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
|
|---|---|---|---|---|---|---|---|---|
eayunstack/fuel-web
|
nailgun/nailgun/task/manager.py
|
2
|
48214
|
# -*- coding: utf-8 -*-
# Copyright 2013 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
from distutils.version import StrictVersion
import traceback
from oslo_serialization import jsonutils
from nailgun.objects.serializers.network_configuration \
import NeutronNetworkConfigurationSerializer
from nailgun.objects.serializers.network_configuration \
import NovaNetworkConfigurationSerializer
from nailgun import consts
from nailgun.db import db
from nailgun.db.sqlalchemy.models import Cluster
from nailgun.db.sqlalchemy.models import Task
from nailgun.errors import errors
from nailgun.logger import logger
from nailgun import notifier
from nailgun import objects
import nailgun.rpc as rpc
from nailgun.task import task as tasks
from nailgun.task.task import TaskHelper
from nailgun.utils import mule
class TaskManager(object):
def __init__(self, cluster_id=None):
if cluster_id:
self.cluster = db().query(Cluster).get(cluster_id)
def _call_silently(self, task, instance, *args, **kwargs):
# create action_log for task
al = TaskHelper.create_action_log(task)
method = getattr(instance, kwargs.pop('method_name', 'execute'))
if task.status == consts.TASK_STATUSES.error:
TaskHelper.update_action_log(task, al)
return
try:
to_return = method(task, *args, **kwargs)
# update action_log instance for task
# for asynchronous task it will be not final update
# as they also are updated in rpc receiver
TaskHelper.update_action_log(task, al)
return to_return
except Exception as exc:
err = str(exc)
if any([
not hasattr(exc, "log_traceback"),
hasattr(exc, "log_traceback") and exc.log_traceback
]):
logger.error(traceback.format_exc())
# update task entity with given data
data = {'status': 'error',
'progress': 100,
'message': err}
objects.Task.update(task, data)
# NOTE(romcheg): Flushing the data is required to unlock
# tasks in order to temporary fix issues with
# the deadlock detection query in tests and let the tests pass.
# TODO(akislitsky): Get rid of this flush as soon as
# task locking issues are resolved.
db().flush()
TaskHelper.update_action_log(task, al)
db().commit()
def check_running_task(self, task_name):
current_tasks = db().query(Task).filter_by(
name=task_name
)
for task in current_tasks:
if task.status == "running":
raise errors.TaskAlreadyRunning()
elif task.status in ("ready", "error"):
db().delete(task)
db().commit()
def serialize_network_cfg(self, cluster):
serializer = {'nova_network': NovaNetworkConfigurationSerializer,
'neutron': NeutronNetworkConfigurationSerializer}
return serializer[cluster.net_provider].serialize_for_cluster(cluster)
class DeploymentCheckMixin(object):
# A list of tasks which we cannot run at the same cluster in parallel
deployment_tasks = (
consts.TASK_NAMES.deploy,
consts.TASK_NAMES.stop_deployment,
consts.TASK_NAMES.reset_environment,
# NOTE(eli): Node deletion may require nodes redeployment
# so it's required to preventing parallel deployment
consts.TASK_NAMES.node_deletion)
@classmethod
def check_no_running_deployment(cls, cluster):
tasks_q = objects.TaskCollection.get_by_name_and_cluster(
cluster, cls.deployment_tasks).filter_by(
status=consts.TASK_STATUSES.running)
tasks_exists = db.query(tasks_q.exists()).scalar()
if tasks_exists:
raise errors.DeploymentAlreadyStarted(
'Cannot perform the actions because there are '
'running tasks {0}'.format(tasks_q.all()))
class ApplyChangesTaskManager(TaskManager, DeploymentCheckMixin):
deployment_type = consts.TASK_NAMES.deploy
def _remove_obsolete_tasks(self):
current_tasks = objects.TaskCollection.get_cluster_tasks(
cluster_id=self.cluster.id, names=(consts.TASK_NAMES.deploy,))
# locking cluster
objects.Cluster.get_by_uid(
self.cluster.id,
fail_if_not_found=True,
lock_for_update=True
)
for task in current_tasks:
if task.status in (consts.TASK_STATUSES.ready,
consts.TASK_STATUSES.error):
db().delete(task)
db().flush()
obsolete_tasks = objects.TaskCollection.filter_by_list(
current_tasks,
'name',
(consts.TASK_NAMES.stop_deployment,
consts.TASK_NAMES.reset_environment)
)
for task in obsolete_tasks:
db().delete(task)
db().flush()
def execute(self, nodes_to_provision_deploy=None, deployment_tasks=None):
logger.info(
u"Trying to start deployment at cluster '{0}'".format(
self.cluster.name or self.cluster.id
)
)
self.check_no_running_deployment(self.cluster)
self._remove_obsolete_tasks()
supertask = Task(name=self.deployment_type, cluster=self.cluster,
status=consts.TASK_STATUSES.pending)
db().add(supertask)
nodes_to_delete = TaskHelper.nodes_to_delete(self.cluster)
nodes_to_deploy = nodes_to_provision_deploy or \
TaskHelper.nodes_to_deploy(self.cluster)
nodes_to_provision = TaskHelper.nodes_to_provision(self.cluster)
if not any([nodes_to_provision, nodes_to_deploy, nodes_to_delete]):
db().rollback()
raise errors.WrongNodeStatus("No changes to deploy")
db().flush()
TaskHelper.create_action_log(supertask)
# we should have task committed for processing in other threads
db().commit()
nodes_ids_to_deploy = ([node.id for node in nodes_to_provision_deploy]
if nodes_to_provision_deploy else None)
mule.call_task_manager_async(
self.__class__,
'_execute_async',
self.cluster.id,
supertask.id,
nodes_to_provision_deploy=nodes_ids_to_deploy,
deployment_tasks=deployment_tasks
)
return supertask
def _execute_async(self, supertask_id, deployment_tasks=None,
nodes_to_provision_deploy=None):
"""Function for execute task in the mule
:param supertask_id: id of parent task
"""
logger.info(u"ApplyChangesTask: execute async starting for task %s",
supertask_id)
supertask = objects.Task.get_by_uid(supertask_id)
try:
self._execute_async_content(
supertask,
deployment_tasks=deployment_tasks,
nodes_to_provision_deploy=nodes_to_provision_deploy)
except Exception as e:
logger.exception('Error occurred when running task')
data = {
'status': consts.TASK_STATUSES.error,
'progress': 100,
'message': u'Error occurred when running task: {0}'.format(
e.message),
}
objects.Task.update(supertask, data)
db().commit()
def delete_nodes(self, supertask, nodes_to_delete):
objects.NodeCollection.lock_nodes(nodes_to_delete)
# For more accurate progress calculation
task_weight = 0.4
task_deletion = supertask.create_subtask(
consts.TASK_NAMES.node_deletion,
weight=task_weight)
logger.debug("Launching deletion task: %s", task_deletion.uuid)
# we should have task committed for processing in other threads
db().commit()
return task_deletion
def _execute_async_content(self, supertask, deployment_tasks=None,
nodes_to_provision_deploy=None):
"""Processes supertask async in mule
:param supertask: SqlAlchemy task object
"""
nodes_to_delete = []
nodes_to_resetup = []
if nodes_to_provision_deploy:
nodes_to_deploy = objects.NodeCollection.get_by_ids(
nodes_to_provision_deploy)
nodes_to_provision = filter(lambda n: any([
n.pending_addition,
n.needs_reprovision]),
nodes_to_deploy)
else:
nodes_to_deploy = TaskHelper.nodes_to_deploy(self.cluster)
nodes_to_provision = TaskHelper.nodes_to_provision(self.cluster)
nodes_to_delete = TaskHelper.nodes_to_delete(self.cluster)
objects.Cluster.adjust_nodes_lists_on_controller_removing(
self.cluster, nodes_to_delete, nodes_to_deploy)
task_messages = []
# Run validation if user didn't redefine
# provisioning and deployment information
if not (nodes_to_provision_deploy or
objects.Cluster.get_provisioning_info(self.cluster) or
objects.Cluster.get_deployment_info(self.cluster)):
try:
self.check_before_deployment(supertask)
except errors.CheckBeforeDeploymentError:
db().commit()
return
if self.cluster.status == consts.CLUSTER_STATUSES.operational:
# rerun particular tasks on all deployed nodes
affected_nodes = set(
nodes_to_deploy + nodes_to_provision + nodes_to_delete)
ready_nodes = set(objects.Cluster.get_nodes_by_status(
self.cluster,
consts.NODE_STATUSES.ready
))
nodes_to_resetup = ready_nodes.difference(affected_nodes)
task_deletion, task_provision, task_deployment = None, None, None
if nodes_to_delete:
task_deletion = self.delete_nodes(supertask, nodes_to_delete)
if nodes_to_provision:
logger.debug("There are nodes to provision: %s",
" ".join([objects.Node.get_node_fqdn(n)
for n in nodes_to_provision]))
# For more accurate progress calculation
task_weight = 0.4
task_provision = supertask.create_subtask(
consts.TASK_NAMES.provision,
status=consts.TASK_STATUSES.pending,
weight=task_weight)
# we should have task committed for processing in other threads
db().commit()
provision_message = self._call_silently(
task_provision,
tasks.ProvisionTask,
nodes_to_provision,
method_name='message'
)
db().commit()
task_provision = objects.Task.get_by_uid(
task_provision.id,
fail_if_not_found=True,
lock_for_update=True
)
# if failed to generate task message for orchestrator
# then task is already set to error
if task_provision.status == consts.TASK_STATUSES.error:
return
task_provision.cache = provision_message
db().commit()
task_messages.append(provision_message)
deployment_message = None
if nodes_to_deploy:
logger.debug("There are nodes to deploy: %s",
" ".join([objects.Node.get_node_fqdn(n)
for n in nodes_to_deploy]))
task_deployment = supertask.create_subtask(
name=consts.TASK_NAMES.deployment,
status=consts.TASK_STATUSES.pending
)
# we should have task committed for processing in other threads
db().commit()
deployment_message = self._call_silently(
task_deployment,
tasks.DeploymentTask,
nodes_to_deploy,
deployment_tasks=deployment_tasks,
method_name='message'
)
db().commit()
task_deployment = objects.Task.get_by_uid(
task_deployment.id,
fail_if_not_found=True,
lock_for_update=True
)
# if failed to generate task message for orchestrator
# then task is already set to error
if task_deployment.status == consts.TASK_STATUSES.error:
return
task_deployment.cache = deployment_message
db().commit()
if nodes_to_resetup:
logger.debug("There are nodes to resetup: %s",
", ".join([objects.Node.get_node_fqdn(n)
for n in nodes_to_resetup]))
if not deployment_message:
task_deployment = supertask.create_subtask(
name=consts.TASK_NAMES.deployment,
status=consts.TASK_STATUSES.pending
)
# we should have task committed for processing in other threads
db().commit()
resetup_message = self._call_silently(
task_deployment,
tasks.DeploymentTask,
nodes_to_resetup,
reexecutable_filter=consts.TASKS_TO_RERUN_ON_DEPLOY_CHANGES,
method_name='message'
)
db().commit()
task_deployment = objects.Task.get_by_uid(
task_deployment.id,
fail_if_not_found=True,
lock_for_update=True
)
# if failed to generate task message for orchestrator
# then task is already set to error
if task_deployment.status == consts.TASK_STATUSES.error:
return
if deployment_message:
deployment_message['args']['deployment_info'].extend(
resetup_message['args']['deployment_info']
)
else:
deployment_message = resetup_message
task_deployment.cache = deployment_message
db().commit()
if deployment_message:
task_messages.append(deployment_message)
# Even if we don't have nodes to deploy, the deployment task
# should be created. Why? Because we need to update both
# nodes.yaml and /etc/hosts on all slaves. Since we need only
# those two tasks, let's create stripped version of
# deployment.
if nodes_to_delete and not nodes_to_deploy:
logger.debug(
"No nodes to deploy, just update nodes.yaml everywhere.")
task_deployment = supertask.create_subtask(
name=consts.TASK_NAMES.deployment,
status=consts.TASK_STATUSES.pending
)
task_message = tasks.UpdateNodesInfoTask.message(task_deployment)
task_deployment.cache = task_message
task_messages.append(task_message)
db().commit()
if nodes_to_provision:
nodes_to_provision = objects.NodeCollection.lock_nodes(
nodes_to_provision
)
for node in nodes_to_provision:
node.status = consts.NODE_STATUSES.provisioning
db().commit()
objects.Cluster.get_by_uid(
self.cluster.id,
fail_if_not_found=True,
lock_for_update=True
)
self.cluster.status = consts.CLUSTER_STATUSES.deployment
db().add(self.cluster)
db().commit()
# We have to execute node deletion task only when provision,
# deployment and other tasks are in the database. Otherwise,
# it may be executed too quick (e.g. our tests) and this
# will affect parent task calculation - it will be marked
# as 'ready' because by that time it have only two subtasks
# - network_check and node_deletion - and they're ready.
# In order to avoid that wrong behavior, let's send
# deletion task to execution only when others subtasks in
# the database.
if task_deletion:
self._call_silently(
task_deletion,
tasks.DeletionTask,
tasks.DeletionTask.get_task_nodes_for_cluster(self.cluster),
check_ceph=True)
db().commit()
if task_messages:
rpc.cast('naily', task_messages)
logger.debug(
u"Deployment: task to deploy cluster '{0}' is {1}".format(
self.cluster.name or self.cluster.id,
supertask.uuid
)
)
def check_before_deployment(self, supertask):
"""Performs checks before deployment
:param supertask: task SqlAlchemy object
"""
try:
# if there are VIPs with same names in the network configuration
# the error will be raised. Such situation may occur when, for
# example, enabled plugins contain conflicting network
# configuration
network_info = self.serialize_network_cfg(self.cluster)
except (errors.DuplicatedVIPNames, errors.NetworkRoleConflict) as e:
raise errors.CheckBeforeDeploymentError(e.message)
logger.info(
u"Network info:\n{0}".format(
jsonutils.dumps(network_info, indent=4)
)
)
# checking admin intersection with untagged
network_info["networks"] = [
n for n in network_info["networks"] if n["name"] != "fuelweb_admin"
]
check_repo_connect = supertask.create_subtask(
consts.TASK_NAMES.check_networks)
self._call_silently(
check_repo_connect,
tasks.CheckRepositoryConnectionFromMasterNodeTask,
)
if check_repo_connect.status == consts.TASK_STATUSES.error:
logger.warning(
"Checking connectivity to repositories failed: %s",
check_repo_connect.message
)
raise errors.CheckBeforeDeploymentError(check_repo_connect.message)
check_networks = supertask.create_subtask(
consts.TASK_NAMES.check_networks)
self._call_silently(
check_networks,
tasks.CheckNetworksTask,
data=network_info,
check_all_parameters=True
)
if check_networks.status == consts.TASK_STATUSES.error:
logger.warning(
"Checking networks failed: %s", check_networks.message
)
raise errors.CheckBeforeDeploymentError(check_networks.message)
TaskHelper.set_ready_if_not_finished(check_networks)
db().delete(check_networks)
db().refresh(supertask)
db().flush()
# checking prerequisites
check_before = supertask.create_subtask(
consts.TASK_NAMES.check_before_deployment
)
logger.debug("Checking prerequisites task: %s", check_before.uuid)
self._call_silently(
check_before,
tasks.CheckBeforeDeploymentTask
)
# if failed to check prerequisites
# then task is already set to error
if check_before.status == consts.TASK_STATUSES.error:
logger.warning(
"Checking prerequisites failed: %s", check_before.message
)
raise errors.CheckBeforeDeploymentError(check_before.message)
logger.debug(
"Checking prerequisites is successful, starting deployment..."
)
TaskHelper.set_ready_if_not_finished(check_before)
db().delete(check_before)
db().refresh(supertask)
db().flush()
class SpawnVMsTaskManager(ApplyChangesTaskManager):
deployment_type = consts.TASK_NAMES.spawn_vms
def delete_nodes(self, supertask, nodes_to_delete):
return None
class ProvisioningTaskManager(TaskManager):
def execute(self, nodes_to_provision):
"""Run provisioning task on specified nodes."""
# locking nodes
nodes_ids = [node.id for node in nodes_to_provision]
nodes = objects.NodeCollection.filter_by_list(
None,
'id',
nodes_ids,
order_by='id'
)
logger.debug('Nodes to provision: {0}'.format(
' '.join([objects.Node.get_node_fqdn(n)
for n in nodes_to_provision])))
task_provision = Task(name=consts.TASK_NAMES.provision,
status=consts.TASK_STATUSES.pending,
cluster=self.cluster)
db().add(task_provision)
for node in nodes:
objects.Node.reset_vms_created_state(node)
db().commit()
provision_message = self._call_silently(
task_provision,
tasks.ProvisionTask,
nodes_to_provision,
method_name='message'
)
task_provision = objects.Task.get_by_uid(
task_provision.id,
fail_if_not_found=True,
lock_for_update=True
)
task_provision.cache = provision_message
objects.NodeCollection.lock_for_update(nodes).all()
for node in nodes_to_provision:
node.pending_addition = False
node.status = consts.NODE_STATUSES.provisioning
node.progress = 0
db().commit()
rpc.cast('naily', provision_message)
return task_provision
class DeploymentTaskManager(TaskManager):
def execute(self, nodes_to_deployment, deployment_tasks=None):
deployment_tasks = deployment_tasks or []
logger.debug('Nodes to deploy: {0}'.format(
' '.join([objects.Node.get_node_fqdn(n)
for n in nodes_to_deployment])))
task_deployment = Task(
name=consts.TASK_NAMES.deployment, cluster=self.cluster,
status=consts.TASK_STATUSES.pending
)
db().add(task_deployment)
deployment_message = self._call_silently(
task_deployment,
tasks.DeploymentTask,
nodes_to_deployment,
deployment_tasks=deployment_tasks,
method_name='message')
db().refresh(task_deployment)
# locking task
task_deployment = objects.Task.get_by_uid(
task_deployment.id,
fail_if_not_found=True,
lock_for_update=True
)
# locking nodes
objects.NodeCollection.lock_nodes(nodes_to_deployment)
task_deployment.cache = deployment_message
for node in nodes_to_deployment:
node.status = 'deploying'
node.progress = 0
db().commit()
rpc.cast('naily', deployment_message)
return task_deployment
class StopDeploymentTaskManager(TaskManager):
def execute(self):
stop_running = objects.TaskCollection.filter_by(
None,
cluster_id=self.cluster.id,
name=consts.TASK_NAMES.stop_deployment
)
stop_running = objects.TaskCollection.order_by(
stop_running, 'id'
).first()
if stop_running:
if stop_running.status in (
consts.TASK_STATUSES.running,
consts.TASK_STATUSES.pending):
raise errors.StopAlreadyRunning(
"Stopping deployment task "
"is already launched"
)
else:
db().delete(stop_running)
db().commit()
deployment_task = objects.TaskCollection.filter_by(
None,
cluster_id=self.cluster.id,
name=consts.TASK_NAMES.deployment,
)
deployment_task = deployment_task.filter(
Task.status != consts.TASK_STATUSES.pending
)
deployment_task = objects.TaskCollection.order_by(
deployment_task, '-id'
).first()
provisioning_task = objects.TaskCollection.filter_by(
None,
cluster_id=self.cluster.id,
name=consts.TASK_NAMES.provision,
)
provisioning_task = provisioning_task.filter(
Task.status != consts.TASK_STATUSES.pending
)
provisioning_task = objects.TaskCollection.order_by(
provisioning_task, '-id'
).first()
if not deployment_task and not provisioning_task:
db().rollback()
raise errors.DeploymentNotRunning(
u"Nothing to stop - deployment is "
u"not running on environment '{0}'".format(
self.cluster.id
)
)
# Updating action logs for deploy task
deploy_task = objects.TaskCollection.filter_by(
None,
cluster_id=self.cluster.id,
name=consts.TASK_NAMES.deploy
)
deploy_task = objects.TaskCollection.order_by(
deploy_task, 'id').first()
if deploy_task:
TaskHelper.set_ready_if_not_finished(deploy_task)
db().commit()
task = Task(
name=consts.TASK_NAMES.stop_deployment,
cluster=self.cluster
)
db().add(task)
db().commit()
self._call_silently(
task,
tasks.StopDeploymentTask,
deploy_task=deployment_task,
provision_task=provisioning_task
)
return task
class ResetEnvironmentTaskManager(TaskManager):
def execute(self):
deploy_running = db().query(Task).filter_by(
cluster=self.cluster,
name=consts.TASK_NAMES.deploy,
status='running'
).first()
if deploy_running:
raise errors.DeploymentAlreadyStarted(
u"Can't reset environment '{0}' when "
u"deployment is running".format(
self.cluster.id
)
)
obsolete_tasks = db().query(Task).filter_by(
cluster_id=self.cluster.id,
).filter(
Task.name.in_([
consts.TASK_NAMES.deploy,
consts.TASK_NAMES.deployment,
consts.TASK_NAMES.stop_deployment
])
)
for task in obsolete_tasks:
db().delete(task)
nodes = objects.Cluster.get_nodes_by_role(
self.cluster, consts.VIRTUAL_NODE_TYPES.virt)
for node in nodes:
objects.Node.reset_vms_created_state(node)
db().commit()
supertask = Task(
name=consts.TASK_NAMES.reset_environment,
cluster=self.cluster
)
db().add(supertask)
al = TaskHelper.create_action_log(supertask)
remove_keys_task = supertask.create_subtask(
consts.TASK_NAMES.reset_environment
)
db.commit()
rpc.cast('naily', [
tasks.ResetEnvironmentTask.message(supertask),
tasks.RemoveClusterKeys.message(remove_keys_task)
])
TaskHelper.update_action_log(supertask, al)
return supertask
class UpdateEnvironmentTaskManager(TaskManager):
def execute(self):
if not self.cluster.pending_release_id:
raise errors.InvalidReleaseId(
u"Can't update environment '{0}' when "
u"new release Id is invalid".format(self.cluster.name))
running_tasks = db().query(Task).filter_by(
cluster_id=self.cluster.id,
status='running'
).filter(
Task.name.in_([
consts.TASK_NAMES.deploy,
consts.TASK_NAMES.deployment,
consts.TASK_NAMES.reset_environment,
consts.TASK_NAMES.stop_deployment
])
)
if running_tasks.first():
raise errors.TaskAlreadyRunning(
u"Can't update environment '{0}' when "
u"other task is running".format(
self.cluster.id
)
)
nodes_to_change = TaskHelper.nodes_to_upgrade(self.cluster)
logger.debug('Nodes to update: {0}'.format(
' '.join([objects.Node.get_node_fqdn(n)
for n in nodes_to_change])))
task_update = Task(name=consts.TASK_NAMES.update, cluster=self.cluster)
db().add(task_update)
self.cluster.status = 'update'
db().flush()
deployment_message = self._call_silently(
task_update,
tasks.UpdateTask,
nodes_to_change,
method_name='message')
db().refresh(task_update)
for node in nodes_to_change:
node.status = 'deploying'
node.progress = 0
db().commit()
rpc.cast('naily', deployment_message)
return task_update
class CheckNetworksTaskManager(TaskManager):
def execute(self, data, check_all_parameters=False):
# Make a copy of original 'data' due to being changed by
# 'tasks.CheckNetworksTask'
data_copy = copy.deepcopy(data)
locked_tasks = objects.TaskCollection.filter_by(
None,
cluster_id=self.cluster.id,
name=consts.TASK_NAMES.check_networks
)
locked_tasks = objects.TaskCollection.order_by(locked_tasks, 'id')
check_networks = objects.TaskCollection.lock_for_update(
locked_tasks
).first()
if check_networks:
TaskHelper.set_ready_if_not_finished(check_networks)
db().delete(check_networks)
db().flush()
task = Task(
name=consts.TASK_NAMES.check_networks,
cluster=self.cluster
)
db().add(task)
db().commit()
self._call_silently(
task,
tasks.CheckNetworksTask,
data_copy,
check_all_parameters
)
task = objects.Task.get_by_uid(
task.id,
fail_if_not_found=True,
lock_for_update=True
)
if task.status == consts.TASK_STATUSES.running:
# update task status with given data
objects.Task.update(
task,
{'status': consts.TASK_STATUSES.ready, 'progress': 100})
db().commit()
return task
class VerifyNetworksTaskManager(TaskManager):
_blocking_statuses = (
consts.CLUSTER_STATUSES.deployment,
consts.CLUSTER_STATUSES.update,
)
def remove_previous_task(self):
locked_tasks = objects.TaskCollection.filter_by(
None,
cluster_id=self.cluster.id
)
locked_tasks = objects.TaskCollection.filter_by_list(
locked_tasks,
'name',
(consts.TASK_NAMES.check_networks,
consts.TASK_NAMES.verify_networks),
order_by='id'
)
locked_tasks = objects.TaskCollection.lock_for_update(
locked_tasks
).all()
check_networks = objects.TaskCollection.filter_by(
locked_tasks,
name=consts.TASK_NAMES.check_networks
)
check_networks = list(check_networks)
if check_networks:
db().delete(check_networks[0])
db().flush()
verification_tasks = objects.TaskCollection.filter_by(
locked_tasks,
name=consts.TASK_NAMES.verify_networks
)
verification_tasks = list(verification_tasks)
# TODO(pkaminski): this code shouldn't be required at all
if verification_tasks:
ver_task = verification_tasks[0]
if ver_task.status == consts.TASK_STATUSES.running:
raise errors.CantRemoveOldVerificationTask()
for subtask in ver_task.subtasks:
db().delete(subtask)
db().delete(ver_task)
db().flush()
def execute(self, nets, vlan_ids):
self.remove_previous_task()
task = Task(
name=consts.TASK_NAMES.check_networks,
cluster=self.cluster
)
if len([n for n in self.cluster.nodes if n.online]) < 2:
task.status = consts.TASK_STATUSES.error
task.progress = 100
task.message = ('At least two online nodes are required to be '
'in the environment for network verification.')
db().add(task)
db().commit()
return task
if len(self.cluster.node_groups) > 1:
task.status = consts.TASK_STATUSES.error
task.progress = 100
task.message = ('Network verification is disabled for '
'environments containing more than one node '
'group.')
db().add(task)
db().commit()
return task
if self.cluster.status in self._blocking_statuses:
task.status = consts.TASK_STATUSES.error
task.progress = 100
task.message = (
"Environment is not ready to run network verification "
"because it is in '{0}' state.".format(self.cluster.status)
)
db().add(task)
db().commit()
return task
db().add(task)
db().commit()
self._call_silently(
task,
tasks.CheckNetworksTask,
data=nets,
check_all_parameters=True
)
db().refresh(task)
if task.status != consts.TASK_STATUSES.error:
# this one is connected with UI issues - we need to
# separate if error happened inside nailgun or somewhere
# in the orchestrator, and UI does it by task name.
task.name = consts.TASK_NAMES.verify_networks
verify_task = tasks.VerifyNetworksTask(task, vlan_ids)
if tasks.CheckDhcpTask.enabled(self.cluster):
dhcp_subtask = objects.task.Task.create_subtask(
task, name=consts.TASK_NAMES.check_dhcp)
verify_task.add_subtask(
tasks.CheckDhcpTask(dhcp_subtask, vlan_ids))
if tasks.MulticastVerificationTask.enabled(self.cluster):
multicast = objects.task.Task.create_subtask(
task, name=consts.TASK_NAMES.multicast_verification)
verify_task.add_subtask(
tasks.MulticastVerificationTask(multicast))
# we have remote connectivity checks since fuel 6.1,
# so we should not create those tasks for old envs
if StrictVersion(self.cluster.release.environment_version) >= \
StrictVersion(consts.FUEL_REMOTE_REPOS):
# repo connectivity check via default gateway
repo_check_task = objects.task.Task.create_subtask(
task, name=consts.TASK_NAMES.check_repo_availability)
verify_task.add_subtask(
tasks.CheckRepoAvailability(repo_check_task, vlan_ids))
# repo connectivity check via external gateway
conf, errors = tasks.CheckRepoAvailabilityWithSetup.get_config(
self.cluster)
# if there is no conf - there is no nodes on which
# we need to setup network
if conf:
repo_check_task = objects.task.Task.create_subtask(
task,
consts.TASK_NAMES.check_repo_availability_with_setup)
verify_task.add_subtask(
tasks.CheckRepoAvailabilityWithSetup(
repo_check_task, conf))
if errors:
notifier.notify(
"warning",
'\n'.join(errors),
self.cluster.id
)
db().commit()
self._call_silently(task, verify_task)
return task
class ClusterDeletionManager(TaskManager):
def execute(self):
current_tasks = objects.TaskCollection.get_cluster_tasks(
self.cluster.id, names=(consts.TASK_NAMES.cluster_deletion,)
)
# locking cluster
objects.Cluster.get_by_uid(
self.cluster.id,
fail_if_not_found=True,
lock_for_update=True
)
# locking nodes
nodes = objects.NodeCollection.filter_by(
None,
cluster_id=self.cluster.id
)
nodes = objects.NodeCollection.order_by(nodes, 'id')
objects.NodeCollection.lock_for_update(nodes).all()
deploy_running = objects.TaskCollection.filter_by(
None,
cluster_id=self.cluster.id,
name=consts.TASK_NAMES.deploy,
status=consts.TASK_STATUSES.running
)
deploy_running = objects.TaskCollection.order_by(
deploy_running,
'id'
).first()
if deploy_running:
logger.error(
u"Deleting cluster '{0}' "
"while deployment is still running".format(
self.cluster.name
)
)
# Updating action logs for deploy task
TaskHelper.set_ready_if_not_finished(deploy_running)
logger.debug("Removing cluster tasks")
for task in current_tasks:
if task.status == consts.TASK_STATUSES.running:
db().rollback()
raise errors.DeletionAlreadyStarted()
elif task.status in (consts.TASK_STATUSES.ready,
consts.TASK_STATUSES.error):
for subtask in task.subtasks:
db().delete(subtask)
db().delete(task)
db().flush()
logger.debug("Labeling cluster nodes to delete")
for node in self.cluster.nodes:
node.pending_deletion = True
db().add(node)
db().flush()
self.cluster.status = consts.CLUSTER_STATUSES.remove
db().add(self.cluster)
logger.debug("Creating cluster deletion task")
task = Task(name=consts.TASK_NAMES.cluster_deletion,
cluster=self.cluster)
db().add(task)
db().commit()
self._call_silently(
task,
tasks.ClusterDeletionTask
)
return task
class DumpTaskManager(TaskManager):
def execute(self, conf=None):
logger.info("Trying to start dump_environment task")
self.check_running_task(consts.TASK_NAMES.dump)
task = Task(name=consts.TASK_NAMES.dump)
db().add(task)
db().flush()
self._call_silently(
task,
tasks.DumpTask,
conf=conf
)
return task
class GenerateCapacityLogTaskManager(TaskManager):
def execute(self):
logger.info("Trying to start capacity_log task")
self.check_running_task(consts.TASK_NAMES.capacity_log)
task = Task(name=consts.TASK_NAMES.capacity_log)
db().add(task)
db().commit()
self._call_silently(
task,
tasks.GenerateCapacityLogTask)
return task
class NodeDeletionTaskManager(TaskManager, DeploymentCheckMixin):
def verify_nodes_with_cluster(self, nodes):
"""Make sure that task.cluster is the same as all nodes' cluster
:param nodes:
:return: bool
"""
cluster_id = None
if hasattr(self, 'cluster'):
cluster_id = self.cluster.id
invalid_nodes = []
for node in nodes:
if node.cluster_id != cluster_id:
invalid_nodes.append(node)
if invalid_nodes:
raise errors.InvalidData(
"Invalid data -- nodes' cluster_ids {0} do not match "
"cluster's id {1}".format(
[node.id for node in invalid_nodes], cluster_id)
)
def execute(self, nodes_to_delete, mclient_remove=True):
cluster = None
if hasattr(self, 'cluster'):
cluster = self.cluster
logger.info("Trying to execute node deletion task with nodes %s",
', '.join(str(node.id) for node in nodes_to_delete))
self.verify_nodes_with_cluster(nodes_to_delete)
objects.NodeCollection.lock_nodes(nodes_to_delete)
if cluster is None:
# DeletionTask operates on cluster's nodes.
# Nodes that are not in cluster are simply deleted.
objects.NodeCollection.delete_by_ids([
n.id for n in nodes_to_delete])
db().flush()
task = Task(name=consts.TASK_NAMES.node_deletion,
progress=100,
status=consts.TASK_STATUSES.ready)
db().add(task)
db().flush()
return task
self.check_no_running_deployment(self.cluster)
task = Task(name=consts.TASK_NAMES.node_deletion,
cluster=self.cluster)
db().add(task)
for node in nodes_to_delete:
objects.Node.update(node,
{'status': consts.NODE_STATUSES.removing,
'pending_deletion': True})
db().flush()
nodes_to_deploy = []
objects.Cluster.adjust_nodes_lists_on_controller_removing(
self.cluster, nodes_to_delete, nodes_to_deploy)
# NOTE(aroma): in case of removing of a controller node we do
# implicit redeployment of all left controllers here in
# order to preserve consistency of a HA cluster.
# The reason following filtering is added is that we must
# redeploy only controllers in ready status. Also in case
# one of the nodes is in error state we must cancel the whole
# operation as result of the redeployment in this case is unpredictable
# and user may end up with not working cluster
controllers_with_ready_status = []
for controller in nodes_to_deploy:
if controller.status == consts.NODE_STATUSES.error:
raise errors.ControllerInErrorState()
elif controller.status == consts.NODE_STATUSES.ready:
controllers_with_ready_status.append(controller)
if controllers_with_ready_status:
logger.debug("There are nodes to deploy: %s",
" ".join([objects.Node.get_node_fqdn(n)
for n in controllers_with_ready_status]))
task_deployment = task.create_subtask(
consts.TASK_NAMES.deployment)
deployment_message = self._call_silently(
task_deployment,
tasks.DeploymentTask,
controllers_with_ready_status,
method_name='message'
)
db().flush()
# if failed to generate task message for orchestrator
# then task is already set to error
if task_deployment.status == consts.TASK_STATUSES.error:
return task_deployment
rpc.cast('naily', [deployment_message])
db().commit()
self._call_silently(
task,
tasks.DeletionTask,
nodes=tasks.DeletionTask.prepare_nodes_for_task(
nodes_to_delete, mclient_remove=mclient_remove))
return task
class BaseStatsUserTaskManager(TaskManager):
task_name = None
task_cls = None
def execute(self):
logger.info("Trying to execute %s in the operational "
"environments", self.task_name)
created_tasks = []
clusters = objects.ClusterCollection.filter_by(
None, status=consts.CLUSTER_STATUSES.operational)
for cluster in clusters:
logger.debug("Creating task for %s on the "
"cluster %s", self.task_name, cluster.id)
primary_controller = objects.Cluster.get_primary_node(
cluster, 'controller')
if primary_controller is not None:
logger.debug("Primary controller cluster %s found: %s. "
"Creating task for %s", cluster.id,
primary_controller.id, self.task_name)
if objects.TaskCollection.filter_by(
None,
cluster_id=cluster.id,
name=self.task_name,
status=consts.TASK_STATUSES.running).count():
logger.debug("Task %s is already running for cluster %s",
self.task_name, cluster.id)
continue
task = Task(name=self.task_name, cluster_id=cluster.id)
db().add(task)
db().commit()
created_tasks.append(task)
self._call_silently(
task,
self.task_cls,
primary_controller
)
else:
logger.debug("Primary controller not found for cluster %s",
cluster.id)
return created_tasks
class CreateStatsUserTaskManager(BaseStatsUserTaskManager):
task_name = consts.TASK_NAMES.create_stats_user
task_cls = tasks.CreateStatsUserTask
class RemoveStatsUserTaskManager(BaseStatsUserTaskManager):
task_name = consts.TASK_NAMES.remove_stats_user
task_cls = tasks.RemoveStatsUserTask
class UpdateDnsmasqTaskManager(TaskManager):
def execute(self):
logger.info("Starting update_dnsmasq task")
self.check_running_task(consts.TASK_NAMES.update_dnsmasq)
task = Task(name=consts.TASK_NAMES.update_dnsmasq)
db().add(task)
db().commit()
self._call_silently(
task,
tasks.UpdateDnsmasqTask
)
return task
class OpenstackConfigTaskManager(TaskManager):
def execute(self, filters):
self.check_running_task(consts.TASK_NAMES.deployment)
task = Task(name=consts.TASK_NAMES.deployment,
cluster=self.cluster,
status=consts.TASK_STATUSES.pending)
db().add(task)
nodes_to_update = objects.Cluster.get_nodes_to_update_config(
self.cluster, filters.get('node_id'), filters.get('node_role'))
message = self._call_silently(
task, tasks.UpdateOpenstackConfigTask,
self.cluster, nodes_to_update, method_name='message')
# locking task
task = objects.Task.get_by_uid(
task.id,
fail_if_not_found=True,
lock_for_update=True
)
# locking nodes
objects.NodeCollection.lock_nodes(nodes_to_update)
task.cache = copy.copy(message)
task.cache['nodes'] = [n.id for n in nodes_to_update]
for node in nodes_to_update:
node.status = consts.NODE_STATUSES.deploying
node.progress = 0
db().commit()
rpc.cast('naily', message)
return task
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
259,
1898,
6171,
603,
723,
4466,
83,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
504,
7065,
14,
1023,
492,
23052,
3353,
199,
646,
5190,
199,
199,
504,
11258,
63,
12161,
492,
18705,
199,
199,
504,
302,
1054,
17924,
14,
1462,
14,
12844,
14,
1200,
63,
4758,
971,
272,
492,
30422,
4491,
5688,
7299,
199,
504,
302,
1054,
17924,
14,
1462,
14,
12844,
14,
1200,
63,
4758,
971,
272,
492,
28184,
4491,
5688,
7299,
199,
199,
504,
302,
1054,
17924,
492,
950,
83,
199,
504,
302,
1054,
17924,
14,
697,
492,
1592,
199,
504,
302,
1054,
17924,
14,
697,
14,
14536,
14,
992,
492,
16454,
199,
504,
302,
1054,
17924,
14,
697,
14,
14536,
14,
992,
492,
8495,
199,
504,
302,
1054,
17924,
14,
2550,
492,
2552,
199,
504,
302,
1054,
17924,
14,
2921,
492,
2512,
199,
504,
302,
1054,
17924,
492,
30154,
199,
504,
302,
1054,
17924,
492,
2251,
199,
646,
302,
1054,
17924,
14,
4354,
465,
8985,
199,
504,
302,
1054,
17924,
14,
1765,
492,
2120,
465,
6527,
199,
504,
302,
1054,
17924,
14,
1765,
14,
1765,
492,
8495,
4433,
199,
504,
302,
1054,
17924,
14,
1208,
492,
333,
443,
421,
199,
533,
8495,
2988,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
4350,
63,
344,
29,
403,
304,
267,
340,
4350,
63,
344,
26,
288,
291,
14,
4201,
275,
1592,
1252,
1131,
8,
9581,
680,
362,
8,
4201,
63,
344,
9,
339,
347,
485,
1250,
63,
25163,
8,
277,
12,
2120,
12,
1256,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
1218,
1595,
63,
793,
367,
2120,
267,
741,
275,
8495,
4433,
14,
981,
63,
1287,
63,
793,
8,
1765,
9,
398,
1083,
275,
2519,
8,
842,
12,
2074,
14,
1935,
360,
765,
63,
354,
297,
283,
2526,
1333,
267,
340,
2120,
14,
1205,
508,
950,
83,
14,
17179,
63,
6305,
654,
14,
705,
26,
288,
8495,
4433,
14,
873,
63,
1287,
63,
793,
8,
1765,
12,
741,
9,
288,
372,
267,
862,
26,
288,
370,
63,
1107,
275,
1083,
8,
1765,
12,
627,
589,
12,
1011,
958,
9,
953,
327,
1678,
1595,
63,
793,
1256,
367,
2120,
288,
327,
367,
15608,
2120,
652,
911,
506,
440,
4242,
1678,
288,
327,
465,
2985,
2597,
787,
4588,
315,
8985,
13035,
288,
8495,
4433,
14,
873,
63,
1287,
63,
793,
8,
1765,
12,
741,
9,
953,
372,
370,
63,
1107,
267,
871,
2186,
465,
3178,
26,
288,
2329,
275,
620,
8,
2804,
9,
288,
340,
1263,
779,
355,
440,
2688,
8,
2804,
12,
298,
793,
63,
6894,
1288,
355,
2688,
8,
2804,
12,
298,
793,
63,
6894,
531,
436,
3178,
14,
793,
63,
6894,
288,
1622,
304,
355,
2512,
14,
705,
8,
6894,
14,
908,
63,
2804,
1012,
953,
327,
1678,
2120,
4642,
543,
1627,
666,
288,
666,
275,
791,
1205,
356,
283,
705,
297,
490,
283,
5734,
356,
2948,
12,
490,
283,
1188,
356,
2329,
93,
288,
2251,
14,
4476,
14,
873,
8,
1765,
12,
666,
9,
288,
327,
6944,
8,
417,
595,
71,
304,
11040,
2084,
316,
314,
666,
365,
1415,
370,
28451,
288,
327,
6527,
315,
1865,
370,
7937,
5325,
10876,
543,
288,
327,
314,
12314,
831,
15212,
1827,
315,
2295,
436,
4691,
314,
2295,
986,
14,
288,
327,
3254,
8,
1151,
374,
1051,
12267,
304,
2372,
16146,
402,
642,
8976,
465,
18930,
465,
288,
327,
2120,
27267,
10876,
787,
12152,
14,
288,
1592,
1252,
4939,
342,
288,
8495,
4433,
14,
873,
63,
1287,
63,
793,
8,
1765,
12,
741,
9,
953,
1592,
1252,
3543,
342,
339,
347,
1104,
63,
5720,
63,
1765,
8,
277,
12,
2120,
63,
354,
304,
267,
1453,
63,
5054,
275,
1592,
1252,
1131,
8,
4476,
680,
1541,
63,
991,
8,
288,
536,
29,
1765,
63,
354,
267,
776,
267,
367,
2120,
315,
1453,
63,
5054,
26,
288,
340,
2120,
14,
1205,
508,
298,
5720,
582,
355,
746,
2552,
14,
4476,
16760,
9602,
342,
288,
916,
2120,
14,
1205,
315,
1689,
2179,
401,
298,
705,
2349,
355,
1592,
1252,
1807,
8,
1765,
9,
355,
1592,
1252,
3543,
342,
339,
347,
8437,
63,
1200,
63,
4128,
8,
277,
12,
4350,
304,
267,
9146,
275,
791,
6765,
63,
1200,
356,
28184,
4491,
5688,
7299,
12,
1993,
283,
10271,
356,
30422,
4491,
5688,
7299,
93,
267,
372,
9146,
59,
4201,
14,
846,
63,
3780,
1055,
3549,
63,
509,
63,
4201,
8,
4201,
9,
421,
199,
533,
21588,
7775,
1799,
4256,
8,
785,
304,
339,
327,
437,
769,
402,
6527,
1314,
781,
3913,
1255,
737,
314,
2011,
4350,
315,
9861,
272,
14295,
63,
5054,
275,
334,
267,
950,
83,
14,
17179,
63,
14546,
14,
11060,
12,
267,
950,
83,
14,
17179,
63,
14546,
14,
2379,
63,
13605,
12,
267,
950,
83,
14,
17179,
63,
14546,
14,
3958,
63,
5418,
12,
267,
327,
6944,
8,
18865,
304,
5013,
14068,
1443,
4409,
3380,
295,
13605,
267,
327,
880,
652,
1159,
1415,
370,
7981,
316,
9861,
14295,
267,
950,
83,
14,
17179,
63,
14546,
14,
932,
63,
14281,
9,
339,
768,
3744,
272,
347,
1104,
63,
889,
63,
5720,
63,
13605,
8,
1886,
12,
4350,
304,
267,
6527,
63,
81,
275,
2251,
14,
4476,
7768,
14,
362,
63,
991,
63,
354,
63,
460,
63,
4201,
8,
288,
4350,
12,
843,
14,
13605,
63,
5054,
680,
1541,
63,
991,
8,
355
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
259,
1898,
6171,
603,
723,
4466,
83,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
504,
7065,
14,
1023,
492,
23052,
3353,
199,
646,
5190,
199,
199,
504,
11258,
63,
12161,
492,
18705,
199,
199,
504,
302,
1054,
17924,
14,
1462,
14,
12844,
14,
1200,
63,
4758,
971,
272,
492,
30422,
4491,
5688,
7299,
199,
504,
302,
1054,
17924,
14,
1462,
14,
12844,
14,
1200,
63,
4758,
971,
272,
492,
28184,
4491,
5688,
7299,
199,
199,
504,
302,
1054,
17924,
492,
950,
83,
199,
504,
302,
1054,
17924,
14,
697,
492,
1592,
199,
504,
302,
1054,
17924,
14,
697,
14,
14536,
14,
992,
492,
16454,
199,
504,
302,
1054,
17924,
14,
697,
14,
14536,
14,
992,
492,
8495,
199,
504,
302,
1054,
17924,
14,
2550,
492,
2552,
199,
504,
302,
1054,
17924,
14,
2921,
492,
2512,
199,
504,
302,
1054,
17924,
492,
30154,
199,
504,
302,
1054,
17924,
492,
2251,
199,
646,
302,
1054,
17924,
14,
4354,
465,
8985,
199,
504,
302,
1054,
17924,
14,
1765,
492,
2120,
465,
6527,
199,
504,
302,
1054,
17924,
14,
1765,
14,
1765,
492,
8495,
4433,
199,
504,
302,
1054,
17924,
14,
1208,
492,
333,
443,
421,
199,
533,
8495,
2988,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
4350,
63,
344,
29,
403,
304,
267,
340,
4350,
63,
344,
26,
288,
291,
14,
4201,
275,
1592,
1252,
1131,
8,
9581,
680,
362,
8,
4201,
63,
344,
9,
339,
347,
485,
1250,
63,
25163,
8,
277,
12,
2120,
12,
1256,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
1218,
1595,
63,
793,
367,
2120,
267,
741,
275,
8495,
4433,
14,
981,
63,
1287,
63,
793,
8,
1765,
9,
398,
1083,
275,
2519,
8,
842,
12,
2074,
14,
1935,
360,
765,
63,
354,
297,
283,
2526,
1333,
267,
340,
2120,
14,
1205,
508,
950,
83,
14,
17179,
63,
6305,
654,
14,
705,
26,
288,
8495,
4433,
14,
873,
63,
1287,
63,
793,
8,
1765,
12,
741,
9,
288,
372,
267,
862,
26,
288,
370,
63,
1107,
275,
1083,
8,
1765,
12,
627,
589,
12,
1011,
958,
9,
953,
327,
1678,
1595,
63,
793,
1256,
367,
2120,
288,
327,
367,
15608,
2120,
652,
911,
506,
440,
4242,
1678,
288,
327,
465,
2985,
2597,
787,
4588,
315,
8985,
13035,
288,
8495,
4433,
14,
873,
63,
1287,
63,
793,
8,
1765,
12,
741,
9,
953,
372,
370,
63,
1107,
267,
871,
2186,
465,
3178,
26,
288,
2329,
275,
620,
8,
2804,
9,
288,
340,
1263,
779,
355,
440,
2688,
8,
2804,
12,
298,
793,
63,
6894,
1288,
355,
2688,
8,
2804,
12,
298,
793,
63,
6894,
531,
436,
3178,
14,
793,
63,
6894,
288,
1622,
304,
355,
2512,
14,
705,
8,
6894,
14,
908,
63,
2804,
1012,
953,
327,
1678,
2120,
4642,
543,
1627,
666,
288,
666,
275,
791,
1205,
356,
283,
705,
297,
490,
283,
5734,
356,
2948,
12,
490,
283,
1188,
356,
2329,
93,
288,
2251,
14,
4476,
14,
873,
8,
1765,
12,
666,
9,
288,
327,
6944,
8,
417,
595,
71,
304,
11040,
2084,
316,
314,
666,
365,
1415,
370,
28451,
288,
327,
6527,
315,
1865,
370,
7937,
5325,
10876,
543,
288,
327,
314,
12314,
831,
15212,
1827,
315,
2295,
436,
4691,
314,
2295,
986,
14,
288,
327,
3254,
8,
1151,
374,
1051,
12267,
304,
2372,
16146,
402,
642,
8976,
465,
18930,
465,
288,
327,
2120,
27267,
10876,
787,
12152,
14,
288,
1592,
1252,
4939,
342,
288,
8495,
4433,
14,
873,
63,
1287,
63,
793,
8,
1765,
12,
741,
9,
953,
1592,
1252,
3543,
342,
339,
347,
1104,
63,
5720,
63,
1765,
8,
277,
12,
2120,
63,
354,
304,
267,
1453,
63,
5054,
275,
1592,
1252,
1131,
8,
4476,
680,
1541,
63,
991,
8,
288,
536,
29,
1765,
63,
354,
267,
776,
267,
367,
2120,
315,
1453,
63,
5054,
26,
288,
340,
2120,
14,
1205,
508,
298,
5720,
582,
355,
746,
2552,
14,
4476,
16760,
9602,
342,
288,
916,
2120,
14,
1205,
315,
1689,
2179,
401,
298,
705,
2349,
355,
1592,
1252,
1807,
8,
1765,
9,
355,
1592,
1252,
3543,
342,
339,
347,
8437,
63,
1200,
63,
4128,
8,
277,
12,
4350,
304,
267,
9146,
275,
791,
6765,
63,
1200,
356,
28184,
4491,
5688,
7299,
12,
1993,
283,
10271,
356,
30422,
4491,
5688,
7299,
93,
267,
372,
9146,
59,
4201,
14,
846,
63,
3780,
1055,
3549,
63,
509,
63,
4201,
8,
4201,
9,
421,
199,
533,
21588,
7775,
1799,
4256,
8,
785,
304,
339,
327,
437,
769,
402,
6527,
1314,
781,
3913,
1255,
737,
314,
2011,
4350,
315,
9861,
272,
14295,
63,
5054,
275,
334,
267,
950,
83,
14,
17179,
63,
14546,
14,
11060,
12,
267,
950,
83,
14,
17179,
63,
14546,
14,
2379,
63,
13605,
12,
267,
950,
83,
14,
17179,
63,
14546,
14,
3958,
63,
5418,
12,
267,
327,
6944,
8,
18865,
304,
5013,
14068,
1443,
4409,
3380,
295,
13605,
267,
327,
880,
652,
1159,
1415,
370,
7981,
316,
9861,
14295,
267,
950,
83,
14,
17179,
63,
14546,
14,
932,
63,
14281,
9,
339,
768,
3744,
272,
347,
1104,
63,
889,
63,
5720,
63,
13605,
8,
1886,
12,
4350,
304,
267,
6527,
63,
81,
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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
] |
pdinges/class-language
|
visitor/util.py
|
1
|
1477
|
# -*- coding: utf-8 -*-
# Copyright (c) 2008--2012 Peter Dinges <pdinges@acm.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 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/>.
class Enum(object):
"""
An Enum assigns integer values to string keys. The values are constant;
their keys are attributes to the Enum object. Enums are (namespaced)
lists to represent constants in the code.
"""
def __init__(self, entries):
val = 0
try:
for e in entries:
if isinstance(e, (tuple, list)) and len(e) >= 2:
key = str(e[0])
val = int(e[1])
else:
key = str(e)
val += 1
if val in self.__dict__.itervalues():
raise ValueError("Value '%i' for key '%s' is ambiguous." % (val, key))
self.__dict__[key] = val
except ValueError:
raise TypeError("Expecting a string as key and an integer as value.")
def __setattr__(self, key, val):
raise AttributeError("Enums are constant.")
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
9079,
306,
7409,
221,
22912,
577,
262,
3389,
665,
8961,
262,
3389,
32,
645,
77,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
533,
11305,
8,
785,
304,
199,
198,
624,
199,
198,
2493,
11305,
465,
20440,
3000,
1338,
370,
1059,
2883,
14,
221,
710,
1338,
787,
4413,
27,
199,
198,
1589,
723,
2883,
787,
3004,
370,
314,
11305,
909,
14,
221,
11305,
83,
787,
334,
19980,
9,
199,
198,
6717,
370,
2954,
5262,
315,
314,
1233,
14,
199,
198,
624,
199,
198,
318,
636,
826,
721,
277,
12,
4811,
304,
507,
198,
637,
275,
378,
507,
198,
893,
26,
686,
198,
509,
325,
315,
4811,
26,
1585,
198,
692,
1228,
8,
69,
12,
334,
2960,
12,
769,
430,
436,
822,
8,
69,
9,
2356,
499,
26,
1871,
198,
498,
275,
620,
8,
69,
59,
16,
566,
1871,
198,
637,
275,
1109,
8,
69,
59,
17,
566,
1585,
198,
2836,
26,
1871,
198,
498,
275,
620,
8,
69,
9,
1871,
198,
637,
847,
413,
1871,
1585,
198,
692,
1139,
315,
291,
855,
807,
4343,
13012,
837,
1871,
198,
3730,
1722,
480,
1110,
1543,
73,
7,
367,
790,
1543,
83,
7,
365,
26711,
2122,
450,
334,
637,
12,
790,
430,
1585,
198,
277,
855,
807,
12298,
498,
61,
275,
1139,
1871,
507,
198,
2590,
1722,
26,
686,
198,
3730,
3146,
480,
28864,
282,
1059,
465,
790,
436,
376,
3000,
465,
574,
2685,
421,
198,
318,
636,
10202,
721,
277,
12,
790,
12,
1139,
304,
507,
198,
3730,
4281,
480,
5081,
83,
787,
4413,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
9079,
306,
7409,
221,
22912,
577,
262,
3389,
665,
8961,
262,
3389,
32,
645,
77,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
533,
11305,
8,
785,
304,
199,
198,
624,
199,
198,
2493,
11305,
465,
20440,
3000,
1338,
370,
1059,
2883,
14,
221,
710,
1338,
787,
4413,
27,
199,
198,
1589,
723,
2883,
787,
3004,
370,
314,
11305,
909,
14,
221,
11305,
83,
787,
334,
19980,
9,
199,
198,
6717,
370,
2954,
5262,
315,
314,
1233,
14,
199,
198,
624,
199,
198,
318,
636,
826,
721,
277,
12,
4811,
304,
507,
198,
637,
275,
378,
507,
198,
893,
26,
686,
198,
509,
325,
315,
4811,
26,
1585,
198,
692,
1228,
8,
69,
12,
334,
2960,
12,
769,
430,
436,
822,
8,
69,
9,
2356,
499,
26,
1871,
198,
498,
275,
620,
8,
69,
59,
16,
566,
1871,
198,
637,
275,
1109,
8,
69,
59,
17,
566,
1585,
198,
2836,
26,
1871,
198,
498,
275,
620,
8,
69,
9,
1871,
198,
637,
847,
413,
1871,
1585,
198,
692,
1139,
315,
291,
855,
807,
4343,
13012,
837,
1871,
198,
3730,
1722,
480,
1110,
1543,
73,
7,
367,
790,
1543,
83,
7,
365,
26711,
2122,
450,
334,
637,
12,
790,
430,
1585,
198,
277,
855,
807,
12298,
498,
61,
275,
1139,
1871,
507,
198,
2590,
1722,
26,
686,
198,
3730,
3146,
480,
28864,
282,
1059,
465,
790,
436,
376,
3000,
465,
574,
2685,
421,
198,
318,
636,
10202,
721,
277,
12,
790,
12,
1139,
304,
507,
198,
3730,
4281,
480,
5081,
83,
787,
4413,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
whitlockjc/kubernetes
|
hack/boilerplate/boilerplate_test.py
|
629
|
1362
|
#!/usr/bin/env python
# Copyright 2016 The Kubernetes 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.
import boilerplate
import unittest
import StringIO
import os
import sys
class TestBoilerplate(unittest.TestCase):
"""
Note: run this test from the hack/boilerplate directory.
$ python -m unittest boilerplate_test
"""
def test_boilerplate(self):
os.chdir("test/")
class Args(object):
def __init__(self):
self.filenames = []
self.rootdir = "."
self.boilerplate_dir = "../"
self.verbose = True
# capture stdout
old_stdout = sys.stdout
sys.stdout = StringIO.StringIO()
boilerplate.args = Args()
ret = boilerplate.main()
output = sorted(sys.stdout.getvalue().split())
sys.stdout = old_stdout
self.assertEquals(
output, ['././fail.go', '././fail.py'])
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
7800,
710,
28723,
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,
646,
1234,
27025,
199,
646,
2882,
199,
646,
5228,
199,
646,
747,
199,
646,
984,
199,
199,
533,
1379,
2208,
27025,
8,
2796,
14,
1746,
304,
523,
408,
523,
3390,
26,
1255,
642,
511,
687,
314,
11176,
15,
656,
27025,
2082,
14,
819,
2672,
2366,
446,
77,
2882,
1234,
27025,
63,
396,
523,
408,
819,
347,
511,
63,
656,
27025,
8,
277,
304,
272,
747,
14,
8563,
480,
396,
13589,
339,
1021,
3033,
8,
785,
304,
489,
347,
636,
826,
721,
277,
304,
267,
291,
14,
10309,
275,
942,
267,
291,
14,
1231,
694,
275,
14530,
267,
291,
14,
656,
27025,
63,
694,
275,
29024,
2,
267,
291,
14,
3832,
275,
715,
339,
327,
12296,
3839,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
14,
6424,
342,
339,
1234,
27025,
14,
589,
275,
3033,
342,
272,
2203,
275,
1234,
27025,
14,
973,
342,
339,
1072,
275,
3355,
8,
1274,
14,
2703,
14,
7150,
1252,
1294,
1012,
339,
984,
14,
2703,
275,
2269,
63,
2703,
339,
291,
14,
2947,
8,
267,
1072,
12,
18953,
8083,
15,
1633,
14,
1939,
297,
1987,
8083,
15,
1633,
14,
647,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
7800,
710,
28723,
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,
646,
1234,
27025,
199,
646,
2882,
199,
646,
5228,
199,
646,
747,
199,
646,
984,
199,
199,
533,
1379,
2208,
27025,
8,
2796,
14,
1746,
304,
523,
408,
523,
3390,
26,
1255,
642,
511,
687,
314,
11176,
15,
656,
27025,
2082,
14,
819,
2672,
2366,
446,
77,
2882,
1234,
27025,
63,
396,
523,
408,
819,
347,
511,
63,
656,
27025,
8,
277,
304,
272,
747,
14,
8563,
480,
396,
13589,
339,
1021,
3033,
8,
785,
304,
489,
347,
636,
826,
721,
277,
304,
267,
291,
14,
10309,
275,
942,
267,
291,
14,
1231,
694,
275,
14530,
267,
291,
14,
656,
27025,
63,
694,
275,
29024,
2,
267,
291,
14,
3832,
275,
715,
339,
327,
12296,
3839,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
14,
6424,
342,
339,
1234,
27025,
14,
589,
275,
3033,
342,
272,
2203,
275,
1234,
27025,
14,
973,
342,
339,
1072,
275,
3355,
8,
1274,
14,
2703,
14,
7150,
1252,
1294,
1012,
339,
984,
14,
2703,
275,
2269,
63,
2703,
339,
291,
14,
2947,
8,
267,
1072,
12,
18953,
8083,
15,
1633,
14,
1939,
297,
1987,
8083,
15,
1633,
14,
647,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
ormnv/os_final_project
|
django/db/backends/oracle/compiler.py
|
112
|
2995
|
from django.db.models.sql import compiler
# The izip_longest was renamed to zip_longest in py3
try:
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest
class SQLCompiler(compiler.SQLCompiler):
def resolve_columns(self, row, fields=()):
# If this query has limit/offset information, then we expect the
# first column to be an extra "_RN" column that we need to throw
# away.
if self.query.high_mark is not None or self.query.low_mark:
rn_offset = 1
else:
rn_offset = 0
index_start = rn_offset + len(self.query.extra_select)
values = [self.query.convert_values(v, None, connection=self.connection)
for v in row[rn_offset:index_start]]
for value, field in zip_longest(row[index_start:], fields):
values.append(self.query.convert_values(value, field, connection=self.connection))
return tuple(values)
def as_sql(self, with_limits=True, with_col_aliases=False):
"""
Creates the SQL for this query. Returns the SQL string and list
of parameters. This is overriden from the original Query class
to handle the additional SQL Oracle requires to emulate LIMIT
and OFFSET.
If 'with_limits' is False, any limit/offset information is not
included in the query.
"""
if with_limits and self.query.low_mark == self.query.high_mark:
return '', ()
# The `do_offset` flag indicates whether we need to construct
# the SQL needed to use limit/offset with Oracle.
do_offset = with_limits and (self.query.high_mark is not None
or self.query.low_mark)
if not do_offset:
sql, params = super(SQLCompiler, self).as_sql(with_limits=False,
with_col_aliases=with_col_aliases)
else:
sql, params = super(SQLCompiler, self).as_sql(with_limits=False,
with_col_aliases=True)
# Wrap the base query in an outer SELECT * with boundaries on
# the "_RN" column. This is the canonical way to emulate LIMIT
# and OFFSET on Oracle.
high_where = ''
if self.query.high_mark is not None:
high_where = 'WHERE ROWNUM <= %d' % (self.query.high_mark,)
sql = 'SELECT * FROM (SELECT ROWNUM AS "_RN", "_SUB".* FROM (%s) "_SUB" %s) WHERE "_RN" > %d' % (sql, high_where, self.query.low_mark)
return sql, params
class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler):
pass
class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
pass
class SQLUpdateCompiler(compiler.SQLUpdateCompiler, SQLCompiler):
pass
class SQLAggregateCompiler(compiler.SQLAggregateCompiler, SQLCompiler):
pass
class SQLDateCompiler(compiler.SQLDateCompiler, SQLCompiler):
pass
|
bsd-3-clause
|
[
504,
1639,
14,
697,
14,
992,
14,
3009,
492,
6365,
199,
3,
710,
28697,
63,
20820,
1990,
17864,
370,
3482,
63,
20820,
315,
1134,
19,
199,
893,
26,
272,
687,
7975,
492,
3482,
63,
20820,
199,
2590,
3545,
26,
272,
687,
7975,
492,
28697,
63,
20820,
465,
3482,
63,
20820,
421,
199,
533,
5385,
9131,
8,
5772,
14,
4657,
9131,
304,
272,
347,
7512,
63,
3406,
8,
277,
12,
1962,
12,
1504,
23603,
267,
327,
982,
642,
1827,
965,
2304,
15,
2743,
2556,
12,
2066,
781,
4282,
314,
267,
327,
1642,
2763,
370,
506,
376,
2402,
2668,
15303,
2,
2763,
626,
781,
1929,
370,
7978,
267,
327,
13437,
14,
267,
340,
291,
14,
1131,
14,
6260,
63,
1657,
365,
440,
488,
503,
291,
14,
1131,
14,
674,
63,
1657,
26,
288,
519,
78,
63,
2743,
275,
413,
267,
587,
26,
288,
519,
78,
63,
2743,
275,
378,
267,
1478,
63,
928,
275,
519,
78,
63,
2743,
435,
822,
8,
277,
14,
1131,
14,
2911,
63,
2416,
9,
267,
1338,
275,
359,
277,
14,
1131,
14,
3916,
63,
1459,
8,
86,
12,
488,
12,
1950,
29,
277,
14,
2105,
9,
2116,
367,
373,
315,
1962,
59,
11641,
63,
2743,
26,
1080,
63,
928,
2677,
267,
367,
574,
12,
901,
315,
3482,
63,
20820,
8,
1143,
59,
1080,
63,
928,
8429,
1504,
304,
288,
1338,
14,
740,
8,
277,
14,
1131,
14,
3916,
63,
1459,
8,
585,
12,
901,
12,
1950,
29,
277,
14,
2105,
430,
267,
372,
2008,
8,
1459,
9,
339,
347,
465,
63,
3009,
8,
277,
12,
543,
63,
9368,
29,
549,
12,
543,
63,
761,
63,
8602,
29,
797,
304,
267,
408,
267,
10560,
314,
5385,
367,
642,
1827,
14,
1803,
314,
5385,
1059,
436,
769,
267,
402,
2633,
14,
221,
961,
365,
1806,
25045,
687,
314,
3379,
8133,
1021,
267,
370,
2429,
314,
4722,
5385,
15309,
5074,
370,
31102,
5138,
267,
436,
32633,
3597,
14,
398,
982,
283,
1045,
63,
9368,
7,
365,
756,
12,
1263,
2304,
15,
2743,
2556,
365,
440,
267,
5120,
315,
314,
1827,
14,
267,
408,
267,
340,
543,
63,
9368,
436,
291,
14,
1131,
14,
674,
63,
1657,
508,
291,
14,
1131,
14,
6260,
63,
1657,
26,
288,
372,
3260,
6248,
398,
327,
710,
658,
1117,
63,
2743,
64,
3305,
9126,
3775,
781,
1929,
370,
6982,
267,
327,
314,
5385,
4346,
370,
675,
2304,
15,
2743,
543,
15309,
14,
267,
886,
63,
2743,
275,
543,
63,
9368,
436,
334,
277,
14,
1131,
14,
6260,
63,
1657,
365,
440,
488,
3660,
503,
291,
14,
1131,
14,
674,
63,
1657,
9,
267,
340,
440,
886,
63,
2743,
26,
288,
3875,
12,
1862,
275,
1613,
8,
4657,
9131,
12,
291,
680,
305,
63,
3009,
8,
1045,
63,
9368,
29,
797,
12,
490,
543,
63,
761,
63,
8602,
29,
1045,
63,
761,
63,
8602,
9,
267,
587,
26,
288,
3875,
12,
1862,
275,
1613,
8,
4657,
9131,
12,
291,
680,
305,
63,
3009,
8,
1045,
63,
9368,
29,
797,
12,
8105,
543,
63,
761,
63,
8602,
29,
549,
9,
953,
327,
20322,
314,
1300,
1827,
315,
376,
6890,
10468,
627,
543,
18135,
641,
288,
327,
314,
2668,
15303,
2,
2763,
14,
221,
961,
365,
314,
11358,
4340,
370,
31102,
5138,
288,
327,
436,
32633,
3597,
641,
15309,
14,
288,
4721,
63,
4509,
275,
2125,
288,
340,
291,
14,
1131,
14,
6260,
63,
1657,
365,
440,
488,
26,
355,
4721,
63,
4509,
275,
283,
17688,
9769,
55,
7125,
2695,
450,
68,
7,
450,
334,
277,
14,
1131,
14,
6260,
63,
1657,
4258,
288,
3875,
275,
283,
4859,
627,
4442,
334,
4859,
9769,
55,
7125,
4319,
2668,
15303,
401,
2668,
6348,
1674,
10,
4442,
4366,
83,
9,
2668,
6348,
2,
450,
83,
9,
6038,
2668,
15303,
2,
690,
450,
68,
7,
450,
334,
3009,
12,
4721,
63,
4509,
12,
291,
14,
1131,
14,
674,
63,
1657,
9,
398,
372,
3875,
12,
1862,
421,
199,
533,
5385,
9971,
9131,
8,
5772,
14,
4657,
9971,
9131,
12,
5385,
9131,
304,
272,
986,
199,
199,
533,
5385,
5392,
9131,
8,
5772,
14,
4657,
5392,
9131,
12,
5385,
9131,
304,
272,
986,
199,
199,
533,
5385,
4152,
9131,
8,
5772,
14,
4657,
4152,
9131,
12,
5385,
9131,
304,
272,
986,
199,
199,
533,
5385,
10170,
9131,
8,
5772,
14,
4657,
10170,
9131,
12,
5385,
9131,
304,
272,
986,
199,
199,
533,
5385,
2506,
9131,
8,
5772,
14,
4657,
2506,
9131,
12,
5385,
9131,
304,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
697,
14,
992,
14,
3009,
492,
6365,
199,
3,
710,
28697,
63,
20820,
1990,
17864,
370,
3482,
63,
20820,
315,
1134,
19,
199,
893,
26,
272,
687,
7975,
492,
3482,
63,
20820,
199,
2590,
3545,
26,
272,
687,
7975,
492,
28697,
63,
20820,
465,
3482,
63,
20820,
421,
199,
533,
5385,
9131,
8,
5772,
14,
4657,
9131,
304,
272,
347,
7512,
63,
3406,
8,
277,
12,
1962,
12,
1504,
23603,
267,
327,
982,
642,
1827,
965,
2304,
15,
2743,
2556,
12,
2066,
781,
4282,
314,
267,
327,
1642,
2763,
370,
506,
376,
2402,
2668,
15303,
2,
2763,
626,
781,
1929,
370,
7978,
267,
327,
13437,
14,
267,
340,
291,
14,
1131,
14,
6260,
63,
1657,
365,
440,
488,
503,
291,
14,
1131,
14,
674,
63,
1657,
26,
288,
519,
78,
63,
2743,
275,
413,
267,
587,
26,
288,
519,
78,
63,
2743,
275,
378,
267,
1478,
63,
928,
275,
519,
78,
63,
2743,
435,
822,
8,
277,
14,
1131,
14,
2911,
63,
2416,
9,
267,
1338,
275,
359,
277,
14,
1131,
14,
3916,
63,
1459,
8,
86,
12,
488,
12,
1950,
29,
277,
14,
2105,
9,
2116,
367,
373,
315,
1962,
59,
11641,
63,
2743,
26,
1080,
63,
928,
2677,
267,
367,
574,
12,
901,
315,
3482,
63,
20820,
8,
1143,
59,
1080,
63,
928,
8429,
1504,
304,
288,
1338,
14,
740,
8,
277,
14,
1131,
14,
3916,
63,
1459,
8,
585,
12,
901,
12,
1950,
29,
277,
14,
2105,
430,
267,
372,
2008,
8,
1459,
9,
339,
347,
465,
63,
3009,
8,
277,
12,
543,
63,
9368,
29,
549,
12,
543,
63,
761,
63,
8602,
29,
797,
304,
267,
408,
267,
10560,
314,
5385,
367,
642,
1827,
14,
1803,
314,
5385,
1059,
436,
769,
267,
402,
2633,
14,
221,
961,
365,
1806,
25045,
687,
314,
3379,
8133,
1021,
267,
370,
2429,
314,
4722,
5385,
15309,
5074,
370,
31102,
5138,
267,
436,
32633,
3597,
14,
398,
982,
283,
1045,
63,
9368,
7,
365,
756,
12,
1263,
2304,
15,
2743,
2556,
365,
440,
267,
5120,
315,
314,
1827,
14,
267,
408,
267,
340,
543,
63,
9368,
436,
291,
14,
1131,
14,
674,
63,
1657,
508,
291,
14,
1131,
14,
6260,
63,
1657,
26,
288,
372,
3260,
6248,
398,
327,
710,
658,
1117,
63,
2743,
64,
3305,
9126,
3775,
781,
1929,
370,
6982,
267,
327,
314,
5385,
4346,
370,
675,
2304,
15,
2743,
543,
15309,
14,
267,
886,
63,
2743,
275,
543,
63,
9368,
436,
334,
277,
14,
1131,
14,
6260,
63,
1657,
365,
440,
488,
3660,
503,
291,
14,
1131,
14,
674,
63,
1657,
9,
267,
340,
440,
886,
63,
2743,
26,
288,
3875,
12,
1862,
275,
1613,
8,
4657,
9131,
12,
291,
680,
305,
63,
3009,
8,
1045,
63,
9368,
29,
797,
12,
490,
543,
63,
761,
63,
8602,
29,
1045,
63,
761,
63,
8602,
9,
267,
587,
26,
288,
3875,
12,
1862,
275,
1613,
8,
4657,
9131,
12,
291,
680,
305,
63,
3009,
8,
1045,
63,
9368,
29,
797,
12,
8105,
543,
63,
761,
63,
8602,
29,
549,
9,
953,
327,
20322,
314,
1300,
1827,
315,
376,
6890,
10468,
627,
543,
18135,
641,
288,
327,
314,
2668,
15303,
2,
2763,
14,
221,
961,
365,
314,
11358,
4340,
370,
31102,
5138,
288,
327,
436,
32633,
3597,
641,
15309,
14,
288,
4721,
63,
4509,
275,
2125,
288,
340,
291,
14,
1131,
14,
6260,
63,
1657,
365,
440,
488,
26,
355,
4721,
63,
4509,
275,
283,
17688,
9769,
55,
7125,
2695,
450,
68,
7,
450,
334,
277,
14,
1131,
14,
6260,
63,
1657,
4258,
288,
3875,
275,
283,
4859,
627,
4442,
334,
4859,
9769,
55,
7125,
4319,
2668,
15303,
401,
2668,
6348,
1674,
10,
4442,
4366,
83,
9,
2668,
6348,
2,
450,
83,
9,
6038,
2668,
15303,
2,
690,
450,
68,
7,
450,
334,
3009,
12,
4721,
63,
4509,
12,
291,
14,
1131,
14,
674,
63,
1657,
9,
398,
372,
3875,
12,
1862,
421,
199,
533,
5385,
9971,
9131,
8,
5772,
14,
4657,
9971,
9131,
12,
5385,
9131,
304,
272,
986,
199,
199,
533,
5385,
5392,
9131,
8,
5772,
14,
4657,
5392,
9131,
12,
5385,
9131,
304,
272,
986,
199,
199,
533,
5385,
4152,
9131,
8,
5772,
14,
4657,
4152,
9131,
12,
5385,
9131,
304,
272,
986,
199,
199,
533,
5385,
10170,
9131,
8,
5772,
14,
4657,
10170,
9131,
12,
5385,
9131,
304,
272,
986,
199,
199,
533,
5385,
2506,
9131,
8,
5772,
14,
4657,
2506,
9131,
12,
5385,
9131,
304,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mhaberler/machinekit
|
src/machinetalk/messagebus/python-mockup/commandsubmitter.py
|
10
|
2369
|
import os, time
import zmq
from machinetalk.protobuf.message_pb2 import Container
from machinetalk.protobuf.types_pb2 import *
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-c", "--cmd", dest="cmduri", default="tcp://127.0.0.1:5571",
help="command URI")
parser.add_option("-r", "--response", dest="responseuri",
default="tcp://127.0.0.1:5573",
help="response URI")
parser.add_option("-n", "--name", dest="actor", default="task",
help="use this as actor name")
parser.add_option("-d", "--destination", dest="destination", default="component",
help="use this actor as command destination")
parser.add_option("-b", "--batch", dest="batch", default=1,type="int",
help="use this actor as command destination")
parser.add_option("-i", "--iterations", dest="iter", default=1,type="int",
help="to run main loop")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
help="print actions as they happen")
parser.add_option("-F", "--fast", action="store_true", dest="fast",
help="do not sleep after an iteration")
(options, args) = parser.parse_args()
me = options.actor
context = zmq.Context()
cmd = context.socket(zmq.XSUB)
cmd.connect(options.cmduri)
# subscribe XSUB-style by sending a message \001<topic>
cmd.send("\001%s" % (me))
response = context.socket(zmq.XSUB)
response.connect(options.responseuri)
response.send("\001%s" % (me))
i = 0
tx = Container()
rx = Container()
tx.type = MT_EMCMOT_SET_LINE
c = tx.SerializeToString()
time.sleep(1) # let subscriptions stabilize
for j in range(options.iter):
for n in range(options.batch):
msg = "cmd %d" % i
i += 1
mp = [me, options.destination,msg,c, c]
if options.verbose:
print "---%s msg %s" % (me,mp)
cmd.send_multipart(mp)
for n in range(options.batch):
msg = response.recv_multipart()
if options.verbose:
#print "---%s receive response: %s" %(me, msg)
print "---%s receive response: %s" %(me, msg)
for m in msg[3:]:
rx.ParseFromString(m)
print str(rx)
if not options.fast:
time.sleep(1)
time.sleep(1)
context.destroy(linger=0)
|
lgpl-2.1
|
[
646,
747,
12,
900,
199,
646,
26633,
199,
504,
14401,
10811,
4878,
14,
7204,
14,
1188,
63,
3317,
18,
492,
15395,
199,
504,
14401,
10811,
4878,
14,
7204,
14,
1313,
63,
3317,
18,
492,
627,
199,
504,
8691,
492,
13491,
199,
199,
2087,
275,
13491,
342,
199,
199,
2087,
14,
525,
63,
1422,
6096,
67,
401,
4320,
1760,
401,
2053,
628,
1760,
2302,
401,
849,
628,
8815,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1229,
3172,
401,
2116,
1720,
628,
1531,
9022,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
82,
401,
4320,
1310,
401,
2053,
628,
1310,
2302,
401,
2116,
849,
628,
8815,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1229,
2898,
401,
2116,
1720,
628,
1310,
9022,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
78,
401,
4320,
354,
401,
2053,
628,
5021,
401,
849,
628,
1765,
401,
2116,
1720,
628,
1180,
642,
465,
20318,
536,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
68,
401,
4320,
6881,
401,
2053,
628,
6881,
401,
849,
628,
3173,
401,
2116,
1720,
628,
1180,
642,
20318,
465,
1414,
5724,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
66,
401,
4320,
2912,
401,
2053,
628,
2912,
401,
849,
29,
17,
12,
466,
628,
442,
401,
2116,
1720,
628,
1180,
642,
20318,
465,
1414,
5724,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
73,
401,
4320,
13570,
401,
2053,
628,
1661,
401,
849,
29,
17,
12,
466,
628,
442,
401,
2116,
1720,
628,
475,
1255,
2446,
4438,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
3832,
401,
2116,
1720,
628,
1361,
5445,
465,
2985,
5992,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
38,
401,
4320,
7015,
401,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
7015,
401,
2116,
1720,
628,
1117,
440,
9435,
2410,
376,
8494,
531,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
278,
275,
1511,
14,
5021,
199,
199,
1100,
275,
26633,
14,
2998,
342,
199,
199,
1760,
275,
1067,
14,
3450,
8,
21290,
14,
56,
6348,
9,
199,
1760,
14,
2242,
8,
1419,
14,
1760,
2302,
9,
199,
3,
23421,
1323,
6348,
13,
2487,
701,
10209,
282,
1245,
221,
971,
4587,
28,
5746,
30,
199,
1760,
14,
2254,
4582,
4587,
5,
83,
2,
450,
334,
278,
430,
199,
199,
1310,
275,
1067,
14,
3450,
8,
21290,
14,
56,
6348,
9,
199,
1310,
14,
2242,
8,
1419,
14,
1310,
2302,
9,
199,
1310,
14,
2254,
4582,
4587,
5,
83,
2,
450,
334,
278,
430,
421,
199,
73,
275,
378,
199,
2347,
275,
15395,
342,
199,
6872,
275,
15395,
342,
199,
2347,
14,
466,
275,
603,
52,
63,
2769,
9249,
1387,
63,
3597,
63,
6174,
199,
199,
67,
275,
4773,
14,
9436,
342,
199,
199,
521,
14,
4532,
8,
17,
9,
327,
4691,
25708,
410,
25007,
806,
199,
509,
1335,
315,
1425,
8,
1419,
14,
1661,
304,
339,
367,
302,
315,
1425,
8,
1419,
14,
2912,
304,
267,
1499,
275,
298,
1760,
450,
68,
2,
450,
284,
267,
284,
847,
413,
267,
6118,
275,
359,
278,
12,
1511,
14,
6881,
12,
1328,
12,
67,
12,
286,
61,
267,
340,
1511,
14,
3832,
26,
288,
870,
298,
2595,
5,
83,
1499,
450,
83,
2,
450,
334,
278,
12,
311,
9,
267,
2088,
14,
2254,
63,
10123,
8,
311,
9,
339,
367,
302,
315,
1425,
8,
1419,
14,
2912,
304,
267,
1499,
275,
1177,
14,
7637,
63,
10123,
342,
267,
340,
1511,
14,
3832,
26,
953,
327,
1361,
298,
2595,
5,
83,
9128,
1177,
26,
450,
83,
2,
2818,
278,
12,
1499,
9,
288,
870,
298,
2595,
5,
83,
9128,
1177,
26,
450,
83,
2,
2818,
278,
12,
1499,
9,
288,
367,
333,
315,
1499,
59,
19,
10688,
355,
12951,
14,
28685,
8,
77,
9,
355,
870,
620,
8,
6872,
9,
272,
340,
440,
1511,
14,
7015,
26,
267,
900,
14,
4532,
8,
17,
9,
199,
199,
521,
14,
4532,
8,
17,
9,
199,
1100,
14,
7237,
8,
2983,
281,
29,
16,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
12,
900,
199,
646,
26633,
199,
504,
14401,
10811,
4878,
14,
7204,
14,
1188,
63,
3317,
18,
492,
15395,
199,
504,
14401,
10811,
4878,
14,
7204,
14,
1313,
63,
3317,
18,
492,
627,
199,
504,
8691,
492,
13491,
199,
199,
2087,
275,
13491,
342,
199,
199,
2087,
14,
525,
63,
1422,
6096,
67,
401,
4320,
1760,
401,
2053,
628,
1760,
2302,
401,
849,
628,
8815,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1229,
3172,
401,
2116,
1720,
628,
1531,
9022,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
82,
401,
4320,
1310,
401,
2053,
628,
1310,
2302,
401,
2116,
849,
628,
8815,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1229,
2898,
401,
2116,
1720,
628,
1310,
9022,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
78,
401,
4320,
354,
401,
2053,
628,
5021,
401,
849,
628,
1765,
401,
2116,
1720,
628,
1180,
642,
465,
20318,
536,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
68,
401,
4320,
6881,
401,
2053,
628,
6881,
401,
849,
628,
3173,
401,
2116,
1720,
628,
1180,
642,
20318,
465,
1414,
5724,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
66,
401,
4320,
2912,
401,
2053,
628,
2912,
401,
849,
29,
17,
12,
466,
628,
442,
401,
2116,
1720,
628,
1180,
642,
20318,
465,
1414,
5724,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
73,
401,
4320,
13570,
401,
2053,
628,
1661,
401,
849,
29,
17,
12,
466,
628,
442,
401,
2116,
1720,
628,
475,
1255,
2446,
4438,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
3832,
401,
2116,
1720,
628,
1361,
5445,
465,
2985,
5992,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
38,
401,
4320,
7015,
401,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
7015,
401,
2116,
1720,
628,
1117,
440,
9435,
2410,
376,
8494,
531,
199,
199,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
278,
275,
1511,
14,
5021,
199,
199,
1100,
275,
26633,
14,
2998,
342,
199,
199,
1760,
275,
1067,
14,
3450,
8,
21290,
14,
56,
6348,
9,
199,
1760,
14,
2242,
8,
1419,
14,
1760,
2302,
9,
199,
3,
23421,
1323,
6348,
13,
2487,
701,
10209,
282,
1245,
221,
971,
4587,
28,
5746,
30,
199,
1760,
14,
2254,
4582,
4587,
5,
83,
2,
450,
334,
278,
430,
199,
199,
1310,
275,
1067,
14,
3450,
8,
21290,
14,
56,
6348,
9,
199,
1310,
14,
2242,
8,
1419,
14,
1310,
2302,
9,
199,
1310,
14,
2254,
4582,
4587,
5,
83,
2,
450,
334,
278,
430,
421,
199,
73,
275,
378,
199,
2347,
275,
15395,
342,
199,
6872,
275,
15395,
342,
199,
2347,
14,
466,
275,
603,
52,
63,
2769,
9249,
1387,
63,
3597,
63,
6174,
199,
199,
67,
275,
4773,
14,
9436,
342,
199,
199,
521,
14,
4532,
8,
17,
9,
327,
4691,
25708,
410,
25007,
806,
199,
509,
1335,
315,
1425,
8,
1419,
14,
1661,
304,
339,
367,
302,
315,
1425,
8,
1419,
14,
2912,
304,
267,
1499,
275,
298,
1760,
450,
68,
2,
450,
284,
267,
284,
847,
413,
267,
6118,
275,
359,
278,
12,
1511,
14,
6881,
12,
1328,
12,
67,
12,
286,
61,
267,
340,
1511,
14,
3832,
26,
288,
870,
298,
2595,
5,
83,
1499,
450,
83,
2,
450,
334,
278,
12,
311,
9,
267,
2088,
14,
2254,
63,
10123,
8,
311,
9,
339,
367,
302,
315,
1425,
8,
1419,
14,
2912,
304,
267,
1499,
275,
1177,
14,
7637,
63,
10123,
342,
267,
340,
1511,
14,
3832,
26,
953,
327,
1361,
298,
2595,
5,
83,
9128,
1177,
26,
450,
83,
2,
2818,
278,
12,
1499,
9,
288,
870,
298,
2595,
5,
83,
9128,
1177,
26,
450,
83,
2,
2818,
278,
12,
1499,
9,
288,
367,
333,
315,
1499,
59,
19,
10688,
355,
12951,
14,
28685,
8,
77,
9,
355,
870,
620,
8,
6872,
9,
272,
340,
440,
1511,
14,
7015,
26,
267,
900,
14,
4532,
8,
17,
9,
199,
199,
521,
14,
4532,
8,
17,
9,
199,
1100,
14,
7237,
8,
2983,
281,
29,
16,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rolandovillca/python_basic_introduction
|
web/client_post_with_urllib2.py
|
4
|
9620
|
'''
urllib2 - Library for opening URLs
A library for opening URLs that can be extended by defining custom protocol
handlers.
The urllib2 module defines functions and classes which help in opening URLs
(mostly HTTP) in a complex world - basic and digest authentication,
redirections, cookies and more.
The urllib2 module provides an updated API for using internet resources
identified by URLs. It is designed to be extended by individual applications to
support new protocols or add variations to existing protocols (such as handling
HTTP basic authentication).
https://pymotw.com/2/urllib2/
'''
import urllib
import urllib2
# EXAMPLE 1: HTTP POST:
# ==============================================================================
# To POST form-encoded data to the remote server, instead of using GET, pass the
# encoded query arguments as data to urlopen().
query_args = { 'q':'query string', 'foo':'bar' }
encoded_args = urllib.urlencode(query_args)
url = 'http://localhost:8080/'
print urllib2.urlopen(url, encoded_args).read()
# EXAMPLE 2: Working with Requests Directly:
# ==============================================================================
# urlopen() is a convenience function that hides some of the details of how the
# request is made and handled for you. For more precise control, you may want to
# instantiate and use a Request object directly.
# EXAMPLE 3: Adding Outgoing Headers:
# ==============================================================================
# As the examples above illustrate, the default User-agent header value is made
# up of the constant Python-urllib, followed by the Python interpreter version.
# If you are creating an application that will access other people’s web
# resources, it is courteous to include real user agent information in your
# requests, so they can identify the source of the hits more easily. Using a
# custom agent also allows them to control crawlers using a robots.txt file
# (see robotparser).
import urllib2
request = urllib2.Request('http://localhost:8080/')
request.add_header('User-agent', 'PyMOTW (http://www.doughellmann.com/PyMOTW/)')
response = urllib2.urlopen(request)
data = response.read()
print data
# EXAMPLE 4: Posting Form Data:
# ==============================================================================
# You can set the outgoing data on the Request to post it to the server.
import urllib
import urllib2
query_args = { 'q':'query string', 'foo':'bar' }
request = urllib2.Request('http://localhost:8080/')
print 'Request method before data:', request.get_method()
request.add_data(urllib.urlencode(query_args))
print 'Request method after data :', request.get_method()
request.add_header('User-agent', 'PyMOTW (http://www.doughellmann.com/PyMOTW/)')
print
print 'OUTGOING DATA:'
print request.get_data()
print
print 'SERVER RESPONSE:'
print urllib2.urlopen(request).read()
# EXAMPLE 5: Uploading Files:
# ==============================================================================
# Encoding files for upload requires a little more work than simple forms.
# A complete MIME message needs to be constructed in the body of the request,
# so that the server can distinguish incoming form fields from uploaded files.
import itertools
import mimetools
import mimetypes
from cStringIO import StringIO
import urllib
import urllib2
class MultiPartForm(object):
'''Accumulate the data to be used when posting a form.'''
def __init__(self):
self.form_fields = []
self.files = []
self.boundary = mimetools.choose_boundary()
return
def get_content_type(self):
return 'multipart/form-data; boundary=%s' % self.boundary
def add_field(self, name, value):
"""Add a simple field to the form data."""
self.form_fields.append((name, value))
return
def add_file(self, fieldname, filename, fileHandle, mimetype=None):
"""Add a file to be uploaded."""
body = fileHandle.read()
if mimetype is None:
mimetype = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
self.files.append((fieldname, filename, mimetype, body))
return
def __str__(self):
'''Return a string representing the form data, including attached files.'''
# Build a list of lists, each containing "lines" of the
# request. Each part is separated by a boundary string.
# Once the list is built, return a string where each
# line is separated by '\r\n'.
parts = []
part_boundary = '--' + self.boundary
# Add the form fields
parts.extend(
[ part_boundary,
'Content-Disposition: form-data; name="%s"' % name,
'',
value,
]
for name, value in self.form_fields
)
# Add the files to upload
parts.extend(
[ part_boundary,
'Content-Disposition: file; name="%s"; filename="%s"' % \
(field_name, filename),
'Content-Type: %s' % content_type,
'',
body,
]
for field_name, filename, content_type, body in self.files
)
# Flatten the list and add closing boundary marker,
# then return CR+LF separated data
flattened = list(itertools.chain(*parts))
flattened.append('--' + self.boundary + '--')
flattened.append('')
return '\r\n'.join(flattened)
if __name__ == '__main__':
# Create the form with simple fields
form = MultiPartForm()
form.add_field('firstname', 'Doug')
form.add_field('lastname', 'Hellmann')
# Add a fake file
form.add_file('biography', 'bio.txt',
fileHandle=StringIO('Python developer and blogger.'))
# Build the request
request = urllib2.Request('http://localhost:8080/')
request.add_header('User-agent', 'PyMOTW (http://www.doughellmann.com/PyMOTW/)')
body = str(form)
request.add_header('Content-type', form.get_content_type())
request.add_header('Content-length', len(body))
request.add_data(body)
print
print 'OUTGOING DATA:'
print request.get_data()
print
print 'SERVER RESPONSE:'
print urllib2.urlopen(request).read()
# EXAMPLE 6: Custom Protocol Handlers:
# ==============================================================================
# urllib2 has built-in support for HTTP(S), FTP, and local file access.
# If you need to add support for other URL types, you can register your own
# protocol handler to be invoked as needed. For example, if you want to support
# URLs pointing to arbitrary files on remote NFS servers, without requiring your
# users to mount the path manually, would create a class derived from
# BaseHandler and with a method nfs_open().
# The protocol open() method takes a single argument, the Request instance, and
# it should return an object with a read() method that can be used to read the
# data, an info() method to return the response headers, and geturl() to return
# the actual URL of the file being read. A simple way to achieve that is to
# create an instance of urllib.addurlinfo, passing the headers, URL, and open
# file handle in to the constructor.
import mimetypes
import os
import tempfile
import urllib
import urllib2
class NFSFile(file):
def __init__(self, tempdir, filename):
self.tempdir = tempdir
file.__init__(self, filename, 'rb')
def close(self):
print
print 'NFSFile:'
print ' unmounting %s' % self.tempdir
print ' when %s is closed' % os.path.basename(self.name)
return file.close(self)
class FauxNFSHandler(urllib2.BaseHandler):
def __init__(self, tempdir):
self.tempdir = tempdir
def nfs_open(self, req):
url = req.get_selector()
directory_name, file_name = os.path.split(url)
server_name = req.get_host()
print
print 'FauxNFSHandler simulating mount:'
print ' Remote path: %s' % directory_name
print ' Server : %s' % server_name
print ' Local path : %s' % tempdir
print ' File name : %s' % file_name
local_file = os.path.join(tempdir, file_name)
fp = NFSFile(tempdir, local_file)
content_type = mimetypes.guess_type(file_name)[0] or 'application/octet-stream'
stats = os.stat(local_file)
size = stats.st_size
headers = { 'Content-type': content_type,
'Content-length': size,
}
return urllib.addinfourl(fp, headers, req.get_full_url())
if __name__ == '__main__':
tempdir = tempfile.mkdtemp()
try:
# Populate the temporary file for the simulation
with open(os.path.join(tempdir, 'file.txt'), 'wt') as f:
f.write('Contents of file.txt')
# Construct an opener with our NFS handler
# and register it as the default opener.
opener = urllib2.build_opener(FauxNFSHandler(tempdir))
urllib2.install_opener(opener)
# Open the file through a URL.
response = urllib2.urlopen('nfs://remote_server/path/to/the/file.txt')
print
print 'READ CONTENTS:', response.read()
print 'URL :', response.geturl()
print 'HEADERS:'
for name, value in sorted(response.info().items()):
print ' %-15s = %s' % (name, value)
response.close()
finally:
os.remove(os.path.join(tempdir, 'file.txt'))
os.removedirs(tempdir)
|
mit
|
[
2344,
199,
4078,
18,
446,
11243,
367,
13618,
10867,
199,
199,
33,
3555,
367,
13618,
10867,
626,
883,
506,
9243,
701,
12669,
3537,
4113,
199,
5586,
14,
199,
199,
1918,
4011,
18,
859,
7890,
3423,
436,
3992,
1314,
1720,
315,
13618,
10867,
199,
8,
2786,
590,
3101,
9,
315,
282,
6114,
6701,
446,
5678,
436,
10017,
6299,
12,
199,
264,
27917,
12,
10049,
436,
1655,
14,
199,
199,
1918,
4011,
18,
859,
6571,
376,
4588,
3261,
367,
1808,
21408,
5944,
199,
9281,
8981,
701,
10867,
14,
2779,
365,
19829,
370,
506,
9243,
701,
8212,
13103,
370,
199,
4058,
892,
19230,
503,
1050,
4172,
1298,
370,
3411,
19230,
334,
10180,
465,
7252,
199,
2856,
5678,
6299,
680,
199,
199,
2859,
921,
647,
30034,
87,
14,
957,
15,
18,
15,
4078,
18,
15,
199,
2344,
199,
199,
646,
4011,
199,
646,
4011,
18,
199,
199,
3,
3651,
10818,
413,
26,
3101,
8761,
26,
199,
3,
11148,
199,
3,
4005,
8761,
1824,
13,
8167,
666,
370,
314,
3982,
1654,
12,
3140,
402,
1808,
9576,
12,
986,
314,
199,
3,
5737,
1827,
2368,
465,
666,
370,
18279,
1252,
199,
199,
1131,
63,
589,
275,
469,
283,
81,
5242,
1131,
1059,
297,
283,
1421,
5242,
1700,
7,
789,
199,
8167,
63,
589,
275,
4011,
14,
10738,
8,
1131,
63,
589,
9,
199,
633,
275,
283,
1014,
921,
5967,
26,
15844,
4805,
199,
1361,
4011,
18,
14,
10890,
8,
633,
12,
5737,
63,
589,
680,
739,
342,
421,
199,
3,
3651,
10818,
499,
26,
9361,
316,
543,
20260,
21128,
590,
26,
199,
3,
11148,
199,
3,
18279,
342,
365,
282,
16777,
805,
626,
13714,
83,
2005,
402,
314,
2436,
402,
4212,
314,
199,
3,
1056,
365,
6326,
436,
8860,
367,
1265,
14,
2104,
1655,
28334,
3304,
12,
1265,
1443,
2934,
370,
199,
3,
17321,
436,
675,
282,
4784,
909,
5370,
14,
421,
199,
3,
3651,
10818,
650,
26,
12934,
6219,
10947,
21391,
26,
199,
3,
11148,
199,
3,
3709,
314,
7251,
3432,
22907,
11409,
323,
12,
314,
849,
2876,
13,
4054,
1406,
574,
365,
6326,
199,
3,
1536,
402,
314,
4413,
2018,
13,
4078,
12,
9437,
701,
314,
2018,
12693,
1015,
14,
199,
3,
982,
1265,
787,
6425,
376,
4223,
626,
911,
2879,
1163,
13135,
21045,
83,
3330,
199,
3,
5944,
12,
652,
365,
512,
300,
266,
1785,
370,
2387,
3363,
922,
6631,
2556,
315,
2195,
199,
3,
4145,
12,
880,
2985,
883,
10405,
314,
1350,
402,
314,
19745,
1655,
16174,
14,
11719,
282,
199,
3,
3537,
6631,
2597,
6127,
3062,
370,
3304,
29550,
83,
1808,
282,
14544,
83,
14,
2424,
570,
199,
3,
334,
3239,
14544,
2087,
680,
199,
199,
646,
4011,
18,
199,
199,
1069,
275,
4011,
18,
14,
2017,
360,
1014,
921,
5967,
26,
15844,
6217,
199,
1069,
14,
525,
63,
1291,
360,
1899,
13,
4054,
297,
283,
2713,
27235,
55,
334,
1014,
921,
1544,
14,
68,
4937,
1697,
20059,
14,
957,
15,
2713,
27235,
55,
15,
5942,
199,
199,
1310,
275,
4011,
18,
14,
10890,
8,
1069,
9,
199,
576,
275,
1177,
14,
739,
342,
199,
1361,
666,
421,
199,
3,
3651,
10818,
841,
26,
7711,
316,
8204,
3918,
26,
199,
3,
11148,
199,
3,
2047,
883,
663,
314,
21507,
666,
641,
314,
4784,
370,
2963,
652,
370,
314,
1654,
14,
199,
199,
646,
4011,
199,
646,
4011,
18,
199,
199,
1131,
63,
589,
275,
469,
283,
81,
5242,
1131,
1059,
297,
283,
1421,
5242,
1700,
7,
789,
199,
199,
1069,
275,
4011,
18,
14,
2017,
360,
1014,
921,
5967,
26,
15844,
6217,
199,
1361,
283,
2017,
1083,
2544,
666,
6536,
1056,
14,
362,
63,
765,
342,
199,
199,
1069,
14,
525,
63,
576,
8,
4078,
14,
10738,
8,
1131,
63,
589,
430,
199,
1361,
283,
2017,
1083,
2410,
666,
520,
297,
1056,
14,
362,
63,
765,
342,
199,
1069,
14,
525,
63,
1291,
360,
1899,
13,
4054,
297,
283,
2713,
27235,
55,
334,
1014,
921,
1544,
14,
68,
4937,
1697,
20059,
14,
957,
15,
2713,
27235,
55,
15,
5942,
199,
199,
1361,
199,
1361,
283,
1877,
13160,
1206,
7126,
4881,
199,
1361,
1056,
14,
362,
63,
576,
342,
199,
199,
1361,
199,
1361,
283,
6613,
820,
7613,
11827,
4881,
199,
1361,
4011,
18,
14,
10890,
8,
1069,
680,
739,
342,
421,
199,
3,
3651,
10818,
959,
26,
4949,
8786,
16920,
26,
199,
3,
11148,
199,
3,
19694,
1584,
367,
5802,
5074,
282,
12050,
1655,
1736,
2419,
3486,
4513,
14,
199,
3,
437,
4890,
14735,
1245,
4839,
370,
506,
14701,
315,
314,
2396,
402,
314,
1056,
12,
199,
3,
880,
626,
314,
1654,
883,
22237,
12467,
1824,
1504,
687,
14238,
1584,
14,
199,
199,
646,
7975,
199,
646,
6660,
2537,
199,
646,
13290,
199,
504,
15073,
492,
5228,
199,
646,
4011,
199,
646,
4011,
18,
199,
199,
533,
6879,
8416,
2821,
8,
785,
304,
272,
1449,
23384,
5434,
314,
666,
370,
506,
1202,
1380,
25386,
282,
1824,
10595,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
964,
63,
955,
275,
942,
267,
291,
14,
1725,
275,
942,
267,
291,
14,
9891,
275,
6660,
2537,
14,
16143,
63,
9891,
342,
267,
372,
2286,
347,
664,
63,
1317,
63,
466,
8,
277,
304,
267,
372,
283,
10123,
15,
964,
13,
576,
27,
8424,
2458,
83,
7,
450,
291,
14,
9891,
339,
347,
1050,
63,
698,
8,
277,
12,
536,
12,
574,
304,
267,
408,
1123,
282,
3486,
901,
370,
314,
1824,
666,
1041,
267,
291,
14,
964,
63,
955,
14,
740,
1332,
354,
12,
574,
430,
267,
372,
339,
347,
1050,
63,
493,
8,
277,
12,
18887,
12,
1788,
12,
570,
5940,
12,
12200,
29,
403,
304,
267,
408,
1123,
282,
570,
370,
506,
14238,
1041,
267,
2396,
275,
570,
5940,
14,
739,
342,
267,
340,
12200,
365,
488,
26,
288,
12200,
275,
13290,
14,
11636,
63,
466,
8,
1501,
2788,
16,
61,
503,
283,
3578,
15,
18162,
13,
1745,
7,
267,
291,
14,
1725,
14,
740,
1332,
13646,
12,
1788,
12,
12200,
12,
2396,
430,
267,
372,
2286,
347,
636,
495,
721,
277,
304,
267,
1449,
1767,
282,
1059,
6144,
314,
1824,
666,
12,
5893,
10102,
1584,
10595,
267,
327,
6516,
282,
769,
402,
5548,
12,
1924,
3035,
298,
1278,
2,
402,
314,
267,
327
] |
[
199,
4078,
18,
446,
11243,
367,
13618,
10867,
199,
199,
33,
3555,
367,
13618,
10867,
626,
883,
506,
9243,
701,
12669,
3537,
4113,
199,
5586,
14,
199,
199,
1918,
4011,
18,
859,
7890,
3423,
436,
3992,
1314,
1720,
315,
13618,
10867,
199,
8,
2786,
590,
3101,
9,
315,
282,
6114,
6701,
446,
5678,
436,
10017,
6299,
12,
199,
264,
27917,
12,
10049,
436,
1655,
14,
199,
199,
1918,
4011,
18,
859,
6571,
376,
4588,
3261,
367,
1808,
21408,
5944,
199,
9281,
8981,
701,
10867,
14,
2779,
365,
19829,
370,
506,
9243,
701,
8212,
13103,
370,
199,
4058,
892,
19230,
503,
1050,
4172,
1298,
370,
3411,
19230,
334,
10180,
465,
7252,
199,
2856,
5678,
6299,
680,
199,
199,
2859,
921,
647,
30034,
87,
14,
957,
15,
18,
15,
4078,
18,
15,
199,
2344,
199,
199,
646,
4011,
199,
646,
4011,
18,
199,
199,
3,
3651,
10818,
413,
26,
3101,
8761,
26,
199,
3,
11148,
199,
3,
4005,
8761,
1824,
13,
8167,
666,
370,
314,
3982,
1654,
12,
3140,
402,
1808,
9576,
12,
986,
314,
199,
3,
5737,
1827,
2368,
465,
666,
370,
18279,
1252,
199,
199,
1131,
63,
589,
275,
469,
283,
81,
5242,
1131,
1059,
297,
283,
1421,
5242,
1700,
7,
789,
199,
8167,
63,
589,
275,
4011,
14,
10738,
8,
1131,
63,
589,
9,
199,
633,
275,
283,
1014,
921,
5967,
26,
15844,
4805,
199,
1361,
4011,
18,
14,
10890,
8,
633,
12,
5737,
63,
589,
680,
739,
342,
421,
199,
3,
3651,
10818,
499,
26,
9361,
316,
543,
20260,
21128,
590,
26,
199,
3,
11148,
199,
3,
18279,
342,
365,
282,
16777,
805,
626,
13714,
83,
2005,
402,
314,
2436,
402,
4212,
314,
199,
3,
1056,
365,
6326,
436,
8860,
367,
1265,
14,
2104,
1655,
28334,
3304,
12,
1265,
1443,
2934,
370,
199,
3,
17321,
436,
675,
282,
4784,
909,
5370,
14,
421,
199,
3,
3651,
10818,
650,
26,
12934,
6219,
10947,
21391,
26,
199,
3,
11148,
199,
3,
3709,
314,
7251,
3432,
22907,
11409,
323,
12,
314,
849,
2876,
13,
4054,
1406,
574,
365,
6326,
199,
3,
1536,
402,
314,
4413,
2018,
13,
4078,
12,
9437,
701,
314,
2018,
12693,
1015,
14,
199,
3,
982,
1265,
787,
6425,
376,
4223,
626,
911,
2879,
1163,
13135,
21045,
83,
3330,
199,
3,
5944,
12,
652,
365,
512,
300,
266,
1785,
370,
2387,
3363,
922,
6631,
2556,
315,
2195,
199,
3,
4145,
12,
880,
2985,
883,
10405,
314,
1350,
402,
314,
19745,
1655,
16174,
14,
11719,
282,
199,
3,
3537,
6631,
2597,
6127,
3062,
370,
3304,
29550,
83,
1808,
282,
14544,
83,
14,
2424,
570,
199,
3,
334,
3239,
14544,
2087,
680,
199,
199,
646,
4011,
18,
199,
199,
1069,
275,
4011,
18,
14,
2017,
360,
1014,
921,
5967,
26,
15844,
6217,
199,
1069,
14,
525,
63,
1291,
360,
1899,
13,
4054,
297,
283,
2713,
27235,
55,
334,
1014,
921,
1544,
14,
68,
4937,
1697,
20059,
14,
957,
15,
2713,
27235,
55,
15,
5942,
199,
199,
1310,
275,
4011,
18,
14,
10890,
8,
1069,
9,
199,
576,
275,
1177,
14,
739,
342,
199,
1361,
666,
421,
199,
3,
3651,
10818,
841,
26,
7711,
316,
8204,
3918,
26,
199,
3,
11148,
199,
3,
2047,
883,
663,
314,
21507,
666,
641,
314,
4784,
370,
2963,
652,
370,
314,
1654,
14,
199,
199,
646,
4011,
199,
646,
4011,
18,
199,
199,
1131,
63,
589,
275,
469,
283,
81,
5242,
1131,
1059,
297,
283,
1421,
5242,
1700,
7,
789,
199,
199,
1069,
275,
4011,
18,
14,
2017,
360,
1014,
921,
5967,
26,
15844,
6217,
199,
1361,
283,
2017,
1083,
2544,
666,
6536,
1056,
14,
362,
63,
765,
342,
199,
199,
1069,
14,
525,
63,
576,
8,
4078,
14,
10738,
8,
1131,
63,
589,
430,
199,
1361,
283,
2017,
1083,
2410,
666,
520,
297,
1056,
14,
362,
63,
765,
342,
199,
1069,
14,
525,
63,
1291,
360,
1899,
13,
4054,
297,
283,
2713,
27235,
55,
334,
1014,
921,
1544,
14,
68,
4937,
1697,
20059,
14,
957,
15,
2713,
27235,
55,
15,
5942,
199,
199,
1361,
199,
1361,
283,
1877,
13160,
1206,
7126,
4881,
199,
1361,
1056,
14,
362,
63,
576,
342,
199,
199,
1361,
199,
1361,
283,
6613,
820,
7613,
11827,
4881,
199,
1361,
4011,
18,
14,
10890,
8,
1069,
680,
739,
342,
421,
199,
3,
3651,
10818,
959,
26,
4949,
8786,
16920,
26,
199,
3,
11148,
199,
3,
19694,
1584,
367,
5802,
5074,
282,
12050,
1655,
1736,
2419,
3486,
4513,
14,
199,
3,
437,
4890,
14735,
1245,
4839,
370,
506,
14701,
315,
314,
2396,
402,
314,
1056,
12,
199,
3,
880,
626,
314,
1654,
883,
22237,
12467,
1824,
1504,
687,
14238,
1584,
14,
199,
199,
646,
7975,
199,
646,
6660,
2537,
199,
646,
13290,
199,
504,
15073,
492,
5228,
199,
646,
4011,
199,
646,
4011,
18,
199,
199,
533,
6879,
8416,
2821,
8,
785,
304,
272,
1449,
23384,
5434,
314,
666,
370,
506,
1202,
1380,
25386,
282,
1824,
10595,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
964,
63,
955,
275,
942,
267,
291,
14,
1725,
275,
942,
267,
291,
14,
9891,
275,
6660,
2537,
14,
16143,
63,
9891,
342,
267,
372,
2286,
347,
664,
63,
1317,
63,
466,
8,
277,
304,
267,
372,
283,
10123,
15,
964,
13,
576,
27,
8424,
2458,
83,
7,
450,
291,
14,
9891,
339,
347,
1050,
63,
698,
8,
277,
12,
536,
12,
574,
304,
267,
408,
1123,
282,
3486,
901,
370,
314,
1824,
666,
1041,
267,
291,
14,
964,
63,
955,
14,
740,
1332,
354,
12,
574,
430,
267,
372,
339,
347,
1050,
63,
493,
8,
277,
12,
18887,
12,
1788,
12,
570,
5940,
12,
12200,
29,
403,
304,
267,
408,
1123,
282,
570,
370,
506,
14238,
1041,
267,
2396,
275,
570,
5940,
14,
739,
342,
267,
340,
12200,
365,
488,
26,
288,
12200,
275,
13290,
14,
11636,
63,
466,
8,
1501,
2788,
16,
61,
503,
283,
3578,
15,
18162,
13,
1745,
7,
267,
291,
14,
1725,
14,
740,
1332,
13646,
12,
1788,
12,
12200,
12,
2396,
430,
267,
372,
2286,
347,
636,
495,
721,
277,
304,
267,
1449,
1767,
282,
1059,
6144,
314,
1824,
666,
12,
5893,
10102,
1584,
10595,
267,
327,
6516,
282,
769,
402,
5548,
12,
1924,
3035,
298,
1278,
2,
402,
314,
267,
327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fsalamero/pilas
|
pilasengine/actores/maton.py
|
5
|
3468
|
# -*- encoding: utf-8 -*-
# pilas engine: un motor para hacer videojuegos
#
# Copyright 2010-2014 - Hugo Ruscitti
# License: LGPLv3 (see http://www.gnu.org/licenses/lgpl.html)
#
# Website - http://www.pilas-engine.com.ar
import pilasengine
from pilasengine.actores.actor import Actor
from pilasengine.comportamientos.comportamiento import Comportamiento
VELOCIDAD = 10
NORTE = 0
SUR = 2
ESTE = 1
OESTE = 3
class Maton(Actor):
"""Representa un personaje de juego tipo RPG."""
def pre_iniciar(self, x=0, y=0):
self.x = x
self.y = y
self.imagen = self.pilas.imagenes.cargar_grilla("rpg/maton.png", 3, 4)
self.direccion = SUR
self.hacer(Esperando)
self.velocidad = VELOCIDAD
self.figura = self.pilas.fisica.Circulo(0, 0, 5)
self.figura.escala_de_gravedad = 0
self.figura.sin_rotacion = True
def definir_cuadro(self, indice):
self.imagen.definir_cuadro(indice)
self.definir_centro((17, 48))
def actualizar(self):
self.x = self.figura.x
self.y = self.figura.y
class Esperando(Comportamiento):
def iniciar(self, receptor):
self.receptor = receptor
if receptor.direccion == NORTE:
receptor.definir_cuadro(1)
elif receptor.direccion == ESTE:
receptor.definir_cuadro(4)
elif receptor.direccion == SUR:
receptor.definir_cuadro(7)
elif receptor.direccion == OESTE:
receptor.definir_cuadro(10)
def actualizar(self):
self.receptor.figura.velocidad_x = 0
self.receptor.figura.velocidad_y = 0
if self.pilas.control.izquierda:
self.receptor.hacer(Caminando)
return True
elif self.pilas.control.derecha:
self.receptor.hacer(Caminando)
return True
elif self.pilas.control.arriba:
self.receptor.hacer(Caminando)
return True
elif self.pilas.control.abajo:
self.receptor.hacer(Caminando)
return True
class Caminando(Esperando):
def iniciar(self, receptor):
self.receptor = receptor
self._repeticion_cuadro = 3
self.paso = 0
self.cuadros = [[1,1,1,1,0,0,0,0,1,1,1,1,2,2,2,2],
[4,4,4,4,3,3,3,3,4,4,4,4,5,5,5,5],
[7,7,7,7,6,6,6,6,7,7,7,7,8,8,8,8],
[10,10,10,10,9,9,9,9,10,10,10,10,11,11,11,11]]
def actualizar(self):
self.avanzar_animacion()
dx = 0
dy = 0
if self.pilas.control.izquierda:
dx = self.receptor.velocidad * -1
self.receptor.direccion = OESTE
elif self.pilas.control.derecha:
dx = self.receptor.velocidad
self.receptor.direccion = ESTE
elif self.pilas.control.arriba:
dy = self.receptor.velocidad
self.receptor.direccion = NORTE
elif self.pilas.control.abajo:
dy = self.receptor.velocidad * -1
self.receptor.direccion = SUR
else:
self.receptor.hacer(Esperando)
return True
self.receptor.figura.velocidad_x = dx
self.receptor.figura.velocidad_y = dy
def avanzar_animacion(self):
self.paso += 1
if self.paso >= len(self.cuadros[self.receptor.direccion]):
self.paso = 0
self.receptor.definir_cuadro(self.cuadros[self.receptor.direccion][self.paso])
|
lgpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
299,
382,
305,
6869,
26,
625,
28496,
12665,
394,
645,
281,
3991,
74,
310,
71,
736,
199,
3,
199,
3,
1898,
7129,
13,
7280,
446,
869,
1518,
79,
820,
527,
14422,
280,
199,
3,
844,
26,
491,
28863,
19,
334,
3239,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
9,
199,
3,
199,
3,
6001,
2124,
446,
1455,
921,
1544,
14,
80,
382,
305,
13,
3908,
14,
957,
14,
285,
199,
199,
646,
299,
382,
482,
78,
2598,
199,
504,
299,
382,
482,
78,
2598,
14,
2442,
7944,
14,
5021,
492,
437,
630,
199,
504,
299,
382,
482,
78,
2598,
14,
331,
412,
13496,
287,
14543,
14,
331,
412,
13496,
287,
475,
492,
1849,
412,
13496,
287,
475,
199,
199,
2524,
5752,
998,
1554,
275,
1616,
199,
199,
46,
2596,
37,
275,
378,
199,
51,
1230,
275,
499,
199,
1719,
37,
275,
413,
199,
47,
1719,
37,
275,
650,
421,
199,
533,
18619,
265,
8,
12258,
304,
272,
408,
10755,
65,
625,
4954,
65,
6532,
477,
1335,
310,
1939,
3367,
555,
820,
11115,
1041,
339,
347,
876,
63,
26715,
73,
285,
8,
277,
12,
671,
29,
16,
12,
612,
29,
16,
304,
267,
291,
14,
88,
275,
671,
267,
291,
14,
89,
275,
612,
267,
291,
14,
11744,
2268,
275,
291,
14,
80,
382,
305,
14,
11744,
26965,
14,
67,
1273,
285,
63,
7928,
76,
416,
480,
82,
4198,
15,
569,
265,
14,
4524,
401,
650,
12,
841,
9,
398,
291,
14,
328,
2761,
9718,
275,
428,
1230,
267,
291,
14,
72,
645,
281,
8,
21658,
529,
22066,
9,
267,
291,
14,
432,
2102,
344,
350,
275,
812,
37,
5752,
998,
1554,
267,
291,
14,
592,
12417,
275,
291,
14,
80,
382,
305,
14,
329,
338,
696,
14,
35,
5958,
13957,
8,
16,
12,
378,
12,
959,
9,
267,
291,
14,
592,
12417,
14,
397,
915,
65,
63,
271,
63,
926,
1354,
350,
275,
378,
267,
291,
14,
592,
12417,
14,
5911,
63,
293,
502,
9718,
275,
715,
339,
347,
347,
262,
723,
63,
67,
8346,
293,
8,
277,
12,
2539,
301,
304,
267,
291,
14,
11744,
2268,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
3558,
301,
9,
267,
291,
14,
318,
262,
723,
63,
2946,
293,
1332,
1196,
12,
9615,
430,
339,
347,
3503,
565,
285,
8,
277,
304,
267,
291,
14,
88,
275,
291,
14,
592,
12417,
14,
88,
267,
291,
14,
89,
275,
291,
14,
592,
12417,
14,
89,
199,
199,
533,
662,
83,
529,
22066,
8,
967,
412,
13496,
287,
475,
304,
339,
347,
315,
530,
73,
285,
8,
277,
12,
295,
716,
269,
304,
267,
291,
14,
264,
716,
269,
275,
295,
716,
269,
398,
340,
295,
716,
269,
14,
328,
2761,
9718,
508,
653,
2596,
37,
26,
288,
295,
716,
269,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
17,
9,
267,
916,
295,
716,
269,
14,
328,
2761,
9718,
508,
221,
1719,
37,
26,
288,
295,
716,
269,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
20,
9,
267,
916,
295,
716,
269,
14,
328,
2761,
9718,
508,
428,
1230,
26,
288,
295,
716,
269,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
23,
9,
267,
916,
295,
716,
269,
14,
328,
2761,
9718,
508,
593,
1719,
37,
26,
288,
295,
716,
269,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
709,
9,
339,
347,
3503,
565,
285,
8,
277,
304,
267,
291,
14,
264,
716,
269,
14,
592,
12417,
14,
432,
2102,
344,
350,
63,
88,
275,
378,
267,
291,
14,
264,
716,
269,
14,
592,
12417,
14,
432,
2102,
344,
350,
63,
89,
275,
378,
398,
340,
291,
14,
80,
382,
305,
14,
2785,
14,
565,
783,
281,
983,
26,
288,
291,
14,
264,
716,
269,
14,
72,
645,
281,
8,
30524,
262,
22066,
9,
288,
372,
715,
267,
916,
291,
14,
80,
382,
305,
14,
2785,
14,
271,
264,
9518,
26,
288,
291,
14,
264,
716,
269,
14,
72,
645,
281,
8,
30524,
262,
22066,
9,
288,
372,
715,
267,
916,
291,
14,
80,
382,
305,
14,
2785,
14,
285,
322,
2470,
26,
288,
291,
14,
264,
716,
269,
14,
72,
645,
281,
8,
30524,
262,
22066,
9,
288,
372,
715,
267,
916,
291,
14,
80,
382,
305,
14,
2785,
14,
20338,
743,
26,
288,
291,
14,
264,
716,
269,
14,
72,
645,
281,
8,
30524,
262,
22066,
9,
288,
372,
715,
199,
199,
533,
445,
32374,
22066,
8,
21658,
529,
22066,
304,
339,
347,
315,
530,
73,
285,
8,
277,
12,
295,
716,
269,
304,
267,
291,
14,
264,
716,
269,
275,
295,
716,
269,
267,
291,
423,
5028,
280,
9718,
63,
67,
8346,
293,
275,
650,
267,
291,
14,
15534,
79,
275,
378,
267,
291,
14,
67,
8346,
4796,
275,
3474,
17,
12,
17,
12,
17,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
12,
17,
12,
17,
12,
17,
12,
18,
12,
18,
12,
18,
12,
18,
467,
717,
359,
20,
12,
20,
12,
20,
12,
20,
12,
19,
12,
19,
12,
19,
12,
19,
12,
20,
12,
20,
12,
20,
12,
20,
12,
21,
12,
21,
12,
21,
12,
21,
467,
717,
359,
23,
12,
23,
12,
23,
12,
23,
12,
22,
12,
22,
12,
22,
12,
22,
12,
23,
12,
23,
12,
23,
12,
23,
12,
24,
12,
24,
12,
24,
12,
24,
467,
717,
359,
709,
12,
709,
12,
709,
12,
709,
12,
25,
12,
25,
12,
25,
12,
25,
12,
709,
12,
709,
12,
709,
12,
709,
12,
845,
12,
845,
12,
845,
12,
845,
2677,
339,
347,
3503,
565,
285,
8,
277,
304,
267,
291,
14,
1214,
290,
90,
285,
63,
290,
11744,
9718,
342,
398,
11868,
275,
378,
267,
13119,
275,
378,
398,
340,
291,
14,
80,
382,
305,
14,
2785,
14,
565,
783,
281,
983,
26,
288,
11868,
275,
291,
14,
264,
716,
269,
14,
432,
2102,
344,
350,
627,
446,
17,
288,
291,
14,
264,
716,
269,
14,
328,
2761,
9718,
275,
593,
1719,
37,
267,
916,
291,
14,
80,
382,
305,
14,
2785,
14,
271,
264
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
299,
382,
305,
6869,
26,
625,
28496,
12665,
394,
645,
281,
3991,
74,
310,
71,
736,
199,
3,
199,
3,
1898,
7129,
13,
7280,
446,
869,
1518,
79,
820,
527,
14422,
280,
199,
3,
844,
26,
491,
28863,
19,
334,
3239,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
9,
199,
3,
199,
3,
6001,
2124,
446,
1455,
921,
1544,
14,
80,
382,
305,
13,
3908,
14,
957,
14,
285,
199,
199,
646,
299,
382,
482,
78,
2598,
199,
504,
299,
382,
482,
78,
2598,
14,
2442,
7944,
14,
5021,
492,
437,
630,
199,
504,
299,
382,
482,
78,
2598,
14,
331,
412,
13496,
287,
14543,
14,
331,
412,
13496,
287,
475,
492,
1849,
412,
13496,
287,
475,
199,
199,
2524,
5752,
998,
1554,
275,
1616,
199,
199,
46,
2596,
37,
275,
378,
199,
51,
1230,
275,
499,
199,
1719,
37,
275,
413,
199,
47,
1719,
37,
275,
650,
421,
199,
533,
18619,
265,
8,
12258,
304,
272,
408,
10755,
65,
625,
4954,
65,
6532,
477,
1335,
310,
1939,
3367,
555,
820,
11115,
1041,
339,
347,
876,
63,
26715,
73,
285,
8,
277,
12,
671,
29,
16,
12,
612,
29,
16,
304,
267,
291,
14,
88,
275,
671,
267,
291,
14,
89,
275,
612,
267,
291,
14,
11744,
2268,
275,
291,
14,
80,
382,
305,
14,
11744,
26965,
14,
67,
1273,
285,
63,
7928,
76,
416,
480,
82,
4198,
15,
569,
265,
14,
4524,
401,
650,
12,
841,
9,
398,
291,
14,
328,
2761,
9718,
275,
428,
1230,
267,
291,
14,
72,
645,
281,
8,
21658,
529,
22066,
9,
267,
291,
14,
432,
2102,
344,
350,
275,
812,
37,
5752,
998,
1554,
267,
291,
14,
592,
12417,
275,
291,
14,
80,
382,
305,
14,
329,
338,
696,
14,
35,
5958,
13957,
8,
16,
12,
378,
12,
959,
9,
267,
291,
14,
592,
12417,
14,
397,
915,
65,
63,
271,
63,
926,
1354,
350,
275,
378,
267,
291,
14,
592,
12417,
14,
5911,
63,
293,
502,
9718,
275,
715,
339,
347,
347,
262,
723,
63,
67,
8346,
293,
8,
277,
12,
2539,
301,
304,
267,
291,
14,
11744,
2268,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
3558,
301,
9,
267,
291,
14,
318,
262,
723,
63,
2946,
293,
1332,
1196,
12,
9615,
430,
339,
347,
3503,
565,
285,
8,
277,
304,
267,
291,
14,
88,
275,
291,
14,
592,
12417,
14,
88,
267,
291,
14,
89,
275,
291,
14,
592,
12417,
14,
89,
199,
199,
533,
662,
83,
529,
22066,
8,
967,
412,
13496,
287,
475,
304,
339,
347,
315,
530,
73,
285,
8,
277,
12,
295,
716,
269,
304,
267,
291,
14,
264,
716,
269,
275,
295,
716,
269,
398,
340,
295,
716,
269,
14,
328,
2761,
9718,
508,
653,
2596,
37,
26,
288,
295,
716,
269,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
17,
9,
267,
916,
295,
716,
269,
14,
328,
2761,
9718,
508,
221,
1719,
37,
26,
288,
295,
716,
269,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
20,
9,
267,
916,
295,
716,
269,
14,
328,
2761,
9718,
508,
428,
1230,
26,
288,
295,
716,
269,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
23,
9,
267,
916,
295,
716,
269,
14,
328,
2761,
9718,
508,
593,
1719,
37,
26,
288,
295,
716,
269,
14,
318,
262,
723,
63,
67,
8346,
293,
8,
709,
9,
339,
347,
3503,
565,
285,
8,
277,
304,
267,
291,
14,
264,
716,
269,
14,
592,
12417,
14,
432,
2102,
344,
350,
63,
88,
275,
378,
267,
291,
14,
264,
716,
269,
14,
592,
12417,
14,
432,
2102,
344,
350,
63,
89,
275,
378,
398,
340,
291,
14,
80,
382,
305,
14,
2785,
14,
565,
783,
281,
983,
26,
288,
291,
14,
264,
716,
269,
14,
72,
645,
281,
8,
30524,
262,
22066,
9,
288,
372,
715,
267,
916,
291,
14,
80,
382,
305,
14,
2785,
14,
271,
264,
9518,
26,
288,
291,
14,
264,
716,
269,
14,
72,
645,
281,
8,
30524,
262,
22066,
9,
288,
372,
715,
267,
916,
291,
14,
80,
382,
305,
14,
2785,
14,
285,
322,
2470,
26,
288,
291,
14,
264,
716,
269,
14,
72,
645,
281,
8,
30524,
262,
22066,
9,
288,
372,
715,
267,
916,
291,
14,
80,
382,
305,
14,
2785,
14,
20338,
743,
26,
288,
291,
14,
264,
716,
269,
14,
72,
645,
281,
8,
30524,
262,
22066,
9,
288,
372,
715,
199,
199,
533,
445,
32374,
22066,
8,
21658,
529,
22066,
304,
339,
347,
315,
530,
73,
285,
8,
277,
12,
295,
716,
269,
304,
267,
291,
14,
264,
716,
269,
275,
295,
716,
269,
267,
291,
423,
5028,
280,
9718,
63,
67,
8346,
293,
275,
650,
267,
291,
14,
15534,
79,
275,
378,
267,
291,
14,
67,
8346,
4796,
275,
3474,
17,
12,
17,
12,
17,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
12,
17,
12,
17,
12,
17,
12,
18,
12,
18,
12,
18,
12,
18,
467,
717,
359,
20,
12,
20,
12,
20,
12,
20,
12,
19,
12,
19,
12,
19,
12,
19,
12,
20,
12,
20,
12,
20,
12,
20,
12,
21,
12,
21,
12,
21,
12,
21,
467,
717,
359,
23,
12,
23,
12,
23,
12,
23,
12,
22,
12,
22,
12,
22,
12,
22,
12,
23,
12,
23,
12,
23,
12,
23,
12,
24,
12,
24,
12,
24,
12,
24,
467,
717,
359,
709,
12,
709,
12,
709,
12,
709,
12,
25,
12,
25,
12,
25,
12,
25,
12,
709,
12,
709,
12,
709,
12,
709,
12,
845,
12,
845,
12,
845,
12,
845,
2677,
339,
347,
3503,
565,
285,
8,
277,
304,
267,
291,
14,
1214,
290,
90,
285,
63,
290,
11744,
9718,
342,
398,
11868,
275,
378,
267,
13119,
275,
378,
398,
340,
291,
14,
80,
382,
305,
14,
2785,
14,
565,
783,
281,
983,
26,
288,
11868,
275,
291,
14,
264,
716,
269,
14,
432,
2102,
344,
350,
627,
446,
17,
288,
291,
14,
264,
716,
269,
14,
328,
2761,
9718,
275,
593,
1719,
37,
267,
916,
291,
14,
80,
382,
305,
14,
2785,
14,
271,
264,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mkhutornenko/incubator-aurora
|
src/main/python/apache/aurora/executor/common/health_checker.py
|
1
|
4022
|
#
# 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 threading
import time
from twitter.common import log
from twitter.common.exceptions import ExceptionalThread
from apache.aurora.common.http_signaler import HttpSignaler
from .status_checker import ExitState, StatusChecker, StatusCheckerProvider, StatusResult
from .task_info import mesos_task_instance_from_assigned_task, resolve_ports
class HealthCheckerThread(StatusChecker, ExceptionalThread):
"""Generic, StatusChecker-conforming thread for arbitrary periodic health checks
health_checker should be a callable returning a tuple of (boolean, reason), indicating
respectively the health of the service and the reason for its failure (or None if the service is
still healthy).
"""
def __init__(self,
health_checker,
interval_secs=10,
initial_interval_secs=None,
max_consecutive_failures=0,
clock=time):
self._checker = health_checker
self._interval = interval_secs
if initial_interval_secs is not None:
self._initial_interval = initial_interval_secs
else:
self._initial_interval = interval_secs * 2
self._current_consecutive_failures = 0
self._max_consecutive_failures = max_consecutive_failures
self._dead = threading.Event()
if self._initial_interval > 0:
self._healthy, self._reason = True, None
else:
self._healthy, self._reason = self._checker()
self._clock = clock
super(HealthCheckerThread, self).__init__()
self.daemon = True
@property
def status(self):
if not self._healthy:
return StatusResult('Failed health check! %s' % self._reason, ExitState.FAILED)
def run(self):
log.debug('Health checker thread started.')
self._clock.sleep(self._initial_interval)
log.debug('Initial interval expired.')
while not self._dead.is_set():
self._maybe_update_failure_count(*self._checker())
self._clock.sleep(self._interval)
def _maybe_update_failure_count(self, is_healthy, reason):
if not is_healthy:
log.warning('Health check failure: %s' % reason)
self._current_consecutive_failures += 1
if self._current_consecutive_failures > self._max_consecutive_failures:
log.warning('Reached consecutive failure limit.')
self._healthy = False
self._reason = reason
else:
if self._current_consecutive_failures > 0:
log.debug('Reset consecutive failures counter.')
self._current_consecutive_failures = 0
def start(self):
StatusChecker.start(self)
ExceptionalThread.start(self)
def stop(self):
log.debug('Health checker thread stopped.')
self._dead.set()
class HealthCheckerProvider(StatusCheckerProvider):
def from_assigned_task(self, assigned_task, _):
mesos_task = mesos_task_instance_from_assigned_task(assigned_task)
portmap = resolve_ports(mesos_task, assigned_task.assignedPorts)
if 'health' not in portmap:
return None
health_check_config = mesos_task.health_check_config().get()
http_signaler = HttpSignaler(
portmap['health'],
timeout_secs=health_check_config.get('timeout_secs'))
health_checker = HealthCheckerThread(
http_signaler.health,
interval_secs=health_check_config.get('interval_secs'),
initial_interval_secs=health_check_config.get('initial_interval_secs'),
max_consecutive_failures=health_check_config.get('max_consecutive_failures'))
return health_checker
|
apache-2.0
|
[
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
5796,
199,
646,
900,
199,
199,
504,
15811,
14,
2330,
492,
943,
199,
504,
15811,
14,
2330,
14,
3924,
492,
2186,
279,
4436,
199,
199,
504,
17098,
14,
65,
300,
11131,
14,
2330,
14,
1014,
63,
1037,
29706,
492,
4760,
4940,
29706,
199,
199,
504,
1275,
1205,
63,
6743,
492,
18704,
2223,
12,
9795,
3048,
12,
9795,
3048,
6663,
12,
9795,
2889,
199,
504,
1275,
1765,
63,
815,
492,
26560,
736,
63,
1765,
63,
842,
63,
504,
63,
12941,
63,
1765,
12,
7512,
63,
5203,
421,
199,
533,
5311,
6130,
3048,
4436,
8,
3694,
3048,
12,
2186,
279,
4436,
304,
523,
408,
9417,
12,
9795,
3048,
13,
388,
964,
316,
2462,
367,
9697,
18745,
13822,
5920,
339,
13822,
63,
6743,
1077,
506,
282,
4550,
8152,
282,
2008,
402,
334,
4871,
12,
4499,
395,
9297,
272,
17342,
314,
13822,
402,
314,
2435,
436,
314,
4499,
367,
2399,
5988,
334,
269,
488,
340,
314,
2435,
365,
272,
5139,
13822,
89,
680,
523,
408,
819,
347,
636,
826,
721,
277,
12,
2049,
13822,
63,
6743,
12,
2049,
6252,
63,
4855,
29,
709,
12,
2049,
2536,
63,
4284,
63,
4855,
29,
403,
12,
2049,
1390,
63,
388,
19068,
63,
9968,
29,
16,
12,
2049,
12516,
29,
521,
304,
272,
291,
423,
6743,
275,
13822,
63,
6743,
272,
291,
423,
4284,
275,
6252,
63,
4855,
272,
340,
2536,
63,
4284,
63,
4855,
365,
440,
488,
26,
489,
291,
423,
2747,
63,
4284,
275,
2536,
63,
4284,
63,
4855,
272,
587,
26,
489,
291,
423,
2747,
63,
4284,
275,
6252,
63,
4855,
627,
499,
272,
291,
423,
1818,
63,
388,
19068,
63,
9968,
275,
378,
272,
291,
423,
988,
63,
388,
19068,
63,
9968,
275,
1390,
63,
388,
19068,
63,
9968,
272,
291,
423,
10957,
275,
5796,
14,
2390,
342,
272,
340,
291,
423,
2747,
63,
4284,
690,
378,
26,
489,
291,
423,
29584,
12,
291,
423,
5764,
275,
715,
12,
488,
272,
587,
26,
489,
291,
423,
29584,
12,
291,
423,
5764,
275,
291,
423,
6743,
342,
272,
291,
423,
9597,
275,
12516,
272,
1613,
8,
18850,
3048,
4436,
12,
291,
2843,
826,
4533,
272,
291,
14,
10824,
275,
715,
819,
768,
1829,
523,
347,
2004,
8,
277,
304,
272,
340,
440,
291,
423,
29584,
26,
489,
372,
9795,
2889,
360,
4276,
13822,
1104,
1,
450,
83,
7,
450,
291,
423,
5764,
12,
18704,
2223,
14,
12299,
9,
819,
347,
1255,
8,
277,
304,
272,
943,
14,
1757,
360,
18850,
7739,
2462,
8239,
2659,
272,
291,
423,
9597,
14,
4532,
8,
277,
423,
2747,
63,
4284,
9,
272,
943,
14,
1757,
360,
5733,
6252,
14721,
2659,
272,
1830,
440,
291,
423,
10957,
14,
374,
63,
409,
837,
489,
291,
423,
11853,
63,
873,
63,
5328,
63,
835,
2031,
277,
423,
6743,
1012,
489,
291,
423,
9597,
14,
4532,
8,
277,
423,
4284,
9,
819,
347,
485,
11853,
63,
873,
63,
5328,
63,
835,
8,
277,
12,
365,
63,
29584,
12,
4499,
304,
272,
340,
440,
365,
63,
29584,
26,
489,
943,
14,
3764,
360,
18850,
1104,
5988,
26,
450,
83,
7,
450,
4499,
9,
489,
291,
423,
1818,
63,
388,
19068,
63,
9968,
847,
413,
489,
340,
291,
423,
1818,
63,
388,
19068,
63,
9968,
690,
291,
423,
988,
63,
388,
19068,
63,
9968,
26,
267,
943,
14,
3764,
360,
497,
4583,
23376,
5988,
2304,
2659,
267,
291,
423,
29584,
275,
756,
267,
291,
423,
5764,
275,
4499,
272,
587,
26,
489,
340,
291,
423,
1818,
63,
388,
19068,
63,
9968,
690,
378,
26,
267,
943,
14,
1757,
360,
9637,
23376,
9081,
7055,
2659,
489,
291,
423,
1818,
63,
388,
19068,
63,
9968,
275,
378,
819,
347,
1343,
8,
277,
304,
272,
9795,
3048,
14,
928,
8,
277,
9,
272,
2186,
279,
4436,
14,
928,
8,
277,
9,
819,
347,
3631,
8,
277,
304,
272,
943,
14,
1757,
360,
18850,
7739,
2462,
15248,
2659,
272,
291,
423,
10957,
14,
409,
342,
421,
199,
533,
5311,
6130,
3048,
6663,
8,
3694,
3048,
6663,
304,
523,
347,
687,
63,
12941,
63,
1765,
8,
277,
12,
7943,
63,
1765,
12,
27574,
272,
26560,
736,
63,
1765,
275,
26560,
736,
63,
1765,
63,
842,
63,
504,
63,
12941,
63,
1765,
8,
12941,
63,
1765,
9,
272,
1844,
1130,
275,
7512,
63,
5203,
8,
6415,
736,
63,
1765,
12,
7943,
63,
1765,
14,
12941,
25573,
9,
339,
340,
283,
9665,
7,
440,
315,
1844,
1130,
26,
489,
372,
488,
339,
13822,
63,
1074,
63,
888,
275,
26560,
736,
63,
1765,
14,
9665,
63,
1074,
63,
888,
1252,
362,
342,
272,
1455,
63,
1037,
29706,
275,
4760,
4940,
29706,
8,
267,
1844,
1130,
459,
9665,
995,
267,
2653,
63,
4855,
29,
9665,
63,
1074,
63,
888,
14,
362,
360,
2593,
63,
4855,
1333,
272,
13822,
63,
6743,
275,
5311,
6130,
3048,
4436,
8,
267,
1455,
63,
1037,
29706,
14,
9665,
12,
267,
6252,
63,
4855,
29,
9665,
63,
1074,
63,
888,
14,
362,
360,
4284,
63,
4855,
659,
267,
2536,
63,
4284,
63,
4855,
29,
9665,
63,
1074,
63,
888,
14,
362,
360,
2747,
63,
4284,
63,
4855,
659,
267,
1390,
63,
388,
19068,
63,
9968,
29,
9665,
63,
1074,
63,
888,
14,
362,
360,
988,
63,
388,
19068,
63,
9968,
1333,
272,
372,
13822,
63,
6743,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
5796,
199,
646,
900,
199,
199,
504,
15811,
14,
2330,
492,
943,
199,
504,
15811,
14,
2330,
14,
3924,
492,
2186,
279,
4436,
199,
199,
504,
17098,
14,
65,
300,
11131,
14,
2330,
14,
1014,
63,
1037,
29706,
492,
4760,
4940,
29706,
199,
199,
504,
1275,
1205,
63,
6743,
492,
18704,
2223,
12,
9795,
3048,
12,
9795,
3048,
6663,
12,
9795,
2889,
199,
504,
1275,
1765,
63,
815,
492,
26560,
736,
63,
1765,
63,
842,
63,
504,
63,
12941,
63,
1765,
12,
7512,
63,
5203,
421,
199,
533,
5311,
6130,
3048,
4436,
8,
3694,
3048,
12,
2186,
279,
4436,
304,
523,
408,
9417,
12,
9795,
3048,
13,
388,
964,
316,
2462,
367,
9697,
18745,
13822,
5920,
339,
13822,
63,
6743,
1077,
506,
282,
4550,
8152,
282,
2008,
402,
334,
4871,
12,
4499,
395,
9297,
272,
17342,
314,
13822,
402,
314,
2435,
436,
314,
4499,
367,
2399,
5988,
334,
269,
488,
340,
314,
2435,
365,
272,
5139,
13822,
89,
680,
523,
408,
819,
347,
636,
826,
721,
277,
12,
2049,
13822,
63,
6743,
12,
2049,
6252,
63,
4855,
29,
709,
12,
2049,
2536,
63,
4284,
63,
4855,
29,
403,
12,
2049,
1390,
63,
388,
19068,
63,
9968,
29,
16,
12,
2049,
12516,
29,
521,
304,
272,
291,
423,
6743,
275,
13822,
63,
6743,
272,
291,
423,
4284,
275,
6252,
63,
4855,
272,
340,
2536,
63,
4284,
63,
4855,
365,
440,
488,
26,
489,
291,
423,
2747,
63,
4284,
275,
2536,
63,
4284,
63,
4855,
272,
587,
26,
489,
291,
423,
2747,
63,
4284,
275,
6252,
63,
4855,
627,
499,
272,
291,
423,
1818,
63,
388,
19068,
63,
9968,
275,
378,
272,
291,
423,
988,
63,
388,
19068,
63,
9968,
275,
1390,
63,
388,
19068,
63,
9968,
272,
291,
423,
10957,
275,
5796,
14,
2390,
342,
272,
340,
291,
423,
2747,
63,
4284,
690,
378,
26,
489,
291,
423,
29584,
12,
291,
423,
5764,
275,
715,
12,
488,
272,
587,
26,
489,
291,
423,
29584,
12,
291,
423,
5764,
275,
291,
423,
6743,
342,
272,
291,
423,
9597,
275,
12516,
272,
1613,
8,
18850,
3048,
4436,
12,
291,
2843,
826,
4533,
272,
291,
14,
10824,
275,
715,
819,
768,
1829,
523,
347,
2004,
8,
277,
304,
272,
340,
440,
291,
423,
29584,
26,
489,
372,
9795,
2889,
360,
4276,
13822,
1104,
1,
450,
83,
7,
450,
291,
423,
5764,
12,
18704,
2223,
14,
12299,
9,
819,
347,
1255,
8,
277,
304,
272,
943,
14,
1757,
360,
18850,
7739,
2462,
8239,
2659,
272,
291,
423,
9597,
14,
4532,
8,
277,
423,
2747,
63,
4284,
9,
272,
943,
14,
1757,
360,
5733,
6252,
14721,
2659,
272,
1830,
440,
291,
423,
10957,
14,
374,
63,
409,
837,
489,
291,
423,
11853,
63,
873,
63,
5328,
63,
835,
2031,
277,
423,
6743,
1012,
489,
291,
423,
9597,
14,
4532,
8,
277,
423,
4284,
9,
819,
347,
485,
11853,
63,
873,
63,
5328,
63,
835,
8,
277,
12,
365,
63,
29584,
12,
4499,
304,
272,
340,
440,
365,
63,
29584,
26,
489,
943,
14,
3764,
360,
18850,
1104,
5988,
26,
450,
83,
7,
450,
4499,
9,
489,
291,
423,
1818,
63,
388,
19068,
63,
9968,
847,
413,
489,
340,
291,
423,
1818,
63,
388,
19068,
63,
9968,
690,
291,
423,
988,
63,
388,
19068,
63,
9968,
26,
267,
943,
14,
3764,
360,
497,
4583,
23376,
5988,
2304,
2659,
267,
291,
423,
29584,
275,
756,
267,
291,
423,
5764,
275,
4499,
272,
587,
26,
489,
340,
291,
423,
1818,
63,
388,
19068,
63,
9968,
690,
378,
26,
267,
943,
14,
1757,
360,
9637,
23376,
9081,
7055,
2659,
489,
291,
423,
1818,
63,
388,
19068,
63,
9968,
275,
378,
819,
347,
1343,
8,
277,
304,
272,
9795,
3048,
14,
928,
8,
277,
9,
272,
2186,
279,
4436,
14,
928,
8,
277,
9,
819,
347,
3631,
8,
277,
304,
272,
943,
14,
1757,
360,
18850,
7739,
2462,
15248,
2659,
272,
291,
423,
10957,
14,
409,
342,
421,
199,
533,
5311,
6130,
3048,
6663,
8,
3694,
3048,
6663,
304,
523,
347,
687,
63,
12941,
63,
1765,
8,
277,
12,
7943,
63,
1765,
12,
27574,
272,
26560,
736,
63,
1765,
275,
26560,
736,
63,
1765,
63,
842,
63,
504,
63,
12941,
63,
1765,
8,
12941,
63,
1765,
9,
272,
1844,
1130,
275,
7512,
63,
5203,
8,
6415,
736,
63,
1765,
12,
7943,
63,
1765,
14,
12941,
25573,
9,
339,
340,
283,
9665,
7,
440,
315,
1844,
1130,
26,
489,
372,
488,
339,
13822,
63,
1074,
63,
888,
275,
26560,
736,
63,
1765,
14,
9665,
63,
1074,
63,
888,
1252,
362,
342,
272,
1455,
63,
1037,
29706,
275,
4760,
4940,
29706,
8,
267,
1844,
1130,
459,
9665,
995,
267,
2653,
63,
4855,
29,
9665,
63,
1074,
63,
888,
14,
362,
360,
2593,
63,
4855,
1333,
272,
13822,
63,
6743,
275,
5311,
6130,
3048,
4436,
8,
267,
1455,
63,
1037,
29706,
14,
9665,
12,
267,
6252,
63,
4855,
29,
9665,
63,
1074,
63,
888,
14,
362,
360,
4284,
63,
4855,
659,
267,
2536,
63,
4284,
63,
4855,
29,
9665,
63,
1074,
63,
888,
14,
362,
360,
2747,
63,
4284,
63,
4855,
659,
267,
1390,
63,
388,
19068,
63,
9968,
29,
9665,
63,
1074,
63,
888,
14,
362,
360,
988,
63,
388,
19068,
63,
9968,
1333,
272,
372,
13822,
63,
6743,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
stharrold/ARCHIVED_bench_fastq
|
bench_fastq/utils.py
|
2
|
15946
|
#!/usr/bin/env python
"""Utils to parse the terminal output from bench_compress.sh
"""
from __future__ import print_function, division, absolute_import
import os
import sys
import json
import datetime as dt
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def parse_elapsed(elapsed):
"""Parse string of elapsed time from output of Unix 'time' command into
`datetime.timedelta`.
Parameters
----------
elapsed : string
Elapsed time field output from Unix 'time' command.
Format: [HH:]MM:SS[.SSS]
Returns
-------
elapsed_dt : datetime.timedelta
Elapsed time as ``datetime.timedelta``.
"""
elapsed_arr = elapsed.split(':')
if len(elapsed_arr) == 2:
hours = '0'
[minutes, seconds] = elapsed_arr
elif len(elapsed_arr) == 3:
[hours, minutes, seconds] = elapsed_arr
else:
raise AssertionError(("Program error. Elapsed time does not have 2 or 3 fields:\n" +
"{ea}").format(ea=elapsed_arr))
hours_int = int(float(hours))
minutes_int = int(float(minutes))
seconds_int = int(float(seconds))
milliseconds_int = int((float(seconds) - seconds_int) / 0.001)
elapsed_dt = dt.timedelta(hours=hours_int,
minutes=minutes_int,
seconds=seconds_int,
milliseconds=milliseconds_int)
return elapsed_dt
def recursive_timedelta_to_totsec(dobj):
"""Recursively convert ``datetime.timedelta`` elements to total seconds
in a ``dict``.
Call this function before writing the ``dict`` to JSON.
Parameters
----------
dobj : dict
``dict`` that may contain ``datetime.timedelta`` elements. ``dict`` may
be nested.
Returns
-------
dobj_converted : dict
``dict`` with ``datetime.timedelta`` elements converted to
total seconds.
"""
dobj_converted = {}
for key in dobj:
if isinstance(dobj[key], dt.timedelta):
dobj_converted[key] = dobj[key].total_seconds()
elif isinstance(dobj[key], dict):
dobj_converted[key] = recursive_timedelta_to_totsec(dobj=dobj[key])
else:
dobj_converted[key] = dobj[key]
return dobj_converted
def parse_compress(fin, fout=None):
"""Parse terminal output from bench_compress.sh
Parse by filename, file size, compression method, compression ratio, compression and decompression speed.
Note: This function is rigidly dependent upon bench_compress.sh.
Parameters
----------
fin : string
Path to text file with terminal output.
fout : {None}, string, optional
Path to output .json file of parsed terminal output.
Returns
-------
parsed : dict
``dict`` of parsed terminal output.
"""
# Check input.
fpath = os.path.abspath(fin)
if not os.path.isfile(fpath):
raise IOError("File does not exist:\n{fpath}".format(fpath=fpath))
if fout is not None:
if not os.path.splitext(fout)[1] == '.json':
raise IOError(("File extension is not '.json':\n" +
"{fout}").format(fout=fout))
# Parse text file into dict.
parsed = {}
skip_lines = None
catch_initial_size = None
catch_comp_cmd = None
catch_comp_time = None
catch_comp_size = None
catch_decomp_cmd = None
catch_decomp_time = None
catch_decomp_size = None
with open(fpath, 'rb') as fobj:
for line in fobj:
line = line.rstrip()
if line.startswith('Begin processing:'):
line_arr = line.split(':')
fname = os.path.splitext(os.path.basename(line_arr[1]))[0]
parsed[fname] = {}
continue
# Note: Typo in original script "Intial". Do not correct.
elif line.startswith('Intial .fastq size:'):
catch_initial_size = True
skip_lines = 1
continue
elif catch_initial_size and skip_lines >= 0:
if skip_lines > 0:
skip_lines -= 1
continue
elif skip_lines == 0:
line_arr = line.split()
parsed[fname]['size_bytes'] = int(line_arr[0])
assert os.path.basename(line_arr[1]) == fname
catch_initial_size = False
skip_lines = None
continue
elif line.startswith('Iteration:'):
line_arr = line.split(':')
iteration = int(line_arr[1])
parsed[fname][iteration] = {}
continue
elif line.startswith('Testing'):
line_arr = line.rstrip(':').split()
method = line_arr[1]
parsed[fname][iteration][method] = {}
catch_comp_cmd = True
continue
elif catch_comp_cmd and line.startswith('+ sudo time'):
parsed[fname][iteration][method]['compress'] = {}
parsed[fname][iteration][method]['compress']['command'] = line
catch_comp_cmd = False
catch_comp_time = True
continue
elif catch_comp_time and ('elapsed' in line) and ('CPU' in line):
line_arr = line.split()
elapsed = parse_elapsed(elapsed=line_arr[2].strip('elapsed'))
parsed[fname][iteration][method]['compress']['elapsed_time'] = elapsed
pct_cpu = line_arr[3].strip('%CPU')
if pct_cpu == '?':
pct_cpu = np.NaN
else:
pct_cpu = float(pct_cpu)
parsed[fname][iteration][method]['compress']['CPU_percent'] = pct_cpu
catch_comp_time = False
catch_comp_size = True
continue
elif catch_comp_size:
if line.startswith('+ du --bytes'):
skip_lines = 0
continue
elif skip_lines == 0:
line_arr = line.split()
parsed[fname][iteration][method]['compress']['size_bytes'] = int(line_arr[0])
catch_comp_size = False
skip_lines = None
catch_decomp_cmd = True
continue
elif catch_decomp_cmd and line.startswith('+ sudo time'):
parsed[fname][iteration][method]['decompress'] = {}
parsed[fname][iteration][method]['decompress']['command'] = line
catch_decomp_cmd = False
catch_decomp_time = True
continue
elif catch_decomp_time and ('elapsed' in line) and ('CPU' in line):
line_arr = line.split()
elapsed = parse_elapsed(elapsed=line_arr[2].strip('elapsed'))
parsed[fname][iteration][method]['decompress']['elapsed_time'] = elapsed
pct_cpu = line_arr[3].strip('%CPU')
if pct_cpu == '?':
pct_cpu = np.NaN
else:
pct_cpu = float(pct_cpu)
parsed[fname][iteration][method]['decompress']['CPU_percent'] = pct_cpu
catch_decomp_time = False
catch_decomp_size = True
continue
elif catch_decomp_size:
if line.startswith('+ du --bytes'):
skip_lines = 0
continue
elif skip_lines == 0:
line_arr = line.split()
parsed[fname][iteration][method]['decompress']['size_bytes'] = int(line_arr[0])
if parsed[fname]['size_bytes'] != parsed[fname][iteration][method]['decompress']['size_bytes']:
# noinspection PyPep8
print(("WARNING: File size before and after compression test do not match.\n" +
"file name = {fname}\n" +
"method = {method}\n" +
"initial size (bytes) = {init_size}\n" +
"final size (bytes) = {finl_size}").format(fname=fname, method=method,
init_size=parsed[fname]['size_bytes'],
finl_size=parsed[fname][iteration][method]['decompress']['size_bytes']),
file=sys.stderr)
catch_decomp_size = False
skip_lines = None
continue
# Write out dict as JSON.
if fout is not None:
parsed_converted = recursive_timedelta_to_totsec(dobj=parsed)
print("Writing parsed text to: {fout}".format(fout=fout))
with open(fout, "wb") as fobj:
json.dump(parsed_converted, fobj, indent=4, sort_keys=True)
return parsed
def parsed_dict_to_df(parsed_dict):
"""Convert ``dict`` from parse_compress to ``pandas.dataframe``.
Parameters
----------
parsed_dict : dict
``dict`` of parsed terminal output.
Returns
-------
parsed_df : pandas.dataframe
``pandas.dataframe`` with heirarchical index by filename, iteration,
method, quantity.
"""
# TODO: make recursive method, e.g. http://stackoverflow.com/questions/9538875/recursive-depth-of-python-dictionary
filename_df_dict = {}
for filename in parsed_dict:
iteration_df_dict = {}
for iteration in parsed_dict[filename]:
method_df_dict = {}
# Skip size_bytes for file since not a nested dict.
if isinstance(parsed_dict[filename][iteration], dict):
for method in parsed_dict[filename][iteration]:
method_df_dict[method] = pd.DataFrame.from_dict(parsed_dict[filename][iteration][method],
orient='columns')
iteration_df_dict[iteration] = pd.concat(method_df_dict, axis=1)
filename_df_dict[filename] = pd.concat(iteration_df_dict, axis=1)
parsed_df = pd.concat(filename_df_dict, axis=1)
parsed_df.index.names = ['quantity']
parsed_df.columns.names = ['filename', 'iteration', 'method', 'process']
return parsed_df
def condense_parsed_df(parsed_df, parsed_dict):
"""Condense ``pandas.dataframe`` from parsed terminal output.
Calculate compression/decompression rate in GB per minute and compression ratio, averaging over iterations and
taking median of results.
Parameters
----------
parsed_df : pandas.DataFrame
``pandas.DataFrame`` from `parsed_dict_to_df`.
Index name: quantity
Heirarchical column names: filename, method, process, iteration
parsed_dict : dict
Nested ``dict`` from parse_compress.
Returns
-------
condensed_df : pandas.DataFrame
Heirarchical index names: method, process, quantity
Column name: quantity
See Also
--------
parsed_dict_to_df, parse_compress, reduce_condensed_df
"""
# Calculate compression/decompression rate in GB per minute and compression ratio.
# Drop quantities except for 'GB_per_minute' and 'compression_ratio'. Drop test files and incomplete tests.
# Average over iterations. Take median of results.
condensed_df = parsed_df.stack(['filename', 'method', 'process', 'iteration']).unstack('quantity').copy()
condensed_df['elapsed_seconds'] = condensed_df['elapsed_time'].apply(
lambda x: x.total_seconds() if isinstance(x, dt.timedelta) else x)
condensed_df['elapsed_seconds'] = condensed_df['elapsed_seconds'].apply(lambda x: np.NaN if x == 0.0 else x)
condensed_df['GB_per_minute'] = np.NaN
condensed_df['compression_ratio'] = np.NaN
# TODO: Use .values to vectorize
for fname in condensed_df.index.levels[0].values:
# TODO: remove SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
condensed_df.loc[fname, 'GB_per_minute'].update(
(parsed_dict[fname]['size_bytes'] / condensed_df.loc[fname, 'elapsed_seconds']).multiply(60.0 / 1.0E9))
condensed_df.loc[fname, 'compression_ratio'].update(
condensed_df.loc[fname, 'size_bytes'].div(parsed_dict[fname]['size_bytes']))
return condensed_df
def reduce_condensed_df(condensed_df):
"""Reduce ``pandas.DataFrame`` from `condense_parsed_df` by averaging over iterations and taking the median over
file names.
Parameters
----------
condensed_df : pandas.DataFrame
Heirarchical index names: method, process, quantity
Column name: quantity
Returns
-------
reduced_ser : pandas.Series'
``pandas.Series`` from `condense_parsed_df`.
Heirarchical index names: method, process, quantity
See Also
--------
condense_parsed_df, plot_rate, plot_ratio
"""
reduced_ser = condensed_df.stack().unstack(['filename', 'method', 'process', 'quantity']).mean()
reduced_ser = reduced_ser.unstack(['method', 'process', 'quantity']).median()
return reduced_ser
def plot_rate(reduced_ser, fout=None):
"""Plot processing rate vs compression method.
Parameters
----------
reduced_ser : pandas.Series
``pandas.Series`` from `reduce_condensed_df`.
Heirarchical index names: method, process, quantity
fout : {None}, string, optional
Path to save plot as image. Extension must be supported by ``matplotlib.pyplot.savefig()``
Returns
-------
None
See Also
--------
reduce_condensed_df, plot_ratio
"""
plt.figure()
pd.DataFrame.plot(reduced_ser.unstack(['quantity'])['GB_per_minute'].unstack(['process']),
title="Processing rate vs compression method\nmedian results over all files",
sort_columns=True, kind='bar')
legend = plt.legend(loc='best', title="Process")
legend.get_texts()[0].set_text('Compress')
legend.get_texts()[1].set_text('Decompress')
xtick_labels = ('(bzip2, --fast)', '(fqz_comp, default)', '(gzip, --fast)', '(quip, default)')
plt.xticks(xrange(len(xtick_labels)), xtick_labels, rotation=45)
plt.xlabel("Compression method with options")
plt.ylabel("Processing rate (GB per minute)")
if fout is not None:
print("Writing plot to: {fout}".format(fout=fout))
plt.savefig(fout, bbox_inches='tight')
plt.show()
return None
def plot_ratio(reduced_ser, fout=None):
"""Plot compression ratio vs compression method.
Parameters
----------
reduced_ser : pandas.Series
``pandas.Series`` from `reduce_condensed_df`.
Heirarchical index names: method, process, quantity
fout : {None}, string, optional
Path to save plot as image. Extension must be supported by ``matplotlib.pyplot.savefig()``
Returns
-------
None
See Also
--------
reduce_condensed_df, plot_rate
"""
plt.figure()
pd.Series.plot(reduced_ser.unstack(['quantity'])['compression_ratio'].unstack(['process'])['compress'],
title="Compression size ratio vs compression method\nmedian results over all files",
sort_columns=True, kind='bar')
xtick_labels = ('(bzip2, --fast)', '(fqz_comp, default)', '(gzip, --fast)', '(quip, default)')
plt.xticks(xrange(len(xtick_labels)), xtick_labels, rotation=45)
plt.xlabel("Compression method with options")
plt.ylabel("Compression size ratio\n(compressed size / decompressed size)")
if fout is not None:
print("Writing plot to: {fout}".format(fout=fout))
plt.savefig(fout, bbox_inches='tight')
plt.show()
return None
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
7535,
370,
2198,
314,
11167,
1072,
687,
26456,
63,
6447,
14,
609,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
12,
3679,
63,
646,
199,
646,
747,
199,
646,
984,
199,
646,
2022,
199,
646,
2197,
465,
4487,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
646,
8027,
14,
13563,
465,
4488,
421,
199,
318,
2198,
63,
16691,
8,
16691,
304,
272,
408,
4003,
1059,
402,
14439,
900,
687,
1072,
402,
13074,
283,
521,
7,
1414,
1901,
272,
658,
2083,
14,
7473,
2313,
339,
3897,
272,
4143,
272,
14439,
520,
1059,
267,
662,
9982,
900,
901,
1072,
687,
13074,
283,
521,
7,
1414,
14,
267,
9701,
26,
359,
10213,
2938,
3218,
26,
2300,
30352,
2300,
51,
61,
339,
1803,
272,
5514,
272,
14439,
63,
3583,
520,
2197,
14,
7473,
267,
662,
9982,
900,
465,
1124,
2083,
14,
7473,
4345,
272,
408,
272,
14439,
63,
5250,
275,
14439,
14,
1294,
11633,
272,
340,
822,
8,
16691,
63,
5250,
9,
508,
499,
26,
267,
10857,
275,
283,
16,
7,
267,
359,
10430,
12,
4696,
61,
275,
14439,
63,
5250,
272,
916,
822,
8,
16691,
63,
5250,
9,
508,
650,
26,
267,
359,
8419,
12,
9395,
12,
4696,
61,
275,
14439,
63,
5250,
272,
587,
26,
267,
746,
9070,
9313,
9184,
1125,
14,
662,
9982,
900,
1630,
440,
1172,
499,
503,
650,
1504,
3427,
78,
2,
435,
2892,
5310,
4489,
30273,
908,
8,
4489,
29,
16691,
63,
5250,
430,
272,
10857,
63,
442,
275,
1109,
8,
1609,
8,
8419,
430,
272,
9395,
63,
442,
275,
1109,
8,
1609,
8,
10430,
430,
272,
4696,
63,
442,
275,
1109,
8,
1609,
8,
4515,
430,
272,
21131,
63,
442,
275,
1109,
1332,
1609,
8,
4515,
9,
446,
4696,
63,
442,
9,
1182,
378,
14,
4587,
9,
272,
14439,
63,
3583,
275,
4487,
14,
7473,
8,
8419,
29,
8419,
63,
442,
12,
2892,
9395,
29,
10430,
63,
442,
12,
2892,
4696,
29,
4515,
63,
442,
12,
2892,
21131,
29,
19579,
4515,
63,
442,
9,
272,
372,
14439,
63,
3583,
421,
199,
318,
9133,
63,
7473,
63,
475,
63,
13280,
3321,
8,
68,
1113,
304,
272,
408,
14244,
9840,
3957,
1124,
2083,
14,
7473,
1040,
4008,
370,
3141,
4696,
272,
315,
282,
1124,
807,
4345,
339,
6523,
642,
805,
2544,
3575,
314,
1124,
807,
1040,
370,
4840,
14,
339,
3897,
272,
4143,
272,
886,
468,
520,
1211,
267,
1124,
807,
1040,
626,
1443,
1395,
1124,
2083,
14,
7473,
1040,
4008,
14,
1124,
807,
1040,
1443,
267,
506,
6032,
14,
339,
1803,
272,
5514,
272,
886,
468,
63,
22818,
520,
1211,
267,
1124,
807,
1040,
543,
1124,
2083,
14,
7473,
1040,
4008,
6702,
370,
267,
3141,
4696,
14,
272,
408,
272,
886,
468,
63,
22818,
275,
1052,
272,
367,
790,
315,
886,
468,
26,
267,
340,
1228,
8,
68,
1113,
59,
498,
467,
4487,
14,
7473,
304,
288,
886,
468,
63,
22818,
59,
498,
61,
275,
886,
468,
59,
498,
1055,
2923,
63,
4515,
342,
267,
916,
1228,
8,
68,
1113,
59,
498,
467,
1211,
304,
288,
886,
468,
63,
22818,
59,
498,
61,
275,
9133,
63,
7473,
63,
475,
63,
13280,
3321,
8,
68,
1113,
29,
68,
1113,
59,
498,
566,
267,
587,
26,
288,
886,
468,
63,
22818,
59,
498,
61,
275,
886,
468,
59,
498,
61,
272,
372,
886,
468,
63,
22818,
421,
199,
318,
2198,
63,
6447,
8,
2408,
12,
17863,
29,
403,
304,
272,
408,
4003,
11167,
1072,
687,
26456,
63,
6447,
14,
609,
339,
6077,
701,
1788,
12,
570,
1568,
12,
10291,
1083,
12,
10291,
10463,
12,
10291,
436,
477,
12849,
8112,
14,
272,
3390,
26,
961,
805,
365,
8012,
8787,
590,
11410,
12188,
26456,
63,
6447,
14,
609,
14,
339,
3897,
272,
4143,
272,
2583,
520,
1059,
267,
6912,
370,
1318,
570,
543,
11167,
1072,
14,
272,
17863,
520,
469,
403,
1386,
1059,
12,
2716,
267,
6912,
370,
1072,
1275,
1001,
570,
402,
4565,
11167,
1072,
14,
339,
1803,
272,
5514,
272,
4565,
520,
1211,
267,
1124,
807,
1040,
402,
4565,
11167,
1072,
14,
272,
408,
272,
327,
2670,
1324,
14,
272,
30540,
275,
747,
14,
515,
14,
4832,
8,
2408,
9,
272,
340,
440,
747,
14,
515,
14,
6292,
8,
23248,
304,
267,
746,
5925,
480,
1173,
1630,
440,
2187,
3427,
78,
91,
23248,
5469,
908,
8,
23248,
29,
23248,
430,
272,
340,
17863,
365,
440,
488,
26,
267,
340,
440,
747,
14,
515,
14,
7973,
8,
30762,
2788,
17,
61,
508,
1987,
1001,
356,
288,
746,
5925,
9313,
1173,
3329,
365,
440,
1987,
1001,
356,
60,
78,
2,
435,
2574,
5310,
30762,
30273,
908,
8,
30762,
29,
30762,
430,
272,
327,
6077,
1318,
570,
1901,
1211,
14,
272,
4565,
275,
1052,
272,
3372,
63,
1278,
275,
488,
272,
8579,
63,
2747,
63,
890,
275,
488,
272,
8579,
63,
863,
63,
1760,
275,
488,
272,
8579,
63,
863,
63,
521,
275,
488,
272,
8579,
63,
863,
63,
890,
275,
488,
272,
8579,
63,
271,
863,
63,
1760,
275,
488,
272,
8579,
63,
271,
863,
63,
521,
275,
488,
272,
8579,
63,
271,
863,
63,
890,
275,
488,
272,
543,
1551,
8,
23248,
12,
283,
4848,
358,
465,
29962,
26,
267,
367,
1004,
315,
29962,
26,
288,
1004,
275,
1004,
14,
6735,
342,
288,
340,
1004,
14,
2460,
360,
5595,
6661,
23117,
355,
1004,
63,
5250,
275,
1004,
14,
1294,
11633,
355,
6748,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
604,
63,
5250,
59,
17,
2459,
59,
16,
61,
355,
4565,
59,
5252,
61,
275,
1052,
355,
1980,
288,
327,
3390,
26,
377,
89,
555,
315,
3379,
2884,
298,
607,
1009,
1674,
4226,
440,
3211,
14,
288,
916,
1004,
14,
2460,
360,
607,
1009,
1275,
26423,
1568,
23117,
355,
8579,
63,
2747,
63,
890,
275,
715,
355,
3372,
63,
1278,
275,
413,
355,
1980,
288,
916,
8579,
63,
2747,
63,
890,
436,
3372,
63,
1278,
2356,
378,
26,
355,
340,
3372,
63,
1278,
690,
378,
26,
490,
3372,
63,
1278,
4862,
413,
490,
1980,
355,
916,
3372,
63,
1278,
508,
378,
26,
490,
1004,
63,
5250,
275,
1004,
14,
1294,
342,
490
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
7535,
370,
2198,
314,
11167,
1072,
687,
26456,
63,
6447,
14,
609,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
12,
3679,
63,
646,
199,
646,
747,
199,
646,
984,
199,
646,
2022,
199,
646,
2197,
465,
4487,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
646,
8027,
14,
13563,
465,
4488,
421,
199,
318,
2198,
63,
16691,
8,
16691,
304,
272,
408,
4003,
1059,
402,
14439,
900,
687,
1072,
402,
13074,
283,
521,
7,
1414,
1901,
272,
658,
2083,
14,
7473,
2313,
339,
3897,
272,
4143,
272,
14439,
520,
1059,
267,
662,
9982,
900,
901,
1072,
687,
13074,
283,
521,
7,
1414,
14,
267,
9701,
26,
359,
10213,
2938,
3218,
26,
2300,
30352,
2300,
51,
61,
339,
1803,
272,
5514,
272,
14439,
63,
3583,
520,
2197,
14,
7473,
267,
662,
9982,
900,
465,
1124,
2083,
14,
7473,
4345,
272,
408,
272,
14439,
63,
5250,
275,
14439,
14,
1294,
11633,
272,
340,
822,
8,
16691,
63,
5250,
9,
508,
499,
26,
267,
10857,
275,
283,
16,
7,
267,
359,
10430,
12,
4696,
61,
275,
14439,
63,
5250,
272,
916,
822,
8,
16691,
63,
5250,
9,
508,
650,
26,
267,
359,
8419,
12,
9395,
12,
4696,
61,
275,
14439,
63,
5250,
272,
587,
26,
267,
746,
9070,
9313,
9184,
1125,
14,
662,
9982,
900,
1630,
440,
1172,
499,
503,
650,
1504,
3427,
78,
2,
435,
2892,
5310,
4489,
30273,
908,
8,
4489,
29,
16691,
63,
5250,
430,
272,
10857,
63,
442,
275,
1109,
8,
1609,
8,
8419,
430,
272,
9395,
63,
442,
275,
1109,
8,
1609,
8,
10430,
430,
272,
4696,
63,
442,
275,
1109,
8,
1609,
8,
4515,
430,
272,
21131,
63,
442,
275,
1109,
1332,
1609,
8,
4515,
9,
446,
4696,
63,
442,
9,
1182,
378,
14,
4587,
9,
272,
14439,
63,
3583,
275,
4487,
14,
7473,
8,
8419,
29,
8419,
63,
442,
12,
2892,
9395,
29,
10430,
63,
442,
12,
2892,
4696,
29,
4515,
63,
442,
12,
2892,
21131,
29,
19579,
4515,
63,
442,
9,
272,
372,
14439,
63,
3583,
421,
199,
318,
9133,
63,
7473,
63,
475,
63,
13280,
3321,
8,
68,
1113,
304,
272,
408,
14244,
9840,
3957,
1124,
2083,
14,
7473,
1040,
4008,
370,
3141,
4696,
272,
315,
282,
1124,
807,
4345,
339,
6523,
642,
805,
2544,
3575,
314,
1124,
807,
1040,
370,
4840,
14,
339,
3897,
272,
4143,
272,
886,
468,
520,
1211,
267,
1124,
807,
1040,
626,
1443,
1395,
1124,
2083,
14,
7473,
1040,
4008,
14,
1124,
807,
1040,
1443,
267,
506,
6032,
14,
339,
1803,
272,
5514,
272,
886,
468,
63,
22818,
520,
1211,
267,
1124,
807,
1040,
543,
1124,
2083,
14,
7473,
1040,
4008,
6702,
370,
267,
3141,
4696,
14,
272,
408,
272,
886,
468,
63,
22818,
275,
1052,
272,
367,
790,
315,
886,
468,
26,
267,
340,
1228,
8,
68,
1113,
59,
498,
467,
4487,
14,
7473,
304,
288,
886,
468,
63,
22818,
59,
498,
61,
275,
886,
468,
59,
498,
1055,
2923,
63,
4515,
342,
267,
916,
1228,
8,
68,
1113,
59,
498,
467,
1211,
304,
288,
886,
468,
63,
22818,
59,
498,
61,
275,
9133,
63,
7473,
63,
475,
63,
13280,
3321,
8,
68,
1113,
29,
68,
1113,
59,
498,
566,
267,
587,
26,
288,
886,
468,
63,
22818,
59,
498,
61,
275,
886,
468,
59,
498,
61,
272,
372,
886,
468,
63,
22818,
421,
199,
318,
2198,
63,
6447,
8,
2408,
12,
17863,
29,
403,
304,
272,
408,
4003,
11167,
1072,
687,
26456,
63,
6447,
14,
609,
339,
6077,
701,
1788,
12,
570,
1568,
12,
10291,
1083,
12,
10291,
10463,
12,
10291,
436,
477,
12849,
8112,
14,
272,
3390,
26,
961,
805,
365,
8012,
8787,
590,
11410,
12188,
26456,
63,
6447,
14,
609,
14,
339,
3897,
272,
4143,
272,
2583,
520,
1059,
267,
6912,
370,
1318,
570,
543,
11167,
1072,
14,
272,
17863,
520,
469,
403,
1386,
1059,
12,
2716,
267,
6912,
370,
1072,
1275,
1001,
570,
402,
4565,
11167,
1072,
14,
339,
1803,
272,
5514,
272,
4565,
520,
1211,
267,
1124,
807,
1040,
402,
4565,
11167,
1072,
14,
272,
408,
272,
327,
2670,
1324,
14,
272,
30540,
275,
747,
14,
515,
14,
4832,
8,
2408,
9,
272,
340,
440,
747,
14,
515,
14,
6292,
8,
23248,
304,
267,
746,
5925,
480,
1173,
1630,
440,
2187,
3427,
78,
91,
23248,
5469,
908,
8,
23248,
29,
23248,
430,
272,
340,
17863,
365,
440,
488,
26,
267,
340,
440,
747,
14,
515,
14,
7973,
8,
30762,
2788,
17,
61,
508,
1987,
1001,
356,
288,
746,
5925,
9313,
1173,
3329,
365,
440,
1987,
1001,
356,
60,
78,
2,
435,
2574,
5310,
30762,
30273,
908,
8,
30762,
29,
30762,
430,
272,
327,
6077,
1318,
570,
1901,
1211,
14,
272,
4565,
275,
1052,
272,
3372,
63,
1278,
275,
488,
272,
8579,
63,
2747,
63,
890,
275,
488,
272,
8579,
63,
863,
63,
1760,
275,
488,
272,
8579,
63,
863,
63,
521,
275,
488,
272,
8579,
63,
863,
63,
890,
275,
488,
272,
8579,
63,
271,
863,
63,
1760,
275,
488,
272,
8579,
63,
271,
863,
63,
521,
275,
488,
272,
8579,
63,
271,
863,
63,
890,
275,
488,
272,
543,
1551,
8,
23248,
12,
283,
4848,
358,
465,
29962,
26,
267,
367,
1004,
315,
29962,
26,
288,
1004,
275,
1004,
14,
6735,
342,
288,
340,
1004,
14,
2460,
360,
5595,
6661,
23117,
355,
1004,
63,
5250,
275,
1004,
14,
1294,
11633,
355,
6748,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
604,
63,
5250,
59,
17,
2459,
59,
16,
61,
355,
4565,
59,
5252,
61,
275,
1052,
355,
1980,
288,
327,
3390,
26,
377,
89,
555,
315,
3379,
2884,
298,
607,
1009,
1674,
4226,
440,
3211,
14,
288,
916,
1004,
14,
2460,
360,
607,
1009,
1275,
26423,
1568,
23117,
355,
8579,
63,
2747,
63,
890,
275,
715,
355,
3372,
63,
1278,
275,
413,
355,
1980,
288,
916,
8579,
63,
2747,
63,
890,
436,
3372,
63,
1278,
2356,
378,
26,
355,
340,
3372,
63,
1278,
690,
378,
26,
490,
3372,
63,
1278,
4862,
413,
490,
1980,
355,
916,
3372,
63,
1278,
508,
378,
26,
490,
1004,
63,
5250,
275,
1004,
14,
1294,
342,
490,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
archyufa/CloudFerry
|
cloudferrylib/os/actions/detach_used_volumes.py
|
12
|
1090
|
# Copyright (c) 2014 Mirantis 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.
from cloudferrylib.base.action import action
from cloudferrylib.utils import utils as utl
class DetachVolumes(action.Action):
def run(self, storage_info={}, **kwargs):
resource_storage = self.cloud.resources[utl.STORAGE_RESOURCE]
for (vol_id, vol_info) \
in storage_info[utl.VOLUMES_TYPE].iteritems():
if 'instance' in vol_info['meta']:
if vol_info['meta']['instance']:
resource_storage.detach_volume(vol_id)
return {}
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
603,
723,
4466,
83,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
844,
2736,
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,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
4319,
2281,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
3,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
504,
8002,
2412,
651,
773,
14,
1095,
14,
1287,
492,
1595,
199,
504,
8002,
2412,
651,
773,
14,
1208,
492,
3778,
465,
11430,
76,
421,
199,
533,
577,
386,
1225,
32480,
8,
1287,
14,
3310,
304,
339,
347,
1255,
8,
277,
12,
4887,
63,
815,
10324,
1011,
958,
304,
267,
2073,
63,
3494,
275,
291,
14,
4091,
14,
4435,
59,
337,
76,
14,
17467,
63,
14110,
61,
267,
367,
334,
5650,
63,
344,
12,
5236,
63,
815,
9,
971,
355,
315,
4887,
63,
815,
59,
337,
76,
14,
12209,
2639,
654,
63,
2711,
1055,
4611,
837,
288,
340,
283,
842,
7,
315,
5236,
63,
815,
459,
2024,
2565,
355,
340,
5236,
63,
815,
459,
2024,
2545,
842,
2565,
490,
2073,
63,
3494,
14,
14481,
63,
2405,
8,
5650,
63,
344,
9,
267,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6927,
603,
723,
4466,
83,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
844,
2736,
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,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
4319,
2281,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
3,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
504,
8002,
2412,
651,
773,
14,
1095,
14,
1287,
492,
1595,
199,
504,
8002,
2412,
651,
773,
14,
1208,
492,
3778,
465,
11430,
76,
421,
199,
533,
577,
386,
1225,
32480,
8,
1287,
14,
3310,
304,
339,
347,
1255,
8,
277,
12,
4887,
63,
815,
10324,
1011,
958,
304,
267,
2073,
63,
3494,
275,
291,
14,
4091,
14,
4435,
59,
337,
76,
14,
17467,
63,
14110,
61,
267,
367,
334,
5650,
63,
344,
12,
5236,
63,
815,
9,
971,
355,
315,
4887,
63,
815,
59,
337,
76,
14,
12209,
2639,
654,
63,
2711,
1055,
4611,
837,
288,
340,
283,
842,
7,
315,
5236,
63,
815,
459,
2024,
2565,
355,
340,
5236,
63,
815,
459,
2024,
2545,
842,
2565,
490,
2073,
63,
3494,
14,
14481,
63,
2405,
8,
5650,
63,
344,
9,
267,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ESMG/ESMG-configs
|
CCS1/plot_vort.py
|
1
|
2295
|
import numpy as np
import netCDF4
import os
import sys
import subprocess
import pyroms
from pyroms_toolbox import jday2date
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
# draw line around map projection limb.
# color background of map projection region.
# missing values over land will show up this color.
# plot sst, then ice with pcolor
# add a title.
#year = int(sys.argv[1])
#lst_year = [year]
lst_file = []
#for year in lst_year:
# year = np.str(year)
#lst = subprocess.getoutput('ls clima/*.nc')
lst = subprocess.getoutput('ls 19800110.ocean_daily.nc')
lst = lst.split()
lst_file = lst_file + lst
#grd = pyroms_toolbox.BGrid_GFDL.get_nc_BGrid_GFDL('prog.nc')
grd = netCDF4.Dataset('sea_ice_geometry.nc', "r")
clat = grd.variables["geolatb"][:]
clon = grd.variables["geolonb"][:]
m = Basemap(llcrnrlon=-121., llcrnrlat=17., urcrnrlon=-125.0, urcrnrlat=53.0,\
rsphere=(6378137.00,6356752.3142),\
resolution='h', projection='lcc',\
lat_0=30., lat_1=40.0, lon_0=-78.)
x, y = m(clon, clat)
levels = np.arange(-.6, 0.6, 0.01)
cmap = plt.cm.get_cmap("seismic")
for file in lst_file:
print("Plotting "+file)
nc = netCDF4.Dataset(file, "r")
time = nc.variables["time"][:]
ntim = len(time)
# for it in range(10):
for it in range(0,ntim,30):
fig = plt.figure(figsize=(4,9))
ax = fig.add_subplot(111)
ax.set_aspect('equal')
# ax.axis(xmin=-300,xmax=300)
# m.drawmapboundary(fill_color='0.3')
m.drawcoastlines()
ssh = nc.variables["RV"][it,0,:-1,:-1]
ssh *= 1.e4
time = nc.variables["time"][it]
cs = m.contourf(x, y, ssh, levels=levels, cmap=cmap, extend='both')
# csa = m.contour(x, y, ssh, levels=levels, linewidths=(0.5,))
# cs = plt.contourf(clon, clat, ssh, levels=levels, cmap=cmap, extend='both')
plt.title('Surface RV')
# csa = plt.contour(clon, clat, ssh, levels=levels, linewidths=(0.5,))
cbaxes = fig.add_axes([0.1, 0.05, 0.8, 0.02])
plt.colorbar(orientation='horizontal', cax=cbaxes)
print('printing frame:', it)
fig.savefig('movie/vort_%(number)04d.png'%{'number': it})
plt.close()
nc.close()
|
gpl-3.0
|
[
646,
2680,
465,
980,
199,
646,
1851,
18967,
20,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
646,
1134,
417,
83,
199,
504,
1134,
417,
83,
63,
3557,
1977,
492,
1335,
2977,
18,
602,
199,
504,
22513,
63,
3557,
75,
1405,
14,
1095,
1130,
492,
3523,
1130,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
2197,
492,
2197,
421,
199,
3,
5954,
1004,
6818,
2341,
14777,
1212,
887,
14,
199,
3,
3164,
8020,
402,
2341,
14777,
4897,
14,
199,
3,
4124,
1338,
1806,
20078,
911,
2498,
1536,
642,
3164,
14,
199,
3,
5137,
308,
270,
12,
2066,
284,
301,
543,
299,
2326,
199,
3,
1050,
282,
2538,
14,
199,
3,
3403,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
3,
6916,
63,
3403,
275,
359,
3403,
61,
199,
199,
6916,
63,
493,
275,
942,
199,
199,
3,
509,
5361,
315,
9877,
63,
3403,
26,
199,
3,
259,
5361,
275,
980,
14,
495,
8,
3403,
9,
199,
3,
6916,
275,
3873,
14,
362,
1199,
360,
478,
5053,
391,
20362,
7966,
358,
199,
6916,
275,
3873,
14,
362,
1199,
360,
478,
413,
2905,
4587,
709,
14,
31737,
63,
18621,
14,
7966,
358,
199,
6916,
275,
9877,
14,
1294,
342,
199,
6916,
63,
493,
275,
9877,
63,
493,
435,
9877,
199,
199,
3,
2587,
68,
275,
1134,
417,
83,
63,
3557,
1977,
14,
34,
7900,
63,
39,
7902,
44,
14,
362,
63,
7966,
63,
34,
7900,
63,
39,
7902,
44,
360,
6595,
14,
7966,
358,
199,
2587,
68,
275,
1851,
18967,
20,
14,
9271,
360,
27590,
63,
1885,
63,
7660,
14,
7966,
297,
298,
82,
531,
199,
199,
429,
292,
275,
486,
6883,
14,
3669,
905,
303,
393,
292,
66,
937,
5873,
199,
429,
265,
275,
486,
6883,
14,
3669,
905,
303,
393,
265,
66,
937,
5873,
199,
199,
77,
275,
3523,
1130,
8,
914,
1556,
78,
4308,
265,
4022,
10753,
2020,
18338,
1556,
78,
4308,
292,
29,
1196,
2020,
7629,
1556,
78,
4308,
265,
4022,
6889,
14,
16,
12,
7629,
1556,
78,
4308,
292,
29,
2481,
14,
16,
4202,
288,
13684,
1681,
2687,
22,
12046,
7498,
14,
383,
12,
31062,
1822,
2528,
14,
8988,
18,
26323,
288,
12401,
534,
72,
297,
14777,
534,
76,
2055,
30989,
288,
8396,
63,
16,
29,
1216,
2020,
8396,
63,
17,
29,
2167,
14,
16,
12,
6132,
63,
16,
4022,
2277,
4959,
199,
88,
12,
612,
275,
333,
8,
429,
265,
12,
824,
292,
9,
199,
11402,
275,
980,
14,
5605,
2801,
14,
22,
12,
378,
14,
22,
12,
378,
14,
614,
9,
199,
16513,
275,
4488,
14,
4400,
14,
362,
63,
16513,
480,
261,
374,
15003,
531,
199,
199,
509,
570,
315,
9877,
63,
493,
26,
272,
870,
480,
10711,
1337,
7210,
493,
9,
272,
12698,
275,
1851,
18967,
20,
14,
9271,
8,
493,
12,
298,
82,
531,
272,
900,
275,
12698,
14,
3669,
905,
521,
937,
5873,
272,
302,
2906,
275,
822,
8,
521,
9,
199,
3,
257,
367,
652,
315,
1425,
8,
709,
304,
272,
367,
652,
315,
1425,
8,
16,
12,
78,
2906,
12,
1216,
304,
267,
6085,
275,
4488,
14,
8941,
8,
23899,
2687,
20,
12,
25,
430,
267,
2185,
275,
6085,
14,
525,
63,
13334,
8,
6673,
9,
267,
2185,
14,
409,
63,
18658,
360,
1452,
358,
199,
3,
755,
2185,
14,
3127,
8,
21601,
4022,
5863,
12,
28961,
29,
5863,
9,
199,
3,
755,
333,
14,
5485,
1130,
9891,
8,
4498,
63,
2326,
534,
16,
14,
19,
358,
267,
333,
14,
5485,
331,
1810,
1278,
342,
267,
8635,
275,
12698,
14,
3669,
905,
28841,
9210,
390,
12,
16,
12,
6809,
17,
12,
6809,
17,
61,
267,
8635,
9000,
413,
14,
69,
20,
267,
900,
275,
12698,
14,
3669,
905,
521,
9210,
390,
61,
267,
7117,
275,
333,
14,
17798,
70,
8,
88,
12,
612,
12,
8635,
12,
11106,
29,
11402,
12,
14920,
29,
16513,
12,
12247,
534,
10727,
358,
199,
3,
755,
286,
2231,
275,
333,
14,
17798,
8,
88,
12,
612,
12,
8635,
12,
11106,
29,
11402,
12,
21213,
83,
2687,
16,
14,
21,
4641,
199,
3,
755,
7117,
275,
4488,
14,
17798,
70,
8,
429,
265,
12,
824,
292,
12,
8635,
12,
11106,
29,
11402,
12,
14920,
29,
16513,
12,
12247,
534,
10727,
358,
267,
4488,
14,
1213,
360,
16923,
820,
54,
358,
199,
3,
755,
286,
2231,
275,
4488,
14,
17798,
8,
429,
265,
12,
824,
292,
12,
8635,
12,
11106,
29,
11402,
12,
21213,
83,
2687,
16,
14,
21,
4641,
398,
7434,
6402,
275,
6085,
14,
525,
63,
6402,
779,
16,
14,
17,
12,
378,
14,
1717,
12,
378,
14,
24,
12,
378,
14,
996,
566,
267,
4488,
14,
30995,
8,
17001,
534,
11392,
297,
286,
1219,
29,
2894,
6402,
9,
398,
870,
360,
26514,
2787,
6536,
652,
9,
267,
6085,
14,
19556,
360,
10888,
15,
86,
361,
20892,
1955,
9,
966,
68,
14,
4524,
5956,
1445,
1955,
356,
652,
1552,
267,
4488,
14,
1600,
342,
339,
12698,
14,
1600,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2680,
465,
980,
199,
646,
1851,
18967,
20,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
646,
1134,
417,
83,
199,
504,
1134,
417,
83,
63,
3557,
1977,
492,
1335,
2977,
18,
602,
199,
504,
22513,
63,
3557,
75,
1405,
14,
1095,
1130,
492,
3523,
1130,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
2197,
492,
2197,
421,
199,
3,
5954,
1004,
6818,
2341,
14777,
1212,
887,
14,
199,
3,
3164,
8020,
402,
2341,
14777,
4897,
14,
199,
3,
4124,
1338,
1806,
20078,
911,
2498,
1536,
642,
3164,
14,
199,
3,
5137,
308,
270,
12,
2066,
284,
301,
543,
299,
2326,
199,
3,
1050,
282,
2538,
14,
199,
3,
3403,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
3,
6916,
63,
3403,
275,
359,
3403,
61,
199,
199,
6916,
63,
493,
275,
942,
199,
199,
3,
509,
5361,
315,
9877,
63,
3403,
26,
199,
3,
259,
5361,
275,
980,
14,
495,
8,
3403,
9,
199,
3,
6916,
275,
3873,
14,
362,
1199,
360,
478,
5053,
391,
20362,
7966,
358,
199,
6916,
275,
3873,
14,
362,
1199,
360,
478,
413,
2905,
4587,
709,
14,
31737,
63,
18621,
14,
7966,
358,
199,
6916,
275,
9877,
14,
1294,
342,
199,
6916,
63,
493,
275,
9877,
63,
493,
435,
9877,
199,
199,
3,
2587,
68,
275,
1134,
417,
83,
63,
3557,
1977,
14,
34,
7900,
63,
39,
7902,
44,
14,
362,
63,
7966,
63,
34,
7900,
63,
39,
7902,
44,
360,
6595,
14,
7966,
358,
199,
2587,
68,
275,
1851,
18967,
20,
14,
9271,
360,
27590,
63,
1885,
63,
7660,
14,
7966,
297,
298,
82,
531,
199,
199,
429,
292,
275,
486,
6883,
14,
3669,
905,
303,
393,
292,
66,
937,
5873,
199,
429,
265,
275,
486,
6883,
14,
3669,
905,
303,
393,
265,
66,
937,
5873,
199,
199,
77,
275,
3523,
1130,
8,
914,
1556,
78,
4308,
265,
4022,
10753,
2020,
18338,
1556,
78,
4308,
292,
29,
1196,
2020,
7629,
1556,
78,
4308,
265,
4022,
6889,
14,
16,
12,
7629,
1556,
78,
4308,
292,
29,
2481,
14,
16,
4202,
288,
13684,
1681,
2687,
22,
12046,
7498,
14,
383,
12,
31062,
1822,
2528,
14,
8988,
18,
26323,
288,
12401,
534,
72,
297,
14777,
534,
76,
2055,
30989,
288,
8396,
63,
16,
29,
1216,
2020,
8396,
63,
17,
29,
2167,
14,
16,
12,
6132,
63,
16,
4022,
2277,
4959,
199,
88,
12,
612,
275,
333,
8,
429,
265,
12,
824,
292,
9,
199,
11402,
275,
980,
14,
5605,
2801,
14,
22,
12,
378,
14,
22,
12,
378,
14,
614,
9,
199,
16513,
275,
4488,
14,
4400,
14,
362,
63,
16513,
480,
261,
374,
15003,
531,
199,
199,
509,
570,
315,
9877,
63,
493,
26,
272,
870,
480,
10711,
1337,
7210,
493,
9,
272,
12698,
275,
1851,
18967,
20,
14,
9271,
8,
493,
12,
298,
82,
531,
272,
900,
275,
12698,
14,
3669,
905,
521,
937,
5873,
272,
302,
2906,
275,
822,
8,
521,
9,
199,
3,
257,
367,
652,
315,
1425,
8,
709,
304,
272,
367,
652,
315,
1425,
8,
16,
12,
78,
2906,
12,
1216,
304,
267,
6085,
275,
4488,
14,
8941,
8,
23899,
2687,
20,
12,
25,
430,
267,
2185,
275,
6085,
14,
525,
63,
13334,
8,
6673,
9,
267,
2185,
14,
409,
63,
18658,
360,
1452,
358,
199,
3,
755,
2185,
14,
3127,
8,
21601,
4022,
5863,
12,
28961,
29,
5863,
9,
199,
3,
755,
333,
14,
5485,
1130,
9891,
8,
4498,
63,
2326,
534,
16,
14,
19,
358,
267,
333,
14,
5485,
331,
1810,
1278,
342,
267,
8635,
275,
12698,
14,
3669,
905,
28841,
9210,
390,
12,
16,
12,
6809,
17,
12,
6809,
17,
61,
267,
8635,
9000,
413,
14,
69,
20,
267,
900,
275,
12698,
14,
3669,
905,
521,
9210,
390,
61,
267,
7117,
275,
333,
14,
17798,
70,
8,
88,
12,
612,
12,
8635,
12,
11106,
29,
11402,
12,
14920,
29,
16513,
12,
12247,
534,
10727,
358,
199,
3,
755,
286,
2231,
275,
333,
14,
17798,
8,
88,
12,
612,
12,
8635,
12,
11106,
29,
11402,
12,
21213,
83,
2687,
16,
14,
21,
4641,
199,
3,
755,
7117,
275,
4488,
14,
17798,
70,
8,
429,
265,
12,
824,
292,
12,
8635,
12,
11106,
29,
11402,
12,
14920,
29,
16513,
12,
12247,
534,
10727,
358,
267,
4488,
14,
1213,
360,
16923,
820,
54,
358,
199,
3,
755,
286,
2231,
275,
4488,
14,
17798,
8,
429,
265,
12,
824,
292,
12,
8635,
12,
11106,
29,
11402,
12,
21213,
83,
2687,
16,
14,
21,
4641,
398,
7434,
6402,
275,
6085,
14,
525,
63,
6402,
779,
16,
14,
17,
12,
378,
14,
1717,
12,
378,
14,
24,
12,
378,
14,
996,
566,
267,
4488,
14,
30995,
8,
17001,
534,
11392,
297,
286,
1219,
29,
2894,
6402,
9,
398,
870,
360,
26514,
2787,
6536,
652,
9,
267,
6085,
14,
19556,
360,
10888,
15,
86,
361,
20892,
1955,
9,
966,
68,
14,
4524,
5956,
1445,
1955,
356,
652,
1552,
267,
4488,
14,
1600,
342,
339,
12698,
14,
1600,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
|
304
|
2040
|
"""Define names for all type symbols known in the standard interpreter.
Types that are part of optional modules (e.g. array) are not listed.
"""
import sys
# Iterators in Python aren't a matter of type but of protocol. A large
# and changing number of builtin types implement *some* flavor of
# iterator. Don't check the type! Use hasattr to check for both
# "__iter__" and "next" attributes instead.
NoneType = type(None)
TypeType = type
ObjectType = object
IntType = int
LongType = long
FloatType = float
BooleanType = bool
try:
ComplexType = complex
except NameError:
pass
StringType = str
# StringTypes is already outdated. Instead of writing "type(x) in
# types.StringTypes", you should use "isinstance(x, basestring)". But
# we keep around for compatibility with Python 2.2.
try:
UnicodeType = unicode
StringTypes = (StringType, UnicodeType)
except NameError:
StringTypes = (StringType,)
BufferType = buffer
TupleType = tuple
ListType = list
DictType = DictionaryType = dict
def _f(): pass
FunctionType = type(_f)
LambdaType = type(lambda: None) # Same as FunctionType
CodeType = type(_f.func_code)
def _g():
yield 1
GeneratorType = type(_g())
class _C:
def _m(self): pass
ClassType = type(_C)
UnboundMethodType = type(_C._m) # Same as MethodType
_x = _C()
InstanceType = type(_x)
MethodType = type(_x._m)
BuiltinFunctionType = type(len)
BuiltinMethodType = type([].append) # Same as BuiltinFunctionType
ModuleType = type(sys)
FileType = file
XRangeType = xrange
try:
raise TypeError
except TypeError:
tb = sys.exc_info()[2]
TracebackType = type(tb)
FrameType = type(tb.tb_frame)
del tb
SliceType = slice
EllipsisType = type(Ellipsis)
DictProxyType = type(TypeType.__dict__)
NotImplementedType = type(NotImplemented)
# For Jython, the following two types are identical
GetSetDescriptorType = type(FunctionType.func_code)
MemberDescriptorType = type(FunctionType.func_globals)
del sys, _f, _g, _C, _x # Not for export
|
gpl-2.0
|
[
624,
16213,
1561,
367,
1006,
730,
6698,
6040,
315,
314,
4465,
12693,
14,
199,
199,
4100,
626,
787,
1777,
402,
2716,
4621,
334,
69,
14,
71,
14,
1625,
9,
787,
440,
10532,
14,
199,
624,
199,
646,
984,
199,
199,
3,
11953,
2750,
315,
2018,
10621,
1133,
282,
17247,
402,
730,
1325,
402,
4113,
14,
221,
437,
7031,
199,
3,
436,
13729,
1329,
402,
6762,
2943,
5669,
627,
3972,
10,
8541,
402,
199,
3,
6122,
14,
221,
7529,
1133,
1104,
314,
730,
1,
221,
3645,
2688,
370,
1104,
367,
3865,
199,
3,
4396,
1661,
16526,
436,
298,
2184,
2,
3004,
3140,
14,
199,
199,
26855,
275,
730,
8,
403,
9,
199,
804,
804,
275,
730,
199,
1692,
804,
275,
909,
199,
199,
29610,
275,
1109,
199,
9551,
804,
275,
1846,
199,
5136,
804,
275,
2069,
199,
4082,
804,
275,
2155,
199,
893,
26,
272,
19178,
804,
275,
6114,
199,
2590,
12746,
26,
272,
986,
199,
199,
22463,
275,
620,
199,
199,
3,
2624,
4100,
365,
2575,
734,
19074,
14,
221,
15345,
402,
3575,
298,
466,
8,
88,
9,
315,
199,
3,
2943,
14,
1558,
4100,
401,
1265,
1077,
675,
298,
6074,
8,
88,
12,
7116,
30351,
221,
11017,
199,
3,
781,
4215,
6818,
367,
7163,
543,
2018,
499,
14,
18,
14,
199,
893,
26,
272,
6140,
804,
275,
2649,
272,
2624,
4100,
275,
334,
22463,
12,
6140,
804,
9,
199,
2590,
12746,
26,
272,
2624,
4100,
275,
334,
22463,
4258,
199,
199,
3299,
804,
275,
3335,
199,
199,
7075,
804,
275,
2008,
199,
22113,
275,
769,
199,
2141,
804,
275,
11932,
804,
275,
1211,
199,
199,
318,
485,
70,
837,
986,
199,
26371,
275,
730,
1547,
70,
9,
199,
21350,
804,
275,
730,
8,
2734,
26,
488,
9,
260,
327,
14766,
465,
6801,
804,
199,
3034,
804,
275,
730,
1547,
70,
14,
1532,
63,
600,
9,
199,
199,
318,
485,
71,
837,
272,
1995,
413,
199,
7599,
804,
275,
730,
1547,
71,
1012,
199,
199,
533,
485,
35,
26,
272,
347,
485,
77,
8,
277,
304,
986,
199,
31165,
275,
730,
1547,
35,
9,
199,
1358,
3556,
24674,
275,
730,
1547,
35,
423,
77,
9,
260,
327,
14766,
465,
9075,
804,
199,
63,
88,
275,
485,
35,
342,
199,
3244,
804,
275,
730,
1547,
88,
9,
199,
24674,
275,
730,
1547,
88,
423,
77,
9,
199,
199,
12306,
26371,
275,
730,
8,
552,
9,
199,
12306,
24674,
275,
730,
779,
1055,
740,
9,
258,
327,
14766,
465,
22422,
26371,
199,
199,
21820,
275,
730,
8,
1274,
9,
199,
20683,
275,
570,
199,
56,
4709,
804,
275,
4945,
199,
199,
893,
26,
272,
746,
3146,
199,
2590,
3146,
26,
272,
7070,
275,
984,
14,
2804,
63,
815,
3430,
18,
61,
272,
15273,
804,
275,
730,
8,
5842,
9,
272,
11726,
804,
275,
730,
8,
5842,
14,
5842,
63,
1943,
9,
272,
2150,
7070,
199,
199,
14034,
804,
275,
6014,
199,
23525,
2316,
804,
275,
730,
8,
23525,
2316,
9,
199,
199,
2141,
4936,
804,
275,
730,
8,
804,
804,
855,
807,
3368,
199,
14278,
804,
275,
730,
8,
14278,
9,
199,
199,
3,
2104,
25333,
12,
314,
2569,
2877,
2943,
787,
13130,
199,
1002,
1084,
4311,
804,
275,
730,
8,
26371,
14,
1532,
63,
600,
9,
199,
7021,
4311,
804,
275,
730,
8,
26371,
14,
1532,
63,
8473,
9,
199,
199,
2264,
984,
12,
485,
70,
12,
485,
71,
12,
485,
35,
12,
485,
88,
13235,
327,
2832,
367,
4843,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
16213,
1561,
367,
1006,
730,
6698,
6040,
315,
314,
4465,
12693,
14,
199,
199,
4100,
626,
787,
1777,
402,
2716,
4621,
334,
69,
14,
71,
14,
1625,
9,
787,
440,
10532,
14,
199,
624,
199,
646,
984,
199,
199,
3,
11953,
2750,
315,
2018,
10621,
1133,
282,
17247,
402,
730,
1325,
402,
4113,
14,
221,
437,
7031,
199,
3,
436,
13729,
1329,
402,
6762,
2943,
5669,
627,
3972,
10,
8541,
402,
199,
3,
6122,
14,
221,
7529,
1133,
1104,
314,
730,
1,
221,
3645,
2688,
370,
1104,
367,
3865,
199,
3,
4396,
1661,
16526,
436,
298,
2184,
2,
3004,
3140,
14,
199,
199,
26855,
275,
730,
8,
403,
9,
199,
804,
804,
275,
730,
199,
1692,
804,
275,
909,
199,
199,
29610,
275,
1109,
199,
9551,
804,
275,
1846,
199,
5136,
804,
275,
2069,
199,
4082,
804,
275,
2155,
199,
893,
26,
272,
19178,
804,
275,
6114,
199,
2590,
12746,
26,
272,
986,
199,
199,
22463,
275,
620,
199,
199,
3,
2624,
4100,
365,
2575,
734,
19074,
14,
221,
15345,
402,
3575,
298,
466,
8,
88,
9,
315,
199,
3,
2943,
14,
1558,
4100,
401,
1265,
1077,
675,
298,
6074,
8,
88,
12,
7116,
30351,
221,
11017,
199,
3,
781,
4215,
6818,
367,
7163,
543,
2018,
499,
14,
18,
14,
199,
893,
26,
272,
6140,
804,
275,
2649,
272,
2624,
4100,
275,
334,
22463,
12,
6140,
804,
9,
199,
2590,
12746,
26,
272,
2624,
4100,
275,
334,
22463,
4258,
199,
199,
3299,
804,
275,
3335,
199,
199,
7075,
804,
275,
2008,
199,
22113,
275,
769,
199,
2141,
804,
275,
11932,
804,
275,
1211,
199,
199,
318,
485,
70,
837,
986,
199,
26371,
275,
730,
1547,
70,
9,
199,
21350,
804,
275,
730,
8,
2734,
26,
488,
9,
260,
327,
14766,
465,
6801,
804,
199,
3034,
804,
275,
730,
1547,
70,
14,
1532,
63,
600,
9,
199,
199,
318,
485,
71,
837,
272,
1995,
413,
199,
7599,
804,
275,
730,
1547,
71,
1012,
199,
199,
533,
485,
35,
26,
272,
347,
485,
77,
8,
277,
304,
986,
199,
31165,
275,
730,
1547,
35,
9,
199,
1358,
3556,
24674,
275,
730,
1547,
35,
423,
77,
9,
260,
327,
14766,
465,
9075,
804,
199,
63,
88,
275,
485,
35,
342,
199,
3244,
804,
275,
730,
1547,
88,
9,
199,
24674,
275,
730,
1547,
88,
423,
77,
9,
199,
199,
12306,
26371,
275,
730,
8,
552,
9,
199,
12306,
24674,
275,
730,
779,
1055,
740,
9,
258,
327,
14766,
465,
22422,
26371,
199,
199,
21820,
275,
730,
8,
1274,
9,
199,
20683,
275,
570,
199,
56,
4709,
804,
275,
4945,
199,
199,
893,
26,
272,
746,
3146,
199,
2590,
3146,
26,
272,
7070,
275,
984,
14,
2804,
63,
815,
3430,
18,
61,
272,
15273,
804,
275,
730,
8,
5842,
9,
272,
11726,
804,
275,
730,
8,
5842,
14,
5842,
63,
1943,
9,
272,
2150,
7070,
199,
199,
14034,
804,
275,
6014,
199,
23525,
2316,
804,
275,
730,
8,
23525,
2316,
9,
199,
199,
2141,
4936,
804,
275,
730,
8,
804,
804,
855,
807,
3368,
199,
14278,
804,
275,
730,
8,
14278,
9,
199,
199,
3,
2104,
25333,
12,
314,
2569,
2877,
2943,
787,
13130,
199,
1002,
1084,
4311,
804,
275,
730,
8,
26371,
14,
1532,
63,
600,
9,
199,
7021,
4311,
804,
275,
730,
8,
26371,
14,
1532,
63,
8473,
9,
199,
199,
2264,
984,
12,
485,
70,
12,
485,
71,
12,
485,
35,
12,
485,
88,
13235,
327,
2832,
367,
4843,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
vimagick/youtube-dl
|
youtube_dl/postprocessor/ffmpeg.py
|
68
|
20687
|
from __future__ import unicode_literals
import io
import os
import subprocess
import time
from .common import AudioConversionError, PostProcessor
from ..compat import (
compat_subprocess_get_DEVNULL,
)
from ..utils import (
encodeArgument,
encodeFilename,
get_exe_version,
is_outdated_version,
PostProcessingError,
prepend_extension,
shell_quote,
subtitles_filename,
dfxp2srt,
ISO639Utils,
)
class FFmpegPostProcessorError(PostProcessingError):
pass
class FFmpegPostProcessor(PostProcessor):
def __init__(self, downloader=None):
PostProcessor.__init__(self, downloader)
self._determine_executables()
def check_version(self):
if not self.available:
raise FFmpegPostProcessorError('ffmpeg or avconv not found. Please install one.')
required_version = '10-0' if self.basename == 'avconv' else '1.0'
if is_outdated_version(
self._versions[self.basename], required_version):
warning = 'Your copy of %s is outdated, update %s to version %s or newer if you encounter any errors.' % (
self.basename, self.basename, required_version)
if self._downloader:
self._downloader.report_warning(warning)
@staticmethod
def get_versions(downloader=None):
return FFmpegPostProcessor(downloader)._versions
def _determine_executables(self):
programs = ['avprobe', 'avconv', 'ffmpeg', 'ffprobe']
prefer_ffmpeg = self._downloader.params.get('prefer_ffmpeg', False)
self.basename = None
self.probe_basename = None
self._paths = None
self._versions = None
if self._downloader:
location = self._downloader.params.get('ffmpeg_location')
if location is not None:
if not os.path.exists(location):
self._downloader.report_warning(
'ffmpeg-location %s does not exist! '
'Continuing without avconv/ffmpeg.' % (location))
self._versions = {}
return
elif not os.path.isdir(location):
basename = os.path.splitext(os.path.basename(location))[0]
if basename not in programs:
self._downloader.report_warning(
'Cannot identify executable %s, its basename should be one of %s. '
'Continuing without avconv/ffmpeg.' %
(location, ', '.join(programs)))
self._versions = {}
return None
location = os.path.dirname(os.path.abspath(location))
if basename in ('ffmpeg', 'ffprobe'):
prefer_ffmpeg = True
self._paths = dict(
(p, os.path.join(location, p)) for p in programs)
self._versions = dict(
(p, get_exe_version(self._paths[p], args=['-version']))
for p in programs)
if self._versions is None:
self._versions = dict(
(p, get_exe_version(p, args=['-version'])) for p in programs)
self._paths = dict((p, p) for p in programs)
if prefer_ffmpeg:
prefs = ('ffmpeg', 'avconv')
else:
prefs = ('avconv', 'ffmpeg')
for p in prefs:
if self._versions[p]:
self.basename = p
break
if prefer_ffmpeg:
prefs = ('ffprobe', 'avprobe')
else:
prefs = ('avprobe', 'ffprobe')
for p in prefs:
if self._versions[p]:
self.probe_basename = p
break
@property
def available(self):
return self.basename is not None
@property
def executable(self):
return self._paths[self.basename]
@property
def probe_available(self):
return self.probe_basename is not None
@property
def probe_executable(self):
return self._paths[self.probe_basename]
def run_ffmpeg_multiple_files(self, input_paths, out_path, opts):
self.check_version()
oldest_mtime = min(
os.stat(encodeFilename(path)).st_mtime for path in input_paths)
opts += self._configuration_args()
files_cmd = []
for path in input_paths:
files_cmd.extend([encodeArgument('-i'), encodeFilename(path, True)])
cmd = ([encodeFilename(self.executable, True), encodeArgument('-y')] +
files_cmd +
[encodeArgument(o) for o in opts] +
[encodeFilename(self._ffmpeg_filename_argument(out_path), True)])
if self._downloader.params.get('verbose', False):
self._downloader.to_screen('[debug] ffmpeg command line: %s' % shell_quote(cmd))
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
stderr = stderr.decode('utf-8', 'replace')
msg = stderr.strip().split('\n')[-1]
raise FFmpegPostProcessorError(msg)
self.try_utime(out_path, oldest_mtime, oldest_mtime)
def run_ffmpeg(self, path, out_path, opts):
self.run_ffmpeg_multiple_files([path], out_path, opts)
def _ffmpeg_filename_argument(self, fn):
# ffmpeg broke --, see https://ffmpeg.org/trac/ffmpeg/ticket/2127 for details
if fn.startswith('-'):
return './' + fn
return fn
class FFmpegExtractAudioPP(FFmpegPostProcessor):
def __init__(self, downloader=None, preferredcodec=None, preferredquality=None, nopostoverwrites=False):
FFmpegPostProcessor.__init__(self, downloader)
if preferredcodec is None:
preferredcodec = 'best'
self._preferredcodec = preferredcodec
self._preferredquality = preferredquality
self._nopostoverwrites = nopostoverwrites
def get_audio_codec(self, path):
if not self.probe_available:
raise PostProcessingError('ffprobe or avprobe not found. Please install one.')
try:
cmd = [
encodeFilename(self.probe_executable, True),
encodeArgument('-show_streams'),
encodeFilename(self._ffmpeg_filename_argument(path), True)]
if self._downloader.params.get('verbose', False):
self._downloader.to_screen('[debug] %s command line: %s' % (self.basename, shell_quote(cmd)))
handle = subprocess.Popen(cmd, stderr=compat_subprocess_get_DEVNULL(), stdout=subprocess.PIPE, stdin=subprocess.PIPE)
output = handle.communicate()[0]
if handle.wait() != 0:
return None
except (IOError, OSError):
return None
audio_codec = None
for line in output.decode('ascii', 'ignore').split('\n'):
if line.startswith('codec_name='):
audio_codec = line.split('=')[1].strip()
elif line.strip() == 'codec_type=audio' and audio_codec is not None:
return audio_codec
return None
def run_ffmpeg(self, path, out_path, codec, more_opts):
if codec is None:
acodec_opts = []
else:
acodec_opts = ['-acodec', codec]
opts = ['-vn'] + acodec_opts + more_opts
try:
FFmpegPostProcessor.run_ffmpeg(self, path, out_path, opts)
except FFmpegPostProcessorError as err:
raise AudioConversionError(err.msg)
def run(self, information):
path = information['filepath']
filecodec = self.get_audio_codec(path)
if filecodec is None:
raise PostProcessingError('WARNING: unable to obtain file audio codec with ffprobe')
more_opts = []
if self._preferredcodec == 'best' or self._preferredcodec == filecodec or (self._preferredcodec == 'm4a' and filecodec == 'aac'):
if filecodec == 'aac' and self._preferredcodec in ['m4a', 'best']:
# Lossless, but in another container
acodec = 'copy'
extension = 'm4a'
more_opts = ['-bsf:a', 'aac_adtstoasc']
elif filecodec in ['aac', 'mp3', 'vorbis', 'opus']:
# Lossless if possible
acodec = 'copy'
extension = filecodec
if filecodec == 'aac':
more_opts = ['-f', 'adts']
if filecodec == 'vorbis':
extension = 'ogg'
else:
# MP3 otherwise.
acodec = 'libmp3lame'
extension = 'mp3'
more_opts = []
if self._preferredquality is not None:
if int(self._preferredquality) < 10:
more_opts += ['-q:a', self._preferredquality]
else:
more_opts += ['-b:a', self._preferredquality + 'k']
else:
# We convert the audio (lossy)
acodec = {'mp3': 'libmp3lame', 'aac': 'aac', 'm4a': 'aac', 'opus': 'opus', 'vorbis': 'libvorbis', 'wav': None}[self._preferredcodec]
extension = self._preferredcodec
more_opts = []
if self._preferredquality is not None:
# The opus codec doesn't support the -aq option
if int(self._preferredquality) < 10 and extension != 'opus':
more_opts += ['-q:a', self._preferredquality]
else:
more_opts += ['-b:a', self._preferredquality + 'k']
if self._preferredcodec == 'aac':
more_opts += ['-f', 'adts']
if self._preferredcodec == 'm4a':
more_opts += ['-bsf:a', 'aac_adtstoasc']
if self._preferredcodec == 'vorbis':
extension = 'ogg'
if self._preferredcodec == 'wav':
extension = 'wav'
more_opts += ['-f', 'wav']
prefix, sep, ext = path.rpartition('.') # not os.path.splitext, since the latter does not work on unicode in all setups
new_path = prefix + sep + extension
# If we download foo.mp3 and convert it to... foo.mp3, then don't delete foo.mp3, silly.
if (new_path == path or
(self._nopostoverwrites and os.path.exists(encodeFilename(new_path)))):
self._downloader.to_screen('[ffmpeg] Post-process file %s exists, skipping' % new_path)
return [], information
try:
self._downloader.to_screen('[' + self.basename + '] Destination: ' + new_path)
self.run_ffmpeg(path, new_path, acodec, more_opts)
except AudioConversionError as e:
raise PostProcessingError(
'audio conversion failed: ' + e.msg)
except Exception:
raise PostProcessingError('error running ' + self.basename)
# Try to update the date time for extracted audio file.
if information.get('filetime') is not None:
self.try_utime(
new_path, time.time(), information['filetime'],
errnote='Cannot update utime of audio file')
information['filepath'] = new_path
information['ext'] = extension
return [path], information
class FFmpegVideoConvertorPP(FFmpegPostProcessor):
def __init__(self, downloader=None, preferedformat=None):
super(FFmpegVideoConvertorPP, self).__init__(downloader)
self._preferedformat = preferedformat
def run(self, information):
path = information['filepath']
if information['ext'] == self._preferedformat:
self._downloader.to_screen('[ffmpeg] Not converting video file %s - already is in target format %s' % (path, self._preferedformat))
return [], information
options = []
if self._preferedformat == 'avi':
options.extend(['-c:v', 'libxvid', '-vtag', 'XVID'])
prefix, sep, ext = path.rpartition('.')
outpath = prefix + sep + self._preferedformat
self._downloader.to_screen('[' + 'ffmpeg' + '] Converting video from %s to %s, Destination: ' % (information['ext'], self._preferedformat) + outpath)
self.run_ffmpeg(path, outpath, options)
information['filepath'] = outpath
information['format'] = self._preferedformat
information['ext'] = self._preferedformat
return [path], information
class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
def run(self, information):
if information['ext'] not in ['mp4', 'mkv']:
self._downloader.to_screen('[ffmpeg] Subtitles can only be embedded in mp4 or mkv files')
return [], information
subtitles = information.get('requested_subtitles')
if not subtitles:
self._downloader.to_screen('[ffmpeg] There aren\'t any subtitles to embed')
return [], information
sub_langs = list(subtitles.keys())
filename = information['filepath']
sub_filenames = [subtitles_filename(filename, lang, sub_info['ext']) for lang, sub_info in subtitles.items()]
input_files = [filename] + sub_filenames
opts = [
'-map', '0',
'-c', 'copy',
# Don't copy the existing subtitles, we may be running the
# postprocessor a second time
'-map', '-0:s',
]
if information['ext'] == 'mp4':
opts += ['-c:s', 'mov_text']
for (i, lang) in enumerate(sub_langs):
opts.extend(['-map', '%d:0' % (i + 1)])
lang_code = ISO639Utils.short2long(lang)
if lang_code is not None:
opts.extend(['-metadata:s:s:%d' % i, 'language=%s' % lang_code])
temp_filename = prepend_extension(filename, 'temp')
self._downloader.to_screen('[ffmpeg] Embedding subtitles in \'%s\'' % filename)
self.run_ffmpeg_multiple_files(input_files, temp_filename, opts)
os.remove(encodeFilename(filename))
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
return sub_filenames, information
class FFmpegMetadataPP(FFmpegPostProcessor):
def run(self, info):
metadata = {}
if info.get('title') is not None:
metadata['title'] = info['title']
if info.get('upload_date') is not None:
metadata['date'] = info['upload_date']
if info.get('artist') is not None:
metadata['artist'] = info['artist']
elif info.get('uploader') is not None:
metadata['artist'] = info['uploader']
elif info.get('uploader_id') is not None:
metadata['artist'] = info['uploader_id']
if info.get('description') is not None:
metadata['description'] = info['description']
metadata['comment'] = info['description']
if info.get('webpage_url') is not None:
metadata['purl'] = info['webpage_url']
if info.get('album') is not None:
metadata['album'] = info['album']
if not metadata:
self._downloader.to_screen('[ffmpeg] There isn\'t any metadata to add')
return [], info
filename = info['filepath']
temp_filename = prepend_extension(filename, 'temp')
if info['ext'] == 'm4a':
options = ['-vn', '-acodec', 'copy']
else:
options = ['-c', 'copy']
for (name, value) in metadata.items():
options.extend(['-metadata', '%s=%s' % (name, value)])
self._downloader.to_screen('[ffmpeg] Adding metadata to \'%s\'' % filename)
self.run_ffmpeg(filename, temp_filename, options)
os.remove(encodeFilename(filename))
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
return [], info
class FFmpegMergerPP(FFmpegPostProcessor):
def run(self, info):
filename = info['filepath']
temp_filename = prepend_extension(filename, 'temp')
args = ['-c', 'copy', '-map', '0:v:0', '-map', '1:a:0']
self._downloader.to_screen('[ffmpeg] Merging formats into "%s"' % filename)
self.run_ffmpeg_multiple_files(info['__files_to_merge'], temp_filename, args)
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
return info['__files_to_merge'], info
def can_merge(self):
# TODO: figure out merge-capable ffmpeg version
if self.basename != 'avconv':
return True
required_version = '10-0'
if is_outdated_version(
self._versions[self.basename], required_version):
warning = ('Your copy of %s is outdated and unable to properly mux separate video and audio files, '
'youtube-dl will download single file media. '
'Update %s to version %s or newer to fix this.') % (
self.basename, self.basename, required_version)
if self._downloader:
self._downloader.report_warning(warning)
return False
return True
class FFmpegFixupStretchedPP(FFmpegPostProcessor):
def run(self, info):
stretched_ratio = info.get('stretched_ratio')
if stretched_ratio is None or stretched_ratio == 1:
return [], info
filename = info['filepath']
temp_filename = prepend_extension(filename, 'temp')
options = ['-c', 'copy', '-aspect', '%f' % stretched_ratio]
self._downloader.to_screen('[ffmpeg] Fixing aspect ratio in "%s"' % filename)
self.run_ffmpeg(filename, temp_filename, options)
os.remove(encodeFilename(filename))
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
return [], info
class FFmpegFixupM4aPP(FFmpegPostProcessor):
def run(self, info):
if info.get('container') != 'm4a_dash':
return [], info
filename = info['filepath']
temp_filename = prepend_extension(filename, 'temp')
options = ['-c', 'copy', '-f', 'mp4']
self._downloader.to_screen('[ffmpeg] Correcting container in "%s"' % filename)
self.run_ffmpeg(filename, temp_filename, options)
os.remove(encodeFilename(filename))
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
return [], info
class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
def __init__(self, downloader=None, format=None):
super(FFmpegSubtitlesConvertorPP, self).__init__(downloader)
self.format = format
def run(self, info):
subs = info.get('requested_subtitles')
filename = info['filepath']
new_ext = self.format
new_format = new_ext
if new_format == 'vtt':
new_format = 'webvtt'
if subs is None:
self._downloader.to_screen('[ffmpeg] There aren\'t any subtitles to convert')
return [], info
self._downloader.to_screen('[ffmpeg] Converting subtitles')
for lang, sub in subs.items():
ext = sub['ext']
if ext == new_ext:
self._downloader.to_screen(
'[ffmpeg] Subtitle file for %s is already in the requested'
'format' % new_ext)
continue
new_file = subtitles_filename(filename, lang, new_ext)
if ext == 'dfxp' or ext == 'ttml':
self._downloader.report_warning(
'You have requested to convert dfxp (TTML) subtitles into another format, '
'which results in style information loss')
dfxp_file = subtitles_filename(filename, lang, ext)
srt_file = subtitles_filename(filename, lang, 'srt')
with io.open(dfxp_file, 'rt', encoding='utf-8') as f:
srt_data = dfxp2srt(f.read())
with io.open(srt_file, 'wt', encoding='utf-8') as f:
f.write(srt_data)
ext = 'srt'
subs[lang] = {
'ext': 'srt',
'data': srt_data
}
if new_ext == 'srt':
continue
self.run_ffmpeg(
subtitles_filename(filename, lang, ext),
new_file, ['-f', new_format])
with io.open(new_file, 'rt', encoding='utf-8') as f:
subs[lang] = {
'ext': ext,
'data': f.read(),
}
return [], info
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
5890,
199,
646,
747,
199,
646,
3873,
199,
646,
900,
421,
199,
504,
1275,
2330,
492,
30885,
20403,
547,
12,
7711,
10438,
199,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
5781,
63,
362,
63,
13260,
8084,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
3752,
5201,
12,
272,
3752,
8117,
12,
272,
664,
63,
5803,
63,
1023,
12,
272,
365,
63,
548,
19074,
63,
1023,
12,
272,
7711,
9589,
547,
12,
272,
18213,
63,
3435,
12,
272,
5218,
63,
3513,
12,
272,
19297,
63,
1501,
12,
272,
4051,
9290,
18,
24336,
12,
272,
9055,
26723,
7535,
12,
199,
9,
421,
199,
533,
25046,
16801,
6564,
10438,
547,
8,
6564,
9589,
547,
304,
272,
986,
421,
199,
533,
25046,
16801,
6564,
10438,
8,
6564,
10438,
304,
272,
347,
636,
826,
721,
277,
12,
3224,
3422,
29,
403,
304,
267,
7711,
10438,
855,
826,
721,
277,
12,
3224,
3422,
9,
267,
291,
423,
22189,
63,
5904,
83,
342,
339,
347,
1104,
63,
1023,
8,
277,
304,
267,
340,
440,
291,
14,
4561,
26,
288,
746,
25046,
16801,
6564,
10438,
547,
360,
27648,
503,
2289,
5598,
440,
1911,
14,
7754,
3907,
1373,
2659,
398,
1415,
63,
1023,
275,
283,
709,
13,
16,
7,
340,
291,
14,
4846,
508,
283,
1214,
5598,
7,
587,
283,
17,
14,
16,
7,
267,
340,
365,
63,
548,
19074,
63,
1023,
8,
355,
291,
423,
6234,
59,
277,
14,
4846,
467,
1415,
63,
1023,
304,
288,
5721,
275,
283,
14398,
1331,
402,
450,
83,
365,
734,
19074,
12,
1678,
450,
83,
370,
1015,
450,
83,
503,
15666,
340,
1265,
655,
5337,
1263,
2552,
3530,
450,
334,
355,
291,
14,
4846,
12,
291,
14,
4846,
12,
1415,
63,
1023,
9,
288,
340,
291,
423,
22846,
26,
355,
291,
423,
22846,
14,
3070,
63,
3764,
8,
3764,
9,
339,
768,
4639,
272,
347,
664,
63,
6234,
8,
22846,
29,
403,
304,
267,
372,
25046,
16801,
6564,
10438,
8,
22846,
10445,
6234,
339,
347,
485,
22189,
63,
5904,
83,
8,
277,
304,
267,
18572,
275,
788,
1214,
15944,
297,
283,
1214,
5598,
297,
283,
27648,
297,
283,
556,
15944,
418,
267,
16602,
63,
27648,
275,
291,
423,
22846,
14,
1162,
14,
362,
360,
24283,
63,
27648,
297,
756,
9,
398,
291,
14,
4846,
275,
488,
267,
291,
14,
15944,
63,
4846,
275,
488,
398,
291,
423,
3771,
275,
488,
267,
291,
423,
6234,
275,
488,
267,
340,
291,
423,
22846,
26,
288,
2909,
275,
291,
423,
22846,
14,
1162,
14,
362,
360,
27648,
63,
1985,
358,
288,
340,
2909,
365,
440,
488,
26,
355,
340,
440,
747,
14,
515,
14,
2444,
8,
1985,
304,
490,
291,
423,
22846,
14,
3070,
63,
3764,
8,
717,
283,
27648,
13,
1985,
450,
83,
1630,
440,
2187,
1,
283,
717,
283,
24593,
23221,
1928,
2289,
5598,
15,
27648,
3530,
450,
334,
1985,
430,
490,
291,
423,
6234,
275,
1052,
490,
372,
355,
916,
440,
747,
14,
515,
14,
6027,
8,
1985,
304,
490,
9593,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
1985,
11515,
16,
61,
490,
340,
9593,
440,
315,
18572,
26,
717,
291,
423,
22846,
14,
3070,
63,
3764,
8,
1169,
283,
6612,
10405,
7286,
450,
83,
12,
2399,
9593,
1077,
506,
1373,
402,
450,
83,
14,
283,
1169,
283,
24593,
23221,
1928,
2289,
5598,
15,
27648,
3530,
450,
1169,
334,
1985,
12,
1656,
1987,
904,
8,
28464,
1724,
717,
291,
423,
6234,
275,
1052,
717,
372,
488,
490,
2909,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1985,
430,
490,
340,
9593,
315,
661,
27648,
297,
283,
556,
15944,
735,
717,
16602,
63,
27648,
275,
715,
2234,
291,
423,
3771,
275,
1211,
8,
490,
334,
80,
12,
747,
14,
515,
14,
904,
8,
1985,
12,
299,
430,
367,
299,
315,
18572,
9,
355,
291,
423,
6234,
275,
1211,
8,
490,
334,
80,
12,
664,
63,
5803,
63,
1023,
8,
277,
423,
3771,
59,
80,
467,
1249,
2968,
13,
1023,
5156,
490,
367,
299,
315,
18572,
9,
267,
340,
291,
423,
6234,
365,
488,
26,
288,
291,
423,
6234,
275,
1211,
8,
355,
334,
80,
12,
664,
63,
5803,
63,
1023,
8,
80,
12,
1249,
2968,
13,
1023,
5156,
367,
299,
315,
18572,
9,
288,
291,
423,
3771,
275,
1211,
1332,
80,
12,
299,
9,
367,
299,
315,
18572,
9,
398,
340,
16602,
63,
27648,
26,
288,
28516,
275,
661,
27648,
297,
283,
1214,
5598,
358,
267,
587,
26,
288,
28516,
275,
661,
1214,
5598,
297,
283,
27648,
358,
267,
367,
299,
315,
28516,
26,
288,
340,
291,
423,
6234,
59,
80,
2189,
355,
291,
14,
4846,
275,
299,
355,
2059,
398,
340,
16602,
63,
27648,
26,
288,
28516,
275,
661,
556,
15944,
297,
283,
1214,
15944,
358,
267,
587,
26,
288,
28516,
275,
661,
1214,
15944,
297,
283,
556,
15944,
358,
267,
367,
299,
315,
28516,
26,
288,
340,
291,
423,
6234,
59,
80,
2189,
355,
291,
14,
15944,
63,
4846,
275,
299,
355,
2059,
339,
768,
1829,
272,
347,
2808,
8,
277,
304,
267,
372,
291,
14,
4846,
365,
440,
488,
339,
768,
1829,
272,
347,
7286,
8,
277,
304,
267,
372,
291,
423,
3771,
59,
277,
14,
4846,
61,
339,
768,
1829,
272,
347,
22362,
63,
4561,
8,
277,
304,
267,
372,
291,
14,
15944,
63,
4846,
365,
440,
488,
339,
768,
1829,
272,
347,
22362,
63,
5904,
8,
277,
304,
267,
372,
291,
423,
3771,
59,
277,
14,
15944,
63,
4846,
61,
339,
347,
1255,
63,
27648,
63,
6048,
63,
1725,
8,
277,
12,
1324,
63,
3771,
12,
734,
63,
515,
12,
3999,
304,
267,
291,
14,
1074,
63,
1023,
342,
398,
29493,
63,
8180,
275,
1748,
8,
288,
747,
14,
3736,
8,
2143,
8117,
8,
515,
4992,
270,
63,
8180,
367,
931,
315,
1324,
63,
3771,
9,
398,
3999,
847,
291,
423,
4758,
63,
589,
342,
398,
1584,
63,
1760,
275,
942,
267,
367,
931,
315,
1324,
63,
3771,
26,
288,
1584,
63,
1760,
14,
2880,
779,
2143,
5201,
3654,
73,
659,
3752,
8117,
8,
515,
12,
715,
3948,
267,
2088,
275,
7287,
2143,
8117,
8,
277
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
5890,
199,
646,
747,
199,
646,
3873,
199,
646,
900,
421,
199,
504,
1275,
2330,
492,
30885,
20403,
547,
12,
7711,
10438,
199,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
5781,
63,
362,
63,
13260,
8084,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
3752,
5201,
12,
272,
3752,
8117,
12,
272,
664,
63,
5803,
63,
1023,
12,
272,
365,
63,
548,
19074,
63,
1023,
12,
272,
7711,
9589,
547,
12,
272,
18213,
63,
3435,
12,
272,
5218,
63,
3513,
12,
272,
19297,
63,
1501,
12,
272,
4051,
9290,
18,
24336,
12,
272,
9055,
26723,
7535,
12,
199,
9,
421,
199,
533,
25046,
16801,
6564,
10438,
547,
8,
6564,
9589,
547,
304,
272,
986,
421,
199,
533,
25046,
16801,
6564,
10438,
8,
6564,
10438,
304,
272,
347,
636,
826,
721,
277,
12,
3224,
3422,
29,
403,
304,
267,
7711,
10438,
855,
826,
721,
277,
12,
3224,
3422,
9,
267,
291,
423,
22189,
63,
5904,
83,
342,
339,
347,
1104,
63,
1023,
8,
277,
304,
267,
340,
440,
291,
14,
4561,
26,
288,
746,
25046,
16801,
6564,
10438,
547,
360,
27648,
503,
2289,
5598,
440,
1911,
14,
7754,
3907,
1373,
2659,
398,
1415,
63,
1023,
275,
283,
709,
13,
16,
7,
340,
291,
14,
4846,
508,
283,
1214,
5598,
7,
587,
283,
17,
14,
16,
7,
267,
340,
365,
63,
548,
19074,
63,
1023,
8,
355,
291,
423,
6234,
59,
277,
14,
4846,
467,
1415,
63,
1023,
304,
288,
5721,
275,
283,
14398,
1331,
402,
450,
83,
365,
734,
19074,
12,
1678,
450,
83,
370,
1015,
450,
83,
503,
15666,
340,
1265,
655,
5337,
1263,
2552,
3530,
450,
334,
355,
291,
14,
4846,
12,
291,
14,
4846,
12,
1415,
63,
1023,
9,
288,
340,
291,
423,
22846,
26,
355,
291,
423,
22846,
14,
3070,
63,
3764,
8,
3764,
9,
339,
768,
4639,
272,
347,
664,
63,
6234,
8,
22846,
29,
403,
304,
267,
372,
25046,
16801,
6564,
10438,
8,
22846,
10445,
6234,
339,
347,
485,
22189,
63,
5904,
83,
8,
277,
304,
267,
18572,
275,
788,
1214,
15944,
297,
283,
1214,
5598,
297,
283,
27648,
297,
283,
556,
15944,
418,
267,
16602,
63,
27648,
275,
291,
423,
22846,
14,
1162,
14,
362,
360,
24283,
63,
27648,
297,
756,
9,
398,
291,
14,
4846,
275,
488,
267,
291,
14,
15944,
63,
4846,
275,
488,
398,
291,
423,
3771,
275,
488,
267,
291,
423,
6234,
275,
488,
267,
340,
291,
423,
22846,
26,
288,
2909,
275,
291,
423,
22846,
14,
1162,
14,
362,
360,
27648,
63,
1985,
358,
288,
340,
2909,
365,
440,
488,
26,
355,
340,
440,
747,
14,
515,
14,
2444,
8,
1985,
304,
490,
291,
423,
22846,
14,
3070,
63,
3764,
8,
717,
283,
27648,
13,
1985,
450,
83,
1630,
440,
2187,
1,
283,
717,
283,
24593,
23221,
1928,
2289,
5598,
15,
27648,
3530,
450,
334,
1985,
430,
490,
291,
423,
6234,
275,
1052,
490,
372,
355,
916,
440,
747,
14,
515,
14,
6027,
8,
1985,
304,
490,
9593,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
1985,
11515,
16,
61,
490,
340,
9593,
440,
315,
18572,
26,
717,
291,
423,
22846,
14,
3070,
63,
3764,
8,
1169,
283,
6612,
10405,
7286,
450,
83,
12,
2399,
9593,
1077,
506,
1373,
402,
450,
83,
14,
283,
1169,
283,
24593,
23221,
1928,
2289,
5598,
15,
27648,
3530,
450,
1169,
334,
1985,
12,
1656,
1987,
904,
8,
28464,
1724,
717,
291,
423,
6234,
275,
1052,
717,
372,
488,
490,
2909,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1985,
430,
490,
340,
9593,
315,
661,
27648,
297,
283,
556,
15944,
735,
717,
16602,
63,
27648,
275,
715,
2234,
291,
423,
3771,
275,
1211,
8,
490,
334,
80,
12,
747,
14,
515,
14,
904,
8,
1985,
12,
299,
430,
367,
299,
315,
18572,
9,
355,
291,
423,
6234,
275,
1211,
8,
490,
334,
80,
12,
664,
63,
5803,
63,
1023,
8,
277,
423,
3771,
59,
80,
467,
1249,
2968,
13,
1023,
5156,
490,
367,
299,
315,
18572,
9,
267,
340,
291,
423,
6234,
365,
488,
26,
288,
291,
423,
6234,
275,
1211,
8,
355,
334,
80,
12,
664,
63,
5803,
63,
1023,
8,
80,
12,
1249,
2968,
13,
1023,
5156,
367,
299,
315,
18572,
9,
288,
291,
423,
3771,
275,
1211,
1332,
80,
12,
299,
9,
367,
299,
315,
18572,
9,
398,
340,
16602,
63,
27648,
26,
288,
28516,
275,
661,
27648,
297,
283,
1214,
5598,
358,
267,
587,
26,
288,
28516,
275,
661,
1214,
5598,
297,
283,
27648,
358,
267,
367,
299,
315,
28516,
26,
288,
340,
291,
423,
6234,
59,
80,
2189,
355,
291,
14,
4846,
275,
299,
355,
2059,
398,
340,
16602,
63,
27648,
26,
288,
28516,
275,
661,
556,
15944,
297,
283,
1214,
15944,
358,
267,
587,
26,
288,
28516,
275,
661,
1214,
15944,
297,
283,
556,
15944,
358,
267,
367,
299,
315,
28516,
26,
288,
340,
291,
423,
6234,
59,
80,
2189,
355,
291,
14,
15944,
63,
4846,
275,
299,
355,
2059,
339,
768,
1829,
272,
347,
2808,
8,
277,
304,
267,
372,
291,
14,
4846,
365,
440,
488,
339,
768,
1829,
272,
347,
7286,
8,
277,
304,
267,
372,
291,
423,
3771,
59,
277,
14,
4846,
61,
339,
768,
1829,
272,
347,
22362,
63,
4561,
8,
277,
304,
267,
372,
291,
14,
15944,
63,
4846,
365,
440,
488,
339,
768,
1829,
272,
347,
22362,
63,
5904,
8,
277,
304,
267,
372,
291,
423,
3771,
59,
277,
14,
15944,
63,
4846,
61,
339,
347,
1255,
63,
27648,
63,
6048,
63,
1725,
8,
277,
12,
1324,
63,
3771,
12,
734,
63,
515,
12,
3999,
304,
267,
291,
14,
1074,
63,
1023,
342,
398,
29493,
63,
8180,
275,
1748,
8,
288,
747,
14,
3736,
8,
2143,
8117,
8,
515,
4992,
270,
63,
8180,
367,
931,
315,
1324,
63,
3771,
9,
398,
3999,
847,
291,
423,
4758,
63,
589,
342,
398,
1584,
63,
1760,
275,
942,
267,
367,
931,
315,
1324,
63,
3771,
26,
288,
1584,
63,
1760,
14,
2880,
779,
2143,
5201,
3654,
73,
659,
3752,
8117,
8,
515,
12,
715,
3948,
267,
2088,
275,
7287,
2143,
8117,
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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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
] |
bendudson/BOUT-1.0
|
tools/tokamak_grids/pyGridGen/aeqdsk.py
|
4
|
18365
|
#!/usr/bin/env python
import re
import numpy
"""
@brief A-Eqdsk reader class
@version $Id$
Copyright © 2006-2008, Tech-X Corporation, Boulder, CO
See LICENSE file for conditions of use.
The official document describing a-eqdsk files:
http://fusion.gat.com/THEORY/efit/a_eqdsk.html
"""
class Aeqdsk:
def __init__(self):
"""
Constructor
"""
self.data = {}
def openFile(self, filename):
"""
open aeqdsk file and parse its content
"""
fmt_1060 = r'^\s*\*\s*([\w\.\-]+)\s+(\d+)\s+(\d+)\s([\w]+)\s+(\d+)\s+(\d+)\s([\w ]+)\s+\d+\s+\d+\s*$'
fmt_1040 = r'^\s*' + 4*r'([\s\-]\d+\.\d+[Ee][\+\-]\d\d)'
fmt_1041 = r'^' + 4*r'\s+([ \-]\d+)'
lines = open(filename, 'r').readlines()
counter = 0
m = None
while m == None:
line = lines[counter]
m = re.match(fmt_1060, line)
counter += 1
# read (neqdsk,1060) time(jj),jflag(jj),lflag,limloc(jj), mco2v,mco2r,qmflag
if m:
self.data['time'] = float(m.group(1)), 'time ms'
self.data['jflag'] = int(m.group(2)), '0 if error'
self.data['lflag'] = int(m.group(3)), '>0 if error'
self.data['limloc'] = m.group(4), 'IN/OUT/TOP/BOT: limiter inside/outside/top/bot SNT/SNB: single null top/bottom DN: double null'
self.data['mco2v'] = int(m.group(5)), 'number of vertical CO2 density chords'
self.data['mco2r'] = int(m.group(6)), 'number of radial CO2 density chords'
self.data['qmflag'] = m.group(7), 'axial q(0) flag, FIX if constrained and CLC for float'
else:
raise 'Read error at line %d' % (counter-1)
# read (neqdsk,1040) tsaisq(jj),rcencm,bcentr(jj),pasmat(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['tsaisq'] = float(m.group(1)), "total chi2 from magnetic probes, flux loops, Rogowskiand external coils"
self.data['rcencm'] = float(m.group(2)), "major radius in cm for vacuum field BCENTR"
self.data['bcentr'] = float(m.group(3)), "vacuum toroidal magnetic field in Tesla at RCENCM"
self.data['pasmat'] = float(m.group(4)), "measured plasma toroidal current in Ampere"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) cpasma(jj),rout(jj),zout(jj),aout(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['cpasma'] = float(m.group(1)), "fitted plasma toroidal current in Ampere-turn"
self.data['rout'] = float(m.group(2)), "major radius of geometric center in cm"
self.data['zout'] = float(m.group(3)), "Z of geometric center in cm"
self.data['aout'] = float(m.group(4)), "plasma minor radius in cm"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) eout(jj),doutu(jj),doutl(jj),vout(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['eout'] = float(m.group(1)), "Plasma boundary elongation"
self.data['doutu'] = float(m.group(2)), "upper triangularity"
self.data['doutl'] = float(m.group(3)), "lower triangularity"
self.data['vout'] = float(m.group(4)), "plasma volume in cm3"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) rcurrt(jj),zcurrt(jj),qsta(jj),betat(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['rcurrt'] = float(m.group(1)), "major radius in cm of current centroid"
self.data['zcurrt'] = float(m.group(2)), "Z in cm at current centroid"
self.data['qsta'] = float(m.group(3)), "equivalent safety factor q*"
self.data['betat'] = float(m.group(4)), "toroidal b in %"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) betap(jj),ali(jj),oleft(jj),oright(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['betap'] = float(m.group(1)), "poloidal b with normalization average poloidal magnetic BPOLAV defined through Ampere's law"
self.data['ali'] = float(m.group(2)), "li with normalization average poloidal magnetic defined through Ampere's law"
self.data['oleft'] = float(m.group(3)), "plasma inner gap in cm"
self.data['oright'] = float(m.group(4)), "plasma outer gap in cm"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) otop(jj),obott(jj),qpsib(jj),vertn(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['otop'] = float(m.group(1)), "plasma top gap in cm"
self.data['obott'] = float(m.group(2)), "plasma bottom gap in cm"
self.data['qpsib'] = float(m.group(3)), "q at 95% of poloidal flux"
self.data['vertn'] = float(m.group(4)), "vacuum field index at current centroid"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
mco2v = self.data['mco2v'][0]
print 'mco2v=', mco2v
# read (neqdsk,1040) (rco2v(k,jj),k=1,mco2v)
data = []
while len(data) < mco2v:
line = lines[counter]
data += eval('[' + re.sub(r'(\d)\s*([\s\-])\s*(\d)', '\\1, \\2\\3', line) + ']')
counter += 1
self.data['rco2v'] = numpy.array(data), "path length in cm of vertical CO2 density chord"
# read (neqdsk,1040) (dco2v(jj,k),k=1,mco2v)
data = []
while len(data) < mco2v:
line = lines[counter]
data += eval('[' + re.sub(r'(\d)\s*([\s\-])\s*(\d)', '\\1, \\2\\3', line) + ']')
counter += 1
self.data['dco2v'] = numpy.array(data), "line average electron density in cm3 from vertical CO2 chord"
mco2r = self.data['mco2r'][0]
print 'mco2r=', mco2r
# read (neqdsk,1040) (rco2r(k,jj),k=1,mco2r)
data = []
while len(data) < mco2r:
line = lines[counter]
data += eval('[' + re.sub(r'(\d)\s*([\s\-])\s*(\d)', '\\1, \\2\\3', line) + ']')
counter += 1
self.data['rco2r'] = numpy.array(data), "path length in cm of radial CO2 density chord"
# read (neqdsk,1040) (dco2r(jj,k),k=1,mco2r)
data = []
while len(data) < mco2r:
line = lines[counter]
data += eval('[' + re.sub(r'(\d)\s*([\s\-])\s*(\d)', '\\1, \\2\\3', line) + ']')
counter += 1
self.data['dco2r'] = numpy.array(data), "line average electron density in cm3 from radial CO2 chord"
# read (neqdsk,1040) shearb(jj),bpolav(jj),s1(jj),s2(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['shearb'] = float(m.group(1)), ""
self.data['bpolav'] = float(m.group(2)), "average poloidal magnetic field in Tesla defined through Ampere's law"
self.data['s1'] = float(m.group(3)), "Shafranov boundary line integrals"
self.data['s2'] = float(m.group(4)), "Shafranov boundary line integrals"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) s3(jj),qout(jj),olefs(jj),orighs(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['s3'] = float(m.group(1)), "Shafranov boundary line integrals"
self.data['qout'] = float(m.group(2)), "q at plasma boundary"
self.data['olefs'] = float(m.group(3)), ""
self.data['orighs'] = float(m.group(4)), "outer gap of external second separatrix in cm"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) otops(jj),sibdry(jj),areao(jj),wplasm(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['otops'] = float(m.group(1)), "top gap of external second separatrix in cm"
self.data['sibdry'] = float(m.group(2)), ""
self.data['areao'] = float(m.group(3)), "cross sectional area in cm2"
self.data['wplasm'] = float(m.group(4)), ""
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) terror(jj),elongm(jj),qqmagx(jj),cdflux(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['terror'] = float(m.group(1)), "equilibrium convergence error"
self.data['elongm'] = float(m.group(2)), "elongation at magnetic axis"
self.data['qqmagx'] = float(m.group(3)), "axial safety factor q(0)"
self.data['cdflux'] = float(m.group(4)), "computed diamagnetic flux in Volt-sec"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) alpha(jj),rttt(jj),psiref(jj),xndnt(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['alpha'] = float(m.group(1)), "Shafranov boundary line integral parameter"
self.data['rttt'] = float(m.group(2)), "Shafranov boundary line integral parameter"
self.data['psiref'] = float(m.group(3)), "reference poloidal flux in VS/rad"
self.data['xndnt'] = float(m.group(4)), "vertical stability parameter, vacuum field index normalized to critical index value"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) rseps(1,jj),zseps(1,jj),rseps(2,jj),zseps(2,jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['rseps1'] = float(m.group(1)), "major radius of x point in cm"
self.data['zseps1'] = float(m.group(2)), ""
self.data['rseps2'] = float(m.group(3)), "major radius of x point in cm"
self.data['zseps2'] = float(m.group(4)), ""
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) sepexp(jj),obots(jj),btaxp(jj),btaxv(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['sepexp'] = float(m.group(1)), "separatrix radial expansion in cm"
self.data['obots'] = float(m.group(2)), "bottom gap of external second separatrix in cm"
self.data['btaxp'] = float(m.group(3)), "toroidal magnetic field at magnetic axis in Tesla"
self.data['btaxv'] = float(m.group(4)), "vacuum toroidal magnetic field at magnetic axis in Tesla"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) aaq1(jj),aaq2(jj),aaq3(jj),seplim(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['aaq1'] = float(m.group(1)), "minor radius of q=1 surface in cm, 100 if not found"
self.data['aaq2'] = float(m.group(2)), "minor radius of q=2 surface in cm, 100 if not found"
self.data['aaq3'] = float(m.group(3)), "minor radius of q=3 surface in cm, 100 if not found"
self.data['seplim'] = float(m.group(4)), "> 0 for minimum gap in cm in divertor configurations, < 0 absolute value for minimum distance to external separatrix in limiter configurations"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040) rmagx(jj),zmagx(jj),simagx(jj),taumhd(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['rmagx'] = float(m.group(1)), "major radius in cm at magnetic axis"
self.data['zmagx'] = float(m.group(2)), ""
self.data['simagx'] = float(m.group(3)), ""
self.data['taumhd'] = float(m.group(4)), "energy confinement time in ms"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040,err=380) betapd(jj),betatd(jj),wplasmd(jj),diamag(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['betapd'] = float(m.group(1)), "diamagnetic poloidal b"
self.data['betatd'] = float(m.group(2)), "diamagnetic toroidal b in %"
self.data['wplasmd'] = float(m.group(3)), "diamagnetic plasma stored energy in Joule"
self.data['fluxx'] = float(m.group(4)), "measured diamagnetic flux in Volt-sec"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# read (neqdsk,1040,err=380) vloopt(jj),taudia(jj),qmerci(jj),tavem(jj)
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['vloopt'] = float(m.group(1)), "measured loop voltage in volt"
self.data['taudia'] = float(m.group(2)), "diamagnetic energy confinement time in ms"
self.data['qmerci'] = float(m.group(3)), "Mercier stability criterion on axial q(0), q(0) > QMERCI for stability"
self.data['tavem'] = float(m.group(4)), "average time in ms for magnetic and MSE data"
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
# ishot > 91000
line = lines[counter]
m = re.match(fmt_1041, line)
if m:
self.data['nsilop'] = int(m.group(1)), ""
self.data['magpri'] = int(m.group(2)), ""
self.data['nfcoil'] = int(m.group(3)), ""
self.data['nesum'] = int(m.group(4)), ""
counter += 1
else:
raise 'Read error at line %d:%s' % (counter, line)
nsilop = self.data['nsilop'][0]
magpri = self.data['magpri'][0]
print 'nsilop=', nsilop, ' magpri=', magpri
data = []
while len(data) < nsilop + magpri:
line = lines[counter]
data += eval('[' + re.sub(r'(\d)\s*([\s\-])\s*(\d)', '\\1, \\2\\3', line) + ']')
counter += 1
self.data['csilop'] = numpy.array( data[:nsilop] ), "computed flux loop signals in Weber"
self.data['cmpr2'] = numpy.array( data[nsilop:] ), ""
#
data = []
nfcoil = self.data['nfcoil'][0]
while len(data) < nfcoil:
line = lines[counter]
data += eval('[' + re.sub(r'(\d)\s*([\s\-])\s*(\d)', '\\1, \\2\\3', line) + ']')
counter += 1
self.data['ccbrsp'] = numpy.array(data), "computed external coil currents in Ampere"
data = []
nesum = self.data['nesum'][0]
while len(data) < nesum:
line = lines[counter]
data += eval('[' + re.sub(r'(\d)\s*([\s\-])\s*(\d)', '\\1, \\2\\3', line) + ']')
counter += 1
self.data['eccurt'] = numpy.array(data), "measured E-coil current in Ampere"
#
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['pbinj'] = float(m.group(1)), "neutral beam injection power in Watts"
self.data['rvsin'] = float(m.group(2)), "major radius of vessel inner hit spot in cm"
self.data['zvsin'] = float(m.group(3)), "Z of vessel inner hit spot in cm"
self.data['rvsout'] = float(m.group(4)), "major radius of vessel outer hit spot in cm"
counter += 1
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['zvsout'] = float(m.group(1)), "Z of vessel outer hit spot in cm"
self.data['vsurfa'] = float(m.group(2)), "plasma surface loop voltage in volt, E EQDSK only"
self.data['wpdot'] = float(m.group(3)), "time derivative of plasma stored energy in Watt, E EQDSK only"
self.data['wbdot'] = float(m.group(4)), "time derivative of poloidal magnetic energy in Watt, E EQDSK only"
counter += 1
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['slantu'] = float(m.group(1)), ""
self.data['slantl'] = float(m.group(2)), ""
self.data['zuperts'] = float(m.group(3)), ""
self.data['chipre'] = float(m.group(4)), "total chi2 pressure"
counter += 1
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['cjor95'] = float(m.group(1)), ""
self.data['pp95'] = float(m.group(2)), "normalized P'(y) at 95% normalized poloidal flux"
self.data['ssep'] = float(m.group(3)), ""
self.data['yyy2'] = float(m.group(4)), "Shafranov Y2 current moment"
counter += 1
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['xnnc'] = float(m.group(1)), ""
self.data['cprof'] = float(m.group(2)), "current profile parametrization parameter"
#self.data['oring'] = float(m.group(3)), "" (not used)
self.data['cjor0'] = float(m.group(4)), "normalized flux surface average current density at 99% of normalized poloidal flux"
counter += 1
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['fexpan'] = float(m.group(1)), "flux expansion at x point"
self.data['qqmin'] = float(m.group(2)), "minimum safety factor qmin"
self.data['chigamt'] = float(m.group(3)), "total chi2 MSE"
self.data['ssi01'] = float(m.group(4)), "magnetic shear at 1% of normalized poloidal flux"
counter += 1
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['fexpvs'] = float(m.group(1)), "flux expansion at outer lower vessel hit spot"
self.data['sepnose'] = float(m.group(2)), "radial distance in cm between x point and external field line at ZNOSE"
self.data['ssi95'] = float(m.group(3)), "magnetic shear at 95% of normalized poloidal flux"
self.data['rqqmin'] = float(m.group(4)), "normalized radius of qmin , square root of normalized volume"
counter += 1
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['cjor99'] = float(m.group(1)), ""
self.data['cj1ave'] = float(m.group(2)), "normalized average current density in plasma outer 5% normalized poloidal flux region"
self.data['rmidin'] = float(m.group(3)), "inner major radius in m at Z=0.0"
self.data['rmidout'] = float(m.group(4)), "outer major radius in m at Z=0.0"
counter += 1
line = lines[counter]
m = re.match(fmt_1040, line)
if m:
self.data['psurfa'] = float(m.group(1)), "plasma boundary surface area in m2"
#self.data[''] = float(m.group(2)), ""
#self.data[''] = float(m.group(3)), ""
#self.data[''] = float(m.group(4)), ""
counter += 1
def getAll(self):
return self.data
def getAllVars(self):
return self.data.keys()
def get(self, varname):
return self.data[varname]
################################
def main():
import sys
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
help="g-eqdsk file", default="")
parser.add_option("-a", "--all", dest="all",
help="display all variables", action="store_true",)
parser.add_option("-v", "--vars", dest="vars",
help="comma separated list of variables (use '-v \"*\"' for all)", default="*")
#parser.add_option("-p", "--plot", dest="plot",
# help="plot all variables", action="store_true",)
parser.add_option("-i", "--inquire", dest="inquire",
help="inquire list of variables", action="store_true",)
options, args = parser.parse_args()
if not options.filename:
parser.error("MUST provide filename (type -h for list of options)")
eq = Aeqdsk()
eq.openFile(options.filename)
if options.inquire:
print eq.getAllVars()
if options.all:
print eq.getAll()
vs = eq.getAllVars()
if options.vars != '*':
vs = options.vars.split(',')
for v in vs:
print '%s: %s'% (v, str(eq.get(v)))
if __name__ == '__main__': main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
295,
199,
646,
2680,
199,
199,
624,
199,
32,
19127,
437,
13,
19706,
795,
75,
7002,
1021,
199,
32,
1023,
2672,
1304,
4,
199,
199,
7384,
1253,
1574,
27,
8315,
13,
9300,
12,
5773,
335,
13,
56,
11098,
12,
5088,
348,
424,
12,
5099,
199,
9295,
5113,
570,
367,
3704,
402,
675,
14,
199,
199,
1918,
25410,
2213,
13660,
282,
13,
4077,
795,
75,
1584,
26,
199,
1014,
921,
70,
12444,
14,
71,
292,
14,
957,
15,
18061,
5347,
15,
69,
3269,
15,
65,
63,
4077,
795,
75,
14,
1360,
199,
624,
199,
199,
533,
437,
4077,
795,
75,
26,
272,
489,
347,
636,
826,
721,
277,
304,
199,
198,
624,
199,
198,
11447,
199,
198,
624,
489,
198,
277,
14,
576,
275,
1052,
2541,
347,
1551,
1173,
8,
277,
12,
1788,
304,
199,
198,
624,
199,
198,
1490,
282,
4077,
795,
75,
570,
436,
2198,
2399,
1564,
199,
198,
624,
8299,
198,
5045,
63,
709,
2259,
275,
519,
15542,
83,
7590,
7590,
83,
10,
16510,
87,
60,
3134,
13,
18096,
83,
20900,
68,
13439,
83,
20900,
68,
13439,
83,
16510,
87,
18096,
83,
20900,
68,
13439,
83,
20900,
68,
13439,
83,
16510,
87,
1622,
13439,
83,
7896,
68,
7896,
83,
7896,
68,
7896,
83,
10,
12913,
199,
198,
5045,
63,
709,
2167,
275,
519,
15542,
83,
10223,
435,
841,
10,
82,
7,
16510,
83,
16185,
7272,
68,
23294,
68,
21324,
37,
69,
30679,
7896,
13,
7272,
68,
60,
68,
3171,
199,
198,
5045,
63,
709,
2953,
275,
519,
4289,
7,
435,
841,
10,
82,
1154,
83,
11,
779,
971,
13,
7272,
68,
29600,
221,
421,
198,
1278,
275,
221,
1551,
8,
1501,
12,
283,
82,
1959,
9684,
342,
421,
198,
5337,
275,
378,
199,
198,
77,
275,
488,
199,
198,
6710,
333,
508,
488,
26,
507,
198,
604,
275,
2385,
59,
5337,
61,
507,
198,
77,
275,
295,
14,
1431,
8,
5045,
63,
709,
2259,
12,
1004,
9,
507,
198,
5337,
847,
413,
199,
3,
1586,
334,
685,
81,
795,
75,
12,
709,
2259,
9,
900,
8,
12098,
395,
74,
4173,
8,
12098,
395,
276,
1823,
12,
4175,
2102,
8,
12098,
395,
333,
331,
18,
86,
12,
77,
331,
18,
82,
12,
17976,
4173,
199,
198,
692,
333,
26,
507,
198,
277,
14,
576,
459,
521,
418,
275,
2069,
8,
77,
14,
923,
8,
17,
1826,
283,
521,
6605,
7,
507,
198,
277,
14,
576,
459,
74,
4173,
418,
275,
1109,
8,
77,
14,
923,
8,
18,
1826,
283,
16,
340,
1125,
7,
507,
198,
277,
14,
576,
459,
276,
1823,
418,
275,
1109,
8,
77,
14,
923,
8,
19,
1826,
12696,
16,
340,
1125,
7,
507,
198,
277,
14,
576,
459,
4175,
2102,
418,
275,
333,
14,
923,
8,
20,
395,
283,
568,
15,
1877,
15,
11422,
15,
11372,
26,
1212,
77,
1661,
6272,
15,
22431,
15,
2119,
15,
3018,
428,
12460,
15,
8199,
34,
26,
2849,
2973,
2746,
15,
8305,
24842,
26,
4270,
2973,
7,
507,
198,
277,
14,
576,
459,
77,
331,
18,
86,
418,
275,
1109,
8,
77,
14,
923,
8,
21,
1826,
283,
1955,
402,
13763,
5099,
18,
13650,
682,
5630,
7,
507,
198,
277,
14,
576,
459,
77,
331,
18,
82,
418,
275,
1109,
8,
77,
14,
923,
8,
22,
1826,
283,
1955,
402,
14070,
279,
5099,
18,
13650,
682,
5630,
7,
507,
198,
277,
14,
576,
459,
17976,
4173,
418,
275,
333,
14,
923,
8,
23,
395,
283,
1219,
2380,
1894,
8,
16,
9,
3305,
12,
7333,
340,
28483,
436,
21458,
367,
2069,
7,
199,
198,
2836,
26,
507,
263,
746,
283,
3284,
1125,
737,
1004,
450,
68,
7,
450,
334,
5337,
13,
17,
9,
199,
199,
3,
1586,
334,
685,
81,
795,
75,
12,
709,
2167,
9,
307,
2231,
374,
81,
8,
12098,
395,
1195,
287,
4400,
12,
66,
2497,
454,
8,
12098,
395,
15534,
569,
8,
12098,
9,
199,
198,
604,
275,
2385,
59,
5337,
61,
199,
198,
77,
275,
295,
14,
1431,
8,
5045,
63,
709,
2167,
12,
1004,
9,
199,
198,
692,
333,
26,
21979,
291,
14,
576,
459,
1086,
65,
374,
81,
418,
275,
2069,
8,
77,
14,
923,
8,
17,
1826,
298,
2923,
23275,
18,
687,
8127,
685,
764,
5128,
397,
12,
21475,
17222,
12,
820,
974,
19844,
460,
5957,
512,
17841,
2,
21979,
291,
14,
576,
459,
1195,
287,
4400,
418,
275,
2069,
8,
77,
14,
923,
8,
18,
1826,
298,
8452,
9362,
315,
6904,
367,
28898,
19805,
901,
699,
17349,
50,
2,
11083,
257,
291,
14,
576,
459,
66,
2497,
454,
418,
275,
2069,
8,
77,
14,
923,
8,
19,
1826,
298,
15367,
19805,
11095,
1170,
279,
8127,
685,
764,
901,
315,
377,
397,
416,
737,
29256,
742,
9249,
2,
21979,
291,
14,
576,
459,
15534,
569,
418,
275,
2069,
8,
77,
14,
923,
8,
20,
1826,
298,
19116,
3297,
1620,
305,
391,
11095,
1170,
279,
1453,
315,
437,
311,
69,
264,
2,
21979,
7055,
847,
413,
199,
198,
2836,
26,
21979,
746,
283,
3284,
1125,
737,
1004,
450,
68,
2689,
83,
7,
450,
334,
5337,
12,
1004,
9,
507,
199,
3,
1586,
334,
685,
81,
795,
75,
12,
709,
2167,
9,
7667,
305,
391,
8,
12098,
395,
12791,
8,
12098,
395,
90,
548,
8,
12098,
395,
65,
548,
8,
12098,
9,
257,
199,
198,
604,
275,
2385,
59,
5337,
61,
199,
198,
77,
275,
295,
14,
1431,
8,
5045,
63,
709,
2167,
12,
1004,
9,
199,
198,
692,
333,
26,
21979,
291,
14,
576,
459,
1850,
305,
391,
418,
275,
2069,
8,
77,
14,
923,
8,
17,
1826,
221,
298,
21903,
1620,
305,
391,
11095,
1170,
279,
1453,
315,
437,
311,
69,
264,
13,
353,
2,
21979,
291,
14,
576,
459,
12791,
418,
275,
2069,
8,
77,
14,
923,
8,
18,
1826,
221,
298,
8452,
9362,
402,
2312,
15890,
8126,
315,
6904,
2,
21979,
291,
14,
576,
459,
90,
548,
418,
275,
2069,
8,
77,
14,
923,
8,
19,
1826,
298,
58,
402,
2312,
15890,
8126,
315,
6904,
2,
21979,
291,
14,
576,
459,
65,
548,
418,
275,
2069,
8,
77,
14,
923,
8,
20,
1826,
298,
1168,
305,
391,
12612,
9362,
315,
6904,
2,
21979,
7055
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
295,
199,
646,
2680,
199,
199,
624,
199,
32,
19127,
437,
13,
19706,
795,
75,
7002,
1021,
199,
32,
1023,
2672,
1304,
4,
199,
199,
7384,
1253,
1574,
27,
8315,
13,
9300,
12,
5773,
335,
13,
56,
11098,
12,
5088,
348,
424,
12,
5099,
199,
9295,
5113,
570,
367,
3704,
402,
675,
14,
199,
199,
1918,
25410,
2213,
13660,
282,
13,
4077,
795,
75,
1584,
26,
199,
1014,
921,
70,
12444,
14,
71,
292,
14,
957,
15,
18061,
5347,
15,
69,
3269,
15,
65,
63,
4077,
795,
75,
14,
1360,
199,
624,
199,
199,
533,
437,
4077,
795,
75,
26,
272,
489,
347,
636,
826,
721,
277,
304,
199,
198,
624,
199,
198,
11447,
199,
198,
624,
489,
198,
277,
14,
576,
275,
1052,
2541,
347,
1551,
1173,
8,
277,
12,
1788,
304,
199,
198,
624,
199,
198,
1490,
282,
4077,
795,
75,
570,
436,
2198,
2399,
1564,
199,
198,
624,
8299,
198,
5045,
63,
709,
2259,
275,
519,
15542,
83,
7590,
7590,
83,
10,
16510,
87,
60,
3134,
13,
18096,
83,
20900,
68,
13439,
83,
20900,
68,
13439,
83,
16510,
87,
18096,
83,
20900,
68,
13439,
83,
20900,
68,
13439,
83,
16510,
87,
1622,
13439,
83,
7896,
68,
7896,
83,
7896,
68,
7896,
83,
10,
12913,
199,
198,
5045,
63,
709,
2167,
275,
519,
15542,
83,
10223,
435,
841,
10,
82,
7,
16510,
83,
16185,
7272,
68,
23294,
68,
21324,
37,
69,
30679,
7896,
13,
7272,
68,
60,
68,
3171,
199,
198,
5045,
63,
709,
2953,
275,
519,
4289,
7,
435,
841,
10,
82,
1154,
83,
11,
779,
971,
13,
7272,
68,
29600,
221,
421,
198,
1278,
275,
221,
1551,
8,
1501,
12,
283,
82,
1959,
9684,
342,
421,
198,
5337,
275,
378,
199,
198,
77,
275,
488,
199,
198,
6710,
333,
508,
488,
26,
507,
198,
604,
275,
2385,
59,
5337,
61,
507,
198,
77,
275,
295,
14,
1431,
8,
5045,
63,
709,
2259,
12,
1004,
9,
507,
198,
5337,
847,
413,
199,
3,
1586,
334,
685,
81,
795,
75,
12,
709,
2259,
9,
900,
8,
12098,
395,
74,
4173,
8,
12098,
395,
276,
1823,
12,
4175,
2102,
8,
12098,
395,
333,
331,
18,
86,
12,
77,
331,
18,
82,
12,
17976,
4173,
199,
198,
692,
333,
26,
507,
198,
277,
14,
576,
459,
521,
418,
275,
2069,
8,
77,
14,
923,
8,
17,
1826,
283,
521,
6605,
7,
507,
198,
277,
14,
576,
459,
74,
4173,
418,
275,
1109,
8,
77,
14,
923,
8,
18,
1826,
283,
16,
340,
1125,
7,
507,
198,
277,
14,
576,
459,
276,
1823,
418,
275,
1109,
8,
77,
14,
923,
8,
19,
1826,
12696,
16,
340,
1125,
7,
507,
198,
277,
14,
576,
459,
4175,
2102,
418,
275,
333,
14,
923,
8,
20,
395,
283,
568,
15,
1877,
15,
11422,
15,
11372,
26,
1212,
77,
1661,
6272,
15,
22431,
15,
2119,
15,
3018,
428,
12460,
15,
8199,
34,
26,
2849,
2973,
2746,
15,
8305,
24842,
26,
4270,
2973,
7,
507,
198,
277,
14,
576,
459,
77,
331,
18,
86,
418,
275,
1109,
8,
77,
14,
923,
8,
21,
1826,
283,
1955,
402,
13763,
5099,
18,
13650,
682,
5630,
7,
507,
198,
277,
14,
576,
459,
77,
331,
18,
82,
418,
275,
1109,
8,
77,
14,
923,
8,
22,
1826,
283,
1955,
402,
14070,
279,
5099,
18,
13650,
682,
5630,
7,
507,
198,
277,
14,
576,
459,
17976,
4173,
418,
275,
333,
14,
923,
8,
23,
395,
283,
1219,
2380,
1894,
8,
16,
9,
3305,
12,
7333,
340,
28483,
436,
21458,
367,
2069,
7,
199,
198,
2836,
26,
507,
263,
746,
283,
3284,
1125,
737,
1004,
450,
68,
7,
450,
334,
5337,
13,
17,
9,
199,
199,
3,
1586,
334,
685,
81,
795,
75,
12,
709,
2167,
9,
307,
2231,
374,
81,
8,
12098,
395,
1195,
287,
4400,
12,
66,
2497,
454,
8,
12098,
395,
15534,
569,
8,
12098,
9,
199,
198,
604,
275,
2385,
59,
5337,
61,
199,
198,
77,
275,
295,
14,
1431,
8,
5045,
63,
709,
2167,
12,
1004,
9,
199,
198,
692,
333,
26,
21979,
291,
14,
576,
459,
1086,
65,
374,
81,
418,
275,
2069,
8,
77,
14,
923,
8,
17,
1826,
298,
2923,
23275,
18,
687,
8127,
685,
764,
5128,
397,
12,
21475,
17222,
12,
820,
974,
19844,
460,
5957,
512,
17841,
2,
21979,
291,
14,
576,
459,
1195,
287,
4400,
418,
275,
2069,
8,
77,
14,
923,
8,
18,
1826,
298,
8452,
9362,
315,
6904,
367,
28898,
19805,
901,
699,
17349,
50,
2,
11083,
257,
291,
14,
576,
459,
66,
2497,
454,
418,
275,
2069,
8,
77,
14,
923,
8,
19,
1826,
298,
15367,
19805,
11095,
1170,
279,
8127,
685,
764,
901,
315,
377,
397,
416,
737,
29256,
742,
9249,
2,
21979,
291,
14,
576,
459,
15534,
569,
418,
275,
2069,
8,
77,
14,
923,
8,
20,
1826,
298,
19116,
3297,
1620,
305,
391,
11095,
1170,
279,
1453,
315,
437,
311,
69,
264,
2,
21979,
7055,
847,
413,
199,
198,
2836,
26,
21979,
746,
283,
3284,
1125,
737,
1004,
450,
68,
2689,
83,
7,
450,
334,
5337,
12,
1004,
9,
507,
199,
3,
1586,
334,
685,
81,
795,
75,
12,
709,
2167,
9,
7667,
305,
391,
8,
12098,
395,
12791,
8,
12098,
395,
90,
548,
8,
12098,
395,
65,
548,
8,
12098,
9,
257,
199,
198,
604,
275,
2385,
59,
5337,
61,
199,
198,
77,
275,
295,
14,
1431,
8,
5045,
63,
709,
2167,
12,
1004,
9,
199,
198,
692,
333,
26,
21979,
291,
14,
576,
459,
1850,
305,
391,
418,
275,
2069,
8,
77,
14,
923,
8,
17,
1826,
221,
298,
21903,
1620,
305,
391,
11095,
1170,
279,
1453,
315,
437,
311,
69,
264,
13,
353,
2,
21979,
291,
14,
576,
459,
12791,
418,
275,
2069,
8,
77,
14,
923,
8,
18,
1826,
221,
298,
8452,
9362,
402,
2312,
15890,
8126,
315,
6904,
2,
21979,
291,
14,
576,
459,
90,
548,
418,
275,
2069,
8,
77,
14,
923,
8,
19,
1826,
298,
58,
402,
2312,
15890,
8126,
315,
6904,
2,
21979,
291,
14,
576,
459,
65,
548,
418,
275,
2069,
8,
77,
14,
923,
8,
20,
1826,
298,
1168,
305,
391,
12612,
9362,
315,
6904,
2,
21979,
7055,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
coreboot/chrome-ec
|
util/flash_cr50.py
|
2
|
27330
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2020 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Flash Cr50 using gsctool or cr50-rescue.
gsctool example:
util/flash_cr50.py --image cr50.bin.prod
util/flash_cr50.py --release prod
cr50-rescue example:
util/flash_cr50.py --image cr50.bin.prod -c cr50-rescue -p 9999
util/flash_cr50.py --release prod -c cr50-rescue -p 9999
"""
import argparse
import os
import pprint
import re
import select
import shutil
import subprocess
import sys
import tempfile
import threading
import time
from chromite.lib import cros_build_lib
from chromite.lib import cros_logging as logging
CR50_FIRMWARE_BASE = '/opt/google/cr50/firmware/cr50.bin.'
RELEASE_PATHS = {
'prepvt': CR50_FIRMWARE_BASE + 'prepvt',
'prod': CR50_FIRMWARE_BASE + 'prod',
}
# Dictionary mapping a setup to controls used to verify that the setup is
# correct. The keys are strings and the values are lists of strings.
REQUIRED_CONTROLS = {
'cr50_uart': [
r'raw_cr50_uart_pty:\S+',
r'cr50_ec3po_interp_connect:\S+',
],
'cr50_reset_odl': [
r'cr50_reset_odl:\S+',
],
'ec_uart': [
r'ec_board:\S+',
],
'flex': [
r'servo_type:.*servo_.[^4]',
],
'type-c_servo_v4': [
r'servo_v4_type:type-c',
r'servo_v4_role:\S+',
],
}
# Supported methods to resetting cr50.
SUPPORTED_RESETS = (
'battery_cutoff',
'cr50_reset_odl',
'manual_reset',
)
class Error(Exception):
"""Exception class for flash_cr50 utility."""
def run_command(cmd, check_error=True):
"""Run the given command.
Args:
cmd: The command to run as a list of arguments.
check_error: Raise an error if the command fails.
Returns:
(exit_status, The command output)
Raises:
The command error if the command fails and check_error is True.
"""
try:
result = cros_build_lib.run(cmd,
check=check_error,
print_cmd=True,
capture_output=True,
encoding='utf-8',
stderr=subprocess.STDOUT,
debug_level=logging.DEBUG,
log_output=True)
except cros_build_lib.RunCommandError as cmd_error:
if check_error:
raise
# OSErrors are handled differently. They're raised even if check is
# False. Return the errno and message for OS errors.
return cmd_error.exception.errno, cmd_error.msg
return result.returncode, result.stdout.strip()
class Cr50Image(object):
"""Class to handle cr50 image conversions."""
SUFFIX_LEN = 6
RW_NAME_BASE = 'cr50.rw.'
def __init__(self, image, artifacts_dir):
"""Create an image object that can be used by cr50 updaters."""
self._remove_dir = False
if not os.path.exists(image):
raise Error('Could not find image: %s' % image)
if not artifacts_dir:
self._remove_dir = tempfile.mkdtemp()
artifacts_dir = self._remove_dir
if not os.path.isdir(artifacts_dir):
raise Error('Directory does not exist: %s' % artifacts_dir)
self._original_image = image
self._artifacts_dir = artifacts_dir
self._generate_file_names()
def __del__(self):
"""Remove temporary files."""
if self._remove_dir:
shutil.rmtree(self._remove_dir)
def _generate_file_names(self):
"""Create some filenames to use for image conversion artifacts."""
self._tmp_rw_bin = os.path.join(self._artifacts_dir,
self.RW_NAME_BASE + '.bin')
self._tmp_rw_hex = os.path.join(self._artifacts_dir,
self.RW_NAME_BASE + '.hex')
self._tmp_cr50_bin = os.path.join(self._artifacts_dir,
self.RW_NAME_BASE + '.orig.bin')
def extract_rw_a_hex(self):
"""Extract RW_A.hex from the original image."""
run_command(['cp', self.get_bin(), self._tmp_cr50_bin])
run_command(['dd', 'if=' + self._tmp_cr50_bin, 'of=' + self._tmp_rw_bin,
'skip=16384', 'count=233472', 'bs=1'])
run_command(['objcopy', '-I', 'binary', '-O', 'ihex',
'--change-addresses', '0x44000', self._tmp_rw_bin,
self._tmp_rw_hex])
def get_rw_hex(self):
"""cr50-rescue uses the .hex file."""
if not os.path.exists(self._tmp_rw_hex):
self.extract_rw_a_hex()
return self._tmp_rw_hex
def get_bin(self):
"""Get the filename of the update image."""
return self._original_image
def get_original_basename(self):
"""Get the basename of the original image."""
return os.path.basename(self._original_image)
class Servo(object):
"""Class to interact with servo."""
# Wait 3 seconds for device to settle after running the dut control command.
SHORT_WAIT = 3
def __init__(self, port):
"""Initialize servo class.
Args:
port: The servo port for the device being updated.
"""
self._port = port
def dut_control(self, cmd, check_error=True, wait=False):
"""Run dut control commands
Args:
cmd: the command to run
check_error: Raise RunCommandError if the command returns a non-zero
exit status.
wait: If True, wait SHORT_WAIT seconds after running the command
Returns:
(exit_status, output string) - The exit_status will be non-zero if
the command failed and check_error is True.
Raises:
RunCommandError if the command fails and check_error is False
"""
dut_control_cmd = ['dut-control', cmd, '-p', self._port]
exit_status, output = run_command(dut_control_cmd, check_error)
if wait:
time.sleep(self.SHORT_WAIT)
return exit_status, output.split(':', 1)[-1]
def get_raw_cr50_pty(self):
"""Return raw_cr50_pty. Disable ec3po, so the raw pty can be used."""
# Disconnect EC3PO, raw_cr50_uart_pty will control the cr50
# output and input.
self.dut_control('cr50_ec3po_interp_connect:off', wait=True)
return self.dut_control('raw_cr50_uart_pty')[1]
def get_cr50_version(self):
"""Return the current cr50 version string."""
# Make sure ec3po is enabled, so getting cr50_version works.
self.dut_control('cr50_ec3po_interp_connect:on', wait=True)
return self.dut_control('cr50_version')[1]
class Cr50Reset(object):
"""Class to enter and exit cr50 reset."""
# A list of requirements for the setup. The requirement strings must match
# something in the REQUIRED_CONTROLS dictionary.
REQUIRED_SETUP = ()
def __init__(self, servo, name):
"""Make sure the setup supports the given reset_type.
Args:
servo: The Servo object for the device.
name: The reset type.
"""
self._servo = servo
self._reset_name = name
self.verify_setup()
self._original_watchdog_state = self.ccd_watchdog_enabled()
self._servo_type = self._servo.dut_control('servo_type')[1]
def verify_setup(self):
"""Verify the setup has all required controls to flash cr50.
Raises:
Error if something is wrong with the setup.
"""
# If this failed before and didn't cleanup correctly, the device may be
# cutoff. Try to set the servo_v4_role to recover the device before
# checking the device state.
self._servo.dut_control('servo_v4_role:src', check_error=False)
logging.info('Requirements for %s: %s', self._reset_name,
pprint.pformat(self.REQUIRED_SETUP))
# Get the specific control requirements for the necessary categories.
required_controls = []
for category in self.REQUIRED_SETUP:
required_controls.extend(REQUIRED_CONTROLS[category])
logging.debug('Required controls for %r:\n%s', self._reset_name,
pprint.pformat(required_controls))
setup_issues = []
# Check the setup has all required controls in the correct state.
for required_control in required_controls:
control, exp_response = required_control.split(':')
returncode, output = self._servo.dut_control(control, False)
logging.debug('%s: got %s expect %s', control, output, exp_response)
match = re.search(exp_response, output)
if returncode:
setup_issues.append('%s: %s' % (control, output))
elif not match:
setup_issues.append('%s: need %s found %s' %
(control, exp_response, output))
else:
logging.debug('matched control: %s:%s', control, match.string)
# Save controls, so they can be restored during cleanup.
setattr(self, '_' + control, output)
if setup_issues:
raise Error('Cannot run update using %s. Setup issues: %s' %
(self._reset_name, setup_issues))
logging.info('Device Setup: ok')
logging.info('Reset Method: %s', self._reset_name)
def cleanup(self):
"""Try to get the device out of reset and restore all controls."""
logging.info('Cleaning up')
self.restore_control('cr50_ec3po_interp_connect')
# Toggle the servo v4 role if possible to try and get the device out of
# cutoff.
self._servo.dut_control('servo_v4_role:snk', check_error=False)
self._servo.dut_control('servo_v4_role:src', check_error=False)
self.restore_control('servo_v4_role')
# Restore the ccd watchdog.
self.enable_ccd_watchdog(self._original_watchdog_state)
def restore_control(self, control):
"""Restore the control setting, if it has been saved.
Args:
control: The name of the servo control to restore.
"""
setting = getattr(self, control, None)
if setting is None:
return
self._servo.dut_control('%s:%s' % (control, setting))
def ccd_watchdog_enabled(self):
"""Return True if servod is monitoring ccd"""
if 'ccd_cr50' not in self._servo_type:
return False
watchdog_state = self._servo.dut_control('watchdog')[1]
logging.debug(watchdog_state)
return not re.search('ccd:.*disconnect ok', watchdog_state)
def enable_ccd_watchdog(self, enable):
"""Control the CCD watchdog.
Servo will die if it's watching CCD and cr50 is held in reset. Disable
the CCD watchdog, so it's ok for CCD to disconnect.
This function does nothing if ccd_cr50 isn't in the servo type.
Args:
enable: If True, enable the CCD watchdog. Otherwise disable it.
"""
if 'ccd_cr50' not in self._servo_type:
logging.debug('Servo is not watching ccd device.')
return
if enable:
self._servo.dut_control('watchdog_add:ccd')
else:
self._servo.dut_control('watchdog_remove:ccd')
if self.ccd_watchdog_enabled() != enable:
raise Error('Could not %sable ccd watchdog' %
('en' if enable else 'dis'))
def enter_reset(self):
"""Disable the CCD watchdog then run the reset cr50 function."""
logging.info('Using %r to enter reset', self._reset_name)
# Disable the CCD watchdog before putting servo into reset otherwise
# servo will die in the middle of flashing cr50.
self.enable_ccd_watchdog(False)
try:
self.run_reset()
except Exception as e:
logging.warning('%s enter reset failed: %s', self._reset_name, e)
raise
def exit_reset(self):
"""Exit cr50 reset."""
logging.info('Recovering from %s', self._reset_name)
try:
self.recover_from_reset()
except Exception as e:
logging.warning('%s exit reset failed: %s', self._reset_name, e)
raise
def run_reset(self):
"""Start the cr50 reset process.
Cr50 doesn't have to enter reset in this function. It just needs to do
whatever setup is necessary for the exit reset function.
"""
raise NotImplementedError()
def recover_from_reset(self):
"""Recover from Cr50 reset.
Cr50 has to hard or power-on reset during this function for rescue to
work. Uart is disabled on deep sleep recovery, so deep sleep is not a
valid reset.
"""
raise NotImplementedError()
class Cr50ResetODLReset(Cr50Reset):
"""Class for using the servo cr50_reset_odl to reset cr50."""
REQUIRED_SETUP = (
# Rescue is done through Cr50 uart. It requires a flex cable not ccd.
'flex',
# cr50_reset_odl is used to hold cr50 in reset. This control only exists
# if it actually resets cr50.
'cr50_reset_odl',
# Cr50 rescue is done through cr50 uart.
'cr50_uart',
)
def cleanup(self):
"""Use the Cr50 reset signal to hold Cr50 in reset."""
try:
self.restore_control('cr50_reset_odl')
finally:
super(Cr50ResetODLReset, self).cleanup()
def run_reset(self):
"""Use cr50_reset_odl to hold Cr50 in reset."""
logging.info('cr50_reset_odl:on')
self._servo.dut_control('cr50_reset_odl:on')
def recover_from_reset(self):
"""Release the reset signal."""
logging.info('cr50_reset_odl:off')
self._servo.dut_control('cr50_reset_odl:off')
class BatteryCutoffReset(Cr50Reset):
"""Class for using a battery cutoff through EC commands to reset cr50."""
REQUIRED_SETUP = (
# Rescue is done through Cr50 uart. It requires a flex cable not ccd.
'flex',
# We need type c servo v4 to recover from battery_cutoff.
'type-c_servo_v4',
# Cr50 rescue is done through cr50 uart.
'cr50_uart',
# EC console needs to be read-write to issue cutoff command.
'ec_uart',
)
def run_reset(self):
"""Use EC commands to cutoff the battery."""
self._servo.dut_control('servo_v4_role:snk')
if self._servo.dut_control('ec_board', check_error=False)[0]:
logging.warning('EC is unresponsive. Cutoff may not work.')
self._servo.dut_control('ec_uart_cmd:cutoff', check_error=False,
wait=True)
self._servo.dut_control('ec_uart_cmd:reboot', check_error=False,
wait=True)
if not self._servo.dut_control('ec_board', check_error=False)[0]:
raise Error('EC still responsive after cutoff')
logging.info('Device is cutoff')
def recover_from_reset(self):
"""Connect power using servo v4 to recover from cutoff."""
logging.info('"Connecting" adapter')
self._servo.dut_control('servo_v4_role:src', wait=True)
class ManualReset(Cr50Reset):
"""Class for using a manual reset to reset Cr50."""
REQUIRED_SETUP = (
# Rescue is done through Cr50 uart. It requires a flex cable not ccd.
'flex',
# Cr50 rescue is done through cr50 uart.
'cr50_uart',
)
PROMPT_WAIT = 5
USER_RESET_TIMEOUT = 60
def run_reset(self):
"""Nothing to do. User will reset cr50."""
def recover_from_reset(self):
"""Wait for the user to reset cr50."""
end_time = time.time() + self.USER_RESET_TIMEOUT
while time.time() < end_time:
logging.info('Press enter after you reset cr50')
user_input = select.select([sys.stdin], [], [], self.PROMPT_WAIT)[0]
if user_input:
logging.info('User reset done')
return
logging.warning('User input timeout: assuming cr50 reset')
class FlashCr50(object):
"""Class for updating cr50."""
NAME = 'FlashCr50'
PACKAGE = ''
DEFAULT_UPDATER = ''
def __init__(self, cmd):
"""Verify the update command exists.
Args:
cmd: The updater command.
Raises:
Error if no valid updater command was found.
"""
updater = self.get_updater(cmd)
if not updater:
emerge_msg = (('Try emerging ' + self.PACKAGE) if self.PACKAGE
else '')
raise Error('Could not find %s command.%s' % (self, emerge_msg))
self._updater = updater
def get_updater(self, cmd):
"""Find a valid updater command.
Args:
cmd: the updater command.
Returns:
A command string or None if none of the commands ran successfully.
The command string will be the one supplied or the DEFAULT_UPDATER
command.
"""
if not self.updater_works(cmd):
return cmd
use_default = (self.DEFAULT_UPDATER and
not self.updater_works(self.DEFAULT_UPDATER))
if use_default:
logging.debug('%r failed using %r to update.', cmd,
self.DEFAULT_UPDATER)
return self.DEFAULT_UPDATER
return None
@staticmethod
def updater_works(cmd):
"""Verify the updater command.
Returns:
non-zero status if the command failed.
"""
logging.debug('Testing update command %r.', cmd)
exit_status, output = run_command([cmd, '-h'], check_error=False)
if 'Usage' in output:
return 0
if exit_status:
logging.debug('Could not run %r (%s): %s', cmd, exit_status, output)
return exit_status
def update(self, image):
"""Try to update cr50 to the given image."""
raise NotImplementedError()
def __str__(self):
"""Use the updater name for the tostring."""
return self.NAME
class GsctoolUpdater(FlashCr50):
"""Class to flash cr50 using gsctool."""
NAME = 'gsctool'
PACKAGE = 'ec-utils'
DEFAULT_UPDATER = '/usr/sbin/gsctool'
# Common failures exit with this status. Use STANDARD_ERRORS to map the
# exit status to reasons for the failure.
STANDARD_ERROR_REGEX = r'Error: status (\S+)'
STANDARD_ERRORS = {
'0x8': 'Rejected image with old header.',
'0x9': 'Update too soon.',
'0xc': 'Board id mismatch',
}
def __init__(self, cmd, serial=None):
"""Generate the gsctool command.
Args:
cmd: gsctool updater command.
serial: The serial number of the CCD device being updated.
"""
super(GsctoolUpdater, self).__init__(cmd)
self._gsctool_cmd = [self._updater]
if serial:
self._gsctool_cmd.extend(['-n', serial])
def update(self, image):
"""Use gsctool to update cr50.
Args:
image: Cr50Image object.
"""
update_cmd = self._gsctool_cmd[:]
update_cmd.append(image.get_bin())
exit_status, output = run_command(update_cmd, check_error=False)
if not exit_status or (exit_status == 1 and 'image updated' in output):
logging.info('update ok')
return
if exit_status == 3:
match = re.search(self.STANDARD_ERROR_REGEX, output)
if match:
update_error = match.group(1)
logging.info('Update error %s', update_error)
raise Error(self.STANDARD_ERRORS[update_error])
raise Error('gsctool update error: %s' % output.splitlines()[-1])
class Cr50RescueUpdater(FlashCr50):
"""Class to flash cr50 through servo micro uart."""
NAME = 'cr50-rescue'
PACKAGE = 'cr50-utils'
DEFAULT_UPDATER = '/usr/bin/cr50-rescue'
WAIT_FOR_UPDATE = 120
RESCUE_RESET_DELAY = 5
def __init__(self, cmd, port, reset_type):
"""Initialize cr50-rescue updater.
cr50-rescue can only be done through servo, because it needs access to
a lot of dut-controls and cr50 uart through servo micro. During rescue
Cr50 has to do a hard reset, so the user should supply a valid reset
method for the setup that's being used.
Args:
cmd: The cr50-rescue command.
port: The servo port of the device being updated.
reset_type: A string (one of SUPPORTED_RESETS) that describes how
to reset Cr50 during cr50-rescue.
"""
super(Cr50RescueUpdater, self).__init__(cmd)
self._servo = Servo(port)
self._rescue_thread = None
self._rescue_process = None
self._cr50_reset = self.get_cr50_reset(reset_type)
def get_cr50_reset(self, reset_type):
"""Get the cr50 reset object for the given reset_type.
Args:
reset_type: a string describing how cr50 will be reset. It must be
in SUPPORTED_RESETS.
Returns:
The Cr50Reset object for the given reset_type.
"""
assert reset_type in SUPPORTED_RESETS, '%s is unsupported.' % reset_type
if reset_type == 'battery_cutoff':
return BatteryCutoffReset(self._servo, reset_type)
elif reset_type == 'cr50_reset_odl':
return Cr50ResetODLReset(self._servo, reset_type)
return ManualReset(self._servo, reset_type)
def update(self, image):
"""Use cr50-rescue to update cr50 then cleanup.
Args:
image: Cr50Image object.
"""
update_file = image.get_rw_hex()
try:
self.run_update(update_file)
finally:
self.restore_state()
def start_rescue_process(self, update_file):
"""Run cr50-rescue in a process, so it can be killed it if it hangs."""
pty = self._servo.get_raw_cr50_pty()
rescue_cmd = [self._updater, '-v', '-i', update_file, '-d', pty]
logging.info('Starting cr50-rescue: %s',
cros_build_lib.CmdToStr(rescue_cmd))
self._rescue_process = subprocess.Popen(rescue_cmd)
self._rescue_process.communicate()
logging.info('Rescue Finished')
def start_rescue_thread(self, update_file):
"""Start cr50-rescue."""
self._rescue_thread = threading.Thread(target=self.start_rescue_process,
args=[update_file])
self._rescue_thread.start()
def run_update(self, update_file):
"""Run the Update"""
# Enter reset before starting rescue, so any extra cr50 messages won't
# interfere with cr50-rescue.
self._cr50_reset.enter_reset()
self.start_rescue_thread(update_file)
time.sleep(self.RESCUE_RESET_DELAY)
# Resume from cr50 reset.
self._cr50_reset.exit_reset()
self._rescue_thread.join(self.WAIT_FOR_UPDATE)
logging.info('cr50_version:%s', self._servo.get_cr50_version())
def restore_state(self):
"""Try to get the device out of reset and restore all controls"""
try:
self._cr50_reset.cleanup()
finally:
self.cleanup_rescue_thread()
def cleanup_rescue_thread(self):
"""Cleanup the rescue process and handle any errors."""
if not self._rescue_thread:
return
if self._rescue_thread.is_alive():
logging.info('Killing cr50-rescue process')
self._rescue_process.terminate()
self._rescue_thread.join()
self._rescue_thread = None
if self._rescue_process.returncode:
logging.info('cr50-rescue failed.')
logging.info('stderr: %s', self._rescue_process.stderr)
logging.info('stdout: %s', self._rescue_process.stdout)
logging.info('returncode: %s', self._rescue_process.returncode)
raise Error('cr50-rescue failed (%d)' %
self._rescue_process.returncode)
def parse_args(argv):
"""Parse commandline arguments.
Args:
argv: command line args
Returns:
options: an argparse.Namespace.
"""
usage = ('%s -i $IMAGE [ -c cr50-rescue -p $SERVO_PORT [ -r '
'$RESET_METHOD]]' % os.path.basename(argv[0]))
parser = argparse.ArgumentParser(usage=usage, description=__doc__)
parser.add_argument('-d', '--debug', action='store_true', default=False,
help='enable debug messages.')
parser.add_argument('-i', '--image', type=str,
help='Path to cr50 binary image.')
parser.add_argument('-R', '--release', type=str,
choices=RELEASE_PATHS.keys(),
help='Type of cr50 release. Use instead of the image '
'arg.')
parser.add_argument('-c', '--updater-cmd', type=str, default='gsctool',
help='Tool to update cr50. Either gsctool or '
'cr50-rescue')
parser.add_argument('-s', '--serial', type=str, default='',
help='serial number to pass to gsctool.')
parser.add_argument('-p', '--port', type=str, default='',
help='port servod is listening on (required for '
'rescue).')
parser.add_argument('-r', '--reset-type', default='battery_cutoff',
choices=SUPPORTED_RESETS,
type=str, help='The method for cr50 reset.')
parser.add_argument('-a', '--artifacts-dir', default=None, type=str,
help='Location to store artifacts')
opts = parser.parse_args(argv[1:])
if 'cr50-rescue' in opts.updater_cmd and not opts.port:
raise parser.error('Servo port is required for cr50 rescue')
return opts
def get_updater(opts):
"""Get the updater object."""
if 'cr50-rescue' in opts.updater_cmd:
return Cr50RescueUpdater(opts.updater_cmd, opts.port, opts.reset_type)
if 'gsctool' in opts.updater_cmd:
return GsctoolUpdater(opts.updater_cmd, opts.serial)
raise Error('Unsupported update command %r' % opts.updater_cmd)
def main(argv):
"""Update cr50 using gsctool or cr50-rescue."""
opts = parse_args(argv)
loglevel = logging.INFO
log_format = '%(asctime)s - %(levelname)7s'
if opts.debug:
loglevel = logging.DEBUG
log_format += ' - %(lineno)3d:%(funcName)-15s'
log_format += ' - %(message)s'
logging.basicConfig(level=loglevel, format=log_format)
image = Cr50Image(RELEASE_PATHS.get(opts.release, opts.image),
opts.artifacts_dir)
flash_cr50 = get_updater(opts)
logging.info('Using %s to update to %s', flash_cr50,
image.get_original_basename())
flash_cr50.update(image)
if __name__ == '__main__':
sys.exit(main(sys.argv))
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
25455,
710,
12051,
4403,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
624,
29189,
30277,
1400,
1808,
8763,
319,
21943,
503,
2467,
1400,
13,
23435,
14,
199,
199,
458,
319,
21943,
2893,
26,
199,
1974,
15,
11331,
63,
1556,
1400,
14,
647,
1553,
1569,
2467,
1400,
14,
1393,
14,
8788,
199,
1974,
15,
11331,
63,
1556,
1400,
14,
647,
1553,
3221,
12441,
199,
199,
1556,
1400,
13,
23435,
2893,
26,
199,
1974,
15,
11331,
63,
1556,
1400,
14,
647,
1553,
1569,
2467,
1400,
14,
1393,
14,
8788,
446,
67,
2467,
1400,
13,
23435,
446,
80,
221,
5008,
199,
1974,
15,
11331,
63,
1556,
1400,
14,
647,
1553,
3221,
12441,
446,
67,
2467,
1400,
13,
23435,
446,
80,
221,
5008,
199,
624,
199,
199,
646,
7534,
199,
646,
747,
199,
646,
10933,
199,
646,
295,
199,
646,
3504,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
646,
5796,
199,
646,
900,
199,
199,
504,
20074,
1175,
14,
773,
492,
25532,
63,
1506,
63,
773,
199,
504,
20074,
1175,
14,
773,
492,
25532,
63,
4806,
465,
2050,
199,
199,
2944,
1400,
63,
28830,
3695,
63,
5825,
275,
1994,
2992,
15,
3098,
15,
1556,
1400,
15,
26374,
15,
1556,
1400,
14,
1393,
3530,
199,
19736,
63,
20202,
275,
469,
272,
283,
657,
1381,
84,
356,
17101,
1400,
63,
28830,
3695,
63,
5825,
435,
283,
657,
1381,
84,
297,
272,
283,
8788,
356,
17101,
1400,
63,
28830,
3695,
63,
5825,
435,
283,
8788,
297,
199,
93,
199,
3,
11932,
4412,
282,
3272,
370,
13467,
1202,
370,
4911,
626,
314,
3272,
365,
199,
3,
3211,
14,
710,
2883,
787,
3326,
436,
314,
1338,
787,
5548,
402,
3326,
14,
199,
12496,
63,
5801,
1092,
5296,
275,
469,
272,
283,
1556,
1400,
63,
85,
580,
356,
359,
267,
519,
7,
1773,
63,
1556,
1400,
63,
85,
580,
63,
28563,
3427,
51,
7386,
267,
519,
7,
1556,
1400,
63,
825,
19,
555,
63,
14252,
63,
2242,
3427,
51,
7386,
272,
2156,
272,
283,
1556,
1400,
63,
3958,
63,
364,
76,
356,
359,
267,
519,
7,
1556,
1400,
63,
3958,
63,
364,
76,
3427,
51,
7386,
272,
2156,
272,
283,
825,
63,
85,
580,
356,
359,
267,
519,
7,
825,
63,
3576,
3427,
51,
7386,
272,
2156,
272,
283,
14759,
356,
359,
267,
519,
1159,
281,
2392,
63,
466,
26,
2795,
25943,
3754,
4735,
20,
4300,
272,
2156,
272,
283,
466,
13,
67,
63,
25943,
63,
86,
20,
356,
359,
267,
519,
1159,
281,
2392,
63,
86,
20,
63,
466,
26,
466,
13,
67,
297,
267,
519,
1159,
281,
2392,
63,
86,
20,
63,
3756,
3427,
51,
7386,
272,
2156,
199,
93,
199,
3,
26167,
3102,
370,
5305,
1337,
2467,
1400,
14,
199,
15925,
63,
18066,
51,
275,
334,
272,
283,
21113,
63,
17708,
297,
272,
283,
1556,
1400,
63,
3958,
63,
364,
76,
297,
272,
283,
9285,
63,
3958,
297,
199,
9,
421,
199,
533,
4520,
8,
1726,
304,
272,
408,
1726,
1021,
367,
14775,
63,
1556,
1400,
11420,
1041,
421,
199,
318,
1255,
63,
1531,
8,
1760,
12,
1104,
63,
705,
29,
549,
304,
272,
408,
2540,
314,
1627,
1414,
14,
339,
3033,
26,
267,
2088,
26,
710,
1414,
370,
1255,
465,
282,
769,
402,
2368,
14,
267,
1104,
63,
705,
26,
14771,
376,
1125,
340,
314,
1414,
6918,
14,
339,
1803,
26,
267,
334,
2224,
63,
1205,
12,
710,
1414,
1072,
9,
339,
6218,
26,
267,
710,
1414,
1125,
340,
314,
1414,
6918,
436,
1104,
63,
705,
365,
715,
14,
272,
408,
272,
862,
26,
267,
754,
275,
25532,
63,
1506,
63,
773,
14,
1065,
8,
1760,
12,
2511,
1104,
29,
1074,
63,
705,
12,
2511,
870,
63,
1760,
29,
549,
12,
2511,
12296,
63,
1199,
29,
549,
12,
2511,
2644,
534,
1624,
13,
24,
297,
2511,
4635,
29,
5781,
14,
13850,
12,
2511,
3105,
63,
1896,
29,
4806,
14,
5287,
12,
2511,
943,
63,
1199,
29,
549,
9,
272,
871,
25532,
63,
1506,
63,
773,
14,
2540,
31542,
465,
2088,
63,
705,
26,
267,
340,
1104,
63,
705,
26,
288,
746,
267,
327,
6440,
83,
787,
8860,
23142,
14,
9322,
3984,
4915,
2755,
340,
1104,
365,
267,
327,
756,
14,
1432,
314,
7554,
436,
1245,
367,
4403,
2552,
14,
267,
372,
2088,
63,
705,
14,
1971,
14,
7931,
12,
2088,
63,
705,
14,
1328,
272,
372,
754,
14,
9913,
12,
754,
14,
2703,
14,
1913,
342,
421,
199,
533,
30277,
1400,
3491,
8,
785,
304,
272,
408,
2543,
370,
2429,
2467,
1400,
1834,
24796,
1041,
339,
5698,
1665,
3867,
63,
5304,
275,
1227,
272,
820,
55,
63,
2339,
63,
5825,
275,
283,
1556,
1400,
14,
13057,
3530,
339,
347,
636,
826,
721,
277,
12,
1834,
12,
27990,
63,
694,
304,
267,
408,
2499,
376,
1834,
909,
626,
883,
506,
1202,
701,
2467,
1400,
1678,
2393,
1041,
267,
291,
423,
2168,
63,
694,
275,
756,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
1569,
304,
288,
746,
4520,
360,
6531,
440,
2342,
1834,
26,
450,
83,
7,
450,
1834,
9,
267,
340,
440,
27990,
63,
694,
26,
288,
291,
423,
2168,
63,
694,
275,
5549,
14,
11983,
342,
288,
27990,
63,
694,
275,
291,
423,
2168,
63,
694,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
30129,
63,
694,
304,
288,
746,
4520,
360,
6231,
1630,
440,
2187,
26,
450,
83,
7,
450,
27990,
63,
694,
9,
267,
291,
423,
5043,
63,
1569,
275,
1834,
267,
291,
423,
30129,
63,
694,
275,
27990,
63,
694,
267,
291,
423,
4208,
63,
493,
63,
1247,
342,
339,
347,
636,
2264,
721,
277,
304,
267,
408,
5587,
7937,
1584,
1041,
267,
340,
291,
423,
2168,
63,
694,
26,
288,
5145,
14,
9242,
8,
277,
423,
2168,
63,
694,
9,
339,
347,
485,
4208,
63,
493,
63,
1247,
8,
277,
304,
267,
408,
2499,
2005,
6203,
370,
675,
367,
1834,
8603,
27990,
1041,
267,
291,
423,
2791,
63,
13057,
63,
1393,
275
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
25455,
710,
12051,
4403,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
624,
29189,
30277,
1400,
1808,
8763,
319,
21943,
503,
2467,
1400,
13,
23435,
14,
199,
199,
458,
319,
21943,
2893,
26,
199,
1974,
15,
11331,
63,
1556,
1400,
14,
647,
1553,
1569,
2467,
1400,
14,
1393,
14,
8788,
199,
1974,
15,
11331,
63,
1556,
1400,
14,
647,
1553,
3221,
12441,
199,
199,
1556,
1400,
13,
23435,
2893,
26,
199,
1974,
15,
11331,
63,
1556,
1400,
14,
647,
1553,
1569,
2467,
1400,
14,
1393,
14,
8788,
446,
67,
2467,
1400,
13,
23435,
446,
80,
221,
5008,
199,
1974,
15,
11331,
63,
1556,
1400,
14,
647,
1553,
3221,
12441,
446,
67,
2467,
1400,
13,
23435,
446,
80,
221,
5008,
199,
624,
199,
199,
646,
7534,
199,
646,
747,
199,
646,
10933,
199,
646,
295,
199,
646,
3504,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
646,
5796,
199,
646,
900,
199,
199,
504,
20074,
1175,
14,
773,
492,
25532,
63,
1506,
63,
773,
199,
504,
20074,
1175,
14,
773,
492,
25532,
63,
4806,
465,
2050,
199,
199,
2944,
1400,
63,
28830,
3695,
63,
5825,
275,
1994,
2992,
15,
3098,
15,
1556,
1400,
15,
26374,
15,
1556,
1400,
14,
1393,
3530,
199,
19736,
63,
20202,
275,
469,
272,
283,
657,
1381,
84,
356,
17101,
1400,
63,
28830,
3695,
63,
5825,
435,
283,
657,
1381,
84,
297,
272,
283,
8788,
356,
17101,
1400,
63,
28830,
3695,
63,
5825,
435,
283,
8788,
297,
199,
93,
199,
3,
11932,
4412,
282,
3272,
370,
13467,
1202,
370,
4911,
626,
314,
3272,
365,
199,
3,
3211,
14,
710,
2883,
787,
3326,
436,
314,
1338,
787,
5548,
402,
3326,
14,
199,
12496,
63,
5801,
1092,
5296,
275,
469,
272,
283,
1556,
1400,
63,
85,
580,
356,
359,
267,
519,
7,
1773,
63,
1556,
1400,
63,
85,
580,
63,
28563,
3427,
51,
7386,
267,
519,
7,
1556,
1400,
63,
825,
19,
555,
63,
14252,
63,
2242,
3427,
51,
7386,
272,
2156,
272,
283,
1556,
1400,
63,
3958,
63,
364,
76,
356,
359,
267,
519,
7,
1556,
1400,
63,
3958,
63,
364,
76,
3427,
51,
7386,
272,
2156,
272,
283,
825,
63,
85,
580,
356,
359,
267,
519,
7,
825,
63,
3576,
3427,
51,
7386,
272,
2156,
272,
283,
14759,
356,
359,
267,
519,
1159,
281,
2392,
63,
466,
26,
2795,
25943,
3754,
4735,
20,
4300,
272,
2156,
272,
283,
466,
13,
67,
63,
25943,
63,
86,
20,
356,
359,
267,
519,
1159,
281,
2392,
63,
86,
20,
63,
466,
26,
466,
13,
67,
297,
267,
519,
1159,
281,
2392,
63,
86,
20,
63,
3756,
3427,
51,
7386,
272,
2156,
199,
93,
199,
3,
26167,
3102,
370,
5305,
1337,
2467,
1400,
14,
199,
15925,
63,
18066,
51,
275,
334,
272,
283,
21113,
63,
17708,
297,
272,
283,
1556,
1400,
63,
3958,
63,
364,
76,
297,
272,
283,
9285,
63,
3958,
297,
199,
9,
421,
199,
533,
4520,
8,
1726,
304,
272,
408,
1726,
1021,
367,
14775,
63,
1556,
1400,
11420,
1041,
421,
199,
318,
1255,
63,
1531,
8,
1760,
12,
1104,
63,
705,
29,
549,
304,
272,
408,
2540,
314,
1627,
1414,
14,
339,
3033,
26,
267,
2088,
26,
710,
1414,
370,
1255,
465,
282,
769,
402,
2368,
14,
267,
1104,
63,
705,
26,
14771,
376,
1125,
340,
314,
1414,
6918,
14,
339,
1803,
26,
267,
334,
2224,
63,
1205,
12,
710,
1414,
1072,
9,
339,
6218,
26,
267,
710,
1414,
1125,
340,
314,
1414,
6918,
436,
1104,
63,
705,
365,
715,
14,
272,
408,
272,
862,
26,
267,
754,
275,
25532,
63,
1506,
63,
773,
14,
1065,
8,
1760,
12,
2511,
1104,
29,
1074,
63,
705,
12,
2511,
870,
63,
1760,
29,
549,
12,
2511,
12296,
63,
1199,
29,
549,
12,
2511,
2644,
534,
1624,
13,
24,
297,
2511,
4635,
29,
5781,
14,
13850,
12,
2511,
3105,
63,
1896,
29,
4806,
14,
5287,
12,
2511,
943,
63,
1199,
29,
549,
9,
272,
871,
25532,
63,
1506,
63,
773,
14,
2540,
31542,
465,
2088,
63,
705,
26,
267,
340,
1104,
63,
705,
26,
288,
746,
267,
327,
6440,
83,
787,
8860,
23142,
14,
9322,
3984,
4915,
2755,
340,
1104,
365,
267,
327,
756,
14,
1432,
314,
7554,
436,
1245,
367,
4403,
2552,
14,
267,
372,
2088,
63,
705,
14,
1971,
14,
7931,
12,
2088,
63,
705,
14,
1328,
272,
372,
754,
14,
9913,
12,
754,
14,
2703,
14,
1913,
342,
421,
199,
533,
30277,
1400,
3491,
8,
785,
304,
272,
408,
2543,
370,
2429,
2467,
1400,
1834,
24796,
1041,
339,
5698,
1665,
3867,
63,
5304,
275,
1227,
272,
820,
55,
63,
2339,
63,
5825,
275,
283,
1556,
1400,
14,
13057,
3530,
339,
347,
636,
826,
721,
277,
12,
1834,
12,
27990,
63,
694,
304,
267,
408,
2499,
376,
1834,
909,
626,
883,
506,
1202,
701,
2467,
1400,
1678,
2393,
1041,
267,
291,
423,
2168,
63,
694,
275,
756,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
1569,
304,
288,
746,
4520,
360,
6531,
440,
2342,
1834,
26,
450,
83,
7,
450,
1834,
9,
267,
340,
440,
27990,
63,
694,
26,
288,
291,
423,
2168,
63,
694,
275,
5549,
14,
11983,
342,
288,
27990,
63,
694,
275,
291,
423,
2168,
63,
694,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
30129,
63,
694,
304,
288,
746,
4520,
360,
6231,
1630,
440,
2187,
26,
450,
83,
7,
450,
27990,
63,
694,
9,
267,
291,
423,
5043,
63,
1569,
275,
1834,
267,
291,
423,
30129,
63,
694,
275,
27990,
63,
694,
267,
291,
423,
4208,
63,
493,
63,
1247,
342,
339,
347,
636,
2264,
721,
277,
304,
267,
408,
5587,
7937,
1584,
1041,
267,
340,
291,
423,
2168,
63,
694,
26,
288,
5145,
14,
9242,
8,
277,
423,
2168,
63,
694,
9,
339,
347,
485,
4208,
63,
493,
63,
1247,
8,
277,
304,
267,
408,
2499,
2005,
6203,
370,
675,
367,
1834,
8603,
27990,
1041,
267,
291,
423,
2791,
63,
13057,
63,
1393,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
firerszd/kbengine
|
kbe/res/scripts/common/Lib/encodings/utf_16_be.py
|
860
|
1037
|
""" Python 'utf-16-be' Codec
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
"""
import codecs
### Codec APIs
encode = codecs.utf_16_be_encode
def decode(input, errors='strict'):
return codecs.utf_16_be_decode(input, errors, True)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.utf_16_be_encode(input, self.errors)[0]
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
_buffer_decode = codecs.utf_16_be_decode
class StreamWriter(codecs.StreamWriter):
encode = codecs.utf_16_be_encode
class StreamReader(codecs.StreamReader):
decode = codecs.utf_16_be_decode
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='utf-16-be',
encode=encode,
decode=decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
|
lgpl-3.0
|
[
624,
2018,
283,
1624,
13,
975,
13,
1235,
7,
13732,
421,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
199,
624,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
2143,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
199,
199,
318,
4849,
8,
1210,
12,
2552,
534,
4768,
735,
272,
372,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
8,
1210,
12,
2552,
12,
715,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
23139,
16703,
304,
272,
485,
2738,
63,
2708,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
199,
199,
533,
24163,
8,
8933,
14,
16551,
304,
272,
3752,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
199,
199,
533,
22970,
8,
8933,
14,
16132,
304,
272,
4849,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1624,
13,
975,
13,
1235,
297,
267,
3752,
29,
2143,
12,
267,
4849,
29,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2018,
283,
1624,
13,
975,
13,
1235,
7,
13732,
421,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
199,
624,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
2143,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
199,
199,
318,
4849,
8,
1210,
12,
2552,
534,
4768,
735,
272,
372,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
8,
1210,
12,
2552,
12,
715,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
23139,
16703,
304,
272,
485,
2738,
63,
2708,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
199,
199,
533,
24163,
8,
8933,
14,
16551,
304,
272,
3752,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2143,
199,
199,
533,
22970,
8,
8933,
14,
16132,
304,
272,
4849,
275,
6010,
14,
1624,
63,
975,
63,
1235,
63,
2708,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1624,
13,
975,
13,
1235,
297,
267,
3752,
29,
2143,
12,
267,
4849,
29,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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address.py
|
339
|
80176
|
# Copyright 2007 Google Inc.
# Licensed to PSF under a Contributor Agreement.
"""A fast, lightweight IPv4/IPv6 manipulation library in Python.
This library is used to create/poke/manipulate IPv4 and IPv6 addresses
and networks.
"""
from __future__ import unicode_literals
import itertools
import struct
__version__ = '1.0.17'
# Compatibility functions
_compat_int_types = (int,)
try:
_compat_int_types = (int, long)
except NameError:
pass
try:
_compat_str = unicode
except NameError:
_compat_str = str
assert bytes != str
if b'\0'[0] == 0: # Python 3 semantics
def _compat_bytes_to_byte_vals(byt):
return byt
else:
def _compat_bytes_to_byte_vals(byt):
return [struct.unpack(b'!B', b)[0] for b in byt]
try:
_compat_int_from_byte_vals = int.from_bytes
except AttributeError:
def _compat_int_from_byte_vals(bytvals, endianess):
assert endianess == 'big'
res = 0
for bv in bytvals:
assert isinstance(bv, _compat_int_types)
res = (res << 8) + bv
return res
def _compat_to_bytes(intval, length, endianess):
assert isinstance(intval, _compat_int_types)
assert endianess == 'big'
if length == 4:
if intval < 0 or intval >= 2 ** 32:
raise struct.error("integer out of range for 'I' format code")
return struct.pack(b'!I', intval)
elif length == 16:
if intval < 0 or intval >= 2 ** 128:
raise struct.error("integer out of range for 'QQ' format code")
return struct.pack(b'!QQ', intval >> 64, intval & 0xffffffffffffffff)
else:
raise NotImplementedError()
if hasattr(int, 'bit_length'):
# Not int.bit_length , since that won't work in 2.7 where long exists
def _compat_bit_length(i):
return i.bit_length()
else:
def _compat_bit_length(i):
for res in itertools.count():
if i >> res == 0:
return res
def _compat_range(start, end, step=1):
assert step > 0
i = start
while i < end:
yield i
i += step
class _TotalOrderingMixin(object):
__slots__ = ()
# Helper that derives the other comparison operations from
# __lt__ and __eq__
# We avoid functools.total_ordering because it doesn't handle
# NotImplemented correctly yet (http://bugs.python.org/issue10042)
def __eq__(self, other):
raise NotImplementedError
def __ne__(self, other):
equal = self.__eq__(other)
if equal is NotImplemented:
return NotImplemented
return not equal
def __lt__(self, other):
raise NotImplementedError
def __le__(self, other):
less = self.__lt__(other)
if less is NotImplemented or not less:
return self.__eq__(other)
return less
def __gt__(self, other):
less = self.__lt__(other)
if less is NotImplemented:
return NotImplemented
equal = self.__eq__(other)
if equal is NotImplemented:
return NotImplemented
return not (less or equal)
def __ge__(self, other):
less = self.__lt__(other)
if less is NotImplemented:
return NotImplemented
return not less
IPV4LENGTH = 32
IPV6LENGTH = 128
class AddressValueError(ValueError):
"""A Value Error related to the address."""
class NetmaskValueError(ValueError):
"""A Value Error related to the netmask."""
def ip_address(address):
"""Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An IPv4Address or IPv6Address object.
Raises:
ValueError: if the *address* passed isn't either a v4 or a v6
address
"""
try:
return IPv4Address(address)
except (AddressValueError, NetmaskValueError):
pass
try:
return IPv6Address(address)
except (AddressValueError, NetmaskValueError):
pass
if isinstance(address, bytes):
raise AddressValueError(
'%r does not appear to be an IPv4 or IPv6 address. '
'Did you pass in a bytes (str in Python 2) instead of'
' a unicode object?' % address)
raise ValueError('%r does not appear to be an IPv4 or IPv6 address' %
address)
def ip_network(address, strict=True):
"""Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP network. Either IPv4 or
IPv6 networks may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An IPv4Network or IPv6Network object.
Raises:
ValueError: if the string passed isn't either a v4 or a v6
address. Or if the network has host bits set.
"""
try:
return IPv4Network(address, strict)
except (AddressValueError, NetmaskValueError):
pass
try:
return IPv6Network(address, strict)
except (AddressValueError, NetmaskValueError):
pass
if isinstance(address, bytes):
raise AddressValueError(
'%r does not appear to be an IPv4 or IPv6 network. '
'Did you pass in a bytes (str in Python 2) instead of'
' a unicode object?' % address)
raise ValueError('%r does not appear to be an IPv4 or IPv6 network' %
address)
def ip_interface(address):
"""Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
Returns:
An IPv4Interface or IPv6Interface object.
Raises:
ValueError: if the string passed isn't either a v4 or a v6
address.
Notes:
The IPv?Interface classes describe an Address on a particular
Network, so they're basically a combination of both the Address
and Network classes.
"""
try:
return IPv4Interface(address)
except (AddressValueError, NetmaskValueError):
pass
try:
return IPv6Interface(address)
except (AddressValueError, NetmaskValueError):
pass
raise ValueError('%r does not appear to be an IPv4 or IPv6 interface' %
address)
def v4_int_to_packed(address):
"""Represent an address as 4 packed bytes in network (big-endian) order.
Args:
address: An integer representation of an IPv4 IP address.
Returns:
The integer address packed as 4 bytes in network (big-endian) order.
Raises:
ValueError: If the integer is negative or too large to be an
IPv4 IP address.
"""
try:
return _compat_to_bytes(address, 4, 'big')
except (struct.error, OverflowError):
raise ValueError("Address negative or too large for IPv4")
def v6_int_to_packed(address):
"""Represent an address as 16 packed bytes in network (big-endian) order.
Args:
address: An integer representation of an IPv6 IP address.
Returns:
The integer address packed as 16 bytes in network (big-endian) order.
"""
try:
return _compat_to_bytes(address, 16, 'big')
except (struct.error, OverflowError):
raise ValueError("Address negative or too large for IPv6")
def _split_optional_netmask(address):
"""Helper to split the netmask and raise AddressValueError if needed"""
addr = _compat_str(address).split('/')
if len(addr) > 2:
raise AddressValueError("Only one '/' permitted in %r" % address)
return addr
def _find_address_range(addresses):
"""Find a sequence of sorted deduplicated IPv#Address.
Args:
addresses: a list of IPv#Address objects.
Yields:
A tuple containing the first and last IP addresses in the sequence.
"""
it = iter(addresses)
first = last = next(it)
for ip in it:
if ip._ip != last._ip + 1:
yield first, last
first = ip
last = ip
yield first, last
def _count_righthand_zero_bits(number, bits):
"""Count the number of zero bits on the right hand side.
Args:
number: an integer.
bits: maximum number of bits to count.
Returns:
The number of zero bits on the right hand side of the number.
"""
if number == 0:
return bits
return min(bits, _compat_bit_length(~number & (number - 1)))
def summarize_address_range(first, last):
"""Summarize a network range given the first and last IP addresses.
Example:
>>> list(summarize_address_range(IPv4Address('192.0.2.0'),
... IPv4Address('192.0.2.130')))
... #doctest: +NORMALIZE_WHITESPACE
[IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'),
IPv4Network('192.0.2.130/32')]
Args:
first: the first IPv4Address or IPv6Address in the range.
last: the last IPv4Address or IPv6Address in the range.
Returns:
An iterator of the summarized IPv(4|6) network objects.
Raise:
TypeError:
If the first and last objects are not IP addresses.
If the first and last objects are not the same version.
ValueError:
If the last object is not greater than the first.
If the version of the first address is not 4 or 6.
"""
if (not (isinstance(first, _BaseAddress) and
isinstance(last, _BaseAddress))):
raise TypeError('first and last must be IP addresses, not networks')
if first.version != last.version:
raise TypeError("%s and %s are not of the same version" % (
first, last))
if first > last:
raise ValueError('last IP address must be greater than first')
if first.version == 4:
ip = IPv4Network
elif first.version == 6:
ip = IPv6Network
else:
raise ValueError('unknown IP version')
ip_bits = first._max_prefixlen
first_int = first._ip
last_int = last._ip
while first_int <= last_int:
nbits = min(_count_righthand_zero_bits(first_int, ip_bits),
_compat_bit_length(last_int - first_int + 1) - 1)
net = ip((first_int, ip_bits - nbits))
yield net
first_int += 1 << nbits
if first_int - 1 == ip._ALL_ONES:
break
def _collapse_addresses_internal(addresses):
"""Loops through the addresses, collapsing concurrent netblocks.
Example:
ip1 = IPv4Network('192.0.2.0/26')
ip2 = IPv4Network('192.0.2.64/26')
ip3 = IPv4Network('192.0.2.128/26')
ip4 = IPv4Network('192.0.2.192/26')
_collapse_addresses_internal([ip1, ip2, ip3, ip4]) ->
[IPv4Network('192.0.2.0/24')]
This shouldn't be called directly; it is called via
collapse_addresses([]).
Args:
addresses: A list of IPv4Network's or IPv6Network's
Returns:
A list of IPv4Network's or IPv6Network's depending on what we were
passed.
"""
# First merge
to_merge = list(addresses)
subnets = {}
while to_merge:
net = to_merge.pop()
supernet = net.supernet()
existing = subnets.get(supernet)
if existing is None:
subnets[supernet] = net
elif existing != net:
# Merge consecutive subnets
del subnets[supernet]
to_merge.append(supernet)
# Then iterate over resulting networks, skipping subsumed subnets
last = None
for net in sorted(subnets.values()):
if last is not None:
# Since they are sorted,
# last.network_address <= net.network_address is a given.
if last.broadcast_address >= net.broadcast_address:
continue
yield net
last = net
def collapse_addresses(addresses):
"""Collapse a list of IP objects.
Example:
collapse_addresses([IPv4Network('192.0.2.0/25'),
IPv4Network('192.0.2.128/25')]) ->
[IPv4Network('192.0.2.0/24')]
Args:
addresses: An iterator of IPv4Network or IPv6Network objects.
Returns:
An iterator of the collapsed IPv(4|6)Network objects.
Raises:
TypeError: If passed a list of mixed version objects.
"""
addrs = []
ips = []
nets = []
# split IP addresses and networks
for ip in addresses:
if isinstance(ip, _BaseAddress):
if ips and ips[-1]._version != ip._version:
raise TypeError("%s and %s are not of the same version" % (
ip, ips[-1]))
ips.append(ip)
elif ip._prefixlen == ip._max_prefixlen:
if ips and ips[-1]._version != ip._version:
raise TypeError("%s and %s are not of the same version" % (
ip, ips[-1]))
try:
ips.append(ip.ip)
except AttributeError:
ips.append(ip.network_address)
else:
if nets and nets[-1]._version != ip._version:
raise TypeError("%s and %s are not of the same version" % (
ip, nets[-1]))
nets.append(ip)
# sort and dedup
ips = sorted(set(ips))
# find consecutive address ranges in the sorted sequence and summarize them
if ips:
for first, last in _find_address_range(ips):
addrs.extend(summarize_address_range(first, last))
return _collapse_addresses_internal(addrs + nets)
def get_mixed_type_key(obj):
"""Return a key suitable for sorting between networks and addresses.
Address and Network objects are not sortable by default; they're
fundamentally different so the expression
IPv4Address('192.0.2.0') <= IPv4Network('192.0.2.0/24')
doesn't make any sense. There are some times however, where you may wish
to have ipaddress sort these for you anyway. If you need to do this, you
can use this function as the key= argument to sorted().
Args:
obj: either a Network or Address object.
Returns:
appropriate key.
"""
if isinstance(obj, _BaseNetwork):
return obj._get_networks_key()
elif isinstance(obj, _BaseAddress):
return obj._get_address_key()
return NotImplemented
class _IPAddressBase(_TotalOrderingMixin):
"""The mother class."""
__slots__ = ()
@property
def exploded(self):
"""Return the longhand version of the IP address as a string."""
return self._explode_shorthand_ip_string()
@property
def compressed(self):
"""Return the shorthand version of the IP address as a string."""
return _compat_str(self)
@property
def reverse_pointer(self):
"""The name of the reverse DNS pointer for the IP address, e.g.:
>>> ipaddress.ip_address("127.0.0.1").reverse_pointer
'1.0.0.127.in-addr.arpa'
>>> ipaddress.ip_address("2001:db8::1").reverse_pointer
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
"""
return self._reverse_pointer()
@property
def version(self):
msg = '%200s has no version specified' % (type(self),)
raise NotImplementedError(msg)
def _check_int_address(self, address):
if address < 0:
msg = "%d (< 0) is not permitted as an IPv%d address"
raise AddressValueError(msg % (address, self._version))
if address > self._ALL_ONES:
msg = "%d (>= 2**%d) is not permitted as an IPv%d address"
raise AddressValueError(msg % (address, self._max_prefixlen,
self._version))
def _check_packed_address(self, address, expected_len):
address_len = len(address)
if address_len != expected_len:
msg = (
'%r (len %d != %d) is not permitted as an IPv%d address. '
'Did you pass in a bytes (str in Python 2) instead of'
' a unicode object?'
)
raise AddressValueError(msg % (address, address_len,
expected_len, self._version))
@classmethod
def _ip_int_from_prefix(cls, prefixlen):
"""Turn the prefix length into a bitwise netmask
Args:
prefixlen: An integer, the prefix length.
Returns:
An integer.
"""
return cls._ALL_ONES ^ (cls._ALL_ONES >> prefixlen)
@classmethod
def _prefix_from_ip_int(cls, ip_int):
"""Return prefix length from the bitwise netmask.
Args:
ip_int: An integer, the netmask in expanded bitwise format
Returns:
An integer, the prefix length.
Raises:
ValueError: If the input intermingles zeroes & ones
"""
trailing_zeroes = _count_righthand_zero_bits(ip_int,
cls._max_prefixlen)
prefixlen = cls._max_prefixlen - trailing_zeroes
leading_ones = ip_int >> trailing_zeroes
all_ones = (1 << prefixlen) - 1
if leading_ones != all_ones:
byteslen = cls._max_prefixlen // 8
details = _compat_to_bytes(ip_int, byteslen, 'big')
msg = 'Netmask pattern %r mixes zeroes & ones'
raise ValueError(msg % details)
return prefixlen
@classmethod
def _report_invalid_netmask(cls, netmask_str):
msg = '%r is not a valid netmask' % netmask_str
raise NetmaskValueError(msg)
@classmethod
def _prefix_from_prefix_string(cls, prefixlen_str):
"""Return prefix length from a numeric string
Args:
prefixlen_str: The string to be converted
Returns:
An integer, the prefix length.
Raises:
NetmaskValueError: If the input is not a valid netmask
"""
# int allows a leading +/- as well as surrounding whitespace,
# so we ensure that isn't the case
if not _BaseV4._DECIMAL_DIGITS.issuperset(prefixlen_str):
cls._report_invalid_netmask(prefixlen_str)
try:
prefixlen = int(prefixlen_str)
except ValueError:
cls._report_invalid_netmask(prefixlen_str)
if not (0 <= prefixlen <= cls._max_prefixlen):
cls._report_invalid_netmask(prefixlen_str)
return prefixlen
@classmethod
def _prefix_from_ip_string(cls, ip_str):
"""Turn a netmask/hostmask string into a prefix length
Args:
ip_str: The netmask/hostmask to be converted
Returns:
An integer, the prefix length.
Raises:
NetmaskValueError: If the input is not a valid netmask/hostmask
"""
# Parse the netmask/hostmask like an IP address.
try:
ip_int = cls._ip_int_from_string(ip_str)
except AddressValueError:
cls._report_invalid_netmask(ip_str)
# Try matching a netmask (this would be /1*0*/ as a bitwise regexp).
# Note that the two ambiguous cases (all-ones and all-zeroes) are
# treated as netmasks.
try:
return cls._prefix_from_ip_int(ip_int)
except ValueError:
pass
# Invert the bits, and try matching a /0+1+/ hostmask instead.
ip_int ^= cls._ALL_ONES
try:
return cls._prefix_from_ip_int(ip_int)
except ValueError:
cls._report_invalid_netmask(ip_str)
def __reduce__(self):
return self.__class__, (_compat_str(self),)
class _BaseAddress(_IPAddressBase):
"""A generic IP object.
This IP class contains the version independent methods which are
used by single IP addresses.
"""
__slots__ = ()
def __int__(self):
return self._ip
def __eq__(self, other):
try:
return (self._ip == other._ip and
self._version == other._version)
except AttributeError:
return NotImplemented
def __lt__(self, other):
if not isinstance(other, _IPAddressBase):
return NotImplemented
if not isinstance(other, _BaseAddress):
raise TypeError('%s and %s are not of the same type' % (
self, other))
if self._version != other._version:
raise TypeError('%s and %s are not of the same version' % (
self, other))
if self._ip != other._ip:
return self._ip < other._ip
return False
# Shorthand for Integer addition and subtraction. This is not
# meant to ever support addition/subtraction of addresses.
def __add__(self, other):
if not isinstance(other, _compat_int_types):
return NotImplemented
return self.__class__(int(self) + other)
def __sub__(self, other):
if not isinstance(other, _compat_int_types):
return NotImplemented
return self.__class__(int(self) - other)
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, _compat_str(self))
def __str__(self):
return _compat_str(self._string_from_ip_int(self._ip))
def __hash__(self):
return hash(hex(int(self._ip)))
def _get_address_key(self):
return (self._version, self)
def __reduce__(self):
return self.__class__, (self._ip,)
class _BaseNetwork(_IPAddressBase):
"""A generic IP network object.
This IP class contains the version independent methods which are
used by networks.
"""
def __init__(self, address):
self._cache = {}
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, _compat_str(self))
def __str__(self):
return '%s/%d' % (self.network_address, self.prefixlen)
def hosts(self):
"""Generate Iterator over usable hosts in a network.
This is like __iter__ except it doesn't return the network
or broadcast addresses.
"""
network = int(self.network_address)
broadcast = int(self.broadcast_address)
for x in _compat_range(network + 1, broadcast):
yield self._address_class(x)
def __iter__(self):
network = int(self.network_address)
broadcast = int(self.broadcast_address)
for x in _compat_range(network, broadcast + 1):
yield self._address_class(x)
def __getitem__(self, n):
network = int(self.network_address)
broadcast = int(self.broadcast_address)
if n >= 0:
if network + n > broadcast:
raise IndexError('address out of range')
return self._address_class(network + n)
else:
n += 1
if broadcast + n < network:
raise IndexError('address out of range')
return self._address_class(broadcast + n)
def __lt__(self, other):
if not isinstance(other, _IPAddressBase):
return NotImplemented
if not isinstance(other, _BaseNetwork):
raise TypeError('%s and %s are not of the same type' % (
self, other))
if self._version != other._version:
raise TypeError('%s and %s are not of the same version' % (
self, other))
if self.network_address != other.network_address:
return self.network_address < other.network_address
if self.netmask != other.netmask:
return self.netmask < other.netmask
return False
def __eq__(self, other):
try:
return (self._version == other._version and
self.network_address == other.network_address and
int(self.netmask) == int(other.netmask))
except AttributeError:
return NotImplemented
def __hash__(self):
return hash(int(self.network_address) ^ int(self.netmask))
def __contains__(self, other):
# always false if one is v4 and the other is v6.
if self._version != other._version:
return False
# dealing with another network.
if isinstance(other, _BaseNetwork):
return False
# dealing with another address
else:
# address
return (int(self.network_address) <= int(other._ip) <=
int(self.broadcast_address))
def overlaps(self, other):
"""Tell if self is partly contained in other."""
return self.network_address in other or (
self.broadcast_address in other or (
other.network_address in self or (
other.broadcast_address in self)))
@property
def broadcast_address(self):
x = self._cache.get('broadcast_address')
if x is None:
x = self._address_class(int(self.network_address) |
int(self.hostmask))
self._cache['broadcast_address'] = x
return x
@property
def hostmask(self):
x = self._cache.get('hostmask')
if x is None:
x = self._address_class(int(self.netmask) ^ self._ALL_ONES)
self._cache['hostmask'] = x
return x
@property
def with_prefixlen(self):
return '%s/%d' % (self.network_address, self._prefixlen)
@property
def with_netmask(self):
return '%s/%s' % (self.network_address, self.netmask)
@property
def with_hostmask(self):
return '%s/%s' % (self.network_address, self.hostmask)
@property
def num_addresses(self):
"""Number of hosts in the current subnet."""
return int(self.broadcast_address) - int(self.network_address) + 1
@property
def _address_class(self):
# Returning bare address objects (rather than interfaces) allows for
# more consistent behaviour across the network address, broadcast
# address and individual host addresses.
msg = '%200s has no associated address class' % (type(self),)
raise NotImplementedError(msg)
@property
def prefixlen(self):
return self._prefixlen
def address_exclude(self, other):
"""Remove an address from a larger block.
For example:
addr1 = ip_network('192.0.2.0/28')
addr2 = ip_network('192.0.2.1/32')
list(addr1.address_exclude(addr2)) =
[IPv4Network('192.0.2.0/32'), IPv4Network('192.0.2.2/31'),
IPv4Network('192.0.2.4/30'), IPv4Network('192.0.2.8/29')]
or IPv6:
addr1 = ip_network('2001:db8::1/32')
addr2 = ip_network('2001:db8::1/128')
list(addr1.address_exclude(addr2)) =
[ip_network('2001:db8::1/128'),
ip_network('2001:db8::2/127'),
ip_network('2001:db8::4/126'),
ip_network('2001:db8::8/125'),
...
ip_network('2001:db8:8000::/33')]
Args:
other: An IPv4Network or IPv6Network object of the same type.
Returns:
An iterator of the IPv(4|6)Network objects which is self
minus other.
Raises:
TypeError: If self and other are of differing address
versions, or if other is not a network object.
ValueError: If other is not completely contained by self.
"""
if not self._version == other._version:
raise TypeError("%s and %s are not of the same version" % (
self, other))
if not isinstance(other, _BaseNetwork):
raise TypeError("%s is not a network object" % other)
if not other.subnet_of(self):
raise ValueError('%s not contained in %s' % (other, self))
if other == self:
return
# Make sure we're comparing the network of other.
other = other.__class__('%s/%s' % (other.network_address,
other.prefixlen))
s1, s2 = self.subnets()
while s1 != other and s2 != other:
if other.subnet_of(s1):
yield s2
s1, s2 = s1.subnets()
elif other.subnet_of(s2):
yield s1
s1, s2 = s2.subnets()
else:
# If we got here, there's a bug somewhere.
raise AssertionError('Error performing exclusion: '
's1: %s s2: %s other: %s' %
(s1, s2, other))
if s1 == other:
yield s2
elif s2 == other:
yield s1
else:
# If we got here, there's a bug somewhere.
raise AssertionError('Error performing exclusion: '
's1: %s s2: %s other: %s' %
(s1, s2, other))
def compare_networks(self, other):
"""Compare two IP objects.
This is only concerned about the comparison of the integer
representation of the network addresses. This means that the
host bits aren't considered at all in this method. If you want
to compare host bits, you can easily enough do a
'HostA._ip < HostB._ip'
Args:
other: An IP object.
Returns:
If the IP versions of self and other are the same, returns:
-1 if self < other:
eg: IPv4Network('192.0.2.0/25') < IPv4Network('192.0.2.128/25')
IPv6Network('2001:db8::1000/124') <
IPv6Network('2001:db8::2000/124')
0 if self == other
eg: IPv4Network('192.0.2.0/24') == IPv4Network('192.0.2.0/24')
IPv6Network('2001:db8::1000/124') ==
IPv6Network('2001:db8::1000/124')
1 if self > other
eg: IPv4Network('192.0.2.128/25') > IPv4Network('192.0.2.0/25')
IPv6Network('2001:db8::2000/124') >
IPv6Network('2001:db8::1000/124')
Raises:
TypeError if the IP versions are different.
"""
# does this need to raise a ValueError?
if self._version != other._version:
raise TypeError('%s and %s are not of the same type' % (
self, other))
# self._version == other._version below here:
if self.network_address < other.network_address:
return -1
if self.network_address > other.network_address:
return 1
# self.network_address == other.network_address below here:
if self.netmask < other.netmask:
return -1
if self.netmask > other.netmask:
return 1
return 0
def _get_networks_key(self):
"""Network-only key function.
Returns an object that identifies this address' network and
netmask. This function is a suitable "key" argument for sorted()
and list.sort().
"""
return (self._version, self.network_address, self.netmask)
def subnets(self, prefixlen_diff=1, new_prefix=None):
"""The subnets which join to make the current subnet.
In the case that self contains only one IP
(self._prefixlen == 32 for IPv4 or self._prefixlen == 128
for IPv6), yield an iterator with just ourself.
Args:
prefixlen_diff: An integer, the amount the prefix length
should be increased by. This should not be set if
new_prefix is also set.
new_prefix: The desired new prefix length. This must be a
larger number (smaller prefix) than the existing prefix.
This should not be set if prefixlen_diff is also set.
Returns:
An iterator of IPv(4|6) objects.
Raises:
ValueError: The prefixlen_diff is too small or too large.
OR
prefixlen_diff and new_prefix are both set or new_prefix
is a smaller number than the current prefix (smaller
number means a larger network)
"""
if self._prefixlen == self._max_prefixlen:
yield self
return
if new_prefix is not None:
if new_prefix < self._prefixlen:
raise ValueError('new prefix must be longer')
if prefixlen_diff != 1:
raise ValueError('cannot set prefixlen_diff and new_prefix')
prefixlen_diff = new_prefix - self._prefixlen
if prefixlen_diff < 0:
raise ValueError('prefix length diff must be > 0')
new_prefixlen = self._prefixlen + prefixlen_diff
if new_prefixlen > self._max_prefixlen:
raise ValueError(
'prefix length diff %d is invalid for netblock %s' % (
new_prefixlen, self))
start = int(self.network_address)
end = int(self.broadcast_address) + 1
step = (int(self.hostmask) + 1) >> prefixlen_diff
for new_addr in _compat_range(start, end, step):
current = self.__class__((new_addr, new_prefixlen))
yield current
def supernet(self, prefixlen_diff=1, new_prefix=None):
"""The supernet containing the current network.
Args:
prefixlen_diff: An integer, the amount the prefix length of
the network should be decreased by. For example, given a
/24 network and a prefixlen_diff of 3, a supernet with a
/21 netmask is returned.
Returns:
An IPv4 network object.
Raises:
ValueError: If self.prefixlen - prefixlen_diff < 0. I.e., you have
a negative prefix length.
OR
If prefixlen_diff and new_prefix are both set or new_prefix is a
larger number than the current prefix (larger number means a
smaller network)
"""
if self._prefixlen == 0:
return self
if new_prefix is not None:
if new_prefix > self._prefixlen:
raise ValueError('new prefix must be shorter')
if prefixlen_diff != 1:
raise ValueError('cannot set prefixlen_diff and new_prefix')
prefixlen_diff = self._prefixlen - new_prefix
new_prefixlen = self.prefixlen - prefixlen_diff
if new_prefixlen < 0:
raise ValueError(
'current prefixlen is %d, cannot have a prefixlen_diff of %d' %
(self.prefixlen, prefixlen_diff))
return self.__class__((
int(self.network_address) & (int(self.netmask) << prefixlen_diff),
new_prefixlen
))
@property
def is_multicast(self):
"""Test if the address is reserved for multicast use.
Returns:
A boolean, True if the address is a multicast address.
See RFC 2373 2.7 for details.
"""
return (self.network_address.is_multicast and
self.broadcast_address.is_multicast)
def subnet_of(self, other):
# always false if one is v4 and the other is v6.
if self._version != other._version:
return False
# dealing with another network.
if (hasattr(other, 'network_address') and
hasattr(other, 'broadcast_address')):
return (other.network_address <= self.network_address and
other.broadcast_address >= self.broadcast_address)
# dealing with another address
else:
raise TypeError('Unable to test subnet containment with element '
'of type %s' % type(other))
def supernet_of(self, other):
# always false if one is v4 and the other is v6.
if self._version != other._version:
return False
# dealing with another network.
if (hasattr(other, 'network_address') and
hasattr(other, 'broadcast_address')):
return (other.network_address >= self.network_address and
other.broadcast_address <= self.broadcast_address)
# dealing with another address
else:
raise TypeError('Unable to test subnet containment with element '
'of type %s' % type(other))
@property
def is_reserved(self):
"""Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within one of the
reserved IPv6 Network ranges.
"""
return (self.network_address.is_reserved and
self.broadcast_address.is_reserved)
@property
def is_link_local(self):
"""Test if the address is reserved for link-local.
Returns:
A boolean, True if the address is reserved per RFC 4291.
"""
return (self.network_address.is_link_local and
self.broadcast_address.is_link_local)
@property
def is_private(self):
"""Test if this address is allocated for private networks.
Returns:
A boolean, True if the address is reserved per
iana-ipv4-special-registry or iana-ipv6-special-registry.
"""
return (self.network_address.is_private and
self.broadcast_address.is_private)
@property
def is_global(self):
"""Test if this address is allocated for public networks.
Returns:
A boolean, True if the address is not reserved per
iana-ipv4-special-registry or iana-ipv6-special-registry.
"""
return not self.is_private
@property
def is_unspecified(self):
"""Test if the address is unspecified.
Returns:
A boolean, True if this is the unspecified address as defined in
RFC 2373 2.5.2.
"""
return (self.network_address.is_unspecified and
self.broadcast_address.is_unspecified)
@property
def is_loopback(self):
"""Test if the address is a loopback address.
Returns:
A boolean, True if the address is a loopback address as defined in
RFC 2373 2.5.3.
"""
return (self.network_address.is_loopback and
self.broadcast_address.is_loopback)
class _BaseV4(object):
"""Base IPv4 object.
The following methods are used by IPv4 objects in both single IP
addresses and networks.
"""
__slots__ = ()
_version = 4
# Equivalent to 255.255.255.255 or 32 bits of 1's.
_ALL_ONES = (2 ** IPV4LENGTH) - 1
_DECIMAL_DIGITS = frozenset('0123456789')
# the valid octets for host and netmasks. only useful for IPv4.
_valid_mask_octets = frozenset([255, 254, 252, 248, 240, 224, 192, 128, 0])
_max_prefixlen = IPV4LENGTH
# There are only a handful of valid v4 netmasks, so we cache them all
# when constructed (see _make_netmask()).
_netmask_cache = {}
def _explode_shorthand_ip_string(self):
return _compat_str(self)
@classmethod
def _make_netmask(cls, arg):
"""Make a (netmask, prefix_len) tuple from the given argument.
Argument can be:
- an integer (the prefix length)
- a string representing the prefix length (e.g. "24")
- a string representing the prefix netmask (e.g. "255.255.255.0")
"""
if arg not in cls._netmask_cache:
if isinstance(arg, _compat_int_types):
prefixlen = arg
else:
try:
# Check for a netmask in prefix length form
prefixlen = cls._prefix_from_prefix_string(arg)
except NetmaskValueError:
# Check for a netmask or hostmask in dotted-quad form.
# This may raise NetmaskValueError.
prefixlen = cls._prefix_from_ip_string(arg)
netmask = IPv4Address(cls._ip_int_from_prefix(prefixlen))
cls._netmask_cache[arg] = netmask, prefixlen
return cls._netmask_cache[arg]
@classmethod
def _ip_int_from_string(cls, ip_str):
"""Turn the given IP string into an integer for comparison.
Args:
ip_str: A string, the IP ip_str.
Returns:
The IP ip_str as an integer.
Raises:
AddressValueError: if ip_str isn't a valid IPv4 Address.
"""
if not ip_str:
raise AddressValueError('Address cannot be empty')
octets = ip_str.split('.')
if len(octets) != 4:
raise AddressValueError("Expected 4 octets in %r" % ip_str)
try:
return _compat_int_from_byte_vals(
map(cls._parse_octet, octets), 'big')
except ValueError as exc:
raise AddressValueError("%s in %r" % (exc, ip_str))
@classmethod
def _parse_octet(cls, octet_str):
"""Convert a decimal octet into an integer.
Args:
octet_str: A string, the number to parse.
Returns:
The octet as an integer.
Raises:
ValueError: if the octet isn't strictly a decimal from [0..255].
"""
if not octet_str:
raise ValueError("Empty octet not permitted")
# Whitelist the characters, since int() allows a lot of bizarre stuff.
if not cls._DECIMAL_DIGITS.issuperset(octet_str):
msg = "Only decimal digits permitted in %r"
raise ValueError(msg % octet_str)
# We do the length check second, since the invalid character error
# is likely to be more informative for the user
if len(octet_str) > 3:
msg = "At most 3 characters permitted in %r"
raise ValueError(msg % octet_str)
# Convert to integer (we know digits are legal)
octet_int = int(octet_str, 10)
# Any octets that look like they *might* be written in octal,
# and which don't look exactly the same in both octal and
# decimal are rejected as ambiguous
if octet_int > 7 and octet_str[0] == '0':
msg = "Ambiguous (octal/decimal) value in %r not permitted"
raise ValueError(msg % octet_str)
if octet_int > 255:
raise ValueError("Octet %d (> 255) not permitted" % octet_int)
return octet_int
@classmethod
def _string_from_ip_int(cls, ip_int):
"""Turns a 32-bit integer into dotted decimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
The IP address as a string in dotted decimal notation.
"""
return '.'.join(_compat_str(struct.unpack(b'!B', b)[0]
if isinstance(b, bytes)
else b)
for b in _compat_to_bytes(ip_int, 4, 'big'))
def _is_hostmask(self, ip_str):
"""Test if the IP string is a hostmask (rather than a netmask).
Args:
ip_str: A string, the potential hostmask.
Returns:
A boolean, True if the IP string is a hostmask.
"""
bits = ip_str.split('.')
try:
parts = [x for x in map(int, bits) if x in self._valid_mask_octets]
except ValueError:
return False
if len(parts) != len(bits):
return False
if parts[0] < parts[-1]:
return True
return False
def _reverse_pointer(self):
"""Return the reverse DNS pointer name for the IPv4 address.
This implements the method described in RFC1035 3.5.
"""
reverse_octets = _compat_str(self).split('.')[::-1]
return '.'.join(reverse_octets) + '.in-addr.arpa'
@property
def max_prefixlen(self):
return self._max_prefixlen
@property
def version(self):
return self._version
class IPv4Address(_BaseV4, _BaseAddress):
"""Represent and manipulate single IPv4 Addresses."""
__slots__ = ('_ip', '__weakref__')
def __init__(self, address):
"""
Args:
address: A string or integer representing the IP
Additionally, an integer can be passed, so
IPv4Address('192.0.2.1') == IPv4Address(3221225985).
or, more generally
IPv4Address(int(IPv4Address('192.0.2.1'))) ==
IPv4Address('192.0.2.1')
Raises:
AddressValueError: If ipaddress isn't a valid IPv4 address.
"""
# Efficient constructor from integer.
if isinstance(address, _compat_int_types):
self._check_int_address(address)
self._ip = address
return
# Constructing from a packed address
if isinstance(address, bytes):
self._check_packed_address(address, 4)
bvs = _compat_bytes_to_byte_vals(address)
self._ip = _compat_int_from_byte_vals(bvs, 'big')
return
# Assume input argument to be string or any object representation
# which converts into a formatted IP string.
addr_str = _compat_str(address)
if '/' in addr_str:
raise AddressValueError("Unexpected '/' in %r" % address)
self._ip = self._ip_int_from_string(addr_str)
@property
def packed(self):
"""The binary representation of this address."""
return v4_int_to_packed(self._ip)
@property
def is_reserved(self):
"""Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within the
reserved IPv4 Network range.
"""
return self in self._constants._reserved_network
@property
def is_private(self):
"""Test if this address is allocated for private networks.
Returns:
A boolean, True if the address is reserved per
iana-ipv4-special-registry.
"""
return any(self in net for net in self._constants._private_networks)
@property
def is_global(self):
return (
self not in self._constants._public_network and
not self.is_private)
@property
def is_multicast(self):
"""Test if the address is reserved for multicast use.
Returns:
A boolean, True if the address is multicast.
See RFC 3171 for details.
"""
return self in self._constants._multicast_network
@property
def is_unspecified(self):
"""Test if the address is unspecified.
Returns:
A boolean, True if this is the unspecified address as defined in
RFC 5735 3.
"""
return self == self._constants._unspecified_address
@property
def is_loopback(self):
"""Test if the address is a loopback address.
Returns:
A boolean, True if the address is a loopback per RFC 3330.
"""
return self in self._constants._loopback_network
@property
def is_link_local(self):
"""Test if the address is reserved for link-local.
Returns:
A boolean, True if the address is link-local per RFC 3927.
"""
return self in self._constants._linklocal_network
class IPv4Interface(IPv4Address):
def __init__(self, address):
if isinstance(address, (bytes, _compat_int_types)):
IPv4Address.__init__(self, address)
self.network = IPv4Network(self._ip)
self._prefixlen = self._max_prefixlen
return
if isinstance(address, tuple):
IPv4Address.__init__(self, address[0])
if len(address) > 1:
self._prefixlen = int(address[1])
else:
self._prefixlen = self._max_prefixlen
self.network = IPv4Network(address, strict=False)
self.netmask = self.network.netmask
self.hostmask = self.network.hostmask
return
addr = _split_optional_netmask(address)
IPv4Address.__init__(self, addr[0])
self.network = IPv4Network(address, strict=False)
self._prefixlen = self.network._prefixlen
self.netmask = self.network.netmask
self.hostmask = self.network.hostmask
def __str__(self):
return '%s/%d' % (self._string_from_ip_int(self._ip),
self.network.prefixlen)
def __eq__(self, other):
address_equal = IPv4Address.__eq__(self, other)
if not address_equal or address_equal is NotImplemented:
return address_equal
try:
return self.network == other.network
except AttributeError:
# An interface with an associated network is NOT the
# same as an unassociated address. That's why the hash
# takes the extra info into account.
return False
def __lt__(self, other):
address_less = IPv4Address.__lt__(self, other)
if address_less is NotImplemented:
return NotImplemented
try:
return self.network < other.network
except AttributeError:
# We *do* allow addresses and interfaces to be sorted. The
# unassociated address is considered less than all interfaces.
return False
def __hash__(self):
return self._ip ^ self._prefixlen ^ int(self.network.network_address)
__reduce__ = _IPAddressBase.__reduce__
@property
def ip(self):
return IPv4Address(self._ip)
@property
def with_prefixlen(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
self._prefixlen)
@property
def with_netmask(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
self.netmask)
@property
def with_hostmask(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
self.hostmask)
class IPv4Network(_BaseV4, _BaseNetwork):
"""This class represents and manipulates 32-bit IPv4 network + addresses..
Attributes: [examples for IPv4Network('192.0.2.0/27')]
.network_address: IPv4Address('192.0.2.0')
.hostmask: IPv4Address('0.0.0.31')
.broadcast_address: IPv4Address('192.0.2.32')
.netmask: IPv4Address('255.255.255.224')
.prefixlen: 27
"""
# Class to use when creating address objects
_address_class = IPv4Address
def __init__(self, address, strict=True):
"""Instantiate a new IPv4 network object.
Args:
address: A string or integer representing the IP [& network].
'192.0.2.0/24'
'192.0.2.0/255.255.255.0'
'192.0.0.2/0.0.0.255'
are all functionally the same in IPv4. Similarly,
'192.0.2.1'
'192.0.2.1/255.255.255.255'
'192.0.2.1/32'
are also functionally equivalent. That is to say, failing to
provide a subnetmask will create an object with a mask of /32.
If the mask (portion after the / in the argument) is given in
dotted quad form, it is treated as a netmask if it starts with a
non-zero field (e.g. /255.0.0.0 == /8) and as a hostmask if it
starts with a zero field (e.g. 0.255.255.255 == /8), with the
single exception of an all-zero mask which is treated as a
netmask == /0. If no mask is given, a default of /32 is used.
Additionally, an integer can be passed, so
IPv4Network('192.0.2.1') == IPv4Network(3221225985)
or, more generally
IPv4Interface(int(IPv4Interface('192.0.2.1'))) ==
IPv4Interface('192.0.2.1')
Raises:
AddressValueError: If ipaddress isn't a valid IPv4 address.
NetmaskValueError: If the netmask isn't valid for
an IPv4 address.
ValueError: If strict is True and a network address is not
supplied.
"""
_BaseNetwork.__init__(self, address)
# Constructing from a packed address or integer
if isinstance(address, (_compat_int_types, bytes)):
self.network_address = IPv4Address(address)
self.netmask, self._prefixlen = self._make_netmask(
self._max_prefixlen)
# fixme: address/network test here.
return
if isinstance(address, tuple):
if len(address) > 1:
arg = address[1]
else:
# We weren't given an address[1]
arg = self._max_prefixlen
self.network_address = IPv4Address(address[0])
self.netmask, self._prefixlen = self._make_netmask(arg)
packed = int(self.network_address)
if packed & int(self.netmask) != packed:
if strict:
raise ValueError('%s has host bits set' % self)
else:
self.network_address = IPv4Address(packed &
int(self.netmask))
return
# Assume input argument to be string or any object representation
# which converts into a formatted IP prefix string.
addr = _split_optional_netmask(address)
self.network_address = IPv4Address(self._ip_int_from_string(addr[0]))
if len(addr) == 2:
arg = addr[1]
else:
arg = self._max_prefixlen
self.netmask, self._prefixlen = self._make_netmask(arg)
if strict:
if (IPv4Address(int(self.network_address) & int(self.netmask)) !=
self.network_address):
raise ValueError('%s has host bits set' % self)
self.network_address = IPv4Address(int(self.network_address) &
int(self.netmask))
if self._prefixlen == (self._max_prefixlen - 1):
self.hosts = self.__iter__
@property
def is_global(self):
"""Test if this address is allocated for public networks.
Returns:
A boolean, True if the address is not reserved per
iana-ipv4-special-registry.
"""
return (not (self.network_address in IPv4Network('100.64.0.0/10') and
self.broadcast_address in IPv4Network('100.64.0.0/10')) and
not self.is_private)
class _IPv4Constants(object):
_linklocal_network = IPv4Network('169.254.0.0/16')
_loopback_network = IPv4Network('127.0.0.0/8')
_multicast_network = IPv4Network('224.0.0.0/4')
_public_network = IPv4Network('100.64.0.0/10')
_private_networks = [
IPv4Network('0.0.0.0/8'),
IPv4Network('10.0.0.0/8'),
IPv4Network('127.0.0.0/8'),
IPv4Network('169.254.0.0/16'),
IPv4Network('172.16.0.0/12'),
IPv4Network('192.0.0.0/29'),
IPv4Network('192.0.0.170/31'),
IPv4Network('192.0.2.0/24'),
IPv4Network('192.168.0.0/16'),
IPv4Network('198.18.0.0/15'),
IPv4Network('198.51.100.0/24'),
IPv4Network('203.0.113.0/24'),
IPv4Network('240.0.0.0/4'),
IPv4Network('255.255.255.255/32'),
]
_reserved_network = IPv4Network('240.0.0.0/4')
_unspecified_address = IPv4Address('0.0.0.0')
IPv4Address._constants = _IPv4Constants
class _BaseV6(object):
"""Base IPv6 object.
The following methods are used by IPv6 objects in both single IP
addresses and networks.
"""
__slots__ = ()
_version = 6
_ALL_ONES = (2 ** IPV6LENGTH) - 1
_HEXTET_COUNT = 8
_HEX_DIGITS = frozenset('0123456789ABCDEFabcdef')
_max_prefixlen = IPV6LENGTH
# There are only a bunch of valid v6 netmasks, so we cache them all
# when constructed (see _make_netmask()).
_netmask_cache = {}
@classmethod
def _make_netmask(cls, arg):
"""Make a (netmask, prefix_len) tuple from the given argument.
Argument can be:
- an integer (the prefix length)
- a string representing the prefix length (e.g. "24")
- a string representing the prefix netmask (e.g. "255.255.255.0")
"""
if arg not in cls._netmask_cache:
if isinstance(arg, _compat_int_types):
prefixlen = arg
else:
prefixlen = cls._prefix_from_prefix_string(arg)
netmask = IPv6Address(cls._ip_int_from_prefix(prefixlen))
cls._netmask_cache[arg] = netmask, prefixlen
return cls._netmask_cache[arg]
@classmethod
def _ip_int_from_string(cls, ip_str):
"""Turn an IPv6 ip_str into an integer.
Args:
ip_str: A string, the IPv6 ip_str.
Returns:
An int, the IPv6 address
Raises:
AddressValueError: if ip_str isn't a valid IPv6 Address.
"""
if not ip_str:
raise AddressValueError('Address cannot be empty')
parts = ip_str.split(':')
# An IPv6 address needs at least 2 colons (3 parts).
_min_parts = 3
if len(parts) < _min_parts:
msg = "At least %d parts expected in %r" % (_min_parts, ip_str)
raise AddressValueError(msg)
# If the address has an IPv4-style suffix, convert it to hexadecimal.
if '.' in parts[-1]:
try:
ipv4_int = IPv4Address(parts.pop())._ip
except AddressValueError as exc:
raise AddressValueError("%s in %r" % (exc, ip_str))
parts.append('%x' % ((ipv4_int >> 16) & 0xFFFF))
parts.append('%x' % (ipv4_int & 0xFFFF))
# An IPv6 address can't have more than 8 colons (9 parts).
# The extra colon comes from using the "::" notation for a single
# leading or trailing zero part.
_max_parts = cls._HEXTET_COUNT + 1
if len(parts) > _max_parts:
msg = "At most %d colons permitted in %r" % (
_max_parts - 1, ip_str)
raise AddressValueError(msg)
# Disregarding the endpoints, find '::' with nothing in between.
# This indicates that a run of zeroes has been skipped.
skip_index = None
for i in _compat_range(1, len(parts) - 1):
if not parts[i]:
if skip_index is not None:
# Can't have more than one '::'
msg = "At most one '::' permitted in %r" % ip_str
raise AddressValueError(msg)
skip_index = i
# parts_hi is the number of parts to copy from above/before the '::'
# parts_lo is the number of parts to copy from below/after the '::'
if skip_index is not None:
# If we found a '::', then check if it also covers the endpoints.
parts_hi = skip_index
parts_lo = len(parts) - skip_index - 1
if not parts[0]:
parts_hi -= 1
if parts_hi:
msg = "Leading ':' only permitted as part of '::' in %r"
raise AddressValueError(msg % ip_str) # ^: requires ^::
if not parts[-1]:
parts_lo -= 1
if parts_lo:
msg = "Trailing ':' only permitted as part of '::' in %r"
raise AddressValueError(msg % ip_str) # :$ requires ::$
parts_skipped = cls._HEXTET_COUNT - (parts_hi + parts_lo)
if parts_skipped < 1:
msg = "Expected at most %d other parts with '::' in %r"
raise AddressValueError(msg % (cls._HEXTET_COUNT - 1, ip_str))
else:
# Otherwise, allocate the entire address to parts_hi. The
# endpoints could still be empty, but _parse_hextet() will check
# for that.
if len(parts) != cls._HEXTET_COUNT:
msg = "Exactly %d parts expected without '::' in %r"
raise AddressValueError(msg % (cls._HEXTET_COUNT, ip_str))
if not parts[0]:
msg = "Leading ':' only permitted as part of '::' in %r"
raise AddressValueError(msg % ip_str) # ^: requires ^::
if not parts[-1]:
msg = "Trailing ':' only permitted as part of '::' in %r"
raise AddressValueError(msg % ip_str) # :$ requires ::$
parts_hi = len(parts)
parts_lo = 0
parts_skipped = 0
try:
# Now, parse the hextets into a 128-bit integer.
ip_int = 0
for i in range(parts_hi):
ip_int <<= 16
ip_int |= cls._parse_hextet(parts[i])
ip_int <<= 16 * parts_skipped
for i in range(-parts_lo, 0):
ip_int <<= 16
ip_int |= cls._parse_hextet(parts[i])
return ip_int
except ValueError as exc:
raise AddressValueError("%s in %r" % (exc, ip_str))
@classmethod
def _parse_hextet(cls, hextet_str):
"""Convert an IPv6 hextet string into an integer.
Args:
hextet_str: A string, the number to parse.
Returns:
The hextet as an integer.
Raises:
ValueError: if the input isn't strictly a hex number from
[0..FFFF].
"""
# Whitelist the characters, since int() allows a lot of bizarre stuff.
if not cls._HEX_DIGITS.issuperset(hextet_str):
raise ValueError("Only hex digits permitted in %r" % hextet_str)
# We do the length check second, since the invalid character error
# is likely to be more informative for the user
if len(hextet_str) > 4:
msg = "At most 4 characters permitted in %r"
raise ValueError(msg % hextet_str)
# Length check means we can skip checking the integer value
return int(hextet_str, 16)
@classmethod
def _compress_hextets(cls, hextets):
"""Compresses a list of hextets.
Compresses a list of strings, replacing the longest continuous
sequence of "0" in the list with "" and adding empty strings at
the beginning or at the end of the string such that subsequently
calling ":".join(hextets) will produce the compressed version of
the IPv6 address.
Args:
hextets: A list of strings, the hextets to compress.
Returns:
A list of strings.
"""
best_doublecolon_start = -1
best_doublecolon_len = 0
doublecolon_start = -1
doublecolon_len = 0
for index, hextet in enumerate(hextets):
if hextet == '0':
doublecolon_len += 1
if doublecolon_start == -1:
# Start of a sequence of zeros.
doublecolon_start = index
if doublecolon_len > best_doublecolon_len:
# This is the longest sequence of zeros so far.
best_doublecolon_len = doublecolon_len
best_doublecolon_start = doublecolon_start
else:
doublecolon_len = 0
doublecolon_start = -1
if best_doublecolon_len > 1:
best_doublecolon_end = (best_doublecolon_start +
best_doublecolon_len)
# For zeros at the end of the address.
if best_doublecolon_end == len(hextets):
hextets += ['']
hextets[best_doublecolon_start:best_doublecolon_end] = ['']
# For zeros at the beginning of the address.
if best_doublecolon_start == 0:
hextets = [''] + hextets
return hextets
@classmethod
def _string_from_ip_int(cls, ip_int=None):
"""Turns a 128-bit integer into hexadecimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
A string, the hexadecimal representation of the address.
Raises:
ValueError: The address is bigger than 128 bits of all ones.
"""
if ip_int is None:
ip_int = int(cls._ip)
if ip_int > cls._ALL_ONES:
raise ValueError('IPv6 address is too large')
hex_str = '%032x' % ip_int
hextets = ['%x' % int(hex_str[x:x + 4], 16) for x in range(0, 32, 4)]
hextets = cls._compress_hextets(hextets)
return ':'.join(hextets)
def _explode_shorthand_ip_string(self):
"""Expand a shortened IPv6 address.
Args:
ip_str: A string, the IPv6 address.
Returns:
A string, the expanded IPv6 address.
"""
if isinstance(self, IPv6Network):
ip_str = _compat_str(self.network_address)
elif isinstance(self, IPv6Interface):
ip_str = _compat_str(self.ip)
else:
ip_str = _compat_str(self)
ip_int = self._ip_int_from_string(ip_str)
hex_str = '%032x' % ip_int
parts = [hex_str[x:x + 4] for x in range(0, 32, 4)]
if isinstance(self, (_BaseNetwork, IPv6Interface)):
return '%s/%d' % (':'.join(parts), self._prefixlen)
return ':'.join(parts)
def _reverse_pointer(self):
"""Return the reverse DNS pointer name for the IPv6 address.
This implements the method described in RFC3596 2.5.
"""
reverse_chars = self.exploded[::-1].replace(':', '')
return '.'.join(reverse_chars) + '.ip6.arpa'
@property
def max_prefixlen(self):
return self._max_prefixlen
@property
def version(self):
return self._version
class IPv6Address(_BaseV6, _BaseAddress):
"""Represent and manipulate single IPv6 Addresses."""
__slots__ = ('_ip', '__weakref__')
def __init__(self, address):
"""Instantiate a new IPv6 address object.
Args:
address: A string or integer representing the IP
Additionally, an integer can be passed, so
IPv6Address('2001:db8::') ==
IPv6Address(42540766411282592856903984951653826560)
or, more generally
IPv6Address(int(IPv6Address('2001:db8::'))) ==
IPv6Address('2001:db8::')
Raises:
AddressValueError: If address isn't a valid IPv6 address.
"""
# Efficient constructor from integer.
if isinstance(address, _compat_int_types):
self._check_int_address(address)
self._ip = address
return
# Constructing from a packed address
if isinstance(address, bytes):
self._check_packed_address(address, 16)
bvs = _compat_bytes_to_byte_vals(address)
self._ip = _compat_int_from_byte_vals(bvs, 'big')
return
# Assume input argument to be string or any object representation
# which converts into a formatted IP string.
addr_str = _compat_str(address)
if '/' in addr_str:
raise AddressValueError("Unexpected '/' in %r" % address)
self._ip = self._ip_int_from_string(addr_str)
@property
def packed(self):
"""The binary representation of this address."""
return v6_int_to_packed(self._ip)
@property
def is_multicast(self):
"""Test if the address is reserved for multicast use.
Returns:
A boolean, True if the address is a multicast address.
See RFC 2373 2.7 for details.
"""
return self in self._constants._multicast_network
@property
def is_reserved(self):
"""Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within one of the
reserved IPv6 Network ranges.
"""
return any(self in x for x in self._constants._reserved_networks)
@property
def is_link_local(self):
"""Test if the address is reserved for link-local.
Returns:
A boolean, True if the address is reserved per RFC 4291.
"""
return self in self._constants._linklocal_network
@property
def is_site_local(self):
"""Test if the address is reserved for site-local.
Note that the site-local address space has been deprecated by RFC 3879.
Use is_private to test if this address is in the space of unique local
addresses as defined by RFC 4193.
Returns:
A boolean, True if the address is reserved per RFC 3513 2.5.6.
"""
return self in self._constants._sitelocal_network
@property
def is_private(self):
"""Test if this address is allocated for private networks.
Returns:
A boolean, True if the address is reserved per
iana-ipv6-special-registry.
"""
return any(self in net for net in self._constants._private_networks)
@property
def is_global(self):
"""Test if this address is allocated for public networks.
Returns:
A boolean, true if the address is not reserved per
iana-ipv6-special-registry.
"""
return not self.is_private
@property
def is_unspecified(self):
"""Test if the address is unspecified.
Returns:
A boolean, True if this is the unspecified address as defined in
RFC 2373 2.5.2.
"""
return self._ip == 0
@property
def is_loopback(self):
"""Test if the address is a loopback address.
Returns:
A boolean, True if the address is a loopback address as defined in
RFC 2373 2.5.3.
"""
return self._ip == 1
@property
def ipv4_mapped(self):
"""Return the IPv4 mapped address.
Returns:
If the IPv6 address is a v4 mapped address, return the
IPv4 mapped address. Return None otherwise.
"""
if (self._ip >> 32) != 0xFFFF:
return None
return IPv4Address(self._ip & 0xFFFFFFFF)
@property
def teredo(self):
"""Tuple of embedded teredo IPs.
Returns:
Tuple of the (server, client) IPs or None if the address
doesn't appear to be a teredo address (doesn't start with
2001::/32)
"""
if (self._ip >> 96) != 0x20010000:
return None
return (IPv4Address((self._ip >> 64) & 0xFFFFFFFF),
IPv4Address(~self._ip & 0xFFFFFFFF))
@property
def sixtofour(self):
"""Return the IPv4 6to4 embedded address.
Returns:
The IPv4 6to4-embedded address if present or None if the
address doesn't appear to contain a 6to4 embedded address.
"""
if (self._ip >> 112) != 0x2002:
return None
return IPv4Address((self._ip >> 80) & 0xFFFFFFFF)
class IPv6Interface(IPv6Address):
def __init__(self, address):
if isinstance(address, (bytes, _compat_int_types)):
IPv6Address.__init__(self, address)
self.network = IPv6Network(self._ip)
self._prefixlen = self._max_prefixlen
return
if isinstance(address, tuple):
IPv6Address.__init__(self, address[0])
if len(address) > 1:
self._prefixlen = int(address[1])
else:
self._prefixlen = self._max_prefixlen
self.network = IPv6Network(address, strict=False)
self.netmask = self.network.netmask
self.hostmask = self.network.hostmask
return
addr = _split_optional_netmask(address)
IPv6Address.__init__(self, addr[0])
self.network = IPv6Network(address, strict=False)
self.netmask = self.network.netmask
self._prefixlen = self.network._prefixlen
self.hostmask = self.network.hostmask
def __str__(self):
return '%s/%d' % (self._string_from_ip_int(self._ip),
self.network.prefixlen)
def __eq__(self, other):
address_equal = IPv6Address.__eq__(self, other)
if not address_equal or address_equal is NotImplemented:
return address_equal
try:
return self.network == other.network
except AttributeError:
# An interface with an associated network is NOT the
# same as an unassociated address. That's why the hash
# takes the extra info into account.
return False
def __lt__(self, other):
address_less = IPv6Address.__lt__(self, other)
if address_less is NotImplemented:
return NotImplemented
try:
return self.network < other.network
except AttributeError:
# We *do* allow addresses and interfaces to be sorted. The
# unassociated address is considered less than all interfaces.
return False
def __hash__(self):
return self._ip ^ self._prefixlen ^ int(self.network.network_address)
__reduce__ = _IPAddressBase.__reduce__
@property
def ip(self):
return IPv6Address(self._ip)
@property
def with_prefixlen(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
self._prefixlen)
@property
def with_netmask(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
self.netmask)
@property
def with_hostmask(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
self.hostmask)
@property
def is_unspecified(self):
return self._ip == 0 and self.network.is_unspecified
@property
def is_loopback(self):
return self._ip == 1 and self.network.is_loopback
class IPv6Network(_BaseV6, _BaseNetwork):
"""This class represents and manipulates 128-bit IPv6 networks.
Attributes: [examples for IPv6('2001:db8::1000/124')]
.network_address: IPv6Address('2001:db8::1000')
.hostmask: IPv6Address('::f')
.broadcast_address: IPv6Address('2001:db8::100f')
.netmask: IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0')
.prefixlen: 124
"""
# Class to use when creating address objects
_address_class = IPv6Address
def __init__(self, address, strict=True):
"""Instantiate a new IPv6 Network object.
Args:
address: A string or integer representing the IPv6 network or the
IP and prefix/netmask.
'2001:db8::/128'
'2001:db8:0000:0000:0000:0000:0000:0000/128'
'2001:db8::'
are all functionally the same in IPv6. That is to say,
failing to provide a subnetmask will create an object with
a mask of /128.
Additionally, an integer can be passed, so
IPv6Network('2001:db8::') ==
IPv6Network(42540766411282592856903984951653826560)
or, more generally
IPv6Network(int(IPv6Network('2001:db8::'))) ==
IPv6Network('2001:db8::')
strict: A boolean. If true, ensure that we have been passed
A true network address, eg, 2001:db8::1000/124 and not an
IP address on a network, eg, 2001:db8::1/124.
Raises:
AddressValueError: If address isn't a valid IPv6 address.
NetmaskValueError: If the netmask isn't valid for
an IPv6 address.
ValueError: If strict was True and a network address was not
supplied.
"""
_BaseNetwork.__init__(self, address)
# Efficient constructor from integer or packed address
if isinstance(address, (bytes, _compat_int_types)):
self.network_address = IPv6Address(address)
self.netmask, self._prefixlen = self._make_netmask(
self._max_prefixlen)
return
if isinstance(address, tuple):
if len(address) > 1:
arg = address[1]
else:
arg = self._max_prefixlen
self.netmask, self._prefixlen = self._make_netmask(arg)
self.network_address = IPv6Address(address[0])
packed = int(self.network_address)
if packed & int(self.netmask) != packed:
if strict:
raise ValueError('%s has host bits set' % self)
else:
self.network_address = IPv6Address(packed &
int(self.netmask))
return
# Assume input argument to be string or any object representation
# which converts into a formatted IP prefix string.
addr = _split_optional_netmask(address)
self.network_address = IPv6Address(self._ip_int_from_string(addr[0]))
if len(addr) == 2:
arg = addr[1]
else:
arg = self._max_prefixlen
self.netmask, self._prefixlen = self._make_netmask(arg)
if strict:
if (IPv6Address(int(self.network_address) & int(self.netmask)) !=
self.network_address):
raise ValueError('%s has host bits set' % self)
self.network_address = IPv6Address(int(self.network_address) &
int(self.netmask))
if self._prefixlen == (self._max_prefixlen - 1):
self.hosts = self.__iter__
def hosts(self):
"""Generate Iterator over usable hosts in a network.
This is like __iter__ except it doesn't return the
Subnet-Router anycast address.
"""
network = int(self.network_address)
broadcast = int(self.broadcast_address)
for x in _compat_range(network + 1, broadcast + 1):
yield self._address_class(x)
@property
def is_site_local(self):
"""Test if the address is reserved for site-local.
Note that the site-local address space has been deprecated by RFC 3879.
Use is_private to test if this address is in the space of unique local
addresses as defined by RFC 4193.
Returns:
A boolean, True if the address is reserved per RFC 3513 2.5.6.
"""
return (self.network_address.is_site_local and
self.broadcast_address.is_site_local)
class _IPv6Constants(object):
_linklocal_network = IPv6Network('fe80::/10')
_multicast_network = IPv6Network('ff00::/8')
_private_networks = [
IPv6Network('::1/128'),
IPv6Network('::/128'),
IPv6Network('::ffff:0:0/96'),
IPv6Network('100::/64'),
IPv6Network('2001::/23'),
IPv6Network('2001:2::/48'),
IPv6Network('2001:db8::/32'),
IPv6Network('2001:10::/28'),
IPv6Network('fc00::/7'),
IPv6Network('fe80::/10'),
]
_reserved_networks = [
IPv6Network('::/8'), IPv6Network('100::/8'),
IPv6Network('200::/7'), IPv6Network('400::/6'),
IPv6Network('800::/5'), IPv6Network('1000::/4'),
IPv6Network('4000::/3'), IPv6Network('6000::/3'),
IPv6Network('8000::/3'), IPv6Network('A000::/3'),
IPv6Network('C000::/3'), IPv6Network('E000::/4'),
IPv6Network('F000::/5'), IPv6Network('F800::/6'),
IPv6Network('FE00::/9'),
]
_sitelocal_network = IPv6Network('fec0::/10')
IPv6Address._constants = _IPv6Constants
|
mit
|
[
3,
1898,
10219,
4475,
3277,
14,
199,
3,
221,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
33,
7377,
12,
10540,
3463,
6509,
20,
15,
12179,
22,
26212,
3555,
315,
2018,
14,
199,
199,
2765,
3555,
365,
1202,
370,
1218,
15,
31696,
15,
29798,
5434,
6509,
20,
436,
6509,
22,
7149,
199,
460,
11759,
14,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
421,
199,
646,
7975,
199,
646,
2702,
199,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
14,
1196,
7,
199,
199,
3,
3599,
5880,
3423,
199,
63,
5819,
63,
442,
63,
1313,
275,
334,
442,
4258,
199,
893,
26,
272,
485,
5819,
63,
442,
63,
1313,
275,
334,
442,
12,
1846,
9,
199,
2590,
12746,
26,
272,
986,
199,
893,
26,
272,
485,
5819,
63,
495,
275,
2649,
199,
2590,
12746,
26,
272,
485,
5819,
63,
495,
275,
620,
272,
702,
2783,
1137,
620,
199,
692,
330,
1154,
16,
3894,
16,
61,
508,
378,
26,
221,
327,
2018,
650,
19002,
272,
347,
485,
5819,
63,
2394,
63,
475,
63,
4414,
63,
3643,
8,
991,
84,
304,
267,
372,
701,
84,
199,
2836,
26,
272,
347,
485,
5819,
63,
2394,
63,
475,
63,
4414,
63,
3643,
8,
991,
84,
304,
267,
372,
359,
1820,
14,
5301,
8,
66,
7,
1,
34,
297,
330,
2788,
16,
61,
367,
330,
315,
701,
84,
61,
199,
893,
26,
272,
485,
5819,
63,
442,
63,
504,
63,
4414,
63,
3643,
275,
1109,
14,
504,
63,
2394,
199,
2590,
4281,
26,
272,
347,
485,
5819,
63,
442,
63,
504,
63,
4414,
63,
3643,
8,
991,
84,
3643,
12,
655,
328,
5865,
385,
304,
267,
702,
655,
328,
5865,
385,
508,
283,
5076,
7,
267,
522,
275,
378,
267,
367,
25794,
315,
701,
84,
3643,
26,
288,
702,
1228,
8,
23064,
12,
485,
5819,
63,
442,
63,
1313,
9,
288,
522,
275,
334,
470,
5213,
1695,
9,
435,
25794,
267,
372,
522,
421,
199,
318,
485,
5819,
63,
475,
63,
2394,
8,
442,
637,
12,
2582,
12,
655,
328,
5865,
385,
304,
272,
702,
1228,
8,
442,
637,
12,
485,
5819,
63,
442,
63,
1313,
9,
272,
702,
655,
328,
5865,
385,
508,
283,
5076,
7,
272,
340,
2582,
508,
841,
26,
267,
340,
26111,
665,
378,
503,
26111,
2356,
499,
1011,
4337,
26,
288,
746,
2702,
14,
705,
480,
4115,
734,
402,
1425,
367,
283,
41,
7,
1475,
1233,
531,
267,
372,
2702,
14,
1389,
8,
66,
7,
1,
41,
297,
26111,
9,
272,
916,
2582,
508,
3193,
26,
267,
340,
26111,
665,
378,
503,
26111,
2356,
499,
1011,
7960,
26,
288,
746,
2702,
14,
705,
480,
4115,
734,
402,
1425,
367,
283,
12917,
7,
1475,
1233,
531,
267,
372,
2702,
14,
1389,
8,
66,
7,
1,
12917,
297,
26111,
4331,
5049,
12,
26111,
1253,
378,
3581,
15798,
12596,
9,
272,
587,
26,
267,
746,
4279,
342,
199,
692,
2688,
8,
442,
12,
283,
2075,
63,
1267,
735,
272,
327,
2832,
1109,
14,
2075,
63,
1267,
2360,
3967,
626,
7859,
1133,
1736,
315,
499,
14,
23,
2382,
1846,
3495,
272,
347,
485,
5819,
63,
2075,
63,
1267,
8,
73,
304,
267,
372,
284,
14,
2075,
63,
1267,
342,
199,
2836,
26,
272,
347,
485,
5819,
63,
2075,
63,
1267,
8,
73,
304,
267,
367,
522,
315,
7975,
14,
835,
837,
288,
340,
284,
4331,
522,
508,
378,
26,
355,
372,
522,
421,
199,
318,
485,
5819,
63,
1842,
8,
928,
12,
1284,
12,
3650,
29,
17,
304,
272,
702,
3650,
690,
378,
272,
284,
275,
1343,
272,
1830,
284,
665,
1284,
26,
267,
1995,
284,
267,
284,
847,
3650,
421,
199,
533,
485,
7316,
4738,
316,
4256,
8,
785,
304,
272,
636,
7257,
363,
275,
6248,
339,
327,
11642,
626,
5405,
2310,
314,
1163,
9132,
5331,
687,
272,
327,
636,
4116,
363,
436,
636,
4077,
363,
272,
327,
2136,
5126,
9143,
14,
2923,
63,
7128,
2952,
652,
3181,
1133,
2429,
272,
327,
3784,
6657,
5966,
334,
1014,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
1960,
2260,
9,
272,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
746,
4279,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
4472,
275,
291,
855,
4077,
721,
1848,
9,
267,
340,
4472,
365,
3784,
26,
288,
372,
3784,
267,
372,
440,
4472,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
746,
4279,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
6656,
275,
291,
855,
4116,
721,
1848,
9,
267,
340,
6656,
365,
3784,
503,
440,
6656,
26,
288,
372,
291,
855,
4077,
721,
1848,
9,
267,
372,
6656,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
6656,
275,
291,
855,
4116,
721,
1848,
9,
267,
340,
6656,
365,
3784,
26,
288,
372,
3784,
267,
4472,
275,
291,
855,
4077,
721,
1848,
9,
267,
340,
4472,
365,
3784,
26,
288,
372,
3784,
267,
372,
440,
334,
2003,
503,
4472,
9,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
6656,
275,
291,
855,
4116,
721,
1848,
9,
267,
340,
6656,
365,
3784,
26,
288,
372,
3784,
267,
372,
440,
6656,
421,
199,
11253,
20,
9127,
275,
4337,
199,
11253,
22,
9127,
275,
7960,
421,
199,
533,
9906,
3393,
8,
3393,
304,
272,
408,
33,
1594,
4520,
4048,
370,
314,
2287,
1041,
421,
199,
533,
5365,
2629,
3393,
8,
3393,
304,
272,
408,
33,
1594,
4520,
4048,
370,
314,
20225,
1041,
421,
199,
318,
3384,
63,
1562,
8,
1562,
304,
272,
408,
27200,
376,
3531,
1059,
15,
442,
436,
372,
376,
909,
402,
314,
3211,
730,
14,
339,
3033,
26,
267,
2287,
26,
437,
1059,
503,
3000,
12,
314,
3531,
2287,
14,
221,
13083,
6509,
20,
503,
881,
6509,
22,
7149,
1443,
506,
6841,
27,
9446,
6656,
2419,
499,
538,
708,
911,
881,
506,
8652,
370,
506,
6509,
20,
701,
849,
14,
339,
1803,
26,
267,
1626,
6509,
20,
1476,
503,
6509,
22,
1476,
909,
14,
339,
6218,
26,
267,
1722,
26,
340,
314,
627,
1562,
10,
3032,
5712,
1133,
1902,
282,
373,
20,
503,
282,
373,
22,
881,
2287,
339,
408,
272,
862,
26,
267,
372,
6509,
20,
1476,
8,
1562,
9,
272
] |
[
1898,
10219,
4475,
3277,
14,
199,
3,
221,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
33,
7377,
12,
10540,
3463,
6509,
20,
15,
12179,
22,
26212,
3555,
315,
2018,
14,
199,
199,
2765,
3555,
365,
1202,
370,
1218,
15,
31696,
15,
29798,
5434,
6509,
20,
436,
6509,
22,
7149,
199,
460,
11759,
14,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
421,
199,
646,
7975,
199,
646,
2702,
199,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
14,
1196,
7,
199,
199,
3,
3599,
5880,
3423,
199,
63,
5819,
63,
442,
63,
1313,
275,
334,
442,
4258,
199,
893,
26,
272,
485,
5819,
63,
442,
63,
1313,
275,
334,
442,
12,
1846,
9,
199,
2590,
12746,
26,
272,
986,
199,
893,
26,
272,
485,
5819,
63,
495,
275,
2649,
199,
2590,
12746,
26,
272,
485,
5819,
63,
495,
275,
620,
272,
702,
2783,
1137,
620,
199,
692,
330,
1154,
16,
3894,
16,
61,
508,
378,
26,
221,
327,
2018,
650,
19002,
272,
347,
485,
5819,
63,
2394,
63,
475,
63,
4414,
63,
3643,
8,
991,
84,
304,
267,
372,
701,
84,
199,
2836,
26,
272,
347,
485,
5819,
63,
2394,
63,
475,
63,
4414,
63,
3643,
8,
991,
84,
304,
267,
372,
359,
1820,
14,
5301,
8,
66,
7,
1,
34,
297,
330,
2788,
16,
61,
367,
330,
315,
701,
84,
61,
199,
893,
26,
272,
485,
5819,
63,
442,
63,
504,
63,
4414,
63,
3643,
275,
1109,
14,
504,
63,
2394,
199,
2590,
4281,
26,
272,
347,
485,
5819,
63,
442,
63,
504,
63,
4414,
63,
3643,
8,
991,
84,
3643,
12,
655,
328,
5865,
385,
304,
267,
702,
655,
328,
5865,
385,
508,
283,
5076,
7,
267,
522,
275,
378,
267,
367,
25794,
315,
701,
84,
3643,
26,
288,
702,
1228,
8,
23064,
12,
485,
5819,
63,
442,
63,
1313,
9,
288,
522,
275,
334,
470,
5213,
1695,
9,
435,
25794,
267,
372,
522,
421,
199,
318,
485,
5819,
63,
475,
63,
2394,
8,
442,
637,
12,
2582,
12,
655,
328,
5865,
385,
304,
272,
702,
1228,
8,
442,
637,
12,
485,
5819,
63,
442,
63,
1313,
9,
272,
702,
655,
328,
5865,
385,
508,
283,
5076,
7,
272,
340,
2582,
508,
841,
26,
267,
340,
26111,
665,
378,
503,
26111,
2356,
499,
1011,
4337,
26,
288,
746,
2702,
14,
705,
480,
4115,
734,
402,
1425,
367,
283,
41,
7,
1475,
1233,
531,
267,
372,
2702,
14,
1389,
8,
66,
7,
1,
41,
297,
26111,
9,
272,
916,
2582,
508,
3193,
26,
267,
340,
26111,
665,
378,
503,
26111,
2356,
499,
1011,
7960,
26,
288,
746,
2702,
14,
705,
480,
4115,
734,
402,
1425,
367,
283,
12917,
7,
1475,
1233,
531,
267,
372,
2702,
14,
1389,
8,
66,
7,
1,
12917,
297,
26111,
4331,
5049,
12,
26111,
1253,
378,
3581,
15798,
12596,
9,
272,
587,
26,
267,
746,
4279,
342,
199,
692,
2688,
8,
442,
12,
283,
2075,
63,
1267,
735,
272,
327,
2832,
1109,
14,
2075,
63,
1267,
2360,
3967,
626,
7859,
1133,
1736,
315,
499,
14,
23,
2382,
1846,
3495,
272,
347,
485,
5819,
63,
2075,
63,
1267,
8,
73,
304,
267,
372,
284,
14,
2075,
63,
1267,
342,
199,
2836,
26,
272,
347,
485,
5819,
63,
2075,
63,
1267,
8,
73,
304,
267,
367,
522,
315,
7975,
14,
835,
837,
288,
340,
284,
4331,
522,
508,
378,
26,
355,
372,
522,
421,
199,
318,
485,
5819,
63,
1842,
8,
928,
12,
1284,
12,
3650,
29,
17,
304,
272,
702,
3650,
690,
378,
272,
284,
275,
1343,
272,
1830,
284,
665,
1284,
26,
267,
1995,
284,
267,
284,
847,
3650,
421,
199,
533,
485,
7316,
4738,
316,
4256,
8,
785,
304,
272,
636,
7257,
363,
275,
6248,
339,
327,
11642,
626,
5405,
2310,
314,
1163,
9132,
5331,
687,
272,
327,
636,
4116,
363,
436,
636,
4077,
363,
272,
327,
2136,
5126,
9143,
14,
2923,
63,
7128,
2952,
652,
3181,
1133,
2429,
272,
327,
3784,
6657,
5966,
334,
1014,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
1960,
2260,
9,
272,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
746,
4279,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
4472,
275,
291,
855,
4077,
721,
1848,
9,
267,
340,
4472,
365,
3784,
26,
288,
372,
3784,
267,
372,
440,
4472,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
746,
4279,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
6656,
275,
291,
855,
4116,
721,
1848,
9,
267,
340,
6656,
365,
3784,
503,
440,
6656,
26,
288,
372,
291,
855,
4077,
721,
1848,
9,
267,
372,
6656,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
6656,
275,
291,
855,
4116,
721,
1848,
9,
267,
340,
6656,
365,
3784,
26,
288,
372,
3784,
267,
4472,
275,
291,
855,
4077,
721,
1848,
9,
267,
340,
4472,
365,
3784,
26,
288,
372,
3784,
267,
372,
440,
334,
2003,
503,
4472,
9,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
6656,
275,
291,
855,
4116,
721,
1848,
9,
267,
340,
6656,
365,
3784,
26,
288,
372,
3784,
267,
372,
440,
6656,
421,
199,
11253,
20,
9127,
275,
4337,
199,
11253,
22,
9127,
275,
7960,
421,
199,
533,
9906,
3393,
8,
3393,
304,
272,
408,
33,
1594,
4520,
4048,
370,
314,
2287,
1041,
421,
199,
533,
5365,
2629,
3393,
8,
3393,
304,
272,
408,
33,
1594,
4520,
4048,
370,
314,
20225,
1041,
421,
199,
318,
3384,
63,
1562,
8,
1562,
304,
272,
408,
27200,
376,
3531,
1059,
15,
442,
436,
372,
376,
909,
402,
314,
3211,
730,
14,
339,
3033,
26,
267,
2287,
26,
437,
1059,
503,
3000,
12,
314,
3531,
2287,
14,
221,
13083,
6509,
20,
503,
881,
6509,
22,
7149,
1443,
506,
6841,
27,
9446,
6656,
2419,
499,
538,
708,
911,
881,
506,
8652,
370,
506,
6509,
20,
701,
849,
14,
339,
1803,
26,
267,
1626,
6509,
20,
1476,
503,
6509,
22,
1476,
909,
14,
339,
6218,
26,
267,
1722,
26,
340,
314,
627,
1562,
10,
3032,
5712,
1133,
1902,
282,
373,
20,
503,
282,
373,
22,
881,
2287,
339,
408,
272,
862,
26,
267,
372,
6509,
20,
1476,
8,
1562,
9,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
wanghongjuan/crosswalk-test-suite
|
misc/sampleapp-android-tests/sampleapp/helloworld_pack.py
|
1
|
2182
|
#!/usr/bin/env python
#
# Copyright (c) 2015 Intel Corporation.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of works must retain the original copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the original copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Intel Corporation nor the names of its contributors
# may be used to endorse or promote products derived from this work without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors:
# Wang, Hongjuan<hongjuanx.wang@intel.com>
import unittest
import os
import sys
import commands
import comm
class TestSampleAppFunctions(unittest.TestCase):
def test_pack(self):
comm.setUp()
app_name = "Helloworld"
sample_src = "hello-world/"
app_root = comm.sample_src_pref + sample_src
cmd = "%s --crosswalk=%s --platforms=android --android=%s --targets=%s --enable-remote-debugging %s" % \
(comm.apptools,
comm.crosswalkzip,
comm.MODE,
comm.ARCH,
app_root)
comm.pack(cmd, app_name.lower(), self)
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
20619,
11098,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
627,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
199,
3,
257,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
257,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
627,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
257,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
199,
3,
257,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
3,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
3,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
260,
644,
621,
12,
869,
951,
74,
7856,
28,
72,
951,
74,
7856,
88,
14,
87,
621,
32,
22264,
14,
957,
30,
199,
199,
646,
2882,
199,
646,
747,
199,
646,
984,
199,
646,
3718,
199,
646,
1923,
421,
199,
533,
1379,
8176,
2640,
13967,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1389,
8,
277,
304,
267,
1923,
14,
5996,
342,
267,
1145,
63,
354,
275,
298,
6257,
7617,
2,
267,
2690,
63,
2164,
275,
298,
5006,
13,
7617,
6687,
267,
1145,
63,
1231,
275,
1923,
14,
3271,
63,
2164,
63,
13829,
435,
2690,
63,
2164,
267,
2088,
275,
2071,
83,
1553,
7925,
7757,
2458,
83,
1553,
19601,
29,
6238,
1553,
6238,
2458,
83,
1553,
4684,
2458,
83,
1553,
4296,
13,
3846,
13,
24913,
450,
83,
2,
450,
971,
288,
334,
1404,
14,
571,
2537,
12,
1467,
1923,
14,
7925,
7757,
3065,
12,
1467,
1923,
14,
6963,
12,
1467,
1923,
14,
7762,
12,
1467,
1145,
63,
1231,
9,
267,
1923,
14,
1389,
8,
1760,
12,
1145,
63,
354,
14,
2325,
1062,
291,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
20619,
11098,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
627,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
199,
3,
257,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
257,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
627,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
257,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
199,
3,
257,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
3,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
3,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
260,
644,
621,
12,
869,
951,
74,
7856,
28,
72,
951,
74,
7856,
88,
14,
87,
621,
32,
22264,
14,
957,
30,
199,
199,
646,
2882,
199,
646,
747,
199,
646,
984,
199,
646,
3718,
199,
646,
1923,
421,
199,
533,
1379,
8176,
2640,
13967,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1389,
8,
277,
304,
267,
1923,
14,
5996,
342,
267,
1145,
63,
354,
275,
298,
6257,
7617,
2,
267,
2690,
63,
2164,
275,
298,
5006,
13,
7617,
6687,
267,
1145,
63,
1231,
275,
1923,
14,
3271,
63,
2164,
63,
13829,
435,
2690,
63,
2164,
267,
2088,
275,
2071,
83,
1553,
7925,
7757,
2458,
83,
1553,
19601,
29,
6238,
1553,
6238,
2458,
83,
1553,
4684,
2458,
83,
1553,
4296,
13,
3846,
13,
24913,
450,
83,
2,
450,
971,
288,
334,
1404,
14,
571,
2537,
12,
1467,
1923,
14,
7925,
7757,
3065,
12,
1467,
1923,
14,
6963,
12,
1467,
1923,
14,
7762,
12,
1467,
1145,
63,
1231,
9,
267,
1923,
14,
1389,
8,
1760,
12,
1145,
63,
354,
14,
2325,
1062,
291,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
menegon/OWSLib
|
owslib/wms.py
|
5
|
24196
|
# -*- coding: iso-8859-15 -*-
# =============================================================================
# Copyright (c) 2004, 2006 Sean C. Gillies
# Copyright (c) 2005 Nuxeo SARL <http://nuxeo.com>
#
# Authors : Sean Gillies <sgillies@frii.com>
# Julien Anguenot <ja@nuxeo.com>
#
# Contact email: sgillies@frii.com
# =============================================================================
"""
API for Web Map Service (WMS) methods and metadata.
Currently supports only version 1.1.1 of the WMS protocol.
"""
from __future__ import (absolute_import, division, print_function)
import cgi
try: # Python 3
from urllib.parse import urlencode
except ImportError: # Python 2
from urllib import urlencode
import warnings
import six
from .etree import etree
from .util import openURL, testXMLValue, extract_xml_list, xmltag_split, OrderedDict
from .fgdc import Metadata
from .iso import MD_Metadata
class ServiceException(Exception):
"""WMS ServiceException
Attributes:
message -- short error message
xml -- full xml error message from server
"""
def __init__(self, message, xml):
self.message = message
self.xml = xml
def __str__(self):
return repr(self.message)
class CapabilitiesError(Exception):
pass
class WebMapService(object):
"""Abstraction for OGC Web Map Service (WMS).
Implements IWebMapService.
"""
def __getitem__(self,name):
''' check contents dictionary to allow dict like access to service layers'''
if name in self.__getattribute__('contents'):
return self.__getattribute__('contents')[name]
else:
raise KeyError("No content named %s" % name)
def __init__(self, url, version='1.1.1', xml=None, username=None, password=None, parse_remote_metadata=False, timeout=30):
"""Initialize."""
self.url = url
self.username = username
self.password = password
self.version = version
self.timeout = timeout
self._capabilities = None
# Authentication handled by Reader
reader = WMSCapabilitiesReader(self.version, url=self.url, un=self.username, pw=self.password)
if xml: # read from stored xml
self._capabilities = reader.readString(xml)
else: # read from server
self._capabilities = reader.read(self.url, timeout=self.timeout)
# avoid building capabilities metadata if the response is a ServiceExceptionReport
se = self._capabilities.find('ServiceException')
if se is not None:
err_message = str(se.text).strip()
raise ServiceException(err_message, xml)
# build metadata objects
self._buildMetadata(parse_remote_metadata)
def _getcapproperty(self):
if not self._capabilities:
reader = WMSCapabilitiesReader(
self.version, url=self.url, un=self.username, pw=self.password
)
self._capabilities = ServiceMetadata(reader.read(self.url))
return self._capabilities
def _buildMetadata(self, parse_remote_metadata=False):
''' set up capabilities metadata objects '''
#serviceIdentification metadata
serviceelem=self._capabilities.find('Service')
self.identification=ServiceIdentification(serviceelem, self.version)
#serviceProvider metadata
self.provider=ServiceProvider(serviceelem)
#serviceOperations metadata
self.operations=[]
for elem in self._capabilities.find('Capability/Request')[:]:
self.operations.append(OperationMetadata(elem))
#serviceContents metadata: our assumption is that services use a top-level
#layer as a metadata organizer, nothing more.
self.contents = OrderedDict()
caps = self._capabilities.find('Capability')
#recursively gather content metadata for all layer elements.
#To the WebMapService.contents store only metadata of named layers.
def gather_layers(parent_elem, parent_metadata):
for index, elem in enumerate(parent_elem.findall('Layer')):
cm = ContentMetadata(elem, parent=parent_metadata, index=index+1, parse_remote_metadata=parse_remote_metadata)
if cm.id:
if cm.id in self.contents:
warnings.warn('Content metadata for layer "%s" already exists. Using child layer' % cm.id)
self.contents[cm.id] = cm
gather_layers(elem, cm)
gather_layers(caps, None)
#exceptions
self.exceptions = [f.text for f \
in self._capabilities.findall('Capability/Exception/Format')]
def items(self):
'''supports dict-like items() access'''
items=[]
for item in self.contents:
items.append((item,self.contents[item]))
return items
def getcapabilities(self):
"""Request and return capabilities document from the WMS as a
file-like object.
NOTE: this is effectively redundant now"""
reader = WMSCapabilitiesReader(
self.version, url=self.url, un=self.username, pw=self.password
)
u = self._open(reader.capabilities_url(self.url))
# check for service exceptions, and return
if u.info()['Content-Type'] == 'application/vnd.ogc.se_xml':
se_xml = u.read()
se_tree = etree.fromstring(se_xml)
err_message = str(se_tree.find('ServiceException').text).strip()
raise ServiceException(err_message, se_xml)
return u
def getmap(self, layers=None, styles=None, srs=None, bbox=None,
format=None, size=None, time=None, transparent=False,
bgcolor='#FFFFFF',
exceptions='application/vnd.ogc.se_xml',
method='Get',
timeout=None,
**kwargs
):
"""Request and return an image from the WMS as a file-like object.
Parameters
----------
layers : list
List of content layer names.
styles : list
Optional list of named styles, must be the same length as the
layers list.
srs : string
A spatial reference system identifier.
bbox : tuple
(left, bottom, right, top) in srs units.
format : string
Output image format such as 'image/jpeg'.
size : tuple
(width, height) in pixels.
transparent : bool
Optional. Transparent background if True.
bgcolor : string
Optional. Image background color.
method : string
Optional. HTTP DCP method name: Get or Post.
**kwargs : extra arguments
anything else e.g. vendor specific parameters
Example
-------
>>> wms = WebMapService('http://giswebservices.massgis.state.ma.us/geoserver/wms', version='1.1.1')
>>> img = wms.getmap(layers=['massgis:GISDATA.SHORELINES_ARC'],\
styles=[''],\
srs='EPSG:4326',\
bbox=(-70.8, 42, -70, 42.8),\
size=(300, 300),\
format='image/jpeg',\
transparent=True)
>>> out = open('example.jpg', 'wb')
>>> bytes_written = out.write(img.read())
>>> out.close()
"""
try:
base_url = next((m.get('url') for m in self.getOperationByName('GetMap').methods if m.get('type').lower() == method.lower()))
except StopIteration:
base_url = self.url
request = {'version': self.version, 'request': 'GetMap'}
# check layers and styles
assert len(layers) > 0
request['layers'] = ','.join(layers)
if styles:
assert len(styles) == len(layers)
request['styles'] = ','.join(styles)
else:
request['styles'] = ''
# size
request['width'] = str(size[0])
request['height'] = str(size[1])
request['srs'] = str(srs)
request['bbox'] = ','.join([repr(x) for x in bbox])
request['format'] = str(format)
request['transparent'] = str(transparent).upper()
request['bgcolor'] = '0x' + bgcolor[1:7]
request['exceptions'] = str(exceptions)
if time is not None:
request['time'] = str(time)
if kwargs:
for kw in kwargs:
request[kw]=kwargs[kw]
data = urlencode(request)
u = openURL(base_url, data, method, username=self.username, password=self.password, timeout=timeout or self.timeout)
# check for service exceptions, and return
if u.info()['Content-Type'] == 'application/vnd.ogc.se_xml':
se_xml = u.read()
se_tree = etree.fromstring(se_xml)
err_message = six.text_type(se_tree.find('ServiceException').text).strip()
raise ServiceException(err_message, se_xml)
return u
def getServiceXML(self):
xml = None
if self._capabilities is not None:
xml = etree.tostring(self._capabilities)
return xml
def getfeatureinfo(self):
raise NotImplementedError
def getOperationByName(self, name):
"""Return a named content item."""
for item in self.operations:
if item.name == name:
return item
raise KeyError("No operation named %s" % name)
class ServiceIdentification(object):
''' Implements IServiceIdentificationMetadata '''
def __init__(self, infoset, version):
self._root=infoset
self.type = testXMLValue(self._root.find('Name'))
self.version = version
self.title = testXMLValue(self._root.find('Title'))
self.abstract = testXMLValue(self._root.find('Abstract'))
self.keywords = extract_xml_list(self._root.findall('KeywordList/Keyword'))
self.accessconstraints = testXMLValue(self._root.find('AccessConstraints'))
self.fees = testXMLValue(self._root.find('Fees'))
class ServiceProvider(object):
''' Implements IServiceProviderMetatdata '''
def __init__(self, infoset):
self._root=infoset
name=self._root.find('ContactInformation/ContactPersonPrimary/ContactOrganization')
if name is not None:
self.name=name.text
else:
self.name=None
self.url=self._root.find('OnlineResource').attrib.get('{http://www.w3.org/1999/xlink}href', '')
#contact metadata
contact = self._root.find('ContactInformation')
## sometimes there is a contact block that is empty, so make
## sure there are children to parse
if contact is not None and contact[:] != []:
self.contact = ContactMetadata(contact)
else:
self.contact = None
def getContentByName(self, name):
"""Return a named content item."""
for item in self.contents:
if item.name == name:
return item
raise KeyError("No content named %s" % name)
def getOperationByName(self, name):
"""Return a named content item."""
for item in self.operations:
if item.name == name:
return item
raise KeyError("No operation named %s" % name)
class ContentMetadata:
"""
Abstraction for WMS layer metadata.
Implements IContentMetadata.
"""
def __init__(self, elem, parent=None, index=0, parse_remote_metadata=False, timeout=30):
if elem.tag != 'Layer':
raise ValueError('%s should be a Layer' % (elem,))
self.parent = parent
if parent:
self.index = "%s.%d" % (parent.index, index)
else:
self.index = str(index)
self.id = self.name = testXMLValue(elem.find('Name'))
# layer attributes
self.queryable = int(elem.attrib.get('queryable', 0))
self.cascaded = int(elem.attrib.get('cascaded', 0))
self.opaque = int(elem.attrib.get('opaque', 0))
self.noSubsets = int(elem.attrib.get('noSubsets', 0))
self.fixedWidth = int(elem.attrib.get('fixedWidth', 0))
self.fixedHeight = int(elem.attrib.get('fixedHeight', 0))
# title is mandatory property
self.title = None
title = testXMLValue(elem.find('Title'))
if title is not None:
self.title = title.strip()
self.abstract = testXMLValue(elem.find('Abstract'))
# bboxes
b = elem.find('BoundingBox')
self.boundingBox = None
if b is not None:
try: #sometimes the SRS attribute is (wrongly) not provided
srs=b.attrib['SRS']
except KeyError:
srs=None
self.boundingBox = (
float(b.attrib['minx']),
float(b.attrib['miny']),
float(b.attrib['maxx']),
float(b.attrib['maxy']),
srs,
)
elif self.parent:
if hasattr(self.parent, 'boundingBox'):
self.boundingBox = self.parent.boundingBox
# ScaleHint
sh = elem.find('ScaleHint')
self.scaleHint = None
if sh is not None:
if 'min' in sh.attrib and 'max' in sh.attrib:
self.scaleHint = {'min': sh.attrib['min'], 'max': sh.attrib['max']}
attribution = elem.find('Attribution')
if attribution is not None:
self.attribution = dict()
title = attribution.find('Title')
url = attribution.find('OnlineResource')
logo = attribution.find('LogoURL')
if title is not None:
self.attribution['title'] = title.text
if url is not None:
self.attribution['url'] = url.attrib['{http://www.w3.org/1999/xlink}href']
if logo is not None:
self.attribution['logo_size'] = (int(logo.attrib['width']), int(logo.attrib['height']))
self.attribution['logo_url'] = logo.find('OnlineResource').attrib['{http://www.w3.org/1999/xlink}href']
b = elem.find('LatLonBoundingBox')
if b is not None:
self.boundingBoxWGS84 = (
float(b.attrib['minx']),
float(b.attrib['miny']),
float(b.attrib['maxx']),
float(b.attrib['maxy']),
)
elif self.parent:
self.boundingBoxWGS84 = self.parent.boundingBoxWGS84
else:
self.boundingBoxWGS84 = None
#SRS options
self.crsOptions = []
#Copy any parent SRS options (they are inheritable properties)
if self.parent:
self.crsOptions = list(self.parent.crsOptions)
#Look for SRS option attached to this layer
if elem.find('SRS') is not None:
## some servers found in the wild use a single SRS
## tag containing a whitespace separated list of SRIDs
## instead of several SRS tags. hence the inner loop
for srslist in [x.text for x in elem.findall('SRS')]:
if srslist:
for srs in srslist.split():
self.crsOptions.append(srs)
#Get rid of duplicate entries
self.crsOptions = list(set(self.crsOptions))
#Set self.crsOptions to None if the layer (and parents) had no SRS options
if len(self.crsOptions) == 0:
#raise ValueError('%s no SRS available!?' % (elem,))
#Comment by D Lowe.
#Do not raise ValueError as it is possible that a layer is purely a parent layer and does not have SRS specified. Instead set crsOptions to None
# Comment by Jachym:
# Do not set it to None, but to [], which will make the code
# work further. Fixed by anthonybaxter
self.crsOptions=[]
#Styles
self.styles = {}
#Copy any parent styles (they are inheritable properties)
if self.parent:
self.styles = self.parent.styles.copy()
#Get the styles for this layer (items with the same name are replaced)
for s in elem.findall('Style'):
name = s.find('Name')
title = s.find('Title')
if name is None or title is None:
raise ValueError('%s missing name or title' % (s,))
style = { 'title' : title.text }
# legend url
legend = s.find('LegendURL/OnlineResource')
if legend is not None:
style['legend'] = legend.attrib['{http://www.w3.org/1999/xlink}href']
self.styles[name.text] = style
# keywords
self.keywords = [f.text for f in elem.findall('KeywordList/Keyword')]
# timepositions - times for which data is available.
self.timepositions=None
self.defaulttimeposition = None
for extent in elem.findall('Extent'):
if extent.attrib.get("name").lower() =='time':
if extent.text:
self.timepositions=extent.text.split(',')
self.defaulttimeposition = extent.attrib.get("default")
break
# Elevations - available vertical levels
self.elevations=None
for extent in elem.findall('Extent'):
if extent.attrib.get("name").lower() =='elevation':
if extent.text:
self.elevations=extent.text.split(',')
break
# MetadataURLs
self.metadataUrls = []
for m in elem.findall('MetadataURL'):
metadataUrl = {
'type': testXMLValue(m.attrib['type'], attrib=True),
'format': testXMLValue(m.find('Format')),
'url': testXMLValue(m.find('OnlineResource').attrib['{http://www.w3.org/1999/xlink}href'], attrib=True)
}
if metadataUrl['url'] is not None and parse_remote_metadata: # download URL
try:
content = openURL(metadataUrl['url'], timeout=timeout)
doc = etree.parse(content)
if metadataUrl['type'] is not None:
if metadataUrl['type'] == 'FGDC':
metadataUrl['metadata'] = Metadata(doc)
if metadataUrl['type'] == 'TC211':
metadataUrl['metadata'] = MD_Metadata(doc)
except Exception:
metadataUrl['metadata'] = None
self.metadataUrls.append(metadataUrl)
# DataURLs
self.dataUrls = []
for m in elem.findall('DataURL'):
dataUrl = {
'format': m.find('Format').text.strip(),
'url': m.find('OnlineResource').attrib['{http://www.w3.org/1999/xlink}href']
}
self.dataUrls.append(dataUrl)
self.layers = []
for child in elem.findall('Layer'):
self.layers.append(ContentMetadata(child, self))
def __str__(self):
return 'Layer Name: %s Title: %s' % (self.name, self.title)
class OperationMetadata:
"""Abstraction for WMS OperationMetadata.
Implements IOperationMetadata.
"""
def __init__(self, elem):
"""."""
self.name = xmltag_split(elem.tag)
# formatOptions
self.formatOptions = [f.text for f in elem.findall('Format')]
self.methods = []
for verb in elem.findall('DCPType/HTTP/*'):
url = verb.find('OnlineResource').attrib['{http://www.w3.org/1999/xlink}href']
self.methods.append({'type' : xmltag_split(verb.tag), 'url': url})
class ContactMetadata:
"""Abstraction for contact details advertised in GetCapabilities.
"""
def __init__(self, elem):
name = elem.find('ContactPersonPrimary/ContactPerson')
if name is not None:
self.name=name.text
else:
self.name=None
email = elem.find('ContactElectronicMailAddress')
if email is not None:
self.email=email.text
else:
self.email=None
self.address = self.city = self.region = None
self.postcode = self.country = None
address = elem.find('ContactAddress')
if address is not None:
street = address.find('Address')
if street is not None: self.address = street.text
city = address.find('City')
if city is not None: self.city = city.text
region = address.find('StateOrProvince')
if region is not None: self.region = region.text
postcode = address.find('PostCode')
if postcode is not None: self.postcode = postcode.text
country = address.find('Country')
if country is not None: self.country = country.text
organization = elem.find('ContactPersonPrimary/ContactOrganization')
if organization is not None: self.organization = organization.text
else:self.organization = None
position = elem.find('ContactPosition')
if position is not None: self.position = position.text
else: self.position = None
class WMSCapabilitiesReader:
"""Read and parse capabilities document into a lxml.etree infoset
"""
def __init__(self, version='1.1.1', url=None, un=None, pw=None):
"""Initialize"""
self.version = version
self._infoset = None
self.url = url
self.username = un
self.password = pw
#if self.username and self.password:
## Provide login information in order to use the WMS server
## Create an OpenerDirector with support for Basic HTTP
## Authentication...
#passman = HTTPPasswordMgrWithDefaultRealm()
#passman.add_password(None, self.url, self.username, self.password)
#auth_handler = HTTPBasicAuthHandler(passman)
#opener = build_opener(auth_handler)
#self._open = opener.open
def capabilities_url(self, service_url):
"""Return a capabilities url
"""
qs = []
if service_url.find('?') != -1:
qs = cgi.parse_qsl(service_url.split('?')[1])
params = [x[0] for x in qs]
if 'service' not in params:
qs.append(('service', 'WMS'))
if 'request' not in params:
qs.append(('request', 'GetCapabilities'))
if 'version' not in params:
qs.append(('version', self.version))
urlqs = urlencode(tuple(qs))
return service_url.split('?')[0] + '?' + urlqs
def read(self, service_url, timeout=30):
"""Get and parse a WMS capabilities document, returning an
elementtree instance
service_url is the base url, to which is appended the service,
version, and request parameters
"""
getcaprequest = self.capabilities_url(service_url)
#now split it up again to use the generic openURL function...
spliturl=getcaprequest.split('?')
u = openURL(spliturl[0], spliturl[1], method='Get', username=self.username, password=self.password, timeout=timeout)
return etree.fromstring(u.read())
def readString(self, st):
"""Parse a WMS capabilities document, returning an elementtree instance
string should be an XML capabilities document
"""
if not isinstance(st, str) and not isinstance(st, bytes):
raise ValueError("String must be of type string or bytes, not %s" % type(st))
return etree.fromstring(st)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
11601,
13,
4830,
13,
1046,
1882,
199,
3,
26237,
199,
3,
1898,
334,
67,
9,
8353,
12,
8315,
3240,
290,
445,
14,
598,
382,
6528,
199,
3,
1898,
334,
67,
9,
11811,
653,
85,
1845,
79,
428,
689,
44,
665,
1014,
921,
4850,
1845,
79,
14,
957,
30,
199,
3,
199,
3,
6642,
520,
3240,
290,
598,
382,
6528,
665,
1226,
382,
6528,
32,
25876,
73,
14,
957,
30,
199,
3,
3698,
1603,
13987,
287,
1626,
6051,
287,
357,
665,
3387,
32,
4850,
1845,
79,
14,
957,
30,
199,
3,
199,
3,
18684,
3031,
26,
12578,
382,
6528,
32,
25876,
73,
14,
957,
199,
3,
26237,
199,
199,
624,
199,
3735,
367,
6001,
9672,
7591,
334,
55,
3053,
9,
3102,
436,
3341,
14,
199,
199,
31499,
5171,
1454,
1015,
413,
14,
17,
14,
17,
402,
314,
644,
3053,
4113,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
199,
646,
16004,
199,
893,
26,
8540,
327,
2018,
650,
272,
687,
4011,
14,
1122,
492,
16511,
199,
2590,
3545,
26,
258,
327,
2018,
499,
272,
687,
4011,
492,
16511,
199,
199,
646,
3598,
199,
199,
646,
3816,
199,
199,
504,
1275,
9464,
492,
7559,
199,
504,
1275,
1974,
492,
1551,
2632,
12,
511,
4317,
1110,
12,
5536,
63,
1652,
63,
513,
12,
2748,
1450,
63,
1294,
12,
8773,
199,
504,
1275,
9681,
3833,
492,
16160,
199,
504,
1275,
4595,
492,
15830,
63,
5142,
421,
199,
533,
7591,
1726,
8,
1726,
304,
272,
408,
55,
3053,
7591,
1726,
339,
9382,
26,
267,
1245,
1553,
3974,
1125,
1245,
267,
2748,
221,
1553,
2615,
2748,
1125,
1245,
687,
1654,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1245,
12,
2748,
304,
267,
291,
14,
1188,
275,
1245,
267,
291,
14,
1652,
275,
2748,
5493,
347,
636,
495,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
1188,
9,
421,
199,
533,
22516,
5807,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
6001,
2956,
3167,
8,
785,
304,
272,
408,
5583,
29639,
367,
593,
7484,
6001,
9672,
7591,
334,
55,
3053,
680,
339,
24664,
473,
5926,
2956,
3167,
14,
272,
408,
2286,
347,
636,
6095,
721,
277,
12,
354,
304,
267,
1449,
1104,
4072,
2600,
370,
2040,
1211,
2839,
2879,
370,
2435,
9393,
2344,
267,
340,
536,
315,
291,
855,
18480,
19734,
4407,
735,
288,
372,
291,
855,
18480,
19734,
4407,
5832,
354,
61,
267,
587,
26,
288,
746,
4067,
480,
1944,
1564,
4310,
450,
83,
2,
450,
536,
9,
25979,
347,
636,
826,
721,
277,
12,
1166,
12,
1015,
534,
17,
14,
17,
14,
17,
297,
2748,
29,
403,
12,
3434,
29,
403,
12,
2505,
29,
403,
12,
2198,
63,
3846,
63,
2343,
29,
797,
12,
2653,
29,
1216,
304,
267,
408,
9345,
1041,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
2473,
275,
3434,
267,
291,
14,
2060,
275,
2505,
267,
291,
14,
1023,
275,
1015,
267,
291,
14,
2593,
275,
2653,
267,
291,
423,
10732,
275,
488,
398,
327,
15995,
8860,
701,
23099,
267,
7002,
275,
644,
3053,
17006,
5929,
8,
277,
14,
1023,
12,
1166,
29,
277,
14,
633,
12,
625,
29,
277,
14,
2473,
12,
19206,
29,
277,
14,
2060,
9,
267,
340,
2748,
26,
221,
327,
1586,
687,
5489,
2748,
288,
291,
423,
10732,
275,
7002,
14,
22765,
8,
1652,
9,
267,
587,
26,
221,
327,
1586,
687,
1654,
288,
291,
423,
10732,
275,
7002,
14,
739,
8,
277,
14,
633,
12,
2653,
29,
277,
14,
2593,
9,
398,
327,
5126,
10015,
14918,
3341,
340,
314,
1177,
365,
282,
7591,
1726,
7457,
267,
542,
275,
291,
423,
10732,
14,
1623,
360,
3167,
1726,
358,
4960,
340,
542,
365,
440,
488,
26,
7205,
2329,
63,
1188,
275,
620,
8,
261,
14,
505,
680,
1913,
342,
7205,
746,
7591,
1726,
8,
1508,
63,
1188,
12,
2748,
9,
24807,
327,
1900,
3341,
2251,
267,
291,
423,
1506,
5142,
8,
1122,
63,
3846,
63,
2343,
9,
339,
347,
485,
362,
2874,
1829,
8,
277,
304,
267,
340,
440,
291,
423,
10732,
26,
288,
7002,
275,
644,
3053,
17006,
5929,
8,
355,
291,
14,
1023,
12,
1166,
29,
277,
14,
633,
12,
625,
29,
277,
14,
2473,
12,
19206,
29,
277,
14,
2060,
355,
776,
288,
291,
423,
10732,
275,
7591,
5142,
8,
5503,
14,
739,
8,
277,
14,
633,
430,
267,
372,
291,
423,
10732,
339,
347,
485,
1506,
5142,
8,
277,
12,
2198,
63,
3846,
63,
2343,
29,
797,
304,
267,
1449,
663,
1536,
14918,
3341,
2251,
1449,
2728,
327,
1364,
41,
24926,
3341,
267,
2435,
6086,
29,
277,
423,
10732,
14,
1623,
360,
3167,
358,
267,
291,
14,
73,
24926,
29,
3167,
41,
24926,
8,
1364,
6086,
12,
291,
14,
1023,
9,
259,
2728,
327,
1364,
6663,
3341,
267,
291,
14,
3780,
29,
3167,
6663,
8,
1364,
6086,
9,
259,
10631,
327,
1364,
12929,
3341,
4960,
291,
14,
8170,
9811,
267,
367,
6193,
315,
291,
423,
10732,
14,
1623,
360,
24512,
15,
2017,
358,
32734,
288,
291,
14,
8170,
14,
740,
8,
6044,
5142,
8,
6086,
430,
1779,
267,
327,
1364,
11383,
3341,
26,
4154,
30075,
365,
626,
8500,
675,
282,
2746,
13,
1896,
4960,
327,
1897,
465,
282,
3341,
20765,
1793,
12,
6548,
1655,
14,
267,
291,
14,
4407,
275,
8773,
342,
267,
22053,
275,
291,
423,
10732,
14,
1623,
360,
24512,
358,
2728,
327,
6794,
9840,
13082,
1564,
3341,
367,
1006,
4045,
4008,
14,
267,
327,
1378,
314,
6001,
2956,
3167,
14,
4407,
3877,
1454,
3341,
402,
4310,
9393,
14,
267,
347,
13082,
63,
4359,
8,
1708,
63,
6086,
12,
1676,
63,
2343,
304,
288,
367,
1478,
12,
6193,
315,
3874,
8,
1708,
63,
6086,
14,
6452,
360,
5003,
8109,
355,
6904,
275,
6646,
5142,
8,
6086,
12,
1676,
29,
1708,
63,
2343,
12,
1478,
29,
1080,
11,
17,
12,
2198,
63,
3846,
63,
2343,
29,
1122,
63,
3846,
63,
2343,
9,
355,
340,
6904,
14,
344,
26,
490,
340,
6904,
14,
344,
315,
291,
14,
4407,
26,
717,
3598,
14,
4050,
360,
2714,
3341,
367,
4045,
2071,
83,
2,
2575,
3495,
14,
11719,
1982,
4045,
7,
450,
6904,
14,
344,
9,
490
] |
[
1882,
2803,
26,
11601,
13,
4830,
13,
1046,
1882,
199,
3,
26237,
199,
3,
1898,
334,
67,
9,
8353,
12,
8315,
3240,
290,
445,
14,
598,
382,
6528,
199,
3,
1898,
334,
67,
9,
11811,
653,
85,
1845,
79,
428,
689,
44,
665,
1014,
921,
4850,
1845,
79,
14,
957,
30,
199,
3,
199,
3,
6642,
520,
3240,
290,
598,
382,
6528,
665,
1226,
382,
6528,
32,
25876,
73,
14,
957,
30,
199,
3,
3698,
1603,
13987,
287,
1626,
6051,
287,
357,
665,
3387,
32,
4850,
1845,
79,
14,
957,
30,
199,
3,
199,
3,
18684,
3031,
26,
12578,
382,
6528,
32,
25876,
73,
14,
957,
199,
3,
26237,
199,
199,
624,
199,
3735,
367,
6001,
9672,
7591,
334,
55,
3053,
9,
3102,
436,
3341,
14,
199,
199,
31499,
5171,
1454,
1015,
413,
14,
17,
14,
17,
402,
314,
644,
3053,
4113,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
199,
646,
16004,
199,
893,
26,
8540,
327,
2018,
650,
272,
687,
4011,
14,
1122,
492,
16511,
199,
2590,
3545,
26,
258,
327,
2018,
499,
272,
687,
4011,
492,
16511,
199,
199,
646,
3598,
199,
199,
646,
3816,
199,
199,
504,
1275,
9464,
492,
7559,
199,
504,
1275,
1974,
492,
1551,
2632,
12,
511,
4317,
1110,
12,
5536,
63,
1652,
63,
513,
12,
2748,
1450,
63,
1294,
12,
8773,
199,
504,
1275,
9681,
3833,
492,
16160,
199,
504,
1275,
4595,
492,
15830,
63,
5142,
421,
199,
533,
7591,
1726,
8,
1726,
304,
272,
408,
55,
3053,
7591,
1726,
339,
9382,
26,
267,
1245,
1553,
3974,
1125,
1245,
267,
2748,
221,
1553,
2615,
2748,
1125,
1245,
687,
1654,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1245,
12,
2748,
304,
267,
291,
14,
1188,
275,
1245,
267,
291,
14,
1652,
275,
2748,
5493,
347,
636,
495,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
1188,
9,
421,
199,
533,
22516,
5807,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
6001,
2956,
3167,
8,
785,
304,
272,
408,
5583,
29639,
367,
593,
7484,
6001,
9672,
7591,
334,
55,
3053,
680,
339,
24664,
473,
5926,
2956,
3167,
14,
272,
408,
2286,
347,
636,
6095,
721,
277,
12,
354,
304,
267,
1449,
1104,
4072,
2600,
370,
2040,
1211,
2839,
2879,
370,
2435,
9393,
2344,
267,
340,
536,
315,
291,
855,
18480,
19734,
4407,
735,
288,
372,
291,
855,
18480,
19734,
4407,
5832,
354,
61,
267,
587,
26,
288,
746,
4067,
480,
1944,
1564,
4310,
450,
83,
2,
450,
536,
9,
25979,
347,
636,
826,
721,
277,
12,
1166,
12,
1015,
534,
17,
14,
17,
14,
17,
297,
2748,
29,
403,
12,
3434,
29,
403,
12,
2505,
29,
403,
12,
2198,
63,
3846,
63,
2343,
29,
797,
12,
2653,
29,
1216,
304,
267,
408,
9345,
1041,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
2473,
275,
3434,
267,
291,
14,
2060,
275,
2505,
267,
291,
14,
1023,
275,
1015,
267,
291,
14,
2593,
275,
2653,
267,
291,
423,
10732,
275,
488,
398,
327,
15995,
8860,
701,
23099,
267,
7002,
275,
644,
3053,
17006,
5929,
8,
277,
14,
1023,
12,
1166,
29,
277,
14,
633,
12,
625,
29,
277,
14,
2473,
12,
19206,
29,
277,
14,
2060,
9,
267,
340,
2748,
26,
221,
327,
1586,
687,
5489,
2748,
288,
291,
423,
10732,
275,
7002,
14,
22765,
8,
1652,
9,
267,
587,
26,
221,
327,
1586,
687,
1654,
288,
291,
423,
10732,
275,
7002,
14,
739,
8,
277,
14,
633,
12,
2653,
29,
277,
14,
2593,
9,
398,
327,
5126,
10015,
14918,
3341,
340,
314,
1177,
365,
282,
7591,
1726,
7457,
267,
542,
275,
291,
423,
10732,
14,
1623,
360,
3167,
1726,
358,
4960,
340,
542,
365,
440,
488,
26,
7205,
2329,
63,
1188,
275,
620,
8,
261,
14,
505,
680,
1913,
342,
7205,
746,
7591,
1726,
8,
1508,
63,
1188,
12,
2748,
9,
24807,
327,
1900,
3341,
2251,
267,
291,
423,
1506,
5142,
8,
1122,
63,
3846,
63,
2343,
9,
339,
347,
485,
362,
2874,
1829,
8,
277,
304,
267,
340,
440,
291,
423,
10732,
26,
288,
7002,
275,
644,
3053,
17006,
5929,
8,
355,
291,
14,
1023,
12,
1166,
29,
277,
14,
633,
12,
625,
29,
277,
14,
2473,
12,
19206,
29,
277,
14,
2060,
355,
776,
288,
291,
423,
10732,
275,
7591,
5142,
8,
5503,
14,
739,
8,
277,
14,
633,
430,
267,
372,
291,
423,
10732,
339,
347,
485,
1506,
5142,
8,
277,
12,
2198,
63,
3846,
63,
2343,
29,
797,
304,
267,
1449,
663,
1536,
14918,
3341,
2251,
1449,
2728,
327,
1364,
41,
24926,
3341,
267,
2435,
6086,
29,
277,
423,
10732,
14,
1623,
360,
3167,
358,
267,
291,
14,
73,
24926,
29,
3167,
41,
24926,
8,
1364,
6086,
12,
291,
14,
1023,
9,
259,
2728,
327,
1364,
6663,
3341,
267,
291,
14,
3780,
29,
3167,
6663,
8,
1364,
6086,
9,
259,
10631,
327,
1364,
12929,
3341,
4960,
291,
14,
8170,
9811,
267,
367,
6193,
315,
291,
423,
10732,
14,
1623,
360,
24512,
15,
2017,
358,
32734,
288,
291,
14,
8170,
14,
740,
8,
6044,
5142,
8,
6086,
430,
1779,
267,
327,
1364,
11383,
3341,
26,
4154,
30075,
365,
626,
8500,
675,
282,
2746,
13,
1896,
4960,
327,
1897,
465,
282,
3341,
20765,
1793,
12,
6548,
1655,
14,
267,
291,
14,
4407,
275,
8773,
342,
267,
22053,
275,
291,
423,
10732,
14,
1623,
360,
24512,
358,
2728,
327,
6794,
9840,
13082,
1564,
3341,
367,
1006,
4045,
4008,
14,
267,
327,
1378,
314,
6001,
2956,
3167,
14,
4407,
3877,
1454,
3341,
402,
4310,
9393,
14,
267,
347,
13082,
63,
4359,
8,
1708,
63,
6086,
12,
1676,
63,
2343,
304,
288,
367,
1478,
12,
6193,
315,
3874,
8,
1708,
63,
6086,
14,
6452,
360,
5003,
8109,
355,
6904,
275,
6646,
5142,
8,
6086,
12,
1676,
29,
1708,
63,
2343,
12,
1478,
29,
1080,
11,
17,
12,
2198,
63,
3846,
63,
2343,
29,
1122,
63,
3846,
63,
2343,
9,
355,
340,
6904,
14,
344,
26,
490,
340,
6904,
14,
344,
315,
291,
14,
4407,
26,
717,
3598,
14,
4050,
360,
2714,
3341,
367,
4045,
2071,
83,
2,
2575,
3495,
14,
11719,
1982,
4045,
7,
450,
6904,
14,
344,
9,
490,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
RoyalKing/zerorpc-python
|
tests/test_events.py
|
39
|
5196
|
# -*- coding: utf-8 -*-
# Open Source Initiative OSI - The MIT License (MIT):Licensing
#
# The MIT License (MIT)
# Copyright (c) 2012 DotCloud Inc (opensource@dotcloud.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from zerorpc import zmq
import zerorpc
from testutils import teardown, random_ipc_endpoint
class MokupContext():
_next_id = 0
def new_msgid(self):
new_id = MokupContext._next_id
MokupContext._next_id += 1
return new_id
def test_context():
c = zerorpc.Context()
assert c.new_msgid() is not None
def test_event():
context = MokupContext()
event = zerorpc.Event('mylittleevent', (None,), context=context)
print event
assert event.name == 'mylittleevent'
assert event.header['message_id'] == 0
assert event.args == (None,)
event = zerorpc.Event('mylittleevent2', ('42',), context=context)
print event
assert event.name == 'mylittleevent2'
assert event.header['message_id'] == 1
assert event.args == ('42',)
event = zerorpc.Event('mylittleevent3', ('a', 42), context=context)
print event
assert event.name == 'mylittleevent3'
assert event.header['message_id'] == 2
assert event.args == ('a', 42)
event = zerorpc.Event('mylittleevent4', ('b', 21), context=context)
print event
assert event.name == 'mylittleevent4'
assert event.header['message_id'] == 3
assert event.args == ('b', 21)
packed = event.pack()
unpacked = zerorpc.Event.unpack(packed)
print unpacked
assert unpacked.name == 'mylittleevent4'
assert unpacked.header['message_id'] == 3
assert unpacked.args == ('b', 21)
event = zerorpc.Event('mylittleevent5', ('c', 24, True),
header={'lol': 'rofl'}, context=None)
print event
assert event.name == 'mylittleevent5'
assert event.header['lol'] == 'rofl'
assert event.args == ('c', 24, True)
event = zerorpc.Event('mod', (42,), context=context)
print event
assert event.name == 'mod'
assert event.header['message_id'] == 4
assert event.args == (42,)
event.header.update({'stream': True})
assert event.header['stream'] is True
def test_events_req_rep():
endpoint = random_ipc_endpoint()
server = zerorpc.Events(zmq.REP)
server.bind(endpoint)
client = zerorpc.Events(zmq.REQ)
client.connect(endpoint)
client.emit('myevent', ('arg1',))
event = server.recv()
print event
assert event.name == 'myevent'
assert event.args == ('arg1',)
def test_events_req_rep2():
endpoint = random_ipc_endpoint()
server = zerorpc.Events(zmq.REP)
server.bind(endpoint)
client = zerorpc.Events(zmq.REQ)
client.connect(endpoint)
for i in xrange(10):
client.emit('myevent' + str(i), (i,))
event = server.recv()
print event
assert event.name == 'myevent' + str(i)
assert event.args == (i,)
server.emit('answser' + str(i * 2), (i * 2,))
event = client.recv()
print event
assert event.name == 'answser' + str(i * 2)
assert event.args == (i * 2,)
def test_events_dealer_router():
endpoint = random_ipc_endpoint()
server = zerorpc.Events(zmq.XREP)
server.bind(endpoint)
client = zerorpc.Events(zmq.XREQ)
client.connect(endpoint)
for i in xrange(6):
client.emit('myevent' + str(i), (i,))
event = server.recv()
print event
assert event.name == 'myevent' + str(i)
assert event.args == (i,)
server.emit('answser' + str(i * 2), (i * 2,),
xheader=dict(zmqid=event.header['zmqid']))
event = client.recv()
print event
assert event.name == 'answser' + str(i * 2)
assert event.args == (i * 2,)
def test_events_push_pull():
endpoint = random_ipc_endpoint()
server = zerorpc.Events(zmq.PULL)
server.bind(endpoint)
client = zerorpc.Events(zmq.PUSH)
client.connect(endpoint)
for x in xrange(10):
client.emit('myevent', (x,))
for x in xrange(10):
event = server.recv()
print event
assert event.name == 'myevent'
assert event.args == (x,)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
3232,
5800,
21412,
1905,
25718,
446,
710,
10697,
844,
334,
13965,
304,
44,
530,
25843,
199,
3,
199,
3,
710,
10697,
844,
334,
13965,
9,
199,
3,
1898,
334,
67,
9,
6029,
24716,
9089,
3277,
334,
16374,
32,
3287,
4091,
14,
957,
9,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
199,
3,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
199,
3,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
199,
3,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
199,
3,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
199,
3,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
421,
199,
504,
8043,
30786,
492,
26633,
199,
646,
8043,
30786,
199,
504,
511,
1208,
492,
17558,
12,
2196,
63,
32352,
63,
6520,
199,
199,
533,
603,
2214,
2998,
837,
272,
485,
2184,
63,
344,
275,
378,
339,
347,
892,
63,
15245,
8,
277,
304,
267,
892,
63,
344,
275,
603,
2214,
2998,
423,
2184,
63,
344,
267,
603,
2214,
2998,
423,
2184,
63,
344,
847,
413,
267,
372,
892,
63,
344,
421,
199,
318,
511,
63,
1100,
837,
272,
286,
275,
8043,
30786,
14,
2998,
342,
272,
702,
286,
14,
1222,
63,
15245,
342,
365,
440,
488,
421,
199,
318,
511,
63,
1430,
837,
272,
1067,
275,
603,
2214,
2998,
342,
272,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
297,
334,
403,
4706,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
378,
272,
702,
1566,
14,
589,
508,
334,
403,
4258,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
18,
297,
661,
2260,
5529,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
18,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
413,
272,
702,
1566,
14,
589,
508,
661,
2260,
9538,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
19,
297,
661,
65,
297,
5685,
395,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
19,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
499,
272,
702,
1566,
14,
589,
508,
661,
65,
297,
5685,
9,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
20,
297,
661,
66,
297,
7829,
395,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
20,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
650,
272,
702,
1566,
14,
589,
508,
661,
66,
297,
7829,
9,
339,
13170,
275,
1566,
14,
1389,
342,
272,
23389,
275,
8043,
30786,
14,
2390,
14,
5301,
8,
12286,
9,
272,
870,
23389,
339,
702,
23389,
14,
354,
508,
283,
1662,
10182,
1430,
20,
7,
272,
702,
23389,
14,
1291,
459,
1188,
63,
344,
418,
508,
650,
272,
702,
23389,
14,
589,
508,
661,
66,
297,
7829,
9,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
21,
297,
661,
67,
297,
5504,
12,
715,
395,
288,
1406,
3713,
320,
76,
356,
283,
293,
2327,
2267,
1067,
29,
403,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
21,
7,
272,
702,
1566,
14,
1291,
459,
320,
76,
418,
508,
283,
293,
2327,
7,
272,
702,
1566,
14,
589,
508,
661,
67,
297,
5504,
12,
715,
9,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1494,
297,
334,
2260,
4706,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1494,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
841,
272,
702,
1566,
14,
589,
508,
334,
2260,
4258,
272,
1566,
14,
1291,
14,
873,
3252,
1745,
356,
715,
1552,
272,
702,
1566,
14,
1291,
459,
1745,
418,
365,
715,
421,
199,
318,
511,
63,
4368,
63,
2103,
63,
1155,
837,
272,
6037,
275,
2196,
63,
32352,
63,
6520,
342,
272,
1654,
275,
8043,
30786,
14,
11770,
8,
21290,
14,
22554,
9,
272,
1654,
14,
3409,
8,
6520,
9,
339,
1890,
275,
8043,
30786,
14,
11770,
8,
21290,
14,
14583,
9,
272,
1890,
14,
2242,
8,
6520,
9,
339,
1890,
14,
8159,
360,
1662,
1430,
297,
661,
1273,
17,
16829,
339,
1566,
275,
1654,
14,
7637,
342,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
1430,
7,
272,
702,
1566,
14,
589,
508,
661,
1273,
17,
9538,
421,
199,
318,
511,
63,
4368,
63,
2103,
63,
1155,
18,
837,
272,
6037,
275,
2196,
63,
32352,
63,
6520,
342,
272,
1654,
275,
8043,
30786,
14,
11770,
8,
21290,
14,
22554,
9,
272,
1654,
14,
3409,
8,
6520,
9,
339,
1890,
275,
8043,
30786,
14,
11770,
8,
21290,
14,
14583,
9,
272,
1890,
14,
2242,
8,
6520,
9,
339,
367,
284,
315,
4945,
8,
709,
304,
267,
1890,
14,
8159,
360,
1662,
1430,
7,
435,
620,
8,
73,
395,
334,
73,
4641,
267,
1566,
275,
1654,
14,
7637,
342,
267,
870,
1566,
267,
702,
1566
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
3232,
5800,
21412,
1905,
25718,
446,
710,
10697,
844,
334,
13965,
304,
44,
530,
25843,
199,
3,
199,
3,
710,
10697,
844,
334,
13965,
9,
199,
3,
1898,
334,
67,
9,
6029,
24716,
9089,
3277,
334,
16374,
32,
3287,
4091,
14,
957,
9,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
199,
3,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
199,
3,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
199,
3,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
199,
3,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
199,
3,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
421,
199,
504,
8043,
30786,
492,
26633,
199,
646,
8043,
30786,
199,
504,
511,
1208,
492,
17558,
12,
2196,
63,
32352,
63,
6520,
199,
199,
533,
603,
2214,
2998,
837,
272,
485,
2184,
63,
344,
275,
378,
339,
347,
892,
63,
15245,
8,
277,
304,
267,
892,
63,
344,
275,
603,
2214,
2998,
423,
2184,
63,
344,
267,
603,
2214,
2998,
423,
2184,
63,
344,
847,
413,
267,
372,
892,
63,
344,
421,
199,
318,
511,
63,
1100,
837,
272,
286,
275,
8043,
30786,
14,
2998,
342,
272,
702,
286,
14,
1222,
63,
15245,
342,
365,
440,
488,
421,
199,
318,
511,
63,
1430,
837,
272,
1067,
275,
603,
2214,
2998,
342,
272,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
297,
334,
403,
4706,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
378,
272,
702,
1566,
14,
589,
508,
334,
403,
4258,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
18,
297,
661,
2260,
5529,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
18,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
413,
272,
702,
1566,
14,
589,
508,
661,
2260,
9538,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
19,
297,
661,
65,
297,
5685,
395,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
19,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
499,
272,
702,
1566,
14,
589,
508,
661,
65,
297,
5685,
9,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
20,
297,
661,
66,
297,
7829,
395,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
20,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
650,
272,
702,
1566,
14,
589,
508,
661,
66,
297,
7829,
9,
339,
13170,
275,
1566,
14,
1389,
342,
272,
23389,
275,
8043,
30786,
14,
2390,
14,
5301,
8,
12286,
9,
272,
870,
23389,
339,
702,
23389,
14,
354,
508,
283,
1662,
10182,
1430,
20,
7,
272,
702,
23389,
14,
1291,
459,
1188,
63,
344,
418,
508,
650,
272,
702,
23389,
14,
589,
508,
661,
66,
297,
7829,
9,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1662,
10182,
1430,
21,
297,
661,
67,
297,
5504,
12,
715,
395,
288,
1406,
3713,
320,
76,
356,
283,
293,
2327,
2267,
1067,
29,
403,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
10182,
1430,
21,
7,
272,
702,
1566,
14,
1291,
459,
320,
76,
418,
508,
283,
293,
2327,
7,
272,
702,
1566,
14,
589,
508,
661,
67,
297,
5504,
12,
715,
9,
339,
1566,
275,
8043,
30786,
14,
2390,
360,
1494,
297,
334,
2260,
4706,
1067,
29,
1100,
9,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1494,
7,
272,
702,
1566,
14,
1291,
459,
1188,
63,
344,
418,
508,
841,
272,
702,
1566,
14,
589,
508,
334,
2260,
4258,
272,
1566,
14,
1291,
14,
873,
3252,
1745,
356,
715,
1552,
272,
702,
1566,
14,
1291,
459,
1745,
418,
365,
715,
421,
199,
318,
511,
63,
4368,
63,
2103,
63,
1155,
837,
272,
6037,
275,
2196,
63,
32352,
63,
6520,
342,
272,
1654,
275,
8043,
30786,
14,
11770,
8,
21290,
14,
22554,
9,
272,
1654,
14,
3409,
8,
6520,
9,
339,
1890,
275,
8043,
30786,
14,
11770,
8,
21290,
14,
14583,
9,
272,
1890,
14,
2242,
8,
6520,
9,
339,
1890,
14,
8159,
360,
1662,
1430,
297,
661,
1273,
17,
16829,
339,
1566,
275,
1654,
14,
7637,
342,
272,
870,
1566,
272,
702,
1566,
14,
354,
508,
283,
1662,
1430,
7,
272,
702,
1566,
14,
589,
508,
661,
1273,
17,
9538,
421,
199,
318,
511,
63,
4368,
63,
2103,
63,
1155,
18,
837,
272,
6037,
275,
2196,
63,
32352,
63,
6520,
342,
272,
1654,
275,
8043,
30786,
14,
11770,
8,
21290,
14,
22554,
9,
272,
1654,
14,
3409,
8,
6520,
9,
339,
1890,
275,
8043,
30786,
14,
11770,
8,
21290,
14,
14583,
9,
272,
1890,
14,
2242,
8,
6520,
9,
339,
367,
284,
315,
4945,
8,
709,
304,
267,
1890,
14,
8159,
360,
1662,
1430,
7,
435,
620,
8,
73,
395,
334,
73,
4641,
267,
1566,
275,
1654,
14,
7637,
342,
267,
870,
1566,
267,
702,
1566,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
murfz/Sick-Beard
|
lib/enzyme/mkv.py
|
163
|
30439
|
# -*- coding: utf-8 -*-
# enzyme - Video metadata parser
# Copyright 2011-2012 Antoine Bertin <diaoulael@gmail.com>
# Copyright 2003-2006 Thomas Schueppel <stain@acm.org>
# Copyright 2003-2006 Dirk Meyer <dischi@freevo.org>
# Copyright 2003-2006 Jason Tackaberry <tack@urandom.ca>
#
# This file is part of enzyme.
#
# enzyme 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.
#
# enzyme 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 enzyme. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from exceptions import ParseError
from struct import unpack
import core
import logging
import re
__all__ = ['Parser']
# get logging object
log = logging.getLogger(__name__)
# Main IDs for the Matroska streams
MATROSKA_VIDEO_TRACK = 0x01
MATROSKA_AUDIO_TRACK = 0x02
MATROSKA_SUBTITLES_TRACK = 0x11
MATROSKA_HEADER_ID = 0x1A45DFA3
MATROSKA_TRACKS_ID = 0x1654AE6B
MATROSKA_CUES_ID = 0x1C53BB6B
MATROSKA_SEGMENT_ID = 0x18538067
MATROSKA_SEGMENT_INFO_ID = 0x1549A966
MATROSKA_CLUSTER_ID = 0x1F43B675
MATROSKA_VOID_ID = 0xEC
MATROSKA_CRC_ID = 0xBF
MATROSKA_TIMECODESCALE_ID = 0x2AD7B1
MATROSKA_DURATION_ID = 0x4489
MATROSKA_CRC32_ID = 0xBF
MATROSKA_TIMECODESCALE_ID = 0x2AD7B1
MATROSKA_MUXING_APP_ID = 0x4D80
MATROSKA_WRITING_APP_ID = 0x5741
MATROSKA_CODEC_ID = 0x86
MATROSKA_CODEC_PRIVATE_ID = 0x63A2
MATROSKA_FRAME_DURATION_ID = 0x23E383
MATROSKA_VIDEO_SETTINGS_ID = 0xE0
MATROSKA_VIDEO_WIDTH_ID = 0xB0
MATROSKA_VIDEO_HEIGHT_ID = 0xBA
MATROSKA_VIDEO_INTERLACED_ID = 0x9A
MATROSKA_VIDEO_DISPLAY_WIDTH_ID = 0x54B0
MATROSKA_VIDEO_DISPLAY_HEIGHT_ID = 0x54BA
MATROSKA_AUDIO_SETTINGS_ID = 0xE1
MATROSKA_AUDIO_SAMPLERATE_ID = 0xB5
MATROSKA_AUDIO_CHANNELS_ID = 0x9F
MATROSKA_TRACK_UID_ID = 0x73C5
MATROSKA_TRACK_NUMBER_ID = 0xD7
MATROSKA_TRACK_TYPE_ID = 0x83
MATROSKA_TRACK_LANGUAGE_ID = 0x22B59C
MATROSKA_TRACK_OFFSET = 0x537F
MATROSKA_TRACK_FLAG_DEFAULT_ID = 0x88
MATROSKA_TRACK_FLAG_ENABLED_ID = 0xB9
MATROSKA_TITLE_ID = 0x7BA9
MATROSKA_DATE_UTC_ID = 0x4461
MATROSKA_NAME_ID = 0x536E
MATROSKA_CHAPTERS_ID = 0x1043A770
MATROSKA_CHAPTER_UID_ID = 0x73C4
MATROSKA_EDITION_ENTRY_ID = 0x45B9
MATROSKA_CHAPTER_ATOM_ID = 0xB6
MATROSKA_CHAPTER_TIME_START_ID = 0x91
MATROSKA_CHAPTER_TIME_END_ID = 0x92
MATROSKA_CHAPTER_FLAG_ENABLED_ID = 0x4598
MATROSKA_CHAPTER_DISPLAY_ID = 0x80
MATROSKA_CHAPTER_LANGUAGE_ID = 0x437C
MATROSKA_CHAPTER_STRING_ID = 0x85
MATROSKA_ATTACHMENTS_ID = 0x1941A469
MATROSKA_ATTACHED_FILE_ID = 0x61A7
MATROSKA_FILE_DESC_ID = 0x467E
MATROSKA_FILE_NAME_ID = 0x466E
MATROSKA_FILE_MIME_TYPE_ID = 0x4660
MATROSKA_FILE_DATA_ID = 0x465C
MATROSKA_SEEKHEAD_ID = 0x114D9B74
MATROSKA_SEEK_ID = 0x4DBB
MATROSKA_SEEKID_ID = 0x53AB
MATROSKA_SEEK_POSITION_ID = 0x53AC
MATROSKA_TAGS_ID = 0x1254C367
MATROSKA_TAG_ID = 0x7373
MATROSKA_TARGETS_ID = 0x63C0
MATROSKA_TARGET_TYPE_VALUE_ID = 0x68CA
MATROSKA_TARGET_TYPE_ID = 0x63CA
MATRSOKA_TAGS_TRACK_UID_ID = 0x63C5
MATRSOKA_TAGS_EDITION_UID_ID = 0x63C9
MATRSOKA_TAGS_CHAPTER_UID_ID = 0x63C4
MATRSOKA_TAGS_ATTACHMENT_UID_ID = 0x63C6
MATROSKA_SIMPLE_TAG_ID = 0x67C8
MATROSKA_TAG_NAME_ID = 0x45A3
MATROSKA_TAG_LANGUAGE_ID = 0x447A
MATROSKA_TAG_STRING_ID = 0x4487
MATROSKA_TAG_BINARY_ID = 0x4485
# See mkv spec for details:
# http://www.matroska.org/technical/specs/index.html
# Map to convert to well known codes
# http://haali.cs.msu.ru/mkv/codecs.pdf
FOURCCMap = {
'V_THEORA': 'THEO',
'V_SNOW': 'SNOW',
'V_MPEG4/ISO/ASP': 'MP4V',
'V_MPEG4/ISO/AVC': 'AVC1',
'A_AC3': 0x2000,
'A_MPEG/L3': 0x0055,
'A_MPEG/L2': 0x0050,
'A_MPEG/L1': 0x0050,
'A_DTS': 0x2001,
'A_PCM/INT/LIT': 0x0001,
'A_PCM/FLOAT/IEEE': 0x003,
'A_TTA1': 0x77a1,
'A_WAVPACK4': 0x5756,
'A_VORBIS': 0x6750,
'A_FLAC': 0xF1AC,
'A_AAC': 0x00ff,
'A_AAC/': 0x00ff
}
def matroska_date_to_datetime(date):
"""
Converts a date in Matroska's date format to a python datetime object.
Returns the given date string if it could not be converted.
"""
# From the specs:
# The fields with dates should have the following format: YYYY-MM-DD
# HH:MM:SS.MSS [...] To store less accuracy, you remove items starting
# from the right. To store only the year, you would use, "2004". To store
# a specific day such as May 1st, 2003, you would use "2003-05-01".
format = re.split(r'([-:. ])', '%Y-%m-%d %H:%M:%S.%f')
while format:
try:
return datetime.strptime(date, ''.join(format))
except ValueError:
format = format[:-2]
return date
def matroska_bps_to_bitrate(bps):
"""
Tries to convert a free-form bps string into a bitrate (bits per second).
"""
m = re.search('([\d.]+)\s*(\D.*)', bps)
if m:
bps, suffix = m.groups()
if 'kbit' in suffix:
return float(bps) * 1024
elif 'kbyte' in suffix:
return float(bps) * 1024 * 8
elif 'byte' in suffix:
return float(bps) * 8
elif 'bps' in suffix or 'bit' in suffix:
return float(bps)
if bps.replace('.', '').isdigit():
if float(bps) < 30000:
# Assume kilobits and convert to bps
return float(bps) * 1024
return float(bps)
# Used to convert the official matroska tag names (only lower-cased) to core
# attributes. tag name -> attr, filter
TAGS_MAP = {
# From Media core
u'title': ('title', None),
u'subtitle': ('caption', None),
u'comment': ('comment', None),
u'url': ('url', None),
u'artist': ('artist', None),
u'keywords': ('keywords', lambda s: [word.strip() for word in s.split(',')]),
u'composer_nationality': ('country', None),
u'date_released': ('datetime', None),
u'date_recorded': ('datetime', None),
u'date_written': ('datetime', None),
# From Video core
u'encoder': ('encoder', None),
u'bps': ('bitrate', matroska_bps_to_bitrate),
u'part_number': ('trackno', int),
u'total_parts': ('trackof', int),
u'copyright': ('copyright', None),
u'genre': ('genre', None),
u'actor': ('actors', None),
u'written_by': ('writer', None),
u'producer': ('producer', None),
u'production_studio': ('studio', None),
u'law_rating': ('rating', None),
u'summary': ('summary', None),
u'synopsis': ('synopsis', None),
}
class EbmlEntity:
"""
This is class that is responsible to handle one Ebml entity as described in
the Matroska/Ebml spec
"""
def __init__(self, inbuf):
# Compute the EBML id
# Set the CRC len to zero
self.crc_len = 0
# Now loop until we find an entity without CRC
try:
self.build_entity(inbuf)
except IndexError:
raise ParseError()
while self.get_id() == MATROSKA_CRC32_ID:
self.crc_len += self.get_total_len()
inbuf = inbuf[self.get_total_len():]
self.build_entity(inbuf)
def build_entity(self, inbuf):
self.compute_id(inbuf)
if self.id_len == 0:
log.error(u'EBML entity not found, bad file format')
raise ParseError()
self.entity_len, self.len_size = self.compute_len(inbuf[self.id_len:])
self.entity_data = inbuf[self.get_header_len() : self.get_total_len()]
self.ebml_length = self.entity_len
self.entity_len = min(len(self.entity_data), self.entity_len)
# if the data size is 8 or less, it could be a numeric value
self.value = 0
if self.entity_len <= 8:
for pos, shift in zip(range(self.entity_len), range((self.entity_len - 1) * 8, -1, -8)):
self.value |= ord(self.entity_data[pos]) << shift
def add_data(self, data):
maxlen = self.ebml_length - len(self.entity_data)
if maxlen <= 0:
return
self.entity_data += data[:maxlen]
self.entity_len = len(self.entity_data)
def compute_id(self, inbuf):
self.id_len = 0
if len(inbuf) < 1:
return 0
first = ord(inbuf[0])
if first & 0x80:
self.id_len = 1
self.entity_id = first
elif first & 0x40:
if len(inbuf) < 2:
return 0
self.id_len = 2
self.entity_id = ord(inbuf[0]) << 8 | ord(inbuf[1])
elif first & 0x20:
if len(inbuf) < 3:
return 0
self.id_len = 3
self.entity_id = (ord(inbuf[0]) << 16) | (ord(inbuf[1]) << 8) | \
(ord(inbuf[2]))
elif first & 0x10:
if len(inbuf) < 4:
return 0
self.id_len = 4
self.entity_id = (ord(inbuf[0]) << 24) | (ord(inbuf[1]) << 16) | \
(ord(inbuf[2]) << 8) | (ord(inbuf[3]))
self.entity_str = inbuf[0:self.id_len]
def compute_len(self, inbuf):
if not inbuf:
return 0, 0
i = num_ffs = 0
len_mask = 0x80
len = ord(inbuf[0])
while not len & len_mask:
i += 1
len_mask >>= 1
if i >= 8:
return 0, 0
len &= len_mask - 1
if len == len_mask - 1:
num_ffs += 1
for p in range(i):
len = (len << 8) | ord(inbuf[p + 1])
if len & 0xff == 0xff:
num_ffs += 1
if num_ffs == i + 1:
len = 0
return len, i + 1
def get_crc_len(self):
return self.crc_len
def get_value(self):
return self.value
def get_float_value(self):
if len(self.entity_data) == 4:
return unpack('!f', self.entity_data)[0]
elif len(self.entity_data) == 8:
return unpack('!d', self.entity_data)[0]
return 0.0
def get_data(self):
return self.entity_data
def get_utf8(self):
return unicode(self.entity_data, 'utf-8', 'replace')
def get_str(self):
return unicode(self.entity_data, 'ascii', 'replace')
def get_id(self):
return self.entity_id
def get_str_id(self):
return self.entity_str
def get_len(self):
return self.entity_len
def get_total_len(self):
return self.entity_len + self.id_len + self.len_size
def get_header_len(self):
return self.id_len + self.len_size
class Matroska(core.AVContainer):
"""
Matroska video and audio parser. If at least one video stream is
detected it will set the type to MEDIA_AV.
"""
def __init__(self, file):
core.AVContainer.__init__(self)
self.samplerate = 1
self.file = file
# Read enough that we're likely to get the full seekhead (FIXME: kludge)
buffer = file.read(2000)
if len(buffer) == 0:
# Regular File end
raise ParseError()
# Check the Matroska header
header = EbmlEntity(buffer)
if header.get_id() != MATROSKA_HEADER_ID:
raise ParseError()
log.debug(u'HEADER ID found %08X' % header.get_id())
self.mime = 'video/x-matroska'
self.type = 'Matroska'
self.has_idx = False
self.objects_by_uid = {}
# Now get the segment
self.segment = segment = EbmlEntity(buffer[header.get_total_len():])
# Record file offset of segment data for seekheads
self.segment.offset = header.get_total_len() + segment.get_header_len()
if segment.get_id() != MATROSKA_SEGMENT_ID:
log.debug(u'SEGMENT ID not found %08X' % segment.get_id())
return
log.debug(u'SEGMENT ID found %08X' % segment.get_id())
try:
for elem in self.process_one_level(segment):
if elem.get_id() == MATROSKA_SEEKHEAD_ID:
self.process_elem(elem)
except ParseError:
pass
if not self.has_idx:
log.warning(u'File has no index')
self._set('corrupt', True)
def process_elem(self, elem):
elem_id = elem.get_id()
log.debug(u'BEGIN: process element %r' % hex(elem_id))
if elem_id == MATROSKA_SEGMENT_INFO_ID:
duration = 0
scalecode = 1000000.0
for ielem in self.process_one_level(elem):
ielem_id = ielem.get_id()
if ielem_id == MATROSKA_TIMECODESCALE_ID:
scalecode = ielem.get_value()
elif ielem_id == MATROSKA_DURATION_ID:
duration = ielem.get_float_value()
elif ielem_id == MATROSKA_TITLE_ID:
self.title = ielem.get_utf8()
elif ielem_id == MATROSKA_DATE_UTC_ID:
timestamp = unpack('!q', ielem.get_data())[0] / 10.0 ** 9
# Date is offset 2001-01-01 00:00:00 (timestamp 978307200.0)
self.timestamp = int(timestamp + 978307200)
self.length = duration * scalecode / 1000000000.0
elif elem_id == MATROSKA_TRACKS_ID:
self.process_tracks(elem)
elif elem_id == MATROSKA_CHAPTERS_ID:
self.process_chapters(elem)
elif elem_id == MATROSKA_ATTACHMENTS_ID:
self.process_attachments(elem)
elif elem_id == MATROSKA_SEEKHEAD_ID:
self.process_seekhead(elem)
elif elem_id == MATROSKA_TAGS_ID:
self.process_tags(elem)
elif elem_id == MATROSKA_CUES_ID:
self.has_idx = True
log.debug(u'END: process element %r' % hex(elem_id))
return True
def process_seekhead(self, elem):
for seek_elem in self.process_one_level(elem):
if seek_elem.get_id() != MATROSKA_SEEK_ID:
continue
for sub_elem in self.process_one_level(seek_elem):
if sub_elem.get_id() == MATROSKA_SEEKID_ID:
if sub_elem.get_value() == MATROSKA_CLUSTER_ID:
# Not interested in these.
return
elif sub_elem.get_id() == MATROSKA_SEEK_POSITION_ID:
self.file.seek(self.segment.offset + sub_elem.get_value())
buffer = self.file.read(100)
try:
elem = EbmlEntity(buffer)
except ParseError:
continue
# Fetch all data necessary for this element.
elem.add_data(self.file.read(elem.ebml_length))
self.process_elem(elem)
def process_tracks(self, tracks):
tracksbuf = tracks.get_data()
index = 0
while index < tracks.get_len():
trackelem = EbmlEntity(tracksbuf[index:])
log.debug (u'ELEMENT %X found' % trackelem.get_id())
self.process_track(trackelem)
index += trackelem.get_total_len() + trackelem.get_crc_len()
def process_one_level(self, item):
buf = item.get_data()
index = 0
while index < item.get_len():
if len(buf[index:]) == 0:
break
elem = EbmlEntity(buf[index:])
yield elem
index += elem.get_total_len() + elem.get_crc_len()
def set_track_defaults(self, track):
track.language = 'eng'
def process_track(self, track):
# Collapse generator into a list since we need to iterate over it
# twice.
elements = [x for x in self.process_one_level(track)]
track_type = [x.get_value() for x in elements if x.get_id() == MATROSKA_TRACK_TYPE_ID]
if not track_type:
log.debug(u'Bad track: no type id found')
return
track_type = track_type[0]
track = None
if track_type == MATROSKA_VIDEO_TRACK:
log.debug(u'Video track found')
track = self.process_video_track(elements)
elif track_type == MATROSKA_AUDIO_TRACK:
log.debug(u'Audio track found')
track = self.process_audio_track(elements)
elif track_type == MATROSKA_SUBTITLES_TRACK:
log.debug(u'Subtitle track found')
track = core.Subtitle()
self.set_track_defaults(track)
track.id = len(self.subtitles)
self.subtitles.append(track)
for elem in elements:
self.process_track_common(elem, track)
def process_track_common(self, elem, track):
elem_id = elem.get_id()
if elem_id == MATROSKA_TRACK_LANGUAGE_ID:
track.language = elem.get_str()
log.debug(u'Track language found: %r' % track.language)
elif elem_id == MATROSKA_NAME_ID:
track.title = elem.get_utf8()
elif elem_id == MATROSKA_TRACK_NUMBER_ID:
track.trackno = elem.get_value()
elif elem_id == MATROSKA_TRACK_FLAG_ENABLED_ID:
track.enabled = bool(elem.get_value())
elif elem_id == MATROSKA_TRACK_FLAG_DEFAULT_ID:
track.default = bool(elem.get_value())
elif elem_id == MATROSKA_CODEC_ID:
track.codec = elem.get_str()
elif elem_id == MATROSKA_CODEC_PRIVATE_ID:
track.codec_private = elem.get_data()
elif elem_id == MATROSKA_TRACK_UID_ID:
self.objects_by_uid[elem.get_value()] = track
def process_video_track(self, elements):
track = core.VideoStream()
# Defaults
track.codec = u'Unknown'
track.fps = 0
self.set_track_defaults(track)
for elem in elements:
elem_id = elem.get_id()
if elem_id == MATROSKA_CODEC_ID:
track.codec = elem.get_str()
elif elem_id == MATROSKA_FRAME_DURATION_ID:
try:
track.fps = 1 / (pow(10, -9) * (elem.get_value()))
except ZeroDivisionError:
pass
elif elem_id == MATROSKA_VIDEO_SETTINGS_ID:
d_width = d_height = None
for settings_elem in self.process_one_level(elem):
settings_elem_id = settings_elem.get_id()
if settings_elem_id == MATROSKA_VIDEO_WIDTH_ID:
track.width = settings_elem.get_value()
elif settings_elem_id == MATROSKA_VIDEO_HEIGHT_ID:
track.height = settings_elem.get_value()
elif settings_elem_id == MATROSKA_VIDEO_DISPLAY_WIDTH_ID:
d_width = settings_elem.get_value()
elif settings_elem_id == MATROSKA_VIDEO_DISPLAY_HEIGHT_ID:
d_height = settings_elem.get_value()
elif settings_elem_id == MATROSKA_VIDEO_INTERLACED_ID:
value = int(settings_elem.get_value())
self._set('interlaced', value)
if None not in [d_width, d_height]:
track.aspect = float(d_width) / d_height
else:
self.process_track_common(elem, track)
# convert codec information
# http://haali.cs.msu.ru/mkv/codecs.pdf
if track.codec in FOURCCMap:
track.codec = FOURCCMap[track.codec]
elif '/' in track.codec and track.codec.split('/')[0] + '/' in FOURCCMap:
track.codec = FOURCCMap[track.codec.split('/')[0] + '/']
elif track.codec.endswith('FOURCC') and len(track.codec_private or '') == 40:
track.codec = track.codec_private[16:20]
elif track.codec.startswith('V_REAL/'):
track.codec = track.codec[7:]
elif track.codec.startswith('V_'):
# FIXME: add more video codecs here
track.codec = track.codec[2:]
track.id = len(self.video)
self.video.append(track)
return track
def process_audio_track(self, elements):
track = core.AudioStream()
track.codec = u'Unknown'
self.set_track_defaults(track)
for elem in elements:
elem_id = elem.get_id()
if elem_id == MATROSKA_CODEC_ID:
track.codec = elem.get_str()
elif elem_id == MATROSKA_AUDIO_SETTINGS_ID:
for settings_elem in self.process_one_level(elem):
settings_elem_id = settings_elem.get_id()
if settings_elem_id == MATROSKA_AUDIO_SAMPLERATE_ID:
track.samplerate = settings_elem.get_float_value()
elif settings_elem_id == MATROSKA_AUDIO_CHANNELS_ID:
track.channels = settings_elem.get_value()
else:
self.process_track_common(elem, track)
if track.codec in FOURCCMap:
track.codec = FOURCCMap[track.codec]
elif '/' in track.codec and track.codec.split('/')[0] + '/' in FOURCCMap:
track.codec = FOURCCMap[track.codec.split('/')[0] + '/']
elif track.codec.startswith('A_'):
track.codec = track.codec[2:]
track.id = len(self.audio)
self.audio.append(track)
return track
def process_chapters(self, chapters):
elements = self.process_one_level(chapters)
for elem in elements:
if elem.get_id() == MATROSKA_EDITION_ENTRY_ID:
buf = elem.get_data()
index = 0
while index < elem.get_len():
sub_elem = EbmlEntity(buf[index:])
if sub_elem.get_id() == MATROSKA_CHAPTER_ATOM_ID:
self.process_chapter_atom(sub_elem)
index += sub_elem.get_total_len() + sub_elem.get_crc_len()
def process_chapter_atom(self, atom):
elements = self.process_one_level(atom)
chap = core.Chapter()
for elem in elements:
elem_id = elem.get_id()
if elem_id == MATROSKA_CHAPTER_TIME_START_ID:
# Scale timecode to seconds (float)
chap.pos = elem.get_value() / 1000000 / 1000.0
elif elem_id == MATROSKA_CHAPTER_FLAG_ENABLED_ID:
chap.enabled = elem.get_value()
elif elem_id == MATROSKA_CHAPTER_DISPLAY_ID:
# Matroska supports multiple (chapter name, language) pairs for
# each chapter, so chapter names can be internationalized. This
# logic will only take the last one in the list.
for display_elem in self.process_one_level(elem):
if display_elem.get_id() == MATROSKA_CHAPTER_STRING_ID:
chap.name = display_elem.get_utf8()
elif elem_id == MATROSKA_CHAPTER_UID_ID:
self.objects_by_uid[elem.get_value()] = chap
log.debug(u'Chapter %r found', chap.name)
chap.id = len(self.chapters)
self.chapters.append(chap)
def process_attachments(self, attachments):
buf = attachments.get_data()
index = 0
while index < attachments.get_len():
elem = EbmlEntity(buf[index:])
if elem.get_id() == MATROSKA_ATTACHED_FILE_ID:
self.process_attachment(elem)
index += elem.get_total_len() + elem.get_crc_len()
def process_attachment(self, attachment):
elements = self.process_one_level(attachment)
name = desc = mimetype = ""
data = None
for elem in elements:
elem_id = elem.get_id()
if elem_id == MATROSKA_FILE_NAME_ID:
name = elem.get_utf8()
elif elem_id == MATROSKA_FILE_DESC_ID:
desc = elem.get_utf8()
elif elem_id == MATROSKA_FILE_MIME_TYPE_ID:
mimetype = elem.get_data()
elif elem_id == MATROSKA_FILE_DATA_ID:
data = elem.get_data()
# Right now we only support attachments that could be cover images.
# Make a guess to see if this attachment is a cover image.
if mimetype.startswith("image/") and u"cover" in (name + desc).lower() and data:
self.thumbnail = data
log.debug(u'Attachment %r found' % name)
def process_tags(self, tags):
# Tags spec: http://www.matroska.org/technical/specs/tagging/index.html
# Iterate over Tags children. Tags element children is a
# Tag element (whose children are SimpleTags) and a Targets element
# whose children specific what objects the tags apply to.
for tag_elem in self.process_one_level(tags):
# Start a new dict to hold all SimpleTag elements.
tags_dict = core.Tags()
# A list of target uids this tags dict applies too. If empty,
# tags are global.
targets = []
for sub_elem in self.process_one_level(tag_elem):
if sub_elem.get_id() == MATROSKA_SIMPLE_TAG_ID:
self.process_simple_tag(sub_elem, tags_dict)
elif sub_elem.get_id() == MATROSKA_TARGETS_ID:
# Targets element: if there is no uid child (track uid,
# chapter uid, etc.) then the tags dict applies to the
# whole file (top-level Media object).
for target_elem in self.process_one_level(sub_elem):
target_elem_id = target_elem.get_id()
if target_elem_id in (MATRSOKA_TAGS_TRACK_UID_ID, MATRSOKA_TAGS_EDITION_UID_ID,
MATRSOKA_TAGS_CHAPTER_UID_ID, MATRSOKA_TAGS_ATTACHMENT_UID_ID):
targets.append(target_elem.get_value())
elif target_elem_id == MATROSKA_TARGET_TYPE_VALUE_ID:
# Target types not supported for now. (Unclear how this
# would fit with kaa.metadata.)
pass
if targets:
# Assign tags to all listed uids
for target in targets:
try:
self.objects_by_uid[target].tags.update(tags_dict)
self.tags_to_attributes(self.objects_by_uid[target], tags_dict)
except KeyError:
log.warning(u'Tags assigned to unknown/unsupported target uid %d', target)
else:
self.tags.update(tags_dict)
self.tags_to_attributes(self, tags_dict)
def process_simple_tag(self, simple_tag_elem, tags_dict):
"""
Returns a dict representing the Tag element.
"""
name = lang = value = children = None
binary = False
for elem in self.process_one_level(simple_tag_elem):
elem_id = elem.get_id()
if elem_id == MATROSKA_TAG_NAME_ID:
name = elem.get_utf8().lower()
elif elem_id == MATROSKA_TAG_STRING_ID:
value = elem.get_utf8()
elif elem_id == MATROSKA_TAG_BINARY_ID:
value = elem.get_data()
binary = True
elif elem_id == MATROSKA_TAG_LANGUAGE_ID:
lang = elem.get_utf8()
elif elem_id == MATROSKA_SIMPLE_TAG_ID:
if children is None:
children = core.Tags()
self.process_simple_tag(elem, children)
if children:
# Convert ourselves to a Tags object.
children.value = value
children.langcode = lang
value = children
else:
if name.startswith('date_'):
# Try to convert date to a datetime object.
value = matroska_date_to_datetime(value)
value = core.Tag(value, lang, binary)
if name in tags_dict:
# Multiple items of this tag name.
if not isinstance(tags_dict[name], list):
# Convert to a list
tags_dict[name] = [tags_dict[name]]
# Append to list
tags_dict[name].append(value)
else:
tags_dict[name] = value
def tags_to_attributes(self, obj, tags):
# Convert tags to core attributes.
for name, tag in tags.items():
if isinstance(tag, dict):
# Nested tags dict, recurse.
self.tags_to_attributes(obj, tag)
continue
elif name not in TAGS_MAP:
continue
attr, filter = TAGS_MAP[name]
if attr not in obj._keys and attr not in self._keys:
# Tag is not in any core attribute for this object or global,
# so skip.
continue
# Pull value out of Tag object or list of Tag objects.
value = [item.value for item in tag] if isinstance(tag, list) else tag.value
if filter:
try:
value = [filter(item) for item in value] if isinstance(value, list) else filter(value)
except Exception, e:
log.warning(u'Failed to convert tag to core attribute: %r', e)
# Special handling for tv series recordings. The 'title' tag
# can be used for both the series and the episode name. The
# same is true for trackno which may refer to the season
# and the episode number. Therefore, if we find these
# attributes already set we try some guessing.
if attr == 'trackno' and getattr(self, attr) is not None:
# delete trackno and save season and episode
self.season = self.trackno
self.episode = value
self.trackno = None
continue
if attr == 'title' and getattr(self, attr) is not None:
# store current value of title as series and use current
# value of title as title
self.series = self.title
if attr in obj._keys:
setattr(obj, attr, value)
else:
setattr(self, attr, value)
Parser = Matroska
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
655,
3605,
278,
446,
15709,
3341,
1798,
199,
3,
1898,
7760,
13,
7409,
437,
29680,
1132,
23207,
1346,
665,
2391,
79,
7586,
352,
32,
6799,
14,
957,
30,
199,
3,
1898,
13004,
13,
7968,
27864,
22985,
310,
80,
28478,
665,
1207,
262,
32,
645,
77,
14,
1308,
30,
199,
3,
1898,
13004,
13,
7968,
25866,
75,
3194,
23009,
665,
2297,
13175,
32,
4624,
2392,
14,
1308,
30,
199,
3,
1898,
13004,
13,
7968,
1603,
2660,
377,
564,
371,
281,
651,
665,
13058,
32,
22776,
14,
696,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
655,
3605,
278,
14,
199,
3,
199,
3,
655,
3605,
278,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
655,
3605,
278,
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,
655,
3605,
278,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
504,
2197,
492,
2197,
199,
504,
4967,
492,
21743,
199,
504,
2702,
492,
7787,
199,
646,
6170,
199,
646,
2050,
199,
646,
295,
199,
199,
363,
452,
363,
275,
788,
2842,
418,
421,
199,
3,
664,
2050,
909,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3,
11298,
11449,
367,
314,
18619,
293,
1339,
65,
13788,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
19755,
275,
378,
88,
614,
199,
16996,
1092,
8656,
33,
63,
27743,
63,
19755,
275,
378,
88,
996,
199,
16996,
1092,
8656,
33,
63,
6348,
52,
649,
11344,
63,
19755,
275,
378,
88,
845,
199,
199,
16996,
1092,
8656,
33,
63,
7311,
63,
998,
275,
378,
88,
17,
33,
2322,
36,
2078,
19,
199,
16996,
1092,
8656,
33,
63,
19755,
51,
63,
998,
275,
378,
88,
975,
1477,
12500,
22,
34,
199,
16996,
1092,
8656,
33,
63,
35,
9318,
63,
998,
275,
378,
88,
17,
35,
2481,
5342,
22,
34,
199,
16996,
1092,
8656,
33,
63,
27001,
63,
998,
275,
378,
88,
1085,
2481,
1257,
1822,
199,
16996,
1092,
8656,
33,
63,
27001,
63,
4531,
63,
998,
275,
378,
88,
1046,
1887,
33,
30689,
199,
16996,
1092,
8656,
33,
63,
26340,
63,
998,
275,
378,
88,
17,
38,
2824,
34,
19895,
199,
16996,
1092,
8656,
33,
63,
17510,
63,
998,
275,
378,
88,
4220,
199,
16996,
1092,
8656,
33,
63,
29243,
63,
998,
275,
378,
8094,
38,
199,
16996,
1092,
8656,
33,
63,
4961,
15639,
13329,
37,
63,
998,
275,
378,
88,
18,
1554,
23,
34,
17,
199,
16996,
1092,
8656,
33,
63,
36,
15301,
63,
998,
275,
378,
88,
1602,
1407,
199,
16996,
1092,
8656,
33,
63,
29243,
708,
63,
998,
275,
378,
8094,
38,
199,
16996,
1092,
8656,
33,
63,
4961,
15639,
13329,
37,
63,
998,
275,
378,
88,
18,
1554,
23,
34,
17,
199,
16996,
1092,
8656,
33,
63,
45,
14272,
1206,
63,
7121,
63,
998,
275,
378,
88,
20,
36,
1257,
199,
16996,
1092,
8656,
33,
63,
6524,
649,
1206,
63,
7121,
63,
998,
275,
378,
88,
10950,
17,
199,
16996,
1092,
8656,
33,
63,
6012,
35,
63,
998,
275,
378,
88,
1184,
199,
16996,
1092,
8656,
33,
63,
6012,
35,
63,
18748,
63,
998,
275,
378,
88,
2766,
33,
18,
199,
16996,
1092,
8656,
33,
63,
12683,
63,
36,
15301,
63,
998,
275,
378,
88,
1789,
37,
15504,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
13931,
63,
998,
275,
378,
6991,
16,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
11139,
63,
998,
275,
378,
8094,
16,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
13509,
63,
998,
275,
378,
88,
4134,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
3843,
44,
1348,
1149,
63,
998,
275,
378,
88,
25,
33,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
20993,
63,
11139,
63,
998,
275,
378,
88,
1477,
34,
16,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
20993,
63,
13509,
63,
998,
275,
378,
88,
1477,
4134,
199,
16996,
1092,
8656,
33,
63,
27743,
63,
13931,
63,
998,
275,
378,
6991,
17,
199,
16996,
1092,
8656,
33,
63,
27743,
63,
51,
7855,
540,
1951,
63,
998,
275,
378,
8094,
21,
199,
16996,
1092,
8656,
33,
63,
27743,
63,
14833,
51,
63,
998,
275,
378,
88,
25,
38,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
6685,
63,
998,
275,
378,
88,
2898,
35,
21,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
9190,
63,
998,
275,
378,
8313,
23,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
2711,
63,
998,
275,
378,
88,
2658,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
13947,
63,
998,
275,
378,
88,
1081,
34,
1427,
35,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
14839,
275,
378,
88,
24416,
38,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
3719,
63,
3472,
63,
998,
275,
378,
88,
1299,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
3719,
63,
15704,
63,
998,
275,
378,
8094,
25,
199,
16996,
1092,
8656,
33,
63,
19091,
63,
998,
275,
378,
88,
23,
4134,
25,
199,
16996,
1092,
8656,
33,
63,
5390,
63,
11288,
63,
998,
275,
378,
88,
1602,
2976,
199,
16996,
1092,
8656,
33,
63,
2339,
63,
998,
275,
378,
88,
25839,
37,
199,
199,
16996,
1092,
8656,
33,
63,
1244,
1282,
1157,
51,
63,
998,
275,
378,
88,
709,
2824,
33,
17902,
199,
16996,
1092,
8656,
33,
63,
1244,
1282,
1157,
63,
6685,
63,
998,
275,
378,
88,
2898,
35,
20,
199,
16996,
1092,
8656,
33,
63,
1149,
12039,
63,
7285,
63,
998,
275,
378,
88,
2322,
34,
25,
199,
16996,
1092
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
655,
3605,
278,
446,
15709,
3341,
1798,
199,
3,
1898,
7760,
13,
7409,
437,
29680,
1132,
23207,
1346,
665,
2391,
79,
7586,
352,
32,
6799,
14,
957,
30,
199,
3,
1898,
13004,
13,
7968,
27864,
22985,
310,
80,
28478,
665,
1207,
262,
32,
645,
77,
14,
1308,
30,
199,
3,
1898,
13004,
13,
7968,
25866,
75,
3194,
23009,
665,
2297,
13175,
32,
4624,
2392,
14,
1308,
30,
199,
3,
1898,
13004,
13,
7968,
1603,
2660,
377,
564,
371,
281,
651,
665,
13058,
32,
22776,
14,
696,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
655,
3605,
278,
14,
199,
3,
199,
3,
655,
3605,
278,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
655,
3605,
278,
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,
655,
3605,
278,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
504,
2197,
492,
2197,
199,
504,
4967,
492,
21743,
199,
504,
2702,
492,
7787,
199,
646,
6170,
199,
646,
2050,
199,
646,
295,
199,
199,
363,
452,
363,
275,
788,
2842,
418,
421,
199,
3,
664,
2050,
909,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3,
11298,
11449,
367,
314,
18619,
293,
1339,
65,
13788,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
19755,
275,
378,
88,
614,
199,
16996,
1092,
8656,
33,
63,
27743,
63,
19755,
275,
378,
88,
996,
199,
16996,
1092,
8656,
33,
63,
6348,
52,
649,
11344,
63,
19755,
275,
378,
88,
845,
199,
199,
16996,
1092,
8656,
33,
63,
7311,
63,
998,
275,
378,
88,
17,
33,
2322,
36,
2078,
19,
199,
16996,
1092,
8656,
33,
63,
19755,
51,
63,
998,
275,
378,
88,
975,
1477,
12500,
22,
34,
199,
16996,
1092,
8656,
33,
63,
35,
9318,
63,
998,
275,
378,
88,
17,
35,
2481,
5342,
22,
34,
199,
16996,
1092,
8656,
33,
63,
27001,
63,
998,
275,
378,
88,
1085,
2481,
1257,
1822,
199,
16996,
1092,
8656,
33,
63,
27001,
63,
4531,
63,
998,
275,
378,
88,
1046,
1887,
33,
30689,
199,
16996,
1092,
8656,
33,
63,
26340,
63,
998,
275,
378,
88,
17,
38,
2824,
34,
19895,
199,
16996,
1092,
8656,
33,
63,
17510,
63,
998,
275,
378,
88,
4220,
199,
16996,
1092,
8656,
33,
63,
29243,
63,
998,
275,
378,
8094,
38,
199,
16996,
1092,
8656,
33,
63,
4961,
15639,
13329,
37,
63,
998,
275,
378,
88,
18,
1554,
23,
34,
17,
199,
16996,
1092,
8656,
33,
63,
36,
15301,
63,
998,
275,
378,
88,
1602,
1407,
199,
16996,
1092,
8656,
33,
63,
29243,
708,
63,
998,
275,
378,
8094,
38,
199,
16996,
1092,
8656,
33,
63,
4961,
15639,
13329,
37,
63,
998,
275,
378,
88,
18,
1554,
23,
34,
17,
199,
16996,
1092,
8656,
33,
63,
45,
14272,
1206,
63,
7121,
63,
998,
275,
378,
88,
20,
36,
1257,
199,
16996,
1092,
8656,
33,
63,
6524,
649,
1206,
63,
7121,
63,
998,
275,
378,
88,
10950,
17,
199,
16996,
1092,
8656,
33,
63,
6012,
35,
63,
998,
275,
378,
88,
1184,
199,
16996,
1092,
8656,
33,
63,
6012,
35,
63,
18748,
63,
998,
275,
378,
88,
2766,
33,
18,
199,
16996,
1092,
8656,
33,
63,
12683,
63,
36,
15301,
63,
998,
275,
378,
88,
1789,
37,
15504,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
13931,
63,
998,
275,
378,
6991,
16,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
11139,
63,
998,
275,
378,
8094,
16,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
13509,
63,
998,
275,
378,
88,
4134,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
3843,
44,
1348,
1149,
63,
998,
275,
378,
88,
25,
33,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
20993,
63,
11139,
63,
998,
275,
378,
88,
1477,
34,
16,
199,
16996,
1092,
8656,
33,
63,
20142,
63,
20993,
63,
13509,
63,
998,
275,
378,
88,
1477,
4134,
199,
16996,
1092,
8656,
33,
63,
27743,
63,
13931,
63,
998,
275,
378,
6991,
17,
199,
16996,
1092,
8656,
33,
63,
27743,
63,
51,
7855,
540,
1951,
63,
998,
275,
378,
8094,
21,
199,
16996,
1092,
8656,
33,
63,
27743,
63,
14833,
51,
63,
998,
275,
378,
88,
25,
38,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
6685,
63,
998,
275,
378,
88,
2898,
35,
21,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
9190,
63,
998,
275,
378,
8313,
23,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
2711,
63,
998,
275,
378,
88,
2658,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
13947,
63,
998,
275,
378,
88,
1081,
34,
1427,
35,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
14839,
275,
378,
88,
24416,
38,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
3719,
63,
3472,
63,
998,
275,
378,
88,
1299,
199,
16996,
1092,
8656,
33,
63,
19755,
63,
3719,
63,
15704,
63,
998,
275,
378,
8094,
25,
199,
16996,
1092,
8656,
33,
63,
19091,
63,
998,
275,
378,
88,
23,
4134,
25,
199,
16996,
1092,
8656,
33,
63,
5390,
63,
11288,
63,
998,
275,
378,
88,
1602,
2976,
199,
16996,
1092,
8656,
33,
63,
2339,
63,
998,
275,
378,
88,
25839,
37,
199,
199,
16996,
1092,
8656,
33,
63,
1244,
1282,
1157,
51,
63,
998,
275,
378,
88,
709,
2824,
33,
17902,
199,
16996,
1092,
8656,
33,
63,
1244,
1282,
1157,
63,
6685,
63,
998,
275,
378,
88,
2898,
35,
20,
199,
16996,
1092,
8656,
33,
63,
1149,
12039,
63,
7285,
63,
998,
275,
378,
88,
2322,
34,
25,
199,
16996,
1092,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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t; }
a { text-decoration:none; color:darkblue; }
a.line { position:relative; padding-top:300px; }
.comment { color:green; font-style:italic; }
.comment a { color:darkgreen; }
</style>
</head>
<body><pre><pre>"""
FOOTER="""</pre></body>"""
prefixes = [ 'fz_', 'pdf_', 'xps_', 'cbz_', 'pdfapp_' ]
def is_public(s):
for prefix in prefixes:
if s.startswith(prefix):
return True
return False
def load_tags():
tags = {}
for line in open("tags-xref").readlines():
ident, type, line, file, text = line.split(None, 4)
if not is_public(ident):
continue
if type == 'function':
tags[ident] = '<a class="function" href="%s#%s">%s</a>' % (os.path.basename(file), line, ident)
if type == 'typedef' or type == 'struct':
tags[ident] = '<a class="typedef" href="%s#%s">%s</a>' % (os.path.basename(file), line, ident)
return tags
tags = load_tags()
def quote(s):
return s.replace('&','&').replace('<','<').replace('>','>')
print HEADER
N = 1
for line in sys.stdin.readlines():
# expand tabs, html-quote special characters and colorize comments
line = line.replace('\t', ' ').rstrip()
line = quote(line)
line = line.replace("/*", '<span class="comment">/*')
line = line.replace("*/", '*/</span>')
line = re.sub('^#include "([a-z-]*\.h)"', '#include "<a href="\\1">\\1</a>"', line)
# find identifiers and hyperlink to their definitions
words = re.split("(\W+)", line)
line = ""
for word in words:
if word in tags:
word = tags[word]
line += word
#print('<a class="line" name="%d">%4d</a> %s' % (N, N, line))
print('<a class="line" name="%d"></a>%s' % (N, line))
N = N + 1
print FOOTER
|
agpl-3.0
|
[
646,
984,
12,
747,
12,
295,
199,
199,
7311,
11916,
28,
2993,
30,
199,
28,
2487,
30,
199,
2030,
469,
8020,
13,
2326,
15596,
4717,
70,
16,
27,
3164,
26,
8399,
27,
11042,
26,
975,
541,
27,
789,
199,
65,
469,
1318,
13,
6518,
425,
26,
3592,
27,
3164,
26,
13625,
6304,
27,
789,
199,
65,
14,
604,
469,
3421,
26,
6188,
27,
6273,
13,
2119,
26,
5863,
5326,
27,
789,
199,
14,
3349,
469,
3164,
26,
7731,
27,
5023,
13,
2487,
26,
21843,
27,
789,
199,
14,
3349,
282,
469,
3164,
26,
13625,
7731,
27,
789,
199,
1108,
2487,
30,
199,
1108,
2993,
30,
199,
28,
2030,
2535,
657,
2535,
657,
11193,
199,
199,
13046,
1157,
11916,
1108,
657,
2957,
2030,
11193,
199,
199,
14124,
275,
359,
283,
70,
90,
14474,
283,
5607,
14474,
283,
88,
1190,
14474,
283,
2894,
90,
14474,
283,
5607,
571,
8650,
1622,
199,
199,
318,
365,
63,
3455,
8,
83,
304,
199,
198,
509,
2403,
315,
13158,
26,
507,
198,
692,
308,
14,
2460,
8,
1861,
304,
686,
198,
1107,
715,
199,
198,
1107,
756,
199,
199,
318,
2248,
63,
2969,
837,
199,
198,
2969,
275,
1052,
199,
198,
509,
1004,
315,
1551,
480,
2969,
13,
31332,
3471,
9684,
837,
507,
198,
5425,
12,
730,
12,
1004,
12,
570,
12,
1318,
275,
1004,
14,
1294,
8,
403,
12,
841,
9,
507,
198,
692,
440,
365,
63,
3455,
8,
5425,
304,
686,
198,
6958,
507,
198,
692,
730,
508,
283,
1593,
356,
686,
198,
2969,
59,
5425,
61,
275,
2650,
65,
1021,
628,
1593,
2,
4369,
5961,
83,
25745,
83,
14423,
83,
1108,
65,
3524,
450,
334,
736,
14,
515,
14,
4846,
8,
493,
395,
1004,
12,
12893,
9,
507,
198,
692,
730,
508,
283,
9594,
7,
503,
730,
508,
283,
1820,
356,
686,
198,
2969,
59,
5425,
61,
275,
2650,
65,
1021,
628,
9594,
2,
4369,
5961,
83,
25745,
83,
14423,
83,
1108,
65,
3524,
450,
334,
736,
14,
515,
14,
4846,
8,
493,
395,
1004,
12,
12893,
9,
199,
198,
1107,
3762,
199,
199,
2969,
275,
2248,
63,
2969,
342,
199,
199,
318,
6313,
8,
83,
304,
199,
198,
1107,
308,
14,
1814,
20040,
1673,
6,
5282,
27,
1959,
1814,
4827,
1673,
6,
4116,
27,
1959,
1814,
16099,
1673,
6,
3308,
10784,
199,
199,
1361,
13053,
540,
199,
199,
46,
275,
413,
199,
509,
1004,
315,
984,
14,
6626,
14,
9684,
837,
199,
198,
3,
6544,
12187,
12,
3517,
13,
3513,
4539,
4110,
436,
31019,
6786,
199,
198,
604,
275,
1004,
14,
1814,
2258,
84,
297,
283,
259,
27274,
6735,
342,
199,
198,
604,
275,
6313,
8,
604,
9,
199,
198,
604,
275,
1004,
14,
1814,
4769,
14421,
2650,
3751,
1021,
628,
3349,
1743,
6331,
358,
199,
198,
604,
275,
1004,
14,
1814,
23124,
10665,
6438,
15,
1108,
3751,
5971,
421,
198,
604,
275,
295,
14,
954,
9097,
3,
2613,
298,
779,
65,
13,
90,
13,
3672,
4537,
72,
32691,
3943,
2613,
3886,
65,
4369,
628,
1103,
17,
1743,
1103,
17,
1108,
65,
4335,
297,
1004,
9,
421,
198,
3,
2342,
14154,
436,
10342,
1073,
370,
3932,
10269,
199,
198,
3148,
275,
295,
14,
1294,
480,
2961,
55,
11,
4186,
1004,
9,
199,
198,
604,
275,
3087,
199,
198,
509,
4349,
315,
5932,
26,
507,
198,
692,
4349,
315,
3762,
26,
686,
198,
1027,
275,
3762,
59,
1027,
61,
507,
198,
604,
847,
4349,
421,
198,
3,
1361,
4827,
65,
1021,
628,
604,
2,
536,
5961,
68,
14423,
20,
68,
1108,
65,
30,
450,
83,
7,
450,
334,
46,
12,
653,
12,
1004,
430,
199,
198,
1361,
4827,
65,
1021,
628,
604,
2,
536,
5961,
68,
10070,
65,
6598,
83,
7,
450,
334,
46,
12,
1004,
430,
421,
198,
46,
275,
653,
435,
413,
199,
199,
1361,
27704,
1157,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
984,
12,
747,
12,
295,
199,
199,
7311,
11916,
28,
2993,
30,
199,
28,
2487,
30,
199,
2030,
469,
8020,
13,
2326,
15596,
4717,
70,
16,
27,
3164,
26,
8399,
27,
11042,
26,
975,
541,
27,
789,
199,
65,
469,
1318,
13,
6518,
425,
26,
3592,
27,
3164,
26,
13625,
6304,
27,
789,
199,
65,
14,
604,
469,
3421,
26,
6188,
27,
6273,
13,
2119,
26,
5863,
5326,
27,
789,
199,
14,
3349,
469,
3164,
26,
7731,
27,
5023,
13,
2487,
26,
21843,
27,
789,
199,
14,
3349,
282,
469,
3164,
26,
13625,
7731,
27,
789,
199,
1108,
2487,
30,
199,
1108,
2993,
30,
199,
28,
2030,
2535,
657,
2535,
657,
11193,
199,
199,
13046,
1157,
11916,
1108,
657,
2957,
2030,
11193,
199,
199,
14124,
275,
359,
283,
70,
90,
14474,
283,
5607,
14474,
283,
88,
1190,
14474,
283,
2894,
90,
14474,
283,
5607,
571,
8650,
1622,
199,
199,
318,
365,
63,
3455,
8,
83,
304,
199,
198,
509,
2403,
315,
13158,
26,
507,
198,
692,
308,
14,
2460,
8,
1861,
304,
686,
198,
1107,
715,
199,
198,
1107,
756,
199,
199,
318,
2248,
63,
2969,
837,
199,
198,
2969,
275,
1052,
199,
198,
509,
1004,
315,
1551,
480,
2969,
13,
31332,
3471,
9684,
837,
507,
198,
5425,
12,
730,
12,
1004,
12,
570,
12,
1318,
275,
1004,
14,
1294,
8,
403,
12,
841,
9,
507,
198,
692,
440,
365,
63,
3455,
8,
5425,
304,
686,
198,
6958,
507,
198,
692,
730,
508,
283,
1593,
356,
686,
198,
2969,
59,
5425,
61,
275,
2650,
65,
1021,
628,
1593,
2,
4369,
5961,
83,
25745,
83,
14423,
83,
1108,
65,
3524,
450,
334,
736,
14,
515,
14,
4846,
8,
493,
395,
1004,
12,
12893,
9,
507,
198,
692,
730,
508,
283,
9594,
7,
503,
730,
508,
283,
1820,
356,
686,
198,
2969,
59,
5425,
61,
275,
2650,
65,
1021,
628,
9594,
2,
4369,
5961,
83,
25745,
83,
14423,
83,
1108,
65,
3524,
450,
334,
736,
14,
515,
14,
4846,
8,
493,
395,
1004,
12,
12893,
9,
199,
198,
1107,
3762,
199,
199,
2969,
275,
2248,
63,
2969,
342,
199,
199,
318,
6313,
8,
83,
304,
199,
198,
1107,
308,
14,
1814,
20040,
1673,
6,
5282,
27,
1959,
1814,
4827,
1673,
6,
4116,
27,
1959,
1814,
16099,
1673,
6,
3308,
10784,
199,
199,
1361,
13053,
540,
199,
199,
46,
275,
413,
199,
509,
1004,
315,
984,
14,
6626,
14,
9684,
837,
199,
198,
3,
6544,
12187,
12,
3517,
13,
3513,
4539,
4110,
436,
31019,
6786,
199,
198,
604,
275,
1004,
14,
1814,
2258,
84,
297,
283,
259,
27274,
6735,
342,
199,
198,
604,
275,
6313,
8,
604,
9,
199,
198,
604,
275,
1004,
14,
1814,
4769,
14421,
2650,
3751,
1021,
628,
3349,
1743,
6331,
358,
199,
198,
604,
275,
1004,
14,
1814,
23124,
10665,
6438,
15,
1108,
3751,
5971,
421,
198,
604,
275,
295,
14,
954,
9097,
3,
2613,
298,
779,
65,
13,
90,
13,
3672,
4537,
72,
32691,
3943,
2613,
3886,
65,
4369,
628,
1103,
17,
1743,
1103,
17,
1108,
65,
4335,
297,
1004,
9,
421,
198,
3,
2342,
14154,
436,
10342,
1073,
370,
3932,
10269,
199,
198,
3148,
275,
295,
14,
1294,
480,
2961,
55,
11,
4186,
1004,
9,
199,
198,
604,
275,
3087,
199,
198,
509,
4349,
315,
5932,
26,
507,
198,
692,
4349,
315,
3762,
26,
686,
198,
1027,
275,
3762,
59,
1027,
61,
507,
198,
604,
847,
4349,
421,
198,
3,
1361,
4827,
65,
1021,
628,
604,
2,
536,
5961,
68,
14423,
20,
68,
1108,
65,
30,
450,
83,
7,
450,
334,
46,
12,
653,
12,
1004,
430,
199,
198,
1361,
4827,
65,
1021,
628,
604,
2,
536,
5961,
68,
10070,
65,
6598,
83,
7,
450,
334,
46,
12,
1004,
430,
421,
198,
46,
275,
653,
435,
413,
199,
199,
1361,
27704,
1157,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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yright (c) 2011 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 glob
import os
import shutil
import stat
import sys
def usage():
print("""Usage: squashdir.py <dest-dir> <source-dir> ...
Basic tool to copy a directory heirarchy into a flat space.
This crawls an arbitrarily deep heirarchy of files and directories, and copies
each file into the destination directory. The destination file name will
include the relative path to the source file, with '^^' inserted between each
directory name.
The resulting directory can then be imported into the file manager test harness,
which will reconstitute the directory structure.
This is used to work around the fact that the FileList and File objects
presented by <input type=file multiple> do not allow users to recurse a
selected directory, nor do they provide information about directory structure.
""")
def status(msg):
sys.stderr.write(msg + '\n')
def scan_path(dest, src, path):
abs_src = os.path.join(src, path)
statinfo = os.stat(abs_src)
basename = os.path.basename(path)
if not stat.S_ISDIR(statinfo.st_mode):
newname = os.path.join(dest, path.replace('/', '^^'))
status(newname)
shutil.copyfile(abs_src, newname)
else:
for child_path in glob.glob(abs_src + '/*'):
scan_path(dest, src, child_path[len(src) + 1:])
def main():
if len(sys.argv) < 3 or sys.argv[1][0] == '-':
usage()
return 1
dest = sys.argv[1]
for src in sys.argv[2:]:
abs_src = os.path.abspath(src)
path = os.path.basename(abs_src)
abs_src = os.path.dirname(abs_src)
scan_path(dest, abs_src, path)
return 0
if __name__ == '__main__':
sys.exit(main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
5739,
199,
646,
747,
199,
646,
5145,
199,
646,
5672,
199,
646,
984,
199,
199,
318,
4503,
837,
523,
870,
4852,
7692,
26,
12345,
1119,
694,
14,
647,
665,
2614,
13,
694,
30,
665,
1365,
13,
694,
30,
2263,
199,
199,
6845,
4744,
370,
1331,
282,
2082,
946,
723,
1047,
89,
1901,
282,
6829,
4601,
14,
199,
199,
2765,
286,
1773,
478,
376,
601,
2075,
82,
11406,
13217,
946,
723,
1047,
89,
402,
1584,
436,
6602,
12,
436,
6866,
199,
10885,
570,
1901,
314,
5724,
2082,
14,
221,
710,
5724,
570,
536,
911,
199,
2613,
314,
3847,
931,
370,
314,
1350,
570,
12,
543,
283,
11871,
7,
11788,
3382,
1924,
199,
3619,
536,
14,
199,
199,
1918,
9183,
2082,
883,
2066,
506,
8439,
1901,
314,
570,
5256,
511,
20458,
12,
199,
6777,
911,
295,
1297,
390,
938,
314,
2082,
5523,
14,
199,
199,
2765,
365,
1202,
370,
1736,
6818,
314,
10572,
626,
314,
3814,
1296,
436,
3814,
2251,
199,
10317,
701,
665,
1210,
730,
29,
493,
3663,
30,
886,
440,
2040,
4390,
370,
18011,
282,
199,
5511,
2082,
12,
6590,
886,
2985,
5647,
2556,
3595,
2082,
5523,
14,
199,
6141,
421,
199,
318,
2004,
8,
1328,
304,
523,
984,
14,
3083,
14,
952,
8,
1328,
435,
1557,
78,
358,
421,
199,
318,
8000,
63,
515,
8,
2614,
12,
2928,
12,
931,
304,
523,
2853,
63,
2164,
275,
747,
14,
515,
14,
904,
8,
2164,
12,
931,
9,
523,
5672,
815,
275,
747,
14,
3736,
8,
2101,
63,
2164,
9,
819,
9593,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
819,
340,
440,
5672,
14,
51,
63,
1311,
3022,
8,
3736,
815,
14,
270,
63,
632,
304,
272,
26383,
275,
747,
14,
515,
14,
904,
8,
2614,
12,
931,
14,
1814,
10998,
283,
11871,
1333,
272,
2004,
8,
1222,
354,
9,
272,
5145,
14,
21997,
8,
2101,
63,
2164,
12,
26383,
9,
523,
587,
26,
272,
367,
1982,
63,
515,
315,
5739,
14,
6463,
8,
2101,
63,
2164,
435,
1994,
10,
735,
489,
8000,
63,
515,
8,
2614,
12,
2928,
12,
1982,
63,
515,
59,
552,
8,
2164,
9,
435,
413,
5728,
421,
199,
318,
2446,
837,
523,
340,
822,
8,
1274,
14,
3020,
9,
665,
650,
503,
984,
14,
3020,
59,
17,
1527,
16,
61,
508,
20905,
272,
4503,
342,
272,
372,
413,
819,
2053,
275,
984,
14,
3020,
59,
17,
61,
523,
367,
2928,
315,
984,
14,
3020,
59,
18,
10688,
272,
2853,
63,
2164,
275,
747,
14,
515,
14,
4832,
8,
2164,
9,
272,
931,
275,
747,
14,
515,
14,
4846,
8,
2101,
63,
2164,
9,
272,
2853,
63,
2164,
275,
747,
14,
515,
14,
3475,
8,
2101,
63,
2164,
9,
272,
8000,
63,
515,
8,
2614,
12,
2853,
63,
2164,
12,
931,
9,
523,
372,
378,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
5739,
199,
646,
747,
199,
646,
5145,
199,
646,
5672,
199,
646,
984,
199,
199,
318,
4503,
837,
523,
870,
4852,
7692,
26,
12345,
1119,
694,
14,
647,
665,
2614,
13,
694,
30,
665,
1365,
13,
694,
30,
2263,
199,
199,
6845,
4744,
370,
1331,
282,
2082,
946,
723,
1047,
89,
1901,
282,
6829,
4601,
14,
199,
199,
2765,
286,
1773,
478,
376,
601,
2075,
82,
11406,
13217,
946,
723,
1047,
89,
402,
1584,
436,
6602,
12,
436,
6866,
199,
10885,
570,
1901,
314,
5724,
2082,
14,
221,
710,
5724,
570,
536,
911,
199,
2613,
314,
3847,
931,
370,
314,
1350,
570,
12,
543,
283,
11871,
7,
11788,
3382,
1924,
199,
3619,
536,
14,
199,
199,
1918,
9183,
2082,
883,
2066,
506,
8439,
1901,
314,
570,
5256,
511,
20458,
12,
199,
6777,
911,
295,
1297,
390,
938,
314,
2082,
5523,
14,
199,
199,
2765,
365,
1202,
370,
1736,
6818,
314,
10572,
626,
314,
3814,
1296,
436,
3814,
2251,
199,
10317,
701,
665,
1210,
730,
29,
493,
3663,
30,
886,
440,
2040,
4390,
370,
18011,
282,
199,
5511,
2082,
12,
6590,
886,
2985,
5647,
2556,
3595,
2082,
5523,
14,
199,
6141,
421,
199,
318,
2004,
8,
1328,
304,
523,
984,
14,
3083,
14,
952,
8,
1328,
435,
1557,
78,
358,
421,
199,
318,
8000,
63,
515,
8,
2614,
12,
2928,
12,
931,
304,
523,
2853,
63,
2164,
275,
747,
14,
515,
14,
904,
8,
2164,
12,
931,
9,
523,
5672,
815,
275,
747,
14,
3736,
8,
2101,
63,
2164,
9,
819,
9593,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
819,
340,
440,
5672,
14,
51,
63,
1311,
3022,
8,
3736,
815,
14,
270,
63,
632,
304,
272,
26383,
275,
747,
14,
515,
14,
904,
8,
2614,
12,
931,
14,
1814,
10998,
283,
11871,
1333,
272,
2004,
8,
1222,
354,
9,
272,
5145,
14,
21997,
8,
2101,
63,
2164,
12,
26383,
9,
523,
587,
26,
272,
367,
1982,
63,
515,
315,
5739,
14,
6463,
8,
2101,
63,
2164,
435,
1994,
10,
735,
489,
8000,
63,
515,
8,
2614,
12,
2928,
12,
1982,
63,
515,
59,
552,
8,
2164,
9,
435,
413,
5728,
421,
199,
318,
2446,
837,
523,
340,
822,
8,
1274,
14,
3020,
9,
665,
650,
503,
984,
14,
3020,
59,
17,
1527,
16,
61,
508,
20905,
272,
4503,
342,
272,
372,
413,
819,
2053,
275,
984,
14,
3020,
59,
17,
61,
523,
367,
2928,
315,
984,
14,
3020,
59,
18,
10688,
272,
2853,
63,
2164,
275,
747,
14,
515,
14,
4832,
8,
2164,
9,
272,
931,
275,
747,
14,
515,
14,
4846,
8,
2101,
63,
2164,
9,
272,
2853,
63,
2164,
275,
747,
14,
515,
14,
3475,
8,
2101,
63,
2164,
9,
272,
8000,
63,
515,
8,
2614,
12,
2853,
63,
2164,
12,
931,
9,
523,
372,
378,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1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
silk/model_factory.py
|
1
|
10193
|
import json
import logging
import sys
import traceback
from django.core.urlresolvers import resolve
from silk import models
from silk.collector import DataCollector
from silk.config import SilkyConfig
Logger = logging.getLogger('silk')
content_types_json = ['application/json',
'application/x-javascript',
'text/javascript',
'text/x-javascript',
'text/x-json']
content_type_form = ['multipart/form-data',
'application/x-www-form-urlencoded']
content_type_html = ['text/html']
content_type_css = ['text/css']
def _parse_content_type(content_type):
"""best efforts on pulling out the content type and encoding from Content-Type header"""
try:
content_type = content_type.strip()
except AttributeError:
pass
char_set = None
if content_type.strip():
splt = content_type.split(';')
content_type = splt[0]
try:
raw_char_set = splt[1].strip()
key, char_set = raw_char_set.split('=')
if key != 'charset':
char_set = None
except (IndexError, ValueError):
pass
return content_type, char_set
class RequestModelFactory(object):
"""Produce Request models from Django request objects"""
def __init__(self, request):
super(RequestModelFactory, self).__init__()
self.request = request
def content_type(self):
content_type = self.request.META.get('CONTENT_TYPE', '')
return _parse_content_type(content_type)
def encoded_headers(self):
"""
From Django docs (https://docs.djangoproject.com/en/1.6/ref/request-response/#httprequest-objects):
"With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to
META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix
to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER."
"""
headers = {}
for k, v in self.request.META.items():
if k.startswith('HTTP') or k in ('CONTENT_TYPE', 'CONTENT_LENGTH'):
splt = k.split('_')
if splt[0] == 'HTTP':
splt = splt[1:]
k = '-'.join(splt)
headers[k] = v
if SilkyConfig().SILKY_HIDE_COOKIES:
try:
del headers['COOKIE']
except KeyError:
pass
return json.dumps(headers)
def _body(self, raw_body, content_type):
"""
Encode body as JSON if possible so can be used as a dictionary in generation
of curl/django test client code
"""
body = ''
if content_type in content_type_form:
body = self.request.POST
body = json.dumps(dict(body), sort_keys=True, indent=4)
elif content_type in content_types_json:
body = json.dumps(json.loads(raw_body), sort_keys=True, indent=4)
return body
def body(self):
content_type, char_set = self.content_type()
raw_body = self.request.body
if char_set:
try:
raw_body = raw_body.decode(char_set)
except AttributeError:
pass
except LookupError: # If no encoding exists, default to UTF-8
try:
raw_body = raw_body.decode('UTF-8')
except AttributeError:
pass
except Exception as e:
Logger.error('Unable to decode request body using char_set %s due to error: %s. Will ignore. Stacktrace:' % (char_set, e))
traceback.print_exc()
else:
# Default to an attempt at UTF-8 decoding.
try:
raw_body = raw_body.decode('UTF-8')
except AttributeError:
pass
max_size = SilkyConfig().SILKY_MAX_REQUEST_BODY_SIZE
body = ''
if raw_body:
if max_size > -1:
Logger.debug('A max request size is set so checking size')
size = sys.getsizeof(raw_body, default=None)
request_identifier = self.request.path
if not size:
Logger.error('No way in which to get size of request body for %s, will ignore it', request_identifier)
elif size <= max_size:
Logger.debug('Request %s has body of size %d which is less than %d so will save the body' % (request_identifier, size, max_size))
body = self._body(raw_body, content_type)
else:
Logger.debug('Request %s has body of size %d which is greater than %d, therefore ignoring' % (request_identifier, size, max_size))
raw_body = None
else:
Logger.debug('No maximum request body size is set, continuing.')
body = self._body(raw_body, content_type)
return body, raw_body
def query_params(self):
query_params = self.request.GET
encoded_query_params = ''
if query_params:
query_params_dict = dict(zip(query_params.keys(), query_params.values()))
encoded_query_params = json.dumps(query_params_dict)
return encoded_query_params
def construct_request_model(self):
body, raw_body = self.body()
query_params = self.query_params()
path = self.request.path
resolved = resolve(path)
namespace = resolved.namespace
view_name = resolved.url_name
if namespace:
view_name = namespace + ':' + view_name
request_model = models.Request.objects.create(
path=path,
encoded_headers=self.encoded_headers(),
method=self.request.method,
query_params=query_params,
view_name=view_name,
body=body)
# Text fields are encoded as UTF-8 in Django and hence will try to coerce
# anything to we pass to UTF-8. Some stuff like binary will fail.
try:
request_model.raw_body = raw_body
except UnicodeDecodeError:
Logger.debug('NYI: Binary request bodies') # TODO
Logger.debug('Created new request model with pk %s' % request_model.pk)
return request_model
class ResponseModelFactory(object):
"""given a response object, craft the silk response model"""
def __init__(self, response):
super(ResponseModelFactory, self).__init__()
self.response = response
self.request = DataCollector().request
def body(self):
body = ''
content_type, char_set = _parse_content_type(self.response.get('Content-Type', ''))
content = self.response.content
if char_set:
try:
content = content.decode(char_set)
except AttributeError:
pass
except LookupError: # If no encoding exists, default to UTF-8
try:
content = content.decode('UTF-8')
except AttributeError:
pass
except Exception as e:
Logger.error('Unable to decode response body using char_set %s due to error: %s. Will ignore. Stacktrace:' % (char_set, e))
traceback.print_exc()
else:
# Default to an attempt at UTF-8 decoding.
try:
content = content.decode('UTF-8')
except AttributeError:
pass
if content:
max_body_size = SilkyConfig().SILKY_MAX_RESPONSE_BODY_SIZE
if max_body_size > -1:
Logger.debug('Max size of response body defined so checking')
size = sys.getsizeof(content, None)
if not size:
Logger.error('Could not get size of response body. Ignoring')
content = ''
else:
if size > max_body_size:
content = ''
Logger.debug('Size of %d for %s is bigger than %d so ignoring response body' % (size, self.request.path, max_body_size))
else:
Logger.debug('Size of %d for %s is less than %d so saving response body' % (size, self.request.path, max_body_size))
if content_type in content_types_json:
# TODO: Perhaps theres a way to format the JSON without parsing it?
try:
body = json.dumps(json.loads(content), sort_keys=True, indent=4)
except (TypeError, ValueError):
Logger.warn('Response to request with pk %s has content type %s but was unable to parse it' % (self.request.pk, content_type))
return body, content
def construct_response_model(self):
assert self.request, 'Cant construct a response model if there is no request model'
Logger.debug('Creating response model for request model with pk %s' % self.request.pk)
b, content = self.body()
raw_headers = self.response._headers
headers = {}
for k, v in raw_headers.items():
try:
header, val = v
except ValueError:
header, val = k, v
finally:
headers[header] = val
silky_response = models.Response.objects.create(request=self.request,
status_code=self.response.status_code,
encoded_headers=json.dumps(headers),
body=b)
# Text fields are encoded as UTF-8 in Django and hence will try to coerce
# anything to we pass to UTF-8. Some stuff like binary will fail.
try:
silky_response.raw_body = content
except UnicodeDecodeError:
Logger.debug('NYI: Saving of binary response body') # TODO
return silky_response
|
mit
|
[
646,
2022,
199,
646,
2050,
199,
646,
984,
199,
646,
5190,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
7512,
199,
199,
504,
24968,
75,
492,
1709,
199,
504,
24968,
75,
14,
10946,
492,
3918,
12852,
199,
504,
24968,
75,
14,
888,
492,
428,
382,
10562,
2028,
421,
199,
4455,
275,
2050,
14,
5572,
360,
20329,
75,
358,
199,
199,
1317,
63,
1313,
63,
1001,
275,
788,
3578,
15,
1001,
297,
1993,
283,
3578,
15,
88,
13,
9554,
297,
1993,
283,
505,
15,
9554,
297,
1993,
283,
505,
15,
88,
13,
9554,
297,
1993,
283,
505,
15,
88,
13,
1001,
418,
199,
1317,
63,
466,
63,
964,
275,
788,
10123,
15,
964,
13,
576,
297,
2151,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
418,
199,
1317,
63,
466,
63,
1360,
275,
788,
505,
15,
1360,
418,
199,
1317,
63,
466,
63,
3919,
275,
788,
505,
15,
3919,
418,
421,
199,
318,
485,
1122,
63,
1317,
63,
466,
8,
1317,
63,
466,
304,
272,
408,
7010,
28058,
83,
641,
10299,
316,
734,
314,
1564,
730,
436,
2644,
687,
6646,
13,
804,
1406,
624,
272,
862,
26,
267,
1564,
63,
466,
275,
1564,
63,
466,
14,
1913,
342,
272,
871,
4281,
26,
267,
986,
272,
1495,
63,
409,
275,
488,
272,
340,
1564,
63,
466,
14,
1913,
837,
267,
308,
6003,
275,
1564,
63,
466,
14,
1294,
26468,
267,
1564,
63,
466,
275,
308,
6003,
59,
16,
61,
267,
862,
26,
288,
3066,
63,
1560,
63,
409,
275,
308,
6003,
59,
17,
1055,
1913,
342,
288,
790,
12,
1495,
63,
409,
275,
3066,
63,
1560,
63,
409,
14,
1294,
23917,
288,
340,
790,
1137,
283,
6043,
356,
355,
1495,
63,
409,
275,
488,
267,
871,
334,
12129,
12,
1722,
304,
288,
986,
272,
372,
1564,
63,
466,
12,
1495,
63,
409,
421,
199,
533,
4784,
1685,
2927,
8,
785,
304,
272,
408,
24391,
4784,
1709,
687,
5634,
1056,
2251,
624,
339,
347,
636,
826,
721,
277,
12,
1056,
304,
267,
1613,
8,
2017,
1685,
2927,
12,
291,
2843,
826,
4533,
267,
291,
14,
1069,
275,
1056,
339,
347,
1564,
63,
466,
8,
277,
304,
267,
1564,
63,
466,
275,
291,
14,
1069,
14,
10614,
14,
362,
360,
9663,
63,
2711,
297,
4074,
267,
372,
485,
1122,
63,
1317,
63,
466,
8,
1317,
63,
466,
9,
339,
347,
5737,
63,
2139,
8,
277,
304,
267,
408,
267,
11606,
5634,
9149,
334,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
1121,
15,
1069,
13,
1310,
12645,
16916,
26762,
13,
1462,
304,
398,
298,
3007,
314,
1919,
402,
29417,
63,
9127,
436,
29417,
63,
2711,
12,
465,
1627,
3432,
12,
1263,
3101,
2323,
315,
314,
1056,
787,
6702,
370,
267,
603,
15808,
2883,
701,
13806,
1006,
4110,
370,
22681,
12,
15810,
1263,
7188,
27920,
543,
23998,
436,
7791,
376,
3101,
63,
2403,
267,
370,
314,
536,
14,
2002,
12,
367,
2893,
12,
282,
1406,
2797,
1323,
13,
34,
13747,
3955,
506,
9994,
370,
314,
603,
15808,
790,
3101,
63,
56,
63,
34,
21951,
2122,
267,
408,
267,
2323,
275,
1052,
267,
367,
1022,
12,
373,
315,
291,
14,
1069,
14,
10614,
14,
1744,
837,
288,
340,
1022,
14,
2460,
360,
2856,
358,
503,
1022,
315,
661,
9663,
63,
2711,
297,
283,
9663,
63,
9127,
735,
355,
308,
6003,
275,
1022,
14,
1294,
26341,
355,
340,
308,
6003,
59,
16,
61,
508,
283,
2856,
356,
490,
308,
6003,
275,
308,
6003,
59,
17,
2938,
355,
1022,
275,
2475,
1370,
904,
8,
681,
4116,
9,
355,
2323,
59,
75,
61,
275,
373,
267,
340,
428,
382,
10562,
2028,
1252,
51,
1193,
32640,
63,
40,
11259,
63,
12189,
2563,
26,
288,
862,
26,
355,
2150,
2323,
459,
13665,
418,
288,
871,
4067,
26,
355,
986,
267,
372,
2022,
14,
4180,
8,
2139,
9,
339,
347,
485,
2030,
8,
277,
12,
3066,
63,
2030,
12,
1564,
63,
466,
304,
267,
408,
267,
19244,
2396,
465,
4840,
340,
3962,
880,
883,
506,
1202,
465,
282,
2600,
315,
10152,
267,
402,
26145,
15,
1176,
511,
1890,
1233,
267,
408,
267,
2396,
275,
2125,
267,
340,
1564,
63,
466,
315,
1564,
63,
466,
63,
964,
26,
288,
2396,
275,
291,
14,
1069,
14,
4030,
288,
2396,
275,
2022,
14,
4180,
8,
807,
8,
2030,
395,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
9,
267,
916,
1564,
63,
466,
315,
1564,
63,
1313,
63,
1001,
26,
288,
2396,
275,
2022,
14,
4180,
8,
1001,
14,
3640,
8,
1773,
63,
2030,
395,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
9,
267,
372,
2396,
339,
347,
2396,
8,
277,
304,
267,
1564,
63,
466,
12,
1495,
63,
409,
275,
291,
14,
1317,
63,
466,
342,
267,
3066,
63,
2030,
275,
291,
14,
1069,
14,
2030,
267,
340,
1495,
63,
409,
26,
288,
862,
26,
355,
3066,
63,
2030,
275,
3066,
63,
2030,
14,
2708,
8,
1560,
63,
409,
9,
288,
871,
4281,
26,
355,
986,
288,
871,
19021,
26,
221,
327,
982,
949,
2644,
3495,
12,
849,
370,
9094,
13,
24,
355,
862,
26,
490,
3066,
63,
2030,
275,
3066,
63,
2030,
14,
2708,
360,
6610,
13,
24,
358,
355,
871,
4281,
26,
490,
986,
288,
871,
2186,
465,
325,
26,
355,
15996,
14,
705,
360,
6005,
370,
4849,
1056,
2396,
1808,
1495,
63,
409,
450,
83,
7037,
370,
1125,
26,
450,
83,
14,
12823,
3686,
14,
13894,
3446,
4881,
450,
334,
1560,
63,
409,
12,
325,
430,
355,
5190,
14,
1361,
63,
2804,
342,
267,
587,
26,
288,
327,
3758,
370,
376,
7427,
737,
9094,
13,
24,
15952,
14,
288,
862,
26,
355,
3066,
63,
2030,
275,
3066,
63,
2030,
14,
2708,
360,
6610,
13,
24,
358,
288,
871,
4281,
26,
355,
986,
267,
1390,
63,
890,
275,
428,
382,
10562,
2028,
1252,
51,
1193,
32640,
63,
4283,
63,
6780,
63,
23708,
63,
4305,
267,
2396,
275,
2125,
267,
340,
3066,
63,
2030,
26,
288,
340,
1390,
63,
890,
690,
446,
17,
26,
355,
15996,
14,
1757,
360,
33,
1390,
1056,
1568,
365,
663,
880,
7907,
1568,
358,
355,
1568,
275,
984,
14,
362,
12590,
8,
1773,
63,
2030,
12,
849,
29,
403,
9
] |
[
2022,
199,
646,
2050,
199,
646,
984,
199,
646,
5190,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
7512,
199,
199,
504,
24968,
75,
492,
1709,
199,
504,
24968,
75,
14,
10946,
492,
3918,
12852,
199,
504,
24968,
75,
14,
888,
492,
428,
382,
10562,
2028,
421,
199,
4455,
275,
2050,
14,
5572,
360,
20329,
75,
358,
199,
199,
1317,
63,
1313,
63,
1001,
275,
788,
3578,
15,
1001,
297,
1993,
283,
3578,
15,
88,
13,
9554,
297,
1993,
283,
505,
15,
9554,
297,
1993,
283,
505,
15,
88,
13,
9554,
297,
1993,
283,
505,
15,
88,
13,
1001,
418,
199,
1317,
63,
466,
63,
964,
275,
788,
10123,
15,
964,
13,
576,
297,
2151,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
418,
199,
1317,
63,
466,
63,
1360,
275,
788,
505,
15,
1360,
418,
199,
1317,
63,
466,
63,
3919,
275,
788,
505,
15,
3919,
418,
421,
199,
318,
485,
1122,
63,
1317,
63,
466,
8,
1317,
63,
466,
304,
272,
408,
7010,
28058,
83,
641,
10299,
316,
734,
314,
1564,
730,
436,
2644,
687,
6646,
13,
804,
1406,
624,
272,
862,
26,
267,
1564,
63,
466,
275,
1564,
63,
466,
14,
1913,
342,
272,
871,
4281,
26,
267,
986,
272,
1495,
63,
409,
275,
488,
272,
340,
1564,
63,
466,
14,
1913,
837,
267,
308,
6003,
275,
1564,
63,
466,
14,
1294,
26468,
267,
1564,
63,
466,
275,
308,
6003,
59,
16,
61,
267,
862,
26,
288,
3066,
63,
1560,
63,
409,
275,
308,
6003,
59,
17,
1055,
1913,
342,
288,
790,
12,
1495,
63,
409,
275,
3066,
63,
1560,
63,
409,
14,
1294,
23917,
288,
340,
790,
1137,
283,
6043,
356,
355,
1495,
63,
409,
275,
488,
267,
871,
334,
12129,
12,
1722,
304,
288,
986,
272,
372,
1564,
63,
466,
12,
1495,
63,
409,
421,
199,
533,
4784,
1685,
2927,
8,
785,
304,
272,
408,
24391,
4784,
1709,
687,
5634,
1056,
2251,
624,
339,
347,
636,
826,
721,
277,
12,
1056,
304,
267,
1613,
8,
2017,
1685,
2927,
12,
291,
2843,
826,
4533,
267,
291,
14,
1069,
275,
1056,
339,
347,
1564,
63,
466,
8,
277,
304,
267,
1564,
63,
466,
275,
291,
14,
1069,
14,
10614,
14,
362,
360,
9663,
63,
2711,
297,
4074,
267,
372,
485,
1122,
63,
1317,
63,
466,
8,
1317,
63,
466,
9,
339,
347,
5737,
63,
2139,
8,
277,
304,
267,
408,
267,
11606,
5634,
9149,
334,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
22,
15,
1121,
15,
1069,
13,
1310,
12645,
16916,
26762,
13,
1462,
304,
398,
298,
3007,
314,
1919,
402,
29417,
63,
9127,
436,
29417,
63,
2711,
12,
465,
1627,
3432,
12,
1263,
3101,
2323,
315,
314,
1056,
787,
6702,
370,
267,
603,
15808,
2883,
701,
13806,
1006,
4110,
370,
22681,
12,
15810,
1263,
7188,
27920,
543,
23998,
436,
7791,
376,
3101,
63,
2403,
267,
370,
314,
536,
14,
2002,
12,
367,
2893,
12,
282,
1406,
2797,
1323,
13,
34,
13747,
3955,
506,
9994,
370,
314,
603,
15808,
790,
3101,
63,
56,
63,
34,
21951,
2122,
267,
408,
267,
2323,
275,
1052,
267,
367,
1022,
12,
373,
315,
291,
14,
1069,
14,
10614,
14,
1744,
837,
288,
340,
1022,
14,
2460,
360,
2856,
358,
503,
1022,
315,
661,
9663,
63,
2711,
297,
283,
9663,
63,
9127,
735,
355,
308,
6003,
275,
1022,
14,
1294,
26341,
355,
340,
308,
6003,
59,
16,
61,
508,
283,
2856,
356,
490,
308,
6003,
275,
308,
6003,
59,
17,
2938,
355,
1022,
275,
2475,
1370,
904,
8,
681,
4116,
9,
355,
2323,
59,
75,
61,
275,
373,
267,
340,
428,
382,
10562,
2028,
1252,
51,
1193,
32640,
63,
40,
11259,
63,
12189,
2563,
26,
288,
862,
26,
355,
2150,
2323,
459,
13665,
418,
288,
871,
4067,
26,
355,
986,
267,
372,
2022,
14,
4180,
8,
2139,
9,
339,
347,
485,
2030,
8,
277,
12,
3066,
63,
2030,
12,
1564,
63,
466,
304,
267,
408,
267,
19244,
2396,
465,
4840,
340,
3962,
880,
883,
506,
1202,
465,
282,
2600,
315,
10152,
267,
402,
26145,
15,
1176,
511,
1890,
1233,
267,
408,
267,
2396,
275,
2125,
267,
340,
1564,
63,
466,
315,
1564,
63,
466,
63,
964,
26,
288,
2396,
275,
291,
14,
1069,
14,
4030,
288,
2396,
275,
2022,
14,
4180,
8,
807,
8,
2030,
395,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
9,
267,
916,
1564,
63,
466,
315,
1564,
63,
1313,
63,
1001,
26,
288,
2396,
275,
2022,
14,
4180,
8,
1001,
14,
3640,
8,
1773,
63,
2030,
395,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
9,
267,
372,
2396,
339,
347,
2396,
8,
277,
304,
267,
1564,
63,
466,
12,
1495,
63,
409,
275,
291,
14,
1317,
63,
466,
342,
267,
3066,
63,
2030,
275,
291,
14,
1069,
14,
2030,
267,
340,
1495,
63,
409,
26,
288,
862,
26,
355,
3066,
63,
2030,
275,
3066,
63,
2030,
14,
2708,
8,
1560,
63,
409,
9,
288,
871,
4281,
26,
355,
986,
288,
871,
19021,
26,
221,
327,
982,
949,
2644,
3495,
12,
849,
370,
9094,
13,
24,
355,
862,
26,
490,
3066,
63,
2030,
275,
3066,
63,
2030,
14,
2708,
360,
6610,
13,
24,
358,
355,
871,
4281,
26,
490,
986,
288,
871,
2186,
465,
325,
26,
355,
15996,
14,
705,
360,
6005,
370,
4849,
1056,
2396,
1808,
1495,
63,
409,
450,
83,
7037,
370,
1125,
26,
450,
83,
14,
12823,
3686,
14,
13894,
3446,
4881,
450,
334,
1560,
63,
409,
12,
325,
430,
355,
5190,
14,
1361,
63,
2804,
342,
267,
587,
26,
288,
327,
3758,
370,
376,
7427,
737,
9094,
13,
24,
15952,
14,
288,
862,
26,
355,
3066,
63,
2030,
275,
3066,
63,
2030,
14,
2708,
360,
6610,
13,
24,
358,
288,
871,
4281,
26,
355,
986,
267,
1390,
63,
890,
275,
428,
382,
10562,
2028,
1252,
51,
1193,
32640,
63,
4283,
63,
6780,
63,
23708,
63,
4305,
267,
2396,
275,
2125,
267,
340,
3066,
63,
2030,
26,
288,
340,
1390,
63,
890,
690,
446,
17,
26,
355,
15996,
14,
1757,
360,
33,
1390,
1056,
1568,
365,
663,
880,
7907,
1568,
358,
355,
1568,
275,
984,
14,
362,
12590,
8,
1773,
63,
2030,
12,
849,
29,
403,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nathandaddio/puzzle_app
|
puzzle_app/puzzle_app/tests/schemas/test_hitori_schemas.py
|
1
|
1692
|
import pytest
from marshmallow import ValidationError
from puzzle_app.schemas.hitori import (
HitoriGameBoardCellSchema,
HitoriGameBoardSchema,
HitoriSolveSchema
)
def _new_dict_without_keys(dictionary, keys):
new_dict = dict(dictionary)
for key in keys:
del new_dict[key]
return new_dict
class TestHitoriGameBoardCellSchema:
_data = {
'id': 1,
'row_number': 2,
'column_number': 3,
'value': 5,
'included_in_solution': True
}
@pytest.fixture
def data(self):
return self._data
def test_schema_loads_data(self, data):
output_data = HitoriGameBoardCellSchema(strict=True).load(data).data
assert output_data == data
def test_schema_dumps_data(self, data):
output_data = HitoriGameBoardCellSchema(strict=True).dump(data).data
assert output_data == data
bad_data = [
{},
{
'row_number': 2,
'column_number': 3,
'value': 5,
'included_in_solution': True
},
dict(_data, id=-1),
dict(_data, row_number=-5),
dict(_data, column_number=-50),
dict(_data, value=-5),
_new_dict_without_keys(_data, ['id']),
_new_dict_without_keys(_data, ['row_number']),
_new_dict_without_keys(_data, ['column_number']),
_new_dict_without_keys(_data, ['value'])
]
@pytest.mark.parametrize('bad_data', bad_data)
def test_bad_data_raises_validation_error(self, bad_data):
with pytest.raises(ValidationError):
HitoriGameBoardCellSchema(strict=True).load(bad_data)
class TestHitoriGameBoardSchema:
pass
|
mit
|
[
646,
4613,
421,
199,
504,
7557,
609,
2174,
674,
492,
8505,
421,
199,
504,
18848,
17622,
63,
571,
14,
9482,
14,
72,
4330,
73,
492,
334,
272,
869,
4330,
73,
11454,
18995,
8108,
6700,
12,
272,
869,
4330,
73,
11454,
18995,
6700,
12,
272,
869,
4330,
73,
51,
3344,
6700,
199,
9,
421,
199,
318,
485,
1222,
63,
807,
63,
7395,
63,
1612,
8,
9086,
12,
2883,
304,
272,
892,
63,
807,
275,
1211,
8,
9086,
9,
272,
367,
790,
315,
2883,
26,
267,
2150,
892,
63,
807,
59,
498,
61,
272,
372,
892,
63,
807,
421,
199,
533,
1379,
40,
4330,
73,
11454,
18995,
8108,
6700,
26,
272,
485,
576,
275,
469,
267,
283,
344,
356,
413,
12,
267,
283,
1143,
63,
1955,
356,
499,
12,
267,
283,
2301,
63,
1955,
356,
650,
12,
267,
283,
585,
356,
959,
12,
267,
283,
12409,
63,
262,
63,
14458,
356,
715,
272,
789,
339,
768,
4462,
14,
5997,
272,
347,
666,
8,
277,
304,
267,
372,
291,
423,
576,
339,
347,
511,
63,
3629,
63,
3640,
63,
576,
8,
277,
12,
666,
304,
267,
1072,
63,
576,
275,
869,
4330,
73,
11454,
18995,
8108,
6700,
8,
4768,
29,
549,
680,
912,
8,
576,
680,
576,
398,
702,
1072,
63,
576,
508,
666,
339,
347,
511,
63,
3629,
63,
4180,
63,
576,
8,
277,
12,
666,
304,
267,
1072,
63,
576,
275,
869,
4330,
73,
11454,
18995,
8108,
6700,
8,
4768,
29,
549,
680,
2724,
8,
576,
680,
576,
267,
702,
1072,
63,
576,
508,
666,
339,
4875,
63,
576,
275,
359,
267,
5479,
267,
469,
288,
283,
1143,
63,
1955,
356,
499,
12,
288,
283,
2301,
63,
1955,
356,
650,
12,
288,
283,
585,
356,
959,
12,
288,
283,
12409,
63,
262,
63,
14458,
356,
715,
267,
1660,
267,
1211,
1547,
576,
12,
1305,
4022,
17,
395,
267,
1211,
1547,
576,
12,
1962,
63,
1955,
4022,
21,
395,
267,
1211,
1547,
576,
12,
2763,
63,
1955,
4022,
1400,
395,
267,
1211,
1547,
576,
12,
574,
4022,
21,
395,
267,
485,
1222,
63,
807,
63,
7395,
63,
1612,
1547,
576,
12,
788,
344,
3815,
267,
485,
1222,
63,
807,
63,
7395,
63,
1612,
1547,
576,
12,
788,
1143,
63,
1955,
3815,
267,
485,
1222,
63,
807,
63,
7395,
63,
1612,
1547,
576,
12,
788,
2301,
63,
1955,
3815,
267,
485,
1222,
63,
807,
63,
7395,
63,
1612,
1547,
576,
12,
788,
585,
1105,
272,
1622,
339,
768,
4462,
14,
1657,
14,
10396,
360,
4087,
63,
576,
297,
4875,
63,
576,
9,
272,
347,
511,
63,
4087,
63,
576,
63,
3536,
63,
6136,
63,
705,
8,
277,
12,
4875,
63,
576,
304,
267,
543,
4613,
14,
3536,
8,
8172,
304,
288,
869,
4330,
73,
11454,
18995,
8108,
6700,
8,
4768,
29,
549,
680,
912,
8,
4087,
63,
576,
9,
421,
199,
533,
1379,
40,
4330,
73,
11454,
18995,
6700,
26,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4613,
421,
199,
504,
7557,
609,
2174,
674,
492,
8505,
421,
199,
504,
18848,
17622,
63,
571,
14,
9482,
14,
72,
4330,
73,
492,
334,
272,
869,
4330,
73,
11454,
18995,
8108,
6700,
12,
272,
869,
4330,
73,
11454,
18995,
6700,
12,
272,
869,
4330,
73,
51,
3344,
6700,
199,
9,
421,
199,
318,
485,
1222,
63,
807,
63,
7395,
63,
1612,
8,
9086,
12,
2883,
304,
272,
892,
63,
807,
275,
1211,
8,
9086,
9,
272,
367,
790,
315,
2883,
26,
267,
2150,
892,
63,
807,
59,
498,
61,
272,
372,
892,
63,
807,
421,
199,
533,
1379,
40,
4330,
73,
11454,
18995,
8108,
6700,
26,
272,
485,
576,
275,
469,
267,
283,
344,
356,
413,
12,
267,
283,
1143,
63,
1955,
356,
499,
12,
267,
283,
2301,
63,
1955,
356,
650,
12,
267,
283,
585,
356,
959,
12,
267,
283,
12409,
63,
262,
63,
14458,
356,
715,
272,
789,
339,
768,
4462,
14,
5997,
272,
347,
666,
8,
277,
304,
267,
372,
291,
423,
576,
339,
347,
511,
63,
3629,
63,
3640,
63,
576,
8,
277,
12,
666,
304,
267,
1072,
63,
576,
275,
869,
4330,
73,
11454,
18995,
8108,
6700,
8,
4768,
29,
549,
680,
912,
8,
576,
680,
576,
398,
702,
1072,
63,
576,
508,
666,
339,
347,
511,
63,
3629,
63,
4180,
63,
576,
8,
277,
12,
666,
304,
267,
1072,
63,
576,
275,
869,
4330,
73,
11454,
18995,
8108,
6700,
8,
4768,
29,
549,
680,
2724,
8,
576,
680,
576,
267,
702,
1072,
63,
576,
508,
666,
339,
4875,
63,
576,
275,
359,
267,
5479,
267,
469,
288,
283,
1143,
63,
1955,
356,
499,
12,
288,
283,
2301,
63,
1955,
356,
650,
12,
288,
283,
585,
356,
959,
12,
288,
283,
12409,
63,
262,
63,
14458,
356,
715,
267,
1660,
267,
1211,
1547,
576,
12,
1305,
4022,
17,
395,
267,
1211,
1547,
576,
12,
1962,
63,
1955,
4022,
21,
395,
267,
1211,
1547,
576,
12,
2763,
63,
1955,
4022,
1400,
395,
267,
1211,
1547,
576,
12,
574,
4022,
21,
395,
267,
485,
1222,
63,
807,
63,
7395,
63,
1612,
1547,
576,
12,
788,
344,
3815,
267,
485,
1222,
63,
807,
63,
7395,
63,
1612,
1547,
576,
12,
788,
1143,
63,
1955,
3815,
267,
485,
1222,
63,
807,
63,
7395,
63,
1612,
1547,
576,
12,
788,
2301,
63,
1955,
3815,
267,
485,
1222,
63,
807,
63,
7395,
63,
1612,
1547,
576,
12,
788,
585,
1105,
272,
1622,
339,
768,
4462,
14,
1657,
14,
10396,
360,
4087,
63,
576,
297,
4875,
63,
576,
9,
272,
347,
511,
63,
4087,
63,
576,
63,
3536,
63,
6136,
63,
705,
8,
277,
12,
4875,
63,
576,
304,
267,
543,
4613,
14,
3536,
8,
8172,
304,
288,
869,
4330,
73,
11454,
18995,
8108,
6700,
8,
4768,
29,
549,
680,
912,
8,
4087,
63,
576,
9,
421,
199,
533,
1379,
40,
4330,
73,
11454,
18995,
6700,
26,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
HeatherHillers/RoamMac
|
tests/test_featurecursor.py
|
3
|
1233
|
import pytest
from mock import Mock
from roam.infodock import FeatureCursor, NoFeature
import tests.objects
layer = tests.objects.newmemorylayer()
layer = tests.objects.addfeaturestolayer(layer, 2)
features = layer.getFeatures()
featureone = features.next()
featuretwo = features.next()
@pytest.fixture
def cursor():
return FeatureCursor(layer=layer, features=[featureone, featuretwo])
def test_should_start_at_index_0(cursor):
assert cursor.index == 0
def test_next_should_move_index(cursor):
cursor.next()
assert cursor.index == 1
def test_next_should_wrap_to_start_when_on_last(cursor):
last = len(cursor.features) - 1
cursor.index = last
assert cursor.index == last
cursor.next()
assert cursor.index == 0
def test_back_should_wrap_to_end_when_on_first(cursor):
last = len(cursor.features) - 1
assert cursor.index == 0
cursor.back()
assert cursor.index == last
def test_should_return_feature_at_index(cursor):
assert cursor.feature.id() == featureone.id()
cursor.next()
assert cursor.feature.id() == featuretwo.id()
def test_should_raise_no_feature_on_invalid_index(cursor):
cursor.index = 99
with pytest.raises(NoFeature):
cursor.feature
|
gpl-2.0
|
[
646,
4613,
199,
504,
1683,
492,
4420,
199,
199,
504,
882,
455,
14,
4904,
364,
766,
492,
13407,
8993,
12,
3091,
5968,
199,
199,
646,
2295,
14,
1462,
199,
199,
1897,
275,
2295,
14,
1462,
14,
1222,
4844,
1897,
342,
199,
1897,
275,
2295,
14,
1462,
14,
525,
4445,
270,
393,
1187,
281,
8,
1897,
12,
499,
9,
199,
199,
3179,
275,
4045,
14,
362,
10807,
342,
199,
4445,
368,
275,
4534,
14,
2184,
342,
199,
4445,
5601,
275,
4534,
14,
2184,
342,
199,
199,
32,
4462,
14,
5997,
199,
318,
3920,
837,
272,
372,
13407,
8993,
8,
1897,
29,
1897,
12,
4534,
1524,
4445,
368,
12,
3878,
5601,
566,
199,
199,
318,
511,
63,
5626,
63,
928,
63,
292,
63,
1080,
63,
16,
8,
3937,
304,
272,
702,
3920,
14,
1080,
508,
378,
199,
199,
318,
511,
63,
2184,
63,
5626,
63,
1185,
63,
1080,
8,
3937,
304,
272,
3920,
14,
2184,
342,
272,
702,
3920,
14,
1080,
508,
413,
199,
199,
318,
511,
63,
2184,
63,
5626,
63,
3823,
63,
475,
63,
928,
63,
6526,
63,
265,
63,
2019,
8,
3937,
304,
272,
2061,
275,
822,
8,
3937,
14,
3179,
9,
446,
413,
272,
3920,
14,
1080,
275,
2061,
272,
702,
3920,
14,
1080,
508,
2061,
272,
3920,
14,
2184,
342,
272,
702,
3920,
14,
1080,
508,
378,
199,
199,
318,
511,
63,
894,
63,
5626,
63,
3823,
63,
475,
63,
500,
63,
6526,
63,
265,
63,
2246,
8,
3937,
304,
272,
2061,
275,
822,
8,
3937,
14,
3179,
9,
446,
413,
272,
702,
3920,
14,
1080,
508,
378,
272,
3920,
14,
894,
342,
272,
702,
3920,
14,
1080,
508,
2061,
199,
199,
318,
511,
63,
5626,
63,
1107,
63,
4445,
63,
292,
63,
1080,
8,
3937,
304,
272,
702,
3920,
14,
4445,
14,
344,
342,
508,
3878,
368,
14,
344,
342,
272,
3920,
14,
2184,
342,
272,
702,
3920,
14,
4445,
14,
344,
342,
508,
3878,
5601,
14,
344,
342,
199,
199,
318,
511,
63,
5626,
63,
3730,
63,
889,
63,
4445,
63,
265,
63,
3197,
63,
1080,
8,
3937,
304,
272,
3920,
14,
1080,
275,
8806,
272,
543,
4613,
14,
3536,
8,
1944,
5968,
304,
267,
3920,
14,
4445,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4613,
199,
504,
1683,
492,
4420,
199,
199,
504,
882,
455,
14,
4904,
364,
766,
492,
13407,
8993,
12,
3091,
5968,
199,
199,
646,
2295,
14,
1462,
199,
199,
1897,
275,
2295,
14,
1462,
14,
1222,
4844,
1897,
342,
199,
1897,
275,
2295,
14,
1462,
14,
525,
4445,
270,
393,
1187,
281,
8,
1897,
12,
499,
9,
199,
199,
3179,
275,
4045,
14,
362,
10807,
342,
199,
4445,
368,
275,
4534,
14,
2184,
342,
199,
4445,
5601,
275,
4534,
14,
2184,
342,
199,
199,
32,
4462,
14,
5997,
199,
318,
3920,
837,
272,
372,
13407,
8993,
8,
1897,
29,
1897,
12,
4534,
1524,
4445,
368,
12,
3878,
5601,
566,
199,
199,
318,
511,
63,
5626,
63,
928,
63,
292,
63,
1080,
63,
16,
8,
3937,
304,
272,
702,
3920,
14,
1080,
508,
378,
199,
199,
318,
511,
63,
2184,
63,
5626,
63,
1185,
63,
1080,
8,
3937,
304,
272,
3920,
14,
2184,
342,
272,
702,
3920,
14,
1080,
508,
413,
199,
199,
318,
511,
63,
2184,
63,
5626,
63,
3823,
63,
475,
63,
928,
63,
6526,
63,
265,
63,
2019,
8,
3937,
304,
272,
2061,
275,
822,
8,
3937,
14,
3179,
9,
446,
413,
272,
3920,
14,
1080,
275,
2061,
272,
702,
3920,
14,
1080,
508,
2061,
272,
3920,
14,
2184,
342,
272,
702,
3920,
14,
1080,
508,
378,
199,
199,
318,
511,
63,
894,
63,
5626,
63,
3823,
63,
475,
63,
500,
63,
6526,
63,
265,
63,
2246,
8,
3937,
304,
272,
2061,
275,
822,
8,
3937,
14,
3179,
9,
446,
413,
272,
702,
3920,
14,
1080,
508,
378,
272,
3920,
14,
894,
342,
272,
702,
3920,
14,
1080,
508,
2061,
199,
199,
318,
511,
63,
5626,
63,
1107,
63,
4445,
63,
292,
63,
1080,
8,
3937,
304,
272,
702,
3920,
14,
4445,
14,
344,
342,
508,
3878,
368,
14,
344,
342,
272,
3920,
14,
2184,
342,
272,
702,
3920,
14,
4445,
14,
344,
342,
508,
3878,
5601,
14,
344,
342,
199,
199,
318,
511,
63,
5626,
63,
3730,
63,
889,
63,
4445,
63,
265,
63,
3197,
63,
1080,
8,
3937,
304,
272,
3920,
14,
1080,
275,
8806,
272,
543,
4613,
14,
3536,
8,
1944,
5968,
304,
267,
3920,
14,
4445,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
kostaspl/SpiderMonkey38
|
python/mozbuild/mozbuild/test/compilation/test_warnings.py
|
8
|
6581
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import unittest
from mozfile.mozfile import NamedTemporaryFile
from mozbuild.compilation.warnings import CompilerWarning
from mozbuild.compilation.warnings import WarningsCollector
from mozbuild.compilation.warnings import WarningsDatabase
from mozunit import main
CLANG_TESTS = [
('foobar.cpp:123:10: warning: you messed up [-Wfoo]',
'foobar.cpp', 123, 10, 'you messed up', '-Wfoo'),
("c_locale_dummy.c:457:1: warning: (near initialization for "
"'full_wmonthname[0]') [-Wpointer-sign]",
'c_locale_dummy.c', 457, 1,
"(near initialization for 'full_wmonthname[0]')", '-Wpointer-sign')
]
MSVC_TESTS = [
("C:/mozilla-central/test/foo.cpp(793) : warning C4244: 'return' : "
"conversion from 'double' to 'uint32_t', possible loss of data",
'C:/mozilla-central/test/foo.cpp', 793, 'C4244',
"'return' : conversion from 'double' to 'uint32_t', possible loss of "
'data')
]
CURRENT_LINE = 1
def get_warning():
global CURRENT_LINE
w = CompilerWarning()
w['filename'] = '/foo/bar/baz.cpp'
w['line'] = CURRENT_LINE
w['column'] = 12
w['message'] = 'This is irrelevant'
CURRENT_LINE += 1
return w
class TestCompilerWarning(unittest.TestCase):
def test_equivalence(self):
w1 = CompilerWarning()
w2 = CompilerWarning()
s = set()
# Empty warnings should be equal.
self.assertEqual(w1, w2)
s.add(w1)
s.add(w2)
self.assertEqual(len(s), 1)
w1['filename'] = '/foo.c'
w2['filename'] = '/bar.c'
self.assertNotEqual(w1, w2)
s = set()
s.add(w1)
s.add(w2)
self.assertEqual(len(s), 2)
w1['filename'] = '/foo.c'
w1['line'] = 5
w2['line'] = 5
w2['filename'] = '/foo.c'
w1['column'] = 3
w2['column'] = 3
self.assertEqual(w1, w2)
def test_comparison(self):
w1 = CompilerWarning()
w2 = CompilerWarning()
w1['filename'] = '/aaa.c'
w1['line'] = 5
w1['column'] = 5
w2['filename'] = '/bbb.c'
w2['line'] = 5
w2['column'] = 5
self.assertLess(w1, w2)
self.assertGreater(w2, w1)
self.assertGreaterEqual(w2, w1)
w2['filename'] = '/aaa.c'
w2['line'] = 4
w2['column'] = 6
self.assertLess(w2, w1)
self.assertGreater(w1, w2)
self.assertGreaterEqual(w1, w2)
w2['filename'] = '/aaa.c'
w2['line'] = 5
w2['column'] = 10
self.assertLess(w1, w2)
self.assertGreater(w2, w1)
self.assertGreaterEqual(w2, w1)
w2['filename'] = '/aaa.c'
w2['line'] = 5
w2['column'] = 5
self.assertLessEqual(w1, w2)
self.assertLessEqual(w2, w1)
self.assertGreaterEqual(w2, w1)
self.assertGreaterEqual(w1, w2)
class TestWarningsParsing(unittest.TestCase):
def test_clang_parsing(self):
for source, filename, line, column, message, flag in CLANG_TESTS:
collector = WarningsCollector(resolve_files=False)
warning = collector.process_line(source)
self.assertIsNotNone(warning)
self.assertEqual(warning['filename'], filename)
self.assertEqual(warning['line'], line)
self.assertEqual(warning['column'], column)
self.assertEqual(warning['message'], message)
self.assertEqual(warning['flag'], flag)
def test_msvc_parsing(self):
for source, filename, line, flag, message in MSVC_TESTS:
collector = WarningsCollector(resolve_files=False)
warning = collector.process_line(source)
self.assertIsNotNone(warning)
self.assertEqual(warning['filename'], os.path.normpath(filename))
self.assertEqual(warning['line'], line)
self.assertEqual(warning['flag'], flag)
self.assertEqual(warning['message'], message)
class TestWarningsDatabase(unittest.TestCase):
def test_basic(self):
db = WarningsDatabase()
self.assertEqual(len(db), 0)
for i in range(10):
db.insert(get_warning(), compute_hash=False)
self.assertEqual(len(db), 10)
warnings = list(db)
self.assertEqual(len(warnings), 10)
def test_hashing(self):
"""Ensure that hashing files on insert works."""
db = WarningsDatabase()
temp = NamedTemporaryFile(mode='wt')
temp.write('x' * 100)
temp.flush()
w = CompilerWarning()
w['filename'] = temp.name
w['line'] = 1
w['column'] = 4
w['message'] = 'foo bar'
# Should not throw.
db.insert(w)
w['filename'] = 'DOES_NOT_EXIST'
with self.assertRaises(Exception):
db.insert(w)
def test_pruning(self):
"""Ensure old warnings are removed from database appropriately."""
db = WarningsDatabase()
source_files = []
for i in range(1, 21):
temp = NamedTemporaryFile(mode='wt')
temp.write('x' * (100 * i))
temp.flush()
# Keep reference so it doesn't get GC'd and deleted.
source_files.append(temp)
w = CompilerWarning()
w['filename'] = temp.name
w['line'] = 1
w['column'] = i * 10
w['message'] = 'irrelevant'
db.insert(w)
self.assertEqual(len(db), 20)
# If we change a source file, inserting a new warning should nuke the
# old one.
source_files[0].write('extra')
source_files[0].flush()
w = CompilerWarning()
w['filename'] = source_files[0].name
w['line'] = 1
w['column'] = 50
w['message'] = 'replaced'
db.insert(w)
self.assertEqual(len(db), 20)
warnings = list(db.warnings_for_file(source_files[0].name))
self.assertEqual(len(warnings), 1)
self.assertEqual(warnings[0]['column'], w['column'])
# If we delete the source file, calling prune should cause the warnings
# to go away.
old_filename = source_files[0].name
del source_files[0]
self.assertFalse(os.path.exists(old_filename))
db.prune()
self.assertEqual(len(db), 19)
if __name__ == '__main__':
main()
|
mpl-2.0
|
[
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
747,
199,
646,
2882,
199,
199,
504,
1303,
90,
493,
14,
23120,
493,
492,
31825,
199,
199,
504,
1303,
90,
1506,
14,
863,
13696,
14,
5451,
492,
27154,
3849,
199,
504,
1303,
90,
1506,
14,
863,
13696,
14,
5451,
492,
644,
2627,
12852,
199,
504,
1303,
90,
1506,
14,
863,
13696,
14,
5451,
492,
644,
2627,
7243,
199,
199,
504,
1303,
90,
3248,
492,
2446,
199,
199,
1981,
3986,
63,
7569,
275,
359,
272,
661,
9664,
14,
5910,
26,
4288,
26,
709,
26,
5721,
26,
1265,
26560,
939,
1536,
5243,
55,
1421,
4300,
1362,
283,
9664,
14,
5910,
297,
11869,
12,
1616,
12,
283,
13297,
26560,
939,
1536,
297,
2475,
55,
1421,
659,
272,
1689,
67,
63,
5508,
63,
5869,
14,
67,
26,
27603,
26,
17,
26,
5721,
26,
334,
21078,
11097,
367,
298,
1362,
3546,
2861,
63,
87,
4482,
354,
59,
16,
10374,
5243,
55,
3929,
13,
1037,
11472,
1362,
283,
67,
63,
5508,
63,
5869,
14,
67,
297,
841,
1641,
12,
413,
12,
1362,
7340,
21078,
11097,
367,
283,
2861,
63,
87,
4482,
354,
59,
16,
10374,
401,
2475,
55,
3929,
13,
1037,
358,
199,
61,
199,
199,
3053,
9454,
63,
7569,
275,
359,
272,
1689,
35,
11254,
12102,
13,
16067,
15,
396,
15,
1421,
14,
5910,
8,
26153,
9,
520,
5721,
445,
20,
11603,
26,
283,
1107,
7,
520,
298,
1362,
298,
15083,
687,
283,
3157,
7,
370,
283,
1635,
708,
63,
84,
297,
3962,
5621,
402,
666,
401,
1362,
283,
35,
11254,
12102,
13,
16067,
15,
396,
15,
1421,
14,
5910,
297,
1520,
3129,
12,
283,
35,
20,
11603,
297,
1362,
3546,
1107,
7,
520,
8603,
687,
283,
3157,
7,
370,
283,
1635,
708,
63,
84,
297,
3962,
5621,
402,
298,
268,
283,
576,
358,
199,
61,
199,
199,
14211,
63,
6174,
275,
413,
199,
199,
318,
664,
63,
3764,
837,
272,
2288,
27946,
63,
6174,
339,
336,
275,
27154,
3849,
342,
272,
336,
459,
1501,
418,
275,
1994,
1421,
15,
1700,
15,
6185,
14,
5910,
7,
272,
336,
459,
604,
418,
275,
27946,
63,
6174,
272,
336,
459,
2301,
418,
275,
3144,
272,
336,
459,
1188,
418,
275,
283,
2765,
365,
8190,
21906,
7,
339,
27946,
63,
6174,
847,
413,
339,
372,
336,
199,
199,
533,
1379,
9131,
3849,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
69,
22810,
8,
277,
304,
267,
336,
17,
275,
27154,
3849,
342,
267,
336,
18,
275,
27154,
3849,
342,
398,
308,
275,
663,
342,
398,
327,
9630,
3598,
1077,
506,
4472,
14,
267,
291,
14,
629,
8,
87,
17,
12,
336,
18,
9,
398,
308,
14,
525,
8,
87,
17,
9,
267,
308,
14,
525,
8,
87,
18,
9,
398,
291,
14,
629,
8,
552,
8,
83,
395,
413,
9,
398,
336,
17,
459,
1501,
418,
275,
1994,
1421,
14,
67,
7,
267,
336,
18,
459,
1501,
418,
275,
1994,
1700,
14,
67,
7,
398,
291,
14,
7418,
8,
87,
17,
12,
336,
18,
9,
398,
308,
275,
663,
342,
267,
308,
14,
525,
8,
87,
17,
9,
267,
308,
14,
525,
8,
87,
18,
9,
398,
291,
14,
629,
8,
552,
8,
83,
395,
499,
9,
398,
336,
17,
459,
1501,
418,
275,
1994,
1421,
14,
67,
7,
267,
336,
17,
459,
604,
418,
275,
959,
267,
336,
18,
459,
604,
418,
275,
959,
398,
336,
18,
459,
1501,
418,
275,
1994,
1421,
14,
67,
7,
267,
336,
17,
459,
2301,
418,
275,
650,
267,
336,
18,
459,
2301,
418,
275,
650,
398,
291,
14,
629,
8,
87,
17,
12,
336,
18,
9,
339,
347,
511,
63,
8547,
8,
277,
304,
267,
336,
17,
275,
27154,
3849,
342,
267,
336,
18,
275,
27154,
3849,
342,
398,
336,
17,
459,
1501,
418,
275,
1994,
11629,
14,
67,
7,
267,
336,
17,
459,
604,
418,
275,
959,
267,
336,
17,
459,
2301,
418,
275,
959,
398,
336,
18,
459,
1501,
418,
275,
1994,
19482,
14,
67,
7,
267,
336,
18,
459,
604,
418,
275,
959,
267,
336,
18,
459,
2301,
418,
275,
959,
398,
291,
14,
15625,
8,
87,
17,
12,
336,
18,
9,
267,
291,
14,
15070,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
26875,
8,
87,
18,
12,
336,
17,
9,
398,
336,
18,
459,
1501,
418,
275,
1994,
11629,
14,
67,
7,
267,
336,
18,
459,
604,
418,
275,
841,
267,
336,
18,
459,
2301,
418,
275,
1227,
398,
291,
14,
15625,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
15070,
8,
87,
17,
12,
336,
18,
9,
267,
291,
14,
26875,
8,
87,
17,
12,
336,
18,
9,
398,
336,
18,
459,
1501,
418,
275,
1994,
11629,
14,
67,
7,
267,
336,
18,
459,
604,
418,
275,
959,
267,
336,
18,
459,
2301,
418,
275,
1616,
398,
291,
14,
15625,
8,
87,
17,
12,
336,
18,
9,
267,
291,
14,
15070,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
26875,
8,
87,
18,
12,
336,
17,
9,
398,
336,
18,
459,
1501,
418,
275,
1994,
11629,
14,
67,
7,
267,
336,
18,
459,
604,
418,
275,
959,
267,
336,
18,
459,
2301,
418,
275,
959,
398,
291,
14,
15625,
591,
8,
87,
17,
12,
336,
18,
9,
267,
291,
14,
15625,
591,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
26875,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
26875,
8,
87,
17,
12,
336,
18,
9,
199,
199,
533,
1379,
15921,
17412,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
16066,
63,
11059,
8,
277,
304,
267,
367,
1350,
12,
1788,
12,
1004,
12,
2763,
12,
1245,
12,
3305,
315,
445,
7442,
63,
7569,
26,
288,
14910,
275,
644,
2627,
12852,
8,
6983,
63,
1725,
29,
797,
9,
288,
5721,
275,
14910,
14,
1412,
63,
604,
8,
1365,
9,
953,
291,
14,
10389,
8,
3764,
9
] |
[
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
747,
199,
646,
2882,
199,
199,
504,
1303,
90,
493,
14,
23120,
493,
492,
31825,
199,
199,
504,
1303,
90,
1506,
14,
863,
13696,
14,
5451,
492,
27154,
3849,
199,
504,
1303,
90,
1506,
14,
863,
13696,
14,
5451,
492,
644,
2627,
12852,
199,
504,
1303,
90,
1506,
14,
863,
13696,
14,
5451,
492,
644,
2627,
7243,
199,
199,
504,
1303,
90,
3248,
492,
2446,
199,
199,
1981,
3986,
63,
7569,
275,
359,
272,
661,
9664,
14,
5910,
26,
4288,
26,
709,
26,
5721,
26,
1265,
26560,
939,
1536,
5243,
55,
1421,
4300,
1362,
283,
9664,
14,
5910,
297,
11869,
12,
1616,
12,
283,
13297,
26560,
939,
1536,
297,
2475,
55,
1421,
659,
272,
1689,
67,
63,
5508,
63,
5869,
14,
67,
26,
27603,
26,
17,
26,
5721,
26,
334,
21078,
11097,
367,
298,
1362,
3546,
2861,
63,
87,
4482,
354,
59,
16,
10374,
5243,
55,
3929,
13,
1037,
11472,
1362,
283,
67,
63,
5508,
63,
5869,
14,
67,
297,
841,
1641,
12,
413,
12,
1362,
7340,
21078,
11097,
367,
283,
2861,
63,
87,
4482,
354,
59,
16,
10374,
401,
2475,
55,
3929,
13,
1037,
358,
199,
61,
199,
199,
3053,
9454,
63,
7569,
275,
359,
272,
1689,
35,
11254,
12102,
13,
16067,
15,
396,
15,
1421,
14,
5910,
8,
26153,
9,
520,
5721,
445,
20,
11603,
26,
283,
1107,
7,
520,
298,
1362,
298,
15083,
687,
283,
3157,
7,
370,
283,
1635,
708,
63,
84,
297,
3962,
5621,
402,
666,
401,
1362,
283,
35,
11254,
12102,
13,
16067,
15,
396,
15,
1421,
14,
5910,
297,
1520,
3129,
12,
283,
35,
20,
11603,
297,
1362,
3546,
1107,
7,
520,
8603,
687,
283,
3157,
7,
370,
283,
1635,
708,
63,
84,
297,
3962,
5621,
402,
298,
268,
283,
576,
358,
199,
61,
199,
199,
14211,
63,
6174,
275,
413,
199,
199,
318,
664,
63,
3764,
837,
272,
2288,
27946,
63,
6174,
339,
336,
275,
27154,
3849,
342,
272,
336,
459,
1501,
418,
275,
1994,
1421,
15,
1700,
15,
6185,
14,
5910,
7,
272,
336,
459,
604,
418,
275,
27946,
63,
6174,
272,
336,
459,
2301,
418,
275,
3144,
272,
336,
459,
1188,
418,
275,
283,
2765,
365,
8190,
21906,
7,
339,
27946,
63,
6174,
847,
413,
339,
372,
336,
199,
199,
533,
1379,
9131,
3849,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
69,
22810,
8,
277,
304,
267,
336,
17,
275,
27154,
3849,
342,
267,
336,
18,
275,
27154,
3849,
342,
398,
308,
275,
663,
342,
398,
327,
9630,
3598,
1077,
506,
4472,
14,
267,
291,
14,
629,
8,
87,
17,
12,
336,
18,
9,
398,
308,
14,
525,
8,
87,
17,
9,
267,
308,
14,
525,
8,
87,
18,
9,
398,
291,
14,
629,
8,
552,
8,
83,
395,
413,
9,
398,
336,
17,
459,
1501,
418,
275,
1994,
1421,
14,
67,
7,
267,
336,
18,
459,
1501,
418,
275,
1994,
1700,
14,
67,
7,
398,
291,
14,
7418,
8,
87,
17,
12,
336,
18,
9,
398,
308,
275,
663,
342,
267,
308,
14,
525,
8,
87,
17,
9,
267,
308,
14,
525,
8,
87,
18,
9,
398,
291,
14,
629,
8,
552,
8,
83,
395,
499,
9,
398,
336,
17,
459,
1501,
418,
275,
1994,
1421,
14,
67,
7,
267,
336,
17,
459,
604,
418,
275,
959,
267,
336,
18,
459,
604,
418,
275,
959,
398,
336,
18,
459,
1501,
418,
275,
1994,
1421,
14,
67,
7,
267,
336,
17,
459,
2301,
418,
275,
650,
267,
336,
18,
459,
2301,
418,
275,
650,
398,
291,
14,
629,
8,
87,
17,
12,
336,
18,
9,
339,
347,
511,
63,
8547,
8,
277,
304,
267,
336,
17,
275,
27154,
3849,
342,
267,
336,
18,
275,
27154,
3849,
342,
398,
336,
17,
459,
1501,
418,
275,
1994,
11629,
14,
67,
7,
267,
336,
17,
459,
604,
418,
275,
959,
267,
336,
17,
459,
2301,
418,
275,
959,
398,
336,
18,
459,
1501,
418,
275,
1994,
19482,
14,
67,
7,
267,
336,
18,
459,
604,
418,
275,
959,
267,
336,
18,
459,
2301,
418,
275,
959,
398,
291,
14,
15625,
8,
87,
17,
12,
336,
18,
9,
267,
291,
14,
15070,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
26875,
8,
87,
18,
12,
336,
17,
9,
398,
336,
18,
459,
1501,
418,
275,
1994,
11629,
14,
67,
7,
267,
336,
18,
459,
604,
418,
275,
841,
267,
336,
18,
459,
2301,
418,
275,
1227,
398,
291,
14,
15625,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
15070,
8,
87,
17,
12,
336,
18,
9,
267,
291,
14,
26875,
8,
87,
17,
12,
336,
18,
9,
398,
336,
18,
459,
1501,
418,
275,
1994,
11629,
14,
67,
7,
267,
336,
18,
459,
604,
418,
275,
959,
267,
336,
18,
459,
2301,
418,
275,
1616,
398,
291,
14,
15625,
8,
87,
17,
12,
336,
18,
9,
267,
291,
14,
15070,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
26875,
8,
87,
18,
12,
336,
17,
9,
398,
336,
18,
459,
1501,
418,
275,
1994,
11629,
14,
67,
7,
267,
336,
18,
459,
604,
418,
275,
959,
267,
336,
18,
459,
2301,
418,
275,
959,
398,
291,
14,
15625,
591,
8,
87,
17,
12,
336,
18,
9,
267,
291,
14,
15625,
591,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
26875,
8,
87,
18,
12,
336,
17,
9,
267,
291,
14,
26875,
8,
87,
17,
12,
336,
18,
9,
199,
199,
533,
1379,
15921,
17412,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
16066,
63,
11059,
8,
277,
304,
267,
367,
1350,
12,
1788,
12,
1004,
12,
2763,
12,
1245,
12,
3305,
315,
445,
7442,
63,
7569,
26,
288,
14910,
275,
644,
2627,
12852,
8,
6983,
63,
1725,
29,
797,
9,
288,
5721,
275,
14910,
14,
1412,
63,
604,
8,
1365,
9,
953,
291,
14,
10389,
8,
3764,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kurli/blink-crosswalk
|
Tools/Scripts/webkitpy/layout_tests/servers/pywebsocket.py
|
25
|
3496
|
# Copyright (C) 2011 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""A class to help start/stop the PyWebSocket server as used by the layout tests."""
import logging
import os
import sys
import time
from webkitpy.layout_tests.servers import server_base
from webkitpy.thirdparty import mod_pywebsocket
_log = logging.getLogger(__name__)
_WS_LOG_PREFIX = 'pywebsocket.ws.log-'
_DEFAULT_WS_PORT = 8880
class PyWebSocket(server_base.ServerBase):
def __init__(self, port_obj, output_dir):
super(PyWebSocket, self).__init__(port_obj, output_dir)
self._name = 'pywebsocket'
self._log_prefixes = (_WS_LOG_PREFIX,)
self._mappings = [{'port': _DEFAULT_WS_PORT}]
self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % self._name)
self._port = _DEFAULT_WS_PORT
self._layout_tests = self._port_obj.layout_tests_dir()
self._web_socket_tests = self._filesystem.join(self._layout_tests, 'http', 'tests', 'websocket')
time_str = time.strftime('%d%b%Y-%H%M%S')
log_file_name = _WS_LOG_PREFIX + time_str
self._error_log = self._filesystem.join(self._output_dir, log_file_name + "-err.txt")
pywebsocket_base = self._port_obj.path_from_webkit_base('Tools', 'Scripts', 'webkitpy', 'thirdparty')
pywebsocket_script = self._filesystem.join(pywebsocket_base, 'mod_pywebsocket', 'standalone.py')
self._start_cmd = [
sys.executable, '-u', pywebsocket_script,
'--server-host', 'localhost',
'--port', str(self._port),
'--document-root', self._web_socket_tests,
'--scan-dir', self._web_socket_tests,
'--cgi-paths', '/',
'--log-file', self._error_log,
'--websock-handlers-map-file', self._filesystem.join(self._web_socket_tests, 'handler_map.txt'),
]
self._env = self._port_obj.setup_environ_for_server()
self._env['PYTHONPATH'] = (pywebsocket_base + os.pathsep + self._env.get('PYTHONPATH', ''))
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
7760,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
33,
1021,
370,
1720,
1343,
15,
2379,
314,
1611,
18477,
1654,
465,
1202,
701,
314,
7054,
2295,
1041,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
504,
18007,
14,
4209,
63,
2219,
14,
5871,
492,
1654,
63,
1095,
199,
504,
18007,
14,
11470,
7522,
492,
3413,
63,
21387,
199,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
63,
5035,
63,
4947,
63,
6351,
275,
283,
21387,
14,
3569,
14,
793,
15668,
199,
199,
63,
3472,
63,
5035,
63,
3657,
275,
10523,
1257,
421,
199,
533,
1611,
18477,
8,
1000,
63,
1095,
14,
3120,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
1844,
63,
1113,
12,
1072,
63,
694,
304,
267,
1613,
8,
2713,
18477,
12,
291,
2843,
826,
721,
719,
63,
1113,
12,
1072,
63,
694,
9,
267,
291,
423,
354,
275,
283,
21387,
7,
267,
291,
423,
793,
63,
14124,
275,
6110,
5035,
63,
4947,
63,
6351,
4258,
267,
291,
423,
14632,
275,
9016,
719,
356,
485,
3472,
63,
5035,
63,
3657,
11049,
267,
291,
423,
3150,
63,
493,
275,
291,
423,
11381,
14,
904,
8,
277,
423,
7726,
63,
515,
12,
1543,
83,
14,
3150,
7,
450,
291,
423,
354,
9,
398,
291,
423,
719,
275,
485,
3472,
63,
5035,
63,
3657,
267,
291,
423,
4209,
63,
2219,
275,
291,
423,
719,
63,
1113,
14,
4209,
63,
2219,
63,
694,
342,
267,
291,
423,
2520,
63,
3450,
63,
2219,
275,
291,
423,
11381,
14,
904,
8,
277,
423,
4209,
63,
2219,
12,
283,
1014,
297,
283,
2219,
297,
283,
13508,
358,
267,
900,
63,
495,
275,
900,
14,
6205,
3508,
68,
5,
66,
5,
57,
3295,
40,
5,
45,
5,
51,
358,
267,
943,
63,
493,
63,
354,
275,
485,
5035,
63,
4947,
63,
6351,
435,
900,
63,
495,
267,
291,
423,
705,
63,
793,
275,
291,
423,
11381,
14,
904,
8,
277,
423,
1199,
63,
694,
12,
943,
63,
493,
63,
354,
435,
3905,
1508,
14,
2424,
531,
267,
1134,
13508,
63,
1095,
275,
291,
423,
719,
63,
1113,
14,
515,
63,
504,
63,
12554,
63,
1095,
360,
11654,
297,
283,
25681,
297,
283,
12554,
647,
297,
283,
11470,
7522,
358,
267,
1134,
13508,
63,
1579,
275,
291,
423,
11381,
14,
904,
8,
21387,
63,
1095,
12,
283,
1494,
63,
21387,
297,
283,
20323,
14,
647,
358,
398,
291,
423,
928,
63,
1760,
275,
359,
288,
984,
14,
5904,
12,
2475,
85,
297,
1134,
13508,
63,
1579,
12,
288,
2850,
1000,
13,
1102,
297,
283,
5967,
297,
288,
2850,
719,
297,
620,
8,
277,
423,
719,
395,
288,
2850,
3554,
13,
1231,
297,
291,
423,
2520,
63,
3450,
63,
2219,
12,
288,
2850,
6282,
13,
694,
297,
291,
423,
2520,
63,
3450,
63,
2219,
12,
288,
2850,
13814,
13,
3771,
297,
17220,
288,
2850,
793,
13,
493,
297,
291,
423,
705,
63,
793,
12,
288,
2850,
1129,
1533,
766,
13,
5586,
13,
1130,
13,
493,
297,
291,
423,
11381,
14,
904,
8,
277,
423,
2520,
63,
3450,
63,
2219,
12,
283,
2232,
63,
1130,
14,
2424,
659,
288,
1622,
267,
291,
423,
1813,
275,
291,
423,
719,
63,
1113,
14,
2758,
63,
2314,
63,
509,
63,
1000,
342,
267,
291,
423,
1813,
459,
29266,
418,
275,
334,
21387,
63,
1095,
435,
747,
14,
17843,
435,
291,
423,
1813,
14,
362,
360,
29266,
297,
12381,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
35,
9,
7760,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
33,
1021,
370,
1720,
1343,
15,
2379,
314,
1611,
18477,
1654,
465,
1202,
701,
314,
7054,
2295,
1041,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
504,
18007,
14,
4209,
63,
2219,
14,
5871,
492,
1654,
63,
1095,
199,
504,
18007,
14,
11470,
7522,
492,
3413,
63,
21387,
199,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
63,
5035,
63,
4947,
63,
6351,
275,
283,
21387,
14,
3569,
14,
793,
15668,
199,
199,
63,
3472,
63,
5035,
63,
3657,
275,
10523,
1257,
421,
199,
533,
1611,
18477,
8,
1000,
63,
1095,
14,
3120,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
1844,
63,
1113,
12,
1072,
63,
694,
304,
267,
1613,
8,
2713,
18477,
12,
291,
2843,
826,
721,
719,
63,
1113,
12,
1072,
63,
694,
9,
267,
291,
423,
354,
275,
283,
21387,
7,
267,
291,
423,
793,
63,
14124,
275,
6110,
5035,
63,
4947,
63,
6351,
4258,
267,
291,
423,
14632,
275,
9016,
719,
356,
485,
3472,
63,
5035,
63,
3657,
11049,
267,
291,
423,
3150,
63,
493,
275,
291,
423,
11381,
14,
904,
8,
277,
423,
7726,
63,
515,
12,
1543,
83,
14,
3150,
7,
450,
291,
423,
354,
9,
398,
291,
423,
719,
275,
485,
3472,
63,
5035,
63,
3657,
267,
291,
423,
4209,
63,
2219,
275,
291,
423,
719,
63,
1113,
14,
4209,
63,
2219,
63,
694,
342,
267,
291,
423,
2520,
63,
3450,
63,
2219,
275,
291,
423,
11381,
14,
904,
8,
277,
423,
4209,
63,
2219,
12,
283,
1014,
297,
283,
2219,
297,
283,
13508,
358,
267,
900,
63,
495,
275,
900,
14,
6205,
3508,
68,
5,
66,
5,
57,
3295,
40,
5,
45,
5,
51,
358,
267,
943,
63,
493,
63,
354,
275,
485,
5035,
63,
4947,
63,
6351,
435,
900,
63,
495,
267,
291,
423,
705,
63,
793,
275,
291,
423,
11381,
14,
904,
8,
277,
423,
1199,
63,
694,
12,
943,
63,
493,
63,
354,
435,
3905,
1508,
14,
2424,
531,
267,
1134,
13508,
63,
1095,
275,
291,
423,
719,
63,
1113,
14,
515,
63,
504,
63,
12554,
63,
1095,
360,
11654,
297,
283,
25681,
297,
283,
12554,
647,
297,
283,
11470,
7522,
358,
267,
1134,
13508,
63,
1579,
275,
291,
423,
11381,
14,
904,
8,
21387,
63,
1095,
12,
283,
1494,
63,
21387,
297,
283,
20323,
14,
647,
358,
398,
291,
423,
928,
63,
1760,
275,
359,
288,
984,
14,
5904,
12,
2475,
85,
297,
1134,
13508,
63,
1579,
12,
288,
2850,
1000,
13,
1102,
297,
283,
5967,
297,
288,
2850,
719,
297,
620,
8,
277,
423,
719,
395,
288,
2850,
3554,
13,
1231,
297,
291,
423,
2520,
63,
3450,
63,
2219,
12,
288,
2850,
6282,
13,
694,
297,
291,
423,
2520,
63,
3450,
63,
2219,
12,
288,
2850,
13814,
13,
3771,
297,
17220,
288,
2850,
793,
13,
493,
297,
291,
423,
705,
63,
793,
12,
288,
2850,
1129,
1533,
766,
13,
5586,
13,
1130,
13,
493,
297,
291,
423,
11381,
14,
904,
8,
277,
423,
2520,
63,
3450,
63,
2219,
12,
283,
2232,
63,
1130,
14,
2424,
659,
288,
1622,
267,
291,
423,
1813,
275,
291,
423,
719,
63,
1113,
14,
2758,
63,
2314,
63,
509,
63,
1000,
342,
267,
291,
423,
1813,
459,
29266,
418,
275,
334,
21387,
63,
1095,
435,
747,
14,
17843,
435,
291,
423,
1813,
14,
362,
360,
29266,
297,
12381,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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,
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
] |
getsentry/zeus
|
zeus/factories/filecoverage.py
|
1
|
1220
|
import factory
import factory.fuzzy
from faker import Factory
faker = Factory.create()
from random import randint
from zeus import models
from .base import ModelFactory
from .types import GUIDFactory
class FileCoverageFactory(ModelFactory):
id = GUIDFactory()
filename = factory.LazyAttribute(
lambda o: "tests/%s/%s/%s.py" % (faker.word(), faker.word(), faker.word())
)
build = factory.SubFactory("zeus.factories.BuildFactory")
build_id = factory.SelfAttribute("build.id")
repository = factory.SelfAttribute("build.repository")
repository_id = factory.SelfAttribute("repository.id")
data = "CCCUUUU"
lines_covered = factory.Faker("random_int", min=0, max=100)
lines_uncovered = factory.Faker("random_int", min=0, max=100)
diff_lines_covered = 0
diff_lines_uncovered = 0
class Meta:
model = models.FileCoverage
class Params:
in_diff = factory.Trait(
diff_lines_covered=factory.LazyAttribute(
lambda o: max(o.lines_covered - randint(0, 3), 0)
),
diff_lines_uncovered=factory.LazyAttribute(
lambda o: max(o.lines_covered - randint(0, 5), 0)
),
)
|
apache-2.0
|
[
646,
6434,
199,
646,
6434,
14,
24529,
199,
199,
504,
289,
12630,
492,
23616,
199,
199,
667,
2570,
275,
23616,
14,
981,
342,
199,
199,
504,
2196,
492,
29722,
199,
504,
29986,
527,
492,
1709,
199,
199,
504,
1275,
1095,
492,
5822,
2927,
199,
504,
1275,
1313,
492,
21645,
2927,
421,
199,
533,
3814,
27444,
2927,
8,
1685,
2927,
304,
272,
1305,
275,
21645,
2927,
342,
272,
1788,
275,
6434,
14,
14269,
1646,
8,
267,
2400,
312,
26,
298,
2219,
3149,
83,
3149,
83,
3149,
83,
14,
647,
2,
450,
334,
667,
2570,
14,
1027,
1062,
289,
12630,
14,
1027,
1062,
289,
12630,
14,
1027,
1012,
272,
776,
272,
1900,
275,
6434,
14,
2610,
2927,
480,
806,
527,
14,
15406,
14,
3425,
2927,
531,
272,
1900,
63,
344,
275,
6434,
14,
12887,
1646,
480,
1506,
14,
344,
531,
272,
7611,
275,
6434,
14,
12887,
1646,
480,
1506,
14,
8421,
531,
272,
7611,
63,
344,
275,
6434,
14,
12887,
1646,
480,
8421,
14,
344,
531,
272,
666,
275,
298,
19837,
9724,
2,
272,
2385,
63,
13560,
275,
6434,
14,
38,
12630,
480,
2355,
63,
442,
401,
1748,
29,
16,
12,
1390,
29,
1960,
9,
272,
2385,
63,
324,
13560,
275,
6434,
14,
38,
12630,
480,
2355,
63,
442,
401,
1748,
29,
16,
12,
1390,
29,
1960,
9,
272,
3915,
63,
1278,
63,
13560,
275,
378,
272,
3915,
63,
1278,
63,
324,
13560,
275,
378,
339,
1021,
6288,
26,
267,
1402,
275,
1709,
14,
1173,
27444,
339,
1021,
30370,
26,
267,
315,
63,
3028,
275,
6434,
14,
27655,
8,
288,
3915,
63,
1278,
63,
13560,
29,
3702,
14,
14269,
1646,
8,
355,
2400,
312,
26,
1390,
8,
79,
14,
1278,
63,
13560,
446,
29722,
8,
16,
12,
650,
395,
378,
9,
288,
2318,
288,
3915,
63,
1278,
63,
324,
13560,
29,
3702,
14,
14269,
1646,
8,
355,
2400,
312,
26,
1390,
8,
79,
14,
1278,
63,
13560,
446,
29722,
8,
16,
12,
959,
395,
378,
9,
288,
2318,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6434,
199,
646,
6434,
14,
24529,
199,
199,
504,
289,
12630,
492,
23616,
199,
199,
667,
2570,
275,
23616,
14,
981,
342,
199,
199,
504,
2196,
492,
29722,
199,
504,
29986,
527,
492,
1709,
199,
199,
504,
1275,
1095,
492,
5822,
2927,
199,
504,
1275,
1313,
492,
21645,
2927,
421,
199,
533,
3814,
27444,
2927,
8,
1685,
2927,
304,
272,
1305,
275,
21645,
2927,
342,
272,
1788,
275,
6434,
14,
14269,
1646,
8,
267,
2400,
312,
26,
298,
2219,
3149,
83,
3149,
83,
3149,
83,
14,
647,
2,
450,
334,
667,
2570,
14,
1027,
1062,
289,
12630,
14,
1027,
1062,
289,
12630,
14,
1027,
1012,
272,
776,
272,
1900,
275,
6434,
14,
2610,
2927,
480,
806,
527,
14,
15406,
14,
3425,
2927,
531,
272,
1900,
63,
344,
275,
6434,
14,
12887,
1646,
480,
1506,
14,
344,
531,
272,
7611,
275,
6434,
14,
12887,
1646,
480,
1506,
14,
8421,
531,
272,
7611,
63,
344,
275,
6434,
14,
12887,
1646,
480,
8421,
14,
344,
531,
272,
666,
275,
298,
19837,
9724,
2,
272,
2385,
63,
13560,
275,
6434,
14,
38,
12630,
480,
2355,
63,
442,
401,
1748,
29,
16,
12,
1390,
29,
1960,
9,
272,
2385,
63,
324,
13560,
275,
6434,
14,
38,
12630,
480,
2355,
63,
442,
401,
1748,
29,
16,
12,
1390,
29,
1960,
9,
272,
3915,
63,
1278,
63,
13560,
275,
378,
272,
3915,
63,
1278,
63,
324,
13560,
275,
378,
339,
1021,
6288,
26,
267,
1402,
275,
1709,
14,
1173,
27444,
339,
1021,
30370,
26,
267,
315,
63,
3028,
275,
6434,
14,
27655,
8,
288,
3915,
63,
1278,
63,
13560,
29,
3702,
14,
14269,
1646,
8,
355,
2400,
312,
26,
1390,
8,
79,
14,
1278,
63,
13560,
446,
29722,
8,
16,
12,
650,
395,
378,
9,
288,
2318,
288,
3915,
63,
1278,
63,
324,
13560,
29,
3702,
14,
14269,
1646,
8,
355,
2400,
312,
26,
1390,
8,
79,
14,
1278,
63,
13560,
446,
29722,
8,
16,
12,
959,
395,
378,
9,
288,
2318,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rameshakulapc/PDFViewer
|
jni/mupdf/freetype/src/tools/docmaker/docmaker.py
|
463
|
2766
|
#!/usr/bin/env python
#
# DocMaker (c) 2002, 2004, 2008 David Turner <david@freetype.org>
#
# This program is a re-write of the original DocMaker took used
# to generate the API Reference of the FreeType font engine
# by converting in-source comments into structured HTML.
#
# This new version is capable of outputting XML data, as well
# as accepts more liberal formatting options.
#
# It also uses regular expression matching and substitution
# to speed things significantly.
#
from sources import *
from content import *
from utils import *
from formatter import *
from tohtml import *
import utils
import sys, os, time, string, glob, getopt
def usage():
print "\nDocMaker Usage information\n"
print " docmaker [options] file1 [file2 ...]\n"
print "using the following options:\n"
print " -h : print this page"
print " -t : set project title, as in '-t \"My Project\"'"
print " -o : set output directory, as in '-o mydir'"
print " -p : set documentation prefix, as in '-p ft2'"
print ""
print " --title : same as -t, as in '--title=\"My Project\"'"
print " --output : same as -o, as in '--output=mydir'"
print " --prefix : same as -p, as in '--prefix=ft2'"
def main( argv ):
"""main program loop"""
global output_dir
try:
opts, args = getopt.getopt( sys.argv[1:], \
"ht:o:p:", \
["help", "title=", "output=", "prefix="] )
except getopt.GetoptError:
usage()
sys.exit( 2 )
if args == []:
usage()
sys.exit( 1 )
# process options
#
project_title = "Project"
project_prefix = None
output_dir = None
for opt in opts:
if opt[0] in ( "-h", "--help" ):
usage()
sys.exit( 0 )
if opt[0] in ( "-t", "--title" ):
project_title = opt[1]
if opt[0] in ( "-o", "--output" ):
utils.output_dir = opt[1]
if opt[0] in ( "-p", "--prefix" ):
project_prefix = opt[1]
check_output()
# create context and processor
source_processor = SourceProcessor()
content_processor = ContentProcessor()
# retrieve the list of files to process
file_list = make_file_list( args )
for filename in file_list:
source_processor.parse_file( filename )
content_processor.parse_sources( source_processor )
# process sections
content_processor.finish()
formatter = HtmlFormatter( content_processor, project_title, project_prefix )
formatter.toc_dump()
formatter.index_dump()
formatter.section_dump_all()
# if called from the command line
#
if __name__ == '__main__':
main( sys.argv )
# eof
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
221,
5454,
23560,
334,
67,
9,
14790,
12,
8353,
12,
9079,
20232,
16147,
281,
665,
983,
5017,
32,
4624,
466,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
282,
295,
13,
952,
402,
314,
3379,
5454,
23560,
27221,
1202,
199,
3,
370,
3550,
314,
3261,
10944,
402,
314,
2868,
804,
5023,
6869,
199,
3,
701,
13806,
315,
13,
1365,
6786,
1901,
21781,
4163,
14,
199,
3,
199,
3,
961,
892,
1015,
365,
4021,
461,
402,
1072,
1337,
4692,
666,
12,
465,
5521,
199,
3,
465,
11479,
1655,
1212,
605,
279,
10803,
1511,
14,
199,
3,
199,
3,
2779,
2597,
4440,
5578,
3965,
4877,
436,
20584,
199,
3,
370,
8112,
7645,
16474,
590,
14,
199,
3,
199,
199,
504,
5274,
257,
492,
627,
199,
504,
1564,
257,
492,
627,
199,
504,
3778,
258,
492,
627,
199,
504,
9698,
492,
627,
199,
504,
370,
1360,
259,
492,
627,
199,
199,
646,
3778,
199,
199,
646,
984,
12,
747,
12,
900,
12,
1059,
12,
5739,
12,
12733,
421,
199,
318,
221,
4503,
837,
272,
870,
1867,
78,
3768,
23560,
11028,
2556,
60,
78,
2,
272,
870,
298,
221,
1382,
14367,
359,
1419,
61,
570,
17,
359,
493,
18,
2263,
7272,
78,
2,
272,
870,
298,
4941,
314,
2569,
1511,
3427,
78,
2,
272,
870,
298,
221,
446,
72,
520,
870,
642,
2034,
2,
272,
870,
298,
221,
446,
84,
520,
663,
2199,
2538,
12,
465,
315,
2475,
84,
8441,
5713,
7290,
4451,
4065,
272,
870,
298,
221,
446,
79,
520,
663,
1072,
2082,
12,
465,
315,
2475,
79,
3002,
694,
4065,
272,
870,
298,
221,
446,
80,
520,
663,
3794,
2403,
12,
465,
315,
2475,
80,
18133,
18,
4065,
272,
870,
3087,
272,
870,
298,
221,
1553,
1213,
221,
520,
2011,
465,
446,
84,
12,
465,
315,
2850,
1213,
8178,
5713,
7290,
4451,
4065,
272,
870,
298,
221,
1553,
1199,
520,
2011,
465,
446,
79,
12,
465,
315,
2850,
1199,
29,
1662,
694,
4065,
272,
870,
298,
221,
1553,
1861,
520,
2011,
465,
446,
80,
12,
465,
315,
2850,
1861,
29,
856,
18,
4065,
421,
199,
318,
221,
2446,
8,
9238,
3461,
272,
408,
973,
2240,
4438,
624,
339,
2288,
1072,
63,
694,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
984,
14,
3020,
59,
17,
8429,
971,
2511,
298,
517,
26,
79,
26,
80,
6783,
259,
971,
2511,
2097,
3437,
401,
298,
1213,
11107,
298,
1199,
11107,
298,
1861,
628,
61,
776,
272,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
499,
776,
339,
340,
1249,
508,
18410,
267,
4503,
342,
267,
984,
14,
2224,
8,
413,
776,
339,
327,
2112,
1511,
272,
327,
272,
2199,
63,
1213,
221,
275,
298,
4761,
2,
272,
2199,
63,
1861,
275,
488,
272,
1072,
63,
694,
258,
275,
488,
339,
367,
2450,
315,
3999,
26,
267,
340,
2450,
59,
16,
61,
315,
334,
3905,
72,
401,
4320,
3437,
2,
3461,
288,
4503,
342,
288,
984,
14,
2224,
8,
378,
776,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
84,
401,
4320,
1213,
2,
3461,
288,
2199,
63,
1213,
275,
2450,
59,
17,
61,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
79,
401,
4320,
1199,
2,
3461,
288,
3778,
14,
1199,
63,
694,
275,
2450,
59,
17,
61,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
80,
401,
4320,
1861,
2,
3461,
288,
2199,
63,
1861,
275,
2450,
59,
17,
61,
339,
1104,
63,
1199,
342,
339,
327,
1218,
1067,
436,
12495,
272,
1350,
63,
6459,
221,
275,
5800,
10438,
342,
272,
1564,
63,
6459,
275,
6646,
10438,
342,
339,
327,
8044,
314,
769,
402,
1584,
370,
2112,
272,
570,
63,
513,
275,
1852,
63,
493,
63,
513,
8,
1249,
776,
272,
367,
1788,
315,
570,
63,
513,
26,
267,
1350,
63,
6459,
14,
1122,
63,
493,
8,
1788,
776,
267,
1564,
63,
6459,
14,
1122,
63,
4553,
8,
1350,
63,
6459,
776,
339,
327,
2112,
10189,
272,
1564,
63,
6459,
14,
8192,
342,
339,
9698,
275,
20880,
7772,
8,
1564,
63,
6459,
12,
2199,
63,
1213,
12,
2199,
63,
1861,
776,
339,
9698,
14,
13255,
63,
2724,
342,
272,
9698,
14,
1080,
63,
2724,
342,
272,
9698,
14,
2792,
63,
2724,
63,
452,
342,
421,
199,
3,
340,
2797,
687,
314,
1414,
1004,
199,
3,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
984,
14,
3020,
776,
421,
199,
3,
29403,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
221,
5454,
23560,
334,
67,
9,
14790,
12,
8353,
12,
9079,
20232,
16147,
281,
665,
983,
5017,
32,
4624,
466,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
282,
295,
13,
952,
402,
314,
3379,
5454,
23560,
27221,
1202,
199,
3,
370,
3550,
314,
3261,
10944,
402,
314,
2868,
804,
5023,
6869,
199,
3,
701,
13806,
315,
13,
1365,
6786,
1901,
21781,
4163,
14,
199,
3,
199,
3,
961,
892,
1015,
365,
4021,
461,
402,
1072,
1337,
4692,
666,
12,
465,
5521,
199,
3,
465,
11479,
1655,
1212,
605,
279,
10803,
1511,
14,
199,
3,
199,
3,
2779,
2597,
4440,
5578,
3965,
4877,
436,
20584,
199,
3,
370,
8112,
7645,
16474,
590,
14,
199,
3,
199,
199,
504,
5274,
257,
492,
627,
199,
504,
1564,
257,
492,
627,
199,
504,
3778,
258,
492,
627,
199,
504,
9698,
492,
627,
199,
504,
370,
1360,
259,
492,
627,
199,
199,
646,
3778,
199,
199,
646,
984,
12,
747,
12,
900,
12,
1059,
12,
5739,
12,
12733,
421,
199,
318,
221,
4503,
837,
272,
870,
1867,
78,
3768,
23560,
11028,
2556,
60,
78,
2,
272,
870,
298,
221,
1382,
14367,
359,
1419,
61,
570,
17,
359,
493,
18,
2263,
7272,
78,
2,
272,
870,
298,
4941,
314,
2569,
1511,
3427,
78,
2,
272,
870,
298,
221,
446,
72,
520,
870,
642,
2034,
2,
272,
870,
298,
221,
446,
84,
520,
663,
2199,
2538,
12,
465,
315,
2475,
84,
8441,
5713,
7290,
4451,
4065,
272,
870,
298,
221,
446,
79,
520,
663,
1072,
2082,
12,
465,
315,
2475,
79,
3002,
694,
4065,
272,
870,
298,
221,
446,
80,
520,
663,
3794,
2403,
12,
465,
315,
2475,
80,
18133,
18,
4065,
272,
870,
3087,
272,
870,
298,
221,
1553,
1213,
221,
520,
2011,
465,
446,
84,
12,
465,
315,
2850,
1213,
8178,
5713,
7290,
4451,
4065,
272,
870,
298,
221,
1553,
1199,
520,
2011,
465,
446,
79,
12,
465,
315,
2850,
1199,
29,
1662,
694,
4065,
272,
870,
298,
221,
1553,
1861,
520,
2011,
465,
446,
80,
12,
465,
315,
2850,
1861,
29,
856,
18,
4065,
421,
199,
318,
221,
2446,
8,
9238,
3461,
272,
408,
973,
2240,
4438,
624,
339,
2288,
1072,
63,
694,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
984,
14,
3020,
59,
17,
8429,
971,
2511,
298,
517,
26,
79,
26,
80,
6783,
259,
971,
2511,
2097,
3437,
401,
298,
1213,
11107,
298,
1199,
11107,
298,
1861,
628,
61,
776,
272,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
499,
776,
339,
340,
1249,
508,
18410,
267,
4503,
342,
267,
984,
14,
2224,
8,
413,
776,
339,
327,
2112,
1511,
272,
327,
272,
2199,
63,
1213,
221,
275,
298,
4761,
2,
272,
2199,
63,
1861,
275,
488,
272,
1072,
63,
694,
258,
275,
488,
339,
367,
2450,
315,
3999,
26,
267,
340,
2450,
59,
16,
61,
315,
334,
3905,
72,
401,
4320,
3437,
2,
3461,
288,
4503,
342,
288,
984,
14,
2224,
8,
378,
776,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
84,
401,
4320,
1213,
2,
3461,
288,
2199,
63,
1213,
275,
2450,
59,
17,
61,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
79,
401,
4320,
1199,
2,
3461,
288,
3778,
14,
1199,
63,
694,
275,
2450,
59,
17,
61,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
80,
401,
4320,
1861,
2,
3461,
288,
2199,
63,
1861,
275,
2450,
59,
17,
61,
339,
1104,
63,
1199,
342,
339,
327,
1218,
1067,
436,
12495,
272,
1350,
63,
6459,
221,
275,
5800,
10438,
342,
272,
1564,
63,
6459,
275,
6646,
10438,
342,
339,
327,
8044,
314,
769,
402,
1584,
370,
2112,
272,
570,
63,
513,
275,
1852,
63,
493,
63,
513,
8,
1249,
776,
272,
367,
1788,
315,
570,
63,
513,
26,
267,
1350,
63,
6459,
14,
1122,
63,
493,
8,
1788,
776,
267,
1564,
63,
6459,
14,
1122,
63,
4553,
8,
1350,
63,
6459,
776,
339,
327,
2112,
10189,
272,
1564,
63,
6459,
14,
8192,
342,
339,
9698,
275,
20880,
7772,
8,
1564,
63,
6459,
12,
2199,
63,
1213,
12,
2199,
63,
1861,
776,
339,
9698,
14,
13255,
63,
2724,
342,
272,
9698,
14,
1080,
63,
2724,
342,
272,
9698,
14,
2792,
63,
2724,
63,
452,
342,
421,
199,
3,
340,
2797,
687,
314,
1414,
1004,
199,
3,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
984,
14,
3020,
776,
421,
199,
3,
29403,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
santiavenda2/griffith
|
lib/people.py
|
4
|
5798
|
# -*- coding: UTF-8 -*-
__revision__ = '$Id$'
# Copyright (c) 2005-2009 Vasco Nunes, Piotr Ożarowski
#
# 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 Library 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
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# You may use and distribute this software under the terms of the
# GNU General Public License, version 2 or later
import logging
import db
import gutils
log = logging.getLogger("Griffith")
def show_people_window(self):
self.widgets['people']['window'].show()
def hide_people_window(self):
self.widgets['people']['window'].hide()
def add_person(self):
clear_person(self)
self.widgets['person']['window'].show()
def add_person_cancel(self):
self.widgets['person']['window'].hide()
self.widgets['people']['window'].present()
def clear_person(self):
self.widgets['person']['name'].set_text('')
self.widgets['person']['email'].set_text('')
self.widgets['person']['phone'].set_text('')
def add_person_db(self):
name = self.widgets['person']['name'].get_text().decode('utf-8')
if name:
p = db.Person()
try:
p.name = self.widgets['person']['name'].get_text().decode('utf-8')
p.email = self.widgets['person']['email'].get_text().decode('utf-8')
p.phone = gutils.digits_only(self.widgets['person']['phone'].get_text().decode('utf-8'))
except ValueError, e:
gutils.warning(e.message)
return False
self.widgets['person']['window'].hide()
self.db.session.add(p)
try:
self.db.session.commit()
except Exception, e:
self.db.session.rollback()
log.info(str(e))
else:
myiter = self.p_treemodel.insert_after(None, None)
self.p_treemodel.set_value(myiter, 0, p.name)
self.p_treemodel.set_value(myiter, 1, p.email)
self.widgets['people']['window'].present()
else:
gutils.error(_("You should fill the person name"))
def edit_person(self):
try:
treeselection = self.widgets['people']['treeview'].get_selection()
(tmp_model, tmp_iter) = treeselection.get_selected()
name = tmp_model.get_value(tmp_iter,0).decode('utf-8')
except:
return
p = self.db.session.query(db.Person).filter_by(name=name).first()
if p:
self.widgets['person']['e_name'].set_text(p.name)
self.widgets['person']['e_email'].set_text(p.email)
self.widgets['person']['e_phone'].set_text(p.phone)
self.widgets['person']['e_id'].set_text(str(p.person_id))
self.widgets['person']['e_window'].show()
def edit_person_cancel(self):
self.widgets['person']['e_window'].hide()
self.widgets['people']['window'].present()
def update_person(self):
p = self.db.session.query(db.Person).filter_by(person_id=self.widgets['person']['e_id'].get_text().decode('utf-8')).first()
if not p:
log.warning('Person not found')
return False
try:
p.name = self.widgets['person']['e_name'].get_text().decode('utf-8')
p.email = self.widgets['person']['e_email'].get_text().decode('utf-8')
p.phone = self.widgets['person']['e_phone'].get_text().decode('utf-8')
except ValueError, e:
gutils.warning(e.message)
return False
self.db.session.add(p)
try:
self.db.session.commit()
except Exception, e:
self.db.session.rollback()
log.info(str(e))
else:
self.update_statusbar(_("Record updated"))
edit_person_cancel(self)
self.p_treemodel.clear()
for p in self.db.session.query(db.Person.name, db.Person.email).order_by(db.Person.name.asc()).all():
myiter = self.p_treemodel.insert_before(None, None)
self.p_treemodel.set_value(myiter, 0, p.name)
self.p_treemodel.set_value(myiter, 1, p.email)
def delete_person(self):
has_history = False
has_history_msg = ''
try:
treeselection = self.widgets['people']['treeview'].get_selection()
(tmp_model, tmp_iter) = treeselection.get_selected()
person = tmp_model.get_value(tmp_iter,0).decode('utf-8')
except:
return
person = self.db.session.query(db.Person).filter_by(name=person).first()
if not person:
return False
if person.loaned_movies_count > 0:
gutils.info(_("This person has loaned films from you. Return them first."), self.widgets['people']['window'])
return False
if person.returned_movies_count > 0:
has_history = True
has_history_msg = _("This person has data in the loan history. This data will be erased if you continue.")
if gutils.question(_("%s\nAre you sure you want to delete this person?" % has_history_msg), self.widgets['people']['window']):
treeselection = self.widgets['people']['treeview'].get_selection()
(tmp_model, tmp_iter) = treeselection.get_selected()
self.db.session.delete(person)
try:
self.db.session.commit()
except Exception, e:
log.info(str(e))
else:
self.p_treemodel.remove(tmp_iter)
self.treeview_clicked()
self.widgets['people']['window'].present()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
363,
5792,
363,
275,
4505,
1304,
12913,
199,
199,
3,
1898,
334,
67,
9,
11811,
13,
8664,
812,
305,
331,
653,
324,
397,
12,
19835,
357,
82,
593,
130,
121,
285,
19844,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
199,
199,
3,
2047,
1443,
675,
436,
11207,
642,
2032,
1334,
314,
2895,
402,
314,
199,
3,
1664,
1696,
1684,
844,
12,
1015,
499,
503,
2945,
199,
199,
646,
2050,
199,
199,
646,
1592,
199,
646,
486,
1208,
199,
199,
793,
275,
2050,
14,
5572,
480,
39,
322,
11286,
273,
531,
199,
199,
318,
2498,
63,
13562,
63,
3806,
8,
277,
304,
272,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
2384,
342,
199,
199,
318,
13714,
63,
13562,
63,
3806,
8,
277,
304,
272,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
8191,
342,
199,
199,
318,
1050,
63,
5484,
8,
277,
304,
272,
5436,
63,
5484,
8,
277,
9,
272,
291,
14,
8583,
459,
5484,
2545,
3806,
2278,
2384,
342,
199,
199,
318,
1050,
63,
5484,
63,
6406,
8,
277,
304,
272,
291,
14,
8583,
459,
5484,
2545,
3806,
2278,
8191,
342,
272,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
1881,
342,
199,
199,
318,
5436,
63,
5484,
8,
277,
304,
272,
291,
14,
8583,
459,
5484,
2545,
354,
2278,
409,
63,
505,
8355,
272,
291,
14,
8583,
459,
5484,
2545,
2123,
2278,
409,
63,
505,
8355,
272,
291,
14,
8583,
459,
5484,
2545,
9339,
2278,
409,
63,
505,
8355,
199,
199,
318,
1050,
63,
5484,
63,
697,
8,
277,
304,
272,
536,
275,
291,
14,
8583,
459,
5484,
2545,
354,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
358,
272,
340,
536,
26,
267,
299,
275,
1592,
14,
7344,
342,
267,
862,
26,
288,
299,
14,
354,
275,
291,
14,
8583,
459,
5484,
2545,
354,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
358,
288,
299,
14,
2123,
275,
291,
14,
8583,
459,
5484,
2545,
2123,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
358,
288,
299,
14,
9339,
275,
486,
1208,
14,
7022,
63,
2118,
8,
277,
14,
8583,
459,
5484,
2545,
9339,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
1333,
267,
871,
1722,
12,
325,
26,
288,
486,
1208,
14,
3764,
8,
69,
14,
1188,
9,
288,
372,
756,
267,
291,
14,
8583,
459,
5484,
2545,
3806,
2278,
8191,
342,
267,
291,
14,
697,
14,
1730,
14,
525,
8,
80,
9,
267,
862,
26,
288,
291,
14,
697,
14,
1730,
14,
3543,
342,
267,
871,
2186,
12,
325,
26,
288,
291,
14,
697,
14,
1730,
14,
10437,
342,
288,
943,
14,
815,
8,
495,
8,
69,
430,
267,
587,
26,
288,
3002,
1661,
275,
291,
14,
80,
63,
2350,
1238,
14,
3176,
63,
4399,
8,
403,
12,
488,
9,
288,
291,
14,
80,
63,
2350,
1238,
14,
409,
63,
585,
8,
1662,
1661,
12,
378,
12,
299,
14,
354,
9,
288,
291,
14,
80,
63,
2350,
1238,
14,
409,
63,
585,
8,
1662,
1661,
12,
413,
12,
299,
14,
2123,
9,
267,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
1881,
342,
272,
587,
26,
267,
486,
1208,
14,
705,
6115,
5556,
1077,
5554,
314,
4954,
536,
2237,
199,
199,
318,
5283,
63,
5484,
8,
277,
304,
272,
862,
26,
267,
3123,
5592,
275,
291,
14,
8583,
459,
13562,
2545,
32440,
2278,
362,
63,
5592,
342,
267,
334,
2791,
63,
1238,
12,
3529,
63,
1661,
9,
275,
3123,
5592,
14,
362,
63,
5511,
342,
267,
536,
275,
3529,
63,
1238,
14,
362,
63,
585,
8,
2791,
63,
1661,
12,
16,
680,
2708,
360,
1624,
13,
24,
358,
272,
871,
26,
267,
372,
272,
299,
275,
291,
14,
697,
14,
1730,
14,
1131,
8,
697,
14,
7344,
680,
1541,
63,
991,
8,
354,
29,
354,
680,
2246,
342,
272,
340,
299,
26,
267,
291,
14,
8583,
459,
5484,
2545,
69,
63,
354,
2278,
409,
63,
505,
8,
80,
14,
354,
9,
267,
291,
14,
8583,
459,
5484,
2545,
69,
63,
2123,
2278,
409,
63,
505,
8,
80,
14,
2123,
9,
267,
291,
14,
8583,
459,
5484,
2545,
69,
63,
9339,
2278,
409,
63,
505,
8,
80,
14,
9339,
9,
267,
291,
14,
8583,
459,
5484,
2545,
69,
63,
344,
2278,
409,
63,
505,
8,
495,
8,
80,
14,
5484,
63,
344,
430,
272,
291,
14,
8583,
459,
5484,
2545,
69,
63,
3806,
2278,
2384,
342,
199,
199,
318,
5283,
63,
5484,
63,
6406,
8,
277,
304,
272,
291,
14,
8583,
459,
5484,
2545,
69,
63,
3806,
2278,
8191,
342,
272,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
1881,
342,
199,
199,
318,
1678,
63,
5484,
8,
277,
304,
272,
299,
275,
291,
14,
697,
14,
1730,
14,
1131,
8,
697,
14,
7344,
680,
1541,
63,
991,
8,
5484,
63,
344,
29,
277,
14,
8583,
459,
5484,
2545,
69,
63,
344,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
11103,
2246,
342,
272,
340,
440,
299,
26,
267,
943,
14,
3764,
360,
7344,
440,
1911,
358,
267,
372,
756,
272,
862,
26,
267,
299,
14,
354,
275,
291,
14,
8583,
459,
5484,
2545,
69,
63,
354,
2278,
362,
63,
505,
1252,
2708,
360,
1624
] |
[
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
363,
5792,
363,
275,
4505,
1304,
12913,
199,
199,
3,
1898,
334,
67,
9,
11811,
13,
8664,
812,
305,
331,
653,
324,
397,
12,
19835,
357,
82,
593,
130,
121,
285,
19844,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
199,
199,
3,
2047,
1443,
675,
436,
11207,
642,
2032,
1334,
314,
2895,
402,
314,
199,
3,
1664,
1696,
1684,
844,
12,
1015,
499,
503,
2945,
199,
199,
646,
2050,
199,
199,
646,
1592,
199,
646,
486,
1208,
199,
199,
793,
275,
2050,
14,
5572,
480,
39,
322,
11286,
273,
531,
199,
199,
318,
2498,
63,
13562,
63,
3806,
8,
277,
304,
272,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
2384,
342,
199,
199,
318,
13714,
63,
13562,
63,
3806,
8,
277,
304,
272,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
8191,
342,
199,
199,
318,
1050,
63,
5484,
8,
277,
304,
272,
5436,
63,
5484,
8,
277,
9,
272,
291,
14,
8583,
459,
5484,
2545,
3806,
2278,
2384,
342,
199,
199,
318,
1050,
63,
5484,
63,
6406,
8,
277,
304,
272,
291,
14,
8583,
459,
5484,
2545,
3806,
2278,
8191,
342,
272,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
1881,
342,
199,
199,
318,
5436,
63,
5484,
8,
277,
304,
272,
291,
14,
8583,
459,
5484,
2545,
354,
2278,
409,
63,
505,
8355,
272,
291,
14,
8583,
459,
5484,
2545,
2123,
2278,
409,
63,
505,
8355,
272,
291,
14,
8583,
459,
5484,
2545,
9339,
2278,
409,
63,
505,
8355,
199,
199,
318,
1050,
63,
5484,
63,
697,
8,
277,
304,
272,
536,
275,
291,
14,
8583,
459,
5484,
2545,
354,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
358,
272,
340,
536,
26,
267,
299,
275,
1592,
14,
7344,
342,
267,
862,
26,
288,
299,
14,
354,
275,
291,
14,
8583,
459,
5484,
2545,
354,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
358,
288,
299,
14,
2123,
275,
291,
14,
8583,
459,
5484,
2545,
2123,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
358,
288,
299,
14,
9339,
275,
486,
1208,
14,
7022,
63,
2118,
8,
277,
14,
8583,
459,
5484,
2545,
9339,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
1333,
267,
871,
1722,
12,
325,
26,
288,
486,
1208,
14,
3764,
8,
69,
14,
1188,
9,
288,
372,
756,
267,
291,
14,
8583,
459,
5484,
2545,
3806,
2278,
8191,
342,
267,
291,
14,
697,
14,
1730,
14,
525,
8,
80,
9,
267,
862,
26,
288,
291,
14,
697,
14,
1730,
14,
3543,
342,
267,
871,
2186,
12,
325,
26,
288,
291,
14,
697,
14,
1730,
14,
10437,
342,
288,
943,
14,
815,
8,
495,
8,
69,
430,
267,
587,
26,
288,
3002,
1661,
275,
291,
14,
80,
63,
2350,
1238,
14,
3176,
63,
4399,
8,
403,
12,
488,
9,
288,
291,
14,
80,
63,
2350,
1238,
14,
409,
63,
585,
8,
1662,
1661,
12,
378,
12,
299,
14,
354,
9,
288,
291,
14,
80,
63,
2350,
1238,
14,
409,
63,
585,
8,
1662,
1661,
12,
413,
12,
299,
14,
2123,
9,
267,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
1881,
342,
272,
587,
26,
267,
486,
1208,
14,
705,
6115,
5556,
1077,
5554,
314,
4954,
536,
2237,
199,
199,
318,
5283,
63,
5484,
8,
277,
304,
272,
862,
26,
267,
3123,
5592,
275,
291,
14,
8583,
459,
13562,
2545,
32440,
2278,
362,
63,
5592,
342,
267,
334,
2791,
63,
1238,
12,
3529,
63,
1661,
9,
275,
3123,
5592,
14,
362,
63,
5511,
342,
267,
536,
275,
3529,
63,
1238,
14,
362,
63,
585,
8,
2791,
63,
1661,
12,
16,
680,
2708,
360,
1624,
13,
24,
358,
272,
871,
26,
267,
372,
272,
299,
275,
291,
14,
697,
14,
1730,
14,
1131,
8,
697,
14,
7344,
680,
1541,
63,
991,
8,
354,
29,
354,
680,
2246,
342,
272,
340,
299,
26,
267,
291,
14,
8583,
459,
5484,
2545,
69,
63,
354,
2278,
409,
63,
505,
8,
80,
14,
354,
9,
267,
291,
14,
8583,
459,
5484,
2545,
69,
63,
2123,
2278,
409,
63,
505,
8,
80,
14,
2123,
9,
267,
291,
14,
8583,
459,
5484,
2545,
69,
63,
9339,
2278,
409,
63,
505,
8,
80,
14,
9339,
9,
267,
291,
14,
8583,
459,
5484,
2545,
69,
63,
344,
2278,
409,
63,
505,
8,
495,
8,
80,
14,
5484,
63,
344,
430,
272,
291,
14,
8583,
459,
5484,
2545,
69,
63,
3806,
2278,
2384,
342,
199,
199,
318,
5283,
63,
5484,
63,
6406,
8,
277,
304,
272,
291,
14,
8583,
459,
5484,
2545,
69,
63,
3806,
2278,
8191,
342,
272,
291,
14,
8583,
459,
13562,
2545,
3806,
2278,
1881,
342,
199,
199,
318,
1678,
63,
5484,
8,
277,
304,
272,
299,
275,
291,
14,
697,
14,
1730,
14,
1131,
8,
697,
14,
7344,
680,
1541,
63,
991,
8,
5484,
63,
344,
29,
277,
14,
8583,
459,
5484,
2545,
69,
63,
344,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
13,
24,
11103,
2246,
342,
272,
340,
440,
299,
26,
267,
943,
14,
3764,
360,
7344,
440,
1911,
358,
267,
372,
756,
272,
862,
26,
267,
299,
14,
354,
275,
291,
14,
8583,
459,
5484,
2545,
69,
63,
354,
2278,
362,
63,
505,
1252,
2708,
360,
1624,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
andlima/olheiro
|
olheiro.py
|
1
|
3435
|
#!/usr/bin/python
import os
import mercado
ARQUIVO_MOD = 'olheiro.mod'
ARQUIVO_DAT = 'olheiro.dat'
GLPSOL_EXEC = 'glpsol -m %s -d %s' % (ARQUIVO_MOD, ARQUIVO_DAT)
LISTA_CONJUNTOS = ['S_Jogadores', 'S_Posicoes', 'S_Formacoes']
LISTA_PARAMETROS = ['P_Patrimonio', 'P_Preco', 'P_Media',
'Pe_Posicao', 'P_Quantidade']
DEFAULT = {'P_Patrimonio': 0.0, 'P_Preco': 0.0,
'P_Media': 0.0, 'P_Quantidade': 0.0}
FORMACOES = {
'343': {
'TEC': 1,
'GOL': 1,
'ZAG': 3,
'MEI': 4,
'ATA': 3,
},
'352': {
'TEC': 1,
'GOL': 1,
'ZAG': 3,
'MEI': 5,
'ATA': 2,
},
'433': {
'TEC': 1,
'GOL': 1,
'ZAG': 2,
'LAT': 2,
'MEI': 3,
'ATA': 3,
},
'442': {
'TEC': 1,
'GOL': 1,
'ZAG': 2,
'LAT': 2,
'MEI': 4,
'ATA': 2,
},
'451': {
'TEC': 1,
'GOL': 1,
'ZAG': 2,
'LAT': 2,
'MEI': 5,
'ATA': 1,
},
}
def gravaConjunto(arq, nome, conteudo):
'''Grava o conteudo de um conjunto no formato DAT.'''
_conteudo = ' '.join(map(lambda z: str(z), conteudo))
arq.write('set %s := %s;\n' % (nome, _conteudo))
def gravaParametro(arq, nome, conteudo, default_=None):
'''Grava o conteudo de um parametro no formato DAT;
o parametro que pode ou nao ter um valor
default (argumento 'default_').'''
arq.write('param %s ' % nome)
if default_ is not None:
arq.write('default %s ' % str(default_))
arq.write(':= \n')
for item in conteudo:
arq.write(' ')
for i in item:
arq.write('%s ' % str(i))
arq.write('\n')
arq.write(';\n')
def identify(j):
return ("'%s : %s'" % (j.apelido, j.clube.slug)).encode('iso-8859-1')
if __name__ == '__main__':
cenario = mercado.busca_mercado()
print ('Filtrando apenas jogadores com status provavel e '
'pelo menos tres jogos.')
cenario.jogadores = [j for j in cenario.jogadores
if (j.status_id == 7 and
j.jogos >= 3)]
data = {}
data['S_Jogadores'] = [identify(j) for j in cenario.jogadores]
data['S_Posicoes'] = list(set("'%s'" % j.posicao
for j in cenario.jogadores))
data['S_Formacoes'] = ["'%s'" % f for f in FORMACOES.keys()]
data['P_Patrimonio'] = [(raw_input('Patrimonio: '),)]
data['P_Preco'] = [(identify(j), j.preco) for j in cenario.jogadores]
data['P_Media'] = [(identify(j), j.media) for j in cenario.jogadores]
data['Pe_Posicao'] = [(identify(j), j.posicao) for j in cenario.jogadores]
data['P_Quantidade'] = [
("'%s'" % f, "'%s'" % p, FORMACOES[f][p])
for p in FORMACOES[f].keys()
for f in FORMACOES.keys()]
arq = open(ARQUIVO_DAT, 'w')
for conj in LISTA_CONJUNTOS:
gravaConjunto(arq, conj, data.get(conj, []))
for param in LISTA_PARAMETROS:
gravaParametro(arq, param, data.get(param, []),
DEFAULT.get(param))
arq.close()
output = os.popen(GLPSOL_EXEC)
skip = True
for linha in output:
if 'Model has been successfully processed' in linha:
break
if 'Resultado da otimizacao' in linha:
skip = False
if not skip:
print linha,
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
747,
199,
199,
646,
562,
1195,
5129,
199,
199,
689,
2328,
6882,
47,
63,
8816,
275,
283,
393,
426,
14352,
14,
1494,
7,
199,
689,
2328,
6882,
47,
63,
6521,
275,
283,
393,
426,
14352,
14,
4616,
7,
199,
2226,
5067,
2228,
63,
10276,
275,
283,
3528,
1190,
393,
446,
77,
450,
83,
446,
68,
450,
83,
7,
450,
334,
689,
2328,
6882,
47,
63,
8816,
12,
4160,
2328,
6882,
47,
63,
6521,
9,
199,
4924,
33,
63,
1864,
42,
1734,
2566,
51,
275,
788,
51,
63,
42,
974,
5129,
470,
297,
283,
51,
63,
1575,
338,
331,
397,
297,
283,
51,
63,
1858,
391,
331,
397,
418,
199,
4924,
33,
63,
11755,
1092,
51,
275,
788,
48,
63,
48,
292,
322,
2106,
2308,
297,
283,
48,
63,
2398,
331,
297,
283,
48,
63,
11398,
297,
490,
283,
8070,
63,
1575,
338,
696,
79,
297,
283,
48,
63,
2371,
4466,
983,
271,
418,
199,
3472,
275,
791,
48,
63,
48,
292,
322,
2106,
2308,
356,
378,
14,
16,
12,
283,
48,
63,
2398,
331,
356,
378,
14,
16,
12,
1779,
283,
48,
63,
11398,
356,
378,
14,
16,
12,
283,
48,
63,
2371,
4466,
983,
271,
356,
378,
14,
16,
93,
199,
3516,
1348,
47,
654,
275,
469,
272,
283,
14761,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
650,
12,
267,
283,
3635,
41,
356,
841,
12,
267,
283,
2751,
356,
650,
12,
267,
1660,
272,
283,
15139,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
650,
12,
267,
283,
3635,
41,
356,
959,
12,
267,
283,
2751,
356,
499,
12,
267,
1660,
272,
283,
23404,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
499,
12,
267,
283,
20307,
356,
499,
12,
267,
283,
3635,
41,
356,
650,
12,
267,
283,
2751,
356,
650,
12,
267,
1660,
272,
283,
24338,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
499,
12,
267,
283,
20307,
356,
499,
12,
267,
283,
3635,
41,
356,
841,
12,
267,
283,
2751,
356,
499,
12,
267,
1660,
272,
283,
24723,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
499,
12,
267,
283,
20307,
356,
499,
12,
267,
283,
3635,
41,
356,
959,
12,
267,
283,
2751,
356,
413,
12,
267,
1660,
272,
789,
421,
199,
318,
1999,
3042,
714,
74,
24087,
8,
285,
81,
12,
949,
278,
12,
406,
266,
5916,
304,
272,
1449,
5761,
3042,
312,
406,
266,
5916,
477,
28236,
14643,
24087,
949,
1475,
79,
17971,
10595,
272,
485,
388,
266,
5916,
275,
283,
1987,
904,
8,
1130,
8,
2734,
1315,
26,
620,
8,
90,
395,
406,
266,
5916,
430,
272,
601,
81,
14,
952,
360,
409,
450,
83,
12952,
450,
83,
3779,
78,
7,
450,
334,
29897,
12,
485,
388,
266,
5916,
430,
421,
199,
318,
1999,
3042,
21438,
1374,
8,
285,
81,
12,
949,
278,
12,
406,
266,
5916,
12,
849,
10683,
403,
304,
272,
1449,
5761,
3042,
312,
406,
266,
5916,
477,
28236,
18117,
1374,
949,
1475,
79,
17971,
27,
272,
312,
18117,
1374,
17414,
299,
380,
29934,
302,
8035,
2044,
28236,
1139,
269,
272,
849,
334,
2094,
79,
283,
885,
63,
1959,
2344,
339,
601,
81,
14,
952,
360,
635,
450,
83,
283,
450,
949,
278,
9,
272,
340,
849,
63,
365,
440,
488,
26,
267,
601,
81,
14,
952,
360,
885,
450,
83,
283,
450,
620,
8,
885,
13309,
272,
601,
81,
14,
952,
6176,
29,
971,
78,
358,
339,
367,
1242,
315,
406,
266,
5916,
26,
267,
601,
81,
14,
952,
360,
259,
5320,
267,
367,
284,
315,
1242,
26,
288,
601,
81,
14,
952,
3508,
83,
283,
450,
620,
8,
73,
430,
267,
601,
81,
14,
952,
2258,
78,
358,
272,
601,
81,
14,
952,
360,
3779,
78,
358,
421,
199,
318,
10405,
8,
74,
304,
272,
372,
1689,
5956,
83,
520,
450,
83,
4065,
450,
334,
74,
14,
924,
317,
1117,
12,
1335,
14,
429,
3375,
14,
5464,
4992,
2143,
360,
4595,
13,
4830,
13,
17,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9679,
6936,
275,
562,
1195,
5129,
14,
464,
7101,
63,
278,
1195,
5129,
342,
339,
870,
661,
13079,
454,
22066,
282,
897,
305,
5225,
71,
5129,
470,
2414,
2004,
557,
3042,
1090,
325,
283,
1779,
283,
321,
320,
562,
12712,
307,
470,
5225,
71,
736,
2659,
272,
9679,
6936,
14,
743,
71,
5129,
470,
275,
359,
74,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
586,
340,
334,
74,
14,
1205,
63,
344,
508,
1520,
436,
2490,
1335,
14,
743,
71,
736,
2356,
650,
1874,
339,
666,
275,
1052,
339,
666,
459,
51,
63,
42,
974,
5129,
470,
418,
275,
359,
22232,
8,
74,
9,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
61,
272,
666,
459,
51,
63,
1575,
338,
331,
397,
418,
275,
769,
8,
409,
21065,
83,
4065,
450,
1335,
14,
555,
338,
696,
79,
3303,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
430,
272,
666,
459,
51,
63,
1858,
391,
331,
397,
418,
275,
2097,
5956,
83,
4065,
450,
289,
367,
289,
315,
2381,
9410,
47,
654,
14,
1612,
5106,
339,
666,
459,
48,
63,
48,
292,
322,
2106,
2308,
418,
275,
3842,
1773,
63,
1210,
360,
48,
292,
322,
2106,
2308,
26,
17748,
1874,
272,
666,
459,
48,
63,
2398,
331,
418,
275,
3842,
22232,
8,
74,
395,
1335,
14,
657,
331,
9,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
61,
272,
666,
459,
48,
63,
11398,
418,
275,
3842,
22232,
8,
74,
395,
1335,
14,
4603,
9,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
61,
272,
666,
459,
8070,
63,
1575,
338,
696,
79,
418,
275,
3842,
22232,
8,
74,
395,
1335,
14,
555,
338,
696,
79,
9
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
646,
747,
199,
199,
646,
562,
1195,
5129,
199,
199,
689,
2328,
6882,
47,
63,
8816,
275,
283,
393,
426,
14352,
14,
1494,
7,
199,
689,
2328,
6882,
47,
63,
6521,
275,
283,
393,
426,
14352,
14,
4616,
7,
199,
2226,
5067,
2228,
63,
10276,
275,
283,
3528,
1190,
393,
446,
77,
450,
83,
446,
68,
450,
83,
7,
450,
334,
689,
2328,
6882,
47,
63,
8816,
12,
4160,
2328,
6882,
47,
63,
6521,
9,
199,
4924,
33,
63,
1864,
42,
1734,
2566,
51,
275,
788,
51,
63,
42,
974,
5129,
470,
297,
283,
51,
63,
1575,
338,
331,
397,
297,
283,
51,
63,
1858,
391,
331,
397,
418,
199,
4924,
33,
63,
11755,
1092,
51,
275,
788,
48,
63,
48,
292,
322,
2106,
2308,
297,
283,
48,
63,
2398,
331,
297,
283,
48,
63,
11398,
297,
490,
283,
8070,
63,
1575,
338,
696,
79,
297,
283,
48,
63,
2371,
4466,
983,
271,
418,
199,
3472,
275,
791,
48,
63,
48,
292,
322,
2106,
2308,
356,
378,
14,
16,
12,
283,
48,
63,
2398,
331,
356,
378,
14,
16,
12,
1779,
283,
48,
63,
11398,
356,
378,
14,
16,
12,
283,
48,
63,
2371,
4466,
983,
271,
356,
378,
14,
16,
93,
199,
3516,
1348,
47,
654,
275,
469,
272,
283,
14761,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
650,
12,
267,
283,
3635,
41,
356,
841,
12,
267,
283,
2751,
356,
650,
12,
267,
1660,
272,
283,
15139,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
650,
12,
267,
283,
3635,
41,
356,
959,
12,
267,
283,
2751,
356,
499,
12,
267,
1660,
272,
283,
23404,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
499,
12,
267,
283,
20307,
356,
499,
12,
267,
283,
3635,
41,
356,
650,
12,
267,
283,
2751,
356,
650,
12,
267,
1660,
272,
283,
24338,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
499,
12,
267,
283,
20307,
356,
499,
12,
267,
283,
3635,
41,
356,
841,
12,
267,
283,
2751,
356,
499,
12,
267,
1660,
272,
283,
24723,
356,
469,
267,
283,
3727,
35,
356,
413,
12,
267,
283,
39,
2228,
356,
413,
12,
267,
283,
58,
1254,
356,
499,
12,
267,
283,
20307,
356,
499,
12,
267,
283,
3635,
41,
356,
959,
12,
267,
283,
2751,
356,
413,
12,
267,
1660,
272,
789,
421,
199,
318,
1999,
3042,
714,
74,
24087,
8,
285,
81,
12,
949,
278,
12,
406,
266,
5916,
304,
272,
1449,
5761,
3042,
312,
406,
266,
5916,
477,
28236,
14643,
24087,
949,
1475,
79,
17971,
10595,
272,
485,
388,
266,
5916,
275,
283,
1987,
904,
8,
1130,
8,
2734,
1315,
26,
620,
8,
90,
395,
406,
266,
5916,
430,
272,
601,
81,
14,
952,
360,
409,
450,
83,
12952,
450,
83,
3779,
78,
7,
450,
334,
29897,
12,
485,
388,
266,
5916,
430,
421,
199,
318,
1999,
3042,
21438,
1374,
8,
285,
81,
12,
949,
278,
12,
406,
266,
5916,
12,
849,
10683,
403,
304,
272,
1449,
5761,
3042,
312,
406,
266,
5916,
477,
28236,
18117,
1374,
949,
1475,
79,
17971,
27,
272,
312,
18117,
1374,
17414,
299,
380,
29934,
302,
8035,
2044,
28236,
1139,
269,
272,
849,
334,
2094,
79,
283,
885,
63,
1959,
2344,
339,
601,
81,
14,
952,
360,
635,
450,
83,
283,
450,
949,
278,
9,
272,
340,
849,
63,
365,
440,
488,
26,
267,
601,
81,
14,
952,
360,
885,
450,
83,
283,
450,
620,
8,
885,
13309,
272,
601,
81,
14,
952,
6176,
29,
971,
78,
358,
339,
367,
1242,
315,
406,
266,
5916,
26,
267,
601,
81,
14,
952,
360,
259,
5320,
267,
367,
284,
315,
1242,
26,
288,
601,
81,
14,
952,
3508,
83,
283,
450,
620,
8,
73,
430,
267,
601,
81,
14,
952,
2258,
78,
358,
272,
601,
81,
14,
952,
360,
3779,
78,
358,
421,
199,
318,
10405,
8,
74,
304,
272,
372,
1689,
5956,
83,
520,
450,
83,
4065,
450,
334,
74,
14,
924,
317,
1117,
12,
1335,
14,
429,
3375,
14,
5464,
4992,
2143,
360,
4595,
13,
4830,
13,
17,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9679,
6936,
275,
562,
1195,
5129,
14,
464,
7101,
63,
278,
1195,
5129,
342,
339,
870,
661,
13079,
454,
22066,
282,
897,
305,
5225,
71,
5129,
470,
2414,
2004,
557,
3042,
1090,
325,
283,
1779,
283,
321,
320,
562,
12712,
307,
470,
5225,
71,
736,
2659,
272,
9679,
6936,
14,
743,
71,
5129,
470,
275,
359,
74,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
586,
340,
334,
74,
14,
1205,
63,
344,
508,
1520,
436,
2490,
1335,
14,
743,
71,
736,
2356,
650,
1874,
339,
666,
275,
1052,
339,
666,
459,
51,
63,
42,
974,
5129,
470,
418,
275,
359,
22232,
8,
74,
9,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
61,
272,
666,
459,
51,
63,
1575,
338,
331,
397,
418,
275,
769,
8,
409,
21065,
83,
4065,
450,
1335,
14,
555,
338,
696,
79,
3303,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
430,
272,
666,
459,
51,
63,
1858,
391,
331,
397,
418,
275,
2097,
5956,
83,
4065,
450,
289,
367,
289,
315,
2381,
9410,
47,
654,
14,
1612,
5106,
339,
666,
459,
48,
63,
48,
292,
322,
2106,
2308,
418,
275,
3842,
1773,
63,
1210,
360,
48,
292,
322,
2106,
2308,
26,
17748,
1874,
272,
666,
459,
48,
63,
2398,
331,
418,
275,
3842,
22232,
8,
74,
395,
1335,
14,
657,
331,
9,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
61,
272,
666,
459,
48,
63,
11398,
418,
275,
3842,
22232,
8,
74,
395,
1335,
14,
4603,
9,
367,
1335,
315,
9679,
6936,
14,
743,
71,
5129,
470,
61,
272,
666,
459,
8070,
63,
1575,
338,
696,
79,
418,
275,
3842,
22232,
8,
74,
395,
1335,
14,
555,
338,
696,
79,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
100health/RedoxBlog
|
node_modules/grunt-docker/node_modules/docker/node_modules/pygmentize-bundled/vendor/pygments/build-3.3/pygments/formatters/img.py
|
94
|
18053
|
# -*- coding: utf-8 -*-
"""
pygments.formatters.img
~~~~~~~~~~~~~~~~~~~~~~~
Formatter for Pixmap output.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import sys
from pygments.formatter import Formatter
from pygments.util import get_bool_opt, get_int_opt, \
get_list_opt, get_choice_opt
# Import this carefully
try:
from PIL import Image, ImageDraw, ImageFont
pil_available = True
except ImportError:
pil_available = False
try:
import winreg
except ImportError:
_winreg = None
__all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter',
'BmpImageFormatter']
# For some unknown reason every font calls it something different
STYLES = {
'NORMAL': ['', 'Roman', 'Book', 'Normal', 'Regular', 'Medium'],
'ITALIC': ['Oblique', 'Italic'],
'BOLD': ['Bold'],
'BOLDITALIC': ['Bold Oblique', 'Bold Italic'],
}
# A sane default for modern systems
DEFAULT_FONT_NAME_NIX = 'Bitstream Vera Sans Mono'
DEFAULT_FONT_NAME_WIN = 'Courier New'
class PilNotAvailable(ImportError):
"""When Python imaging library is not available"""
class FontNotFound(Exception):
"""When there are no usable fonts specified"""
class FontManager(object):
"""
Manages a set of fonts: normal, italic, bold, etc...
"""
def __init__(self, font_name, font_size=14):
self.font_name = font_name
self.font_size = font_size
self.fonts = {}
self.encoding = None
if sys.platform.startswith('win'):
if not font_name:
self.font_name = DEFAULT_FONT_NAME_WIN
self._create_win()
else:
if not font_name:
self.font_name = DEFAULT_FONT_NAME_NIX
self._create_nix()
def _get_nix_font_path(self, name, style):
from subprocess import getstatusoutput
exit, out = getstatusoutput('fc-list "%s:style=%s" file' %
(name, style))
if not exit:
lines = out.splitlines()
if lines:
path = lines[0].strip().strip(':')
return path
def _create_nix(self):
for name in STYLES['NORMAL']:
path = self._get_nix_font_path(self.font_name, name)
if path is not None:
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
break
else:
raise FontNotFound('No usable fonts named: "%s"' %
self.font_name)
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
for stylename in STYLES[style]:
path = self._get_nix_font_path(self.font_name, stylename)
if path is not None:
self.fonts[style] = ImageFont.truetype(path, self.font_size)
break
else:
if style == 'BOLDITALIC':
self.fonts[style] = self.fonts['BOLD']
else:
self.fonts[style] = self.fonts['NORMAL']
def _lookup_win(self, key, basename, styles, fail=False):
for suffix in ('', ' (TrueType)'):
for style in styles:
try:
valname = '%s%s%s' % (basename, style and ' '+style, suffix)
val, _ = winreg.QueryValueEx(key, valname)
return val
except EnvironmentError:
continue
else:
if fail:
raise FontNotFound('Font %s (%s) not found in registry' %
(basename, styles[0]))
return None
def _create_win(self):
try:
key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\Windows NT\CurrentVersion\Fonts')
except EnvironmentError:
try:
key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\Windows\CurrentVersion\Fonts')
except EnvironmentError:
raise FontNotFound('Can\'t open Windows font registry key')
try:
path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True)
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
path = self._lookup_win(key, self.font_name, STYLES[style])
if path:
self.fonts[style] = ImageFont.truetype(path, self.font_size)
else:
if style == 'BOLDITALIC':
self.fonts[style] = self.fonts['BOLD']
else:
self.fonts[style] = self.fonts['NORMAL']
finally:
winreg.CloseKey(key)
def get_char_size(self):
"""
Get the character size.
"""
return self.fonts['NORMAL'].getsize('M')
def get_font(self, bold, oblique):
"""
Get the font based on bold and italic flags.
"""
if bold and oblique:
return self.fonts['BOLDITALIC']
elif bold:
return self.fonts['BOLD']
elif oblique:
return self.fonts['ITALIC']
else:
return self.fonts['NORMAL']
class ImageFormatter(Formatter):
"""
Create a PNG image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code.
*New in Pygments 0.10.*
Additional options accepted:
`image_format`
An image format to output to that is recognised by PIL, these include:
* "PNG" (default)
* "JPEG"
* "BMP"
* "GIF"
`line_pad`
The extra spacing (in pixels) between each line of text.
Default: 2
`font_name`
The font name to be used as the base font from which others, such as
bold and italic fonts will be generated. This really should be a
monospace font to look sane.
Default: "Bitstream Vera Sans Mono"
`font_size`
The font size in points to be used.
Default: 14
`image_pad`
The padding, in pixels to be used at each edge of the resulting image.
Default: 10
`line_numbers`
Whether line numbers should be shown: True/False
Default: True
`line_number_start`
The line number of the first line.
Default: 1
`line_number_step`
The step used when printing line numbers.
Default: 1
`line_number_bg`
The background colour (in "#123456" format) of the line number bar, or
None to use the style background color.
Default: "#eed"
`line_number_fg`
The text color of the line numbers (in "#123456"-like format).
Default: "#886"
`line_number_chars`
The number of columns of line numbers allowable in the line number
margin.
Default: 2
`line_number_bold`
Whether line numbers will be bold: True/False
Default: False
`line_number_italic`
Whether line numbers will be italicized: True/False
Default: False
`line_number_separator`
Whether a line will be drawn between the line number area and the
source code area: True/False
Default: True
`line_number_pad`
The horizontal padding (in pixels) between the line number margin, and
the source code area.
Default: 6
`hl_lines`
Specify a list of lines to be highlighted. *New in Pygments 1.2.*
Default: empty list
`hl_color`
Specify the color for highlighting lines. *New in Pygments 1.2.*
Default: highlight color of the selected style
"""
# Required by the pygments mapper
name = 'img'
aliases = ['img', 'IMG', 'png']
filenames = ['*.png']
unicodeoutput = False
default_image_format = 'png'
def __init__(self, **options):
"""
See the class docstring for explanation of options.
"""
if not pil_available:
raise PilNotAvailable(
'Python Imaging Library is required for this formatter')
Formatter.__init__(self, **options)
# Read the style
self.styles = dict(self.style)
if self.style.background_color is None:
self.background_color = '#fff'
else:
self.background_color = self.style.background_color
# Image options
self.image_format = get_choice_opt(
options, 'image_format', ['png', 'jpeg', 'gif', 'bmp'],
self.default_image_format, normcase=True)
self.image_pad = get_int_opt(options, 'image_pad', 10)
self.line_pad = get_int_opt(options, 'line_pad', 2)
# The fonts
fontsize = get_int_opt(options, 'font_size', 14)
self.fonts = FontManager(options.get('font_name', ''), fontsize)
self.fontw, self.fonth = self.fonts.get_char_size()
# Line number options
self.line_number_fg = options.get('line_number_fg', '#886')
self.line_number_bg = options.get('line_number_bg', '#eed')
self.line_number_chars = get_int_opt(options,
'line_number_chars', 2)
self.line_number_bold = get_bool_opt(options,
'line_number_bold', False)
self.line_number_italic = get_bool_opt(options,
'line_number_italic', False)
self.line_number_pad = get_int_opt(options, 'line_number_pad', 6)
self.line_numbers = get_bool_opt(options, 'line_numbers', True)
self.line_number_separator = get_bool_opt(options,
'line_number_separator', True)
self.line_number_step = get_int_opt(options, 'line_number_step', 1)
self.line_number_start = get_int_opt(options, 'line_number_start', 1)
if self.line_numbers:
self.line_number_width = (self.fontw * self.line_number_chars +
self.line_number_pad * 2)
else:
self.line_number_width = 0
self.hl_lines = []
hl_lines_str = get_list_opt(options, 'hl_lines', [])
for line in hl_lines_str:
try:
self.hl_lines.append(int(line))
except ValueError:
pass
self.hl_color = options.get('hl_color',
self.style.highlight_color) or '#f90'
self.drawables = []
def get_style_defs(self, arg=''):
raise NotImplementedError('The -S option is meaningless for the image '
'formatter. Use -O style=<stylename> instead.')
def _get_line_height(self):
"""
Get the height of a line.
"""
return self.fonth + self.line_pad
def _get_line_y(self, lineno):
"""
Get the Y coordinate of a line number.
"""
return lineno * self._get_line_height() + self.image_pad
def _get_char_width(self):
"""
Get the width of a character.
"""
return self.fontw
def _get_char_x(self, charno):
"""
Get the X coordinate of a character position.
"""
return charno * self.fontw + self.image_pad + self.line_number_width
def _get_text_pos(self, charno, lineno):
"""
Get the actual position for a character and line position.
"""
return self._get_char_x(charno), self._get_line_y(lineno)
def _get_linenumber_pos(self, lineno):
"""
Get the actual position for the start of a line number.
"""
return (self.image_pad, self._get_line_y(lineno))
def _get_text_color(self, style):
"""
Get the correct color for the token from the style.
"""
if style['color'] is not None:
fill = '#' + style['color']
else:
fill = '#000'
return fill
def _get_style_font(self, style):
"""
Get the correct font for the style.
"""
return self.fonts.get_font(style['bold'], style['italic'])
def _get_image_size(self, maxcharno, maxlineno):
"""
Get the required image size.
"""
return (self._get_char_x(maxcharno) + self.image_pad,
self._get_line_y(maxlineno + 0) + self.image_pad)
def _draw_linenumber(self, posno, lineno):
"""
Remember a line number drawable to paint later.
"""
self._draw_text(
self._get_linenumber_pos(posno),
str(lineno).rjust(self.line_number_chars),
font=self.fonts.get_font(self.line_number_bold,
self.line_number_italic),
fill=self.line_number_fg,
)
def _draw_text(self, pos, text, font, **kw):
"""
Remember a single drawable tuple to paint later.
"""
self.drawables.append((pos, text, font, kw))
def _create_drawables(self, tokensource):
"""
Create drawables for the token content.
"""
lineno = charno = maxcharno = 0
for ttype, value in tokensource:
while ttype not in self.styles:
ttype = ttype.parent
style = self.styles[ttype]
# TODO: make sure tab expansion happens earlier in the chain. It
# really ought to be done on the input, as to do it right here is
# quite complex.
value = value.expandtabs(4)
lines = value.splitlines(True)
#print lines
for i, line in enumerate(lines):
temp = line.rstrip('\n')
if temp:
self._draw_text(
self._get_text_pos(charno, lineno),
temp,
font = self._get_style_font(style),
fill = self._get_text_color(style)
)
charno += len(temp)
maxcharno = max(maxcharno, charno)
if line.endswith('\n'):
# add a line for each extra line in the value
charno = 0
lineno += 1
self.maxcharno = maxcharno
self.maxlineno = lineno
def _draw_line_numbers(self):
"""
Create drawables for the line numbers.
"""
if not self.line_numbers:
return
for p in range(self.maxlineno):
n = p + self.line_number_start
if (n % self.line_number_step) == 0:
self._draw_linenumber(p, n)
def _paint_line_number_bg(self, im):
"""
Paint the line number background on the image.
"""
if not self.line_numbers:
return
if self.line_number_fg is None:
return
draw = ImageDraw.Draw(im)
recth = im.size[-1]
rectw = self.image_pad + self.line_number_width - self.line_number_pad
draw.rectangle([(0, 0),
(rectw, recth)],
fill=self.line_number_bg)
draw.line([(rectw, 0), (rectw, recth)], fill=self.line_number_fg)
del draw
def format(self, tokensource, outfile):
"""
Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
tuples and write it into ``outfile``.
This implementation calculates where it should draw each token on the
pixmap, then calculates the required pixmap size and draws the items.
"""
self._create_drawables(tokensource)
self._draw_line_numbers()
im = Image.new(
'RGB',
self._get_image_size(self.maxcharno, self.maxlineno),
self.background_color
)
self._paint_line_number_bg(im)
draw = ImageDraw.Draw(im)
# Highlight
if self.hl_lines:
x = self.image_pad + self.line_number_width - self.line_number_pad + 1
recth = self._get_line_height()
rectw = im.size[0] - x
for linenumber in self.hl_lines:
y = self._get_line_y(linenumber - 1)
draw.rectangle([(x, y), (x + rectw, y + recth)],
fill=self.hl_color)
for pos, value, font, kw in self.drawables:
draw.text(pos, value, font=font, **kw)
im.save(outfile, self.image_format.upper())
# Add one formatter per format, so that the "-f gif" option gives the correct result
# when used in pygmentize.
class GifImageFormatter(ImageFormatter):
"""
Create a GIF image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code.
*New in Pygments 1.0.* (You could create GIF images before by passing a
suitable `image_format` option to the `ImageFormatter`.)
"""
name = 'img_gif'
aliases = ['gif']
filenames = ['*.gif']
default_image_format = 'gif'
class JpgImageFormatter(ImageFormatter):
"""
Create a JPEG image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code.
*New in Pygments 1.0.* (You could create JPEG images before by passing a
suitable `image_format` option to the `ImageFormatter`.)
"""
name = 'img_jpg'
aliases = ['jpg', 'jpeg']
filenames = ['*.jpg']
default_image_format = 'jpeg'
class BmpImageFormatter(ImageFormatter):
"""
Create a bitmap image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code.
*New in Pygments 1.0.* (You could create bitmap images before by passing a
suitable `image_format` option to the `ImageFormatter`.)
"""
name = 'img_bmp'
aliases = ['bmp', 'bitmap']
filenames = ['*.bmp']
default_image_format = 'bmp'
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
24270,
14,
4060,
272,
18294,
2878,
23597,
339,
31084,
367,
510,
12879,
1072,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
984,
199,
199,
504,
13277,
14,
8911,
492,
31084,
199,
504,
13277,
14,
1974,
492,
664,
63,
2245,
63,
2992,
12,
664,
63,
442,
63,
2992,
12,
971,
1362,
664,
63,
513,
63,
2992,
12,
664,
63,
5095,
63,
2992,
199,
199,
3,
3161,
642,
21191,
8525,
199,
893,
26,
272,
687,
14937,
492,
6047,
12,
6047,
9654,
12,
6047,
6986,
272,
299,
382,
63,
4561,
275,
715,
199,
2590,
3545,
26,
272,
299,
382,
63,
4561,
275,
756,
199,
199,
893,
26,
272,
492,
30748,
199,
2590,
3545,
26,
272,
485,
15658,
275,
488,
199,
199,
363,
452,
363,
275,
788,
3491,
7772,
297,
283,
39,
692,
3491,
7772,
297,
283,
42,
4198,
3491,
7772,
297,
1779,
283,
34,
311,
3491,
7772,
418,
421,
199,
3,
2104,
2005,
5809,
4499,
4036,
5023,
4882,
652,
6020,
3365,
199,
12307,
11344,
275,
469,
272,
283,
10765,
356,
258,
18179,
283,
50,
21604,
297,
283,
8696,
297,
283,
6241,
297,
283,
16038,
297,
283,
26139,
995,
272,
283,
649,
748,
948,
356,
258,
788,
11394,
317,
544,
297,
283,
7940,
17999,
995,
272,
283,
30144,
356,
755,
788,
26395,
995,
272,
283,
34,
2228,
3841,
748,
948,
356,
788,
26395,
17985,
317,
544,
297,
283,
26395,
2779,
17999,
995,
199,
93,
199,
199,
3,
437,
31648,
849,
367,
818,
11641,
10460,
199,
3472,
63,
18398,
63,
2339,
63,
46,
3867,
275,
283,
4734,
1745,
5444,
65,
428,
796,
10953,
79,
7,
199,
3472,
63,
18398,
63,
2339,
63,
7941,
275,
283,
35,
567,
4446,
7053,
7,
421,
199,
533,
18130,
1763,
11464,
8,
17825,
304,
272,
408,
11423,
2018,
18884,
1540,
3555,
365,
440,
2808,
624,
421,
199,
533,
26159,
4667,
8,
1726,
304,
272,
408,
11423,
2337,
787,
949,
18025,
26219,
2013,
624,
421,
199,
533,
26159,
2988,
8,
785,
304,
272,
408,
272,
21612,
282,
663,
402,
26219,
26,
3293,
12,
652,
17999,
12,
17268,
12,
5423,
1396,
272,
408,
339,
347,
636,
826,
721,
277,
12,
5023,
63,
354,
12,
5023,
63,
890,
29,
1079,
304,
267,
291,
14,
4246,
63,
354,
275,
5023,
63,
354,
267,
291,
14,
4246,
63,
890,
275,
5023,
63,
890,
267,
291,
14,
19864,
275,
1052,
267,
291,
14,
2991,
275,
488,
267,
340,
984,
14,
3246,
14,
2460,
360,
2676,
735,
288,
340,
440,
5023,
63,
354,
26,
355,
291,
14,
4246,
63,
354,
275,
6186,
63,
18398,
63,
2339,
63,
7941,
288,
291,
423,
981,
63,
2676,
342,
267,
587,
26,
288,
340,
440,
5023,
63,
354,
26,
355,
291,
14,
4246,
63,
354,
275,
6186,
63,
18398,
63,
2339,
63,
46,
3867,
288,
291,
423,
981,
63,
78,
1148,
342,
339,
347,
485,
362,
63,
78,
1148,
63,
4246,
63,
515,
8,
277,
12,
536,
12,
3449,
304,
267,
687,
3873,
492,
664,
1205,
1199,
267,
4458,
12,
734,
275,
664,
1205,
1199,
360,
3003,
13,
513,
2071,
83,
26,
2487,
2458,
83,
2,
570,
7,
450,
2511,
334,
354,
12,
3449,
430,
267,
340,
440,
4458,
26,
288,
2385,
275,
734,
14,
7644,
342,
288,
340,
2385,
26,
355,
931,
275,
2385,
59,
16,
1055,
1913,
1252,
1913,
11633,
355,
372,
931,
339,
347,
485,
981,
63,
78,
1148,
8,
277,
304,
267,
367,
536,
315,
428,
2099,
11344,
459,
10765,
2565,
288,
931,
275,
291,
423,
362,
63,
78,
1148,
63,
4246,
63,
515,
8,
277,
14,
4246,
63,
354,
12,
536,
9,
288,
340,
931,
365,
440,
488,
26,
355,
291,
14,
19864,
459,
10765,
418,
275,
6047,
6986,
14,
2052,
466,
8,
515,
12,
291,
14,
4246,
63,
890,
9,
355,
2059,
267,
587,
26,
288,
746,
26159,
4667,
360,
1944,
18025,
26219,
4310,
26,
2071,
83,
4507,
450,
3044,
291,
14,
4246,
63,
354,
9,
267,
367,
3449,
315,
661,
649,
748,
948,
297,
283,
30144,
297,
283,
34,
2228,
3841,
748,
948,
735,
288,
367,
3449,
354,
315,
428,
2099,
11344,
59,
2487,
2189,
355,
931,
275,
291,
423,
362,
63,
78,
1148,
63,
4246,
63,
515,
8,
277,
14,
4246,
63,
354,
12,
3449,
354,
9,
355,
340,
931,
365,
440,
488,
26,
490,
291,
14,
19864,
59,
2487,
61,
275,
6047,
6986,
14,
2052,
466,
8,
515,
12,
291,
14,
4246,
63,
890,
9,
490,
2059,
288,
587,
26,
355,
340,
3449,
508,
283,
34,
2228,
3841,
748,
948,
356,
490,
291,
14,
19864,
59,
2487,
61,
275,
291,
14,
19864,
459,
30144,
418,
355,
587,
26,
490,
291,
14,
19864,
59,
2487,
61,
275,
291,
14,
19864,
459,
10765,
418,
339,
347,
485,
3892,
63,
2676,
8,
277,
12,
790,
12,
9593,
12,
15725,
12,
2449,
29,
797,
304,
267,
367,
4739,
315,
13134,
283,
334,
549,
804,
9,
735,
288,
367,
3449,
315,
15725,
26,
355,
862,
26,
490,
1139,
354,
275,
1543,
83,
5,
83,
5,
83,
7,
450,
334,
4846,
12,
3449,
436,
283,
6681,
2487,
12,
4739,
9,
490,
1139,
12,
485,
275,
30748,
14,
3227,
1110,
920,
8,
498,
12,
1139,
354,
9,
490,
372,
1139,
355,
871,
25139,
26,
490,
1980,
267,
587,
26,
288,
340,
2449,
26,
355,
746,
26159,
4667,
360,
6986,
450,
83,
4366,
83,
9,
440,
1911,
315,
7086,
7,
450,
3521,
334,
4846,
12,
15725,
59,
16,
2459,
288,
372,
488,
339,
347,
485,
981,
63,
2676,
8,
277,
304,
267,
862,
26,
288,
790,
275,
30748,
14,
28144,
8,
355,
30748,
14,
23802,
63,
7486,
63,
20890,
12,
355,
519,
7,
10337,
60,
12940,
60,
8647,
23350,
60,
5639,
3353,
60,
38,
13366,
358,
267,
871,
25139,
26,
288,
862,
26,
355,
790,
275,
30748,
14,
28144,
8,
490,
30748,
14,
23802,
63,
7486,
63,
20890,
12,
490,
519,
7,
10337,
60,
12940,
60,
8647,
60,
5639,
3353,
60,
38,
13366,
358,
288,
871,
25139,
26,
355,
746,
26159,
4667,
360,
6049,
3985,
84
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
24270,
14,
4060,
272,
18294,
2878,
23597,
339,
31084,
367,
510,
12879,
1072,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
984,
199,
199,
504,
13277,
14,
8911,
492,
31084,
199,
504,
13277,
14,
1974,
492,
664,
63,
2245,
63,
2992,
12,
664,
63,
442,
63,
2992,
12,
971,
1362,
664,
63,
513,
63,
2992,
12,
664,
63,
5095,
63,
2992,
199,
199,
3,
3161,
642,
21191,
8525,
199,
893,
26,
272,
687,
14937,
492,
6047,
12,
6047,
9654,
12,
6047,
6986,
272,
299,
382,
63,
4561,
275,
715,
199,
2590,
3545,
26,
272,
299,
382,
63,
4561,
275,
756,
199,
199,
893,
26,
272,
492,
30748,
199,
2590,
3545,
26,
272,
485,
15658,
275,
488,
199,
199,
363,
452,
363,
275,
788,
3491,
7772,
297,
283,
39,
692,
3491,
7772,
297,
283,
42,
4198,
3491,
7772,
297,
1779,
283,
34,
311,
3491,
7772,
418,
421,
199,
3,
2104,
2005,
5809,
4499,
4036,
5023,
4882,
652,
6020,
3365,
199,
12307,
11344,
275,
469,
272,
283,
10765,
356,
258,
18179,
283,
50,
21604,
297,
283,
8696,
297,
283,
6241,
297,
283,
16038,
297,
283,
26139,
995,
272,
283,
649,
748,
948,
356,
258,
788,
11394,
317,
544,
297,
283,
7940,
17999,
995,
272,
283,
30144,
356,
755,
788,
26395,
995,
272,
283,
34,
2228,
3841,
748,
948,
356,
788,
26395,
17985,
317,
544,
297,
283,
26395,
2779,
17999,
995,
199,
93,
199,
199,
3,
437,
31648,
849,
367,
818,
11641,
10460,
199,
3472,
63,
18398,
63,
2339,
63,
46,
3867,
275,
283,
4734,
1745,
5444,
65,
428,
796,
10953,
79,
7,
199,
3472,
63,
18398,
63,
2339,
63,
7941,
275,
283,
35,
567,
4446,
7053,
7,
421,
199,
533,
18130,
1763,
11464,
8,
17825,
304,
272,
408,
11423,
2018,
18884,
1540,
3555,
365,
440,
2808,
624,
421,
199,
533,
26159,
4667,
8,
1726,
304,
272,
408,
11423,
2337,
787,
949,
18025,
26219,
2013,
624,
421,
199,
533,
26159,
2988,
8,
785,
304,
272,
408,
272,
21612,
282,
663,
402,
26219,
26,
3293,
12,
652,
17999,
12,
17268,
12,
5423,
1396,
272,
408,
339,
347,
636,
826,
721,
277,
12,
5023,
63,
354,
12,
5023,
63,
890,
29,
1079,
304,
267,
291,
14,
4246,
63,
354,
275,
5023,
63,
354,
267,
291,
14,
4246,
63,
890,
275,
5023,
63,
890,
267,
291,
14,
19864,
275,
1052,
267,
291,
14,
2991,
275,
488,
267,
340,
984,
14,
3246,
14,
2460,
360,
2676,
735,
288,
340,
440,
5023,
63,
354,
26,
355,
291,
14,
4246,
63,
354,
275,
6186,
63,
18398,
63,
2339,
63,
7941,
288,
291,
423,
981,
63,
2676,
342,
267,
587,
26,
288,
340,
440,
5023,
63,
354,
26,
355,
291,
14,
4246,
63,
354,
275,
6186,
63,
18398,
63,
2339,
63,
46,
3867,
288,
291,
423,
981,
63,
78,
1148,
342,
339,
347,
485,
362,
63,
78,
1148,
63,
4246,
63,
515,
8,
277,
12,
536,
12,
3449,
304,
267,
687,
3873,
492,
664,
1205,
1199,
267,
4458,
12,
734,
275,
664,
1205,
1199,
360,
3003,
13,
513,
2071,
83,
26,
2487,
2458,
83,
2,
570,
7,
450,
2511,
334,
354,
12,
3449,
430,
267,
340,
440,
4458,
26,
288,
2385,
275,
734,
14,
7644,
342,
288,
340,
2385,
26,
355,
931,
275,
2385,
59,
16,
1055,
1913,
1252,
1913,
11633,
355,
372,
931,
339,
347,
485,
981,
63,
78,
1148,
8,
277,
304,
267,
367,
536,
315,
428,
2099,
11344,
459,
10765,
2565,
288,
931,
275,
291,
423,
362,
63,
78,
1148,
63,
4246,
63,
515,
8,
277,
14,
4246,
63,
354,
12,
536,
9,
288,
340,
931,
365,
440,
488,
26,
355,
291,
14,
19864,
459,
10765,
418,
275,
6047,
6986,
14,
2052,
466,
8,
515,
12,
291,
14,
4246,
63,
890,
9,
355,
2059,
267,
587,
26,
288,
746,
26159,
4667,
360,
1944,
18025,
26219,
4310,
26,
2071,
83,
4507,
450,
3044,
291,
14,
4246,
63,
354,
9,
267,
367,
3449,
315,
661,
649,
748,
948,
297,
283,
30144,
297,
283,
34,
2228,
3841,
748,
948,
735,
288,
367,
3449,
354,
315,
428,
2099,
11344,
59,
2487,
2189,
355,
931,
275,
291,
423,
362,
63,
78,
1148,
63,
4246,
63,
515,
8,
277,
14,
4246,
63,
354,
12,
3449,
354,
9,
355,
340,
931,
365,
440,
488,
26,
490,
291,
14,
19864,
59,
2487,
61,
275,
6047,
6986,
14,
2052,
466,
8,
515,
12,
291,
14,
4246,
63,
890,
9,
490,
2059,
288,
587,
26,
355,
340,
3449,
508,
283,
34,
2228,
3841,
748,
948,
356,
490,
291,
14,
19864,
59,
2487,
61,
275,
291,
14,
19864,
459,
30144,
418,
355,
587,
26,
490,
291,
14,
19864,
59,
2487,
61,
275,
291,
14,
19864,
459,
10765,
418,
339,
347,
485,
3892,
63,
2676,
8,
277,
12,
790,
12,
9593,
12,
15725,
12,
2449,
29,
797,
304,
267,
367,
4739,
315,
13134,
283,
334,
549,
804,
9,
735,
288,
367,
3449,
315,
15725,
26,
355,
862,
26,
490,
1139,
354,
275,
1543,
83,
5,
83,
5,
83,
7,
450,
334,
4846,
12,
3449,
436,
283,
6681,
2487,
12,
4739,
9,
490,
1139,
12,
485,
275,
30748,
14,
3227,
1110,
920,
8,
498,
12,
1139,
354,
9,
490,
372,
1139,
355,
871,
25139,
26,
490,
1980,
267,
587,
26,
288,
340,
2449,
26,
355,
746,
26159,
4667,
360,
6986,
450,
83,
4366,
83,
9,
440,
1911,
315,
7086,
7,
450,
3521,
334,
4846,
12,
15725,
59,
16,
2459,
288,
372,
488,
339,
347,
485,
981,
63,
2676,
8,
277,
304,
267,
862,
26,
288,
790,
275,
30748,
14,
28144,
8,
355,
30748,
14,
23802,
63,
7486,
63,
20890,
12,
355,
519,
7,
10337,
60,
12940,
60,
8647,
23350,
60,
5639,
3353,
60,
38,
13366,
358,
267,
871,
25139,
26,
288,
862,
26,
355,
790,
275,
30748,
14,
28144,
8,
490,
30748,
14,
23802,
63,
7486,
63,
20890,
12,
490,
519,
7,
10337,
60,
12940,
60,
8647,
60,
5639,
3353,
60,
38,
13366,
358,
288,
871,
25139,
26,
355,
746,
26159,
4667,
360,
6049,
3985,
84,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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Text types
"""
from scrapely.extractors import text as extract_text, safehtml
class _BaseTextProcessor(object):
"""basic text processor, defines identity functions, some of which
are overridden in subclasses
"""
def extract(self, text):
"""Matches and extracts any string, as it is"""
return text
def adapt(self, text, htmlpage):
return text
class RawFieldTypeProcessor(_BaseTextProcessor):
"""Extracts the raw data, without processing. Data is escaped for presentation
>>> from scrapely.extractors import htmlregion
>>> r = RawFieldTypeProcessor()
>>> html = htmlregion(u'<p>test</p>')
>>> r.extract(html)
u'<p>test</p>'
>>> r.adapt(html, None)
u'<p>test</p>'
"""
name = 'raw html'
description = 'raw html as it appears in the page'
class TextFieldTypeProcessor(_BaseTextProcessor):
"""Extracts strings, removing all HTML markup
>>> from scrapely.extractors import htmlregion
>>> p = TextFieldTypeProcessor()
>>> html = htmlregion(u'<p>test</p><!-- comment --><script> // script</script>!')
>>> extracted = p.extract(html)
>>> extracted
u'test !'
>>> p.adapt(extracted, None)
u'test !'
>>> html = htmlregion(u'<p> \\n<p>')
>>> p.extract(html)
u''
"""
name = 'text'
description = 'extracts text from web pages, cleaning all markup'
def extract(self, htmlregion):
return extract_text(htmlregion.text_content)
class SafeHtmlFieldTypeProcessor(_BaseTextProcessor):
"""Extracts strings, with only a safe subset of HTML remaining
Extraction checks for presence of text content, and adapt transforms the HTML
>>> from scrapely.extractors import htmlregion
>>> p = SafeHtmlFieldTypeProcessor()
>>> html = htmlregion(u'<p>test</p> <blink>foo')
>>> p.extract(html)
u'<p>test</p> <blink>foo'
>>> p.adapt(html)
u'<p>test</p> foo'
html without text must not be extracted
>>> html = htmlregion(u'<br/>')
"""
name = 'safe html'
description = 'removes all but a small subset of html tags'
def extract(self, htmlregion):
if extract_text(htmlregion.text_content):
return htmlregion
def adapt(self, text, htmlpage=None):
"""Remove html markup"""
return safehtml(text)
|
bsd-3-clause
|
[
624,
199,
1872,
2943,
199,
624,
199,
504,
10328,
321,
590,
14,
2911,
13451,
492,
1318,
465,
5536,
63,
505,
12,
5048,
1360,
199,
199,
533,
485,
1563,
1872,
10438,
8,
785,
304,
272,
408,
4316,
1318,
12495,
12,
7890,
8503,
3423,
12,
2005,
402,
1314,
5591,
787,
10087,
315,
9180,
272,
408,
272,
347,
5536,
8,
277,
12,
1318,
304,
267,
408,
12962,
436,
5536,
83,
1263,
1059,
12,
465,
652,
365,
624,
267,
372,
1318,
2286,
347,
19520,
8,
277,
12,
1318,
12,
3517,
1606,
304,
267,
372,
1318,
1362,
199,
533,
13480,
792,
804,
10438,
1547,
1563,
1872,
10438,
304,
272,
408,
12147,
83,
314,
3066,
666,
12,
1928,
6661,
14,
3918,
365,
11077,
367,
3451,
425,
2286,
1306,
687,
10328,
321,
590,
14,
2911,
13451,
492,
3517,
4551,
272,
1306,
519,
275,
13480,
792,
804,
10438,
342,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
80,
30,
396,
1108,
80,
5971,
272,
1306,
519,
14,
5005,
8,
1360,
9,
272,
399,
7601,
80,
30,
396,
1108,
80,
3524,
272,
1306,
519,
14,
19609,
8,
1360,
12,
488,
9,
272,
399,
7601,
80,
30,
396,
1108,
80,
3524,
272,
408,
272,
536,
275,
283,
1773,
3517,
7,
272,
1369,
275,
283,
1773,
3517,
465,
652,
11337,
315,
314,
2034,
7,
199,
199,
533,
4516,
792,
804,
10438,
1547,
1563,
1872,
10438,
304,
272,
408,
12147,
83,
3326,
12,
12881,
1006,
4163,
9189,
339,
1306,
687,
10328,
321,
590,
14,
2911,
13451,
492,
3517,
4551,
272,
1306,
299,
275,
4516,
792,
804,
10438,
342,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
80,
30,
396,
1108,
80,
2535,
17722,
3721,
1553,
2535,
1579,
30,
5001,
2884,
1108,
1579,
30,
10916,
272,
1306,
12509,
275,
299,
14,
5005,
8,
1360,
9,
272,
1306,
12509,
272,
399,
1133,
597,
8546,
7,
272,
1306,
299,
14,
19609,
8,
29939,
12,
488,
9,
272,
399,
1133,
597,
8546,
7,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
80,
18181,
10758,
27,
1103,
78,
28,
80,
5971,
272,
1306,
299,
14,
5005,
8,
1360,
9,
272,
399,
891,
272,
408,
272,
536,
275,
283,
505,
7,
272,
1369,
275,
283,
5005,
83,
1318,
687,
3330,
6497,
12,
29579,
1006,
9189,
7,
2286,
347,
5536,
8,
277,
12,
3517,
4551,
304,
267,
372,
5536,
63,
505,
8,
1360,
4551,
14,
505,
63,
1317,
9,
10813,
199,
533,
14969,
12957,
792,
804,
10438,
1547,
1563,
1872,
10438,
304,
272,
408,
12147,
83,
3326,
12,
543,
1454,
282,
5048,
10026,
402,
4163,
7971,
339,
7255,
6156,
5920,
367,
20024,
402,
1318,
1564,
12,
436,
19520,
18501,
314,
4163,
272,
1306,
687,
10328,
321,
590,
14,
2911,
13451,
492,
3517,
4551,
272,
1306,
299,
275,
14969,
12957,
792,
804,
10438,
342,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
80,
30,
396,
1108,
80,
30,
665,
24042,
30,
1421,
358,
272,
1306,
299,
14,
5005,
8,
1360,
9,
272,
399,
7601,
80,
30,
396,
1108,
80,
30,
665,
24042,
30,
1421,
7,
272,
1306,
299,
14,
19609,
8,
1360,
9,
272,
399,
7601,
80,
30,
396,
1108,
80,
30,
3925,
7,
2286,
3517,
1928,
1318,
1471,
440,
506,
12509,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
3289,
3133,
358,
339,
408,
272,
536,
275,
283,
3489,
3517,
7,
272,
1369,
275,
283,
264,
4912,
1006,
1325,
282,
7425,
10026,
402,
3517,
3762,
7,
272,
347,
5536,
8,
277,
12,
3517,
4551,
304,
267,
340,
5536,
63,
505,
8,
1360,
4551,
14,
505,
63,
1317,
304,
288,
372,
3517,
4551,
339,
347,
19520,
8,
277,
12,
1318,
12,
3517,
1606,
29,
403,
304,
267,
408,
5587,
3517,
9189,
624,
267,
372,
5048,
1360,
8,
505,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1872,
2943,
199,
624,
199,
504,
10328,
321,
590,
14,
2911,
13451,
492,
1318,
465,
5536,
63,
505,
12,
5048,
1360,
199,
199,
533,
485,
1563,
1872,
10438,
8,
785,
304,
272,
408,
4316,
1318,
12495,
12,
7890,
8503,
3423,
12,
2005,
402,
1314,
5591,
787,
10087,
315,
9180,
272,
408,
272,
347,
5536,
8,
277,
12,
1318,
304,
267,
408,
12962,
436,
5536,
83,
1263,
1059,
12,
465,
652,
365,
624,
267,
372,
1318,
2286,
347,
19520,
8,
277,
12,
1318,
12,
3517,
1606,
304,
267,
372,
1318,
1362,
199,
533,
13480,
792,
804,
10438,
1547,
1563,
1872,
10438,
304,
272,
408,
12147,
83,
314,
3066,
666,
12,
1928,
6661,
14,
3918,
365,
11077,
367,
3451,
425,
2286,
1306,
687,
10328,
321,
590,
14,
2911,
13451,
492,
3517,
4551,
272,
1306,
519,
275,
13480,
792,
804,
10438,
342,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
80,
30,
396,
1108,
80,
5971,
272,
1306,
519,
14,
5005,
8,
1360,
9,
272,
399,
7601,
80,
30,
396,
1108,
80,
3524,
272,
1306,
519,
14,
19609,
8,
1360,
12,
488,
9,
272,
399,
7601,
80,
30,
396,
1108,
80,
3524,
272,
408,
272,
536,
275,
283,
1773,
3517,
7,
272,
1369,
275,
283,
1773,
3517,
465,
652,
11337,
315,
314,
2034,
7,
199,
199,
533,
4516,
792,
804,
10438,
1547,
1563,
1872,
10438,
304,
272,
408,
12147,
83,
3326,
12,
12881,
1006,
4163,
9189,
339,
1306,
687,
10328,
321,
590,
14,
2911,
13451,
492,
3517,
4551,
272,
1306,
299,
275,
4516,
792,
804,
10438,
342,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
80,
30,
396,
1108,
80,
2535,
17722,
3721,
1553,
2535,
1579,
30,
5001,
2884,
1108,
1579,
30,
10916,
272,
1306,
12509,
275,
299,
14,
5005,
8,
1360,
9,
272,
1306,
12509,
272,
399,
1133,
597,
8546,
7,
272,
1306,
299,
14,
19609,
8,
29939,
12,
488,
9,
272,
399,
1133,
597,
8546,
7,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
80,
18181,
10758,
27,
1103,
78,
28,
80,
5971,
272,
1306,
299,
14,
5005,
8,
1360,
9,
272,
399,
891,
272,
408,
272,
536,
275,
283,
505,
7,
272,
1369,
275,
283,
5005,
83,
1318,
687,
3330,
6497,
12,
29579,
1006,
9189,
7,
2286,
347,
5536,
8,
277,
12,
3517,
4551,
304,
267,
372,
5536,
63,
505,
8,
1360,
4551,
14,
505,
63,
1317,
9,
10813,
199,
533,
14969,
12957,
792,
804,
10438,
1547,
1563,
1872,
10438,
304,
272,
408,
12147,
83,
3326,
12,
543,
1454,
282,
5048,
10026,
402,
4163,
7971,
339,
7255,
6156,
5920,
367,
20024,
402,
1318,
1564,
12,
436,
19520,
18501,
314,
4163,
272,
1306,
687,
10328,
321,
590,
14,
2911,
13451,
492,
3517,
4551,
272,
1306,
299,
275,
14969,
12957,
792,
804,
10438,
342,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
80,
30,
396,
1108,
80,
30,
665,
24042,
30,
1421,
358,
272,
1306,
299,
14,
5005,
8,
1360,
9,
272,
399,
7601,
80,
30,
396,
1108,
80,
30,
665,
24042,
30,
1421,
7,
272,
1306,
299,
14,
19609,
8,
1360,
9,
272,
399,
7601,
80,
30,
396,
1108,
80,
30,
3925,
7,
2286,
3517,
1928,
1318,
1471,
440,
506,
12509,
272,
1306,
3517,
275,
3517,
4551,
8,
85,
7601,
3289,
3133,
358,
339,
408,
272,
536,
275,
283,
3489,
3517,
7,
272,
1369,
275,
283,
264,
4912,
1006,
1325,
282,
7425,
10026,
402,
3517,
3762,
7,
272,
347,
5536,
8,
277,
12,
3517,
4551,
304,
267,
340,
5536,
63,
505,
8,
1360,
4551,
14,
505,
63,
1317,
304,
288,
372,
3517,
4551,
339,
347,
19520,
8,
277,
12,
1318,
12,
3517,
1606,
29,
403,
304,
267,
408,
5587,
3517,
9189,
624,
267,
372,
5048,
1360,
8,
505,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
hynnet/hiwifi-openwrt-HC5661-HC5761
|
staging_dir/host/lib/python2.7/test/test_argparse.py
|
20
|
151865
|
# Author: Steven J. Bethard <steven.bethard@gmail.com>.
import codecs
import inspect
import os
import shutil
import stat
import sys
import textwrap
import tempfile
import unittest
import argparse
from StringIO import StringIO
class StdIOBuffer(StringIO):
pass
from test import test_support
class TestCase(unittest.TestCase):
def assertEqual(self, obj1, obj2):
if obj1 != obj2:
print('')
print(repr(obj1))
print(repr(obj2))
print(obj1)
print(obj2)
super(TestCase, self).assertEqual(obj1, obj2)
def setUp(self):
# The tests assume that line wrapping occurs at 80 columns, but this
# behaviour can be overridden by setting the COLUMNS environment
# variable. To ensure that this assumption is true, unset COLUMNS.
env = test_support.EnvironmentVarGuard()
env.unset("COLUMNS")
self.addCleanup(env.__exit__)
class TempDirMixin(object):
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
self.old_dir = os.getcwd()
os.chdir(self.temp_dir)
def tearDown(self):
os.chdir(self.old_dir)
shutil.rmtree(self.temp_dir, True)
def create_readonly_file(self, filename):
file_path = os.path.join(self.temp_dir, filename)
with open(file_path, 'w') as file:
file.write(filename)
os.chmod(file_path, stat.S_IREAD)
class Sig(object):
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
class NS(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
sorted_items = sorted(self.__dict__.items())
kwarg_str = ', '.join(['%s=%r' % tup for tup in sorted_items])
return '%s(%s)' % (type(self).__name__, kwarg_str)
__hash__ = None
def __eq__(self, other):
return vars(self) == vars(other)
def __ne__(self, other):
return not (self == other)
class ArgumentParserError(Exception):
def __init__(self, message, stdout=None, stderr=None, error_code=None):
Exception.__init__(self, message, stdout, stderr)
self.message = message
self.stdout = stdout
self.stderr = stderr
self.error_code = error_code
def stderr_to_parser_error(parse_args, *args, **kwargs):
# if this is being called recursively and stderr or stdout is already being
# redirected, simply call the function and let the enclosing function
# catch the exception
if isinstance(sys.stderr, StdIOBuffer) or isinstance(sys.stdout, StdIOBuffer):
return parse_args(*args, **kwargs)
# if this is not being called recursively, redirect stderr and
# use it as the ArgumentParserError message
old_stdout = sys.stdout
old_stderr = sys.stderr
sys.stdout = StdIOBuffer()
sys.stderr = StdIOBuffer()
try:
try:
result = parse_args(*args, **kwargs)
for key in list(vars(result)):
if getattr(result, key) is sys.stdout:
setattr(result, key, old_stdout)
if getattr(result, key) is sys.stderr:
setattr(result, key, old_stderr)
return result
except SystemExit:
code = sys.exc_info()[1].code
stdout = sys.stdout.getvalue()
stderr = sys.stderr.getvalue()
raise ArgumentParserError("SystemExit", stdout, stderr, code)
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
class ErrorRaisingArgumentParser(argparse.ArgumentParser):
def parse_args(self, *args, **kwargs):
parse_args = super(ErrorRaisingArgumentParser, self).parse_args
return stderr_to_parser_error(parse_args, *args, **kwargs)
def exit(self, *args, **kwargs):
exit = super(ErrorRaisingArgumentParser, self).exit
return stderr_to_parser_error(exit, *args, **kwargs)
def error(self, *args, **kwargs):
error = super(ErrorRaisingArgumentParser, self).error
return stderr_to_parser_error(error, *args, **kwargs)
class ParserTesterMetaclass(type):
"""Adds parser tests using the class attributes.
Classes of this type should specify the following attributes:
argument_signatures -- a list of Sig objects which specify
the signatures of Argument objects to be created
failures -- a list of args lists that should cause the parser
to fail
successes -- a list of (initial_args, options, remaining_args) tuples
where initial_args specifies the string args to be parsed,
options is a dict that should match the vars() of the options
parsed out of initial_args, and remaining_args should be any
remaining unparsed arguments
"""
def __init__(cls, name, bases, bodydict):
if name == 'ParserTestCase':
return
# default parser signature is empty
if not hasattr(cls, 'parser_signature'):
cls.parser_signature = Sig()
if not hasattr(cls, 'parser_class'):
cls.parser_class = ErrorRaisingArgumentParser
# ---------------------------------------
# functions for adding optional arguments
# ---------------------------------------
def no_groups(parser, argument_signatures):
"""Add all arguments directly to the parser"""
for sig in argument_signatures:
parser.add_argument(*sig.args, **sig.kwargs)
def one_group(parser, argument_signatures):
"""Add all arguments under a single group in the parser"""
group = parser.add_argument_group('foo')
for sig in argument_signatures:
group.add_argument(*sig.args, **sig.kwargs)
def many_groups(parser, argument_signatures):
"""Add each argument in its own group to the parser"""
for i, sig in enumerate(argument_signatures):
group = parser.add_argument_group('foo:%i' % i)
group.add_argument(*sig.args, **sig.kwargs)
# --------------------------
# functions for parsing args
# --------------------------
def listargs(parser, args):
"""Parse the args by passing in a list"""
return parser.parse_args(args)
def sysargs(parser, args):
"""Parse the args by defaulting to sys.argv"""
old_sys_argv = sys.argv
sys.argv = [old_sys_argv[0]] + args
try:
return parser.parse_args()
finally:
sys.argv = old_sys_argv
# class that holds the combination of one optional argument
# addition method and one arg parsing method
class AddTests(object):
def __init__(self, tester_cls, add_arguments, parse_args):
self._add_arguments = add_arguments
self._parse_args = parse_args
add_arguments_name = self._add_arguments.__name__
parse_args_name = self._parse_args.__name__
for test_func in [self.test_failures, self.test_successes]:
func_name = test_func.__name__
names = func_name, add_arguments_name, parse_args_name
test_name = '_'.join(names)
def wrapper(self, test_func=test_func):
test_func(self)
try:
wrapper.__name__ = test_name
except TypeError:
pass
setattr(tester_cls, test_name, wrapper)
def _get_parser(self, tester):
args = tester.parser_signature.args
kwargs = tester.parser_signature.kwargs
parser = tester.parser_class(*args, **kwargs)
self._add_arguments(parser, tester.argument_signatures)
return parser
def test_failures(self, tester):
parser = self._get_parser(tester)
for args_str in tester.failures:
args = args_str.split()
raises = tester.assertRaises
raises(ArgumentParserError, parser.parse_args, args)
def test_successes(self, tester):
parser = self._get_parser(tester)
for args, expected_ns in tester.successes:
if isinstance(args, str):
args = args.split()
result_ns = self._parse_args(parser, args)
tester.assertEqual(expected_ns, result_ns)
# add tests for each combination of an optionals adding method
# and an arg parsing method
for add_arguments in [no_groups, one_group, many_groups]:
for parse_args in [listargs, sysargs]:
AddTests(cls, add_arguments, parse_args)
bases = TestCase,
ParserTestCase = ParserTesterMetaclass('ParserTestCase', bases, {})
# ===============
# Optionals tests
# ===============
class TestOptionalsSingleDash(ParserTestCase):
"""Test an Optional with a single-dash option string"""
argument_signatures = [Sig('-x')]
failures = ['-x', 'a', '--foo', '-x --foo', '-x -y']
successes = [
('', NS(x=None)),
('-x a', NS(x='a')),
('-xa', NS(x='a')),
('-x -1', NS(x='-1')),
('-x-1', NS(x='-1')),
]
class TestOptionalsSingleDashCombined(ParserTestCase):
"""Test an Optional with a single-dash option string"""
argument_signatures = [
Sig('-x', action='store_true'),
Sig('-yyy', action='store_const', const=42),
Sig('-z'),
]
failures = ['a', '--foo', '-xa', '-x --foo', '-x -z', '-z -x',
'-yx', '-yz a', '-yyyx', '-yyyza', '-xyza']
successes = [
('', NS(x=False, yyy=None, z=None)),
('-x', NS(x=True, yyy=None, z=None)),
('-za', NS(x=False, yyy=None, z='a')),
('-z a', NS(x=False, yyy=None, z='a')),
('-xza', NS(x=True, yyy=None, z='a')),
('-xz a', NS(x=True, yyy=None, z='a')),
('-x -za', NS(x=True, yyy=None, z='a')),
('-x -z a', NS(x=True, yyy=None, z='a')),
('-y', NS(x=False, yyy=42, z=None)),
('-yyy', NS(x=False, yyy=42, z=None)),
('-x -yyy -za', NS(x=True, yyy=42, z='a')),
('-x -yyy -z a', NS(x=True, yyy=42, z='a')),
]
class TestOptionalsSingleDashLong(ParserTestCase):
"""Test an Optional with a multi-character single-dash option string"""
argument_signatures = [Sig('-foo')]
failures = ['-foo', 'a', '--foo', '-foo --foo', '-foo -y', '-fooa']
successes = [
('', NS(foo=None)),
('-foo a', NS(foo='a')),
('-foo -1', NS(foo='-1')),
('-fo a', NS(foo='a')),
('-f a', NS(foo='a')),
]
class TestOptionalsSingleDashSubsetAmbiguous(ParserTestCase):
"""Test Optionals where option strings are subsets of each other"""
argument_signatures = [Sig('-f'), Sig('-foobar'), Sig('-foorab')]
failures = ['-f', '-foo', '-fo', '-foo b', '-foob', '-fooba', '-foora']
successes = [
('', NS(f=None, foobar=None, foorab=None)),
('-f a', NS(f='a', foobar=None, foorab=None)),
('-fa', NS(f='a', foobar=None, foorab=None)),
('-foa', NS(f='oa', foobar=None, foorab=None)),
('-fooa', NS(f='ooa', foobar=None, foorab=None)),
('-foobar a', NS(f=None, foobar='a', foorab=None)),
('-foorab a', NS(f=None, foobar=None, foorab='a')),
]
class TestOptionalsSingleDashAmbiguous(ParserTestCase):
"""Test Optionals that partially match but are not subsets"""
argument_signatures = [Sig('-foobar'), Sig('-foorab')]
failures = ['-f', '-f a', '-fa', '-foa', '-foo', '-fo', '-foo b']
successes = [
('', NS(foobar=None, foorab=None)),
('-foob a', NS(foobar='a', foorab=None)),
('-foor a', NS(foobar=None, foorab='a')),
('-fooba a', NS(foobar='a', foorab=None)),
('-foora a', NS(foobar=None, foorab='a')),
('-foobar a', NS(foobar='a', foorab=None)),
('-foorab a', NS(foobar=None, foorab='a')),
]
class TestOptionalsNumeric(ParserTestCase):
"""Test an Optional with a short opt string"""
argument_signatures = [Sig('-1', dest='one')]
failures = ['-1', 'a', '-1 --foo', '-1 -y', '-1 -1', '-1 -2']
successes = [
('', NS(one=None)),
('-1 a', NS(one='a')),
('-1a', NS(one='a')),
('-1-2', NS(one='-2')),
]
class TestOptionalsDoubleDash(ParserTestCase):
"""Test an Optional with a double-dash option string"""
argument_signatures = [Sig('--foo')]
failures = ['--foo', '-f', '-f a', 'a', '--foo -x', '--foo --bar']
successes = [
('', NS(foo=None)),
('--foo a', NS(foo='a')),
('--foo=a', NS(foo='a')),
('--foo -2.5', NS(foo='-2.5')),
('--foo=-2.5', NS(foo='-2.5')),
]
class TestOptionalsDoubleDashPartialMatch(ParserTestCase):
"""Tests partial matching with a double-dash option string"""
argument_signatures = [
Sig('--badger', action='store_true'),
Sig('--bat'),
]
failures = ['--bar', '--b', '--ba', '--b=2', '--ba=4', '--badge 5']
successes = [
('', NS(badger=False, bat=None)),
('--bat X', NS(badger=False, bat='X')),
('--bad', NS(badger=True, bat=None)),
('--badg', NS(badger=True, bat=None)),
('--badge', NS(badger=True, bat=None)),
('--badger', NS(badger=True, bat=None)),
]
class TestOptionalsDoubleDashPrefixMatch(ParserTestCase):
"""Tests when one double-dash option string is a prefix of another"""
argument_signatures = [
Sig('--badger', action='store_true'),
Sig('--ba'),
]
failures = ['--bar', '--b', '--ba', '--b=2', '--badge 5']
successes = [
('', NS(badger=False, ba=None)),
('--ba X', NS(badger=False, ba='X')),
('--ba=X', NS(badger=False, ba='X')),
('--bad', NS(badger=True, ba=None)),
('--badg', NS(badger=True, ba=None)),
('--badge', NS(badger=True, ba=None)),
('--badger', NS(badger=True, ba=None)),
]
class TestOptionalsSingleDoubleDash(ParserTestCase):
"""Test an Optional with single- and double-dash option strings"""
argument_signatures = [
Sig('-f', action='store_true'),
Sig('--bar'),
Sig('-baz', action='store_const', const=42),
]
failures = ['--bar', '-fbar', '-fbaz', '-bazf', '-b B', 'B']
successes = [
('', NS(f=False, bar=None, baz=None)),
('-f', NS(f=True, bar=None, baz=None)),
('--ba B', NS(f=False, bar='B', baz=None)),
('-f --bar B', NS(f=True, bar='B', baz=None)),
('-f -b', NS(f=True, bar=None, baz=42)),
('-ba -f', NS(f=True, bar=None, baz=42)),
]
class TestOptionalsAlternatePrefixChars(ParserTestCase):
"""Test an Optional with option strings with custom prefixes"""
parser_signature = Sig(prefix_chars='+:/', add_help=False)
argument_signatures = [
Sig('+f', action='store_true'),
Sig('::bar'),
Sig('/baz', action='store_const', const=42),
]
failures = ['--bar', '-fbar', '-b B', 'B', '-f', '--bar B', '-baz', '-h', '--help', '+h', '::help', '/help']
successes = [
('', NS(f=False, bar=None, baz=None)),
('+f', NS(f=True, bar=None, baz=None)),
('::ba B', NS(f=False, bar='B', baz=None)),
('+f ::bar B', NS(f=True, bar='B', baz=None)),
('+f /b', NS(f=True, bar=None, baz=42)),
('/ba +f', NS(f=True, bar=None, baz=42)),
]
class TestOptionalsAlternatePrefixCharsAddedHelp(ParserTestCase):
"""When ``-`` not in prefix_chars, default operators created for help
should use the prefix_chars in use rather than - or --
http://bugs.python.org/issue9444"""
parser_signature = Sig(prefix_chars='+:/', add_help=True)
argument_signatures = [
Sig('+f', action='store_true'),
Sig('::bar'),
Sig('/baz', action='store_const', const=42),
]
failures = ['--bar', '-fbar', '-b B', 'B', '-f', '--bar B', '-baz']
successes = [
('', NS(f=False, bar=None, baz=None)),
('+f', NS(f=True, bar=None, baz=None)),
('::ba B', NS(f=False, bar='B', baz=None)),
('+f ::bar B', NS(f=True, bar='B', baz=None)),
('+f /b', NS(f=True, bar=None, baz=42)),
('/ba +f', NS(f=True, bar=None, baz=42))
]
class TestOptionalsAlternatePrefixCharsMultipleShortArgs(ParserTestCase):
"""Verify that Optionals must be called with their defined prefixes"""
parser_signature = Sig(prefix_chars='+-', add_help=False)
argument_signatures = [
Sig('-x', action='store_true'),
Sig('+y', action='store_true'),
Sig('+z', action='store_true'),
]
failures = ['-w',
'-xyz',
'+x',
'-y',
'+xyz',
]
successes = [
('', NS(x=False, y=False, z=False)),
('-x', NS(x=True, y=False, z=False)),
('+y -x', NS(x=True, y=True, z=False)),
('+yz -x', NS(x=True, y=True, z=True)),
]
class TestOptionalsShortLong(ParserTestCase):
"""Test a combination of single- and double-dash option strings"""
argument_signatures = [
Sig('-v', '--verbose', '-n', '--noisy', action='store_true'),
]
failures = ['--x --verbose', '-N', 'a', '-v x']
successes = [
('', NS(verbose=False)),
('-v', NS(verbose=True)),
('--verbose', NS(verbose=True)),
('-n', NS(verbose=True)),
('--noisy', NS(verbose=True)),
]
class TestOptionalsDest(ParserTestCase):
"""Tests various means of setting destination"""
argument_signatures = [Sig('--foo-bar'), Sig('--baz', dest='zabbaz')]
failures = ['a']
successes = [
('--foo-bar f', NS(foo_bar='f', zabbaz=None)),
('--baz g', NS(foo_bar=None, zabbaz='g')),
('--foo-bar h --baz i', NS(foo_bar='h', zabbaz='i')),
('--baz j --foo-bar k', NS(foo_bar='k', zabbaz='j')),
]
class TestOptionalsDefault(ParserTestCase):
"""Tests specifying a default for an Optional"""
argument_signatures = [Sig('-x'), Sig('-y', default=42)]
failures = ['a']
successes = [
('', NS(x=None, y=42)),
('-xx', NS(x='x', y=42)),
('-yy', NS(x=None, y='y')),
]
class TestOptionalsNargsDefault(ParserTestCase):
"""Tests not specifying the number of args for an Optional"""
argument_signatures = [Sig('-x')]
failures = ['a', '-x']
successes = [
('', NS(x=None)),
('-x a', NS(x='a')),
]
class TestOptionalsNargs1(ParserTestCase):
"""Tests specifying the 1 arg for an Optional"""
argument_signatures = [Sig('-x', nargs=1)]
failures = ['a', '-x']
successes = [
('', NS(x=None)),
('-x a', NS(x=['a'])),
]
class TestOptionalsNargs3(ParserTestCase):
"""Tests specifying the 3 args for an Optional"""
argument_signatures = [Sig('-x', nargs=3)]
failures = ['a', '-x', '-x a', '-x a b', 'a -x', 'a -x b']
successes = [
('', NS(x=None)),
('-x a b c', NS(x=['a', 'b', 'c'])),
]
class TestOptionalsNargsOptional(ParserTestCase):
"""Tests specifying an Optional arg for an Optional"""
argument_signatures = [
Sig('-w', nargs='?'),
Sig('-x', nargs='?', const=42),
Sig('-y', nargs='?', default='spam'),
Sig('-z', nargs='?', type=int, const='42', default='84'),
]
failures = ['2']
successes = [
('', NS(w=None, x=None, y='spam', z=84)),
('-w', NS(w=None, x=None, y='spam', z=84)),
('-w 2', NS(w='2', x=None, y='spam', z=84)),
('-x', NS(w=None, x=42, y='spam', z=84)),
('-x 2', NS(w=None, x='2', y='spam', z=84)),
('-y', NS(w=None, x=None, y=None, z=84)),
('-y 2', NS(w=None, x=None, y='2', z=84)),
('-z', NS(w=None, x=None, y='spam', z=42)),
('-z 2', NS(w=None, x=None, y='spam', z=2)),
]
class TestOptionalsNargsZeroOrMore(ParserTestCase):
"""Tests specifying an args for an Optional that accepts zero or more"""
argument_signatures = [
Sig('-x', nargs='*'),
Sig('-y', nargs='*', default='spam'),
]
failures = ['a']
successes = [
('', NS(x=None, y='spam')),
('-x', NS(x=[], y='spam')),
('-x a', NS(x=['a'], y='spam')),
('-x a b', NS(x=['a', 'b'], y='spam')),
('-y', NS(x=None, y=[])),
('-y a', NS(x=None, y=['a'])),
('-y a b', NS(x=None, y=['a', 'b'])),
]
class TestOptionalsNargsOneOrMore(ParserTestCase):
"""Tests specifying an args for an Optional that accepts one or more"""
argument_signatures = [
Sig('-x', nargs='+'),
Sig('-y', nargs='+', default='spam'),
]
failures = ['a', '-x', '-y', 'a -x', 'a -y b']
successes = [
('', NS(x=None, y='spam')),
('-x a', NS(x=['a'], y='spam')),
('-x a b', NS(x=['a', 'b'], y='spam')),
('-y a', NS(x=None, y=['a'])),
('-y a b', NS(x=None, y=['a', 'b'])),
]
class TestOptionalsChoices(ParserTestCase):
"""Tests specifying the choices for an Optional"""
argument_signatures = [
Sig('-f', choices='abc'),
Sig('-g', type=int, choices=range(5))]
failures = ['a', '-f d', '-fad', '-ga', '-g 6']
successes = [
('', NS(f=None, g=None)),
('-f a', NS(f='a', g=None)),
('-f c', NS(f='c', g=None)),
('-g 0', NS(f=None, g=0)),
('-g 03', NS(f=None, g=3)),
('-fb -g4', NS(f='b', g=4)),
]
class TestOptionalsRequired(ParserTestCase):
"""Tests the an optional action that is required"""
argument_signatures = [
Sig('-x', type=int, required=True),
]
failures = ['a', '']
successes = [
('-x 1', NS(x=1)),
('-x42', NS(x=42)),
]
class TestOptionalsActionStore(ParserTestCase):
"""Tests the store action for an Optional"""
argument_signatures = [Sig('-x', action='store')]
failures = ['a', 'a -x']
successes = [
('', NS(x=None)),
('-xfoo', NS(x='foo')),
]
class TestOptionalsActionStoreConst(ParserTestCase):
"""Tests the store_const action for an Optional"""
argument_signatures = [Sig('-y', action='store_const', const=object)]
failures = ['a']
successes = [
('', NS(y=None)),
('-y', NS(y=object)),
]
class TestOptionalsActionStoreFalse(ParserTestCase):
"""Tests the store_false action for an Optional"""
argument_signatures = [Sig('-z', action='store_false')]
failures = ['a', '-za', '-z a']
successes = [
('', NS(z=True)),
('-z', NS(z=False)),
]
class TestOptionalsActionStoreTrue(ParserTestCase):
"""Tests the store_true action for an Optional"""
argument_signatures = [Sig('--apple', action='store_true')]
failures = ['a', '--apple=b', '--apple b']
successes = [
('', NS(apple=False)),
('--apple', NS(apple=True)),
]
class TestOptionalsActionAppend(ParserTestCase):
"""Tests the append action for an Optional"""
argument_signatures = [Sig('--baz', action='append')]
failures = ['a', '--baz', 'a --baz', '--baz a b']
successes = [
('', NS(baz=None)),
('--baz a', NS(baz=['a'])),
('--baz a --baz b', NS(baz=['a', 'b'])),
]
class TestOptionalsActionAppendWithDefault(ParserTestCase):
"""Tests the append action for an Optional"""
argument_signatures = [Sig('--baz', action='append', default=['X'])]
failures = ['a', '--baz', 'a --baz', '--baz a b']
successes = [
('', NS(baz=['X'])),
('--baz a', NS(baz=['X', 'a'])),
('--baz a --baz b', NS(baz=['X', 'a', 'b'])),
]
class TestOptionalsActionAppendConst(ParserTestCase):
"""Tests the append_const action for an Optional"""
argument_signatures = [
Sig('-b', action='append_const', const=Exception),
Sig('-c', action='append', dest='b'),
]
failures = ['a', '-c', 'a -c', '-bx', '-b x']
successes = [
('', NS(b=None)),
('-b', NS(b=[Exception])),
('-b -cx -b -cyz', NS(b=[Exception, 'x', Exception, 'yz'])),
]
class TestOptionalsActionAppendConstWithDefault(ParserTestCase):
"""Tests the append_const action for an Optional"""
argument_signatures = [
Sig('-b', action='append_const', const=Exception, default=['X']),
Sig('-c', action='append', dest='b'),
]
failures = ['a', '-c', 'a -c', '-bx', '-b x']
successes = [
('', NS(b=['X'])),
('-b', NS(b=['X', Exception])),
('-b -cx -b -cyz', NS(b=['X', Exception, 'x', Exception, 'yz'])),
]
class TestOptionalsActionCount(ParserTestCase):
"""Tests the count action for an Optional"""
argument_signatures = [Sig('-x', action='count')]
failures = ['a', '-x a', '-x b', '-x a -x b']
successes = [
('', NS(x=None)),
('-x', NS(x=1)),
]
# ================
# Positional tests
# ================
class TestPositionalsNargsNone(ParserTestCase):
"""Test a Positional that doesn't specify nargs"""
argument_signatures = [Sig('foo')]
failures = ['', '-x', 'a b']
successes = [
('a', NS(foo='a')),
]
class TestPositionalsNargs1(ParserTestCase):
"""Test a Positional that specifies an nargs of 1"""
argument_signatures = [Sig('foo', nargs=1)]
failures = ['', '-x', 'a b']
successes = [
('a', NS(foo=['a'])),
]
class TestPositionalsNargs2(ParserTestCase):
"""Test a Positional that specifies an nargs of 2"""
argument_signatures = [Sig('foo', nargs=2)]
failures = ['', 'a', '-x', 'a b c']
successes = [
('a b', NS(foo=['a', 'b'])),
]
class TestPositionalsNargsZeroOrMore(ParserTestCase):
"""Test a Positional that specifies unlimited nargs"""
argument_signatures = [Sig('foo', nargs='*')]
failures = ['-x']
successes = [
('', NS(foo=[])),
('a', NS(foo=['a'])),
('a b', NS(foo=['a', 'b'])),
]
class TestPositionalsNargsZeroOrMoreDefault(ParserTestCase):
"""Test a Positional that specifies unlimited nargs and a default"""
argument_signatures = [Sig('foo', nargs='*', default='bar')]
failures = ['-x']
successes = [
('', NS(foo='bar')),
('a', NS(foo=['a'])),
('a b', NS(foo=['a', 'b'])),
]
class TestPositionalsNargsOneOrMore(ParserTestCase):
"""Test a Positional that specifies one or more nargs"""
argument_signatures = [Sig('foo', nargs='+')]
failures = ['', '-x']
successes = [
('a', NS(foo=['a'])),
('a b', NS(foo=['a', 'b'])),
]
class TestPositionalsNargsOptional(ParserTestCase):
"""Tests an Optional Positional"""
argument_signatures = [Sig('foo', nargs='?')]
failures = ['-x', 'a b']
successes = [
('', NS(foo=None)),
('a', NS(foo='a')),
]
class TestPositionalsNargsOptionalDefault(ParserTestCase):
"""Tests an Optional Positional with a default value"""
argument_signatures = [Sig('foo', nargs='?', default=42)]
failures = ['-x', 'a b']
successes = [
('', NS(foo=42)),
('a', NS(foo='a')),
]
class TestPositionalsNargsOptionalConvertedDefault(ParserTestCase):
"""Tests an Optional Positional with a default value
that needs to be converted to the appropriate type.
"""
argument_signatures = [
Sig('foo', nargs='?', type=int, default='42'),
]
failures = ['-x', 'a b', '1 2']
successes = [
('', NS(foo=42)),
('1', NS(foo=1)),
]
class TestPositionalsNargsNoneNone(ParserTestCase):
"""Test two Positionals that don't specify nargs"""
argument_signatures = [Sig('foo'), Sig('bar')]
failures = ['', '-x', 'a', 'a b c']
successes = [
('a b', NS(foo='a', bar='b')),
]
class TestPositionalsNargsNone1(ParserTestCase):
"""Test a Positional with no nargs followed by one with 1"""
argument_signatures = [Sig('foo'), Sig('bar', nargs=1)]
failures = ['', '--foo', 'a', 'a b c']
successes = [
('a b', NS(foo='a', bar=['b'])),
]
class TestPositionalsNargs2None(ParserTestCase):
"""Test a Positional with 2 nargs followed by one with none"""
argument_signatures = [Sig('foo', nargs=2), Sig('bar')]
failures = ['', '--foo', 'a', 'a b', 'a b c d']
successes = [
('a b c', NS(foo=['a', 'b'], bar='c')),
]
class TestPositionalsNargsNoneZeroOrMore(ParserTestCase):
"""Test a Positional with no nargs followed by one with unlimited"""
argument_signatures = [Sig('foo'), Sig('bar', nargs='*')]
failures = ['', '--foo']
successes = [
('a', NS(foo='a', bar=[])),
('a b', NS(foo='a', bar=['b'])),
('a b c', NS(foo='a', bar=['b', 'c'])),
]
class TestPositionalsNargsNoneOneOrMore(ParserTestCase):
"""Test a Positional with no nargs followed by one with one or more"""
argument_signatures = [Sig('foo'), Sig('bar', nargs='+')]
failures = ['', '--foo', 'a']
successes = [
('a b', NS(foo='a', bar=['b'])),
('a b c', NS(foo='a', bar=['b', 'c'])),
]
class TestPositionalsNargsNoneOptional(ParserTestCase):
"""Test a Positional with no nargs followed by one with an Optional"""
argument_signatures = [Sig('foo'), Sig('bar', nargs='?')]
failures = ['', '--foo', 'a b c']
successes = [
('a', NS(foo='a', bar=None)),
('a b', NS(foo='a', bar='b')),
]
class TestPositionalsNargsZeroOrMoreNone(ParserTestCase):
"""Test a Positional with unlimited nargs followed by one with none"""
argument_signatures = [Sig('foo', nargs='*'), Sig('bar')]
failures = ['', '--foo']
successes = [
('a', NS(foo=[], bar='a')),
('a b', NS(foo=['a'], bar='b')),
('a b c', NS(foo=['a', 'b'], bar='c')),
]
class TestPositionalsNargsOneOrMoreNone(ParserTestCase):
"""Test a Positional with one or more nargs followed by one with none"""
argument_signatures = [Sig('foo', nargs='+'), Sig('bar')]
failures = ['', '--foo', 'a']
successes = [
('a b', NS(foo=['a'], bar='b')),
('a b c', NS(foo=['a', 'b'], bar='c')),
]
class TestPositionalsNargsOptionalNone(ParserTestCase):
"""Test a Positional with an Optional nargs followed by one with none"""
argument_signatures = [Sig('foo', nargs='?', default=42), Sig('bar')]
failures = ['', '--foo', 'a b c']
successes = [
('a', NS(foo=42, bar='a')),
('a b', NS(foo='a', bar='b')),
]
class TestPositionalsNargs2ZeroOrMore(ParserTestCase):
"""Test a Positional with 2 nargs followed by one with unlimited"""
argument_signatures = [Sig('foo', nargs=2), Sig('bar', nargs='*')]
failures = ['', '--foo', 'a']
successes = [
('a b', NS(foo=['a', 'b'], bar=[])),
('a b c', NS(foo=['a', 'b'], bar=['c'])),
]
class TestPositionalsNargs2OneOrMore(ParserTestCase):
"""Test a Positional with 2 nargs followed by one with one or more"""
argument_signatures = [Sig('foo', nargs=2), Sig('bar', nargs='+')]
failures = ['', '--foo', 'a', 'a b']
successes = [
('a b c', NS(foo=['a', 'b'], bar=['c'])),
]
class TestPositionalsNargs2Optional(ParserTestCase):
"""Test a Positional with 2 nargs followed by one optional"""
argument_signatures = [Sig('foo', nargs=2), Sig('bar', nargs='?')]
failures = ['', '--foo', 'a', 'a b c d']
successes = [
('a b', NS(foo=['a', 'b'], bar=None)),
('a b c', NS(foo=['a', 'b'], bar='c')),
]
class TestPositionalsNargsZeroOrMore1(ParserTestCase):
"""Test a Positional with unlimited nargs followed by one with 1"""
argument_signatures = [Sig('foo', nargs='*'), Sig('bar', nargs=1)]
failures = ['', '--foo', ]
successes = [
('a', NS(foo=[], bar=['a'])),
('a b', NS(foo=['a'], bar=['b'])),
('a b c', NS(foo=['a', 'b'], bar=['c'])),
]
class TestPositionalsNargsOneOrMore1(ParserTestCase):
"""Test a Positional with one or more nargs followed by one with 1"""
argument_signatures = [Sig('foo', nargs='+'), Sig('bar', nargs=1)]
failures = ['', '--foo', 'a']
successes = [
('a b', NS(foo=['a'], bar=['b'])),
('a b c', NS(foo=['a', 'b'], bar=['c'])),
]
class TestPositionalsNargsOptional1(ParserTestCase):
"""Test a Positional with an Optional nargs followed by one with 1"""
argument_signatures = [Sig('foo', nargs='?'), Sig('bar', nargs=1)]
failures = ['', '--foo', 'a b c']
successes = [
('a', NS(foo=None, bar=['a'])),
('a b', NS(foo='a', bar=['b'])),
]
class TestPositionalsNargsNoneZeroOrMore1(ParserTestCase):
"""Test three Positionals: no nargs, unlimited nargs and 1 nargs"""
argument_signatures = [
Sig('foo'),
Sig('bar', nargs='*'),
Sig('baz', nargs=1),
]
failures = ['', '--foo', 'a']
successes = [
('a b', NS(foo='a', bar=[], baz=['b'])),
('a b c', NS(foo='a', bar=['b'], baz=['c'])),
]
class TestPositionalsNargsNoneOneOrMore1(ParserTestCase):
"""Test three Positionals: no nargs, one or more nargs and 1 nargs"""
argument_signatures = [
Sig('foo'),
Sig('bar', nargs='+'),
Sig('baz', nargs=1),
]
failures = ['', '--foo', 'a', 'b']
successes = [
('a b c', NS(foo='a', bar=['b'], baz=['c'])),
('a b c d', NS(foo='a', bar=['b', 'c'], baz=['d'])),
]
class TestPositionalsNargsNoneOptional1(ParserTestCase):
"""Test three Positionals: no nargs, optional narg and 1 nargs"""
argument_signatures = [
Sig('foo'),
Sig('bar', nargs='?', default=0.625),
Sig('baz', nargs=1),
]
failures = ['', '--foo', 'a']
successes = [
('a b', NS(foo='a', bar=0.625, baz=['b'])),
('a b c', NS(foo='a', bar='b', baz=['c'])),
]
class TestPositionalsNargsOptionalOptional(ParserTestCase):
"""Test two optional nargs"""
argument_signatures = [
Sig('foo', nargs='?'),
Sig('bar', nargs='?', default=42),
]
failures = ['--foo', 'a b c']
successes = [
('', NS(foo=None, bar=42)),
('a', NS(foo='a', bar=42)),
('a b', NS(foo='a', bar='b')),
]
class TestPositionalsNargsOptionalZeroOrMore(ParserTestCase):
"""Test an Optional narg followed by unlimited nargs"""
argument_signatures = [Sig('foo', nargs='?'), Sig('bar', nargs='*')]
failures = ['--foo']
successes = [
('', NS(foo=None, bar=[])),
('a', NS(foo='a', bar=[])),
('a b', NS(foo='a', bar=['b'])),
('a b c', NS(foo='a', bar=['b', 'c'])),
]
class TestPositionalsNargsOptionalOneOrMore(ParserTestCase):
"""Test an Optional narg followed by one or more nargs"""
argument_signatures = [Sig('foo', nargs='?'), Sig('bar', nargs='+')]
failures = ['', '--foo']
successes = [
('a', NS(foo=None, bar=['a'])),
('a b', NS(foo='a', bar=['b'])),
('a b c', NS(foo='a', bar=['b', 'c'])),
]
class TestPositionalsChoicesString(ParserTestCase):
"""Test a set of single-character choices"""
argument_signatures = [Sig('spam', choices=set('abcdefg'))]
failures = ['', '--foo', 'h', '42', 'ef']
successes = [
('a', NS(spam='a')),
('g', NS(spam='g')),
]
class TestPositionalsChoicesInt(ParserTestCase):
"""Test a set of integer choices"""
argument_signatures = [Sig('spam', type=int, choices=range(20))]
failures = ['', '--foo', 'h', '42', 'ef']
successes = [
('4', NS(spam=4)),
('15', NS(spam=15)),
]
class TestPositionalsActionAppend(ParserTestCase):
"""Test the 'append' action"""
argument_signatures = [
Sig('spam', action='append'),
Sig('spam', action='append', nargs=2),
]
failures = ['', '--foo', 'a', 'a b', 'a b c d']
successes = [
('a b c', NS(spam=['a', ['b', 'c']])),
]
# ========================================
# Combined optionals and positionals tests
# ========================================
class TestOptionalsNumericAndPositionals(ParserTestCase):
"""Tests negative number args when numeric options are present"""
argument_signatures = [
Sig('x', nargs='?'),
Sig('-4', dest='y', action='store_true'),
]
failures = ['-2', '-315']
successes = [
('', NS(x=None, y=False)),
('a', NS(x='a', y=False)),
('-4', NS(x=None, y=True)),
('-4 a', NS(x='a', y=True)),
]
class TestOptionalsAlmostNumericAndPositionals(ParserTestCase):
"""Tests negative number args when almost numeric options are present"""
argument_signatures = [
Sig('x', nargs='?'),
Sig('-k4', dest='y', action='store_true'),
]
failures = ['-k3']
successes = [
('', NS(x=None, y=False)),
('-2', NS(x='-2', y=False)),
('a', NS(x='a', y=False)),
('-k4', NS(x=None, y=True)),
('-k4 a', NS(x='a', y=True)),
]
class TestEmptyAndSpaceContainingArguments(ParserTestCase):
argument_signatures = [
Sig('x', nargs='?'),
Sig('-y', '--yyy', dest='y'),
]
failures = ['-y']
successes = [
([''], NS(x='', y=None)),
(['a badger'], NS(x='a badger', y=None)),
(['-a badger'], NS(x='-a badger', y=None)),
(['-y', ''], NS(x=None, y='')),
(['-y', 'a badger'], NS(x=None, y='a badger')),
(['-y', '-a badger'], NS(x=None, y='-a badger')),
(['--yyy=a badger'], NS(x=None, y='a badger')),
(['--yyy=-a badger'], NS(x=None, y='-a badger')),
]
class TestPrefixCharacterOnlyArguments(ParserTestCase):
parser_signature = Sig(prefix_chars='-+')
argument_signatures = [
Sig('-', dest='x', nargs='?', const='badger'),
Sig('+', dest='y', type=int, default=42),
Sig('-+-', dest='z', action='store_true'),
]
failures = ['-y', '+ -']
successes = [
('', NS(x=None, y=42, z=False)),
('-', NS(x='badger', y=42, z=False)),
('- X', NS(x='X', y=42, z=False)),
('+ -3', NS(x=None, y=-3, z=False)),
('-+-', NS(x=None, y=42, z=True)),
('- ===', NS(x='===', y=42, z=False)),
]
class TestNargsZeroOrMore(ParserTestCase):
"""Tests specifying an args for an Optional that accepts zero or more"""
argument_signatures = [Sig('-x', nargs='*'), Sig('y', nargs='*')]
failures = []
successes = [
('', NS(x=None, y=[])),
('-x', NS(x=[], y=[])),
('-x a', NS(x=['a'], y=[])),
('-x a -- b', NS(x=['a'], y=['b'])),
('a', NS(x=None, y=['a'])),
('a -x', NS(x=[], y=['a'])),
('a -x b', NS(x=['b'], y=['a'])),
]
class TestNargsRemainder(ParserTestCase):
"""Tests specifying a positional with nargs=REMAINDER"""
argument_signatures = [Sig('x'), Sig('y', nargs='...'), Sig('-z')]
failures = ['', '-z', '-z Z']
successes = [
('X', NS(x='X', y=[], z=None)),
('-z Z X', NS(x='X', y=[], z='Z')),
('X A B -z Z', NS(x='X', y=['A', 'B', '-z', 'Z'], z=None)),
('X Y --foo', NS(x='X', y=['Y', '--foo'], z=None)),
]
class TestOptionLike(ParserTestCase):
"""Tests options that may or may not be arguments"""
argument_signatures = [
Sig('-x', type=float),
Sig('-3', type=float, dest='y'),
Sig('z', nargs='*'),
]
failures = ['-x', '-y2.5', '-xa', '-x -a',
'-x -3', '-x -3.5', '-3 -3.5',
'-x -2.5', '-x -2.5 a', '-3 -.5',
'a x -1', '-x -1 a', '-3 -1 a']
successes = [
('', NS(x=None, y=None, z=[])),
('-x 2.5', NS(x=2.5, y=None, z=[])),
('-x 2.5 a', NS(x=2.5, y=None, z=['a'])),
('-3.5', NS(x=None, y=0.5, z=[])),
('-3-.5', NS(x=None, y=-0.5, z=[])),
('-3 .5', NS(x=None, y=0.5, z=[])),
('a -3.5', NS(x=None, y=0.5, z=['a'])),
('a', NS(x=None, y=None, z=['a'])),
('a -x 1', NS(x=1.0, y=None, z=['a'])),
('-x 1 a', NS(x=1.0, y=None, z=['a'])),
('-3 1 a', NS(x=None, y=1.0, z=['a'])),
]
class TestDefaultSuppress(ParserTestCase):
"""Test actions with suppressed defaults"""
argument_signatures = [
Sig('foo', nargs='?', default=argparse.SUPPRESS),
Sig('bar', nargs='*', default=argparse.SUPPRESS),
Sig('--baz', action='store_true', default=argparse.SUPPRESS),
]
failures = ['-x']
successes = [
('', NS()),
('a', NS(foo='a')),
('a b', NS(foo='a', bar=['b'])),
('--baz', NS(baz=True)),
('a --baz', NS(foo='a', baz=True)),
('--baz a b', NS(foo='a', bar=['b'], baz=True)),
]
class TestParserDefaultSuppress(ParserTestCase):
"""Test actions with a parser-level default of SUPPRESS"""
parser_signature = Sig(argument_default=argparse.SUPPRESS)
argument_signatures = [
Sig('foo', nargs='?'),
Sig('bar', nargs='*'),
Sig('--baz', action='store_true'),
]
failures = ['-x']
successes = [
('', NS()),
('a', NS(foo='a')),
('a b', NS(foo='a', bar=['b'])),
('--baz', NS(baz=True)),
('a --baz', NS(foo='a', baz=True)),
('--baz a b', NS(foo='a', bar=['b'], baz=True)),
]
class TestParserDefault42(ParserTestCase):
"""Test actions with a parser-level default of 42"""
parser_signature = Sig(argument_default=42, version='1.0')
argument_signatures = [
Sig('foo', nargs='?'),
Sig('bar', nargs='*'),
Sig('--baz', action='store_true'),
]
failures = ['-x']
successes = [
('', NS(foo=42, bar=42, baz=42)),
('a', NS(foo='a', bar=42, baz=42)),
('a b', NS(foo='a', bar=['b'], baz=42)),
('--baz', NS(foo=42, bar=42, baz=True)),
('a --baz', NS(foo='a', bar=42, baz=True)),
('--baz a b', NS(foo='a', bar=['b'], baz=True)),
]
class TestArgumentsFromFile(TempDirMixin, ParserTestCase):
"""Test reading arguments from a file"""
def setUp(self):
super(TestArgumentsFromFile, self).setUp()
file_texts = [
('hello', 'hello world!\n'),
('recursive', '-a\n'
'A\n'
'@hello'),
('invalid', '@no-such-path\n'),
]
for path, text in file_texts:
file = open(path, 'w')
file.write(text)
file.close()
parser_signature = Sig(fromfile_prefix_chars='@')
argument_signatures = [
Sig('-a'),
Sig('x'),
Sig('y', nargs='+'),
]
failures = ['', '-b', 'X', '@invalid', '@missing']
successes = [
('X Y', NS(a=None, x='X', y=['Y'])),
('X -a A Y Z', NS(a='A', x='X', y=['Y', 'Z'])),
('@hello X', NS(a=None, x='hello world!', y=['X'])),
('X @hello', NS(a=None, x='X', y=['hello world!'])),
('-a B @recursive Y Z', NS(a='A', x='hello world!', y=['Y', 'Z'])),
('X @recursive Z -a B', NS(a='B', x='X', y=['hello world!', 'Z'])),
]
class TestArgumentsFromFileConverter(TempDirMixin, ParserTestCase):
"""Test reading arguments from a file"""
def setUp(self):
super(TestArgumentsFromFileConverter, self).setUp()
file_texts = [
('hello', 'hello world!\n'),
]
for path, text in file_texts:
file = open(path, 'w')
file.write(text)
file.close()
class FromFileConverterArgumentParser(ErrorRaisingArgumentParser):
def convert_arg_line_to_args(self, arg_line):
for arg in arg_line.split():
if not arg.strip():
continue
yield arg
parser_class = FromFileConverterArgumentParser
parser_signature = Sig(fromfile_prefix_chars='@')
argument_signatures = [
Sig('y', nargs='+'),
]
failures = []
successes = [
('@hello X', NS(y=['hello', 'world!', 'X'])),
]
# =====================
# Type conversion tests
# =====================
class TestFileTypeRepr(TestCase):
def test_r(self):
type = argparse.FileType('r')
self.assertEqual("FileType('r')", repr(type))
def test_wb_1(self):
type = argparse.FileType('wb', 1)
self.assertEqual("FileType('wb', 1)", repr(type))
class RFile(object):
seen = {}
def __init__(self, name):
self.name = name
__hash__ = None
def __eq__(self, other):
if other in self.seen:
text = self.seen[other]
else:
text = self.seen[other] = other.read()
other.close()
if not isinstance(text, str):
text = text.decode('ascii')
return self.name == other.name == text
class TestFileTypeR(TempDirMixin, ParserTestCase):
"""Test the FileType option/argument type for reading files"""
def setUp(self):
super(TestFileTypeR, self).setUp()
for file_name in ['foo', 'bar']:
file = open(os.path.join(self.temp_dir, file_name), 'w')
file.write(file_name)
file.close()
self.create_readonly_file('readonly')
argument_signatures = [
Sig('-x', type=argparse.FileType()),
Sig('spam', type=argparse.FileType('r')),
]
failures = ['-x', '-x bar', 'non-existent-file.txt']
successes = [
('foo', NS(x=None, spam=RFile('foo'))),
('-x foo bar', NS(x=RFile('foo'), spam=RFile('bar'))),
('bar -x foo', NS(x=RFile('foo'), spam=RFile('bar'))),
('-x - -', NS(x=sys.stdin, spam=sys.stdin)),
('readonly', NS(x=None, spam=RFile('readonly'))),
]
class TestFileTypeRB(TempDirMixin, ParserTestCase):
"""Test the FileType option/argument type for reading files"""
def setUp(self):
super(TestFileTypeRB, self).setUp()
for file_name in ['foo', 'bar']:
file = open(os.path.join(self.temp_dir, file_name), 'w')
file.write(file_name)
file.close()
argument_signatures = [
Sig('-x', type=argparse.FileType('rb')),
Sig('spam', type=argparse.FileType('rb')),
]
failures = ['-x', '-x bar']
successes = [
('foo', NS(x=None, spam=RFile('foo'))),
('-x foo bar', NS(x=RFile('foo'), spam=RFile('bar'))),
('bar -x foo', NS(x=RFile('foo'), spam=RFile('bar'))),
('-x - -', NS(x=sys.stdin, spam=sys.stdin)),
]
class WFile(object):
seen = set()
def __init__(self, name):
self.name = name
__hash__ = None
def __eq__(self, other):
if other not in self.seen:
text = 'Check that file is writable.'
if 'b' in other.mode:
text = text.encode('ascii')
other.write(text)
other.close()
self.seen.add(other)
return self.name == other.name
@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
"non-root user required")
class TestFileTypeW(TempDirMixin, ParserTestCase):
"""Test the FileType option/argument type for writing files"""
def setUp(self):
super(TestFileTypeW, self).setUp()
self.create_readonly_file('readonly')
argument_signatures = [
Sig('-x', type=argparse.FileType('w')),
Sig('spam', type=argparse.FileType('w')),
]
failures = ['-x', '-x bar']
failures = ['-x', '-x bar', 'readonly']
successes = [
('foo', NS(x=None, spam=WFile('foo'))),
('-x foo bar', NS(x=WFile('foo'), spam=WFile('bar'))),
('bar -x foo', NS(x=WFile('foo'), spam=WFile('bar'))),
('-x - -', NS(x=sys.stdout, spam=sys.stdout)),
]
class TestFileTypeWB(TempDirMixin, ParserTestCase):
argument_signatures = [
Sig('-x', type=argparse.FileType('wb')),
Sig('spam', type=argparse.FileType('wb')),
]
failures = ['-x', '-x bar']
successes = [
('foo', NS(x=None, spam=WFile('foo'))),
('-x foo bar', NS(x=WFile('foo'), spam=WFile('bar'))),
('bar -x foo', NS(x=WFile('foo'), spam=WFile('bar'))),
('-x - -', NS(x=sys.stdout, spam=sys.stdout)),
]
class TestTypeCallable(ParserTestCase):
"""Test some callables as option/argument types"""
argument_signatures = [
Sig('--eggs', type=complex),
Sig('spam', type=float),
]
failures = ['a', '42j', '--eggs a', '--eggs 2i']
successes = [
('--eggs=42 42', NS(eggs=42, spam=42.0)),
('--eggs 2j -- -1.5', NS(eggs=2j, spam=-1.5)),
('1024.675', NS(eggs=None, spam=1024.675)),
]
class TestTypeUserDefined(ParserTestCase):
"""Test a user-defined option/argument type"""
class MyType(TestCase):
def __init__(self, value):
self.value = value
__hash__ = None
def __eq__(self, other):
return (type(self), self.value) == (type(other), other.value)
argument_signatures = [
Sig('-x', type=MyType),
Sig('spam', type=MyType),
]
failures = []
successes = [
('a -x b', NS(x=MyType('b'), spam=MyType('a'))),
('-xf g', NS(x=MyType('f'), spam=MyType('g'))),
]
class TestTypeClassicClass(ParserTestCase):
"""Test a classic class type"""
class C:
def __init__(self, value):
self.value = value
__hash__ = None
def __eq__(self, other):
return (type(self), self.value) == (type(other), other.value)
argument_signatures = [
Sig('-x', type=C),
Sig('spam', type=C),
]
failures = []
successes = [
('a -x b', NS(x=C('b'), spam=C('a'))),
('-xf g', NS(x=C('f'), spam=C('g'))),
]
class TestTypeRegistration(TestCase):
"""Test a user-defined type by registering it"""
def test(self):
def get_my_type(string):
return 'my_type{%s}' % string
parser = argparse.ArgumentParser()
parser.register('type', 'my_type', get_my_type)
parser.add_argument('-x', type='my_type')
parser.add_argument('y', type='my_type')
self.assertEqual(parser.parse_args('1'.split()),
NS(x=None, y='my_type{1}'))
self.assertEqual(parser.parse_args('-x 1 42'.split()),
NS(x='my_type{1}', y='my_type{42}'))
# ============
# Action tests
# ============
class TestActionUserDefined(ParserTestCase):
"""Test a user-defined option/argument action"""
class OptionalAction(argparse.Action):
def __call__(self, parser, namespace, value, option_string=None):
try:
# check destination and option string
assert self.dest == 'spam', 'dest: %s' % self.dest
assert option_string == '-s', 'flag: %s' % option_string
# when option is before argument, badger=2, and when
# option is after argument, badger=<whatever was set>
expected_ns = NS(spam=0.25)
if value in [0.125, 0.625]:
expected_ns.badger = 2
elif value in [2.0]:
expected_ns.badger = 84
else:
raise AssertionError('value: %s' % value)
assert expected_ns == namespace, ('expected %s, got %s' %
(expected_ns, namespace))
except AssertionError:
e = sys.exc_info()[1]
raise ArgumentParserError('opt_action failed: %s' % e)
setattr(namespace, 'spam', value)
class PositionalAction(argparse.Action):
def __call__(self, parser, namespace, value, option_string=None):
try:
assert option_string is None, ('option_string: %s' %
option_string)
# check destination
assert self.dest == 'badger', 'dest: %s' % self.dest
# when argument is before option, spam=0.25, and when
# option is after argument, spam=<whatever was set>
expected_ns = NS(badger=2)
if value in [42, 84]:
expected_ns.spam = 0.25
elif value in [1]:
expected_ns.spam = 0.625
elif value in [2]:
expected_ns.spam = 0.125
else:
raise AssertionError('value: %s' % value)
assert expected_ns == namespace, ('expected %s, got %s' %
(expected_ns, namespace))
except AssertionError:
e = sys.exc_info()[1]
raise ArgumentParserError('arg_action failed: %s' % e)
setattr(namespace, 'badger', value)
argument_signatures = [
Sig('-s', dest='spam', action=OptionalAction,
type=float, default=0.25),
Sig('badger', action=PositionalAction,
type=int, nargs='?', default=2),
]
failures = []
successes = [
('-s0.125', NS(spam=0.125, badger=2)),
('42', NS(spam=0.25, badger=42)),
('-s 0.625 1', NS(spam=0.625, badger=1)),
('84 -s2', NS(spam=2.0, badger=84)),
]
class TestActionRegistration(TestCase):
"""Test a user-defined action supplied by registering it"""
class MyAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, 'foo[%s]' % values)
def test(self):
parser = argparse.ArgumentParser()
parser.register('action', 'my_action', self.MyAction)
parser.add_argument('badger', action='my_action')
self.assertEqual(parser.parse_args(['1']), NS(badger='foo[1]'))
self.assertEqual(parser.parse_args(['42']), NS(badger='foo[42]'))
# ================
# Subparsers tests
# ================
class TestAddSubparsers(TestCase):
"""Test the add_subparsers method"""
def assertArgumentParserError(self, *args, **kwargs):
self.assertRaises(ArgumentParserError, *args, **kwargs)
def _get_parser(self, subparser_help=False, prefix_chars=None):
# create a parser with a subparsers argument
if prefix_chars:
parser = ErrorRaisingArgumentParser(
prog='PROG', description='main description', prefix_chars=prefix_chars)
parser.add_argument(
prefix_chars[0] * 2 + 'foo', action='store_true', help='foo help')
else:
parser = ErrorRaisingArgumentParser(
prog='PROG', description='main description')
parser.add_argument(
'--foo', action='store_true', help='foo help')
parser.add_argument(
'bar', type=float, help='bar help')
# check that only one subparsers argument can be added
subparsers = parser.add_subparsers(help='command help')
self.assertArgumentParserError(parser.add_subparsers)
# add first sub-parser
parser1_kwargs = dict(description='1 description')
if subparser_help:
parser1_kwargs['help'] = '1 help'
parser1 = subparsers.add_parser('1', **parser1_kwargs)
parser1.add_argument('-w', type=int, help='w help')
parser1.add_argument('x', choices='abc', help='x help')
# add second sub-parser
parser2_kwargs = dict(description='2 description')
if subparser_help:
parser2_kwargs['help'] = '2 help'
parser2 = subparsers.add_parser('2', **parser2_kwargs)
parser2.add_argument('-y', choices='123', help='y help')
parser2.add_argument('z', type=complex, nargs='*', help='z help')
# return the main parser
return parser
def setUp(self):
super(TestAddSubparsers, self).setUp()
self.parser = self._get_parser()
self.command_help_parser = self._get_parser(subparser_help=True)
def test_parse_args_failures(self):
# check some failure cases:
for args_str in ['', 'a', 'a a', '0.5 a', '0.5 1',
'0.5 1 -y', '0.5 2 -w']:
args = args_str.split()
self.assertArgumentParserError(self.parser.parse_args, args)
def test_parse_args(self):
# check some non-failure cases:
self.assertEqual(
self.parser.parse_args('0.5 1 b -w 7'.split()),
NS(foo=False, bar=0.5, w=7, x='b'),
)
self.assertEqual(
self.parser.parse_args('0.25 --foo 2 -y 2 3j -- -1j'.split()),
NS(foo=True, bar=0.25, y='2', z=[3j, -1j]),
)
self.assertEqual(
self.parser.parse_args('--foo 0.125 1 c'.split()),
NS(foo=True, bar=0.125, w=None, x='c'),
)
def test_parse_known_args(self):
self.assertEqual(
self.parser.parse_known_args('0.5 1 b -w 7'.split()),
(NS(foo=False, bar=0.5, w=7, x='b'), []),
)
self.assertEqual(
self.parser.parse_known_args('0.5 -p 1 b -w 7'.split()),
(NS(foo=False, bar=0.5, w=7, x='b'), ['-p']),
)
self.assertEqual(
self.parser.parse_known_args('0.5 1 b -w 7 -p'.split()),
(NS(foo=False, bar=0.5, w=7, x='b'), ['-p']),
)
self.assertEqual(
self.parser.parse_known_args('0.5 1 b -q -rs -w 7'.split()),
(NS(foo=False, bar=0.5, w=7, x='b'), ['-q', '-rs']),
)
self.assertEqual(
self.parser.parse_known_args('0.5 -W 1 b -X Y -w 7 Z'.split()),
(NS(foo=False, bar=0.5, w=7, x='b'), ['-W', '-X', 'Y', 'Z']),
)
def test_dest(self):
parser = ErrorRaisingArgumentParser()
parser.add_argument('--foo', action='store_true')
subparsers = parser.add_subparsers(dest='bar')
parser1 = subparsers.add_parser('1')
parser1.add_argument('baz')
self.assertEqual(NS(foo=False, bar='1', baz='2'),
parser.parse_args('1 2'.split()))
def test_help(self):
self.assertEqual(self.parser.format_usage(),
'usage: PROG [-h] [--foo] bar {1,2} ...\n')
self.assertEqual(self.parser.format_help(), textwrap.dedent('''\
usage: PROG [-h] [--foo] bar {1,2} ...
main description
positional arguments:
bar bar help
{1,2} command help
optional arguments:
-h, --help show this help message and exit
--foo foo help
'''))
def test_help_extra_prefix_chars(self):
# Make sure - is still used for help if it is a non-first prefix char
parser = self._get_parser(prefix_chars='+:-')
self.assertEqual(parser.format_usage(),
'usage: PROG [-h] [++foo] bar {1,2} ...\n')
self.assertEqual(parser.format_help(), textwrap.dedent('''\
usage: PROG [-h] [++foo] bar {1,2} ...
main description
positional arguments:
bar bar help
{1,2} command help
optional arguments:
-h, --help show this help message and exit
++foo foo help
'''))
def test_help_alternate_prefix_chars(self):
parser = self._get_parser(prefix_chars='+:/')
self.assertEqual(parser.format_usage(),
'usage: PROG [+h] [++foo] bar {1,2} ...\n')
self.assertEqual(parser.format_help(), textwrap.dedent('''\
usage: PROG [+h] [++foo] bar {1,2} ...
main description
positional arguments:
bar bar help
{1,2} command help
optional arguments:
+h, ++help show this help message and exit
++foo foo help
'''))
def test_parser_command_help(self):
self.assertEqual(self.command_help_parser.format_usage(),
'usage: PROG [-h] [--foo] bar {1,2} ...\n')
self.assertEqual(self.command_help_parser.format_help(),
textwrap.dedent('''\
usage: PROG [-h] [--foo] bar {1,2} ...
main description
positional arguments:
bar bar help
{1,2} command help
1 1 help
2 2 help
optional arguments:
-h, --help show this help message and exit
--foo foo help
'''))
def test_subparser_title_help(self):
parser = ErrorRaisingArgumentParser(prog='PROG',
description='main description')
parser.add_argument('--foo', action='store_true', help='foo help')
parser.add_argument('bar', help='bar help')
subparsers = parser.add_subparsers(title='subcommands',
description='command help',
help='additional text')
parser1 = subparsers.add_parser('1')
parser2 = subparsers.add_parser('2')
self.assertEqual(parser.format_usage(),
'usage: PROG [-h] [--foo] bar {1,2} ...\n')
self.assertEqual(parser.format_help(), textwrap.dedent('''\
usage: PROG [-h] [--foo] bar {1,2} ...
main description
positional arguments:
bar bar help
optional arguments:
-h, --help show this help message and exit
--foo foo help
subcommands:
command help
{1,2} additional text
'''))
def _test_subparser_help(self, args_str, expected_help):
try:
self.parser.parse_args(args_str.split())
except ArgumentParserError:
err = sys.exc_info()[1]
if err.stdout != expected_help:
print(repr(expected_help))
print(repr(err.stdout))
self.assertEqual(err.stdout, expected_help)
def test_subparser1_help(self):
self._test_subparser_help('5.0 1 -h', textwrap.dedent('''\
usage: PROG bar 1 [-h] [-w W] {a,b,c}
1 description
positional arguments:
{a,b,c} x help
optional arguments:
-h, --help show this help message and exit
-w W w help
'''))
def test_subparser2_help(self):
self._test_subparser_help('5.0 2 -h', textwrap.dedent('''\
usage: PROG bar 2 [-h] [-y {1,2,3}] [z [z ...]]
2 description
positional arguments:
z z help
optional arguments:
-h, --help show this help message and exit
-y {1,2,3} y help
'''))
# ============
# Groups tests
# ============
class TestPositionalsGroups(TestCase):
"""Tests that order of group positionals matches construction order"""
def test_nongroup_first(self):
parser = ErrorRaisingArgumentParser()
parser.add_argument('foo')
group = parser.add_argument_group('g')
group.add_argument('bar')
parser.add_argument('baz')
expected = NS(foo='1', bar='2', baz='3')
result = parser.parse_args('1 2 3'.split())
self.assertEqual(expected, result)
def test_group_first(self):
parser = ErrorRaisingArgumentParser()
group = parser.add_argument_group('xxx')
group.add_argument('foo')
parser.add_argument('bar')
parser.add_argument('baz')
expected = NS(foo='1', bar='2', baz='3')
result = parser.parse_args('1 2 3'.split())
self.assertEqual(expected, result)
def test_interleaved_groups(self):
parser = ErrorRaisingArgumentParser()
group = parser.add_argument_group('xxx')
parser.add_argument('foo')
group.add_argument('bar')
parser.add_argument('baz')
group = parser.add_argument_group('yyy')
group.add_argument('frell')
expected = NS(foo='1', bar='2', baz='3', frell='4')
result = parser.parse_args('1 2 3 4'.split())
self.assertEqual(expected, result)
# ===================
# Parent parser tests
# ===================
class TestParentParsers(TestCase):
"""Tests that parsers can be created with parent parsers"""
def assertArgumentParserError(self, *args, **kwargs):
self.assertRaises(ArgumentParserError, *args, **kwargs)
def setUp(self):
super(TestParentParsers, self).setUp()
self.wxyz_parent = ErrorRaisingArgumentParser(add_help=False)
self.wxyz_parent.add_argument('--w')
x_group = self.wxyz_parent.add_argument_group('x')
x_group.add_argument('-y')
self.wxyz_parent.add_argument('z')
self.abcd_parent = ErrorRaisingArgumentParser(add_help=False)
self.abcd_parent.add_argument('a')
self.abcd_parent.add_argument('-b')
c_group = self.abcd_parent.add_argument_group('c')
c_group.add_argument('--d')
self.w_parent = ErrorRaisingArgumentParser(add_help=False)
self.w_parent.add_argument('--w')
self.z_parent = ErrorRaisingArgumentParser(add_help=False)
self.z_parent.add_argument('z')
# parents with mutually exclusive groups
self.ab_mutex_parent = ErrorRaisingArgumentParser(add_help=False)
group = self.ab_mutex_parent.add_mutually_exclusive_group()
group.add_argument('-a', action='store_true')
group.add_argument('-b', action='store_true')
self.main_program = os.path.basename(sys.argv[0])
def test_single_parent(self):
parser = ErrorRaisingArgumentParser(parents=[self.wxyz_parent])
self.assertEqual(parser.parse_args('-y 1 2 --w 3'.split()),
NS(w='3', y='1', z='2'))
def test_single_parent_mutex(self):
self._test_mutex_ab(self.ab_mutex_parent.parse_args)
parser = ErrorRaisingArgumentParser(parents=[self.ab_mutex_parent])
self._test_mutex_ab(parser.parse_args)
def test_single_granparent_mutex(self):
parents = [self.ab_mutex_parent]
parser = ErrorRaisingArgumentParser(add_help=False, parents=parents)
parser = ErrorRaisingArgumentParser(parents=[parser])
self._test_mutex_ab(parser.parse_args)
def _test_mutex_ab(self, parse_args):
self.assertEqual(parse_args([]), NS(a=False, b=False))
self.assertEqual(parse_args(['-a']), NS(a=True, b=False))
self.assertEqual(parse_args(['-b']), NS(a=False, b=True))
self.assertArgumentParserError(parse_args, ['-a', '-b'])
self.assertArgumentParserError(parse_args, ['-b', '-a'])
self.assertArgumentParserError(parse_args, ['-c'])
self.assertArgumentParserError(parse_args, ['-a', '-c'])
self.assertArgumentParserError(parse_args, ['-b', '-c'])
def test_multiple_parents(self):
parents = [self.abcd_parent, self.wxyz_parent]
parser = ErrorRaisingArgumentParser(parents=parents)
self.assertEqual(parser.parse_args('--d 1 --w 2 3 4'.split()),
NS(a='3', b=None, d='1', w='2', y=None, z='4'))
def test_multiple_parents_mutex(self):
parents = [self.ab_mutex_parent, self.wxyz_parent]
parser = ErrorRaisingArgumentParser(parents=parents)
self.assertEqual(parser.parse_args('-a --w 2 3'.split()),
NS(a=True, b=False, w='2', y=None, z='3'))
self.assertArgumentParserError(
parser.parse_args, '-a --w 2 3 -b'.split())
self.assertArgumentParserError(
parser.parse_args, '-a -b --w 2 3'.split())
def test_conflicting_parents(self):
self.assertRaises(
argparse.ArgumentError,
argparse.ArgumentParser,
parents=[self.w_parent, self.wxyz_parent])
def test_conflicting_parents_mutex(self):
self.assertRaises(
argparse.ArgumentError,
argparse.ArgumentParser,
parents=[self.abcd_parent, self.ab_mutex_parent])
def test_same_argument_name_parents(self):
parents = [self.wxyz_parent, self.z_parent]
parser = ErrorRaisingArgumentParser(parents=parents)
self.assertEqual(parser.parse_args('1 2'.split()),
NS(w=None, y=None, z='2'))
def test_subparser_parents(self):
parser = ErrorRaisingArgumentParser()
subparsers = parser.add_subparsers()
abcde_parser = subparsers.add_parser('bar', parents=[self.abcd_parent])
abcde_parser.add_argument('e')
self.assertEqual(parser.parse_args('bar -b 1 --d 2 3 4'.split()),
NS(a='3', b='1', d='2', e='4'))
def test_subparser_parents_mutex(self):
parser = ErrorRaisingArgumentParser()
subparsers = parser.add_subparsers()
parents = [self.ab_mutex_parent]
abc_parser = subparsers.add_parser('foo', parents=parents)
c_group = abc_parser.add_argument_group('c_group')
c_group.add_argument('c')
parents = [self.wxyz_parent, self.ab_mutex_parent]
wxyzabe_parser = subparsers.add_parser('bar', parents=parents)
wxyzabe_parser.add_argument('e')
self.assertEqual(parser.parse_args('foo -a 4'.split()),
NS(a=True, b=False, c='4'))
self.assertEqual(parser.parse_args('bar -b --w 2 3 4'.split()),
NS(a=False, b=True, w='2', y=None, z='3', e='4'))
self.assertArgumentParserError(
parser.parse_args, 'foo -a -b 4'.split())
self.assertArgumentParserError(
parser.parse_args, 'bar -b -a 4'.split())
def test_parent_help(self):
parents = [self.abcd_parent, self.wxyz_parent]
parser = ErrorRaisingArgumentParser(parents=parents)
parser_help = parser.format_help()
progname = self.main_program
self.assertEqual(parser_help, textwrap.dedent('''\
usage: {}{}[-h] [-b B] [--d D] [--w W] [-y Y] a z
positional arguments:
a
z
optional arguments:
-h, --help show this help message and exit
-b B
--w W
c:
--d D
x:
-y Y
'''.format(progname, ' ' if progname else '' )))
def test_groups_parents(self):
parent = ErrorRaisingArgumentParser(add_help=False)
g = parent.add_argument_group(title='g', description='gd')
g.add_argument('-w')
g.add_argument('-x')
m = parent.add_mutually_exclusive_group()
m.add_argument('-y')
m.add_argument('-z')
parser = ErrorRaisingArgumentParser(parents=[parent])
self.assertRaises(ArgumentParserError, parser.parse_args,
['-y', 'Y', '-z', 'Z'])
parser_help = parser.format_help()
progname = self.main_program
self.assertEqual(parser_help, textwrap.dedent('''\
usage: {}{}[-h] [-w W] [-x X] [-y Y | -z Z]
optional arguments:
-h, --help show this help message and exit
-y Y
-z Z
g:
gd
-w W
-x X
'''.format(progname, ' ' if progname else '' )))
# ==============================
# Mutually exclusive group tests
# ==============================
class TestMutuallyExclusiveGroupErrors(TestCase):
def test_invalid_add_argument_group(self):
parser = ErrorRaisingArgumentParser()
raises = self.assertRaises
raises(TypeError, parser.add_mutually_exclusive_group, title='foo')
def test_invalid_add_argument(self):
parser = ErrorRaisingArgumentParser()
group = parser.add_mutually_exclusive_group()
add_argument = group.add_argument
raises = self.assertRaises
raises(ValueError, add_argument, '--foo', required=True)
raises(ValueError, add_argument, 'bar')
raises(ValueError, add_argument, 'bar', nargs='+')
raises(ValueError, add_argument, 'bar', nargs=1)
raises(ValueError, add_argument, 'bar', nargs=argparse.PARSER)
def test_help(self):
parser = ErrorRaisingArgumentParser(prog='PROG')
group1 = parser.add_mutually_exclusive_group()
group1.add_argument('--foo', action='store_true')
group1.add_argument('--bar', action='store_false')
group2 = parser.add_mutually_exclusive_group()
group2.add_argument('--soup', action='store_true')
group2.add_argument('--nuts', action='store_false')
expected = '''\
usage: PROG [-h] [--foo | --bar] [--soup | --nuts]
optional arguments:
-h, --help show this help message and exit
--foo
--bar
--soup
--nuts
'''
self.assertEqual(parser.format_help(), textwrap.dedent(expected))
class MEMixin(object):
def test_failures_when_not_required(self):
parse_args = self.get_parser(required=False).parse_args
error = ArgumentParserError
for args_string in self.failures:
self.assertRaises(error, parse_args, args_string.split())
def test_failures_when_required(self):
parse_args = self.get_parser(required=True).parse_args
error = ArgumentParserError
for args_string in self.failures + ['']:
self.assertRaises(error, parse_args, args_string.split())
def test_successes_when_not_required(self):
parse_args = self.get_parser(required=False).parse_args
successes = self.successes + self.successes_when_not_required
for args_string, expected_ns in successes:
actual_ns = parse_args(args_string.split())
self.assertEqual(actual_ns, expected_ns)
def test_successes_when_required(self):
parse_args = self.get_parser(required=True).parse_args
for args_string, expected_ns in self.successes:
actual_ns = parse_args(args_string.split())
self.assertEqual(actual_ns, expected_ns)
def test_usage_when_not_required(self):
format_usage = self.get_parser(required=False).format_usage
expected_usage = self.usage_when_not_required
self.assertEqual(format_usage(), textwrap.dedent(expected_usage))
def test_usage_when_required(self):
format_usage = self.get_parser(required=True).format_usage
expected_usage = self.usage_when_required
self.assertEqual(format_usage(), textwrap.dedent(expected_usage))
def test_help_when_not_required(self):
format_help = self.get_parser(required=False).format_help
help = self.usage_when_not_required + self.help
self.assertEqual(format_help(), textwrap.dedent(help))
def test_help_when_required(self):
format_help = self.get_parser(required=True).format_help
help = self.usage_when_required + self.help
self.assertEqual(format_help(), textwrap.dedent(help))
class TestMutuallyExclusiveSimple(MEMixin, TestCase):
def get_parser(self, required=None):
parser = ErrorRaisingArgumentParser(prog='PROG')
group = parser.add_mutually_exclusive_group(required=required)
group.add_argument('--bar', help='bar help')
group.add_argument('--baz', nargs='?', const='Z', help='baz help')
return parser
failures = ['--bar X --baz Y', '--bar X --baz']
successes = [
('--bar X', NS(bar='X', baz=None)),
('--bar X --bar Z', NS(bar='Z', baz=None)),
('--baz Y', NS(bar=None, baz='Y')),
('--baz', NS(bar=None, baz='Z')),
]
successes_when_not_required = [
('', NS(bar=None, baz=None)),
]
usage_when_not_required = '''\
usage: PROG [-h] [--bar BAR | --baz [BAZ]]
'''
usage_when_required = '''\
usage: PROG [-h] (--bar BAR | --baz [BAZ])
'''
help = '''\
optional arguments:
-h, --help show this help message and exit
--bar BAR bar help
--baz [BAZ] baz help
'''
class TestMutuallyExclusiveLong(MEMixin, TestCase):
def get_parser(self, required=None):
parser = ErrorRaisingArgumentParser(prog='PROG')
parser.add_argument('--abcde', help='abcde help')
parser.add_argument('--fghij', help='fghij help')
group = parser.add_mutually_exclusive_group(required=required)
group.add_argument('--klmno', help='klmno help')
group.add_argument('--pqrst', help='pqrst help')
return parser
failures = ['--klmno X --pqrst Y']
successes = [
('--klmno X', NS(abcde=None, fghij=None, klmno='X', pqrst=None)),
('--abcde Y --klmno X',
NS(abcde='Y', fghij=None, klmno='X', pqrst=None)),
('--pqrst X', NS(abcde=None, fghij=None, klmno=None, pqrst='X')),
('--pqrst X --fghij Y',
NS(abcde=None, fghij='Y', klmno=None, pqrst='X')),
]
successes_when_not_required = [
('', NS(abcde=None, fghij=None, klmno=None, pqrst=None)),
]
usage_when_not_required = '''\
usage: PROG [-h] [--abcde ABCDE] [--fghij FGHIJ]
[--klmno KLMNO | --pqrst PQRST]
'''
usage_when_required = '''\
usage: PROG [-h] [--abcde ABCDE] [--fghij FGHIJ]
(--klmno KLMNO | --pqrst PQRST)
'''
help = '''\
optional arguments:
-h, --help show this help message and exit
--abcde ABCDE abcde help
--fghij FGHIJ fghij help
--klmno KLMNO klmno help
--pqrst PQRST pqrst help
'''
class TestMutuallyExclusiveFirstSuppressed(MEMixin, TestCase):
def get_parser(self, required):
parser = ErrorRaisingArgumentParser(prog='PROG')
group = parser.add_mutually_exclusive_group(required=required)
group.add_argument('-x', help=argparse.SUPPRESS)
group.add_argument('-y', action='store_false', help='y help')
return parser
failures = ['-x X -y']
successes = [
('-x X', NS(x='X', y=True)),
('-x X -x Y', NS(x='Y', y=True)),
('-y', NS(x=None, y=False)),
]
successes_when_not_required = [
('', NS(x=None, y=True)),
]
usage_when_not_required = '''\
usage: PROG [-h] [-y]
'''
usage_when_required = '''\
usage: PROG [-h] -y
'''
help = '''\
optional arguments:
-h, --help show this help message and exit
-y y help
'''
class TestMutuallyExclusiveManySuppressed(MEMixin, TestCase):
def get_parser(self, required):
parser = ErrorRaisingArgumentParser(prog='PROG')
group = parser.add_mutually_exclusive_group(required=required)
add = group.add_argument
add('--spam', action='store_true', help=argparse.SUPPRESS)
add('--badger', action='store_false', help=argparse.SUPPRESS)
add('--bladder', help=argparse.SUPPRESS)
return parser
failures = [
'--spam --badger',
'--badger --bladder B',
'--bladder B --spam',
]
successes = [
('--spam', NS(spam=True, badger=True, bladder=None)),
('--badger', NS(spam=False, badger=False, bladder=None)),
('--bladder B', NS(spam=False, badger=True, bladder='B')),
('--spam --spam', NS(spam=True, badger=True, bladder=None)),
]
successes_when_not_required = [
('', NS(spam=False, badger=True, bladder=None)),
]
usage_when_required = usage_when_not_required = '''\
usage: PROG [-h]
'''
help = '''\
optional arguments:
-h, --help show this help message and exit
'''
class TestMutuallyExclusiveOptionalAndPositional(MEMixin, TestCase):
def get_parser(self, required):
parser = ErrorRaisingArgumentParser(prog='PROG')
group = parser.add_mutually_exclusive_group(required=required)
group.add_argument('--foo', action='store_true', help='FOO')
group.add_argument('--spam', help='SPAM')
group.add_argument('badger', nargs='*', default='X', help='BADGER')
return parser
failures = [
'--foo --spam S',
'--spam S X',
'X --foo',
'X Y Z --spam S',
'--foo X Y',
]
successes = [
('--foo', NS(foo=True, spam=None, badger='X')),
('--spam S', NS(foo=False, spam='S', badger='X')),
('X', NS(foo=False, spam=None, badger=['X'])),
('X Y Z', NS(foo=False, spam=None, badger=['X', 'Y', 'Z'])),
]
successes_when_not_required = [
('', NS(foo=False, spam=None, badger='X')),
]
usage_when_not_required = '''\
usage: PROG [-h] [--foo | --spam SPAM | badger [badger ...]]
'''
usage_when_required = '''\
usage: PROG [-h] (--foo | --spam SPAM | badger [badger ...])
'''
help = '''\
positional arguments:
badger BADGER
optional arguments:
-h, --help show this help message and exit
--foo FOO
--spam SPAM SPAM
'''
class TestMutuallyExclusiveOptionalsMixed(MEMixin, TestCase):
def get_parser(self, required):
parser = ErrorRaisingArgumentParser(prog='PROG')
parser.add_argument('-x', action='store_true', help='x help')
group = parser.add_mutually_exclusive_group(required=required)
group.add_argument('-a', action='store_true', help='a help')
group.add_argument('-b', action='store_true', help='b help')
parser.add_argument('-y', action='store_true', help='y help')
group.add_argument('-c', action='store_true', help='c help')
return parser
failures = ['-a -b', '-b -c', '-a -c', '-a -b -c']
successes = [
('-a', NS(a=True, b=False, c=False, x=False, y=False)),
('-b', NS(a=False, b=True, c=False, x=False, y=False)),
('-c', NS(a=False, b=False, c=True, x=False, y=False)),
('-a -x', NS(a=True, b=False, c=False, x=True, y=False)),
('-y -b', NS(a=False, b=True, c=False, x=False, y=True)),
('-x -y -c', NS(a=False, b=False, c=True, x=True, y=True)),
]
successes_when_not_required = [
('', NS(a=False, b=False, c=False, x=False, y=False)),
('-x', NS(a=False, b=False, c=False, x=True, y=False)),
('-y', NS(a=False, b=False, c=False, x=False, y=True)),
]
usage_when_required = usage_when_not_required = '''\
usage: PROG [-h] [-x] [-a] [-b] [-y] [-c]
'''
help = '''\
optional arguments:
-h, --help show this help message and exit
-x x help
-a a help
-b b help
-y y help
-c c help
'''
class TestMutuallyExclusiveInGroup(MEMixin, TestCase):
def get_parser(self, required=None):
parser = ErrorRaisingArgumentParser(prog='PROG')
titled_group = parser.add_argument_group(
title='Titled group', description='Group description')
mutex_group = \
titled_group.add_mutually_exclusive_group(required=required)
mutex_group.add_argument('--bar', help='bar help')
mutex_group.add_argument('--baz', help='baz help')
return parser
failures = ['--bar X --baz Y', '--baz X --bar Y']
successes = [
('--bar X', NS(bar='X', baz=None)),
('--baz Y', NS(bar=None, baz='Y')),
]
successes_when_not_required = [
('', NS(bar=None, baz=None)),
]
usage_when_not_required = '''\
usage: PROG [-h] [--bar BAR | --baz BAZ]
'''
usage_when_required = '''\
usage: PROG [-h] (--bar BAR | --baz BAZ)
'''
help = '''\
optional arguments:
-h, --help show this help message and exit
Titled group:
Group description
--bar BAR bar help
--baz BAZ baz help
'''
class TestMutuallyExclusiveOptionalsAndPositionalsMixed(MEMixin, TestCase):
def get_parser(self, required):
parser = ErrorRaisingArgumentParser(prog='PROG')
parser.add_argument('x', help='x help')
parser.add_argument('-y', action='store_true', help='y help')
group = parser.add_mutually_exclusive_group(required=required)
group.add_argument('a', nargs='?', help='a help')
group.add_argument('-b', action='store_true', help='b help')
group.add_argument('-c', action='store_true', help='c help')
return parser
failures = ['X A -b', '-b -c', '-c X A']
successes = [
('X A', NS(a='A', b=False, c=False, x='X', y=False)),
('X -b', NS(a=None, b=True, c=False, x='X', y=False)),
('X -c', NS(a=None, b=False, c=True, x='X', y=False)),
('X A -y', NS(a='A', b=False, c=False, x='X', y=True)),
('X -y -b', NS(a=None, b=True, c=False, x='X', y=True)),
]
successes_when_not_required = [
('X', NS(a=None, b=False, c=False, x='X', y=False)),
('X -y', NS(a=None, b=False, c=False, x='X', y=True)),
]
usage_when_required = usage_when_not_required = '''\
usage: PROG [-h] [-y] [-b] [-c] x [a]
'''
help = '''\
positional arguments:
x x help
a a help
optional arguments:
-h, --help show this help message and exit
-y y help
-b b help
-c c help
'''
# =================================================
# Mutually exclusive group in parent parser tests
# =================================================
class MEPBase(object):
def get_parser(self, required=None):
parent = super(MEPBase, self).get_parser(required=required)
parser = ErrorRaisingArgumentParser(
prog=parent.prog, add_help=False, parents=[parent])
return parser
class TestMutuallyExclusiveGroupErrorsParent(
MEPBase, TestMutuallyExclusiveGroupErrors):
pass
class TestMutuallyExclusiveSimpleParent(
MEPBase, TestMutuallyExclusiveSimple):
pass
class TestMutuallyExclusiveLongParent(
MEPBase, TestMutuallyExclusiveLong):
pass
class TestMutuallyExclusiveFirstSuppressedParent(
MEPBase, TestMutuallyExclusiveFirstSuppressed):
pass
class TestMutuallyExclusiveManySuppressedParent(
MEPBase, TestMutuallyExclusiveManySuppressed):
pass
class TestMutuallyExclusiveOptionalAndPositionalParent(
MEPBase, TestMutuallyExclusiveOptionalAndPositional):
pass
class TestMutuallyExclusiveOptionalsMixedParent(
MEPBase, TestMutuallyExclusiveOptionalsMixed):
pass
class TestMutuallyExclusiveOptionalsAndPositionalsMixedParent(
MEPBase, TestMutuallyExclusiveOptionalsAndPositionalsMixed):
pass
# =================
# Set default tests
# =================
class TestSetDefaults(TestCase):
def test_set_defaults_no_args(self):
parser = ErrorRaisingArgumentParser()
parser.set_defaults(x='foo')
parser.set_defaults(y='bar', z=1)
self.assertEqual(NS(x='foo', y='bar', z=1),
parser.parse_args([]))
self.assertEqual(NS(x='foo', y='bar', z=1),
parser.parse_args([], NS()))
self.assertEqual(NS(x='baz', y='bar', z=1),
parser.parse_args([], NS(x='baz')))
self.assertEqual(NS(x='baz', y='bar', z=2),
parser.parse_args([], NS(x='baz', z=2)))
def test_set_defaults_with_args(self):
parser = ErrorRaisingArgumentParser()
parser.set_defaults(x='foo', y='bar')
parser.add_argument('-x', default='xfoox')
self.assertEqual(NS(x='xfoox', y='bar'),
parser.parse_args([]))
self.assertEqual(NS(x='xfoox', y='bar'),
parser.parse_args([], NS()))
self.assertEqual(NS(x='baz', y='bar'),
parser.parse_args([], NS(x='baz')))
self.assertEqual(NS(x='1', y='bar'),
parser.parse_args('-x 1'.split()))
self.assertEqual(NS(x='1', y='bar'),
parser.parse_args('-x 1'.split(), NS()))
self.assertEqual(NS(x='1', y='bar'),
parser.parse_args('-x 1'.split(), NS(x='baz')))
def test_set_defaults_subparsers(self):
parser = ErrorRaisingArgumentParser()
parser.set_defaults(x='foo')
subparsers = parser.add_subparsers()
parser_a = subparsers.add_parser('a')
parser_a.set_defaults(y='bar')
self.assertEqual(NS(x='foo', y='bar'),
parser.parse_args('a'.split()))
def test_set_defaults_parents(self):
parent = ErrorRaisingArgumentParser(add_help=False)
parent.set_defaults(x='foo')
parser = ErrorRaisingArgumentParser(parents=[parent])
self.assertEqual(NS(x='foo'), parser.parse_args([]))
def test_set_defaults_same_as_add_argument(self):
parser = ErrorRaisingArgumentParser()
parser.set_defaults(w='W', x='X', y='Y', z='Z')
parser.add_argument('-w')
parser.add_argument('-x', default='XX')
parser.add_argument('y', nargs='?')
parser.add_argument('z', nargs='?', default='ZZ')
# defaults set previously
self.assertEqual(NS(w='W', x='XX', y='Y', z='ZZ'),
parser.parse_args([]))
# reset defaults
parser.set_defaults(w='WW', x='X', y='YY', z='Z')
self.assertEqual(NS(w='WW', x='X', y='YY', z='Z'),
parser.parse_args([]))
def test_set_defaults_same_as_add_argument_group(self):
parser = ErrorRaisingArgumentParser()
parser.set_defaults(w='W', x='X', y='Y', z='Z')
group = parser.add_argument_group('foo')
group.add_argument('-w')
group.add_argument('-x', default='XX')
group.add_argument('y', nargs='?')
group.add_argument('z', nargs='?', default='ZZ')
# defaults set previously
self.assertEqual(NS(w='W', x='XX', y='Y', z='ZZ'),
parser.parse_args([]))
# reset defaults
parser.set_defaults(w='WW', x='X', y='YY', z='Z')
self.assertEqual(NS(w='WW', x='X', y='YY', z='Z'),
parser.parse_args([]))
# =================
# Get default tests
# =================
class TestGetDefault(TestCase):
def test_get_default(self):
parser = ErrorRaisingArgumentParser()
self.assertEqual(None, parser.get_default("foo"))
self.assertEqual(None, parser.get_default("bar"))
parser.add_argument("--foo")
self.assertEqual(None, parser.get_default("foo"))
self.assertEqual(None, parser.get_default("bar"))
parser.add_argument("--bar", type=int, default=42)
self.assertEqual(None, parser.get_default("foo"))
self.assertEqual(42, parser.get_default("bar"))
parser.set_defaults(foo="badger")
self.assertEqual("badger", parser.get_default("foo"))
self.assertEqual(42, parser.get_default("bar"))
# ==========================
# Namespace 'contains' tests
# ==========================
class TestNamespaceContainsSimple(TestCase):
def test_empty(self):
ns = argparse.Namespace()
self.assertEqual('' in ns, False)
self.assertEqual('' not in ns, True)
self.assertEqual('x' in ns, False)
def test_non_empty(self):
ns = argparse.Namespace(x=1, y=2)
self.assertEqual('x' in ns, True)
self.assertEqual('x' not in ns, False)
self.assertEqual('y' in ns, True)
self.assertEqual('' in ns, False)
self.assertEqual('xx' in ns, False)
self.assertEqual('z' in ns, False)
# =====================
# Help formatting tests
# =====================
class TestHelpFormattingMetaclass(type):
def __init__(cls, name, bases, bodydict):
if name == 'HelpTestCase':
return
class AddTests(object):
def __init__(self, test_class, func_suffix, std_name):
self.func_suffix = func_suffix
self.std_name = std_name
for test_func in [self.test_format,
self.test_print,
self.test_print_file]:
test_name = '%s_%s' % (test_func.__name__, func_suffix)
def test_wrapper(self, test_func=test_func):
test_func(self)
try:
test_wrapper.__name__ = test_name
except TypeError:
pass
setattr(test_class, test_name, test_wrapper)
def _get_parser(self, tester):
parser = argparse.ArgumentParser(
*tester.parser_signature.args,
**tester.parser_signature.kwargs)
for argument_sig in getattr(tester, 'argument_signatures', []):
parser.add_argument(*argument_sig.args,
**argument_sig.kwargs)
group_sigs = getattr(tester, 'argument_group_signatures', [])
for group_sig, argument_sigs in group_sigs:
group = parser.add_argument_group(*group_sig.args,
**group_sig.kwargs)
for argument_sig in argument_sigs:
group.add_argument(*argument_sig.args,
**argument_sig.kwargs)
subparsers_sigs = getattr(tester, 'subparsers_signatures', [])
if subparsers_sigs:
subparsers = parser.add_subparsers()
for subparser_sig in subparsers_sigs:
subparsers.add_parser(*subparser_sig.args,
**subparser_sig.kwargs)
return parser
def _test(self, tester, parser_text):
expected_text = getattr(tester, self.func_suffix)
expected_text = textwrap.dedent(expected_text)
if expected_text != parser_text:
print(repr(expected_text))
print(repr(parser_text))
for char1, char2 in zip(expected_text, parser_text):
if char1 != char2:
print('first diff: %r %r' % (char1, char2))
break
tester.assertEqual(expected_text, parser_text)
def test_format(self, tester):
parser = self._get_parser(tester)
format = getattr(parser, 'format_%s' % self.func_suffix)
self._test(tester, format())
def test_print(self, tester):
parser = self._get_parser(tester)
print_ = getattr(parser, 'print_%s' % self.func_suffix)
old_stream = getattr(sys, self.std_name)
setattr(sys, self.std_name, StdIOBuffer())
try:
print_()
parser_text = getattr(sys, self.std_name).getvalue()
finally:
setattr(sys, self.std_name, old_stream)
self._test(tester, parser_text)
def test_print_file(self, tester):
parser = self._get_parser(tester)
print_ = getattr(parser, 'print_%s' % self.func_suffix)
sfile = StdIOBuffer()
print_(sfile)
parser_text = sfile.getvalue()
self._test(tester, parser_text)
# add tests for {format,print}_{usage,help,version}
for func_suffix, std_name in [('usage', 'stdout'),
('help', 'stdout'),
('version', 'stderr')]:
AddTests(cls, func_suffix, std_name)
bases = TestCase,
HelpTestCase = TestHelpFormattingMetaclass('HelpTestCase', bases, {})
class TestHelpBiggerOptionals(HelpTestCase):
"""Make sure that argument help aligns when options are longer"""
parser_signature = Sig(prog='PROG', description='DESCRIPTION',
epilog='EPILOG', version='0.1')
argument_signatures = [
Sig('-x', action='store_true', help='X HELP'),
Sig('--y', help='Y HELP'),
Sig('foo', help='FOO HELP'),
Sig('bar', help='BAR HELP'),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [-v] [-x] [--y Y] foo bar
'''
help = usage + '''\
DESCRIPTION
positional arguments:
foo FOO HELP
bar BAR HELP
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-x X HELP
--y Y Y HELP
EPILOG
'''
version = '''\
0.1
'''
class TestHelpBiggerOptionalGroups(HelpTestCase):
"""Make sure that argument help aligns when options are longer"""
parser_signature = Sig(prog='PROG', description='DESCRIPTION',
epilog='EPILOG', version='0.1')
argument_signatures = [
Sig('-x', action='store_true', help='X HELP'),
Sig('--y', help='Y HELP'),
Sig('foo', help='FOO HELP'),
Sig('bar', help='BAR HELP'),
]
argument_group_signatures = [
(Sig('GROUP TITLE', description='GROUP DESCRIPTION'), [
Sig('baz', help='BAZ HELP'),
Sig('-z', nargs='+', help='Z HELP')]),
]
usage = '''\
usage: PROG [-h] [-v] [-x] [--y Y] [-z Z [Z ...]] foo bar baz
'''
help = usage + '''\
DESCRIPTION
positional arguments:
foo FOO HELP
bar BAR HELP
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-x X HELP
--y Y Y HELP
GROUP TITLE:
GROUP DESCRIPTION
baz BAZ HELP
-z Z [Z ...] Z HELP
EPILOG
'''
version = '''\
0.1
'''
class TestHelpBiggerPositionals(HelpTestCase):
"""Make sure that help aligns when arguments are longer"""
parser_signature = Sig(usage='USAGE', description='DESCRIPTION')
argument_signatures = [
Sig('-x', action='store_true', help='X HELP'),
Sig('--y', help='Y HELP'),
Sig('ekiekiekifekang', help='EKI HELP'),
Sig('bar', help='BAR HELP'),
]
argument_group_signatures = []
usage = '''\
usage: USAGE
'''
help = usage + '''\
DESCRIPTION
positional arguments:
ekiekiekifekang EKI HELP
bar BAR HELP
optional arguments:
-h, --help show this help message and exit
-x X HELP
--y Y Y HELP
'''
version = ''
class TestHelpReformatting(HelpTestCase):
"""Make sure that text after short names starts on the first line"""
parser_signature = Sig(
prog='PROG',
description=' oddly formatted\n'
'description\n'
'\n'
'that is so long that it should go onto multiple '
'lines when wrapped')
argument_signatures = [
Sig('-x', metavar='XX', help='oddly\n'
' formatted -x help'),
Sig('y', metavar='yyy', help='normal y help'),
]
argument_group_signatures = [
(Sig('title', description='\n'
' oddly formatted group\n'
'\n'
'description'),
[Sig('-a', action='store_true',
help=' oddly \n'
'formatted -a help \n'
' again, so long that it should be wrapped over '
'multiple lines')]),
]
usage = '''\
usage: PROG [-h] [-x XX] [-a] yyy
'''
help = usage + '''\
oddly formatted description that is so long that it should go onto \
multiple
lines when wrapped
positional arguments:
yyy normal y help
optional arguments:
-h, --help show this help message and exit
-x XX oddly formatted -x help
title:
oddly formatted group description
-a oddly formatted -a help again, so long that it should \
be wrapped
over multiple lines
'''
version = ''
class TestHelpWrappingShortNames(HelpTestCase):
"""Make sure that text after short names starts on the first line"""
parser_signature = Sig(prog='PROG', description= 'D\nD' * 30)
argument_signatures = [
Sig('-x', metavar='XX', help='XHH HX' * 20),
Sig('y', metavar='yyy', help='YH YH' * 20),
]
argument_group_signatures = [
(Sig('ALPHAS'), [
Sig('-a', action='store_true', help='AHHH HHA' * 10)]),
]
usage = '''\
usage: PROG [-h] [-x XX] [-a] yyy
'''
help = usage + '''\
D DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD \
DD DD DD
DD DD DD DD D
positional arguments:
yyy YH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH \
YHYH YHYH
YHYH YHYH YHYH YHYH YHYH YHYH YHYH YH
optional arguments:
-h, --help show this help message and exit
-x XX XHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH \
HXXHH HXXHH
HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HX
ALPHAS:
-a AHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH HHAAHHH \
HHAAHHH
HHAAHHH HHAAHHH HHA
'''
version = ''
class TestHelpWrappingLongNames(HelpTestCase):
"""Make sure that text after long names starts on the next line"""
parser_signature = Sig(usage='USAGE', description= 'D D' * 30,
version='V V'*30)
argument_signatures = [
Sig('-x', metavar='X' * 25, help='XH XH' * 20),
Sig('y', metavar='y' * 25, help='YH YH' * 20),
]
argument_group_signatures = [
(Sig('ALPHAS'), [
Sig('-a', metavar='A' * 25, help='AH AH' * 20),
Sig('z', metavar='z' * 25, help='ZH ZH' * 20)]),
]
usage = '''\
usage: USAGE
'''
help = usage + '''\
D DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD \
DD DD DD
DD DD DD DD D
positional arguments:
yyyyyyyyyyyyyyyyyyyyyyyyy
YH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH \
YHYH YHYH
YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YH
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-x XXXXXXXXXXXXXXXXXXXXXXXXX
XH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH \
XHXH XHXH
XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XHXH XH
ALPHAS:
-a AAAAAAAAAAAAAAAAAAAAAAAAA
AH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH \
AHAH AHAH
AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AHAH AH
zzzzzzzzzzzzzzzzzzzzzzzzz
ZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH \
ZHZH ZHZH
ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZHZH ZH
'''
version = '''\
V VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV VV \
VV VV VV
VV VV VV VV V
'''
class TestHelpUsage(HelpTestCase):
"""Test basic usage messages"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('-w', nargs='+', help='w'),
Sig('-x', nargs='*', help='x'),
Sig('a', help='a'),
Sig('b', help='b', nargs=2),
Sig('c', help='c', nargs='?'),
]
argument_group_signatures = [
(Sig('group'), [
Sig('-y', nargs='?', help='y'),
Sig('-z', nargs=3, help='z'),
Sig('d', help='d', nargs='*'),
Sig('e', help='e', nargs='+'),
])
]
usage = '''\
usage: PROG [-h] [-w W [W ...]] [-x [X [X ...]]] [-y [Y]] [-z Z Z Z]
a b b [c] [d [d ...]] e [e ...]
'''
help = usage + '''\
positional arguments:
a a
b b
c c
optional arguments:
-h, --help show this help message and exit
-w W [W ...] w
-x [X [X ...]] x
group:
-y [Y] y
-z Z Z Z z
d d
e e
'''
version = ''
class TestHelpOnlyUserGroups(HelpTestCase):
"""Test basic usage messages"""
parser_signature = Sig(prog='PROG', add_help=False)
argument_signatures = []
argument_group_signatures = [
(Sig('xxxx'), [
Sig('-x', help='x'),
Sig('a', help='a'),
]),
(Sig('yyyy'), [
Sig('b', help='b'),
Sig('-y', help='y'),
]),
]
usage = '''\
usage: PROG [-x X] [-y Y] a b
'''
help = usage + '''\
xxxx:
-x X x
a a
yyyy:
b b
-y Y y
'''
version = ''
class TestHelpUsageLongProg(HelpTestCase):
"""Test usage messages where the prog is long"""
parser_signature = Sig(prog='P' * 60)
argument_signatures = [
Sig('-w', metavar='W'),
Sig('-x', metavar='X'),
Sig('a'),
Sig('b'),
]
argument_group_signatures = []
usage = '''\
usage: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
[-h] [-w W] [-x X] a b
'''
help = usage + '''\
positional arguments:
a
b
optional arguments:
-h, --help show this help message and exit
-w W
-x X
'''
version = ''
class TestHelpUsageLongProgOptionsWrap(HelpTestCase):
"""Test usage messages where the prog is long and the optionals wrap"""
parser_signature = Sig(prog='P' * 60)
argument_signatures = [
Sig('-w', metavar='W' * 25),
Sig('-x', metavar='X' * 25),
Sig('-y', metavar='Y' * 25),
Sig('-z', metavar='Z' * 25),
Sig('a'),
Sig('b'),
]
argument_group_signatures = []
usage = '''\
usage: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
[-h] [-w WWWWWWWWWWWWWWWWWWWWWWWWW] \
[-x XXXXXXXXXXXXXXXXXXXXXXXXX]
[-y YYYYYYYYYYYYYYYYYYYYYYYYY] [-z ZZZZZZZZZZZZZZZZZZZZZZZZZ]
a b
'''
help = usage + '''\
positional arguments:
a
b
optional arguments:
-h, --help show this help message and exit
-w WWWWWWWWWWWWWWWWWWWWWWWWW
-x XXXXXXXXXXXXXXXXXXXXXXXXX
-y YYYYYYYYYYYYYYYYYYYYYYYYY
-z ZZZZZZZZZZZZZZZZZZZZZZZZZ
'''
version = ''
class TestHelpUsageLongProgPositionalsWrap(HelpTestCase):
"""Test usage messages where the prog is long and the positionals wrap"""
parser_signature = Sig(prog='P' * 60, add_help=False)
argument_signatures = [
Sig('a' * 25),
Sig('b' * 25),
Sig('c' * 25),
]
argument_group_signatures = []
usage = '''\
usage: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
aaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccc
'''
help = usage + '''\
positional arguments:
aaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccc
'''
version = ''
class TestHelpUsageOptionalsWrap(HelpTestCase):
"""Test usage messages where the optionals wrap"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('-w', metavar='W' * 25),
Sig('-x', metavar='X' * 25),
Sig('-y', metavar='Y' * 25),
Sig('-z', metavar='Z' * 25),
Sig('a'),
Sig('b'),
Sig('c'),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [-w WWWWWWWWWWWWWWWWWWWWWWWWW] \
[-x XXXXXXXXXXXXXXXXXXXXXXXXX]
[-y YYYYYYYYYYYYYYYYYYYYYYYYY] \
[-z ZZZZZZZZZZZZZZZZZZZZZZZZZ]
a b c
'''
help = usage + '''\
positional arguments:
a
b
c
optional arguments:
-h, --help show this help message and exit
-w WWWWWWWWWWWWWWWWWWWWWWWWW
-x XXXXXXXXXXXXXXXXXXXXXXXXX
-y YYYYYYYYYYYYYYYYYYYYYYYYY
-z ZZZZZZZZZZZZZZZZZZZZZZZZZ
'''
version = ''
class TestHelpUsagePositionalsWrap(HelpTestCase):
"""Test usage messages where the positionals wrap"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('-x'),
Sig('-y'),
Sig('-z'),
Sig('a' * 25),
Sig('b' * 25),
Sig('c' * 25),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [-x X] [-y Y] [-z Z]
aaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccc
'''
help = usage + '''\
positional arguments:
aaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccc
optional arguments:
-h, --help show this help message and exit
-x X
-y Y
-z Z
'''
version = ''
class TestHelpUsageOptionalsPositionalsWrap(HelpTestCase):
"""Test usage messages where the optionals and positionals wrap"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('-x', metavar='X' * 25),
Sig('-y', metavar='Y' * 25),
Sig('-z', metavar='Z' * 25),
Sig('a' * 25),
Sig('b' * 25),
Sig('c' * 25),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [-x XXXXXXXXXXXXXXXXXXXXXXXXX] \
[-y YYYYYYYYYYYYYYYYYYYYYYYYY]
[-z ZZZZZZZZZZZZZZZZZZZZZZZZZ]
aaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccc
'''
help = usage + '''\
positional arguments:
aaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccc
optional arguments:
-h, --help show this help message and exit
-x XXXXXXXXXXXXXXXXXXXXXXXXX
-y YYYYYYYYYYYYYYYYYYYYYYYYY
-z ZZZZZZZZZZZZZZZZZZZZZZZZZ
'''
version = ''
class TestHelpUsageOptionalsOnlyWrap(HelpTestCase):
"""Test usage messages where there are only optionals and they wrap"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('-x', metavar='X' * 25),
Sig('-y', metavar='Y' * 25),
Sig('-z', metavar='Z' * 25),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [-x XXXXXXXXXXXXXXXXXXXXXXXXX] \
[-y YYYYYYYYYYYYYYYYYYYYYYYYY]
[-z ZZZZZZZZZZZZZZZZZZZZZZZZZ]
'''
help = usage + '''\
optional arguments:
-h, --help show this help message and exit
-x XXXXXXXXXXXXXXXXXXXXXXXXX
-y YYYYYYYYYYYYYYYYYYYYYYYYY
-z ZZZZZZZZZZZZZZZZZZZZZZZZZ
'''
version = ''
class TestHelpUsagePositionalsOnlyWrap(HelpTestCase):
"""Test usage messages where there are only positionals and they wrap"""
parser_signature = Sig(prog='PROG', add_help=False)
argument_signatures = [
Sig('a' * 25),
Sig('b' * 25),
Sig('c' * 25),
]
argument_group_signatures = []
usage = '''\
usage: PROG aaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccc
'''
help = usage + '''\
positional arguments:
aaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccc
'''
version = ''
class TestHelpVariableExpansion(HelpTestCase):
"""Test that variables are expanded properly in help messages"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('-x', type=int,
help='x %(prog)s %(default)s %(type)s %%'),
Sig('-y', action='store_const', default=42, const='XXX',
help='y %(prog)s %(default)s %(const)s'),
Sig('--foo', choices='abc',
help='foo %(prog)s %(default)s %(choices)s'),
Sig('--bar', default='baz', choices=[1, 2], metavar='BBB',
help='bar %(prog)s %(default)s %(dest)s'),
Sig('spam', help='spam %(prog)s %(default)s'),
Sig('badger', default=0.5, help='badger %(prog)s %(default)s'),
]
argument_group_signatures = [
(Sig('group'), [
Sig('-a', help='a %(prog)s %(default)s'),
Sig('-b', default=-1, help='b %(prog)s %(default)s'),
])
]
usage = ('''\
usage: PROG [-h] [-x X] [-y] [--foo {a,b,c}] [--bar BBB] [-a A] [-b B]
spam badger
''')
help = usage + '''\
positional arguments:
spam spam PROG None
badger badger PROG 0.5
optional arguments:
-h, --help show this help message and exit
-x X x PROG None int %
-y y PROG 42 XXX
--foo {a,b,c} foo PROG None a, b, c
--bar BBB bar PROG baz bar
group:
-a A a PROG None
-b B b PROG -1
'''
version = ''
class TestHelpVariableExpansionUsageSupplied(HelpTestCase):
"""Test that variables are expanded properly when usage= is present"""
parser_signature = Sig(prog='PROG', usage='%(prog)s FOO')
argument_signatures = []
argument_group_signatures = []
usage = ('''\
usage: PROG FOO
''')
help = usage + '''\
optional arguments:
-h, --help show this help message and exit
'''
version = ''
class TestHelpVariableExpansionNoArguments(HelpTestCase):
"""Test that variables are expanded properly with no arguments"""
parser_signature = Sig(prog='PROG', add_help=False)
argument_signatures = []
argument_group_signatures = []
usage = ('''\
usage: PROG
''')
help = usage
version = ''
class TestHelpSuppressUsage(HelpTestCase):
"""Test that items can be suppressed in usage messages"""
parser_signature = Sig(prog='PROG', usage=argparse.SUPPRESS)
argument_signatures = [
Sig('--foo', help='foo help'),
Sig('spam', help='spam help'),
]
argument_group_signatures = []
help = '''\
positional arguments:
spam spam help
optional arguments:
-h, --help show this help message and exit
--foo FOO foo help
'''
usage = ''
version = ''
class TestHelpSuppressOptional(HelpTestCase):
"""Test that optional arguments can be suppressed in help messages"""
parser_signature = Sig(prog='PROG', add_help=False)
argument_signatures = [
Sig('--foo', help=argparse.SUPPRESS),
Sig('spam', help='spam help'),
]
argument_group_signatures = []
usage = '''\
usage: PROG spam
'''
help = usage + '''\
positional arguments:
spam spam help
'''
version = ''
class TestHelpSuppressOptionalGroup(HelpTestCase):
"""Test that optional groups can be suppressed in help messages"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('--foo', help='foo help'),
Sig('spam', help='spam help'),
]
argument_group_signatures = [
(Sig('group'), [Sig('--bar', help=argparse.SUPPRESS)]),
]
usage = '''\
usage: PROG [-h] [--foo FOO] spam
'''
help = usage + '''\
positional arguments:
spam spam help
optional arguments:
-h, --help show this help message and exit
--foo FOO foo help
'''
version = ''
class TestHelpSuppressPositional(HelpTestCase):
"""Test that positional arguments can be suppressed in help messages"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('--foo', help='foo help'),
Sig('spam', help=argparse.SUPPRESS),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [--foo FOO]
'''
help = usage + '''\
optional arguments:
-h, --help show this help message and exit
--foo FOO foo help
'''
version = ''
class TestHelpRequiredOptional(HelpTestCase):
"""Test that required options don't look optional"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('--foo', required=True, help='foo help'),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] --foo FOO
'''
help = usage + '''\
optional arguments:
-h, --help show this help message and exit
--foo FOO foo help
'''
version = ''
class TestHelpAlternatePrefixChars(HelpTestCase):
"""Test that options display with different prefix characters"""
parser_signature = Sig(prog='PROG', prefix_chars='^;', add_help=False)
argument_signatures = [
Sig('^^foo', action='store_true', help='foo help'),
Sig(';b', ';;bar', help='bar help'),
]
argument_group_signatures = []
usage = '''\
usage: PROG [^^foo] [;b BAR]
'''
help = usage + '''\
optional arguments:
^^foo foo help
;b BAR, ;;bar BAR bar help
'''
version = ''
class TestHelpNoHelpOptional(HelpTestCase):
"""Test that the --help argument can be suppressed help messages"""
parser_signature = Sig(prog='PROG', add_help=False)
argument_signatures = [
Sig('--foo', help='foo help'),
Sig('spam', help='spam help'),
]
argument_group_signatures = []
usage = '''\
usage: PROG [--foo FOO] spam
'''
help = usage + '''\
positional arguments:
spam spam help
optional arguments:
--foo FOO foo help
'''
version = ''
class TestHelpVersionOptional(HelpTestCase):
"""Test that the --version argument can be suppressed help messages"""
parser_signature = Sig(prog='PROG', version='1.0')
argument_signatures = [
Sig('--foo', help='foo help'),
Sig('spam', help='spam help'),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [-v] [--foo FOO] spam
'''
help = usage + '''\
positional arguments:
spam spam help
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
--foo FOO foo help
'''
version = '''\
1.0
'''
class TestHelpNone(HelpTestCase):
"""Test that no errors occur if no help is specified"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('--foo'),
Sig('spam'),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [--foo FOO] spam
'''
help = usage + '''\
positional arguments:
spam
optional arguments:
-h, --help show this help message and exit
--foo FOO
'''
version = ''
class TestHelpTupleMetavar(HelpTestCase):
"""Test specifying metavar as a tuple"""
parser_signature = Sig(prog='PROG')
argument_signatures = [
Sig('-w', help='w', nargs='+', metavar=('W1', 'W2')),
Sig('-x', help='x', nargs='*', metavar=('X1', 'X2')),
Sig('-y', help='y', nargs=3, metavar=('Y1', 'Y2', 'Y3')),
Sig('-z', help='z', nargs='?', metavar=('Z1', )),
]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [-w W1 [W2 ...]] [-x [X1 [X2 ...]]] [-y Y1 Y2 Y3] \
[-z [Z1]]
'''
help = usage + '''\
optional arguments:
-h, --help show this help message and exit
-w W1 [W2 ...] w
-x [X1 [X2 ...]] x
-y Y1 Y2 Y3 y
-z [Z1] z
'''
version = ''
class TestHelpRawText(HelpTestCase):
"""Test the RawTextHelpFormatter"""
parser_signature = Sig(
prog='PROG', formatter_class=argparse.RawTextHelpFormatter,
description='Keep the formatting\n'
' exactly as it is written\n'
'\n'
'here\n')
argument_signatures = [
Sig('--foo', help=' foo help should also\n'
'appear as given here'),
Sig('spam', help='spam help'),
]
argument_group_signatures = [
(Sig('title', description=' This text\n'
' should be indented\n'
' exactly like it is here\n'),
[Sig('--bar', help='bar help')]),
]
usage = '''\
usage: PROG [-h] [--foo FOO] [--bar BAR] spam
'''
help = usage + '''\
Keep the formatting
exactly as it is written
here
positional arguments:
spam spam help
optional arguments:
-h, --help show this help message and exit
--foo FOO foo help should also
appear as given here
title:
This text
should be indented
exactly like it is here
--bar BAR bar help
'''
version = ''
class TestHelpRawDescription(HelpTestCase):
"""Test the RawTextHelpFormatter"""
parser_signature = Sig(
prog='PROG', formatter_class=argparse.RawDescriptionHelpFormatter,
description='Keep the formatting\n'
' exactly as it is written\n'
'\n'
'here\n')
argument_signatures = [
Sig('--foo', help=' foo help should not\n'
' retain this odd formatting'),
Sig('spam', help='spam help'),
]
argument_group_signatures = [
(Sig('title', description=' This text\n'
' should be indented\n'
' exactly like it is here\n'),
[Sig('--bar', help='bar help')]),
]
usage = '''\
usage: PROG [-h] [--foo FOO] [--bar BAR] spam
'''
help = usage + '''\
Keep the formatting
exactly as it is written
here
positional arguments:
spam spam help
optional arguments:
-h, --help show this help message and exit
--foo FOO foo help should not retain this odd formatting
title:
This text
should be indented
exactly like it is here
--bar BAR bar help
'''
version = ''
class TestHelpArgumentDefaults(HelpTestCase):
"""Test the ArgumentDefaultsHelpFormatter"""
parser_signature = Sig(
prog='PROG', formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='description')
argument_signatures = [
Sig('--foo', help='foo help - oh and by the way, %(default)s'),
Sig('--bar', action='store_true', help='bar help'),
Sig('spam', help='spam help'),
Sig('badger', nargs='?', default='wooden', help='badger help'),
]
argument_group_signatures = [
(Sig('title', description='description'),
[Sig('--baz', type=int, default=42, help='baz help')]),
]
usage = '''\
usage: PROG [-h] [--foo FOO] [--bar] [--baz BAZ] spam [badger]
'''
help = usage + '''\
description
positional arguments:
spam spam help
badger badger help (default: wooden)
optional arguments:
-h, --help show this help message and exit
--foo FOO foo help - oh and by the way, None
--bar bar help (default: False)
title:
description
--baz BAZ baz help (default: 42)
'''
version = ''
class TestHelpVersionAction(HelpTestCase):
"""Test the default help for the version action"""
parser_signature = Sig(prog='PROG', description='description')
argument_signatures = [Sig('-V', '--version', action='version', version='3.6')]
argument_group_signatures = []
usage = '''\
usage: PROG [-h] [-V]
'''
help = usage + '''\
description
optional arguments:
-h, --help show this help message and exit
-V, --version show program's version number and exit
'''
version = ''
class TestHelpSubparsersOrdering(HelpTestCase):
"""Test ordering of subcommands in help matches the code"""
parser_signature = Sig(prog='PROG',
description='display some subcommands',
version='0.1')
subparsers_signatures = [Sig(name=name)
for name in ('a', 'b', 'c', 'd', 'e')]
usage = '''\
usage: PROG [-h] [-v] {a,b,c,d,e} ...
'''
help = usage + '''\
display some subcommands
positional arguments:
{a,b,c,d,e}
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
'''
version = '''\
0.1
'''
class TestHelpSubparsersWithHelpOrdering(HelpTestCase):
"""Test ordering of subcommands in help matches the code"""
parser_signature = Sig(prog='PROG',
description='display some subcommands',
version='0.1')
subcommand_data = (('a', 'a subcommand help'),
('b', 'b subcommand help'),
('c', 'c subcommand help'),
('d', 'd subcommand help'),
('e', 'e subcommand help'),
)
subparsers_signatures = [Sig(name=name, help=help)
for name, help in subcommand_data]
usage = '''\
usage: PROG [-h] [-v] {a,b,c,d,e} ...
'''
help = usage + '''\
display some subcommands
positional arguments:
{a,b,c,d,e}
a a subcommand help
b b subcommand help
c c subcommand help
d d subcommand help
e e subcommand help
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
'''
version = '''\
0.1
'''
# =====================================
# Optional/Positional constructor tests
# =====================================
class TestInvalidArgumentConstructors(TestCase):
"""Test a bunch of invalid Argument constructors"""
def assertTypeError(self, *args, **kwargs):
parser = argparse.ArgumentParser()
self.assertRaises(TypeError, parser.add_argument,
*args, **kwargs)
def assertValueError(self, *args, **kwargs):
parser = argparse.ArgumentParser()
self.assertRaises(ValueError, parser.add_argument,
*args, **kwargs)
def test_invalid_keyword_arguments(self):
self.assertTypeError('-x', bar=None)
self.assertTypeError('-y', callback='foo')
self.assertTypeError('-y', callback_args=())
self.assertTypeError('-y', callback_kwargs={})
def test_missing_destination(self):
self.assertTypeError()
for action in ['append', 'store']:
self.assertTypeError(action=action)
def test_invalid_option_strings(self):
self.assertValueError('--')
self.assertValueError('---')
def test_invalid_type(self):
self.assertValueError('--foo', type='int')
self.assertValueError('--foo', type=(int, float))
def test_invalid_action(self):
self.assertValueError('-x', action='foo')
self.assertValueError('foo', action='baz')
self.assertValueError('--foo', action=('store', 'append'))
parser = argparse.ArgumentParser()
try:
parser.add_argument("--foo", action="store-true")
except ValueError:
e = sys.exc_info()[1]
expected = 'unknown action'
msg = 'expected %r, found %r' % (expected, e)
self.assertTrue(expected in str(e), msg)
def test_multiple_dest(self):
parser = argparse.ArgumentParser()
parser.add_argument(dest='foo')
try:
parser.add_argument('bar', dest='baz')
except ValueError:
e = sys.exc_info()[1]
expected = 'dest supplied twice for positional argument'
msg = 'expected %r, found %r' % (expected, e)
self.assertTrue(expected in str(e), msg)
def test_no_argument_actions(self):
for action in ['store_const', 'store_true', 'store_false',
'append_const', 'count']:
for attrs in [dict(type=int), dict(nargs='+'),
dict(choices='ab')]:
self.assertTypeError('-x', action=action, **attrs)
def test_no_argument_no_const_actions(self):
# options with zero arguments
for action in ['store_true', 'store_false', 'count']:
# const is always disallowed
self.assertTypeError('-x', const='foo', action=action)
# nargs is always disallowed
self.assertTypeError('-x', nargs='*', action=action)
def test_more_than_one_argument_actions(self):
for action in ['store', 'append']:
# nargs=0 is disallowed
self.assertValueError('-x', nargs=0, action=action)
self.assertValueError('spam', nargs=0, action=action)
# const is disallowed with non-optional arguments
for nargs in [1, '*', '+']:
self.assertValueError('-x', const='foo',
nargs=nargs, action=action)
self.assertValueError('spam', const='foo',
nargs=nargs, action=action)
def test_required_const_actions(self):
for action in ['store_const', 'append_const']:
# nargs is always disallowed
self.assertTypeError('-x', nargs='+', action=action)
def test_parsers_action_missing_params(self):
self.assertTypeError('command', action='parsers')
self.assertTypeError('command', action='parsers', prog='PROG')
self.assertTypeError('command', action='parsers',
parser_class=argparse.ArgumentParser)
def test_required_positional(self):
self.assertTypeError('foo', required=True)
def test_user_defined_action(self):
class Success(Exception):
pass
class Action(object):
def __init__(self,
option_strings,
dest,
const,
default,
required=False):
if dest == 'spam':
if const is Success:
if default is Success:
raise Success()
def __call__(self, *args, **kwargs):
pass
parser = argparse.ArgumentParser()
self.assertRaises(Success, parser.add_argument, '--spam',
action=Action, default=Success, const=Success)
self.assertRaises(Success, parser.add_argument, 'spam',
action=Action, default=Success, const=Success)
# ================================
# Actions returned by add_argument
# ================================
class TestActionsReturned(TestCase):
def test_dest(self):
parser = argparse.ArgumentParser()
action = parser.add_argument('--foo')
self.assertEqual(action.dest, 'foo')
action = parser.add_argument('-b', '--bar')
self.assertEqual(action.dest, 'bar')
action = parser.add_argument('-x', '-y')
self.assertEqual(action.dest, 'x')
def test_misc(self):
parser = argparse.ArgumentParser()
action = parser.add_argument('--foo', nargs='?', const=42,
default=84, type=int, choices=[1, 2],
help='FOO', metavar='BAR', dest='baz')
self.assertEqual(action.nargs, '?')
self.assertEqual(action.const, 42)
self.assertEqual(action.default, 84)
self.assertEqual(action.type, int)
self.assertEqual(action.choices, [1, 2])
self.assertEqual(action.help, 'FOO')
self.assertEqual(action.metavar, 'BAR')
self.assertEqual(action.dest, 'baz')
# ================================
# Argument conflict handling tests
# ================================
class TestConflictHandling(TestCase):
def test_bad_type(self):
self.assertRaises(ValueError, argparse.ArgumentParser,
conflict_handler='foo')
def test_conflict_error(self):
parser = argparse.ArgumentParser()
parser.add_argument('-x')
self.assertRaises(argparse.ArgumentError,
parser.add_argument, '-x')
parser.add_argument('--spam')
self.assertRaises(argparse.ArgumentError,
parser.add_argument, '--spam')
def test_resolve_error(self):
get_parser = argparse.ArgumentParser
parser = get_parser(prog='PROG', conflict_handler='resolve')
parser.add_argument('-x', help='OLD X')
parser.add_argument('-x', help='NEW X')
self.assertEqual(parser.format_help(), textwrap.dedent('''\
usage: PROG [-h] [-x X]
optional arguments:
-h, --help show this help message and exit
-x X NEW X
'''))
parser.add_argument('--spam', metavar='OLD_SPAM')
parser.add_argument('--spam', metavar='NEW_SPAM')
self.assertEqual(parser.format_help(), textwrap.dedent('''\
usage: PROG [-h] [-x X] [--spam NEW_SPAM]
optional arguments:
-h, --help show this help message and exit
-x X NEW X
--spam NEW_SPAM
'''))
# =============================
# Help and Version option tests
# =============================
class TestOptionalsHelpVersionActions(TestCase):
"""Test the help and version actions"""
def _get_error(self, func, *args, **kwargs):
try:
func(*args, **kwargs)
except ArgumentParserError:
return sys.exc_info()[1]
else:
self.assertRaises(ArgumentParserError, func, *args, **kwargs)
def assertPrintHelpExit(self, parser, args_str):
self.assertEqual(
parser.format_help(),
self._get_error(parser.parse_args, args_str.split()).stdout)
def assertPrintVersionExit(self, parser, args_str):
self.assertEqual(
parser.format_version(),
self._get_error(parser.parse_args, args_str.split()).stderr)
def assertArgumentParserError(self, parser, *args):
self.assertRaises(ArgumentParserError, parser.parse_args, args)
def test_version(self):
parser = ErrorRaisingArgumentParser(version='1.0')
self.assertPrintHelpExit(parser, '-h')
self.assertPrintHelpExit(parser, '--help')
self.assertPrintVersionExit(parser, '-v')
self.assertPrintVersionExit(parser, '--version')
def test_version_format(self):
parser = ErrorRaisingArgumentParser(prog='PPP', version='%(prog)s 3.5')
msg = self._get_error(parser.parse_args, ['-v']).stderr
self.assertEqual('PPP 3.5\n', msg)
def test_version_no_help(self):
parser = ErrorRaisingArgumentParser(add_help=False, version='1.0')
self.assertArgumentParserError(parser, '-h')
self.assertArgumentParserError(parser, '--help')
self.assertPrintVersionExit(parser, '-v')
self.assertPrintVersionExit(parser, '--version')
def test_version_action(self):
parser = ErrorRaisingArgumentParser(prog='XXX')
parser.add_argument('-V', action='version', version='%(prog)s 3.7')
msg = self._get_error(parser.parse_args, ['-V']).stderr
self.assertEqual('XXX 3.7\n', msg)
def test_no_help(self):
parser = ErrorRaisingArgumentParser(add_help=False)
self.assertArgumentParserError(parser, '-h')
self.assertArgumentParserError(parser, '--help')
self.assertArgumentParserError(parser, '-v')
self.assertArgumentParserError(parser, '--version')
def test_alternate_help_version(self):
parser = ErrorRaisingArgumentParser()
parser.add_argument('-x', action='help')
parser.add_argument('-y', action='version')
self.assertPrintHelpExit(parser, '-x')
self.assertPrintVersionExit(parser, '-y')
self.assertArgumentParserError(parser, '-v')
self.assertArgumentParserError(parser, '--version')
def test_help_version_extra_arguments(self):
parser = ErrorRaisingArgumentParser(version='1.0')
parser.add_argument('-x', action='store_true')
parser.add_argument('y')
# try all combinations of valid prefixes and suffixes
valid_prefixes = ['', '-x', 'foo', '-x bar', 'baz -x']
valid_suffixes = valid_prefixes + ['--bad-option', 'foo bar baz']
for prefix in valid_prefixes:
for suffix in valid_suffixes:
format = '%s %%s %s' % (prefix, suffix)
self.assertPrintHelpExit(parser, format % '-h')
self.assertPrintHelpExit(parser, format % '--help')
self.assertPrintVersionExit(parser, format % '-v')
self.assertPrintVersionExit(parser, format % '--version')
# ======================
# str() and repr() tests
# ======================
class TestStrings(TestCase):
"""Test str() and repr() on Optionals and Positionals"""
def assertStringEqual(self, obj, result_string):
for func in [str, repr]:
self.assertEqual(func(obj), result_string)
def test_optional(self):
option = argparse.Action(
option_strings=['--foo', '-a', '-b'],
dest='b',
type='int',
nargs='+',
default=42,
choices=[1, 2, 3],
help='HELP',
metavar='METAVAR')
string = (
"Action(option_strings=['--foo', '-a', '-b'], dest='b', "
"nargs='+', const=None, default=42, type='int', "
"choices=[1, 2, 3], help='HELP', metavar='METAVAR')")
self.assertStringEqual(option, string)
def test_argument(self):
argument = argparse.Action(
option_strings=[],
dest='x',
type=float,
nargs='?',
default=2.5,
choices=[0.5, 1.5, 2.5],
help='H HH H',
metavar='MV MV MV')
string = (
"Action(option_strings=[], dest='x', nargs='?', "
"const=None, default=2.5, type=%r, choices=[0.5, 1.5, 2.5], "
"help='H HH H', metavar='MV MV MV')" % float)
self.assertStringEqual(argument, string)
def test_namespace(self):
ns = argparse.Namespace(foo=42, bar='spam')
string = "Namespace(bar='spam', foo=42)"
self.assertStringEqual(ns, string)
def test_parser(self):
parser = argparse.ArgumentParser(prog='PROG')
string = (
"ArgumentParser(prog='PROG', usage=None, description=None, "
"version=None, formatter_class=%r, conflict_handler='error', "
"add_help=True)" % argparse.HelpFormatter)
self.assertStringEqual(parser, string)
# ===============
# Namespace tests
# ===============
class TestNamespace(TestCase):
def test_constructor(self):
ns = argparse.Namespace()
self.assertRaises(AttributeError, getattr, ns, 'x')
ns = argparse.Namespace(a=42, b='spam')
self.assertEqual(ns.a, 42)
self.assertEqual(ns.b, 'spam')
def test_equality(self):
ns1 = argparse.Namespace(a=1, b=2)
ns2 = argparse.Namespace(b=2, a=1)
ns3 = argparse.Namespace(a=1)
ns4 = argparse.Namespace(b=2)
self.assertEqual(ns1, ns2)
self.assertNotEqual(ns1, ns3)
self.assertNotEqual(ns1, ns4)
self.assertNotEqual(ns2, ns3)
self.assertNotEqual(ns2, ns4)
self.assertTrue(ns1 != ns3)
self.assertTrue(ns1 != ns4)
self.assertTrue(ns2 != ns3)
self.assertTrue(ns2 != ns4)
# ===================
# File encoding tests
# ===================
class TestEncoding(TestCase):
def _test_module_encoding(self, path):
path, _ = os.path.splitext(path)
path += ".py"
with codecs.open(path, 'r', 'utf8') as f:
f.read()
def test_argparse_module_encoding(self):
self._test_module_encoding(argparse.__file__)
def test_test_argparse_module_encoding(self):
self._test_module_encoding(__file__)
# ===================
# ArgumentError tests
# ===================
class TestArgumentError(TestCase):
def test_argument_error(self):
msg = "my error here"
error = argparse.ArgumentError(None, msg)
self.assertEqual(str(error), msg)
# =======================
# ArgumentTypeError tests
# =======================
class TestArgumentTypeError(TestCase):
def test_argument_type_error(self):
def spam(string):
raise argparse.ArgumentTypeError('spam!')
parser = ErrorRaisingArgumentParser(prog='PROG', add_help=False)
parser.add_argument('x', type=spam)
try:
parser.parse_args(['XXX'])
except ArgumentParserError:
expected = 'usage: PROG x\nPROG: error: argument x: spam!\n'
msg = sys.exc_info()[1].stderr
self.assertEqual(expected, msg)
else:
self.fail()
# ======================
# parse_known_args tests
# ======================
class TestParseKnownArgs(TestCase):
def test_optionals(self):
parser = argparse.ArgumentParser()
parser.add_argument('--foo')
args, extras = parser.parse_known_args('--foo F --bar --baz'.split())
self.assertEqual(NS(foo='F'), args)
self.assertEqual(['--bar', '--baz'], extras)
def test_mixed(self):
parser = argparse.ArgumentParser()
parser.add_argument('-v', nargs='?', const=1, type=int)
parser.add_argument('--spam', action='store_false')
parser.add_argument('badger')
argv = ["B", "C", "--foo", "-v", "3", "4"]
args, extras = parser.parse_known_args(argv)
self.assertEqual(NS(v=3, spam=True, badger="B"), args)
self.assertEqual(["C", "--foo", "4"], extras)
# ==========================
# add_argument metavar tests
# ==========================
class TestAddArgumentMetavar(TestCase):
EXPECTED_MESSAGE = "length of metavar tuple does not match nargs"
def do_test_no_exception(self, nargs, metavar):
parser = argparse.ArgumentParser()
parser.add_argument("--foo", nargs=nargs, metavar=metavar)
def do_test_exception(self, nargs, metavar):
parser = argparse.ArgumentParser()
with self.assertRaises(ValueError) as cm:
parser.add_argument("--foo", nargs=nargs, metavar=metavar)
self.assertEqual(cm.exception.args[0], self.EXPECTED_MESSAGE)
# Unit tests for different values of metavar when nargs=None
def test_nargs_None_metavar_string(self):
self.do_test_no_exception(nargs=None, metavar="1")
def test_nargs_None_metavar_length0(self):
self.do_test_exception(nargs=None, metavar=tuple())
def test_nargs_None_metavar_length1(self):
self.do_test_no_exception(nargs=None, metavar=("1"))
def test_nargs_None_metavar_length2(self):
self.do_test_exception(nargs=None, metavar=("1", "2"))
def test_nargs_None_metavar_length3(self):
self.do_test_exception(nargs=None, metavar=("1", "2", "3"))
# Unit tests for different values of metavar when nargs=?
def test_nargs_optional_metavar_string(self):
self.do_test_no_exception(nargs="?", metavar="1")
def test_nargs_optional_metavar_length0(self):
self.do_test_exception(nargs="?", metavar=tuple())
def test_nargs_optional_metavar_length1(self):
self.do_test_no_exception(nargs="?", metavar=("1"))
def test_nargs_optional_metavar_length2(self):
self.do_test_exception(nargs="?", metavar=("1", "2"))
def test_nargs_optional_metavar_length3(self):
self.do_test_exception(nargs="?", metavar=("1", "2", "3"))
# Unit tests for different values of metavar when nargs=*
def test_nargs_zeroormore_metavar_string(self):
self.do_test_no_exception(nargs="*", metavar="1")
def test_nargs_zeroormore_metavar_length0(self):
self.do_test_exception(nargs="*", metavar=tuple())
def test_nargs_zeroormore_metavar_length1(self):
self.do_test_no_exception(nargs="*", metavar=("1"))
def test_nargs_zeroormore_metavar_length2(self):
self.do_test_no_exception(nargs="*", metavar=("1", "2"))
def test_nargs_zeroormore_metavar_length3(self):
self.do_test_exception(nargs="*", metavar=("1", "2", "3"))
# Unit tests for different values of metavar when nargs=+
def test_nargs_oneormore_metavar_string(self):
self.do_test_no_exception(nargs="+", metavar="1")
def test_nargs_oneormore_metavar_length0(self):
self.do_test_exception(nargs="+", metavar=tuple())
def test_nargs_oneormore_metavar_length1(self):
self.do_test_no_exception(nargs="+", metavar=("1"))
def test_nargs_oneormore_metavar_length2(self):
self.do_test_no_exception(nargs="+", metavar=("1", "2"))
def test_nargs_oneormore_metavar_length3(self):
self.do_test_exception(nargs="+", metavar=("1", "2", "3"))
# Unit tests for different values of metavar when nargs=...
def test_nargs_remainder_metavar_string(self):
self.do_test_no_exception(nargs="...", metavar="1")
def test_nargs_remainder_metavar_length0(self):
self.do_test_no_exception(nargs="...", metavar=tuple())
def test_nargs_remainder_metavar_length1(self):
self.do_test_no_exception(nargs="...", metavar=("1"))
def test_nargs_remainder_metavar_length2(self):
self.do_test_no_exception(nargs="...", metavar=("1", "2"))
def test_nargs_remainder_metavar_length3(self):
self.do_test_no_exception(nargs="...", metavar=("1", "2", "3"))
# Unit tests for different values of metavar when nargs=A...
def test_nargs_parser_metavar_string(self):
self.do_test_no_exception(nargs="A...", metavar="1")
def test_nargs_parser_metavar_length0(self):
self.do_test_exception(nargs="A...", metavar=tuple())
def test_nargs_parser_metavar_length1(self):
self.do_test_no_exception(nargs="A...", metavar=("1"))
def test_nargs_parser_metavar_length2(self):
self.do_test_exception(nargs="A...", metavar=("1", "2"))
def test_nargs_parser_metavar_length3(self):
self.do_test_exception(nargs="A...", metavar=("1", "2", "3"))
# Unit tests for different values of metavar when nargs=1
def test_nargs_1_metavar_string(self):
self.do_test_no_exception(nargs=1, metavar="1")
def test_nargs_1_metavar_length0(self):
self.do_test_exception(nargs=1, metavar=tuple())
def test_nargs_1_metavar_length1(self):
self.do_test_no_exception(nargs=1, metavar=("1"))
def test_nargs_1_metavar_length2(self):
self.do_test_exception(nargs=1, metavar=("1", "2"))
def test_nargs_1_metavar_length3(self):
self.do_test_exception(nargs=1, metavar=("1", "2", "3"))
# Unit tests for different values of metavar when nargs=2
def test_nargs_2_metavar_string(self):
self.do_test_no_exception(nargs=2, metavar="1")
def test_nargs_2_metavar_length0(self):
self.do_test_exception(nargs=2, metavar=tuple())
def test_nargs_2_metavar_length1(self):
self.do_test_no_exception(nargs=2, metavar=("1"))
def test_nargs_2_metavar_length2(self):
self.do_test_no_exception(nargs=2, metavar=("1", "2"))
def test_nargs_2_metavar_length3(self):
self.do_test_exception(nargs=2, metavar=("1", "2", "3"))
# Unit tests for different values of metavar when nargs=3
def test_nargs_3_metavar_string(self):
self.do_test_no_exception(nargs=3, metavar="1")
def test_nargs_3_metavar_length0(self):
self.do_test_exception(nargs=3, metavar=tuple())
def test_nargs_3_metavar_length1(self):
self.do_test_no_exception(nargs=3, metavar=("1"))
def test_nargs_3_metavar_length2(self):
self.do_test_exception(nargs=3, metavar=("1", "2"))
def test_nargs_3_metavar_length3(self):
self.do_test_no_exception(nargs=3, metavar=("1", "2", "3"))
# ============================
# from argparse import * tests
# ============================
class TestImportStar(TestCase):
def test(self):
for name in argparse.__all__:
self.assertTrue(hasattr(argparse, name))
def test_all_exports_everything_but_modules(self):
items = [
name
for name, value in vars(argparse).items()
if not name.startswith("_")
if not inspect.ismodule(value)
]
self.assertEqual(sorted(items), sorted(argparse.__all__))
def test_main():
# silence warnings about version argument - these are expected
with test_support.check_warnings(
('The "version" argument to ArgumentParser is deprecated.',
DeprecationWarning),
('The (format|print)_version method is deprecated',
DeprecationWarning)):
test_support.run_unittest(__name__)
# Remove global references to avoid looking like we have refleaks.
RFile.seen = {}
WFile.seen = set()
if __name__ == '__main__':
test_main()
|
gpl-2.0
|
[
3,
6529,
26,
17854,
1856,
1603,
14,
6423,
273,
1005,
665,
1597,
1856,
14,
1235,
273,
1005,
32,
6799,
14,
957,
10827,
199,
199,
646,
6010,
199,
646,
6485,
199,
646,
747,
199,
646,
5145,
199,
646,
5672,
199,
646,
984,
199,
646,
13390,
199,
646,
5549,
199,
646,
2882,
199,
646,
7534,
199,
199,
504,
5228,
492,
5228,
199,
199,
533,
20992,
2090,
3299,
8,
6424,
304,
272,
986,
199,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
533,
7640,
8,
2796,
14,
1746,
304,
339,
347,
26400,
8,
277,
12,
1559,
17,
12,
1559,
18,
304,
267,
340,
1559,
17,
1137,
1559,
18,
26,
288,
870,
8355,
288,
870,
8,
2722,
8,
1113,
17,
430,
288,
870,
8,
2722,
8,
1113,
18,
430,
288,
870,
8,
1113,
17,
9,
288,
870,
8,
1113,
18,
9,
267,
1613,
8,
1746,
12,
291,
680,
629,
8,
1113,
17,
12,
1559,
18,
9,
339,
347,
3613,
8,
277,
304,
267,
327,
710,
2295,
5534,
626,
1004,
19696,
11058,
737,
5939,
4362,
12,
1325,
642,
267,
327,
13942,
883,
506,
10087,
701,
4260,
314,
26865,
2709,
3734,
267,
327,
1750,
14,
221,
4005,
4868,
626,
642,
30075,
365,
2549,
12,
15376,
26865,
2709,
14,
267,
2589,
275,
511,
63,
4058,
14,
8263,
5894,
18183,
342,
267,
2589,
14,
16787,
480,
28427,
531,
267,
291,
14,
12808,
8,
1813,
855,
2224,
3368,
421,
199,
533,
12540,
3567,
4256,
8,
785,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
808,
63,
694,
275,
5549,
14,
11983,
342,
267,
291,
14,
1753,
63,
694,
275,
747,
14,
9458,
342,
267,
747,
14,
8563,
8,
277,
14,
808,
63,
694,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
8563,
8,
277,
14,
1753,
63,
694,
9,
267,
5145,
14,
9242,
8,
277,
14,
808,
63,
694,
12,
715,
9,
339,
347,
1218,
63,
6753,
63,
493,
8,
277,
12,
1788,
304,
267,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
808,
63,
694,
12,
1788,
9,
267,
543,
1551,
8,
493,
63,
515,
12,
283,
87,
358,
465,
570,
26,
288,
570,
14,
952,
8,
1501,
9,
267,
747,
14,
11693,
8,
493,
63,
515,
12,
5672,
14,
51,
63,
41,
5670,
9,
199,
199,
533,
14625,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
958,
275,
2074,
421,
199,
533,
9380,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
855,
807,
4343,
873,
8,
958,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
3355,
63,
1744,
275,
3355,
8,
277,
855,
807,
4343,
1744,
1012,
267,
17582,
63,
495,
275,
1656,
1987,
904,
26861,
83,
2458,
82,
7,
450,
16477,
367,
16477,
315,
3355,
63,
1744,
566,
267,
372,
1543,
83,
4042,
83,
3171,
450,
334,
466,
8,
277,
2843,
354,
3108,
17582,
63,
495,
9,
339,
636,
2227,
363,
275,
488,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
6802,
8,
277,
9,
508,
6802,
8,
1848,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
421,
199,
533,
5886,
21811,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1245,
12,
3839,
29,
403,
12,
4635,
29,
403,
12,
1125,
63,
600,
29,
403,
304,
267,
2186,
855,
826,
721,
277,
12,
1245,
12,
3839,
12,
4635,
9,
267,
291,
14,
1188,
275,
1245,
267,
291,
14,
2703,
275,
3839,
267,
291,
14,
3083,
275,
4635,
267,
291,
14,
705,
63,
600,
275,
1125,
63,
600,
421,
199,
318,
4635,
63,
475,
63,
2087,
63,
705,
8,
1122,
63,
589,
12,
627,
589,
12,
1011,
958,
304,
272,
327,
340,
642,
365,
3769,
2797,
15035,
436,
4635,
503,
3839,
365,
2575,
3769,
272,
327,
20884,
12,
9329,
1240,
314,
805,
436,
4691,
314,
25188,
805,
272,
327,
8579,
314,
1919,
272,
340,
1228,
8,
1274,
14,
3083,
12,
20992,
2090,
3299,
9,
503,
1228,
8,
1274,
14,
2703,
12,
20992,
2090,
3299,
304,
267,
372,
2198,
63,
589,
2031,
589,
12,
1011,
958,
9,
339,
327,
340,
642,
365,
440,
3769,
2797,
15035,
12,
4660,
4635,
436,
272,
327,
675,
652,
465,
314,
5886,
21811,
1245,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
2269,
63,
3083,
275,
984,
14,
3083,
272,
984,
14,
2703,
275,
20992,
2090,
3299,
342,
272,
984,
14,
3083,
275,
20992,
2090,
3299,
342,
272,
862,
26,
267,
862,
26,
288,
754,
275,
2198,
63,
589,
2031,
589,
12,
1011,
958,
9,
288,
367,
790,
315,
769,
8,
2936,
8,
1099,
2298,
355,
340,
2519,
8,
1099,
12,
790,
9,
365,
984,
14,
2703,
26,
490,
5371,
8,
1099,
12,
790,
12,
2269,
63,
2703,
9,
355,
340,
2519,
8,
1099,
12,
790,
9,
365,
984,
14,
3083,
26,
490,
5371,
8,
1099,
12,
790,
12,
2269,
63,
3083,
9,
288,
372,
754,
267,
871,
14838,
26,
288,
1233,
275,
984,
14,
2804,
63,
815,
3430,
17,
1055,
600,
288,
3839,
275,
984,
14,
2703,
14,
7150,
342,
288,
4635,
275,
984,
14,
3083,
14,
7150,
342,
288,
746,
5886,
21811,
480,
24738,
401,
3839,
12,
4635,
12,
1233,
9,
272,
3753,
26,
267,
984,
14,
2703,
275,
2269,
63,
2703,
267,
984,
14,
3083,
275,
2269,
63,
3083,
421,
199,
533,
4520,
1537,
11136,
10730,
8,
18978,
14,
10730,
304,
339,
347,
2198,
63,
589,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2198,
63,
589,
275,
1613,
8,
547,
1537,
11136,
10730,
12,
291,
680,
1122,
63,
589,
267,
372,
4635,
63,
475,
63,
2087,
63,
705,
8,
1122,
63,
589,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
4458,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
4458,
275,
1613,
8,
547,
1537,
11136,
10730,
12,
291,
680,
2224,
267,
372,
4635,
63,
475,
63,
2087,
63,
705,
8,
2224,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
1125,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1125,
275,
1613,
8,
547,
1537
] |
[
6529,
26,
17854,
1856,
1603,
14,
6423,
273,
1005,
665,
1597,
1856,
14,
1235,
273,
1005,
32,
6799,
14,
957,
10827,
199,
199,
646,
6010,
199,
646,
6485,
199,
646,
747,
199,
646,
5145,
199,
646,
5672,
199,
646,
984,
199,
646,
13390,
199,
646,
5549,
199,
646,
2882,
199,
646,
7534,
199,
199,
504,
5228,
492,
5228,
199,
199,
533,
20992,
2090,
3299,
8,
6424,
304,
272,
986,
199,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
533,
7640,
8,
2796,
14,
1746,
304,
339,
347,
26400,
8,
277,
12,
1559,
17,
12,
1559,
18,
304,
267,
340,
1559,
17,
1137,
1559,
18,
26,
288,
870,
8355,
288,
870,
8,
2722,
8,
1113,
17,
430,
288,
870,
8,
2722,
8,
1113,
18,
430,
288,
870,
8,
1113,
17,
9,
288,
870,
8,
1113,
18,
9,
267,
1613,
8,
1746,
12,
291,
680,
629,
8,
1113,
17,
12,
1559,
18,
9,
339,
347,
3613,
8,
277,
304,
267,
327,
710,
2295,
5534,
626,
1004,
19696,
11058,
737,
5939,
4362,
12,
1325,
642,
267,
327,
13942,
883,
506,
10087,
701,
4260,
314,
26865,
2709,
3734,
267,
327,
1750,
14,
221,
4005,
4868,
626,
642,
30075,
365,
2549,
12,
15376,
26865,
2709,
14,
267,
2589,
275,
511,
63,
4058,
14,
8263,
5894,
18183,
342,
267,
2589,
14,
16787,
480,
28427,
531,
267,
291,
14,
12808,
8,
1813,
855,
2224,
3368,
421,
199,
533,
12540,
3567,
4256,
8,
785,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
808,
63,
694,
275,
5549,
14,
11983,
342,
267,
291,
14,
1753,
63,
694,
275,
747,
14,
9458,
342,
267,
747,
14,
8563,
8,
277,
14,
808,
63,
694,
9,
339,
347,
6766,
8,
277,
304,
267,
747,
14,
8563,
8,
277,
14,
1753,
63,
694,
9,
267,
5145,
14,
9242,
8,
277,
14,
808,
63,
694,
12,
715,
9,
339,
347,
1218,
63,
6753,
63,
493,
8,
277,
12,
1788,
304,
267,
570,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
808,
63,
694,
12,
1788,
9,
267,
543,
1551,
8,
493,
63,
515,
12,
283,
87,
358,
465,
570,
26,
288,
570,
14,
952,
8,
1501,
9,
267,
747,
14,
11693,
8,
493,
63,
515,
12,
5672,
14,
51,
63,
41,
5670,
9,
199,
199,
533,
14625,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
958,
275,
2074,
421,
199,
533,
9380,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
855,
807,
4343,
873,
8,
958,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
3355,
63,
1744,
275,
3355,
8,
277,
855,
807,
4343,
1744,
1012,
267,
17582,
63,
495,
275,
1656,
1987,
904,
26861,
83,
2458,
82,
7,
450,
16477,
367,
16477,
315,
3355,
63,
1744,
566,
267,
372,
1543,
83,
4042,
83,
3171,
450,
334,
466,
8,
277,
2843,
354,
3108,
17582,
63,
495,
9,
339,
636,
2227,
363,
275,
488,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
6802,
8,
277,
9,
508,
6802,
8,
1848,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
421,
199,
533,
5886,
21811,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1245,
12,
3839,
29,
403,
12,
4635,
29,
403,
12,
1125,
63,
600,
29,
403,
304,
267,
2186,
855,
826,
721,
277,
12,
1245,
12,
3839,
12,
4635,
9,
267,
291,
14,
1188,
275,
1245,
267,
291,
14,
2703,
275,
3839,
267,
291,
14,
3083,
275,
4635,
267,
291,
14,
705,
63,
600,
275,
1125,
63,
600,
421,
199,
318,
4635,
63,
475,
63,
2087,
63,
705,
8,
1122,
63,
589,
12,
627,
589,
12,
1011,
958,
304,
272,
327,
340,
642,
365,
3769,
2797,
15035,
436,
4635,
503,
3839,
365,
2575,
3769,
272,
327,
20884,
12,
9329,
1240,
314,
805,
436,
4691,
314,
25188,
805,
272,
327,
8579,
314,
1919,
272,
340,
1228,
8,
1274,
14,
3083,
12,
20992,
2090,
3299,
9,
503,
1228,
8,
1274,
14,
2703,
12,
20992,
2090,
3299,
304,
267,
372,
2198,
63,
589,
2031,
589,
12,
1011,
958,
9,
339,
327,
340,
642,
365,
440,
3769,
2797,
15035,
12,
4660,
4635,
436,
272,
327,
675,
652,
465,
314,
5886,
21811,
1245,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
2269,
63,
3083,
275,
984,
14,
3083,
272,
984,
14,
2703,
275,
20992,
2090,
3299,
342,
272,
984,
14,
3083,
275,
20992,
2090,
3299,
342,
272,
862,
26,
267,
862,
26,
288,
754,
275,
2198,
63,
589,
2031,
589,
12,
1011,
958,
9,
288,
367,
790,
315,
769,
8,
2936,
8,
1099,
2298,
355,
340,
2519,
8,
1099,
12,
790,
9,
365,
984,
14,
2703,
26,
490,
5371,
8,
1099,
12,
790,
12,
2269,
63,
2703,
9,
355,
340,
2519,
8,
1099,
12,
790,
9,
365,
984,
14,
3083,
26,
490,
5371,
8,
1099,
12,
790,
12,
2269,
63,
3083,
9,
288,
372,
754,
267,
871,
14838,
26,
288,
1233,
275,
984,
14,
2804,
63,
815,
3430,
17,
1055,
600,
288,
3839,
275,
984,
14,
2703,
14,
7150,
342,
288,
4635,
275,
984,
14,
3083,
14,
7150,
342,
288,
746,
5886,
21811,
480,
24738,
401,
3839,
12,
4635,
12,
1233,
9,
272,
3753,
26,
267,
984,
14,
2703,
275,
2269,
63,
2703,
267,
984,
14,
3083,
275,
2269,
63,
3083,
421,
199,
533,
4520,
1537,
11136,
10730,
8,
18978,
14,
10730,
304,
339,
347,
2198,
63,
589,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2198,
63,
589,
275,
1613,
8,
547,
1537,
11136,
10730,
12,
291,
680,
1122,
63,
589,
267,
372,
4635,
63,
475,
63,
2087,
63,
705,
8,
1122,
63,
589,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
4458,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
4458,
275,
1613,
8,
547,
1537,
11136,
10730,
12,
291,
680,
2224,
267,
372,
4635,
63,
475,
63,
2087,
63,
705,
8,
2224,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
1125,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1125,
275,
1613,
8,
547,
1537,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mrcslws/htmresearch
|
projects/thing_classification/thing_convergence.py
|
3
|
13625
|
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2016, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
"""
This file is used to run Thing experiments using simulated sensations.
"""
import random
import os
from math import ceil
import numpy as np
import pprint
import matplotlib.pyplot as plt
from sklearn import manifold, random_projection
from htmresearch.frameworks.layers.l2_l4_inference import (
L4L2Experiment, rerunExperimentFromLogfile)
from htmresearch.frameworks.layers.object_machine_factory import (
createObjectMachine
)
def getL4Params():
"""
Returns a good default set of parameters to use in the L4 region.
"""
return {
"columnCount": 256,
"cellsPerColumn": 16,
"learn": True,
"learnOnOneCell": False,
"initialPermanence": 0.51,
"connectedPermanence": 0.6,
"permanenceIncrement": 0.1,
"permanenceDecrement": 0.01,
"minThreshold": 19,
"predictedSegmentDecrement": 0.0,
"activationThreshold": 19,
"sampleSize": 20,
"implementation": "etm",
}
def getL2Params():
"""
Returns a good default set of parameters to use in the L4 region.
"""
return {
"inputWidth": 256 * 16,
"cellCount": 4096,
"sdrSize": 40,
"synPermProximalInc": 0.5,
"synPermProximalDec": 0.0,
"initialProximalPermanence": 0.6,
"minThresholdProximal": 9,
"sampleSizeProximal": 10,
"connectedPermanenceProximal": 0.5,
"synPermDistalInc": 0.1,
"synPermDistalDec": 0.001,
"initialDistalPermanence": 0.41,
"activationThresholdDistal": 13,
"sampleSizeDistal": 30,
"connectedPermanenceDistal": 0.5,
"distalSegmentInhibitionFactor": 1.001,
"learningMode": True,
}
def locateConvergencePoint(stats, minOverlap, maxOverlap):
"""
Walk backwards through stats until you locate the first point that diverges
from target overlap values. We need this to handle cases where it might get
to target values, diverge, and then get back again. We want the last
convergence point.
"""
for i,v in enumerate(stats[::-1]):
if not (v >= minOverlap and v <= maxOverlap):
return len(stats)-i + 1
# Never differs - converged in one iteration
return 1
def averageConvergencePoint(inferenceStats, prefix, minOverlap, maxOverlap,
settlingTime):
"""
inferenceStats contains activity traces while the system visits each object.
Given the i'th object, inferenceStats[i] contains activity statistics for
each column for each region for the entire sequence of sensations.
For each object, compute the convergence time - the first point when all
L2 columns have converged.
Return the average convergence time across all objects.
Given inference statistics for a bunch of runs, locate all traces with the
given prefix. For each trace locate the iteration where it finally settles
on targetValue. Return the average settling iteration across all runs.
"""
convergenceSum = 0.0
# For each object
for stats in inferenceStats:
# For each L2 column locate convergence time
convergencePoint = 0.0
for key in stats.iterkeys():
if prefix in key:
columnConvergence = locateConvergencePoint(
stats[key], minOverlap, maxOverlap)
# Ensure this column has converged by the last iteration
# assert(columnConvergence <= len(stats[key]))
convergencePoint = max(convergencePoint, columnConvergence)
convergenceSum += ceil(float(convergencePoint)/settlingTime)
return convergenceSum/len(inferenceStats)
def loadThingObjects(numCorticalColumns=1, objDataPath='./data/'):
"""
Load simulated sensation data on a number of different objects
There is one file per object, each row contains one feature, location pairs
The format is as follows
[(-33.6705, 75.5003, 2.4207)/10] => [[list of active bits of location],
[list of active bits of feature]]
The content before "=>" is the true 3D location / sensation
The number of active bits in the location and feature is listed after "=>".
@return A simple object machine
"""
# create empty simple object machine
objects = createObjectMachine(
machineType="simple",
numInputBits=20,
sensorInputSize=1024,
externalInputSize=1024,
numCorticalColumns=numCorticalColumns,
numFeatures=0,
numLocations=0,
)
for _ in range(numCorticalColumns):
objects.locations.append([])
objects.features.append([])
objFiles = []
for f in os.listdir(objDataPath):
if os.path.isfile(os.path.join(objDataPath, f)):
if '.log' in f:
objFiles.append(f)
idx = 0
OnBitsList = []
for f in objFiles:
objName = f.split('.')[0]
objName = objName[4:]
objFile = open('{}/{}'.format(objDataPath, f))
sensationList = []
for line in objFile.readlines():
# parse thing data file and extract feature/location vectors
sense = line.split('=>')[1].strip(' ').strip('\n')
OnBitsList.append(float(line.split('] =>')[0].split('/')[1]))
location = sense.split('],[')[0].strip('[')
feature = sense.split('],[')[1].strip(']')
location = np.fromstring(location, sep=',', dtype=np.uint8)
feature = np.fromstring(feature, sep=',', dtype=np.uint8)
# add the current sensation to object Machine
sensationList.append((idx, idx))
for c in range(numCorticalColumns):
objects.locations[c].append(set(location.tolist()))
objects.features[c].append(set(feature.tolist()))
idx += 1
objects.addObject(sensationList, objName)
print "load object file: {} object name: {} sensation # {}".format(
f, objName, len(sensationList))
OnBitsList
OnBitsList = np.array(OnBitsList)
plt.figure()
plt.hist(OnBitsList)
return objects, OnBitsList
def trainNetwork(objects, numColumns, l4Params, l2Params, verbose=False):
print " Training sensorimotor network ..."
objectNames = objects.objects.keys()
numObjects = len(objectNames)
exp = L4L2Experiment("shared_features",
L2Overrides=l2Params,
L4Overrides=l4Params,
numCorticalColumns=numColumns)
exp.learnObjects(objects.provideObjectsToLearn())
settlingTime = 1
L2Representations = exp.objectL2Representations
# if verbose:
# print "Learned object representations:"
# pprint.pprint(L2Representations, width=400)
# print "=========================="
# For inference, we will check and plot convergence for each object. For each
# object, we create a sequence of random sensations for each column. We will
# present each sensation for settlingTime time steps to let it settle and
# ensure it converges.
maxSensationNumber = 30
overlapMat = np.zeros((numObjects, numObjects, maxSensationNumber))
numL2ActiveCells = np.zeros((numObjects, maxSensationNumber))
for objectIdx in range(numObjects):
objectId = objectNames[objectIdx]
obj = objects[objectId]
# Create sequence of sensations for this object for one column. The total
# number of sensations is equal to the number of points on the object. No
# point should be visited more than once.
objectCopy = [pair for pair in obj]
random.shuffle(objectCopy)
exp.sendReset()
for sensationNumber in range(maxSensationNumber):
objectSensations = {}
for c in range(numColumns):
objectSensations[c] = []
if sensationNumber >= len(objectCopy):
pair = objectCopy[-1]
else:
pair = objectCopy[sensationNumber]
if numColumns > 1:
raise NotImplementedError
else:
# stay multiple steps on each sensation
for _ in xrange(settlingTime):
objectSensations[0].append(pair)
inferConfig = {
"object": objectId,
"numSteps": len(objectSensations[0]),
"pairs": objectSensations,
"includeRandomLocation": False,
}
inferenceSDRs = objects.provideObjectToInfer(inferConfig)
exp.infer(inferenceSDRs, objectName=objectId, reset=False)
for i in range(numObjects):
overlapMat[objectIdx, i, sensationNumber] = len(
exp.getL2Representations()[0] &
L2Representations[objects.objects.keys()[i]][0])
# if verbose:
# print "Intersection with {}:{}".format(
# objectNames[i], overlapMat[objectIdx, i])
for c in range(numColumns):
numL2ActiveCells[objectIdx, sensationNumber] += len(
exp.getL2Representations()[c])
print "{} # L2 active cells {}: ".format(sensationNumber,
numL2ActiveCells[
objectIdx, sensationNumber])
if verbose:
print "Output for {}: {}".format(objectId, exp.getL2Representations())
print "Final L2 active cells {}: ".format(
numL2ActiveCells[objectIdx, sensationNumber])
print
exp.sendReset()
expResult = {'overlapMat': overlapMat,
'numL2ActiveCells': numL2ActiveCells}
return expResult
def computeAccuracy(expResult, objects):
objectNames = objects.objects.keys()
overlapMat = expResult['overlapMat'][:, :, -1]
numL2ActiveCells = expResult['numL2ActiveCells'][:, -1]
numCorrect = 0
numObjects = overlapMat.shape[0]
numFound = 0
percentOverlap = np.zeros(overlapMat.shape)
for i in range(numObjects):
for j in range(i, numObjects):
percentOverlap[i, j] = overlapMat[i, j] # / np.min([numL2ActiveCells[i], numL2ActiveCells[j]])
objectNames = np.array(objectNames)
for i in range(numObjects):
# idx = np.where(overlapMat[i, :]>confuseThresh)[0]
idx = np.where(percentOverlap[i, :] == np.max(percentOverlap[i, :]))[0]
print " {}, # sensations {}, best match is {}".format(
objectNames[i], len(objects[objectNames[i]]), objectNames[idx])
found = len(np.where(idx == i)[0]) > 0
numFound += found
if not found:
print "<=========== {} was not detected ! ===========>".format(objectNames[i])
if len(idx) > 1:
continue
if idx[0] == i:
numCorrect += 1
accuracy = float(numCorrect)/numObjects
numPerfect = len(np.where(numL2ActiveCells<=40)[0])
print "accuracy: {} ({}/{}) ".format(accuracy, numCorrect, numObjects)
print "perfect retrival ratio: {} ({}/{}) ".format(
float(numPerfect)/numObjects, numPerfect, numObjects)
print "Object detection ratio {}/{} ".format(numFound, numObjects)
return accuracy
def runExperimentAccuracyVsL4Thresh():
accuracyVsThresh = []
threshList = np.arange(13, 20)
for thresh in threshList:
numColumns = 1
l2Params = getL2Params()
l4Params = getL4Params()
l4Params['minThreshold'] = thresh
l4Params['activationThreshold'] = thresh
objects = loadThingObjects(1, './data')
expResult = trainNetwork(objects, numColumns, l4Params, l2Params, True)
accuracy = computeAccuracy(expResult, objects)
accuracyVsThresh.append(accuracy)
plt.figure()
plt.plot(threshList, accuracyVsThresh, '-o')
plt.xlabel('L4 distal Threshold')
plt.ylabel('Classification Accuracy')
plt.savefig('accuracyVsL4Thresh.pdf')
return threshList, accuracyVsThresh
if __name__ == "__main__":
# uncomment to plot accuracy as a function of L4 threshold
# threshList, accuracyVsThresh = runExperimentAccuracyVsL4Thresh()
numColumns = 1
l2Params = getL2Params()
l4Params = getL4Params()
verbose = 1
objects, OnBitsList = loadThingObjects(numColumns, './data')
expResult = trainNetwork(objects, numColumns, l4Params, l2Params, True)
accuracy = computeAccuracy(expResult, objects)
objectNames = objects.objects.keys()
numObjects = len(objectNames)
overlapMat = expResult['overlapMat']
numL2ActiveCells = expResult['numL2ActiveCells']
objectNames = objects.objects.keys()
numObjects = len(objectNames)
plt.figure()
for sensationNumber in range(10):
plt.imshow(overlapMat[:, :, sensationNumber])
plt.xticks(range(numObjects), objectNames, rotation='vertical', fontsize=4)
plt.yticks(range(numObjects), objectNames, fontsize=4)
plt.title('pairwise overlap at step {}'.format(sensationNumber))
plt.xlabel('target representation')
plt.ylabel('inferred representation')
plt.tight_layout()
plt.savefig('plots/overlap_matrix_step_{}.png'.format(sensationNumber))
# plot number of active cells for each object
plt.figure()
objectNamesSort = []
idx = np.argsort(expResult['numL2ActiveCells'][:, -1])
for i in idx:
objectNamesSort.append(objectNames[i])
plt.plot(numL2ActiveCells[idx, -1])
plt.xticks(range(numObjects), objectNamesSort, rotation='vertical', fontsize=5)
plt.tight_layout()
plt.ylabel('Number of active L2 cells')
plt.savefig('plots/number_of_active_l2_cells.pdf')
#
|
agpl-3.0
|
[
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
7800,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
2765,
570,
365,
1202,
370,
1255,
3868,
316,
444,
22263,
1808,
4389,
8097,
542,
561,
1298,
14,
199,
624,
199,
646,
2196,
199,
646,
747,
199,
504,
3473,
492,
30449,
199,
646,
2680,
465,
980,
199,
646,
10933,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
6357,
492,
2169,
32294,
12,
2196,
63,
16539,
199,
199,
504,
30010,
31788,
14,
32037,
14,
4359,
14,
76,
18,
63,
76,
20,
63,
20580,
492,
334,
523,
491,
20,
44,
18,
20781,
12,
295,
1065,
20781,
2532,
2445,
493,
9,
199,
199,
504,
30010,
31788,
14,
32037,
14,
4359,
14,
785,
63,
6744,
63,
3702,
492,
334,
523,
1218,
1692,
8412,
199,
9,
421,
199,
318,
664,
44,
20,
6007,
837,
523,
408,
523,
1803,
282,
6954,
849,
663,
402,
2633,
370,
675,
315,
314,
491,
20,
4897,
14,
523,
408,
523,
372,
469,
272,
298,
2301,
2353,
582,
7633,
12,
272,
298,
9041,
2623,
4547,
582,
3193,
12,
272,
298,
4643,
582,
715,
12,
272,
298,
4643,
3314,
4395,
8108,
582,
756,
12,
272,
298,
2747,
2623,
24492,
582,
378,
14,
2869,
12,
272,
298,
7113,
2623,
24492,
582,
378,
14,
22,
12,
272,
298,
529,
24492,
29485,
582,
378,
14,
17,
12,
272,
298,
529,
24492,
8584,
264,
434,
582,
378,
14,
614,
12,
272,
298,
827,
12109,
582,
5851,
12,
272,
298,
21118,
12520,
8584,
264,
434,
582,
378,
14,
16,
12,
272,
298,
12312,
12109,
582,
5851,
12,
272,
298,
3271,
2320,
582,
3388,
12,
272,
298,
12236,
582,
298,
386,
77,
401,
523,
789,
4388,
199,
318,
664,
44,
18,
6007,
837,
523,
408,
523,
1803,
282,
6954,
849,
663,
402,
2633,
370,
675,
315,
314,
491,
20,
4897,
14,
523,
408,
523,
372,
469,
272,
298,
1210,
6216,
582,
7633,
627,
3193,
12,
272,
298,
3890,
2353,
582,
17125,
12,
272,
298,
3893,
82,
2320,
582,
6335,
12,
272,
298,
9466,
23554,
26689,
7265,
30612,
582,
378,
14,
21,
12,
272,
298,
9466,
23554,
26689,
7265,
8584,
582,
378,
14,
16,
12,
272,
298,
2747,
26689,
7265,
2623,
24492,
582,
378,
14,
22,
12,
272,
298,
827,
12109,
26689,
7265,
582,
1749,
12,
272,
298,
3271,
2320,
26689,
7265,
582,
1616,
12,
272,
298,
7113,
2623,
24492,
26689,
7265,
582,
378,
14,
21,
12,
272,
298,
9466,
23554,
12012,
279,
30612,
582,
378,
14,
17,
12,
272,
298,
9466,
23554,
12012,
279,
8584,
582,
378,
14,
4587,
12,
272,
298,
2747,
12012,
279,
2623,
24492,
582,
378,
14,
2953,
12,
272,
298,
12312,
12109,
12012,
279,
582,
4944,
12,
272,
298,
3271,
2320,
12012,
279,
582,
4233,
12,
272,
298,
7113,
2623,
24492,
12012,
279,
582,
378,
14,
21,
12,
272,
298,
2686,
279,
12520,
607,
20215,
15415,
12666,
582,
413,
14,
4587,
12,
272,
298,
10546,
1385,
582,
715,
12,
523,
789,
421,
199,
318,
16592,
7619,
10925,
3428,
8,
3200,
12,
1748,
28709,
12,
1390,
28709,
304,
523,
408,
523,
644,
4878,
8552,
4012,
5020,
5133,
1265,
16592,
314,
1642,
2376,
626,
487,
422,
3389,
523,
687,
1347,
15145,
1338,
14,
221,
2136,
1929,
642,
370,
2429,
5560,
2382,
652,
5594,
664,
523,
370,
1347,
1338,
12,
487,
422,
303,
12,
436,
2066,
664,
1771,
4020,
14,
221,
2136,
2934,
314,
2061,
523,
21346,
2376,
14,
523,
408,
523,
367,
284,
12,
86,
315,
3874,
8,
3200,
14172,
17,
4682,
272,
340,
440,
334,
86,
2356,
1748,
28709,
436,
373,
2695,
1390,
28709,
304,
489,
372,
822,
8,
3200,
7216,
73,
435,
413,
819,
327,
5612,
422,
22754,
446,
3818,
3046,
315,
1373,
8494,
523,
372,
413,
421,
199,
318,
8095,
7619,
10925,
3428,
8,
20580,
8257,
12,
2403,
12,
1748,
28709,
12,
1390,
28709,
12,
1169,
663,
32642,
1366,
304,
523,
408,
523,
17353,
8257,
3509,
10679,
26365,
1830,
314,
2656,
1321,
30066,
1924,
909,
14,
819,
9138,
314,
284,
1133,
72,
909,
12,
17353,
8257,
59,
73,
61,
3509,
10679,
11076,
367,
523,
1924,
2763,
367,
1924,
4897,
367,
314,
8039,
3414,
402,
542,
561,
1298,
14,
819,
2104,
1924,
909,
12,
4526,
314,
21346,
900,
446,
314,
1642,
2376,
1380,
1006,
523,
491,
18,
4362,
1172,
3818,
3046,
14,
819,
1432,
314,
8095,
21346,
900,
9371,
1006,
2251,
14,
819,
9138,
17353,
11076,
367,
282,
22219,
402,
7858,
12,
16592,
1006,
26365,
543,
314,
523,
1627,
2403,
14,
2104,
1924,
3307,
16592,
314,
8494,
2382,
652,
3753,
663,
1118,
83,
523,
641,
1347,
1110,
14,
1432,
314,
8095,
663,
32642,
8494,
9371,
1006,
7858,
14,
523,
408,
523,
21346,
6959,
275,
378,
14,
16,
819,
327,
2104,
1924,
909,
523,
367,
5020,
315,
17353,
8257,
26,
339,
327,
2104,
1924,
491,
18,
2763,
16592,
21346,
900,
272,
21346,
3428,
275,
378,
14,
16,
272,
367,
790,
315,
5020,
14,
16007,
837,
489,
340,
2403,
315,
790,
26,
267,
2763,
7619,
10925,
275,
16592,
7619,
10925,
3428,
8,
881,
5020,
59,
498,
467,
1748,
28709,
12,
1390,
28709,
9,
398
] |
[
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
7800,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
2765,
570,
365,
1202,
370,
1255,
3868,
316,
444,
22263,
1808,
4389,
8097,
542,
561,
1298,
14,
199,
624,
199,
646,
2196,
199,
646,
747,
199,
504,
3473,
492,
30449,
199,
646,
2680,
465,
980,
199,
646,
10933,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
6357,
492,
2169,
32294,
12,
2196,
63,
16539,
199,
199,
504,
30010,
31788,
14,
32037,
14,
4359,
14,
76,
18,
63,
76,
20,
63,
20580,
492,
334,
523,
491,
20,
44,
18,
20781,
12,
295,
1065,
20781,
2532,
2445,
493,
9,
199,
199,
504,
30010,
31788,
14,
32037,
14,
4359,
14,
785,
63,
6744,
63,
3702,
492,
334,
523,
1218,
1692,
8412,
199,
9,
421,
199,
318,
664,
44,
20,
6007,
837,
523,
408,
523,
1803,
282,
6954,
849,
663,
402,
2633,
370,
675,
315,
314,
491,
20,
4897,
14,
523,
408,
523,
372,
469,
272,
298,
2301,
2353,
582,
7633,
12,
272,
298,
9041,
2623,
4547,
582,
3193,
12,
272,
298,
4643,
582,
715,
12,
272,
298,
4643,
3314,
4395,
8108,
582,
756,
12,
272,
298,
2747,
2623,
24492,
582,
378,
14,
2869,
12,
272,
298,
7113,
2623,
24492,
582,
378,
14,
22,
12,
272,
298,
529,
24492,
29485,
582,
378,
14,
17,
12,
272,
298,
529,
24492,
8584,
264,
434,
582,
378,
14,
614,
12,
272,
298,
827,
12109,
582,
5851,
12,
272,
298,
21118,
12520,
8584,
264,
434,
582,
378,
14,
16,
12,
272,
298,
12312,
12109,
582,
5851,
12,
272,
298,
3271,
2320,
582,
3388,
12,
272,
298,
12236,
582,
298,
386,
77,
401,
523,
789,
4388,
199,
318,
664,
44,
18,
6007,
837,
523,
408,
523,
1803,
282,
6954,
849,
663,
402,
2633,
370,
675,
315,
314,
491,
20,
4897,
14,
523,
408,
523,
372,
469,
272,
298,
1210,
6216,
582,
7633,
627,
3193,
12,
272,
298,
3890,
2353,
582,
17125,
12,
272,
298,
3893,
82,
2320,
582,
6335,
12,
272,
298,
9466,
23554,
26689,
7265,
30612,
582,
378,
14,
21,
12,
272,
298,
9466,
23554,
26689,
7265,
8584,
582,
378,
14,
16,
12,
272,
298,
2747,
26689,
7265,
2623,
24492,
582,
378,
14,
22,
12,
272,
298,
827,
12109,
26689,
7265,
582,
1749,
12,
272,
298,
3271,
2320,
26689,
7265,
582,
1616,
12,
272,
298,
7113,
2623,
24492,
26689,
7265,
582,
378,
14,
21,
12,
272,
298,
9466,
23554,
12012,
279,
30612,
582,
378,
14,
17,
12,
272,
298,
9466,
23554,
12012,
279,
8584,
582,
378,
14,
4587,
12,
272,
298,
2747,
12012,
279,
2623,
24492,
582,
378,
14,
2953,
12,
272,
298,
12312,
12109,
12012,
279,
582,
4944,
12,
272,
298,
3271,
2320,
12012,
279,
582,
4233,
12,
272,
298,
7113,
2623,
24492,
12012,
279,
582,
378,
14,
21,
12,
272,
298,
2686,
279,
12520,
607,
20215,
15415,
12666,
582,
413,
14,
4587,
12,
272,
298,
10546,
1385,
582,
715,
12,
523,
789,
421,
199,
318,
16592,
7619,
10925,
3428,
8,
3200,
12,
1748,
28709,
12,
1390,
28709,
304,
523,
408,
523,
644,
4878,
8552,
4012,
5020,
5133,
1265,
16592,
314,
1642,
2376,
626,
487,
422,
3389,
523,
687,
1347,
15145,
1338,
14,
221,
2136,
1929,
642,
370,
2429,
5560,
2382,
652,
5594,
664,
523,
370,
1347,
1338,
12,
487,
422,
303,
12,
436,
2066,
664,
1771,
4020,
14,
221,
2136,
2934,
314,
2061,
523,
21346,
2376,
14,
523,
408,
523,
367,
284,
12,
86,
315,
3874,
8,
3200,
14172,
17,
4682,
272,
340,
440,
334,
86,
2356,
1748,
28709,
436,
373,
2695,
1390,
28709,
304,
489,
372,
822,
8,
3200,
7216,
73,
435,
413,
819,
327,
5612,
422,
22754,
446,
3818,
3046,
315,
1373,
8494,
523,
372,
413,
421,
199,
318,
8095,
7619,
10925,
3428,
8,
20580,
8257,
12,
2403,
12,
1748,
28709,
12,
1390,
28709,
12,
1169,
663,
32642,
1366,
304,
523,
408,
523,
17353,
8257,
3509,
10679,
26365,
1830,
314,
2656,
1321,
30066,
1924,
909,
14,
819,
9138,
314,
284,
1133,
72,
909,
12,
17353,
8257,
59,
73,
61,
3509,
10679,
11076,
367,
523,
1924,
2763,
367,
1924,
4897,
367,
314,
8039,
3414,
402,
542,
561,
1298,
14,
819,
2104,
1924,
909,
12,
4526,
314,
21346,
900,
446,
314,
1642,
2376,
1380,
1006,
523,
491,
18,
4362,
1172,
3818,
3046,
14,
819,
1432,
314,
8095,
21346,
900,
9371,
1006,
2251,
14,
819,
9138,
17353,
11076,
367,
282,
22219,
402,
7858,
12,
16592,
1006,
26365,
543,
314,
523,
1627,
2403,
14,
2104,
1924,
3307,
16592,
314,
8494,
2382,
652,
3753,
663,
1118,
83,
523,
641,
1347,
1110,
14,
1432,
314,
8095,
663,
32642,
8494,
9371,
1006,
7858,
14,
523,
408,
523,
21346,
6959,
275,
378,
14,
16,
819,
327,
2104,
1924,
909,
523,
367,
5020,
315,
17353,
8257,
26,
339,
327,
2104,
1924,
491,
18,
2763,
16592,
21346,
900,
272,
21346,
3428,
275,
378,
14,
16,
272,
367,
790,
315,
5020,
14,
16007,
837,
489,
340,
2403,
315,
790,
26,
267,
2763,
7619,
10925,
275,
16592,
7619,
10925,
3428,
8,
881,
5020,
59,
498,
467,
1748,
28709,
12,
1390,
28709,
9,
398,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import json
import pytest
import sys
if sys.version_info < (2, 7):
pytestmark = pytest.mark.skip("F5 Ansible modules require Python >= 2.7")
from ansible.module_utils.basic import AnsibleModule
try:
from library.modules.bigip_lx_package import Parameters
from library.modules.bigip_lx_package import ModuleManager
from library.modules.bigip_lx_package import ArgumentSpec
# In Ansible 2.8, Ansible changed import paths.
from test.units.compat import unittest
from test.units.compat.mock import Mock
from test.units.compat.mock import patch
from test.units.modules.utils import set_module_args
except ImportError:
from ansible.modules.network.f5.bigip_lx_package import Parameters
from ansible.modules.network.f5.bigip_lx_package import ArgumentSpec
from ansible.modules.network.f5.bigip_lx_package import ModuleManager
# Ansible 2.8 imports
from units.compat import unittest
from units.compat.mock import Mock
from units.compat.mock import patch
from units.modules.utils import set_module_args
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
if path in fixture_data:
return fixture_data[path]
with open(path) as f:
data = f.read()
try:
data = json.loads(data)
except Exception:
pass
fixture_data[path] = data
return data
class TestParameters(unittest.TestCase):
def test_module_parameters(self):
args = dict(
package='MyApp-0.1.0-0001.noarch.rpm',
state='present'
)
p = Parameters(params=args)
assert p.package == 'MyApp-0.1.0-0001.noarch.rpm'
class TestManager(unittest.TestCase):
def setUp(self):
self.spec = ArgumentSpec()
self.patcher1 = patch('time.sleep')
self.patcher1.start()
try:
self.p1 = patch('library.modules.bigip_lx_package.tmos_version')
self.m1 = self.p1.start()
self.m1.return_value = '12.1.3'
except Exception:
self.p1 = patch('ansible.modules.network.f5.bigip_lx_package.tmos_version')
self.m1 = self.p1.start()
self.m1.return_value = '12.1.3'
def tearDown(self):
self.patcher1.stop()
def test_create_iapp_template(self, *args):
package_name = os.path.join(fixture_path, 'MyApp-0.1.0-0001.noarch.rpm')
# Configure the arguments that would be sent to the Ansible module
set_module_args(dict(
package=package_name,
state='present',
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode,
required_if=self.spec.required_if
)
mm = ModuleManager(module=module)
# Override methods to force specific logic in the module to happen
mm.exists = Mock(side_effect=[False, True])
mm.create_on_device = Mock(return_value=True)
mm.upload_to_device = Mock(return_value=True)
mm.enable_iapplx_on_device = Mock(return_value=True)
mm.remove_package_file_from_device = Mock(return_value=True)
results = mm.exec_module()
assert results['changed'] is True
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
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,
646,
2022,
199,
646,
4613,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
1520,
304,
272,
4613,
1657,
275,
4613,
14,
1657,
14,
2759,
480,
38,
21,
2622,
4621,
4409,
2018,
2356,
499,
14,
23,
531,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
893,
26,
272,
687,
3555,
14,
3112,
14,
17833,
63,
23605,
63,
2491,
492,
3897,
272,
687,
3555,
14,
3112,
14,
17833,
63,
23605,
63,
2491,
492,
24118,
272,
687,
3555,
14,
3112,
14,
17833,
63,
23605,
63,
2491,
492,
28405,
339,
327,
1010,
2622,
499,
14,
24,
12,
2622,
2896,
492,
3792,
14,
272,
687,
511,
14,
5260,
14,
5819,
492,
2882,
272,
687,
511,
14,
5260,
14,
5819,
14,
1805,
492,
4420,
272,
687,
511,
14,
5260,
14,
5819,
14,
1805,
492,
3371,
339,
687,
511,
14,
5260,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
2590,
3545,
26,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
23605,
63,
2491,
492,
3897,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
23605,
63,
2491,
492,
28405,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
23605,
63,
2491,
492,
24118,
339,
327,
2622,
499,
14,
24,
8925,
272,
687,
6204,
14,
5819,
492,
2882,
272,
687,
6204,
14,
5819,
14,
1805,
492,
4420,
272,
687,
6204,
14,
5819,
14,
1805,
492,
3371,
339,
687,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
421,
199,
5997,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
8769,
358,
199,
5997,
63,
576,
275,
1052,
421,
199,
318,
2248,
63,
5997,
8,
354,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
5997,
63,
515,
12,
536,
9,
339,
340,
931,
315,
10949,
63,
576,
26,
267,
372,
10949,
63,
576,
59,
515,
61,
339,
543,
1551,
8,
515,
9,
465,
289,
26,
267,
666,
275,
289,
14,
739,
342,
339,
862,
26,
267,
666,
275,
2022,
14,
3640,
8,
576,
9,
272,
871,
2186,
26,
267,
986,
339,
10949,
63,
576,
59,
515,
61,
275,
666,
272,
372,
666,
421,
199,
533,
1379,
5976,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
578,
63,
3214,
8,
277,
304,
267,
1249,
275,
1211,
8,
288,
2559,
534,
5713,
2640,
13,
16,
14,
17,
14,
16,
13,
4183,
14,
889,
1047,
14,
14191,
297,
288,
1174,
534,
1881,
7,
267,
776,
267,
299,
275,
3897,
8,
1162,
29,
589,
9,
267,
702,
299,
14,
2491,
508,
283,
5713,
2640,
13,
16,
14,
17,
14,
16,
13,
4183,
14,
889,
1047,
14,
14191,
7,
421,
199,
533,
1379,
2988,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1650,
275,
28405,
342,
267,
291,
14,
11238,
17,
275,
3371,
360,
521,
14,
4532,
358,
267,
291,
14,
11238,
17,
14,
928,
342,
398,
862,
26,
288,
291,
14,
80,
17,
275,
3371,
360,
4342,
14,
3112,
14,
17833,
63,
23605,
63,
2491,
14,
84,
16908,
63,
1023,
358,
288,
291,
14,
77,
17,
275,
291,
14,
80,
17,
14,
928,
342,
288,
291,
14,
77,
17,
14,
1107,
63,
585,
275,
283,
713,
14,
17,
14,
19,
7,
267,
871,
2186,
26,
288,
291,
14,
80,
17,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
23605,
63,
2491,
14,
84,
16908,
63,
1023,
358,
288,
291,
14,
77,
17,
275,
291,
14,
80,
17,
14,
928,
342,
288,
291,
14,
77,
17,
14,
1107,
63,
585,
275,
283,
713,
14,
17,
14,
19,
7,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
11238,
17,
14,
2379,
342,
339,
347,
511,
63,
981,
63,
73,
571,
63,
1160,
8,
277,
12,
627,
589,
304,
267,
2559,
63,
354,
275,
747,
14,
515,
14,
904,
8,
5997,
63,
515,
12,
283,
5713,
2640,
13,
16,
14,
17,
14,
16,
13,
4183,
14,
889,
1047,
14,
14191,
358,
267,
327,
15453,
314,
2368,
626,
3955,
506,
4847,
370,
314,
2622,
859,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
2559,
29,
2491,
63,
354,
12,
288,
1174,
534,
1881,
297,
288,
5022,
29,
807,
8,
355,
1654,
534,
5967,
297,
355,
2505,
534,
2060,
297,
355,
922,
534,
2113,
7,
288,
776,
267,
5082,
398,
859,
275,
6953,
8,
288,
1423,
63,
1650,
29,
277,
14,
1650,
14,
2094,
63,
1650,
12,
288,
5171,
63,
1074,
63,
632,
29,
277,
14,
1650,
14,
9823,
63,
1074,
63,
632,
12,
288,
1415,
63,
692,
29,
277,
14,
1650,
14,
2427,
63,
692,
267,
776,
267,
8562,
275,
24118,
8,
578,
29,
578,
9,
398,
327,
11041,
3102,
370,
3542,
2488,
9661,
315,
314,
859,
370,
5992,
267,
8562,
14,
2444,
275,
4420,
8,
2441,
63,
5881,
1524,
797,
12,
715,
566,
267,
8562,
14,
981,
63,
265,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
267,
8562,
14,
5064,
63,
475,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
267,
8562,
14,
4296,
63,
73,
571,
23605,
63,
265,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
267,
8562,
14,
2168,
63,
2491,
63,
493,
63,
504,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
398,
2058,
275,
8562,
14,
1628,
63,
578,
342,
398,
702,
2058,
459,
2489,
418,
365,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
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,
646,
2022,
199,
646,
4613,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
1520,
304,
272,
4613,
1657,
275,
4613,
14,
1657,
14,
2759,
480,
38,
21,
2622,
4621,
4409,
2018,
2356,
499,
14,
23,
531,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
893,
26,
272,
687,
3555,
14,
3112,
14,
17833,
63,
23605,
63,
2491,
492,
3897,
272,
687,
3555,
14,
3112,
14,
17833,
63,
23605,
63,
2491,
492,
24118,
272,
687,
3555,
14,
3112,
14,
17833,
63,
23605,
63,
2491,
492,
28405,
339,
327,
1010,
2622,
499,
14,
24,
12,
2622,
2896,
492,
3792,
14,
272,
687,
511,
14,
5260,
14,
5819,
492,
2882,
272,
687,
511,
14,
5260,
14,
5819,
14,
1805,
492,
4420,
272,
687,
511,
14,
5260,
14,
5819,
14,
1805,
492,
3371,
339,
687,
511,
14,
5260,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
2590,
3545,
26,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
23605,
63,
2491,
492,
3897,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
23605,
63,
2491,
492,
28405,
272,
687,
3242,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
23605,
63,
2491,
492,
24118,
339,
327,
2622,
499,
14,
24,
8925,
272,
687,
6204,
14,
5819,
492,
2882,
272,
687,
6204,
14,
5819,
14,
1805,
492,
4420,
272,
687,
6204,
14,
5819,
14,
1805,
492,
3371,
339,
687,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
421,
199,
5997,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
8769,
358,
199,
5997,
63,
576,
275,
1052,
421,
199,
318,
2248,
63,
5997,
8,
354,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
5997,
63,
515,
12,
536,
9,
339,
340,
931,
315,
10949,
63,
576,
26,
267,
372,
10949,
63,
576,
59,
515,
61,
339,
543,
1551,
8,
515,
9,
465,
289,
26,
267,
666,
275,
289,
14,
739,
342,
339,
862,
26,
267,
666,
275,
2022,
14,
3640,
8,
576,
9,
272,
871,
2186,
26,
267,
986,
339,
10949,
63,
576,
59,
515,
61,
275,
666,
272,
372,
666,
421,
199,
533,
1379,
5976,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
578,
63,
3214,
8,
277,
304,
267,
1249,
275,
1211,
8,
288,
2559,
534,
5713,
2640,
13,
16,
14,
17,
14,
16,
13,
4183,
14,
889,
1047,
14,
14191,
297,
288,
1174,
534,
1881,
7,
267,
776,
267,
299,
275,
3897,
8,
1162,
29,
589,
9,
267,
702,
299,
14,
2491,
508,
283,
5713,
2640,
13,
16,
14,
17,
14,
16,
13,
4183,
14,
889,
1047,
14,
14191,
7,
421,
199,
533,
1379,
2988,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1650,
275,
28405,
342,
267,
291,
14,
11238,
17,
275,
3371,
360,
521,
14,
4532,
358,
267,
291,
14,
11238,
17,
14,
928,
342,
398,
862,
26,
288,
291,
14,
80,
17,
275,
3371,
360,
4342,
14,
3112,
14,
17833,
63,
23605,
63,
2491,
14,
84,
16908,
63,
1023,
358,
288,
291,
14,
77,
17,
275,
291,
14,
80,
17,
14,
928,
342,
288,
291,
14,
77,
17,
14,
1107,
63,
585,
275,
283,
713,
14,
17,
14,
19,
7,
267,
871,
2186,
26,
288,
291,
14,
80,
17,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
70,
21,
14,
17833,
63,
23605,
63,
2491,
14,
84,
16908,
63,
1023,
358,
288,
291,
14,
77,
17,
275,
291,
14,
80,
17,
14,
928,
342,
288,
291,
14,
77,
17,
14,
1107,
63,
585,
275,
283,
713,
14,
17,
14,
19,
7,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
11238,
17,
14,
2379,
342,
339,
347,
511,
63,
981,
63,
73,
571,
63,
1160,
8,
277,
12,
627,
589,
304,
267,
2559,
63,
354,
275,
747,
14,
515,
14,
904,
8,
5997,
63,
515,
12,
283,
5713,
2640,
13,
16,
14,
17,
14,
16,
13,
4183,
14,
889,
1047,
14,
14191,
358,
267,
327,
15453,
314,
2368,
626,
3955,
506,
4847,
370,
314,
2622,
859,
267,
663,
63,
578,
63,
589,
8,
807,
8,
288,
2559,
29,
2491,
63,
354,
12,
288,
1174,
534,
1881,
297,
288,
5022,
29,
807,
8,
355,
1654,
534,
5967,
297,
355,
2505,
534,
2060,
297,
355,
922,
534,
2113,
7,
288,
776,
267,
5082,
398,
859,
275,
6953,
8,
288,
1423,
63,
1650,
29,
277,
14,
1650,
14,
2094,
63,
1650,
12,
288,
5171,
63,
1074,
63,
632,
29,
277,
14,
1650,
14,
9823,
63,
1074,
63,
632,
12,
288,
1415,
63,
692,
29,
277,
14,
1650,
14,
2427,
63,
692,
267,
776,
267,
8562,
275,
24118,
8,
578,
29,
578,
9,
398,
327,
11041,
3102,
370,
3542,
2488,
9661,
315,
314,
859,
370,
5992,
267,
8562,
14,
2444,
275,
4420,
8,
2441,
63,
5881,
1524,
797,
12,
715,
566,
267,
8562,
14,
981,
63,
265,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
267,
8562,
14,
5064,
63,
475,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
267,
8562,
14,
4296,
63,
73,
571,
23605,
63,
265,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
267,
8562,
14,
2168,
63,
2491,
63,
493,
63,
504,
63,
1782,
275,
4420,
8,
1107,
63,
585,
29,
549,
9,
398,
2058,
275,
8562,
14,
1628,
63,
578,
342,
398,
702,
2058,
459,
2489,
418,
365,
715,
199,
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,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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
osvalr/odoo
|
addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit.py
|
337
|
3122
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import datetime
from openerp.osv import fields, osv
from openerp.tools.translate import _
class account_analytic_profit(osv.osv_memory):
_name = 'hr.timesheet.analytic.profit'
_description = 'Print Timesheet Profit'
_columns = {
'date_from': fields.date('From', required=True),
'date_to': fields.date('To', required=True),
'journal_ids': fields.many2many('account.analytic.journal', 'analytic_profit_journal_rel', 'analytic_id', 'journal_id', 'Journal', required=True),
'employee_ids': fields.many2many('res.users', 'analytic_profit_emp_rel', 'analytic_id', 'emp_id', 'User', required=True),
}
def _date_from(*a):
return datetime.date.today().replace(day=1).strftime('%Y-%m-%d')
def _date_to(*a):
return datetime.date.today().strftime('%Y-%m-%d')
_defaults = {
'date_from': _date_from,
'date_to': _date_to
}
def print_report(self, cr, uid, ids, context=None):
line_obj = self.pool.get('account.analytic.line')
data = {}
data['form'] = self.read(cr, uid , ids, context=context)[0]
ids_chk = line_obj.search(cr, uid, [
('date', '>=', data['form']['date_from']),
('date', '<=', data['form']['date_to']),
('journal_id', 'in', data['form']['journal_ids']),
('user_id', 'in', data['form']['employee_ids']),
], context=context)
if not ids_chk:
raise osv.except_osv(_('Insufficient Data!'), _('No record(s) found for this report.'))
data['form']['journal_ids'] = [(6, 0, data['form']['journal_ids'])] # Improve me => Change the rml/sxw so that it can support withou [0][2]
data['form']['employee_ids'] = [(6, 0, data['form']['employee_ids'])]
datas = {
'ids': [],
'model': 'account.analytic.line',
'form': data['form']
}
return self.pool['report'].get_action(
cr, uid, [], 'hr_timesheet_invoice.report_analyticprofit', data=datas, context=context
)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
2197,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
533,
2933,
63,
9782,
63,
496,
3269,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
6271,
14,
17739,
14,
9782,
14,
496,
3269,
7,
272,
485,
1802,
275,
283,
5375,
4703,
5069,
2165,
3269,
7,
272,
485,
3406,
275,
469,
267,
283,
602,
63,
504,
356,
1504,
14,
602,
360,
2532,
297,
1415,
29,
549,
395,
267,
283,
602,
63,
475,
356,
1504,
14,
602,
360,
1378,
297,
1415,
29,
549,
395,
267,
283,
7067,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
360,
2048,
14,
9782,
14,
7067,
297,
283,
9782,
63,
496,
3269,
63,
7067,
63,
3369,
297,
283,
9782,
63,
344,
297,
283,
7067,
63,
344,
297,
283,
25909,
297,
1415,
29,
549,
395,
267,
283,
10103,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
360,
470,
14,
3707,
297,
283,
9782,
63,
496,
3269,
63,
2109,
63,
3369,
297,
283,
9782,
63,
344,
297,
283,
2109,
63,
344,
297,
283,
1899,
297,
1415,
29,
549,
395,
272,
789,
339,
347,
485,
602,
63,
504,
2031,
65,
304,
267,
372,
2197,
14,
602,
14,
8136,
1252,
1814,
8,
2977,
29,
17,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
339,
347,
485,
602,
63,
475,
2031,
65,
304,
267,
372,
2197,
14,
602,
14,
8136,
1252,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
339,
485,
4322,
275,
469,
267,
283,
602,
63,
504,
356,
485,
602,
63,
504,
12,
267,
283,
602,
63,
475,
356,
485,
602,
63,
475,
272,
789,
339,
347,
870,
63,
3070,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
1004,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
9782,
14,
604,
358,
267,
666,
275,
1052,
267,
666,
459,
964,
418,
275,
291,
14,
739,
8,
1556,
12,
1747,
2360,
2762,
12,
1067,
29,
1100,
2788,
16,
61,
267,
2762,
63,
14823,
275,
1004,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
359,
355,
661,
602,
297,
12696,
4009,
666,
459,
964,
2545,
602,
63,
504,
3815,
355,
661,
602,
297,
2650,
4009,
666,
459,
964,
2545,
602,
63,
475,
3815,
355,
661,
7067,
63,
344,
297,
283,
262,
297,
666,
459,
964,
2545,
7067,
63,
1580,
3815,
355,
661,
751,
63,
344,
297,
283,
262,
297,
666,
459,
964,
2545,
10103,
63,
1580,
3815,
355,
2156,
1067,
29,
1100,
9,
267,
340,
440,
2762,
63,
14823,
26,
288,
746,
9506,
14,
2590,
63,
4795,
6723,
13962,
12983,
3918,
15659,
4018,
1944,
2777,
8,
83,
9,
1911,
367,
642,
3622,
12459,
398,
666,
459,
964,
2545,
7067,
63,
1580,
418,
275,
3842,
22,
12,
378,
12,
666,
459,
964,
2545,
7067,
63,
1580,
24437,
327,
8362,
11750,
562,
9265,
7743,
314,
519,
757,
15,
20851,
880,
626,
652,
883,
2291,
543,
810,
359,
16,
1527,
18,
61,
267,
666,
459,
964,
2545,
10103,
63,
1580,
418,
275,
3842,
22,
12,
378,
12,
666,
459,
964,
2545,
10103,
63,
1580,
24437,
267,
15012,
275,
469,
288,
283,
1580,
356,
990,
288,
283,
1238,
356,
283,
2048,
14,
9782,
14,
604,
297,
288,
283,
964,
356,
666,
459,
964,
418,
267,
789,
267,
372,
291,
14,
2293,
459,
3070,
2278,
362,
63,
1287,
8,
288,
2467,
12,
1747,
12,
990,
283,
6271,
63,
17739,
63,
5404,
14,
3070,
63,
9782,
496,
3269,
297,
666,
29,
11563,
12,
1067,
29,
1100,
267,
776,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
2197,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
533,
2933,
63,
9782,
63,
496,
3269,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
6271,
14,
17739,
14,
9782,
14,
496,
3269,
7,
272,
485,
1802,
275,
283,
5375,
4703,
5069,
2165,
3269,
7,
272,
485,
3406,
275,
469,
267,
283,
602,
63,
504,
356,
1504,
14,
602,
360,
2532,
297,
1415,
29,
549,
395,
267,
283,
602,
63,
475,
356,
1504,
14,
602,
360,
1378,
297,
1415,
29,
549,
395,
267,
283,
7067,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
360,
2048,
14,
9782,
14,
7067,
297,
283,
9782,
63,
496,
3269,
63,
7067,
63,
3369,
297,
283,
9782,
63,
344,
297,
283,
7067,
63,
344,
297,
283,
25909,
297,
1415,
29,
549,
395,
267,
283,
10103,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
360,
470,
14,
3707,
297,
283,
9782,
63,
496,
3269,
63,
2109,
63,
3369,
297,
283,
9782,
63,
344,
297,
283,
2109,
63,
344,
297,
283,
1899,
297,
1415,
29,
549,
395,
272,
789,
339,
347,
485,
602,
63,
504,
2031,
65,
304,
267,
372,
2197,
14,
602,
14,
8136,
1252,
1814,
8,
2977,
29,
17,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
339,
347,
485,
602,
63,
475,
2031,
65,
304,
267,
372,
2197,
14,
602,
14,
8136,
1252,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
339,
485,
4322,
275,
469,
267,
283,
602,
63,
504,
356,
485,
602,
63,
504,
12,
267,
283,
602,
63,
475,
356,
485,
602,
63,
475,
272,
789,
339,
347,
870,
63,
3070,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
1004,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
9782,
14,
604,
358,
267,
666,
275,
1052,
267,
666,
459,
964,
418,
275,
291,
14,
739,
8,
1556,
12,
1747,
2360,
2762,
12,
1067,
29,
1100,
2788,
16,
61,
267,
2762,
63,
14823,
275,
1004,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
359,
355,
661,
602,
297,
12696,
4009,
666,
459,
964,
2545,
602,
63,
504,
3815,
355,
661,
602,
297,
2650,
4009,
666,
459,
964,
2545,
602,
63,
475,
3815,
355,
661,
7067,
63,
344,
297,
283,
262,
297,
666,
459,
964,
2545,
7067,
63,
1580,
3815,
355,
661,
751,
63,
344,
297,
283,
262,
297,
666,
459,
964,
2545,
10103,
63,
1580,
3815,
355,
2156,
1067,
29,
1100,
9,
267,
340,
440,
2762,
63,
14823,
26,
288,
746,
9506,
14,
2590,
63,
4795,
6723,
13962,
12983,
3918,
15659,
4018,
1944,
2777,
8,
83,
9,
1911,
367,
642,
3622,
12459,
398,
666,
459,
964,
2545,
7067,
63,
1580,
418,
275,
3842,
22,
12,
378,
12,
666,
459,
964,
2545,
7067,
63,
1580,
24437,
327,
8362,
11750,
562,
9265,
7743,
314,
519,
757,
15,
20851,
880,
626,
652,
883,
2291,
543,
810,
359,
16,
1527,
18,
61,
267,
666,
459,
964,
2545,
10103,
63,
1580,
418,
275,
3842,
22,
12,
378,
12,
666,
459,
964,
2545,
10103,
63,
1580,
24437,
267,
15012,
275,
469,
288,
283,
1580,
356,
990,
288,
283,
1238,
356,
283,
2048,
14,
9782,
14,
604,
297,
288,
283,
964,
356,
666,
459,
964,
418,
267,
789,
267,
372,
291,
14,
2293,
459,
3070,
2278,
362,
63,
1287,
8,
288,
2467,
12,
1747,
12,
990,
283,
6271,
63,
17739,
63,
5404,
14,
3070,
63,
9782,
496,
3269,
297,
666,
29,
11563,
12,
1067,
29,
1100,
267,
776,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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|
1
|
5594
|
import numpy as np
import pytest
from pandas import DataFrame, NaT, compat, date_range
import pandas.util.testing as tm
@pytest.fixture
def float_frame():
"""
Fixture for DataFrame of floats with index of unique strings
Columns are ['A', 'B', 'C', 'D'].
"""
return DataFrame(tm.getSeriesData())
@pytest.fixture
def float_frame_with_na():
"""
Fixture for DataFrame of floats with index of unique strings
Columns are ['A', 'B', 'C', 'D']; some entries are missing
"""
df = DataFrame(tm.getSeriesData())
# set some NAs
df.loc[5:10] = np.nan
df.loc[15:20, -2:] = np.nan
return df
@pytest.fixture
def float_frame2():
"""
Fixture for DataFrame of floats with index of unique strings
Columns are ['D', 'C', 'B', 'A']
"""
return DataFrame(tm.getSeriesData(), columns=['D', 'C', 'B', 'A'])
@pytest.fixture
def bool_frame_with_na():
"""
Fixture for DataFrame of booleans with index of unique strings
Columns are ['A', 'B', 'C', 'D']; some entries are missing
"""
df = DataFrame(tm.getSeriesData()) > 0
df = df.astype(object)
# set some NAs
df.loc[5:10] = np.nan
df.loc[15:20, -2:] = np.nan
return df
@pytest.fixture
def int_frame():
"""
Fixture for DataFrame of ints with index of unique strings
Columns are ['A', 'B', 'C', 'D']
"""
df = DataFrame({k: v.astype(int)
for k, v in compat.iteritems(tm.getSeriesData())})
# force these all to int64 to avoid platform testing issues
return DataFrame({c: s for c, s in compat.iteritems(df)}, dtype=np.int64)
@pytest.fixture
def datetime_frame():
"""
Fixture for DataFrame of floats with DatetimeIndex
Columns are ['A', 'B', 'C', 'D']
"""
return DataFrame(tm.getTimeSeriesData())
@pytest.fixture
def float_string_frame():
"""
Fixture for DataFrame of floats and strings with index of unique strings
Columns are ['A', 'B', 'C', 'D', 'foo'].
"""
df = DataFrame(tm.getSeriesData())
df['foo'] = 'bar'
return df
@pytest.fixture
def mixed_float_frame():
"""
Fixture for DataFrame of different float types with index of unique strings
Columns are ['A', 'B', 'C', 'D'].
"""
df = DataFrame(tm.getSeriesData())
df.A = df.A.astype('float32')
df.B = df.B.astype('float32')
df.C = df.C.astype('float16')
df.D = df.D.astype('float64')
return df
@pytest.fixture
def mixed_float_frame2():
"""
Fixture for DataFrame of different float types with index of unique strings
Columns are ['A', 'B', 'C', 'D'].
"""
df = DataFrame(tm.getSeriesData())
df.D = df.D.astype('float32')
df.C = df.C.astype('float32')
df.B = df.B.astype('float16')
df.D = df.D.astype('float64')
return df
@pytest.fixture
def mixed_int_frame():
"""
Fixture for DataFrame of different int types with index of unique strings
Columns are ['A', 'B', 'C', 'D'].
"""
df = DataFrame({k: v.astype(int)
for k, v in compat.iteritems(tm.getSeriesData())})
df.A = df.A.astype('int32')
df.B = np.ones(len(df.B), dtype='uint64')
df.C = df.C.astype('uint8')
df.D = df.C.astype('int64')
return df
@pytest.fixture
def mixed_type_frame():
"""
Fixture for DataFrame of float/int/string columns with RangeIndex
Columns are ['a', 'b', 'c', 'float32', 'int32'].
"""
return DataFrame({'a': 1., 'b': 2, 'c': 'foo',
'float32': np.array([1.] * 10, dtype='float32'),
'int32': np.array([1] * 10, dtype='int32')},
index=np.arange(10))
@pytest.fixture
def timezone_frame():
"""
Fixture for DataFrame of date_range Series with different time zones
Columns are ['A', 'B', 'C']; some entries are missing
"""
df = DataFrame({'A': date_range('20130101', periods=3),
'B': date_range('20130101', periods=3,
tz='US/Eastern'),
'C': date_range('20130101', periods=3,
tz='CET')})
df.iloc[1, 1] = NaT
df.iloc[1, 2] = NaT
return df
@pytest.fixture
def empty_frame():
"""
Fixture for empty DataFrame
"""
return DataFrame({})
@pytest.fixture
def datetime_series():
"""
Fixture for Series of floats with DatetimeIndex
"""
return tm.makeTimeSeries(nper=30)
@pytest.fixture
def datetime_series_short():
"""
Fixture for Series of floats with DatetimeIndex
"""
return tm.makeTimeSeries(nper=30)[5:]
@pytest.fixture
def simple_frame():
"""
Fixture for simple 3x3 DataFrame
Columns are ['one', 'two', 'three'], index is ['a', 'b', 'c'].
"""
arr = np.array([[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]])
return DataFrame(arr, columns=['one', 'two', 'three'],
index=['a', 'b', 'c'])
@pytest.fixture
def frame_of_index_cols():
"""
Fixture for DataFrame of columns that can be used for indexing
Columns are ['A', 'B', 'C', 'D', 'E', ('tuple', 'as', 'label')];
'A' & 'B' contain duplicates (but are jointly unique), the rest are unique.
"""
df = DataFrame({'A': ['foo', 'foo', 'foo', 'bar', 'bar'],
'B': ['one', 'two', 'three', 'one', 'two'],
'C': ['a', 'b', 'c', 'd', 'e'],
'D': np.random.randn(5),
'E': np.random.randn(5),
('tuple', 'as', 'label'): np.random.randn(5)})
return df
|
bsd-3-clause
|
[
646,
2680,
465,
980,
199,
646,
4613,
199,
199,
504,
10634,
492,
10071,
12,
11290,
52,
12,
8434,
12,
1434,
63,
1842,
199,
646,
10634,
14,
1974,
14,
4776,
465,
7352,
421,
199,
32,
4462,
14,
5997,
199,
318,
2069,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
2278,
272,
408,
272,
372,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
421,
199,
32,
4462,
14,
5997,
199,
318,
2069,
63,
1943,
63,
1045,
63,
3540,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
27,
2005,
4811,
787,
4124,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
272,
327,
663,
2005,
653,
2822,
272,
4051,
14,
2102,
59,
21,
26,
709,
61,
275,
980,
14,
4304,
272,
4051,
14,
2102,
59,
1046,
26,
1165,
12,
446,
18,
2938,
275,
980,
14,
4304,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
2069,
63,
1943,
18,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
36,
297,
283,
35,
297,
283,
34,
297,
283,
33,
418,
272,
408,
272,
372,
10071,
8,
7574,
14,
362,
9641,
1451,
1062,
4362,
2968,
36,
297,
283,
35,
297,
283,
34,
297,
283,
33,
1105,
421,
199,
32,
4462,
14,
5997,
199,
318,
2155,
63,
1943,
63,
1045,
63,
3540,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
1234,
16721,
796,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
27,
2005,
4811,
787,
4124,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
690,
378,
272,
4051,
275,
4051,
14,
6041,
8,
785,
9,
272,
327,
663,
2005,
653,
2822,
272,
4051,
14,
2102,
59,
21,
26,
709,
61,
275,
980,
14,
4304,
272,
4051,
14,
2102,
59,
1046,
26,
1165,
12,
446,
18,
2938,
275,
980,
14,
4304,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
1109,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
14526,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
272,
408,
272,
4051,
275,
10071,
2561,
75,
26,
373,
14,
6041,
8,
442,
9,
673,
367,
1022,
12,
373,
315,
8434,
14,
4611,
8,
7574,
14,
362,
9641,
1451,
1012,
1552,
272,
327,
3542,
3520,
1006,
370,
1109,
772,
370,
5126,
4298,
5343,
10876,
272,
372,
10071,
2561,
67,
26,
308,
367,
286,
12,
308,
315,
8434,
14,
4611,
8,
1587,
16658,
2152,
29,
1590,
14,
442,
772,
9,
421,
199,
32,
4462,
14,
5997,
199,
318,
2197,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
543,
29825,
2681,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
272,
408,
272,
372,
10071,
8,
7574,
14,
362,
30887,
1451,
1012,
421,
199,
32,
4462,
14,
5997,
199,
318,
2069,
63,
875,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
436,
3326,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
297,
283,
1421,
2278,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
272,
4051,
459,
1421,
418,
275,
283,
1700,
7,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
13492,
63,
1609,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
3365,
2069,
2943,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
2278,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
272,
4051,
14,
33,
275,
4051,
14,
33,
14,
6041,
360,
1609,
708,
358,
272,
4051,
14,
34,
275,
4051,
14,
34,
14,
6041,
360,
1609,
708,
358,
272,
4051,
14,
35,
275,
4051,
14,
35,
14,
6041,
360,
1609,
975,
358,
272,
4051,
14,
36,
275,
4051,
14,
36,
14,
6041,
360,
1609,
772,
358,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
13492,
63,
1609,
63,
1943,
18,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
3365,
2069,
2943,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
2278,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
272,
4051,
14,
36,
275,
4051,
14,
36,
14,
6041,
360,
1609,
708,
358,
272,
4051,
14,
35,
275,
4051,
14,
35,
14,
6041,
360,
1609,
708,
358,
272,
4051,
14,
34,
275,
4051,
14,
34,
14,
6041,
360,
1609,
975,
358,
272,
4051,
14,
36,
275,
4051,
14,
36,
14,
6041,
360,
1609,
772,
358,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
13492,
63,
442,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
3365,
1109,
2943,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
2278,
272,
408,
272,
4051,
275,
10071,
2561,
75,
26,
373,
14,
6041,
8,
442,
9,
673,
367,
1022,
12,
373,
315,
8434,
14,
4611,
8,
7574,
14,
362,
9641,
1451,
1012,
1552,
272,
4051,
14,
33,
275,
4051,
14,
33,
14,
6041,
360,
442,
708,
358,
272,
4051,
14,
34,
275,
980,
14,
4548,
8,
552,
8,
1587,
14,
34,
395,
2152,
534,
1635,
772,
358,
272,
4051,
14,
35,
275,
4051,
14,
35,
14,
6041,
360,
1635,
24,
358,
272,
4051,
14,
36,
275,
4051,
14,
35,
14,
6041,
360,
442,
772,
358,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
13492,
63,
466,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
2069,
15,
442,
15,
875,
4362,
543,
13114,
2681,
339,
3626,
2346,
787,
788
] |
[
2680,
465,
980,
199,
646,
4613,
199,
199,
504,
10634,
492,
10071,
12,
11290,
52,
12,
8434,
12,
1434,
63,
1842,
199,
646,
10634,
14,
1974,
14,
4776,
465,
7352,
421,
199,
32,
4462,
14,
5997,
199,
318,
2069,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
2278,
272,
408,
272,
372,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
421,
199,
32,
4462,
14,
5997,
199,
318,
2069,
63,
1943,
63,
1045,
63,
3540,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
27,
2005,
4811,
787,
4124,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
272,
327,
663,
2005,
653,
2822,
272,
4051,
14,
2102,
59,
21,
26,
709,
61,
275,
980,
14,
4304,
272,
4051,
14,
2102,
59,
1046,
26,
1165,
12,
446,
18,
2938,
275,
980,
14,
4304,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
2069,
63,
1943,
18,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
36,
297,
283,
35,
297,
283,
34,
297,
283,
33,
418,
272,
408,
272,
372,
10071,
8,
7574,
14,
362,
9641,
1451,
1062,
4362,
2968,
36,
297,
283,
35,
297,
283,
34,
297,
283,
33,
1105,
421,
199,
32,
4462,
14,
5997,
199,
318,
2155,
63,
1943,
63,
1045,
63,
3540,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
1234,
16721,
796,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
27,
2005,
4811,
787,
4124,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
690,
378,
272,
4051,
275,
4051,
14,
6041,
8,
785,
9,
272,
327,
663,
2005,
653,
2822,
272,
4051,
14,
2102,
59,
21,
26,
709,
61,
275,
980,
14,
4304,
272,
4051,
14,
2102,
59,
1046,
26,
1165,
12,
446,
18,
2938,
275,
980,
14,
4304,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
1109,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
14526,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
272,
408,
272,
4051,
275,
10071,
2561,
75,
26,
373,
14,
6041,
8,
442,
9,
673,
367,
1022,
12,
373,
315,
8434,
14,
4611,
8,
7574,
14,
362,
9641,
1451,
1012,
1552,
272,
327,
3542,
3520,
1006,
370,
1109,
772,
370,
5126,
4298,
5343,
10876,
272,
372,
10071,
2561,
67,
26,
308,
367,
286,
12,
308,
315,
8434,
14,
4611,
8,
1587,
16658,
2152,
29,
1590,
14,
442,
772,
9,
421,
199,
32,
4462,
14,
5997,
199,
318,
2197,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
543,
29825,
2681,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
418,
272,
408,
272,
372,
10071,
8,
7574,
14,
362,
30887,
1451,
1012,
421,
199,
32,
4462,
14,
5997,
199,
318,
2069,
63,
875,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
15657,
436,
3326,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
297,
283,
1421,
2278,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
272,
4051,
459,
1421,
418,
275,
283,
1700,
7,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
13492,
63,
1609,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
3365,
2069,
2943,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
2278,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
272,
4051,
14,
33,
275,
4051,
14,
33,
14,
6041,
360,
1609,
708,
358,
272,
4051,
14,
34,
275,
4051,
14,
34,
14,
6041,
360,
1609,
708,
358,
272,
4051,
14,
35,
275,
4051,
14,
35,
14,
6041,
360,
1609,
975,
358,
272,
4051,
14,
36,
275,
4051,
14,
36,
14,
6041,
360,
1609,
772,
358,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
13492,
63,
1609,
63,
1943,
18,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
3365,
2069,
2943,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
2278,
272,
408,
272,
4051,
275,
10071,
8,
7574,
14,
362,
9641,
1451,
1012,
272,
4051,
14,
36,
275,
4051,
14,
36,
14,
6041,
360,
1609,
708,
358,
272,
4051,
14,
35,
275,
4051,
14,
35,
14,
6041,
360,
1609,
708,
358,
272,
4051,
14,
34,
275,
4051,
14,
34,
14,
6041,
360,
1609,
975,
358,
272,
4051,
14,
36,
275,
4051,
14,
36,
14,
6041,
360,
1609,
772,
358,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
13492,
63,
442,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
3365,
1109,
2943,
543,
1478,
402,
3747,
3326,
339,
3626,
2346,
787,
788,
33,
297,
283,
34,
297,
283,
35,
297,
283,
36,
2278,
272,
408,
272,
4051,
275,
10071,
2561,
75,
26,
373,
14,
6041,
8,
442,
9,
673,
367,
1022,
12,
373,
315,
8434,
14,
4611,
8,
7574,
14,
362,
9641,
1451,
1012,
1552,
272,
4051,
14,
33,
275,
4051,
14,
33,
14,
6041,
360,
442,
708,
358,
272,
4051,
14,
34,
275,
980,
14,
4548,
8,
552,
8,
1587,
14,
34,
395,
2152,
534,
1635,
772,
358,
272,
4051,
14,
35,
275,
4051,
14,
35,
14,
6041,
360,
1635,
24,
358,
272,
4051,
14,
36,
275,
4051,
14,
35,
14,
6041,
360,
442,
772,
358,
272,
372,
4051,
421,
199,
32,
4462,
14,
5997,
199,
318,
13492,
63,
466,
63,
1943,
837,
272,
408,
272,
31574,
4167,
367,
10071,
402,
2069,
15,
442,
15,
875,
4362,
543,
13114,
2681,
339,
3626,
2346,
787,
788,
0
] |
[
1,
1,
1,
1,
1,
1,
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apclient
|
tests/test_resources/updater_test/fieldworkpcregfemur2landmarksstep-master/mapclientplugins/fieldworkpcregfemur2landmarksstep/resources_rc.py
|
3
|
7857
|
# -*- coding: utf-8 -*-
# Resource object code
#
# Created: Tue Jul 8 07:21:06 2014
# by: The Resource Compiler for PySide (Qt v4.8.4)
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore
qt_resource_data = "\x00\x00\x08\xe2\x89PNG\x0d\x0a\x1a\x0a\x00\x00\x00\x0dIHDR\x00\x00\x00@\x00\x00\x00@\x08\x06\x00\x00\x00\xaaiq\xde\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00\x09pHYs\x00\x00\x0d\xd7\x00\x00\x0d\xd7\x01B(\x9bx\x00\x00\x00\x19tEXtSoftware\x00www.inkscape.org\x9b\xee<\x1a\x00\x00\x08_IDATx\x9c\xed\x9ao\x8c\x5cU\x19\xc6\x7f\xef\x9d\xd9\xdd61\xb2M\xa4\xac\xa0f\x88\x8diP\xe9(a\xa5,\xd0\xb9BK\x22Fv\x82\xe1\x83\x91t\xd7h\xa2\xf8\xc1%&~\xe0\x83\xcb&&&jh\x1b\xbf\x18H\xd8b\x22\x1a\xa9\xcen\xc0HXp\xae\x14(\xb4\x9a\xde\x92Rj\x02t\x08\x82\x84\x1a3(\xd2\xed\xee\xbd\xe7\xf1\xc3=S\x86\xed\xee\x16\xd8;\x1d\x90}\x92I\xce\x9f\xf7\x9c\xfb\x9c\xe7\xbc\xef9\xe7\x9e\xb9&\x89\x0f2\x8a\x00f6\x0d\x9c\xb7\xa0nT\xd23g\x9f\xd2\xe90\xb3\x8f\x03\x9f\x92\xf4\xb0\xcf\xff\x0c\xb8\xc2W\xff\x07x\x08\xf8\x9d\xa4g}\xfd\x000\xeem\xfa\x81C\xc0\xad\x92\x9e2\xb320/\xe9i\x80\xc0w\xf2y\xe0\x0b\xc0\xdf\x80\xa3\xfew\xa2\x8d@\x8f\x99\xad]\x86\xe0\x9a\xb6t`f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0m\xac\x0a\xd0m\x02\xdd\xc6\xaa\x00\xdd&\xd0m\xac\x0a\xd0m\x02\xdd\xc6\xaa\x00\xdd&\xd0m\xac\x0a\xd0m\x02\xdd\xc6\xaa\x00\xdd&\xd0m|\xe0\x05\xf8\x1f7\x0e-l\xaam\xd7\xbb\x00\x00\x00\x00IEND\xaeB`\x82"
qt_resource_name = "\x00!\x0eWs\xc0\x00f\x00i\x00e\x00l\x00d\x00w\x00o\x00r\x00k\x00p\x00c\x00r\x00e\x00g\x00f\x00e\x00m\x00u\x00r\x002\x00l\x00a\x00n\x00d\x00m\x00a\x00r\x00k\x00s\x00s\x00t\x00e\x00p\x00\x06\x07\x03}\xc3\x00i\x00m\x00a\x00g\x00e\x00s\x00\x1b\x05\x88\xe5\xa7\x00f\x00i\x00e\x00l\x00d\x00w\x00o\x00r\x00k\x00f\x00e\x00m\x00u\x00r\x00p\x00c\x00r\x00e\x00g\x00i\x00c\x00o\x00n\x00.\x00p\x00n\x00g"
qt_resource_struct = "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00H\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00Z\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00"
def qInitResources():
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
def qCleanupResources():
QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
qInitResources()
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
7337,
909,
1233,
199,
3,
199,
3,
18208,
26,
377,
310,
1603,
348,
1695,
24937,
26,
2025,
26,
1690,
6927,
199,
3,
420,
701,
26,
710,
7337,
27154,
367,
1611,
15414,
334,
4238,
373,
20,
14,
24,
14,
20,
9,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
1611,
15414,
492,
10565,
199,
199,
8440,
63,
1927,
63,
576,
275,
1867,
88,
383,
60,
88,
383,
60,
88,
2036,
60,
1845,
18,
60,
88,
1407,
24454,
60,
88,
16,
68,
60,
88,
16,
65,
60,
88,
17,
65,
60,
88,
16,
65,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
16,
68,
19824,
4564,
60,
88,
383,
60,
88,
383,
60,
88,
383,
32,
60,
88,
383,
60,
88,
383,
60,
88,
383,
32,
60,
88,
2036,
60,
88,
1690,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
1800,
5789,
81,
60,
10745,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
966,
83,
11970,
60,
88,
2036,
60,
88,
2036,
60,
88,
2036,
60,
88,
2036,
6113,
88,
2036,
68,
60,
88,
1299,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1643,
80,
16255,
83,
60,
88,
383,
60,
88,
383,
60,
88,
16,
68,
60,
2207,
23,
60,
88,
383,
60,
88,
383,
60,
88,
16,
68,
60,
2207,
23,
60,
88,
614,
34,
2961,
88,
25,
13691,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1167,
84,
1438,
84,
10337,
60,
88,
383,
1544,
14,
2292,
3588,
14,
1308,
60,
88,
25,
66,
60,
11127,
31873,
88,
17,
65,
60,
88,
383,
60,
88,
383,
60,
88,
2036,
63,
998,
619,
88,
60,
88,
25,
67,
60,
7887,
60,
88,
25,
8035,
60,
88,
24,
67,
60,
88,
21,
67,
53,
60,
88,
1167,
60,
1812,
22,
60,
88,
23,
70,
60,
9532,
60,
88,
25,
68,
60,
2207,
25,
60,
11110,
2976,
60,
1774,
18,
45,
60,
1800,
20,
60,
10104,
60,
1800,
16,
70,
60,
88,
1299,
60,
88,
24,
328,
48,
60,
1845,
25,
8,
65,
60,
1800,
21,
4202,
2207,
16,
60,
1774,
25,
17672,
60,
88,
1081,
38,
86,
60,
88,
2564,
60,
1845,
17,
60,
88,
2658,
60,
88,
3328,
84,
60,
2207,
23,
72,
60,
1800,
18,
60,
1949,
24,
60,
1812,
17,
5,
6,
94,
60,
1845,
16,
60,
88,
2658,
60,
10351,
12574,
6,
31623,
60,
88,
17,
66,
60,
9566,
60,
88,
1085,
40,
60,
2207,
24,
66,
60,
88,
1081,
60,
88,
17,
65,
60,
1800,
25,
60,
1812,
287,
60,
1812,
16,
40,
56,
80,
60,
10183,
60,
88,
1079,
2961,
1774,
20,
60,
88,
25,
65,
60,
10745,
60,
88,
2942,
50,
74,
60,
88,
996,
84,
60,
88,
2036,
60,
88,
2564,
60,
88,
1349,
60,
88,
17,
65,
19,
2961,
2207,
18,
60,
7887,
60,
11127,
60,
9826,
60,
1845,
23,
60,
1949,
17,
60,
1812,
19,
29,
51,
60,
88,
1184,
60,
7887,
60,
11127,
60,
88,
975,
60,
2207,
24,
3779,
88,
17,
68,
60,
88,
2710,
4988,
88,
2942,
41,
60,
10489,
60,
88,
25,
70,
60,
1949,
23,
60,
88,
25,
67,
60,
10272,
60,
88,
25,
67,
60,
1845,
23,
60,
10323,
60,
9532,
25,
60,
1845,
23,
60,
88,
25,
69,
60,
1774,
25,
28103,
88,
1407,
60,
88,
16,
70,
18,
60,
88,
24,
65,
60,
88,
383,
70,
22,
60,
88,
16,
68,
60,
88,
25,
67,
60,
1774,
23,
60,
1800,
16,
78,
52,
60,
2207,
1789,
71,
60,
88,
25,
70,
60,
2207,
18,
60,
1845,
2710,
60,
1774,
19,
60,
88,
24,
70,
60,
88,
1644,
60,
88,
25,
70,
60,
88,
2942,
60,
1949,
20,
60,
1774,
16,
60,
10493,
60,
3581,
60,
88,
16,
67,
60,
1774,
24,
60,
1812,
18,
55,
60,
3581,
60,
88,
1780,
88,
60,
88,
2036,
60,
1949,
24,
60,
88,
25,
68,
60,
1800,
20,
71,
4988,
11208,
60,
88,
1493,
60,
11127,
77,
60,
10500,
60,
88,
2835,
35,
60,
1812,
16,
60,
10135,
60,
88,
2942,
60,
88,
25,
69,
18,
60,
1774,
12122,
6307,
1845,
25,
73,
60,
88,
1257,
60,
1812,
16,
87,
60,
1949,
18,
89,
60,
1845,
16,
60,
88,
16,
66,
60,
1812,
16,
60,
10418,
60,
88,
1257,
60,
1800,
19,
60,
1949,
546,
60,
1800,
18,
60,
88,
24,
68,
32,
60,
88,
24,
70,
60,
88,
1020,
60,
10135,
7272,
88,
1184,
60,
1845,
16,
60,
88,
25,
65,
60,
1774,
22,
84,
64,
70,
60,
1812,
21,
87,
25,
60,
2207,
16,
83,
60,
88,
975,
2862,
10145,
60,
88,
1717,
26119,
60,
88,
16,
68,
60,
88,
7778,
60,
1800,
19,
60,
1845,
23,
60,
10272,
31873,
1949,
16,
6307,
1845,
16,
39,
60,
1812,
16,
60,
11208,
60,
10745,
60,
8371,
17577,
60,
88,
16,
67,
6113,
88,
25,
66,
44,
60,
88,
25,
67,
3779,
88,
2835,
16540,
60,
88,
24,
70,
60,
1800,
20,
60,
88,
1085,
60,
1774,
24,
60,
10768,
60,
10719,
60,
88,
2835,
60,
88,
16,
70,
60,
88,
2835,
60,
88,
1196,
60,
88,
614,
60,
88,
614,
37,
41,
60,
1774,
20,
94,
60,
1812,
16,
60,
1774,
25,
60,
9957,
60,
1845,
19,
89,
971,
88,
1717,
70,
60,
88,
1257,
60,
1949,
19,
6113,
11110,
60,
88,
1644,
60,
1812,
16,
4202,
1774,
16,
60,
10719,
60,
2207,
23,
60,
88,
17,
68,
60,
88,
966,
60,
9957,
60,
1845,
22,
60,
88,
1643,
60,
9826,
60,
88,
16,
65,
6113,
1812,
19,
60,
10719,
60,
11110,
60,
1845,
20,
60,
7887,
60,
9957,
60,
11127,
60,
1949,
19,
87,
60,
10500,
60,
10347,
1154,
88,
1257,
60,
10493,
60,
10500,
60,
1949,
20,
60,
9826,
60,
1812,
16,
60,
2207,
19,
32,
60,
1800,
19,
60,
11208,
60,
1949,
25,
60,
10745,
94,
3779,
1774,
16,
69,
33,
60,
2207,
25,
60,
11208,
60,
88,
25,
69,
60,
9532,
5,
3072,
3581,
60,
88,
2710,
60,
10493,
60
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
7337,
909,
1233,
199,
3,
199,
3,
18208,
26,
377,
310,
1603,
348,
1695,
24937,
26,
2025,
26,
1690,
6927,
199,
3,
420,
701,
26,
710,
7337,
27154,
367,
1611,
15414,
334,
4238,
373,
20,
14,
24,
14,
20,
9,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
1611,
15414,
492,
10565,
199,
199,
8440,
63,
1927,
63,
576,
275,
1867,
88,
383,
60,
88,
383,
60,
88,
2036,
60,
1845,
18,
60,
88,
1407,
24454,
60,
88,
16,
68,
60,
88,
16,
65,
60,
88,
17,
65,
60,
88,
16,
65,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
16,
68,
19824,
4564,
60,
88,
383,
60,
88,
383,
60,
88,
383,
32,
60,
88,
383,
60,
88,
383,
60,
88,
383,
32,
60,
88,
2036,
60,
88,
1690,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
1800,
5789,
81,
60,
10745,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
966,
83,
11970,
60,
88,
2036,
60,
88,
2036,
60,
88,
2036,
60,
88,
2036,
6113,
88,
2036,
68,
60,
88,
1299,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1643,
80,
16255,
83,
60,
88,
383,
60,
88,
383,
60,
88,
16,
68,
60,
2207,
23,
60,
88,
383,
60,
88,
383,
60,
88,
16,
68,
60,
2207,
23,
60,
88,
614,
34,
2961,
88,
25,
13691,
60,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1167,
84,
1438,
84,
10337,
60,
88,
383,
1544,
14,
2292,
3588,
14,
1308,
60,
88,
25,
66,
60,
11127,
31873,
88,
17,
65,
60,
88,
383,
60,
88,
383,
60,
88,
2036,
63,
998,
619,
88,
60,
88,
25,
67,
60,
7887,
60,
88,
25,
8035,
60,
88,
24,
67,
60,
88,
21,
67,
53,
60,
88,
1167,
60,
1812,
22,
60,
88,
23,
70,
60,
9532,
60,
88,
25,
68,
60,
2207,
25,
60,
11110,
2976,
60,
1774,
18,
45,
60,
1800,
20,
60,
10104,
60,
1800,
16,
70,
60,
88,
1299,
60,
88,
24,
328,
48,
60,
1845,
25,
8,
65,
60,
1800,
21,
4202,
2207,
16,
60,
1774,
25,
17672,
60,
88,
1081,
38,
86,
60,
88,
2564,
60,
1845,
17,
60,
88,
2658,
60,
88,
3328,
84,
60,
2207,
23,
72,
60,
1800,
18,
60,
1949,
24,
60,
1812,
17,
5,
6,
94,
60,
1845,
16,
60,
88,
2658,
60,
10351,
12574,
6,
31623,
60,
88,
17,
66,
60,
9566,
60,
88,
1085,
40,
60,
2207,
24,
66,
60,
88,
1081,
60,
88,
17,
65,
60,
1800,
25,
60,
1812,
287,
60,
1812,
16,
40,
56,
80,
60,
10183,
60,
88,
1079,
2961,
1774,
20,
60,
88,
25,
65,
60,
10745,
60,
88,
2942,
50,
74,
60,
88,
996,
84,
60,
88,
2036,
60,
88,
2564,
60,
88,
1349,
60,
88,
17,
65,
19,
2961,
2207,
18,
60,
7887,
60,
11127,
60,
9826,
60,
1845,
23,
60,
1949,
17,
60,
1812,
19,
29,
51,
60,
88,
1184,
60,
7887,
60,
11127,
60,
88,
975,
60,
2207,
24,
3779,
88,
17,
68,
60,
88,
2710,
4988,
88,
2942,
41,
60,
10489,
60,
88,
25,
70,
60,
1949,
23,
60,
88,
25,
67,
60,
10272,
60,
88,
25,
67,
60,
1845,
23,
60,
10323,
60,
9532,
25,
60,
1845,
23,
60,
88,
25,
69,
60,
1774,
25,
28103,
88,
1407,
60,
88,
16,
70,
18,
60,
88,
24,
65,
60,
88,
383,
70,
22,
60,
88,
16,
68,
60,
88,
25,
67,
60,
1774,
23,
60,
1800,
16,
78,
52,
60,
2207,
1789,
71,
60,
88,
25,
70,
60,
2207,
18,
60,
1845,
2710,
60,
1774,
19,
60,
88,
24,
70,
60,
88,
1644,
60,
88,
25,
70,
60,
88,
2942,
60,
1949,
20,
60,
1774,
16,
60,
10493,
60,
3581,
60,
88,
16,
67,
60,
1774,
24,
60,
1812,
18,
55,
60,
3581,
60,
88,
1780,
88,
60,
88,
2036,
60,
1949,
24,
60,
88,
25,
68,
60,
1800,
20,
71,
4988,
11208,
60,
88,
1493,
60,
11127,
77,
60,
10500,
60,
88,
2835,
35,
60,
1812,
16,
60,
10135,
60,
88,
2942,
60,
88,
25,
69,
18,
60,
1774,
12122,
6307,
1845,
25,
73,
60,
88,
1257,
60,
1812,
16,
87,
60,
1949,
18,
89,
60,
1845,
16,
60,
88,
16,
66,
60,
1812,
16,
60,
10418,
60,
88,
1257,
60,
1800,
19,
60,
1949,
546,
60,
1800,
18,
60,
88,
24,
68,
32,
60,
88,
24,
70,
60,
88,
1020,
60,
10135,
7272,
88,
1184,
60,
1845,
16,
60,
88,
25,
65,
60,
1774,
22,
84,
64,
70,
60,
1812,
21,
87,
25,
60,
2207,
16,
83,
60,
88,
975,
2862,
10145,
60,
88,
1717,
26119,
60,
88,
16,
68,
60,
88,
7778,
60,
1800,
19,
60,
1845,
23,
60,
10272,
31873,
1949,
16,
6307,
1845,
16,
39,
60,
1812,
16,
60,
11208,
60,
10745,
60,
8371,
17577,
60,
88,
16,
67,
6113,
88,
25,
66,
44,
60,
88,
25,
67,
3779,
88,
2835,
16540,
60,
88,
24,
70,
60,
1800,
20,
60,
88,
1085,
60,
1774,
24,
60,
10768,
60,
10719,
60,
88,
2835,
60,
88,
16,
70,
60,
88,
2835,
60,
88,
1196,
60,
88,
614,
60,
88,
614,
37,
41,
60,
1774,
20,
94,
60,
1812,
16,
60,
1774,
25,
60,
9957,
60,
1845,
19,
89,
971,
88,
1717,
70,
60,
88,
1257,
60,
1949,
19,
6113,
11110,
60,
88,
1644,
60,
1812,
16,
4202,
1774,
16,
60,
10719,
60,
2207,
23,
60,
88,
17,
68,
60,
88,
966,
60,
9957,
60,
1845,
22,
60,
88,
1643,
60,
9826,
60,
88,
16,
65,
6113,
1812,
19,
60,
10719,
60,
11110,
60,
1845,
20,
60,
7887,
60,
9957,
60,
11127,
60,
1949,
19,
87,
60,
10500,
60,
10347,
1154,
88,
1257,
60,
10493,
60,
10500,
60,
1949,
20,
60,
9826,
60,
1812,
16,
60,
2207,
19,
32,
60,
1800,
19,
60,
11208,
60,
1949,
25,
60,
10745,
94,
3779,
1774,
16,
69,
33,
60,
2207,
25,
60,
11208,
60,
88,
25,
69,
60,
9532,
5,
3072,
3581,
60,
88,
2710,
60,
10493,
60,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
uwafsl/MissionPlanner
|
Lib/site-packages/numpy/lib/tests/test_financial.py
|
83
|
1912
|
from numpy.testing import *
import numpy as np
class TestFinancial(TestCase):
def test_rate(self):
assert_almost_equal(np.rate(10,0,-3500,10000),
0.1107, 4)
def test_irr(self):
v = [-150000, 15000, 25000, 35000, 45000, 60000]
assert_almost_equal(np.irr(v),
0.0524, 2)
def test_pv(self):
assert_almost_equal(np.pv(0.07,20,12000,0),
-127128.17, 2)
def test_fv(self):
assert_almost_equal(np.fv(0.075, 20, -2000,0,0),
86609.36, 2)
def test_pmt(self):
assert_almost_equal(np.pmt(0.08/12,5*12,15000),
-304.146, 3)
def test_nper(self):
assert_almost_equal(np.nper(0.075,-2000,0,100000.),
21.54, 2)
def test_nper2(self):
assert_almost_equal(np.nper(0.0,-2000,0,100000.),
50.0, 1)
def test_npv(self):
assert_almost_equal(np.npv(0.05,[-15000,1500,2500,3500,4500,6000]),
117.04, 2)
def test_mirr(self):
val = [-4500,-800,800,800,600,600,800,800,700,3000]
assert_almost_equal(np.mirr(val, 0.08, 0.055), 0.0666, 4)
val = [-120000,39000,30000,21000,37000,46000]
assert_almost_equal(np.mirr(val, 0.10, 0.12), 0.126094, 6)
val = [100,200,-50,300,-200]
assert_almost_equal(np.mirr(val, 0.05, 0.06), 0.3428, 4)
val = [39000,30000,21000,37000,46000]
assert_(np.isnan(np.mirr(val, 0.10, 0.12)))
def test_unimplemented():
# np.round(np.ppmt(0.1/12,1,60,55000),2) == 710.25
assert_raises(NotImplementedError, np.ppmt, 0.1/12, 1, 60, 55000)
# np.round(np.ipmt(0.1/12,1,24,2000),2) == 16.67
assert_raises(NotImplementedError, np.ipmt, 0.1/12, 1, 24, 2000)
if __name__ == "__main__":
run_module_suite()
|
gpl-3.0
|
[
504,
2680,
14,
4776,
492,
627,
199,
646,
2680,
465,
980,
199,
199,
533,
1379,
8694,
24409,
8,
1746,
304,
272,
347,
511,
63,
1866,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
1866,
8,
709,
12,
16,
3057,
1276,
383,
12,
9943,
395,
1169,
378,
14,
6019,
23,
12,
841,
9,
339,
347,
511,
63,
723,
82,
8,
277,
304,
267,
373,
275,
5243,
1046,
993,
12,
4114,
1493,
12,
5661,
1493,
12,
8685,
1493,
12,
10416,
1493,
12,
1227,
993,
61,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
723,
82,
8,
86,
395,
1169,
378,
14,
1717,
1194,
12,
499,
9,
339,
347,
511,
63,
1381,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
1381,
8,
16,
14,
1780,
12,
1165,
12,
713,
1493,
12,
16,
395,
1169,
446,
4195,
3933,
14,
1196,
12,
499,
9,
339,
347,
511,
63,
13692,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
13692,
8,
16,
14,
19339,
12,
3388,
12,
446,
8269,
12,
16,
12,
16,
395,
1169,
10300,
14520,
14,
1344,
12,
499,
9,
339,
347,
511,
63,
80,
2037,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
80,
2037,
8,
16,
14,
2036,
15,
713,
12,
21,
10,
713,
12,
1046,
1493,
395,
1169,
446,
8533,
14,
11432,
12,
650,
9,
339,
347,
511,
63,
78,
529,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
78,
529,
8,
16,
14,
19339,
3057,
8269,
12,
16,
12,
15274,
15631,
1169,
7829,
14,
1477,
12,
499,
9,
339,
347,
511,
63,
78,
529,
18,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
78,
529,
8,
16,
14,
16,
3057,
8269,
12,
16,
12,
15274,
15631,
1169,
5238,
14,
16,
12,
413,
9,
339,
347,
511,
63,
78,
1381,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
78,
1381,
8,
16,
14,
1717,
12,
1988,
1046,
1493,
12,
27607,
12,
21962,
12,
1276,
383,
12,
2322,
383,
12,
32623,
2522,
1169,
26189,
14,
966,
12,
499,
9,
339,
347,
511,
63,
77,
723,
82,
8,
277,
304,
267,
1139,
275,
5243,
2322,
383,
3057,
6718,
12,
6718,
12,
6718,
12,
6683,
12,
6683,
12,
6718,
12,
6718,
12,
15946,
12,
19962,
61,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
77,
723,
82,
8,
637,
12,
378,
14,
2036,
12,
378,
14,
16458,
395,
378,
14,
16,
11829,
12,
841,
9,
398,
1139,
275,
5243,
713,
993,
12,
1355,
1493,
12,
19,
993,
12,
2025,
1493,
12,
1401,
1493,
12,
2466,
1493,
61,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
77,
723,
82,
8,
637,
12,
378,
14,
709,
12,
378,
14,
713,
395,
378,
14,
7957,
16285,
12,
1227,
9,
398,
1139,
275,
359,
1960,
12,
1840,
3057,
1400,
12,
5863,
3057,
1840,
61,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
77,
723,
82,
8,
637,
12,
378,
14,
1717,
12,
378,
14,
1690,
395,
378,
14,
1082,
1651,
12,
841,
9,
398,
1139,
275,
359,
1355,
1493,
12,
19,
993,
12,
2025,
1493,
12,
1401,
1493,
12,
2466,
1493,
61,
267,
702,
2531,
1590,
14,
12936,
8,
1590,
14,
77,
723,
82,
8,
637,
12,
378,
14,
709,
12,
378,
14,
713,
1724,
4388,
199,
318,
511,
63,
324,
13825,
837,
272,
327,
980,
14,
2363,
8,
1590,
14,
802,
2037,
8,
16,
14,
17,
15,
713,
12,
17,
12,
2259,
12,
1229,
1493,
395,
18,
9,
508,
1520,
709,
14,
821,
272,
702,
63,
3536,
8,
18097,
12,
980,
14,
802,
2037,
12,
378,
14,
17,
15,
713,
12,
413,
12,
5212,
12,
12766,
1493,
9,
339,
327,
980,
14,
2363,
8,
1590,
14,
711,
2037,
8,
16,
14,
17,
15,
713,
12,
17,
12,
1194,
12,
8269,
395,
18,
9,
508,
3193,
14,
1822,
272,
702,
63,
3536,
8,
18097,
12,
980,
14,
711,
2037,
12,
378,
14,
17,
15,
713,
12,
413,
12,
5504,
12,
12293,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
578,
63,
5768,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2680,
14,
4776,
492,
627,
199,
646,
2680,
465,
980,
199,
199,
533,
1379,
8694,
24409,
8,
1746,
304,
272,
347,
511,
63,
1866,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
1866,
8,
709,
12,
16,
3057,
1276,
383,
12,
9943,
395,
1169,
378,
14,
6019,
23,
12,
841,
9,
339,
347,
511,
63,
723,
82,
8,
277,
304,
267,
373,
275,
5243,
1046,
993,
12,
4114,
1493,
12,
5661,
1493,
12,
8685,
1493,
12,
10416,
1493,
12,
1227,
993,
61,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
723,
82,
8,
86,
395,
1169,
378,
14,
1717,
1194,
12,
499,
9,
339,
347,
511,
63,
1381,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
1381,
8,
16,
14,
1780,
12,
1165,
12,
713,
1493,
12,
16,
395,
1169,
446,
4195,
3933,
14,
1196,
12,
499,
9,
339,
347,
511,
63,
13692,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
13692,
8,
16,
14,
19339,
12,
3388,
12,
446,
8269,
12,
16,
12,
16,
395,
1169,
10300,
14520,
14,
1344,
12,
499,
9,
339,
347,
511,
63,
80,
2037,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
80,
2037,
8,
16,
14,
2036,
15,
713,
12,
21,
10,
713,
12,
1046,
1493,
395,
1169,
446,
8533,
14,
11432,
12,
650,
9,
339,
347,
511,
63,
78,
529,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
78,
529,
8,
16,
14,
19339,
3057,
8269,
12,
16,
12,
15274,
15631,
1169,
7829,
14,
1477,
12,
499,
9,
339,
347,
511,
63,
78,
529,
18,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
78,
529,
8,
16,
14,
16,
3057,
8269,
12,
16,
12,
15274,
15631,
1169,
5238,
14,
16,
12,
413,
9,
339,
347,
511,
63,
78,
1381,
8,
277,
304,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
78,
1381,
8,
16,
14,
1717,
12,
1988,
1046,
1493,
12,
27607,
12,
21962,
12,
1276,
383,
12,
2322,
383,
12,
32623,
2522,
1169,
26189,
14,
966,
12,
499,
9,
339,
347,
511,
63,
77,
723,
82,
8,
277,
304,
267,
1139,
275,
5243,
2322,
383,
3057,
6718,
12,
6718,
12,
6718,
12,
6683,
12,
6683,
12,
6718,
12,
6718,
12,
15946,
12,
19962,
61,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
77,
723,
82,
8,
637,
12,
378,
14,
2036,
12,
378,
14,
16458,
395,
378,
14,
16,
11829,
12,
841,
9,
398,
1139,
275,
5243,
713,
993,
12,
1355,
1493,
12,
19,
993,
12,
2025,
1493,
12,
1401,
1493,
12,
2466,
1493,
61,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
77,
723,
82,
8,
637,
12,
378,
14,
709,
12,
378,
14,
713,
395,
378,
14,
7957,
16285,
12,
1227,
9,
398,
1139,
275,
359,
1960,
12,
1840,
3057,
1400,
12,
5863,
3057,
1840,
61,
267,
702,
63,
4398,
63,
1452,
8,
1590,
14,
77,
723,
82,
8,
637,
12,
378,
14,
1717,
12,
378,
14,
1690,
395,
378,
14,
1082,
1651,
12,
841,
9,
398,
1139,
275,
359,
1355,
1493,
12,
19,
993,
12,
2025,
1493,
12,
1401,
1493,
12,
2466,
1493,
61,
267,
702,
2531,
1590,
14,
12936,
8,
1590,
14,
77,
723,
82,
8,
637,
12,
378,
14,
709,
12,
378,
14,
713,
1724,
4388,
199,
318,
511,
63,
324,
13825,
837,
272,
327,
980,
14,
2363,
8,
1590,
14,
802,
2037,
8,
16,
14,
17,
15,
713,
12,
17,
12,
2259,
12,
1229,
1493,
395,
18,
9,
508,
1520,
709,
14,
821,
272,
702,
63,
3536,
8,
18097,
12,
980,
14,
802,
2037,
12,
378,
14,
17,
15,
713,
12,
413,
12,
5212,
12,
12766,
1493,
9,
339,
327,
980,
14,
2363,
8,
1590,
14,
711,
2037,
8,
16,
14,
17,
15,
713,
12,
17,
12,
1194,
12,
8269,
395,
18,
9,
508,
3193,
14,
1822,
272,
702,
63,
3536,
8,
18097,
12,
980,
14,
711,
2037,
12,
378,
14,
17,
15,
713,
12,
413,
12,
5504,
12,
12293,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
578,
63,
5768,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
r-mart/scikit-learn
|
sklearn/manifold/tests/test_t_sne.py
|
162
|
9771
|
import sys
from sklearn.externals.six.moves import cStringIO as StringIO
import numpy as np
import scipy.sparse as sp
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_almost_equal
from sklearn.utils.testing import assert_less
from sklearn.utils.testing import assert_raises_regexp
from sklearn.utils import check_random_state
from sklearn.manifold.t_sne import _joint_probabilities
from sklearn.manifold.t_sne import _kl_divergence
from sklearn.manifold.t_sne import _gradient_descent
from sklearn.manifold.t_sne import trustworthiness
from sklearn.manifold.t_sne import TSNE
from sklearn.manifold._utils import _binary_search_perplexity
from scipy.optimize import check_grad
from scipy.spatial.distance import pdist
from scipy.spatial.distance import squareform
def test_gradient_descent_stops():
# Test stopping conditions of gradient descent.
class ObjectiveSmallGradient:
def __init__(self):
self.it = -1
def __call__(self, _):
self.it += 1
return (10 - self.it) / 10.0, np.array([1e-5])
def flat_function(_):
return 0.0, np.ones(1)
# Gradient norm
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
_, error, it = _gradient_descent(
ObjectiveSmallGradient(), np.zeros(1), 0, n_iter=100,
n_iter_without_progress=100, momentum=0.0, learning_rate=0.0,
min_gain=0.0, min_grad_norm=1e-5, min_error_diff=0.0, verbose=2)
finally:
out = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = old_stdout
assert_equal(error, 1.0)
assert_equal(it, 0)
assert("gradient norm" in out)
# Error difference
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
_, error, it = _gradient_descent(
ObjectiveSmallGradient(), np.zeros(1), 0, n_iter=100,
n_iter_without_progress=100, momentum=0.0, learning_rate=0.0,
min_gain=0.0, min_grad_norm=0.0, min_error_diff=0.2, verbose=2)
finally:
out = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = old_stdout
assert_equal(error, 0.9)
assert_equal(it, 1)
assert("error difference" in out)
# Maximum number of iterations without improvement
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
_, error, it = _gradient_descent(
flat_function, np.zeros(1), 0, n_iter=100,
n_iter_without_progress=10, momentum=0.0, learning_rate=0.0,
min_gain=0.0, min_grad_norm=0.0, min_error_diff=-1.0, verbose=2)
finally:
out = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = old_stdout
assert_equal(error, 0.0)
assert_equal(it, 11)
assert("did not make any progress" in out)
# Maximum number of iterations
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
_, error, it = _gradient_descent(
ObjectiveSmallGradient(), np.zeros(1), 0, n_iter=11,
n_iter_without_progress=100, momentum=0.0, learning_rate=0.0,
min_gain=0.0, min_grad_norm=0.0, min_error_diff=0.0, verbose=2)
finally:
out = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = old_stdout
assert_equal(error, 0.0)
assert_equal(it, 10)
assert("Iteration 10" in out)
def test_binary_search():
# Test if the binary search finds Gaussians with desired perplexity.
random_state = check_random_state(0)
distances = random_state.randn(50, 2)
distances = distances.dot(distances.T)
np.fill_diagonal(distances, 0.0)
desired_perplexity = 25.0
P = _binary_search_perplexity(distances, desired_perplexity, verbose=0)
P = np.maximum(P, np.finfo(np.double).eps)
mean_perplexity = np.mean([np.exp(-np.sum(P[i] * np.log(P[i])))
for i in range(P.shape[0])])
assert_almost_equal(mean_perplexity, desired_perplexity, decimal=3)
def test_gradient():
# Test gradient of Kullback-Leibler divergence.
random_state = check_random_state(0)
n_samples = 50
n_features = 2
n_components = 2
alpha = 1.0
distances = random_state.randn(n_samples, n_features)
distances = distances.dot(distances.T)
np.fill_diagonal(distances, 0.0)
X_embedded = random_state.randn(n_samples, n_components)
P = _joint_probabilities(distances, desired_perplexity=25.0,
verbose=0)
fun = lambda params: _kl_divergence(params, P, alpha, n_samples,
n_components)[0]
grad = lambda params: _kl_divergence(params, P, alpha, n_samples,
n_components)[1]
assert_almost_equal(check_grad(fun, grad, X_embedded.ravel()), 0.0,
decimal=5)
def test_trustworthiness():
# Test trustworthiness score.
random_state = check_random_state(0)
# Affine transformation
X = random_state.randn(100, 2)
assert_equal(trustworthiness(X, 5.0 + X / 10.0), 1.0)
# Randomly shuffled
X = np.arange(100).reshape(-1, 1)
X_embedded = X.copy()
random_state.shuffle(X_embedded)
assert_less(trustworthiness(X, X_embedded), 0.6)
# Completely different
X = np.arange(5).reshape(-1, 1)
X_embedded = np.array([[0], [2], [4], [1], [3]])
assert_almost_equal(trustworthiness(X, X_embedded, n_neighbors=1), 0.2)
def test_preserve_trustworthiness_approximately():
# Nearest neighbors should be preserved approximately.
random_state = check_random_state(0)
X = random_state.randn(100, 2)
for init in ('random', 'pca'):
tsne = TSNE(n_components=2, perplexity=10, learning_rate=100.0,
init=init, random_state=0)
X_embedded = tsne.fit_transform(X)
assert_almost_equal(trustworthiness(X, X_embedded, n_neighbors=1), 1.0,
decimal=1)
def test_fit_csr_matrix():
# X can be a sparse matrix.
random_state = check_random_state(0)
X = random_state.randn(100, 2)
X[(np.random.randint(0, 100, 50), np.random.randint(0, 2, 50))] = 0.0
X_csr = sp.csr_matrix(X)
tsne = TSNE(n_components=2, perplexity=10, learning_rate=100.0,
random_state=0)
X_embedded = tsne.fit_transform(X_csr)
assert_almost_equal(trustworthiness(X_csr, X_embedded, n_neighbors=1), 1.0,
decimal=1)
def test_preserve_trustworthiness_approximately_with_precomputed_distances():
# Nearest neighbors should be preserved approximately.
random_state = check_random_state(0)
X = random_state.randn(100, 2)
D = squareform(pdist(X), "sqeuclidean")
tsne = TSNE(n_components=2, perplexity=10, learning_rate=100.0,
metric="precomputed", random_state=0)
X_embedded = tsne.fit_transform(D)
assert_almost_equal(trustworthiness(D, X_embedded, n_neighbors=1,
precomputed=True), 1.0, decimal=1)
def test_early_exaggeration_too_small():
# Early exaggeration factor must be >= 1.
tsne = TSNE(early_exaggeration=0.99)
assert_raises_regexp(ValueError, "early_exaggeration .*",
tsne.fit_transform, np.array([[0.0]]))
def test_too_few_iterations():
# Number of gradient descent iterations must be at least 200.
tsne = TSNE(n_iter=199)
assert_raises_regexp(ValueError, "n_iter .*", tsne.fit_transform,
np.array([[0.0]]))
def test_non_square_precomputed_distances():
# Precomputed distance matrices must be square matrices.
tsne = TSNE(metric="precomputed")
assert_raises_regexp(ValueError, ".* square distance matrix",
tsne.fit_transform, np.array([[0.0], [1.0]]))
def test_init_not_available():
# 'init' must be 'pca' or 'random'.
assert_raises_regexp(ValueError, "'init' must be either 'pca' or 'random'",
TSNE, init="not available")
def test_distance_not_available():
# 'metric' must be valid.
tsne = TSNE(metric="not available")
assert_raises_regexp(ValueError, "Unknown metric not available.*",
tsne.fit_transform, np.array([[0.0], [1.0]]))
def test_pca_initialization_not_compatible_with_precomputed_kernel():
# Precomputed distance matrices must be square matrices.
tsne = TSNE(metric="precomputed", init="pca")
assert_raises_regexp(ValueError, "The parameter init=\"pca\" cannot be "
"used with metric=\"precomputed\".",
tsne.fit_transform, np.array([[0.0], [1.0]]))
def test_verbose():
random_state = check_random_state(0)
tsne = TSNE(verbose=2)
X = random_state.randn(5, 2)
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
tsne.fit_transform(X)
finally:
out = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = old_stdout
assert("[t-SNE]" in out)
assert("Computing pairwise distances" in out)
assert("Computed conditional probabilities" in out)
assert("Mean sigma" in out)
assert("Finished" in out)
assert("early exaggeration" in out)
assert("Finished" in out)
def test_chebyshev_metric():
# t-SNE should allow metrics that cannot be squared (issue #3526).
random_state = check_random_state(0)
tsne = TSNE(metric="chebyshev")
X = random_state.randn(5, 2)
tsne.fit_transform(X)
def test_reduction_to_one_component():
# t-SNE should allow reduction to one component (issue #4154).
random_state = check_random_state(0)
tsne = TSNE(n_components=1)
X = random_state.randn(5, 2)
X_embedded = tsne.fit(X).embedding_
assert(np.all(np.isfinite(X_embedded)))
|
bsd-3-clause
|
[
646,
984,
199,
504,
6357,
14,
24688,
14,
4174,
14,
4912,
492,
15073,
465,
5228,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
4421,
465,
2249,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
63,
11191,
199,
504,
6357,
14,
1208,
492,
1104,
63,
2355,
63,
929,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
485,
10153,
63,
27583,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
485,
9503,
63,
32049,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
485,
7490,
63,
26269,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
16822,
584,
273,
9585,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
29642,
6388,
199,
504,
6357,
14,
1237,
32294,
423,
1208,
492,
485,
3008,
63,
1733,
63,
529,
22198,
1209,
199,
504,
7026,
14,
13416,
492,
1104,
63,
6017,
199,
504,
7026,
14,
11679,
14,
5590,
492,
299,
2686,
199,
504,
7026,
14,
11679,
14,
5590,
492,
12386,
964,
421,
199,
318,
511,
63,
7490,
63,
26269,
63,
270,
1483,
837,
272,
327,
1379,
23599,
3704,
402,
6709,
31518,
14,
272,
1021,
24921,
6850,
10712,
9942,
26,
267,
347,
636,
826,
721,
277,
304,
288,
291,
14,
390,
275,
446,
17,
398,
347,
636,
1250,
721,
277,
12,
27574,
288,
291,
14,
390,
847,
413,
288,
372,
334,
709,
446,
291,
14,
390,
9,
1182,
1616,
14,
16,
12,
980,
14,
1144,
779,
17,
69,
13,
21,
566,
339,
347,
6829,
63,
1593,
1547,
304,
267,
372,
378,
14,
16,
12,
980,
14,
4548,
8,
17,
9,
339,
327,
19603,
6316,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
342,
272,
862,
26,
267,
5501,
1125,
12,
652,
275,
485,
7490,
63,
26269,
8,
288,
24921,
6850,
10712,
9942,
1062,
980,
14,
4250,
8,
17,
395,
378,
12,
302,
63,
1661,
29,
1960,
12,
288,
302,
63,
1661,
63,
7395,
63,
5734,
29,
1960,
12,
23887,
29,
16,
14,
16,
12,
9328,
63,
1866,
29,
16,
14,
16,
12,
288,
1748,
63,
13020,
29,
16,
14,
16,
12,
1748,
63,
6017,
63,
4791,
29,
17,
69,
13,
21,
12,
1748,
63,
705,
63,
3028,
29,
16,
14,
16,
12,
3376,
29,
18,
9,
272,
3753,
26,
267,
734,
275,
984,
14,
2703,
14,
7150,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
2703,
275,
2269,
63,
2703,
272,
702,
63,
1452,
8,
705,
12,
413,
14,
16,
9,
272,
702,
63,
1452,
8,
390,
12,
378,
9,
272,
702,
480,
7490,
6316,
2,
315,
734,
9,
339,
327,
4520,
8865,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
342,
272,
862,
26,
267,
5501,
1125,
12,
652,
275,
485,
7490,
63,
26269,
8,
288,
24921,
6850,
10712,
9942,
1062,
980,
14,
4250,
8,
17,
395,
378,
12,
302,
63,
1661,
29,
1960,
12,
288,
302,
63,
1661,
63,
7395,
63,
5734,
29,
1960,
12,
23887,
29,
16,
14,
16,
12,
9328,
63,
1866,
29,
16,
14,
16,
12,
288,
1748,
63,
13020,
29,
16,
14,
16,
12,
1748,
63,
6017,
63,
4791,
29,
16,
14,
16,
12,
1748,
63,
705,
63,
3028,
29,
16,
14,
18,
12,
3376,
29,
18,
9,
272,
3753,
26,
267,
734,
275,
984,
14,
2703,
14,
7150,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
2703,
275,
2269,
63,
2703,
272,
702,
63,
1452,
8,
705,
12,
378,
14,
25,
9,
272,
702,
63,
1452,
8,
390,
12,
413,
9,
272,
702,
480,
705,
8865,
2,
315,
734,
9,
339,
327,
14212,
1329,
402,
10615,
1928,
19053,
434,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
342,
272,
862,
26,
267,
5501,
1125,
12,
652,
275,
485,
7490,
63,
26269,
8,
288,
6829,
63,
1593,
12,
980,
14,
4250,
8,
17,
395,
378,
12,
302,
63,
1661,
29,
1960,
12,
288,
302,
63,
1661,
63,
7395,
63,
5734,
29,
709,
12,
23887,
29,
16,
14,
16,
12,
9328,
63,
1866,
29,
16,
14,
16,
12,
288,
1748,
63,
13020,
29,
16,
14,
16,
12,
1748,
63,
6017,
63,
4791,
29,
16,
14,
16,
12,
1748,
63,
705,
63,
3028,
4022,
17,
14,
16,
12,
3376,
29,
18,
9,
272,
3753,
26,
267,
734,
275,
984,
14,
2703,
14,
7150,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
2703,
275,
2269,
63,
2703,
272,
702,
63,
1452,
8,
705,
12,
378,
14,
16,
9,
272,
702,
63,
1452,
8,
390,
12,
4119,
9,
272,
702,
480,
14887,
440,
1852,
1263,
6696,
2,
315,
734,
9,
339,
327,
14212,
1329,
402,
10615,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
342,
272,
862,
26,
267,
5501,
1125,
12,
652,
275,
485,
7490,
63,
26269,
8,
288,
24921,
6850,
10712,
9942,
1062,
980,
14,
4250,
8,
17,
395,
378,
12,
302,
63,
1661,
29,
845,
12,
288,
302,
63,
1661,
63,
7395,
63,
5734,
29,
1960,
12,
23887,
29,
16,
14,
16,
12,
9328,
63,
1866,
29,
16,
14,
16,
12,
288,
1748,
63,
13020,
29,
16,
14,
16,
12,
1748,
63,
6017,
63,
4791,
29,
16,
14,
16,
12,
1748,
63,
705,
63,
3028,
29,
16,
14,
16,
12,
3376,
29,
18,
9,
272,
3753,
26,
267,
734,
275,
984,
14,
2703,
14,
7150,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
2703,
275,
2269,
63,
2703,
272,
702,
63,
1452,
8,
705,
12,
378,
14,
16,
9,
272,
702,
63,
1452,
8,
390,
12,
1616,
9,
272,
702,
480,
8666,
1616,
2,
315,
734,
9,
421,
199,
318,
511,
63,
3008,
63,
1733,
837,
272,
327,
1379,
340,
314,
3366,
2754,
17651,
9647,
17759,
796,
543,
6387,
1126,
22198,
1209,
14,
272,
2196,
63,
929,
275,
1104,
63,
2355,
63,
929,
8,
16
] |
[
984,
199,
504,
6357,
14,
24688,
14,
4174,
14,
4912,
492,
15073,
465,
5228,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
4421,
465,
2249,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
63,
11191,
199,
504,
6357,
14,
1208,
492,
1104,
63,
2355,
63,
929,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
485,
10153,
63,
27583,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
485,
9503,
63,
32049,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
485,
7490,
63,
26269,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
16822,
584,
273,
9585,
199,
504,
6357,
14,
1237,
32294,
14,
84,
63,
83,
685,
492,
29642,
6388,
199,
504,
6357,
14,
1237,
32294,
423,
1208,
492,
485,
3008,
63,
1733,
63,
529,
22198,
1209,
199,
504,
7026,
14,
13416,
492,
1104,
63,
6017,
199,
504,
7026,
14,
11679,
14,
5590,
492,
299,
2686,
199,
504,
7026,
14,
11679,
14,
5590,
492,
12386,
964,
421,
199,
318,
511,
63,
7490,
63,
26269,
63,
270,
1483,
837,
272,
327,
1379,
23599,
3704,
402,
6709,
31518,
14,
272,
1021,
24921,
6850,
10712,
9942,
26,
267,
347,
636,
826,
721,
277,
304,
288,
291,
14,
390,
275,
446,
17,
398,
347,
636,
1250,
721,
277,
12,
27574,
288,
291,
14,
390,
847,
413,
288,
372,
334,
709,
446,
291,
14,
390,
9,
1182,
1616,
14,
16,
12,
980,
14,
1144,
779,
17,
69,
13,
21,
566,
339,
347,
6829,
63,
1593,
1547,
304,
267,
372,
378,
14,
16,
12,
980,
14,
4548,
8,
17,
9,
339,
327,
19603,
6316,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
342,
272,
862,
26,
267,
5501,
1125,
12,
652,
275,
485,
7490,
63,
26269,
8,
288,
24921,
6850,
10712,
9942,
1062,
980,
14,
4250,
8,
17,
395,
378,
12,
302,
63,
1661,
29,
1960,
12,
288,
302,
63,
1661,
63,
7395,
63,
5734,
29,
1960,
12,
23887,
29,
16,
14,
16,
12,
9328,
63,
1866,
29,
16,
14,
16,
12,
288,
1748,
63,
13020,
29,
16,
14,
16,
12,
1748,
63,
6017,
63,
4791,
29,
17,
69,
13,
21,
12,
1748,
63,
705,
63,
3028,
29,
16,
14,
16,
12,
3376,
29,
18,
9,
272,
3753,
26,
267,
734,
275,
984,
14,
2703,
14,
7150,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
2703,
275,
2269,
63,
2703,
272,
702,
63,
1452,
8,
705,
12,
413,
14,
16,
9,
272,
702,
63,
1452,
8,
390,
12,
378,
9,
272,
702,
480,
7490,
6316,
2,
315,
734,
9,
339,
327,
4520,
8865,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
342,
272,
862,
26,
267,
5501,
1125,
12,
652,
275,
485,
7490,
63,
26269,
8,
288,
24921,
6850,
10712,
9942,
1062,
980,
14,
4250,
8,
17,
395,
378,
12,
302,
63,
1661,
29,
1960,
12,
288,
302,
63,
1661,
63,
7395,
63,
5734,
29,
1960,
12,
23887,
29,
16,
14,
16,
12,
9328,
63,
1866,
29,
16,
14,
16,
12,
288,
1748,
63,
13020,
29,
16,
14,
16,
12,
1748,
63,
6017,
63,
4791,
29,
16,
14,
16,
12,
1748,
63,
705,
63,
3028,
29,
16,
14,
18,
12,
3376,
29,
18,
9,
272,
3753,
26,
267,
734,
275,
984,
14,
2703,
14,
7150,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
2703,
275,
2269,
63,
2703,
272,
702,
63,
1452,
8,
705,
12,
378,
14,
25,
9,
272,
702,
63,
1452,
8,
390,
12,
413,
9,
272,
702,
480,
705,
8865,
2,
315,
734,
9,
339,
327,
14212,
1329,
402,
10615,
1928,
19053,
434,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
342,
272,
862,
26,
267,
5501,
1125,
12,
652,
275,
485,
7490,
63,
26269,
8,
288,
6829,
63,
1593,
12,
980,
14,
4250,
8,
17,
395,
378,
12,
302,
63,
1661,
29,
1960,
12,
288,
302,
63,
1661,
63,
7395,
63,
5734,
29,
709,
12,
23887,
29,
16,
14,
16,
12,
9328,
63,
1866,
29,
16,
14,
16,
12,
288,
1748,
63,
13020,
29,
16,
14,
16,
12,
1748,
63,
6017,
63,
4791,
29,
16,
14,
16,
12,
1748,
63,
705,
63,
3028,
4022,
17,
14,
16,
12,
3376,
29,
18,
9,
272,
3753,
26,
267,
734,
275,
984,
14,
2703,
14,
7150,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
2703,
275,
2269,
63,
2703,
272,
702,
63,
1452,
8,
705,
12,
378,
14,
16,
9,
272,
702,
63,
1452,
8,
390,
12,
4119,
9,
272,
702,
480,
14887,
440,
1852,
1263,
6696,
2,
315,
734,
9,
339,
327,
14212,
1329,
402,
10615,
272,
2269,
63,
2703,
275,
984,
14,
2703,
272,
984,
14,
2703,
275,
5228,
342,
272,
862,
26,
267,
5501,
1125,
12,
652,
275,
485,
7490,
63,
26269,
8,
288,
24921,
6850,
10712,
9942,
1062,
980,
14,
4250,
8,
17,
395,
378,
12,
302,
63,
1661,
29,
845,
12,
288,
302,
63,
1661,
63,
7395,
63,
5734,
29,
1960,
12,
23887,
29,
16,
14,
16,
12,
9328,
63,
1866,
29,
16,
14,
16,
12,
288,
1748,
63,
13020,
29,
16,
14,
16,
12,
1748,
63,
6017,
63,
4791,
29,
16,
14,
16,
12,
1748,
63,
705,
63,
3028,
29,
16,
14,
16,
12,
3376,
29,
18,
9,
272,
3753,
26,
267,
734,
275,
984,
14,
2703,
14,
7150,
342,
267,
984,
14,
2703,
14,
1600,
342,
267,
984,
14,
2703,
275,
2269,
63,
2703,
272,
702,
63,
1452,
8,
705,
12,
378,
14,
16,
9,
272,
702,
63,
1452,
8,
390,
12,
1616,
9,
272,
702,
480,
8666,
1616,
2,
315,
734,
9,
421,
199,
318,
511,
63,
3008,
63,
1733,
837,
272,
327,
1379,
340,
314,
3366,
2754,
17651,
9647,
17759,
796,
543,
6387,
1126,
22198,
1209,
14,
272,
2196,
63,
929,
275,
1104,
63,
2355,
63,
929,
8,
16,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
Sorsly/subtle
|
google-cloud-sdk/lib/surface/app/versions/start.py
|
3
|
3908
|
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Start command."""
from googlecloudsdk.api_lib.app import appengine_api_client
from googlecloudsdk.api_lib.app import operations_util
from googlecloudsdk.api_lib.app import version_util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions as calliope_exceptions
from googlecloudsdk.core import exceptions
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
from googlecloudsdk.core.console import progress_tracker
from googlecloudsdk.core.resource import resource_printer
class VersionsStartError(exceptions.Error):
"""Errors occurring when starting versions."""
pass
class Start(base.Command):
"""Start serving specified versions.
This command starts serving the specified versions. It may only be used if the
scaling module for your service has been set to manual.
"""
detailed_help = {
'DESCRIPTION': '{description}',
'EXAMPLES': """\
To start a specific version across all services, run:
$ {command} v1
To start multiple named versions across all services, run:
$ {command} v1 v2
To start a single version on a single service, run:
$ {command} --service servicename v1
To start multiple versions in a single service, run:
$ {command} --service servicename v1 v2
""",
}
@staticmethod
def Args(parser):
parser.add_argument('versions', nargs='+', help=(
'The versions to start. (optionally filtered by the --service flag).'))
parser.add_argument('--service', '-s',
help=('If specified, only start versions from the '
'given service.'))
def Run(self, args):
# TODO(user): This fails with "module/version does not exist" even
# when it exists if the scaling mode is set to auto. It would be good
# to improve that error message.
api_client = appengine_api_client.GetApiClient()
services = api_client.ListServices()
versions = version_util.GetMatchingVersions(
api_client.ListVersions(services),
args.versions, args.service)
if not versions:
log.warn('No matching versions found.')
return
fmt = 'list[title="Starting the following versions:"]'
resource_printer.Print(versions, fmt, out=log.status)
console_io.PromptContinue(cancel_on_no=True)
errors = {}
# Sort versions to make behavior deterministic enough for unit testing.
for version in sorted(versions):
try:
with progress_tracker.ProgressTracker('Starting [{0}]'.format(version)):
api_client.StartVersion(version.service, version.id)
except (calliope_exceptions.HttpException,
operations_util.OperationError,
operations_util.OperationTimeoutError) as err:
errors[version] = str(err)
if errors:
printable_errors = {}
for version, error_msg in errors.items():
short_name = '[{0}/{1}]'.format(version.service, version.id)
printable_errors[short_name] = '{0}: {1}'.format(short_name, error_msg)
raise VersionsStartError(
'Issues starting version(s): {0}\n\n'.format(
', '.join(printable_errors.keys())) +
'\n\n'.join(printable_errors.values()))
|
mit
|
[
3,
1898,
6900,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
1918,
7707,
1414,
1041,
199,
199,
504,
6233,
29691,
6341,
14,
1246,
63,
773,
14,
571,
492,
1145,
3908,
63,
1246,
63,
1258,
199,
504,
6233,
29691,
6341,
14,
1246,
63,
773,
14,
571,
492,
5331,
63,
1974,
199,
504,
6233,
29691,
6341,
14,
1246,
63,
773,
14,
571,
492,
1015,
63,
1974,
199,
504,
6233,
29691,
6341,
14,
915,
317,
13458,
492,
1300,
199,
504,
6233,
29691,
6341,
14,
915,
317,
13458,
492,
4967,
465,
3213,
317,
13458,
63,
3924,
199,
504,
6233,
29691,
6341,
14,
1018,
492,
4967,
199,
504,
6233,
29691,
6341,
14,
1018,
492,
943,
199,
504,
6233,
29691,
6341,
14,
1018,
14,
6614,
492,
8559,
63,
2308,
199,
504,
6233,
29691,
6341,
14,
1018,
14,
6614,
492,
6696,
63,
8877,
199,
504,
6233,
29691,
6341,
14,
1018,
14,
1927,
492,
2073,
63,
11835,
421,
199,
533,
5444,
1356,
3162,
547,
8,
3924,
14,
547,
304,
523,
408,
9298,
4781,
5985,
1380,
6617,
5459,
1041,
523,
986,
421,
199,
533,
7707,
8,
1095,
14,
3110,
304,
523,
408,
3162,
22701,
2013,
5459,
14,
819,
961,
1414,
9174,
22701,
314,
2013,
5459,
14,
2779,
1443,
1454,
506,
1202,
340,
314,
523,
13690,
859,
367,
2195,
2435,
965,
2757,
663,
370,
8722,
14,
523,
408,
819,
16212,
63,
3437,
275,
469,
489,
283,
17705,
356,
5041,
1802,
7293,
489,
283,
8918,
356,
9638,
881,
4005,
1343,
282,
2488,
1015,
9371,
1006,
8500,
12,
1255,
26,
953,
2672,
469,
1531,
93,
373,
17,
8592,
4005,
1343,
3663,
4310,
5459,
9371,
1006,
8500,
12,
1255,
26,
953,
2672,
469,
1531,
93,
373,
17,
373,
18,
8592,
4005,
1343,
282,
2849,
1015,
641,
282,
2849,
2435,
12,
1255,
26,
953,
2672,
469,
1531,
93,
1553,
1364,
8926,
433,
25869,
373,
17,
8592,
4005,
1343,
3663,
5459,
315,
282,
2849,
2435,
12,
1255,
26,
953,
2672,
469,
1531,
93,
1553,
1364,
8926,
433,
25869,
373,
17,
373,
18,
881,
10327,
523,
789,
819,
768,
4639,
523,
347,
3033,
8,
2087,
304,
272,
1798,
14,
525,
63,
2094,
360,
6234,
297,
9237,
534,
7386,
1720,
2687,
267,
283,
1918,
5459,
370,
1343,
14,
334,
1422,
1183,
9806,
701,
314,
1553,
1364,
3305,
680,
1333,
272,
1798,
14,
525,
63,
2094,
4517,
1364,
297,
2475,
83,
297,
717,
1720,
7782,
3917,
2013,
12,
1454,
1343,
5459,
687,
314,
283,
2892,
283,
11809,
2435,
12459,
819,
347,
3378,
8,
277,
12,
1249,
304,
272,
327,
3254,
8,
751,
304,
961,
6918,
543,
298,
578,
15,
1023,
1630,
440,
2187,
2,
2755,
272,
327,
1380,
652,
3495,
340,
314,
13690,
818,
365,
663,
370,
2599,
14,
221,
2779,
3955,
506,
6954,
272,
327,
370,
19053,
626,
1125,
1245,
14,
272,
2986,
63,
1258,
275,
1145,
3908,
63,
1246,
63,
1258,
14,
1002,
7394,
3041,
342,
272,
8500,
275,
2986,
63,
1258,
14,
1296,
15803,
342,
272,
5459,
275,
1015,
63,
1974,
14,
1002,
14215,
21167,
8,
267,
2986,
63,
1258,
14,
1296,
21167,
8,
5950,
395,
267,
1249,
14,
6234,
12,
1249,
14,
1364,
9,
339,
340,
440,
5459,
26,
489,
943,
14,
4050,
360,
1944,
4877,
5459,
1911,
2659,
489,
372,
339,
7104,
275,
283,
513,
59,
1213,
628,
14139,
314,
2569,
5459,
26,
937,
7,
272,
2073,
63,
11835,
14,
5375,
8,
6234,
12,
7104,
12,
734,
29,
793,
14,
1205,
9,
272,
8559,
63,
2308,
14,
20430,
24055,
8,
6406,
63,
265,
63,
889,
29,
549,
9,
339,
2552,
275,
1052,
272,
327,
16722,
5459,
370,
1852,
5953,
25286,
8321,
367,
4137,
5343,
14,
272,
367,
1015,
315,
3355,
8,
6234,
304,
489,
862,
26,
267,
543,
6696,
63,
8877,
14,
11504,
13652,
360,
14139,
8910,
16,
11049,
1370,
908,
8,
1023,
2298,
881,
2986,
63,
1258,
14,
3162,
3353,
8,
1023,
14,
1364,
12,
1015,
14,
344,
9,
489,
871,
334,
915,
317,
13458,
63,
3924,
14,
5779,
1726,
12,
1598,
5331,
63,
1974,
14,
3632,
5263,
12,
1598,
5331,
63,
1974,
14,
6044,
19382,
9,
465,
2329,
26,
267,
2552,
59,
1023,
61,
275,
620,
8,
1508,
9,
272,
340,
2552,
26,
489,
21834,
63,
2550,
275,
1052,
489,
367,
1015,
12,
1125,
63,
1328,
315,
2552,
14,
1744,
837,
267,
3974,
63,
354,
275,
6730,
91,
16,
16152,
17,
11049,
1370,
908,
8,
1023,
14,
1364,
12,
1015,
14,
344,
9,
267,
21834,
63,
2550,
59,
3612,
63,
354,
61,
275,
5041,
16,
9160,
469,
17,
5285,
908,
8,
3612,
63,
354,
12,
1125,
63,
1328,
9,
489,
746,
5444,
1356,
3162,
547,
8,
881,
283,
17106,
83,
6617,
1015,
8,
83,
304,
469,
16,
4988,
78,
60,
78,
1370,
908,
8,
1598,
1656,
1987,
904,
8,
20557,
63,
2550,
14,
1612,
4059,
435,
881,
1557,
78,
60,
78,
1370,
904,
8,
20557,
63,
2550,
14,
1459,
4059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6900,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
1918,
7707,
1414,
1041,
199,
199,
504,
6233,
29691,
6341,
14,
1246,
63,
773,
14,
571,
492,
1145,
3908,
63,
1246,
63,
1258,
199,
504,
6233,
29691,
6341,
14,
1246,
63,
773,
14,
571,
492,
5331,
63,
1974,
199,
504,
6233,
29691,
6341,
14,
1246,
63,
773,
14,
571,
492,
1015,
63,
1974,
199,
504,
6233,
29691,
6341,
14,
915,
317,
13458,
492,
1300,
199,
504,
6233,
29691,
6341,
14,
915,
317,
13458,
492,
4967,
465,
3213,
317,
13458,
63,
3924,
199,
504,
6233,
29691,
6341,
14,
1018,
492,
4967,
199,
504,
6233,
29691,
6341,
14,
1018,
492,
943,
199,
504,
6233,
29691,
6341,
14,
1018,
14,
6614,
492,
8559,
63,
2308,
199,
504,
6233,
29691,
6341,
14,
1018,
14,
6614,
492,
6696,
63,
8877,
199,
504,
6233,
29691,
6341,
14,
1018,
14,
1927,
492,
2073,
63,
11835,
421,
199,
533,
5444,
1356,
3162,
547,
8,
3924,
14,
547,
304,
523,
408,
9298,
4781,
5985,
1380,
6617,
5459,
1041,
523,
986,
421,
199,
533,
7707,
8,
1095,
14,
3110,
304,
523,
408,
3162,
22701,
2013,
5459,
14,
819,
961,
1414,
9174,
22701,
314,
2013,
5459,
14,
2779,
1443,
1454,
506,
1202,
340,
314,
523,
13690,
859,
367,
2195,
2435,
965,
2757,
663,
370,
8722,
14,
523,
408,
819,
16212,
63,
3437,
275,
469,
489,
283,
17705,
356,
5041,
1802,
7293,
489,
283,
8918,
356,
9638,
881,
4005,
1343,
282,
2488,
1015,
9371,
1006,
8500,
12,
1255,
26,
953,
2672,
469,
1531,
93,
373,
17,
8592,
4005,
1343,
3663,
4310,
5459,
9371,
1006,
8500,
12,
1255,
26,
953,
2672,
469,
1531,
93,
373,
17,
373,
18,
8592,
4005,
1343,
282,
2849,
1015,
641,
282,
2849,
2435,
12,
1255,
26,
953,
2672,
469,
1531,
93,
1553,
1364,
8926,
433,
25869,
373,
17,
8592,
4005,
1343,
3663,
5459,
315,
282,
2849,
2435,
12,
1255,
26,
953,
2672,
469,
1531,
93,
1553,
1364,
8926,
433,
25869,
373,
17,
373,
18,
881,
10327,
523,
789,
819,
768,
4639,
523,
347,
3033,
8,
2087,
304,
272,
1798,
14,
525,
63,
2094,
360,
6234,
297,
9237,
534,
7386,
1720,
2687,
267,
283,
1918,
5459,
370,
1343,
14,
334,
1422,
1183,
9806,
701,
314,
1553,
1364,
3305,
680,
1333,
272,
1798,
14,
525,
63,
2094,
4517,
1364,
297,
2475,
83,
297,
717,
1720,
7782,
3917,
2013,
12,
1454,
1343,
5459,
687,
314,
283,
2892,
283,
11809,
2435,
12459,
819,
347,
3378,
8,
277,
12,
1249,
304,
272,
327,
3254,
8,
751,
304,
961,
6918,
543,
298,
578,
15,
1023,
1630,
440,
2187,
2,
2755,
272,
327,
1380,
652,
3495,
340,
314,
13690,
818,
365,
663,
370,
2599,
14,
221,
2779,
3955,
506,
6954,
272,
327,
370,
19053,
626,
1125,
1245,
14,
272,
2986,
63,
1258,
275,
1145,
3908,
63,
1246,
63,
1258,
14,
1002,
7394,
3041,
342,
272,
8500,
275,
2986,
63,
1258,
14,
1296,
15803,
342,
272,
5459,
275,
1015,
63,
1974,
14,
1002,
14215,
21167,
8,
267,
2986,
63,
1258,
14,
1296,
21167,
8,
5950,
395,
267,
1249,
14,
6234,
12,
1249,
14,
1364,
9,
339,
340,
440,
5459,
26,
489,
943,
14,
4050,
360,
1944,
4877,
5459,
1911,
2659,
489,
372,
339,
7104,
275,
283,
513,
59,
1213,
628,
14139,
314,
2569,
5459,
26,
937,
7,
272,
2073,
63,
11835,
14,
5375,
8,
6234,
12,
7104,
12,
734,
29,
793,
14,
1205,
9,
272,
8559,
63,
2308,
14,
20430,
24055,
8,
6406,
63,
265,
63,
889,
29,
549,
9,
339,
2552,
275,
1052,
272,
327,
16722,
5459,
370,
1852,
5953,
25286,
8321,
367,
4137,
5343,
14,
272,
367,
1015,
315,
3355,
8,
6234,
304,
489,
862,
26,
267,
543,
6696,
63,
8877,
14,
11504,
13652,
360,
14139,
8910,
16,
11049,
1370,
908,
8,
1023,
2298,
881,
2986,
63,
1258,
14,
3162,
3353,
8,
1023,
14,
1364,
12,
1015,
14,
344,
9,
489,
871,
334,
915,
317,
13458,
63,
3924,
14,
5779,
1726,
12,
1598,
5331,
63,
1974,
14,
3632,
5263,
12,
1598,
5331,
63,
1974,
14,
6044,
19382,
9,
465,
2329,
26,
267,
2552,
59,
1023,
61,
275,
620,
8,
1508,
9,
272,
340,
2552,
26,
489,
21834,
63,
2550,
275,
1052,
489,
367,
1015,
12,
1125,
63,
1328,
315,
2552,
14,
1744,
837,
267,
3974,
63,
354,
275,
6730,
91,
16,
16152,
17,
11049,
1370,
908,
8,
1023,
14,
1364,
12,
1015,
14,
344,
9,
267,
21834,
63,
2550,
59,
3612,
63,
354,
61,
275,
5041,
16,
9160,
469,
17,
5285,
908,
8,
3612,
63,
354,
12,
1125,
63,
1328,
9,
489,
746,
5444,
1356,
3162,
547,
8,
881,
283,
17106,
83,
6617,
1015,
8,
83,
304,
469,
16,
4988,
78,
60,
78,
1370,
908,
8,
1598,
1656,
1987,
904,
8,
20557,
63,
2550,
14,
1612,
4059,
435,
881,
1557,
78,
60,
78,
1370,
904,
8,
20557,
63,
2550,
14,
1459,
4059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dimagol/trex-core
|
scripts/astf/http_manual_commands_connect_rst.py
|
2
|
1855
|
# Example connect and reset. should show syn-syn/ack-rst
from trex_astf_lib.api import *
# we can send either Python bytes type as below:
http_req = b'GET /3384 HTTP/1.1\r\nHost: 22.0.0.3\r\nConnection: Keep-Alive\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)\r\nAccept: */*\r\nAccept-Language: en-us\r\nAccept-Encoding: gzip, deflate, compress\r\n\r\n'
# or we can send Python string containing ascii chars, as below:
http_response = 'HTTP/1.1 200 OK\r\nServer: Microsoft-IIS/6.0\r\nContent-Type: text/html\r\nContent-Length: 32000\r\n\r\n<html><pre>**********</pre></html>'
class Prof1():
def __init__(self):
pass # tunables
def create_profile(self):
# client commands
prog_c = ASTFProgram()
prog_c.connect(); ## connect
prog_c.reset(); ## send RST from client side
prog_s = ASTFProgram()
prog_s.wait_for_peer_close(); # wait for client to close the socket
# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)
# template
temp_c = ASTFTCPClientTemplate(program=prog_c, ip_gen=ip_gen)
temp_s = ASTFTCPServerTemplate(program=prog_s) # using default association
template = ASTFTemplate(client_template=temp_c, server_template=temp_s)
# profile
profile = ASTFProfile(default_ip_gen=ip_gen, templates=template)
return profile
def get_profile(self,**kwargs):
return self.create_profile()
def register():
return Prof1()
|
apache-2.0
|
[
3,
5679,
4907,
436,
5305,
14,
1077,
2498,
9560,
13,
9466,
15,
564,
13,
8332,
257,
199,
199,
504,
307,
15063,
63,
1810,
70,
63,
773,
14,
1246,
492,
627,
421,
199,
3,
781,
883,
3222,
1902,
2018,
2783,
730,
465,
5084,
26,
199,
1014,
63,
2103,
275,
330,
7,
2970,
1182,
1153,
1349,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
4965,
26,
6928,
14,
16,
14,
16,
14,
19,
60,
82,
60,
78,
3225,
26,
14797,
13,
23692,
60,
82,
60,
78,
1899,
13,
7788,
26,
17728,
15,
20,
14,
16,
334,
6490,
27,
603,
2684,
37,
1520,
14,
16,
27,
5417,
23350,
959,
14,
17,
27,
14056,
17,
27,
1275,
7278,
13354,
50,
413,
14,
17,
14,
10657,
18,
27,
1275,
7278,
13354,
50,
499,
14,
16,
14,
13583,
1465,
2862,
82,
60,
78,
8422,
26,
627,
26695,
82,
60,
78,
8422,
13,
8493,
26,
655,
13,
527,
60,
82,
60,
78,
8422,
13,
7630,
26,
11756,
12,
347,
750,
12,
11029,
60,
82,
60,
78,
60,
82,
60,
78,
7,
199,
3,
503,
781,
883,
3222,
2018,
1059,
3035,
13294,
8365,
12,
465,
5084,
26,
199,
1014,
63,
1310,
275,
283,
2856,
15,
17,
14,
17,
1926,
9949,
60,
82,
60,
78,
3120,
26,
15332,
13,
41,
1311,
15,
22,
14,
16,
60,
82,
60,
78,
2714,
13,
804,
26,
1318,
15,
1360,
60,
82,
60,
78,
2714,
13,
4625,
26,
4337,
1493,
60,
82,
60,
78,
60,
82,
60,
78,
28,
1360,
2535,
657,
30,
1801,
538,
1108,
657,
2957,
1360,
3524,
199,
199,
533,
2165,
70,
17,
837,
272,
347,
636,
826,
721,
277,
304,
267,
986,
221,
327,
15486,
5921,
339,
347,
1218,
63,
2913,
8,
277,
304,
267,
327,
1890,
3718,
267,
13205,
63,
67,
275,
20788,
38,
9184,
342,
267,
13205,
63,
67,
14,
2242,
7303,
925,
4907,
4960,
13205,
63,
67,
14,
3958,
7303,
257,
925,
3222,
820,
840,
687,
1890,
5366,
24807,
13205,
63,
83,
275,
20788,
38,
9184,
342,
267,
13205,
63,
83,
14,
2573,
63,
509,
63,
7866,
63,
1600,
7303,
327,
3618,
367,
1890,
370,
4002,
314,
2838,
24807,
327,
3384,
4306,
267,
3384,
63,
2268,
63,
67,
275,
20788,
38,
1772,
8168,
12012,
8,
711,
63,
1842,
6270,
975,
14,
16,
14,
16,
14,
16,
401,
298,
975,
14,
16,
14,
16,
14,
2299,
2255,
4084,
628,
3610,
531,
267,
3384,
63,
2268,
63,
83,
275,
20788,
38,
1772,
8168,
12012,
8,
711,
63,
1842,
6270,
2006,
14,
16,
14,
16,
14,
16,
401,
298,
2006,
14,
16,
14,
2299,
14,
2299,
2255,
4084,
628,
3610,
531,
267,
3384,
63,
2268,
275,
20788,
38,
1772,
8168,
8,
6463,
29,
11307,
38,
1772,
8168,
7025,
8,
711,
63,
2743,
628,
17,
14,
16,
14,
16,
14,
16,
1288,
2574,
2917,
63,
1258,
29,
711,
63,
2268,
63,
67,
12,
2574,
2917,
63,
1000,
29,
711,
63,
2268,
63,
83,
9,
398,
327,
1978,
267,
2388,
63,
67,
275,
20788,
2161,
2890,
3041,
4231,
8,
6815,
29,
6595,
63,
67,
12,
3384,
63,
2268,
29,
711,
63,
2268,
9,
267,
2388,
63,
83,
275,
20788,
2161,
2890,
3120,
4231,
8,
6815,
29,
6595,
63,
83,
9,
221,
327,
1808,
849,
20640,
267,
1978,
275,
20788,
2161,
3051,
8,
1258,
63,
1160,
29,
808,
63,
67,
12,
1654,
63,
1160,
29,
808,
63,
83,
9,
398,
327,
4690,
267,
4690,
275,
20788,
38,
5736,
8,
885,
63,
711,
63,
2268,
29,
711,
63,
2268,
12,
7009,
29,
1160,
9,
267,
372,
4690,
339,
347,
664,
63,
2913,
8,
277,
12663,
958,
304,
267,
372,
291,
14,
981,
63,
2913,
342,
421,
199,
318,
2274,
837,
272,
372,
2165,
70,
17,
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
] |
[
5679,
4907,
436,
5305,
14,
1077,
2498,
9560,
13,
9466,
15,
564,
13,
8332,
257,
199,
199,
504,
307,
15063,
63,
1810,
70,
63,
773,
14,
1246,
492,
627,
421,
199,
3,
781,
883,
3222,
1902,
2018,
2783,
730,
465,
5084,
26,
199,
1014,
63,
2103,
275,
330,
7,
2970,
1182,
1153,
1349,
3101,
15,
17,
14,
17,
60,
82,
60,
78,
4965,
26,
6928,
14,
16,
14,
16,
14,
19,
60,
82,
60,
78,
3225,
26,
14797,
13,
23692,
60,
82,
60,
78,
1899,
13,
7788,
26,
17728,
15,
20,
14,
16,
334,
6490,
27,
603,
2684,
37,
1520,
14,
16,
27,
5417,
23350,
959,
14,
17,
27,
14056,
17,
27,
1275,
7278,
13354,
50,
413,
14,
17,
14,
10657,
18,
27,
1275,
7278,
13354,
50,
499,
14,
16,
14,
13583,
1465,
2862,
82,
60,
78,
8422,
26,
627,
26695,
82,
60,
78,
8422,
13,
8493,
26,
655,
13,
527,
60,
82,
60,
78,
8422,
13,
7630,
26,
11756,
12,
347,
750,
12,
11029,
60,
82,
60,
78,
60,
82,
60,
78,
7,
199,
3,
503,
781,
883,
3222,
2018,
1059,
3035,
13294,
8365,
12,
465,
5084,
26,
199,
1014,
63,
1310,
275,
283,
2856,
15,
17,
14,
17,
1926,
9949,
60,
82,
60,
78,
3120,
26,
15332,
13,
41,
1311,
15,
22,
14,
16,
60,
82,
60,
78,
2714,
13,
804,
26,
1318,
15,
1360,
60,
82,
60,
78,
2714,
13,
4625,
26,
4337,
1493,
60,
82,
60,
78,
60,
82,
60,
78,
28,
1360,
2535,
657,
30,
1801,
538,
1108,
657,
2957,
1360,
3524,
199,
199,
533,
2165,
70,
17,
837,
272,
347,
636,
826,
721,
277,
304,
267,
986,
221,
327,
15486,
5921,
339,
347,
1218,
63,
2913,
8,
277,
304,
267,
327,
1890,
3718,
267,
13205,
63,
67,
275,
20788,
38,
9184,
342,
267,
13205,
63,
67,
14,
2242,
7303,
925,
4907,
4960,
13205,
63,
67,
14,
3958,
7303,
257,
925,
3222,
820,
840,
687,
1890,
5366,
24807,
13205,
63,
83,
275,
20788,
38,
9184,
342,
267,
13205,
63,
83,
14,
2573,
63,
509,
63,
7866,
63,
1600,
7303,
327,
3618,
367,
1890,
370,
4002,
314,
2838,
24807,
327,
3384,
4306,
267,
3384,
63,
2268,
63,
67,
275,
20788,
38,
1772,
8168,
12012,
8,
711,
63,
1842,
6270,
975,
14,
16,
14,
16,
14,
16,
401,
298,
975,
14,
16,
14,
16,
14,
2299,
2255,
4084,
628,
3610,
531,
267,
3384,
63,
2268,
63,
83,
275,
20788,
38,
1772,
8168,
12012,
8,
711,
63,
1842,
6270,
2006,
14,
16,
14,
16,
14,
16,
401,
298,
2006,
14,
16,
14,
2299,
14,
2299,
2255,
4084,
628,
3610,
531,
267,
3384,
63,
2268,
275,
20788,
38,
1772,
8168,
8,
6463,
29,
11307,
38,
1772,
8168,
7025,
8,
711,
63,
2743,
628,
17,
14,
16,
14,
16,
14,
16,
1288,
2574,
2917,
63,
1258,
29,
711,
63,
2268,
63,
67,
12,
2574,
2917,
63,
1000,
29,
711,
63,
2268,
63,
83,
9,
398,
327,
1978,
267,
2388,
63,
67,
275,
20788,
2161,
2890,
3041,
4231,
8,
6815,
29,
6595,
63,
67,
12,
3384,
63,
2268,
29,
711,
63,
2268,
9,
267,
2388,
63,
83,
275,
20788,
2161,
2890,
3120,
4231,
8,
6815,
29,
6595,
63,
83,
9,
221,
327,
1808,
849,
20640,
267,
1978,
275,
20788,
2161,
3051,
8,
1258,
63,
1160,
29,
808,
63,
67,
12,
1654,
63,
1160,
29,
808,
63,
83,
9,
398,
327,
4690,
267,
4690,
275,
20788,
38,
5736,
8,
885,
63,
711,
63,
2268,
29,
711,
63,
2268,
12,
7009,
29,
1160,
9,
267,
372,
4690,
339,
347,
664,
63,
2913,
8,
277,
12663,
958,
304,
267,
372,
291,
14,
981,
63,
2913,
342,
421,
199,
318,
2274,
837,
272,
372,
2165,
70,
17,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jonasjj/oslo-quant
|
spiders/osloquant/middlewares.py
|
1
|
1907
|
# -*- coding: utf-8 -*-
# Define here the models for your spider middleware
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/spider-middleware.html
from scrapy import signals
class OsloquantSpiderMiddleware(object):
# Not all methods need to be defined. If a method is not defined,
# scrapy acts as if the spider middleware does not modify the
# passed objects.
@classmethod
def from_crawler(cls, crawler):
# This method is used by Scrapy to create your spiders.
s = cls()
crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)
return s
def process_spider_input(self, response, spider):
# Called for each response that goes through the spider
# middleware and into the spider.
# Should return None or raise an exception.
return None
def process_spider_output(self, response, result, spider):
# Called with the results returned from the Spider, after
# it has processed the response.
# Must return an iterable of Request, dict or Item objects.
for i in result:
yield i
def process_spider_exception(self, response, exception, spider):
# Called when a spider or process_spider_input() method
# (from other spider middleware) raises an exception.
# Should return either None or an iterable of Response, dict
# or Item objects.
pass
def process_start_requests(self, start_requests, spider):
# Called with the start requests of the spider, and works
# similarly to the process_spider_output() method, except
# that it doesn’t have a response associated.
# Must return only requests (not items).
for r in start_requests:
yield r
def spider_opened(self, spider):
spider.logger.info('Spider opened: %s' % spider.name)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
13930,
2348,
314,
1709,
367,
2195,
18094,
10816,
199,
3,
199,
3,
1666,
3794,
315,
26,
199,
3,
1455,
921,
1301,
14,
26442,
14,
1308,
15,
287,
15,
7410,
15,
11299,
15,
12856,
13,
5754,
14,
1360,
199,
199,
504,
18918,
492,
10166,
421,
199,
533,
593,
83,
320,
13603,
25157,
6608,
8,
785,
304,
272,
327,
2832,
1006,
3102,
1929,
370,
506,
3247,
14,
982,
282,
1083,
365,
440,
3247,
12,
272,
327,
18918,
17795,
465,
340,
314,
18094,
10816,
1630,
440,
2811,
314,
272,
327,
3032,
2251,
14,
339,
768,
3744,
272,
347,
687,
63,
23972,
8,
1886,
12,
29550,
304,
267,
327,
961,
1083,
365,
1202,
701,
13916,
345,
647,
370,
1218,
2195,
19441,
7735,
14,
267,
308,
275,
843,
342,
267,
29550,
14,
10458,
14,
2242,
8,
83,
14,
12856,
63,
19234,
12,
4673,
29,
10458,
14,
12856,
63,
19234,
9,
267,
372,
308,
339,
347,
2112,
63,
12856,
63,
1210,
8,
277,
12,
1177,
12,
18094,
304,
267,
327,
12295,
367,
1924,
1177,
626,
13538,
4012,
314,
18094,
267,
327,
10816,
436,
1901,
314,
18094,
14,
398,
327,
7719,
372,
488,
503,
746,
376,
1919,
14,
267,
372,
488,
339,
347,
2112,
63,
12856,
63,
1199,
8,
277,
12,
1177,
12,
754,
12,
18094,
304,
267,
327,
12295,
543,
314,
2058,
2138,
687,
314,
428,
12508,
12,
2410,
267,
327,
652,
965,
7686,
314,
1177,
14,
398,
327,
9498,
372,
376,
6076,
402,
4784,
12,
1211,
503,
7020,
2251,
14,
267,
367,
284,
315,
754,
26,
288,
1995,
284,
339,
347,
2112,
63,
12856,
63,
1971,
8,
277,
12,
1177,
12,
1919,
12,
18094,
304,
267,
327,
12295,
1380,
282,
18094,
503,
2112,
63,
12856,
63,
1210,
342,
1083,
267,
327,
334,
504,
1163,
18094,
10816,
9,
6534,
376,
1919,
14,
398,
327,
7719,
372,
1902,
488,
503,
376,
6076,
402,
7232,
12,
1211,
267,
327,
503,
7020,
2251,
14,
267,
986,
339,
347,
2112,
63,
928,
63,
6615,
8,
277,
12,
1343,
63,
6615,
12,
18094,
304,
267,
327,
12295,
543,
314,
1343,
4145,
402,
314,
18094,
12,
436,
5419,
267,
327,
8545,
590,
370,
314,
2112,
63,
12856,
63,
1199,
342,
1083,
12,
871,
267,
327,
626,
652,
3181,
21045,
84,
1172,
282,
1177,
4568,
14,
398,
327,
9498,
372,
1454,
4145,
334,
1397,
2974,
680,
267,
367,
519,
315,
1343,
63,
6615,
26,
288,
1995,
519,
339,
347,
18094,
63,
19234,
8,
277,
12,
18094,
304,
267,
18094,
14,
2921,
14,
815,
360,
25157,
12123,
26,
450,
83,
7,
450,
18094,
14,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
13930,
2348,
314,
1709,
367,
2195,
18094,
10816,
199,
3,
199,
3,
1666,
3794,
315,
26,
199,
3,
1455,
921,
1301,
14,
26442,
14,
1308,
15,
287,
15,
7410,
15,
11299,
15,
12856,
13,
5754,
14,
1360,
199,
199,
504,
18918,
492,
10166,
421,
199,
533,
593,
83,
320,
13603,
25157,
6608,
8,
785,
304,
272,
327,
2832,
1006,
3102,
1929,
370,
506,
3247,
14,
982,
282,
1083,
365,
440,
3247,
12,
272,
327,
18918,
17795,
465,
340,
314,
18094,
10816,
1630,
440,
2811,
314,
272,
327,
3032,
2251,
14,
339,
768,
3744,
272,
347,
687,
63,
23972,
8,
1886,
12,
29550,
304,
267,
327,
961,
1083,
365,
1202,
701,
13916,
345,
647,
370,
1218,
2195,
19441,
7735,
14,
267,
308,
275,
843,
342,
267,
29550,
14,
10458,
14,
2242,
8,
83,
14,
12856,
63,
19234,
12,
4673,
29,
10458,
14,
12856,
63,
19234,
9,
267,
372,
308,
339,
347,
2112,
63,
12856,
63,
1210,
8,
277,
12,
1177,
12,
18094,
304,
267,
327,
12295,
367,
1924,
1177,
626,
13538,
4012,
314,
18094,
267,
327,
10816,
436,
1901,
314,
18094,
14,
398,
327,
7719,
372,
488,
503,
746,
376,
1919,
14,
267,
372,
488,
339,
347,
2112,
63,
12856,
63,
1199,
8,
277,
12,
1177,
12,
754,
12,
18094,
304,
267,
327,
12295,
543,
314,
2058,
2138,
687,
314,
428,
12508,
12,
2410,
267,
327,
652,
965,
7686,
314,
1177,
14,
398,
327,
9498,
372,
376,
6076,
402,
4784,
12,
1211,
503,
7020,
2251,
14,
267,
367,
284,
315,
754,
26,
288,
1995,
284,
339,
347,
2112,
63,
12856,
63,
1971,
8,
277,
12,
1177,
12,
1919,
12,
18094,
304,
267,
327,
12295,
1380,
282,
18094,
503,
2112,
63,
12856,
63,
1210,
342,
1083,
267,
327,
334,
504,
1163,
18094,
10816,
9,
6534,
376,
1919,
14,
398,
327,
7719,
372,
1902,
488,
503,
376,
6076,
402,
7232,
12,
1211,
267,
327,
503,
7020,
2251,
14,
267,
986,
339,
347,
2112,
63,
928,
63,
6615,
8,
277,
12,
1343,
63,
6615,
12,
18094,
304,
267,
327,
12295,
543,
314,
1343,
4145,
402,
314,
18094,
12,
436,
5419,
267,
327,
8545,
590,
370,
314,
2112,
63,
12856,
63,
1199,
342,
1083,
12,
871,
267,
327,
626,
652,
3181,
21045,
84,
1172,
282,
1177,
4568,
14,
398,
327,
9498,
372,
1454,
4145,
334,
1397,
2974,
680,
267,
367,
519,
315,
1343,
63,
6615,
26,
288,
1995,
519,
339,
347,
18094,
63,
19234,
8,
277,
12,
18094,
304,
267,
18094,
14,
2921,
14,
815,
360,
25157,
12123,
26,
450,
83,
7,
450,
18094,
14,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
wuhengzhi/chromium-crosswalk
|
third_party/WebKit/Source/build/scripts/in_file_unittest.py
|
78
|
3166
|
#!/usr/bin/env python
# Copyright (C) 2013 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import unittest
from in_file import InFile
class InFileTest(unittest.TestCase):
def test_basic_parse(self):
contents = """
name1 arg=value, arg2=value2, arg2=value3
name2
"""
lines = contents.split("\n")
defaults = {
'arg': None,
'arg2': [],
}
in_file = InFile(lines, defaults, None)
expected_values = [
{'name': 'name1', 'arg': 'value', 'arg2': ['value2', 'value3']},
{'name': 'name2', 'arg': None, 'arg2': []},
]
self.assertEquals(in_file.name_dictionaries, expected_values)
def test_with_parameters(self):
contents = """namespace=TestNamespace
fruit
name1 arg=value, arg2=value2, arg2=value3
name2
"""
lines = contents.split("\n")
defaults = {
'arg': None,
'arg2': [],
}
default_parameters = {
'namespace': '',
'fruit': False,
}
in_file = InFile(lines, defaults, default_parameters=default_parameters)
expected_parameters = {
'namespace': 'TestNamespace',
'fruit': True,
}
self.assertEquals(in_file.parameters, expected_parameters)
def test_assertion_for_non_in_files(self):
in_files = ['some_sample_file.json']
assertion_thrown = False
try:
in_file = InFile.load_from_files(in_files, None, None, None)
except AssertionError:
assertion_thrown = True
except:
pass
self.assertTrue(assertion_thrown)
if __name__ == "__main__":
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
35,
9,
6171,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
199,
199,
504,
315,
63,
493,
492,
1010,
1173,
199,
199,
533,
1010,
1173,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
4316,
63,
1122,
8,
277,
304,
267,
4072,
275,
408,
199,
354,
17,
1680,
29,
585,
12,
1680,
18,
29,
585,
18,
12,
1680,
18,
29,
585,
19,
199,
354,
18,
199,
624,
267,
2385,
275,
4072,
14,
1294,
4582,
78,
531,
267,
4243,
275,
469,
288,
283,
1273,
356,
488,
12,
288,
283,
1273,
18,
356,
990,
267,
789,
267,
315,
63,
493,
275,
1010,
1173,
8,
1278,
12,
4243,
12,
488,
9,
267,
1420,
63,
1459,
275,
359,
288,
791,
354,
356,
283,
354,
17,
297,
283,
1273,
356,
283,
585,
297,
283,
1273,
18,
356,
788,
585,
18,
297,
283,
585,
19,
14949,
288,
791,
354,
356,
283,
354,
18,
297,
283,
1273,
356,
488,
12,
283,
1273,
18,
356,
28657,
267,
1622,
267,
291,
14,
2947,
8,
262,
63,
493,
14,
354,
63,
328,
10150,
12,
1420,
63,
1459,
9,
339,
347,
511,
63,
1045,
63,
3214,
8,
277,
304,
267,
4072,
275,
408,
3251,
29,
774,
8814,
199,
4391,
4993,
199,
199,
354,
17,
1680,
29,
585,
12,
1680,
18,
29,
585,
18,
12,
1680,
18,
29,
585,
19,
199,
354,
18,
199,
624,
267,
2385,
275,
4072,
14,
1294,
4582,
78,
531,
267,
4243,
275,
469,
288,
283,
1273,
356,
488,
12,
288,
283,
1273,
18,
356,
990,
267,
789,
267,
849,
63,
3214,
275,
469,
288,
283,
3251,
356,
3260,
288,
283,
4391,
4993,
356,
756,
12,
267,
789,
267,
315,
63,
493,
275,
1010,
1173,
8,
1278,
12,
4243,
12,
849,
63,
3214,
29,
885,
63,
3214,
9,
267,
1420,
63,
3214,
275,
469,
288,
283,
3251,
356,
283,
774,
8814,
297,
288,
283,
4391,
4993,
356,
715,
12,
267,
789,
267,
291,
14,
2947,
8,
262,
63,
493,
14,
3214,
12,
1420,
63,
3214,
9,
339,
347,
511,
63,
18487,
63,
509,
63,
2865,
63,
262,
63,
1725,
8,
277,
304,
267,
315,
63,
1725,
275,
788,
3972,
63,
3271,
63,
493,
14,
1001,
418,
267,
14412,
63,
11964,
78,
275,
756,
267,
862,
26,
288,
315,
63,
493,
275,
1010,
1173,
14,
912,
63,
504,
63,
1725,
8,
262,
63,
1725,
12,
488,
12,
488,
12,
488,
9,
267,
871,
9070,
26,
288,
14412,
63,
11964,
78,
275,
715,
267,
871,
26,
288,
986,
267,
291,
14,
1815,
8,
18487,
63,
11964,
78,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
35,
9,
6171,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
199,
199,
504,
315,
63,
493,
492,
1010,
1173,
199,
199,
533,
1010,
1173,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
4316,
63,
1122,
8,
277,
304,
267,
4072,
275,
408,
199,
354,
17,
1680,
29,
585,
12,
1680,
18,
29,
585,
18,
12,
1680,
18,
29,
585,
19,
199,
354,
18,
199,
624,
267,
2385,
275,
4072,
14,
1294,
4582,
78,
531,
267,
4243,
275,
469,
288,
283,
1273,
356,
488,
12,
288,
283,
1273,
18,
356,
990,
267,
789,
267,
315,
63,
493,
275,
1010,
1173,
8,
1278,
12,
4243,
12,
488,
9,
267,
1420,
63,
1459,
275,
359,
288,
791,
354,
356,
283,
354,
17,
297,
283,
1273,
356,
283,
585,
297,
283,
1273,
18,
356,
788,
585,
18,
297,
283,
585,
19,
14949,
288,
791,
354,
356,
283,
354,
18,
297,
283,
1273,
356,
488,
12,
283,
1273,
18,
356,
28657,
267,
1622,
267,
291,
14,
2947,
8,
262,
63,
493,
14,
354,
63,
328,
10150,
12,
1420,
63,
1459,
9,
339,
347,
511,
63,
1045,
63,
3214,
8,
277,
304,
267,
4072,
275,
408,
3251,
29,
774,
8814,
199,
4391,
4993,
199,
199,
354,
17,
1680,
29,
585,
12,
1680,
18,
29,
585,
18,
12,
1680,
18,
29,
585,
19,
199,
354,
18,
199,
624,
267,
2385,
275,
4072,
14,
1294,
4582,
78,
531,
267,
4243,
275,
469,
288,
283,
1273,
356,
488,
12,
288,
283,
1273,
18,
356,
990,
267,
789,
267,
849,
63,
3214,
275,
469,
288,
283,
3251,
356,
3260,
288,
283,
4391,
4993,
356,
756,
12,
267,
789,
267,
315,
63,
493,
275,
1010,
1173,
8,
1278,
12,
4243,
12,
849,
63,
3214,
29,
885,
63,
3214,
9,
267,
1420,
63,
3214,
275,
469,
288,
283,
3251,
356,
283,
774,
8814,
297,
288,
283,
4391,
4993,
356,
715,
12,
267,
789,
267,
291,
14,
2947,
8,
262,
63,
493,
14,
3214,
12,
1420,
63,
3214,
9,
339,
347,
511,
63,
18487,
63,
509,
63,
2865,
63,
262,
63,
1725,
8,
277,
304,
267,
315,
63,
1725,
275,
788,
3972,
63,
3271,
63,
493,
14,
1001,
418,
267,
14412,
63,
11964,
78,
275,
756,
267,
862,
26,
288,
315,
63,
493,
275,
1010,
1173,
14,
912,
63,
504,
63,
1725,
8,
262,
63,
1725,
12,
488,
12,
488,
12,
488,
9,
267,
871,
9070,
26,
288,
14412,
63,
11964,
78,
275,
715,
267,
871,
26,
288,
986,
267,
291,
14,
1815,
8,
18487,
63,
11964,
78,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
EnTeQuAk/django-allauth
|
docs/conf.py
|
3
|
7802
|
# -*- coding: utf-8 -*-
#
# django-allauth documentation build configuration file, created by
# sphinx-quickstart on Wed Jun 6 22:58:42 2012.
#
# 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.
# 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 = []
# 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 = 'index'
# General information about the project.
project = u'django-allauth'
copyright = u'2014, Raymond Penners'
# 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 = '0.18.1-dev'
# The full version, including alpha/beta/rc tags.
release = '0.18.1-dev'
# 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 = ['_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 = '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 = 'django-allauthdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-allauth.tex', u'django-allauth Documentation',
u'Raymond Penners', '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
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-allauth', u'django-allauth Documentation',
[u'Raymond Penners'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'django-allauth', u'django-allauth Documentation',
u'Raymond Penners', 'django-allauth', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1639,
13,
29339,
762,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
644,
379,
1603,
324,
221,
1227,
6928,
26,
2010,
26,
2260,
6029,
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,
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,
942,
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,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
5121,
858,
13,
29339,
762,
7,
199,
7307,
275,
399,
7,
7280,
12,
30703,
2106,
68,
510,
287,
8715,
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,
16,
14,
1085,
14,
17,
13,
2374,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
1085,
14,
17,
13,
2374,
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,
4044,
1506,
418,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1639,
13,
29339,
762,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
644,
379,
1603,
324,
221,
1227,
6928,
26,
2010,
26,
2260,
6029,
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,
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,
942,
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,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
5121,
858,
13,
29339,
762,
7,
199,
7307,
275,
399,
7,
7280,
12,
30703,
2106,
68,
510,
287,
8715,
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,
16,
14,
1085,
14,
17,
13,
2374,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
1085,
14,
17,
13,
2374,
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,
4044,
1506,
418,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
anderson1008/NOCulator
|
hring/src/Script/my_print.py
|
1
|
8437
|
#!/usr/bin/python
import sys
import os
import re
import fnmatch
import string
import matplotlib.pyplot as plt
def print_period(stat):
# use to profile the application running solo.
# stat is an iterator or array
i = 0
for item in stat:
plt.plot(item, label=str(i))
plt.legend()
i = i + 1
def print_double_array (x):
for x_i in x:
sys.stdout.write(str("%.2f" % x_i) + ' ')
print "\n"
sys.stdout.flush()
def print_int_array (x):
for x_i in x:
sys.stdout.write(str(x_i) + ' ')
print "\n"
sys.stdout.flush()
def print_stat_dict (my_stat):
for key, value in iter(sorted(my_stat.iteritems())):
if type(value) is not list:
print key.ljust(20), value.ljust(20)
# else:
# for element in value:
# print element
def print_power (stat):
output_str = '\n\n############# Power Distribution ################\n\n'
output_str = output_str + ''.ljust(15) + 'Static'.ljust(20) + 'Dynamic'.ljust(20) + 'Overall'.ljust(20) + '\n'
## print BLESS
static_percent = "{:.2f}".format(stat[0]/stat[2]*100)
dynamic_percent = "{:.2f}".format(stat[1]/stat[2]*100)
output_str = output_str + 'BLESS'.ljust(15) + ('%s (%s%%)'%("{:.2f}".format(stat[0]),static_percent)).ljust(20) + ('%s (%s%%)'%("{:.2f}".format(stat[1]),dynamic_percent)).ljust(20) + str(stat[2]).ljust(20) + '\n'
# print MBNoC
static_percent = "{:.2f}".format(stat[3]/stat[5]*100)
dynamic_percent = "{:.2f}".format(stat[4]/stat[5]*100)
output_str = output_str + 'MBNoC'.ljust(15) + ('%s (%s%%)'%("{:.2f}".format(stat[3]),static_percent)).ljust(20) + ('%s (%s%%)'%("{:.2f}".format(stat[4]),dynamic_percent)).ljust(20) + str(stat[5]).ljust(20)
output_str = output_str + '\n'
print output_str
def print_power_breakdown (stat):
output_str = '\n\n############# Power Breakdown ################\n\n'
output_str = output_str + ''.ljust(15) + 'Static'.ljust(20) + 'Dynamic'.ljust(20) + 'Overall'.ljust(20) + '\n'
output_str = output_str + 'Component'.ljust(15) + 'BLESS'.ljust(10) + 'MBNoC'.ljust(10) + 'BLESS'.ljust(10) + 'MBNoC'.ljust(10) + 'BLESS'.ljust(10) + 'MBNoC'.ljust(10) + '\n'
print_order = ['DFF', 'portAlloc', 'RC', 'Xbar', 'Local', 'permNet', 'link']
for component in range (0, 7):
output_str = output_str + print_order[component].ljust(15)
for metric in stat:
output_str = output_str + str(metric[component+1]).ljust(10)
output_str = output_str + '\n'
print output_str
def print_final_stat (stat):
output_str = '\n\n############# Overall ################\n\n'
output_str = output_str + ''.ljust(20) + 'weighted_speedup'.ljust(20) + 'Energy'.ljust(20) + 'Throughput'.ljust(20) + 'Defection Rate'.ljust(20) + '\n'
output_str = output_str + 'Load'.ljust(10) + 'Count'.ljust(10)
for i in range (0, 4):
output_str = output_str + 'BLESS'.ljust(10) + 'MBNoC'.ljust(10)
output_str = output_str + '\n' + 'Low'.ljust(10)
for metric in stat[0]:
output_str = output_str + str(metric).ljust(10)
output_str = output_str + '\n'
output_str = output_str + 'Medium'.ljust(10)
for metric in stat[1]:
output_str = output_str + str(metric).ljust(10)
output_str = output_str + '\n'
output_str = output_str + 'High'.ljust(10)
for metric in stat[2]:
output_str = output_str + str(metric).ljust(10)
output_str = output_str + '\n'
output_str = output_str + 'Average'.ljust(10)
for metric in stat[3]:
output_str = output_str + str(metric).ljust(10)
output_str = output_str + '\n'
print output_str
return output_str
def print_for_plot (stat):
output_str = '\n\n############# Print for plot ################\n\n'
output_str = output_str + 'Baseline of each metrics of interest is 1.\nEach metric is normailized to BLESS with the same network size.\n\n'
output_str = output_str + 'Load'.ljust(8) + 'Count'.ljust(8) + 'ws'.ljust(8) + '4x4'.ljust(8) + '8x8'.ljust(8) + '16x6'.ljust(8) + 'engy'.ljust(8) + '4x4'.ljust(8) + '8x8'.ljust(8) + '16x16'.ljust(8) + 'th'.ljust(8) + '4x4'.ljust(8) + '8x8'.ljust(8) + '16x16'.ljust(8) + 'defl'.ljust(8) + '4x4'.ljust(8) + '8x8'.ljust(8) + '16x16'.ljust(8) + '\n'
groups = ['Low','Medium','High','Average']
i = 0
for element in stat:
output_str = output_str + groups[i].ljust(8)
for metric in element:
output_str = output_str + str(metric).ljust(8)
i = i + 1
output_str = output_str + '\n'
print output_str
return output_str
def print_synth (stat, design):
traffic = str(stat.pop(0))
network = str(stat.pop(0))
#output_str = '\n\n############# ' + "Traffic = " + traffic.ljust(20) + "Network = " + network.ljust(20) + ' ################\n\n'
#output_str = output_str + 'Inject_rate'.ljust(20) + 'Energy'.ljust(20) + 'Latency'.ljust(20) + 'Deflect_rate'.ljust(20) + 'Throughput'.ljust(20) + '\n\n'
#output_str = output_str + 'BLESS'.ljust(10) + 'MBNoC'.ljust(10) + 'BLESS'.ljust(10) + 'MBNoC'.ljust(10) + 'BLESS'.ljust(10) + 'MBNoC'.ljust(10) + 'BLESS'.ljust(10) + 'MBNoC'.ljust(10) + 'BLESS'.ljust(10) + 'MBNoC'.ljust(10) + '\n'
output_str = '\n\n############# ' + 'Traffic = ' + traffic.ljust(20) + 'Network = ' + network.ljust(20) + ' ################\n\n'
type_stat = len(stat) / len(design)
#for i in range (0, type_stat):
space = (len(design)+1)*10
output_str = output_str + 'Energy'.ljust(space) + 'Latency'.ljust(space) + 'Throughput'.ljust(space) + 'Deflect_rate'.ljust(space) + '\n\n'
for i in range (1, 80, 1):
load = "{:.2f}".format(float(i)/100)
for j in range (0, len(stat)):
if j % len(design) is 0:
output_str = output_str + load.ljust(10)
if load in stat[j]:
output_str = output_str + str(stat[j][load]).ljust(10)
else:
output_str = output_str + '-'.ljust(10)
output_str = output_str + '\n'
#for i in range (0, len(stat[0])):
# for j in range (0, len(stat)):
# output_str = output_str + str(stat[j][i]).ljust(10)
# output_str = output_str + '\n'
output_str = output_str + '********* Based on %u data points ************' % len(stat[0])
print output_str
def print_synth_wrt_load (stat, design):
traffic = str(stat.pop(0))
network = str(stat.pop(0))
output_str = '\n\n############# ' + 'Traffic = ' + traffic.ljust(20) + 'Network = ' + network.ljust(20) + ' ################\n\n'
type_stat = len(stat) / len(design)
#for i in range (0, type_stat):
space = (len(design)+1)*10
output_str = output_str + 'Latency'.ljust(space) + 'Throughput'.ljust(space) + 'Deflect_rate'.ljust(space) + '\n\n'
for i in range (0, type_stat):
output_str = output_str + 'InjRate'.ljust(10)
for element in design:
output_str = output_str + element.ljust(10)
output_str = output_str + '\n'
for i in range (1, 80, 1):
load = "{:.2f}".format(float(i)/100)
for j in range (0, len(stat)):
if j % len(design) is 0:
output_str = output_str + load.ljust(10)
if load in stat[j]:
output_str = output_str + str(stat[j][load]).ljust(10)
else:
output_str = output_str + '-'.ljust(10)
output_str = output_str + '\n'
output_str = output_str + '********* Based on %u data points ************' % len(stat[0])
print output_str
def print_synth_avg_reduction (stat, design):
output_str = ''
for element in design:
output_str = output_str + element.ljust(10)
baseline = stat[0]
output_str = output_str + '\n' + '1'.ljust(10)
stat.pop(0)
for element in stat:
reduction = ''
if baseline > 0: reduction = "{:.2f}".format((baseline - element) / baseline)
output_str = output_str + reduction.ljust(10)
output_str = output_str + '\n'
print output_str
def print_synth_avg_gain (stat, design):
output_str = ''
for element in design:
output_str = output_str + element.ljust(10)
baseline = stat[0]
output_str = output_str + '\n' + '1'.ljust(10)
stat.pop(0)
for element in stat:
reduction = ''
if baseline > 0: reduction = "{:.2f}".format((element - baseline) / baseline)
output_str = output_str + reduction.ljust(10)
output_str = output_str + '\n'
print output_str
def print_final (stat, design):
output_str = ''
for element in design:
output_str = output_str + element.ljust(10)
output_str = output_str + '\n'
for element in stat:
output_str = output_str + "{:.2f}".format(float(element)).ljust(10)
output_str = output_str + '\n'
print output_str
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
2999,
199,
646,
984,
202,
199,
646,
747,
202,
199,
646,
295,
202,
199,
646,
15951,
202,
199,
646,
1059,
202,
199,
646,
8027,
14,
13563,
465,
4488,
8065,
507,
202,
199,
318,
870,
63,
5191,
8,
3736,
304,
1128,
327,
675,
370,
4690,
314,
4223,
3879,
880,
320,
14,
1128,
327,
5672,
365,
376,
6122,
503,
1625,
1128,
284,
275,
378,
1128,
367,
1242,
315,
5672,
26,
1039,
4488,
14,
2798,
8,
1053,
12,
1768,
29,
495,
8,
73,
430,
1039,
4488,
14,
10231,
342,
1039,
284,
275,
284,
435,
413,
2999,
199,
318,
870,
63,
3157,
63,
1144,
334,
88,
304,
1223,
198,
509,
671,
63,
73,
315,
671,
26,
4122,
198,
1274,
14,
2703,
14,
952,
8,
495,
3647,
14,
18,
70,
2,
450,
671,
63,
73,
9,
435,
283,
5320,
1223,
198,
1361,
1867,
78,
2,
1223,
198,
1274,
14,
2703,
14,
4939,
342,
4122,
202,
199,
318,
870,
63,
442,
63,
1144,
334,
88,
304,
1223,
198,
509,
671,
63,
73,
315,
671,
26,
4122,
198,
1274,
14,
2703,
14,
952,
8,
495,
8,
88,
63,
73,
9,
435,
283,
5320,
1223,
198,
1361,
1867,
78,
2,
1223,
198,
1274,
14,
2703,
14,
4939,
342,
2999,
199,
318,
870,
63,
3736,
63,
807,
334,
1662,
63,
3736,
304,
1057,
1223,
198,
509,
790,
12,
574,
315,
2740,
8,
5917,
8,
1662,
63,
3736,
14,
4611,
28256,
4122,
198,
692,
730,
8,
585,
9,
365,
440,
769,
26,
1057,
7903,
198,
1361,
790,
14,
19996,
8,
1165,
395,
574,
14,
19996,
8,
1165,
9,
202,
199,
3,
198,
198,
2836,
26,
202,
199,
3,
1057,
198,
509,
1819,
315,
574,
26,
202,
199,
3,
9622,
198,
1361,
1819,
2999,
199,
318,
870,
63,
5652,
334,
3736,
304,
1223,
198,
1199,
63,
495,
275,
1557,
78,
60,
78,
516,
8776,
259,
18879,
11839,
221,
21905,
60,
78,
60,
78,
7,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
6522,
19996,
8,
1046,
9,
435,
283,
9278,
1370,
19996,
8,
1165,
9,
435,
283,
14451,
1370,
19996,
8,
1165,
9,
435,
283,
5674,
452,
1370,
19996,
8,
1165,
9,
435,
1557,
78,
7,
1223,
198,
309,
870,
15979,
1608,
1223,
198,
1986,
63,
7045,
275,
5310,
14010,
18,
70,
5469,
908,
8,
3736,
59,
16,
12978,
3736,
59,
18,
3672,
1960,
9,
1223,
198,
7764,
63,
7045,
275,
5310,
14010,
18,
70,
5469,
908,
8,
3736,
59,
17,
12978,
3736,
59,
18,
3672,
1960,
9,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
283,
7847,
1608,
1370,
19996,
8,
1046,
9,
435,
16651,
83,
4366,
83,
8530,
3171,
5,
13076,
14010,
18,
70,
5469,
908,
8,
3736,
59,
16,
2522,
1986,
63,
7045,
4992,
19996,
8,
1165,
9,
435,
16651,
83,
4366,
83,
8530,
3171,
5,
13076,
14010,
18,
70,
5469,
908,
8,
3736,
59,
17,
2522,
7764,
63,
7045,
4992,
19996,
8,
1165,
9,
435,
620,
8,
3736,
59,
18,
6575,
19996,
8,
1165,
9,
435,
1557,
78,
7,
1223,
198,
3,
870,
19487,
1944,
35,
1223,
198,
1986,
63,
7045,
275,
5310,
14010,
18,
70,
5469,
908,
8,
3736,
59,
19,
12978,
3736,
59,
21,
3672,
1960,
9,
1223,
198,
7764,
63,
7045,
275,
5310,
14010,
18,
70,
5469,
908,
8,
3736,
59,
20,
12978,
3736,
59,
21,
3672,
1960,
9,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
283,
4567,
1944,
35,
1370,
19996,
8,
1046,
9,
435,
16651,
83,
4366,
83,
8530,
3171,
5,
13076,
14010,
18,
70,
5469,
908,
8,
3736,
59,
19,
2522,
1986,
63,
7045,
4992,
19996,
8,
1165,
9,
435,
16651,
83,
4366,
83,
8530,
3171,
5,
13076,
14010,
18,
70,
5469,
908,
8,
3736,
59,
20,
2522,
7764,
63,
7045,
4992,
19996,
8,
1165,
9,
435,
620,
8,
3736,
59,
21,
6575,
19996,
8,
1165,
9,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
1557,
78,
7,
198,
10060,
198,
1361,
1072,
63,
495,
10060,
1223,
8065,
199,
318,
870,
63,
5652,
63,
4785,
2110,
334,
3736,
304,
1223,
198,
1199,
63,
495,
275,
1557,
78,
60,
78,
516,
8776,
259,
18879,
22535,
2110,
257,
21905,
60,
78,
60,
78,
7,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
6522,
19996,
8,
1046,
9,
435,
283,
9278,
1370,
19996,
8,
1165,
9,
435,
283,
14451,
1370,
19996,
8,
1165,
9,
435,
283,
5674,
452,
1370,
19996,
8,
1165,
9,
435,
1557,
78,
7,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
283,
7004,
1370,
19996,
8,
1046,
9,
435,
283,
7847,
1608,
1370,
19996,
8,
709,
9,
435,
283,
4567,
1944,
35,
1370,
19996,
8,
709,
9,
435,
283,
7847,
1608,
1370,
19996,
8,
709,
9,
435,
283,
4567,
1944,
35,
1370,
19996,
8,
709,
9,
435,
283,
7847,
1608,
1370,
19996,
8,
709,
9,
435,
283,
4567,
1944,
35,
1370,
19996,
8,
709,
9,
435,
1557,
78,
7,
1223,
198,
1361,
63,
1648,
275,
788,
36,
1665,
297,
283,
719,
2439,
2102,
297,
283,
8205,
297,
283,
56,
1700,
297,
283,
5339,
297,
283,
8220,
2480,
297,
283,
1073,
418,
1223,
198,
509,
3931,
315,
1425,
334,
16,
12,
1520,
304,
4122,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
870,
63,
1648,
59,
3173,
1055,
19996,
8,
1046,
9,
4122,
198,
509,
6370,
315,
5672,
26,
7903,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
620,
8,
5165,
59,
3173,
11,
17,
6575,
19996,
8,
709,
9,
4122,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
1557,
78,
7,
198,
10060,
198,
1361,
1072,
63,
495,
2999,
199,
318,
870,
63,
5094,
63,
3736,
334,
3736,
304,
1223,
198,
1199,
63,
495,
275,
1557,
78,
60,
78,
516,
8776,
259,
7259,
452,
259,
21905,
60,
78,
60,
78,
7,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
6522,
19996,
8,
1165,
9,
435,
283,
13522,
63,
7625,
384,
1370,
19996,
8,
1165,
9,
435,
283,
9900,
1370,
19996,
8,
1165,
9,
435,
283,
26732,
524,
1370,
19996,
8,
1165,
9,
435,
283,
872,
771,
414,
26311,
1370,
19996,
8,
1165,
9,
435,
1557,
78,
7,
1223,
198,
1199
] |
[
2647,
15,
1393,
15,
1548,
2999,
199,
646,
984,
202,
199,
646,
747,
202,
199,
646,
295,
202,
199,
646,
15951,
202,
199,
646,
1059,
202,
199,
646,
8027,
14,
13563,
465,
4488,
8065,
507,
202,
199,
318,
870,
63,
5191,
8,
3736,
304,
1128,
327,
675,
370,
4690,
314,
4223,
3879,
880,
320,
14,
1128,
327,
5672,
365,
376,
6122,
503,
1625,
1128,
284,
275,
378,
1128,
367,
1242,
315,
5672,
26,
1039,
4488,
14,
2798,
8,
1053,
12,
1768,
29,
495,
8,
73,
430,
1039,
4488,
14,
10231,
342,
1039,
284,
275,
284,
435,
413,
2999,
199,
318,
870,
63,
3157,
63,
1144,
334,
88,
304,
1223,
198,
509,
671,
63,
73,
315,
671,
26,
4122,
198,
1274,
14,
2703,
14,
952,
8,
495,
3647,
14,
18,
70,
2,
450,
671,
63,
73,
9,
435,
283,
5320,
1223,
198,
1361,
1867,
78,
2,
1223,
198,
1274,
14,
2703,
14,
4939,
342,
4122,
202,
199,
318,
870,
63,
442,
63,
1144,
334,
88,
304,
1223,
198,
509,
671,
63,
73,
315,
671,
26,
4122,
198,
1274,
14,
2703,
14,
952,
8,
495,
8,
88,
63,
73,
9,
435,
283,
5320,
1223,
198,
1361,
1867,
78,
2,
1223,
198,
1274,
14,
2703,
14,
4939,
342,
2999,
199,
318,
870,
63,
3736,
63,
807,
334,
1662,
63,
3736,
304,
1057,
1223,
198,
509,
790,
12,
574,
315,
2740,
8,
5917,
8,
1662,
63,
3736,
14,
4611,
28256,
4122,
198,
692,
730,
8,
585,
9,
365,
440,
769,
26,
1057,
7903,
198,
1361,
790,
14,
19996,
8,
1165,
395,
574,
14,
19996,
8,
1165,
9,
202,
199,
3,
198,
198,
2836,
26,
202,
199,
3,
1057,
198,
509,
1819,
315,
574,
26,
202,
199,
3,
9622,
198,
1361,
1819,
2999,
199,
318,
870,
63,
5652,
334,
3736,
304,
1223,
198,
1199,
63,
495,
275,
1557,
78,
60,
78,
516,
8776,
259,
18879,
11839,
221,
21905,
60,
78,
60,
78,
7,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
6522,
19996,
8,
1046,
9,
435,
283,
9278,
1370,
19996,
8,
1165,
9,
435,
283,
14451,
1370,
19996,
8,
1165,
9,
435,
283,
5674,
452,
1370,
19996,
8,
1165,
9,
435,
1557,
78,
7,
1223,
198,
309,
870,
15979,
1608,
1223,
198,
1986,
63,
7045,
275,
5310,
14010,
18,
70,
5469,
908,
8,
3736,
59,
16,
12978,
3736,
59,
18,
3672,
1960,
9,
1223,
198,
7764,
63,
7045,
275,
5310,
14010,
18,
70,
5469,
908,
8,
3736,
59,
17,
12978,
3736,
59,
18,
3672,
1960,
9,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
283,
7847,
1608,
1370,
19996,
8,
1046,
9,
435,
16651,
83,
4366,
83,
8530,
3171,
5,
13076,
14010,
18,
70,
5469,
908,
8,
3736,
59,
16,
2522,
1986,
63,
7045,
4992,
19996,
8,
1165,
9,
435,
16651,
83,
4366,
83,
8530,
3171,
5,
13076,
14010,
18,
70,
5469,
908,
8,
3736,
59,
17,
2522,
7764,
63,
7045,
4992,
19996,
8,
1165,
9,
435,
620,
8,
3736,
59,
18,
6575,
19996,
8,
1165,
9,
435,
1557,
78,
7,
1223,
198,
3,
870,
19487,
1944,
35,
1223,
198,
1986,
63,
7045,
275,
5310,
14010,
18,
70,
5469,
908,
8,
3736,
59,
19,
12978,
3736,
59,
21,
3672,
1960,
9,
1223,
198,
7764,
63,
7045,
275,
5310,
14010,
18,
70,
5469,
908,
8,
3736,
59,
20,
12978,
3736,
59,
21,
3672,
1960,
9,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
283,
4567,
1944,
35,
1370,
19996,
8,
1046,
9,
435,
16651,
83,
4366,
83,
8530,
3171,
5,
13076,
14010,
18,
70,
5469,
908,
8,
3736,
59,
19,
2522,
1986,
63,
7045,
4992,
19996,
8,
1165,
9,
435,
16651,
83,
4366,
83,
8530,
3171,
5,
13076,
14010,
18,
70,
5469,
908,
8,
3736,
59,
20,
2522,
7764,
63,
7045,
4992,
19996,
8,
1165,
9,
435,
620,
8,
3736,
59,
21,
6575,
19996,
8,
1165,
9,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
1557,
78,
7,
198,
10060,
198,
1361,
1072,
63,
495,
10060,
1223,
8065,
199,
318,
870,
63,
5652,
63,
4785,
2110,
334,
3736,
304,
1223,
198,
1199,
63,
495,
275,
1557,
78,
60,
78,
516,
8776,
259,
18879,
22535,
2110,
257,
21905,
60,
78,
60,
78,
7,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
6522,
19996,
8,
1046,
9,
435,
283,
9278,
1370,
19996,
8,
1165,
9,
435,
283,
14451,
1370,
19996,
8,
1165,
9,
435,
283,
5674,
452,
1370,
19996,
8,
1165,
9,
435,
1557,
78,
7,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
283,
7004,
1370,
19996,
8,
1046,
9,
435,
283,
7847,
1608,
1370,
19996,
8,
709,
9,
435,
283,
4567,
1944,
35,
1370,
19996,
8,
709,
9,
435,
283,
7847,
1608,
1370,
19996,
8,
709,
9,
435,
283,
4567,
1944,
35,
1370,
19996,
8,
709,
9,
435,
283,
7847,
1608,
1370,
19996,
8,
709,
9,
435,
283,
4567,
1944,
35,
1370,
19996,
8,
709,
9,
435,
1557,
78,
7,
1223,
198,
1361,
63,
1648,
275,
788,
36,
1665,
297,
283,
719,
2439,
2102,
297,
283,
8205,
297,
283,
56,
1700,
297,
283,
5339,
297,
283,
8220,
2480,
297,
283,
1073,
418,
1223,
198,
509,
3931,
315,
1425,
334,
16,
12,
1520,
304,
4122,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
870,
63,
1648,
59,
3173,
1055,
19996,
8,
1046,
9,
4122,
198,
509,
6370,
315,
5672,
26,
7903,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
620,
8,
5165,
59,
3173,
11,
17,
6575,
19996,
8,
709,
9,
4122,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
1557,
78,
7,
198,
10060,
198,
1361,
1072,
63,
495,
2999,
199,
318,
870,
63,
5094,
63,
3736,
334,
3736,
304,
1223,
198,
1199,
63,
495,
275,
1557,
78,
60,
78,
516,
8776,
259,
7259,
452,
259,
21905,
60,
78,
60,
78,
7,
1223,
198,
1199,
63,
495,
275,
1072,
63,
495,
435,
6522,
19996,
8,
1165,
9,
435,
283,
13522,
63,
7625,
384,
1370,
19996,
8,
1165,
9,
435,
283,
9900,
1370,
19996,
8,
1165,
9,
435,
283,
26732,
524,
1370,
19996,
8,
1165,
9,
435,
283,
872,
771,
414,
26311,
1370,
19996,
8,
1165,
9,
435,
1557,
78,
7,
1223,
198,
1199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wunderlins/learning
|
python/zodb/lib/linux64/setuptools/command/build_py.py
|
87
|
7983
|
from glob import glob
from distutils.util import convert_path
import distutils.command.build_py as orig
import os
import fnmatch
import textwrap
import io
import distutils.errors
import collections
import itertools
from setuptools.extern.six.moves import map
try:
from setuptools.lib2to3_ex import Mixin2to3
except ImportError:
class Mixin2to3:
def run_2to3(self, files, doctests=True):
"do nothing"
class build_py(orig.build_py, Mixin2to3):
"""Enhanced 'build_py' command that includes data files with packages
The data files are specified via a 'package_data' argument to 'setup()'.
See 'setuptools.dist.Distribution' for more details.
Also, this version of the 'build_py' command allows you to specify both
'py_modules' and 'packages' in the same setup operation.
"""
def finalize_options(self):
orig.build_py.finalize_options(self)
self.package_data = self.distribution.package_data
self.exclude_package_data = (self.distribution.exclude_package_data or
{})
if 'data_files' in self.__dict__:
del self.__dict__['data_files']
self.__updated_files = []
self.__doctests_2to3 = []
def run(self):
"""Build modules, packages, and copy data files to build directory"""
if not self.py_modules and not self.packages:
return
if self.py_modules:
self.build_modules()
if self.packages:
self.build_packages()
self.build_package_data()
self.run_2to3(self.__updated_files, False)
self.run_2to3(self.__updated_files, True)
self.run_2to3(self.__doctests_2to3, True)
# Only compile actual .py files, using our base class' idea of what our
# output files are.
self.byte_compile(orig.build_py.get_outputs(self, include_bytecode=0))
def __getattr__(self, attr):
"lazily compute data files"
if attr == 'data_files':
self.data_files = self._get_data_files()
return self.data_files
return orig.build_py.__getattr__(self, attr)
def build_module(self, module, module_file, package):
outfile, copied = orig.build_py.build_module(self, module, module_file,
package)
if copied:
self.__updated_files.append(outfile)
return outfile, copied
def _get_data_files(self):
"""Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
self.analyze_manifest()
return list(map(self._get_pkg_data_files, self.packages or ()))
def _get_pkg_data_files(self, package):
# Locate package source directory
src_dir = self.get_package_dir(package)
# Compute package build directory
build_dir = os.path.join(*([self.build_lib] + package.split('.')))
# Strip directory from globbed filenames
filenames = [
os.path.relpath(file, src_dir)
for file in self.find_data_files(package, src_dir)
]
return package, src_dir, build_dir, filenames
def find_data_files(self, package, src_dir):
"""Return filenames for package's data files in 'src_dir'"""
globs = (self.package_data.get('', [])
+ self.package_data.get(package, []))
files = self.manifest_files.get(package, [])[:]
for pattern in globs:
# Each pattern has to be converted to a platform-specific path
files.extend(glob(os.path.join(src_dir, convert_path(pattern))))
return self.exclude_data_files(package, src_dir, files)
def build_package_data(self):
"""Copy data files into build directory"""
for package, src_dir, build_dir, filenames in self.data_files:
for filename in filenames:
target = os.path.join(build_dir, filename)
self.mkpath(os.path.dirname(target))
srcfile = os.path.join(src_dir, filename)
outf, copied = self.copy_file(srcfile, target)
srcfile = os.path.abspath(srcfile)
if (copied and
srcfile in self.distribution.convert_2to3_doctests):
self.__doctests_2to3.append(outf)
def analyze_manifest(self):
self.manifest_files = mf = {}
if not self.distribution.include_package_data:
return
src_dirs = {}
for package in self.packages or ():
# Locate package source directory
src_dirs[assert_relative(self.get_package_dir(package))] = package
self.run_command('egg_info')
ei_cmd = self.get_finalized_command('egg_info')
for path in ei_cmd.filelist.files:
d, f = os.path.split(assert_relative(path))
prev = None
oldf = f
while d and d != prev and d not in src_dirs:
prev = d
d, df = os.path.split(d)
f = os.path.join(df, f)
if d in src_dirs:
if path.endswith('.py') and f == oldf:
continue # it's a module, not data
mf.setdefault(src_dirs[d], []).append(path)
def get_data_files(self):
pass # Lazily compute data files in _get_data_files() function.
def check_package(self, package, package_dir):
"""Check namespace packages' __init__ for declare_namespace"""
try:
return self.packages_checked[package]
except KeyError:
pass
init_py = orig.build_py.check_package(self, package, package_dir)
self.packages_checked[package] = init_py
if not init_py or not self.distribution.namespace_packages:
return init_py
for pkg in self.distribution.namespace_packages:
if pkg == package or pkg.startswith(package + '.'):
break
else:
return init_py
with io.open(init_py, 'rb') as f:
contents = f.read()
if b'declare_namespace' not in contents:
raise distutils.errors.DistutilsError(
"Namespace package problem: %s is a namespace package, but "
"its\n__init__.py does not call declare_namespace()! Please "
'fix it.\n(See the setuptools manual under '
'"Namespace Packages" for details.)\n"' % (package,)
)
return init_py
def initialize_options(self):
self.packages_checked = {}
orig.build_py.initialize_options(self)
def get_package_dir(self, package):
res = orig.build_py.get_package_dir(self, package)
if self.distribution.src_root is not None:
return os.path.join(self.distribution.src_root, res)
return res
def exclude_data_files(self, package, src_dir, files):
"""Filter filenames for package's data files in 'src_dir'"""
globs = (
self.exclude_package_data.get('', [])
+ self.exclude_package_data.get(package, [])
)
bad = set(
item
for pattern in globs
for item in fnmatch.filter(
files,
os.path.join(src_dir, convert_path(pattern)),
)
)
seen = collections.defaultdict(itertools.count)
return [
fn
for fn in files
if fn not in bad
# ditch dupes
and not next(seen[fn])
]
def assert_relative(path):
if not os.path.isabs(path):
return path
from distutils.errors import DistutilsSetupError
msg = textwrap.dedent("""
Error: setup script specifies an absolute path:
%s
setup() arguments must *always* be /-separated paths relative to the
setup.py directory, *never* absolute paths.
""").lstrip() % path
raise DistutilsSetupError(msg)
|
gpl-2.0
|
[
504,
5739,
492,
5739,
199,
504,
7065,
14,
1974,
492,
3957,
63,
515,
199,
646,
7065,
14,
1531,
14,
1506,
63,
647,
465,
2306,
199,
646,
747,
199,
646,
15951,
199,
646,
13390,
199,
646,
5890,
199,
646,
7065,
14,
2550,
199,
646,
5055,
199,
646,
7975,
199,
199,
504,
9116,
14,
18587,
14,
4174,
14,
4912,
492,
2341,
199,
199,
893,
26,
272,
687,
9116,
14,
773,
18,
475,
19,
63,
476,
492,
28438,
18,
475,
19,
199,
2590,
3545,
26,
272,
1021,
28438,
18,
475,
19,
26,
267,
347,
1255,
63,
18,
475,
19,
8,
277,
12,
1584,
12,
26721,
29,
549,
304,
288,
298,
1117,
6548,
2,
421,
199,
533,
1900,
63,
647,
8,
2981,
14,
1506,
63,
647,
12,
28438,
18,
475,
19,
304,
272,
408,
1327,
24384,
283,
1506,
63,
647,
7,
1414,
626,
6952,
666,
1584,
543,
6117,
339,
710,
666,
1584,
787,
2013,
4799,
282,
283,
2491,
63,
576,
7,
1423,
370,
283,
2758,
342,
1370,
272,
1666,
283,
13623,
14,
2686,
14,
8580,
7,
367,
1655,
2436,
14,
339,
6121,
12,
642,
1015,
402,
314,
283,
1506,
63,
647,
7,
1414,
6127,
1265,
370,
4165,
3865,
272,
283,
647,
63,
3112,
7,
436,
283,
5154,
7,
315,
314,
2011,
3272,
3439,
14,
272,
408,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
2306,
14,
1506,
63,
647,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
2491,
63,
576,
275,
291,
14,
4972,
14,
2491,
63,
576,
267,
291,
14,
5473,
63,
2491,
63,
576,
275,
334,
277,
14,
4972,
14,
5473,
63,
2491,
63,
576,
503,
3660,
5009,
267,
340,
283,
576,
63,
1725,
7,
315,
291,
855,
807,
10651,
288,
2150,
291,
855,
807,
23010,
576,
63,
1725,
418,
267,
291,
855,
5334,
63,
1725,
275,
942,
267,
291,
855,
1301,
2219,
63,
18,
475,
19,
275,
942,
339,
347,
1255,
8,
277,
304,
267,
408,
3425,
4621,
12,
6117,
12,
436,
1331,
666,
1584,
370,
1900,
2082,
624,
267,
340,
440,
291,
14,
647,
63,
3112,
436,
440,
291,
14,
5154,
26,
288,
372,
398,
340,
291,
14,
647,
63,
3112,
26,
288,
291,
14,
1506,
63,
3112,
342,
398,
340,
291,
14,
5154,
26,
288,
291,
14,
1506,
63,
5154,
342,
288,
291,
14,
1506,
63,
2491,
63,
576,
342,
398,
291,
14,
1065,
63,
18,
475,
19,
8,
277,
855,
5334,
63,
1725,
12,
756,
9,
267,
291,
14,
1065,
63,
18,
475,
19,
8,
277,
855,
5334,
63,
1725,
12,
715,
9,
267,
291,
14,
1065,
63,
18,
475,
19,
8,
277,
855,
1301,
2219,
63,
18,
475,
19,
12,
715,
9,
398,
327,
5972,
6555,
3503,
1275,
647,
1584,
12,
1808,
4154,
1300,
1021,
7,
16819,
402,
4052,
4154,
267,
327,
1072,
1584,
787,
14,
267,
291,
14,
4414,
63,
2014,
8,
2981,
14,
1506,
63,
647,
14,
362,
63,
4467,
8,
277,
12,
2387,
63,
19812,
29,
16,
430,
339,
347,
636,
5675,
721,
277,
12,
1921,
304,
267,
298,
416,
90,
3444,
4526,
666,
1584,
2,
267,
340,
1921,
508,
283,
576,
63,
1725,
356,
288,
291,
14,
576,
63,
1725,
275,
291,
423,
362,
63,
576,
63,
1725,
342,
288,
372,
291,
14,
576,
63,
1725,
267,
372,
2306,
14,
1506,
63,
647,
855,
5675,
721,
277,
12,
1921,
9,
339,
347,
1900,
63,
578,
8,
277,
12,
859,
12,
859,
63,
493,
12,
2559,
304,
267,
4386,
12,
8876,
275,
2306,
14,
1506,
63,
647,
14,
1506,
63,
578,
8,
277,
12,
859,
12,
859,
63,
493,
12,
9349,
2559,
9,
267,
340,
8876,
26,
288,
291,
855,
5334,
63,
1725,
14,
740,
8,
4984,
9,
267,
372,
4386,
12,
8876,
339,
347,
485,
362,
63,
576,
63,
1725,
8,
277,
304,
267,
408,
6864,
769,
402,
8189,
2491,
12,
2164,
63,
694,
12,
1506,
63,
694,
12,
10309,
3171,
6346,
624,
267,
291,
14,
21184,
63,
6418,
342,
267,
372,
769,
8,
1130,
8,
277,
423,
362,
63,
4600,
63,
576,
63,
1725,
12,
291,
14,
5154,
503,
334,
1724,
339,
347,
485,
362,
63,
4600,
63,
576,
63,
1725,
8,
277,
12,
2559,
304,
267,
327,
6263,
323,
2559,
1350,
2082,
267,
2928,
63,
694,
275,
291,
14,
362,
63,
2491,
63,
694,
8,
2491,
9,
398,
327,
8354,
2559,
1900,
2082,
267,
1900,
63,
694,
275,
747,
14,
515,
14,
904,
2031,
779,
277,
14,
1506,
63,
773,
61,
435,
2559,
14,
1294,
7563,
430,
398,
327,
19828,
2082,
687,
5739,
6123,
6203,
267,
6203,
275,
359,
288,
747,
14,
515,
14,
12405,
8,
493,
12,
2928,
63,
694,
9,
288,
367,
570,
315,
291,
14,
1623,
63,
576,
63,
1725,
8,
2491,
12,
2928,
63,
694,
9,
267,
1622,
267,
372,
2559,
12,
2928,
63,
694,
12,
1900,
63,
694,
12,
6203,
339,
347,
2342,
63,
576,
63,
1725,
8,
277,
12,
2559,
12,
2928,
63,
694,
304,
267,
408,
1767,
6203,
367,
2559,
1159,
666,
1584,
315,
283,
2164,
63,
694,
26555,
267,
13977,
275,
334,
277,
14,
2491,
63,
576,
14,
362,
8594,
3073,
326,
435,
291,
14,
2491,
63,
576,
14,
362,
8,
2491,
12,
15927,
267,
1584,
275,
291,
14,
6418,
63,
1725,
14,
362,
8,
2491,
12,
3073,
5873,
267,
367,
3851,
315,
13977,
26,
288,
327,
7048,
3851,
965,
370,
506,
6702,
370,
282,
4298,
13,
6100,
931,
288,
1584,
14,
2880,
8,
6463,
8,
736,
14,
515,
14,
904,
8,
2164,
63,
694,
12,
3957,
63,
515,
8,
3401,
7845,
267,
372,
291,
14,
5473,
63,
576,
63,
1725,
8,
2491,
12,
2928,
63,
694,
12,
1584,
9,
339,
347,
1900,
63,
2491,
63,
576,
8,
277,
304,
267,
408,
5116,
666,
1584,
1901,
1900,
2082,
624,
267,
367,
2559,
12,
2928,
63,
694,
12,
1900,
63,
694,
12,
6203,
315,
291,
14,
576,
63,
1725,
26,
288,
367,
1788,
315,
6203,
26,
355,
1347,
275,
747,
14,
515,
14,
904,
8,
1506,
63,
694,
12,
1788,
9,
355,
291,
14,
3880,
515,
8,
736,
14,
515,
14,
3475,
8,
1375,
430,
355,
2928,
493,
275,
747,
14,
515,
14,
904,
8,
2164,
63,
694,
12,
1788,
9,
355,
27552,
12,
8876
] |
[
5739,
492,
5739,
199,
504,
7065,
14,
1974,
492,
3957,
63,
515,
199,
646,
7065,
14,
1531,
14,
1506,
63,
647,
465,
2306,
199,
646,
747,
199,
646,
15951,
199,
646,
13390,
199,
646,
5890,
199,
646,
7065,
14,
2550,
199,
646,
5055,
199,
646,
7975,
199,
199,
504,
9116,
14,
18587,
14,
4174,
14,
4912,
492,
2341,
199,
199,
893,
26,
272,
687,
9116,
14,
773,
18,
475,
19,
63,
476,
492,
28438,
18,
475,
19,
199,
2590,
3545,
26,
272,
1021,
28438,
18,
475,
19,
26,
267,
347,
1255,
63,
18,
475,
19,
8,
277,
12,
1584,
12,
26721,
29,
549,
304,
288,
298,
1117,
6548,
2,
421,
199,
533,
1900,
63,
647,
8,
2981,
14,
1506,
63,
647,
12,
28438,
18,
475,
19,
304,
272,
408,
1327,
24384,
283,
1506,
63,
647,
7,
1414,
626,
6952,
666,
1584,
543,
6117,
339,
710,
666,
1584,
787,
2013,
4799,
282,
283,
2491,
63,
576,
7,
1423,
370,
283,
2758,
342,
1370,
272,
1666,
283,
13623,
14,
2686,
14,
8580,
7,
367,
1655,
2436,
14,
339,
6121,
12,
642,
1015,
402,
314,
283,
1506,
63,
647,
7,
1414,
6127,
1265,
370,
4165,
3865,
272,
283,
647,
63,
3112,
7,
436,
283,
5154,
7,
315,
314,
2011,
3272,
3439,
14,
272,
408,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
2306,
14,
1506,
63,
647,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
2491,
63,
576,
275,
291,
14,
4972,
14,
2491,
63,
576,
267,
291,
14,
5473,
63,
2491,
63,
576,
275,
334,
277,
14,
4972,
14,
5473,
63,
2491,
63,
576,
503,
3660,
5009,
267,
340,
283,
576,
63,
1725,
7,
315,
291,
855,
807,
10651,
288,
2150,
291,
855,
807,
23010,
576,
63,
1725,
418,
267,
291,
855,
5334,
63,
1725,
275,
942,
267,
291,
855,
1301,
2219,
63,
18,
475,
19,
275,
942,
339,
347,
1255,
8,
277,
304,
267,
408,
3425,
4621,
12,
6117,
12,
436,
1331,
666,
1584,
370,
1900,
2082,
624,
267,
340,
440,
291,
14,
647,
63,
3112,
436,
440,
291,
14,
5154,
26,
288,
372,
398,
340,
291,
14,
647,
63,
3112,
26,
288,
291,
14,
1506,
63,
3112,
342,
398,
340,
291,
14,
5154,
26,
288,
291,
14,
1506,
63,
5154,
342,
288,
291,
14,
1506,
63,
2491,
63,
576,
342,
398,
291,
14,
1065,
63,
18,
475,
19,
8,
277,
855,
5334,
63,
1725,
12,
756,
9,
267,
291,
14,
1065,
63,
18,
475,
19,
8,
277,
855,
5334,
63,
1725,
12,
715,
9,
267,
291,
14,
1065,
63,
18,
475,
19,
8,
277,
855,
1301,
2219,
63,
18,
475,
19,
12,
715,
9,
398,
327,
5972,
6555,
3503,
1275,
647,
1584,
12,
1808,
4154,
1300,
1021,
7,
16819,
402,
4052,
4154,
267,
327,
1072,
1584,
787,
14,
267,
291,
14,
4414,
63,
2014,
8,
2981,
14,
1506,
63,
647,
14,
362,
63,
4467,
8,
277,
12,
2387,
63,
19812,
29,
16,
430,
339,
347,
636,
5675,
721,
277,
12,
1921,
304,
267,
298,
416,
90,
3444,
4526,
666,
1584,
2,
267,
340,
1921,
508,
283,
576,
63,
1725,
356,
288,
291,
14,
576,
63,
1725,
275,
291,
423,
362,
63,
576,
63,
1725,
342,
288,
372,
291,
14,
576,
63,
1725,
267,
372,
2306,
14,
1506,
63,
647,
855,
5675,
721,
277,
12,
1921,
9,
339,
347,
1900,
63,
578,
8,
277,
12,
859,
12,
859,
63,
493,
12,
2559,
304,
267,
4386,
12,
8876,
275,
2306,
14,
1506,
63,
647,
14,
1506,
63,
578,
8,
277,
12,
859,
12,
859,
63,
493,
12,
9349,
2559,
9,
267,
340,
8876,
26,
288,
291,
855,
5334,
63,
1725,
14,
740,
8,
4984,
9,
267,
372,
4386,
12,
8876,
339,
347,
485,
362,
63,
576,
63,
1725,
8,
277,
304,
267,
408,
6864,
769,
402,
8189,
2491,
12,
2164,
63,
694,
12,
1506,
63,
694,
12,
10309,
3171,
6346,
624,
267,
291,
14,
21184,
63,
6418,
342,
267,
372,
769,
8,
1130,
8,
277,
423,
362,
63,
4600,
63,
576,
63,
1725,
12,
291,
14,
5154,
503,
334,
1724,
339,
347,
485,
362,
63,
4600,
63,
576,
63,
1725,
8,
277,
12,
2559,
304,
267,
327,
6263,
323,
2559,
1350,
2082,
267,
2928,
63,
694,
275,
291,
14,
362,
63,
2491,
63,
694,
8,
2491,
9,
398,
327,
8354,
2559,
1900,
2082,
267,
1900,
63,
694,
275,
747,
14,
515,
14,
904,
2031,
779,
277,
14,
1506,
63,
773,
61,
435,
2559,
14,
1294,
7563,
430,
398,
327,
19828,
2082,
687,
5739,
6123,
6203,
267,
6203,
275,
359,
288,
747,
14,
515,
14,
12405,
8,
493,
12,
2928,
63,
694,
9,
288,
367,
570,
315,
291,
14,
1623,
63,
576,
63,
1725,
8,
2491,
12,
2928,
63,
694,
9,
267,
1622,
267,
372,
2559,
12,
2928,
63,
694,
12,
1900,
63,
694,
12,
6203,
339,
347,
2342,
63,
576,
63,
1725,
8,
277,
12,
2559,
12,
2928,
63,
694,
304,
267,
408,
1767,
6203,
367,
2559,
1159,
666,
1584,
315,
283,
2164,
63,
694,
26555,
267,
13977,
275,
334,
277,
14,
2491,
63,
576,
14,
362,
8594,
3073,
326,
435,
291,
14,
2491,
63,
576,
14,
362,
8,
2491,
12,
15927,
267,
1584,
275,
291,
14,
6418,
63,
1725,
14,
362,
8,
2491,
12,
3073,
5873,
267,
367,
3851,
315,
13977,
26,
288,
327,
7048,
3851,
965,
370,
506,
6702,
370,
282,
4298,
13,
6100,
931,
288,
1584,
14,
2880,
8,
6463,
8,
736,
14,
515,
14,
904,
8,
2164,
63,
694,
12,
3957,
63,
515,
8,
3401,
7845,
267,
372,
291,
14,
5473,
63,
576,
63,
1725,
8,
2491,
12,
2928,
63,
694,
12,
1584,
9,
339,
347,
1900,
63,
2491,
63,
576,
8,
277,
304,
267,
408,
5116,
666,
1584,
1901,
1900,
2082,
624,
267,
367,
2559,
12,
2928,
63,
694,
12,
1900,
63,
694,
12,
6203,
315,
291,
14,
576,
63,
1725,
26,
288,
367,
1788,
315,
6203,
26,
355,
1347,
275,
747,
14,
515,
14,
904,
8,
1506,
63,
694,
12,
1788,
9,
355,
291,
14,
3880,
515,
8,
736,
14,
515,
14,
3475,
8,
1375,
430,
355,
2928,
493,
275,
747,
14,
515,
14,
904,
8,
2164,
63,
694,
12,
1788,
9,
355,
27552,
12,
8876,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gfyoung/pandas
|
pandas/tests/arrays/integer/test_function.py
|
5
|
6401
|
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
from pandas.core.arrays import FloatingArray
@pytest.mark.parametrize("ufunc", [np.abs, np.sign])
# np.sign emits a warning with nans, <https://github.com/numpy/numpy/issues/15127>
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign")
def test_ufuncs_single_int(ufunc):
a = pd.array([1, 2, -3, np.nan])
result = ufunc(a)
expected = pd.array(ufunc(a.astype(float)), dtype="Int64")
tm.assert_extension_array_equal(result, expected)
s = pd.Series(a)
result = ufunc(s)
expected = pd.Series(pd.array(ufunc(a.astype(float)), dtype="Int64"))
tm.assert_series_equal(result, expected)
@pytest.mark.parametrize("ufunc", [np.log, np.exp, np.sin, np.cos, np.sqrt])
def test_ufuncs_single_float(ufunc):
a = pd.array([1, 2, -3, np.nan])
with np.errstate(invalid="ignore"):
result = ufunc(a)
expected = FloatingArray(ufunc(a.astype(float)), mask=a._mask)
tm.assert_extension_array_equal(result, expected)
s = pd.Series(a)
with np.errstate(invalid="ignore"):
result = ufunc(s)
expected = pd.Series(expected)
tm.assert_series_equal(result, expected)
@pytest.mark.parametrize("ufunc", [np.add, np.subtract])
def test_ufuncs_binary_int(ufunc):
# two IntegerArrays
a = pd.array([1, 2, -3, np.nan])
result = ufunc(a, a)
expected = pd.array(ufunc(a.astype(float), a.astype(float)), dtype="Int64")
tm.assert_extension_array_equal(result, expected)
# IntegerArray with numpy array
arr = np.array([1, 2, 3, 4])
result = ufunc(a, arr)
expected = pd.array(ufunc(a.astype(float), arr), dtype="Int64")
tm.assert_extension_array_equal(result, expected)
result = ufunc(arr, a)
expected = pd.array(ufunc(arr, a.astype(float)), dtype="Int64")
tm.assert_extension_array_equal(result, expected)
# IntegerArray with scalar
result = ufunc(a, 1)
expected = pd.array(ufunc(a.astype(float), 1), dtype="Int64")
tm.assert_extension_array_equal(result, expected)
result = ufunc(1, a)
expected = pd.array(ufunc(1, a.astype(float)), dtype="Int64")
tm.assert_extension_array_equal(result, expected)
def test_ufunc_binary_output():
a = pd.array([1, 2, np.nan])
result = np.modf(a)
expected = np.modf(a.to_numpy(na_value=np.nan, dtype="float"))
expected = (pd.array(expected[0]), pd.array(expected[1]))
assert isinstance(result, tuple)
assert len(result) == 2
for x, y in zip(result, expected):
tm.assert_extension_array_equal(x, y)
@pytest.mark.parametrize("values", [[0, 1], [0, None]])
def test_ufunc_reduce_raises(values):
a = pd.array(values)
msg = r"The 'reduce' method is not supported."
with pytest.raises(NotImplementedError, match=msg):
np.add.reduce(a)
@pytest.mark.parametrize(
"pandasmethname, kwargs",
[
("var", {"ddof": 0}),
("var", {"ddof": 1}),
("kurtosis", {}),
("skew", {}),
("sem", {}),
],
)
def test_stat_method(pandasmethname, kwargs):
s = pd.Series(data=[1, 2, 3, 4, 5, 6, np.nan, np.nan], dtype="Int64")
pandasmeth = getattr(s, pandasmethname)
result = pandasmeth(**kwargs)
s2 = pd.Series(data=[1, 2, 3, 4, 5, 6], dtype="Int64")
pandasmeth = getattr(s2, pandasmethname)
expected = pandasmeth(**kwargs)
assert expected == result
def test_value_counts_na():
arr = pd.array([1, 2, 1, pd.NA], dtype="Int64")
result = arr.value_counts(dropna=False)
expected = pd.Series([2, 1, 1], index=[1, 2, pd.NA], dtype="Int64")
tm.assert_series_equal(result, expected)
result = arr.value_counts(dropna=True)
expected = pd.Series([2, 1], index=[1, 2], dtype="Int64")
tm.assert_series_equal(result, expected)
def test_value_counts_empty():
# https://github.com/pandas-dev/pandas/issues/33317
s = pd.Series([], dtype="Int64")
result = s.value_counts()
# TODO: The dtype of the index seems wrong (it's int64 for non-empty)
idx = pd.Index([], dtype="object")
expected = pd.Series([], index=idx, dtype="Int64")
tm.assert_series_equal(result, expected)
def test_value_counts_with_normalize():
# GH 33172
s = pd.Series([1, 2, 1, pd.NA], dtype="Int64")
result = s.value_counts(normalize=True)
expected = pd.Series([2, 1], index=[1, 2], dtype="Float64") / 3
tm.assert_series_equal(result, expected)
@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("min_count", [0, 4])
def test_integer_array_sum(skipna, min_count, any_nullable_int_dtype):
dtype = any_nullable_int_dtype
arr = pd.array([1, 2, 3, None], dtype=dtype)
result = arr.sum(skipna=skipna, min_count=min_count)
if skipna and min_count == 0:
assert result == 6
else:
assert result is pd.NA
@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("method", ["min", "max"])
def test_integer_array_min_max(skipna, method, any_nullable_int_dtype):
dtype = any_nullable_int_dtype
arr = pd.array([0, 1, None], dtype=dtype)
func = getattr(arr, method)
result = func(skipna=skipna)
if skipna:
assert result == (0 if method == "min" else 1)
else:
assert result is pd.NA
@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("min_count", [0, 9])
def test_integer_array_prod(skipna, min_count, any_nullable_int_dtype):
dtype = any_nullable_int_dtype
arr = pd.array([1, 2, None], dtype=dtype)
result = arr.prod(skipna=skipna, min_count=min_count)
if skipna and min_count == 0:
assert result == 2
else:
assert result is pd.NA
@pytest.mark.parametrize(
"values, expected", [([1, 2, 3], 6), ([1, 2, 3, None], 6), ([None], 0)]
)
def test_integer_array_numpy_sum(values, expected):
arr = pd.array(values, dtype="Int64")
result = np.sum(arr)
assert result == expected
@pytest.mark.parametrize("op", ["sum", "prod", "min", "max"])
def test_dataframe_reductions(op):
# https://github.com/pandas-dev/pandas/pull/32867
# ensure the integers are not cast to float during reductions
df = pd.DataFrame({"a": pd.array([1, 2], dtype="Int64")})
result = df.max()
assert isinstance(result["a"], np.int64)
# TODO(jreback) - these need testing / are broken
# shift
# set_index (destroys type)
|
bsd-3-clause
|
[
646,
2680,
465,
980,
199,
646,
4613,
199,
199,
646,
10634,
465,
6454,
199,
646,
10634,
423,
4776,
465,
7352,
199,
504,
10634,
14,
1018,
14,
10095,
492,
27729,
3836,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
18810,
401,
359,
1590,
14,
2101,
12,
980,
14,
1037,
566,
199,
3,
980,
14,
1037,
8689,
83,
282,
5721,
543,
302,
796,
12,
665,
2859,
921,
5031,
14,
957,
15,
4714,
15,
4714,
15,
10115,
15,
1046,
4195,
30,
199,
32,
4462,
14,
1657,
14,
23945,
480,
4247,
26,
3197,
574,
14556,
315,
2070,
531,
199,
318,
511,
63,
18810,
83,
63,
4780,
63,
442,
8,
18810,
304,
272,
282,
275,
6454,
14,
1144,
779,
17,
12,
499,
12,
446,
19,
12,
980,
14,
4304,
566,
272,
754,
275,
30149,
8,
65,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
308,
275,
6454,
14,
9641,
8,
65,
9,
272,
754,
275,
30149,
8,
83,
9,
272,
1420,
275,
6454,
14,
9641,
8,
8961,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
2237,
272,
7352,
14,
479,
63,
5602,
63,
1452,
8,
1099,
12,
1420,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
18810,
401,
359,
1590,
14,
793,
12,
980,
14,
1474,
12,
980,
14,
5911,
12,
980,
14,
5197,
12,
980,
14,
5079,
566,
199,
318,
511,
63,
18810,
83,
63,
4780,
63,
1609,
8,
18810,
304,
272,
282,
275,
6454,
14,
1144,
779,
17,
12,
499,
12,
446,
19,
12,
980,
14,
4304,
566,
272,
543,
980,
14,
1508,
929,
8,
3197,
628,
4247,
2349,
267,
754,
275,
30149,
8,
65,
9,
267,
1420,
275,
27729,
3836,
8,
18810,
8,
65,
14,
6041,
8,
1609,
1826,
3656,
29,
65,
423,
2629,
9,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
308,
275,
6454,
14,
9641,
8,
65,
9,
272,
543,
980,
14,
1508,
929,
8,
3197,
628,
4247,
2349,
267,
754,
275,
30149,
8,
83,
9,
272,
1420,
275,
6454,
14,
9641,
8,
2062,
9,
272,
7352,
14,
479,
63,
5602,
63,
1452,
8,
1099,
12,
1420,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
18810,
401,
359,
1590,
14,
525,
12,
980,
14,
25719,
566,
199,
318,
511,
63,
18810,
83,
63,
3008,
63,
442,
8,
18810,
304,
272,
327,
2877,
7225,
29033,
272,
282,
275,
6454,
14,
1144,
779,
17,
12,
499,
12,
446,
19,
12,
980,
14,
4304,
566,
272,
754,
275,
30149,
8,
65,
12,
282,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
395,
282,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
327,
7225,
3836,
543,
2680,
1625,
272,
7953,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
12,
841,
566,
272,
754,
275,
30149,
8,
65,
12,
7953,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
395,
7953,
395,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
754,
275,
30149,
8,
5250,
12,
282,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
5250,
12,
282,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
327,
7225,
3836,
543,
6917,
272,
754,
275,
30149,
8,
65,
12,
413,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
395,
413,
395,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
754,
275,
30149,
8,
17,
12,
282,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
17,
12,
282,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
421,
199,
318,
511,
63,
18810,
63,
3008,
63,
1199,
837,
272,
282,
275,
6454,
14,
1144,
779,
17,
12,
499,
12,
980,
14,
4304,
566,
272,
754,
275,
980,
14,
1494,
70,
8,
65,
9,
272,
1420,
275,
980,
14,
1494,
70,
8,
65,
14,
475,
63,
4714,
8,
3540,
63,
585,
29,
1590,
14,
4304,
12,
2152,
628,
1609,
2237,
272,
1420,
275,
334,
8961,
14,
1144,
8,
2062,
59,
16,
2522,
6454,
14,
1144,
8,
2062,
59,
17,
2459,
339,
702,
1228,
8,
1099,
12,
2008,
9,
272,
702,
822,
8,
1099,
9,
508,
499,
339,
367,
671,
12,
612,
315,
3482,
8,
1099,
12,
1420,
304,
267,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
88,
12,
612,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1459,
401,
3474,
16,
12,
413,
467,
359,
16,
12,
488,
3934,
199,
318,
511,
63,
18810,
63,
5270,
63,
3536,
8,
1459,
304,
272,
282,
275,
6454,
14,
1144,
8,
1459,
9,
272,
1499,
275,
519,
2,
1918,
283,
5270,
7,
1083,
365,
440,
3748,
2122,
272,
543,
4613,
14,
3536,
8,
18097,
12,
1336,
29,
1328,
304,
267,
980,
14,
525,
14,
5270,
8,
65,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
298,
15718,
5247,
354,
12,
2074,
401,
272,
359,
267,
1689,
1391,
401,
2420,
617,
1618,
582,
378,
8688,
267,
1689,
1391,
401,
2420,
617,
1618,
582,
413,
8688,
267,
1689,
75,
32746,
401,
8613,
267,
1689,
27424,
401,
8613,
267,
1689,
21678,
401,
8613,
272,
2156,
199,
9,
199,
318,
511,
63,
3736,
63,
765,
8,
15718,
5247,
354,
12,
2074,
304,
272,
308,
275,
6454,
14,
9641,
8,
576,
1524,
17,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
980,
14,
4304,
12,
980,
14,
4304,
467,
2152,
628,
3241,
772,
531,
272,
10634,
5247,
275,
2519,
8,
83,
12,
10634,
5247,
354
] |
[
2680,
465,
980,
199,
646,
4613,
199,
199,
646,
10634,
465,
6454,
199,
646,
10634,
423,
4776,
465,
7352,
199,
504,
10634,
14,
1018,
14,
10095,
492,
27729,
3836,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
18810,
401,
359,
1590,
14,
2101,
12,
980,
14,
1037,
566,
199,
3,
980,
14,
1037,
8689,
83,
282,
5721,
543,
302,
796,
12,
665,
2859,
921,
5031,
14,
957,
15,
4714,
15,
4714,
15,
10115,
15,
1046,
4195,
30,
199,
32,
4462,
14,
1657,
14,
23945,
480,
4247,
26,
3197,
574,
14556,
315,
2070,
531,
199,
318,
511,
63,
18810,
83,
63,
4780,
63,
442,
8,
18810,
304,
272,
282,
275,
6454,
14,
1144,
779,
17,
12,
499,
12,
446,
19,
12,
980,
14,
4304,
566,
272,
754,
275,
30149,
8,
65,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
308,
275,
6454,
14,
9641,
8,
65,
9,
272,
754,
275,
30149,
8,
83,
9,
272,
1420,
275,
6454,
14,
9641,
8,
8961,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
2237,
272,
7352,
14,
479,
63,
5602,
63,
1452,
8,
1099,
12,
1420,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
18810,
401,
359,
1590,
14,
793,
12,
980,
14,
1474,
12,
980,
14,
5911,
12,
980,
14,
5197,
12,
980,
14,
5079,
566,
199,
318,
511,
63,
18810,
83,
63,
4780,
63,
1609,
8,
18810,
304,
272,
282,
275,
6454,
14,
1144,
779,
17,
12,
499,
12,
446,
19,
12,
980,
14,
4304,
566,
272,
543,
980,
14,
1508,
929,
8,
3197,
628,
4247,
2349,
267,
754,
275,
30149,
8,
65,
9,
267,
1420,
275,
27729,
3836,
8,
18810,
8,
65,
14,
6041,
8,
1609,
1826,
3656,
29,
65,
423,
2629,
9,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
308,
275,
6454,
14,
9641,
8,
65,
9,
272,
543,
980,
14,
1508,
929,
8,
3197,
628,
4247,
2349,
267,
754,
275,
30149,
8,
83,
9,
272,
1420,
275,
6454,
14,
9641,
8,
2062,
9,
272,
7352,
14,
479,
63,
5602,
63,
1452,
8,
1099,
12,
1420,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
18810,
401,
359,
1590,
14,
525,
12,
980,
14,
25719,
566,
199,
318,
511,
63,
18810,
83,
63,
3008,
63,
442,
8,
18810,
304,
272,
327,
2877,
7225,
29033,
272,
282,
275,
6454,
14,
1144,
779,
17,
12,
499,
12,
446,
19,
12,
980,
14,
4304,
566,
272,
754,
275,
30149,
8,
65,
12,
282,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
395,
282,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
327,
7225,
3836,
543,
2680,
1625,
272,
7953,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
12,
841,
566,
272,
754,
275,
30149,
8,
65,
12,
7953,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
395,
7953,
395,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
754,
275,
30149,
8,
5250,
12,
282,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
5250,
12,
282,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
327,
7225,
3836,
543,
6917,
272,
754,
275,
30149,
8,
65,
12,
413,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
65,
14,
6041,
8,
1609,
395,
413,
395,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
339,
754,
275,
30149,
8,
17,
12,
282,
9,
272,
1420,
275,
6454,
14,
1144,
8,
18810,
8,
17,
12,
282,
14,
6041,
8,
1609,
1826,
2152,
628,
3241,
772,
531,
272,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
1099,
12,
1420,
9,
421,
199,
318,
511,
63,
18810,
63,
3008,
63,
1199,
837,
272,
282,
275,
6454,
14,
1144,
779,
17,
12,
499,
12,
980,
14,
4304,
566,
272,
754,
275,
980,
14,
1494,
70,
8,
65,
9,
272,
1420,
275,
980,
14,
1494,
70,
8,
65,
14,
475,
63,
4714,
8,
3540,
63,
585,
29,
1590,
14,
4304,
12,
2152,
628,
1609,
2237,
272,
1420,
275,
334,
8961,
14,
1144,
8,
2062,
59,
16,
2522,
6454,
14,
1144,
8,
2062,
59,
17,
2459,
339,
702,
1228,
8,
1099,
12,
2008,
9,
272,
702,
822,
8,
1099,
9,
508,
499,
339,
367,
671,
12,
612,
315,
3482,
8,
1099,
12,
1420,
304,
267,
7352,
14,
479,
63,
3435,
63,
1144,
63,
1452,
8,
88,
12,
612,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1459,
401,
3474,
16,
12,
413,
467,
359,
16,
12,
488,
3934,
199,
318,
511,
63,
18810,
63,
5270,
63,
3536,
8,
1459,
304,
272,
282,
275,
6454,
14,
1144,
8,
1459,
9,
272,
1499,
275,
519,
2,
1918,
283,
5270,
7,
1083,
365,
440,
3748,
2122,
272,
543,
4613,
14,
3536,
8,
18097,
12,
1336,
29,
1328,
304,
267,
980,
14,
525,
14,
5270,
8,
65,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
298,
15718,
5247,
354,
12,
2074,
401,
272,
359,
267,
1689,
1391,
401,
2420,
617,
1618,
582,
378,
8688,
267,
1689,
1391,
401,
2420,
617,
1618,
582,
413,
8688,
267,
1689,
75,
32746,
401,
8613,
267,
1689,
27424,
401,
8613,
267,
1689,
21678,
401,
8613,
272,
2156,
199,
9,
199,
318,
511,
63,
3736,
63,
765,
8,
15718,
5247,
354,
12,
2074,
304,
272,
308,
275,
6454,
14,
9641,
8,
576,
1524,
17,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
980,
14,
4304,
12,
980,
14,
4304,
467,
2152,
628,
3241,
772,
531,
272,
10634,
5247,
275,
2519,
8,
83,
12,
10634,
5247,
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,
1,
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
] |
varunarya10/tempest
|
tempest/api/identity/admin/v3/test_projects_negative.py
|
9
|
3528
|
# Copyright 2013 OpenStack, LLC
# 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 tempest_lib import exceptions as lib_exc
from tempest.api.identity import base
from tempest.common.utils import data_utils
from tempest import test
class ProjectsNegativeTestJSON(base.BaseIdentityV3AdminTest):
@test.attr(type=['negative'])
@test.idempotent_id('24c49279-45dd-4155-887a-cb738c2385aa')
def test_list_projects_by_unauthorized_user(self):
# Non-admin user should not be able to list projects
self.assertRaises(lib_exc.Forbidden,
self.non_admin_client.list_projects)
@test.attr(type=['negative'])
@test.idempotent_id('874c3e84-d174-4348-a16b-8c01f599561b')
def test_project_create_duplicate(self):
# Project names should be unique
project_name = data_utils.rand_name('project-dup')
project = self.client.create_project(project_name)
self.data.projects.append(project)
self.assertRaises(
lib_exc.Conflict, self.client.create_project, project_name)
@test.attr(type=['negative'])
@test.idempotent_id('8fba9de2-3e1f-4e77-812a-60cb68f8df13')
def test_create_project_by_unauthorized_user(self):
# Non-admin user should not be authorized to create a project
project_name = data_utils.rand_name('project')
self.assertRaises(
lib_exc.Forbidden, self.non_admin_client.create_project,
project_name)
@test.attr(type=['negative'])
@test.idempotent_id('7828db17-95e5-475b-9432-9a51b4aa79a9')
def test_create_project_with_empty_name(self):
# Project name should not be empty
self.assertRaises(lib_exc.BadRequest, self.client.create_project,
name='')
@test.attr(type=['negative'])
@test.idempotent_id('502b6ceb-b0c8-4422-bf53-f08fdb21e2f0')
def test_create_projects_name_length_over_64(self):
# Project name length should not be greater than 64 characters
project_name = 'a' * 65
self.assertRaises(lib_exc.BadRequest, self.client.create_project,
project_name)
@test.attr(type=['negative'])
@test.idempotent_id('8d68c012-89e0-4394-8d6b-ccd7196def97')
def test_project_delete_by_unauthorized_user(self):
# Non-admin user should not be able to delete a project
project_name = data_utils.rand_name('project')
project = self.client.create_project(project_name)
self.data.projects.append(project)
self.assertRaises(
lib_exc.Forbidden, self.non_admin_client.delete_project,
project['id'])
@test.attr(type=['negative'])
@test.idempotent_id('7965b581-60c1-43b7-8169-95d4ab7fc6fb')
def test_delete_non_existent_project(self):
# Attempt to delete a non existent project should fail
self.assertRaises(lib_exc.NotFound, self.client.delete_project,
data_utils.rand_uuid_hex())
|
apache-2.0
|
[
3,
1898,
6171,
14260,
12,
20376,
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,
24076,
63,
773,
492,
4967,
465,
1973,
63,
2804,
199,
199,
504,
24076,
14,
1246,
14,
5582,
492,
1300,
199,
504,
24076,
14,
2330,
14,
1208,
492,
666,
63,
1208,
199,
504,
24076,
492,
511,
421,
199,
533,
7290,
83,
15562,
774,
6243,
8,
1095,
14,
1563,
10193,
54,
19,
4880,
774,
304,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
1194,
67,
1887,
12987,
13,
2322,
617,
13,
20,
11520,
13,
15989,
65,
13,
2894,
23,
1703,
67,
12332,
21,
2158,
358,
272,
347,
511,
63,
513,
63,
6776,
63,
991,
63,
324,
11497,
63,
751,
8,
277,
304,
267,
327,
10172,
13,
2113,
922,
1077,
440,
506,
7688,
370,
769,
11336,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
17454,
12,
2079,
291,
14,
2865,
63,
2113,
63,
1258,
14,
513,
63,
6776,
9,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
28664,
67,
19,
69,
1349,
13,
68,
9892,
13,
20,
13442,
13,
65,
975,
66,
13,
24,
67,
614,
70,
30859,
17538,
66,
358,
272,
347,
511,
63,
1715,
63,
981,
63,
11081,
8,
277,
304,
267,
327,
7290,
1561,
1077,
506,
3747,
267,
2199,
63,
354,
275,
666,
63,
1208,
14,
3759,
63,
354,
360,
1715,
13,
11048,
358,
267,
2199,
275,
291,
14,
1258,
14,
981,
63,
1715,
8,
1715,
63,
354,
9,
267,
291,
14,
576,
14,
6776,
14,
740,
8,
1715,
9,
398,
291,
14,
1855,
8,
288,
1973,
63,
2804,
14,
15919,
12,
291,
14,
1258,
14,
981,
63,
1715,
12,
2199,
63,
354,
9,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
24,
70,
2470,
25,
271,
18,
13,
19,
69,
17,
70,
13,
20,
69,
1138,
13,
29601,
65,
13,
2259,
2894,
2333,
70,
24,
1587,
969,
358,
272,
347,
511,
63,
981,
63,
1715,
63,
991,
63,
324,
11497,
63,
751,
8,
277,
304,
267,
327,
10172,
13,
2113,
922,
1077,
440,
506,
18788,
370,
1218,
282,
2199,
267,
2199,
63,
354,
275,
666,
63,
1208,
14,
3759,
63,
354,
360,
1715,
358,
267,
291,
14,
1855,
8,
288,
1973,
63,
2804,
14,
17454,
12,
291,
14,
2865,
63,
2113,
63,
1258,
14,
981,
63,
1715,
12,
288,
2199,
63,
354,
9,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
2277,
1651,
697,
1196,
13,
2720,
69,
21,
13,
30494,
66,
13,
2635,
708,
13,
25,
65,
2869,
66,
20,
2158,
1965,
65,
25,
358,
272,
347,
511,
63,
981,
63,
1715,
63,
1045,
63,
1667,
63,
354,
8,
277,
304,
267,
327,
7290,
536,
1077,
440,
506,
2701,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
12380,
12,
291,
14,
1258,
14,
981,
63,
1715,
12,
2079,
536,
13275,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
24653,
66,
22,
301,
66,
13,
66,
16,
67,
24,
13,
1602,
1081,
13,
4361,
2481,
13,
70,
2036,
29636,
2025,
69,
18,
70,
16,
358,
272,
347,
511,
63,
981,
63,
6776,
63,
354,
63,
1267,
63,
1883,
63,
772,
8,
277,
304,
267,
327,
7290,
536,
2582,
1077,
440,
506,
8932,
2419,
5049,
4110,
267,
2199,
63,
354,
275,
283,
65,
7,
627,
11738,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
12380,
12,
291,
14,
1258,
14,
981,
63,
1715,
12,
2079,
2199,
63,
354,
9,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
24,
68,
2333,
67,
11533,
13,
1407,
69,
16,
13,
20,
13549,
13,
24,
68,
22,
66,
13,
30013,
23,
10800,
318,
2576,
358,
272,
347,
511,
63,
1715,
63,
1807,
63,
991,
63,
324,
11497,
63,
751,
8,
277,
304,
267,
327,
10172,
13,
2113,
922,
1077,
440,
506,
7688,
370,
3145,
282,
2199,
267,
2199,
63,
354,
275,
666,
63,
1208,
14,
3759,
63,
354,
360,
1715,
358,
267,
2199,
275,
291,
14,
1258,
14,
981,
63,
1715,
8,
1715,
63,
354,
9,
267,
291,
14,
576,
14,
6776,
14,
740,
8,
1715,
9,
267,
291,
14,
1855,
8,
288,
1973,
63,
2804,
14,
17454,
12,
291,
14,
2865,
63,
2113,
63,
1258,
14,
1807,
63,
1715,
12,
288,
2199,
459,
344,
1105,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
1965,
2182,
66,
18844,
13,
2259,
67,
17,
13,
2824,
66,
23,
13,
24,
10143,
13,
2720,
68,
20,
371,
23,
3003,
22,
4675,
358,
272,
347,
511,
63,
1807,
63,
2865,
63,
15025,
63,
1715,
8,
277,
304,
267,
327,
23115,
370,
3145,
282,
2222,
444,
13298,
2199,
1077,
2449,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
4667,
12,
291,
14,
1258,
14,
1807,
63,
1715,
12,
2079,
666,
63,
1208,
14,
3759,
63,
2580,
63,
4097,
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
] |
[
1898,
6171,
14260,
12,
20376,
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,
24076,
63,
773,
492,
4967,
465,
1973,
63,
2804,
199,
199,
504,
24076,
14,
1246,
14,
5582,
492,
1300,
199,
504,
24076,
14,
2330,
14,
1208,
492,
666,
63,
1208,
199,
504,
24076,
492,
511,
421,
199,
533,
7290,
83,
15562,
774,
6243,
8,
1095,
14,
1563,
10193,
54,
19,
4880,
774,
304,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
1194,
67,
1887,
12987,
13,
2322,
617,
13,
20,
11520,
13,
15989,
65,
13,
2894,
23,
1703,
67,
12332,
21,
2158,
358,
272,
347,
511,
63,
513,
63,
6776,
63,
991,
63,
324,
11497,
63,
751,
8,
277,
304,
267,
327,
10172,
13,
2113,
922,
1077,
440,
506,
7688,
370,
769,
11336,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
17454,
12,
2079,
291,
14,
2865,
63,
2113,
63,
1258,
14,
513,
63,
6776,
9,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
28664,
67,
19,
69,
1349,
13,
68,
9892,
13,
20,
13442,
13,
65,
975,
66,
13,
24,
67,
614,
70,
30859,
17538,
66,
358,
272,
347,
511,
63,
1715,
63,
981,
63,
11081,
8,
277,
304,
267,
327,
7290,
1561,
1077,
506,
3747,
267,
2199,
63,
354,
275,
666,
63,
1208,
14,
3759,
63,
354,
360,
1715,
13,
11048,
358,
267,
2199,
275,
291,
14,
1258,
14,
981,
63,
1715,
8,
1715,
63,
354,
9,
267,
291,
14,
576,
14,
6776,
14,
740,
8,
1715,
9,
398,
291,
14,
1855,
8,
288,
1973,
63,
2804,
14,
15919,
12,
291,
14,
1258,
14,
981,
63,
1715,
12,
2199,
63,
354,
9,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
24,
70,
2470,
25,
271,
18,
13,
19,
69,
17,
70,
13,
20,
69,
1138,
13,
29601,
65,
13,
2259,
2894,
2333,
70,
24,
1587,
969,
358,
272,
347,
511,
63,
981,
63,
1715,
63,
991,
63,
324,
11497,
63,
751,
8,
277,
304,
267,
327,
10172,
13,
2113,
922,
1077,
440,
506,
18788,
370,
1218,
282,
2199,
267,
2199,
63,
354,
275,
666,
63,
1208,
14,
3759,
63,
354,
360,
1715,
358,
267,
291,
14,
1855,
8,
288,
1973,
63,
2804,
14,
17454,
12,
291,
14,
2865,
63,
2113,
63,
1258,
14,
981,
63,
1715,
12,
288,
2199,
63,
354,
9,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
2277,
1651,
697,
1196,
13,
2720,
69,
21,
13,
30494,
66,
13,
2635,
708,
13,
25,
65,
2869,
66,
20,
2158,
1965,
65,
25,
358,
272,
347,
511,
63,
981,
63,
1715,
63,
1045,
63,
1667,
63,
354,
8,
277,
304,
267,
327,
7290,
536,
1077,
440,
506,
2701,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
12380,
12,
291,
14,
1258,
14,
981,
63,
1715,
12,
2079,
536,
13275,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
24653,
66,
22,
301,
66,
13,
66,
16,
67,
24,
13,
1602,
1081,
13,
4361,
2481,
13,
70,
2036,
29636,
2025,
69,
18,
70,
16,
358,
272,
347,
511,
63,
981,
63,
6776,
63,
354,
63,
1267,
63,
1883,
63,
772,
8,
277,
304,
267,
327,
7290,
536,
2582,
1077,
440,
506,
8932,
2419,
5049,
4110,
267,
2199,
63,
354,
275,
283,
65,
7,
627,
11738,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
12380,
12,
291,
14,
1258,
14,
981,
63,
1715,
12,
2079,
2199,
63,
354,
9,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
24,
68,
2333,
67,
11533,
13,
1407,
69,
16,
13,
20,
13549,
13,
24,
68,
22,
66,
13,
30013,
23,
10800,
318,
2576,
358,
272,
347,
511,
63,
1715,
63,
1807,
63,
991,
63,
324,
11497,
63,
751,
8,
277,
304,
267,
327,
10172,
13,
2113,
922,
1077,
440,
506,
7688,
370,
3145,
282,
2199,
267,
2199,
63,
354,
275,
666,
63,
1208,
14,
3759,
63,
354,
360,
1715,
358,
267,
2199,
275,
291,
14,
1258,
14,
981,
63,
1715,
8,
1715,
63,
354,
9,
267,
291,
14,
576,
14,
6776,
14,
740,
8,
1715,
9,
267,
291,
14,
1855,
8,
288,
1973,
63,
2804,
14,
17454,
12,
291,
14,
2865,
63,
2113,
63,
1258,
14,
1807,
63,
1715,
12,
288,
2199,
459,
344,
1105,
339,
768,
396,
14,
962,
8,
466,
2968,
7371,
1105,
272,
768,
396,
14,
21307,
63,
344,
360,
1965,
2182,
66,
18844,
13,
2259,
67,
17,
13,
2824,
66,
23,
13,
24,
10143,
13,
2720,
68,
20,
371,
23,
3003,
22,
4675,
358,
272,
347,
511,
63,
1807,
63,
2865,
63,
15025,
63,
1715,
8,
277,
304,
267,
327,
23115,
370,
3145,
282,
2222,
444,
13298,
2199,
1077,
2449,
267,
291,
14,
1855,
8,
773,
63,
2804,
14,
4667,
12,
291,
14,
1258,
14,
1807,
63,
1715,
12,
2079,
666,
63,
1208,
14,
3759,
63,
2580,
63,
4097,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dnephin/openLETS
|
src/openlets/core/db.py
|
1
|
7160
|
"""
Database Acess Layer
"""
import datetime
import itertools
import operator
from django.db.models import Q
from django.db import transaction
from django.core.exceptions import ObjectDoesNotExist
from openlets.core import models
def get_balance(persona, personb, currency):
"""Load a balance between two persons.
"""
return (models.PersonBalance.objects
.select_related(
'balance'
'balance__persons'
)
.get(
person=persona,
balance__persons=personb,
balance__currency=currency
).balance
)
def get_balances(user, include_balanced=False, credited=None):
"""Get the list of balances for a user. Filter out any where the value is
back to 0.
"""
q = models.PersonBalance.objects.filter(person=user.person)
if not include_balanced:
q = q.exclude(balance__value=0)
if credited is not None:
q = q.filter(credited=credited)
return q
def get_balances_many(persons, currency, credited, include_balanced=False):
"""Return a map of person -> balances."""
q = models.PersonBalance.objects.filter(
person__in=persons,
credited=credited,
balance__currency=currency
)
if not include_balanced:
q = q.exclude(balance__value=0)
return q
def get_pending_trans_for_user(user):
"""Get pending transactions for a user which were
created by some other user, and need to be accepted.
"""
return models.TransactionRecord.objects.filter(
target_person=user.person,
transaction__isnull=True,
rejected=False
)
def get_recent_trans_for_user(user, days=10, limit=15, pending_only=False):
"""Get recent transaction records for the user. These transaction records
may be confirmed.
"""
earliest_day = datetime.date.today() - datetime.timedelta(days)
q = models.TransactionRecord.objects.filter(
creator_person=user.person,
time_created__gte=earliest_day
)
if pending_only:
q = q.filter(transaction__isnull=True)
return q.order_by('-transaction_time')[:limit]
def get_exchange_rates(user):
"""Get exchange rates for the user."""
return models.ExchangeRate.objects.filter(
person=user.person
)
# TODO: tests
def get_transfer_history(user, filters):
"""Get a list of all transactions and resolutions for the user filtered
by form filters.
"""
query_sets = []
resolution_query, trans_query = [], []
now = datetime.datetime.now()
def conv(key, trans, resolution, coerce_val=None):
"""Helper to setup filters for both tables."""
val = filters.get(key)
if not val:
return
if coerce_val:
val = coerce_val(val)
if trans:
trans_query.append((trans, val))
if resolution:
resolution_query.append((resolution, val))
# Setup filters
transfer_type = filters.get('transfer_type')
conv('person', 'target_person', 'resolution__persons')
conv('transaction_type', 'from_receiver', 'credited', lambda x: x == 'charge')
conv('currency', 'currency', 'resolution__currency')
if filters.get('status') == 'rejected':
conv('status', 'rejected', None, lambda x: True)
else:
conv('status',
'transaction__time_confirmed__isnull',
'resolution__time_confirmed__isnull',
lambda x: x == 'pending'
)
conv('transaction_time',
'transaction_time__gt',
'resolution__time_confirmed__gt',
lambda d: now - datetime.timedelta(days=d)
)
conv('confirmed_time',
'transaction__time_confirmed__gt',
'resolution__time_confirmed__gt',
lambda d: now - datetime.timedelta(days=d)
)
# Query Transactions
if not transfer_type or transfer_type == 'transaction':
query_sets.append(models.TransactionRecord.objects.filter(
creator_person=user.person,
**dict(trans_query)
))
# Query Resolutions
if not transfer_type or transfer_type == 'resolution':
query_sets.append(models.PersonResolution.objects.filter(
person=user.person,
**dict(resolution_query)
))
# Merge results
return sorted(
itertools.chain.from_iterable(query_sets),
key=operator.attrgetter('transaction_time'),
reverse=True
)
def get_trans_record_for_user(trans_record_id, user):
"""Get a transaction record for a user."""
return models.TransactionRecord.objects.get(
id=trans_record_id,
target_person=user.person,
rejected=False
)
@transaction.commit_on_success
def reject_trans_record(trans_record_id, user):
"""Reject a transaction record where the user is the target."""
trans_record = get_trans_record_for_user(trans_record_id, user)
trans_record.rejected = True
trans_record.save()
@transaction.commit_on_success
def confirm_trans_record(trans_record):
"""Confirm a transaction record."""
# Build and save matching record
confirm_record = models.TransactionRecord(
creator_person=trans_record.target_person,
target_person=trans_record.creator_person,
from_receiver=not trans_record.from_receiver,
currency=trans_record.currency,
transaction_time=trans_record.transaction_time,
value=trans_record.value
)
transaction = models.Transaction()
transaction.save()
confirm_record.transaction_id = trans_record.transaction_id = transaction.id
confirm_record.save()
trans_record.save()
# Update the balance, or create a new one
update_balance(
trans_record,
trans_record.provider,
trans_record.receiver
)
# TODO: tests!
def update_balance(currency_type, provider, receiver):
"""Update or create a balance between two users for a currency. Should be
called from a method that was already created a transfer.
"""
try:
balance = get_balance(provider, receiver, currency=currency_type.currency)
except ObjectDoesNotExist:
return new_balance(currency_type, provider, receiver)
# Establish the direction of the transfer
if provider == balance.debted:
balance.value += currency_type.value
balance.save()
return balance
balance.value -= currency_type.value
if (balance.value) < 0:
balance.value = abs(balance.value)
for personbalance in balance.personbalance_set.all():
personbalance.credited = not personbalance.credited
personbalance.save()
balance.save()
# TODO: does this cascade to the personbalance ?
return balance
# TODO: tests
def new_balance(currency_type, provider, receiver):
balance = models.Balance(
currency=currency_type.currency,
value=currency_type.value
)
balance.save()
personbalancea = models.PersonBalance(
person=provider,
credited=False,
balance=balance
)
personbalanceb = models.PersonBalance(
person=receiver,
credited=True,
balance=balance
)
personbalancea.save()
personbalanceb.save()
balance.save()
return balance
def get_transaction_count(user):
"""Get a count of transaction records by this user."""
return models.TransactionRecord.objects.filter(
creator_person=user.person
).count()
def get_transaction_notifications(user, days=2):
"""Get recent transaction actions targetted at the user."""
now = datetime.datetime.now()
return models.TransactionRecord.objects.filter(
target_person=user.person,
time_created__gte=now - datetime.timedelta(days=days)
)
def get_recent_resolutions(user, days=2):
"""Get recent resolutions involsing the user."""
now = datetime.datetime.now()
return models.PersonResolution.objects.filter(
person=user.person,
resolution__time_confirmed__gte=now - datetime.timedelta(days=days)
)
|
bsd-3-clause
|
[
624,
199,
7243,
437,
670,
11915,
199,
624,
199,
646,
2197,
199,
646,
7975,
199,
646,
4182,
199,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
504,
1639,
14,
697,
492,
6008,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
199,
504,
1551,
16537,
14,
1018,
492,
1709,
199,
199,
318,
664,
63,
7358,
8,
5484,
65,
12,
4954,
66,
12,
9952,
304,
199,
198,
624,
6200,
282,
14094,
3382,
2877,
12103,
14,
9948,
198,
624,
199,
198,
1107,
334,
992,
14,
7344,
27106,
14,
1462,
507,
198,
14,
2416,
63,
2407,
8,
686,
198,
7,
7358,
7,
686,
198,
7,
7358,
363,
32146,
7,
507,
198,
9,
507,
198,
14,
362,
8,
686,
198,
5484,
29,
5484,
65,
12,
686,
198,
7358,
363,
32146,
29,
5484,
66,
12,
686,
198,
7358,
363,
4968,
29,
4968,
507,
198,
680,
7358,
199,
198,
9,
199,
199,
318,
664,
63,
7358,
83,
8,
751,
12,
2387,
63,
18923,
29,
797,
12,
2837,
328,
471,
29,
403,
304,
199,
198,
624,
1002,
314,
769,
402,
8091,
13236,
367,
282,
922,
14,
9388,
734,
1263,
2382,
314,
574,
365,
199,
198,
894,
370,
378,
14,
199,
198,
624,
199,
198,
81,
275,
1709,
14,
7344,
27106,
14,
1462,
14,
1541,
8,
5484,
29,
751,
14,
5484,
9,
199,
198,
692,
440,
2387,
63,
18923,
26,
507,
198,
81,
275,
1894,
14,
5473,
8,
7358,
363,
585,
29,
16,
9,
199,
198,
692,
2837,
328,
471,
365,
440,
488,
26,
507,
198,
81,
275,
1894,
14,
1541,
8,
1353,
328,
471,
29,
1353,
328,
471,
9,
199,
198,
1107,
1894,
199,
199,
318,
664,
63,
7358,
83,
63,
3479,
8,
32146,
12,
9952,
12,
2837,
328,
471,
12,
2387,
63,
18923,
29,
797,
304,
199,
198,
624,
1767,
282,
2341,
402,
4954,
1035,
8091,
13236,
1041,
199,
198,
81,
275,
1709,
14,
7344,
27106,
14,
1462,
14,
1541,
8,
507,
198,
5484,
363,
262,
29,
32146,
12,
507,
198,
1353,
328,
471,
29,
1353,
328,
471,
12,
507,
198,
7358,
363,
4968,
29,
4968,
199,
198,
9,
199,
198,
692,
440,
2387,
63,
18923,
26,
507,
198,
81,
275,
1894,
14,
5473,
8,
7358,
363,
585,
29,
16,
9,
199,
198,
1107,
1894,
199,
199,
318,
664,
63,
6455,
63,
1515,
63,
509,
63,
751,
8,
751,
304,
199,
198,
624,
1002,
9413,
15809,
367,
282,
922,
1314,
4898,
199,
198,
3966,
701,
2005,
1163,
922,
12,
436,
1929,
370,
506,
10226,
14,
199,
198,
624,
199,
198,
1107,
1709,
14,
10161,
5433,
14,
1462,
14,
1541,
8,
507,
198,
1375,
63,
5484,
29,
751,
14,
5484,
12,
507,
198,
5945,
363,
15114,
29,
549,
12,
507,
198,
24054,
29,
797,
199,
198,
9,
199,
199,
318,
664,
63,
14951,
63,
1515,
63,
509,
63,
751,
8,
751,
12,
7609,
29,
709,
12,
2304,
29,
1046,
12,
9413,
63,
2118,
29,
797,
304,
199,
198,
624,
1002,
8058,
6008,
5767,
367,
314,
922,
14,
221,
5723,
6008,
5767,
199,
198,
7551,
506,
22763,
14,
199,
198,
624,
199,
198,
2210,
24951,
63,
2977,
275,
2197,
14,
602,
14,
8136,
342,
446,
2197,
14,
7473,
8,
4899,
9,
199,
198,
81,
275,
1709,
14,
10161,
5433,
14,
1462,
14,
1541,
8,
507,
198,
9986,
63,
5484,
29,
751,
14,
5484,
12,
507,
198,
521,
63,
3966,
363,
19586,
29,
2210,
24951,
63,
2977,
199,
198,
9,
421,
198,
692,
9413,
63,
2118,
26,
507,
198,
81,
275,
1894,
14,
1541,
8,
5945,
363,
15114,
29,
549,
9,
421,
198,
1107,
1894,
14,
1648,
63,
991,
3654,
5945,
63,
521,
358,
1491,
3097,
61,
199,
199,
318,
664,
63,
14197,
63,
17153,
8,
751,
304,
199,
198,
624,
1002,
15343,
24434,
367,
314,
922,
1041,
199,
198,
1107,
1709,
14,
13188,
6621,
14,
1462,
14,
1541,
8,
507,
198,
5484,
29,
751,
14,
5484,
199,
198,
9,
421,
199,
3,
3254,
26,
2295,
199,
318,
664,
63,
9609,
63,
5570,
8,
751,
12,
4766,
304,
199,
198,
624,
1002,
282,
769,
402,
1006,
15809,
436,
17416,
8653,
367,
314,
922,
9806,
199,
198,
991,
1824,
4766,
14,
199,
198,
624,
199,
198,
1131,
63,
2193,
275,
942,
199,
198,
12588,
63,
1131,
12,
1752,
63,
1131,
275,
990,
942,
199,
198,
2131,
275,
2197,
14,
2083,
14,
2131,
342,
421,
198,
318,
8260,
8,
498,
12,
1752,
12,
12401,
12,
19874,
63,
637,
29,
403,
304,
507,
198,
624,
4433,
370,
3272,
4766,
367,
3865,
6716,
1041,
507,
198,
637,
275,
4766,
14,
362,
8,
498,
9,
507,
198,
692,
440,
1139,
26,
686,
198,
1107,
507,
198,
692,
19874,
63,
637,
26,
686,
198,
637,
275,
19874,
63,
637,
8,
637,
9,
507,
198,
692,
1752,
26,
686,
198,
1515,
63,
1131,
14,
740,
1332,
1515,
12,
1139,
430,
507,
198,
692,
12401,
26,
686,
198,
12588,
63,
1131,
14,
740,
1332,
12588,
12,
1139,
430,
421,
198,
3,
12439,
4766,
9948,
198,
9609,
63,
466,
275,
4766,
14,
362,
360,
9609,
63,
466,
358,
199,
198,
5598,
360,
5484,
297,
283,
1375,
63,
5484,
297,
283,
12588,
363,
32146,
358,
199,
198,
5598,
360,
5945,
63,
466,
297,
283,
504,
63,
10244,
297,
283,
1353,
328,
471,
297,
2400,
671,
26,
671,
508,
283,
16441,
358,
199,
198,
5598,
360,
4968,
297,
283,
4968,
297,
283,
12588,
363,
4968,
358,
421,
198,
692,
4766,
14,
362,
360,
1205,
358,
508,
283,
24054,
356,
507,
198,
5598,
360,
1205,
297,
283,
24054,
297,
488,
12,
2400,
671,
26,
715,
9,
199,
198,
2836,
26,
507,
198,
5598,
360,
1205,
297,
686,
198,
1133,
1320,
1287,
363,
521,
63,
16391,
363,
15114,
297,
686,
198,
3984,
14458,
363,
521,
63,
16391,
363,
15114,
297,
686,
198,
2734,
671,
26,
671,
508,
283,
6455,
7,
507,
198,
9,
421,
198,
5598,
360,
5945,
63,
521,
297,
11083,
198,
1133,
1320,
1287,
63,
521,
363,
3308,
297,
11083,
198,
3984,
14458,
363,
521,
63,
16391,
363,
3308,
297,
507,
198,
2734,
366,
26,
3063,
446,
2197,
14,
7473,
8,
4899,
29,
68,
9,
199,
198,
9,
421,
198,
5598,
360,
16391,
63,
521,
297,
507,
198,
1133,
1320,
1287
] |
[
199,
7243,
437,
670,
11915,
199,
624,
199,
646,
2197,
199,
646,
7975,
199,
646,
4182,
199,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
504,
1639,
14,
697,
492,
6008,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
199,
504,
1551,
16537,
14,
1018,
492,
1709,
199,
199,
318,
664,
63,
7358,
8,
5484,
65,
12,
4954,
66,
12,
9952,
304,
199,
198,
624,
6200,
282,
14094,
3382,
2877,
12103,
14,
9948,
198,
624,
199,
198,
1107,
334,
992,
14,
7344,
27106,
14,
1462,
507,
198,
14,
2416,
63,
2407,
8,
686,
198,
7,
7358,
7,
686,
198,
7,
7358,
363,
32146,
7,
507,
198,
9,
507,
198,
14,
362,
8,
686,
198,
5484,
29,
5484,
65,
12,
686,
198,
7358,
363,
32146,
29,
5484,
66,
12,
686,
198,
7358,
363,
4968,
29,
4968,
507,
198,
680,
7358,
199,
198,
9,
199,
199,
318,
664,
63,
7358,
83,
8,
751,
12,
2387,
63,
18923,
29,
797,
12,
2837,
328,
471,
29,
403,
304,
199,
198,
624,
1002,
314,
769,
402,
8091,
13236,
367,
282,
922,
14,
9388,
734,
1263,
2382,
314,
574,
365,
199,
198,
894,
370,
378,
14,
199,
198,
624,
199,
198,
81,
275,
1709,
14,
7344,
27106,
14,
1462,
14,
1541,
8,
5484,
29,
751,
14,
5484,
9,
199,
198,
692,
440,
2387,
63,
18923,
26,
507,
198,
81,
275,
1894,
14,
5473,
8,
7358,
363,
585,
29,
16,
9,
199,
198,
692,
2837,
328,
471,
365,
440,
488,
26,
507,
198,
81,
275,
1894,
14,
1541,
8,
1353,
328,
471,
29,
1353,
328,
471,
9,
199,
198,
1107,
1894,
199,
199,
318,
664,
63,
7358,
83,
63,
3479,
8,
32146,
12,
9952,
12,
2837,
328,
471,
12,
2387,
63,
18923,
29,
797,
304,
199,
198,
624,
1767,
282,
2341,
402,
4954,
1035,
8091,
13236,
1041,
199,
198,
81,
275,
1709,
14,
7344,
27106,
14,
1462,
14,
1541,
8,
507,
198,
5484,
363,
262,
29,
32146,
12,
507,
198,
1353,
328,
471,
29,
1353,
328,
471,
12,
507,
198,
7358,
363,
4968,
29,
4968,
199,
198,
9,
199,
198,
692,
440,
2387,
63,
18923,
26,
507,
198,
81,
275,
1894,
14,
5473,
8,
7358,
363,
585,
29,
16,
9,
199,
198,
1107,
1894,
199,
199,
318,
664,
63,
6455,
63,
1515,
63,
509,
63,
751,
8,
751,
304,
199,
198,
624,
1002,
9413,
15809,
367,
282,
922,
1314,
4898,
199,
198,
3966,
701,
2005,
1163,
922,
12,
436,
1929,
370,
506,
10226,
14,
199,
198,
624,
199,
198,
1107,
1709,
14,
10161,
5433,
14,
1462,
14,
1541,
8,
507,
198,
1375,
63,
5484,
29,
751,
14,
5484,
12,
507,
198,
5945,
363,
15114,
29,
549,
12,
507,
198,
24054,
29,
797,
199,
198,
9,
199,
199,
318,
664,
63,
14951,
63,
1515,
63,
509,
63,
751,
8,
751,
12,
7609,
29,
709,
12,
2304,
29,
1046,
12,
9413,
63,
2118,
29,
797,
304,
199,
198,
624,
1002,
8058,
6008,
5767,
367,
314,
922,
14,
221,
5723,
6008,
5767,
199,
198,
7551,
506,
22763,
14,
199,
198,
624,
199,
198,
2210,
24951,
63,
2977,
275,
2197,
14,
602,
14,
8136,
342,
446,
2197,
14,
7473,
8,
4899,
9,
199,
198,
81,
275,
1709,
14,
10161,
5433,
14,
1462,
14,
1541,
8,
507,
198,
9986,
63,
5484,
29,
751,
14,
5484,
12,
507,
198,
521,
63,
3966,
363,
19586,
29,
2210,
24951,
63,
2977,
199,
198,
9,
421,
198,
692,
9413,
63,
2118,
26,
507,
198,
81,
275,
1894,
14,
1541,
8,
5945,
363,
15114,
29,
549,
9,
421,
198,
1107,
1894,
14,
1648,
63,
991,
3654,
5945,
63,
521,
358,
1491,
3097,
61,
199,
199,
318,
664,
63,
14197,
63,
17153,
8,
751,
304,
199,
198,
624,
1002,
15343,
24434,
367,
314,
922,
1041,
199,
198,
1107,
1709,
14,
13188,
6621,
14,
1462,
14,
1541,
8,
507,
198,
5484,
29,
751,
14,
5484,
199,
198,
9,
421,
199,
3,
3254,
26,
2295,
199,
318,
664,
63,
9609,
63,
5570,
8,
751,
12,
4766,
304,
199,
198,
624,
1002,
282,
769,
402,
1006,
15809,
436,
17416,
8653,
367,
314,
922,
9806,
199,
198,
991,
1824,
4766,
14,
199,
198,
624,
199,
198,
1131,
63,
2193,
275,
942,
199,
198,
12588,
63,
1131,
12,
1752,
63,
1131,
275,
990,
942,
199,
198,
2131,
275,
2197,
14,
2083,
14,
2131,
342,
421,
198,
318,
8260,
8,
498,
12,
1752,
12,
12401,
12,
19874,
63,
637,
29,
403,
304,
507,
198,
624,
4433,
370,
3272,
4766,
367,
3865,
6716,
1041,
507,
198,
637,
275,
4766,
14,
362,
8,
498,
9,
507,
198,
692,
440,
1139,
26,
686,
198,
1107,
507,
198,
692,
19874,
63,
637,
26,
686,
198,
637,
275,
19874,
63,
637,
8,
637,
9,
507,
198,
692,
1752,
26,
686,
198,
1515,
63,
1131,
14,
740,
1332,
1515,
12,
1139,
430,
507,
198,
692,
12401,
26,
686,
198,
12588,
63,
1131,
14,
740,
1332,
12588,
12,
1139,
430,
421,
198,
3,
12439,
4766,
9948,
198,
9609,
63,
466,
275,
4766,
14,
362,
360,
9609,
63,
466,
358,
199,
198,
5598,
360,
5484,
297,
283,
1375,
63,
5484,
297,
283,
12588,
363,
32146,
358,
199,
198,
5598,
360,
5945,
63,
466,
297,
283,
504,
63,
10244,
297,
283,
1353,
328,
471,
297,
2400,
671,
26,
671,
508,
283,
16441,
358,
199,
198,
5598,
360,
4968,
297,
283,
4968,
297,
283,
12588,
363,
4968,
358,
421,
198,
692,
4766,
14,
362,
360,
1205,
358,
508,
283,
24054,
356,
507,
198,
5598,
360,
1205,
297,
283,
24054,
297,
488,
12,
2400,
671,
26,
715,
9,
199,
198,
2836,
26,
507,
198,
5598,
360,
1205,
297,
686,
198,
1133,
1320,
1287,
363,
521,
63,
16391,
363,
15114,
297,
686,
198,
3984,
14458,
363,
521,
63,
16391,
363,
15114,
297,
686,
198,
2734,
671,
26,
671,
508,
283,
6455,
7,
507,
198,
9,
421,
198,
5598,
360,
5945,
63,
521,
297,
11083,
198,
1133,
1320,
1287,
63,
521,
363,
3308,
297,
11083,
198,
3984,
14458,
363,
521,
63,
16391,
363,
3308,
297,
507,
198,
2734,
366,
26,
3063,
446,
2197,
14,
7473,
8,
4899,
29,
68,
9,
199,
198,
9,
421,
198,
5598,
360,
16391,
63,
521,
297,
507,
198,
1133,
1320,
1287,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DJMelonz/basic-blog
|
django/views/generic/list.py
|
98
|
5863
|
import re
from django.core.paginator import Paginator, InvalidPage
from django.core.exceptions import ImproperlyConfigured
from django.http import Http404
from django.utils.encoding import smart_str
from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateResponseMixin, View
class MultipleObjectMixin(object):
allow_empty = True
queryset = None
model = None
paginate_by = None
context_object_name = None
paginator_class = Paginator
def get_queryset(self):
"""
Get the list of items for this view. This must be an interable, and may
be a queryset (in which qs-specific behavior will be enabled).
"""
if self.queryset is not None:
queryset = self.queryset
if hasattr(queryset, '_clone'):
queryset = queryset._clone()
elif self.model is not None:
queryset = self.model._default_manager.all()
else:
raise ImproperlyConfigured(u"'%s' must define 'queryset' or 'model'"
% self.__class__.__name__)
return queryset
def paginate_queryset(self, queryset, page_size):
"""
Paginate the queryset, if needed.
"""
paginator = self.get_paginator(queryset, page_size, allow_empty_first_page=self.get_allow_empty())
page = self.kwargs.get('page') or self.request.GET.get('page') or 1
try:
page_number = int(page)
except ValueError:
if page == 'last':
page_number = paginator.num_pages
else:
raise Http404(_(u"Page is not 'last', nor can it be converted to an int."))
try:
page = paginator.page(page_number)
return (paginator, page, page.object_list, page.has_other_pages())
except InvalidPage:
raise Http404(_(u'Invalid page (%(page_number)s)') % {
'page_number': page_number
})
def get_paginate_by(self, queryset):
"""
Get the number of items to paginate by, or ``None`` for no pagination.
"""
return self.paginate_by
def get_paginator(self, queryset, per_page, orphans=0, allow_empty_first_page=True):
"""
Return an instance of the paginator for this view.
"""
return self.paginator_class(queryset, per_page, orphans=orphans, allow_empty_first_page=allow_empty_first_page)
def get_allow_empty(self):
"""
Returns ``True`` if the view should display empty lists, and ``False``
if a 404 should be raised instead.
"""
return self.allow_empty
def get_context_object_name(self, object_list):
"""
Get the name of the item to be used in the context.
"""
if self.context_object_name:
return self.context_object_name
elif hasattr(object_list, 'model'):
return smart_str('%s_list' % object_list.model._meta.object_name.lower())
else:
return None
def get_context_data(self, **kwargs):
"""
Get the context for this view.
"""
queryset = kwargs.pop('object_list')
page_size = self.get_paginate_by(queryset)
if page_size:
paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
context = {
'paginator': paginator,
'page_obj': page,
'is_paginated': is_paginated,
'object_list': queryset
}
else:
context = {
'paginator': None,
'page_obj': None,
'is_paginated': False,
'object_list': queryset
}
context.update(kwargs)
context_object_name = self.get_context_object_name(queryset)
if context_object_name is not None:
context[context_object_name] = queryset
return context
class BaseListView(MultipleObjectMixin, View):
def get(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
allow_empty = self.get_allow_empty()
if not allow_empty and len(self.object_list) == 0:
raise Http404(_(u"Empty list and '%(class_name)s.allow_empty' is False.")
% {'class_name': self.__class__.__name__})
context = self.get_context_data(object_list=self.object_list)
return self.render_to_response(context)
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
template_name_suffix = '_list'
def get_template_names(self):
"""
Return a list of template names to be used for the request. Must return
a list. May not be called if get_template is overridden.
"""
try:
names = super(MultipleObjectTemplateResponseMixin, self).get_template_names()
except ImproperlyConfigured:
# If template_name isn't specified, it's not a problem --
# we just start with an empty list.
names = []
# If the list is a queryset, we'll invent a template name based on the
# app and model name. This name gets put at the end of the template
# name list so that user-supplied names override the automatically-
# generated ones.
if hasattr(self.object_list, 'model'):
opts = self.object_list.model._meta
names.append("%s/%s%s.html" % (opts.app_label, opts.object_name.lower(), self.template_name_suffix))
return names
class ListView(MultipleObjectTemplateResponseMixin, BaseListView):
"""
Render some list of objects, set by `self.model` or `self.queryset`.
`self.queryset` can actually be any iterable of items, not just a queryset.
"""
|
bsd-3-clause
|
[
646,
295,
199,
199,
504,
1639,
14,
1018,
14,
22073,
492,
28006,
8566,
12,
6378,
3276,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
495,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
6767,
14,
1095,
492,
29264,
4256,
12,
10935,
421,
199,
533,
14326,
1692,
4256,
8,
785,
304,
272,
2040,
63,
1667,
275,
715,
272,
7594,
275,
488,
272,
1402,
275,
488,
272,
9881,
23043,
63,
991,
275,
488,
272,
1067,
63,
785,
63,
354,
275,
488,
272,
21398,
63,
533,
275,
28006,
8566,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
408,
267,
2372,
314,
769,
402,
2974,
367,
642,
2455,
14,
961,
1471,
506,
376,
315,
13048,
12,
436,
1443,
267,
506,
282,
7594,
334,
262,
1314,
6377,
13,
6100,
5953,
911,
506,
5223,
680,
267,
408,
267,
340,
291,
14,
7924,
365,
440,
488,
26,
288,
7594,
275,
291,
14,
7924,
288,
340,
2688,
8,
7924,
12,
2513,
6311,
735,
355,
7594,
275,
7594,
423,
6311,
342,
267,
916,
291,
14,
1238,
365,
440,
488,
26,
288,
7594,
275,
291,
14,
1238,
423,
885,
63,
2609,
14,
452,
342,
267,
587,
26,
288,
746,
11897,
8,
85,
4507,
5,
83,
7,
1471,
5627,
283,
7924,
7,
503,
283,
1238,
4065,
4318,
450,
291,
855,
533,
4914,
354,
3368,
267,
372,
7594,
339,
347,
9881,
23043,
63,
7924,
8,
277,
12,
7594,
12,
2034,
63,
890,
304,
267,
408,
267,
28006,
23043,
314,
7594,
12,
340,
4346,
14,
267,
408,
267,
21398,
275,
291,
14,
362,
63,
22073,
8,
7924,
12,
2034,
63,
890,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
277,
14,
362,
63,
3306,
63,
1667,
1012,
267,
2034,
275,
291,
14,
958,
14,
362,
360,
1606,
358,
503,
291,
14,
1069,
14,
2970,
14,
362,
360,
1606,
358,
503,
413,
267,
862,
26,
288,
2034,
63,
1955,
275,
1109,
8,
1606,
9,
267,
871,
1722,
26,
288,
340,
2034,
508,
283,
2019,
356,
355,
2034,
63,
1955,
275,
21398,
14,
1507,
63,
5856,
288,
587,
26,
355,
746,
4760,
5188,
27594,
85,
2,
3276,
365,
440,
283,
2019,
297,
6590,
883,
652,
506,
6702,
370,
376,
1109,
13853,
267,
862,
26,
288,
2034,
275,
21398,
14,
1606,
8,
1606,
63,
1955,
9,
288,
372,
334,
22073,
12,
2034,
12,
2034,
14,
785,
63,
513,
12,
2034,
14,
1989,
63,
1848,
63,
5856,
1012,
267,
871,
6378,
3276,
26,
288,
746,
4760,
5188,
27594,
85,
7,
3364,
2034,
17753,
1606,
63,
1955,
9,
83,
5942,
450,
469,
1816,
283,
1606,
63,
1955,
356,
2034,
63,
1955,
288,
3828,
339,
347,
664,
63,
30979,
63,
991,
8,
277,
12,
7594,
304,
267,
408,
267,
2372,
314,
1329,
402,
2974,
370,
9881,
23043,
701,
12,
503,
1124,
403,
1040,
367,
949,
21192,
14,
267,
408,
267,
372,
291,
14,
30979,
63,
991,
339,
347,
664,
63,
22073,
8,
277,
12,
7594,
12,
1126,
63,
1606,
12,
503,
838,
796,
29,
16,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
549,
304,
267,
408,
267,
1432,
376,
1256,
402,
314,
21398,
367,
642,
2455,
14,
267,
408,
267,
372,
291,
14,
22073,
63,
533,
8,
7924,
12,
1126,
63,
1606,
12,
503,
838,
796,
29,
6847,
796,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
3306,
63,
1667,
63,
2246,
63,
1606,
9,
339,
347,
664,
63,
3306,
63,
1667,
8,
277,
304,
267,
408,
267,
1803,
1124,
549,
1040,
340,
314,
2455,
1077,
2929,
2701,
5548,
12,
436,
1124,
797,
1040,
267,
340,
282,
7901,
1077,
506,
4915,
3140,
14,
267,
408,
267,
372,
291,
14,
3306,
63,
1667,
339,
347,
664,
63,
1100,
63,
785,
63,
354,
8,
277,
12,
909,
63,
513,
304,
267,
408,
267,
2372,
314,
536,
402,
314,
1242,
370,
506,
1202,
315,
314,
1067,
14,
267,
408,
267,
340,
291,
14,
1100,
63,
785,
63,
354,
26,
288,
372,
291,
14,
1100,
63,
785,
63,
354,
267,
916,
2688,
8,
785,
63,
513,
12,
283,
1238,
735,
288,
372,
11179,
63,
495,
3508,
83,
63,
513,
7,
450,
909,
63,
513,
14,
1238,
423,
2024,
14,
785,
63,
354,
14,
2325,
1012,
267,
587,
26,
288,
372,
488,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
408,
267,
2372,
314,
1067,
367,
642,
2455,
14,
267,
408,
267,
7594,
275,
2074,
14,
1935,
360,
785,
63,
513,
358,
267,
2034,
63,
890,
275,
291,
14,
362,
63,
30979,
63,
991,
8,
7924,
9,
267,
340,
2034,
63,
890,
26,
288,
21398,
12,
2034,
12,
7594,
12,
365,
63,
28030,
275,
291,
14,
30979,
63,
7924,
8,
7924,
12,
2034,
63,
890,
9,
288,
1067,
275,
469,
355,
283,
22073,
356,
21398,
12,
355,
283,
1606,
63,
1113,
356,
2034,
12,
355,
283,
374,
63,
28030,
356,
365,
63,
28030,
12,
355,
283,
785,
63,
513,
356,
7594,
288,
789,
267,
587,
26,
288,
1067,
275,
469,
355,
283,
22073,
356,
488,
12,
355,
283,
1606,
63,
1113,
356,
488,
12,
355,
283,
374,
63,
28030,
356,
756,
12,
355,
283,
785,
63,
513,
356,
7594,
288,
789,
267,
1067,
14,
873,
8,
958,
9,
267,
1067,
63,
785,
63,
354,
275,
291,
14,
362,
63,
1100,
63,
785,
63,
354,
8,
7924,
9,
267,
340,
1067,
63,
785,
63,
354,
365,
440,
488,
26,
288,
1067,
59,
1100,
63,
785,
63,
354,
61,
275,
7594,
267,
372,
1067,
421,
199,
533,
3523,
23239,
8,
8433,
1692,
4256,
12,
10935,
304,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
785,
63,
513,
275,
291,
14,
362,
63,
7924,
342,
267,
2040,
63,
1667,
275,
291,
14,
362,
63,
3306,
63,
1667,
342,
267,
340,
440,
2040,
63,
1667,
436,
822,
8,
277,
14,
785,
63,
513,
9,
508,
378,
26,
288,
746,
4760,
5188,
27594,
85,
2,
4699,
769,
436,
9487,
533,
63,
354,
9,
83,
14,
3306,
63,
1667,
7,
365,
756,
2685,
2079,
450,
791
] |
[
295,
199,
199,
504,
1639,
14,
1018,
14,
22073,
492,
28006,
8566,
12,
6378,
3276,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
495,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
6767,
14,
1095,
492,
29264,
4256,
12,
10935,
421,
199,
533,
14326,
1692,
4256,
8,
785,
304,
272,
2040,
63,
1667,
275,
715,
272,
7594,
275,
488,
272,
1402,
275,
488,
272,
9881,
23043,
63,
991,
275,
488,
272,
1067,
63,
785,
63,
354,
275,
488,
272,
21398,
63,
533,
275,
28006,
8566,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
408,
267,
2372,
314,
769,
402,
2974,
367,
642,
2455,
14,
961,
1471,
506,
376,
315,
13048,
12,
436,
1443,
267,
506,
282,
7594,
334,
262,
1314,
6377,
13,
6100,
5953,
911,
506,
5223,
680,
267,
408,
267,
340,
291,
14,
7924,
365,
440,
488,
26,
288,
7594,
275,
291,
14,
7924,
288,
340,
2688,
8,
7924,
12,
2513,
6311,
735,
355,
7594,
275,
7594,
423,
6311,
342,
267,
916,
291,
14,
1238,
365,
440,
488,
26,
288,
7594,
275,
291,
14,
1238,
423,
885,
63,
2609,
14,
452,
342,
267,
587,
26,
288,
746,
11897,
8,
85,
4507,
5,
83,
7,
1471,
5627,
283,
7924,
7,
503,
283,
1238,
4065,
4318,
450,
291,
855,
533,
4914,
354,
3368,
267,
372,
7594,
339,
347,
9881,
23043,
63,
7924,
8,
277,
12,
7594,
12,
2034,
63,
890,
304,
267,
408,
267,
28006,
23043,
314,
7594,
12,
340,
4346,
14,
267,
408,
267,
21398,
275,
291,
14,
362,
63,
22073,
8,
7924,
12,
2034,
63,
890,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
277,
14,
362,
63,
3306,
63,
1667,
1012,
267,
2034,
275,
291,
14,
958,
14,
362,
360,
1606,
358,
503,
291,
14,
1069,
14,
2970,
14,
362,
360,
1606,
358,
503,
413,
267,
862,
26,
288,
2034,
63,
1955,
275,
1109,
8,
1606,
9,
267,
871,
1722,
26,
288,
340,
2034,
508,
283,
2019,
356,
355,
2034,
63,
1955,
275,
21398,
14,
1507,
63,
5856,
288,
587,
26,
355,
746,
4760,
5188,
27594,
85,
2,
3276,
365,
440,
283,
2019,
297,
6590,
883,
652,
506,
6702,
370,
376,
1109,
13853,
267,
862,
26,
288,
2034,
275,
21398,
14,
1606,
8,
1606,
63,
1955,
9,
288,
372,
334,
22073,
12,
2034,
12,
2034,
14,
785,
63,
513,
12,
2034,
14,
1989,
63,
1848,
63,
5856,
1012,
267,
871,
6378,
3276,
26,
288,
746,
4760,
5188,
27594,
85,
7,
3364,
2034,
17753,
1606,
63,
1955,
9,
83,
5942,
450,
469,
1816,
283,
1606,
63,
1955,
356,
2034,
63,
1955,
288,
3828,
339,
347,
664,
63,
30979,
63,
991,
8,
277,
12,
7594,
304,
267,
408,
267,
2372,
314,
1329,
402,
2974,
370,
9881,
23043,
701,
12,
503,
1124,
403,
1040,
367,
949,
21192,
14,
267,
408,
267,
372,
291,
14,
30979,
63,
991,
339,
347,
664,
63,
22073,
8,
277,
12,
7594,
12,
1126,
63,
1606,
12,
503,
838,
796,
29,
16,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
549,
304,
267,
408,
267,
1432,
376,
1256,
402,
314,
21398,
367,
642,
2455,
14,
267,
408,
267,
372,
291,
14,
22073,
63,
533,
8,
7924,
12,
1126,
63,
1606,
12,
503,
838,
796,
29,
6847,
796,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
3306,
63,
1667,
63,
2246,
63,
1606,
9,
339,
347,
664,
63,
3306,
63,
1667,
8,
277,
304,
267,
408,
267,
1803,
1124,
549,
1040,
340,
314,
2455,
1077,
2929,
2701,
5548,
12,
436,
1124,
797,
1040,
267,
340,
282,
7901,
1077,
506,
4915,
3140,
14,
267,
408,
267,
372,
291,
14,
3306,
63,
1667,
339,
347,
664,
63,
1100,
63,
785,
63,
354,
8,
277,
12,
909,
63,
513,
304,
267,
408,
267,
2372,
314,
536,
402,
314,
1242,
370,
506,
1202,
315,
314,
1067,
14,
267,
408,
267,
340,
291,
14,
1100,
63,
785,
63,
354,
26,
288,
372,
291,
14,
1100,
63,
785,
63,
354,
267,
916,
2688,
8,
785,
63,
513,
12,
283,
1238,
735,
288,
372,
11179,
63,
495,
3508,
83,
63,
513,
7,
450,
909,
63,
513,
14,
1238,
423,
2024,
14,
785,
63,
354,
14,
2325,
1012,
267,
587,
26,
288,
372,
488,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
408,
267,
2372,
314,
1067,
367,
642,
2455,
14,
267,
408,
267,
7594,
275,
2074,
14,
1935,
360,
785,
63,
513,
358,
267,
2034,
63,
890,
275,
291,
14,
362,
63,
30979,
63,
991,
8,
7924,
9,
267,
340,
2034,
63,
890,
26,
288,
21398,
12,
2034,
12,
7594,
12,
365,
63,
28030,
275,
291,
14,
30979,
63,
7924,
8,
7924,
12,
2034,
63,
890,
9,
288,
1067,
275,
469,
355,
283,
22073,
356,
21398,
12,
355,
283,
1606,
63,
1113,
356,
2034,
12,
355,
283,
374,
63,
28030,
356,
365,
63,
28030,
12,
355,
283,
785,
63,
513,
356,
7594,
288,
789,
267,
587,
26,
288,
1067,
275,
469,
355,
283,
22073,
356,
488,
12,
355,
283,
1606,
63,
1113,
356,
488,
12,
355,
283,
374,
63,
28030,
356,
756,
12,
355,
283,
785,
63,
513,
356,
7594,
288,
789,
267,
1067,
14,
873,
8,
958,
9,
267,
1067,
63,
785,
63,
354,
275,
291,
14,
362,
63,
1100,
63,
785,
63,
354,
8,
7924,
9,
267,
340,
1067,
63,
785,
63,
354,
365,
440,
488,
26,
288,
1067,
59,
1100,
63,
785,
63,
354,
61,
275,
7594,
267,
372,
1067,
421,
199,
533,
3523,
23239,
8,
8433,
1692,
4256,
12,
10935,
304,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
785,
63,
513,
275,
291,
14,
362,
63,
7924,
342,
267,
2040,
63,
1667,
275,
291,
14,
362,
63,
3306,
63,
1667,
342,
267,
340,
440,
2040,
63,
1667,
436,
822,
8,
277,
14,
785,
63,
513,
9,
508,
378,
26,
288,
746,
4760,
5188,
27594,
85,
2,
4699,
769,
436,
9487,
533,
63,
354,
9,
83,
14,
3306,
63,
1667,
7,
365,
756,
2685,
2079,
450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1,
1,
1,
1
] |
mathuin/pyment
|
django/inventory/models.py
|
1
|
7620
|
from django.urls import reverse
from django.db import models
from meadery.models import Product
from django.core.exceptions import ValidationError
class Warehouse(models.Model):
number = models.IntegerField()
slug = models.SlugField(max_length=50, unique=True, help_text="Unique value for warehouse page URL, created from name.")
location = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["number"]
@property
def rows(self):
return self.row_set.count()
@property
def shortname(self):
return "W%d" % self.number
@property
def longname(self):
return "Warehouse %d" % self.number
@property
def name(self):
return self.longname
def __str__(self):
return self.name
def save(self, *args, **kwargs):
self.slug = "w%d" % self.number
super(Warehouse, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse("inventory_warehouse", kwargs={"warehouse_slug": self.slug})
class Row(models.Model):
warehouse = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
number = models.IntegerField()
slug = models.SlugField(max_length=55, blank=True, help_text="Unique value for this row page URL.")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["warehouse", "number"]
unique_together = ("warehouse", "number")
@property
def shelves(self):
return self.shelf_set.count()
@property
def shortname(self):
return "%sR%d" % (self.warehouse.shortname, self.number)
@property
def longname(self):
return "%s Row %d" % (self.warehouse.longname, self.number)
@property
def name(self):
return self.longname
def __str__(self):
return self.name
def save(self, *args, **kwargs):
self.slug = "-".join([self.warehouse.slug, "r%d" % self.number])
super(Row, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse("inventory_row", kwargs={"row_slug": self.slug})
class Shelf(models.Model):
row = models.ForeignKey(Row, on_delete=models.CASCADE)
number = models.IntegerField()
slug = models.SlugField(max_length=60, blank=True, help_text="Unique value for this shelf page URL.")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["row", "number"]
unique_together = ("row", "number")
verbose_name_plural = "Shelves"
@property
def warehouse(self):
return self.row.warehouse
@property
def bins(self):
return self.bin_set.count()
@property
def shortname(self):
return "%sS%d" % (self.row.shortname, self.number)
@property
def longname(self):
return "%s Shelf %d" % (self.row.longname, self.number)
@property
def name(self):
return self.longname
def __str__(self):
return self.name
def save(self, *args, **kwargs):
self.slug = "-".join([self.row.slug, "s%d" % self.number])
super(Shelf, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse("inventory_shelf", kwargs={"shelf_slug": self.slug})
class Bin(models.Model):
shelf = models.ForeignKey(Shelf, on_delete=models.CASCADE)
# must be unique within the shelf
number = models.IntegerField()
slug = models.SlugField(max_length=65, blank=True, help_text="Unique value for this bin page URL.")
# how many crates can fit in this bin
capacity = models.IntegerField(default=1)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["shelf", "number"]
unique_together = ("shelf", "number")
@property
def warehouse(self):
return self.shelf.row.warehouse
@property
def row(self):
return self.shelf.row
@property
def crates(self):
return self.crate_set.count()
@property
def shortname(self):
return "%sB%d" % (self.shelf.shortname, self.number)
@property
def longname(self):
return "%s Bin %d" % (self.shelf.longname, self.number)
@property
def name(self):
return self.longname
def __str__(self):
return self.name
def save(self, *args, **kwargs):
self.slug = "-".join([self.shelf.slug, "b%d" % self.number])
super(Bin, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse("inventory_bin", kwargs={"bin_slug": self.slug})
def clean(self):
# ensure that the current number of crates is less than or equal to the capacity
if self.crates > self.capacity:
raise ValidationError("Capacity of bin exceeded")
class Crate(models.Model):
number = models.IntegerField()
slug = models.SlugField(max_length=10, unique=True, blank=True)
capacity = models.IntegerField(default=12)
# bin where the crate can currently be found
bin = models.ForeignKey(Bin, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["number"]
@property
def jars(self):
return self.jar_set.filter(is_active=True).count()
@property
def shortname(self):
return "C%d" % self.number
@property
def longname(self):
return "Crate %d" % self.number
@property
def name(self):
return self.longname
def __str__(self):
return self.name
def save(self, *args, **kwargs):
self.slug = "c%d" % self.number
super(Crate, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse("inventory_crate", kwargs={"crate_slug": self.slug})
def clean(self):
# ensure that the current number of jars is less than or equal to the capacity
if self.jars > self.capacity:
raise ValidationError("Capacity of crate exceeded")
class InStockJarManager(models.Manager):
def get_queryset(self):
return super(InStockJarManager, self).get_queryset().filter(is_active=True, is_available=True)
class Jar(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
number = models.IntegerField()
slug = models.SlugField(max_length=13, unique=True, blank=True)
# volume in liters
volume = models.IntegerField(default=1)
crate = models.ForeignKey(Crate, on_delete=models.CASCADE)
# is_active = not yet sold
is_active = models.BooleanField(default=True)
# is_available = considered 'in stock'
is_available = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
objects = models.Manager()
instock = InStockJarManager()
class Meta:
ordering = ["created_at"]
unique_together = ("product", "number")
@property
def name(self):
return "%s%d" % (self.product, self.number)
def __str__(self):
return self.name
def save(self, *args, **kwargs):
self.slug = "".join([self.product.slug, str(self.number)])
super(Jar, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse("inventory_jar", kwargs={"jar_slug": self.slug})
|
mit
|
[
504,
1639,
14,
3603,
492,
3837,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
562,
669,
89,
14,
992,
492,
12705,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
421,
199,
533,
644,
11499,
8,
992,
14,
1685,
304,
272,
1329,
275,
1709,
14,
3901,
342,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1400,
12,
3747,
29,
549,
12,
1720,
63,
505,
628,
11427,
574,
367,
13782,
2034,
2851,
12,
2737,
687,
536,
2685,
272,
2909,
275,
1709,
14,
6254,
342,
339,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
2097,
1955,
937,
339,
768,
1829,
272,
347,
4730,
8,
277,
304,
267,
372,
291,
14,
1143,
63,
409,
14,
835,
342,
339,
768,
1829,
272,
347,
3974,
354,
8,
277,
304,
267,
372,
298,
55,
5,
68,
2,
450,
291,
14,
1955,
339,
768,
1829,
272,
347,
1846,
354,
8,
277,
304,
267,
372,
298,
55,
11499,
450,
68,
2,
450,
291,
14,
1955,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
372,
291,
14,
2809,
354,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
5464,
275,
298,
87,
5,
68,
2,
450,
291,
14,
1955,
267,
1613,
8,
55,
11499,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
480,
7212,
63,
12806,
401,
2074,
8871,
12806,
63,
5464,
582,
291,
14,
5464,
1552,
421,
199,
533,
15231,
8,
992,
14,
1685,
304,
272,
13782,
275,
1709,
14,
3190,
8,
55,
11499,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
1329,
275,
1709,
14,
3901,
342,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1229,
12,
4596,
29,
549,
12,
1720,
63,
505,
628,
11427,
574,
367,
642,
1962,
2034,
2851,
2685,
339,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
2097,
12806,
401,
298,
1955,
937,
267,
3747,
63,
6314,
275,
1689,
12806,
401,
298,
1955,
531,
339,
768,
1829,
272,
347,
1033,
352,
2310,
8,
277,
304,
267,
372,
291,
14,
19195,
276,
63,
409,
14,
835,
342,
339,
768,
1829,
272,
347,
3974,
354,
8,
277,
304,
267,
372,
2071,
83,
50,
5,
68,
2,
450,
334,
277,
14,
12806,
14,
3612,
354,
12,
291,
14,
1955,
9,
339,
768,
1829,
272,
347,
1846,
354,
8,
277,
304,
267,
372,
2071,
83,
15231,
450,
68,
2,
450,
334,
277,
14,
12806,
14,
2809,
354,
12,
291,
14,
1955,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
372,
291,
14,
2809,
354,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
5464,
275,
3905,
1674,
904,
779,
277,
14,
12806,
14,
5464,
12,
298,
82,
5,
68,
2,
450,
291,
14,
1955,
566,
267,
1613,
8,
5810,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
480,
7212,
63,
1143,
401,
2074,
8871,
1143,
63,
5464,
582,
291,
14,
5464,
1552,
421,
199,
533,
428,
426,
276,
8,
992,
14,
1685,
304,
272,
1962,
275,
1709,
14,
3190,
8,
5810,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
1329,
275,
1709,
14,
3901,
342,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
2259,
12,
4596,
29,
549,
12,
1720,
63,
505,
628,
11427,
574,
367,
642,
21920,
276,
2034,
2851,
2685,
339,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
2097,
1143,
401,
298,
1955,
937,
267,
3747,
63,
6314,
275,
1689,
1143,
401,
298,
1955,
531,
267,
3376,
63,
354,
63,
10019,
275,
298,
2662,
352,
2310,
2,
339,
768,
1829,
272,
347,
13782,
8,
277,
304,
267,
372,
291,
14,
1143,
14,
12806,
339,
768,
1829,
272,
347,
13341,
8,
277,
304,
267,
372,
291,
14,
1393,
63,
409,
14,
835,
342,
339,
768,
1829,
272,
347,
3974,
354,
8,
277,
304,
267,
372,
2071,
83,
51,
5,
68,
2,
450,
334,
277,
14,
1143,
14,
3612,
354,
12,
291,
14,
1955,
9,
339,
768,
1829,
272,
347,
1846,
354,
8,
277,
304,
267,
372,
2071,
83,
428,
426,
276,
450,
68,
2,
450,
334,
277,
14,
1143,
14,
2809,
354,
12,
291,
14,
1955,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
372,
291,
14,
2809,
354,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
5464,
275,
3905,
1674,
904,
779,
277,
14,
1143,
14,
5464,
12,
298,
83,
5,
68,
2,
450,
291,
14,
1955,
566,
267,
1613,
8,
31306,
276,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
480,
7212,
63,
19195,
276,
401,
2074,
8871,
19195,
276,
63,
5464,
582,
291,
14,
5464,
1552,
421,
199,
533,
32613,
8,
992,
14,
1685,
304,
272,
21920,
276,
275,
1709,
14,
3190,
8,
31306,
276,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
327,
1471,
506,
3747,
4453,
314,
21920,
276,
272,
1329,
275,
1709,
14,
3901,
342,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
2182,
12,
4596,
29,
549,
12,
1720,
63,
505,
628,
11427,
574,
367,
642,
2517,
2034,
2851,
2685,
272,
327,
4212,
5002,
286,
17153,
883,
5542,
315,
642,
2517,
272,
14893,
275
] |
[
1639,
14,
3603,
492,
3837,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
562,
669,
89,
14,
992,
492,
12705,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
421,
199,
533,
644,
11499,
8,
992,
14,
1685,
304,
272,
1329,
275,
1709,
14,
3901,
342,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1400,
12,
3747,
29,
549,
12,
1720,
63,
505,
628,
11427,
574,
367,
13782,
2034,
2851,
12,
2737,
687,
536,
2685,
272,
2909,
275,
1709,
14,
6254,
342,
339,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
2097,
1955,
937,
339,
768,
1829,
272,
347,
4730,
8,
277,
304,
267,
372,
291,
14,
1143,
63,
409,
14,
835,
342,
339,
768,
1829,
272,
347,
3974,
354,
8,
277,
304,
267,
372,
298,
55,
5,
68,
2,
450,
291,
14,
1955,
339,
768,
1829,
272,
347,
1846,
354,
8,
277,
304,
267,
372,
298,
55,
11499,
450,
68,
2,
450,
291,
14,
1955,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
372,
291,
14,
2809,
354,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
5464,
275,
298,
87,
5,
68,
2,
450,
291,
14,
1955,
267,
1613,
8,
55,
11499,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
480,
7212,
63,
12806,
401,
2074,
8871,
12806,
63,
5464,
582,
291,
14,
5464,
1552,
421,
199,
533,
15231,
8,
992,
14,
1685,
304,
272,
13782,
275,
1709,
14,
3190,
8,
55,
11499,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
1329,
275,
1709,
14,
3901,
342,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1229,
12,
4596,
29,
549,
12,
1720,
63,
505,
628,
11427,
574,
367,
642,
1962,
2034,
2851,
2685,
339,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
2097,
12806,
401,
298,
1955,
937,
267,
3747,
63,
6314,
275,
1689,
12806,
401,
298,
1955,
531,
339,
768,
1829,
272,
347,
1033,
352,
2310,
8,
277,
304,
267,
372,
291,
14,
19195,
276,
63,
409,
14,
835,
342,
339,
768,
1829,
272,
347,
3974,
354,
8,
277,
304,
267,
372,
2071,
83,
50,
5,
68,
2,
450,
334,
277,
14,
12806,
14,
3612,
354,
12,
291,
14,
1955,
9,
339,
768,
1829,
272,
347,
1846,
354,
8,
277,
304,
267,
372,
2071,
83,
15231,
450,
68,
2,
450,
334,
277,
14,
12806,
14,
2809,
354,
12,
291,
14,
1955,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
372,
291,
14,
2809,
354,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
5464,
275,
3905,
1674,
904,
779,
277,
14,
12806,
14,
5464,
12,
298,
82,
5,
68,
2,
450,
291,
14,
1955,
566,
267,
1613,
8,
5810,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
480,
7212,
63,
1143,
401,
2074,
8871,
1143,
63,
5464,
582,
291,
14,
5464,
1552,
421,
199,
533,
428,
426,
276,
8,
992,
14,
1685,
304,
272,
1962,
275,
1709,
14,
3190,
8,
5810,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
1329,
275,
1709,
14,
3901,
342,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
2259,
12,
4596,
29,
549,
12,
1720,
63,
505,
628,
11427,
574,
367,
642,
21920,
276,
2034,
2851,
2685,
339,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
2097,
1143,
401,
298,
1955,
937,
267,
3747,
63,
6314,
275,
1689,
1143,
401,
298,
1955,
531,
267,
3376,
63,
354,
63,
10019,
275,
298,
2662,
352,
2310,
2,
339,
768,
1829,
272,
347,
13782,
8,
277,
304,
267,
372,
291,
14,
1143,
14,
12806,
339,
768,
1829,
272,
347,
13341,
8,
277,
304,
267,
372,
291,
14,
1393,
63,
409,
14,
835,
342,
339,
768,
1829,
272,
347,
3974,
354,
8,
277,
304,
267,
372,
2071,
83,
51,
5,
68,
2,
450,
334,
277,
14,
1143,
14,
3612,
354,
12,
291,
14,
1955,
9,
339,
768,
1829,
272,
347,
1846,
354,
8,
277,
304,
267,
372,
2071,
83,
428,
426,
276,
450,
68,
2,
450,
334,
277,
14,
1143,
14,
2809,
354,
12,
291,
14,
1955,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
372,
291,
14,
2809,
354,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
5464,
275,
3905,
1674,
904,
779,
277,
14,
1143,
14,
5464,
12,
298,
83,
5,
68,
2,
450,
291,
14,
1955,
566,
267,
1613,
8,
31306,
276,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
480,
7212,
63,
19195,
276,
401,
2074,
8871,
19195,
276,
63,
5464,
582,
291,
14,
5464,
1552,
421,
199,
533,
32613,
8,
992,
14,
1685,
304,
272,
21920,
276,
275,
1709,
14,
3190,
8,
31306,
276,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
327,
1471,
506,
3747,
4453,
314,
21920,
276,
272,
1329,
275,
1709,
14,
3901,
342,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
2182,
12,
4596,
29,
549,
12,
1720,
63,
505,
628,
11427,
574,
367,
642,
2517,
2034,
2851,
2685,
272,
327,
4212,
5002,
286,
17153,
883,
5542,
315,
642,
2517,
272,
14893,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rschnapka/account-closing
|
account_cutoff_accrual_picking/__init__.py
|
10
|
1081
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# Account Cut-off Accrual Picking module for OpenERP
# Copyright (C) 2013 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import account_cutoff
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
9973,
445,
337,
13,
1997,
4473,
1556,
1061,
16568,
316,
859,
367,
7653,
199,
3,
259,
1898,
334,
35,
9,
6171,
437,
75,
264,
296,
334,
1014,
921,
1544,
14,
1151,
264,
296,
14,
957,
9,
199,
3,
259,
768,
2502,
22986,
374,
477,
491,
6796,
264,
665,
1895,
7291,
14,
2264,
6796,
264,
32,
1151,
264,
296,
14,
957,
30,
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,
1275,
492,
2933,
63,
17708,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
9973,
445,
337,
13,
1997,
4473,
1556,
1061,
16568,
316,
859,
367,
7653,
199,
3,
259,
1898,
334,
35,
9,
6171,
437,
75,
264,
296,
334,
1014,
921,
1544,
14,
1151,
264,
296,
14,
957,
9,
199,
3,
259,
768,
2502,
22986,
374,
477,
491,
6796,
264,
665,
1895,
7291,
14,
2264,
6796,
264,
32,
1151,
264,
296,
14,
957,
30,
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,
1275,
492,
2933,
63,
17708,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
gsmartway/odoo
|
addons/account/report/account_general_ledger.py
|
183
|
15416
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2005-2006 CamptoCamp
# Copyright (c) 2006-2010 OpenERP S.A
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
##############################################################################
import time
from openerp.osv import osv
from openerp.report import report_sxw
from common_report_header import common_report_header
class general_ledger(report_sxw.rml_parse, common_report_header):
_name = 'report.account.general.ledger'
def set_context(self, objects, data, ids, report_type=None):
new_ids = ids
obj_move = self.pool.get('account.move.line')
self.sortby = data['form'].get('sortby', 'sort_date')
self.query = obj_move._query_get(self.cr, self.uid, obj='l', context=data['form'].get('used_context',{}))
ctx2 = data['form'].get('used_context',{}).copy()
self.init_balance = data['form'].get('initial_balance', True)
if self.init_balance:
ctx2.update({'initial_bal': True})
self.init_query = obj_move._query_get(self.cr, self.uid, obj='l', context=ctx2)
self.display_account = data['form']['display_account']
self.target_move = data['form'].get('target_move', 'all')
ctx = self.context.copy()
ctx['fiscalyear'] = data['form']['fiscalyear_id']
if data['form']['filter'] == 'filter_period':
ctx['periods'] = data['form']['periods']
elif data['form']['filter'] == 'filter_date':
ctx['date_from'] = data['form']['date_from']
ctx['date_to'] = data['form']['date_to']
ctx['state'] = data['form']['target_move']
self.context.update(ctx)
if (data['model'] == 'ir.ui.menu'):
new_ids = [data['form']['chart_account_id']]
objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
return super(general_ledger, self).set_context(objects, data, new_ids, report_type=report_type)
def __init__(self, cr, uid, name, context=None):
if context is None:
context = {}
super(general_ledger, self).__init__(cr, uid, name, context=context)
self.query = ""
self.tot_currency = 0.0
self.period_sql = ""
self.sold_accounts = {}
self.sortby = 'sort_date'
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit_account': self._sum_debit_account,
'sum_credit_account': self._sum_credit_account,
'sum_balance_account': self._sum_balance_account,
'sum_currency_amount_account': self._sum_currency_amount_account,
'get_children_accounts': self.get_children_accounts,
'get_fiscalyear': self._get_fiscalyear,
'get_journal': self._get_journal,
'get_account': self._get_account,
'get_start_period': self.get_start_period,
'get_end_period': self.get_end_period,
'get_filter': self._get_filter,
'get_sortby': self._get_sortby,
'get_start_date':self._get_start_date,
'get_end_date':self._get_end_date,
'get_target_move': self._get_target_move,
})
self.context = context
def _sum_currency_amount_account(self, account):
self.cr.execute('SELECT sum(l.amount_currency) AS tot_currency \
FROM account_move_line l \
WHERE l.account_id = %s AND %s' %(account.id, self.query))
sum_currency = self.cr.fetchone()[0] or 0.0
if self.init_balance:
self.cr.execute('SELECT sum(l.amount_currency) AS tot_currency \
FROM account_move_line l \
WHERE l.account_id = %s AND %s '%(account.id, self.init_query))
sum_currency += self.cr.fetchone()[0] or 0.0
return sum_currency
def get_children_accounts(self, account):
res = []
currency_obj = self.pool.get('res.currency')
ids_acc = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, account.id)
currency = account.currency_id and account.currency_id or account.company_id.currency_id
for child_account in self.pool.get('account.account').browse(self.cr, self.uid, ids_acc, context=self.context):
sql = """
SELECT count(id)
FROM account_move_line AS l
WHERE %s AND l.account_id = %%s
""" % (self.query)
self.cr.execute(sql, (child_account.id,))
num_entry = self.cr.fetchone()[0] or 0
sold_account = self._sum_balance_account(child_account)
self.sold_accounts[child_account.id] = sold_account
if self.display_account == 'movement':
if child_account.type != 'view' and num_entry <> 0:
res.append(child_account)
elif self.display_account == 'not_zero':
if child_account.type != 'view' and num_entry <> 0:
if not currency_obj.is_zero(self.cr, self.uid, currency, sold_account):
res.append(child_account)
else:
res.append(child_account)
if not res:
return [account]
return res
def lines(self, account):
""" Return all the account_move_line of account with their account code counterparts """
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted', '']
# First compute all counterpart strings for every move_id where this account appear.
# Currently, the counterpart info is used only in landscape mode
sql = """
SELECT m1.move_id,
array_to_string(ARRAY(SELECT DISTINCT a.code
FROM account_move_line m2
LEFT JOIN account_account a ON (m2.account_id=a.id)
WHERE m2.move_id = m1.move_id
AND m2.account_id<>%%s), ', ') AS counterpart
FROM (SELECT move_id
FROM account_move_line l
LEFT JOIN account_move am ON (am.id = l.move_id)
WHERE am.state IN %s and %s AND l.account_id = %%s GROUP BY move_id) m1
"""% (tuple(move_state), self.query)
self.cr.execute(sql, (account.id, account.id))
counterpart_res = self.cr.dictfetchall()
counterpart_accounts = {}
for i in counterpart_res:
counterpart_accounts[i['move_id']] = i['counterpart']
del counterpart_res
# Then select all account_move_line of this account
if self.sortby == 'sort_journal_partner':
sql_sort='j.code, p.name, l.move_id'
else:
sql_sort='l.date, l.move_id'
sql = """
SELECT l.id AS lid, l.date AS ldate, j.code AS lcode, l.currency_id,l.amount_currency,l.ref AS lref, l.name AS lname, COALESCE(l.debit,0) AS debit, COALESCE(l.credit,0) AS credit, l.period_id AS lperiod_id, l.partner_id AS lpartner_id,
m.name AS move_name, m.id AS mmove_id,per.code as period_code,
c.symbol AS currency_code,
i.id AS invoice_id, i.type AS invoice_type, i.number AS invoice_number,
p.name AS partner_name
FROM account_move_line l
JOIN account_move m on (l.move_id=m.id)
LEFT JOIN res_currency c on (l.currency_id=c.id)
LEFT JOIN res_partner p on (l.partner_id=p.id)
LEFT JOIN account_invoice i on (m.id =i.move_id)
LEFT JOIN account_period per on (per.id=l.period_id)
JOIN account_journal j on (l.journal_id=j.id)
WHERE %s AND m.state IN %s AND l.account_id = %%s ORDER by %s
""" %(self.query, tuple(move_state), sql_sort)
self.cr.execute(sql, (account.id,))
res_lines = self.cr.dictfetchall()
res_init = []
if res_lines and self.init_balance:
#FIXME: replace the label of lname with a string translatable
sql = """
SELECT 0 AS lid, '' AS ldate, '' AS lcode, COALESCE(SUM(l.amount_currency),0.0) AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, '' AS lperiod_id, '' AS lpartner_id,
'' AS move_name, '' AS mmove_id, '' AS period_code,
'' AS currency_code,
NULL AS currency_id,
'' AS invoice_id, '' AS invoice_type, '' AS invoice_number,
'' AS partner_name
FROM account_move_line l
LEFT JOIN account_move m on (l.move_id=m.id)
LEFT JOIN res_currency c on (l.currency_id=c.id)
LEFT JOIN res_partner p on (l.partner_id=p.id)
LEFT JOIN account_invoice i on (m.id =i.move_id)
JOIN account_journal j on (l.journal_id=j.id)
WHERE %s AND m.state IN %s AND l.account_id = %%s
""" %(self.init_query, tuple(move_state))
self.cr.execute(sql, (account.id,))
res_init = self.cr.dictfetchall()
res = res_init + res_lines
account_sum = 0.0
for l in res:
l['move'] = l['move_name'] != '/' and l['move_name'] or ('*'+str(l['mmove_id']))
l['partner'] = l['partner_name'] or ''
account_sum += l['debit'] - l['credit']
l['progress'] = account_sum
l['line_corresp'] = l['mmove_id'] == '' and ' ' or counterpart_accounts[l['mmove_id']].replace(', ',',')
# Modification of amount Currency
if l['credit'] > 0:
if l['amount_currency'] != None:
l['amount_currency'] = abs(l['amount_currency']) * -1
if l['amount_currency'] != None:
self.tot_currency = self.tot_currency + l['amount_currency']
return res
def _sum_debit_account(self, account):
if account.type == 'view':
return account.debit
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted','']
self.cr.execute('SELECT sum(debit) \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.query +' '
,(account.id, tuple(move_state)))
sum_debit = self.cr.fetchone()[0] or 0.0
if self.init_balance:
self.cr.execute('SELECT sum(debit) \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.init_query +' '
,(account.id, tuple(move_state)))
# Add initial balance to the result
sum_debit += self.cr.fetchone()[0] or 0.0
return sum_debit
def _sum_credit_account(self, account):
if account.type == 'view':
return account.credit
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted','']
self.cr.execute('SELECT sum(credit) \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.query +' '
,(account.id, tuple(move_state)))
sum_credit = self.cr.fetchone()[0] or 0.0
if self.init_balance:
self.cr.execute('SELECT sum(credit) \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.init_query +' '
,(account.id, tuple(move_state)))
# Add initial balance to the result
sum_credit += self.cr.fetchone()[0] or 0.0
return sum_credit
def _sum_balance_account(self, account):
if account.type == 'view':
return account.balance
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted','']
self.cr.execute('SELECT (sum(debit) - sum(credit)) as tot_balance \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.query +' '
,(account.id, tuple(move_state)))
sum_balance = self.cr.fetchone()[0] or 0.0
if self.init_balance:
self.cr.execute('SELECT (sum(debit) - sum(credit)) as tot_balance \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.init_query +' '
,(account.id, tuple(move_state)))
# Add initial balance to the result
sum_balance += self.cr.fetchone()[0] or 0.0
return sum_balance
def _get_account(self, data):
if data['model'] == 'account.account':
return self.pool.get('account.account').browse(self.cr, self.uid, data['form']['id']).company_id.name
return super(general_ledger ,self)._get_account(data)
def _get_sortby(self, data):
if self.sortby == 'sort_date':
return self._translate('Date')
elif self.sortby == 'sort_journal_partner':
return self._translate('Journal & Partner')
return self._translate('Date')
class report_generalledger(osv.AbstractModel):
_name = 'report.account.report_generalledger'
_inherit = 'report.abstract_report'
_template = 'account.report_generalledger'
_wrapped_report_class = general_ledger
# 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,
1898,
334,
67,
9,
11811,
13,
7968,
24569,
475,
3630,
311,
199,
3,
1898,
334,
67,
9,
8315,
13,
6542,
7653,
428,
14,
33,
199,
3,
199,
3,
14750,
26,
961,
2240,
465,
4066,
365,
11619,
370,
506,
1202,
701,
22398,
28661,
199,
3,
2240,
16465,
3963,
5452,
314,
8852,
9163,
4783,
402,
465,
5480,
316,
1006,
12330,
199,
3,
406,
13436,
9183,
687,
2399,
1566,
1061,
315,
9587,
27164,
2578,
436,
18227,
199,
3,
9599,
4390,
3963,
787,
10023,
367,
282,
10144,
13,
475,
13,
1180,
8744,
543,
2414,
23012,
199,
3,
12072,
397,
436,
2291,
787,
30390,
1503,
17311,
370,
16077,
282,
2868,
2290,
199,
3,
7591,
15878,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
199,
504,
2863,
63,
3070,
63,
1291,
492,
2863,
63,
3070,
63,
1291,
421,
199,
533,
8605,
63,
28771,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
12,
2863,
63,
3070,
63,
1291,
304,
272,
485,
354,
275,
283,
3070,
14,
2048,
14,
10706,
14,
28771,
7,
339,
347,
663,
63,
1100,
8,
277,
12,
2251,
12,
666,
12,
2762,
12,
3622,
63,
466,
29,
403,
304,
267,
892,
63,
1580,
275,
2762,
267,
1559,
63,
1185,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
1185,
14,
604,
358,
267,
291,
14,
3191,
991,
275,
666,
459,
964,
2278,
362,
360,
3191,
991,
297,
283,
3191,
63,
602,
358,
267,
291,
14,
1131,
275,
1559,
63,
1185,
423,
1131,
63,
362,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1559,
534,
76,
297,
1067,
29,
576,
459,
964,
2278,
362,
360,
2972,
63,
1100,
297,
2440,
430,
267,
4027,
18,
275,
666,
459,
964,
2278,
362,
360,
2972,
63,
1100,
297,
2440,
680,
1574,
342,
267,
291,
14,
826,
63,
7358,
275,
666,
459,
964,
2278,
362,
360,
2747,
63,
7358,
297,
715,
9,
267,
340,
291,
14,
826,
63,
7358,
26,
288,
4027,
18,
14,
873,
3252,
2747,
63,
4982,
356,
715,
1552,
267,
291,
14,
826,
63,
1131,
275,
1559,
63,
1185,
423,
1131,
63,
362,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1559,
534,
76,
297,
1067,
29,
3799,
18,
9,
267,
291,
14,
2918,
63,
2048,
275,
666,
459,
964,
2545,
2918,
63,
2048,
418,
267,
291,
14,
1375,
63,
1185,
275,
666,
459,
964,
2278,
362,
360,
1375,
63,
1185,
297,
283,
452,
358,
267,
4027,
275,
291,
14,
1100,
14,
1574,
342,
267,
4027,
459,
21260,
418,
275,
666,
459,
964,
2545,
21260,
63,
344,
418,
267,
340,
666,
459,
964,
2545,
1541,
418,
508,
283,
1541,
63,
5191,
356,
288,
4027,
459,
20441,
418,
275,
666,
459,
964,
2545,
20441,
418,
267,
916,
666,
459,
964,
2545,
1541,
418,
508,
283,
1541,
63,
602,
356,
288,
4027,
459,
602,
63,
504,
418,
275,
666,
459,
964,
2545,
602,
63,
504,
418,
288,
4027,
459,
602,
63,
475,
418,
275,
221,
666,
459,
964,
2545,
602,
63,
475,
418,
267,
4027,
459,
929,
418,
275,
666,
459,
964,
2545,
1375,
63,
1185,
418,
267,
291,
14,
1100,
14,
873,
8,
3799,
9,
267,
340,
334,
576,
459,
1238,
418,
508,
283,
723,
14,
1907,
14,
4470,
735,
288,
892,
63,
1580,
275,
359,
576,
459,
964,
2545,
9019,
63,
2048,
63,
344,
6538,
288,
2251,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
2048,
1959,
4570,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
892,
63,
1580,
9,
267,
372,
1613,
8,
10706,
63,
28771,
12,
291,
680,
409,
63,
1100,
8,
1462,
12,
666,
12,
892,
63,
1580,
12,
3622,
63,
466,
29,
3070,
63,
466,
9,
339,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
1613,
8,
10706,
63,
28771,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
1131,
275,
3087,
267,
291,
14,
13280,
63,
4968,
275,
378,
14,
16,
267,
291,
14,
5191,
63,
3009,
275,
3087,
267,
291,
14,
83,
1753,
63,
8370,
275,
1052,
267,
291,
14,
3191,
991,
275,
283,
3191,
63,
602,
7,
267,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
521,
356,
900,
12,
288,
283,
1278,
356,
291,
14,
1278,
12,
288,
283,
1838,
63,
12964,
63,
2048,
356,
291,
423,
1838,
63,
12964,
63,
2048,
12,
288,
283,
1838,
63,
9365,
63,
2048,
356,
291,
423,
1838,
63,
9365,
63,
2048,
12,
288,
283,
1838,
63,
7358,
63,
2048,
356,
291,
423,
1838,
63,
7358,
63,
2048,
12,
288,
283,
1838,
63,
4968,
63,
4606,
63,
2048,
356,
291,
423,
1838,
63,
4968,
63,
4606,
63,
2048,
12,
288,
283,
362,
63,
3223,
63,
8370,
356,
291,
14,
362,
63,
3223,
63,
8370,
12,
288,
283,
362,
63,
21260,
356,
291,
423,
362,
63,
21260,
12,
288,
283,
362,
63,
7067,
356,
291,
423,
362,
63,
7067,
12,
288,
283,
362,
63,
2048,
356,
291,
423,
362
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
11811,
13,
7968,
24569,
475,
3630,
311,
199,
3,
1898,
334,
67,
9,
8315,
13,
6542,
7653,
428,
14,
33,
199,
3,
199,
3,
14750,
26,
961,
2240,
465,
4066,
365,
11619,
370,
506,
1202,
701,
22398,
28661,
199,
3,
2240,
16465,
3963,
5452,
314,
8852,
9163,
4783,
402,
465,
5480,
316,
1006,
12330,
199,
3,
406,
13436,
9183,
687,
2399,
1566,
1061,
315,
9587,
27164,
2578,
436,
18227,
199,
3,
9599,
4390,
3963,
787,
10023,
367,
282,
10144,
13,
475,
13,
1180,
8744,
543,
2414,
23012,
199,
3,
12072,
397,
436,
2291,
787,
30390,
1503,
17311,
370,
16077,
282,
2868,
2290,
199,
3,
7591,
15878,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
199,
504,
2863,
63,
3070,
63,
1291,
492,
2863,
63,
3070,
63,
1291,
421,
199,
533,
8605,
63,
28771,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
12,
2863,
63,
3070,
63,
1291,
304,
272,
485,
354,
275,
283,
3070,
14,
2048,
14,
10706,
14,
28771,
7,
339,
347,
663,
63,
1100,
8,
277,
12,
2251,
12,
666,
12,
2762,
12,
3622,
63,
466,
29,
403,
304,
267,
892,
63,
1580,
275,
2762,
267,
1559,
63,
1185,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
1185,
14,
604,
358,
267,
291,
14,
3191,
991,
275,
666,
459,
964,
2278,
362,
360,
3191,
991,
297,
283,
3191,
63,
602,
358,
267,
291,
14,
1131,
275,
1559,
63,
1185,
423,
1131,
63,
362,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1559,
534,
76,
297,
1067,
29,
576,
459,
964,
2278,
362,
360,
2972,
63,
1100,
297,
2440,
430,
267,
4027,
18,
275,
666,
459,
964,
2278,
362,
360,
2972,
63,
1100,
297,
2440,
680,
1574,
342,
267,
291,
14,
826,
63,
7358,
275,
666,
459,
964,
2278,
362,
360,
2747,
63,
7358,
297,
715,
9,
267,
340,
291,
14,
826,
63,
7358,
26,
288,
4027,
18,
14,
873,
3252,
2747,
63,
4982,
356,
715,
1552,
267,
291,
14,
826,
63,
1131,
275,
1559,
63,
1185,
423,
1131,
63,
362,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1559,
534,
76,
297,
1067,
29,
3799,
18,
9,
267,
291,
14,
2918,
63,
2048,
275,
666,
459,
964,
2545,
2918,
63,
2048,
418,
267,
291,
14,
1375,
63,
1185,
275,
666,
459,
964,
2278,
362,
360,
1375,
63,
1185,
297,
283,
452,
358,
267,
4027,
275,
291,
14,
1100,
14,
1574,
342,
267,
4027,
459,
21260,
418,
275,
666,
459,
964,
2545,
21260,
63,
344,
418,
267,
340,
666,
459,
964,
2545,
1541,
418,
508,
283,
1541,
63,
5191,
356,
288,
4027,
459,
20441,
418,
275,
666,
459,
964,
2545,
20441,
418,
267,
916,
666,
459,
964,
2545,
1541,
418,
508,
283,
1541,
63,
602,
356,
288,
4027,
459,
602,
63,
504,
418,
275,
666,
459,
964,
2545,
602,
63,
504,
418,
288,
4027,
459,
602,
63,
475,
418,
275,
221,
666,
459,
964,
2545,
602,
63,
475,
418,
267,
4027,
459,
929,
418,
275,
666,
459,
964,
2545,
1375,
63,
1185,
418,
267,
291,
14,
1100,
14,
873,
8,
3799,
9,
267,
340,
334,
576,
459,
1238,
418,
508,
283,
723,
14,
1907,
14,
4470,
735,
288,
892,
63,
1580,
275,
359,
576,
459,
964,
2545,
9019,
63,
2048,
63,
344,
6538,
288,
2251,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
2048,
1959,
4570,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
892,
63,
1580,
9,
267,
372,
1613,
8,
10706,
63,
28771,
12,
291,
680,
409,
63,
1100,
8,
1462,
12,
666,
12,
892,
63,
1580,
12,
3622,
63,
466,
29,
3070,
63,
466,
9,
339,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
1613,
8,
10706,
63,
28771,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
1131,
275,
3087,
267,
291,
14,
13280,
63,
4968,
275,
378,
14,
16,
267,
291,
14,
5191,
63,
3009,
275,
3087,
267,
291,
14,
83,
1753,
63,
8370,
275,
1052,
267,
291,
14,
3191,
991,
275,
283,
3191,
63,
602,
7,
267,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
521,
356,
900,
12,
288,
283,
1278,
356,
291,
14,
1278,
12,
288,
283,
1838,
63,
12964,
63,
2048,
356,
291,
423,
1838,
63,
12964,
63,
2048,
12,
288,
283,
1838,
63,
9365,
63,
2048,
356,
291,
423,
1838,
63,
9365,
63,
2048,
12,
288,
283,
1838,
63,
7358,
63,
2048,
356,
291,
423,
1838,
63,
7358,
63,
2048,
12,
288,
283,
1838,
63,
4968,
63,
4606,
63,
2048,
356,
291,
423,
1838,
63,
4968,
63,
4606,
63,
2048,
12,
288,
283,
362,
63,
3223,
63,
8370,
356,
291,
14,
362,
63,
3223,
63,
8370,
12,
288,
283,
362,
63,
21260,
356,
291,
423,
362,
63,
21260,
12,
288,
283,
362,
63,
7067,
356,
291,
423,
362,
63,
7067,
12,
288,
283,
362,
63,
2048,
356,
291,
423,
362,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cchurch/ansible
|
lib/ansible/modules/cloud/google/gcp_mlengine_model.py
|
7
|
11591
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 Google
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file at
# https://www.github.com/GoogleCloudPlatform/magic-modules
#
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
module: gcp_mlengine_model
description:
- Represents a machine learning solution.
- A model can have multiple versions, each of which is a deployed, trained model ready
to receive prediction requests. The model itself is just a container.
short_description: Creates a GCP Model
version_added: 2.9
author: Google Inc. (@googlecloudplatform)
requirements:
- python >= 2.6
- requests >= 2.18.4
- google-auth >= 1.3.0
options:
state:
description:
- Whether the given object should exist in GCP
choices:
- present
- absent
default: present
type: str
name:
description:
- The name specified for the model.
required: true
type: str
description:
description:
- The description specified for the model when it was created.
required: false
type: str
default_version:
description:
- The default version of the model. This version will be used to handle prediction
requests that do not specify a version.
required: false
type: dict
suboptions:
name:
description:
- The name specified for the version when it was created.
required: false
type: str
regions:
description:
- The list of regions where the model is going to be deployed.
- Currently only one region per model is supported .
required: false
type: list
online_prediction_logging:
description:
- If true, online prediction access logs are sent to StackDriver Logging.
required: false
type: bool
online_prediction_console_logging:
description:
- If true, online prediction nodes send stderr and stdout streams to Stackdriver
Logging.
required: false
type: bool
labels:
description:
- One or more labels that you can add, to organize your models.
required: false
type: dict
extends_documentation_fragment: gcp
'''
EXAMPLES = '''
- name: create a model
gcp_mlengine_model:
name: "{{ resource_name | replace('-', '_') }}"
description: My model
regions:
- us-central1
project: test_project
auth_kind: serviceaccount
service_account_file: "/tmp/auth.pem"
state: present
'''
RETURN = '''
name:
description:
- The name specified for the model.
returned: success
type: str
description:
description:
- The description specified for the model when it was created.
returned: success
type: str
defaultVersion:
description:
- The default version of the model. This version will be used to handle prediction
requests that do not specify a version.
returned: success
type: complex
contains:
name:
description:
- The name specified for the version when it was created.
returned: success
type: str
regions:
description:
- The list of regions where the model is going to be deployed.
- Currently only one region per model is supported .
returned: success
type: list
onlinePredictionLogging:
description:
- If true, online prediction access logs are sent to StackDriver Logging.
returned: success
type: bool
onlinePredictionConsoleLogging:
description:
- If true, online prediction nodes send stderr and stdout streams to Stackdriver
Logging.
returned: success
type: bool
labels:
description:
- One or more labels that you can add, to organize your models.
returned: success
type: dict
'''
################################################################################
# Imports
################################################################################
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, remove_nones_from_dict, replace_resource_dict
import json
import time
################################################################################
# Main
################################################################################
def main():
"""Main function"""
module = GcpModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(required=True, type='str'),
description=dict(type='str'),
default_version=dict(type='dict', options=dict(name=dict(type='str'))),
regions=dict(type='list', elements='str'),
online_prediction_logging=dict(type='bool'),
online_prediction_console_logging=dict(type='bool'),
labels=dict(type='dict'),
)
)
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
state = module.params['state']
fetch = fetch_resource(module, self_link(module))
changed = False
if fetch:
if state == 'present':
if is_different(module, fetch):
update(module, self_link(module))
fetch = fetch_resource(module, self_link(module))
changed = True
else:
delete(module, self_link(module))
fetch = {}
changed = True
else:
if state == 'present':
fetch = create(module, collection(module))
changed = True
else:
fetch = {}
fetch.update({'changed': changed})
module.exit_json(**fetch)
def create(module, link):
auth = GcpSession(module, 'mlengine')
return return_if_object(module, auth.post(link, resource_to_request(module)))
def update(module, link):
delete(module, self_link(module))
create(module, collection(module))
def delete(module, link):
auth = GcpSession(module, 'mlengine')
return wait_for_operation(module, auth.delete(link))
def resource_to_request(module):
request = {
u'name': module.params.get('name'),
u'description': module.params.get('description'),
u'defaultVersion': ModelDefaultversion(module.params.get('default_version', {}), module).to_request(),
u'regions': module.params.get('regions'),
u'onlinePredictionLogging': module.params.get('online_prediction_logging'),
u'onlinePredictionConsoleLogging': module.params.get('online_prediction_console_logging'),
u'labels': module.params.get('labels'),
}
return_vals = {}
for k, v in request.items():
if v or v is False:
return_vals[k] = v
return return_vals
def fetch_resource(module, link, allow_not_found=True):
auth = GcpSession(module, 'mlengine')
return return_if_object(module, auth.get(link), allow_not_found)
def self_link(module):
return "https://ml.googleapis.com/v1/projects/{project}/models/{name}".format(**module.params)
def collection(module):
return "https://ml.googleapis.com/v1/projects/{project}/models".format(**module.params)
def return_if_object(module, response, allow_not_found=False):
# If not found, return nothing.
if allow_not_found and response.status_code == 404:
return None
# If no content, return nothing.
if response.status_code == 204:
return None
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_response(result, module)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
return result
def is_different(module, response):
request = resource_to_request(module)
response = response_to_hash(module, response)
request = decode_response(request, module)
# Remove all output-only from response.
response_vals = {}
for k, v in response.items():
if k in request:
response_vals[k] = v
request_vals = {}
for k, v in request.items():
if k in response:
request_vals[k] = v
return GcpRequest(request_vals) != GcpRequest(response_vals)
# Remove unnecessary properties from the response.
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'name': response.get(u'name'),
u'description': response.get(u'description'),
u'defaultVersion': ModelDefaultversion(response.get(u'defaultVersion', {}), module).from_response(),
u'regions': response.get(u'regions'),
u'onlinePredictionLogging': response.get(u'onlinePredictionLogging'),
u'onlinePredictionConsoleLogging': response.get(u'onlinePredictionConsoleLogging'),
u'labels': response.get(u'labels'),
}
def async_op_url(module, extra_data=None):
if extra_data is None:
extra_data = {}
url = "https://ml.googleapis.com/v1/{op_id}"
combined = extra_data.copy()
combined.update(module.params)
return url.format(**combined)
def wait_for_operation(module, response):
op_result = return_if_object(module, response)
if op_result is None:
return {}
status = navigate_hash(op_result, ['done'])
wait_done = wait_for_completion(status, op_result, module)
raise_if_errors(wait_done, ['error'], module)
return navigate_hash(wait_done, ['response'])
def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while not status:
raise_if_errors(op_result, ['error'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, False)
status = navigate_hash(op_result, ['done'])
return op_result
def raise_if_errors(response, err_path, module):
errors = navigate_hash(response, err_path)
if errors is not None:
module.fail_json(msg=errors)
# Short names are given (and expected) by the API
# but are returned as full names.
def decode_response(response, module):
if 'name' in response and 'metadata' not in response:
response['name'] = response['name'].split('/')[-1]
return response
class ModelDefaultversion(object):
def __init__(self, request, module):
self.module = module
if request:
self.request = request
else:
self.request = {}
def to_request(self):
return remove_nones_from_dict({u'name': self.request.get('name')})
def from_response(self):
return remove_nones_from_dict({u'name': self.request.get(u'name')})
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
4475,
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,
3,
27103,
199,
3,
199,
3,
258,
19688,
258,
25420,
29087,
6989,
22547,
259,
19688,
259,
25420,
29087,
6989,
22547,
258,
19688,
199,
3,
199,
3,
27103,
199,
3,
199,
3,
258,
961,
570,
365,
5847,
4046,
701,
603,
6573,
18167,
436,
8722,
199,
3,
258,
4493,
911,
506,
286,
1191,
18897,
1380,
314,
570,
365,
31904,
14,
199,
3,
199,
3,
258,
7754,
1586,
1655,
3595,
4212,
370,
1570,
642,
570,
737,
199,
3,
258,
4178,
921,
1544,
14,
5031,
14,
957,
15,
13266,
9089,
10397,
15,
11523,
13,
3112,
199,
3,
199,
3,
27103,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
13289,
199,
3,
15249,
199,
13289,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
283,
1205,
356,
2097,
7780,
2255,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22088,
63,
77,
552,
2598,
63,
1238,
199,
1802,
26,
199,
13,
21591,
282,
6844,
9328,
8744,
14,
199,
13,
437,
1402,
883,
1172,
3663,
5459,
12,
1924,
402,
1314,
365,
282,
26181,
12,
28161,
1402,
10144,
523,
370,
9128,
12044,
4145,
14,
710,
1402,
6337,
365,
2951,
282,
3970,
14,
199,
3612,
63,
1802,
26,
10560,
282,
30902,
5822,
199,
1023,
63,
3270,
26,
499,
14,
25,
199,
2502,
26,
4475,
3277,
14,
8593,
3098,
4091,
3246,
9,
199,
7538,
26,
199,
13,
2366,
2356,
499,
14,
22,
199,
13,
4145,
2356,
499,
14,
1085,
14,
20,
199,
13,
6233,
13,
1178,
2356,
413,
14,
19,
14,
16,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
272,
446,
7480,
314,
1627,
909,
1077,
2187,
315,
30902,
272,
3415,
26,
272,
446,
3451,
272,
446,
9552,
272,
849,
26,
3451,
272,
730,
26,
620,
523,
536,
26,
272,
1369,
26,
272,
446,
710,
536,
2013,
367,
314,
1402,
14,
272,
1415,
26,
2549,
272,
730,
26,
620,
523,
1369,
26,
272,
1369,
26,
272,
446,
710,
1369,
2013,
367,
314,
1402,
1380,
652,
1990,
2737,
14,
272,
1415,
26,
3055,
272,
730,
26,
620,
523,
849,
63,
1023,
26,
272,
1369,
26,
272,
446,
710,
849,
1015,
402,
314,
1402,
14,
961,
1015,
911,
506,
1202,
370,
2429,
12044,
489,
4145,
626,
886,
440,
4165,
282,
1015,
14,
272,
1415,
26,
3055,
272,
730,
26,
1211,
272,
26265,
26,
489,
536,
26,
267,
1369,
26,
267,
446,
710,
536,
2013,
367,
314,
1015,
1380,
652,
1990,
2737,
14,
267,
1415,
26,
3055,
267,
730,
26,
620,
523,
16150,
26,
272,
1369,
26,
272,
446,
710,
769,
402,
16150,
2382,
314,
1402,
365,
9995,
370,
506,
26181,
14,
272,
446,
13550,
1454,
1373,
4897,
1126,
1402,
365,
3748,
1275,
272,
1415,
26,
3055,
272,
730,
26,
769,
523,
18470,
63,
14845,
63,
4806,
26,
272,
1369,
26,
272,
446,
982,
2549,
12,
18470,
12044,
2879,
9610,
787,
4847,
370,
13894,
6158,
19928,
14,
272,
1415,
26,
3055,
272,
730,
26,
2155,
523,
18470,
63,
14845,
63,
6614,
63,
4806,
26,
272,
1369,
26,
272,
446,
982,
2549,
12,
18470,
12044,
3380,
3222,
4635,
436,
3839,
13788,
370,
13894,
3090,
489,
19928,
14,
272,
1415,
26,
3055,
272,
730,
26,
2155,
523,
3628,
26,
272,
1369,
26,
272,
446,
7309,
503,
1655,
3628,
626,
1265,
883,
1050,
12,
370,
20765,
794,
2195,
1709,
14,
272,
1415,
26,
3055,
272,
730,
26,
1211,
199,
11036,
63,
9970,
63,
7677,
26,
22088,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
1218,
282,
1402,
523,
22088,
63,
77,
552,
2598,
63,
1238,
26,
272,
536,
26,
7370,
2073,
63,
354,
1204,
3350,
13858,
18962,
7820,
272,
1369,
26,
4932,
1402,
272,
16150,
26,
272,
446,
2739,
13,
16067,
17,
272,
2199,
26,
511,
63,
1715,
272,
1790,
63,
5091,
26,
2435,
2048,
272,
2435,
63,
2048,
63,
493,
26,
3286,
2791,
15,
1178,
14,
13102,
2,
272,
1174,
26,
3451,
199,
2344,
199,
199,
9677,
275,
1449,
199,
354,
26,
523,
1369,
26,
523,
446,
710,
536,
2013,
367,
314,
1402,
14,
523,
2138,
26,
3182,
523,
730,
26,
620,
199,
1802,
26,
523,
1369,
26,
523,
446,
710,
1369,
2013,
367,
314,
1402,
1380,
652,
1990,
2737,
14,
523,
2138,
26,
3182,
523,
730,
26,
620,
199,
885,
3353,
26,
523,
1369,
26,
523,
446,
710,
849,
1015,
402,
314,
1402,
14,
961,
1015,
911,
506,
1202,
370,
2429,
12044,
272,
4145,
626,
886,
440,
4165,
282,
1015,
14,
523,
2138,
26,
3182,
523,
730,
26,
6114,
523,
3509,
26,
272,
536,
26,
489,
1369,
26,
489,
446,
710,
536,
2013,
367,
314,
1015,
1380,
652,
1990,
2737,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
199,
11963,
26,
523,
1369,
26,
523,
446,
710,
769,
402,
16150,
2382,
314,
1402,
365,
9995,
370,
506,
26181,
14,
523,
446,
13550,
1454,
1373,
4897,
1126,
1402,
365,
3748,
1275,
523,
2138,
26,
3182,
523,
730,
26,
769,
199,
15178,
24261,
14054,
26,
523,
1369,
26,
523,
446,
982,
2549,
12,
18470,
12044,
2879,
9610,
787,
4847,
370,
13894,
6158,
19928,
14,
523,
2138,
26,
3182,
523,
730,
26,
2155,
199,
15178,
24261,
9270,
14054,
26,
523,
1369,
26,
523,
446,
982,
2549,
12,
18470,
12044,
3380,
3222,
4635,
436,
3839,
13788,
370,
13894,
3090,
272,
19928,
14,
523,
2138,
26,
3182,
523,
730,
26,
2155,
199,
3512,
26,
523,
1369,
26,
523,
446,
7309,
503,
1655,
3628,
626,
1265,
883,
1050,
12,
370,
20765,
794,
2195,
1709,
14,
523,
2138,
26,
3182,
523,
730,
26,
1211,
199,
2344,
199,
199,
13289,
199,
3,
24339,
199,
13289,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
20622,
63,
1208,
492,
20850,
63,
2227,
12,
28702,
4434,
12,
28702,
2377
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
4475,
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,
3,
27103,
199,
3,
199,
3,
258,
19688,
258,
25420,
29087,
6989,
22547,
259,
19688,
259,
25420,
29087,
6989,
22547,
258,
19688,
199,
3,
199,
3,
27103,
199,
3,
199,
3,
258,
961,
570,
365,
5847,
4046,
701,
603,
6573,
18167,
436,
8722,
199,
3,
258,
4493,
911,
506,
286,
1191,
18897,
1380,
314,
570,
365,
31904,
14,
199,
3,
199,
3,
258,
7754,
1586,
1655,
3595,
4212,
370,
1570,
642,
570,
737,
199,
3,
258,
4178,
921,
1544,
14,
5031,
14,
957,
15,
13266,
9089,
10397,
15,
11523,
13,
3112,
199,
3,
199,
3,
27103,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
13289,
199,
3,
15249,
199,
13289,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
283,
1205,
356,
2097,
7780,
2255,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22088,
63,
77,
552,
2598,
63,
1238,
199,
1802,
26,
199,
13,
21591,
282,
6844,
9328,
8744,
14,
199,
13,
437,
1402,
883,
1172,
3663,
5459,
12,
1924,
402,
1314,
365,
282,
26181,
12,
28161,
1402,
10144,
523,
370,
9128,
12044,
4145,
14,
710,
1402,
6337,
365,
2951,
282,
3970,
14,
199,
3612,
63,
1802,
26,
10560,
282,
30902,
5822,
199,
1023,
63,
3270,
26,
499,
14,
25,
199,
2502,
26,
4475,
3277,
14,
8593,
3098,
4091,
3246,
9,
199,
7538,
26,
199,
13,
2366,
2356,
499,
14,
22,
199,
13,
4145,
2356,
499,
14,
1085,
14,
20,
199,
13,
6233,
13,
1178,
2356,
413,
14,
19,
14,
16,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
272,
446,
7480,
314,
1627,
909,
1077,
2187,
315,
30902,
272,
3415,
26,
272,
446,
3451,
272,
446,
9552,
272,
849,
26,
3451,
272,
730,
26,
620,
523,
536,
26,
272,
1369,
26,
272,
446,
710,
536,
2013,
367,
314,
1402,
14,
272,
1415,
26,
2549,
272,
730,
26,
620,
523,
1369,
26,
272,
1369,
26,
272,
446,
710,
1369,
2013,
367,
314,
1402,
1380,
652,
1990,
2737,
14,
272,
1415,
26,
3055,
272,
730,
26,
620,
523,
849,
63,
1023,
26,
272,
1369,
26,
272,
446,
710,
849,
1015,
402,
314,
1402,
14,
961,
1015,
911,
506,
1202,
370,
2429,
12044,
489,
4145,
626,
886,
440,
4165,
282,
1015,
14,
272,
1415,
26,
3055,
272,
730,
26,
1211,
272,
26265,
26,
489,
536,
26,
267,
1369,
26,
267,
446,
710,
536,
2013,
367,
314,
1015,
1380,
652,
1990,
2737,
14,
267,
1415,
26,
3055,
267,
730,
26,
620,
523,
16150,
26,
272,
1369,
26,
272,
446,
710,
769,
402,
16150,
2382,
314,
1402,
365,
9995,
370,
506,
26181,
14,
272,
446,
13550,
1454,
1373,
4897,
1126,
1402,
365,
3748,
1275,
272,
1415,
26,
3055,
272,
730,
26,
769,
523,
18470,
63,
14845,
63,
4806,
26,
272,
1369,
26,
272,
446,
982,
2549,
12,
18470,
12044,
2879,
9610,
787,
4847,
370,
13894,
6158,
19928,
14,
272,
1415,
26,
3055,
272,
730,
26,
2155,
523,
18470,
63,
14845,
63,
6614,
63,
4806,
26,
272,
1369,
26,
272,
446,
982,
2549,
12,
18470,
12044,
3380,
3222,
4635,
436,
3839,
13788,
370,
13894,
3090,
489,
19928,
14,
272,
1415,
26,
3055,
272,
730,
26,
2155,
523,
3628,
26,
272,
1369,
26,
272,
446,
7309,
503,
1655,
3628,
626,
1265,
883,
1050,
12,
370,
20765,
794,
2195,
1709,
14,
272,
1415,
26,
3055,
272,
730,
26,
1211,
199,
11036,
63,
9970,
63,
7677,
26,
22088,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
1218,
282,
1402,
523,
22088,
63,
77,
552,
2598,
63,
1238,
26,
272,
536,
26,
7370,
2073,
63,
354,
1204,
3350,
13858,
18962,
7820,
272,
1369,
26,
4932,
1402,
272,
16150,
26,
272,
446,
2739,
13,
16067,
17,
272,
2199,
26,
511,
63,
1715,
272,
1790,
63,
5091,
26,
2435,
2048,
272,
2435,
63,
2048,
63,
493,
26,
3286,
2791,
15,
1178,
14,
13102,
2,
272,
1174,
26,
3451,
199,
2344,
199,
199,
9677,
275,
1449,
199,
354,
26,
523,
1369,
26,
523,
446,
710,
536,
2013,
367,
314,
1402,
14,
523,
2138,
26,
3182,
523,
730,
26,
620,
199,
1802,
26,
523,
1369,
26,
523,
446,
710,
1369,
2013,
367,
314,
1402,
1380,
652,
1990,
2737,
14,
523,
2138,
26,
3182,
523,
730,
26,
620,
199,
885,
3353,
26,
523,
1369,
26,
523,
446,
710,
849,
1015,
402,
314,
1402,
14,
961,
1015,
911,
506,
1202,
370,
2429,
12044,
272,
4145,
626,
886,
440,
4165,
282,
1015,
14,
523,
2138,
26,
3182,
523,
730,
26,
6114,
523,
3509,
26,
272,
536,
26,
489,
1369,
26,
489,
446,
710,
536,
2013,
367,
314,
1015,
1380,
652,
1990,
2737,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
199,
11963,
26,
523,
1369,
26,
523,
446,
710,
769,
402,
16150,
2382,
314,
1402,
365,
9995,
370,
506,
26181,
14,
523,
446,
13550,
1454,
1373,
4897,
1126,
1402,
365,
3748,
1275,
523,
2138,
26,
3182,
523,
730,
26,
769,
199,
15178,
24261,
14054,
26,
523,
1369,
26,
523,
446,
982,
2549,
12,
18470,
12044,
2879,
9610,
787,
4847,
370,
13894,
6158,
19928,
14,
523,
2138,
26,
3182,
523,
730,
26,
2155,
199,
15178,
24261,
9270,
14054,
26,
523,
1369,
26,
523,
446,
982,
2549,
12,
18470,
12044,
3380,
3222,
4635,
436,
3839,
13788,
370,
13894,
3090,
272,
19928,
14,
523,
2138,
26,
3182,
523,
730,
26,
2155,
199,
3512,
26,
523,
1369,
26,
523,
446,
7309,
503,
1655,
3628,
626,
1265,
883,
1050,
12,
370,
20765,
794,
2195,
1709,
14,
523,
2138,
26,
3182,
523,
730,
26,
1211,
199,
2344,
199,
199,
13289,
199,
3,
24339,
199,
13289,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
20622,
63,
1208,
492,
20850,
63,
2227,
12,
28702,
4434,
12,
28702,
2377,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
haad/ansible
|
test/units/module_utils/facts/test_ansible_collector.py
|
25
|
12747
|
# -*- coding: utf-8 -*-
#
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
# Make coding more python3-ish
from __future__ import (absolute_import, division)
__metaclass__ = type
# for testing
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import Mock, patch
from ansible.module_utils.facts import collector
from ansible.module_utils.facts import ansible_collector
from ansible.module_utils.facts import namespace
from ansible.module_utils.facts.other.facter import FacterFactCollector
from ansible.module_utils.facts.other.ohai import OhaiFactCollector
from ansible.module_utils.facts.system.apparmor import ApparmorFactCollector
from ansible.module_utils.facts.system.caps import SystemCapabilitiesFactCollector
from ansible.module_utils.facts.system.date_time import DateTimeFactCollector
from ansible.module_utils.facts.system.env import EnvFactCollector
from ansible.module_utils.facts.system.distribution import DistributionFactCollector
from ansible.module_utils.facts.system.dns import DnsFactCollector
from ansible.module_utils.facts.system.fips import FipsFactCollector
from ansible.module_utils.facts.system.local import LocalFactCollector
from ansible.module_utils.facts.system.lsb import LSBFactCollector
from ansible.module_utils.facts.system.pkg_mgr import PkgMgrFactCollector, OpenBSDPkgMgrFactCollector
from ansible.module_utils.facts.system.platform import PlatformFactCollector
from ansible.module_utils.facts.system.python import PythonFactCollector
from ansible.module_utils.facts.system.selinux import SelinuxFactCollector
from ansible.module_utils.facts.system.service_mgr import ServiceMgrFactCollector
from ansible.module_utils.facts.system.user import UserFactCollector
# from ansible.module_utils.facts.hardware.base import HardwareCollector
from ansible.module_utils.facts.network.base import NetworkCollector
from ansible.module_utils.facts.virtual.base import VirtualCollector
ALL_COLLECTOR_CLASSES = \
[PlatformFactCollector,
DistributionFactCollector,
SelinuxFactCollector,
ApparmorFactCollector,
SystemCapabilitiesFactCollector,
FipsFactCollector,
PkgMgrFactCollector,
OpenBSDPkgMgrFactCollector,
ServiceMgrFactCollector,
LSBFactCollector,
DateTimeFactCollector,
UserFactCollector,
LocalFactCollector,
EnvFactCollector,
DnsFactCollector,
PythonFactCollector,
# FIXME: re-enable when hardware doesnt Hardware() doesnt munge self.facts
# HardwareCollector
NetworkCollector,
VirtualCollector,
OhaiFactCollector,
FacterFactCollector]
def mock_module(gather_subset=None):
if gather_subset is None:
gather_subset = ['all', '!facter', '!ohai']
mock_module = Mock()
mock_module.params = {'gather_subset': gather_subset,
'gather_timeout': 5,
'filter': '*'}
mock_module.get_bin_path = Mock(return_value=None)
return mock_module
def _collectors(module,
all_collector_classes=None,
minimal_gather_subset=None):
gather_subset = module.params.get('gather_subset')
if all_collector_classes is None:
all_collector_classes = ALL_COLLECTOR_CLASSES
if minimal_gather_subset is None:
minimal_gather_subset = frozenset([])
collector_classes = \
collector.collector_classes_from_gather_subset(all_collector_classes=all_collector_classes,
minimal_gather_subset=minimal_gather_subset,
gather_subset=gather_subset)
collectors = []
for collector_class in collector_classes:
collector_obj = collector_class()
collectors.append(collector_obj)
# Add a collector that knows what gather_subset we used so it it can provide a fact
collector_meta_data_collector = \
ansible_collector.CollectorMetaDataCollector(gather_subset=gather_subset,
module_setup=True)
collectors.append(collector_meta_data_collector)
return collectors
ns = namespace.PrefixFactNamespace('ansible_facts', 'ansible_')
# FIXME: this is brute force, but hopefully enough to get some refactoring to make facts testable
class TestInPlace(unittest.TestCase):
def _mock_module(self, gather_subset=None):
return mock_module(gather_subset=gather_subset)
def _collectors(self, module,
all_collector_classes=None,
minimal_gather_subset=None):
return _collectors(module=module,
all_collector_classes=all_collector_classes,
minimal_gather_subset=minimal_gather_subset)
def test(self):
gather_subset = ['all']
mock_module = self._mock_module(gather_subset=gather_subset)
all_collector_classes = [EnvFactCollector]
collectors = self._collectors(mock_module,
all_collector_classes=all_collector_classes)
fact_collector = \
ansible_collector.AnsibleFactCollector(collectors=collectors,
namespace=ns)
res = fact_collector.collect(module=mock_module)
self.assertIsInstance(res, dict)
self.assertIn('env', res)
self.assertIn('gather_subset', res)
self.assertEqual(res['gather_subset'], ['all'])
def test1(self):
gather_subset = ['all']
mock_module = self._mock_module(gather_subset=gather_subset)
collectors = self._collectors(mock_module)
fact_collector = \
ansible_collector.AnsibleFactCollector(collectors=collectors,
namespace=ns)
res = fact_collector.collect(module=mock_module)
self.assertIsInstance(res, dict)
# just assert it's not almost empty
# with run_command and get_file_content mock, many facts are empty, like network
self.assertGreater(len(res), 20)
def test_empty_all_collector_classes(self):
mock_module = self._mock_module()
all_collector_classes = []
collectors = self._collectors(mock_module,
all_collector_classes=all_collector_classes)
fact_collector = \
ansible_collector.AnsibleFactCollector(collectors=collectors,
namespace=ns)
res = fact_collector.collect()
self.assertIsInstance(res, dict)
# just assert it's not almost empty
self.assertLess(len(res), 3)
# def test_facts_class(self):
# mock_module = self._mock_module()
# Facts(mock_module)
# def test_facts_class_load_on_init_false(self):
# mock_module = self._mock_module()
# Facts(mock_module, load_on_init=False)
# # FIXME: assert something
class TestCollectedFacts(unittest.TestCase):
gather_subset = ['all', '!facter', '!ohai']
min_fact_count = 30
max_fact_count = 1000
# TODO: add ansible_cmdline, ansible_*_pubkey* back when TempFactCollector goes away
expected_facts = ['date_time',
'user_id', 'distribution',
'gather_subset', 'module_setup',
'env']
not_expected_facts = ['facter', 'ohai']
def _mock_module(self, gather_subset=None):
return mock_module(gather_subset=self.gather_subset)
def setUp(self):
mock_module = self._mock_module()
collectors = self._collectors(mock_module)
fact_collector = \
ansible_collector.AnsibleFactCollector(collectors=collectors,
namespace=ns)
self.facts = fact_collector.collect(module=mock_module)
def _collectors(self, module,
all_collector_classes=None,
minimal_gather_subset=None):
return _collectors(module=module,
all_collector_classes=all_collector_classes,
minimal_gather_subset=minimal_gather_subset)
def test_basics(self):
self._assert_basics(self.facts)
def test_expected_facts(self):
self._assert_expected_facts(self.facts)
def test_not_expected_facts(self):
self._assert_not_expected_facts(self.facts)
def _assert_basics(self, facts):
self.assertIsInstance(facts, dict)
# just assert it's not almost empty
self.assertGreaterEqual(len(facts), self.min_fact_count)
# and that is not huge number of keys
self.assertLess(len(facts), self.max_fact_count)
# everything starts with ansible_ namespace
def _assert_ansible_namespace(self, facts):
# FIXME: kluge for non-namespace fact
facts.pop('module_setup', None)
facts.pop('gather_subset', None)
for fact_key in facts:
self.assertTrue(fact_key.startswith('ansible_'),
'The fact name "%s" does not startwith "ansible_"' % fact_key)
def _assert_expected_facts(self, facts):
facts_keys = sorted(facts.keys())
for expected_fact in self.expected_facts:
self.assertIn(expected_fact, facts_keys)
def _assert_not_expected_facts(self, facts):
facts_keys = sorted(facts.keys())
for not_expected_fact in self.not_expected_facts:
self.assertNotIn(not_expected_fact, facts_keys)
class ExceptionThrowingCollector(collector.BaseFactCollector):
def collect(self, module=None, collected_facts=None):
raise Exception('A collector failed')
class TestExceptionCollectedFacts(TestCollectedFacts):
def _collectors(self, module,
all_collector_classes=None,
minimal_gather_subset=None):
collectors = _collectors(module=module,
all_collector_classes=all_collector_classes,
minimal_gather_subset=minimal_gather_subset)
c = [ExceptionThrowingCollector()] + collectors
return c
class TestOnlyExceptionCollector(TestCollectedFacts):
expected_facts = []
min_fact_count = 0
def _collectors(self, module,
all_collector_classes=None,
minimal_gather_subset=None):
return [ExceptionThrowingCollector()]
class TestMinimalCollectedFacts(TestCollectedFacts):
gather_subset = ['!all']
min_fact_count = 1
max_fact_count = 10
expected_facts = ['gather_subset',
'module_setup']
not_expected_facts = ['lsb']
class TestFacterCollectedFacts(TestCollectedFacts):
gather_subset = ['!all', 'facter']
min_fact_count = 1
max_fact_count = 10
expected_facts = ['gather_subset',
'module_setup']
not_expected_facts = ['lsb']
class TestOhaiCollectedFacts(TestCollectedFacts):
gather_subset = ['!all', 'ohai']
min_fact_count = 1
max_fact_count = 10
expected_facts = ['gather_subset',
'module_setup']
not_expected_facts = ['lsb']
class TestPkgMgrFacts(TestCollectedFacts):
gather_subset = ['pkg_mgr']
min_fact_count = 1
max_fact_count = 10
expected_facts = ['gather_subset',
'module_setup',
'pkg_mgr']
class TestOpenBSDPkgMgrFacts(TestPkgMgrFacts):
def test_is_openbsd_pkg(self):
self.assertIn('pkg_mgr', self.facts)
self.assertEqual(self.facts['pkg_mgr'], 'openbsd_pkg')
def setUp(self):
self.patcher = patch('platform.system')
mock_platform = self.patcher.start()
mock_platform.return_value = 'OpenBSD'
mock_module = self._mock_module()
collectors = self._collectors(mock_module)
fact_collector = \
ansible_collector.AnsibleFactCollector(collectors=collectors,
namespace=ns)
self.facts = fact_collector.collect(module=mock_module)
def tearDown(self):
self.patcher.stop()
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
3,
367,
5343,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
4420,
12,
3371,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
492,
14910,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
492,
3242,
63,
10946,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
492,
3231,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1848,
14,
70,
6747,
492,
481,
6747,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1848,
14,
79,
17945,
492,
593,
17945,
24704,
12852,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
439,
462,
12416,
492,
13450,
462,
12416,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
12029,
492,
6187,
17006,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
602,
63,
521,
492,
13686,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
1813,
492,
31543,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
4972,
492,
11839,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
5797,
492,
577,
561,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
329,
1190,
492,
481,
6142,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
1832,
492,
10111,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
30740,
492,
491,
12463,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
4600,
63,
7755,
492,
510,
9761,
20752,
24704,
12852,
12,
3232,
15400,
26878,
20752,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
3246,
492,
16078,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
1548,
492,
2018,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
19931,
492,
428,
352,
7226,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
1364,
63,
7755,
492,
7591,
20752,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
751,
492,
2876,
24704,
12852,
199,
199,
3,
687,
3242,
14,
578,
63,
1208,
14,
5047,
14,
16529,
14,
1095,
492,
22825,
1068,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1200,
14,
1095,
492,
7220,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2065,
14,
1095,
492,
13311,
12852,
199,
199,
1761,
63,
23037,
726,
63,
13748,
275,
971,
272,
359,
10397,
24704,
12852,
12,
1362,
11839,
24704,
12852,
12,
1362,
428,
352,
7226,
24704,
12852,
12,
1362,
13450,
462,
12416,
24704,
12852,
12,
1362,
6187,
17006,
24704,
12852,
12,
1362,
481,
6142,
24704,
12852,
12,
1362,
510,
9761,
20752,
24704,
12852,
12,
1362,
3232,
15400,
26878,
20752,
24704,
12852,
12,
1362,
7591,
20752,
24704,
12852,
12,
1362,
491,
12463,
24704,
12852,
12,
1362,
13686,
24704,
12852,
12,
1362,
2876,
24704,
12852,
12,
1362,
10111,
24704,
12852,
12,
1362,
31543,
24704,
12852,
12,
1362,
577,
561,
24704,
12852,
12,
1362,
2018,
24704,
12852,
12,
1362,
327,
7600,
26,
295,
13,
4296,
1380,
14991,
1630,
343,
22825,
1068,
342,
1630,
343,
333,
16993,
291,
14,
5047,
1362,
327,
12793,
22825,
1068,
12852,
1362,
7220,
12852,
12,
1362,
13311,
12852,
12,
1362,
593,
17945,
24704,
12852,
12,
1362,
481,
6747,
24704,
12852,
61,
421,
199,
318,
1683,
63,
578,
8,
13737,
63,
9401,
29,
403,
304,
272,
340,
13082,
63,
9401,
365,
488,
26,
267,
13082,
63,
9401,
275,
788,
452,
297,
14597,
70,
6747,
297,
14597,
79,
17945,
418,
272,
1683,
63,
578,
275,
4420,
342,
272,
1683,
63,
578,
14,
1162,
275,
791,
13737,
63,
9401,
356,
13082,
63,
9401,
12,
2079,
283,
13737,
63,
2593,
356,
959,
12,
2079,
283,
1541,
356,
6438,
936,
272,
1683,
63,
578,
14,
362,
63,
1393,
63,
515,
275,
4420,
8,
1107,
63,
585,
29,
403,
9,
272,
372,
1683,
63,
578,
421,
199,
318,
485,
10946,
83,
8,
578,
12,
355,
1006,
63,
10946,
63,
2888,
29,
403,
12,
355,
13460,
63,
13737,
63,
9401,
29,
403,
304,
272,
13082,
63,
9401,
275,
859,
14,
1162,
14,
362,
360,
13737,
63,
9401,
358,
272,
340,
1006,
63,
10946,
63,
2888,
365,
488,
26,
267,
1006,
63,
10946,
63,
2888,
275,
11727,
63,
23037,
726,
63,
13748,
272,
340,
13460,
63,
13737,
63,
9401,
365,
488,
26,
267,
13460,
63,
13737,
63,
9401,
275,
9522,
4157,
339,
14910,
63,
2888,
275,
971,
267,
14910,
14,
10946,
63,
2888,
63,
504,
63,
13737,
63,
9401,
8,
452,
63,
10946,
63,
2888,
29,
452,
63,
10946,
63,
2888,
12,
10940,
13460,
63,
13737,
63,
9401,
29,
21508,
63,
13737,
63,
9401,
12,
10940,
13082,
63,
9401,
29,
13737,
63,
9401,
9,
339,
14910,
83,
275,
942,
272,
367,
14910,
63,
533,
315,
14910
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
3,
367,
5343,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
4420,
12,
3371,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
492,
14910,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
492,
3242,
63,
10946,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
492,
3231,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1848,
14,
70,
6747,
492,
481,
6747,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1848,
14,
79,
17945,
492,
593,
17945,
24704,
12852,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
439,
462,
12416,
492,
13450,
462,
12416,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
12029,
492,
6187,
17006,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
602,
63,
521,
492,
13686,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
1813,
492,
31543,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
4972,
492,
11839,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
5797,
492,
577,
561,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
329,
1190,
492,
481,
6142,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
1832,
492,
10111,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
30740,
492,
491,
12463,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
4600,
63,
7755,
492,
510,
9761,
20752,
24704,
12852,
12,
3232,
15400,
26878,
20752,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
3246,
492,
16078,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
1548,
492,
2018,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
19931,
492,
428,
352,
7226,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
1364,
63,
7755,
492,
7591,
20752,
24704,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2253,
14,
751,
492,
2876,
24704,
12852,
199,
199,
3,
687,
3242,
14,
578,
63,
1208,
14,
5047,
14,
16529,
14,
1095,
492,
22825,
1068,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
1200,
14,
1095,
492,
7220,
12852,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
2065,
14,
1095,
492,
13311,
12852,
199,
199,
1761,
63,
23037,
726,
63,
13748,
275,
971,
272,
359,
10397,
24704,
12852,
12,
1362,
11839,
24704,
12852,
12,
1362,
428,
352,
7226,
24704,
12852,
12,
1362,
13450,
462,
12416,
24704,
12852,
12,
1362,
6187,
17006,
24704,
12852,
12,
1362,
481,
6142,
24704,
12852,
12,
1362,
510,
9761,
20752,
24704,
12852,
12,
1362,
3232,
15400,
26878,
20752,
24704,
12852,
12,
1362,
7591,
20752,
24704,
12852,
12,
1362,
491,
12463,
24704,
12852,
12,
1362,
13686,
24704,
12852,
12,
1362,
2876,
24704,
12852,
12,
1362,
10111,
24704,
12852,
12,
1362,
31543,
24704,
12852,
12,
1362,
577,
561,
24704,
12852,
12,
1362,
2018,
24704,
12852,
12,
1362,
327,
7600,
26,
295,
13,
4296,
1380,
14991,
1630,
343,
22825,
1068,
342,
1630,
343,
333,
16993,
291,
14,
5047,
1362,
327,
12793,
22825,
1068,
12852,
1362,
7220,
12852,
12,
1362,
13311,
12852,
12,
1362,
593,
17945,
24704,
12852,
12,
1362,
481,
6747,
24704,
12852,
61,
421,
199,
318,
1683,
63,
578,
8,
13737,
63,
9401,
29,
403,
304,
272,
340,
13082,
63,
9401,
365,
488,
26,
267,
13082,
63,
9401,
275,
788,
452,
297,
14597,
70,
6747,
297,
14597,
79,
17945,
418,
272,
1683,
63,
578,
275,
4420,
342,
272,
1683,
63,
578,
14,
1162,
275,
791,
13737,
63,
9401,
356,
13082,
63,
9401,
12,
2079,
283,
13737,
63,
2593,
356,
959,
12,
2079,
283,
1541,
356,
6438,
936,
272,
1683,
63,
578,
14,
362,
63,
1393,
63,
515,
275,
4420,
8,
1107,
63,
585,
29,
403,
9,
272,
372,
1683,
63,
578,
421,
199,
318,
485,
10946,
83,
8,
578,
12,
355,
1006,
63,
10946,
63,
2888,
29,
403,
12,
355,
13460,
63,
13737,
63,
9401,
29,
403,
304,
272,
13082,
63,
9401,
275,
859,
14,
1162,
14,
362,
360,
13737,
63,
9401,
358,
272,
340,
1006,
63,
10946,
63,
2888,
365,
488,
26,
267,
1006,
63,
10946,
63,
2888,
275,
11727,
63,
23037,
726,
63,
13748,
272,
340,
13460,
63,
13737,
63,
9401,
365,
488,
26,
267,
13460,
63,
13737,
63,
9401,
275,
9522,
4157,
339,
14910,
63,
2888,
275,
971,
267,
14910,
14,
10946,
63,
2888,
63,
504,
63,
13737,
63,
9401,
8,
452,
63,
10946,
63,
2888,
29,
452,
63,
10946,
63,
2888,
12,
10940,
13460,
63,
13737,
63,
9401,
29,
21508,
63,
13737,
63,
9401,
12,
10940,
13082,
63,
9401,
29,
13737,
63,
9401,
9,
339,
14910,
83,
275,
942,
272,
367,
14910,
63,
533,
315,
14910,
0
] |
[
1,
1,
1,
1,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UI
|
PySchedGUI/UI/Menus/PathCompleter.py
|
2
|
1417
|
# -*- coding: utf-8 -*-
'''
Created on 2013-04-22 14:54
@summary:
@author: Martin predki
'''
from PySchedGUI.PySchedUI import FileUtils
import os
import readline
import atexit
class PathCompleter(object):
'''
@summary: Implements history path auto completion for all user input
'''
def __init__(self):
history_file = os.path.expanduser('~/.PySchedUI_history')
atexit.register(readline.write_history_file, history_file)
def _listdir(self, root):
"List directory 'root' appending the path separator to subdirs."
res = []
for name in os.listdir(root):
path = os.path.join(root, name)
if os.path.isdir(path):
name += os.sep
res.append(name)
return res
def complete(self, text, state):
line = readline.get_line_buffer().split()
"Perform completion of filesystem path."
dirname, rest = os.path.split(line[0])
dirname = FileUtils.expandPath(dirname)
rest = FileUtils.expandPath(rest)
if dirname == '':
dirname = '/'
if rest == '':
name = self._listdir(dirname)
return name[state]
else:
tmp = self._listdir(dirname)
name = []
for t in tmp:
if t.startswith(rest):
name.append(t)
return name[state]
|
lgpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
199,
10502,
641,
6171,
13,
966,
13,
1081,
4329,
26,
1477,
199,
32,
4705,
26,
221,
199,
32,
2502,
26,
603,
26788,
8869,
8810,
199,
2344,
199,
199,
504,
1611,
29806,
14438,
14,
2713,
29806,
6379,
492,
3814,
7535,
199,
199,
646,
747,
199,
646,
14441,
199,
646,
19840,
199,
199,
533,
6912,
6600,
351,
8,
785,
304,
14821,
1449,
272,
768,
4705,
26,
24664,
7994,
931,
2599,
13659,
367,
1006,
922,
1324,
272,
1449,
272,
347,
636,
826,
721,
277,
304,
267,
7994,
63,
493,
275,
747,
14,
515,
14,
12131,
21114,
8083,
2713,
29806,
6379,
63,
5570,
358,
267,
19840,
14,
2683,
8,
6407,
14,
952,
63,
5570,
63,
493,
12,
7994,
63,
493,
9,
339,
347,
485,
7374,
8,
277,
12,
1738,
304,
267,
298,
1296,
2082,
283,
1231,
7,
24373,
314,
931,
9432,
370,
31396,
2122,
267,
522,
275,
942,
267,
367,
536,
315,
747,
14,
7374,
8,
1231,
304,
288,
931,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
288,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
355,
536,
847,
747,
14,
4127,
288,
522,
14,
740,
8,
354,
9,
267,
372,
522,
339,
347,
4890,
8,
277,
12,
1318,
12,
1174,
304,
267,
1004,
275,
14441,
14,
362,
63,
604,
63,
2738,
1252,
1294,
342,
18418,
298,
20906,
13659,
402,
10036,
931,
2122,
267,
9017,
12,
4618,
275,
747,
14,
515,
14,
1294,
8,
604,
59,
16,
566,
267,
9017,
275,
3814,
7535,
14,
4441,
2042,
8,
3475,
9,
267,
4618,
275,
3814,
7535,
14,
4441,
2042,
8,
3911,
9,
267,
340,
9017,
508,
8061,
288,
9017,
275,
7324,
398,
340,
4618,
508,
8061,
288,
536,
275,
291,
423,
7374,
8,
3475,
9,
288,
372,
536,
59,
929,
61,
398,
587,
26,
288,
3529,
275,
291,
423,
7374,
8,
3475,
9,
288,
536,
275,
942,
288,
367,
307,
315,
3529,
26,
355,
340,
307,
14,
2460,
8,
3911,
304,
490,
536,
14,
740,
8,
84,
9,
288,
372,
536,
59,
929,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
199,
10502,
641,
6171,
13,
966,
13,
1081,
4329,
26,
1477,
199,
32,
4705,
26,
221,
199,
32,
2502,
26,
603,
26788,
8869,
8810,
199,
2344,
199,
199,
504,
1611,
29806,
14438,
14,
2713,
29806,
6379,
492,
3814,
7535,
199,
199,
646,
747,
199,
646,
14441,
199,
646,
19840,
199,
199,
533,
6912,
6600,
351,
8,
785,
304,
14821,
1449,
272,
768,
4705,
26,
24664,
7994,
931,
2599,
13659,
367,
1006,
922,
1324,
272,
1449,
272,
347,
636,
826,
721,
277,
304,
267,
7994,
63,
493,
275,
747,
14,
515,
14,
12131,
21114,
8083,
2713,
29806,
6379,
63,
5570,
358,
267,
19840,
14,
2683,
8,
6407,
14,
952,
63,
5570,
63,
493,
12,
7994,
63,
493,
9,
339,
347,
485,
7374,
8,
277,
12,
1738,
304,
267,
298,
1296,
2082,
283,
1231,
7,
24373,
314,
931,
9432,
370,
31396,
2122,
267,
522,
275,
942,
267,
367,
536,
315,
747,
14,
7374,
8,
1231,
304,
288,
931,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
288,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
355,
536,
847,
747,
14,
4127,
288,
522,
14,
740,
8,
354,
9,
267,
372,
522,
339,
347,
4890,
8,
277,
12,
1318,
12,
1174,
304,
267,
1004,
275,
14441,
14,
362,
63,
604,
63,
2738,
1252,
1294,
342,
18418,
298,
20906,
13659,
402,
10036,
931,
2122,
267,
9017,
12,
4618,
275,
747,
14,
515,
14,
1294,
8,
604,
59,
16,
566,
267,
9017,
275,
3814,
7535,
14,
4441,
2042,
8,
3475,
9,
267,
4618,
275,
3814,
7535,
14,
4441,
2042,
8,
3911,
9,
267,
340,
9017,
508,
8061,
288,
9017,
275,
7324,
398,
340,
4618,
508,
8061,
288,
536,
275,
291,
423,
7374,
8,
3475,
9,
288,
372,
536,
59,
929,
61,
398,
587,
26,
288,
3529,
275,
291,
423,
7374,
8,
3475,
9,
288,
536,
275,
942,
288,
367,
307,
315,
3529,
26,
355,
340,
307,
14,
2460,
8,
3911,
304,
490,
536,
14,
740,
8,
84,
9,
288,
372,
536,
59,
929,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sosy-lab/benchexec
|
benchexec/tools/tbf_testsuite_validator.py
|
3
|
2508
|
# This file is part of BenchExec, a framework for reliable benchmarking:
# https://github.com/sosy-lab/benchexec
#
# SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org>
#
# SPDX-License-Identifier: Apache-2.0
import re
import benchexec.result as result
import benchexec.util as util
import benchexec.tools.template
class Tool(benchexec.tools.template.BaseTool):
"""
Tool info for tbf test-suite validator (https://gitlab.com/sosy-lab/software/test-format).
"""
REQUIRED_PATHS = ["python_modules", "lib", "bin"]
def program_files(self, executable):
return self._program_files_from_executable(
executable, self.REQUIRED_PATHS, parent_dir=True
)
def executable(self):
return util.find_executable(
"tbf-testsuite-validator", "bin/tbf-testsuite-validator"
)
def version(self, executable):
return self._version_from_tool(executable)
def name(self):
return "Tbf Test-suite Validator"
def determine_result(self, returncode, returnsignal, output, isTimeout):
"""
Parse the output of the tool and extract the verification result.
This method always needs to be overridden.
If the tool gave a result, this method needs to return one of the
benchexec.result.RESULT_* strings.
Otherwise an arbitrary string can be returned that will be shown to the user
and should give some indication of the failure reason
(e.g., "CRASH", "OUT_OF_MEMORY", etc.).
"""
for line in reversed(output):
if line.startswith("ERROR:"):
if "timeout" in line.lower():
return "TIMEOUT"
else:
return f"ERROR ({returncode})"
elif line.startswith("Result:") and "FALSE" in line:
return result.RESULT_FALSE_REACH
elif line.startswith("Result:") and "TRUE" in line:
return result.RESULT_TRUE_PROP
elif line.startswith("Result") and "DONE" in line:
return result.RESULT_DONE
return result.RESULT_UNKNOWN
def get_value_from_output(self, lines, identifier):
for line in reversed(lines):
pattern = identifier
if pattern[-1] != ":":
pattern += ":"
match = re.match(f"^{pattern}([^(]*)", line)
if match and match.group(1):
return match.group(1).strip()
return None
|
apache-2.0
|
[
3,
961,
570,
365,
1777,
402,
699,
5368,
4858,
12,
282,
10059,
367,
32150,
12338,
316,
26,
199,
3,
4178,
921,
5031,
14,
957,
15,
83,
736,
89,
13,
5561,
15,
16571,
1628,
199,
3,
199,
3,
6988,
19596,
13,
1173,
7384,
1872,
26,
10219,
13,
13934,
25866,
75,
6423,
23009,
665,
2859,
921,
1544,
14,
83,
736,
89,
13,
5561,
14,
1308,
30,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
3668,
13,
18,
14,
16,
199,
199,
646,
295,
199,
646,
26456,
1628,
14,
1099,
465,
754,
199,
646,
26456,
1628,
14,
1974,
465,
4884,
199,
646,
26456,
1628,
14,
2537,
14,
1160,
421,
199,
533,
15650,
8,
16571,
1628,
14,
2537,
14,
1160,
14,
1563,
5157,
304,
272,
408,
272,
15650,
2256,
367,
307,
4361,
511,
13,
5768,
11822,
334,
2859,
921,
30615,
14,
957,
15,
83,
736,
89,
13,
5561,
15,
15619,
15,
396,
13,
908,
680,
272,
408,
339,
25090,
63,
20202,
275,
2097,
1548,
63,
3112,
401,
298,
773,
401,
298,
1393,
937,
339,
347,
2240,
63,
1725,
8,
277,
12,
7286,
304,
267,
372,
291,
423,
6815,
63,
1725,
63,
504,
63,
5904,
8,
288,
7286,
12,
291,
14,
12496,
63,
20202,
12,
1676,
63,
694,
29,
549,
267,
776,
339,
347,
7286,
8,
277,
304,
267,
372,
4884,
14,
1623,
63,
5904,
8,
288,
298,
84,
4361,
13,
14239,
13,
11034,
401,
298,
1393,
15,
84,
4361,
13,
14239,
13,
11034,
2,
267,
776,
339,
347,
1015,
8,
277,
12,
7286,
304,
267,
372,
291,
423,
1023,
63,
504,
63,
3557,
8,
5904,
9,
339,
347,
536,
8,
277,
304,
267,
372,
298,
52,
4361,
1379,
13,
5768,
4821,
707,
2,
339,
347,
6705,
63,
1099,
8,
277,
12,
17630,
12,
372,
4653,
12,
1072,
12,
365,
6372,
304,
267,
408,
267,
6077,
314,
1072,
402,
314,
4744,
436,
5536,
314,
14786,
754,
14,
267,
961,
1083,
3544,
4839,
370,
506,
10087,
14,
267,
982,
314,
4744,
486,
811,
282,
754,
12,
642,
1083,
4839,
370,
372,
1373,
402,
314,
267,
26456,
1628,
14,
1099,
14,
9517,
15192,
3326,
14,
267,
6630,
376,
9697,
1059,
883,
506,
2138,
626,
911,
506,
9164,
370,
314,
922,
267,
436,
1077,
8120,
2005,
2539,
1063,
402,
314,
5988,
4499,
267,
334,
69,
14,
71,
2020,
298,
2944,
8100,
401,
298,
1877,
63,
3359,
63,
19495,
401,
5423,
25860,
267,
408,
267,
367,
1004,
315,
10822,
8,
1199,
304,
288,
340,
1004,
14,
2460,
480,
3170,
26,
2349,
355,
340,
298,
2593,
2,
315,
1004,
14,
2325,
837,
490,
372,
298,
8899,
2,
355,
587,
26,
490,
372,
289,
2,
3170,
11459,
9913,
1552,
2,
288,
916,
1004,
14,
2460,
480,
2889,
9107,
436,
298,
19823,
2,
315,
1004,
26,
355,
372,
754,
14,
9517,
63,
19823,
63,
24345,
1244,
288,
916,
1004,
14,
2460,
480,
2889,
9107,
436,
298,
15064,
2,
315,
1004,
26,
355,
372,
754,
14,
9517,
63,
15064,
63,
19926,
288,
916,
1004,
14,
2460,
480,
2889,
531,
436,
298,
22162,
2,
315,
1004,
26,
355,
372,
754,
14,
9517,
63,
22162,
267,
372,
754,
14,
9517,
63,
11588,
339,
347,
664,
63,
585,
63,
504,
63,
1199,
8,
277,
12,
2385,
12,
5148,
304,
267,
367,
1004,
315,
10822,
8,
1278,
304,
288,
3851,
275,
5148,
288,
340,
3851,
1988,
17,
61,
1137,
7244,
582,
355,
3851,
847,
14725,
288,
1336,
275,
295,
14,
1431,
8,
70,
2,
11683,
3401,
93,
7059,
8,
3672,
4186,
1004,
9,
288,
340,
1336,
436,
1336,
14,
923,
8,
17,
304,
355,
372,
1336,
14,
923,
8,
17,
680,
1913,
342,
267,
372,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
570,
365,
1777,
402,
699,
5368,
4858,
12,
282,
10059,
367,
32150,
12338,
316,
26,
199,
3,
4178,
921,
5031,
14,
957,
15,
83,
736,
89,
13,
5561,
15,
16571,
1628,
199,
3,
199,
3,
6988,
19596,
13,
1173,
7384,
1872,
26,
10219,
13,
13934,
25866,
75,
6423,
23009,
665,
2859,
921,
1544,
14,
83,
736,
89,
13,
5561,
14,
1308,
30,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
3668,
13,
18,
14,
16,
199,
199,
646,
295,
199,
646,
26456,
1628,
14,
1099,
465,
754,
199,
646,
26456,
1628,
14,
1974,
465,
4884,
199,
646,
26456,
1628,
14,
2537,
14,
1160,
421,
199,
533,
15650,
8,
16571,
1628,
14,
2537,
14,
1160,
14,
1563,
5157,
304,
272,
408,
272,
15650,
2256,
367,
307,
4361,
511,
13,
5768,
11822,
334,
2859,
921,
30615,
14,
957,
15,
83,
736,
89,
13,
5561,
15,
15619,
15,
396,
13,
908,
680,
272,
408,
339,
25090,
63,
20202,
275,
2097,
1548,
63,
3112,
401,
298,
773,
401,
298,
1393,
937,
339,
347,
2240,
63,
1725,
8,
277,
12,
7286,
304,
267,
372,
291,
423,
6815,
63,
1725,
63,
504,
63,
5904,
8,
288,
7286,
12,
291,
14,
12496,
63,
20202,
12,
1676,
63,
694,
29,
549,
267,
776,
339,
347,
7286,
8,
277,
304,
267,
372,
4884,
14,
1623,
63,
5904,
8,
288,
298,
84,
4361,
13,
14239,
13,
11034,
401,
298,
1393,
15,
84,
4361,
13,
14239,
13,
11034,
2,
267,
776,
339,
347,
1015,
8,
277,
12,
7286,
304,
267,
372,
291,
423,
1023,
63,
504,
63,
3557,
8,
5904,
9,
339,
347,
536,
8,
277,
304,
267,
372,
298,
52,
4361,
1379,
13,
5768,
4821,
707,
2,
339,
347,
6705,
63,
1099,
8,
277,
12,
17630,
12,
372,
4653,
12,
1072,
12,
365,
6372,
304,
267,
408,
267,
6077,
314,
1072,
402,
314,
4744,
436,
5536,
314,
14786,
754,
14,
267,
961,
1083,
3544,
4839,
370,
506,
10087,
14,
267,
982,
314,
4744,
486,
811,
282,
754,
12,
642,
1083,
4839,
370,
372,
1373,
402,
314,
267,
26456,
1628,
14,
1099,
14,
9517,
15192,
3326,
14,
267,
6630,
376,
9697,
1059,
883,
506,
2138,
626,
911,
506,
9164,
370,
314,
922,
267,
436,
1077,
8120,
2005,
2539,
1063,
402,
314,
5988,
4499,
267,
334,
69,
14,
71,
2020,
298,
2944,
8100,
401,
298,
1877,
63,
3359,
63,
19495,
401,
5423,
25860,
267,
408,
267,
367,
1004,
315,
10822,
8,
1199,
304,
288,
340,
1004,
14,
2460,
480,
3170,
26,
2349,
355,
340,
298,
2593,
2,
315,
1004,
14,
2325,
837,
490,
372,
298,
8899,
2,
355,
587,
26,
490,
372,
289,
2,
3170,
11459,
9913,
1552,
2,
288,
916,
1004,
14,
2460,
480,
2889,
9107,
436,
298,
19823,
2,
315,
1004,
26,
355,
372,
754,
14,
9517,
63,
19823,
63,
24345,
1244,
288,
916,
1004,
14,
2460,
480,
2889,
9107,
436,
298,
15064,
2,
315,
1004,
26,
355,
372,
754,
14,
9517,
63,
15064,
63,
19926,
288,
916,
1004,
14,
2460,
480,
2889,
531,
436,
298,
22162,
2,
315,
1004,
26,
355,
372,
754,
14,
9517,
63,
22162,
267,
372,
754,
14,
9517,
63,
11588,
339,
347,
664,
63,
585,
63,
504,
63,
1199,
8,
277,
12,
2385,
12,
5148,
304,
267,
367,
1004,
315,
10822,
8,
1278,
304,
288,
3851,
275,
5148,
288,
340,
3851,
1988,
17,
61,
1137,
7244,
582,
355,
3851,
847,
14725,
288,
1336,
275,
295,
14,
1431,
8,
70,
2,
11683,
3401,
93,
7059,
8,
3672,
4186,
1004,
9,
288,
340,
1336,
436,
1336,
14,
923,
8,
17,
304,
355,
372,
1336,
14,
923,
8,
17,
680,
1913,
342,
267,
372,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rhurkes/chasegame
|
venv/lib/python2.7/site-packages/rsa/cli.py
|
79
|
12016
|
# -*- coding: utf-8 -*-
#
# Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu>
#
# 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.
'''Commandline scripts.
These scripts are called by the executables defined in setup.py.
'''
from __future__ import with_statement, print_function
import abc
import sys
from optparse import OptionParser
import rsa
import rsa.bigfile
import rsa.pkcs1
HASH_METHODS = sorted(rsa.pkcs1.HASH_METHODS.keys())
def keygen():
'''Key generator.'''
# Parse the CLI options
parser = OptionParser(usage='usage: %prog [options] keysize',
description='Generates a new RSA keypair of "keysize" bits.')
parser.add_option('--pubout', type='string',
help='Output filename for the public key. The public key is '
'not saved if this option is not present. You can use '
'pyrsa-priv2pub to create the public key file later.')
parser.add_option('-o', '--out', type='string',
help='Output filename for the private key. The key is '
'written to stdout if this option is not present.')
parser.add_option('--form',
help='key format of the private and public keys - default PEM',
choices=('PEM', 'DER'), default='PEM')
(cli, cli_args) = parser.parse_args(sys.argv[1:])
if len(cli_args) != 1:
parser.print_help()
raise SystemExit(1)
try:
keysize = int(cli_args[0])
except ValueError:
parser.print_help()
print('Not a valid number: %s' % cli_args[0], file=sys.stderr)
raise SystemExit(1)
print('Generating %i-bit key' % keysize, file=sys.stderr)
(pub_key, priv_key) = rsa.newkeys(keysize)
# Save public key
if cli.pubout:
print('Writing public key to %s' % cli.pubout, file=sys.stderr)
data = pub_key.save_pkcs1(format=cli.form)
with open(cli.pubout, 'wb') as outfile:
outfile.write(data)
# Save private key
data = priv_key.save_pkcs1(format=cli.form)
if cli.out:
print('Writing private key to %s' % cli.out, file=sys.stderr)
with open(cli.out, 'wb') as outfile:
outfile.write(data)
else:
print('Writing private key to stdout', file=sys.stderr)
sys.stdout.write(data)
class CryptoOperation(object):
'''CLI callable that operates with input, output, and a key.'''
__metaclass__ = abc.ABCMeta
keyname = 'public' # or 'private'
usage = 'usage: %%prog [options] %(keyname)s_key'
description = None
operation = 'decrypt'
operation_past = 'decrypted'
operation_progressive = 'decrypting'
input_help = 'Name of the file to %(operation)s. Reads from stdin if ' \
'not specified.'
output_help = 'Name of the file to write the %(operation_past)s file ' \
'to. Written to stdout if this option is not present.'
expected_cli_args = 1
has_output = True
key_class = rsa.PublicKey
def __init__(self):
self.usage = self.usage % self.__class__.__dict__
self.input_help = self.input_help % self.__class__.__dict__
self.output_help = self.output_help % self.__class__.__dict__
@abc.abstractmethod
def perform_operation(self, indata, key, cli_args=None):
'''Performs the program's operation.
Implement in a subclass.
:returns: the data to write to the output.
'''
def __call__(self):
'''Runs the program.'''
(cli, cli_args) = self.parse_cli()
key = self.read_key(cli_args[0], cli.keyform)
indata = self.read_infile(cli.input)
print(self.operation_progressive.title(), file=sys.stderr)
outdata = self.perform_operation(indata, key, cli_args)
if self.has_output:
self.write_outfile(outdata, cli.output)
def parse_cli(self):
'''Parse the CLI options
:returns: (cli_opts, cli_args)
'''
parser = OptionParser(usage=self.usage, description=self.description)
parser.add_option('-i', '--input', type='string', help=self.input_help)
if self.has_output:
parser.add_option('-o', '--output', type='string', help=self.output_help)
parser.add_option('--keyform',
help='Key format of the %s key - default PEM' % self.keyname,
choices=('PEM', 'DER'), default='PEM')
(cli, cli_args) = parser.parse_args(sys.argv[1:])
if len(cli_args) != self.expected_cli_args:
parser.print_help()
raise SystemExit(1)
return (cli, cli_args)
def read_key(self, filename, keyform):
'''Reads a public or private key.'''
print('Reading %s key from %s' % (self.keyname, filename), file=sys.stderr)
with open(filename, 'rb') as keyfile:
keydata = keyfile.read()
return self.key_class.load_pkcs1(keydata, keyform)
def read_infile(self, inname):
'''Read the input file'''
if inname:
print('Reading input from %s' % inname, file=sys.stderr)
with open(inname, 'rb') as infile:
return infile.read()
print('Reading input from stdin', file=sys.stderr)
return sys.stdin.read()
def write_outfile(self, outdata, outname):
'''Write the output file'''
if outname:
print('Writing output to %s' % outname, file=sys.stderr)
with open(outname, 'wb') as outfile:
outfile.write(outdata)
else:
print('Writing output to stdout', file=sys.stderr)
sys.stdout.write(outdata)
class EncryptOperation(CryptoOperation):
'''Encrypts a file.'''
keyname = 'public'
description = ('Encrypts a file. The file must be shorter than the key '
'length in order to be encrypted. For larger files, use the '
'pyrsa-encrypt-bigfile command.')
operation = 'encrypt'
operation_past = 'encrypted'
operation_progressive = 'encrypting'
def perform_operation(self, indata, pub_key, cli_args=None):
'''Encrypts files.'''
return rsa.encrypt(indata, pub_key)
class DecryptOperation(CryptoOperation):
'''Decrypts a file.'''
keyname = 'private'
description = ('Decrypts a file. The original file must be shorter than '
'the key length in order to have been encrypted. For larger '
'files, use the pyrsa-decrypt-bigfile command.')
operation = 'decrypt'
operation_past = 'decrypted'
operation_progressive = 'decrypting'
key_class = rsa.PrivateKey
def perform_operation(self, indata, priv_key, cli_args=None):
'''Decrypts files.'''
return rsa.decrypt(indata, priv_key)
class SignOperation(CryptoOperation):
'''Signs a file.'''
keyname = 'private'
usage = 'usage: %%prog [options] private_key hash_method'
description = ('Signs a file, outputs the signature. Choose the hash '
'method from %s' % ', '.join(HASH_METHODS))
operation = 'sign'
operation_past = 'signature'
operation_progressive = 'Signing'
key_class = rsa.PrivateKey
expected_cli_args = 2
output_help = ('Name of the file to write the signature to. Written '
'to stdout if this option is not present.')
def perform_operation(self, indata, priv_key, cli_args):
'''Decrypts files.'''
hash_method = cli_args[1]
if hash_method not in HASH_METHODS:
raise SystemExit('Invalid hash method, choose one of %s' %
', '.join(HASH_METHODS))
return rsa.sign(indata, priv_key, hash_method)
class VerifyOperation(CryptoOperation):
'''Verify a signature.'''
keyname = 'public'
usage = 'usage: %%prog [options] public_key signature_file'
description = ('Verifies a signature, exits with status 0 upon success, '
'prints an error message and exits with status 1 upon error.')
operation = 'verify'
operation_past = 'verified'
operation_progressive = 'Verifying'
key_class = rsa.PublicKey
expected_cli_args = 2
has_output = False
def perform_operation(self, indata, pub_key, cli_args):
'''Decrypts files.'''
signature_file = cli_args[1]
with open(signature_file, 'rb') as sigfile:
signature = sigfile.read()
try:
rsa.verify(indata, signature, pub_key)
except rsa.VerificationError:
raise SystemExit('Verification failed.')
print('Verification OK', file=sys.stderr)
class BigfileOperation(CryptoOperation):
'''CryptoOperation that doesn't read the entire file into memory.'''
def __init__(self):
CryptoOperation.__init__(self)
self.file_objects = []
def __del__(self):
'''Closes any open file handles.'''
for fobj in self.file_objects:
fobj.close()
def __call__(self):
'''Runs the program.'''
(cli, cli_args) = self.parse_cli()
key = self.read_key(cli_args[0], cli.keyform)
# Get the file handles
infile = self.get_infile(cli.input)
outfile = self.get_outfile(cli.output)
# Call the operation
print(self.operation_progressive.title(), file=sys.stderr)
self.perform_operation(infile, outfile, key, cli_args)
def get_infile(self, inname):
'''Returns the input file object'''
if inname:
print('Reading input from %s' % inname, file=sys.stderr)
fobj = open(inname, 'rb')
self.file_objects.append(fobj)
else:
print('Reading input from stdin', file=sys.stderr)
fobj = sys.stdin
return fobj
def get_outfile(self, outname):
'''Returns the output file object'''
if outname:
print('Will write output to %s' % outname, file=sys.stderr)
fobj = open(outname, 'wb')
self.file_objects.append(fobj)
else:
print('Will write output to stdout', file=sys.stderr)
fobj = sys.stdout
return fobj
class EncryptBigfileOperation(BigfileOperation):
'''Encrypts a file to VARBLOCK format.'''
keyname = 'public'
description = ('Encrypts a file to an encrypted VARBLOCK file. The file '
'can be larger than the key length, but the output file is only '
'compatible with Python-RSA.')
operation = 'encrypt'
operation_past = 'encrypted'
operation_progressive = 'encrypting'
def perform_operation(self, infile, outfile, pub_key, cli_args=None):
'''Encrypts files to VARBLOCK.'''
return rsa.bigfile.encrypt_bigfile(infile, outfile, pub_key)
class DecryptBigfileOperation(BigfileOperation):
'''Decrypts a file in VARBLOCK format.'''
keyname = 'private'
description = ('Decrypts an encrypted VARBLOCK file that was encrypted '
'with pyrsa-encrypt-bigfile')
operation = 'decrypt'
operation_past = 'decrypted'
operation_progressive = 'decrypting'
key_class = rsa.PrivateKey
def perform_operation(self, infile, outfile, priv_key, cli_args=None):
'''Decrypts a VARBLOCK file.'''
return rsa.bigfile.decrypt_bigfile(infile, outfile, priv_key)
encrypt = EncryptOperation()
decrypt = DecryptOperation()
sign = SignOperation()
verify = VerifyOperation()
encrypt_bigfile = EncryptBigfileOperation()
decrypt_bigfile = DecryptBigfileOperation()
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
1898,
7760,
5515,
66,
828,
437,
14,
1933,
17709,
1090,
665,
1786,
66,
828,
32,
270,
85,
1090,
14,
16913,
30,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
2344,
3110,
604,
10554,
14,
199,
199,
20676,
10554,
787,
2797,
701,
314,
31172,
3247,
315,
3272,
14,
647,
14,
199,
2344,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
12,
870,
63,
1593,
199,
199,
646,
13022,
199,
646,
984,
199,
504,
8691,
492,
13491,
199,
199,
646,
23609,
199,
646,
23609,
14,
5076,
493,
199,
646,
23609,
14,
27100,
17,
199,
199,
14395,
63,
18383,
275,
3355,
8,
13487,
14,
27100,
17,
14,
14395,
63,
18383,
14,
1612,
1012,
199,
199,
318,
790,
2268,
837,
272,
1449,
1197,
4306,
10595,
339,
327,
6077,
314,
14214,
1511,
272,
1798,
275,
13491,
8,
3807,
534,
3807,
26,
450,
6595,
359,
1419,
61,
790,
890,
297,
288,
1369,
534,
20551,
282,
892,
18471,
23911,
402,
298,
498,
890,
2,
5821,
2659,
2286,
1798,
14,
525,
63,
1422,
4517,
5645,
548,
297,
730,
534,
875,
297,
288,
1720,
534,
2959,
1788,
367,
314,
4575,
790,
14,
710,
4575,
790,
365,
283,
288,
283,
1397,
6290,
340,
642,
945,
365,
440,
3451,
14,
2047,
883,
675,
283,
288,
283,
647,
13487,
13,
10605,
18,
5645,
370,
1218,
314,
4575,
790,
570,
2945,
2659,
2286,
1798,
14,
525,
63,
1422,
3654,
79,
297,
2850,
548,
297,
730,
534,
875,
297,
288,
1720,
534,
2959,
1788,
367,
314,
5726,
790,
14,
710,
790,
365,
283,
288,
283,
8938,
370,
3839,
340,
642,
945,
365,
440,
3451,
2659,
339,
1798,
14,
525,
63,
1422,
4517,
964,
297,
288,
1720,
534,
498,
1475,
402,
314,
5726,
436,
4575,
2883,
446,
849,
25957,
297,
288,
3415,
7782,
24160,
297,
283,
11733,
659,
849,
534,
24160,
358,
339,
334,
2764,
12,
5053,
63,
589,
9,
275,
1798,
14,
1122,
63,
589,
8,
1274,
14,
3020,
59,
17,
5728,
339,
340,
822,
8,
2764,
63,
589,
9,
1137,
413,
26,
267,
1798,
14,
1361,
63,
3437,
342,
267,
746,
14838,
8,
17,
9,
2286,
862,
26,
267,
790,
890,
275,
1109,
8,
2764,
63,
589,
59,
16,
566,
272,
871,
1722,
26,
267,
1798,
14,
1361,
63,
3437,
342,
267,
870,
360,
1763,
282,
1686,
1329,
26,
450,
83,
7,
450,
5053,
63,
589,
59,
16,
467,
570,
29,
1274,
14,
3083,
9,
267,
746,
14838,
8,
17,
9,
339,
870,
360,
29244,
450,
73,
13,
2075,
790,
7,
450,
790,
890,
12,
570,
29,
1274,
14,
3083,
9,
272,
334,
5645,
63,
498,
12,
16254,
63,
498,
9,
275,
23609,
14,
1222,
1612,
8,
498,
890,
9,
2378,
327,
11063,
4575,
790,
272,
340,
5053,
14,
5645,
548,
26,
267,
870,
360,
16646,
4575,
790,
370,
450,
83,
7,
450,
5053,
14,
5645,
548,
12,
570,
29,
1274,
14,
3083,
9,
267,
666,
275,
7974,
63,
498,
14,
2117,
63,
27100,
17,
8,
908,
29,
2764,
14,
964,
9,
267,
543,
1551,
8,
2764,
14,
5645,
548,
12,
283,
6603,
358,
465,
4386,
26,
288,
4386,
14,
952,
8,
576,
9,
339,
327,
11063,
5726,
790,
272,
666,
275,
16254,
63,
498,
14,
2117,
63,
27100,
17,
8,
908,
29,
2764,
14,
964,
9,
2286,
340,
5053,
14,
548,
26,
267,
870,
360,
16646,
5726,
790,
370,
450,
83,
7,
450,
5053,
14,
548,
12,
570,
29,
1274,
14,
3083,
9,
267,
543,
1551,
8,
2764,
14,
548,
12,
283,
6603,
358,
465,
4386,
26,
288,
4386,
14,
952,
8,
576,
9,
272,
587,
26,
267,
870,
360,
16646,
5726,
790,
370,
3839,
297,
570,
29,
1274,
14,
3083,
9,
267,
984,
14,
2703,
14,
952,
8,
576,
9,
421,
199,
533,
18855,
6044,
8,
785,
304,
272,
1449,
7802,
4550,
626,
1758,
2335,
543,
1324,
12,
1072,
12,
436,
282,
790,
10595,
339,
636,
6577,
363,
275,
13022,
14,
22254,
339,
790,
354,
275,
283,
3455,
7,
327,
503,
283,
4239,
7,
272,
4503,
275,
283,
3807,
26,
11539,
6595,
359,
1419,
61,
2818,
30499,
9,
83,
63,
498,
7,
272,
1369,
275,
488,
272,
3439,
275,
283,
15682,
7,
272,
3439,
63,
18597,
275,
283,
271,
8274,
7,
272,
3439,
63,
6595,
470,
3398,
275,
283,
15682,
316,
7,
272,
1324,
63,
3437,
275,
283,
985,
402,
314,
570,
370,
2818,
5735,
9,
83,
14,
26129,
687,
9009,
340,
283,
971,
288,
283,
1397,
2013,
3530,
272,
1072,
63,
3437,
275,
283,
985,
402,
314,
570,
370,
2218,
314,
2818,
5735,
63,
18597,
9,
83,
570,
283,
971,
288,
283,
475,
14,
27694,
370,
3839,
340,
642,
945,
365,
440,
3451,
3530,
272,
1420,
63,
2764,
63,
589,
275,
413,
272,
965,
63,
1199,
275,
715,
339,
790,
63,
533,
275,
23609,
14,
26238,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3807,
275,
291,
14,
3807,
450,
291,
855,
533,
4914,
807,
363,
267,
291,
14,
1210,
63,
3437,
275,
291,
14,
1210,
63,
3437,
450,
291,
855,
533,
4914,
807,
363,
267,
291,
14,
1199,
63,
3437,
275,
291,
14,
1199,
63,
3437,
450,
291,
855,
533,
4914,
807,
363,
339,
768,
3175,
14,
10315,
272,
347,
5147,
63,
5735,
8,
277,
12,
315,
576,
12,
790,
12,
5053,
63,
589,
29,
403,
304,
267,
1449,
2623,
3351,
314,
2240
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
1898,
7760,
5515,
66,
828,
437,
14,
1933,
17709,
1090,
665,
1786,
66,
828,
32,
270,
85,
1090,
14,
16913,
30,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
2344,
3110,
604,
10554,
14,
199,
199,
20676,
10554,
787,
2797,
701,
314,
31172,
3247,
315,
3272,
14,
647,
14,
199,
2344,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
12,
870,
63,
1593,
199,
199,
646,
13022,
199,
646,
984,
199,
504,
8691,
492,
13491,
199,
199,
646,
23609,
199,
646,
23609,
14,
5076,
493,
199,
646,
23609,
14,
27100,
17,
199,
199,
14395,
63,
18383,
275,
3355,
8,
13487,
14,
27100,
17,
14,
14395,
63,
18383,
14,
1612,
1012,
199,
199,
318,
790,
2268,
837,
272,
1449,
1197,
4306,
10595,
339,
327,
6077,
314,
14214,
1511,
272,
1798,
275,
13491,
8,
3807,
534,
3807,
26,
450,
6595,
359,
1419,
61,
790,
890,
297,
288,
1369,
534,
20551,
282,
892,
18471,
23911,
402,
298,
498,
890,
2,
5821,
2659,
2286,
1798,
14,
525,
63,
1422,
4517,
5645,
548,
297,
730,
534,
875,
297,
288,
1720,
534,
2959,
1788,
367,
314,
4575,
790,
14,
710,
4575,
790,
365,
283,
288,
283,
1397,
6290,
340,
642,
945,
365,
440,
3451,
14,
2047,
883,
675,
283,
288,
283,
647,
13487,
13,
10605,
18,
5645,
370,
1218,
314,
4575,
790,
570,
2945,
2659,
2286,
1798,
14,
525,
63,
1422,
3654,
79,
297,
2850,
548,
297,
730,
534,
875,
297,
288,
1720,
534,
2959,
1788,
367,
314,
5726,
790,
14,
710,
790,
365,
283,
288,
283,
8938,
370,
3839,
340,
642,
945,
365,
440,
3451,
2659,
339,
1798,
14,
525,
63,
1422,
4517,
964,
297,
288,
1720,
534,
498,
1475,
402,
314,
5726,
436,
4575,
2883,
446,
849,
25957,
297,
288,
3415,
7782,
24160,
297,
283,
11733,
659,
849,
534,
24160,
358,
339,
334,
2764,
12,
5053,
63,
589,
9,
275,
1798,
14,
1122,
63,
589,
8,
1274,
14,
3020,
59,
17,
5728,
339,
340,
822,
8,
2764,
63,
589,
9,
1137,
413,
26,
267,
1798,
14,
1361,
63,
3437,
342,
267,
746,
14838,
8,
17,
9,
2286,
862,
26,
267,
790,
890,
275,
1109,
8,
2764,
63,
589,
59,
16,
566,
272,
871,
1722,
26,
267,
1798,
14,
1361,
63,
3437,
342,
267,
870,
360,
1763,
282,
1686,
1329,
26,
450,
83,
7,
450,
5053,
63,
589,
59,
16,
467,
570,
29,
1274,
14,
3083,
9,
267,
746,
14838,
8,
17,
9,
339,
870,
360,
29244,
450,
73,
13,
2075,
790,
7,
450,
790,
890,
12,
570,
29,
1274,
14,
3083,
9,
272,
334,
5645,
63,
498,
12,
16254,
63,
498,
9,
275,
23609,
14,
1222,
1612,
8,
498,
890,
9,
2378,
327,
11063,
4575,
790,
272,
340,
5053,
14,
5645,
548,
26,
267,
870,
360,
16646,
4575,
790,
370,
450,
83,
7,
450,
5053,
14,
5645,
548,
12,
570,
29,
1274,
14,
3083,
9,
267,
666,
275,
7974,
63,
498,
14,
2117,
63,
27100,
17,
8,
908,
29,
2764,
14,
964,
9,
267,
543,
1551,
8,
2764,
14,
5645,
548,
12,
283,
6603,
358,
465,
4386,
26,
288,
4386,
14,
952,
8,
576,
9,
339,
327,
11063,
5726,
790,
272,
666,
275,
16254,
63,
498,
14,
2117,
63,
27100,
17,
8,
908,
29,
2764,
14,
964,
9,
2286,
340,
5053,
14,
548,
26,
267,
870,
360,
16646,
5726,
790,
370,
450,
83,
7,
450,
5053,
14,
548,
12,
570,
29,
1274,
14,
3083,
9,
267,
543,
1551,
8,
2764,
14,
548,
12,
283,
6603,
358,
465,
4386,
26,
288,
4386,
14,
952,
8,
576,
9,
272,
587,
26,
267,
870,
360,
16646,
5726,
790,
370,
3839,
297,
570,
29,
1274,
14,
3083,
9,
267,
984,
14,
2703,
14,
952,
8,
576,
9,
421,
199,
533,
18855,
6044,
8,
785,
304,
272,
1449,
7802,
4550,
626,
1758,
2335,
543,
1324,
12,
1072,
12,
436,
282,
790,
10595,
339,
636,
6577,
363,
275,
13022,
14,
22254,
339,
790,
354,
275,
283,
3455,
7,
327,
503,
283,
4239,
7,
272,
4503,
275,
283,
3807,
26,
11539,
6595,
359,
1419,
61,
2818,
30499,
9,
83,
63,
498,
7,
272,
1369,
275,
488,
272,
3439,
275,
283,
15682,
7,
272,
3439,
63,
18597,
275,
283,
271,
8274,
7,
272,
3439,
63,
6595,
470,
3398,
275,
283,
15682,
316,
7,
272,
1324,
63,
3437,
275,
283,
985,
402,
314,
570,
370,
2818,
5735,
9,
83,
14,
26129,
687,
9009,
340,
283,
971,
288,
283,
1397,
2013,
3530,
272,
1072,
63,
3437,
275,
283,
985,
402,
314,
570,
370,
2218,
314,
2818,
5735,
63,
18597,
9,
83,
570,
283,
971,
288,
283,
475,
14,
27694,
370,
3839,
340,
642,
945,
365,
440,
3451,
3530,
272,
1420,
63,
2764,
63,
589,
275,
413,
272,
965,
63,
1199,
275,
715,
339,
790,
63,
533,
275,
23609,
14,
26238,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3807,
275,
291,
14,
3807,
450,
291,
855,
533,
4914,
807,
363,
267,
291,
14,
1210,
63,
3437,
275,
291,
14,
1210,
63,
3437,
450,
291,
855,
533,
4914,
807,
363,
267,
291,
14,
1199,
63,
3437,
275,
291,
14,
1199,
63,
3437,
450,
291,
855,
533,
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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
] |
jswope00/GAI
|
common/test/acceptance/pages/studio/auto_auth.py
|
10
|
2168
|
"""
Auto-auth page (used to automatically log in during testing).
"""
import re
import urllib
from bok_choy.page_object import PageObject
from . import BASE_URL
class AutoAuthPage(PageObject):
"""
The automatic authorization page.
When allowed via the django settings file, visiting
this url will create a user and log them in.
"""
def __init__(self, browser, username=None, email=None, password=None, staff=None, course_id=None, roles=None):
"""
Auto-auth is an end-point for HTTP GET requests.
By default, it will create accounts with random user credentials,
but you can also specify credentials using querystring parameters.
`username`, `email`, and `password` are the user's credentials (strings)
`staff` is a boolean indicating whether the user is global staff.
`course_id` is the ID of the course to enroll the student in.
Currently, this has the form "org/number/run"
Note that "global staff" is NOT the same as course staff.
"""
super(AutoAuthPage, self).__init__(browser)
# Create query string parameters if provided
self._params = {}
if username is not None:
self._params['username'] = username
if email is not None:
self._params['email'] = email
if password is not None:
self._params['password'] = password
if staff is not None:
self._params['staff'] = "true" if staff else "false"
if course_id is not None:
self._params['course_id'] = course_id
if roles is not None:
self._params['roles'] = roles
@property
def url(self):
"""
Construct the URL.
"""
url = BASE_URL + "/auto_auth"
query_str = urllib.urlencode(self._params)
if query_str:
url += "?" + query_str
return url
def is_browser_on_page(self):
return True
def get_user_id(self):
message = self.q(css='BODY').text[0].strip()
match = re.search(r' user_id ([^$]+)$', message)
return match.groups()[0] if match else None
|
agpl-3.0
|
[
624,
199,
3358,
13,
1178,
2034,
334,
2972,
370,
5847,
943,
315,
5309,
5343,
680,
199,
624,
199,
199,
646,
295,
199,
646,
4011,
199,
504,
330,
745,
63,
2239,
89,
14,
1606,
63,
785,
492,
10331,
1692,
199,
504,
1275,
492,
19721,
63,
2632,
421,
199,
533,
9195,
2817,
3276,
8,
3276,
1692,
304,
272,
408,
272,
710,
4834,
13448,
2034,
14,
272,
3979,
4370,
4799,
314,
1639,
2202,
570,
12,
1321,
338,
1337,
272,
642,
1166,
911,
1218,
282,
922,
436,
943,
3062,
315,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
7042,
12,
3434,
29,
403,
12,
3031,
29,
403,
12,
2505,
29,
403,
12,
12622,
29,
403,
12,
2518,
63,
344,
29,
403,
12,
11689,
29,
403,
304,
267,
408,
267,
9195,
13,
1178,
365,
376,
1284,
13,
1403,
367,
3101,
9576,
4145,
14,
267,
4885,
849,
12,
652,
911,
1218,
12639,
543,
2196,
922,
6235,
12,
267,
1325,
1265,
883,
2597,
4165,
6235,
1808,
1827,
875,
2633,
14,
398,
658,
2473,
3559,
658,
2123,
3559,
436,
658,
2060,
64,
787,
314,
922,
1159,
6235,
334,
5465,
9,
267,
658,
7018,
64,
365,
282,
5046,
9297,
3775,
314,
922,
365,
2288,
12622,
14,
267,
658,
1972,
63,
344,
64,
365,
314,
2870,
402,
314,
2518,
370,
26361,
314,
6474,
315,
14,
267,
13550,
12,
642,
965,
314,
1824,
298,
1308,
15,
1955,
15,
1065,
2,
398,
3390,
626,
298,
2966,
12622,
2,
365,
2845,
314,
2011,
465,
2518,
12622,
14,
267,
408,
267,
1613,
8,
3358,
2817,
3276,
12,
291,
2843,
826,
721,
5750,
9,
398,
327,
2790,
1827,
1059,
2633,
340,
2741,
267,
291,
423,
1162,
275,
1052,
398,
340,
3434,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
2473,
418,
275,
3434,
398,
340,
3031,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
2123,
418,
275,
3031,
398,
340,
2505,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
2060,
418,
275,
2505,
398,
340,
12622,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
7018,
418,
275,
298,
2052,
2,
340,
12622,
587,
298,
3910,
2,
398,
340,
2518,
63,
344,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
1972,
63,
344,
418,
275,
2518,
63,
344,
398,
340,
11689,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
8050,
418,
275,
11689,
339,
768,
1829,
272,
347,
1166,
8,
277,
304,
267,
408,
267,
9215,
314,
2851,
14,
267,
408,
267,
1166,
275,
19721,
63,
2632,
435,
3286,
2495,
63,
1178,
2,
267,
1827,
63,
495,
275,
4011,
14,
10738,
8,
277,
423,
1162,
9,
398,
340,
1827,
63,
495,
26,
288,
1166,
847,
29325,
435,
1827,
63,
495,
398,
372,
1166,
339,
347,
365,
63,
5750,
63,
265,
63,
1606,
8,
277,
304,
267,
372,
715,
339,
347,
664,
63,
751,
63,
344,
8,
277,
304,
267,
1245,
275,
291,
14,
81,
8,
3919,
534,
23708,
1959,
505,
59,
16,
1055,
1913,
342,
267,
1336,
275,
295,
14,
1733,
8,
82,
7,
922,
63,
344,
334,
4735,
4,
11896,
4268,
1245,
9,
267,
372,
1336,
14,
2634,
3430,
16,
61,
340,
1336,
587,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3358,
13,
1178,
2034,
334,
2972,
370,
5847,
943,
315,
5309,
5343,
680,
199,
624,
199,
199,
646,
295,
199,
646,
4011,
199,
504,
330,
745,
63,
2239,
89,
14,
1606,
63,
785,
492,
10331,
1692,
199,
504,
1275,
492,
19721,
63,
2632,
421,
199,
533,
9195,
2817,
3276,
8,
3276,
1692,
304,
272,
408,
272,
710,
4834,
13448,
2034,
14,
272,
3979,
4370,
4799,
314,
1639,
2202,
570,
12,
1321,
338,
1337,
272,
642,
1166,
911,
1218,
282,
922,
436,
943,
3062,
315,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
7042,
12,
3434,
29,
403,
12,
3031,
29,
403,
12,
2505,
29,
403,
12,
12622,
29,
403,
12,
2518,
63,
344,
29,
403,
12,
11689,
29,
403,
304,
267,
408,
267,
9195,
13,
1178,
365,
376,
1284,
13,
1403,
367,
3101,
9576,
4145,
14,
267,
4885,
849,
12,
652,
911,
1218,
12639,
543,
2196,
922,
6235,
12,
267,
1325,
1265,
883,
2597,
4165,
6235,
1808,
1827,
875,
2633,
14,
398,
658,
2473,
3559,
658,
2123,
3559,
436,
658,
2060,
64,
787,
314,
922,
1159,
6235,
334,
5465,
9,
267,
658,
7018,
64,
365,
282,
5046,
9297,
3775,
314,
922,
365,
2288,
12622,
14,
267,
658,
1972,
63,
344,
64,
365,
314,
2870,
402,
314,
2518,
370,
26361,
314,
6474,
315,
14,
267,
13550,
12,
642,
965,
314,
1824,
298,
1308,
15,
1955,
15,
1065,
2,
398,
3390,
626,
298,
2966,
12622,
2,
365,
2845,
314,
2011,
465,
2518,
12622,
14,
267,
408,
267,
1613,
8,
3358,
2817,
3276,
12,
291,
2843,
826,
721,
5750,
9,
398,
327,
2790,
1827,
1059,
2633,
340,
2741,
267,
291,
423,
1162,
275,
1052,
398,
340,
3434,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
2473,
418,
275,
3434,
398,
340,
3031,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
2123,
418,
275,
3031,
398,
340,
2505,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
2060,
418,
275,
2505,
398,
340,
12622,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
7018,
418,
275,
298,
2052,
2,
340,
12622,
587,
298,
3910,
2,
398,
340,
2518,
63,
344,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
1972,
63,
344,
418,
275,
2518,
63,
344,
398,
340,
11689,
365,
440,
488,
26,
288,
291,
423,
1162,
459,
8050,
418,
275,
11689,
339,
768,
1829,
272,
347,
1166,
8,
277,
304,
267,
408,
267,
9215,
314,
2851,
14,
267,
408,
267,
1166,
275,
19721,
63,
2632,
435,
3286,
2495,
63,
1178,
2,
267,
1827,
63,
495,
275,
4011,
14,
10738,
8,
277,
423,
1162,
9,
398,
340,
1827,
63,
495,
26,
288,
1166,
847,
29325,
435,
1827,
63,
495,
398,
372,
1166,
339,
347,
365,
63,
5750,
63,
265,
63,
1606,
8,
277,
304,
267,
372,
715,
339,
347,
664,
63,
751,
63,
344,
8,
277,
304,
267,
1245,
275,
291,
14,
81,
8,
3919,
534,
23708,
1959,
505,
59,
16,
1055,
1913,
342,
267,
1336,
275,
295,
14,
1733,
8,
82,
7,
922,
63,
344,
334,
4735,
4,
11896,
4268,
1245,
9,
267,
372,
1336,
14,
2634,
3430,
16,
61,
340,
1336,
587,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Rasor1911/stagger
|
test/__init__.py
|
16
|
1483
|
#
# __init__.py
# From the stagger project: http://code.google.com/p/stagger/
#
# Copyright (c) 2009-2011 Karoly Lorentey <karoly@lorentey.hu>
# 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.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import test.alltests;
|
bsd-2-clause
|
[
3,
199,
3,
636,
826,
4343,
647,
199,
3,
11606,
314,
410,
16267,
2199,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
270,
16267,
15,
199,
3,
199,
3,
1898,
334,
67,
9,
8937,
13,
8128,
1804,
285,
16242,
491,
720,
78,
266,
89,
221,
665,
75,
285,
16242,
32,
320,
828,
266,
89,
14,
10616,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
221,
199,
3,
446,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
199,
3,
446,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
3,
257,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
257,
4084,
14,
199,
3,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
511,
14,
452,
2219,
27,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
636,
826,
4343,
647,
199,
3,
11606,
314,
410,
16267,
2199,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
270,
16267,
15,
199,
3,
199,
3,
1898,
334,
67,
9,
8937,
13,
8128,
1804,
285,
16242,
491,
720,
78,
266,
89,
221,
665,
75,
285,
16242,
32,
320,
828,
266,
89,
14,
10616,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
221,
199,
3,
446,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
199,
3,
446,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
3,
257,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
257,
4084,
14,
199,
3,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
511,
14,
452,
2219,
27,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
PHSTARS/hovercraft
|
hovercraft/__init__.py
|
3
|
6030
|
import argparse
import gettext
import os
import sys
import threading
import time
from collections import defaultdict
from http.server import HTTPServer, SimpleHTTPRequestHandler
from tempfile import TemporaryDirectory
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from .generate import generate
class HovercraftEventHandler(FileSystemEventHandler):
def __init__(self, filelist):
self.filelist = filelist
self.quit = False
super().__init__()
def on_modified(self, event):
if event.src_path in self.filelist:
print("File %s modified, update presentation" % event.src_path)
self.quit = True
def generate_and_observe(args, event):
while event.isSet():
# Generate the presentation
monitor_list = generate(args)
print("Presentation generated.")
# Make a list of involved directories
directories = defaultdict(list)
for file in monitor_list:
directory, filename = os.path.split(file)
directories[directory].append(filename)
observer = Observer()
handler = HovercraftEventHandler(monitor_list)
for directory, files in directories.items():
observer.schedule(handler, directory, recursive=False)
observer.start()
while event.wait(1):
if handler.quit:
break
observer.stop()
observer.join()
def main():
# That the argparse default strings are lowercase is ugly.
def my_gettext(s):
return s.capitalize()
gettext.gettext = my_gettext
parser = argparse.ArgumentParser(
description='Create impress.js presentations with reStructuredText',
add_help=False)
parser.add_argument(
'presentation',
metavar='<presentation>',
help='The path to the reStructuredText presentation file.')
parser.add_argument(
'targetdir',
metavar='<targetdir>',
nargs='?',
help=('The directory where the presentation is saved. Will be created '
'if it does not exist. If you do not specify a targetdir '
'Hovercraft! will instead start a webserver and serve the '
'presentation from that server.'))
parser.add_argument(
'-h', '--help',
action='help',
help='Show this help.')
parser.add_argument(
'-t',
'--template',
help=('Specify a template. Must be a .cfg file, or a directory with a '
'template.cfg file. If not given it will use a default template.'))
parser.add_argument(
'-c',
'--css',
help=('An additional css file for the presentation to use. '
'See also the ``:css:`` settings of the presentation.'))
parser.add_argument(
'-a',
'--auto-console',
action='store_true',
help=('Open the presenter console automatically. This is useful when '
'you are rehearsing and making sure the presenter notes are '
'correct. You can also set this by having ``:auto-console: '
'true`` first in the presentation.'))
parser.add_argument(
'-s',
'--skip-help',
action='store_true',
help=('Do not show the initial help popup.'))
parser.add_argument(
'-n',
'--skip-notes',
action='store_true',
help=('Do not include presenter notes in the output.'))
parser.add_argument(
'-p',
'--port',
default='0.0.0.0:8000',
help=('The address and port that the server uses. '
'Ex 8080 or 127.0.0.1:9000. Defaults to 0.0.0.0:8000.'))
args = parser.parse_args()
# XXX Bit of a hack, clean this up, I check for this twice, also in the template.
if args.template and args.template not in ('simple', 'default'):
args.template = os.path.abspath(args.template)
if args.targetdir:
# Generate the presentation
generate(args)
else:
# Server mode. Start a server that serves a temporary directory.
with TemporaryDirectory() as targetdir:
args.targetdir = targetdir
args.presentation = os.path.abspath(args.presentation)
# Set up watchdog to regenerate presentation if saved.
event = threading.Event()
event.set()
thread = threading.Thread(target=generate_and_observe, args=(args, event))
try:
# Serve presentation
if ':' in args.port:
bind, port = args.port.split(':')
else:
bind, port = '0.0.0.0', args.port
port = int(port)
# First create the server. This checks that we can connect to
# the port we want to.
os.chdir(targetdir)
server = HTTPServer((bind, port), SimpleHTTPRequestHandler)
print("Serving HTTP on", bind, "port", port, "...")
try:
# Now generate the presentation
thread.start()
try:
# All is good, start the server
server.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")
finally:
# Server exited
server.server_close()
finally:
# Stop the generation thread
event.clear()
# Wait for it to end
thread.join()
except PermissionError:
print("Can't bind to port %s:%s: No permission" % (bind, port))
except OSError as e:
if e.errno == 98:
print("Can't bind to port %s:%s: port already in use" % (bind, port))
else:
raise
|
mit
|
[
646,
7534,
199,
646,
9796,
199,
646,
747,
199,
646,
984,
199,
646,
5796,
199,
646,
900,
199,
504,
5055,
492,
10018,
199,
504,
1455,
14,
1000,
492,
3101,
3120,
12,
5870,
23518,
199,
504,
5549,
492,
21791,
6231,
199,
504,
9626,
13889,
14,
2873,
5871,
492,
17985,
1000,
199,
504,
9626,
13889,
14,
4368,
492,
23754,
2390,
2461,
199,
199,
504,
1275,
4208,
492,
3550,
421,
199,
533,
869,
1883,
32342,
2390,
2461,
8,
17521,
2390,
2461,
304,
272,
347,
636,
826,
721,
277,
12,
26148,
304,
267,
291,
14,
14964,
275,
26148,
267,
291,
14,
10589,
275,
756,
267,
1613,
11027,
826,
4533,
339,
347,
641,
63,
5540,
8,
277,
12,
1566,
304,
267,
340,
1566,
14,
2164,
63,
515,
315,
291,
14,
14964,
26,
288,
870,
480,
1173,
450,
83,
6042,
12,
1678,
3451,
425,
2,
450,
1566,
14,
2164,
63,
515,
9,
288,
291,
14,
10589,
275,
715,
421,
199,
318,
3550,
63,
460,
63,
2873,
4909,
8,
589,
12,
1566,
304,
272,
1830,
1566,
14,
374,
1084,
837,
267,
327,
7958,
314,
3451,
425,
267,
8372,
63,
513,
275,
3550,
8,
589,
9,
267,
870,
480,
19794,
425,
4046,
2685,
398,
327,
4155,
282,
769,
402,
28244,
6602,
267,
6602,
275,
10018,
8,
513,
9,
267,
367,
570,
315,
8372,
63,
513,
26,
288,
2082,
12,
1788,
275,
747,
14,
515,
14,
1294,
8,
493,
9,
288,
6602,
59,
3619,
1055,
740,
8,
1501,
9,
398,
27336,
275,
17985,
1000,
342,
267,
3016,
275,
869,
1883,
32342,
2390,
2461,
8,
7157,
63,
513,
9,
267,
367,
2082,
12,
1584,
315,
6602,
14,
1744,
837,
288,
27336,
14,
7211,
8,
2232,
12,
2082,
12,
9133,
29,
797,
9,
398,
27336,
14,
928,
342,
267,
1830,
1566,
14,
2573,
8,
17,
304,
288,
340,
3016,
14,
10589,
26,
355,
2059,
398,
27336,
14,
2379,
342,
267,
27336,
14,
904,
342,
421,
199,
318,
2446,
837,
339,
327,
10314,
314,
7534,
849,
3326,
787,
12141,
365,
23761,
14,
339,
347,
3002,
63,
5152,
8,
83,
304,
267,
372,
308,
14,
18351,
342,
339,
9796,
14,
5152,
275,
3002,
63,
5152,
339,
1798,
275,
7534,
14,
10730,
8,
267,
1369,
534,
2499,
1742,
753,
14,
3596,
3451,
1298,
543,
295,
27486,
1872,
297,
267,
1050,
63,
3437,
29,
797,
9,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
31993,
297,
267,
8214,
15829,
31993,
4206,
267,
1720,
534,
1918,
931,
370,
314,
295,
27486,
1872,
3451,
425,
570,
2659,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
1375,
694,
297,
267,
8214,
15829,
1375,
694,
4206,
267,
9237,
31468,
267,
1720,
7782,
1918,
2082,
2382,
314,
3451,
425,
365,
6290,
14,
12823,
506,
2737,
283,
1598,
283,
692,
652,
1630,
440,
2187,
14,
982,
1265,
886,
440,
4165,
282,
1347,
694,
283,
1598,
283,
40,
1883,
32342,
1,
911,
3140,
1343,
282,
3330,
1000,
436,
14062,
314,
283,
1598,
283,
31993,
687,
626,
1654,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
72,
297,
2850,
3437,
297,
267,
1595,
534,
3437,
297,
267,
1720,
534,
6824,
642,
1720,
2659,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
84,
297,
267,
2850,
1160,
297,
267,
1720,
7782,
17768,
282,
1978,
14,
9498,
506,
282,
1275,
4128,
570,
12,
503,
282,
2082,
543,
282,
283,
1598,
283,
1160,
14,
4128,
570,
14,
982,
440,
1627,
652,
911,
675,
282,
849,
1978,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
67,
297,
267,
2850,
3919,
297,
267,
1720,
7782,
2493,
4722,
11431,
570,
367,
314,
3451,
425,
370,
675,
14,
283,
1598,
283,
9295,
2597,
314,
1124,
26,
3919,
5409,
2202,
402,
314,
3451,
425,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
65,
297,
267,
2850,
2495,
13,
6614,
297,
267,
1595,
534,
1617,
63,
2052,
297,
267,
1720,
7782,
4299,
314,
23250,
351,
8559,
5847,
14,
961,
365,
2997,
1380,
283,
1598,
283,
13297,
787,
295,
426,
285,
1044,
436,
10663,
3238,
314,
23250,
351,
12681,
787,
283,
1598,
283,
4525,
14,
2047,
883,
2597,
663,
642,
701,
9445,
1124,
26,
2495,
13,
6614,
26,
283,
1598,
283,
2052,
1040,
1642,
315,
314,
3451,
425,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
83,
297,
267,
2850,
2759,
13,
3437,
297,
267,
1595,
534,
1617,
63,
2052,
297,
267,
1720,
7782,
2585,
440,
2498,
314,
2536,
1720,
22365,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
78,
297,
267,
2850,
2759,
13,
5983,
297,
267,
1595,
534,
1617,
63,
2052,
297,
267,
1720,
7782,
2585,
440,
2387,
23250,
351,
12681,
315,
314,
1072,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
80,
297,
267,
2850,
719,
297,
267,
849,
534,
16,
14,
16,
14,
16,
14,
16,
26,
15214,
297,
267,
1720,
7782,
1918,
2287,
436,
1844,
626,
314,
1654,
4440,
14,
283,
1598,
283,
920,
30220,
503,
12792,
14,
16,
14,
16,
14,
17,
26,
25,
1493,
14,
7827,
370,
378,
14,
16,
14,
16,
14,
16,
26,
15214,
12459,
339,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
327,
5787,
10199,
402,
282,
11176,
12,
3633,
642,
1536,
12,
473,
1104,
367,
642,
13373,
12,
2597,
315,
314,
1978,
14,
272,
340,
1249,
14,
1160,
436,
1249,
14,
1160,
440,
315,
661,
4129,
297,
283,
885,
735,
267,
1249,
14,
1160,
275,
747,
14,
515,
14,
4832,
8,
589,
14,
1160,
9,
339,
340,
1249,
14,
1375,
694,
26,
267,
327,
7958,
314,
3451,
425,
267,
3550,
8,
589,
9,
272,
587,
26,
267,
327,
7146,
818,
14,
7707,
282,
1654,
626,
23739,
282,
7937,
2082,
14,
398,
543,
21791,
6231,
342,
465,
1347,
694,
26,
288,
1249,
14,
1375,
694,
275,
1347,
694,
288,
1249,
14,
31993,
275,
747,
14,
515,
14,
4832,
8,
589,
14,
31993,
9,
953,
327,
2494,
1536,
9626,
13889,
370,
30943,
3451,
425,
340,
6290,
14,
288,
1566,
275,
5796,
14,
2390,
342,
288,
1566,
14,
409,
342,
288,
2462,
275,
5796,
14,
4436,
8,
1375,
29,
4208,
63,
460,
63,
2873,
4909,
12,
1249,
2687,
589,
12,
1566,
430,
288,
862,
26,
355,
327,
3739,
432,
3451,
425,
355
] |
[
7534,
199,
646,
9796,
199,
646,
747,
199,
646,
984,
199,
646,
5796,
199,
646,
900,
199,
504,
5055,
492,
10018,
199,
504,
1455,
14,
1000,
492,
3101,
3120,
12,
5870,
23518,
199,
504,
5549,
492,
21791,
6231,
199,
504,
9626,
13889,
14,
2873,
5871,
492,
17985,
1000,
199,
504,
9626,
13889,
14,
4368,
492,
23754,
2390,
2461,
199,
199,
504,
1275,
4208,
492,
3550,
421,
199,
533,
869,
1883,
32342,
2390,
2461,
8,
17521,
2390,
2461,
304,
272,
347,
636,
826,
721,
277,
12,
26148,
304,
267,
291,
14,
14964,
275,
26148,
267,
291,
14,
10589,
275,
756,
267,
1613,
11027,
826,
4533,
339,
347,
641,
63,
5540,
8,
277,
12,
1566,
304,
267,
340,
1566,
14,
2164,
63,
515,
315,
291,
14,
14964,
26,
288,
870,
480,
1173,
450,
83,
6042,
12,
1678,
3451,
425,
2,
450,
1566,
14,
2164,
63,
515,
9,
288,
291,
14,
10589,
275,
715,
421,
199,
318,
3550,
63,
460,
63,
2873,
4909,
8,
589,
12,
1566,
304,
272,
1830,
1566,
14,
374,
1084,
837,
267,
327,
7958,
314,
3451,
425,
267,
8372,
63,
513,
275,
3550,
8,
589,
9,
267,
870,
480,
19794,
425,
4046,
2685,
398,
327,
4155,
282,
769,
402,
28244,
6602,
267,
6602,
275,
10018,
8,
513,
9,
267,
367,
570,
315,
8372,
63,
513,
26,
288,
2082,
12,
1788,
275,
747,
14,
515,
14,
1294,
8,
493,
9,
288,
6602,
59,
3619,
1055,
740,
8,
1501,
9,
398,
27336,
275,
17985,
1000,
342,
267,
3016,
275,
869,
1883,
32342,
2390,
2461,
8,
7157,
63,
513,
9,
267,
367,
2082,
12,
1584,
315,
6602,
14,
1744,
837,
288,
27336,
14,
7211,
8,
2232,
12,
2082,
12,
9133,
29,
797,
9,
398,
27336,
14,
928,
342,
267,
1830,
1566,
14,
2573,
8,
17,
304,
288,
340,
3016,
14,
10589,
26,
355,
2059,
398,
27336,
14,
2379,
342,
267,
27336,
14,
904,
342,
421,
199,
318,
2446,
837,
339,
327,
10314,
314,
7534,
849,
3326,
787,
12141,
365,
23761,
14,
339,
347,
3002,
63,
5152,
8,
83,
304,
267,
372,
308,
14,
18351,
342,
339,
9796,
14,
5152,
275,
3002,
63,
5152,
339,
1798,
275,
7534,
14,
10730,
8,
267,
1369,
534,
2499,
1742,
753,
14,
3596,
3451,
1298,
543,
295,
27486,
1872,
297,
267,
1050,
63,
3437,
29,
797,
9,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
31993,
297,
267,
8214,
15829,
31993,
4206,
267,
1720,
534,
1918,
931,
370,
314,
295,
27486,
1872,
3451,
425,
570,
2659,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
1375,
694,
297,
267,
8214,
15829,
1375,
694,
4206,
267,
9237,
31468,
267,
1720,
7782,
1918,
2082,
2382,
314,
3451,
425,
365,
6290,
14,
12823,
506,
2737,
283,
1598,
283,
692,
652,
1630,
440,
2187,
14,
982,
1265,
886,
440,
4165,
282,
1347,
694,
283,
1598,
283,
40,
1883,
32342,
1,
911,
3140,
1343,
282,
3330,
1000,
436,
14062,
314,
283,
1598,
283,
31993,
687,
626,
1654,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
72,
297,
2850,
3437,
297,
267,
1595,
534,
3437,
297,
267,
1720,
534,
6824,
642,
1720,
2659,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
84,
297,
267,
2850,
1160,
297,
267,
1720,
7782,
17768,
282,
1978,
14,
9498,
506,
282,
1275,
4128,
570,
12,
503,
282,
2082,
543,
282,
283,
1598,
283,
1160,
14,
4128,
570,
14,
982,
440,
1627,
652,
911,
675,
282,
849,
1978,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
67,
297,
267,
2850,
3919,
297,
267,
1720,
7782,
2493,
4722,
11431,
570,
367,
314,
3451,
425,
370,
675,
14,
283,
1598,
283,
9295,
2597,
314,
1124,
26,
3919,
5409,
2202,
402,
314,
3451,
425,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
65,
297,
267,
2850,
2495,
13,
6614,
297,
267,
1595,
534,
1617,
63,
2052,
297,
267,
1720,
7782,
4299,
314,
23250,
351,
8559,
5847,
14,
961,
365,
2997,
1380,
283,
1598,
283,
13297,
787,
295,
426,
285,
1044,
436,
10663,
3238,
314,
23250,
351,
12681,
787,
283,
1598,
283,
4525,
14,
2047,
883,
2597,
663,
642,
701,
9445,
1124,
26,
2495,
13,
6614,
26,
283,
1598,
283,
2052,
1040,
1642,
315,
314,
3451,
425,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
83,
297,
267,
2850,
2759,
13,
3437,
297,
267,
1595,
534,
1617,
63,
2052,
297,
267,
1720,
7782,
2585,
440,
2498,
314,
2536,
1720,
22365,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
78,
297,
267,
2850,
2759,
13,
5983,
297,
267,
1595,
534,
1617,
63,
2052,
297,
267,
1720,
7782,
2585,
440,
2387,
23250,
351,
12681,
315,
314,
1072,
12459,
272,
1798,
14,
525,
63,
2094,
8,
267,
2475,
80,
297,
267,
2850,
719,
297,
267,
849,
534,
16,
14,
16,
14,
16,
14,
16,
26,
15214,
297,
267,
1720,
7782,
1918,
2287,
436,
1844,
626,
314,
1654,
4440,
14,
283,
1598,
283,
920,
30220,
503,
12792,
14,
16,
14,
16,
14,
17,
26,
25,
1493,
14,
7827,
370,
378,
14,
16,
14,
16,
14,
16,
26,
15214,
12459,
339,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
327,
5787,
10199,
402,
282,
11176,
12,
3633,
642,
1536,
12,
473,
1104,
367,
642,
13373,
12,
2597,
315,
314,
1978,
14,
272,
340,
1249,
14,
1160,
436,
1249,
14,
1160,
440,
315,
661,
4129,
297,
283,
885,
735,
267,
1249,
14,
1160,
275,
747,
14,
515,
14,
4832,
8,
589,
14,
1160,
9,
339,
340,
1249,
14,
1375,
694,
26,
267,
327,
7958,
314,
3451,
425,
267,
3550,
8,
589,
9,
272,
587,
26,
267,
327,
7146,
818,
14,
7707,
282,
1654,
626,
23739,
282,
7937,
2082,
14,
398,
543,
21791,
6231,
342,
465,
1347,
694,
26,
288,
1249,
14,
1375,
694,
275,
1347,
694,
288,
1249,
14,
31993,
275,
747,
14,
515,
14,
4832,
8,
589,
14,
31993,
9,
953,
327,
2494,
1536,
9626,
13889,
370,
30943,
3451,
425,
340,
6290,
14,
288,
1566,
275,
5796,
14,
2390,
342,
288,
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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
] |
mrroach/CentralServer
|
csrv/model/cards/runner/card01020.py
|
1
|
2867
|
from csrv.model import actions
from csrv.model import timing_phases
from csrv.model.cards import card_info
from csrv.model.cards import event
class ChooseUnrezzedIce(timing_phases.BasePhase):
"""Choose unrezzed ice to force the corp to rez or trash it."""
DESCRIPTION = 'Choose unrezzed ice to force the corp to rez or trash it.'
NULL_OK = False
def __init__(self, game, player, card):
timing_phases.BasePhase.__init__(self, game, player, both_players=False)
self.card = card
def choices(self, refresh=False):
if not self._choices or refresh:
self._choices = self.card.force_rez_actions()
return self._choices
def resolve(self, choice, response=None):
timing_phases.BasePhase.resolve(self, choice, response)
if choice:
self.end_phase()
class ForceRezAction(actions.Action):
"""Force the corp to rez or trash ice."""
DESCRIPTION = 'Force the corp to either rez this ice or trash it'
def resolve(self, response=None, ignore_clicks=False, ignore_all_costs=False):
actions.Action.resolve(self, response,
ignore_clicks=ignore_clicks,
ignore_all_costs=ignore_all_costs)
self.game.insert_next_phase(
RezOrTrash(self.game, self.game.corp, self.card))
class RezOrTrash(timing_phases.BasePhase):
"""Decide whether to rez ice or trash it."""
DESCRIPTION = 'Decide whether to rez ice or trash it.'
NULL_CHOICE = 'Trash the ice'
def __init__(self, game, player, ice):
timing_phases.BasePhase.__init__(self, game, player, both_players=False)
self.ice = ice
def choices(self, refresh=False):
if not self._choices or refresh:
self._choices = self.ice.rez_actions()
return self._choices
def resolve(self, choice, response=None):
timing_phases.BasePhase.resolve(self, choice, response)
if choice:
self.end_phase()
else:
self.game.log('The corp chooses to trash the ice.')
self.ice.trash()
class Card01020(event.Event):
NAME = u'Card01020'
SET = card_info.CORE
NUMBER = 20
SIDE = card_info.RUNNER
FACTION = card_info.CRIMINAL
INFLUENCE = 2
UNIQUE = False
KEYWORDS = set([
card_info.SABOTAGE,
])
COST = 1
IMAGE_SRC = '01020.png'
def build_actions(self):
event.Event.build_actions(self)
def play(self):
event.Event.play(self)
self.game.insert_next_phase(ChooseUnrezzedIce(self.game, self.player, self))
def is_playable(self):
return event.Event.is_playable(self) and bool(self.unrezzed_ice())
def force_rez_actions(self):
return [ForceRezAction(self.game, self.player, card=ice)
for ice in self.unrezzed_ice()]
def unrezzed_ice(self):
targets = []
for server in self.game.corp.servers:
for ice in server.ice.cards:
if not ice.is_rezzed:
targets.append(ice)
return targets
|
apache-2.0
|
[
504,
286,
15165,
14,
1238,
492,
5445,
199,
504,
286,
15165,
14,
1238,
492,
20542,
63,
14236,
199,
504,
286,
15165,
14,
1238,
14,
13761,
492,
12564,
63,
815,
199,
504,
286,
15165,
14,
1238,
14,
13761,
492,
1566,
421,
199,
533,
29826,
1358,
264,
4348,
379,
41,
301,
8,
14639,
63,
14236,
14,
1563,
10521,
304,
523,
408,
23932,
625,
264,
4348,
379,
284,
301,
370,
3542,
314,
1970,
80,
370,
295,
90,
503,
5651,
1119,
652,
1041,
819,
17410,
1075,
275,
283,
23932,
625,
264,
4348,
379,
284,
301,
370,
3542,
314,
1970,
80,
370,
295,
90,
503,
5651,
1119,
652,
3530,
523,
5962,
63,
3593,
275,
756,
819,
347,
636,
826,
721,
277,
12,
9219,
12,
7748,
12,
12564,
304,
272,
20542,
63,
14236,
14,
1563,
10521,
855,
826,
721,
277,
12,
9219,
12,
7748,
12,
3865,
63,
20716,
29,
797,
9,
272,
291,
14,
5841,
275,
12564,
819,
347,
3415,
8,
277,
12,
9236,
29,
797,
304,
272,
340,
440,
291,
423,
4577,
503,
9236,
26,
489,
291,
423,
4577,
275,
291,
14,
5841,
14,
3990,
63,
25409,
63,
3723,
342,
272,
372,
291,
423,
4577,
819,
347,
7512,
8,
277,
12,
7141,
12,
1177,
29,
403,
304,
272,
20542,
63,
14236,
14,
1563,
10521,
14,
6983,
8,
277,
12,
7141,
12,
1177,
9,
272,
340,
7141,
26,
489,
291,
14,
500,
63,
6971,
342,
421,
199,
533,
18771,
497,
90,
3310,
8,
3723,
14,
3310,
304,
523,
408,
13606,
314,
1970,
80,
370,
295,
90,
503,
5651,
1119,
284,
301,
1041,
523,
17410,
1075,
275,
283,
13606,
314,
1970,
80,
370,
1902,
295,
90,
642,
284,
301,
503,
5651,
1119,
652,
7,
819,
347,
7512,
8,
277,
12,
1177,
29,
403,
12,
3686,
63,
4891,
83,
29,
797,
12,
3686,
63,
452,
63,
25432,
29,
797,
304,
272,
5445,
14,
3310,
14,
6983,
8,
277,
12,
1177,
12,
2574,
3686,
63,
4891,
83,
29,
4247,
63,
4891,
83,
12,
2574,
3686,
63,
452,
63,
25432,
29,
4247,
63,
452,
63,
25432,
9,
272,
291,
14,
5097,
14,
3176,
63,
2184,
63,
6971,
8,
267,
799,
90,
2844,
14064,
1119,
8,
277,
14,
5097,
12,
291,
14,
5097,
14,
989,
80,
12,
291,
14,
5841,
430,
421,
199,
533,
799,
90,
2844,
14064,
1119,
8,
14639,
63,
14236,
14,
1563,
10521,
304,
523,
408,
872,
559,
271,
3775,
370,
295,
90,
284,
301,
503,
5651,
1119,
652,
1041,
523,
17410,
1075,
275,
283,
872,
559,
271,
3775,
370,
295,
90,
284,
301,
503,
5651,
1119,
652,
3530,
523,
5962,
63,
22544,
275,
283,
14064,
1119,
314,
284,
301,
7,
819,
347,
636,
826,
721,
277,
12,
9219,
12,
7748,
12,
284,
301,
304,
272,
20542,
63,
14236,
14,
1563,
10521,
855,
826,
721,
277,
12,
9219,
12,
7748,
12,
3865,
63,
20716,
29,
797,
9,
272,
291,
14,
1885,
275,
284,
301,
819,
347,
3415,
8,
277,
12,
9236,
29,
797,
304,
272,
340,
440,
291,
423,
4577,
503,
9236,
26,
489,
291,
423,
4577,
275,
291,
14,
1885,
14,
25409,
63,
3723,
342,
272,
372,
291,
423,
4577,
819,
347,
7512,
8,
277,
12,
7141,
12,
1177,
29,
403,
304,
272,
20542,
63,
14236,
14,
1563,
10521,
14,
6983,
8,
277,
12,
7141,
12,
1177,
9,
272,
340,
7141,
26,
489,
291,
14,
500,
63,
6971,
342,
272,
587,
26,
489,
291,
14,
5097,
14,
793,
360,
1918,
1970,
80,
2468,
32128,
370,
5651,
1119,
314,
284,
301,
2659,
489,
291,
14,
1885,
14,
28272,
342,
421,
199,
533,
445,
1005,
614,
10173,
8,
1430,
14,
2390,
304,
819,
13637,
275,
399,
7,
13832,
614,
10173,
7,
523,
11543,
275,
12564,
63,
815,
14,
24428,
523,
18122,
275,
3388,
523,
428,
11259,
275,
12564,
63,
815,
14,
9390,
15215,
523,
481,
10052,
275,
12564,
63,
815,
14,
2944,
1469,
13384,
523,
1621,
3143,
53,
6013,
275,
499,
523,
6778,
41,
10526,
275,
756,
523,
9301,
19984,
275,
663,
779,
489,
12564,
63,
815,
14,
51,
1217,
1387,
2962,
12,
523,
4794,
523,
5099,
840,
275,
413,
523,
25228,
63,
12447,
275,
283,
614,
10173,
14,
4524,
7,
819,
347,
1900,
63,
3723,
8,
277,
304,
272,
1566,
14,
2390,
14,
1506,
63,
3723,
8,
277,
9,
819,
347,
5232,
8,
277,
304,
272,
1566,
14,
2390,
14,
2802,
8,
277,
9,
272,
291,
14,
5097,
14,
3176,
63,
2184,
63,
6971,
8,
23932,
1358,
264,
4348,
379,
41,
301,
8,
277,
14,
5097,
12,
291,
14,
6147,
12,
291,
430,
819,
347,
365,
63,
2802,
461,
8,
277,
304,
272,
372,
1566,
14,
2390,
14,
374,
63,
2802,
461,
8,
277,
9,
436,
2155,
8,
277,
14,
324,
264,
4348,
379,
63,
1885,
1012,
819,
347,
3542,
63,
25409,
63,
3723,
8,
277,
304,
272,
372,
359,
13606,
497,
90,
3310,
8,
277,
14,
5097,
12,
291,
14,
6147,
12,
12564,
29,
1885,
9,
288,
367,
284,
301,
315,
291,
14,
324,
264,
4348,
379,
63,
1885,
5106,
819,
347,
625,
264,
4348,
379,
63,
1885,
8,
277,
304,
272,
4545,
275,
942,
272,
367,
1654,
315,
291,
14,
5097,
14,
989,
80,
14,
5871,
26,
489,
367,
284,
301,
315,
1654,
14,
1885,
14,
13761,
26,
267,
340,
440,
284,
301,
14,
374,
63,
264,
4348,
379,
26,
881,
4545,
14,
740,
8,
1885,
9,
272,
372,
4545,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
286,
15165,
14,
1238,
492,
5445,
199,
504,
286,
15165,
14,
1238,
492,
20542,
63,
14236,
199,
504,
286,
15165,
14,
1238,
14,
13761,
492,
12564,
63,
815,
199,
504,
286,
15165,
14,
1238,
14,
13761,
492,
1566,
421,
199,
533,
29826,
1358,
264,
4348,
379,
41,
301,
8,
14639,
63,
14236,
14,
1563,
10521,
304,
523,
408,
23932,
625,
264,
4348,
379,
284,
301,
370,
3542,
314,
1970,
80,
370,
295,
90,
503,
5651,
1119,
652,
1041,
819,
17410,
1075,
275,
283,
23932,
625,
264,
4348,
379,
284,
301,
370,
3542,
314,
1970,
80,
370,
295,
90,
503,
5651,
1119,
652,
3530,
523,
5962,
63,
3593,
275,
756,
819,
347,
636,
826,
721,
277,
12,
9219,
12,
7748,
12,
12564,
304,
272,
20542,
63,
14236,
14,
1563,
10521,
855,
826,
721,
277,
12,
9219,
12,
7748,
12,
3865,
63,
20716,
29,
797,
9,
272,
291,
14,
5841,
275,
12564,
819,
347,
3415,
8,
277,
12,
9236,
29,
797,
304,
272,
340,
440,
291,
423,
4577,
503,
9236,
26,
489,
291,
423,
4577,
275,
291,
14,
5841,
14,
3990,
63,
25409,
63,
3723,
342,
272,
372,
291,
423,
4577,
819,
347,
7512,
8,
277,
12,
7141,
12,
1177,
29,
403,
304,
272,
20542,
63,
14236,
14,
1563,
10521,
14,
6983,
8,
277,
12,
7141,
12,
1177,
9,
272,
340,
7141,
26,
489,
291,
14,
500,
63,
6971,
342,
421,
199,
533,
18771,
497,
90,
3310,
8,
3723,
14,
3310,
304,
523,
408,
13606,
314,
1970,
80,
370,
295,
90,
503,
5651,
1119,
284,
301,
1041,
523,
17410,
1075,
275,
283,
13606,
314,
1970,
80,
370,
1902,
295,
90,
642,
284,
301,
503,
5651,
1119,
652,
7,
819,
347,
7512,
8,
277,
12,
1177,
29,
403,
12,
3686,
63,
4891,
83,
29,
797,
12,
3686,
63,
452,
63,
25432,
29,
797,
304,
272,
5445,
14,
3310,
14,
6983,
8,
277,
12,
1177,
12,
2574,
3686,
63,
4891,
83,
29,
4247,
63,
4891,
83,
12,
2574,
3686,
63,
452,
63,
25432,
29,
4247,
63,
452,
63,
25432,
9,
272,
291,
14,
5097,
14,
3176,
63,
2184,
63,
6971,
8,
267,
799,
90,
2844,
14064,
1119,
8,
277,
14,
5097,
12,
291,
14,
5097,
14,
989,
80,
12,
291,
14,
5841,
430,
421,
199,
533,
799,
90,
2844,
14064,
1119,
8,
14639,
63,
14236,
14,
1563,
10521,
304,
523,
408,
872,
559,
271,
3775,
370,
295,
90,
284,
301,
503,
5651,
1119,
652,
1041,
523,
17410,
1075,
275,
283,
872,
559,
271,
3775,
370,
295,
90,
284,
301,
503,
5651,
1119,
652,
3530,
523,
5962,
63,
22544,
275,
283,
14064,
1119,
314,
284,
301,
7,
819,
347,
636,
826,
721,
277,
12,
9219,
12,
7748,
12,
284,
301,
304,
272,
20542,
63,
14236,
14,
1563,
10521,
855,
826,
721,
277,
12,
9219,
12,
7748,
12,
3865,
63,
20716,
29,
797,
9,
272,
291,
14,
1885,
275,
284,
301,
819,
347,
3415,
8,
277,
12,
9236,
29,
797,
304,
272,
340,
440,
291,
423,
4577,
503,
9236,
26,
489,
291,
423,
4577,
275,
291,
14,
1885,
14,
25409,
63,
3723,
342,
272,
372,
291,
423,
4577,
819,
347,
7512,
8,
277,
12,
7141,
12,
1177,
29,
403,
304,
272,
20542,
63,
14236,
14,
1563,
10521,
14,
6983,
8,
277,
12,
7141,
12,
1177,
9,
272,
340,
7141,
26,
489,
291,
14,
500,
63,
6971,
342,
272,
587,
26,
489,
291,
14,
5097,
14,
793,
360,
1918,
1970,
80,
2468,
32128,
370,
5651,
1119,
314,
284,
301,
2659,
489,
291,
14,
1885,
14,
28272,
342,
421,
199,
533,
445,
1005,
614,
10173,
8,
1430,
14,
2390,
304,
819,
13637,
275,
399,
7,
13832,
614,
10173,
7,
523,
11543,
275,
12564,
63,
815,
14,
24428,
523,
18122,
275,
3388,
523,
428,
11259,
275,
12564,
63,
815,
14,
9390,
15215,
523,
481,
10052,
275,
12564,
63,
815,
14,
2944,
1469,
13384,
523,
1621,
3143,
53,
6013,
275,
499,
523,
6778,
41,
10526,
275,
756,
523,
9301,
19984,
275,
663,
779,
489,
12564,
63,
815,
14,
51,
1217,
1387,
2962,
12,
523,
4794,
523,
5099,
840,
275,
413,
523,
25228,
63,
12447,
275,
283,
614,
10173,
14,
4524,
7,
819,
347,
1900,
63,
3723,
8,
277,
304,
272,
1566,
14,
2390,
14,
1506,
63,
3723,
8,
277,
9,
819,
347,
5232,
8,
277,
304,
272,
1566,
14,
2390,
14,
2802,
8,
277,
9,
272,
291,
14,
5097,
14,
3176,
63,
2184,
63,
6971,
8,
23932,
1358,
264,
4348,
379,
41,
301,
8,
277,
14,
5097,
12,
291,
14,
6147,
12,
291,
430,
819,
347,
365,
63,
2802,
461,
8,
277,
304,
272,
372,
1566,
14,
2390,
14,
374,
63,
2802,
461,
8,
277,
9,
436,
2155,
8,
277,
14,
324,
264,
4348,
379,
63,
1885,
1012,
819,
347,
3542,
63,
25409,
63,
3723,
8,
277,
304,
272,
372,
359,
13606,
497,
90,
3310,
8,
277,
14,
5097,
12,
291,
14,
6147,
12,
12564,
29,
1885,
9,
288,
367,
284,
301,
315,
291,
14,
324,
264,
4348,
379,
63,
1885,
5106,
819,
347,
625,
264,
4348,
379,
63,
1885,
8,
277,
304,
272,
4545,
275,
942,
272,
367,
1654,
315,
291,
14,
5097,
14,
989,
80,
14,
5871,
26,
489,
367,
284,
301,
315,
1654,
14,
1885,
14,
13761,
26,
267,
340,
440,
284,
301,
14,
374,
63,
264,
4348,
379,
26,
881,
4545,
14,
740,
8,
1885,
9,
272,
372,
4545,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
Nitaco/ansible
|
lib/ansible/modules/cloud/azure/azure_rm_mysqldatabase.py
|
5
|
10551
|
#!/usr/bin/python
#
# Copyright (c) 2017 Zim Kalinowski, <zikalino@microsoft.com>
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: azure_rm_mysqldatabase
version_added: "2.5"
short_description: Manage MySQL Database instance.
description:
- Create, update and delete instance of MySQL Database.
options:
resource_group:
description:
- The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal.
required: True
server_name:
description:
- The name of the server.
required: True
name:
description:
- The name of the database.
required: True
charset:
description:
- The charset of the database. Check MySQL documentation for possible values.
- This is only set on creation, use I(force_update) to recreate a database if the
values don't match.
collation:
description:
- The collation of the database. Check MySQL documentation for possible values.
- This is only set on creation, use I(force_update) to recreate a database if the
values don't match.
force_update:
description:
- When set to C(true), will delete and recreate the existing MySQL database if any
of the properties don't match what is set.
- When set to C(false), no change will occur to the database even if any
of the properties do not match.
type: bool
default: 'no'
state:
description:
- Assert the state of the MySQL Database. Use 'present' to create or update a database and 'absent' to delete it.
default: present
choices:
- absent
- present
extends_documentation_fragment:
- azure
author:
- "Zim Kalinowski (@zikalino)"
'''
EXAMPLES = '''
- name: Create (or update) MySQL Database
azure_rm_mysqldatabase:
resource_group: TestGroup
server_name: testserver
name: db1
'''
RETURN = '''
id:
description:
- Resource ID
returned: always
type: str
sample: /subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforMySQL/servers/testserver/databases/db1
name:
description:
- Resource name.
returned: always
type: str
sample: db1
'''
import time
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
try:
from azure.mgmt.rdbms.mysql import MySQLManagementClient
from msrestazure.azure_exceptions import CloudError
from msrest.polling import LROPoller
from msrest.serialization import Model
except ImportError:
# This is handled in azure_rm_common
pass
class Actions:
NoAction, Create, Update, Delete = range(4)
class AzureRMDatabases(AzureRMModuleBase):
"""Configuration class for an Azure RM MySQL Database resource"""
def __init__(self):
self.module_arg_spec = dict(
resource_group=dict(
type='str',
required=True
),
server_name=dict(
type='str',
required=True
),
name=dict(
type='str',
required=True
),
charset=dict(
type='str'
),
collation=dict(
type='str'
),
force_update=dict(
type='bool',
default=False
),
state=dict(
type='str',
default='present',
choices=['present', 'absent']
)
)
self.resource_group = None
self.server_name = None
self.name = None
self.parameters = dict()
self.results = dict(changed=False)
self.mgmt_client = None
self.state = None
self.to_do = Actions.NoAction
super(AzureRMDatabases, self).__init__(derived_arg_spec=self.module_arg_spec,
supports_check_mode=True,
supports_tags=False)
def exec_module(self, **kwargs):
"""Main module execution method"""
for key in list(self.module_arg_spec.keys()):
if hasattr(self, key):
setattr(self, key, kwargs[key])
elif kwargs[key] is not None:
if key == "charset":
self.parameters["charset"] = kwargs[key]
elif key == "collation":
self.parameters["collation"] = kwargs[key]
old_response = None
response = None
self.mgmt_client = self.get_mgmt_svc_client(MySQLManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager)
resource_group = self.get_resource_group(self.resource_group)
old_response = self.get_mysqldatabase()
if not old_response:
self.log("MySQL Database instance doesn't exist")
if self.state == 'absent':
self.log("Old instance didn't exist")
else:
self.to_do = Actions.Create
else:
self.log("MySQL Database instance already exists")
if self.state == 'absent':
self.to_do = Actions.Delete
elif self.state == 'present':
self.log("Need to check if MySQL Database instance has to be deleted or may be updated")
if ('collation' in self.parameters) and (self.parameters['collation'] != old_response['collation']):
self.to_do = Actions.Update
if ('charset' in self.parameters) and (self.parameters['charset'] != old_response['charset']):
self.to_do = Actions.Update
if self.to_do == Actions.Update:
if self.force_update:
if not self.check_mode:
self.delete_mysqldatabase()
else:
self.to_do = Actions.NoAction
if (self.to_do == Actions.Create) or (self.to_do == Actions.Update):
self.log("Need to Create / Update the MySQL Database instance")
if self.check_mode:
self.results['changed'] = True
return self.results
response = self.create_update_mysqldatabase()
self.results['changed'] = True
self.log("Creation / Update done")
elif self.to_do == Actions.Delete:
self.log("MySQL Database instance deleted")
self.results['changed'] = True
if self.check_mode:
return self.results
self.delete_mysqldatabase()
# make sure instance is actually deleted, for some Azure resources, instance is hanging around
# for some time after deletion -- this should be really fixed in Azure
while self.get_mysqldatabase():
time.sleep(20)
else:
self.log("MySQL Database instance unchanged")
self.results['changed'] = False
response = old_response
if response:
self.results["id"] = response["id"]
self.results["name"] = response["name"]
return self.results
def create_update_mysqldatabase(self):
'''
Creates or updates MySQL Database with the specified configuration.
:return: deserialized MySQL Database instance state dictionary
'''
self.log("Creating / Updating the MySQL Database instance {0}".format(self.name))
try:
response = self.mgmt_client.databases.create_or_update(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name,
parameters=self.parameters)
if isinstance(response, LROPoller):
response = self.get_poller_result(response)
except CloudError as exc:
self.log('Error attempting to create the MySQL Database instance.')
self.fail("Error creating the MySQL Database instance: {0}".format(str(exc)))
return response.as_dict()
def delete_mysqldatabase(self):
'''
Deletes specified MySQL Database instance in the specified subscription and resource group.
:return: True
'''
self.log("Deleting the MySQL Database instance {0}".format(self.name))
try:
response = self.mgmt_client.databases.delete(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name)
except CloudError as e:
self.log('Error attempting to delete the MySQL Database instance.')
self.fail("Error deleting the MySQL Database instance: {0}".format(str(e)))
return True
def get_mysqldatabase(self):
'''
Gets the properties of the specified MySQL Database.
:return: deserialized MySQL Database instance state dictionary
'''
self.log("Checking if the MySQL Database instance {0} is present".format(self.name))
found = False
try:
response = self.mgmt_client.databases.get(resource_group_name=self.resource_group,
server_name=self.server_name,
database_name=self.name)
found = True
self.log("Response : {0}".format(response))
self.log("MySQL Database instance : {0} found".format(response.name))
except CloudError as e:
self.log('Did not find the MySQL Database instance.')
if found is True:
return response.as_dict()
return False
def main():
"""Main execution"""
AzureRMDatabases()
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
3107,
1017,
1804,
279,
262,
19844,
12,
665,
90,
3258,
279,
10175,
32,
17040,
14,
957,
30,
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,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
13601,
63,
5682,
63,
23726,
81,
1447,
1963,
199,
1023,
63,
3270,
26,
298,
18,
14,
21,
2,
199,
3612,
63,
1802,
26,
14944,
11200,
8692,
1256,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
436,
3145,
1256,
402,
11200,
8692,
14,
199,
199,
1419,
26,
272,
2073,
63,
923,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
2073,
1572,
626,
3509,
314,
2073,
14,
2047,
883,
3332,
642,
574,
687,
314,
15474,
7337,
13537,
3261,
503,
314,
18428,
14,
267,
1415,
26,
715,
272,
1654,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
1654,
14,
267,
1415,
26,
715,
272,
536,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
3050,
14,
267,
1415,
26,
715,
272,
5960,
26,
267,
1369,
26,
288,
446,
710,
5960,
402,
314,
3050,
14,
2670,
11200,
3794,
367,
3962,
1338,
14,
288,
446,
961,
365,
1454,
663,
641,
7143,
12,
675,
473,
8,
3990,
63,
873,
9,
370,
23959,
282,
3050,
340,
314,
1598,
1338,
2793,
1133,
1336,
14,
272,
1048,
2212,
26,
267,
1369,
26,
288,
446,
710,
1048,
2212,
402,
314,
3050,
14,
2670,
11200,
3794,
367,
3962,
1338,
14,
288,
446,
961,
365,
1454,
663,
641,
7143,
12,
675,
473,
8,
3990,
63,
873,
9,
370,
23959,
282,
3050,
340,
314,
1598,
1338,
2793,
1133,
1336,
14,
272,
3542,
63,
873,
26,
489,
1369,
26,
881,
446,
3979,
663,
370,
445,
8,
2052,
395,
911,
3145,
436,
23959,
314,
3411,
11200,
3050,
340,
1263,
288,
402,
314,
4382,
2793,
1133,
1336,
4052,
365,
663,
14,
881,
446,
3979,
663,
370,
445,
8,
3910,
395,
949,
1570,
911,
4781,
370,
314,
3050,
2755,
340,
1263,
288,
402,
314,
4382,
886,
440,
1336,
14,
489,
730,
26,
2155,
489,
849,
26,
283,
889,
7,
272,
1174,
26,
267,
1369,
26,
288,
446,
10716,
314,
1174,
402,
314,
11200,
8692,
14,
3645,
283,
1881,
7,
370,
1218,
503,
1678,
282,
3050,
436,
283,
5575,
7,
370,
3145,
652,
14,
267,
849,
26,
3451,
267,
3415,
26,
288,
446,
9552,
288,
446,
3451,
199,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
13601,
199,
199,
2502,
26,
272,
446,
298,
58,
1017,
1804,
279,
262,
19844,
8593,
90,
3258,
279,
10175,
2924,
199,
199,
2344,
199,
199,
8918,
275,
1449,
523,
446,
536,
26,
2790,
334,
269,
1678,
9,
11200,
8692,
272,
13601,
63,
5682,
63,
23726,
81,
1447,
1963,
26,
489,
2073,
63,
923,
26,
1379,
2448,
489,
1654,
63,
354,
26,
511,
1000,
489,
536,
26,
1592,
17,
199,
2344,
199,
199,
9677,
275,
1449,
199,
344,
26,
272,
1369,
26,
267,
446,
7337,
2870,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
1182,
13233,
15,
15798,
13,
4717,
13,
4717,
13,
4717,
13,
15798,
4717,
15,
26952,
15,
774,
2448,
15,
9710,
15,
12940,
14,
2846,
509,
20784,
15,
5871,
15,
22471,
15,
17439,
15,
697,
17,
199,
354,
26,
272,
1369,
26,
267,
446,
7337,
536,
14,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
1592,
17,
199,
2344,
199,
199,
646,
900,
199,
504,
3242,
14,
578,
63,
1208,
14,
9078,
63,
5682,
63,
2330,
492,
15474,
11026,
2377,
1563,
199,
199,
893,
26,
272,
687,
13601,
14,
9752,
14,
82,
697,
706,
14,
8644,
492,
11200,
14552,
3041,
272,
687,
6605,
264,
1207,
7895,
14,
9078,
63,
3924,
492,
30059,
272,
687,
6605,
3911,
14,
17154,
492,
491,
26898,
272,
687,
6605,
3911,
14,
12161,
492,
5822,
199,
2590,
3545,
26,
272,
327,
961,
365,
8860,
315,
13601,
63,
5682,
63,
2330,
272,
986,
421,
199,
533,
24367,
26,
272,
3091,
3310,
12,
2790,
12,
6162,
12,
8496,
275,
1425,
8,
20,
9,
421,
199,
533,
15474,
50,
5127,
1963,
83,
8,
22386,
11026,
2377,
1563,
304,
272,
408,
5688,
1021,
367,
376,
15474,
820,
45,
11200,
8692,
2073,
624,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
578,
63,
1273,
63,
1650,
275,
1211,
8,
288,
2073,
63,
923,
29,
807,
8,
355,
730,
534,
495,
297,
355,
1415,
29,
549,
288,
2318,
288,
1654,
63,
354,
29,
807,
8,
355,
730,
534,
495,
297,
355,
1415,
29,
549,
288,
2318,
288,
536,
29,
807,
8,
355,
730,
534,
495,
297,
355,
1415,
29,
549,
288,
2318,
288,
5960,
29,
807,
8,
355,
730,
534,
495,
7,
288,
2318,
288,
1048,
2212,
29,
807,
8,
355,
730,
534,
495,
7,
288,
2318,
288,
3542,
63,
873,
29,
807,
8,
355,
730,
534,
2245,
297,
355,
849,
29,
797,
288,
2318,
288,
1174,
29,
807,
8,
355,
730,
534,
495,
297,
355,
849,
534,
1881,
297,
355,
3415,
2968,
1881,
297,
283,
5575,
418,
288,
776,
267,
776,
398,
291,
14,
1927,
63,
923,
275,
488,
267,
291,
14,
1000,
63,
354,
275,
488,
267,
291,
14,
354,
275,
488,
267,
291,
14,
3214,
275,
1211,
342,
398,
291,
14,
2604,
275,
1211,
8,
2489,
29,
797,
9,
267,
291,
14,
9752,
63,
1258,
275,
488,
267,
291,
14,
929,
275,
488,
267,
291,
14,
475,
63,
1117,
275,
24367,
14,
1944,
3310,
398,
1613,
8,
22386,
50,
5127,
1963,
83,
12,
291,
2843,
826,
721,
19588,
63,
1273,
63,
1650,
29,
277,
14,
578,
63,
1273,
63,
1650,
12,
6901,
5171,
63,
1074,
63,
632,
29,
549,
12,
6901,
5171,
63,
2969,
29
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
3107,
1017,
1804,
279,
262,
19844,
12,
665,
90,
3258,
279,
10175,
32,
17040,
14,
957,
30,
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,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
13601,
63,
5682,
63,
23726,
81,
1447,
1963,
199,
1023,
63,
3270,
26,
298,
18,
14,
21,
2,
199,
3612,
63,
1802,
26,
14944,
11200,
8692,
1256,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
436,
3145,
1256,
402,
11200,
8692,
14,
199,
199,
1419,
26,
272,
2073,
63,
923,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
2073,
1572,
626,
3509,
314,
2073,
14,
2047,
883,
3332,
642,
574,
687,
314,
15474,
7337,
13537,
3261,
503,
314,
18428,
14,
267,
1415,
26,
715,
272,
1654,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
1654,
14,
267,
1415,
26,
715,
272,
536,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
3050,
14,
267,
1415,
26,
715,
272,
5960,
26,
267,
1369,
26,
288,
446,
710,
5960,
402,
314,
3050,
14,
2670,
11200,
3794,
367,
3962,
1338,
14,
288,
446,
961,
365,
1454,
663,
641,
7143,
12,
675,
473,
8,
3990,
63,
873,
9,
370,
23959,
282,
3050,
340,
314,
1598,
1338,
2793,
1133,
1336,
14,
272,
1048,
2212,
26,
267,
1369,
26,
288,
446,
710,
1048,
2212,
402,
314,
3050,
14,
2670,
11200,
3794,
367,
3962,
1338,
14,
288,
446,
961,
365,
1454,
663,
641,
7143,
12,
675,
473,
8,
3990,
63,
873,
9,
370,
23959,
282,
3050,
340,
314,
1598,
1338,
2793,
1133,
1336,
14,
272,
3542,
63,
873,
26,
489,
1369,
26,
881,
446,
3979,
663,
370,
445,
8,
2052,
395,
911,
3145,
436,
23959,
314,
3411,
11200,
3050,
340,
1263,
288,
402,
314,
4382,
2793,
1133,
1336,
4052,
365,
663,
14,
881,
446,
3979,
663,
370,
445,
8,
3910,
395,
949,
1570,
911,
4781,
370,
314,
3050,
2755,
340,
1263,
288,
402,
314,
4382,
886,
440,
1336,
14,
489,
730,
26,
2155,
489,
849,
26,
283,
889,
7,
272,
1174,
26,
267,
1369,
26,
288,
446,
10716,
314,
1174,
402,
314,
11200,
8692,
14,
3645,
283,
1881,
7,
370,
1218,
503,
1678,
282,
3050,
436,
283,
5575,
7,
370,
3145,
652,
14,
267,
849,
26,
3451,
267,
3415,
26,
288,
446,
9552,
288,
446,
3451,
199,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
13601,
199,
199,
2502,
26,
272,
446,
298,
58,
1017,
1804,
279,
262,
19844,
8593,
90,
3258,
279,
10175,
2924,
199,
199,
2344,
199,
199,
8918,
275,
1449,
523,
446,
536,
26,
2790,
334,
269,
1678,
9,
11200,
8692,
272,
13601,
63,
5682,
63,
23726,
81,
1447,
1963,
26,
489,
2073,
63,
923,
26,
1379,
2448,
489,
1654,
63,
354,
26,
511,
1000,
489,
536,
26,
1592,
17,
199,
2344,
199,
199,
9677,
275,
1449,
199,
344,
26,
272,
1369,
26,
267,
446,
7337,
2870,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
1182,
13233,
15,
15798,
13,
4717,
13,
4717,
13,
4717,
13,
15798,
4717,
15,
26952,
15,
774,
2448,
15,
9710,
15,
12940,
14,
2846,
509,
20784,
15,
5871,
15,
22471,
15,
17439,
15,
697,
17,
199,
354,
26,
272,
1369,
26,
267,
446,
7337,
536,
14,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
1592,
17,
199,
2344,
199,
199,
646,
900,
199,
504,
3242,
14,
578,
63,
1208,
14,
9078,
63,
5682,
63,
2330,
492,
15474,
11026,
2377,
1563,
199,
199,
893,
26,
272,
687,
13601,
14,
9752,
14,
82,
697,
706,
14,
8644,
492,
11200,
14552,
3041,
272,
687,
6605,
264,
1207,
7895,
14,
9078,
63,
3924,
492,
30059,
272,
687,
6605,
3911,
14,
17154,
492,
491,
26898,
272,
687,
6605,
3911,
14,
12161,
492,
5822,
199,
2590,
3545,
26,
272,
327,
961,
365,
8860,
315,
13601,
63,
5682,
63,
2330,
272,
986,
421,
199,
533,
24367,
26,
272,
3091,
3310,
12,
2790,
12,
6162,
12,
8496,
275,
1425,
8,
20,
9,
421,
199,
533,
15474,
50,
5127,
1963,
83,
8,
22386,
11026,
2377,
1563,
304,
272,
408,
5688,
1021,
367,
376,
15474,
820,
45,
11200,
8692,
2073,
624,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
578,
63,
1273,
63,
1650,
275,
1211,
8,
288,
2073,
63,
923,
29,
807,
8,
355,
730,
534,
495,
297,
355,
1415,
29,
549,
288,
2318,
288,
1654,
63,
354,
29,
807,
8,
355,
730,
534,
495,
297,
355,
1415,
29,
549,
288,
2318,
288,
536,
29,
807,
8,
355,
730,
534,
495,
297,
355,
1415,
29,
549,
288,
2318,
288,
5960,
29,
807,
8,
355,
730,
534,
495,
7,
288,
2318,
288,
1048,
2212,
29,
807,
8,
355,
730,
534,
495,
7,
288,
2318,
288,
3542,
63,
873,
29,
807,
8,
355,
730,
534,
2245,
297,
355,
849,
29,
797,
288,
2318,
288,
1174,
29,
807,
8,
355,
730,
534,
495,
297,
355,
849,
534,
1881,
297,
355,
3415,
2968,
1881,
297,
283,
5575,
418,
288,
776,
267,
776,
398,
291,
14,
1927,
63,
923,
275,
488,
267,
291,
14,
1000,
63,
354,
275,
488,
267,
291,
14,
354,
275,
488,
267,
291,
14,
3214,
275,
1211,
342,
398,
291,
14,
2604,
275,
1211,
8,
2489,
29,
797,
9,
267,
291,
14,
9752,
63,
1258,
275,
488,
267,
291,
14,
929,
275,
488,
267,
291,
14,
475,
63,
1117,
275,
24367,
14,
1944,
3310,
398,
1613,
8,
22386,
50,
5127,
1963,
83,
12,
291,
2843,
826,
721,
19588,
63,
1273,
63,
1650,
29,
277,
14,
578,
63,
1273,
63,
1650,
12,
6901,
5171,
63,
1074,
63,
632,
29,
549,
12,
6901,
5171,
63,
2969,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
proxysh/Safejumper-for-Mac
|
buildlinux/env64/lib/python2.7/site-packages/twisted/internet/test/test_newtls.py
|
12
|
6693
|
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.internet._newtls}.
"""
from __future__ import division, absolute_import
from twisted.trial import unittest
from twisted.internet import interfaces
from twisted.internet.test.reactormixins import ReactorBuilder
from twisted.internet.test.connectionmixins import (
ConnectableProtocol, runProtocolsWithReactor)
from twisted.internet.test.test_tls import SSLCreator, TLSMixin
from twisted.internet.test.test_tls import StartTLSClientCreator
from twisted.internet.test.test_tls import ContextGeneratingMixin
from twisted.internet.test.test_tcp import TCPCreator
try:
from twisted.protocols import tls
from twisted.internet import _newtls
except ImportError:
_newtls = None
from zope.interface import implementer
class BypassTLSTests(unittest.TestCase):
"""
Tests for the L{_newtls._BypassTLS} class.
"""
if not _newtls:
skip = "Couldn't import _newtls, perhaps pyOpenSSL is old or missing"
def test_loseConnectionPassThrough(self):
"""
C{_BypassTLS.loseConnection} calls C{loseConnection} on the base
class, while preserving any default argument in the base class'
C{loseConnection} implementation.
"""
default = object()
result = []
class FakeTransport(object):
def loseConnection(self, _connDone=default):
result.append(_connDone)
bypass = _newtls._BypassTLS(FakeTransport, FakeTransport())
# The default from FakeTransport is used:
bypass.loseConnection()
self.assertEqual(result, [default])
# And we can pass our own:
notDefault = object()
bypass.loseConnection(notDefault)
self.assertEqual(result, [default, notDefault])
class FakeProducer(object):
"""
A producer that does nothing.
"""
def pauseProducing(self):
pass
def resumeProducing(self):
pass
def stopProducing(self):
pass
@implementer(interfaces.IHandshakeListener)
class ProducerProtocol(ConnectableProtocol):
"""
Register a producer, unregister it, and verify the producer hooks up to
innards of C{TLSMemoryBIOProtocol}.
"""
def __init__(self, producer, result):
self.producer = producer
self.result = result
def handshakeCompleted(self):
if not isinstance(self.transport.protocol,
tls.TLSMemoryBIOProtocol):
# Either the test or the code have a bug...
raise RuntimeError("TLSMemoryBIOProtocol not hooked up.")
self.transport.registerProducer(self.producer, True)
# The producer was registered with the TLSMemoryBIOProtocol:
self.result.append(self.transport.protocol._producer._producer)
self.transport.unregisterProducer()
# The producer was unregistered from the TLSMemoryBIOProtocol:
self.result.append(self.transport.protocol._producer)
self.transport.loseConnection()
class ProducerTestsMixin(ReactorBuilder, TLSMixin, ContextGeneratingMixin):
"""
Test the new TLS code integrates C{TLSMemoryBIOProtocol} correctly.
"""
if not _newtls:
skip = "Could not import twisted.internet._newtls"
def test_producerSSLFromStart(self):
"""
C{registerProducer} and C{unregisterProducer} on TLS transports
created as SSL from the get go are passed to the
C{TLSMemoryBIOProtocol}, not the underlying transport directly.
"""
result = []
producer = FakeProducer()
runProtocolsWithReactor(self, ConnectableProtocol(),
ProducerProtocol(producer, result),
SSLCreator())
self.assertEqual(result, [producer, None])
def test_producerAfterStartTLS(self):
"""
C{registerProducer} and C{unregisterProducer} on TLS transports
created by C{startTLS} are passed to the C{TLSMemoryBIOProtocol}, not
the underlying transport directly.
"""
result = []
producer = FakeProducer()
runProtocolsWithReactor(self, ConnectableProtocol(),
ProducerProtocol(producer, result),
StartTLSClientCreator())
self.assertEqual(result, [producer, None])
def startTLSAfterRegisterProducer(self, streaming):
"""
When a producer is registered, and then startTLS is called,
the producer is re-registered with the C{TLSMemoryBIOProtocol}.
"""
clientContext = self.getClientContext()
serverContext = self.getServerContext()
result = []
producer = FakeProducer()
class RegisterTLSProtocol(ConnectableProtocol):
def connectionMade(self):
self.transport.registerProducer(producer, streaming)
self.transport.startTLS(serverContext)
# Store TLSMemoryBIOProtocol and underlying transport producer
# status:
if streaming:
# _ProducerMembrane -> producer:
result.append(self.transport.protocol._producer._producer)
result.append(self.transport.producer._producer)
else:
# _ProducerMembrane -> _PullToPush -> producer:
result.append(
self.transport.protocol._producer._producer._producer)
result.append(self.transport.producer._producer._producer)
self.transport.unregisterProducer()
self.transport.loseConnection()
class StartTLSProtocol(ConnectableProtocol):
def connectionMade(self):
self.transport.startTLS(clientContext)
runProtocolsWithReactor(self, RegisterTLSProtocol(),
StartTLSProtocol(), TCPCreator())
self.assertEqual(result, [producer, producer])
def test_startTLSAfterRegisterProducerStreaming(self):
"""
When a streaming producer is registered, and then startTLS is called,
the producer is re-registered with the C{TLSMemoryBIOProtocol}.
"""
self.startTLSAfterRegisterProducer(True)
def test_startTLSAfterRegisterProducerNonStreaming(self):
"""
When a non-streaming producer is registered, and then startTLS is
called, the producer is re-registered with the
C{TLSMemoryBIOProtocol}.
"""
self.startTLSAfterRegisterProducer(False)
globals().update(ProducerTestsMixin.makeTestCaseClasses())
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
4901,
423,
1222,
9945,
5565,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
504,
7390,
14,
4901,
492,
8386,
199,
504,
7390,
14,
4901,
14,
396,
14,
13544,
30192,
492,
799,
5021,
6437,
199,
504,
7390,
14,
4901,
14,
396,
14,
2105,
30192,
492,
334,
272,
15175,
461,
3658,
12,
1255,
8548,
4574,
3007,
15860,
9,
199,
504,
7390,
14,
4901,
14,
396,
14,
396,
63,
9945,
492,
7799,
17523,
12,
377,
44,
4029,
3774,
199,
504,
7390,
14,
4901,
14,
396,
14,
396,
63,
9945,
492,
7707,
10224,
3041,
17523,
199,
504,
7390,
14,
4901,
14,
396,
14,
396,
63,
9945,
492,
9470,
29244,
4256,
199,
504,
7390,
14,
4901,
14,
396,
14,
396,
63,
8815,
492,
13488,
17523,
199,
893,
26,
272,
687,
7390,
14,
16541,
492,
15142,
272,
687,
7390,
14,
4901,
492,
485,
1222,
9945,
199,
2590,
3545,
26,
272,
485,
1222,
9945,
275,
488,
199,
504,
20110,
14,
3266,
492,
2456,
28826,
421,
199,
533,
4885,
1529,
10224,
2925,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
314,
491,
26975,
1222,
9945,
423,
2175,
1529,
10224,
93,
1021,
14,
272,
408,
339,
340,
440,
485,
1222,
9945,
26,
267,
3372,
275,
298,
20485,
1133,
492,
485,
1222,
9945,
12,
25358,
1134,
22791,
365,
2269,
503,
4124,
2,
339,
347,
511,
63,
32452,
4986,
26732,
8,
277,
304,
267,
408,
267,
445,
26975,
2175,
1529,
10224,
14,
32452,
93,
4882,
445,
91,
32452,
93,
641,
314,
1300,
267,
1021,
12,
1830,
876,
14717,
1263,
849,
1423,
315,
314,
1300,
1021,
7,
267,
445,
91,
32452,
93,
4514,
14,
267,
408,
267,
849,
275,
909,
342,
267,
754,
275,
942,
398,
1021,
7777,
7836,
8,
785,
304,
288,
347,
27332,
3225,
8,
277,
12,
485,
1631,
10759,
29,
885,
304,
355,
754,
14,
740,
1547,
1631,
10759,
9,
398,
21115,
275,
485,
1222,
9945,
423,
2175,
1529,
10224,
8,
8249,
7836,
12,
7777,
7836,
1012,
398,
327,
710,
849,
687,
7777,
7836,
365,
1202,
26,
267,
21115,
14,
32452,
342,
267,
291,
14,
629,
8,
1099,
12,
359,
885,
566,
398,
327,
6061,
781,
883,
986,
4154,
5705,
26,
267,
440,
2698,
275,
909,
342,
267,
21115,
14,
32452,
8,
1397,
2698,
9,
267,
291,
14,
629,
8,
1099,
12,
359,
885,
12,
440,
2698,
566,
4388,
199,
533,
7777,
15532,
8,
785,
304,
272,
408,
272,
437,
17339,
626,
1630,
6548,
14,
272,
408,
339,
347,
16834,
24982,
8,
277,
304,
267,
986,
2378,
347,
14604,
24982,
8,
277,
304,
267,
986,
2378,
347,
3631,
24982,
8,
277,
304,
267,
986,
4388,
199,
32,
1729,
28826,
8,
7436,
14,
41,
26392,
10464,
9,
199,
533,
2165,
7610,
3658,
8,
8631,
461,
3658,
304,
272,
408,
272,
11828,
282,
17339,
12,
24369,
652,
12,
436,
4911,
314,
17339,
12604,
1536,
370,
272,
315,
78,
5596,
402,
445,
91,
10224,
8628,
34,
2090,
3658,
5565,
272,
408,
339,
347,
636,
826,
721,
277,
12,
17339,
12,
754,
304,
267,
291,
14,
16376,
275,
17339,
267,
291,
14,
1099,
275,
754,
2378,
347,
14305,
19908,
8,
277,
304,
267,
340,
440,
1228,
8,
277,
14,
5545,
14,
3922,
12,
2079,
15142,
14,
10224,
8628,
34,
2090,
3658,
304,
288,
327,
13083,
314,
511,
503,
314,
1233,
1172,
282,
6519,
1396,
288,
746,
6064,
480,
10224,
8628,
34,
2090,
3658,
440,
5759,
379,
1536,
2685,
398,
291,
14,
5545,
14,
2683,
15532,
8,
277,
14,
16376,
12,
715,
9,
267,
327,
710,
17339,
1990,
7264,
543,
314,
12213,
8628,
34,
2090,
3658,
26,
267,
291,
14,
1099,
14,
740,
8,
277,
14,
5545,
14,
3922,
423,
16376,
423,
16376,
9,
398,
291,
14,
5545,
14,
18408,
15532,
342,
267,
327,
710,
17339,
1990,
625,
11616,
687,
314,
12213,
8628,
34,
2090,
3658,
26,
267,
291,
14,
1099,
14,
740,
8,
277,
14,
5545,
14,
3922,
423,
16376,
9,
267,
291,
14,
5545,
14,
32452,
342,
4388,
199,
533,
2165,
7610,
2925,
4256,
8,
15860,
6437,
12,
377,
44,
4029,
3774,
12,
9470,
29244,
4256,
304,
272,
408,
272,
1379,
314,
892,
12213,
1233,
21494,
83,
445,
91,
10224,
8628,
34,
2090,
3658,
93,
6657,
14,
272,
408,
339,
340,
440,
485,
1222,
9945,
26,
267,
3372,
275,
298,
6531,
440,
492,
7390,
14,
4901,
423,
1222,
9945,
2,
339,
347,
511,
63,
16376,
5413,
2532,
3162,
8,
277,
304,
267,
408,
267,
445,
91,
2683,
15532,
93,
436,
445,
91,
18408,
15532,
93,
641,
12213,
7773,
83,
267,
2737,
465,
7799,
687,
314,
664,
2621,
787,
3032,
370,
314,
267,
445,
91,
10224,
8628,
34,
2090,
3658,
1386,
440,
314,
8793,
7773,
5370,
14,
267,
408,
267,
754,
275,
942,
267,
17339,
275,
7777,
15532,
342,
398,
1255,
8548,
4574,
3007,
15860,
8,
277,
12,
15175,
461,
3658,
1062,
1816,
2165,
7610,
3658,
8,
16376,
12,
754,
395,
1816,
7799,
17523,
1012,
267,
291,
14,
629,
8,
1099,
12,
359,
16376,
12,
488,
566,
2378,
347,
511,
63,
16376,
10881,
3162,
10224,
8,
277,
304,
267,
408,
267,
445,
91,
2683,
15532,
93,
436,
445,
91,
18408,
15532,
93,
641,
12213,
7773,
83,
267,
2737,
701,
445,
91,
928,
10224,
93,
787,
3032,
370,
314,
445,
91,
10224,
8628,
34,
2090,
3658,
1386,
440,
267,
314,
8793,
7773,
5370,
14,
267,
408,
267,
754,
275,
942,
267,
17339,
275,
7777,
15532,
342,
398,
1255,
8548,
4574,
3007,
15860,
8,
277,
12,
15175,
461,
3658,
1062,
1816,
2165,
7610,
3658,
8,
16376,
12,
754,
395,
1816,
7707,
10224,
3041,
17523,
1012,
267,
291,
14,
629,
8,
1099,
12,
359,
16376,
12,
488,
566,
2378,
347,
1343,
7308,
4251,
1796,
7099,
15532,
8,
277,
12,
18490,
304,
267,
408,
267,
3979,
282,
17339,
365,
7264,
12,
436,
2066,
1343,
10224,
365,
2797,
12,
267,
314,
17339,
365,
295,
13,
11616,
543,
314,
445,
91,
10224,
8628,
34,
2090,
3658,
5565,
267,
408,
267,
1890,
2998,
275,
291,
14,
362,
3041,
2998,
342,
267
] |
[
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
4901,
423,
1222,
9945,
5565,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
504,
7390,
14,
4901,
492,
8386,
199,
504,
7390,
14,
4901,
14,
396,
14,
13544,
30192,
492,
799,
5021,
6437,
199,
504,
7390,
14,
4901,
14,
396,
14,
2105,
30192,
492,
334,
272,
15175,
461,
3658,
12,
1255,
8548,
4574,
3007,
15860,
9,
199,
504,
7390,
14,
4901,
14,
396,
14,
396,
63,
9945,
492,
7799,
17523,
12,
377,
44,
4029,
3774,
199,
504,
7390,
14,
4901,
14,
396,
14,
396,
63,
9945,
492,
7707,
10224,
3041,
17523,
199,
504,
7390,
14,
4901,
14,
396,
14,
396,
63,
9945,
492,
9470,
29244,
4256,
199,
504,
7390,
14,
4901,
14,
396,
14,
396,
63,
8815,
492,
13488,
17523,
199,
893,
26,
272,
687,
7390,
14,
16541,
492,
15142,
272,
687,
7390,
14,
4901,
492,
485,
1222,
9945,
199,
2590,
3545,
26,
272,
485,
1222,
9945,
275,
488,
199,
504,
20110,
14,
3266,
492,
2456,
28826,
421,
199,
533,
4885,
1529,
10224,
2925,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
314,
491,
26975,
1222,
9945,
423,
2175,
1529,
10224,
93,
1021,
14,
272,
408,
339,
340,
440,
485,
1222,
9945,
26,
267,
3372,
275,
298,
20485,
1133,
492,
485,
1222,
9945,
12,
25358,
1134,
22791,
365,
2269,
503,
4124,
2,
339,
347,
511,
63,
32452,
4986,
26732,
8,
277,
304,
267,
408,
267,
445,
26975,
2175,
1529,
10224,
14,
32452,
93,
4882,
445,
91,
32452,
93,
641,
314,
1300,
267,
1021,
12,
1830,
876,
14717,
1263,
849,
1423,
315,
314,
1300,
1021,
7,
267,
445,
91,
32452,
93,
4514,
14,
267,
408,
267,
849,
275,
909,
342,
267,
754,
275,
942,
398,
1021,
7777,
7836,
8,
785,
304,
288,
347,
27332,
3225,
8,
277,
12,
485,
1631,
10759,
29,
885,
304,
355,
754,
14,
740,
1547,
1631,
10759,
9,
398,
21115,
275,
485,
1222,
9945,
423,
2175,
1529,
10224,
8,
8249,
7836,
12,
7777,
7836,
1012,
398,
327,
710,
849,
687,
7777,
7836,
365,
1202,
26,
267,
21115,
14,
32452,
342,
267,
291,
14,
629,
8,
1099,
12,
359,
885,
566,
398,
327,
6061,
781,
883,
986,
4154,
5705,
26,
267,
440,
2698,
275,
909,
342,
267,
21115,
14,
32452,
8,
1397,
2698,
9,
267,
291,
14,
629,
8,
1099,
12,
359,
885,
12,
440,
2698,
566,
4388,
199,
533,
7777,
15532,
8,
785,
304,
272,
408,
272,
437,
17339,
626,
1630,
6548,
14,
272,
408,
339,
347,
16834,
24982,
8,
277,
304,
267,
986,
2378,
347,
14604,
24982,
8,
277,
304,
267,
986,
2378,
347,
3631,
24982,
8,
277,
304,
267,
986,
4388,
199,
32,
1729,
28826,
8,
7436,
14,
41,
26392,
10464,
9,
199,
533,
2165,
7610,
3658,
8,
8631,
461,
3658,
304,
272,
408,
272,
11828,
282,
17339,
12,
24369,
652,
12,
436,
4911,
314,
17339,
12604,
1536,
370,
272,
315,
78,
5596,
402,
445,
91,
10224,
8628,
34,
2090,
3658,
5565,
272,
408,
339,
347,
636,
826,
721,
277,
12,
17339,
12,
754,
304,
267,
291,
14,
16376,
275,
17339,
267,
291,
14,
1099,
275,
754,
2378,
347,
14305,
19908,
8,
277,
304,
267,
340,
440,
1228,
8,
277,
14,
5545,
14,
3922,
12,
2079,
15142,
14,
10224,
8628,
34,
2090,
3658,
304,
288,
327,
13083,
314,
511,
503,
314,
1233,
1172,
282,
6519,
1396,
288,
746,
6064,
480,
10224,
8628,
34,
2090,
3658,
440,
5759,
379,
1536,
2685,
398,
291,
14,
5545,
14,
2683,
15532,
8,
277,
14,
16376,
12,
715,
9,
267,
327,
710,
17339,
1990,
7264,
543,
314,
12213,
8628,
34,
2090,
3658,
26,
267,
291,
14,
1099,
14,
740,
8,
277,
14,
5545,
14,
3922,
423,
16376,
423,
16376,
9,
398,
291,
14,
5545,
14,
18408,
15532,
342,
267,
327,
710,
17339,
1990,
625,
11616,
687,
314,
12213,
8628,
34,
2090,
3658,
26,
267,
291,
14,
1099,
14,
740,
8,
277,
14,
5545,
14,
3922,
423,
16376,
9,
267,
291,
14,
5545,
14,
32452,
342,
4388,
199,
533,
2165,
7610,
2925,
4256,
8,
15860,
6437,
12,
377,
44,
4029,
3774,
12,
9470,
29244,
4256,
304,
272,
408,
272,
1379,
314,
892,
12213,
1233,
21494,
83,
445,
91,
10224,
8628,
34,
2090,
3658,
93,
6657,
14,
272,
408,
339,
340,
440,
485,
1222,
9945,
26,
267,
3372,
275,
298,
6531,
440,
492,
7390,
14,
4901,
423,
1222,
9945,
2,
339,
347,
511,
63,
16376,
5413,
2532,
3162,
8,
277,
304,
267,
408,
267,
445,
91,
2683,
15532,
93,
436,
445,
91,
18408,
15532,
93,
641,
12213,
7773,
83,
267,
2737,
465,
7799,
687,
314,
664,
2621,
787,
3032,
370,
314,
267,
445,
91,
10224,
8628,
34,
2090,
3658,
1386,
440,
314,
8793,
7773,
5370,
14,
267,
408,
267,
754,
275,
942,
267,
17339,
275,
7777,
15532,
342,
398,
1255,
8548,
4574,
3007,
15860,
8,
277,
12,
15175,
461,
3658,
1062,
1816,
2165,
7610,
3658,
8,
16376,
12,
754,
395,
1816,
7799,
17523,
1012,
267,
291,
14,
629,
8,
1099,
12,
359,
16376,
12,
488,
566,
2378,
347,
511,
63,
16376,
10881,
3162,
10224,
8,
277,
304,
267,
408,
267,
445,
91,
2683,
15532,
93,
436,
445,
91,
18408,
15532,
93,
641,
12213,
7773,
83,
267,
2737,
701,
445,
91,
928,
10224,
93,
787,
3032,
370,
314,
445,
91,
10224,
8628,
34,
2090,
3658,
1386,
440,
267,
314,
8793,
7773,
5370,
14,
267,
408,
267,
754,
275,
942,
267,
17339,
275,
7777,
15532,
342,
398,
1255,
8548,
4574,
3007,
15860,
8,
277,
12,
15175,
461,
3658,
1062,
1816,
2165,
7610,
3658,
8,
16376,
12,
754,
395,
1816,
7707,
10224,
3041,
17523,
1012,
267,
291,
14,
629,
8,
1099,
12,
359,
16376,
12,
488,
566,
2378,
347,
1343,
7308,
4251,
1796,
7099,
15532,
8,
277,
12,
18490,
304,
267,
408,
267,
3979,
282,
17339,
365,
7264,
12,
436,
2066,
1343,
10224,
365,
2797,
12,
267,
314,
17339,
365,
295,
13,
11616,
543,
314,
445,
91,
10224,
8628,
34,
2090,
3658,
5565,
267,
408,
267,
1890,
2998,
275,
291,
14,
362,
3041,
2998,
342,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mglukhikh/intellij-community
|
python/lib/Lib/site-packages/django/contrib/localflavor/pl/forms.py
|
273
|
5444
|
"""
Polish-specific form helpers
"""
import re
from django.forms import ValidationError
from django.forms.fields import Select, RegexField
from django.utils.translation import ugettext_lazy as _
from django.core.validators import EMPTY_VALUES
class PLProvinceSelect(Select):
"""
A select widget with list of Polish administrative provinces as choices.
"""
def __init__(self, attrs=None):
from pl_voivodeships import VOIVODESHIP_CHOICES
super(PLProvinceSelect, self).__init__(attrs, choices=VOIVODESHIP_CHOICES)
class PLCountySelect(Select):
"""
A select widget with list of Polish administrative units as choices.
"""
def __init__(self, attrs=None):
from pl_administrativeunits import ADMINISTRATIVE_UNIT_CHOICES
super(PLCountySelect, self).__init__(attrs, choices=ADMINISTRATIVE_UNIT_CHOICES)
class PLPESELField(RegexField):
"""
A form field that validates as Polish Identification Number (PESEL).
Checks the following rules:
* the length consist of 11 digits
* has a valid checksum
The algorithm is documented at http://en.wikipedia.org/wiki/PESEL.
"""
default_error_messages = {
'invalid': _(u'National Identification Number consists of 11 digits.'),
'checksum': _(u'Wrong checksum for the National Identification Number.'),
}
def __init__(self, *args, **kwargs):
super(PLPESELField, self).__init__(r'^\d{11}$',
max_length=None, min_length=None, *args, **kwargs)
def clean(self,value):
super(PLPESELField, self).clean(value)
if value in EMPTY_VALUES:
return u''
if not self.has_valid_checksum(value):
raise ValidationError(self.error_messages['checksum'])
return u'%s' % value
def has_valid_checksum(self, number):
"""
Calculates a checksum with the provided algorithm.
"""
multiple_table = (1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1)
result = 0
for i in range(len(number)):
result += int(number[i]) * multiple_table[i]
return result % 10 == 0
class PLNIPField(RegexField):
"""
A form field that validates as Polish Tax Number (NIP).
Valid forms are: XXX-XXX-YY-YY or XX-XX-YYY-YYY.
Checksum algorithm based on documentation at
http://wipos.p.lodz.pl/zylla/ut/nip-rego.html
"""
default_error_messages = {
'invalid': _(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.'),
'checksum': _(u'Wrong checksum for the Tax Number (NIP).'),
}
def __init__(self, *args, **kwargs):
super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{2}-\d{2}-\d{3}-\d{3}$',
max_length=None, min_length=None, *args, **kwargs)
def clean(self,value):
super(PLNIPField, self).clean(value)
if value in EMPTY_VALUES:
return u''
value = re.sub("[-]", "", value)
if not self.has_valid_checksum(value):
raise ValidationError(self.error_messages['checksum'])
return u'%s' % value
def has_valid_checksum(self, number):
"""
Calculates a checksum with the provided algorithm.
"""
multiple_table = (6, 5, 7, 2, 3, 4, 5, 6, 7)
result = 0
for i in range(len(number)-1):
result += int(number[i]) * multiple_table[i]
result %= 11
if result == int(number[-1]):
return True
else:
return False
class PLREGONField(RegexField):
"""
A form field that validates its input is a REGON number.
Valid regon number consists of 9 or 14 digits.
See http://www.stat.gov.pl/bip/regon_ENG_HTML.htm for more information.
"""
default_error_messages = {
'invalid': _(u'National Business Register Number (REGON) consists of 9 or 14 digits.'),
'checksum': _(u'Wrong checksum for the National Business Register Number (REGON).'),
}
def __init__(self, *args, **kwargs):
super(PLREGONField, self).__init__(r'^\d{9,14}$',
max_length=None, min_length=None, *args, **kwargs)
def clean(self,value):
super(PLREGONField, self).clean(value)
if value in EMPTY_VALUES:
return u''
if not self.has_valid_checksum(value):
raise ValidationError(self.error_messages['checksum'])
return u'%s' % value
def has_valid_checksum(self, number):
"""
Calculates a checksum with the provided algorithm.
"""
weights = (
(8, 9, 2, 3, 4, 5, 6, 7, -1),
(2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8, -1),
(8, 9, 2, 3, 4, 5, 6, 7, -1, 0, 0, 0, 0, 0),
)
weights = [table for table in weights if len(table) == len(number)]
for table in weights:
checksum = sum([int(n) * w for n, w in zip(number, table)])
if checksum % 11 % 10:
return False
return bool(weights)
class PLPostalCodeField(RegexField):
"""
A form field that validates as Polish postal code.
Valid code is XX-XXX where X is digit.
"""
default_error_messages = {
'invalid': _(u'Enter a postal code in the format XX-XXX.'),
}
def __init__(self, *args, **kwargs):
super(PLPostalCodeField, self).__init__(r'^\d{2}-\d{3}$',
max_length=None, min_length=None, *args, **kwargs)
|
apache-2.0
|
[
624,
199,
1575,
1891,
13,
6100,
1824,
10897,
199,
624,
199,
199,
646,
295,
199,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
3351,
14,
955,
492,
9496,
12,
12939,
792,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
199,
533,
10092,
919,
86,
2855,
5446,
8,
5446,
304,
272,
408,
272,
437,
3504,
3938,
543,
769,
402,
4376,
1891,
4628,
25124,
557,
11908,
823,
465,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
1620,
63,
2392,
1003,
380,
3319,
83,
492,
812,
47,
6882,
47,
4448,
40,
1772,
63,
16236,
267,
1613,
8,
2749,
919,
86,
2855,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
10662,
6882,
47,
4448,
40,
1772,
63,
16236,
9,
199,
199,
533,
10092,
24532,
369,
5446,
8,
5446,
304,
272,
408,
272,
437,
3504,
3938,
543,
769,
402,
4376,
1891,
4628,
25124,
6204,
465,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
1620,
63,
2113,
25124,
5260,
492,
29948,
21340,
14277,
63,
15505,
63,
16236,
267,
1613,
8,
2749,
24532,
369,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
14288,
21340,
14277,
63,
15505,
63,
16236,
9,
199,
199,
533,
510,
9257,
654,
2901,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
465,
4376,
1891,
473,
24926,
4860,
334,
48,
654,
2901,
680,
339,
13813,
314,
2569,
4713,
26,
267,
627,
314,
2582,
17568,
402,
4119,
7576,
267,
627,
965,
282,
1686,
9040,
339,
710,
5563,
365,
22751,
737,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
48,
654,
2901,
14,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
46,
6279,
473,
24926,
4860,
18581,
402,
4119,
7576,
8038,
267,
283,
8928,
356,
12561,
85,
7,
14858,
9040,
367,
314,
20548,
473,
24926,
4860,
8038,
272,
789,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
2749,
48,
654,
2901,
792,
12,
291,
2843,
826,
721,
82,
15542,
68,
91,
845,
19204,
288,
1390,
63,
1267,
29,
403,
12,
1748,
63,
1267,
29,
403,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
585,
304,
267,
1613,
8,
2749,
48,
654,
2901,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
340,
440,
291,
14,
1989,
63,
1078,
63,
8928,
8,
585,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
8928,
1105,
267,
372,
399,
5956,
83,
7,
450,
574,
339,
347,
965,
63,
1078,
63,
8928,
8,
277,
12,
1329,
304,
267,
408,
267,
28562,
282,
9040,
543,
314,
2741,
5563,
14,
267,
408,
267,
3663,
63,
1224,
275,
334,
17,
12,
650,
12,
1520,
12,
1749,
12,
413,
12,
650,
12,
1520,
12,
1749,
12,
413,
12,
650,
12,
413,
9,
267,
754,
275,
378,
267,
367,
284,
315,
1425,
8,
552,
8,
1955,
2298,
288,
754,
847,
1109,
8,
1955,
59,
73,
566,
627,
3663,
63,
1224,
59,
73,
61,
267,
372,
754,
450,
1616,
508,
378,
199,
199,
533,
10092,
46,
1772,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
465,
4376,
1891,
30174,
4860,
334,
46,
1772,
680,
272,
4821,
4513,
787,
26,
5787,
13,
13933,
13,
7080,
13,
7080,
503,
1323,
56,
13,
2483,
13,
28443,
13,
28443,
14,
339,
2670,
1838,
5563,
4079,
641,
3794,
737,
272,
1455,
921,
14249,
1712,
14,
80,
14,
320,
17019,
14,
1168,
15,
3605,
76,
416,
15,
337,
15,
78,
711,
13,
1135,
79,
14,
1360,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
8468,
282,
9067,
1329,
901,
334,
46,
1772,
9,
315,
314,
1475,
5787,
13,
13933,
13,
2483,
13,
2483,
503,
1323,
56,
13,
2483,
13,
13933,
13,
13933,
8038,
267,
283,
8928,
356,
12561,
85,
7,
14858,
9040,
367,
314,
30174,
4860,
334,
46,
1772,
680,
659,
272,
789,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
2749,
46,
1772,
792,
12,
291,
2843,
826,
721,
82,
15542,
68,
91,
19,
93,
2696,
68,
91,
19,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
93,
31686,
12773,
68,
91,
18,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
19,
93,
2696,
68,
91,
19,
19204,
288,
1390,
63,
1267,
29,
403,
12,
1748,
63,
1267,
29,
403,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
585,
304,
267,
1613,
8,
2749,
46,
1772,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
574,
275,
295,
14,
954,
480,
1988,
11472,
4873,
574,
9,
267,
340,
440,
291,
14,
1989,
63,
1078,
63,
8928,
8,
585,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
8928,
1105,
267,
372,
399,
5956,
83,
7,
450,
574,
339,
347,
965,
63,
1078,
63,
8928,
8,
277,
12,
1329,
304,
267,
408,
267,
28562,
282,
9040,
543,
314,
2741,
5563,
14,
267,
408,
267,
3663,
63,
1224,
275,
334,
22,
12,
959,
12,
1520,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
9,
267,
754,
275,
378,
267,
367,
284,
315,
1425,
8,
552,
8,
1955,
7216,
17,
304,
288,
754,
847,
1109,
8,
1955,
59,
73,
566,
627,
3663,
63,
1224,
59,
73,
61,
398,
754,
450,
29,
4119,
267,
340,
754,
508,
1109,
8,
1955,
1988,
17,
4682,
288,
372,
715,
267,
587,
26,
288,
372,
756,
199,
199,
533,
10092,
5616,
615,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
2399,
1324,
365,
282,
14142,
615,
1329,
14,
339,
4821,
1295,
265,
1329,
18581,
402,
1749,
503,
4329,
7576,
14,
272,
1666,
1455,
921,
1544,
14,
3736,
14,
16294,
14,
1168,
15,
27566,
15,
1135
] |
[
199,
1575,
1891,
13,
6100,
1824,
10897,
199,
624,
199,
199,
646,
295,
199,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
3351,
14,
955,
492,
9496,
12,
12939,
792,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
199,
533,
10092,
919,
86,
2855,
5446,
8,
5446,
304,
272,
408,
272,
437,
3504,
3938,
543,
769,
402,
4376,
1891,
4628,
25124,
557,
11908,
823,
465,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
1620,
63,
2392,
1003,
380,
3319,
83,
492,
812,
47,
6882,
47,
4448,
40,
1772,
63,
16236,
267,
1613,
8,
2749,
919,
86,
2855,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
10662,
6882,
47,
4448,
40,
1772,
63,
16236,
9,
199,
199,
533,
10092,
24532,
369,
5446,
8,
5446,
304,
272,
408,
272,
437,
3504,
3938,
543,
769,
402,
4376,
1891,
4628,
25124,
6204,
465,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
1620,
63,
2113,
25124,
5260,
492,
29948,
21340,
14277,
63,
15505,
63,
16236,
267,
1613,
8,
2749,
24532,
369,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
14288,
21340,
14277,
63,
15505,
63,
16236,
9,
199,
199,
533,
510,
9257,
654,
2901,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
465,
4376,
1891,
473,
24926,
4860,
334,
48,
654,
2901,
680,
339,
13813,
314,
2569,
4713,
26,
267,
627,
314,
2582,
17568,
402,
4119,
7576,
267,
627,
965,
282,
1686,
9040,
339,
710,
5563,
365,
22751,
737,
1455,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
48,
654,
2901,
14,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
46,
6279,
473,
24926,
4860,
18581,
402,
4119,
7576,
8038,
267,
283,
8928,
356,
12561,
85,
7,
14858,
9040,
367,
314,
20548,
473,
24926,
4860,
8038,
272,
789,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
2749,
48,
654,
2901,
792,
12,
291,
2843,
826,
721,
82,
15542,
68,
91,
845,
19204,
288,
1390,
63,
1267,
29,
403,
12,
1748,
63,
1267,
29,
403,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
585,
304,
267,
1613,
8,
2749,
48,
654,
2901,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
340,
440,
291,
14,
1989,
63,
1078,
63,
8928,
8,
585,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
8928,
1105,
267,
372,
399,
5956,
83,
7,
450,
574,
339,
347,
965,
63,
1078,
63,
8928,
8,
277,
12,
1329,
304,
267,
408,
267,
28562,
282,
9040,
543,
314,
2741,
5563,
14,
267,
408,
267,
3663,
63,
1224,
275,
334,
17,
12,
650,
12,
1520,
12,
1749,
12,
413,
12,
650,
12,
1520,
12,
1749,
12,
413,
12,
650,
12,
413,
9,
267,
754,
275,
378,
267,
367,
284,
315,
1425,
8,
552,
8,
1955,
2298,
288,
754,
847,
1109,
8,
1955,
59,
73,
566,
627,
3663,
63,
1224,
59,
73,
61,
267,
372,
754,
450,
1616,
508,
378,
199,
199,
533,
10092,
46,
1772,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
465,
4376,
1891,
30174,
4860,
334,
46,
1772,
680,
272,
4821,
4513,
787,
26,
5787,
13,
13933,
13,
7080,
13,
7080,
503,
1323,
56,
13,
2483,
13,
28443,
13,
28443,
14,
339,
2670,
1838,
5563,
4079,
641,
3794,
737,
272,
1455,
921,
14249,
1712,
14,
80,
14,
320,
17019,
14,
1168,
15,
3605,
76,
416,
15,
337,
15,
78,
711,
13,
1135,
79,
14,
1360,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
8468,
282,
9067,
1329,
901,
334,
46,
1772,
9,
315,
314,
1475,
5787,
13,
13933,
13,
2483,
13,
2483,
503,
1323,
56,
13,
2483,
13,
13933,
13,
13933,
8038,
267,
283,
8928,
356,
12561,
85,
7,
14858,
9040,
367,
314,
30174,
4860,
334,
46,
1772,
680,
659,
272,
789,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
2749,
46,
1772,
792,
12,
291,
2843,
826,
721,
82,
15542,
68,
91,
19,
93,
2696,
68,
91,
19,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
93,
31686,
12773,
68,
91,
18,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
19,
93,
2696,
68,
91,
19,
19204,
288,
1390,
63,
1267,
29,
403,
12,
1748,
63,
1267,
29,
403,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
585,
304,
267,
1613,
8,
2749,
46,
1772,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
574,
275,
295,
14,
954,
480,
1988,
11472,
4873,
574,
9,
267,
340,
440,
291,
14,
1989,
63,
1078,
63,
8928,
8,
585,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
8928,
1105,
267,
372,
399,
5956,
83,
7,
450,
574,
339,
347,
965,
63,
1078,
63,
8928,
8,
277,
12,
1329,
304,
267,
408,
267,
28562,
282,
9040,
543,
314,
2741,
5563,
14,
267,
408,
267,
3663,
63,
1224,
275,
334,
22,
12,
959,
12,
1520,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
9,
267,
754,
275,
378,
267,
367,
284,
315,
1425,
8,
552,
8,
1955,
7216,
17,
304,
288,
754,
847,
1109,
8,
1955,
59,
73,
566,
627,
3663,
63,
1224,
59,
73,
61,
398,
754,
450,
29,
4119,
267,
340,
754,
508,
1109,
8,
1955,
1988,
17,
4682,
288,
372,
715,
267,
587,
26,
288,
372,
756,
199,
199,
533,
10092,
5616,
615,
792,
8,
5103,
792,
304,
272,
408,
272,
437,
1824,
901,
626,
29280,
2399,
1324,
365,
282,
14142,
615,
1329,
14,
339,
4821,
1295,
265,
1329,
18581,
402,
1749,
503,
4329,
7576,
14,
272,
1666,
1455,
921,
1544,
14,
3736,
14,
16294,
14,
1168,
15,
27566,
15,
1135,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
flumotion-mirror/flumotion
|
flumotion/test/test_component_httpserver_httpcached_httputils.py
|
3
|
11944
|
# -*- Mode: Python; test-case-name: flumotion.test.test_common -*-
# vi:si:et:sw=4:sts=4:ts=4
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L.
# Copyright (C) 2010,2011 Flumotion Services, S.A.
# All rights reserved.
#
# This file may be distributed and/or modified under the terms of
# the GNU Lesser General Public License version 2.1 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.LGPL" in the source distribution for more information.
#
# Headers in this file shall remain intact.
from flumotion.common.testsuite import TestCase
from flumotion.component.misc.httpserver.httpcached.http_utils import Url
#TODO: Add a test for multiple different query fields (reordering issues)
class TestURL(TestCase):
def testQuotedSpaces(self):
def check(_url, _loc, _path, _query, **kwargs):
obj = Url(**kwargs)
self.assertEqual(str(obj), _url)
self.assertEqual(obj.url, _url)
self.assertEqual(obj.location, _loc)
self.assertEqual(obj.path, _path)
self.assertEqual(obj.query, _query)
obj2 = Url.fromString(_url)
self.assertEqual(str(obj2), str(obj))
self.assertEqual(str(obj2), _url)
check("/", "/", "/", {}, path="/")
check("/with%20lots/%20of%20/nasty%20spaces.txt",
"/with%20lots/%20of%20/nasty%20spaces.txt",
"/with lots/ of /nasty spaces.txt", {},
path="/with lots/ of /nasty spaces.txt")
check("/path?que%20ry=val%20u",
"/path?que%20ry=val%20u",
"/path", {"que ry": ["val u"]},
path="/path", query={"que ry": ["val u"]})
def testRelativeToString(self):
def check(url, loc, **kwargs):
obj = Url(**kwargs)
self.assertEqual(str(obj), url)
self.assertEqual(obj.url, url)
self.assertEqual(obj.location, loc)
check("/", "/")
check("/", "/", path="/")
check("/;P", "/;P", params="P")
check("/?n=v", "/?n=v", query={"n": ["v"]})
check("/#f", "/#f", fragment="f")
check("/", "/", username="user")
check("/", "/", password="test")
check("/", "/", port=8080)
check("/sub/dir/file.py;params?query=val#anchor",
"/sub/dir/file.py;params?query=val#anchor",
path="/sub/dir/file.py", params="params",
query={"query": ["val"]}, fragment="anchor")
check("/;params?query=val#anchor",
"/;params?query=val#anchor",
params="params",
query={"query": ["val"]}, fragment="anchor")
check("/sub/dir/file.py?query=val#anchor",
"/sub/dir/file.py?query=val#anchor",
path="/sub/dir/file.py",
query={"query": ["val"]}, fragment="anchor")
check("/sub/dir/file.py;params#anchor",
"/sub/dir/file.py;params#anchor",
path="/sub/dir/file.py", params="params",
query={}, fragment="anchor")
check("/sub/dir/file.py;params?query=val",
"/sub/dir/file.py;params?query=val",
path="/sub/dir/file.py", params="params",
query={"query": ["val"]})
def testAbsoluteToString(self):
def check(url, loc, netloc, host, **kwargs):
obj = Url(**kwargs)
self.assertEqual(str(obj), url)
self.assertEqual(obj.url, url)
self.assertEqual(obj.netloc, netloc)
self.assertEqual(obj.host, host)
self.assertEqual(obj.location, loc)
check("http://localhost/", "/", "localhost", "localhost",
hostname="localhost")
check("http://localhost/", "/", "localhost", "localhost",
hostname="localhost", path="/")
check("https://localhost/", "/", "localhost", "localhost",
scheme='https', hostname="localhost")
check("http://localhost:8080/", "/", "localhost:8080",
"localhost:8080", hostname="localhost", port=8080)
check("http://localhost/", "/", "localhost", "localhost",
hostname="localhost", port=80)
check("https://localhost:80/", "/", "localhost:80", "localhost:80",
scheme="https", hostname="localhost", port=80)
check("http://user@localhost/", "/", "user@localhost", "localhost",
hostname="localhost", username='user')
check("http://localhost/", "/", "localhost", "localhost",
hostname="localhost", password='test')
check("http://user:test@localhost/", "/", "user:test@localhost",
"localhost", hostname="localhost",
username='user', password='test')
check("http://user:test@localhost:8080/", "/",
"user:test@localhost:8080", "localhost:8080",
hostname="localhost", port=8080,
username='user', password='test')
check("http://localhost/sub/dir/file.py;P?Q=#F",
"/sub/dir/file.py;P?Q=#F", "localhost", "localhost",
hostname="localhost", path="/sub/dir/file.py",
query={"Q": [""]}, params="P", fragment="F")
def testRelativeFromString(self):
def check(url, **kwargs):
obj = Url.fromString(url)
self.assertEqual(obj.url, url)
for n, v in kwargs.items():
self.assertEqual(getattr(obj, n), v)
self.assertEqual(type(Url.fromString("/")), type(Url()))
check("/",
scheme="", hostname="", path="/",
username=None, password=None, port=None,
params="", query={}, fragment="",
location="/")
check("/sub/file;param?query=string#fragment",
scheme="", hostname="", path="/sub/file",
username=None, password=None, port=None,
params="param", query={"query": ["string"]},
fragment="fragment",
location="/sub/file;param?query=string#fragment")
check("/;param?query=s1&query=s2#fragment",
scheme="", hostname="", path="/",
username=None, password=None, port=None,
params="param", query={"query": ["s1", "s2"]},
fragment="fragment",
location="/;param?query=s1&query=s2#fragment")
check("/sub/file?q1=s1#fragment",
scheme="", hostname="", path="/sub/file",
username=None, password=None, port=None,
params="", query={"q1": ["s1"]},
fragment="fragment",
location="/sub/file?q1=s1#fragment")
check("/sub/file;param#fragment",
scheme="", hostname="", path="/sub/file",
username=None, password=None, port=None,
params="param", query={}, fragment="fragment",
location="/sub/file;param#fragment")
check("/sub/file;param?query=string",
scheme="", hostname="", path="/sub/file",
username=None, password=None, port=None,
params="param", query={"query": ["string"]},
fragment="", location="/sub/file;param?query=string")
def testAbsoluteFromString(self):
def check(url, netloc, host, **kwargs):
obj = Url.fromString(url)
self.assertEqual(obj.url, url)
self.assertEqual(obj.netloc, netloc)
self.assertEqual(obj.host, host)
for n, v in kwargs.items():
self.assertEqual(getattr(obj, n), v)
check("http://user:test@localhost:8080"
"/sub/file;param?query=string#fragment",
"user:test@localhost:8080", "localhost:8080",
scheme="http", hostname="localhost", path="/sub/file",
username="user", password="test", port=8080,
params="param", query={"query": ["string"]},
fragment="fragment",
location="/sub/file;param?query=string#fragment")
check("https://user:test@localhost:8080"
"/sub/file;param?q=s1&q=s2&q=s3#fragment",
"user:test@localhost:8080", "localhost:8080",
scheme="https", hostname="localhost", path="/sub/file",
username="user", password="test", port=8080,
params="param", query={"q": ["s1", "s2", "s3"]},
fragment="fragment",
location="/sub/file;param?q=s1&q=s2&q=s3#fragment")
check("http://user@localhost:8080"
"/sub/file;param?query=#fragment",
"user@localhost:8080", "localhost:8080",
scheme="http", hostname="localhost", path="/sub/file",
username="user", password=None, port=8080,
params="param", query={"query": [""]},
fragment="fragment",
location="/sub/file;param?query=#fragment")
check("http://localhost:8080"
"/sub/file;param?query=string#fragment",
"localhost:8080", "localhost:8080",
scheme="http", hostname="localhost", path="/sub/file",
username=None, password=None, port=8080,
params="param", query={"query": ["string"]},
fragment="fragment",
location="/sub/file;param?query=string#fragment")
check("http://user:test@localhost"
"/sub/file;param?query=string#fragment",
"user:test@localhost", "localhost",
scheme="http", hostname="localhost", path="/sub/file",
username="user", password="test", port=80,
params="param", query={"query": ["string"]},
fragment="fragment",
location="/sub/file;param?query=string#fragment")
check("https://user:test@localhost"
"/sub/file;param?query=string#fragment",
"user:test@localhost", "localhost",
scheme="https", hostname="localhost", path="/sub/file",
username="user", password="test", port=443,
params="param", query={"query": ["string"]},
fragment="fragment",
location="/sub/file;param?query=string#fragment")
check("http://user:test@localhost:8080"
"/;param?query=string#fragment",
"user:test@localhost:8080", "localhost:8080",
scheme="http", hostname="localhost", path="/",
username="user", password="test", port=8080,
params="param", query={"query": ["string"]},
fragment="fragment",
location="/;param?query=string#fragment")
check("http://user:test@localhost:8080"
"/sub/file?query=string#fragment",
"user:test@localhost:8080", "localhost:8080",
scheme="http", hostname="localhost", path="/sub/file",
username="user", password="test", port=8080,
params="", query={"query": ["string"]},
fragment="fragment",
location="/sub/file?query=string#fragment")
check("http://user:test@localhost:8080/sub/file;param#fragment",
"user:test@localhost:8080", "localhost:8080",
scheme="http", hostname="localhost", path="/sub/file",
username="user", password="test", port=8080,
params="param", query={}, fragment="fragment",
location="/sub/file;param#fragment")
check("http://user:test@localhost:8080/sub/file;param?query=string",
"user:test@localhost:8080", "localhost:8080",
scheme="http", hostname="localhost", path="/sub/file",
username="user", password="test", port=8080,
params="param", query={"query": ["string"]},
fragment="", location="/sub/file;param?query=string")
|
lgpl-2.1
|
[
3,
1882,
4900,
26,
2018,
27,
511,
13,
2546,
13,
354,
26,
2717,
453,
23193,
14,
396,
14,
396,
63,
2330,
1882,
199,
3,
1321,
26,
338,
26,
386,
26,
3519,
29,
20,
26,
10329,
29,
20,
26,
1086,
29,
20,
199,
199,
3,
11040,
453,
23193,
446,
282,
18490,
5898,
1654,
199,
3,
1898,
334,
35,
9,
8353,
12,
9397,
12,
7968,
12,
9488,
12,
9300,
12,
8664,
481,
10836,
500,
79,
12,
428,
14,
44,
14,
199,
3,
1898,
334,
35,
9,
7129,
12,
8128,
11040,
453,
23193,
21813,
12,
428,
14,
33,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
1443,
506,
1854,
436,
15,
269,
6042,
1334,
314,
2895,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
1015,
499,
14,
17,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
14,
199,
3,
961,
570,
365,
1854,
1928,
1263,
3750,
27,
1928,
2755,
314,
2478,
199,
3,
3750,
402,
4004,
26938,
3616,
503,
5542,
4171,
367,
282,
6770,
12016,
14,
199,
3,
1666,
298,
3961,
14,
44,
12006,
2,
315,
314,
1350,
4084,
367,
1655,
2556,
14,
199,
3,
199,
3,
21391,
315,
642,
570,
10989,
5706,
315,
4552,
14,
199,
199,
504,
2717,
453,
23193,
14,
2330,
14,
14239,
492,
7640,
199,
199,
504,
2717,
453,
23193,
14,
3173,
14,
9923,
14,
1014,
1000,
14,
1014,
5245,
14,
1014,
63,
1208,
492,
20503,
199,
199,
3,
11768,
26,
2654,
282,
511,
367,
3663,
3365,
1827,
1504,
334,
264,
7128,
10876,
9,
421,
199,
533,
1379,
2632,
8,
1746,
304,
339,
347,
511,
24115,
23415,
8,
277,
304,
398,
347,
1104,
1547,
633,
12,
485,
2102,
12,
485,
515,
12,
485,
1131,
12,
1011,
958,
304,
288,
1559,
275,
20503,
3682,
958,
9,
288,
291,
14,
629,
8,
495,
8,
1113,
395,
485,
633,
9,
288,
291,
14,
629,
8,
1113,
14,
633,
12,
485,
633,
9,
288,
291,
14,
629,
8,
1113,
14,
1985,
12,
485,
2102,
9,
288,
291,
14,
629,
8,
1113,
14,
515,
12,
485,
515,
9,
288,
291,
14,
629,
8,
1113,
14,
1131,
12,
485,
1131,
9,
953,
1559,
18,
275,
20503,
14,
504,
1558,
1547,
633,
9,
288,
291,
14,
629,
8,
495,
8,
1113,
18,
395,
620,
8,
1113,
430,
288,
291,
14,
629,
8,
495,
8,
1113,
18,
395,
485,
633,
9,
398,
1104,
27374,
3286,
401,
3286,
401,
5479,
931,
9555,
531,
398,
1104,
4769,
1045,
5,
1165,
4555,
3149,
1165,
1618,
5,
1165,
15,
78,
27352,
5,
1165,
10749,
14,
2424,
401,
1598,
3286,
1045,
5,
1165,
4555,
3149,
1165,
1618,
5,
1165,
15,
78,
27352,
5,
1165,
10749,
14,
2424,
401,
1598,
3286,
1045,
24213,
15,
402,
1182,
78,
27352,
7883,
14,
2424,
401,
5479,
1598,
931,
9555,
1045,
24213,
15,
402,
1182,
78,
27352,
7883,
14,
2424,
531,
398,
1104,
4769,
515,
31,
544,
5,
1165,
651,
29,
637,
5,
1165,
85,
401,
1598,
3286,
515,
31,
544,
5,
1165,
651,
29,
637,
5,
1165,
85,
401,
1598,
3286,
515,
401,
2420,
544,
519,
89,
582,
2097,
637,
399,
19057,
1598,
931,
9555,
515,
401,
1827,
8871,
544,
519,
89,
582,
2097,
637,
399,
21900,
339,
347,
511,
15277,
7756,
8,
277,
304,
398,
347,
1104,
8,
633,
12,
4355,
12,
1011,
958,
304,
288,
1559,
275,
20503,
3682,
958,
9,
288,
291,
14,
629,
8,
495,
8,
1113,
395,
1166,
9,
288,
291,
14,
629,
8,
1113,
14,
633,
12,
1166,
9,
288,
291,
14,
629,
8,
1113,
14,
1985,
12,
4355,
9,
398,
1104,
27374,
3286,
531,
267,
1104,
27374,
3286,
401,
931,
9555,
531,
267,
1104,
4769,
27,
48,
401,
3286,
27,
48,
401,
1862,
628,
48,
531,
267,
1104,
4769,
31,
78,
29,
86,
401,
3286,
31,
78,
29,
86,
401,
1827,
8871,
78,
582,
2097,
86,
21900,
267,
1104,
4769,
3,
70,
401,
3286,
3,
70,
401,
7956,
628,
70,
531,
267,
1104,
27374,
3286,
401,
3434,
628,
751,
531,
267,
1104,
27374,
3286,
401,
2505,
628,
396,
531,
267,
1104,
27374,
3286,
401,
1844,
29,
15844,
9,
267,
1104,
4769,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
31,
1131,
29,
637,
3,
11498,
401,
1598,
3286,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
31,
1131,
29,
637,
3,
11498,
401,
1598,
931,
9555,
954,
15,
694,
15,
493,
14,
647,
401,
1862,
628,
1162,
401,
1598,
1827,
8871,
1131,
582,
2097,
637,
19057,
7956,
628,
11498,
531,
267,
1104,
4769,
27,
1162,
31,
1131,
29,
637,
3,
11498,
401,
1598,
3286,
27,
1162,
31,
1131,
29,
637,
3,
11498,
401,
1598,
1862,
628,
1162,
401,
1598,
1827,
8871,
1131,
582,
2097,
637,
19057,
7956,
628,
11498,
531,
267,
1104,
4769,
954,
15,
694,
15,
493,
14,
647,
31,
1131,
29,
637,
3,
11498,
401,
1598,
3286,
954,
15,
694,
15,
493,
14,
647,
31,
1131,
29,
637,
3,
11498,
401,
1598,
931,
9555,
954,
15,
694,
15,
493,
14,
647,
401,
1598,
1827,
8871,
1131,
582,
2097,
637,
19057,
7956,
628,
11498,
531,
267,
1104,
4769,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
3,
11498,
401,
1598,
3286,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
3,
11498,
401,
1598,
931,
9555,
954,
15,
694,
15,
493,
14,
647,
401,
1862,
628,
1162,
401,
1598,
1827,
10324,
7956,
628,
11498,
531,
267,
1104,
4769,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
31,
1131,
29,
637,
401,
1598,
3286,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
31,
1131,
29,
637,
401,
1598,
931,
9555,
954,
15,
694,
15,
493,
14,
647,
401,
1862,
628,
1162,
401,
1598,
1827,
8871,
1131,
582,
2097,
637,
21900,
339,
347,
511,
24677,
7756,
8,
277,
304,
398,
347,
1104,
8,
633,
12,
4355,
12,
10154,
12,
1591,
12,
1011,
958,
304,
288,
1559,
275,
20503,
3682,
958,
9,
288,
291,
14,
629,
8,
495,
8,
1113,
395,
1166,
9,
288,
291,
14,
629,
8,
1113,
14,
633,
12,
1166,
9,
288,
291,
14,
629,
8,
1113,
14,
12652,
12,
10154,
9,
288,
291,
14,
629,
8,
1113,
14,
1102,
12,
1591,
9,
288,
291,
14,
629,
8,
1113,
14
] |
[
1882,
4900,
26,
2018,
27,
511,
13,
2546,
13,
354,
26,
2717,
453,
23193,
14,
396,
14,
396,
63,
2330,
1882,
199,
3,
1321,
26,
338,
26,
386,
26,
3519,
29,
20,
26,
10329,
29,
20,
26,
1086,
29,
20,
199,
199,
3,
11040,
453,
23193,
446,
282,
18490,
5898,
1654,
199,
3,
1898,
334,
35,
9,
8353,
12,
9397,
12,
7968,
12,
9488,
12,
9300,
12,
8664,
481,
10836,
500,
79,
12,
428,
14,
44,
14,
199,
3,
1898,
334,
35,
9,
7129,
12,
8128,
11040,
453,
23193,
21813,
12,
428,
14,
33,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
1443,
506,
1854,
436,
15,
269,
6042,
1334,
314,
2895,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
1015,
499,
14,
17,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
14,
199,
3,
961,
570,
365,
1854,
1928,
1263,
3750,
27,
1928,
2755,
314,
2478,
199,
3,
3750,
402,
4004,
26938,
3616,
503,
5542,
4171,
367,
282,
6770,
12016,
14,
199,
3,
1666,
298,
3961,
14,
44,
12006,
2,
315,
314,
1350,
4084,
367,
1655,
2556,
14,
199,
3,
199,
3,
21391,
315,
642,
570,
10989,
5706,
315,
4552,
14,
199,
199,
504,
2717,
453,
23193,
14,
2330,
14,
14239,
492,
7640,
199,
199,
504,
2717,
453,
23193,
14,
3173,
14,
9923,
14,
1014,
1000,
14,
1014,
5245,
14,
1014,
63,
1208,
492,
20503,
199,
199,
3,
11768,
26,
2654,
282,
511,
367,
3663,
3365,
1827,
1504,
334,
264,
7128,
10876,
9,
421,
199,
533,
1379,
2632,
8,
1746,
304,
339,
347,
511,
24115,
23415,
8,
277,
304,
398,
347,
1104,
1547,
633,
12,
485,
2102,
12,
485,
515,
12,
485,
1131,
12,
1011,
958,
304,
288,
1559,
275,
20503,
3682,
958,
9,
288,
291,
14,
629,
8,
495,
8,
1113,
395,
485,
633,
9,
288,
291,
14,
629,
8,
1113,
14,
633,
12,
485,
633,
9,
288,
291,
14,
629,
8,
1113,
14,
1985,
12,
485,
2102,
9,
288,
291,
14,
629,
8,
1113,
14,
515,
12,
485,
515,
9,
288,
291,
14,
629,
8,
1113,
14,
1131,
12,
485,
1131,
9,
953,
1559,
18,
275,
20503,
14,
504,
1558,
1547,
633,
9,
288,
291,
14,
629,
8,
495,
8,
1113,
18,
395,
620,
8,
1113,
430,
288,
291,
14,
629,
8,
495,
8,
1113,
18,
395,
485,
633,
9,
398,
1104,
27374,
3286,
401,
3286,
401,
5479,
931,
9555,
531,
398,
1104,
4769,
1045,
5,
1165,
4555,
3149,
1165,
1618,
5,
1165,
15,
78,
27352,
5,
1165,
10749,
14,
2424,
401,
1598,
3286,
1045,
5,
1165,
4555,
3149,
1165,
1618,
5,
1165,
15,
78,
27352,
5,
1165,
10749,
14,
2424,
401,
1598,
3286,
1045,
24213,
15,
402,
1182,
78,
27352,
7883,
14,
2424,
401,
5479,
1598,
931,
9555,
1045,
24213,
15,
402,
1182,
78,
27352,
7883,
14,
2424,
531,
398,
1104,
4769,
515,
31,
544,
5,
1165,
651,
29,
637,
5,
1165,
85,
401,
1598,
3286,
515,
31,
544,
5,
1165,
651,
29,
637,
5,
1165,
85,
401,
1598,
3286,
515,
401,
2420,
544,
519,
89,
582,
2097,
637,
399,
19057,
1598,
931,
9555,
515,
401,
1827,
8871,
544,
519,
89,
582,
2097,
637,
399,
21900,
339,
347,
511,
15277,
7756,
8,
277,
304,
398,
347,
1104,
8,
633,
12,
4355,
12,
1011,
958,
304,
288,
1559,
275,
20503,
3682,
958,
9,
288,
291,
14,
629,
8,
495,
8,
1113,
395,
1166,
9,
288,
291,
14,
629,
8,
1113,
14,
633,
12,
1166,
9,
288,
291,
14,
629,
8,
1113,
14,
1985,
12,
4355,
9,
398,
1104,
27374,
3286,
531,
267,
1104,
27374,
3286,
401,
931,
9555,
531,
267,
1104,
4769,
27,
48,
401,
3286,
27,
48,
401,
1862,
628,
48,
531,
267,
1104,
4769,
31,
78,
29,
86,
401,
3286,
31,
78,
29,
86,
401,
1827,
8871,
78,
582,
2097,
86,
21900,
267,
1104,
4769,
3,
70,
401,
3286,
3,
70,
401,
7956,
628,
70,
531,
267,
1104,
27374,
3286,
401,
3434,
628,
751,
531,
267,
1104,
27374,
3286,
401,
2505,
628,
396,
531,
267,
1104,
27374,
3286,
401,
1844,
29,
15844,
9,
267,
1104,
4769,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
31,
1131,
29,
637,
3,
11498,
401,
1598,
3286,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
31,
1131,
29,
637,
3,
11498,
401,
1598,
931,
9555,
954,
15,
694,
15,
493,
14,
647,
401,
1862,
628,
1162,
401,
1598,
1827,
8871,
1131,
582,
2097,
637,
19057,
7956,
628,
11498,
531,
267,
1104,
4769,
27,
1162,
31,
1131,
29,
637,
3,
11498,
401,
1598,
3286,
27,
1162,
31,
1131,
29,
637,
3,
11498,
401,
1598,
1862,
628,
1162,
401,
1598,
1827,
8871,
1131,
582,
2097,
637,
19057,
7956,
628,
11498,
531,
267,
1104,
4769,
954,
15,
694,
15,
493,
14,
647,
31,
1131,
29,
637,
3,
11498,
401,
1598,
3286,
954,
15,
694,
15,
493,
14,
647,
31,
1131,
29,
637,
3,
11498,
401,
1598,
931,
9555,
954,
15,
694,
15,
493,
14,
647,
401,
1598,
1827,
8871,
1131,
582,
2097,
637,
19057,
7956,
628,
11498,
531,
267,
1104,
4769,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
3,
11498,
401,
1598,
3286,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
3,
11498,
401,
1598,
931,
9555,
954,
15,
694,
15,
493,
14,
647,
401,
1862,
628,
1162,
401,
1598,
1827,
10324,
7956,
628,
11498,
531,
267,
1104,
4769,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
31,
1131,
29,
637,
401,
1598,
3286,
954,
15,
694,
15,
493,
14,
647,
27,
1162,
31,
1131,
29,
637,
401,
1598,
931,
9555,
954,
15,
694,
15,
493,
14,
647,
401,
1862,
628,
1162,
401,
1598,
1827,
8871,
1131,
582,
2097,
637,
21900,
339,
347,
511,
24677,
7756,
8,
277,
304,
398,
347,
1104,
8,
633,
12,
4355,
12,
10154,
12,
1591,
12,
1011,
958,
304,
288,
1559,
275,
20503,
3682,
958,
9,
288,
291,
14,
629,
8,
495,
8,
1113,
395,
1166,
9,
288,
291,
14,
629,
8,
1113,
14,
633,
12,
1166,
9,
288,
291,
14,
629,
8,
1113,
14,
12652,
12,
10154,
9,
288,
291,
14,
629,
8,
1113,
14,
1102,
12,
1591,
9,
288,
291,
14,
629,
8,
1113,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
cs564/heron
|
third_party/pex/setup.py
|
11
|
1509
|
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
import os
from setuptools import setup
with open(os.path.join(os.path.dirname(__file__), 'CHANGES.rst')) as fp:
LONG_DESCRIPTION = fp.read()
# This seems to be a fairly standard version file pattern.
#
# Populates the following variables:
# __version__
# __setuptools_requirement
# __wheel_requirement
__version__ = ''
version_py_file = os.path.join(os.path.dirname(__file__), 'pex', 'version.py')
with open(version_py_file) as version_py:
exec(compile(version_py.read(), version_py_file, 'exec'))
setup(
name = 'pex',
version = __version__,
description = "The PEX packaging toolchain.",
long_description = LONG_DESCRIPTION,
url = 'https://github.com/pantsbuild/pex',
license = 'Apache License, Version 2.0',
zip_safe = True,
classifiers = [
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
],
packages = [
'pex',
'pex.bin',
],
install_requires = [
SETUPTOOLS_REQUIREMENT,
],
tests_require = [
'mock',
'twitter.common.contextutil>=0.3.1,<0.4.0',
'twitter.common.lang>=0.3.1,<0.4.0',
'twitter.common.testing>=0.3.1,<0.4.0',
'twitter.common.dirutil>=0.3.1,<0.4.0',
'pytest',
],
entry_points = {
'console_scripts': [
'pex = pex.bin.pex:main',
],
},
)
|
apache-2.0
|
[
3,
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
646,
747,
199,
199,
504,
9116,
492,
3272,
421,
199,
1045,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
17858,
654,
14,
8332,
1333,
465,
4090,
26,
523,
26594,
63,
17705,
275,
4090,
14,
739,
342,
421,
199,
3,
961,
12237,
370,
506,
282,
28092,
590,
4465,
1015,
570,
3851,
14,
199,
3,
199,
3,
13244,
15409,
314,
2569,
2860,
26,
199,
3,
257,
636,
1023,
363,
199,
3,
257,
636,
13623,
63,
12434,
199,
3,
257,
636,
11798,
63,
12434,
199,
363,
1023,
363,
275,
2125,
199,
1023,
63,
647,
63,
493,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
16531,
297,
283,
1023,
14,
647,
358,
199,
1045,
1551,
8,
1023,
63,
647,
63,
493,
9,
465,
1015,
63,
647,
26,
523,
2146,
8,
2014,
8,
1023,
63,
647,
14,
739,
1062,
1015,
63,
647,
63,
493,
12,
283,
1628,
1333,
421,
199,
2758,
8,
523,
536,
275,
283,
16531,
297,
523,
1015,
275,
636,
1023,
3108,
523,
1369,
275,
298,
1918,
510,
1438,
27369,
22689,
4765,
523,
1846,
63,
1802,
275,
26594,
63,
17705,
12,
523,
1166,
275,
283,
2859,
921,
5031,
14,
957,
15,
21970,
1506,
15,
16531,
297,
523,
4190,
275,
283,
28993,
844,
12,
3394,
499,
14,
16,
297,
523,
3482,
63,
3489,
275,
715,
12,
523,
19137,
275,
359,
272,
283,
23910,
23975,
3800,
23493,
297,
272,
283,
3761,
3800,
25718,
26330,
3800,
3668,
2290,
844,
297,
272,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
272,
283,
11411,
8466,
3800,
2018,
297,
523,
2156,
523,
6117,
275,
359,
272,
283,
16531,
297,
272,
283,
16531,
14,
1393,
297,
523,
2156,
523,
3907,
63,
6537,
275,
359,
272,
11543,
2160,
20261,
63,
29168,
4479,
12,
523,
2156,
523,
2295,
63,
4365,
275,
359,
272,
283,
1805,
297,
272,
283,
13746,
14,
2330,
14,
1100,
1974,
8119,
16,
14,
19,
14,
17,
30027,
16,
14,
20,
14,
16,
297,
272,
283,
13746,
14,
2330,
14,
4159,
8119,
16,
14,
19,
14,
17,
30027,
16,
14,
20,
14,
16,
297,
272,
283,
13746,
14,
2330,
14,
4776,
8119,
16,
14,
19,
14,
17,
30027,
16,
14,
20,
14,
16,
297,
272,
283,
13746,
14,
2330,
14,
694,
1974,
8119,
16,
14,
19,
14,
17,
30027,
16,
14,
20,
14,
16,
297,
272,
283,
4462,
297,
523,
2156,
523,
2397,
63,
3438,
275,
469,
272,
283,
6614,
63,
6429,
356,
359,
489,
283,
16531,
275,
299,
476,
14,
1393,
14,
16531,
26,
973,
297,
272,
2156,
523,
1660,
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
] |
[
1898,
6927,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
646,
747,
199,
199,
504,
9116,
492,
3272,
421,
199,
1045,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
17858,
654,
14,
8332,
1333,
465,
4090,
26,
523,
26594,
63,
17705,
275,
4090,
14,
739,
342,
421,
199,
3,
961,
12237,
370,
506,
282,
28092,
590,
4465,
1015,
570,
3851,
14,
199,
3,
199,
3,
13244,
15409,
314,
2569,
2860,
26,
199,
3,
257,
636,
1023,
363,
199,
3,
257,
636,
13623,
63,
12434,
199,
3,
257,
636,
11798,
63,
12434,
199,
363,
1023,
363,
275,
2125,
199,
1023,
63,
647,
63,
493,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
16531,
297,
283,
1023,
14,
647,
358,
199,
1045,
1551,
8,
1023,
63,
647,
63,
493,
9,
465,
1015,
63,
647,
26,
523,
2146,
8,
2014,
8,
1023,
63,
647,
14,
739,
1062,
1015,
63,
647,
63,
493,
12,
283,
1628,
1333,
421,
199,
2758,
8,
523,
536,
275,
283,
16531,
297,
523,
1015,
275,
636,
1023,
3108,
523,
1369,
275,
298,
1918,
510,
1438,
27369,
22689,
4765,
523,
1846,
63,
1802,
275,
26594,
63,
17705,
12,
523,
1166,
275,
283,
2859,
921,
5031,
14,
957,
15,
21970,
1506,
15,
16531,
297,
523,
4190,
275,
283,
28993,
844,
12,
3394,
499,
14,
16,
297,
523,
3482,
63,
3489,
275,
715,
12,
523,
19137,
275,
359,
272,
283,
23910,
23975,
3800,
23493,
297,
272,
283,
3761,
3800,
25718,
26330,
3800,
3668,
2290,
844,
297,
272,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
272,
283,
11411,
8466,
3800,
2018,
297,
523,
2156,
523,
6117,
275,
359,
272,
283,
16531,
297,
272,
283,
16531,
14,
1393,
297,
523,
2156,
523,
3907,
63,
6537,
275,
359,
272,
11543,
2160,
20261,
63,
29168,
4479,
12,
523,
2156,
523,
2295,
63,
4365,
275,
359,
272,
283,
1805,
297,
272,
283,
13746,
14,
2330,
14,
1100,
1974,
8119,
16,
14,
19,
14,
17,
30027,
16,
14,
20,
14,
16,
297,
272,
283,
13746,
14,
2330,
14,
4159,
8119,
16,
14,
19,
14,
17,
30027,
16,
14,
20,
14,
16,
297,
272,
283,
13746,
14,
2330,
14,
4776,
8119,
16,
14,
19,
14,
17,
30027,
16,
14,
20,
14,
16,
297,
272,
283,
13746,
14,
2330,
14,
694,
1974,
8119,
16,
14,
19,
14,
17,
30027,
16,
14,
20,
14,
16,
297,
272,
283,
4462,
297,
523,
2156,
523,
2397,
63,
3438,
275,
469,
272,
283,
6614,
63,
6429,
356,
359,
489,
283,
16531,
275,
299,
476,
14,
1393,
14,
16531,
26,
973,
297,
272,
2156,
523,
1660,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wpjesus/codematch
|
ietf/doc/lastcall.py
|
1
|
2727
|
# helpers for handling last calls on Internet Drafts
import datetime
from django.db.models import Q
from ietf.doc.models import Document, State, DocEvent, LastCallDocEvent, WriteupDocEvent
from ietf.doc.models import save_document_in_history
from ietf.doc.models import IESG_SUBSTATE_TAGS
from ietf.person.models import Person
from ietf.doc.utils import add_state_change_event
from ietf.doc.mails import generate_ballot_writeup, generate_approval_mail, generate_last_call_announcement
from ietf.doc.mails import send_last_call_request, email_last_call_expired
def request_last_call(request, doc):
if not doc.latest_event(type="changed_ballot_writeup_text"):
generate_ballot_writeup(request, doc)
if not doc.latest_event(type="changed_ballot_approval_text"):
generate_approval_mail(request, doc)
if not doc.latest_event(type="changed_last_call_text"):
generate_last_call_announcement(request, doc)
send_last_call_request(request, doc)
e = DocEvent()
e.type = "requested_last_call"
e.by = request.user.person
e.doc = doc
e.desc = "Last call was requested"
e.save()
def get_expired_last_calls():
today = datetime.date.today()
for d in Document.objects.filter(Q(states__type="draft-iesg", states__slug="lc")
| Q(states__type="statchg", states__slug="in-lc")):
e = d.latest_event(LastCallDocEvent, type="sent_last_call")
if e and e.expires.date() <= today:
yield d
def expire_last_call(doc):
if doc.type_id == 'draft':
new_state = State.objects.get(used=True, type="draft-iesg", slug="writeupw")
e = doc.latest_event(WriteupDocEvent, type="changed_ballot_writeup_text")
if e and "Relevant content can frequently be found in the abstract" not in e.text:
# if boiler-plate text has been removed, we assume the
# write-up has been written
new_state = State.objects.get(used=True, type="draft-iesg", slug="goaheadw")
elif doc.type_id == 'statchg':
new_state = State.objects.get(used=True, type="statchg", slug="goahead")
else:
raise ValueError("Unexpected document type to expire_last_call(): %s" % doc.type)
save_document_in_history(doc)
prev_state = doc.get_state(new_state.type_id)
doc.set_state(new_state)
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
doc.tags.remove(*prev_tags)
system = Person.objects.get(name="(System)")
e = add_state_change_event(doc, system, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
doc.time = (e and e.time) or datetime.datetime.now()
doc.save()
email_last_call_expired(doc)
|
bsd-3-clause
|
[
3,
10897,
367,
7252,
2061,
4882,
641,
22026,
28090,
83,
199,
199,
646,
2197,
199,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
199,
504,
284,
386,
70,
14,
1301,
14,
992,
492,
7543,
12,
8511,
12,
5454,
2390,
12,
15237,
2176,
3768,
2390,
12,
6990,
384,
3768,
2390,
199,
504,
284,
386,
70,
14,
1301,
14,
992,
492,
3354,
63,
3554,
63,
262,
63,
5570,
199,
504,
284,
386,
70,
14,
1301,
14,
992,
492,
473,
654,
39,
63,
6348,
6689,
63,
17626,
199,
504,
284,
386,
70,
14,
5484,
14,
992,
492,
8028,
199,
504,
284,
386,
70,
14,
1301,
14,
1208,
492,
1050,
63,
929,
63,
1461,
63,
1430,
199,
504,
284,
386,
70,
14,
1301,
14,
1198,
83,
492,
3550,
63,
4982,
1653,
63,
952,
384,
12,
3550,
63,
28302,
63,
1198,
12,
3550,
63,
2019,
63,
1250,
63,
17803,
434,
199,
504,
284,
386,
70,
14,
1301,
14,
1198,
83,
492,
3222,
63,
2019,
63,
1250,
63,
1069,
12,
3031,
63,
2019,
63,
1250,
63,
16340,
199,
199,
318,
1056,
63,
2019,
63,
1250,
8,
1069,
12,
1382,
304,
272,
340,
440,
1382,
14,
7410,
63,
1430,
8,
466,
628,
2489,
63,
4982,
1653,
63,
952,
384,
63,
505,
2349,
267,
3550,
63,
4982,
1653,
63,
952,
384,
8,
1069,
12,
1382,
9,
272,
340,
440,
1382,
14,
7410,
63,
1430,
8,
466,
628,
2489,
63,
4982,
1653,
63,
28302,
63,
505,
2349,
267,
3550,
63,
28302,
63,
1198,
8,
1069,
12,
1382,
9,
272,
340,
440,
1382,
14,
7410,
63,
1430,
8,
466,
628,
2489,
63,
2019,
63,
1250,
63,
505,
2349,
267,
3550,
63,
2019,
63,
1250,
63,
17803,
434,
8,
1069,
12,
1382,
9,
2286,
3222,
63,
2019,
63,
1250,
63,
1069,
8,
1069,
12,
1382,
9,
2286,
325,
275,
5454,
2390,
342,
272,
325,
14,
466,
275,
298,
11151,
63,
2019,
63,
1250,
2,
272,
325,
14,
991,
275,
1056,
14,
751,
14,
5484,
272,
325,
14,
1301,
275,
1382,
272,
325,
14,
3257,
275,
298,
6090,
1240,
1990,
5839,
2,
272,
325,
14,
2117,
342,
199,
199,
318,
664,
63,
16340,
63,
2019,
63,
5352,
837,
272,
11168,
275,
2197,
14,
602,
14,
8136,
342,
272,
367,
366,
315,
7543,
14,
1462,
14,
1541,
8,
49,
8,
4981,
363,
466,
628,
7185,
13,
1500,
71,
401,
6363,
363,
5464,
628,
10181,
531,
2511,
1204,
1413,
8,
4981,
363,
466,
628,
270,
693,
71,
401,
6363,
363,
5464,
628,
262,
13,
10181,
14150,
267,
325,
275,
366,
14,
7410,
63,
1430,
8,
6090,
2176,
3768,
2390,
12,
730,
628,
1150,
63,
2019,
63,
1250,
531,
267,
340,
325,
436,
325,
14,
12342,
14,
602,
342,
2695,
11168,
26,
288,
1995,
366,
199,
199,
318,
16667,
63,
2019,
63,
1250,
8,
1301,
304,
272,
340,
1382,
14,
466,
63,
344,
508,
283,
7185,
356,
267,
892,
63,
929,
275,
8511,
14,
1462,
14,
362,
8,
2972,
29,
549,
12,
730,
628,
7185,
13,
1500,
71,
401,
8889,
628,
952,
384,
87,
531,
267,
325,
275,
1382,
14,
7410,
63,
1430,
8,
3534,
384,
3768,
2390,
12,
730,
628,
2489,
63,
4982,
1653,
63,
952,
384,
63,
505,
531,
267,
340,
325,
436,
298,
497,
9723,
1564,
883,
28914,
590,
506,
1911,
315,
314,
9006,
2,
440,
315,
325,
14,
505,
26,
288,
327,
340,
1234,
3566,
13,
17673,
1318,
965,
2757,
4829,
12,
781,
5534,
314,
288,
327,
2218,
13,
384,
965,
2757,
5313,
288,
892,
63,
929,
275,
8511,
14,
1462,
14,
362,
8,
2972,
29,
549,
12,
730,
628,
7185,
13,
1500,
71,
401,
8889,
628,
1939,
10938,
87,
531,
272,
916,
1382,
14,
466,
63,
344,
508,
283,
270,
693,
71,
356,
267,
892,
63,
929,
275,
8511,
14,
1462,
14,
362,
8,
2972,
29,
549,
12,
730,
628,
270,
693,
71,
401,
8889,
628,
1939,
10938,
531,
272,
587,
26,
267,
746,
1722,
480,
8708,
2213,
730,
370,
16667,
63,
2019,
63,
1250,
837,
450,
83,
2,
450,
1382,
14,
466,
9,
339,
3354,
63,
3554,
63,
262,
63,
5570,
8,
1301,
9,
339,
5071,
63,
929,
275,
1382,
14,
362,
63,
929,
8,
1222,
63,
929,
14,
466,
63,
344,
9,
272,
1382,
14,
409,
63,
929,
8,
1222,
63,
929,
9,
339,
5071,
63,
2969,
275,
1382,
14,
2969,
14,
1541,
8,
5464,
363,
262,
29,
2563,
39,
63,
6348,
6689,
63,
17626,
9,
272,
1382,
14,
2969,
14,
2168,
2031,
5701,
63,
2969,
9,
339,
2656,
275,
8028,
14,
1462,
14,
362,
8,
354,
628,
8,
3989,
6320,
272,
325,
275,
1050,
63,
929,
63,
1461,
63,
1430,
8,
1301,
12,
2656,
12,
5071,
63,
929,
12,
892,
63,
929,
12,
5071,
63,
2969,
29,
5701,
63,
2969,
12,
892,
63,
2969,
14285,
2151,
272,
1382,
14,
521,
275,
334,
69,
436,
325,
14,
521,
9,
503,
2197,
14,
2083,
14,
2131,
342,
272,
1382,
14,
2117,
342,
339,
3031,
63,
2019,
63,
1250,
63,
16340,
8,
1301,
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
] |
[
10897,
367,
7252,
2061,
4882,
641,
22026,
28090,
83,
199,
199,
646,
2197,
199,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
199,
504,
284,
386,
70,
14,
1301,
14,
992,
492,
7543,
12,
8511,
12,
5454,
2390,
12,
15237,
2176,
3768,
2390,
12,
6990,
384,
3768,
2390,
199,
504,
284,
386,
70,
14,
1301,
14,
992,
492,
3354,
63,
3554,
63,
262,
63,
5570,
199,
504,
284,
386,
70,
14,
1301,
14,
992,
492,
473,
654,
39,
63,
6348,
6689,
63,
17626,
199,
504,
284,
386,
70,
14,
5484,
14,
992,
492,
8028,
199,
504,
284,
386,
70,
14,
1301,
14,
1208,
492,
1050,
63,
929,
63,
1461,
63,
1430,
199,
504,
284,
386,
70,
14,
1301,
14,
1198,
83,
492,
3550,
63,
4982,
1653,
63,
952,
384,
12,
3550,
63,
28302,
63,
1198,
12,
3550,
63,
2019,
63,
1250,
63,
17803,
434,
199,
504,
284,
386,
70,
14,
1301,
14,
1198,
83,
492,
3222,
63,
2019,
63,
1250,
63,
1069,
12,
3031,
63,
2019,
63,
1250,
63,
16340,
199,
199,
318,
1056,
63,
2019,
63,
1250,
8,
1069,
12,
1382,
304,
272,
340,
440,
1382,
14,
7410,
63,
1430,
8,
466,
628,
2489,
63,
4982,
1653,
63,
952,
384,
63,
505,
2349,
267,
3550,
63,
4982,
1653,
63,
952,
384,
8,
1069,
12,
1382,
9,
272,
340,
440,
1382,
14,
7410,
63,
1430,
8,
466,
628,
2489,
63,
4982,
1653,
63,
28302,
63,
505,
2349,
267,
3550,
63,
28302,
63,
1198,
8,
1069,
12,
1382,
9,
272,
340,
440,
1382,
14,
7410,
63,
1430,
8,
466,
628,
2489,
63,
2019,
63,
1250,
63,
505,
2349,
267,
3550,
63,
2019,
63,
1250,
63,
17803,
434,
8,
1069,
12,
1382,
9,
2286,
3222,
63,
2019,
63,
1250,
63,
1069,
8,
1069,
12,
1382,
9,
2286,
325,
275,
5454,
2390,
342,
272,
325,
14,
466,
275,
298,
11151,
63,
2019,
63,
1250,
2,
272,
325,
14,
991,
275,
1056,
14,
751,
14,
5484,
272,
325,
14,
1301,
275,
1382,
272,
325,
14,
3257,
275,
298,
6090,
1240,
1990,
5839,
2,
272,
325,
14,
2117,
342,
199,
199,
318,
664,
63,
16340,
63,
2019,
63,
5352,
837,
272,
11168,
275,
2197,
14,
602,
14,
8136,
342,
272,
367,
366,
315,
7543,
14,
1462,
14,
1541,
8,
49,
8,
4981,
363,
466,
628,
7185,
13,
1500,
71,
401,
6363,
363,
5464,
628,
10181,
531,
2511,
1204,
1413,
8,
4981,
363,
466,
628,
270,
693,
71,
401,
6363,
363,
5464,
628,
262,
13,
10181,
14150,
267,
325,
275,
366,
14,
7410,
63,
1430,
8,
6090,
2176,
3768,
2390,
12,
730,
628,
1150,
63,
2019,
63,
1250,
531,
267,
340,
325,
436,
325,
14,
12342,
14,
602,
342,
2695,
11168,
26,
288,
1995,
366,
199,
199,
318,
16667,
63,
2019,
63,
1250,
8,
1301,
304,
272,
340,
1382,
14,
466,
63,
344,
508,
283,
7185,
356,
267,
892,
63,
929,
275,
8511,
14,
1462,
14,
362,
8,
2972,
29,
549,
12,
730,
628,
7185,
13,
1500,
71,
401,
8889,
628,
952,
384,
87,
531,
267,
325,
275,
1382,
14,
7410,
63,
1430,
8,
3534,
384,
3768,
2390,
12,
730,
628,
2489,
63,
4982,
1653,
63,
952,
384,
63,
505,
531,
267,
340,
325,
436,
298,
497,
9723,
1564,
883,
28914,
590,
506,
1911,
315,
314,
9006,
2,
440,
315,
325,
14,
505,
26,
288,
327,
340,
1234,
3566,
13,
17673,
1318,
965,
2757,
4829,
12,
781,
5534,
314,
288,
327,
2218,
13,
384,
965,
2757,
5313,
288,
892,
63,
929,
275,
8511,
14,
1462,
14,
362,
8,
2972,
29,
549,
12,
730,
628,
7185,
13,
1500,
71,
401,
8889,
628,
1939,
10938,
87,
531,
272,
916,
1382,
14,
466,
63,
344,
508,
283,
270,
693,
71,
356,
267,
892,
63,
929,
275,
8511,
14,
1462,
14,
362,
8,
2972,
29,
549,
12,
730,
628,
270,
693,
71,
401,
8889,
628,
1939,
10938,
531,
272,
587,
26,
267,
746,
1722,
480,
8708,
2213,
730,
370,
16667,
63,
2019,
63,
1250,
837,
450,
83,
2,
450,
1382,
14,
466,
9,
339,
3354,
63,
3554,
63,
262,
63,
5570,
8,
1301,
9,
339,
5071,
63,
929,
275,
1382,
14,
362,
63,
929,
8,
1222,
63,
929,
14,
466,
63,
344,
9,
272,
1382,
14,
409,
63,
929,
8,
1222,
63,
929,
9,
339,
5071,
63,
2969,
275,
1382,
14,
2969,
14,
1541,
8,
5464,
363,
262,
29,
2563,
39,
63,
6348,
6689,
63,
17626,
9,
272,
1382,
14,
2969,
14,
2168,
2031,
5701,
63,
2969,
9,
339,
2656,
275,
8028,
14,
1462,
14,
362,
8,
354,
628,
8,
3989,
6320,
272,
325,
275,
1050,
63,
929,
63,
1461,
63,
1430,
8,
1301,
12,
2656,
12,
5071,
63,
929,
12,
892,
63,
929,
12,
5071,
63,
2969,
29,
5701,
63,
2969,
12,
892,
63,
2969,
14285,
2151,
272,
1382,
14,
521,
275,
334,
69,
436,
325,
14,
521,
9,
503,
2197,
14,
2083,
14,
2131,
342,
272,
1382,
14,
2117,
342,
339,
3031,
63,
2019,
63,
1250,
63,
16340,
8,
1301,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pizcogirl/Astron
|
test/test_messagedirector.py
|
4
|
21866
|
#!/usr/bin/env python2
import unittest
from socket import *
from common.unittests import ProtocolTest
from common.astron import *
CONFIG = """\
messagedirector:
bind: 127.0.0.1:57123
connect: 127.0.0.1:57124
"""
class TestMessageDirector(ProtocolTest):
@classmethod
def setUpClass(cls):
listener = socket(AF_INET, SOCK_STREAM)
listener.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
listener.bind(('127.0.0.1', 57124))
listener.listen(1)
listener.settimeout(0.3)
cls.daemon = Daemon(CONFIG)
cls.daemon.start()
l, _ = listener.accept()
listener.close()
cls.l1 = MDConnection(l)
cls.c1 = cls.connectToServer()
cls.c2 = cls.connectToServer()
@classmethod
def tearDownClass(cls):
cls.l1.close()
cls.c1.close()
cls.c2.close()
cls.daemon.stop()
def test_single(self):
self.l1.flush()
# Send a datagram...
dg = Datagram.create([1234], 4321, 1337)
dg.add_string('HELLO')
self.c1.send(dg)
# Make sure the MD passes it upward.
self.expect(self.l1, dg)
def test_subscribe(self):
self.l1.flush()
self.c1.flush()
self.c2.flush()
# Subscribe to a channel...
dg = Datagram.create_add_channel(12345654321)
self.c1.send(dg)
self.expectNone(self.c1)
# Make sure the MD subscribes to its parent.
self.expect(self.l1, dg)
# Send a test datagram on second connection...
dg = Datagram()
dg = Datagram.create([12345654321], 0, 1234)
dg.add_uint32(0xDEADBEEF)
self.c2.send(dg)
self.expect(self.c1, dg)
# MD will, of course, relay this datagram upward.
self.expect(self.l1, dg)
# Subscribe on the second connection...
dg = Datagram.create_add_channel(12345654321)
self.c2.send(dg)
self.expectNone(self.c2)
# MD should not ask for the channel a second time.
self.expectNone(self.l1)
# Send a test datagram on first connection...
dg = Datagram.create([12345654321], 0, 1234)
dg.add_uint32(0xDEADBEEF)
self.c1.send(dg)
self.expect(self.c2, dg) # Should be relayed to second.
self.expect(self.l1, dg) # Should be sent upward.
#self.expectNone(self.c1) # Should NOT be echoed back.
# Unsubscribe on the first connection...
dg = Datagram.create_remove_channel(12345654321)
self.c1.send(dg)
self.expectNone(self.c1)
self.expectNone(self.c2)
# MD should NOT unsubscribe from parent!
self.expectNone(self.l1)
# Send another test datagram on second connection...
dg = Datagram.create([12345654321], 0, 1234)
dg.add_uint32(0xDEADBEEF)
self.c2.send(dg)
self.expect(self.l1, dg) # Should be sent upward.
self.expectNone(self.c2) # Should NOT be relayed.
self.expectNone(self.c1) # Should NOT be echoed back.
# Abandon the second connection, which should auto-unsubscribe it.
self.c2.close()
self.__class__.c2 = self.connectToServer()
self.expectNone(self.c1)
# MD should unsubscribe from parent.
self.expect(self.l1, Datagram.create_remove_channel(12345654321))
def test_multi(self):
self.l1.flush()
self.c1.flush()
self.c2.flush()
# Subscribe to a pair of channels on c1.
for channel in [1111, 2222]:
dg = Datagram.create_add_channel(channel)
self.c1.send(dg)
# Subscribe to another pair of channels on c2.
for channel in [2222, 3333]:
dg = Datagram.create_add_channel(channel)
self.c2.send(dg)
self.l1.flush() # Don't care about the subscribe messages.
# Sanity check: A datagram on channel 2222 should be delivered to both.
dg = Datagram.create([2222], 0, 1234)
dg.add_uint32(0xDEADBEEF)
self.l1.send(dg)
self.expect(self.c1, dg)
self.expect(self.c2, dg)
# A datagram to channels 1111 and 3333 should be delievered to both.
dg = Datagram.create([1111, 3333], 0, 1234)
dg.add_uint32(0xDEADBEEF)
self.l1.send(dg)
self.expect(self.c1, dg)
self.expect(self.c2, dg)
# A datagram should only be delivered once if multiple channels match.
dg = Datagram.create([1111, 2222], 0, 1234)
dg.add_uint32(0xDEADBEEF)
self.l1.send(dg)
self.expect(self.c1, dg)
self.expectNone(self.c1)
self.expect(self.c2, dg)
# Let's try something really absurd:
dg = Datagram.create([1111, 2222, 3333, 1111, 1111,
2222, 3333, 3333, 2222], 0, 1234)
dg.add_uint32(0xDEADBEEF)
self.l1.send(dg)
self.expect(self.c1, dg)
self.expectNone(self.c1)
self.expect(self.c2, dg)
self.expectNone(self.c2)
# And, of course, sending this monstrosity on c1 should result in it
# showing up on c2 and l1 once only; no echo back on c1.
self.c1.send(dg)
self.expect(self.l1, dg)
self.expectNone(self.l1)
self.expect(self.c2, dg)
self.expectNone(self.c2)
self.expectNone(self.c1)
# Unsubscribe the channels...
for channel in [1111, 2222, 3333]:
dg = Datagram.create_remove_channel(channel)
self.c1.send(dg)
self.c2.send(dg)
def test_post_remove(self):
self.l1.flush()
self.c1.flush()
self.c2.flush()
# Create a datagram to be sent post-remove...
dg_pr = Datagram.create([555444333], 0, 4321)
dg_pr.add_string('Testing...')
# Hang it on c1...
dg_add_pr = Datagram.create_add_post_remove(171717, dg_pr)
self.c1.send(dg_add_pr)
# Expect post remove to be pre-routed upstream
self.expect(self.l1, dg_add_pr)
# Verify nothing else is happening yet...
self.expectNone(self.l1)
self.expectNone(self.c1)
self.expectNone(self.c2)
# Reconnect c1 and see if dg gets sent.
self.c1.close()
self.__class__.c1 = self.connectToServer()
# The upstream should receive the post remove and also receive a clear_post_removes
dg_clear_prs = Datagram.create_clear_post_removes(171717)
self.expectMany(self.l1, [dg_pr, dg_clear_prs])
# Reconnect c1, the message shouldn't be sent again
self.c1.close()
self.__class__.c1 = self.connectToServer()
self.expectNone(self.l1)
# Hang dg as a post-remove for c2...
dg_add_pr = Datagram.create_add_post_remove(181818, dg_pr)
self.c2.send(dg_add_pr)
self.expect(self.l1, dg_add_pr)
# Wait, nevermind...
dg_clear_prs = Datagram.create_clear_post_removes(181818)
self.c2.send(dg_clear_prs)
self.expect(self.l1, dg_clear_prs)
# Did the cancellation work?
self.c2.close()
self.__class__.c2 = self.connectToServer()
self.expectNone(self.l1)
# Try hanging multiple post-removes on c1
dg_add_pr = Datagram.create_add_post_remove(191919, dg_pr)
dg_pr2 = Datagram.create([987987987], 0, 6959)
dg_add_pr2 = Datagram.create_add_post_remove(191919, dg_pr2)
dg_pr3 = Datagram.create([986666687], 0, 1252)
dg_add_pr3 = Datagram.create_add_post_remove(202020, dg_pr3)
self.c1.send(dg_add_pr)
self.c1.send(dg_add_pr2)
self.c1.send(dg_add_pr3)
# Expect post removes to be pre-routed upstream
self.expectMany(self.l1, [dg_add_pr, dg_add_pr2, dg_add_pr3])
# After adding three, we don't want to see anything "pushed" or the like
self.expectNone(self.l1)
self.expectNone(self.c1)
self.expectNone(self.c2)
# Reconnect c1 and see if both datagrams gets sent ...
self.c1.close()
self.__class__.c1 = self.connectToServer()
# ... expecting the post removes ...
expected = [dg_pr, dg_pr2, dg_pr3]
# ... and a clear for each channel ...
dg_clear_prs = Datagram.create_clear_post_removes(191919)
dg_clear_prs2 = Datagram.create_clear_post_removes(202020)
expected += [dg_clear_prs, dg_clear_prs2]
# ... exactly 2 Post Removes, and 3 Clears ...
self.expectMany(self.l1, expected)
# ... and no more messages (duplicates or otherwise)
self.expectNone(self.l1)
def test_ranges(self):
self.l1.flush()
self.c1.flush()
self.c2.flush()
# Subscribe to range 1000-1999...
dg = Datagram.create_add_range(1000, 1999)
self.c1.send(dg)
# Verify that l1 asks for the range as well...
self.expect(self.l1, dg)
# Send messages on a few channels on c2, see which ones c1 gets.
def check_channels(channels):
for channel, should_receive in channels:
dg = Datagram.create([channel], 123456789, 5858)
dg.add_uint16(channel) # For some semblance of uniqueness
self.c2.send(dg)
if should_receive:
self.expect(self.c1, dg)
self.expectNone(self.c1) # No repeats!
else:
self.expectNone(self.c1)
# And, of course, l1 receives all of these:
self.expect(self.l1, dg)
check_channels([
(500, False),
(999, False),
(1000, True),
(1001, True),
(1299, True),
(1300, True),
(1500, True),
(1699, True),
(1700, True),
(1701, True),
(1900, True),
(1999, True),
(2000, False),
(2050, False),
(2500, False)])
# Ranged-subscriptions should still receive messages only once, even if
# multiple channels are in the range.
dg = Datagram.create([500, 1001, 1500], 0, 34)
dg.add_string('test')
self.c2.send(dg)
self.expect(self.c1, dg)
self.expectNone(self.c1) # No repeats!
self.expect(self.l1, dg)
# Now let's "slice" the range.
dg = Datagram.create_remove_range(1300, 1700)
self.c1.send(dg)
# l1 should request the slice upward
self.expect(self.l1, dg)
# And the slice should be gone:
check_channels([
(500, False),
(999, False),
(1000, True),
(1001, True),
(1299, True),
(1300, False),
(1500, False),
(1699, False),
(1700, False),
(1701, True),
(1900, True),
(1999, True),
(2000, False),
(2050, False),
(2500, False)])
# How about adding a second range that overlaps?
dg = Datagram.create_add_range(1900, 2100)
self.c1.send(dg)
# Verify that md asks for the entire range from l1...
self.expect(self.l1, dg)
# Now the subscriptions should be updated:
check_channels([
(500, False),
(999, False),
(1000, True),
(1001, True),
(1299, True),
(1300, False),
(1500, False),
(1699, False),
(1700, False),
(1701, True),
(1900, True),
(1999, True),
(2000, True),
(2050, True),
(2500, False)])
# Drop that first range...
dg = Datagram.create_remove_range(1000, 1999)
self.c1.send(dg)
# -- See comments after block --
## And again, l1 should ask for difference only...
#expected = []
## Difference #1: Drop 1000-1299
#expected.append(Datagram.create_remove_range(1000, 1299))
## Difference #2: Drop 1701-1999
#expected.append(Datagram.create_remove_range(1701, 1999))
#self.expectMany(self.l1, expected)
# In this case because there are no remaining subscriptions in the
# entire removed range, it is more efficient for the network, CPU,
# and memory to just forward the entire range.
dg = Datagram.create_remove_range(1000, 1999)
self.expect(self.l1, dg)
# Now see if only the second range is active...
check_channels([
(500, False),
(999, False),
(1000, False),
(1001, False),
(1999, False),
(2000, True),
(2050, True),
(2500, False)])
# Grand finale: Cut c1 and see if the remaining range dies.
self.c1.close()
self.c1 = self.connectToServer()
self.expect(self.l1, Datagram.create_remove_range(2000, 2100))
self.expectNone(self.l1)
# ... but we lied! Now there are some more tests
# Lets add a new range to play with
dg = Datagram.create_add_range(3000, 5000)
self.c1.send(dg)
self.expect(self.l1, dg)
check_channels([
(2499, False),
(2501, False),
(2999, False),
(3000, True),
(4000, True),
(4372, True),
(5000, True),
(5001, False),
(5109, False)])
# Test removing a range that intersects with the front part
dg = Datagram.create_remove_range(2950, 3043)
self.c1.send(dg)
# --> and expect only the subscribed part to be removed
dg = Datagram.create_remove_range(3000, 3043)
self.expect(self.l1, dg)
check_channels([
(2913, False),
(2999, False),
(3000, False),
(3043, False),
(3044, True),
(4000, True),
(4372, True),
(5000, True),
(5001, False),
(5109, False)])
# Test removing a range that intersects with the end part
dg = Datagram.create_remove_range(4763, 6000)
self.c1.send(dg)
# --> and expect only the subscribed part to be removed
dg = Datagram.create_remove_range(4763, 5000)
self.expect(self.l1, dg)
check_channels([
(3000, False),
(3043, False),
(3044, True),
(4000, True),
(4372, True),
(4762, True),
(4763, False),
(5000, False),
(5001, False),
(5109, False)])
# Now remove some from the middle again so we can test weird intersections
dg = Datagram.create_remove_range(3951, 4049)
self.c1.send(dg)
# The entire range is subscribed, so it should all be unsubscribed
self.expect(self.l1, dg)
check_channels([
(3043, False),
(3044, True),
(3802, True),
(3950, True),
(3951, False),
(4049, False),
(4050, True),
(4133, True),
(4762, True),
(4763, False)])
# Ok... remove an intersection from the lower half of the upper range
dg = Datagram.create_remove_range(4030, 4070)
self.c1.send(dg)
# N.B. Its worth considering which of the following behaviors is preferred,
# the first is a lot more work for the current MD, but may reduce the
# work for other MDs. Consider performance testing both implementations.
## --> and expect only the subscribed part to be removed
#self.expect(self.l1, Datagram.create_remove_range(4050, 4070))
self.expect(self.l1, dg)
check_channels([
(3043, False),
(3044, True),
(3802, True),
(3950, True),
(3951, False),
(4070, False),
(4071, True),
(4133, True),
(4762, True),
(4763, False)])
# Now remove an intersection from the upper half of the lower range
dg = Datagram.create_remove_range(3891, 4040)
self.c1.send(dg)
# N.B. Its worth considering which of the following behaviors is preferred,
# the first is a lot more work for the current MD, but may reduce the
# work for other MDs. Consider performance testing both implementations.
## --> and expect only the subscribed part to be removed
#self.expect(self.l1, Datagram.create_remove_range(3891, 3950))
self.expect(self.l1, dg)
check_channels([
(3043, False),
(3044, True),
(3672, True),
(3890, True),
(3891, False),
(3893, False),
(4070, False),
(4071, True),
(4762, True),
(4763, False)])
# Now lets intersect part of both the upper and lower range
dg = Datagram.create_remove_range(3700, 4200)
self.c1.send(dg)
# N.B. Its worth considering which of the following behaviors is preferred,
# the first is a lot more work for the current MD, but may reduce the
# work for other MDs. Consider performance testing both implementations.
# Additionally the first requires twice as much network traffice, but
# it is still relatively small on a relatively infrequent operation.
## --> and expect only the subscribed parts to be removed
#expected = []
#expected.append(Datagram.create_remove_range(3700, 3890))
#expected.append(Datagram.create_remove_range(4070, 4200))
#self.expectMany(self.l1, expected)
self.expect(self.l1, dg)
check_channels([
(3043, False),
(3044, True),
(3699, True),
(3700, False),
(4200, False),
(4201, True),
(4762, True),
(4763, False)])
# Now lets subscribe our 2nd client to an intersecting range
dg = Datagram.create_add_range(3500, 4500)
self.c2.send(dg)
self.expect(self.l1, dg)
# Now remove an upper part of the lower range that is contained within c2's range
dg = Datagram.create_remove_range(3650, 3800)
self.c1.send(dg)
# We shouldn't get a remove for this upstream, because the 2nd client is still interested
self.expectNone(self.l1)
check_channels([
# Lower range
(3043, False),
(3044, True), # lower bound
(3333, True),
(3480, True),
(3499, True),
(3500, True),
(3649, True), # upper bound
(3650, False),
(3787, False),
(4000, False),
# Upper range
(4200, False),
(4201, True)]) # lower bound
# Now remove part of the lower range that contains just the lower bound of c2's range,
# but not the upper bound of the lower range.
dg = Datagram.create_remove_range(3475, 3525)
self.c1.send(dg)
# We should expect to receive only the portion of the range which is outside c2's range
self.expect(self.l1, Datagram.create_remove_range(3475, 3499))
check_channels([
# Lower range
(3043, False),
(3044, True), # lower bound
(3474, True), # upper bound
(3475, False),
(3482, False),
(3499, False),
# Mid range
(3525, False),
(3526, True), # Lower bound
(3600, True),
(3649, True), # upper bound
(3650, False),
# Upper range
(4200, False),
(4201, True)]) # lower bound
# Now remove a range from c2 which contains the mid-range's upper bound
# and the upper-range's lower bound.
dg = Datagram.create_remove_range(3620, 4300)
self.c2.send(dg)
# We should expect to recieve only the portion of c2 which is between the two ranges
self.expect(self.l1, Datagram.create_remove_range(3650, 4200))
check_channels([
# Lower range
(3474, True), # upper bound
(3475, False),
# Mid range
(3525, False),
(3526, True), # Lower bound
(3649, True), # upper bound
(3650, False),
# Upper range
(4200, False),
(4201, True), # lower bound
(4762, True), # upper bound
(4763, False)])
# Cut c2 and watch the part die that is not in c1
self.c2.close()
self.c2 = self.connectToServer()
self.expect(self.l1, Datagram.create_remove_range(3500, 3525))
self.expectNone(self.l1)
# Now add c2 such that it contains all the c1 ranges
dg = Datagram.create_add_range(1000, 5000)
self.c2.send(dg)
self.expect(self.l1, dg)
# Then remove that range and see all the inbetween parts die
self.c2.send(Datagram.create_remove_range(1000, 5000))
expected = []
expected.append(Datagram.create_remove_range(1000, 3043))
expected.append(Datagram.create_remove_range(3475, 3525))
expected.append(Datagram.create_remove_range(3650, 4200))
expected.append(Datagram.create_remove_range(4763, 5000))
self.expectMany(self.l1, expected)
self.expectNone(self.l1)
# Cleanup
self.c1.close()
self.c2.close()
self.__class__.c1 = self.connectToServer()
self.__class__.c2 = self.connectToServer()
self.l1.flush()
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
646,
2882,
199,
504,
2838,
492,
627,
199,
199,
504,
2863,
14,
31053,
492,
11557,
774,
199,
504,
2863,
14,
65,
495,
265,
492,
627,
199,
199,
5569,
275,
9638,
199,
1188,
24712,
26,
272,
5398,
26,
12792,
14,
16,
14,
16,
14,
17,
26,
1641,
4288,
272,
4907,
26,
12792,
14,
16,
14,
16,
14,
17,
26,
1641,
7214,
199,
624,
199,
199,
533,
1379,
2209,
28704,
8,
3658,
774,
304,
272,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
11647,
275,
2838,
8,
5699,
63,
11367,
12,
26327,
63,
9484,
9,
267,
11647,
14,
27689,
8,
15096,
63,
17462,
12,
3562,
63,
907,
4701,
7803,
12,
413,
9,
267,
11647,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
12699,
7214,
430,
267,
11647,
14,
5859,
8,
17,
9,
267,
11647,
14,
24630,
8,
16,
14,
19,
9,
398,
843,
14,
10824,
275,
577,
8770,
8,
5569,
9,
267,
843,
14,
10824,
14,
928,
342,
398,
634,
12,
485,
275,
11647,
14,
5694,
342,
267,
11647,
14,
1600,
342,
267,
843,
14,
76,
17,
275,
15830,
3225,
8,
76,
9,
398,
843,
14,
67,
17,
275,
843,
14,
2242,
1378,
3120,
342,
267,
843,
14,
67,
18,
275,
843,
14,
2242,
1378,
3120,
342,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
843,
14,
76,
17,
14,
1600,
342,
267,
843,
14,
67,
17,
14,
1600,
342,
267,
843,
14,
67,
18,
14,
1600,
342,
267,
843,
14,
10824,
14,
2379,
342,
339,
347,
511,
63,
4780,
8,
277,
304,
267,
291,
14,
76,
17,
14,
4939,
342,
398,
327,
10217,
282,
666,
1679,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
779,
4321,
467,
841,
12638,
12,
413,
11062,
9,
267,
366,
71,
14,
525,
63,
875,
360,
24771,
1484,
358,
267,
291,
14,
67,
17,
14,
2254,
8,
13279,
9,
398,
327,
4155,
3238,
314,
15830,
14933,
652,
1536,
3079,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
339,
347,
511,
63,
10108,
8,
277,
304,
267,
291,
14,
76,
17,
14,
4939,
342,
267,
291,
14,
67,
17,
14,
4939,
342,
267,
291,
14,
67,
18,
14,
4939,
342,
398,
327,
4804,
5355,
370,
282,
3623,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
63,
525,
63,
2775,
8,
19060,
1477,
12638,
9,
267,
291,
14,
67,
17,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
267,
327,
4155,
3238,
314,
15830,
1007,
729,
11562,
370,
2399,
1676,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
398,
327,
10217,
282,
511,
666,
1679,
641,
3499,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
342,
267,
366,
71,
275,
3918,
1679,
14,
981,
779,
19060,
1477,
12638,
467,
378,
12,
14763,
9,
267,
366,
71,
14,
525,
63,
1635,
708,
8,
16,
88,
29031,
6773,
14153,
9,
267,
291,
14,
67,
18,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
8,
277,
14,
67,
17,
12,
366,
71,
9,
267,
327,
15830,
911,
12,
402,
2518,
12,
25931,
642,
666,
1679,
1536,
3079,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
398,
327,
4804,
5355,
641,
314,
3499,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
63,
525,
63,
2775,
8,
19060,
1477,
12638,
9,
267,
291,
14,
67,
18,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
18,
9,
267,
327,
15830,
1077,
440,
7198,
367,
314,
3623,
282,
3499,
900,
14,
267,
291,
14,
4921,
403,
8,
277,
14,
76,
17,
9,
398,
327,
10217,
282,
511,
666,
1679,
641,
1642,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
779,
19060,
1477,
12638,
467,
378,
12,
14763,
9,
267,
366,
71,
14,
525,
63,
1635,
708,
8,
16,
88,
29031,
6773,
14153,
9,
267,
291,
14,
67,
17,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
8,
277,
14,
67,
18,
12,
366,
71,
9,
327,
7719,
506,
25931,
379,
370,
3499,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
327,
7719,
506,
4847,
1536,
3079,
14,
267,
327,
277,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
327,
7719,
2845,
506,
11343,
379,
1771,
14,
398,
327,
15254,
456,
5355,
641,
314,
1642,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
63,
2168,
63,
2775,
8,
19060,
1477,
12638,
9,
267,
291,
14,
67,
17,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
18,
9,
267,
327,
15830,
1077,
2845,
625,
10108,
687,
1676,
1,
267,
291,
14,
4921,
403,
8,
277,
14,
76,
17,
9,
398,
327,
10217,
4573,
511,
666,
1679,
641,
3499,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
779,
19060,
1477,
12638,
467,
378,
12,
14763,
9,
267,
366,
71,
14,
525,
63,
1635,
708,
8,
16,
88,
29031,
6773,
14153,
9,
267,
291,
14,
67,
18,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
327,
7719,
506,
4847,
1536,
3079,
14,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
18,
9,
327,
7719,
2845,
506,
25931,
379,
14,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
327,
7719,
2845,
506,
11343,
379,
1771,
14,
398,
327,
437,
7877,
265,
314,
3499,
1950,
12,
1314,
1077,
2599,
13,
25592,
652,
14,
267,
291,
14,
67,
18,
14,
1600,
342,
267,
291,
855,
533,
4343,
67,
18,
275,
291,
14,
2242,
1378,
3120,
342,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
267,
327,
15830,
1077,
625,
10108,
687,
1676,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
3918,
1679,
14,
981,
63,
2168,
63,
2775,
8,
19060,
1477,
12638,
430,
339,
347,
511,
63,
3029,
8,
277,
304,
267,
291,
14,
76,
17,
14,
4939,
342,
267,
291,
14,
67
] |
[
2647,
15,
1393,
15,
1813,
2366,
18,
199,
646,
2882,
199,
504,
2838,
492,
627,
199,
199,
504,
2863,
14,
31053,
492,
11557,
774,
199,
504,
2863,
14,
65,
495,
265,
492,
627,
199,
199,
5569,
275,
9638,
199,
1188,
24712,
26,
272,
5398,
26,
12792,
14,
16,
14,
16,
14,
17,
26,
1641,
4288,
272,
4907,
26,
12792,
14,
16,
14,
16,
14,
17,
26,
1641,
7214,
199,
624,
199,
199,
533,
1379,
2209,
28704,
8,
3658,
774,
304,
272,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
11647,
275,
2838,
8,
5699,
63,
11367,
12,
26327,
63,
9484,
9,
267,
11647,
14,
27689,
8,
15096,
63,
17462,
12,
3562,
63,
907,
4701,
7803,
12,
413,
9,
267,
11647,
14,
3409,
4725,
4195,
14,
16,
14,
16,
14,
17,
297,
12699,
7214,
430,
267,
11647,
14,
5859,
8,
17,
9,
267,
11647,
14,
24630,
8,
16,
14,
19,
9,
398,
843,
14,
10824,
275,
577,
8770,
8,
5569,
9,
267,
843,
14,
10824,
14,
928,
342,
398,
634,
12,
485,
275,
11647,
14,
5694,
342,
267,
11647,
14,
1600,
342,
267,
843,
14,
76,
17,
275,
15830,
3225,
8,
76,
9,
398,
843,
14,
67,
17,
275,
843,
14,
2242,
1378,
3120,
342,
267,
843,
14,
67,
18,
275,
843,
14,
2242,
1378,
3120,
342,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
843,
14,
76,
17,
14,
1600,
342,
267,
843,
14,
67,
17,
14,
1600,
342,
267,
843,
14,
67,
18,
14,
1600,
342,
267,
843,
14,
10824,
14,
2379,
342,
339,
347,
511,
63,
4780,
8,
277,
304,
267,
291,
14,
76,
17,
14,
4939,
342,
398,
327,
10217,
282,
666,
1679,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
779,
4321,
467,
841,
12638,
12,
413,
11062,
9,
267,
366,
71,
14,
525,
63,
875,
360,
24771,
1484,
358,
267,
291,
14,
67,
17,
14,
2254,
8,
13279,
9,
398,
327,
4155,
3238,
314,
15830,
14933,
652,
1536,
3079,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
339,
347,
511,
63,
10108,
8,
277,
304,
267,
291,
14,
76,
17,
14,
4939,
342,
267,
291,
14,
67,
17,
14,
4939,
342,
267,
291,
14,
67,
18,
14,
4939,
342,
398,
327,
4804,
5355,
370,
282,
3623,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
63,
525,
63,
2775,
8,
19060,
1477,
12638,
9,
267,
291,
14,
67,
17,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
267,
327,
4155,
3238,
314,
15830,
1007,
729,
11562,
370,
2399,
1676,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
398,
327,
10217,
282,
511,
666,
1679,
641,
3499,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
342,
267,
366,
71,
275,
3918,
1679,
14,
981,
779,
19060,
1477,
12638,
467,
378,
12,
14763,
9,
267,
366,
71,
14,
525,
63,
1635,
708,
8,
16,
88,
29031,
6773,
14153,
9,
267,
291,
14,
67,
18,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
8,
277,
14,
67,
17,
12,
366,
71,
9,
267,
327,
15830,
911,
12,
402,
2518,
12,
25931,
642,
666,
1679,
1536,
3079,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
398,
327,
4804,
5355,
641,
314,
3499,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
63,
525,
63,
2775,
8,
19060,
1477,
12638,
9,
267,
291,
14,
67,
18,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
18,
9,
267,
327,
15830,
1077,
440,
7198,
367,
314,
3623,
282,
3499,
900,
14,
267,
291,
14,
4921,
403,
8,
277,
14,
76,
17,
9,
398,
327,
10217,
282,
511,
666,
1679,
641,
1642,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
779,
19060,
1477,
12638,
467,
378,
12,
14763,
9,
267,
366,
71,
14,
525,
63,
1635,
708,
8,
16,
88,
29031,
6773,
14153,
9,
267,
291,
14,
67,
17,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
8,
277,
14,
67,
18,
12,
366,
71,
9,
327,
7719,
506,
25931,
379,
370,
3499,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
327,
7719,
506,
4847,
1536,
3079,
14,
267,
327,
277,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
327,
7719,
2845,
506,
11343,
379,
1771,
14,
398,
327,
15254,
456,
5355,
641,
314,
1642,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
63,
2168,
63,
2775,
8,
19060,
1477,
12638,
9,
267,
291,
14,
67,
17,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
18,
9,
267,
327,
15830,
1077,
2845,
625,
10108,
687,
1676,
1,
267,
291,
14,
4921,
403,
8,
277,
14,
76,
17,
9,
398,
327,
10217,
4573,
511,
666,
1679,
641,
3499,
1950,
1396,
267,
366,
71,
275,
3918,
1679,
14,
981,
779,
19060,
1477,
12638,
467,
378,
12,
14763,
9,
267,
366,
71,
14,
525,
63,
1635,
708,
8,
16,
88,
29031,
6773,
14153,
9,
267,
291,
14,
67,
18,
14,
2254,
8,
13279,
9,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
366,
71,
9,
327,
7719,
506,
4847,
1536,
3079,
14,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
18,
9,
327,
7719,
2845,
506,
25931,
379,
14,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
327,
7719,
2845,
506,
11343,
379,
1771,
14,
398,
327,
437,
7877,
265,
314,
3499,
1950,
12,
1314,
1077,
2599,
13,
25592,
652,
14,
267,
291,
14,
67,
18,
14,
1600,
342,
267,
291,
855,
533,
4343,
67,
18,
275,
291,
14,
2242,
1378,
3120,
342,
267,
291,
14,
4921,
403,
8,
277,
14,
67,
17,
9,
267,
327,
15830,
1077,
625,
10108,
687,
1676,
14,
267,
291,
14,
4921,
8,
277,
14,
76,
17,
12,
3918,
1679,
14,
981,
63,
2168,
63,
2775,
8,
19060,
1477,
12638,
430,
339,
347,
511,
63,
3029,
8,
277,
304,
267,
291,
14,
76,
17,
14,
4939,
342,
267,
291,
14,
67,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mdietrichc2c/OCB
|
openerp/report/render/makohtml2html/makohtml2html.py
|
443
|
4762
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
import mako
from lxml import etree
from mako.template import Template
from mako.lookup import TemplateLookup
import os
_logger = logging.getLogger(__name__)
class makohtml2html(object):
def __init__(self, html, localcontext):
self.localcontext = localcontext
self.html = html
def format_header(self, html):
head = html.findall('head')
header = ''
for node in head:
header += etree.tostring(node)
return header
def format_footer(self, footer):
html_footer = ''
for node in footer[0].getchildren():
html_footer += etree.tostring(node)
return html_footer
def format_body(self, html):
body = html.findall('body')
body_list = []
footer = self.format_footer(body[-1].getchildren())
for b in body[:-1]:
body_list.append(etree.tostring(b).replace('\t', '').replace('\n',''))
html_body ='''
<script type="text/javascript">
var indexer = 0;
var aryTest = %s ;
function nextData()
{
if(indexer < aryTest.length -1)
{
indexer += 1;
document.forms[0].prev.disabled = false;
document.getElementById("openerp_data").innerHTML=aryTest[indexer];
document.getElementById("counter").innerHTML= indexer + 1 + ' / ' + aryTest.length;
}
else
{
document.forms[0].next.disabled = true;
}
}
function prevData()
{
if (indexer > 0)
{
indexer -= 1;
document.forms[0].next.disabled = false;
document.getElementById("openerp_data").innerHTML=aryTest[indexer];
document.getElementById("counter").innerHTML= indexer + 1 + ' / ' + aryTest.length;
}
else
{
document.forms[0].prev.disabled = true;
}
}
</script>
</head>
<body>
<div id="openerp_data">
%s
</div>
<div>
%s
</div>
<br>
<form>
<table>
<tr>
<td td align="left">
<input name = "prev" type="button" value="Previous" onclick="prevData();">
</td>
<td>
<div id = "counter">%s / %s</div>
</td>
<td align="right">
<input name = "next" type="button" value="Next" onclick="nextData();">
</td>
</tr>
</table>
</form>
</body></html>'''%(body_list,body_list[0],footer,'1',len(body_list))
return html_body
def render(self):
path = os.path.realpath('addons/base/report')
temp_lookup = TemplateLookup(directories=[path],output_encoding='utf-8', encoding_errors='replace')
template = Template(self.html, lookup=temp_lookup)
self.localcontext.update({'css_path':path})
final_html ='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>'''
try:
html = template.render_unicode(**self.localcontext)
etree_obj = etree.HTML(html)
final_html += self.format_header(etree_obj)
final_html += self.format_body(etree_obj)
return final_html
except Exception:
_logger.exception('report :')
def parseNode(html, localcontext = {}):
r = makohtml2html(html, localcontext)
return r.render()
# 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,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
2050,
199,
646,
26834,
199,
504,
14490,
492,
7559,
199,
504,
26834,
14,
1160,
492,
5458,
199,
504,
26834,
14,
3892,
492,
5458,
7521,
199,
646,
747,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
26834,
1360,
18,
1360,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3517,
12,
2257,
1100,
304,
267,
291,
14,
17886,
275,
2257,
1100,
267,
291,
14,
1360,
275,
3517,
339,
347,
1475,
63,
1291,
8,
277,
12,
3517,
304,
267,
4854,
275,
3517,
14,
6452,
360,
2993,
358,
267,
1406,
275,
2125,
267,
367,
1031,
315,
4854,
26,
288,
1406,
847,
7559,
14,
14028,
8,
932,
9,
267,
372,
1406,
339,
347,
1475,
63,
12781,
8,
277,
12,
14178,
304,
267,
3517,
63,
12781,
275,
2125,
267,
367,
1031,
315,
14178,
59,
16,
1055,
362,
3223,
837,
288,
3517,
63,
12781,
847,
7559,
14,
14028,
8,
932,
9,
267,
372,
3517,
63,
12781,
339,
347,
1475,
63,
2030,
8,
277,
12,
3517,
304,
267,
2396,
275,
3517,
14,
6452,
360,
2030,
358,
267,
2396,
63,
513,
275,
942,
267,
14178,
275,
221,
291,
14,
908,
63,
12781,
8,
2030,
1988,
17,
1055,
362,
3223,
1012,
267,
367,
330,
315,
2396,
4439,
17,
2189,
288,
2396,
63,
513,
14,
740,
8,
9464,
14,
14028,
8,
66,
680,
1814,
2258,
84,
297,
12548,
1814,
2258,
78,
1673,
1333,
267,
3517,
63,
2030,
275,
2344,
267,
665,
1579,
730,
628,
505,
15,
9554,
1743,
398,
2729,
23093,
275,
378,
27,
267,
2729,
601,
89,
774,
275,
450,
83,
8700,
267,
805,
2163,
1451,
342,
288,
469,
288,
340,
8,
15615,
665,
601,
89,
774,
14,
1267,
446,
17,
9,
355,
469,
355,
23093,
847,
413,
27,
355,
2213,
14,
3351,
59,
16,
1055,
5701,
14,
7011,
275,
3055,
27,
355,
2213,
14,
26215,
480,
11267,
63,
576,
3471,
26502,
29,
695,
774,
59,
15615,
11566,
355,
2213,
14,
26215,
480,
5337,
3471,
26502,
29,
23093,
435,
413,
435,
283,
1182,
283,
435,
601,
89,
774,
14,
1267,
27,
355,
789,
288,
587,
2049,
469,
355,
2213,
14,
3351,
59,
16,
1055,
2184,
14,
7011,
275,
2549,
27,
2049,
789,
288,
789,
267,
805,
5071,
1451,
342,
288,
469,
288,
340,
334,
15615,
690,
378,
9,
355,
469,
355,
23093,
4862,
413,
27,
355,
2213,
14,
3351,
59,
16,
1055,
2184,
14,
7011,
275,
3055,
27,
355,
2213,
14,
26215,
480,
11267,
63,
576,
3471,
26502,
29,
695,
774,
59,
15615,
11566,
355,
2213,
14,
26215,
480,
5337,
3471,
26502,
29,
221,
23093,
435,
413,
435,
283,
1182,
283,
435,
601,
89,
774,
14,
1267,
27,
355,
789,
288,
587,
2049,
469,
355,
2213,
14,
3351,
59,
16,
1055,
5701,
14,
7011,
275,
2549,
27,
2049,
789,
288,
789,
272,
3068,
1579,
30,
272,
3068,
2993,
30,
272,
665,
2030,
30,
267,
665,
3015,
1305,
628,
11267,
63,
576,
1743,
288,
450,
83,
267,
3068,
3015,
30,
267,
665,
3015,
30,
267,
450,
83,
267,
3068,
3015,
30,
267,
665,
3289,
30,
267,
665,
964,
30,
288,
665,
1224,
30,
355,
665,
454,
30,
490,
665,
2076,
12749,
6998,
628,
3039,
1743,
717,
665,
1210,
536,
275,
298,
5701,
2,
730,
628,
3887,
2,
574,
628,
18021,
2,
31156,
628,
5701,
1451,
7303,
1743,
490,
3068,
2076,
30,
490,
665,
2076,
30,
717,
665,
3015,
1305,
275,
298,
5337,
14423,
83,
1182,
450,
83,
1108,
3015,
30,
490,
3068,
2076,
30,
490,
665,
2076,
6998,
628,
1019,
1743,
717,
665,
1210,
536,
275,
298,
2184,
2,
730,
628,
3887,
2,
574,
628,
5765,
2,
31156,
628,
2184,
1451,
7303,
1743,
490,
3068,
2076,
30,
355,
3068,
454,
30,
288,
3068,
1224,
30,
267,
3068,
964,
30,
272,
3068,
2030,
2957,
1360,
26934,
2840,
2030,
63,
513,
12,
2030,
63,
513,
59,
16,
467,
12781,
2584,
17,
297,
552,
8,
2030,
63,
513,
430,
267,
372,
3517,
63,
2030,
339,
347,
3795,
8,
277,
304,
267,
931,
275,
747,
14,
515,
14,
11091,
360,
10788,
15,
1095,
15,
3070,
358,
267,
2388,
63,
3892,
275,
5458,
7521,
8,
12629,
1524,
515,
467,
1199,
63,
2991,
534,
1624,
13,
24,
297,
2644,
63,
2550,
534,
1814,
358,
267,
1978,
275,
5458,
8,
277,
14,
1360,
12,
4237,
29,
808,
63,
3892,
9,
267,
291,
14,
17886,
14,
873,
3252,
3919,
63,
515,
356,
515,
1552,
267,
4242,
63,
1360,
275,
2344,
11230,
16556,
4163,
21755,
21486,
55,
19,
35,
501,
21156,
4163,
841,
14,
16,
19894,
1588,
279,
501,
742,
1743,
490,
665,
1360,
26934,
267,
862,
26,
288,
3517,
275,
1978,
14,
3352,
63,
2975,
3682,
277,
14,
17886,
9,
288,
7559,
63,
1113,
275,
7559,
14,
4943,
8,
1360,
9,
288,
4242,
63,
1360,
847,
291,
14,
908,
63,
1291,
8,
9464,
63,
1113,
9,
288,
4242,
63,
1360,
847,
291,
14,
908,
63,
2030,
8,
9464,
63,
1113,
9,
288,
372,
4242,
63
] |
[
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,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
2050,
199,
646,
26834,
199,
504,
14490,
492,
7559,
199,
504,
26834,
14,
1160,
492,
5458,
199,
504,
26834,
14,
3892,
492,
5458,
7521,
199,
646,
747,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
26834,
1360,
18,
1360,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3517,
12,
2257,
1100,
304,
267,
291,
14,
17886,
275,
2257,
1100,
267,
291,
14,
1360,
275,
3517,
339,
347,
1475,
63,
1291,
8,
277,
12,
3517,
304,
267,
4854,
275,
3517,
14,
6452,
360,
2993,
358,
267,
1406,
275,
2125,
267,
367,
1031,
315,
4854,
26,
288,
1406,
847,
7559,
14,
14028,
8,
932,
9,
267,
372,
1406,
339,
347,
1475,
63,
12781,
8,
277,
12,
14178,
304,
267,
3517,
63,
12781,
275,
2125,
267,
367,
1031,
315,
14178,
59,
16,
1055,
362,
3223,
837,
288,
3517,
63,
12781,
847,
7559,
14,
14028,
8,
932,
9,
267,
372,
3517,
63,
12781,
339,
347,
1475,
63,
2030,
8,
277,
12,
3517,
304,
267,
2396,
275,
3517,
14,
6452,
360,
2030,
358,
267,
2396,
63,
513,
275,
942,
267,
14178,
275,
221,
291,
14,
908,
63,
12781,
8,
2030,
1988,
17,
1055,
362,
3223,
1012,
267,
367,
330,
315,
2396,
4439,
17,
2189,
288,
2396,
63,
513,
14,
740,
8,
9464,
14,
14028,
8,
66,
680,
1814,
2258,
84,
297,
12548,
1814,
2258,
78,
1673,
1333,
267,
3517,
63,
2030,
275,
2344,
267,
665,
1579,
730,
628,
505,
15,
9554,
1743,
398,
2729,
23093,
275,
378,
27,
267,
2729,
601,
89,
774,
275,
450,
83,
8700,
267,
805,
2163,
1451,
342,
288,
469,
288,
340,
8,
15615,
665,
601,
89,
774,
14,
1267,
446,
17,
9,
355,
469,
355,
23093,
847,
413,
27,
355,
2213,
14,
3351,
59,
16,
1055,
5701,
14,
7011,
275,
3055,
27,
355,
2213,
14,
26215,
480,
11267,
63,
576,
3471,
26502,
29,
695,
774,
59,
15615,
11566,
355,
2213,
14,
26215,
480,
5337,
3471,
26502,
29,
23093,
435,
413,
435,
283,
1182,
283,
435,
601,
89,
774,
14,
1267,
27,
355,
789,
288,
587,
2049,
469,
355,
2213,
14,
3351,
59,
16,
1055,
2184,
14,
7011,
275,
2549,
27,
2049,
789,
288,
789,
267,
805,
5071,
1451,
342,
288,
469,
288,
340,
334,
15615,
690,
378,
9,
355,
469,
355,
23093,
4862,
413,
27,
355,
2213,
14,
3351,
59,
16,
1055,
2184,
14,
7011,
275,
3055,
27,
355,
2213,
14,
26215,
480,
11267,
63,
576,
3471,
26502,
29,
695,
774,
59,
15615,
11566,
355,
2213,
14,
26215,
480,
5337,
3471,
26502,
29,
221,
23093,
435,
413,
435,
283,
1182,
283,
435,
601,
89,
774,
14,
1267,
27,
355,
789,
288,
587,
2049,
469,
355,
2213,
14,
3351,
59,
16,
1055,
5701,
14,
7011,
275,
2549,
27,
2049,
789,
288,
789,
272,
3068,
1579,
30,
272,
3068,
2993,
30,
272,
665,
2030,
30,
267,
665,
3015,
1305,
628,
11267,
63,
576,
1743,
288,
450,
83,
267,
3068,
3015,
30,
267,
665,
3015,
30,
267,
450,
83,
267,
3068,
3015,
30,
267,
665,
3289,
30,
267,
665,
964,
30,
288,
665,
1224,
30,
355,
665,
454,
30,
490,
665,
2076,
12749,
6998,
628,
3039,
1743,
717,
665,
1210,
536,
275,
298,
5701,
2,
730,
628,
3887,
2,
574,
628,
18021,
2,
31156,
628,
5701,
1451,
7303,
1743,
490,
3068,
2076,
30,
490,
665,
2076,
30,
717,
665,
3015,
1305,
275,
298,
5337,
14423,
83,
1182,
450,
83,
1108,
3015,
30,
490,
3068,
2076,
30,
490,
665,
2076,
6998,
628,
1019,
1743,
717,
665,
1210,
536,
275,
298,
2184,
2,
730,
628,
3887,
2,
574,
628,
5765,
2,
31156,
628,
2184,
1451,
7303,
1743,
490,
3068,
2076,
30,
355,
3068,
454,
30,
288,
3068,
1224,
30,
267,
3068,
964,
30,
272,
3068,
2030,
2957,
1360,
26934,
2840,
2030,
63,
513,
12,
2030,
63,
513,
59,
16,
467,
12781,
2584,
17,
297,
552,
8,
2030,
63,
513,
430,
267,
372,
3517,
63,
2030,
339,
347,
3795,
8,
277,
304,
267,
931,
275,
747,
14,
515,
14,
11091,
360,
10788,
15,
1095,
15,
3070,
358,
267,
2388,
63,
3892,
275,
5458,
7521,
8,
12629,
1524,
515,
467,
1199,
63,
2991,
534,
1624,
13,
24,
297,
2644,
63,
2550,
534,
1814,
358,
267,
1978,
275,
5458,
8,
277,
14,
1360,
12,
4237,
29,
808,
63,
3892,
9,
267,
291,
14,
17886,
14,
873,
3252,
3919,
63,
515,
356,
515,
1552,
267,
4242,
63,
1360,
275,
2344,
11230,
16556,
4163,
21755,
21486,
55,
19,
35,
501,
21156,
4163,
841,
14,
16,
19894,
1588,
279,
501,
742,
1743,
490,
665,
1360,
26934,
267,
862,
26,
288,
3517,
275,
1978,
14,
3352,
63,
2975,
3682,
277,
14,
17886,
9,
288,
7559,
63,
1113,
275,
7559,
14,
4943,
8,
1360,
9,
288,
4242,
63,
1360,
847,
291,
14,
908,
63,
1291,
8,
9464,
63,
1113,
9,
288,
4242,
63,
1360,
847,
291,
14,
908,
63,
2030,
8,
9464,
63,
1113,
9,
288,
372,
4242,
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,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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
] |
MIPS/external-chromium_org
|
tools/site_compare/drivers/win32/mouse.py
|
189
|
6462
|
#!/usr/bin/env python
# Copyright (c) 2011 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.
"""SiteCompare module for simulating mouse input.
This module contains functions that can be used to simulate a user
navigating using a pointing device. This includes mouse movement,
clicking with any button, and dragging.
"""
import time # for sleep
import win32api # for mouse_event
import win32con # Windows constants
import win32gui # for window functions
def ScreenToMouse(pt):
"""Convert a value in screen coordinates to mouse coordinates.
Mouse coordinates are specified as a percentage of screen dimensions,
normalized to 16 bits. 0 represents the far left/top of the screen,
65535 represents the far right/bottom. This function assumes that
the size of the screen is fixed at module load time and does not change
Args:
pt: the point of the coords to convert
Returns:
the converted point
"""
# Initialize the screen dimensions on first execution. Note that this
# function assumes that the screen dimensions do not change during run.
if not ScreenToMouse._SCREEN_DIMENSIONS:
desktop = win32gui.GetClientRect(win32gui.GetDesktopWindow())
ScreenToMouse._SCREEN_DIMENSIONS = (desktop[2], desktop[3])
return ((65535 * pt[0]) / ScreenToMouse._SCREEN_DIMENSIONS[0],
(65535 * pt[1]) / ScreenToMouse._SCREEN_DIMENSIONS[1])
ScreenToMouse._SCREEN_DIMENSIONS = None
def PressButton(down, button='left'):
"""Simulate a mouse button press or release at the current mouse location.
Args:
down: whether the button is pressed or released
button: which button is pressed
Returns:
None
"""
# Put the mouse_event flags in a convenient dictionary by button
flags = {
'left': (win32con.MOUSEEVENTF_LEFTUP, win32con.MOUSEEVENTF_LEFTDOWN),
'middle': (win32con.MOUSEEVENTF_MIDDLEUP, win32con.MOUSEEVENTF_MIDDLEDOWN),
'right': (win32con.MOUSEEVENTF_RIGHTUP, win32con.MOUSEEVENTF_RIGHTDOWN)
}
# hit the button
win32api.mouse_event(flags[button][down], 0, 0)
def ClickButton(button='left', click_time=0):
"""Press and release a mouse button at the current mouse location.
Args:
button: which button to click
click_time: duration between press and release
Returns:
None
"""
PressButton(True, button)
time.sleep(click_time)
PressButton(False, button)
def DoubleClickButton(button='left', click_time=0, time_between_clicks=0):
"""Double-click a mouse button at the current mouse location.
Args:
button: which button to click
click_time: duration between press and release
time_between_clicks: time to pause between clicks
Returns:
None
"""
ClickButton(button, click_time)
time.sleep(time_between_clicks)
ClickButton(button, click_time)
def MoveToLocation(pos, duration=0, tick=0.01):
"""Move the mouse cursor to a specified location, taking the specified time.
Args:
pos: position (in screen coordinates) to move to
duration: amount of time the move should take
tick: amount of time between successive moves of the mouse
Returns:
None
"""
# calculate the number of moves to reach the destination
num_steps = (duration/tick)+1
# get the current and final mouse position in mouse coords
current_location = ScreenToMouse(win32gui.GetCursorPos())
end_location = ScreenToMouse(pos)
# Calculate the step size
step_size = ((end_location[0]-current_location[0])/num_steps,
(end_location[1]-current_location[1])/num_steps)
step = 0
while step < num_steps:
# Move the mouse one step
current_location = (current_location[0]+step_size[0],
current_location[1]+step_size[1])
# Coerce the coords to int to avoid a warning from pywin32
win32api.mouse_event(
win32con.MOUSEEVENTF_MOVE|win32con.MOUSEEVENTF_ABSOLUTE,
int(current_location[0]), int(current_location[1]))
step += 1
time.sleep(tick)
def ClickAtLocation(pos, button='left', click_time=0):
"""Simulate a mouse click in a particular location, in screen coordinates.
Args:
pos: position in screen coordinates (x,y)
button: which button to click
click_time: duration of the click
Returns:
None
"""
MoveToLocation(pos)
ClickButton(button, click_time)
def ClickInWindow(hwnd, offset=None, button='left', click_time=0):
"""Simulate a user mouse click in the center of a window.
Args:
hwnd: handle of the window to click in
offset: where to click, defaults to dead center
button: which button to click
click_time: duration of the click
Returns:
Nothing
"""
rect = win32gui.GetClientRect(hwnd)
if offset is None: offset = (rect[2]/2, rect[3]/2)
# get the screen coordinates of the window's center
pos = win32gui.ClientToScreen(hwnd, offset)
ClickAtLocation(pos, button, click_time)
def DoubleClickInWindow(
hwnd, offset=None, button='left', click_time=0, time_between_clicks=0.1):
"""Simulate a user mouse double click in the center of a window.
Args:
hwnd: handle of the window to click in
offset: where to click, defaults to dead center
button: which button to click
click_time: duration of the clicks
time_between_clicks: length of time to pause between clicks
Returns:
Nothing
"""
ClickInWindow(hwnd, offset, button, click_time)
time.sleep(time_between_clicks)
ClickInWindow(hwnd, offset, button, click_time)
def main():
# We're being invoked rather than imported. Let's do some tests
screen_size = win32gui.GetClientRect(win32gui.GetDesktopWindow())
screen_size = (screen_size[2], screen_size[3])
# move the mouse (instantly) to the upper right corner
MoveToLocation((screen_size[0], 0))
# move the mouse (over five seconds) to the lower left corner
MoveToLocation((0, screen_size[1]), 5)
# click the left mouse button. This will open up the Start menu
# if the taskbar is at the bottom
ClickButton()
# wait a bit, then click the right button to open the context menu
time.sleep(3)
ClickButton('right')
# move the mouse away and then click the left button to dismiss the
# context menu
MoveToLocation((screen_size[0]/2, screen_size[1]/2), 3)
MoveToLocation((0, 0), 3)
ClickButton()
if __name__ == "__main__":
sys.exit(main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
8972,
16051,
859,
367,
4389,
20529,
12817,
1324,
14,
199,
199,
2765,
859,
3509,
3423,
626,
883,
506,
1202,
370,
20577,
282,
922,
199,
15595,
71,
1958,
1808,
282,
20686,
2243,
14,
961,
6952,
12817,
4057,
434,
12,
199,
4891,
316,
543,
1263,
5528,
12,
436,
18981,
1540,
14,
199,
624,
199,
199,
646,
900,
463,
327,
367,
9435,
199,
199,
646,
4747,
708,
1246,
3777,
327,
367,
12817,
63,
1430,
199,
646,
4747,
708,
388,
3777,
327,
5417,
5262,
199,
646,
4747,
708,
5885,
3777,
327,
367,
4353,
3423,
421,
199,
318,
17804,
1378,
17141,
8,
541,
304,
523,
408,
7306,
282,
574,
315,
6426,
8983,
370,
12817,
8983,
14,
819,
603,
7130,
8983,
787,
2013,
465,
282,
16327,
402,
6426,
7365,
12,
523,
9657,
370,
3193,
5821,
14,
378,
8469,
314,
12474,
3602,
15,
2119,
402,
314,
6426,
12,
523,
18247,
8469,
314,
12474,
2451,
15,
8305,
14,
961,
805,
15194,
626,
523,
314,
1568,
402,
314,
6426,
365,
6317,
737,
859,
2248,
900,
436,
1630,
440,
1570,
819,
3033,
26,
272,
10063,
26,
314,
2376,
402,
314,
13259,
370,
3957,
819,
1803,
26,
272,
314,
6702,
2376,
523,
408,
819,
327,
11578,
314,
6426,
7365,
641,
1642,
6451,
14,
3390,
626,
642,
523,
327,
805,
15194,
626,
314,
6426,
7365,
886,
440,
1570,
5309,
1255,
14,
523,
340,
440,
17804,
1378,
17141,
423,
25070,
63,
19080,
17427,
26,
272,
19763,
275,
4747,
708,
5885,
14,
1002,
3041,
8252,
8,
2676,
708,
5885,
14,
1002,
20436,
4301,
1012,
272,
17804,
1378,
17141,
423,
25070,
63,
19080,
17427,
275,
334,
14487,
59,
18,
467,
19763,
59,
19,
566,
819,
372,
3666,
26439,
627,
10063,
59,
16,
566,
1182,
17804,
1378,
17141,
423,
25070,
63,
19080,
17427,
59,
16,
467,
881,
334,
26439,
627,
10063,
59,
17,
566,
1182,
17804,
1378,
17141,
423,
25070,
63,
19080,
17427,
59,
17,
566,
199,
199,
9616,
1378,
17141,
423,
25070,
63,
19080,
17427,
275,
488,
421,
199,
318,
23583,
4259,
8,
2110,
12,
5528,
534,
3039,
735,
523,
408,
7467,
5434,
282,
12817,
5528,
15105,
503,
4683,
737,
314,
1453,
12817,
2909,
14,
819,
3033,
26,
272,
3224,
26,
3775,
314,
5528,
365,
25167,
503,
14286,
272,
5528,
26,
1314,
5528,
365,
25167,
819,
1803,
26,
272,
488,
523,
408,
819,
327,
16280,
314,
12817,
63,
1430,
3285,
315,
282,
22700,
2600,
701,
5528,
523,
3285,
275,
469,
272,
283,
3039,
356,
257,
334,
2676,
708,
388,
14,
25571,
8193,
38,
63,
9894,
2160,
12,
257,
4747,
708,
388,
14,
25571,
8193,
38,
63,
9894,
8819,
395,
272,
283,
14885,
356,
334,
2676,
708,
388,
14,
25571,
8193,
38,
63,
45,
13016,
2160,
12,
4747,
708,
388,
14,
25571,
8193,
38,
63,
45,
13016,
8819,
395,
272,
283,
1019,
356,
221,
334,
2676,
708,
388,
14,
25571,
8193,
38,
63,
12811,
2160,
12,
221,
4747,
708,
388,
14,
25571,
8193,
38,
63,
12811,
8819,
9,
272,
789,
819,
327,
9793,
314,
5528,
523,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2469,
59,
3887,
1527,
2110,
467,
378,
12,
378,
9,
421,
199,
318,
26147,
4259,
8,
3887,
534,
3039,
297,
8968,
63,
521,
29,
16,
304,
523,
408,
14414,
436,
4683,
282,
12817,
5528,
737,
314,
1453,
12817,
2909,
14,
819,
3033,
26,
272,
5528,
26,
1314,
5528,
370,
8968,
272,
8968,
63,
521,
26,
7373,
3382,
15105,
436,
4683,
819,
1803,
26,
272,
488,
523,
408,
523,
23583,
4259,
8,
549,
12,
5528,
9,
523,
900,
14,
4532,
8,
4891,
63,
521,
9,
523,
23583,
4259,
8,
797,
12,
5528,
9,
421,
199,
318,
22945,
12040,
4259,
8,
3887,
534,
3039,
297,
8968,
63,
521,
29,
16,
12,
900,
63,
13007,
63,
4891,
83,
29,
16,
304,
523,
408,
7281,
13,
4891,
282,
12817,
5528,
737,
314,
1453,
12817,
2909,
14,
819,
3033,
26,
272,
5528,
26,
1314,
5528,
370,
8968,
272,
8968,
63,
521,
26,
7373,
3382,
15105,
436,
4683,
272,
900,
63,
13007,
63,
4891,
83,
26,
900,
370,
16834,
3382,
5053,
5618,
819,
1803,
26,
272,
488,
523,
408,
523,
26147,
4259,
8,
3887,
12,
8968,
63,
521,
9,
523,
900,
14,
4532,
8,
521,
63,
13007,
63,
4891,
83,
9,
523,
26147,
4259,
8,
3887,
12,
8968,
63,
521,
9,
421,
199,
318,
14171,
1378,
6592,
8,
1712,
12,
7373,
29,
16,
12,
11748,
29,
16,
14,
614,
304,
523,
408,
10370,
314,
12817,
3920,
370,
282,
2013,
2909,
12,
16466,
314,
2013,
900,
14,
819,
3033,
26,
272,
2086,
26,
3421,
334,
262,
6426,
8983,
9,
370,
4057,
370,
272,
7373,
26,
5982,
402,
900,
314,
4057,
1077,
5452,
272,
11748,
26,
5982,
402,
900,
3382,
27028,
3398,
14569,
402,
314,
12817,
819,
1803,
26,
272,
488,
523,
408,
523,
327,
8671,
314,
1329,
402,
14569,
370,
12276,
314,
5724,
523,
1967,
63,
5895,
275,
334,
5553,
15,
8284,
6393,
17,
819,
327,
664,
314,
1453,
436,
4242,
12817,
3421,
315,
12817,
13259,
523,
1453,
63,
1985,
275,
17804,
1378,
17141,
8,
2676,
708,
5885,
14,
1002,
8993,
6981,
1012,
523,
1284,
63,
1985,
275,
17804,
1378,
17141,
8,
1712,
9,
819,
327,
12707,
314,
3650,
1568,
523,
3650,
63,
890,
275,
3666,
500,
63,
1985,
59,
16,
11285,
1818,
63,
1985,
59,
16,
23067,
1507,
63,
5895,
12,
2049,
334,
500,
63,
1985,
59,
17,
11285,
1818,
63,
1985,
59,
17,
23067,
1507,
63,
5895,
9,
523,
3650,
275,
378,
819,
1830,
3650,
665,
1967,
63,
5895,
26,
272,
327,
14171,
314,
12817,
1373,
3650,
272,
1453,
63,
1985,
275,
334,
1818,
63,
1985,
59,
16,
2807,
2926,
63,
890,
59,
16,
467,
717,
1453,
63,
1985,
59,
17,
2807,
2926,
63,
890,
59,
17,
566,
339,
327,
1849,
9810,
314,
13259,
370,
1109,
370,
5126,
282,
5721,
687,
1134,
2676,
708,
272,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
489,
4747,
708,
388,
14,
25571,
8193
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
8972,
16051,
859,
367,
4389,
20529,
12817,
1324,
14,
199,
199,
2765,
859,
3509,
3423,
626,
883,
506,
1202,
370,
20577,
282,
922,
199,
15595,
71,
1958,
1808,
282,
20686,
2243,
14,
961,
6952,
12817,
4057,
434,
12,
199,
4891,
316,
543,
1263,
5528,
12,
436,
18981,
1540,
14,
199,
624,
199,
199,
646,
900,
463,
327,
367,
9435,
199,
199,
646,
4747,
708,
1246,
3777,
327,
367,
12817,
63,
1430,
199,
646,
4747,
708,
388,
3777,
327,
5417,
5262,
199,
646,
4747,
708,
5885,
3777,
327,
367,
4353,
3423,
421,
199,
318,
17804,
1378,
17141,
8,
541,
304,
523,
408,
7306,
282,
574,
315,
6426,
8983,
370,
12817,
8983,
14,
819,
603,
7130,
8983,
787,
2013,
465,
282,
16327,
402,
6426,
7365,
12,
523,
9657,
370,
3193,
5821,
14,
378,
8469,
314,
12474,
3602,
15,
2119,
402,
314,
6426,
12,
523,
18247,
8469,
314,
12474,
2451,
15,
8305,
14,
961,
805,
15194,
626,
523,
314,
1568,
402,
314,
6426,
365,
6317,
737,
859,
2248,
900,
436,
1630,
440,
1570,
819,
3033,
26,
272,
10063,
26,
314,
2376,
402,
314,
13259,
370,
3957,
819,
1803,
26,
272,
314,
6702,
2376,
523,
408,
819,
327,
11578,
314,
6426,
7365,
641,
1642,
6451,
14,
3390,
626,
642,
523,
327,
805,
15194,
626,
314,
6426,
7365,
886,
440,
1570,
5309,
1255,
14,
523,
340,
440,
17804,
1378,
17141,
423,
25070,
63,
19080,
17427,
26,
272,
19763,
275,
4747,
708,
5885,
14,
1002,
3041,
8252,
8,
2676,
708,
5885,
14,
1002,
20436,
4301,
1012,
272,
17804,
1378,
17141,
423,
25070,
63,
19080,
17427,
275,
334,
14487,
59,
18,
467,
19763,
59,
19,
566,
819,
372,
3666,
26439,
627,
10063,
59,
16,
566,
1182,
17804,
1378,
17141,
423,
25070,
63,
19080,
17427,
59,
16,
467,
881,
334,
26439,
627,
10063,
59,
17,
566,
1182,
17804,
1378,
17141,
423,
25070,
63,
19080,
17427,
59,
17,
566,
199,
199,
9616,
1378,
17141,
423,
25070,
63,
19080,
17427,
275,
488,
421,
199,
318,
23583,
4259,
8,
2110,
12,
5528,
534,
3039,
735,
523,
408,
7467,
5434,
282,
12817,
5528,
15105,
503,
4683,
737,
314,
1453,
12817,
2909,
14,
819,
3033,
26,
272,
3224,
26,
3775,
314,
5528,
365,
25167,
503,
14286,
272,
5528,
26,
1314,
5528,
365,
25167,
819,
1803,
26,
272,
488,
523,
408,
819,
327,
16280,
314,
12817,
63,
1430,
3285,
315,
282,
22700,
2600,
701,
5528,
523,
3285,
275,
469,
272,
283,
3039,
356,
257,
334,
2676,
708,
388,
14,
25571,
8193,
38,
63,
9894,
2160,
12,
257,
4747,
708,
388,
14,
25571,
8193,
38,
63,
9894,
8819,
395,
272,
283,
14885,
356,
334,
2676,
708,
388,
14,
25571,
8193,
38,
63,
45,
13016,
2160,
12,
4747,
708,
388,
14,
25571,
8193,
38,
63,
45,
13016,
8819,
395,
272,
283,
1019,
356,
221,
334,
2676,
708,
388,
14,
25571,
8193,
38,
63,
12811,
2160,
12,
221,
4747,
708,
388,
14,
25571,
8193,
38,
63,
12811,
8819,
9,
272,
789,
819,
327,
9793,
314,
5528,
523,
4747,
708,
1246,
14,
10544,
63,
1430,
8,
2469,
59,
3887,
1527,
2110,
467,
378,
12,
378,
9,
421,
199,
318,
26147,
4259,
8,
3887,
534,
3039,
297,
8968,
63,
521,
29,
16,
304,
523,
408,
14414,
436,
4683,
282,
12817,
5528,
737,
314,
1453,
12817,
2909,
14,
819,
3033,
26,
272,
5528,
26,
1314,
5528,
370,
8968,
272,
8968,
63,
521,
26,
7373,
3382,
15105,
436,
4683,
819,
1803,
26,
272,
488,
523,
408,
523,
23583,
4259,
8,
549,
12,
5528,
9,
523,
900,
14,
4532,
8,
4891,
63,
521,
9,
523,
23583,
4259,
8,
797,
12,
5528,
9,
421,
199,
318,
22945,
12040,
4259,
8,
3887,
534,
3039,
297,
8968,
63,
521,
29,
16,
12,
900,
63,
13007,
63,
4891,
83,
29,
16,
304,
523,
408,
7281,
13,
4891,
282,
12817,
5528,
737,
314,
1453,
12817,
2909,
14,
819,
3033,
26,
272,
5528,
26,
1314,
5528,
370,
8968,
272,
8968,
63,
521,
26,
7373,
3382,
15105,
436,
4683,
272,
900,
63,
13007,
63,
4891,
83,
26,
900,
370,
16834,
3382,
5053,
5618,
819,
1803,
26,
272,
488,
523,
408,
523,
26147,
4259,
8,
3887,
12,
8968,
63,
521,
9,
523,
900,
14,
4532,
8,
521,
63,
13007,
63,
4891,
83,
9,
523,
26147,
4259,
8,
3887,
12,
8968,
63,
521,
9,
421,
199,
318,
14171,
1378,
6592,
8,
1712,
12,
7373,
29,
16,
12,
11748,
29,
16,
14,
614,
304,
523,
408,
10370,
314,
12817,
3920,
370,
282,
2013,
2909,
12,
16466,
314,
2013,
900,
14,
819,
3033,
26,
272,
2086,
26,
3421,
334,
262,
6426,
8983,
9,
370,
4057,
370,
272,
7373,
26,
5982,
402,
900,
314,
4057,
1077,
5452,
272,
11748,
26,
5982,
402,
900,
3382,
27028,
3398,
14569,
402,
314,
12817,
819,
1803,
26,
272,
488,
523,
408,
523,
327,
8671,
314,
1329,
402,
14569,
370,
12276,
314,
5724,
523,
1967,
63,
5895,
275,
334,
5553,
15,
8284,
6393,
17,
819,
327,
664,
314,
1453,
436,
4242,
12817,
3421,
315,
12817,
13259,
523,
1453,
63,
1985,
275,
17804,
1378,
17141,
8,
2676,
708,
5885,
14,
1002,
8993,
6981,
1012,
523,
1284,
63,
1985,
275,
17804,
1378,
17141,
8,
1712,
9,
819,
327,
12707,
314,
3650,
1568,
523,
3650,
63,
890,
275,
3666,
500,
63,
1985,
59,
16,
11285,
1818,
63,
1985,
59,
16,
23067,
1507,
63,
5895,
12,
2049,
334,
500,
63,
1985,
59,
17,
11285,
1818,
63,
1985,
59,
17,
23067,
1507,
63,
5895,
9,
523,
3650,
275,
378,
819,
1830,
3650,
665,
1967,
63,
5895,
26,
272,
327,
14171,
314,
12817,
1373,
3650,
272,
1453,
63,
1985,
275,
334,
1818,
63,
1985,
59,
16,
2807,
2926,
63,
890,
59,
16,
467,
717,
1453,
63,
1985,
59,
17,
2807,
2926,
63,
890,
59,
17,
566,
339,
327,
1849,
9810,
314,
13259,
370,
1109,
370,
5126,
282,
5721,
687,
1134,
2676,
708,
272,
4747,
708,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ticklemepierce/osf.io
|
scripts/prereg/reject_draft_registrations.py
|
9
|
1717
|
""" A script for testing DraftRegistrationApprovals. Automatically adds comments to and rejects
pending DraftRegistrationApprovals
"""
import sys
import logging
import datetime as dt
from website.app import init_app
from website.models import DraftRegistration, Sanction, User
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.WARN)
logging.disable(level=logging.INFO)
def add_comments(draft):
comment = [{
'user': {
'id': 'itsMe',
'name': 'Mario!'
},
'value': 'Ahoy! This is a comment!',
'lastModified': dt.datetime.utcnow().isoformat()
}]
for question_id, value in draft.registration_metadata.iteritems():
value['comments'] = comment
draft.save()
def main(dry_run=True):
if dry_run:
logger.warn('DRY RUN mode')
pending_approval_drafts = DraftRegistration.find()
need_approval_drafts = [draft for draft in pending_approval_drafts
if draft.requires_approval and draft.approval and draft.approval.state == Sanction.UNAPPROVED]
for draft in need_approval_drafts:
add_comments(draft)
sanction = draft.approval
try:
if not dry_run:
sanction.forcibly_reject()
#manually do the on_reject functionality to prevent send_mail problems
sanction.meta = {}
sanction.save()
draft.approval = None
draft.save()
logger.warn('Rejected {0}'.format(draft._id))
except Exception as e:
logger.error(e)
if __name__ == '__main__':
dry_run = 'dry' in sys.argv
init_app(routes=False)
main(dry_run=dry_run)
|
apache-2.0
|
[
624,
437,
2884,
367,
5343,
28090,
11757,
25923,
3643,
14,
9195,
17174,
9584,
6786,
370,
436,
17100,
83,
199,
6455,
28090,
11757,
25923,
3643,
199,
624,
199,
646,
984,
199,
646,
2050,
199,
646,
2197,
465,
4487,
199,
199,
504,
10691,
14,
571,
492,
4205,
63,
571,
199,
504,
10691,
14,
992,
492,
28090,
11757,
12,
29359,
414,
12,
2876,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
17449,
9,
199,
4806,
14,
5993,
8,
1896,
29,
4806,
14,
4531,
9,
421,
199,
318,
1050,
63,
6223,
8,
7185,
304,
272,
3721,
275,
8910,
267,
283,
751,
356,
469,
288,
283,
344,
356,
283,
1405,
1352,
297,
288,
283,
354,
356,
283,
45,
6936,
11213,
267,
1660,
267,
283,
585,
356,
283,
33,
526,
89,
1,
961,
365,
282,
3721,
12389,
267,
283,
2019,
11911,
356,
4487,
14,
2083,
14,
10779,
1252,
17070,
342,
272,
14877,
272,
367,
7894,
63,
344,
12,
574,
315,
11872,
14,
8054,
63,
2343,
14,
4611,
837,
267,
574,
459,
6223,
418,
275,
3721,
272,
11872,
14,
2117,
342,
199,
199,
318,
2446,
8,
10481,
63,
1065,
29,
549,
304,
272,
340,
9951,
63,
1065,
26,
267,
2512,
14,
4050,
360,
4564,
57,
21277,
818,
358,
272,
9413,
63,
28302,
63,
7185,
83,
275,
28090,
11757,
14,
1623,
342,
272,
1929,
63,
28302,
63,
7185,
83,
275,
359,
7185,
367,
11872,
315,
9413,
63,
28302,
63,
7185,
83,
1169,
340,
11872,
14,
6537,
63,
28302,
436,
11872,
14,
28302,
436,
11872,
14,
28302,
14,
929,
508,
29359,
414,
14,
1734,
1282,
2514,
14112,
61,
339,
367,
11872,
315,
1929,
63,
28302,
63,
7185,
83,
26,
267,
1050,
63,
6223,
8,
7185,
9,
267,
28698,
414,
275,
11872,
14,
28302,
267,
862,
26,
288,
340,
440,
9951,
63,
1065,
26,
355,
28698,
414,
14,
509,
559,
66,
590,
63,
16857,
342,
355,
327,
1237,
3163,
886,
314,
641,
63,
16857,
9330,
370,
7981,
3222,
63,
1198,
8826,
355,
28698,
414,
14,
2024,
275,
1052,
355,
28698,
414,
14,
2117,
342,
355,
11872,
14,
28302,
275,
488,
355,
11872,
14,
2117,
342,
288,
2512,
14,
4050,
360,
497,
8553,
469,
16,
5285,
908,
8,
7185,
423,
344,
430,
267,
871,
2186,
465,
325,
26,
288,
2512,
14,
705,
8,
69,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9951,
63,
1065,
275,
283,
10481,
7,
315,
984,
14,
3020,
272,
4205,
63,
571,
8,
13243,
29,
797,
9,
272,
2446,
8,
10481,
63,
1065,
29,
10481,
63,
1065,
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
] |
[
437,
2884,
367,
5343,
28090,
11757,
25923,
3643,
14,
9195,
17174,
9584,
6786,
370,
436,
17100,
83,
199,
6455,
28090,
11757,
25923,
3643,
199,
624,
199,
646,
984,
199,
646,
2050,
199,
646,
2197,
465,
4487,
199,
199,
504,
10691,
14,
571,
492,
4205,
63,
571,
199,
504,
10691,
14,
992,
492,
28090,
11757,
12,
29359,
414,
12,
2876,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
17449,
9,
199,
4806,
14,
5993,
8,
1896,
29,
4806,
14,
4531,
9,
421,
199,
318,
1050,
63,
6223,
8,
7185,
304,
272,
3721,
275,
8910,
267,
283,
751,
356,
469,
288,
283,
344,
356,
283,
1405,
1352,
297,
288,
283,
354,
356,
283,
45,
6936,
11213,
267,
1660,
267,
283,
585,
356,
283,
33,
526,
89,
1,
961,
365,
282,
3721,
12389,
267,
283,
2019,
11911,
356,
4487,
14,
2083,
14,
10779,
1252,
17070,
342,
272,
14877,
272,
367,
7894,
63,
344,
12,
574,
315,
11872,
14,
8054,
63,
2343,
14,
4611,
837,
267,
574,
459,
6223,
418,
275,
3721,
272,
11872,
14,
2117,
342,
199,
199,
318,
2446,
8,
10481,
63,
1065,
29,
549,
304,
272,
340,
9951,
63,
1065,
26,
267,
2512,
14,
4050,
360,
4564,
57,
21277,
818,
358,
272,
9413,
63,
28302,
63,
7185,
83,
275,
28090,
11757,
14,
1623,
342,
272,
1929,
63,
28302,
63,
7185,
83,
275,
359,
7185,
367,
11872,
315,
9413,
63,
28302,
63,
7185,
83,
1169,
340,
11872,
14,
6537,
63,
28302,
436,
11872,
14,
28302,
436,
11872,
14,
28302,
14,
929,
508,
29359,
414,
14,
1734,
1282,
2514,
14112,
61,
339,
367,
11872,
315,
1929,
63,
28302,
63,
7185,
83,
26,
267,
1050,
63,
6223,
8,
7185,
9,
267,
28698,
414,
275,
11872,
14,
28302,
267,
862,
26,
288,
340,
440,
9951,
63,
1065,
26,
355,
28698,
414,
14,
509,
559,
66,
590,
63,
16857,
342,
355,
327,
1237,
3163,
886,
314,
641,
63,
16857,
9330,
370,
7981,
3222,
63,
1198,
8826,
355,
28698,
414,
14,
2024,
275,
1052,
355,
28698,
414,
14,
2117,
342,
355,
11872,
14,
28302,
275,
488,
355,
11872,
14,
2117,
342,
288,
2512,
14,
4050,
360,
497,
8553,
469,
16,
5285,
908,
8,
7185,
423,
344,
430,
267,
871,
2186,
465,
325,
26,
288,
2512,
14,
705,
8,
69,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9951,
63,
1065,
275,
283,
10481,
7,
315,
984,
14,
3020,
272,
4205,
63,
571,
8,
13243,
29,
797,
9,
272,
2446,
8,
10481,
63,
1065,
29,
10481,
63,
1065,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tylerjereddy/scipy
|
scipy/linalg/tests/test_decomp_update.py
|
12
|
68330
|
import itertools
import numpy as np
from numpy.testing import assert_, assert_allclose, assert_equal
from pytest import raises as assert_raises
from scipy import linalg
import scipy.linalg._decomp_update as _decomp_update
from scipy.linalg._decomp_update import qr_delete, qr_update, qr_insert
def assert_unitary(a, rtol=None, atol=None, assert_sqr=True):
if rtol is None:
rtol = 10.0 ** -(np.finfo(a.dtype).precision-2)
if atol is None:
atol = 10*np.finfo(a.dtype).eps
if assert_sqr:
assert_(a.shape[0] == a.shape[1], 'unitary matrices must be square')
aTa = np.dot(a.T.conj(), a)
assert_allclose(aTa, np.eye(a.shape[1]), rtol=rtol, atol=atol)
def assert_upper_tri(a, rtol=None, atol=None):
if rtol is None:
rtol = 10.0 ** -(np.finfo(a.dtype).precision-2)
if atol is None:
atol = 2*np.finfo(a.dtype).eps
mask = np.tri(a.shape[0], a.shape[1], -1, np.bool_)
assert_allclose(a[mask], 0.0, rtol=rtol, atol=atol)
def check_qr(q, r, a, rtol, atol, assert_sqr=True):
assert_unitary(q, rtol, atol, assert_sqr)
assert_upper_tri(r, rtol, atol)
assert_allclose(q.dot(r), a, rtol=rtol, atol=atol)
def make_strided(arrs):
strides = [(3, 7), (2, 2), (3, 4), (4, 2), (5, 4), (2, 3), (2, 1), (4, 5)]
kmax = len(strides)
k = 0
ret = []
for a in arrs:
if a.ndim == 1:
s = strides[k % kmax]
k += 1
base = np.zeros(s[0]*a.shape[0]+s[1], a.dtype)
view = base[s[1]::s[0]]
view[...] = a
elif a.ndim == 2:
s = strides[k % kmax]
t = strides[(k+1) % kmax]
k += 2
base = np.zeros((s[0]*a.shape[0]+s[1], t[0]*a.shape[1]+t[1]),
a.dtype)
view = base[s[1]::s[0], t[1]::t[0]]
view[...] = a
else:
raise ValueError('make_strided only works for ndim = 1 or'
' 2 arrays')
ret.append(view)
return ret
def negate_strides(arrs):
ret = []
for a in arrs:
b = np.zeros_like(a)
if b.ndim == 2:
b = b[::-1, ::-1]
elif b.ndim == 1:
b = b[::-1]
else:
raise ValueError('negate_strides only works for ndim = 1 or'
' 2 arrays')
b[...] = a
ret.append(b)
return ret
def nonitemsize_strides(arrs):
out = []
for a in arrs:
a_dtype = a.dtype
b = np.zeros(a.shape, [('a', a_dtype), ('junk', 'S1')])
c = b.getfield(a_dtype)
c[...] = a
out.append(c)
return out
def make_nonnative(arrs):
return [a.astype(a.dtype.newbyteorder()) for a in arrs]
class BaseQRdeltas:
def setup_method(self):
self.rtol = 10.0 ** -(np.finfo(self.dtype).precision-2)
self.atol = 10 * np.finfo(self.dtype).eps
def generate(self, type, mode='full'):
np.random.seed(29382)
shape = {'sqr': (8, 8), 'tall': (12, 7), 'fat': (7, 12),
'Mx1': (8, 1), '1xN': (1, 8), '1x1': (1, 1)}[type]
a = np.random.random(shape)
if np.iscomplexobj(self.dtype.type(1)):
b = np.random.random(shape)
a = a + 1j * b
a = a.astype(self.dtype)
q, r = linalg.qr(a, mode=mode)
return a, q, r
class BaseQRdelete(BaseQRdeltas):
def test_sqr_1_row(self):
a, q, r = self.generate('sqr')
for row in range(r.shape[0]):
q1, r1 = qr_delete(q, r, row, overwrite_qr=False)
a1 = np.delete(a, row, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_sqr_p_row(self):
a, q, r = self.generate('sqr')
for ndel in range(2, 6):
for row in range(a.shape[0]-ndel):
q1, r1 = qr_delete(q, r, row, ndel, overwrite_qr=False)
a1 = np.delete(a, slice(row, row+ndel), 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_sqr_1_col(self):
a, q, r = self.generate('sqr')
for col in range(r.shape[1]):
q1, r1 = qr_delete(q, r, col, which='col', overwrite_qr=False)
a1 = np.delete(a, col, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_sqr_p_col(self):
a, q, r = self.generate('sqr')
for ndel in range(2, 6):
for col in range(r.shape[1]-ndel):
q1, r1 = qr_delete(q, r, col, ndel, which='col',
overwrite_qr=False)
a1 = np.delete(a, slice(col, col+ndel), 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_1_row(self):
a, q, r = self.generate('tall')
for row in range(r.shape[0]):
q1, r1 = qr_delete(q, r, row, overwrite_qr=False)
a1 = np.delete(a, row, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_p_row(self):
a, q, r = self.generate('tall')
for ndel in range(2, 6):
for row in range(a.shape[0]-ndel):
q1, r1 = qr_delete(q, r, row, ndel, overwrite_qr=False)
a1 = np.delete(a, slice(row, row+ndel), 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_1_col(self):
a, q, r = self.generate('tall')
for col in range(r.shape[1]):
q1, r1 = qr_delete(q, r, col, which='col', overwrite_qr=False)
a1 = np.delete(a, col, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_p_col(self):
a, q, r = self.generate('tall')
for ndel in range(2, 6):
for col in range(r.shape[1]-ndel):
q1, r1 = qr_delete(q, r, col, ndel, which='col',
overwrite_qr=False)
a1 = np.delete(a, slice(col, col+ndel), 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_fat_1_row(self):
a, q, r = self.generate('fat')
for row in range(r.shape[0]):
q1, r1 = qr_delete(q, r, row, overwrite_qr=False)
a1 = np.delete(a, row, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_fat_p_row(self):
a, q, r = self.generate('fat')
for ndel in range(2, 6):
for row in range(a.shape[0]-ndel):
q1, r1 = qr_delete(q, r, row, ndel, overwrite_qr=False)
a1 = np.delete(a, slice(row, row+ndel), 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_fat_1_col(self):
a, q, r = self.generate('fat')
for col in range(r.shape[1]):
q1, r1 = qr_delete(q, r, col, which='col', overwrite_qr=False)
a1 = np.delete(a, col, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_fat_p_col(self):
a, q, r = self.generate('fat')
for ndel in range(2, 6):
for col in range(r.shape[1]-ndel):
q1, r1 = qr_delete(q, r, col, ndel, which='col',
overwrite_qr=False)
a1 = np.delete(a, slice(col, col+ndel), 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_economic_1_row(self):
# this test always starts and ends with an economic decomp.
a, q, r = self.generate('tall', 'economic')
for row in range(r.shape[0]):
q1, r1 = qr_delete(q, r, row, overwrite_qr=False)
a1 = np.delete(a, row, 0)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
# for economic row deletes
# eco - prow = eco
# eco - prow = sqr
# eco - prow = fat
def base_economic_p_row_xxx(self, ndel):
a, q, r = self.generate('tall', 'economic')
for row in range(a.shape[0]-ndel):
q1, r1 = qr_delete(q, r, row, ndel, overwrite_qr=False)
a1 = np.delete(a, slice(row, row+ndel), 0)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_economic_p_row_economic(self):
# (12, 7) - (3, 7) = (9,7) --> stays economic
self.base_economic_p_row_xxx(3)
def test_economic_p_row_sqr(self):
# (12, 7) - (5, 7) = (7, 7) --> becomes square
self.base_economic_p_row_xxx(5)
def test_economic_p_row_fat(self):
# (12, 7) - (7,7) = (5, 7) --> becomes fat
self.base_economic_p_row_xxx(7)
def test_economic_1_col(self):
a, q, r = self.generate('tall', 'economic')
for col in range(r.shape[1]):
q1, r1 = qr_delete(q, r, col, which='col', overwrite_qr=False)
a1 = np.delete(a, col, 1)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_economic_p_col(self):
a, q, r = self.generate('tall', 'economic')
for ndel in range(2, 6):
for col in range(r.shape[1]-ndel):
q1, r1 = qr_delete(q, r, col, ndel, which='col',
overwrite_qr=False)
a1 = np.delete(a, slice(col, col+ndel), 1)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_Mx1_1_row(self):
a, q, r = self.generate('Mx1')
for row in range(r.shape[0]):
q1, r1 = qr_delete(q, r, row, overwrite_qr=False)
a1 = np.delete(a, row, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_Mx1_p_row(self):
a, q, r = self.generate('Mx1')
for ndel in range(2, 6):
for row in range(a.shape[0]-ndel):
q1, r1 = qr_delete(q, r, row, ndel, overwrite_qr=False)
a1 = np.delete(a, slice(row, row+ndel), 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1xN_1_col(self):
a, q, r = self.generate('1xN')
for col in range(r.shape[1]):
q1, r1 = qr_delete(q, r, col, which='col', overwrite_qr=False)
a1 = np.delete(a, col, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1xN_p_col(self):
a, q, r = self.generate('1xN')
for ndel in range(2, 6):
for col in range(r.shape[1]-ndel):
q1, r1 = qr_delete(q, r, col, ndel, which='col',
overwrite_qr=False)
a1 = np.delete(a, slice(col, col+ndel), 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_Mx1_economic_1_row(self):
a, q, r = self.generate('Mx1', 'economic')
for row in range(r.shape[0]):
q1, r1 = qr_delete(q, r, row, overwrite_qr=False)
a1 = np.delete(a, row, 0)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_Mx1_economic_p_row(self):
a, q, r = self.generate('Mx1', 'economic')
for ndel in range(2, 6):
for row in range(a.shape[0]-ndel):
q1, r1 = qr_delete(q, r, row, ndel, overwrite_qr=False)
a1 = np.delete(a, slice(row, row+ndel), 0)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_delete_last_1_row(self):
# full and eco are the same for 1xN
a, q, r = self.generate('1xN')
q1, r1 = qr_delete(q, r, 0, 1, 'row')
assert_equal(q1, np.ndarray(shape=(0, 0), dtype=q.dtype))
assert_equal(r1, np.ndarray(shape=(0, r.shape[1]), dtype=r.dtype))
def test_delete_last_p_row(self):
a, q, r = self.generate('tall', 'full')
q1, r1 = qr_delete(q, r, 0, a.shape[0], 'row')
assert_equal(q1, np.ndarray(shape=(0, 0), dtype=q.dtype))
assert_equal(r1, np.ndarray(shape=(0, r.shape[1]), dtype=r.dtype))
a, q, r = self.generate('tall', 'economic')
q1, r1 = qr_delete(q, r, 0, a.shape[0], 'row')
assert_equal(q1, np.ndarray(shape=(0, 0), dtype=q.dtype))
assert_equal(r1, np.ndarray(shape=(0, r.shape[1]), dtype=r.dtype))
def test_delete_last_1_col(self):
a, q, r = self.generate('Mx1', 'economic')
q1, r1 = qr_delete(q, r, 0, 1, 'col')
assert_equal(q1, np.ndarray(shape=(q.shape[0], 0), dtype=q.dtype))
assert_equal(r1, np.ndarray(shape=(0, 0), dtype=r.dtype))
a, q, r = self.generate('Mx1', 'full')
q1, r1 = qr_delete(q, r, 0, 1, 'col')
assert_unitary(q1)
assert_(q1.dtype == q.dtype)
assert_(q1.shape == q.shape)
assert_equal(r1, np.ndarray(shape=(r.shape[0], 0), dtype=r.dtype))
def test_delete_last_p_col(self):
a, q, r = self.generate('tall', 'full')
q1, r1 = qr_delete(q, r, 0, a.shape[1], 'col')
assert_unitary(q1)
assert_(q1.dtype == q.dtype)
assert_(q1.shape == q.shape)
assert_equal(r1, np.ndarray(shape=(r.shape[0], 0), dtype=r.dtype))
a, q, r = self.generate('tall', 'economic')
q1, r1 = qr_delete(q, r, 0, a.shape[1], 'col')
assert_equal(q1, np.ndarray(shape=(q.shape[0], 0), dtype=q.dtype))
assert_equal(r1, np.ndarray(shape=(0, 0), dtype=r.dtype))
def test_delete_1x1_row_col(self):
a, q, r = self.generate('1x1')
q1, r1 = qr_delete(q, r, 0, 1, 'row')
assert_equal(q1, np.ndarray(shape=(0, 0), dtype=q.dtype))
assert_equal(r1, np.ndarray(shape=(0, r.shape[1]), dtype=r.dtype))
a, q, r = self.generate('1x1')
q1, r1 = qr_delete(q, r, 0, 1, 'col')
assert_unitary(q1)
assert_(q1.dtype == q.dtype)
assert_(q1.shape == q.shape)
assert_equal(r1, np.ndarray(shape=(r.shape[0], 0), dtype=r.dtype))
# all full qr, row deletes and single column deletes should be able to
# handle any non negative strides. (only row and column vector
# operations are used.) p column delete require fortran ordered
# Q and R and will make a copy as necessary. Economic qr row deletes
# requre a contigous q.
def base_non_simple_strides(self, adjust_strides, ks, p, which,
overwriteable):
if which == 'row':
qind = (slice(p,None), slice(p,None))
rind = (slice(p,None), slice(None))
else:
qind = (slice(None), slice(None))
rind = (slice(None), slice(None,-p))
for type, k in itertools.product(['sqr', 'tall', 'fat'], ks):
a, q0, r0, = self.generate(type)
qs, rs = adjust_strides((q0, r0))
if p == 1:
a1 = np.delete(a, k, 0 if which == 'row' else 1)
else:
s = slice(k,k+p)
if k < 0:
s = slice(k, k + p +
(a.shape[0] if which == 'row' else a.shape[1]))
a1 = np.delete(a, s, 0 if which == 'row' else 1)
# for each variable, q, r we try with it strided and
# overwrite=False. Then we try with overwrite=True, and make
# sure that q and r are still overwritten.
q = q0.copy('F')
r = r0.copy('F')
q1, r1 = qr_delete(qs, r, k, p, which, False)
check_qr(q1, r1, a1, self.rtol, self.atol)
q1o, r1o = qr_delete(qs, r, k, p, which, True)
check_qr(q1o, r1o, a1, self.rtol, self.atol)
if overwriteable:
assert_allclose(q1o, qs[qind], rtol=self.rtol, atol=self.atol)
assert_allclose(r1o, r[rind], rtol=self.rtol, atol=self.atol)
q = q0.copy('F')
r = r0.copy('F')
q2, r2 = qr_delete(q, rs, k, p, which, False)
check_qr(q2, r2, a1, self.rtol, self.atol)
q2o, r2o = qr_delete(q, rs, k, p, which, True)
check_qr(q2o, r2o, a1, self.rtol, self.atol)
if overwriteable:
assert_allclose(q2o, q[qind], rtol=self.rtol, atol=self.atol)
assert_allclose(r2o, rs[rind], rtol=self.rtol, atol=self.atol)
q = q0.copy('F')
r = r0.copy('F')
# since some of these were consumed above
qs, rs = adjust_strides((q, r))
q3, r3 = qr_delete(qs, rs, k, p, which, False)
check_qr(q3, r3, a1, self.rtol, self.atol)
q3o, r3o = qr_delete(qs, rs, k, p, which, True)
check_qr(q3o, r3o, a1, self.rtol, self.atol)
if overwriteable:
assert_allclose(q2o, qs[qind], rtol=self.rtol, atol=self.atol)
assert_allclose(r3o, rs[rind], rtol=self.rtol, atol=self.atol)
def test_non_unit_strides_1_row(self):
self.base_non_simple_strides(make_strided, [0], 1, 'row', True)
def test_non_unit_strides_p_row(self):
self.base_non_simple_strides(make_strided, [0], 3, 'row', True)
def test_non_unit_strides_1_col(self):
self.base_non_simple_strides(make_strided, [0], 1, 'col', True)
def test_non_unit_strides_p_col(self):
self.base_non_simple_strides(make_strided, [0], 3, 'col', False)
def test_neg_strides_1_row(self):
self.base_non_simple_strides(negate_strides, [0], 1, 'row', False)
def test_neg_strides_p_row(self):
self.base_non_simple_strides(negate_strides, [0], 3, 'row', False)
def test_neg_strides_1_col(self):
self.base_non_simple_strides(negate_strides, [0], 1, 'col', False)
def test_neg_strides_p_col(self):
self.base_non_simple_strides(negate_strides, [0], 3, 'col', False)
def test_non_itemize_strides_1_row(self):
self.base_non_simple_strides(nonitemsize_strides, [0], 1, 'row', False)
def test_non_itemize_strides_p_row(self):
self.base_non_simple_strides(nonitemsize_strides, [0], 3, 'row', False)
def test_non_itemize_strides_1_col(self):
self.base_non_simple_strides(nonitemsize_strides, [0], 1, 'col', False)
def test_non_itemize_strides_p_col(self):
self.base_non_simple_strides(nonitemsize_strides, [0], 3, 'col', False)
def test_non_native_byte_order_1_row(self):
self.base_non_simple_strides(make_nonnative, [0], 1, 'row', False)
def test_non_native_byte_order_p_row(self):
self.base_non_simple_strides(make_nonnative, [0], 3, 'row', False)
def test_non_native_byte_order_1_col(self):
self.base_non_simple_strides(make_nonnative, [0], 1, 'col', False)
def test_non_native_byte_order_p_col(self):
self.base_non_simple_strides(make_nonnative, [0], 3, 'col', False)
def test_neg_k(self):
a, q, r = self.generate('sqr')
for k, p, w in itertools.product([-3, -7], [1, 3], ['row', 'col']):
q1, r1 = qr_delete(q, r, k, p, w, overwrite_qr=False)
if w == 'row':
a1 = np.delete(a, slice(k+a.shape[0], k+p+a.shape[0]), 0)
else:
a1 = np.delete(a, slice(k+a.shape[0], k+p+a.shape[1]), 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def base_overwrite_qr(self, which, p, test_C, test_F, mode='full'):
assert_sqr = True if mode == 'full' else False
if which == 'row':
qind = (slice(p,None), slice(p,None))
rind = (slice(p,None), slice(None))
else:
qind = (slice(None), slice(None))
rind = (slice(None), slice(None,-p))
a, q0, r0 = self.generate('sqr', mode)
if p == 1:
a1 = np.delete(a, 3, 0 if which == 'row' else 1)
else:
a1 = np.delete(a, slice(3, 3+p), 0 if which == 'row' else 1)
# don't overwrite
q = q0.copy('F')
r = r0.copy('F')
q1, r1 = qr_delete(q, r, 3, p, which, False)
check_qr(q1, r1, a1, self.rtol, self.atol, assert_sqr)
check_qr(q, r, a, self.rtol, self.atol, assert_sqr)
if test_F:
q = q0.copy('F')
r = r0.copy('F')
q2, r2 = qr_delete(q, r, 3, p, which, True)
check_qr(q2, r2, a1, self.rtol, self.atol, assert_sqr)
# verify the overwriting
assert_allclose(q2, q[qind], rtol=self.rtol, atol=self.atol)
assert_allclose(r2, r[rind], rtol=self.rtol, atol=self.atol)
if test_C:
q = q0.copy('C')
r = r0.copy('C')
q3, r3 = qr_delete(q, r, 3, p, which, True)
check_qr(q3, r3, a1, self.rtol, self.atol, assert_sqr)
assert_allclose(q3, q[qind], rtol=self.rtol, atol=self.atol)
assert_allclose(r3, r[rind], rtol=self.rtol, atol=self.atol)
def test_overwrite_qr_1_row(self):
# any positively strided q and r.
self.base_overwrite_qr('row', 1, True, True)
def test_overwrite_economic_qr_1_row(self):
# Any contiguous q and positively strided r.
self.base_overwrite_qr('row', 1, True, True, 'economic')
def test_overwrite_qr_1_col(self):
# any positively strided q and r.
# full and eco share code paths
self.base_overwrite_qr('col', 1, True, True)
def test_overwrite_qr_p_row(self):
# any positively strided q and r.
self.base_overwrite_qr('row', 3, True, True)
def test_overwrite_economic_qr_p_row(self):
# any contiguous q and positively strided r
self.base_overwrite_qr('row', 3, True, True, 'economic')
def test_overwrite_qr_p_col(self):
# only F orderd q and r can be overwritten for cols
# full and eco share code paths
self.base_overwrite_qr('col', 3, False, True)
def test_bad_which(self):
a, q, r = self.generate('sqr')
assert_raises(ValueError, qr_delete, q, r, 0, which='foo')
def test_bad_k(self):
a, q, r = self.generate('tall')
assert_raises(ValueError, qr_delete, q, r, q.shape[0], 1)
assert_raises(ValueError, qr_delete, q, r, -q.shape[0]-1, 1)
assert_raises(ValueError, qr_delete, q, r, r.shape[0], 1, 'col')
assert_raises(ValueError, qr_delete, q, r, -r.shape[0]-1, 1, 'col')
def test_bad_p(self):
a, q, r = self.generate('tall')
# p must be positive
assert_raises(ValueError, qr_delete, q, r, 0, -1)
assert_raises(ValueError, qr_delete, q, r, 0, -1, 'col')
# and nonzero
assert_raises(ValueError, qr_delete, q, r, 0, 0)
assert_raises(ValueError, qr_delete, q, r, 0, 0, 'col')
# must have at least k+p rows or cols, depending.
assert_raises(ValueError, qr_delete, q, r, 3, q.shape[0]-2)
assert_raises(ValueError, qr_delete, q, r, 3, r.shape[1]-2, 'col')
def test_empty_q(self):
a, q, r = self.generate('tall')
# same code path for 'row' and 'col'
assert_raises(ValueError, qr_delete, np.array([]), r, 0, 1)
def test_empty_r(self):
a, q, r = self.generate('tall')
# same code path for 'row' and 'col'
assert_raises(ValueError, qr_delete, q, np.array([]), 0, 1)
def test_mismatched_q_and_r(self):
a, q, r = self.generate('tall')
r = r[1:]
assert_raises(ValueError, qr_delete, q, r, 0, 1)
def test_unsupported_dtypes(self):
dts = ['int8', 'int16', 'int32', 'int64',
'uint8', 'uint16', 'uint32', 'uint64',
'float16', 'longdouble', 'longcomplex',
'bool']
a, q0, r0 = self.generate('tall')
for dtype in dts:
q = q0.real.astype(dtype)
r = r0.real.astype(dtype)
assert_raises(ValueError, qr_delete, q, r0, 0, 1, 'row')
assert_raises(ValueError, qr_delete, q, r0, 0, 2, 'row')
assert_raises(ValueError, qr_delete, q, r0, 0, 1, 'col')
assert_raises(ValueError, qr_delete, q, r0, 0, 2, 'col')
assert_raises(ValueError, qr_delete, q0, r, 0, 1, 'row')
assert_raises(ValueError, qr_delete, q0, r, 0, 2, 'row')
assert_raises(ValueError, qr_delete, q0, r, 0, 1, 'col')
assert_raises(ValueError, qr_delete, q0, r, 0, 2, 'col')
def test_check_finite(self):
a0, q0, r0 = self.generate('tall')
q = q0.copy('F')
q[1,1] = np.nan
assert_raises(ValueError, qr_delete, q, r0, 0, 1, 'row')
assert_raises(ValueError, qr_delete, q, r0, 0, 3, 'row')
assert_raises(ValueError, qr_delete, q, r0, 0, 1, 'col')
assert_raises(ValueError, qr_delete, q, r0, 0, 3, 'col')
r = r0.copy('F')
r[1,1] = np.nan
assert_raises(ValueError, qr_delete, q0, r, 0, 1, 'row')
assert_raises(ValueError, qr_delete, q0, r, 0, 3, 'row')
assert_raises(ValueError, qr_delete, q0, r, 0, 1, 'col')
assert_raises(ValueError, qr_delete, q0, r, 0, 3, 'col')
def test_qr_scalar(self):
a, q, r = self.generate('1x1')
assert_raises(ValueError, qr_delete, q[0, 0], r, 0, 1, 'row')
assert_raises(ValueError, qr_delete, q, r[0, 0], 0, 1, 'row')
assert_raises(ValueError, qr_delete, q[0, 0], r, 0, 1, 'col')
assert_raises(ValueError, qr_delete, q, r[0, 0], 0, 1, 'col')
class TestQRdelete_f(BaseQRdelete):
dtype = np.dtype('f')
class TestQRdelete_F(BaseQRdelete):
dtype = np.dtype('F')
class TestQRdelete_d(BaseQRdelete):
dtype = np.dtype('d')
class TestQRdelete_D(BaseQRdelete):
dtype = np.dtype('D')
class BaseQRinsert(BaseQRdeltas):
def generate(self, type, mode='full', which='row', p=1):
a, q, r = super().generate(type, mode)
assert_(p > 0)
# super call set the seed...
if which == 'row':
if p == 1:
u = np.random.random(a.shape[1])
else:
u = np.random.random((p, a.shape[1]))
elif which == 'col':
if p == 1:
u = np.random.random(a.shape[0])
else:
u = np.random.random((a.shape[0], p))
else:
ValueError('which should be either "row" or "col"')
if np.iscomplexobj(self.dtype.type(1)):
b = np.random.random(u.shape)
u = u + 1j * b
u = u.astype(self.dtype)
return a, q, r, u
def test_sqr_1_row(self):
a, q, r, u = self.generate('sqr', which='row')
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, row, u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_sqr_p_row(self):
# sqr + rows --> fat always
a, q, r, u = self.generate('sqr', which='row', p=3)
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, np.full(3, row, np.intp), u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_sqr_1_col(self):
a, q, r, u = self.generate('sqr', which='col')
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, col, u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_sqr_p_col(self):
# sqr + cols --> fat always
a, q, r, u = self.generate('sqr', which='col', p=3)
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, np.full(3, col, np.intp), u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_1_row(self):
a, q, r, u = self.generate('tall', which='row')
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, row, u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_p_row(self):
# tall + rows --> tall always
a, q, r, u = self.generate('tall', which='row', p=3)
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, np.full(3, row, np.intp), u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_1_col(self):
a, q, r, u = self.generate('tall', which='col')
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, col, u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
# for column adds to tall matrices there are three cases to test
# tall + pcol --> tall
# tall + pcol --> sqr
# tall + pcol --> fat
def base_tall_p_col_xxx(self, p):
a, q, r, u = self.generate('tall', which='col', p=p)
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, np.full(p, col, np.intp), u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_p_col_tall(self):
# 12x7 + 12x3 = 12x10 --> stays tall
self.base_tall_p_col_xxx(3)
def test_tall_p_col_sqr(self):
# 12x7 + 12x5 = 12x12 --> becomes sqr
self.base_tall_p_col_xxx(5)
def test_tall_p_col_fat(self):
# 12x7 + 12x7 = 12x14 --> becomes fat
self.base_tall_p_col_xxx(7)
def test_fat_1_row(self):
a, q, r, u = self.generate('fat', which='row')
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, row, u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
# for row adds to fat matrices there are three cases to test
# fat + prow --> fat
# fat + prow --> sqr
# fat + prow --> tall
def base_fat_p_row_xxx(self, p):
a, q, r, u = self.generate('fat', which='row', p=p)
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, np.full(p, row, np.intp), u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_fat_p_row_fat(self):
# 7x12 + 3x12 = 10x12 --> stays fat
self.base_fat_p_row_xxx(3)
def test_fat_p_row_sqr(self):
# 7x12 + 5x12 = 12x12 --> becomes sqr
self.base_fat_p_row_xxx(5)
def test_fat_p_row_tall(self):
# 7x12 + 7x12 = 14x12 --> becomes tall
self.base_fat_p_row_xxx(7)
def test_fat_1_col(self):
a, q, r, u = self.generate('fat', which='col')
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, col, u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_fat_p_col(self):
# fat + cols --> fat always
a, q, r, u = self.generate('fat', which='col', p=3)
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, np.full(3, col, np.intp), u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_economic_1_row(self):
a, q, r, u = self.generate('tall', 'economic', 'row')
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row, overwrite_qru=False)
a1 = np.insert(a, row, u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_economic_p_row(self):
# tall + rows --> tall always
a, q, r, u = self.generate('tall', 'economic', 'row', 3)
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row, overwrite_qru=False)
a1 = np.insert(a, np.full(3, row, np.intp), u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_economic_1_col(self):
a, q, r, u = self.generate('tall', 'economic', which='col')
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u.copy(), col, 'col', overwrite_qru=False)
a1 = np.insert(a, col, u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_economic_1_col_bad_update(self):
# When the column to be added lies in the span of Q, the update is
# not meaningful. This is detected, and a LinAlgError is issued.
q = np.eye(5, 3, dtype=self.dtype)
r = np.eye(3, dtype=self.dtype)
u = np.array([1, 0, 0, 0, 0], self.dtype)
assert_raises(linalg.LinAlgError, qr_insert, q, r, u, 0, 'col')
# for column adds to economic matrices there are three cases to test
# eco + pcol --> eco
# eco + pcol --> sqr
# eco + pcol --> fat
def base_economic_p_col_xxx(self, p):
a, q, r, u = self.generate('tall', 'economic', which='col', p=p)
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, np.full(p, col, np.intp), u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_economic_p_col_eco(self):
# 12x7 + 12x3 = 12x10 --> stays eco
self.base_economic_p_col_xxx(3)
def test_economic_p_col_sqr(self):
# 12x7 + 12x5 = 12x12 --> becomes sqr
self.base_economic_p_col_xxx(5)
def test_economic_p_col_fat(self):
# 12x7 + 12x7 = 12x14 --> becomes fat
self.base_economic_p_col_xxx(7)
def test_Mx1_1_row(self):
a, q, r, u = self.generate('Mx1', which='row')
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, row, u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_Mx1_p_row(self):
a, q, r, u = self.generate('Mx1', which='row', p=3)
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, np.full(3, row, np.intp), u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_Mx1_1_col(self):
a, q, r, u = self.generate('Mx1', which='col')
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, col, u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_Mx1_p_col(self):
a, q, r, u = self.generate('Mx1', which='col', p=3)
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, np.full(3, col, np.intp), u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_Mx1_economic_1_row(self):
a, q, r, u = self.generate('Mx1', 'economic', 'row')
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, row, u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_Mx1_economic_p_row(self):
a, q, r, u = self.generate('Mx1', 'economic', 'row', 3)
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, np.full(3, row, np.intp), u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_Mx1_economic_1_col(self):
a, q, r, u = self.generate('Mx1', 'economic', 'col')
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, col, u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_Mx1_economic_p_col(self):
a, q, r, u = self.generate('Mx1', 'economic', 'col', 3)
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, np.full(3, col, np.intp), u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_1xN_1_row(self):
a, q, r, u = self.generate('1xN', which='row')
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, row, u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1xN_p_row(self):
a, q, r, u = self.generate('1xN', which='row', p=3)
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, np.full(3, row, np.intp), u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1xN_1_col(self):
a, q, r, u = self.generate('1xN', which='col')
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, col, u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1xN_p_col(self):
a, q, r, u = self.generate('1xN', which='col', p=3)
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, np.full(3, col, np.intp), u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1x1_1_row(self):
a, q, r, u = self.generate('1x1', which='row')
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, row, u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1x1_p_row(self):
a, q, r, u = self.generate('1x1', which='row', p=3)
for row in range(r.shape[0] + 1):
q1, r1 = qr_insert(q, r, u, row)
a1 = np.insert(a, np.full(3, row, np.intp), u, 0)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1x1_1_col(self):
a, q, r, u = self.generate('1x1', which='col')
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, col, u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1x1_p_col(self):
a, q, r, u = self.generate('1x1', which='col', p=3)
for col in range(r.shape[1] + 1):
q1, r1 = qr_insert(q, r, u, col, 'col', overwrite_qru=False)
a1 = np.insert(a, np.full(3, col, np.intp), u, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1x1_1_scalar(self):
a, q, r, u = self.generate('1x1', which='row')
assert_raises(ValueError, qr_insert, q[0, 0], r, u, 0, 'row')
assert_raises(ValueError, qr_insert, q, r[0, 0], u, 0, 'row')
assert_raises(ValueError, qr_insert, q, r, u[0], 0, 'row')
assert_raises(ValueError, qr_insert, q[0, 0], r, u, 0, 'col')
assert_raises(ValueError, qr_insert, q, r[0, 0], u, 0, 'col')
assert_raises(ValueError, qr_insert, q, r, u[0], 0, 'col')
def base_non_simple_strides(self, adjust_strides, k, p, which):
for type in ['sqr', 'tall', 'fat']:
a, q0, r0, u0 = self.generate(type, which=which, p=p)
qs, rs, us = adjust_strides((q0, r0, u0))
if p == 1:
ai = np.insert(a, k, u0, 0 if which == 'row' else 1)
else:
ai = np.insert(a, np.full(p, k, np.intp),
u0 if which == 'row' else u0,
0 if which == 'row' else 1)
# for each variable, q, r, u we try with it strided and
# overwrite=False. Then we try with overwrite=True. Nothing
# is checked to see if it can be overwritten, since only
# F ordered Q can be overwritten when adding columns.
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
q1, r1 = qr_insert(qs, r, u, k, which, overwrite_qru=False)
check_qr(q1, r1, ai, self.rtol, self.atol)
q1o, r1o = qr_insert(qs, r, u, k, which, overwrite_qru=True)
check_qr(q1o, r1o, ai, self.rtol, self.atol)
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
q2, r2 = qr_insert(q, rs, u, k, which, overwrite_qru=False)
check_qr(q2, r2, ai, self.rtol, self.atol)
q2o, r2o = qr_insert(q, rs, u, k, which, overwrite_qru=True)
check_qr(q2o, r2o, ai, self.rtol, self.atol)
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
q3, r3 = qr_insert(q, r, us, k, which, overwrite_qru=False)
check_qr(q3, r3, ai, self.rtol, self.atol)
q3o, r3o = qr_insert(q, r, us, k, which, overwrite_qru=True)
check_qr(q3o, r3o, ai, self.rtol, self.atol)
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
# since some of these were consumed above
qs, rs, us = adjust_strides((q, r, u))
q5, r5 = qr_insert(qs, rs, us, k, which, overwrite_qru=False)
check_qr(q5, r5, ai, self.rtol, self.atol)
q5o, r5o = qr_insert(qs, rs, us, k, which, overwrite_qru=True)
check_qr(q5o, r5o, ai, self.rtol, self.atol)
def test_non_unit_strides_1_row(self):
self.base_non_simple_strides(make_strided, 0, 1, 'row')
def test_non_unit_strides_p_row(self):
self.base_non_simple_strides(make_strided, 0, 3, 'row')
def test_non_unit_strides_1_col(self):
self.base_non_simple_strides(make_strided, 0, 1, 'col')
def test_non_unit_strides_p_col(self):
self.base_non_simple_strides(make_strided, 0, 3, 'col')
def test_neg_strides_1_row(self):
self.base_non_simple_strides(negate_strides, 0, 1, 'row')
def test_neg_strides_p_row(self):
self.base_non_simple_strides(negate_strides, 0, 3, 'row')
def test_neg_strides_1_col(self):
self.base_non_simple_strides(negate_strides, 0, 1, 'col')
def test_neg_strides_p_col(self):
self.base_non_simple_strides(negate_strides, 0, 3, 'col')
def test_non_itemsize_strides_1_row(self):
self.base_non_simple_strides(nonitemsize_strides, 0, 1, 'row')
def test_non_itemsize_strides_p_row(self):
self.base_non_simple_strides(nonitemsize_strides, 0, 3, 'row')
def test_non_itemsize_strides_1_col(self):
self.base_non_simple_strides(nonitemsize_strides, 0, 1, 'col')
def test_non_itemsize_strides_p_col(self):
self.base_non_simple_strides(nonitemsize_strides, 0, 3, 'col')
def test_non_native_byte_order_1_row(self):
self.base_non_simple_strides(make_nonnative, 0, 1, 'row')
def test_non_native_byte_order_p_row(self):
self.base_non_simple_strides(make_nonnative, 0, 3, 'row')
def test_non_native_byte_order_1_col(self):
self.base_non_simple_strides(make_nonnative, 0, 1, 'col')
def test_non_native_byte_order_p_col(self):
self.base_non_simple_strides(make_nonnative, 0, 3, 'col')
def test_overwrite_qu_rank_1(self):
# when inserting rows, the size of both Q and R change, so only
# column inserts can overwrite q. Only complex column inserts
# with C ordered Q overwrite u. Any contiguous Q is overwritten
# when inserting 1 column
a, q0, r, u, = self.generate('sqr', which='col', p=1)
q = q0.copy('C')
u0 = u.copy()
# don't overwrite
q1, r1 = qr_insert(q, r, u, 0, 'col', overwrite_qru=False)
a1 = np.insert(a, 0, u0, 1)
check_qr(q1, r1, a1, self.rtol, self.atol)
check_qr(q, r, a, self.rtol, self.atol)
# try overwriting
q2, r2 = qr_insert(q, r, u, 0, 'col', overwrite_qru=True)
check_qr(q2, r2, a1, self.rtol, self.atol)
# verify the overwriting
assert_allclose(q2, q, rtol=self.rtol, atol=self.atol)
assert_allclose(u, u0.conj(), self.rtol, self.atol)
# now try with a fortran ordered Q
qF = q0.copy('F')
u1 = u0.copy()
q3, r3 = qr_insert(qF, r, u1, 0, 'col', overwrite_qru=False)
check_qr(q3, r3, a1, self.rtol, self.atol)
check_qr(qF, r, a, self.rtol, self.atol)
# try overwriting
q4, r4 = qr_insert(qF, r, u1, 0, 'col', overwrite_qru=True)
check_qr(q4, r4, a1, self.rtol, self.atol)
assert_allclose(q4, qF, rtol=self.rtol, atol=self.atol)
def test_overwrite_qu_rank_p(self):
# when inserting rows, the size of both Q and R change, so only
# column inserts can potentially overwrite Q. In practice, only
# F ordered Q are overwritten with a rank p update.
a, q0, r, u, = self.generate('sqr', which='col', p=3)
q = q0.copy('F')
a1 = np.insert(a, np.zeros(3, np.intp), u, 1)
# don't overwrite
q1, r1 = qr_insert(q, r, u, 0, 'col', overwrite_qru=False)
check_qr(q1, r1, a1, self.rtol, self.atol)
check_qr(q, r, a, self.rtol, self.atol)
# try overwriting
q2, r2 = qr_insert(q, r, u, 0, 'col', overwrite_qru=True)
check_qr(q2, r2, a1, self.rtol, self.atol)
assert_allclose(q2, q, rtol=self.rtol, atol=self.atol)
def test_empty_inputs(self):
a, q, r, u = self.generate('sqr', which='row')
assert_raises(ValueError, qr_insert, np.array([]), r, u, 0, 'row')
assert_raises(ValueError, qr_insert, q, np.array([]), u, 0, 'row')
assert_raises(ValueError, qr_insert, q, r, np.array([]), 0, 'row')
assert_raises(ValueError, qr_insert, np.array([]), r, u, 0, 'col')
assert_raises(ValueError, qr_insert, q, np.array([]), u, 0, 'col')
assert_raises(ValueError, qr_insert, q, r, np.array([]), 0, 'col')
def test_mismatched_shapes(self):
a, q, r, u = self.generate('tall', which='row')
assert_raises(ValueError, qr_insert, q, r[1:], u, 0, 'row')
assert_raises(ValueError, qr_insert, q[:-2], r, u, 0, 'row')
assert_raises(ValueError, qr_insert, q, r, u[1:], 0, 'row')
assert_raises(ValueError, qr_insert, q, r[1:], u, 0, 'col')
assert_raises(ValueError, qr_insert, q[:-2], r, u, 0, 'col')
assert_raises(ValueError, qr_insert, q, r, u[1:], 0, 'col')
def test_unsupported_dtypes(self):
dts = ['int8', 'int16', 'int32', 'int64',
'uint8', 'uint16', 'uint32', 'uint64',
'float16', 'longdouble', 'longcomplex',
'bool']
a, q0, r0, u0 = self.generate('sqr', which='row')
for dtype in dts:
q = q0.real.astype(dtype)
r = r0.real.astype(dtype)
u = u0.real.astype(dtype)
assert_raises(ValueError, qr_insert, q, r0, u0, 0, 'row')
assert_raises(ValueError, qr_insert, q, r0, u0, 0, 'col')
assert_raises(ValueError, qr_insert, q0, r, u0, 0, 'row')
assert_raises(ValueError, qr_insert, q0, r, u0, 0, 'col')
assert_raises(ValueError, qr_insert, q0, r0, u, 0, 'row')
assert_raises(ValueError, qr_insert, q0, r0, u, 0, 'col')
def test_check_finite(self):
a0, q0, r0, u0 = self.generate('sqr', which='row', p=3)
q = q0.copy('F')
q[1,1] = np.nan
assert_raises(ValueError, qr_insert, q, r0, u0[:,0], 0, 'row')
assert_raises(ValueError, qr_insert, q, r0, u0, 0, 'row')
assert_raises(ValueError, qr_insert, q, r0, u0[:,0], 0, 'col')
assert_raises(ValueError, qr_insert, q, r0, u0, 0, 'col')
r = r0.copy('F')
r[1,1] = np.nan
assert_raises(ValueError, qr_insert, q0, r, u0[:,0], 0, 'row')
assert_raises(ValueError, qr_insert, q0, r, u0, 0, 'row')
assert_raises(ValueError, qr_insert, q0, r, u0[:,0], 0, 'col')
assert_raises(ValueError, qr_insert, q0, r, u0, 0, 'col')
u = u0.copy('F')
u[0,0] = np.nan
assert_raises(ValueError, qr_insert, q0, r0, u[:,0], 0, 'row')
assert_raises(ValueError, qr_insert, q0, r0, u, 0, 'row')
assert_raises(ValueError, qr_insert, q0, r0, u[:,0], 0, 'col')
assert_raises(ValueError, qr_insert, q0, r0, u, 0, 'col')
class TestQRinsert_f(BaseQRinsert):
dtype = np.dtype('f')
class TestQRinsert_F(BaseQRinsert):
dtype = np.dtype('F')
class TestQRinsert_d(BaseQRinsert):
dtype = np.dtype('d')
class TestQRinsert_D(BaseQRinsert):
dtype = np.dtype('D')
class BaseQRupdate(BaseQRdeltas):
def generate(self, type, mode='full', p=1):
a, q, r = super().generate(type, mode)
# super call set the seed...
if p == 1:
u = np.random.random(q.shape[0])
v = np.random.random(r.shape[1])
else:
u = np.random.random((q.shape[0], p))
v = np.random.random((r.shape[1], p))
if np.iscomplexobj(self.dtype.type(1)):
b = np.random.random(u.shape)
u = u + 1j * b
c = np.random.random(v.shape)
v = v + 1j * c
u = u.astype(self.dtype)
v = v.astype(self.dtype)
return a, q, r, u, v
def test_sqr_rank_1(self):
a, q, r, u, v = self.generate('sqr')
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.outer(u, v.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_sqr_rank_p(self):
# test ndim = 2, rank 1 updates here too
for p in [1, 2, 3, 5]:
a, q, r, u, v = self.generate('sqr', p=p)
if p == 1:
u = u.reshape(u.size, 1)
v = v.reshape(v.size, 1)
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.dot(u, v.T.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_rank_1(self):
a, q, r, u, v = self.generate('tall')
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.outer(u, v.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_tall_rank_p(self):
for p in [1, 2, 3, 5]:
a, q, r, u, v = self.generate('tall', p=p)
if p == 1:
u = u.reshape(u.size, 1)
v = v.reshape(v.size, 1)
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.dot(u, v.T.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_fat_rank_1(self):
a, q, r, u, v = self.generate('fat')
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.outer(u, v.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_fat_rank_p(self):
for p in [1, 2, 3, 5]:
a, q, r, u, v = self.generate('fat', p=p)
if p == 1:
u = u.reshape(u.size, 1)
v = v.reshape(v.size, 1)
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.dot(u, v.T.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_economic_rank_1(self):
a, q, r, u, v = self.generate('tall', 'economic')
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.outer(u, v.conj())
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_economic_rank_p(self):
for p in [1, 2, 3, 5]:
a, q, r, u, v = self.generate('tall', 'economic', p)
if p == 1:
u = u.reshape(u.size, 1)
v = v.reshape(v.size, 1)
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.dot(u, v.T.conj())
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_Mx1_rank_1(self):
a, q, r, u, v = self.generate('Mx1')
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.outer(u, v.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_Mx1_rank_p(self):
# when M or N == 1, only a rank 1 update is allowed. This isn't
# fundamental limitation, but the code does not support it.
a, q, r, u, v = self.generate('Mx1', p=1)
u = u.reshape(u.size, 1)
v = v.reshape(v.size, 1)
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.dot(u, v.T.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_Mx1_economic_rank_1(self):
a, q, r, u, v = self.generate('Mx1', 'economic')
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.outer(u, v.conj())
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_Mx1_economic_rank_p(self):
# when M or N == 1, only a rank 1 update is allowed. This isn't
# fundamental limitation, but the code does not support it.
a, q, r, u, v = self.generate('Mx1', 'economic', p=1)
u = u.reshape(u.size, 1)
v = v.reshape(v.size, 1)
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.dot(u, v.T.conj())
check_qr(q1, r1, a1, self.rtol, self.atol, False)
def test_1xN_rank_1(self):
a, q, r, u, v = self.generate('1xN')
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.outer(u, v.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1xN_rank_p(self):
# when M or N == 1, only a rank 1 update is allowed. This isn't
# fundamental limitation, but the code does not support it.
a, q, r, u, v = self.generate('1xN', p=1)
u = u.reshape(u.size, 1)
v = v.reshape(v.size, 1)
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.dot(u, v.T.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1x1_rank_1(self):
a, q, r, u, v = self.generate('1x1')
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.outer(u, v.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1x1_rank_p(self):
# when M or N == 1, only a rank 1 update is allowed. This isn't
# fundamental limitation, but the code does not support it.
a, q, r, u, v = self.generate('1x1', p=1)
u = u.reshape(u.size, 1)
v = v.reshape(v.size, 1)
q1, r1 = qr_update(q, r, u, v, False)
a1 = a + np.dot(u, v.T.conj())
check_qr(q1, r1, a1, self.rtol, self.atol)
def test_1x1_rank_1_scalar(self):
a, q, r, u, v = self.generate('1x1')
assert_raises(ValueError, qr_update, q[0, 0], r, u, v)
assert_raises(ValueError, qr_update, q, r[0, 0], u, v)
assert_raises(ValueError, qr_update, q, r, u[0], v)
assert_raises(ValueError, qr_update, q, r, u, v[0])
def base_non_simple_strides(self, adjust_strides, mode, p, overwriteable):
assert_sqr = False if mode == 'economic' else True
for type in ['sqr', 'tall', 'fat']:
a, q0, r0, u0, v0 = self.generate(type, mode, p)
qs, rs, us, vs = adjust_strides((q0, r0, u0, v0))
if p == 1:
aup = a + np.outer(u0, v0.conj())
else:
aup = a + np.dot(u0, v0.T.conj())
# for each variable, q, r, u, v we try with it strided and
# overwrite=False. Then we try with overwrite=True, and make
# sure that if p == 1, r and v are still overwritten.
# a strided q and u must always be copied.
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
v = v0.copy('C')
q1, r1 = qr_update(qs, r, u, v, False)
check_qr(q1, r1, aup, self.rtol, self.atol, assert_sqr)
q1o, r1o = qr_update(qs, r, u, v, True)
check_qr(q1o, r1o, aup, self.rtol, self.atol, assert_sqr)
if overwriteable:
assert_allclose(r1o, r, rtol=self.rtol, atol=self.atol)
assert_allclose(v, v0.conj(), rtol=self.rtol, atol=self.atol)
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
v = v0.copy('C')
q2, r2 = qr_update(q, rs, u, v, False)
check_qr(q2, r2, aup, self.rtol, self.atol, assert_sqr)
q2o, r2o = qr_update(q, rs, u, v, True)
check_qr(q2o, r2o, aup, self.rtol, self.atol, assert_sqr)
if overwriteable:
assert_allclose(r2o, rs, rtol=self.rtol, atol=self.atol)
assert_allclose(v, v0.conj(), rtol=self.rtol, atol=self.atol)
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
v = v0.copy('C')
q3, r3 = qr_update(q, r, us, v, False)
check_qr(q3, r3, aup, self.rtol, self.atol, assert_sqr)
q3o, r3o = qr_update(q, r, us, v, True)
check_qr(q3o, r3o, aup, self.rtol, self.atol, assert_sqr)
if overwriteable:
assert_allclose(r3o, r, rtol=self.rtol, atol=self.atol)
assert_allclose(v, v0.conj(), rtol=self.rtol, atol=self.atol)
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
v = v0.copy('C')
q4, r4 = qr_update(q, r, u, vs, False)
check_qr(q4, r4, aup, self.rtol, self.atol, assert_sqr)
q4o, r4o = qr_update(q, r, u, vs, True)
check_qr(q4o, r4o, aup, self.rtol, self.atol, assert_sqr)
if overwriteable:
assert_allclose(r4o, r, rtol=self.rtol, atol=self.atol)
assert_allclose(vs, v0.conj(), rtol=self.rtol, atol=self.atol)
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
v = v0.copy('C')
# since some of these were consumed above
qs, rs, us, vs = adjust_strides((q, r, u, v))
q5, r5 = qr_update(qs, rs, us, vs, False)
check_qr(q5, r5, aup, self.rtol, self.atol, assert_sqr)
q5o, r5o = qr_update(qs, rs, us, vs, True)
check_qr(q5o, r5o, aup, self.rtol, self.atol, assert_sqr)
if overwriteable:
assert_allclose(r5o, rs, rtol=self.rtol, atol=self.atol)
assert_allclose(vs, v0.conj(), rtol=self.rtol, atol=self.atol)
def test_non_unit_strides_rank_1(self):
self.base_non_simple_strides(make_strided, 'full', 1, True)
def test_non_unit_strides_economic_rank_1(self):
self.base_non_simple_strides(make_strided, 'economic', 1, True)
def test_non_unit_strides_rank_p(self):
self.base_non_simple_strides(make_strided, 'full', 3, False)
def test_non_unit_strides_economic_rank_p(self):
self.base_non_simple_strides(make_strided, 'economic', 3, False)
def test_neg_strides_rank_1(self):
self.base_non_simple_strides(negate_strides, 'full', 1, False)
def test_neg_strides_economic_rank_1(self):
self.base_non_simple_strides(negate_strides, 'economic', 1, False)
def test_neg_strides_rank_p(self):
self.base_non_simple_strides(negate_strides, 'full', 3, False)
def test_neg_strides_economic_rank_p(self):
self.base_non_simple_strides(negate_strides, 'economic', 3, False)
def test_non_itemsize_strides_rank_1(self):
self.base_non_simple_strides(nonitemsize_strides, 'full', 1, False)
def test_non_itemsize_strides_economic_rank_1(self):
self.base_non_simple_strides(nonitemsize_strides, 'economic', 1, False)
def test_non_itemsize_strides_rank_p(self):
self.base_non_simple_strides(nonitemsize_strides, 'full', 3, False)
def test_non_itemsize_strides_economic_rank_p(self):
self.base_non_simple_strides(nonitemsize_strides, 'economic', 3, False)
def test_non_native_byte_order_rank_1(self):
self.base_non_simple_strides(make_nonnative, 'full', 1, False)
def test_non_native_byte_order_economic_rank_1(self):
self.base_non_simple_strides(make_nonnative, 'economic', 1, False)
def test_non_native_byte_order_rank_p(self):
self.base_non_simple_strides(make_nonnative, 'full', 3, False)
def test_non_native_byte_order_economic_rank_p(self):
self.base_non_simple_strides(make_nonnative, 'economic', 3, False)
def test_overwrite_qruv_rank_1(self):
# Any positive strided q, r, u, and v can be overwritten for a rank 1
# update, only checking C and F contiguous.
a, q0, r0, u0, v0 = self.generate('sqr')
a1 = a + np.outer(u0, v0.conj())
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
v = v0.copy('F')
# don't overwrite
q1, r1 = qr_update(q, r, u, v, False)
check_qr(q1, r1, a1, self.rtol, self.atol)
check_qr(q, r, a, self.rtol, self.atol)
q2, r2 = qr_update(q, r, u, v, True)
check_qr(q2, r2, a1, self.rtol, self.atol)
# verify the overwriting, no good way to check u and v.
assert_allclose(q2, q, rtol=self.rtol, atol=self.atol)
assert_allclose(r2, r, rtol=self.rtol, atol=self.atol)
q = q0.copy('C')
r = r0.copy('C')
u = u0.copy('C')
v = v0.copy('C')
q3, r3 = qr_update(q, r, u, v, True)
check_qr(q3, r3, a1, self.rtol, self.atol)
assert_allclose(q3, q, rtol=self.rtol, atol=self.atol)
assert_allclose(r3, r, rtol=self.rtol, atol=self.atol)
def test_overwrite_qruv_rank_1_economic(self):
# updating economic decompositions can overwrite any contigous r,
# and positively strided r and u. V is only ever read.
# only checking C and F contiguous.
a, q0, r0, u0, v0 = self.generate('tall', 'economic')
a1 = a + np.outer(u0, v0.conj())
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
v = v0.copy('F')
# don't overwrite
q1, r1 = qr_update(q, r, u, v, False)
check_qr(q1, r1, a1, self.rtol, self.atol, False)
check_qr(q, r, a, self.rtol, self.atol, False)
q2, r2 = qr_update(q, r, u, v, True)
check_qr(q2, r2, a1, self.rtol, self.atol, False)
# verify the overwriting, no good way to check u and v.
assert_allclose(q2, q, rtol=self.rtol, atol=self.atol)
assert_allclose(r2, r, rtol=self.rtol, atol=self.atol)
q = q0.copy('C')
r = r0.copy('C')
u = u0.copy('C')
v = v0.copy('C')
q3, r3 = qr_update(q, r, u, v, True)
check_qr(q3, r3, a1, self.rtol, self.atol, False)
assert_allclose(q3, q, rtol=self.rtol, atol=self.atol)
assert_allclose(r3, r, rtol=self.rtol, atol=self.atol)
def test_overwrite_qruv_rank_p(self):
# for rank p updates, q r must be F contiguous, v must be C (v.T --> F)
# and u can be C or F, but is only overwritten if Q is C and complex
a, q0, r0, u0, v0 = self.generate('sqr', p=3)
a1 = a + np.dot(u0, v0.T.conj())
q = q0.copy('F')
r = r0.copy('F')
u = u0.copy('F')
v = v0.copy('C')
# don't overwrite
q1, r1 = qr_update(q, r, u, v, False)
check_qr(q1, r1, a1, self.rtol, self.atol)
check_qr(q, r, a, self.rtol, self.atol)
q2, r2 = qr_update(q, r, u, v, True)
check_qr(q2, r2, a1, self.rtol, self.atol)
# verify the overwriting, no good way to check u and v.
assert_allclose(q2, q, rtol=self.rtol, atol=self.atol)
assert_allclose(r2, r, rtol=self.rtol, atol=self.atol)
def test_empty_inputs(self):
a, q, r, u, v = self.generate('tall')
assert_raises(ValueError, qr_update, np.array([]), r, u, v)
assert_raises(ValueError, qr_update, q, np.array([]), u, v)
assert_raises(ValueError, qr_update, q, r, np.array([]), v)
assert_raises(ValueError, qr_update, q, r, u, np.array([]))
def test_mismatched_shapes(self):
a, q, r, u, v = self.generate('tall')
assert_raises(ValueError, qr_update, q, r[1:], u, v)
assert_raises(ValueError, qr_update, q[:-2], r, u, v)
assert_raises(ValueError, qr_update, q, r, u[1:], v)
assert_raises(ValueError, qr_update, q, r, u, v[1:])
def test_unsupported_dtypes(self):
dts = ['int8', 'int16', 'int32', 'int64',
'uint8', 'uint16', 'uint32', 'uint64',
'float16', 'longdouble', 'longcomplex',
'bool']
a, q0, r0, u0, v0 = self.generate('tall')
for dtype in dts:
q = q0.real.astype(dtype)
r = r0.real.astype(dtype)
u = u0.real.astype(dtype)
v = v0.real.astype(dtype)
assert_raises(ValueError, qr_update, q, r0, u0, v0)
assert_raises(ValueError, qr_update, q0, r, u0, v0)
assert_raises(ValueError, qr_update, q0, r0, u, v0)
assert_raises(ValueError, qr_update, q0, r0, u0, v)
def test_integer_input(self):
q = np.arange(16).reshape(4, 4)
r = q.copy() # doesn't matter
u = q[:, 0].copy()
v = r[0, :].copy()
assert_raises(ValueError, qr_update, q, r, u, v)
def test_check_finite(self):
a0, q0, r0, u0, v0 = self.generate('tall', p=3)
q = q0.copy('F')
q[1,1] = np.nan
assert_raises(ValueError, qr_update, q, r0, u0[:,0], v0[:,0])
assert_raises(ValueError, qr_update, q, r0, u0, v0)
r = r0.copy('F')
r[1,1] = np.nan
assert_raises(ValueError, qr_update, q0, r, u0[:,0], v0[:,0])
assert_raises(ValueError, qr_update, q0, r, u0, v0)
u = u0.copy('F')
u[0,0] = np.nan
assert_raises(ValueError, qr_update, q0, r0, u[:,0], v0[:,0])
assert_raises(ValueError, qr_update, q0, r0, u, v0)
v = v0.copy('F')
v[0,0] = np.nan
assert_raises(ValueError, qr_update, q0, r0, u[:,0], v[:,0])
assert_raises(ValueError, qr_update, q0, r0, u, v)
def test_economic_check_finite(self):
a0, q0, r0, u0, v0 = self.generate('tall', mode='economic', p=3)
q = q0.copy('F')
q[1,1] = np.nan
assert_raises(ValueError, qr_update, q, r0, u0[:,0], v0[:,0])
assert_raises(ValueError, qr_update, q, r0, u0, v0)
r = r0.copy('F')
r[1,1] = np.nan
assert_raises(ValueError, qr_update, q0, r, u0[:,0], v0[:,0])
assert_raises(ValueError, qr_update, q0, r, u0, v0)
u = u0.copy('F')
u[0,0] = np.nan
assert_raises(ValueError, qr_update, q0, r0, u[:,0], v0[:,0])
assert_raises(ValueError, qr_update, q0, r0, u, v0)
v = v0.copy('F')
v[0,0] = np.nan
assert_raises(ValueError, qr_update, q0, r0, u[:,0], v[:,0])
assert_raises(ValueError, qr_update, q0, r0, u, v)
def test_u_exactly_in_span_q(self):
q = np.array([[0, 0], [0, 0], [1, 0], [0, 1]], self.dtype)
r = np.array([[1, 0], [0, 1]], self.dtype)
u = np.array([0, 0, 0, -1], self.dtype)
v = np.array([1, 2], self.dtype)
q1, r1 = qr_update(q, r, u, v)
a1 = np.dot(q, r) + np.outer(u, v.conj())
check_qr(q1, r1, a1, self.rtol, self.atol, False)
class TestQRupdate_f(BaseQRupdate):
dtype = np.dtype('f')
class TestQRupdate_F(BaseQRupdate):
dtype = np.dtype('F')
class TestQRupdate_d(BaseQRupdate):
dtype = np.dtype('d')
class TestQRupdate_D(BaseQRupdate):
dtype = np.dtype('D')
def test_form_qTu():
# We want to ensure that all of the code paths through this function are
# tested. Most of them should be hit with the rest of test suite, but
# explicit tests make clear precisely what is being tested.
#
# This function expects that Q is either C or F contiguous and square.
# Economic mode decompositions (Q is (M, N), M != N) do not go through this
# function. U may have any positive strides.
#
# Some of these test are duplicates, since contiguous 1d arrays are both C
# and F.
q_order = ['F', 'C']
q_shape = [(8, 8), ]
u_order = ['F', 'C', 'A'] # here A means is not F not C
u_shape = [1, 3]
dtype = ['f', 'd', 'F', 'D']
for qo, qs, uo, us, d in \
itertools.product(q_order, q_shape, u_order, u_shape, dtype):
if us == 1:
check_form_qTu(qo, qs, uo, us, 1, d)
check_form_qTu(qo, qs, uo, us, 2, d)
else:
check_form_qTu(qo, qs, uo, us, 2, d)
def check_form_qTu(q_order, q_shape, u_order, u_shape, u_ndim, dtype):
np.random.seed(47)
if u_shape == 1 and u_ndim == 1:
u_shape = (q_shape[0],)
else:
u_shape = (q_shape[0], u_shape)
dtype = np.dtype(dtype)
if dtype.char in 'fd':
q = np.random.random(q_shape)
u = np.random.random(u_shape)
elif dtype.char in 'FD':
q = np.random.random(q_shape) + 1j*np.random.random(q_shape)
u = np.random.random(u_shape) + 1j*np.random.random(u_shape)
else:
ValueError("form_qTu doesn't support this dtype")
q = np.require(q, dtype, q_order)
if u_order != 'A':
u = np.require(u, dtype, u_order)
else:
u, = make_strided((u.astype(dtype),))
rtol = 10.0 ** -(np.finfo(dtype).precision-2)
atol = 2*np.finfo(dtype).eps
expected = np.dot(q.T.conj(), u)
res = _decomp_update._form_qTu(q, u)
assert_allclose(res, expected, rtol=rtol, atol=atol)
|
bsd-3-clause
|
[
646,
7975,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
3131,
702,
63,
7520,
12,
702,
63,
1452,
199,
504,
4613,
492,
6534,
465,
702,
63,
3536,
199,
504,
7026,
492,
16727,
199,
646,
7026,
14,
10096,
423,
271,
863,
63,
873,
465,
485,
271,
863,
63,
873,
199,
504,
7026,
14,
10096,
423,
271,
863,
63,
873,
492,
29757,
63,
1807,
12,
29757,
63,
873,
12,
29757,
63,
3176,
199,
199,
318,
702,
63,
3248,
695,
8,
65,
12,
10561,
29,
403,
12,
9543,
29,
403,
12,
702,
63,
3526,
82,
29,
549,
304,
272,
340,
10561,
365,
488,
26,
267,
10561,
275,
1616,
14,
16,
1011,
24953,
1590,
14,
23087,
8,
65,
14,
2271,
680,
6833,
13,
18,
9,
272,
340,
9543,
365,
488,
26,
267,
9543,
275,
1616,
10,
1590,
14,
23087,
8,
65,
14,
2271,
680,
8277,
339,
340,
702,
63,
3526,
82,
26,
267,
702,
2531,
65,
14,
1392,
59,
16,
61,
508,
282,
14,
1392,
59,
17,
467,
283,
3248,
695,
12627,
1471,
506,
12386,
358,
272,
282,
22620,
275,
980,
14,
3287,
8,
65,
14,
52,
14,
14765,
1062,
282,
9,
272,
702,
63,
7520,
8,
65,
22620,
12,
980,
14,
15240,
8,
65,
14,
1392,
59,
17,
2522,
10561,
29,
23565,
12,
9543,
29,
24504,
9,
199,
199,
318,
702,
63,
4142,
63,
599,
8,
65,
12,
10561,
29,
403,
12,
9543,
29,
403,
304,
272,
340,
10561,
365,
488,
26,
267,
10561,
275,
1616,
14,
16,
1011,
24953,
1590,
14,
23087,
8,
65,
14,
2271,
680,
6833,
13,
18,
9,
272,
340,
9543,
365,
488,
26,
267,
9543,
275,
499,
10,
1590,
14,
23087,
8,
65,
14,
2271,
680,
8277,
272,
3656,
275,
980,
14,
599,
8,
65,
14,
1392,
59,
16,
467,
282,
14,
1392,
59,
17,
467,
446,
17,
12,
980,
14,
2245,
4602,
272,
702,
63,
7520,
8,
65,
59,
2629,
467,
378,
14,
16,
12,
10561,
29,
23565,
12,
9543,
29,
24504,
9,
199,
199,
318,
1104,
63,
16596,
8,
81,
12,
519,
12,
282,
12,
10561,
12,
9543,
12,
702,
63,
3526,
82,
29,
549,
304,
272,
702,
63,
3248,
695,
8,
81,
12,
10561,
12,
9543,
12,
702,
63,
3526,
82,
9,
272,
702,
63,
4142,
63,
599,
8,
82,
12,
10561,
12,
9543,
9,
272,
702,
63,
7520,
8,
81,
14,
3287,
8,
82,
395,
282,
12,
10561,
29,
23565,
12,
9543,
29,
24504,
9,
199,
199,
318,
1852,
63,
816,
770,
8,
285,
2393,
304,
272,
11883,
275,
3842,
19,
12,
1520,
395,
334,
18,
12,
499,
395,
334,
19,
12,
841,
395,
334,
20,
12,
499,
395,
334,
21,
12,
841,
395,
334,
18,
12,
650,
395,
334,
18,
12,
413,
395,
334,
20,
12,
959,
1874,
272,
1022,
988,
275,
822,
8,
16759,
9,
272,
1022,
275,
378,
272,
2203,
275,
942,
272,
367,
282,
315,
601,
2393,
26,
267,
340,
282,
14,
8322,
508,
413,
26,
288,
308,
275,
11883,
59,
75,
450,
1022,
988,
61,
288,
1022,
847,
413,
288,
1300,
275,
980,
14,
4250,
8,
83,
59,
16,
3672,
65,
14,
1392,
59,
16,
2807,
83,
59,
17,
467,
282,
14,
2271,
9,
288,
2455,
275,
1300,
59,
83,
59,
17,
61,
447,
83,
59,
16,
2677,
288,
2455,
59,
18737,
275,
282,
267,
916,
282,
14,
8322,
508,
499,
26,
288,
308,
275,
11883,
59,
75,
450,
1022,
988,
61,
288,
307,
275,
11883,
7528,
75,
11,
17,
9,
450,
1022,
988,
61,
288,
1022,
847,
499,
288,
1300,
275,
980,
14,
4250,
1332,
83,
59,
16,
3672,
65,
14,
1392,
59,
16,
2807,
83,
59,
17,
467,
307,
59,
16,
3672,
65,
14,
1392,
59,
17,
2807,
84,
59,
17,
2522,
1169,
282,
14,
2271,
9,
288,
2455,
275,
1300,
59,
83,
59,
17,
61,
447,
83,
59,
16,
467,
307,
59,
17,
61,
447,
84,
59,
16,
2677,
288,
2455,
59,
18737,
275,
282,
267,
587,
26,
288,
746,
1722,
360,
1875,
63,
816,
770,
1454,
5419,
367,
17951,
275,
413,
503,
7,
2490,
283,
499,
6572,
358,
267,
2203,
14,
740,
8,
1345,
9,
272,
372,
2203,
199,
199,
318,
30112,
63,
16759,
8,
285,
2393,
304,
272,
2203,
275,
942,
272,
367,
282,
315,
601,
2393,
26,
267,
330,
275,
980,
14,
4250,
63,
2930,
8,
65,
9,
267,
340,
330,
14,
8322,
508,
499,
26,
288,
330,
275,
330,
14172,
17,
12,
3800,
13,
17,
61,
267,
916,
330,
14,
8322,
508,
413,
26,
288,
330,
275,
330,
14172,
17,
61,
267,
587,
26,
288,
746,
1722,
360,
28901,
63,
16759,
1454,
5419,
367,
17951,
275,
413,
503,
7,
2490,
283,
499,
6572,
358,
267,
330,
59,
18737,
275,
282,
267,
2203,
14,
740,
8,
66,
9,
272,
372,
2203,
199,
199,
318,
2222,
21210,
63,
16759,
8,
285,
2393,
304,
272,
734,
275,
942,
272,
367,
282,
315,
601,
2393,
26,
267,
282,
63,
2271,
275,
282,
14,
2271,
267,
330,
275,
980,
14,
4250,
8,
65,
14,
1392,
12,
4274,
65,
297,
282,
63,
2271,
395,
661,
17941,
297,
283,
51,
17,
2023,
267,
286,
275,
330,
14,
362,
698,
8,
65,
63,
2271,
9,
267,
286,
59,
18737,
275,
282,
267,
734,
14,
740,
8,
67,
9,
272,
372,
734,
421,
199,
318,
1852,
63,
2865,
6106,
8,
285,
2393,
304,
272,
372,
359,
65,
14,
6041,
8,
65,
14,
2271,
14,
1222,
19415,
1012,
367,
282,
315,
601,
2393,
61,
421,
199,
533,
3523,
26779,
25446,
26,
272,
347,
3272,
63,
765,
8,
277,
304,
267,
291,
14,
23565,
275,
1616,
14,
16,
1011,
24953,
1590,
14,
23087,
8,
277,
14,
2271,
680,
6833,
13,
18,
9,
267,
291,
14,
24504,
275,
1616,
627,
980,
14,
23087,
8,
277,
14,
2271,
680,
8277,
339,
347,
3550,
8,
277,
12,
730,
12,
818,
534,
2861,
735,
267,
980,
14,
2355,
14,
5176,
8,
1398,
16244,
9,
267,
2215,
275,
791,
3526,
82,
356,
334,
24,
12,
1695,
395,
283,
84,
452,
356,
334,
713,
12,
1520,
395,
283,
23156,
356,
334,
23,
12,
3144,
395,
326,
283,
45,
88,
17,
356,
334,
24,
12,
413,
395,
283,
17
] |
[
7975,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
3131,
702,
63,
7520,
12,
702,
63,
1452,
199,
504,
4613,
492,
6534,
465,
702,
63,
3536,
199,
504,
7026,
492,
16727,
199,
646,
7026,
14,
10096,
423,
271,
863,
63,
873,
465,
485,
271,
863,
63,
873,
199,
504,
7026,
14,
10096,
423,
271,
863,
63,
873,
492,
29757,
63,
1807,
12,
29757,
63,
873,
12,
29757,
63,
3176,
199,
199,
318,
702,
63,
3248,
695,
8,
65,
12,
10561,
29,
403,
12,
9543,
29,
403,
12,
702,
63,
3526,
82,
29,
549,
304,
272,
340,
10561,
365,
488,
26,
267,
10561,
275,
1616,
14,
16,
1011,
24953,
1590,
14,
23087,
8,
65,
14,
2271,
680,
6833,
13,
18,
9,
272,
340,
9543,
365,
488,
26,
267,
9543,
275,
1616,
10,
1590,
14,
23087,
8,
65,
14,
2271,
680,
8277,
339,
340,
702,
63,
3526,
82,
26,
267,
702,
2531,
65,
14,
1392,
59,
16,
61,
508,
282,
14,
1392,
59,
17,
467,
283,
3248,
695,
12627,
1471,
506,
12386,
358,
272,
282,
22620,
275,
980,
14,
3287,
8,
65,
14,
52,
14,
14765,
1062,
282,
9,
272,
702,
63,
7520,
8,
65,
22620,
12,
980,
14,
15240,
8,
65,
14,
1392,
59,
17,
2522,
10561,
29,
23565,
12,
9543,
29,
24504,
9,
199,
199,
318,
702,
63,
4142,
63,
599,
8,
65,
12,
10561,
29,
403,
12,
9543,
29,
403,
304,
272,
340,
10561,
365,
488,
26,
267,
10561,
275,
1616,
14,
16,
1011,
24953,
1590,
14,
23087,
8,
65,
14,
2271,
680,
6833,
13,
18,
9,
272,
340,
9543,
365,
488,
26,
267,
9543,
275,
499,
10,
1590,
14,
23087,
8,
65,
14,
2271,
680,
8277,
272,
3656,
275,
980,
14,
599,
8,
65,
14,
1392,
59,
16,
467,
282,
14,
1392,
59,
17,
467,
446,
17,
12,
980,
14,
2245,
4602,
272,
702,
63,
7520,
8,
65,
59,
2629,
467,
378,
14,
16,
12,
10561,
29,
23565,
12,
9543,
29,
24504,
9,
199,
199,
318,
1104,
63,
16596,
8,
81,
12,
519,
12,
282,
12,
10561,
12,
9543,
12,
702,
63,
3526,
82,
29,
549,
304,
272,
702,
63,
3248,
695,
8,
81,
12,
10561,
12,
9543,
12,
702,
63,
3526,
82,
9,
272,
702,
63,
4142,
63,
599,
8,
82,
12,
10561,
12,
9543,
9,
272,
702,
63,
7520,
8,
81,
14,
3287,
8,
82,
395,
282,
12,
10561,
29,
23565,
12,
9543,
29,
24504,
9,
199,
199,
318,
1852,
63,
816,
770,
8,
285,
2393,
304,
272,
11883,
275,
3842,
19,
12,
1520,
395,
334,
18,
12,
499,
395,
334,
19,
12,
841,
395,
334,
20,
12,
499,
395,
334,
21,
12,
841,
395,
334,
18,
12,
650,
395,
334,
18,
12,
413,
395,
334,
20,
12,
959,
1874,
272,
1022,
988,
275,
822,
8,
16759,
9,
272,
1022,
275,
378,
272,
2203,
275,
942,
272,
367,
282,
315,
601,
2393,
26,
267,
340,
282,
14,
8322,
508,
413,
26,
288,
308,
275,
11883,
59,
75,
450,
1022,
988,
61,
288,
1022,
847,
413,
288,
1300,
275,
980,
14,
4250,
8,
83,
59,
16,
3672,
65,
14,
1392,
59,
16,
2807,
83,
59,
17,
467,
282,
14,
2271,
9,
288,
2455,
275,
1300,
59,
83,
59,
17,
61,
447,
83,
59,
16,
2677,
288,
2455,
59,
18737,
275,
282,
267,
916,
282,
14,
8322,
508,
499,
26,
288,
308,
275,
11883,
59,
75,
450,
1022,
988,
61,
288,
307,
275,
11883,
7528,
75,
11,
17,
9,
450,
1022,
988,
61,
288,
1022,
847,
499,
288,
1300,
275,
980,
14,
4250,
1332,
83,
59,
16,
3672,
65,
14,
1392,
59,
16,
2807,
83,
59,
17,
467,
307,
59,
16,
3672,
65,
14,
1392,
59,
17,
2807,
84,
59,
17,
2522,
1169,
282,
14,
2271,
9,
288,
2455,
275,
1300,
59,
83,
59,
17,
61,
447,
83,
59,
16,
467,
307,
59,
17,
61,
447,
84,
59,
16,
2677,
288,
2455,
59,
18737,
275,
282,
267,
587,
26,
288,
746,
1722,
360,
1875,
63,
816,
770,
1454,
5419,
367,
17951,
275,
413,
503,
7,
2490,
283,
499,
6572,
358,
267,
2203,
14,
740,
8,
1345,
9,
272,
372,
2203,
199,
199,
318,
30112,
63,
16759,
8,
285,
2393,
304,
272,
2203,
275,
942,
272,
367,
282,
315,
601,
2393,
26,
267,
330,
275,
980,
14,
4250,
63,
2930,
8,
65,
9,
267,
340,
330,
14,
8322,
508,
499,
26,
288,
330,
275,
330,
14172,
17,
12,
3800,
13,
17,
61,
267,
916,
330,
14,
8322,
508,
413,
26,
288,
330,
275,
330,
14172,
17,
61,
267,
587,
26,
288,
746,
1722,
360,
28901,
63,
16759,
1454,
5419,
367,
17951,
275,
413,
503,
7,
2490,
283,
499,
6572,
358,
267,
330,
59,
18737,
275,
282,
267,
2203,
14,
740,
8,
66,
9,
272,
372,
2203,
199,
199,
318,
2222,
21210,
63,
16759,
8,
285,
2393,
304,
272,
734,
275,
942,
272,
367,
282,
315,
601,
2393,
26,
267,
282,
63,
2271,
275,
282,
14,
2271,
267,
330,
275,
980,
14,
4250,
8,
65,
14,
1392,
12,
4274,
65,
297,
282,
63,
2271,
395,
661,
17941,
297,
283,
51,
17,
2023,
267,
286,
275,
330,
14,
362,
698,
8,
65,
63,
2271,
9,
267,
286,
59,
18737,
275,
282,
267,
734,
14,
740,
8,
67,
9,
272,
372,
734,
421,
199,
318,
1852,
63,
2865,
6106,
8,
285,
2393,
304,
272,
372,
359,
65,
14,
6041,
8,
65,
14,
2271,
14,
1222,
19415,
1012,
367,
282,
315,
601,
2393,
61,
421,
199,
533,
3523,
26779,
25446,
26,
272,
347,
3272,
63,
765,
8,
277,
304,
267,
291,
14,
23565,
275,
1616,
14,
16,
1011,
24953,
1590,
14,
23087,
8,
277,
14,
2271,
680,
6833,
13,
18,
9,
267,
291,
14,
24504,
275,
1616,
627,
980,
14,
23087,
8,
277,
14,
2271,
680,
8277,
339,
347,
3550,
8,
277,
12,
730,
12,
818,
534,
2861,
735,
267,
980,
14,
2355,
14,
5176,
8,
1398,
16244,
9,
267,
2215,
275,
791,
3526,
82,
356,
334,
24,
12,
1695,
395,
283,
84,
452,
356,
334,
713,
12,
1520,
395,
283,
23156,
356,
334,
23,
12,
3144,
395,
326,
283,
45,
88,
17,
356,
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
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
CourseTalk/edx-platform
|
cms/djangoapps/contentstore/tests/utils.py
|
32
|
17927
|
'''
Utilities for contentstore tests
'''
import json
import textwrap
from mock import Mock
from django.conf import settings
from django.contrib.auth.models import User
from django.test.client import Client
from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation
from contentstore.utils import reverse_url
from student.models import Registration
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
from xmodule.contentstore.django import contentstore
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.inheritance import own_metadata
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.xml_importer import import_course_from_xml
from xmodule.modulestore.tests.utils import ProceduralCourseTestMixin
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
def parse_json(response):
"""Parse response, which is assumed to be json"""
return json.loads(response.content)
def user(email):
"""look up a user by email"""
return User.objects.get(email=email)
def registration(email):
"""look up registration object by email"""
return Registration.objects.get(user__email=email)
class AjaxEnabledTestClient(Client):
"""
Convenience class to make testing easier.
"""
def ajax_post(self, path, data=None, content_type="application/json", **kwargs):
"""
Convenience method for client post which serializes the data into json and sets the accept type
to json
"""
if not isinstance(data, basestring):
data = json.dumps(data or {})
kwargs.setdefault("HTTP_X_REQUESTED_WITH", "XMLHttpRequest")
kwargs.setdefault("HTTP_ACCEPT", "application/json")
return self.post(path=path, data=data, content_type=content_type, **kwargs)
def get_html(self, path, data=None, follow=False, **extra):
"""
Convenience method for client.get which sets the accept type to html
"""
return self.get(path, data or {}, follow, HTTP_ACCEPT="text/html", **extra)
def get_json(self, path, data=None, follow=False, **extra):
"""
Convenience method for client.get which sets the accept type to json
"""
return self.get(path, data or {}, follow, HTTP_ACCEPT="application/json", **extra)
class CourseTestCase(ProceduralCourseTestMixin, ModuleStoreTestCase):
"""
Base class for Studio tests that require a logged in user and a course.
Also provides helper methods for manipulating and verifying the course.
"""
def setUp(self):
"""
These tests need a user in the DB so that the django Test Client can log them in.
The test user is created in the ModuleStoreTestCase setUp method.
They inherit from the ModuleStoreTestCase class so that the mongodb collection
will be cleared out before each test case execution and deleted
afterwards.
"""
self.user_password = super(CourseTestCase, self).setUp()
self.client = AjaxEnabledTestClient()
self.client.login(username=self.user.username, password=self.user_password)
self.course = CourseFactory.create()
def create_non_staff_authed_user_client(self, authenticate=True):
"""
Create a non-staff user, log them in (if authenticate=True), and return the client, user to use for testing.
"""
nonstaff, password = self.create_non_staff_user()
client = AjaxEnabledTestClient()
if authenticate:
client.login(username=nonstaff.username, password=password)
nonstaff.is_authenticated = lambda: authenticate
return client, nonstaff
def reload_course(self):
"""
Reloads the course object from the database
"""
self.course = self.store.get_course(self.course.id)
def save_course(self):
"""
Updates the course object in the database
"""
self.course.save()
self.store.update_item(self.course, self.user.id)
TEST_VERTICAL = 'vertical_test'
ORPHAN_DRAFT_VERTICAL = 'orphan_draft_vertical'
ORPHAN_DRAFT_HTML = 'orphan_draft_html'
PRIVATE_VERTICAL = 'a_private_vertical'
PUBLISHED_VERTICAL = 'a_published_vertical'
SEQUENTIAL = 'vertical_sequential'
DRAFT_HTML = 'draft_html'
DRAFT_VIDEO = 'draft_video'
LOCKED_ASSET_KEY = AssetLocation.from_deprecated_string('/c4x/edX/toy/asset/sample_static.txt')
def import_and_populate_course(self):
"""
Imports the test toy course and populates it with additional test data
"""
content_store = contentstore()
import_course_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'], static_content_store=content_store)
course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
# create an Orphan
# We had a bug where orphaned draft nodes caused export to fail. This is here to cover that case.
vertical = self.store.get_item(course_id.make_usage_key('vertical', self.TEST_VERTICAL), depth=1)
vertical.location = vertical.location.replace(name='no_references')
self.store.update_item(vertical, self.user.id, allow_not_found=True)
orphan_vertical = self.store.get_item(vertical.location)
self.assertEqual(orphan_vertical.location.name, 'no_references')
self.assertEqual(len(orphan_vertical.children), len(vertical.children))
# create an orphan vertical and html; we already don't try to import
# the orphaned vertical, but we should make sure we don't import
# the orphaned vertical's child html, too
orphan_draft_vertical = self.store.create_item(
self.user.id, course_id, 'vertical', self.ORPHAN_DRAFT_VERTICAL
)
orphan_draft_html = self.store.create_item(
self.user.id, course_id, 'html', self.ORPHAN_DRAFT_HTML
)
orphan_draft_vertical.children.append(orphan_draft_html.location)
self.store.update_item(orphan_draft_vertical, self.user.id)
# create a Draft vertical
vertical = self.store.get_item(course_id.make_usage_key('vertical', self.TEST_VERTICAL), depth=1)
draft_vertical = self.store.convert_to_draft(vertical.location, self.user.id)
self.assertTrue(self.store.has_published_version(draft_vertical))
# create a Private (draft only) vertical
private_vertical = self.store.create_item(self.user.id, course_id, 'vertical', self.PRIVATE_VERTICAL)
self.assertFalse(self.store.has_published_version(private_vertical))
# create a Published (no draft) vertical
public_vertical = self.store.create_item(self.user.id, course_id, 'vertical', self.PUBLISHED_VERTICAL)
public_vertical = self.store.publish(public_vertical.location, self.user.id)
self.assertTrue(self.store.has_published_version(public_vertical))
# add the new private and new public as children of the sequential
sequential = self.store.get_item(course_id.make_usage_key('sequential', self.SEQUENTIAL))
sequential.children.append(private_vertical.location)
sequential.children.append(public_vertical.location)
self.store.update_item(sequential, self.user.id)
# create an html and video component to make drafts:
draft_html = self.store.create_item(self.user.id, course_id, 'html', self.DRAFT_HTML)
draft_video = self.store.create_item(self.user.id, course_id, 'video', self.DRAFT_VIDEO)
# add them as children to the public_vertical
public_vertical.children.append(draft_html.location)
public_vertical.children.append(draft_video.location)
self.store.update_item(public_vertical, self.user.id)
# publish changes to vertical
self.store.publish(public_vertical.location, self.user.id)
# convert html/video to draft
self.store.convert_to_draft(draft_html.location, self.user.id)
self.store.convert_to_draft(draft_video.location, self.user.id)
# lock an asset
content_store.set_attr(self.LOCKED_ASSET_KEY, 'locked', True)
# create a non-portable link - should be rewritten in new courses
html_module = self.store.get_item(course_id.make_usage_key('html', 'nonportable'))
new_data = html_module.data = html_module.data.replace(
'/static/',
'/c4x/{0}/{1}/asset/'.format(course_id.org, course_id.course)
)
self.store.update_item(html_module, self.user.id)
html_module = self.store.get_item(html_module.location)
self.assertEqual(new_data, html_module.data)
return course_id
def check_populated_course(self, course_id):
"""
Verifies the content of the given course, per data that was populated in import_and_populate_course
"""
items = self.store.get_items(
course_id,
qualifiers={'category': 'vertical'},
revision=ModuleStoreEnum.RevisionOption.published_only
)
self.check_verticals(items)
def verify_item_publish_state(item, publish_state):
"""Verifies the publish state of the item is as expected."""
self.assertEqual(self.store.has_published_version(item), publish_state)
def get_and_verify_publish_state(item_type, item_name, publish_state):
"""
Gets the given item from the store and verifies the publish state
of the item is as expected.
"""
item = self.store.get_item(course_id.make_usage_key(item_type, item_name))
verify_item_publish_state(item, publish_state)
return item
# verify draft vertical has a published version with published children
vertical = get_and_verify_publish_state('vertical', self.TEST_VERTICAL, True)
for child in vertical.get_children():
verify_item_publish_state(child, True)
# verify that it has a draft too
self.assertTrue(getattr(vertical, "is_draft", False))
# make sure that we don't have a sequential that is in draft mode
sequential = get_and_verify_publish_state('sequential', self.SEQUENTIAL, True)
self.assertFalse(getattr(sequential, "is_draft", False))
# verify that we have the private vertical
private_vertical = get_and_verify_publish_state('vertical', self.PRIVATE_VERTICAL, False)
# verify that we have the public vertical
public_vertical = get_and_verify_publish_state('vertical', self.PUBLISHED_VERTICAL, True)
# verify that we have the draft html
draft_html = self.store.get_item(course_id.make_usage_key('html', self.DRAFT_HTML))
self.assertTrue(getattr(draft_html, 'is_draft', False))
# verify that we have the draft video
draft_video = self.store.get_item(course_id.make_usage_key('video', self.DRAFT_VIDEO))
self.assertTrue(getattr(draft_video, 'is_draft', False))
# verify verticals are children of sequential
for vert in [vertical, private_vertical, public_vertical]:
self.assertIn(vert.location, sequential.children)
# verify draft html is the child of the public vertical
self.assertIn(draft_html.location, public_vertical.children)
# verify draft video is the child of the public vertical
self.assertIn(draft_video.location, public_vertical.children)
# verify textbook exists
course = self.store.get_course(course_id)
self.assertGreater(len(course.textbooks), 0)
# verify asset attributes of locked asset key
self.assertAssetsEqual(self.LOCKED_ASSET_KEY, self.LOCKED_ASSET_KEY.course_key, course_id)
# verify non-portable links are rewritten
html_module = self.store.get_item(course_id.make_usage_key('html', 'nonportable'))
self.assertIn('/static/foo.jpg', html_module.data)
return course
def assertCoursesEqual(self, course1_id, course2_id):
"""
Verifies the content of the two given courses are equal
"""
course1_items = self.store.get_items(course1_id)
course2_items = self.store.get_items(course2_id)
self.assertGreater(len(course1_items), 0) # ensure it found content instead of [] == []
if len(course1_items) != len(course2_items):
course1_block_ids = set([item.location.block_id for item in course1_items])
course2_block_ids = set([item.location.block_id for item in course2_items])
raise AssertionError(
u"Course1 extra blocks: {}; course2 extra blocks: {}".format(
course1_block_ids - course2_block_ids, course2_block_ids - course1_block_ids
)
)
for course1_item in course1_items:
course1_item_loc = course1_item.location
course2_item_loc = course2_id.make_usage_key(course1_item_loc.block_type, course1_item_loc.block_id)
if course1_item_loc.block_type == 'course':
# mongo uses the run as the name, split uses 'course'
store = self.store._get_modulestore_for_courselike(course2_id) # pylint: disable=protected-access
new_name = 'course' if isinstance(store, SplitMongoModuleStore) else course2_item_loc.run
course2_item_loc = course2_item_loc.replace(name=new_name)
course2_item = self.store.get_item(course2_item_loc)
# compare published state
self.assertEqual(
self.store.has_published_version(course1_item),
self.store.has_published_version(course2_item)
)
# compare data
self.assertEqual(hasattr(course1_item, 'data'), hasattr(course2_item, 'data'))
if hasattr(course1_item, 'data'):
self.assertEqual(course1_item.data, course2_item.data)
# compare meta-data
self.assertEqual(own_metadata(course1_item), own_metadata(course2_item))
# compare children
self.assertEqual(course1_item.has_children, course2_item.has_children)
if course1_item.has_children:
expected_children = []
for course1_item_child in course1_item.children:
expected_children.append(
course2_id.make_usage_key(course1_item_child.block_type, course1_item_child.block_id)
)
self.assertEqual(expected_children, course2_item.children)
# compare assets
content_store = self.store.contentstore
course1_assets, count_course1_assets = content_store.get_all_content_for_course(course1_id)
_, count_course2_assets = content_store.get_all_content_for_course(course2_id)
self.assertEqual(count_course1_assets, count_course2_assets)
for asset in course1_assets:
asset_son = asset.get('content_son', asset['_id'])
self.assertAssetsEqual(asset_son, course1_id, course2_id)
def check_verticals(self, items):
""" Test getting the editing HTML for each vertical. """
# assert is here to make sure that the course being tested actually has verticals (units) to check.
self.assertGreater(len(items), 0, "Course has no verticals (units) to check")
for descriptor in items:
resp = self.client.get_html(get_url('container_handler', descriptor.location))
self.assertEqual(resp.status_code, 200)
def assertAssetsEqual(self, asset_son, course1_id, course2_id):
"""Verifies the asset of the given key has the same attributes in both given courses."""
content_store = contentstore()
category = asset_son.block_type if hasattr(asset_son, 'block_type') else asset_son['category']
filename = asset_son.block_id if hasattr(asset_son, 'block_id') else asset_son['name']
course1_asset_attrs = content_store.get_attrs(course1_id.make_asset_key(category, filename))
course2_asset_attrs = content_store.get_attrs(course2_id.make_asset_key(category, filename))
self.assertEqual(len(course1_asset_attrs), len(course2_asset_attrs))
for key, value in course1_asset_attrs.iteritems():
if key in ['_id', 'filename', 'uploadDate', 'content_son', 'thumbnail_location']:
pass
else:
self.assertEqual(value, course2_asset_attrs[key])
def mock_requests_get(*args, **kwargs):
"""
Returns mock responses for the youtube API.
"""
# pylint: disable=unused-argument
response_transcript_list = """
<transcript_list>
<track id="1" name="Custom" lang_code="en" />
<track id="0" name="Custom1" lang_code="en-GB"/>
</transcript_list>
"""
response_transcript = textwrap.dedent("""
<transcript>
<text start="100" dur="100">subs #1</text>
<text start="200" dur="40">subs #2</text>
<text start="240" dur="140">subs #3</text>
</transcript>
""")
if kwargs == {'params': {'lang': 'en', 'v': 'good_id_2'}}:
return Mock(status_code=200, text='')
elif kwargs == {'params': {'type': 'list', 'v': 'good_id_2'}}:
return Mock(status_code=200, text=response_transcript_list, content=response_transcript_list)
elif kwargs == {'params': {'lang': 'en', 'v': 'good_id_2', 'name': 'Custom'}}:
return Mock(status_code=200, text=response_transcript, content=response_transcript)
return Mock(status_code=404, text='')
def get_url(handler_name, key_value, key_name='usage_key_string', kwargs=None):
"""
Helper function for getting HTML for a page in Studio and checking that it does not error.
"""
return reverse_url(handler_name, key_name, key_value, kwargs)
|
agpl-3.0
|
[
2344,
199,
22905,
367,
23061,
2295,
199,
2344,
199,
646,
2022,
199,
646,
13390,
199,
504,
1683,
492,
4420,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
12,
25670,
6592,
199,
199,
504,
23061,
14,
1208,
492,
3837,
63,
633,
199,
504,
6474,
14,
992,
492,
20764,
199,
504,
9872,
14,
10012,
14,
1294,
63,
9217,
14,
1294,
492,
11740,
20393,
14389,
199,
504,
9872,
14,
28160,
14,
1176,
492,
23061,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
9872,
14,
10012,
14,
13136,
492,
5705,
63,
2343,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
504,
9872,
14,
10012,
14,
1652,
63,
12138,
492,
492,
63,
1972,
63,
504,
63,
1652,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1208,
492,
2165,
6867,
4889,
6979,
22060,
199,
199,
2864,
63,
3998,
63,
3022,
275,
2202,
14,
21637,
63,
2864,
63,
3998,
63,
5441,
421,
199,
318,
2198,
63,
1001,
8,
1310,
304,
272,
408,
4003,
1177,
12,
1314,
365,
10826,
370,
506,
2022,
624,
272,
372,
2022,
14,
3640,
8,
1310,
14,
1317,
9,
421,
199,
318,
922,
8,
2123,
304,
272,
408,
11660,
1536,
282,
922,
701,
3031,
624,
272,
372,
2876,
14,
1462,
14,
362,
8,
2123,
29,
2123,
9,
421,
199,
318,
10991,
8,
2123,
304,
272,
408,
11660,
1536,
10991,
909,
701,
3031,
624,
272,
372,
20764,
14,
1462,
14,
362,
8,
751,
363,
2123,
29,
2123,
9,
421,
199,
533,
437,
15863,
6589,
774,
3041,
8,
3041,
304,
272,
408,
272,
1448,
23329,
1021,
370,
1852,
5343,
14905,
14,
272,
408,
272,
347,
25930,
63,
1932,
8,
277,
12,
931,
12,
666,
29,
403,
12,
1564,
63,
466,
628,
3578,
15,
1001,
401,
1011,
958,
304,
267,
408,
267,
1448,
23329,
1083,
367,
1890,
2963,
1314,
3012,
6491,
314,
666,
1901,
2022,
436,
5951,
314,
4729,
730,
267,
370,
2022,
267,
408,
267,
340,
440,
1228,
8,
576,
12,
7116,
304,
288,
666,
275,
2022,
14,
4180,
8,
576,
503,
5009,
267,
2074,
14,
5486,
480,
2856,
63,
56,
63,
6780,
1149,
63,
9139,
401,
298,
4317,
10441,
531,
267,
2074,
14,
5486,
480,
2856,
63,
13089,
401,
298,
3578,
15,
1001,
531,
267,
372,
291,
14,
1932,
8,
515,
29,
515,
12,
666,
29,
576,
12,
1564,
63,
466,
29,
1317,
63,
466,
12,
1011,
958,
9,
339,
347,
664,
63,
1360,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2035,
29,
797,
12,
1011,
2911,
304,
267,
408,
267,
1448,
23329,
1083,
367,
1890,
14,
362,
1314,
5951,
314,
4729,
730,
370,
3517,
267,
408,
267,
372,
291,
14,
362,
8,
515,
12,
666,
503,
5479,
2035,
12,
3101,
63,
13089,
628,
505,
15,
1360,
401,
1011,
2911,
9,
339,
347,
664,
63,
1001,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2035,
29,
797,
12,
1011,
2911,
304,
267,
408,
267,
1448,
23329,
1083,
367,
1890,
14,
362,
1314,
5951,
314,
4729,
730,
370,
2022,
267,
408,
267,
372,
291,
14,
362,
8,
515,
12,
666,
503,
5479,
2035,
12,
3101,
63,
13089,
628,
3578,
15,
1001,
401,
1011,
2911,
9,
421,
199,
533,
5531,
1746,
8,
919,
6867,
4889,
6979,
22060,
12,
17996,
1746,
304,
272,
408,
272,
3523,
1021,
367,
13225,
2295,
626,
4409,
282,
10367,
315,
922,
436,
282,
2518,
14,
272,
6121,
6571,
5922,
3102,
367,
13335,
20529,
436,
31866,
314,
2518,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
408,
267,
5723,
2295,
1929,
282,
922,
315,
314,
6249,
880,
626,
314,
1639,
1379,
6810,
883,
943,
3062,
315,
14,
267,
710,
511,
922,
365,
2737,
315,
314,
17996,
1746,
3613,
1083,
14,
267,
9322,
8287,
687,
314,
17996,
1746,
1021,
880,
626,
314,
32315,
13152,
3245,
267,
911,
506,
20518,
734,
2544,
1924,
511,
1930,
6451,
436,
5463,
267,
26982,
14,
267,
408,
398,
291,
14,
751,
63,
2060,
275,
1613,
8,
6979,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
1258,
275,
437,
15863,
6589,
774,
3041,
342,
267,
291,
14,
1258,
14,
2886,
8,
2473,
29,
277,
14,
751,
14,
2473,
12,
2505,
29,
277,
14,
751,
63,
2060,
9,
398,
291,
14,
1972,
275,
17862,
14,
981,
342,
339,
347,
1218,
63,
2865,
63,
7018,
63,
1178,
379,
63,
751,
63,
1258,
8,
277,
12,
12895,
29,
549,
304,
267,
408,
267,
2790,
282,
2222,
13,
7018,
922,
12,
943,
3062,
315,
334,
692,
12895,
29,
549,
395,
436,
372,
314,
1890,
12,
922,
370,
675,
367,
5343,
14,
267,
408,
267,
2222,
7018,
12,
2505,
275,
291,
14,
981,
63,
2865,
63,
7018,
63,
751,
342,
398,
1890,
275,
437,
15863,
6589,
774,
3041,
342,
267,
340,
12895,
26,
288,
1890,
14,
2886,
8,
2473,
29,
2865,
7018,
14,
2473,
12,
2505,
29,
2060,
9,
267,
2222,
7018,
14,
374,
63,
12177,
275,
2400,
26,
12895,
267,
372,
1890,
12,
2222,
7018,
339,
347,
13101,
63,
1972,
8,
277,
304,
267,
408,
267,
799,
3640,
314,
2518,
909,
687,
314,
3050,
267,
408,
267,
291,
14,
1972,
275,
291,
14,
1617,
14,
362,
63,
1972,
8,
277,
14,
1972,
14,
344,
9,
339,
347,
3354,
63,
1972,
8,
277,
304,
267,
408,
267,
24663,
314,
2518,
909,
315,
314,
3050,
267,
408,
267,
291,
14,
1972,
14,
2117,
342,
267,
291,
14,
1617,
14,
873,
63,
1053,
8,
277,
14,
1972,
12,
291,
14,
751,
14,
344,
9,
339,
7393,
63,
22634,
275,
283,
7870,
63,
396,
7,
272,
1549,
9791,
879,
63,
36,
29650,
63,
22634,
275,
283,
22161,
63,
7185,
63,
7870,
7,
272,
1549,
9791,
879,
63,
36,
29650,
63,
4943,
275,
283,
22161,
63,
7185,
63,
1360,
7,
272,
28644,
1951,
63,
22634,
275,
283,
65,
63,
4239,
63,
7870,
7,
272,
18787,
44,
20450,
63,
22634,
275,
283,
65,
63,
8987,
63,
7870,
7,
272,
28130,
8246,
275,
283,
7870,
63,
16211,
7,
272,
577
] |
[
199,
22905,
367,
23061,
2295,
199,
2344,
199,
646,
2022,
199,
646,
13390,
199,
504,
1683,
492,
4420,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
12,
25670,
6592,
199,
199,
504,
23061,
14,
1208,
492,
3837,
63,
633,
199,
504,
6474,
14,
992,
492,
20764,
199,
504,
9872,
14,
10012,
14,
1294,
63,
9217,
14,
1294,
492,
11740,
20393,
14389,
199,
504,
9872,
14,
28160,
14,
1176,
492,
23061,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
9872,
14,
10012,
14,
13136,
492,
5705,
63,
2343,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
504,
9872,
14,
10012,
14,
1652,
63,
12138,
492,
492,
63,
1972,
63,
504,
63,
1652,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1208,
492,
2165,
6867,
4889,
6979,
22060,
199,
199,
2864,
63,
3998,
63,
3022,
275,
2202,
14,
21637,
63,
2864,
63,
3998,
63,
5441,
421,
199,
318,
2198,
63,
1001,
8,
1310,
304,
272,
408,
4003,
1177,
12,
1314,
365,
10826,
370,
506,
2022,
624,
272,
372,
2022,
14,
3640,
8,
1310,
14,
1317,
9,
421,
199,
318,
922,
8,
2123,
304,
272,
408,
11660,
1536,
282,
922,
701,
3031,
624,
272,
372,
2876,
14,
1462,
14,
362,
8,
2123,
29,
2123,
9,
421,
199,
318,
10991,
8,
2123,
304,
272,
408,
11660,
1536,
10991,
909,
701,
3031,
624,
272,
372,
20764,
14,
1462,
14,
362,
8,
751,
363,
2123,
29,
2123,
9,
421,
199,
533,
437,
15863,
6589,
774,
3041,
8,
3041,
304,
272,
408,
272,
1448,
23329,
1021,
370,
1852,
5343,
14905,
14,
272,
408,
272,
347,
25930,
63,
1932,
8,
277,
12,
931,
12,
666,
29,
403,
12,
1564,
63,
466,
628,
3578,
15,
1001,
401,
1011,
958,
304,
267,
408,
267,
1448,
23329,
1083,
367,
1890,
2963,
1314,
3012,
6491,
314,
666,
1901,
2022,
436,
5951,
314,
4729,
730,
267,
370,
2022,
267,
408,
267,
340,
440,
1228,
8,
576,
12,
7116,
304,
288,
666,
275,
2022,
14,
4180,
8,
576,
503,
5009,
267,
2074,
14,
5486,
480,
2856,
63,
56,
63,
6780,
1149,
63,
9139,
401,
298,
4317,
10441,
531,
267,
2074,
14,
5486,
480,
2856,
63,
13089,
401,
298,
3578,
15,
1001,
531,
267,
372,
291,
14,
1932,
8,
515,
29,
515,
12,
666,
29,
576,
12,
1564,
63,
466,
29,
1317,
63,
466,
12,
1011,
958,
9,
339,
347,
664,
63,
1360,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2035,
29,
797,
12,
1011,
2911,
304,
267,
408,
267,
1448,
23329,
1083,
367,
1890,
14,
362,
1314,
5951,
314,
4729,
730,
370,
3517,
267,
408,
267,
372,
291,
14,
362,
8,
515,
12,
666,
503,
5479,
2035,
12,
3101,
63,
13089,
628,
505,
15,
1360,
401,
1011,
2911,
9,
339,
347,
664,
63,
1001,
8,
277,
12,
931,
12,
666,
29,
403,
12,
2035,
29,
797,
12,
1011,
2911,
304,
267,
408,
267,
1448,
23329,
1083,
367,
1890,
14,
362,
1314,
5951,
314,
4729,
730,
370,
2022,
267,
408,
267,
372,
291,
14,
362,
8,
515,
12,
666,
503,
5479,
2035,
12,
3101,
63,
13089,
628,
3578,
15,
1001,
401,
1011,
2911,
9,
421,
199,
533,
5531,
1746,
8,
919,
6867,
4889,
6979,
22060,
12,
17996,
1746,
304,
272,
408,
272,
3523,
1021,
367,
13225,
2295,
626,
4409,
282,
10367,
315,
922,
436,
282,
2518,
14,
272,
6121,
6571,
5922,
3102,
367,
13335,
20529,
436,
31866,
314,
2518,
14,
272,
408,
272,
347,
3613,
8,
277,
304,
267,
408,
267,
5723,
2295,
1929,
282,
922,
315,
314,
6249,
880,
626,
314,
1639,
1379,
6810,
883,
943,
3062,
315,
14,
267,
710,
511,
922,
365,
2737,
315,
314,
17996,
1746,
3613,
1083,
14,
267,
9322,
8287,
687,
314,
17996,
1746,
1021,
880,
626,
314,
32315,
13152,
3245,
267,
911,
506,
20518,
734,
2544,
1924,
511,
1930,
6451,
436,
5463,
267,
26982,
14,
267,
408,
398,
291,
14,
751,
63,
2060,
275,
1613,
8,
6979,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
1258,
275,
437,
15863,
6589,
774,
3041,
342,
267,
291,
14,
1258,
14,
2886,
8,
2473,
29,
277,
14,
751,
14,
2473,
12,
2505,
29,
277,
14,
751,
63,
2060,
9,
398,
291,
14,
1972,
275,
17862,
14,
981,
342,
339,
347,
1218,
63,
2865,
63,
7018,
63,
1178,
379,
63,
751,
63,
1258,
8,
277,
12,
12895,
29,
549,
304,
267,
408,
267,
2790,
282,
2222,
13,
7018,
922,
12,
943,
3062,
315,
334,
692,
12895,
29,
549,
395,
436,
372,
314,
1890,
12,
922,
370,
675,
367,
5343,
14,
267,
408,
267,
2222,
7018,
12,
2505,
275,
291,
14,
981,
63,
2865,
63,
7018,
63,
751,
342,
398,
1890,
275,
437,
15863,
6589,
774,
3041,
342,
267,
340,
12895,
26,
288,
1890,
14,
2886,
8,
2473,
29,
2865,
7018,
14,
2473,
12,
2505,
29,
2060,
9,
267,
2222,
7018,
14,
374,
63,
12177,
275,
2400,
26,
12895,
267,
372,
1890,
12,
2222,
7018,
339,
347,
13101,
63,
1972,
8,
277,
304,
267,
408,
267,
799,
3640,
314,
2518,
909,
687,
314,
3050,
267,
408,
267,
291,
14,
1972,
275,
291,
14,
1617,
14,
362,
63,
1972,
8,
277,
14,
1972,
14,
344,
9,
339,
347,
3354,
63,
1972,
8,
277,
304,
267,
408,
267,
24663,
314,
2518,
909,
315,
314,
3050,
267,
408,
267,
291,
14,
1972,
14,
2117,
342,
267,
291,
14,
1617,
14,
873,
63,
1053,
8,
277,
14,
1972,
12,
291,
14,
751,
14,
344,
9,
339,
7393,
63,
22634,
275,
283,
7870,
63,
396,
7,
272,
1549,
9791,
879,
63,
36,
29650,
63,
22634,
275,
283,
22161,
63,
7185,
63,
7870,
7,
272,
1549,
9791,
879,
63,
36,
29650,
63,
4943,
275,
283,
22161,
63,
7185,
63,
1360,
7,
272,
28644,
1951,
63,
22634,
275,
283,
65,
63,
4239,
63,
7870,
7,
272,
18787,
44,
20450,
63,
22634,
275,
283,
65,
63,
8987,
63,
7870,
7,
272,
28130,
8246,
275,
283,
7870,
63,
16211,
7,
272,
577,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
frenkowski/Tyrannus_Kernel_MM
|
Documentation/target/tcm_mod_builder.py
|
2358
|
40707
|
#!/usr/bin/python
# The TCM v4 multi-protocol fabric module generation script for drivers/target/$NEW_MOD
#
# Copyright (c) 2010 Rising Tide Systems
# Copyright (c) 2010 Linux-iSCSI.org
#
# Author: nab@kernel.org
#
import os, sys
import subprocess as sub
import string
import re
import optparse
tcm_dir = ""
fabric_ops = []
fabric_mod_dir = ""
fabric_mod_port = ""
fabric_mod_init_port = ""
def tcm_mod_err(msg):
print msg
sys.exit(1)
def tcm_mod_create_module_subdir(fabric_mod_dir_var):
if os.path.isdir(fabric_mod_dir_var) == True:
return 1
print "Creating fabric_mod_dir: " + fabric_mod_dir_var
ret = os.mkdir(fabric_mod_dir_var)
if ret:
tcm_mod_err("Unable to mkdir " + fabric_mod_dir_var)
return
def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name):
global fabric_mod_port
global fabric_mod_init_port
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_nacl {\n"
buf += " /* Binary World Wide unique Port Name for FC Initiator Nport */\n"
buf += " u64 nport_wwpn;\n"
buf += " /* ASCII formatted WWPN for FC Initiator Nport */\n"
buf += " char nport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
buf += " struct se_node_acl se_node_acl;\n"
buf += "};\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_tpg {\n"
buf += " /* FC lport target portal group tag for TCM */\n"
buf += " u16 lport_tpgt;\n"
buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n"
buf += " struct " + fabric_mod_name + "_lport *lport;\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
buf += " struct se_portal_group se_tpg;\n"
buf += "};\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_lport {\n"
buf += " /* SCSI protocol the lport is providing */\n"
buf += " u8 lport_proto_id;\n"
buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n"
buf += " u64 lport_wwpn;\n"
buf += " /* ASCII formatted WWPN for FC Target Lport */\n"
buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n"
buf += " struct se_wwn lport_wwn;\n"
buf += "};\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
fabric_mod_port = "lport"
fabric_mod_init_port = "nport"
return
def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name):
global fabric_mod_port
global fabric_mod_init_port
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_nacl {\n"
buf += " /* Binary World Wide unique Port Name for SAS Initiator port */\n"
buf += " u64 iport_wwpn;\n"
buf += " /* ASCII formatted WWPN for Sas Initiator port */\n"
buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
buf += " struct se_node_acl se_node_acl;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tpg {\n"
buf += " /* SAS port target portal group tag for TCM */\n"
buf += " u16 tport_tpgt;\n"
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
buf += " struct " + fabric_mod_name + "_tport *tport;\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
buf += " struct se_portal_group se_tpg;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tport {\n"
buf += " /* SCSI protocol the tport is providing */\n"
buf += " u8 tport_proto_id;\n"
buf += " /* Binary World Wide unique Port Name for SAS Target port */\n"
buf += " u64 tport_wwpn;\n"
buf += " /* ASCII formatted WWPN for SAS Target port */\n"
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
buf += " struct se_wwn tport_wwn;\n"
buf += "};\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
fabric_mod_port = "tport"
fabric_mod_init_port = "iport"
return
def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name):
global fabric_mod_port
global fabric_mod_init_port
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_nacl {\n"
buf += " /* ASCII formatted InitiatorName */\n"
buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
buf += " struct se_node_acl se_node_acl;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tpg {\n"
buf += " /* iSCSI target portal group tag for TCM */\n"
buf += " u16 tport_tpgt;\n"
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
buf += " struct " + fabric_mod_name + "_tport *tport;\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
buf += " struct se_portal_group se_tpg;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tport {\n"
buf += " /* SCSI protocol the tport is providing */\n"
buf += " u8 tport_proto_id;\n"
buf += " /* ASCII formatted TargetName for IQN */\n"
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
buf += " struct se_wwn tport_wwn;\n"
buf += "};\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
fabric_mod_port = "tport"
fabric_mod_init_port = "iport"
return
def tcm_mod_build_base_includes(proto_ident, fabric_mod_dir_val, fabric_mod_name):
if proto_ident == "FC":
tcm_mod_build_FC_include(fabric_mod_dir_val, fabric_mod_name)
elif proto_ident == "SAS":
tcm_mod_build_SAS_include(fabric_mod_dir_val, fabric_mod_name)
elif proto_ident == "iSCSI":
tcm_mod_build_iSCSI_include(fabric_mod_dir_val, fabric_mod_name)
else:
print "Unsupported proto_ident: " + proto_ident
sys.exit(1)
return
def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_configfs.c"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#include <linux/module.h>\n"
buf += "#include <linux/moduleparam.h>\n"
buf += "#include <linux/version.h>\n"
buf += "#include <generated/utsrelease.h>\n"
buf += "#include <linux/utsname.h>\n"
buf += "#include <linux/init.h>\n"
buf += "#include <linux/slab.h>\n"
buf += "#include <linux/kthread.h>\n"
buf += "#include <linux/types.h>\n"
buf += "#include <linux/string.h>\n"
buf += "#include <linux/configfs.h>\n"
buf += "#include <linux/ctype.h>\n"
buf += "#include <asm/unaligned.h>\n\n"
buf += "#include <target/target_core_base.h>\n"
buf += "#include <target/target_core_fabric.h>\n"
buf += "#include <target/target_core_fabric_configfs.h>\n"
buf += "#include <target/target_core_configfs.h>\n"
buf += "#include <target/configfs_macros.h>\n\n"
buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
buf += "/* Local pointer to allocated TCM configfs fabric module */\n"
buf += "struct target_fabric_configfs *" + fabric_mod_name + "_fabric_configfs;\n\n"
buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct config_group *group,\n"
buf += " const char *name)\n"
buf += "{\n"
buf += " struct se_node_acl *se_nacl, *se_nacl_new;\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl;\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " u64 wwpn = 0;\n"
buf += " u32 nexus_depth;\n\n"
buf += " /* " + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
buf += " return ERR_PTR(-EINVAL); */\n"
buf += " se_nacl_new = " + fabric_mod_name + "_alloc_fabric_acl(se_tpg);\n"
buf += " if (!se_nacl_new)\n"
buf += " return ERR_PTR(-ENOMEM);\n"
buf += "//#warning FIXME: Hardcoded nexus depth in " + fabric_mod_name + "_make_nodeacl()\n"
buf += " nexus_depth = 1;\n"
buf += " /*\n"
buf += " * se_nacl_new may be released by core_tpg_add_initiator_node_acl()\n"
buf += " * when converting a NodeACL from demo mode -> explict\n"
buf += " */\n"
buf += " se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,\n"
buf += " name, nexus_depth);\n"
buf += " if (IS_ERR(se_nacl)) {\n"
buf += " " + fabric_mod_name + "_release_fabric_acl(se_tpg, se_nacl_new);\n"
buf += " return se_nacl;\n"
buf += " }\n"
buf += " /*\n"
buf += " * Locate our struct " + fabric_mod_name + "_nacl and set the FC Nport WWPN\n"
buf += " */\n"
buf += " nacl = container_of(se_nacl, struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " nacl->" + fabric_mod_init_port + "_wwpn = wwpn;\n"
buf += " /* " + fabric_mod_name + "_format_wwn(&nacl->" + fabric_mod_init_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
buf += " return se_nacl;\n"
buf += "}\n\n"
buf += "static void " + fabric_mod_name + "_drop_nodeacl(struct se_node_acl *se_acl)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_acl,\n"
buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
buf += " core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);\n"
buf += " kfree(nacl);\n"
buf += "}\n\n"
buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n"
buf += " struct se_wwn *wwn,\n"
buf += " struct config_group *group,\n"
buf += " const char *name)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg;\n"
buf += " unsigned long tpgt;\n"
buf += " int ret;\n\n"
buf += " if (strstr(name, \"tpgt_\") != name)\n"
buf += " return ERR_PTR(-EINVAL);\n"
buf += " if (strict_strtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n"
buf += " return ERR_PTR(-EINVAL);\n\n"
buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n"
buf += " if (!tpg) {\n"
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n"
buf += " return ERR_PTR(-ENOMEM);\n"
buf += " }\n"
buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n"
buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n"
buf += " ret = core_tpg_register(&" + fabric_mod_name + "_fabric_configfs->tf_ops, wwn,\n"
buf += " &tpg->se_tpg, (void *)tpg,\n"
buf += " TRANSPORT_TPG_TYPE_NORMAL);\n"
buf += " if (ret < 0) {\n"
buf += " kfree(tpg);\n"
buf += " return NULL;\n"
buf += " }\n"
buf += " return &tpg->se_tpg;\n"
buf += "}\n\n"
buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n"
buf += " core_tpg_deregister(se_tpg);\n"
buf += " kfree(tpg);\n"
buf += "}\n\n"
buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n"
buf += " struct target_fabric_configfs *tf,\n"
buf += " struct config_group *group,\n"
buf += " const char *name)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " u64 wwpn = 0;\n\n"
buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
buf += " return ERR_PTR(-EINVAL); */\n\n"
buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n"
buf += " if (!" + fabric_mod_port + ") {\n"
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n"
buf += " return ERR_PTR(-ENOMEM);\n"
buf += " }\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n"
buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n"
buf += "}\n\n"
buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"
buf += " kfree(" + fabric_mod_port + ");\n"
buf += "}\n\n"
buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n"
buf += " struct target_fabric_configfs *tf,\n"
buf += " char *page)\n"
buf += "{\n"
buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
buf += " utsname()->machine);\n"
buf += "}\n\n"
buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n"
buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n"
buf += " &" + fabric_mod_name + "_wwn_version.attr,\n"
buf += " NULL,\n"
buf += "};\n\n"
buf += "static struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"
buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"
buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n"
buf += " .tpg_get_default_depth = " + fabric_mod_name + "_get_default_depth,\n"
buf += " .tpg_get_pr_transport_id = " + fabric_mod_name + "_get_pr_transport_id,\n"
buf += " .tpg_get_pr_transport_id_len = " + fabric_mod_name + "_get_pr_transport_id_len,\n"
buf += " .tpg_parse_pr_out_transport_id = " + fabric_mod_name + "_parse_pr_out_transport_id,\n"
buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n"
buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n"
buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n"
buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n"
buf += " .tpg_alloc_fabric_acl = " + fabric_mod_name + "_alloc_fabric_acl,\n"
buf += " .tpg_release_fabric_acl = " + fabric_mod_name + "_release_fabric_acl,\n"
buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n"
buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n"
buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n"
buf += " .close_session = " + fabric_mod_name + "_close_session,\n"
buf += " .stop_session = " + fabric_mod_name + "_stop_session,\n"
buf += " .fall_back_to_erl0 = " + fabric_mod_name + "_reset_nexus,\n"
buf += " .sess_logged_in = " + fabric_mod_name + "_sess_logged_in,\n"
buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n"
buf += " .sess_get_initiator_sid = NULL,\n"
buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n"
buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n"
buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n"
buf += " .get_task_tag = " + fabric_mod_name + "_get_task_tag,\n"
buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n"
buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n"
buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n"
buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n"
buf += " .is_state_remove = " + fabric_mod_name + "_is_state_remove,\n"
buf += " /*\n"
buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
buf += " */\n"
buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n"
buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n"
buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n"
buf += " .fabric_post_link = NULL,\n"
buf += " .fabric_pre_unlink = NULL,\n"
buf += " .fabric_make_np = NULL,\n"
buf += " .fabric_drop_np = NULL,\n"
buf += " .fabric_make_nodeacl = " + fabric_mod_name + "_make_nodeacl,\n"
buf += " .fabric_drop_nodeacl = " + fabric_mod_name + "_drop_nodeacl,\n"
buf += "};\n\n"
buf += "static int " + fabric_mod_name + "_register_configfs(void)\n"
buf += "{\n"
buf += " struct target_fabric_configfs *fabric;\n"
buf += " int ret;\n\n"
buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
buf += " \" on \"UTS_RELEASE\"\\n\"," + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
buf += " utsname()->machine);\n"
buf += " /*\n"
buf += " * Register the top level struct config_item_type with TCM core\n"
buf += " */\n"
buf += " fabric = target_fabric_configfs_init(THIS_MODULE, \"" + fabric_mod_name[4:] + "\");\n"
buf += " if (IS_ERR(fabric)) {\n"
buf += " printk(KERN_ERR \"target_fabric_configfs_init() failed\\n\");\n"
buf += " return PTR_ERR(fabric);\n"
buf += " }\n"
buf += " /*\n"
buf += " * Setup fabric->tf_ops from our local " + fabric_mod_name + "_ops\n"
buf += " */\n"
buf += " fabric->tf_ops = " + fabric_mod_name + "_ops;\n"
buf += " /*\n"
buf += " * Setup default attribute lists for various fabric->tf_cit_tmpl\n"
buf += " */\n"
buf += " TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = " + fabric_mod_name + "_wwn_attrs;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = NULL;\n"
buf += " /*\n"
buf += " * Register the fabric for use within TCM\n"
buf += " */\n"
buf += " ret = target_fabric_configfs_register(fabric);\n"
buf += " if (ret < 0) {\n"
buf += " printk(KERN_ERR \"target_fabric_configfs_register() failed\"\n"
buf += " \" for " + fabric_mod_name.upper() + "\\n\");\n"
buf += " return ret;\n"
buf += " }\n"
buf += " /*\n"
buf += " * Setup our local pointer to *fabric\n"
buf += " */\n"
buf += " " + fabric_mod_name + "_fabric_configfs = fabric;\n"
buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Set fabric -> " + fabric_mod_name + "_fabric_configfs\\n\");\n"
buf += " return 0;\n"
buf += "};\n\n"
buf += "static void __exit " + fabric_mod_name + "_deregister_configfs(void)\n"
buf += "{\n"
buf += " if (!" + fabric_mod_name + "_fabric_configfs)\n"
buf += " return;\n\n"
buf += " target_fabric_configfs_deregister(" + fabric_mod_name + "_fabric_configfs);\n"
buf += " " + fabric_mod_name + "_fabric_configfs = NULL;\n"
buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Cleared " + fabric_mod_name + "_fabric_configfs\\n\");\n"
buf += "};\n\n"
buf += "static int __init " + fabric_mod_name + "_init(void)\n"
buf += "{\n"
buf += " int ret;\n\n"
buf += " ret = " + fabric_mod_name + "_register_configfs();\n"
buf += " if (ret < 0)\n"
buf += " return ret;\n\n"
buf += " return 0;\n"
buf += "};\n\n"
buf += "static void __exit " + fabric_mod_name + "_exit(void)\n"
buf += "{\n"
buf += " " + fabric_mod_name + "_deregister_configfs();\n"
buf += "};\n\n"
buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"
buf += "MODULE_LICENSE(\"GPL\");\n"
buf += "module_init(" + fabric_mod_name + "_init);\n"
buf += "module_exit(" + fabric_mod_name + "_exit);\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
return
def tcm_mod_scan_fabric_ops(tcm_dir):
fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h"
print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api
process_fo = 0;
p = open(fabric_ops_api, 'r')
line = p.readline()
while line:
if process_fo == 0 and re.search('struct target_core_fabric_ops {', line):
line = p.readline()
continue
if process_fo == 0:
process_fo = 1;
line = p.readline()
# Search for function pointer
if not re.search('\(\*', line):
continue
fabric_ops.append(line.rstrip())
continue
line = p.readline()
# Search for function pointer
if not re.search('\(\*', line):
continue
fabric_ops.append(line.rstrip())
p.close()
return
def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
buf = ""
bufi = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c"
print "Writing file: " + f
p = open(f, 'w')
if not p:
tcm_mod_err("Unable to open file: " + f)
fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h"
print "Writing file: " + fi
pi = open(fi, 'w')
if not pi:
tcm_mod_err("Unable to open file: " + fi)
buf = "#include <linux/slab.h>\n"
buf += "#include <linux/kthread.h>\n"
buf += "#include <linux/types.h>\n"
buf += "#include <linux/list.h>\n"
buf += "#include <linux/types.h>\n"
buf += "#include <linux/string.h>\n"
buf += "#include <linux/ctype.h>\n"
buf += "#include <asm/unaligned.h>\n"
buf += "#include <scsi/scsi.h>\n"
buf += "#include <scsi/scsi_host.h>\n"
buf += "#include <scsi/scsi_device.h>\n"
buf += "#include <scsi/scsi_cmnd.h>\n"
buf += "#include <scsi/libfc.h>\n\n"
buf += "#include <target/target_core_base.h>\n"
buf += "#include <target/target_core_fabric.h>\n"
buf += "#include <target/target_core_configfs.h>\n\n"
buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 1;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n"
buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n"
total_fabric_ops = len(fabric_ops)
i = 0
while i < total_fabric_ops:
fo = fabric_ops[i]
i += 1
# print "fabric_ops: " + fo
if re.search('get_fabric_name', fo):
buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"
buf += "{\n"
buf += " return \"" + fabric_mod_name[4:] + "\";\n"
buf += "}\n\n"
bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"
continue
if re.search('get_fabric_proto_ident', fo):
buf += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " u8 proto_id;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " proto_id = fc_get_fabric_proto_ident(se_tpg);\n"
buf += " break;\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " proto_id = sas_get_fabric_proto_ident(se_tpg);\n"
buf += " break;\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " proto_id = iscsi_get_fabric_proto_ident(se_tpg);\n"
buf += " break;\n"
buf += " }\n\n"
buf += " return proto_id;\n"
buf += "}\n\n"
bufi += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *);\n"
if re.search('get_wwn', fo):
buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n"
buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n"
buf += "}\n\n"
bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n"
if re.search('get_tag', fo):
buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " return tpg->" + fabric_mod_port + "_tpgt;\n"
buf += "}\n\n"
bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n"
if re.search('get_default_depth', fo):
buf += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 1;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *);\n"
if re.search('get_pr_transport_id\)\(', fo):
buf += "u32 " + fabric_mod_name + "_get_pr_transport_id(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct se_node_acl *se_nacl,\n"
buf += " struct t10_pr_registration *pr_reg,\n"
buf += " int *format_code,\n"
buf += " unsigned char *buf)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " int ret = 0;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code, buf);\n"
buf += " break;\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code, buf);\n"
buf += " break;\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code, buf);\n"
buf += " break;\n"
buf += " }\n\n"
buf += " return ret;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n"
bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
bufi += " int *, unsigned char *);\n"
if re.search('get_pr_transport_id_len\)\(', fo):
buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct se_node_acl *se_nacl,\n"
buf += " struct t10_pr_registration *pr_reg,\n"
buf += " int *format_code)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " int ret = 0;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code);\n"
buf += " break;\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code);\n"
buf += " break;\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code);\n"
buf += " break;\n"
buf += " }\n\n"
buf += " return ret;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n"
bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
bufi += " int *);\n"
if re.search('parse_pr_out_transport_id\)\(', fo):
buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " const char *buf,\n"
buf += " u32 *out_tid_len,\n"
buf += " char **port_nexus_ptr)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " char *tid = NULL;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
buf += " port_nexus_ptr);\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
buf += " port_nexus_ptr);\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
buf += " port_nexus_ptr);\n"
buf += " }\n\n"
buf += " return tid;\n"
buf += "}\n\n"
bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n"
bufi += " const char *, u32 *, char **);\n"
if re.search('alloc_fabric_acl\)\(', fo):
buf += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl;\n\n"
buf += " nacl = kzalloc(sizeof(struct " + fabric_mod_name + "_nacl), GFP_KERNEL);\n"
buf += " if (!nacl) {\n"
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_nacl\\n\");\n"
buf += " return NULL;\n"
buf += " }\n\n"
buf += " return &nacl->se_node_acl;\n"
buf += "}\n\n"
bufi += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *);\n"
if re.search('release_fabric_acl\)\(', fo):
buf += "void " + fabric_mod_name + "_release_fabric_acl(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct se_node_acl *se_nacl)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_nacl,\n"
buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
buf += " kfree(nacl);\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_release_fabric_acl(struct se_portal_group *,\n"
bufi += " struct se_node_acl *);\n"
if re.search('tpg_get_inst_index\)\(', fo):
buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 1;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n"
if re.search('\*release_cmd\)\(', fo):
buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n"
if re.search('shutdown_session\)\(', fo):
buf += "int " + fabric_mod_name + "_shutdown_session(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_shutdown_session(struct se_session *);\n"
if re.search('close_session\)\(', fo):
buf += "void " + fabric_mod_name + "_close_session(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n"
if re.search('stop_session\)\(', fo):
buf += "void " + fabric_mod_name + "_stop_session(struct se_session *se_sess, int sess_sleep , int conn_sleep)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_stop_session(struct se_session *, int, int);\n"
if re.search('fall_back_to_erl0\)\(', fo):
buf += "void " + fabric_mod_name + "_reset_nexus(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_reset_nexus(struct se_session *);\n"
if re.search('sess_logged_in\)\(', fo):
buf += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *);\n"
if re.search('sess_get_index\)\(', fo):
buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n"
if re.search('write_pending\)\(', fo):
buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n"
if re.search('write_pending_status\)\(', fo):
buf += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *);\n"
if re.search('set_default_node_attributes\)\(', fo):
buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n"
if re.search('get_task_tag\)\(', fo):
buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n"
if re.search('get_cmd_state\)\(', fo):
buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n"
if re.search('queue_data_in\)\(', fo):
buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n"
if re.search('queue_status\)\(', fo):
buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"
if re.search('queue_tm_rsp\)\(', fo):
buf += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"
if re.search('is_state_remove\)\(', fo):
buf += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *);\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
ret = pi.write(bufi)
if ret:
tcm_mod_err("Unable to write fi: " + fi)
pi.close()
return
def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name):
buf = ""
f = fabric_mod_dir_var + "/Makefile"
print "Writing file: " + f
p = open(f, 'w')
if not p:
tcm_mod_err("Unable to open file: " + f)
buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n"
buf += " " + fabric_mod_name + "_configfs.o\n"
buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
return
def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name):
buf = ""
f = fabric_mod_dir_var + "/Kconfig"
print "Writing file: " + f
p = open(f, 'w')
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "config " + fabric_mod_name.upper() + "\n"
buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n"
buf += " depends on TARGET_CORE && CONFIGFS_FS\n"
buf += " default n\n"
buf += " ---help---\n"
buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
return
def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name):
buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n"
kbuild = tcm_dir + "/drivers/target/Makefile"
f = open(kbuild, 'a')
f.write(buf)
f.close()
return
def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name):
buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n"
kconfig = tcm_dir + "/drivers/target/Kconfig"
f = open(kconfig, 'a')
f.write(buf)
f.close()
return
def main(modname, proto_ident):
# proto_ident = "FC"
# proto_ident = "SAS"
# proto_ident = "iSCSI"
tcm_dir = os.getcwd();
tcm_dir += "/../../"
print "tcm_dir: " + tcm_dir
fabric_mod_name = modname
fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name
print "Set fabric_mod_name: " + fabric_mod_name
print "Set fabric_mod_dir: " + fabric_mod_dir
print "Using proto_ident: " + proto_ident
if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI":
print "Unsupported proto_ident: " + proto_ident
sys.exit(1)
ret = tcm_mod_create_module_subdir(fabric_mod_dir)
if ret:
print "tcm_mod_create_module_subdir() failed because module already exists!"
sys.exit(1)
tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name)
tcm_mod_scan_fabric_ops(tcm_dir)
tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name)
tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name)
tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)
tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)
input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Makefile..? [yes,no]: ")
if input == "yes" or input == "y":
tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)
input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Kconfig..? [yes,no]: ")
if input == "yes" or input == "y":
tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)
return
parser = optparse.OptionParser()
parser.add_option('-m', '--modulename', help='Module name', dest='modname',
action='store', nargs=1, type='string')
parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident',
action='store', nargs=1, type='string')
(opts, args) = parser.parse_args()
mandatories = ['modname', 'protoident']
for m in mandatories:
if not opts.__dict__[m]:
print "mandatory option is missing\n"
parser.print_help()
exit(-1)
if __name__ == "__main__":
main(str(opts.modname), opts.protoident)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
710,
28526,
373,
20,
3510,
13,
3922,
2630,
859,
10152,
2884,
367,
19016,
15,
1375,
21792,
11365,
63,
8816,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
820,
11136,
377,
2655,
15285,
199,
3,
1898,
334,
67,
9,
7129,
10130,
13,
21534,
14,
1308,
199,
3,
199,
3,
6529,
26,
302,
371,
32,
4989,
14,
1308,
199,
3,
199,
646,
747,
12,
984,
199,
646,
3873,
465,
1007,
199,
646,
1059,
199,
646,
295,
199,
646,
8691,
199,
199,
10606,
63,
694,
275,
3087,
199,
199,
4991,
63,
1483,
275,
942,
199,
4991,
63,
1494,
63,
694,
275,
3087,
199,
4991,
63,
1494,
63,
719,
275,
3087,
199,
4991,
63,
1494,
63,
826,
63,
719,
275,
3087,
199,
199,
318,
15288,
63,
1494,
63,
1508,
8,
1328,
304,
199,
198,
1361,
1499,
199,
198,
1274,
14,
2224,
8,
17,
9,
199,
199,
318,
15288,
63,
1494,
63,
981,
63,
578,
63,
10622,
8,
4991,
63,
1494,
63,
694,
63,
1391,
304,
421,
198,
692,
747,
14,
515,
14,
6027,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
508,
715,
26,
507,
198,
1107,
413,
421,
198,
1361,
298,
14380,
2630,
63,
1494,
63,
694,
26,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
199,
198,
3292,
275,
747,
14,
8215,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
20366,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
9,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
4161,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304,
199,
198,
2966,
2630,
63,
1494,
63,
719,
199,
198,
2966,
2630,
63,
1494,
63,
826,
63,
719,
199,
198,
1436,
275,
3087,
421,
198,
70,
275,
2630,
63,
1494,
63,
694,
63,
1391,
435,
10609,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1095,
14,
72,
2,
199,
198,
1361,
298,
16646,
570,
26,
298,
435,
289,
421,
198,
80,
275,
1551,
8,
70,
12,
283,
87,
11339,
199,
198,
692,
440,
299,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
1551,
570,
26,
298,
435,
289,
9,
421,
198,
1436,
275,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
4612,
198,
4451,
86,
16,
14,
17,
13356,
78,
2,
199,
198,
1436,
847,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
198,
708,
60,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
7745,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
302,
719,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
302,
719,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
23964,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
932,
63,
5853,
542,
63,
932,
63,
5853,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
5249,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
20934,
27167,
1347,
18428,
1572,
1947,
367,
28526,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
975,
27167,
63,
28552,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
28833,
1771,
370,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
627,
25623,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
5249,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
8707,
63,
923,
542,
63,
5249,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
17822,
4113,
314,
27167,
365,
13070,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
24,
27167,
63,
2625,
63,
344,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
27167,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
27167,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
25623,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
10988,
27167,
63,
10988,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
421,
198,
3292,
275,
299,
14,
952,
8,
1436,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
2218,
289,
26,
298,
435,
289,
9,
421,
198,
80,
14,
1600,
342,
421,
198,
4991,
63,
1494,
63,
719,
275,
298,
25623,
2,
199,
198,
4991,
63,
1494,
63,
826,
63,
719,
275,
298,
78,
719,
2,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
15319,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
710,
28526,
373,
20,
3510,
13,
3922,
2630,
859,
10152,
2884,
367,
19016,
15,
1375,
21792,
11365,
63,
8816,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
820,
11136,
377,
2655,
15285,
199,
3,
1898,
334,
67,
9,
7129,
10130,
13,
21534,
14,
1308,
199,
3,
199,
3,
6529,
26,
302,
371,
32,
4989,
14,
1308,
199,
3,
199,
646,
747,
12,
984,
199,
646,
3873,
465,
1007,
199,
646,
1059,
199,
646,
295,
199,
646,
8691,
199,
199,
10606,
63,
694,
275,
3087,
199,
199,
4991,
63,
1483,
275,
942,
199,
4991,
63,
1494,
63,
694,
275,
3087,
199,
4991,
63,
1494,
63,
719,
275,
3087,
199,
4991,
63,
1494,
63,
826,
63,
719,
275,
3087,
199,
199,
318,
15288,
63,
1494,
63,
1508,
8,
1328,
304,
199,
198,
1361,
1499,
199,
198,
1274,
14,
2224,
8,
17,
9,
199,
199,
318,
15288,
63,
1494,
63,
981,
63,
578,
63,
10622,
8,
4991,
63,
1494,
63,
694,
63,
1391,
304,
421,
198,
692,
747,
14,
515,
14,
6027,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
508,
715,
26,
507,
198,
1107,
413,
421,
198,
1361,
298,
14380,
2630,
63,
1494,
63,
694,
26,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
199,
198,
3292,
275,
747,
14,
8215,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
20366,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
9,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
4161,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304,
199,
198,
2966,
2630,
63,
1494,
63,
719,
199,
198,
2966,
2630,
63,
1494,
63,
826,
63,
719,
199,
198,
1436,
275,
3087,
421,
198,
70,
275,
2630,
63,
1494,
63,
694,
63,
1391,
435,
10609,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1095,
14,
72,
2,
199,
198,
1361,
298,
16646,
570,
26,
298,
435,
289,
421,
198,
80,
275,
1551,
8,
70,
12,
283,
87,
11339,
199,
198,
692,
440,
299,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
1551,
570,
26,
298,
435,
289,
9,
421,
198,
1436,
275,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
4612,
198,
4451,
86,
16,
14,
17,
13356,
78,
2,
199,
198,
1436,
847,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
198,
708,
60,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
7745,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
302,
719,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
302,
719,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
23964,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
932,
63,
5853,
542,
63,
932,
63,
5853,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
5249,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
20934,
27167,
1347,
18428,
1572,
1947,
367,
28526,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
975,
27167,
63,
28552,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
28833,
1771,
370,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
627,
25623,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
5249,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
8707,
63,
923,
542,
63,
5249,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
17822,
4113,
314,
27167,
365,
13070,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
24,
27167,
63,
2625,
63,
344,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
27167,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
27167,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
25623,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
10988,
27167,
63,
10988,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
421,
198,
3292,
275,
299,
14,
952,
8,
1436,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
2218,
289,
26,
298,
435,
289,
9,
421,
198,
80,
14,
1600,
342,
421,
198,
4991,
63,
1494,
63,
719,
275,
298,
25623,
2,
199,
198,
4991,
63,
1494,
63,
826,
63,
719,
275,
298,
78,
719,
2,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
15319,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
manjunaths/tensorflow
|
tensorflow/python/training/server_lib_sparse_job_test.py
|
133
|
1605
|
# 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.
# ==============================================================================
"""Tests for tf.GrpcServer."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.client import session
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import ops
from tensorflow.python.platform import test
from tensorflow.python.training import server_lib
class SparseJobTest(test.TestCase):
# TODO(b/34465411): Starting multiple servers with different configurations
# in the same test is flaky. Move this test case back into
# "server_lib_test.py" when this is no longer the case.
def testSparseJob(self):
server = server_lib.Server({"local": {37: "localhost:0"}})
with ops.device("/job:local/task:37"):
a = constant_op.constant(1.0)
with session.Session(server.target) as sess:
self.assertEqual(1.0, sess.run(a))
if __name__ == "__main__":
test.main()
|
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,
2925,
367,
2833,
14,
39,
4354,
3120,
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,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
421,
199,
533,
14531,
6694,
774,
8,
396,
14,
1746,
304,
819,
327,
3254,
8,
66,
15,
1082,
2466,
1477,
845,
304,
24175,
3663,
8037,
543,
3365,
13422,
523,
327,
315,
314,
2011,
511,
365,
17566,
10562,
14,
14171,
642,
511,
1930,
1771,
1901,
523,
327,
298,
1000,
63,
773,
63,
396,
14,
647,
2,
1380,
642,
365,
949,
8088,
314,
1930,
14,
523,
347,
511,
8629,
6694,
8,
277,
304,
272,
1654,
275,
1654,
63,
773,
14,
3120,
6333,
1832,
582,
469,
1401,
26,
298,
5967,
26,
16,
3570,
1552,
272,
543,
4156,
14,
1782,
4769,
2423,
26,
1832,
15,
1765,
26,
1401,
2349,
489,
282,
275,
4413,
63,
411,
14,
4083,
8,
17,
14,
16,
9,
339,
543,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
465,
4043,
26,
489,
291,
14,
629,
8,
17,
14,
16,
12,
4043,
14,
1065,
8,
65,
430,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
2925,
367,
2833,
14,
39,
4354,
3120,
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,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1654,
63,
773,
421,
199,
533,
14531,
6694,
774,
8,
396,
14,
1746,
304,
819,
327,
3254,
8,
66,
15,
1082,
2466,
1477,
845,
304,
24175,
3663,
8037,
543,
3365,
13422,
523,
327,
315,
314,
2011,
511,
365,
17566,
10562,
14,
14171,
642,
511,
1930,
1771,
1901,
523,
327,
298,
1000,
63,
773,
63,
396,
14,
647,
2,
1380,
642,
365,
949,
8088,
314,
1930,
14,
523,
347,
511,
8629,
6694,
8,
277,
304,
272,
1654,
275,
1654,
63,
773,
14,
3120,
6333,
1832,
582,
469,
1401,
26,
298,
5967,
26,
16,
3570,
1552,
272,
543,
4156,
14,
1782,
4769,
2423,
26,
1832,
15,
1765,
26,
1401,
2349,
489,
282,
275,
4413,
63,
411,
14,
4083,
8,
17,
14,
16,
9,
339,
543,
2351,
14,
4434,
8,
1000,
14,
1375,
9,
465,
4043,
26,
489,
291,
14,
629,
8,
17,
14,
16,
12,
4043,
14,
1065,
8,
65,
430,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
kkdd/arangodb
|
3rdParty/V8-4.3.61/third_party/python_26/Lib/site-packages/win32comext/axscript/client/pydumper.py
|
35
|
2124
|
# pydumper.py
#
# This is being worked on - it does not yet work at all, in ay way
# shape or form :-)
#
# A new script engine, derived from the standard scripting engine,
# which dumps information.
# This generally can be used to grab all sorts of useful details about
# an engine - expose bugs in it or Python, dump the object model, etc.
# As it is derived from the standard engine, it fully supports Python
# as a scripting language - meaning the dumps produced can be quite dynamic,
# and based on the script code you execute.
import pyscript
from win32com.axscript import axscript
from pyscript import RaiseAssert, trace, Exception, SCRIPTTEXT_FORCEEXECUTION
PyDump_CLSID = '{ac527e60-c693-11d0-9c25-00aa00125a98}'
class AXScriptAttribute(pyscript.AXScriptAttribute):
pass
class NamedScriptAttribute(pyscript.NamedScriptAttribute):
pass
class PyScript(pyscript.PyScript):
pass
def Register():
import sys
if '-d' in sys.argv:
dispatcher = "DispatcherWin32trace"
debug_desc = " ("+dispatcher+")"
debug_option = "Yes"
else:
dispatcher = None
debug_desc = ""
debug_option = ""
categories = [axscript.CATID_ActiveScript,axscript.CATID_ActiveScriptParse]
clsid = PyDump_CLSID
lcid = 0x0409 # // english
policy = None # "win32com.axscript.client.axspolicy.AXScriptPolicy"
print "Registering COM server%s..." % debug_desc
from win32com.server.register import RegisterServer
languageName = "PyDump"
verProgId = "Python.Dumper.1"
RegisterServer(clsid = clsid, pythonInstString = "win32com.axscript.client.pyscript.PyDumper",
className = "Python Debugging/Dumping ActiveX Scripting Engine",
progID = languageName, verProgID = verProgId,
catids = categories,
policy=policy, dispatcher = dispatcher)
CreateRegKey(languageName + "\\OLEScript")
# Basic Registration for wsh.
win32com.server.register._set_string(".pysDump", "pysDumpFile")
win32com.server.register._set_string("pysDumpFile\\ScriptEngine", languageName)
print "Dumping Server registered."
if __name__=='__main__':
Register()
|
apache-2.0
|
[
3,
1134,
2724,
281,
14,
647,
199,
3,
199,
3,
961,
365,
3769,
26731,
641,
446,
652,
1630,
440,
5966,
1736,
737,
1006,
12,
315,
282,
89,
4340,
199,
3,
2215,
503,
1824,
22901,
9,
199,
3,
199,
3,
437,
892,
2884,
6869,
12,
7131,
687,
314,
4465,
2884,
316,
6869,
12,
199,
3,
1314,
16864,
2556,
14,
199,
199,
3,
961,
16711,
883,
506,
1202,
370,
18200,
1006,
30313,
402,
2997,
2436,
3595,
199,
3,
376,
6869,
446,
23705,
18227,
315,
652,
503,
2018,
12,
5461,
314,
909,
1402,
12,
5423,
14,
199,
199,
3,
3709,
652,
365,
7131,
687,
314,
4465,
6869,
12,
652,
9999,
5171,
2018,
199,
3,
465,
282,
2884,
316,
2637,
446,
11150,
314,
16864,
13584,
883,
506,
18794,
8336,
12,
199,
3,
436,
4079,
641,
314,
2884,
1233,
1265,
5341,
14,
199,
199,
646,
1134,
1579,
199,
504,
4747,
708,
957,
14,
1219,
1579,
492,
2185,
1579,
199,
199,
504,
1134,
1579,
492,
14771,
9699,
12,
3307,
12,
2186,
12,
428,
2944,
1772,
1481,
2472,
63,
27240,
18074,
1075,
199,
199,
2713,
11772,
63,
1981,
19514,
275,
5041,
645,
29399,
69,
2259,
13,
67,
27370,
13,
845,
68,
16,
13,
25,
67,
821,
13,
383,
2158,
383,
6889,
65,
2905,
6834,
199,
199,
533,
437,
56,
5229,
1646,
8,
647,
1579,
14,
9839,
5229,
1646,
304,
199,
198,
1529,
199,
199,
533,
16198,
5229,
1646,
8,
647,
1579,
14,
7989,
5229,
1646,
304,
199,
198,
1529,
421,
199,
533,
1611,
5229,
8,
647,
1579,
14,
2713,
5229,
304,
199,
198,
1529,
421,
199,
318,
11828,
837,
199,
198,
646,
984,
199,
198,
692,
2475,
68,
7,
315,
984,
14,
3020,
26,
507,
198,
14913,
275,
298,
15461,
8886,
708,
3446,
2,
507,
198,
1757,
63,
3257,
275,
298,
1689,
11,
14913,
21425,
2,
507,
198,
1757,
63,
1422,
275,
298,
12555,
2,
199,
198,
2836,
26,
507,
198,
14913,
275,
488,
507,
198,
1757,
63,
3257,
275,
3087,
507,
198,
1757,
63,
1422,
275,
3087,
421,
198,
8906,
275,
359,
1219,
1579,
14,
11206,
998,
63,
7472,
5229,
12,
1219,
1579,
14,
11206,
998,
63,
7472,
5229,
4003,
61,
199,
198,
429,
4148,
275,
1611,
11772,
63,
1981,
19514,
199,
198,
76,
7504,
275,
378,
88,
966,
1643,
327,
5001,
20171,
1891,
199,
198,
3185,
275,
488,
327,
298,
2676,
708,
957,
14,
1219,
1579,
14,
1258,
14,
1219,
83,
3185,
14,
9839,
5229,
4845,
2,
421,
198,
1361,
298,
7099,
316,
18877,
1654,
5,
83,
11500,
450,
3105,
63,
3257,
199,
198,
504,
4747,
708,
957,
14,
1000,
14,
2683,
492,
11828,
3120,
421,
198,
3671,
985,
275,
298,
2713,
11772,
2,
199,
198,
422,
919,
71,
1304,
275,
298,
4718,
14,
28593,
14,
17,
2,
199,
198,
7099,
3120,
8,
429,
4148,
275,
824,
4148,
12,
2366,
10083,
1558,
275,
298,
2676,
708,
957,
14,
1219,
1579,
14,
1258,
14,
647,
1579,
14,
2713,
28593,
401,
221,
2432,
1021,
985,
275,
298,
4718,
14245,
1540,
15,
11772,
316,
23241,
56,
14914,
316,
12580,
401,
507,
7861,
13205,
998,
275,
2637,
985,
12,
809,
919,
71,
998,
275,
809,
919,
71,
1304,
12,
2432,
1704,
280,
795,
275,
9695,
12,
221,
2432,
4592,
29,
3185,
12,
17475,
275,
17475,
9,
421,
198,
2499,
2872,
1197,
8,
3671,
985,
435,
9926,
2228,
654,
1669,
531,
199,
198,
3,
10082,
20764,
367,
336,
609,
14,
199,
198,
2676,
708,
957,
14,
1000,
14,
2683,
423,
409,
63,
875,
9520,
15983,
11772,
401,
298,
15983,
11772,
1173,
531,
199,
198,
2676,
708,
957,
14,
1000,
14,
2683,
423,
409,
63,
875,
480,
15983,
11772,
1173,
1103,
5229,
8524,
401,
2637,
985,
9,
199,
198,
1361,
298,
11772,
316,
7146,
7264,
2122,
507,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
7099,
342,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1134,
2724,
281,
14,
647,
199,
3,
199,
3,
961,
365,
3769,
26731,
641,
446,
652,
1630,
440,
5966,
1736,
737,
1006,
12,
315,
282,
89,
4340,
199,
3,
2215,
503,
1824,
22901,
9,
199,
3,
199,
3,
437,
892,
2884,
6869,
12,
7131,
687,
314,
4465,
2884,
316,
6869,
12,
199,
3,
1314,
16864,
2556,
14,
199,
199,
3,
961,
16711,
883,
506,
1202,
370,
18200,
1006,
30313,
402,
2997,
2436,
3595,
199,
3,
376,
6869,
446,
23705,
18227,
315,
652,
503,
2018,
12,
5461,
314,
909,
1402,
12,
5423,
14,
199,
199,
3,
3709,
652,
365,
7131,
687,
314,
4465,
6869,
12,
652,
9999,
5171,
2018,
199,
3,
465,
282,
2884,
316,
2637,
446,
11150,
314,
16864,
13584,
883,
506,
18794,
8336,
12,
199,
3,
436,
4079,
641,
314,
2884,
1233,
1265,
5341,
14,
199,
199,
646,
1134,
1579,
199,
504,
4747,
708,
957,
14,
1219,
1579,
492,
2185,
1579,
199,
199,
504,
1134,
1579,
492,
14771,
9699,
12,
3307,
12,
2186,
12,
428,
2944,
1772,
1481,
2472,
63,
27240,
18074,
1075,
199,
199,
2713,
11772,
63,
1981,
19514,
275,
5041,
645,
29399,
69,
2259,
13,
67,
27370,
13,
845,
68,
16,
13,
25,
67,
821,
13,
383,
2158,
383,
6889,
65,
2905,
6834,
199,
199,
533,
437,
56,
5229,
1646,
8,
647,
1579,
14,
9839,
5229,
1646,
304,
199,
198,
1529,
199,
199,
533,
16198,
5229,
1646,
8,
647,
1579,
14,
7989,
5229,
1646,
304,
199,
198,
1529,
421,
199,
533,
1611,
5229,
8,
647,
1579,
14,
2713,
5229,
304,
199,
198,
1529,
421,
199,
318,
11828,
837,
199,
198,
646,
984,
199,
198,
692,
2475,
68,
7,
315,
984,
14,
3020,
26,
507,
198,
14913,
275,
298,
15461,
8886,
708,
3446,
2,
507,
198,
1757,
63,
3257,
275,
298,
1689,
11,
14913,
21425,
2,
507,
198,
1757,
63,
1422,
275,
298,
12555,
2,
199,
198,
2836,
26,
507,
198,
14913,
275,
488,
507,
198,
1757,
63,
3257,
275,
3087,
507,
198,
1757,
63,
1422,
275,
3087,
421,
198,
8906,
275,
359,
1219,
1579,
14,
11206,
998,
63,
7472,
5229,
12,
1219,
1579,
14,
11206,
998,
63,
7472,
5229,
4003,
61,
199,
198,
429,
4148,
275,
1611,
11772,
63,
1981,
19514,
199,
198,
76,
7504,
275,
378,
88,
966,
1643,
327,
5001,
20171,
1891,
199,
198,
3185,
275,
488,
327,
298,
2676,
708,
957,
14,
1219,
1579,
14,
1258,
14,
1219,
83,
3185,
14,
9839,
5229,
4845,
2,
421,
198,
1361,
298,
7099,
316,
18877,
1654,
5,
83,
11500,
450,
3105,
63,
3257,
199,
198,
504,
4747,
708,
957,
14,
1000,
14,
2683,
492,
11828,
3120,
421,
198,
3671,
985,
275,
298,
2713,
11772,
2,
199,
198,
422,
919,
71,
1304,
275,
298,
4718,
14,
28593,
14,
17,
2,
199,
198,
7099,
3120,
8,
429,
4148,
275,
824,
4148,
12,
2366,
10083,
1558,
275,
298,
2676,
708,
957,
14,
1219,
1579,
14,
1258,
14,
647,
1579,
14,
2713,
28593,
401,
221,
2432,
1021,
985,
275,
298,
4718,
14245,
1540,
15,
11772,
316,
23241,
56,
14914,
316,
12580,
401,
507,
7861,
13205,
998,
275,
2637,
985,
12,
809,
919,
71,
998,
275,
809,
919,
71,
1304,
12,
2432,
1704,
280,
795,
275,
9695,
12,
221,
2432,
4592,
29,
3185,
12,
17475,
275,
17475,
9,
421,
198,
2499,
2872,
1197,
8,
3671,
985,
435,
9926,
2228,
654,
1669,
531,
199,
198,
3,
10082,
20764,
367,
336,
609,
14,
199,
198,
2676,
708,
957,
14,
1000,
14,
2683,
423,
409,
63,
875,
9520,
15983,
11772,
401,
298,
15983,
11772,
1173,
531,
199,
198,
2676,
708,
957,
14,
1000,
14,
2683,
423,
409,
63,
875,
480,
15983,
11772,
1173,
1103,
5229,
8524,
401,
2637,
985,
9,
199,
198,
1361,
298,
11772,
316,
7146,
7264,
2122,
507,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
7099,
342,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
urfonline/api
|
config/settings/base.py
|
1
|
11017
|
"""
Django settings for api project.
For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""
import environ
ROOT_DIR = environ.Path(__file__) - 3 # (api/config/settings/base.py - 3 = api/)
APPS_DIR = ROOT_DIR.path('api')
# Load operating system environment variables and then prepare to use them
env = environ.Env()
# .env file, should load only in development environment
READ_DOT_ENV_FILE = env.bool('DJANGO_READ_DOT_ENV_FILE', default=False)
if READ_DOT_ENV_FILE:
# Operating System Environment variables have precedence over variables defined in the .env file,
# that is to say variables from the .env files will only be used if not defined
# as environment variables.
env_file = str(ROOT_DIR.path('.env'))
print('Loading : {}'.format(env_file))
env.read_env(env_file)
print('The .env file has been loaded. See base.py for more information')
# APP CONFIGURATION
# ------------------------------------------------------------------------------
DJANGO_APPS = [
# Default Django apps:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Useful template tags:
# 'django.contrib.humanize',
# Admin
'django.contrib.admin',
]
THIRD_PARTY_APPS = [
'corsheaders',
'rest_framework',
'rest_framework.authtoken',
'graphene_django',
'solo',
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
'wagtail.api.v2',
'wagtail.contrib.modeladmin',
'modelcluster',
'taggit',
]
LOCAL_APPS = [
'api.core.apps.CoreConfig',
'api.users.apps.UsersConfig',
'api.shows.apps.ShowsConfig',
'api.schema.apps.SchemaConfig',
'api.events.apps.EventsConfig',
'api.articles.apps.ArticlesConfig',
'api.home.apps.HomeConfig',
'api.streams.apps.StreamConfig',
'api.applications.apps.ApplicationsConfig',
'api.podcasts.apps.PodcastConfig',
'api.elections.apps.ElectionsConfig',
#'api.feed.apps.FeedConfig',
#'api.articles.apps.ArticlesConfig',
]
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
# MIDDLEWARE CONFIGURATION
# ------------------------------------------------------------------------------
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
]
WAGTAIL_SITE_NAME = 'URF Online'
# MIGRATIONS CONFIGURATION
# ------------------------------------------------------------------------------
MIGRATION_MODULES = {
'sites': 'api.contrib.sites.migrations'
}
# DEBUG
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool('DJANGO_DEBUG', False)
# FIXTURE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (
str(APPS_DIR.path('fixtures')),
)
# EMAIL CONFIGURATION
# ------------------------------------------------------------------------------
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
# MANAGER CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
ADMINS = [
("""URF Online""", 'james@brudil.com'),
]
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS
# DATABASE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': env.db('DATABASE_URL', default='postgres:///api'),
}
DATABASES['default']['ATOMIC_REQUESTS'] = True
# GENERAL CONFIGURATION
# ------------------------------------------------------------------------------
# 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.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'UTC'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
LANGUAGE_CODE = 'en-us'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
SITE_ID = 1
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
USE_I18N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
USE_L10N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
USE_TZ = True
# TEMPLATE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#templates
TEMPLATES = [
{
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
'DIRS': [
str(APPS_DIR.path('templates')),
],
'OPTIONS': {
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
'debug': DEBUG,
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
# Your stuff: custom template context processors go here
],
},
},
]
# STATIC FILE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(ROOT_DIR('staticfiles'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/'
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = [
str(APPS_DIR.path('static')),
]
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
# MEDIA CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = str(APPS_DIR('media'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = '/media/'
# URL Configuration
# ------------------------------------------------------------------------------
ROOT_URLCONF = 'config.urls'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = 'config.wsgi.application'
# PASSWORD STORAGE SETTINGS
# ------------------------------------------------------------------------------
# See https://docs.djangoproject.com/en/dev/topics/auth/passwords/#using-argon2-with-django
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.Argon2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
]
# PASSWORD VALIDATION
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
# ------------------------------------------------------------------------------
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# AUTHENTICATION CONFIGURATION
# ------------------------------------------------------------------------------
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
]
# Some really nice defaults
ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_ALLOW_REGISTRATION = env.bool('DJANGO_ACCOUNT_ALLOW_REGISTRATION', True)
ACCOUNT_ADAPTER = 'api.users.adapters.AccountAdapter'
SOCIALACCOUNT_ADAPTER = 'api.users.adapters.SocialAccountAdapter'
# Custom user app defaults
# Select the correct user model
AUTH_USER_MODEL = 'users.User'
LOGIN_REDIRECT_URL = 'users:redirect'
LOGIN_URL = 'account_login'
# Location of root django.contrib.admin URL, use {% url 'admin:index' %}
ADMIN_URL = 'admin/'
# Your common stuff: Below this line define 3rd party library settings
GRAPHENE = {
'SCHEMA': 'api.schema.schema.schema' # Where your Graphene schema lives
}
WAGTAILIMAGES_IMAGE_MODEL = 'core.UrfImage'
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
|
mit
|
[
624,
199,
9323,
2202,
367,
2986,
2199,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
15,
199,
624,
199,
646,
6160,
199,
199,
5441,
63,
3022,
275,
6160,
14,
2042,
3460,
493,
3368,
446,
650,
221,
327,
334,
1246,
15,
888,
15,
1751,
15,
1095,
14,
647,
446,
650,
275,
2986,
24793,
199,
14219,
63,
3022,
275,
16547,
63,
3022,
14,
515,
360,
1246,
358,
199,
199,
3,
7190,
17406,
2656,
3734,
2860,
436,
2066,
9275,
370,
675,
3062,
199,
1813,
275,
6160,
14,
7744,
342,
199,
199,
3,
1275,
1813,
570,
12,
1077,
2248,
1454,
315,
16367,
3734,
199,
5670,
63,
13203,
63,
9984,
63,
3817,
275,
2589,
14,
2245,
360,
22848,
63,
5670,
63,
13203,
63,
9984,
63,
3817,
297,
849,
29,
797,
9,
199,
199,
692,
16767,
63,
13203,
63,
9984,
63,
3817,
26,
272,
327,
6654,
1958,
6187,
9711,
2860,
1172,
13823,
1806,
2860,
3247,
315,
314,
1275,
1813,
570,
12,
272,
327,
626,
365,
370,
14722,
2860,
687,
314,
1275,
1813,
1584,
911,
1454,
506,
1202,
340,
440,
3247,
272,
327,
465,
3734,
2860,
14,
272,
2589,
63,
493,
275,
620,
8,
5441,
63,
3022,
14,
515,
5175,
1813,
1333,
272,
870,
360,
19236,
520,
9499,
908,
8,
1813,
63,
493,
430,
272,
2589,
14,
739,
63,
1813,
8,
1813,
63,
493,
9,
272,
870,
360,
1918,
1275,
1813,
570,
965,
2757,
6511,
14,
1666,
1300,
14,
647,
367,
1655,
2556,
358,
199,
199,
3,
19525,
15869,
15301,
199,
3,
5620,
10965,
199,
22848,
63,
14219,
275,
359,
272,
327,
3758,
5634,
8686,
26,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
8619,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
339,
327,
18491,
1978,
3762,
26,
272,
327,
283,
1176,
14,
2828,
14,
14864,
794,
297,
339,
327,
9516,
272,
283,
1176,
14,
2828,
14,
2113,
297,
199,
61,
199,
2080,
3927,
36,
63,
4014,
2099,
63,
14219,
275,
359,
272,
283,
30967,
2139,
297,
272,
283,
3911,
63,
4857,
297,
272,
283,
3911,
63,
4857,
14,
1178,
1418,
297,
272,
283,
2180,
6349,
63,
1176,
297,
272,
283,
1152,
320,
297,
272,
283,
29339,
762,
297,
221,
327,
10991,
272,
283,
29339,
762,
14,
2048,
297,
221,
327,
10991,
272,
283,
29339,
762,
14,
31932,
297,
221,
327,
10991,
339,
283,
17296,
14,
2828,
14,
3351,
297,
272,
283,
17296,
14,
2828,
14,
13607,
297,
272,
283,
17296,
14,
6427,
83,
297,
272,
283,
17296,
14,
8619,
297,
272,
283,
17296,
14,
3707,
297,
272,
283,
17296,
14,
32566,
297,
272,
283,
17296,
14,
12233,
297,
272,
283,
17296,
14,
4782,
297,
272,
283,
17296,
14,
1733,
297,
272,
283,
17296,
14,
2113,
297,
272,
283,
17296,
14,
1018,
297,
272,
283,
17296,
14,
1246,
14,
86,
18,
297,
272,
283,
17296,
14,
2828,
14,
1238,
2113,
297,
272,
283,
1238,
4201,
297,
272,
283,
1450,
3187,
297,
199,
61,
199,
199,
7486,
63,
14219,
275,
359,
272,
283,
1246,
14,
1018,
14,
5181,
14,
5402,
2028,
297,
272,
283,
1246,
14,
3707,
14,
5181,
14,
12117,
2028,
297,
272,
283,
1246,
14,
23866,
14,
5181,
14,
6824,
83,
2028,
297,
272,
283,
1246,
14,
3629,
14,
5181,
14,
6700,
2028,
297,
272,
283,
1246,
14,
4368,
14,
5181,
14,
11770,
2028,
297,
272,
283,
1246,
14,
19813,
14,
5181,
14,
7221,
83,
2028,
297,
272,
283,
1246,
14,
4219,
14,
5181,
14,
12054,
2028,
297,
272,
283,
1246,
14,
11231,
14,
5181,
14,
3296,
2028,
297,
272,
283,
1246,
14,
15853,
14,
5181,
14,
31907,
2028,
297,
272,
283,
1246,
14,
12656,
2931,
83,
14,
5181,
14,
25928,
2931,
2028,
297,
272,
283,
1246,
14,
28507,
83,
14,
5181,
14,
37,
1486,
83,
2028,
297,
272,
17384,
1246,
14,
3871,
14,
5181,
14,
7658,
2028,
297,
272,
17384,
1246,
14,
19813,
14,
5181,
14,
7221,
83,
2028,
297,
199,
61,
199,
199,
15942,
63,
14219,
275,
577,
42,
18822,
63,
14219,
435,
4221,
3927,
36,
63,
4014,
2099,
63,
14219,
435,
20639,
63,
14219,
199,
199,
3,
30718,
15869,
15301,
199,
3,
5620,
10965,
199,
19987,
275,
359,
272,
283,
30967,
2139,
14,
5754,
14,
35,
1384,
6608,
297,
339,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
339,
283,
17296,
14,
2828,
14,
13607,
14,
5754,
14,
7071,
6608,
297,
199,
61,
199,
199,
55,
1254,
30890,
63,
7917,
63,
2339,
275,
283,
1230,
38,
4068,
604,
7,
199,
199,
3,
603,
1277,
50,
12969,
15869,
15301,
199,
3,
5620,
10965,
199,
22487,
23743,
63,
21194,
275,
469,
272,
283,
8619,
356,
283,
1246,
14,
2828,
14,
8619,
14,
7685,
7,
199,
93,
199,
199,
3,
10990,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
1757,
199,
5287,
275,
2589,
14,
2245,
360,
22848,
63,
5287,
297,
756,
9,
199,
199,
3,
7333,
52,
3942,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
1516,
26,
6031,
13,
5192,
52,
3942,
63,
14455,
199,
5192,
52,
3942,
63,
14455,
275,
334,
272,
620,
8,
14219,
63,
3022,
14,
515,
360,
8769,
3855,
199,
9
] |
[
199,
9323,
2202,
367,
2986,
2199,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
15,
199,
624,
199,
646,
6160,
199,
199,
5441,
63,
3022,
275,
6160,
14,
2042,
3460,
493,
3368,
446,
650,
221,
327,
334,
1246,
15,
888,
15,
1751,
15,
1095,
14,
647,
446,
650,
275,
2986,
24793,
199,
14219,
63,
3022,
275,
16547,
63,
3022,
14,
515,
360,
1246,
358,
199,
199,
3,
7190,
17406,
2656,
3734,
2860,
436,
2066,
9275,
370,
675,
3062,
199,
1813,
275,
6160,
14,
7744,
342,
199,
199,
3,
1275,
1813,
570,
12,
1077,
2248,
1454,
315,
16367,
3734,
199,
5670,
63,
13203,
63,
9984,
63,
3817,
275,
2589,
14,
2245,
360,
22848,
63,
5670,
63,
13203,
63,
9984,
63,
3817,
297,
849,
29,
797,
9,
199,
199,
692,
16767,
63,
13203,
63,
9984,
63,
3817,
26,
272,
327,
6654,
1958,
6187,
9711,
2860,
1172,
13823,
1806,
2860,
3247,
315,
314,
1275,
1813,
570,
12,
272,
327,
626,
365,
370,
14722,
2860,
687,
314,
1275,
1813,
1584,
911,
1454,
506,
1202,
340,
440,
3247,
272,
327,
465,
3734,
2860,
14,
272,
2589,
63,
493,
275,
620,
8,
5441,
63,
3022,
14,
515,
5175,
1813,
1333,
272,
870,
360,
19236,
520,
9499,
908,
8,
1813,
63,
493,
430,
272,
2589,
14,
739,
63,
1813,
8,
1813,
63,
493,
9,
272,
870,
360,
1918,
1275,
1813,
570,
965,
2757,
6511,
14,
1666,
1300,
14,
647,
367,
1655,
2556,
358,
199,
199,
3,
19525,
15869,
15301,
199,
3,
5620,
10965,
199,
22848,
63,
14219,
275,
359,
272,
327,
3758,
5634,
8686,
26,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
8619,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
339,
327,
18491,
1978,
3762,
26,
272,
327,
283,
1176,
14,
2828,
14,
14864,
794,
297,
339,
327,
9516,
272,
283,
1176,
14,
2828,
14,
2113,
297,
199,
61,
199,
2080,
3927,
36,
63,
4014,
2099,
63,
14219,
275,
359,
272,
283,
30967,
2139,
297,
272,
283,
3911,
63,
4857,
297,
272,
283,
3911,
63,
4857,
14,
1178,
1418,
297,
272,
283,
2180,
6349,
63,
1176,
297,
272,
283,
1152,
320,
297,
272,
283,
29339,
762,
297,
221,
327,
10991,
272,
283,
29339,
762,
14,
2048,
297,
221,
327,
10991,
272,
283,
29339,
762,
14,
31932,
297,
221,
327,
10991,
339,
283,
17296,
14,
2828,
14,
3351,
297,
272,
283,
17296,
14,
2828,
14,
13607,
297,
272,
283,
17296,
14,
6427,
83,
297,
272,
283,
17296,
14,
8619,
297,
272,
283,
17296,
14,
3707,
297,
272,
283,
17296,
14,
32566,
297,
272,
283,
17296,
14,
12233,
297,
272,
283,
17296,
14,
4782,
297,
272,
283,
17296,
14,
1733,
297,
272,
283,
17296,
14,
2113,
297,
272,
283,
17296,
14,
1018,
297,
272,
283,
17296,
14,
1246,
14,
86,
18,
297,
272,
283,
17296,
14,
2828,
14,
1238,
2113,
297,
272,
283,
1238,
4201,
297,
272,
283,
1450,
3187,
297,
199,
61,
199,
199,
7486,
63,
14219,
275,
359,
272,
283,
1246,
14,
1018,
14,
5181,
14,
5402,
2028,
297,
272,
283,
1246,
14,
3707,
14,
5181,
14,
12117,
2028,
297,
272,
283,
1246,
14,
23866,
14,
5181,
14,
6824,
83,
2028,
297,
272,
283,
1246,
14,
3629,
14,
5181,
14,
6700,
2028,
297,
272,
283,
1246,
14,
4368,
14,
5181,
14,
11770,
2028,
297,
272,
283,
1246,
14,
19813,
14,
5181,
14,
7221,
83,
2028,
297,
272,
283,
1246,
14,
4219,
14,
5181,
14,
12054,
2028,
297,
272,
283,
1246,
14,
11231,
14,
5181,
14,
3296,
2028,
297,
272,
283,
1246,
14,
15853,
14,
5181,
14,
31907,
2028,
297,
272,
283,
1246,
14,
12656,
2931,
83,
14,
5181,
14,
25928,
2931,
2028,
297,
272,
283,
1246,
14,
28507,
83,
14,
5181,
14,
37,
1486,
83,
2028,
297,
272,
17384,
1246,
14,
3871,
14,
5181,
14,
7658,
2028,
297,
272,
17384,
1246,
14,
19813,
14,
5181,
14,
7221,
83,
2028,
297,
199,
61,
199,
199,
15942,
63,
14219,
275,
577,
42,
18822,
63,
14219,
435,
4221,
3927,
36,
63,
4014,
2099,
63,
14219,
435,
20639,
63,
14219,
199,
199,
3,
30718,
15869,
15301,
199,
3,
5620,
10965,
199,
19987,
275,
359,
272,
283,
30967,
2139,
14,
5754,
14,
35,
1384,
6608,
297,
339,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
339,
283,
17296,
14,
2828,
14,
13607,
14,
5754,
14,
7071,
6608,
297,
199,
61,
199,
199,
55,
1254,
30890,
63,
7917,
63,
2339,
275,
283,
1230,
38,
4068,
604,
7,
199,
199,
3,
603,
1277,
50,
12969,
15869,
15301,
199,
3,
5620,
10965,
199,
22487,
23743,
63,
21194,
275,
469,
272,
283,
8619,
356,
283,
1246,
14,
2828,
14,
8619,
14,
7685,
7,
199,
93,
199,
199,
3,
10990,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
1757,
199,
5287,
275,
2589,
14,
2245,
360,
22848,
63,
5287,
297,
756,
9,
199,
199,
3,
7333,
52,
3942,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
26,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
12645,
1516,
26,
6031,
13,
5192,
52,
3942,
63,
14455,
199,
5192,
52,
3942,
63,
14455,
275,
334,
272,
620,
8,
14219,
63,
3022,
14,
515,
360,
8769,
3855,
199,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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kitpy/layout_tests/layout_package/json_results_generator.py
|
42
|
4812
|
# Copyright (C) 2010 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import json
import logging
_log = logging.getLogger(__name__)
_JSON_PREFIX = "ADD_RESULTS("
_JSON_SUFFIX = ");"
def has_json_wrapper(string):
return string.startswith(_JSON_PREFIX) and string.endswith(_JSON_SUFFIX)
def strip_json_wrapper(json_content):
# FIXME: Kill this code once the server returns json instead of jsonp.
if has_json_wrapper(json_content):
return json_content[len(_JSON_PREFIX):len(json_content) - len(_JSON_SUFFIX)]
return json_content
def load_json(filesystem, file_path):
content = filesystem.read_text_file(file_path)
content = strip_json_wrapper(content)
return json.loads(content)
def write_json(filesystem, json_object, file_path, callback=None):
# Specify separators in order to get compact encoding.
json_string = json.dumps(json_object, separators=(',', ':'))
if callback:
json_string = callback + "(" + json_string + ");"
filesystem.write_text_file(file_path, json_string)
def convert_trie_to_flat_paths(trie, prefix=None):
"""Converts the directory structure in the given trie to flat paths, prepending a prefix to each."""
result = {}
for name, data in trie.iteritems():
if prefix:
name = prefix + "/" + name
if len(data) and not "results" in data:
result.update(convert_trie_to_flat_paths(data, name))
else:
result[name] = data
return result
def add_path_to_trie(path, value, trie):
"""Inserts a single flat directory path and associated value into a directory trie structure."""
if not "/" in path:
trie[path] = value
return
directory, slash, rest = path.partition("/")
if not directory in trie:
trie[directory] = {}
add_path_to_trie(rest, value, trie[directory])
def test_timings_trie(individual_test_timings):
"""Breaks a test name into chunks by directory and puts the test time as a value in the lowest part, e.g.
foo/bar/baz.html: 1ms
foo/bar/baz1.html: 3ms
becomes
foo: {
bar: {
baz.html: 1,
baz1.html: 3
}
}
"""
trie = {}
for test_result in individual_test_timings:
test = test_result.test_name
add_path_to_trie(test, int(1000 * test_result.test_run_time), trie)
return trie
# FIXME: We already have a TestResult class in test_results.py
class TestResult(object):
"""A simple class that represents a single test result."""
# Test modifier constants.
(NONE, FAILS, FLAKY, DISABLED) = range(4)
def __init__(self, test, failed=False, elapsed_time=0):
self.test_name = test
self.failed = failed
self.test_run_time = elapsed_time
test_name = test
try:
test_name = test.split('.')[1]
except IndexError:
_log.warn("Invalid test name: %s.", test)
pass
if test_name.startswith('FAILS_'):
self.modifier = self.FAILS
elif test_name.startswith('FLAKY_'):
self.modifier = self.FLAKY
elif test_name.startswith('DISABLED_'):
self.modifier = self.DISABLED
else:
self.modifier = self.NONE
def fixable(self):
return self.failed or self.modifier == self.DISABLED
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2022,
199,
646,
2050,
199,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
63,
6243,
63,
6351,
275,
298,
9732,
63,
23545,
480,
199,
63,
6243,
63,
12273,
275,
298,
27556,
421,
199,
318,
965,
63,
1001,
63,
5029,
8,
875,
304,
272,
372,
1059,
14,
2460,
1547,
6243,
63,
6351,
9,
436,
1059,
14,
4130,
1547,
6243,
63,
12273,
9,
421,
199,
318,
6202,
63,
1001,
63,
5029,
8,
1001,
63,
1317,
304,
272,
327,
7600,
26,
1804,
778,
642,
1233,
5403,
314,
1654,
2529,
2022,
3140,
402,
2022,
80,
14,
272,
340,
965,
63,
1001,
63,
5029,
8,
1001,
63,
1317,
304,
267,
372,
2022,
63,
1317,
59,
552,
1547,
6243,
63,
6351,
304,
552,
8,
1001,
63,
1317,
9,
446,
822,
1547,
6243,
63,
12273,
1874,
272,
372,
2022,
63,
1317,
421,
199,
318,
2248,
63,
1001,
8,
11381,
12,
570,
63,
515,
304,
272,
1564,
275,
10036,
14,
739,
63,
505,
63,
493,
8,
493,
63,
515,
9,
272,
1564,
275,
6202,
63,
1001,
63,
5029,
8,
1317,
9,
272,
372,
2022,
14,
3640,
8,
1317,
9,
421,
199,
318,
2218,
63,
1001,
8,
11381,
12,
2022,
63,
785,
12,
570,
63,
515,
12,
3233,
29,
403,
304,
272,
327,
13327,
17658,
315,
1865,
370,
664,
23314,
2644,
14,
272,
2022,
63,
875,
275,
2022,
14,
4180,
8,
1001,
63,
785,
12,
17658,
2687,
23324,
7596,
1333,
272,
340,
3233,
26,
267,
2022,
63,
875,
275,
3233,
435,
26054,
435,
2022,
63,
875,
435,
298,
27556,
272,
10036,
14,
952,
63,
505,
63,
493,
8,
493,
63,
515,
12,
2022,
63,
875,
9,
421,
199,
318,
3957,
63,
599,
69,
63,
475,
63,
7088,
63,
3771,
8,
599,
69,
12,
2403,
29,
403,
304,
272,
408,
17729,
314,
2082,
5523,
315,
314,
1627,
3229,
69,
370,
6829,
3792,
12,
876,
6455,
282,
2403,
370,
1924,
1041,
272,
754,
275,
1052,
272,
367,
536,
12,
666,
315,
3229,
69,
14,
4611,
837,
267,
340,
2403,
26,
288,
536,
275,
2403,
435,
10609,
435,
536,
398,
340,
822,
8,
576,
9,
436,
440,
298,
2604,
2,
315,
666,
26,
288,
754,
14,
873,
8,
3916,
63,
599,
69,
63,
475,
63,
7088,
63,
3771,
8,
576,
12,
536,
430,
267,
587,
26,
288,
754,
59,
354,
61,
275,
666,
339,
372,
754,
421,
199,
318,
1050,
63,
515,
63,
475,
63,
599,
69,
8,
515,
12,
574,
12,
3229,
69,
304,
272,
408,
9971,
83,
282,
2849,
6829,
2082,
931,
436,
4568,
574,
1901,
282,
2082,
3229,
69,
5523,
1041,
272,
340,
440,
10609,
315,
931,
26,
267,
3229,
69,
59,
515,
61,
275,
574,
267,
372,
339,
2082,
12,
14457,
12,
4618,
275,
931,
14,
5312,
19031,
272,
340,
440,
2082,
315,
3229,
69,
26,
267,
3229,
69,
59,
3619,
61,
275,
1052,
272,
1050,
63,
515,
63,
475,
63,
599,
69,
8,
3911,
12,
574,
12,
3229,
69,
59,
3619,
566,
421,
199,
318,
511,
63,
27337,
63,
599,
69,
8,
23001,
63,
396,
63,
27337,
304,
272,
408,
13948,
83,
282,
511,
536,
1901,
8291,
701,
2082,
436,
27000,
314,
511,
900,
465,
282,
574,
315,
314,
18966,
1777,
12,
325,
14,
71,
14,
272,
3925,
15,
1700,
15,
6185,
14,
1360,
26,
413,
706,
272,
3925,
15,
1700,
15,
6185,
17,
14,
1360,
26,
650,
706,
339,
15410,
272,
3925,
26,
469,
267,
4681,
26,
469,
288,
15507,
14,
1360,
26,
413,
12,
288,
15507,
17,
14,
1360,
26,
650,
267,
789,
272,
789,
272,
408,
272,
3229,
69,
275,
1052,
272,
367,
511,
63,
1099,
315,
8212,
63,
396,
63,
27337,
26,
267,
511,
275,
511,
63,
1099,
14,
396,
63,
354,
398,
1050,
63,
515,
63,
475,
63,
599,
69,
8,
396,
12,
1109,
8,
5279,
627,
511,
63,
1099,
14,
396,
63,
1065,
63,
521,
395,
3229,
69,
9,
339,
372,
3229,
69,
421,
199,
3,
7600,
26,
2136,
2575,
1172,
282,
23795,
1021,
315,
511,
63,
2604,
14,
647,
199,
533,
23795,
8,
785,
304,
272,
408,
33,
3486,
1021,
626,
8469,
282,
2849,
511,
754,
1041,
339,
327,
1379,
17880,
5262,
14,
272,
334,
9185,
12,
10341,
51,
12,
481,
5837,
32640,
12,
32147,
36,
9
] |
[
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2022,
199,
646,
2050,
199,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
63,
6243,
63,
6351,
275,
298,
9732,
63,
23545,
480,
199,
63,
6243,
63,
12273,
275,
298,
27556,
421,
199,
318,
965,
63,
1001,
63,
5029,
8,
875,
304,
272,
372,
1059,
14,
2460,
1547,
6243,
63,
6351,
9,
436,
1059,
14,
4130,
1547,
6243,
63,
12273,
9,
421,
199,
318,
6202,
63,
1001,
63,
5029,
8,
1001,
63,
1317,
304,
272,
327,
7600,
26,
1804,
778,
642,
1233,
5403,
314,
1654,
2529,
2022,
3140,
402,
2022,
80,
14,
272,
340,
965,
63,
1001,
63,
5029,
8,
1001,
63,
1317,
304,
267,
372,
2022,
63,
1317,
59,
552,
1547,
6243,
63,
6351,
304,
552,
8,
1001,
63,
1317,
9,
446,
822,
1547,
6243,
63,
12273,
1874,
272,
372,
2022,
63,
1317,
421,
199,
318,
2248,
63,
1001,
8,
11381,
12,
570,
63,
515,
304,
272,
1564,
275,
10036,
14,
739,
63,
505,
63,
493,
8,
493,
63,
515,
9,
272,
1564,
275,
6202,
63,
1001,
63,
5029,
8,
1317,
9,
272,
372,
2022,
14,
3640,
8,
1317,
9,
421,
199,
318,
2218,
63,
1001,
8,
11381,
12,
2022,
63,
785,
12,
570,
63,
515,
12,
3233,
29,
403,
304,
272,
327,
13327,
17658,
315,
1865,
370,
664,
23314,
2644,
14,
272,
2022,
63,
875,
275,
2022,
14,
4180,
8,
1001,
63,
785,
12,
17658,
2687,
23324,
7596,
1333,
272,
340,
3233,
26,
267,
2022,
63,
875,
275,
3233,
435,
26054,
435,
2022,
63,
875,
435,
298,
27556,
272,
10036,
14,
952,
63,
505,
63,
493,
8,
493,
63,
515,
12,
2022,
63,
875,
9,
421,
199,
318,
3957,
63,
599,
69,
63,
475,
63,
7088,
63,
3771,
8,
599,
69,
12,
2403,
29,
403,
304,
272,
408,
17729,
314,
2082,
5523,
315,
314,
1627,
3229,
69,
370,
6829,
3792,
12,
876,
6455,
282,
2403,
370,
1924,
1041,
272,
754,
275,
1052,
272,
367,
536,
12,
666,
315,
3229,
69,
14,
4611,
837,
267,
340,
2403,
26,
288,
536,
275,
2403,
435,
10609,
435,
536,
398,
340,
822,
8,
576,
9,
436,
440,
298,
2604,
2,
315,
666,
26,
288,
754,
14,
873,
8,
3916,
63,
599,
69,
63,
475,
63,
7088,
63,
3771,
8,
576,
12,
536,
430,
267,
587,
26,
288,
754,
59,
354,
61,
275,
666,
339,
372,
754,
421,
199,
318,
1050,
63,
515,
63,
475,
63,
599,
69,
8,
515,
12,
574,
12,
3229,
69,
304,
272,
408,
9971,
83,
282,
2849,
6829,
2082,
931,
436,
4568,
574,
1901,
282,
2082,
3229,
69,
5523,
1041,
272,
340,
440,
10609,
315,
931,
26,
267,
3229,
69,
59,
515,
61,
275,
574,
267,
372,
339,
2082,
12,
14457,
12,
4618,
275,
931,
14,
5312,
19031,
272,
340,
440,
2082,
315,
3229,
69,
26,
267,
3229,
69,
59,
3619,
61,
275,
1052,
272,
1050,
63,
515,
63,
475,
63,
599,
69,
8,
3911,
12,
574,
12,
3229,
69,
59,
3619,
566,
421,
199,
318,
511,
63,
27337,
63,
599,
69,
8,
23001,
63,
396,
63,
27337,
304,
272,
408,
13948,
83,
282,
511,
536,
1901,
8291,
701,
2082,
436,
27000,
314,
511,
900,
465,
282,
574,
315,
314,
18966,
1777,
12,
325,
14,
71,
14,
272,
3925,
15,
1700,
15,
6185,
14,
1360,
26,
413,
706,
272,
3925,
15,
1700,
15,
6185,
17,
14,
1360,
26,
650,
706,
339,
15410,
272,
3925,
26,
469,
267,
4681,
26,
469,
288,
15507,
14,
1360,
26,
413,
12,
288,
15507,
17,
14,
1360,
26,
650,
267,
789,
272,
789,
272,
408,
272,
3229,
69,
275,
1052,
272,
367,
511,
63,
1099,
315,
8212,
63,
396,
63,
27337,
26,
267,
511,
275,
511,
63,
1099,
14,
396,
63,
354,
398,
1050,
63,
515,
63,
475,
63,
599,
69,
8,
396,
12,
1109,
8,
5279,
627,
511,
63,
1099,
14,
396,
63,
1065,
63,
521,
395,
3229,
69,
9,
339,
372,
3229,
69,
421,
199,
3,
7600,
26,
2136,
2575,
1172,
282,
23795,
1021,
315,
511,
63,
2604,
14,
647,
199,
533,
23795,
8,
785,
304,
272,
408,
33,
3486,
1021,
626,
8469,
282,
2849,
511,
754,
1041,
339,
327,
1379,
17880,
5262,
14,
272,
334,
9185,
12,
10341,
51,
12,
481,
5837,
32640,
12,
32147,
36,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fintech-circle/edx-platform
|
openedx/core/djangoapps/embargo/migrations/0001_initial.py
|
20
|
6043
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django_countries.fields
import django.db.models.deletion
from django.conf import settings
from openedx.core.djangoapps.xmodule_django.models import CourseKeyField
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Country',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('country', django_countries.fields.CountryField(help_text='Two character ISO country code.', unique=True, max_length=2, db_index=True)),
],
options={
'ordering': ['country'],
},
),
migrations.CreateModel(
name='CountryAccessRule',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('rule_type', models.CharField(default=b'blacklist', help_text='Whether to include or exclude the given course. If whitelist countries are specified, then ONLY users from whitelisted countries will be able to access the course. If blacklist countries are specified, then users from blacklisted countries will NOT be able to access the course.', max_length=255, choices=[(b'whitelist', b'Whitelist (allow only these countries)'), (b'blacklist', b'Blacklist (block these countries)')])),
('country', models.ForeignKey(help_text='The country to which this rule applies.', to='embargo.Country')),
],
),
migrations.CreateModel(
name='CourseAccessRuleHistory',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('timestamp', models.DateTimeField(auto_now_add=True, db_index=True)),
('course_key', CourseKeyField(max_length=255, db_index=True)),
('snapshot', models.TextField(null=True, blank=True)),
],
options={
'get_latest_by': 'timestamp',
},
),
migrations.CreateModel(
name='EmbargoedCourse',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('course_id', CourseKeyField(unique=True, max_length=255, db_index=True)),
('embargoed', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='EmbargoedState',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('change_date', models.DateTimeField(auto_now_add=True, verbose_name='Change date')),
('enabled', models.BooleanField(default=False, verbose_name='Enabled')),
('embargoed_countries', models.TextField(help_text=b'A comma-separated list of country codes that fall under U.S. embargo restrictions', blank=True)),
('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, editable=False, to=settings.AUTH_USER_MODEL, null=True, verbose_name='Changed by')),
],
options={
'ordering': ('-change_date',),
'abstract': False,
},
),
migrations.CreateModel(
name='IPFilter',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('change_date', models.DateTimeField(auto_now_add=True, verbose_name='Change date')),
('enabled', models.BooleanField(default=False, verbose_name='Enabled')),
('whitelist', models.TextField(help_text=b'A comma-separated list of IP addresses that should not fall under embargo restrictions.', blank=True)),
('blacklist', models.TextField(help_text=b'A comma-separated list of IP addresses that should fall under embargo restrictions.', blank=True)),
('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, editable=False, to=settings.AUTH_USER_MODEL, null=True, verbose_name='Changed by')),
],
options={
'ordering': ('-change_date',),
'abstract': False,
},
),
migrations.CreateModel(
name='RestrictedCourse',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('course_key', CourseKeyField(help_text='The course key for the restricted course.', unique=True, max_length=255, db_index=True)),
('enroll_msg_key', models.CharField(default=b'default', help_text='The message to show when a user is blocked from enrollment.', max_length=255, choices=[(b'default', b'Default'), (b'embargo', b'Embargo')])),
('access_msg_key', models.CharField(default=b'default', help_text='The message to show when a user is blocked from accessing a course.', max_length=255, choices=[(b'default', b'Default'), (b'embargo', b'Embargo')])),
('disable_access_check', models.BooleanField(default=False, help_text='Allow users who enrolled in an allowed country to access restricted courses from excluded countries.')),
],
),
migrations.AddField(
model_name='countryaccessrule',
name='restricted_course',
field=models.ForeignKey(help_text='The course to which this rule applies.', to='embargo.RestrictedCourse'),
),
migrations.AlterUniqueTogether(
name='countryaccessrule',
unique_together=set([('restricted_course', 'country')]),
),
]
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
63,
23598,
14,
955,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
22709,
14,
1018,
14,
16432,
14,
14293,
63,
1176,
14,
992,
492,
22574,
792,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
6180,
14,
31925,
63,
8575,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
395,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
17393,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
6063,
297,
1639,
63,
23598,
14,
955,
14,
17393,
792,
8,
3437,
63,
505,
534,
11467,
4528,
9055,
9023,
1233,
3130,
3747,
29,
549,
12,
1390,
63,
1267,
29,
18,
12,
1592,
63,
1080,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
788,
6063,
995,
288,
1660,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
17393,
3946,
5065,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
2200,
63,
466,
297,
1709,
14,
2183,
8,
885,
29,
66,
7,
22126,
297,
1720,
63,
505,
534,
26625,
370,
2387,
503,
5760,
314,
1627,
2518,
14,
982,
22671,
26013,
787,
2013,
12,
2066,
5258,
6084,
4390,
687,
10424,
15023,
26013,
911,
506,
7688,
370,
2879,
314,
2518,
14,
221,
982,
23180,
26013,
787,
2013,
12,
2066,
4390,
687,
12136,
15023,
26013,
911,
2845,
506,
7688,
370,
2879,
314,
2518,
3130,
1390,
63,
1267,
29,
2299,
12,
3415,
17497,
66,
7,
14189,
297,
330,
7,
19803,
513,
334,
3306,
1454,
3520,
26013,
11218,
334,
66,
7,
22126,
297,
330,
7,
23405,
513,
334,
1457,
3520,
26013,
9,
2023,
395,
355,
661,
6063,
297,
1709,
14,
3190,
8,
3437,
63,
505,
534,
1918,
9023,
370,
1314,
642,
2332,
12966,
3130,
370,
534,
31889,
14,
17393,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
6979,
3946,
5065,
12114,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
3954,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
1972,
63,
498,
297,
22574,
792,
8,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
4753,
297,
1709,
14,
6254,
8,
2307,
29,
549,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
362,
63,
7410,
63,
991,
356,
283,
3954,
297,
288,
1660,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
887,
16308,
379,
6979,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1972,
63,
344,
297,
22574,
792,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
31889,
379,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
887,
16308,
379,
2223,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1461,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
3376,
63,
354,
534,
4001,
1434,
3855,
355,
661,
3827,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6589,
3855,
355,
661,
31889,
379,
63,
23598,
297,
1709,
14,
6254,
8,
3437,
63,
505,
29,
66,
7,
33,
10029,
13,
12794,
769,
402,
9023,
9479,
626,
11264,
1334,
738,
14,
51,
14,
25316,
16308,
24488,
297,
4596,
29,
549,
1826,
355,
661,
2489,
63,
991,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
29148,
12,
14783,
29,
797,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2973,
29,
549,
12,
3376,
63,
354,
534,
6970,
701,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
12291,
1461,
63,
602,
5529,
355,
283,
6198,
356,
756,
12,
288,
1660,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
1772,
4131,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1461,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
3376,
63,
354,
534,
4001,
1434,
3855,
355,
661,
3827,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6589,
3855,
355,
661,
14189,
297,
1709,
14,
6254,
8,
3437,
63,
505,
29,
66,
7,
33,
10029,
13,
12794,
769,
402,
3531,
7149,
626,
1077,
440,
11264,
1334,
25316,
16308,
24488,
3130,
4596,
29,
549,
1826,
355,
661,
22126,
297,
1709,
14,
6254,
8,
3437,
63,
505,
29,
66,
7,
33,
10029,
13,
12794,
769,
402,
3531,
7149,
626,
1077,
11264,
1334,
25316,
16308,
24488,
3130,
4596,
29,
549,
1826,
355,
661,
2489,
63,
991,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
29148,
12,
14783,
29,
797,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2973,
29,
549,
12,
3376,
63,
354,
534,
6970,
701,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
12291,
1461,
63,
602,
5529,
355,
283,
6198,
356
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
63,
23598,
14,
955,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
22709,
14,
1018,
14,
16432,
14,
14293,
63,
1176,
14,
992,
492,
22574,
792,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
6180,
14,
31925,
63,
8575,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
395,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
17393,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
6063,
297,
1639,
63,
23598,
14,
955,
14,
17393,
792,
8,
3437,
63,
505,
534,
11467,
4528,
9055,
9023,
1233,
3130,
3747,
29,
549,
12,
1390,
63,
1267,
29,
18,
12,
1592,
63,
1080,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
788,
6063,
995,
288,
1660,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
17393,
3946,
5065,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
2200,
63,
466,
297,
1709,
14,
2183,
8,
885,
29,
66,
7,
22126,
297,
1720,
63,
505,
534,
26625,
370,
2387,
503,
5760,
314,
1627,
2518,
14,
982,
22671,
26013,
787,
2013,
12,
2066,
5258,
6084,
4390,
687,
10424,
15023,
26013,
911,
506,
7688,
370,
2879,
314,
2518,
14,
221,
982,
23180,
26013,
787,
2013,
12,
2066,
4390,
687,
12136,
15023,
26013,
911,
2845,
506,
7688,
370,
2879,
314,
2518,
3130,
1390,
63,
1267,
29,
2299,
12,
3415,
17497,
66,
7,
14189,
297,
330,
7,
19803,
513,
334,
3306,
1454,
3520,
26013,
11218,
334,
66,
7,
22126,
297,
330,
7,
23405,
513,
334,
1457,
3520,
26013,
9,
2023,
395,
355,
661,
6063,
297,
1709,
14,
3190,
8,
3437,
63,
505,
534,
1918,
9023,
370,
1314,
642,
2332,
12966,
3130,
370,
534,
31889,
14,
17393,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
6979,
3946,
5065,
12114,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
3954,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
1972,
63,
498,
297,
22574,
792,
8,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
4753,
297,
1709,
14,
6254,
8,
2307,
29,
549,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
362,
63,
7410,
63,
991,
356,
283,
3954,
297,
288,
1660,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
887,
16308,
379,
6979,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1972,
63,
344,
297,
22574,
792,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
31889,
379,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
887,
16308,
379,
2223,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1461,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
3376,
63,
354,
534,
4001,
1434,
3855,
355,
661,
3827,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6589,
3855,
355,
661,
31889,
379,
63,
23598,
297,
1709,
14,
6254,
8,
3437,
63,
505,
29,
66,
7,
33,
10029,
13,
12794,
769,
402,
9023,
9479,
626,
11264,
1334,
738,
14,
51,
14,
25316,
16308,
24488,
297,
4596,
29,
549,
1826,
355,
661,
2489,
63,
991,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
29148,
12,
14783,
29,
797,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2973,
29,
549,
12,
3376,
63,
354,
534,
6970,
701,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
12291,
1461,
63,
602,
5529,
355,
283,
6198,
356,
756,
12,
288,
1660,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
1772,
4131,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1461,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
3376,
63,
354,
534,
4001,
1434,
3855,
355,
661,
3827,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6589,
3855,
355,
661,
14189,
297,
1709,
14,
6254,
8,
3437,
63,
505,
29,
66,
7,
33,
10029,
13,
12794,
769,
402,
3531,
7149,
626,
1077,
440,
11264,
1334,
25316,
16308,
24488,
3130,
4596,
29,
549,
1826,
355,
661,
22126,
297,
1709,
14,
6254,
8,
3437,
63,
505,
29,
66,
7,
33,
10029,
13,
12794,
769,
402,
3531,
7149,
626,
1077,
11264,
1334,
25316,
16308,
24488,
3130,
4596,
29,
549,
1826,
355,
661,
2489,
63,
991,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
29148,
12,
14783,
29,
797,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2973,
29,
549,
12,
3376,
63,
354,
534,
6970,
701,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
12291,
1461,
63,
602,
5529,
355,
283,
6198,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
brian-l/django-1.4.10
|
tests/modeltests/test_client/views.py
|
39
|
7984
|
from xml.dom.minidom import parseString
from django.contrib.auth.decorators import login_required, permission_required
from django.core import mail
from django.forms import fields
from django.forms.forms import Form
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
from django.shortcuts import render_to_response
from django.template import Context, Template
from django.utils.decorators import method_decorator
def get_view(request):
"A simple view that expects a GET request, and returns a rendered template"
t = Template('This is a test. {{ var }} is the value.', name='GET Template')
c = Context({'var': request.GET.get('var', 42)})
return HttpResponse(t.render(c))
def post_view(request):
"""A view that expects a POST, and returns a different template depending
on whether any POST data is available
"""
if request.method == 'POST':
if request.POST:
t = Template('Data received: {{ data }} is the value.', name='POST Template')
c = Context({'data': request.POST['value']})
else:
t = Template('Viewing POST page.', name='Empty POST Template')
c = Context()
else:
t = Template('Viewing GET page.', name='Empty GET Template')
c = Context()
return HttpResponse(t.render(c))
def view_with_header(request):
"A view that has a custom header"
response = HttpResponse()
response['X-DJANGO-TEST'] = 'Slartibartfast'
return response
def raw_post_view(request):
"""A view which expects raw XML to be posted and returns content extracted
from the XML"""
if request.method == 'POST':
root = parseString(request.body)
first_book = root.firstChild.firstChild
title, author = [n.firstChild.nodeValue for n in first_book.childNodes]
t = Template("{{ title }} - {{ author }}", name="Book template")
c = Context({"title": title, "author": author})
else:
t = Template("GET request.", name="Book GET template")
c = Context()
return HttpResponse(t.render(c))
def redirect_view(request):
"A view that redirects all requests to the GET view"
if request.GET:
from urllib import urlencode
query = '?' + urlencode(request.GET, True)
else:
query = ''
return HttpResponseRedirect('/test_client/get_view/' + query)
def view_with_secure(request):
"A view that indicates if the request was secure"
response = HttpResponse()
response.test_was_secure_request = request.is_secure()
return response
def double_redirect_view(request):
"A view that redirects all requests to a redirection view"
return HttpResponseRedirect('/test_client/permanent_redirect_view/')
def bad_view(request):
"A view that returns a 404 with some error content"
return HttpResponseNotFound('Not found!. This page contains some MAGIC content')
TestChoices = (
('a', 'First Choice'),
('b', 'Second Choice'),
('c', 'Third Choice'),
('d', 'Fourth Choice'),
('e', 'Fifth Choice')
)
class TestForm(Form):
text = fields.CharField()
email = fields.EmailField()
value = fields.IntegerField()
single = fields.ChoiceField(choices=TestChoices)
multi = fields.MultipleChoiceField(choices=TestChoices)
def form_view(request):
"A view that tests a simple form"
if request.method == 'POST':
form = TestForm(request.POST)
if form.is_valid():
t = Template('Valid POST data.', name='Valid POST Template')
c = Context()
else:
t = Template('Invalid POST data. {{ form.errors }}', name='Invalid POST Template')
c = Context({'form': form})
else:
form = TestForm(request.GET)
t = Template('Viewing base form. {{ form }}.', name='Form GET Template')
c = Context({'form': form})
return HttpResponse(t.render(c))
def form_view_with_template(request):
"A view that tests a simple form"
if request.method == 'POST':
form = TestForm(request.POST)
if form.is_valid():
message = 'POST data OK'
else:
message = 'POST data has errors'
else:
form = TestForm()
message = 'GET form page'
return render_to_response('form_view.html',
{
'form': form,
'message': message
}
)
def login_protected_view(request):
"A simple view that is login protected."
t = Template('This is a login protected test. Username is {{ user.username }}.', name='Login Template')
c = Context({'user': request.user})
return HttpResponse(t.render(c))
login_protected_view = login_required(login_protected_view)
def login_protected_view_changed_redirect(request):
"A simple view that is login protected with a custom redirect field set"
t = Template('This is a login protected test. Username is {{ user.username }}.', name='Login Template')
c = Context({'user': request.user})
return HttpResponse(t.render(c))
login_protected_view_changed_redirect = login_required(redirect_field_name="redirect_to")(login_protected_view_changed_redirect)
def _permission_protected_view(request):
"A simple view that is permission protected."
t = Template('This is a permission protected test. '
'Username is {{ user.username }}. '
'Permissions are {{ user.get_all_permissions }}.' ,
name='Permissions Template')
c = Context({'user': request.user})
return HttpResponse(t.render(c))
permission_protected_view = permission_required('modeltests.test_perm')(_permission_protected_view)
permission_protected_view_exception = permission_required('modeltests.test_perm', raise_exception=True)(_permission_protected_view)
class _ViewManager(object):
@method_decorator(login_required)
def login_protected_view(self, request):
t = Template('This is a login protected test using a method. '
'Username is {{ user.username }}.',
name='Login Method Template')
c = Context({'user': request.user})
return HttpResponse(t.render(c))
@method_decorator(permission_required('modeltests.test_perm'))
def permission_protected_view(self, request):
t = Template('This is a permission protected test using a method. '
'Username is {{ user.username }}. '
'Permissions are {{ user.get_all_permissions }}.' ,
name='Permissions Template')
c = Context({'user': request.user})
return HttpResponse(t.render(c))
_view_manager = _ViewManager()
login_protected_method_view = _view_manager.login_protected_view
permission_protected_method_view = _view_manager.permission_protected_view
def session_view(request):
"A view that modifies the session"
request.session['tobacconist'] = 'hovercraft'
t = Template('This is a view that modifies the session.',
name='Session Modifying View Template')
c = Context()
return HttpResponse(t.render(c))
def broken_view(request):
"""A view which just raises an exception, simulating a broken view."""
raise KeyError("Oops! Looks like you wrote some bad code.")
def mail_sending_view(request):
mail.EmailMessage(
"Test message",
"This is a test email",
"from@example.com",
['first@example.com', 'second@example.com']).send()
return HttpResponse("Mail sent")
def mass_mail_sending_view(request):
m1 = mail.EmailMessage(
'First Test message',
'This is the first test email',
'from@example.com',
['first@example.com', 'second@example.com'])
m2 = mail.EmailMessage(
'Second Test message',
'This is the second test email',
'from@example.com',
['second@example.com', 'third@example.com'])
c = mail.get_connection()
c.send_messages([m1,m2])
return HttpResponse("Mail sent")
|
bsd-3-clause
|
[
504,
2748,
14,
4556,
14,
21827,
492,
2198,
1558,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
12,
4983,
63,
2427,
199,
504,
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
3351,
492,
1504,
199,
504,
1639,
14,
3351,
14,
3351,
492,
8204,
199,
504,
1639,
14,
1014,
492,
6183,
12,
14935,
12,
6183,
4667,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
1639,
14,
1160,
492,
9470,
12,
5458,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
421,
199,
318,
664,
63,
1345,
8,
1069,
304,
272,
298,
33,
3486,
2455,
626,
14292,
282,
9576,
1056,
12,
436,
2529,
282,
8018,
1978,
2,
272,
307,
275,
5458,
360,
2765,
365,
282,
511,
14,
8448,
2729,
3586,
365,
314,
574,
3130,
536,
534,
2970,
5458,
358,
272,
286,
275,
9470,
3252,
1391,
356,
1056,
14,
2970,
14,
362,
360,
1391,
297,
5685,
11466,
339,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
199,
199,
318,
2963,
63,
1345,
8,
1069,
304,
272,
408,
33,
2455,
626,
14292,
282,
8761,
12,
436,
2529,
282,
3365,
1978,
10298,
272,
641,
3775,
1263,
8761,
666,
365,
2808,
272,
408,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
340,
1056,
14,
4030,
26,
288,
307,
275,
5458,
360,
1451,
3086,
26,
8448,
666,
3586,
365,
314,
574,
3130,
536,
534,
4030,
5458,
358,
288,
286,
275,
9470,
3252,
576,
356,
1056,
14,
4030,
459,
585,
13678,
267,
587,
26,
288,
307,
275,
5458,
360,
2768,
316,
8761,
2034,
3130,
536,
534,
4699,
8761,
5458,
358,
288,
286,
275,
9470,
342,
272,
587,
26,
267,
307,
275,
5458,
360,
2768,
316,
9576,
2034,
3130,
536,
534,
4699,
9576,
5458,
358,
267,
286,
275,
9470,
342,
339,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
199,
199,
318,
2455,
63,
1045,
63,
1291,
8,
1069,
304,
272,
298,
33,
2455,
626,
965,
282,
3537,
1406,
2,
272,
1177,
275,
6183,
342,
272,
1177,
459,
56,
13,
22848,
13,
2864,
418,
275,
283,
51,
9828,
280,
66,
580,
7015,
7,
272,
372,
1177,
199,
199,
318,
3066,
63,
1932,
63,
1345,
8,
1069,
304,
272,
408,
33,
2455,
1314,
14292,
3066,
4692,
370,
506,
22752,
436,
2529,
1564,
12509,
272,
687,
314,
4692,
624,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
1738,
275,
2198,
1558,
8,
1069,
14,
2030,
9,
267,
1642,
63,
2706,
275,
1738,
14,
22262,
14,
22262,
267,
2538,
12,
4132,
275,
359,
78,
14,
22262,
14,
17240,
367,
302,
315,
1642,
63,
2706,
14,
10626,
61,
267,
307,
275,
5458,
480,
3638,
2538,
3586,
446,
8448,
4132,
3586,
401,
536,
628,
8696,
1978,
531,
267,
286,
275,
9470,
6333,
1213,
582,
2538,
12,
298,
2502,
582,
4132,
1552,
272,
587,
26,
267,
307,
275,
5458,
480,
2970,
1056,
4765,
536,
628,
8696,
9576,
1978,
531,
267,
286,
275,
9470,
342,
339,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
199,
199,
318,
4660,
63,
1345,
8,
1069,
304,
272,
298,
33,
2455,
626,
17784,
1006,
4145,
370,
314,
9576,
2455,
2,
272,
340,
1056,
14,
2970,
26,
267,
687,
4011,
492,
16511,
267,
1827,
275,
15539,
435,
16511,
8,
1069,
14,
2970,
12,
715,
9,
272,
587,
26,
267,
1827,
275,
2125,
272,
372,
14935,
2336,
396,
63,
1258,
15,
362,
63,
1345,
4805,
435,
1827,
9,
199,
199,
318,
2455,
63,
1045,
63,
7817,
8,
1069,
304,
272,
298,
33,
2455,
626,
9126,
340,
314,
1056,
1990,
11153,
2,
272,
1177,
275,
6183,
342,
272,
1177,
14,
396,
63,
10274,
63,
7817,
63,
1069,
275,
1056,
14,
374,
63,
7817,
342,
272,
372,
1177,
199,
199,
318,
4270,
63,
4876,
63,
1345,
8,
1069,
304,
272,
298,
33,
2455,
626,
17784,
1006,
4145,
370,
282,
23713,
2455,
2,
272,
372,
14935,
2336,
396,
63,
1258,
15,
19904,
63,
4876,
63,
1345,
6217,
199,
199,
318,
4875,
63,
1345,
8,
1069,
304,
272,
298,
33,
2455,
626,
2529,
282,
7901,
543,
2005,
1125,
1564,
2,
272,
372,
6183,
4667,
360,
1763,
1911,
1,
14,
961,
2034,
3509,
2005,
23336,
1564,
358,
199,
199,
774,
30806,
275,
334,
272,
661,
65,
297,
283,
7147,
16053,
659,
272,
661,
66,
297,
283,
11906,
16053,
659,
272,
661,
67,
297,
283,
28611,
16053,
659,
272,
661,
68,
297,
283,
24766,
273,
16053,
659,
272,
661,
69,
297,
283,
38,
11509,
16053,
358,
199,
9,
199,
199,
533,
1379,
2821,
8,
2821,
304,
272,
1318,
275,
1504,
14,
2183,
342,
272,
3031,
275,
1504,
14,
16577,
342,
272,
574,
275,
1504,
14,
3901,
342,
272,
2849,
275,
1504,
14,
15792,
8,
4577,
29,
774,
30806,
9,
272,
3510,
275,
1504,
14,
8433,
15792,
8,
4577,
29,
774,
30806,
9,
199,
199,
318,
1824,
63,
1345,
8,
1069,
304,
272,
298,
33,
2455,
626,
2295,
282,
3486,
1824,
2,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
1824,
275,
1379,
2821,
8,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
307,
275,
5458,
360,
3490,
8761,
666,
3130,
536,
534,
3490,
8761,
5458,
358,
288,
286,
275,
9470,
342,
267,
587,
26,
288,
307,
275,
5458,
360,
3364,
8761,
666,
14,
8448,
1824,
14,
2550,
23688,
536,
534,
3364,
8761,
5458,
358,
288,
286,
275,
9470,
3252,
964,
356,
1824,
1552,
272,
587,
26,
267,
1824,
275,
1379,
2821,
8,
1069,
14,
2970,
9,
267,
307,
275,
5458,
360,
2768,
316,
1300,
1824,
14,
8448,
1824,
3586,
3130,
536,
534,
2821,
9576,
5458,
358,
267,
286,
275,
9470,
3252,
964,
356,
1824,
1552,
339,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
199,
199,
318,
1824,
63,
1345,
63,
1045,
63,
1160,
8,
1069,
304,
272,
298,
33,
2455,
626,
2295,
282,
3486,
1824,
2,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
1824,
275,
1379,
2821,
8,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1245,
275,
283,
4030,
666,
9949,
7,
267,
587,
26,
288,
1245,
275,
283,
4030,
666,
965,
2552,
7,
272,
587,
26,
267,
1824,
275,
1379,
2821,
342
] |
[
2748,
14,
4556,
14,
21827,
492,
2198,
1558,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
12,
4983,
63,
2427,
199,
504,
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
3351,
492,
1504,
199,
504,
1639,
14,
3351,
14,
3351,
492,
8204,
199,
504,
1639,
14,
1014,
492,
6183,
12,
14935,
12,
6183,
4667,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
1639,
14,
1160,
492,
9470,
12,
5458,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
421,
199,
318,
664,
63,
1345,
8,
1069,
304,
272,
298,
33,
3486,
2455,
626,
14292,
282,
9576,
1056,
12,
436,
2529,
282,
8018,
1978,
2,
272,
307,
275,
5458,
360,
2765,
365,
282,
511,
14,
8448,
2729,
3586,
365,
314,
574,
3130,
536,
534,
2970,
5458,
358,
272,
286,
275,
9470,
3252,
1391,
356,
1056,
14,
2970,
14,
362,
360,
1391,
297,
5685,
11466,
339,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
199,
199,
318,
2963,
63,
1345,
8,
1069,
304,
272,
408,
33,
2455,
626,
14292,
282,
8761,
12,
436,
2529,
282,
3365,
1978,
10298,
272,
641,
3775,
1263,
8761,
666,
365,
2808,
272,
408,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
340,
1056,
14,
4030,
26,
288,
307,
275,
5458,
360,
1451,
3086,
26,
8448,
666,
3586,
365,
314,
574,
3130,
536,
534,
4030,
5458,
358,
288,
286,
275,
9470,
3252,
576,
356,
1056,
14,
4030,
459,
585,
13678,
267,
587,
26,
288,
307,
275,
5458,
360,
2768,
316,
8761,
2034,
3130,
536,
534,
4699,
8761,
5458,
358,
288,
286,
275,
9470,
342,
272,
587,
26,
267,
307,
275,
5458,
360,
2768,
316,
9576,
2034,
3130,
536,
534,
4699,
9576,
5458,
358,
267,
286,
275,
9470,
342,
339,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
199,
199,
318,
2455,
63,
1045,
63,
1291,
8,
1069,
304,
272,
298,
33,
2455,
626,
965,
282,
3537,
1406,
2,
272,
1177,
275,
6183,
342,
272,
1177,
459,
56,
13,
22848,
13,
2864,
418,
275,
283,
51,
9828,
280,
66,
580,
7015,
7,
272,
372,
1177,
199,
199,
318,
3066,
63,
1932,
63,
1345,
8,
1069,
304,
272,
408,
33,
2455,
1314,
14292,
3066,
4692,
370,
506,
22752,
436,
2529,
1564,
12509,
272,
687,
314,
4692,
624,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
1738,
275,
2198,
1558,
8,
1069,
14,
2030,
9,
267,
1642,
63,
2706,
275,
1738,
14,
22262,
14,
22262,
267,
2538,
12,
4132,
275,
359,
78,
14,
22262,
14,
17240,
367,
302,
315,
1642,
63,
2706,
14,
10626,
61,
267,
307,
275,
5458,
480,
3638,
2538,
3586,
446,
8448,
4132,
3586,
401,
536,
628,
8696,
1978,
531,
267,
286,
275,
9470,
6333,
1213,
582,
2538,
12,
298,
2502,
582,
4132,
1552,
272,
587,
26,
267,
307,
275,
5458,
480,
2970,
1056,
4765,
536,
628,
8696,
9576,
1978,
531,
267,
286,
275,
9470,
342,
339,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
199,
199,
318,
4660,
63,
1345,
8,
1069,
304,
272,
298,
33,
2455,
626,
17784,
1006,
4145,
370,
314,
9576,
2455,
2,
272,
340,
1056,
14,
2970,
26,
267,
687,
4011,
492,
16511,
267,
1827,
275,
15539,
435,
16511,
8,
1069,
14,
2970,
12,
715,
9,
272,
587,
26,
267,
1827,
275,
2125,
272,
372,
14935,
2336,
396,
63,
1258,
15,
362,
63,
1345,
4805,
435,
1827,
9,
199,
199,
318,
2455,
63,
1045,
63,
7817,
8,
1069,
304,
272,
298,
33,
2455,
626,
9126,
340,
314,
1056,
1990,
11153,
2,
272,
1177,
275,
6183,
342,
272,
1177,
14,
396,
63,
10274,
63,
7817,
63,
1069,
275,
1056,
14,
374,
63,
7817,
342,
272,
372,
1177,
199,
199,
318,
4270,
63,
4876,
63,
1345,
8,
1069,
304,
272,
298,
33,
2455,
626,
17784,
1006,
4145,
370,
282,
23713,
2455,
2,
272,
372,
14935,
2336,
396,
63,
1258,
15,
19904,
63,
4876,
63,
1345,
6217,
199,
199,
318,
4875,
63,
1345,
8,
1069,
304,
272,
298,
33,
2455,
626,
2529,
282,
7901,
543,
2005,
1125,
1564,
2,
272,
372,
6183,
4667,
360,
1763,
1911,
1,
14,
961,
2034,
3509,
2005,
23336,
1564,
358,
199,
199,
774,
30806,
275,
334,
272,
661,
65,
297,
283,
7147,
16053,
659,
272,
661,
66,
297,
283,
11906,
16053,
659,
272,
661,
67,
297,
283,
28611,
16053,
659,
272,
661,
68,
297,
283,
24766,
273,
16053,
659,
272,
661,
69,
297,
283,
38,
11509,
16053,
358,
199,
9,
199,
199,
533,
1379,
2821,
8,
2821,
304,
272,
1318,
275,
1504,
14,
2183,
342,
272,
3031,
275,
1504,
14,
16577,
342,
272,
574,
275,
1504,
14,
3901,
342,
272,
2849,
275,
1504,
14,
15792,
8,
4577,
29,
774,
30806,
9,
272,
3510,
275,
1504,
14,
8433,
15792,
8,
4577,
29,
774,
30806,
9,
199,
199,
318,
1824,
63,
1345,
8,
1069,
304,
272,
298,
33,
2455,
626,
2295,
282,
3486,
1824,
2,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
1824,
275,
1379,
2821,
8,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
307,
275,
5458,
360,
3490,
8761,
666,
3130,
536,
534,
3490,
8761,
5458,
358,
288,
286,
275,
9470,
342,
267,
587,
26,
288,
307,
275,
5458,
360,
3364,
8761,
666,
14,
8448,
1824,
14,
2550,
23688,
536,
534,
3364,
8761,
5458,
358,
288,
286,
275,
9470,
3252,
964,
356,
1824,
1552,
272,
587,
26,
267,
1824,
275,
1379,
2821,
8,
1069,
14,
2970,
9,
267,
307,
275,
5458,
360,
2768,
316,
1300,
1824,
14,
8448,
1824,
3586,
3130,
536,
534,
2821,
9576,
5458,
358,
267,
286,
275,
9470,
3252,
964,
356,
1824,
1552,
339,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
199,
199,
318,
1824,
63,
1345,
63,
1045,
63,
1160,
8,
1069,
304,
272,
298,
33,
2455,
626,
2295,
282,
3486,
1824,
2,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
1824,
275,
1379,
2821,
8,
1069,
14,
4030,
9,
267,
340,
1824,
14,
374,
63,
1078,
837,
288,
1245,
275,
283,
4030,
666,
9949,
7,
267,
587,
26,
288,
1245,
275,
283,
4030,
666,
965,
2552,
7,
272,
587,
26,
267,
1824,
275,
1379,
2821,
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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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
] |
caphrim007/ansible
|
test/units/parsing/utils/test_jsonify.py
|
119
|
1499
|
# -*- coding: utf-8 -*-
# (c) 2016, James Cammarata <jimi@sngx.net>
#
# 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
from ansible.compat.tests import unittest
from ansible.parsing.utils.jsonify import jsonify
class TestJsonify(unittest.TestCase):
def test_jsonify_simple(self):
self.assertEqual(jsonify(dict(a=1, b=2, c=3)), '{"a": 1, "b": 2, "c": 3}')
def test_jsonify_simple_format(self):
res = jsonify(dict(a=1, b=2, c=3), format=True)
cleaned = "".join([x.strip() for x in res.splitlines()])
self.assertEqual(cleaned, '{"a": 1,"b": 2,"c": 3}')
def test_jsonify_unicode(self):
self.assertEqual(jsonify(dict(toshio=u'くらとみ')), u'{"toshio": "くらとみ"}')
def test_jsonify_empty(self):
self.assertEqual(jsonify(None), '{}')
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
334,
67,
9,
7800,
12,
1603,
14015,
445,
455,
4584,
419,
665,
74,
1017,
73,
32,
83,
2753,
88,
14,
846,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
3242,
14,
11059,
14,
1208,
14,
1001,
2021,
492,
23819,
421,
199,
533,
1379,
9653,
2021,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1001,
2021,
63,
4129,
8,
277,
304,
267,
291,
14,
629,
8,
1001,
2021,
8,
807,
8,
65,
29,
17,
12,
330,
29,
18,
12,
286,
29,
19,
1826,
17137,
65,
582,
413,
12,
298,
66,
582,
499,
12,
298,
67,
582,
650,
12216,
339,
347,
511,
63,
1001,
2021,
63,
4129,
63,
908,
8,
277,
304,
267,
522,
275,
23819,
8,
807,
8,
65,
29,
17,
12,
330,
29,
18,
12,
286,
29,
19,
395,
1475,
29,
549,
9,
267,
12364,
275,
10587,
904,
779,
88,
14,
1913,
342,
367,
671,
315,
522,
14,
7644,
9383,
267,
291,
14,
629,
8,
8275,
12,
17137,
65,
582,
413,
4589,
66,
582,
499,
4589,
67,
582,
650,
12216,
339,
347,
511,
63,
1001,
2021,
63,
2975,
8,
277,
304,
267,
291,
14,
629,
8,
1001,
2021,
8,
807,
8,
475,
609,
2308,
29,
85,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
3855,
399,
7,
6641,
475,
609,
2308,
582,
298,
4197,
238,
5573,
232,
29472,
4197,
124,
3570,
358,
339,
347,
511,
63,
1001,
2021,
63,
1667,
8,
277,
304,
267,
291,
14,
629,
8,
1001,
2021,
8,
403,
395,
9005,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
334,
67,
9,
7800,
12,
1603,
14015,
445,
455,
4584,
419,
665,
74,
1017,
73,
32,
83,
2753,
88,
14,
846,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
3242,
14,
11059,
14,
1208,
14,
1001,
2021,
492,
23819,
421,
199,
533,
1379,
9653,
2021,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1001,
2021,
63,
4129,
8,
277,
304,
267,
291,
14,
629,
8,
1001,
2021,
8,
807,
8,
65,
29,
17,
12,
330,
29,
18,
12,
286,
29,
19,
1826,
17137,
65,
582,
413,
12,
298,
66,
582,
499,
12,
298,
67,
582,
650,
12216,
339,
347,
511,
63,
1001,
2021,
63,
4129,
63,
908,
8,
277,
304,
267,
522,
275,
23819,
8,
807,
8,
65,
29,
17,
12,
330,
29,
18,
12,
286,
29,
19,
395,
1475,
29,
549,
9,
267,
12364,
275,
10587,
904,
779,
88,
14,
1913,
342,
367,
671,
315,
522,
14,
7644,
9383,
267,
291,
14,
629,
8,
8275,
12,
17137,
65,
582,
413,
4589,
66,
582,
499,
4589,
67,
582,
650,
12216,
339,
347,
511,
63,
1001,
2021,
63,
2975,
8,
277,
304,
267,
291,
14,
629,
8,
1001,
2021,
8,
807,
8,
475,
609,
2308,
29,
85,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
3855,
399,
7,
6641,
475,
609,
2308,
582,
298,
4197,
238,
5573,
232,
29472,
4197,
124,
3570,
358,
339,
347,
511,
63,
1001,
2021,
63,
1667,
8,
277,
304,
267,
291,
14,
629,
8,
1001,
2021,
8,
403,
395,
9005,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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=utf-8
# This is the MIT License
# http://www.opensource.org/licenses/mit-license.php
#
# Copyright (c) 2007,2008 Nick Galbreath
#
# 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.
#
#
# Version 1.0 - 21-Apr-2007
# initial
# Version 2.0 - 16-Nov-2008
# made class Gmetric thread safe
# made gmetrix xdr writers _and readers_
# Now this only works for gmond 2.X packets, not tested with 3.X
#
# Version 3.0 - 09-Jan-2011 Author: Vladimir Vuksan
# Made it work with the Ganglia 3.1 data format
from xdrlib import Packer, Unpacker
import socket
slope_str2int = {'zero': 0,
'positive': 1,
'negative': 2,
'both': 3,
'unspecified': 4}
# could be autogenerated from previous but whatever
slope_int2str = {0: 'zero',
1: 'positive',
2: 'negative',
3: 'both',
4: 'unspecified'}
class Gmetric:
"""
Class to send gmetric/gmond 2.X packets
Thread safe
"""
type = ('', 'string', 'uint16', 'int16', 'uint32', 'int32', 'float',
'double', 'timestamp')
protocol = ('udp', 'multicast')
def __init__(self, host, port, protocol):
if protocol not in self.protocol:
raise ValueError("Protocol must be one of: " + str(self.protocol))
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
if protocol == 'multicast':
self.socket.setsockopt(socket.IPPROTO_IP,
socket.IP_MULTICAST_TTL, 20)
self.hostport = (host, int(port))
# self.socket.connect(self.hostport)
def send(self, NAME, VAL, TYPE='', UNITS='', SLOPE='both',
TMAX=60, DMAX=0, GROUP=""):
if SLOPE not in slope_str2int:
raise ValueError("Slope must be one of: " + str(self.slope.keys()))
if TYPE not in self.type:
raise ValueError("Type must be one of: " + str(self.type))
if len(NAME) == 0:
raise ValueError("Name must be non-empty")
(meta_msg, data_msg) = gmetric_write(NAME,
VAL,
TYPE,
UNITS,
SLOPE,
TMAX,
DMAX,
GROUP)
# print msg
self.socket.sendto(meta_msg, self.hostport)
self.socket.sendto(data_msg, self.hostport)
def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
HOSTNAME = "test"
SPOOF = 0
# Meta data about a metric
packer.pack_int(128)
packer.pack_string(HOSTNAME)
packer.pack_string(NAME)
packer.pack_int(SPOOF)
packer.pack_string(TYPE)
packer.pack_string(NAME)
packer.pack_string(UNITS)
packer.pack_int(slope_str2int[SLOPE]) # map slope string to int
packer.pack_uint(int(TMAX))
packer.pack_uint(int(DMAX))
# Magic number. Indicates number of entries to follow. Put in 1 for GROUP
if GROUP == "":
packer.pack_int(0)
else:
packer.pack_int(1)
packer.pack_string("GROUP")
packer.pack_string(GROUP)
# Actual data sent in a separate packet
data = Packer()
data.pack_int(128 + 5)
data.pack_string(HOSTNAME)
data.pack_string(NAME)
data.pack_int(SPOOF)
data.pack_string("%s")
data.pack_string(str(VAL))
return packer.get_buffer(), data.get_buffer()
def gmetric_read(msg):
unpacker = Unpacker(msg)
values = dict()
unpacker.unpack_int()
values['TYPE'] = unpacker.unpack_string()
values['NAME'] = unpacker.unpack_string()
values['VAL'] = unpacker.unpack_string()
values['UNITS'] = unpacker.unpack_string()
values['SLOPE'] = slope_int2str[unpacker.unpack_int()]
values['TMAX'] = unpacker.unpack_uint()
values['DMAX'] = unpacker.unpack_uint()
unpacker.done()
return values
if __name__ == '__main__':
import optparse
parser = optparse.OptionParser()
parser.add_option("", "--protocol", dest="protocol", default="udp",
help="The gmetric internet protocol, either udp or"
+ "multicast, default udp")
parser.add_option("", "--host", dest="host", default="127.0.0.1",
help="GMond aggregator hostname to send data to")
parser.add_option("", "--port", dest="port", default="8649",
help="GMond aggregator port to send data to")
parser.add_option("", "--name", dest="name", default="",
help="The name of the metric")
parser.add_option("", "--value", dest="value", default="",
help="The value of the metric")
parser.add_option("", "--units", dest="units", default="",
help="The units for the value, e.g. 'kb/sec'")
parser.add_option("", "--slope", dest="slope", default="both",
help="The sign of the derivative of the value over time,"
+ "one of zero, positive, negative, both (default)")
parser.add_option("", "--type", dest="type", default="",
help="The value data type, one of string, int8, uint8,"
+ "int16, uint16, int32, uint32, float, double")
parser.add_option("", "--tmax", dest="tmax", default="60",
help="The maximum time in seconds between gmetric calls,"
+ "default 60")
parser.add_option("", "--dmax", dest="dmax", default="0",
help="The lifetime in seconds of this metric, default=0,"
+ "meaning unlimited")
parser.add_option("", "--group", dest="group", default="",
help="Group metric belongs to. If not specified Ganglia"
+ "will show it as no_group")
(options, args) = parser.parse_args()
g = Gmetric(options.host, options.port, options.protocol)
g.send(options.name, options.value, options.type, options.units,
options.slope, options.tmax, options.dmax, options.group)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
29,
1624,
13,
24,
199,
199,
3,
961,
365,
314,
10697,
844,
199,
3,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
12,
9300,
653,
2000,
598,
279,
10205,
1619,
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,
199,
3,
199,
3,
3394,
413,
14,
16,
446,
7829,
13,
33,
2700,
13,
9488,
199,
3,
257,
2536,
199,
3,
3394,
499,
14,
16,
446,
3193,
13,
1944,
86,
13,
9300,
199,
3,
257,
6326,
1021,
598,
5165,
2462,
5048,
199,
3,
257,
6326,
486,
3318,
88,
671,
5012,
2211,
878,
485,
460,
7002,
83,
63,
199,
3,
257,
7356,
642,
1454,
5419,
367,
486,
2106,
68,
499,
14,
56,
14593,
12,
440,
12470,
543,
650,
14,
56,
199,
3,
199,
3,
3394,
650,
14,
16,
446,
21798,
13,
19825,
13,
8128,
6529,
26,
812,
416,
3572,
723,
812,
3210,
18904,
199,
3,
257,
603,
9587,
652,
1736,
543,
314,
598,
621,
21796,
650,
14,
17,
666,
1475,
421,
199,
504,
671,
5012,
773,
492,
9954,
281,
12,
31017,
281,
199,
646,
2838,
199,
199,
25278,
63,
495,
18,
442,
275,
791,
4262,
356,
378,
12,
326,
283,
8965,
356,
413,
12,
326,
283,
7371,
356,
499,
12,
326,
283,
10727,
356,
650,
12,
326,
283,
324,
10085,
356,
841,
93,
199,
199,
3,
4293,
506,
18392,
687,
4136,
1325,
15685,
199,
25278,
63,
442,
18,
495,
275,
469,
16,
26,
283,
4262,
297,
326,
413,
26,
283,
8965,
297,
326,
499,
26,
283,
7371,
297,
326,
650,
26,
283,
10727,
297,
326,
841,
26,
283,
324,
10085,
936,
421,
199,
533,
598,
5165,
26,
272,
408,
272,
8089,
370,
3222,
486,
5165,
15,
71,
2106,
68,
499,
14,
56,
14593,
339,
11086,
5048,
272,
408,
339,
730,
275,
13134,
283,
875,
297,
283,
1635,
975,
297,
283,
442,
975,
297,
283,
1635,
708,
297,
283,
442,
708,
297,
283,
1609,
297,
288,
283,
3157,
297,
283,
3954,
358,
272,
4113,
275,
661,
15036,
297,
283,
23797,
358,
339,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
4113,
304,
267,
340,
4113,
440,
315,
291,
14,
3922,
26,
288,
746,
1722,
480,
3658,
1471,
506,
1373,
402,
26,
298,
435,
620,
8,
277,
14,
3922,
430,
398,
291,
14,
3450,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
267,
340,
4113,
508,
283,
23797,
356,
288,
291,
14,
3450,
14,
27689,
8,
3450,
14,
20130,
63,
1772,
12,
3521,
2838,
14,
1772,
63,
8203,
948,
11307,
63,
25567,
12,
3388,
9,
267,
291,
14,
1102,
719,
275,
334,
1102,
12,
1109,
8,
719,
430,
267,
327,
291,
14,
3450,
14,
2242,
8,
277,
14,
1102,
719,
9,
339,
347,
3222,
8,
277,
12,
13637,
12,
8986,
12,
11511,
4581,
6778,
5930,
4581,
428,
1484,
1510,
534,
10727,
297,
1467,
377,
4283,
29,
2259,
12,
577,
4283,
29,
16,
12,
15443,
17364,
267,
340,
428,
1484,
1510,
440,
315,
24140,
63,
495,
18,
442,
26,
288,
746,
1722,
480,
51,
14363,
1471,
506,
1373,
402,
26,
298,
435,
620,
8,
277,
14,
25278,
14,
1612,
4059,
267,
340,
11511,
440,
315,
291,
14,
466,
26,
288,
746,
1722,
480,
804,
1471,
506,
1373,
402,
26,
298,
435,
620,
8,
277,
14,
466,
430,
267,
340,
822,
8,
2339,
9,
508,
378,
26,
288,
746,
1722,
480,
985,
1471,
506,
2222,
13,
1667,
531,
398,
334,
2024,
63,
1328,
12,
666,
63,
1328,
9,
275,
486,
5165,
63,
952,
8,
2339,
12,
6163,
8986,
12,
6163,
11511,
12,
6163,
6778,
5930,
12,
6163,
428,
1484,
1510,
12,
6163,
377,
4283,
12,
6163,
577,
4283,
12,
6163,
15443,
9,
267,
327,
870,
1499,
398,
291,
14,
3450,
14,
23267,
8,
2024,
63,
1328,
12,
291,
14,
1102,
719,
9,
267,
291,
14,
3450,
14,
23267,
8,
576,
63,
1328,
12,
291,
14,
1102,
719,
9,
421,
199,
318,
486,
5165,
63,
952,
8,
2339,
12,
8986,
12,
11511,
12,
6778,
5930,
12,
428,
1484,
1510,
12,
377,
4283,
12,
577,
4283,
12,
15443,
304,
272,
408,
272,
7628,
787,
315,
1006,
7008,
13,
2546,
370,
1336,
4692,
272,
408,
272,
1706,
281,
275,
9954,
281,
342,
272,
25741,
2339,
275,
298,
396,
2,
272,
428,
1512,
3359,
275,
378,
272,
327,
6288,
666,
3595,
282,
6370,
272,
1706,
281,
14,
1389,
63,
442,
8,
3933,
9,
272,
1706,
281,
14,
1389,
63,
875,
8,
22647,
9,
272,
1706,
281,
14,
1389,
63,
875,
8,
2339,
9,
272,
1706,
281,
14,
1389,
63,
442,
8,
51,
1512,
3359,
9,
272,
1706,
281,
14,
1389,
63,
875,
8,
2711,
9,
272,
1706,
281,
14,
1389,
63,
875,
8,
2339
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
29,
1624,
13,
24,
199,
199,
3,
961,
365,
314,
10697,
844,
199,
3,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
12,
9300,
653,
2000,
598,
279,
10205,
1619,
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,
199,
3,
199,
3,
3394,
413,
14,
16,
446,
7829,
13,
33,
2700,
13,
9488,
199,
3,
257,
2536,
199,
3,
3394,
499,
14,
16,
446,
3193,
13,
1944,
86,
13,
9300,
199,
3,
257,
6326,
1021,
598,
5165,
2462,
5048,
199,
3,
257,
6326,
486,
3318,
88,
671,
5012,
2211,
878,
485,
460,
7002,
83,
63,
199,
3,
257,
7356,
642,
1454,
5419,
367,
486,
2106,
68,
499,
14,
56,
14593,
12,
440,
12470,
543,
650,
14,
56,
199,
3,
199,
3,
3394,
650,
14,
16,
446,
21798,
13,
19825,
13,
8128,
6529,
26,
812,
416,
3572,
723,
812,
3210,
18904,
199,
3,
257,
603,
9587,
652,
1736,
543,
314,
598,
621,
21796,
650,
14,
17,
666,
1475,
421,
199,
504,
671,
5012,
773,
492,
9954,
281,
12,
31017,
281,
199,
646,
2838,
199,
199,
25278,
63,
495,
18,
442,
275,
791,
4262,
356,
378,
12,
326,
283,
8965,
356,
413,
12,
326,
283,
7371,
356,
499,
12,
326,
283,
10727,
356,
650,
12,
326,
283,
324,
10085,
356,
841,
93,
199,
199,
3,
4293,
506,
18392,
687,
4136,
1325,
15685,
199,
25278,
63,
442,
18,
495,
275,
469,
16,
26,
283,
4262,
297,
326,
413,
26,
283,
8965,
297,
326,
499,
26,
283,
7371,
297,
326,
650,
26,
283,
10727,
297,
326,
841,
26,
283,
324,
10085,
936,
421,
199,
533,
598,
5165,
26,
272,
408,
272,
8089,
370,
3222,
486,
5165,
15,
71,
2106,
68,
499,
14,
56,
14593,
339,
11086,
5048,
272,
408,
339,
730,
275,
13134,
283,
875,
297,
283,
1635,
975,
297,
283,
442,
975,
297,
283,
1635,
708,
297,
283,
442,
708,
297,
283,
1609,
297,
288,
283,
3157,
297,
283,
3954,
358,
272,
4113,
275,
661,
15036,
297,
283,
23797,
358,
339,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
4113,
304,
267,
340,
4113,
440,
315,
291,
14,
3922,
26,
288,
746,
1722,
480,
3658,
1471,
506,
1373,
402,
26,
298,
435,
620,
8,
277,
14,
3922,
430,
398,
291,
14,
3450,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
267,
340,
4113,
508,
283,
23797,
356,
288,
291,
14,
3450,
14,
27689,
8,
3450,
14,
20130,
63,
1772,
12,
3521,
2838,
14,
1772,
63,
8203,
948,
11307,
63,
25567,
12,
3388,
9,
267,
291,
14,
1102,
719,
275,
334,
1102,
12,
1109,
8,
719,
430,
267,
327,
291,
14,
3450,
14,
2242,
8,
277,
14,
1102,
719,
9,
339,
347,
3222,
8,
277,
12,
13637,
12,
8986,
12,
11511,
4581,
6778,
5930,
4581,
428,
1484,
1510,
534,
10727,
297,
1467,
377,
4283,
29,
2259,
12,
577,
4283,
29,
16,
12,
15443,
17364,
267,
340,
428,
1484,
1510,
440,
315,
24140,
63,
495,
18,
442,
26,
288,
746,
1722,
480,
51,
14363,
1471,
506,
1373,
402,
26,
298,
435,
620,
8,
277,
14,
25278,
14,
1612,
4059,
267,
340,
11511,
440,
315,
291,
14,
466,
26,
288,
746,
1722,
480,
804,
1471,
506,
1373,
402,
26,
298,
435,
620,
8,
277,
14,
466,
430,
267,
340,
822,
8,
2339,
9,
508,
378,
26,
288,
746,
1722,
480,
985,
1471,
506,
2222,
13,
1667,
531,
398,
334,
2024,
63,
1328,
12,
666,
63,
1328,
9,
275,
486,
5165,
63,
952,
8,
2339,
12,
6163,
8986,
12,
6163,
11511,
12,
6163,
6778,
5930,
12,
6163,
428,
1484,
1510,
12,
6163,
377,
4283,
12,
6163,
577,
4283,
12,
6163,
15443,
9,
267,
327,
870,
1499,
398,
291,
14,
3450,
14,
23267,
8,
2024,
63,
1328,
12,
291,
14,
1102,
719,
9,
267,
291,
14,
3450,
14,
23267,
8,
576,
63,
1328,
12,
291,
14,
1102,
719,
9,
421,
199,
318,
486,
5165,
63,
952,
8,
2339,
12,
8986,
12,
11511,
12,
6778,
5930,
12,
428,
1484,
1510,
12,
377,
4283,
12,
577,
4283,
12,
15443,
304,
272,
408,
272,
7628,
787,
315,
1006,
7008,
13,
2546,
370,
1336,
4692,
272,
408,
272,
1706,
281,
275,
9954,
281,
342,
272,
25741,
2339,
275,
298,
396,
2,
272,
428,
1512,
3359,
275,
378,
272,
327,
6288,
666,
3595,
282,
6370,
272,
1706,
281,
14,
1389,
63,
442,
8,
3933,
9,
272,
1706,
281,
14,
1389,
63,
875,
8,
22647,
9,
272,
1706,
281,
14,
1389,
63,
875,
8,
2339,
9,
272,
1706,
281,
14,
1389,
63,
442,
8,
51,
1512,
3359,
9,
272,
1706,
281,
14,
1389,
63,
875,
8,
2711,
9,
272,
1706,
281,
14,
1389,
63,
875,
8,
2339,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bussiere/pypyjs
|
website/demo/home/rfk/repos/pypy/lib-python/2.7/sndhdr.py
|
257
|
5973
|
"""Routines to help recognizing sound files.
Function whathdr() recognizes various types of sound file headers.
It understands almost all headers that SOX can decode.
The return tuple contains the following items, in this order:
- file type (as SOX understands it)
- sampling rate (0 if unknown or hard to decode)
- number of channels (0 if unknown or hard to decode)
- number of frames in the file (-1 if unknown or hard to decode)
- number of bits/sample, or 'U' for U-LAW, or 'A' for A-LAW
If the file doesn't have a recognizable type, it returns None.
If the file can't be opened, IOError is raised.
To compute the total time, divide the number of frames by the
sampling rate (a frame contains a sample for each channel).
Function what() calls whathdr(). (It used to also use some
heuristics for raw data, but this doesn't work very well.)
Finally, the function test() is a simple main program that calls
what() for all files mentioned on the argument list. For directory
arguments it calls what() for all files in that directory. Default
argument is "." (testing all files in the current directory). The
option -r tells it to recurse down directories found inside
explicitly given directories.
"""
# The file structure is top-down except that the test program and its
# subroutine come last.
__all__ = ["what","whathdr"]
def what(filename):
"""Guess the type of a sound file"""
res = whathdr(filename)
return res
def whathdr(filename):
"""Recognize sound headers"""
f = open(filename, 'rb')
h = f.read(512)
for tf in tests:
res = tf(h, f)
if res:
return res
return None
#-----------------------------------#
# Subroutines per sound header type #
#-----------------------------------#
tests = []
def test_aifc(h, f):
import aifc
if h[:4] != 'FORM':
return None
if h[8:12] == 'AIFC':
fmt = 'aifc'
elif h[8:12] == 'AIFF':
fmt = 'aiff'
else:
return None
f.seek(0)
try:
a = aifc.openfp(f, 'r')
except (EOFError, aifc.Error):
return None
return (fmt, a.getframerate(), a.getnchannels(), \
a.getnframes(), 8*a.getsampwidth())
tests.append(test_aifc)
def test_au(h, f):
if h[:4] == '.snd':
f = get_long_be
elif h[:4] in ('\0ds.', 'dns.'):
f = get_long_le
else:
return None
type = 'au'
hdr_size = f(h[4:8])
data_size = f(h[8:12])
encoding = f(h[12:16])
rate = f(h[16:20])
nchannels = f(h[20:24])
sample_size = 1 # default
if encoding == 1:
sample_bits = 'U'
elif encoding == 2:
sample_bits = 8
elif encoding == 3:
sample_bits = 16
sample_size = 2
else:
sample_bits = '?'
frame_size = sample_size * nchannels
return type, rate, nchannels, data_size//frame_size, sample_bits
tests.append(test_au)
def test_hcom(h, f):
if h[65:69] != 'FSSD' or h[128:132] != 'HCOM':
return None
divisor = get_long_be(h[128+16:128+20])
return 'hcom', 22050//divisor, 1, -1, 8
tests.append(test_hcom)
def test_voc(h, f):
if h[:20] != 'Creative Voice File\032':
return None
sbseek = get_short_le(h[20:22])
rate = 0
if 0 <= sbseek < 500 and h[sbseek] == '\1':
ratecode = ord(h[sbseek+4])
rate = int(1000000.0 / (256 - ratecode))
return 'voc', rate, 1, -1, 8
tests.append(test_voc)
def test_wav(h, f):
# 'RIFF' <len> 'WAVE' 'fmt ' <len>
if h[:4] != 'RIFF' or h[8:12] != 'WAVE' or h[12:16] != 'fmt ':
return None
style = get_short_le(h[20:22])
nchannels = get_short_le(h[22:24])
rate = get_long_le(h[24:28])
sample_bits = get_short_le(h[34:36])
return 'wav', rate, nchannels, -1, sample_bits
tests.append(test_wav)
def test_8svx(h, f):
if h[:4] != 'FORM' or h[8:12] != '8SVX':
return None
# Should decode it to get #channels -- assume always 1
return '8svx', 0, 1, 0, 8
tests.append(test_8svx)
def test_sndt(h, f):
if h[:5] == 'SOUND':
nsamples = get_long_le(h[8:12])
rate = get_short_le(h[20:22])
return 'sndt', rate, 1, nsamples, 8
tests.append(test_sndt)
def test_sndr(h, f):
if h[:2] == '\0\0':
rate = get_short_le(h[2:4])
if 4000 <= rate <= 25000:
return 'sndr', rate, 1, -1, 8
tests.append(test_sndr)
#---------------------------------------------#
# Subroutines to extract numbers from strings #
#---------------------------------------------#
def get_long_be(s):
return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3])
def get_long_le(s):
return (ord(s[3])<<24) | (ord(s[2])<<16) | (ord(s[1])<<8) | ord(s[0])
def get_short_be(s):
return (ord(s[0])<<8) | ord(s[1])
def get_short_le(s):
return (ord(s[1])<<8) | ord(s[0])
#--------------------#
# Small test program #
#--------------------#
def test():
import sys
recursive = 0
if sys.argv[1:] and sys.argv[1] == '-r':
del sys.argv[1:2]
recursive = 1
try:
if sys.argv[1:]:
testall(sys.argv[1:], recursive, 1)
else:
testall(['.'], recursive, 1)
except KeyboardInterrupt:
sys.stderr.write('\n[Interrupted]\n')
sys.exit(1)
def testall(list, recursive, toplevel):
import sys
import os
for filename in list:
if os.path.isdir(filename):
print filename + '/:',
if recursive or toplevel:
print 'recursing down:'
import glob
names = glob.glob(os.path.join(filename, '*'))
testall(names, recursive, 0)
else:
print '*** directory (use -r) ***'
else:
print filename + ':',
sys.stdout.flush()
try:
print what(filename)
except IOError:
print '*** not found ***'
if __name__ == '__main__':
test()
|
mit
|
[
624,
7595,
3746,
370,
1720,
17319,
9147,
20453,
1584,
14,
199,
199,
3481,
704,
1619,
5012,
342,
17319,
6491,
7750,
2943,
402,
20453,
570,
2323,
14,
199,
7940,
1334,
26580,
18871,
1006,
2323,
626,
3562,
56,
883,
4849,
14,
199,
199,
1918,
372,
2008,
3509,
314,
2569,
2974,
12,
315,
642,
1865,
26,
199,
13,
570,
730,
334,
305,
3562,
56,
1334,
26580,
652,
9,
199,
13,
15877,
6634,
334,
16,
340,
5809,
503,
7508,
370,
4849,
9,
199,
13,
1329,
402,
9245,
334,
16,
340,
5809,
503,
7508,
370,
4849,
9,
199,
13,
1329,
402,
11223,
315,
314,
570,
5868,
17,
340,
5809,
503,
7508,
370,
4849,
9,
199,
13,
1329,
402,
5821,
15,
3271,
12,
503,
283,
53,
7,
367,
738,
13,
5837,
55,
12,
503,
283,
33,
7,
367,
437,
13,
5837,
55,
199,
199,
3917,
314,
570,
3181,
1133,
1172,
282,
17319,
14065,
730,
12,
652,
2529,
488,
14,
199,
3917,
314,
570,
883,
1133,
506,
12123,
12,
5925,
365,
4915,
14,
199,
199,
1378,
4526,
314,
3141,
900,
12,
23003,
314,
1329,
402,
11223,
701,
314,
199,
17376,
6634,
334,
65,
2787,
3509,
282,
2690,
367,
1924,
3623,
680,
199,
199,
3481,
4052,
342,
4882,
704,
1619,
5012,
1252,
221,
334,
7940,
1202,
370,
2597,
675,
2005,
199,
426,
300,
631,
2932,
367,
3066,
666,
12,
1325,
642,
3181,
1133,
1736,
7437,
5521,
4959,
199,
199,
8694,
1183,
12,
314,
805,
511,
342,
365,
282,
3486,
2446,
2240,
626,
4882,
199,
10058,
342,
367,
1006,
1584,
26239,
641,
314,
1423,
769,
14,
221,
2104,
2082,
199,
4958,
652,
4882,
4052,
342,
367,
1006,
1584,
315,
626,
2082,
14,
221,
3758,
199,
2094,
365,
14530,
334,
4776,
1006,
1584,
315,
314,
1453,
2082,
680,
221,
710,
199,
1422,
446,
82,
26544,
652,
370,
18011,
3224,
6602,
1911,
6272,
199,
10306,
590,
1627,
6602,
14,
199,
624,
199,
199,
3,
710,
570,
5523,
365,
2746,
13,
2110,
871,
626,
314,
511,
2240,
436,
2399,
199,
3,
1007,
17765,
11492,
2061,
14,
199,
199,
363,
452,
363,
275,
2097,
10058,
2266,
2191,
1619,
5012,
937,
199,
199,
318,
4052,
8,
1501,
304,
272,
408,
25541,
314,
730,
402,
282,
20453,
570,
624,
272,
522,
275,
704,
1619,
5012,
8,
1501,
9,
272,
372,
522,
421,
199,
318,
704,
1619,
5012,
8,
1501,
304,
272,
408,
497,
6862,
794,
20453,
2323,
624,
272,
289,
275,
1551,
8,
1501,
12,
283,
4848,
358,
272,
394,
275,
289,
14,
739,
8,
7736,
9,
272,
367,
2833,
315,
2295,
26,
267,
522,
275,
2833,
8,
72,
12,
289,
9,
267,
340,
522,
26,
288,
372,
522,
272,
372,
488,
421,
199,
3,
1444,
2595,
3,
199,
3,
4804,
12791,
3746,
1126,
20453,
1406,
730,
327,
199,
3,
1444,
2595,
3,
199,
199,
2219,
275,
942,
199,
199,
318,
511,
63,
65,
25040,
8,
72,
12,
289,
304,
272,
492,
282,
25040,
272,
340,
394,
1491,
20,
61,
1137,
283,
3516,
356,
267,
372,
488,
272,
340,
394,
59,
24,
26,
713,
61,
508,
283,
7730,
4161,
356,
267,
7104,
275,
283,
65,
25040,
7,
272,
916,
394,
59,
24,
26,
713,
61,
508,
283,
7730,
1665,
356,
267,
7104,
275,
283,
5789,
556,
7,
272,
587,
26,
267,
372,
488,
272,
289,
14,
5507,
8,
16,
9,
272,
862,
26,
267,
282,
275,
282,
25040,
14,
1490,
3997,
8,
70,
12,
283,
82,
358,
272,
871,
334,
13178,
547,
12,
282,
25040,
14,
547,
304,
267,
372,
488,
272,
372,
334,
5045,
12,
282,
14,
20912,
1866,
1062,
282,
14,
362,
78,
6324,
1062,
971,
288,
282,
14,
362,
31607,
1062,
1695,
10,
65,
14,
362,
16557,
2063,
1012,
199,
199,
2219,
14,
740,
8,
396,
63,
65,
25040,
9,
421,
199,
318,
511,
63,
3844,
8,
72,
12,
289,
304,
272,
340,
394,
1491,
20,
61,
508,
1987,
83,
977,
356,
267,
289,
275,
664,
63,
2809,
63,
1235,
272,
916,
394,
1491,
20,
61,
315,
17485,
16,
795,
3130,
283,
5797,
30194,
267,
289,
275,
664,
63,
2809,
63,
274,
272,
587,
26,
267,
372,
488,
272,
730,
275,
283,
3844,
7,
272,
15260,
63,
890,
275,
289,
8,
72,
59,
20,
26,
24,
566,
272,
666,
63,
890,
275,
289,
8,
72,
59,
24,
26,
713,
566,
272,
2644,
275,
289,
8,
72,
59,
713,
26,
975,
566,
272,
6634,
275,
289,
8,
72,
59,
975,
26,
1165,
566,
272,
302,
6324,
275,
289,
8,
72,
59,
1165,
26,
1194,
566,
272,
2690,
63,
890,
275,
413,
327,
849,
272,
340,
2644,
508,
413,
26,
267,
2690,
63,
5609,
275,
283,
53,
7,
272,
916,
2644,
508,
499,
26,
267,
2690,
63,
5609,
275,
1695,
272,
916,
2644,
508,
650,
26,
267,
2690,
63,
5609,
275,
3193,
267,
2690,
63,
890,
275,
499,
272,
587,
26,
267,
2690,
63,
5609,
275,
15539,
272,
2787,
63,
890,
275,
2690,
63,
890,
627,
302,
6324,
272,
372,
730,
12,
6634,
12,
302,
6324,
12,
666,
63,
890,
501,
1943,
63,
890,
12,
2690,
63,
5609,
199,
199,
2219,
14,
740,
8,
396,
63,
3844,
9,
421,
199,
318,
511,
63,
72,
957,
8,
72,
12,
289,
304,
272,
340,
394,
59,
2182,
26,
1876,
61,
1137,
283,
38,
2300,
36,
7,
503,
394,
59,
3933,
26,
6557,
61,
1137,
283,
40,
11265,
356,
267,
372,
488,
272,
487,
8286,
275,
664,
63,
2809,
63,
1235,
8,
72,
59,
3933,
11,
975,
26,
3933,
11,
1165,
566,
272,
372,
283,
72,
957,
297,
25647,
1400,
501,
3015,
374,
269,
12,
413,
12,
446,
17,
12,
1695,
199,
199,
2219,
14,
740,
8,
396,
63,
72,
957,
9,
421,
199,
318,
511,
63,
86,
679,
8,
72,
12,
289,
304,
272,
340,
394,
1491,
1165,
61,
1137,
283,
5482,
1905,
32665,
1885,
3814,
60,
21683,
356,
267,
372,
488,
272,
20088,
5507,
275,
664,
63,
3612,
63,
274,
8,
72,
59,
1165,
26,
1081,
566,
272,
6634,
275,
378,
272,
340,
378,
2695,
20088,
5507,
665,
6891,
436,
394,
59,
9264,
5507,
61,
508,
1557,
17,
356,
267,
6634,
600,
275,
6206,
8,
72,
59,
9264,
5507,
11,
20,
566,
267,
6634,
275,
1109,
8,
22589,
14
] |
[
7595,
3746,
370,
1720,
17319,
9147,
20453,
1584,
14,
199,
199,
3481,
704,
1619,
5012,
342,
17319,
6491,
7750,
2943,
402,
20453,
570,
2323,
14,
199,
7940,
1334,
26580,
18871,
1006,
2323,
626,
3562,
56,
883,
4849,
14,
199,
199,
1918,
372,
2008,
3509,
314,
2569,
2974,
12,
315,
642,
1865,
26,
199,
13,
570,
730,
334,
305,
3562,
56,
1334,
26580,
652,
9,
199,
13,
15877,
6634,
334,
16,
340,
5809,
503,
7508,
370,
4849,
9,
199,
13,
1329,
402,
9245,
334,
16,
340,
5809,
503,
7508,
370,
4849,
9,
199,
13,
1329,
402,
11223,
315,
314,
570,
5868,
17,
340,
5809,
503,
7508,
370,
4849,
9,
199,
13,
1329,
402,
5821,
15,
3271,
12,
503,
283,
53,
7,
367,
738,
13,
5837,
55,
12,
503,
283,
33,
7,
367,
437,
13,
5837,
55,
199,
199,
3917,
314,
570,
3181,
1133,
1172,
282,
17319,
14065,
730,
12,
652,
2529,
488,
14,
199,
3917,
314,
570,
883,
1133,
506,
12123,
12,
5925,
365,
4915,
14,
199,
199,
1378,
4526,
314,
3141,
900,
12,
23003,
314,
1329,
402,
11223,
701,
314,
199,
17376,
6634,
334,
65,
2787,
3509,
282,
2690,
367,
1924,
3623,
680,
199,
199,
3481,
4052,
342,
4882,
704,
1619,
5012,
1252,
221,
334,
7940,
1202,
370,
2597,
675,
2005,
199,
426,
300,
631,
2932,
367,
3066,
666,
12,
1325,
642,
3181,
1133,
1736,
7437,
5521,
4959,
199,
199,
8694,
1183,
12,
314,
805,
511,
342,
365,
282,
3486,
2446,
2240,
626,
4882,
199,
10058,
342,
367,
1006,
1584,
26239,
641,
314,
1423,
769,
14,
221,
2104,
2082,
199,
4958,
652,
4882,
4052,
342,
367,
1006,
1584,
315,
626,
2082,
14,
221,
3758,
199,
2094,
365,
14530,
334,
4776,
1006,
1584,
315,
314,
1453,
2082,
680,
221,
710,
199,
1422,
446,
82,
26544,
652,
370,
18011,
3224,
6602,
1911,
6272,
199,
10306,
590,
1627,
6602,
14,
199,
624,
199,
199,
3,
710,
570,
5523,
365,
2746,
13,
2110,
871,
626,
314,
511,
2240,
436,
2399,
199,
3,
1007,
17765,
11492,
2061,
14,
199,
199,
363,
452,
363,
275,
2097,
10058,
2266,
2191,
1619,
5012,
937,
199,
199,
318,
4052,
8,
1501,
304,
272,
408,
25541,
314,
730,
402,
282,
20453,
570,
624,
272,
522,
275,
704,
1619,
5012,
8,
1501,
9,
272,
372,
522,
421,
199,
318,
704,
1619,
5012,
8,
1501,
304,
272,
408,
497,
6862,
794,
20453,
2323,
624,
272,
289,
275,
1551,
8,
1501,
12,
283,
4848,
358,
272,
394,
275,
289,
14,
739,
8,
7736,
9,
272,
367,
2833,
315,
2295,
26,
267,
522,
275,
2833,
8,
72,
12,
289,
9,
267,
340,
522,
26,
288,
372,
522,
272,
372,
488,
421,
199,
3,
1444,
2595,
3,
199,
3,
4804,
12791,
3746,
1126,
20453,
1406,
730,
327,
199,
3,
1444,
2595,
3,
199,
199,
2219,
275,
942,
199,
199,
318,
511,
63,
65,
25040,
8,
72,
12,
289,
304,
272,
492,
282,
25040,
272,
340,
394,
1491,
20,
61,
1137,
283,
3516,
356,
267,
372,
488,
272,
340,
394,
59,
24,
26,
713,
61,
508,
283,
7730,
4161,
356,
267,
7104,
275,
283,
65,
25040,
7,
272,
916,
394,
59,
24,
26,
713,
61,
508,
283,
7730,
1665,
356,
267,
7104,
275,
283,
5789,
556,
7,
272,
587,
26,
267,
372,
488,
272,
289,
14,
5507,
8,
16,
9,
272,
862,
26,
267,
282,
275,
282,
25040,
14,
1490,
3997,
8,
70,
12,
283,
82,
358,
272,
871,
334,
13178,
547,
12,
282,
25040,
14,
547,
304,
267,
372,
488,
272,
372,
334,
5045,
12,
282,
14,
20912,
1866,
1062,
282,
14,
362,
78,
6324,
1062,
971,
288,
282,
14,
362,
31607,
1062,
1695,
10,
65,
14,
362,
16557,
2063,
1012,
199,
199,
2219,
14,
740,
8,
396,
63,
65,
25040,
9,
421,
199,
318,
511,
63,
3844,
8,
72,
12,
289,
304,
272,
340,
394,
1491,
20,
61,
508,
1987,
83,
977,
356,
267,
289,
275,
664,
63,
2809,
63,
1235,
272,
916,
394,
1491,
20,
61,
315,
17485,
16,
795,
3130,
283,
5797,
30194,
267,
289,
275,
664,
63,
2809,
63,
274,
272,
587,
26,
267,
372,
488,
272,
730,
275,
283,
3844,
7,
272,
15260,
63,
890,
275,
289,
8,
72,
59,
20,
26,
24,
566,
272,
666,
63,
890,
275,
289,
8,
72,
59,
24,
26,
713,
566,
272,
2644,
275,
289,
8,
72,
59,
713,
26,
975,
566,
272,
6634,
275,
289,
8,
72,
59,
975,
26,
1165,
566,
272,
302,
6324,
275,
289,
8,
72,
59,
1165,
26,
1194,
566,
272,
2690,
63,
890,
275,
413,
327,
849,
272,
340,
2644,
508,
413,
26,
267,
2690,
63,
5609,
275,
283,
53,
7,
272,
916,
2644,
508,
499,
26,
267,
2690,
63,
5609,
275,
1695,
272,
916,
2644,
508,
650,
26,
267,
2690,
63,
5609,
275,
3193,
267,
2690,
63,
890,
275,
499,
272,
587,
26,
267,
2690,
63,
5609,
275,
15539,
272,
2787,
63,
890,
275,
2690,
63,
890,
627,
302,
6324,
272,
372,
730,
12,
6634,
12,
302,
6324,
12,
666,
63,
890,
501,
1943,
63,
890,
12,
2690,
63,
5609,
199,
199,
2219,
14,
740,
8,
396,
63,
3844,
9,
421,
199,
318,
511,
63,
72,
957,
8,
72,
12,
289,
304,
272,
340,
394,
59,
2182,
26,
1876,
61,
1137,
283,
38,
2300,
36,
7,
503,
394,
59,
3933,
26,
6557,
61,
1137,
283,
40,
11265,
356,
267,
372,
488,
272,
487,
8286,
275,
664,
63,
2809,
63,
1235,
8,
72,
59,
3933,
11,
975,
26,
3933,
11,
1165,
566,
272,
372,
283,
72,
957,
297,
25647,
1400,
501,
3015,
374,
269,
12,
413,
12,
446,
17,
12,
1695,
199,
199,
2219,
14,
740,
8,
396,
63,
72,
957,
9,
421,
199,
318,
511,
63,
86,
679,
8,
72,
12,
289,
304,
272,
340,
394,
1491,
1165,
61,
1137,
283,
5482,
1905,
32665,
1885,
3814,
60,
21683,
356,
267,
372,
488,
272,
20088,
5507,
275,
664,
63,
3612,
63,
274,
8,
72,
59,
1165,
26,
1081,
566,
272,
6634,
275,
378,
272,
340,
378,
2695,
20088,
5507,
665,
6891,
436,
394,
59,
9264,
5507,
61,
508,
1557,
17,
356,
267,
6634,
600,
275,
6206,
8,
72,
59,
9264,
5507,
11,
20,
566,
267,
6634,
275,
1109,
8,
22589,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
jshiv/turntable
|
test/lib/python2.7/site-packages/scipy/fftpack/setup.py
|
20
|
1552
|
#!/usr/bin/env python
# Created by Pearu Peterson, August 2002
from __future__ import division, print_function, absolute_import
from os.path import join
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('fftpack',parent_package, top_path)
config.add_data_dir('tests')
config.add_data_dir('benchmarks')
dfftpack_src = [join('src/dfftpack','*.f')]
config.add_library('dfftpack', sources=dfftpack_src)
fftpack_src = [join('src/fftpack','*.f')]
config.add_library('fftpack', sources=fftpack_src)
sources = ['fftpack.pyf','src/zfft.c','src/drfft.c','src/zrfft.c',
'src/zfftnd.c', 'src/dct.c.src', 'src/dst.c.src']
config.add_extension('_fftpack',
sources=sources,
libraries=['dfftpack', 'fftpack'],
include_dirs=['src'],
depends=(dfftpack_src + fftpack_src))
config.add_extension('convolve',
sources=['convolve.pyf','src/convolve.c'],
libraries=['dfftpack'],
depends=dfftpack_src,
)
return config
if __name__ == '__main__':
from numpy.distutils.core import setup
from fftpack_version import fftpack_version
setup(version=fftpack_version,
description='fftpack - Discrete Fourier Transform package',
author='Pearu Peterson',
author_email='pearu@cens.ioc.ee',
maintainer_email='scipy-dev@scipy.org',
license='SciPy License (BSD Style)',
**configuration(top_path='').todict())
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
18208,
701,
510,
2210,
85,
22912,
834,
12,
25298,
833,
14790,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
421,
199,
504,
747,
14,
515,
492,
4263,
421,
199,
318,
2897,
8,
1708,
63,
2491,
4581,
2119,
63,
515,
29,
403,
304,
272,
687,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
11595,
339,
1101,
275,
11595,
360,
9996,
1389,
297,
1708,
63,
2491,
12,
2746,
63,
515,
9,
339,
1101,
14,
525,
63,
576,
63,
694,
360,
2219,
358,
272,
1101,
14,
525,
63,
576,
63,
694,
360,
11861,
83,
358,
339,
366,
9996,
1389,
63,
2164,
275,
359,
904,
360,
2164,
15,
68,
9996,
1389,
1673,
4856,
70,
5440,
272,
1101,
14,
525,
63,
4342,
360,
68,
9996,
1389,
297,
5274,
29,
68,
9996,
1389,
63,
2164,
9,
339,
18160,
1389,
63,
2164,
275,
359,
904,
360,
2164,
15,
9996,
1389,
1673,
4856,
70,
5440,
272,
1101,
14,
525,
63,
4342,
360,
9996,
1389,
297,
5274,
29,
9996,
1389,
63,
2164,
9,
339,
5274,
275,
788,
9996,
1389,
14,
647,
70,
1673,
2164,
15,
90,
9996,
14,
67,
1673,
2164,
15,
5012,
9996,
14,
67,
1673,
2164,
15,
32605,
9996,
14,
67,
297,
2049,
283,
2164,
15,
90,
9996,
977,
14,
67,
297,
283,
2164,
15,
20660,
14,
67,
14,
2164,
297,
283,
2164,
15,
5119,
14,
67,
14,
2164,
418,
339,
1101,
14,
525,
63,
3435,
6412,
9996,
1389,
297,
267,
5274,
29,
4553,
12,
267,
8363,
2968,
68,
9996,
1389,
297,
283,
9996,
1389,
995,
267,
2387,
63,
3220,
2968,
2164,
995,
267,
8350,
2687,
68,
9996,
1389,
63,
2164,
435,
18160,
1389,
63,
2164,
430,
339,
1101,
14,
525,
63,
3435,
360,
5598,
3344,
297,
267,
5274,
2968,
5598,
3344,
14,
647,
70,
1673,
2164,
15,
5598,
3344,
14,
67,
995,
267,
8363,
2968,
68,
9996,
1389,
995,
267,
8350,
29,
68,
9996,
1389,
63,
2164,
12,
272,
776,
272,
372,
1101,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
687,
2680,
14,
13350,
14,
1018,
492,
3272,
272,
687,
18160,
1389,
63,
1023,
492,
18160,
1389,
63,
1023,
272,
3272,
8,
1023,
29,
9996,
1389,
63,
1023,
12,
881,
1369,
534,
9996,
1389,
446,
5289,
7564,
23843,
4446,
19463,
2559,
297,
881,
4132,
534,
48,
2210,
85,
22912,
834,
297,
881,
4132,
63,
2123,
534,
16343,
85,
32,
2497,
83,
14,
73,
679,
14,
1024,
297,
881,
11075,
281,
63,
2123,
534,
14248,
13,
2374,
32,
14248,
14,
1308,
297,
881,
4190,
534,
29231,
2713,
844,
334,
15400,
19442,
3196,
881,
1011,
4758,
8,
2119,
63,
515,
534,
1959,
475,
807,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
18208,
701,
510,
2210,
85,
22912,
834,
12,
25298,
833,
14790,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
421,
199,
504,
747,
14,
515,
492,
4263,
421,
199,
318,
2897,
8,
1708,
63,
2491,
4581,
2119,
63,
515,
29,
403,
304,
272,
687,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
11595,
339,
1101,
275,
11595,
360,
9996,
1389,
297,
1708,
63,
2491,
12,
2746,
63,
515,
9,
339,
1101,
14,
525,
63,
576,
63,
694,
360,
2219,
358,
272,
1101,
14,
525,
63,
576,
63,
694,
360,
11861,
83,
358,
339,
366,
9996,
1389,
63,
2164,
275,
359,
904,
360,
2164,
15,
68,
9996,
1389,
1673,
4856,
70,
5440,
272,
1101,
14,
525,
63,
4342,
360,
68,
9996,
1389,
297,
5274,
29,
68,
9996,
1389,
63,
2164,
9,
339,
18160,
1389,
63,
2164,
275,
359,
904,
360,
2164,
15,
9996,
1389,
1673,
4856,
70,
5440,
272,
1101,
14,
525,
63,
4342,
360,
9996,
1389,
297,
5274,
29,
9996,
1389,
63,
2164,
9,
339,
5274,
275,
788,
9996,
1389,
14,
647,
70,
1673,
2164,
15,
90,
9996,
14,
67,
1673,
2164,
15,
5012,
9996,
14,
67,
1673,
2164,
15,
32605,
9996,
14,
67,
297,
2049,
283,
2164,
15,
90,
9996,
977,
14,
67,
297,
283,
2164,
15,
20660,
14,
67,
14,
2164,
297,
283,
2164,
15,
5119,
14,
67,
14,
2164,
418,
339,
1101,
14,
525,
63,
3435,
6412,
9996,
1389,
297,
267,
5274,
29,
4553,
12,
267,
8363,
2968,
68,
9996,
1389,
297,
283,
9996,
1389,
995,
267,
2387,
63,
3220,
2968,
2164,
995,
267,
8350,
2687,
68,
9996,
1389,
63,
2164,
435,
18160,
1389,
63,
2164,
430,
339,
1101,
14,
525,
63,
3435,
360,
5598,
3344,
297,
267,
5274,
2968,
5598,
3344,
14,
647,
70,
1673,
2164,
15,
5598,
3344,
14,
67,
995,
267,
8363,
2968,
68,
9996,
1389,
995,
267,
8350,
29,
68,
9996,
1389,
63,
2164,
12,
272,
776,
272,
372,
1101,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
687,
2680,
14,
13350,
14,
1018,
492,
3272,
272,
687,
18160,
1389,
63,
1023,
492,
18160,
1389,
63,
1023,
272,
3272,
8,
1023,
29,
9996,
1389,
63,
1023,
12,
881,
1369,
534,
9996,
1389,
446,
5289,
7564,
23843,
4446,
19463,
2559,
297,
881,
4132,
534,
48,
2210,
85,
22912,
834,
297,
881,
4132,
63,
2123,
534,
16343,
85,
32,
2497,
83,
14,
73,
679,
14,
1024,
297,
881,
11075,
281,
63,
2123,
534,
14248,
13,
2374,
32,
14248,
14,
1308,
297,
881,
4190,
534,
29231,
2713,
844,
334,
15400,
19442,
3196,
881,
1011,
4758,
8,
2119,
63,
515,
534,
1959,
475,
807,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
crafty78/ansible
|
lib/ansible/modules/packaging/os/layman.py
|
23
|
8066
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2014, Jakub Jirutka <jakub@jirutka.cz>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import shutil
from os import path
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = '''
---
module: layman
author: "Jakub Jirutka (@jirutka)"
version_added: "1.6"
short_description: Manage Gentoo overlays
description:
- Uses Layman to manage an additional repositories for the Portage package manager on Gentoo Linux.
Please note that Layman must be installed on a managed node prior using this module.
requirements:
- "python >= 2.6"
- layman python module
options:
name:
description:
- The overlay id to install, synchronize, or uninstall.
Use 'ALL' to sync all of the installed overlays (can be used only when C(state=updated)).
required: true
list_url:
description:
- An URL of the alternative overlays list that defines the overlay to install.
This list will be fetched and saved under C(${overlay_defs})/${name}.xml), where
C(overlay_defs) is readed from the Layman's configuration.
required: false
state:
description:
- Whether to install (C(present)), sync (C(updated)), or uninstall (C(absent)) the overlay.
required: false
default: present
choices: [present, absent, updated]
validate_certs:
description:
- If C(no), SSL certificates will not be validated. This should only be
set to C(no) when no other option exists. Prior to 1.9.3 the code
defaulted to C(no).
required: false
default: 'yes'
choices: ['yes', 'no']
version_added: '1.9.3'
'''
EXAMPLES = '''
# Install the overlay 'mozilla' which is on the central overlays list.
- layman:
name: mozilla
# Install the overlay 'cvut' from the specified alternative list.
- layman:
name: cvut
list_url: 'http://raw.github.com/cvut/gentoo-overlay/master/overlay.xml'
# Update (sync) the overlay 'cvut', or install if not installed yet.
- layman:
name: cvut
list_url: 'http://raw.github.com/cvut/gentoo-overlay/master/overlay.xml'
state: updated
# Update (sync) all of the installed overlays.
- layman:
name: ALL
state: updated
# Uninstall the overlay 'cvut'.
- layman:
name: cvut
state: absent
'''
USERAGENT = 'ansible-httpget'
try:
from layman.api import LaymanAPI
from layman.config import BareConfig
HAS_LAYMAN_API = True
except ImportError:
HAS_LAYMAN_API = False
class ModuleError(Exception): pass
def init_layman(config=None):
'''Returns the initialized ``LaymanAPI``.
:param config: the layman's configuration to use (optional)
'''
if config is None:
config = BareConfig(read_configfile=True, quietness=1)
return LaymanAPI(config)
def download_url(module, url, dest):
'''
:param url: the URL to download
:param dest: the absolute path of where to save the downloaded content to;
it must be writable and not a directory
:raises ModuleError
'''
# Hack to add params in the form that fetch_url expects
module.params['http_agent'] = USERAGENT
response, info = fetch_url(module, url)
if info['status'] != 200:
raise ModuleError("Failed to get %s: %s" % (url, info['msg']))
try:
with open(dest, 'w') as f:
shutil.copyfileobj(response, f)
except IOError as e:
raise ModuleError("Failed to write: %s" % str(e))
def install_overlay(module, name, list_url=None):
'''Installs the overlay repository. If not on the central overlays list,
then :list_url of an alternative list must be provided. The list will be
fetched and saved under ``%(overlay_defs)/%(name.xml)`` (location of the
``overlay_defs`` is read from the Layman's configuration).
:param name: the overlay id
:param list_url: the URL of the remote repositories list to look for the overlay
definition (optional, default: None)
:returns: True if the overlay was installed, or False if already exists
(i.e. nothing has changed)
:raises ModuleError
'''
# read Layman configuration
layman_conf = BareConfig(read_configfile=True)
layman = init_layman(layman_conf)
if layman.is_installed(name):
return False
if module.check_mode:
mymsg = 'Would add layman repo \'' + name + '\''
module.exit_json(changed=True, msg=mymsg)
if not layman.is_repo(name):
if not list_url:
raise ModuleError("Overlay '%s' is not on the list of known " \
"overlays and URL of the remote list was not provided." % name)
overlay_defs = layman_conf.get_option('overlay_defs')
dest = path.join(overlay_defs, name + '.xml')
download_url(module, list_url, dest)
# reload config
layman = init_layman()
if not layman.add_repos(name):
raise ModuleError(layman.get_errors())
return True
def uninstall_overlay(module, name):
'''Uninstalls the given overlay repository from the system.
:param name: the overlay id to uninstall
:returns: True if the overlay was uninstalled, or False if doesn't exist
(i.e. nothing has changed)
:raises ModuleError
'''
layman = init_layman()
if not layman.is_installed(name):
return False
if module.check_mode:
mymsg = 'Would remove layman repo \'' + name + '\''
module.exit_json(changed=True, msg=mymsg)
layman.delete_repos(name)
if layman.get_errors(): raise ModuleError(layman.get_errors())
return True
def sync_overlay(name):
'''Synchronizes the specified overlay repository.
:param name: the overlay repository id to sync
:raises ModuleError
'''
layman = init_layman()
if not layman.sync(name):
messages = [ str(item[1]) for item in layman.sync_results[2] ]
raise ModuleError(messages)
def sync_overlays():
'''Synchronize all of the installed overlays.
:raises ModuleError
'''
layman = init_layman()
for name in layman.get_installed():
sync_overlay(name)
def main():
# define module
module = AnsibleModule(
argument_spec = dict(
name = dict(required=True),
list_url = dict(aliases=['url']),
state = dict(default="present", choices=['present', 'absent', 'updated']),
validate_certs = dict(required=False, default=True, type='bool'),
),
supports_check_mode=True
)
if not HAS_LAYMAN_API:
module.fail_json(msg='Layman is not installed')
state, name, url = (module.params[key] for key in ['state', 'name', 'list_url'])
changed = False
try:
if state == 'present':
changed = install_overlay(module, name, url)
elif state == 'updated':
if name == 'ALL':
sync_overlays()
elif install_overlay(module, name, url):
changed = True
else:
sync_overlay(name)
else:
changed = uninstall_overlay(module, name)
except ModuleError as e:
module.fail_json(msg=e.message)
else:
module.exit_json(changed=changed, name=name)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6927,
12,
1603,
1151,
456,
1603,
723,
337,
7351,
665,
74,
1151,
456,
32,
74,
723,
337,
7351,
14,
16823,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
5145,
199,
504,
747,
492,
931,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
27305,
1237,
199,
2502,
26,
298,
42,
1151,
456,
1603,
723,
337,
7351,
8593,
74,
723,
337,
7351,
2924,
199,
1023,
63,
3270,
26,
298,
17,
14,
22,
2,
199,
3612,
63,
1802,
26,
14944,
18870,
7354,
1806,
9316,
199,
1802,
26,
523,
446,
14911,
9366,
1237,
370,
9635,
376,
4722,
23737,
367,
314,
10977,
474,
2559,
5256,
641,
18870,
7354,
10130,
14,
272,
7754,
5317,
626,
9366,
1237,
1471,
506,
4903,
641,
282,
12883,
1031,
6791,
1808,
642,
859,
14,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
27305,
1237,
2366,
859,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
24393,
1305,
370,
3907,
12,
31021,
12,
503,
22199,
14,
267,
3645,
283,
1761,
7,
370,
7604,
1006,
402,
314,
4903,
1806,
9316,
334,
2425,
506,
1202,
1454,
1380,
445,
8,
929,
29,
5334,
4992,
272,
1415,
26,
2549,
523,
769,
63,
633,
26,
272,
1369,
26,
489,
446,
1626,
2851,
402,
314,
13943,
1806,
9316,
769,
626,
7890,
314,
24393,
370,
3907,
14,
267,
961,
769,
911,
506,
19251,
436,
6290,
1334,
445,
8,
10545,
18534,
63,
8710,
1552,
15,
10545,
354,
5565,
1652,
395,
2382,
267,
445,
8,
18534,
63,
8710,
9,
365,
295,
3074,
687,
314,
9366,
1237,
1159,
2897,
14,
272,
1415,
26,
3055,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
370,
3907,
334,
35,
8,
1881,
1826,
7604,
334,
35,
8,
5334,
1826,
503,
22199,
334,
35,
8,
5575,
430,
314,
24393,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
359,
1881,
12,
9552,
12,
4588,
61,
523,
4107,
63,
8356,
26,
272,
1369,
26,
489,
446,
982,
445,
8,
889,
395,
7799,
14512,
911,
440,
506,
16468,
14,
961,
1077,
1454,
506,
267,
663,
370,
445,
8,
889,
9,
1380,
949,
1163,
945,
3495,
14,
221,
8538,
269,
370,
413,
14,
25,
14,
19,
314,
1233,
267,
347,
21642,
471,
370,
445,
8,
889,
680,
272,
1415,
26,
3055,
272,
849,
26,
283,
5066,
7,
272,
3415,
26,
788,
5066,
297,
283,
889,
418,
272,
1015,
63,
3270,
26,
283,
17,
14,
25,
14,
19,
7,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
13276,
314,
24393,
283,
12102,
7,
1314,
365,
641,
314,
18796,
1806,
9316,
769,
14,
199,
13,
27305,
1237,
26,
272,
536,
26,
1303,
6956,
199,
199,
3,
13276,
314,
24393,
283,
5107,
337,
7,
687,
314,
2013,
13943,
769,
14,
199,
13,
27305,
1237,
26,
272,
536,
26,
6277,
337,
272,
769,
63,
633,
26,
283,
1014,
921,
1773,
14,
5031,
14,
957,
15,
5107,
337,
15,
2268,
7354,
13,
18534,
15,
4133,
15,
18534,
14,
1652,
7,
199,
199,
3,
6162,
334,
5186,
9,
314,
24393,
283,
5107,
337,
297,
503,
3907,
340,
440,
4903,
5966,
14,
199,
13,
27305,
1237,
26,
272,
536,
26,
6277,
337,
272,
769,
63,
633,
26,
283,
1014,
921,
1773,
14,
5031,
14,
957,
15,
5107,
337,
15,
2268,
7354,
13,
18534,
15,
4133,
15,
18534,
14,
1652,
7,
272,
1174,
26,
4588,
199,
199,
3,
6162,
334,
5186,
9,
1006,
402,
314,
4903,
1806,
9316,
14,
199,
13,
27305,
1237,
26,
272,
536,
26,
11727,
272,
1174,
26,
4588,
199,
199,
3,
1910,
3174,
314,
24393,
283,
5107,
337,
1370,
199,
13,
27305,
1237,
26,
272,
536,
26,
6277,
337,
272,
1174,
26,
9552,
199,
2344,
199,
199,
3791,
14565,
275,
283,
4853,
13,
1014,
362,
7,
199,
199,
893,
26,
272,
687,
27305,
1237,
14,
1246,
492,
9366,
1237,
3735,
272,
687,
27305,
1237,
14,
888,
492,
699,
1530,
2028,
272,
7509,
63,
16897,
6588,
63,
3735,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
16897,
6588,
63,
3735,
275,
756,
421,
199,
533,
5673,
547,
8,
1726,
304,
986,
421,
199,
318,
4205,
63,
817,
1237,
8,
888,
29,
403,
304,
272,
1449,
3407,
314,
10038,
1124,
3047,
1237,
3735,
4345,
339,
520,
635,
1101,
26,
314,
27305,
1237,
1159,
2897,
370,
675,
334,
4144,
9,
272,
1449,
272,
340,
1101,
365,
488,
26,
267,
1101,
275,
699,
1530,
2028,
8,
739,
63,
29217,
29,
549,
12,
11971,
4171,
29,
17,
9,
272,
372,
9366,
1237,
3735,
8,
888,
9,
421,
199,
318,
5235,
63,
633,
8,
578,
12,
1166,
12,
2053,
304,
272,
1449,
272,
520,
635,
1166,
26,
314,
2851,
370,
5235,
272,
520,
635,
2053,
26,
314,
3679,
931,
402,
2382,
370,
3354,
314,
13557,
1564,
370,
27,
267,
652,
1471,
506,
17267,
436,
440,
282,
2082,
339,
520,
3536,
5673,
547,
272,
1449,
339,
327,
30802,
370,
1050,
1862,
315,
314,
1824,
626,
5267,
63,
633,
14292,
272,
859,
14,
1162
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6927,
12,
1603,
1151,
456,
1603,
723,
337,
7351,
665,
74,
1151,
456,
32,
74,
723,
337,
7351,
14,
16823,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
5145,
199,
504,
747,
492,
931,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
27305,
1237,
199,
2502,
26,
298,
42,
1151,
456,
1603,
723,
337,
7351,
8593,
74,
723,
337,
7351,
2924,
199,
1023,
63,
3270,
26,
298,
17,
14,
22,
2,
199,
3612,
63,
1802,
26,
14944,
18870,
7354,
1806,
9316,
199,
1802,
26,
523,
446,
14911,
9366,
1237,
370,
9635,
376,
4722,
23737,
367,
314,
10977,
474,
2559,
5256,
641,
18870,
7354,
10130,
14,
272,
7754,
5317,
626,
9366,
1237,
1471,
506,
4903,
641,
282,
12883,
1031,
6791,
1808,
642,
859,
14,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
27305,
1237,
2366,
859,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
24393,
1305,
370,
3907,
12,
31021,
12,
503,
22199,
14,
267,
3645,
283,
1761,
7,
370,
7604,
1006,
402,
314,
4903,
1806,
9316,
334,
2425,
506,
1202,
1454,
1380,
445,
8,
929,
29,
5334,
4992,
272,
1415,
26,
2549,
523,
769,
63,
633,
26,
272,
1369,
26,
489,
446,
1626,
2851,
402,
314,
13943,
1806,
9316,
769,
626,
7890,
314,
24393,
370,
3907,
14,
267,
961,
769,
911,
506,
19251,
436,
6290,
1334,
445,
8,
10545,
18534,
63,
8710,
1552,
15,
10545,
354,
5565,
1652,
395,
2382,
267,
445,
8,
18534,
63,
8710,
9,
365,
295,
3074,
687,
314,
9366,
1237,
1159,
2897,
14,
272,
1415,
26,
3055,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
370,
3907,
334,
35,
8,
1881,
1826,
7604,
334,
35,
8,
5334,
1826,
503,
22199,
334,
35,
8,
5575,
430,
314,
24393,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
359,
1881,
12,
9552,
12,
4588,
61,
523,
4107,
63,
8356,
26,
272,
1369,
26,
489,
446,
982,
445,
8,
889,
395,
7799,
14512,
911,
440,
506,
16468,
14,
961,
1077,
1454,
506,
267,
663,
370,
445,
8,
889,
9,
1380,
949,
1163,
945,
3495,
14,
221,
8538,
269,
370,
413,
14,
25,
14,
19,
314,
1233,
267,
347,
21642,
471,
370,
445,
8,
889,
680,
272,
1415,
26,
3055,
272,
849,
26,
283,
5066,
7,
272,
3415,
26,
788,
5066,
297,
283,
889,
418,
272,
1015,
63,
3270,
26,
283,
17,
14,
25,
14,
19,
7,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
13276,
314,
24393,
283,
12102,
7,
1314,
365,
641,
314,
18796,
1806,
9316,
769,
14,
199,
13,
27305,
1237,
26,
272,
536,
26,
1303,
6956,
199,
199,
3,
13276,
314,
24393,
283,
5107,
337,
7,
687,
314,
2013,
13943,
769,
14,
199,
13,
27305,
1237,
26,
272,
536,
26,
6277,
337,
272,
769,
63,
633,
26,
283,
1014,
921,
1773,
14,
5031,
14,
957,
15,
5107,
337,
15,
2268,
7354,
13,
18534,
15,
4133,
15,
18534,
14,
1652,
7,
199,
199,
3,
6162,
334,
5186,
9,
314,
24393,
283,
5107,
337,
297,
503,
3907,
340,
440,
4903,
5966,
14,
199,
13,
27305,
1237,
26,
272,
536,
26,
6277,
337,
272,
769,
63,
633,
26,
283,
1014,
921,
1773,
14,
5031,
14,
957,
15,
5107,
337,
15,
2268,
7354,
13,
18534,
15,
4133,
15,
18534,
14,
1652,
7,
272,
1174,
26,
4588,
199,
199,
3,
6162,
334,
5186,
9,
1006,
402,
314,
4903,
1806,
9316,
14,
199,
13,
27305,
1237,
26,
272,
536,
26,
11727,
272,
1174,
26,
4588,
199,
199,
3,
1910,
3174,
314,
24393,
283,
5107,
337,
1370,
199,
13,
27305,
1237,
26,
272,
536,
26,
6277,
337,
272,
1174,
26,
9552,
199,
2344,
199,
199,
3791,
14565,
275,
283,
4853,
13,
1014,
362,
7,
199,
199,
893,
26,
272,
687,
27305,
1237,
14,
1246,
492,
9366,
1237,
3735,
272,
687,
27305,
1237,
14,
888,
492,
699,
1530,
2028,
272,
7509,
63,
16897,
6588,
63,
3735,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
16897,
6588,
63,
3735,
275,
756,
421,
199,
533,
5673,
547,
8,
1726,
304,
986,
421,
199,
318,
4205,
63,
817,
1237,
8,
888,
29,
403,
304,
272,
1449,
3407,
314,
10038,
1124,
3047,
1237,
3735,
4345,
339,
520,
635,
1101,
26,
314,
27305,
1237,
1159,
2897,
370,
675,
334,
4144,
9,
272,
1449,
272,
340,
1101,
365,
488,
26,
267,
1101,
275,
699,
1530,
2028,
8,
739,
63,
29217,
29,
549,
12,
11971,
4171,
29,
17,
9,
272,
372,
9366,
1237,
3735,
8,
888,
9,
421,
199,
318,
5235,
63,
633,
8,
578,
12,
1166,
12,
2053,
304,
272,
1449,
272,
520,
635,
1166,
26,
314,
2851,
370,
5235,
272,
520,
635,
2053,
26,
314,
3679,
931,
402,
2382,
370,
3354,
314,
13557,
1564,
370,
27,
267,
652,
1471,
506,
17267,
436,
440,
282,
2082,
339,
520,
3536,
5673,
547,
272,
1449,
339,
327,
30802,
370,
1050,
1862,
315,
314,
1824,
626,
5267,
63,
633,
14292,
272,
859,
14,
1162,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
igboyes/virtool
|
virtool/pathoscope.py
|
2
|
13498
|
import collections
import copy
import csv
import math
import os
import shutil
def rescale_samscore(u, nu, max_score, min_score):
if min_score < 0:
scaling_factor = 100.0 / max_score - min_score
else:
scaling_factor = 100.0 / max_score
for read_index in u:
if min_score < 0:
u[read_index][1][0] = u[read_index][1][0] - min_score
u[read_index][1][0] = math.exp(u[read_index][1][0] * scaling_factor)
u[read_index][3] = u[read_index][1][0]
for read_index in nu:
nu[read_index][3] = 0.0
for i in range(0, len(nu[read_index][1])):
if min_score < 0:
nu[read_index][1][i] = nu[read_index][1][i] - min_score
nu[read_index][1][i] = math.exp(nu[read_index][1][i] * scaling_factor)
if nu[read_index][1][i] > nu[read_index][3]:
nu[read_index][3] = nu[read_index][1][i]
return u, nu
def find_sam_align_score(fields):
"""
Find the Bowtie2 alignment score for the given split line (``fields``).
Searches the SAM fields for the ``AS:i`` substring and extracts the Bowtie2-specific alignment score. This will not
work for other aligners.
:param fields: a line that has been split on "\t"
:type fields: list
:return: the alignment score
:rtype: float
"""
read_length = float(len(fields[9]))
for field in fields:
if field.startswith("AS:i:"):
a_score = int(field[5:])
return a_score + read_length
raise ValueError("Could not find alignment score")
def build_matrix(vta_path, p_score_cutoff=0.01):
u = dict()
nu = dict()
h_read_id = {}
h_ref_id = {}
refs = []
reads = []
ref_count = 0
read_count = 0
max_score = 0
min_score = 0
with open(vta_path, "r") as handle:
for line in handle:
read_id, ref_id, _, _, p_score = line.rstrip().split(",")
p_score = float(p_score)
if p_score < p_score_cutoff:
continue
min_score = min(min_score, p_score)
max_score = max(max_score, p_score)
ref_index = h_ref_id.get(ref_id, -1)
if ref_index == -1:
ref_index = ref_count
h_ref_id[ref_id] = ref_index
refs.append(ref_id)
ref_count += 1
read_index = h_read_id.get(read_id, -1)
if read_index == -1:
# hold on this new read. first, wrap previous read profile and see if any previous read has a same
# profile with that!
read_index = read_count
h_read_id[read_id] = read_index
reads.append(read_id)
read_count += 1
u[read_index] = [[ref_index], [p_score], [float(p_score)], p_score]
else:
if read_index in u:
if ref_index in u[read_index][0]:
continue
nu[read_index] = u[read_index]
del u[read_index]
if ref_index in nu[read_index][0]:
continue
nu[read_index][0].append(ref_index)
nu[read_index][1].append(p_score)
if p_score > nu[read_index][3]:
nu[read_index][3] = p_score
u, nu = rescale_samscore(u, nu, max_score, min_score)
for read_index in u:
# keep ref_index and score only
u[read_index] = [u[read_index][0][0], u[read_index][1][0]]
for read_index in nu:
p_score_sum = sum(nu[read_index][1])
# Normalize p_score.
nu[read_index][2] = [k / p_score_sum for k in nu[read_index][1]]
return u, nu, refs, reads
def em(u, nu, genomes, max_iter, epsilon, pi_prior, theta_prior):
genome_count = len(genomes)
pi = [1. / genome_count] * genome_count
init_pi = copy.copy(pi)
theta = copy.copy(pi)
pi_sum_0 = [0] * genome_count
u_weights = [u[i][1] for i in u]
max_u_weights = 0
u_total = 0
if u_weights:
max_u_weights = max(u_weights)
u_total = sum(u_weights)
for i in u:
pi_sum_0[u[i][0]] += u[i][1]
nu_weights = [nu[i][3] for i in nu]
max_nu_weights = 0
nu_total = 0
if nu_weights:
max_nu_weights = max(nu_weights)
nu_total = sum(nu_weights)
prior_weight = max(max_u_weights, max_nu_weights)
nu_length = len(nu)
if nu_length == 0:
nu_length = 1
# EM iterations
for i in range(max_iter):
pi_old = pi
theta_sum = [0 for _ in genomes]
# E Step
for j in nu:
z = nu[j]
# A set of any genome mapping with j
ind = z[0]
# Get relevant pis for the read
pi_tmp = [pi[k] for k in ind]
# Get relevant thetas for the read.
theta_tmp = [theta[k] for k in ind]
# Calculate non-normalized xs
x_tmp = [1. * pi_tmp[k] * theta_tmp[k] * z[1][k] for k in range(len(ind))]
x_sum = sum(x_tmp)
# Avoid dividing by 0 at all times.
if x_sum == 0:
x_norm = [0.0 for _ in x_tmp]
else:
# Normalize new xs.
x_norm = [1. * k / x_sum for k in x_tmp]
# Update x in nu.
nu[j][2] = x_norm
for k, _ in enumerate(ind):
# Keep weighted running tally for theta
theta_sum[ind[k]] += x_norm[k] * nu[j][3]
# M step
pi_sum = [theta_sum[k] + pi_sum_0[k] for k in range(len(theta_sum))]
pip = pi_prior * prior_weight
# Update pi.
pi = [(1. * k + pip) / (u_total + nu_total + pip * len(pi_sum)) for k in pi_sum]
if i == 0:
init_pi = pi
theta_p = theta_prior * prior_weight
nu_total_div = nu_total
if nu_total_div == 0:
nu_total_div = 1
theta = [(1. * k + theta_p) / (nu_total_div + theta_p * len(theta_sum)) for k in theta_sum]
cutoff = 0.0
for k, _ in enumerate(pi):
cutoff += abs(pi_old[k] - pi[k])
if cutoff <= epsilon or nu_length == 1:
break
return init_pi, pi, theta, nu
def find_updated_score(nu, read_index, ref_index):
try:
index = nu[read_index][0].index(ref_index)
except ValueError:
return 0.0, 0.0
p_score_sum = 0.0
for p_score in nu[read_index][1]:
p_score_sum += p_score
updated_pscore = nu[read_index][2][index]
return updated_pscore
def compute_best_hit(u, nu, refs, reads):
ref_count = len(refs)
best_hit_reads = [0.0] * ref_count
level_1_reads = [0.0] * ref_count
level_2_reads = [0.0] * ref_count
for i in u:
best_hit_reads[u[i][0]] += 1
level_1_reads[u[i][0]] += 1
for j in nu:
z = nu[j]
ind = z[0]
x_norm = z[2]
best_ref = max(x_norm)
num_best_ref = 0
for i, _ in enumerate(x_norm):
if x_norm[i] == best_ref:
num_best_ref += 1
num_best_ref = num_best_ref or 1
for i, _ in enumerate(x_norm):
if x_norm[i] == best_ref:
best_hit_reads[ind[i]] += 1.0 / num_best_ref
if x_norm[i] >= 0.5:
level_1_reads[ind[i]] += 1
elif x_norm[i] >= 0.01:
level_2_reads[ind[i]] += 1
ref_count = len(refs)
read_count = len(reads)
best_hit = [best_hit_reads[k] / read_count for k in range(ref_count)]
level_1 = [level_1_reads[k] / read_count for k in range(ref_count)]
level_2 = [level_2_reads[k] / read_count for k in range(ref_count)]
return best_hit_reads, best_hit, level_1, level_2
def write_report(path, pi, refs, read_count, init_pi, best_hit_initial, best_hit_initial_reads, best_hit_final,
best_hit_final_reads, level_1_initial, level_2_initial, level_1_final, level_2_final):
tmp = zip(
pi,
refs,
init_pi,
best_hit_initial,
best_hit_initial_reads,
best_hit_final,
best_hit_final_reads,
level_1_initial,
level_2_initial,
level_1_final,
level_2_final
)
tmp = sorted(tmp, reverse=True)
x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11 = zip(*tmp)
no_cutoff = False
for i, _ in enumerate(x10):
if not no_cutoff and x1[i] < 0.01 and x10[i] <= 0 and x11[i] <= 0:
break
if i == (len(x10) - 1):
i += 1
# Changing the column order here
tmp = zip(
x2[:i],
x1[:i],
x6[:i],
x7[:i],
x10[:i],
x11[:i],
x3[:i],
x4[:i],
x5[:i],
x8[:i],
x9[:i]
)
with open(path, "w") as handle:
csv_writer = csv.writer(handle, delimiter='\t')
header = [
"Genome",
"Final Guess",
"Final Best Hit",
"Final Best Hit Read Numbers",
"Final High Confidence Hits",
"Final Low Confidence Hits",
"Initial Guess",
"Initial Best Hit",
"Initial Best Hit Read Numbers",
"Initial High Confidence Hits",
"Initial Low Confidence Hits"
]
header1 = ["Total Number of Aligned Reads:", read_count, "Total Number of Mapped Genomes:", len(refs)]
csv_writer.writerow(header1)
csv_writer.writerow(header)
csv_writer.writerows(tmp)
results = dict()
for i, ref_id in enumerate(x2[:i]):
if x1[i] < 0.01 and x10[i] <= 0 and x11[i] <= 0:
pass
else:
results[ref_id] = {
"final": {
"pi": x1[i],
"best": x6[i],
"high": x10[i],
"low": x11[i],
"reads": int(x7[i])
},
"initial": {
"pi": x3[i],
"best": x4[i],
"high": x8[i],
"low": x9[i],
"reads": int(x5[i])
}
}
return results
def rewrite_align(u, nu, vta_path, p_score_cutoff, path):
with open(path, 'w') as of:
with open(vta_path, 'r') as in1:
read_id_dict = {}
ref_id_dict = {}
genomes = []
read = []
ref_count = 0
read_count = 0
for line in in1:
read_id, ref_id, _, _, p_score = line.split(",")
p_score = float(p_score)
if p_score < p_score_cutoff:
continue
ref_index = ref_id_dict.get(ref_id, -1)
if ref_index == -1:
ref_index = ref_count
ref_id_dict[ref_id] = ref_index
genomes.append(ref_id)
ref_count += 1
read_index = read_id_dict.get(read_id, -1)
if read_index == -1:
# hold on this new read
# first, wrap previous read profile and see if any previous read has a same profile with that!
read_index = read_count
read_id_dict[read_id] = read_index
read.append(read_id)
read_count += 1
if read_index in u:
of.write(line)
continue
if read_index in nu:
if find_updated_score(nu, read_index, ref_index) < p_score_cutoff:
continue
of.write(line)
def calculate_coverage(vta_path, ref_lengths):
coverage_dict = dict()
pos_length_list = list()
with open(vta_path, "r") as old_handle:
for line in old_handle:
_, ref_id, pos, length, _ = line.split(",")
coverage_dict[ref_id] = None
pos_length_list.append((ref_id, int(pos), int(length)))
for key in coverage_dict:
coverage_dict[key] = [0] * ref_lengths[key]
for ref_id, pos, length in pos_length_list:
start_index = pos - 1
for i in range(start_index, start_index + length):
try:
coverage_dict[ref_id][i] += 1
except IndexError:
pass
return coverage_dict
def subtract(analysis_path, host_scores):
vta_path = os.path.join(analysis_path, "to_isolates.vta")
isolates_high_scores = collections.defaultdict(int)
with open(vta_path, "r") as handle:
for line in handle:
fields = line.rstrip().split(",")
read_id = fields[0]
isolates_high_scores[read_id] = max(isolates_high_scores[read_id], float(fields[4]))
out_path = os.path.join(analysis_path, "subtracted.vta")
subtracted_read_ids = set()
with open(vta_path, "r") as vta_handle:
with open(out_path, "w") as out_handle:
for line in vta_handle:
fields = line.rstrip().split(",")
read_id = fields[0]
if isolates_high_scores[read_id] > host_scores.get(read_id, 0):
out_handle.write(line)
else:
subtracted_read_ids.add(read_id)
os.remove(vta_path)
shutil.move(out_path, vta_path)
return len(subtracted_read_ids)
|
mit
|
[
646,
5055,
199,
646,
1331,
199,
646,
7392,
199,
646,
3473,
199,
646,
747,
199,
646,
5145,
421,
199,
318,
522,
2357,
63,
21660,
3397,
8,
85,
12,
15699,
12,
1390,
63,
3397,
12,
1748,
63,
3397,
304,
272,
340,
1748,
63,
3397,
665,
378,
26,
267,
13690,
63,
4778,
275,
2948,
14,
16,
1182,
1390,
63,
3397,
446,
1748,
63,
3397,
272,
587,
26,
267,
13690,
63,
4778,
275,
2948,
14,
16,
1182,
1390,
63,
3397,
339,
367,
1586,
63,
1080,
315,
399,
26,
267,
340,
1748,
63,
3397,
665,
378,
26,
288,
399,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
275,
399,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
446,
1748,
63,
3397,
398,
399,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
275,
3473,
14,
1474,
8,
85,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
627,
13690,
63,
4778,
9,
267,
399,
59,
739,
63,
1080,
1527,
19,
61,
275,
399,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
339,
367,
1586,
63,
1080,
315,
15699,
26,
267,
15699,
59,
739,
63,
1080,
1527,
19,
61,
275,
378,
14,
16,
398,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
4850,
59,
739,
63,
1080,
1527,
17,
18710,
288,
340,
1748,
63,
3397,
665,
378,
26,
355,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
275,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
446,
1748,
63,
3397,
953,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
275,
3473,
14,
1474,
8,
4850,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
627,
13690,
63,
4778,
9,
953,
340,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
690,
15699,
59,
739,
63,
1080,
1527,
19,
2189,
355,
15699,
59,
739,
63,
1080,
1527,
19,
61,
275,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
339,
372,
399,
12,
15699,
421,
199,
318,
2342,
63,
21660,
63,
5743,
63,
3397,
8,
955,
304,
272,
408,
272,
6668,
314,
699,
583,
23958,
18,
13177,
5396,
367,
314,
1627,
3715,
1004,
15693,
955,
20008,
339,
8730,
397,
314,
428,
1156,
1504,
367,
314,
1124,
1179,
26,
73,
1040,
20597,
436,
5536,
83,
314,
699,
583,
23958,
18,
13,
6100,
13177,
5396,
14,
961,
911,
440,
272,
1736,
367,
1163,
6998,
1192,
14,
339,
520,
635,
1504,
26,
282,
1004,
626,
965,
2757,
3715,
641,
1867,
84,
2,
272,
520,
466,
1504,
26,
769,
339,
520,
1107,
26,
314,
13177,
5396,
272,
520,
4500,
26,
2069,
339,
408,
272,
1586,
63,
1267,
275,
2069,
8,
552,
8,
955,
59,
25,
2459,
339,
367,
901,
315,
1504,
26,
267,
340,
901,
14,
2460,
480,
1179,
26,
73,
26,
2349,
288,
282,
63,
3397,
275,
1109,
8,
698,
59,
21,
5728,
288,
372,
282,
63,
3397,
435,
1586,
63,
1267,
339,
746,
1722,
480,
6531,
440,
2342,
13177,
5396,
531,
421,
199,
318,
1900,
63,
3642,
8,
86,
502,
63,
515,
12,
299,
63,
3397,
63,
17708,
29,
16,
14,
614,
304,
272,
399,
275,
1211,
342,
272,
15699,
275,
1211,
342,
339,
394,
63,
739,
63,
344,
275,
1052,
272,
394,
63,
1121,
63,
344,
275,
1052,
339,
15749,
275,
942,
272,
11597,
275,
942,
339,
2984,
63,
835,
275,
378,
272,
1586,
63,
835,
275,
378,
339,
1390,
63,
3397,
275,
378,
272,
1748,
63,
3397,
275,
378,
339,
543,
1551,
8,
86,
502,
63,
515,
12,
298,
82,
531,
465,
2429,
26,
267,
367,
1004,
315,
2429,
26,
288,
1586,
63,
344,
12,
2984,
63,
344,
12,
5501,
5501,
299,
63,
3397,
275,
1004,
14,
6735,
1252,
1294,
20324,
953,
299,
63,
3397,
275,
2069,
8,
80,
63,
3397,
9,
953,
340,
299,
63,
3397,
665,
299,
63,
3397,
63,
17708,
26,
355,
1980,
953,
1748,
63,
3397,
275,
1748,
8,
827,
63,
3397,
12,
299,
63,
3397,
9,
288,
1390,
63,
3397,
275,
1390,
8,
988,
63,
3397,
12,
299,
63,
3397,
9,
953,
2984,
63,
1080,
275,
394,
63,
1121,
63,
344,
14,
362,
8,
1121,
63,
344,
12,
446,
17,
9,
953,
340,
2984,
63,
1080,
508,
446,
17,
26,
355,
2984,
63,
1080,
275,
2984,
63,
835,
355,
394,
63,
1121,
63,
344,
59,
1121,
63,
344,
61,
275,
2984,
63,
1080,
355,
15749,
14,
740,
8,
1121,
63,
344,
9,
355,
2984,
63,
835,
847,
413,
953,
1586,
63,
1080,
275,
394,
63,
739,
63,
344,
14,
362,
8,
739,
63,
344,
12,
446,
17,
9,
953,
340,
1586,
63,
1080,
508,
446,
17,
26,
355,
327,
10266,
641,
642,
892,
1586,
14,
1642,
12,
4816,
4136,
1586,
4690,
436,
1937,
340,
1263,
4136,
1586,
965,
282,
2011,
355,
327,
4690,
543,
626,
1,
355,
1586,
63,
1080,
275,
1586,
63,
835,
355,
394,
63,
739,
63,
344,
59,
739,
63,
344,
61,
275,
1586,
63,
1080,
355,
11597,
14,
740,
8,
739,
63,
344,
9,
355,
1586,
63,
835,
847,
413,
355,
399,
59,
739,
63,
1080,
61,
275,
3474,
1121,
63,
1080,
467,
359,
80,
63,
3397,
467,
359,
1609,
8,
80,
63,
3397,
4360,
299,
63,
3397,
61,
288,
587,
26,
355,
340,
1586,
63,
1080,
315,
399,
26,
490,
340,
2984,
63,
1080,
315,
399,
59,
739,
63,
1080,
1527,
16,
2189,
717,
1980,
490,
15699,
59,
739,
63,
1080,
61,
275,
399,
59,
739,
63,
1080,
61,
490,
2150,
399,
59,
739,
63,
1080,
61,
2234,
340,
2984,
63,
1080,
315,
15699,
59,
739,
63,
1080,
1527,
16,
2189,
490,
1980,
2234,
15699,
59,
739,
63,
1080,
1527,
16,
1055,
740,
8,
1121,
63,
1080,
9,
355,
15699,
59,
739,
63,
1080,
1527,
17,
1055,
740,
8,
80,
63,
3397,
9,
2234,
340,
299,
63,
3397,
690,
15699,
59,
739,
63,
1080,
1527,
19,
2189,
490,
15699,
59,
739,
63,
1080,
1527,
19,
61,
275,
299,
63,
3397,
339,
399,
12,
15699,
275,
522,
2357,
63,
21660,
3397,
8,
85,
12,
15699,
12,
1390,
63,
3397,
12,
1748,
63,
3397,
9,
339,
367,
1586,
63,
1080,
315,
399,
26,
267,
327,
4215,
2984,
63,
1080,
436,
5396,
1454,
267,
399,
59,
739,
63,
1080,
61,
275
] |
[
5055,
199,
646,
1331,
199,
646,
7392,
199,
646,
3473,
199,
646,
747,
199,
646,
5145,
421,
199,
318,
522,
2357,
63,
21660,
3397,
8,
85,
12,
15699,
12,
1390,
63,
3397,
12,
1748,
63,
3397,
304,
272,
340,
1748,
63,
3397,
665,
378,
26,
267,
13690,
63,
4778,
275,
2948,
14,
16,
1182,
1390,
63,
3397,
446,
1748,
63,
3397,
272,
587,
26,
267,
13690,
63,
4778,
275,
2948,
14,
16,
1182,
1390,
63,
3397,
339,
367,
1586,
63,
1080,
315,
399,
26,
267,
340,
1748,
63,
3397,
665,
378,
26,
288,
399,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
275,
399,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
446,
1748,
63,
3397,
398,
399,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
275,
3473,
14,
1474,
8,
85,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
627,
13690,
63,
4778,
9,
267,
399,
59,
739,
63,
1080,
1527,
19,
61,
275,
399,
59,
739,
63,
1080,
1527,
17,
1527,
16,
61,
339,
367,
1586,
63,
1080,
315,
15699,
26,
267,
15699,
59,
739,
63,
1080,
1527,
19,
61,
275,
378,
14,
16,
398,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
4850,
59,
739,
63,
1080,
1527,
17,
18710,
288,
340,
1748,
63,
3397,
665,
378,
26,
355,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
275,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
446,
1748,
63,
3397,
953,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
275,
3473,
14,
1474,
8,
4850,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
627,
13690,
63,
4778,
9,
953,
340,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
690,
15699,
59,
739,
63,
1080,
1527,
19,
2189,
355,
15699,
59,
739,
63,
1080,
1527,
19,
61,
275,
15699,
59,
739,
63,
1080,
1527,
17,
1527,
73,
61,
339,
372,
399,
12,
15699,
421,
199,
318,
2342,
63,
21660,
63,
5743,
63,
3397,
8,
955,
304,
272,
408,
272,
6668,
314,
699,
583,
23958,
18,
13177,
5396,
367,
314,
1627,
3715,
1004,
15693,
955,
20008,
339,
8730,
397,
314,
428,
1156,
1504,
367,
314,
1124,
1179,
26,
73,
1040,
20597,
436,
5536,
83,
314,
699,
583,
23958,
18,
13,
6100,
13177,
5396,
14,
961,
911,
440,
272,
1736,
367,
1163,
6998,
1192,
14,
339,
520,
635,
1504,
26,
282,
1004,
626,
965,
2757,
3715,
641,
1867,
84,
2,
272,
520,
466,
1504,
26,
769,
339,
520,
1107,
26,
314,
13177,
5396,
272,
520,
4500,
26,
2069,
339,
408,
272,
1586,
63,
1267,
275,
2069,
8,
552,
8,
955,
59,
25,
2459,
339,
367,
901,
315,
1504,
26,
267,
340,
901,
14,
2460,
480,
1179,
26,
73,
26,
2349,
288,
282,
63,
3397,
275,
1109,
8,
698,
59,
21,
5728,
288,
372,
282,
63,
3397,
435,
1586,
63,
1267,
339,
746,
1722,
480,
6531,
440,
2342,
13177,
5396,
531,
421,
199,
318,
1900,
63,
3642,
8,
86,
502,
63,
515,
12,
299,
63,
3397,
63,
17708,
29,
16,
14,
614,
304,
272,
399,
275,
1211,
342,
272,
15699,
275,
1211,
342,
339,
394,
63,
739,
63,
344,
275,
1052,
272,
394,
63,
1121,
63,
344,
275,
1052,
339,
15749,
275,
942,
272,
11597,
275,
942,
339,
2984,
63,
835,
275,
378,
272,
1586,
63,
835,
275,
378,
339,
1390,
63,
3397,
275,
378,
272,
1748,
63,
3397,
275,
378,
339,
543,
1551,
8,
86,
502,
63,
515,
12,
298,
82,
531,
465,
2429,
26,
267,
367,
1004,
315,
2429,
26,
288,
1586,
63,
344,
12,
2984,
63,
344,
12,
5501,
5501,
299,
63,
3397,
275,
1004,
14,
6735,
1252,
1294,
20324,
953,
299,
63,
3397,
275,
2069,
8,
80,
63,
3397,
9,
953,
340,
299,
63,
3397,
665,
299,
63,
3397,
63,
17708,
26,
355,
1980,
953,
1748,
63,
3397,
275,
1748,
8,
827,
63,
3397,
12,
299,
63,
3397,
9,
288,
1390,
63,
3397,
275,
1390,
8,
988,
63,
3397,
12,
299,
63,
3397,
9,
953,
2984,
63,
1080,
275,
394,
63,
1121,
63,
344,
14,
362,
8,
1121,
63,
344,
12,
446,
17,
9,
953,
340,
2984,
63,
1080,
508,
446,
17,
26,
355,
2984,
63,
1080,
275,
2984,
63,
835,
355,
394,
63,
1121,
63,
344,
59,
1121,
63,
344,
61,
275,
2984,
63,
1080,
355,
15749,
14,
740,
8,
1121,
63,
344,
9,
355,
2984,
63,
835,
847,
413,
953,
1586,
63,
1080,
275,
394,
63,
739,
63,
344,
14,
362,
8,
739,
63,
344,
12,
446,
17,
9,
953,
340,
1586,
63,
1080,
508,
446,
17,
26,
355,
327,
10266,
641,
642,
892,
1586,
14,
1642,
12,
4816,
4136,
1586,
4690,
436,
1937,
340,
1263,
4136,
1586,
965,
282,
2011,
355,
327,
4690,
543,
626,
1,
355,
1586,
63,
1080,
275,
1586,
63,
835,
355,
394,
63,
739,
63,
344,
59,
739,
63,
344,
61,
275,
1586,
63,
1080,
355,
11597,
14,
740,
8,
739,
63,
344,
9,
355,
1586,
63,
835,
847,
413,
355,
399,
59,
739,
63,
1080,
61,
275,
3474,
1121,
63,
1080,
467,
359,
80,
63,
3397,
467,
359,
1609,
8,
80,
63,
3397,
4360,
299,
63,
3397,
61,
288,
587,
26,
355,
340,
1586,
63,
1080,
315,
399,
26,
490,
340,
2984,
63,
1080,
315,
399,
59,
739,
63,
1080,
1527,
16,
2189,
717,
1980,
490,
15699,
59,
739,
63,
1080,
61,
275,
399,
59,
739,
63,
1080,
61,
490,
2150,
399,
59,
739,
63,
1080,
61,
2234,
340,
2984,
63,
1080,
315,
15699,
59,
739,
63,
1080,
1527,
16,
2189,
490,
1980,
2234,
15699,
59,
739,
63,
1080,
1527,
16,
1055,
740,
8,
1121,
63,
1080,
9,
355,
15699,
59,
739,
63,
1080,
1527,
17,
1055,
740,
8,
80,
63,
3397,
9,
2234,
340,
299,
63,
3397,
690,
15699,
59,
739,
63,
1080,
1527,
19,
2189,
490,
15699,
59,
739,
63,
1080,
1527,
19,
61,
275,
299,
63,
3397,
339,
399,
12,
15699,
275,
522,
2357,
63,
21660,
3397,
8,
85,
12,
15699,
12,
1390,
63,
3397,
12,
1748,
63,
3397,
9,
339,
367,
1586,
63,
1080,
315,
399,
26,
267,
327,
4215,
2984,
63,
1080,
436,
5396,
1454,
267,
399,
59,
739,
63,
1080,
61,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
itpubs/reflecting
|
apps/users/views.py
|
1
|
7234
|
from django.shortcuts import render, HttpResponseRedirect, reverse, HttpResponse
from django.contrib.auth import authenticate, login, logout
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.hashers import make_password
from django.contrib.auth.backends import ModelBackend
from users.models import Message, EmailVerifyCode
from utils.email_send import send_password_email
from django.views.generic import View
from django.utils import timezone
from .models import UserProfile
from django.db.models import Q
from .forms import *
from utils.mixin_utils import LoginRequiredMixin
__all__ = [
'RegisterView',
'LoginView',
'LogoutView',
'PasswordView'
]
class CustomBackend(ModelBackend):
"""自定义auth验证,可以通过用户名邮箱登录"""
def authenticate(self, username=None, password=None, **kwargs):
try:
user = UserProfile.objects.get(Q(username=username) | Q(email=username)) # 通过用户名或邮箱获取用户是否存在
if user.check_password(password): # 如果用户密码正确返回user对象
return user
else: # 出错或者用户密码错误就返回None
return None
except Exception:
return None
# Create your views here.
class RegisterView(View):
def get(self, request):
return render(request, 'register.html')
def post(self, request):
register_form = RegisterForm(request.POST) # 验证传过来的参数
if register_form.is_valid():
email = request.POST.get('email', '') # 获取邮箱
try:
UserProfile.objects.get(email=email) # 如果邮箱已经存在
return render(request, 'register.html', {'errors': '邮箱:%s 已存在!' % email})
except ObjectDoesNotExist:
password = request.POST.get('password', '') # 获取密码
retype_password = request.POST.get('retype_password', '') # 确认密码
if password == retype_password:
UserProfile.objects.create(username=email, email=email, password=make_password(password))
Message.objects.create(body="用户%s于%s进行了注册" % (email, timezone.now()))
return HttpResponseRedirect(reverse('login')) # 跳转到登录页面
else:
errors = '两次密码不一致~'
return render(request, 'register.html', {'errors': errors})
else:
return render(request, 'register.html', {'errors': register_form.errors})
class LoginView(View):
def get(self, request):
return render(request, 'login.html')
def post(self, request):
"""验证用户是否是否可以成功登录"""
login_form = LoginForm(request.POST) # FORM验证传过来的值是否合法
if login_form.is_valid(): # 验证是否错误
email = request.POST.get('email', '') # 获取用户名
password = request.POST.get('password', '') # 获取密码
user = authenticate(username=email, password=password) # 验证用户名和密码
if user is not None: # 如果用户名和密码匹配
if user.is_active: # 如果用户是激活状态
login(request, user) # 把SESSION和COOKIE写入request
if user.is_superuser:
return HttpResponseRedirect(reverse('admin:dashboard')) # 返回首页
else:
return HttpResponseRedirect(reverse('index')) # 返回首页
else: # 用户未激活
return render(request, 'login.html', {'errors': '用户尚未激活!'})
else: # 用户名和密码错误
return render(request, 'login.html', {'errors': '用户名或密码错误!'})
else: # FORM验证出错,并吧出错信息传递到前端
return render(request, 'login.html', {'errors': login_form.errors})
class LogoutView(LoginRequiredMixin, View):
def get(self, request):
logout(request)
return HttpResponseRedirect(reverse('login'))
class PasswordView(View):
def get(self, request):
code = request.GET.get('code', '')
if code:
try:
EmailVerifyCode.objects.get(code=code)
return render(request, 'password.html', {'code': code, 'flag': True})
except EmailVerifyCode.DoesNotExist:
return HttpResponse('重置密码链接已失效~')
else:
return render(request, 'password.html')
def post(self, request):
email = request.POST.get('email', '')
try:
UserProfile.objects.get(email=email)
result = send_password_email(email=email)
if result:
return HttpResponse('重置密码的链接已发送至你的邮箱,请注意查收~')
return HttpResponse('用户不存在~')
except UserProfile.DoesNotExist:
return HttpResponse('用户不存在~')
class RestPasswordView(View):
def post(self, request):
code = request.POST.get('code') # Code
if code:
rest_form = RestPasswordForm(request.POST)
if rest_form.is_valid():
password = request.POST.get('password', '') # 获取密码
retype_password = request.POST.get('retype_password', '') # 确认密码
if password == retype_password:
emailverify = EmailVerifyCode.objects.get(code=code)
email = emailverify.email
user = UserProfile.objects.get(email=email)
user.password = make_password(password)
user.save()
emailverify.delete()
Message.objects.create(body="用户%s于%s修改了密码" % (email, timezone.now()))
return HttpResponseRedirect(reverse('login'))
else:
return HttpResponse('两次密码不一致~')
else:
return HttpResponse(rest_form.errors)
else:
admin_password_form = AdminRestPasswordForm(request.POST)
if admin_password_form.is_valid():
oldpassword = request.POST.get('oldpassword')
newpassword = request.POST.get('newpassword')
retypepassword = request.POST.get('retypepassword')
user = authenticate(username=request.user.email, password=oldpassword)
if newpassword == retypepassword and user:
user.password = make_password(newpassword)
user.save()
logout(request)
Message.objects.create(body="用户%s于%s通过后台修改了密码" % (request.user.email, timezone.now()))
return HttpResponseRedirect(reverse('login'))
else:
return HttpResponse('请确保两次密码相同且旧密码正确~')
else:
return HttpResponse(admin_password_form.errors)
|
mit
|
[
504,
1639,
14,
17469,
492,
3795,
12,
14935,
12,
3837,
12,
6183,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
12,
4676,
12,
22079,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
2828,
14,
1178,
14,
31342,
492,
1852,
63,
2060,
199,
504,
1639,
14,
2828,
14,
1178,
14,
7765,
492,
5822,
8447,
199,
504,
4390,
14,
992,
492,
6430,
12,
11426,
7496,
3034,
199,
504,
3778,
14,
2123,
63,
2254,
492,
3222,
63,
2060,
63,
2123,
199,
504,
1639,
14,
4196,
14,
6767,
492,
10935,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1275,
992,
492,
19037,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
504,
1275,
3351,
492,
627,
199,
504,
3778,
14,
20406,
63,
1208,
492,
16430,
8030,
4256,
199,
199,
363,
452,
363,
275,
359,
272,
283,
7099,
2768,
297,
272,
283,
8880,
2768,
297,
272,
283,
2445,
548,
2768,
297,
272,
283,
6139,
2768,
7,
199,
61,
421,
199,
533,
8388,
8447,
8,
1685,
8447,
304,
272,
408,
27345,
104,
20766,
17837,
232,
1178,
166,
104,
235,
20886,
12356,
25521,
23681,
14333,
249,
13201,
230,
22445,
21434,
166,
225,
107,
16716,
110,
23460,
8698,
122,
244,
624,
339,
347,
12895,
8,
277,
12,
3434,
29,
403,
12,
2505,
29,
403,
12,
1011,
958,
304,
267,
862,
26,
288,
922,
275,
19037,
14,
1462,
14,
362,
8,
49,
8,
2473,
29,
2473,
9,
1204,
1413,
8,
2123,
29,
2473,
430,
221,
327,
10469,
223,
249,
13201,
230,
22445,
21434,
9077,
245,
166,
225,
107,
16716,
110,
165,
237,
116,
22924,
22445,
9729,
8197,
100,
29846,
21448,
288,
340,
922,
14,
1074,
63,
2060,
8,
2060,
304,
221,
327,
7094,
100,
225,
19349,
251,
22445,
26505,
8967,
17627,
97,
164,
95,
107,
13201,
243,
22234,
751,
26604,
165,
110,
95,
355,
372,
922,
288,
587,
26,
221,
327,
7094,
230,
119,
28851,
9077,
245,
18497,
22445,
26505,
8967,
32064,
15348,
110,
13201,
243,
22234,
403,
355,
372,
488,
267,
871,
2186,
26,
288,
372,
488,
421,
199,
3,
2790,
2195,
6858,
2348,
14,
199,
199,
533,
11828,
2768,
8,
2768,
304,
272,
347,
664,
8,
277,
12,
1056,
304,
267,
372,
3795,
8,
1069,
12,
283,
2683,
14,
1360,
358,
339,
347,
2963,
8,
277,
12,
1056,
304,
267,
2274,
63,
964,
275,
11828,
2821,
8,
1069,
14,
4030,
9,
221,
327,
10469,
104,
235,
20886,
17848,
255,
13201,
230,
15771,
99,
8106,
32549,
12211,
267,
340,
2274,
63,
964,
14,
374,
63,
1078,
837,
288,
3031,
275,
1056,
14,
4030,
14,
362,
360,
2123,
297,
4074,
221,
327,
9065,
237,
116,
22924,
166,
225,
107,
16716,
110,
288,
862,
26,
355,
19037,
14,
1462,
14,
362,
8,
2123,
29,
2123,
9,
221,
327,
7094,
100,
225,
19349,
251,
166,
225,
107,
16716,
110,
28913,
20134,
29846,
21448,
355,
372,
3795,
8,
1069,
12,
283,
2683,
14,
1360,
297,
791,
2550,
356,
283,
166,
225,
107,
16716,
110,
25742,
5,
83,
7094,
116,
111,
29846,
21448,
8454,
224,
7,
450,
3031,
1552,
288,
871,
24803,
26,
355,
2505,
275,
1056,
14,
4030,
14,
362,
360,
2060,
297,
4074,
221,
327,
9065,
237,
116,
22924,
26505,
8967,
355,
295,
466,
63,
2060,
275,
1056,
14,
4030,
14,
362,
360,
264,
466,
63,
2060,
297,
4074,
221,
327,
9112,
95,
107,
14082,
98,
26505,
8967,
355,
340,
2505,
508,
295,
466,
63,
2060,
26,
490,
19037,
14,
1462,
14,
981,
8,
2473,
29,
2123,
12,
3031,
29,
2123,
12,
2505,
29,
1875,
63,
2060,
8,
2060,
430,
490,
6430,
14,
1462,
14,
981,
8,
2030,
628,
22445,
5,
83,
6923,
237,
5,
83,
13201,
250,
12609,
30998,
20021,
102,
17950,
235,
2,
450,
334,
2123,
12,
7137,
14,
2131,
4059,
490,
372,
14935,
8,
4471,
360,
2886,
1333,
221,
327,
9065,
116,
112,
30229,
29507,
23460,
8698,
122,
244,
27513,
114,
26398,
96,
355,
587,
26,
490,
2552,
275,
283,
4344,
98,
30493,
26505,
8967,
19594,
9372,
27345,
113,
94,
7,
490,
372,
3795,
8,
1069,
12,
283,
2683,
14,
1360,
297,
791,
2550,
356,
2552,
1552,
267,
587,
26,
288,
372,
3795,
8,
1069,
12,
283,
2683,
14,
1360,
297,
791,
2550,
356,
2274,
63,
964,
14,
2550,
1552,
421,
199,
533,
16430,
2768,
8,
2768,
304,
272,
347,
664,
8,
277,
12,
1056,
304,
267,
372,
3795,
8,
1069,
12,
283,
2886,
14,
1360,
358,
339,
347,
2963,
8,
277,
12,
1056,
304,
267,
408,
166,
104,
235,
20886,
22445,
9729,
8197,
100,
9729,
8197,
100,
25521,
23681,
16888,
12163,
254,
23460,
8698,
122,
244,
624,
267,
4676,
63,
964,
275,
16430,
2821,
8,
1069,
14,
4030,
9,
221,
327,
11295,
166,
104,
235,
20886,
17848,
255,
13201,
230,
15771,
99,
8106,
32678,
9729,
8197,
100,
16803,
27397,
267,
340,
4676,
63,
964,
14,
374,
63,
1078,
837,
221,
327,
10469,
104,
235,
20886,
9729,
8197,
100,
32064,
288,
3031,
275,
1056,
14,
4030,
14,
362,
360,
2123,
297,
4074,
221,
327,
9065,
237,
116,
22924,
22445,
21434,
288,
2505,
275,
1056,
14,
4030,
14,
362,
360,
2060,
297,
4074,
221,
327,
9065,
237,
116,
22924,
26505,
8967,
288,
922,
275,
12895,
8,
2473,
29,
2123,
12,
2505,
29,
2060,
9,
221,
327,
10469,
104,
235,
20886,
22445,
21434,
30557,
26505,
8967,
288,
340,
922,
365,
440,
488,
26,
221,
327,
7094,
100,
225,
19349,
251,
22445,
21434,
30557,
26505,
8967,
21018,
118,
166,
228,
236,
355,
340,
922,
14,
374,
63,
2682,
26,
221,
327,
7094,
100,
225,
19349,
251,
22445,
9729,
163,
124,
223,
163,
113,
120,
30729,
490,
4676,
8,
1069,
12,
922,
9,
221,
327,
8853,
233,
233,
12763,
30557,
13665,
17950,
248,
18236,
1069,
490,
340,
922,
14,
374,
63,
11434,
26,
717,
372,
14935,
8,
4471,
360,
2113,
26,
9743,
1333,
221,
327,
9065,
124,
243,
22234,
166,
100,
245,
27513,
114,
490,
587,
26,
717,
372,
14935,
8,
4471,
360,
1080,
1333,
221,
327,
9065,
124,
243,
22234,
166,
100,
245,
27513,
114,
355,
587,
26,
221,
327,
221,
22445,
6587,
104,
163,
124,
223,
163,
113,
120,
490,
372,
3795,
8,
1069,
12,
283,
2886,
14,
1360,
297,
791,
2550,
356,
283,
22445,
15348
] |
[
1639,
14,
17469,
492,
3795,
12,
14935,
12,
3837,
12,
6183,
199,
504,
1639,
14,
2828,
14,
1178,
492,
12895,
12,
4676,
12,
22079,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
2828,
14,
1178,
14,
31342,
492,
1852,
63,
2060,
199,
504,
1639,
14,
2828,
14,
1178,
14,
7765,
492,
5822,
8447,
199,
504,
4390,
14,
992,
492,
6430,
12,
11426,
7496,
3034,
199,
504,
3778,
14,
2123,
63,
2254,
492,
3222,
63,
2060,
63,
2123,
199,
504,
1639,
14,
4196,
14,
6767,
492,
10935,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1275,
992,
492,
19037,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
199,
504,
1275,
3351,
492,
627,
199,
504,
3778,
14,
20406,
63,
1208,
492,
16430,
8030,
4256,
199,
199,
363,
452,
363,
275,
359,
272,
283,
7099,
2768,
297,
272,
283,
8880,
2768,
297,
272,
283,
2445,
548,
2768,
297,
272,
283,
6139,
2768,
7,
199,
61,
421,
199,
533,
8388,
8447,
8,
1685,
8447,
304,
272,
408,
27345,
104,
20766,
17837,
232,
1178,
166,
104,
235,
20886,
12356,
25521,
23681,
14333,
249,
13201,
230,
22445,
21434,
166,
225,
107,
16716,
110,
23460,
8698,
122,
244,
624,
339,
347,
12895,
8,
277,
12,
3434,
29,
403,
12,
2505,
29,
403,
12,
1011,
958,
304,
267,
862,
26,
288,
922,
275,
19037,
14,
1462,
14,
362,
8,
49,
8,
2473,
29,
2473,
9,
1204,
1413,
8,
2123,
29,
2473,
430,
221,
327,
10469,
223,
249,
13201,
230,
22445,
21434,
9077,
245,
166,
225,
107,
16716,
110,
165,
237,
116,
22924,
22445,
9729,
8197,
100,
29846,
21448,
288,
340,
922,
14,
1074,
63,
2060,
8,
2060,
304,
221,
327,
7094,
100,
225,
19349,
251,
22445,
26505,
8967,
17627,
97,
164,
95,
107,
13201,
243,
22234,
751,
26604,
165,
110,
95,
355,
372,
922,
288,
587,
26,
221,
327,
7094,
230,
119,
28851,
9077,
245,
18497,
22445,
26505,
8967,
32064,
15348,
110,
13201,
243,
22234,
403,
355,
372,
488,
267,
871,
2186,
26,
288,
372,
488,
421,
199,
3,
2790,
2195,
6858,
2348,
14,
199,
199,
533,
11828,
2768,
8,
2768,
304,
272,
347,
664,
8,
277,
12,
1056,
304,
267,
372,
3795,
8,
1069,
12,
283,
2683,
14,
1360,
358,
339,
347,
2963,
8,
277,
12,
1056,
304,
267,
2274,
63,
964,
275,
11828,
2821,
8,
1069,
14,
4030,
9,
221,
327,
10469,
104,
235,
20886,
17848,
255,
13201,
230,
15771,
99,
8106,
32549,
12211,
267,
340,
2274,
63,
964,
14,
374,
63,
1078,
837,
288,
3031,
275,
1056,
14,
4030,
14,
362,
360,
2123,
297,
4074,
221,
327,
9065,
237,
116,
22924,
166,
225,
107,
16716,
110,
288,
862,
26,
355,
19037,
14,
1462,
14,
362,
8,
2123,
29,
2123,
9,
221,
327,
7094,
100,
225,
19349,
251,
166,
225,
107,
16716,
110,
28913,
20134,
29846,
21448,
355,
372,
3795,
8,
1069,
12,
283,
2683,
14,
1360,
297,
791,
2550,
356,
283,
166,
225,
107,
16716,
110,
25742,
5,
83,
7094,
116,
111,
29846,
21448,
8454,
224,
7,
450,
3031,
1552,
288,
871,
24803,
26,
355,
2505,
275,
1056,
14,
4030,
14,
362,
360,
2060,
297,
4074,
221,
327,
9065,
237,
116,
22924,
26505,
8967,
355,
295,
466,
63,
2060,
275,
1056,
14,
4030,
14,
362,
360,
264,
466,
63,
2060,
297,
4074,
221,
327,
9112,
95,
107,
14082,
98,
26505,
8967,
355,
340,
2505,
508,
295,
466,
63,
2060,
26,
490,
19037,
14,
1462,
14,
981,
8,
2473,
29,
2123,
12,
3031,
29,
2123,
12,
2505,
29,
1875,
63,
2060,
8,
2060,
430,
490,
6430,
14,
1462,
14,
981,
8,
2030,
628,
22445,
5,
83,
6923,
237,
5,
83,
13201,
250,
12609,
30998,
20021,
102,
17950,
235,
2,
450,
334,
2123,
12,
7137,
14,
2131,
4059,
490,
372,
14935,
8,
4471,
360,
2886,
1333,
221,
327,
9065,
116,
112,
30229,
29507,
23460,
8698,
122,
244,
27513,
114,
26398,
96,
355,
587,
26,
490,
2552,
275,
283,
4344,
98,
30493,
26505,
8967,
19594,
9372,
27345,
113,
94,
7,
490,
372,
3795,
8,
1069,
12,
283,
2683,
14,
1360,
297,
791,
2550,
356,
2552,
1552,
267,
587,
26,
288,
372,
3795,
8,
1069,
12,
283,
2683,
14,
1360,
297,
791,
2550,
356,
2274,
63,
964,
14,
2550,
1552,
421,
199,
533,
16430,
2768,
8,
2768,
304,
272,
347,
664,
8,
277,
12,
1056,
304,
267,
372,
3795,
8,
1069,
12,
283,
2886,
14,
1360,
358,
339,
347,
2963,
8,
277,
12,
1056,
304,
267,
408,
166,
104,
235,
20886,
22445,
9729,
8197,
100,
9729,
8197,
100,
25521,
23681,
16888,
12163,
254,
23460,
8698,
122,
244,
624,
267,
4676,
63,
964,
275,
16430,
2821,
8,
1069,
14,
4030,
9,
221,
327,
11295,
166,
104,
235,
20886,
17848,
255,
13201,
230,
15771,
99,
8106,
32678,
9729,
8197,
100,
16803,
27397,
267,
340,
4676,
63,
964,
14,
374,
63,
1078,
837,
221,
327,
10469,
104,
235,
20886,
9729,
8197,
100,
32064,
288,
3031,
275,
1056,
14,
4030,
14,
362,
360,
2123,
297,
4074,
221,
327,
9065,
237,
116,
22924,
22445,
21434,
288,
2505,
275,
1056,
14,
4030,
14,
362,
360,
2060,
297,
4074,
221,
327,
9065,
237,
116,
22924,
26505,
8967,
288,
922,
275,
12895,
8,
2473,
29,
2123,
12,
2505,
29,
2060,
9,
221,
327,
10469,
104,
235,
20886,
22445,
21434,
30557,
26505,
8967,
288,
340,
922,
365,
440,
488,
26,
221,
327,
7094,
100,
225,
19349,
251,
22445,
21434,
30557,
26505,
8967,
21018,
118,
166,
228,
236,
355,
340,
922,
14,
374,
63,
2682,
26,
221,
327,
7094,
100,
225,
19349,
251,
22445,
9729,
163,
124,
223,
163,
113,
120,
30729,
490,
4676,
8,
1069,
12,
922,
9,
221,
327,
8853,
233,
233,
12763,
30557,
13665,
17950,
248,
18236,
1069,
490,
340,
922,
14,
374,
63,
11434,
26,
717,
372,
14935,
8,
4471,
360,
2113,
26,
9743,
1333,
221,
327,
9065,
124,
243,
22234,
166,
100,
245,
27513,
114,
490,
587,
26,
717,
372,
14935,
8,
4471,
360,
1080,
1333,
221,
327,
9065,
124,
243,
22234,
166,
100,
245,
27513,
114,
355,
587,
26,
221,
327,
221,
22445,
6587,
104,
163,
124,
223,
163,
113,
120,
490,
372,
3795,
8,
1069,
12,
283,
2886,
14,
1360,
297,
791,
2550,
356,
283,
22445,
15348,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ably-forks/node-gyp
|
gyp/test/variables/filelist/gyptest-filelist.py
|
102
|
1583
|
#!/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.
"""
Test variable expansion of '<|(list.txt ...)' syntax commands.
"""
import os
import sys
import TestGyp
test = TestGyp.TestGyp(format='gypd')
expect = test.read('filelist.gyp.stdout')
if sys.platform == 'win32':
expect = expect.replace('/', r'\\').replace('\r\n', '\n')
test.run_gyp('src/filelist.gyp',
'--debug', 'variables',
stdout=expect, ignore_line_numbers=True)
# Verify the filelist.gypd against the checked-in expected contents.
#
# Normally, we should canonicalize line endings in the expected
# contents file setting the Subversion svn:eol-style to native,
# but that would still fail if multiple systems are sharing a single
# workspace on a network-mounted file system. Consequently, we
# massage the Windows line endings ('\r\n') in the output to the
# checked-in UNIX endings ('\n').
contents = test.read('src/filelist.gypd').replace(
'\r', '').replace('\\\\', '/')
expect = test.read('filelist.gypd.golden').replace('\r', '')
if not test.match(contents, expect):
print "Unexpected contents of `src/filelist.gypd'"
test.diff(expect, contents, 'src/filelist.gypd ')
test.fail_test()
contents = test.read('src/names.txt')
expect = 'John\nJacob\nJingleheimer\nSchmidt\n'
if not test.match(contents, expect):
print "Unexpected contents of `src/names.txt'"
test.diff(expect, contents, 'src/names.txt ')
test.fail_test()
test.pass_test()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
774,
1750,
14819,
402,
2650,
92,
8,
513,
14,
2424,
2263,
3171,
6302,
3718,
14,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
199,
646,
25688,
199,
199,
396,
275,
25688,
14,
774,
13899,
8,
908,
534,
6179,
68,
358,
199,
199,
4921,
275,
511,
14,
739,
360,
14964,
14,
6179,
14,
2703,
358,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
523,
4282,
275,
4282,
14,
1814,
10998,
519,
8124,
1959,
1814,
2258,
82,
60,
78,
297,
1557,
78,
358,
199,
199,
396,
14,
1065,
63,
6179,
360,
2164,
15,
14964,
14,
6179,
297,
1467,
2850,
1757,
297,
283,
3669,
297,
1467,
3839,
29,
4921,
12,
3686,
63,
604,
63,
10548,
29,
549,
9,
199,
199,
3,
7635,
314,
26148,
14,
6179,
68,
6169,
314,
7923,
13,
262,
1420,
4072,
14,
199,
3,
199,
3,
24573,
12,
781,
1077,
11358,
794,
1004,
1284,
780,
315,
314,
1420,
199,
3,
4072,
570,
4260,
314,
31098,
11327,
26,
20470,
13,
2487,
370,
5438,
12,
199,
3,
1325,
626,
3955,
5139,
2449,
340,
3663,
10460,
787,
26994,
282,
2849,
199,
3,
14466,
641,
282,
2784,
13,
27919,
570,
2656,
14,
221,
1448,
11277,
590,
12,
781,
199,
3,
12250,
474,
314,
5417,
1004,
1284,
780,
17485,
82,
60,
78,
358,
315,
314,
1072,
370,
314,
199,
3,
7923,
13,
262,
22242,
1284,
780,
17485,
78,
1959,
199,
199,
4407,
275,
511,
14,
739,
360,
2164,
15,
14964,
14,
6179,
68,
1959,
1814,
8,
272,
1557,
82,
297,
12548,
1814,
360,
8712,
297,
15107,
199,
4921,
275,
511,
14,
739,
360,
14964,
14,
6179,
68,
14,
19440,
1959,
1814,
2258,
82,
297,
4074,
199,
692,
440,
511,
14,
1431,
8,
4407,
12,
4282,
304,
523,
870,
298,
8708,
4072,
402,
658,
2164,
15,
14964,
14,
6179,
68,
4065,
523,
511,
14,
3028,
8,
4921,
12,
4072,
12,
283,
2164,
15,
14964,
14,
6179,
68,
5320,
523,
511,
14,
1633,
63,
396,
342,
199,
199,
4407,
275,
511,
14,
739,
360,
2164,
15,
1247,
14,
2424,
358,
199,
4921,
275,
283,
12923,
60,
78,
42,
13286,
66,
60,
78,
42,
2361,
426,
6267,
60,
78,
31936,
8523,
84,
60,
78,
7,
199,
692,
440,
511,
14,
1431,
8,
4407,
12,
4282,
304,
523,
870,
298,
8708,
4072,
402,
658,
2164,
15,
1247,
14,
2424,
4065,
523,
511,
14,
3028,
8,
4921,
12,
4072,
12,
283,
2164,
15,
1247,
14,
2424,
5320,
523,
511,
14,
1633,
63,
396,
342,
199,
199,
396,
14,
1529,
63,
396,
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
] |
[
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,
199,
774,
1750,
14819,
402,
2650,
92,
8,
513,
14,
2424,
2263,
3171,
6302,
3718,
14,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
199,
646,
25688,
199,
199,
396,
275,
25688,
14,
774,
13899,
8,
908,
534,
6179,
68,
358,
199,
199,
4921,
275,
511,
14,
739,
360,
14964,
14,
6179,
14,
2703,
358,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
523,
4282,
275,
4282,
14,
1814,
10998,
519,
8124,
1959,
1814,
2258,
82,
60,
78,
297,
1557,
78,
358,
199,
199,
396,
14,
1065,
63,
6179,
360,
2164,
15,
14964,
14,
6179,
297,
1467,
2850,
1757,
297,
283,
3669,
297,
1467,
3839,
29,
4921,
12,
3686,
63,
604,
63,
10548,
29,
549,
9,
199,
199,
3,
7635,
314,
26148,
14,
6179,
68,
6169,
314,
7923,
13,
262,
1420,
4072,
14,
199,
3,
199,
3,
24573,
12,
781,
1077,
11358,
794,
1004,
1284,
780,
315,
314,
1420,
199,
3,
4072,
570,
4260,
314,
31098,
11327,
26,
20470,
13,
2487,
370,
5438,
12,
199,
3,
1325,
626,
3955,
5139,
2449,
340,
3663,
10460,
787,
26994,
282,
2849,
199,
3,
14466,
641,
282,
2784,
13,
27919,
570,
2656,
14,
221,
1448,
11277,
590,
12,
781,
199,
3,
12250,
474,
314,
5417,
1004,
1284,
780,
17485,
82,
60,
78,
358,
315,
314,
1072,
370,
314,
199,
3,
7923,
13,
262,
22242,
1284,
780,
17485,
78,
1959,
199,
199,
4407,
275,
511,
14,
739,
360,
2164,
15,
14964,
14,
6179,
68,
1959,
1814,
8,
272,
1557,
82,
297,
12548,
1814,
360,
8712,
297,
15107,
199,
4921,
275,
511,
14,
739,
360,
14964,
14,
6179,
68,
14,
19440,
1959,
1814,
2258,
82,
297,
4074,
199,
692,
440,
511,
14,
1431,
8,
4407,
12,
4282,
304,
523,
870,
298,
8708,
4072,
402,
658,
2164,
15,
14964,
14,
6179,
68,
4065,
523,
511,
14,
3028,
8,
4921,
12,
4072,
12,
283,
2164,
15,
14964,
14,
6179,
68,
5320,
523,
511,
14,
1633,
63,
396,
342,
199,
199,
4407,
275,
511,
14,
739,
360,
2164,
15,
1247,
14,
2424,
358,
199,
4921,
275,
283,
12923,
60,
78,
42,
13286,
66,
60,
78,
42,
2361,
426,
6267,
60,
78,
31936,
8523,
84,
60,
78,
7,
199,
692,
440,
511,
14,
1431,
8,
4407,
12,
4282,
304,
523,
870,
298,
8708,
4072,
402,
658,
2164,
15,
1247,
14,
2424,
4065,
523,
511,
14,
3028,
8,
4921,
12,
4072,
12,
283,
2164,
15,
1247,
14,
2424,
5320,
523,
511,
14,
1633,
63,
396,
342,
199,
199,
396,
14,
1529,
63,
396,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ahmed-mahran/hue
|
desktop/core/ext-py/lxml/src/lxml/tests/test_dtd.py
|
30
|
4579
|
# -*- coding: utf-8 -*-
"""
Test cases related to DTD parsing and validation
"""
import unittest, sys, os.path
this_dir = os.path.dirname(__file__)
if this_dir not in sys.path:
sys.path.insert(0, this_dir) # needed for Py3
from common_imports import etree, StringIO, BytesIO, _bytes, doctest
from common_imports import HelperTestCase, fileInTestDir, make_doctest
class ETreeDtdTestCase(HelperTestCase):
def test_dtd(self):
pass
def test_dtd_file(self):
parse = etree.parse
tree = parse(fileInTestDir("test.xml"))
root = tree.getroot()
dtd = etree.DTD(fileInTestDir("test.dtd"))
self.assert_(dtd.validate(root))
def test_dtd_stringio(self):
root = etree.XML(_bytes("<b/>"))
dtd = etree.DTD(BytesIO("<!ELEMENT b EMPTY>"))
self.assert_(dtd.validate(root))
def test_dtd_parse_invalid(self):
fromstring = etree.fromstring
parser = etree.XMLParser(dtd_validation=True)
xml = _bytes('<!DOCTYPE b SYSTEM "%s"><b><a/></b>' % fileInTestDir("test.dtd"))
self.assertRaises(etree.XMLSyntaxError,
fromstring, xml, parser=parser)
def test_dtd_parse_file_not_found(self):
fromstring = etree.fromstring
dtd_filename = fileInTestDir("__nosuch.dtd")
parser = etree.XMLParser(dtd_validation=True)
xml = _bytes('<!DOCTYPE b SYSTEM "%s"><b><a/></b>' % dtd_filename)
self.assertRaises(etree.XMLSyntaxError,
fromstring, xml, parser=parser)
errors = None
try:
fromstring(xml, parser=parser)
except etree.XMLSyntaxError:
e = sys.exc_info()[1]
errors = [ entry.message for entry in e.error_log
if dtd_filename in entry.message ]
self.assert_(errors)
def test_dtd_parse_valid(self):
parser = etree.XMLParser(dtd_validation=True)
xml = '<!DOCTYPE a SYSTEM "%s"><a><b/></a>' % fileInTestDir("test.dtd")
root = etree.fromstring(xml, parser=parser)
def test_dtd_parse_valid_relative(self):
parser = etree.XMLParser(dtd_validation=True)
xml = '<!DOCTYPE a SYSTEM "test.dtd"><a><b/></a>'
root = etree.fromstring(xml, parser=parser,
base_url=fileInTestDir("test.xml"))
def test_dtd_invalid(self):
root = etree.XML("<b><a/></b>")
dtd = etree.DTD(BytesIO("<!ELEMENT b EMPTY>"))
self.assertRaises(etree.DocumentInvalid, dtd.assertValid, root)
def test_dtd_assertValid(self):
root = etree.XML("<b><a/></b>")
dtd = etree.DTD(BytesIO("<!ELEMENT b (a)><!ELEMENT a EMPTY>"))
dtd.assertValid(root)
def test_dtd_internal(self):
root = etree.XML(_bytes('''
<!DOCTYPE b SYSTEM "none" [
<!ELEMENT b (a)>
<!ELEMENT a EMPTY>
]>
<b><a/></b>
'''))
dtd = etree.ElementTree(root).docinfo.internalDTD
self.assert_(dtd)
dtd.assertValid(root)
def test_dtd_internal_invalid(self):
root = etree.XML(_bytes('''
<!DOCTYPE b SYSTEM "none" [
<!ELEMENT b (a)>
<!ELEMENT a (c)>
<!ELEMENT c EMPTY>
]>
<b><a/></b>
'''))
dtd = etree.ElementTree(root).docinfo.internalDTD
self.assert_(dtd)
self.assertFalse(dtd.validate(root))
def test_dtd_broken(self):
self.assertRaises(etree.DTDParseError, etree.DTD,
BytesIO("<!ELEMENT b HONKEY>"))
def test_parse_file_dtd(self):
parser = etree.XMLParser(attribute_defaults=True)
tree = etree.parse(fileInTestDir('test.xml'), parser)
root = tree.getroot()
self.assertEquals(
"valueA",
root.get("default"))
self.assertEquals(
"valueB",
root[0].get("default"))
def test_iterparse_file_dtd(self):
iterparse = etree.iterparse
iterator = iterparse(fileInTestDir("test.xml"), events=("start",),
attribute_defaults=True)
attributes = [ element.get("default")
for event, element in iterator ]
self.assertEquals(
["valueA", "valueB"],
attributes)
def test_suite():
suite = unittest.TestSuite()
suite.addTests([unittest.makeSuite(ETreeDtdTestCase)])
suite.addTests(
[make_doctest('../../../doc/validation.txt')])
return suite
if __name__ == '__main__':
print('to test use test.py %s' % __file__)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
774,
5560,
4048,
370,
577,
13449,
6057,
436,
6411,
199,
624,
199,
199,
646,
2882,
12,
984,
12,
747,
14,
515,
199,
199,
3749,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
692,
642,
63,
694,
440,
315,
984,
14,
515,
26,
272,
984,
14,
515,
14,
3176,
8,
16,
12,
642,
63,
694,
9,
327,
4346,
367,
1611,
19,
199,
199,
504,
2863,
63,
12775,
492,
7559,
12,
5228,
12,
11808,
12,
485,
2394,
12,
8868,
199,
504,
2863,
63,
12775,
492,
11642,
1746,
12,
570,
607,
774,
3567,
12,
1852,
63,
11390,
199,
199,
533,
662,
3987,
36,
2076,
1746,
8,
4433,
1746,
304,
272,
347,
511,
63,
15662,
8,
277,
304,
267,
986,
339,
347,
511,
63,
15662,
63,
493,
8,
277,
304,
267,
2198,
275,
7559,
14,
1122,
267,
3123,
275,
2198,
8,
493,
607,
774,
3567,
480,
396,
14,
1652,
2237,
267,
1738,
275,
3123,
14,
24544,
342,
398,
366,
2076,
275,
7559,
14,
21156,
8,
493,
607,
774,
3567,
480,
396,
14,
15662,
2237,
267,
291,
14,
479,
2531,
15662,
14,
3502,
8,
1231,
430,
339,
347,
511,
63,
15662,
63,
875,
2308,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
1547,
2394,
6757,
66,
3133,
2237,
267,
366,
2076,
275,
7559,
14,
21156,
8,
15466,
6757,
1,
12535,
330,
16589,
30,
2237,
267,
291,
14,
479,
2531,
15662,
14,
3502,
8,
1231,
430,
339,
347,
511,
63,
15662,
63,
1122,
63,
3197,
8,
277,
304,
267,
687,
875,
275,
7559,
14,
13521,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
15662,
63,
6136,
29,
549,
9,
267,
2748,
275,
485,
2394,
4827,
1,
16556,
330,
20859,
2071,
83,
8186,
66,
2535,
65,
15,
2957,
66,
3524,
450,
570,
607,
774,
3567,
480,
396,
14,
15662,
2237,
267,
291,
14,
1855,
8,
9464,
14,
4317,
9294,
12,
2079,
687,
875,
12,
2748,
12,
1798,
29,
2087,
9,
339,
347,
511,
63,
15662,
63,
1122,
63,
493,
63,
1397,
63,
4214,
8,
277,
304,
267,
687,
875,
275,
7559,
14,
13521,
267,
366,
2076,
63,
1501,
275,
570,
607,
774,
3567,
16232,
12712,
2133,
14,
15662,
531,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
15662,
63,
6136,
29,
549,
9,
267,
2748,
275,
485,
2394,
4827,
1,
16556,
330,
20859,
2071,
83,
8186,
66,
2535,
65,
15,
2957,
66,
3524,
450,
366,
2076,
63,
1501,
9,
267,
291,
14,
1855,
8,
9464,
14,
4317,
9294,
12,
2079,
687,
875,
12,
2748,
12,
1798,
29,
2087,
9,
267,
2552,
275,
488,
267,
862,
26,
288,
687,
875,
8,
1652,
12,
1798,
29,
2087,
9,
267,
871,
7559,
14,
4317,
9294,
26,
288,
325,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
2552,
275,
359,
2397,
14,
1188,
367,
2397,
315,
325,
14,
705,
63,
793,
2432,
340,
366,
2076,
63,
1501,
315,
2397,
14,
1188,
1622,
267,
291,
14,
479,
2531,
2550,
9,
339,
347,
511,
63,
15662,
63,
1122,
63,
1078,
8,
277,
304,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
15662,
63,
6136,
29,
549,
9,
267,
2748,
275,
2650,
1,
16556,
282,
20859,
2071,
83,
8186,
65,
2535,
66,
15,
2957,
65,
3524,
450,
570,
607,
774,
3567,
480,
396,
14,
15662,
531,
267,
1738,
275,
7559,
14,
13521,
8,
1652,
12,
1798,
29,
2087,
9,
339,
347,
511,
63,
15662,
63,
1122,
63,
1078,
63,
6188,
8,
277,
304,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
15662,
63,
6136,
29,
549,
9,
267,
2748,
275,
2650,
1,
16556,
282,
20859,
298,
396,
14,
15662,
8186,
65,
2535,
66,
15,
2957,
65,
3524,
267,
1738,
275,
7559,
14,
13521,
8,
1652,
12,
1798,
29,
2087,
12,
1816,
1300,
63,
633,
29,
493,
607,
774,
3567,
480,
396,
14,
1652,
2237,
339,
347,
511,
63,
15662,
63,
3197,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
6757,
66,
2535,
65,
15,
2957,
66,
9579,
267,
366,
2076,
275,
7559,
14,
21156,
8,
15466,
6757,
1,
12535,
330,
16589,
30,
2237,
267,
291,
14,
1855,
8,
9464,
14,
5564,
3364,
12,
366,
2076,
14,
479,
3490,
12,
1738,
9,
339,
347,
511,
63,
15662,
63,
479,
3490,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
6757,
66,
2535,
65,
15,
2957,
66,
9579,
267,
366,
2076,
275,
7559,
14,
21156,
8,
15466,
6757,
1,
12535,
330,
334,
65,
9,
2535,
1,
12535,
282,
16589,
30,
2237,
267,
366,
2076,
14,
479,
3490,
8,
1231,
9,
339,
347,
511,
63,
15662,
63,
4672,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
1547,
2394,
10505,
267,
31513,
16556,
330,
20859,
298,
3592,
2,
359,
267,
31513,
12535,
330,
334,
65,
13032,
267,
31513,
12535,
282,
16589,
30,
267,
1622,
30,
267,
665,
66,
2535,
65,
15,
2957,
66,
30,
267,
2125,
1333,
267,
366,
2076,
275,
7559,
14,
15325,
8,
1231,
680,
32139,
14,
4672,
21156,
267,
291,
14,
479,
2531,
15662,
9,
267,
366,
2076,
14,
479,
3490,
8,
1231,
9,
339,
347,
511,
63,
15662,
63,
4672,
63,
3197,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
1547,
2394,
10505,
267,
31513,
16556,
330,
20859,
298,
3592,
2,
359,
267,
31513,
12535,
330,
334,
65,
13032,
267,
31513,
12535,
282,
334,
67,
13032,
267,
31513,
12535,
286,
16589,
30,
267,
1622,
30,
267,
665,
66,
2535,
65,
15,
2957,
66,
30,
267,
2125,
1333,
267,
366,
2076,
275,
7559,
14,
15325,
8,
1231,
680,
32139,
14,
4672,
21156,
267,
291,
14,
479,
2531,
15662,
9,
267,
291,
14,
3334,
8,
15662,
14,
3502,
8,
1231,
430,
339,
347,
511,
63,
15662,
63,
15697,
8,
277,
304,
267,
291,
14,
1855,
8,
9464,
14,
21156,
9123,
12,
7559,
14,
21156,
12,
2079,
11808,
6757,
1,
12535,
330,
869,
615,
3078,
30,
2237,
339,
347,
511,
63,
1122,
63,
493,
63,
15662,
8,
277,
304,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
3215,
63,
4322,
29,
549,
9,
398,
3123,
275,
7559,
14,
1122,
8,
493,
607,
774,
3567,
360,
396,
14,
1652,
659,
1798,
9,
267,
1738,
275,
3123,
14,
24544,
342,
398
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
774,
5560,
4048,
370,
577,
13449,
6057,
436,
6411,
199,
624,
199,
199,
646,
2882,
12,
984,
12,
747,
14,
515,
199,
199,
3749,
63,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
692,
642,
63,
694,
440,
315,
984,
14,
515,
26,
272,
984,
14,
515,
14,
3176,
8,
16,
12,
642,
63,
694,
9,
327,
4346,
367,
1611,
19,
199,
199,
504,
2863,
63,
12775,
492,
7559,
12,
5228,
12,
11808,
12,
485,
2394,
12,
8868,
199,
504,
2863,
63,
12775,
492,
11642,
1746,
12,
570,
607,
774,
3567,
12,
1852,
63,
11390,
199,
199,
533,
662,
3987,
36,
2076,
1746,
8,
4433,
1746,
304,
272,
347,
511,
63,
15662,
8,
277,
304,
267,
986,
339,
347,
511,
63,
15662,
63,
493,
8,
277,
304,
267,
2198,
275,
7559,
14,
1122,
267,
3123,
275,
2198,
8,
493,
607,
774,
3567,
480,
396,
14,
1652,
2237,
267,
1738,
275,
3123,
14,
24544,
342,
398,
366,
2076,
275,
7559,
14,
21156,
8,
493,
607,
774,
3567,
480,
396,
14,
15662,
2237,
267,
291,
14,
479,
2531,
15662,
14,
3502,
8,
1231,
430,
339,
347,
511,
63,
15662,
63,
875,
2308,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
1547,
2394,
6757,
66,
3133,
2237,
267,
366,
2076,
275,
7559,
14,
21156,
8,
15466,
6757,
1,
12535,
330,
16589,
30,
2237,
267,
291,
14,
479,
2531,
15662,
14,
3502,
8,
1231,
430,
339,
347,
511,
63,
15662,
63,
1122,
63,
3197,
8,
277,
304,
267,
687,
875,
275,
7559,
14,
13521,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
15662,
63,
6136,
29,
549,
9,
267,
2748,
275,
485,
2394,
4827,
1,
16556,
330,
20859,
2071,
83,
8186,
66,
2535,
65,
15,
2957,
66,
3524,
450,
570,
607,
774,
3567,
480,
396,
14,
15662,
2237,
267,
291,
14,
1855,
8,
9464,
14,
4317,
9294,
12,
2079,
687,
875,
12,
2748,
12,
1798,
29,
2087,
9,
339,
347,
511,
63,
15662,
63,
1122,
63,
493,
63,
1397,
63,
4214,
8,
277,
304,
267,
687,
875,
275,
7559,
14,
13521,
267,
366,
2076,
63,
1501,
275,
570,
607,
774,
3567,
16232,
12712,
2133,
14,
15662,
531,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
15662,
63,
6136,
29,
549,
9,
267,
2748,
275,
485,
2394,
4827,
1,
16556,
330,
20859,
2071,
83,
8186,
66,
2535,
65,
15,
2957,
66,
3524,
450,
366,
2076,
63,
1501,
9,
267,
291,
14,
1855,
8,
9464,
14,
4317,
9294,
12,
2079,
687,
875,
12,
2748,
12,
1798,
29,
2087,
9,
267,
2552,
275,
488,
267,
862,
26,
288,
687,
875,
8,
1652,
12,
1798,
29,
2087,
9,
267,
871,
7559,
14,
4317,
9294,
26,
288,
325,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
2552,
275,
359,
2397,
14,
1188,
367,
2397,
315,
325,
14,
705,
63,
793,
2432,
340,
366,
2076,
63,
1501,
315,
2397,
14,
1188,
1622,
267,
291,
14,
479,
2531,
2550,
9,
339,
347,
511,
63,
15662,
63,
1122,
63,
1078,
8,
277,
304,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
15662,
63,
6136,
29,
549,
9,
267,
2748,
275,
2650,
1,
16556,
282,
20859,
2071,
83,
8186,
65,
2535,
66,
15,
2957,
65,
3524,
450,
570,
607,
774,
3567,
480,
396,
14,
15662,
531,
267,
1738,
275,
7559,
14,
13521,
8,
1652,
12,
1798,
29,
2087,
9,
339,
347,
511,
63,
15662,
63,
1122,
63,
1078,
63,
6188,
8,
277,
304,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
15662,
63,
6136,
29,
549,
9,
267,
2748,
275,
2650,
1,
16556,
282,
20859,
298,
396,
14,
15662,
8186,
65,
2535,
66,
15,
2957,
65,
3524,
267,
1738,
275,
7559,
14,
13521,
8,
1652,
12,
1798,
29,
2087,
12,
1816,
1300,
63,
633,
29,
493,
607,
774,
3567,
480,
396,
14,
1652,
2237,
339,
347,
511,
63,
15662,
63,
3197,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
6757,
66,
2535,
65,
15,
2957,
66,
9579,
267,
366,
2076,
275,
7559,
14,
21156,
8,
15466,
6757,
1,
12535,
330,
16589,
30,
2237,
267,
291,
14,
1855,
8,
9464,
14,
5564,
3364,
12,
366,
2076,
14,
479,
3490,
12,
1738,
9,
339,
347,
511,
63,
15662,
63,
479,
3490,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
6757,
66,
2535,
65,
15,
2957,
66,
9579,
267,
366,
2076,
275,
7559,
14,
21156,
8,
15466,
6757,
1,
12535,
330,
334,
65,
9,
2535,
1,
12535,
282,
16589,
30,
2237,
267,
366,
2076,
14,
479,
3490,
8,
1231,
9,
339,
347,
511,
63,
15662,
63,
4672,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
1547,
2394,
10505,
267,
31513,
16556,
330,
20859,
298,
3592,
2,
359,
267,
31513,
12535,
330,
334,
65,
13032,
267,
31513,
12535,
282,
16589,
30,
267,
1622,
30,
267,
665,
66,
2535,
65,
15,
2957,
66,
30,
267,
2125,
1333,
267,
366,
2076,
275,
7559,
14,
15325,
8,
1231,
680,
32139,
14,
4672,
21156,
267,
291,
14,
479,
2531,
15662,
9,
267,
366,
2076,
14,
479,
3490,
8,
1231,
9,
339,
347,
511,
63,
15662,
63,
4672,
63,
3197,
8,
277,
304,
267,
1738,
275,
7559,
14,
4317,
1547,
2394,
10505,
267,
31513,
16556,
330,
20859,
298,
3592,
2,
359,
267,
31513,
12535,
330,
334,
65,
13032,
267,
31513,
12535,
282,
334,
67,
13032,
267,
31513,
12535,
286,
16589,
30,
267,
1622,
30,
267,
665,
66,
2535,
65,
15,
2957,
66,
30,
267,
2125,
1333,
267,
366,
2076,
275,
7559,
14,
15325,
8,
1231,
680,
32139,
14,
4672,
21156,
267,
291,
14,
479,
2531,
15662,
9,
267,
291,
14,
3334,
8,
15662,
14,
3502,
8,
1231,
430,
339,
347,
511,
63,
15662,
63,
15697,
8,
277,
304,
267,
291,
14,
1855,
8,
9464,
14,
21156,
9123,
12,
7559,
14,
21156,
12,
2079,
11808,
6757,
1,
12535,
330,
869,
615,
3078,
30,
2237,
339,
347,
511,
63,
1122,
63,
493,
63,
15662,
8,
277,
304,
267,
1798,
275,
7559,
14,
4317,
2842,
8,
3215,
63,
4322,
29,
549,
9,
398,
3123,
275,
7559,
14,
1122,
8,
493,
607,
774,
3567,
360,
396,
14,
1652,
659,
1798,
9,
267,
1738,
275,
3123,
14,
24544,
342,
398,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
AOSPU/external_chromium_org
|
tools/telemetry/telemetry/core/platform/power_monitor/monsoon_power_monitor.py
|
11
|
4251
|
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import json
import multiprocessing
import tempfile
import time
from telemetry.core import exceptions
from telemetry.core.platform.profiler import monsoon
import telemetry.core.platform.power_monitor as power_monitor
def _MonitorPower(device, is_collecting, output):
"""Monitoring process
Args:
device: A profiler.monsoon object to collect samples from.
is_collecting: the event to synchronize on.
output: opened file to write the samples.
"""
with output:
samples = []
start_time = None
end_time = None
try:
device.StartDataCollection()
is_collecting.set()
# First sample also calibrate the computation.
device.CollectData()
start_time = time.time()
while is_collecting.is_set():
new_data = device.CollectData()
assert new_data, 'Unable to collect data from device'
samples += new_data
end_time = time.time()
finally:
device.StopDataCollection()
result = {
'duration_s': end_time - start_time,
'samples': samples
}
json.dump(result, output)
class MonsoonPowerMonitor(power_monitor.PowerMonitor):
def __init__(self):
super(MonsoonPowerMonitor, self).__init__()
self._powermonitor_process = None
self._powermonitor_output_file = None
self._is_collecting = None
self._monsoon = None
try:
self._monsoon = monsoon.Monsoon(wait=False)
# Nominal Li-ion voltage is 3.7V, but it puts out 4.2V at max capacity.
# Use 4.0V to simulate a "~80%" charged battery. Google "li-ion voltage
# curve". This is true only for a single cell. (Most smartphones, some
# tablets.)
self._monsoon.SetVoltage(4.0)
except EnvironmentError:
self._monsoon = None
def CanMonitorPower(self):
return self._monsoon is not None
def StartMonitoringPower(self, browser):
assert not self._powermonitor_process, (
'Must call StopMonitoringPower().')
self._powermonitor_output_file = tempfile.TemporaryFile()
self._is_collecting = multiprocessing.Event()
self._powermonitor_process = multiprocessing.Process(
target=_MonitorPower,
args=(self._monsoon,
self._is_collecting,
self._powermonitor_output_file))
self._powermonitor_process.start()
if not self._is_collecting.wait(timeout=0.5):
self._powermonitor_process.terminate()
raise exceptions.ProfilingException('Failed to start data collection.')
def StopMonitoringPower(self):
assert self._powermonitor_process, (
'StartMonitoringPower() not called.')
try:
# Tell powermonitor to take an immediate sample and join.
self._is_collecting.clear()
self._powermonitor_process.join()
with self._powermonitor_output_file:
self._powermonitor_output_file.seek(0)
powermonitor_output = self._powermonitor_output_file.read()
assert powermonitor_output, 'PowerMonitor produced no output'
return MonsoonPowerMonitor.ParseSamplingOutput(powermonitor_output)
finally:
self._powermonitor_output_file = None
self._powermonitor_process = None
self._is_collecting = None
@staticmethod
def ParseSamplingOutput(powermonitor_output):
"""Parse the output of of the samples collector process.
Returns:
Dictionary in the format returned by StopMonitoringPower().
"""
power_samples = []
total_energy_consumption_mwh = 0
result = json.loads(powermonitor_output)
timedelta_h = result['duration_s'] / len(result['samples']) / 3600
for (current_a, voltage_v) in result['samples']:
energy_consumption_mw = current_a * voltage_v * 10**3
total_energy_consumption_mwh += energy_consumption_mw * timedelta_h
power_samples.append(energy_consumption_mw)
# -------- Collect and Process Data -------------
out_dict = {}
# Raw power usage samples.
out_dict['identifier'] = 'monsoon'
out_dict['power_samples_mw'] = power_samples
out_dict['energy_consumption_mwh'] = total_energy_consumption_mwh
return out_dict
|
bsd-3-clause
|
[
3,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2022,
199,
646,
12866,
199,
646,
5549,
199,
646,
900,
199,
199,
504,
17298,
14,
1018,
492,
4967,
199,
504,
17298,
14,
1018,
14,
3246,
14,
20132,
492,
3485,
1152,
265,
199,
646,
17298,
14,
1018,
14,
3246,
14,
5652,
63,
7157,
465,
7074,
63,
7157,
421,
199,
318,
485,
13189,
6921,
8,
1782,
12,
365,
63,
7112,
316,
12,
1072,
304,
523,
408,
13189,
316,
2112,
1362,
3033,
26,
2126,
2243,
26,
437,
23173,
14,
2106,
1152,
265,
909,
370,
8775,
5845,
687,
14,
2126,
365,
63,
7112,
316,
26,
314,
1566,
370,
31021,
641,
14,
2126,
1072,
26,
12123,
570,
370,
2218,
314,
5845,
14,
523,
408,
523,
543,
1072,
26,
272,
5845,
275,
942,
272,
1343,
63,
521,
275,
488,
272,
1284,
63,
521,
275,
488,
272,
862,
26,
489,
2243,
14,
3162,
1451,
7768,
342,
489,
365,
63,
7112,
316,
14,
409,
342,
489,
327,
7758,
2690,
2597,
12855,
1866,
314,
14009,
14,
489,
2243,
14,
25023,
1451,
342,
489,
1343,
63,
521,
275,
900,
14,
521,
342,
489,
1830,
365,
63,
7112,
316,
14,
374,
63,
409,
837,
267,
892,
63,
576,
275,
2243,
14,
25023,
1451,
342,
267,
702,
892,
63,
576,
12,
283,
6005,
370,
8775,
666,
687,
2243,
7,
267,
5845,
847,
892,
63,
576,
489,
1284,
63,
521,
275,
900,
14,
521,
342,
272,
3753,
26,
489,
2243,
14,
6293,
1451,
7768,
342,
272,
754,
275,
469,
489,
283,
5553,
63,
83,
356,
1284,
63,
521,
446,
1343,
63,
521,
12,
489,
283,
3356,
356,
5845,
272,
789,
272,
2022,
14,
2724,
8,
1099,
12,
1072,
9,
199,
199,
533,
10953,
1152,
265,
6921,
13189,
8,
5652,
63,
7157,
14,
6921,
13189,
304,
523,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
6671,
1152,
265,
6921,
13189,
12,
291,
2843,
826,
4533,
272,
291,
423,
5652,
7157,
63,
1412,
275,
488,
272,
291,
423,
5652,
7157,
63,
1199,
63,
493,
275,
488,
272,
291,
423,
374,
63,
7112,
316,
275,
488,
272,
291,
423,
2106,
1152,
265,
275,
488,
272,
862,
26,
489,
291,
423,
2106,
1152,
265,
275,
3485,
1152,
265,
14,
6671,
1152,
265,
8,
2573,
29,
797,
9,
489,
327,
653,
676,
1582,
24157,
13,
1636,
29943,
365,
650,
14,
23,
54,
12,
1325,
652,
27000,
734,
841,
14,
18,
54,
737,
1390,
14893,
14,
489,
327,
3645,
841,
14,
16,
54,
370,
20577,
282,
26810,
1257,
5,
2,
1495,
3046,
330,
13891,
14,
4475,
298,
317,
13,
1636,
29943,
489,
327,
15318,
1674,
961,
365,
2549,
1454,
367,
282,
2849,
4917,
14,
334,
24625,
11179,
838,
4548,
12,
2005,
489,
327,
1817,
1086,
4959,
489,
291,
423,
2106,
1152,
265,
14,
1084,
16969,
15028,
8,
20,
14,
16,
9,
272,
871,
25139,
26,
489,
291,
423,
2106,
1152,
265,
275,
488,
819,
347,
6855,
13189,
6921,
8,
277,
304,
272,
372,
291,
423,
2106,
1152,
265,
365,
440,
488,
819,
347,
7707,
13189,
316,
6921,
8,
277,
12,
7042,
304,
272,
702,
440,
291,
423,
5652,
7157,
63,
1412,
12,
334,
267,
283,
13757,
1240,
8015,
13189,
316,
6921,
1252,
358,
272,
291,
423,
5652,
7157,
63,
1199,
63,
493,
275,
5549,
14,
13271,
342,
272,
291,
423,
374,
63,
7112,
316,
275,
12866,
14,
2390,
342,
272,
291,
423,
5652,
7157,
63,
1412,
275,
12866,
14,
3498,
8,
267,
1347,
3699,
13189,
6921,
12,
267,
1249,
2687,
277,
423,
2106,
1152,
265,
12,
1598,
291,
423,
374,
63,
7112,
316,
12,
1598,
291,
423,
5652,
7157,
63,
1199,
63,
493,
430,
272,
291,
423,
5652,
7157,
63,
1412,
14,
928,
342,
272,
340,
440,
291,
423,
374,
63,
7112,
316,
14,
2573,
8,
2593,
29,
16,
14,
21,
304,
489,
291,
423,
5652,
7157,
63,
1412,
14,
14478,
342,
489,
746,
4967,
14,
919,
19294,
1726,
360,
4276,
370,
1343,
666,
3245,
2659,
819,
347,
8015,
13189,
316,
6921,
8,
277,
304,
272,
702,
291,
423,
5652,
7157,
63,
1412,
12,
334,
267,
283,
3162,
13189,
316,
6921,
342,
440,
2797,
2659,
272,
862,
26,
489,
327,
30528,
7074,
7157,
370,
5452,
376,
8569,
2690,
436,
4263,
14,
489,
291,
423,
374,
63,
7112,
316,
14,
3584,
342,
489,
291,
423,
5652,
7157,
63,
1412,
14,
904,
342,
489,
543,
291,
423,
5652,
7157,
63,
1199,
63,
493,
26,
267,
291,
423,
5652,
7157,
63,
1199,
63,
493,
14,
5507,
8,
16,
9,
267,
7074,
7157,
63,
1199,
275,
291,
423,
5652,
7157,
63,
1199,
63,
493,
14,
739,
342,
489,
702,
7074,
7157,
63,
1199,
12,
283,
6921,
13189,
13584,
949,
1072,
7,
489,
372,
10953,
1152,
265,
6921,
13189,
14,
4003,
12226,
8922,
2959,
8,
5652,
7157,
63,
1199,
9,
272,
3753,
26,
489,
291,
423,
5652,
7157,
63,
1199,
63,
493,
275,
488,
489,
291,
423,
5652,
7157,
63,
1412,
275,
488,
489,
291,
423,
374,
63,
7112,
316,
275,
488,
819,
768,
4639,
523,
347,
6077,
12226,
8922,
2959,
8,
5652,
7157,
63,
1199,
304,
272,
408,
4003,
314,
1072,
402,
402,
314,
5845,
14910,
2112,
14,
339,
1803,
26,
267,
11932,
315,
314,
1475,
2138,
701,
8015,
13189,
316,
6921,
1252,
272,
408,
272,
7074,
63,
3356,
275,
942,
272,
3141,
63,
8443,
63,
8704,
15052,
63,
77,
2191,
275,
378,
272,
754,
275,
2022,
14,
3640,
8,
5652,
7157,
63,
1199,
9,
272,
6871,
63,
72,
275,
754,
459,
5553,
63,
83,
418,
1182,
822,
8,
1099,
459,
3356,
1105,
1182,
15751,
272,
367,
334,
1818,
63,
65,
12,
29943,
63,
86,
9,
315,
754,
459,
3356,
2565,
489,
12304,
63,
8704,
15052,
63,
14716,
275,
1453,
63,
65,
627,
29943,
63,
86,
627,
1616,
538,
19,
489,
3141,
63,
8443,
63,
8704,
15052,
63,
77,
2191,
847,
12304,
63,
8704,
15052,
63,
14716,
627,
6871,
63,
72,
489,
7074,
63,
3356,
14,
740,
8,
8443,
63,
8704,
15052,
63,
14716,
9,
272,
327,
3001,
19649,
436,
7132,
3918,
3001,
9858,
272,
734
] |
[
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2022,
199,
646,
12866,
199,
646,
5549,
199,
646,
900,
199,
199,
504,
17298,
14,
1018,
492,
4967,
199,
504,
17298,
14,
1018,
14,
3246,
14,
20132,
492,
3485,
1152,
265,
199,
646,
17298,
14,
1018,
14,
3246,
14,
5652,
63,
7157,
465,
7074,
63,
7157,
421,
199,
318,
485,
13189,
6921,
8,
1782,
12,
365,
63,
7112,
316,
12,
1072,
304,
523,
408,
13189,
316,
2112,
1362,
3033,
26,
2126,
2243,
26,
437,
23173,
14,
2106,
1152,
265,
909,
370,
8775,
5845,
687,
14,
2126,
365,
63,
7112,
316,
26,
314,
1566,
370,
31021,
641,
14,
2126,
1072,
26,
12123,
570,
370,
2218,
314,
5845,
14,
523,
408,
523,
543,
1072,
26,
272,
5845,
275,
942,
272,
1343,
63,
521,
275,
488,
272,
1284,
63,
521,
275,
488,
272,
862,
26,
489,
2243,
14,
3162,
1451,
7768,
342,
489,
365,
63,
7112,
316,
14,
409,
342,
489,
327,
7758,
2690,
2597,
12855,
1866,
314,
14009,
14,
489,
2243,
14,
25023,
1451,
342,
489,
1343,
63,
521,
275,
900,
14,
521,
342,
489,
1830,
365,
63,
7112,
316,
14,
374,
63,
409,
837,
267,
892,
63,
576,
275,
2243,
14,
25023,
1451,
342,
267,
702,
892,
63,
576,
12,
283,
6005,
370,
8775,
666,
687,
2243,
7,
267,
5845,
847,
892,
63,
576,
489,
1284,
63,
521,
275,
900,
14,
521,
342,
272,
3753,
26,
489,
2243,
14,
6293,
1451,
7768,
342,
272,
754,
275,
469,
489,
283,
5553,
63,
83,
356,
1284,
63,
521,
446,
1343,
63,
521,
12,
489,
283,
3356,
356,
5845,
272,
789,
272,
2022,
14,
2724,
8,
1099,
12,
1072,
9,
199,
199,
533,
10953,
1152,
265,
6921,
13189,
8,
5652,
63,
7157,
14,
6921,
13189,
304,
523,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
6671,
1152,
265,
6921,
13189,
12,
291,
2843,
826,
4533,
272,
291,
423,
5652,
7157,
63,
1412,
275,
488,
272,
291,
423,
5652,
7157,
63,
1199,
63,
493,
275,
488,
272,
291,
423,
374,
63,
7112,
316,
275,
488,
272,
291,
423,
2106,
1152,
265,
275,
488,
272,
862,
26,
489,
291,
423,
2106,
1152,
265,
275,
3485,
1152,
265,
14,
6671,
1152,
265,
8,
2573,
29,
797,
9,
489,
327,
653,
676,
1582,
24157,
13,
1636,
29943,
365,
650,
14,
23,
54,
12,
1325,
652,
27000,
734,
841,
14,
18,
54,
737,
1390,
14893,
14,
489,
327,
3645,
841,
14,
16,
54,
370,
20577,
282,
26810,
1257,
5,
2,
1495,
3046,
330,
13891,
14,
4475,
298,
317,
13,
1636,
29943,
489,
327,
15318,
1674,
961,
365,
2549,
1454,
367,
282,
2849,
4917,
14,
334,
24625,
11179,
838,
4548,
12,
2005,
489,
327,
1817,
1086,
4959,
489,
291,
423,
2106,
1152,
265,
14,
1084,
16969,
15028,
8,
20,
14,
16,
9,
272,
871,
25139,
26,
489,
291,
423,
2106,
1152,
265,
275,
488,
819,
347,
6855,
13189,
6921,
8,
277,
304,
272,
372,
291,
423,
2106,
1152,
265,
365,
440,
488,
819,
347,
7707,
13189,
316,
6921,
8,
277,
12,
7042,
304,
272,
702,
440,
291,
423,
5652,
7157,
63,
1412,
12,
334,
267,
283,
13757,
1240,
8015,
13189,
316,
6921,
1252,
358,
272,
291,
423,
5652,
7157,
63,
1199,
63,
493,
275,
5549,
14,
13271,
342,
272,
291,
423,
374,
63,
7112,
316,
275,
12866,
14,
2390,
342,
272,
291,
423,
5652,
7157,
63,
1412,
275,
12866,
14,
3498,
8,
267,
1347,
3699,
13189,
6921,
12,
267,
1249,
2687,
277,
423,
2106,
1152,
265,
12,
1598,
291,
423,
374,
63,
7112,
316,
12,
1598,
291,
423,
5652,
7157,
63,
1199,
63,
493,
430,
272,
291,
423,
5652,
7157,
63,
1412,
14,
928,
342,
272,
340,
440,
291,
423,
374,
63,
7112,
316,
14,
2573,
8,
2593,
29,
16,
14,
21,
304,
489,
291,
423,
5652,
7157,
63,
1412,
14,
14478,
342,
489,
746,
4967,
14,
919,
19294,
1726,
360,
4276,
370,
1343,
666,
3245,
2659,
819,
347,
8015,
13189,
316,
6921,
8,
277,
304,
272,
702,
291,
423,
5652,
7157,
63,
1412,
12,
334,
267,
283,
3162,
13189,
316,
6921,
342,
440,
2797,
2659,
272,
862,
26,
489,
327,
30528,
7074,
7157,
370,
5452,
376,
8569,
2690,
436,
4263,
14,
489,
291,
423,
374,
63,
7112,
316,
14,
3584,
342,
489,
291,
423,
5652,
7157,
63,
1412,
14,
904,
342,
489,
543,
291,
423,
5652,
7157,
63,
1199,
63,
493,
26,
267,
291,
423,
5652,
7157,
63,
1199,
63,
493,
14,
5507,
8,
16,
9,
267,
7074,
7157,
63,
1199,
275,
291,
423,
5652,
7157,
63,
1199,
63,
493,
14,
739,
342,
489,
702,
7074,
7157,
63,
1199,
12,
283,
6921,
13189,
13584,
949,
1072,
7,
489,
372,
10953,
1152,
265,
6921,
13189,
14,
4003,
12226,
8922,
2959,
8,
5652,
7157,
63,
1199,
9,
272,
3753,
26,
489,
291,
423,
5652,
7157,
63,
1199,
63,
493,
275,
488,
489,
291,
423,
5652,
7157,
63,
1412,
275,
488,
489,
291,
423,
374,
63,
7112,
316,
275,
488,
819,
768,
4639,
523,
347,
6077,
12226,
8922,
2959,
8,
5652,
7157,
63,
1199,
304,
272,
408,
4003,
314,
1072,
402,
402,
314,
5845,
14910,
2112,
14,
339,
1803,
26,
267,
11932,
315,
314,
1475,
2138,
701,
8015,
13189,
316,
6921,
1252,
272,
408,
272,
7074,
63,
3356,
275,
942,
272,
3141,
63,
8443,
63,
8704,
15052,
63,
77,
2191,
275,
378,
272,
754,
275,
2022,
14,
3640,
8,
5652,
7157,
63,
1199,
9,
272,
6871,
63,
72,
275,
754,
459,
5553,
63,
83,
418,
1182,
822,
8,
1099,
459,
3356,
1105,
1182,
15751,
272,
367,
334,
1818,
63,
65,
12,
29943,
63,
86,
9,
315,
754,
459,
3356,
2565,
489,
12304,
63,
8704,
15052,
63,
14716,
275,
1453,
63,
65,
627,
29943,
63,
86,
627,
1616,
538,
19,
489,
3141,
63,
8443,
63,
8704,
15052,
63,
77,
2191,
847,
12304,
63,
8704,
15052,
63,
14716,
627,
6871,
63,
72,
489,
7074,
63,
3356,
14,
740,
8,
8443,
63,
8704,
15052,
63,
14716,
9,
272,
327,
3001,
19649,
436,
7132,
3918,
3001,
9858,
272,
734,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nortikin/sverchok
|
node_scripts/SNLite_templates/demo/recursive_subdivision.py
|
1
|
1833
|
"""
in quad_verts v
in quad_faces s
in seed s d=1 n=2
in random_factor s d=0.1 n=2
in iterations s d=1 n=2
out verts v
out edges s
out faces s
"""
from sverchok.utils.modules.geom_utils import interp_v3_v3v3 as lerp
from sverchok.utils.sv_mesh_utils import mesh_join
from sverchok.utils.sv_bmesh_utils import remove_doubles
import random
# loosely based on https://www.youtube.com/watch?v=GhquYJ9m1Oc
sort = lambda vex, pox: [vex[i] for i in pox]
def random_subdiv_mesh(verts_m, pols_m, iteration):
verts, faces = [], []
for pol in pols_m:
verts_out, faces_out = [], []
new_quad = faces_out.append
pts = sort(verts_m, pol)
X = 0.5 +(random.random() - 0.5) * random_factor
Y = 0.5 +(random.random() - 0.5) * random_factor
pos_a = lerp(pts[0], pts[1], Y)
pos_b = lerp(pts[1], pts[2], X)
pos_c = lerp(pts[3], pts[2], 1-Y)
pos_d = lerp(pts[0], pts[3], X)
pos_e = lerp(pos_d, pos_b, Y)
pos_f = lerp(pos_d, pos_b, 1-Y)
# indices = 0, 1, 2, 3
verts_out.extend(pts)
# indices = 4, 5, 6, 7, 8, 9
verts_out.extend([pos_a, pos_b, pos_c, pos_d, pos_e, pos_f])
new_quad([0, 4, 8, 7])
new_quad([4, 1, 5, 8])
new_quad([5, 2, 6, 9])
new_quad([7, 9, 6, 3])
faces.append(faces_out)
verts.append(verts_out)
verts, _, faces = mesh_join(verts, [], faces)
if iteration < 2 :
return verts, faces
else:
return random_subdiv_mesh(verts, faces, iteration - 1)
if quad_verts and quad_faces:
random.seed(seed)
verts, faces = random_subdiv_mesh(quad_verts[0], quad_faces[0], iterations)
verts, edges, faces = remove_doubles(verts, [], faces, 1e-5)
verts = [verts]
edges = [edges]
faces = [faces]
|
gpl-3.0
|
[
624,
199,
262,
16744,
63,
21505,
373,
199,
262,
16744,
63,
4309,
308,
199,
262,
6347,
308,
366,
29,
17,
302,
29,
18,
199,
262,
2196,
63,
4778,
308,
366,
29,
16,
14,
17,
302,
29,
18,
199,
262,
10615,
308,
366,
29,
17,
302,
29,
18,
199,
548,
809,
1086,
373,
199,
548,
8207,
308,
199,
548,
21143,
308,
199,
624,
199,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
3112,
14,
6481,
63,
1208,
492,
23716,
63,
86,
19,
63,
86,
19,
86,
19,
465,
1026,
4599,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
2772,
63,
6480,
63,
1208,
492,
9364,
63,
904,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
2772,
63,
66,
6480,
63,
1208,
492,
2813,
63,
3157,
83,
199,
646,
221,
2196,
199,
199,
3,
560,
3362,
590,
4079,
641,
4178,
921,
1544,
14,
9788,
14,
957,
15,
6821,
31,
86,
29,
39,
72,
392,
57,
42,
25,
77,
17,
16184,
199,
199,
3191,
275,
2400,
373,
476,
12,
1115,
88,
26,
359,
26221,
59,
73,
61,
367,
284,
315,
1115,
88,
61,
199,
199,
318,
2196,
63,
954,
3015,
63,
6480,
8,
21505,
63,
77,
12,
299,
1446,
63,
77,
12,
8494,
304,
339,
809,
1086,
12,
21143,
275,
990,
942,
272,
367,
3708,
315,
299,
1446,
63,
77,
26,
267,
809,
1086,
63,
548,
12,
21143,
63,
548,
275,
990,
942,
267,
892,
63,
14567,
275,
21143,
63,
548,
14,
740,
398,
21286,
275,
4069,
8,
21505,
63,
77,
12,
3708,
9,
267,
1323,
275,
378,
14,
21,
435,
8,
2355,
14,
2355,
342,
446,
378,
14,
21,
9,
627,
2196,
63,
4778,
267,
1488,
275,
378,
14,
21,
435,
8,
2355,
14,
2355,
342,
446,
378,
14,
21,
9,
627,
2196,
63,
4778,
267,
2086,
63,
65,
275,
1026,
4599,
8,
8382,
59,
16,
467,
21286,
59,
17,
467,
1488,
9,
267,
2086,
63,
66,
275,
1026,
4599,
8,
8382,
59,
17,
467,
21286,
59,
18,
467,
1323,
9,
267,
2086,
63,
67,
275,
1026,
4599,
8,
8382,
59,
19,
467,
21286,
59,
18,
467,
413,
13,
57,
9,
267,
2086,
63,
68,
275,
1026,
4599,
8,
8382,
59,
16,
467,
21286,
59,
19,
467,
1323,
9,
267,
2086,
63,
69,
275,
1026,
4599,
8,
1712,
63,
68,
12,
2086,
63,
66,
12,
1488,
9,
267,
2086,
63,
70,
275,
1026,
4599,
8,
1712,
63,
68,
12,
2086,
63,
66,
12,
413,
13,
57,
9,
398,
327,
4918,
275,
378,
12,
413,
12,
499,
12,
650,
267,
809,
1086,
63,
548,
14,
2880,
8,
8382,
9,
398,
327,
4918,
275,
755,
841,
12,
258,
959,
12,
258,
1227,
12,
258,
1520,
12,
258,
1695,
12,
258,
1749,
267,
809,
1086,
63,
548,
14,
2880,
779,
1712,
63,
65,
12,
2086,
63,
66,
12,
2086,
63,
67,
12,
2086,
63,
68,
12,
2086,
63,
69,
12,
2086,
63,
70,
566,
398,
892,
63,
14567,
779,
16,
12,
841,
12,
1695,
12,
1520,
566,
267,
892,
63,
14567,
779,
20,
12,
413,
12,
959,
12,
1695,
566,
267,
892,
63,
14567,
779,
21,
12,
499,
12,
1227,
12,
1749,
566,
267,
892,
63,
14567,
779,
23,
12,
1749,
12,
1227,
12,
650,
566,
267,
21143,
14,
740,
8,
4309,
63,
548,
9,
267,
809,
1086,
14,
740,
8,
21505,
63,
548,
9,
339,
809,
1086,
12,
5501,
21143,
275,
9364,
63,
904,
8,
21505,
12,
990,
21143,
9,
272,
340,
8494,
665,
499,
520,
267,
372,
809,
1086,
12,
21143,
272,
587,
26,
267,
372,
2196,
63,
954,
3015,
63,
6480,
8,
21505,
12,
21143,
12,
8494,
446,
413,
9,
199,
199,
692,
16744,
63,
21505,
436,
16744,
63,
4309,
26,
272,
2196,
14,
5176,
8,
5176,
9,
272,
809,
1086,
12,
21143,
275,
2196,
63,
954,
3015,
63,
6480,
8,
14567,
63,
21505,
59,
16,
467,
16744,
63,
4309,
59,
16,
467,
10615,
9,
272,
809,
1086,
12,
8207,
12,
21143,
275,
2813,
63,
3157,
83,
8,
21505,
12,
990,
21143,
12,
413,
69,
13,
21,
9,
272,
809,
1086,
275,
359,
21505,
61,
272,
8207,
275,
359,
6929,
61,
272,
21143,
275,
359,
4309,
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
] |
[
199,
262,
16744,
63,
21505,
373,
199,
262,
16744,
63,
4309,
308,
199,
262,
6347,
308,
366,
29,
17,
302,
29,
18,
199,
262,
2196,
63,
4778,
308,
366,
29,
16,
14,
17,
302,
29,
18,
199,
262,
10615,
308,
366,
29,
17,
302,
29,
18,
199,
548,
809,
1086,
373,
199,
548,
8207,
308,
199,
548,
21143,
308,
199,
624,
199,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
3112,
14,
6481,
63,
1208,
492,
23716,
63,
86,
19,
63,
86,
19,
86,
19,
465,
1026,
4599,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
2772,
63,
6480,
63,
1208,
492,
9364,
63,
904,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
2772,
63,
66,
6480,
63,
1208,
492,
2813,
63,
3157,
83,
199,
646,
221,
2196,
199,
199,
3,
560,
3362,
590,
4079,
641,
4178,
921,
1544,
14,
9788,
14,
957,
15,
6821,
31,
86,
29,
39,
72,
392,
57,
42,
25,
77,
17,
16184,
199,
199,
3191,
275,
2400,
373,
476,
12,
1115,
88,
26,
359,
26221,
59,
73,
61,
367,
284,
315,
1115,
88,
61,
199,
199,
318,
2196,
63,
954,
3015,
63,
6480,
8,
21505,
63,
77,
12,
299,
1446,
63,
77,
12,
8494,
304,
339,
809,
1086,
12,
21143,
275,
990,
942,
272,
367,
3708,
315,
299,
1446,
63,
77,
26,
267,
809,
1086,
63,
548,
12,
21143,
63,
548,
275,
990,
942,
267,
892,
63,
14567,
275,
21143,
63,
548,
14,
740,
398,
21286,
275,
4069,
8,
21505,
63,
77,
12,
3708,
9,
267,
1323,
275,
378,
14,
21,
435,
8,
2355,
14,
2355,
342,
446,
378,
14,
21,
9,
627,
2196,
63,
4778,
267,
1488,
275,
378,
14,
21,
435,
8,
2355,
14,
2355,
342,
446,
378,
14,
21,
9,
627,
2196,
63,
4778,
267,
2086,
63,
65,
275,
1026,
4599,
8,
8382,
59,
16,
467,
21286,
59,
17,
467,
1488,
9,
267,
2086,
63,
66,
275,
1026,
4599,
8,
8382,
59,
17,
467,
21286,
59,
18,
467,
1323,
9,
267,
2086,
63,
67,
275,
1026,
4599,
8,
8382,
59,
19,
467,
21286,
59,
18,
467,
413,
13,
57,
9,
267,
2086,
63,
68,
275,
1026,
4599,
8,
8382,
59,
16,
467,
21286,
59,
19,
467,
1323,
9,
267,
2086,
63,
69,
275,
1026,
4599,
8,
1712,
63,
68,
12,
2086,
63,
66,
12,
1488,
9,
267,
2086,
63,
70,
275,
1026,
4599,
8,
1712,
63,
68,
12,
2086,
63,
66,
12,
413,
13,
57,
9,
398,
327,
4918,
275,
378,
12,
413,
12,
499,
12,
650,
267,
809,
1086,
63,
548,
14,
2880,
8,
8382,
9,
398,
327,
4918,
275,
755,
841,
12,
258,
959,
12,
258,
1227,
12,
258,
1520,
12,
258,
1695,
12,
258,
1749,
267,
809,
1086,
63,
548,
14,
2880,
779,
1712,
63,
65,
12,
2086,
63,
66,
12,
2086,
63,
67,
12,
2086,
63,
68,
12,
2086,
63,
69,
12,
2086,
63,
70,
566,
398,
892,
63,
14567,
779,
16,
12,
841,
12,
1695,
12,
1520,
566,
267,
892,
63,
14567,
779,
20,
12,
413,
12,
959,
12,
1695,
566,
267,
892,
63,
14567,
779,
21,
12,
499,
12,
1227,
12,
1749,
566,
267,
892,
63,
14567,
779,
23,
12,
1749,
12,
1227,
12,
650,
566,
267,
21143,
14,
740,
8,
4309,
63,
548,
9,
267,
809,
1086,
14,
740,
8,
21505,
63,
548,
9,
339,
809,
1086,
12,
5501,
21143,
275,
9364,
63,
904,
8,
21505,
12,
990,
21143,
9,
272,
340,
8494,
665,
499,
520,
267,
372,
809,
1086,
12,
21143,
272,
587,
26,
267,
372,
2196,
63,
954,
3015,
63,
6480,
8,
21505,
12,
21143,
12,
8494,
446,
413,
9,
199,
199,
692,
16744,
63,
21505,
436,
16744,
63,
4309,
26,
272,
2196,
14,
5176,
8,
5176,
9,
272,
809,
1086,
12,
21143,
275,
2196,
63,
954,
3015,
63,
6480,
8,
14567,
63,
21505,
59,
16,
467,
16744,
63,
4309,
59,
16,
467,
10615,
9,
272,
809,
1086,
12,
8207,
12,
21143,
275,
2813,
63,
3157,
83,
8,
21505,
12,
990,
21143,
12,
413,
69,
13,
21,
9,
272,
809,
1086,
275,
359,
21505,
61,
272,
8207,
275,
359,
6929,
61,
272,
21143,
275,
359,
4309,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
imclab/ckanext-comments
|
ckanext/comments/tests/logic/test_threads.py
|
2
|
2933
|
from nose.tools import assert_raises
from pylons import config
import ckan.model as model
from ckan.logic import get_action, NotAuthorized
import ckanext.comments.tests.test_data as test_data
class TestCommentThread(object):
@classmethod
def setup_class(cls):
model.repo.new_revision()
test_data.create()
@classmethod
def teardown_class(cls):
test_data.cleanup()
model.repo.rebuild_db()
def test_comment_create_basic(self):
thread = self._create_valid('/dataset/create_test')
assert len(thread['comments']) == 1, "Missing top level comment"
assert len(thread['comments'][0]['comments']) == 1, "Missing child comment"
def test_comment_delete_valid(self):
thread = self._create_valid('/dataset/delete_test')
c_upper_id = thread['comments'][0]['id']
c_id = thread['comments'][0]['comments'][0]['id']
# Process a leaf comment
ctx = { 'model': model, 'session': model.Session,
'user': test_data.site_user() }
try:
res = get_action('comment_delete')(ctx, { 'id': c_id })
except NotAuthorized:
assert False, "Should allow user to delete comment"
try:
res = get_action('comment_show')(ctx, { 'id': c_id })
except NotAuthorized:
assert False, "Should allow user to view comment"
assert res['state'] == 'deleted', "Comment does not have deleted state"
# Try a comment that has children
try:
res = get_action('comment_delete')(ctx, { 'id': c_upper_id })
except NotAuthorized:
assert False, "Should allow user to delete comment"
try:
res = get_action('comment_show')(ctx, { 'id': c_upper_id })
except NotAuthorized:
assert False, "Should allow user to view comment"
assert res['content'] == config.get('ckan.comments.deleted.text', 'This message was deleted'),\
"Comment did not have text set correctly, it has children"
def _create_valid(self, url):
ctx = { 'model': model, 'session': model.Session,
'user': test_data.site_user() }
data = {
'url': url,
'parent_id': '',
'comment': 'A comment'
}
try:
res = get_action('comment_create')(ctx, data)
except NotAuthorized:
assert False, "Should allow user to create valid comment"
data = {
'url': url,
'parent_id': res['id'],
'comment': 'Another comment'
}
try:
res = get_action('comment_create')(ctx, data)
except NotAuthorized:
assert False, "Should allow user to create valid comment"
return get_action('thread_show')({'model':model, 'user':''}, {'id': res['thread_id']})
def test_comment_create_fail(self):
pass
|
gpl-3.0
|
[
504,
11354,
14,
2537,
492,
702,
63,
3536,
199,
504,
1134,
76,
4654,
492,
1101,
199,
199,
646,
22030,
290,
14,
1238,
465,
1402,
199,
504,
22030,
290,
14,
15370,
492,
664,
63,
1287,
12,
2832,
29284,
199,
199,
646,
22030,
290,
832,
14,
6223,
14,
2219,
14,
396,
63,
576,
465,
511,
63,
576,
199,
199,
533,
1379,
7488,
4436,
8,
785,
304,
339,
768,
3744,
272,
347,
3272,
63,
533,
8,
1886,
304,
267,
1402,
14,
3417,
14,
1222,
63,
5792,
342,
267,
511,
63,
576,
14,
981,
342,
339,
768,
3744,
272,
347,
17558,
63,
533,
8,
1886,
304,
267,
511,
63,
576,
14,
7661,
342,
267,
1402,
14,
3417,
14,
19278,
63,
697,
342,
339,
347,
511,
63,
3349,
63,
981,
63,
4316,
8,
277,
304,
267,
2462,
275,
291,
423,
981,
63,
1078,
2336,
5214,
15,
981,
63,
396,
358,
267,
702,
822,
8,
2671,
459,
6223,
1105,
508,
413,
12,
298,
7718,
2746,
2166,
3721,
2,
267,
702,
822,
8,
2671,
459,
6223,
3488,
16,
2733,
6223,
1105,
508,
413,
12,
298,
7718,
1982,
3721,
2,
339,
347,
511,
63,
3349,
63,
1807,
63,
1078,
8,
277,
304,
267,
2462,
275,
291,
423,
981,
63,
1078,
2336,
5214,
15,
1807,
63,
396,
358,
398,
286,
63,
4142,
63,
344,
275,
2462,
459,
6223,
3488,
16,
2733,
344,
418,
267,
286,
63,
344,
275,
2462,
459,
6223,
3488,
16,
2733,
6223,
3488,
16,
2733,
344,
418,
398,
327,
7132,
282,
11747,
3721,
267,
4027,
275,
469,
283,
1238,
356,
1402,
12,
283,
1730,
356,
1402,
14,
4434,
12,
355,
283,
751,
356,
511,
63,
576,
14,
2124,
63,
751,
342,
789,
267,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
1807,
7533,
3799,
12,
469,
283,
344,
356,
286,
63,
344,
3828,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
3145,
3721,
2,
398,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
2384,
7533,
3799,
12,
469,
283,
344,
356,
286,
63,
344,
3828,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
2455,
3721,
2,
267,
702,
522,
459,
929,
418,
508,
283,
6062,
297,
298,
7488,
1630,
440,
1172,
5463,
1174,
2,
398,
327,
7649,
282,
3721,
626,
965,
4978,
267,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
1807,
7533,
3799,
12,
469,
283,
344,
356,
286,
63,
4142,
63,
344,
3828,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
3145,
3721,
2,
398,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
2384,
7533,
3799,
12,
469,
283,
344,
356,
286,
63,
4142,
63,
344,
3828,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
2455,
3721,
2,
398,
702,
522,
459,
1317,
418,
508,
1101,
14,
362,
360,
346,
290,
14,
6223,
14,
6062,
14,
505,
297,
283,
2765,
1245,
1990,
5463,
659,
60,
288,
298,
7488,
8103,
440,
1172,
1318,
663,
6657,
12,
652,
965,
4978,
2,
2378,
347,
485,
981,
63,
1078,
8,
277,
12,
1166,
304,
267,
4027,
275,
469,
283,
1238,
356,
1402,
12,
283,
1730,
356,
1402,
14,
4434,
12,
355,
283,
751,
356,
511,
63,
576,
14,
2124,
63,
751,
342,
789,
267,
666,
275,
469,
288,
283,
633,
356,
1166,
12,
288,
283,
1708,
63,
344,
356,
3260,
288,
283,
3349,
356,
283,
33,
3721,
7,
267,
789,
267,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
981,
7533,
3799,
12,
666,
9,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
1218,
1686,
3721,
2,
398,
666,
275,
469,
288,
283,
633,
356,
1166,
12,
288,
283,
1708,
63,
344,
356,
522,
459,
344,
995,
288,
283,
3349,
356,
283,
23296,
3721,
7,
267,
789,
398,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
981,
7533,
3799,
12,
666,
9,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
1218,
1686,
3721,
2,
398,
372,
664,
63,
1287,
360,
2671,
63,
2384,
358,
3252,
1238,
356,
1238,
12,
283,
751,
356,
891,
1386,
791,
344,
356,
522,
459,
2671,
63,
344,
13678,
2378,
347,
511,
63,
3349,
63,
981,
63,
1633,
8,
277,
304,
267,
986,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11354,
14,
2537,
492,
702,
63,
3536,
199,
504,
1134,
76,
4654,
492,
1101,
199,
199,
646,
22030,
290,
14,
1238,
465,
1402,
199,
504,
22030,
290,
14,
15370,
492,
664,
63,
1287,
12,
2832,
29284,
199,
199,
646,
22030,
290,
832,
14,
6223,
14,
2219,
14,
396,
63,
576,
465,
511,
63,
576,
199,
199,
533,
1379,
7488,
4436,
8,
785,
304,
339,
768,
3744,
272,
347,
3272,
63,
533,
8,
1886,
304,
267,
1402,
14,
3417,
14,
1222,
63,
5792,
342,
267,
511,
63,
576,
14,
981,
342,
339,
768,
3744,
272,
347,
17558,
63,
533,
8,
1886,
304,
267,
511,
63,
576,
14,
7661,
342,
267,
1402,
14,
3417,
14,
19278,
63,
697,
342,
339,
347,
511,
63,
3349,
63,
981,
63,
4316,
8,
277,
304,
267,
2462,
275,
291,
423,
981,
63,
1078,
2336,
5214,
15,
981,
63,
396,
358,
267,
702,
822,
8,
2671,
459,
6223,
1105,
508,
413,
12,
298,
7718,
2746,
2166,
3721,
2,
267,
702,
822,
8,
2671,
459,
6223,
3488,
16,
2733,
6223,
1105,
508,
413,
12,
298,
7718,
1982,
3721,
2,
339,
347,
511,
63,
3349,
63,
1807,
63,
1078,
8,
277,
304,
267,
2462,
275,
291,
423,
981,
63,
1078,
2336,
5214,
15,
1807,
63,
396,
358,
398,
286,
63,
4142,
63,
344,
275,
2462,
459,
6223,
3488,
16,
2733,
344,
418,
267,
286,
63,
344,
275,
2462,
459,
6223,
3488,
16,
2733,
6223,
3488,
16,
2733,
344,
418,
398,
327,
7132,
282,
11747,
3721,
267,
4027,
275,
469,
283,
1238,
356,
1402,
12,
283,
1730,
356,
1402,
14,
4434,
12,
355,
283,
751,
356,
511,
63,
576,
14,
2124,
63,
751,
342,
789,
267,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
1807,
7533,
3799,
12,
469,
283,
344,
356,
286,
63,
344,
3828,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
3145,
3721,
2,
398,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
2384,
7533,
3799,
12,
469,
283,
344,
356,
286,
63,
344,
3828,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
2455,
3721,
2,
267,
702,
522,
459,
929,
418,
508,
283,
6062,
297,
298,
7488,
1630,
440,
1172,
5463,
1174,
2,
398,
327,
7649,
282,
3721,
626,
965,
4978,
267,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
1807,
7533,
3799,
12,
469,
283,
344,
356,
286,
63,
4142,
63,
344,
3828,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
3145,
3721,
2,
398,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
2384,
7533,
3799,
12,
469,
283,
344,
356,
286,
63,
4142,
63,
344,
3828,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
2455,
3721,
2,
398,
702,
522,
459,
1317,
418,
508,
1101,
14,
362,
360,
346,
290,
14,
6223,
14,
6062,
14,
505,
297,
283,
2765,
1245,
1990,
5463,
659,
60,
288,
298,
7488,
8103,
440,
1172,
1318,
663,
6657,
12,
652,
965,
4978,
2,
2378,
347,
485,
981,
63,
1078,
8,
277,
12,
1166,
304,
267,
4027,
275,
469,
283,
1238,
356,
1402,
12,
283,
1730,
356,
1402,
14,
4434,
12,
355,
283,
751,
356,
511,
63,
576,
14,
2124,
63,
751,
342,
789,
267,
666,
275,
469,
288,
283,
633,
356,
1166,
12,
288,
283,
1708,
63,
344,
356,
3260,
288,
283,
3349,
356,
283,
33,
3721,
7,
267,
789,
267,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
981,
7533,
3799,
12,
666,
9,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
1218,
1686,
3721,
2,
398,
666,
275,
469,
288,
283,
633,
356,
1166,
12,
288,
283,
1708,
63,
344,
356,
522,
459,
344,
995,
288,
283,
3349,
356,
283,
23296,
3721,
7,
267,
789,
398,
862,
26,
288,
522,
275,
664,
63,
1287,
360,
3349,
63,
981,
7533,
3799,
12,
666,
9,
267,
871,
2832,
29284,
26,
288,
702,
756,
12,
298,
11408,
2040,
922,
370,
1218,
1686,
3721,
2,
398,
372,
664,
63,
1287,
360,
2671,
63,
2384,
358,
3252,
1238,
356,
1238,
12,
283,
751,
356,
891,
1386,
791,
344,
356,
522,
459,
2671,
63,
344,
13678,
2378,
347,
511,
63,
3349,
63,
981,
63,
1633,
8,
277,
304,
267,
986,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
larrybradley/astropy
|
astropy/stats/bls/__init__.py
|
12
|
2112
|
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# The BoxLeastSquares periodogram functionality has been moved to
# astropy.timeseries.periodograms.bls. The purpose of this file is to provide backward-
# compatibility during a transition phase. We can't emit a deprecation warning
# simply on import of this module, since the classes are imported into the
# top-level astropy.stats, so instead we wrap the main class and emit a
# warning during initialization.
import warnings
from astropy.timeseries.periodograms.bls import (BoxLeastSquares as TimeseriesBoxLeastSquares,
BoxLeastSquaresResults as TimeseriesBoxLeastSquaresResults)
from astropy.utils.exceptions import AstropyDeprecationWarning
__all__ = ['BoxLeastSquares', 'BoxLeastSquaresResults']
class BoxLeastSquares(TimeseriesBoxLeastSquares):
"""
Compute the box least squares periodogram.
This class has been deprecated and will be removed in a future version.
Use `astropy.timeseries.BoxLeastSquares` instead.
"""
def __init__(self, *args, **kwargs):
warnings.warn('Importing BoxLeastSquares from astropy.stats has been '
'deprecated and will no longer be supported in future. '
'Please import this class from the astropy.timeseries '
'module instead', AstropyDeprecationWarning)
super().__init__(*args, **kwargs)
class BoxLeastSquaresResults(TimeseriesBoxLeastSquaresResults):
"""
The results of a BoxLeastSquares search.
This class has been deprecated and will be removed in a future version.
Use `astropy.timeseries.BoxLeastSquaresResults` instead.
"""
def __init__(self, *args, **kwargs):
warnings.warn('Importing BoxLeastSquaresResults from astropy.stats has been '
'deprecated and will no longer be supported in future. '
'Please import this class from the astropy.timeseries '
'module instead', AstropyDeprecationWarning)
super().__init__(*args, **kwargs)
|
bsd-3-clause
|
[
3,
3909,
1334,
282,
650,
13,
8501,
6289,
3449,
4190,
446,
1937,
5113,
14,
8332,
199,
199,
3,
710,
20783,
2553,
1810,
51,
392,
11044,
6247,
79,
1679,
9330,
965,
2757,
12155,
370,
199,
3,
28753,
14,
28551,
14,
5191,
79,
9292,
14,
66,
478,
14,
710,
12016,
402,
642,
570,
365,
370,
5647,
13388,
13,
199,
3,
7163,
5309,
282,
14116,
7669,
14,
2136,
883,
1133,
8689,
282,
17831,
5721,
199,
3,
9329,
641,
492,
402,
642,
859,
12,
3967,
314,
3992,
787,
8439,
1901,
314,
199,
3,
2746,
13,
1896,
28753,
14,
3200,
12,
880,
3140,
781,
4816,
314,
2446,
1021,
436,
8689,
282,
199,
3,
5721,
5309,
11097,
14,
199,
199,
646,
3598,
199,
199,
504,
28753,
14,
28551,
14,
5191,
79,
9292,
14,
66,
478,
492,
334,
3532,
2553,
1810,
51,
392,
11044,
465,
4703,
5602,
3532,
2553,
1810,
51,
392,
11044,
12,
1740,
20783,
2553,
1810,
51,
392,
11044,
6579,
465,
4703,
5602,
3532,
2553,
1810,
51,
392,
11044,
6579,
9,
199,
504,
28753,
14,
1208,
14,
3924,
492,
31986,
7537,
15561,
199,
199,
363,
452,
363,
275,
788,
3532,
2553,
1810,
51,
392,
11044,
297,
283,
3532,
2553,
1810,
51,
392,
11044,
6579,
418,
421,
199,
533,
20783,
2553,
1810,
51,
392,
11044,
8,
1366,
5602,
3532,
2553,
1810,
51,
392,
11044,
304,
272,
408,
272,
8354,
314,
5689,
5210,
26170,
6247,
79,
1679,
14,
339,
961,
1021,
965,
2757,
5906,
436,
911,
506,
4829,
315,
282,
6466,
1015,
14,
272,
3645,
658,
1810,
7537,
14,
28551,
14,
3532,
2553,
1810,
51,
392,
11044,
64,
3140,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
3598,
14,
4050,
360,
6295,
316,
20783,
2553,
1810,
51,
392,
11044,
687,
28753,
14,
3200,
965,
2757,
283,
1993,
283,
6667,
436,
911,
949,
8088,
506,
3748,
315,
6466,
14,
283,
1993,
283,
8254,
492,
642,
1021,
687,
314,
28753,
14,
28551,
283,
1993,
283,
578,
3140,
297,
31986,
7537,
15561,
9,
267,
1613,
11027,
826,
9308,
589,
12,
1011,
958,
9,
421,
199,
533,
20783,
2553,
1810,
51,
392,
11044,
6579,
8,
1366,
5602,
3532,
2553,
1810,
51,
392,
11044,
6579,
304,
272,
408,
272,
710,
2058,
402,
282,
20783,
2553,
1810,
51,
392,
11044,
2754,
14,
339,
961,
1021,
965,
2757,
5906,
436,
911,
506,
4829,
315,
282,
6466,
1015,
14,
272,
3645,
658,
1810,
7537,
14,
28551,
14,
3532,
2553,
1810,
51,
392,
11044,
6579,
64,
3140,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
3598,
14,
4050,
360,
6295,
316,
20783,
2553,
1810,
51,
392,
11044,
6579,
687,
28753,
14,
3200,
965,
2757,
283,
1993,
283,
6667,
436,
911,
949,
8088,
506,
3748,
315,
6466,
14,
283,
1993,
283,
8254,
492,
642,
1021,
687,
314,
28753,
14,
28551,
283,
1993,
283,
578,
3140,
297,
31986,
7537,
15561,
9,
267,
1613,
11027,
826,
9308,
589,
12,
1011,
958,
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
] |
[
3909,
1334,
282,
650,
13,
8501,
6289,
3449,
4190,
446,
1937,
5113,
14,
8332,
199,
199,
3,
710,
20783,
2553,
1810,
51,
392,
11044,
6247,
79,
1679,
9330,
965,
2757,
12155,
370,
199,
3,
28753,
14,
28551,
14,
5191,
79,
9292,
14,
66,
478,
14,
710,
12016,
402,
642,
570,
365,
370,
5647,
13388,
13,
199,
3,
7163,
5309,
282,
14116,
7669,
14,
2136,
883,
1133,
8689,
282,
17831,
5721,
199,
3,
9329,
641,
492,
402,
642,
859,
12,
3967,
314,
3992,
787,
8439,
1901,
314,
199,
3,
2746,
13,
1896,
28753,
14,
3200,
12,
880,
3140,
781,
4816,
314,
2446,
1021,
436,
8689,
282,
199,
3,
5721,
5309,
11097,
14,
199,
199,
646,
3598,
199,
199,
504,
28753,
14,
28551,
14,
5191,
79,
9292,
14,
66,
478,
492,
334,
3532,
2553,
1810,
51,
392,
11044,
465,
4703,
5602,
3532,
2553,
1810,
51,
392,
11044,
12,
1740,
20783,
2553,
1810,
51,
392,
11044,
6579,
465,
4703,
5602,
3532,
2553,
1810,
51,
392,
11044,
6579,
9,
199,
504,
28753,
14,
1208,
14,
3924,
492,
31986,
7537,
15561,
199,
199,
363,
452,
363,
275,
788,
3532,
2553,
1810,
51,
392,
11044,
297,
283,
3532,
2553,
1810,
51,
392,
11044,
6579,
418,
421,
199,
533,
20783,
2553,
1810,
51,
392,
11044,
8,
1366,
5602,
3532,
2553,
1810,
51,
392,
11044,
304,
272,
408,
272,
8354,
314,
5689,
5210,
26170,
6247,
79,
1679,
14,
339,
961,
1021,
965,
2757,
5906,
436,
911,
506,
4829,
315,
282,
6466,
1015,
14,
272,
3645,
658,
1810,
7537,
14,
28551,
14,
3532,
2553,
1810,
51,
392,
11044,
64,
3140,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
3598,
14,
4050,
360,
6295,
316,
20783,
2553,
1810,
51,
392,
11044,
687,
28753,
14,
3200,
965,
2757,
283,
1993,
283,
6667,
436,
911,
949,
8088,
506,
3748,
315,
6466,
14,
283,
1993,
283,
8254,
492,
642,
1021,
687,
314,
28753,
14,
28551,
283,
1993,
283,
578,
3140,
297,
31986,
7537,
15561,
9,
267,
1613,
11027,
826,
9308,
589,
12,
1011,
958,
9,
421,
199,
533,
20783,
2553,
1810,
51,
392,
11044,
6579,
8,
1366,
5602,
3532,
2553,
1810,
51,
392,
11044,
6579,
304,
272,
408,
272,
710,
2058,
402,
282,
20783,
2553,
1810,
51,
392,
11044,
2754,
14,
339,
961,
1021,
965,
2757,
5906,
436,
911,
506,
4829,
315,
282,
6466,
1015,
14,
272,
3645,
658,
1810,
7537,
14,
28551,
14,
3532,
2553,
1810,
51,
392,
11044,
6579,
64,
3140,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
3598,
14,
4050,
360,
6295,
316,
20783,
2553,
1810,
51,
392,
11044,
6579,
687,
28753,
14,
3200,
965,
2757,
283,
1993,
283,
6667,
436,
911,
949,
8088,
506,
3748,
315,
6466,
14,
283,
1993,
283,
8254,
492,
642,
1021,
687,
314,
28753,
14,
28551,
283,
1993,
283,
578,
3140,
297,
31986,
7537,
15561,
9,
267,
1613,
11027,
826,
9308,
589,
12,
1011,
958,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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itter. 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.
# pylint: disable=missing-docstring
import Queue
import unittest
from heron.common.src.python.utils.misc import HeronCommunicator
import heron.common.tests.python.utils.mock_generator as mock_generator
class CommunicatorTest(unittest.TestCase):
def setUp(self):
self.global_value = 6
def test_generic(self):
"""Unittest with no producer, consumer specified"""
communicator = HeronCommunicator(producer_cb=None, consumer_cb=None)
for obj in mock_generator.prim_list:
communicator.offer(obj)
for obj in mock_generator.prim_list:
self.assertEqual(obj, communicator.poll())
def test_empty(self):
communicator = HeronCommunicator(producer_cb=None, consumer_cb=None)
with self.assertRaises(Queue.Empty):
communicator.poll()
def test_producer_callback(self):
def callback():
self.global_value = 10
# test producer cb
communicator = HeronCommunicator(producer_cb=callback, consumer_cb=None)
communicator.offer("object")
self.assertEqual(self.global_value, 6)
ret = communicator.poll()
self.assertEqual(ret, "object")
self.assertEqual(self.global_value, 10)
def test_consumer_callback(self):
def callback():
self.global_value = 10
# test consumer cb
communicator = HeronCommunicator(producer_cb=None, consumer_cb=callback)
self.assertEqual(self.global_value, 6)
communicator.offer("object")
self.assertEqual(self.global_value, 10)
|
apache-2.0
|
[
3,
1898,
7800,
19259,
14,
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,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
646,
10703,
199,
646,
2882,
199,
199,
504,
14737,
265,
14,
2330,
14,
2164,
14,
1548,
14,
1208,
14,
9923,
492,
18769,
265,
27258,
707,
199,
646,
14737,
265,
14,
2330,
14,
2219,
14,
1548,
14,
1208,
14,
1805,
63,
4679,
465,
1683,
63,
4679,
199,
199,
533,
13338,
707,
774,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
14,
2966,
63,
585,
275,
1227,
819,
347,
511,
63,
6767,
8,
277,
304,
272,
408,
1358,
1770,
543,
949,
17339,
12,
9790,
2013,
624,
272,
13882,
707,
275,
18769,
265,
27258,
707,
8,
16376,
63,
2894,
29,
403,
12,
9790,
63,
2894,
29,
403,
9,
272,
367,
1559,
315,
1683,
63,
4679,
14,
31878,
63,
513,
26,
489,
13882,
707,
14,
12786,
8,
1113,
9,
339,
367,
1559,
315,
1683,
63,
4679,
14,
31878,
63,
513,
26,
489,
291,
14,
629,
8,
1113,
12,
13882,
707,
14,
6843,
1012,
819,
347,
511,
63,
1667,
8,
277,
304,
272,
13882,
707,
275,
18769,
265,
27258,
707,
8,
16376,
63,
2894,
29,
403,
12,
9790,
63,
2894,
29,
403,
9,
272,
543,
291,
14,
1855,
8,
3737,
14,
4699,
304,
489,
13882,
707,
14,
6843,
342,
819,
347,
511,
63,
16376,
63,
3058,
8,
277,
304,
272,
347,
3233,
837,
489,
291,
14,
2966,
63,
585,
275,
1616,
339,
327,
511,
17339,
7434,
272,
13882,
707,
275,
18769,
265,
27258,
707,
8,
16376,
63,
2894,
29,
3058,
12,
9790,
63,
2894,
29,
403,
9,
272,
13882,
707,
14,
12786,
480,
785,
531,
272,
291,
14,
629,
8,
277,
14,
2966,
63,
585,
12,
1227,
9,
272,
2203,
275,
13882,
707,
14,
6843,
342,
272,
291,
14,
629,
8,
3292,
12,
298,
785,
531,
272,
291,
14,
629,
8,
277,
14,
2966,
63,
585,
12,
1616,
9,
819,
347,
511,
63,
8542,
63,
3058,
8,
277,
304,
272,
347,
3233,
837,
489,
291,
14,
2966,
63,
585,
275,
1616,
339,
327,
511,
9790,
7434,
272,
13882,
707,
275,
18769,
265,
27258,
707,
8,
16376,
63,
2894,
29,
403,
12,
9790,
63,
2894,
29,
3058,
9,
272,
291,
14,
629,
8,
277,
14,
2966,
63,
585,
12,
1227,
9,
272,
13882,
707,
14,
12786,
480,
785,
531,
272,
291,
14,
629,
8,
277,
14,
2966,
63,
585,
12,
1616,
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
] |
[
1898,
7800,
19259,
14,
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,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
4287,
26,
3507,
29,
4752,
13,
12485,
199,
646,
10703,
199,
646,
2882,
199,
199,
504,
14737,
265,
14,
2330,
14,
2164,
14,
1548,
14,
1208,
14,
9923,
492,
18769,
265,
27258,
707,
199,
646,
14737,
265,
14,
2330,
14,
2219,
14,
1548,
14,
1208,
14,
1805,
63,
4679,
465,
1683,
63,
4679,
199,
199,
533,
13338,
707,
774,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
14,
2966,
63,
585,
275,
1227,
819,
347,
511,
63,
6767,
8,
277,
304,
272,
408,
1358,
1770,
543,
949,
17339,
12,
9790,
2013,
624,
272,
13882,
707,
275,
18769,
265,
27258,
707,
8,
16376,
63,
2894,
29,
403,
12,
9790,
63,
2894,
29,
403,
9,
272,
367,
1559,
315,
1683,
63,
4679,
14,
31878,
63,
513,
26,
489,
13882,
707,
14,
12786,
8,
1113,
9,
339,
367,
1559,
315,
1683,
63,
4679,
14,
31878,
63,
513,
26,
489,
291,
14,
629,
8,
1113,
12,
13882,
707,
14,
6843,
1012,
819,
347,
511,
63,
1667,
8,
277,
304,
272,
13882,
707,
275,
18769,
265,
27258,
707,
8,
16376,
63,
2894,
29,
403,
12,
9790,
63,
2894,
29,
403,
9,
272,
543,
291,
14,
1855,
8,
3737,
14,
4699,
304,
489,
13882,
707,
14,
6843,
342,
819,
347,
511,
63,
16376,
63,
3058,
8,
277,
304,
272,
347,
3233,
837,
489,
291,
14,
2966,
63,
585,
275,
1616,
339,
327,
511,
17339,
7434,
272,
13882,
707,
275,
18769,
265,
27258,
707,
8,
16376,
63,
2894,
29,
3058,
12,
9790,
63,
2894,
29,
403,
9,
272,
13882,
707,
14,
12786,
480,
785,
531,
272,
291,
14,
629,
8,
277,
14,
2966,
63,
585,
12,
1227,
9,
272,
2203,
275,
13882,
707,
14,
6843,
342,
272,
291,
14,
629,
8,
3292,
12,
298,
785,
531,
272,
291,
14,
629,
8,
277,
14,
2966,
63,
585,
12,
1616,
9,
819,
347,
511,
63,
8542,
63,
3058,
8,
277,
304,
272,
347,
3233,
837,
489,
291,
14,
2966,
63,
585,
275,
1616,
339,
327,
511,
9790,
7434,
272,
13882,
707,
275,
18769,
265,
27258,
707,
8,
16376,
63,
2894,
29,
403,
12,
9790,
63,
2894,
29,
3058,
9,
272,
291,
14,
629,
8,
277,
14,
2966,
63,
585,
12,
1227,
9,
272,
13882,
707,
14,
12786,
480,
785,
531,
272,
291,
14,
629,
8,
277,
14,
2966,
63,
585,
12,
1616,
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,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
lizzha/azure-linux-extensions
|
CustomScript/azure/http/batchclient.py
|
47
|
13769
|
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. 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 sys
import uuid
from azure import (
_update_request_uri_query,
WindowsAzureError,
WindowsAzureBatchOperationError,
_get_children_from_path,
url_unquote,
_ERROR_CANNOT_FIND_PARTITION_KEY,
_ERROR_CANNOT_FIND_ROW_KEY,
_ERROR_INCORRECT_TABLE_IN_BATCH,
_ERROR_INCORRECT_PARTITION_KEY_IN_BATCH,
_ERROR_DUPLICATE_ROW_KEY_IN_BATCH,
_ERROR_BATCH_COMMIT_FAIL,
)
from azure.http import HTTPError, HTTPRequest, HTTPResponse
from azure.http.httpclient import _HTTPClient
from azure.storage import (
_update_storage_table_header,
METADATA_NS,
_sign_storage_table_request,
)
from xml.dom import minidom
_DATASERVICES_NS = 'http://schemas.microsoft.com/ado/2007/08/dataservices'
if sys.version_info < (3,):
def _new_boundary():
return str(uuid.uuid1())
else:
def _new_boundary():
return str(uuid.uuid1()).encode('utf-8')
class _BatchClient(_HTTPClient):
'''
This is the class that is used for batch operation for storage table
service. It only supports one changeset.
'''
def __init__(self, service_instance, account_key, account_name,
protocol='http'):
_HTTPClient.__init__(self, service_instance, account_name=account_name,
account_key=account_key, protocol=protocol)
self.is_batch = False
self.batch_requests = []
self.batch_table = ''
self.batch_partition_key = ''
self.batch_row_keys = []
def get_request_table(self, request):
'''
Extracts table name from request.uri. The request.uri has either
"/mytable(...)" or "/mytable" format.
request: the request to insert, update or delete entity
'''
if '(' in request.path:
pos = request.path.find('(')
return request.path[1:pos]
else:
return request.path[1:]
def get_request_partition_key(self, request):
'''
Extracts PartitionKey from request.body if it is a POST request or from
request.path if it is not a POST request. Only insert operation request
is a POST request and the PartitionKey is in the request body.
request: the request to insert, update or delete entity
'''
if request.method == 'POST':
doc = minidom.parseString(request.body)
part_key = _get_children_from_path(
doc, 'entry', 'content', (METADATA_NS, 'properties'),
(_DATASERVICES_NS, 'PartitionKey'))
if not part_key:
raise WindowsAzureError(_ERROR_CANNOT_FIND_PARTITION_KEY)
return part_key[0].firstChild.nodeValue
else:
uri = url_unquote(request.path)
pos1 = uri.find('PartitionKey=\'')
pos2 = uri.find('\',', pos1)
if pos1 == -1 or pos2 == -1:
raise WindowsAzureError(_ERROR_CANNOT_FIND_PARTITION_KEY)
return uri[pos1 + len('PartitionKey=\''):pos2]
def get_request_row_key(self, request):
'''
Extracts RowKey from request.body if it is a POST request or from
request.path if it is not a POST request. Only insert operation request
is a POST request and the Rowkey is in the request body.
request: the request to insert, update or delete entity
'''
if request.method == 'POST':
doc = minidom.parseString(request.body)
row_key = _get_children_from_path(
doc, 'entry', 'content', (METADATA_NS, 'properties'),
(_DATASERVICES_NS, 'RowKey'))
if not row_key:
raise WindowsAzureError(_ERROR_CANNOT_FIND_ROW_KEY)
return row_key[0].firstChild.nodeValue
else:
uri = url_unquote(request.path)
pos1 = uri.find('RowKey=\'')
pos2 = uri.find('\')', pos1)
if pos1 == -1 or pos2 == -1:
raise WindowsAzureError(_ERROR_CANNOT_FIND_ROW_KEY)
row_key = uri[pos1 + len('RowKey=\''):pos2]
return row_key
def validate_request_table(self, request):
'''
Validates that all requests have the same table name. Set the table
name if it is the first request for the batch operation.
request: the request to insert, update or delete entity
'''
if self.batch_table:
if self.get_request_table(request) != self.batch_table:
raise WindowsAzureError(_ERROR_INCORRECT_TABLE_IN_BATCH)
else:
self.batch_table = self.get_request_table(request)
def validate_request_partition_key(self, request):
'''
Validates that all requests have the same PartitiionKey. Set the
PartitionKey if it is the first request for the batch operation.
request: the request to insert, update or delete entity
'''
if self.batch_partition_key:
if self.get_request_partition_key(request) != \
self.batch_partition_key:
raise WindowsAzureError(_ERROR_INCORRECT_PARTITION_KEY_IN_BATCH)
else:
self.batch_partition_key = self.get_request_partition_key(request)
def validate_request_row_key(self, request):
'''
Validates that all requests have the different RowKey and adds RowKey
to existing RowKey list.
request: the request to insert, update or delete entity
'''
if self.batch_row_keys:
if self.get_request_row_key(request) in self.batch_row_keys:
raise WindowsAzureError(_ERROR_DUPLICATE_ROW_KEY_IN_BATCH)
else:
self.batch_row_keys.append(self.get_request_row_key(request))
def begin_batch(self):
'''
Starts the batch operation. Intializes the batch variables
is_batch: batch operation flag.
batch_table: the table name of the batch operation
batch_partition_key: the PartitionKey of the batch requests.
batch_row_keys: the RowKey list of adding requests.
batch_requests: the list of the requests.
'''
self.is_batch = True
self.batch_table = ''
self.batch_partition_key = ''
self.batch_row_keys = []
self.batch_requests = []
def insert_request_to_batch(self, request):
'''
Adds request to batch operation.
request: the request to insert, update or delete entity
'''
self.validate_request_table(request)
self.validate_request_partition_key(request)
self.validate_request_row_key(request)
self.batch_requests.append(request)
def commit_batch(self):
''' Resets batch flag and commits the batch requests. '''
if self.is_batch:
self.is_batch = False
self.commit_batch_requests()
def commit_batch_requests(self):
''' Commits the batch requests. '''
batch_boundary = b'batch_' + _new_boundary()
changeset_boundary = b'changeset_' + _new_boundary()
# Commits batch only the requests list is not empty.
if self.batch_requests:
request = HTTPRequest()
request.method = 'POST'
request.host = self.batch_requests[0].host
request.path = '/$batch'
request.headers = [
('Content-Type', 'multipart/mixed; boundary=' + \
batch_boundary.decode('utf-8')),
('Accept', 'application/atom+xml,application/xml'),
('Accept-Charset', 'UTF-8')]
request.body = b'--' + batch_boundary + b'\n'
request.body += b'Content-Type: multipart/mixed; boundary='
request.body += changeset_boundary + b'\n\n'
content_id = 1
# Adds each request body to the POST data.
for batch_request in self.batch_requests:
request.body += b'--' + changeset_boundary + b'\n'
request.body += b'Content-Type: application/http\n'
request.body += b'Content-Transfer-Encoding: binary\n\n'
request.body += batch_request.method.encode('utf-8')
request.body += b' http://'
request.body += batch_request.host.encode('utf-8')
request.body += batch_request.path.encode('utf-8')
request.body += b' HTTP/1.1\n'
request.body += b'Content-ID: '
request.body += str(content_id).encode('utf-8') + b'\n'
content_id += 1
# Add different headers for different type requests.
if not batch_request.method == 'DELETE':
request.body += \
b'Content-Type: application/atom+xml;type=entry\n'
for name, value in batch_request.headers:
if name == 'If-Match':
request.body += name.encode('utf-8') + b': '
request.body += value.encode('utf-8') + b'\n'
break
request.body += b'Content-Length: '
request.body += str(len(batch_request.body)).encode('utf-8')
request.body += b'\n\n'
request.body += batch_request.body + b'\n'
else:
for name, value in batch_request.headers:
# If-Match should be already included in
# batch_request.headers, but in case it is missing,
# just add it.
if name == 'If-Match':
request.body += name.encode('utf-8') + b': '
request.body += value.encode('utf-8') + b'\n\n'
break
else:
request.body += b'If-Match: *\n\n'
request.body += b'--' + changeset_boundary + b'--' + b'\n'
request.body += b'--' + batch_boundary + b'--'
request.path, request.query = _update_request_uri_query(request)
request.headers = _update_storage_table_header(request)
auth = _sign_storage_table_request(request,
self.account_name,
self.account_key)
request.headers.append(('Authorization', auth))
# Submit the whole request as batch request.
response = self.perform_request(request)
if response.status >= 300:
raise HTTPError(response.status,
_ERROR_BATCH_COMMIT_FAIL,
self.respheader,
response.body)
# http://www.odata.org/documentation/odata-version-2-0/batch-processing/
# The body of a ChangeSet response is either a response for all the
# successfully processed change request within the ChangeSet,
# formatted exactly as it would have appeared outside of a batch,
# or a single response indicating a failure of the entire ChangeSet.
responses = self._parse_batch_response(response.body)
if responses and responses[0].status >= 300:
self._report_batch_error(responses[0])
def cancel_batch(self):
''' Resets the batch flag. '''
self.is_batch = False
def _parse_batch_response(self, body):
parts = body.split(b'--changesetresponse_')
responses = []
for part in parts:
httpLocation = part.find(b'HTTP/')
if httpLocation > 0:
response = self._parse_batch_response_part(part[httpLocation:])
responses.append(response)
return responses
def _parse_batch_response_part(self, part):
lines = part.splitlines();
# First line is the HTTP status/reason
status, _, reason = lines[0].partition(b' ')[2].partition(b' ')
# Followed by headers and body
headers = []
body = b''
isBody = False
for line in lines[1:]:
if line == b'' and not isBody:
isBody = True
elif isBody:
body += line
else:
headerName, _, headerVal = line.partition(b':')
headers.append((headerName.lower(), headerVal))
return HTTPResponse(int(status), reason.strip(), headers, body)
def _report_batch_error(self, response):
xml = response.body.decode('utf-8')
doc = minidom.parseString(xml)
n = _get_children_from_path(doc, (METADATA_NS, 'error'), 'code')
code = n[0].firstChild.nodeValue if n and n[0].firstChild else ''
n = _get_children_from_path(doc, (METADATA_NS, 'error'), 'message')
message = n[0].firstChild.nodeValue if n and n[0].firstChild else xml
raise WindowsAzureBatchOperationError(message, code)
|
apache-2.0
|
[
25812,
199,
3,
1898,
334,
67,
9,
15332,
14,
221,
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,
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,
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,
7656,
9460,
199,
646,
984,
199,
646,
5377,
199,
199,
504,
13601,
492,
334,
272,
485,
873,
63,
1069,
63,
2302,
63,
1131,
12,
272,
5417,
22386,
547,
12,
272,
5417,
22386,
8842,
3632,
5263,
12,
272,
485,
362,
63,
3223,
63,
504,
63,
515,
12,
272,
1166,
63,
12240,
12,
272,
485,
3170,
63,
18988,
4609,
63,
27087,
63,
30407,
63,
3078,
12,
272,
485,
3170,
63,
18988,
4609,
63,
27087,
63,
11415,
63,
3078,
12,
272,
485,
3170,
63,
568,
31704,
63,
8723,
63,
568,
63,
20813,
12,
272,
485,
3170,
63,
568,
31704,
63,
30407,
63,
3078,
63,
568,
63,
20813,
12,
272,
485,
3170,
63,
24099,
2507,
1951,
63,
11415,
63,
3078,
63,
568,
63,
20813,
12,
272,
485,
3170,
63,
20813,
63,
23446,
63,
8784,
12,
272,
776,
199,
504,
13601,
14,
1014,
492,
15050,
12,
3101,
2017,
12,
29034,
199,
504,
13601,
14,
1014,
14,
1014,
1258,
492,
485,
27757,
199,
504,
13601,
14,
3494,
492,
334,
272,
485,
873,
63,
3494,
63,
1224,
63,
1291,
12,
272,
19357,
8071,
63,
2709,
12,
272,
485,
1037,
63,
3494,
63,
1224,
63,
1069,
12,
272,
776,
199,
504,
2748,
14,
4556,
492,
19165,
199,
199,
63,
28231,
540,
8670,
63,
2709,
275,
283,
1014,
921,
9482,
14,
17040,
14,
957,
15,
5129,
15,
9488,
15,
2036,
15,
576,
5950,
7,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
16095,
272,
347,
485,
1222,
63,
9891,
837,
267,
372,
620,
8,
2580,
14,
2580,
17,
1012,
199,
2836,
26,
272,
347,
485,
1222,
63,
9891,
837,
267,
372,
620,
8,
2580,
14,
2580,
17,
8801,
2143,
360,
1624,
13,
24,
358,
421,
199,
533,
485,
8842,
3041,
1547,
27757,
304,
339,
1449,
272,
961,
365,
314,
1021,
626,
365,
1202,
367,
3522,
3439,
367,
4887,
1817,
272,
2435,
14,
2779,
1454,
5171,
1373,
23316,
14,
272,
1449,
339,
347,
636,
826,
721,
277,
12,
2435,
63,
842,
12,
2933,
63,
498,
12,
2933,
63,
354,
12,
326,
4113,
534,
1014,
735,
267,
485,
27757,
855,
826,
721,
277,
12,
2435,
63,
842,
12,
2933,
63,
354,
29,
2048,
63,
354,
12,
2490,
2933,
63,
498,
29,
2048,
63,
498,
12,
4113,
29,
3922,
9,
267,
291,
14,
374,
63,
2912,
275,
756,
267,
291,
14,
2912,
63,
6615,
275,
942,
267,
291,
14,
2912,
63,
1224,
275,
2125,
267,
291,
14,
2912,
63,
5312,
63,
498,
275,
2125,
267,
291,
14,
2912,
63,
1143,
63,
1612,
275,
942,
339,
347,
664,
63,
1069,
63,
1224,
8,
277,
12,
1056,
304,
267,
1449,
267,
12892,
83,
1817,
536,
687,
1056,
14,
2302,
14,
710,
1056,
14,
2302,
965,
1902,
267,
3286,
1662,
1224,
29195,
2924,
503,
3286,
1662,
1224,
2,
1475,
14,
398,
1056,
26,
314,
1056,
370,
5518,
12,
1678,
503,
3145,
4642,
267,
1449,
267,
340,
16746,
315,
1056,
14,
515,
26,
288,
2086,
275,
1056,
14,
515,
14,
1623,
14097,
358,
288,
372,
1056,
14,
515,
59,
17,
26,
1712,
61,
267,
587,
26,
288,
372,
1056,
14,
515,
59,
17,
2938,
339,
347,
664,
63,
1069,
63,
5312,
63,
498,
8,
277,
12,
1056,
304,
267,
1449,
267,
12892,
83,
27353,
1197,
687,
1056,
14,
2030,
340,
652,
365,
282,
8761,
1056,
503,
687,
267,
1056,
14,
515,
340,
652,
365,
440,
282,
8761,
1056,
14,
5972,
5518,
3439,
1056,
267,
365,
282,
8761,
1056,
436,
314,
27353,
1197,
365,
315,
314,
1056,
2396,
14,
398,
1056,
26,
314,
1056,
370,
5518,
12,
1678,
503,
3145,
4642,
267,
1449,
267,
340,
1056,
14,
765,
508,
283,
4030,
356,
288,
1382,
275,
19165,
14,
14934,
8,
1069,
14,
2030,
9,
288,
1777,
63,
498,
275,
485,
362,
63,
3223,
63,
504,
63,
515,
8,
355,
1382,
12,
283,
2373,
297,
283,
1317,
297,
334,
8314,
63,
2709,
12,
283,
3282,
659,
355,
6110,
28231,
540,
8670,
63,
2709,
12,
283,
13068,
1197,
1333,
288,
340,
440,
1777,
63,
498,
26,
355,
746,
5417,
22386,
547,
1547,
3170,
63,
18988,
4609,
63,
27087,
63,
30407,
63,
3078,
9,
288,
372,
1777,
63,
498,
59,
16,
1055,
22262,
14,
17240,
267,
587,
26,
288,
5108,
275,
1166,
63,
12240,
8,
1069,
14,
515,
9,
288,
2086,
17,
275,
5108,
14,
1623,
360,
13068,
1197,
25641,
358,
288,
2086,
18,
275,
5108,
14,
1623,
2258,
23324,
2086,
17,
9,
288,
340,
2086,
17,
508,
446,
17,
503,
2086,
18,
508,
446,
17,
26,
355,
746,
5417,
22386,
547,
1547,
3170,
63,
18988,
4609,
63,
27087,
63,
30407,
63,
3078,
9,
288,
372,
5108,
59,
1712,
17,
435,
822,
360,
13068,
1197,
25641,
735,
1712,
18,
61,
339,
347,
664,
63,
1069,
63,
1143,
63,
498,
8,
277,
12,
1056,
304,
267,
1449,
267,
12892,
83,
15231,
1197,
687,
1056,
14,
2030,
340,
652,
365,
282,
8761,
1056,
503,
687,
267,
1056,
14,
515,
340,
652,
365,
440,
282,
8761,
1056,
14,
5972,
5518,
3439,
1056,
267,
365,
282,
8761,
1056,
436,
314,
15231,
498,
365,
315,
314,
1056,
2396,
14,
398,
1056,
26,
314,
1056,
370,
5518,
12,
1678,
503,
3145,
4642,
267,
1449,
267,
340,
1056,
14,
765,
508,
283,
4030,
356,
288,
1382,
275,
19165,
14,
14934,
8,
1069,
14,
2030,
9,
288,
1962,
63,
498,
275,
485,
362,
63,
3223,
63
] |
[
199,
3,
1898,
334,
67,
9,
15332,
14,
221,
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,
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,
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,
7656,
9460,
199,
646,
984,
199,
646,
5377,
199,
199,
504,
13601,
492,
334,
272,
485,
873,
63,
1069,
63,
2302,
63,
1131,
12,
272,
5417,
22386,
547,
12,
272,
5417,
22386,
8842,
3632,
5263,
12,
272,
485,
362,
63,
3223,
63,
504,
63,
515,
12,
272,
1166,
63,
12240,
12,
272,
485,
3170,
63,
18988,
4609,
63,
27087,
63,
30407,
63,
3078,
12,
272,
485,
3170,
63,
18988,
4609,
63,
27087,
63,
11415,
63,
3078,
12,
272,
485,
3170,
63,
568,
31704,
63,
8723,
63,
568,
63,
20813,
12,
272,
485,
3170,
63,
568,
31704,
63,
30407,
63,
3078,
63,
568,
63,
20813,
12,
272,
485,
3170,
63,
24099,
2507,
1951,
63,
11415,
63,
3078,
63,
568,
63,
20813,
12,
272,
485,
3170,
63,
20813,
63,
23446,
63,
8784,
12,
272,
776,
199,
504,
13601,
14,
1014,
492,
15050,
12,
3101,
2017,
12,
29034,
199,
504,
13601,
14,
1014,
14,
1014,
1258,
492,
485,
27757,
199,
504,
13601,
14,
3494,
492,
334,
272,
485,
873,
63,
3494,
63,
1224,
63,
1291,
12,
272,
19357,
8071,
63,
2709,
12,
272,
485,
1037,
63,
3494,
63,
1224,
63,
1069,
12,
272,
776,
199,
504,
2748,
14,
4556,
492,
19165,
199,
199,
63,
28231,
540,
8670,
63,
2709,
275,
283,
1014,
921,
9482,
14,
17040,
14,
957,
15,
5129,
15,
9488,
15,
2036,
15,
576,
5950,
7,
199,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
16095,
272,
347,
485,
1222,
63,
9891,
837,
267,
372,
620,
8,
2580,
14,
2580,
17,
1012,
199,
2836,
26,
272,
347,
485,
1222,
63,
9891,
837,
267,
372,
620,
8,
2580,
14,
2580,
17,
8801,
2143,
360,
1624,
13,
24,
358,
421,
199,
533,
485,
8842,
3041,
1547,
27757,
304,
339,
1449,
272,
961,
365,
314,
1021,
626,
365,
1202,
367,
3522,
3439,
367,
4887,
1817,
272,
2435,
14,
2779,
1454,
5171,
1373,
23316,
14,
272,
1449,
339,
347,
636,
826,
721,
277,
12,
2435,
63,
842,
12,
2933,
63,
498,
12,
2933,
63,
354,
12,
326,
4113,
534,
1014,
735,
267,
485,
27757,
855,
826,
721,
277,
12,
2435,
63,
842,
12,
2933,
63,
354,
29,
2048,
63,
354,
12,
2490,
2933,
63,
498,
29,
2048,
63,
498,
12,
4113,
29,
3922,
9,
267,
291,
14,
374,
63,
2912,
275,
756,
267,
291,
14,
2912,
63,
6615,
275,
942,
267,
291,
14,
2912,
63,
1224,
275,
2125,
267,
291,
14,
2912,
63,
5312,
63,
498,
275,
2125,
267,
291,
14,
2912,
63,
1143,
63,
1612,
275,
942,
339,
347,
664,
63,
1069,
63,
1224,
8,
277,
12,
1056,
304,
267,
1449,
267,
12892,
83,
1817,
536,
687,
1056,
14,
2302,
14,
710,
1056,
14,
2302,
965,
1902,
267,
3286,
1662,
1224,
29195,
2924,
503,
3286,
1662,
1224,
2,
1475,
14,
398,
1056,
26,
314,
1056,
370,
5518,
12,
1678,
503,
3145,
4642,
267,
1449,
267,
340,
16746,
315,
1056,
14,
515,
26,
288,
2086,
275,
1056,
14,
515,
14,
1623,
14097,
358,
288,
372,
1056,
14,
515,
59,
17,
26,
1712,
61,
267,
587,
26,
288,
372,
1056,
14,
515,
59,
17,
2938,
339,
347,
664,
63,
1069,
63,
5312,
63,
498,
8,
277,
12,
1056,
304,
267,
1449,
267,
12892,
83,
27353,
1197,
687,
1056,
14,
2030,
340,
652,
365,
282,
8761,
1056,
503,
687,
267,
1056,
14,
515,
340,
652,
365,
440,
282,
8761,
1056,
14,
5972,
5518,
3439,
1056,
267,
365,
282,
8761,
1056,
436,
314,
27353,
1197,
365,
315,
314,
1056,
2396,
14,
398,
1056,
26,
314,
1056,
370,
5518,
12,
1678,
503,
3145,
4642,
267,
1449,
267,
340,
1056,
14,
765,
508,
283,
4030,
356,
288,
1382,
275,
19165,
14,
14934,
8,
1069,
14,
2030,
9,
288,
1777,
63,
498,
275,
485,
362,
63,
3223,
63,
504,
63,
515,
8,
355,
1382,
12,
283,
2373,
297,
283,
1317,
297,
334,
8314,
63,
2709,
12,
283,
3282,
659,
355,
6110,
28231,
540,
8670,
63,
2709,
12,
283,
13068,
1197,
1333,
288,
340,
440,
1777,
63,
498,
26,
355,
746,
5417,
22386,
547,
1547,
3170,
63,
18988,
4609,
63,
27087,
63,
30407,
63,
3078,
9,
288,
372,
1777,
63,
498,
59,
16,
1055,
22262,
14,
17240,
267,
587,
26,
288,
5108,
275,
1166,
63,
12240,
8,
1069,
14,
515,
9,
288,
2086,
17,
275,
5108,
14,
1623,
360,
13068,
1197,
25641,
358,
288,
2086,
18,
275,
5108,
14,
1623,
2258,
23324,
2086,
17,
9,
288,
340,
2086,
17,
508,
446,
17,
503,
2086,
18,
508,
446,
17,
26,
355,
746,
5417,
22386,
547,
1547,
3170,
63,
18988,
4609,
63,
27087,
63,
30407,
63,
3078,
9,
288,
372,
5108,
59,
1712,
17,
435,
822,
360,
13068,
1197,
25641,
735,
1712,
18,
61,
339,
347,
664,
63,
1069,
63,
1143,
63,
498,
8,
277,
12,
1056,
304,
267,
1449,
267,
12892,
83,
15231,
1197,
687,
1056,
14,
2030,
340,
652,
365,
282,
8761,
1056,
503,
687,
267,
1056,
14,
515,
340,
652,
365,
440,
282,
8761,
1056,
14,
5972,
5518,
3439,
1056,
267,
365,
282,
8761,
1056,
436,
314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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kenshay/ImageScripter
|
ProgramData/SystemFiles/Python/Lib/site-packages/wheel/egg2wheel.py
|
471
|
2633
|
#!/usr/bin/env python
import os.path
import re
import sys
import tempfile
import zipfile
import wheel.bdist_wheel
import shutil
import distutils.dist
from distutils.archive_util import make_archive
from argparse import ArgumentParser
from glob import iglob
egg_info_re = re.compile(r'''(?P<name>.+?)-(?P<ver>.+?)
(-(?P<pyver>.+?))?(-(?P<arch>.+?))?.egg''', re.VERBOSE)
def egg2wheel(egg_path, dest_dir):
egg_info = egg_info_re.match(os.path.basename(egg_path)).groupdict()
dir = tempfile.mkdtemp(suffix="_e2w")
if os.path.isfile(egg_path):
# assume we have a bdist_egg otherwise
egg = zipfile.ZipFile(egg_path)
egg.extractall(dir)
else:
# support buildout-style installed eggs directories
for pth in os.listdir(egg_path):
src = os.path.join(egg_path, pth)
if os.path.isfile(src):
shutil.copy2(src, dir)
else:
shutil.copytree(src, os.path.join(dir, pth))
dist_info = "%s-%s" % (egg_info['name'], egg_info['ver'])
abi = 'none'
pyver = egg_info['pyver'].replace('.', '')
arch = (egg_info['arch'] or 'any').replace('.', '_').replace('-', '_')
if arch != 'any':
# assume all binary eggs are for CPython
pyver = 'cp' + pyver[2:]
wheel_name = '-'.join((
dist_info,
pyver,
abi,
arch
))
bw = wheel.bdist_wheel.bdist_wheel(distutils.dist.Distribution())
bw.root_is_purelib = egg_info['arch'] is None
dist_info_dir = os.path.join(dir, '%s.dist-info' % dist_info)
bw.egg2dist(os.path.join(dir, 'EGG-INFO'),
dist_info_dir)
bw.write_wheelfile(dist_info_dir, generator='egg2wheel')
bw.write_record(dir, dist_info_dir)
filename = make_archive(os.path.join(dest_dir, wheel_name), 'zip', root_dir=dir)
os.rename(filename, filename[:-3] + 'whl')
shutil.rmtree(dir)
def main():
parser = ArgumentParser()
parser.add_argument('eggs', nargs='*', help="Eggs to convert")
parser.add_argument('--dest-dir', '-d', default=os.path.curdir,
help="Directory to store wheels (default %(default)s)")
parser.add_argument('--verbose', '-v', action='store_true')
args = parser.parse_args()
for pat in args.eggs:
for egg in iglob(pat):
if args.verbose:
sys.stdout.write("{0}... ".format(egg))
egg2wheel(egg, args.dest_dir)
if args.verbose:
sys.stdout.write("OK\n")
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
984,
199,
646,
5549,
199,
646,
10392,
199,
646,
9989,
14,
17403,
63,
11798,
199,
646,
5145,
199,
646,
7065,
14,
2686,
199,
504,
7065,
14,
6404,
63,
1974,
492,
1852,
63,
6404,
199,
504,
7534,
492,
27615,
199,
504,
5739,
492,
284,
6463,
199,
199,
5799,
63,
815,
63,
264,
275,
295,
14,
2014,
8,
82,
2344,
2229,
48,
28,
354,
29587,
7216,
2229,
48,
28,
422,
29587,
9,
272,
5868,
2229,
48,
28,
29686,
29587,
22119,
2801,
2229,
48,
28,
1047,
29587,
22119,
14,
5799,
18108,
295,
14,
16075,
9,
199,
199,
318,
11393,
18,
11798,
8,
5799,
63,
515,
12,
2053,
63,
694,
304,
272,
11393,
63,
815,
275,
11393,
63,
815,
63,
264,
14,
1431,
8,
736,
14,
515,
14,
4846,
8,
5799,
63,
515,
4992,
20567,
342,
272,
2935,
275,
5549,
14,
11983,
8,
4511,
19667,
69,
18,
87,
531,
272,
340,
747,
14,
515,
14,
6292,
8,
5799,
63,
515,
304,
267,
327,
5534,
781,
1172,
282,
26308,
63,
5799,
4257,
267,
11393,
275,
10392,
14,
15016,
8,
5799,
63,
515,
9,
267,
11393,
14,
5005,
452,
8,
694,
9,
272,
587,
26,
267,
327,
2291,
1900,
548,
13,
2487,
4903,
22151,
6602,
267,
367,
25504,
315,
747,
14,
7374,
8,
5799,
63,
515,
304,
288,
2928,
275,
747,
14,
515,
14,
904,
8,
5799,
63,
515,
12,
25504,
9,
288,
340,
747,
14,
515,
14,
6292,
8,
2164,
304,
355,
5145,
14,
1574,
18,
8,
2164,
12,
2935,
9,
288,
587,
26,
355,
5145,
14,
29296,
8,
2164,
12,
747,
14,
515,
14,
904,
8,
694,
12,
25504,
430,
339,
2917,
63,
815,
275,
2071,
83,
3295,
83,
2,
450,
334,
5799,
63,
815,
459,
354,
995,
11393,
63,
815,
459,
422,
1105,
272,
25570,
275,
283,
3592,
7,
272,
1134,
422,
275,
11393,
63,
815,
459,
29686,
2278,
1814,
14078,
4074,
272,
3819,
275,
334,
5799,
63,
815,
459,
1047,
418,
503,
283,
1629,
1959,
1814,
14078,
2513,
1959,
1814,
13858,
18962,
272,
340,
3819,
1137,
283,
1629,
356,
267,
327,
5534,
1006,
3366,
22151,
787,
367,
25654,
267,
1134,
422,
275,
283,
1850,
7,
435,
1134,
422,
59,
18,
2938,
272,
9989,
63,
354,
275,
2475,
1370,
904,
1332,
2079,
2917,
63,
815,
12,
2079,
1134,
422,
12,
2079,
25570,
12,
2079,
3819,
2079,
5082,
272,
21028,
275,
9989,
14,
17403,
63,
11798,
14,
17403,
63,
11798,
8,
13350,
14,
2686,
14,
8580,
1012,
272,
21028,
14,
1231,
63,
374,
63,
31882,
275,
11393,
63,
815,
459,
1047,
418,
365,
488,
272,
2917,
63,
815,
63,
694,
275,
747,
14,
515,
14,
904,
8,
694,
12,
1543,
83,
14,
2686,
13,
815,
7,
450,
2917,
63,
815,
9,
272,
21028,
14,
5799,
18,
2686,
8,
736,
14,
515,
14,
904,
8,
694,
12,
283,
30124,
13,
4531,
659,
355,
2917,
63,
815,
63,
694,
9,
272,
21028,
14,
952,
63,
87,
26824,
12059,
8,
2686,
63,
815,
63,
694,
12,
4306,
534,
5799,
18,
11798,
358,
272,
21028,
14,
952,
63,
3059,
8,
694,
12,
2917,
63,
815,
63,
694,
9,
272,
1788,
275,
1852,
63,
6404,
8,
736,
14,
515,
14,
904,
8,
2614,
63,
694,
12,
9989,
63,
354,
395,
283,
3065,
297,
1738,
63,
694,
29,
694,
9,
272,
747,
14,
8165,
8,
1501,
12,
1788,
4439,
19,
61,
435,
283,
2191,
76,
358,
272,
5145,
14,
9242,
8,
694,
9,
199,
199,
318,
2446,
837,
272,
1798,
275,
27615,
342,
272,
1798,
14,
525,
63,
2094,
360,
14488,
297,
9237,
534,
7693,
1720,
628,
29496,
458,
370,
3957,
531,
272,
1798,
14,
525,
63,
2094,
4517,
2614,
13,
694,
297,
2475,
68,
297,
849,
29,
736,
14,
515,
14,
15594,
12,
288,
1720,
628,
6231,
370,
3877,
28300,
334,
885,
2818,
885,
9,
83,
6320,
272,
1798,
14,
525,
63,
2094,
4517,
3832,
297,
2475,
86,
297,
1595,
534,
1617,
63,
2052,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
367,
12713,
315,
1249,
14,
14488,
26,
267,
367,
11393,
315,
284,
6463,
8,
10853,
304,
288,
340,
1249,
14,
3832,
26,
355,
984,
14,
2703,
14,
952,
13076,
16,
93,
1396,
3680,
908,
8,
5799,
430,
288,
11393,
18,
11798,
8,
5799,
12,
1249,
14,
2614,
63,
694,
9,
288,
340,
1249,
14,
3832,
26,
355,
984,
14,
2703,
14,
952,
480,
3593,
60,
78,
531,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
984,
199,
646,
5549,
199,
646,
10392,
199,
646,
9989,
14,
17403,
63,
11798,
199,
646,
5145,
199,
646,
7065,
14,
2686,
199,
504,
7065,
14,
6404,
63,
1974,
492,
1852,
63,
6404,
199,
504,
7534,
492,
27615,
199,
504,
5739,
492,
284,
6463,
199,
199,
5799,
63,
815,
63,
264,
275,
295,
14,
2014,
8,
82,
2344,
2229,
48,
28,
354,
29587,
7216,
2229,
48,
28,
422,
29587,
9,
272,
5868,
2229,
48,
28,
29686,
29587,
22119,
2801,
2229,
48,
28,
1047,
29587,
22119,
14,
5799,
18108,
295,
14,
16075,
9,
199,
199,
318,
11393,
18,
11798,
8,
5799,
63,
515,
12,
2053,
63,
694,
304,
272,
11393,
63,
815,
275,
11393,
63,
815,
63,
264,
14,
1431,
8,
736,
14,
515,
14,
4846,
8,
5799,
63,
515,
4992,
20567,
342,
272,
2935,
275,
5549,
14,
11983,
8,
4511,
19667,
69,
18,
87,
531,
272,
340,
747,
14,
515,
14,
6292,
8,
5799,
63,
515,
304,
267,
327,
5534,
781,
1172,
282,
26308,
63,
5799,
4257,
267,
11393,
275,
10392,
14,
15016,
8,
5799,
63,
515,
9,
267,
11393,
14,
5005,
452,
8,
694,
9,
272,
587,
26,
267,
327,
2291,
1900,
548,
13,
2487,
4903,
22151,
6602,
267,
367,
25504,
315,
747,
14,
7374,
8,
5799,
63,
515,
304,
288,
2928,
275,
747,
14,
515,
14,
904,
8,
5799,
63,
515,
12,
25504,
9,
288,
340,
747,
14,
515,
14,
6292,
8,
2164,
304,
355,
5145,
14,
1574,
18,
8,
2164,
12,
2935,
9,
288,
587,
26,
355,
5145,
14,
29296,
8,
2164,
12,
747,
14,
515,
14,
904,
8,
694,
12,
25504,
430,
339,
2917,
63,
815,
275,
2071,
83,
3295,
83,
2,
450,
334,
5799,
63,
815,
459,
354,
995,
11393,
63,
815,
459,
422,
1105,
272,
25570,
275,
283,
3592,
7,
272,
1134,
422,
275,
11393,
63,
815,
459,
29686,
2278,
1814,
14078,
4074,
272,
3819,
275,
334,
5799,
63,
815,
459,
1047,
418,
503,
283,
1629,
1959,
1814,
14078,
2513,
1959,
1814,
13858,
18962,
272,
340,
3819,
1137,
283,
1629,
356,
267,
327,
5534,
1006,
3366,
22151,
787,
367,
25654,
267,
1134,
422,
275,
283,
1850,
7,
435,
1134,
422,
59,
18,
2938,
272,
9989,
63,
354,
275,
2475,
1370,
904,
1332,
2079,
2917,
63,
815,
12,
2079,
1134,
422,
12,
2079,
25570,
12,
2079,
3819,
2079,
5082,
272,
21028,
275,
9989,
14,
17403,
63,
11798,
14,
17403,
63,
11798,
8,
13350,
14,
2686,
14,
8580,
1012,
272,
21028,
14,
1231,
63,
374,
63,
31882,
275,
11393,
63,
815,
459,
1047,
418,
365,
488,
272,
2917,
63,
815,
63,
694,
275,
747,
14,
515,
14,
904,
8,
694,
12,
1543,
83,
14,
2686,
13,
815,
7,
450,
2917,
63,
815,
9,
272,
21028,
14,
5799,
18,
2686,
8,
736,
14,
515,
14,
904,
8,
694,
12,
283,
30124,
13,
4531,
659,
355,
2917,
63,
815,
63,
694,
9,
272,
21028,
14,
952,
63,
87,
26824,
12059,
8,
2686,
63,
815,
63,
694,
12,
4306,
534,
5799,
18,
11798,
358,
272,
21028,
14,
952,
63,
3059,
8,
694,
12,
2917,
63,
815,
63,
694,
9,
272,
1788,
275,
1852,
63,
6404,
8,
736,
14,
515,
14,
904,
8,
2614,
63,
694,
12,
9989,
63,
354,
395,
283,
3065,
297,
1738,
63,
694,
29,
694,
9,
272,
747,
14,
8165,
8,
1501,
12,
1788,
4439,
19,
61,
435,
283,
2191,
76,
358,
272,
5145,
14,
9242,
8,
694,
9,
199,
199,
318,
2446,
837,
272,
1798,
275,
27615,
342,
272,
1798,
14,
525,
63,
2094,
360,
14488,
297,
9237,
534,
7693,
1720,
628,
29496,
458,
370,
3957,
531,
272,
1798,
14,
525,
63,
2094,
4517,
2614,
13,
694,
297,
2475,
68,
297,
849,
29,
736,
14,
515,
14,
15594,
12,
288,
1720,
628,
6231,
370,
3877,
28300,
334,
885,
2818,
885,
9,
83,
6320,
272,
1798,
14,
525,
63,
2094,
4517,
3832,
297,
2475,
86,
297,
1595,
534,
1617,
63,
2052,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
367,
12713,
315,
1249,
14,
14488,
26,
267,
367,
11393,
315,
284,
6463,
8,
10853,
304,
288,
340,
1249,
14,
3832,
26,
355,
984,
14,
2703,
14,
952,
13076,
16,
93,
1396,
3680,
908,
8,
5799,
430,
288,
11393,
18,
11798,
8,
5799,
12,
1249,
14,
2614,
63,
694,
9,
288,
340,
1249,
14,
3832,
26,
355,
984,
14,
2703,
14,
952,
480,
3593,
60,
78,
531,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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