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
|
|---|---|---|---|---|---|---|---|---|
batermj/algorithm-challenger
|
code-analysis/programming_anguage/python/source_codes/Python3.8.0/Python-3.8.0/Lib/test/test_asyncio/test_unix_events.py
|
1
|
67821
|
"""Tests for unix_events.py."""
import collections
import contextlib
import errno
import io
import os
import pathlib
import signal
import socket
import stat
import sys
import tempfile
import threading
import unittest
from unittest import mock
from test import support
if sys.platform == 'win32':
raise unittest.SkipTest('UNIX only')
import asyncio
from asyncio import log
from asyncio import unix_events
from test.test_asyncio import utils as test_utils
MOCK_ANY = mock.ANY
def tearDownModule():
asyncio.set_event_loop_policy(None)
def close_pipe_transport(transport):
# Don't call transport.close() because the event loop and the selector
# are mocked
if transport._pipe is None:
return
transport._pipe.close()
transport._pipe = None
@unittest.skipUnless(signal, 'Signals are not supported')
class SelectorEventLoopSignalTests(test_utils.TestCase):
def setUp(self):
super().setUp()
self.loop = asyncio.SelectorEventLoop()
self.set_event_loop(self.loop)
def test_check_signal(self):
self.assertRaises(
TypeError, self.loop._check_signal, '1')
self.assertRaises(
ValueError, self.loop._check_signal, signal.NSIG + 1)
def test_handle_signal_no_handler(self):
self.loop._handle_signal(signal.NSIG + 1)
def test_handle_signal_cancelled_handler(self):
h = asyncio.Handle(mock.Mock(), (),
loop=mock.Mock())
h.cancel()
self.loop._signal_handlers[signal.NSIG + 1] = h
self.loop.remove_signal_handler = mock.Mock()
self.loop._handle_signal(signal.NSIG + 1)
self.loop.remove_signal_handler.assert_called_with(signal.NSIG + 1)
@mock.patch('asyncio.unix_events.signal')
def test_add_signal_handler_setup_error(self, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
m_signal.set_wakeup_fd.side_effect = ValueError
self.assertRaises(
RuntimeError,
self.loop.add_signal_handler,
signal.SIGINT, lambda: True)
@mock.patch('asyncio.unix_events.signal')
def test_add_signal_handler_coroutine_error(self, m_signal):
m_signal.NSIG = signal.NSIG
async def simple_coroutine():
pass
# callback must not be a coroutine function
coro_func = simple_coroutine
coro_obj = coro_func()
self.addCleanup(coro_obj.close)
for func in (coro_func, coro_obj):
self.assertRaisesRegex(
TypeError, 'coroutines cannot be used with add_signal_handler',
self.loop.add_signal_handler,
signal.SIGINT, func)
@mock.patch('asyncio.unix_events.signal')
def test_add_signal_handler(self, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
cb = lambda: True
self.loop.add_signal_handler(signal.SIGHUP, cb)
h = self.loop._signal_handlers.get(signal.SIGHUP)
self.assertIsInstance(h, asyncio.Handle)
self.assertEqual(h._callback, cb)
@mock.patch('asyncio.unix_events.signal')
def test_add_signal_handler_install_error(self, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
def set_wakeup_fd(fd):
if fd == -1:
raise ValueError()
m_signal.set_wakeup_fd = set_wakeup_fd
class Err(OSError):
errno = errno.EFAULT
m_signal.signal.side_effect = Err
self.assertRaises(
Err,
self.loop.add_signal_handler,
signal.SIGINT, lambda: True)
@mock.patch('asyncio.unix_events.signal')
@mock.patch('asyncio.base_events.logger')
def test_add_signal_handler_install_error2(self, m_logging, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
class Err(OSError):
errno = errno.EINVAL
m_signal.signal.side_effect = Err
self.loop._signal_handlers[signal.SIGHUP] = lambda: True
self.assertRaises(
RuntimeError,
self.loop.add_signal_handler,
signal.SIGINT, lambda: True)
self.assertFalse(m_logging.info.called)
self.assertEqual(1, m_signal.set_wakeup_fd.call_count)
@mock.patch('asyncio.unix_events.signal')
@mock.patch('asyncio.base_events.logger')
def test_add_signal_handler_install_error3(self, m_logging, m_signal):
class Err(OSError):
errno = errno.EINVAL
m_signal.signal.side_effect = Err
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
self.assertRaises(
RuntimeError,
self.loop.add_signal_handler,
signal.SIGINT, lambda: True)
self.assertFalse(m_logging.info.called)
self.assertEqual(2, m_signal.set_wakeup_fd.call_count)
@mock.patch('asyncio.unix_events.signal')
def test_remove_signal_handler(self, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
self.assertTrue(
self.loop.remove_signal_handler(signal.SIGHUP))
self.assertTrue(m_signal.set_wakeup_fd.called)
self.assertTrue(m_signal.signal.called)
self.assertEqual(
(signal.SIGHUP, m_signal.SIG_DFL), m_signal.signal.call_args[0])
@mock.patch('asyncio.unix_events.signal')
def test_remove_signal_handler_2(self, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.SIGINT = signal.SIGINT
m_signal.valid_signals = signal.valid_signals
self.loop.add_signal_handler(signal.SIGINT, lambda: True)
self.loop._signal_handlers[signal.SIGHUP] = object()
m_signal.set_wakeup_fd.reset_mock()
self.assertTrue(
self.loop.remove_signal_handler(signal.SIGINT))
self.assertFalse(m_signal.set_wakeup_fd.called)
self.assertTrue(m_signal.signal.called)
self.assertEqual(
(signal.SIGINT, m_signal.default_int_handler),
m_signal.signal.call_args[0])
@mock.patch('asyncio.unix_events.signal')
@mock.patch('asyncio.base_events.logger')
def test_remove_signal_handler_cleanup_error(self, m_logging, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
m_signal.set_wakeup_fd.side_effect = ValueError
self.loop.remove_signal_handler(signal.SIGHUP)
self.assertTrue(m_logging.info)
@mock.patch('asyncio.unix_events.signal')
def test_remove_signal_handler_error(self, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
m_signal.signal.side_effect = OSError
self.assertRaises(
OSError, self.loop.remove_signal_handler, signal.SIGHUP)
@mock.patch('asyncio.unix_events.signal')
def test_remove_signal_handler_error2(self, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
class Err(OSError):
errno = errno.EINVAL
m_signal.signal.side_effect = Err
self.assertRaises(
RuntimeError, self.loop.remove_signal_handler, signal.SIGHUP)
@mock.patch('asyncio.unix_events.signal')
def test_close(self, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
self.loop.add_signal_handler(signal.SIGCHLD, lambda: True)
self.assertEqual(len(self.loop._signal_handlers), 2)
m_signal.set_wakeup_fd.reset_mock()
self.loop.close()
self.assertEqual(len(self.loop._signal_handlers), 0)
m_signal.set_wakeup_fd.assert_called_once_with(-1)
@mock.patch('asyncio.unix_events.sys')
@mock.patch('asyncio.unix_events.signal')
def test_close_on_finalizing(self, m_signal, m_sys):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals
self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
self.assertEqual(len(self.loop._signal_handlers), 1)
m_sys.is_finalizing.return_value = True
m_signal.signal.reset_mock()
with self.assertWarnsRegex(ResourceWarning,
"skipping signal handlers removal"):
self.loop.close()
self.assertEqual(len(self.loop._signal_handlers), 0)
self.assertFalse(m_signal.signal.called)
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'),
'UNIX Sockets are not supported')
class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
def setUp(self):
super().setUp()
self.loop = asyncio.SelectorEventLoop()
self.set_event_loop(self.loop)
@support.skip_unless_bind_unix_socket
def test_create_unix_server_existing_path_sock(self):
with test_utils.unix_socket_path() as path:
sock = socket.socket(socket.AF_UNIX)
sock.bind(path)
sock.listen(1)
sock.close()
coro = self.loop.create_unix_server(lambda: None, path)
srv = self.loop.run_until_complete(coro)
srv.close()
self.loop.run_until_complete(srv.wait_closed())
@support.skip_unless_bind_unix_socket
def test_create_unix_server_pathlib(self):
with test_utils.unix_socket_path() as path:
path = pathlib.Path(path)
srv_coro = self.loop.create_unix_server(lambda: None, path)
srv = self.loop.run_until_complete(srv_coro)
srv.close()
self.loop.run_until_complete(srv.wait_closed())
def test_create_unix_connection_pathlib(self):
with test_utils.unix_socket_path() as path:
path = pathlib.Path(path)
coro = self.loop.create_unix_connection(lambda: None, path)
with self.assertRaises(FileNotFoundError):
# If pathlib.Path wasn't supported, the exception would be
# different.
self.loop.run_until_complete(coro)
def test_create_unix_server_existing_path_nonsock(self):
with tempfile.NamedTemporaryFile() as file:
coro = self.loop.create_unix_server(lambda: None, file.name)
with self.assertRaisesRegex(OSError,
'Address.*is already in use'):
self.loop.run_until_complete(coro)
def test_create_unix_server_ssl_bool(self):
coro = self.loop.create_unix_server(lambda: None, path='spam',
ssl=True)
with self.assertRaisesRegex(TypeError,
'ssl argument must be an SSLContext'):
self.loop.run_until_complete(coro)
def test_create_unix_server_nopath_nosock(self):
coro = self.loop.create_unix_server(lambda: None, path=None)
with self.assertRaisesRegex(ValueError,
'path was not specified, and no sock'):
self.loop.run_until_complete(coro)
def test_create_unix_server_path_inetsock(self):
sock = socket.socket()
with sock:
coro = self.loop.create_unix_server(lambda: None, path=None,
sock=sock)
with self.assertRaisesRegex(ValueError,
'A UNIX Domain Stream.*was expected'):
self.loop.run_until_complete(coro)
def test_create_unix_server_path_dgram(self):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
with sock:
coro = self.loop.create_unix_server(lambda: None, path=None,
sock=sock)
with self.assertRaisesRegex(ValueError,
'A UNIX Domain Stream.*was expected'):
self.loop.run_until_complete(coro)
@unittest.skipUnless(hasattr(socket, 'SOCK_NONBLOCK'),
'no socket.SOCK_NONBLOCK (linux only)')
@support.skip_unless_bind_unix_socket
def test_create_unix_server_path_stream_bittype(self):
sock = socket.socket(
socket.AF_UNIX, socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
with tempfile.NamedTemporaryFile() as file:
fn = file.name
try:
with sock:
sock.bind(fn)
coro = self.loop.create_unix_server(lambda: None, path=None,
sock=sock)
srv = self.loop.run_until_complete(coro)
srv.close()
self.loop.run_until_complete(srv.wait_closed())
finally:
os.unlink(fn)
def test_create_unix_server_ssl_timeout_with_plain_sock(self):
coro = self.loop.create_unix_server(lambda: None, path='spam',
ssl_handshake_timeout=1)
with self.assertRaisesRegex(
ValueError,
'ssl_handshake_timeout is only meaningful with ssl'):
self.loop.run_until_complete(coro)
def test_create_unix_connection_path_inetsock(self):
sock = socket.socket()
with sock:
coro = self.loop.create_unix_connection(lambda: None,
sock=sock)
with self.assertRaisesRegex(ValueError,
'A UNIX Domain Stream.*was expected'):
self.loop.run_until_complete(coro)
@mock.patch('asyncio.unix_events.socket')
def test_create_unix_server_bind_error(self, m_socket):
# Ensure that the socket is closed on any bind error
sock = mock.Mock()
m_socket.socket.return_value = sock
sock.bind.side_effect = OSError
coro = self.loop.create_unix_server(lambda: None, path="/test")
with self.assertRaises(OSError):
self.loop.run_until_complete(coro)
self.assertTrue(sock.close.called)
sock.bind.side_effect = MemoryError
coro = self.loop.create_unix_server(lambda: None, path="/test")
with self.assertRaises(MemoryError):
self.loop.run_until_complete(coro)
self.assertTrue(sock.close.called)
def test_create_unix_connection_path_sock(self):
coro = self.loop.create_unix_connection(
lambda: None, os.devnull, sock=object())
with self.assertRaisesRegex(ValueError, 'path and sock can not be'):
self.loop.run_until_complete(coro)
def test_create_unix_connection_nopath_nosock(self):
coro = self.loop.create_unix_connection(
lambda: None, None)
with self.assertRaisesRegex(ValueError,
'no path and sock were specified'):
self.loop.run_until_complete(coro)
def test_create_unix_connection_nossl_serverhost(self):
coro = self.loop.create_unix_connection(
lambda: None, os.devnull, server_hostname='spam')
with self.assertRaisesRegex(ValueError,
'server_hostname is only meaningful'):
self.loop.run_until_complete(coro)
def test_create_unix_connection_ssl_noserverhost(self):
coro = self.loop.create_unix_connection(
lambda: None, os.devnull, ssl=True)
with self.assertRaisesRegex(
ValueError, 'you have to pass server_hostname when using ssl'):
self.loop.run_until_complete(coro)
def test_create_unix_connection_ssl_timeout_with_plain_sock(self):
coro = self.loop.create_unix_connection(lambda: None, path='spam',
ssl_handshake_timeout=1)
with self.assertRaisesRegex(
ValueError,
'ssl_handshake_timeout is only meaningful with ssl'):
self.loop.run_until_complete(coro)
@unittest.skipUnless(hasattr(os, 'sendfile'),
'sendfile is not supported')
class SelectorEventLoopUnixSockSendfileTests(test_utils.TestCase):
DATA = b"12345abcde" * 16 * 1024 # 160 KiB
class MyProto(asyncio.Protocol):
def __init__(self, loop):
self.started = False
self.closed = False
self.data = bytearray()
self.fut = loop.create_future()
self.transport = None
self._ready = loop.create_future()
def connection_made(self, transport):
self.started = True
self.transport = transport
self._ready.set_result(None)
def data_received(self, data):
self.data.extend(data)
def connection_lost(self, exc):
self.closed = True
self.fut.set_result(None)
async def wait_closed(self):
await self.fut
@classmethod
def setUpClass(cls):
with open(support.TESTFN, 'wb') as fp:
fp.write(cls.DATA)
super().setUpClass()
@classmethod
def tearDownClass(cls):
support.unlink(support.TESTFN)
super().tearDownClass()
def setUp(self):
self.loop = asyncio.new_event_loop()
self.set_event_loop(self.loop)
self.file = open(support.TESTFN, 'rb')
self.addCleanup(self.file.close)
super().setUp()
def make_socket(self, cleanup=True):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setblocking(False)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024)
if cleanup:
self.addCleanup(sock.close)
return sock
def run_loop(self, coro):
return self.loop.run_until_complete(coro)
def prepare(self):
sock = self.make_socket()
proto = self.MyProto(self.loop)
port = support.find_unused_port()
srv_sock = self.make_socket(cleanup=False)
srv_sock.bind((support.HOST, port))
server = self.run_loop(self.loop.create_server(
lambda: proto, sock=srv_sock))
self.run_loop(self.loop.sock_connect(sock, (support.HOST, port)))
self.run_loop(proto._ready)
def cleanup():
proto.transport.close()
self.run_loop(proto.wait_closed())
server.close()
self.run_loop(server.wait_closed())
self.addCleanup(cleanup)
return sock, proto
def test_sock_sendfile_not_available(self):
sock, proto = self.prepare()
with mock.patch('asyncio.unix_events.os', spec=[]):
with self.assertRaisesRegex(asyncio.SendfileNotAvailableError,
"os[.]sendfile[(][)] is not available"):
self.run_loop(self.loop._sock_sendfile_native(sock, self.file,
0, None))
self.assertEqual(self.file.tell(), 0)
def test_sock_sendfile_not_a_file(self):
sock, proto = self.prepare()
f = object()
with self.assertRaisesRegex(asyncio.SendfileNotAvailableError,
"not a regular file"):
self.run_loop(self.loop._sock_sendfile_native(sock, f,
0, None))
self.assertEqual(self.file.tell(), 0)
def test_sock_sendfile_iobuffer(self):
sock, proto = self.prepare()
f = io.BytesIO()
with self.assertRaisesRegex(asyncio.SendfileNotAvailableError,
"not a regular file"):
self.run_loop(self.loop._sock_sendfile_native(sock, f,
0, None))
self.assertEqual(self.file.tell(), 0)
def test_sock_sendfile_not_regular_file(self):
sock, proto = self.prepare()
f = mock.Mock()
f.fileno.return_value = -1
with self.assertRaisesRegex(asyncio.SendfileNotAvailableError,
"not a regular file"):
self.run_loop(self.loop._sock_sendfile_native(sock, f,
0, None))
self.assertEqual(self.file.tell(), 0)
def test_sock_sendfile_cancel1(self):
sock, proto = self.prepare()
fut = self.loop.create_future()
fileno = self.file.fileno()
self.loop._sock_sendfile_native_impl(fut, None, sock, fileno,
0, None, len(self.DATA), 0)
fut.cancel()
with contextlib.suppress(asyncio.CancelledError):
self.run_loop(fut)
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)
def test_sock_sendfile_cancel2(self):
sock, proto = self.prepare()
fut = self.loop.create_future()
fileno = self.file.fileno()
self.loop._sock_sendfile_native_impl(fut, None, sock, fileno,
0, None, len(self.DATA), 0)
fut.cancel()
self.loop._sock_sendfile_native_impl(fut, sock.fileno(), sock, fileno,
0, None, len(self.DATA), 0)
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)
def test_sock_sendfile_blocking_error(self):
sock, proto = self.prepare()
fileno = self.file.fileno()
fut = mock.Mock()
fut.cancelled.return_value = False
with mock.patch('os.sendfile', side_effect=BlockingIOError()):
self.loop._sock_sendfile_native_impl(fut, None, sock, fileno,
0, None, len(self.DATA), 0)
key = self.loop._selector.get_key(sock)
self.assertIsNotNone(key)
fut.add_done_callback.assert_called_once_with(mock.ANY)
def test_sock_sendfile_os_error_first_call(self):
sock, proto = self.prepare()
fileno = self.file.fileno()
fut = self.loop.create_future()
with mock.patch('os.sendfile', side_effect=OSError()):
self.loop._sock_sendfile_native_impl(fut, None, sock, fileno,
0, None, len(self.DATA), 0)
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)
exc = fut.exception()
self.assertIsInstance(exc, asyncio.SendfileNotAvailableError)
self.assertEqual(0, self.file.tell())
def test_sock_sendfile_os_error_next_call(self):
sock, proto = self.prepare()
fileno = self.file.fileno()
fut = self.loop.create_future()
err = OSError()
with mock.patch('os.sendfile', side_effect=err):
self.loop._sock_sendfile_native_impl(fut, sock.fileno(),
sock, fileno,
1000, None, len(self.DATA),
1000)
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)
exc = fut.exception()
self.assertIs(exc, err)
self.assertEqual(1000, self.file.tell())
def test_sock_sendfile_exception(self):
sock, proto = self.prepare()
fileno = self.file.fileno()
fut = self.loop.create_future()
err = asyncio.SendfileNotAvailableError()
with mock.patch('os.sendfile', side_effect=err):
self.loop._sock_sendfile_native_impl(fut, sock.fileno(),
sock, fileno,
1000, None, len(self.DATA),
1000)
with self.assertRaises(KeyError):
self.loop._selector.get_key(sock)
exc = fut.exception()
self.assertIs(exc, err)
self.assertEqual(1000, self.file.tell())
class UnixReadPipeTransportTests(test_utils.TestCase):
def setUp(self):
super().setUp()
self.loop = self.new_test_loop()
self.protocol = test_utils.make_test_protocol(asyncio.Protocol)
self.pipe = mock.Mock(spec_set=io.RawIOBase)
self.pipe.fileno.return_value = 5
blocking_patcher = mock.patch('os.set_blocking')
blocking_patcher.start()
self.addCleanup(blocking_patcher.stop)
fstat_patcher = mock.patch('os.fstat')
m_fstat = fstat_patcher.start()
st = mock.Mock()
st.st_mode = stat.S_IFIFO
m_fstat.return_value = st
self.addCleanup(fstat_patcher.stop)
def read_pipe_transport(self, waiter=None):
transport = unix_events._UnixReadPipeTransport(self.loop, self.pipe,
self.protocol,
waiter=waiter)
self.addCleanup(close_pipe_transport, transport)
return transport
def test_ctor(self):
waiter = self.loop.create_future()
tr = self.read_pipe_transport(waiter=waiter)
self.loop.run_until_complete(waiter)
self.protocol.connection_made.assert_called_with(tr)
self.loop.assert_reader(5, tr._read_ready)
self.assertIsNone(waiter.result())
@mock.patch('os.read')
def test__read_ready(self, m_read):
tr = self.read_pipe_transport()
m_read.return_value = b'data'
tr._read_ready()
m_read.assert_called_with(5, tr.max_size)
self.protocol.data_received.assert_called_with(b'data')
@mock.patch('os.read')
def test__read_ready_eof(self, m_read):
tr = self.read_pipe_transport()
m_read.return_value = b''
tr._read_ready()
m_read.assert_called_with(5, tr.max_size)
self.assertFalse(self.loop.readers)
test_utils.run_briefly(self.loop)
self.protocol.eof_received.assert_called_with()
self.protocol.connection_lost.assert_called_with(None)
@mock.patch('os.read')
def test__read_ready_blocked(self, m_read):
tr = self.read_pipe_transport()
m_read.side_effect = BlockingIOError
tr._read_ready()
m_read.assert_called_with(5, tr.max_size)
test_utils.run_briefly(self.loop)
self.assertFalse(self.protocol.data_received.called)
@mock.patch('asyncio.log.logger.error')
@mock.patch('os.read')
def test__read_ready_error(self, m_read, m_logexc):
tr = self.read_pipe_transport()
err = OSError()
m_read.side_effect = err
tr._close = mock.Mock()
tr._read_ready()
m_read.assert_called_with(5, tr.max_size)
tr._close.assert_called_with(err)
m_logexc.assert_called_with(
test_utils.MockPattern(
'Fatal read error on pipe transport'
'\nprotocol:.*\ntransport:.*'),
exc_info=(OSError, MOCK_ANY, MOCK_ANY))
@mock.patch('os.read')
def test_pause_reading(self, m_read):
tr = self.read_pipe_transport()
m = mock.Mock()
self.loop.add_reader(5, m)
tr.pause_reading()
self.assertFalse(self.loop.readers)
@mock.patch('os.read')
def test_resume_reading(self, m_read):
tr = self.read_pipe_transport()
tr.pause_reading()
tr.resume_reading()
self.loop.assert_reader(5, tr._read_ready)
@mock.patch('os.read')
def test_close(self, m_read):
tr = self.read_pipe_transport()
tr._close = mock.Mock()
tr.close()
tr._close.assert_called_with(None)
@mock.patch('os.read')
def test_close_already_closing(self, m_read):
tr = self.read_pipe_transport()
tr._closing = True
tr._close = mock.Mock()
tr.close()
self.assertFalse(tr._close.called)
@mock.patch('os.read')
def test__close(self, m_read):
tr = self.read_pipe_transport()
err = object()
tr._close(err)
self.assertTrue(tr.is_closing())
self.assertFalse(self.loop.readers)
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(err)
def test__call_connection_lost(self):
tr = self.read_pipe_transport()
self.assertIsNotNone(tr._protocol)
self.assertIsNotNone(tr._loop)
err = None
tr._call_connection_lost(err)
self.protocol.connection_lost.assert_called_with(err)
self.pipe.close.assert_called_with()
self.assertIsNone(tr._protocol)
self.assertIsNone(tr._loop)
def test__call_connection_lost_with_err(self):
tr = self.read_pipe_transport()
self.assertIsNotNone(tr._protocol)
self.assertIsNotNone(tr._loop)
err = OSError()
tr._call_connection_lost(err)
self.protocol.connection_lost.assert_called_with(err)
self.pipe.close.assert_called_with()
self.assertIsNone(tr._protocol)
self.assertIsNone(tr._loop)
def test_pause_reading_on_closed_pipe(self):
tr = self.read_pipe_transport()
tr.close()
test_utils.run_briefly(self.loop)
self.assertIsNone(tr._loop)
tr.pause_reading()
def test_pause_reading_on_paused_pipe(self):
tr = self.read_pipe_transport()
tr.pause_reading()
# the second call should do nothing
tr.pause_reading()
def test_resume_reading_on_closed_pipe(self):
tr = self.read_pipe_transport()
tr.close()
test_utils.run_briefly(self.loop)
self.assertIsNone(tr._loop)
tr.resume_reading()
def test_resume_reading_on_paused_pipe(self):
tr = self.read_pipe_transport()
# the pipe is not paused
# resuming should do nothing
tr.resume_reading()
class UnixWritePipeTransportTests(test_utils.TestCase):
def setUp(self):
super().setUp()
self.loop = self.new_test_loop()
self.protocol = test_utils.make_test_protocol(asyncio.BaseProtocol)
self.pipe = mock.Mock(spec_set=io.RawIOBase)
self.pipe.fileno.return_value = 5
blocking_patcher = mock.patch('os.set_blocking')
blocking_patcher.start()
self.addCleanup(blocking_patcher.stop)
fstat_patcher = mock.patch('os.fstat')
m_fstat = fstat_patcher.start()
st = mock.Mock()
st.st_mode = stat.S_IFSOCK
m_fstat.return_value = st
self.addCleanup(fstat_patcher.stop)
def write_pipe_transport(self, waiter=None):
transport = unix_events._UnixWritePipeTransport(self.loop, self.pipe,
self.protocol,
waiter=waiter)
self.addCleanup(close_pipe_transport, transport)
return transport
def test_ctor(self):
waiter = self.loop.create_future()
tr = self.write_pipe_transport(waiter=waiter)
self.loop.run_until_complete(waiter)
self.protocol.connection_made.assert_called_with(tr)
self.loop.assert_reader(5, tr._read_ready)
self.assertEqual(None, waiter.result())
def test_can_write_eof(self):
tr = self.write_pipe_transport()
self.assertTrue(tr.can_write_eof())
@mock.patch('os.write')
def test_write(self, m_write):
tr = self.write_pipe_transport()
m_write.return_value = 4
tr.write(b'data')
m_write.assert_called_with(5, b'data')
self.assertFalse(self.loop.writers)
self.assertEqual(bytearray(), tr._buffer)
@mock.patch('os.write')
def test_write_no_data(self, m_write):
tr = self.write_pipe_transport()
tr.write(b'')
self.assertFalse(m_write.called)
self.assertFalse(self.loop.writers)
self.assertEqual(bytearray(b''), tr._buffer)
@mock.patch('os.write')
def test_write_partial(self, m_write):
tr = self.write_pipe_transport()
m_write.return_value = 2
tr.write(b'data')
self.loop.assert_writer(5, tr._write_ready)
self.assertEqual(bytearray(b'ta'), tr._buffer)
@mock.patch('os.write')
def test_write_buffer(self, m_write):
tr = self.write_pipe_transport()
self.loop.add_writer(5, tr._write_ready)
tr._buffer = bytearray(b'previous')
tr.write(b'data')
self.assertFalse(m_write.called)
self.loop.assert_writer(5, tr._write_ready)
self.assertEqual(bytearray(b'previousdata'), tr._buffer)
@mock.patch('os.write')
def test_write_again(self, m_write):
tr = self.write_pipe_transport()
m_write.side_effect = BlockingIOError()
tr.write(b'data')
m_write.assert_called_with(5, bytearray(b'data'))
self.loop.assert_writer(5, tr._write_ready)
self.assertEqual(bytearray(b'data'), tr._buffer)
@mock.patch('asyncio.unix_events.logger')
@mock.patch('os.write')
def test_write_err(self, m_write, m_log):
tr = self.write_pipe_transport()
err = OSError()
m_write.side_effect = err
tr._fatal_error = mock.Mock()
tr.write(b'data')
m_write.assert_called_with(5, b'data')
self.assertFalse(self.loop.writers)
self.assertEqual(bytearray(), tr._buffer)
tr._fatal_error.assert_called_with(
err,
'Fatal write error on pipe transport')
self.assertEqual(1, tr._conn_lost)
tr.write(b'data')
self.assertEqual(2, tr._conn_lost)
tr.write(b'data')
tr.write(b'data')
tr.write(b'data')
tr.write(b'data')
# This is a bit overspecified. :-(
m_log.warning.assert_called_with(
'pipe closed by peer or os.write(pipe, data) raised exception.')
tr.close()
@mock.patch('os.write')
def test_write_close(self, m_write):
tr = self.write_pipe_transport()
tr._read_ready() # pipe was closed by peer
tr.write(b'data')
self.assertEqual(tr._conn_lost, 1)
tr.write(b'data')
self.assertEqual(tr._conn_lost, 2)
def test__read_ready(self):
tr = self.write_pipe_transport()
tr._read_ready()
self.assertFalse(self.loop.readers)
self.assertFalse(self.loop.writers)
self.assertTrue(tr.is_closing())
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(None)
@mock.patch('os.write')
def test__write_ready(self, m_write):
tr = self.write_pipe_transport()
self.loop.add_writer(5, tr._write_ready)
tr._buffer = bytearray(b'data')
m_write.return_value = 4
tr._write_ready()
self.assertFalse(self.loop.writers)
self.assertEqual(bytearray(), tr._buffer)
@mock.patch('os.write')
def test__write_ready_partial(self, m_write):
tr = self.write_pipe_transport()
self.loop.add_writer(5, tr._write_ready)
tr._buffer = bytearray(b'data')
m_write.return_value = 3
tr._write_ready()
self.loop.assert_writer(5, tr._write_ready)
self.assertEqual(bytearray(b'a'), tr._buffer)
@mock.patch('os.write')
def test__write_ready_again(self, m_write):
tr = self.write_pipe_transport()
self.loop.add_writer(5, tr._write_ready)
tr._buffer = bytearray(b'data')
m_write.side_effect = BlockingIOError()
tr._write_ready()
m_write.assert_called_with(5, bytearray(b'data'))
self.loop.assert_writer(5, tr._write_ready)
self.assertEqual(bytearray(b'data'), tr._buffer)
@mock.patch('os.write')
def test__write_ready_empty(self, m_write):
tr = self.write_pipe_transport()
self.loop.add_writer(5, tr._write_ready)
tr._buffer = bytearray(b'data')
m_write.return_value = 0
tr._write_ready()
m_write.assert_called_with(5, bytearray(b'data'))
self.loop.assert_writer(5, tr._write_ready)
self.assertEqual(bytearray(b'data'), tr._buffer)
@mock.patch('asyncio.log.logger.error')
@mock.patch('os.write')
def test__write_ready_err(self, m_write, m_logexc):
tr = self.write_pipe_transport()
self.loop.add_writer(5, tr._write_ready)
tr._buffer = bytearray(b'data')
m_write.side_effect = err = OSError()
tr._write_ready()
self.assertFalse(self.loop.writers)
self.assertFalse(self.loop.readers)
self.assertEqual(bytearray(), tr._buffer)
self.assertTrue(tr.is_closing())
m_logexc.assert_not_called()
self.assertEqual(1, tr._conn_lost)
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(err)
@mock.patch('os.write')
def test__write_ready_closing(self, m_write):
tr = self.write_pipe_transport()
self.loop.add_writer(5, tr._write_ready)
tr._closing = True
tr._buffer = bytearray(b'data')
m_write.return_value = 4
tr._write_ready()
self.assertFalse(self.loop.writers)
self.assertFalse(self.loop.readers)
self.assertEqual(bytearray(), tr._buffer)
self.protocol.connection_lost.assert_called_with(None)
self.pipe.close.assert_called_with()
@mock.patch('os.write')
def test_abort(self, m_write):
tr = self.write_pipe_transport()
self.loop.add_writer(5, tr._write_ready)
self.loop.add_reader(5, tr._read_ready)
tr._buffer = [b'da', b'ta']
tr.abort()
self.assertFalse(m_write.called)
self.assertFalse(self.loop.readers)
self.assertFalse(self.loop.writers)
self.assertEqual([], tr._buffer)
self.assertTrue(tr.is_closing())
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(None)
def test__call_connection_lost(self):
tr = self.write_pipe_transport()
self.assertIsNotNone(tr._protocol)
self.assertIsNotNone(tr._loop)
err = None
tr._call_connection_lost(err)
self.protocol.connection_lost.assert_called_with(err)
self.pipe.close.assert_called_with()
self.assertIsNone(tr._protocol)
self.assertIsNone(tr._loop)
def test__call_connection_lost_with_err(self):
tr = self.write_pipe_transport()
self.assertIsNotNone(tr._protocol)
self.assertIsNotNone(tr._loop)
err = OSError()
tr._call_connection_lost(err)
self.protocol.connection_lost.assert_called_with(err)
self.pipe.close.assert_called_with()
self.assertIsNone(tr._protocol)
self.assertIsNone(tr._loop)
def test_close(self):
tr = self.write_pipe_transport()
tr.write_eof = mock.Mock()
tr.close()
tr.write_eof.assert_called_with()
# closing the transport twice must not fail
tr.close()
def test_close_closing(self):
tr = self.write_pipe_transport()
tr.write_eof = mock.Mock()
tr._closing = True
tr.close()
self.assertFalse(tr.write_eof.called)
def test_write_eof(self):
tr = self.write_pipe_transport()
tr.write_eof()
self.assertTrue(tr.is_closing())
self.assertFalse(self.loop.readers)
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(None)
def test_write_eof_pending(self):
tr = self.write_pipe_transport()
tr._buffer = [b'data']
tr.write_eof()
self.assertTrue(tr.is_closing())
self.assertFalse(self.protocol.connection_lost.called)
class AbstractChildWatcherTests(unittest.TestCase):
def test_not_implemented(self):
f = mock.Mock()
watcher = asyncio.AbstractChildWatcher()
self.assertRaises(
NotImplementedError, watcher.add_child_handler, f, f)
self.assertRaises(
NotImplementedError, watcher.remove_child_handler, f)
self.assertRaises(
NotImplementedError, watcher.attach_loop, f)
self.assertRaises(
NotImplementedError, watcher.close)
self.assertRaises(
NotImplementedError, watcher.is_active)
self.assertRaises(
NotImplementedError, watcher.__enter__)
self.assertRaises(
NotImplementedError, watcher.__exit__, f, f, f)
class BaseChildWatcherTests(unittest.TestCase):
def test_not_implemented(self):
f = mock.Mock()
watcher = unix_events.BaseChildWatcher()
self.assertRaises(
NotImplementedError, watcher._do_waitpid, f)
WaitPidMocks = collections.namedtuple("WaitPidMocks",
("waitpid",
"WIFEXITED",
"WIFSIGNALED",
"WEXITSTATUS",
"WTERMSIG",
))
class ChildWatcherTestsMixin:
ignore_warnings = mock.patch.object(log.logger, "warning")
def setUp(self):
super().setUp()
self.loop = self.new_test_loop()
self.running = False
self.zombies = {}
with mock.patch.object(
self.loop, "add_signal_handler") as self.m_add_signal_handler:
self.watcher = self.create_watcher()
self.watcher.attach_loop(self.loop)
def waitpid(self, pid, flags):
if isinstance(self.watcher, asyncio.SafeChildWatcher) or pid != -1:
self.assertGreater(pid, 0)
try:
if pid < 0:
return self.zombies.popitem()
else:
return pid, self.zombies.pop(pid)
except KeyError:
pass
if self.running:
return 0, 0
else:
raise ChildProcessError()
def add_zombie(self, pid, returncode):
self.zombies[pid] = returncode + 32768
def WIFEXITED(self, status):
return status >= 32768
def WIFSIGNALED(self, status):
return 32700 < status < 32768
def WEXITSTATUS(self, status):
self.assertTrue(self.WIFEXITED(status))
return status - 32768
def WTERMSIG(self, status):
self.assertTrue(self.WIFSIGNALED(status))
return 32768 - status
def test_create_watcher(self):
self.m_add_signal_handler.assert_called_once_with(
signal.SIGCHLD, self.watcher._sig_chld)
def waitpid_mocks(func):
def wrapped_func(self):
def patch(target, wrapper):
return mock.patch(target, wraps=wrapper,
new_callable=mock.Mock)
with patch('os.WTERMSIG', self.WTERMSIG) as m_WTERMSIG, \
patch('os.WEXITSTATUS', self.WEXITSTATUS) as m_WEXITSTATUS, \
patch('os.WIFSIGNALED', self.WIFSIGNALED) as m_WIFSIGNALED, \
patch('os.WIFEXITED', self.WIFEXITED) as m_WIFEXITED, \
patch('os.waitpid', self.waitpid) as m_waitpid:
func(self, WaitPidMocks(m_waitpid,
m_WIFEXITED, m_WIFSIGNALED,
m_WEXITSTATUS, m_WTERMSIG,
))
return wrapped_func
@waitpid_mocks
def test_sigchld(self, m):
# register a child
callback = mock.Mock()
with self.watcher:
self.running = True
self.watcher.add_child_handler(42, callback, 9, 10, 14)
self.assertFalse(callback.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# child is running
self.watcher._sig_chld()
self.assertFalse(callback.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# child terminates (returncode 12)
self.running = False
self.add_zombie(42, 12)
self.watcher._sig_chld()
self.assertTrue(m.WIFEXITED.called)
self.assertTrue(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
callback.assert_called_once_with(42, 12, 9, 10, 14)
m.WIFSIGNALED.reset_mock()
m.WIFEXITED.reset_mock()
m.WEXITSTATUS.reset_mock()
callback.reset_mock()
# ensure that the child is effectively reaped
self.add_zombie(42, 13)
with self.ignore_warnings:
self.watcher._sig_chld()
self.assertFalse(callback.called)
self.assertFalse(m.WTERMSIG.called)
m.WIFSIGNALED.reset_mock()
m.WIFEXITED.reset_mock()
m.WEXITSTATUS.reset_mock()
# sigchld called again
self.zombies.clear()
self.watcher._sig_chld()
self.assertFalse(callback.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
@waitpid_mocks
def test_sigchld_two_children(self, m):
callback1 = mock.Mock()
callback2 = mock.Mock()
# register child 1
with self.watcher:
self.running = True
self.watcher.add_child_handler(43, callback1, 7, 8)
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# register child 2
with self.watcher:
self.watcher.add_child_handler(44, callback2, 147, 18)
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# children are running
self.watcher._sig_chld()
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# child 1 terminates (signal 3)
self.add_zombie(43, -3)
self.watcher._sig_chld()
callback1.assert_called_once_with(43, -3, 7, 8)
self.assertFalse(callback2.called)
self.assertTrue(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertTrue(m.WTERMSIG.called)
m.WIFSIGNALED.reset_mock()
m.WIFEXITED.reset_mock()
m.WTERMSIG.reset_mock()
callback1.reset_mock()
# child 2 still running
self.watcher._sig_chld()
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# child 2 terminates (code 108)
self.add_zombie(44, 108)
self.running = False
self.watcher._sig_chld()
callback2.assert_called_once_with(44, 108, 147, 18)
self.assertFalse(callback1.called)
self.assertTrue(m.WIFEXITED.called)
self.assertTrue(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
m.WIFSIGNALED.reset_mock()
m.WIFEXITED.reset_mock()
m.WEXITSTATUS.reset_mock()
callback2.reset_mock()
# ensure that the children are effectively reaped
self.add_zombie(43, 14)
self.add_zombie(44, 15)
with self.ignore_warnings:
self.watcher._sig_chld()
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WTERMSIG.called)
m.WIFSIGNALED.reset_mock()
m.WIFEXITED.reset_mock()
m.WEXITSTATUS.reset_mock()
# sigchld called again
self.zombies.clear()
self.watcher._sig_chld()
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
@waitpid_mocks
def test_sigchld_two_children_terminating_together(self, m):
callback1 = mock.Mock()
callback2 = mock.Mock()
# register child 1
with self.watcher:
self.running = True
self.watcher.add_child_handler(45, callback1, 17, 8)
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# register child 2
with self.watcher:
self.watcher.add_child_handler(46, callback2, 1147, 18)
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# children are running
self.watcher._sig_chld()
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# child 1 terminates (code 78)
# child 2 terminates (signal 5)
self.add_zombie(45, 78)
self.add_zombie(46, -5)
self.running = False
self.watcher._sig_chld()
callback1.assert_called_once_with(45, 78, 17, 8)
callback2.assert_called_once_with(46, -5, 1147, 18)
self.assertTrue(m.WIFSIGNALED.called)
self.assertTrue(m.WIFEXITED.called)
self.assertTrue(m.WEXITSTATUS.called)
self.assertTrue(m.WTERMSIG.called)
m.WIFSIGNALED.reset_mock()
m.WIFEXITED.reset_mock()
m.WTERMSIG.reset_mock()
m.WEXITSTATUS.reset_mock()
callback1.reset_mock()
callback2.reset_mock()
# ensure that the children are effectively reaped
self.add_zombie(45, 14)
self.add_zombie(46, 15)
with self.ignore_warnings:
self.watcher._sig_chld()
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WTERMSIG.called)
@waitpid_mocks
def test_sigchld_race_condition(self, m):
# register a child
callback = mock.Mock()
with self.watcher:
# child terminates before being registered
self.add_zombie(50, 4)
self.watcher._sig_chld()
self.watcher.add_child_handler(50, callback, 1, 12)
callback.assert_called_once_with(50, 4, 1, 12)
callback.reset_mock()
# ensure that the child is effectively reaped
self.add_zombie(50, -1)
with self.ignore_warnings:
self.watcher._sig_chld()
self.assertFalse(callback.called)
@waitpid_mocks
def test_sigchld_replace_handler(self, m):
callback1 = mock.Mock()
callback2 = mock.Mock()
# register a child
with self.watcher:
self.running = True
self.watcher.add_child_handler(51, callback1, 19)
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# register the same child again
with self.watcher:
self.watcher.add_child_handler(51, callback2, 21)
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# child terminates (signal 8)
self.running = False
self.add_zombie(51, -8)
self.watcher._sig_chld()
callback2.assert_called_once_with(51, -8, 21)
self.assertFalse(callback1.called)
self.assertTrue(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertTrue(m.WTERMSIG.called)
m.WIFSIGNALED.reset_mock()
m.WIFEXITED.reset_mock()
m.WTERMSIG.reset_mock()
callback2.reset_mock()
# ensure that the child is effectively reaped
self.add_zombie(51, 13)
with self.ignore_warnings:
self.watcher._sig_chld()
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(m.WTERMSIG.called)
@waitpid_mocks
def test_sigchld_remove_handler(self, m):
callback = mock.Mock()
# register a child
with self.watcher:
self.running = True
self.watcher.add_child_handler(52, callback, 1984)
self.assertFalse(callback.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# unregister the child
self.watcher.remove_child_handler(52)
self.assertFalse(callback.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# child terminates (code 99)
self.running = False
self.add_zombie(52, 99)
with self.ignore_warnings:
self.watcher._sig_chld()
self.assertFalse(callback.called)
@waitpid_mocks
def test_sigchld_unknown_status(self, m):
callback = mock.Mock()
# register a child
with self.watcher:
self.running = True
self.watcher.add_child_handler(53, callback, -19)
self.assertFalse(callback.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# terminate with unknown status
self.zombies[53] = 1178
self.running = False
self.watcher._sig_chld()
callback.assert_called_once_with(53, 1178, -19)
self.assertTrue(m.WIFEXITED.called)
self.assertTrue(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
callback.reset_mock()
m.WIFEXITED.reset_mock()
m.WIFSIGNALED.reset_mock()
# ensure that the child is effectively reaped
self.add_zombie(53, 101)
with self.ignore_warnings:
self.watcher._sig_chld()
self.assertFalse(callback.called)
@waitpid_mocks
def test_remove_child_handler(self, m):
callback1 = mock.Mock()
callback2 = mock.Mock()
callback3 = mock.Mock()
# register children
with self.watcher:
self.running = True
self.watcher.add_child_handler(54, callback1, 1)
self.watcher.add_child_handler(55, callback2, 2)
self.watcher.add_child_handler(56, callback3, 3)
# remove child handler 1
self.assertTrue(self.watcher.remove_child_handler(54))
# remove child handler 2 multiple times
self.assertTrue(self.watcher.remove_child_handler(55))
self.assertFalse(self.watcher.remove_child_handler(55))
self.assertFalse(self.watcher.remove_child_handler(55))
# all children terminate
self.add_zombie(54, 0)
self.add_zombie(55, 1)
self.add_zombie(56, 2)
self.running = False
with self.ignore_warnings:
self.watcher._sig_chld()
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
callback3.assert_called_once_with(56, 2, 3)
@waitpid_mocks
def test_sigchld_unhandled_exception(self, m):
callback = mock.Mock()
# register a child
with self.watcher:
self.running = True
self.watcher.add_child_handler(57, callback)
# raise an exception
m.waitpid.side_effect = ValueError
with mock.patch.object(log.logger,
'error') as m_error:
self.assertEqual(self.watcher._sig_chld(), None)
self.assertTrue(m_error.called)
@waitpid_mocks
def test_sigchld_child_reaped_elsewhere(self, m):
# register a child
callback = mock.Mock()
with self.watcher:
self.running = True
self.watcher.add_child_handler(58, callback)
self.assertFalse(callback.called)
self.assertFalse(m.WIFEXITED.called)
self.assertFalse(m.WIFSIGNALED.called)
self.assertFalse(m.WEXITSTATUS.called)
self.assertFalse(m.WTERMSIG.called)
# child terminates
self.running = False
self.add_zombie(58, 4)
# waitpid is called elsewhere
os.waitpid(58, os.WNOHANG)
m.waitpid.reset_mock()
# sigchld
with self.ignore_warnings:
self.watcher._sig_chld()
if isinstance(self.watcher, asyncio.FastChildWatcher):
# here the FastChildWatche enters a deadlock
# (there is no way to prevent it)
self.assertFalse(callback.called)
else:
callback.assert_called_once_with(58, 255)
@waitpid_mocks
def test_sigchld_unknown_pid_during_registration(self, m):
# register two children
callback1 = mock.Mock()
callback2 = mock.Mock()
with self.ignore_warnings, self.watcher:
self.running = True
# child 1 terminates
self.add_zombie(591, 7)
# an unknown child terminates
self.add_zombie(593, 17)
self.watcher._sig_chld()
self.watcher.add_child_handler(591, callback1)
self.watcher.add_child_handler(592, callback2)
callback1.assert_called_once_with(591, 7)
self.assertFalse(callback2.called)
@waitpid_mocks
def test_set_loop(self, m):
# register a child
callback = mock.Mock()
with self.watcher:
self.running = True
self.watcher.add_child_handler(60, callback)
# attach a new loop
old_loop = self.loop
self.loop = self.new_test_loop()
patch = mock.patch.object
with patch(old_loop, "remove_signal_handler") as m_old_remove, \
patch(self.loop, "add_signal_handler") as m_new_add:
self.watcher.attach_loop(self.loop)
m_old_remove.assert_called_once_with(
signal.SIGCHLD)
m_new_add.assert_called_once_with(
signal.SIGCHLD, self.watcher._sig_chld)
# child terminates
self.running = False
self.add_zombie(60, 9)
self.watcher._sig_chld()
callback.assert_called_once_with(60, 9)
@waitpid_mocks
def test_set_loop_race_condition(self, m):
# register 3 children
callback1 = mock.Mock()
callback2 = mock.Mock()
callback3 = mock.Mock()
with self.watcher:
self.running = True
self.watcher.add_child_handler(61, callback1)
self.watcher.add_child_handler(62, callback2)
self.watcher.add_child_handler(622, callback3)
# detach the loop
old_loop = self.loop
self.loop = None
with mock.patch.object(
old_loop, "remove_signal_handler") as m_remove_signal_handler:
with self.assertWarnsRegex(
RuntimeWarning, 'A loop is being detached'):
self.watcher.attach_loop(None)
m_remove_signal_handler.assert_called_once_with(
signal.SIGCHLD)
# child 1 & 2 terminate
self.add_zombie(61, 11)
self.add_zombie(62, -5)
# SIGCHLD was not caught
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
self.assertFalse(callback3.called)
# attach a new loop
self.loop = self.new_test_loop()
with mock.patch.object(
self.loop, "add_signal_handler") as m_add_signal_handler:
self.watcher.attach_loop(self.loop)
m_add_signal_handler.assert_called_once_with(
signal.SIGCHLD, self.watcher._sig_chld)
callback1.assert_called_once_with(61, 11) # race condition!
callback2.assert_called_once_with(62, -5) # race condition!
self.assertFalse(callback3.called)
callback1.reset_mock()
callback2.reset_mock()
# child 3 terminates
self.running = False
self.add_zombie(622, 19)
self.watcher._sig_chld()
self.assertFalse(callback1.called)
self.assertFalse(callback2.called)
callback3.assert_called_once_with(622, 19)
@waitpid_mocks
def test_close(self, m):
# register two children
callback1 = mock.Mock()
with self.watcher:
self.running = True
# child 1 terminates
self.add_zombie(63, 9)
# other child terminates
self.add_zombie(65, 18)
self.watcher._sig_chld()
self.watcher.add_child_handler(63, callback1)
self.watcher.add_child_handler(64, callback1)
self.assertEqual(len(self.watcher._callbacks), 1)
if isinstance(self.watcher, asyncio.FastChildWatcher):
self.assertEqual(len(self.watcher._zombies), 1)
with mock.patch.object(
self.loop,
"remove_signal_handler") as m_remove_signal_handler:
self.watcher.close()
m_remove_signal_handler.assert_called_once_with(
signal.SIGCHLD)
self.assertFalse(self.watcher._callbacks)
if isinstance(self.watcher, asyncio.FastChildWatcher):
self.assertFalse(self.watcher._zombies)
class SafeChildWatcherTests (ChildWatcherTestsMixin, test_utils.TestCase):
def create_watcher(self):
return asyncio.SafeChildWatcher()
class FastChildWatcherTests (ChildWatcherTestsMixin, test_utils.TestCase):
def create_watcher(self):
return asyncio.FastChildWatcher()
class PolicyTests(unittest.TestCase):
def create_policy(self):
return asyncio.DefaultEventLoopPolicy()
def test_get_default_child_watcher(self):
policy = self.create_policy()
self.assertIsNone(policy._watcher)
watcher = policy.get_child_watcher()
self.assertIsInstance(watcher, asyncio.ThreadedChildWatcher)
self.assertIs(policy._watcher, watcher)
self.assertIs(watcher, policy.get_child_watcher())
def test_get_child_watcher_after_set(self):
policy = self.create_policy()
watcher = asyncio.FastChildWatcher()
policy.set_child_watcher(watcher)
self.assertIs(policy._watcher, watcher)
self.assertIs(watcher, policy.get_child_watcher())
def test_get_child_watcher_thread(self):
def f():
policy.set_event_loop(policy.new_event_loop())
self.assertIsInstance(policy.get_event_loop(),
asyncio.AbstractEventLoop)
watcher = policy.get_child_watcher()
self.assertIsInstance(watcher, asyncio.SafeChildWatcher)
self.assertIsNone(watcher._loop)
policy.get_event_loop().close()
policy = self.create_policy()
policy.set_child_watcher(asyncio.SafeChildWatcher())
th = threading.Thread(target=f)
th.start()
th.join()
def test_child_watcher_replace_mainloop_existing(self):
policy = self.create_policy()
loop = policy.get_event_loop()
# Explicitly setup SafeChildWatcher,
# default ThreadedChildWatcher has no _loop property
watcher = asyncio.SafeChildWatcher()
policy.set_child_watcher(watcher)
watcher.attach_loop(loop)
self.assertIs(watcher._loop, loop)
new_loop = policy.new_event_loop()
policy.set_event_loop(new_loop)
self.assertIs(watcher._loop, new_loop)
policy.set_event_loop(None)
self.assertIs(watcher._loop, None)
loop.close()
new_loop.close()
class TestFunctional(unittest.TestCase):
def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
def tearDown(self):
self.loop.close()
asyncio.set_event_loop(None)
def test_add_reader_invalid_argument(self):
def assert_raises():
return self.assertRaisesRegex(ValueError, r'Invalid file object')
cb = lambda: None
with assert_raises():
self.loop.add_reader(object(), cb)
with assert_raises():
self.loop.add_writer(object(), cb)
with assert_raises():
self.loop.remove_reader(object())
with assert_raises():
self.loop.remove_writer(object())
def test_add_reader_or_writer_transport_fd(self):
def assert_raises():
return self.assertRaisesRegex(
RuntimeError,
r'File descriptor .* is used by transport')
async def runner():
tr, pr = await self.loop.create_connection(
lambda: asyncio.Protocol(), sock=rsock)
try:
cb = lambda: None
with assert_raises():
self.loop.add_reader(rsock, cb)
with assert_raises():
self.loop.add_reader(rsock.fileno(), cb)
with assert_raises():
self.loop.remove_reader(rsock)
with assert_raises():
self.loop.remove_reader(rsock.fileno())
with assert_raises():
self.loop.add_writer(rsock, cb)
with assert_raises():
self.loop.add_writer(rsock.fileno(), cb)
with assert_raises():
self.loop.remove_writer(rsock)
with assert_raises():
self.loop.remove_writer(rsock.fileno())
finally:
tr.close()
rsock, wsock = socket.socketpair()
try:
self.loop.run_until_complete(runner())
finally:
rsock.close()
wsock.close()
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
624,
2925,
367,
16572,
63,
4368,
14,
647,
1041,
199,
199,
646,
5055,
199,
646,
15502,
199,
646,
7554,
199,
646,
5890,
199,
646,
747,
199,
646,
32212,
199,
646,
4673,
199,
646,
2838,
199,
646,
5672,
199,
646,
984,
199,
646,
5549,
199,
646,
5796,
199,
646,
2882,
199,
504,
2882,
492,
1683,
199,
504,
511,
492,
2291,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
746,
2882,
14,
25755,
360,
19584,
1454,
358,
421,
199,
646,
16195,
199,
504,
16195,
492,
943,
199,
504,
16195,
492,
16572,
63,
4368,
199,
504,
511,
14,
396,
63,
19343,
492,
3778,
465,
511,
63,
1208,
421,
199,
17749,
63,
8974,
275,
1683,
14,
8974,
421,
199,
318,
6766,
2377,
837,
272,
16195,
14,
409,
63,
1430,
63,
3813,
63,
3185,
8,
403,
9,
421,
199,
318,
4002,
63,
4990,
63,
5545,
8,
5545,
304,
272,
327,
7529,
1133,
1240,
7773,
14,
1600,
342,
2952,
314,
1566,
4438,
436,
314,
9759,
272,
327,
787,
16991,
272,
340,
7773,
423,
4990,
365,
488,
26,
267,
372,
272,
7773,
423,
4990,
14,
1600,
342,
272,
7773,
423,
4990,
275,
488,
421,
199,
32,
2796,
14,
11278,
8,
4653,
12,
283,
28536,
787,
440,
3748,
358,
199,
533,
3240,
3283,
2390,
7382,
11274,
2925,
8,
396,
63,
1208,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
1252,
5996,
342,
267,
291,
14,
3813,
275,
16195,
14,
11212,
2390,
7382,
342,
267,
291,
14,
409,
63,
1430,
63,
3813,
8,
277,
14,
3813,
9,
339,
347,
511,
63,
1074,
63,
4653,
8,
277,
304,
267,
291,
14,
1855,
8,
288,
3146,
12,
291,
14,
3813,
423,
1074,
63,
4653,
12,
283,
17,
358,
267,
291,
14,
1855,
8,
288,
1722,
12,
291,
14,
3813,
423,
1074,
63,
4653,
12,
4673,
14,
2709,
1277,
435,
413,
9,
339,
347,
511,
63,
2479,
63,
4653,
63,
889,
63,
2232,
8,
277,
304,
267,
291,
14,
3813,
423,
2479,
63,
4653,
8,
4653,
14,
2709,
1277,
435,
413,
9,
339,
347,
511,
63,
2479,
63,
4653,
63,
21924,
63,
2232,
8,
277,
304,
267,
394,
275,
16195,
14,
5940,
8,
1805,
14,
3346,
1062,
11969,
2574,
4438,
29,
1805,
14,
3346,
1012,
267,
394,
14,
6406,
342,
267,
291,
14,
3813,
423,
4653,
63,
5586,
59,
4653,
14,
2709,
1277,
435,
413,
61,
275,
394,
267,
291,
14,
3813,
14,
2168,
63,
4653,
63,
2232,
275,
1683,
14,
3346,
342,
267,
291,
14,
3813,
423,
2479,
63,
4653,
8,
4653,
14,
2709,
1277,
435,
413,
9,
267,
291,
14,
3813,
14,
2168,
63,
4653,
63,
2232,
14,
479,
63,
3527,
63,
1045,
8,
4653,
14,
2709,
1277,
435,
413,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
63,
2758,
63,
705,
8,
277,
12,
333,
63,
4653,
304,
267,
333,
63,
4653,
14,
2709,
1277,
275,
4673,
14,
2709,
1277,
267,
333,
63,
4653,
14,
1078,
63,
10458,
275,
4673,
14,
1078,
63,
10458,
267,
333,
63,
4653,
14,
409,
63,
28715,
63,
2592,
14,
2441,
63,
5881,
275,
1722,
398,
291,
14,
1855,
8,
288,
6064,
12,
288,
291,
14,
3813,
14,
525,
63,
4653,
63,
2232,
12,
288,
4673,
14,
21223,
12,
2400,
26,
715,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
63,
16675,
63,
705,
8,
277,
12,
333,
63,
4653,
304,
267,
333,
63,
4653,
14,
2709,
1277,
275,
4673,
14,
2709,
1277,
398,
5316,
347,
3486,
63,
16675,
837,
288,
986,
398,
327,
3233,
1471,
440,
506,
282,
1970,
13242,
805,
267,
1970,
79,
63,
1532,
275,
3486,
63,
16675,
267,
1970,
79,
63,
1113,
275,
1970,
79,
63,
1532,
342,
267,
291,
14,
12808,
8,
989,
79,
63,
1113,
14,
1600,
9,
267,
367,
2562,
315,
334,
989,
79,
63,
1532,
12,
1970,
79,
63,
1113,
304,
288,
291,
14,
16499,
8,
355,
3146,
12,
283,
989,
548,
3746,
3913,
506,
1202,
543,
1050,
63,
4653,
63,
2232,
297,
355,
291,
14,
3813,
14,
525,
63,
4653,
63,
2232,
12,
355,
4673,
14,
21223,
12,
2562,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
8,
277,
12,
333,
63,
4653,
304,
267,
333,
63,
4653,
14,
2709,
1277,
275,
4673,
14,
2709,
1277,
267,
333,
63,
4653,
14,
1078,
63,
10458,
275,
4673,
14,
1078,
63,
10458,
398,
7434,
275,
2400,
26,
715,
267,
291,
14,
3813,
14,
525,
63,
4653,
63,
2232,
8,
4653,
14,
7864,
40,
2160,
12,
7434,
9,
267,
394,
275,
291,
14,
3813,
423,
4653,
63,
5586,
14,
362,
8,
4653,
14,
7864,
40,
2160,
9,
267,
291,
14,
6926,
8,
72,
12,
16195,
14,
5940,
9,
267,
291,
14,
629,
8,
72,
423,
3058,
12,
7434,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
63,
3174,
63,
705,
8,
277,
12,
333,
63,
4653,
304,
267,
333,
63,
4653,
14,
2709,
1277,
275,
4673,
14,
2709,
1277,
267,
333,
63,
4653,
14,
1078,
63,
10458,
275,
4673,
14,
1078,
63,
10458,
398,
347,
663,
63,
28715,
63,
2592,
8,
2592,
304,
288,
340,
6111,
508,
446,
17,
26,
355,
746,
1722,
342,
267,
333,
63,
4653,
14,
409,
63,
28715,
63,
2592,
275,
663,
63,
28715,
63,
2592,
398,
1021,
221,
5432,
8,
16719,
304,
288,
7554,
275,
7554,
14,
37,
2794,
267,
333,
63,
4653,
14,
4653,
14,
2441,
63,
5881,
275,
221,
5432,
398,
291,
14,
1855,
8,
288,
221,
5432,
12,
288,
291,
14,
3813,
14,
525,
63,
4653,
63,
2232,
12,
288,
4673,
14,
21223,
12,
2400,
26,
715,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
768,
1805,
14,
2068,
360,
19343,
14,
1095,
63,
4368,
14,
2921,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
63,
3174,
63,
705,
18,
8,
277,
12
] |
[
2925,
367,
16572,
63,
4368,
14,
647,
1041,
199,
199,
646,
5055,
199,
646,
15502,
199,
646,
7554,
199,
646,
5890,
199,
646,
747,
199,
646,
32212,
199,
646,
4673,
199,
646,
2838,
199,
646,
5672,
199,
646,
984,
199,
646,
5549,
199,
646,
5796,
199,
646,
2882,
199,
504,
2882,
492,
1683,
199,
504,
511,
492,
2291,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
746,
2882,
14,
25755,
360,
19584,
1454,
358,
421,
199,
646,
16195,
199,
504,
16195,
492,
943,
199,
504,
16195,
492,
16572,
63,
4368,
199,
504,
511,
14,
396,
63,
19343,
492,
3778,
465,
511,
63,
1208,
421,
199,
17749,
63,
8974,
275,
1683,
14,
8974,
421,
199,
318,
6766,
2377,
837,
272,
16195,
14,
409,
63,
1430,
63,
3813,
63,
3185,
8,
403,
9,
421,
199,
318,
4002,
63,
4990,
63,
5545,
8,
5545,
304,
272,
327,
7529,
1133,
1240,
7773,
14,
1600,
342,
2952,
314,
1566,
4438,
436,
314,
9759,
272,
327,
787,
16991,
272,
340,
7773,
423,
4990,
365,
488,
26,
267,
372,
272,
7773,
423,
4990,
14,
1600,
342,
272,
7773,
423,
4990,
275,
488,
421,
199,
32,
2796,
14,
11278,
8,
4653,
12,
283,
28536,
787,
440,
3748,
358,
199,
533,
3240,
3283,
2390,
7382,
11274,
2925,
8,
396,
63,
1208,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
1252,
5996,
342,
267,
291,
14,
3813,
275,
16195,
14,
11212,
2390,
7382,
342,
267,
291,
14,
409,
63,
1430,
63,
3813,
8,
277,
14,
3813,
9,
339,
347,
511,
63,
1074,
63,
4653,
8,
277,
304,
267,
291,
14,
1855,
8,
288,
3146,
12,
291,
14,
3813,
423,
1074,
63,
4653,
12,
283,
17,
358,
267,
291,
14,
1855,
8,
288,
1722,
12,
291,
14,
3813,
423,
1074,
63,
4653,
12,
4673,
14,
2709,
1277,
435,
413,
9,
339,
347,
511,
63,
2479,
63,
4653,
63,
889,
63,
2232,
8,
277,
304,
267,
291,
14,
3813,
423,
2479,
63,
4653,
8,
4653,
14,
2709,
1277,
435,
413,
9,
339,
347,
511,
63,
2479,
63,
4653,
63,
21924,
63,
2232,
8,
277,
304,
267,
394,
275,
16195,
14,
5940,
8,
1805,
14,
3346,
1062,
11969,
2574,
4438,
29,
1805,
14,
3346,
1012,
267,
394,
14,
6406,
342,
267,
291,
14,
3813,
423,
4653,
63,
5586,
59,
4653,
14,
2709,
1277,
435,
413,
61,
275,
394,
267,
291,
14,
3813,
14,
2168,
63,
4653,
63,
2232,
275,
1683,
14,
3346,
342,
267,
291,
14,
3813,
423,
2479,
63,
4653,
8,
4653,
14,
2709,
1277,
435,
413,
9,
267,
291,
14,
3813,
14,
2168,
63,
4653,
63,
2232,
14,
479,
63,
3527,
63,
1045,
8,
4653,
14,
2709,
1277,
435,
413,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
63,
2758,
63,
705,
8,
277,
12,
333,
63,
4653,
304,
267,
333,
63,
4653,
14,
2709,
1277,
275,
4673,
14,
2709,
1277,
267,
333,
63,
4653,
14,
1078,
63,
10458,
275,
4673,
14,
1078,
63,
10458,
267,
333,
63,
4653,
14,
409,
63,
28715,
63,
2592,
14,
2441,
63,
5881,
275,
1722,
398,
291,
14,
1855,
8,
288,
6064,
12,
288,
291,
14,
3813,
14,
525,
63,
4653,
63,
2232,
12,
288,
4673,
14,
21223,
12,
2400,
26,
715,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
63,
16675,
63,
705,
8,
277,
12,
333,
63,
4653,
304,
267,
333,
63,
4653,
14,
2709,
1277,
275,
4673,
14,
2709,
1277,
398,
5316,
347,
3486,
63,
16675,
837,
288,
986,
398,
327,
3233,
1471,
440,
506,
282,
1970,
13242,
805,
267,
1970,
79,
63,
1532,
275,
3486,
63,
16675,
267,
1970,
79,
63,
1113,
275,
1970,
79,
63,
1532,
342,
267,
291,
14,
12808,
8,
989,
79,
63,
1113,
14,
1600,
9,
267,
367,
2562,
315,
334,
989,
79,
63,
1532,
12,
1970,
79,
63,
1113,
304,
288,
291,
14,
16499,
8,
355,
3146,
12,
283,
989,
548,
3746,
3913,
506,
1202,
543,
1050,
63,
4653,
63,
2232,
297,
355,
291,
14,
3813,
14,
525,
63,
4653,
63,
2232,
12,
355,
4673,
14,
21223,
12,
2562,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
8,
277,
12,
333,
63,
4653,
304,
267,
333,
63,
4653,
14,
2709,
1277,
275,
4673,
14,
2709,
1277,
267,
333,
63,
4653,
14,
1078,
63,
10458,
275,
4673,
14,
1078,
63,
10458,
398,
7434,
275,
2400,
26,
715,
267,
291,
14,
3813,
14,
525,
63,
4653,
63,
2232,
8,
4653,
14,
7864,
40,
2160,
12,
7434,
9,
267,
394,
275,
291,
14,
3813,
423,
4653,
63,
5586,
14,
362,
8,
4653,
14,
7864,
40,
2160,
9,
267,
291,
14,
6926,
8,
72,
12,
16195,
14,
5940,
9,
267,
291,
14,
629,
8,
72,
423,
3058,
12,
7434,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
63,
3174,
63,
705,
8,
277,
12,
333,
63,
4653,
304,
267,
333,
63,
4653,
14,
2709,
1277,
275,
4673,
14,
2709,
1277,
267,
333,
63,
4653,
14,
1078,
63,
10458,
275,
4673,
14,
1078,
63,
10458,
398,
347,
663,
63,
28715,
63,
2592,
8,
2592,
304,
288,
340,
6111,
508,
446,
17,
26,
355,
746,
1722,
342,
267,
333,
63,
4653,
14,
409,
63,
28715,
63,
2592,
275,
663,
63,
28715,
63,
2592,
398,
1021,
221,
5432,
8,
16719,
304,
288,
7554,
275,
7554,
14,
37,
2794,
267,
333,
63,
4653,
14,
4653,
14,
2441,
63,
5881,
275,
221,
5432,
398,
291,
14,
1855,
8,
288,
221,
5432,
12,
288,
291,
14,
3813,
14,
525,
63,
4653,
63,
2232,
12,
288,
4673,
14,
21223,
12,
2400,
26,
715,
9,
339,
768,
1805,
14,
2068,
360,
19343,
14,
11864,
63,
4368,
14,
4653,
358,
272,
768,
1805,
14,
2068,
360,
19343,
14,
1095,
63,
4368,
14,
2921,
358,
272,
347,
511,
63,
525,
63,
4653,
63,
2232,
63,
3174,
63,
705,
18,
8,
277,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
Conceiva/MezzmoKodiPlugin
|
common.py
|
1
|
2918
|
import xbmc
import xbmcaddon
import inspect
import os
import sys
import socket
import re
class printDebug:
def __init__(self, main, sub=None):
self.main=main
if sub:
self.sub="."+sub
else:
self.sub=''
self.level=settings.get_debug()
self.DEBUG_OFF=0
self.DEBUG_INFO=1
self.DEBUG_DEBUG=2
self.DEBUG_DEBUGPLUS=3
self.token_regex=re.compile('-Token=[a-z|0-9].*[&|$]')
self.ip_regex=re.compile('\.\d{1,3}\.\d{1,3}\.')
self.DEBUG_MAP={ self.DEBUG_OFF : "off",
self.DEBUG_INFO : "info",
self.DEBUG_DEBUG : "debug",
self.DEBUG_DEBUGPLUS : "debug+"}
def get_name(self, level):
return self.DEBUG_MAP[level]
def error(self,message):
return self.__printDebug(message, 0)
def info(self, message):
return self.__printDebug(message, 1)
def debug(self, message):
return self.__printDebug(message, 2)
def dev(self, message):
return self.__printDebug(message, 3)
def debugplus(self, message):
return self.__printDebug(message, 3)
def __printDebug( self, msg, level=1 ):
if self.level >= level :
#msg=self.token_regex.sub("-Token=XXXXXXXXXX&", str(msg))
#msg=self.ip_regex.sub(".X.X.", msg)
print "%s%s -> %s : %s" % (self.main, self.sub, inspect.stack(0)[2][3], msg)
return
def __call__(self, msg, level=1):
return self.__printDebug(msg, level)
def get_platform( ):
if xbmc.getCondVisibility('system.platform.osx'):
return "OSX"
elif xbmc.getCondVisibility('system.platform.atv2'):
return "ATV2"
elif xbmc.getCondVisibility('system.platform.ios'):
return "iOS"
elif xbmc.getCondVisibility('system.platform.windows'):
return "Windows"
elif xbmc.getCondVisibility('system.platform.linux'):
return "Linux/RPi"
elif xbmc.getCondVisibility('system.platform.android'):
return "Linux/Android"
return "Unknown"
def setup_python_locations():
setup={}
setup['__addon__'] = xbmcaddon.Addon()
setup['__cachedir__'] = setup['__addon__'].getAddonInfo('profile')
setup['__cwd__'] = xbmc.translatePath(setup['__addon__'].getAddonInfo('path')).decode('utf-8')
setup['__version__'] = setup['__addon__'].getAddonInfo('version')
setup['__resources__'] = xbmc.translatePath(os.path.join(setup['__cwd__'], 'resources', 'lib'))
sys.path.append(setup['__resources__'])
return setup
GLOBAL_SETUP=setup_python_locations()
GLOBAL_SETUP['platform']=get_platform()
GENERIC_THUMBNAIL = "%s/resource/thumb.png" % GLOBAL_SETUP['__cwd__']
REQUIRED_REVISION="1.0.7"
|
gpl-2.0
|
[
646,
11709,
202,
199,
646,
11709,
9291,
202,
199,
646,
6485,
202,
199,
646,
747,
202,
199,
646,
984,
202,
199,
646,
2838,
202,
199,
646,
295,
2999,
199,
533,
870,
7084,
26,
2958,
347,
636,
826,
721,
277,
12,
2446,
12,
1007,
29,
403,
304,
4341,
291,
14,
973,
29,
973,
1039,
340,
1007,
26,
1675,
291,
14,
954,
628,
2122,
11,
954,
1039,
587,
26,
1675,
291,
14,
954,
19070,
4341,
291,
14,
1896,
29,
1751,
14,
362,
63,
1757,
342,
4341,
291,
14,
5287,
63,
7517,
29,
16,
1039,
291,
14,
5287,
63,
4531,
29,
17,
1039,
291,
14,
5287,
63,
5287,
29,
18,
1039,
291,
14,
5287,
63,
5287,
27280,
29,
19,
1039,
291,
14,
1418,
63,
3821,
29,
264,
14,
2014,
3654,
3264,
1524,
65,
13,
90,
92,
16,
13,
25,
1055,
23033,
6,
92,
4,
10374,
1039,
291,
14,
711,
63,
3821,
29,
264,
14,
2014,
2258,
3134,
68,
91,
17,
12,
19,
4988,
3134,
68,
91,
17,
12,
19,
4988,
2659,
260,
4341,
291,
14,
5287,
63,
5443,
3126,
291,
14,
5287,
63,
7517,
755,
520,
298,
1997,
401,
202,
586,
291,
14,
5287,
63,
4531,
420,
520,
298,
815,
401,
202,
586,
291,
14,
5287,
63,
5287,
258,
520,
298,
1757,
401,
202,
586,
291,
14,
5287,
63,
5287,
27280,
520,
298,
1757,
11,
3570,
2958,
347,
664,
63,
354,
8,
277,
12,
2166,
304,
1039,
372,
291,
14,
5287,
63,
5443,
59,
1896,
61,
2958,
347,
1125,
8,
277,
12,
1188,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
378,
9,
260,
2958,
347,
2256,
8,
277,
12,
1245,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
413,
9,
2958,
347,
3105,
8,
277,
12,
1245,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
499,
9,
2958,
347,
4866,
8,
277,
12,
1245,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
650,
9,
2958,
347,
3105,
6666,
8,
277,
12,
1245,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
650,
9,
2958,
347,
636,
1361,
7084,
8,
291,
12,
1499,
12,
2166,
29,
17,
3461,
1039,
340,
291,
14,
1896,
2356,
2166,
520,
1675,
327,
1328,
29,
277,
14,
1418,
63,
3821,
14,
954,
6096,
3264,
29,
13312,
2483,
6,
401,
620,
8,
1328,
430,
1675,
327,
1328,
29,
277,
14,
711,
63,
3821,
14,
954,
9520,
56,
14,
56,
4765,
1499,
9,
1675,
870,
2071,
83,
5,
83,
1035,
450,
83,
520,
450,
83,
2,
450,
334,
277,
14,
973,
12,
291,
14,
954,
12,
6485,
14,
2340,
8,
16,
2788,
18,
1527,
19,
467,
1499,
9,
1039,
372,
2958,
347,
636,
1250,
721,
277,
12,
1499,
12,
2166,
29,
17,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1328,
12,
2166,
9,
2999,
199,
318,
664,
63,
3246,
8,
3461,
1128,
340,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
28197,
735,
1039,
372,
298,
25160,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
292,
86,
18,
735,
1039,
372,
298,
619,
54,
18,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
9207,
735,
1039,
372,
298,
73,
3100,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
8258,
735,
1039,
372,
298,
8647,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
5135,
735,
1039,
372,
298,
14091,
15,
50,
10542,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
6238,
735,
30199,
372,
298,
14091,
15,
20762,
2,
1128,
372,
298,
5912,
2,
2999,
199,
318,
3272,
63,
1548,
63,
8022,
837,
1128,
3272,
7622,
1128,
3272,
13742,
9291,
17501,
275,
11709,
9291,
14,
19654,
342,
1128,
3272,
13742,
1637,
694,
17501,
275,
3272,
13742,
9291,
363,
2278,
362,
19654,
2354,
360,
2913,
358,
1128,
3272,
13742,
6525,
17501,
258,
275,
11709,
14,
5275,
2042,
8,
2758,
13742,
9291,
363,
2278,
362,
19654,
2354,
360,
515,
11103,
2708,
360,
1624,
13,
24,
358,
1128,
3272,
13742,
1023,
17501,
275,
3272,
13742,
9291,
363,
2278,
362,
19654,
2354,
360,
1023,
358,
2958,
3272,
13742,
4435,
17501,
275,
11709,
14,
5275,
2042,
8,
736,
14,
515,
14,
904,
8,
2758,
13742,
6525,
363,
995,
283,
4435,
297,
283,
773,
1333,
1128,
984,
14,
515,
14,
740,
8,
2758,
13742,
4435,
363,
1105,
1128,
372,
3272,
463,
2999,
199,
13808,
63,
20836,
29,
2758,
63,
1548,
63,
8022,
342,
202,
199,
13808,
63,
20836,
459,
3246,
13784,
362,
63,
3246,
342,
202,
199,
29395,
63,
2080,
2639,
18273,
6593,
275,
2071,
83,
15,
1927,
15,
16534,
14,
4524,
2,
450,
598,
12667,
63,
20836,
13742,
6525,
17501,
202,
199,
12496,
63,
907,
18775,
628,
17,
14,
16,
14,
23,
2,
10060,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11709,
202,
199,
646,
11709,
9291,
202,
199,
646,
6485,
202,
199,
646,
747,
202,
199,
646,
984,
202,
199,
646,
2838,
202,
199,
646,
295,
2999,
199,
533,
870,
7084,
26,
2958,
347,
636,
826,
721,
277,
12,
2446,
12,
1007,
29,
403,
304,
4341,
291,
14,
973,
29,
973,
1039,
340,
1007,
26,
1675,
291,
14,
954,
628,
2122,
11,
954,
1039,
587,
26,
1675,
291,
14,
954,
19070,
4341,
291,
14,
1896,
29,
1751,
14,
362,
63,
1757,
342,
4341,
291,
14,
5287,
63,
7517,
29,
16,
1039,
291,
14,
5287,
63,
4531,
29,
17,
1039,
291,
14,
5287,
63,
5287,
29,
18,
1039,
291,
14,
5287,
63,
5287,
27280,
29,
19,
1039,
291,
14,
1418,
63,
3821,
29,
264,
14,
2014,
3654,
3264,
1524,
65,
13,
90,
92,
16,
13,
25,
1055,
23033,
6,
92,
4,
10374,
1039,
291,
14,
711,
63,
3821,
29,
264,
14,
2014,
2258,
3134,
68,
91,
17,
12,
19,
4988,
3134,
68,
91,
17,
12,
19,
4988,
2659,
260,
4341,
291,
14,
5287,
63,
5443,
3126,
291,
14,
5287,
63,
7517,
755,
520,
298,
1997,
401,
202,
586,
291,
14,
5287,
63,
4531,
420,
520,
298,
815,
401,
202,
586,
291,
14,
5287,
63,
5287,
258,
520,
298,
1757,
401,
202,
586,
291,
14,
5287,
63,
5287,
27280,
520,
298,
1757,
11,
3570,
2958,
347,
664,
63,
354,
8,
277,
12,
2166,
304,
1039,
372,
291,
14,
5287,
63,
5443,
59,
1896,
61,
2958,
347,
1125,
8,
277,
12,
1188,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
378,
9,
260,
2958,
347,
2256,
8,
277,
12,
1245,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
413,
9,
2958,
347,
3105,
8,
277,
12,
1245,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
499,
9,
2958,
347,
4866,
8,
277,
12,
1245,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
650,
9,
2958,
347,
3105,
6666,
8,
277,
12,
1245,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1188,
12,
650,
9,
2958,
347,
636,
1361,
7084,
8,
291,
12,
1499,
12,
2166,
29,
17,
3461,
1039,
340,
291,
14,
1896,
2356,
2166,
520,
1675,
327,
1328,
29,
277,
14,
1418,
63,
3821,
14,
954,
6096,
3264,
29,
13312,
2483,
6,
401,
620,
8,
1328,
430,
1675,
327,
1328,
29,
277,
14,
711,
63,
3821,
14,
954,
9520,
56,
14,
56,
4765,
1499,
9,
1675,
870,
2071,
83,
5,
83,
1035,
450,
83,
520,
450,
83,
2,
450,
334,
277,
14,
973,
12,
291,
14,
954,
12,
6485,
14,
2340,
8,
16,
2788,
18,
1527,
19,
467,
1499,
9,
1039,
372,
2958,
347,
636,
1250,
721,
277,
12,
1499,
12,
2166,
29,
17,
304,
1039,
372,
291,
855,
1361,
7084,
8,
1328,
12,
2166,
9,
2999,
199,
318,
664,
63,
3246,
8,
3461,
1128,
340,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
28197,
735,
1039,
372,
298,
25160,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
292,
86,
18,
735,
1039,
372,
298,
619,
54,
18,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
9207,
735,
1039,
372,
298,
73,
3100,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
8258,
735,
1039,
372,
298,
8647,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
5135,
735,
1039,
372,
298,
14091,
15,
50,
10542,
2,
1128,
916,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
6238,
735,
30199,
372,
298,
14091,
15,
20762,
2,
1128,
372,
298,
5912,
2,
2999,
199,
318,
3272,
63,
1548,
63,
8022,
837,
1128,
3272,
7622,
1128,
3272,
13742,
9291,
17501,
275,
11709,
9291,
14,
19654,
342,
1128,
3272,
13742,
1637,
694,
17501,
275,
3272,
13742,
9291,
363,
2278,
362,
19654,
2354,
360,
2913,
358,
1128,
3272,
13742,
6525,
17501,
258,
275,
11709,
14,
5275,
2042,
8,
2758,
13742,
9291,
363,
2278,
362,
19654,
2354,
360,
515,
11103,
2708,
360,
1624,
13,
24,
358,
1128,
3272,
13742,
1023,
17501,
275,
3272,
13742,
9291,
363,
2278,
362,
19654,
2354,
360,
1023,
358,
2958,
3272,
13742,
4435,
17501,
275,
11709,
14,
5275,
2042,
8,
736,
14,
515,
14,
904,
8,
2758,
13742,
6525,
363,
995,
283,
4435,
297,
283,
773,
1333,
1128,
984,
14,
515,
14,
740,
8,
2758,
13742,
4435,
363,
1105,
1128,
372,
3272,
463,
2999,
199,
13808,
63,
20836,
29,
2758,
63,
1548,
63,
8022,
342,
202,
199,
13808,
63,
20836,
459,
3246,
13784,
362,
63,
3246,
342,
202,
199,
29395,
63,
2080,
2639,
18273,
6593,
275,
2071,
83,
15,
1927,
15,
16534,
14,
4524,
2,
450,
598,
12667,
63,
20836,
13742,
6525,
17501,
202,
199,
12496,
63,
907,
18775,
628,
17,
14,
16,
14,
23,
2,
10060,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
maheshp/novatest
|
nova/virt/disk/mount/nbd.py
|
13
|
4153
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 Red Hat, 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.
"""Support for mounting images with qemu-nbd."""
import os
import random
import re
import time
from oslo.config import cfg
from nova.openstack.common import log as logging
from nova import utils
from nova.virt.disk.mount import api
LOG = logging.getLogger(__name__)
nbd_opts = [
cfg.IntOpt('timeout_nbd',
default=10,
help='time to wait for a NBD device coming up'),
]
CONF = cfg.CONF
CONF.register_opts(nbd_opts)
NBD_DEVICE_RE = re.compile('nbd[0-9]+')
class NbdMount(api.Mount):
"""qemu-nbd support disk images."""
mode = 'nbd'
def _detect_nbd_devices(self):
"""Detect nbd device files."""
return filter(NBD_DEVICE_RE.match, os.listdir('/sys/block/'))
def _find_unused(self, devices):
for device in devices:
if not os.path.exists(os.path.join('/sys/block/', device, 'pid')):
return device
LOG.warn(_('No free nbd devices'))
return None
def _allocate_nbd(self):
if not os.path.exists('/sys/block/nbd0'):
LOG.error(_('nbd module not loaded'))
self.error = _('nbd unavailable: module not loaded')
return None
devices = self._detect_nbd_devices()
random.shuffle(devices)
device = self._find_unused(devices)
if not device:
# really want to log this info, not raise
self.error = _('No free nbd devices')
return None
return os.path.join('/dev', device)
def _read_pid_file(self, pidfile):
# This is for unit test convenience
with open(pidfile) as f:
pid = int(f.readline())
return pid
def _inner_get_dev(self):
device = self._allocate_nbd()
if not device:
return False
# NOTE(mikal): qemu-nbd will return an error if the device file is
# already in use.
LOG.debug(_('Get nbd device %(dev)s for %(imgfile)s'),
{'dev': device, 'imgfile': self.image})
_out, err = utils.trycmd('qemu-nbd', '-c', device, self.image,
run_as_root=True)
if err:
self.error = _('qemu-nbd error: %s') % err
LOG.info(_('NBD mount error: %s'), self.error)
return False
# NOTE(vish): this forks into another process, so give it a chance
# to set up before continuing
pidfile = "/sys/block/%s/pid" % os.path.basename(device)
for _i in range(CONF.timeout_nbd):
if os.path.exists(pidfile):
self.device = device
break
time.sleep(1)
else:
self.error = _('nbd device %s did not show up') % device
LOG.info(_('NBD mount error: %s'), self.error)
# Cleanup
_out, err = utils.trycmd('qemu-nbd', '-d', device,
run_as_root=True)
if err:
LOG.warn(_('Detaching from erroneous nbd device returned '
'error: %s'), err)
return False
self.error = ''
self.linked = True
return True
def get_dev(self):
"""Retry requests for NBD devices."""
return self._get_dev_retry_helper()
def unget_dev(self):
if not self.linked:
return
LOG.debug(_('Release nbd device %s'), self.device)
utils.execute('qemu-nbd', '-d', self.device, run_as_root=True)
self.linked = False
self.device = None
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7760,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
624,
11532,
367,
10760,
316,
5935,
543,
1894,
14756,
13,
78,
3691,
1041,
199,
199,
646,
747,
199,
646,
2196,
199,
646,
295,
199,
646,
900,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
5913,
492,
3778,
199,
504,
5913,
14,
4549,
14,
4032,
14,
3956,
492,
2986,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
78,
3691,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
2593,
63,
78,
3691,
297,
2049,
849,
29,
709,
12,
2049,
1720,
534,
521,
370,
3618,
367,
282,
653,
11156,
2243,
17262,
1536,
659,
272,
1622,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
78,
3691,
63,
3291,
9,
199,
199,
46,
11156,
63,
10555,
63,
907,
275,
295,
14,
2014,
360,
78,
3691,
59,
16,
13,
25,
2807,
358,
421,
199,
533,
653,
3691,
24467,
8,
1246,
14,
24467,
304,
272,
408,
19839,
13,
78,
3691,
2291,
4543,
5935,
1041,
272,
818,
275,
283,
78,
3691,
7,
339,
347,
485,
13552,
63,
78,
3691,
63,
6410,
8,
277,
304,
267,
408,
20064,
302,
3691,
2243,
1584,
1041,
267,
372,
2457,
8,
46,
11156,
63,
10555,
63,
907,
14,
1431,
12,
747,
14,
7374,
2336,
1274,
15,
1457,
15,
1333,
339,
347,
485,
1623,
63,
8618,
8,
277,
12,
7256,
304,
267,
367,
2243,
315,
7256,
26,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
2336,
1274,
15,
1457,
3678,
2243,
12,
283,
3150,
8109,
355,
372,
2243,
267,
5051,
14,
4050,
6723,
1944,
2867,
302,
3691,
7256,
1333,
267,
372,
488,
339,
347,
485,
12991,
63,
78,
3691,
8,
277,
304,
267,
340,
440,
747,
14,
515,
14,
2444,
2336,
1274,
15,
1457,
15,
78,
3691,
16,
735,
288,
5051,
14,
705,
6723,
78,
3691,
859,
440,
6511,
1333,
288,
291,
14,
705,
275,
4018,
78,
3691,
18735,
26,
859,
440,
6511,
358,
288,
372,
488,
398,
7256,
275,
291,
423,
13552,
63,
78,
3691,
63,
6410,
342,
267,
2196,
14,
11777,
8,
6410,
9,
267,
2243,
275,
291,
423,
1623,
63,
8618,
8,
6410,
9,
267,
340,
440,
2243,
26,
288,
327,
7710,
2934,
370,
943,
642,
2256,
12,
440,
746,
288,
291,
14,
705,
275,
4018,
1944,
2867,
302,
3691,
7256,
358,
288,
372,
488,
267,
372,
747,
14,
515,
14,
904,
2336,
2374,
297,
2243,
9,
339,
347,
485,
739,
63,
3150,
63,
493,
8,
277,
12,
32739,
304,
267,
327,
961,
365,
367,
4137,
511,
16777,
267,
543,
1551,
8,
21957,
9,
465,
289,
26,
288,
4422,
275,
1109,
8,
70,
14,
6407,
1012,
267,
372,
4422,
339,
347,
485,
5216,
63,
362,
63,
2374,
8,
277,
304,
267,
2243,
275,
291,
423,
12991,
63,
78,
3691,
342,
267,
340,
440,
2243,
26,
288,
372,
756,
398,
327,
6944,
8,
2664,
26446,
304,
1894,
14756,
13,
78,
3691,
911,
372,
376,
1125,
340,
314,
2243,
570,
365,
267,
327,
2575,
315,
675,
14,
267,
5051,
14,
1757,
6723,
1002,
302,
3691,
2243,
2818,
2374,
9,
83,
367,
2818,
4060,
493,
9,
83,
659,
2116,
791,
2374,
356,
2243,
12,
283,
4060,
493,
356,
291,
14,
1569,
1552,
267,
485,
548,
12,
2329,
275,
3778,
14,
893,
1760,
360,
19839,
13,
78,
3691,
297,
2475,
67,
297,
2243,
12,
291,
14,
1569,
12,
639,
1255,
63,
305,
63,
1231,
29,
549,
9,
267,
340,
2329,
26,
288,
291,
14,
705,
275,
4018,
19839,
13,
78,
3691,
1125,
26,
450,
83,
358,
450,
2329,
288,
5051,
14,
815,
6723,
46,
11156,
10760,
1125,
26,
450,
83,
659,
291,
14,
705,
9,
288,
372,
756,
398,
327,
6944,
8,
86,
2453,
304,
642,
367,
6080,
1901,
4573,
2112,
12,
880,
8120,
652,
282,
22044,
267,
327,
370,
663,
1536,
2544,
32620,
267,
32739,
275,
3286,
1274,
15,
1457,
3149,
83,
15,
3150,
2,
450,
747,
14,
515,
14,
4846,
8,
1782,
9,
267,
367,
485,
73,
315,
1425,
8,
3103,
14,
2593,
63,
78,
3691,
304,
288,
340,
747,
14,
515,
14,
2444,
8,
21957,
304,
355,
291,
14,
1782,
275,
2243,
355,
2059,
288,
900,
14,
4532,
8,
17,
9,
267,
587,
26,
288,
291,
14,
705,
275,
4018,
78,
3691,
2243,
450,
83,
8103,
440,
2498,
1536,
358,
450,
2243,
288,
5051,
14,
815,
6723,
46,
11156,
10760,
1125,
26,
450,
83,
659,
291,
14,
705,
9,
953,
327,
30022,
288,
485,
548,
12,
2329,
275,
3778,
14,
893,
1760,
360,
19839,
13,
78,
3691,
297,
2475,
68,
297,
2243,
12,
3660,
1255,
63,
305,
63,
1231,
29,
549,
9,
288,
340,
2329,
26,
355,
5051,
14,
4050,
6723,
21097,
23302,
687,
2329,
368,
1785,
302,
3691,
2243,
2138,
283,
2574,
283,
705,
26,
450,
83,
659,
2329,
9,
288,
372,
756,
398,
291,
14,
705,
275,
2125,
267,
291,
14,
12751,
275,
715,
267,
372,
715,
339,
347,
664,
63,
2374,
8,
277,
304,
267,
408,
12989,
4145,
367,
653,
11156,
7256,
1041,
267,
372,
291,
423,
362,
63,
2374,
63,
7154,
63,
3676,
342,
339,
347,
625,
362,
63,
2374,
8,
277,
304,
267,
340,
440,
291,
14,
12751,
26,
288,
372,
267,
5051,
14,
1757,
6723
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7760,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
624,
11532,
367,
10760,
316,
5935,
543,
1894,
14756,
13,
78,
3691,
1041,
199,
199,
646,
747,
199,
646,
2196,
199,
646,
295,
199,
646,
900,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
5913,
492,
3778,
199,
504,
5913,
14,
4549,
14,
4032,
14,
3956,
492,
2986,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
78,
3691,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
2593,
63,
78,
3691,
297,
2049,
849,
29,
709,
12,
2049,
1720,
534,
521,
370,
3618,
367,
282,
653,
11156,
2243,
17262,
1536,
659,
272,
1622,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
78,
3691,
63,
3291,
9,
199,
199,
46,
11156,
63,
10555,
63,
907,
275,
295,
14,
2014,
360,
78,
3691,
59,
16,
13,
25,
2807,
358,
421,
199,
533,
653,
3691,
24467,
8,
1246,
14,
24467,
304,
272,
408,
19839,
13,
78,
3691,
2291,
4543,
5935,
1041,
272,
818,
275,
283,
78,
3691,
7,
339,
347,
485,
13552,
63,
78,
3691,
63,
6410,
8,
277,
304,
267,
408,
20064,
302,
3691,
2243,
1584,
1041,
267,
372,
2457,
8,
46,
11156,
63,
10555,
63,
907,
14,
1431,
12,
747,
14,
7374,
2336,
1274,
15,
1457,
15,
1333,
339,
347,
485,
1623,
63,
8618,
8,
277,
12,
7256,
304,
267,
367,
2243,
315,
7256,
26,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
2336,
1274,
15,
1457,
3678,
2243,
12,
283,
3150,
8109,
355,
372,
2243,
267,
5051,
14,
4050,
6723,
1944,
2867,
302,
3691,
7256,
1333,
267,
372,
488,
339,
347,
485,
12991,
63,
78,
3691,
8,
277,
304,
267,
340,
440,
747,
14,
515,
14,
2444,
2336,
1274,
15,
1457,
15,
78,
3691,
16,
735,
288,
5051,
14,
705,
6723,
78,
3691,
859,
440,
6511,
1333,
288,
291,
14,
705,
275,
4018,
78,
3691,
18735,
26,
859,
440,
6511,
358,
288,
372,
488,
398,
7256,
275,
291,
423,
13552,
63,
78,
3691,
63,
6410,
342,
267,
2196,
14,
11777,
8,
6410,
9,
267,
2243,
275,
291,
423,
1623,
63,
8618,
8,
6410,
9,
267,
340,
440,
2243,
26,
288,
327,
7710,
2934,
370,
943,
642,
2256,
12,
440,
746,
288,
291,
14,
705,
275,
4018,
1944,
2867,
302,
3691,
7256,
358,
288,
372,
488,
267,
372,
747,
14,
515,
14,
904,
2336,
2374,
297,
2243,
9,
339,
347,
485,
739,
63,
3150,
63,
493,
8,
277,
12,
32739,
304,
267,
327,
961,
365,
367,
4137,
511,
16777,
267,
543,
1551,
8,
21957,
9,
465,
289,
26,
288,
4422,
275,
1109,
8,
70,
14,
6407,
1012,
267,
372,
4422,
339,
347,
485,
5216,
63,
362,
63,
2374,
8,
277,
304,
267,
2243,
275,
291,
423,
12991,
63,
78,
3691,
342,
267,
340,
440,
2243,
26,
288,
372,
756,
398,
327,
6944,
8,
2664,
26446,
304,
1894,
14756,
13,
78,
3691,
911,
372,
376,
1125,
340,
314,
2243,
570,
365,
267,
327,
2575,
315,
675,
14,
267,
5051,
14,
1757,
6723,
1002,
302,
3691,
2243,
2818,
2374,
9,
83,
367,
2818,
4060,
493,
9,
83,
659,
2116,
791,
2374,
356,
2243,
12,
283,
4060,
493,
356,
291,
14,
1569,
1552,
267,
485,
548,
12,
2329,
275,
3778,
14,
893,
1760,
360,
19839,
13,
78,
3691,
297,
2475,
67,
297,
2243,
12,
291,
14,
1569,
12,
639,
1255,
63,
305,
63,
1231,
29,
549,
9,
267,
340,
2329,
26,
288,
291,
14,
705,
275,
4018,
19839,
13,
78,
3691,
1125,
26,
450,
83,
358,
450,
2329,
288,
5051,
14,
815,
6723,
46,
11156,
10760,
1125,
26,
450,
83,
659,
291,
14,
705,
9,
288,
372,
756,
398,
327,
6944,
8,
86,
2453,
304,
642,
367,
6080,
1901,
4573,
2112,
12,
880,
8120,
652,
282,
22044,
267,
327,
370,
663,
1536,
2544,
32620,
267,
32739,
275,
3286,
1274,
15,
1457,
3149,
83,
15,
3150,
2,
450,
747,
14,
515,
14,
4846,
8,
1782,
9,
267,
367,
485,
73,
315,
1425,
8,
3103,
14,
2593,
63,
78,
3691,
304,
288,
340,
747,
14,
515,
14,
2444,
8,
21957,
304,
355,
291,
14,
1782,
275,
2243,
355,
2059,
288,
900,
14,
4532,
8,
17,
9,
267,
587,
26,
288,
291,
14,
705,
275,
4018,
78,
3691,
2243,
450,
83,
8103,
440,
2498,
1536,
358,
450,
2243,
288,
5051,
14,
815,
6723,
46,
11156,
10760,
1125,
26,
450,
83,
659,
291,
14,
705,
9,
953,
327,
30022,
288,
485,
548,
12,
2329,
275,
3778,
14,
893,
1760,
360,
19839,
13,
78,
3691,
297,
2475,
68,
297,
2243,
12,
3660,
1255,
63,
305,
63,
1231,
29,
549,
9,
288,
340,
2329,
26,
355,
5051,
14,
4050,
6723,
21097,
23302,
687,
2329,
368,
1785,
302,
3691,
2243,
2138,
283,
2574,
283,
705,
26,
450,
83,
659,
2329,
9,
288,
372,
756,
398,
291,
14,
705,
275,
2125,
267,
291,
14,
12751,
275,
715,
267,
372,
715,
339,
347,
664,
63,
2374,
8,
277,
304,
267,
408,
12989,
4145,
367,
653,
11156,
7256,
1041,
267,
372,
291,
423,
362,
63,
2374,
63,
7154,
63,
3676,
342,
339,
347,
625,
362,
63,
2374,
8,
277,
304,
267,
340,
440,
291,
14,
12751,
26,
288,
372,
267,
5051,
14,
1757,
6723,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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|
14
|
1099
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010 OpenERP S.A. http://www.openerp.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from test_osv import *
from test_translate import *
# 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,
7129,
7653,
428,
14,
33,
14,
1455,
921,
1544,
14,
11267,
14,
957,
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,
511,
63,
4795,
492,
627,
199,
504,
511,
63,
5275,
492,
627,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
7129,
7653,
428,
14,
33,
14,
1455,
921,
1544,
14,
11267,
14,
957,
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,
511,
63,
4795,
492,
627,
199,
504,
511,
63,
5275,
492,
627,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
lafayette/JBTT
|
framework/framework/pym/yaml/__init__.py
|
112
|
9273
|
from error import *
from tokens import *
from events import *
from nodes import *
from loader import *
from dumper import *
__version__ = '3.09'
try:
from cyaml import *
__with_libyaml__ = True
except ImportError:
__with_libyaml__ = False
def scan(stream, Loader=Loader):
"""
Scan a YAML stream and produce scanning tokens.
"""
loader = Loader(stream)
while loader.check_token():
yield loader.get_token()
def parse(stream, Loader=Loader):
"""
Parse a YAML stream and produce parsing events.
"""
loader = Loader(stream)
while loader.check_event():
yield loader.get_event()
def compose(stream, Loader=Loader):
"""
Parse the first YAML document in a stream
and produce the corresponding representation tree.
"""
loader = Loader(stream)
return loader.get_single_node()
def compose_all(stream, Loader=Loader):
"""
Parse all YAML documents in a stream
and produce corresponding representation trees.
"""
loader = Loader(stream)
while loader.check_node():
yield loader.get_node()
def load(stream, Loader=Loader):
"""
Parse the first YAML document in a stream
and produce the corresponding Python object.
"""
loader = Loader(stream)
return loader.get_single_data()
def load_all(stream, Loader=Loader):
"""
Parse all YAML documents in a stream
and produce corresponding Python objects.
"""
loader = Loader(stream)
while loader.check_data():
yield loader.get_data()
def safe_load(stream):
"""
Parse the first YAML document in a stream
and produce the corresponding Python object.
Resolve only basic YAML tags.
"""
return load(stream, SafeLoader)
def safe_load_all(stream):
"""
Parse all YAML documents in a stream
and produce corresponding Python objects.
Resolve only basic YAML tags.
"""
return load_all(stream, SafeLoader)
def emit(events, stream=None, Dumper=Dumper,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None):
"""
Emit YAML parsing events into a stream.
If stream is None, return the produced string instead.
"""
getvalue = None
if stream is None:
from StringIO import StringIO
stream = StringIO()
getvalue = stream.getvalue
dumper = Dumper(stream, canonical=canonical, indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break)
for event in events:
dumper.emit(event)
if getvalue:
return getvalue()
def serialize_all(nodes, stream=None, Dumper=Dumper,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding='utf-8', explicit_start=None, explicit_end=None,
version=None, tags=None):
"""
Serialize a sequence of representation trees into a YAML stream.
If stream is None, return the produced string instead.
"""
getvalue = None
if stream is None:
if encoding is None:
from StringIO import StringIO
else:
from cStringIO import StringIO
stream = StringIO()
getvalue = stream.getvalue
dumper = Dumper(stream, canonical=canonical, indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break,
encoding=encoding, version=version, tags=tags,
explicit_start=explicit_start, explicit_end=explicit_end)
dumper.open()
for node in nodes:
dumper.serialize(node)
dumper.close()
if getvalue:
return getvalue()
def serialize(node, stream=None, Dumper=Dumper, **kwds):
"""
Serialize a representation tree into a YAML stream.
If stream is None, return the produced string instead.
"""
return serialize_all([node], stream, Dumper=Dumper, **kwds)
def dump_all(documents, stream=None, Dumper=Dumper,
default_style=None, default_flow_style=None,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding='utf-8', explicit_start=None, explicit_end=None,
version=None, tags=None):
"""
Serialize a sequence of Python objects into a YAML stream.
If stream is None, return the produced string instead.
"""
getvalue = None
if stream is None:
if encoding is None:
from StringIO import StringIO
else:
from cStringIO import StringIO
stream = StringIO()
getvalue = stream.getvalue
dumper = Dumper(stream, default_style=default_style,
default_flow_style=default_flow_style,
canonical=canonical, indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break,
encoding=encoding, version=version, tags=tags,
explicit_start=explicit_start, explicit_end=explicit_end)
dumper.open()
for data in documents:
dumper.represent(data)
dumper.close()
if getvalue:
return getvalue()
def dump(data, stream=None, Dumper=Dumper, **kwds):
"""
Serialize a Python object into a YAML stream.
If stream is None, return the produced string instead.
"""
return dump_all([data], stream, Dumper=Dumper, **kwds)
def safe_dump_all(documents, stream=None, **kwds):
"""
Serialize a sequence of Python objects into a YAML stream.
Produce only basic YAML tags.
If stream is None, return the produced string instead.
"""
return dump_all(documents, stream, Dumper=SafeDumper, **kwds)
def safe_dump(data, stream=None, **kwds):
"""
Serialize a Python object into a YAML stream.
Produce only basic YAML tags.
If stream is None, return the produced string instead.
"""
return dump_all([data], stream, Dumper=SafeDumper, **kwds)
def add_implicit_resolver(tag, regexp, first=None,
Loader=Loader, Dumper=Dumper):
"""
Add an implicit scalar detector.
If an implicit scalar value matches the given regexp,
the corresponding tag is assigned to the scalar.
first is a sequence of possible initial characters or None.
"""
Loader.add_implicit_resolver(tag, regexp, first)
Dumper.add_implicit_resolver(tag, regexp, first)
def add_path_resolver(tag, path, kind=None, Loader=Loader, Dumper=Dumper):
"""
Add a path based resolver for the given tag.
A path is a list of keys that forms a path
to a node in the representation tree.
Keys can be string values, integers, or None.
"""
Loader.add_path_resolver(tag, path, kind)
Dumper.add_path_resolver(tag, path, kind)
def add_constructor(tag, constructor, Loader=Loader):
"""
Add a constructor for the given tag.
Constructor is a function that accepts a Loader instance
and a node object and produces the corresponding Python object.
"""
Loader.add_constructor(tag, constructor)
def add_multi_constructor(tag_prefix, multi_constructor, Loader=Loader):
"""
Add a multi-constructor for the given tag prefix.
Multi-constructor is called for a node if its tag starts with tag_prefix.
Multi-constructor accepts a Loader instance, a tag suffix,
and a node object and produces the corresponding Python object.
"""
Loader.add_multi_constructor(tag_prefix, multi_constructor)
def add_representer(data_type, representer, Dumper=Dumper):
"""
Add a representer for the given type.
Representer is a function accepting a Dumper instance
and an instance of the given data type
and producing the corresponding representation node.
"""
Dumper.add_representer(data_type, representer)
def add_multi_representer(data_type, multi_representer, Dumper=Dumper):
"""
Add a representer for the given type.
Multi-representer is a function accepting a Dumper instance
and an instance of the given data type or subtype
and producing the corresponding representation node.
"""
Dumper.add_multi_representer(data_type, multi_representer)
class YAMLObjectMetaclass(type):
"""
The metaclass for YAMLObject.
"""
def __init__(cls, name, bases, kwds):
super(YAMLObjectMetaclass, cls).__init__(name, bases, kwds)
if 'yaml_tag' in kwds and kwds['yaml_tag'] is not None:
cls.yaml_loader.add_constructor(cls.yaml_tag, cls.from_yaml)
cls.yaml_dumper.add_representer(cls, cls.to_yaml)
class YAMLObject(object):
"""
An object that can dump itself to a YAML stream
and load itself from a YAML stream.
"""
__metaclass__ = YAMLObjectMetaclass
__slots__ = () # no direct instantiation, so allow immutable subclasses
yaml_loader = Loader
yaml_dumper = Dumper
yaml_tag = None
yaml_flow_style = None
def from_yaml(cls, loader, node):
"""
Convert a representation node to a Python object.
"""
return loader.construct_yaml_object(node, cls)
from_yaml = classmethod(from_yaml)
def to_yaml(cls, dumper, data):
"""
Convert a Python object to a representation node.
"""
return dumper.represent_yaml_object(cls.yaml_tag, data, cls,
flow_style=cls.yaml_flow_style)
to_yaml = classmethod(to_yaml)
|
mit
|
[
199,
504,
1125,
492,
627,
199,
199,
504,
4645,
492,
627,
199,
504,
4474,
492,
627,
199,
504,
3380,
492,
627,
199,
199,
504,
5077,
492,
627,
199,
504,
5461,
281,
492,
627,
199,
199,
363,
1023,
363,
275,
283,
19,
14,
1643,
7,
199,
199,
893,
26,
272,
687,
286,
5963,
492,
627,
272,
636,
1045,
63,
773,
5963,
363,
275,
715,
199,
2590,
3545,
26,
272,
636,
1045,
63,
773,
5963,
363,
275,
756,
199,
199,
318,
8000,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
24833,
282,
18916,
2547,
436,
7389,
24928,
4645,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
1830,
5077,
14,
1074,
63,
1418,
837,
267,
1995,
5077,
14,
362,
63,
1418,
342,
199,
199,
318,
2198,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
282,
18916,
2547,
436,
7389,
6057,
4474,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
1830,
5077,
14,
1074,
63,
1430,
837,
267,
1995,
5077,
14,
362,
63,
1430,
342,
199,
199,
318,
23366,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
314,
1642,
18916,
2213,
315,
282,
2547,
272,
436,
7389,
314,
5226,
6025,
3123,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
372,
5077,
14,
362,
63,
4780,
63,
932,
342,
199,
199,
318,
23366,
63,
452,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
1006,
18916,
8247,
315,
282,
2547,
272,
436,
7389,
5226,
6025,
14416,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
1830,
5077,
14,
1074,
63,
932,
837,
267,
1995,
5077,
14,
362,
63,
932,
342,
199,
199,
318,
2248,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
314,
1642,
18916,
2213,
315,
282,
2547,
272,
436,
7389,
314,
5226,
2018,
909,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
372,
5077,
14,
362,
63,
4780,
63,
576,
342,
199,
199,
318,
2248,
63,
452,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
1006,
18916,
8247,
315,
282,
2547,
272,
436,
7389,
5226,
2018,
2251,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
1830,
5077,
14,
1074,
63,
576,
837,
267,
1995,
5077,
14,
362,
63,
576,
342,
199,
199,
318,
5048,
63,
912,
8,
1745,
304,
272,
408,
272,
6077,
314,
1642,
18916,
2213,
315,
282,
2547,
272,
436,
7389,
314,
5226,
2018,
909,
14,
272,
31096,
1454,
5678,
18916,
3762,
14,
272,
408,
272,
372,
2248,
8,
1745,
12,
14969,
5455,
9,
199,
199,
318,
5048,
63,
912,
63,
452,
8,
1745,
304,
272,
408,
272,
6077,
1006,
18916,
8247,
315,
282,
2547,
272,
436,
7389,
5226,
2018,
2251,
14,
272,
31096,
1454,
5678,
18916,
3762,
14,
272,
408,
272,
372,
2248,
63,
452,
8,
1745,
12,
14969,
5455,
9,
199,
199,
318,
8689,
8,
4368,
12,
2547,
29,
403,
12,
19460,
281,
29,
28593,
12,
267,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
267,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
304,
272,
408,
272,
662,
1147,
18916,
6057,
4474,
1901,
282,
2547,
14,
272,
982,
2547,
365,
488,
12,
372,
314,
13584,
1059,
3140,
14,
272,
408,
272,
664,
585,
275,
488,
272,
340,
2547,
365,
488,
26,
267,
687,
5228,
492,
5228,
267,
2547,
275,
5228,
342,
267,
664,
585,
275,
2547,
14,
7150,
272,
5461,
281,
275,
19460,
281,
8,
1745,
12,
11358,
29,
13109,
12,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
288,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
272,
367,
1566,
315,
4474,
26,
267,
5461,
281,
14,
8159,
8,
1430,
9,
272,
340,
664,
585,
26,
267,
372,
664,
585,
342,
199,
199,
318,
8437,
63,
452,
8,
2415,
12,
2547,
29,
403,
12,
19460,
281,
29,
28593,
12,
267,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
267,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
267,
2644,
534,
1624,
13,
24,
297,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
267,
1015,
29,
403,
12,
3762,
29,
403,
304,
272,
408,
272,
11973,
794,
282,
3414,
402,
6025,
14416,
1901,
282,
18916,
2547,
14,
272,
982,
2547,
365,
488,
12,
372,
314,
13584,
1059,
3140,
14,
272,
408,
272,
664,
585,
275,
488,
272,
340,
2547,
365,
488,
26,
267,
340,
2644,
365,
488,
26,
288,
687,
5228,
492,
5228,
267,
587,
26,
288,
687,
15073,
492,
5228,
267,
2547,
275,
5228,
342,
267,
664,
585,
275,
2547,
14,
7150,
272,
5461,
281,
275,
19460,
281,
8,
1745,
12,
11358,
29,
13109,
12,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
288,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
12,
288,
2644,
29,
2991,
12,
1015,
29,
1023,
12,
3762,
29,
2969,
12,
288,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
9,
272,
5461,
281,
14,
1490,
342,
272,
367,
1031,
315,
3380,
26,
267,
5461,
281,
14,
3549,
8,
932,
9,
272,
5461,
281,
14,
1600,
342,
272,
340,
664,
585,
26,
267,
372,
664,
585,
342,
199,
199,
318,
8437,
8,
932,
12,
2547,
29,
403,
12,
19460,
281,
29,
28593,
12,
1011,
10340,
304,
272,
408,
272,
11973,
794,
282,
6025,
3123,
1901,
282,
18916,
2547,
14,
272,
982,
2547,
365,
488,
12,
372,
314,
13584,
1059,
3140,
14,
272,
408,
272,
372,
8437,
63,
452,
779,
932,
467,
2547,
12,
19460,
281,
29,
28593,
12,
1011,
10340,
9,
199,
199,
318,
5461,
63,
452,
8,
12233,
12,
2547,
29,
403,
12,
19460,
281,
29,
28593,
12,
267,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
267,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
267,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
267,
2644,
534,
1624,
13,
24,
297,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
267,
1015,
29
] |
[
504,
1125,
492,
627,
199,
199,
504,
4645,
492,
627,
199,
504,
4474,
492,
627,
199,
504,
3380,
492,
627,
199,
199,
504,
5077,
492,
627,
199,
504,
5461,
281,
492,
627,
199,
199,
363,
1023,
363,
275,
283,
19,
14,
1643,
7,
199,
199,
893,
26,
272,
687,
286,
5963,
492,
627,
272,
636,
1045,
63,
773,
5963,
363,
275,
715,
199,
2590,
3545,
26,
272,
636,
1045,
63,
773,
5963,
363,
275,
756,
199,
199,
318,
8000,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
24833,
282,
18916,
2547,
436,
7389,
24928,
4645,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
1830,
5077,
14,
1074,
63,
1418,
837,
267,
1995,
5077,
14,
362,
63,
1418,
342,
199,
199,
318,
2198,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
282,
18916,
2547,
436,
7389,
6057,
4474,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
1830,
5077,
14,
1074,
63,
1430,
837,
267,
1995,
5077,
14,
362,
63,
1430,
342,
199,
199,
318,
23366,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
314,
1642,
18916,
2213,
315,
282,
2547,
272,
436,
7389,
314,
5226,
6025,
3123,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
372,
5077,
14,
362,
63,
4780,
63,
932,
342,
199,
199,
318,
23366,
63,
452,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
1006,
18916,
8247,
315,
282,
2547,
272,
436,
7389,
5226,
6025,
14416,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
1830,
5077,
14,
1074,
63,
932,
837,
267,
1995,
5077,
14,
362,
63,
932,
342,
199,
199,
318,
2248,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
314,
1642,
18916,
2213,
315,
282,
2547,
272,
436,
7389,
314,
5226,
2018,
909,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
372,
5077,
14,
362,
63,
4780,
63,
576,
342,
199,
199,
318,
2248,
63,
452,
8,
1745,
12,
22865,
29,
5455,
304,
272,
408,
272,
6077,
1006,
18916,
8247,
315,
282,
2547,
272,
436,
7389,
5226,
2018,
2251,
14,
272,
408,
272,
5077,
275,
22865,
8,
1745,
9,
272,
1830,
5077,
14,
1074,
63,
576,
837,
267,
1995,
5077,
14,
362,
63,
576,
342,
199,
199,
318,
5048,
63,
912,
8,
1745,
304,
272,
408,
272,
6077,
314,
1642,
18916,
2213,
315,
282,
2547,
272,
436,
7389,
314,
5226,
2018,
909,
14,
272,
31096,
1454,
5678,
18916,
3762,
14,
272,
408,
272,
372,
2248,
8,
1745,
12,
14969,
5455,
9,
199,
199,
318,
5048,
63,
912,
63,
452,
8,
1745,
304,
272,
408,
272,
6077,
1006,
18916,
8247,
315,
282,
2547,
272,
436,
7389,
5226,
2018,
2251,
14,
272,
31096,
1454,
5678,
18916,
3762,
14,
272,
408,
272,
372,
2248,
63,
452,
8,
1745,
12,
14969,
5455,
9,
199,
199,
318,
8689,
8,
4368,
12,
2547,
29,
403,
12,
19460,
281,
29,
28593,
12,
267,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
267,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
304,
272,
408,
272,
662,
1147,
18916,
6057,
4474,
1901,
282,
2547,
14,
272,
982,
2547,
365,
488,
12,
372,
314,
13584,
1059,
3140,
14,
272,
408,
272,
664,
585,
275,
488,
272,
340,
2547,
365,
488,
26,
267,
687,
5228,
492,
5228,
267,
2547,
275,
5228,
342,
267,
664,
585,
275,
2547,
14,
7150,
272,
5461,
281,
275,
19460,
281,
8,
1745,
12,
11358,
29,
13109,
12,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
288,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
272,
367,
1566,
315,
4474,
26,
267,
5461,
281,
14,
8159,
8,
1430,
9,
272,
340,
664,
585,
26,
267,
372,
664,
585,
342,
199,
199,
318,
8437,
63,
452,
8,
2415,
12,
2547,
29,
403,
12,
19460,
281,
29,
28593,
12,
267,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
267,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
267,
2644,
534,
1624,
13,
24,
297,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
267,
1015,
29,
403,
12,
3762,
29,
403,
304,
272,
408,
272,
11973,
794,
282,
3414,
402,
6025,
14416,
1901,
282,
18916,
2547,
14,
272,
982,
2547,
365,
488,
12,
372,
314,
13584,
1059,
3140,
14,
272,
408,
272,
664,
585,
275,
488,
272,
340,
2547,
365,
488,
26,
267,
340,
2644,
365,
488,
26,
288,
687,
5228,
492,
5228,
267,
587,
26,
288,
687,
15073,
492,
5228,
267,
2547,
275,
5228,
342,
267,
664,
585,
275,
2547,
14,
7150,
272,
5461,
281,
275,
19460,
281,
8,
1745,
12,
11358,
29,
13109,
12,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
288,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
12,
288,
2644,
29,
2991,
12,
1015,
29,
1023,
12,
3762,
29,
2969,
12,
288,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
9,
272,
5461,
281,
14,
1490,
342,
272,
367,
1031,
315,
3380,
26,
267,
5461,
281,
14,
3549,
8,
932,
9,
272,
5461,
281,
14,
1600,
342,
272,
340,
664,
585,
26,
267,
372,
664,
585,
342,
199,
199,
318,
8437,
8,
932,
12,
2547,
29,
403,
12,
19460,
281,
29,
28593,
12,
1011,
10340,
304,
272,
408,
272,
11973,
794,
282,
6025,
3123,
1901,
282,
18916,
2547,
14,
272,
982,
2547,
365,
488,
12,
372,
314,
13584,
1059,
3140,
14,
272,
408,
272,
372,
8437,
63,
452,
779,
932,
467,
2547,
12,
19460,
281,
29,
28593,
12,
1011,
10340,
9,
199,
199,
318,
5461,
63,
452,
8,
12233,
12,
2547,
29,
403,
12,
19460,
281,
29,
28593,
12,
267,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
267,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
267,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
267,
2644,
534,
1624,
13,
24,
297,
5027,
63,
928,
29,
403,
12,
5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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
fxia22/ASM_xf
|
PythonD/lib/python2.4/pkgutil.py
|
13
|
3100
|
"""Utilities to support packages."""
import os
import sys
def extend_path(path, name):
"""Extend a package's path.
Intended use is to place the following code in a package's __init__.py:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
This will add to the package's __path__ all subdirectories of
directories on sys.path named after the package. This is useful
if one wants to distribute different parts of a single logical
package as multiple directories.
It also looks for *.pkg files beginning where * matches the name
argument. This feature is similar to *.pth files (see site.py),
except that it doesn't special-case lines starting with 'import'.
A *.pkg file is trusted at face value: apart from checking for
duplicates, all entries found in a *.pkg file are added to the
path, regardless of whether they are exist the filesystem. (This
is a feature.)
If the input path is not a list (as is the case for frozen
packages) it is returned unchanged. The input path is not
modified; an extended copy is returned. Items are only appended
to the copy at the end.
It is assumed that sys.path is a sequence. Items of sys.path that
are not (unicode or 8-bit) strings referring to existing
directories are ignored. Unicode items of sys.path that cause
errors when used as filenames may cause this function to raise an
exception (in line with os.path.isdir() behavior).
"""
if not isinstance(path, list):
# This could happen e.g. when this is called from inside a
# frozen package. Return the path unchanged in that case.
return path
pname = os.path.join(*name.split('.')) # Reconstitute as relative path
# Just in case os.extsep != '.'
sname = os.extsep.join(name.split('.'))
sname_pkg = sname + os.extsep + "pkg"
init_py = "__init__" + os.extsep + "py"
path = path[:] # Start with a copy of the existing path
for dir in sys.path:
if not isinstance(dir, basestring) or not os.path.isdir(dir):
continue
subdir = os.path.join(dir, pname)
# XXX This may still add duplicate entries to path on
# case-insensitive filesystems
initfile = os.path.join(subdir, init_py)
if subdir not in path and os.path.isfile(initfile):
path.append(subdir)
# XXX Is this the right thing for subpackages like zope.app?
# It looks for a file named "zope.app.pkg"
pkgfile = os.path.join(dir, sname_pkg)
if os.path.isfile(pkgfile):
try:
f = open(pkgfile)
except IOError, msg:
sys.stderr.write("Can't open %s: %s\n" %
(pkgfile, msg))
else:
for line in f:
line = line.rstrip('\n')
if not line or line.startswith('#'):
continue
path.append(line) # Don't check for existence!
f.close()
return path
|
gpl-2.0
|
[
624,
22905,
370,
2291,
6117,
1041,
199,
199,
646,
747,
199,
646,
984,
199,
199,
318,
12247,
63,
515,
8,
515,
12,
536,
304,
272,
408,
30775,
282,
2559,
1159,
931,
14,
339,
1010,
6943,
675,
365,
370,
4192,
314,
2569,
1233,
315,
282,
2559,
1159,
636,
826,
4343,
647,
26,
398,
687,
28728,
492,
12247,
63,
515,
267,
636,
515,
363,
275,
12247,
63,
515,
3460,
515,
3108,
636,
354,
3368,
339,
961,
911,
1050,
370,
314,
2559,
1159,
636,
515,
363,
1006,
24799,
402,
272,
6602,
641,
984,
14,
515,
4310,
2410,
314,
2559,
14,
221,
961,
365,
2997,
272,
340,
1373,
15061,
370,
11207,
3365,
4184,
402,
282,
2849,
11461,
272,
2559,
465,
3663,
6602,
14,
339,
2779,
2597,
10734,
367,
23588,
4600,
1584,
9608,
2382,
627,
4450,
314,
536,
272,
1423,
14,
221,
961,
3878,
365,
8545,
370,
23588,
13316,
1584,
334,
3239,
4770,
14,
647,
395,
272,
871,
626,
652,
3181,
1133,
4539,
13,
2546,
2385,
6617,
543,
283,
646,
1370,
272,
437,
23588,
4600,
570,
365,
19427,
737,
8870,
574,
26,
29430,
687,
7907,
367,
272,
15755,
12,
1006,
4811,
1911,
315,
282,
23588,
4600,
570,
787,
3483,
370,
314,
272,
931,
12,
15270,
402,
3775,
2985,
787,
2187,
314,
10036,
14,
221,
334,
2765,
272,
365,
282,
3878,
4959,
339,
982,
314,
1324,
931,
365,
440,
282,
769,
334,
305,
365,
314,
1930,
367,
8101,
272,
6117,
9,
652,
365,
2138,
14874,
14,
221,
710,
1324,
931,
365,
440,
272,
6042,
27,
376,
9243,
1331,
365,
2138,
14,
221,
20720,
787,
1454,
11544,
272,
370,
314,
1331,
737,
314,
1284,
14,
339,
2779,
365,
10826,
626,
984,
14,
515,
365,
282,
3414,
14,
221,
20720,
402,
984,
14,
515,
626,
272,
787,
440,
334,
2975,
503,
1695,
13,
2075,
9,
3326,
21864,
370,
3411,
272,
6602,
787,
5525,
14,
221,
6140,
2974,
402,
984,
14,
515,
626,
7675,
272,
2552,
1380,
1202,
465,
6203,
1443,
7675,
642,
805,
370,
746,
376,
272,
1919,
334,
262,
1004,
543,
747,
14,
515,
14,
6027,
342,
5953,
680,
272,
408,
339,
340,
440,
1228,
8,
515,
12,
769,
304,
267,
327,
961,
4293,
5992,
325,
14,
71,
14,
1380,
642,
365,
2797,
687,
6272,
282,
267,
327,
8101,
2559,
14,
221,
1432,
314,
931,
14874,
315,
626,
1930,
14,
267,
372,
931,
339,
27700,
275,
747,
14,
515,
14,
904,
2031,
354,
14,
1294,
24535,
327,
799,
1297,
390,
938,
465,
3847,
931,
272,
327,
13870,
315,
1930,
747,
14,
832,
4127,
1137,
7815,
272,
308,
354,
275,
747,
14,
832,
4127,
14,
904,
8,
354,
14,
1294,
24535,
272,
308,
354,
63,
4600,
275,
308,
354,
435,
747,
14,
832,
4127,
435,
298,
4600,
2,
272,
4205,
63,
647,
275,
4396,
826,
16526,
435,
747,
14,
832,
4127,
435,
298,
647,
2,
339,
931,
275,
931,
5873,
327,
7707,
543,
282,
1331,
402,
314,
3411,
931,
339,
367,
2935,
315,
984,
14,
515,
26,
267,
340,
440,
1228,
8,
694,
12,
7116,
9,
503,
440,
747,
14,
515,
14,
6027,
8,
694,
304,
288,
1980,
267,
15488,
275,
747,
14,
515,
14,
904,
8,
694,
12,
27700,
9,
267,
327,
5787,
961,
1443,
5139,
1050,
9250,
4811,
370,
931,
641,
267,
327,
1930,
13,
15851,
10036,
83,
267,
4205,
493,
275,
747,
14,
515,
14,
904,
8,
10622,
12,
4205,
63,
647,
9,
267,
340,
15488,
440,
315,
931,
436,
747,
14,
515,
14,
6292,
8,
826,
493,
304,
288,
931,
14,
740,
8,
10622,
9,
267,
327,
5787,
6596,
642,
314,
2451,
8377,
367,
1007,
5154,
2839,
20110,
14,
571,
31,
267,
327,
2779,
10734,
367,
282,
570,
4310,
298,
90,
13458,
14,
571,
14,
4600,
2,
267,
5496,
493,
275,
747,
14,
515,
14,
904,
8,
694,
12,
308,
354,
63,
4600,
9,
267,
340,
747,
14,
515,
14,
6292,
8,
4600,
493,
304,
288,
862,
26,
355,
289,
275,
1551,
8,
4600,
493,
9,
288,
871,
5925,
12,
1499,
26,
355,
984,
14,
3083,
14,
952,
480,
6049,
1133,
1551,
450,
83,
26,
450,
83,
60,
78,
2,
450,
639,
334,
4600,
493,
12,
1499,
430,
288,
587,
26,
355,
367,
1004,
315,
289,
26,
490,
1004,
275,
1004,
14,
6735,
2258,
78,
358,
490,
340,
440,
1004,
503,
1004,
14,
2460,
7863,
735,
717,
1980,
490,
931,
14,
740,
8,
604,
9,
327,
7529,
1133,
1104,
367,
23780,
1,
355,
289,
14,
1600,
342,
339,
372,
931,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
22905,
370,
2291,
6117,
1041,
199,
199,
646,
747,
199,
646,
984,
199,
199,
318,
12247,
63,
515,
8,
515,
12,
536,
304,
272,
408,
30775,
282,
2559,
1159,
931,
14,
339,
1010,
6943,
675,
365,
370,
4192,
314,
2569,
1233,
315,
282,
2559,
1159,
636,
826,
4343,
647,
26,
398,
687,
28728,
492,
12247,
63,
515,
267,
636,
515,
363,
275,
12247,
63,
515,
3460,
515,
3108,
636,
354,
3368,
339,
961,
911,
1050,
370,
314,
2559,
1159,
636,
515,
363,
1006,
24799,
402,
272,
6602,
641,
984,
14,
515,
4310,
2410,
314,
2559,
14,
221,
961,
365,
2997,
272,
340,
1373,
15061,
370,
11207,
3365,
4184,
402,
282,
2849,
11461,
272,
2559,
465,
3663,
6602,
14,
339,
2779,
2597,
10734,
367,
23588,
4600,
1584,
9608,
2382,
627,
4450,
314,
536,
272,
1423,
14,
221,
961,
3878,
365,
8545,
370,
23588,
13316,
1584,
334,
3239,
4770,
14,
647,
395,
272,
871,
626,
652,
3181,
1133,
4539,
13,
2546,
2385,
6617,
543,
283,
646,
1370,
272,
437,
23588,
4600,
570,
365,
19427,
737,
8870,
574,
26,
29430,
687,
7907,
367,
272,
15755,
12,
1006,
4811,
1911,
315,
282,
23588,
4600,
570,
787,
3483,
370,
314,
272,
931,
12,
15270,
402,
3775,
2985,
787,
2187,
314,
10036,
14,
221,
334,
2765,
272,
365,
282,
3878,
4959,
339,
982,
314,
1324,
931,
365,
440,
282,
769,
334,
305,
365,
314,
1930,
367,
8101,
272,
6117,
9,
652,
365,
2138,
14874,
14,
221,
710,
1324,
931,
365,
440,
272,
6042,
27,
376,
9243,
1331,
365,
2138,
14,
221,
20720,
787,
1454,
11544,
272,
370,
314,
1331,
737,
314,
1284,
14,
339,
2779,
365,
10826,
626,
984,
14,
515,
365,
282,
3414,
14,
221,
20720,
402,
984,
14,
515,
626,
272,
787,
440,
334,
2975,
503,
1695,
13,
2075,
9,
3326,
21864,
370,
3411,
272,
6602,
787,
5525,
14,
221,
6140,
2974,
402,
984,
14,
515,
626,
7675,
272,
2552,
1380,
1202,
465,
6203,
1443,
7675,
642,
805,
370,
746,
376,
272,
1919,
334,
262,
1004,
543,
747,
14,
515,
14,
6027,
342,
5953,
680,
272,
408,
339,
340,
440,
1228,
8,
515,
12,
769,
304,
267,
327,
961,
4293,
5992,
325,
14,
71,
14,
1380,
642,
365,
2797,
687,
6272,
282,
267,
327,
8101,
2559,
14,
221,
1432,
314,
931,
14874,
315,
626,
1930,
14,
267,
372,
931,
339,
27700,
275,
747,
14,
515,
14,
904,
2031,
354,
14,
1294,
24535,
327,
799,
1297,
390,
938,
465,
3847,
931,
272,
327,
13870,
315,
1930,
747,
14,
832,
4127,
1137,
7815,
272,
308,
354,
275,
747,
14,
832,
4127,
14,
904,
8,
354,
14,
1294,
24535,
272,
308,
354,
63,
4600,
275,
308,
354,
435,
747,
14,
832,
4127,
435,
298,
4600,
2,
272,
4205,
63,
647,
275,
4396,
826,
16526,
435,
747,
14,
832,
4127,
435,
298,
647,
2,
339,
931,
275,
931,
5873,
327,
7707,
543,
282,
1331,
402,
314,
3411,
931,
339,
367,
2935,
315,
984,
14,
515,
26,
267,
340,
440,
1228,
8,
694,
12,
7116,
9,
503,
440,
747,
14,
515,
14,
6027,
8,
694,
304,
288,
1980,
267,
15488,
275,
747,
14,
515,
14,
904,
8,
694,
12,
27700,
9,
267,
327,
5787,
961,
1443,
5139,
1050,
9250,
4811,
370,
931,
641,
267,
327,
1930,
13,
15851,
10036,
83,
267,
4205,
493,
275,
747,
14,
515,
14,
904,
8,
10622,
12,
4205,
63,
647,
9,
267,
340,
15488,
440,
315,
931,
436,
747,
14,
515,
14,
6292,
8,
826,
493,
304,
288,
931,
14,
740,
8,
10622,
9,
267,
327,
5787,
6596,
642,
314,
2451,
8377,
367,
1007,
5154,
2839,
20110,
14,
571,
31,
267,
327,
2779,
10734,
367,
282,
570,
4310,
298,
90,
13458,
14,
571,
14,
4600,
2,
267,
5496,
493,
275,
747,
14,
515,
14,
904,
8,
694,
12,
308,
354,
63,
4600,
9,
267,
340,
747,
14,
515,
14,
6292,
8,
4600,
493,
304,
288,
862,
26,
355,
289,
275,
1551,
8,
4600,
493,
9,
288,
871,
5925,
12,
1499,
26,
355,
984,
14,
3083,
14,
952,
480,
6049,
1133,
1551,
450,
83,
26,
450,
83,
60,
78,
2,
450,
639,
334,
4600,
493,
12,
1499,
430,
288,
587,
26,
355,
367,
1004,
315,
289,
26,
490,
1004,
275,
1004,
14,
6735,
2258,
78,
358,
490,
340,
440,
1004,
503,
1004,
14,
2460,
7863,
735,
717,
1980,
490,
931,
14,
740,
8,
604,
9,
327,
7529,
1133,
1104,
367,
23780,
1,
355,
289,
14,
1600,
342,
339,
372,
931,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
frewsxcv/keyczar
|
cpp/src/tools/swtoolkit/bin/runtest.py
|
9
|
11270
|
#!/usr/bin/python2.4
#
# Copyright 2009, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Significant portions of this script are lifted from:
#
# runtest.py - wrapper script for running SCons tests
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
#
"""Wrapper script for running tests. Use 'runtest.py -h' to print usage."""
import glob
import os
import optparse
import re
import subprocess
import sys
import time
OPTION_LIST = [
optparse.make_option(
"-a", "--all", action="store_true", dest="all", default=False,
help=("Run all tests; does a virtual 'find' for all tests under "
"the current directory."),
),
optparse.make_option(
"-d", "--debug",
action="store_true", dest="debug", default=False,
help=("Runs the script under the Python debugger "
"(pdb.py) so you don't have to muck with PYTHONPATH yourself."),
),
optparse.make_option(
"-f", "--file", dest="testlistfile", metavar="FILE", default=None,
help="Only execute the tests listed in the specified FILE.",
),
optparse.make_option(
"--ignore-no-result",
action="store_false", dest="fail_on_no_result", default=True,
help="Don't return 2 on tests with no result.",
),
optparse.make_option(
"-q", "--quiet",
action="store_true", dest="quiet", default=False,
help=("By default, runtest.py prints the command line "
"it will execute before executing it. This suppresses "
"that print."),
),
optparse.make_option(
"-t", "--time",
action="store_true", dest="time", default=False,
help="Print the execution time of each test.",
),
optparse.make_option(
"-l", "--list",
action="store_true", dest="list_only", default=False,
help="List available tests and exit.",
),
optparse.make_option(
"-n", "--no-exec",
action="store_false", dest="execute_tests", default=True,
help="No execute, just print command lines.",
),
optparse.make_option(
"-P", dest="python", metavar="PYTHON", default=None,
help="Use the specified PYTHON interpreter.",
),
optparse.make_option(
"-F", dest="pythonflags", metavar="FLAG", default=[], type="string",
action="append",
help=("Pass the specified FLAG to python. May be specified multiple "
"times to pass multiple flags.")
),
optparse.make_option(
"--verbose", dest="verbose", metavar="LEVEL",
help=("Set verbose level: "
"1 = print executed commands. "
"2 = print commands and non-zero output. "
"3 = print commands and all output."),
),
optparse.make_option(
"--passed",
action="store_true", dest="passed_summary", default=False,
help=("In the final summary, also report which tests passed. "
"The default is to only report tests which failed or "
"returned NO RESULT."),
),
]
class Error(Exception):
"""Local Error class."""
pass
class Unbuffered:
"""Class for flushing after every write()."""
def __init__(self, filehandle):
self.filehandle = filehandle
def write(self, arg):
"""Write the specified arg and flush()."""
self.filehandle.write(arg)
self.filehandle.flush()
def __getattr__(self, attr):
return getattr(self.filehandle, attr)
class Test:
"""An individual test."""
command = ["python"]
common_args = []
_ws_expr = re.compile("\s")
EXIT_SUCCESS = 0
EXIT_FAILED = 1
EXIT_NO_RESULT = 2
def __init__(self, path):
"""Test initialization.
Args:
path: the path to the test being executed/recorded
"""
self.path = path
self.abspath = os.path.abspath(path)
self.status = None
self.test_args = []
def Execute(self):
"""Execute the test command line."""
self.status = subprocess.call(self.GetCommandStr(), shell=True)
if self.status < 0 or self.status > 2:
sys.stdout.write("Unexpected exit status %d\n" % self.status)
def GetCommandArgs(self):
"""Return the complete command-line arguments as a list."""
return self.command + self.common_args + self.test_args
def GetCommandStr(self):
"""Return the command-line as a string, suitable for display."""
return " ".join(map(self.Quote, self.GetCommandArgs()))
def Quote(self, s):
"""Return a quoted version of a string if it has white space.
Args:
s: The input string.
Returns:
The quoted string if it contains white space, or the original if not.
"""
if self._ws_expr.search(s):
s = '"' + s + '"'
return s
def main():
parser = optparse.OptionParser(option_list=OPTION_LIST)
opts, args = parser.parse_args()
if opts.quiet:
print_command = lambda s: None
else:
print_command = lambda s: sys.stdout.write(s)
if opts.time:
print_time = lambda fmt, time: sys.stdout.write(fmt % time)
else:
print_time = lambda fmt, time: None
if opts.debug:
for d in sys.path:
pdb = os.path.join(d, "pdb.py")
if os.path.exists(pdb):
debug = pdb
break
else:
debug = ""
testlistfile = opts.testlistfile
if testlistfile:
testlistfile = os.path.abspath(testlistfile)
if opts.verbose:
os.environ['TESTCMD_VERBOSE'] = opts.verbose
if not args and not opts.all and not testlistfile and not opts.list_only:
parser.print_help()
parser.error('No tests were specified')
return 1
if not sys.stdout.isatty():
sys.stdout = Unbuffered(sys.stdout)
python = opts.python
if not python:
if os.name == "java":
python = os.path.join(sys.prefix, "jython")
else:
python = sys.executable
Test.command = [python]
Test.common_args = opts.pythonflags
# Need SCONS_DEV_DIR environment variable to point to the root of a
# SCons source (scons-src) package, so that we can use its QMTest modules.
scons_dev_dir = os.environ.get("SCONS_DEV_DIR")
if not scons_dev_dir:
parser.error('SCONS_DEV_DIR environment variable not set.')
return 1
scons_dir = os.path.join(scons_dev_dir, "src", "engine")
cwd = os.getcwd()
test_dir = os.path.join(cwd, "test")
pythonpaths = [
os.path.join(cwd, "lib"),
os.path.join(cwd, "site_scons"),
os.path.join(scons_dev_dir, "QMTest"),
scons_dir,
]
old_pythonpath = os.environ.get("PYTHONPATH")
if old_pythonpath:
pythonpaths.append(old_pythonpath)
os.environ["PYTHONPATH"] = os.pathsep.join(pythonpaths)
os.environ["SCONS_DIR"] = scons_dir
tests = []
if args:
for a in args:
tests.extend(glob.glob(a))
elif testlistfile:
for line in open(testlistfile, "r"):
line = line.strip()
if line and line[0] != "#":
tests.append(line)
elif opts.all or opts.list_only:
def FindPy(tests, dirname, names):
"""Add any .py files to the list of tests.
Passed to os.path.walk() to find all the .py files, and conforms
to the calling signature for os.path.walk() callbacks.
Args:
tests: list in which we're accumulating python files
dirname: directory we're examining
names: the entries in that directory
"""
python_names = [n for n in names if n[-3:].lower() == ".py"]
tests.extend([os.path.join(dirname, n) for n in python_names])
os.path.walk(test_dir, FindPy, tests)
tests.sort()
tests = [Test(t) for t in tests]
if opts.list_only:
# Print tests in a format which can be passed back in using --file
sys.stdout.write("# runtest found the following tests:\n")
for t in tests:
sys.stdout.write(" %s\n" % t.abspath)
sys.stdout.write("\n")
return 0
# time.clock() is the suggested interface for doing benchmarking
# timings, but time.time() does a better job on Linux systems, so let
# that be the non-Windows default.
if sys.platform == "win32":
time_func = time.clock
else:
time_func = time.time
total_start_time = time_func()
for t in tests:
if debug:
t.test_args.append(debug)
t.test_args.append(t.abspath)
print_command(t.GetCommandStr() + ": ")
test_start_time = time_func()
if opts.execute_tests:
t.Execute()
t.test_time = time_func() - test_start_time
print_time("Test execution time: %.1f seconds\n", t.test_time)
if tests:
tests[0].total_time = time_func() - total_start_time
fmt = "Total execution time for all tests: %.1f seconds\n"
print_time(fmt, tests[0].total_time)
passed = [t for t in tests if t.status == t.EXIT_SUCCESS]
failed = [t for t in tests if t.status == t.EXIT_FAILED]
no_result = [t for t in tests if t.status == t.EXIT_NO_RESULT]
if len(tests) != 1 and opts.execute_tests:
def PrintResults(result_list, result_string):
"""Common function for printing different types of test results.
Args:
result_list: the list of tests that {passed, failed, no result}
result_string: a string to print describing the type of results
"""
if not result_list:
return
l = len(result_list)
if l == 1:
s = "\n%s the following test:\n" % result_string
else:
s = "\n%s the following %d tests:\n" % (result_string, l)
sys.stdout.write(s)
paths = [x.path for x in result_list]
sys.stdout.write("\t" + "\n\t".join(paths) + "\n")
if opts.passed_summary:
PrintResults(passed, "Passed")
PrintResults(failed, "Failed")
PrintResults(no_result, "NO RESULT from")
if failed:
return 1
elif no_result and opts.fail_on_no_result:
return 2
else:
return 0
if __name__ == "__main__":
sys.exit(main())
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
6632,
14266,
12468,
402,
642,
2884,
787,
221,
853,
471,
687,
26,
199,
3,
199,
3,
1255,
396,
14,
647,
446,
4975,
2884,
367,
3879,
8218,
2295,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
710,
8218,
2752,
199,
3,
199,
199,
624,
4590,
2884,
367,
3879,
2295,
14,
221,
3645,
283,
1065,
396,
14,
647,
446,
72,
7,
370,
870,
4503,
1041,
421,
199,
646,
5739,
199,
646,
747,
199,
646,
8691,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
646,
900,
421,
199,
13352,
63,
4924,
275,
359,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
65,
401,
4320,
452,
401,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
452,
401,
849,
29,
797,
12,
267,
1720,
15387,
2540,
1006,
2295,
27,
1630,
282,
5791,
283,
1623,
7,
367,
1006,
2295,
1334,
298,
1598,
298,
1589,
1453,
2082,
7651,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
68,
401,
4320,
1757,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
1757,
401,
849,
29,
797,
12,
267,
1720,
15387,
16291,
314,
2884,
1334,
314,
2018,
14958,
298,
1598,
7340,
10511,
14,
647,
9,
880,
1265,
2793,
1133,
1172,
370,
8504,
346,
543,
31176,
28225,
7651,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
70,
401,
4320,
493,
401,
2053,
628,
396,
513,
493,
401,
8214,
628,
3817,
401,
849,
29,
403,
12,
267,
1720,
628,
5903,
5341,
314,
2295,
10532,
315,
314,
2013,
13024,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
4320,
4247,
13,
889,
13,
1099,
401,
267,
1595,
628,
1617,
63,
3910,
401,
2053,
628,
1633,
63,
265,
63,
889,
63,
1099,
401,
849,
29,
549,
12,
267,
1720,
628,
16932,
1133,
372,
499,
641,
2295,
543,
949,
754,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
81,
401,
4320,
10243,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
10243,
401,
849,
29,
797,
12,
267,
1720,
15387,
2175,
849,
12,
1255,
396,
14,
647,
14767,
314,
1414,
1004,
298,
1598,
298,
390,
911,
5341,
2544,
14043,
652,
14,
221,
961,
4973,
4357,
298,
1598,
298,
9099,
870,
7651,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
84,
401,
4320,
521,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
521,
401,
849,
29,
797,
12,
267,
1720,
628,
5375,
314,
6451,
900,
402,
1924,
511,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
76,
401,
4320,
513,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
513,
63,
2118,
401,
849,
29,
797,
12,
267,
1720,
628,
1296,
2808,
2295,
436,
4458,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
78,
401,
4320,
889,
13,
1628,
401,
267,
1595,
628,
1617,
63,
3910,
401,
2053,
628,
2526,
63,
2219,
401,
849,
29,
549,
12,
267,
1720,
628,
1944,
5341,
12,
2951,
870,
1414,
2385,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
48,
401,
2053,
628,
1548,
401,
8214,
628,
11720,
401,
849,
29,
403,
12,
267,
1720,
628,
6119,
314,
2013,
18280,
12693,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
38,
401,
2053,
628,
1548,
2469,
401,
8214,
628,
3719,
401,
849,
6034,
730,
628,
875,
401,
267,
1595,
628,
740,
401,
267,
1720,
15387,
4986,
314,
2013,
11031,
370,
2366,
14,
221,
10162,
506,
2013,
3663,
298,
1598,
298,
4508,
370,
986,
3663,
3285,
2685,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
4320,
3832,
401,
2053,
628,
3832,
401,
8214,
628,
11817,
401,
267,
1720,
15387,
1084,
3376,
2166,
26,
298,
1598,
298,
17,
275,
870,
7934,
3718,
14,
298,
1598,
298,
18,
275,
870,
3718,
436,
2222,
13,
4262,
1072,
14,
298,
1598,
298,
19,
275,
870,
3718,
436,
1006,
1072,
7651,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
4320,
12070,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
12070,
63,
4705,
401,
849,
29,
797,
12,
267
] |
[
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
6632,
14266,
12468,
402,
642,
2884,
787,
221,
853,
471,
687,
26,
199,
3,
199,
3,
1255,
396,
14,
647,
446,
4975,
2884,
367,
3879,
8218,
2295,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
710,
8218,
2752,
199,
3,
199,
199,
624,
4590,
2884,
367,
3879,
2295,
14,
221,
3645,
283,
1065,
396,
14,
647,
446,
72,
7,
370,
870,
4503,
1041,
421,
199,
646,
5739,
199,
646,
747,
199,
646,
8691,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
646,
900,
421,
199,
13352,
63,
4924,
275,
359,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
65,
401,
4320,
452,
401,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
452,
401,
849,
29,
797,
12,
267,
1720,
15387,
2540,
1006,
2295,
27,
1630,
282,
5791,
283,
1623,
7,
367,
1006,
2295,
1334,
298,
1598,
298,
1589,
1453,
2082,
7651,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
68,
401,
4320,
1757,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
1757,
401,
849,
29,
797,
12,
267,
1720,
15387,
16291,
314,
2884,
1334,
314,
2018,
14958,
298,
1598,
7340,
10511,
14,
647,
9,
880,
1265,
2793,
1133,
1172,
370,
8504,
346,
543,
31176,
28225,
7651,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
70,
401,
4320,
493,
401,
2053,
628,
396,
513,
493,
401,
8214,
628,
3817,
401,
849,
29,
403,
12,
267,
1720,
628,
5903,
5341,
314,
2295,
10532,
315,
314,
2013,
13024,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
4320,
4247,
13,
889,
13,
1099,
401,
267,
1595,
628,
1617,
63,
3910,
401,
2053,
628,
1633,
63,
265,
63,
889,
63,
1099,
401,
849,
29,
549,
12,
267,
1720,
628,
16932,
1133,
372,
499,
641,
2295,
543,
949,
754,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
81,
401,
4320,
10243,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
10243,
401,
849,
29,
797,
12,
267,
1720,
15387,
2175,
849,
12,
1255,
396,
14,
647,
14767,
314,
1414,
1004,
298,
1598,
298,
390,
911,
5341,
2544,
14043,
652,
14,
221,
961,
4973,
4357,
298,
1598,
298,
9099,
870,
7651,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
84,
401,
4320,
521,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
521,
401,
849,
29,
797,
12,
267,
1720,
628,
5375,
314,
6451,
900,
402,
1924,
511,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
76,
401,
4320,
513,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
513,
63,
2118,
401,
849,
29,
797,
12,
267,
1720,
628,
1296,
2808,
2295,
436,
4458,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
78,
401,
4320,
889,
13,
1628,
401,
267,
1595,
628,
1617,
63,
3910,
401,
2053,
628,
2526,
63,
2219,
401,
849,
29,
549,
12,
267,
1720,
628,
1944,
5341,
12,
2951,
870,
1414,
2385,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
48,
401,
2053,
628,
1548,
401,
8214,
628,
11720,
401,
849,
29,
403,
12,
267,
1720,
628,
6119,
314,
2013,
18280,
12693,
4765,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
3905,
38,
401,
2053,
628,
1548,
2469,
401,
8214,
628,
3719,
401,
849,
6034,
730,
628,
875,
401,
267,
1595,
628,
740,
401,
267,
1720,
15387,
4986,
314,
2013,
11031,
370,
2366,
14,
221,
10162,
506,
2013,
3663,
298,
1598,
298,
4508,
370,
986,
3663,
3285,
2685,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
4320,
3832,
401,
2053,
628,
3832,
401,
8214,
628,
11817,
401,
267,
1720,
15387,
1084,
3376,
2166,
26,
298,
1598,
298,
17,
275,
870,
7934,
3718,
14,
298,
1598,
298,
18,
275,
870,
3718,
436,
2222,
13,
4262,
1072,
14,
298,
1598,
298,
19,
275,
870,
3718,
436,
1006,
1072,
7651,
272,
2318,
272,
8691,
14,
1875,
63,
1422,
8,
267,
4320,
12070,
401,
267,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
12070,
63,
4705,
401,
849,
29,
797,
12,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
rgmining/fraudar
|
fraudar/export/run_greedy.py
|
1
|
2152
|
# FRAUDAR: Bounding Graph Fraud in the Face of Camouflage
# Authors: Bryan Hooi, Hyun Ah Song, Alex Beutel, Neil Shah, Kijung Shin, Christos Faloutsos
#
# This software is licensed under 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.
#
# Version: 1.0
# Date: Oct 3, 2016
# Main Contact: Bryan Hooi (bhooi@andrew.cmu.edu)
# runs the greedy algorithm. first argument is path to data file. second argument is name to save
# pickle containing results.
import time
start_time = time.time()
from greedy import *
import sys
M = readData(sys.argv[1])
print "finished reading data: shape = ", M.shape, " @ ", time.time() - start_time
# (m, n) = (500, 500)
# M = M[0:m, 0:n]
# M[0:20, 0:20] = 1
# M2 = M.toarray().astype(int)
# print np.transpose(np.nonzero(M2))
# np.savetxt('example.txt', np.transpose(np.nonzero(M2)), fmt='%d')
# M, rowFilter, colFilter = subsetAboveDegree(M, int(sys.argv[3]), int(sys.argv[4]))
# filter_name = "output/%s_%s_%s_filter.pickle" % (sys.argv[2], sys.argv[3], sys.argv[4])
# pickle.dump((rowFilter, colFilter), open(filter_name, "wb" ))
# print "finished subsetting: shape = ", M.shape, " @ ", time.time() - start_time
# subset_filepath = '%s_%s_%s.txt' % (sys.argv[2], sys.argv[3], sys.argv[4])
# pickle.dump(M, open(subset_filepath, "wb"))
# np.savetxt(subset_filepath, M.nonzero().transpose(), fmt='%i')
print "finished writing data", " @ ", time.time() - start_time
lwRes = logWeightedAveDegree(M)
print lwRes
np.savetxt("%s.rows" % (sys.argv[2], ), np.array(list(lwRes[0][0])), fmt='%d')
np.savetxt("%s.cols" % (sys.argv[2], ), np.array(list(lwRes[0][1])), fmt='%d')
print "score obtained is ", lwRes[1]
print "done @ ", time.time() - start_time
|
gpl-3.0
|
[
3,
481,
2847,
3383,
689,
26,
21972,
316,
11513,
481,
345,
1181,
315,
314,
21459,
402,
445,
455,
810,
14163,
303,
199,
3,
6642,
26,
699,
651,
290,
869,
1534,
73,
12,
29591,
324,
437,
72,
29405,
12,
22986,
6423,
938,
76,
12,
5612,
382,
428,
2411,
72,
12,
1804,
7879,
10335,
5244,
262,
12,
2799,
18824,
736,
481,
279,
16816,
736,
199,
3,
199,
3,
961,
2032,
365,
18233,
1334,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
221,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
3394,
26,
413,
14,
16,
199,
3,
6148,
26,
18365,
650,
12,
7800,
199,
3,
11298,
18684,
26,
699,
651,
290,
869,
1534,
73,
334,
66,
526,
16142,
32,
460,
5257,
14,
4400,
85,
14,
8654,
9,
421,
199,
3,
7858,
314,
486,
24737,
5563,
14,
1642,
1423,
365,
931,
370,
666,
570,
14,
3499,
1423,
365,
536,
370,
3354,
199,
3,
5927,
3035,
2058,
14,
199,
646,
900,
199,
928,
63,
521,
275,
900,
14,
521,
342,
199,
504,
486,
24737,
492,
627,
199,
646,
984,
199,
45,
275,
1586,
1451,
8,
1274,
14,
3020,
59,
17,
566,
199,
1361,
298,
8669,
7664,
666,
26,
2215,
275,
3872,
603,
14,
1392,
12,
298,
768,
3872,
900,
14,
521,
342,
446,
1343,
63,
521,
199,
199,
3,
334,
77,
12,
302,
9,
275,
334,
5783,
12,
6891,
9,
199,
3,
603,
275,
603,
59,
16,
26,
77,
12,
378,
26,
78,
61,
199,
3,
603,
59,
16,
26,
1165,
12,
378,
26,
1165,
61,
275,
413,
199,
3,
603,
18,
275,
603,
14,
18993,
1252,
6041,
8,
442,
9,
199,
3,
870,
980,
14,
10483,
8,
1590,
14,
10262,
8,
45,
18,
430,
199,
3,
980,
14,
23374,
386,
400,
360,
2694,
14,
2424,
297,
980,
14,
10483,
8,
1590,
14,
10262,
8,
45,
18,
1826,
7104,
9569,
68,
358,
199,
199,
3,
603,
12,
1962,
4131,
12,
1048,
4131,
275,
10026,
33,
3395,
26135,
850,
8,
45,
12,
1109,
8,
1274,
14,
3020,
59,
19,
2522,
1109,
8,
1274,
14,
3020,
59,
20,
2459,
199,
3,
2457,
63,
354,
275,
298,
1199,
3149,
83,
4970,
83,
4970,
83,
63,
1541,
14,
8092,
2,
450,
334,
1274,
14,
3020,
59,
18,
467,
984,
14,
3020,
59,
19,
467,
984,
14,
3020,
59,
20,
566,
199,
3,
5927,
14,
2724,
1332,
1143,
4131,
12,
1048,
4131,
395,
1551,
8,
1541,
63,
354,
12,
298,
6603,
2,
5082,
199,
3,
870,
298,
8669,
1007,
6031,
26,
2215,
275,
3872,
603,
14,
1392,
12,
298,
768,
3872,
900,
14,
521,
342,
446,
1343,
63,
521,
199,
3,
10026,
63,
7218,
275,
1543,
83,
4970,
83,
4970,
83,
14,
2424,
7,
450,
334,
1274,
14,
3020,
59,
18,
467,
984,
14,
3020,
59,
19,
467,
984,
14,
3020,
59,
20,
566,
199,
3,
5927,
14,
2724,
8,
45,
12,
1551,
8,
9401,
63,
7218,
12,
298,
6603,
2237,
199,
3,
980,
14,
23374,
386,
400,
8,
9401,
63,
7218,
12,
603,
14,
10262,
1252,
10483,
1062,
7104,
9569,
73,
358,
199,
199,
1361,
298,
8669,
3575,
666,
401,
298,
768,
3872,
900,
14,
521,
342,
446,
1343,
63,
521,
199,
20692,
1322,
275,
943,
6004,
8364,
33,
432,
26135,
850,
8,
45,
9,
199,
1361,
20482,
1322,
199,
1590,
14,
23374,
386,
400,
3647,
83,
14,
3838,
2,
450,
334,
1274,
14,
3020,
59,
18,
467,
2318,
980,
14,
1144,
8,
513,
8,
20692,
1322,
59,
16,
1527,
16,
12884,
7104,
9569,
68,
358,
199,
1590,
14,
23374,
386,
400,
3647,
83,
14,
4574,
2,
450,
334,
1274,
14,
3020,
59,
18,
467,
2318,
980,
14,
1144,
8,
513,
8,
20692,
1322,
59,
16,
1527,
17,
12884,
7104,
9569,
68,
358,
199,
1361,
298,
3397,
15884,
365,
3872,
20482,
1322,
59,
17,
61,
199,
1361,
298,
4456,
768,
3872,
900,
14,
521,
342,
446,
1343,
63,
521,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
481,
2847,
3383,
689,
26,
21972,
316,
11513,
481,
345,
1181,
315,
314,
21459,
402,
445,
455,
810,
14163,
303,
199,
3,
6642,
26,
699,
651,
290,
869,
1534,
73,
12,
29591,
324,
437,
72,
29405,
12,
22986,
6423,
938,
76,
12,
5612,
382,
428,
2411,
72,
12,
1804,
7879,
10335,
5244,
262,
12,
2799,
18824,
736,
481,
279,
16816,
736,
199,
3,
199,
3,
961,
2032,
365,
18233,
1334,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
221,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
3394,
26,
413,
14,
16,
199,
3,
6148,
26,
18365,
650,
12,
7800,
199,
3,
11298,
18684,
26,
699,
651,
290,
869,
1534,
73,
334,
66,
526,
16142,
32,
460,
5257,
14,
4400,
85,
14,
8654,
9,
421,
199,
3,
7858,
314,
486,
24737,
5563,
14,
1642,
1423,
365,
931,
370,
666,
570,
14,
3499,
1423,
365,
536,
370,
3354,
199,
3,
5927,
3035,
2058,
14,
199,
646,
900,
199,
928,
63,
521,
275,
900,
14,
521,
342,
199,
504,
486,
24737,
492,
627,
199,
646,
984,
199,
45,
275,
1586,
1451,
8,
1274,
14,
3020,
59,
17,
566,
199,
1361,
298,
8669,
7664,
666,
26,
2215,
275,
3872,
603,
14,
1392,
12,
298,
768,
3872,
900,
14,
521,
342,
446,
1343,
63,
521,
199,
199,
3,
334,
77,
12,
302,
9,
275,
334,
5783,
12,
6891,
9,
199,
3,
603,
275,
603,
59,
16,
26,
77,
12,
378,
26,
78,
61,
199,
3,
603,
59,
16,
26,
1165,
12,
378,
26,
1165,
61,
275,
413,
199,
3,
603,
18,
275,
603,
14,
18993,
1252,
6041,
8,
442,
9,
199,
3,
870,
980,
14,
10483,
8,
1590,
14,
10262,
8,
45,
18,
430,
199,
3,
980,
14,
23374,
386,
400,
360,
2694,
14,
2424,
297,
980,
14,
10483,
8,
1590,
14,
10262,
8,
45,
18,
1826,
7104,
9569,
68,
358,
199,
199,
3,
603,
12,
1962,
4131,
12,
1048,
4131,
275,
10026,
33,
3395,
26135,
850,
8,
45,
12,
1109,
8,
1274,
14,
3020,
59,
19,
2522,
1109,
8,
1274,
14,
3020,
59,
20,
2459,
199,
3,
2457,
63,
354,
275,
298,
1199,
3149,
83,
4970,
83,
4970,
83,
63,
1541,
14,
8092,
2,
450,
334,
1274,
14,
3020,
59,
18,
467,
984,
14,
3020,
59,
19,
467,
984,
14,
3020,
59,
20,
566,
199,
3,
5927,
14,
2724,
1332,
1143,
4131,
12,
1048,
4131,
395,
1551,
8,
1541,
63,
354,
12,
298,
6603,
2,
5082,
199,
3,
870,
298,
8669,
1007,
6031,
26,
2215,
275,
3872,
603,
14,
1392,
12,
298,
768,
3872,
900,
14,
521,
342,
446,
1343,
63,
521,
199,
3,
10026,
63,
7218,
275,
1543,
83,
4970,
83,
4970,
83,
14,
2424,
7,
450,
334,
1274,
14,
3020,
59,
18,
467,
984,
14,
3020,
59,
19,
467,
984,
14,
3020,
59,
20,
566,
199,
3,
5927,
14,
2724,
8,
45,
12,
1551,
8,
9401,
63,
7218,
12,
298,
6603,
2237,
199,
3,
980,
14,
23374,
386,
400,
8,
9401,
63,
7218,
12,
603,
14,
10262,
1252,
10483,
1062,
7104,
9569,
73,
358,
199,
199,
1361,
298,
8669,
3575,
666,
401,
298,
768,
3872,
900,
14,
521,
342,
446,
1343,
63,
521,
199,
20692,
1322,
275,
943,
6004,
8364,
33,
432,
26135,
850,
8,
45,
9,
199,
1361,
20482,
1322,
199,
1590,
14,
23374,
386,
400,
3647,
83,
14,
3838,
2,
450,
334,
1274,
14,
3020,
59,
18,
467,
2318,
980,
14,
1144,
8,
513,
8,
20692,
1322,
59,
16,
1527,
16,
12884,
7104,
9569,
68,
358,
199,
1590,
14,
23374,
386,
400,
3647,
83,
14,
4574,
2,
450,
334,
1274,
14,
3020,
59,
18,
467,
2318,
980,
14,
1144,
8,
513,
8,
20692,
1322,
59,
16,
1527,
17,
12884,
7104,
9569,
68,
358,
199,
1361,
298,
3397,
15884,
365,
3872,
20482,
1322,
59,
17,
61,
199,
1361,
298,
4456,
768,
3872,
900,
14,
521,
342,
446,
1343,
63,
521,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
MebiusHKU/flask-web
|
flask/lib/python2.7/site-packages/pip/_vendor/requests/packages/chardet/gb2312prober.py
|
2994
|
1681
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from .mbcharsetprober import MultiByteCharSetProber
from .codingstatemachine import CodingStateMachine
from .chardistribution import GB2312DistributionAnalysis
from .mbcssm import GB2312SMModel
class GB2312Prober(MultiByteCharSetProber):
def __init__(self):
MultiByteCharSetProber.__init__(self)
self._mCodingSM = CodingStateMachine(GB2312SMModel)
self._mDistributionAnalyzer = GB2312DistributionAnalysis()
self.reset()
def get_charset_name(self):
return "GB2312"
|
bsd-3-clause
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
1303,
6956,
14,
1308,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
887,
6043,
19903,
492,
6879,
21312,
199,
504,
1275,
1523,
929,
6744,
492,
30539,
199,
504,
1275,
1560,
4972,
492,
18553,
16909,
24906,
199,
504,
1275,
887,
3919,
77,
492,
18553,
16909,
25335,
199,
199,
533,
18553,
16909,
8029,
8,
3947,
21312,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6879,
21312,
855,
826,
721,
277,
9,
267,
291,
423,
29633,
275,
30539,
8,
6487,
16909,
25335,
9,
267,
291,
423,
77,
8580,
17606,
275,
18553,
16909,
24906,
342,
267,
291,
14,
3958,
342,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
372,
298,
6487,
16909,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
1303,
6956,
14,
1308,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
887,
6043,
19903,
492,
6879,
21312,
199,
504,
1275,
1523,
929,
6744,
492,
30539,
199,
504,
1275,
1560,
4972,
492,
18553,
16909,
24906,
199,
504,
1275,
887,
3919,
77,
492,
18553,
16909,
25335,
199,
199,
533,
18553,
16909,
8029,
8,
3947,
21312,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6879,
21312,
855,
826,
721,
277,
9,
267,
291,
423,
29633,
275,
30539,
8,
6487,
16909,
25335,
9,
267,
291,
423,
77,
8580,
17606,
275,
18553,
16909,
24906,
342,
267,
291,
14,
3958,
342,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
372,
298,
6487,
16909,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
kch8qx/osf.io
|
website/addons/badges/util.py
|
22
|
1909
|
import io
import os
import errno
import urllib2
from PIL import Image
from collections import defaultdict
from modularodm import Q
from website.addons.badges.settings import * # noqa
#TODO: Possible security errors
#TODO: Send to task queue may lock up thread
def acquire_badge_image(imageurl, uid):
location = os.path.join(BADGES_ABS_LOCATION, uid + '.png')
try:
os.makedirs(BADGES_ABS_LOCATION)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
try:
dl = urllib2.urlopen(imageurl)
except urllib2.URLError:
return None
length = int(dl.info().getheaders('Content-Length')[0])
mime = dl.info().getheaders('Content-Type')[0]
if length > MAX_IMAGE_SIZE or 'image' not in mime:
return None
Image.open(io.BytesIO(dl.read())).save(location)
return os.path.join(BADGES_LOCATION, uid + '.png')
def sort_badges(items):
ret = []
for item in items:
index = next((ind for ind in ret if ind.badge is item.badge), None)
if index:
index.dates[item.awarder.owner.fullname].append((item.issued_date, item.evidence, item.awarder))
index.amount += 1
else:
item.dates = defaultdict(list)
item.dates[item.awarder.owner.fullname] = [(item.issued_date, item.evidence, item.awarder)]
item.amount = 1
ret.append(item)
return ret
def get_node_badges(node):
from .model import BadgeAssertion # Circular import
return BadgeAssertion.find(Q('node', 'eq', node._id) & Q('revoked', 'ne', True))
def get_sorted_node_badges(node):
return sort_badges(get_node_badges(node))
#Lol list comprehensions
def get_user_badges(user):
return [badge for node in user.contributed for badge in get_node_badges(node)]
def get_sorted_user_badges(user):
return sort_badges(get_user_badges(user))
|
apache-2.0
|
[
646,
5890,
199,
646,
747,
199,
646,
7554,
199,
646,
4011,
18,
199,
504,
14937,
492,
6047,
199,
504,
5055,
492,
10018,
199,
199,
504,
3413,
2238,
364,
77,
492,
1413,
199,
504,
10691,
14,
10788,
14,
4087,
3389,
14,
1751,
492,
627,
221,
327,
8151,
421,
199,
3,
11768,
26,
18558,
6391,
2552,
199,
3,
11768,
26,
10217,
370,
2120,
4126,
1443,
4650,
1536,
2462,
199,
318,
16919,
63,
18465,
63,
1569,
8,
1569,
633,
12,
1747,
304,
339,
2909,
275,
747,
14,
515,
14,
904,
8,
9439,
39,
654,
63,
27851,
63,
16575,
12,
1747,
435,
1987,
4524,
358,
339,
862,
26,
267,
747,
14,
8347,
8,
9439,
39,
654,
63,
27851,
63,
16575,
9,
272,
871,
6440,
465,
1919,
26,
267,
340,
1919,
14,
7931,
1137,
7554,
14,
28596,
26,
288,
746,
272,
862,
26,
267,
15396,
275,
4011,
18,
14,
10890,
8,
1569,
633,
9,
272,
871,
4011,
18,
14,
31475,
26,
267,
372,
488,
339,
2582,
275,
1109,
8,
5030,
14,
815,
1252,
19958,
83,
360,
2714,
13,
4625,
5832,
16,
566,
272,
6660,
275,
15396,
14,
815,
1252,
19958,
83,
360,
2714,
13,
804,
5832,
16,
61,
339,
340,
2582,
690,
9141,
63,
9438,
63,
4305,
503,
283,
1569,
7,
440,
315,
6660,
26,
267,
372,
488,
339,
6047,
14,
1490,
8,
2308,
14,
15466,
8,
5030,
14,
739,
4059,
14,
2117,
8,
1985,
9,
339,
372,
747,
14,
515,
14,
904,
8,
9439,
39,
654,
63,
16575,
12,
1747,
435,
1987,
4524,
358,
421,
199,
318,
4069,
63,
4087,
3389,
8,
1744,
304,
272,
2203,
275,
942,
272,
367,
1242,
315,
2974,
26,
267,
1478,
275,
2163,
1332,
688,
367,
7654,
315,
2203,
340,
7654,
14,
18465,
365,
1242,
14,
18465,
395,
488,
9,
267,
340,
1478,
26,
288,
1478,
14,
9356,
59,
1053,
14,
65,
26829,
14,
4597,
14,
9930,
1055,
740,
1332,
1053,
14,
5237,
68,
63,
602,
12,
1242,
14,
69,
433,
5606,
12,
1242,
14,
65,
26829,
430,
288,
1478,
14,
4606,
847,
413,
267,
587,
26,
288,
1242,
14,
9356,
275,
10018,
8,
513,
9,
288,
1242,
14,
9356,
59,
1053,
14,
65,
26829,
14,
4597,
14,
9930,
61,
275,
3842,
1053,
14,
5237,
68,
63,
602,
12,
1242,
14,
69,
433,
5606,
12,
1242,
14,
65,
26829,
1874,
288,
1242,
14,
4606,
275,
413,
288,
2203,
14,
740,
8,
1053,
9,
272,
372,
2203,
421,
199,
318,
664,
63,
932,
63,
4087,
3389,
8,
932,
304,
272,
687,
1275,
1238,
492,
8857,
303,
26860,
221,
327,
445,
24998,
492,
272,
372,
8857,
303,
26860,
14,
1623,
8,
49,
360,
932,
297,
283,
4077,
297,
1031,
423,
344,
9,
1253,
1413,
360,
4964,
7620,
297,
283,
685,
297,
715,
430,
421,
199,
318,
664,
63,
5917,
63,
932,
63,
4087,
3389,
8,
932,
304,
272,
372,
4069,
63,
4087,
3389,
8,
362,
63,
932,
63,
4087,
3389,
8,
932,
430,
421,
199,
3,
44,
393,
769,
1013,
22868,
1356,
199,
318,
664,
63,
751,
63,
4087,
3389,
8,
751,
304,
272,
372,
359,
18465,
367,
1031,
315,
922,
14,
388,
24855,
367,
23122,
315,
664,
63,
932,
63,
4087,
3389,
8,
932,
1874,
421,
199,
318,
664,
63,
5917,
63,
751,
63,
4087,
3389,
8,
751,
304,
272,
372,
4069,
63,
4087,
3389,
8,
362,
63,
751,
63,
4087,
3389,
8,
751,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5890,
199,
646,
747,
199,
646,
7554,
199,
646,
4011,
18,
199,
504,
14937,
492,
6047,
199,
504,
5055,
492,
10018,
199,
199,
504,
3413,
2238,
364,
77,
492,
1413,
199,
504,
10691,
14,
10788,
14,
4087,
3389,
14,
1751,
492,
627,
221,
327,
8151,
421,
199,
3,
11768,
26,
18558,
6391,
2552,
199,
3,
11768,
26,
10217,
370,
2120,
4126,
1443,
4650,
1536,
2462,
199,
318,
16919,
63,
18465,
63,
1569,
8,
1569,
633,
12,
1747,
304,
339,
2909,
275,
747,
14,
515,
14,
904,
8,
9439,
39,
654,
63,
27851,
63,
16575,
12,
1747,
435,
1987,
4524,
358,
339,
862,
26,
267,
747,
14,
8347,
8,
9439,
39,
654,
63,
27851,
63,
16575,
9,
272,
871,
6440,
465,
1919,
26,
267,
340,
1919,
14,
7931,
1137,
7554,
14,
28596,
26,
288,
746,
272,
862,
26,
267,
15396,
275,
4011,
18,
14,
10890,
8,
1569,
633,
9,
272,
871,
4011,
18,
14,
31475,
26,
267,
372,
488,
339,
2582,
275,
1109,
8,
5030,
14,
815,
1252,
19958,
83,
360,
2714,
13,
4625,
5832,
16,
566,
272,
6660,
275,
15396,
14,
815,
1252,
19958,
83,
360,
2714,
13,
804,
5832,
16,
61,
339,
340,
2582,
690,
9141,
63,
9438,
63,
4305,
503,
283,
1569,
7,
440,
315,
6660,
26,
267,
372,
488,
339,
6047,
14,
1490,
8,
2308,
14,
15466,
8,
5030,
14,
739,
4059,
14,
2117,
8,
1985,
9,
339,
372,
747,
14,
515,
14,
904,
8,
9439,
39,
654,
63,
16575,
12,
1747,
435,
1987,
4524,
358,
421,
199,
318,
4069,
63,
4087,
3389,
8,
1744,
304,
272,
2203,
275,
942,
272,
367,
1242,
315,
2974,
26,
267,
1478,
275,
2163,
1332,
688,
367,
7654,
315,
2203,
340,
7654,
14,
18465,
365,
1242,
14,
18465,
395,
488,
9,
267,
340,
1478,
26,
288,
1478,
14,
9356,
59,
1053,
14,
65,
26829,
14,
4597,
14,
9930,
1055,
740,
1332,
1053,
14,
5237,
68,
63,
602,
12,
1242,
14,
69,
433,
5606,
12,
1242,
14,
65,
26829,
430,
288,
1478,
14,
4606,
847,
413,
267,
587,
26,
288,
1242,
14,
9356,
275,
10018,
8,
513,
9,
288,
1242,
14,
9356,
59,
1053,
14,
65,
26829,
14,
4597,
14,
9930,
61,
275,
3842,
1053,
14,
5237,
68,
63,
602,
12,
1242,
14,
69,
433,
5606,
12,
1242,
14,
65,
26829,
1874,
288,
1242,
14,
4606,
275,
413,
288,
2203,
14,
740,
8,
1053,
9,
272,
372,
2203,
421,
199,
318,
664,
63,
932,
63,
4087,
3389,
8,
932,
304,
272,
687,
1275,
1238,
492,
8857,
303,
26860,
221,
327,
445,
24998,
492,
272,
372,
8857,
303,
26860,
14,
1623,
8,
49,
360,
932,
297,
283,
4077,
297,
1031,
423,
344,
9,
1253,
1413,
360,
4964,
7620,
297,
283,
685,
297,
715,
430,
421,
199,
318,
664,
63,
5917,
63,
932,
63,
4087,
3389,
8,
932,
304,
272,
372,
4069,
63,
4087,
3389,
8,
362,
63,
932,
63,
4087,
3389,
8,
932,
430,
421,
199,
3,
44,
393,
769,
1013,
22868,
1356,
199,
318,
664,
63,
751,
63,
4087,
3389,
8,
751,
304,
272,
372,
359,
18465,
367,
1031,
315,
922,
14,
388,
24855,
367,
23122,
315,
664,
63,
932,
63,
4087,
3389,
8,
932,
1874,
421,
199,
318,
664,
63,
5917,
63,
751,
63,
4087,
3389,
8,
751,
304,
272,
372,
4069,
63,
4087,
3389,
8,
362,
63,
751,
63,
4087,
3389,
8,
751,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
markroxor/gensim
|
gensim/test/test_doc2vec.py
|
1
|
23647
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2010 Radim Rehurek <radimrehurek@seznam.cz>
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
"""
Automated tests for checking transformation algorithms (the models package).
"""
from __future__ import with_statement
import logging
import unittest
import os
from six.moves import zip as izip
from collections import namedtuple
from testfixtures import log_capture
import numpy as np
from gensim import utils
from gensim.models import doc2vec, keyedvectors
from gensim.test.utils import datapath, get_tmpfile, common_texts as raw_sentences
class DocsLeeCorpus(object):
def __init__(self, string_tags=False, unicode_tags=False):
self.string_tags = string_tags
self.unicode_tags = unicode_tags
def _tag(self, i):
if self.unicode_tags:
return u'_\xa1_%d' % i
elif self.string_tags:
return '_*%d' % i
return i
def __iter__(self):
with open(datapath('lee_background.cor')) as f:
for i, line in enumerate(f):
yield doc2vec.TaggedDocument(utils.simple_preprocess(line), [self._tag(i)])
list_corpus = list(DocsLeeCorpus())
sentences = [doc2vec.TaggedDocument(words, [i]) for i, words in enumerate(raw_sentences)]
def load_on_instance():
# Save and load a Doc2Vec Model on instance for test
tmpf = get_tmpfile('gensim_doc2vec.tst')
model = doc2vec.Doc2Vec(DocsLeeCorpus(), min_count=1)
model.save(tmpf)
model = doc2vec.Doc2Vec() # should fail at this point
return model.load(tmpf)
class TestDoc2VecModel(unittest.TestCase):
def test_persistence(self):
"""Test storing/loading the entire model."""
tmpf = get_tmpfile('gensim_doc2vec.tst')
model = doc2vec.Doc2Vec(DocsLeeCorpus(), min_count=1)
model.save(tmpf)
self.models_equal(model, doc2vec.Doc2Vec.load(tmpf))
def testPersistenceWord2VecFormat(self):
"""Test storing the entire model in word2vec format."""
model = doc2vec.Doc2Vec(DocsLeeCorpus(), min_count=1)
# test saving both document and word embedding
test_doc_word = get_tmpfile('gensim_doc2vec.dw')
model.save_word2vec_format(test_doc_word, doctag_vec=True, word_vec=True, binary=True)
binary_model_dv = keyedvectors.KeyedVectors.load_word2vec_format(test_doc_word, binary=True)
self.assertEqual(len(model.wv.vocab) + len(model.docvecs), len(binary_model_dv.vocab))
# test saving document embedding only
test_doc = get_tmpfile('gensim_doc2vec.d')
model.save_word2vec_format(test_doc, doctag_vec=True, word_vec=False, binary=True)
binary_model_dv = keyedvectors.KeyedVectors.load_word2vec_format(test_doc, binary=True)
self.assertEqual(len(model.docvecs), len(binary_model_dv.vocab))
# test saving word embedding only
test_word = get_tmpfile('gensim_doc2vec.w')
model.save_word2vec_format(test_word, doctag_vec=False, word_vec=True, binary=True)
binary_model_dv = keyedvectors.KeyedVectors.load_word2vec_format(test_word, binary=True)
self.assertEqual(len(model.wv.vocab), len(binary_model_dv.vocab))
def test_unicode_in_doctag(self):
"""Test storing document vectors of a model with unicode titles."""
model = doc2vec.Doc2Vec(DocsLeeCorpus(unicode_tags=True), min_count=1)
tmpf = get_tmpfile('gensim_doc2vec.tst')
try:
model.save_word2vec_format(tmpf, doctag_vec=True, word_vec=True, binary=True)
except UnicodeEncodeError:
self.fail('Failed storing unicode title.')
def test_load_mmap(self):
"""Test storing/loading the entire model."""
model = doc2vec.Doc2Vec(sentences, min_count=1)
tmpf = get_tmpfile('gensim_doc2vec.tst')
# test storing the internal arrays into separate files
model.save(tmpf, sep_limit=0)
self.models_equal(model, doc2vec.Doc2Vec.load(tmpf))
# make sure mmaping the arrays back works, too
self.models_equal(model, doc2vec.Doc2Vec.load(tmpf, mmap='r'))
def test_int_doctags(self):
"""Test doc2vec doctag alternatives"""
corpus = DocsLeeCorpus()
model = doc2vec.Doc2Vec(min_count=1)
model.build_vocab(corpus)
self.assertEqual(len(model.docvecs.doctag_syn0), 300)
self.assertEqual(model.docvecs[0].shape, (100,))
self.assertEqual(model.docvecs[np.int64(0)].shape, (100,))
self.assertRaises(KeyError, model.__getitem__, '_*0')
def test_missing_string_doctag(self):
"""Test doc2vec doctag alternatives"""
corpus = list(DocsLeeCorpus(True))
# force duplicated tags
corpus = corpus[0:10] + corpus
model = doc2vec.Doc2Vec(min_count=1)
model.build_vocab(corpus)
self.assertRaises(KeyError, model.docvecs.__getitem__, 'not_a_tag')
def test_string_doctags(self):
"""Test doc2vec doctag alternatives"""
corpus = list(DocsLeeCorpus(True))
# force duplicated tags
corpus = corpus[0:10] + corpus
model = doc2vec.Doc2Vec(min_count=1)
model.build_vocab(corpus)
self.assertEqual(len(model.docvecs.doctag_syn0), 300)
self.assertEqual(model.docvecs[0].shape, (100,))
self.assertEqual(model.docvecs['_*0'].shape, (100,))
self.assertTrue(all(model.docvecs['_*0'] == model.docvecs[0]))
self.assertTrue(max(d.offset for d in model.docvecs.doctags.values()) < len(model.docvecs.doctags))
self.assertTrue(
max(model.docvecs._int_index(str_key) for str_key in model.docvecs.doctags.keys())
< len(model.docvecs.doctag_syn0)
)
# verify docvecs.most_similar() returns string doctags rather than indexes
self.assertEqual(model.docvecs.offset2doctag[0], model.docvecs.most_similar([model.docvecs[0]])[0][0])
def test_empty_errors(self):
# no input => "RuntimeError: you must first build vocabulary before training the model"
self.assertRaises(RuntimeError, doc2vec.Doc2Vec, [])
# input not empty, but rather completely filtered out
self.assertRaises(RuntimeError, doc2vec.Doc2Vec, list_corpus, min_count=10000)
def test_similarity_unseen_docs(self):
"""Test similarity of out of training sentences"""
rome_str = ['rome', 'italy']
car_str = ['car']
corpus = list(DocsLeeCorpus(True))
model = doc2vec.Doc2Vec(min_count=1)
model.build_vocab(corpus)
self.assertTrue(
model.docvecs.similarity_unseen_docs(model, rome_str, rome_str) >
model.docvecs.similarity_unseen_docs(model, rome_str, car_str)
)
def model_sanity(self, model, keep_training=True):
"""Any non-trivial model on DocsLeeCorpus can pass these sanity checks"""
fire1 = 0 # doc 0 sydney fires
fire2 = np.int64(8) # doc 8 sydney fires
tennis1 = 6 # doc 6 tennis
# inferred vector should be top10 close to bulk-trained one
doc0_inferred = model.infer_vector(list(DocsLeeCorpus())[0].words)
sims_to_infer = model.docvecs.most_similar([doc0_inferred], topn=len(model.docvecs))
f_rank = [docid for docid, sim in sims_to_infer].index(fire1)
self.assertLess(f_rank, 10)
# fire2 should be top30 close to fire1
sims = model.docvecs.most_similar(fire1, topn=len(model.docvecs))
f2_rank = [docid for docid, sim in sims].index(fire2)
self.assertLess(f2_rank, 30)
# same sims should appear in lookup by vec as by index
doc0_vec = model.docvecs[fire1]
sims2 = model.docvecs.most_similar(positive=[doc0_vec], topn=21)
sims2 = [(id, sim) for id, sim in sims2 if id != fire1] # ignore the doc itself
sims = sims[:20]
self.assertEqual(list(zip(*sims))[0], list(zip(*sims2))[0]) # same doc ids
self.assertTrue(np.allclose(list(zip(*sims))[1], list(zip(*sims2))[1])) # close-enough dists
# sim results should be in clip range if given
clip_sims = \
model.docvecs.most_similar(fire1, clip_start=len(model.docvecs) // 2, clip_end=len(model.docvecs) * 2 // 3)
sims_doc_id = [docid for docid, sim in clip_sims]
for s_id in sims_doc_id:
self.assertTrue(len(model.docvecs) // 2 <= s_id <= len(model.docvecs) * 2 // 3)
# tennis doc should be out-of-place among fire news
self.assertEqual(model.docvecs.doesnt_match([fire1, tennis1, fire2]), tennis1)
# fire docs should be closer than fire-tennis
self.assertTrue(model.docvecs.similarity(fire1, fire2) > model.docvecs.similarity(fire1, tennis1))
# keep training after save
if keep_training:
tmpf = get_tmpfile('gensim_doc2vec.tst')
model.save(tmpf)
loaded = doc2vec.Doc2Vec.load(tmpf)
loaded.train(sentences, total_examples=loaded.corpus_count, epochs=loaded.iter)
def test_training(self):
"""Test doc2vec training."""
corpus = DocsLeeCorpus()
model = doc2vec.Doc2Vec(size=100, min_count=2, iter=20, workers=1)
model.build_vocab(corpus)
self.assertEqual(model.docvecs.doctag_syn0.shape, (300, 100))
model.train(corpus, total_examples=model.corpus_count, epochs=model.iter)
self.model_sanity(model)
# build vocab and train in one step; must be the same as above
model2 = doc2vec.Doc2Vec(corpus, size=100, min_count=2, iter=20, workers=1)
self.models_equal(model, model2)
def test_dbow_hs(self):
"""Test DBOW doc2vec training."""
model = doc2vec.Doc2Vec(list_corpus, dm=0, hs=1, negative=0, min_count=2, iter=20)
self.model_sanity(model)
def test_dmm_hs(self):
"""Test DM/mean doc2vec training."""
model = doc2vec.Doc2Vec(
list_corpus, dm=1, dm_mean=1, size=24, window=4,
hs=1, negative=0, alpha=0.05, min_count=2, iter=20
)
self.model_sanity(model)
def test_dms_hs(self):
"""Test DM/sum doc2vec training."""
model = doc2vec.Doc2Vec(
list_corpus, dm=1, dm_mean=0, size=24, window=4, hs=1,
negative=0, alpha=0.05, min_count=2, iter=20
)
self.model_sanity(model)
def test_dmc_hs(self):
"""Test DM/concatenate doc2vec training."""
model = doc2vec.Doc2Vec(
list_corpus, dm=1, dm_concat=1, size=24, window=4,
hs=1, negative=0, alpha=0.05, min_count=2, iter=20
)
self.model_sanity(model)
def test_dbow_neg(self):
"""Test DBOW doc2vec training."""
model = doc2vec.Doc2Vec(list_corpus, dm=0, hs=0, negative=10, min_count=2, iter=20)
self.model_sanity(model)
def test_dmm_neg(self):
"""Test DM/mean doc2vec training."""
model = doc2vec.Doc2Vec(
list_corpus, dm=1, dm_mean=1, size=24, window=4, hs=0,
negative=10, alpha=0.05, min_count=2, iter=20
)
self.model_sanity(model)
def test_dms_neg(self):
"""Test DM/sum doc2vec training."""
model = doc2vec.Doc2Vec(
list_corpus, dm=1, dm_mean=0, size=24, window=4, hs=0,
negative=10, alpha=0.05, min_count=2, iter=20
)
self.model_sanity(model)
def test_dmc_neg(self):
"""Test DM/concatenate doc2vec training."""
model = doc2vec.Doc2Vec(
list_corpus, dm=1, dm_concat=1, size=24, window=4, hs=0,
negative=10, alpha=0.05, min_count=2, iter=20
)
self.model_sanity(model)
def test_parallel(self):
"""Test doc2vec parallel training."""
if doc2vec.FAST_VERSION < 0: # don't test the plain NumPy version for parallelism (too slow)
return
corpus = utils.RepeatCorpus(DocsLeeCorpus(), 10000)
for workers in [2, 4]:
model = doc2vec.Doc2Vec(corpus, workers=workers)
self.model_sanity(model)
def test_deterministic_hs(self):
"""Test doc2vec results identical with identical RNG seed."""
# hs
model = doc2vec.Doc2Vec(DocsLeeCorpus(), seed=42, workers=1)
model2 = doc2vec.Doc2Vec(DocsLeeCorpus(), seed=42, workers=1)
self.models_equal(model, model2)
def test_deterministic_neg(self):
"""Test doc2vec results identical with identical RNG seed."""
# neg
model = doc2vec.Doc2Vec(DocsLeeCorpus(), hs=0, negative=3, seed=42, workers=1)
model2 = doc2vec.Doc2Vec(DocsLeeCorpus(), hs=0, negative=3, seed=42, workers=1)
self.models_equal(model, model2)
def test_deterministic_dmc(self):
"""Test doc2vec results identical with identical RNG seed."""
# bigger, dmc
model = doc2vec.Doc2Vec(
DocsLeeCorpus(), dm=1, dm_concat=1, size=24,
window=4, hs=1, negative=3, seed=42, workers=1
)
model2 = doc2vec.Doc2Vec(
DocsLeeCorpus(), dm=1, dm_concat=1, size=24,
window=4, hs=1, negative=3, seed=42, workers=1
)
self.models_equal(model, model2)
def test_mixed_tag_types(self):
"""Ensure alternating int/string tags don't share indexes in doctag_syn0"""
mixed_tag_corpus = [doc2vec.TaggedDocument(words, [i, words[0]]) for i, words in enumerate(raw_sentences)]
model = doc2vec.Doc2Vec()
model.build_vocab(mixed_tag_corpus)
expected_length = len(sentences) + len(model.docvecs.doctags) # 9 sentences, 7 unique first tokens
self.assertEqual(len(model.docvecs.doctag_syn0), expected_length)
def models_equal(self, model, model2):
# check words/hidden-weights
self.assertEqual(len(model.wv.vocab), len(model2.wv.vocab))
self.assertTrue(np.allclose(model.wv.syn0, model2.wv.syn0))
if model.hs:
self.assertTrue(np.allclose(model.syn1, model2.syn1))
if model.negative:
self.assertTrue(np.allclose(model.syn1neg, model2.syn1neg))
# check docvecs
self.assertEqual(len(model.docvecs.doctags), len(model2.docvecs.doctags))
self.assertEqual(len(model.docvecs.offset2doctag), len(model2.docvecs.offset2doctag))
self.assertTrue(np.allclose(model.docvecs.doctag_syn0, model2.docvecs.doctag_syn0))
def test_delete_temporary_training_data(self):
"""Test doc2vec model after delete_temporary_training_data"""
for i in [0, 1]:
for j in [0, 1]:
model = doc2vec.Doc2Vec(sentences, size=5, min_count=1, window=4, hs=i, negative=j)
if i:
self.assertTrue(hasattr(model, 'syn1'))
if j:
self.assertTrue(hasattr(model, 'syn1neg'))
self.assertTrue(hasattr(model, 'syn0_lockf'))
model.delete_temporary_training_data(keep_doctags_vectors=False, keep_inference=False)
self.assertTrue(len(model['human']), 10)
self.assertTrue(model.wv.vocab['graph'].count, 5)
self.assertTrue(not hasattr(model, 'syn1'))
self.assertTrue(not hasattr(model, 'syn1neg'))
self.assertTrue(not hasattr(model, 'syn0_lockf'))
self.assertTrue(model.docvecs and not hasattr(model.docvecs, 'doctag_syn0'))
self.assertTrue(model.docvecs and not hasattr(model.docvecs, 'doctag_syn0_lockf'))
model = doc2vec.Doc2Vec(
list_corpus, dm=1, dm_mean=1, size=24, window=4, hs=1,
negative=0, alpha=0.05, min_count=2, iter=20
)
model.delete_temporary_training_data(keep_doctags_vectors=True, keep_inference=True)
self.assertTrue(model.docvecs and hasattr(model.docvecs, 'doctag_syn0'))
self.assertTrue(hasattr(model, 'syn1'))
self.model_sanity(model, keep_training=False)
model = doc2vec.Doc2Vec(
list_corpus, dm=1, dm_mean=1, size=24, window=4, hs=0,
negative=1, alpha=0.05, min_count=2, iter=20
)
model.delete_temporary_training_data(keep_doctags_vectors=True, keep_inference=True)
self.model_sanity(model, keep_training=False)
self.assertTrue(hasattr(model, 'syn1neg'))
def test_word_vec_non_writeable(self):
model = keyedvectors.KeyedVectors.load_word2vec_format(datapath('word2vec_pre_kv_c'))
vector = model['says']
with self.assertRaises(ValueError):
vector *= 0
@log_capture()
def testBuildVocabWarning(self, l):
"""Test if logger warning is raised on non-ideal input to a doc2vec model"""
raw_sentences = ['human', 'machine']
sentences = [doc2vec.TaggedDocument(words, [i]) for i, words in enumerate(raw_sentences)]
model = doc2vec.Doc2Vec()
model.build_vocab(sentences)
warning = "Each 'words' should be a list of words (usually unicode strings)."
self.assertTrue(warning in str(l))
@log_capture()
def testTrainWarning(self, l):
"""Test if warning is raised if alpha rises during subsequent calls to train()"""
raw_sentences = [['human'],
['graph', 'trees']]
sentences = [doc2vec.TaggedDocument(words, [i]) for i, words in enumerate(raw_sentences)]
model = doc2vec.Doc2Vec(alpha=0.025, min_alpha=0.025, min_count=1, workers=8, size=5)
model.build_vocab(sentences)
for epoch in range(10):
model.train(sentences, total_examples=model.corpus_count, epochs=model.iter)
model.alpha -= 0.002
model.min_alpha = model.alpha
if epoch == 5:
model.alpha += 0.05
warning = "Effective 'alpha' higher than previous training cycles"
self.assertTrue(warning in str(l))
def testLoadOnClassError(self):
"""Test if exception is raised when loading doc2vec model on instance"""
self.assertRaises(AttributeError, load_on_instance)
# endclass TestDoc2VecModel
if not hasattr(TestDoc2VecModel, 'assertLess'):
# workaround for python 2.6
def assertLess(self, a, b, msg=None):
self.assertTrue(a < b, msg="%s is not less than %s" % (a, b))
setattr(TestDoc2VecModel, 'assertLess', assertLess)
# following code is useful for reproducing paragraph-vectors paper sentiment experiments
class ConcatenatedDoc2Vec(object):
"""
Concatenation of multiple models for reproducing the Paragraph Vectors paper.
Models must have exactly-matching vocabulary and document IDs. (Models should
be trained separately; this wrapper just returns concatenated results.)
"""
def __init__(self, models):
self.models = models
if hasattr(models[0], 'docvecs'):
self.docvecs = ConcatenatedDocvecs([model.docvecs for model in models])
def __getitem__(self, token):
return np.concatenate([model[token] for model in self.models])
def infer_vector(self, document, alpha=0.1, min_alpha=0.0001, steps=5):
return np.concatenate([model.infer_vector(document, alpha, min_alpha, steps) for model in self.models])
def train(self, *ignore_args, **ignore_kwargs):
pass # train subcomponents individually
class ConcatenatedDocvecs(object):
def __init__(self, models):
self.models = models
def __getitem__(self, token):
return np.concatenate([model[token] for model in self.models])
SentimentDocument = namedtuple('SentimentDocument', 'words tags split sentiment')
def read_su_sentiment_rotten_tomatoes(dirname, lowercase=True):
"""
Read and return documents from the Stanford Sentiment Treebank
corpus (Rotten Tomatoes reviews), from http://nlp.Stanford.edu/sentiment/
Initialize the corpus from a given directory, where
http://nlp.stanford.edu/~socherr/stanfordSentimentTreebank.zip
has been expanded. It's not too big, so compose entirely into memory.
"""
logging.info("loading corpus from %s", dirname)
# many mangled chars in sentences (datasetSentences.txt)
chars_sst_mangled = [
'à', 'á', 'â', 'ã', 'æ', 'ç', 'è', 'é', 'í',
'í', 'ï', 'ñ', 'ó', 'ô', 'ö', 'û', 'ü'
]
sentence_fixups = [(char.encode('utf-8').decode('latin1'), char) for char in chars_sst_mangled]
# more junk, and the replace necessary for sentence-phrase consistency
sentence_fixups.extend([
('Â', ''),
('\xa0', ' '),
('-LRB-', '('),
('-RRB-', ')'),
])
# only this junk in phrases (dictionary.txt)
phrase_fixups = [('\xa0', ' ')]
# sentence_id and split are only positive for the full sentences
# read sentences to temp {sentence -> (id,split) dict, to correlate with dictionary.txt
info_by_sentence = {}
with open(os.path.join(dirname, 'datasetSentences.txt'), 'r') as sentences:
with open(os.path.join(dirname, 'datasetSplit.txt'), 'r') as splits:
next(sentences) # legend
next(splits) # legend
for sentence_line, split_line in izip(sentences, splits):
(id, text) = sentence_line.split('\t')
id = int(id)
text = text.rstrip()
for junk, fix in sentence_fixups:
text = text.replace(junk, fix)
(id2, split_i) = split_line.split(',')
assert id == int(id2)
if text not in info_by_sentence: # discard duplicates
info_by_sentence[text] = (id, int(split_i))
# read all phrase text
phrases = [None] * 239232 # known size of phrases
with open(os.path.join(dirname, 'dictionary.txt'), 'r') as phrase_lines:
for line in phrase_lines:
(text, id) = line.split('|')
for junk, fix in phrase_fixups:
text = text.replace(junk, fix)
phrases[int(id)] = text.rstrip() # for 1st pass just string
SentimentPhrase = namedtuple('SentimentPhrase', SentimentDocument._fields + ('sentence_id',))
# add sentiment labels, correlate with sentences
with open(os.path.join(dirname, 'sentiment_labels.txt'), 'r') as sentiments:
next(sentiments) # legend
for line in sentiments:
(id, sentiment) = line.split('|')
id = int(id)
sentiment = float(sentiment)
text = phrases[id]
words = text.split()
if lowercase:
words = [word.lower() for word in words]
(sentence_id, split_i) = info_by_sentence.get(text, (None, 0))
split = [None, 'train', 'test', 'dev'][split_i]
phrases[id] = SentimentPhrase(words, [id], split, sentiment, sentence_id)
assert len([phrase for phrase in phrases if phrase.sentence_id is not None]) == len(info_by_sentence) # all
# counts don't match 8544, 2210, 1101 because 13 TRAIN and 1 DEV sentences are duplicates
assert len([phrase for phrase in phrases if phrase.split == 'train']) == 8531 # 'train'
assert len([phrase for phrase in phrases if phrase.split == 'test']) == 2210 # 'test'
assert len([phrase for phrase in phrases if phrase.split == 'dev']) == 1100 # 'dev'
logging.info(
"loaded corpus with %i sentences and %i phrases from %s",
len(info_by_sentence), len(phrases), dirname
)
return phrases
if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.DEBUG)
logging.info("using optimization %s", doc2vec.FAST_VERSION)
unittest.main()
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
3898,
3572,
799,
72,
608,
75,
665,
345,
3572,
264,
72,
608,
75,
32,
261,
90,
17811,
14,
16823,
30,
199,
3,
3909,
1334,
314,
1664,
32426,
373,
18,
14,
17,
446,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
199,
199,
624,
199,
23570,
23513,
2295,
367,
7907,
13315,
18036,
334,
1589,
1709,
2559,
680,
199,
624,
421,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
2050,
199,
646,
2882,
199,
646,
747,
199,
199,
504,
3816,
14,
4912,
492,
3482,
465,
28697,
199,
504,
5055,
492,
12863,
199,
504,
511,
8769,
492,
943,
63,
12685,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3805,
5206,
492,
3778,
199,
504,
3805,
5206,
14,
992,
492,
1382,
18,
6046,
12,
19272,
12280,
199,
504,
3805,
5206,
14,
396,
14,
1208,
492,
24991,
12,
664,
63,
21930,
12,
2863,
63,
19517,
465,
3066,
63,
25669,
421,
199,
533,
5454,
83,
44,
1024,
26424,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1059,
63,
2969,
29,
797,
12,
2649,
63,
2969,
29,
797,
304,
267,
291,
14,
875,
63,
2969,
275,
1059,
63,
2969,
267,
291,
14,
2975,
63,
2969,
275,
2649,
63,
2969,
339,
347,
485,
1450,
8,
277,
12,
284,
304,
267,
340,
291,
14,
2975,
63,
2969,
26,
288,
372,
399,
7,
18005,
1800,
17,
4970,
68,
7,
450,
284,
267,
916,
291,
14,
875,
63,
2969,
26,
288,
372,
2513,
32639,
68,
7,
450,
284,
267,
372,
284,
339,
347,
636,
1661,
721,
277,
304,
267,
543,
1551,
8,
25019,
360,
18387,
63,
7451,
14,
989,
1333,
465,
289,
26,
288,
367,
284,
12,
1004,
315,
3874,
8,
70,
304,
355,
1995,
1382,
18,
6046,
14,
26403,
5564,
8,
1208,
14,
4129,
63,
17677,
8,
604,
395,
359,
277,
423,
1450,
8,
73,
3948,
421,
199,
513,
63,
16780,
275,
769,
8,
27858,
44,
1024,
26424,
1012,
421,
199,
25669,
275,
359,
1301,
18,
6046,
14,
26403,
5564,
8,
3148,
12,
359,
73,
566,
367,
284,
12,
5932,
315,
3874,
8,
1773,
63,
25669,
1874,
421,
199,
318,
2248,
63,
265,
63,
842,
837,
272,
327,
11063,
436,
2248,
282,
5454,
18,
14373,
5822,
641,
1256,
367,
511,
272,
3529,
70,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
84,
270,
358,
272,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
8,
27858,
44,
1024,
26424,
1062,
1748,
63,
835,
29,
17,
9,
272,
1402,
14,
2117,
8,
2791,
70,
9,
272,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
342,
221,
327,
1077,
2449,
737,
642,
2376,
272,
372,
1402,
14,
912,
8,
2791,
70,
9,
421,
199,
533,
1379,
3768,
18,
14373,
1685,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
24854,
8,
277,
304,
267,
408,
774,
16915,
15,
8786,
314,
8039,
1402,
1041,
267,
3529,
70,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
84,
270,
358,
267,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
8,
27858,
44,
1024,
26424,
1062,
1748,
63,
835,
29,
17,
9,
267,
1402,
14,
2117,
8,
2791,
70,
9,
267,
291,
14,
992,
63,
1452,
8,
1238,
12,
1382,
18,
6046,
14,
3768,
18,
14373,
14,
912,
8,
2791,
70,
430,
339,
347,
511,
2623,
15284,
10155,
18,
14373,
3484,
8,
277,
304,
267,
408,
774,
16915,
314,
8039,
1402,
315,
4349,
18,
6046,
1475,
1041,
267,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
8,
27858,
44,
1024,
26424,
1062,
1748,
63,
835,
29,
17,
9,
267,
327,
511,
13369,
3865,
2213,
436,
4349,
12452,
267,
511,
63,
1301,
63,
1027,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
10772,
358,
267,
1402,
14,
2117,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1301,
63,
1027,
12,
886,
319,
643,
63,
6046,
29,
549,
12,
4349,
63,
6046,
29,
549,
12,
3366,
29,
549,
9,
267,
3366,
63,
1238,
63,
8398,
275,
19272,
12280,
14,
1197,
379,
31465,
14,
912,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1301,
63,
1027,
12,
3366,
29,
549,
9,
267,
291,
14,
629,
8,
552,
8,
1238,
14,
26880,
14,
9953,
9,
435,
822,
8,
1238,
14,
1301,
25130,
395,
822,
8,
3008,
63,
1238,
63,
8398,
14,
9953,
430,
267,
327,
511,
13369,
2213,
12452,
1454,
267,
511,
63,
1301,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
68,
358,
267,
1402,
14,
2117,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1301,
12,
886,
319,
643,
63,
6046,
29,
549,
12,
4349,
63,
6046,
29,
797,
12,
3366,
29,
549,
9,
267,
3366,
63,
1238,
63,
8398,
275,
19272,
12280,
14,
1197,
379,
31465,
14,
912,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1301,
12,
3366,
29,
549,
9,
267,
291,
14,
629,
8,
552,
8,
1238,
14,
1301,
25130,
395,
822,
8,
3008,
63,
1238,
63,
8398,
14,
9953,
430,
267,
327,
511,
13369,
4349,
12452,
1454,
267,
511,
63,
1027,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
87,
358,
267,
1402,
14,
2117,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1027,
12,
886,
319,
643,
63,
6046,
29,
797,
12,
4349,
63,
6046,
29,
549,
12,
3366,
29,
549,
9,
267,
3366,
63,
1238,
63,
8398,
275,
19272,
12280,
14,
1197,
379,
31465,
14,
912,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1027,
12,
3366,
29,
549,
9,
267,
291,
14,
629,
8,
552,
8,
1238,
14,
26880,
14,
9953,
395,
822,
8,
3008,
63,
1238,
63,
8398,
14,
9953,
430,
339,
347,
511,
63,
2975,
63,
262,
63,
1117,
319,
643,
8,
277,
304,
267,
408,
774,
16915,
2213,
11102,
402,
282,
1402,
543,
2649,
16194,
1041,
267,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
8,
27858,
44,
1024,
26424,
8,
2975,
63,
2969,
29,
549,
395,
1748,
63,
835,
29,
17,
9
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
3898,
3572,
799,
72,
608,
75,
665,
345,
3572,
264,
72,
608,
75,
32,
261,
90,
17811,
14,
16823,
30,
199,
3,
3909,
1334,
314,
1664,
32426,
373,
18,
14,
17,
446,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
199,
199,
624,
199,
23570,
23513,
2295,
367,
7907,
13315,
18036,
334,
1589,
1709,
2559,
680,
199,
624,
421,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
2050,
199,
646,
2882,
199,
646,
747,
199,
199,
504,
3816,
14,
4912,
492,
3482,
465,
28697,
199,
504,
5055,
492,
12863,
199,
504,
511,
8769,
492,
943,
63,
12685,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3805,
5206,
492,
3778,
199,
504,
3805,
5206,
14,
992,
492,
1382,
18,
6046,
12,
19272,
12280,
199,
504,
3805,
5206,
14,
396,
14,
1208,
492,
24991,
12,
664,
63,
21930,
12,
2863,
63,
19517,
465,
3066,
63,
25669,
421,
199,
533,
5454,
83,
44,
1024,
26424,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1059,
63,
2969,
29,
797,
12,
2649,
63,
2969,
29,
797,
304,
267,
291,
14,
875,
63,
2969,
275,
1059,
63,
2969,
267,
291,
14,
2975,
63,
2969,
275,
2649,
63,
2969,
339,
347,
485,
1450,
8,
277,
12,
284,
304,
267,
340,
291,
14,
2975,
63,
2969,
26,
288,
372,
399,
7,
18005,
1800,
17,
4970,
68,
7,
450,
284,
267,
916,
291,
14,
875,
63,
2969,
26,
288,
372,
2513,
32639,
68,
7,
450,
284,
267,
372,
284,
339,
347,
636,
1661,
721,
277,
304,
267,
543,
1551,
8,
25019,
360,
18387,
63,
7451,
14,
989,
1333,
465,
289,
26,
288,
367,
284,
12,
1004,
315,
3874,
8,
70,
304,
355,
1995,
1382,
18,
6046,
14,
26403,
5564,
8,
1208,
14,
4129,
63,
17677,
8,
604,
395,
359,
277,
423,
1450,
8,
73,
3948,
421,
199,
513,
63,
16780,
275,
769,
8,
27858,
44,
1024,
26424,
1012,
421,
199,
25669,
275,
359,
1301,
18,
6046,
14,
26403,
5564,
8,
3148,
12,
359,
73,
566,
367,
284,
12,
5932,
315,
3874,
8,
1773,
63,
25669,
1874,
421,
199,
318,
2248,
63,
265,
63,
842,
837,
272,
327,
11063,
436,
2248,
282,
5454,
18,
14373,
5822,
641,
1256,
367,
511,
272,
3529,
70,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
84,
270,
358,
272,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
8,
27858,
44,
1024,
26424,
1062,
1748,
63,
835,
29,
17,
9,
272,
1402,
14,
2117,
8,
2791,
70,
9,
272,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
342,
221,
327,
1077,
2449,
737,
642,
2376,
272,
372,
1402,
14,
912,
8,
2791,
70,
9,
421,
199,
533,
1379,
3768,
18,
14373,
1685,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
24854,
8,
277,
304,
267,
408,
774,
16915,
15,
8786,
314,
8039,
1402,
1041,
267,
3529,
70,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
84,
270,
358,
267,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
8,
27858,
44,
1024,
26424,
1062,
1748,
63,
835,
29,
17,
9,
267,
1402,
14,
2117,
8,
2791,
70,
9,
267,
291,
14,
992,
63,
1452,
8,
1238,
12,
1382,
18,
6046,
14,
3768,
18,
14373,
14,
912,
8,
2791,
70,
430,
339,
347,
511,
2623,
15284,
10155,
18,
14373,
3484,
8,
277,
304,
267,
408,
774,
16915,
314,
8039,
1402,
315,
4349,
18,
6046,
1475,
1041,
267,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
8,
27858,
44,
1024,
26424,
1062,
1748,
63,
835,
29,
17,
9,
267,
327,
511,
13369,
3865,
2213,
436,
4349,
12452,
267,
511,
63,
1301,
63,
1027,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
10772,
358,
267,
1402,
14,
2117,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1301,
63,
1027,
12,
886,
319,
643,
63,
6046,
29,
549,
12,
4349,
63,
6046,
29,
549,
12,
3366,
29,
549,
9,
267,
3366,
63,
1238,
63,
8398,
275,
19272,
12280,
14,
1197,
379,
31465,
14,
912,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1301,
63,
1027,
12,
3366,
29,
549,
9,
267,
291,
14,
629,
8,
552,
8,
1238,
14,
26880,
14,
9953,
9,
435,
822,
8,
1238,
14,
1301,
25130,
395,
822,
8,
3008,
63,
1238,
63,
8398,
14,
9953,
430,
267,
327,
511,
13369,
2213,
12452,
1454,
267,
511,
63,
1301,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
68,
358,
267,
1402,
14,
2117,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1301,
12,
886,
319,
643,
63,
6046,
29,
549,
12,
4349,
63,
6046,
29,
797,
12,
3366,
29,
549,
9,
267,
3366,
63,
1238,
63,
8398,
275,
19272,
12280,
14,
1197,
379,
31465,
14,
912,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1301,
12,
3366,
29,
549,
9,
267,
291,
14,
629,
8,
552,
8,
1238,
14,
1301,
25130,
395,
822,
8,
3008,
63,
1238,
63,
8398,
14,
9953,
430,
267,
327,
511,
13369,
4349,
12452,
1454,
267,
511,
63,
1027,
275,
664,
63,
21930,
360,
2268,
5206,
63,
1301,
18,
6046,
14,
87,
358,
267,
1402,
14,
2117,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1027,
12,
886,
319,
643,
63,
6046,
29,
797,
12,
4349,
63,
6046,
29,
549,
12,
3366,
29,
549,
9,
267,
3366,
63,
1238,
63,
8398,
275,
19272,
12280,
14,
1197,
379,
31465,
14,
912,
63,
1027,
18,
6046,
63,
908,
8,
396,
63,
1027,
12,
3366,
29,
549,
9,
267,
291,
14,
629,
8,
552,
8,
1238,
14,
26880,
14,
9953,
395,
822,
8,
3008,
63,
1238,
63,
8398,
14,
9953,
430,
339,
347,
511,
63,
2975,
63,
262,
63,
1117,
319,
643,
8,
277,
304,
267,
408,
774,
16915,
2213,
11102,
402,
282,
1402,
543,
2649,
16194,
1041,
267,
1402,
275,
1382,
18,
6046,
14,
3768,
18,
14373,
8,
27858,
44,
1024,
26424,
8,
2975,
63,
2969,
29,
549,
395,
1748,
63,
835,
29,
17,
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,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. See license.txt
from __future__ import unicode_literals
import frappe
import json
from frappe.model.naming import set_name_by_naming_series
from frappe import _, msgprint
import frappe.defaults
from frappe.utils import flt, cint, cstr, today, get_formatted_email, add_months, add_days, formatdate
from frappe.desk.reportview import build_match_conditions, get_filters_cond
from erpnext.utilities.transaction_base import TransactionBase
from erpnext.accounts.party import validate_party_accounts, get_dashboard_info, get_timeline_data # keep this
from frappe.contacts.address_and_contact import load_address_and_contact, delete_contact_and_address
from frappe.model.rename_doc import update_linked_doctypes
from frappe.model.mapper import get_mapped_doc
from frappe.utils.user import get_users_with_role
class Customer(TransactionBase):
def get_feed(self):
return self.customer_name
def onload(self):
"""Load address and contacts in `__onload`"""
load_address_and_contact(self)
self.load_dashboard_info()
def load_dashboard_info(self):
info = get_dashboard_info(self.doctype, self.name, self.loyalty_program)
self.set_onload('dashboard_info', info)
def autoname(self):
cust_master_name = frappe.defaults.get_global_default('cust_master_name')
if cust_master_name == 'Customer Name':
self.name = self.get_customer_name()
else:
set_name_by_naming_series(self)
def get_customer_name(self):
if frappe.db.get_value("Customer", self.customer_name):
count = frappe.db.sql("""select ifnull(MAX(CAST(SUBSTRING_INDEX(name, ' ', -1) AS UNSIGNED)), 0) from tabCustomer
where name like %s""", "%{0} - %".format(self.customer_name), as_list=1)[0][0]
count = cint(count) + 1
return "{0} - {1}".format(self.customer_name, cstr(count))
return self.customer_name
def after_insert(self):
'''If customer created from Lead, update customer id in quotations, opportunities'''
self.update_lead_status()
def validate(self):
self.flags.is_new_doc = self.is_new()
self.flags.old_lead = self.lead_name
validate_party_accounts(self)
self.validate_credit_limit_on_change()
self.set_loyalty_program()
self.check_customer_group_change()
self.validate_default_bank_account()
self.validate_delivery_window_times()
# set loyalty program tier
if frappe.db.exists('Customer', self.name):
customer = frappe.get_doc('Customer', self.name)
if self.loyalty_program == customer.loyalty_program and not self.loyalty_program_tier:
self.loyalty_program_tier = customer.loyalty_program_tier
if self.sales_team:
if sum([member.allocated_percentage or 0 for member in self.sales_team]) != 100:
frappe.throw(_("Total contribution percentage should be equal to 100"))
def check_customer_group_change(self):
frappe.flags.customer_group_changed = False
if not self.get('__islocal'):
if self.customer_group != frappe.db.get_value('Customer', self.name, 'customer_group'):
frappe.flags.customer_group_changed = True
def validate_default_bank_account(self):
if self.default_bank_account:
is_company_account = frappe.db.get_value('Bank Account', self.default_bank_account, 'is_company_account')
if not is_company_account:
frappe.throw(_("{0} is not a company bank account").format(frappe.bold(self.default_bank_account)))
def validate_delivery_window_times(self):
if self.delivery_start_time and self.delivery_end_time:
if self.delivery_start_time > self.delivery_end_time:
return frappe.throw(_('Delivery start window should be before closing window'))
def on_update(self):
self.validate_name_with_customer_group()
self.create_primary_contact()
self.create_primary_address()
if self.flags.old_lead != self.lead_name:
self.update_lead_status()
if self.flags.is_new_doc:
self.create_lead_address_contact()
self.update_customer_groups()
def update_customer_groups(self):
ignore_doctypes = ["Lead", "Opportunity", "POS Profile", "Tax Rule", "Pricing Rule"]
if frappe.flags.customer_group_changed:
update_linked_doctypes('Customer', self.name, 'Customer Group',
self.customer_group, ignore_doctypes)
def create_primary_contact(self):
if not self.customer_primary_contact and not self.lead_name:
if self.mobile_no or self.email_id:
contact = make_contact(self)
self.db_set('customer_primary_contact', contact.name)
self.db_set('mobile_no', self.mobile_no)
self.db_set('email_id', self.email_id)
def create_primary_address(self):
if self.flags.is_new_doc and self.get('address_line1'):
make_address(self)
def update_lead_status(self):
'''If Customer created from Lead, update lead status to "Converted"
update Customer link in Quotation, Opportunity'''
if self.lead_name:
frappe.db.set_value('Lead', self.lead_name, 'status', 'Converted', update_modified=False)
def create_lead_address_contact(self):
if self.lead_name:
# assign lead address to customer (if already not set)
address_names = frappe.get_all('Dynamic Link', filters={
"parenttype":"Address",
"link_doctype":"Lead",
"link_name":self.lead_name
}, fields=["parent as name"])
for address_name in address_names:
address = frappe.get_doc('Address', address_name.get('name'))
if not address.has_link('Customer', self.name):
address.append('links', dict(link_doctype='Customer', link_name=self.name))
address.save()
lead = frappe.db.get_value("Lead", self.lead_name, ["organization_lead", "lead_name", "email_id", "phone", "mobile_no", "gender", "salutation"], as_dict=True)
if not lead.lead_name:
frappe.throw(_("Please mention the Lead Name in Lead {0}").format(self.lead_name))
if lead.organization_lead:
contact_names = frappe.get_all('Dynamic Link', filters={
"parenttype":"Contact",
"link_doctype":"Lead",
"link_name":self.lead_name
}, fields=["parent as name"])
for contact_name in contact_names:
contact = frappe.get_doc('Contact', contact_name.get('name'))
if not contact.has_link('Customer', self.name):
contact.append('links', dict(link_doctype='Customer', link_name=self.name))
contact.save()
else:
lead.lead_name = lead.lead_name.lstrip().split(" ")
lead.first_name = lead.lead_name[0]
lead.last_name = " ".join(lead.lead_name[1:])
# create contact from lead
contact = frappe.new_doc('Contact')
contact.first_name = lead.first_name
contact.last_name = lead.last_name
contact.gender = lead.gender
contact.salutation = lead.salutation
contact.email_id = lead.email_id
contact.phone = lead.phone
contact.mobile_no = lead.mobile_no
contact.is_primary_contact = 1
contact.append('links', dict(link_doctype='Customer', link_name=self.name))
if lead.email_id:
contact.append('email_ids', dict(email_id=lead.email_id, is_primary=1))
if lead.mobile_no:
contact.append('phone_nos', dict(phone=lead.mobile_no, is_primary_mobile_no=1))
contact.flags.ignore_permissions = self.flags.ignore_permissions
contact.autoname()
if not frappe.db.exists("Contact", contact.name):
contact.insert()
def validate_name_with_customer_group(self):
if frappe.db.exists("Customer Group", self.name):
frappe.throw(_("A Customer Group exists with same name please change the Customer name or rename the Customer Group"), frappe.NameError)
def validate_credit_limit_on_change(self):
if self.get("__islocal") or not self.credit_limits:
return
company_record = []
for limit in self.credit_limits:
if limit.company in company_record:
frappe.throw(_("Credit limit is already defined for the Company {0}").format(limit.company, self.name))
else:
company_record.append(limit.company)
outstanding_amt = get_customer_outstanding(self.name, limit.company)
if flt(limit.credit_limit) < outstanding_amt:
frappe.throw(_("""New credit limit is less than current outstanding amount for the customer. Credit limit has to be atleast {0}""").format(outstanding_amt))
def on_trash(self):
if self.customer_primary_contact:
frappe.db.sql("""update `tabCustomer`
set customer_primary_contact=null, mobile_no=null, email_id=null
where name=%s""", self.name)
delete_contact_and_address('Customer', self.name)
if self.lead_name:
frappe.db.sql("update `tabLead` set status='Interested' where name=%s", self.lead_name)
def after_rename(self, olddn, newdn, merge=False):
if frappe.defaults.get_global_default('cust_master_name') == 'Customer Name':
frappe.db.set(self, "customer_name", newdn)
def set_loyalty_program(self):
if self.loyalty_program: return
loyalty_program = get_loyalty_programs(self)
if not loyalty_program: return
if len(loyalty_program) == 1:
self.loyalty_program = loyalty_program[0]
else:
frappe.msgprint(_("Multiple Loyalty Program found for the Customer. Please select manually."))
@frappe.whitelist()
def make_quotation(source_name, target_doc=None):
def set_missing_values(source, target):
_set_missing_values(source, target)
target_doc = get_mapped_doc("Customer", source_name,
{"Customer": {
"doctype": "Quotation",
"field_map": {
"name":"party_name"
}
}}, target_doc, set_missing_values)
target_doc.quotation_to = "Customer"
target_doc.run_method("set_missing_values")
target_doc.run_method("set_other_charges")
target_doc.run_method("calculate_taxes_and_totals")
price_list, currency = frappe.db.get_value("Customer", source_name, ['default_price_list', 'default_currency'])
if price_list:
target_doc.selling_price_list = price_list
if currency:
target_doc.currency = currency
return target_doc
@frappe.whitelist()
def make_opportunity(source_name, target_doc=None):
def set_missing_values(source, target):
_set_missing_values(source, target)
target_doc = get_mapped_doc("Customer", source_name,
{"Customer": {
"doctype": "Opportunity",
"field_map": {
"name": "party_name",
"doctype": "opportunity_from",
}
}}, target_doc, set_missing_values)
return target_doc
@frappe.whitelist()
def make_contract(source_name, target_doc=None):
target_doc = get_mapped_doc("Customer", source_name,
{"Customer": {
"doctype": "Contract",
"field_map": {
"name": "party_name",
"doctype": "party_type",
}
}}, target_doc)
return target_doc
@frappe.whitelist()
def make_subscription(source_name, target_doc=None):
target_doc = get_mapped_doc("Customer", source_name,
{"Customer": {
"doctype": "Subscription",
"field_map": {
"doctype": "party_type",
"name": "party"
}
}}, target_doc)
return target_doc
def _set_missing_values(source, target):
address = frappe.get_all('Dynamic Link', {
'link_doctype': source.doctype,
'link_name': source.name,
'parenttype': 'Address',
}, ['parent'], limit=1)
contact = frappe.get_all('Dynamic Link', {
'link_doctype': source.doctype,
'link_name': source.name,
'parenttype': 'Contact',
}, ['parent'], limit=1)
if address:
target.customer_address = address[0].parent
if contact:
target.contact_person = contact[0].parent
@frappe.whitelist()
def get_loyalty_programs(doc):
''' returns applicable loyalty programs for a customer '''
from frappe.desk.treeview import get_children
lp_details = []
loyalty_programs = frappe.get_all("Loyalty Program",
fields=["name", "customer_group", "customer_territory"],
filters={"auto_opt_in": 1, "from_date": ["<=", today()],
"ifnull(to_date, '2500-01-01')": [">=", today()]})
for loyalty_program in loyalty_programs:
customer_groups = [d.value for d in get_children("Customer Group", loyalty_program.customer_group)] + [loyalty_program.customer_group]
customer_territories = [d.value for d in get_children("Territory", loyalty_program.customer_territory)] + [loyalty_program.customer_territory]
if (not loyalty_program.customer_group or doc.customer_group in customer_groups)\
and (not loyalty_program.customer_territory or doc.territory in customer_territories):
lp_details.append(loyalty_program.name)
return lp_details
def get_customer_list(doctype, txt, searchfield, start, page_len, filters=None):
from erpnext.controllers.queries import get_fields
if frappe.db.get_default("cust_master_name") == "Customer Name":
fields = ["name", "customer_group", "territory"]
else:
fields = ["name", "customer_name", "customer_group", "territory"]
fields = get_fields("Customer", fields)
match_conditions = build_match_conditions("Customer")
match_conditions = "and {}".format(match_conditions) if match_conditions else ""
if filters:
filter_conditions = get_filters_cond(doctype, filters, [])
match_conditions += "{}".format(filter_conditions)
return frappe.db.sql("""
select %s
from `tabCustomer`
where docstatus < 2
and (%s like %s or customer_name like %s)
{match_conditions}
order by
case when name like %s then 0 else 1 end,
case when customer_name like %s then 0 else 1 end,
name, customer_name limit %s, %s
""".format(match_conditions=match_conditions) % (", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"),
("%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, start, page_len))
def check_credit_limit(customer, company, reference_doctype, reference_document, ignore_outstanding_sales_order=False, extra_amount=0):
customer_outstanding = get_customer_outstanding(customer, company, ignore_outstanding_sales_order)
if extra_amount > 0:
customer_outstanding += flt(extra_amount)
credit_limit = get_credit_limit(customer, company)
if credit_limit > 0 and flt(customer_outstanding) > credit_limit:
msgprint(_("Credit limit has been crossed for customer {0} ({1}/{2})")
.format(customer, customer_outstanding, credit_limit))
# If not authorized person raise exception
credit_controller_role = frappe.db.get_single_value('Accounts Settings', 'credit_controller')
if not credit_controller_role or credit_controller_role not in frappe.get_roles():
# form a list of emails for the credit controller users
credit_controller_users = get_users_with_role(credit_controller_role or "Sales Master Manager")
credit_controller_users = [user[0] for user in credit_controller_users]
# form a list of emails and names to show to the user
credit_controller_users_list = [user for user in credit_controller_users if frappe.db.exists("Employee", {"prefered_email": user})]
credit_controller_users = [get_formatted_email(user).replace("<", "(").replace(">", ")") for user in credit_controller_users_list]
if not credit_controller_users:
frappe.throw(_("Please contact your administrator to extend the credit limits for {0}.".format(customer)))
message = """Please contact any of the following users to extend the credit limits for {0}:
<br><br><ul><li>{1}</li></ul>""".format(customer, '<li>'.join(credit_controller_users))
# if the current user does not have permissions to override credit limit,
# prompt them to send out an email to the controller users
frappe.msgprint(message,
title="Notify",
raise_exception=1,
primary_action={
'label': 'Send Email',
'server_action': 'erpnext.selling.doctype.customer.customer.send_emails',
'hide_on_success': 1,
'args': {
'customer': customer,
'customer_outstanding': customer_outstanding,
'credit_limit': credit_limit,
'credit_controller_users_list': credit_controller_users_list,
'document_link': frappe.utils.get_link_to_form(reference_doctype, reference_document)
}
}
)
@frappe.whitelist()
def send_emails(args):
args = json.loads(args)
subject = (_("Credit limit reached for customer {0}").format(args.get('customer')))
message = (_("Credit limit has been crossed for customer {0} ({1}/{2})<br>Document Link: {3}").format(
args.get('customer'), args.get('customer_outstanding'), args.get('credit_limit'), args.get('document_link')))
frappe.sendmail(recipients=args.get('credit_controller_user_list'), subject=subject, message=message)
return (_("""A request was sent to the following people:<br><br><ul><li>{0}</li></ul>""").format(
'<li>'.join(args.get('credit_controller_users_list'))))
def get_customer_outstanding(customer, company, ignore_outstanding_sales_order=False, cost_center=None):
# Outstanding based on GL Entries
cond = ""
if cost_center:
lft, rgt = frappe.get_cached_value("Cost Center",
cost_center, ['lft', 'rgt'])
cond = """ and cost_center in (select name from `tabCost Center` where
lft >= {0} and rgt <= {1})""".format(lft, rgt)
outstanding_based_on_gle = frappe.db.sql("""
select sum(debit) - sum(credit)
from `tabGL Entry` where party_type = 'Customer'
and party = %s and company=%s {0}""".format(cond), (customer, company))
outstanding_based_on_gle = flt(outstanding_based_on_gle[0][0]) if outstanding_based_on_gle else 0
# Outstanding based on Sales Order
outstanding_based_on_so = 0.0
# if credit limit check is bypassed at sales order level,
# we should not consider outstanding Sales Orders, when customer credit balance report is run
if not ignore_outstanding_sales_order:
outstanding_based_on_so = frappe.db.sql("""
select sum(base_grand_total*(100 - per_billed)/100)
from `tabSales Order`
where customer=%s and docstatus = 1 and company=%s
and per_billed < 100 and status != 'Closed'""", (customer, company))
outstanding_based_on_so = flt(outstanding_based_on_so[0][0]) if outstanding_based_on_so else 0.0
# Outstanding based on Delivery Note, which are not created against Sales Order
unmarked_delivery_note_items = frappe.db.sql("""select
dn_item.name, dn_item.amount, dn.base_net_total, dn.base_grand_total
from `tabDelivery Note` dn, `tabDelivery Note Item` dn_item
where
dn.name = dn_item.parent
and dn.customer=%s and dn.company=%s
and dn.docstatus = 1 and dn.status not in ('Closed', 'Stopped')
and ifnull(dn_item.against_sales_order, '') = ''
and ifnull(dn_item.against_sales_invoice, '') = ''
""", (customer, company), as_dict=True)
outstanding_based_on_dn = 0.0
for dn_item in unmarked_delivery_note_items:
si_amount = frappe.db.sql("""select sum(amount)
from `tabSales Invoice Item`
where dn_detail = %s and docstatus = 1""", dn_item.name)[0][0]
if flt(dn_item.amount) > flt(si_amount) and dn_item.base_net_total:
outstanding_based_on_dn += ((flt(dn_item.amount) - flt(si_amount)) \
/ dn_item.base_net_total) * dn_item.base_grand_total
return outstanding_based_on_gle + outstanding_based_on_so + outstanding_based_on_dn
def get_credit_limit(customer, company):
credit_limit = None
if customer:
credit_limit = frappe.db.get_value("Customer Credit Limit",
{'parent': customer, 'parenttype': 'Customer', 'company': company}, 'credit_limit')
if not credit_limit:
customer_group = frappe.get_cached_value("Customer", customer, 'customer_group')
credit_limit = frappe.db.get_value("Customer Credit Limit",
{'parent': customer_group, 'parenttype': 'Customer Group', 'company': company}, 'credit_limit')
if not credit_limit:
credit_limit = frappe.get_cached_value('Company', company, "credit_limit")
return flt(credit_limit)
def make_contact(args, is_primary_contact=1):
contact = frappe.get_doc({
'doctype': 'Contact',
'first_name': args.get('name'),
'is_primary_contact': is_primary_contact,
'links': [{
'link_doctype': args.get('doctype'),
'link_name': args.get('name')
}]
})
if args.get('email_id'):
contact.add_email(args.get('email_id'), is_primary=True)
if args.get('mobile_no'):
contact.add_phone(args.get('mobile_no'), is_primary_mobile_no=True)
contact.insert()
return contact
def make_address(args, is_primary_address=1):
reqd_fields = []
for field in ['city', 'country']:
if not args.get(field):
reqd_fields.append( '<li>' + field.title() + '</li>')
if reqd_fields:
msg = _("Following fields are mandatory to create address:")
frappe.throw("{0} <br><br> <ul>{1}</ul>".format(msg, '\n'.join(reqd_fields)),
title = _("Missing Values Required"))
address = frappe.get_doc({
'doctype': 'Address',
'address_title': args.get('name'),
'address_line1': args.get('address_line1'),
'address_line2': args.get('address_line2'),
'phone': args.get('phone', args.get('mobile_no'), ''),
'city': args.get('city'),
'state': args.get('state'),
'pincode': args.get('pincode'),
'country': args.get('country'),
'links': [{
'link_doctype': args.get('doctype'),
'link_name': args.get('name')
}]
}).insert()
return address
def get_customer_primary_contact(doctype, txt, searchfield, start, page_len, filters):
customer = filters.get('customer')
return frappe.db.sql("""
select `tabContact`.name from `tabContact`, `tabDynamic Link`
where `tabContact`.name = `tabDynamic Link`.parent and `tabDynamic Link`.link_name = %(customer)s
and `tabDynamic Link`.link_doctype = 'Customer'
and `tabContact`.name like %(txt)s
""", {
'customer': customer,
'txt': '%%%s%%' % txt
})
def get_customer_primary_address(doctype, txt, searchfield, start, page_len, filters):
customer = filters.get('customer')
return frappe.db.sql("""
select `tabAddress`.name from `tabAddress`, `tabDynamic Link`
where `tabAddress`.name = `tabDynamic Link`.parent and `tabDynamic Link`.link_name = %(customer)s
and `tabDynamic Link`.link_doctype = 'Customer'
and `tabAddress`.name like %(txt)s
""", {
'customer': customer,
'txt': '%%%s%%' % txt
})
def update_customer_current_month_sales(customer):
current_month_year = formatdate(today(), "MM-yyyy")
results = frappe.db.sql('''
SELECT
SUM(base_grand_total) AS total,
DATE_FORMAT(`posting_date`, '%m-%Y') AS month_year
FROM
`tabSales Invoice`
WHERE
DATE_FORMAT(`posting_date`, '%m-%Y') = '{current_month_year}'
AND docstatus = 1
AND customer = {customer}
GROUP BY
month_year
'''.format(current_month_year=current_month_year, customer=frappe.db.escape(customer)),
as_dict = True)
monthly_total = results[0]['total'] if len(results) > 0 else 0
frappe.db.set_value("Customer", customer, "total_monthly_sales", monthly_total)
def set_total_monthly_sales_to_zero():
# will be trigger on the 1st of month at 12:00 AM and set total_monthly_sales to 0
frappe.db.sql(""" UPDATE `tabCustomer` SET total_monthly_sales = 0""")
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
646,
2022,
199,
504,
6950,
14,
1238,
14,
26919,
492,
663,
63,
354,
63,
991,
63,
26919,
63,
5602,
199,
504,
6950,
492,
5501,
1499,
1361,
199,
646,
6950,
14,
4322,
199,
504,
6950,
14,
1208,
492,
17166,
12,
286,
442,
12,
286,
495,
12,
11168,
12,
664,
63,
15317,
63,
2123,
12,
1050,
63,
16745,
12,
1050,
63,
4899,
12,
1475,
602,
199,
504,
6950,
14,
10368,
14,
3070,
1345,
492,
1900,
63,
1431,
63,
9855,
12,
664,
63,
4273,
63,
2067,
199,
504,
29106,
14,
16355,
14,
5945,
63,
1095,
492,
18244,
1563,
199,
504,
29106,
14,
8370,
14,
7522,
492,
4107,
63,
7522,
63,
8370,
12,
664,
63,
9743,
63,
815,
12,
664,
63,
19369,
63,
576,
327,
4215,
642,
199,
504,
6950,
14,
18147,
14,
1562,
63,
460,
63,
7811,
492,
2248,
63,
1562,
63,
460,
63,
7811,
12,
3145,
63,
7811,
63,
460,
63,
1562,
199,
504,
6950,
14,
1238,
14,
8165,
63,
1301,
492,
1678,
63,
12751,
63,
6356,
83,
199,
504,
6950,
14,
1238,
14,
7153,
492,
664,
63,
11663,
63,
1301,
199,
504,
6950,
14,
1208,
14,
751,
492,
664,
63,
3707,
63,
1045,
63,
3756,
421,
199,
533,
22397,
8,
10161,
1563,
304,
199,
198,
318,
664,
63,
3871,
8,
277,
304,
507,
198,
1107,
291,
14,
10178,
63,
354,
421,
198,
318,
641,
912,
8,
277,
304,
507,
198,
624,
6200,
2287,
436,
27989,
315,
26856,
265,
912,
64,
624,
507,
198,
912,
63,
1562,
63,
460,
63,
7811,
8,
277,
9,
507,
198,
277,
14,
912,
63,
9743,
63,
815,
342,
421,
198,
318,
2248,
63,
9743,
63,
815,
8,
277,
304,
507,
198,
815,
275,
664,
63,
9743,
63,
815,
8,
277,
14,
6356,
12,
291,
14,
354,
12,
291,
14,
3374,
13248,
63,
6815,
9,
507,
198,
277,
14,
409,
63,
265,
912,
360,
9743,
63,
815,
297,
2256,
9,
421,
198,
318,
6384,
32203,
8,
277,
304,
507,
198,
29872,
63,
4133,
63,
354,
275,
6950,
14,
4322,
14,
362,
63,
2966,
63,
885,
360,
29872,
63,
4133,
63,
354,
358,
507,
198,
692,
286,
833,
63,
4133,
63,
354,
508,
283,
17025,
2812,
356,
686,
198,
277,
14,
354,
275,
291,
14,
362,
63,
10178,
63,
354,
342,
507,
198,
2836,
26,
686,
198,
409,
63,
354,
63,
991,
63,
26919,
63,
5602,
8,
277,
9,
421,
198,
318,
664,
63,
10178,
63,
354,
8,
277,
304,
507,
198,
692,
6950,
14,
697,
14,
362,
63,
585,
480,
17025,
401,
291,
14,
10178,
63,
354,
304,
686,
198,
835,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
340,
2307,
8,
4283,
8,
18898,
8,
6348,
5353,
63,
10215,
8,
354,
12,
283,
1656,
446,
17,
9,
4319,
32708,
3203,
1149,
1826,
378,
9,
687,
5174,
17025,
1871,
2382,
536,
2839,
450,
83,
7208,
2071,
91,
16,
93,
446,
450,
1674,
908,
8,
277,
14,
10178,
63,
354,
395,
465,
63,
513,
29,
17,
2788,
16,
1527,
16,
61,
686,
198,
835,
275,
286,
442,
8,
835,
9,
435,
413,
686,
198,
1107,
5310,
16,
93,
446,
469,
17,
5469,
908,
8,
277,
14,
10178,
63,
354,
12,
286,
495,
8,
835,
430,
2742,
198,
1107,
291,
14,
10178,
63,
354,
421,
198,
318,
2410,
63,
3176,
8,
277,
304,
507,
198,
2344,
3917,
15229,
2737,
687,
7005,
350,
12,
1678,
15229,
1305,
315,
7487,
1298,
12,
1687,
719,
22047,
2344,
507,
198,
277,
14,
873,
63,
13799,
63,
1205,
342,
421,
198,
318,
4107,
8,
277,
304,
507,
198,
277,
14,
2469,
14,
374,
63,
1222,
63,
1301,
275,
291,
14,
374,
63,
1222,
342,
507,
198,
277,
14,
2469,
14,
1753,
63,
13799,
275,
291,
14,
13799,
63,
354,
507,
198,
3502,
63,
7522,
63,
8370,
8,
277,
9,
507,
198,
277,
14,
3502,
63,
9365,
63,
3097,
63,
265,
63,
1461,
342,
507,
198,
277,
14,
409,
63,
3374,
13248,
63,
6815,
342,
507,
198,
277,
14,
1074,
63,
10178,
63,
923,
63,
1461,
342,
507,
198,
277,
14,
3502,
63,
885,
63,
9860,
63,
2048,
342,
507,
198,
277,
14,
3502,
63,
14564,
63,
3806,
63,
4508,
342,
2742,
198,
3,
663,
560,
89,
13248,
2240,
31800,
507,
198,
692,
6950,
14,
697,
14,
2444,
360,
17025,
297,
291,
14,
354,
304,
686,
198,
10178,
275,
6950,
14,
362,
63,
1301,
360,
17025,
297,
291,
14,
354,
9,
686,
198,
692,
291,
14,
3374,
13248,
63,
6815,
508,
15229,
14,
3374,
13248,
63,
6815,
436,
440,
291,
14,
3374,
13248,
63,
6815,
63,
13949,
26,
1585,
198,
277,
14,
3374,
13248,
63,
6815,
63,
13949,
275,
15229,
14,
3374,
13248,
63,
6815,
63,
13949,
2742,
198,
692,
291,
14,
16175,
63,
5969,
26,
686,
198,
692,
3089,
779,
1114,
14,
19570,
63,
14200,
503,
378,
367,
3653,
315,
291,
14,
16175,
63,
5969,
566,
1137,
2948,
26,
1585,
198,
9098,
14,
11964,
6115,
7316,
406,
15980,
16327,
1077,
506,
4472,
370,
2948,
2237,
421,
198,
318,
1104,
63,
10178,
63,
923,
63,
1461,
8,
277,
304,
507,
198,
9098,
14,
2469,
14,
10178,
63,
923,
63,
2489,
275,
756,
2742,
198,
692,
440,
291,
14,
362,
10714,
374,
1832,
735,
686,
198,
692,
291,
14,
10178,
63,
923,
1137,
6950,
14,
697,
14,
362,
63,
585,
360,
17025,
297,
291,
14,
354,
12,
283,
10178,
63,
923,
735,
1585,
198,
9098,
14,
2469,
14,
10178,
63,
923,
63,
2489,
275,
715,
421,
198,
318,
4107,
63,
885,
63,
9860,
63,
2048,
8,
277,
304,
507,
198,
692,
291,
14,
885,
63,
9860,
63,
2048,
26,
686,
198,
374,
63,
4627,
63,
2048,
275,
6950,
14,
697,
14,
362,
63,
585,
360,
14814,
9973,
297,
291,
14,
885,
63,
9860,
63,
2048,
12,
283,
374,
63,
4627,
63,
2048,
358,
686,
198,
692,
440,
365,
63,
4627,
63,
2048,
26,
1585,
198,
9098,
14,
11964,
6115,
91,
16,
93,
365,
440,
282
] |
[
1898,
334,
67,
9,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
646,
2022,
199,
504,
6950,
14,
1238,
14,
26919,
492,
663,
63,
354,
63,
991,
63,
26919,
63,
5602,
199,
504,
6950,
492,
5501,
1499,
1361,
199,
646,
6950,
14,
4322,
199,
504,
6950,
14,
1208,
492,
17166,
12,
286,
442,
12,
286,
495,
12,
11168,
12,
664,
63,
15317,
63,
2123,
12,
1050,
63,
16745,
12,
1050,
63,
4899,
12,
1475,
602,
199,
504,
6950,
14,
10368,
14,
3070,
1345,
492,
1900,
63,
1431,
63,
9855,
12,
664,
63,
4273,
63,
2067,
199,
504,
29106,
14,
16355,
14,
5945,
63,
1095,
492,
18244,
1563,
199,
504,
29106,
14,
8370,
14,
7522,
492,
4107,
63,
7522,
63,
8370,
12,
664,
63,
9743,
63,
815,
12,
664,
63,
19369,
63,
576,
327,
4215,
642,
199,
504,
6950,
14,
18147,
14,
1562,
63,
460,
63,
7811,
492,
2248,
63,
1562,
63,
460,
63,
7811,
12,
3145,
63,
7811,
63,
460,
63,
1562,
199,
504,
6950,
14,
1238,
14,
8165,
63,
1301,
492,
1678,
63,
12751,
63,
6356,
83,
199,
504,
6950,
14,
1238,
14,
7153,
492,
664,
63,
11663,
63,
1301,
199,
504,
6950,
14,
1208,
14,
751,
492,
664,
63,
3707,
63,
1045,
63,
3756,
421,
199,
533,
22397,
8,
10161,
1563,
304,
199,
198,
318,
664,
63,
3871,
8,
277,
304,
507,
198,
1107,
291,
14,
10178,
63,
354,
421,
198,
318,
641,
912,
8,
277,
304,
507,
198,
624,
6200,
2287,
436,
27989,
315,
26856,
265,
912,
64,
624,
507,
198,
912,
63,
1562,
63,
460,
63,
7811,
8,
277,
9,
507,
198,
277,
14,
912,
63,
9743,
63,
815,
342,
421,
198,
318,
2248,
63,
9743,
63,
815,
8,
277,
304,
507,
198,
815,
275,
664,
63,
9743,
63,
815,
8,
277,
14,
6356,
12,
291,
14,
354,
12,
291,
14,
3374,
13248,
63,
6815,
9,
507,
198,
277,
14,
409,
63,
265,
912,
360,
9743,
63,
815,
297,
2256,
9,
421,
198,
318,
6384,
32203,
8,
277,
304,
507,
198,
29872,
63,
4133,
63,
354,
275,
6950,
14,
4322,
14,
362,
63,
2966,
63,
885,
360,
29872,
63,
4133,
63,
354,
358,
507,
198,
692,
286,
833,
63,
4133,
63,
354,
508,
283,
17025,
2812,
356,
686,
198,
277,
14,
354,
275,
291,
14,
362,
63,
10178,
63,
354,
342,
507,
198,
2836,
26,
686,
198,
409,
63,
354,
63,
991,
63,
26919,
63,
5602,
8,
277,
9,
421,
198,
318,
664,
63,
10178,
63,
354,
8,
277,
304,
507,
198,
692,
6950,
14,
697,
14,
362,
63,
585,
480,
17025,
401,
291,
14,
10178,
63,
354,
304,
686,
198,
835,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
340,
2307,
8,
4283,
8,
18898,
8,
6348,
5353,
63,
10215,
8,
354,
12,
283,
1656,
446,
17,
9,
4319,
32708,
3203,
1149,
1826,
378,
9,
687,
5174,
17025,
1871,
2382,
536,
2839,
450,
83,
7208,
2071,
91,
16,
93,
446,
450,
1674,
908,
8,
277,
14,
10178,
63,
354,
395,
465,
63,
513,
29,
17,
2788,
16,
1527,
16,
61,
686,
198,
835,
275,
286,
442,
8,
835,
9,
435,
413,
686,
198,
1107,
5310,
16,
93,
446,
469,
17,
5469,
908,
8,
277,
14,
10178,
63,
354,
12,
286,
495,
8,
835,
430,
2742,
198,
1107,
291,
14,
10178,
63,
354,
421,
198,
318,
2410,
63,
3176,
8,
277,
304,
507,
198,
2344,
3917,
15229,
2737,
687,
7005,
350,
12,
1678,
15229,
1305,
315,
7487,
1298,
12,
1687,
719,
22047,
2344,
507,
198,
277,
14,
873,
63,
13799,
63,
1205,
342,
421,
198,
318,
4107,
8,
277,
304,
507,
198,
277,
14,
2469,
14,
374,
63,
1222,
63,
1301,
275,
291,
14,
374,
63,
1222,
342,
507,
198,
277,
14,
2469,
14,
1753,
63,
13799,
275,
291,
14,
13799,
63,
354,
507,
198,
3502,
63,
7522,
63,
8370,
8,
277,
9,
507,
198,
277,
14,
3502,
63,
9365,
63,
3097,
63,
265,
63,
1461,
342,
507,
198,
277,
14,
409,
63,
3374,
13248,
63,
6815,
342,
507,
198,
277,
14,
1074,
63,
10178,
63,
923,
63,
1461,
342,
507,
198,
277,
14,
3502,
63,
885,
63,
9860,
63,
2048,
342,
507,
198,
277,
14,
3502,
63,
14564,
63,
3806,
63,
4508,
342,
2742,
198,
3,
663,
560,
89,
13248,
2240,
31800,
507,
198,
692,
6950,
14,
697,
14,
2444,
360,
17025,
297,
291,
14,
354,
304,
686,
198,
10178,
275,
6950,
14,
362,
63,
1301,
360,
17025,
297,
291,
14,
354,
9,
686,
198,
692,
291,
14,
3374,
13248,
63,
6815,
508,
15229,
14,
3374,
13248,
63,
6815,
436,
440,
291,
14,
3374,
13248,
63,
6815,
63,
13949,
26,
1585,
198,
277,
14,
3374,
13248,
63,
6815,
63,
13949,
275,
15229,
14,
3374,
13248,
63,
6815,
63,
13949,
2742,
198,
692,
291,
14,
16175,
63,
5969,
26,
686,
198,
692,
3089,
779,
1114,
14,
19570,
63,
14200,
503,
378,
367,
3653,
315,
291,
14,
16175,
63,
5969,
566,
1137,
2948,
26,
1585,
198,
9098,
14,
11964,
6115,
7316,
406,
15980,
16327,
1077,
506,
4472,
370,
2948,
2237,
421,
198,
318,
1104,
63,
10178,
63,
923,
63,
1461,
8,
277,
304,
507,
198,
9098,
14,
2469,
14,
10178,
63,
923,
63,
2489,
275,
756,
2742,
198,
692,
440,
291,
14,
362,
10714,
374,
1832,
735,
686,
198,
692,
291,
14,
10178,
63,
923,
1137,
6950,
14,
697,
14,
362,
63,
585,
360,
17025,
297,
291,
14,
354,
12,
283,
10178,
63,
923,
735,
1585,
198,
9098,
14,
2469,
14,
10178,
63,
923,
63,
2489,
275,
715,
421,
198,
318,
4107,
63,
885,
63,
9860,
63,
2048,
8,
277,
304,
507,
198,
692,
291,
14,
885,
63,
9860,
63,
2048,
26,
686,
198,
374,
63,
4627,
63,
2048,
275,
6950,
14,
697,
14,
362,
63,
585,
360,
14814,
9973,
297,
291,
14,
885,
63,
9860,
63,
2048,
12,
283,
374,
63,
4627,
63,
2048,
358,
686,
198,
692,
440,
365,
63,
4627,
63,
2048,
26,
1585,
198,
9098,
14,
11964,
6115,
91,
16,
93,
365,
440,
282,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
barseghyanartur/jellyfish
|
jellyfish/porter.py
|
1
|
6796
|
from .compat import _range
_s2_options = {
'a': ((['a', 't', 'i', 'o', 'n', 'a', 'l'], ['a', 't', 'e']),
(['t', 'i', 'o', 'n', 'a', 'l'], ['t', 'i', 'o', 'n'])),
'c': ((['e', 'n', 'c', 'i'], ['e', 'n', 'c', 'e']),
(['a', 'n', 'c', 'i'], ['a', 'n', 'c', 'e']),),
'e': ((['i', 'z', 'e', 'r'], ['i', 'z', 'e']),),
'l': ((['b', 'l', 'i'], ['b', 'l', 'e']),
(['a', 'l', 'l', 'i'], ['a', 'l']),
(['e', 'n', 't', 'l', 'i'], ['e', 'n', 't']),
(['e', 'l', 'i'], ['e']),
(['o', 'u', 's', 'l', 'i'], ['o', 'u', 's']),),
'o': ((['i', 'z', 'a', 't', 'i', 'o', 'n'], ['i', 'z', 'e']),
(['a', 't', 'i', 'o', 'n'], ['a', 't', 'e']),
(['a', 't', 'o', 'r'], ['a', 't', 'e']),),
's': ((['a', 'l', 'i', 's', 'm'], ['a', 'l']),
(['i', 'v', 'e', 'n', 'e', 's', 's'], ['i', 'v', 'e']),
(['f', 'u', 'l', 'n', 'e', 's', 's'], ['f', 'u', 'l']),
(['o', 'u', 's', 'n', 'e', 's', 's'], ['o', 'u', 's']),),
't': ((['a', 'l', 'i', 't', 'i'], ['a', 'l']),
(['i', 'v', 'i', 't', 'i'], ['i', 'v', 'e']),
(['b', 'i', 'l', 'i', 't', 'i'], ['b', 'l', 'e']),),
'g': ((['l', 'o', 'g', 'i'], ['l', 'o', 'g']),),
}
_s3_options = {
'e': ((['i', 'c', 'a', 't', 'e'], ['i', 'c']),
(['a', 't', 'i', 'v', 'e'], []),
(['a', 'l', 'i', 'z', 'e'], ['a', 'l']),),
'i': ((['i', 'c', 'i', 't', 'i'], ['i', 'c']),),
'l': ((['i', 'c', 'a', 'l'], ['i', 'c']),
(['f', 'u', 'l'], []),),
's': ((['n', 'e', 's', 's'], []),),
}
_s4_endings = {
'a': (['a', 'l'],),
'c': (['a', 'n', 'c', 'e'], ['e', 'n', 'c', 'e']),
'e': (['e', 'r'],),
'i': (['i', 'c'],),
'l': (['a', 'b', 'l', 'e'], ['i', 'b', 'l', 'e']),
'n': (['a', 'n', 't'], ['e', 'm', 'e', 'n', 't'], ['m', 'e', 'n', 't'],
['e', 'n', 't']),
# handle 'o' separately
's': (['i', 's', 'm'],),
't': (['a', 't', 'e'], ['i', 't', 'i']),
'u': (['o', 'u', 's'],),
'v': (['i', 'v', 'e'],),
'z': (['i', 'z', 'e'],),
}
class Stemmer(object):
def __init__(self, b):
self.b = list(b)
self.k = len(b)-1
self.j = 0
def cons(self, i):
""" True iff b[i] is a consonant """
if self.b[i] in 'aeiou':
return False
elif self.b[i] == 'y':
return True if i == 0 else not self.cons(i-1)
return True
def m(self):
n = i = 0
while True:
if i > self.j:
return n
if not self.cons(i):
break
i += 1
i += 1
while True:
while True:
if i > self.j:
return n
if self.cons(i):
break
i += 1
i += 1
n += 1
while True:
if i > self.j:
return n
if not self.cons(i):
break
i += 1
i += 1
def vowel_in_stem(self):
""" True iff 0...j contains vowel """
for i in _range(0, self.j+1):
if not self.cons(i):
return True
return False
def doublec(self, j):
""" True iff j, j-1 contains double consonant """
if j < 1 or self.b[j] != self.b[j-1]:
return False
return self.cons(j)
def cvc(self, i):
""" True iff i-2,i-1,i is consonent-vowel consonant
and if second c isn't w,x, or y.
used to restore e at end of short words like cave, love, hope, crime
"""
if (i < 2 or not self.cons(i) or self.cons(i-1) or not self.cons(i-2)
or self.b[i] in 'wxy'):
return False
return True
def ends(self, s):
length = len(s)
""" True iff 0...k ends with string s """
res = (self.b[self.k-length+1:self.k+1] == s)
if res:
self.j = self.k - length
return res
def setto(self, s):
""" set j+1...k to string s, readjusting k """
length = len(s)
self.b[self.j+1:self.j+1+length] = s
self.k = self.j + length
def r(self, s):
if self.m() > 0:
self.setto(s)
def step1ab(self):
if self.b[self.k] == 's':
if self.ends(['s', 's', 'e', 's']):
self.k -= 2
elif self.ends(['i', 'e', 's']):
self.setto(['i'])
elif self.b[self.k-1] != 's':
self.k -= 1
if self.ends(['e', 'e', 'd']):
if self.m() > 0:
self.k -= 1
elif ((self.ends(['e', 'd']) or self.ends(['i', 'n', 'g']))
and self.vowel_in_stem()):
self.k = self.j
if self.ends(['a', 't']):
self.setto(['a', 't', 'e'])
elif self.ends(['b', 'l']):
self.setto(['b', 'l', 'e'])
elif self.ends(['i', 'z']):
self.setto(['i', 'z', 'e'])
elif self.doublec(self.k):
self.k -= 1
if self.b[self.k] in 'lsz':
self.k += 1
elif self.m() == 1 and self.cvc(self.k):
self.setto(['e'])
def step1c(self):
""" turn terminal y into i if there's a vowel in stem """
if self.ends(['y']) and self.vowel_in_stem():
self.b[self.k] = 'i'
def step2and3(self):
for end, repl in _s2_options.get(self.b[self.k-1], []):
if self.ends(end):
self.r(repl)
break
for end, repl in _s3_options.get(self.b[self.k], []):
if self.ends(end):
self.r(repl)
break
def step4(self):
ch = self.b[self.k-1]
if ch == 'o':
if not ((self.ends(['i', 'o', 'n']) and self.b[self.j] in 'st') or
self.ends(['o', 'u'])):
return
else:
endings = _s4_endings.get(ch, [])
for end in endings:
if self.ends(end):
break
else:
return
if self.m() > 1:
self.k = self.j
def step5(self):
self.j = self.k
if self.b[self.k] == 'e':
a = self.m()
if a > 1 or a == 1 and not self.cvc(self.k-1):
self.k -= 1
if self.b[self.k] == 'l' and self.doublec(self.k) and self.m() > 1:
self.k -= 1
def result(self):
return ''.join(self.b[:self.k+1])
def stem(self):
if self.k > 1:
self.step1ab()
self.step1c()
self.step2and3()
self.step4()
self.step5()
return self.result()
|
bsd-3-clause
|
[
504,
1275,
5819,
492,
485,
1842,
199,
199,
63,
83,
18,
63,
1419,
275,
469,
272,
283,
65,
356,
334,
2941,
65,
297,
283,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
297,
283,
65,
297,
283,
76,
995,
788,
65,
297,
283,
84,
297,
283,
69,
3815,
881,
21022,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
297,
283,
65,
297,
283,
76,
995,
788,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
16607,
272,
283,
67,
356,
334,
2941,
69,
297,
283,
78,
297,
283,
67,
297,
283,
73,
995,
788,
69,
297,
283,
78,
297,
283,
67,
297,
283,
69,
3815,
881,
21022,
65,
297,
283,
78,
297,
283,
67,
297,
283,
73,
995,
788,
65,
297,
283,
78,
297,
283,
67,
297,
283,
69,
3815,
395,
272,
283,
69,
356,
334,
2941,
73,
297,
283,
90,
297,
283,
69,
297,
283,
82,
995,
788,
73,
297,
283,
90,
297,
283,
69,
3815,
395,
272,
283,
76,
356,
334,
2941,
66,
297,
283,
76,
297,
283,
73,
995,
788,
66,
297,
283,
76,
297,
283,
69,
3815,
881,
21022,
65,
297,
283,
76,
297,
283,
76,
297,
283,
73,
995,
788,
65,
297,
283,
76,
3815,
881,
21022,
69,
297,
283,
78,
297,
283,
84,
297,
283,
76,
297,
283,
73,
995,
788,
69,
297,
283,
78,
297,
283,
84,
3815,
881,
21022,
69,
297,
283,
76,
297,
283,
73,
995,
788,
69,
3815,
881,
21022,
79,
297,
283,
85,
297,
283,
83,
297,
283,
76,
297,
283,
73,
995,
788,
79,
297,
283,
85,
297,
283,
83,
3815,
395,
272,
283,
79,
356,
334,
2941,
73,
297,
283,
90,
297,
283,
65,
297,
283,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
995,
788,
73,
297,
283,
90,
297,
283,
69,
3815,
881,
21022,
65,
297,
283,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
995,
788,
65,
297,
283,
84,
297,
283,
69,
3815,
881,
21022,
65,
297,
283,
84,
297,
283,
79,
297,
283,
82,
995,
788,
65,
297,
283,
84,
297,
283,
69,
3815,
395,
272,
283,
83,
356,
334,
2941,
65,
297,
283,
76,
297,
283,
73,
297,
283,
83,
297,
283,
77,
995,
788,
65,
297,
283,
76,
3815,
881,
21022,
73,
297,
283,
86,
297,
283,
69,
297,
283,
78,
297,
283,
69,
297,
283,
83,
297,
283,
83,
995,
788,
73,
297,
283,
86,
297,
283,
69,
3815,
881,
21022,
70,
297,
283,
85,
297,
283,
76,
297,
283,
78,
297,
283,
69,
297,
283,
83,
297,
283,
83,
995,
788,
70,
297,
283,
85,
297,
283,
76,
3815,
881,
21022,
79,
297,
283,
85,
297,
283,
83,
297,
283,
78,
297,
283,
69,
297,
283,
83,
297,
283,
83,
995,
788,
79,
297,
283,
85,
297,
283,
83,
3815,
395,
272,
283,
84,
356,
334,
2941,
65,
297,
283,
76,
297,
283,
73,
297,
283,
84,
297,
283,
73,
995,
788,
65,
297,
283,
76,
3815,
881,
21022,
73,
297,
283,
86,
297,
283,
73,
297,
283,
84,
297,
283,
73,
995,
788,
73,
297,
283,
86,
297,
283,
69,
3815,
881,
21022,
66,
297,
283,
73,
297,
283,
76,
297,
283,
73,
297,
283,
84,
297,
283,
73,
995,
788,
66,
297,
283,
76,
297,
283,
69,
3815,
395,
272,
283,
71,
356,
334,
2941,
76,
297,
283,
79,
297,
283,
71,
297,
283,
73,
995,
788,
76,
297,
283,
79,
297,
283,
71,
3815,
395,
199,
93,
421,
199,
63,
83,
19,
63,
1419,
275,
469,
272,
283,
69,
356,
334,
2941,
73,
297,
283,
67,
297,
283,
65,
297,
283,
84,
297,
283,
69,
995,
788,
73,
297,
283,
67,
3815,
881,
21022,
65,
297,
283,
84,
297,
283,
73,
297,
283,
86,
297,
283,
69,
995,
14431,
881,
21022,
65,
297,
283,
76,
297,
283,
73,
297,
283,
90,
297,
283,
69,
995,
788,
65,
297,
283,
76,
3815,
395,
272,
283,
73,
356,
334,
2941,
73,
297,
283,
67,
297,
283,
73,
297,
283,
84,
297,
283,
73,
995,
788,
73,
297,
283,
67,
3815,
395,
272,
283,
76,
356,
334,
2941,
73,
297,
283,
67,
297,
283,
65,
297,
283,
76,
995,
788,
73,
297,
283,
67,
3815,
881,
21022,
70,
297,
283,
85,
297,
283,
76,
995,
14431,
395,
272,
283,
83,
356,
334,
2941,
78,
297,
283,
69,
297,
283,
83,
297,
283,
83,
995,
14431,
395,
199,
93,
199,
199,
63,
83,
20,
63,
500,
780,
275,
469,
272,
283,
65,
356,
21022,
65,
297,
283,
76,
995,
395,
272,
283,
67,
356,
21022,
65,
297,
283,
78,
297,
283,
67,
297,
283,
69,
995,
788,
69,
297,
283,
78,
297,
283,
67,
297,
283,
69,
3815,
272,
283,
69,
356,
21022,
69,
297,
283,
82,
995,
395,
272,
283,
73,
356,
21022,
73,
297,
283,
67,
995,
395,
272,
283,
76,
356,
21022,
65,
297,
283,
66,
297,
283,
76,
297,
283,
69,
995,
788,
73,
297,
283,
66,
297,
283,
76,
297,
283,
69,
3815,
272,
283,
78,
356,
21022,
65,
297,
283,
78,
297,
283,
84,
995,
788,
69,
297,
283,
77,
297,
283,
69,
297,
283,
78,
297,
283,
84,
995,
788,
77,
297,
283,
69,
297,
283,
78,
297,
283,
84,
995,
881,
788,
69,
297,
283,
78,
297,
283,
84,
3815,
272,
327,
2429,
283,
79,
7,
18159,
272,
283,
83,
356,
21022,
73,
297,
283,
83,
297,
283,
77,
995,
395,
272,
283,
84,
356,
21022,
65,
297,
283,
84,
297,
283,
69,
995,
788,
73,
297,
283,
84,
297,
283,
73,
3815,
272,
283,
85,
356,
21022,
79,
297,
283,
85,
297,
283,
83,
995,
395,
272,
283,
86,
356,
21022,
73,
297,
283,
86,
297,
283,
69,
995,
395,
272,
283,
90,
356,
21022,
73,
297,
283,
90,
297,
283,
69,
995,
395,
199,
93,
421,
199,
533,
428,
563,
2626,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
330,
304,
267,
291,
14,
66,
275,
769,
8,
66,
9,
267,
291,
14,
75,
275,
822,
8,
66,
7216,
17,
267,
291,
14,
74,
275,
378,
339,
347,
13447,
8,
277,
12
] |
[
1275,
5819,
492,
485,
1842,
199,
199,
63,
83,
18,
63,
1419,
275,
469,
272,
283,
65,
356,
334,
2941,
65,
297,
283,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
297,
283,
65,
297,
283,
76,
995,
788,
65,
297,
283,
84,
297,
283,
69,
3815,
881,
21022,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
297,
283,
65,
297,
283,
76,
995,
788,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
16607,
272,
283,
67,
356,
334,
2941,
69,
297,
283,
78,
297,
283,
67,
297,
283,
73,
995,
788,
69,
297,
283,
78,
297,
283,
67,
297,
283,
69,
3815,
881,
21022,
65,
297,
283,
78,
297,
283,
67,
297,
283,
73,
995,
788,
65,
297,
283,
78,
297,
283,
67,
297,
283,
69,
3815,
395,
272,
283,
69,
356,
334,
2941,
73,
297,
283,
90,
297,
283,
69,
297,
283,
82,
995,
788,
73,
297,
283,
90,
297,
283,
69,
3815,
395,
272,
283,
76,
356,
334,
2941,
66,
297,
283,
76,
297,
283,
73,
995,
788,
66,
297,
283,
76,
297,
283,
69,
3815,
881,
21022,
65,
297,
283,
76,
297,
283,
76,
297,
283,
73,
995,
788,
65,
297,
283,
76,
3815,
881,
21022,
69,
297,
283,
78,
297,
283,
84,
297,
283,
76,
297,
283,
73,
995,
788,
69,
297,
283,
78,
297,
283,
84,
3815,
881,
21022,
69,
297,
283,
76,
297,
283,
73,
995,
788,
69,
3815,
881,
21022,
79,
297,
283,
85,
297,
283,
83,
297,
283,
76,
297,
283,
73,
995,
788,
79,
297,
283,
85,
297,
283,
83,
3815,
395,
272,
283,
79,
356,
334,
2941,
73,
297,
283,
90,
297,
283,
65,
297,
283,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
995,
788,
73,
297,
283,
90,
297,
283,
69,
3815,
881,
21022,
65,
297,
283,
84,
297,
283,
73,
297,
283,
79,
297,
283,
78,
995,
788,
65,
297,
283,
84,
297,
283,
69,
3815,
881,
21022,
65,
297,
283,
84,
297,
283,
79,
297,
283,
82,
995,
788,
65,
297,
283,
84,
297,
283,
69,
3815,
395,
272,
283,
83,
356,
334,
2941,
65,
297,
283,
76,
297,
283,
73,
297,
283,
83,
297,
283,
77,
995,
788,
65,
297,
283,
76,
3815,
881,
21022,
73,
297,
283,
86,
297,
283,
69,
297,
283,
78,
297,
283,
69,
297,
283,
83,
297,
283,
83,
995,
788,
73,
297,
283,
86,
297,
283,
69,
3815,
881,
21022,
70,
297,
283,
85,
297,
283,
76,
297,
283,
78,
297,
283,
69,
297,
283,
83,
297,
283,
83,
995,
788,
70,
297,
283,
85,
297,
283,
76,
3815,
881,
21022,
79,
297,
283,
85,
297,
283,
83,
297,
283,
78,
297,
283,
69,
297,
283,
83,
297,
283,
83,
995,
788,
79,
297,
283,
85,
297,
283,
83,
3815,
395,
272,
283,
84,
356,
334,
2941,
65,
297,
283,
76,
297,
283,
73,
297,
283,
84,
297,
283,
73,
995,
788,
65,
297,
283,
76,
3815,
881,
21022,
73,
297,
283,
86,
297,
283,
73,
297,
283,
84,
297,
283,
73,
995,
788,
73,
297,
283,
86,
297,
283,
69,
3815,
881,
21022,
66,
297,
283,
73,
297,
283,
76,
297,
283,
73,
297,
283,
84,
297,
283,
73,
995,
788,
66,
297,
283,
76,
297,
283,
69,
3815,
395,
272,
283,
71,
356,
334,
2941,
76,
297,
283,
79,
297,
283,
71,
297,
283,
73,
995,
788,
76,
297,
283,
79,
297,
283,
71,
3815,
395,
199,
93,
421,
199,
63,
83,
19,
63,
1419,
275,
469,
272,
283,
69,
356,
334,
2941,
73,
297,
283,
67,
297,
283,
65,
297,
283,
84,
297,
283,
69,
995,
788,
73,
297,
283,
67,
3815,
881,
21022,
65,
297,
283,
84,
297,
283,
73,
297,
283,
86,
297,
283,
69,
995,
14431,
881,
21022,
65,
297,
283,
76,
297,
283,
73,
297,
283,
90,
297,
283,
69,
995,
788,
65,
297,
283,
76,
3815,
395,
272,
283,
73,
356,
334,
2941,
73,
297,
283,
67,
297,
283,
73,
297,
283,
84,
297,
283,
73,
995,
788,
73,
297,
283,
67,
3815,
395,
272,
283,
76,
356,
334,
2941,
73,
297,
283,
67,
297,
283,
65,
297,
283,
76,
995,
788,
73,
297,
283,
67,
3815,
881,
21022,
70,
297,
283,
85,
297,
283,
76,
995,
14431,
395,
272,
283,
83,
356,
334,
2941,
78,
297,
283,
69,
297,
283,
83,
297,
283,
83,
995,
14431,
395,
199,
93,
199,
199,
63,
83,
20,
63,
500,
780,
275,
469,
272,
283,
65,
356,
21022,
65,
297,
283,
76,
995,
395,
272,
283,
67,
356,
21022,
65,
297,
283,
78,
297,
283,
67,
297,
283,
69,
995,
788,
69,
297,
283,
78,
297,
283,
67,
297,
283,
69,
3815,
272,
283,
69,
356,
21022,
69,
297,
283,
82,
995,
395,
272,
283,
73,
356,
21022,
73,
297,
283,
67,
995,
395,
272,
283,
76,
356,
21022,
65,
297,
283,
66,
297,
283,
76,
297,
283,
69,
995,
788,
73,
297,
283,
66,
297,
283,
76,
297,
283,
69,
3815,
272,
283,
78,
356,
21022,
65,
297,
283,
78,
297,
283,
84,
995,
788,
69,
297,
283,
77,
297,
283,
69,
297,
283,
78,
297,
283,
84,
995,
788,
77,
297,
283,
69,
297,
283,
78,
297,
283,
84,
995,
881,
788,
69,
297,
283,
78,
297,
283,
84,
3815,
272,
327,
2429,
283,
79,
7,
18159,
272,
283,
83,
356,
21022,
73,
297,
283,
83,
297,
283,
77,
995,
395,
272,
283,
84,
356,
21022,
65,
297,
283,
84,
297,
283,
69,
995,
788,
73,
297,
283,
84,
297,
283,
73,
3815,
272,
283,
85,
356,
21022,
79,
297,
283,
85,
297,
283,
83,
995,
395,
272,
283,
86,
356,
21022,
73,
297,
283,
86,
297,
283,
69,
995,
395,
272,
283,
90,
356,
21022,
73,
297,
283,
90,
297,
283,
69,
995,
395,
199,
93,
421,
199,
533,
428,
563,
2626,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
330,
304,
267,
291,
14,
66,
275,
769,
8,
66,
9,
267,
291,
14,
75,
275,
822,
8,
66,
7216,
17,
267,
291,
14,
74,
275,
378,
339,
347,
13447,
8,
277,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
maxive/erp
|
addons/hr/tests/common.py
|
38
|
2037
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import common
class TestHrCommon(common.TransactionCase):
def setUp(self):
super(TestHrCommon, self).setUp()
self.Users = self.env['res.users']
self.group_hr_manager_id = self.ref('hr.group_hr_manager')
self.group_hr_user_id = self.ref('hr.group_hr_user')
self.group_user_id = self.ref('base.group_user')
# Will be used in various test cases of test_hr_flow
self.demo_user_id = self.ref('base.user_demo')
self.main_company_id = self.ref('base.main_company')
self.main_partner_id = self.ref('base.main_partner')
self.rd_department_id = self.ref('hr.dep_rd')
# Creating three users and assigning each a group related to Human Resource Management
self.res_users_hr_manager = self.Users.create({
'company_id': self.main_company_id,
'name': 'HR manager',
'login': 'hrm',
'email': 'hrm@example.com',
'groups_id': [(6, 0, [self.group_hr_manager_id])]
})
self.res_users_hr_officer = self.Users.create({
'company_id': self.main_company_id,
'name': 'HR Officer',
'login': 'hro',
'email': 'hro@example.com',
'groups_id': [(6, 0, [self.group_hr_user_id])]
})
self.res_users_employee = self.Users.create({
'company_id': self.main_company_id,
'name': 'Employee',
'login': 'emp',
'email': 'emp@example.com',
'groups_id': [(6, 0, [self.group_user_id])]
})
# Will be used to test the flow of jobs(i.e. opening the job position for "Developer" for
# recruitment and closing it after recruitment done)
self.job_developer = self.env(user=self.res_users_hr_officer.id).ref('hr.job_developer')
self.employee_niv = self.env(user=self.res_users_hr_officer.id).ref('hr.employee_niv')
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
28811,
14,
2219,
492,
2863,
421,
199,
533,
1379,
40,
82,
7844,
8,
2330,
14,
10161,
1538,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
40,
82,
7844,
12,
291,
680,
5996,
342,
398,
291,
14,
12117,
275,
291,
14,
1813,
459,
470,
14,
3707,
418,
398,
291,
14,
923,
63,
6271,
63,
2609,
63,
344,
275,
291,
14,
1121,
360,
6271,
14,
923,
63,
6271,
63,
2609,
358,
267,
291,
14,
923,
63,
6271,
63,
751,
63,
344,
275,
291,
14,
1121,
360,
6271,
14,
923,
63,
6271,
63,
751,
358,
267,
291,
14,
923,
63,
751,
63,
344,
275,
291,
14,
1121,
360,
1095,
14,
923,
63,
751,
358,
398,
327,
12823,
506,
1202,
315,
7750,
511,
5560,
402,
511,
63,
6271,
63,
1659,
267,
291,
14,
8768,
63,
751,
63,
344,
275,
291,
14,
1121,
360,
1095,
14,
751,
63,
8768,
358,
267,
291,
14,
973,
63,
4627,
63,
344,
275,
291,
14,
1121,
360,
1095,
14,
973,
63,
4627,
358,
267,
291,
14,
973,
63,
3899,
63,
344,
275,
291,
14,
1121,
360,
1095,
14,
973,
63,
3899,
358,
267,
291,
14,
6883,
63,
19623,
63,
344,
275,
291,
14,
1121,
360,
6271,
14,
2601,
63,
6883,
358,
398,
327,
20507,
7795,
4390,
436,
26694,
1924,
282,
1572,
4048,
370,
869,
7652,
7337,
8259,
267,
291,
14,
470,
63,
3707,
63,
6271,
63,
2609,
275,
291,
14,
12117,
14,
981,
2561,
288,
283,
4627,
63,
344,
356,
291,
14,
973,
63,
4627,
63,
344,
12,
288,
283,
354,
356,
283,
14784,
5256,
297,
288,
283,
2886,
356,
283,
22276,
297,
288,
283,
2123,
356,
283,
22276,
32,
2694,
14,
957,
297,
288,
283,
2634,
63,
344,
356,
3842,
22,
12,
378,
12,
359,
277,
14,
923,
63,
6271,
63,
2609,
63,
344,
12457,
267,
3828,
398,
291,
14,
470,
63,
3707,
63,
6271,
63,
1618,
1792,
281,
275,
291,
14,
12117,
14,
981,
2561,
288,
283,
4627,
63,
344,
356,
291,
14,
973,
63,
4627,
63,
344,
12,
288,
283,
354,
356,
283,
14784,
593,
8376,
281,
297,
288,
283,
2886,
356,
283,
72,
293,
297,
288,
283,
2123,
356,
283,
72,
293,
32,
2694,
14,
957,
297,
288,
283,
2634,
63,
344,
356,
3842,
22,
12,
378,
12,
359,
277,
14,
923,
63,
6271,
63,
751,
63,
344,
12457,
267,
3828,
398,
291,
14,
470,
63,
3707,
63,
10103,
275,
291,
14,
12117,
14,
981,
2561,
288,
283,
4627,
63,
344,
356,
291,
14,
973,
63,
4627,
63,
344,
12,
288,
283,
354,
356,
283,
22635,
297,
288,
283,
2886,
356,
283,
2109,
297,
288,
283,
2123,
356,
283,
2109,
32,
2694,
14,
957,
297,
288,
283,
2634,
63,
344,
356,
3842,
22,
12,
378,
12,
359,
277,
14,
923,
63,
751,
63,
344,
12457,
267,
3828,
398,
327,
12823,
506,
1202,
370,
511,
314,
6369,
402,
9643,
8,
73,
14,
69,
14,
13618,
314,
3906,
3421,
367,
298,
31032,
2,
367,
267,
327,
295,
31365,
434,
436,
11261,
652,
2410,
295,
31365,
434,
4224,
9,
267,
291,
14,
2423,
63,
11071,
275,
291,
14,
1813,
8,
751,
29,
277,
14,
470,
63,
3707,
63,
6271,
63,
1618,
1792,
281,
14,
344,
680,
1121,
360,
6271,
14,
2423,
63,
11071,
358,
267,
291,
14,
10103,
63,
78,
1003,
275,
291,
14,
1813,
8,
751,
29,
277,
14,
470,
63,
3707,
63,
6271,
63,
1618,
1792,
281,
14,
344,
680,
1121,
360,
6271,
14,
10103,
63,
78,
1003,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
28811,
14,
2219,
492,
2863,
421,
199,
533,
1379,
40,
82,
7844,
8,
2330,
14,
10161,
1538,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
40,
82,
7844,
12,
291,
680,
5996,
342,
398,
291,
14,
12117,
275,
291,
14,
1813,
459,
470,
14,
3707,
418,
398,
291,
14,
923,
63,
6271,
63,
2609,
63,
344,
275,
291,
14,
1121,
360,
6271,
14,
923,
63,
6271,
63,
2609,
358,
267,
291,
14,
923,
63,
6271,
63,
751,
63,
344,
275,
291,
14,
1121,
360,
6271,
14,
923,
63,
6271,
63,
751,
358,
267,
291,
14,
923,
63,
751,
63,
344,
275,
291,
14,
1121,
360,
1095,
14,
923,
63,
751,
358,
398,
327,
12823,
506,
1202,
315,
7750,
511,
5560,
402,
511,
63,
6271,
63,
1659,
267,
291,
14,
8768,
63,
751,
63,
344,
275,
291,
14,
1121,
360,
1095,
14,
751,
63,
8768,
358,
267,
291,
14,
973,
63,
4627,
63,
344,
275,
291,
14,
1121,
360,
1095,
14,
973,
63,
4627,
358,
267,
291,
14,
973,
63,
3899,
63,
344,
275,
291,
14,
1121,
360,
1095,
14,
973,
63,
3899,
358,
267,
291,
14,
6883,
63,
19623,
63,
344,
275,
291,
14,
1121,
360,
6271,
14,
2601,
63,
6883,
358,
398,
327,
20507,
7795,
4390,
436,
26694,
1924,
282,
1572,
4048,
370,
869,
7652,
7337,
8259,
267,
291,
14,
470,
63,
3707,
63,
6271,
63,
2609,
275,
291,
14,
12117,
14,
981,
2561,
288,
283,
4627,
63,
344,
356,
291,
14,
973,
63,
4627,
63,
344,
12,
288,
283,
354,
356,
283,
14784,
5256,
297,
288,
283,
2886,
356,
283,
22276,
297,
288,
283,
2123,
356,
283,
22276,
32,
2694,
14,
957,
297,
288,
283,
2634,
63,
344,
356,
3842,
22,
12,
378,
12,
359,
277,
14,
923,
63,
6271,
63,
2609,
63,
344,
12457,
267,
3828,
398,
291,
14,
470,
63,
3707,
63,
6271,
63,
1618,
1792,
281,
275,
291,
14,
12117,
14,
981,
2561,
288,
283,
4627,
63,
344,
356,
291,
14,
973,
63,
4627,
63,
344,
12,
288,
283,
354,
356,
283,
14784,
593,
8376,
281,
297,
288,
283,
2886,
356,
283,
72,
293,
297,
288,
283,
2123,
356,
283,
72,
293,
32,
2694,
14,
957,
297,
288,
283,
2634,
63,
344,
356,
3842,
22,
12,
378,
12,
359,
277,
14,
923,
63,
6271,
63,
751,
63,
344,
12457,
267,
3828,
398,
291,
14,
470,
63,
3707,
63,
10103,
275,
291,
14,
12117,
14,
981,
2561,
288,
283,
4627,
63,
344,
356,
291,
14,
973,
63,
4627,
63,
344,
12,
288,
283,
354,
356,
283,
22635,
297,
288,
283,
2886,
356,
283,
2109,
297,
288,
283,
2123,
356,
283,
2109,
32,
2694,
14,
957,
297,
288,
283,
2634,
63,
344,
356,
3842,
22,
12,
378,
12,
359,
277,
14,
923,
63,
751,
63,
344,
12457,
267,
3828,
398,
327,
12823,
506,
1202,
370,
511,
314,
6369,
402,
9643,
8,
73,
14,
69,
14,
13618,
314,
3906,
3421,
367,
298,
31032,
2,
367,
267,
327,
295,
31365,
434,
436,
11261,
652,
2410,
295,
31365,
434,
4224,
9,
267,
291,
14,
2423,
63,
11071,
275,
291,
14,
1813,
8,
751,
29,
277,
14,
470,
63,
3707,
63,
6271,
63,
1618,
1792,
281,
14,
344,
680,
1121,
360,
6271,
14,
2423,
63,
11071,
358,
267,
291,
14,
10103,
63,
78,
1003,
275,
291,
14,
1813,
8,
751,
29,
277,
14,
470,
63,
3707,
63,
6271,
63,
1618,
1792,
281,
14,
344,
680,
1121,
360,
6271,
14,
10103,
63,
78,
1003,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Javier-Acosta/meran
|
dev-plugins/node64/lib/node/wafadmin/Tools/icpc.py
|
4
|
2581
|
#!/usr/bin/env python
# Meran - MERAN UNLP is a ILS (Integrated Library System) wich provides Catalog,
# Circulation and User's Management. It's written in Perl, and uses Apache2
# Web-Server, MySQL database and Sphinx 2 indexing.
# Copyright (C) 2009-2013 Grupo de desarrollo de Meran CeSPI-UNLP
#
# This file is part of Meran.
#
# Meran 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.
#
# Meran 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 Meran. If not, see <http://www.gnu.org/licenses/>.
# encoding: utf-8
# Meran - MERAN UNLP is a ILS (Integrated Library System) wich provides Catalog,
# Circulation and User's Management. It's written in Perl, and uses Apache2
# Web-Server, MySQL database and Sphinx 2 indexing.
# Copyright (C) 2009-2013 Grupo de desarrollo de Meran CeSPI-UNLP
#
# This file is part of Meran.
#
# Meran 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.
#
# Meran 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 Meran. If not, see <http://www.gnu.org/licenses/>.
# Thomas Nagy 2009
import os, sys
import Configure, Options, Utils
import ccroot, ar, gxx
from Configure import conftest
@conftest
def find_icpc(conf):
if sys.platform == 'cygwin':
conf.fatal('The Intel compiler does not work on Cygwin')
v = conf.env
cxx = None
if v['CXX']: cxx = v['CXX']
elif 'CXX' in conf.environ: cxx = conf.environ['CXX']
if not cxx: cxx = conf.find_program('icpc', var='CXX')
if not cxx: conf.fatal('Intel C++ Compiler (icpc) was not found')
cxx = conf.cmd_to_list(cxx)
ccroot.get_cc_version(conf, cxx, icc=True)
v['CXX'] = cxx
v['CXX_NAME'] = 'icc'
detect = '''
find_icpc
find_ar
gxx_common_flags
gxx_modifier_platform
cxx_load_tools
cxx_add_flags
'''
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
18880,
290,
446,
603,
540,
879,
6778,
9257,
365,
282,
473,
5296,
334,
8309,
2587,
972,
11243,
6187,
9,
336,
1158,
6571,
22881,
12,
199,
3,
445,
723,
3119,
425,
436,
2876,
1159,
8259,
14,
2779,
1159,
5313,
315,
3492,
76,
12,
436,
4440,
3668,
18,
199,
3,
6001,
13,
3120,
12,
11200,
3050,
436,
10229,
499,
16356,
14,
199,
3,
1898,
334,
35,
9,
8937,
13,
6965,
598,
5505,
79,
477,
18618,
285,
8459,
320,
477,
18880,
290,
445,
69,
20495,
13,
1734,
9257,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
18880,
290,
14,
199,
3,
199,
3,
18880,
290,
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,
18880,
290,
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,
18880,
290,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
2644,
26,
2774,
13,
24,
199,
199,
3,
18880,
290,
446,
603,
540,
879,
6778,
9257,
365,
282,
473,
5296,
334,
8309,
2587,
972,
11243,
6187,
9,
336,
1158,
6571,
22881,
12,
199,
3,
445,
723,
3119,
425,
436,
2876,
1159,
8259,
14,
2779,
1159,
5313,
315,
3492,
76,
12,
436,
4440,
3668,
18,
199,
3,
6001,
13,
3120,
12,
11200,
3050,
436,
10229,
499,
16356,
14,
199,
3,
1898,
334,
35,
9,
8937,
13,
6965,
598,
5505,
79,
477,
18618,
285,
8459,
320,
477,
18880,
290,
445,
69,
20495,
13,
1734,
9257,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
18880,
290,
14,
199,
3,
199,
3,
18880,
290,
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,
18880,
290,
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,
18880,
290,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
27864,
653,
643,
89,
8937,
199,
199,
646,
747,
12,
984,
199,
646,
15453,
12,
8394,
12,
17397,
199,
646,
7429,
1231,
12,
601,
12,
486,
2154,
199,
504,
15453,
492,
3743,
396,
199,
199,
32,
22454,
199,
318,
2342,
63,
530,
2352,
8,
2190,
304,
199,
198,
692,
984,
14,
3246,
508,
283,
16680,
356,
507,
198,
2190,
14,
16208,
360,
1918,
20619,
6365,
1630,
440,
1736,
641,
445,
18313,
358,
421,
198,
86,
275,
3743,
14,
1813,
199,
198,
9634,
275,
488,
199,
198,
692,
373,
459,
12206,
2565,
17327,
275,
373,
459,
12206,
418,
199,
198,
4164,
283,
12206,
7,
315,
3743,
14,
2314,
26,
17327,
275,
3743,
14,
2314,
459,
12206,
418,
199,
198,
692,
440,
17327,
26,
17327,
275,
3743,
14,
1623,
63,
6815,
360,
530,
2352,
297,
2729,
534,
12206,
358,
199,
198,
692,
440,
17327,
26,
3743,
14,
16208,
360,
27528,
445,
4176,
27154,
334,
530,
2352,
9,
1990,
440,
1911,
358,
199,
198,
9634,
275,
3743,
14,
1760,
63,
475,
63,
513,
8,
9634,
9,
421,
198,
2055,
1231,
14,
362,
63,
2055,
63,
1023,
8,
2190,
12,
17327,
12,
284,
2055,
29,
549,
9,
199,
198,
86,
459,
12206,
418,
275,
17327,
199,
198,
86,
459,
12206,
63,
2339,
418,
275,
283,
530,
67,
7,
199,
199,
13552,
275,
1449,
199,
1623,
63,
530,
2352,
199,
1623,
63,
285,
199,
71,
2154,
63,
2330,
63,
2469,
199,
71,
2154,
63,
18156,
63,
3246,
199,
9634,
63,
912,
63,
2537,
199,
9634,
63,
525,
63,
2469,
199,
2344,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
18880,
290,
446,
603,
540,
879,
6778,
9257,
365,
282,
473,
5296,
334,
8309,
2587,
972,
11243,
6187,
9,
336,
1158,
6571,
22881,
12,
199,
3,
445,
723,
3119,
425,
436,
2876,
1159,
8259,
14,
2779,
1159,
5313,
315,
3492,
76,
12,
436,
4440,
3668,
18,
199,
3,
6001,
13,
3120,
12,
11200,
3050,
436,
10229,
499,
16356,
14,
199,
3,
1898,
334,
35,
9,
8937,
13,
6965,
598,
5505,
79,
477,
18618,
285,
8459,
320,
477,
18880,
290,
445,
69,
20495,
13,
1734,
9257,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
18880,
290,
14,
199,
3,
199,
3,
18880,
290,
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,
18880,
290,
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,
18880,
290,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
2644,
26,
2774,
13,
24,
199,
199,
3,
18880,
290,
446,
603,
540,
879,
6778,
9257,
365,
282,
473,
5296,
334,
8309,
2587,
972,
11243,
6187,
9,
336,
1158,
6571,
22881,
12,
199,
3,
445,
723,
3119,
425,
436,
2876,
1159,
8259,
14,
2779,
1159,
5313,
315,
3492,
76,
12,
436,
4440,
3668,
18,
199,
3,
6001,
13,
3120,
12,
11200,
3050,
436,
10229,
499,
16356,
14,
199,
3,
1898,
334,
35,
9,
8937,
13,
6965,
598,
5505,
79,
477,
18618,
285,
8459,
320,
477,
18880,
290,
445,
69,
20495,
13,
1734,
9257,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
18880,
290,
14,
199,
3,
199,
3,
18880,
290,
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,
18880,
290,
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,
18880,
290,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
27864,
653,
643,
89,
8937,
199,
199,
646,
747,
12,
984,
199,
646,
15453,
12,
8394,
12,
17397,
199,
646,
7429,
1231,
12,
601,
12,
486,
2154,
199,
504,
15453,
492,
3743,
396,
199,
199,
32,
22454,
199,
318,
2342,
63,
530,
2352,
8,
2190,
304,
199,
198,
692,
984,
14,
3246,
508,
283,
16680,
356,
507,
198,
2190,
14,
16208,
360,
1918,
20619,
6365,
1630,
440,
1736,
641,
445,
18313,
358,
421,
198,
86,
275,
3743,
14,
1813,
199,
198,
9634,
275,
488,
199,
198,
692,
373,
459,
12206,
2565,
17327,
275,
373,
459,
12206,
418,
199,
198,
4164,
283,
12206,
7,
315,
3743,
14,
2314,
26,
17327,
275,
3743,
14,
2314,
459,
12206,
418,
199,
198,
692,
440,
17327,
26,
17327,
275,
3743,
14,
1623,
63,
6815,
360,
530,
2352,
297,
2729,
534,
12206,
358,
199,
198,
692,
440,
17327,
26,
3743,
14,
16208,
360,
27528,
445,
4176,
27154,
334,
530,
2352,
9,
1990,
440,
1911,
358,
199,
198,
9634,
275,
3743,
14,
1760,
63,
475,
63,
513,
8,
9634,
9,
421,
198,
2055,
1231,
14,
362,
63,
2055,
63,
1023,
8,
2190,
12,
17327,
12,
284,
2055,
29,
549,
9,
199,
198,
86,
459,
12206,
418,
275,
17327,
199,
198,
86,
459,
12206,
63,
2339,
418,
275,
283,
530,
67,
7,
199,
199,
13552,
275,
1449,
199,
1623,
63,
530,
2352,
199,
1623,
63,
285,
199,
71,
2154,
63,
2330,
63,
2469,
199,
71,
2154,
63,
18156,
63,
3246,
199,
9634,
63,
912,
63,
2537,
199,
9634,
63,
525,
63,
2469,
199,
2344,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
wilvk/ansible
|
lib/ansible/modules/web_infrastructure/jenkins_job.py
|
64
|
11177
|
#!/usr/bin/python
#
# Copyright: (c) Ansible Project
# 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: jenkins_job
short_description: Manage jenkins jobs
description:
- Manage Jenkins jobs by using Jenkins REST API.
requirements:
- "python-jenkins >= 0.4.12"
- "lxml >= 3.3.3"
version_added: "2.2"
author: "Sergio Millan Rodriguez (@sermilrod)"
options:
config:
description:
- config in XML format.
- Required if job does not yet exist.
- Mututally exclusive with C(enabled).
- Considered if C(state=present).
required: false
enabled:
description:
- Whether the job should be enabled or disabled.
- Mututally exclusive with C(config).
- Considered if C(state=present).
required: false
name:
description:
- Name of the Jenkins job.
required: true
password:
description:
- Password to authenticate with the Jenkins server.
required: false
state:
description:
- Attribute that specifies if the job has to be created or deleted.
required: false
default: present
choices: ['present', 'absent']
token:
description:
- API token used to authenticate alternatively to password.
required: false
url:
description:
- Url where the Jenkins server is accessible.
required: false
default: http://localhost:8080
user:
description:
- User to authenticate with the Jenkins server.
required: false
'''
EXAMPLES = '''
# Create a jenkins job using basic authentication
- jenkins_job:
config: "{{ lookup('file', 'templates/test.xml') }}"
name: test
password: admin
url: http://localhost:8080
user: admin
# Create a jenkins job using the token
- jenkins_job:
config: "{{ lookup('template', 'templates/test.xml.j2') }}"
name: test
token: asdfasfasfasdfasdfadfasfasdfasdfc
url: http://localhost:8080
user: admin
# Delete a jenkins job using basic authentication
- jenkins_job:
name: test
password: admin
state: absent
url: http://localhost:8080
user: admin
# Delete a jenkins job using the token
- jenkins_job:
name: test
token: asdfasfasfasdfasdfadfasfasdfasdfc
state: absent
url: http://localhost:8080
user: admin
# Disable a jenkins job using basic authentication
- jenkins_job:
name: test
password: admin
enabled: False
url: http://localhost:8080
user: admin
# Disable a jenkins job using the token
- jenkins_job:
name: test
token: asdfasfasfasdfasdfadfasfasdfasdfc
enabled: False
url: http://localhost:8080
user: admin
'''
RETURN = '''
---
name:
description: Name of the jenkins job.
returned: success
type: string
sample: test-job
state:
description: State of the jenkins job.
returned: success
type: string
sample: present
enabled:
description: Whether the jenkins job is enabled or not.
returned: success
type: bool
sample: true
user:
description: User used for authentication.
returned: success
type: string
sample: admin
url:
description: Url to connect to the Jenkins server.
returned: success
type: string
sample: https://jenkins.mydomain.com
'''
import traceback
try:
import jenkins
python_jenkins_installed = True
except ImportError:
python_jenkins_installed = False
try:
from lxml import etree as ET
python_lxml_installed = True
except ImportError:
python_lxml_installed = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
class JenkinsJob:
def __init__(self, module):
self.module = module
self.config = module.params.get('config')
self.name = module.params.get('name')
self.password = module.params.get('password')
self.state = module.params.get('state')
self.enabled = module.params.get('enabled')
self.token = module.params.get('token')
self.user = module.params.get('user')
self.jenkins_url = module.params.get('url')
self.server = self.get_jenkins_connection()
self.result = {
'changed': False,
'url': self.jenkins_url,
'name': self.name,
'user': self.user,
'state': self.state,
'diff': {
'before': "",
'after': ""
}
}
self.EXCL_STATE = "excluded state"
def get_jenkins_connection(self):
try:
if (self.user and self.password):
return jenkins.Jenkins(self.jenkins_url, self.user, self.password)
elif (self.user and self.token):
return jenkins.Jenkins(self.jenkins_url, self.user, self.token)
elif (self.user and not (self.password or self.token)):
return jenkins.Jenkins(self.jenkins_url, self.user)
else:
return jenkins.Jenkins(self.jenkins_url)
except Exception as e:
self.module.fail_json(msg='Unable to connect to Jenkins server, %s' % to_native(e), exception=traceback.format_exc())
def get_job_status(self):
try:
response = self.server.get_job_info(self.name)
if "color" not in response:
return self.EXCL_STATE
else:
return response['color'].encode('utf-8')
except Exception as e:
self.module.fail_json(msg='Unable to fetch job information, %s' % to_native(e), exception=traceback.format_exc())
def job_exists(self):
try:
return bool(self.server.job_exists(self.name))
except Exception as e:
self.module.fail_json(msg='Unable to validate if job exists, %s for %s' % (to_native(e), self.jenkins_url),
exception=traceback.format_exc())
def get_config(self):
return job_config_to_string(self.config)
def get_current_config(self):
return job_config_to_string(self.server.get_job_config(self.name).encode('utf-8'))
def has_config_changed(self):
# config is optional, if not provided we keep the current config as is
if self.config is None:
return False
config_file = self.get_config()
machine_file = self.get_current_config()
self.result['diff']['after'] = config_file
self.result['diff']['before'] = machine_file
if machine_file != config_file:
return True
return False
def present_job(self):
if self.config is None and self.enabled is None:
self.module.fail_json(msg='one of the following params is required on state=present: config,enabled')
if not self.job_exists():
self.create_job()
else:
self.update_job()
def has_state_changed(self, status):
# Keep in current state if enabled arg_spec is not given
if self.enabled is None:
return False
if ((self.enabled is False and status != "disabled") or (self.enabled is True and status == "disabled")):
return True
return False
def switch_state(self):
if self.enabled is False:
self.server.disable_job(self.name)
else:
self.server.enable_job(self.name)
def update_job(self):
try:
status = self.get_job_status()
# Handle job config
if self.has_config_changed():
self.result['changed'] = True
if not self.module.check_mode:
self.server.reconfig_job(self.name, self.get_config())
# Handle job disable/enable
elif (status != self.EXCL_STATE and self.has_state_changed(status)):
self.result['changed'] = True
if not self.module.check_mode:
self.switch_state()
except Exception as e:
self.module.fail_json(msg='Unable to reconfigure job, %s for %s' % (to_native(e), self.jenkins_url),
exception=traceback.format_exc())
def create_job(self):
if self.config is None:
self.module.fail_json(msg='missing required param: config')
self.result['changed'] = True
try:
config_file = self.get_config()
self.result['diff']['after'] = config_file
if not self.module.check_mode:
self.server.create_job(self.name, config_file)
except Exception as e:
self.module.fail_json(msg='Unable to create job, %s for %s' % (to_native(e), self.jenkins_url),
exception=traceback.format_exc())
def absent_job(self):
if self.job_exists():
self.result['changed'] = True
self.result['diff']['before'] = self.get_current_config()
if not self.module.check_mode:
try:
self.server.delete_job(self.name)
except Exception as e:
self.module.fail_json(msg='Unable to delete job, %s for %s' % (to_native(e), self.jenkins_url),
exception=traceback.format_exc())
def get_result(self):
result = self.result
if self.job_exists():
result['enabled'] = self.get_job_status() != "disabled"
else:
result['enabled'] = None
return result
def test_dependencies(module):
if not python_jenkins_installed:
module.fail_json(msg="python-jenkins required for this module. "
"see http://python-jenkins.readthedocs.io/en/latest/install.html")
if not python_lxml_installed:
module.fail_json(msg="lxml required for this module. "
"see http://lxml.de/installation.html")
def job_config_to_string(xml_str):
return ET.tostring(ET.fromstring(xml_str))
def main():
module = AnsibleModule(
argument_spec=dict(
config=dict(required=False),
name=dict(required=True),
password=dict(required=False, no_log=True),
state=dict(required=False, choices=['present', 'absent'], default="present"),
enabled=dict(required=False, type='bool'),
token=dict(required=False, no_log=True),
url=dict(required=False, default="http://localhost:8080"),
user=dict(required=False)
),
mutually_exclusive=[
['password', 'token'],
['config', 'enabled'],
],
supports_check_mode=True,
)
test_dependencies(module)
jenkins_job = JenkinsJob(module)
if module.params.get('state') == "present":
jenkins_job.present_job()
else:
jenkins_job.absent_job()
result = jenkins_job.get_result()
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
26,
334,
67,
9,
2622,
7290,
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,
29537,
63,
2423,
199,
3612,
63,
1802,
26,
14944,
29537,
9643,
199,
1802,
26,
272,
446,
14944,
32516,
9643,
701,
1808,
32516,
14880,
3261,
14,
199,
7538,
26,
523,
446,
298,
1548,
13,
25622,
2356,
378,
14,
20,
14,
713,
2,
523,
446,
298,
22899,
2356,
650,
14,
19,
14,
19,
2,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
2502,
26,
298,
1505,
71,
2308,
603,
778,
290,
820,
364,
322,
71,
310,
90,
8593,
332,
77,
382,
19402,
2924,
199,
1419,
26,
523,
1101,
26,
272,
1369,
26,
489,
446,
1101,
315,
4692,
1475,
14,
489,
446,
11105,
340,
3906,
1630,
440,
5966,
2187,
14,
489,
446,
26550,
337,
1183,
13914,
543,
445,
8,
3827,
680,
489,
446,
1448,
2441,
581,
340,
445,
8,
929,
29,
1881,
680,
272,
1415,
26,
3055,
523,
5223,
26,
272,
1369,
26,
489,
446,
7480,
314,
3906,
1077,
506,
5223,
503,
6980,
14,
489,
446,
26550,
337,
1183,
13914,
543,
445,
8,
888,
680,
489,
446,
1448,
2441,
581,
340,
445,
8,
929,
29,
1881,
680,
272,
1415,
26,
3055,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
32516,
3906,
14,
272,
1415,
26,
2549,
523,
2505,
26,
272,
1369,
26,
489,
446,
13635,
370,
12895,
543,
314,
32516,
1654,
14,
272,
1415,
26,
3055,
523,
1174,
26,
272,
1369,
26,
489,
446,
3882,
626,
9314,
340,
314,
3906,
965,
370,
506,
2737,
503,
5463,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
523,
1526,
26,
272,
1369,
26,
489,
446,
3261,
1526,
1202,
370,
12895,
8679,
17330,
370,
2505,
14,
272,
1415,
26,
3055,
523,
1166,
26,
272,
1369,
26,
489,
446,
20503,
2382,
314,
32516,
1654,
365,
17909,
14,
272,
1415,
26,
3055,
272,
849,
26,
1455,
921,
5967,
26,
15844,
523,
922,
26,
272,
1369,
26,
2126,
446,
2876,
370,
12895,
543,
314,
32516,
1654,
14,
272,
1415,
26,
3055,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
282,
29537,
3906,
1808,
5678,
6299,
199,
13,
29537,
63,
2423,
26,
272,
1101,
26,
7370,
4237,
360,
493,
297,
283,
5876,
15,
396,
14,
1652,
358,
7820,
272,
536,
26,
511,
272,
2505,
26,
4628,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
2790,
282,
29537,
3906,
1808,
314,
1526,
199,
13,
29537,
63,
2423,
26,
272,
1101,
26,
7370,
4237,
360,
1160,
297,
283,
5876,
15,
396,
14,
1652,
14,
74,
18,
358,
7820,
272,
536,
26,
511,
272,
1526,
26,
465,
1587,
29551,
29551,
18196,
18196,
24642,
29551,
18196,
18196,
67,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
8496,
282,
29537,
3906,
1808,
5678,
6299,
199,
13,
29537,
63,
2423,
26,
272,
536,
26,
511,
272,
2505,
26,
4628,
272,
1174,
26,
9552,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
8496,
282,
29537,
3906,
1808,
314,
1526,
199,
13,
29537,
63,
2423,
26,
272,
536,
26,
511,
272,
1526,
26,
465,
1587,
29551,
29551,
18196,
18196,
24642,
29551,
18196,
18196,
67,
272,
1174,
26,
9552,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
17534,
282,
29537,
3906,
1808,
5678,
6299,
199,
13,
29537,
63,
2423,
26,
272,
536,
26,
511,
272,
2505,
26,
4628,
272,
5223,
26,
756,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
17534,
282,
29537,
3906,
1808,
314,
1526,
199,
13,
29537,
63,
2423,
26,
272,
536,
26,
511,
272,
1526,
26,
465,
1587,
29551,
29551,
18196,
18196,
24642,
29551,
18196,
18196,
67,
272,
5223,
26,
756,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2595,
199,
354,
26,
523,
1369,
26,
2812,
402,
314,
29537,
3906,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
511,
13,
2423,
199,
929,
26,
523,
1369,
26,
8511,
402,
314,
29537,
3906,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
3451,
199,
3827,
26,
523,
1369,
26,
7480,
314,
29537,
3906,
365,
5223,
503,
440,
14,
523,
2138,
26,
3182,
523,
730,
26,
2155,
523,
2690,
26,
2549,
199,
751,
26,
523,
1369,
26,
2876,
1202,
367,
6299,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
4628,
199,
633,
26,
523,
1369,
26,
20503,
370,
4907,
370,
314,
32516,
1654,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
4178,
921,
25622,
14,
30945,
14,
957,
199,
2344,
199,
199,
646,
5190,
199,
199,
893,
26,
272,
492,
29537,
272,
2366,
63,
25622,
63,
7657,
275,
715,
199,
2590,
3545,
26,
272,
2366,
63,
25622,
63,
7657,
275,
756,
199,
199,
893,
26,
272,
687,
14490,
492,
7559,
465,
12265,
272,
2366,
63,
22899,
63,
7657,
275,
715,
199,
2590,
3545,
26,
272,
2366,
63,
22899,
63,
7657,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
421,
199,
533,
32516,
6694,
26,
339,
347,
636,
826,
721,
277,
12,
859,
304,
267,
291,
14,
578,
275,
859,
398,
291,
14,
888,
275,
859,
14,
1162,
14,
362,
360,
888,
358,
267,
291,
14,
354,
275,
859,
14,
1162,
14,
362,
360,
354,
358,
267,
291,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
26,
334,
67,
9,
2622,
7290,
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,
29537,
63,
2423,
199,
3612,
63,
1802,
26,
14944,
29537,
9643,
199,
1802,
26,
272,
446,
14944,
32516,
9643,
701,
1808,
32516,
14880,
3261,
14,
199,
7538,
26,
523,
446,
298,
1548,
13,
25622,
2356,
378,
14,
20,
14,
713,
2,
523,
446,
298,
22899,
2356,
650,
14,
19,
14,
19,
2,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
2502,
26,
298,
1505,
71,
2308,
603,
778,
290,
820,
364,
322,
71,
310,
90,
8593,
332,
77,
382,
19402,
2924,
199,
1419,
26,
523,
1101,
26,
272,
1369,
26,
489,
446,
1101,
315,
4692,
1475,
14,
489,
446,
11105,
340,
3906,
1630,
440,
5966,
2187,
14,
489,
446,
26550,
337,
1183,
13914,
543,
445,
8,
3827,
680,
489,
446,
1448,
2441,
581,
340,
445,
8,
929,
29,
1881,
680,
272,
1415,
26,
3055,
523,
5223,
26,
272,
1369,
26,
489,
446,
7480,
314,
3906,
1077,
506,
5223,
503,
6980,
14,
489,
446,
26550,
337,
1183,
13914,
543,
445,
8,
888,
680,
489,
446,
1448,
2441,
581,
340,
445,
8,
929,
29,
1881,
680,
272,
1415,
26,
3055,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
32516,
3906,
14,
272,
1415,
26,
2549,
523,
2505,
26,
272,
1369,
26,
489,
446,
13635,
370,
12895,
543,
314,
32516,
1654,
14,
272,
1415,
26,
3055,
523,
1174,
26,
272,
1369,
26,
489,
446,
3882,
626,
9314,
340,
314,
3906,
965,
370,
506,
2737,
503,
5463,
14,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
523,
1526,
26,
272,
1369,
26,
489,
446,
3261,
1526,
1202,
370,
12895,
8679,
17330,
370,
2505,
14,
272,
1415,
26,
3055,
523,
1166,
26,
272,
1369,
26,
489,
446,
20503,
2382,
314,
32516,
1654,
365,
17909,
14,
272,
1415,
26,
3055,
272,
849,
26,
1455,
921,
5967,
26,
15844,
523,
922,
26,
272,
1369,
26,
2126,
446,
2876,
370,
12895,
543,
314,
32516,
1654,
14,
272,
1415,
26,
3055,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
282,
29537,
3906,
1808,
5678,
6299,
199,
13,
29537,
63,
2423,
26,
272,
1101,
26,
7370,
4237,
360,
493,
297,
283,
5876,
15,
396,
14,
1652,
358,
7820,
272,
536,
26,
511,
272,
2505,
26,
4628,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
2790,
282,
29537,
3906,
1808,
314,
1526,
199,
13,
29537,
63,
2423,
26,
272,
1101,
26,
7370,
4237,
360,
1160,
297,
283,
5876,
15,
396,
14,
1652,
14,
74,
18,
358,
7820,
272,
536,
26,
511,
272,
1526,
26,
465,
1587,
29551,
29551,
18196,
18196,
24642,
29551,
18196,
18196,
67,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
8496,
282,
29537,
3906,
1808,
5678,
6299,
199,
13,
29537,
63,
2423,
26,
272,
536,
26,
511,
272,
2505,
26,
4628,
272,
1174,
26,
9552,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
8496,
282,
29537,
3906,
1808,
314,
1526,
199,
13,
29537,
63,
2423,
26,
272,
536,
26,
511,
272,
1526,
26,
465,
1587,
29551,
29551,
18196,
18196,
24642,
29551,
18196,
18196,
67,
272,
1174,
26,
9552,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
17534,
282,
29537,
3906,
1808,
5678,
6299,
199,
13,
29537,
63,
2423,
26,
272,
536,
26,
511,
272,
2505,
26,
4628,
272,
5223,
26,
756,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
199,
3,
17534,
282,
29537,
3906,
1808,
314,
1526,
199,
13,
29537,
63,
2423,
26,
272,
536,
26,
511,
272,
1526,
26,
465,
1587,
29551,
29551,
18196,
18196,
24642,
29551,
18196,
18196,
67,
272,
5223,
26,
756,
272,
1166,
26,
1455,
921,
5967,
26,
15844,
272,
922,
26,
4628,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2595,
199,
354,
26,
523,
1369,
26,
2812,
402,
314,
29537,
3906,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
511,
13,
2423,
199,
929,
26,
523,
1369,
26,
8511,
402,
314,
29537,
3906,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
3451,
199,
3827,
26,
523,
1369,
26,
7480,
314,
29537,
3906,
365,
5223,
503,
440,
14,
523,
2138,
26,
3182,
523,
730,
26,
2155,
523,
2690,
26,
2549,
199,
751,
26,
523,
1369,
26,
2876,
1202,
367,
6299,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
4628,
199,
633,
26,
523,
1369,
26,
20503,
370,
4907,
370,
314,
32516,
1654,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
4178,
921,
25622,
14,
30945,
14,
957,
199,
2344,
199,
199,
646,
5190,
199,
199,
893,
26,
272,
492,
29537,
272,
2366,
63,
25622,
63,
7657,
275,
715,
199,
2590,
3545,
26,
272,
2366,
63,
25622,
63,
7657,
275,
756,
199,
199,
893,
26,
272,
687,
14490,
492,
7559,
465,
12265,
272,
2366,
63,
22899,
63,
7657,
275,
715,
199,
2590,
3545,
26,
272,
2366,
63,
22899,
63,
7657,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
421,
199,
533,
32516,
6694,
26,
339,
347,
636,
826,
721,
277,
12,
859,
304,
267,
291,
14,
578,
275,
859,
398,
291,
14,
888,
275,
859,
14,
1162,
14,
362,
360,
888,
358,
267,
291,
14,
354,
275,
859,
14,
1162,
14,
362,
360,
354,
358,
267,
291,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
armikhael/software-center
|
utils/piston-helpers/x2go_helper.py
|
2
|
2962
|
#!/usr/bin/python -u
import x2go, gevent, sys, fcntl, os, shlex
def connect(server, port, login, password, session):
print "PROGRESS: creating"
cli = x2go.X2goClient(start_pulseaudio=True)
uuid = cli.register_session(
server=server,
port=int(port),
username=login,
add_to_known_hosts=True,
cmd="WEBLIVE",
geometry="1024x600"
)
x2go.defaults.X2GO_DESKTOPSESSIONS['WEBLIVE']="/usr/local/bin/weblive-session %s" % session
print "PROGRESS: connecting"
try:
if cli.connect_session(uuid, password=password) not in (None, True):
# According to documentation, connect_session may return False
exception("unable to connect")
except:
# Any paramiko exception will get here
exception("unable to connect")
print "PROGRESS: starting"
try:
if cli.start_session(uuid) not in (None, True):
# According to documentation, start_session may return False
exception("unable to start")
except:
# Just in case
exception("unable to start")
print "CONNECTED"
return (cli,uuid)
def exception(string):
print "EXCEPTION: %s" % string
sys.exit(1)
def warning(string):
print "WARNING: %s" % string
def disconnect(connection, uuid):
try:
if connection.terminate_session(uuid) not in (None, True):
# According to documentation, connect_session may return False
exception("unable to disconnect")
except:
# Any paramiko exception will get here
exception("unable to disconnect")
print "DISCONNECTED"
sys.exit(0)
if __name__ == "__main__":
# make stdin nonblocking
fd = sys.stdin.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
# main loop
connection = None
uuid = None
while True:
# Get anything that appeared on stdin
try:
buf = sys.stdin.readline().strip()
except IOError:
buf = None
if buf:
params = shlex.split(buf)
# Parse command from stdin
if params[0] == "CONNECT:":
if not len(params) == 6:
exception("invalid connect string")
if not uuid and not connection:
connection, uuid = connect(*params[1:])
else:
warning("already connected")
elif params[0] == "DISCONNECT":
if connection and uuid:
disconnect(connection, uuid)
else:
exception("no existing connection")
else:
warning("invalid command: '%s'" % params)
# Check if the session ended
if connection and uuid and not connection.session_ok(uuid):
disconnect(connection, uuid)
if not buf:
gevent.sleep(0.5)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
446,
85,
199,
646,
671,
18,
1939,
12,
23386,
12,
984,
12,
12871,
12,
747,
12,
16701,
199,
199,
318,
4907,
8,
1000,
12,
1844,
12,
4676,
12,
2505,
12,
2351,
304,
272,
870,
298,
24547,
26,
6425,
2,
272,
5053,
275,
671,
18,
1939,
14,
56,
18,
1939,
3041,
8,
928,
63,
19538,
8130,
29,
549,
9,
272,
5377,
275,
5053,
14,
2683,
63,
1730,
8,
267,
1654,
29,
1000,
12,
267,
1844,
29,
442,
8,
719,
395,
267,
3434,
29,
2886,
12,
267,
1050,
63,
475,
63,
3159,
63,
5146,
29,
549,
12,
267,
2088,
628,
13166,
31541,
401,
267,
3400,
628,
7727,
88,
6683,
2,
272,
776,
272,
671,
18,
1939,
14,
4322,
14,
56,
18,
13160,
63,
4448,
43,
11422,
51,
1608,
2823,
459,
13166,
31541,
418,
9555,
2647,
15,
1832,
15,
1393,
15,
2520,
6442,
13,
1730,
450,
83,
2,
450,
2351,
339,
870,
298,
24547,
26,
18170,
2,
272,
862,
26,
267,
340,
5053,
14,
2242,
63,
1730,
8,
2580,
12,
2505,
29,
2060,
9,
440,
315,
334,
403,
12,
715,
304,
288,
327,
31970,
370,
3794,
12,
4907,
63,
1730,
1443,
372,
756,
288,
1919,
480,
17200,
370,
4907,
531,
272,
871,
26,
267,
327,
6184,
26162,
1919,
911,
664,
2348,
267,
1919,
480,
17200,
370,
4907,
531,
339,
870,
298,
24547,
26,
6617,
2,
272,
862,
26,
267,
340,
5053,
14,
928,
63,
1730,
8,
2580,
9,
440,
315,
334,
403,
12,
715,
304,
288,
327,
31970,
370,
3794,
12,
1343,
63,
1730,
1443,
372,
756,
288,
1919,
480,
17200,
370,
1343,
531,
272,
871,
26,
267,
327,
13870,
315,
1930,
267,
1919,
480,
17200,
370,
1343,
531,
339,
870,
298,
14657,
1149,
2,
272,
372,
334,
2764,
12,
2580,
9,
199,
199,
318,
1919,
8,
875,
304,
272,
870,
298,
15375,
26,
450,
83,
2,
450,
1059,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
5721,
8,
875,
304,
272,
870,
298,
9171,
26,
450,
83,
2,
450,
1059,
199,
199,
318,
17639,
8,
2105,
12,
5377,
304,
272,
862,
26,
267,
340,
1950,
14,
14478,
63,
1730,
8,
2580,
9,
440,
315,
334,
403,
12,
715,
304,
288,
327,
31970,
370,
3794,
12,
4907,
63,
1730,
1443,
372,
756,
288,
1919,
480,
17200,
370,
17639,
531,
272,
871,
26,
267,
327,
6184,
26162,
1919,
911,
664,
2348,
267,
1919,
480,
17200,
370,
17639,
531,
339,
870,
298,
6178,
14657,
1149,
2,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
339,
327,
1852,
9009,
2222,
13091,
272,
6111,
275,
984,
14,
6626,
14,
9843,
342,
272,
2717,
275,
12871,
14,
24477,
8,
2592,
12,
12871,
14,
38,
63,
2970,
3143,
9,
272,
12871,
14,
24477,
8,
2592,
12,
12871,
14,
38,
63,
3597,
3143,
12,
2717,
1204,
747,
14,
47,
63,
13887,
8475,
9,
339,
327,
2446,
4438,
272,
1950,
275,
488,
272,
5377,
275,
488,
339,
1830,
715,
26,
267,
327,
2372,
7003,
626,
5704,
2899,
641,
9009,
267,
862,
26,
288,
4123,
275,
984,
14,
6626,
14,
6407,
1252,
1913,
342,
267,
871,
5925,
26,
288,
4123,
275,
488,
398,
340,
4123,
26,
288,
1862,
275,
16701,
14,
1294,
8,
1436,
9,
953,
327,
6077,
1414,
687,
9009,
288,
340,
1862,
59,
16,
61,
508,
298,
14657,
25165,
355,
340,
440,
822,
8,
1162,
9,
508,
1227,
26,
490,
1919,
480,
3197,
4907,
1059,
531,
2234,
340,
440,
5377,
436,
440,
1950,
26,
490,
1950,
12,
5377,
275,
4907,
2031,
1162,
59,
17,
5728,
355,
587,
26,
490,
5721,
480,
14039,
8539,
531,
953,
916,
1862,
59,
16,
61,
508,
298,
6178,
14657,
582,
355,
340,
1950,
436,
5377,
26,
490,
17639,
8,
2105,
12,
5377,
9,
355,
587,
26,
490,
1919,
480,
889,
3411,
1950,
531,
953,
587,
26,
355,
5721,
480,
3197,
1414,
26,
1543,
83,
4065,
450,
1862,
9,
398,
327,
2670,
340,
314,
2351,
22480,
267,
340,
1950,
436,
5377,
436,
440,
1950,
14,
1730,
63,
745,
8,
2580,
304,
288,
17639,
8,
2105,
12,
5377,
9,
398,
340,
440,
4123,
26,
288,
23386,
14,
4532,
8,
16,
14,
21,
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
] |
[
2647,
15,
1393,
15,
1548,
446,
85,
199,
646,
671,
18,
1939,
12,
23386,
12,
984,
12,
12871,
12,
747,
12,
16701,
199,
199,
318,
4907,
8,
1000,
12,
1844,
12,
4676,
12,
2505,
12,
2351,
304,
272,
870,
298,
24547,
26,
6425,
2,
272,
5053,
275,
671,
18,
1939,
14,
56,
18,
1939,
3041,
8,
928,
63,
19538,
8130,
29,
549,
9,
272,
5377,
275,
5053,
14,
2683,
63,
1730,
8,
267,
1654,
29,
1000,
12,
267,
1844,
29,
442,
8,
719,
395,
267,
3434,
29,
2886,
12,
267,
1050,
63,
475,
63,
3159,
63,
5146,
29,
549,
12,
267,
2088,
628,
13166,
31541,
401,
267,
3400,
628,
7727,
88,
6683,
2,
272,
776,
272,
671,
18,
1939,
14,
4322,
14,
56,
18,
13160,
63,
4448,
43,
11422,
51,
1608,
2823,
459,
13166,
31541,
418,
9555,
2647,
15,
1832,
15,
1393,
15,
2520,
6442,
13,
1730,
450,
83,
2,
450,
2351,
339,
870,
298,
24547,
26,
18170,
2,
272,
862,
26,
267,
340,
5053,
14,
2242,
63,
1730,
8,
2580,
12,
2505,
29,
2060,
9,
440,
315,
334,
403,
12,
715,
304,
288,
327,
31970,
370,
3794,
12,
4907,
63,
1730,
1443,
372,
756,
288,
1919,
480,
17200,
370,
4907,
531,
272,
871,
26,
267,
327,
6184,
26162,
1919,
911,
664,
2348,
267,
1919,
480,
17200,
370,
4907,
531,
339,
870,
298,
24547,
26,
6617,
2,
272,
862,
26,
267,
340,
5053,
14,
928,
63,
1730,
8,
2580,
9,
440,
315,
334,
403,
12,
715,
304,
288,
327,
31970,
370,
3794,
12,
1343,
63,
1730,
1443,
372,
756,
288,
1919,
480,
17200,
370,
1343,
531,
272,
871,
26,
267,
327,
13870,
315,
1930,
267,
1919,
480,
17200,
370,
1343,
531,
339,
870,
298,
14657,
1149,
2,
272,
372,
334,
2764,
12,
2580,
9,
199,
199,
318,
1919,
8,
875,
304,
272,
870,
298,
15375,
26,
450,
83,
2,
450,
1059,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
5721,
8,
875,
304,
272,
870,
298,
9171,
26,
450,
83,
2,
450,
1059,
199,
199,
318,
17639,
8,
2105,
12,
5377,
304,
272,
862,
26,
267,
340,
1950,
14,
14478,
63,
1730,
8,
2580,
9,
440,
315,
334,
403,
12,
715,
304,
288,
327,
31970,
370,
3794,
12,
4907,
63,
1730,
1443,
372,
756,
288,
1919,
480,
17200,
370,
17639,
531,
272,
871,
26,
267,
327,
6184,
26162,
1919,
911,
664,
2348,
267,
1919,
480,
17200,
370,
17639,
531,
339,
870,
298,
6178,
14657,
1149,
2,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
339,
327,
1852,
9009,
2222,
13091,
272,
6111,
275,
984,
14,
6626,
14,
9843,
342,
272,
2717,
275,
12871,
14,
24477,
8,
2592,
12,
12871,
14,
38,
63,
2970,
3143,
9,
272,
12871,
14,
24477,
8,
2592,
12,
12871,
14,
38,
63,
3597,
3143,
12,
2717,
1204,
747,
14,
47,
63,
13887,
8475,
9,
339,
327,
2446,
4438,
272,
1950,
275,
488,
272,
5377,
275,
488,
339,
1830,
715,
26,
267,
327,
2372,
7003,
626,
5704,
2899,
641,
9009,
267,
862,
26,
288,
4123,
275,
984,
14,
6626,
14,
6407,
1252,
1913,
342,
267,
871,
5925,
26,
288,
4123,
275,
488,
398,
340,
4123,
26,
288,
1862,
275,
16701,
14,
1294,
8,
1436,
9,
953,
327,
6077,
1414,
687,
9009,
288,
340,
1862,
59,
16,
61,
508,
298,
14657,
25165,
355,
340,
440,
822,
8,
1162,
9,
508,
1227,
26,
490,
1919,
480,
3197,
4907,
1059,
531,
2234,
340,
440,
5377,
436,
440,
1950,
26,
490,
1950,
12,
5377,
275,
4907,
2031,
1162,
59,
17,
5728,
355,
587,
26,
490,
5721,
480,
14039,
8539,
531,
953,
916,
1862,
59,
16,
61,
508,
298,
6178,
14657,
582,
355,
340,
1950,
436,
5377,
26,
490,
17639,
8,
2105,
12,
5377,
9,
355,
587,
26,
490,
1919,
480,
889,
3411,
1950,
531,
953,
587,
26,
355,
5721,
480,
3197,
1414,
26,
1543,
83,
4065,
450,
1862,
9,
398,
327,
2670,
340,
314,
2351,
22480,
267,
340,
1950,
436,
5377,
436,
440,
1950,
14,
1730,
63,
745,
8,
2580,
304,
288,
17639,
8,
2105,
12,
5377,
9,
398,
340,
440,
4123,
26,
288,
23386,
14,
4532,
8,
16,
14,
21,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
babble/babble
|
include/jython/Lib/test/test_tempfile.py
|
1
|
21877
|
# From Python 2.5.1
# tempfile.py unit tests.
import tempfile
import os
import sys
import re
import errno
import warnings
import unittest
from test import test_support
warnings.filterwarnings("ignore",
category=RuntimeWarning,
message="mktemp", module=__name__)
if hasattr(os, 'stat'):
import stat
has_stat = 1
else:
has_stat = 0
has_textmode = (tempfile._text_openflags != tempfile._bin_openflags)
has_spawnl = hasattr(os, 'spawnl')
# TEST_FILES may need to be tweaked for systems depending on the maximum
# number of files that can be opened at one time (see ulimit -n)
if sys.platform == 'mac':
TEST_FILES = 32
elif sys.platform in ('openbsd3', 'openbsd4'):
TEST_FILES = 48
else:
TEST_FILES = 100
# This is organized as one test for each chunk of code in tempfile.py,
# in order of their appearance in the file. Testing which requires
# threads is not done here.
# Common functionality.
class TC(unittest.TestCase):
str_check = re.compile(r"[a-zA-Z0-9_-]{6}$")
def failOnException(self, what, ei=None):
if ei is None:
ei = sys.exc_info()
self.fail("%s raised %s: %s" % (what, ei[0], ei[1]))
def nameCheck(self, name, dir, pre, suf):
(ndir, nbase) = os.path.split(name)
npre = nbase[:len(pre)]
nsuf = nbase[len(nbase)-len(suf):]
# check for equality of the absolute paths!
self.assertEqual(os.path.abspath(ndir), os.path.abspath(dir),
"file '%s' not in directory '%s'" % (name, dir))
self.assertEqual(npre, pre,
"file '%s' does not begin with '%s'" % (nbase, pre))
self.assertEqual(nsuf, suf,
"file '%s' does not end with '%s'" % (nbase, suf))
nbase = nbase[len(pre):len(nbase)-len(suf)]
self.assert_(self.str_check.match(nbase),
"random string '%s' does not match /^[a-zA-Z0-9_-]{6}$/"
% nbase)
test_classes = []
class test_exports(TC):
def test_exports(self):
# There are no surprising symbols in the tempfile module
dict = tempfile.__dict__
expected = {
"NamedTemporaryFile" : 1,
"TemporaryFile" : 1,
"mkstemp" : 1,
"mkdtemp" : 1,
"mktemp" : 1,
"TMP_MAX" : 1,
"gettempprefix" : 1,
"gettempdir" : 1,
"tempdir" : 1,
"template" : 1
}
unexp = []
for key in dict:
if key[0] != '_' and key not in expected:
unexp.append(key)
self.failUnless(len(unexp) == 0,
"unexpected keys: %s" % unexp)
test_classes.append(test_exports)
class test__RandomNameSequence(TC):
"""Test the internal iterator object _RandomNameSequence."""
def setUp(self):
self.r = tempfile._RandomNameSequence()
def test_get_six_char_str(self):
# _RandomNameSequence returns a six-character string
s = self.r.next()
self.nameCheck(s, '', '', '')
def test_many(self):
# _RandomNameSequence returns no duplicate strings (stochastic)
dict = {}
r = self.r
for i in xrange(TEST_FILES):
s = r.next()
self.nameCheck(s, '', '', '')
self.failIf(s in dict)
dict[s] = 1
def test_supports_iter(self):
# _RandomNameSequence supports the iterator protocol
i = 0
r = self.r
try:
for s in r:
i += 1
if i == 20:
break
except:
failOnException("iteration")
test_classes.append(test__RandomNameSequence)
class test__candidate_tempdir_list(TC):
"""Test the internal function _candidate_tempdir_list."""
def test_nonempty_list(self):
# _candidate_tempdir_list returns a nonempty list of strings
cand = tempfile._candidate_tempdir_list()
self.failIf(len(cand) == 0)
for c in cand:
self.assert_(isinstance(c, basestring),
"%s is not a string" % c)
def test_wanted_dirs(self):
# _candidate_tempdir_list contains the expected directories
# Make sure the interesting environment variables are all set.
added = []
try:
for envname in 'TMPDIR', 'TEMP', 'TMP':
dirname = os.getenv(envname)
if not dirname:
os.environ[envname] = os.path.abspath(envname)
added.append(envname)
cand = tempfile._candidate_tempdir_list()
for envname in 'TMPDIR', 'TEMP', 'TMP':
dirname = os.getenv(envname)
if not dirname: raise ValueError
self.assert_(dirname in cand)
try:
dirname = os.getcwd()
except (AttributeError, os.error):
dirname = os.curdir
self.assert_(dirname in cand)
# Not practical to try to verify the presence of OS-specific
# paths in this list.
finally:
for p in added:
del os.environ[p]
test_classes.append(test__candidate_tempdir_list)
# We test _get_default_tempdir by testing gettempdir.
class test__get_candidate_names(TC):
"""Test the internal function _get_candidate_names."""
def test_retval(self):
# _get_candidate_names returns a _RandomNameSequence object
obj = tempfile._get_candidate_names()
self.assert_(isinstance(obj, tempfile._RandomNameSequence))
def test_same_thing(self):
# _get_candidate_names always returns the same object
a = tempfile._get_candidate_names()
b = tempfile._get_candidate_names()
self.assert_(a is b)
test_classes.append(test__get_candidate_names)
class test__mkstemp_inner(TC):
"""Test the internal function _mkstemp_inner."""
class mkstemped:
_bflags = tempfile._bin_openflags
_tflags = tempfile._text_openflags
def __init__(self, dir, pre, suf, bin):
if bin: flags = self._bflags
else: flags = self._tflags
# XXX: CPython assigns _close/_unlink as class vars but this
# would rebind Jython's close/unlink (to be classmethods)
# because they're not built-in functions (unfortunately
# built-in functions act differently when binding:
# http://mail.python.org/pipermail/python-dev/2003-April/034749.html)
self._close = os.close
self._unlink = os.unlink
(self.fd, self.name) = tempfile._mkstemp_inner(dir, pre, suf, flags)
def write(self, str):
os.write(self.fd, str)
# XXX: self.test_choose_directory expects the file to have been deleted
# (via __del__) by the time it's called, which is CPython specific
# garbage collection behavior. We need to delete it now in Jython
self._close(self.fd)
self._unlink(self.name)
def __del__(self):
self._close(self.fd)
if os.path.exists(self.name):
self._unlink(self.name)
def do_create(self, dir=None, pre="", suf="", bin=1):
if dir is None:
dir = tempfile.gettempdir()
try:
file = self.mkstemped(dir, pre, suf, bin)
except:
self.failOnException("_mkstemp_inner")
self.nameCheck(file.name, dir, pre, suf)
return file
def test_basic(self):
# _mkstemp_inner can create files
self.do_create().write("blat")
self.do_create(pre="a").write("blat")
self.do_create(suf="b").write("blat")
self.do_create(pre="a", suf="b").write("blat")
self.do_create(pre="aa", suf=".txt").write("blat")
def test_basic_many(self):
# _mkstemp_inner can create many files (stochastic)
extant = range(TEST_FILES)
for i in extant:
extant[i] = self.do_create(pre="aa")
# XXX: Ensure mkstemped files are deleted (can't rely on Java's
# GC)
for i in extant:
i.__del__()
def test_choose_directory(self):
# _mkstemp_inner can create files in a user-selected directory
dir = tempfile.mkdtemp()
try:
self.do_create(dir=dir).write("blat")
finally:
os.rmdir(dir)
# XXX: Jython can't set the write mode yet
def _test_file_mode(self):
# _mkstemp_inner creates files with the proper mode
if not has_stat:
return # ugh, can't use TestSkipped.
file = self.do_create()
mode = stat.S_IMODE(os.stat(file.name).st_mode)
expected = 0600
if sys.platform in ('win32', 'os2emx', 'mac'):
# There's no distinction among 'user', 'group' and 'world';
# replicate the 'user' bits.
user = expected >> 6
expected = user * (1 + 8 + 64)
self.assertEqual(mode, expected)
def test_noinherit(self):
# _mkstemp_inner file handles are not inherited by child processes
if not has_spawnl:
return # ugh, can't use TestSkipped.
if test_support.verbose:
v="v"
else:
v="q"
file = self.do_create()
fd = "%d" % file.fd
try:
me = __file__
except NameError:
me = sys.argv[0]
# We have to exec something, so that FD_CLOEXEC will take
# effect. The core of this test is therefore in
# tf_inherit_check.py, which see.
tester = os.path.join(os.path.dirname(os.path.abspath(me)),
"tf_inherit_check.py")
# On Windows a spawn* /path/ with embedded spaces shouldn't be quoted,
# but an arg with embedded spaces should be decorated with double
# quotes on each end
if sys.platform in ('win32'):
decorated = '"%s"' % sys.executable
tester = '"%s"' % tester
else:
decorated = sys.executable
retval = os.spawnl(os.P_WAIT, sys.executable, decorated, tester, v, fd)
self.failIf(retval < 0,
"child process caught fatal signal %d" % -retval)
self.failIf(retval > 0, "child process reports failure %d"%retval)
def test_textmode(self):
# _mkstemp_inner can create files in text mode
if not has_textmode:
return # ugh, can't use TestSkipped.
self.do_create(bin=0).write("blat\n")
# XXX should test that the file really is a text file
test_classes.append(test__mkstemp_inner)
class test_gettempprefix(TC):
"""Test gettempprefix()."""
def test_sane_template(self):
# gettempprefix returns a nonempty prefix string
p = tempfile.gettempprefix()
self.assert_(isinstance(p, basestring))
self.assert_(len(p) > 0)
def test_usable_template(self):
# gettempprefix returns a usable prefix string
# Create a temp directory, avoiding use of the prefix.
# Then attempt to create a file whose name is
# prefix + 'xxxxxx.xxx' in that directory.
p = tempfile.gettempprefix() + "xxxxxx.xxx"
d = tempfile.mkdtemp(prefix="")
try:
p = os.path.join(d, p)
try:
fd = os.open(p, os.O_RDWR | os.O_CREAT)
except:
self.failOnException("os.open")
os.close(fd)
os.unlink(p)
finally:
os.rmdir(d)
test_classes.append(test_gettempprefix)
class test_gettempdir(TC):
"""Test gettempdir()."""
def test_directory_exists(self):
# gettempdir returns a directory which exists
dir = tempfile.gettempdir()
self.assert_(os.path.isabs(dir) or dir == os.curdir,
"%s is not an absolute path" % dir)
self.assert_(os.path.isdir(dir),
"%s is not a directory" % dir)
def test_directory_writable(self):
# gettempdir returns a directory writable by the user
# sneaky: just instantiate a NamedTemporaryFile, which
# defaults to writing into the directory returned by
# gettempdir.
try:
file = tempfile.NamedTemporaryFile()
file.write("blat")
file.close()
except:
self.failOnException("create file in %s" % tempfile.gettempdir())
def test_same_thing(self):
# gettempdir always returns the same object
a = tempfile.gettempdir()
b = tempfile.gettempdir()
self.assert_(a is b)
test_classes.append(test_gettempdir)
class test_mkstemp(TC):
"""Test mkstemp()."""
def do_create(self, dir=None, pre="", suf=""):
if dir is None:
dir = tempfile.gettempdir()
try:
(fd, name) = tempfile.mkstemp(dir=dir, prefix=pre, suffix=suf)
(ndir, nbase) = os.path.split(name)
adir = os.path.abspath(dir)
self.assertEqual(adir, ndir,
"Directory '%s' incorrectly returned as '%s'" % (adir, ndir))
except:
self.failOnException("mkstemp")
try:
self.nameCheck(name, dir, pre, suf)
finally:
os.close(fd)
os.unlink(name)
def test_basic(self):
# mkstemp can create files
self.do_create()
self.do_create(pre="a")
self.do_create(suf="b")
self.do_create(pre="a", suf="b")
self.do_create(pre="aa", suf=".txt")
self.do_create(dir=".")
def test_choose_directory(self):
# mkstemp can create directories in a user-selected directory
dir = tempfile.mkdtemp()
try:
self.do_create(dir=dir)
finally:
os.rmdir(dir)
test_classes.append(test_mkstemp)
class test_mkdtemp(TC):
"""Test mkdtemp()."""
def do_create(self, dir=None, pre="", suf=""):
if dir is None:
dir = tempfile.gettempdir()
try:
name = tempfile.mkdtemp(dir=dir, prefix=pre, suffix=suf)
except:
self.failOnException("mkdtemp")
try:
self.nameCheck(name, dir, pre, suf)
return name
except:
os.rmdir(name)
raise
def test_basic(self):
# mkdtemp can create directories
os.rmdir(self.do_create())
os.rmdir(self.do_create(pre="a"))
os.rmdir(self.do_create(suf="b"))
os.rmdir(self.do_create(pre="a", suf="b"))
os.rmdir(self.do_create(pre="aa", suf=".txt"))
def test_basic_many(self):
# mkdtemp can create many directories (stochastic)
extant = range(TEST_FILES)
try:
for i in extant:
extant[i] = self.do_create(pre="aa")
finally:
for i in extant:
if(isinstance(i, basestring)):
os.rmdir(i)
def test_choose_directory(self):
# mkdtemp can create directories in a user-selected directory
dir = tempfile.mkdtemp()
try:
os.rmdir(self.do_create(dir=dir))
finally:
os.rmdir(dir)
def test_mode(self):
# mkdtemp creates directories with the proper mode
if not has_stat:
return # ugh, can't use TestSkipped.
if os.name == 'java':
# Java doesn't support stating files for permissions
return
dir = self.do_create()
try:
mode = stat.S_IMODE(os.stat(dir).st_mode)
mode &= 0777 # Mask off sticky bits inherited from /tmp
expected = 0700
if sys.platform in ('win32', 'os2emx', 'mac'):
# There's no distinction among 'user', 'group' and 'world';
# replicate the 'user' bits.
user = expected >> 6
expected = user * (1 + 8 + 64)
self.assertEqual(mode, expected)
finally:
os.rmdir(dir)
test_classes.append(test_mkdtemp)
class test_mktemp(TC):
"""Test mktemp()."""
# For safety, all use of mktemp must occur in a private directory.
# We must also suppress the RuntimeWarning it generates.
def setUp(self):
self.dir = tempfile.mkdtemp()
def tearDown(self):
if self.dir:
os.rmdir(self.dir)
self.dir = None
class mktemped:
_bflags = tempfile._bin_openflags
def __init__(self, dir, pre, suf):
# XXX: Assign _unlink here, instead of as a class var. See
# mkstemped.__init__ for an explanation
self._unlink = os.unlink
self.name = tempfile.mktemp(dir=dir, prefix=pre, suffix=suf)
# Create the file. This will raise an exception if it's
# mysteriously appeared in the meanwhile.
os.close(os.open(self.name, self._bflags, 0600))
# XXX: test_mktemp.tearDown expects the file to have been deleted
# (via __del__) by the time it's called, which is CPython specific
# garbage collection behavior. We need to delete it now in Jython
self._unlink(self.name)
#def __del__(self):
# self._unlink(self.name)
def do_create(self, pre="", suf=""):
try:
file = self.mktemped(self.dir, pre, suf)
except:
self.failOnException("mktemp")
self.nameCheck(file.name, self.dir, pre, suf)
return file
def test_basic(self):
# mktemp can choose usable file names
self.do_create()
self.do_create(pre="a")
self.do_create(suf="b")
self.do_create(pre="a", suf="b")
self.do_create(pre="aa", suf=".txt")
def test_many(self):
# mktemp can choose many usable file names (stochastic)
extant = range(TEST_FILES)
for i in extant:
extant[i] = self.do_create(pre="aa")
## def test_warning(self):
## # mktemp issues a warning when used
## warnings.filterwarnings("error",
## category=RuntimeWarning,
## message="mktemp")
## self.assertRaises(RuntimeWarning,
## tempfile.mktemp, dir=self.dir)
test_classes.append(test_mktemp)
# We test _TemporaryFileWrapper by testing NamedTemporaryFile.
class test_NamedTemporaryFile(TC):
"""Test NamedTemporaryFile()."""
def do_create(self, dir=None, pre="", suf=""):
if dir is None:
dir = tempfile.gettempdir()
try:
file = tempfile.NamedTemporaryFile(dir=dir, prefix=pre, suffix=suf)
except:
self.failOnException("NamedTemporaryFile")
self.nameCheck(file.name, dir, pre, suf)
return file
def test_basic(self):
# NamedTemporaryFile can create files
self.do_create()
self.do_create(pre="a")
self.do_create(suf="b")
self.do_create(pre="a", suf="b")
self.do_create(pre="aa", suf=".txt")
def test_creates_named(self):
# NamedTemporaryFile creates files with names
f = tempfile.NamedTemporaryFile()
self.failUnless(os.path.exists(f.name),
"NamedTemporaryFile %s does not exist" % f.name)
def test_del_on_close(self):
# A NamedTemporaryFile is deleted when closed
dir = tempfile.mkdtemp()
try:
f = tempfile.NamedTemporaryFile(dir=dir)
f.write('blat')
f.close()
self.failIf(os.path.exists(f.name),
"NamedTemporaryFile %s exists after close" % f.name)
finally:
os.rmdir(dir)
def test_multiple_close(self):
# A NamedTemporaryFile can be closed many times without error
f = tempfile.NamedTemporaryFile()
f.write('abc\n')
f.close()
try:
f.close()
f.close()
except:
self.failOnException("close")
# How to test the mode and bufsize parameters?
test_classes.append(test_NamedTemporaryFile)
class test_TemporaryFile(TC):
"""Test TemporaryFile()."""
def test_basic(self):
# TemporaryFile can create files
# No point in testing the name params - the file has no name.
try:
tempfile.TemporaryFile()
except:
self.failOnException("TemporaryFile")
def test_has_no_name(self):
# TemporaryFile creates files with no names (on this system)
dir = tempfile.mkdtemp()
f = tempfile.TemporaryFile(dir=dir)
f.write('blat')
# Sneaky: because this file has no name, it should not prevent
# us from removing the directory it was created in.
try:
os.rmdir(dir)
except:
ei = sys.exc_info()
# cleanup
f.close()
os.rmdir(dir)
self.failOnException("rmdir", ei)
def test_multiple_close(self):
# A TemporaryFile can be closed many times without error
f = tempfile.TemporaryFile()
f.write('abc\n')
f.close()
try:
f.close()
f.close()
except:
self.failOnException("close")
# How to test the mode and bufsize parameters?
if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile:
test_classes.append(test_TemporaryFile)
def test_main():
test_support.run_unittest(*test_classes)
if __name__ == "__main__":
test_main()
# XXX: Nudge Java's GC in an attempt to trigger any temp file's
# __del__ (cause them to be deleted) that hasn't been called
from java.lang import System
System.gc()
|
apache-2.0
|
[
3,
11606,
2018,
499,
14,
21,
14,
17,
199,
3,
5549,
14,
647,
4137,
2295,
14,
199,
199,
646,
5549,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
646,
7554,
199,
646,
3598,
199,
199,
646,
2882,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
5451,
14,
23945,
480,
4247,
401,
717,
4637,
29,
14357,
3849,
12,
717,
1245,
628,
22136,
401,
859,
18971,
354,
3368,
199,
199,
692,
2688,
8,
736,
12,
283,
3736,
735,
272,
492,
5672,
272,
965,
63,
3736,
275,
413,
199,
2836,
26,
272,
965,
63,
3736,
275,
378,
199,
199,
1989,
63,
505,
632,
275,
334,
17336,
423,
505,
63,
1490,
2469,
1137,
5549,
423,
1393,
63,
1490,
2469,
9,
199,
1989,
63,
10212,
76,
275,
2688,
8,
736,
12,
283,
10212,
76,
358,
199,
199,
3,
7393,
63,
9472,
1443,
1929,
370,
506,
32464,
379,
367,
10460,
10298,
641,
314,
5696,
199,
3,
1329,
402,
1584,
626,
883,
506,
12123,
737,
1373,
900,
334,
3239,
399,
3097,
446,
78,
9,
199,
692,
984,
14,
3246,
508,
283,
3088,
356,
272,
7393,
63,
9472,
275,
4337,
199,
4164,
984,
14,
3246,
315,
661,
1490,
15746,
19,
297,
283,
1490,
15746,
20,
735,
272,
7393,
63,
9472,
275,
9615,
199,
2836,
26,
272,
7393,
63,
9472,
275,
2948,
199,
199,
3,
961,
365,
20765,
1759,
465,
1373,
511,
367,
1924,
3728,
402,
1233,
315,
5549,
14,
647,
12,
199,
3,
315,
1865,
402,
3932,
7468,
554,
315,
314,
570,
14,
221,
11940,
1314,
5074,
199,
3,
7183,
365,
440,
4224,
2348,
14,
199,
199,
3,
13964,
9330,
14,
199,
533,
377,
35,
8,
2796,
14,
1746,
304,
339,
620,
63,
1074,
275,
295,
14,
2014,
8,
82,
22774,
65,
13,
6353,
13,
58,
16,
13,
25,
32069,
8194,
22,
93,
22550,
339,
347,
2449,
3314,
1726,
8,
277,
12,
4052,
12,
20654,
29,
403,
304,
267,
340,
20654,
365,
488,
26,
288,
20654,
275,
984,
14,
2804,
63,
815,
342,
267,
291,
14,
1633,
3647,
83,
4915,
450,
83,
26,
450,
83,
2,
450,
334,
10058,
12,
20654,
59,
16,
467,
20654,
59,
17,
2459,
339,
347,
536,
1799,
8,
277,
12,
536,
12,
2935,
12,
876,
12,
308,
1286,
304,
267,
334,
78,
694,
12,
302,
1095,
9,
275,
747,
14,
515,
14,
1294,
8,
354,
9,
267,
302,
657,
221,
275,
302,
1095,
1491,
552,
8,
657,
1874,
267,
700,
1286,
221,
275,
302,
1095,
59,
552,
8,
78,
1095,
7216,
552,
8,
83,
1286,
15405,
398,
327,
1104,
367,
16612,
402,
314,
3679,
3792,
1,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
8,
78,
694,
395,
747,
14,
515,
14,
4832,
8,
694,
395,
586,
298,
493,
1543,
83,
7,
440,
315,
2082,
1543,
83,
4065,
450,
334,
354,
12,
2935,
430,
267,
291,
14,
629,
8,
78,
657,
12,
876,
12,
586,
298,
493,
1543,
83,
7,
1630,
440,
5386,
543,
1543,
83,
4065,
450,
334,
78,
1095,
12,
876,
430,
267,
291,
14,
629,
8,
561,
1286,
12,
308,
1286,
12,
586,
298,
493,
1543,
83,
7,
1630,
440,
1284,
543,
1543,
83,
4065,
450,
334,
78,
1095,
12,
308,
1286,
430,
398,
302,
1095,
275,
302,
1095,
59,
552,
8,
657,
304,
552,
8,
78,
1095,
7216,
552,
8,
83,
1286,
1874,
267,
291,
14,
479,
2531,
277,
14,
495,
63,
1074,
14,
1431,
8,
78,
1095,
395,
2151,
298,
2355,
1059,
1543,
83,
7,
1630,
440,
1336,
1182,
62,
59,
65,
13,
6353,
13,
58,
16,
13,
25,
32069,
8194,
22,
93,
4,
6687,
2151,
450,
302,
1095,
9,
199,
199,
396,
63,
2888,
275,
942,
199,
199,
533,
511,
63,
20775,
8,
5708,
304,
272,
347,
511,
63,
20775,
8,
277,
304,
267,
327,
6006,
787,
949,
6296,
1359,
1044,
6698,
315,
314,
5549,
859,
267,
1211,
275,
5549,
855,
807,
363,
398,
1420,
275,
469,
288,
298,
19320,
2,
520,
413,
12,
288,
298,
13271,
2,
520,
413,
12,
288,
298,
17721,
2,
520,
413,
12,
288,
298,
11983,
2,
520,
413,
12,
288,
298,
22136,
2,
520,
413,
12,
288,
298,
17983,
63,
4283,
2,
520,
413,
12,
288,
298,
362,
808,
1861,
2,
520,
413,
12,
288,
298,
31572,
2,
520,
413,
12,
288,
298,
11567,
2,
520,
413,
12,
288,
298,
1160,
2,
520,
413,
267,
789,
398,
625,
1474,
275,
942,
267,
367,
790,
315,
1211,
26,
288,
340,
790,
59,
16,
61,
1137,
14135,
436,
790,
440,
315,
1420,
26,
355,
625,
1474,
14,
740,
8,
498,
9,
267,
291,
14,
7589,
8,
552,
8,
324,
1474,
9,
508,
378,
12,
717,
298,
8953,
2883,
26,
450,
83,
2,
450,
625,
1474,
9,
199,
199,
396,
63,
2888,
14,
740,
8,
396,
63,
20775,
9,
421,
199,
533,
511,
363,
3883,
985,
5826,
8,
5708,
304,
272,
408,
774,
314,
5007,
6122,
909,
485,
3883,
985,
5826,
1041,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
82,
275,
5549,
423,
3883,
985,
5826,
342,
339,
347,
511,
63,
362,
63,
4174,
63,
1560,
63,
495,
8,
277,
304,
267,
327,
485,
3883,
985,
5826,
2529,
282,
3816,
13,
10856,
1059,
267,
308,
275,
291,
14,
82,
14,
2184,
342,
267,
291,
14,
354,
1799,
8,
83,
12,
3260,
3260,
4074,
339,
347,
511,
63,
3479,
8,
277,
304,
267,
327,
485,
3883,
985,
5826,
2529,
949,
9250,
3326,
334,
14308,
21913,
9,
398,
1211,
275,
1052,
267,
519,
275,
291,
14,
82,
267,
367,
284,
315,
4945,
8,
2864,
63,
9472,
304,
288,
308,
275,
519,
14,
2184,
342,
288,
291,
14,
354,
1799,
8,
83,
12,
3260,
3260,
4074,
288,
291,
14,
19670,
8,
83,
315,
1211,
9,
288,
1211,
59,
83,
61,
275,
413,
339,
347,
511,
63,
9823,
63,
1661,
8,
277,
304,
267,
327,
485,
3883,
985,
5826,
5171,
314,
6122,
4113,
398,
284,
275,
378,
267,
519,
275,
291,
14,
82,
267,
862,
26,
288,
367,
308,
315,
519,
26,
355,
284,
847,
413,
355,
340,
284,
508,
3388,
26,
490,
2059,
267,
871,
26,
288,
2449,
3314,
1726,
480,
12575,
531,
199,
199,
396,
63,
2888,
14,
740,
8,
396,
363,
3883
] |
[
11606,
2018,
499,
14,
21,
14,
17,
199,
3,
5549,
14,
647,
4137,
2295,
14,
199,
199,
646,
5549,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
646,
7554,
199,
646,
3598,
199,
199,
646,
2882,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
5451,
14,
23945,
480,
4247,
401,
717,
4637,
29,
14357,
3849,
12,
717,
1245,
628,
22136,
401,
859,
18971,
354,
3368,
199,
199,
692,
2688,
8,
736,
12,
283,
3736,
735,
272,
492,
5672,
272,
965,
63,
3736,
275,
413,
199,
2836,
26,
272,
965,
63,
3736,
275,
378,
199,
199,
1989,
63,
505,
632,
275,
334,
17336,
423,
505,
63,
1490,
2469,
1137,
5549,
423,
1393,
63,
1490,
2469,
9,
199,
1989,
63,
10212,
76,
275,
2688,
8,
736,
12,
283,
10212,
76,
358,
199,
199,
3,
7393,
63,
9472,
1443,
1929,
370,
506,
32464,
379,
367,
10460,
10298,
641,
314,
5696,
199,
3,
1329,
402,
1584,
626,
883,
506,
12123,
737,
1373,
900,
334,
3239,
399,
3097,
446,
78,
9,
199,
692,
984,
14,
3246,
508,
283,
3088,
356,
272,
7393,
63,
9472,
275,
4337,
199,
4164,
984,
14,
3246,
315,
661,
1490,
15746,
19,
297,
283,
1490,
15746,
20,
735,
272,
7393,
63,
9472,
275,
9615,
199,
2836,
26,
272,
7393,
63,
9472,
275,
2948,
199,
199,
3,
961,
365,
20765,
1759,
465,
1373,
511,
367,
1924,
3728,
402,
1233,
315,
5549,
14,
647,
12,
199,
3,
315,
1865,
402,
3932,
7468,
554,
315,
314,
570,
14,
221,
11940,
1314,
5074,
199,
3,
7183,
365,
440,
4224,
2348,
14,
199,
199,
3,
13964,
9330,
14,
199,
533,
377,
35,
8,
2796,
14,
1746,
304,
339,
620,
63,
1074,
275,
295,
14,
2014,
8,
82,
22774,
65,
13,
6353,
13,
58,
16,
13,
25,
32069,
8194,
22,
93,
22550,
339,
347,
2449,
3314,
1726,
8,
277,
12,
4052,
12,
20654,
29,
403,
304,
267,
340,
20654,
365,
488,
26,
288,
20654,
275,
984,
14,
2804,
63,
815,
342,
267,
291,
14,
1633,
3647,
83,
4915,
450,
83,
26,
450,
83,
2,
450,
334,
10058,
12,
20654,
59,
16,
467,
20654,
59,
17,
2459,
339,
347,
536,
1799,
8,
277,
12,
536,
12,
2935,
12,
876,
12,
308,
1286,
304,
267,
334,
78,
694,
12,
302,
1095,
9,
275,
747,
14,
515,
14,
1294,
8,
354,
9,
267,
302,
657,
221,
275,
302,
1095,
1491,
552,
8,
657,
1874,
267,
700,
1286,
221,
275,
302,
1095,
59,
552,
8,
78,
1095,
7216,
552,
8,
83,
1286,
15405,
398,
327,
1104,
367,
16612,
402,
314,
3679,
3792,
1,
267,
291,
14,
629,
8,
736,
14,
515,
14,
4832,
8,
78,
694,
395,
747,
14,
515,
14,
4832,
8,
694,
395,
586,
298,
493,
1543,
83,
7,
440,
315,
2082,
1543,
83,
4065,
450,
334,
354,
12,
2935,
430,
267,
291,
14,
629,
8,
78,
657,
12,
876,
12,
586,
298,
493,
1543,
83,
7,
1630,
440,
5386,
543,
1543,
83,
4065,
450,
334,
78,
1095,
12,
876,
430,
267,
291,
14,
629,
8,
561,
1286,
12,
308,
1286,
12,
586,
298,
493,
1543,
83,
7,
1630,
440,
1284,
543,
1543,
83,
4065,
450,
334,
78,
1095,
12,
308,
1286,
430,
398,
302,
1095,
275,
302,
1095,
59,
552,
8,
657,
304,
552,
8,
78,
1095,
7216,
552,
8,
83,
1286,
1874,
267,
291,
14,
479,
2531,
277,
14,
495,
63,
1074,
14,
1431,
8,
78,
1095,
395,
2151,
298,
2355,
1059,
1543,
83,
7,
1630,
440,
1336,
1182,
62,
59,
65,
13,
6353,
13,
58,
16,
13,
25,
32069,
8194,
22,
93,
4,
6687,
2151,
450,
302,
1095,
9,
199,
199,
396,
63,
2888,
275,
942,
199,
199,
533,
511,
63,
20775,
8,
5708,
304,
272,
347,
511,
63,
20775,
8,
277,
304,
267,
327,
6006,
787,
949,
6296,
1359,
1044,
6698,
315,
314,
5549,
859,
267,
1211,
275,
5549,
855,
807,
363,
398,
1420,
275,
469,
288,
298,
19320,
2,
520,
413,
12,
288,
298,
13271,
2,
520,
413,
12,
288,
298,
17721,
2,
520,
413,
12,
288,
298,
11983,
2,
520,
413,
12,
288,
298,
22136,
2,
520,
413,
12,
288,
298,
17983,
63,
4283,
2,
520,
413,
12,
288,
298,
362,
808,
1861,
2,
520,
413,
12,
288,
298,
31572,
2,
520,
413,
12,
288,
298,
11567,
2,
520,
413,
12,
288,
298,
1160,
2,
520,
413,
267,
789,
398,
625,
1474,
275,
942,
267,
367,
790,
315,
1211,
26,
288,
340,
790,
59,
16,
61,
1137,
14135,
436,
790,
440,
315,
1420,
26,
355,
625,
1474,
14,
740,
8,
498,
9,
267,
291,
14,
7589,
8,
552,
8,
324,
1474,
9,
508,
378,
12,
717,
298,
8953,
2883,
26,
450,
83,
2,
450,
625,
1474,
9,
199,
199,
396,
63,
2888,
14,
740,
8,
396,
63,
20775,
9,
421,
199,
533,
511,
363,
3883,
985,
5826,
8,
5708,
304,
272,
408,
774,
314,
5007,
6122,
909,
485,
3883,
985,
5826,
1041,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
82,
275,
5549,
423,
3883,
985,
5826,
342,
339,
347,
511,
63,
362,
63,
4174,
63,
1560,
63,
495,
8,
277,
304,
267,
327,
485,
3883,
985,
5826,
2529,
282,
3816,
13,
10856,
1059,
267,
308,
275,
291,
14,
82,
14,
2184,
342,
267,
291,
14,
354,
1799,
8,
83,
12,
3260,
3260,
4074,
339,
347,
511,
63,
3479,
8,
277,
304,
267,
327,
485,
3883,
985,
5826,
2529,
949,
9250,
3326,
334,
14308,
21913,
9,
398,
1211,
275,
1052,
267,
519,
275,
291,
14,
82,
267,
367,
284,
315,
4945,
8,
2864,
63,
9472,
304,
288,
308,
275,
519,
14,
2184,
342,
288,
291,
14,
354,
1799,
8,
83,
12,
3260,
3260,
4074,
288,
291,
14,
19670,
8,
83,
315,
1211,
9,
288,
1211,
59,
83,
61,
275,
413,
339,
347,
511,
63,
9823,
63,
1661,
8,
277,
304,
267,
327,
485,
3883,
985,
5826,
5171,
314,
6122,
4113,
398,
284,
275,
378,
267,
519,
275,
291,
14,
82,
267,
862,
26,
288,
367,
308,
315,
519,
26,
355,
284,
847,
413,
355,
340,
284,
508,
3388,
26,
490,
2059,
267,
871,
26,
288,
2449,
3314,
1726,
480,
12575,
531,
199,
199,
396,
63,
2888,
14,
740,
8,
396,
363,
3883,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
log2timeline/dfvfs
|
tests/vfs/gzip_file_system.py
|
2
|
2511
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the file system implementation using gzip."""
import unittest
from dfvfs.lib import definitions
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import context
from dfvfs.vfs import gzip_file_system
from tests import test_lib as shared_test_lib
class GZIPFileSystemTest(shared_test_lib.BaseTestCase):
"""Tests for the gzip file system."""
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_path = self._GetTestFilePath(['syslog.gz'])
self._SkipIfPathNotExists(test_path)
test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._gzip_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_GZIP, parent=test_os_path_spec)
def tearDown(self):
"""Cleans up the needed objects used throughout the test."""
self._resolver_context.Empty()
def testOpenAndClose(self):
"""Test the open and close functionality."""
file_system = gzip_file_system.GzipFileSystem(
self._resolver_context, self._gzip_path_spec)
self.assertIsNotNone(file_system)
file_system.Open()
def testFileEntryExistsByPathSpec(self):
"""Test the file entry exists by path specification functionality."""
file_system = gzip_file_system.GzipFileSystem(
self._resolver_context, self._gzip_path_spec)
self.assertIsNotNone(file_system)
file_system.Open()
result = file_system.FileEntryExistsByPathSpec(self._gzip_path_spec)
self.assertTrue(result)
def testGetFileEntryByPathSpec(self):
"""Tests the GetFileEntryByPathSpec function."""
file_system = gzip_file_system.GzipFileSystem(
self._resolver_context, self._gzip_path_spec)
self.assertIsNotNone(file_system)
file_system.Open()
file_entry = file_system.GetFileEntryByPathSpec(self._gzip_path_spec)
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')
def testGetRootFileEntry(self):
"""Test the get root file entry functionality."""
file_system = gzip_file_system.GzipFileSystem(
self._resolver_context, self._gzip_path_spec)
self.assertIsNotNone(file_system)
file_system.Open()
file_entry = file_system.GetRootFileEntry()
self.assertIsNotNone(file_entry)
self.assertEqual(file_entry.name, '')
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2925,
367,
314,
570,
2656,
4514,
1808,
11756,
1041,
199,
199,
646,
2882,
199,
199,
504,
4051,
20970,
14,
773,
492,
10269,
199,
504,
4051,
20970,
14,
515,
492,
6434,
465,
931,
63,
1650,
63,
3702,
199,
504,
4051,
20970,
14,
7717,
492,
1067,
199,
504,
4051,
20970,
14,
20970,
492,
11756,
63,
493,
63,
2253,
199,
199,
504,
2295,
492,
511,
63,
773,
465,
5709,
63,
396,
63,
773,
421,
199,
533,
598,
16977,
17521,
774,
8,
5555,
63,
396,
63,
773,
14,
20760,
304,
523,
408,
2925,
367,
314,
11756,
570,
2656,
1041,
819,
347,
3613,
8,
277,
304,
272,
408,
9899,
1536,
314,
4346,
2251,
1202,
23088,
314,
511,
1041,
272,
291,
423,
7717,
63,
1100,
275,
1067,
14,
2998,
342,
272,
511,
63,
515,
275,
291,
423,
28967,
14225,
2941,
16878,
14,
6838,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
396,
63,
515,
9,
339,
511,
63,
736,
63,
515,
63,
1650,
275,
931,
63,
1650,
63,
3702,
14,
2927,
14,
4665,
2042,
5307,
8,
267,
10269,
14,
2711,
63,
23723,
6467,
63,
3100,
12,
2909,
29,
396,
63,
515,
9,
272,
291,
423,
12256,
63,
515,
63,
1650,
275,
931,
63,
1650,
63,
3702,
14,
2927,
14,
4665,
2042,
5307,
8,
267,
10269,
14,
2711,
63,
23723,
6467,
63,
39,
16977,
12,
1676,
29,
396,
63,
736,
63,
515,
63,
1650,
9,
819,
347,
6766,
8,
277,
304,
272,
408,
35,
274,
796,
1536,
314,
4346,
2251,
1202,
23088,
314,
511,
1041,
272,
291,
423,
7717,
63,
1100,
14,
4699,
342,
819,
347,
511,
4299,
3325,
4724,
8,
277,
304,
272,
408,
774,
314,
1551,
436,
4002,
9330,
1041,
272,
570,
63,
2253,
275,
11756,
63,
493,
63,
2253,
14,
21975,
17521,
8,
267,
291,
423,
7717,
63,
1100,
12,
291,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2253,
9,
339,
570,
63,
2253,
14,
4299,
342,
819,
347,
511,
1173,
3900,
7965,
2175,
2042,
5307,
8,
277,
304,
272,
408,
774,
314,
570,
2397,
3495,
701,
931,
8929,
9330,
1041,
272,
570,
63,
2253,
275,
11756,
63,
493,
63,
2253,
14,
21975,
17521,
8,
267,
291,
423,
7717,
63,
1100,
12,
291,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2253,
9,
339,
570,
63,
2253,
14,
4299,
342,
339,
754,
275,
570,
63,
2253,
14,
1173,
3900,
7965,
2175,
2042,
5307,
8,
277,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
1815,
8,
1099,
9,
819,
347,
19970,
1173,
3900,
2175,
2042,
5307,
8,
277,
304,
272,
408,
2925,
314,
2372,
1173,
3900,
2175,
2042,
5307,
805,
1041,
272,
570,
63,
2253,
275,
11756,
63,
493,
63,
2253,
14,
21975,
17521,
8,
267,
291,
423,
7717,
63,
1100,
12,
291,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2253,
9,
339,
570,
63,
2253,
14,
4299,
342,
339,
570,
63,
2373,
275,
570,
63,
2253,
14,
26535,
3900,
2175,
2042,
5307,
8,
277,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2373,
9,
272,
291,
14,
629,
8,
493,
63,
2373,
14,
354,
12,
4074,
819,
347,
19970,
6405,
1173,
3900,
8,
277,
304,
272,
408,
774,
314,
664,
1738,
570,
2397,
9330,
1041,
272,
570,
63,
2253,
275,
11756,
63,
493,
63,
2253,
14,
21975,
17521,
8,
267,
291,
423,
7717,
63,
1100,
12,
291,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2253,
9,
339,
570,
63,
2253,
14,
4299,
342,
339,
570,
63,
2373,
275,
570,
63,
2253,
14,
1002,
6405,
1173,
3900,
342,
272,
291,
14,
10389,
8,
493,
63,
2373,
9,
272,
291,
14,
629,
8,
493,
63,
2373,
14,
354,
12,
4074,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2925,
367,
314,
570,
2656,
4514,
1808,
11756,
1041,
199,
199,
646,
2882,
199,
199,
504,
4051,
20970,
14,
773,
492,
10269,
199,
504,
4051,
20970,
14,
515,
492,
6434,
465,
931,
63,
1650,
63,
3702,
199,
504,
4051,
20970,
14,
7717,
492,
1067,
199,
504,
4051,
20970,
14,
20970,
492,
11756,
63,
493,
63,
2253,
199,
199,
504,
2295,
492,
511,
63,
773,
465,
5709,
63,
396,
63,
773,
421,
199,
533,
598,
16977,
17521,
774,
8,
5555,
63,
396,
63,
773,
14,
20760,
304,
523,
408,
2925,
367,
314,
11756,
570,
2656,
1041,
819,
347,
3613,
8,
277,
304,
272,
408,
9899,
1536,
314,
4346,
2251,
1202,
23088,
314,
511,
1041,
272,
291,
423,
7717,
63,
1100,
275,
1067,
14,
2998,
342,
272,
511,
63,
515,
275,
291,
423,
28967,
14225,
2941,
16878,
14,
6838,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
396,
63,
515,
9,
339,
511,
63,
736,
63,
515,
63,
1650,
275,
931,
63,
1650,
63,
3702,
14,
2927,
14,
4665,
2042,
5307,
8,
267,
10269,
14,
2711,
63,
23723,
6467,
63,
3100,
12,
2909,
29,
396,
63,
515,
9,
272,
291,
423,
12256,
63,
515,
63,
1650,
275,
931,
63,
1650,
63,
3702,
14,
2927,
14,
4665,
2042,
5307,
8,
267,
10269,
14,
2711,
63,
23723,
6467,
63,
39,
16977,
12,
1676,
29,
396,
63,
736,
63,
515,
63,
1650,
9,
819,
347,
6766,
8,
277,
304,
272,
408,
35,
274,
796,
1536,
314,
4346,
2251,
1202,
23088,
314,
511,
1041,
272,
291,
423,
7717,
63,
1100,
14,
4699,
342,
819,
347,
511,
4299,
3325,
4724,
8,
277,
304,
272,
408,
774,
314,
1551,
436,
4002,
9330,
1041,
272,
570,
63,
2253,
275,
11756,
63,
493,
63,
2253,
14,
21975,
17521,
8,
267,
291,
423,
7717,
63,
1100,
12,
291,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2253,
9,
339,
570,
63,
2253,
14,
4299,
342,
819,
347,
511,
1173,
3900,
7965,
2175,
2042,
5307,
8,
277,
304,
272,
408,
774,
314,
570,
2397,
3495,
701,
931,
8929,
9330,
1041,
272,
570,
63,
2253,
275,
11756,
63,
493,
63,
2253,
14,
21975,
17521,
8,
267,
291,
423,
7717,
63,
1100,
12,
291,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2253,
9,
339,
570,
63,
2253,
14,
4299,
342,
339,
754,
275,
570,
63,
2253,
14,
1173,
3900,
7965,
2175,
2042,
5307,
8,
277,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
1815,
8,
1099,
9,
819,
347,
19970,
1173,
3900,
2175,
2042,
5307,
8,
277,
304,
272,
408,
2925,
314,
2372,
1173,
3900,
2175,
2042,
5307,
805,
1041,
272,
570,
63,
2253,
275,
11756,
63,
493,
63,
2253,
14,
21975,
17521,
8,
267,
291,
423,
7717,
63,
1100,
12,
291,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2253,
9,
339,
570,
63,
2253,
14,
4299,
342,
339,
570,
63,
2373,
275,
570,
63,
2253,
14,
26535,
3900,
2175,
2042,
5307,
8,
277,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2373,
9,
272,
291,
14,
629,
8,
493,
63,
2373,
14,
354,
12,
4074,
819,
347,
19970,
6405,
1173,
3900,
8,
277,
304,
272,
408,
774,
314,
664,
1738,
570,
2397,
9330,
1041,
272,
570,
63,
2253,
275,
11756,
63,
493,
63,
2253,
14,
21975,
17521,
8,
267,
291,
423,
7717,
63,
1100,
12,
291,
423,
12256,
63,
515,
63,
1650,
9,
272,
291,
14,
10389,
8,
493,
63,
2253,
9,
339,
570,
63,
2253,
14,
4299,
342,
339,
570,
63,
2373,
275,
570,
63,
2253,
14,
1002,
6405,
1173,
3900,
342,
272,
291,
14,
10389,
8,
493,
63,
2373,
9,
272,
291,
14,
629,
8,
493,
63,
2373,
14,
354,
12,
4074,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
MrBasset/libcloud
|
libcloud/test/__init__.py
|
8
|
10398
|
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import random
from libcloud.utils.py3 import httplib
from libcloud.utils.py3 import StringIO
from libcloud.utils.py3 import urlparse
from libcloud.utils.py3 import parse_qs
from libcloud.utils.py3 import parse_qsl
from libcloud.utils.py3 import u
from libcloud.utils.py3 import unittest2_required
if unittest2_required:
import unittest2 as unittest
else:
import unittest
XML_HEADERS = {'content-type': 'application/xml'}
class LibcloudTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
self._visited_urls = []
self._executed_mock_methods = []
super(LibcloudTestCase, self).__init__(*args, **kwargs)
def setUp(self):
self._visited_urls = []
self._executed_mock_methods = []
def _add_visited_url(self, url):
self._visited_urls.append(url)
def _add_executed_mock_method(self, method_name):
self._executed_mock_methods.append(method_name)
def assertExecutedMethodCount(self, expected):
actual = len(self._executed_mock_methods)
self.assertEqual(actual, expected,
'expected %d, but %d mock methods were executed'
% (expected, actual))
class multipleresponse(object):
"""
A decorator that allows MockHttp objects to return multi responses
"""
count = 0
func = None
def __init__(self, f):
self.func = f
def __call__(self, *args, **kwargs):
ret = self.func(self.func.__class__, *args, **kwargs)
response = ret[self.count]
self.count = self.count + 1
return response
class MockResponse(object):
"""
A mock HTTPResponse
"""
headers = {}
body = StringIO()
status = 0
reason = ''
version = 11
def __init__(self, status, body=None, headers=None, reason=None):
self.status = status
self.body = StringIO(u(body)) if body else StringIO()
self.headers = headers or self.headers
self.reason = reason or self.reason
def read(self, *args, **kwargs):
return self.body.read(*args, **kwargs)
def next(self):
if sys.version_info >= (2, 5) and sys.version_info <= (2, 6):
return self.body.next()
else:
return next(self.body)
def __next__(self):
return self.next()
def getheader(self, name, *args, **kwargs):
return self.headers.get(name, *args, **kwargs)
def getheaders(self):
return list(self.headers.items())
def msg(self):
raise NotImplemented
class BaseMockHttpObject(object):
def _get_method_name(self, type, use_param, qs, path):
path = path.split('?')[0]
meth_name = path.replace('/', '_').replace('.', '_').replace('-', '_')
if type:
meth_name = '%s_%s' % (meth_name, self.type)
if use_param and use_param in qs:
param = qs[use_param][0].replace('.', '_').replace('-', '_')
meth_name = '%s_%s' % (meth_name, param)
return meth_name
class MockHttp(BaseMockHttpObject):
"""
A mock HTTP client/server suitable for testing purposes. This replaces
`HTTPConnection` by implementing its API and returning a mock response.
Define methods by request path, replacing slashes (/) with underscores (_).
Each of these mock methods should return a tuple of:
(int status, str body, dict headers, str reason)
>>> mock = MockHttp('localhost', 8080)
>>> mock.request('GET', '/example/')
>>> response = mock.getresponse()
>>> response.body.read()
'Hello World!'
>>> response.status
200
>>> response.getheaders()
[('X-Foo', 'libcloud')]
>>> MockHttp.type = 'fail'
>>> mock.request('GET', '/example/')
>>> response = mock.getresponse()
>>> response.body.read()
'Oh Noes!'
>>> response.status
403
>>> response.getheaders()
[('X-Foo', 'fail')]
"""
responseCls = MockResponse
host = None
port = None
response = None
type = None
use_param = None # will use this param to namespace the request function
test = None # TestCase instance which is using this mock
proxy_url = None
def __init__(self, host, port, *args, **kwargs):
self.host = host
self.port = port
def request(self, method, url, body=None, headers=None, raw=False):
# Find a method we can use for this request
parsed = urlparse.urlparse(url)
scheme, netloc, path, params, query, fragment = parsed
qs = parse_qs(query)
if path.endswith('/'):
path = path[:-1]
meth_name = self._get_method_name(type=self.type,
use_param=self.use_param,
qs=qs, path=path)
meth = getattr(self, meth_name.replace('%', '_'))
if self.test and isinstance(self.test, LibcloudTestCase):
self.test._add_visited_url(url=url)
self.test._add_executed_mock_method(method_name=meth_name)
status, body, headers, reason = meth(method, url, body, headers)
self.response = self.responseCls(status, body, headers, reason)
def getresponse(self):
return self.response
def connect(self):
"""
Can't think of anything to mock here.
"""
pass
def close(self):
pass
def set_http_proxy(self, proxy_url):
self.proxy_url = proxy_url
# Mock request/response example
def _example(self, method, url, body, headers):
"""
Return a simple message and header, regardless of input.
"""
return (httplib.OK, 'Hello World!', {'X-Foo': 'libcloud'},
httplib.responses[httplib.OK])
def _example_fail(self, method, url, body, headers):
return (httplib.FORBIDDEN, 'Oh Noes!', {'X-Foo': 'fail'},
httplib.responses[httplib.FORBIDDEN])
class MockHttpTestCase(MockHttp, unittest.TestCase):
# Same as the MockHttp class, but you can also use assertions in the
# classes which inherit from this one.
def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self)
if kwargs.get('host', None) and kwargs.get('port', None):
MockHttp.__init__(self, *args, **kwargs)
def runTest(self):
pass
def assertUrlContainsQueryParams(self, url, expected_params, strict=False):
"""
Assert that provided url contains provided query parameters.
:param url: URL to assert.
:type url: ``str``
:param expected_params: Dictionary of expected query parameters.
:type expected_params: ``dict``
:param strict: Assert that provided url contains only expected_params.
(defaults to ``False``)
:type strict: ``bool``
"""
question_mark_index = url.find('?')
if question_mark_index != -1:
url = url[question_mark_index + 1:]
params = dict(parse_qsl(url))
if strict:
self.assertDictEqual(params, expected_params)
else:
for key, value in expected_params.items():
self.assertEqual(params[key], value)
class StorageMockHttp(MockHttp):
def putrequest(self, method, action):
pass
def putheader(self, key, value):
pass
def endheaders(self):
pass
def send(self, data):
pass
class MockRawResponse(BaseMockHttpObject):
"""
Mock RawResponse object suitable for testing.
"""
type = None
responseCls = MockResponse
def __init__(self, connection):
super(MockRawResponse, self).__init__()
self._data = []
self._current_item = 0
self._status = None
self._response = None
self._headers = None
self._reason = None
self.connection = connection
def next(self):
if self._current_item == len(self._data):
raise StopIteration
value = self._data[self._current_item]
self._current_item += 1
return value
def __next__(self):
return self.next()
def _generate_random_data(self, size):
data = ''
current_size = 0
while current_size < size:
value = str(random.randint(0, 9))
value_size = len(value)
data += value
current_size += value_size
return data
@property
def response(self):
return self._get_response_if_not_availale()
@property
def status(self):
self._get_response_if_not_availale()
return self._status
@property
def headers(self):
self._get_response_if_not_availale()
return self._headers
@property
def reason(self):
self._get_response_if_not_availale()
return self._reason
def _get_response_if_not_availale(self):
if not self._response:
meth_name = self._get_method_name(type=self.type,
use_param=False, qs=None,
path=self.connection.action)
meth = getattr(self, meth_name.replace('%', '_'))
result = meth(self.connection.method, None, None, None)
self._status, self._body, self._headers, self._reason = result
self._response = self.responseCls(self._status, self._body,
self._headers, self._reason)
return self._response
if __name__ == "__main__":
import doctest
doctest.testmod()
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
984,
199,
646,
2196,
199,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
8809,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
5228,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
7097,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
2198,
63,
6177,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
2198,
63,
26714,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
399,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
2882,
18,
63,
2427,
199,
199,
692,
2882,
18,
63,
2427,
26,
272,
492,
2882,
18,
465,
2882,
199,
2836,
26,
272,
492,
2882,
421,
199,
4317,
63,
21178,
275,
791,
1317,
13,
466,
356,
283,
3578,
15,
1652,
936,
421,
199,
533,
8003,
4091,
1746,
8,
2796,
14,
1746,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
21736,
63,
3603,
275,
942,
267,
291,
423,
22564,
63,
1805,
63,
2474,
275,
942,
267,
1613,
8,
4728,
4091,
1746,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
423,
21736,
63,
3603,
275,
942,
267,
291,
423,
22564,
63,
1805,
63,
2474,
275,
942,
339,
347,
485,
525,
63,
21736,
63,
633,
8,
277,
12,
1166,
304,
267,
291,
423,
21736,
63,
3603,
14,
740,
8,
633,
9,
339,
347,
485,
525,
63,
22564,
63,
1805,
63,
765,
8,
277,
12,
1083,
63,
354,
304,
267,
291,
423,
22564,
63,
1805,
63,
2474,
14,
740,
8,
765,
63,
354,
9,
339,
347,
702,
4858,
4241,
3767,
2353,
8,
277,
12,
1420,
304,
267,
3503,
275,
822,
8,
277,
423,
22564,
63,
1805,
63,
2474,
9,
267,
291,
14,
629,
8,
6514,
12,
1420,
12,
586,
283,
2062,
450,
68,
12,
1325,
450,
68,
1683,
3102,
4898,
7934,
7,
586,
450,
334,
2062,
12,
3503,
430,
421,
199,
533,
3663,
1310,
8,
785,
304,
272,
408,
272,
437,
7531,
626,
6127,
4420,
5779,
2251,
370,
372,
3510,
9320,
272,
408,
272,
2338,
275,
378,
272,
2562,
275,
488,
339,
347,
636,
826,
721,
277,
12,
289,
304,
267,
291,
14,
1532,
275,
289,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2203,
275,
291,
14,
1532,
8,
277,
14,
1532,
855,
533,
3108,
627,
589,
12,
1011,
958,
9,
267,
1177,
275,
2203,
59,
277,
14,
835,
61,
267,
291,
14,
835,
275,
291,
14,
835,
435,
413,
267,
372,
1177,
421,
199,
533,
4420,
2364,
8,
785,
304,
272,
408,
272,
437,
1683,
29034,
272,
408,
272,
2323,
275,
1052,
272,
2396,
275,
5228,
342,
272,
2004,
275,
378,
272,
4499,
275,
2125,
272,
1015,
275,
4119,
339,
347,
636,
826,
721,
277,
12,
2004,
12,
2396,
29,
403,
12,
2323,
29,
403,
12,
4499,
29,
403,
304,
267,
291,
14,
1205,
275,
2004,
267,
291,
14,
2030,
275,
5228,
8,
85,
8,
2030,
430,
340,
2396,
587,
5228,
342,
267,
291,
14,
2139,
275,
2323,
503,
291,
14,
2139,
267,
291,
14,
5764,
275,
4499,
503,
291,
14,
5764,
339,
347,
1586,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
291,
14,
2030,
14,
739,
2031,
589,
12,
1011,
958,
9,
339,
347,
2163,
8,
277,
304,
267,
340,
984,
14,
1023,
63,
815,
2356,
334,
18,
12,
959,
9,
436,
984,
14,
1023,
63,
815,
2695,
334,
18,
12,
1227,
304,
288,
372,
291,
14,
2030,
14,
2184,
342,
267,
587,
26,
288,
372,
2163,
8,
277,
14,
2030,
9,
339,
347,
636,
2184,
721,
277,
304,
267,
372,
291,
14,
2184,
342,
339,
347,
2312,
16946,
8,
277,
12,
536,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
291,
14,
2139,
14,
362,
8,
354,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
2312,
16946,
83,
8,
277,
304,
267,
372,
769,
8,
277,
14,
2139,
14,
1744,
1012,
339,
347,
1499,
8,
277,
304,
267,
746,
3784,
421,
199,
533,
3523,
3346,
5779,
1692,
8,
785,
304,
272,
347,
485,
362,
63,
765,
63,
354,
8,
277,
12,
730,
12,
675,
63,
635,
12,
6377,
12,
931,
304,
267,
931,
275,
931,
14,
1294,
360,
31,
5832,
16,
61,
267,
12750,
63,
354,
275,
931,
14,
1814,
10998,
2513,
1959,
1814,
14078,
2513,
1959,
1814,
13858,
18962,
398,
340,
730,
26,
288,
12750,
63,
354,
275,
1543,
83,
4970,
83,
7,
450,
334,
5247,
63,
354,
12,
291,
14,
466,
9,
398,
340,
675,
63,
635,
436,
675,
63,
635,
315,
6377,
26,
288,
1215,
275,
6377,
59,
1180,
63,
635,
1527,
16,
1055,
1814,
14078,
2513,
1959,
1814,
13858,
18962,
288,
12750,
63,
354,
275,
1543,
83,
4970,
83,
7,
450,
334,
5247,
63,
354,
12,
1215,
9,
398,
372,
12750,
63,
354,
421,
199,
533,
4420,
5779,
8,
1563,
3346,
5779,
1692,
304,
272,
408,
272,
437,
1683,
3101,
1890,
15,
1000,
11233,
367,
5343,
12901,
14,
961,
19058,
272,
658,
19114,
64,
701,
18234,
2399,
3261,
436,
8152,
282,
1683,
1177,
14,
339,
13930,
3102,
701,
1056,
931,
12,
15810,
20275,
334,
24793
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
984,
199,
646,
2196,
199,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
8809,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
5228,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
7097,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
2198,
63,
6177,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
2198,
63,
26714,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
399,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
2882,
18,
63,
2427,
199,
199,
692,
2882,
18,
63,
2427,
26,
272,
492,
2882,
18,
465,
2882,
199,
2836,
26,
272,
492,
2882,
421,
199,
4317,
63,
21178,
275,
791,
1317,
13,
466,
356,
283,
3578,
15,
1652,
936,
421,
199,
533,
8003,
4091,
1746,
8,
2796,
14,
1746,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
21736,
63,
3603,
275,
942,
267,
291,
423,
22564,
63,
1805,
63,
2474,
275,
942,
267,
1613,
8,
4728,
4091,
1746,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
423,
21736,
63,
3603,
275,
942,
267,
291,
423,
22564,
63,
1805,
63,
2474,
275,
942,
339,
347,
485,
525,
63,
21736,
63,
633,
8,
277,
12,
1166,
304,
267,
291,
423,
21736,
63,
3603,
14,
740,
8,
633,
9,
339,
347,
485,
525,
63,
22564,
63,
1805,
63,
765,
8,
277,
12,
1083,
63,
354,
304,
267,
291,
423,
22564,
63,
1805,
63,
2474,
14,
740,
8,
765,
63,
354,
9,
339,
347,
702,
4858,
4241,
3767,
2353,
8,
277,
12,
1420,
304,
267,
3503,
275,
822,
8,
277,
423,
22564,
63,
1805,
63,
2474,
9,
267,
291,
14,
629,
8,
6514,
12,
1420,
12,
586,
283,
2062,
450,
68,
12,
1325,
450,
68,
1683,
3102,
4898,
7934,
7,
586,
450,
334,
2062,
12,
3503,
430,
421,
199,
533,
3663,
1310,
8,
785,
304,
272,
408,
272,
437,
7531,
626,
6127,
4420,
5779,
2251,
370,
372,
3510,
9320,
272,
408,
272,
2338,
275,
378,
272,
2562,
275,
488,
339,
347,
636,
826,
721,
277,
12,
289,
304,
267,
291,
14,
1532,
275,
289,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2203,
275,
291,
14,
1532,
8,
277,
14,
1532,
855,
533,
3108,
627,
589,
12,
1011,
958,
9,
267,
1177,
275,
2203,
59,
277,
14,
835,
61,
267,
291,
14,
835,
275,
291,
14,
835,
435,
413,
267,
372,
1177,
421,
199,
533,
4420,
2364,
8,
785,
304,
272,
408,
272,
437,
1683,
29034,
272,
408,
272,
2323,
275,
1052,
272,
2396,
275,
5228,
342,
272,
2004,
275,
378,
272,
4499,
275,
2125,
272,
1015,
275,
4119,
339,
347,
636,
826,
721,
277,
12,
2004,
12,
2396,
29,
403,
12,
2323,
29,
403,
12,
4499,
29,
403,
304,
267,
291,
14,
1205,
275,
2004,
267,
291,
14,
2030,
275,
5228,
8,
85,
8,
2030,
430,
340,
2396,
587,
5228,
342,
267,
291,
14,
2139,
275,
2323,
503,
291,
14,
2139,
267,
291,
14,
5764,
275,
4499,
503,
291,
14,
5764,
339,
347,
1586,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
291,
14,
2030,
14,
739,
2031,
589,
12,
1011,
958,
9,
339,
347,
2163,
8,
277,
304,
267,
340,
984,
14,
1023,
63,
815,
2356,
334,
18,
12,
959,
9,
436,
984,
14,
1023,
63,
815,
2695,
334,
18,
12,
1227,
304,
288,
372,
291,
14,
2030,
14,
2184,
342,
267,
587,
26,
288,
372,
2163,
8,
277,
14,
2030,
9,
339,
347,
636,
2184,
721,
277,
304,
267,
372,
291,
14,
2184,
342,
339,
347,
2312,
16946,
8,
277,
12,
536,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
291,
14,
2139,
14,
362,
8,
354,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
2312,
16946,
83,
8,
277,
304,
267,
372,
769,
8,
277,
14,
2139,
14,
1744,
1012,
339,
347,
1499,
8,
277,
304,
267,
746,
3784,
421,
199,
533,
3523,
3346,
5779,
1692,
8,
785,
304,
272,
347,
485,
362,
63,
765,
63,
354,
8,
277,
12,
730,
12,
675,
63,
635,
12,
6377,
12,
931,
304,
267,
931,
275,
931,
14,
1294,
360,
31,
5832,
16,
61,
267,
12750,
63,
354,
275,
931,
14,
1814,
10998,
2513,
1959,
1814,
14078,
2513,
1959,
1814,
13858,
18962,
398,
340,
730,
26,
288,
12750,
63,
354,
275,
1543,
83,
4970,
83,
7,
450,
334,
5247,
63,
354,
12,
291,
14,
466,
9,
398,
340,
675,
63,
635,
436,
675,
63,
635,
315,
6377,
26,
288,
1215,
275,
6377,
59,
1180,
63,
635,
1527,
16,
1055,
1814,
14078,
2513,
1959,
1814,
13858,
18962,
288,
12750,
63,
354,
275,
1543,
83,
4970,
83,
7,
450,
334,
5247,
63,
354,
12,
1215,
9,
398,
372,
12750,
63,
354,
421,
199,
533,
4420,
5779,
8,
1563,
3346,
5779,
1692,
304,
272,
408,
272,
437,
1683,
3101,
1890,
15,
1000,
11233,
367,
5343,
12901,
14,
961,
19058,
272,
658,
19114,
64,
701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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
] |
letouriste001/SmartForest_2.0
|
python3.4Smartforest/lib/python3.4/site-packages/django/contrib/gis/utils/wkt.py
|
1
|
1923
|
"""
Utilities for manipulating Geometry WKT.
"""
from django.utils import six
def precision_wkt(geom, prec):
"""
Returns WKT text of the geometry according to the given precision (an
integer or a string). If the precision is an integer, then the decimal
places of coordinates WKT will be truncated to that number:
>>> from django.contrib.gis.geos import Point
>>> pnt = Point(5, 23)
>>> pnt.wkt
'POINT (5.0000000000000000 23.0000000000000000)'
>>> precision_wkt(pnt, 1)
'POINT (5.0 23.0)'
If the precision is a string, it must be valid Python format string
(e.g., '%20.7f') -- thus, you should know what you're doing.
"""
if isinstance(prec, int):
num_fmt = '%%.%df' % prec
elif isinstance(prec, six.string_types):
num_fmt = prec
else:
raise TypeError
# TODO: Support 3D geometries.
coord_fmt = ' '.join([num_fmt, num_fmt])
def formatted_coords(coords):
return ','.join(coord_fmt % c[:2] for c in coords)
def formatted_poly(poly):
return ','.join('(%s)' % formatted_coords(r) for r in poly)
def formatted_geom(g):
gtype = str(g.geom_type).upper()
yield '%s(' % gtype
if gtype == 'POINT':
yield formatted_coords((g.coords,))
elif gtype in ('LINESTRING', 'LINEARRING'):
yield formatted_coords(g.coords)
elif gtype in ('POLYGON', 'MULTILINESTRING'):
yield formatted_poly(g)
elif gtype == 'MULTIPOINT':
yield formatted_coords(g.coords)
elif gtype == 'MULTIPOLYGON':
yield ','.join('(%s)' % formatted_poly(p) for p in g)
elif gtype == 'GEOMETRYCOLLECTION':
yield ','.join(''.join(wkt for wkt in formatted_geom(child)) for child in g)
else:
raise TypeError
yield ')'
return ''.join(wkt for wkt in formatted_geom(geom))
|
mit
|
[
624,
202,
738,
17933,
367,
13335,
20529,
10579,
22561,
14,
202,
624,
202,
202,
504,
1639,
14,
1208,
492,
3816,
202,
202,
202,
318,
7151,
63,
11412,
8,
6481,
12,
13826,
304,
202,
259,
408,
202,
259,
1803,
22561,
1318,
402,
314,
3400,
7182,
370,
314,
1627,
7151,
334,
290,
202,
259,
3000,
503,
282,
1059,
680,
221,
982,
314,
7151,
365,
376,
3000,
12,
2066,
314,
6107,
202,
259,
9825,
402,
8983,
22561,
911,
506,
17661,
370,
626,
1329,
26,
202,
202,
258,
1306,
687,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
7584,
202,
258,
1306,
19948,
275,
7584,
8,
21,
12,
6546,
9,
202,
258,
1306,
19948,
14,
11412,
202,
258,
283,
7217,
334,
21,
14,
9409,
6546,
14,
9409,
3171,
202,
258,
1306,
7151,
63,
11412,
8,
24519,
12,
413,
9,
202,
258,
283,
7217,
334,
21,
14,
16,
6546,
14,
16,
3171,
202,
202,
259,
982,
314,
7151,
365,
282,
1059,
12,
652,
1471,
506,
1686,
2018,
1475,
1059,
202,
259,
334,
69,
14,
71,
2020,
1543,
1165,
14,
23,
70,
358,
1553,
12850,
12,
1265,
1077,
5715,
4052,
1265,
3984,
9689,
14,
202,
259,
408,
202,
259,
340,
1228,
8,
9218,
12,
1109,
304,
202,
263,
1967,
63,
5045,
275,
23100,
4111,
1587,
7,
450,
13826,
202,
259,
916,
1228,
8,
9218,
12,
3816,
14,
875,
63,
1313,
304,
202,
263,
1967,
63,
5045,
275,
13826,
202,
259,
587,
26,
202,
263,
746,
3146,
202,
202,
259,
327,
3254,
26,
12502,
650,
36,
24883,
14,
202,
259,
11021,
63,
5045,
275,
283,
1987,
904,
779,
1507,
63,
5045,
12,
1967,
63,
5045,
566,
202,
202,
259,
347,
7871,
63,
8032,
8,
8032,
304,
202,
263,
372,
12814,
904,
8,
7988,
63,
5045,
450,
286,
1491,
18,
61,
367,
286,
315,
13259,
9,
202,
202,
259,
347,
7871,
63,
6023,
8,
6023,
304,
202,
263,
372,
12814,
904,
360,
4042,
83,
3171,
450,
7871,
63,
8032,
8,
82,
9,
367,
519,
315,
8446,
9,
202,
202,
259,
347,
7871,
63,
6481,
8,
71,
304,
202,
263,
486,
466,
275,
620,
8,
71,
14,
6481,
63,
466,
680,
4142,
342,
202,
263,
1995,
1543,
83,
360,
450,
486,
466,
202,
263,
340,
486,
466,
508,
283,
7217,
356,
202,
3322,
1995,
7871,
63,
8032,
1332,
71,
14,
8032,
4641,
202,
263,
916,
486,
466,
315,
661,
6143,
29780,
297,
283,
6174,
1920,
1206,
735,
202,
3322,
1995,
7871,
63,
8032,
8,
71,
14,
8032,
9,
202,
263,
916,
486,
466,
315,
661,
23602,
297,
283,
15635,
568,
29780,
735,
202,
3322,
1995,
7871,
63,
6023,
8,
71,
9,
202,
263,
916,
486,
466,
508,
283,
21389,
7217,
356,
202,
3322,
1995,
7871,
63,
8032,
8,
71,
14,
8032,
9,
202,
263,
916,
486,
466,
508,
283,
21389,
23602,
356,
202,
3322,
1995,
12814,
904,
360,
4042,
83,
3171,
450,
7871,
63,
6023,
8,
80,
9,
367,
299,
315,
486,
9,
202,
263,
916,
486,
466,
508,
283,
28472,
29374,
356,
202,
3322,
1995,
12814,
904,
17840,
904,
8,
11412,
367,
21992,
315,
7871,
63,
6481,
8,
1739,
430,
367,
1982,
315,
486,
9,
202,
263,
587,
26,
202,
3322,
746,
3146,
202,
263,
1995,
16107,
202,
202,
259,
372,
6522,
904,
8,
11412,
367,
21992,
315,
7871,
63,
6481,
8,
6481,
430,
202,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
202,
738,
17933,
367,
13335,
20529,
10579,
22561,
14,
202,
624,
202,
202,
504,
1639,
14,
1208,
492,
3816,
202,
202,
202,
318,
7151,
63,
11412,
8,
6481,
12,
13826,
304,
202,
259,
408,
202,
259,
1803,
22561,
1318,
402,
314,
3400,
7182,
370,
314,
1627,
7151,
334,
290,
202,
259,
3000,
503,
282,
1059,
680,
221,
982,
314,
7151,
365,
376,
3000,
12,
2066,
314,
6107,
202,
259,
9825,
402,
8983,
22561,
911,
506,
17661,
370,
626,
1329,
26,
202,
202,
258,
1306,
687,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
7584,
202,
258,
1306,
19948,
275,
7584,
8,
21,
12,
6546,
9,
202,
258,
1306,
19948,
14,
11412,
202,
258,
283,
7217,
334,
21,
14,
9409,
6546,
14,
9409,
3171,
202,
258,
1306,
7151,
63,
11412,
8,
24519,
12,
413,
9,
202,
258,
283,
7217,
334,
21,
14,
16,
6546,
14,
16,
3171,
202,
202,
259,
982,
314,
7151,
365,
282,
1059,
12,
652,
1471,
506,
1686,
2018,
1475,
1059,
202,
259,
334,
69,
14,
71,
2020,
1543,
1165,
14,
23,
70,
358,
1553,
12850,
12,
1265,
1077,
5715,
4052,
1265,
3984,
9689,
14,
202,
259,
408,
202,
259,
340,
1228,
8,
9218,
12,
1109,
304,
202,
263,
1967,
63,
5045,
275,
23100,
4111,
1587,
7,
450,
13826,
202,
259,
916,
1228,
8,
9218,
12,
3816,
14,
875,
63,
1313,
304,
202,
263,
1967,
63,
5045,
275,
13826,
202,
259,
587,
26,
202,
263,
746,
3146,
202,
202,
259,
327,
3254,
26,
12502,
650,
36,
24883,
14,
202,
259,
11021,
63,
5045,
275,
283,
1987,
904,
779,
1507,
63,
5045,
12,
1967,
63,
5045,
566,
202,
202,
259,
347,
7871,
63,
8032,
8,
8032,
304,
202,
263,
372,
12814,
904,
8,
7988,
63,
5045,
450,
286,
1491,
18,
61,
367,
286,
315,
13259,
9,
202,
202,
259,
347,
7871,
63,
6023,
8,
6023,
304,
202,
263,
372,
12814,
904,
360,
4042,
83,
3171,
450,
7871,
63,
8032,
8,
82,
9,
367,
519,
315,
8446,
9,
202,
202,
259,
347,
7871,
63,
6481,
8,
71,
304,
202,
263,
486,
466,
275,
620,
8,
71,
14,
6481,
63,
466,
680,
4142,
342,
202,
263,
1995,
1543,
83,
360,
450,
486,
466,
202,
263,
340,
486,
466,
508,
283,
7217,
356,
202,
3322,
1995,
7871,
63,
8032,
1332,
71,
14,
8032,
4641,
202,
263,
916,
486,
466,
315,
661,
6143,
29780,
297,
283,
6174,
1920,
1206,
735,
202,
3322,
1995,
7871,
63,
8032,
8,
71,
14,
8032,
9,
202,
263,
916,
486,
466,
315,
661,
23602,
297,
283,
15635,
568,
29780,
735,
202,
3322,
1995,
7871,
63,
6023,
8,
71,
9,
202,
263,
916,
486,
466,
508,
283,
21389,
7217,
356,
202,
3322,
1995,
7871,
63,
8032,
8,
71,
14,
8032,
9,
202,
263,
916,
486,
466,
508,
283,
21389,
23602,
356,
202,
3322,
1995,
12814,
904,
360,
4042,
83,
3171,
450,
7871,
63,
6023,
8,
80,
9,
367,
299,
315,
486,
9,
202,
263,
916,
486,
466,
508,
283,
28472,
29374,
356,
202,
3322,
1995,
12814,
904,
17840,
904,
8,
11412,
367,
21992,
315,
7871,
63,
6481,
8,
1739,
430,
367,
1982,
315,
486,
9,
202,
263,
587,
26,
202,
3322,
746,
3146,
202,
263,
1995,
16107,
202,
202,
259,
372,
6522,
904,
8,
11412,
367,
21992,
315,
7871,
63,
6481,
8,
6481,
430,
202,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
isard-vdi/isard
|
webapp/webapp/webapp/lib/isardScheduler.py
|
1
|
5947
|
# Copyright 2017 the Isard-vdi project authors:
# Josep Maria Viñolas Auquer
# Alberto Larraz Dalmases
# License: AGPLv3
#!/usr/bin/env python
# coding=utf-8
from decimal import Decimal
import random, queue
from threading import Thread
import time, pytz
from webapp import app
import rethinkdb as r
from flask import current_app
from .flask_rethink import RethinkDB
db = RethinkDB(app)
db.init_app(app)
from ..lib.log import *
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.rethinkdb import RethinkDBJobStore
from datetime import datetime, timedelta
class isardScheduler():
def __init__(self):
'''
JOB SCHEDULER
'''
self.rStore=RethinkDBJobStore()
self.scheduler = BackgroundScheduler(timezone=pytz.timezone('UTC'))
self.scheduler.add_jobstore('rethinkdb',self.rStore, database='isard', table='scheduler_jobs',host=app.config['RETHINKDB_HOST'],
port=app.config['RETHINKDB_PORT'],
auth_key='')
self.scheduler.remove_all_jobs()
#self.scheduler.add_job(alarm, 'date', run_date=alarm_time, args=[datetime.now()])
#app.sched.shutdown(wait=False)
#self.add_scheduler('interval','stop_shutting_down_desktops','0','1')
self.turnOn()
self.add_scheduler('interval','stop_shutting_down_desktops','0','1')
def add_scheduler(self,kind,action,hour,minute):
id=kind+'_'+action+'_'+str(hour)+str(minute)
function=getattr(isardScheduler,action)
if kind == 'cron':
self.scheduler.add_job(function, kind, hour=int(hour), minute=int(minute), jobstore=self.rStore, replace_existing=True, id=id)
if kind == 'interval':
self.scheduler.add_job(function, kind, hours=int(hour), minutes=int(minute), jobstore=self.rStore, replace_existing=True, id=id)
if kind == 'date':
alarm_time = datetime.now() + timedelta(hours=int(hour),minutes=int(minute))
self.scheduler.add_job(function, kind, run_date=alarm_time, jobstore=self.rStore, replace_existing=True, id=id)
with app.app_context():
r.table('scheduler_jobs').get(id).update({'kind':kind,'action':action,'name':action.replace('_',' '),'hour':hour,'minute':minute}).run(db.conn)
return True
'''
Scheduler actions
'''
def stop_domains():
with app.app_context():
r.table('domains').get_all('Started',index='status').update({'status':'Stopping'}).run(db.conn)
def stop_domains_without_viewer():
with app.app_context():
r.table('domains').get_all('Started',index='status').filter({'viewer':{'client_since':False}}).update({'status':'Stopping'}).run(db.conn)
def stop_shutting_down_desktops():
with app.app_context():
domains=r.table('domains').get_all('Shutting-down',index='status').pluck('id','accessed').run(db.conn)
t=time.time()
for d in domains:
if d['accessed']+1.9*60 < t: # 2 minutes * 60 seconds
r.table('domains').get(d['id']).update({'status':'Stopping','accessed':time.time()}).run(db.conn)
def check_ephimeral_status():
with app.app_context():
domains=r.table('domains').get_all('Started',index='status').has_fields('ephimeral').pluck('id','ephimeral','history_domain').run(db.conn)
t=time.time()
for d in domains:
if d['history_domain'][0]['when']+int(d['ephimeral']['minutes'])*60 < t:
r.table('domains').get(d['id']).update({'status':d['ephimeral']['action']}).run(db.conn)
def backup_database():
app.adminapi.backup_db()
def delete_old_stats(reduce_interval=300,delete_interval=86400): # 24h
with app.app_context():
# domains_status
r.table('domains_status_history').filter(r.row['when'] < int(time.time()) - delete_interval).delete().run(db.conn)
reduced=[]
cursor = r.table('domains_status').filter(r.row['when'] < int(time.time()) - reduce_interval).order_by('when').run(db.conn)
r.table('domains_status').filter(r.row['when'] < int(time.time()) - reduce_interval).delete().run(db.conn)
i=0
for c in cursor:
if i % 50 == 0: reduced.append(c)
i+=1
r.table('domains_status_history').insert(reduced).run(db.conn)
# Hypervisors_status
r.table('hypervisors_status_history').filter(r.row['when'] < int(time.time()) - delete_interval).delete().run(db.conn)
reduced=[]
cursor = r.table('hypervisors_status').filter(r.row['when'] < int(time.time()) - reduce_interval).order_by('when').run(db.conn)
r.table('hypervisors_status').filter(r.row['when'] < int(time.time()) - reduce_interval).delete().run(db.conn)
i=0
for c in cursor:
if i % 50 == 0: reduced.append(c)
i+=1
r.table('hypervisors_status_history').insert(reduced).run(db.conn)
# Hypervisors_events (does not grow at the same speed)
r.table('hypervisors_events').filter(r.row['when'] < int(time.time()) - delete_interval).delete().run(db.conn)
def turnOff(self):
self.scheduler.shutdown()
def turnOn(self):
self.scheduler.start()
def removeJobs(self):
self.scheduler.remove_all_jobs()
'''
BULK ACTIONS
'''
def bulk_action(self,table,tbl_filter,tbl_update):
with app.app_context():
log.info('BULK ACTION: Table {}, Filter {}, Update {}'.format(table,filter, update))
r.table(table).filter(filter).update(update).run(db.conn)
r.table(table).filter({'status':'Unknown'}).update({'status':'Stopping'}).run(db.conn)
|
agpl-3.0
|
[
3,
1898,
9708,
314,
6596,
1005,
13,
17493,
2199,
11462,
26,
199,
3,
420,
1603,
3362,
80,
603,
27957,
6561,
22692,
393,
305,
31853,
16891,
199,
3,
420,
4580,
605,
475,
491,
285,
345,
90,
577,
279,
391,
874,
199,
3,
844,
26,
437,
28863,
19,
199,
199,
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
29,
1624,
13,
24,
199,
504,
6107,
492,
6345,
199,
646,
2196,
12,
4126,
199,
504,
5796,
492,
11086,
199,
646,
900,
12,
15444,
199,
504,
24812,
492,
1145,
199,
646,
295,
29727,
697,
465,
519,
199,
504,
7209,
492,
1453,
63,
571,
199,
199,
504,
1275,
15720,
63,
264,
29727,
492,
799,
29727,
2846,
199,
697,
275,
799,
29727,
2846,
8,
571,
9,
199,
697,
14,
826,
63,
571,
8,
571,
9,
199,
199,
504,
2508,
773,
14,
793,
492,
627,
199,
199,
504,
282,
1190,
5085,
14,
7211,
2393,
14,
7451,
492,
10257,
3928,
11251,
199,
504,
282,
1190,
5085,
14,
2423,
18958,
14,
264,
29727,
697,
492,
799,
29727,
2846,
6694,
5502,
199,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
533,
365,
1005,
11251,
837,
272,
347,
636,
826,
721,
277,
304,
267,
1449,
267,
1603,
5488,
428,
22492,
1293,
540,
267,
1449,
267,
291,
14,
82,
5502,
29,
497,
29727,
2846,
6694,
5502,
342,
398,
291,
14,
8874,
275,
10257,
3928,
11251,
8,
7145,
29,
21948,
14,
7145,
360,
11288,
1333,
267,
291,
14,
8874,
14,
525,
63,
2423,
1617,
360,
264,
29727,
697,
297,
277,
14,
82,
5502,
12,
3050,
534,
374,
1005,
297,
1817,
534,
8874,
63,
6920,
297,
1102,
29,
571,
14,
888,
459,
7341,
40,
12394,
2846,
63,
5449,
995,
586,
1844,
29,
571,
14,
888,
459,
7341,
40,
12394,
2846,
63,
3657,
995,
586,
1790,
63,
498,
13275,
267,
291,
14,
8874,
14,
2168,
63,
452,
63,
6920,
342,
267,
327,
277,
14,
8874,
14,
525,
63,
2423,
8,
14160,
12,
283,
602,
297,
1255,
63,
602,
29,
14160,
63,
521,
12,
1249,
1524,
2083,
14,
2131,
9383,
267,
327,
571,
14,
10487,
14,
8831,
8,
2573,
29,
797,
9,
267,
327,
277,
14,
525,
63,
8874,
360,
4284,
1673,
2379,
63,
609,
337,
1337,
63,
2110,
63,
10368,
84,
1483,
1673,
16,
1673,
17,
358,
267,
291,
14,
353,
3314,
342,
267,
291,
14,
525,
63,
8874,
360,
4284,
1673,
2379,
63,
609,
337,
1337,
63,
2110,
63,
10368,
84,
1483,
1673,
16,
1673,
17,
358,
268,
5493,
347,
1050,
63,
8874,
8,
277,
12,
5091,
12,
1287,
12,
5180,
12,
10698,
304,
267,
1305,
29,
5091,
4786,
20013,
1287,
4786,
20013,
495,
8,
5180,
6393,
495,
8,
10698,
9,
267,
805,
29,
5675,
8,
374,
1005,
11251,
12,
1287,
9,
4960,
340,
4928,
508,
283,
14829,
356,
288,
291,
14,
8874,
14,
525,
63,
2423,
8,
1593,
12,
4928,
12,
6925,
29,
442,
8,
5180,
395,
12709,
29,
442,
8,
10698,
395,
3906,
1617,
29,
277,
14,
82,
5502,
12,
3350,
63,
5952,
29,
549,
12,
1305,
29,
344,
9,
267,
340,
4928,
508,
283,
4284,
356,
288,
291,
14,
8874,
14,
525,
63,
2423,
8,
1593,
12,
4928,
12,
10857,
29,
442,
8,
5180,
395,
9395,
29,
442,
8,
10698,
395,
3906,
1617,
29,
277,
14,
82,
5502,
12,
3350,
63,
5952,
29,
549,
12,
1305,
29,
344,
9,
267,
340,
4928,
508,
283,
602,
356,
288,
17987,
63,
521,
275,
2197,
14,
2131,
342,
435,
6871,
8,
8419,
29,
442,
8,
5180,
395,
10430,
29,
442,
8,
10698,
430,
288,
291,
14,
8874,
14,
525,
63,
2423,
8,
1593,
12,
4928,
12,
1255,
63,
602,
29,
14160,
63,
521,
12,
3906,
1617,
29,
277,
14,
82,
5502,
12,
3350,
63,
5952,
29,
549,
12,
1305,
29,
344,
9,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
519,
14,
1224,
360,
8874,
63,
6920,
1959,
362,
8,
344,
680,
873,
3252,
5091,
356,
5091,
2584,
1287,
356,
1287,
2584,
354,
356,
1287,
14,
1814,
6412,
1673,
17748,
7,
5180,
356,
5180,
2584,
10698,
356,
10698,
21385,
1065,
8,
697,
14,
1631,
9,
267,
372,
715,
339,
1449,
272,
32051,
5445,
272,
1449,
272,
347,
3631,
63,
9756,
837,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
519,
14,
1224,
360,
9756,
1959,
362,
63,
452,
360,
21031,
297,
1080,
534,
1205,
1959,
873,
3252,
1205,
5242,
6293,
4073,
936,
680,
1065,
8,
697,
14,
1631,
9,
339,
347,
3631,
63,
9756,
63,
7395,
63,
16645,
837,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
519,
14,
1224,
360,
9756,
1959,
362,
63,
452,
360,
21031,
297,
1080,
534,
1205,
1959,
1541,
3252,
16645,
3010,
1258,
63,
8585,
356,
797,
4863,
680,
873,
3252,
1205,
5242,
6293,
4073,
936,
680,
1065,
8,
697,
14,
1631,
9,
339,
347,
3631,
63,
609,
337,
1337,
63,
2110,
63,
10368,
84,
1483,
837,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
14006,
29,
82,
14,
1224,
360,
9756,
1959,
362,
63,
452,
360,
2662,
337,
1337,
13,
2110,
297,
1080,
534,
1205,
1959,
1168,
10112,
360,
344,
1673,
29433,
1959,
1065,
8,
697,
14,
1631,
9,
288,
307,
29,
521,
14,
521,
342,
288,
367,
366,
315,
14006,
26,
355,
340,
366,
459,
29433,
21899,
17,
14,
25,
10,
2259,
665,
307,
26,
327,
499,
9395,
627,
5212,
4696,
490,
519,
14,
1224,
360,
9756,
1959,
362,
8,
68,
459,
344,
13227,
873,
3252,
1205,
5242,
6293,
4073,
1673,
29433,
356,
521,
14,
521,
12737,
680,
1065,
8,
697,
14,
1631,
9,
339,
347,
1104,
63,
69,
838,
6267,
279,
63,
1205,
837,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
14006,
29,
82,
14,
1224,
360,
9756,
1959,
362,
63,
452,
360,
21031,
297,
1080,
534,
1205,
1959,
1989,
63,
955,
360,
69,
838,
6267,
279,
1959,
1168,
10112,
360,
344,
1673,
69,
838,
6267,
279,
1673,
5570,
63,
2261,
1959,
1065,
8,
697,
14,
1631,
9,
288,
307,
29,
521,
14,
521,
342,
288,
367,
366,
315,
14006,
26,
355,
340,
366,
459,
5570,
63,
2261,
3488,
16,
2733,
6526,
21899,
442,
8,
68,
459,
69,
838,
6267,
279,
2545,
10430,
1105,
10,
2259,
665,
307,
26,
490,
519
] |
[
1898,
9708,
314,
6596,
1005,
13,
17493,
2199,
11462,
26,
199,
3,
420,
1603,
3362,
80,
603,
27957,
6561,
22692,
393,
305,
31853,
16891,
199,
3,
420,
4580,
605,
475,
491,
285,
345,
90,
577,
279,
391,
874,
199,
3,
844,
26,
437,
28863,
19,
199,
199,
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
29,
1624,
13,
24,
199,
504,
6107,
492,
6345,
199,
646,
2196,
12,
4126,
199,
504,
5796,
492,
11086,
199,
646,
900,
12,
15444,
199,
504,
24812,
492,
1145,
199,
646,
295,
29727,
697,
465,
519,
199,
504,
7209,
492,
1453,
63,
571,
199,
199,
504,
1275,
15720,
63,
264,
29727,
492,
799,
29727,
2846,
199,
697,
275,
799,
29727,
2846,
8,
571,
9,
199,
697,
14,
826,
63,
571,
8,
571,
9,
199,
199,
504,
2508,
773,
14,
793,
492,
627,
199,
199,
504,
282,
1190,
5085,
14,
7211,
2393,
14,
7451,
492,
10257,
3928,
11251,
199,
504,
282,
1190,
5085,
14,
2423,
18958,
14,
264,
29727,
697,
492,
799,
29727,
2846,
6694,
5502,
199,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
533,
365,
1005,
11251,
837,
272,
347,
636,
826,
721,
277,
304,
267,
1449,
267,
1603,
5488,
428,
22492,
1293,
540,
267,
1449,
267,
291,
14,
82,
5502,
29,
497,
29727,
2846,
6694,
5502,
342,
398,
291,
14,
8874,
275,
10257,
3928,
11251,
8,
7145,
29,
21948,
14,
7145,
360,
11288,
1333,
267,
291,
14,
8874,
14,
525,
63,
2423,
1617,
360,
264,
29727,
697,
297,
277,
14,
82,
5502,
12,
3050,
534,
374,
1005,
297,
1817,
534,
8874,
63,
6920,
297,
1102,
29,
571,
14,
888,
459,
7341,
40,
12394,
2846,
63,
5449,
995,
586,
1844,
29,
571,
14,
888,
459,
7341,
40,
12394,
2846,
63,
3657,
995,
586,
1790,
63,
498,
13275,
267,
291,
14,
8874,
14,
2168,
63,
452,
63,
6920,
342,
267,
327,
277,
14,
8874,
14,
525,
63,
2423,
8,
14160,
12,
283,
602,
297,
1255,
63,
602,
29,
14160,
63,
521,
12,
1249,
1524,
2083,
14,
2131,
9383,
267,
327,
571,
14,
10487,
14,
8831,
8,
2573,
29,
797,
9,
267,
327,
277,
14,
525,
63,
8874,
360,
4284,
1673,
2379,
63,
609,
337,
1337,
63,
2110,
63,
10368,
84,
1483,
1673,
16,
1673,
17,
358,
267,
291,
14,
353,
3314,
342,
267,
291,
14,
525,
63,
8874,
360,
4284,
1673,
2379,
63,
609,
337,
1337,
63,
2110,
63,
10368,
84,
1483,
1673,
16,
1673,
17,
358,
268,
5493,
347,
1050,
63,
8874,
8,
277,
12,
5091,
12,
1287,
12,
5180,
12,
10698,
304,
267,
1305,
29,
5091,
4786,
20013,
1287,
4786,
20013,
495,
8,
5180,
6393,
495,
8,
10698,
9,
267,
805,
29,
5675,
8,
374,
1005,
11251,
12,
1287,
9,
4960,
340,
4928,
508,
283,
14829,
356,
288,
291,
14,
8874,
14,
525,
63,
2423,
8,
1593,
12,
4928,
12,
6925,
29,
442,
8,
5180,
395,
12709,
29,
442,
8,
10698,
395,
3906,
1617,
29,
277,
14,
82,
5502,
12,
3350,
63,
5952,
29,
549,
12,
1305,
29,
344,
9,
267,
340,
4928,
508,
283,
4284,
356,
288,
291,
14,
8874,
14,
525,
63,
2423,
8,
1593,
12,
4928,
12,
10857,
29,
442,
8,
5180,
395,
9395,
29,
442,
8,
10698,
395,
3906,
1617,
29,
277,
14,
82,
5502,
12,
3350,
63,
5952,
29,
549,
12,
1305,
29,
344,
9,
267,
340,
4928,
508,
283,
602,
356,
288,
17987,
63,
521,
275,
2197,
14,
2131,
342,
435,
6871,
8,
8419,
29,
442,
8,
5180,
395,
10430,
29,
442,
8,
10698,
430,
288,
291,
14,
8874,
14,
525,
63,
2423,
8,
1593,
12,
4928,
12,
1255,
63,
602,
29,
14160,
63,
521,
12,
3906,
1617,
29,
277,
14,
82,
5502,
12,
3350,
63,
5952,
29,
549,
12,
1305,
29,
344,
9,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
519,
14,
1224,
360,
8874,
63,
6920,
1959,
362,
8,
344,
680,
873,
3252,
5091,
356,
5091,
2584,
1287,
356,
1287,
2584,
354,
356,
1287,
14,
1814,
6412,
1673,
17748,
7,
5180,
356,
5180,
2584,
10698,
356,
10698,
21385,
1065,
8,
697,
14,
1631,
9,
267,
372,
715,
339,
1449,
272,
32051,
5445,
272,
1449,
272,
347,
3631,
63,
9756,
837,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
519,
14,
1224,
360,
9756,
1959,
362,
63,
452,
360,
21031,
297,
1080,
534,
1205,
1959,
873,
3252,
1205,
5242,
6293,
4073,
936,
680,
1065,
8,
697,
14,
1631,
9,
339,
347,
3631,
63,
9756,
63,
7395,
63,
16645,
837,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
519,
14,
1224,
360,
9756,
1959,
362,
63,
452,
360,
21031,
297,
1080,
534,
1205,
1959,
1541,
3252,
16645,
3010,
1258,
63,
8585,
356,
797,
4863,
680,
873,
3252,
1205,
5242,
6293,
4073,
936,
680,
1065,
8,
697,
14,
1631,
9,
339,
347,
3631,
63,
609,
337,
1337,
63,
2110,
63,
10368,
84,
1483,
837,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
14006,
29,
82,
14,
1224,
360,
9756,
1959,
362,
63,
452,
360,
2662,
337,
1337,
13,
2110,
297,
1080,
534,
1205,
1959,
1168,
10112,
360,
344,
1673,
29433,
1959,
1065,
8,
697,
14,
1631,
9,
288,
307,
29,
521,
14,
521,
342,
288,
367,
366,
315,
14006,
26,
355,
340,
366,
459,
29433,
21899,
17,
14,
25,
10,
2259,
665,
307,
26,
327,
499,
9395,
627,
5212,
4696,
490,
519,
14,
1224,
360,
9756,
1959,
362,
8,
68,
459,
344,
13227,
873,
3252,
1205,
5242,
6293,
4073,
1673,
29433,
356,
521,
14,
521,
12737,
680,
1065,
8,
697,
14,
1631,
9,
339,
347,
1104,
63,
69,
838,
6267,
279,
63,
1205,
837,
267,
543,
1145,
14,
571,
63,
1100,
837,
288,
14006,
29,
82,
14,
1224,
360,
9756,
1959,
362,
63,
452,
360,
21031,
297,
1080,
534,
1205,
1959,
1989,
63,
955,
360,
69,
838,
6267,
279,
1959,
1168,
10112,
360,
344,
1673,
69,
838,
6267,
279,
1673,
5570,
63,
2261,
1959,
1065,
8,
697,
14,
1631,
9,
288,
307,
29,
521,
14,
521,
342,
288,
367,
366,
315,
14006,
26,
355,
340,
366,
459,
5570,
63,
2261,
3488,
16,
2733,
6526,
21899,
442,
8,
68,
459,
69,
838,
6267,
279,
2545,
10430,
1105,
10,
2259,
665,
307,
26,
490,
519,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alanljj/Pentaho-reports-for-OpenERP
|
openerp_addon/pentaho_report_selection_sets/report_formulae_definitions.py
|
6
|
6817
|
from datetime import date, datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp.addons.pentaho_reports.java_oe import *
from openerp.tools.translate import _
FTYPE_TIMEDELTA = 'tdel'
FUNCTION_TYPES = OPENERP_DATA_TYPES + [(FTYPE_TIMEDELTA, 'Time Delta')]
# FORMULAE are defined as dictionaries:
#
# key is the formula name to be recognised in the parameter evaluation
#
# value is a dictionary:
# 'type' : type of value this formula returns
# 'type_2m' : true if formula returns a list of values
# 'call' : the actual formula call, with place holders defined as %x
# 'arguments' : a list of dictionaries to define acceptable arguments.
# 'name' : argument name or undefined for positional arguments
# 'types' : list of valid types this argument can accept
# 'lists' : arguments can be lists or not
# 'insert_at' : which place-holder this should be inserted at - if more than one defined for same 'insert_at', they will be comma separated
# 'insert_as' : value will be inserted as a named argument using this as the name - if not defined, then name will be used - if that is undefined, then value only will be inserted
FORMULAE = {'now': {'type': TYPE_TIME,
'call': 'self.localise(cr, uid, datetime.now(), context=context)',
'arguments': [],
},
'today': {'type': TYPE_DATE,
'call': 'self.localise(cr, uid, datetime.now(), context=context).date()',
'arguments': [],
},
'start_of_month': {'type': TYPE_DATE,
'call': 'self.localise(cr, uid, datetime.now(), context=context).date() + relativedelta(day=1)',
'arguments': [],
},
'start_of_year': {'type': TYPE_DATE,
'call': 'self.localise(cr, uid, datetime.now(), context=context).date() + relativedelta(day=1, month=1)',
'arguments': [],
},
'last_dow': {'type': TYPE_DATE,
'call': 'self.localise(cr, uid, datetime.now(), context=context).date() - relativedelta(days=7) + dow_offset(%1)',
'arguments': [{'types': (TYPE_STRING,),
'lists': (False,),
'insert_at': 1,
'insert_as': 'dow_name'
}],
},
'next_dow': {'type': TYPE_DATE,
'call': 'self.localise(cr, uid, datetime.now(), context=context).date() + relativedelta(days=1) + dow_offset(%1)',
'arguments': [{'types': (TYPE_STRING),
'lists': (False,),
'insert_at': 1,
'insert_as': 'dow_name'
}],
},
'date_offset': {'type': FTYPE_TIMEDELTA,
'call': 'relativedelta(%1)',
'arguments': [{'name': 'years',
'types': (TYPE_INTEGER, TYPE_NUMBER),
'lists': (False,),
'insert_at': 1,
},
{'name': 'months',
'types': (TYPE_INTEGER, TYPE_NUMBER),
'lists': (False,),
'insert_at': 1,
},
{'name': 'weeks',
'types': (TYPE_INTEGER, TYPE_NUMBER),
'lists': (False,),
'insert_at': 1,
},
{'name': 'days',
'types': (TYPE_INTEGER, TYPE_NUMBER),
'lists': (False,),
'insert_at': 1,
},
{'name': 'hours',
'types': (TYPE_INTEGER, TYPE_NUMBER),
'lists': (False,),
'insert_at': 1,
},
{'name': 'minutes',
'types': (TYPE_INTEGER, TYPE_NUMBER),
'lists': (False,),
'insert_at': 1,
},
{'name': 'seconds',
'types': (TYPE_INTEGER, TYPE_NUMBER),
'lists': (False,),
'insert_at': 1,
},
{'name': 'microseconds',
'types': (TYPE_INTEGER, TYPE_NUMBER),
'lists': (False,),
'insert_at': 1,
},
],
},
'current_user': {'type': TYPE_INTEGER,
'call': 'uid',
'arguments': [],
}
}
def dow_offset(dow_name=''):
weekday=0
if dow_name.lower() in ('monday', _('monday'), 'mon', 'mo', '0'):
weekday=0
if dow_name.lower() in ('tuesday', _('tuesday'), 'tues', 'tue', 'tu', '1'):
weekday=1
if dow_name.lower() in ('wednesday', _('wednesday'), 'wednes', 'wed', 'we', '2'):
weekday=2
if dow_name.lower() in ('thursday', _('thursday'), 'thurs', 'thu', 'th', '3'):
weekday=3
if dow_name.lower() in ('friday', _('friday'), 'fri', 'fr', '4'):
weekday=4
if dow_name.lower() in ('saturday', _('saturday'), 'satur', 'sat', 'sa', '5'):
weekday=5
if dow_name.lower() in ('sunday', _('sunday'), 'sun', 'su', '6'):
weekday=6
return relativedelta(weekday=weekday)
|
gpl-2.0
|
[
504,
2197,
492,
1434,
12,
2197,
12,
6871,
199,
504,
22208,
14,
32300,
492,
20599,
199,
199,
504,
5166,
14,
10788,
14,
80,
21335,
526,
63,
15629,
14,
6138,
63,
13361,
492,
627,
199,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
38,
2711,
63,
4961,
4424,
6166,
275,
283,
84,
2264,
7,
199,
15476,
63,
7893,
275,
24164,
6758,
63,
3998,
63,
7893,
435,
3842,
38,
2711,
63,
4961,
4424,
6166,
12,
283,
1366,
18464,
502,
5440,
421,
199,
3,
11295,
1293,
12500,
787,
3247,
465,
11196,
26,
199,
3,
199,
3,
259,
790,
365,
314,
15723,
536,
370,
506,
17319,
9096,
315,
314,
2725,
11735,
199,
3,
199,
3,
259,
574,
365,
282,
2600,
26,
199,
3,
263,
283,
466,
7,
520,
730,
402,
574,
642,
15723,
2529,
199,
3,
263,
283,
466,
63,
18,
77,
7,
520,
2549,
340,
15723,
2529,
282,
769,
402,
1338,
199,
3,
263,
283,
1250,
7,
520,
314,
3503,
15723,
1240,
12,
543,
4192,
31976,
3247,
465,
450,
88,
199,
3,
263,
283,
4958,
7,
520,
282,
769,
402,
11196,
370,
5627,
14712,
2368,
14,
199,
3,
12788,
283,
354,
7,
520,
1423,
536,
503,
10942,
367,
11333,
2368,
199,
3,
12788,
283,
1313,
7,
520,
769,
402,
1686,
2943,
642,
1423,
883,
4729,
199,
3,
12788,
283,
6717,
7,
520,
2368,
883,
506,
5548,
503,
440,
199,
3,
12788,
283,
3176,
63,
292,
7,
520,
1314,
4192,
13,
4302,
642,
1077,
506,
11788,
737,
446,
340,
1655,
2419,
1373,
3247,
367,
2011,
283,
3176,
63,
292,
297,
2985,
911,
506,
10029,
11673,
199,
3,
12788,
283,
3176,
63,
305,
7,
520,
574,
911,
506,
11788,
465,
282,
4310,
1423,
1808,
642,
465,
314,
536,
446,
340,
440,
3247,
12,
2066,
536,
911,
506,
1202,
446,
340,
626,
365,
10942,
12,
2066,
574,
1454,
911,
506,
11788,
421,
199,
3516,
1293,
12500,
275,
791,
2131,
356,
791,
466,
356,
11511,
63,
4961,
12,
490,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
3196,
490,
283,
4958,
356,
990,
490,
1660,
288,
283,
8136,
356,
791,
466,
356,
11511,
63,
5390,
12,
1993,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
19633,
1993,
283,
4958,
356,
990,
1993,
1660,
288,
283,
928,
63,
1618,
63,
4482,
356,
791,
466,
356,
11511,
63,
5390,
12,
3044,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
342,
435,
20599,
8,
2977,
29,
17,
3196,
3044,
283,
4958,
356,
990,
3044,
1660,
288,
283,
928,
63,
1618,
63,
3403,
356,
791,
466,
356,
11511,
63,
5390,
12,
2892,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
342,
435,
20599,
8,
2977,
29,
17,
12,
5794,
29,
17,
3196,
2892,
283,
4958,
356,
990,
2892,
1660,
288,
283,
2019,
63,
68,
583,
356,
791,
466,
356,
11511,
63,
5390,
12,
586,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
342,
446,
20599,
8,
4899,
29,
23,
9,
435,
366,
583,
63,
2743,
4042,
17,
3196,
586,
283,
4958,
356,
9016,
1313,
356,
334,
2711,
63,
5353,
4706,
3147,
283,
6717,
356,
334,
797,
4706,
3147,
283,
3176,
63,
292,
356,
413,
12,
3147,
283,
3176,
63,
305,
356,
283,
68,
583,
63,
354,
7,
3147,
19971,
586,
1660,
288,
283,
2184,
63,
68,
583,
356,
791,
466,
356,
11511,
63,
5390,
12,
586,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
342,
435,
20599,
8,
4899,
29,
17,
9,
435,
366,
583,
63,
2743,
4042,
17,
3196,
586,
283,
4958,
356,
9016,
1313,
356,
334,
2711,
63,
5353,
395,
3147,
283,
6717,
356,
334,
797,
4706,
3147,
283,
3176,
63,
292,
356,
413,
12,
3147,
283,
3176,
63,
305,
356,
283,
68,
583,
63,
354,
7,
3147,
19971,
586,
1660,
953,
283,
602,
63,
2743,
356,
791,
466,
356,
481,
2711,
63,
4961,
4424,
6166,
12,
1169,
283,
1250,
356,
283,
32300,
4042,
17,
3196,
1169,
283,
4958,
356,
9016,
354,
356,
283,
18431,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
16745,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
25287,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
4899,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
8419,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
10430,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
4515,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
18144,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
2156,
1169
] |
[
2197,
492,
1434,
12,
2197,
12,
6871,
199,
504,
22208,
14,
32300,
492,
20599,
199,
199,
504,
5166,
14,
10788,
14,
80,
21335,
526,
63,
15629,
14,
6138,
63,
13361,
492,
627,
199,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
38,
2711,
63,
4961,
4424,
6166,
275,
283,
84,
2264,
7,
199,
15476,
63,
7893,
275,
24164,
6758,
63,
3998,
63,
7893,
435,
3842,
38,
2711,
63,
4961,
4424,
6166,
12,
283,
1366,
18464,
502,
5440,
421,
199,
3,
11295,
1293,
12500,
787,
3247,
465,
11196,
26,
199,
3,
199,
3,
259,
790,
365,
314,
15723,
536,
370,
506,
17319,
9096,
315,
314,
2725,
11735,
199,
3,
199,
3,
259,
574,
365,
282,
2600,
26,
199,
3,
263,
283,
466,
7,
520,
730,
402,
574,
642,
15723,
2529,
199,
3,
263,
283,
466,
63,
18,
77,
7,
520,
2549,
340,
15723,
2529,
282,
769,
402,
1338,
199,
3,
263,
283,
1250,
7,
520,
314,
3503,
15723,
1240,
12,
543,
4192,
31976,
3247,
465,
450,
88,
199,
3,
263,
283,
4958,
7,
520,
282,
769,
402,
11196,
370,
5627,
14712,
2368,
14,
199,
3,
12788,
283,
354,
7,
520,
1423,
536,
503,
10942,
367,
11333,
2368,
199,
3,
12788,
283,
1313,
7,
520,
769,
402,
1686,
2943,
642,
1423,
883,
4729,
199,
3,
12788,
283,
6717,
7,
520,
2368,
883,
506,
5548,
503,
440,
199,
3,
12788,
283,
3176,
63,
292,
7,
520,
1314,
4192,
13,
4302,
642,
1077,
506,
11788,
737,
446,
340,
1655,
2419,
1373,
3247,
367,
2011,
283,
3176,
63,
292,
297,
2985,
911,
506,
10029,
11673,
199,
3,
12788,
283,
3176,
63,
305,
7,
520,
574,
911,
506,
11788,
465,
282,
4310,
1423,
1808,
642,
465,
314,
536,
446,
340,
440,
3247,
12,
2066,
536,
911,
506,
1202,
446,
340,
626,
365,
10942,
12,
2066,
574,
1454,
911,
506,
11788,
421,
199,
3516,
1293,
12500,
275,
791,
2131,
356,
791,
466,
356,
11511,
63,
4961,
12,
490,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
3196,
490,
283,
4958,
356,
990,
490,
1660,
288,
283,
8136,
356,
791,
466,
356,
11511,
63,
5390,
12,
1993,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
19633,
1993,
283,
4958,
356,
990,
1993,
1660,
288,
283,
928,
63,
1618,
63,
4482,
356,
791,
466,
356,
11511,
63,
5390,
12,
3044,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
342,
435,
20599,
8,
2977,
29,
17,
3196,
3044,
283,
4958,
356,
990,
3044,
1660,
288,
283,
928,
63,
1618,
63,
3403,
356,
791,
466,
356,
11511,
63,
5390,
12,
2892,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
342,
435,
20599,
8,
2977,
29,
17,
12,
5794,
29,
17,
3196,
2892,
283,
4958,
356,
990,
2892,
1660,
288,
283,
2019,
63,
68,
583,
356,
791,
466,
356,
11511,
63,
5390,
12,
586,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
342,
446,
20599,
8,
4899,
29,
23,
9,
435,
366,
583,
63,
2743,
4042,
17,
3196,
586,
283,
4958,
356,
9016,
1313,
356,
334,
2711,
63,
5353,
4706,
3147,
283,
6717,
356,
334,
797,
4706,
3147,
283,
3176,
63,
292,
356,
413,
12,
3147,
283,
3176,
63,
305,
356,
283,
68,
583,
63,
354,
7,
3147,
19971,
586,
1660,
288,
283,
2184,
63,
68,
583,
356,
791,
466,
356,
11511,
63,
5390,
12,
586,
283,
1250,
356,
283,
277,
14,
1832,
572,
8,
1556,
12,
1747,
12,
2197,
14,
2131,
1062,
1067,
29,
1100,
680,
602,
342,
435,
20599,
8,
4899,
29,
17,
9,
435,
366,
583,
63,
2743,
4042,
17,
3196,
586,
283,
4958,
356,
9016,
1313,
356,
334,
2711,
63,
5353,
395,
3147,
283,
6717,
356,
334,
797,
4706,
3147,
283,
3176,
63,
292,
356,
413,
12,
3147,
283,
3176,
63,
305,
356,
283,
68,
583,
63,
354,
7,
3147,
19971,
586,
1660,
953,
283,
602,
63,
2743,
356,
791,
466,
356,
481,
2711,
63,
4961,
4424,
6166,
12,
1169,
283,
1250,
356,
283,
32300,
4042,
17,
3196,
1169,
283,
4958,
356,
9016,
354,
356,
283,
18431,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
16745,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
25287,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
4899,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
8419,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
10430,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
4515,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
791,
354,
356,
283,
18144,
297,
5644,
283,
1313,
356,
334,
2711,
63,
9596,
12,
11511,
63,
9190,
395,
5644,
283,
6717,
356,
334,
797,
4706,
5644,
283,
3176,
63,
292,
356,
413,
12,
5644,
1660,
5101,
2156,
1169,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of the <ORGANIZATION> nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
import cherrypy
import uuid
import os
from urllib.parse import parse_qs, urlsplit
from ConfigManager.ConfigArgs import ConfigArg, ConfigArgs
from ConfigManager.ConfigManager import ConfigManager
from rf2db.utils import urlutil
from rf2db.parameterparser.ParmParser import booleanparam
_curdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
settings_filename = os.path.join(os.path.dirname(__file__), '..', '..', 'settings.conf')
config_parms = ConfigArgs('authentication',
[ConfigArg('autobypass', abbrev='a', help='True means skip the authentication screen'),
ConfigArg('manualbypass', abbrev='m', help='True means bypass=1 is allowed')
])
settings = ConfigManager(config_parms)
license_html = open(os.path.join(_curdir, '..', 'html', 'license.html')).read()
SESSION_KEY = '_copyright_ack'
CHALLENGE = '_challenge'
FROM_PAGE = '_from_page'
def check_auth(*_, **kwargs):
""" Check whether the user is authorized to use a page that has IHTSDO content. A user can be authorized by:
1. Setting tools.auth.no_auth to True in the class header
2. Carrying the passed session key in the request header
3. Setting autobypass in the settings to "True" (debug mode)
4. Adding a "bypass" parameter to the request header and setting manualbypass in the settings to True
"""
# Don't try if disabled
if booleanparam.v(settings.autobypass, default=False) or kwargs.get('no_auth'):
return
# Check for already authenticated
if cherrypy.session.get(SESSION_KEY) and cherrypy.session.get(SESSION_KEY) == cherrypy.session.get(CHALLENGE):
return
# If the kwargs include a bypass keyword, go on as well
rqst = cherrypy.request.request_line.split()[1]
if booleanparam.v(settings.manualbypass, default=False) and 'bypass' in parse_qs(urlsplit(rqst).query, True):
return
# Not authorized redirect it to the authorization session
cherrypy.session[CHALLENGE] = uuid.uuid4()
cherrypy.session[FROM_PAGE] = rqst
urlutil.redirect('license')
cherrypy.tools.auth = cherrypy.Tool('before_handler', check_auth)
class License(object):
_cp_config = {
'tools.auth.no_auth': True}
@cherrypy.expose
@cherrypy.tools.allow()
def index(self):
return license_html % {'token': cherrypy.session.get(CHALLENGE, 'none')}
@cherrypy.expose
@cherrypy.tools.allow(methods=['POST'])
def submit(self, accept=None, token=None):
if accept and token == str(cherrypy.session.get(CHALLENGE, 'NoN')):
cherrypy.session[SESSION_KEY] = cherrypy.session[CHALLENGE]
raise cherrypy.HTTPRedirect(cherrypy.session.pop(FROM_PAGE))
else:
raise cherrypy.HTTPRedirect("http://ihtsdo.org/license")
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
6171,
12,
10162,
79,
445,
472,
530,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
258,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
258,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
258,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
258,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
258,
11443,
314,
536,
402,
314,
665,
25797,
879,
22800,
30,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
258,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
199,
3,
258,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
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,
221,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
199,
3,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
199,
3,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
646,
13397,
199,
646,
5377,
199,
646,
747,
199,
504,
4011,
14,
1122,
492,
2198,
63,
6177,
12,
29596,
199,
199,
504,
4094,
2988,
14,
2028,
6213,
492,
4094,
6373,
12,
4094,
6213,
199,
504,
4094,
2988,
14,
2028,
2988,
492,
4094,
2988,
199,
504,
17781,
18,
697,
14,
1208,
492,
1166,
1974,
199,
504,
17781,
18,
697,
14,
5329,
2087,
14,
1262,
77,
2842,
492,
5046,
635,
199,
199,
63,
15594,
275,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
747,
14,
515,
14,
3475,
3460,
493,
8964,
199,
1751,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
19155,
19155,
283,
1751,
14,
2190,
358,
199,
199,
888,
63,
28899,
275,
4094,
6213,
360,
11725,
297,
2079,
359,
2028,
6373,
360,
2495,
20605,
297,
2236,
66,
4964,
534,
65,
297,
1720,
534,
549,
4910,
3372,
314,
6299,
6426,
659,
2574,
4094,
6373,
360,
9285,
20605,
297,
2236,
66,
4964,
534,
77,
297,
1720,
534,
549,
4910,
21115,
29,
17,
365,
4370,
358,
2574,
4794,
199,
199,
1751,
275,
4094,
2988,
8,
888,
63,
28899,
9,
199,
1682,
63,
1360,
275,
1551,
8,
736,
14,
515,
14,
904,
1547,
15594,
12,
19155,
283,
1360,
297,
283,
1682,
14,
1360,
11103,
739,
342,
199,
199,
12763,
63,
3078,
275,
2513,
7307,
63,
564,
7,
199,
1244,
1761,
742,
4962,
275,
2513,
13911,
7,
199,
12491,
63,
12898,
275,
2513,
504,
63,
1606,
7,
421,
199,
318,
1104,
63,
1178,
2031,
3131,
1011,
958,
304,
272,
408,
2670,
3775,
314,
922,
365,
18788,
370,
675,
282,
2034,
626,
965,
473,
2148,
24399,
1564,
14,
221,
437,
922,
883,
506,
18788,
701,
26,
267,
413,
14,
13510,
7249,
14,
1178,
14,
889,
63,
1178,
370,
715,
315,
314,
1021,
1406,
398,
499,
14,
14243,
651,
316,
314,
3032,
2351,
790,
315,
314,
1056,
1406,
398,
650,
14,
13510,
2599,
20605,
315,
314,
2202,
370,
298,
549,
2,
334,
1757,
818,
9,
398,
841,
14,
12934,
282,
298,
20605,
2,
2725,
370,
314,
1056,
1406,
436,
4260,
8722,
20605,
315,
314,
2202,
370,
715,
272,
408,
339,
327,
7529,
1133,
862,
340,
6980,
272,
340,
5046,
635,
14,
86,
8,
1751,
14,
2495,
20605,
12,
849,
29,
797,
9,
503,
2074,
14,
362,
360,
889,
63,
1178,
735,
267,
372,
339,
327,
2670,
367,
2575,
15082,
272,
340,
13397,
14,
1730,
14,
362,
8,
12763,
63,
3078,
9,
436,
13397,
14,
1730,
14,
362,
8,
12763,
63,
3078,
9,
508,
13397,
14,
1730,
14,
362,
8,
1244,
1761,
742,
4962,
304,
267,
372,
339,
327,
982,
314,
2074,
2387,
282,
21115,
4252,
12,
2621,
641,
465,
5521,
272,
24659,
270,
275,
13397,
14,
1069,
14,
1069,
63,
604,
14,
1294,
3430,
17,
61,
272,
340,
5046,
635,
14,
86,
8,
1751,
14,
9285,
20605,
12,
849,
29,
797,
9,
436,
283,
20605,
7,
315,
2198,
63,
6177,
8,
29491,
8,
5098,
270,
680,
1131,
12,
715,
304,
267,
372,
339,
327,
2832,
18788,
4660,
652,
370,
314,
13448,
2351,
272,
13397,
14,
1730,
59,
1244,
1761,
742,
4962,
61,
275,
5377,
14,
2580,
20,
342,
272,
13397,
14,
1730,
59,
12491,
63,
12898,
61,
275,
24659,
270,
272,
1166,
1974,
14,
4876,
360,
1682,
358,
421,
199,
23438,
14,
2537,
14,
1178,
275,
13397,
14,
5157,
360,
5182,
63,
2232,
297,
1104,
63,
1178,
9,
421,
199,
533,
844,
8,
785,
304,
272,
485,
1850,
63,
888,
275,
469,
267,
283,
2537,
14,
1178,
14,
889,
63,
1178,
356,
715,
93,
339,
768,
23438,
14,
20586,
272,
768,
23438,
14,
2537,
14,
3306,
342,
272,
347,
1478,
8,
277,
304,
267,
372,
4190,
63,
1360,
450,
791,
1418,
356,
13397,
14,
1730,
14,
362,
8,
1244,
1761,
742,
4962,
12,
283,
3592,
21004,
339,
768,
23438,
14,
20586,
272,
768,
23438,
14,
2537,
14,
3306,
8,
2474,
2968,
4030,
1105,
272,
347,
11482,
8,
277,
12,
4729,
29,
403,
12,
1526,
29,
403,
304,
267,
340,
4729,
436,
1526,
508,
620,
8,
23438,
14,
1730,
14,
362,
8,
1244,
1761,
742,
4962,
12,
283,
1944,
46,
8109,
288
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
6171,
12,
10162,
79,
445,
472,
530,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
258,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
258,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
258,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
258,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
258,
11443,
314,
536,
402,
314,
665,
25797,
879,
22800,
30,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
258,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
199,
3,
258,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
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,
221,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
199,
3,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
199,
3,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
646,
13397,
199,
646,
5377,
199,
646,
747,
199,
504,
4011,
14,
1122,
492,
2198,
63,
6177,
12,
29596,
199,
199,
504,
4094,
2988,
14,
2028,
6213,
492,
4094,
6373,
12,
4094,
6213,
199,
504,
4094,
2988,
14,
2028,
2988,
492,
4094,
2988,
199,
504,
17781,
18,
697,
14,
1208,
492,
1166,
1974,
199,
504,
17781,
18,
697,
14,
5329,
2087,
14,
1262,
77,
2842,
492,
5046,
635,
199,
199,
63,
15594,
275,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
747,
14,
515,
14,
3475,
3460,
493,
8964,
199,
1751,
63,
1501,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
19155,
19155,
283,
1751,
14,
2190,
358,
199,
199,
888,
63,
28899,
275,
4094,
6213,
360,
11725,
297,
2079,
359,
2028,
6373,
360,
2495,
20605,
297,
2236,
66,
4964,
534,
65,
297,
1720,
534,
549,
4910,
3372,
314,
6299,
6426,
659,
2574,
4094,
6373,
360,
9285,
20605,
297,
2236,
66,
4964,
534,
77,
297,
1720,
534,
549,
4910,
21115,
29,
17,
365,
4370,
358,
2574,
4794,
199,
199,
1751,
275,
4094,
2988,
8,
888,
63,
28899,
9,
199,
1682,
63,
1360,
275,
1551,
8,
736,
14,
515,
14,
904,
1547,
15594,
12,
19155,
283,
1360,
297,
283,
1682,
14,
1360,
11103,
739,
342,
199,
199,
12763,
63,
3078,
275,
2513,
7307,
63,
564,
7,
199,
1244,
1761,
742,
4962,
275,
2513,
13911,
7,
199,
12491,
63,
12898,
275,
2513,
504,
63,
1606,
7,
421,
199,
318,
1104,
63,
1178,
2031,
3131,
1011,
958,
304,
272,
408,
2670,
3775,
314,
922,
365,
18788,
370,
675,
282,
2034,
626,
965,
473,
2148,
24399,
1564,
14,
221,
437,
922,
883,
506,
18788,
701,
26,
267,
413,
14,
13510,
7249,
14,
1178,
14,
889,
63,
1178,
370,
715,
315,
314,
1021,
1406,
398,
499,
14,
14243,
651,
316,
314,
3032,
2351,
790,
315,
314,
1056,
1406,
398,
650,
14,
13510,
2599,
20605,
315,
314,
2202,
370,
298,
549,
2,
334,
1757,
818,
9,
398,
841,
14,
12934,
282,
298,
20605,
2,
2725,
370,
314,
1056,
1406,
436,
4260,
8722,
20605,
315,
314,
2202,
370,
715,
272,
408,
339,
327,
7529,
1133,
862,
340,
6980,
272,
340,
5046,
635,
14,
86,
8,
1751,
14,
2495,
20605,
12,
849,
29,
797,
9,
503,
2074,
14,
362,
360,
889,
63,
1178,
735,
267,
372,
339,
327,
2670,
367,
2575,
15082,
272,
340,
13397,
14,
1730,
14,
362,
8,
12763,
63,
3078,
9,
436,
13397,
14,
1730,
14,
362,
8,
12763,
63,
3078,
9,
508,
13397,
14,
1730,
14,
362,
8,
1244,
1761,
742,
4962,
304,
267,
372,
339,
327,
982,
314,
2074,
2387,
282,
21115,
4252,
12,
2621,
641,
465,
5521,
272,
24659,
270,
275,
13397,
14,
1069,
14,
1069,
63,
604,
14,
1294,
3430,
17,
61,
272,
340,
5046,
635,
14,
86,
8,
1751,
14,
9285,
20605,
12,
849,
29,
797,
9,
436,
283,
20605,
7,
315,
2198,
63,
6177,
8,
29491,
8,
5098,
270,
680,
1131,
12,
715,
304,
267,
372,
339,
327,
2832,
18788,
4660,
652,
370,
314,
13448,
2351,
272,
13397,
14,
1730,
59,
1244,
1761,
742,
4962,
61,
275,
5377,
14,
2580,
20,
342,
272,
13397,
14,
1730,
59,
12491,
63,
12898,
61,
275,
24659,
270,
272,
1166,
1974,
14,
4876,
360,
1682,
358,
421,
199,
23438,
14,
2537,
14,
1178,
275,
13397,
14,
5157,
360,
5182,
63,
2232,
297,
1104,
63,
1178,
9,
421,
199,
533,
844,
8,
785,
304,
272,
485,
1850,
63,
888,
275,
469,
267,
283,
2537,
14,
1178,
14,
889,
63,
1178,
356,
715,
93,
339,
768,
23438,
14,
20586,
272,
768,
23438,
14,
2537,
14,
3306,
342,
272,
347,
1478,
8,
277,
304,
267,
372,
4190,
63,
1360,
450,
791,
1418,
356,
13397,
14,
1730,
14,
362,
8,
1244,
1761,
742,
4962,
12,
283,
3592,
21004,
339,
768,
23438,
14,
20586,
272,
768,
23438,
14,
2537,
14,
3306,
8,
2474,
2968,
4030,
1105,
272,
347,
11482,
8,
277,
12,
4729,
29,
403,
12,
1526,
29,
403,
304,
267,
340,
4729,
436,
1526,
508,
620,
8,
23438,
14,
1730,
14,
362,
8,
1244,
1761,
742,
4962,
12,
283,
1944,
46,
8109,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
Akrog/cinder
|
cinder/tests/fake_hp_client_exceptions.py
|
32
|
3077
|
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
# 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.
#
"""Fake HP client exceptions to use when mocking HP clients."""
class UnsupportedVersion(Exception):
"""Unsupported version of the client."""
pass
class ClientException(Exception):
"""The base exception class for these fake exceptions."""
_error_code = None
_error_desc = None
_error_ref = None
_debug1 = None
_debug2 = None
def __init__(self, error=None):
if error:
if 'code' in error:
self._error_code = error['code']
if 'desc' in error:
self._error_desc = error['desc']
if 'ref' in error:
self._error_ref = error['ref']
if 'debug1' in error:
self._debug1 = error['debug1']
if 'debug2' in error:
self._debug2 = error['debug2']
def get_code(self):
return self._error_code
def get_description(self):
return self._error_desc
def get_ref(self):
return self._error_ref
def __str__(self):
formatted_string = self.message
if self.http_status:
formatted_string += " (HTTP %s)" % self.http_status
if self._error_code:
formatted_string += " %s" % self._error_code
if self._error_desc:
formatted_string += " - %s" % self._error_desc
if self._error_ref:
formatted_string += " - %s" % self._error_ref
if self._debug1:
formatted_string += " (1: '%s')" % self._debug1
if self._debug2:
formatted_string += " (2: '%s')" % self._debug2
return formatted_string
class HTTPConflict(Exception):
http_status = 409
message = "Conflict"
def __init__(self, error=None):
if error and 'message' in error:
self._error_desc = error['message']
def get_description(self):
return self._error_desc
class HTTPNotFound(Exception):
http_status = 404
message = "Not found"
class HTTPForbidden(ClientException):
http_status = 403
message = "Forbidden"
class HTTPBadRequest(Exception):
http_status = 400
message = "Bad request"
class HTTPServerError(Exception):
http_status = 500
message = "Error"
def __init__(self, error=None):
if error and 'message' in error:
self._error_desc = error['message']
def get_description(self):
return self._error_desc
|
apache-2.0
|
[
3,
334,
67,
9,
1898,
6927,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
259,
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,
3,
199,
624,
8249,
869,
48,
1890,
4967,
370,
675,
1380,
1683,
316,
869,
48,
13431,
1041,
421,
199,
533,
19022,
3353,
8,
1726,
304,
272,
408,
12647,
1015,
402,
314,
1890,
1041,
272,
986,
421,
199,
533,
6810,
1726,
8,
1726,
304,
272,
408,
1918,
1300,
1919,
1021,
367,
3520,
4026,
4967,
1041,
272,
485,
705,
63,
600,
275,
488,
272,
485,
705,
63,
3257,
275,
488,
272,
485,
705,
63,
1121,
275,
488,
339,
485,
1757,
17,
275,
488,
272,
485,
1757,
18,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1125,
29,
403,
304,
267,
340,
1125,
26,
288,
340,
283,
600,
7,
315,
1125,
26,
355,
291,
423,
705,
63,
600,
275,
1125,
459,
600,
418,
288,
340,
283,
3257,
7,
315,
1125,
26,
355,
291,
423,
705,
63,
3257,
275,
1125,
459,
3257,
418,
288,
340,
283,
1121,
7,
315,
1125,
26,
355,
291,
423,
705,
63,
1121,
275,
1125,
459,
1121,
418,
953,
340,
283,
1757,
17,
7,
315,
1125,
26,
355,
291,
423,
1757,
17,
275,
1125,
459,
1757,
17,
418,
288,
340,
283,
1757,
18,
7,
315,
1125,
26,
355,
291,
423,
1757,
18,
275,
1125,
459,
1757,
18,
418,
339,
347,
664,
63,
600,
8,
277,
304,
267,
372,
291,
423,
705,
63,
600,
339,
347,
664,
63,
1802,
8,
277,
304,
267,
372,
291,
423,
705,
63,
3257,
339,
347,
664,
63,
1121,
8,
277,
304,
267,
372,
291,
423,
705,
63,
1121,
339,
347,
636,
495,
721,
277,
304,
267,
7871,
63,
875,
275,
291,
14,
1188,
267,
340,
291,
14,
1014,
63,
1205,
26,
288,
7871,
63,
875,
847,
298,
334,
2856,
450,
83,
2924,
450,
291,
14,
1014,
63,
1205,
267,
340,
291,
423,
705,
63,
600,
26,
288,
7871,
63,
875,
847,
298,
450,
83,
2,
450,
291,
423,
705,
63,
600,
267,
340,
291,
423,
705,
63,
3257,
26,
288,
7871,
63,
875,
847,
298,
446,
450,
83,
2,
450,
291,
423,
705,
63,
3257,
267,
340,
291,
423,
705,
63,
1121,
26,
288,
7871,
63,
875,
847,
298,
446,
450,
83,
2,
450,
291,
423,
705,
63,
1121,
398,
340,
291,
423,
1757,
17,
26,
288,
7871,
63,
875,
847,
298,
334,
17,
26,
1543,
83,
19124,
450,
291,
423,
1757,
17,
398,
340,
291,
423,
1757,
18,
26,
288,
7871,
63,
875,
847,
298,
334,
18,
26,
1543,
83,
19124,
450,
291,
423,
1757,
18,
398,
372,
7871,
63,
875,
421,
199,
533,
3101,
15919,
8,
1726,
304,
272,
1455,
63,
1205,
275,
21292,
272,
1245,
275,
298,
15919,
2,
339,
347,
636,
826,
721,
277,
12,
1125,
29,
403,
304,
267,
340,
1125,
436,
283,
1188,
7,
315,
1125,
26,
288,
291,
423,
705,
63,
3257,
275,
1125,
459,
1188,
418,
339,
347,
664,
63,
1802,
8,
277,
304,
267,
372,
291,
423,
705,
63,
3257,
421,
199,
533,
3101,
4667,
8,
1726,
304,
272,
1455,
63,
1205,
275,
7901,
272,
1245,
275,
298,
1763,
1911,
2,
421,
199,
533,
3101,
17454,
8,
3041,
1726,
304,
272,
1455,
63,
1205,
275,
13269,
272,
1245,
275,
298,
17454,
2,
421,
199,
533,
3101,
12380,
8,
1726,
304,
272,
1455,
63,
1205,
275,
8290,
272,
1245,
275,
298,
5725,
1056,
2,
421,
199,
533,
3101,
17692,
8,
1726,
304,
272,
1455,
63,
1205,
275,
6891,
272,
1245,
275,
298,
547,
2,
339,
347,
636,
826,
721,
277,
12,
1125,
29,
403,
304,
267,
340,
1125,
436,
283,
1188,
7,
315,
1125,
26,
288,
291,
423,
705,
63,
3257,
275,
1125,
459,
1188,
418,
339,
347,
664,
63,
1802,
8,
277,
304,
267,
372,
291,
423,
705,
63,
3257,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
334,
67,
9,
1898,
6927,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
259,
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,
3,
199,
624,
8249,
869,
48,
1890,
4967,
370,
675,
1380,
1683,
316,
869,
48,
13431,
1041,
421,
199,
533,
19022,
3353,
8,
1726,
304,
272,
408,
12647,
1015,
402,
314,
1890,
1041,
272,
986,
421,
199,
533,
6810,
1726,
8,
1726,
304,
272,
408,
1918,
1300,
1919,
1021,
367,
3520,
4026,
4967,
1041,
272,
485,
705,
63,
600,
275,
488,
272,
485,
705,
63,
3257,
275,
488,
272,
485,
705,
63,
1121,
275,
488,
339,
485,
1757,
17,
275,
488,
272,
485,
1757,
18,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1125,
29,
403,
304,
267,
340,
1125,
26,
288,
340,
283,
600,
7,
315,
1125,
26,
355,
291,
423,
705,
63,
600,
275,
1125,
459,
600,
418,
288,
340,
283,
3257,
7,
315,
1125,
26,
355,
291,
423,
705,
63,
3257,
275,
1125,
459,
3257,
418,
288,
340,
283,
1121,
7,
315,
1125,
26,
355,
291,
423,
705,
63,
1121,
275,
1125,
459,
1121,
418,
953,
340,
283,
1757,
17,
7,
315,
1125,
26,
355,
291,
423,
1757,
17,
275,
1125,
459,
1757,
17,
418,
288,
340,
283,
1757,
18,
7,
315,
1125,
26,
355,
291,
423,
1757,
18,
275,
1125,
459,
1757,
18,
418,
339,
347,
664,
63,
600,
8,
277,
304,
267,
372,
291,
423,
705,
63,
600,
339,
347,
664,
63,
1802,
8,
277,
304,
267,
372,
291,
423,
705,
63,
3257,
339,
347,
664,
63,
1121,
8,
277,
304,
267,
372,
291,
423,
705,
63,
1121,
339,
347,
636,
495,
721,
277,
304,
267,
7871,
63,
875,
275,
291,
14,
1188,
267,
340,
291,
14,
1014,
63,
1205,
26,
288,
7871,
63,
875,
847,
298,
334,
2856,
450,
83,
2924,
450,
291,
14,
1014,
63,
1205,
267,
340,
291,
423,
705,
63,
600,
26,
288,
7871,
63,
875,
847,
298,
450,
83,
2,
450,
291,
423,
705,
63,
600,
267,
340,
291,
423,
705,
63,
3257,
26,
288,
7871,
63,
875,
847,
298,
446,
450,
83,
2,
450,
291,
423,
705,
63,
3257,
267,
340,
291,
423,
705,
63,
1121,
26,
288,
7871,
63,
875,
847,
298,
446,
450,
83,
2,
450,
291,
423,
705,
63,
1121,
398,
340,
291,
423,
1757,
17,
26,
288,
7871,
63,
875,
847,
298,
334,
17,
26,
1543,
83,
19124,
450,
291,
423,
1757,
17,
398,
340,
291,
423,
1757,
18,
26,
288,
7871,
63,
875,
847,
298,
334,
18,
26,
1543,
83,
19124,
450,
291,
423,
1757,
18,
398,
372,
7871,
63,
875,
421,
199,
533,
3101,
15919,
8,
1726,
304,
272,
1455,
63,
1205,
275,
21292,
272,
1245,
275,
298,
15919,
2,
339,
347,
636,
826,
721,
277,
12,
1125,
29,
403,
304,
267,
340,
1125,
436,
283,
1188,
7,
315,
1125,
26,
288,
291,
423,
705,
63,
3257,
275,
1125,
459,
1188,
418,
339,
347,
664,
63,
1802,
8,
277,
304,
267,
372,
291,
423,
705,
63,
3257,
421,
199,
533,
3101,
4667,
8,
1726,
304,
272,
1455,
63,
1205,
275,
7901,
272,
1245,
275,
298,
1763,
1911,
2,
421,
199,
533,
3101,
17454,
8,
3041,
1726,
304,
272,
1455,
63,
1205,
275,
13269,
272,
1245,
275,
298,
17454,
2,
421,
199,
533,
3101,
12380,
8,
1726,
304,
272,
1455,
63,
1205,
275,
8290,
272,
1245,
275,
298,
5725,
1056,
2,
421,
199,
533,
3101,
17692,
8,
1726,
304,
272,
1455,
63,
1205,
275,
6891,
272,
1245,
275,
298,
547,
2,
339,
347,
636,
826,
721,
277,
12,
1125,
29,
403,
304,
267,
340,
1125,
436,
283,
1188,
7,
315,
1125,
26,
288,
291,
423,
705,
63,
3257,
275,
1125,
459,
1188,
418,
339,
347,
664,
63,
1802,
8,
277,
304,
267,
372,
291,
423,
705,
63,
3257,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
syscoin/syscoin2
|
test/functional/feature_dersig.py
|
1
|
5813
|
#!/usr/bin/env python3
# Copyright (c) 2015-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test BIP66 (DER SIG).
Test that the DERSIG soft-fork activates at (regtest) height 1251.
"""
from test_framework.blocktools import create_coinbase, create_block, create_transaction
from test_framework.messages import msg_block
from test_framework.mininode import P2PInterface
from test_framework.script import CScript
from test_framework.test_framework import SyscoinTestFramework
from test_framework.util import (
assert_equal,
)
DERSIG_HEIGHT = 1251
# A canonical signature consists of:
# <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>
def unDERify(tx):
"""
Make the signature in vin 0 of a tx non-DER-compliant,
by adding padding after the S-value.
"""
scriptSig = CScript(tx.vin[0].scriptSig)
newscript = []
for i in scriptSig:
if (len(newscript) == 0):
newscript.append(i[0:-1] + b'\0' + i[-1:])
else:
newscript.append(i)
tx.vin[0].scriptSig = CScript(newscript)
class BIP66Test(SyscoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.extra_args = [[
'-whitelist=noban@127.0.0.1',
'-par=1', # Use only one script thread to get the exact log msg for testing
]]
self.setup_clean_chain = True
self.rpc_timeout = 240
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def test_dersig_info(self, *, is_active):
assert_equal(self.nodes[0].getblockchaininfo()['softforks']['bip66'],
{
"active": is_active,
"height": DERSIG_HEIGHT,
"type": "buried",
},
)
def run_test(self):
self.nodes[0].add_p2p_connection(P2PInterface())
self.test_dersig_info(is_active=False)
self.log.info("Mining %d blocks", DERSIG_HEIGHT - 2)
self.coinbase_txids = [self.nodes[0].getblock(b)['tx'][0] for b in self.nodes[0].generate(DERSIG_HEIGHT - 2)]
self.nodeaddress = self.nodes[0].getnewaddress()
self.log.info("Test that a transaction with non-DER signature can still appear in a block")
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[0],
self.nodeaddress, amount=1.0)
unDERify(spendtx)
spendtx.rehash()
tip = self.nodes[0].getbestblockhash()
block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
block = create_block(int(tip, 16), create_coinbase(DERSIG_HEIGHT - 1), block_time)
block.set_base_version(2)
block.vtx.append(spendtx)
block.hashMerkleRoot = block.calc_merkle_root()
block.rehash()
block.solve()
self.test_dersig_info(is_active=False) # Not active as of current tip and next block does not need to obey rules
self.nodes[0].p2p.send_and_ping(msg_block(block))
self.test_dersig_info(is_active=True) # Not active as of current tip, but next block must obey rules
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
self.log.info("Test that blocks must now be at least version 3")
tip = block.sha256
block_time += 1
block = create_block(tip, create_coinbase(DERSIG_HEIGHT), block_time)
block.set_base_version(2)
block.rehash()
block.solve()
with self.nodes[0].assert_debug_log(expected_msgs=['{}, bad-version(0x00010002)'.format(block.hash)]):
self.nodes[0].p2p.send_and_ping(msg_block(block))
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
self.nodes[0].p2p.sync_with_ping()
self.log.info("Test that transactions with non-DER signatures cannot appear in a block")
block.set_base_version(3)
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[1],
self.nodeaddress, amount=1.0)
unDERify(spendtx)
spendtx.rehash()
# First we show that this tx is valid except for DERSIG by getting it
# rejected from the mempool for exactly that reason.
assert_equal(
[{'txid': spendtx.hash, 'allowed': False, 'reject-reason': 'non-mandatory-script-verify-flag (Non-canonical DER signature)'}],
self.nodes[0].testmempoolaccept(rawtxs=[spendtx.serialize().hex()], maxfeerate=0)
)
# Now we verify that a block with this transaction is also invalid.
block.vtx.append(spendtx)
block.hashMerkleRoot = block.calc_merkle_root()
block.rehash()
block.solve()
with self.nodes[0].assert_debug_log(expected_msgs=['CheckInputScripts on {} failed with non-mandatory-script-verify-flag (Non-canonical DER signature)'.format(block.vtx[-1].hash)]):
self.nodes[0].p2p.send_and_ping(msg_block(block))
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
self.nodes[0].p2p.sync_with_ping()
self.log.info("Test that a version 3 block with a DERSIG-compliant transaction is accepted")
block.vtx[1] = create_transaction(self.nodes[0], self.coinbase_txids[1], self.nodeaddress, amount=1.0)
block.hashMerkleRoot = block.calc_merkle_root()
block.rehash()
block.solve()
self.test_dersig_info(is_active=True) # Not active as of current tip, but next block must obey rules
self.nodes[0].p2p.send_and_ping(msg_block(block))
self.test_dersig_info(is_active=True) # Active as of current tip
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)
if __name__ == '__main__':
BIP66Test().main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6900,
13,
14982,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
774,
699,
1772,
1272,
334,
11733,
15522,
680,
199,
199,
774,
626,
314,
577,
3960,
1277,
11620,
13,
11796,
6633,
86,
2335,
737,
334,
1135,
396,
9,
4569,
413,
12140,
14,
199,
624,
199,
199,
504,
511,
63,
4857,
14,
1457,
2537,
492,
1218,
63,
30488,
12,
1218,
63,
1457,
12,
1218,
63,
5945,
199,
504,
511,
63,
4857,
14,
3431,
492,
1499,
63,
1457,
199,
504,
511,
63,
4857,
14,
827,
15993,
492,
510,
18,
48,
4267,
199,
504,
511,
63,
4857,
14,
1579,
492,
24682,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
28766,
9061,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
334,
272,
702,
63,
1452,
12,
199,
9,
199,
199,
36,
3960,
1277,
63,
13509,
275,
413,
12140,
421,
199,
3,
437,
11358,
4955,
18581,
402,
26,
199,
3,
665,
1216,
30,
665,
2923,
822,
30,
665,
996,
30,
665,
552,
820,
30,
665,
50,
30,
665,
996,
30,
665,
552,
428,
30,
665,
51,
30,
665,
2227,
466,
30,
199,
318,
625,
11733,
2021,
8,
2347,
304,
272,
408,
272,
4155,
314,
4955,
315,
373,
262,
378,
402,
282,
4773,
2222,
13,
11733,
13,
863,
22676,
12,
272,
701,
7791,
6273,
2410,
314,
428,
13,
585,
14,
272,
408,
272,
2884,
11575,
275,
24682,
8,
2347,
14,
11908,
59,
16,
1055,
1579,
11575,
9,
272,
892,
1579,
275,
942,
272,
367,
284,
315,
2884,
11575,
26,
267,
340,
334,
552,
8,
1222,
1579,
9,
508,
378,
304,
288,
892,
1579,
14,
740,
8,
73,
59,
16,
6809,
17,
61,
435,
330,
1154,
16,
7,
435,
284,
1988,
17,
5728,
267,
587,
26,
288,
892,
1579,
14,
740,
8,
73,
9,
272,
4773,
14,
11908,
59,
16,
1055,
1579,
11575,
275,
24682,
8,
1222,
1579,
9,
421,
199,
533,
699,
1772,
1272,
774,
8,
11319,
9061,
26203,
304,
272,
347,
663,
63,
396,
63,
1162,
8,
277,
304,
267,
291,
14,
1507,
63,
2415,
275,
413,
267,
291,
14,
2911,
63,
589,
275,
3474,
288,
2475,
14189,
29,
889,
13206,
32,
4195,
14,
16,
14,
16,
14,
17,
297,
288,
2475,
462,
29,
17,
297,
221,
327,
3645,
1454,
1373,
2884,
2462,
370,
664,
314,
5835,
943,
1499,
367,
5343,
267,
1622,
61,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
715,
267,
291,
14,
4354,
63,
2593,
275,
21883,
339,
347,
3372,
63,
396,
63,
692,
63,
4752,
63,
578,
8,
277,
304,
267,
291,
14,
2759,
63,
692,
63,
889,
63,
13892,
342,
339,
347,
511,
63,
424,
4093,
63,
815,
8,
277,
12,
9889,
365,
63,
2682,
304,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
17785,
4429,
815,
12047,
4617,
509,
6080,
2545,
27566,
1272,
995,
288,
469,
355,
298,
2682,
582,
365,
63,
2682,
12,
355,
298,
3333,
582,
577,
3960,
1277,
63,
13509,
12,
355,
298,
466,
582,
298,
66,
2302,
379,
401,
288,
1660,
267,
776,
339,
347,
1255,
63,
396,
8,
277,
304,
267,
291,
14,
2415,
59,
16,
1055,
525,
63,
80,
18,
80,
63,
2105,
8,
48,
18,
48,
4267,
1012,
398,
291,
14,
396,
63,
424,
4093,
63,
815,
8,
374,
63,
2682,
29,
797,
9,
398,
291,
14,
793,
14,
815,
480,
4649,
316,
450,
68,
5664,
401,
577,
3960,
1277,
63,
13509,
446,
499,
9,
267,
291,
14,
30488,
63,
2347,
1580,
275,
359,
277,
14,
2415,
59,
16,
1055,
17785,
8,
66,
11820,
2347,
3488,
16,
61,
367,
330,
315,
291,
14,
2415,
59,
16,
1055,
4208,
8,
36,
3960,
1277,
63,
13509,
446,
499,
1874,
267,
291,
14,
932,
1562,
275,
291,
14,
2415,
59,
16,
1055,
21102,
342,
398,
291,
14,
793,
14,
815,
480,
774,
626,
282,
6008,
543,
2222,
13,
11733,
4955,
883,
5139,
7468,
315,
282,
1853,
531,
398,
26387,
2347,
275,
1218,
63,
5945,
8,
277,
14,
2415,
59,
16,
467,
291,
14,
30488,
63,
2347,
1580,
59,
16,
467,
355,
291,
14,
932,
1562,
12,
5982,
29,
17,
14,
16,
9,
267,
625,
11733,
2021,
8,
31340,
2347,
9,
267,
26387,
2347,
14,
264,
2227,
342,
398,
19201,
275,
291,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
342,
267,
1853,
63,
521,
275,
291,
14,
2415,
59,
16,
1055,
17785,
1291,
8,
8996,
11820,
13106,
521,
418,
435,
413,
267,
1853,
275,
1218,
63,
1457,
8,
442,
8,
8996,
12,
3193,
395,
1218,
63,
30488,
8,
36,
3960,
1277,
63,
13509,
446,
413,
395,
1853,
63,
521,
9,
267,
1853,
14,
409,
63,
1095,
63,
1023,
8,
18,
9,
267,
1853,
14,
26784,
14,
740,
8,
31340,
2347,
9,
267,
1853,
14,
2227,
16797,
23572,
6405,
275,
1853,
14,
8104,
63,
2626,
23572,
63,
1231,
342,
267,
1853,
14,
264,
2227,
342,
267,
1853,
14,
11356,
342,
398,
291,
14,
396,
63,
424,
4093,
63,
815,
8,
374,
63,
2682,
29,
797,
9,
221,
327,
2832,
4702,
465,
402,
1453,
19201,
436,
2163,
1853,
1630,
440,
1929,
370,
312,
32236,
4713,
267,
291,
14,
2415,
59,
16,
1055,
80,
18,
80,
14,
2254,
63,
460,
63,
4073,
8,
1328,
63,
1457,
8,
1457,
430,
267,
291,
14,
396,
63,
424,
4093,
63,
815,
8,
374,
63,
2682,
29,
549,
9,
221,
327,
2832,
4702,
465,
402,
1453,
19201,
12,
1325,
2163,
1853,
1471,
312,
32236,
4713,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
1853,
14,
2227,
9,
398,
291,
14,
793,
14,
815,
480,
774,
626,
5664,
1471,
3063,
506,
737,
5210,
1015,
650,
531,
267,
19201,
275,
1853,
14,
4835,
3912,
267,
1853,
63,
521,
847,
413,
267,
1853,
275,
1218,
63,
1457,
8,
8996,
12,
1218,
63,
30488,
8,
36,
3960,
1277,
63,
13509,
395,
1853,
63,
521,
9,
267,
1853,
14,
409,
63,
1095,
63,
1023,
8,
18,
9,
267,
1853,
14,
264
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6900,
13,
14982,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
774,
699,
1772,
1272,
334,
11733,
15522,
680,
199,
199,
774,
626,
314,
577,
3960,
1277,
11620,
13,
11796,
6633,
86,
2335,
737,
334,
1135,
396,
9,
4569,
413,
12140,
14,
199,
624,
199,
199,
504,
511,
63,
4857,
14,
1457,
2537,
492,
1218,
63,
30488,
12,
1218,
63,
1457,
12,
1218,
63,
5945,
199,
504,
511,
63,
4857,
14,
3431,
492,
1499,
63,
1457,
199,
504,
511,
63,
4857,
14,
827,
15993,
492,
510,
18,
48,
4267,
199,
504,
511,
63,
4857,
14,
1579,
492,
24682,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
28766,
9061,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
334,
272,
702,
63,
1452,
12,
199,
9,
199,
199,
36,
3960,
1277,
63,
13509,
275,
413,
12140,
421,
199,
3,
437,
11358,
4955,
18581,
402,
26,
199,
3,
665,
1216,
30,
665,
2923,
822,
30,
665,
996,
30,
665,
552,
820,
30,
665,
50,
30,
665,
996,
30,
665,
552,
428,
30,
665,
51,
30,
665,
2227,
466,
30,
199,
318,
625,
11733,
2021,
8,
2347,
304,
272,
408,
272,
4155,
314,
4955,
315,
373,
262,
378,
402,
282,
4773,
2222,
13,
11733,
13,
863,
22676,
12,
272,
701,
7791,
6273,
2410,
314,
428,
13,
585,
14,
272,
408,
272,
2884,
11575,
275,
24682,
8,
2347,
14,
11908,
59,
16,
1055,
1579,
11575,
9,
272,
892,
1579,
275,
942,
272,
367,
284,
315,
2884,
11575,
26,
267,
340,
334,
552,
8,
1222,
1579,
9,
508,
378,
304,
288,
892,
1579,
14,
740,
8,
73,
59,
16,
6809,
17,
61,
435,
330,
1154,
16,
7,
435,
284,
1988,
17,
5728,
267,
587,
26,
288,
892,
1579,
14,
740,
8,
73,
9,
272,
4773,
14,
11908,
59,
16,
1055,
1579,
11575,
275,
24682,
8,
1222,
1579,
9,
421,
199,
533,
699,
1772,
1272,
774,
8,
11319,
9061,
26203,
304,
272,
347,
663,
63,
396,
63,
1162,
8,
277,
304,
267,
291,
14,
1507,
63,
2415,
275,
413,
267,
291,
14,
2911,
63,
589,
275,
3474,
288,
2475,
14189,
29,
889,
13206,
32,
4195,
14,
16,
14,
16,
14,
17,
297,
288,
2475,
462,
29,
17,
297,
221,
327,
3645,
1454,
1373,
2884,
2462,
370,
664,
314,
5835,
943,
1499,
367,
5343,
267,
1622,
61,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
715,
267,
291,
14,
4354,
63,
2593,
275,
21883,
339,
347,
3372,
63,
396,
63,
692,
63,
4752,
63,
578,
8,
277,
304,
267,
291,
14,
2759,
63,
692,
63,
889,
63,
13892,
342,
339,
347,
511,
63,
424,
4093,
63,
815,
8,
277,
12,
9889,
365,
63,
2682,
304,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
17785,
4429,
815,
12047,
4617,
509,
6080,
2545,
27566,
1272,
995,
288,
469,
355,
298,
2682,
582,
365,
63,
2682,
12,
355,
298,
3333,
582,
577,
3960,
1277,
63,
13509,
12,
355,
298,
466,
582,
298,
66,
2302,
379,
401,
288,
1660,
267,
776,
339,
347,
1255,
63,
396,
8,
277,
304,
267,
291,
14,
2415,
59,
16,
1055,
525,
63,
80,
18,
80,
63,
2105,
8,
48,
18,
48,
4267,
1012,
398,
291,
14,
396,
63,
424,
4093,
63,
815,
8,
374,
63,
2682,
29,
797,
9,
398,
291,
14,
793,
14,
815,
480,
4649,
316,
450,
68,
5664,
401,
577,
3960,
1277,
63,
13509,
446,
499,
9,
267,
291,
14,
30488,
63,
2347,
1580,
275,
359,
277,
14,
2415,
59,
16,
1055,
17785,
8,
66,
11820,
2347,
3488,
16,
61,
367,
330,
315,
291,
14,
2415,
59,
16,
1055,
4208,
8,
36,
3960,
1277,
63,
13509,
446,
499,
1874,
267,
291,
14,
932,
1562,
275,
291,
14,
2415,
59,
16,
1055,
21102,
342,
398,
291,
14,
793,
14,
815,
480,
774,
626,
282,
6008,
543,
2222,
13,
11733,
4955,
883,
5139,
7468,
315,
282,
1853,
531,
398,
26387,
2347,
275,
1218,
63,
5945,
8,
277,
14,
2415,
59,
16,
467,
291,
14,
30488,
63,
2347,
1580,
59,
16,
467,
355,
291,
14,
932,
1562,
12,
5982,
29,
17,
14,
16,
9,
267,
625,
11733,
2021,
8,
31340,
2347,
9,
267,
26387,
2347,
14,
264,
2227,
342,
398,
19201,
275,
291,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
342,
267,
1853,
63,
521,
275,
291,
14,
2415,
59,
16,
1055,
17785,
1291,
8,
8996,
11820,
13106,
521,
418,
435,
413,
267,
1853,
275,
1218,
63,
1457,
8,
442,
8,
8996,
12,
3193,
395,
1218,
63,
30488,
8,
36,
3960,
1277,
63,
13509,
446,
413,
395,
1853,
63,
521,
9,
267,
1853,
14,
409,
63,
1095,
63,
1023,
8,
18,
9,
267,
1853,
14,
26784,
14,
740,
8,
31340,
2347,
9,
267,
1853,
14,
2227,
16797,
23572,
6405,
275,
1853,
14,
8104,
63,
2626,
23572,
63,
1231,
342,
267,
1853,
14,
264,
2227,
342,
267,
1853,
14,
11356,
342,
398,
291,
14,
396,
63,
424,
4093,
63,
815,
8,
374,
63,
2682,
29,
797,
9,
221,
327,
2832,
4702,
465,
402,
1453,
19201,
436,
2163,
1853,
1630,
440,
1929,
370,
312,
32236,
4713,
267,
291,
14,
2415,
59,
16,
1055,
80,
18,
80,
14,
2254,
63,
460,
63,
4073,
8,
1328,
63,
1457,
8,
1457,
430,
267,
291,
14,
396,
63,
424,
4093,
63,
815,
8,
374,
63,
2682,
29,
549,
9,
221,
327,
2832,
4702,
465,
402,
1453,
19201,
12,
1325,
2163,
1853,
1471,
312,
32236,
4713,
267,
702,
63,
1452,
8,
277,
14,
2415,
59,
16,
1055,
362,
7010,
25848,
1062,
1853,
14,
2227,
9,
398,
291,
14,
793,
14,
815,
480,
774,
626,
5664,
1471,
3063,
506,
737,
5210,
1015,
650,
531,
267,
19201,
275,
1853,
14,
4835,
3912,
267,
1853,
63,
521,
847,
413,
267,
1853,
275,
1218,
63,
1457,
8,
8996,
12,
1218,
63,
30488,
8,
36,
3960,
1277,
63,
13509,
395,
1853,
63,
521,
9,
267,
1853,
14,
409,
63,
1095,
63,
1023,
8,
18,
9,
267,
1853,
14,
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,
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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
] |
anubhavvardhan/qutip
|
qutip/tests/test_mcsolve.py
|
4
|
20286
|
# This file is part of QuTiP: Quantum Toolbox in Python.
#
# Copyright (c) 2011 and later, Paul D. Nation and Robert J. Johansson.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. 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.
#
# 3. Neither the name of the QuTiP: Quantum Toolbox in Python nor the names
# of its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###############################################################################
import numpy as np
from numpy.testing import assert_equal, run_module_suite, assert_
import unittest
from qutip import *
from qutip import _version2int
# find Cython if it exists
try:
import Cython
except:
Cython_found = 0
else:
Cython_found = 1
kappa = 0.2
def sqrt_kappa(t, args):
return np.sqrt(kappa)
def sqrt_kappa2(t, args):
return np.sqrt(kappa * np.exp(-t))
def const_H1_coeff(t, args):
return 0.0
# average error for failure
mc_error = 5e-2 # 5%
ntraj = 750
def test_MCNoCollExpt():
"Monte-carlo: Constant H with no collapse ops (expect)"
error = 1e-8
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
c_op_list = []
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj)
expt = mcdata.expect[0]
actual_answer = 9.0 * np.ones(len(tlist))
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
def test_MCNoCollStates():
"Monte-carlo: Constant H with no collapse ops (states)"
error = 1e-8
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
c_op_list = []
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [], ntraj=ntraj)
states = mcdata.states
expt = expect(a.dag() * a, states)
actual_answer = 9.0 * np.ones(len(tlist))
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
def test_MCNoCollExpectStates():
"Monte-carlo: Constant H with no collapse ops (expect and states)"
error = 1e-8
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
c_op_list = []
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj,
options=Options(store_states=True))
actual_answer = 9.0 * np.ones(len(tlist))
expt = mcdata.expect[0]
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
assert_(len(mcdata.states) == len(tlist))
assert_(isinstance(mcdata.states[0], Qobj))
expt = expect(a.dag() * a, mcdata.states)
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
def test_MCNoCollStrExpt():
"Monte-carlo: Constant H (str format) with no collapse ops (expect)"
error = 1e-8
N = 10 # number of basis states to consider
a = destroy(N)
H = [a.dag() * a, [a.dag() * a, 'c']]
psi0 = basis(N, 9) # initial state
c_op_list = []
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], args={'c': 0.0},
ntraj=ntraj)
expt = mcdata.expect[0]
actual_answer = 9.0 * np.ones(len(tlist))
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
def test_MCNoCollFuncExpt():
"Monte-carlo: Constant H (func format) with no collapse ops (expect)"
error = 1e-8
N = 10 # number of basis states to consider
a = destroy(N)
H = [a.dag() * a, [a.dag() * a, const_H1_coeff]]
psi0 = basis(N, 9) # initial state
c_op_list = []
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj)
expt = mcdata.expect[0]
actual_answer = 9.0 * np.ones(len(tlist))
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
def test_MCNoCollStrStates():
"Monte-carlo: Constant H (str format) with no collapse ops (states)"
error = 1e-8
N = 10 # number of basis states to consider
a = destroy(N)
H = [a.dag() * a, [a.dag() * a, 'c']]
psi0 = basis(N, 9) # initial state
c_op_list = []
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [], args={'c': 0.0})
states = mcdata.states
expt = expect(a.dag() * a, states)
actual_answer = 9.0 * np.ones(len(tlist))
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
def test_MCNoCollFuncStates():
"Monte-carlo: Constant H (func format) with no collapse ops (states)"
error = 1e-8
N = 10 # number of basis states to consider
a = destroy(N)
H = [a.dag() * a, [a.dag() * a, const_H1_coeff]]
psi0 = basis(N, 9) # initial state
c_op_list = []
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [], ntraj=ntraj)
states = mcdata.states
expt = expect(a.dag() * a, states)
actual_answer = 9.0 * np.ones(len(tlist))
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
def test_MCCollapseTimesOperators():
"Monte-carlo: Check for stored collapse operators and times"
N = 10
kappa = 5.0
times = np.linspace(0, 10, 100)
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9)
c_ops = [np.sqrt(kappa) * a, np.sqrt(kappa) * a]
result = mcsolve(H, psi0, times, c_ops, [], ntraj=1)
assert_(len(result.col_times[0]) > 0)
assert_(len(result.col_which) == len(result.col_times))
assert_(set(result.col_which[0]) == {0, 1})
def test_MCSimpleConst():
"Monte-carlo: Constant H with constant collapse"
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [np.sqrt(kappa) * a]
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj)
expt = mcdata.expect[0]
actual_answer = 9.0 * np.exp(-kappa * tlist)
avg_diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(avg_diff < mc_error, True)
def test_MCSimpleConstStates():
"Monte-carlo: Constant H with constant collapse (states)"
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [np.sqrt(kappa) * a]
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [], ntraj=ntraj,
options=Options(average_states=True))
assert_(len(mcdata.states) == len(tlist))
assert_(isinstance(mcdata.states[0], Qobj))
expt = expect(a.dag() * a, mcdata.states)
actual_answer = 9.0 * np.exp(-kappa * tlist)
avg_diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(avg_diff < mc_error, True)
def test_MCSimpleConstExptStates():
"Monte-carlo: Constant H with constant collapse (states)"
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [np.sqrt(kappa) * a]
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj,
options=Options(average_states=True, store_states=True))
actual_answer = 9.0 * np.exp(-kappa * tlist)
expt1 = mcdata.expect[0]
avg_diff = np.mean(abs(actual_answer - expt1) / actual_answer)
assert_equal(avg_diff < mc_error, True)
assert_(len(mcdata.states) == len(tlist))
assert_(isinstance(mcdata.states[0], Qobj))
expt2 = expect(a.dag() * a, mcdata.states)
avg_diff = np.mean(abs(actual_answer - expt2) / actual_answer)
assert_equal(avg_diff < mc_error, True)
def test_MCSimpleSingleCollapse():
"""Monte-carlo: Constant H with single collapse operator"""
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [np.sqrt(kappa) * a]
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj)
expt = mcdata.expect[0]
actual_answer = 9.0 * np.exp(-kappa * tlist)
avg_diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(avg_diff < mc_error, True)
def test_MCSimpleSingleExpect():
"""Monte-carlo: Constant H with single expect operator"""
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [np.sqrt(kappa) * a]
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj)
expt = mcdata.expect[0]
actual_answer = 9.0 * np.exp(-kappa * tlist)
avg_diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(avg_diff < mc_error, True)
def test_MCSimpleConstFunc():
"Monte-carlo: Collapse terms constant (func format)"
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [[a, sqrt_kappa]]
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj)
expt = mcdata.expect[0]
actual_answer = 9.0 * np.exp(-kappa * tlist)
avg_diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(avg_diff < mc_error, True)
@unittest.skipIf(_version2int(Cython.__version__) < _version2int('0.14') or
Cython_found == 0, 'Cython not found or version too low.')
def test_MCSimpleConstStr():
"Monte-carlo: Collapse terms constant (str format)"
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [[a, 'sqrt(k)']]
args = {'k': kappa}
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], args=args,
ntraj=ntraj)
expt = mcdata.expect[0]
actual_answer = 9.0 * np.exp(-kappa * tlist)
avg_diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(avg_diff < mc_error, True)
def test_MCTDFunc():
"Monte-carlo: Time-dependent H (func format)"
error = 5e-2
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [[a, sqrt_kappa2]]
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=ntraj)
expt = mcdata.expect[0]
actual_answer = 9.0 * np.exp(-kappa * (1.0 - np.exp(-tlist)))
diff = np.mean(abs(actual_answer - expt) / actual_answer)
assert_equal(diff < error, True)
@unittest.skipIf(_version2int(Cython.__version__) < _version2int('0.14') or
Cython_found == 0, 'Cython not found or version too low.')
def test_TDStr():
"Monte-carlo: Time-dependent H (str format)"
error = 5e-2
N = 10 # number of basis states to consider
a = destroy(N)
H = a.dag() * a
psi0 = basis(N, 9) # initial state
kappa = 0.2 # coupling to oscillator
c_op_list = [[a, 'sqrt(k*exp(-t))']]
args = {'k': kappa}
tlist = np.linspace(0, 10, 100)
mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], args=args,
ntraj=ntraj)
expt = mcdata.expect[0]
actual = 9.0 * np.exp(-kappa * (1.0 - np.exp(-tlist)))
diff = np.mean(abs(actual - expt) / actual)
assert_equal(diff < error, True)
def test_mc_dtypes1():
"Monte-carlo: check for correct dtypes (average_states=True)"
# set system parameters
kappa = 2.0 # mirror coupling
gamma = 0.2 # spontaneous emission rate
g = 1 # atom/cavity coupling strength
wc = 0 # cavity frequency
w0 = 0 # atom frequency
wl = 0 # driving frequency
E = 0.5 # driving amplitude
N = 5 # number of cavity energy levels (0->3 Fock states)
tlist = np.linspace(0, 10, 5) # times for expectation values
# construct Hamiltonian
ida = qeye(N)
idatom = qeye(2)
a = tensor(destroy(N), idatom)
sm = tensor(ida, sigmam())
H = (w0 - wl) * sm.dag() * sm + (wc - wl) * a.dag() * a + \
1j * g * (a.dag() * sm - sm.dag() * a) + E * (a.dag() + a)
# collapse operators
C1 = np.sqrt(2 * kappa) * a
C2 = np.sqrt(gamma) * sm
C1dC1 = C1.dag() * C1
C2dC2 = C2.dag() * C2
# intial state
psi0 = tensor(basis(N, 0), basis(2, 1))
opts = Options(average_expect=True)
data = mcsolve(
H, psi0, tlist, [C1, C2], [C1dC1, C2dC2, a], ntraj=5, options=opts)
assert_equal(isinstance(data.expect[0][1], float), True)
assert_equal(isinstance(data.expect[1][1], float), True)
assert_equal(isinstance(data.expect[2][1], complex), True)
def test_mc_dtypes2():
"Monte-carlo: check for correct dtypes (average_states=False)"
# set system parameters
kappa = 2.0 # mirror coupling
gamma = 0.2 # spontaneous emission rate
g = 1 # atom/cavity coupling strength
wc = 0 # cavity frequency
w0 = 0 # atom frequency
wl = 0 # driving frequency
E = 0.5 # driving amplitude
N = 5 # number of cavity energy levels (0->3 Fock states)
tlist = np.linspace(0, 10, 5) # times for expectation values
# construct Hamiltonian
ida = qeye(N)
idatom = qeye(2)
a = tensor(destroy(N), idatom)
sm = tensor(ida, sigmam())
H = (w0 - wl) * sm.dag() * sm + (wc - wl) * a.dag() * a + \
1j * g * (a.dag() * sm - sm.dag() * a) + E * (a.dag() + a)
# collapse operators
C1 = np.sqrt(2 * kappa) * a
C2 = np.sqrt(gamma) * sm
C1dC1 = C1.dag() * C1
C2dC2 = C2.dag() * C2
# intial state
psi0 = tensor(basis(N, 0), basis(2, 1))
opts = Options(average_expect=False)
data = mcsolve(
H, psi0, tlist, [C1, C2], [C1dC1, C2dC2, a], ntraj=5, options=opts)
assert_equal(isinstance(data.expect[0][0][1], float), True)
assert_equal(isinstance(data.expect[0][1][1], float), True)
assert_equal(isinstance(data.expect[0][2][1], complex), True)
def test_mc_seed_reuse():
"Monte-carlo: check reusing seeds"
N0 = 6
N1 = 6
N2 = 6
# damping rates
gamma0 = 0.1
gamma1 = 0.4
gamma2 = 0.1
alpha = np.sqrt(2) # initial coherent state param for mode 0
tlist = np.linspace(0, 10, 2)
ntraj = 500 # number of trajectories
# define operators
a0 = tensor(destroy(N0), qeye(N1), qeye(N2))
a1 = tensor(qeye(N0), destroy(N1), qeye(N2))
a2 = tensor(qeye(N0), qeye(N1), destroy(N2))
# number operators for each mode
num0 = a0.dag() * a0
num1 = a1.dag() * a1
num2 = a2.dag() * a2
# dissipative operators for zero-temp. baths
C0 = np.sqrt(2.0 * gamma0) * a0
C1 = np.sqrt(2.0 * gamma1) * a1
C2 = np.sqrt(2.0 * gamma2) * a2
# initial state: coherent mode 0 & vacuum for modes #1 & #2
psi0 = tensor(coherent(N0, alpha), basis(N1, 0), basis(N2, 0))
# trilinear Hamiltonian
H = 1j * (a0 * a1.dag() * a2.dag() - a0.dag() * a1 * a2)
# run Monte-Carlo
data1 = mcsolve(H, psi0, tlist, [C0, C1, C2], [num0, num1, num2],
ntraj=ntraj)
data2 = mcsolve(H, psi0, tlist, [C0, C1, C2], [num0, num1, num2],
ntraj=ntraj, options=Options(seeds=data1.seeds))
for k in range(ntraj):
assert_equal(np.allclose(data1.col_times[k],data2.col_times[k]), True)
assert_equal(np.allclose(data1.col_which[k],data2.col_which[k]), True)
def test_mc_seed_noreuse():
"Monte-carlo: check not reusing seeds"
N0 = 6
N1 = 6
N2 = 6
# damping rates
gamma0 = 0.1
gamma1 = 0.4
gamma2 = 0.1
alpha = np.sqrt(2) # initial coherent state param for mode 0
tlist = np.linspace(0, 10, 2)
ntraj = 500 # number of trajectories
# define operators
a0 = tensor(destroy(N0), qeye(N1), qeye(N2))
a1 = tensor(qeye(N0), destroy(N1), qeye(N2))
a2 = tensor(qeye(N0), qeye(N1), destroy(N2))
# number operators for each mode
num0 = a0.dag() * a0
num1 = a1.dag() * a1
num2 = a2.dag() * a2
# dissipative operators for zero-temp. baths
C0 = np.sqrt(2.0 * gamma0) * a0
C1 = np.sqrt(2.0 * gamma1) * a1
C2 = np.sqrt(2.0 * gamma2) * a2
# initial state: coherent mode 0 & vacuum for modes #1 & #2
psi0 = tensor(coherent(N0, alpha), basis(N1, 0), basis(N2, 0))
# trilinear Hamiltonian
H = 1j * (a0 * a1.dag() * a2.dag() - a0.dag() * a1 * a2)
# run Monte-Carlo
data1 = mcsolve(H, psi0, tlist, [C0, C1, C2], [num0, num1, num2],
ntraj=ntraj)
data2 = mcsolve(H, psi0, tlist, [C0, C1, C2], [num0, num1, num2],
ntraj=ntraj)
diff_flag = False
for k in range(ntraj):
if len(data1.col_times[k]) != len(data2.col_times[k]):
diff_flag = 1
break
else:
if not np.allclose(data1.col_which[k],data2.col_which[k]):
diff_flag = 1
break
assert_equal(diff_flag, 1)
def test_mc_ntraj_list():
"Monte-carlo: list of trajectories"
N = 5
a = destroy(N)
H = a.dag()*a # Simple oscillator Hamiltonian
psi0 = basis(N, 1) # Initial Fock state with one photon
kappa = 1.0/0.129 # Coupling rate to heat bath
nth = 0.063 # Temperature with <n>=0.063
# Build collapse operators for the thermal bath
c_ops = []
c_ops.append(np.sqrt(kappa * (1 + nth)) * a)
c_ops.append(np.sqrt(kappa * nth) * a.dag())
ntraj = [1, 5, 15, 904] # number of MC trajectories
tlist = np.linspace(0, 0.8, 100)
mc = mcsolve(H, psi0, tlist, c_ops, [a.dag()*a], ntraj)
assert_equal(len(mc.expect), 4)
def test_mc_functd_sum():
"Monte-carlo: Test for #490"
psi0 = (basis(2,0) + basis(2,1)).unit()
H0 = sigmax()
H1 = sigmay()
H2 = sigmaz()
def H1_coeff(t,args):
return t-1
def H2_coeff(t,args):
return -t
h_t = [H0,[H1, H1_coeff],
[H2, H2_coeff]]
ntraj = 1
tlist = np.linspace(0, 3, 10)
medata = mesolve(h_t, psi0, tlist, [], [], args = {})
mcdata = mcsolve(h_t, psi0, tlist, [], [], ntraj = ntraj, args = {})
assert_(max([(medata.states[k]-mcdata.states[k]).norm() for k in range(10)]) < 1e-5)
if __name__ == "__main__":
run_module_suite()
|
bsd-3-clause
|
[
3,
961,
570,
365,
1777,
402,
5843,
22731,
48,
26,
5843,
867,
453,
15650,
1977,
315,
2018,
14,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
7760,
436,
2945,
12,
28574,
577,
14,
653,
425,
436,
6848,
12504,
1603,
14,
7135,
19262,
385,
265,
14,
199,
3,
259,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
259,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
259,
7647,
26,
199,
3,
199,
3,
259,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
755,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
259,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
259,
650,
14,
11443,
314,
536,
402,
314,
5843,
22731,
48,
26,
5843,
867,
453,
15650,
1977,
315,
2018,
6590,
314,
1561,
199,
3,
755,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
755,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
259,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
259,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
259,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
199,
3,
259,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
259,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
259,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
259,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
259,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
259,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
259,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
259,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
11490,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
1452,
12,
1255,
63,
578,
63,
5768,
12,
702,
63,
199,
646,
2882,
199,
504,
2173,
8996,
492,
627,
199,
504,
2173,
8996,
492,
485,
1023,
18,
442,
199,
199,
3,
2342,
26741,
340,
652,
3495,
199,
893,
26,
272,
492,
26741,
199,
2590,
26,
272,
26741,
63,
4214,
275,
378,
199,
2836,
26,
272,
26741,
63,
4214,
275,
413,
199,
199,
31918,
275,
378,
14,
18,
421,
199,
318,
7452,
63,
31918,
8,
84,
12,
1249,
304,
272,
372,
980,
14,
5079,
8,
31918,
9,
421,
199,
318,
7452,
63,
31918,
18,
8,
84,
12,
1249,
304,
272,
372,
980,
14,
5079,
8,
31918,
627,
980,
14,
1474,
2801,
84,
430,
421,
199,
318,
950,
63,
40,
17,
63,
8903,
8,
84,
12,
1249,
304,
272,
372,
378,
14,
16,
199,
199,
3,
8095,
1125,
367,
5988,
199,
5466,
63,
705,
275,
959,
69,
13,
18,
221,
327,
959,
5,
199,
343,
345,
74,
275,
1520,
1400,
421,
199,
318,
511,
63,
7608,
1944,
2001,
76,
920,
541,
837,
272,
298,
6671,
266,
13,
7007,
320,
26,
19991,
869,
543,
949,
24311,
4156,
334,
4921,
2924,
272,
1125,
275,
413,
69,
13,
24,
272,
653,
275,
1616,
221,
327,
1329,
402,
5597,
6363,
370,
11201,
272,
282,
275,
11972,
8,
46,
9,
272,
869,
275,
282,
14,
7406,
342,
627,
282,
272,
20742,
16,
275,
5597,
8,
46,
12,
1749,
9,
221,
327,
2536,
1174,
272,
286,
63,
411,
63,
513,
275,
942,
272,
307,
513,
275,
980,
14,
11649,
8,
16,
12,
1616,
12,
2948,
9,
272,
333,
15892,
275,
333,
1259,
3344,
8,
40,
12,
20742,
16,
12,
307,
513,
12,
286,
63,
411,
63,
513,
12,
359,
65,
14,
7406,
342,
627,
282,
467,
302,
22788,
29,
343,
345,
74,
9,
272,
444,
541,
275,
333,
15892,
14,
4921,
59,
16,
61,
272,
3503,
63,
5934,
275,
1749,
14,
16,
627,
980,
14,
4548,
8,
552,
8,
84,
513,
430,
272,
3915,
275,
980,
14,
3670,
8,
2101,
8,
6514,
63,
5934,
446,
444,
541,
9,
1182,
3503,
63,
5934,
9,
272,
702,
63,
1452,
8,
3028,
665,
1125,
12,
715,
9,
421,
199,
318,
511,
63,
7608,
1944,
2001,
76,
18010,
837,
272,
298,
6671,
266,
13,
7007,
320,
26,
19991,
869,
543,
949,
24311,
4156,
334,
4981,
2924,
272,
1125,
275,
413,
69,
13,
24,
272,
653,
275,
1616,
221,
327,
1329,
402,
5597,
6363,
370,
11201,
272,
282,
275,
11972,
8,
46,
9,
272,
869,
275,
282,
14,
7406,
342,
627,
282,
272,
20742,
16,
275,
5597,
8,
46,
12,
1749,
9,
221,
327,
2536,
1174,
272,
286,
63,
411,
63,
513,
275,
942,
272,
307,
513,
275,
980,
14,
11649,
8,
16,
12,
1616,
12,
2948,
9,
272,
333,
15892,
275,
333,
1259,
3344,
8,
40,
12,
20742,
16,
12,
307,
513,
12,
286,
63,
411,
63,
513,
12,
990,
302,
22788,
29,
343,
345,
74,
9,
272,
6363,
275,
333,
15892,
14,
4981,
272,
444,
541,
275,
4282,
8,
65,
14,
7406,
342,
627,
282,
12,
6363,
9,
272,
3503,
63,
5934,
275,
1749,
14,
16,
627,
980,
14,
4548,
8,
552,
8,
84,
513,
430,
272,
3915,
275,
980,
14,
3670,
8,
2101,
8,
6514,
63,
5934,
446,
444,
541,
9,
1182,
3503,
63,
5934,
9,
272,
702,
63,
1452,
8,
3028,
665,
1125,
12,
715,
9,
421,
199,
318,
511,
63,
7608,
1944,
2001,
76,
13495,
18010,
837,
272,
298,
6671,
266,
13,
7007,
320,
26,
19991,
869,
543,
949,
24311,
4156,
334,
4921,
436,
6363,
2924,
272,
1125,
275,
413,
69,
13,
24,
272,
653,
275,
1616,
221,
327,
1329,
402,
5597,
6363,
370,
11201,
272,
282,
275,
11972,
8,
46,
9,
272
] |
[
961,
570,
365,
1777,
402,
5843,
22731,
48,
26,
5843,
867,
453,
15650,
1977,
315,
2018,
14,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
7760,
436,
2945,
12,
28574,
577,
14,
653,
425,
436,
6848,
12504,
1603,
14,
7135,
19262,
385,
265,
14,
199,
3,
259,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
259,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
259,
7647,
26,
199,
3,
199,
3,
259,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
755,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
259,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
259,
650,
14,
11443,
314,
536,
402,
314,
5843,
22731,
48,
26,
5843,
867,
453,
15650,
1977,
315,
2018,
6590,
314,
1561,
199,
3,
755,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
755,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
259,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
259,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
259,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
199,
3,
259,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
259,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
259,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
259,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
259,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
259,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
259,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
259,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
11490,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
1452,
12,
1255,
63,
578,
63,
5768,
12,
702,
63,
199,
646,
2882,
199,
504,
2173,
8996,
492,
627,
199,
504,
2173,
8996,
492,
485,
1023,
18,
442,
199,
199,
3,
2342,
26741,
340,
652,
3495,
199,
893,
26,
272,
492,
26741,
199,
2590,
26,
272,
26741,
63,
4214,
275,
378,
199,
2836,
26,
272,
26741,
63,
4214,
275,
413,
199,
199,
31918,
275,
378,
14,
18,
421,
199,
318,
7452,
63,
31918,
8,
84,
12,
1249,
304,
272,
372,
980,
14,
5079,
8,
31918,
9,
421,
199,
318,
7452,
63,
31918,
18,
8,
84,
12,
1249,
304,
272,
372,
980,
14,
5079,
8,
31918,
627,
980,
14,
1474,
2801,
84,
430,
421,
199,
318,
950,
63,
40,
17,
63,
8903,
8,
84,
12,
1249,
304,
272,
372,
378,
14,
16,
199,
199,
3,
8095,
1125,
367,
5988,
199,
5466,
63,
705,
275,
959,
69,
13,
18,
221,
327,
959,
5,
199,
343,
345,
74,
275,
1520,
1400,
421,
199,
318,
511,
63,
7608,
1944,
2001,
76,
920,
541,
837,
272,
298,
6671,
266,
13,
7007,
320,
26,
19991,
869,
543,
949,
24311,
4156,
334,
4921,
2924,
272,
1125,
275,
413,
69,
13,
24,
272,
653,
275,
1616,
221,
327,
1329,
402,
5597,
6363,
370,
11201,
272,
282,
275,
11972,
8,
46,
9,
272,
869,
275,
282,
14,
7406,
342,
627,
282,
272,
20742,
16,
275,
5597,
8,
46,
12,
1749,
9,
221,
327,
2536,
1174,
272,
286,
63,
411,
63,
513,
275,
942,
272,
307,
513,
275,
980,
14,
11649,
8,
16,
12,
1616,
12,
2948,
9,
272,
333,
15892,
275,
333,
1259,
3344,
8,
40,
12,
20742,
16,
12,
307,
513,
12,
286,
63,
411,
63,
513,
12,
359,
65,
14,
7406,
342,
627,
282,
467,
302,
22788,
29,
343,
345,
74,
9,
272,
444,
541,
275,
333,
15892,
14,
4921,
59,
16,
61,
272,
3503,
63,
5934,
275,
1749,
14,
16,
627,
980,
14,
4548,
8,
552,
8,
84,
513,
430,
272,
3915,
275,
980,
14,
3670,
8,
2101,
8,
6514,
63,
5934,
446,
444,
541,
9,
1182,
3503,
63,
5934,
9,
272,
702,
63,
1452,
8,
3028,
665,
1125,
12,
715,
9,
421,
199,
318,
511,
63,
7608,
1944,
2001,
76,
18010,
837,
272,
298,
6671,
266,
13,
7007,
320,
26,
19991,
869,
543,
949,
24311,
4156,
334,
4981,
2924,
272,
1125,
275,
413,
69,
13,
24,
272,
653,
275,
1616,
221,
327,
1329,
402,
5597,
6363,
370,
11201,
272,
282,
275,
11972,
8,
46,
9,
272,
869,
275,
282,
14,
7406,
342,
627,
282,
272,
20742,
16,
275,
5597,
8,
46,
12,
1749,
9,
221,
327,
2536,
1174,
272,
286,
63,
411,
63,
513,
275,
942,
272,
307,
513,
275,
980,
14,
11649,
8,
16,
12,
1616,
12,
2948,
9,
272,
333,
15892,
275,
333,
1259,
3344,
8,
40,
12,
20742,
16,
12,
307,
513,
12,
286,
63,
411,
63,
513,
12,
990,
302,
22788,
29,
343,
345,
74,
9,
272,
6363,
275,
333,
15892,
14,
4981,
272,
444,
541,
275,
4282,
8,
65,
14,
7406,
342,
627,
282,
12,
6363,
9,
272,
3503,
63,
5934,
275,
1749,
14,
16,
627,
980,
14,
4548,
8,
552,
8,
84,
513,
430,
272,
3915,
275,
980,
14,
3670,
8,
2101,
8,
6514,
63,
5934,
446,
444,
541,
9,
1182,
3503,
63,
5934,
9,
272,
702,
63,
1452,
8,
3028,
665,
1125,
12,
715,
9,
421,
199,
318,
511,
63,
7608,
1944,
2001,
76,
13495,
18010,
837,
272,
298,
6671,
266,
13,
7007,
320,
26,
19991,
869,
543,
949,
24311,
4156,
334,
4921,
436,
6363,
2924,
272,
1125,
275,
413,
69,
13,
24,
272,
653,
275,
1616,
221,
327,
1329,
402,
5597,
6363,
370,
11201,
272,
282,
275,
11972,
8,
46,
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,
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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
] |
skavulya/spark-tk
|
python/sparktk/models/timeseries/arimax.py
|
14
|
15211
|
# vim: set encoding=utf-8
# Copyright (c) 2016 Intel Corporation
#
# 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.
#
"""
ARIMAX (Autoregressive Integrated Moving Average with Exogeneous Variables) Model
"""
from sparktk.loggers import log_load; log_load(__name__); del log_load
from sparktk.lazyloader import implicit
from sparktk.propobj import PropertiesObject
def train(frame, ts_column, x_columns, p, d, q, x_max_lag, include_original_x=True, include_intercept=True, init_params=None):
"""
Creates Autoregressive Integrated Moving Average with Explanatory Variables (ARIMAX) Model from the specified
time series values.
Given a time series, fits an non-seasonal Autoregressive Integrated Moving Average with Explanatory Variables
(ARIMAX) model of order (p, d, q) where p represents the autoregression terms, d represents the order of differencing
and q represents the moving average error terms. X_max_lag represents the maximum lag order for exogenous variables.
If include_original_x is true, the model is fitted with an original exogenous variables. If includeIntercept is true,
the model is fitted with an intercept.
Parameters
----------
:param frame: (Frame) Frame used for training.
:param ts_column: (str) Name of the column that contains the time series values.
:param x_columns: (List(str)) Names of the column(s) that contain the values of exogenous regressors.
:param p: (int) Autoregressive order
:param d: (int) Differencing order
:param q: (int) Moving average order
:param x_max_lag: (int) The maximum lag order for exogenous variables.
:param include_original_x: (Optional(boolean)) If True, the model is fit with an original exogenous variables
(intercept for exogenous variables). Default is True.
:param include_intercept: (Optional(boolean)) If True, the model is fit with an intercept. Default is True.
:param init_params: (Optional(List[float]) A set of user provided initial parameters for optimization. If the
list is empty (default), initialized using Hannan-Rissanen algorithm. If provided, order
of parameter should be: intercept term, AR parameters (in increasing order of lag), MA
parameters (in increasing order of lag) and paramteres for exogenous variables (in
increasing order of lag).
:return: (ArimaxModel) Trained ARIMAX model
"""
if not isinstance(ts_column, basestring):
raise TypeError("'ts_column' should be a string (name of the column that has the timeseries value).")
if not isinstance(x_columns, list) or not all(isinstance(c, str) for c in x_columns):
raise TypeError("'x_columns' should be a list of strings (names of the exogenous columns).")
elif len(x_columns) <= 0:
raise ValueError("'x_columns' should not be empty.")
if not isinstance(p, int):
raise TypeError("'p' parameter must be an integer.")
if not isinstance(d, int):
raise TypeError("'d' parameter must be an integer.")
if not isinstance(q, int):
raise TypeError("'q' parameter must be an integer.")
if not isinstance(x_max_lag, int):
raise TypeError("'x_max_lag' should be an integer.")
if not isinstance(include_original_x, bool):
raise TypeError("'include_original_x' parameter must be a boolean")
if not isinstance(include_intercept, bool):
raise TypeError("'include_intercept' parameter must be a boolean")
if init_params is not None:
if not isinstance(init_params, list):
raise TypeError("'init_params' parameter must be a list")
tc = frame._tc
_scala_obj = _get_scala_obj(tc)
scala_x_columns = tc.jutils.convert.to_scala_vector_string(x_columns)
scala_init_params = tc.jutils.convert.to_scala_option_list_double(init_params)
scala_model = _scala_obj.train(frame._scala, ts_column, scala_x_columns, p, d, q, x_max_lag, include_original_x, include_intercept, scala_init_params)
return ArimaxModel(tc, scala_model)
def load(path, tc=implicit):
"""load ARIMAXModel from given path"""
if tc is implicit:
implicit.error("tc")
return tc.load(path, ArimaxModel)
def _get_scala_obj(tc):
"""Gets reference to the ARIMAX model scala object"""
return tc.sc._jvm.org.trustedanalytics.sparktk.models.timeseries.arimax.ArimaxModel
class ArimaxModel(PropertiesObject):
"""
A trained ARIMAX model.
Example
-------
Data from Lichman, M. (2013). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml].
Irvine, CA: University of California, School of Information and Computer Science.
Consider the following model trained and tested on the sample data set in *frame* 'frame'.
The frame has five columns where "CO_GT" is the time series value and "C6H6_GT", "PT08_S2_NMHC"
and "T" are exogenous inputs.
CO_GT - True hourly averaged concentration CO in mg/m^3
C6H6_GT - True hourly averaged Benzene concentration in microg/m^3
PT08_S2_NMHC - Titania hourly averaged sensor response (nominally NMHC targeted)
T - Temperature in C
<hide>
>>> schema = [("CO_GT", float),("C6H6_GT", float),("PT08_S2_NMHC", float),("T", float)]
>>> frame = tc.frame.create([[2.6, 11.9, 1046.0, 13.6],
... [2.0, 9.4, 955.0, 13.3],
... [2.2, 9.0, 939.0, 11.9],
... [2.2, 9.2, 948.0, 11.0],
... [1.6, 6.5, 836.0, 11.2],
... [1.2, 4.7, 750.0, 11.2],
... [1.2, 3.6, 690.0, 11.3],
... [1.0, 3.3, 672.0, 10.7],
... [2.9, 2.3, 609.0, 10.7],
... [2.6, 1.7, 561.0, 10.3],
... [2.0, 1.3, 527.0, 10.1],
... [2.7, 1.1, 512.0, 11.0],
... [2.7, 1.6, 553.0, 10.5],
... [1.1, 3.2, 667.0, 10.2],
... [2.0, 8.0, 900.0, 10.8],
... [2.2, 9.5, 960.0, 10.5],
... [2.7, 6.3, 827.0, 10.8],
... [2.5, 5.0, 762.0, 10.5],
... [2.6, 5.2, 774.0, 9.5],
... [2.9, 7.3, 869.0, 8.3]],
... schema=schema, validate_schema=True)
-etc-
</hide>
>>> frame.inspect()
[#] CO_GT C6H6_GT PT08_S2_NMHC T
=======================================
[0] 2.6 11.9 1046.0 13.6
[1] 2.0 9.4 955.0 13.3
[2] 2.2 9.0 939.0 11.9
[3] 2.2 9.2 948.0 11.0
[4] 1.6 6.5 836.0 11.2
[5] 1.2 4.7 750.0 11.2
[6] 1.2 3.6 690.0 11.3
[7] 1.0 3.3 672.0 10.7
[8] 2.9 2.3 609.0 10.7
[9] 2.6 1.7 561.0 10.3
>>> model = tc.models.timeseries.arimax.train(frame, "CO_GT", ["C6H6_GT", "PT08_S2_NMHC", "T"], 1, 1, 1, 1, True, False)
<progress>
>>> model.c
0.24886373113659435
>>> model.ar
[-0.8612398115782316]
>>> model.ma
[-0.45556700539598505]
>>> model.xreg
[0.09496697769170012, -0.00043805552312166737, 0.0006888829627820128, 0.8523170824191132, -0.017901092786057428, 0.017936687425751337]
In this example, we will call predict using the same frame that was used for training, again specifying the name
of the time series column and the names of the columns that contain exogenous regressors.
>>> predicted_frame = model.predict(frame, "CO_GT", ["C6H6_GT", "PT08_S2_NMHC", "T"])
<progress>
The predicted_frame that's return has a new column called *predicted_y*. This column contains the predicted
time series values.
>>> predicted_frame.column_names
[u'CO_GT', u'C6H6_GT', u'PT08_S2_NMHC', u'T', u'predicted_y']
>>> predicted_frame.inspect(columns=["CO_GT","predicted_y"])
[#] CO_GT predicted_y
=========================
[0] 2.6 2.83896716391
[1] 2.0 2.89056663602
[2] 2.2 2.84550712171
[3] 2.2 2.88445194591
[4] 1.6 2.85091111286
[5] 1.2 2.8798667019
[6] 1.2 2.85451566607
[7] 1.0 2.87634898739
[8] 2.9 2.85726970866
[9] 2.6 2.87356376648
The trained model can be saved to be used later:
>>> model_path = "sandbox/savedArimaxModel"
>>> model.save(model_path)
The saved model can be loaded through the tk context and then used for forecasting values the same way
that the original model was used.
>>> loaded_model = tc.load(model_path)
>>> predicted_frame = loaded_model.predict(frame, "CO_GT", ["C6H6_GT", "PT08_S2_NMHC", "T"])
>>> predicted_frame.inspect(columns=["CO_GT","predicted_y"])
[#] CO_GT predicted_y
=========================
[0] 2.6 2.83896716391
[1] 2.0 2.89056663602
[2] 2.2 2.84550712171
[3] 2.2 2.88445194591
[4] 1.6 2.85091111286
[5] 1.2 2.8798667019
[6] 1.2 2.85451566607
[7] 1.0 2.87634898739
[8] 2.9 2.85726970866
[9] 2.6 2.87356376648
The trained model can also be exported to a .mar file, to be used with the scoring engine:
>>> canonical_path = model.export_to_mar("sandbox/arimax.mar")
<hide>
>>> import os
>>> assert(os.path.isfile(canonical_path))
</hide>
"""
def __init__(self, tc, scala_model):
self._tc = tc
tc.jutils.validate_is_jvm_instance_of(scala_model, _get_scala_obj(tc))
self._scala = scala_model
@staticmethod
def _from_scala(tc, scala_model):
"""
Load an ARIMAX model
:param tc: (TkContext) Active TkContext
:param scala_model: (scala ArimaxModel) Scala model to load.
:return: (ArimaxModel) ArimaxModel object
"""
return ArimaxModel(tc, scala_model)
@property
def p(self):
"""
Autoregressive order
"""
return self._scala.p()
@property
def d(self):
"""
Differencing order
"""
return self._scala.d()
@property
def q(self):
"""
Moving average order
"""
return self._scala.q()
@property
def x_max_lag(self):
"""
The maximum lag order for exogenous variables.
"""
return self._scala.xregMaxLag()
@property
def includeIntercept(self):
"""
A boolean flag indicating if the intercept should be included.
"""
return self._scala.includeIntercept()
@property
def includeOriginalXreg(self):
"""
A boolean flag indicating if the non-lagged exogenous variables should be included.
"""
return self._scala.includeOriginalXreg()
@property
def init_params(self):
"""
A set of user provided initial parameters for optimization
"""
return self._scala.initParams()
@property
def c(self):
"""
Intercept
"""
return self._scala.c()
@property
def ar(self):
"""
Coefficient values from the trained model (AR with increasing degrees).
"""
return list(self._tc.jutils.convert.from_scala_seq(self._scala.ar()))
@property
def ma(self):
"""
Coefficient values from the trained model (MA with increasing degrees).
"""
return list(self._tc.jutils.convert.from_scala_seq(self._scala.ma()))
@property
def xreg(self):
"""
Coefficient values from the trained model fox exogenous variables with increasing degrees.
"""
return list(self._tc.jutils.convert.from_scala_seq(self._scala.xreg()))
def predict(self, frame, ts_column, x_columns):
"""
New frame with column of predicted y values
Predict the time series values for a test frame, based on the specified x values. Creates a new frame
revision with the existing columns and a new predicted_y column.
Parameters
----------
:param frame: (Frame) Frame used for predicting the ts values
:param ts_column: (str) Name of the time series column
:param x_columns: (List[str]) Names of the column(s) that contain the values of the exogenous inputs.
:return: (Frame) A new frame containing the original frame's columns and a column *predictied_y*
"""
if not isinstance(frame, self._tc.frame.Frame):
raise TypeError("'frame' parameter should be a spark-tk Frame object.")
if not isinstance(ts_column, basestring):
raise TypeError("'ts_column' parameter should be a string (name of the column that has the timeseries value).")
if not isinstance(x_columns, list) or not all(isinstance(c, str) for c in x_columns):
raise TypeError("'x_columns' parameter should be a list of strings (names of the exogenous columns).")
elif len(x_columns) <= 0:
raise ValueError("'x_columns' should not be empty.")
scala_x_columns = self._tc.jutils.convert.to_scala_vector_string(x_columns)
from sparktk.frame.frame import Frame
return Frame(self._tc, self._scala.predict(frame._scala, ts_column, scala_x_columns))
def save(self, path):
"""
Save the trained model to the specified path
Parameters
----------
:param path: Path to save
"""
self._scala.save(self._tc._scala_sc, path)
def export_to_mar(self, path):
"""
Exports the trained model as a model archive (.mar) to the specified path.
Parameters
----------
:param path: (str) Path to save the trained model
:returns (str) Full path to the saved .mar file
"""
if not isinstance(path, basestring):
raise TypeError("path parameter must be a str, but received %s" % type(path))
return self._scala.exportToMar(self._tc._scala_sc, path)
del PropertiesObject
|
apache-2.0
|
[
3,
6695,
26,
663,
2644,
29,
1624,
13,
24,
199,
199,
3,
221,
1898,
10619,
8,
67,
9,
10619,
9261,
20619,
10619,
8380,
10633,
10619,
199,
3,
199,
3,
221,
3909,
10619,
7138,
10619,
1589,
10619,
28993,
10619,
3761,
12,
10619,
3353,
10619,
18,
14,
16,
10619,
8,
1589,
10619,
2,
3761,
3547,
199,
3,
221,
1265,
10619,
7551,
10619,
1397,
10619,
1180,
10619,
3749,
10619,
493,
10619,
2590,
10619,
262,
10619,
863,
3636,
10619,
1045,
10619,
1589,
10619,
3761,
14,
199,
3,
221,
2047,
10619,
7551,
10619,
2873,
877,
10619,
65,
10619,
1574,
10619,
1618,
10619,
1589,
10619,
3761,
10619,
292,
199,
3,
199,
3,
221,
10619,
10619,
10619,
10619,
10619,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
10619,
2427,
10619,
991,
10619,
30002,
10619,
22277,
10619,
269,
10619,
643,
3798,
10619,
475,
10619,
262,
10619,
14827,
12,
10619,
15619,
199,
3,
221,
1854,
10619,
7138,
10619,
1589,
10619,
3761,
10619,
374,
10619,
16832,
10619,
265,
10619,
290,
10619,
2,
1179,
10619,
1311,
2,
10619,
20205,
1311,
12,
199,
3,
221,
2428,
10619,
55,
2007,
2563,
10619,
726,
10619,
1864,
4150,
10619,
3359,
10619,
8974,
10619,
43,
3192,
12,
10619,
22051,
10619,
476,
2915,
10619,
269,
10619,
22063,
14,
199,
3,
221,
1666,
10619,
1589,
10619,
3761,
10619,
509,
10619,
1589,
10619,
6100,
10619,
3671,
10619,
71,
1883,
1835,
10619,
6060,
10619,
460,
199,
3,
221,
4204,
10619,
7138,
10619,
1589,
10619,
3761,
14,
199,
3,
199,
199,
624,
199,
689,
1469,
9839,
334,
23570,
720,
25787,
8883,
2587,
972,
3930,
4007,
437,
3652,
543,
1316,
974,
6349,
1785,
17198,
9,
5822,
199,
624,
199,
199,
504,
15442,
2663,
14,
22771,
492,
943,
63,
912,
27,
943,
63,
912,
3460,
354,
363,
2736,
2150,
943,
63,
912,
199,
504,
15442,
2663,
14,
6395,
3422,
492,
9227,
199,
504,
15442,
2663,
14,
496,
555,
468,
492,
19329,
1692,
199,
199,
318,
3560,
8,
1943,
12,
6714,
63,
2301,
12,
671,
63,
3406,
12,
299,
12,
366,
12,
1894,
12,
671,
63,
988,
63,
1823,
12,
2387,
63,
5043,
63,
88,
29,
549,
12,
2387,
63,
10863,
29,
549,
12,
4205,
63,
1162,
29,
403,
304,
272,
408,
272,
10560,
27722,
720,
25787,
8883,
2587,
972,
3930,
4007,
437,
3652,
543,
1316,
5140,
8658,
17198,
334,
689,
1469,
9839,
9,
5822,
687,
314,
2013,
272,
900,
6779,
1338,
14,
339,
9138,
282,
900,
6779,
12,
20147,
376,
2222,
13,
12605,
279,
27722,
720,
25787,
8883,
2587,
972,
3930,
4007,
437,
3652,
543,
1316,
5140,
8658,
17198,
272,
334,
689,
1469,
9839,
9,
1402,
402,
1865,
334,
80,
12,
366,
12,
1894,
9,
2382,
299,
8469,
314,
28589,
71,
1941,
2895,
12,
366,
8469,
314,
1865,
402,
18317,
4477,
272,
436,
1894,
8469,
314,
12876,
8095,
1125,
2895,
14,
1323,
63,
988,
63,
1823,
8469,
314,
5696,
17891,
1865,
367,
444,
26300,
1785,
2860,
14,
272,
982,
2387,
63,
5043,
63,
88,
365,
2549,
12,
314,
1402,
365,
26093,
543,
376,
3379,
444,
26300,
1785,
2860,
14,
982,
2387,
2620,
716,
365,
2549,
12,
272,
314,
1402,
365,
26093,
543,
376,
13926,
14,
339,
3897,
272,
4143,
339,
520,
635,
2787,
26,
334,
3160,
9,
11726,
1202,
367,
6093,
14,
272,
520,
635,
6714,
63,
2301,
26,
334,
495,
9,
2812,
402,
314,
2763,
626,
3509,
314,
900,
6779,
1338,
14,
272,
520,
635,
671,
63,
3406,
26,
334,
1296,
8,
495,
430,
23923,
402,
314,
2763,
8,
83,
9,
626,
1395,
314,
1338,
402,
444,
26300,
1785,
1295,
753,
1384,
14,
272,
520,
635,
299,
26,
334,
442,
9,
27722,
720,
25787,
1865,
272,
520,
635,
366,
26,
334,
442,
9,
18029,
828,
4477,
1865,
272,
520,
635,
1894,
26,
334,
442,
9,
3930,
4007,
8095,
1865,
272,
520,
635,
671,
63,
988,
63,
1823,
26,
334,
442,
9,
710,
5696,
17891,
1865,
367,
444,
26300,
1785,
2860,
14,
272,
520,
635,
2387,
63,
5043,
63,
88,
26,
334,
7012,
8,
4871,
430,
982,
715,
12,
314,
1402,
365,
5542,
543,
376,
3379,
444,
26300,
1785,
2860,
3044,
334,
10863,
367,
444,
26300,
1785,
2860,
680,
3758,
365,
715,
14,
272,
520,
635,
2387,
63,
10863,
26,
334,
7012,
8,
4871,
430,
982,
715,
12,
314,
1402,
365,
5542,
543,
376,
13926,
14,
221,
3758,
365,
715,
14,
272,
520,
635,
4205,
63,
1162,
26,
334,
7012,
8,
1296,
59,
1609,
566,
437,
663,
402,
922,
2741,
2536,
2633,
367,
13712,
14,
982,
314,
717,
769,
365,
2701,
334,
885,
395,
10038,
1808,
869,
1189,
290,
13,
50,
374,
18904,
287,
5563,
14,
982,
2741,
12,
1865,
717,
402,
2725,
1077,
506,
26,
13926,
6707,
12,
4160,
2633,
334,
262,
22255,
1865,
402,
17891,
395,
4828,
717,
2633,
334,
262,
22255,
1865,
402,
17891,
9,
436,
1215,
266,
470,
367,
444,
26300,
1785,
2860,
334,
262,
717,
22255,
1865,
402,
17891,
680,
272,
520,
1107,
26,
334,
26291,
988,
1685,
9,
12643,
1942,
4160,
1469,
9839,
1402,
272,
408,
339,
340,
440,
1228,
8,
1086,
63,
2301,
12,
7116,
304,
267,
746,
3146,
15587,
1086,
63,
2301,
7,
1077,
506,
282,
1059,
334,
354,
402,
314,
2763,
626,
965,
314,
900,
5602,
574,
26744,
272,
340,
440,
1228,
8,
88,
63,
3406,
12,
769,
9,
503,
440,
1006,
8,
6074,
8,
67,
12,
620,
9,
367,
286,
315,
671,
63,
3406,
304,
267,
746,
3146,
15587,
88,
63,
3406,
7,
1077,
506,
282,
769,
402,
3326,
334,
1247,
402,
314,
444,
26300,
1785,
4362,
26744,
272,
916,
822,
8,
88,
63,
3406,
9,
2695,
378,
26,
267,
746,
1722,
15587,
88,
63,
3406,
7,
1077,
440,
506,
2701,
2685,
272,
340,
440,
1228,
8,
80,
12,
1109,
304,
267,
746,
3146,
15587,
80,
7,
2725,
1471,
506,
376,
3000,
2685,
272,
340,
440,
1228,
8,
68,
12,
1109,
304,
267,
746,
3146,
15587,
68,
7,
2725,
1471,
506,
376,
3000,
2685,
272,
340,
440,
1228,
8,
81,
12,
1109,
304,
267,
746,
3146,
15587,
81,
7,
2725,
1471,
506,
376,
3000,
2685,
272,
340,
440,
1228,
8,
88,
63,
988,
63,
1823,
12,
1109,
304,
267,
746,
3146,
15587,
88,
63
] |
[
6695,
26,
663,
2644,
29,
1624,
13,
24,
199,
199,
3,
221,
1898,
10619,
8,
67,
9,
10619,
9261,
20619,
10619,
8380,
10633,
10619,
199,
3,
199,
3,
221,
3909,
10619,
7138,
10619,
1589,
10619,
28993,
10619,
3761,
12,
10619,
3353,
10619,
18,
14,
16,
10619,
8,
1589,
10619,
2,
3761,
3547,
199,
3,
221,
1265,
10619,
7551,
10619,
1397,
10619,
1180,
10619,
3749,
10619,
493,
10619,
2590,
10619,
262,
10619,
863,
3636,
10619,
1045,
10619,
1589,
10619,
3761,
14,
199,
3,
221,
2047,
10619,
7551,
10619,
2873,
877,
10619,
65,
10619,
1574,
10619,
1618,
10619,
1589,
10619,
3761,
10619,
292,
199,
3,
199,
3,
221,
10619,
10619,
10619,
10619,
10619,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
10619,
2427,
10619,
991,
10619,
30002,
10619,
22277,
10619,
269,
10619,
643,
3798,
10619,
475,
10619,
262,
10619,
14827,
12,
10619,
15619,
199,
3,
221,
1854,
10619,
7138,
10619,
1589,
10619,
3761,
10619,
374,
10619,
16832,
10619,
265,
10619,
290,
10619,
2,
1179,
10619,
1311,
2,
10619,
20205,
1311,
12,
199,
3,
221,
2428,
10619,
55,
2007,
2563,
10619,
726,
10619,
1864,
4150,
10619,
3359,
10619,
8974,
10619,
43,
3192,
12,
10619,
22051,
10619,
476,
2915,
10619,
269,
10619,
22063,
14,
199,
3,
221,
1666,
10619,
1589,
10619,
3761,
10619,
509,
10619,
1589,
10619,
6100,
10619,
3671,
10619,
71,
1883,
1835,
10619,
6060,
10619,
460,
199,
3,
221,
4204,
10619,
7138,
10619,
1589,
10619,
3761,
14,
199,
3,
199,
199,
624,
199,
689,
1469,
9839,
334,
23570,
720,
25787,
8883,
2587,
972,
3930,
4007,
437,
3652,
543,
1316,
974,
6349,
1785,
17198,
9,
5822,
199,
624,
199,
199,
504,
15442,
2663,
14,
22771,
492,
943,
63,
912,
27,
943,
63,
912,
3460,
354,
363,
2736,
2150,
943,
63,
912,
199,
504,
15442,
2663,
14,
6395,
3422,
492,
9227,
199,
504,
15442,
2663,
14,
496,
555,
468,
492,
19329,
1692,
199,
199,
318,
3560,
8,
1943,
12,
6714,
63,
2301,
12,
671,
63,
3406,
12,
299,
12,
366,
12,
1894,
12,
671,
63,
988,
63,
1823,
12,
2387,
63,
5043,
63,
88,
29,
549,
12,
2387,
63,
10863,
29,
549,
12,
4205,
63,
1162,
29,
403,
304,
272,
408,
272,
10560,
27722,
720,
25787,
8883,
2587,
972,
3930,
4007,
437,
3652,
543,
1316,
5140,
8658,
17198,
334,
689,
1469,
9839,
9,
5822,
687,
314,
2013,
272,
900,
6779,
1338,
14,
339,
9138,
282,
900,
6779,
12,
20147,
376,
2222,
13,
12605,
279,
27722,
720,
25787,
8883,
2587,
972,
3930,
4007,
437,
3652,
543,
1316,
5140,
8658,
17198,
272,
334,
689,
1469,
9839,
9,
1402,
402,
1865,
334,
80,
12,
366,
12,
1894,
9,
2382,
299,
8469,
314,
28589,
71,
1941,
2895,
12,
366,
8469,
314,
1865,
402,
18317,
4477,
272,
436,
1894,
8469,
314,
12876,
8095,
1125,
2895,
14,
1323,
63,
988,
63,
1823,
8469,
314,
5696,
17891,
1865,
367,
444,
26300,
1785,
2860,
14,
272,
982,
2387,
63,
5043,
63,
88,
365,
2549,
12,
314,
1402,
365,
26093,
543,
376,
3379,
444,
26300,
1785,
2860,
14,
982,
2387,
2620,
716,
365,
2549,
12,
272,
314,
1402,
365,
26093,
543,
376,
13926,
14,
339,
3897,
272,
4143,
339,
520,
635,
2787,
26,
334,
3160,
9,
11726,
1202,
367,
6093,
14,
272,
520,
635,
6714,
63,
2301,
26,
334,
495,
9,
2812,
402,
314,
2763,
626,
3509,
314,
900,
6779,
1338,
14,
272,
520,
635,
671,
63,
3406,
26,
334,
1296,
8,
495,
430,
23923,
402,
314,
2763,
8,
83,
9,
626,
1395,
314,
1338,
402,
444,
26300,
1785,
1295,
753,
1384,
14,
272,
520,
635,
299,
26,
334,
442,
9,
27722,
720,
25787,
1865,
272,
520,
635,
366,
26,
334,
442,
9,
18029,
828,
4477,
1865,
272,
520,
635,
1894,
26,
334,
442,
9,
3930,
4007,
8095,
1865,
272,
520,
635,
671,
63,
988,
63,
1823,
26,
334,
442,
9,
710,
5696,
17891,
1865,
367,
444,
26300,
1785,
2860,
14,
272,
520,
635,
2387,
63,
5043,
63,
88,
26,
334,
7012,
8,
4871,
430,
982,
715,
12,
314,
1402,
365,
5542,
543,
376,
3379,
444,
26300,
1785,
2860,
3044,
334,
10863,
367,
444,
26300,
1785,
2860,
680,
3758,
365,
715,
14,
272,
520,
635,
2387,
63,
10863,
26,
334,
7012,
8,
4871,
430,
982,
715,
12,
314,
1402,
365,
5542,
543,
376,
13926,
14,
221,
3758,
365,
715,
14,
272,
520,
635,
4205,
63,
1162,
26,
334,
7012,
8,
1296,
59,
1609,
566,
437,
663,
402,
922,
2741,
2536,
2633,
367,
13712,
14,
982,
314,
717,
769,
365,
2701,
334,
885,
395,
10038,
1808,
869,
1189,
290,
13,
50,
374,
18904,
287,
5563,
14,
982,
2741,
12,
1865,
717,
402,
2725,
1077,
506,
26,
13926,
6707,
12,
4160,
2633,
334,
262,
22255,
1865,
402,
17891,
395,
4828,
717,
2633,
334,
262,
22255,
1865,
402,
17891,
9,
436,
1215,
266,
470,
367,
444,
26300,
1785,
2860,
334,
262,
717,
22255,
1865,
402,
17891,
680,
272,
520,
1107,
26,
334,
26291,
988,
1685,
9,
12643,
1942,
4160,
1469,
9839,
1402,
272,
408,
339,
340,
440,
1228,
8,
1086,
63,
2301,
12,
7116,
304,
267,
746,
3146,
15587,
1086,
63,
2301,
7,
1077,
506,
282,
1059,
334,
354,
402,
314,
2763,
626,
965,
314,
900,
5602,
574,
26744,
272,
340,
440,
1228,
8,
88,
63,
3406,
12,
769,
9,
503,
440,
1006,
8,
6074,
8,
67,
12,
620,
9,
367,
286,
315,
671,
63,
3406,
304,
267,
746,
3146,
15587,
88,
63,
3406,
7,
1077,
506,
282,
769,
402,
3326,
334,
1247,
402,
314,
444,
26300,
1785,
4362,
26744,
272,
916,
822,
8,
88,
63,
3406,
9,
2695,
378,
26,
267,
746,
1722,
15587,
88,
63,
3406,
7,
1077,
440,
506,
2701,
2685,
272,
340,
440,
1228,
8,
80,
12,
1109,
304,
267,
746,
3146,
15587,
80,
7,
2725,
1471,
506,
376,
3000,
2685,
272,
340,
440,
1228,
8,
68,
12,
1109,
304,
267,
746,
3146,
15587,
68,
7,
2725,
1471,
506,
376,
3000,
2685,
272,
340,
440,
1228,
8,
81,
12,
1109,
304,
267,
746,
3146,
15587,
81,
7,
2725,
1471,
506,
376,
3000,
2685,
272,
340,
440,
1228,
8,
88,
63,
988,
63,
1823,
12,
1109,
304,
267,
746,
3146,
15587,
88,
63,
0
] |
[
1,
1,
1,
1,
1,
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Server
|
libs/chardet/chardistribution.py
|
2755
|
9226
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from .euctwfreq import (EUCTWCharToFreqOrder, EUCTW_TABLE_SIZE,
EUCTW_TYPICAL_DISTRIBUTION_RATIO)
from .euckrfreq import (EUCKRCharToFreqOrder, EUCKR_TABLE_SIZE,
EUCKR_TYPICAL_DISTRIBUTION_RATIO)
from .gb2312freq import (GB2312CharToFreqOrder, GB2312_TABLE_SIZE,
GB2312_TYPICAL_DISTRIBUTION_RATIO)
from .big5freq import (Big5CharToFreqOrder, BIG5_TABLE_SIZE,
BIG5_TYPICAL_DISTRIBUTION_RATIO)
from .jisfreq import (JISCharToFreqOrder, JIS_TABLE_SIZE,
JIS_TYPICAL_DISTRIBUTION_RATIO)
from .compat import wrap_ord
ENOUGH_DATA_THRESHOLD = 1024
SURE_YES = 0.99
SURE_NO = 0.01
MINIMUM_DATA_THRESHOLD = 3
class CharDistributionAnalysis:
def __init__(self):
# Mapping table to get frequency order from char order (get from
# GetOrder())
self._mCharToFreqOrder = None
self._mTableSize = None # Size of above table
# This is a constant value which varies from language to language,
# used in calculating confidence. See
# http://www.mozilla.org/projects/intl/UniversalCharsetDetection.html
# for further detail.
self._mTypicalDistributionRatio = None
self.reset()
def reset(self):
"""reset analyser, clear any state"""
# If this flag is set to True, detection is done and conclusion has
# been made
self._mDone = False
self._mTotalChars = 0 # Total characters encountered
# The number of characters whose frequency order is less than 512
self._mFreqChars = 0
def feed(self, aBuf, aCharLen):
"""feed a character with known length"""
if aCharLen == 2:
# we only care about 2-bytes character in our distribution analysis
order = self.get_order(aBuf)
else:
order = -1
if order >= 0:
self._mTotalChars += 1
# order is valid
if order < self._mTableSize:
if 512 > self._mCharToFreqOrder[order]:
self._mFreqChars += 1
def get_confidence(self):
"""return confidence based on existing data"""
# if we didn't receive any character in our consideration range,
# return negative answer
if self._mTotalChars <= 0 or self._mFreqChars <= MINIMUM_DATA_THRESHOLD:
return SURE_NO
if self._mTotalChars != self._mFreqChars:
r = (self._mFreqChars / ((self._mTotalChars - self._mFreqChars)
* self._mTypicalDistributionRatio))
if r < SURE_YES:
return r
# normalize confidence (we don't want to be 100% sure)
return SURE_YES
def got_enough_data(self):
# It is not necessary to receive all data to draw conclusion.
# For charset detection, certain amount of data is enough
return self._mTotalChars > ENOUGH_DATA_THRESHOLD
def get_order(self, aBuf):
# We do not handle characters based on the original encoding string,
# but convert this encoding string to a number, here called order.
# This allows multiple encodings of a language to share one frequency
# table.
return -1
class EUCTWDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = EUCTWCharToFreqOrder
self._mTableSize = EUCTW_TABLE_SIZE
self._mTypicalDistributionRatio = EUCTW_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aBuf):
# for euc-TW encoding, we are interested
# first byte range: 0xc4 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
first_char = wrap_ord(aBuf[0])
if first_char >= 0xC4:
return 94 * (first_char - 0xC4) + wrap_ord(aBuf[1]) - 0xA1
else:
return -1
class EUCKRDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = EUCKRCharToFreqOrder
self._mTableSize = EUCKR_TABLE_SIZE
self._mTypicalDistributionRatio = EUCKR_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aBuf):
# for euc-KR encoding, we are interested
# first byte range: 0xb0 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
first_char = wrap_ord(aBuf[0])
if first_char >= 0xB0:
return 94 * (first_char - 0xB0) + wrap_ord(aBuf[1]) - 0xA1
else:
return -1
class GB2312DistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = GB2312CharToFreqOrder
self._mTableSize = GB2312_TABLE_SIZE
self._mTypicalDistributionRatio = GB2312_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aBuf):
# for GB2312 encoding, we are interested
# first byte range: 0xb0 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
first_char, second_char = wrap_ord(aBuf[0]), wrap_ord(aBuf[1])
if (first_char >= 0xB0) and (second_char >= 0xA1):
return 94 * (first_char - 0xB0) + second_char - 0xA1
else:
return -1
class Big5DistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = Big5CharToFreqOrder
self._mTableSize = BIG5_TABLE_SIZE
self._mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aBuf):
# for big5 encoding, we are interested
# first byte range: 0xa4 -- 0xfe
# second byte range: 0x40 -- 0x7e , 0xa1 -- 0xfe
# no validation needed here. State machine has done that
first_char, second_char = wrap_ord(aBuf[0]), wrap_ord(aBuf[1])
if first_char >= 0xA4:
if second_char >= 0xA1:
return 157 * (first_char - 0xA4) + second_char - 0xA1 + 63
else:
return 157 * (first_char - 0xA4) + second_char - 0x40
else:
return -1
class SJISDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = JISCharToFreqOrder
self._mTableSize = JIS_TABLE_SIZE
self._mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aBuf):
# for sjis encoding, we are interested
# first byte range: 0x81 -- 0x9f , 0xe0 -- 0xfe
# second byte range: 0x40 -- 0x7e, 0x81 -- oxfe
# no validation needed here. State machine has done that
first_char, second_char = wrap_ord(aBuf[0]), wrap_ord(aBuf[1])
if (first_char >= 0x81) and (first_char <= 0x9F):
order = 188 * (first_char - 0x81)
elif (first_char >= 0xE0) and (first_char <= 0xEF):
order = 188 * (first_char - 0xE0 + 31)
else:
return -1
order = order + second_char - 0x40
if second_char > 0x7F:
order = -1
return order
class EUCJPDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
CharDistributionAnalysis.__init__(self)
self._mCharToFreqOrder = JISCharToFreqOrder
self._mTableSize = JIS_TABLE_SIZE
self._mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO
def get_order(self, aBuf):
# for euc-JP encoding, we are interested
# first byte range: 0xa0 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
char = wrap_ord(aBuf[0])
if char >= 0xA0:
return 94 * (char - 0xA1) + wrap_ord(aBuf[1]) - 0xa1
else:
return -1
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
69,
918,
87,
5646,
492,
334,
37,
27120,
18139,
13875,
4738,
12,
662,
27120,
63,
8723,
63,
4305,
12,
717,
662,
27120,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
69,
10112,
3941,
2103,
492,
334,
23539,
27373,
18139,
13875,
4738,
12,
26007,
27373,
63,
8723,
63,
4305,
12,
717,
26007,
27373,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
4908,
16909,
5646,
492,
334,
6487,
16909,
18139,
13875,
4738,
12,
18553,
16909,
63,
8723,
63,
4305,
12,
586,
18553,
16909,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
5076,
21,
5646,
492,
334,
7279,
21,
18139,
13875,
4738,
12,
16524,
21,
63,
8723,
63,
4305,
12,
2432,
16524,
21,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
18941,
5646,
492,
334,
22290,
18139,
13875,
4738,
12,
1603,
1311,
63,
8723,
63,
4305,
12,
1993,
1603,
1311,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
5819,
492,
4816,
63,
2181,
199,
199,
15577,
10134,
40,
63,
3998,
63,
19307,
275,
6619,
199,
51,
3942,
63,
15641,
275,
378,
14,
1020,
199,
51,
3942,
63,
2826,
275,
378,
14,
614,
199,
4896,
27078,
63,
3998,
63,
19307,
275,
650,
421,
199,
533,
6659,
24906,
26,
272,
347,
636,
826,
721,
277,
304,
267,
327,
12340,
1817,
370,
664,
9857,
1865,
687,
1495,
1865,
334,
362,
687,
267,
327,
2372,
4738,
1012,
267,
291,
423,
77,
18139,
13875,
4738,
275,
488,
267,
291,
423,
77,
3186,
2320,
275,
488,
221,
327,
14579,
402,
3432,
1817,
267,
327,
961,
365,
282,
4413,
574,
1314,
373,
3433,
687,
2637,
370,
2637,
12,
267,
327,
1202,
315,
26079,
15197,
14,
221,
1666,
267,
327,
1455,
921,
1544,
14,
12102,
14,
1308,
15,
6776,
15,
442,
76,
15,
1358,
10959,
28200,
31198,
14,
1360,
267,
327,
367,
9848,
10093,
14,
267,
291,
423,
30376,
8580,
13971,
275,
488,
267,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
408,
3958,
5909,
332,
12,
5436,
1263,
1174,
624,
267,
327,
982,
642,
3305,
365,
663,
370,
715,
12,
15212,
365,
4224,
436,
406,
10248,
965,
267,
327,
2757,
6326,
267,
291,
423,
77,
10759,
275,
756,
267,
291,
423,
77,
7316,
11229,
275,
378,
221,
327,
19271,
4110,
14556,
267,
327,
710,
1329,
402,
4110,
7447,
9857,
1865,
365,
6656,
2419,
10574,
267,
291,
423,
77,
13875,
11229,
275,
378,
339,
347,
4733,
8,
277,
12,
17407,
12,
282,
1610,
3166,
304,
267,
408,
3871,
282,
4528,
543,
6040,
2582,
624,
267,
340,
282,
1610,
3166,
508,
499,
26,
288,
327,
781,
1454,
10296,
3595,
499,
13,
2394,
4528,
315,
4154,
4084,
11284,
288,
1865,
275,
291,
14,
362,
63,
1648,
8,
22353,
9,
267,
587,
26,
288,
1865,
275,
446,
17,
267,
340,
1865,
2356,
378,
26,
288,
291,
423,
77,
7316,
11229,
847,
413,
288,
327,
1865,
365,
1686,
288,
340,
1865,
665,
291,
423,
77,
3186,
2320,
26,
355,
340,
10574,
690,
291,
423,
77,
18139,
13875,
4738,
59,
1648,
2189,
490,
291,
423,
77,
13875,
11229,
847,
413,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
408,
1107,
15197,
4079,
641,
3411,
666,
624,
267,
327,
340,
781,
9980,
1133,
9128,
1263,
4528,
315,
4154,
8219,
1754,
1425,
12,
267,
327,
372,
6946,
6385,
267,
340,
291,
423,
77,
7316,
11229,
2695,
378,
503,
291,
423,
77,
13875,
11229,
2695,
15861,
27078,
63,
3998,
63,
19307,
26,
288,
372,
428,
3942,
63,
2826,
398,
340,
291,
423,
77,
7316,
11229,
1137,
291,
423,
77,
13875,
11229,
26,
288,
519,
275,
334,
277,
423,
77,
13875,
11229,
1182,
3666,
277,
423,
77,
7316,
11229,
446,
291,
423,
77,
13875,
11229,
9,
326,
627,
291,
423,
30376,
8580,
13971,
430,
288,
340,
519,
665,
428,
3942,
63,
15641,
26,
355,
372,
519,
398,
327,
7666,
15197,
334,
1129,
2793,
1133,
2934,
370,
506,
2948,
5,
3238,
9,
267,
372,
428,
3942,
63,
15641,
339,
347,
4788,
63,
30881,
63,
576,
8,
277,
304,
267,
327,
2779,
365,
440,
5784,
370,
9128,
1006,
666,
370,
5954,
406,
10248,
14,
267,
327,
2104,
5960,
15212,
12,
9842,
5982,
402,
666,
365,
8321,
267,
372,
291,
423,
77,
7316,
11229,
690,
662,
2826,
10134,
40,
63,
3998,
63,
19307,
339,
347,
664,
63,
1648,
8,
277,
12,
17407,
304,
267,
327,
2136,
886,
440,
2429,
4110,
4079,
641,
314,
3379,
2644,
1059,
12,
267,
327,
1325,
3957,
642,
2644,
1059,
370,
282,
1329,
12,
2348,
2797,
1865,
14,
267,
327,
961,
6127,
3663,
14134,
402,
282,
2637,
370,
8663,
1373,
9857,
267
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
69,
918,
87,
5646,
492,
334,
37,
27120,
18139,
13875,
4738,
12,
662,
27120,
63,
8723,
63,
4305,
12,
717,
662,
27120,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
69,
10112,
3941,
2103,
492,
334,
23539,
27373,
18139,
13875,
4738,
12,
26007,
27373,
63,
8723,
63,
4305,
12,
717,
26007,
27373,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
4908,
16909,
5646,
492,
334,
6487,
16909,
18139,
13875,
4738,
12,
18553,
16909,
63,
8723,
63,
4305,
12,
586,
18553,
16909,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
5076,
21,
5646,
492,
334,
7279,
21,
18139,
13875,
4738,
12,
16524,
21,
63,
8723,
63,
4305,
12,
2432,
16524,
21,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
18941,
5646,
492,
334,
22290,
18139,
13875,
4738,
12,
1603,
1311,
63,
8723,
63,
4305,
12,
1993,
1603,
1311,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
9,
199,
504,
1275,
5819,
492,
4816,
63,
2181,
199,
199,
15577,
10134,
40,
63,
3998,
63,
19307,
275,
6619,
199,
51,
3942,
63,
15641,
275,
378,
14,
1020,
199,
51,
3942,
63,
2826,
275,
378,
14,
614,
199,
4896,
27078,
63,
3998,
63,
19307,
275,
650,
421,
199,
533,
6659,
24906,
26,
272,
347,
636,
826,
721,
277,
304,
267,
327,
12340,
1817,
370,
664,
9857,
1865,
687,
1495,
1865,
334,
362,
687,
267,
327,
2372,
4738,
1012,
267,
291,
423,
77,
18139,
13875,
4738,
275,
488,
267,
291,
423,
77,
3186,
2320,
275,
488,
221,
327,
14579,
402,
3432,
1817,
267,
327,
961,
365,
282,
4413,
574,
1314,
373,
3433,
687,
2637,
370,
2637,
12,
267,
327,
1202,
315,
26079,
15197,
14,
221,
1666,
267,
327,
1455,
921,
1544,
14,
12102,
14,
1308,
15,
6776,
15,
442,
76,
15,
1358,
10959,
28200,
31198,
14,
1360,
267,
327,
367,
9848,
10093,
14,
267,
291,
423,
30376,
8580,
13971,
275,
488,
267,
291,
14,
3958,
342,
339,
347,
5305,
8,
277,
304,
267,
408,
3958,
5909,
332,
12,
5436,
1263,
1174,
624,
267,
327,
982,
642,
3305,
365,
663,
370,
715,
12,
15212,
365,
4224,
436,
406,
10248,
965,
267,
327,
2757,
6326,
267,
291,
423,
77,
10759,
275,
756,
267,
291,
423,
77,
7316,
11229,
275,
378,
221,
327,
19271,
4110,
14556,
267,
327,
710,
1329,
402,
4110,
7447,
9857,
1865,
365,
6656,
2419,
10574,
267,
291,
423,
77,
13875,
11229,
275,
378,
339,
347,
4733,
8,
277,
12,
17407,
12,
282,
1610,
3166,
304,
267,
408,
3871,
282,
4528,
543,
6040,
2582,
624,
267,
340,
282,
1610,
3166,
508,
499,
26,
288,
327,
781,
1454,
10296,
3595,
499,
13,
2394,
4528,
315,
4154,
4084,
11284,
288,
1865,
275,
291,
14,
362,
63,
1648,
8,
22353,
9,
267,
587,
26,
288,
1865,
275,
446,
17,
267,
340,
1865,
2356,
378,
26,
288,
291,
423,
77,
7316,
11229,
847,
413,
288,
327,
1865,
365,
1686,
288,
340,
1865,
665,
291,
423,
77,
3186,
2320,
26,
355,
340,
10574,
690,
291,
423,
77,
18139,
13875,
4738,
59,
1648,
2189,
490,
291,
423,
77,
13875,
11229,
847,
413,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
408,
1107,
15197,
4079,
641,
3411,
666,
624,
267,
327,
340,
781,
9980,
1133,
9128,
1263,
4528,
315,
4154,
8219,
1754,
1425,
12,
267,
327,
372,
6946,
6385,
267,
340,
291,
423,
77,
7316,
11229,
2695,
378,
503,
291,
423,
77,
13875,
11229,
2695,
15861,
27078,
63,
3998,
63,
19307,
26,
288,
372,
428,
3942,
63,
2826,
398,
340,
291,
423,
77,
7316,
11229,
1137,
291,
423,
77,
13875,
11229,
26,
288,
519,
275,
334,
277,
423,
77,
13875,
11229,
1182,
3666,
277,
423,
77,
7316,
11229,
446,
291,
423,
77,
13875,
11229,
9,
326,
627,
291,
423,
30376,
8580,
13971,
430,
288,
340,
519,
665,
428,
3942,
63,
15641,
26,
355,
372,
519,
398,
327,
7666,
15197,
334,
1129,
2793,
1133,
2934,
370,
506,
2948,
5,
3238,
9,
267,
372,
428,
3942,
63,
15641,
339,
347,
4788,
63,
30881,
63,
576,
8,
277,
304,
267,
327,
2779,
365,
440,
5784,
370,
9128,
1006,
666,
370,
5954,
406,
10248,
14,
267,
327,
2104,
5960,
15212,
12,
9842,
5982,
402,
666,
365,
8321,
267,
372,
291,
423,
77,
7316,
11229,
690,
662,
2826,
10134,
40,
63,
3998,
63,
19307,
339,
347,
664,
63,
1648,
8,
277,
12,
17407,
304,
267,
327,
2136,
886,
440,
2429,
4110,
4079,
641,
314,
3379,
2644,
1059,
12,
267,
327,
1325,
3957,
642,
2644,
1059,
370,
282,
1329,
12,
2348,
2797,
1865,
14,
267,
327,
961,
6127,
3663,
14134,
402,
282,
2637,
370,
8663,
1373,
9857,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
sYnfo/samba
|
third_party/waf/wafadmin/Tools/unittestw.py
|
32
|
9789
|
#!/usr/bin/env python
# encoding: utf-8
# Carlos Rafael Giani, 2006
"""
Unit tests run in the shutdown() method, and for c/c++ programs
One should NOT have to give parameters to programs to execute
In the shutdown method, add the following code:
>>> def shutdown():
... ut = UnitTest.unit_test()
... ut.run()
... ut.print_results()
Each object to use as a unit test must be a program and must have X{obj.unit_test=1}
"""
import os, sys
import Build, TaskGen, Utils, Options, Logs, Task
from TaskGen import before, after, feature
from Constants import *
class unit_test(object):
"Unit test representation"
def __init__(self):
self.returncode_ok = 0 # Unit test returncode considered OK. All returncodes differing from this one
# will cause the unit test to be marked as "FAILED".
# The following variables are filled with data by run().
# print_results() uses these for printing the unit test summary,
# but if there is need for direct access to the results,
# they can be retrieved here, after calling run().
self.num_tests_ok = 0 # Number of successful unit tests
self.num_tests_failed = 0 # Number of failed unit tests
self.num_tests_err = 0 # Tests that have not even run
self.total_num_tests = 0 # Total amount of unit tests
self.max_label_length = 0 # Maximum label length (pretty-print the output)
self.unit_tests = Utils.ordered_dict() # Unit test dictionary. Key: the label (unit test filename relative
# to the build dir), value: unit test filename with absolute path
self.unit_test_results = {} # Dictionary containing the unit test results.
# Key: the label, value: result (true = success false = failure)
self.unit_test_erroneous = {} # Dictionary indicating erroneous unit tests.
# Key: the label, value: true = unit test has an error false = unit test is ok
self.change_to_testfile_dir = False #True if the test file needs to be executed from the same dir
self.want_to_see_test_output = False #True to see the stdout from the testfile (for example check suites)
self.want_to_see_test_error = False #True to see the stderr from the testfile (for example check suites)
self.run_if_waf_does = 'check' #build was the old default
def run(self):
"Run the unit tests and gather results (note: no output here)"
self.num_tests_ok = 0
self.num_tests_failed = 0
self.num_tests_err = 0
self.total_num_tests = 0
self.max_label_length = 0
self.unit_tests = Utils.ordered_dict()
self.unit_test_results = {}
self.unit_test_erroneous = {}
ld_library_path = []
# If waf is not building, don't run anything
if not Options.commands[self.run_if_waf_does]: return
# Get the paths for the shared libraries, and obtain the unit tests to execute
for obj in Build.bld.all_task_gen:
try:
link_task = obj.link_task
except AttributeError:
pass
else:
lib_path = link_task.outputs[0].parent.abspath(obj.env)
if lib_path not in ld_library_path:
ld_library_path.append(lib_path)
unit_test = getattr(obj, 'unit_test', '')
if unit_test and 'cprogram' in obj.features:
try:
output = obj.path
filename = os.path.join(output.abspath(obj.env), obj.target)
srcdir = output.abspath()
label = os.path.join(output.bldpath(obj.env), obj.target)
self.max_label_length = max(self.max_label_length, len(label))
self.unit_tests[label] = (filename, srcdir)
except KeyError:
pass
self.total_num_tests = len(self.unit_tests)
# Now run the unit tests
Utils.pprint('GREEN', 'Running the unit tests')
count = 0
result = 1
for label in self.unit_tests.allkeys:
file_and_src = self.unit_tests[label]
filename = file_and_src[0]
srcdir = file_and_src[1]
count += 1
line = Build.bld.progress_line(count, self.total_num_tests, Logs.colors.GREEN, Logs.colors.NORMAL)
if Options.options.progress_bar and line:
sys.stderr.write(line)
sys.stderr.flush()
try:
kwargs = {}
kwargs['env'] = os.environ.copy()
if self.change_to_testfile_dir:
kwargs['cwd'] = srcdir
if not self.want_to_see_test_output:
kwargs['stdout'] = Utils.pproc.PIPE # PIPE for ignoring output
if not self.want_to_see_test_error:
kwargs['stderr'] = Utils.pproc.PIPE # PIPE for ignoring output
if ld_library_path:
v = kwargs['env']
def add_path(dct, path, var):
dct[var] = os.pathsep.join(Utils.to_list(path) + [os.environ.get(var, '')])
if sys.platform == 'win32':
add_path(v, ld_library_path, 'PATH')
elif sys.platform == 'darwin':
add_path(v, ld_library_path, 'DYLD_LIBRARY_PATH')
add_path(v, ld_library_path, 'LD_LIBRARY_PATH')
else:
add_path(v, ld_library_path, 'LD_LIBRARY_PATH')
pp = Utils.pproc.Popen(filename, **kwargs)
(out, err) = pp.communicate() # uh, and the output is ignored?? - fortunately this is going to disappear
result = int(pp.returncode == self.returncode_ok)
if result:
self.num_tests_ok += 1
else:
self.num_tests_failed += 1
self.unit_test_results[label] = result
self.unit_test_erroneous[label] = 0
except OSError:
self.unit_test_erroneous[label] = 1
self.num_tests_err += 1
except KeyboardInterrupt:
pass
if Options.options.progress_bar: sys.stdout.write(Logs.colors.cursor_on)
def print_results(self):
"Pretty-prints a summary of all unit tests, along with some statistics"
# If waf is not building, don't output anything
if not Options.commands[self.run_if_waf_does]: return
p = Utils.pprint
# Early quit if no tests were performed
if self.total_num_tests == 0:
p('YELLOW', 'No unit tests present')
return
for label in self.unit_tests.allkeys:
filename = self.unit_tests[label]
err = 0
result = 0
try: err = self.unit_test_erroneous[label]
except KeyError: pass
try: result = self.unit_test_results[label]
except KeyError: pass
n = self.max_label_length - len(label)
if err: n += 4
elif result: n += 7
else: n += 3
line = '%s %s' % (label, '.' * n)
if err: p('RED', '%sERROR' % line)
elif result: p('GREEN', '%sOK' % line)
else: p('YELLOW', '%sFAILED' % line)
percentage_ok = float(self.num_tests_ok) / float(self.total_num_tests) * 100.0
percentage_failed = float(self.num_tests_failed) / float(self.total_num_tests) * 100.0
percentage_erroneous = float(self.num_tests_err) / float(self.total_num_tests) * 100.0
p('NORMAL', '''
Successful tests: %i (%.1f%%)
Failed tests: %i (%.1f%%)
Erroneous tests: %i (%.1f%%)
Total number of tests: %i
''' % (self.num_tests_ok, percentage_ok, self.num_tests_failed, percentage_failed,
self.num_tests_err, percentage_erroneous, self.total_num_tests))
p('GREEN', 'Unit tests finished')
############################################################################################
"""
New unit test system
The targets with feature 'test' are executed after they are built
bld(features='cprogram cc test', ...)
To display the results:
import UnitTest
bld.add_post_fun(UnitTest.summary)
"""
import threading
testlock = threading.Lock()
def set_options(opt):
opt.add_option('--alltests', action='store_true', default=True, help='Exec all unit tests', dest='all_tests')
@feature('test')
@after('apply_link', 'vars_target_cprogram')
def make_test(self):
if not 'cprogram' in self.features:
Logs.error('test cannot be executed %s' % self)
return
self.default_install_path = None
self.create_task('utest', self.link_task.outputs)
def exec_test(self):
status = 0
variant = self.env.variant()
filename = self.inputs[0].abspath(self.env)
self.ut_exec = getattr(self, 'ut_exec', [filename])
if getattr(self.generator, 'ut_fun', None):
self.generator.ut_fun(self)
try:
fu = getattr(self.generator.bld, 'all_test_paths')
except AttributeError:
fu = os.environ.copy()
self.generator.bld.all_test_paths = fu
lst = []
for obj in self.generator.bld.all_task_gen:
link_task = getattr(obj, 'link_task', None)
if link_task and link_task.env.variant() == variant:
lst.append(link_task.outputs[0].parent.abspath(obj.env))
def add_path(dct, path, var):
dct[var] = os.pathsep.join(Utils.to_list(path) + [os.environ.get(var, '')])
if sys.platform == 'win32':
add_path(fu, lst, 'PATH')
elif sys.platform == 'darwin':
add_path(fu, lst, 'DYLD_LIBRARY_PATH')
add_path(fu, lst, 'LD_LIBRARY_PATH')
else:
add_path(fu, lst, 'LD_LIBRARY_PATH')
cwd = getattr(self.generator, 'ut_cwd', '') or self.inputs[0].parent.abspath(self.env)
proc = Utils.pproc.Popen(self.ut_exec, cwd=cwd, env=fu, stderr=Utils.pproc.PIPE, stdout=Utils.pproc.PIPE)
(stdout, stderr) = proc.communicate()
tup = (filename, proc.returncode, stdout, stderr)
self.generator.utest_result = tup
testlock.acquire()
try:
bld = self.generator.bld
Logs.debug("ut: %r", tup)
try:
bld.utest_results.append(tup)
except AttributeError:
bld.utest_results = [tup]
finally:
testlock.release()
cls = Task.task_type_from_func('utest', func=exec_test, color='PINK', ext_in='.bin')
old = cls.runnable_status
def test_status(self):
ret = old(self)
if ret == SKIP_ME and getattr(Options.options, 'all_tests', False):
return RUN_ME
return ret
cls.runnable_status = test_status
cls.quiet = 1
def summary(bld):
lst = getattr(bld, 'utest_results', [])
if lst:
Utils.pprint('CYAN', 'execution summary')
total = len(lst)
tfail = len([x for x in lst if x[1]])
Utils.pprint('CYAN', ' tests that pass %d/%d' % (total-tfail, total))
for (f, code, out, err) in lst:
if not code:
Utils.pprint('CYAN', ' %s' % f)
Utils.pprint('CYAN', ' tests that fail %d/%d' % (tfail, total))
for (f, code, out, err) in lst:
if code:
Utils.pprint('CYAN', ' %s' % f)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14243,
11560,
3898,
667,
352,
598,
5653,
73,
12,
8315,
199,
199,
624,
199,
5072,
2295,
1255,
315,
314,
12842,
342,
1083,
12,
436,
367,
286,
15,
67,
4176,
18572,
199,
199,
4395,
1077,
2845,
1172,
370,
8120,
2633,
370,
18572,
370,
5341,
199,
199,
607,
314,
12842,
1083,
12,
1050,
314,
2569,
1233,
26,
421,
198,
6071,
347,
12842,
837,
199,
198,
1396,
198,
337,
275,
12008,
774,
14,
3248,
63,
396,
342,
199,
198,
1396,
198,
337,
14,
1065,
342,
199,
198,
1396,
198,
337,
14,
1361,
63,
2604,
342,
421,
199,
22321,
909,
370,
675,
465,
282,
4137,
511,
1471,
506,
282,
2240,
436,
1471,
1172,
1323,
91,
1113,
14,
3248,
63,
396,
29,
17,
93,
199,
624,
199,
646,
747,
12,
984,
199,
646,
6516,
12,
8495,
8168,
12,
17397,
12,
8394,
12,
3835,
458,
12,
8495,
199,
504,
8495,
8168,
492,
2544,
12,
2410,
12,
3878,
199,
504,
22296,
492,
627,
199,
199,
533,
4137,
63,
396,
8,
785,
304,
199,
198,
2,
5072,
511,
6025,
2,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
9913,
63,
745,
275,
378,
198,
198,
3,
12008,
511,
17630,
8652,
9949,
14,
2900,
372,
6021,
28488,
687,
642,
1373,
4671,
198,
3,
911,
7675,
314,
4137,
511,
370,
506,
11584,
465,
298,
12299,
1674,
2742,
198,
3,
710,
2569,
2860,
787,
13457,
543,
666,
701,
1255,
1252,
2742,
198,
3,
870,
63,
2604,
342,
4440,
3520,
367,
16116,
314,
4137,
511,
6212,
12,
507,
198,
3,
1325,
340,
2337,
365,
1929,
367,
4125,
2879,
370,
314,
2058,
12,
507,
198,
3,
2985,
883,
506,
12396,
2348,
12,
2410,
6358,
1255,
1252,
2742,
198,
277,
14,
1507,
63,
2219,
63,
745,
275,
378,
198,
198,
3,
4860,
402,
9512,
4137,
2295,
507,
198,
277,
14,
1507,
63,
2219,
63,
4892,
275,
378,
198,
3,
4860,
402,
3405,
4137,
2295,
507,
198,
277,
14,
1507,
63,
2219,
63,
1508,
275,
378,
198,
198,
3,
6496,
626,
1172,
440,
2755,
1255,
507,
198,
277,
14,
2923,
63,
1507,
63,
2219,
275,
378,
198,
3,
19271,
5982,
402,
4137,
2295,
507,
198,
277,
14,
988,
63,
1302,
63,
1267,
275,
378,
198,
3,
14212,
1768,
2582,
334,
9118,
13,
1361,
314,
1072,
9,
2742,
198,
277,
14,
3248,
63,
2219,
275,
17397,
14,
8235,
63,
807,
342,
198,
198,
3,
12008,
511,
2600,
14,
2606,
26,
314,
1768,
334,
3248,
511,
1788,
3847,
4671,
198,
3,
370,
314,
1900,
2935,
395,
574,
26,
4137,
511,
1788,
543,
3679,
931,
507,
198,
277,
14,
3248,
63,
396,
63,
2604,
275,
1052,
198,
3,
11932,
3035,
314,
4137,
511,
2058,
14,
4671,
198,
3,
2606,
26,
314,
1768,
12,
574,
26,
754,
334,
2052,
275,
3182,
3055,
275,
5988,
9,
507,
198,
277,
14,
3248,
63,
396,
63,
1508,
368,
1785,
275,
1052,
198,
3,
11932,
9297,
2329,
368,
1785,
4137,
2295,
14,
4671,
198,
3,
2606,
26,
314,
1768,
12,
574,
26,
2549,
275,
4137,
511,
965,
376,
1125,
221,
3055,
275,
4137,
511,
365,
4112,
507,
198,
277,
14,
1461,
63,
475,
63,
21091,
63,
694,
275,
756,
327,
549,
340,
314,
511,
570,
4839,
370,
506,
7934,
687,
314,
2011,
2935,
507,
198,
277,
14,
7051,
63,
475,
63,
3239,
63,
396,
63,
1199,
275,
756,
327,
549,
370,
1937,
314,
3839,
687,
314,
30530,
334,
509,
2893,
1104,
24203,
9,
507,
198,
277,
14,
7051,
63,
475,
63,
3239,
63,
396,
63,
705,
275,
756,
327,
549,
370,
1937,
314,
4635,
687,
314,
30530,
334,
509,
2893,
1104,
24203,
9,
507,
198,
277,
14,
1065,
63,
692,
63,
21500,
63,
9105,
275,
283,
1074,
7,
327,
1506,
1990,
314,
2269,
849,
421,
198,
318,
1255,
8,
277,
304,
507,
198,
2,
2540,
314,
4137,
2295,
436,
13082,
2058,
334,
4610,
26,
949,
1072,
2348,
2924,
2742,
198,
277,
14,
1507,
63,
2219,
63,
745,
275,
378,
507,
198,
277,
14,
1507,
63,
2219,
63,
4892,
275,
378,
507,
198,
277,
14,
1507,
63,
2219,
63,
1508,
275,
378,
507,
198,
277,
14,
2923,
63,
1507,
63,
2219,
275,
378,
507,
198,
277,
14,
988,
63,
1302,
63,
1267,
275,
378,
2742,
198,
277,
14,
3248,
63,
2219,
275,
17397,
14,
8235,
63,
807,
342,
507,
198,
277,
14,
3248,
63,
396,
63,
2604,
275,
1052,
507,
198,
277,
14,
3248,
63,
396,
63,
1508,
368,
1785,
275,
1052,
2742,
198,
1447,
63,
4342,
63,
515,
275,
942,
2742,
198,
3,
982,
25782,
365,
440,
10015,
12,
2793,
1133,
1255,
7003,
507,
198,
692,
440,
8394,
14,
4405,
59,
277,
14,
1065,
63,
692,
63,
21500,
63,
9105,
2189,
372,
2742,
198,
3,
2372,
314,
3792,
367,
314,
5709,
8363,
12,
436,
3332,
314,
4137,
2295,
370,
5341,
507,
198,
509,
1559,
315,
6516,
14,
14341,
14,
452,
63,
1765,
63,
2268,
26,
686,
198,
893,
26,
1585,
198,
1073,
63,
1765,
275,
1559,
14,
1073,
63,
1765,
686,
198,
2590,
4281,
26,
1585,
198,
1529,
686,
198,
2836,
26,
1585,
198,
773,
63,
515,
275,
2142,
63,
1765,
14,
4467,
59,
16,
1055,
1708,
14,
4832,
8,
1113,
14,
1813,
9,
1585,
198,
692,
1973,
63,
515,
440,
315,
8827,
63,
4342,
63,
515,
26,
1871,
198,
1447,
63,
4342,
63,
515,
14,
740,
8,
773,
63,
515,
9,
6319,
198,
3248,
63,
396,
275,
2519,
8,
1113,
12,
283,
3248,
63,
396,
297,
4074,
686,
198,
692,
4137,
63,
396,
436,
283,
67,
6815,
7,
315,
1559,
14,
3179,
26,
1585,
198,
893,
26,
1871,
198,
1199,
275,
1559,
14,
515,
1871,
198,
1501,
275,
747,
14,
515,
14,
904,
8,
1199,
14,
4832,
8,
1113,
14,
1813,
395,
1559,
14,
1375,
9,
1871,
198,
17878,
275,
1072,
14,
4832,
342,
1871,
198,
1302,
275,
747,
14,
515,
14,
904,
8,
1199,
14,
14341,
515,
8,
1113,
14,
1813,
395,
1559,
14,
1375,
9,
1871,
198,
277,
14,
988,
63,
1302,
63,
1267,
275,
1390,
8,
277,
14,
988,
63,
1302,
63,
1267,
12,
822,
8,
1302,
430,
1871,
198,
277,
14,
3248
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14243,
11560,
3898,
667,
352,
598,
5653,
73,
12,
8315,
199,
199,
624,
199,
5072,
2295,
1255,
315,
314,
12842,
342,
1083,
12,
436,
367,
286,
15,
67,
4176,
18572,
199,
199,
4395,
1077,
2845,
1172,
370,
8120,
2633,
370,
18572,
370,
5341,
199,
199,
607,
314,
12842,
1083,
12,
1050,
314,
2569,
1233,
26,
421,
198,
6071,
347,
12842,
837,
199,
198,
1396,
198,
337,
275,
12008,
774,
14,
3248,
63,
396,
342,
199,
198,
1396,
198,
337,
14,
1065,
342,
199,
198,
1396,
198,
337,
14,
1361,
63,
2604,
342,
421,
199,
22321,
909,
370,
675,
465,
282,
4137,
511,
1471,
506,
282,
2240,
436,
1471,
1172,
1323,
91,
1113,
14,
3248,
63,
396,
29,
17,
93,
199,
624,
199,
646,
747,
12,
984,
199,
646,
6516,
12,
8495,
8168,
12,
17397,
12,
8394,
12,
3835,
458,
12,
8495,
199,
504,
8495,
8168,
492,
2544,
12,
2410,
12,
3878,
199,
504,
22296,
492,
627,
199,
199,
533,
4137,
63,
396,
8,
785,
304,
199,
198,
2,
5072,
511,
6025,
2,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
9913,
63,
745,
275,
378,
198,
198,
3,
12008,
511,
17630,
8652,
9949,
14,
2900,
372,
6021,
28488,
687,
642,
1373,
4671,
198,
3,
911,
7675,
314,
4137,
511,
370,
506,
11584,
465,
298,
12299,
1674,
2742,
198,
3,
710,
2569,
2860,
787,
13457,
543,
666,
701,
1255,
1252,
2742,
198,
3,
870,
63,
2604,
342,
4440,
3520,
367,
16116,
314,
4137,
511,
6212,
12,
507,
198,
3,
1325,
340,
2337,
365,
1929,
367,
4125,
2879,
370,
314,
2058,
12,
507,
198,
3,
2985,
883,
506,
12396,
2348,
12,
2410,
6358,
1255,
1252,
2742,
198,
277,
14,
1507,
63,
2219,
63,
745,
275,
378,
198,
198,
3,
4860,
402,
9512,
4137,
2295,
507,
198,
277,
14,
1507,
63,
2219,
63,
4892,
275,
378,
198,
3,
4860,
402,
3405,
4137,
2295,
507,
198,
277,
14,
1507,
63,
2219,
63,
1508,
275,
378,
198,
198,
3,
6496,
626,
1172,
440,
2755,
1255,
507,
198,
277,
14,
2923,
63,
1507,
63,
2219,
275,
378,
198,
3,
19271,
5982,
402,
4137,
2295,
507,
198,
277,
14,
988,
63,
1302,
63,
1267,
275,
378,
198,
3,
14212,
1768,
2582,
334,
9118,
13,
1361,
314,
1072,
9,
2742,
198,
277,
14,
3248,
63,
2219,
275,
17397,
14,
8235,
63,
807,
342,
198,
198,
3,
12008,
511,
2600,
14,
2606,
26,
314,
1768,
334,
3248,
511,
1788,
3847,
4671,
198,
3,
370,
314,
1900,
2935,
395,
574,
26,
4137,
511,
1788,
543,
3679,
931,
507,
198,
277,
14,
3248,
63,
396,
63,
2604,
275,
1052,
198,
3,
11932,
3035,
314,
4137,
511,
2058,
14,
4671,
198,
3,
2606,
26,
314,
1768,
12,
574,
26,
754,
334,
2052,
275,
3182,
3055,
275,
5988,
9,
507,
198,
277,
14,
3248,
63,
396,
63,
1508,
368,
1785,
275,
1052,
198,
3,
11932,
9297,
2329,
368,
1785,
4137,
2295,
14,
4671,
198,
3,
2606,
26,
314,
1768,
12,
574,
26,
2549,
275,
4137,
511,
965,
376,
1125,
221,
3055,
275,
4137,
511,
365,
4112,
507,
198,
277,
14,
1461,
63,
475,
63,
21091,
63,
694,
275,
756,
327,
549,
340,
314,
511,
570,
4839,
370,
506,
7934,
687,
314,
2011,
2935,
507,
198,
277,
14,
7051,
63,
475,
63,
3239,
63,
396,
63,
1199,
275,
756,
327,
549,
370,
1937,
314,
3839,
687,
314,
30530,
334,
509,
2893,
1104,
24203,
9,
507,
198,
277,
14,
7051,
63,
475,
63,
3239,
63,
396,
63,
705,
275,
756,
327,
549,
370,
1937,
314,
4635,
687,
314,
30530,
334,
509,
2893,
1104,
24203,
9,
507,
198,
277,
14,
1065,
63,
692,
63,
21500,
63,
9105,
275,
283,
1074,
7,
327,
1506,
1990,
314,
2269,
849,
421,
198,
318,
1255,
8,
277,
304,
507,
198,
2,
2540,
314,
4137,
2295,
436,
13082,
2058,
334,
4610,
26,
949,
1072,
2348,
2924,
2742,
198,
277,
14,
1507,
63,
2219,
63,
745,
275,
378,
507,
198,
277,
14,
1507,
63,
2219,
63,
4892,
275,
378,
507,
198,
277,
14,
1507,
63,
2219,
63,
1508,
275,
378,
507,
198,
277,
14,
2923,
63,
1507,
63,
2219,
275,
378,
507,
198,
277,
14,
988,
63,
1302,
63,
1267,
275,
378,
2742,
198,
277,
14,
3248,
63,
2219,
275,
17397,
14,
8235,
63,
807,
342,
507,
198,
277,
14,
3248,
63,
396,
63,
2604,
275,
1052,
507,
198,
277,
14,
3248,
63,
396,
63,
1508,
368,
1785,
275,
1052,
2742,
198,
1447,
63,
4342,
63,
515,
275,
942,
2742,
198,
3,
982,
25782,
365,
440,
10015,
12,
2793,
1133,
1255,
7003,
507,
198,
692,
440,
8394,
14,
4405,
59,
277,
14,
1065,
63,
692,
63,
21500,
63,
9105,
2189,
372,
2742,
198,
3,
2372,
314,
3792,
367,
314,
5709,
8363,
12,
436,
3332,
314,
4137,
2295,
370,
5341,
507,
198,
509,
1559,
315,
6516,
14,
14341,
14,
452,
63,
1765,
63,
2268,
26,
686,
198,
893,
26,
1585,
198,
1073,
63,
1765,
275,
1559,
14,
1073,
63,
1765,
686,
198,
2590,
4281,
26,
1585,
198,
1529,
686,
198,
2836,
26,
1585,
198,
773,
63,
515,
275,
2142,
63,
1765,
14,
4467,
59,
16,
1055,
1708,
14,
4832,
8,
1113,
14,
1813,
9,
1585,
198,
692,
1973,
63,
515,
440,
315,
8827,
63,
4342,
63,
515,
26,
1871,
198,
1447,
63,
4342,
63,
515,
14,
740,
8,
773,
63,
515,
9,
6319,
198,
3248,
63,
396,
275,
2519,
8,
1113,
12,
283,
3248,
63,
396,
297,
4074,
686,
198,
692,
4137,
63,
396,
436,
283,
67,
6815,
7,
315,
1559,
14,
3179,
26,
1585,
198,
893,
26,
1871,
198,
1199,
275,
1559,
14,
515,
1871,
198,
1501,
275,
747,
14,
515,
14,
904,
8,
1199,
14,
4832,
8,
1113,
14,
1813,
395,
1559,
14,
1375,
9,
1871,
198,
17878,
275,
1072,
14,
4832,
342,
1871,
198,
1302,
275,
747,
14,
515,
14,
904,
8,
1199,
14,
14341,
515,
8,
1113,
14,
1813,
395,
1559,
14,
1375,
9,
1871,
198,
277,
14,
988,
63,
1302,
63,
1267,
275,
1390,
8,
277,
14,
988,
63,
1302,
63,
1267,
12,
822,
8,
1302,
430,
1871,
198,
277,
14,
3248,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cwu2011/scikit-learn
|
sklearn/preprocessing/__init__.py
|
14
|
1184
|
"""
The :mod:`sklearn.preprocessing` module includes scaling, centering,
normalization, binarization and imputation methods.
"""
from .data import Binarizer
from .data import KernelCenterer
from .data import MinMaxScaler
from .data import MaxAbsScaler
from .data import Normalizer
from .data import RobustScaler
from .data import StandardScaler
from .data import add_dummy_feature
from .data import binarize
from .data import normalize
from .data import scale
from .data import robust_scale
from .data import maxabs_scale
from .data import OneHotEncoder
from .data import PolynomialFeatures
from .label import label_binarize
from .label import LabelBinarizer
from .label import LabelEncoder
from .label import MultiLabelBinarizer
from .imputation import Imputer
__all__ = [
'Binarizer',
'Imputer',
'KernelCenterer',
'LabelBinarizer',
'LabelEncoder',
'MultiLabelBinarizer',
'MinMaxScaler',
'MaxAbsScaler',
'Normalizer',
'OneHotEncoder',
'RobustScaler',
'StandardScaler',
'add_dummy_feature',
'PolynomialFeatures',
'binarize',
'normalize',
'scale',
'robust_scale',
'maxabs_scale',
'label_binarize',
]
|
bsd-3-clause
|
[
624,
199,
1918,
520,
1494,
1705,
27993,
14,
21402,
64,
859,
6952,
13690,
12,
8126,
316,
12,
199,
22384,
12,
2517,
285,
2072,
436,
1742,
10326,
3102,
14,
199,
624,
199,
199,
504,
1275,
576,
492,
32613,
31008,
199,
504,
1275,
576,
492,
24901,
18345,
266,
3859,
199,
504,
1275,
576,
492,
10195,
4261,
24274,
199,
504,
1275,
576,
492,
8228,
15447,
24274,
199,
504,
1275,
576,
492,
11514,
1793,
199,
504,
1275,
576,
492,
6848,
15549,
24274,
199,
504,
1275,
576,
492,
9739,
24274,
199,
504,
1275,
576,
492,
1050,
63,
5869,
63,
4445,
199,
504,
1275,
576,
492,
2517,
285,
794,
199,
504,
1275,
576,
492,
7666,
199,
504,
1275,
576,
492,
4666,
199,
504,
1275,
576,
492,
23399,
63,
3467,
199,
504,
1275,
576,
492,
1390,
2101,
63,
3467,
199,
504,
1275,
576,
492,
7309,
19942,
6679,
199,
199,
504,
1275,
576,
492,
8467,
8887,
10807,
199,
199,
504,
1275,
1302,
492,
1768,
63,
1393,
285,
794,
199,
504,
1275,
1302,
492,
10354,
13394,
31008,
199,
504,
1275,
1302,
492,
10354,
6679,
199,
504,
1275,
1302,
492,
6879,
4314,
13394,
31008,
199,
199,
504,
1275,
3236,
10326,
492,
8362,
2699,
199,
199,
363,
452,
363,
275,
359,
272,
283,
13394,
31008,
297,
272,
283,
8499,
2699,
297,
272,
283,
14127,
18345,
266,
3859,
297,
272,
283,
4314,
13394,
31008,
297,
272,
283,
4314,
6679,
297,
272,
283,
3947,
4314,
13394,
31008,
297,
272,
283,
29334,
24274,
297,
272,
283,
4261,
15447,
24274,
297,
272,
283,
6241,
1793,
297,
272,
283,
4395,
19942,
6679,
297,
272,
283,
3863,
15549,
24274,
297,
272,
283,
9232,
24274,
297,
272,
283,
525,
63,
5869,
63,
4445,
297,
272,
283,
5858,
8887,
10807,
297,
272,
283,
1393,
285,
794,
297,
272,
283,
7721,
297,
272,
283,
3467,
297,
272,
283,
293,
15549,
63,
3467,
297,
272,
283,
988,
2101,
63,
3467,
297,
272,
283,
1302,
63,
1393,
285,
794,
297,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1918,
520,
1494,
1705,
27993,
14,
21402,
64,
859,
6952,
13690,
12,
8126,
316,
12,
199,
22384,
12,
2517,
285,
2072,
436,
1742,
10326,
3102,
14,
199,
624,
199,
199,
504,
1275,
576,
492,
32613,
31008,
199,
504,
1275,
576,
492,
24901,
18345,
266,
3859,
199,
504,
1275,
576,
492,
10195,
4261,
24274,
199,
504,
1275,
576,
492,
8228,
15447,
24274,
199,
504,
1275,
576,
492,
11514,
1793,
199,
504,
1275,
576,
492,
6848,
15549,
24274,
199,
504,
1275,
576,
492,
9739,
24274,
199,
504,
1275,
576,
492,
1050,
63,
5869,
63,
4445,
199,
504,
1275,
576,
492,
2517,
285,
794,
199,
504,
1275,
576,
492,
7666,
199,
504,
1275,
576,
492,
4666,
199,
504,
1275,
576,
492,
23399,
63,
3467,
199,
504,
1275,
576,
492,
1390,
2101,
63,
3467,
199,
504,
1275,
576,
492,
7309,
19942,
6679,
199,
199,
504,
1275,
576,
492,
8467,
8887,
10807,
199,
199,
504,
1275,
1302,
492,
1768,
63,
1393,
285,
794,
199,
504,
1275,
1302,
492,
10354,
13394,
31008,
199,
504,
1275,
1302,
492,
10354,
6679,
199,
504,
1275,
1302,
492,
6879,
4314,
13394,
31008,
199,
199,
504,
1275,
3236,
10326,
492,
8362,
2699,
199,
199,
363,
452,
363,
275,
359,
272,
283,
13394,
31008,
297,
272,
283,
8499,
2699,
297,
272,
283,
14127,
18345,
266,
3859,
297,
272,
283,
4314,
13394,
31008,
297,
272,
283,
4314,
6679,
297,
272,
283,
3947,
4314,
13394,
31008,
297,
272,
283,
29334,
24274,
297,
272,
283,
4261,
15447,
24274,
297,
272,
283,
6241,
1793,
297,
272,
283,
4395,
19942,
6679,
297,
272,
283,
3863,
15549,
24274,
297,
272,
283,
9232,
24274,
297,
272,
283,
525,
63,
5869,
63,
4445,
297,
272,
283,
5858,
8887,
10807,
297,
272,
283,
1393,
285,
794,
297,
272,
283,
7721,
297,
272,
283,
3467,
297,
272,
283,
293,
15549,
63,
3467,
297,
272,
283,
988,
2101,
63,
3467,
297,
272,
283,
1302,
63,
1393,
285,
794,
297,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
NeCTAR-RC/horizon
|
openstack_dashboard/dashboards/project/vg_snapshots/tests.py
|
3
|
8730
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.urls import reverse
import mock
from openstack_dashboard.api import cinder
from openstack_dashboard.test import helpers as test
INDEX_URL = reverse('horizon:project:vg_snapshots:index')
class GroupSnapshotTests(test.TestCase):
@mock.patch.object(cinder, 'group_snapshot_get')
@mock.patch.object(cinder, 'group_create_from_source')
def test_create_group_from_snapshot(self,
mock_group_create_from_source,
mock_group_snapshot_get):
group = self.cinder_groups.first()
vg_snapshot = self.cinder_group_snapshots.first()
formData = {'vg_snapshot_id': vg_snapshot.id,
'name': 'test VG SS Create',
'description': 'test desc'}
mock_group_snapshot_get.return_value = vg_snapshot
mock_group_create_from_source.return_value = group
url = reverse('horizon:project:vg_snapshots:create_group',
args=[vg_snapshot.id])
res = self.client.post(url, formData)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(
res, reverse('horizon:project:volume_groups:index'))
mock_group_snapshot_get.assert_called_once_with(
test.IsHttpRequest(), vg_snapshot.id)
mock_group_create_from_source.assert_called_once_with(
test.IsHttpRequest(),
formData['name'],
group_snapshot_id=formData['vg_snapshot_id'],
description=formData['description'])
@mock.patch.object(cinder, 'group_snapshot_get')
@mock.patch.object(cinder, 'group_create_from_source')
def test_create_group_from_snapshot_exception(
self,
mock_group_create_from_source,
mock_group_snapshot_get):
vg_snapshot = self.cinder_group_snapshots.first()
new_cg_name = 'test VG SS Create'
formData = {'vg_snapshot_id': vg_snapshot.id,
'name': new_cg_name,
'description': 'test desc'}
mock_group_snapshot_get.return_value = vg_snapshot
mock_group_create_from_source.side_effect = \
self.exceptions.cinder
url = reverse('horizon:project:vg_snapshots:create_group',
args=[vg_snapshot.id])
res = self.client.post(url, formData)
self.assertNoFormErrors(res)
# There are a bunch of backslashes for formatting in the message from
# the response, so remove them when validating the error message.
self.assertIn('Unable to create group "%s" from snapshot.'
% new_cg_name,
res.cookies.output().replace('\\', ''))
self.assertRedirectsNoFollow(res, INDEX_URL)
mock_group_snapshot_get.assert_called_once_with(
test.IsHttpRequest(), vg_snapshot.id)
mock_group_create_from_source.assert_called_once_with(
test.IsHttpRequest(),
formData['name'],
group_snapshot_id=formData['vg_snapshot_id'],
description=formData['description'])
@mock.patch.object(cinder, 'group_snapshot_list')
@mock.patch.object(cinder, 'group_snapshot_delete')
@mock.patch.object(cinder, 'group_list')
def test_delete_group_snapshot(self,
mock_group_list,
mock_group_snapshot_delete,
mock_group_snapshot_list):
vg_snapshots = self.cinder_group_snapshots.list()
vg_snapshot = self.cinder_group_snapshots.first()
mock_group_snapshot_list.return_value = vg_snapshots
mock_group_snapshot_delete.return_value = None
mock_group_list.return_value = self.cinder_groups.list()
form_data = {'action': 'volume_vg_snapshots__delete_vg_snapshot__%s'
% vg_snapshot.id}
res = self.client.post(INDEX_URL, form_data, follow=True)
self.assertEqual(res.status_code, 200)
self.assertIn("Scheduled deletion of Snapshot: %s" % vg_snapshot.name,
[m.message for m in res.context['messages']])
self.assert_mock_multiple_calls_with_same_arguments(
mock_group_snapshot_list, 2,
mock.call(test.IsHttpRequest()))
mock_group_snapshot_delete.assert_called_once_with(
test.IsHttpRequest(), vg_snapshot.id)
self.assert_mock_multiple_calls_with_same_arguments(
mock_group_list, 2,
mock.call(test.IsHttpRequest()))
@mock.patch.object(cinder, 'group_snapshot_list')
@mock.patch.object(cinder, 'group_snapshot_delete')
@mock.patch.object(cinder, 'group_list')
def test_delete_group_snapshot_exception(self,
mock_group_list,
mock_group_snapshot_delete,
mock_group_snapshot_list):
vg_snapshots = self.cinder_group_snapshots.list()
vg_snapshot = self.cinder_group_snapshots.first()
mock_group_snapshot_list.return_value = vg_snapshots
mock_group_snapshot_delete.side_effect = self.exceptions.cinder
mock_group_list.return_value = self.cinder_groups.list()
form_data = {'action': 'volume_vg_snapshots__delete_vg_snapshot__%s'
% vg_snapshot.id}
res = self.client.post(INDEX_URL, form_data, follow=True)
self.assertEqual(res.status_code, 200)
self.assertIn("Unable to delete snapshot: %s" % vg_snapshot.name,
[m.message for m in res.context['messages']])
self.assert_mock_multiple_calls_with_same_arguments(
mock_group_snapshot_list, 2,
mock.call(test.IsHttpRequest()))
mock_group_snapshot_delete.assert_called_once_with(
test.IsHttpRequest(), vg_snapshot.id)
self.assert_mock_multiple_calls_with_same_arguments(
mock_group_list, 2,
mock.call(test.IsHttpRequest()))
@mock.patch.object(cinder, 'group_snapshot_get')
@mock.patch.object(cinder, 'group_get')
@mock.patch.object(cinder, 'volume_type_get')
@mock.patch.object(cinder, 'volume_list')
def test_detail_view(self,
mock_volume_list,
mock_volume_type_get,
mock_group_get,
mock_group_snapshot_get):
vg_snapshot = self.cinder_group_snapshots.first()
group = self.cinder_groups.first()
volume_type = self.cinder_volume_types.first()
volumes = self.cinder_volumes.list()
mock_group_snapshot_get.return_value = vg_snapshot
mock_group_get.return_value = group
mock_volume_type_get.return_value = volume_type
mock_volume_list.return_value = volumes
url = reverse(
'horizon:project:vg_snapshots:detail',
args=[vg_snapshot.id])
res = self.client.get(url)
self.assertNoFormErrors(res)
self.assertEqual(res.status_code, 200)
mock_group_snapshot_get.assert_called_once_with(
test.IsHttpRequest(), vg_snapshot.id)
mock_group_get.assert_called_once_with(
test.IsHttpRequest(), group.id)
mock_volume_type_get.assert_called_once_with(
test.IsHttpRequest(), volume_type.id)
search_opts = {'group_id': group.id}
mock_volume_list.assert_called_once_with(
test.IsHttpRequest(), search_opts=search_opts)
@mock.patch.object(cinder, 'group_snapshot_get')
def test_detail_view_with_exception(self, mock_group_snapshot_get):
vg_snapshot = self.cinder_group_snapshots.first()
mock_group_snapshot_get.side_effect = self.exceptions.cinder
url = reverse(
'horizon:project:vg_snapshots:detail',
args=[vg_snapshot.id])
res = self.client.get(url)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
mock_group_snapshot_get.assert_called_once_with(
test.IsHttpRequest(), vg_snapshot.id)
|
apache-2.0
|
[
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
3603,
492,
3837,
199,
646,
1683,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
13069,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
465,
511,
421,
199,
10215,
63,
2632,
275,
3837,
360,
16561,
26,
1715,
26,
10929,
63,
15331,
26,
1080,
358,
421,
199,
533,
5611,
12038,
2925,
8,
396,
14,
1746,
304,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
4753,
63,
362,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
981,
63,
504,
63,
1365,
358,
272,
347,
511,
63,
981,
63,
923,
63,
504,
63,
4753,
8,
277,
12,
3147,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
12,
3147,
1683,
63,
923,
63,
4753,
63,
362,
304,
267,
1572,
275,
291,
14,
12372,
63,
2634,
14,
2246,
342,
267,
23842,
63,
4753,
275,
291,
14,
12372,
63,
923,
63,
15331,
14,
2246,
342,
267,
1824,
1451,
275,
791,
10929,
63,
4753,
63,
344,
356,
23842,
63,
4753,
14,
344,
12,
490,
283,
354,
356,
283,
396,
812,
39,
32101,
2790,
297,
490,
283,
1802,
356,
283,
396,
4328,
936,
398,
1683,
63,
923,
63,
4753,
63,
362,
14,
1107,
63,
585,
275,
23842,
63,
4753,
267,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
14,
1107,
63,
585,
275,
1572,
398,
1166,
275,
3837,
360,
16561,
26,
1715,
26,
10929,
63,
15331,
26,
981,
63,
923,
297,
1993,
1249,
1524,
10929,
63,
4753,
14,
344,
566,
267,
522,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
1824,
1451,
9,
267,
291,
14,
22389,
2821,
9298,
8,
470,
9,
267,
291,
14,
17466,
1944,
18696,
8,
288,
522,
12,
3837,
360,
16561,
26,
1715,
26,
2405,
63,
2634,
26,
1080,
1333,
398,
1683,
63,
923,
63,
4753,
63,
362,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
511,
14,
1831,
10441,
1062,
23842,
63,
4753,
14,
344,
9,
267,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
511,
14,
1831,
10441,
1062,
288,
1824,
1451,
459,
354,
995,
288,
1572,
63,
4753,
63,
344,
29,
964,
1451,
459,
10929,
63,
4753,
63,
344,
995,
288,
1369,
29,
964,
1451,
459,
1802,
1105,
339,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
4753,
63,
362,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
981,
63,
504,
63,
1365,
358,
272,
347,
511,
63,
981,
63,
923,
63,
504,
63,
4753,
63,
1971,
8,
288,
291,
12,
288,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
12,
288,
1683,
63,
923,
63,
4753,
63,
362,
304,
267,
23842,
63,
4753,
275,
291,
14,
12372,
63,
923,
63,
15331,
14,
2246,
342,
267,
892,
63,
12595,
63,
354,
275,
283,
396,
812,
39,
32101,
2790,
7,
267,
1824,
1451,
275,
791,
10929,
63,
4753,
63,
344,
356,
23842,
63,
4753,
14,
344,
12,
490,
283,
354,
356,
892,
63,
12595,
63,
354,
12,
490,
283,
1802,
356,
283,
396,
4328,
936,
398,
1683,
63,
923,
63,
4753,
63,
362,
14,
1107,
63,
585,
275,
23842,
63,
4753,
267,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
14,
2441,
63,
5881,
275,
971,
288,
291,
14,
3924,
14,
12372,
398,
1166,
275,
3837,
360,
16561,
26,
1715,
26,
10929,
63,
15331,
26,
981,
63,
923,
297,
1993,
1249,
1524,
10929,
63,
4753,
14,
344,
566,
267,
522,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
1824,
1451,
9,
267,
291,
14,
22389,
2821,
9298,
8,
470,
9,
267,
327,
6006,
787,
282,
22219,
402,
23396,
367,
10803,
315,
314,
1245,
687,
267,
327,
314,
1177,
12,
880,
2813,
3062,
1380,
1686,
1958,
314,
1125,
1245,
14,
267,
291,
14,
4080,
360,
6005,
370,
1218,
1572,
2071,
83,
2,
687,
5740,
3530,
1993,
450,
892,
63,
12595,
63,
354,
12,
1993,
522,
14,
7792,
14,
1199,
1252,
1814,
20786,
12381,
267,
291,
14,
17466,
1944,
18696,
8,
470,
12,
17055,
63,
2632,
9,
398,
1683,
63,
923,
63,
4753,
63,
362,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
511,
14,
1831,
10441,
1062,
23842,
63,
4753,
14,
344,
9,
267,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
511,
14,
1831,
10441,
1062,
288,
1824,
1451,
459,
354,
995,
288,
1572,
63,
4753,
63,
344,
29,
964,
1451,
459,
10929,
63,
4753,
63,
344,
995,
288,
1369,
29,
964,
1451,
459,
1802,
1105,
339,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
4753,
63,
513,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
4753,
63,
1807,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
513,
358,
272,
347,
511,
63,
1807,
63,
923,
63,
4753,
8,
277,
12,
3521,
1683,
63,
923,
63,
513,
12,
3521,
1683,
63,
923,
63,
4753,
63,
1807,
12,
3521,
1683,
63,
923,
63,
4753,
63,
513,
304,
267,
23842,
63,
15331,
275,
291,
14,
12372,
63,
923,
63,
15331,
14,
513,
342,
267,
23842,
63,
4753,
275,
291,
14,
12372,
63,
923,
63,
15331,
14,
2246,
342,
398,
1683,
63,
923,
63,
4753,
63,
513,
14
] |
[
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
3603,
492,
3837,
199,
646,
1683,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
13069,
199,
504,
13869,
63,
9743,
14,
396,
492,
10897,
465,
511,
421,
199,
10215,
63,
2632,
275,
3837,
360,
16561,
26,
1715,
26,
10929,
63,
15331,
26,
1080,
358,
421,
199,
533,
5611,
12038,
2925,
8,
396,
14,
1746,
304,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
4753,
63,
362,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
981,
63,
504,
63,
1365,
358,
272,
347,
511,
63,
981,
63,
923,
63,
504,
63,
4753,
8,
277,
12,
3147,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
12,
3147,
1683,
63,
923,
63,
4753,
63,
362,
304,
267,
1572,
275,
291,
14,
12372,
63,
2634,
14,
2246,
342,
267,
23842,
63,
4753,
275,
291,
14,
12372,
63,
923,
63,
15331,
14,
2246,
342,
267,
1824,
1451,
275,
791,
10929,
63,
4753,
63,
344,
356,
23842,
63,
4753,
14,
344,
12,
490,
283,
354,
356,
283,
396,
812,
39,
32101,
2790,
297,
490,
283,
1802,
356,
283,
396,
4328,
936,
398,
1683,
63,
923,
63,
4753,
63,
362,
14,
1107,
63,
585,
275,
23842,
63,
4753,
267,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
14,
1107,
63,
585,
275,
1572,
398,
1166,
275,
3837,
360,
16561,
26,
1715,
26,
10929,
63,
15331,
26,
981,
63,
923,
297,
1993,
1249,
1524,
10929,
63,
4753,
14,
344,
566,
267,
522,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
1824,
1451,
9,
267,
291,
14,
22389,
2821,
9298,
8,
470,
9,
267,
291,
14,
17466,
1944,
18696,
8,
288,
522,
12,
3837,
360,
16561,
26,
1715,
26,
2405,
63,
2634,
26,
1080,
1333,
398,
1683,
63,
923,
63,
4753,
63,
362,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
511,
14,
1831,
10441,
1062,
23842,
63,
4753,
14,
344,
9,
267,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
511,
14,
1831,
10441,
1062,
288,
1824,
1451,
459,
354,
995,
288,
1572,
63,
4753,
63,
344,
29,
964,
1451,
459,
10929,
63,
4753,
63,
344,
995,
288,
1369,
29,
964,
1451,
459,
1802,
1105,
339,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
4753,
63,
362,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
981,
63,
504,
63,
1365,
358,
272,
347,
511,
63,
981,
63,
923,
63,
504,
63,
4753,
63,
1971,
8,
288,
291,
12,
288,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
12,
288,
1683,
63,
923,
63,
4753,
63,
362,
304,
267,
23842,
63,
4753,
275,
291,
14,
12372,
63,
923,
63,
15331,
14,
2246,
342,
267,
892,
63,
12595,
63,
354,
275,
283,
396,
812,
39,
32101,
2790,
7,
267,
1824,
1451,
275,
791,
10929,
63,
4753,
63,
344,
356,
23842,
63,
4753,
14,
344,
12,
490,
283,
354,
356,
892,
63,
12595,
63,
354,
12,
490,
283,
1802,
356,
283,
396,
4328,
936,
398,
1683,
63,
923,
63,
4753,
63,
362,
14,
1107,
63,
585,
275,
23842,
63,
4753,
267,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
14,
2441,
63,
5881,
275,
971,
288,
291,
14,
3924,
14,
12372,
398,
1166,
275,
3837,
360,
16561,
26,
1715,
26,
10929,
63,
15331,
26,
981,
63,
923,
297,
1993,
1249,
1524,
10929,
63,
4753,
14,
344,
566,
267,
522,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
1824,
1451,
9,
267,
291,
14,
22389,
2821,
9298,
8,
470,
9,
267,
327,
6006,
787,
282,
22219,
402,
23396,
367,
10803,
315,
314,
1245,
687,
267,
327,
314,
1177,
12,
880,
2813,
3062,
1380,
1686,
1958,
314,
1125,
1245,
14,
267,
291,
14,
4080,
360,
6005,
370,
1218,
1572,
2071,
83,
2,
687,
5740,
3530,
1993,
450,
892,
63,
12595,
63,
354,
12,
1993,
522,
14,
7792,
14,
1199,
1252,
1814,
20786,
12381,
267,
291,
14,
17466,
1944,
18696,
8,
470,
12,
17055,
63,
2632,
9,
398,
1683,
63,
923,
63,
4753,
63,
362,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
511,
14,
1831,
10441,
1062,
23842,
63,
4753,
14,
344,
9,
267,
1683,
63,
923,
63,
981,
63,
504,
63,
1365,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
511,
14,
1831,
10441,
1062,
288,
1824,
1451,
459,
354,
995,
288,
1572,
63,
4753,
63,
344,
29,
964,
1451,
459,
10929,
63,
4753,
63,
344,
995,
288,
1369,
29,
964,
1451,
459,
1802,
1105,
339,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
4753,
63,
513,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
4753,
63,
1807,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
12372,
12,
283,
923,
63,
513,
358,
272,
347,
511,
63,
1807,
63,
923,
63,
4753,
8,
277,
12,
3521,
1683,
63,
923,
63,
513,
12,
3521,
1683,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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
] |
bspaans/bookmark-tools
|
btools/matching/FileMatcher.py
|
1
|
6660
|
import os
import subprocess
import pipes
import btools.pybookmark as pybookmark
import btools.common as common
from ConfParser import ConfParser
class FileMatcher:
def __init__(self, bookmark_file = "", rules_file = ""):
if rules_file == "":
rules_file = common.get_conf_location()
c = ConfParser(bookmark_file)
c.parse_file(rules_file)
self.variables = c.variables
self.rules = c.rules
self.bookmarks = c.bookmarks
self.interactive = False
def strict(self):
return self.variables["strict"].lower() not in [ "0", "false", ""]
def symlink(self):
return self.variables["symlink"].lower() not in ["0", "false", ""]
def retain_structure(self):
return self.variables["retain_structure"].lower() not in ["0", "false", ""]
def get_weighted_table(self, file):
"""Returns sorted [(bookmark, weight)] list. Best match first."""
common.debug("Weighing %s" % file)
res = {}
for r in self.rules:
w = res.get(r.bookmark, 0.0)
dw = r.weigh(file, self.variables)
res[r.bookmark] = w + dw
if dw > 0.0:
common.info("Matched %s on %s using %s rule (%s)" % (file, r.bookmark, r.match_token, r.text))
return filter(lambda a: a[1] >= float(self.variables["threshold"]),
sorted(res.iteritems(), key=lambda a: a[1], reverse=True))
def match(self, fileOrDir, depth = 0):
if os.path.isdir(fileOrDir):
self.match_directory(fileOrDir, depth = depth)
elif os.path.isfile(fileOrDir):
self.match_file(fileOrDir, depth = depth)
else:
common.error("File not found '%s'" % fileOrDir)
def match_file(self, file, matching_dir = False, depth = 0):
ftable = self.get_weighted_table(file)
if len(ftable) == 0:
if not matching_dir:
self.exec_unmatched(file)
else:
return False
elif self.strict():
if len(ftable) == 1:
match = ftable[0]
self.exec_matched(file, match, depth = depth)
else:
common.warning("Conflict: Disregarding matches for %s. "
"Strictness is set and there are %d matches" % (file, len(ftable)))
else:
match = ftable[0]
self.exec_matched(file, match, depth = depth)
if self.symlink():
bms = pybookmark.get_bookmark(match[0], self.bookmarks)
if len(bms) != 1 and os.path.isdir(match[0]):
dir = match[0]
else:
dir = bms[0][1]
for m in ftable[1:]:
self.exec_latter(os.path.join(dir, file), m, depth = depth)
def match_directory(self, dir, depth = 0):
if self.variables["handle_directories"] in ["0", "2"]:
if self.match_file(dir, matching_dir = True, depth = depth) is False:
if self.variables["handle_directories"] == "2":
self.match_recursively(dir, depth = depth)
else:
self.match_recursively(dir, depth = depth)
def match_recursively(self, dir, depth = 0):
common.debug("Recursing on directory %s" % dir)
map(lambda a: self.match(os.path.join(dir, a), depth = depth + 1), os.listdir(dir))
def exec_unmatched(self, file):
e = str.strip(self.variables["exec_unmatched"])
if e != "":
e = common.replace_variables(e.replace("%file%", os.path.realpath(file).replace("'", "\'")), self.variables)
common.info("Executing: %s" % e)
subprocess.Popen(e, shell = True)
else:
common.debug("Nothing to execute for %s. exec_unmatched is empty" % file)
def exec_matched(self, file, match, depth = 0):
self._exec_help("exec_best", file, match, depth)
def exec_latter(self, file, match, depth = 0):
self._exec_help("exec_latter", file, match, depth)
def _exec_help(self, key, file, match, depth = 0):
bms = pybookmark.get_bookmark(match[0], self.bookmarks)
if len(bms) != 1 and os.path.isdir(match[0]):
bms = [(match[0], match[0])]
if len(bms) == 1:
x = bms[0]
e = self.variables[key]
if e != "":
file = os.path.realpath(file)
dest = self.get_dest_retained_structure(file, os.path.realpath(x[1]), depth, makedir = False)
e = e.replace("%file%", pipes.quote(file))
e = e.replace("%bookmark%", pipes.quote(x[0]))
e = e.replace("%match%", pipes.quote(dest))
e = common.replace_variables(e, self.variables)
common.info("Executing: %s" % e)
if self.interactive:
t = common.theme
no = common.NOCOLOR
print
print "=" * 80
print
print "%s%s%s %s===>%s %s%s%s" % (t[2], file, no, t[1], no,
t[3], dest, no)
print "%sMatched on %s%s" % (t[1], x[0], no)
print "%sThe following command is about to be executed%s" % (t[1], no)
print
print " ", e
print
proceed= raw_input("Proceed? [Y/n/q] ").lower()
if proceed == "": proceed = "y"
print
if proceed[0] == "n":
return
elif proceed[0] == 'q':
os.sys.exit(0)
dest = self.get_dest_retained_structure(file, os.path.realpath(x[1]), depth, makedir =True)
subprocess.Popen(e, shell = True)
else:
common.debug("Nothing to execute for %s. %s is empty." % (file, key))
else:
common.warning("Bookmark matches too many directories. Can't move file.")
def get_dest_retained_structure(self, file, dest, depth, makedir = False):
if depth > 0 and self.retain_structure():
dirs = file.split(os.sep)[-(depth + 1):]
for d in dirs[:-1]:
tmp = os.path.join(dest, d)
if not os.path.exists(tmp):
common.debug("Making sub directory in destination. %s." % tmp)
if makedir:
os.mkdir(tmp)
dest = tmp
dest = os.path.join(dest, dirs[-1])
return dest
|
gpl-3.0
|
[
646,
747,
199,
646,
3873,
199,
646,
20988,
199,
199,
646,
330,
2537,
14,
647,
17341,
465,
1134,
17341,
199,
646,
330,
2537,
14,
2330,
465,
2863,
199,
504,
32539,
2842,
492,
32539,
2842,
199,
199,
533,
3814,
16073,
26,
339,
347,
636,
826,
721,
277,
12,
23799,
63,
493,
275,
4873,
4713,
63,
493,
275,
26430,
267,
340,
4713,
63,
493,
508,
10812,
288,
4713,
63,
493,
275,
2863,
14,
362,
63,
2190,
63,
1985,
342,
398,
286,
275,
32539,
2842,
8,
17341,
63,
493,
9,
267,
286,
14,
1122,
63,
493,
8,
4423,
63,
493,
9,
267,
291,
14,
3669,
275,
286,
14,
3669,
267,
291,
14,
4423,
275,
286,
14,
4423,
267,
291,
14,
25799,
275,
286,
14,
25799,
267,
291,
14,
13543,
275,
756,
2378,
347,
7478,
8,
277,
304,
267,
372,
291,
14,
3669,
905,
4768,
4140,
2325,
342,
440,
315,
359,
298,
16,
401,
298,
3910,
401,
298,
937,
339,
347,
15296,
8,
277,
304,
267,
372,
291,
14,
3669,
905,
13380,
4140,
2325,
342,
440,
315,
2097,
16,
401,
298,
3910,
401,
298,
937,
339,
347,
8074,
63,
6976,
8,
277,
304,
267,
372,
291,
14,
3669,
905,
264,
877,
63,
6976,
4140,
2325,
342,
440,
315,
2097,
16,
401,
298,
3910,
401,
298,
937,
2378,
347,
664,
63,
13522,
63,
1224,
8,
277,
12,
570,
304,
267,
408,
3407,
3355,
3842,
17341,
12,
5401,
1874,
769,
14,
699,
597,
1336,
1642,
1041,
398,
2863,
14,
1757,
480,
6004,
2056,
316,
450,
83,
2,
450,
570,
9,
267,
522,
275,
1052,
398,
367,
519,
315,
291,
14,
4423,
26,
288,
336,
275,
522,
14,
362,
8,
82,
14,
17341,
12,
378,
14,
16,
9,
288,
17594,
275,
519,
14,
1129,
2056,
8,
493,
12,
291,
14,
3669,
9,
288,
522,
59,
82,
14,
17341,
61,
275,
336,
435,
17594,
288,
340,
17594,
690,
378,
14,
16,
26,
355,
2863,
14,
815,
480,
4486,
379,
450,
83,
641,
450,
83,
1808,
450,
83,
2332,
4366,
83,
2924,
450,
334,
493,
12,
519,
14,
17341,
12,
519,
14,
1431,
63,
1418,
12,
519,
14,
505,
430,
398,
372,
2457,
8,
2734,
282,
26,
282,
59,
17,
61,
2356,
2069,
8,
277,
14,
3669,
905,
7227,
10252,
355,
3355,
8,
470,
14,
4611,
1062,
790,
29,
2734,
282,
26,
282,
59,
17,
467,
3837,
29,
549,
430,
2378,
347,
1336,
8,
277,
12,
570,
2844,
3567,
12,
5818,
275,
378,
304,
398,
340,
747,
14,
515,
14,
6027,
8,
493,
2844,
3567,
304,
288,
291,
14,
1431,
63,
3619,
8,
493,
2844,
3567,
12,
5818,
275,
5818,
9,
267,
916,
747,
14,
515,
14,
6292,
8,
493,
2844,
3567,
304,
288,
291,
14,
1431,
63,
493,
8,
493,
2844,
3567,
12,
5818,
275,
5818,
9,
267,
587,
26,
288,
2863,
14,
705,
480,
1173,
440,
1911,
1543,
83,
4065,
450,
570,
2844,
3567,
9,
339,
347,
1336,
63,
493,
8,
277,
12,
570,
12,
4877,
63,
694,
275,
756,
12,
5818,
275,
378,
304,
267,
289,
1224,
275,
291,
14,
362,
63,
13522,
63,
1224,
8,
493,
9,
267,
340,
822,
8,
856,
461,
9,
508,
378,
26,
288,
340,
440,
4877,
63,
694,
26,
355,
291,
14,
1628,
63,
324,
10151,
8,
493,
9,
288,
587,
26,
355,
372,
756,
267,
916,
291,
14,
4768,
837,
288,
340,
822,
8,
856,
461,
9,
508,
413,
26,
355,
1336,
275,
289,
1224,
59,
16,
61,
355,
291,
14,
1628,
63,
10151,
8,
493,
12,
1336,
12,
5818,
275,
5818,
9,
288,
587,
26,
355,
2863,
14,
3764,
480,
15919,
26,
5289,
1135,
1005,
316,
4450,
367,
450,
83,
14,
298,
355,
298,
18625,
4171,
365,
663,
436,
2337,
787,
450,
68,
4450,
2,
450,
334,
493,
12,
822,
8,
856,
461,
1724,
267,
587,
26,
288,
1336,
275,
289,
1224,
59,
16,
61,
288,
291,
14,
1628,
63,
10151,
8,
493,
12,
1336,
12,
5818,
275,
5818,
9,
288,
340,
291,
14,
13380,
837,
355,
330,
706,
275,
1134,
17341,
14,
362,
63,
17341,
8,
1431,
59,
16,
467,
291,
14,
25799,
9,
355,
340,
822,
8,
66,
706,
9,
1137,
413,
436,
747,
14,
515,
14,
6027,
8,
1431,
59,
16,
4682,
490,
2935,
275,
1336,
59,
16,
61,
355,
587,
26,
490,
2935,
275,
330,
706,
59,
16,
1527,
17,
61,
355,
367,
333,
315,
289,
1224,
59,
17,
10688,
490,
291,
14,
1628,
63,
76,
3760,
8,
736,
14,
515,
14,
904,
8,
694,
12,
570,
395,
333,
12,
5818,
275,
5818,
9,
339,
347,
1336,
63,
3619,
8,
277,
12,
2935,
12,
5818,
275,
378,
304,
267,
340,
291,
14,
3669,
905,
2479,
63,
12629,
937,
315,
2097,
16,
401,
298,
18,
6229,
288,
340,
291,
14,
1431,
63,
493,
8,
694,
12,
4877,
63,
694,
275,
715,
12,
5818,
275,
5818,
9,
365,
756,
26,
355,
340,
291,
14,
3669,
905,
2479,
63,
12629,
937,
508,
298,
18,
582,
490,
291,
14,
1431,
63,
6794,
9840,
8,
694,
12,
5818,
275,
5818,
9,
267,
587,
26,
288,
291,
14,
1431,
63,
6794,
9840,
8,
694,
12,
5818,
275,
5818,
9,
339,
347,
1336,
63,
6794,
9840,
8,
277,
12,
2935,
12,
5818,
275,
378,
304,
267,
2863,
14,
1757,
480,
14244,
1044,
641,
2082,
450,
83,
2,
450,
2935,
9,
267,
2341,
8,
2734,
282,
26,
291,
14,
1431,
8,
736,
14,
515,
14,
904,
8,
694,
12,
282,
395,
5818,
275,
5818,
435,
413,
395,
747,
14,
7374,
8,
694,
430,
16478,
347,
2146,
63,
324,
10151,
8,
277,
12,
570,
304,
267,
325,
275,
620,
14,
1913,
8,
277,
14,
3669,
905,
1628,
63,
324,
10151,
3135,
267,
340,
325,
1137,
10812,
288,
325,
275,
2863,
14,
1814,
63,
3669,
8,
69,
14,
1814,
3647,
493,
31181,
747,
14,
515,
14,
11091,
8,
493,
680,
1814,
27769,
1867,
7,
8150,
291,
14,
3669,
9,
288,
2863,
14,
815,
480,
4858,
4655,
26,
450,
83,
2,
450,
325,
9,
288,
3873,
14,
7942,
8,
69,
12,
5218,
275,
715,
9,
267,
587,
26,
288,
2863,
14,
1757,
480,
19627,
370,
5341,
367,
450,
83,
14,
2146,
63,
324,
10151,
365,
2701,
2,
450,
570
] |
[
747,
199,
646,
3873,
199,
646,
20988,
199,
199,
646,
330,
2537,
14,
647,
17341,
465,
1134,
17341,
199,
646,
330,
2537,
14,
2330,
465,
2863,
199,
504,
32539,
2842,
492,
32539,
2842,
199,
199,
533,
3814,
16073,
26,
339,
347,
636,
826,
721,
277,
12,
23799,
63,
493,
275,
4873,
4713,
63,
493,
275,
26430,
267,
340,
4713,
63,
493,
508,
10812,
288,
4713,
63,
493,
275,
2863,
14,
362,
63,
2190,
63,
1985,
342,
398,
286,
275,
32539,
2842,
8,
17341,
63,
493,
9,
267,
286,
14,
1122,
63,
493,
8,
4423,
63,
493,
9,
267,
291,
14,
3669,
275,
286,
14,
3669,
267,
291,
14,
4423,
275,
286,
14,
4423,
267,
291,
14,
25799,
275,
286,
14,
25799,
267,
291,
14,
13543,
275,
756,
2378,
347,
7478,
8,
277,
304,
267,
372,
291,
14,
3669,
905,
4768,
4140,
2325,
342,
440,
315,
359,
298,
16,
401,
298,
3910,
401,
298,
937,
339,
347,
15296,
8,
277,
304,
267,
372,
291,
14,
3669,
905,
13380,
4140,
2325,
342,
440,
315,
2097,
16,
401,
298,
3910,
401,
298,
937,
339,
347,
8074,
63,
6976,
8,
277,
304,
267,
372,
291,
14,
3669,
905,
264,
877,
63,
6976,
4140,
2325,
342,
440,
315,
2097,
16,
401,
298,
3910,
401,
298,
937,
2378,
347,
664,
63,
13522,
63,
1224,
8,
277,
12,
570,
304,
267,
408,
3407,
3355,
3842,
17341,
12,
5401,
1874,
769,
14,
699,
597,
1336,
1642,
1041,
398,
2863,
14,
1757,
480,
6004,
2056,
316,
450,
83,
2,
450,
570,
9,
267,
522,
275,
1052,
398,
367,
519,
315,
291,
14,
4423,
26,
288,
336,
275,
522,
14,
362,
8,
82,
14,
17341,
12,
378,
14,
16,
9,
288,
17594,
275,
519,
14,
1129,
2056,
8,
493,
12,
291,
14,
3669,
9,
288,
522,
59,
82,
14,
17341,
61,
275,
336,
435,
17594,
288,
340,
17594,
690,
378,
14,
16,
26,
355,
2863,
14,
815,
480,
4486,
379,
450,
83,
641,
450,
83,
1808,
450,
83,
2332,
4366,
83,
2924,
450,
334,
493,
12,
519,
14,
17341,
12,
519,
14,
1431,
63,
1418,
12,
519,
14,
505,
430,
398,
372,
2457,
8,
2734,
282,
26,
282,
59,
17,
61,
2356,
2069,
8,
277,
14,
3669,
905,
7227,
10252,
355,
3355,
8,
470,
14,
4611,
1062,
790,
29,
2734,
282,
26,
282,
59,
17,
467,
3837,
29,
549,
430,
2378,
347,
1336,
8,
277,
12,
570,
2844,
3567,
12,
5818,
275,
378,
304,
398,
340,
747,
14,
515,
14,
6027,
8,
493,
2844,
3567,
304,
288,
291,
14,
1431,
63,
3619,
8,
493,
2844,
3567,
12,
5818,
275,
5818,
9,
267,
916,
747,
14,
515,
14,
6292,
8,
493,
2844,
3567,
304,
288,
291,
14,
1431,
63,
493,
8,
493,
2844,
3567,
12,
5818,
275,
5818,
9,
267,
587,
26,
288,
2863,
14,
705,
480,
1173,
440,
1911,
1543,
83,
4065,
450,
570,
2844,
3567,
9,
339,
347,
1336,
63,
493,
8,
277,
12,
570,
12,
4877,
63,
694,
275,
756,
12,
5818,
275,
378,
304,
267,
289,
1224,
275,
291,
14,
362,
63,
13522,
63,
1224,
8,
493,
9,
267,
340,
822,
8,
856,
461,
9,
508,
378,
26,
288,
340,
440,
4877,
63,
694,
26,
355,
291,
14,
1628,
63,
324,
10151,
8,
493,
9,
288,
587,
26,
355,
372,
756,
267,
916,
291,
14,
4768,
837,
288,
340,
822,
8,
856,
461,
9,
508,
413,
26,
355,
1336,
275,
289,
1224,
59,
16,
61,
355,
291,
14,
1628,
63,
10151,
8,
493,
12,
1336,
12,
5818,
275,
5818,
9,
288,
587,
26,
355,
2863,
14,
3764,
480,
15919,
26,
5289,
1135,
1005,
316,
4450,
367,
450,
83,
14,
298,
355,
298,
18625,
4171,
365,
663,
436,
2337,
787,
450,
68,
4450,
2,
450,
334,
493,
12,
822,
8,
856,
461,
1724,
267,
587,
26,
288,
1336,
275,
289,
1224,
59,
16,
61,
288,
291,
14,
1628,
63,
10151,
8,
493,
12,
1336,
12,
5818,
275,
5818,
9,
288,
340,
291,
14,
13380,
837,
355,
330,
706,
275,
1134,
17341,
14,
362,
63,
17341,
8,
1431,
59,
16,
467,
291,
14,
25799,
9,
355,
340,
822,
8,
66,
706,
9,
1137,
413,
436,
747,
14,
515,
14,
6027,
8,
1431,
59,
16,
4682,
490,
2935,
275,
1336,
59,
16,
61,
355,
587,
26,
490,
2935,
275,
330,
706,
59,
16,
1527,
17,
61,
355,
367,
333,
315,
289,
1224,
59,
17,
10688,
490,
291,
14,
1628,
63,
76,
3760,
8,
736,
14,
515,
14,
904,
8,
694,
12,
570,
395,
333,
12,
5818,
275,
5818,
9,
339,
347,
1336,
63,
3619,
8,
277,
12,
2935,
12,
5818,
275,
378,
304,
267,
340,
291,
14,
3669,
905,
2479,
63,
12629,
937,
315,
2097,
16,
401,
298,
18,
6229,
288,
340,
291,
14,
1431,
63,
493,
8,
694,
12,
4877,
63,
694,
275,
715,
12,
5818,
275,
5818,
9,
365,
756,
26,
355,
340,
291,
14,
3669,
905,
2479,
63,
12629,
937,
508,
298,
18,
582,
490,
291,
14,
1431,
63,
6794,
9840,
8,
694,
12,
5818,
275,
5818,
9,
267,
587,
26,
288,
291,
14,
1431,
63,
6794,
9840,
8,
694,
12,
5818,
275,
5818,
9,
339,
347,
1336,
63,
6794,
9840,
8,
277,
12,
2935,
12,
5818,
275,
378,
304,
267,
2863,
14,
1757,
480,
14244,
1044,
641,
2082,
450,
83,
2,
450,
2935,
9,
267,
2341,
8,
2734,
282,
26,
291,
14,
1431,
8,
736,
14,
515,
14,
904,
8,
694,
12,
282,
395,
5818,
275,
5818,
435,
413,
395,
747,
14,
7374,
8,
694,
430,
16478,
347,
2146,
63,
324,
10151,
8,
277,
12,
570,
304,
267,
325,
275,
620,
14,
1913,
8,
277,
14,
3669,
905,
1628,
63,
324,
10151,
3135,
267,
340,
325,
1137,
10812,
288,
325,
275,
2863,
14,
1814,
63,
3669,
8,
69,
14,
1814,
3647,
493,
31181,
747,
14,
515,
14,
11091,
8,
493,
680,
1814,
27769,
1867,
7,
8150,
291,
14,
3669,
9,
288,
2863,
14,
815,
480,
4858,
4655,
26,
450,
83,
2,
450,
325,
9,
288,
3873,
14,
7942,
8,
69,
12,
5218,
275,
715,
9,
267,
587,
26,
288,
2863,
14,
1757,
480,
19627,
370,
5341,
367,
450,
83,
14,
2146,
63,
324,
10151,
365,
2701,
2,
450,
570,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
|
26
|
6955
|
#!/usr/bin/python
# (c) 2012, Stephen Fromm <sfromm@gmail.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': ['stableinterface'],
'supported_by': 'core'}
DOCUMENTATION = '''
---
module: seboolean
short_description: Toggles SELinux booleans.
description:
- Toggles SELinux booleans.
version_added: "0.7"
options:
name:
description:
- Name of the boolean to configure
required: true
default: null
persistent:
description:
- Set to C(yes) if the boolean setting should survive a reboot
required: false
default: no
choices: [ "yes", "no" ]
state:
description:
- Desired boolean value
required: true
default: null
choices: [ 'yes', 'no' ]
notes:
- Not tested on any debian based system
requirements: [ libselinux-python, libsemanage-python ]
author: "Stephen Fromm (@sfromm)"
'''
EXAMPLES = '''
# Set (httpd_can_network_connect) flag on and keep it persistent across reboots
- seboolean:
name: httpd_can_network_connect
state: yes
persistent: yes
'''
import os
try:
import selinux
HAVE_SELINUX=True
except ImportError:
HAVE_SELINUX=False
try:
import semanage
HAVE_SEMANAGE=True
except ImportError:
HAVE_SEMANAGE=False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import binary_type
from ansible.module_utils._text import to_bytes
def has_boolean_value(module, name):
bools = []
try:
rc, bools = selinux.security_get_boolean_names()
except OSError:
module.fail_json(msg="Failed to get list of boolean names")
# work around for selinux who changed its API, see
# https://github.com/ansible/ansible/issues/25651
if len(bools) > 0:
if isinstance(bools[0], binary_type):
name = to_bytes(name)
if name in bools:
return True
else:
return False
def get_boolean_value(module, name):
state = 0
try:
state = selinux.security_get_boolean_active(name)
except OSError:
module.fail_json(msg="Failed to determine current state for boolean %s" % name)
if state == 1:
return True
else:
return False
# The following method implements what setsebool.c does to change
# a boolean and make it persist after reboot..
def semanage_boolean_value(module, name, state):
rc = 0
value = 0
if state:
value = 1
handle = semanage.semanage_handle_create()
if handle is None:
module.fail_json(msg="Failed to create semanage library handle")
try:
managed = semanage.semanage_is_managed(handle)
if managed < 0:
module.fail_json(msg="Failed to determine whether policy is manage")
if managed == 0:
if os.getuid() == 0:
module.fail_json(msg="Cannot set persistent booleans without managed policy")
else:
module.fail_json(msg="Cannot set persistent booleans; please try as root")
if semanage.semanage_connect(handle) < 0:
module.fail_json(msg="Failed to connect to semanage")
if semanage.semanage_begin_transaction(handle) < 0:
module.fail_json(msg="Failed to begin semanage transaction")
rc, sebool = semanage.semanage_bool_create(handle)
if rc < 0:
module.fail_json(msg="Failed to create seboolean with semanage")
if semanage.semanage_bool_set_name(handle, sebool, name) < 0:
module.fail_json(msg="Failed to set seboolean name with semanage")
semanage.semanage_bool_set_value(sebool, value)
rc, boolkey = semanage.semanage_bool_key_extract(handle, sebool)
if rc < 0:
module.fail_json(msg="Failed to extract boolean key with semanage")
if semanage.semanage_bool_modify_local(handle, boolkey, sebool) < 0:
module.fail_json(msg="Failed to modify boolean key with semanage")
if semanage.semanage_bool_set_active(handle, boolkey, sebool) < 0:
module.fail_json(msg="Failed to set boolean key active with semanage")
semanage.semanage_bool_key_free(boolkey)
semanage.semanage_bool_free(sebool)
semanage.semanage_set_reload(handle, 0)
if semanage.semanage_commit(handle) < 0:
module.fail_json(msg="Failed to commit changes to semanage")
semanage.semanage_disconnect(handle)
semanage.semanage_handle_destroy(handle)
except Exception as e:
module.fail_json(msg="Failed to manage policy for boolean %s: %s" % (name, str(e)))
return True
def set_boolean_value(module, name, state):
rc = 0
value = 0
if state:
value = 1
try:
rc = selinux.security_set_boolean(name, value)
except OSError:
module.fail_json(msg="Failed to set boolean %s to %s" % (name, value))
if rc == 0:
return True
else:
return False
def main():
module = AnsibleModule(
argument_spec = dict(
name=dict(required=True),
persistent=dict(default='no', type='bool'),
state=dict(required=True, type='bool')
),
supports_check_mode=True
)
if not HAVE_SELINUX:
module.fail_json(msg="This module requires libselinux-python support")
if not HAVE_SEMANAGE:
module.fail_json(msg="This module requires libsemanage-python support")
if not selinux.is_selinux_enabled():
module.fail_json(msg="SELinux is disabled on this host.")
name = module.params['name']
persistent = module.params['persistent']
state = module.params['state']
result = {}
result['name'] = name
if hasattr(selinux, 'selinux_boolean_sub'):
# selinux_boolean_sub allows sites to rename a boolean and alias the old name
# Feature only available in selinux library since 2012.
name = selinux.selinux_boolean_sub(name)
if not has_boolean_value(module, name):
module.fail_json(msg="SELinux boolean %s does not exist." % name)
cur_value = get_boolean_value(module, name)
if cur_value == state:
result['state'] = cur_value
result['changed'] = False
module.exit_json(**result)
if module.check_mode:
module.exit_json(changed=True)
if persistent:
r = semanage_boolean_value(module, name, state)
else:
r = set_boolean_value(module, name, state)
result['changed'] = r
if not r:
module.fail_json(msg="Failed to set boolean %s to %s" % (name, state))
try:
selinux.security_commit_booleans()
except:
module.fail_json(msg="Failed to commit pending boolean %s value" % name)
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
6029,
12,
17854,
17579,
11606,
77,
665,
83,
504,
77,
32,
6799,
14,
957,
30,
199,
3,
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,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
542,
4871,
199,
3612,
63,
1802,
26,
377,
24798,
2978,
428,
2901,
7226,
1234,
16721,
796,
14,
199,
1802,
26,
1362,
446,
377,
24798,
2978,
428,
2901,
7226,
1234,
16721,
796,
14,
199,
1023,
63,
3270,
26,
298,
16,
14,
23,
2,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5046,
370,
7908,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
16149,
26,
272,
1369,
26,
489,
446,
2494,
370,
445,
8,
5066,
9,
340,
314,
5046,
4260,
1077,
6296,
433,
432,
282,
19457,
272,
1415,
26,
3055,
272,
849,
26,
949,
272,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
523,
1174,
26,
272,
1369,
26,
489,
446,
1487,
5381,
5046,
574,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
3415,
26,
359,
283,
5066,
297,
283,
889,
7,
1622,
199,
5983,
26,
2043,
446,
2832,
12470,
641,
1263,
477,
9662,
4079,
2656,
199,
7538,
26,
359,
1973,
19931,
13,
1548,
12,
1973,
261,
9053,
13,
1548,
1622,
199,
2502,
26,
298,
26696,
17579,
11606,
77,
8593,
83,
504,
77,
2924,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2494,
334,
21594,
63,
2425,
63,
1200,
63,
2242,
9,
3305,
641,
436,
4215,
652,
16149,
9371,
19457,
83,
199,
13,
542,
4871,
26,
272,
536,
26,
23913,
63,
2425,
63,
1200,
63,
2242,
272,
1174,
26,
9456,
272,
16149,
26,
9456,
199,
2344,
199,
199,
646,
747,
199,
199,
893,
26,
272,
492,
542,
5135,
272,
25227,
63,
899,
26030,
29,
549,
199,
2590,
3545,
26,
272,
25227,
63,
899,
26030,
29,
797,
199,
199,
893,
26,
272,
492,
542,
9053,
272,
25227,
63,
899,
6588,
2962,
29,
549,
199,
2590,
3545,
26,
272,
25227,
63,
899,
6588,
2962,
29,
797,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
3366,
63,
466,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
2394,
421,
199,
318,
965,
63,
4871,
63,
585,
8,
578,
12,
536,
304,
272,
1234,
1446,
275,
942,
272,
862,
26,
267,
4819,
12,
1234,
1446,
275,
542,
5135,
14,
4416,
63,
362,
63,
4871,
63,
1247,
342,
272,
871,
6440,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
664,
769,
402,
5046,
1561,
531,
272,
327,
1736,
6818,
367,
542,
5135,
3963,
2896,
2399,
3261,
12,
1937,
272,
327,
4178,
921,
5031,
14,
957,
15,
4853,
15,
4853,
15,
10115,
15,
821,
25459,
272,
340,
822,
8,
656,
1446,
9,
690,
378,
26,
267,
340,
1228,
8,
656,
1446,
59,
16,
467,
3366,
63,
466,
304,
288,
536,
275,
370,
63,
2394,
8,
354,
9,
272,
340,
536,
315,
1234,
1446,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
318,
664,
63,
4871,
63,
585,
8,
578,
12,
536,
304,
272,
1174,
275,
378,
272,
862,
26,
267,
1174,
275,
542,
5135,
14,
4416,
63,
362,
63,
4871,
63,
2682,
8,
354,
9,
272,
871,
6440,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
6705,
1453,
1174,
367,
5046,
450,
83,
2,
450,
536,
9,
272,
340,
1174,
508,
413,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
3,
710,
2569,
1083,
9031,
4052,
663,
261,
2245,
14,
67,
1630,
370,
1570,
199,
3,
282,
5046,
436,
1852,
652,
22400,
2410,
19457,
703,
199,
318,
542,
9053,
63,
4871,
63,
585,
8,
578,
12,
536,
12,
1174,
304,
272,
4819,
275,
378,
272,
574,
275,
378,
272,
340,
1174,
26,
267,
574,
275,
413,
272,
2429,
275,
542,
9053,
14,
261,
9053,
63,
2479,
63,
981,
342,
272,
340,
2429,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
1218,
542,
9053,
3555,
2429,
531,
272,
862,
26,
267,
12883,
275,
542,
9053,
14,
261,
9053,
63,
374,
63,
11122,
8,
2479,
9,
267,
340,
12883,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
6705,
3775,
4592,
365,
9635,
531,
267,
340,
12883,
508,
378,
26,
288,
340,
747,
14,
362,
1535,
342,
508,
378,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
628,
6612,
663,
16149,
1234,
16721,
796,
1928,
12883,
4592,
531,
288,
587,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
628,
6612,
663,
16149,
1234,
16721,
796,
27,
8749,
862,
465,
1738,
531,
267,
340,
542,
9053,
14,
261,
9053,
63,
2242,
8,
2479,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
4907,
370,
542,
9053,
531,
398,
340,
542,
9053,
14,
261,
9053,
63,
5037,
63,
5945,
8,
2479,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
5386,
542,
9053,
6008,
531,
398,
4819,
12,
542,
2245,
275,
542,
9053,
14,
261,
9053,
63,
2245,
63,
981,
8,
2479,
9,
267,
340,
4819,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
1218,
542,
4871,
543,
542,
9053,
531,
267,
340,
542,
9053,
14,
261,
9053,
63,
2245,
63,
409,
63,
354,
8,
2479,
12,
542,
2245,
12,
536,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
663,
542,
4871,
536,
543,
542,
9053,
531,
267,
542,
9053,
14,
261,
9053,
63,
2245,
63,
409,
63,
585
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
6029,
12,
17854,
17579,
11606,
77,
665,
83,
504,
77,
32,
6799,
14,
957,
30,
199,
3,
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,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
542,
4871,
199,
3612,
63,
1802,
26,
377,
24798,
2978,
428,
2901,
7226,
1234,
16721,
796,
14,
199,
1802,
26,
1362,
446,
377,
24798,
2978,
428,
2901,
7226,
1234,
16721,
796,
14,
199,
1023,
63,
3270,
26,
298,
16,
14,
23,
2,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5046,
370,
7908,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
16149,
26,
272,
1369,
26,
489,
446,
2494,
370,
445,
8,
5066,
9,
340,
314,
5046,
4260,
1077,
6296,
433,
432,
282,
19457,
272,
1415,
26,
3055,
272,
849,
26,
949,
272,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
523,
1174,
26,
272,
1369,
26,
489,
446,
1487,
5381,
5046,
574,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
3415,
26,
359,
283,
5066,
297,
283,
889,
7,
1622,
199,
5983,
26,
2043,
446,
2832,
12470,
641,
1263,
477,
9662,
4079,
2656,
199,
7538,
26,
359,
1973,
19931,
13,
1548,
12,
1973,
261,
9053,
13,
1548,
1622,
199,
2502,
26,
298,
26696,
17579,
11606,
77,
8593,
83,
504,
77,
2924,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2494,
334,
21594,
63,
2425,
63,
1200,
63,
2242,
9,
3305,
641,
436,
4215,
652,
16149,
9371,
19457,
83,
199,
13,
542,
4871,
26,
272,
536,
26,
23913,
63,
2425,
63,
1200,
63,
2242,
272,
1174,
26,
9456,
272,
16149,
26,
9456,
199,
2344,
199,
199,
646,
747,
199,
199,
893,
26,
272,
492,
542,
5135,
272,
25227,
63,
899,
26030,
29,
549,
199,
2590,
3545,
26,
272,
25227,
63,
899,
26030,
29,
797,
199,
199,
893,
26,
272,
492,
542,
9053,
272,
25227,
63,
899,
6588,
2962,
29,
549,
199,
2590,
3545,
26,
272,
25227,
63,
899,
6588,
2962,
29,
797,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
3366,
63,
466,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
2394,
421,
199,
318,
965,
63,
4871,
63,
585,
8,
578,
12,
536,
304,
272,
1234,
1446,
275,
942,
272,
862,
26,
267,
4819,
12,
1234,
1446,
275,
542,
5135,
14,
4416,
63,
362,
63,
4871,
63,
1247,
342,
272,
871,
6440,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
664,
769,
402,
5046,
1561,
531,
272,
327,
1736,
6818,
367,
542,
5135,
3963,
2896,
2399,
3261,
12,
1937,
272,
327,
4178,
921,
5031,
14,
957,
15,
4853,
15,
4853,
15,
10115,
15,
821,
25459,
272,
340,
822,
8,
656,
1446,
9,
690,
378,
26,
267,
340,
1228,
8,
656,
1446,
59,
16,
467,
3366,
63,
466,
304,
288,
536,
275,
370,
63,
2394,
8,
354,
9,
272,
340,
536,
315,
1234,
1446,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
318,
664,
63,
4871,
63,
585,
8,
578,
12,
536,
304,
272,
1174,
275,
378,
272,
862,
26,
267,
1174,
275,
542,
5135,
14,
4416,
63,
362,
63,
4871,
63,
2682,
8,
354,
9,
272,
871,
6440,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
6705,
1453,
1174,
367,
5046,
450,
83,
2,
450,
536,
9,
272,
340,
1174,
508,
413,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
199,
199,
3,
710,
2569,
1083,
9031,
4052,
663,
261,
2245,
14,
67,
1630,
370,
1570,
199,
3,
282,
5046,
436,
1852,
652,
22400,
2410,
19457,
703,
199,
318,
542,
9053,
63,
4871,
63,
585,
8,
578,
12,
536,
12,
1174,
304,
272,
4819,
275,
378,
272,
574,
275,
378,
272,
340,
1174,
26,
267,
574,
275,
413,
272,
2429,
275,
542,
9053,
14,
261,
9053,
63,
2479,
63,
981,
342,
272,
340,
2429,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
1218,
542,
9053,
3555,
2429,
531,
272,
862,
26,
267,
12883,
275,
542,
9053,
14,
261,
9053,
63,
374,
63,
11122,
8,
2479,
9,
267,
340,
12883,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
6705,
3775,
4592,
365,
9635,
531,
267,
340,
12883,
508,
378,
26,
288,
340,
747,
14,
362,
1535,
342,
508,
378,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
628,
6612,
663,
16149,
1234,
16721,
796,
1928,
12883,
4592,
531,
288,
587,
26,
355,
859,
14,
1633,
63,
1001,
8,
1328,
628,
6612,
663,
16149,
1234,
16721,
796,
27,
8749,
862,
465,
1738,
531,
267,
340,
542,
9053,
14,
261,
9053,
63,
2242,
8,
2479,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
4907,
370,
542,
9053,
531,
398,
340,
542,
9053,
14,
261,
9053,
63,
5037,
63,
5945,
8,
2479,
9,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
5386,
542,
9053,
6008,
531,
398,
4819,
12,
542,
2245,
275,
542,
9053,
14,
261,
9053,
63,
2245,
63,
981,
8,
2479,
9,
267,
340,
4819,
665,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
628,
4276,
370,
1218,
542,
4871,
543,
542,
9053,
531,
267,
340,
542,
9053,
14,
261,
9053,
63,
2245,
63,
409,
63,
354,
8,
2479,
12,
542,
2245,
12,
536,
9,
665,
378,
26,
288,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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
] |
ElDeveloper/scikit-learn
|
sklearn/tree/tests/test_tree.py
|
13
|
52365
|
"""
Testing for the tree module (sklearn.tree).
"""
import pickle
from functools import partial
from itertools import product
import platform
import numpy as np
from scipy.sparse import csc_matrix
from scipy.sparse import csr_matrix
from scipy.sparse import coo_matrix
from sklearn.random_projection import sparse_random_matrix
from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_squared_error
from sklearn.utils.testing import assert_array_equal
from sklearn.utils.testing import assert_array_almost_equal
from sklearn.utils.testing import assert_almost_equal
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_in
from sklearn.utils.testing import assert_raises
from sklearn.utils.testing import assert_greater
from sklearn.utils.testing import assert_greater_equal
from sklearn.utils.testing import assert_less
from sklearn.utils.testing import assert_less_equal
from sklearn.utils.testing import assert_true
from sklearn.utils.testing import assert_warns
from sklearn.utils.testing import raises
from sklearn.utils.testing import ignore_warnings
from sklearn.utils.validation import check_random_state
from sklearn.exceptions import NotFittedError
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import DecisionTreeRegressor
from sklearn.tree import ExtraTreeClassifier
from sklearn.tree import ExtraTreeRegressor
from sklearn import tree
from sklearn.tree.tree import SPARSE_SPLITTERS
from sklearn.tree._tree import TREE_LEAF
from sklearn import datasets
from sklearn.utils import compute_sample_weight
CLF_CRITERIONS = ("gini", "entropy")
REG_CRITERIONS = ("mse", )
CLF_TREES = {
"DecisionTreeClassifier": DecisionTreeClassifier,
"Presort-DecisionTreeClassifier": partial(DecisionTreeClassifier,
presort=True),
"ExtraTreeClassifier": ExtraTreeClassifier,
}
REG_TREES = {
"DecisionTreeRegressor": DecisionTreeRegressor,
"Presort-DecisionTreeRegressor": partial(DecisionTreeRegressor,
presort=True),
"ExtraTreeRegressor": ExtraTreeRegressor,
}
ALL_TREES = dict()
ALL_TREES.update(CLF_TREES)
ALL_TREES.update(REG_TREES)
SPARSE_TREES = ["DecisionTreeClassifier", "DecisionTreeRegressor",
"ExtraTreeClassifier", "ExtraTreeRegressor"]
X_small = np.array([
[0, 0, 4, 0, 0, 0, 1, -14, 0, -4, 0, 0, 0, 0, ],
[0, 0, 5, 3, 0, -4, 0, 0, 1, -5, 0.2, 0, 4, 1, ],
[-1, -1, 0, 0, -4.5, 0, 0, 2.1, 1, 0, 0, -4.5, 0, 1, ],
[-1, -1, 0, -1.2, 0, 0, 0, 0, 0, 0, 0.2, 0, 0, 1, ],
[-1, -1, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 1, ],
[-1, -2, 0, 4, -3, 10, 4, 0, -3.2, 0, 4, 3, -4, 1, ],
[2.11, 0, -6, -0.5, 0, 11, 0, 0, -3.2, 6, 0.5, 0, -3, 1, ],
[2.11, 0, -6, -0.5, 0, 11, 0, 0, -3.2, 6, 0, 0, -2, 1, ],
[2.11, 8, -6, -0.5, 0, 11, 0, 0, -3.2, 6, 0, 0, -2, 1, ],
[2.11, 8, -6, -0.5, 0, 11, 0, 0, -3.2, 6, 0.5, 0, -1, 0, ],
[2, 8, 5, 1, 0.5, -4, 10, 0, 1, -5, 3, 0, 2, 0, ],
[2, 0, 1, 1, 1, -1, 1, 0, 0, -2, 3, 0, 1, 0, ],
[2, 0, 1, 2, 3, -1, 10, 2, 0, -1, 1, 2, 2, 0, ],
[1, 1, 0, 2, 2, -1, 1, 2, 0, -5, 1, 2, 3, 0, ],
[3, 1, 0, 3, 0, -4, 10, 0, 1, -5, 3, 0, 3, 1, ],
[2.11, 8, -6, -0.5, 0, 1, 0, 0, -3.2, 6, 0.5, 0, -3, 1, ],
[2.11, 8, -6, -0.5, 0, 1, 0, 0, -3.2, 6, 1.5, 1, -1, -1, ],
[2.11, 8, -6, -0.5, 0, 10, 0, 0, -3.2, 6, 0.5, 0, -1, -1, ],
[2, 0, 5, 1, 0.5, -2, 10, 0, 1, -5, 3, 1, 0, -1, ],
[2, 0, 1, 1, 1, -2, 1, 0, 0, -2, 0, 0, 0, 1, ],
[2, 1, 1, 1, 2, -1, 10, 2, 0, -1, 0, 2, 1, 1, ],
[1, 1, 0, 0, 1, -3, 1, 2, 0, -5, 1, 2, 1, 1, ],
[3, 1, 0, 1, 0, -4, 1, 0, 1, -2, 0, 0, 1, 0, ]])
y_small = [1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0,
0, 0]
y_small_reg = [1.0, 2.1, 1.2, 0.05, 10, 2.4, 3.1, 1.01, 0.01, 2.98, 3.1, 1.1,
0.0, 1.2, 2, 11, 0, 0, 4.5, 0.201, 1.06, 0.9, 0]
# toy sample
X = [[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]]
y = [-1, -1, -1, 1, 1, 1]
T = [[-1, -1], [2, 2], [3, 2]]
true_result = [-1, 1, 1]
# also load the iris dataset
# and randomly permute it
iris = datasets.load_iris()
rng = np.random.RandomState(1)
perm = rng.permutation(iris.target.size)
iris.data = iris.data[perm]
iris.target = iris.target[perm]
# also load the boston dataset
# and randomly permute it
boston = datasets.load_boston()
perm = rng.permutation(boston.target.size)
boston.data = boston.data[perm]
boston.target = boston.target[perm]
digits = datasets.load_digits()
perm = rng.permutation(digits.target.size)
digits.data = digits.data[perm]
digits.target = digits.target[perm]
random_state = check_random_state(0)
X_multilabel, y_multilabel = datasets.make_multilabel_classification(
random_state=0, n_samples=30, n_features=10)
X_sparse_pos = random_state.uniform(size=(20, 5))
X_sparse_pos[X_sparse_pos <= 0.8] = 0.
y_random = random_state.randint(0, 4, size=(20, ))
X_sparse_mix = sparse_random_matrix(20, 10, density=0.25, random_state=0)
DATASETS = {
"iris": {"X": iris.data, "y": iris.target},
"boston": {"X": boston.data, "y": boston.target},
"digits": {"X": digits.data, "y": digits.target},
"toy": {"X": X, "y": y},
"clf_small": {"X": X_small, "y": y_small},
"reg_small": {"X": X_small, "y": y_small_reg},
"multilabel": {"X": X_multilabel, "y": y_multilabel},
"sparse-pos": {"X": X_sparse_pos, "y": y_random},
"sparse-neg": {"X": - X_sparse_pos, "y": y_random},
"sparse-mix": {"X": X_sparse_mix, "y": y_random},
"zeros": {"X": np.zeros((20, 3)), "y": y_random}
}
for name in DATASETS:
DATASETS[name]["X_sparse"] = csc_matrix(DATASETS[name]["X"])
def assert_tree_equal(d, s, message):
assert_equal(s.node_count, d.node_count,
"{0}: inequal number of node ({1} != {2})"
"".format(message, s.node_count, d.node_count))
assert_array_equal(d.children_right, s.children_right,
message + ": inequal children_right")
assert_array_equal(d.children_left, s.children_left,
message + ": inequal children_left")
external = d.children_right == TREE_LEAF
internal = np.logical_not(external)
assert_array_equal(d.feature[internal], s.feature[internal],
message + ": inequal features")
assert_array_equal(d.threshold[internal], s.threshold[internal],
message + ": inequal threshold")
assert_array_equal(d.n_node_samples.sum(), s.n_node_samples.sum(),
message + ": inequal sum(n_node_samples)")
assert_array_equal(d.n_node_samples, s.n_node_samples,
message + ": inequal n_node_samples")
assert_almost_equal(d.impurity, s.impurity,
err_msg=message + ": inequal impurity")
assert_array_almost_equal(d.value[external], s.value[external],
err_msg=message + ": inequal value")
def test_classification_toy():
# Check classification on a toy dataset.
for name, Tree in CLF_TREES.items():
clf = Tree(random_state=0)
clf.fit(X, y)
assert_array_equal(clf.predict(T), true_result,
"Failed with {0}".format(name))
clf = Tree(max_features=1, random_state=1)
clf.fit(X, y)
assert_array_equal(clf.predict(T), true_result,
"Failed with {0}".format(name))
def test_weighted_classification_toy():
# Check classification on a weighted toy dataset.
for name, Tree in CLF_TREES.items():
clf = Tree(random_state=0)
clf.fit(X, y, sample_weight=np.ones(len(X)))
assert_array_equal(clf.predict(T), true_result,
"Failed with {0}".format(name))
clf.fit(X, y, sample_weight=np.ones(len(X)) * 0.5)
assert_array_equal(clf.predict(T), true_result,
"Failed with {0}".format(name))
def test_regression_toy():
# Check regression on a toy dataset.
for name, Tree in REG_TREES.items():
reg = Tree(random_state=1)
reg.fit(X, y)
assert_almost_equal(reg.predict(T), true_result,
err_msg="Failed with {0}".format(name))
clf = Tree(max_features=1, random_state=1)
clf.fit(X, y)
assert_almost_equal(reg.predict(T), true_result,
err_msg="Failed with {0}".format(name))
def test_xor():
# Check on a XOR problem
y = np.zeros((10, 10))
y[:5, :5] = 1
y[5:, 5:] = 1
gridx, gridy = np.indices(y.shape)
X = np.vstack([gridx.ravel(), gridy.ravel()]).T
y = y.ravel()
for name, Tree in CLF_TREES.items():
clf = Tree(random_state=0)
clf.fit(X, y)
assert_equal(clf.score(X, y), 1.0,
"Failed with {0}".format(name))
clf = Tree(random_state=0, max_features=1)
clf.fit(X, y)
assert_equal(clf.score(X, y), 1.0,
"Failed with {0}".format(name))
def test_iris():
# Check consistency on dataset iris.
for (name, Tree), criterion in product(CLF_TREES.items(), CLF_CRITERIONS):
clf = Tree(criterion=criterion, random_state=0)
clf.fit(iris.data, iris.target)
score = accuracy_score(clf.predict(iris.data), iris.target)
assert_greater(score, 0.9,
"Failed with {0}, criterion = {1} and score = {2}"
"".format(name, criterion, score))
clf = Tree(criterion=criterion, max_features=2, random_state=0)
clf.fit(iris.data, iris.target)
score = accuracy_score(clf.predict(iris.data), iris.target)
assert_greater(score, 0.5,
"Failed with {0}, criterion = {1} and score = {2}"
"".format(name, criterion, score))
def test_boston():
# Check consistency on dataset boston house prices.
for (name, Tree), criterion in product(REG_TREES.items(), REG_CRITERIONS):
reg = Tree(criterion=criterion, random_state=0)
reg.fit(boston.data, boston.target)
score = mean_squared_error(boston.target, reg.predict(boston.data))
assert_less(score, 1,
"Failed with {0}, criterion = {1} and score = {2}"
"".format(name, criterion, score))
# using fewer features reduces the learning ability of this tree,
# but reduces training time.
reg = Tree(criterion=criterion, max_features=6, random_state=0)
reg.fit(boston.data, boston.target)
score = mean_squared_error(boston.target, reg.predict(boston.data))
assert_less(score, 2,
"Failed with {0}, criterion = {1} and score = {2}"
"".format(name, criterion, score))
def test_probability():
# Predict probabilities using DecisionTreeClassifier.
for name, Tree in CLF_TREES.items():
clf = Tree(max_depth=1, max_features=1, random_state=42)
clf.fit(iris.data, iris.target)
prob_predict = clf.predict_proba(iris.data)
assert_array_almost_equal(np.sum(prob_predict, 1),
np.ones(iris.data.shape[0]),
err_msg="Failed with {0}".format(name))
assert_array_equal(np.argmax(prob_predict, 1),
clf.predict(iris.data),
err_msg="Failed with {0}".format(name))
assert_almost_equal(clf.predict_proba(iris.data),
np.exp(clf.predict_log_proba(iris.data)), 8,
err_msg="Failed with {0}".format(name))
def test_arrayrepr():
# Check the array representation.
# Check resize
X = np.arange(10000)[:, np.newaxis]
y = np.arange(10000)
for name, Tree in REG_TREES.items():
reg = Tree(max_depth=None, random_state=0)
reg.fit(X, y)
def test_pure_set():
# Check when y is pure.
X = [[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]]
y = [1, 1, 1, 1, 1, 1]
for name, TreeClassifier in CLF_TREES.items():
clf = TreeClassifier(random_state=0)
clf.fit(X, y)
assert_array_equal(clf.predict(X), y,
err_msg="Failed with {0}".format(name))
for name, TreeRegressor in REG_TREES.items():
reg = TreeRegressor(random_state=0)
reg.fit(X, y)
assert_almost_equal(clf.predict(X), y,
err_msg="Failed with {0}".format(name))
def test_numerical_stability():
# Check numerical stability.
X = np.array([
[152.08097839, 140.40744019, 129.75102234, 159.90493774],
[142.50700378, 135.81935120, 117.82884979, 162.75781250],
[127.28772736, 140.40744019, 129.75102234, 159.90493774],
[132.37025452, 143.71923828, 138.35694885, 157.84558105],
[103.10237122, 143.71928406, 138.35696411, 157.84559631],
[127.71276855, 143.71923828, 138.35694885, 157.84558105],
[120.91514587, 140.40744019, 129.75102234, 159.90493774]])
y = np.array(
[1., 0.70209277, 0.53896582, 0., 0.90914464, 0.48026916, 0.49622521])
with np.errstate(all="raise"):
for name, Tree in REG_TREES.items():
reg = Tree(random_state=0)
reg.fit(X, y)
reg.fit(X, -y)
reg.fit(-X, y)
reg.fit(-X, -y)
def test_importances():
# Check variable importances.
X, y = datasets.make_classification(n_samples=2000,
n_features=10,
n_informative=3,
n_redundant=0,
n_repeated=0,
shuffle=False,
random_state=0)
for name, Tree in CLF_TREES.items():
clf = Tree(random_state=0)
clf.fit(X, y)
importances = clf.feature_importances_
n_important = np.sum(importances > 0.1)
assert_equal(importances.shape[0], 10, "Failed with {0}".format(name))
assert_equal(n_important, 3, "Failed with {0}".format(name))
X_new = assert_warns(
DeprecationWarning, clf.transform, X, threshold="mean")
assert_less(0, X_new.shape[1], "Failed with {0}".format(name))
assert_less(X_new.shape[1], X.shape[1], "Failed with {0}".format(name))
# Check on iris that importances are the same for all builders
clf = DecisionTreeClassifier(random_state=0)
clf.fit(iris.data, iris.target)
clf2 = DecisionTreeClassifier(random_state=0,
max_leaf_nodes=len(iris.data))
clf2.fit(iris.data, iris.target)
assert_array_equal(clf.feature_importances_,
clf2.feature_importances_)
@raises(ValueError)
def test_importances_raises():
# Check if variable importance before fit raises ValueError.
clf = DecisionTreeClassifier()
clf.feature_importances_
def test_importances_gini_equal_mse():
# Check that gini is equivalent to mse for binary output variable
X, y = datasets.make_classification(n_samples=2000,
n_features=10,
n_informative=3,
n_redundant=0,
n_repeated=0,
shuffle=False,
random_state=0)
# The gini index and the mean square error (variance) might differ due
# to numerical instability. Since those instabilities mainly occurs at
# high tree depth, we restrict this maximal depth.
clf = DecisionTreeClassifier(criterion="gini", max_depth=5,
random_state=0).fit(X, y)
reg = DecisionTreeRegressor(criterion="mse", max_depth=5,
random_state=0).fit(X, y)
assert_almost_equal(clf.feature_importances_, reg.feature_importances_)
assert_array_equal(clf.tree_.feature, reg.tree_.feature)
assert_array_equal(clf.tree_.children_left, reg.tree_.children_left)
assert_array_equal(clf.tree_.children_right, reg.tree_.children_right)
assert_array_equal(clf.tree_.n_node_samples, reg.tree_.n_node_samples)
def test_max_features():
# Check max_features.
for name, TreeRegressor in REG_TREES.items():
reg = TreeRegressor(max_features="auto")
reg.fit(boston.data, boston.target)
assert_equal(reg.max_features_, boston.data.shape[1])
for name, TreeClassifier in CLF_TREES.items():
clf = TreeClassifier(max_features="auto")
clf.fit(iris.data, iris.target)
assert_equal(clf.max_features_, 2)
for name, TreeEstimator in ALL_TREES.items():
est = TreeEstimator(max_features="sqrt")
est.fit(iris.data, iris.target)
assert_equal(est.max_features_,
int(np.sqrt(iris.data.shape[1])))
est = TreeEstimator(max_features="log2")
est.fit(iris.data, iris.target)
assert_equal(est.max_features_,
int(np.log2(iris.data.shape[1])))
est = TreeEstimator(max_features=1)
est.fit(iris.data, iris.target)
assert_equal(est.max_features_, 1)
est = TreeEstimator(max_features=3)
est.fit(iris.data, iris.target)
assert_equal(est.max_features_, 3)
est = TreeEstimator(max_features=0.01)
est.fit(iris.data, iris.target)
assert_equal(est.max_features_, 1)
est = TreeEstimator(max_features=0.5)
est.fit(iris.data, iris.target)
assert_equal(est.max_features_,
int(0.5 * iris.data.shape[1]))
est = TreeEstimator(max_features=1.0)
est.fit(iris.data, iris.target)
assert_equal(est.max_features_, iris.data.shape[1])
est = TreeEstimator(max_features=None)
est.fit(iris.data, iris.target)
assert_equal(est.max_features_, iris.data.shape[1])
# use values of max_features that are invalid
est = TreeEstimator(max_features=10)
assert_raises(ValueError, est.fit, X, y)
est = TreeEstimator(max_features=-1)
assert_raises(ValueError, est.fit, X, y)
est = TreeEstimator(max_features=0.0)
assert_raises(ValueError, est.fit, X, y)
est = TreeEstimator(max_features=1.5)
assert_raises(ValueError, est.fit, X, y)
est = TreeEstimator(max_features="foobar")
assert_raises(ValueError, est.fit, X, y)
def test_error():
# Test that it gives proper exception on deficient input.
for name, TreeEstimator in CLF_TREES.items():
# predict before fit
est = TreeEstimator()
assert_raises(NotFittedError, est.predict_proba, X)
est.fit(X, y)
X2 = [[-2, -1, 1]] # wrong feature shape for sample
assert_raises(ValueError, est.predict_proba, X2)
for name, TreeEstimator in ALL_TREES.items():
# Invalid values for parameters
assert_raises(ValueError, TreeEstimator(min_samples_leaf=-1).fit, X, y)
assert_raises(ValueError, TreeEstimator(min_samples_leaf=.6).fit, X, y)
assert_raises(ValueError, TreeEstimator(min_samples_leaf=0.).fit, X, y)
assert_raises(ValueError,
TreeEstimator(min_weight_fraction_leaf=-1).fit,
X, y)
assert_raises(ValueError,
TreeEstimator(min_weight_fraction_leaf=0.51).fit,
X, y)
assert_raises(ValueError, TreeEstimator(min_samples_split=-1).fit,
X, y)
assert_raises(ValueError, TreeEstimator(min_samples_split=0.0).fit,
X, y)
assert_raises(ValueError, TreeEstimator(min_samples_split=1.1).fit,
X, y)
assert_raises(ValueError, TreeEstimator(max_depth=-1).fit, X, y)
assert_raises(ValueError, TreeEstimator(max_features=42).fit, X, y)
# Wrong dimensions
est = TreeEstimator()
y2 = y[:-1]
assert_raises(ValueError, est.fit, X, y2)
# Test with arrays that are non-contiguous.
Xf = np.asfortranarray(X)
est = TreeEstimator()
est.fit(Xf, y)
assert_almost_equal(est.predict(T), true_result)
# predict before fitting
est = TreeEstimator()
assert_raises(NotFittedError, est.predict, T)
# predict on vector with different dims
est.fit(X, y)
t = np.asarray(T)
assert_raises(ValueError, est.predict, t[:, 1:])
# wrong sample shape
Xt = np.array(X).T
est = TreeEstimator()
est.fit(np.dot(X, Xt), y)
assert_raises(ValueError, est.predict, X)
assert_raises(ValueError, est.apply, X)
clf = TreeEstimator()
clf.fit(X, y)
assert_raises(ValueError, clf.predict, Xt)
assert_raises(ValueError, clf.apply, Xt)
# apply before fitting
est = TreeEstimator()
assert_raises(NotFittedError, est.apply, T)
def test_min_samples_split():
"""Test min_samples_split parameter"""
X = np.asfortranarray(iris.data.astype(tree._tree.DTYPE))
y = iris.target
# test both DepthFirstTreeBuilder and BestFirstTreeBuilder
# by setting max_leaf_nodes
for max_leaf_nodes, name in product((None, 1000), ALL_TREES.keys()):
TreeEstimator = ALL_TREES[name]
# test for integer parameter
est = TreeEstimator(min_samples_split=10,
max_leaf_nodes=max_leaf_nodes,
random_state=0)
est.fit(X, y)
# count samples on nodes, -1 means it is a leaf
node_samples = est.tree_.n_node_samples[est.tree_.children_left != -1]
assert_greater(np.min(node_samples), 9,
"Failed with {0}".format(name))
# test for float parameter
est = TreeEstimator(min_samples_split=0.2,
max_leaf_nodes=max_leaf_nodes,
random_state=0)
est.fit(X, y)
# count samples on nodes, -1 means it is a leaf
node_samples = est.tree_.n_node_samples[est.tree_.children_left != -1]
assert_greater(np.min(node_samples), 9,
"Failed with {0}".format(name))
def test_min_samples_leaf():
# Test if leaves contain more than leaf_count training examples
X = np.asfortranarray(iris.data.astype(tree._tree.DTYPE))
y = iris.target
# test both DepthFirstTreeBuilder and BestFirstTreeBuilder
# by setting max_leaf_nodes
for max_leaf_nodes, name in product((None, 1000), ALL_TREES.keys()):
TreeEstimator = ALL_TREES[name]
# test integer parameter
est = TreeEstimator(min_samples_leaf=5,
max_leaf_nodes=max_leaf_nodes,
random_state=0)
est.fit(X, y)
out = est.tree_.apply(X)
node_counts = np.bincount(out)
# drop inner nodes
leaf_count = node_counts[node_counts != 0]
assert_greater(np.min(leaf_count), 4,
"Failed with {0}".format(name))
# test float parameter
est = TreeEstimator(min_samples_leaf=0.1,
max_leaf_nodes=max_leaf_nodes,
random_state=0)
est.fit(X, y)
out = est.tree_.apply(X)
node_counts = np.bincount(out)
# drop inner nodes
leaf_count = node_counts[node_counts != 0]
assert_greater(np.min(leaf_count), 4,
"Failed with {0}".format(name))
def check_min_weight_fraction_leaf(name, datasets, sparse=False):
"""Test if leaves contain at least min_weight_fraction_leaf of the
training set"""
if sparse:
X = DATASETS[datasets]["X_sparse"].astype(np.float32)
else:
X = DATASETS[datasets]["X"].astype(np.float32)
y = DATASETS[datasets]["y"]
weights = rng.rand(X.shape[0])
total_weight = np.sum(weights)
TreeEstimator = ALL_TREES[name]
# test both DepthFirstTreeBuilder and BestFirstTreeBuilder
# by setting max_leaf_nodes
for max_leaf_nodes, frac in product((None, 1000), np.linspace(0, 0.5, 6)):
est = TreeEstimator(min_weight_fraction_leaf=frac,
max_leaf_nodes=max_leaf_nodes,
random_state=0)
est.fit(X, y, sample_weight=weights)
if sparse:
out = est.tree_.apply(X.tocsr())
else:
out = est.tree_.apply(X)
node_weights = np.bincount(out, weights=weights)
# drop inner nodes
leaf_weights = node_weights[node_weights != 0]
assert_greater_equal(
np.min(leaf_weights),
total_weight * est.min_weight_fraction_leaf,
"Failed with {0} "
"min_weight_fraction_leaf={1}".format(
name, est.min_weight_fraction_leaf))
def test_min_weight_fraction_leaf():
# Check on dense input
for name in ALL_TREES:
yield check_min_weight_fraction_leaf, name, "iris"
# Check on sparse input
for name in SPARSE_TREES:
yield check_min_weight_fraction_leaf, name, "multilabel", True
def test_pickle():
for name, TreeEstimator in ALL_TREES.items():
if "Classifier" in name:
X, y = iris.data, iris.target
else:
X, y = boston.data, boston.target
est = TreeEstimator(random_state=0)
est.fit(X, y)
score = est.score(X, y)
fitted_attribute = dict()
for attribute in ["max_depth", "node_count", "capacity"]:
fitted_attribute[attribute] = getattr(est.tree_, attribute)
serialized_object = pickle.dumps(est)
est2 = pickle.loads(serialized_object)
assert_equal(type(est2), est.__class__)
score2 = est2.score(X, y)
assert_equal(score, score2,
"Failed to generate same score after pickling "
"with {0}".format(name))
for attribute in fitted_attribute:
assert_equal(getattr(est2.tree_, attribute),
fitted_attribute[attribute],
"Failed to generate same attribute {0} after "
"pickling with {1}".format(attribute, name))
def test_multioutput():
# Check estimators on multi-output problems.
X = [[-2, -1],
[-1, -1],
[-1, -2],
[1, 1],
[1, 2],
[2, 1],
[-2, 1],
[-1, 1],
[-1, 2],
[2, -1],
[1, -1],
[1, -2]]
y = [[-1, 0],
[-1, 0],
[-1, 0],
[1, 1],
[1, 1],
[1, 1],
[-1, 2],
[-1, 2],
[-1, 2],
[1, 3],
[1, 3],
[1, 3]]
T = [[-1, -1], [1, 1], [-1, 1], [1, -1]]
y_true = [[-1, 0], [1, 1], [-1, 2], [1, 3]]
# toy classification problem
for name, TreeClassifier in CLF_TREES.items():
clf = TreeClassifier(random_state=0)
y_hat = clf.fit(X, y).predict(T)
assert_array_equal(y_hat, y_true)
assert_equal(y_hat.shape, (4, 2))
proba = clf.predict_proba(T)
assert_equal(len(proba), 2)
assert_equal(proba[0].shape, (4, 2))
assert_equal(proba[1].shape, (4, 4))
log_proba = clf.predict_log_proba(T)
assert_equal(len(log_proba), 2)
assert_equal(log_proba[0].shape, (4, 2))
assert_equal(log_proba[1].shape, (4, 4))
# toy regression problem
for name, TreeRegressor in REG_TREES.items():
reg = TreeRegressor(random_state=0)
y_hat = reg.fit(X, y).predict(T)
assert_almost_equal(y_hat, y_true)
assert_equal(y_hat.shape, (4, 2))
def test_classes_shape():
# Test that n_classes_ and classes_ have proper shape.
for name, TreeClassifier in CLF_TREES.items():
# Classification, single output
clf = TreeClassifier(random_state=0)
clf.fit(X, y)
assert_equal(clf.n_classes_, 2)
assert_array_equal(clf.classes_, [-1, 1])
# Classification, multi-output
_y = np.vstack((y, np.array(y) * 2)).T
clf = TreeClassifier(random_state=0)
clf.fit(X, _y)
assert_equal(len(clf.n_classes_), 2)
assert_equal(len(clf.classes_), 2)
assert_array_equal(clf.n_classes_, [2, 2])
assert_array_equal(clf.classes_, [[-1, 1], [-2, 2]])
def test_unbalanced_iris():
# Check class rebalancing.
unbalanced_X = iris.data[:125]
unbalanced_y = iris.target[:125]
sample_weight = compute_sample_weight("balanced", unbalanced_y)
for name, TreeClassifier in CLF_TREES.items():
clf = TreeClassifier(random_state=0)
clf.fit(unbalanced_X, unbalanced_y, sample_weight=sample_weight)
assert_almost_equal(clf.predict(unbalanced_X), unbalanced_y)
def test_memory_layout():
# Check that it works no matter the memory layout
for (name, TreeEstimator), dtype in product(ALL_TREES.items(),
[np.float64, np.float32]):
est = TreeEstimator(random_state=0)
# Nothing
X = np.asarray(iris.data, dtype=dtype)
y = iris.target
assert_array_equal(est.fit(X, y).predict(X), y)
# C-order
X = np.asarray(iris.data, order="C", dtype=dtype)
y = iris.target
assert_array_equal(est.fit(X, y).predict(X), y)
# F-order
X = np.asarray(iris.data, order="F", dtype=dtype)
y = iris.target
assert_array_equal(est.fit(X, y).predict(X), y)
# Contiguous
X = np.ascontiguousarray(iris.data, dtype=dtype)
y = iris.target
assert_array_equal(est.fit(X, y).predict(X), y)
if not est.presort:
# csr matrix
X = csr_matrix(iris.data, dtype=dtype)
y = iris.target
assert_array_equal(est.fit(X, y).predict(X), y)
# csc_matrix
X = csc_matrix(iris.data, dtype=dtype)
y = iris.target
assert_array_equal(est.fit(X, y).predict(X), y)
# Strided
X = np.asarray(iris.data[::3], dtype=dtype)
y = iris.target[::3]
assert_array_equal(est.fit(X, y).predict(X), y)
def test_sample_weight():
# Check sample weighting.
# Test that zero-weighted samples are not taken into account
X = np.arange(100)[:, np.newaxis]
y = np.ones(100)
y[:50] = 0.0
sample_weight = np.ones(100)
sample_weight[y == 0] = 0.0
clf = DecisionTreeClassifier(random_state=0)
clf.fit(X, y, sample_weight=sample_weight)
assert_array_equal(clf.predict(X), np.ones(100))
# Test that low weighted samples are not taken into account at low depth
X = np.arange(200)[:, np.newaxis]
y = np.zeros(200)
y[50:100] = 1
y[100:200] = 2
X[100:200, 0] = 200
sample_weight = np.ones(200)
sample_weight[y == 2] = .51 # Samples of class '2' are still weightier
clf = DecisionTreeClassifier(max_depth=1, random_state=0)
clf.fit(X, y, sample_weight=sample_weight)
assert_equal(clf.tree_.threshold[0], 149.5)
sample_weight[y == 2] = .5 # Samples of class '2' are no longer weightier
clf = DecisionTreeClassifier(max_depth=1, random_state=0)
clf.fit(X, y, sample_weight=sample_weight)
assert_equal(clf.tree_.threshold[0], 49.5) # Threshold should have moved
# Test that sample weighting is the same as having duplicates
X = iris.data
y = iris.target
duplicates = rng.randint(0, X.shape[0], 100)
clf = DecisionTreeClassifier(random_state=1)
clf.fit(X[duplicates], y[duplicates])
sample_weight = np.bincount(duplicates, minlength=X.shape[0])
clf2 = DecisionTreeClassifier(random_state=1)
clf2.fit(X, y, sample_weight=sample_weight)
internal = clf.tree_.children_left != tree._tree.TREE_LEAF
assert_array_almost_equal(clf.tree_.threshold[internal],
clf2.tree_.threshold[internal])
def test_sample_weight_invalid():
# Check sample weighting raises errors.
X = np.arange(100)[:, np.newaxis]
y = np.ones(100)
y[:50] = 0.0
clf = DecisionTreeClassifier(random_state=0)
sample_weight = np.random.rand(100, 1)
assert_raises(ValueError, clf.fit, X, y, sample_weight=sample_weight)
sample_weight = np.array(0)
assert_raises(ValueError, clf.fit, X, y, sample_weight=sample_weight)
sample_weight = np.ones(101)
assert_raises(ValueError, clf.fit, X, y, sample_weight=sample_weight)
sample_weight = np.ones(99)
assert_raises(ValueError, clf.fit, X, y, sample_weight=sample_weight)
def check_class_weights(name):
"""Check class_weights resemble sample_weights behavior."""
TreeClassifier = CLF_TREES[name]
# Iris is balanced, so no effect expected for using 'balanced' weights
clf1 = TreeClassifier(random_state=0)
clf1.fit(iris.data, iris.target)
clf2 = TreeClassifier(class_weight='balanced', random_state=0)
clf2.fit(iris.data, iris.target)
assert_almost_equal(clf1.feature_importances_, clf2.feature_importances_)
# Make a multi-output problem with three copies of Iris
iris_multi = np.vstack((iris.target, iris.target, iris.target)).T
# Create user-defined weights that should balance over the outputs
clf3 = TreeClassifier(class_weight=[{0: 2., 1: 2., 2: 1.},
{0: 2., 1: 1., 2: 2.},
{0: 1., 1: 2., 2: 2.}],
random_state=0)
clf3.fit(iris.data, iris_multi)
assert_almost_equal(clf2.feature_importances_, clf3.feature_importances_)
# Check against multi-output "auto" which should also have no effect
clf4 = TreeClassifier(class_weight='balanced', random_state=0)
clf4.fit(iris.data, iris_multi)
assert_almost_equal(clf3.feature_importances_, clf4.feature_importances_)
# Inflate importance of class 1, check against user-defined weights
sample_weight = np.ones(iris.target.shape)
sample_weight[iris.target == 1] *= 100
class_weight = {0: 1., 1: 100., 2: 1.}
clf1 = TreeClassifier(random_state=0)
clf1.fit(iris.data, iris.target, sample_weight)
clf2 = TreeClassifier(class_weight=class_weight, random_state=0)
clf2.fit(iris.data, iris.target)
assert_almost_equal(clf1.feature_importances_, clf2.feature_importances_)
# Check that sample_weight and class_weight are multiplicative
clf1 = TreeClassifier(random_state=0)
clf1.fit(iris.data, iris.target, sample_weight ** 2)
clf2 = TreeClassifier(class_weight=class_weight, random_state=0)
clf2.fit(iris.data, iris.target, sample_weight)
assert_almost_equal(clf1.feature_importances_, clf2.feature_importances_)
def test_class_weights():
for name in CLF_TREES:
yield check_class_weights, name
def check_class_weight_errors(name):
# Test if class_weight raises errors and warnings when expected.
TreeClassifier = CLF_TREES[name]
_y = np.vstack((y, np.array(y) * 2)).T
# Invalid preset string
clf = TreeClassifier(class_weight='the larch', random_state=0)
assert_raises(ValueError, clf.fit, X, y)
assert_raises(ValueError, clf.fit, X, _y)
# Not a list or preset for multi-output
clf = TreeClassifier(class_weight=1, random_state=0)
assert_raises(ValueError, clf.fit, X, _y)
# Incorrect length list for multi-output
clf = TreeClassifier(class_weight=[{-1: 0.5, 1: 1.}], random_state=0)
assert_raises(ValueError, clf.fit, X, _y)
def test_class_weight_errors():
for name in CLF_TREES:
yield check_class_weight_errors, name
def test_max_leaf_nodes():
# Test greedy trees with max_depth + 1 leafs.
from sklearn.tree._tree import TREE_LEAF
X, y = datasets.make_hastie_10_2(n_samples=100, random_state=1)
k = 4
for name, TreeEstimator in ALL_TREES.items():
est = TreeEstimator(max_depth=None, max_leaf_nodes=k + 1).fit(X, y)
tree = est.tree_
assert_equal((tree.children_left == TREE_LEAF).sum(), k + 1)
# max_leaf_nodes in (0, 1) should raise ValueError
est = TreeEstimator(max_depth=None, max_leaf_nodes=0)
assert_raises(ValueError, est.fit, X, y)
est = TreeEstimator(max_depth=None, max_leaf_nodes=1)
assert_raises(ValueError, est.fit, X, y)
est = TreeEstimator(max_depth=None, max_leaf_nodes=0.1)
assert_raises(ValueError, est.fit, X, y)
def test_max_leaf_nodes_max_depth():
# Test preceedence of max_leaf_nodes over max_depth.
X, y = datasets.make_hastie_10_2(n_samples=100, random_state=1)
k = 4
for name, TreeEstimator in ALL_TREES.items():
est = TreeEstimator(max_depth=1, max_leaf_nodes=k).fit(X, y)
tree = est.tree_
assert_greater(tree.max_depth, 1)
def test_arrays_persist():
# Ensure property arrays' memory stays alive when tree disappears
# non-regression for #2726
for attr in ['n_classes', 'value', 'children_left', 'children_right',
'threshold', 'impurity', 'feature', 'n_node_samples']:
value = getattr(DecisionTreeClassifier().fit([[0], [1]], [0, 1]).tree_, attr)
# if pointing to freed memory, contents may be arbitrary
assert_true(-3 <= value.flat[0] < 3,
'Array points to arbitrary memory')
def test_only_constant_features():
random_state = check_random_state(0)
X = np.zeros((10, 20))
y = random_state.randint(0, 2, (10, ))
for name, TreeEstimator in ALL_TREES.items():
est = TreeEstimator(random_state=0)
est.fit(X, y)
assert_equal(est.tree_.max_depth, 0)
def test_with_only_one_non_constant_features():
X = np.hstack([np.array([[1.], [1.], [0.], [0.]]),
np.zeros((4, 1000))])
y = np.array([0., 1., 0., 1.0])
for name, TreeEstimator in CLF_TREES.items():
est = TreeEstimator(random_state=0, max_features=1)
est.fit(X, y)
assert_equal(est.tree_.max_depth, 1)
assert_array_equal(est.predict_proba(X), 0.5 * np.ones((4, 2)))
for name, TreeEstimator in REG_TREES.items():
est = TreeEstimator(random_state=0, max_features=1)
est.fit(X, y)
assert_equal(est.tree_.max_depth, 1)
assert_array_equal(est.predict(X), 0.5 * np.ones((4, )))
def test_big_input():
# Test if the warning for too large inputs is appropriate.
X = np.repeat(10 ** 40., 4).astype(np.float64).reshape(-1, 1)
clf = DecisionTreeClassifier()
try:
clf.fit(X, [0, 1, 0, 1])
except ValueError as e:
assert_in("float32", str(e))
def test_realloc():
from sklearn.tree._utils import _realloc_test
assert_raises(MemoryError, _realloc_test)
def test_huge_allocations():
n_bits = int(platform.architecture()[0].rstrip('bit'))
X = np.random.randn(10, 2)
y = np.random.randint(0, 2, 10)
# Sanity check: we cannot request more memory than the size of the address
# space. Currently raises OverflowError.
huge = 2 ** (n_bits + 1)
clf = DecisionTreeClassifier(splitter='best', max_leaf_nodes=huge)
assert_raises(Exception, clf.fit, X, y)
# Non-regression test: MemoryError used to be dropped by Cython
# because of missing "except *".
huge = 2 ** (n_bits - 1) - 1
clf = DecisionTreeClassifier(splitter='best', max_leaf_nodes=huge)
assert_raises(MemoryError, clf.fit, X, y)
def check_sparse_input(tree, dataset, max_depth=None):
TreeEstimator = ALL_TREES[tree]
X = DATASETS[dataset]["X"]
X_sparse = DATASETS[dataset]["X_sparse"]
y = DATASETS[dataset]["y"]
# Gain testing time
if dataset in ["digits", "boston"]:
n_samples = X.shape[0] // 5
X = X[:n_samples]
X_sparse = X_sparse[:n_samples]
y = y[:n_samples]
for sparse_format in (csr_matrix, csc_matrix, coo_matrix):
X_sparse = sparse_format(X_sparse)
# Check the default (depth first search)
d = TreeEstimator(random_state=0, max_depth=max_depth).fit(X, y)
s = TreeEstimator(random_state=0, max_depth=max_depth).fit(X_sparse, y)
assert_tree_equal(d.tree_, s.tree_,
"{0} with dense and sparse format gave different "
"trees".format(tree))
y_pred = d.predict(X)
if tree in CLF_TREES:
y_proba = d.predict_proba(X)
y_log_proba = d.predict_log_proba(X)
for sparse_matrix in (csr_matrix, csc_matrix, coo_matrix):
X_sparse_test = sparse_matrix(X_sparse, dtype=np.float32)
assert_array_almost_equal(s.predict(X_sparse_test), y_pred)
if tree in CLF_TREES:
assert_array_almost_equal(s.predict_proba(X_sparse_test),
y_proba)
assert_array_almost_equal(s.predict_log_proba(X_sparse_test),
y_log_proba)
def test_sparse_input():
for tree, dataset in product(SPARSE_TREES,
("clf_small", "toy", "digits", "multilabel",
"sparse-pos", "sparse-neg", "sparse-mix",
"zeros")):
max_depth = 3 if dataset == "digits" else None
yield (check_sparse_input, tree, dataset, max_depth)
# Due to numerical instability of MSE and too strict test, we limit the
# maximal depth
for tree, dataset in product(REG_TREES, ["boston", "reg_small"]):
if tree in SPARSE_TREES:
yield (check_sparse_input, tree, dataset, 2)
def check_sparse_parameters(tree, dataset):
TreeEstimator = ALL_TREES[tree]
X = DATASETS[dataset]["X"]
X_sparse = DATASETS[dataset]["X_sparse"]
y = DATASETS[dataset]["y"]
# Check max_features
d = TreeEstimator(random_state=0, max_features=1, max_depth=2).fit(X, y)
s = TreeEstimator(random_state=0, max_features=1,
max_depth=2).fit(X_sparse, y)
assert_tree_equal(d.tree_, s.tree_,
"{0} with dense and sparse format gave different "
"trees".format(tree))
assert_array_almost_equal(s.predict(X), d.predict(X))
# Check min_samples_split
d = TreeEstimator(random_state=0, max_features=1,
min_samples_split=10).fit(X, y)
s = TreeEstimator(random_state=0, max_features=1,
min_samples_split=10).fit(X_sparse, y)
assert_tree_equal(d.tree_, s.tree_,
"{0} with dense and sparse format gave different "
"trees".format(tree))
assert_array_almost_equal(s.predict(X), d.predict(X))
# Check min_samples_leaf
d = TreeEstimator(random_state=0,
min_samples_leaf=X_sparse.shape[0] // 2).fit(X, y)
s = TreeEstimator(random_state=0,
min_samples_leaf=X_sparse.shape[0] // 2).fit(X_sparse, y)
assert_tree_equal(d.tree_, s.tree_,
"{0} with dense and sparse format gave different "
"trees".format(tree))
assert_array_almost_equal(s.predict(X), d.predict(X))
# Check best-first search
d = TreeEstimator(random_state=0, max_leaf_nodes=3).fit(X, y)
s = TreeEstimator(random_state=0, max_leaf_nodes=3).fit(X_sparse, y)
assert_tree_equal(d.tree_, s.tree_,
"{0} with dense and sparse format gave different "
"trees".format(tree))
assert_array_almost_equal(s.predict(X), d.predict(X))
def test_sparse_parameters():
for tree, dataset in product(SPARSE_TREES,
["sparse-pos", "sparse-neg", "sparse-mix",
"zeros"]):
yield (check_sparse_parameters, tree, dataset)
def check_sparse_criterion(tree, dataset):
TreeEstimator = ALL_TREES[tree]
X = DATASETS[dataset]["X"]
X_sparse = DATASETS[dataset]["X_sparse"]
y = DATASETS[dataset]["y"]
# Check various criterion
CRITERIONS = REG_CRITERIONS if tree in REG_TREES else CLF_CRITERIONS
for criterion in CRITERIONS:
d = TreeEstimator(random_state=0, max_depth=3,
criterion=criterion).fit(X, y)
s = TreeEstimator(random_state=0, max_depth=3,
criterion=criterion).fit(X_sparse, y)
assert_tree_equal(d.tree_, s.tree_,
"{0} with dense and sparse format gave different "
"trees".format(tree))
assert_array_almost_equal(s.predict(X), d.predict(X))
def test_sparse_criterion():
for tree, dataset in product(SPARSE_TREES,
["sparse-pos", "sparse-neg", "sparse-mix",
"zeros"]):
yield (check_sparse_criterion, tree, dataset)
def check_explicit_sparse_zeros(tree, max_depth=3,
n_features=10):
TreeEstimator = ALL_TREES[tree]
# n_samples set n_feature to ease construction of a simultaneous
# construction of a csr and csc matrix
n_samples = n_features
samples = np.arange(n_samples)
# Generate X, y
random_state = check_random_state(0)
indices = []
data = []
offset = 0
indptr = [offset]
for i in range(n_features):
n_nonzero_i = random_state.binomial(n_samples, 0.5)
indices_i = random_state.permutation(samples)[:n_nonzero_i]
indices.append(indices_i)
data_i = random_state.binomial(3, 0.5, size=(n_nonzero_i, )) - 1
data.append(data_i)
offset += n_nonzero_i
indptr.append(offset)
indices = np.concatenate(indices)
data = np.array(np.concatenate(data), dtype=np.float32)
X_sparse = csc_matrix((data, indices, indptr),
shape=(n_samples, n_features))
X = X_sparse.toarray()
X_sparse_test = csr_matrix((data, indices, indptr),
shape=(n_samples, n_features))
X_test = X_sparse_test.toarray()
y = random_state.randint(0, 3, size=(n_samples, ))
# Ensure that X_sparse_test owns its data, indices and indptr array
X_sparse_test = X_sparse_test.copy()
# Ensure that we have explicit zeros
assert_greater((X_sparse.data == 0.).sum(), 0)
assert_greater((X_sparse_test.data == 0.).sum(), 0)
# Perform the comparison
d = TreeEstimator(random_state=0, max_depth=max_depth).fit(X, y)
s = TreeEstimator(random_state=0, max_depth=max_depth).fit(X_sparse, y)
assert_tree_equal(d.tree_, s.tree_,
"{0} with dense and sparse format gave different "
"trees".format(tree))
Xs = (X_test, X_sparse_test)
for X1, X2 in product(Xs, Xs):
assert_array_almost_equal(s.tree_.apply(X1), d.tree_.apply(X2))
assert_array_almost_equal(s.apply(X1), d.apply(X2))
assert_array_almost_equal(s.apply(X1), s.tree_.apply(X1))
assert_array_almost_equal(s.tree_.decision_path(X1).toarray(),
d.tree_.decision_path(X2).toarray())
assert_array_almost_equal(s.decision_path(X1).toarray(),
d.decision_path(X2).toarray())
assert_array_almost_equal(s.decision_path(X1).toarray(),
s.tree_.decision_path(X1).toarray())
assert_array_almost_equal(s.predict(X1), d.predict(X2))
if tree in CLF_TREES:
assert_array_almost_equal(s.predict_proba(X1),
d.predict_proba(X2))
def test_explicit_sparse_zeros():
for tree in SPARSE_TREES:
yield (check_explicit_sparse_zeros, tree)
@ignore_warnings
def check_raise_error_on_1d_input(name):
TreeEstimator = ALL_TREES[name]
X = iris.data[:, 0].ravel()
X_2d = iris.data[:, 0].reshape((-1, 1))
y = iris.target
assert_raises(ValueError, TreeEstimator(random_state=0).fit, X, y)
est = TreeEstimator(random_state=0)
est.fit(X_2d, y)
assert_raises(ValueError, est.predict, [X])
@ignore_warnings
def test_1d_input():
for name in ALL_TREES:
yield check_raise_error_on_1d_input, name
def _check_min_weight_leaf_split_level(TreeEstimator, X, y, sample_weight):
# Private function to keep pretty printing in nose yielded tests
est = TreeEstimator(random_state=0)
est.fit(X, y, sample_weight=sample_weight)
assert_equal(est.tree_.max_depth, 1)
est = TreeEstimator(random_state=0, min_weight_fraction_leaf=0.4)
est.fit(X, y, sample_weight=sample_weight)
assert_equal(est.tree_.max_depth, 0)
def check_min_weight_leaf_split_level(name):
TreeEstimator = ALL_TREES[name]
X = np.array([[0], [0], [0], [0], [1]])
y = [0, 0, 0, 0, 1]
sample_weight = [0.2, 0.2, 0.2, 0.2, 0.2]
_check_min_weight_leaf_split_level(TreeEstimator, X, y, sample_weight)
if not TreeEstimator().presort:
_check_min_weight_leaf_split_level(TreeEstimator, csc_matrix(X), y,
sample_weight)
def test_min_weight_leaf_split_level():
for name in ALL_TREES:
yield check_min_weight_leaf_split_level, name
def check_public_apply(name):
X_small32 = X_small.astype(tree._tree.DTYPE)
est = ALL_TREES[name]()
est.fit(X_small, y_small)
assert_array_equal(est.apply(X_small),
est.tree_.apply(X_small32))
def check_public_apply_sparse(name):
X_small32 = csr_matrix(X_small.astype(tree._tree.DTYPE))
est = ALL_TREES[name]()
est.fit(X_small, y_small)
assert_array_equal(est.apply(X_small),
est.tree_.apply(X_small32))
def test_public_apply():
for name in ALL_TREES:
yield (check_public_apply, name)
for name in SPARSE_TREES:
yield (check_public_apply_sparse, name)
def check_presort_sparse(est, X, y):
assert_raises(ValueError, est.fit, X, y)
def test_presort_sparse():
ests = (DecisionTreeClassifier(presort=True),
DecisionTreeRegressor(presort=True))
sparse_matrices = (csr_matrix, csc_matrix, coo_matrix)
y, X = datasets.make_multilabel_classification(random_state=0,
n_samples=50,
n_features=1,
n_classes=20)
y = y[:, 0]
for est, sparse_matrix in product(ests, sparse_matrices):
yield check_presort_sparse, est, sparse_matrix(X), y
def test_decision_path_hardcoded():
X = iris.data
y = iris.target
est = DecisionTreeClassifier(random_state=0, max_depth=1).fit(X, y)
node_indicator = est.decision_path(X[:2]).toarray()
assert_array_equal(node_indicator, [[1, 1, 0], [1, 0, 1]])
def check_decision_path(name):
X = iris.data
y = iris.target
n_samples = X.shape[0]
TreeEstimator = ALL_TREES[name]
est = TreeEstimator(random_state=0, max_depth=2)
est.fit(X, y)
node_indicator_csr = est.decision_path(X)
node_indicator = node_indicator_csr.toarray()
assert_equal(node_indicator.shape, (n_samples, est.tree_.node_count))
# Assert that leaves index are correct
leaves = est.apply(X)
leave_indicator = [node_indicator[i, j] for i, j in enumerate(leaves)]
assert_array_almost_equal(leave_indicator, np.ones(shape=n_samples))
# Ensure only one leave node per sample
all_leaves = est.tree_.children_left == TREE_LEAF
assert_array_almost_equal(np.dot(node_indicator, all_leaves),
np.ones(shape=n_samples))
# Ensure max depth is consistent with sum of indicator
max_depth = node_indicator.sum(axis=1).max()
assert_less_equal(est.tree_.max_depth, max_depth)
def test_decision_path():
for name in ALL_TREES:
yield (check_decision_path, name)
def check_no_sparse_y_support(name):
X, y = X_multilabel, csr_matrix(y_multilabel)
TreeEstimator = ALL_TREES[name]
assert_raises(ValueError, TreeEstimator(random_state=0).fit, X, y)
def test_no_sparse_y_support():
# Currently we don't support sparse y
for name in ALL_TREES:
yield (check_decision_path, name)
|
bsd-3-clause
|
[
624,
199,
9029,
367,
314,
3123,
859,
334,
27993,
14,
2350,
680,
199,
624,
199,
646,
5927,
199,
504,
9143,
492,
7417,
199,
504,
7975,
492,
3336,
199,
646,
4298,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
4421,
492,
28308,
63,
3642,
199,
504,
7026,
14,
4421,
492,
22258,
63,
3642,
199,
504,
7026,
14,
4421,
492,
512,
79,
63,
3642,
199,
199,
504,
6357,
14,
2355,
63,
16539,
492,
5178,
63,
2355,
63,
3642,
199,
199,
504,
6357,
14,
6759,
492,
12862,
63,
3397,
199,
504,
6357,
14,
6759,
492,
4615,
63,
12973,
63,
705,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
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,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
262,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
4776,
492,
6534,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
199,
504,
6357,
14,
1208,
14,
6136,
492,
1104,
63,
2355,
63,
929,
199,
199,
504,
6357,
14,
3924,
492,
2832,
13776,
471,
547,
199,
199,
504,
6357,
14,
2350,
492,
1487,
24116,
8508,
199,
504,
6357,
14,
2350,
492,
1487,
24116,
15155,
199,
504,
6357,
14,
2350,
492,
11177,
3987,
8508,
199,
504,
6357,
14,
2350,
492,
11177,
3987,
15155,
199,
199,
504,
6357,
492,
3123,
199,
504,
6357,
14,
2350,
14,
2350,
492,
428,
23354,
63,
30538,
1157,
51,
199,
504,
6357,
14,
2350,
423,
2350,
492,
377,
5271,
63,
906,
5699,
199,
504,
6357,
492,
13148,
199,
199,
504,
6357,
14,
1208,
492,
4526,
63,
3271,
63,
3463,
199,
199,
1981,
38,
63,
2944,
11084,
2823,
275,
1689,
903,
73,
401,
298,
10435,
531,
199,
5616,
63,
2944,
11084,
2823,
275,
1689,
23927,
401,
776,
199,
199,
1981,
38,
63,
52,
907,
654,
275,
469,
272,
298,
872,
24116,
8508,
582,
1487,
24116,
8508,
12,
272,
298,
48,
470,
361,
13,
872,
24116,
8508,
582,
7417,
8,
872,
24116,
8508,
12,
6343,
25210,
361,
29,
549,
395,
272,
298,
7426,
3987,
8508,
582,
11177,
3987,
8508,
12,
199,
93,
199,
199,
5616,
63,
52,
907,
654,
275,
469,
272,
298,
872,
24116,
15155,
582,
1487,
24116,
15155,
12,
272,
298,
48,
470,
361,
13,
872,
24116,
15155,
582,
7417,
8,
872,
24116,
15155,
12,
6163,
25210,
361,
29,
549,
395,
272,
298,
7426,
3987,
15155,
582,
11177,
3987,
15155,
12,
199,
93,
199,
199,
1761,
63,
52,
907,
654,
275,
1211,
342,
199,
1761,
63,
52,
907,
654,
14,
873,
8,
1981,
38,
63,
52,
907,
654,
9,
199,
1761,
63,
52,
907,
654,
14,
873,
8,
5616,
63,
52,
907,
654,
9,
199,
199,
51,
23354,
63,
52,
907,
654,
275,
2097,
872,
24116,
8508,
401,
298,
872,
24116,
15155,
401,
355,
298,
7426,
3987,
8508,
401,
298,
7426,
3987,
15155,
937,
421,
199,
56,
63,
7241,
275,
980,
14,
1144,
779,
272,
359,
16,
12,
378,
12,
841,
12,
378,
12,
378,
12,
378,
12,
413,
12,
446,
1079,
12,
378,
12,
446,
20,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2156,
272,
359,
16,
12,
378,
12,
959,
12,
650,
12,
378,
12,
446,
20,
12,
378,
12,
378,
12,
413,
12,
446,
21,
12,
378,
14,
18,
12,
378,
12,
841,
12,
413,
12,
2156,
272,
5243,
17,
12,
446,
17,
12,
378,
12,
378,
12,
446,
20,
14,
21,
12,
378,
12,
378,
12,
499,
14,
17,
12,
413,
12,
378,
12,
378,
12,
446,
20,
14,
21,
12,
378,
12,
413,
12,
2156,
272,
5243,
17,
12,
446,
17,
12,
378,
12,
446,
17,
14,
18,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
14,
18,
12,
378,
12,
378,
12,
413,
12,
2156,
272,
5243,
17,
12,
446,
17,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
650,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
413,
12,
2156,
272,
5243,
17,
12,
446,
18,
12,
378,
12,
841,
12,
446,
19,
12,
1616,
12,
841,
12,
378,
12,
446,
19,
14,
18,
12,
378,
12,
841,
12,
650,
12,
446,
20,
12,
413,
12,
2156,
272,
359,
18,
14,
845,
12,
378,
12,
446,
22,
12,
446,
16,
14,
21,
12,
378,
12,
4119,
12,
378,
12,
378,
12,
446,
19,
14,
18,
12,
1227,
12,
378,
14,
21,
12,
378,
12,
446,
19,
12,
413,
12,
2156,
272,
359,
18,
14,
845,
12,
378,
12,
446,
22,
12,
446,
16,
14,
21,
12,
378,
12,
4119,
12,
378,
12,
378,
12,
446,
19,
14,
18,
12,
1227,
12,
378,
12,
378,
12,
446,
18,
12,
413,
12,
2156,
272,
359,
18,
14,
845,
12,
1695,
12,
446,
22,
12,
446,
16,
14,
21,
12,
378,
12,
4119,
12,
378,
12,
378,
12,
446,
19,
14,
18,
12,
1227,
12,
378,
12,
378,
12,
446,
18,
12,
413,
12,
2156,
272,
359,
18,
14,
845,
12,
1695,
12,
446,
22,
12,
446,
16,
14,
21,
12,
378,
12,
4119,
12,
378,
12,
378,
12,
446,
19,
14,
18,
12,
1227,
12,
378,
14,
21,
12,
378,
12,
446,
17,
12,
378,
12,
2156,
272,
359,
18,
12,
1695,
12,
959,
12,
413,
12,
378,
14,
21,
12,
446,
20,
12,
1616,
12,
378,
12,
413,
12,
446,
21,
12,
650,
12,
378,
12,
499,
12,
378,
12,
2156,
272,
359,
18,
12,
378,
12,
413,
12,
413,
12,
413,
12,
446,
17,
12,
413
] |
[
199,
9029,
367,
314,
3123,
859,
334,
27993,
14,
2350,
680,
199,
624,
199,
646,
5927,
199,
504,
9143,
492,
7417,
199,
504,
7975,
492,
3336,
199,
646,
4298,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
14,
4421,
492,
28308,
63,
3642,
199,
504,
7026,
14,
4421,
492,
22258,
63,
3642,
199,
504,
7026,
14,
4421,
492,
512,
79,
63,
3642,
199,
199,
504,
6357,
14,
2355,
63,
16539,
492,
5178,
63,
2355,
63,
3642,
199,
199,
504,
6357,
14,
6759,
492,
12862,
63,
3397,
199,
504,
6357,
14,
6759,
492,
4615,
63,
12973,
63,
705,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
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,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
262,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
4776,
492,
6534,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
199,
504,
6357,
14,
1208,
14,
6136,
492,
1104,
63,
2355,
63,
929,
199,
199,
504,
6357,
14,
3924,
492,
2832,
13776,
471,
547,
199,
199,
504,
6357,
14,
2350,
492,
1487,
24116,
8508,
199,
504,
6357,
14,
2350,
492,
1487,
24116,
15155,
199,
504,
6357,
14,
2350,
492,
11177,
3987,
8508,
199,
504,
6357,
14,
2350,
492,
11177,
3987,
15155,
199,
199,
504,
6357,
492,
3123,
199,
504,
6357,
14,
2350,
14,
2350,
492,
428,
23354,
63,
30538,
1157,
51,
199,
504,
6357,
14,
2350,
423,
2350,
492,
377,
5271,
63,
906,
5699,
199,
504,
6357,
492,
13148,
199,
199,
504,
6357,
14,
1208,
492,
4526,
63,
3271,
63,
3463,
199,
199,
1981,
38,
63,
2944,
11084,
2823,
275,
1689,
903,
73,
401,
298,
10435,
531,
199,
5616,
63,
2944,
11084,
2823,
275,
1689,
23927,
401,
776,
199,
199,
1981,
38,
63,
52,
907,
654,
275,
469,
272,
298,
872,
24116,
8508,
582,
1487,
24116,
8508,
12,
272,
298,
48,
470,
361,
13,
872,
24116,
8508,
582,
7417,
8,
872,
24116,
8508,
12,
6343,
25210,
361,
29,
549,
395,
272,
298,
7426,
3987,
8508,
582,
11177,
3987,
8508,
12,
199,
93,
199,
199,
5616,
63,
52,
907,
654,
275,
469,
272,
298,
872,
24116,
15155,
582,
1487,
24116,
15155,
12,
272,
298,
48,
470,
361,
13,
872,
24116,
15155,
582,
7417,
8,
872,
24116,
15155,
12,
6163,
25210,
361,
29,
549,
395,
272,
298,
7426,
3987,
15155,
582,
11177,
3987,
15155,
12,
199,
93,
199,
199,
1761,
63,
52,
907,
654,
275,
1211,
342,
199,
1761,
63,
52,
907,
654,
14,
873,
8,
1981,
38,
63,
52,
907,
654,
9,
199,
1761,
63,
52,
907,
654,
14,
873,
8,
5616,
63,
52,
907,
654,
9,
199,
199,
51,
23354,
63,
52,
907,
654,
275,
2097,
872,
24116,
8508,
401,
298,
872,
24116,
15155,
401,
355,
298,
7426,
3987,
8508,
401,
298,
7426,
3987,
15155,
937,
421,
199,
56,
63,
7241,
275,
980,
14,
1144,
779,
272,
359,
16,
12,
378,
12,
841,
12,
378,
12,
378,
12,
378,
12,
413,
12,
446,
1079,
12,
378,
12,
446,
20,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2156,
272,
359,
16,
12,
378,
12,
959,
12,
650,
12,
378,
12,
446,
20,
12,
378,
12,
378,
12,
413,
12,
446,
21,
12,
378,
14,
18,
12,
378,
12,
841,
12,
413,
12,
2156,
272,
5243,
17,
12,
446,
17,
12,
378,
12,
378,
12,
446,
20,
14,
21,
12,
378,
12,
378,
12,
499,
14,
17,
12,
413,
12,
378,
12,
378,
12,
446,
20,
14,
21,
12,
378,
12,
413,
12,
2156,
272,
5243,
17,
12,
446,
17,
12,
378,
12,
446,
17,
14,
18,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
14,
18,
12,
378,
12,
378,
12,
413,
12,
2156,
272,
5243,
17,
12,
446,
17,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
650,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
413,
12,
2156,
272,
5243,
17,
12,
446,
18,
12,
378,
12,
841,
12,
446,
19,
12,
1616,
12,
841,
12,
378,
12,
446,
19,
14,
18,
12,
378,
12,
841,
12,
650,
12,
446,
20,
12,
413,
12,
2156,
272,
359,
18,
14,
845,
12,
378,
12,
446,
22,
12,
446,
16,
14,
21,
12,
378,
12,
4119,
12,
378,
12,
378,
12,
446,
19,
14,
18,
12,
1227,
12,
378,
14,
21,
12,
378,
12,
446,
19,
12,
413,
12,
2156,
272,
359,
18,
14,
845,
12,
378,
12,
446,
22,
12,
446,
16,
14,
21,
12,
378,
12,
4119,
12,
378,
12,
378,
12,
446,
19,
14,
18,
12,
1227,
12,
378,
12,
378,
12,
446,
18,
12,
413,
12,
2156,
272,
359,
18,
14,
845,
12,
1695,
12,
446,
22,
12,
446,
16,
14,
21,
12,
378,
12,
4119,
12,
378,
12,
378,
12,
446,
19,
14,
18,
12,
1227,
12,
378,
12,
378,
12,
446,
18,
12,
413,
12,
2156,
272,
359,
18,
14,
845,
12,
1695,
12,
446,
22,
12,
446,
16,
14,
21,
12,
378,
12,
4119,
12,
378,
12,
378,
12,
446,
19,
14,
18,
12,
1227,
12,
378,
14,
21,
12,
378,
12,
446,
17,
12,
378,
12,
2156,
272,
359,
18,
12,
1695,
12,
959,
12,
413,
12,
378,
14,
21,
12,
446,
20,
12,
1616,
12,
378,
12,
413,
12,
446,
21,
12,
650,
12,
378,
12,
499,
12,
378,
12,
2156,
272,
359,
18,
12,
378,
12,
413,
12,
413,
12,
413,
12,
446,
17,
12,
413,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cicorias/mongo-web-shell
|
tests/__init__.py
|
8
|
1468
|
# Copyright 2013 10gen 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 logging
import flask
from unittest2 import defaultTestLoader, TestCase
from webapps.server.app import create_app
if not flask.has_app_context():
app = create_app()
app.testing = True
app.config['QUOTA_NUM_COLLECTIONS'] = None
_logger = logging.getLogger(__name__)
class MongoWSTestCase(TestCase):
"""A generic test case for the mongows package."""
def setUp(self):
self.real_app = app
self.app = app.test_client()
ctx = app.app_context()
ctx.push()
def tearDown(self):
pass
def load_tests():
"""Returns the test modules for the mongows package.
The expected output of this function is defined by the unittest module's
load_tests protocol. unittest.main() will runs tests on the modules
returned by this function.
"""
return defaultTestLoader.discover(__name__)
|
apache-2.0
|
[
3,
259,
1898,
6171,
1616,
2268,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
259,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
259,
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,
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,
199,
3,
259,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
259,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
259,
4204,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
646,
7209,
199,
504,
2882,
18,
492,
849,
15824,
12,
7640,
199,
199,
504,
3330,
5181,
14,
1000,
14,
571,
492,
1218,
63,
571,
199,
199,
692,
440,
7209,
14,
1989,
63,
571,
63,
1100,
837,
272,
1145,
275,
1218,
63,
571,
342,
272,
1145,
14,
4776,
275,
715,
272,
1145,
14,
888,
459,
18654,
33,
63,
7125,
63,
23037,
2823,
418,
275,
488,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
13503,
5035,
1746,
8,
1746,
304,
272,
408,
33,
7809,
511,
1930,
367,
314,
32315,
27649,
2559,
1041,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3093,
63,
571,
275,
1145,
267,
291,
14,
571,
275,
1145,
14,
396,
63,
1258,
342,
267,
4027,
275,
1145,
14,
571,
63,
1100,
342,
267,
4027,
14,
5335,
342,
339,
347,
6766,
8,
277,
304,
267,
986,
421,
199,
318,
2248,
63,
2219,
837,
272,
408,
3407,
314,
511,
4621,
367,
314,
32315,
27649,
2559,
14,
339,
710,
1420,
1072,
402,
642,
805,
365,
3247,
701,
314,
2882,
859,
1159,
272,
2248,
63,
2219,
4113,
14,
2882,
14,
973,
342,
911,
7858,
2295,
641,
314,
4621,
272,
2138,
701,
642,
805,
14,
339,
408,
272,
372,
849,
15824,
14,
18861,
3460,
354,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
259,
1898,
6171,
1616,
2268,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
259,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
259,
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,
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,
199,
3,
259,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
259,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
259,
4204,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
646,
7209,
199,
504,
2882,
18,
492,
849,
15824,
12,
7640,
199,
199,
504,
3330,
5181,
14,
1000,
14,
571,
492,
1218,
63,
571,
199,
199,
692,
440,
7209,
14,
1989,
63,
571,
63,
1100,
837,
272,
1145,
275,
1218,
63,
571,
342,
272,
1145,
14,
4776,
275,
715,
272,
1145,
14,
888,
459,
18654,
33,
63,
7125,
63,
23037,
2823,
418,
275,
488,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
13503,
5035,
1746,
8,
1746,
304,
272,
408,
33,
7809,
511,
1930,
367,
314,
32315,
27649,
2559,
1041,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3093,
63,
571,
275,
1145,
267,
291,
14,
571,
275,
1145,
14,
396,
63,
1258,
342,
267,
4027,
275,
1145,
14,
571,
63,
1100,
342,
267,
4027,
14,
5335,
342,
339,
347,
6766,
8,
277,
304,
267,
986,
421,
199,
318,
2248,
63,
2219,
837,
272,
408,
3407,
314,
511,
4621,
367,
314,
32315,
27649,
2559,
14,
339,
710,
1420,
1072,
402,
642,
805,
365,
3247,
701,
314,
2882,
859,
1159,
272,
2248,
63,
2219,
4113,
14,
2882,
14,
973,
342,
911,
7858,
2295,
641,
314,
4621,
272,
2138,
701,
642,
805,
14,
339,
408,
272,
372,
849,
15824,
14,
18861,
3460,
354,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
gauribhoite/personfinder
|
env/site-packages/py-1.4.30-py2.7.egg/py/_code/_assertionnew.py
|
217
|
12384
|
"""
Find intermediate evalutation results in assert statements through builtin AST.
This should replace _assertionold.py eventually.
"""
import sys
import ast
import py
from py._code.assertion import _format_explanation, BuiltinAssertionError
if sys.platform.startswith("java") and sys.version_info < (2, 5, 2):
# See http://bugs.jython.org/issue1497
_exprs = ("BoolOp", "BinOp", "UnaryOp", "Lambda", "IfExp", "Dict",
"ListComp", "GeneratorExp", "Yield", "Compare", "Call",
"Repr", "Num", "Str", "Attribute", "Subscript", "Name",
"List", "Tuple")
_stmts = ("FunctionDef", "ClassDef", "Return", "Delete", "Assign",
"AugAssign", "Print", "For", "While", "If", "With", "Raise",
"TryExcept", "TryFinally", "Assert", "Import", "ImportFrom",
"Exec", "Global", "Expr", "Pass", "Break", "Continue")
_expr_nodes = set(getattr(ast, name) for name in _exprs)
_stmt_nodes = set(getattr(ast, name) for name in _stmts)
def _is_ast_expr(node):
return node.__class__ in _expr_nodes
def _is_ast_stmt(node):
return node.__class__ in _stmt_nodes
else:
def _is_ast_expr(node):
return isinstance(node, ast.expr)
def _is_ast_stmt(node):
return isinstance(node, ast.stmt)
class Failure(Exception):
"""Error found while interpreting AST."""
def __init__(self, explanation=""):
self.cause = sys.exc_info()
self.explanation = explanation
def interpret(source, frame, should_fail=False):
mod = ast.parse(source)
visitor = DebugInterpreter(frame)
try:
visitor.visit(mod)
except Failure:
failure = sys.exc_info()[1]
return getfailure(failure)
if should_fail:
return ("(assertion failed, but when it was re-run for "
"printing intermediate values, it did not fail. Suggestions: "
"compute assert expression before the assert or use --no-assert)")
def run(offending_line, frame=None):
if frame is None:
frame = py.code.Frame(sys._getframe(1))
return interpret(offending_line, frame)
def getfailure(failure):
explanation = _format_explanation(failure.explanation)
value = failure.cause[1]
if str(value):
lines = explanation.splitlines()
if not lines:
lines.append("")
lines[0] += " << %s" % (value,)
explanation = "\n".join(lines)
text = "%s: %s" % (failure.cause[0].__name__, explanation)
if text.startswith("AssertionError: assert "):
text = text[16:]
return text
operator_map = {
ast.BitOr : "|",
ast.BitXor : "^",
ast.BitAnd : "&",
ast.LShift : "<<",
ast.RShift : ">>",
ast.Add : "+",
ast.Sub : "-",
ast.Mult : "*",
ast.Div : "/",
ast.FloorDiv : "//",
ast.Mod : "%",
ast.Eq : "==",
ast.NotEq : "!=",
ast.Lt : "<",
ast.LtE : "<=",
ast.Gt : ">",
ast.GtE : ">=",
ast.Pow : "**",
ast.Is : "is",
ast.IsNot : "is not",
ast.In : "in",
ast.NotIn : "not in"
}
unary_map = {
ast.Not : "not %s",
ast.Invert : "~%s",
ast.USub : "-%s",
ast.UAdd : "+%s"
}
class DebugInterpreter(ast.NodeVisitor):
"""Interpret AST nodes to gleam useful debugging information. """
def __init__(self, frame):
self.frame = frame
def generic_visit(self, node):
# Fallback when we don't have a special implementation.
if _is_ast_expr(node):
mod = ast.Expression(node)
co = self._compile(mod)
try:
result = self.frame.eval(co)
except Exception:
raise Failure()
explanation = self.frame.repr(result)
return explanation, result
elif _is_ast_stmt(node):
mod = ast.Module([node])
co = self._compile(mod, "exec")
try:
self.frame.exec_(co)
except Exception:
raise Failure()
return None, None
else:
raise AssertionError("can't handle %s" %(node,))
def _compile(self, source, mode="eval"):
return compile(source, "<assertion interpretation>", mode)
def visit_Expr(self, expr):
return self.visit(expr.value)
def visit_Module(self, mod):
for stmt in mod.body:
self.visit(stmt)
def visit_Name(self, name):
explanation, result = self.generic_visit(name)
# See if the name is local.
source = "%r in locals() is not globals()" % (name.id,)
co = self._compile(source)
try:
local = self.frame.eval(co)
except Exception:
# have to assume it isn't
local = False
if not local:
return name.id, result
return explanation, result
def visit_Compare(self, comp):
left = comp.left
left_explanation, left_result = self.visit(left)
for op, next_op in zip(comp.ops, comp.comparators):
next_explanation, next_result = self.visit(next_op)
op_symbol = operator_map[op.__class__]
explanation = "%s %s %s" % (left_explanation, op_symbol,
next_explanation)
source = "__exprinfo_left %s __exprinfo_right" % (op_symbol,)
co = self._compile(source)
try:
result = self.frame.eval(co, __exprinfo_left=left_result,
__exprinfo_right=next_result)
except Exception:
raise Failure(explanation)
try:
if not result:
break
except KeyboardInterrupt:
raise
except:
break
left_explanation, left_result = next_explanation, next_result
rcomp = py.code._reprcompare
if rcomp:
res = rcomp(op_symbol, left_result, next_result)
if res:
explanation = res
return explanation, result
def visit_BoolOp(self, boolop):
is_or = isinstance(boolop.op, ast.Or)
explanations = []
for operand in boolop.values:
explanation, result = self.visit(operand)
explanations.append(explanation)
if result == is_or:
break
name = is_or and " or " or " and "
explanation = "(" + name.join(explanations) + ")"
return explanation, result
def visit_UnaryOp(self, unary):
pattern = unary_map[unary.op.__class__]
operand_explanation, operand_result = self.visit(unary.operand)
explanation = pattern % (operand_explanation,)
co = self._compile(pattern % ("__exprinfo_expr",))
try:
result = self.frame.eval(co, __exprinfo_expr=operand_result)
except Exception:
raise Failure(explanation)
return explanation, result
def visit_BinOp(self, binop):
left_explanation, left_result = self.visit(binop.left)
right_explanation, right_result = self.visit(binop.right)
symbol = operator_map[binop.op.__class__]
explanation = "(%s %s %s)" % (left_explanation, symbol,
right_explanation)
source = "__exprinfo_left %s __exprinfo_right" % (symbol,)
co = self._compile(source)
try:
result = self.frame.eval(co, __exprinfo_left=left_result,
__exprinfo_right=right_result)
except Exception:
raise Failure(explanation)
return explanation, result
def visit_Call(self, call):
func_explanation, func = self.visit(call.func)
arg_explanations = []
ns = {"__exprinfo_func" : func}
arguments = []
for arg in call.args:
arg_explanation, arg_result = self.visit(arg)
arg_name = "__exprinfo_%s" % (len(ns),)
ns[arg_name] = arg_result
arguments.append(arg_name)
arg_explanations.append(arg_explanation)
for keyword in call.keywords:
arg_explanation, arg_result = self.visit(keyword.value)
arg_name = "__exprinfo_%s" % (len(ns),)
ns[arg_name] = arg_result
keyword_source = "%s=%%s" % (keyword.arg)
arguments.append(keyword_source % (arg_name,))
arg_explanations.append(keyword_source % (arg_explanation,))
if call.starargs:
arg_explanation, arg_result = self.visit(call.starargs)
arg_name = "__exprinfo_star"
ns[arg_name] = arg_result
arguments.append("*%s" % (arg_name,))
arg_explanations.append("*%s" % (arg_explanation,))
if call.kwargs:
arg_explanation, arg_result = self.visit(call.kwargs)
arg_name = "__exprinfo_kwds"
ns[arg_name] = arg_result
arguments.append("**%s" % (arg_name,))
arg_explanations.append("**%s" % (arg_explanation,))
args_explained = ", ".join(arg_explanations)
explanation = "%s(%s)" % (func_explanation, args_explained)
args = ", ".join(arguments)
source = "__exprinfo_func(%s)" % (args,)
co = self._compile(source)
try:
result = self.frame.eval(co, **ns)
except Exception:
raise Failure(explanation)
pattern = "%s\n{%s = %s\n}"
rep = self.frame.repr(result)
explanation = pattern % (rep, rep, explanation)
return explanation, result
def _is_builtin_name(self, name):
pattern = "%r not in globals() and %r not in locals()"
source = pattern % (name.id, name.id)
co = self._compile(source)
try:
return self.frame.eval(co)
except Exception:
return False
def visit_Attribute(self, attr):
if not isinstance(attr.ctx, ast.Load):
return self.generic_visit(attr)
source_explanation, source_result = self.visit(attr.value)
explanation = "%s.%s" % (source_explanation, attr.attr)
source = "__exprinfo_expr.%s" % (attr.attr,)
co = self._compile(source)
try:
result = self.frame.eval(co, __exprinfo_expr=source_result)
except Exception:
raise Failure(explanation)
explanation = "%s\n{%s = %s.%s\n}" % (self.frame.repr(result),
self.frame.repr(result),
source_explanation, attr.attr)
# Check if the attr is from an instance.
source = "%r in getattr(__exprinfo_expr, '__dict__', {})"
source = source % (attr.attr,)
co = self._compile(source)
try:
from_instance = self.frame.eval(co, __exprinfo_expr=source_result)
except Exception:
from_instance = True
if from_instance:
rep = self.frame.repr(result)
pattern = "%s\n{%s = %s\n}"
explanation = pattern % (rep, rep, explanation)
return explanation, result
def visit_Assert(self, assrt):
test_explanation, test_result = self.visit(assrt.test)
if test_explanation.startswith("False\n{False =") and \
test_explanation.endswith("\n"):
test_explanation = test_explanation[15:-2]
explanation = "assert %s" % (test_explanation,)
if not test_result:
try:
raise BuiltinAssertionError
except Exception:
raise Failure(explanation)
return explanation, test_result
def visit_Assign(self, assign):
value_explanation, value_result = self.visit(assign.value)
explanation = "... = %s" % (value_explanation,)
name = ast.Name("__exprinfo_expr", ast.Load(),
lineno=assign.value.lineno,
col_offset=assign.value.col_offset)
new_assign = ast.Assign(assign.targets, name, lineno=assign.lineno,
col_offset=assign.col_offset)
mod = ast.Module([new_assign])
co = self._compile(mod, "exec")
try:
self.frame.exec_(co, __exprinfo_expr=value_result)
except Exception:
raise Failure(explanation)
return explanation, value_result
|
apache-2.0
|
[
624,
199,
6591,
13197,
3468,
10326,
2058,
315,
702,
9834,
4012,
6762,
20788,
14,
199,
2765,
1077,
3350,
485,
18487,
1753,
14,
647,
21356,
14,
199,
624,
199,
199,
646,
984,
199,
646,
6073,
199,
199,
646,
1134,
199,
504,
1134,
423,
600,
14,
18487,
492,
485,
908,
63,
15228,
12,
22422,
14844,
421,
199,
692,
984,
14,
3246,
14,
2460,
480,
6138,
531,
436,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
959,
12,
499,
304,
272,
327,
1666,
1455,
921,
13017,
14,
27179,
14,
1308,
15,
5237,
1079,
2576,
272,
485,
16006,
275,
1689,
10349,
4619,
401,
298,
13394,
4619,
401,
298,
22401,
4619,
401,
298,
21350,
401,
298,
3917,
4527,
401,
298,
2141,
401,
1598,
298,
1296,
2404,
401,
298,
7599,
4527,
401,
298,
22889,
401,
298,
16051,
401,
298,
2176,
401,
1598,
298,
15713,
401,
298,
5667,
401,
298,
2848,
401,
298,
1646,
401,
298,
2610,
1579,
401,
298,
985,
401,
1598,
298,
1296,
401,
298,
7075,
531,
272,
485,
270,
22862,
275,
1689,
3481,
6172,
401,
298,
2543,
6172,
401,
298,
1767,
401,
298,
5392,
401,
298,
9595,
401,
1598,
298,
21640,
9595,
401,
298,
5375,
401,
298,
1858,
401,
298,
25215,
401,
298,
3917,
401,
298,
3007,
401,
298,
18111,
401,
1598,
298,
12357,
920,
716,
401,
298,
12357,
8694,
1183,
401,
298,
9699,
401,
298,
6295,
401,
298,
6295,
2532,
401,
1598,
298,
4858,
401,
298,
7025,
401,
298,
8561,
401,
298,
4986,
401,
298,
13948,
401,
298,
24055,
531,
272,
485,
3684,
63,
2415,
275,
663,
8,
5675,
8,
1810,
12,
536,
9,
367,
536,
315,
485,
16006,
9,
272,
485,
9649,
63,
2415,
275,
663,
8,
5675,
8,
1810,
12,
536,
9,
367,
536,
315,
485,
270,
22862,
9,
272,
347,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
267,
372,
1031,
855,
533,
363,
315,
485,
3684,
63,
2415,
272,
347,
485,
374,
63,
1810,
63,
9649,
8,
932,
304,
267,
372,
1031,
855,
533,
363,
315,
485,
9649,
63,
2415,
199,
2836,
26,
272,
347,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
267,
372,
1228,
8,
932,
12,
6073,
14,
3684,
9,
272,
347,
485,
374,
63,
1810,
63,
9649,
8,
932,
304,
267,
372,
1228,
8,
932,
12,
6073,
14,
9649,
9,
421,
199,
533,
20367,
8,
1726,
304,
272,
408,
547,
1911,
1830,
6421,
1337,
20788,
1041,
339,
347,
636,
826,
721,
277,
12,
17531,
17364,
267,
291,
14,
2651,
275,
984,
14,
2804,
63,
815,
342,
267,
291,
14,
15228,
275,
17531,
421,
199,
318,
15579,
8,
1365,
12,
2787,
12,
1077,
63,
1633,
29,
797,
304,
272,
3413,
275,
6073,
14,
1122,
8,
1365,
9,
272,
18040,
275,
14245,
2620,
26499,
8,
1943,
9,
272,
862,
26,
267,
18040,
14,
5427,
8,
1494,
9,
272,
871,
20367,
26,
267,
5988,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
267,
372,
664,
5328,
8,
5328,
9,
272,
340,
1077,
63,
1633,
26,
267,
372,
1689,
8,
18487,
3405,
12,
1325,
1380,
652,
1990,
295,
13,
1065,
367,
298,
355,
298,
26514,
13197,
1338,
12,
652,
8103,
440,
2449,
14,
221,
428,
11914,
15293,
26,
298,
355,
298,
3357,
702,
3965,
2544,
314,
702,
503,
675,
1553,
889,
13,
479,
6320,
199,
199,
318,
1255,
8,
1997,
3219,
63,
604,
12,
2787,
29,
403,
304,
272,
340,
2787,
365,
488,
26,
267,
2787,
275,
1134,
14,
600,
14,
3160,
8,
1274,
423,
20912,
8,
17,
430,
272,
372,
15579,
8,
1997,
3219,
63,
604,
12,
2787,
9,
199,
199,
318,
664,
5328,
8,
5328,
304,
272,
17531,
275,
485,
908,
63,
15228,
8,
5328,
14,
15228,
9,
272,
574,
275,
5988,
14,
2651,
59,
17,
61,
272,
340,
620,
8,
585,
304,
267,
2385,
275,
17531,
14,
7644,
342,
267,
340,
440,
2385,
26,
288,
2385,
14,
740,
10804,
267,
2385,
59,
16,
61,
847,
298,
5213,
450,
83,
2,
450,
334,
585,
4258,
267,
17531,
275,
1867,
78,
1674,
904,
8,
1278,
9,
272,
1318,
275,
2071,
83,
26,
450,
83,
2,
450,
334,
5328,
14,
2651,
59,
16,
17979,
354,
3108,
17531,
9,
272,
340,
1318,
14,
2460,
480,
14844,
26,
702,
26699,
267,
1318,
275,
1318,
59,
975,
2938,
272,
372,
1318,
421,
199,
3856,
63,
1130,
275,
469,
272,
6073,
14,
4734,
2844,
520,
15733,
401,
272,
6073,
14,
4734,
56,
269,
520,
18129,
401,
272,
6073,
14,
4734,
3325,
520,
11746,
401,
272,
6073,
14,
44,
14379,
520,
3886,
28,
401,
272,
6073,
14,
50,
14379,
520,
298,
1140,
401,
272,
6073,
14,
1123,
520,
7210,
401,
272,
6073,
14,
2610,
520,
3905,
401,
272,
6073,
14,
30233,
520,
8969,
401,
272,
6073,
14,
24305,
520,
3286,
401,
272,
6073,
14,
38,
6367,
24305,
520,
23057,
401,
272,
6073,
14,
9871,
520,
2071,
401,
272,
6073,
14,
19706,
520,
298,
389,
401,
272,
6073,
14,
1763,
19706,
520,
298,
1111,
401,
272,
6073,
14,
31252,
520,
3886,
401,
272,
6073,
14,
31252,
37,
520,
3886,
11107,
272,
6073,
14,
39,
84,
520,
298,
7166,
272,
6073,
14,
39,
84,
37,
520,
298,
8119,
401,
272,
6073,
14,
23432,
520,
298,
538,
401,
272,
6073,
14,
1831,
520,
298,
374,
401,
272,
6073,
14,
1831,
1763,
520,
298,
374,
440,
401,
272,
6073,
14,
607,
520,
298,
262,
401,
272,
6073,
14,
1763,
607,
520,
298,
1397,
315,
2,
199,
93,
199,
199,
13124,
63,
1130,
275,
469,
272,
6073,
14,
1763,
520,
298,
1397,
450,
83,
401,
272,
6073,
14,
26498,
520,
26810,
5,
83,
401,
272,
6073,
14,
1668,
456,
520,
298,
3295,
83,
401,
272,
6073,
14,
53,
1123,
520,
7210,
5,
83,
2,
199,
93,
421,
199,
533,
14245,
2620,
26499,
8,
1810,
14,
1716,
18324,
304,
272,
408,
2620,
25133,
20788,
3380,
370,
486,
274,
455,
2997,
10201,
2556,
14,
408,
339,
347,
636,
826,
721,
277,
12,
2787,
304,
267,
291,
14,
1943,
275,
2787,
339,
347,
7809,
63,
5427,
8,
277,
12,
1031,
304,
267,
327,
481,
5421,
1380,
781,
2793,
1133,
1172,
282,
4539,
4514,
14,
267,
340,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
288,
3413,
275,
6073,
14,
9093,
8
] |
[
199,
6591,
13197,
3468,
10326,
2058,
315,
702,
9834,
4012,
6762,
20788,
14,
199,
2765,
1077,
3350,
485,
18487,
1753,
14,
647,
21356,
14,
199,
624,
199,
199,
646,
984,
199,
646,
6073,
199,
199,
646,
1134,
199,
504,
1134,
423,
600,
14,
18487,
492,
485,
908,
63,
15228,
12,
22422,
14844,
421,
199,
692,
984,
14,
3246,
14,
2460,
480,
6138,
531,
436,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
959,
12,
499,
304,
272,
327,
1666,
1455,
921,
13017,
14,
27179,
14,
1308,
15,
5237,
1079,
2576,
272,
485,
16006,
275,
1689,
10349,
4619,
401,
298,
13394,
4619,
401,
298,
22401,
4619,
401,
298,
21350,
401,
298,
3917,
4527,
401,
298,
2141,
401,
1598,
298,
1296,
2404,
401,
298,
7599,
4527,
401,
298,
22889,
401,
298,
16051,
401,
298,
2176,
401,
1598,
298,
15713,
401,
298,
5667,
401,
298,
2848,
401,
298,
1646,
401,
298,
2610,
1579,
401,
298,
985,
401,
1598,
298,
1296,
401,
298,
7075,
531,
272,
485,
270,
22862,
275,
1689,
3481,
6172,
401,
298,
2543,
6172,
401,
298,
1767,
401,
298,
5392,
401,
298,
9595,
401,
1598,
298,
21640,
9595,
401,
298,
5375,
401,
298,
1858,
401,
298,
25215,
401,
298,
3917,
401,
298,
3007,
401,
298,
18111,
401,
1598,
298,
12357,
920,
716,
401,
298,
12357,
8694,
1183,
401,
298,
9699,
401,
298,
6295,
401,
298,
6295,
2532,
401,
1598,
298,
4858,
401,
298,
7025,
401,
298,
8561,
401,
298,
4986,
401,
298,
13948,
401,
298,
24055,
531,
272,
485,
3684,
63,
2415,
275,
663,
8,
5675,
8,
1810,
12,
536,
9,
367,
536,
315,
485,
16006,
9,
272,
485,
9649,
63,
2415,
275,
663,
8,
5675,
8,
1810,
12,
536,
9,
367,
536,
315,
485,
270,
22862,
9,
272,
347,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
267,
372,
1031,
855,
533,
363,
315,
485,
3684,
63,
2415,
272,
347,
485,
374,
63,
1810,
63,
9649,
8,
932,
304,
267,
372,
1031,
855,
533,
363,
315,
485,
9649,
63,
2415,
199,
2836,
26,
272,
347,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
267,
372,
1228,
8,
932,
12,
6073,
14,
3684,
9,
272,
347,
485,
374,
63,
1810,
63,
9649,
8,
932,
304,
267,
372,
1228,
8,
932,
12,
6073,
14,
9649,
9,
421,
199,
533,
20367,
8,
1726,
304,
272,
408,
547,
1911,
1830,
6421,
1337,
20788,
1041,
339,
347,
636,
826,
721,
277,
12,
17531,
17364,
267,
291,
14,
2651,
275,
984,
14,
2804,
63,
815,
342,
267,
291,
14,
15228,
275,
17531,
421,
199,
318,
15579,
8,
1365,
12,
2787,
12,
1077,
63,
1633,
29,
797,
304,
272,
3413,
275,
6073,
14,
1122,
8,
1365,
9,
272,
18040,
275,
14245,
2620,
26499,
8,
1943,
9,
272,
862,
26,
267,
18040,
14,
5427,
8,
1494,
9,
272,
871,
20367,
26,
267,
5988,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
267,
372,
664,
5328,
8,
5328,
9,
272,
340,
1077,
63,
1633,
26,
267,
372,
1689,
8,
18487,
3405,
12,
1325,
1380,
652,
1990,
295,
13,
1065,
367,
298,
355,
298,
26514,
13197,
1338,
12,
652,
8103,
440,
2449,
14,
221,
428,
11914,
15293,
26,
298,
355,
298,
3357,
702,
3965,
2544,
314,
702,
503,
675,
1553,
889,
13,
479,
6320,
199,
199,
318,
1255,
8,
1997,
3219,
63,
604,
12,
2787,
29,
403,
304,
272,
340,
2787,
365,
488,
26,
267,
2787,
275,
1134,
14,
600,
14,
3160,
8,
1274,
423,
20912,
8,
17,
430,
272,
372,
15579,
8,
1997,
3219,
63,
604,
12,
2787,
9,
199,
199,
318,
664,
5328,
8,
5328,
304,
272,
17531,
275,
485,
908,
63,
15228,
8,
5328,
14,
15228,
9,
272,
574,
275,
5988,
14,
2651,
59,
17,
61,
272,
340,
620,
8,
585,
304,
267,
2385,
275,
17531,
14,
7644,
342,
267,
340,
440,
2385,
26,
288,
2385,
14,
740,
10804,
267,
2385,
59,
16,
61,
847,
298,
5213,
450,
83,
2,
450,
334,
585,
4258,
267,
17531,
275,
1867,
78,
1674,
904,
8,
1278,
9,
272,
1318,
275,
2071,
83,
26,
450,
83,
2,
450,
334,
5328,
14,
2651,
59,
16,
17979,
354,
3108,
17531,
9,
272,
340,
1318,
14,
2460,
480,
14844,
26,
702,
26699,
267,
1318,
275,
1318,
59,
975,
2938,
272,
372,
1318,
421,
199,
3856,
63,
1130,
275,
469,
272,
6073,
14,
4734,
2844,
520,
15733,
401,
272,
6073,
14,
4734,
56,
269,
520,
18129,
401,
272,
6073,
14,
4734,
3325,
520,
11746,
401,
272,
6073,
14,
44,
14379,
520,
3886,
28,
401,
272,
6073,
14,
50,
14379,
520,
298,
1140,
401,
272,
6073,
14,
1123,
520,
7210,
401,
272,
6073,
14,
2610,
520,
3905,
401,
272,
6073,
14,
30233,
520,
8969,
401,
272,
6073,
14,
24305,
520,
3286,
401,
272,
6073,
14,
38,
6367,
24305,
520,
23057,
401,
272,
6073,
14,
9871,
520,
2071,
401,
272,
6073,
14,
19706,
520,
298,
389,
401,
272,
6073,
14,
1763,
19706,
520,
298,
1111,
401,
272,
6073,
14,
31252,
520,
3886,
401,
272,
6073,
14,
31252,
37,
520,
3886,
11107,
272,
6073,
14,
39,
84,
520,
298,
7166,
272,
6073,
14,
39,
84,
37,
520,
298,
8119,
401,
272,
6073,
14,
23432,
520,
298,
538,
401,
272,
6073,
14,
1831,
520,
298,
374,
401,
272,
6073,
14,
1831,
1763,
520,
298,
374,
440,
401,
272,
6073,
14,
607,
520,
298,
262,
401,
272,
6073,
14,
1763,
607,
520,
298,
1397,
315,
2,
199,
93,
199,
199,
13124,
63,
1130,
275,
469,
272,
6073,
14,
1763,
520,
298,
1397,
450,
83,
401,
272,
6073,
14,
26498,
520,
26810,
5,
83,
401,
272,
6073,
14,
1668,
456,
520,
298,
3295,
83,
401,
272,
6073,
14,
53,
1123,
520,
7210,
5,
83,
2,
199,
93,
421,
199,
533,
14245,
2620,
26499,
8,
1810,
14,
1716,
18324,
304,
272,
408,
2620,
25133,
20788,
3380,
370,
486,
274,
455,
2997,
10201,
2556,
14,
408,
339,
347,
636,
826,
721,
277,
12,
2787,
304,
267,
291,
14,
1943,
275,
2787,
339,
347,
7809,
63,
5427,
8,
277,
12,
1031,
304,
267,
327,
481,
5421,
1380,
781,
2793,
1133,
1172,
282,
4539,
4514,
14,
267,
340,
485,
374,
63,
1810,
63,
3684,
8,
932,
304,
288,
3413,
275,
6073,
14,
9093,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
neiudemo1/django
|
tests/postgres_tests/fields.py
|
302
|
1087
|
"""
Indirection layer for PostgreSQL-specific fields, so the tests don't fail when
run with a backend other than PostgreSQL.
"""
from django.db import models
try:
from django.contrib.postgres.fields import (
ArrayField, BigIntegerRangeField, DateRangeField, DateTimeRangeField,
FloatRangeField, HStoreField, IntegerRangeField, JSONField,
)
except ImportError:
class DummyArrayField(models.Field):
def __init__(self, base_field, size=None, **kwargs):
super(DummyArrayField, self).__init__(**kwargs)
def deconstruct(self):
name, path, args, kwargs = super(DummyArrayField, self).deconstruct()
kwargs.update({
'base_field': '',
'size': 1,
})
return name, path, args, kwargs
ArrayField = DummyArrayField
BigIntegerRangeField = models.Field
DateRangeField = models.Field
DateTimeRangeField = models.Field
FloatRangeField = models.Field
HStoreField = models.Field
IntegerRangeField = models.Field
JSONField = models.Field
|
bsd-3-clause
|
[
624,
199,
607,
6874,
4045,
367,
20175,
13,
6100,
1504,
12,
880,
314,
2295,
2793,
1133,
2449,
1380,
199,
1065,
543,
282,
4865,
1163,
2419,
20175,
14,
199,
624,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
893,
26,
272,
687,
1639,
14,
2828,
14,
10675,
14,
955,
492,
334,
267,
8725,
792,
12,
13123,
2674,
28707,
12,
6148,
28707,
12,
13686,
28707,
12,
267,
11140,
28707,
12,
869,
5502,
792,
12,
7225,
28707,
12,
4840,
792,
12,
272,
776,
199,
2590,
3545,
26,
272,
1021,
9762,
3836,
792,
8,
992,
14,
792,
304,
267,
347,
636,
826,
721,
277,
12,
1300,
63,
698,
12,
1568,
29,
403,
12,
1011,
958,
304,
288,
1613,
8,
11324,
3836,
792,
12,
291,
2843,
826,
14155,
958,
9,
398,
347,
477,
8514,
8,
277,
304,
288,
536,
12,
931,
12,
1249,
12,
2074,
275,
1613,
8,
11324,
3836,
792,
12,
291,
680,
23693,
342,
288,
2074,
14,
873,
2561,
355,
283,
1095,
63,
698,
356,
3260,
355,
283,
890,
356,
413,
12,
288,
3828,
288,
372,
536,
12,
931,
12,
1249,
12,
2074,
339,
8725,
792,
275,
9762,
3836,
792,
272,
13123,
2674,
28707,
275,
1709,
14,
792,
272,
6148,
28707,
275,
1709,
14,
792,
272,
13686,
28707,
275,
1709,
14,
792,
272,
11140,
28707,
275,
1709,
14,
792,
272,
869,
5502,
792,
275,
1709,
14,
792,
272,
7225,
28707,
275,
1709,
14,
792,
272,
4840,
792,
275,
1709,
14,
792,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
607,
6874,
4045,
367,
20175,
13,
6100,
1504,
12,
880,
314,
2295,
2793,
1133,
2449,
1380,
199,
1065,
543,
282,
4865,
1163,
2419,
20175,
14,
199,
624,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
893,
26,
272,
687,
1639,
14,
2828,
14,
10675,
14,
955,
492,
334,
267,
8725,
792,
12,
13123,
2674,
28707,
12,
6148,
28707,
12,
13686,
28707,
12,
267,
11140,
28707,
12,
869,
5502,
792,
12,
7225,
28707,
12,
4840,
792,
12,
272,
776,
199,
2590,
3545,
26,
272,
1021,
9762,
3836,
792,
8,
992,
14,
792,
304,
267,
347,
636,
826,
721,
277,
12,
1300,
63,
698,
12,
1568,
29,
403,
12,
1011,
958,
304,
288,
1613,
8,
11324,
3836,
792,
12,
291,
2843,
826,
14155,
958,
9,
398,
347,
477,
8514,
8,
277,
304,
288,
536,
12,
931,
12,
1249,
12,
2074,
275,
1613,
8,
11324,
3836,
792,
12,
291,
680,
23693,
342,
288,
2074,
14,
873,
2561,
355,
283,
1095,
63,
698,
356,
3260,
355,
283,
890,
356,
413,
12,
288,
3828,
288,
372,
536,
12,
931,
12,
1249,
12,
2074,
339,
8725,
792,
275,
9762,
3836,
792,
272,
13123,
2674,
28707,
275,
1709,
14,
792,
272,
6148,
28707,
275,
1709,
14,
792,
272,
13686,
28707,
275,
1709,
14,
792,
272,
11140,
28707,
275,
1709,
14,
792,
272,
869,
5502,
792,
275,
1709,
14,
792,
272,
7225,
28707,
275,
1709,
14,
792,
272,
4840,
792,
275,
1709,
14,
792,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
samedder/azure-cli
|
src/command_modules/azure-cli-profile/azure/cli/command_modules/profile/_params.py
|
4
|
2571
|
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long
from azure.cli.core.commands import register_cli_argument
from .custom import load_subscriptions
def get_subscription_id_list(prefix, **kwargs): # pylint: disable=unused-argument
subscriptions = load_subscriptions()
result = []
for subscription in subscriptions:
result.append(subscription['id'])
result.append(subscription['name'])
return result
register_cli_argument('login', 'password', options_list=('--password', '-p'), help="Credentials like user password, or for a service principal, provide client secret or a pem file with key and public certificate. Will prompt if not given.")
register_cli_argument('login', 'service_principal', action='store_true', help='The credential representing a service principal.')
register_cli_argument('login', 'username', options_list=('--username', '-u'), help='Organization id or service principal')
register_cli_argument('login', 'tenant', options_list=('--tenant', '-t'), help='The AAD tenant, must provide when using service principals.')
register_cli_argument('login', 'allow_no_subscriptions', action='store_true', help="Support access tenants without subscriptions. It's uncommon but useful to run tenant level commands, such as 'az ad'")
register_cli_argument('login', 'msi', action='store_true', help="Log in using the Virtual Machine's identity", arg_group='Managed Service Identity')
register_cli_argument('login', 'msi_port', help="the port to retrieve tokens for login", arg_group='Managed Service Identity')
register_cli_argument('logout', 'username', help='account user, if missing, logout the current active account')
register_cli_argument('account', 'subscription', options_list=('--subscription', '-s'), help='Name or ID of subscription.', completer=get_subscription_id_list)
register_cli_argument('account list', 'all', help="List all subscriptions, rather just 'Enabled' ones", action='store_true')
register_cli_argument('account list', 'refresh', help="retrieve up to date subscriptions from server", action='store_true')
register_cli_argument('account show', 'show_auth_for_sdk', options_list=('--sdk-auth',), action='store_true', help='output result in compatible with Azure SDK auth file')
|
mit
|
[
3,
5620,
777,
4559,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
4190,
2556,
14,
199,
3,
5620,
777,
4559,
199,
199,
3,
4287,
26,
3507,
29,
604,
13,
7354,
13,
2809,
199,
504,
13601,
14,
2764,
14,
1018,
14,
4405,
492,
2274,
63,
2764,
63,
2094,
199,
504,
1275,
4229,
492,
2248,
63,
13233,
421,
199,
318,
664,
63,
6645,
63,
344,
63,
513,
8,
1861,
12,
1011,
958,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
25708,
275,
2248,
63,
13233,
342,
272,
754,
275,
942,
272,
367,
9966,
315,
25708,
26,
267,
754,
14,
740,
8,
6645,
459,
344,
1105,
267,
754,
14,
740,
8,
6645,
459,
354,
1105,
272,
372,
754,
421,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
2060,
297,
1511,
63,
513,
29,
4517,
2060,
297,
2475,
80,
659,
1720,
628,
13428,
2839,
922,
2505,
12,
503,
367,
282,
2435,
21646,
12,
5647,
1890,
7565,
503,
282,
4837,
77,
570,
543,
790,
436,
4575,
5897,
14,
12823,
8457,
340,
440,
1627,
2685,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
1364,
63,
19200,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
1918,
16338,
6144,
282,
2435,
21646,
2659,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
2473,
297,
1511,
63,
513,
29,
4517,
2473,
297,
2475,
85,
659,
1720,
534,
15928,
1305,
503,
2435,
21646,
358,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
4647,
297,
1511,
63,
513,
29,
4517,
4647,
297,
2475,
84,
659,
1720,
534,
1918,
437,
1554,
8261,
12,
1471,
5647,
1380,
1808,
2435,
5448,
10352,
2551,
2659,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
3306,
63,
889,
63,
13233,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
628,
11532,
2879,
16685,
2285,
1928,
25708,
14,
2779,
1159,
625,
2330,
1325,
2997,
370,
1255,
8261,
2166,
3718,
12,
4066,
465,
283,
4651,
1503,
9859,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
77,
338,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
628,
2445,
315,
1808,
314,
13311,
18722,
1159,
8503,
401,
1680,
63,
923,
534,
22625,
7591,
22034,
358,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
77,
338,
63,
719,
297,
1720,
628,
1589,
1844,
370,
8044,
4645,
367,
4676,
401,
1680,
63,
923,
534,
22625,
7591,
22034,
358,
199,
199,
2683,
63,
2764,
63,
2094,
360,
11646,
297,
283,
2473,
297,
1720,
534,
2048,
922,
12,
340,
4124,
12,
22079,
314,
1453,
4702,
2933,
358,
199,
199,
2683,
63,
2764,
63,
2094,
360,
2048,
297,
283,
6645,
297,
1511,
63,
513,
29,
4517,
6645,
297,
2475,
83,
659,
1720,
534,
985,
503,
2870,
402,
9966,
3130,
2831,
351,
29,
362,
63,
6645,
63,
344,
63,
513,
9,
199,
2683,
63,
2764,
63,
2094,
360,
2048,
769,
297,
283,
452,
297,
1720,
628,
1296,
1006,
25708,
12,
7830,
2951,
283,
6589,
7,
7869,
401,
1595,
534,
1617,
63,
2052,
358,
199,
2683,
63,
2764,
63,
2094,
360,
2048,
769,
297,
283,
6635,
297,
1720,
628,
14270,
1536,
370,
1434,
25708,
687,
1654,
401,
1595,
534,
1617,
63,
2052,
358,
199,
2683,
63,
2764,
63,
2094,
360,
2048,
2498,
297,
283,
2384,
63,
1178,
63,
509,
63,
9277,
297,
1511,
63,
513,
29,
4517,
9277,
13,
1178,
5529,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
1199,
754,
315,
9025,
543,
15474,
15610,
1790,
570,
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
] |
[
5620,
777,
4559,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
4190,
2556,
14,
199,
3,
5620,
777,
4559,
199,
199,
3,
4287,
26,
3507,
29,
604,
13,
7354,
13,
2809,
199,
504,
13601,
14,
2764,
14,
1018,
14,
4405,
492,
2274,
63,
2764,
63,
2094,
199,
504,
1275,
4229,
492,
2248,
63,
13233,
421,
199,
318,
664,
63,
6645,
63,
344,
63,
513,
8,
1861,
12,
1011,
958,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
25708,
275,
2248,
63,
13233,
342,
272,
754,
275,
942,
272,
367,
9966,
315,
25708,
26,
267,
754,
14,
740,
8,
6645,
459,
344,
1105,
267,
754,
14,
740,
8,
6645,
459,
354,
1105,
272,
372,
754,
421,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
2060,
297,
1511,
63,
513,
29,
4517,
2060,
297,
2475,
80,
659,
1720,
628,
13428,
2839,
922,
2505,
12,
503,
367,
282,
2435,
21646,
12,
5647,
1890,
7565,
503,
282,
4837,
77,
570,
543,
790,
436,
4575,
5897,
14,
12823,
8457,
340,
440,
1627,
2685,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
1364,
63,
19200,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
1918,
16338,
6144,
282,
2435,
21646,
2659,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
2473,
297,
1511,
63,
513,
29,
4517,
2473,
297,
2475,
85,
659,
1720,
534,
15928,
1305,
503,
2435,
21646,
358,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
4647,
297,
1511,
63,
513,
29,
4517,
4647,
297,
2475,
84,
659,
1720,
534,
1918,
437,
1554,
8261,
12,
1471,
5647,
1380,
1808,
2435,
5448,
10352,
2551,
2659,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
3306,
63,
889,
63,
13233,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
628,
11532,
2879,
16685,
2285,
1928,
25708,
14,
2779,
1159,
625,
2330,
1325,
2997,
370,
1255,
8261,
2166,
3718,
12,
4066,
465,
283,
4651,
1503,
9859,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
77,
338,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
628,
2445,
315,
1808,
314,
13311,
18722,
1159,
8503,
401,
1680,
63,
923,
534,
22625,
7591,
22034,
358,
199,
2683,
63,
2764,
63,
2094,
360,
2886,
297,
283,
77,
338,
63,
719,
297,
1720,
628,
1589,
1844,
370,
8044,
4645,
367,
4676,
401,
1680,
63,
923,
534,
22625,
7591,
22034,
358,
199,
199,
2683,
63,
2764,
63,
2094,
360,
11646,
297,
283,
2473,
297,
1720,
534,
2048,
922,
12,
340,
4124,
12,
22079,
314,
1453,
4702,
2933,
358,
199,
199,
2683,
63,
2764,
63,
2094,
360,
2048,
297,
283,
6645,
297,
1511,
63,
513,
29,
4517,
6645,
297,
2475,
83,
659,
1720,
534,
985,
503,
2870,
402,
9966,
3130,
2831,
351,
29,
362,
63,
6645,
63,
344,
63,
513,
9,
199,
2683,
63,
2764,
63,
2094,
360,
2048,
769,
297,
283,
452,
297,
1720,
628,
1296,
1006,
25708,
12,
7830,
2951,
283,
6589,
7,
7869,
401,
1595,
534,
1617,
63,
2052,
358,
199,
2683,
63,
2764,
63,
2094,
360,
2048,
769,
297,
283,
6635,
297,
1720,
628,
14270,
1536,
370,
1434,
25708,
687,
1654,
401,
1595,
534,
1617,
63,
2052,
358,
199,
2683,
63,
2764,
63,
2094,
360,
2048,
2498,
297,
283,
2384,
63,
1178,
63,
509,
63,
9277,
297,
1511,
63,
513,
29,
4517,
9277,
13,
1178,
5529,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
1199,
754,
315,
9025,
543,
15474,
15610,
1790,
570,
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,
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
] |
quru/qis
|
src/imageserver/user_auth.py
|
1
|
7528
|
#
# Quru Image Server
#
# Document: user_auth.py
# Date started: 10 Aug 2011
# By: Matt Fozard
# Purpose: Image server user authentication module
# Requires:
# Copyright: Quru Ltd (www.quru.com)
# Licence:
#
# 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/
#
# Last Changed: $Date$ $Rev$ by $Author$
#
# Notable modifications:
# Date By Details
# ========= ==== ============================================================
#
from . import ldap_client
from .errors import AuthenticationError
from .flask_app import app
from .models import User
from .util import ensure_string, generate_password
def authenticate_user(username, password, data_engine, logger):
"""
Authenticates the given user credentials, returning the associated User
object on success, or None if either the username or password is incorrect.
If LDAP integration is enabled, a new image server user account will be
created if there is no existing account but the username and password are
valid on the LDAP server.
An AuthenticationError is raised if an error occurrs performing the
authentication process.
"""
try:
logger.debug('Authenticating user \'' + username + '\'')
user = data_engine.get_user(username=username)
if user is not None:
if user.auth_type == User.AUTH_TYPE_PASSWORD:
# Standard authentication
auth = user.check_password(password)
auth_type = 'Standard'
elif user.auth_type == User.AUTH_TYPE_LDAP:
# LDAP authentication
auth, _ = _authenticate_ldap(username, password, logger)
auth_type = 'LDAP'
else:
raise AuthenticationError('Unsupported authentication type')
logger.debug(
auth_type + ' authentication ' + ('OK' if auth else 'failed') +
' for \'' + username + '\''
)
# Return result for known username
return user if auth else None
else:
# The username is not known locally
if app.config['LDAP_INTEGRATION']:
logger.debug('Checking LDAP server for unknown user \'' + username + '\'')
auth, user_attrs = _authenticate_ldap(username, password, logger)
if auth:
# Valid LDAP user, auto-create a new user account
logger.debug(
'Identified user \'' + username + '\' on LDAP server, ' +
'authentication OK, creating new user account'
)
logger.debug('User details: ' + str(user_attrs))
(firstname, lastname) = _get_firstname_lastname(user_attrs)
new_user = User(
firstname,
lastname,
'',
username,
generate_password(), # This won't get used...
User.AUTH_TYPE_LDAP, # as long as this flag still says LDAP
False,
User.STATUS_ACTIVE
)
data_engine.create_user(new_user)
return new_user
else:
logger.debug('LDAP authentication failed for \'' + username + '\'')
return None
# Unknown username
logger.debug('Unknown user \'' + username + '\'')
return None
except AuthenticationError as e:
raise
except Exception as e:
raise AuthenticationError(str(e))
def _get_firstname_lastname(ldap_user_attrs):
"""
Returns a string tuple of (forename, surname) from the supplied dictionary
of user attributes. This is taken from the cn attribute is possible,
otherwise from the givenName and sn attributes.
"""
cn = ensure_string(ldap_user_attrs.get('cn', ['Unknown'])[0])
gn = ensure_string(ldap_user_attrs.get('givenName', ['Unknown'])[0])
sn = ensure_string(ldap_user_attrs.get('sn', ['Unknown'])[0])
parts = cn.split(' ')
if len(parts) == 2:
gn = parts[0]
sn = parts[1]
return (gn.capitalize(), sn.capitalize())
def _authenticate_ldap(username, password, logger):
"""
Authenticates the given username and password against the configured LDAP
server. Returns a tuple indicating success and the user's LDAP attributes,
so either (True, { user attrs }) or (False, None).
The returned LDAP attributes are server-specific and have format
{ 'attr_name': ['attr_value_1', ...] }
An AuthenticationError is raised if an LDAP server is not configured or
if it could not be contacted.
"""
if not app.config['LDAP_INTEGRATION']:
raise AuthenticationError('LDAP integration is disabled')
if not app.config['LDAP_SERVER'] or not app.config['LDAP_SERVER_TYPE']:
raise AuthenticationError('LDAP authentication has not been configured')
if not ldap_client.ldap_installed:
raise AuthenticationError('LDAP support is not installed')
if app.config['LDAP_SECURE'] and not ldap_client.ldap_tls_installed:
raise AuthenticationError('TLS support for LDAP is not installed (e.g. OpenSSL)')
try:
# Get LDAP config
ldap_type = app.config['LDAP_SERVER_TYPE'].lower()
ldap_config = ldap_client.LDAP_Settings(
app.config['LDAP_SERVER'],
app.config['LDAP_SECURE'],
app.config['LDAP_QUERY_BASE'],
app.config['LDAP_BIND_USER_DN'],
app.config['LDAP_BIND_PASSWORD']
)
# Create correct client type
if ldap_type == 'openldapposix':
ldap_engine = ldap_client.OpenLDAP_Client(ldap_config, True)
elif ldap_type == 'openldaporganizational':
ldap_engine = ldap_client.OpenLDAP_Client(ldap_config, False)
elif ldap_type == 'apple':
ldap_engine = ldap_client.AppleLDAP_Client(ldap_config)
elif ldap_type == 'activedirectory':
ldap_engine = ldap_client.Windows2008R2_Client(ldap_config)
else:
raise AuthenticationError('Unsupported LDAP type: ' + app.config['LDAP_SERVER_TYPE'])
# Try authentication
auth = ldap_engine.authenticate_user(username, password)
if auth:
# Success, return user info too
user_attrs = ldap_engine.get_user_attributes(username)
return (True, user_attrs)
# Rejected
return (False, None)
except ldap_client.LDAP_Error as e:
logger.error(
'LDAP error authenticating user \'' + username + '\': ' +
e.type_name + ': ' +
e.desc + ((' (' + e.info + ')') if e.info else '')
)
raise AuthenticationError(e.desc)
|
agpl-3.0
|
[
3,
199,
3,
1413,
300,
85,
6047,
7146,
199,
3,
199,
3,
7543,
26,
420,
922,
63,
1178,
14,
647,
199,
3,
6148,
8239,
26,
221,
1616,
25298,
7760,
199,
3,
4885,
26,
3322,
31653,
481,
26051,
1005,
199,
3,
23177,
4070,
26,
755,
6047,
1654,
922,
6299,
859,
199,
3,
15127,
26,
199,
3,
1898,
26,
258,
1413,
300,
85,
12126,
334,
1544,
14,
81,
300,
85,
14,
957,
9,
199,
3,
491,
530,
4894,
26,
199,
3,
199,
3,
257,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
199,
3,
257,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
257,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
199,
3,
199,
3,
15237,
25649,
26,
221,
2672,
2506,
4,
2672,
26176,
4,
701,
2672,
5949,
4,
199,
3,
199,
3,
2832,
461,
23070,
26,
199,
3,
6148,
755,
4885,
259,
15621,
199,
3,
275,
763,
221,
275,
5918,
221,
19691,
21326,
199,
3,
199,
199,
504,
1275,
492,
13727,
63,
1258,
199,
199,
504,
1275,
2550,
492,
15995,
547,
199,
504,
1275,
15720,
63,
571,
492,
1145,
199,
504,
1275,
992,
492,
2876,
199,
504,
1275,
1974,
492,
4868,
63,
875,
12,
3550,
63,
2060,
421,
199,
318,
12895,
63,
751,
8,
2473,
12,
2505,
12,
666,
63,
3908,
12,
2512,
304,
272,
408,
272,
3590,
2815,
2335,
314,
1627,
922,
6235,
12,
8152,
314,
4568,
2876,
272,
909,
641,
3182,
12,
503,
488,
340,
1902,
314,
3434,
503,
2505,
365,
8927,
14,
339,
982,
20717,
13150,
365,
5223,
12,
282,
892,
1834,
1654,
922,
2933,
911,
506,
272,
2737,
340,
2337,
365,
949,
3411,
2933,
1325,
314,
3434,
436,
2505,
787,
272,
1686,
641,
314,
20717,
1654,
14,
339,
1626,
15995,
547,
365,
4915,
340,
376,
1125,
4781,
2393,
19203,
314,
272,
6299,
2112,
14,
272,
408,
272,
862,
26,
267,
2512,
14,
1757,
360,
2817,
2815,
1958,
922,
971,
891,
435,
3434,
435,
1557,
17483,
267,
922,
275,
666,
63,
3908,
14,
362,
63,
751,
8,
2473,
29,
2473,
9,
398,
340,
922,
365,
440,
488,
26,
288,
340,
922,
14,
1178,
63,
466,
508,
2876,
14,
5580,
63,
2711,
63,
9032,
26,
355,
327,
9739,
6299,
355,
1790,
275,
922,
14,
1074,
63,
2060,
8,
2060,
9,
355,
1790,
63,
466,
275,
283,
9232,
7,
288,
916,
922,
14,
1178,
63,
466,
508,
2876,
14,
5580,
63,
2711,
63,
19534,
26,
355,
327,
20717,
6299,
355,
1790,
12,
485,
275,
485,
13975,
63,
9642,
8,
2473,
12,
2505,
12,
2512,
9,
355,
1790,
63,
466,
275,
283,
19534,
7,
288,
587,
26,
355,
746,
15995,
547,
360,
12647,
6299,
730,
358,
953,
2512,
14,
1757,
8,
355,
1790,
63,
466,
435,
283,
6299,
283,
435,
661,
3593,
7,
340,
1790,
587,
283,
4892,
358,
435,
355,
283,
367,
971,
891,
435,
3434,
435,
1557,
891,
288,
776,
288,
327,
1432,
754,
367,
6040,
3434,
288,
372,
922,
340,
1790,
587,
488,
267,
587,
26,
288,
327,
710,
3434,
365,
440,
6040,
17738,
288,
340,
1145,
14,
888,
459,
19534,
63,
2919,
37,
3975,
2594,
2565,
355,
2512,
14,
1757,
360,
14740,
20717,
1654,
367,
5809,
922,
971,
891,
435,
3434,
435,
1557,
17483,
355,
1790,
12,
922,
63,
3288,
275,
485,
13975,
63,
9642,
8,
2473,
12,
2505,
12,
2512,
9,
355,
340,
1790,
26,
490,
327,
4821,
20717,
922,
12,
2599,
13,
981,
282,
892,
922,
2933,
490,
2512,
14,
1757,
8,
717,
283,
17062,
8981,
922,
971,
891,
435,
3434,
435,
32496,
641,
20717,
1654,
12,
283,
435,
717,
283,
11725,
9949,
12,
6425,
892,
922,
2933,
7,
490,
776,
490,
2512,
14,
1757,
360,
1899,
2436,
26,
283,
435,
620,
8,
751,
63,
3288,
430,
490,
334,
25603,
12,
2061,
354,
9,
275,
485,
362,
63,
25603,
63,
31164,
8,
751,
63,
3288,
9,
490,
892,
63,
751,
275,
2876,
8,
717,
1642,
354,
12,
717,
2061,
354,
12,
717,
3260,
717,
3434,
12,
717,
3550,
63,
2060,
1062,
221,
327,
961,
7859,
1133,
664,
1202,
1396,
717,
2876,
14,
5580,
63,
2711,
63,
19534,
12,
221,
327,
465,
1846,
465,
642,
3305,
5139,
20065,
20717,
717,
756,
12,
717,
2876,
14,
6305,
63,
10401,
490,
776,
490,
666,
63,
3908,
14,
981,
63,
751,
8,
1222,
63,
751,
9,
490,
372,
892,
63,
751,
355,
587,
26,
490,
2512,
14,
1757,
360,
19534,
6299,
3405,
367,
971,
891,
435,
3434,
435,
1557,
17483,
490,
372,
488,
953,
327,
14831,
3434,
288,
2512,
14,
1757,
360,
5912,
922,
971,
891,
435,
3434,
435,
1557,
17483,
288,
372,
488,
339,
871,
15995,
547,
465,
325,
26,
267,
746,
272,
871,
2186,
465,
325,
26,
267,
746,
15995,
547,
8,
495,
8,
69,
430,
421,
199,
318,
485,
362,
63,
25603,
63,
31164,
8,
9642,
63,
751,
63,
3288,
304,
272,
408,
272,
1803,
282,
1059,
2008,
402,
334,
1707,
354,
12,
308,
21121,
9,
687,
314,
6841,
2600,
272,
402,
922,
3004,
14,
961,
365,
9394,
687,
314,
20087,
2225,
365,
3962,
12,
272,
4257,
687,
314,
1627,
985,
436,
6895,
3004,
14,
272,
408,
272,
20087,
275,
4868,
63,
875,
8,
9642,
63,
751,
63,
3288,
14,
362,
360,
6413,
297,
788,
5912,
25945,
16,
566,
272,
19964,
275,
4868,
63,
875,
8,
9642,
63,
751,
63,
3288,
14,
362,
360,
11809,
985,
297,
788,
5912,
25945,
16,
566,
272,
6895,
275,
4868,
63,
875,
8
] |
[
199,
3,
1413,
300,
85,
6047,
7146,
199,
3,
199,
3,
7543,
26,
420,
922,
63,
1178,
14,
647,
199,
3,
6148,
8239,
26,
221,
1616,
25298,
7760,
199,
3,
4885,
26,
3322,
31653,
481,
26051,
1005,
199,
3,
23177,
4070,
26,
755,
6047,
1654,
922,
6299,
859,
199,
3,
15127,
26,
199,
3,
1898,
26,
258,
1413,
300,
85,
12126,
334,
1544,
14,
81,
300,
85,
14,
957,
9,
199,
3,
491,
530,
4894,
26,
199,
3,
199,
3,
257,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
199,
3,
257,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
257,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
199,
3,
199,
3,
15237,
25649,
26,
221,
2672,
2506,
4,
2672,
26176,
4,
701,
2672,
5949,
4,
199,
3,
199,
3,
2832,
461,
23070,
26,
199,
3,
6148,
755,
4885,
259,
15621,
199,
3,
275,
763,
221,
275,
5918,
221,
19691,
21326,
199,
3,
199,
199,
504,
1275,
492,
13727,
63,
1258,
199,
199,
504,
1275,
2550,
492,
15995,
547,
199,
504,
1275,
15720,
63,
571,
492,
1145,
199,
504,
1275,
992,
492,
2876,
199,
504,
1275,
1974,
492,
4868,
63,
875,
12,
3550,
63,
2060,
421,
199,
318,
12895,
63,
751,
8,
2473,
12,
2505,
12,
666,
63,
3908,
12,
2512,
304,
272,
408,
272,
3590,
2815,
2335,
314,
1627,
922,
6235,
12,
8152,
314,
4568,
2876,
272,
909,
641,
3182,
12,
503,
488,
340,
1902,
314,
3434,
503,
2505,
365,
8927,
14,
339,
982,
20717,
13150,
365,
5223,
12,
282,
892,
1834,
1654,
922,
2933,
911,
506,
272,
2737,
340,
2337,
365,
949,
3411,
2933,
1325,
314,
3434,
436,
2505,
787,
272,
1686,
641,
314,
20717,
1654,
14,
339,
1626,
15995,
547,
365,
4915,
340,
376,
1125,
4781,
2393,
19203,
314,
272,
6299,
2112,
14,
272,
408,
272,
862,
26,
267,
2512,
14,
1757,
360,
2817,
2815,
1958,
922,
971,
891,
435,
3434,
435,
1557,
17483,
267,
922,
275,
666,
63,
3908,
14,
362,
63,
751,
8,
2473,
29,
2473,
9,
398,
340,
922,
365,
440,
488,
26,
288,
340,
922,
14,
1178,
63,
466,
508,
2876,
14,
5580,
63,
2711,
63,
9032,
26,
355,
327,
9739,
6299,
355,
1790,
275,
922,
14,
1074,
63,
2060,
8,
2060,
9,
355,
1790,
63,
466,
275,
283,
9232,
7,
288,
916,
922,
14,
1178,
63,
466,
508,
2876,
14,
5580,
63,
2711,
63,
19534,
26,
355,
327,
20717,
6299,
355,
1790,
12,
485,
275,
485,
13975,
63,
9642,
8,
2473,
12,
2505,
12,
2512,
9,
355,
1790,
63,
466,
275,
283,
19534,
7,
288,
587,
26,
355,
746,
15995,
547,
360,
12647,
6299,
730,
358,
953,
2512,
14,
1757,
8,
355,
1790,
63,
466,
435,
283,
6299,
283,
435,
661,
3593,
7,
340,
1790,
587,
283,
4892,
358,
435,
355,
283,
367,
971,
891,
435,
3434,
435,
1557,
891,
288,
776,
288,
327,
1432,
754,
367,
6040,
3434,
288,
372,
922,
340,
1790,
587,
488,
267,
587,
26,
288,
327,
710,
3434,
365,
440,
6040,
17738,
288,
340,
1145,
14,
888,
459,
19534,
63,
2919,
37,
3975,
2594,
2565,
355,
2512,
14,
1757,
360,
14740,
20717,
1654,
367,
5809,
922,
971,
891,
435,
3434,
435,
1557,
17483,
355,
1790,
12,
922,
63,
3288,
275,
485,
13975,
63,
9642,
8,
2473,
12,
2505,
12,
2512,
9,
355,
340,
1790,
26,
490,
327,
4821,
20717,
922,
12,
2599,
13,
981,
282,
892,
922,
2933,
490,
2512,
14,
1757,
8,
717,
283,
17062,
8981,
922,
971,
891,
435,
3434,
435,
32496,
641,
20717,
1654,
12,
283,
435,
717,
283,
11725,
9949,
12,
6425,
892,
922,
2933,
7,
490,
776,
490,
2512,
14,
1757,
360,
1899,
2436,
26,
283,
435,
620,
8,
751,
63,
3288,
430,
490,
334,
25603,
12,
2061,
354,
9,
275,
485,
362,
63,
25603,
63,
31164,
8,
751,
63,
3288,
9,
490,
892,
63,
751,
275,
2876,
8,
717,
1642,
354,
12,
717,
2061,
354,
12,
717,
3260,
717,
3434,
12,
717,
3550,
63,
2060,
1062,
221,
327,
961,
7859,
1133,
664,
1202,
1396,
717,
2876,
14,
5580,
63,
2711,
63,
19534,
12,
221,
327,
465,
1846,
465,
642,
3305,
5139,
20065,
20717,
717,
756,
12,
717,
2876,
14,
6305,
63,
10401,
490,
776,
490,
666,
63,
3908,
14,
981,
63,
751,
8,
1222,
63,
751,
9,
490,
372,
892,
63,
751,
355,
587,
26,
490,
2512,
14,
1757,
360,
19534,
6299,
3405,
367,
971,
891,
435,
3434,
435,
1557,
17483,
490,
372,
488,
953,
327,
14831,
3434,
288,
2512,
14,
1757,
360,
5912,
922,
971,
891,
435,
3434,
435,
1557,
17483,
288,
372,
488,
339,
871,
15995,
547,
465,
325,
26,
267,
746,
272,
871,
2186,
465,
325,
26,
267,
746,
15995,
547,
8,
495,
8,
69,
430,
421,
199,
318,
485,
362,
63,
25603,
63,
31164,
8,
9642,
63,
751,
63,
3288,
304,
272,
408,
272,
1803,
282,
1059,
2008,
402,
334,
1707,
354,
12,
308,
21121,
9,
687,
314,
6841,
2600,
272,
402,
922,
3004,
14,
961,
365,
9394,
687,
314,
20087,
2225,
365,
3962,
12,
272,
4257,
687,
314,
1627,
985,
436,
6895,
3004,
14,
272,
408,
272,
20087,
275,
4868,
63,
875,
8,
9642,
63,
751,
63,
3288,
14,
362,
360,
6413,
297,
788,
5912,
25945,
16,
566,
272,
19964,
275,
4868,
63,
875,
8,
9642,
63,
751,
63,
3288,
14,
362,
360,
11809,
985,
297,
788,
5912,
25945,
16,
566,
272,
6895,
275,
4868,
63,
875,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
helixyte/TheLMA
|
thelma/tests/functional/test_rack.py
|
1
|
1605
|
"""
Created on Dec 09, 2014.
"""
from pyramid.httpexceptions import HTTPOk
from everest.mime import XmlMime
from everest.resources.utils import get_root_collection
from thelma.interfaces import ITubeRack
from thelma.tests.functional.conftest import TestFunctionalBase
class TestRackFunctional(TestFunctionalBase):
path = '/tube-racks'
setup_rdb_context = True
def test_load_racks(self, app_creator):
rsp = app_creator.get(self.path,
params=dict(size=10),
status=HTTPOk.code)
assert not rsp is None
def test_patch_set_location(self, app_creator,
rack_patch_set_location_data):
rack_bc = '02490469'
loc_id = 1513
rsp = app_creator.patch('%s/%s' % (self.path, rack_bc),
params=rack_patch_set_location_data,
content_type=XmlMime.mime_type_string,
status=HTTPOk.code)
assert not rsp is None
coll = get_root_collection(ITubeRack)
rack = coll[rack_bc]
lr = rack.get_entity().location_rack
assert not lr is None
assert lr.location.id == loc_id
def test_patch_unset_location(self, app_creator):
rack_bc = '02481966'
rsp = app_creator.delete('%s/%s/location' % (self.path, rack_bc),
status=HTTPOk.code)
assert not rsp is None
coll = get_root_collection(ITubeRack)
rack = coll[rack_bc]
assert rack.get_entity().location_rack is None
|
mit
|
[
624,
199,
10502,
641,
13966,
21798,
12,
6927,
14,
199,
624,
199,
504,
30704,
14,
16916,
321,
16010,
83,
492,
869,
1481,
1512,
75,
199,
199,
504,
325,
432,
3911,
14,
7626,
492,
24881,
45,
1036,
199,
504,
325,
432,
3911,
14,
4435,
14,
1208,
492,
664,
63,
1231,
63,
3627,
199,
504,
314,
76,
391,
14,
7436,
492,
473,
16397,
50,
564,
199,
504,
314,
76,
391,
14,
2219,
14,
15481,
14,
22454,
492,
1379,
3481,
279,
1563,
421,
199,
533,
1379,
50,
564,
3481,
279,
8,
774,
3481,
279,
1563,
304,
272,
931,
275,
1994,
84,
3375,
13,
345,
5618,
7,
272,
3272,
63,
82,
697,
63,
1100,
275,
715,
339,
347,
511,
63,
912,
63,
345,
5618,
8,
277,
12,
1145,
63,
9986,
304,
267,
13684,
275,
1145,
63,
9986,
14,
362,
8,
277,
14,
515,
12,
2892,
1862,
29,
807,
8,
890,
29,
709,
395,
2892,
2004,
29,
40,
1481,
1512,
75,
14,
600,
9,
267,
702,
440,
13684,
365,
488,
339,
347,
511,
63,
2068,
63,
409,
63,
1985,
8,
277,
12,
1145,
63,
9986,
12,
1816,
660,
346,
63,
2068,
63,
409,
63,
1985,
63,
576,
304,
267,
660,
346,
63,
3776,
275,
283,
996,
1887,
966,
1876,
7,
267,
4355,
63,
344,
275,
4114,
969,
267,
13684,
275,
1145,
63,
9986,
14,
2068,
3508,
83,
3149,
83,
7,
450,
334,
277,
14,
515,
12,
660,
346,
63,
3776,
395,
1816,
1862,
29,
8085,
63,
2068,
63,
409,
63,
1985,
63,
576,
12,
1816,
1564,
63,
466,
29,
8672,
45,
1036,
14,
7626,
63,
466,
63,
875,
12,
1816,
2004,
29,
40,
1481,
1512,
75,
14,
600,
9,
267,
702,
440,
13684,
365,
488,
267,
23721,
275,
664,
63,
1231,
63,
3627,
8,
649,
3375,
50,
564,
9,
267,
660,
346,
275,
23721,
59,
8085,
63,
3776,
61,
267,
13645,
275,
660,
346,
14,
362,
63,
4502,
1252,
1985,
63,
8085,
267,
702,
440,
13645,
365,
488,
267,
702,
13645,
14,
1985,
14,
344,
508,
4355,
63,
344,
339,
347,
511,
63,
2068,
63,
16787,
63,
1985,
8,
277,
12,
1145,
63,
9986,
304,
267,
660,
346,
63,
3776,
275,
283,
996,
2006,
1167,
1272,
7,
267,
13684,
275,
1145,
63,
9986,
14,
1807,
3508,
83,
3149,
83,
15,
1985,
7,
450,
334,
277,
14,
515,
12,
660,
346,
63,
3776,
395,
639,
2004,
29,
40,
1481,
1512,
75,
14,
600,
9,
267,
702,
440,
13684,
365,
488,
267,
23721,
275,
664,
63,
1231,
63,
3627,
8,
649,
3375,
50,
564,
9,
267,
660,
346,
275,
23721,
59,
8085,
63,
3776,
61,
267,
702,
660,
346,
14,
362,
63,
4502,
1252,
1985,
63,
8085,
365,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
10502,
641,
13966,
21798,
12,
6927,
14,
199,
624,
199,
504,
30704,
14,
16916,
321,
16010,
83,
492,
869,
1481,
1512,
75,
199,
199,
504,
325,
432,
3911,
14,
7626,
492,
24881,
45,
1036,
199,
504,
325,
432,
3911,
14,
4435,
14,
1208,
492,
664,
63,
1231,
63,
3627,
199,
504,
314,
76,
391,
14,
7436,
492,
473,
16397,
50,
564,
199,
504,
314,
76,
391,
14,
2219,
14,
15481,
14,
22454,
492,
1379,
3481,
279,
1563,
421,
199,
533,
1379,
50,
564,
3481,
279,
8,
774,
3481,
279,
1563,
304,
272,
931,
275,
1994,
84,
3375,
13,
345,
5618,
7,
272,
3272,
63,
82,
697,
63,
1100,
275,
715,
339,
347,
511,
63,
912,
63,
345,
5618,
8,
277,
12,
1145,
63,
9986,
304,
267,
13684,
275,
1145,
63,
9986,
14,
362,
8,
277,
14,
515,
12,
2892,
1862,
29,
807,
8,
890,
29,
709,
395,
2892,
2004,
29,
40,
1481,
1512,
75,
14,
600,
9,
267,
702,
440,
13684,
365,
488,
339,
347,
511,
63,
2068,
63,
409,
63,
1985,
8,
277,
12,
1145,
63,
9986,
12,
1816,
660,
346,
63,
2068,
63,
409,
63,
1985,
63,
576,
304,
267,
660,
346,
63,
3776,
275,
283,
996,
1887,
966,
1876,
7,
267,
4355,
63,
344,
275,
4114,
969,
267,
13684,
275,
1145,
63,
9986,
14,
2068,
3508,
83,
3149,
83,
7,
450,
334,
277,
14,
515,
12,
660,
346,
63,
3776,
395,
1816,
1862,
29,
8085,
63,
2068,
63,
409,
63,
1985,
63,
576,
12,
1816,
1564,
63,
466,
29,
8672,
45,
1036,
14,
7626,
63,
466,
63,
875,
12,
1816,
2004,
29,
40,
1481,
1512,
75,
14,
600,
9,
267,
702,
440,
13684,
365,
488,
267,
23721,
275,
664,
63,
1231,
63,
3627,
8,
649,
3375,
50,
564,
9,
267,
660,
346,
275,
23721,
59,
8085,
63,
3776,
61,
267,
13645,
275,
660,
346,
14,
362,
63,
4502,
1252,
1985,
63,
8085,
267,
702,
440,
13645,
365,
488,
267,
702,
13645,
14,
1985,
14,
344,
508,
4355,
63,
344,
339,
347,
511,
63,
2068,
63,
16787,
63,
1985,
8,
277,
12,
1145,
63,
9986,
304,
267,
660,
346,
63,
3776,
275,
283,
996,
2006,
1167,
1272,
7,
267,
13684,
275,
1145,
63,
9986,
14,
1807,
3508,
83,
3149,
83,
15,
1985,
7,
450,
334,
277,
14,
515,
12,
660,
346,
63,
3776,
395,
639,
2004,
29,
40,
1481,
1512,
75,
14,
600,
9,
267,
702,
440,
13684,
365,
488,
267,
23721,
275,
664,
63,
1231,
63,
3627,
8,
649,
3375,
50,
564,
9,
267,
660,
346,
275,
23721,
59,
8085,
63,
3776,
61,
267,
702,
660,
346,
14,
362,
63,
4502,
1252,
1985,
63,
8085,
365,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
shaufi/odoo
|
addons/base_gengo/wizard/base_gengo_translations.py
|
296
|
13127
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (C) 2004-2012 OpenERP S.A. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import uuid
import logging
import re
import time
from openerp.osv import osv, fields
from openerp import tools, SUPERUSER_ID
from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
try:
from gengo import Gengo
except ImportError:
_logger.warning('Gengo library not found, Gengo features disabled. If you plan to use it, please install the gengo library from http://pypi.python.org/pypi/gengo')
GENGO_DEFAULT_LIMIT = 20
class base_gengo_translations(osv.osv_memory):
GENGO_KEY = "Gengo.UUID"
GROUPS = ['base.group_system']
_name = 'base.gengo.translations'
_columns = {
'sync_type': fields.selection([('send', 'Send New Terms'),
('receive', 'Receive Translation'),
('both', 'Both')], "Sync Type"),
'lang_id': fields.many2one('res.lang', 'Language', required=True),
'sync_limit': fields.integer("No. of terms to sync"),
}
_defaults = {
'sync_type': 'both',
'sync_limit': 20
}
def init(self, cr):
icp = self.pool['ir.config_parameter']
if not icp.get_param(cr, SUPERUSER_ID, self.GENGO_KEY, default=None):
icp.set_param(cr, SUPERUSER_ID, self.GENGO_KEY, str(uuid.uuid4()), groups=self.GROUPS)
def get_gengo_key(self, cr):
icp = self.pool['ir.config_parameter']
return icp.get_param(cr, SUPERUSER_ID, self.GENGO_KEY, default="Undefined")
def gengo_authentication(self, cr, uid, context=None):
'''
This method tries to open a connection with Gengo. For that, it uses the Public and Private
keys that are linked to the company (given by Gengo on subscription). It returns a tuple with
* as first element: a boolean depicting if the authentication was a success or not
* as second element: the connection, if it was a success, or the error message returned by
Gengo when the connection failed.
This error message can either be displayed in the server logs (if the authentication was called
by the cron) or in a dialog box (if requested by the user), thus it's important to return it
translated.
'''
user = self.pool.get('res.users').browse(cr, 1, uid, context=context)
if not user.company_id.gengo_public_key or not user.company_id.gengo_private_key:
return (False, _("Gengo `Public Key` or `Private Key` are missing. Enter your Gengo authentication parameters under `Settings > Companies > Gengo Parameters`."))
try:
gengo = Gengo(
public_key=user.company_id.gengo_public_key.encode('ascii'),
private_key=user.company_id.gengo_private_key.encode('ascii'),
sandbox=user.company_id.gengo_sandbox,
)
gengo.getAccountStats()
return (True, gengo)
except Exception, e:
_logger.exception('Gengo connection failed')
return (False, _("Gengo connection failed with this message:\n``%s``") % e)
def act_update(self, cr, uid, ids, context=None):
'''
Function called by the wizard.
'''
if context is None:
context = {}
flag, gengo = self.gengo_authentication(cr, uid, context=context)
if not flag:
raise osv.except_osv(_('Gengo Authentication Error'), gengo)
for wizard in self.browse(cr, uid, ids, context=context):
supported_langs = self.pool.get('ir.translation')._get_all_supported_languages(cr, uid, context=context)
language = self.pool.get('ir.translation')._get_gengo_corresponding_language(wizard.lang_id.code)
if language not in supported_langs:
raise osv.except_osv(_("Warning"), _('This language is not supported by the Gengo translation services.'))
ctx = context.copy()
ctx['gengo_language'] = wizard.lang_id.id
if wizard.sync_limit > 200 or wizard.sync_limit < 1:
raise osv.except_osv(_("Warning"), _('Sync limit should between 1 to 200 for Gengo translation services.'))
if wizard.sync_type in ['send', 'both']:
self._sync_request(cr, uid, wizard.sync_limit, context=ctx)
if wizard.sync_type in ['receive', 'both']:
self._sync_response(cr, uid, wizard.sync_limit, context=ctx)
return {'type': 'ir.actions.act_window_close'}
def _sync_response(self, cr, uid, limit=GENGO_DEFAULT_LIMIT, context=None):
"""
This method will be called by cron services to get translations from
Gengo. It will read translated terms and comments from Gengo and will
update respective ir.translation in Odoo.
"""
translation_pool = self.pool.get('ir.translation')
flag, gengo = self.gengo_authentication(cr, uid, context=context)
if not flag:
_logger.warning("%s", gengo)
else:
offset = 0
all_translation_ids = translation_pool.search(cr, uid, [('state', '=', 'inprogress'), ('gengo_translation', 'in', ('machine', 'standard', 'pro', 'ultra')), ('order_id', "!=", False)], context=context)
while True:
translation_ids = all_translation_ids[offset:offset + limit]
offset += limit
if not translation_ids:
break
terms_progress = {
'gengo_order_ids': set(),
'ir_translation_ids': set(),
}
translation_terms = translation_pool.browse(cr, uid, translation_ids, context=context)
for term in translation_terms:
terms_progress['gengo_order_ids'].add(term.order_id)
terms_progress['ir_translation_ids'].add(tools.ustr(term.id))
for order_id in terms_progress['gengo_order_ids']:
order_response = gengo.getTranslationOrderJobs(id=order_id)
jobs_approved = order_response.get('response', []).get('order', []).get('jobs_approved', [])
gengo_ids = ','.join(jobs_approved)
if gengo_ids: # Need to check, because getTranslationJobBatch don't catch this case and so call the getTranslationJobs because no ids in url
try:
job_response = gengo.getTranslationJobBatch(id=gengo_ids)
except:
continue
if job_response['opstat'] == 'ok':
for job in job_response['response'].get('jobs', []):
if job.get('custom_data') in terms_progress['ir_translation_ids']:
self._update_terms_job(cr, uid, job, context=context)
return True
def _update_terms_job(self, cr, uid, job, context=None):
translation_pool = self.pool.get('ir.translation')
tid = int(job['custom_data'])
vals = {}
if job.get('status', False) in ('queued', 'available', 'pending', 'reviewable'):
vals['state'] = 'inprogress'
if job.get('body_tgt', False) and job.get('status', False) == 'approved':
vals['value'] = job['body_tgt']
if job.get('status', False) in ('approved', 'canceled'):
vals['state'] = 'translated'
if vals:
translation_pool.write(cr, uid, [tid], vals, context=context)
def _update_terms(self, cr, uid, response, term_ids, context=None):
"""
Update the terms after their translation were requested to Gengo
"""
translation_pool = self.pool.get('ir.translation')
vals = {
'order_id': response.get('order_id', ''),
'state': 'inprogress'
}
translation_pool.write(cr, uid, term_ids, vals, context=context)
jobs = response.get('jobs', [])
if jobs:
for t_id, res in jobs.items():
self._update_terms_job(cr, uid, res, context=context)
return
def pack_jobs_request(self, cr, uid, term_ids, context=None):
''' prepare the terms that will be requested to gengo and returns them in a dictionary with following format
{'jobs': {
'term1.id': {...}
'term2.id': {...}
}
}'''
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
translation_pool = self.pool.get('ir.translation')
jobs = {}
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
auto_approve = 1 if user.company_id.gengo_auto_approve else 0
for term in translation_pool.browse(cr, uid, term_ids, context=context):
if re.search(r"\w", term.src or ""):
comment = user.company_id.gengo_comment or ''
if term.gengo_comment:
comment += '\n' + term.gengo_comment
jobs[time.strftime('%Y%m%d%H%M%S') + '-' + str(term.id)] = {
'type': 'text',
'slug': 'Single :: English to ' + term.lang,
'tier': tools.ustr(term.gengo_translation),
'custom_data': str(term.id),
'body_src': term.src,
'lc_src': 'en',
'lc_tgt': translation_pool._get_gengo_corresponding_language(term.lang),
'auto_approve': auto_approve,
'comment': comment,
'callback_url': "%s/website/gengo_callback?pgk=%s&db=%s" % (base_url, self.get_gengo_key(cr), cr.dbname)
}
return {'jobs': jobs, 'as_group': 0}
def _send_translation_terms(self, cr, uid, term_ids, context=None):
"""
Send a request to Gengo with all the term_ids in a different job, get the response and update the terms in
database accordingly.
"""
flag, gengo = self.gengo_authentication(cr, uid, context=context)
if flag:
request = self.pack_jobs_request(cr, uid, term_ids, context=context)
if request['jobs']:
result = gengo.postTranslationJobs(jobs=request)
if result['opstat'] == 'ok':
self._update_terms(cr, uid, result['response'], term_ids, context=context)
else:
_logger.error(gengo)
return True
def _sync_request(self, cr, uid, limit=GENGO_DEFAULT_LIMIT, context=None):
"""
This scheduler will send a job request to the gengo , which terms are
waiing to be translated and for which gengo_translation is enabled.
A special key 'gengo_language' can be passed in the context in order to
request only translations of that language only. Its value is the language
ID in Odoo.
"""
if context is None:
context = {}
language_pool = self.pool.get('res.lang')
translation_pool = self.pool.get('ir.translation')
domain = [('state', '=', 'to_translate'), ('gengo_translation', 'in', ('machine', 'standard', 'pro', 'ultra')), ('order_id', "=", False)]
if context.get('gengo_language', False):
lc = language_pool.browse(cr, uid, context['gengo_language'], context=context).code
domain.append(('lang', '=', lc))
all_term_ids = translation_pool.search(cr, uid, domain, context=context)
try:
offset = 0
while True:
#search for the n first terms to translate
term_ids = all_term_ids[offset:offset + limit]
if term_ids:
offset += limit
self._send_translation_terms(cr, uid, term_ids, context=context)
_logger.info("%s Translation terms have been posted to Gengo successfully", len(term_ids))
if not len(term_ids) == limit:
break
except Exception, e:
_logger.error("%s", e)
# 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,
23813,
24636,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
7653,
428,
14,
33,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
9295,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
5377,
199,
646,
2050,
199,
646,
295,
199,
646,
900,
199,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
492,
7249,
12,
12824,
63,
998,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
893,
26,
272,
687,
3805,
1939,
492,
18870,
1939,
199,
2590,
3545,
26,
272,
485,
2921,
14,
3764,
360,
8168,
1939,
3555,
440,
1911,
12,
18870,
1939,
4534,
6980,
14,
982,
1265,
8683,
370,
675,
652,
12,
8749,
3907,
314,
3805,
1939,
3555,
687,
1455,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
2268,
1939,
358,
199,
199,
9289,
13160,
63,
3472,
63,
13387,
275,
3388,
421,
199,
533,
1300,
63,
2268,
1939,
63,
13982,
8,
4795,
14,
4795,
63,
4844,
304,
272,
22813,
13160,
63,
3078,
275,
298,
8168,
1939,
14,
8757,
2,
272,
15443,
51,
275,
788,
1095,
14,
923,
63,
2253,
418,
339,
485,
354,
275,
283,
1095,
14,
2268,
1939,
14,
13982,
7,
272,
485,
3406,
275,
469,
267,
283,
5186,
63,
466,
356,
1504,
14,
5592,
8318,
2254,
297,
283,
6795,
7053,
13861,
706,
659,
4318,
661,
9391,
297,
283,
14235,
25224,
659,
4318,
661,
10727,
297,
283,
18088,
2665,
298,
10878,
2434,
1288,
267,
283,
4159,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
4159,
297,
283,
8493,
297,
1415,
29,
549,
395,
267,
283,
5186,
63,
3097,
356,
1504,
14,
4115,
480,
1944,
14,
402,
2895,
370,
7604,
1288,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
5186,
63,
466,
356,
283,
10727,
297,
267,
283,
5186,
63,
3097,
356,
3388,
272,
789,
339,
347,
4205,
8,
277,
12,
2467,
304,
267,
284,
1850,
275,
291,
14,
2293,
459,
723,
14,
888,
63,
5329,
418,
267,
340,
440,
284,
1850,
14,
362,
63,
635,
8,
1556,
12,
12824,
63,
998,
12,
291,
14,
9289,
13160,
63,
3078,
12,
849,
29,
403,
304,
288,
284,
1850,
14,
409,
63,
635,
8,
1556,
12,
12824,
63,
998,
12,
291,
14,
9289,
13160,
63,
3078,
12,
620,
8,
2580,
14,
2580,
20,
4000,
4652,
29,
277,
14,
27544,
9,
339,
347,
664,
63,
2268,
1939,
63,
498,
8,
277,
12,
2467,
304,
267,
284,
1850,
275,
291,
14,
2293,
459,
723,
14,
888,
63,
5329,
418,
267,
372,
284,
1850,
14,
362,
63,
635,
8,
1556,
12,
12824,
63,
998,
12,
291,
14,
9289,
13160,
63,
3078,
12,
849,
628,
16283,
531,
339,
347,
3805,
1939,
63,
11725,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
1449,
267,
961,
1083,
11275,
370,
1551,
282,
1950,
543,
18870,
1939,
14,
2104,
626,
12,
652,
4440,
314,
1684,
436,
18551,
267,
2883,
626,
787,
10632,
370,
314,
7233,
334,
11809,
701,
18870,
1939,
641,
9966,
680,
2779,
2529,
282,
2008,
543,
268,
627,
465,
1642,
1819,
26,
282,
5046,
477,
1038,
319,
316,
340,
314,
6299,
1990,
282,
3182,
503,
440,
268,
627,
465,
3499,
1819,
26,
314,
1950,
12,
340,
652,
1990,
282,
3182,
12,
503,
314,
1125,
1245,
2138,
701,
288,
18870,
1939,
1380,
314,
1950,
3405,
14,
288,
961,
1125,
1245,
883,
1902,
506,
9080,
315,
314,
1654,
9610,
334,
692,
314,
6299,
1990,
2797,
288,
701,
314,
19818,
9,
503,
315,
282,
9592,
5689,
334,
692,
5839,
701,
314,
922,
395,
12850,
652,
1159,
11012,
370,
372,
652,
288,
14598,
14,
267,
1449,
267,
922,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
3707,
1959,
4570,
8,
1556,
12,
413,
12,
1747,
12,
1067,
29,
1100,
9,
267,
340,
440,
922,
14,
4627,
63,
344,
14,
2268,
1939,
63,
3455,
63,
498,
503,
440,
922,
14,
4627,
63,
344,
14,
2268,
1939,
63,
4239,
63,
498,
26,
288,
372,
334,
797,
12,
3824,
8168,
1939,
658,
9885,
2606,
64,
503,
658,
12185,
2606,
64,
787,
4124,
14,
16401,
2195,
18870,
1939,
6299,
2633,
1334,
658,
5268,
690,
3599,
23461,
690,
18870,
1939,
3897,
64,
13853,
267,
862,
26,
288,
3805,
1939,
275,
18870,
1939,
8,
355,
4575,
63,
498,
29,
751,
14,
4627,
63,
344,
14,
2268,
1939,
63,
3455,
63,
498,
14,
2143,
360,
4371,
659,
355,
5726,
63,
498,
29,
751,
14,
4627,
63,
344,
14,
2268,
1939,
63,
4239,
63,
498,
14,
2143,
360,
4371,
659,
355,
19699,
29,
751,
14,
4627,
63,
344,
14,
2268,
1939,
63,
16647,
12,
288,
776,
288,
3805,
1939,
14,
362,
6009,
8257,
342,
288,
372,
334,
549,
12,
3805,
1939,
9,
267,
871,
2186,
12,
325,
26,
288,
485,
2921,
14,
1971,
360,
8168,
1939,
1950,
3405,
358,
288,
372,
334,
797,
12,
3824,
8168,
1939,
1950,
3405,
543,
642,
1245,
3427,
78,
1040,
5,
83,
1040,
531,
450,
325,
9,
339,
347,
2454,
63,
873,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
1449,
267,
6801,
2797
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
23813,
24636,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
7653,
428,
14,
33,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
9295,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
5377,
199,
646,
2050,
199,
646,
295,
199,
646,
900,
199,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
492,
7249,
12,
12824,
63,
998,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
893,
26,
272,
687,
3805,
1939,
492,
18870,
1939,
199,
2590,
3545,
26,
272,
485,
2921,
14,
3764,
360,
8168,
1939,
3555,
440,
1911,
12,
18870,
1939,
4534,
6980,
14,
982,
1265,
8683,
370,
675,
652,
12,
8749,
3907,
314,
3805,
1939,
3555,
687,
1455,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
2268,
1939,
358,
199,
199,
9289,
13160,
63,
3472,
63,
13387,
275,
3388,
421,
199,
533,
1300,
63,
2268,
1939,
63,
13982,
8,
4795,
14,
4795,
63,
4844,
304,
272,
22813,
13160,
63,
3078,
275,
298,
8168,
1939,
14,
8757,
2,
272,
15443,
51,
275,
788,
1095,
14,
923,
63,
2253,
418,
339,
485,
354,
275,
283,
1095,
14,
2268,
1939,
14,
13982,
7,
272,
485,
3406,
275,
469,
267,
283,
5186,
63,
466,
356,
1504,
14,
5592,
8318,
2254,
297,
283,
6795,
7053,
13861,
706,
659,
4318,
661,
9391,
297,
283,
14235,
25224,
659,
4318,
661,
10727,
297,
283,
18088,
2665,
298,
10878,
2434,
1288,
267,
283,
4159,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
4159,
297,
283,
8493,
297,
1415,
29,
549,
395,
267,
283,
5186,
63,
3097,
356,
1504,
14,
4115,
480,
1944,
14,
402,
2895,
370,
7604,
1288,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
5186,
63,
466,
356,
283,
10727,
297,
267,
283,
5186,
63,
3097,
356,
3388,
272,
789,
339,
347,
4205,
8,
277,
12,
2467,
304,
267,
284,
1850,
275,
291,
14,
2293,
459,
723,
14,
888,
63,
5329,
418,
267,
340,
440,
284,
1850,
14,
362,
63,
635,
8,
1556,
12,
12824,
63,
998,
12,
291,
14,
9289,
13160,
63,
3078,
12,
849,
29,
403,
304,
288,
284,
1850,
14,
409,
63,
635,
8,
1556,
12,
12824,
63,
998,
12,
291,
14,
9289,
13160,
63,
3078,
12,
620,
8,
2580,
14,
2580,
20,
4000,
4652,
29,
277,
14,
27544,
9,
339,
347,
664,
63,
2268,
1939,
63,
498,
8,
277,
12,
2467,
304,
267,
284,
1850,
275,
291,
14,
2293,
459,
723,
14,
888,
63,
5329,
418,
267,
372,
284,
1850,
14,
362,
63,
635,
8,
1556,
12,
12824,
63,
998,
12,
291,
14,
9289,
13160,
63,
3078,
12,
849,
628,
16283,
531,
339,
347,
3805,
1939,
63,
11725,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
1449,
267,
961,
1083,
11275,
370,
1551,
282,
1950,
543,
18870,
1939,
14,
2104,
626,
12,
652,
4440,
314,
1684,
436,
18551,
267,
2883,
626,
787,
10632,
370,
314,
7233,
334,
11809,
701,
18870,
1939,
641,
9966,
680,
2779,
2529,
282,
2008,
543,
268,
627,
465,
1642,
1819,
26,
282,
5046,
477,
1038,
319,
316,
340,
314,
6299,
1990,
282,
3182,
503,
440,
268,
627,
465,
3499,
1819,
26,
314,
1950,
12,
340,
652,
1990,
282,
3182,
12,
503,
314,
1125,
1245,
2138,
701,
288,
18870,
1939,
1380,
314,
1950,
3405,
14,
288,
961,
1125,
1245,
883,
1902,
506,
9080,
315,
314,
1654,
9610,
334,
692,
314,
6299,
1990,
2797,
288,
701,
314,
19818,
9,
503,
315,
282,
9592,
5689,
334,
692,
5839,
701,
314,
922,
395,
12850,
652,
1159,
11012,
370,
372,
652,
288,
14598,
14,
267,
1449,
267,
922,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
3707,
1959,
4570,
8,
1556,
12,
413,
12,
1747,
12,
1067,
29,
1100,
9,
267,
340,
440,
922,
14,
4627,
63,
344,
14,
2268,
1939,
63,
3455,
63,
498,
503,
440,
922,
14,
4627,
63,
344,
14,
2268,
1939,
63,
4239,
63,
498,
26,
288,
372,
334,
797,
12,
3824,
8168,
1939,
658,
9885,
2606,
64,
503,
658,
12185,
2606,
64,
787,
4124,
14,
16401,
2195,
18870,
1939,
6299,
2633,
1334,
658,
5268,
690,
3599,
23461,
690,
18870,
1939,
3897,
64,
13853,
267,
862,
26,
288,
3805,
1939,
275,
18870,
1939,
8,
355,
4575,
63,
498,
29,
751,
14,
4627,
63,
344,
14,
2268,
1939,
63,
3455,
63,
498,
14,
2143,
360,
4371,
659,
355,
5726,
63,
498,
29,
751,
14,
4627,
63,
344,
14,
2268,
1939,
63,
4239,
63,
498,
14,
2143,
360,
4371,
659,
355,
19699,
29,
751,
14,
4627,
63,
344,
14,
2268,
1939,
63,
16647,
12,
288,
776,
288,
3805,
1939,
14,
362,
6009,
8257,
342,
288,
372,
334,
549,
12,
3805,
1939,
9,
267,
871,
2186,
12,
325,
26,
288,
485,
2921,
14,
1971,
360,
8168,
1939,
1950,
3405,
358,
288,
372,
334,
797,
12,
3824,
8168,
1939,
1950,
3405,
543,
642,
1245,
3427,
78,
1040,
5,
83,
1040,
531,
450,
325,
9,
339,
347,
2454,
63,
873,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
1449,
267,
6801,
2797,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Thor77/youtube-dl
|
youtube_dl/extractor/eyedotv.py
|
25
|
2710
|
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import (
xpath_text,
parse_duration,
ExtractorError,
)
class EyedoTVIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?eyedo\.tv/[^/]+/(?:#!/)?Live/Detail/(?P<id>[0-9]+)'
_TEST = {
'url': 'https://www.eyedo.tv/en-US/#!/Live/Detail/16301',
'md5': 'ba14f17995cdfc20c36ba40e21bf73f7',
'info_dict': {
'id': '16301',
'ext': 'mp4',
'title': 'Journée du conseil scientifique de l\'Afnic 2015',
'description': 'md5:4abe07293b2f73efc6e1c37028d58c98',
'uploader': 'Afnic Live',
'uploader_id': '8023',
}
}
_ROOT_URL = 'http://live.eyedo.net:1935/'
def _real_extract(self, url):
video_id = self._match_id(url)
video_data = self._download_xml('http://eyedo.tv/api/live/GetLive/%s' % video_id, video_id)
def _add_ns(path):
return self._xpath_ns(path, 'http://schemas.datacontract.org/2004/07/EyeDo.Core.Implementation.Web.ViewModels.Api')
title = xpath_text(video_data, _add_ns('Titre'), 'title', True)
state_live_code = xpath_text(video_data, _add_ns('StateLiveCode'), 'title', True)
if state_live_code == 'avenir':
raise ExtractorError(
'%s said: We\'re sorry, but this video is not yet available.' % self.IE_NAME,
expected=True)
is_live = state_live_code == 'live'
m3u8_url = None
# http://eyedo.tv/Content/Html5/Scripts/html5view.js
if is_live:
if xpath_text(video_data, 'Cdn') == 'true':
m3u8_url = 'http://rrr.sz.xlcdn.com/?account=eyedo&file=A%s&type=live&service=wowza&protocol=http&output=playlist.m3u8' % video_id
else:
m3u8_url = self._ROOT_URL + 'w/%s/eyedo_720p/playlist.m3u8' % video_id
else:
m3u8_url = self._ROOT_URL + 'replay-w/%s/mp4:%s.mp4/playlist.m3u8' % (video_id, video_id)
return {
'id': video_id,
'title': title,
'formats': self._extract_m3u8_formats(
m3u8_url, video_id, 'mp4', 'm3u8' if is_live else 'm3u8_native'),
'description': xpath_text(video_data, _add_ns('Description')),
'duration': parse_duration(xpath_text(video_data, _add_ns('Duration'))),
'uploader': xpath_text(video_data, _add_ns('Createur')),
'uploader_id': xpath_text(video_data, _add_ns('CreateurId')),
'chapter': xpath_text(video_data, _add_ns('ChapitreTitre')),
'chapter_id': xpath_text(video_data, _add_ns('ChapitreId')),
}
|
unlicense
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
14462,
63,
505,
12,
272,
2198,
63,
5553,
12,
272,
19783,
12,
199,
9,
421,
199,
533,
662,
89,
379,
79,
12764,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
14655,
379,
79,
4537,
6993,
15,
26285,
32576,
3381,
5547,
17458,
15,
8064,
9448,
48,
28,
344,
9514,
16,
13,
25,
29716,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
2859,
921,
1544,
14,
14655,
379,
79,
14,
6993,
15,
287,
13,
1668,
15,
3381,
17458,
15,
8064,
15,
975,
8507,
297,
267,
283,
1064,
21,
356,
283,
2470,
1079,
70,
1196,
14732,
10790,
67,
1165,
67,
1344,
2470,
2167,
69,
2025,
4361,
2898,
70,
23,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
975,
8507,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
5691,
349,
5741,
69,
15776,
406,
261,
382,
6276,
287,
1428,
544,
477,
634,
3985,
33,
2324,
530,
6900,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
20,
7570,
1780,
16417,
66,
18,
70,
2898,
2829,
67,
22,
69,
17,
67,
1401,
15501,
68,
2010,
67,
2905,
297,
288,
283,
13671,
356,
283,
33,
2324,
530,
24683,
297,
288,
283,
13671,
63,
344,
356,
283,
11366,
19,
297,
267,
789,
272,
789,
272,
485,
5441,
63,
2632,
275,
283,
1014,
921,
6442,
14,
14655,
379,
79,
14,
846,
26,
1167,
1276,
4805,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
3991,
63,
576,
275,
291,
423,
4249,
63,
1652,
360,
1014,
921,
14655,
379,
79,
14,
6993,
15,
1246,
15,
6442,
15,
1002,
17458,
3149,
83,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
398,
347,
485,
525,
63,
561,
8,
515,
304,
288,
372,
291,
423,
8006,
63,
561,
8,
515,
12,
283,
1014,
921,
9482,
14,
576,
14624,
14,
1308,
15,
15431,
15,
1780,
15,
37,
8048,
2585,
14,
5402,
14,
7921,
14,
5926,
14,
2768,
20474,
14,
7394,
358,
398,
2538,
275,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
52,
390,
264,
659,
283,
1213,
297,
715,
9,
267,
1174,
63,
6442,
63,
600,
275,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
2223,
17458,
3034,
659,
283,
1213,
297,
715,
9,
267,
340,
1174,
63,
6442,
63,
600,
508,
283,
15556,
723,
356,
288,
746,
19783,
8,
355,
1543,
83,
25097,
26,
2136,
3985,
264,
308,
21342,
12,
1325,
642,
3991,
365,
440,
5966,
2808,
3530,
450,
291,
14,
4332,
63,
2339,
12,
355,
1420,
29,
549,
9,
398,
365,
63,
6442,
275,
1174,
63,
6442,
63,
600,
508,
283,
6442,
7,
267,
333,
19,
85,
24,
63,
633,
275,
488,
267,
327,
1455,
921,
14655,
379,
79,
14,
6993,
15,
2714,
15,
12957,
21,
15,
25681,
15,
1360,
21,
1345,
14,
3596,
267,
340,
365,
63,
6442,
26,
288,
340,
14462,
63,
505,
8,
3722,
63,
576,
12,
283,
35,
4272,
358,
508,
283,
2052,
356,
355,
333,
19,
85,
24,
63,
633,
275,
283,
1014,
921,
9734,
82,
14,
11803,
14,
15455,
23982,
14,
957,
10197,
2048,
29,
14655,
379,
79,
6,
493,
29,
33,
5,
83,
6,
466,
29,
6442,
6,
1364,
29,
87,
583,
8076,
6,
3922,
29,
1014,
6,
1199,
29,
10411,
14,
77,
19,
85,
24,
7,
450,
3991,
63,
344,
288,
587,
26,
355,
333,
19,
85,
24,
63,
633,
275,
291,
423,
5441,
63,
2632,
435,
283,
87,
3149,
83,
15,
14655,
379,
79,
63,
18386,
80,
15,
10411,
14,
77,
19,
85,
24,
7,
450,
3991,
63,
344,
267,
587,
26,
288,
333,
19,
85,
24,
63,
633,
275,
291,
423,
5441,
63,
2632,
435,
283,
19540,
13,
87,
3149,
83,
15,
311,
20,
2689,
83,
14,
311,
20,
15,
10411,
14,
77,
19,
85,
24,
7,
450,
334,
3722,
63,
344,
12,
3991,
63,
344,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
6321,
356,
291,
423,
5005,
63,
77,
19,
85,
24,
63,
6321,
8,
355,
333,
19,
85,
24,
63,
633,
12,
3991,
63,
344,
12,
283,
311,
20,
297,
283,
77,
19,
85,
24,
7,
340,
365,
63,
6442,
587,
283,
77,
19,
85,
24,
63,
6106,
659,
288,
283,
1802,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
5831,
3855,
288,
283,
5553,
356,
2198,
63,
5553,
8,
8006,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
13283,
22645,
288,
283,
13671,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
2499,
300,
3855,
288,
283,
13671,
63,
344,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
2499,
300,
1304,
3855,
288,
283,
11316,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
1049,
439,
390,
264,
52,
390,
264,
3855,
288,
283,
11316,
63,
344,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
1049,
439,
390,
264,
1304,
3855,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
14462,
63,
505,
12,
272,
2198,
63,
5553,
12,
272,
19783,
12,
199,
9,
421,
199,
533,
662,
89,
379,
79,
12764,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
14655,
379,
79,
4537,
6993,
15,
26285,
32576,
3381,
5547,
17458,
15,
8064,
9448,
48,
28,
344,
9514,
16,
13,
25,
29716,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
2859,
921,
1544,
14,
14655,
379,
79,
14,
6993,
15,
287,
13,
1668,
15,
3381,
17458,
15,
8064,
15,
975,
8507,
297,
267,
283,
1064,
21,
356,
283,
2470,
1079,
70,
1196,
14732,
10790,
67,
1165,
67,
1344,
2470,
2167,
69,
2025,
4361,
2898,
70,
23,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
975,
8507,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
5691,
349,
5741,
69,
15776,
406,
261,
382,
6276,
287,
1428,
544,
477,
634,
3985,
33,
2324,
530,
6900,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
20,
7570,
1780,
16417,
66,
18,
70,
2898,
2829,
67,
22,
69,
17,
67,
1401,
15501,
68,
2010,
67,
2905,
297,
288,
283,
13671,
356,
283,
33,
2324,
530,
24683,
297,
288,
283,
13671,
63,
344,
356,
283,
11366,
19,
297,
267,
789,
272,
789,
272,
485,
5441,
63,
2632,
275,
283,
1014,
921,
6442,
14,
14655,
379,
79,
14,
846,
26,
1167,
1276,
4805,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
3991,
63,
576,
275,
291,
423,
4249,
63,
1652,
360,
1014,
921,
14655,
379,
79,
14,
6993,
15,
1246,
15,
6442,
15,
1002,
17458,
3149,
83,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
398,
347,
485,
525,
63,
561,
8,
515,
304,
288,
372,
291,
423,
8006,
63,
561,
8,
515,
12,
283,
1014,
921,
9482,
14,
576,
14624,
14,
1308,
15,
15431,
15,
1780,
15,
37,
8048,
2585,
14,
5402,
14,
7921,
14,
5926,
14,
2768,
20474,
14,
7394,
358,
398,
2538,
275,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
52,
390,
264,
659,
283,
1213,
297,
715,
9,
267,
1174,
63,
6442,
63,
600,
275,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
2223,
17458,
3034,
659,
283,
1213,
297,
715,
9,
267,
340,
1174,
63,
6442,
63,
600,
508,
283,
15556,
723,
356,
288,
746,
19783,
8,
355,
1543,
83,
25097,
26,
2136,
3985,
264,
308,
21342,
12,
1325,
642,
3991,
365,
440,
5966,
2808,
3530,
450,
291,
14,
4332,
63,
2339,
12,
355,
1420,
29,
549,
9,
398,
365,
63,
6442,
275,
1174,
63,
6442,
63,
600,
508,
283,
6442,
7,
267,
333,
19,
85,
24,
63,
633,
275,
488,
267,
327,
1455,
921,
14655,
379,
79,
14,
6993,
15,
2714,
15,
12957,
21,
15,
25681,
15,
1360,
21,
1345,
14,
3596,
267,
340,
365,
63,
6442,
26,
288,
340,
14462,
63,
505,
8,
3722,
63,
576,
12,
283,
35,
4272,
358,
508,
283,
2052,
356,
355,
333,
19,
85,
24,
63,
633,
275,
283,
1014,
921,
9734,
82,
14,
11803,
14,
15455,
23982,
14,
957,
10197,
2048,
29,
14655,
379,
79,
6,
493,
29,
33,
5,
83,
6,
466,
29,
6442,
6,
1364,
29,
87,
583,
8076,
6,
3922,
29,
1014,
6,
1199,
29,
10411,
14,
77,
19,
85,
24,
7,
450,
3991,
63,
344,
288,
587,
26,
355,
333,
19,
85,
24,
63,
633,
275,
291,
423,
5441,
63,
2632,
435,
283,
87,
3149,
83,
15,
14655,
379,
79,
63,
18386,
80,
15,
10411,
14,
77,
19,
85,
24,
7,
450,
3991,
63,
344,
267,
587,
26,
288,
333,
19,
85,
24,
63,
633,
275,
291,
423,
5441,
63,
2632,
435,
283,
19540,
13,
87,
3149,
83,
15,
311,
20,
2689,
83,
14,
311,
20,
15,
10411,
14,
77,
19,
85,
24,
7,
450,
334,
3722,
63,
344,
12,
3991,
63,
344,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
6321,
356,
291,
423,
5005,
63,
77,
19,
85,
24,
63,
6321,
8,
355,
333,
19,
85,
24,
63,
633,
12,
3991,
63,
344,
12,
283,
311,
20,
297,
283,
77,
19,
85,
24,
7,
340,
365,
63,
6442,
587,
283,
77,
19,
85,
24,
63,
6106,
659,
288,
283,
1802,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
5831,
3855,
288,
283,
5553,
356,
2198,
63,
5553,
8,
8006,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
13283,
22645,
288,
283,
13671,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
2499,
300,
3855,
288,
283,
13671,
63,
344,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
2499,
300,
1304,
3855,
288,
283,
11316,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
1049,
439,
390,
264,
52,
390,
264,
3855,
288,
283,
11316,
63,
344,
356,
14462,
63,
505,
8,
3722,
63,
576,
12,
485,
525,
63,
561,
360,
1049,
439,
390,
264,
1304,
3855,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
stackforge/tacker
|
tacker/tests/functional/vnfm/test_tosca_vnf_block_storage.py
|
2
|
4322
|
# Copyright 2016 Brocade Communications System, 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 yaml
from oslo_config import cfg
from tacker.plugins.common import constants as evt_constants
from tacker.tests import constants
from tacker.tests.functional import base
CONF = cfg.CONF
VNF_CIRROS_CREATE_TIMEOUT = 120
class VnfBlockStorageTestToscaCreate(base.BaseTackerTest):
def _test_create_vnf(self, vnfd_file, vnf_name,
template_source="onboarded"):
if template_source == "onboarded":
(vnfd_instance,
vnf_instance,
tosca_dict) = self.vnfd_and_vnf_create(vnfd_file, vnf_name)
if template_source == 'inline':
vnf_instance, tosca_dict = self.vnfd_and_vnf_create_inline(
vnfd_file, vnf_name)
vnfd_id = vnf_instance['vnf']['vnfd_id']
vnf_id = vnf_instance['vnf']['id']
self.wait_until_vnf_active(
vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
vnf_show_out = self.client.show_vnf(vnf_id)['vnf']
self.assertIsNotNone(vnf_show_out['mgmt_ip_address'])
prop_dict = tosca_dict['topology_template']['node_templates'][
'CP1']['properties']
# Verify if ip_address is static, it is same as in show_vnf
if prop_dict.get('ip_address'):
mgmt_ip_address_input = prop_dict.get('ip_address')
mgmt_info = yaml.safe_load(
vnf_show_out['mgmt_ip_address'])
self.assertEqual(mgmt_ip_address_input, mgmt_info['VDU1'])
# Verify anti spoofing settings
stack_id = vnf_show_out['instance_id']
template_dict = tosca_dict['topology_template']['node_templates']
for field in template_dict:
prop_dict = template_dict[field]['properties']
if prop_dict.get('anti_spoofing_protection'):
self.verify_antispoofing_in_stack(stack_id=stack_id,
resource_name=field)
self.verify_vnf_crud_events(
vnf_id, evt_constants.RES_EVT_CREATE,
evt_constants.PENDING_CREATE, cnt=2)
self.verify_vnf_crud_events(
vnf_id, evt_constants.RES_EVT_CREATE, evt_constants.ACTIVE)
return vnfd_id, vnf_id
def _test_delete_vnf(self, vnf_id):
# Delete vnf_instance with vnf_id
try:
self.client.delete_vnf(vnf_id)
except Exception:
assert False, "vnf Delete failed"
self.wait_until_vnf_delete(vnf_id,
constants.VNF_CIRROS_DELETE_TIMEOUT)
self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_DELETE,
evt_constants.PENDING_DELETE, cnt=2)
def _test_create_delete_vnf_tosca(self, vnfd_file, vnf_name,
template_source):
vnfd_id, vnf_id = self._test_create_vnf(vnfd_file, vnf_name,
template_source)
servers = self.novaclient().servers.list()
vdus = []
for server in servers:
vdus.append(server.name)
self.assertIn('test-vdu-block-storage', vdus)
for server in servers:
if server.name == 'test-vdu-block-storage':
server_id = server.id
server_volumes = self.novaclient().volumes\
.get_server_volumes(server_id)
self.assertTrue(len(server_volumes) > 0)
self._test_delete_vnf(vnf_id)
def test_create_delete_vnf_tosca_from_vnfd(self):
self._test_create_delete_vnf_tosca(
'sample-tosca-vnfd-block-storage.yaml',
'test_tosca_vnf_with_cirros',
'onboarded')
|
apache-2.0
|
[
3,
1898,
7800,
699,
293,
9490,
18686,
6187,
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,
8864,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
307,
564,
281,
14,
5265,
14,
2330,
492,
5262,
465,
16330,
63,
5559,
199,
504,
307,
564,
281,
14,
2219,
492,
5262,
199,
504,
307,
564,
281,
14,
2219,
14,
15481,
492,
1300,
421,
199,
3103,
275,
4810,
14,
3103,
199,
54,
19749,
63,
3553,
50,
1092,
51,
63,
8366,
63,
8899,
275,
13960,
421,
199,
533,
812,
9914,
3142,
6408,
774,
1378,
7101,
2499,
8,
1095,
14,
1563,
52,
564,
281,
774,
304,
272,
347,
485,
396,
63,
981,
63,
6002,
70,
8,
277,
12,
373,
78,
2592,
63,
493,
12,
373,
9914,
63,
354,
12,
586,
1978,
63,
1365,
628,
265,
656,
12910,
2349,
398,
340,
1978,
63,
1365,
508,
298,
265,
656,
12910,
582,
288,
334,
6002,
2592,
63,
842,
12,
1467,
373,
9914,
63,
842,
12,
1467,
370,
7101,
63,
807,
9,
275,
291,
14,
6002,
2592,
63,
460,
63,
6002,
70,
63,
981,
8,
6002,
2592,
63,
493,
12,
373,
9914,
63,
354,
9,
398,
340,
1978,
63,
1365,
508,
283,
6460,
356,
288,
373,
9914,
63,
842,
12,
370,
7101,
63,
807,
275,
291,
14,
6002,
2592,
63,
460,
63,
6002,
70,
63,
981,
63,
6460,
8,
355,
373,
78,
2592,
63,
493,
12,
373,
9914,
63,
354,
9,
398,
373,
78,
2592,
63,
344,
275,
373,
9914,
63,
842,
459,
6002,
70,
2545,
6002,
2592,
63,
344,
418,
267,
373,
9914,
63,
344,
275,
373,
9914,
63,
842,
459,
6002,
70,
2545,
344,
418,
267,
291,
14,
2573,
63,
8111,
63,
6002,
70,
63,
2682,
8,
288,
373,
9914,
63,
344,
12,
288,
5262,
14,
54,
19749,
63,
3553,
50,
1092,
51,
63,
8366,
63,
8899,
12,
288,
5262,
14,
10401,
63,
51,
906,
6102,
63,
4961,
9,
267,
373,
9914,
63,
2384,
63,
548,
275,
291,
14,
1258,
14,
2384,
63,
6002,
70,
8,
6002,
70,
63,
344,
11820,
6002,
70,
418,
267,
291,
14,
10389,
8,
6002,
70,
63,
2384,
63,
548,
459,
9752,
63,
711,
63,
1562,
1105,
398,
5931,
63,
807,
275,
370,
7101,
63,
807,
459,
10775,
63,
1160,
2545,
932,
63,
5876,
3488,
288,
283,
2890,
17,
2545,
3282,
418,
398,
327,
7635,
340,
3384,
63,
1562,
365,
2955,
12,
652,
365,
2011,
465,
315,
2498,
63,
6002,
70,
267,
340,
5931,
63,
807,
14,
362,
360,
711,
63,
1562,
735,
288,
333,
22489,
63,
711,
63,
1562,
63,
1210,
275,
5931,
63,
807,
14,
362,
360,
711,
63,
1562,
358,
288,
333,
22489,
63,
815,
275,
8864,
14,
3489,
63,
912,
8,
355,
373,
9914,
63,
2384,
63,
548,
459,
9752,
63,
711,
63,
1562,
1105,
288,
291,
14,
629,
8,
9752,
63,
711,
63,
1562,
63,
1210,
12,
333,
22489,
63,
815,
459,
54,
4980,
17,
1105,
398,
327,
7635,
24141,
25664,
1618,
316,
2202,
267,
3464,
63,
344,
275,
373,
9914,
63,
2384,
63,
548,
459,
842,
63,
344,
418,
267,
1978,
63,
807,
275,
370,
7101,
63,
807,
459,
10775,
63,
1160,
2545,
932,
63,
5876,
418,
267,
367,
901,
315,
1978,
63,
807,
26,
288,
5931,
63,
807,
275,
1978,
63,
807,
59,
698,
2733,
3282,
418,
288,
340,
5931,
63,
807,
14,
362,
360,
4466,
63,
22522,
1618,
316,
63,
14103,
735,
355,
291,
14,
4712,
63,
4466,
22522,
1618,
316,
63,
262,
63,
2340,
8,
2340,
63,
344,
29,
2340,
63,
344,
12,
8179,
2073,
63,
354,
29,
698,
9,
398,
291,
14,
4712,
63,
6002,
70,
63,
28941,
63,
4368,
8,
288,
373,
9914,
63,
344,
12,
16330,
63,
5559,
14,
3830,
63,
12093,
63,
8366,
12,
288,
16330,
63,
5559,
14,
21243,
63,
8366,
12,
12703,
29,
18,
9,
267,
291,
14,
4712,
63,
6002,
70,
63,
28941,
63,
4368,
8,
288,
373,
9914,
63,
344,
12,
16330,
63,
5559,
14,
3830,
63,
12093,
63,
8366,
12,
16330,
63,
5559,
14,
10401,
9,
267,
372,
373,
78,
2592,
63,
344,
12,
373,
9914,
63,
344,
339,
347,
485,
396,
63,
1807,
63,
6002,
70,
8,
277,
12,
373,
9914,
63,
344,
304,
267,
327,
8496,
373,
9914,
63,
842,
543,
373,
9914,
63,
344,
267,
862,
26,
288,
291,
14,
1258,
14,
1807,
63,
6002,
70,
8,
6002,
70,
63,
344,
9,
267,
871,
2186,
26,
288,
702,
756,
12,
298,
6002,
70,
8496,
3405,
2,
398,
291,
14,
2573,
63,
8111,
63,
6002,
70,
63,
1807,
8,
6002,
70,
63,
344,
12,
3521,
5262,
14,
54,
19749,
63,
3553,
50,
1092,
51,
63,
7014,
63,
8899,
9,
267,
291,
14,
4712,
63,
6002,
70,
63,
28941,
63,
4368,
8,
6002,
70,
63,
344,
12,
16330,
63,
5559,
14,
3830,
63,
12093,
63,
7014,
12,
2511,
16330,
63,
5559,
14,
21243,
63,
7014,
12,
12703,
29,
18,
9,
339,
347,
485,
396,
63,
981,
63,
1807,
63,
6002,
70,
63,
475,
7101,
8,
277,
12,
373,
78,
2592,
63,
493,
12,
373,
9914,
63,
354,
12,
288,
1978,
63,
1365,
304,
267,
373,
78,
2592,
63,
344,
12,
373,
9914,
63,
344,
275,
291,
423,
396,
63,
981,
63,
6002,
70,
8,
6002,
2592,
63,
493,
12,
373,
9914,
63,
354,
12,
6059,
1978,
63,
1365,
9,
267,
8037,
275,
291,
14,
889,
15367,
864,
1252,
5871
] |
[
1898,
7800,
699,
293,
9490,
18686,
6187,
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,
8864,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
307,
564,
281,
14,
5265,
14,
2330,
492,
5262,
465,
16330,
63,
5559,
199,
504,
307,
564,
281,
14,
2219,
492,
5262,
199,
504,
307,
564,
281,
14,
2219,
14,
15481,
492,
1300,
421,
199,
3103,
275,
4810,
14,
3103,
199,
54,
19749,
63,
3553,
50,
1092,
51,
63,
8366,
63,
8899,
275,
13960,
421,
199,
533,
812,
9914,
3142,
6408,
774,
1378,
7101,
2499,
8,
1095,
14,
1563,
52,
564,
281,
774,
304,
272,
347,
485,
396,
63,
981,
63,
6002,
70,
8,
277,
12,
373,
78,
2592,
63,
493,
12,
373,
9914,
63,
354,
12,
586,
1978,
63,
1365,
628,
265,
656,
12910,
2349,
398,
340,
1978,
63,
1365,
508,
298,
265,
656,
12910,
582,
288,
334,
6002,
2592,
63,
842,
12,
1467,
373,
9914,
63,
842,
12,
1467,
370,
7101,
63,
807,
9,
275,
291,
14,
6002,
2592,
63,
460,
63,
6002,
70,
63,
981,
8,
6002,
2592,
63,
493,
12,
373,
9914,
63,
354,
9,
398,
340,
1978,
63,
1365,
508,
283,
6460,
356,
288,
373,
9914,
63,
842,
12,
370,
7101,
63,
807,
275,
291,
14,
6002,
2592,
63,
460,
63,
6002,
70,
63,
981,
63,
6460,
8,
355,
373,
78,
2592,
63,
493,
12,
373,
9914,
63,
354,
9,
398,
373,
78,
2592,
63,
344,
275,
373,
9914,
63,
842,
459,
6002,
70,
2545,
6002,
2592,
63,
344,
418,
267,
373,
9914,
63,
344,
275,
373,
9914,
63,
842,
459,
6002,
70,
2545,
344,
418,
267,
291,
14,
2573,
63,
8111,
63,
6002,
70,
63,
2682,
8,
288,
373,
9914,
63,
344,
12,
288,
5262,
14,
54,
19749,
63,
3553,
50,
1092,
51,
63,
8366,
63,
8899,
12,
288,
5262,
14,
10401,
63,
51,
906,
6102,
63,
4961,
9,
267,
373,
9914,
63,
2384,
63,
548,
275,
291,
14,
1258,
14,
2384,
63,
6002,
70,
8,
6002,
70,
63,
344,
11820,
6002,
70,
418,
267,
291,
14,
10389,
8,
6002,
70,
63,
2384,
63,
548,
459,
9752,
63,
711,
63,
1562,
1105,
398,
5931,
63,
807,
275,
370,
7101,
63,
807,
459,
10775,
63,
1160,
2545,
932,
63,
5876,
3488,
288,
283,
2890,
17,
2545,
3282,
418,
398,
327,
7635,
340,
3384,
63,
1562,
365,
2955,
12,
652,
365,
2011,
465,
315,
2498,
63,
6002,
70,
267,
340,
5931,
63,
807,
14,
362,
360,
711,
63,
1562,
735,
288,
333,
22489,
63,
711,
63,
1562,
63,
1210,
275,
5931,
63,
807,
14,
362,
360,
711,
63,
1562,
358,
288,
333,
22489,
63,
815,
275,
8864,
14,
3489,
63,
912,
8,
355,
373,
9914,
63,
2384,
63,
548,
459,
9752,
63,
711,
63,
1562,
1105,
288,
291,
14,
629,
8,
9752,
63,
711,
63,
1562,
63,
1210,
12,
333,
22489,
63,
815,
459,
54,
4980,
17,
1105,
398,
327,
7635,
24141,
25664,
1618,
316,
2202,
267,
3464,
63,
344,
275,
373,
9914,
63,
2384,
63,
548,
459,
842,
63,
344,
418,
267,
1978,
63,
807,
275,
370,
7101,
63,
807,
459,
10775,
63,
1160,
2545,
932,
63,
5876,
418,
267,
367,
901,
315,
1978,
63,
807,
26,
288,
5931,
63,
807,
275,
1978,
63,
807,
59,
698,
2733,
3282,
418,
288,
340,
5931,
63,
807,
14,
362,
360,
4466,
63,
22522,
1618,
316,
63,
14103,
735,
355,
291,
14,
4712,
63,
4466,
22522,
1618,
316,
63,
262,
63,
2340,
8,
2340,
63,
344,
29,
2340,
63,
344,
12,
8179,
2073,
63,
354,
29,
698,
9,
398,
291,
14,
4712,
63,
6002,
70,
63,
28941,
63,
4368,
8,
288,
373,
9914,
63,
344,
12,
16330,
63,
5559,
14,
3830,
63,
12093,
63,
8366,
12,
288,
16330,
63,
5559,
14,
21243,
63,
8366,
12,
12703,
29,
18,
9,
267,
291,
14,
4712,
63,
6002,
70,
63,
28941,
63,
4368,
8,
288,
373,
9914,
63,
344,
12,
16330,
63,
5559,
14,
3830,
63,
12093,
63,
8366,
12,
16330,
63,
5559,
14,
10401,
9,
267,
372,
373,
78,
2592,
63,
344,
12,
373,
9914,
63,
344,
339,
347,
485,
396,
63,
1807,
63,
6002,
70,
8,
277,
12,
373,
9914,
63,
344,
304,
267,
327,
8496,
373,
9914,
63,
842,
543,
373,
9914,
63,
344,
267,
862,
26,
288,
291,
14,
1258,
14,
1807,
63,
6002,
70,
8,
6002,
70,
63,
344,
9,
267,
871,
2186,
26,
288,
702,
756,
12,
298,
6002,
70,
8496,
3405,
2,
398,
291,
14,
2573,
63,
8111,
63,
6002,
70,
63,
1807,
8,
6002,
70,
63,
344,
12,
3521,
5262,
14,
54,
19749,
63,
3553,
50,
1092,
51,
63,
7014,
63,
8899,
9,
267,
291,
14,
4712,
63,
6002,
70,
63,
28941,
63,
4368,
8,
6002,
70,
63,
344,
12,
16330,
63,
5559,
14,
3830,
63,
12093,
63,
7014,
12,
2511,
16330,
63,
5559,
14,
21243,
63,
7014,
12,
12703,
29,
18,
9,
339,
347,
485,
396,
63,
981,
63,
1807,
63,
6002,
70,
63,
475,
7101,
8,
277,
12,
373,
78,
2592,
63,
493,
12,
373,
9914,
63,
354,
12,
288,
1978,
63,
1365,
304,
267,
373,
78,
2592,
63,
344,
12,
373,
9914,
63,
344,
275,
291,
423,
396,
63,
981,
63,
6002,
70,
8,
6002,
2592,
63,
493,
12,
373,
9914,
63,
354,
12,
6059,
1978,
63,
1365,
9,
267,
8037,
275,
291,
14,
889,
15367,
864,
1252,
5871,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kohnle-lernmodule/exe201based
|
twisted/copyright.py
|
14
|
1377
|
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Copyright information for Twisted.
"""
version="2.2.0"
longversion="Twisted %s" % version
copyright="""\
Copyright (c) 2001-2004 Twisted Matrix Laboratories.
See LICENSE for details."""
disclaimer='''
Twisted, the Framework of Your Internet
%s
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.
''' % copyright
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
4388,
199,
624,
199,
7384,
2556,
367,
17078,
14,
199,
624,
421,
199,
1023,
628,
18,
14,
18,
14,
16,
2,
199,
2809,
1023,
628,
52,
5221,
450,
83,
2,
450,
1015,
199,
7307,
11916,
60,
199,
7384,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
9295,
5113,
367,
2436,
1041,
199,
199,
6409,
6400,
19938,
199,
52,
5221,
12,
314,
22545,
402,
19519,
22026,
199,
5,
83,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
65,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
2,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
7395,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3470,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
529,
1147,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
1589,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
199,
12409,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
1438,
5786,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
31461,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
13887,
12799,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
2673,
2617,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3359,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
9139,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
2344,
450,
4248,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
4388,
199,
624,
199,
7384,
2556,
367,
17078,
14,
199,
624,
421,
199,
1023,
628,
18,
14,
18,
14,
16,
2,
199,
2809,
1023,
628,
52,
5221,
450,
83,
2,
450,
1015,
199,
7307,
11916,
60,
199,
7384,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
9295,
5113,
367,
2436,
1041,
199,
199,
6409,
6400,
19938,
199,
52,
5221,
12,
314,
22545,
402,
19519,
22026,
199,
5,
83,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
65,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
2,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
7395,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3470,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
529,
1147,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
1589,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
199,
12409,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
1438,
5786,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
31461,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
13887,
12799,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
2673,
2617,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3359,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
9139,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
2344,
450,
4248,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
jesux/PatataWifi
|
FruityWifi/www/modules/responder/includes/Responder-master/LDAPPackets.py
|
2
|
14612
|
#! /usr/bin/env python
# NBT-NS/LLMNR Responder
# Created by Laurent Gaffie
# Copyright (C) 2014 Trustwave Holdings, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import struct
from odict import OrderedDict
class Packet():
fields = OrderedDict([
("data", ""),
])
def __init__(self, **kw):
self.fields = OrderedDict(self.__class__.fields)
for k,v in kw.items():
if callable(v):
self.fields[k] = v(self.fields[k])
else:
self.fields[k] = v
def __str__(self):
return "".join(map(str, self.fields.values()))
class LDAPSearchDefaultPacket(Packet):
fields = OrderedDict([
("ParserHeadASNID", "\x30"),
("ParserHeadASNLen", "\x0c"),
("MessageIDASNID", "\x02"),
("MessageIDASNLen", "\x01"),
("MessageIDASNStr", "\x0f"),
("OpHeadASNID", "\x65"),
("OpHeadASNIDLen", "\x07"),
("SearchDoneSuccess", "\x0A\x01\x00\x04\x00\x04\x00"),#No Results.
])
class LDAPSearchSupportedCapabilitiesPacket(Packet):
fields = OrderedDict([
("ParserHeadASNID", "\x30"),
("ParserHeadASNLenOfLen", "\x84"),
("ParserHeadASNLen", "\x00\x00\x00\x7e"),#126
("MessageIDASNID", "\x02"),
("MessageIDASNLen", "\x01"),
("MessageIDASNStr", "\x02"),
("OpHeadASNID", "\x64"),
("OpHeadASNIDLenOfLen", "\x84"),
("OpHeadASNIDLen", "\x00\x00\x00\x75"),#117
("ObjectName", "\x04\x00"),
("SearchAttribASNID", "\x30"),
("SearchAttribASNLenOfLen", "\x84"),
("SearchAttribASNLen", "\x00\x00\x00\x6d"),#109
("SearchAttribASNID1", "\x30"),
("SearchAttribASN1LenOfLen", "\x84"),
("SearchAttribASN1Len", "\x00\x00\x00\x67"),#103
("SearchAttribASN2ID", "\x04"),
("SearchAttribASN2Len", "\x15"),#21
("SearchAttribASN2Str", "supportedCapabilities"),
("SearchAttribASN3ID", "\x31"),
("SearchAttribASN3LenOfLen", "\x84"),
("SearchAttribASN3Len", "\x00\x00\x00\x4a"),
("SearchAttrib1ASNID", "\x04"),
("SearchAttrib1ASNLen", "\x16"),#22
("SearchAttrib1ASNStr", "1.2.840.113556.1.4.800"),
("SearchAttrib2ASNID", "\x04"),
("SearchAttrib2ASNLen", "\x17"),#23
("SearchAttrib2ASNStr", "1.2.840.113556.1.4.1670"),
("SearchAttrib3ASNID", "\x04"),
("SearchAttrib3ASNLen", "\x17"),#23
("SearchAttrib3ASNStr", "1.2.840.113556.1.4.1791"),
("SearchDoneASNID", "\x30"),
("SearchDoneASNLenOfLen", "\x84"),
("SearchDoneASNLen", "\x00\x00\x00\x10"),#16
("MessageIDASN2ID", "\x02"),
("MessageIDASN2Len", "\x01"),
("MessageIDASN2Str", "\x02"),
("SearchDoneStr", "\x65\x84\x00\x00\x00\x07\x0a\x01\x00\x04\x00\x04\x00"),
## No need to calculate anything this time, this packet is generic.
])
class LDAPSearchSupportedMechanismsPacket(Packet):
fields = OrderedDict([
("ParserHeadASNID", "\x30"),
("ParserHeadASNLenOfLen", "\x84"),
("ParserHeadASNLen", "\x00\x00\x00\x60"),#96
("MessageIDASNID", "\x02"),
("MessageIDASNLen", "\x01"),
("MessageIDASNStr", "\x02"),
("OpHeadASNID", "\x64"),
("OpHeadASNIDLenOfLen", "\x84"),
("OpHeadASNIDLen", "\x00\x00\x00\x57"),#87
("ObjectName", "\x04\x00"),
("SearchAttribASNID", "\x30"),
("SearchAttribASNLenOfLen", "\x84"),
("SearchAttribASNLen", "\x00\x00\x00\x4f"),#79
("SearchAttribASNID1", "\x30"),
("SearchAttribASN1LenOfLen", "\x84"),
("SearchAttribASN1Len", "\x00\x00\x00\x49"),#73
("SearchAttribASN2ID", "\x04"),
("SearchAttribASN2Len", "\x17"),#23
("SearchAttribASN2Str", "supportedSASLMechanisms"),
("SearchAttribASN3ID", "\x31"),
("SearchAttribASN3LenOfLen", "\x84"),
("SearchAttribASN3Len", "\x00\x00\x00\x2a"),#42
("SearchAttrib1ASNID", "\x04"),
("SearchAttrib1ASNLen", "\x06"),#6
("SearchAttrib1ASNStr", "GSSAPI"),
("SearchAttrib2ASNID", "\x04"),
("SearchAttrib2ASNLen", "\x0a"),#10
("SearchAttrib2ASNStr", "GSS-SPNEGO"),
("SearchAttrib3ASNID", "\x04"),
("SearchAttrib3ASNLen", "\x08"),#8
("SearchAttrib3ASNStr", "EXTERNAL"),
("SearchAttrib4ASNID", "\x04"),
("SearchAttrib4ASNLen", "\x0a"),#10
("SearchAttrib4ASNStr", "DIGEST-MD5"),
("SearchDoneASNID", "\x30"),
("SearchDoneASNLenOfLen", "\x84"),
("SearchDoneASNLen", "\x00\x00\x00\x10"),#16
("MessageIDASN2ID", "\x02"),
("MessageIDASN2Len", "\x01"),
("MessageIDASN2Str", "\x02"),
("SearchDoneStr", "\x65\x84\x00\x00\x00\x07\x0a\x01\x00\x04\x00\x04\x00"),
## No need to calculate anything this time, this packet is generic.
])
class LDAPNTLMChallenge(Packet):
fields = OrderedDict([
("ParserHeadASNID", "\x30"),
("ParserHeadASNLenOfLen", "\x84"),
("ParserHeadASNLen", "\x00\x00\x00\xD0"),#208
("MessageIDASNID", "\x02"),
("MessageIDASNLen", "\x01"),
("MessageIDASNStr", "\x02"),
("OpHeadASNID", "\x61"),
("OpHeadASNIDLenOfLen", "\x84"),
("OpHeadASNIDLen", "\x00\x00\x00\xc7"),#199
("Status", "\x0A"),
("StatusASNLen", "\x01"),
("StatusASNStr", "\x0e"), #In Progress.
("MatchedDN", "\x04\x00"), #Null
("ErrorMessage", "\x04\x00"), #Null
("SequenceHeader", "\x87"),
("SequenceHeaderLenOfLen", "\x81"),
("SequenceHeaderLen", "\x82"), #188
("NTLMSSPSignature", "NTLMSSP"),
("NTLMSSPSignatureNull", "\x00"),
("NTLMSSPMessageType", "\x02\x00\x00\x00"),
("NTLMSSPNtWorkstationLen","\x1e\x00"),
("NTLMSSPNtWorkstationMaxLen","\x1e\x00"),
("NTLMSSPNtWorkstationBuffOffset","\x38\x00\x00\x00"),
("NTLMSSPNtNegotiateFlags","\x15\x82\x89\xe2"),
("NTLMSSPNtServerChallenge","\x81\x22\x33\x34\x55\x46\xe7\x88"),
("NTLMSSPNtReserved","\x00\x00\x00\x00\x00\x00\x00\x00"),
("NTLMSSPNtTargetInfoLen","\x94\x00"),
("NTLMSSPNtTargetInfoMaxLen","\x94\x00"),
("NTLMSSPNtTargetInfoBuffOffset","\x56\x00\x00\x00"),
("NegTokenInitSeqMechMessageVersionHigh","\x05"),
("NegTokenInitSeqMechMessageVersionLow","\x02"),
("NegTokenInitSeqMechMessageVersionBuilt","\xce\x0e"),
("NegTokenInitSeqMechMessageVersionReserved","\x00\x00\x00"),
("NegTokenInitSeqMechMessageVersionNTLMType","\x0f"),
("NTLMSSPNtWorkstationName","SMB12"),
("NTLMSSPNTLMChallengeAVPairsId","\x02\x00"),
("NTLMSSPNTLMChallengeAVPairsLen","\x0a\x00"),
("NTLMSSPNTLMChallengeAVPairsUnicodeStr","smb12"),
("NTLMSSPNTLMChallengeAVPairs1Id","\x01\x00"),
("NTLMSSPNTLMChallengeAVPairs1Len","\x1e\x00"),
("NTLMSSPNTLMChallengeAVPairs1UnicodeStr","SERVER2008"),
("NTLMSSPNTLMChallengeAVPairs2Id","\x04\x00"),
("NTLMSSPNTLMChallengeAVPairs2Len","\x1e\x00"),
("NTLMSSPNTLMChallengeAVPairs2UnicodeStr","smb12.local"),
("NTLMSSPNTLMChallengeAVPairs3Id","\x03\x00"),
("NTLMSSPNTLMChallengeAVPairs3Len","\x1e\x00"),
("NTLMSSPNTLMChallengeAVPairs3UnicodeStr","SERVER2008.smb12.local"),
("NTLMSSPNTLMChallengeAVPairs5Id","\x05\x00"),
("NTLMSSPNTLMChallengeAVPairs5Len","\x04\x00"),
("NTLMSSPNTLMChallengeAVPairs5UnicodeStr","smb12.local"),
("NTLMSSPNTLMChallengeAVPairs6Id","\x00\x00"),
("NTLMSSPNTLMChallengeAVPairs6Len","\x00\x00"),
])
def calculate(self):
##Convert strings to Unicode first...
self.fields["NTLMSSPNtWorkstationName"] = self.fields["NTLMSSPNtWorkstationName"].encode('utf-16le')
self.fields["NTLMSSPNTLMChallengeAVPairsUnicodeStr"] = self.fields["NTLMSSPNTLMChallengeAVPairsUnicodeStr"].encode('utf-16le')
self.fields["NTLMSSPNTLMChallengeAVPairs1UnicodeStr"] = self.fields["NTLMSSPNTLMChallengeAVPairs1UnicodeStr"].encode('utf-16le')
self.fields["NTLMSSPNTLMChallengeAVPairs2UnicodeStr"] = self.fields["NTLMSSPNTLMChallengeAVPairs2UnicodeStr"].encode('utf-16le')
self.fields["NTLMSSPNTLMChallengeAVPairs3UnicodeStr"] = self.fields["NTLMSSPNTLMChallengeAVPairs3UnicodeStr"].encode('utf-16le')
self.fields["NTLMSSPNTLMChallengeAVPairs5UnicodeStr"] = self.fields["NTLMSSPNTLMChallengeAVPairs5UnicodeStr"].encode('utf-16le')
###### Workstation Offset
CalculateOffsetWorkstation = str(self.fields["NTLMSSPSignature"])+str(self.fields["NTLMSSPSignatureNull"])+str(self.fields["NTLMSSPMessageType"])+str(self.fields["NTLMSSPNtWorkstationLen"])+str(self.fields["NTLMSSPNtWorkstationMaxLen"])+str(self.fields["NTLMSSPNtWorkstationBuffOffset"])+str(self.fields["NTLMSSPNtNegotiateFlags"])+str(self.fields["NTLMSSPNtServerChallenge"])+str(self.fields["NTLMSSPNtReserved"])+str(self.fields["NTLMSSPNtTargetInfoLen"])+str(self.fields["NTLMSSPNtTargetInfoMaxLen"])+str(self.fields["NTLMSSPNtTargetInfoBuffOffset"])+str(self.fields["NegTokenInitSeqMechMessageVersionHigh"])+str(self.fields["NegTokenInitSeqMechMessageVersionLow"])+str(self.fields["NegTokenInitSeqMechMessageVersionBuilt"])+str(self.fields["NegTokenInitSeqMechMessageVersionReserved"])+str(self.fields["NegTokenInitSeqMechMessageVersionNTLMType"])
###### AvPairs Offset
CalculateLenAvpairs = str(self.fields["NTLMSSPNTLMChallengeAVPairsId"])+str(self.fields["NTLMSSPNTLMChallengeAVPairsLen"])+str(self.fields["NTLMSSPNTLMChallengeAVPairsUnicodeStr"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs1Id"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs1Len"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs1UnicodeStr"])+(self.fields["NTLMSSPNTLMChallengeAVPairs2Id"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs2Len"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs2UnicodeStr"])+(self.fields["NTLMSSPNTLMChallengeAVPairs3Id"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs3Len"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs3UnicodeStr"])+(self.fields["NTLMSSPNTLMChallengeAVPairs5Id"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs5Len"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs5UnicodeStr"])+(self.fields["NTLMSSPNTLMChallengeAVPairs6Id"])+str(self.fields["NTLMSSPNTLMChallengeAVPairs6Len"])
###### LDAP Packet Len
CalculatePacketLen = str(self.fields["MessageIDASNID"])+str(self.fields["MessageIDASNLen"])+str(self.fields["MessageIDASNStr"])+str(self.fields["OpHeadASNID"])+str(self.fields["OpHeadASNIDLenOfLen"])+str(self.fields["OpHeadASNIDLen"])+str(self.fields["Status"])+str(self.fields["StatusASNLen"])+str(self.fields["StatusASNStr"])+str(self.fields["MatchedDN"])+str(self.fields["ErrorMessage"])+str(self.fields["SequenceHeader"])+str(self.fields["SequenceHeaderLen"])+str(self.fields["SequenceHeaderLenOfLen"])+CalculateOffsetWorkstation+str(self.fields["NTLMSSPNtWorkstationName"])+CalculateLenAvpairs
OperationPacketLen = str(self.fields["Status"])+str(self.fields["StatusASNLen"])+str(self.fields["StatusASNStr"])+str(self.fields["MatchedDN"])+str(self.fields["ErrorMessage"])+str(self.fields["SequenceHeader"])+str(self.fields["SequenceHeaderLen"])+str(self.fields["SequenceHeaderLenOfLen"])+CalculateOffsetWorkstation+str(self.fields["NTLMSSPNtWorkstationName"])+CalculateLenAvpairs
NTLMMessageLen = CalculateOffsetWorkstation+str(self.fields["NTLMSSPNtWorkstationName"])+CalculateLenAvpairs
##### LDAP Len Calculation:
self.fields["ParserHeadASNLen"] = struct.pack(">i", len(CalculatePacketLen))
self.fields["OpHeadASNIDLen"] = struct.pack(">i", len(OperationPacketLen))
self.fields["SequenceHeaderLen"] = struct.pack(">B", len(NTLMMessageLen))
##### Workstation Offset Calculation:
self.fields["NTLMSSPNtWorkstationBuffOffset"] = struct.pack("<i", len(CalculateOffsetWorkstation))
self.fields["NTLMSSPNtWorkstationLen"] = struct.pack("<h", len(str(self.fields["NTLMSSPNtWorkstationName"])))
self.fields["NTLMSSPNtWorkstationMaxLen"] = struct.pack("<h", len(str(self.fields["NTLMSSPNtWorkstationName"])))
##### IvPairs Offset Calculation:
self.fields["NTLMSSPNtTargetInfoBuffOffset"] = struct.pack("<i", len(CalculateOffsetWorkstation+str(self.fields["NTLMSSPNtWorkstationName"])))
self.fields["NTLMSSPNtTargetInfoLen"] = struct.pack("<h", len(CalculateLenAvpairs))
self.fields["NTLMSSPNtTargetInfoMaxLen"] = struct.pack("<h", len(CalculateLenAvpairs))
##### IvPair Calculation:
self.fields["NTLMSSPNTLMChallengeAVPairs5Len"] = struct.pack("<h", len(str(self.fields["NTLMSSPNTLMChallengeAVPairs5UnicodeStr"])))
self.fields["NTLMSSPNTLMChallengeAVPairs3Len"] = struct.pack("<h", len(str(self.fields["NTLMSSPNTLMChallengeAVPairs3UnicodeStr"])))
self.fields["NTLMSSPNTLMChallengeAVPairs2Len"] = struct.pack("<h", len(str(self.fields["NTLMSSPNTLMChallengeAVPairs2UnicodeStr"])))
self.fields["NTLMSSPNTLMChallengeAVPairs1Len"] = struct.pack("<h", len(str(self.fields["NTLMSSPNTLMChallengeAVPairs1UnicodeStr"])))
self.fields["NTLMSSPNTLMChallengeAVPairsLen"] = struct.pack("<h", len(str(self.fields["NTLMSSPNTLMChallengeAVPairsUnicodeStr"])))
|
gpl-3.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
653,
19162,
13,
2709,
15,
4464,
16237,
50,
3591,
23621,
199,
3,
18208,
701,
7964,
608,
343,
598,
27054,
69,
199,
3,
1898,
334,
35,
9,
6927,
377,
19622,
10024,
869,
1753,
780,
12,
3277,
14,
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,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2702,
199,
504,
312,
807,
492,
8773,
199,
199,
533,
31782,
837,
272,
1504,
275,
8773,
779,
267,
1689,
576,
401,
16241,
272,
4794,
272,
347,
636,
826,
721,
277,
12,
1011,
829,
304,
267,
291,
14,
955,
275,
8773,
8,
277,
855,
533,
4343,
955,
9,
267,
367,
1022,
12,
86,
315,
4775,
14,
1744,
837,
288,
340,
4550,
8,
86,
304,
355,
291,
14,
955,
59,
75,
61,
275,
373,
8,
277,
14,
955,
59,
75,
566,
288,
587,
26,
355,
291,
14,
955,
59,
75,
61,
275,
373,
272,
347,
636,
495,
721,
277,
304,
267,
372,
10587,
904,
8,
1130,
8,
495,
12,
291,
14,
955,
14,
1459,
4059,
421,
199,
533,
20717,
5278,
2698,
2726,
8,
2726,
304,
272,
1504,
275,
8773,
779,
267,
1689,
2842,
11664,
21696,
998,
401,
257,
1867,
88,
1216,
1288,
267,
1689,
2842,
11664,
21696,
3166,
401,
221,
1867,
88,
16,
67,
1288,
267,
1689,
2209,
998,
21696,
998,
401,
259,
1867,
88,
996,
1288,
267,
1689,
2209,
998,
21696,
3166,
401,
257,
1867,
88,
614,
1288,
267,
1689,
2209,
998,
1179,
2709,
454,
401,
257,
1867,
88,
16,
70,
1288,
267,
1689,
4619,
11664,
21696,
998,
401,
755,
1867,
88,
2182,
1288,
267,
1689,
4619,
11664,
21696,
998,
3166,
401,
259,
1867,
88,
1780,
1288,
267,
1689,
5278,
10759,
8300,
401,
1867,
88,
16,
33,
60,
88,
614,
60,
88,
383,
60,
88,
966,
60,
88,
383,
60,
88,
966,
60,
88,
383,
1288,
3,
1944,
24288,
14,
272,
4794,
199,
199,
533,
20717,
5278,
10682,
17006,
2726,
8,
2726,
304,
272,
1504,
275,
8773,
779,
267,
1689,
2842,
11664,
21696,
998,
401,
3515,
1867,
88,
1216,
1288,
267,
1689,
2842,
11664,
21696,
3166,
3466,
3166,
401,
259,
1867,
88,
1349,
1288,
267,
1689,
2842,
11664,
21696,
3166,
401,
260,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
23,
69,
1288,
3,
7957,
267,
1689,
2209,
998,
21696,
998,
401,
3698,
1867,
88,
996,
1288,
267,
1689,
2209,
998,
21696,
3166,
401,
3515,
1867,
88,
614,
1288,
267,
1689,
2209,
998,
1179,
2709,
454,
401,
3515,
1867,
88,
996,
1288,
267,
1689,
4619,
11664,
21696,
998,
401,
4519,
1867,
88,
772,
1288,
267,
1689,
4619,
11664,
21696,
998,
3166,
3466,
3166,
401,
420,
1867,
88,
1349,
1288,
267,
1689,
4619,
11664,
21696,
998,
3166,
401,
3698,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
2194,
1288,
3,
7362,
267,
1689,
10073,
401,
5185,
1867,
88,
966,
60,
88,
383,
1288,
267,
1689,
5278,
17937,
21696,
998,
401,
263,
1867,
88,
1216,
1288,
267,
1689,
5278,
17937,
21696,
3166,
3466,
3166,
401,
221,
1867,
88,
1349,
1288,
267,
1689,
5278,
17937,
21696,
3166,
401,
755,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
22,
68,
1288,
3,
6996,
267,
1689,
5278,
17937,
21696,
998,
17,
401,
755,
1867,
88,
1216,
1288,
267,
1689,
5278,
17937,
21696,
17,
3166,
3466,
3166,
401,
1867,
88,
1349,
1288,
267,
1689,
5278,
17937,
21696,
17,
3166,
401,
420,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1822,
1288,
3,
8845,
267,
1689,
5278,
17937,
21696,
18,
998,
401,
755,
1867,
88,
966,
1288,
267,
1689,
5278,
17937,
21696,
18,
3166,
401,
420,
1867,
88,
1046,
1288,
3,
2025,
267,
1689,
5278,
17937,
21696,
18,
2848,
401,
420,
298,
4946,
17006,
1288,
267,
1689,
5278,
17937,
21696,
19,
998,
401,
755,
1867,
88,
2192,
1288,
267,
1689,
5278,
17937,
21696,
19,
3166,
3466,
3166,
401,
1867,
88,
1349,
1288,
267,
1689,
5278,
17937,
21696,
19,
3166,
401,
420,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
20,
65,
1288,
267,
1689,
5278,
17937,
17,
21696,
998,
401,
755,
1867,
88,
966,
1288,
267,
1689,
5278,
17937,
17,
21696,
3166,
401,
420,
1867,
88,
975,
1288,
3,
1081,
267,
1689,
5278,
17937,
17,
1179,
2709,
454,
401,
420,
298,
17,
14,
18,
14,
13462,
14,
9225,
18683,
14,
17,
14,
20,
14,
6718,
1288,
267,
1689,
5278,
17937,
18,
21696,
998,
401,
755,
1867,
88,
966,
1288,
267,
1689,
5278,
17937,
18,
21696,
3166,
401,
420,
1867,
88,
1196,
1288,
3,
1789,
267,
1689,
5278,
17937,
18,
1179,
2709,
454,
401,
420,
298,
17,
14,
18,
14,
13462,
14,
9225,
18683,
14,
17,
14,
20,
14,
975,
2760,
1288,
267,
1689,
5278,
17937,
19,
21696,
998,
401,
755,
1867,
88,
966,
1288,
267,
1689,
5278,
17937,
19,
21696,
3166,
401,
420,
1867,
88,
1196,
1288,
3,
1789,
267,
1689,
5278,
17937,
19,
1179,
2709,
454,
401,
420,
298,
17,
14,
18,
14,
13462,
14,
9225,
18683,
14,
17,
14,
20,
14,
1196,
3328,
1288,
267,
1689,
5278,
10759,
21696,
998,
401,
3515,
1867,
88,
1216,
1288,
267,
1689,
5278,
10759,
21696,
3166,
3466,
3166,
401,
259,
1867,
88,
1349,
1288,
267,
1689,
5278,
10759,
21696,
3166,
401,
260,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
709,
1288,
3,
975,
267
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
653,
19162,
13,
2709,
15,
4464,
16237,
50,
3591,
23621,
199,
3,
18208,
701,
7964,
608,
343,
598,
27054,
69,
199,
3,
1898,
334,
35,
9,
6927,
377,
19622,
10024,
869,
1753,
780,
12,
3277,
14,
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,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2702,
199,
504,
312,
807,
492,
8773,
199,
199,
533,
31782,
837,
272,
1504,
275,
8773,
779,
267,
1689,
576,
401,
16241,
272,
4794,
272,
347,
636,
826,
721,
277,
12,
1011,
829,
304,
267,
291,
14,
955,
275,
8773,
8,
277,
855,
533,
4343,
955,
9,
267,
367,
1022,
12,
86,
315,
4775,
14,
1744,
837,
288,
340,
4550,
8,
86,
304,
355,
291,
14,
955,
59,
75,
61,
275,
373,
8,
277,
14,
955,
59,
75,
566,
288,
587,
26,
355,
291,
14,
955,
59,
75,
61,
275,
373,
272,
347,
636,
495,
721,
277,
304,
267,
372,
10587,
904,
8,
1130,
8,
495,
12,
291,
14,
955,
14,
1459,
4059,
421,
199,
533,
20717,
5278,
2698,
2726,
8,
2726,
304,
272,
1504,
275,
8773,
779,
267,
1689,
2842,
11664,
21696,
998,
401,
257,
1867,
88,
1216,
1288,
267,
1689,
2842,
11664,
21696,
3166,
401,
221,
1867,
88,
16,
67,
1288,
267,
1689,
2209,
998,
21696,
998,
401,
259,
1867,
88,
996,
1288,
267,
1689,
2209,
998,
21696,
3166,
401,
257,
1867,
88,
614,
1288,
267,
1689,
2209,
998,
1179,
2709,
454,
401,
257,
1867,
88,
16,
70,
1288,
267,
1689,
4619,
11664,
21696,
998,
401,
755,
1867,
88,
2182,
1288,
267,
1689,
4619,
11664,
21696,
998,
3166,
401,
259,
1867,
88,
1780,
1288,
267,
1689,
5278,
10759,
8300,
401,
1867,
88,
16,
33,
60,
88,
614,
60,
88,
383,
60,
88,
966,
60,
88,
383,
60,
88,
966,
60,
88,
383,
1288,
3,
1944,
24288,
14,
272,
4794,
199,
199,
533,
20717,
5278,
10682,
17006,
2726,
8,
2726,
304,
272,
1504,
275,
8773,
779,
267,
1689,
2842,
11664,
21696,
998,
401,
3515,
1867,
88,
1216,
1288,
267,
1689,
2842,
11664,
21696,
3166,
3466,
3166,
401,
259,
1867,
88,
1349,
1288,
267,
1689,
2842,
11664,
21696,
3166,
401,
260,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
23,
69,
1288,
3,
7957,
267,
1689,
2209,
998,
21696,
998,
401,
3698,
1867,
88,
996,
1288,
267,
1689,
2209,
998,
21696,
3166,
401,
3515,
1867,
88,
614,
1288,
267,
1689,
2209,
998,
1179,
2709,
454,
401,
3515,
1867,
88,
996,
1288,
267,
1689,
4619,
11664,
21696,
998,
401,
4519,
1867,
88,
772,
1288,
267,
1689,
4619,
11664,
21696,
998,
3166,
3466,
3166,
401,
420,
1867,
88,
1349,
1288,
267,
1689,
4619,
11664,
21696,
998,
3166,
401,
3698,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
2194,
1288,
3,
7362,
267,
1689,
10073,
401,
5185,
1867,
88,
966,
60,
88,
383,
1288,
267,
1689,
5278,
17937,
21696,
998,
401,
263,
1867,
88,
1216,
1288,
267,
1689,
5278,
17937,
21696,
3166,
3466,
3166,
401,
221,
1867,
88,
1349,
1288,
267,
1689,
5278,
17937,
21696,
3166,
401,
755,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
22,
68,
1288,
3,
6996,
267,
1689,
5278,
17937,
21696,
998,
17,
401,
755,
1867,
88,
1216,
1288,
267,
1689,
5278,
17937,
21696,
17,
3166,
3466,
3166,
401,
1867,
88,
1349,
1288,
267,
1689,
5278,
17937,
21696,
17,
3166,
401,
420,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
1822,
1288,
3,
8845,
267,
1689,
5278,
17937,
21696,
18,
998,
401,
755,
1867,
88,
966,
1288,
267,
1689,
5278,
17937,
21696,
18,
3166,
401,
420,
1867,
88,
1046,
1288,
3,
2025,
267,
1689,
5278,
17937,
21696,
18,
2848,
401,
420,
298,
4946,
17006,
1288,
267,
1689,
5278,
17937,
21696,
19,
998,
401,
755,
1867,
88,
2192,
1288,
267,
1689,
5278,
17937,
21696,
19,
3166,
3466,
3166,
401,
1867,
88,
1349,
1288,
267,
1689,
5278,
17937,
21696,
19,
3166,
401,
420,
1867,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
20,
65,
1288,
267,
1689,
5278,
17937,
17,
21696,
998,
401,
755,
1867,
88,
966,
1288,
267,
1689,
5278,
17937,
17,
21696,
3166,
401,
420,
1867,
88,
975,
1288,
3,
1081,
267,
1689,
5278,
17937,
17,
1179,
2709,
454,
401,
420,
298,
17,
14,
18,
14,
13462,
14,
9225,
18683,
14,
17,
14,
20,
14,
6718,
1288,
267,
1689,
5278,
17937,
18,
21696,
998,
401,
755,
1867,
88,
966,
1288,
267,
1689,
5278,
17937,
18,
21696,
3166,
401,
420,
1867,
88,
1196,
1288,
3,
1789,
267,
1689,
5278,
17937,
18,
1179,
2709,
454,
401,
420,
298,
17,
14,
18,
14,
13462,
14,
9225,
18683,
14,
17,
14,
20,
14,
975,
2760,
1288,
267,
1689,
5278,
17937,
19,
21696,
998,
401,
755,
1867,
88,
966,
1288,
267,
1689,
5278,
17937,
19,
21696,
3166,
401,
420,
1867,
88,
1196,
1288,
3,
1789,
267,
1689,
5278,
17937,
19,
1179,
2709,
454,
401,
420,
298,
17,
14,
18,
14,
13462,
14,
9225,
18683,
14,
17,
14,
20,
14,
1196,
3328,
1288,
267,
1689,
5278,
10759,
21696,
998,
401,
3515,
1867,
88,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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
] |
xshotD/pyglet
|
pyglet/input/evdev_constants.py
|
25
|
8529
|
#!/usr/bin/env python
'''Event constants from /usr/include/linux/input.h
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
EV_SYN = 0x00
EV_KEY = 0x01
EV_REL = 0x02
EV_ABS = 0x03
EV_MSC = 0x04
EV_LED = 0x11
EV_SND = 0x12
EV_REP = 0x14
EV_FF = 0x15
EV_PWR = 0x16
EV_FF_STATUS = 0x17
EV_MAX = 0x1f
# Synchronization events.
SYN_REPORT = 0
SYN_CONFIG = 1
# Keys and buttons
KEY_RESERVED = 0
KEY_ESC = 1
KEY_1 = 2
KEY_2 = 3
KEY_3 = 4
KEY_4 = 5
KEY_5 = 6
KEY_6 = 7
KEY_7 = 8
KEY_8 = 9
KEY_9 = 10
KEY_0 = 11
KEY_MINUS = 12
KEY_EQUAL = 13
KEY_BACKSPACE = 14
KEY_TAB = 15
KEY_Q = 16
KEY_W = 17
KEY_E = 18
KEY_R = 19
KEY_T = 20
KEY_Y = 21
KEY_U = 22
KEY_I = 23
KEY_O = 24
KEY_P = 25
KEY_LEFTBRACE = 26
KEY_RIGHTBRACE = 27
KEY_ENTER = 28
KEY_LEFTCTRL = 29
KEY_A = 30
KEY_S = 31
KEY_D = 32
KEY_F = 33
KEY_G = 34
KEY_H = 35
KEY_J = 36
KEY_K = 37
KEY_L = 38
KEY_SEMICOLON = 39
KEY_APOSTROPHE = 40
KEY_GRAVE = 41
KEY_LEFTSHIFT = 42
KEY_BACKSLASH = 43
KEY_Z = 44
KEY_X = 45
KEY_C = 46
KEY_V = 47
KEY_B = 48
KEY_N = 49
KEY_M = 50
KEY_COMMA = 51
KEY_DOT = 52
KEY_SLASH = 53
KEY_RIGHTSHIFT = 54
KEY_KPASTERISK = 55
KEY_LEFTALT = 56
KEY_SPACE = 57
KEY_CAPSLOCK = 58
KEY_F1 = 59
KEY_F2 = 60
KEY_F3 = 61
KEY_F4 = 62
KEY_F5 = 63
KEY_F6 = 64
KEY_F7 = 65
KEY_F8 = 66
KEY_F9 = 67
KEY_F10 = 68
KEY_NUMLOCK = 69
KEY_SCROLLLOCK = 70
KEY_KP7 = 71
KEY_KP8 = 72
KEY_KP9 = 73
KEY_KPMINUS = 74
KEY_KP4 = 75
KEY_KP5 = 76
KEY_KP6 = 77
KEY_KPPLUS = 78
KEY_KP1 = 79
KEY_KP2 = 80
KEY_KP3 = 81
KEY_KP0 = 82
KEY_KPDOT = 83
KEY_ZENKAKUHANKAKU = 85
KEY_102ND = 86
KEY_F11 = 87
KEY_F12 = 88
KEY_RO = 89
KEY_KATAKANA = 90
KEY_HIRAGANA = 91
KEY_HENKAN = 92
KEY_KATAKANAHIRAGANA = 93
KEY_MUHENKAN = 94
KEY_KPJPCOMMA = 95
KEY_KPENTER = 96
KEY_RIGHTCTRL = 97
KEY_KPSLASH = 98
KEY_SYSRQ = 99
KEY_RIGHTALT = 100
KEY_LINEFEED = 101
KEY_HOME = 102
KEY_UP = 103
KEY_PAGEUP = 104
KEY_LEFT = 105
KEY_RIGHT = 106
KEY_END = 107
KEY_DOWN = 108
KEY_PAGEDOWN = 109
KEY_INSERT = 110
KEY_DELETE = 111
KEY_MACRO = 112
KEY_MUTE = 113
KEY_VOLUMEDOWN = 114
KEY_VOLUMEUP = 115
KEY_POWER = 116
KEY_KPEQUAL = 117
KEY_KPPLUSMINUS = 118
KEY_PAUSE = 119
KEY_KPCOMMA = 121
KEY_HANGUEL = 122
KEY_HANJA = 123
KEY_YEN = 124
KEY_LEFTMETA = 125
KEY_RIGHTMETA = 126
KEY_COMPOSE = 127
KEY_STOP = 128
KEY_AGAIN = 129
KEY_PROPS = 130
KEY_UNDO = 131
KEY_FRONT = 132
KEY_COPY = 133
KEY_OPEN = 134
KEY_PASTE = 135
KEY_FIND = 136
KEY_CUT = 137
KEY_HELP = 138
KEY_MENU = 139
KEY_CALC = 140
KEY_SETUP = 141
KEY_SLEEP = 142
KEY_WAKEUP = 143
KEY_FILE = 144
KEY_SENDFILE = 145
KEY_DELETEFILE = 146
KEY_XFER = 147
KEY_PROG1 = 148
KEY_PROG2 = 149
KEY_WWW = 150
KEY_MSDOS = 151
KEY_COFFEE = 152
KEY_DIRECTION = 153
KEY_CYCLEWINDOWS = 154
KEY_MAIL = 155
KEY_BOOKMARKS = 156
KEY_COMPUTER = 157
KEY_BACK = 158
KEY_FORWARD = 159
KEY_CLOSECD = 160
KEY_EJECTCD = 161
KEY_EJECTCLOSECD = 162
KEY_NEXTSONG = 163
KEY_PLAYPAUSE = 164
KEY_PREVIOUSSONG = 165
KEY_STOPCD = 166
KEY_RECORD = 167
KEY_REWIND = 168
KEY_PHONE = 169
KEY_ISO = 170
KEY_CONFIG = 171
KEY_HOMEPAGE = 172
KEY_REFRESH = 173
KEY_EXIT = 174
KEY_MOVE = 175
KEY_EDIT = 176
KEY_SCROLLUP = 177
KEY_SCROLLDOWN = 178
KEY_KPLEFTPAREN = 179
KEY_KPRIGHTPAREN = 180
KEY_F13 = 183
KEY_F14 = 184
KEY_F15 = 185
KEY_F16 = 186
KEY_F17 = 187
KEY_F18 = 188
KEY_F19 = 189
KEY_F20 = 190
KEY_F21 = 191
KEY_F22 = 192
KEY_F23 = 193
KEY_F24 = 194
KEY_PLAYCD = 200
KEY_PAUSECD = 201
KEY_PROG3 = 202
KEY_PROG4 = 203
KEY_SUSPEND = 205
KEY_CLOSE = 206
KEY_PLAY = 207
KEY_FASTFORWARD = 208
KEY_BASSBOOST = 209
KEY_PRINT = 210
KEY_HP = 211
KEY_CAMERA = 212
KEY_SOUND = 213
KEY_QUESTION = 214
KEY_EMAIL = 215
KEY_CHAT = 216
KEY_SEARCH = 217
KEY_CONNECT = 218
KEY_FINANCE = 219
KEY_SPORT = 220
KEY_SHOP = 221
KEY_ALTERASE = 222
KEY_CANCEL = 223
KEY_BRIGHTNESSDOWN = 224
KEY_BRIGHTNESSUP = 225
KEY_MEDIA = 226
KEY_UNKNOWN = 240
BTN_MISC = 0x100
BTN_0 = 0x100
BTN_1 = 0x101
BTN_2 = 0x102
BTN_3 = 0x103
BTN_4 = 0x104
BTN_5 = 0x105
BTN_6 = 0x106
BTN_7 = 0x107
BTN_8 = 0x108
BTN_9 = 0x109
BTN_MOUSE = 0x110
BTN_LEFT = 0x110
BTN_RIGHT = 0x111
BTN_MIDDLE = 0x112
BTN_SIDE = 0x113
BTN_EXTRA = 0x114
BTN_FORWARD = 0x115
BTN_BACK = 0x116
BTN_TASK = 0x117
BTN_JOYSTICK = 0x120
BTN_TRIGGER = 0x120
BTN_THUMB = 0x121
BTN_THUMB2 = 0x122
BTN_TOP = 0x123
BTN_TOP2 = 0x124
BTN_PINKIE = 0x125
BTN_BASE = 0x126
BTN_BASE2 = 0x127
BTN_BASE3 = 0x128
BTN_BASE4 = 0x129
BTN_BASE5 = 0x12a
BTN_BASE6 = 0x12b
BTN_DEAD = 0x12f
BTN_GAMEPAD = 0x130
BTN_A = 0x130
BTN_B = 0x131
BTN_C = 0x132
BTN_X = 0x133
BTN_Y = 0x134
BTN_Z = 0x135
BTN_TL = 0x136
BTN_TR = 0x137
BTN_TL2 = 0x138
BTN_TR2 = 0x139
BTN_SELECT = 0x13a
BTN_START = 0x13b
BTN_MODE = 0x13c
BTN_THUMBL = 0x13d
BTN_THUMBR = 0x13e
BTN_DIGI = 0x140
BTN_TOOL_PEN = 0x140
BTN_TOOL_RUBBER = 0x141
BTN_TOOL_BRUSH = 0x142
BTN_TOOL_PENCIL = 0x143
BTN_TOOL_AIRBRUSH = 0x144
BTN_TOOL_FINGER = 0x145
BTN_TOOL_MOUSE = 0x146
BTN_TOOL_LENS = 0x147
BTN_TOUCH = 0x14a
BTN_STYLUS = 0x14b
BTN_STYLUS2 = 0x14c
BTN_TOOL_DOUBLETAP = 0x14d
BTN_TOOL_TRIPLETAP = 0x14e
BTN_WHEEL = 0x150
BTN_GEAR_DOWN = 0x150
BTN_GEAR_UP = 0x151
KEY_OK = 0x160
KEY_SELECT = 0x161
KEY_GOTO = 0x162
KEY_CLEAR = 0x163
KEY_POWER2 = 0x164
KEY_OPTION = 0x165
KEY_INFO = 0x166
KEY_TIME = 0x167
KEY_VENDOR = 0x168
KEY_ARCHIVE = 0x169
KEY_PROGRAM = 0x16a
KEY_CHANNEL = 0x16b
KEY_FAVORITES = 0x16c
KEY_EPG = 0x16d
KEY_PVR = 0x16e
KEY_MHP = 0x16f
KEY_LANGUAGE = 0x170
KEY_TITLE = 0x171
KEY_SUBTITLE = 0x172
KEY_ANGLE = 0x173
KEY_ZOOM = 0x174
KEY_MODE = 0x175
KEY_KEYBOARD = 0x176
KEY_SCREEN = 0x177
KEY_PC = 0x178
KEY_TV = 0x179
KEY_TV2 = 0x17a
KEY_VCR = 0x17b
KEY_VCR2 = 0x17c
KEY_SAT = 0x17d
KEY_SAT2 = 0x17e
KEY_CD = 0x17f
KEY_TAPE = 0x180
KEY_RADIO = 0x181
KEY_TUNER = 0x182
KEY_PLAYER = 0x183
KEY_TEXT = 0x184
KEY_DVD = 0x185
KEY_AUX = 0x186
KEY_MP3 = 0x187
KEY_AUDIO = 0x188
KEY_VIDEO = 0x189
KEY_DIRECTORY = 0x18a
KEY_LIST = 0x18b
KEY_MEMO = 0x18c
KEY_CALENDAR = 0x18d
KEY_RED = 0x18e
KEY_GREEN = 0x18f
KEY_YELLOW = 0x190
KEY_BLUE = 0x191
KEY_CHANNELUP = 0x192
KEY_CHANNELDOWN = 0x193
KEY_FIRST = 0x194
KEY_LAST = 0x195
KEY_AB = 0x196
KEY_NEXT = 0x197
KEY_RESTART = 0x198
KEY_SLOW = 0x199
KEY_SHUFFLE = 0x19a
KEY_BREAK = 0x19b
KEY_PREVIOUS = 0x19c
KEY_DIGITS = 0x19d
KEY_TEEN = 0x19e
KEY_TWEN = 0x19f
KEY_DEL_EOL = 0x1c0
KEY_DEL_EOS = 0x1c1
KEY_INS_LINE = 0x1c2
KEY_DEL_LINE = 0x1c3
KEY_FN = 0x1d0
KEY_FN_ESC = 0x1d1
KEY_FN_F1 = 0x1d2
KEY_FN_F2 = 0x1d3
KEY_FN_F3 = 0x1d4
KEY_FN_F4 = 0x1d5
KEY_FN_F5 = 0x1d6
KEY_FN_F6 = 0x1d7
KEY_FN_F7 = 0x1d8
KEY_FN_F8 = 0x1d9
KEY_FN_F9 = 0x1da
KEY_FN_F10 = 0x1db
KEY_FN_F11 = 0x1dc
KEY_FN_F12 = 0x1dd
KEY_FN_1 = 0x1de
KEY_FN_2 = 0x1df
KEY_FN_D = 0x1e0
KEY_FN_E = 0x1e1
KEY_FN_F = 0x1e2
KEY_FN_S = 0x1e3
KEY_FN_B = 0x1e4
KEY_MAX = 0x1ff
# Relative axes
REL_X = 0x00
REL_Y = 0x01
REL_Z = 0x02
REL_RX = 0x03
REL_RY = 0x04
REL_RZ = 0x05
REL_HWHEEL = 0x06
REL_DIAL = 0x07
REL_WHEEL = 0x08
REL_MISC = 0x09
REL_MAX = 0x0f
# Absolute axes
ABS_X = 0x00
ABS_Y = 0x01
ABS_Z = 0x02
ABS_RX = 0x03
ABS_RY = 0x04
ABS_RZ = 0x05
ABS_THROTTLE = 0x06
ABS_RUDDER = 0x07
ABS_WHEEL = 0x08
ABS_GAS = 0x09
ABS_BRAKE = 0x0a
ABS_HAT0X = 0x10
ABS_HAT0Y = 0x11
ABS_HAT1X = 0x12
ABS_HAT1Y = 0x13
ABS_HAT2X = 0x14
ABS_HAT2Y = 0x15
ABS_HAT3X = 0x16
ABS_HAT3Y = 0x17
ABS_PRESSURE = 0x18
ABS_DISTANCE = 0x19
ABS_TILT_X = 0x1a
ABS_TILT_Y = 0x1b
ABS_TOOL_WIDTH = 0x1c
ABS_VOLUME = 0x20
ABS_MISC = 0x28
ABS_MAX = 0x3f
# Misc events
MSC_SERIAL = 0x00
MSC_PULSELED = 0x01
MSC_GESTURE = 0x02
MSC_RAW = 0x03
MSC_SCAN = 0x04
MSC_MAX = 0x07
# LEDs
LED_NUML = 0x00
LED_CAPSL = 0x01
LED_SCROLLL = 0x02
LED_COMPOSE = 0x03
LED_KANA = 0x04
LED_SLEEP = 0x05
LED_SUSPEND = 0x06
LED_MUTE = 0x07
LED_MISC = 0x08
LED_MAIL = 0x09
LED_CHARGING = 0x0a
LED_MAX = 0x0f
# Autorepeat values
REP_DELAY = 0x00
REP_PERIOD = 0x01
REP_MAX = 0x01
# Sounds
SND_CLICK = 0x00
SND_BELL = 0x01
SND_TONE = 0x02
SND_MAX = 0x07
# IDs.
ID_BUS = 0
ID_VENDOR = 1
ID_PRODUCT = 2
ID_VERSION = 3
BUS_PCI = 0x01
BUS_ISAPNP = 0x02
BUS_USB = 0x03
BUS_HIL = 0x04
BUS_BLUETOOTH = 0x05
BUS_ISA = 0x10
BUS_I8042 = 0x11
BUS_XTKBD = 0x12
BUS_RS232 = 0x13
BUS_GAMEPORT = 0x14
BUS_PARPORT = 0x15
BUS_AMIGA = 0x16
BUS_ADB = 0x17
BUS_I2C = 0x18
BUS_HOST = 0x19
# Values describing the status of an effect
FF_STATUS_STOPPED = 0x00
FF_STATUS_PLAYING = 0x01
FF_STATUS_MAX = 0x01
_rel_raw_names = {}
_abs_raw_names = {}
_key_raw_names = {}
for _name, _val in locals().copy().items():
if _name.startswith('REL_'):
_rel_raw_names[_val] = _name
elif _name.startswith('ABS_'):
_abs_raw_names[_val] = _name
elif _name.startswith('KEY_') or _name.startswith('BTN_'):
_key_raw_names[_val] = _name
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
2390,
5262,
687,
1182,
2647,
15,
2613,
15,
5135,
15,
1210,
14,
72,
199,
2344,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
421,
199,
18015,
63,
31802,
275,
378,
88,
383,
199,
18015,
63,
3078,
275,
378,
88,
614,
199,
18015,
63,
13604,
275,
378,
88,
996,
199,
18015,
63,
27851,
275,
378,
88,
1644,
199,
18015,
63,
3053,
35,
275,
378,
88,
966,
199,
18015,
63,
5290,
275,
378,
88,
845,
199,
18015,
63,
8199,
36,
275,
378,
88,
713,
199,
18015,
63,
22554,
275,
378,
88,
1079,
199,
18015,
63,
1665,
275,
378,
88,
1046,
199,
18015,
63,
48,
6524,
275,
378,
88,
975,
199,
18015,
63,
1665,
63,
6305,
275,
378,
88,
1196,
199,
18015,
63,
4283,
275,
378,
88,
17,
70,
199,
199,
3,
428,
6030,
2072,
4474,
14,
199,
199,
31802,
63,
17356,
275,
378,
199,
31802,
63,
5569,
275,
413,
199,
199,
3,
17276,
436,
15766,
199,
199,
3078,
63,
26933,
275,
378,
199,
3078,
63,
654,
35,
275,
413,
199,
3078,
63,
17,
275,
499,
199,
3078,
63,
18,
275,
650,
199,
3078,
63,
19,
275,
841,
199,
3078,
63,
20,
275,
959,
199,
3078,
63,
21,
275,
1227,
199,
3078,
63,
22,
275,
1520,
199,
3078,
63,
23,
275,
1695,
199,
3078,
63,
24,
275,
1749,
199,
3078,
63,
25,
275,
1616,
199,
3078,
63,
16,
275,
4119,
199,
3078,
63,
18004,
275,
3144,
199,
3078,
63,
16352,
275,
4944,
199,
3078,
63,
7111,
11658,
275,
4329,
199,
3078,
63,
10129,
275,
4114,
199,
3078,
63,
49,
275,
3193,
199,
3078,
63,
55,
275,
5557,
199,
3078,
63,
37,
275,
6155,
199,
3078,
63,
50,
275,
5851,
199,
3078,
63,
52,
275,
3388,
199,
3078,
63,
57,
275,
7829,
199,
3078,
63,
53,
275,
6928,
199,
3078,
63,
41,
275,
6546,
199,
3078,
63,
47,
275,
5504,
199,
3078,
63,
48,
275,
5661,
199,
3078,
63,
9894,
29246,
275,
7875,
199,
3078,
63,
12811,
29246,
275,
8087,
199,
3078,
63,
12533,
275,
7294,
199,
3078,
63,
9894,
22584,
275,
7349,
199,
3078,
63,
33,
275,
4233,
199,
3078,
63,
51,
275,
7105,
199,
3078,
63,
36,
275,
4337,
199,
3078,
63,
38,
275,
9404,
199,
3078,
63,
39,
275,
8177,
199,
3078,
63,
40,
275,
8685,
199,
3078,
63,
42,
275,
8780,
199,
3078,
63,
43,
275,
6877,
199,
3078,
63,
44,
275,
10448,
199,
3078,
63,
899,
17233,
22670,
275,
10551,
199,
3078,
63,
1282,
47,
840,
30405,
275,
6335,
199,
3078,
63,
18583,
2524,
275,
13385,
199,
3078,
63,
9894,
18013,
275,
5685,
199,
3078,
63,
7111,
27192,
275,
11851,
199,
3078,
63,
58,
275,
10868,
199,
3078,
63,
56,
275,
10416,
199,
3078,
63,
35,
275,
12426,
199,
3078,
63,
54,
275,
10954,
199,
3078,
63,
34,
275,
9615,
199,
3078,
63,
46,
275,
12260,
199,
3078,
63,
45,
275,
5238,
199,
3078,
63,
11265,
2054,
275,
8026,
199,
3078,
63,
13203,
275,
14589,
199,
3078,
63,
27192,
275,
13564,
199,
3078,
63,
12811,
18013,
275,
13470,
199,
3078,
63,
43,
8470,
14471,
22481,
275,
12766,
199,
3078,
63,
9894,
19600,
275,
12001,
199,
3078,
63,
11658,
275,
12699,
199,
3078,
63,
8549,
51,
4406,
275,
13713,
199,
3078,
63,
38,
17,
275,
8155,
199,
3078,
63,
38,
18,
275,
5212,
199,
3078,
63,
38,
19,
275,
17017,
199,
3078,
63,
38,
20,
275,
16202,
199,
3078,
63,
38,
21,
275,
13668,
199,
3078,
63,
38,
22,
275,
5049,
199,
3078,
63,
38,
23,
275,
11738,
199,
3078,
63,
38,
24,
275,
14157,
199,
3078,
63,
38,
25,
275,
13296,
199,
3078,
63,
38,
709,
275,
10851,
199,
3078,
63,
7125,
4406,
275,
14610,
199,
3078,
63,
26315,
4406,
275,
10045,
199,
3078,
63,
24974,
23,
275,
17245,
199,
3078,
63,
24974,
24,
275,
15323,
199,
3078,
63,
24974,
25,
275,
18525,
199,
3078,
63,
24974,
18004,
275,
9720,
199,
3078,
63,
24974,
20,
275,
13098,
199,
3078,
63,
24974,
21,
275,
14646,
199,
3078,
63,
24974,
22,
275,
8375,
199,
3078,
63,
24974,
27280,
275,
14679,
199,
3078,
63,
24974,
17,
275,
13734,
199,
3078,
63,
24974,
18,
275,
5939,
199,
3078,
63,
24974,
19,
275,
19071,
199,
3078,
63,
24974,
16,
275,
18051,
199,
3078,
63,
43,
11435,
1387,
275,
20582,
199,
199,
3078,
63,
58,
742,
43,
7872,
53,
40,
15874,
7872,
53,
275,
16412,
199,
3078,
63,
7759,
8711,
275,
10300,
199,
3078,
63,
38,
845,
275,
10513,
199,
3078,
63,
38,
713,
275,
10523,
199,
3078,
63,
1092,
275,
17838,
199,
3078,
63,
43,
2751,
43,
879,
33,
275,
9137,
199,
3078,
63,
40,
3927,
1254,
879,
33,
275,
21358,
199,
3078,
63,
40,
742,
43,
879,
275,
20140,
199,
3078,
63,
43,
2751,
43,
879,
20755,
3927,
1254,
879,
33,
275,
18969,
199,
3078,
63,
45,
53,
40,
742,
43,
879,
275,
18729,
199,
3078,
63,
24974,
15819,
11265,
2054,
275,
16102,
199,
3078,
63,
24974,
12533,
275,
15580,
199,
3078,
63,
12811,
22584,
275,
15997,
199,
3078,
63,
24974,
27192,
275,
16096,
199,
3078,
63,
4669,
5943,
49,
275,
8806,
199,
3078,
63,
12811,
19600,
275,
2948,
199,
3078,
63,
6174,
18068,
275,
14313,
199,
3078,
63,
9524,
275,
12996,
199,
3078,
63,
2160,
275,
22363,
199,
3078,
63,
12898,
2160,
275,
21083,
199,
3078,
63,
9894,
275,
20462,
199,
3078,
63,
12811,
275,
23746,
199,
3078,
63,
3902,
275,
23543,
199,
3078,
63,
8819,
275,
24579,
199,
3078,
63,
48,
1254,
1149,
47,
3705,
275,
24058,
199,
3078,
63,
10258,
275,
16814,
199,
3078,
63,
7014,
275,
20128,
199,
3078,
63,
9410,
1092,
275,
20240,
199,
3078,
63,
45,
4586,
275,
24073,
199,
3078,
63,
12209,
2639,
1149,
47,
3705,
275,
23510,
199,
3078,
63,
16689,
2160,
275,
22560,
199,
3078,
63,
16064,
275,
25186,
199,
3078,
63,
43,
1510,
9283,
275,
26189,
199,
3078,
63,
24974,
27280,
18004,
275,
25760,
199,
3078,
63,
8470,
4701,
275,
26497,
199,
199,
3078,
63,
24974,
11265,
2054,
275,
26228,
199,
3078,
63,
40,
3986,
53,
2901,
275,
24557,
199,
3078,
63,
40,
879,
29849,
275,
11869,
199
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
2390,
5262,
687,
1182,
2647,
15,
2613,
15,
5135,
15,
1210,
14,
72,
199,
2344,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
421,
199,
18015,
63,
31802,
275,
378,
88,
383,
199,
18015,
63,
3078,
275,
378,
88,
614,
199,
18015,
63,
13604,
275,
378,
88,
996,
199,
18015,
63,
27851,
275,
378,
88,
1644,
199,
18015,
63,
3053,
35,
275,
378,
88,
966,
199,
18015,
63,
5290,
275,
378,
88,
845,
199,
18015,
63,
8199,
36,
275,
378,
88,
713,
199,
18015,
63,
22554,
275,
378,
88,
1079,
199,
18015,
63,
1665,
275,
378,
88,
1046,
199,
18015,
63,
48,
6524,
275,
378,
88,
975,
199,
18015,
63,
1665,
63,
6305,
275,
378,
88,
1196,
199,
18015,
63,
4283,
275,
378,
88,
17,
70,
199,
199,
3,
428,
6030,
2072,
4474,
14,
199,
199,
31802,
63,
17356,
275,
378,
199,
31802,
63,
5569,
275,
413,
199,
199,
3,
17276,
436,
15766,
199,
199,
3078,
63,
26933,
275,
378,
199,
3078,
63,
654,
35,
275,
413,
199,
3078,
63,
17,
275,
499,
199,
3078,
63,
18,
275,
650,
199,
3078,
63,
19,
275,
841,
199,
3078,
63,
20,
275,
959,
199,
3078,
63,
21,
275,
1227,
199,
3078,
63,
22,
275,
1520,
199,
3078,
63,
23,
275,
1695,
199,
3078,
63,
24,
275,
1749,
199,
3078,
63,
25,
275,
1616,
199,
3078,
63,
16,
275,
4119,
199,
3078,
63,
18004,
275,
3144,
199,
3078,
63,
16352,
275,
4944,
199,
3078,
63,
7111,
11658,
275,
4329,
199,
3078,
63,
10129,
275,
4114,
199,
3078,
63,
49,
275,
3193,
199,
3078,
63,
55,
275,
5557,
199,
3078,
63,
37,
275,
6155,
199,
3078,
63,
50,
275,
5851,
199,
3078,
63,
52,
275,
3388,
199,
3078,
63,
57,
275,
7829,
199,
3078,
63,
53,
275,
6928,
199,
3078,
63,
41,
275,
6546,
199,
3078,
63,
47,
275,
5504,
199,
3078,
63,
48,
275,
5661,
199,
3078,
63,
9894,
29246,
275,
7875,
199,
3078,
63,
12811,
29246,
275,
8087,
199,
3078,
63,
12533,
275,
7294,
199,
3078,
63,
9894,
22584,
275,
7349,
199,
3078,
63,
33,
275,
4233,
199,
3078,
63,
51,
275,
7105,
199,
3078,
63,
36,
275,
4337,
199,
3078,
63,
38,
275,
9404,
199,
3078,
63,
39,
275,
8177,
199,
3078,
63,
40,
275,
8685,
199,
3078,
63,
42,
275,
8780,
199,
3078,
63,
43,
275,
6877,
199,
3078,
63,
44,
275,
10448,
199,
3078,
63,
899,
17233,
22670,
275,
10551,
199,
3078,
63,
1282,
47,
840,
30405,
275,
6335,
199,
3078,
63,
18583,
2524,
275,
13385,
199,
3078,
63,
9894,
18013,
275,
5685,
199,
3078,
63,
7111,
27192,
275,
11851,
199,
3078,
63,
58,
275,
10868,
199,
3078,
63,
56,
275,
10416,
199,
3078,
63,
35,
275,
12426,
199,
3078,
63,
54,
275,
10954,
199,
3078,
63,
34,
275,
9615,
199,
3078,
63,
46,
275,
12260,
199,
3078,
63,
45,
275,
5238,
199,
3078,
63,
11265,
2054,
275,
8026,
199,
3078,
63,
13203,
275,
14589,
199,
3078,
63,
27192,
275,
13564,
199,
3078,
63,
12811,
18013,
275,
13470,
199,
3078,
63,
43,
8470,
14471,
22481,
275,
12766,
199,
3078,
63,
9894,
19600,
275,
12001,
199,
3078,
63,
11658,
275,
12699,
199,
3078,
63,
8549,
51,
4406,
275,
13713,
199,
3078,
63,
38,
17,
275,
8155,
199,
3078,
63,
38,
18,
275,
5212,
199,
3078,
63,
38,
19,
275,
17017,
199,
3078,
63,
38,
20,
275,
16202,
199,
3078,
63,
38,
21,
275,
13668,
199,
3078,
63,
38,
22,
275,
5049,
199,
3078,
63,
38,
23,
275,
11738,
199,
3078,
63,
38,
24,
275,
14157,
199,
3078,
63,
38,
25,
275,
13296,
199,
3078,
63,
38,
709,
275,
10851,
199,
3078,
63,
7125,
4406,
275,
14610,
199,
3078,
63,
26315,
4406,
275,
10045,
199,
3078,
63,
24974,
23,
275,
17245,
199,
3078,
63,
24974,
24,
275,
15323,
199,
3078,
63,
24974,
25,
275,
18525,
199,
3078,
63,
24974,
18004,
275,
9720,
199,
3078,
63,
24974,
20,
275,
13098,
199,
3078,
63,
24974,
21,
275,
14646,
199,
3078,
63,
24974,
22,
275,
8375,
199,
3078,
63,
24974,
27280,
275,
14679,
199,
3078,
63,
24974,
17,
275,
13734,
199,
3078,
63,
24974,
18,
275,
5939,
199,
3078,
63,
24974,
19,
275,
19071,
199,
3078,
63,
24974,
16,
275,
18051,
199,
3078,
63,
43,
11435,
1387,
275,
20582,
199,
199,
3078,
63,
58,
742,
43,
7872,
53,
40,
15874,
7872,
53,
275,
16412,
199,
3078,
63,
7759,
8711,
275,
10300,
199,
3078,
63,
38,
845,
275,
10513,
199,
3078,
63,
38,
713,
275,
10523,
199,
3078,
63,
1092,
275,
17838,
199,
3078,
63,
43,
2751,
43,
879,
33,
275,
9137,
199,
3078,
63,
40,
3927,
1254,
879,
33,
275,
21358,
199,
3078,
63,
40,
742,
43,
879,
275,
20140,
199,
3078,
63,
43,
2751,
43,
879,
20755,
3927,
1254,
879,
33,
275,
18969,
199,
3078,
63,
45,
53,
40,
742,
43,
879,
275,
18729,
199,
3078,
63,
24974,
15819,
11265,
2054,
275,
16102,
199,
3078,
63,
24974,
12533,
275,
15580,
199,
3078,
63,
12811,
22584,
275,
15997,
199,
3078,
63,
24974,
27192,
275,
16096,
199,
3078,
63,
4669,
5943,
49,
275,
8806,
199,
3078,
63,
12811,
19600,
275,
2948,
199,
3078,
63,
6174,
18068,
275,
14313,
199,
3078,
63,
9524,
275,
12996,
199,
3078,
63,
2160,
275,
22363,
199,
3078,
63,
12898,
2160,
275,
21083,
199,
3078,
63,
9894,
275,
20462,
199,
3078,
63,
12811,
275,
23746,
199,
3078,
63,
3902,
275,
23543,
199,
3078,
63,
8819,
275,
24579,
199,
3078,
63,
48,
1254,
1149,
47,
3705,
275,
24058,
199,
3078,
63,
10258,
275,
16814,
199,
3078,
63,
7014,
275,
20128,
199,
3078,
63,
9410,
1092,
275,
20240,
199,
3078,
63,
45,
4586,
275,
24073,
199,
3078,
63,
12209,
2639,
1149,
47,
3705,
275,
23510,
199,
3078,
63,
16689,
2160,
275,
22560,
199,
3078,
63,
16064,
275,
25186,
199,
3078,
63,
43,
1510,
9283,
275,
26189,
199,
3078,
63,
24974,
27280,
18004,
275,
25760,
199,
3078,
63,
8470,
4701,
275,
26497,
199,
199,
3078,
63,
24974,
11265,
2054,
275,
26228,
199,
3078,
63,
40,
3986,
53,
2901,
275,
24557,
199,
3078,
63,
40,
879,
29849,
275,
11869,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
tuomas2/automate
|
src/automate/extensions/arduino/arduino_actuators.py
|
1
|
6343
|
# -*- coding: utf-8 -*-
# (c) 2015 Tuomas Airaksinen
#
# This file is part of automate-arduino.
#
# automate-arduino 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.
#
# automate-arduino 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 automate-arduino. If not, see <http://www.gnu.org/licenses/>.
from traits.api import CInt, Instance, CBool, CFloat, CStr
import pyfirmata
from automate.actuators import FloatActuator
from automate.service import AbstractSystemService
from automate.statusobject import AbstractActuator
from . import arduino_service
class AbstractArduinoActuator(AbstractActuator):
"""
Abstract base class for Arduino actuators
"""
#: Arduino service number (specify, if more than 1 ArduinoService are configured in the system)
service = CInt(0)
#: Arduino pin number
pin = CInt
_arduino = Instance(AbstractSystemService, transient=True)
view = AbstractActuator.view + ["pin"]
simple_view = AbstractActuator.simple_view + ["pin"]
def setup(self, *args, **kwargs):
super().setup(*args, **kwargs)
self.logger.debug('Arduino actuator setup')
self._arduino = self.system.request_service('ArduinoService', self.service)
class ArduinoDigitalActuator(AbstractArduinoActuator):
"""
Boolean-valued actuator object for digital Arduino output pins
"""
_status = CBool(transient=True)
def setup(self, *args, **kwargs):
super().setup(*args, **kwargs)
self._arduino.setup_digital(self.pin)
def _status_changed(self):
self._arduino.change_digital(self.pin, self._status)
def cleanup(self):
self._arduino.cleanup_digital_actuator(self.pin)
class ArduinoLCDActuator(AbstractArduinoActuator):
"""
Actuator that sends target device digital output pin status change requests
Needs `AutomateFirmata <https://github.com/tuomas2/AutomateFirmata>`_
"""
_status = CStr(transient=True)
#: Target device number
device = CInt
def _status_changed(self):
self._arduino.lcd_print(self._status)
class ArduinoRemoteDigitalActuator(AbstractArduinoActuator):
"""
Actuator that sends target device digital output pin status change requests
Needs `AutomateFirmata <https://github.com/tuomas2/AutomateFirmata>`_
"""
_status = CBool(transient=True)
#: Target device number
device = CInt
def setup(self, *args, **kwargs):
super().setup(*args, **kwargs)
self._arduino.send_virtualwire_command(self.device,
arduino_service.VIRTUALWIRE_SET_PIN_MODE,
self.pin,
pyfirmata.OUTPUT)
def _status_changed(self):
self._arduino.send_virtualwire_command(self.device,
arduino_service.VIRTUALWIRE_SET_DIGITAL_PIN_VALUE,
self.pin,
self.status)
class ArduinoRemotePWMActuator(AbstractArduinoActuator):
"""
Actuator that sends target device analog (PWM) output pin status change requests
Needs `AutomateFirmata <https://github.com/tuomas2/AutomateFirmata>`_
"""
_status = CFloat(transient=True)
#: Target device number
device = CInt
def setup(self, *args, **kwargs):
super().setup(*args, **kwargs)
self._arduino.send_virtualwire_command(self.device,
arduino_service.VIRTUALWIRE_SET_PIN_MODE,
self.pin,
pyfirmata.PWM)
def _status_changed(self):
value = min(max(self.status, 0.), 1.)
value = int(round(value * 255)) # Arduino PWM has 8 bit resolution
self._arduino.send_virtualwire_command(self.device,
arduino_service.VIRTUALWIRE_ANALOG_MESSAGE,
self.pin,
value)
class ArduinoServoActuator(AbstractArduinoActuator):
"""
Float-valued actuator object for Arduino output pins that can be configured in Servo mode
Status is servo angle (0-360).
"""
_status = CFloat(transient=True)
#: Minimum pulse time (in microseconds)
min_pulse = CInt(544)
#: Maximum pulse time (in microseconds)
max_pulse = CInt(2400)
def _min_pulse_changed(self):
if self.traits_inited():
self.setup()
def _max_pulse_changed(self):
if self.traits_inited():
self.setup()
def setup(self, *args, **kwargs):
super().setup(*args, **kwargs)
self.logger.debug("setup_servo %s %s %s %s %s %s", self, self.service, self.pin, self.min_pulse, self.max_pulse,
int(round(self._status)))
self._arduino.setup_servo(self.pin, self.min_pulse, self.max_pulse, int(round(self._status)))
def _status_changed(self):
self.logger.debug("change_servo %s %s %s", self.pin, int(round(self._status)))
self._arduino.change_digital(self.pin, int(round(self._status)))
def cleanup(self):
self._arduino.cleanup_digital_actuator(self.pin)
class ArduinoPWMActuator(FloatActuator, AbstractArduinoActuator):
"""
Float-valued actuator object for Arduino output pins that can be configured in PWM mode
Status is float between 0.0 and 1.0.
"""
def setup(self, *args, **kwargs):
super().setup(*args, **kwargs)
self._arduino.setup_pwm(self.pin)
def _status_changed(self):
self._arduino.change_digital(self.pin, max(0., min(1., self._status)))
def cleanup(self):
self._arduino.cleanup_digital_actuator(self.pin)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
334,
67,
9,
6900,
377,
7519,
305,
437,
20936,
75,
5911,
287,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
6384,
676,
323,
13,
1005,
85,
10175,
14,
199,
3,
199,
3,
6384,
676,
323,
13,
1005,
85,
10175,
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,
6384,
676,
323,
13,
1005,
85,
10175,
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,
6384,
676,
323,
13,
1005,
85,
10175,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
19692,
14,
1246,
492,
445,
3241,
12,
10066,
12,
445,
10349,
12,
445,
5136,
12,
445,
2848,
199,
199,
646,
1134,
6022,
419,
199,
199,
504,
6384,
676,
323,
14,
2442,
85,
2750,
492,
11140,
19348,
16530,
199,
504,
6384,
676,
323,
14,
1364,
492,
11836,
3989,
3167,
199,
504,
6384,
676,
323,
14,
1205,
785,
492,
11836,
19348,
16530,
199,
504,
1275,
492,
601,
2033,
10175,
63,
1364,
421,
199,
533,
11836,
31924,
10175,
19348,
16530,
8,
8458,
19348,
16530,
304,
272,
408,
267,
11836,
1300,
1021,
367,
1952,
2033,
10175,
2454,
85,
2750,
272,
408,
339,
6079,
1952,
2033,
10175,
2435,
1329,
334,
26164,
12,
340,
1655,
2419,
413,
1952,
2033,
10175,
3167,
787,
7526,
315,
314,
2656,
9,
272,
2435,
275,
445,
3241,
8,
16,
9,
339,
6079,
1952,
2033,
10175,
10713,
1329,
272,
10713,
275,
445,
3241,
339,
485,
1005,
85,
10175,
275,
10066,
8,
8458,
3989,
3167,
12,
7115,
14928,
29,
549,
9,
339,
2455,
275,
11836,
19348,
16530,
14,
1345,
435,
2097,
7751,
937,
272,
3486,
63,
1345,
275,
11836,
19348,
16530,
14,
4129,
63,
1345,
435,
2097,
7751,
937,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1252,
2758,
2031,
589,
12,
1011,
958,
9,
267,
291,
14,
2921,
14,
1757,
360,
31924,
10175,
2454,
16530,
3272,
358,
267,
291,
423,
1005,
85,
10175,
275,
291,
14,
2253,
14,
1069,
63,
1364,
360,
31924,
10175,
3167,
297,
291,
14,
1364,
9,
421,
199,
533,
1952,
2033,
10175,
32660,
19348,
16530,
8,
8458,
31924,
10175,
19348,
16530,
304,
272,
408,
267,
9411,
13,
16611,
2454,
16530,
909,
367,
20545,
1952,
2033,
10175,
1072,
30541,
272,
408,
272,
485,
1205,
275,
445,
10349,
8,
23387,
29,
549,
9,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1252,
2758,
2031,
589,
12,
1011,
958,
9,
267,
291,
423,
1005,
85,
10175,
14,
2758,
63,
25888,
8,
277,
14,
7751,
9,
339,
347,
485,
1205,
63,
2489,
8,
277,
304,
267,
291,
423,
1005,
85,
10175,
14,
1461,
63,
25888,
8,
277,
14,
7751,
12,
291,
423,
1205,
9,
339,
347,
9058,
8,
277,
304,
267,
291,
423,
1005,
85,
10175,
14,
7661,
63,
25888,
63,
2442,
16530,
8,
277,
14,
7751,
9,
421,
199,
533,
1952,
2033,
10175,
7027,
8980,
319,
16530,
8,
8458,
31924,
10175,
19348,
16530,
304,
272,
408,
267,
18982,
16530,
626,
16178,
1347,
2243,
20545,
1072,
10713,
2004,
1570,
4145,
398,
29613,
658,
23570,
676,
323,
38,
18698,
419,
665,
2859,
921,
5031,
14,
957,
15,
84,
7519,
305,
18,
15,
23570,
676,
323,
38,
18698,
419,
18740,
272,
408,
339,
485,
1205,
275,
445,
2848,
8,
23387,
29,
549,
9,
339,
6079,
10256,
2243,
1329,
272,
2243,
275,
445,
3241,
339,
347,
485,
1205,
63,
2489,
8,
277,
304,
267,
291,
423,
1005,
85,
10175,
14,
31670,
63,
1361,
8,
277,
423,
1205,
9,
421,
199,
533,
1952,
2033,
10175,
6713,
32660,
19348,
16530,
8,
8458,
31924,
10175,
19348,
16530,
304,
272,
408,
267,
18982,
16530,
626,
16178,
1347,
2243,
20545,
1072,
10713,
2004,
1570,
4145,
398,
29613,
658,
23570,
676,
323,
38,
18698,
419,
665,
2859,
921,
5031,
14,
957,
15,
84,
7519,
305,
18,
15,
23570,
676,
323,
38,
18698,
419,
18740,
272,
408,
339,
485,
1205,
275,
445,
10349,
8,
23387,
29,
549,
9,
339,
6079,
10256,
2243,
1329,
272,
2243,
275,
445,
3241,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1252,
2758,
2031,
589,
12,
1011,
958,
9,
267,
291,
423,
1005,
85,
10175,
14,
2254,
63,
2065,
11239,
63,
1531,
8,
277,
14,
1782,
12,
6901,
601,
2033,
10175,
63,
1364,
14,
25618,
18759,
907,
63,
3597,
63,
30929,
63,
6963,
12,
6901,
291,
14,
7751,
12,
6901,
1134,
6022,
419,
14,
8414,
9,
339,
347,
485,
1205,
63,
2489,
8,
277,
304,
267,
291,
423,
1005,
85,
10175,
14,
2254,
63,
2065,
11239,
63,
1531,
8,
277,
14,
1782,
12,
6901,
601,
2033,
10175,
63,
1364,
14,
25618,
18759,
907,
63,
3597,
63,
36,
6995,
748,
63,
30929,
63,
7041,
12,
6901,
291,
14,
7751,
12,
6901,
291,
14,
1205,
9,
421,
199,
533,
1952,
2033,
10175,
6713,
10780,
2054,
319,
16530,
8,
8458,
31924,
10175,
19348,
16530,
304,
272,
408,
267,
18982,
16530,
626,
16178,
1347,
2243,
20439,
334,
10780,
45,
9,
1072,
10713,
2004,
1570,
4145,
398,
29613,
658,
23570,
676,
323,
38,
18698,
419,
665,
2859,
921,
5031,
14,
957,
15,
84,
7519,
305,
18,
15,
23570,
676,
323,
38,
18698,
419,
18740,
272,
408,
339,
485,
1205,
275,
445,
5136,
8,
23387,
29,
549,
9,
339,
6079,
10256,
2243,
1329,
272,
2243,
275,
445,
3241,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1252,
2758,
2031,
589,
12,
1011,
958,
9,
267,
291,
423,
1005,
85,
10175,
14,
2254,
63,
2065,
11239
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
334,
67,
9,
6900,
377,
7519,
305,
437,
20936,
75,
5911,
287,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
6384,
676,
323,
13,
1005,
85,
10175,
14,
199,
3,
199,
3,
6384,
676,
323,
13,
1005,
85,
10175,
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,
6384,
676,
323,
13,
1005,
85,
10175,
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,
6384,
676,
323,
13,
1005,
85,
10175,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
19692,
14,
1246,
492,
445,
3241,
12,
10066,
12,
445,
10349,
12,
445,
5136,
12,
445,
2848,
199,
199,
646,
1134,
6022,
419,
199,
199,
504,
6384,
676,
323,
14,
2442,
85,
2750,
492,
11140,
19348,
16530,
199,
504,
6384,
676,
323,
14,
1364,
492,
11836,
3989,
3167,
199,
504,
6384,
676,
323,
14,
1205,
785,
492,
11836,
19348,
16530,
199,
504,
1275,
492,
601,
2033,
10175,
63,
1364,
421,
199,
533,
11836,
31924,
10175,
19348,
16530,
8,
8458,
19348,
16530,
304,
272,
408,
267,
11836,
1300,
1021,
367,
1952,
2033,
10175,
2454,
85,
2750,
272,
408,
339,
6079,
1952,
2033,
10175,
2435,
1329,
334,
26164,
12,
340,
1655,
2419,
413,
1952,
2033,
10175,
3167,
787,
7526,
315,
314,
2656,
9,
272,
2435,
275,
445,
3241,
8,
16,
9,
339,
6079,
1952,
2033,
10175,
10713,
1329,
272,
10713,
275,
445,
3241,
339,
485,
1005,
85,
10175,
275,
10066,
8,
8458,
3989,
3167,
12,
7115,
14928,
29,
549,
9,
339,
2455,
275,
11836,
19348,
16530,
14,
1345,
435,
2097,
7751,
937,
272,
3486,
63,
1345,
275,
11836,
19348,
16530,
14,
4129,
63,
1345,
435,
2097,
7751,
937,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1252,
2758,
2031,
589,
12,
1011,
958,
9,
267,
291,
14,
2921,
14,
1757,
360,
31924,
10175,
2454,
16530,
3272,
358,
267,
291,
423,
1005,
85,
10175,
275,
291,
14,
2253,
14,
1069,
63,
1364,
360,
31924,
10175,
3167,
297,
291,
14,
1364,
9,
421,
199,
533,
1952,
2033,
10175,
32660,
19348,
16530,
8,
8458,
31924,
10175,
19348,
16530,
304,
272,
408,
267,
9411,
13,
16611,
2454,
16530,
909,
367,
20545,
1952,
2033,
10175,
1072,
30541,
272,
408,
272,
485,
1205,
275,
445,
10349,
8,
23387,
29,
549,
9,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1252,
2758,
2031,
589,
12,
1011,
958,
9,
267,
291,
423,
1005,
85,
10175,
14,
2758,
63,
25888,
8,
277,
14,
7751,
9,
339,
347,
485,
1205,
63,
2489,
8,
277,
304,
267,
291,
423,
1005,
85,
10175,
14,
1461,
63,
25888,
8,
277,
14,
7751,
12,
291,
423,
1205,
9,
339,
347,
9058,
8,
277,
304,
267,
291,
423,
1005,
85,
10175,
14,
7661,
63,
25888,
63,
2442,
16530,
8,
277,
14,
7751,
9,
421,
199,
533,
1952,
2033,
10175,
7027,
8980,
319,
16530,
8,
8458,
31924,
10175,
19348,
16530,
304,
272,
408,
267,
18982,
16530,
626,
16178,
1347,
2243,
20545,
1072,
10713,
2004,
1570,
4145,
398,
29613,
658,
23570,
676,
323,
38,
18698,
419,
665,
2859,
921,
5031,
14,
957,
15,
84,
7519,
305,
18,
15,
23570,
676,
323,
38,
18698,
419,
18740,
272,
408,
339,
485,
1205,
275,
445,
2848,
8,
23387,
29,
549,
9,
339,
6079,
10256,
2243,
1329,
272,
2243,
275,
445,
3241,
339,
347,
485,
1205,
63,
2489,
8,
277,
304,
267,
291,
423,
1005,
85,
10175,
14,
31670,
63,
1361,
8,
277,
423,
1205,
9,
421,
199,
533,
1952,
2033,
10175,
6713,
32660,
19348,
16530,
8,
8458,
31924,
10175,
19348,
16530,
304,
272,
408,
267,
18982,
16530,
626,
16178,
1347,
2243,
20545,
1072,
10713,
2004,
1570,
4145,
398,
29613,
658,
23570,
676,
323,
38,
18698,
419,
665,
2859,
921,
5031,
14,
957,
15,
84,
7519,
305,
18,
15,
23570,
676,
323,
38,
18698,
419,
18740,
272,
408,
339,
485,
1205,
275,
445,
10349,
8,
23387,
29,
549,
9,
339,
6079,
10256,
2243,
1329,
272,
2243,
275,
445,
3241,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1252,
2758,
2031,
589,
12,
1011,
958,
9,
267,
291,
423,
1005,
85,
10175,
14,
2254,
63,
2065,
11239,
63,
1531,
8,
277,
14,
1782,
12,
6901,
601,
2033,
10175,
63,
1364,
14,
25618,
18759,
907,
63,
3597,
63,
30929,
63,
6963,
12,
6901,
291,
14,
7751,
12,
6901,
1134,
6022,
419,
14,
8414,
9,
339,
347,
485,
1205,
63,
2489,
8,
277,
304,
267,
291,
423,
1005,
85,
10175,
14,
2254,
63,
2065,
11239,
63,
1531,
8,
277,
14,
1782,
12,
6901,
601,
2033,
10175,
63,
1364,
14,
25618,
18759,
907,
63,
3597,
63,
36,
6995,
748,
63,
30929,
63,
7041,
12,
6901,
291,
14,
7751,
12,
6901,
291,
14,
1205,
9,
421,
199,
533,
1952,
2033,
10175,
6713,
10780,
2054,
319,
16530,
8,
8458,
31924,
10175,
19348,
16530,
304,
272,
408,
267,
18982,
16530,
626,
16178,
1347,
2243,
20439,
334,
10780,
45,
9,
1072,
10713,
2004,
1570,
4145,
398,
29613,
658,
23570,
676,
323,
38,
18698,
419,
665,
2859,
921,
5031,
14,
957,
15,
84,
7519,
305,
18,
15,
23570,
676,
323,
38,
18698,
419,
18740,
272,
408,
339,
485,
1205,
275,
445,
5136,
8,
23387,
29,
549,
9,
339,
6079,
10256,
2243,
1329,
272,
2243,
275,
445,
3241,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
1252,
2758,
2031,
589,
12,
1011,
958,
9,
267,
291,
423,
1005,
85,
10175,
14,
2254,
63,
2065,
11239,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wsp/git
|
contrib/fast-import/import-zips.py
|
47
|
1848
|
#!/usr/bin/env python
## zip archive frontend for git-fast-import
##
## For example:
##
## mkdir project; cd project; git init
## python import-zips.py *.zip
## git log --stat import-zips
from os import popen, path
from sys import argv, exit
from time import mktime
from zipfile import ZipFile
if len(argv) < 2:
print 'Usage:', argv[0], '<zipfile>...'
exit(1)
branch_ref = 'refs/heads/import-zips'
committer_name = 'Z Ip Creator'
committer_email = 'zip@example.com'
fast_import = popen('git fast-import --quiet', 'w')
def printlines(list):
for str in list:
fast_import.write(str + "\n")
for zipfile in argv[1:]:
commit_time = 0
next_mark = 1
common_prefix = None
mark = dict()
zip = ZipFile(zipfile, 'r')
for name in zip.namelist():
if name.endswith('/'):
continue
info = zip.getinfo(name)
if commit_time < info.date_time:
commit_time = info.date_time
if common_prefix == None:
common_prefix = name[:name.rfind('/') + 1]
else:
while not name.startswith(common_prefix):
last_slash = common_prefix[:-1].rfind('/') + 1
common_prefix = common_prefix[:last_slash]
mark[name] = ':' + str(next_mark)
next_mark += 1
printlines(('blob', 'mark ' + mark[name], \
'data ' + str(info.file_size)))
fast_import.write(zip.read(name) + "\n")
committer = committer_name + ' <' + committer_email + '> %d +0000' % \
mktime(commit_time + (0, 0, 0))
printlines(('commit ' + branch_ref, 'committer ' + committer, \
'data <<EOM', 'Imported from ' + zipfile + '.', 'EOM', \
'', 'deleteall'))
for name in mark.keys():
fast_import.write('M 100644 ' + mark[name] + ' ' +
name[len(common_prefix):] + "\n")
printlines(('', 'tag ' + path.basename(zipfile), \
'from ' + branch_ref, 'tagger ' + committer, \
'data <<EOM', 'Package ' + zipfile, 'EOM', ''))
if fast_import.close():
exit(1)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
309,
3482,
6359,
22523,
367,
6135,
13,
7015,
13,
646,
199,
309,
199,
309,
2104,
2893,
26,
199,
309,
199,
309,
221,
20366,
2199,
27,
12829,
2199,
27,
6135,
4205,
199,
309,
221,
2366,
492,
13,
3065,
83,
14,
647,
23588,
3065,
199,
309,
221,
6135,
943,
1553,
3736,
492,
13,
3065,
83,
199,
199,
504,
747,
492,
17758,
12,
931,
199,
504,
984,
492,
9238,
12,
4458,
199,
504,
900,
492,
9199,
521,
199,
504,
10392,
492,
26755,
199,
199,
692,
822,
8,
3020,
9,
665,
499,
26,
199,
198,
1361,
283,
7692,
6536,
9238,
59,
16,
467,
2650,
18717,
30,
13698,
199,
198,
2224,
8,
17,
9,
199,
199,
4694,
63,
1121,
275,
283,
7655,
15,
17033,
15,
646,
13,
3065,
83,
7,
199,
3543,
351,
63,
354,
275,
283,
58,
31045,
9750,
707,
7,
199,
3543,
351,
63,
2123,
275,
283,
3065,
32,
2694,
14,
957,
7,
199,
199,
7015,
63,
646,
275,
17758,
360,
3187,
7377,
13,
646,
1553,
10243,
297,
283,
87,
358,
199,
318,
870,
1278,
8,
513,
304,
199,
198,
509,
620,
315,
769,
26,
507,
198,
7015,
63,
646,
14,
952,
8,
495,
435,
1867,
78,
531,
199,
199,
509,
10392,
315,
9238,
59,
17,
10688,
199,
198,
3543,
63,
521,
275,
378,
199,
198,
2184,
63,
1657,
275,
413,
199,
198,
2330,
63,
1861,
275,
488,
199,
198,
1657,
275,
1211,
342,
421,
198,
3065,
275,
26755,
8,
18717,
12,
283,
82,
358,
199,
198,
509,
536,
315,
3482,
14,
23841,
837,
507,
198,
692,
536,
14,
4130,
18265,
686,
198,
6958,
507,
198,
815,
275,
3482,
14,
32286,
8,
354,
9,
2742,
198,
692,
5532,
63,
521,
665,
2256,
14,
602,
63,
521,
26,
686,
198,
3543,
63,
521,
275,
2256,
14,
602,
63,
521,
507,
198,
692,
2863,
63,
1861,
508,
488,
26,
686,
198,
2330,
63,
1861,
275,
536,
1491,
354,
14,
14542,
7825,
435,
413,
61,
507,
198,
2836,
26,
686,
198,
6710,
440,
536,
14,
2460,
8,
2330,
63,
1861,
304,
1585,
198,
2019,
63,
7001,
275,
2863,
63,
1861,
4439,
17,
1055,
14542,
7825,
435,
413,
1585,
198,
2330,
63,
1861,
275,
2863,
63,
1861,
1491,
2019,
63,
7001,
61,
2742,
198,
1657,
59,
354,
61,
275,
10871,
435,
620,
8,
2184,
63,
1657,
9,
507,
198,
2184,
63,
1657,
847,
413,
2742,
198,
1361,
1278,
4725,
6582,
297,
283,
1657,
283,
435,
2216,
59,
354,
467,
971,
1871,
198,
5121,
419,
283,
435,
620,
8,
815,
14,
493,
63,
890,
1724,
507,
198,
7015,
63,
646,
14,
952,
8,
3065,
14,
739,
8,
354,
9,
435,
1867,
78,
531,
421,
198,
3543,
351,
275,
5532,
351,
63,
354,
435,
283,
665,
7,
435,
5532,
351,
63,
2123,
435,
12696,
450,
68,
435,
993,
7,
450,
971,
507,
198,
23456,
8,
3543,
63,
521,
435,
334,
16,
12,
378,
12,
378,
430,
421,
198,
1361,
1278,
4725,
3543,
283,
435,
5246,
63,
1121,
12,
283,
3543,
351,
283,
435,
5532,
351,
12,
971,
507,
198,
5121,
419,
5213,
37,
7474,
297,
283,
8499,
1376,
687,
283,
435,
10392,
435,
22608,
283,
37,
7474,
297,
971,
507,
198,
6448,
283,
1807,
452,
1333,
421,
198,
509,
536,
315,
2216,
14,
1612,
837,
507,
198,
7015,
63,
646,
14,
952,
360,
45,
2948,
10893,
283,
435,
2216,
59,
354,
61,
435,
283,
283,
435,
686,
198,
354,
59,
552,
8,
2330,
63,
1861,
15405,
435,
1867,
78,
531,
421,
198,
1361,
1278,
4725,
297,
221,
283,
1450,
283,
435,
931,
14,
4846,
8,
18717,
395,
971,
507,
198,
7,
504,
283,
435,
5246,
63,
1121,
12,
283,
1450,
836,
283,
435,
5532,
351,
12,
971,
507,
198,
5121,
419,
5213,
37,
7474,
297,
283,
8599,
283,
435,
10392,
12,
283,
37,
7474,
297,
12381,
199,
199,
692,
7377,
63,
646,
14,
1600,
837,
199,
198,
2224,
8,
17,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
309,
3482,
6359,
22523,
367,
6135,
13,
7015,
13,
646,
199,
309,
199,
309,
2104,
2893,
26,
199,
309,
199,
309,
221,
20366,
2199,
27,
12829,
2199,
27,
6135,
4205,
199,
309,
221,
2366,
492,
13,
3065,
83,
14,
647,
23588,
3065,
199,
309,
221,
6135,
943,
1553,
3736,
492,
13,
3065,
83,
199,
199,
504,
747,
492,
17758,
12,
931,
199,
504,
984,
492,
9238,
12,
4458,
199,
504,
900,
492,
9199,
521,
199,
504,
10392,
492,
26755,
199,
199,
692,
822,
8,
3020,
9,
665,
499,
26,
199,
198,
1361,
283,
7692,
6536,
9238,
59,
16,
467,
2650,
18717,
30,
13698,
199,
198,
2224,
8,
17,
9,
199,
199,
4694,
63,
1121,
275,
283,
7655,
15,
17033,
15,
646,
13,
3065,
83,
7,
199,
3543,
351,
63,
354,
275,
283,
58,
31045,
9750,
707,
7,
199,
3543,
351,
63,
2123,
275,
283,
3065,
32,
2694,
14,
957,
7,
199,
199,
7015,
63,
646,
275,
17758,
360,
3187,
7377,
13,
646,
1553,
10243,
297,
283,
87,
358,
199,
318,
870,
1278,
8,
513,
304,
199,
198,
509,
620,
315,
769,
26,
507,
198,
7015,
63,
646,
14,
952,
8,
495,
435,
1867,
78,
531,
199,
199,
509,
10392,
315,
9238,
59,
17,
10688,
199,
198,
3543,
63,
521,
275,
378,
199,
198,
2184,
63,
1657,
275,
413,
199,
198,
2330,
63,
1861,
275,
488,
199,
198,
1657,
275,
1211,
342,
421,
198,
3065,
275,
26755,
8,
18717,
12,
283,
82,
358,
199,
198,
509,
536,
315,
3482,
14,
23841,
837,
507,
198,
692,
536,
14,
4130,
18265,
686,
198,
6958,
507,
198,
815,
275,
3482,
14,
32286,
8,
354,
9,
2742,
198,
692,
5532,
63,
521,
665,
2256,
14,
602,
63,
521,
26,
686,
198,
3543,
63,
521,
275,
2256,
14,
602,
63,
521,
507,
198,
692,
2863,
63,
1861,
508,
488,
26,
686,
198,
2330,
63,
1861,
275,
536,
1491,
354,
14,
14542,
7825,
435,
413,
61,
507,
198,
2836,
26,
686,
198,
6710,
440,
536,
14,
2460,
8,
2330,
63,
1861,
304,
1585,
198,
2019,
63,
7001,
275,
2863,
63,
1861,
4439,
17,
1055,
14542,
7825,
435,
413,
1585,
198,
2330,
63,
1861,
275,
2863,
63,
1861,
1491,
2019,
63,
7001,
61,
2742,
198,
1657,
59,
354,
61,
275,
10871,
435,
620,
8,
2184,
63,
1657,
9,
507,
198,
2184,
63,
1657,
847,
413,
2742,
198,
1361,
1278,
4725,
6582,
297,
283,
1657,
283,
435,
2216,
59,
354,
467,
971,
1871,
198,
5121,
419,
283,
435,
620,
8,
815,
14,
493,
63,
890,
1724,
507,
198,
7015,
63,
646,
14,
952,
8,
3065,
14,
739,
8,
354,
9,
435,
1867,
78,
531,
421,
198,
3543,
351,
275,
5532,
351,
63,
354,
435,
283,
665,
7,
435,
5532,
351,
63,
2123,
435,
12696,
450,
68,
435,
993,
7,
450,
971,
507,
198,
23456,
8,
3543,
63,
521,
435,
334,
16,
12,
378,
12,
378,
430,
421,
198,
1361,
1278,
4725,
3543,
283,
435,
5246,
63,
1121,
12,
283,
3543,
351,
283,
435,
5532,
351,
12,
971,
507,
198,
5121,
419,
5213,
37,
7474,
297,
283,
8499,
1376,
687,
283,
435,
10392,
435,
22608,
283,
37,
7474,
297,
971,
507,
198,
6448,
283,
1807,
452,
1333,
421,
198,
509,
536,
315,
2216,
14,
1612,
837,
507,
198,
7015,
63,
646,
14,
952,
360,
45,
2948,
10893,
283,
435,
2216,
59,
354,
61,
435,
283,
283,
435,
686,
198,
354,
59,
552,
8,
2330,
63,
1861,
15405,
435,
1867,
78,
531,
421,
198,
1361,
1278,
4725,
297,
221,
283,
1450,
283,
435,
931,
14,
4846,
8,
18717,
395,
971,
507,
198,
7,
504,
283,
435,
5246,
63,
1121,
12,
283,
1450,
836,
283,
435,
5532,
351,
12,
971,
507,
198,
5121,
419,
5213,
37,
7474,
297,
283,
8599,
283,
435,
10392,
12,
283,
37,
7474,
297,
12381,
199,
199,
692,
7377,
63,
646,
14,
1600,
837,
199,
198,
2224,
8,
17,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rlindner81/pyload
|
module/plugins/hoster/QuickshareCz.py
|
1
|
3533
|
# -*- coding: utf-8 -*-
import re
from module.plugins.internal.SimpleHoster import SimpleHoster
class QuickshareCz(SimpleHoster):
__name__ = "QuickshareCz"
__type__ = "hoster"
__version__ = "0.61"
__status__ = "testing"
__pattern__ = r'http://(?:[^/]*\.)?quickshare\.cz/stahnout-soubor/.+'
__config__ = [("activated", "bool", "Activated", True),
("use_premium", "bool", "Use premium account if available", True),
("fallback", "bool",
"Fallback to free download if premium fails", True),
("chk_filesize", "bool", "Check file size", True),
("max_wait", "int", "Reconnect if waiting time is greater than minutes", 10)]
__description__ = """Quickshare.cz hoster plugin"""
__license__ = "GPLv3"
__authors__ = [("zoidberg", "zoidberg@mujmail.cz")]
NAME_PATTERN = r'<th width="145px">Název:</th>\s*<td style="word-wrap:break-word;">(?P<N>.+?)</td>'
SIZE_PATTERN = r'<th>Velikost:</th>\s*<td>(?P<S>[\d.,]+) (?P<U>[\w^_]+)</td>'
OFFLINE_PATTERN = r'<script type="text/javascript">location\.href=\'/chyba\';</script>'
def process(self, pyfile):
self.data = self.load(pyfile.url)
self.get_fileInfo()
#: Parse js variables
self.jsvars = dict(
(x, y.strip("'")) for x, y in re.findall(
r"var (\w+) = ([\d.]+|'.+?')", self.data))
self.log_debug(self.jsvars)
pyfile.name = self.jsvars['ID3']
#: Determine download type - free or premium
if self.premium:
if 'UU_prihlasen' in self.jsvars:
if self.jsvars['UU_prihlasen'] == "0":
self.log_warning(_("User not logged in"))
self.relogin()
self.retry()
elif float(self.jsvars['UU_kredit']) < float(self.jsvars['kredit_odecet']):
self.log_warning(_("Not enough credit left"))
self.premium = False
if self.premium:
self.handle_premium(pyfile)
else:
self.handle_free(pyfile)
if self.scan_download(
{'error': re.compile(r'\AChyba!')}, read_size=100):
self.fail(_("File not m or plugin defect"))
def handle_free(self, pyfile):
#: Get download url
download_url = '%s/download.php' % self.jsvars['server']
data = dict(
(x, self.jsvars[x]) for x in self.jsvars if x in (
"ID1", "ID2", "ID3", "ID4"))
self.log_debug("FREE URL1:" + download_url, data)
header = self.load(download_url, post=data, just_header=True)
self.link = header.get('location')
if not self.link:
elf.fail(_("File not found"))
self.link = m.group(1)
self.log_debug("FREE URL2:" + self.link)
#: Check errors
m = re.search(r'/chyba/(\d+)', self.link)
if m is not None:
if m.group(1) == "1":
self.retry(60, 2 * 60, "This IP is already downloading")
elif m.group(1) == "2":
self.retry(60, 60, "No free slots available")
else:
self.fail(_("Error %d") % m.group(1))
def handle_premium(self, pyfile):
download_url = '%s/download_premium.php' % self.jsvars['server']
data = dict(
(x, self.jsvars[x]) for x in self.jsvars if x in (
"ID1", "ID2", "ID4", "ID5"))
self.download(download_url, get=data)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
295,
199,
199,
504,
859,
14,
5265,
14,
4672,
14,
3184,
40,
29895,
492,
5870,
40,
29895,
421,
199,
533,
27534,
6251,
35,
90,
8,
3184,
40,
29895,
304,
272,
636,
354,
363,
275,
298,
19684,
6251,
35,
90,
2,
272,
636,
466,
363,
275,
298,
526,
11652,
2,
272,
636,
1023,
363,
275,
298,
16,
14,
2976,
2,
272,
636,
1205,
363,
275,
298,
4776,
2,
339,
636,
3401,
363,
275,
519,
7,
1014,
921,
5169,
4735,
15,
3672,
20316,
13239,
6251,
4537,
16823,
15,
1207,
6164,
548,
13,
1152,
456,
269,
8083,
4786,
272,
636,
888,
363,
275,
10003,
18218,
401,
298,
2245,
401,
298,
13767,
12529,
401,
715,
395,
2116,
1689,
1180,
63,
657,
23481,
401,
298,
2245,
401,
298,
6119,
876,
23481,
2933,
340,
2808,
401,
715,
395,
2116,
1689,
10538,
401,
298,
2245,
401,
673,
298,
21860,
370,
2867,
5235,
340,
876,
23481,
6918,
401,
715,
395,
2116,
1689,
14823,
63,
19233,
401,
298,
2245,
401,
298,
1799,
570,
1568,
401,
715,
395,
2116,
1689,
988,
63,
2573,
401,
298,
442,
401,
298,
497,
2242,
340,
10923,
900,
365,
8932,
2419,
9395,
401,
1616,
1874,
339,
636,
1802,
363,
275,
408,
19684,
6251,
14,
16823,
394,
29895,
3589,
624,
272,
636,
1682,
363,
275,
298,
28863,
19,
2,
272,
636,
8149,
363,
275,
10003,
90,
1170,
14630,
401,
298,
90,
1170,
14630,
32,
6553,
74,
1198,
14,
16823,
11323,
339,
13637,
63,
10764,
275,
519,
7601,
273,
3462,
628,
11731,
5326,
1743,
46,
11302,
806,
86,
9919,
273,
3072,
83,
10,
28,
2076,
3449,
628,
1027,
13,
3823,
26,
4785,
13,
1027,
31328,
2229,
48,
28,
46,
29587,
15939,
2076,
3524,
272,
32289,
63,
10764,
275,
519,
7601,
273,
30,
15169,
317,
75,
941,
9919,
273,
3072,
83,
10,
28,
2076,
30,
2229,
48,
28,
51,
24693,
68,
2020,
11896,
7558,
48,
28,
53,
24693,
87,
62,
63,
11896,
1108,
2076,
3524,
272,
1634,
3143,
3565,
63,
10764,
275,
519,
7601,
1579,
730,
628,
505,
15,
9554,
1743,
1985,
4537,
6399,
25641,
15,
335,
89,
2470,
3985,
12279,
1579,
3524,
339,
347,
2112,
8,
277,
12,
1134,
493,
304,
267,
291,
14,
576,
275,
291,
14,
912,
8,
14792,
14,
633,
9,
267,
291,
14,
362,
63,
493,
2354,
342,
398,
6079,
6077,
8586,
2860,
267,
291,
14,
3596,
2936,
275,
1211,
8,
288,
334,
88,
12,
612,
14,
1913,
15587,
2237,
367,
671,
12,
612,
315,
295,
14,
6452,
8,
355,
519,
2,
1391,
14749,
87,
8771,
275,
334,
7023,
68,
32455,
92,
1370,
23778,
18106,
291,
14,
576,
430,
267,
291,
14,
793,
63,
1757,
8,
277,
14,
3596,
2936,
9,
267,
1134,
493,
14,
354,
275,
291,
14,
3596,
2936,
459,
998,
19,
418,
398,
6079,
14703,
5235,
730,
446,
2867,
503,
876,
23481,
267,
340,
291,
14,
657,
23481,
26,
288,
340,
283,
4622,
63,
1359,
72,
416,
2464,
7,
315,
291,
14,
3596,
2936,
26,
355,
340,
291,
14,
3596,
2936,
459,
4622,
63,
1359,
72,
416,
2464,
418,
508,
298,
16,
582,
490,
291,
14,
793,
63,
3764,
6115,
1899,
440,
10367,
315,
2237,
490,
291,
14,
264,
2886,
342,
490,
291,
14,
7154,
342,
355,
916,
2069,
8,
277,
14,
3596,
2936,
459,
4622,
63,
75,
264,
1741,
1105,
665,
2069,
8,
277,
14,
3596,
2936,
459,
75,
264,
1741,
63,
380,
301,
84,
9090,
490,
291,
14,
793,
63,
3764,
6115,
1763,
8321,
16630,
3602,
2237,
490,
291,
14,
657,
23481,
275,
756,
398,
340,
291,
14,
657,
23481,
26,
288,
291,
14,
2479,
63,
657,
23481,
8,
14792,
9,
267,
587,
26,
288,
291,
14,
2479,
63,
4624,
8,
14792,
9,
398,
340,
291,
14,
6282,
63,
4249,
8,
355,
791,
705,
356,
295,
14,
2014,
8,
82,
1154,
33,
1049,
89,
2470,
1,
3904,
1586,
63,
890,
29,
1960,
304,
288,
291,
14,
1633,
6115,
1173,
440,
333,
503,
3589,
347,
449,
2237,
339,
347,
2429,
63,
4624,
8,
277,
12,
1134,
493,
304,
267,
6079,
2372,
5235,
1166,
267,
5235,
63,
633,
275,
1543,
83,
15,
4249,
14,
8624,
7,
450,
291,
14,
3596,
2936,
459,
1000,
418,
267,
666,
275,
1211,
8,
288,
334,
88,
12,
291,
14,
3596,
2936,
59,
88,
566,
367,
671,
315,
291,
14,
3596,
2936,
340,
671,
315,
334,
355,
298,
998,
17,
401,
298,
998,
18,
401,
298,
998,
19,
401,
298,
998,
20,
2237,
267,
291,
14,
793,
63,
1757,
480,
28170,
2851,
17,
5424,
435,
5235,
63,
633,
12,
666,
9,
398,
1406,
275,
291,
14,
912,
8,
4249,
63,
633,
12,
2963,
29,
576,
12,
2951,
63,
1291,
29,
549,
9,
398,
291,
14,
1073,
275,
1406,
14,
362,
360,
1985,
358,
267,
340,
440,
291,
14,
1073,
26,
288,
325,
276,
14,
1633,
6115,
1173,
440,
1911,
2237,
398,
291,
14,
1073,
275,
333,
14,
923,
8,
17,
9,
267,
291,
14,
793,
63,
1757,
480,
28170,
2851,
18,
5424,
435,
291,
14,
1073,
9,
398,
6079,
2670,
2552,
267,
333,
275,
295,
14,
1733,
8,
82,
9807,
335,
89,
2470,
15,
2961,
68,
14705,
291,
14,
1073,
9,
267,
340,
333,
365,
440,
488,
26,
288,
340,
333,
14,
923,
8,
17,
9,
508,
298,
17,
582,
355,
291,
14,
7154,
8,
2259,
12,
499,
627,
5212,
12,
298,
2765,
3531,
365,
2575,
25937,
531,
288,
916,
333,
14,
923,
8,
17,
9,
508,
298,
18,
582,
355,
291,
14,
7154,
8,
2259,
12,
5212,
12,
298,
1944,
2867,
14319,
2808,
531,
288,
587,
26,
355,
291,
14,
1633,
6115,
547,
450,
68,
531,
450,
333,
14,
923,
8,
17,
430,
339,
347,
2429,
63,
657,
23481,
8,
277,
12,
1134,
493,
304,
267,
5235,
63,
633,
275,
1543,
83,
15,
4249,
63,
657,
23481,
14,
8624,
7,
450,
291,
14,
3596,
2936,
459,
1000,
418,
267,
666,
275,
1211,
8,
288,
334,
88,
12,
291,
14,
3596,
2936,
59,
88,
566,
367,
671,
315,
291,
14,
3596,
2936,
340,
671,
315,
334,
355,
298,
998,
17,
401,
298,
998,
18,
401,
298,
998,
20,
401,
298,
998,
21,
2237,
267,
291,
14,
4249,
8
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
295,
199,
199,
504,
859,
14,
5265,
14,
4672,
14,
3184,
40,
29895,
492,
5870,
40,
29895,
421,
199,
533,
27534,
6251,
35,
90,
8,
3184,
40,
29895,
304,
272,
636,
354,
363,
275,
298,
19684,
6251,
35,
90,
2,
272,
636,
466,
363,
275,
298,
526,
11652,
2,
272,
636,
1023,
363,
275,
298,
16,
14,
2976,
2,
272,
636,
1205,
363,
275,
298,
4776,
2,
339,
636,
3401,
363,
275,
519,
7,
1014,
921,
5169,
4735,
15,
3672,
20316,
13239,
6251,
4537,
16823,
15,
1207,
6164,
548,
13,
1152,
456,
269,
8083,
4786,
272,
636,
888,
363,
275,
10003,
18218,
401,
298,
2245,
401,
298,
13767,
12529,
401,
715,
395,
2116,
1689,
1180,
63,
657,
23481,
401,
298,
2245,
401,
298,
6119,
876,
23481,
2933,
340,
2808,
401,
715,
395,
2116,
1689,
10538,
401,
298,
2245,
401,
673,
298,
21860,
370,
2867,
5235,
340,
876,
23481,
6918,
401,
715,
395,
2116,
1689,
14823,
63,
19233,
401,
298,
2245,
401,
298,
1799,
570,
1568,
401,
715,
395,
2116,
1689,
988,
63,
2573,
401,
298,
442,
401,
298,
497,
2242,
340,
10923,
900,
365,
8932,
2419,
9395,
401,
1616,
1874,
339,
636,
1802,
363,
275,
408,
19684,
6251,
14,
16823,
394,
29895,
3589,
624,
272,
636,
1682,
363,
275,
298,
28863,
19,
2,
272,
636,
8149,
363,
275,
10003,
90,
1170,
14630,
401,
298,
90,
1170,
14630,
32,
6553,
74,
1198,
14,
16823,
11323,
339,
13637,
63,
10764,
275,
519,
7601,
273,
3462,
628,
11731,
5326,
1743,
46,
11302,
806,
86,
9919,
273,
3072,
83,
10,
28,
2076,
3449,
628,
1027,
13,
3823,
26,
4785,
13,
1027,
31328,
2229,
48,
28,
46,
29587,
15939,
2076,
3524,
272,
32289,
63,
10764,
275,
519,
7601,
273,
30,
15169,
317,
75,
941,
9919,
273,
3072,
83,
10,
28,
2076,
30,
2229,
48,
28,
51,
24693,
68,
2020,
11896,
7558,
48,
28,
53,
24693,
87,
62,
63,
11896,
1108,
2076,
3524,
272,
1634,
3143,
3565,
63,
10764,
275,
519,
7601,
1579,
730,
628,
505,
15,
9554,
1743,
1985,
4537,
6399,
25641,
15,
335,
89,
2470,
3985,
12279,
1579,
3524,
339,
347,
2112,
8,
277,
12,
1134,
493,
304,
267,
291,
14,
576,
275,
291,
14,
912,
8,
14792,
14,
633,
9,
267,
291,
14,
362,
63,
493,
2354,
342,
398,
6079,
6077,
8586,
2860,
267,
291,
14,
3596,
2936,
275,
1211,
8,
288,
334,
88,
12,
612,
14,
1913,
15587,
2237,
367,
671,
12,
612,
315,
295,
14,
6452,
8,
355,
519,
2,
1391,
14749,
87,
8771,
275,
334,
7023,
68,
32455,
92,
1370,
23778,
18106,
291,
14,
576,
430,
267,
291,
14,
793,
63,
1757,
8,
277,
14,
3596,
2936,
9,
267,
1134,
493,
14,
354,
275,
291,
14,
3596,
2936,
459,
998,
19,
418,
398,
6079,
14703,
5235,
730,
446,
2867,
503,
876,
23481,
267,
340,
291,
14,
657,
23481,
26,
288,
340,
283,
4622,
63,
1359,
72,
416,
2464,
7,
315,
291,
14,
3596,
2936,
26,
355,
340,
291,
14,
3596,
2936,
459,
4622,
63,
1359,
72,
416,
2464,
418,
508,
298,
16,
582,
490,
291,
14,
793,
63,
3764,
6115,
1899,
440,
10367,
315,
2237,
490,
291,
14,
264,
2886,
342,
490,
291,
14,
7154,
342,
355,
916,
2069,
8,
277,
14,
3596,
2936,
459,
4622,
63,
75,
264,
1741,
1105,
665,
2069,
8,
277,
14,
3596,
2936,
459,
75,
264,
1741,
63,
380,
301,
84,
9090,
490,
291,
14,
793,
63,
3764,
6115,
1763,
8321,
16630,
3602,
2237,
490,
291,
14,
657,
23481,
275,
756,
398,
340,
291,
14,
657,
23481,
26,
288,
291,
14,
2479,
63,
657,
23481,
8,
14792,
9,
267,
587,
26,
288,
291,
14,
2479,
63,
4624,
8,
14792,
9,
398,
340,
291,
14,
6282,
63,
4249,
8,
355,
791,
705,
356,
295,
14,
2014,
8,
82,
1154,
33,
1049,
89,
2470,
1,
3904,
1586,
63,
890,
29,
1960,
304,
288,
291,
14,
1633,
6115,
1173,
440,
333,
503,
3589,
347,
449,
2237,
339,
347,
2429,
63,
4624,
8,
277,
12,
1134,
493,
304,
267,
6079,
2372,
5235,
1166,
267,
5235,
63,
633,
275,
1543,
83,
15,
4249,
14,
8624,
7,
450,
291,
14,
3596,
2936,
459,
1000,
418,
267,
666,
275,
1211,
8,
288,
334,
88,
12,
291,
14,
3596,
2936,
59,
88,
566,
367,
671,
315,
291,
14,
3596,
2936,
340,
671,
315,
334,
355,
298,
998,
17,
401,
298,
998,
18,
401,
298,
998,
19,
401,
298,
998,
20,
2237,
267,
291,
14,
793,
63,
1757,
480,
28170,
2851,
17,
5424,
435,
5235,
63,
633,
12,
666,
9,
398,
1406,
275,
291,
14,
912,
8,
4249,
63,
633,
12,
2963,
29,
576,
12,
2951,
63,
1291,
29,
549,
9,
398,
291,
14,
1073,
275,
1406,
14,
362,
360,
1985,
358,
267,
340,
440,
291,
14,
1073,
26,
288,
325,
276,
14,
1633,
6115,
1173,
440,
1911,
2237,
398,
291,
14,
1073,
275,
333,
14,
923,
8,
17,
9,
267,
291,
14,
793,
63,
1757,
480,
28170,
2851,
18,
5424,
435,
291,
14,
1073,
9,
398,
6079,
2670,
2552,
267,
333,
275,
295,
14,
1733,
8,
82,
9807,
335,
89,
2470,
15,
2961,
68,
14705,
291,
14,
1073,
9,
267,
340,
333,
365,
440,
488,
26,
288,
340,
333,
14,
923,
8,
17,
9,
508,
298,
17,
582,
355,
291,
14,
7154,
8,
2259,
12,
499,
627,
5212,
12,
298,
2765,
3531,
365,
2575,
25937,
531,
288,
916,
333,
14,
923,
8,
17,
9,
508,
298,
18,
582,
355,
291,
14,
7154,
8,
2259,
12,
5212,
12,
298,
1944,
2867,
14319,
2808,
531,
288,
587,
26,
355,
291,
14,
1633,
6115,
547,
450,
68,
531,
450,
333,
14,
923,
8,
17,
430,
339,
347,
2429,
63,
657,
23481,
8,
277,
12,
1134,
493,
304,
267,
5235,
63,
633,
275,
1543,
83,
15,
4249,
63,
657,
23481,
14,
8624,
7,
450,
291,
14,
3596,
2936,
459,
1000,
418,
267,
666,
275,
1211,
8,
288,
334,
88,
12,
291,
14,
3596,
2936,
59,
88,
566,
367,
671,
315,
291,
14,
3596,
2936,
340,
671,
315,
334,
355,
298,
998,
17,
401,
298,
998,
18,
401,
298,
998,
20,
401,
298,
998,
21,
2237,
267,
291,
14,
4249,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
gluke77/rally
|
tests/unit/plugins/openstack/scenarios/ec2/test_utils.py
|
7
|
2842
|
# 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 mock
from oslo_config import cfg
from rally.plugins.openstack.scenarios.ec2 import utils
from tests.unit import test
CONF = cfg.CONF
class EC2ScenarioTestCase(test.ScenarioTestCase):
def setUp(self):
super(EC2ScenarioTestCase, self).setUp()
self.server1 = mock.MagicMock()
self.server2 = mock.MagicMock()
self.reservations = mock.MagicMock(instances=[self.server1,
self.server2])
def test__list_servers(self):
servers_list = []
self.clients("ec2").get_only_instances.return_value = servers_list
ec2_scenario = utils.EC2Scenario()
return_servers_list = ec2_scenario._list_servers()
self.assertEqual(servers_list, return_servers_list)
self._test_atomic_action_timer(ec2_scenario.atomic_actions(),
"ec2.list_servers")
def test__update_resource(self):
resource = mock.MagicMock()
scenario = utils.EC2Scenario(self.context)
self.assertEqual(scenario._update_resource(resource), resource)
resource.update.assert_called_once_with()
def test__boot_servers(self):
self.clients("ec2").run_instances.return_value = self.reservations
ec2_scenario = utils.EC2Scenario(context={})
ec2_scenario._update_resource = mock.Mock()
ec2_scenario._boot_servers("image", "flavor", 2)
expected = [
mock.call(
self.server1,
ready_statuses=["RUNNING"],
update_resource=ec2_scenario._update_resource,
check_interval=CONF.benchmark.ec2_server_boot_poll_interval,
timeout=CONF.benchmark.ec2_server_boot_timeout
),
mock.call(
self.server2,
ready_statuses=["RUNNING"],
update_resource=ec2_scenario._update_resource,
check_interval=CONF.benchmark.ec2_server_boot_poll_interval,
timeout=CONF.benchmark.ec2_server_boot_timeout
)
]
self.mock_wait_for.mock.assert_has_calls(expected)
self._test_atomic_action_timer(ec2_scenario.atomic_actions(),
"ec2.boot_servers")
|
apache-2.0
|
[
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
519,
1183,
14,
5265,
14,
8512,
14,
32225,
14,
825,
18,
492,
3778,
199,
504,
2295,
14,
3248,
492,
511,
199,
199,
3103,
275,
4810,
14,
3103,
421,
199,
533,
15352,
18,
12327,
6936,
1746,
8,
396,
14,
12327,
6936,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
4220,
18,
12327,
6936,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
1000,
17,
275,
1683,
14,
11988,
342,
267,
291,
14,
1000,
18,
275,
1683,
14,
11988,
342,
267,
291,
14,
264,
12225,
275,
1683,
14,
11988,
8,
5990,
1524,
277,
14,
1000,
17,
12,
10028,
291,
14,
1000,
18,
566,
339,
347,
511,
363,
513,
63,
5871,
8,
277,
304,
267,
8037,
63,
513,
275,
942,
267,
291,
14,
14555,
480,
825,
18,
3471,
362,
63,
2118,
63,
5990,
14,
1107,
63,
585,
275,
8037,
63,
513,
267,
7062,
18,
63,
13444,
275,
3778,
14,
4220,
18,
12327,
6936,
342,
267,
372,
63,
5871,
63,
513,
275,
7062,
18,
63,
13444,
423,
513,
63,
5871,
342,
267,
291,
14,
629,
8,
5871,
63,
513,
12,
372,
63,
5871,
63,
513,
9,
267,
291,
423,
396,
63,
10910,
63,
1287,
63,
7414,
8,
825,
18,
63,
13444,
14,
10910,
63,
3723,
1062,
4318,
298,
825,
18,
14,
513,
63,
5871,
531,
339,
347,
511,
363,
873,
63,
1927,
8,
277,
304,
267,
2073,
275,
1683,
14,
11988,
342,
267,
15728,
275,
3778,
14,
4220,
18,
12327,
6936,
8,
277,
14,
1100,
9,
267,
291,
14,
629,
8,
13444,
423,
873,
63,
1927,
8,
1927,
395,
2073,
9,
267,
2073,
14,
873,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
339,
347,
511,
363,
4930,
63,
5871,
8,
277,
304,
267,
291,
14,
14555,
480,
825,
18,
3471,
1065,
63,
5990,
14,
1107,
63,
585,
275,
291,
14,
264,
12225,
267,
7062,
18,
63,
13444,
275,
3778,
14,
4220,
18,
12327,
6936,
8,
1100,
21146,
267,
7062,
18,
63,
13444,
423,
873,
63,
1927,
275,
1683,
14,
3346,
342,
267,
7062,
18,
63,
13444,
423,
4930,
63,
5871,
480,
1569,
401,
298,
6081,
401,
499,
9,
267,
1420,
275,
359,
288,
1683,
14,
1250,
8,
355,
291,
14,
1000,
17,
12,
355,
10144,
63,
17084,
6270,
17305,
2255,
355,
1678,
63,
1927,
29,
825,
18,
63,
13444,
423,
873,
63,
1927,
12,
355,
1104,
63,
4284,
29,
3103,
14,
11861,
14,
825,
18,
63,
1000,
63,
4930,
63,
6843,
63,
4284,
12,
355,
2653,
29,
3103,
14,
11861,
14,
825,
18,
63,
1000,
63,
4930,
63,
2593,
288,
2318,
288,
1683,
14,
1250,
8,
355,
291,
14,
1000,
18,
12,
355,
10144,
63,
17084,
6270,
17305,
2255,
355,
1678,
63,
1927,
29,
825,
18,
63,
13444,
423,
873,
63,
1927,
12,
355,
1104,
63,
4284,
29,
3103,
14,
11861,
14,
825,
18,
63,
1000,
63,
4930,
63,
6843,
63,
4284,
12,
355,
2653,
29,
3103,
14,
11861,
14,
825,
18,
63,
1000,
63,
4930,
63,
2593,
288,
776,
267,
1622,
267,
291,
14,
1805,
63,
2573,
63,
509,
14,
1805,
14,
479,
63,
1989,
63,
5352,
8,
2062,
9,
267,
291,
423,
396,
63,
10910,
63,
1287,
63,
7414,
8,
825,
18,
63,
13444,
14,
10910,
63,
3723,
1062,
4318,
298,
825,
18,
14,
4930,
63,
5871,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
519,
1183,
14,
5265,
14,
8512,
14,
32225,
14,
825,
18,
492,
3778,
199,
504,
2295,
14,
3248,
492,
511,
199,
199,
3103,
275,
4810,
14,
3103,
421,
199,
533,
15352,
18,
12327,
6936,
1746,
8,
396,
14,
12327,
6936,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
4220,
18,
12327,
6936,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
1000,
17,
275,
1683,
14,
11988,
342,
267,
291,
14,
1000,
18,
275,
1683,
14,
11988,
342,
267,
291,
14,
264,
12225,
275,
1683,
14,
11988,
8,
5990,
1524,
277,
14,
1000,
17,
12,
10028,
291,
14,
1000,
18,
566,
339,
347,
511,
363,
513,
63,
5871,
8,
277,
304,
267,
8037,
63,
513,
275,
942,
267,
291,
14,
14555,
480,
825,
18,
3471,
362,
63,
2118,
63,
5990,
14,
1107,
63,
585,
275,
8037,
63,
513,
267,
7062,
18,
63,
13444,
275,
3778,
14,
4220,
18,
12327,
6936,
342,
267,
372,
63,
5871,
63,
513,
275,
7062,
18,
63,
13444,
423,
513,
63,
5871,
342,
267,
291,
14,
629,
8,
5871,
63,
513,
12,
372,
63,
5871,
63,
513,
9,
267,
291,
423,
396,
63,
10910,
63,
1287,
63,
7414,
8,
825,
18,
63,
13444,
14,
10910,
63,
3723,
1062,
4318,
298,
825,
18,
14,
513,
63,
5871,
531,
339,
347,
511,
363,
873,
63,
1927,
8,
277,
304,
267,
2073,
275,
1683,
14,
11988,
342,
267,
15728,
275,
3778,
14,
4220,
18,
12327,
6936,
8,
277,
14,
1100,
9,
267,
291,
14,
629,
8,
13444,
423,
873,
63,
1927,
8,
1927,
395,
2073,
9,
267,
2073,
14,
873,
14,
479,
63,
3527,
63,
5089,
63,
1045,
342,
339,
347,
511,
363,
4930,
63,
5871,
8,
277,
304,
267,
291,
14,
14555,
480,
825,
18,
3471,
1065,
63,
5990,
14,
1107,
63,
585,
275,
291,
14,
264,
12225,
267,
7062,
18,
63,
13444,
275,
3778,
14,
4220,
18,
12327,
6936,
8,
1100,
21146,
267,
7062,
18,
63,
13444,
423,
873,
63,
1927,
275,
1683,
14,
3346,
342,
267,
7062,
18,
63,
13444,
423,
4930,
63,
5871,
480,
1569,
401,
298,
6081,
401,
499,
9,
267,
1420,
275,
359,
288,
1683,
14,
1250,
8,
355,
291,
14,
1000,
17,
12,
355,
10144,
63,
17084,
6270,
17305,
2255,
355,
1678,
63,
1927,
29,
825,
18,
63,
13444,
423,
873,
63,
1927,
12,
355,
1104,
63,
4284,
29,
3103,
14,
11861,
14,
825,
18,
63,
1000,
63,
4930,
63,
6843,
63,
4284,
12,
355,
2653,
29,
3103,
14,
11861,
14,
825,
18,
63,
1000,
63,
4930,
63,
2593,
288,
2318,
288,
1683,
14,
1250,
8,
355,
291,
14,
1000,
18,
12,
355,
10144,
63,
17084,
6270,
17305,
2255,
355,
1678,
63,
1927,
29,
825,
18,
63,
13444,
423,
873,
63,
1927,
12,
355,
1104,
63,
4284,
29,
3103,
14,
11861,
14,
825,
18,
63,
1000,
63,
4930,
63,
6843,
63,
4284,
12,
355,
2653,
29,
3103,
14,
11861,
14,
825,
18,
63,
1000,
63,
4930,
63,
2593,
288,
776,
267,
1622,
267,
291,
14,
1805,
63,
2573,
63,
509,
14,
1805,
14,
479,
63,
1989,
63,
5352,
8,
2062,
9,
267,
291,
423,
396,
63,
10910,
63,
1287,
63,
7414,
8,
825,
18,
63,
13444,
14,
10910,
63,
3723,
1062,
4318,
298,
825,
18,
14,
4930,
63,
5871,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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ton example of a Ginga global plugin called 'MyGlobalPlugin'
To enable it, run ginga with the command
$ ginga --modules=MyLocalPlugin
it should become active in the right panel.
"""
from ginga import GingaPlugin
from ginga.gw import Widgets
# import any other modules you want here--it's a python world!
class MyGlobalPlugin(GingaPlugin.GlobalPlugin):
def __init__(self, fv):
"""
This method is called when the plugin is loaded for the first
time. ``fv`` is a reference to the Ginga (reference viewer) shell.
You need to call the superclass initializer and then do any local
initialization.
"""
super(MyGlobalPlugin, self).__init__(fv)
# Your initialization here
# Create some variables to keep track of what is happening
# with which channel
self.active = None
# Subscribe to some interesting callbacks that will inform us
# of channel events. You may not need these depending on what
# your plugin does
fv.set_callback('add-channel', self.add_channel)
fv.set_callback('delete-channel', self.delete_channel)
fv.set_callback('channel-change', self.focus_cb)
def build_gui(self, container):
"""
This method is called when the plugin is invoked. It builds the
GUI used by the plugin into the widget layout passed as
``container``.
This method could be called several times if the plugin is opened
and closed. The method may be omitted if there is no GUI for the
plugin.
This specific example uses the GUI widget set agnostic wrappers
to build the GUI, but you can also just as easily use explicit
toolkit calls here if you only want to support one widget set.
"""
top = Widgets.VBox()
top.set_border_width(4)
# this is a little trick for making plugins that work either in
# a vertical or horizontal orientation. It returns a box container,
# a scroll widget and an orientation ('vertical', 'horizontal')
vbox, sw, orientation = Widgets.get_oriented_box(container)
vbox.set_border_width(4)
vbox.set_spacing(2)
# Take a text widget to show some instructions
self.msgFont = self.fv.getFont("sansFont", 12)
tw = Widgets.TextArea(wrap=True, editable=False)
tw.set_font(self.msgFont)
self.tw = tw
# Frame for instructions and add the text widget with another
# blank widget to stretch as needed to fill emp
fr = Widgets.Frame("Status")
fr.set_widget(tw)
vbox.add_widget(fr, stretch=0)
# Add a spacer to stretch the rest of the way to the end of the
# plugin space
spacer = Widgets.Label('')
vbox.add_widget(spacer, stretch=1)
# scroll bars will allow lots of content to be accessed
top.add_widget(sw, stretch=1)
# A button box that is always visible at the bottom
btns = Widgets.HBox()
btns.set_spacing(3)
# Add a close button for the convenience of the user
btn = Widgets.Button("Close")
btn.add_callback('activated', lambda w: self.close())
btns.add_widget(btn, stretch=0)
btns.add_widget(Widgets.Label(''), stretch=1)
top.add_widget(btns, stretch=0)
# Add our GUI to the container
container.add_widget(top, stretch=1)
# NOTE: if you are building a GUI using a specific widget toolkit
# (e.g. Qt) GUI calls, you need to extract the widget or layout
# from the non-toolkit specific container wrapper and call on that
# to pack your widget, e.g.:
#cw = container.get_widget()
#cw.addWidget(widget, stretch=1)
def get_channel_info(self, fitsimage):
chname = self.fv.get_channelName(fitsimage)
channel = self.fv.get_channelInfo(chname)
return channel
def set_info(self, text):
self.tw.set_text(text)
# CALLBACKS
def add_channel(self, viewer, channel):
"""
Callback from the reference viewer shell when a channel is added.
"""
self.set_info("Channel '%s' has been added" % (
channel.name))
def delete_channel(self, viewer, channel):
"""
Callback from the reference viewer shell when a channel is deleted.
"""
self.set_info("Channel '%s' has been deleted" % (
channel.name))
return True
def focus_cb(self, viewer, channel):
"""
Callback from the reference viewer shell when the focus changes
between channels.
"""
chname = channel.name
if self.active != chname:
# focus has shifted to a different channel than our idea
# of the active one
self.active = chname
self.set_info("Focus is now in channel '%s'" % (
self.active))
return True
def redo(self, channel, image):
"""
Called from the reference viewer shell when a new image has
been added to a channel.
"""
chname = channel.name
# Only update our GUI if the activity is in the focused
# channel
if self.active == chname:
imname = image.get('name', 'NONAME')
self.set_info("A new image '%s' has been added to channel %s" % (
imname, chname))
return True
def start(self):
"""
This method is called just after ``build_gui()`` when the plugin
is invoked. This method could be called more than once if the
plugin is opened and closed. This method may be omitted
in many cases.
"""
pass
def stop(self):
"""
This method is called when the plugin is stopped.
It should perform any special clean up necessary to terminate
the operation. This method could be called more than once if
the plugin is opened and closed, and may be omitted if there is no
special cleanup required when stopping.
"""
pass
def close(self):
self.fv.stop_global_plugin(str(self))
return True
def __str__(self):
"""
This method should be provided and should return the lower case
name of the plugin.
"""
return 'myglobalplugin'
|
bsd-3-clause
|
[
624,
199,
51,
415,
17589,
2893,
402,
282,
598,
316,
65,
2288,
3589,
2797,
283,
5713,
7025,
5061,
7,
199,
199,
1378,
4756,
652,
12,
1255,
486,
316,
65,
543,
314,
1414,
272,
2672,
486,
316,
65,
1553,
3112,
29,
5713,
5339,
5061,
199,
199,
390,
1077,
8649,
4702,
315,
314,
2451,
12748,
14,
199,
624,
199,
199,
504,
486,
316,
65,
492,
598,
316,
65,
5061,
199,
504,
486,
316,
65,
14,
8392,
492,
16905,
83,
199,
199,
3,
492,
1263,
1163,
4621,
1265,
2934,
2348,
306,
390,
1159,
282,
2366,
6701,
1,
199,
199,
533,
4932,
7025,
5061,
8,
39,
316,
65,
5061,
14,
7025,
5061,
304,
339,
347,
636,
826,
721,
277,
12,
289,
86,
304,
267,
408,
267,
961,
1083,
365,
2797,
1380,
314,
3589,
365,
6511,
367,
314,
221,
1642,
267,
900,
14,
221,
1124,
13692,
1040,
365,
282,
3659,
370,
314,
598,
316,
65,
334,
4443,
27354,
9,
5218,
14,
398,
2047,
1929,
370,
1240,
314,
17035,
11130,
436,
2066,
886,
1263,
2257,
267,
11097,
14,
267,
408,
267,
1613,
8,
5713,
7025,
5061,
12,
291,
2843,
826,
721,
13692,
9,
398,
327,
19519,
11097,
2348,
398,
327,
2790,
2005,
2860,
370,
4215,
4426,
402,
4052,
365,
5992,
316,
267,
327,
543,
1314,
3623,
267,
291,
14,
2682,
275,
488,
398,
327,
4804,
5355,
370,
2005,
19604,
13484,
626,
911,
315,
964,
2739,
267,
327,
402,
3623,
4474,
14,
221,
2047,
1443,
440,
1929,
3520,
10298,
641,
4052,
267,
327,
2195,
3589,
1630,
267,
289,
86,
14,
409,
63,
3058,
360,
525,
13,
2775,
297,
291,
14,
525,
63,
2775,
9,
267,
289,
86,
14,
409,
63,
3058,
360,
1807,
13,
2775,
297,
291,
14,
1807,
63,
2775,
9,
267,
289,
86,
14,
409,
63,
3058,
360,
2775,
13,
1461,
297,
291,
14,
12283,
63,
2894,
9,
339,
347,
1900,
63,
5885,
8,
277,
12,
3970,
304,
267,
408,
267,
961,
1083,
365,
2797,
1380,
314,
3589,
365,
10302,
14,
221,
2779,
14723,
314,
267,
17160,
1202,
701,
314,
3589,
1901,
314,
3938,
7054,
3032,
465,
267,
1124,
3600,
4345,
267,
961,
1083,
4293,
506,
2797,
9978,
5431,
340,
314,
3589,
365,
12123,
267,
436,
6876,
14,
221,
710,
1083,
1443,
506,
11684,
340,
2337,
365,
949,
17160,
367,
314,
267,
3589,
14,
398,
961,
2488,
2893,
4440,
314,
17160,
3938,
663,
282,
784,
941,
530,
17995,
267,
370,
1900,
314,
17160,
12,
1325,
1265,
883,
2597,
2951,
465,
16174,
675,
5027,
267,
4744,
6065,
4882,
2348,
340,
1265,
1454,
2934,
370,
2291,
1373,
3938,
663,
14,
267,
408,
267,
2746,
275,
16905,
83,
14,
54,
3532,
342,
267,
2746,
14,
409,
63,
8665,
63,
2063,
8,
20,
9,
398,
327,
642,
365,
282,
12050,
20907,
367,
10663,
8963,
626,
1736,
1902,
315,
267,
327,
282,
13763,
503,
17528,
16774,
14,
221,
2779,
2529,
282,
5689,
3970,
12,
267,
327,
282,
13704,
3938,
436,
376,
16774,
661,
7870,
297,
283,
11392,
358,
267,
20163,
12,
5584,
12,
16774,
275,
16905,
83,
14,
362,
63,
16039,
287,
471,
63,
1977,
8,
3600,
9,
267,
20163,
14,
409,
63,
8665,
63,
2063,
8,
20,
9,
267,
20163,
14,
409,
63,
15880,
8,
18,
9,
398,
327,
18146,
282,
1318,
3938,
370,
2498,
2005,
15794,
267,
291,
14,
1328,
6986,
275,
291,
14,
13692,
14,
362,
6986,
480,
26052,
6986,
401,
3144,
9,
267,
8900,
275,
16905,
83,
14,
1872,
11043,
8,
3823,
29,
549,
12,
14783,
29,
797,
9,
267,
8900,
14,
409,
63,
4246,
8,
277,
14,
1328,
6986,
9,
267,
291,
14,
8122,
275,
8900,
398,
327,
11726,
367,
15794,
436,
1050,
314,
1318,
3938,
543,
4573,
267,
327,
4596,
3938,
370,
31262,
465,
4346,
370,
5554,
9052,
267,
9513,
275,
16905,
83,
14,
3160,
480,
3694,
531,
267,
9513,
14,
409,
63,
3440,
8,
8122,
9,
267,
20163,
14,
525,
63,
3440,
8,
4391,
12,
31262,
29,
16,
9,
398,
327,
2654,
282,
5844,
2247,
370,
31262,
314,
4618,
402,
314,
4340,
370,
314,
1284,
402,
314,
267,
327,
3589,
4601,
267,
5844,
2247,
275,
16905,
83,
14,
4314,
8355,
267,
20163,
14,
525,
63,
3440,
8,
3770,
2247,
12,
31262,
29,
17,
9,
398,
327,
13704,
29130,
911,
2040,
24213,
402,
1564,
370,
506,
13810,
267,
2746,
14,
525,
63,
3440,
8,
3519,
12,
31262,
29,
17,
9,
398,
327,
437,
5528,
5689,
626,
365,
3544,
8917,
737,
314,
9048,
267,
22342,
561,
275,
16905,
83,
14,
40,
3532,
342,
267,
22342,
561,
14,
409,
63,
15880,
8,
19,
9,
398,
327,
2654,
282,
4002,
5528,
367,
314,
16777,
402,
314,
922,
267,
19368,
275,
16905,
83,
14,
4259,
480,
4724,
531,
267,
19368,
14,
525,
63,
3058,
360,
18218,
297,
2400,
336,
26,
291,
14,
1600,
1012,
267,
22342,
561,
14,
525,
63,
3440,
8,
9633,
12,
31262,
29,
16,
9,
267,
22342,
561,
14,
525,
63,
3440,
8,
12462,
14,
4314,
31150,
31262,
29,
17,
9,
267,
2746,
14,
525,
63,
3440,
8,
13061,
561,
12,
31262,
29,
16,
9,
398,
327,
2654,
4154,
17160,
370,
314,
3970,
267,
3970,
14,
525,
63,
3440,
8,
2119,
12,
31262,
29,
17,
9,
267,
327,
6944,
26,
340,
1265,
787,
10015,
282,
17160,
1808,
282,
2488,
3938,
4744,
6065,
267,
327,
334,
69,
14,
71,
14,
3959,
9,
17160,
4882,
12,
1265,
1929,
370,
5536,
314,
3938,
503,
7054,
267,
327,
687,
314,
2222,
13,
31994,
2488,
3970,
4975,
436,
1240,
641,
626,
267,
327,
370,
1706,
2195,
3938,
12,
325,
14,
71,
16781,
267,
327,
15346,
275,
3970,
14,
362,
63,
3440,
342,
267,
327,
15346,
14,
9475,
8,
3440,
12,
31262,
29,
17,
9,
339,
347,
664,
63,
2775,
63,
815,
8,
277,
12,
5542,
338,
960,
304,
267,
682,
354,
275,
291,
14,
13692,
14,
362,
63,
2775,
985,
8,
3269,
338,
960,
9,
267,
3623,
275,
291,
14,
13692,
14,
362,
63,
2775,
2354,
8,
335,
354,
9,
267,
372,
3623,
339,
347,
663,
63,
815,
8,
277,
12,
1318,
304,
267,
291,
14,
8122,
14,
409,
63,
505,
8,
505,
9,
339,
327,
24251,
7111,
51,
339,
347,
1050,
63,
2775,
8,
277,
12,
27354,
12,
3623,
304,
267,
408,
267
] |
[
199,
51,
415,
17589,
2893,
402,
282,
598,
316,
65,
2288,
3589,
2797,
283,
5713,
7025,
5061,
7,
199,
199,
1378,
4756,
652,
12,
1255,
486,
316,
65,
543,
314,
1414,
272,
2672,
486,
316,
65,
1553,
3112,
29,
5713,
5339,
5061,
199,
199,
390,
1077,
8649,
4702,
315,
314,
2451,
12748,
14,
199,
624,
199,
199,
504,
486,
316,
65,
492,
598,
316,
65,
5061,
199,
504,
486,
316,
65,
14,
8392,
492,
16905,
83,
199,
199,
3,
492,
1263,
1163,
4621,
1265,
2934,
2348,
306,
390,
1159,
282,
2366,
6701,
1,
199,
199,
533,
4932,
7025,
5061,
8,
39,
316,
65,
5061,
14,
7025,
5061,
304,
339,
347,
636,
826,
721,
277,
12,
289,
86,
304,
267,
408,
267,
961,
1083,
365,
2797,
1380,
314,
3589,
365,
6511,
367,
314,
221,
1642,
267,
900,
14,
221,
1124,
13692,
1040,
365,
282,
3659,
370,
314,
598,
316,
65,
334,
4443,
27354,
9,
5218,
14,
398,
2047,
1929,
370,
1240,
314,
17035,
11130,
436,
2066,
886,
1263,
2257,
267,
11097,
14,
267,
408,
267,
1613,
8,
5713,
7025,
5061,
12,
291,
2843,
826,
721,
13692,
9,
398,
327,
19519,
11097,
2348,
398,
327,
2790,
2005,
2860,
370,
4215,
4426,
402,
4052,
365,
5992,
316,
267,
327,
543,
1314,
3623,
267,
291,
14,
2682,
275,
488,
398,
327,
4804,
5355,
370,
2005,
19604,
13484,
626,
911,
315,
964,
2739,
267,
327,
402,
3623,
4474,
14,
221,
2047,
1443,
440,
1929,
3520,
10298,
641,
4052,
267,
327,
2195,
3589,
1630,
267,
289,
86,
14,
409,
63,
3058,
360,
525,
13,
2775,
297,
291,
14,
525,
63,
2775,
9,
267,
289,
86,
14,
409,
63,
3058,
360,
1807,
13,
2775,
297,
291,
14,
1807,
63,
2775,
9,
267,
289,
86,
14,
409,
63,
3058,
360,
2775,
13,
1461,
297,
291,
14,
12283,
63,
2894,
9,
339,
347,
1900,
63,
5885,
8,
277,
12,
3970,
304,
267,
408,
267,
961,
1083,
365,
2797,
1380,
314,
3589,
365,
10302,
14,
221,
2779,
14723,
314,
267,
17160,
1202,
701,
314,
3589,
1901,
314,
3938,
7054,
3032,
465,
267,
1124,
3600,
4345,
267,
961,
1083,
4293,
506,
2797,
9978,
5431,
340,
314,
3589,
365,
12123,
267,
436,
6876,
14,
221,
710,
1083,
1443,
506,
11684,
340,
2337,
365,
949,
17160,
367,
314,
267,
3589,
14,
398,
961,
2488,
2893,
4440,
314,
17160,
3938,
663,
282,
784,
941,
530,
17995,
267,
370,
1900,
314,
17160,
12,
1325,
1265,
883,
2597,
2951,
465,
16174,
675,
5027,
267,
4744,
6065,
4882,
2348,
340,
1265,
1454,
2934,
370,
2291,
1373,
3938,
663,
14,
267,
408,
267,
2746,
275,
16905,
83,
14,
54,
3532,
342,
267,
2746,
14,
409,
63,
8665,
63,
2063,
8,
20,
9,
398,
327,
642,
365,
282,
12050,
20907,
367,
10663,
8963,
626,
1736,
1902,
315,
267,
327,
282,
13763,
503,
17528,
16774,
14,
221,
2779,
2529,
282,
5689,
3970,
12,
267,
327,
282,
13704,
3938,
436,
376,
16774,
661,
7870,
297,
283,
11392,
358,
267,
20163,
12,
5584,
12,
16774,
275,
16905,
83,
14,
362,
63,
16039,
287,
471,
63,
1977,
8,
3600,
9,
267,
20163,
14,
409,
63,
8665,
63,
2063,
8,
20,
9,
267,
20163,
14,
409,
63,
15880,
8,
18,
9,
398,
327,
18146,
282,
1318,
3938,
370,
2498,
2005,
15794,
267,
291,
14,
1328,
6986,
275,
291,
14,
13692,
14,
362,
6986,
480,
26052,
6986,
401,
3144,
9,
267,
8900,
275,
16905,
83,
14,
1872,
11043,
8,
3823,
29,
549,
12,
14783,
29,
797,
9,
267,
8900,
14,
409,
63,
4246,
8,
277,
14,
1328,
6986,
9,
267,
291,
14,
8122,
275,
8900,
398,
327,
11726,
367,
15794,
436,
1050,
314,
1318,
3938,
543,
4573,
267,
327,
4596,
3938,
370,
31262,
465,
4346,
370,
5554,
9052,
267,
9513,
275,
16905,
83,
14,
3160,
480,
3694,
531,
267,
9513,
14,
409,
63,
3440,
8,
8122,
9,
267,
20163,
14,
525,
63,
3440,
8,
4391,
12,
31262,
29,
16,
9,
398,
327,
2654,
282,
5844,
2247,
370,
31262,
314,
4618,
402,
314,
4340,
370,
314,
1284,
402,
314,
267,
327,
3589,
4601,
267,
5844,
2247,
275,
16905,
83,
14,
4314,
8355,
267,
20163,
14,
525,
63,
3440,
8,
3770,
2247,
12,
31262,
29,
17,
9,
398,
327,
13704,
29130,
911,
2040,
24213,
402,
1564,
370,
506,
13810,
267,
2746,
14,
525,
63,
3440,
8,
3519,
12,
31262,
29,
17,
9,
398,
327,
437,
5528,
5689,
626,
365,
3544,
8917,
737,
314,
9048,
267,
22342,
561,
275,
16905,
83,
14,
40,
3532,
342,
267,
22342,
561,
14,
409,
63,
15880,
8,
19,
9,
398,
327,
2654,
282,
4002,
5528,
367,
314,
16777,
402,
314,
922,
267,
19368,
275,
16905,
83,
14,
4259,
480,
4724,
531,
267,
19368,
14,
525,
63,
3058,
360,
18218,
297,
2400,
336,
26,
291,
14,
1600,
1012,
267,
22342,
561,
14,
525,
63,
3440,
8,
9633,
12,
31262,
29,
16,
9,
267,
22342,
561,
14,
525,
63,
3440,
8,
12462,
14,
4314,
31150,
31262,
29,
17,
9,
267,
2746,
14,
525,
63,
3440,
8,
13061,
561,
12,
31262,
29,
16,
9,
398,
327,
2654,
4154,
17160,
370,
314,
3970,
267,
3970,
14,
525,
63,
3440,
8,
2119,
12,
31262,
29,
17,
9,
267,
327,
6944,
26,
340,
1265,
787,
10015,
282,
17160,
1808,
282,
2488,
3938,
4744,
6065,
267,
327,
334,
69,
14,
71,
14,
3959,
9,
17160,
4882,
12,
1265,
1929,
370,
5536,
314,
3938,
503,
7054,
267,
327,
687,
314,
2222,
13,
31994,
2488,
3970,
4975,
436,
1240,
641,
626,
267,
327,
370,
1706,
2195,
3938,
12,
325,
14,
71,
16781,
267,
327,
15346,
275,
3970,
14,
362,
63,
3440,
342,
267,
327,
15346,
14,
9475,
8,
3440,
12,
31262,
29,
17,
9,
339,
347,
664,
63,
2775,
63,
815,
8,
277,
12,
5542,
338,
960,
304,
267,
682,
354,
275,
291,
14,
13692,
14,
362,
63,
2775,
985,
8,
3269,
338,
960,
9,
267,
3623,
275,
291,
14,
13692,
14,
362,
63,
2775,
2354,
8,
335,
354,
9,
267,
372,
3623,
339,
347,
663,
63,
815,
8,
277,
12,
1318,
304,
267,
291,
14,
8122,
14,
409,
63,
505,
8,
505,
9,
339,
327,
24251,
7111,
51,
339,
347,
1050,
63,
2775,
8,
277,
12,
27354,
12,
3623,
304,
267,
408,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
steebchen/youtube-dl
|
youtube_dl/extractor/giantbomb.py
|
30
|
2928
|
from __future__ import unicode_literals
import re
import json
from .common import InfoExtractor
from ..utils import (
determine_ext,
int_or_none,
qualities,
unescapeHTML,
)
class GiantBombIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?giantbomb\.com/videos/(?P<display_id>[^/]+)/(?P<id>\d+-\d+)'
_TEST = {
'url': 'http://www.giantbomb.com/videos/quick-look-destiny-the-dark-below/2300-9782/',
'md5': 'c8ea694254a59246a42831155dec57ac',
'info_dict': {
'id': '2300-9782',
'display_id': 'quick-look-destiny-the-dark-below',
'ext': 'mp4',
'title': 'Quick Look: Destiny: The Dark Below',
'description': 'md5:0aa3aaf2772a41b91d44c63f30dfad24',
'duration': 2399,
'thumbnail': r're:^https?://.*\.jpg$',
}
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
display_id = mobj.group('display_id')
webpage = self._download_webpage(url, display_id)
title = self._og_search_title(webpage)
description = self._og_search_description(webpage)
thumbnail = self._og_search_thumbnail(webpage)
video = json.loads(unescapeHTML(self._search_regex(
r'data-video="([^"]+)"', webpage, 'data-video')))
duration = int_or_none(video.get('lengthSeconds'))
quality = qualities([
'f4m_low', 'progressive_low', 'f4m_high',
'progressive_high', 'f4m_hd', 'progressive_hd'])
formats = []
for format_id, video_url in video['videoStreams'].items():
if format_id == 'f4m_stream':
continue
ext = determine_ext(video_url)
if ext == 'f4m':
f4m_formats = self._extract_f4m_formats(video_url + '?hdcore=3.3.1', display_id)
if f4m_formats:
f4m_formats[0]['quality'] = quality(format_id)
formats.extend(f4m_formats)
elif ext == 'm3u8':
formats.extend(self._extract_m3u8_formats(
video_url, display_id, ext='mp4', entry_protocol='m3u8_native',
m3u8_id='hls', fatal=False))
else:
formats.append({
'url': video_url,
'format_id': format_id,
'quality': quality(format_id),
})
if not formats:
youtube_id = video.get('youtubeID')
if youtube_id:
return self.url_result(youtube_id, 'Youtube')
self._sort_formats(formats)
return {
'id': video_id,
'display_id': display_id,
'title': title,
'description': description,
'thumbnail': thumbnail,
'duration': duration,
'formats': formats,
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
6705,
63,
832,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
6420,
12107,
12,
272,
22221,
4943,
12,
199,
9,
421,
199,
533,
598,
73,
867,
34,
24370,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
6153,
867,
656,
887,
4537,
957,
15,
11418,
9448,
48,
28,
2918,
63,
344,
26906,
2447,
2229,
48,
28,
344,
3072,
68,
11,
2696,
68,
29600,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
6153,
867,
656,
887,
14,
957,
15,
11418,
15,
13239,
13,
11660,
13,
2614,
8952,
13,
1589,
13,
13625,
13,
12843,
15,
1789,
383,
13,
25,
23199,
3678,
267,
283,
1064,
21,
356,
283,
67,
24,
4489,
19421,
8306,
65,
1427,
11440,
65,
20,
16029,
845,
1229,
7778,
1641,
645,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1789,
383,
13,
25,
23199,
297,
288,
283,
2918,
63,
344,
356,
283,
13239,
13,
11660,
13,
2614,
8952,
13,
1589,
13,
13625,
13,
12843,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
19684,
12077,
26,
20547,
8952,
26,
710,
577,
1096,
6423,
674,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
16,
2158,
19,
31498,
9963,
18,
65,
2953,
66,
3328,
68,
1602,
67,
2766,
70,
1216,
1587,
350,
1194,
297,
288,
283,
5553,
356,
6546,
1020,
12,
288,
283,
8311,
356,
519,
3984,
23497,
2859,
32569,
8476,
4268,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
2929,
63,
344,
275,
14208,
14,
923,
360,
2918,
63,
344,
358,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2929,
63,
344,
9,
398,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
9,
267,
1369,
275,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
9,
267,
10062,
275,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
9,
398,
3991,
275,
2022,
14,
3640,
8,
22726,
4943,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
5121,
419,
13,
3722,
32391,
297,
9248,
12,
283,
576,
13,
3722,
7058,
398,
7373,
275,
1109,
63,
269,
63,
3592,
8,
3722,
14,
362,
360,
1267,
13165,
1333,
398,
11030,
275,
6420,
12107,
779,
288,
283,
70,
20,
77,
63,
674,
297,
283,
6595,
470,
3398,
63,
674,
297,
283,
70,
20,
77,
63,
6260,
297,
288,
283,
6595,
470,
3398,
63,
6260,
297,
283,
70,
20,
77,
63,
7952,
297,
283,
6595,
470,
3398,
63,
7952,
1105,
398,
6752,
275,
942,
267,
367,
1475,
63,
344,
12,
3991,
63,
633,
315,
3991,
459,
3722,
19358,
2278,
1744,
837,
288,
340,
1475,
63,
344,
508,
283,
70,
20,
77,
63,
1745,
356,
355,
1980,
288,
1599,
275,
6705,
63,
832,
8,
3722,
63,
633,
9,
288,
340,
1599,
508,
283,
70,
20,
77,
356,
355,
289,
20,
77,
63,
6321,
275,
291,
423,
5005,
63,
70,
20,
77,
63,
6321,
8,
3722,
63,
633,
435,
8720,
7952,
1018,
29,
19,
14,
19,
14,
17,
297,
2929,
63,
344,
9,
355,
340,
289,
20,
77,
63,
6321,
26,
490,
289,
20,
77,
63,
6321,
59,
16,
2733,
9161,
418,
275,
11030,
8,
908,
63,
344,
9,
490,
6752,
14,
2880,
8,
70,
20,
77,
63,
6321,
9,
288,
916,
1599,
508,
283,
77,
19,
85,
24,
356,
355,
6752,
14,
2880,
8,
277,
423,
5005,
63,
77,
19,
85,
24,
63,
6321,
8,
490,
3991,
63,
633,
12,
2929,
63,
344,
12,
1599,
534,
311,
20,
297,
2397,
63,
3922,
534,
77,
19,
85,
24,
63,
6106,
297,
490,
333,
19,
85,
24,
63,
344,
534,
30252,
297,
14294,
29,
797,
430,
288,
587,
26,
355,
6752,
14,
740,
2561,
490,
283,
633,
356,
3991,
63,
633,
12,
490,
283,
908,
63,
344,
356,
1475,
63,
344,
12,
490,
283,
9161,
356,
11030,
8,
908,
63,
344,
395,
355,
3828,
398,
340,
440,
6752,
26,
288,
22378,
63,
344,
275,
3991,
14,
362,
360,
9788,
998,
358,
288,
340,
22378,
63,
344,
26,
355,
372,
291,
14,
633,
63,
1099,
8,
9788,
63,
344,
12,
283,
57,
7715,
358,
398,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
2918,
63,
344,
356,
2929,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
5553,
356,
7373,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
6705,
63,
832,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
6420,
12107,
12,
272,
22221,
4943,
12,
199,
9,
421,
199,
533,
598,
73,
867,
34,
24370,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
6153,
867,
656,
887,
4537,
957,
15,
11418,
9448,
48,
28,
2918,
63,
344,
26906,
2447,
2229,
48,
28,
344,
3072,
68,
11,
2696,
68,
29600,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
6153,
867,
656,
887,
14,
957,
15,
11418,
15,
13239,
13,
11660,
13,
2614,
8952,
13,
1589,
13,
13625,
13,
12843,
15,
1789,
383,
13,
25,
23199,
3678,
267,
283,
1064,
21,
356,
283,
67,
24,
4489,
19421,
8306,
65,
1427,
11440,
65,
20,
16029,
845,
1229,
7778,
1641,
645,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1789,
383,
13,
25,
23199,
297,
288,
283,
2918,
63,
344,
356,
283,
13239,
13,
11660,
13,
2614,
8952,
13,
1589,
13,
13625,
13,
12843,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
19684,
12077,
26,
20547,
8952,
26,
710,
577,
1096,
6423,
674,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
16,
2158,
19,
31498,
9963,
18,
65,
2953,
66,
3328,
68,
1602,
67,
2766,
70,
1216,
1587,
350,
1194,
297,
288,
283,
5553,
356,
6546,
1020,
12,
288,
283,
8311,
356,
519,
3984,
23497,
2859,
32569,
8476,
4268,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
2929,
63,
344,
275,
14208,
14,
923,
360,
2918,
63,
344,
358,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2929,
63,
344,
9,
398,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
9,
267,
1369,
275,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
9,
267,
10062,
275,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
9,
398,
3991,
275,
2022,
14,
3640,
8,
22726,
4943,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
5121,
419,
13,
3722,
32391,
297,
9248,
12,
283,
576,
13,
3722,
7058,
398,
7373,
275,
1109,
63,
269,
63,
3592,
8,
3722,
14,
362,
360,
1267,
13165,
1333,
398,
11030,
275,
6420,
12107,
779,
288,
283,
70,
20,
77,
63,
674,
297,
283,
6595,
470,
3398,
63,
674,
297,
283,
70,
20,
77,
63,
6260,
297,
288,
283,
6595,
470,
3398,
63,
6260,
297,
283,
70,
20,
77,
63,
7952,
297,
283,
6595,
470,
3398,
63,
7952,
1105,
398,
6752,
275,
942,
267,
367,
1475,
63,
344,
12,
3991,
63,
633,
315,
3991,
459,
3722,
19358,
2278,
1744,
837,
288,
340,
1475,
63,
344,
508,
283,
70,
20,
77,
63,
1745,
356,
355,
1980,
288,
1599,
275,
6705,
63,
832,
8,
3722,
63,
633,
9,
288,
340,
1599,
508,
283,
70,
20,
77,
356,
355,
289,
20,
77,
63,
6321,
275,
291,
423,
5005,
63,
70,
20,
77,
63,
6321,
8,
3722,
63,
633,
435,
8720,
7952,
1018,
29,
19,
14,
19,
14,
17,
297,
2929,
63,
344,
9,
355,
340,
289,
20,
77,
63,
6321,
26,
490,
289,
20,
77,
63,
6321,
59,
16,
2733,
9161,
418,
275,
11030,
8,
908,
63,
344,
9,
490,
6752,
14,
2880,
8,
70,
20,
77,
63,
6321,
9,
288,
916,
1599,
508,
283,
77,
19,
85,
24,
356,
355,
6752,
14,
2880,
8,
277,
423,
5005,
63,
77,
19,
85,
24,
63,
6321,
8,
490,
3991,
63,
633,
12,
2929,
63,
344,
12,
1599,
534,
311,
20,
297,
2397,
63,
3922,
534,
77,
19,
85,
24,
63,
6106,
297,
490,
333,
19,
85,
24,
63,
344,
534,
30252,
297,
14294,
29,
797,
430,
288,
587,
26,
355,
6752,
14,
740,
2561,
490,
283,
633,
356,
3991,
63,
633,
12,
490,
283,
908,
63,
344,
356,
1475,
63,
344,
12,
490,
283,
9161,
356,
11030,
8,
908,
63,
344,
395,
355,
3828,
398,
340,
440,
6752,
26,
288,
22378,
63,
344,
275,
3991,
14,
362,
360,
9788,
998,
358,
288,
340,
22378,
63,
344,
26,
355,
372,
291,
14,
633,
63,
1099,
8,
9788,
63,
344,
12,
283,
57,
7715,
358,
398,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
2918,
63,
344,
356,
2929,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
5553,
356,
7373,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
guorendong/iridium-browser-ubuntu
|
third_party/webrtc/build/extra_gitignore.py
|
40
|
1443
|
#!/usr/bin/env python
# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
""" Adds extra patterns to the root .gitignore file.
Reads the contents of the filename given as the first argument and appends
them to the root .gitignore file. The new entires are intended to be additional
ignoring patterns, or negating patterns to override existing entries (man
gitignore for more details).
"""
import os
import sys
MODIFY_STRING = '# The following added by %s\n'
def main(argv):
if not argv[1]:
# Special case; do nothing.
return 0
modify_string = MODIFY_STRING % argv[0]
gitignore_file = os.path.dirname(argv[0]) + '/../../.gitignore'
lines = open(gitignore_file, 'r').readlines()
for i, line in enumerate(lines):
# Look for modify_string in the file to ensure we don't append the extra
# patterns more than once.
if line == modify_string:
lines = lines[:i]
break
lines.append(modify_string)
f = open(gitignore_file, 'w')
f.write(''.join(lines))
f.write(open(argv[1], 'r').read())
f.close()
if __name__ == '__main__':
sys.exit(main(sys.argv))
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
710,
6001,
50,
5708,
2199,
11462,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
199,
3,
626,
883,
506,
1911,
315,
314,
5113,
570,
315,
314,
1738,
402,
314,
1350,
199,
3,
3123,
14,
1626,
4722,
27925,
1264,
1061,
3324,
4481,
16085,
883,
506,
1911,
199,
3,
315,
314,
570,
31467,
1309,
51,
14,
221,
2900,
5914,
4655,
2199,
11462,
1443,
199,
3,
506,
1911,
315,
314,
10610,
570,
315,
314,
1738,
402,
314,
1350,
3123,
14,
199,
199,
624,
15747,
2402,
7970,
370,
314,
1738,
1275,
71,
5277,
7160,
570,
14,
199,
199,
23614,
314,
4072,
402,
314,
1788,
1627,
465,
314,
1642,
1423,
436,
1145,
3198,
199,
1589,
77,
370,
314,
1738,
1275,
71,
5277,
7160,
570,
14,
710,
892,
655,
280,
470,
787,
11619,
370,
506,
4722,
199,
1030,
6854,
7970,
12,
503,
14158,
1958,
7970,
370,
4278,
3411,
4811,
334,
1237,
199,
71,
5277,
7160,
367,
1655,
2436,
680,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
199,
31225,
63,
5353,
275,
3943,
710,
2569,
3483,
701,
450,
83,
60,
78,
7,
421,
199,
318,
2446,
8,
3020,
304,
523,
340,
440,
9238,
59,
17,
2189,
272,
327,
12568,
1930,
27,
886,
6548,
14,
272,
372,
378,
819,
2811,
63,
875,
275,
10362,
1914,
18114,
63,
5353,
450,
9238,
59,
16,
61,
523,
486,
5277,
7160,
63,
493,
275,
747,
14,
515,
14,
3475,
8,
3020,
59,
16,
566,
435,
1994,
9707,
14,
71,
5277,
7160,
7,
523,
2385,
275,
1551,
8,
71,
5277,
7160,
63,
493,
12,
283,
82,
1959,
9684,
342,
523,
367,
284,
12,
1004,
315,
3874,
8,
1278,
304,
272,
327,
12077,
367,
2811,
63,
875,
315,
314,
570,
370,
4868,
781,
2793,
1133,
5666,
314,
2402,
272,
327,
7970,
1655,
2419,
5403,
14,
272,
340,
1004,
508,
2811,
63,
875,
26,
489,
2385,
275,
2385,
1491,
73,
61,
489,
2059,
523,
2385,
14,
740,
8,
8951,
63,
875,
9,
819,
289,
275,
1551,
8,
71,
5277,
7160,
63,
493,
12,
283,
87,
358,
523,
289,
14,
952,
17840,
904,
8,
1278,
430,
523,
289,
14,
952,
8,
1490,
8,
3020,
59,
17,
467,
283,
82,
1959,
739,
1012,
523,
289,
14,
1600,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
8,
1274,
14,
3020,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6029,
710,
6001,
50,
5708,
2199,
11462,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
199,
3,
626,
883,
506,
1911,
315,
314,
5113,
570,
315,
314,
1738,
402,
314,
1350,
199,
3,
3123,
14,
1626,
4722,
27925,
1264,
1061,
3324,
4481,
16085,
883,
506,
1911,
199,
3,
315,
314,
570,
31467,
1309,
51,
14,
221,
2900,
5914,
4655,
2199,
11462,
1443,
199,
3,
506,
1911,
315,
314,
10610,
570,
315,
314,
1738,
402,
314,
1350,
3123,
14,
199,
199,
624,
15747,
2402,
7970,
370,
314,
1738,
1275,
71,
5277,
7160,
570,
14,
199,
199,
23614,
314,
4072,
402,
314,
1788,
1627,
465,
314,
1642,
1423,
436,
1145,
3198,
199,
1589,
77,
370,
314,
1738,
1275,
71,
5277,
7160,
570,
14,
710,
892,
655,
280,
470,
787,
11619,
370,
506,
4722,
199,
1030,
6854,
7970,
12,
503,
14158,
1958,
7970,
370,
4278,
3411,
4811,
334,
1237,
199,
71,
5277,
7160,
367,
1655,
2436,
680,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
199,
31225,
63,
5353,
275,
3943,
710,
2569,
3483,
701,
450,
83,
60,
78,
7,
421,
199,
318,
2446,
8,
3020,
304,
523,
340,
440,
9238,
59,
17,
2189,
272,
327,
12568,
1930,
27,
886,
6548,
14,
272,
372,
378,
819,
2811,
63,
875,
275,
10362,
1914,
18114,
63,
5353,
450,
9238,
59,
16,
61,
523,
486,
5277,
7160,
63,
493,
275,
747,
14,
515,
14,
3475,
8,
3020,
59,
16,
566,
435,
1994,
9707,
14,
71,
5277,
7160,
7,
523,
2385,
275,
1551,
8,
71,
5277,
7160,
63,
493,
12,
283,
82,
1959,
9684,
342,
523,
367,
284,
12,
1004,
315,
3874,
8,
1278,
304,
272,
327,
12077,
367,
2811,
63,
875,
315,
314,
570,
370,
4868,
781,
2793,
1133,
5666,
314,
2402,
272,
327,
7970,
1655,
2419,
5403,
14,
272,
340,
1004,
508,
2811,
63,
875,
26,
489,
2385,
275,
2385,
1491,
73,
61,
489,
2059,
523,
2385,
14,
740,
8,
8951,
63,
875,
9,
819,
289,
275,
1551,
8,
71,
5277,
7160,
63,
493,
12,
283,
87,
358,
523,
289,
14,
952,
17840,
904,
8,
1278,
430,
523,
289,
14,
952,
8,
1490,
8,
3020,
59,
17,
467,
283,
82,
1959,
739,
1012,
523,
289,
14,
1600,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
8,
1274,
14,
3020,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
enjaz/enjaz
|
niqati/templatetags/niqati_tags.py
|
2
|
2718
|
# -*- coding: utf-8 -*-
from django.core.urlresolvers import reverse
from django.template import Library
from django.utils.http import urlquote
import requests
from activities.models import Episode
from bulb.models import Request, Session
register = Library()
@register.simple_tag
def get_short_link(domain, endpoint, code):
"""
If the code has a short link, then return it.
Otherwise, generate it and return the result.
"""
if not code.short_link:
full_url = urlquote("http://%s%s?code=%s" % (domain, reverse("niqati:submit"), code.string))
response = requests.get(endpoint + full_url)
short_link = response.text
code.short_link = short_link
code.save()
return "<a href='%s'>%s</a>" % (code.short_link, code.short_link)
@register.filter
def get_description(code):
if not code.content_object:
return u"مُخصّصة ({})".format(code.note)
elif type(code.content_object) is Episode and code.containing_collections.exists():
activity_link = u"<a href=\"{}\">{}</a>".format(reverse('activities:show',
args=(code.content_object.activity.pk,)),
code.content_object)
category = code.containing_collections.first().category
if category.label == "Idea":
return u"صغت فكرة {}".format(activity_link)
elif category.label == "Organizer":
return u"نظّمت {}".format(activity_link)
elif category.label == "Participation":
return u"شاركت في {}".format(activity_link)
elif type(code.content_object) is Request:
book_link = u"<a href=\"{}\">{}</a>".format(reverse('bulb:show_book',
args=(code.content_object.book.pk,)),
code.content_object.book)
return u"ساهمت بكتاب " + book_link
elif type(code.content_object) is Session:
if code.points == 1:
action = u"حضرت"
elif code.points == 2:
action = u"نظمت"
elif code.points == 3:
action = u"انطلاقة المجموعة:"
group_link = u"<a href=\"{}\">{}</a>".format(reverse('bulb:show_group',
args=(code.content_object.group.pk,)),
code.content_object.group)
return action + u" جلسة {} لمجموعة {}".format(code.content_object.title, group_link)
else:
return "<span class=\"english-field\">{}</span>".format(code.string)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
221,
1882,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1160,
492,
11243,
199,
504,
1639,
14,
1208,
14,
1014,
492,
1166,
3513,
199,
646,
4145,
199,
199,
504,
30744,
14,
992,
492,
27255,
6045,
199,
504,
330,
348,
66,
14,
992,
492,
4784,
12,
8596,
421,
199,
2683,
275,
11243,
342,
199,
199,
32,
2683,
14,
4129,
63,
1450,
199,
318,
664,
63,
3612,
63,
1073,
8,
2261,
12,
6037,
12,
1233,
304,
272,
408,
272,
982,
314,
1233,
965,
282,
3974,
2142,
12,
2066,
372,
652,
14,
272,
6630,
12,
3550,
652,
436,
372,
314,
754,
14,
272,
408,
272,
340,
440,
1233,
14,
3612,
63,
1073,
26,
267,
2615,
63,
633,
275,
1166,
3513,
480,
1014,
13827,
83,
5,
83,
31,
600,
2458,
83,
2,
450,
334,
2261,
12,
3837,
480,
8445,
81,
2159,
26,
7275,
1288,
1233,
14,
875,
430,
267,
1177,
275,
4145,
14,
362,
8,
6520,
435,
2615,
63,
633,
9,
267,
3974,
63,
1073,
275,
1177,
14,
505,
267,
1233,
14,
3612,
63,
1073,
275,
3974,
63,
1073,
267,
1233,
14,
2117,
342,
339,
372,
3886,
65,
4369,
9569,
83,
7,
6598,
83,
1108,
65,
4335,
450,
334,
600,
14,
3612,
63,
1073,
12,
1233,
14,
3612,
63,
1073,
9,
199,
199,
32,
2683,
14,
1541,
199,
318,
664,
63,
1802,
8,
600,
304,
272,
340,
440,
1233,
14,
1317,
63,
785,
26,
267,
372,
399,
2,
9789,
150,
238,
26321,
149,
114,
150,
240,
149,
114,
22863,
11459,
25974,
908,
8,
600,
14,
4610,
9,
272,
916,
730,
8,
600,
14,
1317,
63,
785,
9,
365,
27255,
6045,
436,
1233,
14,
16133,
63,
7882,
14,
2444,
837,
267,
10679,
63,
1073,
275,
399,
17030,
65,
4369,
8178,
24423,
1743,
2440,
1108,
65,
23167,
908,
8,
4471,
360,
27442,
26,
2384,
297,
18295,
1249,
2687,
600,
14,
1317,
63,
785,
14,
8240,
14,
2051,
16965,
9144,
1233,
14,
1317,
63,
785,
9,
267,
4637,
275,
1233,
14,
16133,
63,
7882,
14,
2246,
1252,
3710,
267,
340,
4637,
14,
1302,
508,
298,
41,
25395,
582,
288,
372,
399,
2,
149,
114,
149,
119,
14276,
221,
18570,
150,
226,
13273,
22863,
8352,
908,
8,
8240,
63,
1073,
9,
267,
916,
4637,
14,
1302,
508,
298,
11014,
290,
1793,
582,
288,
372,
399,
2,
11056,
149,
117,
150,
240,
9789,
14276,
8352,
908,
8,
8240,
63,
1073,
9,
267,
916,
4637,
14,
1302,
508,
298,
1262,
31089,
387,
296,
582,
288,
372,
399,
2,
32010,
26837,
150,
226,
14276,
221,
18570,
15441,
8352,
908,
8,
8240,
63,
1073,
9,
272,
916,
730,
8,
600,
14,
1317,
63,
785,
9,
365,
4784,
26,
267,
6719,
63,
1073,
275,
399,
17030,
65,
4369,
8178,
24423,
1743,
2440,
1108,
65,
23167,
908,
8,
4471,
360,
25792,
66,
26,
2384,
63,
2706,
297,
15491,
1249,
2687,
600,
14,
1317,
63,
785,
14,
2706,
14,
2051,
16965,
8105,
1233,
14,
1317,
63,
785,
14,
2706,
9,
267,
372,
399,
2,
18438,
6494,
10687,
9789,
14276,
8702,
102,
150,
226,
14276,
11321,
102,
298,
435,
6719,
63,
1073,
272,
916,
730,
8,
600,
14,
1317,
63,
785,
9,
365,
8596,
26,
267,
340,
1233,
14,
3438,
508,
413,
26,
288,
1595,
275,
399,
2,
24795,
149,
115,
13273,
14276,
2,
267,
916,
1233,
14,
3438,
508,
499,
26,
288,
1595,
275,
399,
2,
11056,
149,
117,
9789,
14276,
2,
267,
916,
1233,
14,
3438,
508,
650,
26,
288,
1595,
275,
399,
2,
6494,
11056,
149,
116,
8403,
6494,
25202,
22863,
20022,
9789,
30645,
9789,
9012,
20328,
22863,
5424,
267,
1572,
63,
1073,
275,
399,
17030,
65,
4369,
8178,
24423,
1743,
2440,
1108,
65,
23167,
908,
8,
4471,
360,
25792,
66,
26,
2384,
63,
923,
297,
14663,
1249,
2687,
600,
14,
1317,
63,
785,
14,
923,
14,
2051,
16965,
9349,
1233,
14,
1317,
63,
785,
14,
923,
9,
267,
372,
1595,
435,
399,
2,
8702,
106,
8403,
18438,
22863,
1052,
29023,
9789,
30645,
9789,
9012,
20328,
22863,
8352,
908,
8,
600,
14,
1317,
63,
785,
14,
1213,
12,
1572,
63,
1073,
9,
272,
587,
26,
267,
372,
3886,
3751,
1021,
8178,
17872,
13,
698,
60,
1743,
2440,
1108,
3751,
23167,
908,
8,
600,
14,
875,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
221,
1882,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1160,
492,
11243,
199,
504,
1639,
14,
1208,
14,
1014,
492,
1166,
3513,
199,
646,
4145,
199,
199,
504,
30744,
14,
992,
492,
27255,
6045,
199,
504,
330,
348,
66,
14,
992,
492,
4784,
12,
8596,
421,
199,
2683,
275,
11243,
342,
199,
199,
32,
2683,
14,
4129,
63,
1450,
199,
318,
664,
63,
3612,
63,
1073,
8,
2261,
12,
6037,
12,
1233,
304,
272,
408,
272,
982,
314,
1233,
965,
282,
3974,
2142,
12,
2066,
372,
652,
14,
272,
6630,
12,
3550,
652,
436,
372,
314,
754,
14,
272,
408,
272,
340,
440,
1233,
14,
3612,
63,
1073,
26,
267,
2615,
63,
633,
275,
1166,
3513,
480,
1014,
13827,
83,
5,
83,
31,
600,
2458,
83,
2,
450,
334,
2261,
12,
3837,
480,
8445,
81,
2159,
26,
7275,
1288,
1233,
14,
875,
430,
267,
1177,
275,
4145,
14,
362,
8,
6520,
435,
2615,
63,
633,
9,
267,
3974,
63,
1073,
275,
1177,
14,
505,
267,
1233,
14,
3612,
63,
1073,
275,
3974,
63,
1073,
267,
1233,
14,
2117,
342,
339,
372,
3886,
65,
4369,
9569,
83,
7,
6598,
83,
1108,
65,
4335,
450,
334,
600,
14,
3612,
63,
1073,
12,
1233,
14,
3612,
63,
1073,
9,
199,
199,
32,
2683,
14,
1541,
199,
318,
664,
63,
1802,
8,
600,
304,
272,
340,
440,
1233,
14,
1317,
63,
785,
26,
267,
372,
399,
2,
9789,
150,
238,
26321,
149,
114,
150,
240,
149,
114,
22863,
11459,
25974,
908,
8,
600,
14,
4610,
9,
272,
916,
730,
8,
600,
14,
1317,
63,
785,
9,
365,
27255,
6045,
436,
1233,
14,
16133,
63,
7882,
14,
2444,
837,
267,
10679,
63,
1073,
275,
399,
17030,
65,
4369,
8178,
24423,
1743,
2440,
1108,
65,
23167,
908,
8,
4471,
360,
27442,
26,
2384,
297,
18295,
1249,
2687,
600,
14,
1317,
63,
785,
14,
8240,
14,
2051,
16965,
9144,
1233,
14,
1317,
63,
785,
9,
267,
4637,
275,
1233,
14,
16133,
63,
7882,
14,
2246,
1252,
3710,
267,
340,
4637,
14,
1302,
508,
298,
41,
25395,
582,
288,
372,
399,
2,
149,
114,
149,
119,
14276,
221,
18570,
150,
226,
13273,
22863,
8352,
908,
8,
8240,
63,
1073,
9,
267,
916,
4637,
14,
1302,
508,
298,
11014,
290,
1793,
582,
288,
372,
399,
2,
11056,
149,
117,
150,
240,
9789,
14276,
8352,
908,
8,
8240,
63,
1073,
9,
267,
916,
4637,
14,
1302,
508,
298,
1262,
31089,
387,
296,
582,
288,
372,
399,
2,
32010,
26837,
150,
226,
14276,
221,
18570,
15441,
8352,
908,
8,
8240,
63,
1073,
9,
272,
916,
730,
8,
600,
14,
1317,
63,
785,
9,
365,
4784,
26,
267,
6719,
63,
1073,
275,
399,
17030,
65,
4369,
8178,
24423,
1743,
2440,
1108,
65,
23167,
908,
8,
4471,
360,
25792,
66,
26,
2384,
63,
2706,
297,
15491,
1249,
2687,
600,
14,
1317,
63,
785,
14,
2706,
14,
2051,
16965,
8105,
1233,
14,
1317,
63,
785,
14,
2706,
9,
267,
372,
399,
2,
18438,
6494,
10687,
9789,
14276,
8702,
102,
150,
226,
14276,
11321,
102,
298,
435,
6719,
63,
1073,
272,
916,
730,
8,
600,
14,
1317,
63,
785,
9,
365,
8596,
26,
267,
340,
1233,
14,
3438,
508,
413,
26,
288,
1595,
275,
399,
2,
24795,
149,
115,
13273,
14276,
2,
267,
916,
1233,
14,
3438,
508,
499,
26,
288,
1595,
275,
399,
2,
11056,
149,
117,
9789,
14276,
2,
267,
916,
1233,
14,
3438,
508,
650,
26,
288,
1595,
275,
399,
2,
6494,
11056,
149,
116,
8403,
6494,
25202,
22863,
20022,
9789,
30645,
9789,
9012,
20328,
22863,
5424,
267,
1572,
63,
1073,
275,
399,
17030,
65,
4369,
8178,
24423,
1743,
2440,
1108,
65,
23167,
908,
8,
4471,
360,
25792,
66,
26,
2384,
63,
923,
297,
14663,
1249,
2687,
600,
14,
1317,
63,
785,
14,
923,
14,
2051,
16965,
9349,
1233,
14,
1317,
63,
785,
14,
923,
9,
267,
372,
1595,
435,
399,
2,
8702,
106,
8403,
18438,
22863,
1052,
29023,
9789,
30645,
9789,
9012,
20328,
22863,
8352,
908,
8,
600,
14,
1317,
63,
785,
14,
1213,
12,
1572,
63,
1073,
9,
272,
587,
26,
267,
372,
3886,
3751,
1021,
8178,
17872,
13,
698,
60,
1743,
2440,
1108,
3751,
23167,
908,
8,
600,
14,
875,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
drmrd/ansible
|
lib/ansible/modules/network/aci/aci_access_port_to_interface_policy_leaf_profile.py
|
2
|
11226
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2017, Bruno Calogero <brunocalogero@hotmail.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 = r'''
---
module: aci_access_port_to_interface_policy_leaf_profile
short_description: Manage Fabric interface policy leaf profile interface selectors (infra:HPortS, infra:RsAccBaseGrp, infra:PortBlk)
description:
- Manage Fabric interface policy leaf profile interface selectors on Cisco ACI fabrics.
notes:
- More information about the internal APIC classes B(infra:HPortS), B(infra:RsAccBaseGrp) and B(infra:PortBlk) from
L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/)
author:
- Bruno Calogero (@brunocalogero)
version_added: '2.5'
options:
leaf_interface_profile:
description:
- The name of the Fabric access policy leaf interface profile.
required: yes
aliases: [ leaf_interface_profile_name ]
access_port_selector:
description:
- The name of the Fabric access policy leaf interface profile access port selector.
required: yes
aliases: [ name, access_port_selector_name ]
description:
description:
- The description to assign to the C(access_port_selector)
leaf_port_blk:
description:
- The name of the Fabric access policy leaf interface profile access port block.
required: yes
aliases: [ leaf_port_blk_name ]
leaf_port_blk_description:
description:
- The description to assign to the C(leaf_port_blk)
required: no
from:
description:
- The beggining (from range) of the port range block for the leaf access port block.
required: yes
aliases: [ fromPort, from_port_range ]
to:
description:
- The end (to range) of the port range block for the leaf access port block.
required: yes
aliases: [ toPort, to_port_range ]
policy_group:
description:
- The name of the fabric access policy group to be associated with the leaf interface profile interface selector.
aliases: [ policy_group_name ]
interface_type:
version_added: '2.6'
description:
- The type of interface for the static EPG deployement.
choices: [ fex, port_channel, switch_port, vpc ]
default: switch_port
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: aci
'''
EXAMPLES = r'''
- name: Associate an Interface Access Port Selector to an Interface Policy Leaf Profile with a Policy Group
aci_access_port_to_interface_policy_leaf_profile:
host: apic
username: admin
password: SomeSecretPassword
leaf_interface_profile: leafintprfname
access_port_selector: accessportselectorname
leaf_port_blk: leafportblkname
from: 13
to: 16
policy_group: policygroupname
state: present
- name: Associate an interface access port selector to an Interface Policy Leaf Profile (w/o policy group) (check if this works)
aci_access_port_to_interface_policy_leaf_profile:
host: apic
username: admin
password: SomeSecretPassword
leaf_interface_profile: leafintprfname
access_port_selector: accessportselectorname
leaf_port_blk: leafportblkname
from: 13
to: 16
state: present
- name: Remove an interface access port selector associated with an Interface Policy Leaf Profile
aci_access_port_to_interface_policy_leaf_profile:
host: apic
username: admin
password: SomeSecretPassword
leaf_interface_profile: leafintprfname
access_port_selector: accessportselectorname
state: absent
- name: Query Specific access_port_selector under given leaf_interface_profile
aci_access_port_to_interface_policy_leaf_profile:
host: apic
username: admin
password: SomeSecretPassword
leaf_interface_profile: leafintprfname
access_port_selector: accessportselectorname
state: query
'''
RETURN = r'''
current:
description: The existing configuration from the APIC after the module has finished
returned: success
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
error:
description: The error information as returned from the APIC
returned: failure
type: dict
sample:
{
"code": "122",
"text": "unknown managed object class foo"
}
raw:
description: The raw output returned by the APIC REST API (xml or json)
returned: parse error
type: string
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
sent:
description: The actual/minimal configuration pushed to the APIC
returned: info
type: list
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment"
}
}
}
previous:
description: The original configuration from the APIC before the module has started
returned: info
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
proposed:
description: The assembled configuration from the user-provided parameters
returned: info
type: dict
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"name": "production"
}
}
}
filter_string:
description: The filter string used for the request
returned: failure or debug
type: string
sample: ?rsp-prop-include=config-only
method:
description: The HTTP method used for the request to the APIC
returned: failure or debug
type: string
sample: POST
response:
description: The HTTP response from the APIC
returned: failure or debug
type: string
sample: OK (30 bytes)
status:
description: The HTTP status from the APIC
returned: failure or debug
type: int
sample: 200
url:
description: The HTTP url used for the request to the APIC
returned: failure or debug
type: string
sample: https://10.11.12.13/api/mo/uni/tn-production.json
'''
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule
def main():
argument_spec = aci_argument_spec()
argument_spec.update({
'leaf_interface_profile': dict(type='str', aliases=['leaf_interface_profile_name']), # Not required for querying all objects
'access_port_selector': dict(type='str', aliases=['name', 'access_port_selector_name']), # Not required for querying all objects
'description': dict(typ='str'),
'leaf_port_blk': dict(type='str', aliases=['leaf_port_blk_name']),
'leaf_port_blk_description': dict(type='str'),
# NOTE: Keyword 'from' is a reserved word in python, so we need it as a string
'from': dict(type='str', aliases=['fromPort', 'from_port_range']),
'to': dict(type='str', aliases=['toPort', 'to_port_range']),
'policy_group': dict(type='str', aliases=['policy_group_name']),
'interface_type': dict(type='str', default='switch_port', choices=['fex', 'port_channel', 'switch_port', 'vpc']),
'state': dict(type='str', default='present', choices=['absent', 'present', 'query']),
})
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['leaf_interface_profile', 'access_port_selector']],
['state', 'present', ['leaf_interface_profile', 'access_port_selector']],
],
)
leaf_interface_profile = module.params['leaf_interface_profile']
access_port_selector = module.params['access_port_selector']
description = module.params['description']
leaf_port_blk = module.params['leaf_port_blk']
leaf_port_blk_description = module.params['leaf_port_blk_description']
from_ = module.params['from']
to_ = module.params['to']
policy_group = module.params['policy_group']
interface_type = module.params['interface_type']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='infraAccPortP',
aci_rn='infra/accportprof-{0}'.format(leaf_interface_profile),
filter_target='eq(infraAccPortP.name, "{0}")'.format(leaf_interface_profile),
module_object=leaf_interface_profile
),
subclass_1=dict(
aci_class='infraHPortS',
# NOTE: normal rn: hports-{name}-typ-{type}, hence here hardcoded to range for purposes of module
aci_rn='hports-{0}-typ-range'.format(access_port_selector),
filter_target='eq(infraHPortS.name, "{0}")'.format(access_port_selector),
module_object=access_port_selector,
),
child_classes=['infraPortBlk', 'infraRsAccBaseGrp']
)
INTERFACE_TYPE_MAPPING = dict(
fex='uni/infra/funcprof/accportgrp-{0}'.format(policy_group),
port_channel='uni/infra/funcprof/accbundle-{0}'.format(policy_group),
switch_port='uni/infra/funcprof/accportgrp-{0}'.format(policy_group),
vpc='uni/infra/funcprof/accbundle-{0}'.format(policy_group),
)
aci.get_existing()
if state == 'present':
aci.payload(
aci_class='infraHPortS',
class_config=dict(
descr=description,
name=access_port_selector,
),
child_configs=[
dict(
infraPortBlk=dict(
attributes=dict(
descr=leaf_port_blk_description,
name=leaf_port_blk,
fromPort=from_,
toPort=to_,
),
),
),
dict(
infraRsAccBaseGrp=dict(
attributes=dict(
tDn=INTERFACE_TYPE_MAPPING[interface_type],
),
),
),
],
)
aci.get_diff(aci_class='infraHPortS')
aci.post_config()
elif state == 'absent':
aci.delete_config()
aci.exit_json()
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,
1898,
26,
334,
67,
9,
9708,
12,
699,
1065,
79,
8256,
79,
836,
79,
665,
66,
1065,
679,
12201,
836,
79,
32,
8885,
1198,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
19631,
63,
2732,
63,
719,
63,
475,
63,
3266,
63,
3185,
63,
8914,
63,
2913,
199,
3612,
63,
1802,
26,
14944,
481,
2129,
3217,
4592,
11747,
4690,
3217,
9759,
83,
334,
19505,
26,
40,
4313,
51,
12,
28890,
26,
28868,
26828,
1563,
39,
4599,
12,
28890,
26,
4313,
34,
23333,
9,
199,
1802,
26,
199,
13,
14944,
481,
2129,
3217,
4592,
11747,
4690,
3217,
9759,
83,
641,
28356,
437,
3553,
31507,
11818,
14,
199,
5983,
26,
199,
13,
16917,
2556,
3595,
314,
5007,
25418,
3992,
699,
8,
19505,
26,
40,
4313,
51,
395,
699,
8,
19505,
26,
28868,
26828,
1563,
39,
4599,
9,
436,
699,
8,
19505,
26,
4313,
34,
23333,
9,
687,
523,
491,
8,
1589,
25418,
8259,
17064,
5822,
3659,
12,
2859,
921,
11071,
14,
19597,
14,
957,
15,
4757,
15,
20789,
13,
77,
1017,
13,
1121,
24793,
199,
2502,
26,
199,
13,
699,
1065,
79,
8256,
79,
836,
79,
8593,
66,
1065,
679,
12201,
836,
79,
9,
199,
1023,
63,
3270,
26,
283,
18,
14,
21,
7,
199,
1419,
26,
523,
11747,
63,
3266,
63,
2913,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
481,
2129,
2879,
4592,
11747,
3217,
4690,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
11747,
63,
3266,
63,
2913,
63,
354,
1622,
523,
2879,
63,
719,
63,
6662,
26,
272,
1369,
26,
272,
446,
221,
710,
536,
402,
314,
481,
2129,
2879,
4592,
11747,
3217,
4690,
2879,
1844,
9759,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
536,
12,
2879,
63,
719,
63,
6662,
63,
354,
1622,
523,
1369,
26,
272,
1369,
26,
272,
446,
710,
1369,
370,
5090,
370,
314,
445,
8,
2732,
63,
719,
63,
6662,
9,
523,
11747,
63,
719,
63,
14023,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
481,
2129,
2879,
4592,
11747,
3217,
4690,
2879,
1844,
1853,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
11747,
63,
719,
63,
14023,
63,
354,
1622,
523,
11747,
63,
719,
63,
14023,
63,
1802,
26,
272,
1369,
26,
272,
446,
710,
1369,
370,
5090,
370,
314,
445,
8,
8914,
63,
719,
63,
14023,
9,
272,
1415,
26,
949,
523,
687,
26,
272,
1369,
26,
272,
446,
710,
31191,
903,
316,
334,
504,
1425,
9,
402,
314,
1844,
1425,
1853,
367,
314,
11747,
2879,
1844,
1853,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
687,
4313,
12,
687,
63,
719,
63,
1842,
1622,
523,
370,
26,
272,
1369,
26,
272,
446,
710,
1284,
334,
475,
1425,
9,
402,
314,
1844,
1425,
1853,
367,
314,
11747,
2879,
1844,
1853,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
370,
4313,
12,
370,
63,
719,
63,
1842,
1622,
523,
4592,
63,
923,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
2630,
2879,
4592,
1572,
370,
506,
4568,
543,
314,
11747,
3217,
4690,
3217,
9759,
14,
272,
5481,
26,
359,
4592,
63,
923,
63,
354,
1622,
523,
3217,
63,
466,
26,
272,
1015,
63,
3270,
26,
283,
18,
14,
22,
7,
272,
1369,
26,
272,
446,
710,
730,
402,
3217,
367,
314,
2955,
662,
11115,
12287,
69,
434,
14,
272,
3415,
26,
359,
289,
476,
12,
1844,
63,
2775,
12,
6258,
63,
719,
12,
12830,
1622,
272,
849,
26,
6258,
63,
719,
523,
1174,
26,
272,
1369,
26,
272,
446,
3645,
445,
8,
1881,
9,
503,
445,
8,
5575,
9,
367,
7791,
503,
12881,
14,
272,
446,
3645,
445,
8,
1131,
9,
367,
13778,
376,
909,
503,
3663,
2251,
14,
272,
3415,
26,
359,
9552,
12,
3451,
12,
1827,
1622,
272,
849,
26,
3451,
199,
11036,
63,
9970,
63,
7677,
26,
19631,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
24207,
323,
376,
14816,
11003,
10977,
3240,
3283,
370,
376,
14816,
18141,
27836,
14386,
543,
282,
18141,
5611,
523,
19631,
63,
2732,
63,
719,
63,
475,
63,
3266,
63,
3185,
63,
8914,
63,
2913,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
11747,
63,
3266,
63,
2913,
26,
11747,
442,
2700,
5252,
272,
2879,
63,
719,
63,
6662,
26,
2879,
719,
6662,
354,
272,
11747,
63,
719,
63,
14023,
26,
11747,
719,
14023,
354,
272,
687,
26,
4944,
272,
370,
26,
3193,
272,
4592,
63,
923,
26,
4592,
923,
354,
272,
1174,
26,
3451,
199,
199,
13,
536,
26,
24207,
323,
376,
3217,
2879,
1844,
9759,
370,
376,
14816,
18141,
27836,
14386,
334,
87,
15,
79,
4592,
1572,
9,
334,
1074,
340,
642,
5419,
9,
523,
19631,
63,
2732,
63,
719,
63,
475,
63,
3266,
63,
3185,
63,
8914,
63,
2913,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
11747,
63,
3266,
63,
2913,
26,
11747,
442,
2700,
5252,
272,
2879,
63,
719,
63,
6662,
26,
2879,
719,
6662,
354,
272,
11747,
63,
719,
63,
14023,
26,
11747,
719,
14023,
354,
272,
687,
26,
4944,
272,
370,
26,
3193,
272,
1174,
26,
3451,
199,
199,
13,
536,
26,
5852,
376,
3217,
2879,
1844,
9759,
4568,
543,
376,
14816,
18141,
27836,
14386,
523,
19631,
63,
2732,
63,
719,
63,
475,
63,
3266,
63,
3185,
63,
8914,
63,
2913,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
11747,
63,
3266,
63,
2913,
26,
11747,
442
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
26,
334,
67,
9,
9708,
12,
699,
1065,
79,
8256,
79,
836,
79,
665,
66,
1065,
679,
12201,
836,
79,
32,
8885,
1198,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
19631,
63,
2732,
63,
719,
63,
475,
63,
3266,
63,
3185,
63,
8914,
63,
2913,
199,
3612,
63,
1802,
26,
14944,
481,
2129,
3217,
4592,
11747,
4690,
3217,
9759,
83,
334,
19505,
26,
40,
4313,
51,
12,
28890,
26,
28868,
26828,
1563,
39,
4599,
12,
28890,
26,
4313,
34,
23333,
9,
199,
1802,
26,
199,
13,
14944,
481,
2129,
3217,
4592,
11747,
4690,
3217,
9759,
83,
641,
28356,
437,
3553,
31507,
11818,
14,
199,
5983,
26,
199,
13,
16917,
2556,
3595,
314,
5007,
25418,
3992,
699,
8,
19505,
26,
40,
4313,
51,
395,
699,
8,
19505,
26,
28868,
26828,
1563,
39,
4599,
9,
436,
699,
8,
19505,
26,
4313,
34,
23333,
9,
687,
523,
491,
8,
1589,
25418,
8259,
17064,
5822,
3659,
12,
2859,
921,
11071,
14,
19597,
14,
957,
15,
4757,
15,
20789,
13,
77,
1017,
13,
1121,
24793,
199,
2502,
26,
199,
13,
699,
1065,
79,
8256,
79,
836,
79,
8593,
66,
1065,
679,
12201,
836,
79,
9,
199,
1023,
63,
3270,
26,
283,
18,
14,
21,
7,
199,
1419,
26,
523,
11747,
63,
3266,
63,
2913,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
481,
2129,
2879,
4592,
11747,
3217,
4690,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
11747,
63,
3266,
63,
2913,
63,
354,
1622,
523,
2879,
63,
719,
63,
6662,
26,
272,
1369,
26,
272,
446,
221,
710,
536,
402,
314,
481,
2129,
2879,
4592,
11747,
3217,
4690,
2879,
1844,
9759,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
536,
12,
2879,
63,
719,
63,
6662,
63,
354,
1622,
523,
1369,
26,
272,
1369,
26,
272,
446,
710,
1369,
370,
5090,
370,
314,
445,
8,
2732,
63,
719,
63,
6662,
9,
523,
11747,
63,
719,
63,
14023,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
481,
2129,
2879,
4592,
11747,
3217,
4690,
2879,
1844,
1853,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
11747,
63,
719,
63,
14023,
63,
354,
1622,
523,
11747,
63,
719,
63,
14023,
63,
1802,
26,
272,
1369,
26,
272,
446,
710,
1369,
370,
5090,
370,
314,
445,
8,
8914,
63,
719,
63,
14023,
9,
272,
1415,
26,
949,
523,
687,
26,
272,
1369,
26,
272,
446,
710,
31191,
903,
316,
334,
504,
1425,
9,
402,
314,
1844,
1425,
1853,
367,
314,
11747,
2879,
1844,
1853,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
687,
4313,
12,
687,
63,
719,
63,
1842,
1622,
523,
370,
26,
272,
1369,
26,
272,
446,
710,
1284,
334,
475,
1425,
9,
402,
314,
1844,
1425,
1853,
367,
314,
11747,
2879,
1844,
1853,
14,
272,
1415,
26,
9456,
272,
5481,
26,
359,
370,
4313,
12,
370,
63,
719,
63,
1842,
1622,
523,
4592,
63,
923,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
2630,
2879,
4592,
1572,
370,
506,
4568,
543,
314,
11747,
3217,
4690,
3217,
9759,
14,
272,
5481,
26,
359,
4592,
63,
923,
63,
354,
1622,
523,
3217,
63,
466,
26,
272,
1015,
63,
3270,
26,
283,
18,
14,
22,
7,
272,
1369,
26,
272,
446,
710,
730,
402,
3217,
367,
314,
2955,
662,
11115,
12287,
69,
434,
14,
272,
3415,
26,
359,
289,
476,
12,
1844,
63,
2775,
12,
6258,
63,
719,
12,
12830,
1622,
272,
849,
26,
6258,
63,
719,
523,
1174,
26,
272,
1369,
26,
272,
446,
3645,
445,
8,
1881,
9,
503,
445,
8,
5575,
9,
367,
7791,
503,
12881,
14,
272,
446,
3645,
445,
8,
1131,
9,
367,
13778,
376,
909,
503,
3663,
2251,
14,
272,
3415,
26,
359,
9552,
12,
3451,
12,
1827,
1622,
272,
849,
26,
3451,
199,
11036,
63,
9970,
63,
7677,
26,
19631,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
24207,
323,
376,
14816,
11003,
10977,
3240,
3283,
370,
376,
14816,
18141,
27836,
14386,
543,
282,
18141,
5611,
523,
19631,
63,
2732,
63,
719,
63,
475,
63,
3266,
63,
3185,
63,
8914,
63,
2913,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
11747,
63,
3266,
63,
2913,
26,
11747,
442,
2700,
5252,
272,
2879,
63,
719,
63,
6662,
26,
2879,
719,
6662,
354,
272,
11747,
63,
719,
63,
14023,
26,
11747,
719,
14023,
354,
272,
687,
26,
4944,
272,
370,
26,
3193,
272,
4592,
63,
923,
26,
4592,
923,
354,
272,
1174,
26,
3451,
199,
199,
13,
536,
26,
24207,
323,
376,
3217,
2879,
1844,
9759,
370,
376,
14816,
18141,
27836,
14386,
334,
87,
15,
79,
4592,
1572,
9,
334,
1074,
340,
642,
5419,
9,
523,
19631,
63,
2732,
63,
719,
63,
475,
63,
3266,
63,
3185,
63,
8914,
63,
2913,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
11747,
63,
3266,
63,
2913,
26,
11747,
442,
2700,
5252,
272,
2879,
63,
719,
63,
6662,
26,
2879,
719,
6662,
354,
272,
11747,
63,
719,
63,
14023,
26,
11747,
719,
14023,
354,
272,
687,
26,
4944,
272,
370,
26,
3193,
272,
1174,
26,
3451,
199,
199,
13,
536,
26,
5852,
376,
3217,
2879,
1844,
9759,
4568,
543,
376,
14816,
18141,
27836,
14386,
523,
19631,
63,
2732,
63,
719,
63,
475,
63,
3266,
63,
3185,
63,
8914,
63,
2913,
26,
272,
1591,
26,
2771,
530,
272,
3434,
26,
4628,
272,
2505,
26,
6601,
13790,
6139,
272,
11747,
63,
3266,
63,
2913,
26,
11747,
442,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
abec/getabe.com
|
DjangoSite/apps/flashcards/api.py
|
1
|
1367
|
import logging
from rest_framework.generics import GenericAPIView, ListCreateAPIView
from rest_framework.response import Response
from .models import FlashCard
from .serializers import FlashCardSerializer
LOG = logging.getLogger(__name__)
class ListAddFlashCards(ListCreateAPIView):
model = FlashCard
serializer_class = FlashCardSerializer
def post(self, request):
update_card_objs = []
category = request.POST.get('category')
cards = request.POST.get('cards')
if not category:
return Response(status=400)
if not cards:
return Response(status=400)
for card in cards.split(","):
card = card.strip()
if card:
update_card_objs.append(FlashCard.objects.get_or_create(english=card.strip())[0])
for card in update_card_objs:
card.category = category
card.save()
return Response(status=204)
list_add_flash_cards = ListAddFlashCards.as_view()
class VoiceAnswer(GenericAPIView):
model = FlashCard
lookup_url_kwarg = 'card'
def post(self, request, card):
# Remember wave file.
# Need to delete these periodically.
with open('/tmp/test.wav', 'wb') as f:
f.write(request.FILES.get('blob').read())
# request.FILES.get('blob').seek(0)
# card.audio_answer(request.FILES.get('blob'))
return Response(status=200)
voice_answer = VoiceAnswer.as_view()
|
mit
|
[
646,
2050,
199,
199,
504,
4618,
63,
4857,
14,
2038,
2932,
492,
8307,
25778,
12,
3820,
2499,
25778,
199,
504,
4618,
63,
4857,
14,
1310,
492,
7232,
199,
199,
504,
1275,
992,
492,
11040,
1119,
13832,
199,
504,
1275,
12844,
492,
11040,
1119,
13832,
7299,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
3820,
1123,
29189,
35,
5596,
8,
1296,
2499,
25778,
304,
523,
1402,
275,
11040,
1119,
13832,
523,
9146,
63,
533,
275,
11040,
1119,
13832,
7299,
819,
347,
2963,
8,
277,
12,
1056,
304,
272,
1678,
63,
5841,
63,
8718,
275,
942,
339,
4637,
275,
1056,
14,
4030,
14,
362,
360,
3710,
358,
272,
27181,
275,
1056,
14,
4030,
14,
362,
360,
13761,
358,
339,
340,
440,
4637,
26,
489,
372,
7232,
8,
1205,
29,
5303,
9,
339,
340,
440,
27181,
26,
489,
372,
7232,
8,
1205,
29,
5303,
9,
339,
367,
12564,
315,
27181,
14,
1294,
8,
2266,
304,
489,
12564,
275,
12564,
14,
1913,
342,
489,
340,
12564,
26,
267,
1678,
63,
5841,
63,
8718,
14,
740,
8,
29189,
13832,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
17872,
29,
5841,
14,
1913,
18756,
16,
566,
339,
367,
12564,
315,
1678,
63,
5841,
63,
8718,
26,
489,
12564,
14,
3710,
275,
4637,
489,
12564,
14,
2117,
342,
339,
372,
7232,
8,
1205,
29,
6686,
9,
199,
513,
63,
525,
63,
11331,
63,
13761,
275,
3820,
1123,
29189,
35,
5596,
14,
305,
63,
1345,
342,
421,
199,
533,
32665,
1885,
19104,
8,
9417,
25778,
304,
523,
1402,
275,
11040,
1119,
13832,
523,
4237,
63,
633,
63,
12745,
275,
283,
5841,
7,
819,
347,
2963,
8,
277,
12,
1056,
12,
12564,
304,
272,
327,
31859,
12204,
570,
14,
272,
327,
14012,
370,
3145,
3520,
18745,
1183,
14,
272,
543,
1551,
2336,
2791,
15,
396,
14,
19118,
297,
283,
6603,
358,
465,
289,
26,
489,
289,
14,
952,
8,
1069,
14,
9472,
14,
362,
360,
6582,
1959,
739,
1012,
272,
327,
1056,
14,
9472,
14,
362,
360,
6582,
1959,
5507,
8,
16,
9,
272,
327,
12564,
14,
8130,
63,
5934,
8,
1069,
14,
9472,
14,
362,
360,
6582,
1333,
272,
372,
7232,
8,
1205,
29,
1840,
9,
199,
3789,
63,
5934,
275,
32665,
1885,
19104,
14,
305,
63,
1345,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2050,
199,
199,
504,
4618,
63,
4857,
14,
2038,
2932,
492,
8307,
25778,
12,
3820,
2499,
25778,
199,
504,
4618,
63,
4857,
14,
1310,
492,
7232,
199,
199,
504,
1275,
992,
492,
11040,
1119,
13832,
199,
504,
1275,
12844,
492,
11040,
1119,
13832,
7299,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
3820,
1123,
29189,
35,
5596,
8,
1296,
2499,
25778,
304,
523,
1402,
275,
11040,
1119,
13832,
523,
9146,
63,
533,
275,
11040,
1119,
13832,
7299,
819,
347,
2963,
8,
277,
12,
1056,
304,
272,
1678,
63,
5841,
63,
8718,
275,
942,
339,
4637,
275,
1056,
14,
4030,
14,
362,
360,
3710,
358,
272,
27181,
275,
1056,
14,
4030,
14,
362,
360,
13761,
358,
339,
340,
440,
4637,
26,
489,
372,
7232,
8,
1205,
29,
5303,
9,
339,
340,
440,
27181,
26,
489,
372,
7232,
8,
1205,
29,
5303,
9,
339,
367,
12564,
315,
27181,
14,
1294,
8,
2266,
304,
489,
12564,
275,
12564,
14,
1913,
342,
489,
340,
12564,
26,
267,
1678,
63,
5841,
63,
8718,
14,
740,
8,
29189,
13832,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
17872,
29,
5841,
14,
1913,
18756,
16,
566,
339,
367,
12564,
315,
1678,
63,
5841,
63,
8718,
26,
489,
12564,
14,
3710,
275,
4637,
489,
12564,
14,
2117,
342,
339,
372,
7232,
8,
1205,
29,
6686,
9,
199,
513,
63,
525,
63,
11331,
63,
13761,
275,
3820,
1123,
29189,
35,
5596,
14,
305,
63,
1345,
342,
421,
199,
533,
32665,
1885,
19104,
8,
9417,
25778,
304,
523,
1402,
275,
11040,
1119,
13832,
523,
4237,
63,
633,
63,
12745,
275,
283,
5841,
7,
819,
347,
2963,
8,
277,
12,
1056,
12,
12564,
304,
272,
327,
31859,
12204,
570,
14,
272,
327,
14012,
370,
3145,
3520,
18745,
1183,
14,
272,
543,
1551,
2336,
2791,
15,
396,
14,
19118,
297,
283,
6603,
358,
465,
289,
26,
489,
289,
14,
952,
8,
1069,
14,
9472,
14,
362,
360,
6582,
1959,
739,
1012,
272,
327,
1056,
14,
9472,
14,
362,
360,
6582,
1959,
5507,
8,
16,
9,
272,
327,
12564,
14,
8130,
63,
5934,
8,
1069,
14,
9472,
14,
362,
360,
6582,
1333,
272,
372,
7232,
8,
1205,
29,
1840,
9,
199,
3789,
63,
5934,
275,
32665,
1885,
19104,
14,
305,
63,
1345,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
kdwink/intellij-community
|
python/helpers/rest_formatter.py
|
1
|
11961
|
import re
import sys
from docutils import nodes
from docutils.core import publish_string
from docutils.frontend import OptionParser
from docutils.nodes import Text, field_body, field_name, rubric
from docutils.parsers.rst import directives
from docutils.parsers.rst.directives.admonitions import BaseAdmonition
from docutils.writers.html4css1 import HTMLTranslator, Writer as HTMLWriter
from docutils.writers import Writer
# Copied from the Sphinx' sources. Docutils doesn't handle "seealso" directives by default.
class seealso(nodes.Admonition, nodes.Element):
"""Custom "see also" admonition."""
class SeeAlso(BaseAdmonition):
"""
An admonition mentioning things to look at as reference.
"""
node_class = seealso
directives.register_directive('seealso', SeeAlso)
class RestHTMLTranslator(HTMLTranslator):
settings = None
def __init__(self, document):
# Copied from epydoc.markup.restructuredtext._EpydocHTMLTranslator
if self.settings is None:
settings = OptionParser([HTMLWriter()]).get_default_values()
self.__class__.settings = settings
document.settings = self.settings
HTMLTranslator.__init__(self, document)
def visit_document(self, node):
pass
def depart_document(self, node):
pass
def visit_docinfo(self, node):
pass
def depart_docinfo(self, node):
pass
def unimplemented_visit(self, node):
pass
def visit_field_name(self, node):
atts = {}
if self.in_docinfo:
atts['class'] = 'docinfo-name'
else:
atts['class'] = 'field-name'
self.context.append('')
atts['align'] = "right"
self.body.append(self.starttag(node, 'th', '', **atts))
def visit_field_body(self, node):
self.body.append(self.starttag(node, 'td', '', CLASS='field-body'))
parent_text = node.parent[0][0].astext()
if hasattr(node.parent, "type"):
self.body.append("(")
self.body.append(self.starttag(node, 'a', '',
href='psi_element://#typename#' + node.parent.type))
self.body.append(node.parent.type)
self.body.append("</a>")
self.body.append(") ")
elif parent_text.startswith("type "):
index = parent_text.index("type ")
type_string = parent_text[index + len("type ")]
self.body.append(self.starttag(node, 'a', '',
href='psi_element://#typename#' + type_string))
elif parent_text.startswith("rtype"):
type_string = node.children[0][0].astext()
self.body.append(self.starttag(node, 'a', '',
href='psi_element://#typename#' + type_string))
self.set_class_on_child(node, 'first', 0)
field = node.parent
if (self.compact_field_list or
isinstance(field.parent, nodes.docinfo) or
field.parent.index(field) == len(field.parent) - 1):
# If we are in a compact list, the docinfo, or if this is
# the last field of the field list, do not add vertical
# space after last element.
self.set_class_on_child(node, 'last', -1)
def depart_field_body(self, node):
if node.parent[0][0].astext().startswith("type "):
self.body.append("</a>")
HTMLTranslator.depart_field_body(self, node)
def visit_reference(self, node):
atts = {}
if 'refuri' in node:
atts['href'] = node['refuri']
if self.settings.cloak_email_addresses and atts['href'].startswith('mailto:'):
atts['href'] = self.cloak_mailto(atts['href'])
self.in_mailto = True
# atts['class'] += ' external'
else:
assert 'refid' in node, 'References must have "refuri" or "refid" attribute.'
atts['href'] = '#' + node['refid']
atts['class'] += ' internal'
if not isinstance(node.parent, nodes.TextElement):
assert len(node) == 1 and isinstance(node[0], nodes.image)
atts['class'] += ' image-reference'
self.body.append(self.starttag(node, 'a', '', **atts))
def starttag(self, node, tagname, suffix='\n', **attributes):
attr_dicts = [attributes]
if isinstance(node, nodes.Node):
attr_dicts.append(node.attributes)
if isinstance(node, dict):
attr_dicts.append(node)
# Munge each attribute dictionary. Unfortunately, we need to
# iterate through attributes one at a time because some
# versions of docutils don't case-normalize attributes.
for attr_dict in attr_dicts:
# For some reason additional classes in bullet list make it render poorly.
# Such lists are used to render multiple return values in Numpy docstrings by Napoleon.
if tagname == 'ul' and isinstance(node.parent, field_body):
attr_dict.pop('class', None)
attr_dict.pop('classes', None)
continue
for (key, val) in attr_dict.items():
# Prefix all CSS classes with "rst-"; and prefix all
# names with "rst-" to avoid conflicts.
if key.lower() in ('class', 'id', 'name'):
attr_dict[key] = 'rst-%s' % val
elif key.lower() in ('classes', 'ids', 'names'):
attr_dict[key] = ['rst-%s' % cls for cls in val]
elif key.lower() == 'href':
if attr_dict[key][:1] == '#':
attr_dict[key] = '#rst-%s' % attr_dict[key][1:]
if tagname == 'th' and isinstance(node, field_name):
attributes['valign'] = 'top'
# For headings, use class="heading"
if re.match(r'^h\d+$', tagname):
attributes['class'] = ' '.join([attributes.get('class', ''), 'heading']).strip()
return HTMLTranslator.starttag(self, node, tagname, suffix, **attributes)
def visit_rubric(self, node):
self.body.append(self.starttag(node, 'h1', '', CLASS='rubric'))
def depart_rubric(self, node):
self.body.append('</h1>\n')
def visit_note(self, node):
self.body.append('<h1 class="heading">Note</h1>\n')
def depart_note(self, node):
pass
def visit_seealso(self, node):
self.body.append('<h1 class="heading">See Also</h1>\n')
def depart_seealso(self, node):
pass
def visit_field_list(self, node):
fields = {}
for n in node.children:
if not n.children:
continue
child = n.children[0]
rawsource = child.rawsource
if rawsource.startswith("param "):
index = rawsource.index("param ")
if not child.children:
continue
param_name = rawsource[index + len("param "):]
param_type = None
parts = param_name.rsplit(None, 1)
if len(parts) == 2:
param_type, param_name = parts
# Strip leading escaped asterisks for vararg parameters in Google code style docstrings
param_name = re.sub(r'\\\*', '*', param_name)
child.children[0] = Text(param_name)
fields[param_name] = n
if param_type:
n.type = param_type
if rawsource == "return":
fields["return"] = n
for n in node.children:
if len(n.children) < 2:
continue
field_name, field_body = n.children[0], n.children[1]
rawsource = field_name.rawsource
if rawsource.startswith("type "):
index = rawsource.index("type ")
name = re.sub(r'\\\*', '*', rawsource[index + len("type "):])
if name in fields:
fields[name].type = self._strip_markup(field_body.astext())[1]
node.children.remove(n)
if rawsource == "rtype":
if "return" in fields:
fields["return"].type = self._strip_markup(field_body.astext())[1]
node.children.remove(n)
HTMLTranslator.visit_field_list(self, node)
def unknown_visit(self, node):
""" Ignore unknown nodes """
def unknown_departure(self, node):
""" Ignore unknown nodes """
def visit_problematic(self, node):
# Don't insert hyperlinks to nowhere for e.g. unclosed asterisks
if not self._is_text_wrapper(node):
return HTMLTranslator.visit_problematic(self, node)
directive, text = self._strip_markup(node.astext())
if directive[1:-1] in ('exc', 'class'):
self.body.append(self.starttag(node, 'a', '', href='psi_element://#typename#' + text))
self.body.append(text)
self.body.append('</a>')
else:
self.body.append(text)
raise nodes.SkipNode
@staticmethod
def _strip_markup(text):
m = re.match(r'(:\w+)?(:\S+:)?`(.+?)`', text)
if m:
_, directive, trimmed = m.groups('')
return directive, trimmed
return None, text
def depart_problematic(self, node):
if not self._is_text_wrapper(node):
return HTMLTranslator.depart_problematic(self, node)
def visit_Text(self, node):
text = node.astext()
encoded = self.encode(text)
if not isinstance(node.parent, (nodes.literal, nodes.literal_block)):
encoded = encoded.replace('---', '—').replace('--', '–')
if self.in_mailto and self.settings.cloak_email_addresses:
encoded = self.cloak_email(encoded)
self.body.append(encoded)
def _is_text_wrapper(self, node):
return len(node.children) == 1 and isinstance(node.children[0], Text)
def visit_block_quote(self, node):
self.body.append(self.emptytag(node, "br"))
def depart_block_quote(self, node):
pass
def visit_literal(self, node):
"""Process text to prevent tokens from wrapping."""
self.body.append(self.starttag(node, 'tt', '', CLASS='docutils literal'))
text = node.astext()
for token in self.words_and_spaces.findall(text):
if token.strip():
self.body.append('<code>%s</code>'
% self.encode(token))
elif token in ('\n', ' '):
# Allow breaks at whitespace:
self.body.append(token)
else:
# Protect runs of multiple spaces; the last space can wrap:
self.body.append(' ' * (len(token) - 1) + ' ')
self.body.append('</tt>')
raise nodes.SkipNode
def format_docstring(docstring):
class _DocumentPseudoWriter(Writer):
def __init__(self):
self.document = None
Writer.__init__(self)
def translate(self):
self.output = ''
writer = _DocumentPseudoWriter()
publish_string(docstring, writer=writer, settings_overrides={'report_level': 10000,
'halt_level': 10000,
'warning_stream': None,
'docinfo_xform': False})
document = writer.document
document.settings.xml_declaration = None
visitor = RestHTMLTranslator(document)
document.walkabout(visitor)
return ''.join(visitor.body)
def main(text=None):
src = sys.stdin.read() if text is None else text
html = format_docstring(src)
sys.stdout.write(html)
sys.stdout.flush()
if __name__ == '__main__':
main()
|
apache-2.0
|
[
646,
295,
199,
646,
984,
199,
199,
504,
18382,
492,
3380,
199,
504,
18382,
14,
1018,
492,
2780,
63,
875,
199,
504,
18382,
14,
18062,
492,
13491,
199,
504,
18382,
14,
2415,
492,
4516,
12,
901,
63,
2030,
12,
901,
63,
354,
12,
519,
17147,
199,
504,
18382,
14,
11531,
14,
8332,
492,
13502,
199,
504,
18382,
14,
11531,
14,
8332,
14,
23216,
14,
350,
2106,
73,
852,
492,
3523,
2767,
31722,
199,
504,
18382,
14,
26224,
14,
1360,
20,
3919,
17,
492,
4163,
26059,
12,
24441,
465,
4163,
6261,
199,
504,
18382,
14,
26224,
492,
24441,
421,
199,
3,
29622,
5299,
687,
314,
10229,
7,
5274,
14,
5454,
1208,
3181,
1133,
2429,
298,
3239,
12344,
2,
13502,
701,
849,
14,
199,
533,
19352,
8,
2415,
14,
2767,
31722,
12,
3380,
14,
2162,
304,
272,
408,
7223,
298,
3239,
2597,
2,
1503,
31722,
1041,
421,
199,
533,
1666,
31892,
8,
1563,
2767,
31722,
304,
272,
408,
272,
1626,
1503,
31722,
20811,
316,
7645,
370,
3648,
737,
465,
3659,
14,
272,
408,
272,
1031,
63,
533,
275,
19352,
199,
199,
23216,
14,
2683,
63,
15047,
360,
3239,
12344,
297,
1666,
31892,
9,
421,
199,
533,
30417,
4943,
26059,
8,
4943,
26059,
304,
272,
2202,
275,
488,
339,
347,
636,
826,
721,
277,
12,
2213,
304,
267,
327,
29622,
5299,
687,
325,
25048,
14,
10131,
14,
26854,
423,
37,
25048,
4943,
26059,
267,
340,
291,
14,
1751,
365,
488,
26,
288,
2202,
275,
13491,
779,
4943,
6261,
342,
6575,
362,
63,
885,
63,
1459,
342,
288,
291,
855,
533,
4343,
1751,
275,
2202,
267,
2213,
14,
1751,
275,
291,
14,
1751,
398,
4163,
26059,
855,
826,
721,
277,
12,
2213,
9,
339,
347,
5684,
63,
3554,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
21124,
63,
3554,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
5684,
63,
32139,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
21124,
63,
32139,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
625,
13825,
63,
5427,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
5684,
63,
698,
63,
354,
8,
277,
12,
1031,
304,
267,
737,
1086,
275,
1052,
267,
340,
291,
14,
262,
63,
32139,
26,
288,
737,
1086,
459,
533,
418,
275,
283,
32139,
13,
354,
7,
267,
587,
26,
288,
737,
1086,
459,
533,
418,
275,
283,
698,
13,
354,
7,
398,
291,
14,
1100,
14,
740,
8355,
267,
737,
1086,
459,
5743,
418,
275,
298,
1019,
2,
267,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
273,
297,
3260,
1011,
32369,
430,
339,
347,
5684,
63,
698,
63,
2030,
8,
277,
12,
1031,
304,
267,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
2076,
297,
3260,
24221,
534,
698,
13,
2030,
1333,
267,
1676,
63,
505,
275,
1031,
14,
1708,
59,
16,
1527,
16,
1055,
305,
505,
342,
267,
340,
2688,
8,
932,
14,
1708,
12,
298,
466,
2349,
288,
291,
14,
2030,
14,
740,
480,
480,
9,
288,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
65,
297,
3260,
5644,
4369,
534,
18645,
63,
2108,
921,
3,
18596,
19367,
435,
1031,
14,
1708,
14,
466,
430,
288,
291,
14,
2030,
14,
740,
8,
932,
14,
1708,
14,
466,
9,
288,
291,
14,
2030,
14,
740,
23790,
65,
9579,
288,
291,
14,
2030,
14,
740,
480,
9,
6099,
267,
916,
1676,
63,
505,
14,
2460,
480,
466,
26699,
288,
1478,
275,
1676,
63,
505,
14,
1080,
480,
466,
6099,
288,
730,
63,
875,
275,
1676,
63,
505,
59,
1080,
435,
822,
480,
466,
298,
1874,
288,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
65,
297,
3260,
5644,
4369,
534,
18645,
63,
2108,
921,
3,
18596,
19367,
435,
730,
63,
875,
430,
267,
916,
1676,
63,
505,
14,
2460,
480,
4500,
2349,
288,
730,
63,
875,
275,
1031,
14,
3223,
59,
16,
1527,
16,
1055,
305,
505,
342,
288,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
65,
297,
3260,
5644,
4369,
534,
18645,
63,
2108,
921,
3,
18596,
19367,
435,
730,
63,
875,
430,
398,
291,
14,
409,
63,
533,
63,
265,
63,
1739,
8,
932,
12,
283,
2246,
297,
378,
9,
267,
901,
275,
1031,
14,
1708,
267,
340,
334,
277,
14,
23046,
63,
698,
63,
513,
503,
355,
1228,
8,
698,
14,
1708,
12,
3380,
14,
32139,
9,
503,
490,
901,
14,
1708,
14,
1080,
8,
698,
9,
508,
822,
8,
698,
14,
1708,
9,
446,
413,
304,
288,
327,
982,
781,
787,
315,
282,
23314,
769,
12,
314,
1382,
815,
12,
503,
340,
642,
365,
288,
327,
314,
2061,
901,
402,
314,
901,
769,
12,
886,
440,
1050,
13763,
288,
327,
4601,
2410,
2061,
1819,
14,
288,
291,
14,
409,
63,
533,
63,
265,
63,
1739,
8,
932,
12,
283,
2019,
297,
446,
17,
9,
339,
347,
21124,
63,
698,
63,
2030,
8,
277,
12,
1031,
304,
267,
340,
1031,
14,
1708,
59,
16,
1527,
16,
1055,
305,
505,
1252,
2460,
480,
466,
26699,
288,
291,
14,
2030,
14,
740,
23790,
65,
9579,
267,
4163,
26059,
14,
27532,
63,
698,
63,
2030,
8,
277,
12,
1031,
9,
339,
347,
5684,
63,
4443,
8,
277,
12,
1031,
304,
267,
737,
1086,
275,
1052,
267,
340,
283,
1121,
2302,
7,
315,
1031,
26,
288,
737,
1086,
459,
6399,
418,
275,
1031,
459,
1121,
2302,
418,
288,
340,
291,
14,
1751,
14,
1251,
1151,
63,
2123,
63,
7423,
436,
737,
1086,
459,
6399,
2278,
2460,
360,
26206,
23117,
355,
737,
1086,
459,
6399,
418,
275,
291,
14,
1251,
1151,
63,
26206,
8,
32369,
459,
6399,
1105,
355,
291,
14,
262,
63,
26206,
275,
715,
355,
327,
737,
1086,
459,
533,
418,
847,
283,
5957,
7,
267,
587,
26,
288,
702,
283,
21470,
7,
315,
1031,
12,
283,
15242,
1471,
1172,
298,
1121,
2302,
2,
503,
298,
21470,
2,
2225,
3530,
288,
737,
1086,
459,
6399,
418,
275,
19619,
435,
1031,
459,
21470,
418,
288,
737,
1086,
459,
533,
418,
847,
283,
5007,
7,
267,
340,
440,
1228,
8,
932,
14,
1708,
12,
3380,
14,
1872,
2162
] |
[
295,
199,
646,
984,
199,
199,
504,
18382,
492,
3380,
199,
504,
18382,
14,
1018,
492,
2780,
63,
875,
199,
504,
18382,
14,
18062,
492,
13491,
199,
504,
18382,
14,
2415,
492,
4516,
12,
901,
63,
2030,
12,
901,
63,
354,
12,
519,
17147,
199,
504,
18382,
14,
11531,
14,
8332,
492,
13502,
199,
504,
18382,
14,
11531,
14,
8332,
14,
23216,
14,
350,
2106,
73,
852,
492,
3523,
2767,
31722,
199,
504,
18382,
14,
26224,
14,
1360,
20,
3919,
17,
492,
4163,
26059,
12,
24441,
465,
4163,
6261,
199,
504,
18382,
14,
26224,
492,
24441,
421,
199,
3,
29622,
5299,
687,
314,
10229,
7,
5274,
14,
5454,
1208,
3181,
1133,
2429,
298,
3239,
12344,
2,
13502,
701,
849,
14,
199,
533,
19352,
8,
2415,
14,
2767,
31722,
12,
3380,
14,
2162,
304,
272,
408,
7223,
298,
3239,
2597,
2,
1503,
31722,
1041,
421,
199,
533,
1666,
31892,
8,
1563,
2767,
31722,
304,
272,
408,
272,
1626,
1503,
31722,
20811,
316,
7645,
370,
3648,
737,
465,
3659,
14,
272,
408,
272,
1031,
63,
533,
275,
19352,
199,
199,
23216,
14,
2683,
63,
15047,
360,
3239,
12344,
297,
1666,
31892,
9,
421,
199,
533,
30417,
4943,
26059,
8,
4943,
26059,
304,
272,
2202,
275,
488,
339,
347,
636,
826,
721,
277,
12,
2213,
304,
267,
327,
29622,
5299,
687,
325,
25048,
14,
10131,
14,
26854,
423,
37,
25048,
4943,
26059,
267,
340,
291,
14,
1751,
365,
488,
26,
288,
2202,
275,
13491,
779,
4943,
6261,
342,
6575,
362,
63,
885,
63,
1459,
342,
288,
291,
855,
533,
4343,
1751,
275,
2202,
267,
2213,
14,
1751,
275,
291,
14,
1751,
398,
4163,
26059,
855,
826,
721,
277,
12,
2213,
9,
339,
347,
5684,
63,
3554,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
21124,
63,
3554,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
5684,
63,
32139,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
21124,
63,
32139,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
625,
13825,
63,
5427,
8,
277,
12,
1031,
304,
267,
986,
339,
347,
5684,
63,
698,
63,
354,
8,
277,
12,
1031,
304,
267,
737,
1086,
275,
1052,
267,
340,
291,
14,
262,
63,
32139,
26,
288,
737,
1086,
459,
533,
418,
275,
283,
32139,
13,
354,
7,
267,
587,
26,
288,
737,
1086,
459,
533,
418,
275,
283,
698,
13,
354,
7,
398,
291,
14,
1100,
14,
740,
8355,
267,
737,
1086,
459,
5743,
418,
275,
298,
1019,
2,
267,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
273,
297,
3260,
1011,
32369,
430,
339,
347,
5684,
63,
698,
63,
2030,
8,
277,
12,
1031,
304,
267,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
2076,
297,
3260,
24221,
534,
698,
13,
2030,
1333,
267,
1676,
63,
505,
275,
1031,
14,
1708,
59,
16,
1527,
16,
1055,
305,
505,
342,
267,
340,
2688,
8,
932,
14,
1708,
12,
298,
466,
2349,
288,
291,
14,
2030,
14,
740,
480,
480,
9,
288,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
65,
297,
3260,
5644,
4369,
534,
18645,
63,
2108,
921,
3,
18596,
19367,
435,
1031,
14,
1708,
14,
466,
430,
288,
291,
14,
2030,
14,
740,
8,
932,
14,
1708,
14,
466,
9,
288,
291,
14,
2030,
14,
740,
23790,
65,
9579,
288,
291,
14,
2030,
14,
740,
480,
9,
6099,
267,
916,
1676,
63,
505,
14,
2460,
480,
466,
26699,
288,
1478,
275,
1676,
63,
505,
14,
1080,
480,
466,
6099,
288,
730,
63,
875,
275,
1676,
63,
505,
59,
1080,
435,
822,
480,
466,
298,
1874,
288,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
65,
297,
3260,
5644,
4369,
534,
18645,
63,
2108,
921,
3,
18596,
19367,
435,
730,
63,
875,
430,
267,
916,
1676,
63,
505,
14,
2460,
480,
4500,
2349,
288,
730,
63,
875,
275,
1031,
14,
3223,
59,
16,
1527,
16,
1055,
305,
505,
342,
288,
291,
14,
2030,
14,
740,
8,
277,
14,
15234,
8,
932,
12,
283,
65,
297,
3260,
5644,
4369,
534,
18645,
63,
2108,
921,
3,
18596,
19367,
435,
730,
63,
875,
430,
398,
291,
14,
409,
63,
533,
63,
265,
63,
1739,
8,
932,
12,
283,
2246,
297,
378,
9,
267,
901,
275,
1031,
14,
1708,
267,
340,
334,
277,
14,
23046,
63,
698,
63,
513,
503,
355,
1228,
8,
698,
14,
1708,
12,
3380,
14,
32139,
9,
503,
490,
901,
14,
1708,
14,
1080,
8,
698,
9,
508,
822,
8,
698,
14,
1708,
9,
446,
413,
304,
288,
327,
982,
781,
787,
315,
282,
23314,
769,
12,
314,
1382,
815,
12,
503,
340,
642,
365,
288,
327,
314,
2061,
901,
402,
314,
901,
769,
12,
886,
440,
1050,
13763,
288,
327,
4601,
2410,
2061,
1819,
14,
288,
291,
14,
409,
63,
533,
63,
265,
63,
1739,
8,
932,
12,
283,
2019,
297,
446,
17,
9,
339,
347,
21124,
63,
698,
63,
2030,
8,
277,
12,
1031,
304,
267,
340,
1031,
14,
1708,
59,
16,
1527,
16,
1055,
305,
505,
1252,
2460,
480,
466,
26699,
288,
291,
14,
2030,
14,
740,
23790,
65,
9579,
267,
4163,
26059,
14,
27532,
63,
698,
63,
2030,
8,
277,
12,
1031,
9,
339,
347,
5684,
63,
4443,
8,
277,
12,
1031,
304,
267,
737,
1086,
275,
1052,
267,
340,
283,
1121,
2302,
7,
315,
1031,
26,
288,
737,
1086,
459,
6399,
418,
275,
1031,
459,
1121,
2302,
418,
288,
340,
291,
14,
1751,
14,
1251,
1151,
63,
2123,
63,
7423,
436,
737,
1086,
459,
6399,
2278,
2460,
360,
26206,
23117,
355,
737,
1086,
459,
6399,
418,
275,
291,
14,
1251,
1151,
63,
26206,
8,
32369,
459,
6399,
1105,
355,
291,
14,
262,
63,
26206,
275,
715,
355,
327,
737,
1086,
459,
533,
418,
847,
283,
5957,
7,
267,
587,
26,
288,
702,
283,
21470,
7,
315,
1031,
12,
283,
15242,
1471,
1172,
298,
1121,
2302,
2,
503,
298,
21470,
2,
2225,
3530,
288,
737,
1086,
459,
6399,
418,
275,
19619,
435,
1031,
459,
21470,
418,
288,
737,
1086,
459,
533,
418,
847,
283,
5007,
7,
267,
340,
440,
1228,
8,
932,
14,
1708,
12,
3380,
14,
1872,
2162,
0
] |
[
1,
1,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n/UnbalancedDataset
|
imblearn/ensemble/_weight_boosting.py
|
2
|
11479
|
from copy import deepcopy
import numpy as np
from sklearn.base import clone
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble._base import _set_random_states
from sklearn.utils import _safe_indexing
from ..under_sampling.base import BaseUnderSampler
from ..under_sampling import RandomUnderSampler
from ..pipeline import make_pipeline
from ..utils import Substitution, check_target_type
from ..utils._docstring import _random_state_docstring
from ..utils._validation import _deprecate_positional_args
@Substitution(
sampling_strategy=BaseUnderSampler._sampling_strategy_docstring,
random_state=_random_state_docstring,
)
class RUSBoostClassifier(AdaBoostClassifier):
"""Random under-sampling integrated in the learning of AdaBoost.
During learning, the problem of class balancing is alleviated by random
under-sampling the sample at each iteration of the boosting algorithm.
Read more in the :ref:`User Guide <boosting>`.
.. versionadded:: 0.4
Parameters
----------
base_estimator : estimator object, default=None
The base estimator from which the boosted ensemble is built.
Support for sample weighting is required, as well as proper
``classes_`` and ``n_classes_`` attributes. If ``None``, then
the base estimator is ``DecisionTreeClassifier(max_depth=1)``.
n_estimators : int, default=50
The maximum number of estimators at which boosting is terminated.
In case of perfect fit, the learning procedure is stopped early.
learning_rate : float, default=1.0
Learning rate shrinks the contribution of each classifier by
``learning_rate``. There is a trade-off between ``learning_rate`` and
``n_estimators``.
algorithm : {{'SAMME', 'SAMME.R'}}, default='SAMME.R'
If 'SAMME.R' then use the SAMME.R real boosting algorithm.
``base_estimator`` must support calculation of class probabilities.
If 'SAMME' then use the SAMME discrete boosting algorithm.
The SAMME.R algorithm typically converges faster than SAMME,
achieving a lower test error with fewer boosting iterations.
{sampling_strategy}
replacement : bool, default=False
Whether or not to sample randomly with replacement or not.
{random_state}
Attributes
----------
base_estimator_ : estimator
The base estimator from which the ensemble is grown.
estimators_ : list of classifiers
The collection of fitted sub-estimators.
samplers_ : list of RandomUnderSampler
The collection of fitted samplers.
pipelines_ : list of Pipeline
The collection of fitted pipelines (samplers + trees).
classes_ : ndarray of shape (n_classes,)
The classes labels.
n_classes_ : int
The number of classes.
estimator_weights_ : ndarray of shape (n_estimator,)
Weights for each estimator in the boosted ensemble.
estimator_errors_ : ndarray of shape (n_estimator,)
Classification error for each estimator in the boosted
ensemble.
feature_importances_ : ndarray of shape (n_features,)
The feature importances if supported by the ``base_estimator``.
See Also
--------
BalancedBaggingClassifier : Bagging classifier for which each base
estimator is trained on a balanced bootstrap.
BalancedRandomForestClassifier : Random forest applying random-under
sampling to balance the different bootstraps.
EasyEnsembleClassifier : Ensemble of AdaBoost classifier trained on
balanced bootstraps.
References
----------
.. [1] Seiffert, C., Khoshgoftaar, T. M., Van Hulse, J., & Napolitano, A.
"RUSBoost: A hybrid approach to alleviating class imbalance." IEEE
Transactions on Systems, Man, and Cybernetics-Part A: Systems and Humans
40.1 (2010): 185-197.
Examples
--------
>>> from imblearn.ensemble import RUSBoostClassifier
>>> from sklearn.datasets import make_classification
>>>
>>> X, y = make_classification(n_samples=1000, n_classes=3,
... n_informative=4, weights=[0.2, 0.3, 0.5],
... random_state=0)
>>> clf = RUSBoostClassifier(random_state=0)
>>> clf.fit(X, y) # doctest: +ELLIPSIS
RUSBoostClassifier(...)
>>> clf.predict(X) # doctest: +ELLIPSIS
array([...])
"""
@_deprecate_positional_args
def __init__(
self,
base_estimator=None,
*,
n_estimators=50,
learning_rate=1.0,
algorithm="SAMME.R",
sampling_strategy="auto",
replacement=False,
random_state=None,
):
super().__init__(
base_estimator=base_estimator,
n_estimators=n_estimators,
learning_rate=learning_rate,
algorithm=algorithm,
random_state=random_state,
)
self.sampling_strategy = sampling_strategy
self.replacement = replacement
def fit(self, X, y, sample_weight=None):
"""Build a boosted classifier from the training set (X, y).
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The training input samples. Sparse matrix can be CSC, CSR, COO,
DOK, or LIL. DOK and LIL are converted to CSR.
y : array-like of shape (n_samples,)
The target values (class labels).
sample_weight : array-like of shape (n_samples,), default=None
Sample weights. If None, the sample weights are initialized to
``1 / n_samples``.
Returns
-------
self : object
Returns self.
"""
check_target_type(y)
self.samplers_ = []
self.pipelines_ = []
super().fit(X, y, sample_weight)
return self
def _validate_estimator(self):
"""Check the estimator and the n_estimator attribute, set the
`base_estimator_` attribute."""
super()._validate_estimator()
self.base_sampler_ = RandomUnderSampler(
sampling_strategy=self.sampling_strategy,
replacement=self.replacement,
)
def _make_sampler_estimator(self, append=True, random_state=None):
"""Make and configure a copy of the `base_estimator_` attribute.
Warning: This method should be used to properly instantiate new
sub-estimators.
"""
estimator = clone(self.base_estimator_)
estimator.set_params(**{p: getattr(self, p) for p in self.estimator_params})
sampler = clone(self.base_sampler_)
if random_state is not None:
_set_random_states(estimator, random_state)
_set_random_states(sampler, random_state)
if append:
self.estimators_.append(estimator)
self.samplers_.append(sampler)
self.pipelines_.append(
make_pipeline(deepcopy(sampler), deepcopy(estimator))
)
return estimator, sampler
def _boost_real(self, iboost, X, y, sample_weight, random_state):
"""Implement a single boost using the SAMME.R real algorithm."""
estimator, sampler = self._make_sampler_estimator(random_state=random_state)
X_res, y_res = sampler.fit_resample(X, y)
sample_weight_res = _safe_indexing(sample_weight, sampler.sample_indices_)
estimator.fit(X_res, y_res, sample_weight=sample_weight_res)
y_predict_proba = estimator.predict_proba(X)
if iboost == 0:
self.classes_ = getattr(estimator, "classes_", None)
self.n_classes_ = len(self.classes_)
y_predict = self.classes_.take(np.argmax(y_predict_proba, axis=1), axis=0)
# Instances incorrectly classified
incorrect = y_predict != y
# Error fraction
estimator_error = np.mean(np.average(incorrect, weights=sample_weight, axis=0))
# Stop if classification is perfect
if estimator_error <= 0:
return sample_weight, 1.0, 0.0
# Construct y coding as described in Zhu et al [2]:
#
# y_k = 1 if c == k else -1 / (K - 1)
#
# where K == n_classes_ and c, k in [0, K) are indices along the second
# axis of the y coding with c being the index corresponding to the true
# class label.
n_classes = self.n_classes_
classes = self.classes_
y_codes = np.array([-1.0 / (n_classes - 1), 1.0])
y_coding = y_codes.take(classes == y[:, np.newaxis])
# Displace zero probabilities so the log is defined.
# Also fix negative elements which may occur with
# negative sample weights.
proba = y_predict_proba # alias for readability
np.clip(proba, np.finfo(proba.dtype).eps, None, out=proba)
# Boost weight using multi-class AdaBoost SAMME.R alg
estimator_weight = (
-1.0
* self.learning_rate
* ((n_classes - 1.0) / n_classes)
* (y_coding * np.log(y_predict_proba)).sum(axis=1)
)
# Only boost the weights if it will fit again
if not iboost == self.n_estimators - 1:
# Only boost positive weights
sample_weight *= np.exp(
estimator_weight * ((sample_weight > 0) | (estimator_weight < 0))
)
return sample_weight, 1.0, estimator_error
def _boost_discrete(self, iboost, X, y, sample_weight, random_state):
"""Implement a single boost using the SAMME discrete algorithm."""
estimator, sampler = self._make_sampler_estimator(random_state=random_state)
X_res, y_res = sampler.fit_resample(X, y)
sample_weight_res = _safe_indexing(sample_weight, sampler.sample_indices_)
estimator.fit(X_res, y_res, sample_weight=sample_weight_res)
y_predict = estimator.predict(X)
if iboost == 0:
self.classes_ = getattr(estimator, "classes_", None)
self.n_classes_ = len(self.classes_)
# Instances incorrectly classified
incorrect = y_predict != y
# Error fraction
estimator_error = np.mean(np.average(incorrect, weights=sample_weight, axis=0))
# Stop if classification is perfect
if estimator_error <= 0:
return sample_weight, 1.0, 0.0
n_classes = self.n_classes_
# Stop if the error is at least as bad as random guessing
if estimator_error >= 1.0 - (1.0 / n_classes):
self.estimators_.pop(-1)
self.samplers_.pop(-1)
self.pipelines_.pop(-1)
if len(self.estimators_) == 0:
raise ValueError(
"BaseClassifier in AdaBoostClassifier "
"ensemble is worse than random, ensemble "
"can not be fit."
)
return None, None, None
# Boost weight using multi-class AdaBoost SAMME alg
estimator_weight = self.learning_rate * (
np.log((1.0 - estimator_error) / estimator_error) + np.log(n_classes - 1.0)
)
# Only boost the weights if I will fit again
if not iboost == self.n_estimators - 1:
# Only boost positive weights
sample_weight *= np.exp(estimator_weight * incorrect * (sample_weight > 0))
return sample_weight, estimator_weight, estimator_error
|
mit
|
[
504,
1331,
492,
14800,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1095,
492,
7289,
199,
504,
6357,
14,
15628,
492,
437,
983,
18814,
8508,
199,
504,
6357,
14,
15628,
423,
1095,
492,
485,
409,
63,
2355,
63,
4981,
199,
504,
6357,
14,
1208,
492,
485,
3489,
63,
28703,
199,
199,
504,
2508,
7138,
63,
17376,
14,
1095,
492,
3523,
16001,
27434,
199,
504,
2508,
7138,
63,
17376,
492,
9571,
16001,
27434,
199,
504,
2508,
7379,
492,
1852,
63,
7379,
199,
504,
2508,
1208,
492,
4804,
26575,
12,
1104,
63,
1375,
63,
466,
199,
504,
2508,
1208,
423,
12485,
492,
485,
2355,
63,
929,
63,
12485,
199,
504,
2508,
1208,
423,
6136,
492,
485,
27891,
63,
17867,
63,
589,
421,
199,
32,
2610,
26575,
8,
272,
15877,
63,
8590,
29,
1563,
16001,
27434,
423,
17376,
63,
8590,
63,
12485,
12,
272,
2196,
63,
929,
3699,
2355,
63,
929,
63,
12485,
12,
199,
9,
199,
533,
820,
1668,
18814,
8508,
8,
33,
983,
18814,
8508,
304,
272,
408,
3883,
1334,
13,
17376,
17806,
972,
315,
314,
9328,
402,
437,
983,
18814,
14,
339,
577,
4039,
9328,
12,
314,
5160,
402,
1021,
29300,
365,
27458,
433,
972,
701,
2196,
272,
1334,
13,
17376,
314,
2690,
737,
1924,
8494,
402,
314,
20198,
316,
5563,
14,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
15589,
316,
14943,
339,
2508,
7445,
447,
378,
14,
20,
339,
3897,
272,
4143,
272,
1300,
63,
8627,
520,
8943,
909,
12,
849,
29,
403,
267,
710,
1300,
8943,
687,
1314,
314,
1234,
17849,
19965,
365,
6137,
14,
267,
12502,
367,
2690,
5401,
316,
365,
1415,
12,
465,
5521,
465,
5576,
267,
1124,
2888,
63,
1040,
436,
1124,
78,
63,
2888,
63,
1040,
3004,
14,
982,
1124,
403,
4542,
2066,
267,
314,
1300,
8943,
365,
1124,
872,
24116,
8508,
8,
988,
63,
4631,
29,
17,
20642,
339,
302,
63,
10646,
520,
1109,
12,
849,
29,
1400,
267,
710,
5696,
1329,
402,
23155,
737,
1314,
20198,
316,
365,
15745,
14,
267,
1010,
1930,
402,
23668,
5542,
12,
314,
9328,
17782,
365,
15248,
14670,
14,
339,
9328,
63,
1866,
520,
2069,
12,
849,
29,
17,
14,
16,
267,
29127,
6634,
19790,
83,
314,
406,
15980,
402,
1924,
12429,
701,
267,
1124,
10546,
63,
1866,
4345,
6006,
365,
282,
21032,
13,
1997,
3382,
1124,
10546,
63,
1866,
1040,
436,
267,
1124,
78,
63,
10646,
4345,
339,
5563,
520,
469,
1445,
51,
1156,
3635,
297,
283,
51,
1156,
3635,
14,
50,
28400,
849,
534,
51,
1156,
3635,
14,
50,
7,
267,
982,
283,
51,
1156,
3635,
14,
50,
7,
2066,
675,
314,
428,
1156,
3635,
14,
50,
3363,
20198,
316,
5563,
14,
267,
1124,
1095,
63,
8627,
1040,
1471,
2291,
15232,
402,
1021,
19555,
14,
267,
982,
283,
51,
1156,
3635,
7,
2066,
675,
314,
428,
1156,
3635,
24635,
20198,
316,
5563,
14,
267,
710,
428,
1156,
3635,
14,
50,
5563,
13609,
3818,
3389,
12930,
2419,
428,
1156,
3635,
12,
267,
22175,
4007,
282,
5117,
511,
1125,
543,
27392,
20198,
316,
10615,
14,
339,
469,
17376,
63,
8590,
93,
339,
8343,
520,
2155,
12,
849,
29,
797,
267,
7480,
503,
440,
370,
2690,
19311,
543,
8343,
503,
440,
14,
339,
469,
2355,
63,
929,
93,
339,
9382,
272,
4143,
272,
1300,
63,
8627,
63,
520,
8943,
267,
710,
1300,
8943,
687,
1314,
314,
19965,
365,
486,
18406,
14,
339,
23155,
63,
520,
769,
402,
19137,
267,
710,
3245,
402,
26093,
1007,
13,
10646,
14,
339,
2690,
2393,
63,
520,
769,
402,
9571,
16001,
27434,
267,
710,
3245,
402,
26093,
2690,
2393,
14,
339,
5200,
1278,
63,
520,
769,
402,
19090,
267,
710,
3245,
402,
26093,
5200,
1278,
334,
3271,
2393,
435,
14416,
680,
339,
3992,
63,
520,
6800,
402,
2215,
334,
78,
63,
2888,
4258,
267,
710,
3992,
3628,
14,
339,
302,
63,
2888,
63,
520,
1109,
267,
710,
1329,
402,
3992,
14,
339,
8943,
63,
4916,
63,
520,
6800,
402,
2215,
334,
78,
63,
8627,
4258,
267,
2136,
2492,
367,
1924,
8943,
315,
314,
1234,
17849,
19965,
14,
339,
8943,
63,
2550,
63,
520,
6800,
402,
2215,
334,
78,
63,
8627,
4258,
267,
8465,
7789,
1125,
367,
1924,
8943,
315,
314,
1234,
17849,
267,
19965,
14,
339,
3878,
63,
646,
13236,
63,
520,
6800,
402,
2215,
334,
78,
63,
3179,
4258,
267,
710,
3878,
492,
13236,
340,
3748,
701,
314,
1124,
1095,
63,
8627,
4345,
339,
1666,
6121,
272,
3001,
272,
23928,
554,
26256,
643,
1540,
8508,
520,
699,
643,
1540,
12429,
367,
1314,
1924,
1300,
267,
8943,
365,
28161,
641,
282,
14094,
68,
15865,
14,
339,
23928,
554,
68,
3883,
21668,
8508,
520,
9571,
27882,
18876,
2196,
13,
7138,
267,
15877,
370,
14094,
314,
3365,
8498,
270,
8146,
14,
339,
18951,
1327,
8834,
8508,
520,
3447,
8834,
402,
437,
983,
18814,
12429,
28161,
641,
267,
14094,
68,
8498,
270,
8146,
14,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
3240,
73,
1260,
84,
12,
445,
2020,
1804,
526,
609,
71,
1618,
502,
285,
12,
377,
14,
603,
2020,
812,
290,
869,
13055,
12,
1603,
2020,
1253,
653,
439,
79,
1051,
8143,
12,
437,
14,
2126,
298,
50,
1668,
18814,
26,
437,
7188,
14601,
18140,
370,
27458,
433,
1958,
1021,
284,
887,
279,
554,
2122,
473,
29146,
2126,
6266,
3723,
641,
15285,
12,
4688,
12,
436,
18461,
605,
685,
7769,
13,
8416,
437,
26,
15285,
436,
869,
453,
796,
2126,
6335,
14,
17,
334,
6542,
304,
413,
2426,
13,
11165,
14,
339,
6058,
272,
3001,
272,
1306,
687,
3416,
830,
1060,
14,
15628,
492,
820,
1668,
18814,
8508,
272,
1306,
687,
6357,
14,
12281,
492,
1852,
63,
14368,
272,
1306,
272,
1306,
1323,
12,
612,
275,
1852,
63,
14368,
8,
78,
63,
3356,
29,
5279,
12,
302,
63,
2888,
29,
19,
12,
272,
2263,
14960,
302,
63,
27666,
29,
20,
12,
4931,
1524,
16,
14,
18,
12,
378,
14,
19,
12,
378,
14,
21,
467,
272,
2263,
14960,
2196,
63,
929,
29,
16,
9,
272,
1306,
6975,
275,
820,
1668,
18814,
8508,
8,
2355,
63,
929,
29,
16,
9,
272,
1306,
6975,
14,
3269,
8,
56,
12,
612,
9,
221,
327,
8868,
26,
435,
21677,
272,
820,
1668,
18814,
8508
] |
[
1331,
492,
14800,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1095,
492,
7289,
199,
504,
6357,
14,
15628,
492,
437,
983,
18814,
8508,
199,
504,
6357,
14,
15628,
423,
1095,
492,
485,
409,
63,
2355,
63,
4981,
199,
504,
6357,
14,
1208,
492,
485,
3489,
63,
28703,
199,
199,
504,
2508,
7138,
63,
17376,
14,
1095,
492,
3523,
16001,
27434,
199,
504,
2508,
7138,
63,
17376,
492,
9571,
16001,
27434,
199,
504,
2508,
7379,
492,
1852,
63,
7379,
199,
504,
2508,
1208,
492,
4804,
26575,
12,
1104,
63,
1375,
63,
466,
199,
504,
2508,
1208,
423,
12485,
492,
485,
2355,
63,
929,
63,
12485,
199,
504,
2508,
1208,
423,
6136,
492,
485,
27891,
63,
17867,
63,
589,
421,
199,
32,
2610,
26575,
8,
272,
15877,
63,
8590,
29,
1563,
16001,
27434,
423,
17376,
63,
8590,
63,
12485,
12,
272,
2196,
63,
929,
3699,
2355,
63,
929,
63,
12485,
12,
199,
9,
199,
533,
820,
1668,
18814,
8508,
8,
33,
983,
18814,
8508,
304,
272,
408,
3883,
1334,
13,
17376,
17806,
972,
315,
314,
9328,
402,
437,
983,
18814,
14,
339,
577,
4039,
9328,
12,
314,
5160,
402,
1021,
29300,
365,
27458,
433,
972,
701,
2196,
272,
1334,
13,
17376,
314,
2690,
737,
1924,
8494,
402,
314,
20198,
316,
5563,
14,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
15589,
316,
14943,
339,
2508,
7445,
447,
378,
14,
20,
339,
3897,
272,
4143,
272,
1300,
63,
8627,
520,
8943,
909,
12,
849,
29,
403,
267,
710,
1300,
8943,
687,
1314,
314,
1234,
17849,
19965,
365,
6137,
14,
267,
12502,
367,
2690,
5401,
316,
365,
1415,
12,
465,
5521,
465,
5576,
267,
1124,
2888,
63,
1040,
436,
1124,
78,
63,
2888,
63,
1040,
3004,
14,
982,
1124,
403,
4542,
2066,
267,
314,
1300,
8943,
365,
1124,
872,
24116,
8508,
8,
988,
63,
4631,
29,
17,
20642,
339,
302,
63,
10646,
520,
1109,
12,
849,
29,
1400,
267,
710,
5696,
1329,
402,
23155,
737,
1314,
20198,
316,
365,
15745,
14,
267,
1010,
1930,
402,
23668,
5542,
12,
314,
9328,
17782,
365,
15248,
14670,
14,
339,
9328,
63,
1866,
520,
2069,
12,
849,
29,
17,
14,
16,
267,
29127,
6634,
19790,
83,
314,
406,
15980,
402,
1924,
12429,
701,
267,
1124,
10546,
63,
1866,
4345,
6006,
365,
282,
21032,
13,
1997,
3382,
1124,
10546,
63,
1866,
1040,
436,
267,
1124,
78,
63,
10646,
4345,
339,
5563,
520,
469,
1445,
51,
1156,
3635,
297,
283,
51,
1156,
3635,
14,
50,
28400,
849,
534,
51,
1156,
3635,
14,
50,
7,
267,
982,
283,
51,
1156,
3635,
14,
50,
7,
2066,
675,
314,
428,
1156,
3635,
14,
50,
3363,
20198,
316,
5563,
14,
267,
1124,
1095,
63,
8627,
1040,
1471,
2291,
15232,
402,
1021,
19555,
14,
267,
982,
283,
51,
1156,
3635,
7,
2066,
675,
314,
428,
1156,
3635,
24635,
20198,
316,
5563,
14,
267,
710,
428,
1156,
3635,
14,
50,
5563,
13609,
3818,
3389,
12930,
2419,
428,
1156,
3635,
12,
267,
22175,
4007,
282,
5117,
511,
1125,
543,
27392,
20198,
316,
10615,
14,
339,
469,
17376,
63,
8590,
93,
339,
8343,
520,
2155,
12,
849,
29,
797,
267,
7480,
503,
440,
370,
2690,
19311,
543,
8343,
503,
440,
14,
339,
469,
2355,
63,
929,
93,
339,
9382,
272,
4143,
272,
1300,
63,
8627,
63,
520,
8943,
267,
710,
1300,
8943,
687,
1314,
314,
19965,
365,
486,
18406,
14,
339,
23155,
63,
520,
769,
402,
19137,
267,
710,
3245,
402,
26093,
1007,
13,
10646,
14,
339,
2690,
2393,
63,
520,
769,
402,
9571,
16001,
27434,
267,
710,
3245,
402,
26093,
2690,
2393,
14,
339,
5200,
1278,
63,
520,
769,
402,
19090,
267,
710,
3245,
402,
26093,
5200,
1278,
334,
3271,
2393,
435,
14416,
680,
339,
3992,
63,
520,
6800,
402,
2215,
334,
78,
63,
2888,
4258,
267,
710,
3992,
3628,
14,
339,
302,
63,
2888,
63,
520,
1109,
267,
710,
1329,
402,
3992,
14,
339,
8943,
63,
4916,
63,
520,
6800,
402,
2215,
334,
78,
63,
8627,
4258,
267,
2136,
2492,
367,
1924,
8943,
315,
314,
1234,
17849,
19965,
14,
339,
8943,
63,
2550,
63,
520,
6800,
402,
2215,
334,
78,
63,
8627,
4258,
267,
8465,
7789,
1125,
367,
1924,
8943,
315,
314,
1234,
17849,
267,
19965,
14,
339,
3878,
63,
646,
13236,
63,
520,
6800,
402,
2215,
334,
78,
63,
3179,
4258,
267,
710,
3878,
492,
13236,
340,
3748,
701,
314,
1124,
1095,
63,
8627,
4345,
339,
1666,
6121,
272,
3001,
272,
23928,
554,
26256,
643,
1540,
8508,
520,
699,
643,
1540,
12429,
367,
1314,
1924,
1300,
267,
8943,
365,
28161,
641,
282,
14094,
68,
15865,
14,
339,
23928,
554,
68,
3883,
21668,
8508,
520,
9571,
27882,
18876,
2196,
13,
7138,
267,
15877,
370,
14094,
314,
3365,
8498,
270,
8146,
14,
339,
18951,
1327,
8834,
8508,
520,
3447,
8834,
402,
437,
983,
18814,
12429,
28161,
641,
267,
14094,
68,
8498,
270,
8146,
14,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
3240,
73,
1260,
84,
12,
445,
2020,
1804,
526,
609,
71,
1618,
502,
285,
12,
377,
14,
603,
2020,
812,
290,
869,
13055,
12,
1603,
2020,
1253,
653,
439,
79,
1051,
8143,
12,
437,
14,
2126,
298,
50,
1668,
18814,
26,
437,
7188,
14601,
18140,
370,
27458,
433,
1958,
1021,
284,
887,
279,
554,
2122,
473,
29146,
2126,
6266,
3723,
641,
15285,
12,
4688,
12,
436,
18461,
605,
685,
7769,
13,
8416,
437,
26,
15285,
436,
869,
453,
796,
2126,
6335,
14,
17,
334,
6542,
304,
413,
2426,
13,
11165,
14,
339,
6058,
272,
3001,
272,
1306,
687,
3416,
830,
1060,
14,
15628,
492,
820,
1668,
18814,
8508,
272,
1306,
687,
6357,
14,
12281,
492,
1852,
63,
14368,
272,
1306,
272,
1306,
1323,
12,
612,
275,
1852,
63,
14368,
8,
78,
63,
3356,
29,
5279,
12,
302,
63,
2888,
29,
19,
12,
272,
2263,
14960,
302,
63,
27666,
29,
20,
12,
4931,
1524,
16,
14,
18,
12,
378,
14,
19,
12,
378,
14,
21,
467,
272,
2263,
14960,
2196,
63,
929,
29,
16,
9,
272,
1306,
6975,
275,
820,
1668,
18814,
8508,
8,
2355,
63,
929,
29,
16,
9,
272,
1306,
6975,
14,
3269,
8,
56,
12,
612,
9,
221,
327,
8868,
26,
435,
21677,
272,
820,
1668,
18814,
8508,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
apdjustino/DRCOG_Urbansim
|
urbandeveloper/elasticity_model_2SLS.py
|
1
|
6896
|
__author__ = 'JMartinez'
import numpy as np, pandas as pd, os
from synthicity.utils import misc
import pysal as py
class elasticity_model(object):
def __init__(self, dset):
self.zones = dset.zones
self.buildings_far = pd.merge(dset.buildings, dset.fars, left_on='far_id', right_index=True)
def estimate_elasticity(self, zones):
dummies = pd.get_dummies(zones.county)
zones = pd.concat([zones, dummies], axis=1)
zones['avg_far'] = self.buildings_far.groupby('zone_id').far.mean() #use far_x because Xavier's code adds far to buildings
#zones = zones[zones.residential_sqft_zone>0]
#wrook = py.queen_from_shapefile('C:/users/jmartinez/documents/Test Zones/zones_prj_res2.shp')
wqueen = py.queen_from_shapefile(os.path.join(misc.data_dir(),'shapefiles\\zones.shp'))
w = py.weights.weights.W(wqueen.neighbors, wqueen.weights)
x = zones[['zonal_pop','mean_income']]
x = x.apply(np.log1p)
x['ln_jobs_within_30min'] = zones['ln_jobs_within_30min']
x['zone_contains_park'] = zones['zone_contains_park']
x['Arapahoe'] = zones['Arapahoe']
x['Boulder'] = zones['Boulder']
x['Broomfield'] = zones['Broomfield']
x['Clear Creek'] = zones['Clear Creek']
x['Denver'] = zones['Denver']
x['Douglas'] = zones['Douglas']
x['Elbert'] = zones['Elbert']
x['Gilpin'] = zones['Gilpin']
x['Jefferson'] = zones['Jefferson']
x['Weld'] = zones['Weld']
x=x.fillna(0)
x = x.as_matrix()
imat = zones[['ln_avg_nonres_unit_price_zone','avg_far']]
imat = imat.fillna(0)
imat = imat.as_matrix()
yend = zones['ln_avg_unit_price_zone']
yend = yend.fillna(0)
yend = yend.as_matrix()
yend = np.reshape(yend,(zones.shape[0],1))
y = zones['residential_sqft_zone']
y = y.fillna(0)
y = y.apply(np.log1p)
y = y.as_matrix()
y = np.reshape(y,(zones.shape[0],1))
imat_names = ['non_res_price','avg_far']
x_names = ['zonal_pop', 'mean_income', 'ln_jobs_within_30min', 'zone_contains_park','Arapahoe','Boulder','Broomfield','Clear Creek','Denver','Douglas','Elbert','Gilpin','Jefferson','Weld']
yend_name = ['ln_avg_unit_price_zone']
y_name = 'residential_sqft_zone'
reg_2sls = py.spreg.twosls_sp.GM_Lag(y, x, yend=yend, q=imat, w=w, w_lags=2, robust ='white', name_x = x_names, name_q = imat_names, name_y = y_name, name_yend = yend_name)
demand_elasticity = np.absolute(reg_2sls.betas[15])
demand_elasticity = 1/demand_elasticity[0]
#
return demand_elasticity
def estimate_non_res_elasticity(self,zones):
dummies = pd.get_dummies(zones.county)
zones = pd.concat([zones, dummies], axis=1)
zones['avg_far'] = self.buildings_far.groupby('zone_id').far.mean() #use far_x because Xavier's code adds far to buildings
#zones = zones[zones.non_residential_sqft_zone>0]
####spatial weights matrix#####
#zones = zones.reset_index()
#zone_coord = zones[['zone_id','zonecentroid_x', 'zonecentroid_y']]
#zone_coord = zone_coord.as_matrix()
wqueen = py.queen_from_shapefile(os.path.join(misc.data_dir(),'shapefiles\\zones.shp'))
#w = py.weights.Distance.DistanceBand(zone_coord, threshold = 50000, binary = False)
#w.transform ='r'
#w = py.weights.weights.W(w.neighbors, w.weights)
w = py.weights.weights.W(wqueen.neighbors, wqueen.weights)
x = zones[['zonal_emp','residential_units_zone']]
x = x.apply(np.log1p)
#x['ln_emp_aggsector_within_5min'] = zones['ln_emp_aggsector_within_5min']
#x['zone_contains_park'] = zones['zone_contains_park']
x['percent_younghead'] = zones['percent_younghead']
x['Arapahoe'] = zones['Arapahoe']
x['Boulder'] = zones['Boulder']
x['Broomfield'] = zones['Broomfield']
x['Clear Creek'] = zones['Clear Creek']
x['Denver'] = zones['Denver']
x['Douglas'] = zones['Douglas']
x['Elbert'] = zones['Elbert']
x['Gilpin'] = zones['Gilpin']
x['Jefferson'] = zones['Jefferson']
x['Weld'] = zones['Weld']
x=x.fillna(0)
x = x.as_matrix()
imat = zones[['ln_avg_unit_price_zone','avg_far']]
imat = imat.fillna(0)
imat = imat.as_matrix()
yend = zones['ln_avg_nonres_unit_price_zone']
yend = yend.fillna(0)
yend = yend.as_matrix()
yend = np.reshape(yend,(zones.shape[0],1))
y = zones['non_residential_sqft_zone']
y = y.fillna(0)
y = y.apply(np.log1p)
y = y.as_matrix()
y = np.reshape(y,(zones.shape[0],1))
imat_names = ['res_price','avg_far']
x_names = ['zonal_emp', 'residential_units_zone', 'percent_younghead','Arapahoe','Boulder','Broomfield','Clear Creek', 'Denver', 'Douglas','Elbert','Gilpin','Jefferson','Weld']
yend_name = ['ln_avg_nonres_unit_price_zone']
y_name = 'non_residential_sqft_zone'
reg_2sls = py.spreg.twosls_sp.GM_Lag(y, x, yend=yend, q=imat, w=w, w_lags=2,robust ='white', name_x = x_names, name_q = imat_names, name_y = y_name, name_yend = yend_name)
#
# ######estimation
# x = zones[['zonal_emp','residential_units_zone']]
# x = x.apply(np.log1p)
# #x['ln_emp_aggsector_within_5min'] = zones['ln_emp_aggsector_within_5min']
# #x['zone_contains_park'] = zones['zone_contains_park']
# x['percent_younghead'] = zones['percent_younghead']
# x=x.fillna(0)
# x = x.as_matrix()
#
# imat = zones[['ln_avg_unit_price_zone','ln_avg_land_value_per_sqft_zone','median_year_built']]
# imat = imat.fillna(0)
# imat = imat.as_matrix()
#
# yend = zones['ln_avg_nonres_unit_price_zone']
# yend = yend.fillna(0)
# yend = yend.as_matrix()
# yend = np.reshape(yend,(zones.shape[0],1))
#
# y = zones['non_residential_sqft_zone']
# y = y.fillna(0)
# y = y.apply(np.log1p)
# y = y.as_matrix()
# y = np.reshape(y,(zones.shape[0],1))
#
#
# imat_names = ['res_price','land_value','median_year_built']
# x_names = ['zonal_emp', 'residential_units_zone', 'percent_younghead']
# yend_name = ['ln_avg_nonres_unit_price_zone']
# y_name = 'non_residential_sqft_zone'
#
# reg_2sls = py.spreg.twosls_sp.GM_Lag(y, x, yend=yend, q=imat, w=w, robust ='white', name_x = x_names, name_q = imat_names, name_y = y_name, name_yend = yend_name)
#
#
demand_elasticity = np.absolute(reg_2sls.betas[14])
demand_elasticity = 1/demand_elasticity[0]
#
return demand_elasticity
|
agpl-3.0
|
[
363,
2502,
363,
275,
283,
42,
45,
580,
1132,
90,
7,
421,
199,
646,
2680,
465,
980,
12,
10634,
465,
6454,
12,
747,
199,
504,
9560,
273,
530,
1209,
14,
1208,
492,
18576,
199,
646,
10382,
279,
465,
1134,
199,
199,
533,
24380,
1209,
63,
1238,
8,
785,
304,
2378,
347,
636,
826,
721,
277,
12,
366,
409,
304,
267,
291,
14,
13325,
275,
366,
409,
14,
13325,
267,
291,
14,
32589,
63,
15315,
275,
6454,
14,
5628,
8,
68,
409,
14,
32589,
12,
366,
409,
14,
70,
4291,
12,
3602,
63,
265,
534,
15315,
63,
344,
297,
2451,
63,
1080,
29,
549,
9,
421,
2378,
347,
14497,
63,
15565,
1209,
8,
277,
12,
18666,
304,
267,
366,
453,
31284,
275,
6454,
14,
362,
63,
27512,
31284,
8,
13325,
14,
3094,
369,
9,
267,
18666,
275,
6454,
14,
9419,
779,
13325,
12,
366,
453,
31284,
467,
3114,
29,
17,
9,
267,
18666,
459,
8595,
63,
15315,
418,
275,
291,
14,
32589,
63,
15315,
14,
16968,
360,
2619,
63,
344,
1959,
15315,
14,
3670,
342,
327,
1180,
12474,
63,
88,
2952,
1323,
7194,
281,
1159,
1233,
9584,
12474,
370,
1900,
780,
398,
327,
13325,
275,
18666,
59,
13325,
14,
20807,
3256,
63,
3526,
856,
63,
2619,
30,
16,
61,
398,
327,
87,
293,
745,
275,
1134,
14,
544,
287,
63,
504,
63,
1392,
493,
360,
35,
11254,
3707,
15,
74,
77,
580,
1132,
90,
15,
12233,
15,
774,
3107,
4548,
15,
13325,
63,
2700,
74,
63,
470,
18,
14,
17299,
358,
267,
336,
544,
287,
275,
1134,
14,
544,
287,
63,
504,
63,
1392,
493,
8,
736,
14,
515,
14,
904,
8,
9923,
14,
576,
63,
694,
1062,
7,
1392,
1725,
1103,
13325,
14,
17299,
1333,
267,
336,
275,
1134,
14,
4916,
14,
4916,
14,
55,
8,
87,
544,
287,
14,
11113,
12,
336,
544,
287,
14,
4916,
9,
267,
671,
275,
18666,
59,
459,
90,
8125,
63,
1935,
1673,
3670,
63,
23607,
6538,
267,
671,
275,
671,
14,
4998,
8,
1590,
14,
793,
17,
80,
9,
398,
671,
459,
6066,
63,
6920,
63,
12541,
63,
1216,
827,
418,
275,
18666,
459,
6066,
63,
6920,
63,
12541,
63,
1216,
827,
418,
267,
671,
459,
2619,
63,
6134,
63,
5149,
418,
275,
18666,
459,
2619,
63,
6134,
63,
5149,
418,
267,
671,
459,
33,
345,
387,
526,
69,
418,
275,
18666,
459,
33,
345,
387,
526,
69,
418,
267,
671,
459,
2208,
348,
424,
418,
275,
18666,
459,
2208,
348,
424,
418,
267,
671,
459,
34,
11245,
698,
418,
275,
18666,
459,
34,
11245,
698,
418,
267,
671,
459,
9721,
445,
14291,
418,
275,
18666,
459,
9721,
445,
14291,
418,
267,
671,
459,
10655,
422,
418,
275,
18666,
459,
10655,
422,
418,
267,
671,
459,
36,
810,
3528,
305,
418,
275,
18666,
459,
36,
810,
3528,
305,
418,
267,
671,
459,
10420,
12504,
418,
275,
18666,
459,
10420,
12504,
418,
267,
671,
459,
39,
382,
7751,
418,
275,
18666,
459,
39,
382,
7751,
418,
267,
671,
459,
27888,
1260,
834,
418,
275,
18666,
459,
27888,
1260,
834,
418,
267,
671,
459,
55,
457,
418,
275,
18666,
459,
55,
457,
418,
267,
671,
29,
88,
14,
4498,
3540,
8,
16,
9,
267,
671,
275,
671,
14,
305,
63,
3642,
342,
398,
284,
569,
275,
18666,
59,
459,
6066,
63,
8595,
63,
2865,
470,
63,
3248,
63,
4777,
63,
2619,
1673,
8595,
63,
15315,
6538,
267,
284,
569,
275,
284,
569,
14,
4498,
3540,
8,
16,
9,
267,
284,
569,
275,
284,
569,
14,
305,
63,
3642,
342,
398,
612,
500,
275,
18666,
459,
6066,
63,
8595,
63,
3248,
63,
4777,
63,
2619,
418,
267,
612,
500,
275,
612,
500,
14,
4498,
3540,
8,
16,
9,
267,
612,
500,
275,
612,
500,
14,
305,
63,
3642,
342,
267,
612,
500,
275,
980,
14,
5217,
8,
89,
500,
12803,
13325,
14,
1392,
59,
16,
467,
17,
430,
398,
612,
275,
18666,
459,
20807,
3256,
63,
3526,
856,
63,
2619,
418,
267,
612,
275,
612,
14,
4498,
3540,
8,
16,
9,
267,
612,
275,
612,
14,
4998,
8,
1590,
14,
793,
17,
80,
9,
267,
612,
275,
612,
14,
305,
63,
3642,
342,
267,
612,
275,
980,
14,
5217,
8,
89,
12803,
13325,
14,
1392,
59,
16,
467,
17,
430,
7318,
284,
569,
63,
1247,
275,
788,
2865,
63,
470,
63,
4777,
1673,
8595,
63,
15315,
418,
267,
671,
63,
1247,
275,
788,
90,
8125,
63,
1935,
297,
283,
3670,
63,
23607,
297,
283,
6066,
63,
6920,
63,
12541,
63,
1216,
827,
297,
283,
2619,
63,
6134,
63,
5149,
1673,
33,
345,
387,
526,
69,
1673,
2208,
348,
424,
1673,
34,
11245,
698,
1673,
9721,
445,
14291,
1673,
10655,
422,
1673,
36,
810,
3528,
305,
1673,
10420,
12504,
1673,
39,
382,
7751,
1673,
27888,
1260,
834,
1673,
55,
457,
418,
267,
612,
500,
63,
354,
275,
788,
6066,
63,
8595,
63,
3248,
63,
4777,
63,
2619,
418,
267,
612,
63,
354,
275,
283,
20807,
3256,
63,
3526,
856,
63,
2619,
7,
398,
1295,
63,
18,
83,
478,
275,
1134,
14,
83,
657,
71,
14,
8122,
736,
478,
63,
681,
14,
22636,
63,
44,
643,
8,
89,
12,
671,
12,
612,
500,
29,
89,
500,
12,
1894,
29,
3969,
12,
336,
29,
87,
12,
336,
63,
1550,
29,
18,
12,
23399,
275,
7,
7510,
297,
536,
63,
88,
275,
671,
63,
1247,
12,
536,
63,
81,
275,
284,
569,
63,
1247,
12,
536,
63,
89,
275,
612,
63,
354,
12,
536,
63,
89,
500,
275,
612,
500,
63,
354,
9,
398,
29237,
63,
15565,
1209,
275,
980,
14,
6116,
8,
1135,
63,
18,
83,
478,
14,
9549,
305,
59,
1046,
566,
267,
29237,
63,
15565,
1209,
275,
413,
15,
24152,
63,
15565,
1209,
59,
16,
61,
267,
327,
267,
372,
29237,
63,
15565,
1209,
2378,
347,
14497,
63,
2865,
63,
470,
63,
15565,
1209,
8,
277,
12,
13325,
304,
398,
366,
453,
31284,
275,
6454,
14,
362,
63,
27512,
31284,
8,
13325,
14,
3094,
369,
9,
267,
18666,
275,
6454,
14,
9419,
779,
13325,
12,
366,
453,
31284,
467,
3114,
29,
17,
9,
267,
18666,
459,
8595,
63,
15315,
418,
275,
291,
14,
32589,
63,
15315,
14,
16968,
360,
2619,
63
] |
[
2502,
363,
275,
283,
42,
45,
580,
1132,
90,
7,
421,
199,
646,
2680,
465,
980,
12,
10634,
465,
6454,
12,
747,
199,
504,
9560,
273,
530,
1209,
14,
1208,
492,
18576,
199,
646,
10382,
279,
465,
1134,
199,
199,
533,
24380,
1209,
63,
1238,
8,
785,
304,
2378,
347,
636,
826,
721,
277,
12,
366,
409,
304,
267,
291,
14,
13325,
275,
366,
409,
14,
13325,
267,
291,
14,
32589,
63,
15315,
275,
6454,
14,
5628,
8,
68,
409,
14,
32589,
12,
366,
409,
14,
70,
4291,
12,
3602,
63,
265,
534,
15315,
63,
344,
297,
2451,
63,
1080,
29,
549,
9,
421,
2378,
347,
14497,
63,
15565,
1209,
8,
277,
12,
18666,
304,
267,
366,
453,
31284,
275,
6454,
14,
362,
63,
27512,
31284,
8,
13325,
14,
3094,
369,
9,
267,
18666,
275,
6454,
14,
9419,
779,
13325,
12,
366,
453,
31284,
467,
3114,
29,
17,
9,
267,
18666,
459,
8595,
63,
15315,
418,
275,
291,
14,
32589,
63,
15315,
14,
16968,
360,
2619,
63,
344,
1959,
15315,
14,
3670,
342,
327,
1180,
12474,
63,
88,
2952,
1323,
7194,
281,
1159,
1233,
9584,
12474,
370,
1900,
780,
398,
327,
13325,
275,
18666,
59,
13325,
14,
20807,
3256,
63,
3526,
856,
63,
2619,
30,
16,
61,
398,
327,
87,
293,
745,
275,
1134,
14,
544,
287,
63,
504,
63,
1392,
493,
360,
35,
11254,
3707,
15,
74,
77,
580,
1132,
90,
15,
12233,
15,
774,
3107,
4548,
15,
13325,
63,
2700,
74,
63,
470,
18,
14,
17299,
358,
267,
336,
544,
287,
275,
1134,
14,
544,
287,
63,
504,
63,
1392,
493,
8,
736,
14,
515,
14,
904,
8,
9923,
14,
576,
63,
694,
1062,
7,
1392,
1725,
1103,
13325,
14,
17299,
1333,
267,
336,
275,
1134,
14,
4916,
14,
4916,
14,
55,
8,
87,
544,
287,
14,
11113,
12,
336,
544,
287,
14,
4916,
9,
267,
671,
275,
18666,
59,
459,
90,
8125,
63,
1935,
1673,
3670,
63,
23607,
6538,
267,
671,
275,
671,
14,
4998,
8,
1590,
14,
793,
17,
80,
9,
398,
671,
459,
6066,
63,
6920,
63,
12541,
63,
1216,
827,
418,
275,
18666,
459,
6066,
63,
6920,
63,
12541,
63,
1216,
827,
418,
267,
671,
459,
2619,
63,
6134,
63,
5149,
418,
275,
18666,
459,
2619,
63,
6134,
63,
5149,
418,
267,
671,
459,
33,
345,
387,
526,
69,
418,
275,
18666,
459,
33,
345,
387,
526,
69,
418,
267,
671,
459,
2208,
348,
424,
418,
275,
18666,
459,
2208,
348,
424,
418,
267,
671,
459,
34,
11245,
698,
418,
275,
18666,
459,
34,
11245,
698,
418,
267,
671,
459,
9721,
445,
14291,
418,
275,
18666,
459,
9721,
445,
14291,
418,
267,
671,
459,
10655,
422,
418,
275,
18666,
459,
10655,
422,
418,
267,
671,
459,
36,
810,
3528,
305,
418,
275,
18666,
459,
36,
810,
3528,
305,
418,
267,
671,
459,
10420,
12504,
418,
275,
18666,
459,
10420,
12504,
418,
267,
671,
459,
39,
382,
7751,
418,
275,
18666,
459,
39,
382,
7751,
418,
267,
671,
459,
27888,
1260,
834,
418,
275,
18666,
459,
27888,
1260,
834,
418,
267,
671,
459,
55,
457,
418,
275,
18666,
459,
55,
457,
418,
267,
671,
29,
88,
14,
4498,
3540,
8,
16,
9,
267,
671,
275,
671,
14,
305,
63,
3642,
342,
398,
284,
569,
275,
18666,
59,
459,
6066,
63,
8595,
63,
2865,
470,
63,
3248,
63,
4777,
63,
2619,
1673,
8595,
63,
15315,
6538,
267,
284,
569,
275,
284,
569,
14,
4498,
3540,
8,
16,
9,
267,
284,
569,
275,
284,
569,
14,
305,
63,
3642,
342,
398,
612,
500,
275,
18666,
459,
6066,
63,
8595,
63,
3248,
63,
4777,
63,
2619,
418,
267,
612,
500,
275,
612,
500,
14,
4498,
3540,
8,
16,
9,
267,
612,
500,
275,
612,
500,
14,
305,
63,
3642,
342,
267,
612,
500,
275,
980,
14,
5217,
8,
89,
500,
12803,
13325,
14,
1392,
59,
16,
467,
17,
430,
398,
612,
275,
18666,
459,
20807,
3256,
63,
3526,
856,
63,
2619,
418,
267,
612,
275,
612,
14,
4498,
3540,
8,
16,
9,
267,
612,
275,
612,
14,
4998,
8,
1590,
14,
793,
17,
80,
9,
267,
612,
275,
612,
14,
305,
63,
3642,
342,
267,
612,
275,
980,
14,
5217,
8,
89,
12803,
13325,
14,
1392,
59,
16,
467,
17,
430,
7318,
284,
569,
63,
1247,
275,
788,
2865,
63,
470,
63,
4777,
1673,
8595,
63,
15315,
418,
267,
671,
63,
1247,
275,
788,
90,
8125,
63,
1935,
297,
283,
3670,
63,
23607,
297,
283,
6066,
63,
6920,
63,
12541,
63,
1216,
827,
297,
283,
2619,
63,
6134,
63,
5149,
1673,
33,
345,
387,
526,
69,
1673,
2208,
348,
424,
1673,
34,
11245,
698,
1673,
9721,
445,
14291,
1673,
10655,
422,
1673,
36,
810,
3528,
305,
1673,
10420,
12504,
1673,
39,
382,
7751,
1673,
27888,
1260,
834,
1673,
55,
457,
418,
267,
612,
500,
63,
354,
275,
788,
6066,
63,
8595,
63,
3248,
63,
4777,
63,
2619,
418,
267,
612,
63,
354,
275,
283,
20807,
3256,
63,
3526,
856,
63,
2619,
7,
398,
1295,
63,
18,
83,
478,
275,
1134,
14,
83,
657,
71,
14,
8122,
736,
478,
63,
681,
14,
22636,
63,
44,
643,
8,
89,
12,
671,
12,
612,
500,
29,
89,
500,
12,
1894,
29,
3969,
12,
336,
29,
87,
12,
336,
63,
1550,
29,
18,
12,
23399,
275,
7,
7510,
297,
536,
63,
88,
275,
671,
63,
1247,
12,
536,
63,
81,
275,
284,
569,
63,
1247,
12,
536,
63,
89,
275,
612,
63,
354,
12,
536,
63,
89,
500,
275,
612,
500,
63,
354,
9,
398,
29237,
63,
15565,
1209,
275,
980,
14,
6116,
8,
1135,
63,
18,
83,
478,
14,
9549,
305,
59,
1046,
566,
267,
29237,
63,
15565,
1209,
275,
413,
15,
24152,
63,
15565,
1209,
59,
16,
61,
267,
327,
267,
372,
29237,
63,
15565,
1209,
2378,
347,
14497,
63,
2865,
63,
470,
63,
15565,
1209,
8,
277,
12,
13325,
304,
398,
366,
453,
31284,
275,
6454,
14,
362,
63,
27512,
31284,
8,
13325,
14,
3094,
369,
9,
267,
18666,
275,
6454,
14,
9419,
779,
13325,
12,
366,
453,
31284,
467,
3114,
29,
17,
9,
267,
18666,
459,
8595,
63,
15315,
418,
275,
291,
14,
32589,
63,
15315,
14,
16968,
360,
2619,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
mitchelljkotler/django
|
django/contrib/gis/geos/prototypes/threadsafe.py
|
529
|
2859
|
import threading
from django.contrib.gis.geos.libgeos import (
CONTEXT_PTR, error_h, lgeos, notice_h,
)
class GEOSContextHandle(object):
"""
Python object representing a GEOS context handle.
"""
def __init__(self):
# Initializing the context handler for this thread with
# the notice and error handler.
self.ptr = lgeos.initGEOS_r(notice_h, error_h)
def __del__(self):
if self.ptr and lgeos:
lgeos.finishGEOS_r(self.ptr)
# Defining a thread-local object and creating an instance
# to hold a reference to GEOSContextHandle for this thread.
class GEOSContext(threading.local):
handle = None
thread_context = GEOSContext()
class GEOSFunc(object):
"""
Class that serves as a wrapper for GEOS C Functions, and will
use thread-safe function variants when available.
"""
def __init__(self, func_name):
try:
# GEOS thread-safe function signatures end with '_r', and
# take an additional context handle parameter.
self.cfunc = getattr(lgeos, func_name + '_r')
self.threaded = True
# Create a reference here to thread_context so it's not
# garbage-collected before an attempt to call this object.
self.thread_context = thread_context
except AttributeError:
# Otherwise, use usual function.
self.cfunc = getattr(lgeos, func_name)
self.threaded = False
def __call__(self, *args):
if self.threaded:
# If a context handle does not exist for this thread, initialize one.
if not self.thread_context.handle:
self.thread_context.handle = GEOSContextHandle()
# Call the threaded GEOS routine with pointer of the context handle
# as the first argument.
return self.cfunc(self.thread_context.handle.ptr, *args)
else:
return self.cfunc(*args)
def __str__(self):
return self.cfunc.__name__
# argtypes property
def _get_argtypes(self):
return self.cfunc.argtypes
def _set_argtypes(self, argtypes):
if self.threaded:
new_argtypes = [CONTEXT_PTR]
new_argtypes.extend(argtypes)
self.cfunc.argtypes = new_argtypes
else:
self.cfunc.argtypes = argtypes
argtypes = property(_get_argtypes, _set_argtypes)
# restype property
def _get_restype(self):
return self.cfunc.restype
def _set_restype(self, restype):
self.cfunc.restype = restype
restype = property(_get_restype, _set_restype)
# errcheck property
def _get_errcheck(self):
return self.cfunc.errcheck
def _set_errcheck(self, errcheck):
self.cfunc.errcheck = errcheck
errcheck = property(_get_errcheck, _set_errcheck)
|
bsd-3-clause
|
[
646,
5796,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
773,
12151,
492,
334,
272,
1868,
3876,
63,
14528,
12,
1125,
63,
72,
12,
634,
12151,
12,
4245,
63,
72,
12,
199,
9,
421,
199,
533,
11920,
2998,
5940,
8,
785,
304,
272,
408,
272,
2018,
909,
6144,
282,
11920,
1067,
2429,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
327,
6026,
9147,
314,
1067,
3016,
367,
642,
2462,
543,
267,
327,
314,
4245,
436,
1125,
3016,
14,
267,
291,
14,
4695,
275,
634,
12151,
14,
826,
14151,
63,
82,
8,
20556,
63,
72,
12,
1125,
63,
72,
9,
339,
347,
636,
2264,
721,
277,
304,
267,
340,
291,
14,
4695,
436,
634,
12151,
26,
288,
634,
12151,
14,
8192,
14151,
63,
82,
8,
277,
14,
4695,
9,
421,
199,
3,
1487,
2408,
316,
282,
2462,
13,
1832,
909,
436,
6425,
376,
1256,
199,
3,
370,
10266,
282,
3659,
370,
11920,
2998,
5940,
367,
642,
2462,
14,
199,
533,
11920,
2998,
8,
12562,
14,
1832,
304,
272,
2429,
275,
488,
199,
199,
2671,
63,
1100,
275,
11920,
2998,
342,
421,
199,
533,
11920,
7465,
8,
785,
304,
272,
408,
272,
8089,
626,
23739,
465,
282,
4975,
367,
11920,
445,
17471,
12,
436,
911,
272,
675,
2462,
13,
3489,
805,
21169,
1380,
2808,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2562,
63,
354,
304,
267,
862,
26,
288,
327,
11920,
2462,
13,
3489,
805,
17597,
1284,
543,
2513,
82,
297,
436,
288,
327,
5452,
376,
4722,
1067,
2429,
2725,
14,
288,
291,
14,
67,
1532,
275,
2519,
8,
76,
12151,
12,
2562,
63,
354,
435,
2513,
82,
358,
288,
291,
14,
19710,
275,
715,
288,
327,
2790,
282,
3659,
2348,
370,
2462,
63,
1100,
880,
652,
1159,
440,
288,
327,
17516,
13,
22766,
2544,
376,
7427,
370,
1240,
642,
909,
14,
288,
291,
14,
2671,
63,
1100,
275,
2462,
63,
1100,
267,
871,
4281,
26,
288,
327,
6630,
12,
675,
20195,
805,
14,
288,
291,
14,
67,
1532,
275,
2519,
8,
76,
12151,
12,
2562,
63,
354,
9,
288,
291,
14,
19710,
275,
756,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
267,
340,
291,
14,
19710,
26,
288,
327,
982,
282,
1067,
2429,
1630,
440,
2187,
367,
642,
2462,
12,
8265,
1373,
14,
288,
340,
440,
291,
14,
2671,
63,
1100,
14,
2479,
26,
355,
291,
14,
2671,
63,
1100,
14,
2479,
275,
11920,
2998,
5940,
342,
288,
327,
6523,
314,
25396,
11920,
12981,
543,
7849,
402,
314,
1067,
2429,
288,
327,
465,
314,
1642,
1423,
14,
288,
372,
291,
14,
67,
1532,
8,
277,
14,
2671,
63,
1100,
14,
2479,
14,
4695,
12,
627,
589,
9,
267,
587,
26,
288,
372,
291,
14,
67,
1532,
2031,
589,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
67,
1532,
855,
354,
363,
339,
327,
29669,
3324,
272,
347,
485,
362,
63,
10025,
8,
277,
304,
267,
372,
291,
14,
67,
1532,
14,
10025,
339,
347,
485,
409,
63,
10025,
8,
277,
12,
29669,
304,
267,
340,
291,
14,
19710,
26,
288,
892,
63,
10025,
275,
359,
9059,
63,
14528,
61,
288,
892,
63,
10025,
14,
2880,
8,
10025,
9,
288,
291,
14,
67,
1532,
14,
10025,
275,
892,
63,
10025,
267,
587,
26,
288,
291,
14,
67,
1532,
14,
10025,
275,
29669,
339,
29669,
275,
3324,
1547,
362,
63,
10025,
12,
485,
409,
63,
10025,
9,
339,
327,
4618,
514,
3324,
272,
347,
485,
362,
63,
9990,
8,
277,
304,
267,
372,
291,
14,
67,
1532,
14,
9990,
339,
347,
485,
409,
63,
9990,
8,
277,
12,
4618,
514,
304,
267,
291,
14,
67,
1532,
14,
9990,
275,
4618,
514,
339,
4618,
514,
275,
3324,
1547,
362,
63,
9990,
12,
485,
409,
63,
9990,
9,
339,
327,
2329,
1074,
3324,
272,
347,
485,
362,
63,
21205,
8,
277,
304,
267,
372,
291,
14,
67,
1532,
14,
21205,
339,
347,
485,
409,
63,
21205,
8,
277,
12,
2329,
1074,
304,
267,
291,
14,
67,
1532,
14,
21205,
275,
2329,
1074,
339,
2329,
1074,
275,
3324,
1547,
362,
63,
21205,
12,
485,
409,
63,
21205,
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
] |
[
5796,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
773,
12151,
492,
334,
272,
1868,
3876,
63,
14528,
12,
1125,
63,
72,
12,
634,
12151,
12,
4245,
63,
72,
12,
199,
9,
421,
199,
533,
11920,
2998,
5940,
8,
785,
304,
272,
408,
272,
2018,
909,
6144,
282,
11920,
1067,
2429,
14,
272,
408,
272,
347,
636,
826,
721,
277,
304,
267,
327,
6026,
9147,
314,
1067,
3016,
367,
642,
2462,
543,
267,
327,
314,
4245,
436,
1125,
3016,
14,
267,
291,
14,
4695,
275,
634,
12151,
14,
826,
14151,
63,
82,
8,
20556,
63,
72,
12,
1125,
63,
72,
9,
339,
347,
636,
2264,
721,
277,
304,
267,
340,
291,
14,
4695,
436,
634,
12151,
26,
288,
634,
12151,
14,
8192,
14151,
63,
82,
8,
277,
14,
4695,
9,
421,
199,
3,
1487,
2408,
316,
282,
2462,
13,
1832,
909,
436,
6425,
376,
1256,
199,
3,
370,
10266,
282,
3659,
370,
11920,
2998,
5940,
367,
642,
2462,
14,
199,
533,
11920,
2998,
8,
12562,
14,
1832,
304,
272,
2429,
275,
488,
199,
199,
2671,
63,
1100,
275,
11920,
2998,
342,
421,
199,
533,
11920,
7465,
8,
785,
304,
272,
408,
272,
8089,
626,
23739,
465,
282,
4975,
367,
11920,
445,
17471,
12,
436,
911,
272,
675,
2462,
13,
3489,
805,
21169,
1380,
2808,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2562,
63,
354,
304,
267,
862,
26,
288,
327,
11920,
2462,
13,
3489,
805,
17597,
1284,
543,
2513,
82,
297,
436,
288,
327,
5452,
376,
4722,
1067,
2429,
2725,
14,
288,
291,
14,
67,
1532,
275,
2519,
8,
76,
12151,
12,
2562,
63,
354,
435,
2513,
82,
358,
288,
291,
14,
19710,
275,
715,
288,
327,
2790,
282,
3659,
2348,
370,
2462,
63,
1100,
880,
652,
1159,
440,
288,
327,
17516,
13,
22766,
2544,
376,
7427,
370,
1240,
642,
909,
14,
288,
291,
14,
2671,
63,
1100,
275,
2462,
63,
1100,
267,
871,
4281,
26,
288,
327,
6630,
12,
675,
20195,
805,
14,
288,
291,
14,
67,
1532,
275,
2519,
8,
76,
12151,
12,
2562,
63,
354,
9,
288,
291,
14,
19710,
275,
756,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
267,
340,
291,
14,
19710,
26,
288,
327,
982,
282,
1067,
2429,
1630,
440,
2187,
367,
642,
2462,
12,
8265,
1373,
14,
288,
340,
440,
291,
14,
2671,
63,
1100,
14,
2479,
26,
355,
291,
14,
2671,
63,
1100,
14,
2479,
275,
11920,
2998,
5940,
342,
288,
327,
6523,
314,
25396,
11920,
12981,
543,
7849,
402,
314,
1067,
2429,
288,
327,
465,
314,
1642,
1423,
14,
288,
372,
291,
14,
67,
1532,
8,
277,
14,
2671,
63,
1100,
14,
2479,
14,
4695,
12,
627,
589,
9,
267,
587,
26,
288,
372,
291,
14,
67,
1532,
2031,
589,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
67,
1532,
855,
354,
363,
339,
327,
29669,
3324,
272,
347,
485,
362,
63,
10025,
8,
277,
304,
267,
372,
291,
14,
67,
1532,
14,
10025,
339,
347,
485,
409,
63,
10025,
8,
277,
12,
29669,
304,
267,
340,
291,
14,
19710,
26,
288,
892,
63,
10025,
275,
359,
9059,
63,
14528,
61,
288,
892,
63,
10025,
14,
2880,
8,
10025,
9,
288,
291,
14,
67,
1532,
14,
10025,
275,
892,
63,
10025,
267,
587,
26,
288,
291,
14,
67,
1532,
14,
10025,
275,
29669,
339,
29669,
275,
3324,
1547,
362,
63,
10025,
12,
485,
409,
63,
10025,
9,
339,
327,
4618,
514,
3324,
272,
347,
485,
362,
63,
9990,
8,
277,
304,
267,
372,
291,
14,
67,
1532,
14,
9990,
339,
347,
485,
409,
63,
9990,
8,
277,
12,
4618,
514,
304,
267,
291,
14,
67,
1532,
14,
9990,
275,
4618,
514,
339,
4618,
514,
275,
3324,
1547,
362,
63,
9990,
12,
485,
409,
63,
9990,
9,
339,
327,
2329,
1074,
3324,
272,
347,
485,
362,
63,
21205,
8,
277,
304,
267,
372,
291,
14,
67,
1532,
14,
21205,
339,
347,
485,
409,
63,
21205,
8,
277,
12,
2329,
1074,
304,
267,
291,
14,
67,
1532,
14,
21205,
275,
2329,
1074,
339,
2329,
1074,
275,
3324,
1547,
362,
63,
21205,
12,
485,
409,
63,
21205,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mzdaniel/oh-mainline
|
vendor/packages/django-model-utils/model_utils/tests/tests.py
|
2
|
18640
|
from __future__ import with_statement
import pickle, sys, warnings
from datetime import datetime, timedelta
import django
from django.test import TestCase
from django.db import models
from django.db.models.fields import FieldDoesNotExist
from django.core.exceptions import ImproperlyConfigured
from django.contrib.contenttypes.models import ContentType
from model_utils import Choices
from model_utils.fields import get_excerpt, MonitorField
from model_utils.managers import QueryManager, manager_from
from model_utils.models import StatusModel, TimeFramedModel
from model_utils.tests.models import (
InheritParent, InheritChild, InheritChild2, InheritanceManagerTestRelated,
InheritanceManagerTestParent, InheritanceManagerTestChild1,
InheritanceManagerTestChild2, TimeStamp, Post, Article, Status,
StatusPlainTuple, TimeFrame, Monitored, StatusManagerAdded,
TimeFrameManagerAdded, Entry, Dude, SplitFieldAbstractParent)
class GetExcerptTests(TestCase):
def test_split(self):
e = get_excerpt("some content\n\n<!-- split -->\n\nsome more")
self.assertEquals(e, 'some content\n')
def test_auto_split(self):
e = get_excerpt("para one\n\npara two\n\npara three")
self.assertEquals(e, 'para one\n\npara two')
def test_middle_of_para(self):
e = get_excerpt("some text\n<!-- split -->\nmore text")
self.assertEquals(e, 'some text')
def test_middle_of_line(self):
e = get_excerpt("some text <!-- split --> more text")
self.assertEquals(e, "some text <!-- split --> more text")
class SplitFieldTests(TestCase):
full_text = u'summary\n\n<!-- split -->\n\nmore'
excerpt = u'summary\n'
def setUp(self):
self.post = Article.objects.create(
title='example post', body=self.full_text)
def test_unicode_content(self):
self.assertEquals(unicode(self.post.body), self.full_text)
def test_excerpt(self):
self.assertEquals(self.post.body.excerpt, self.excerpt)
def test_content(self):
self.assertEquals(self.post.body.content, self.full_text)
def test_has_more(self):
self.failUnless(self.post.body.has_more)
def test_not_has_more(self):
post = Article.objects.create(title='example 2',
body='some text\n\nsome more\n')
self.failIf(post.body.has_more)
def test_load_back(self):
post = Article.objects.get(pk=self.post.pk)
self.assertEquals(post.body.content, self.post.body.content)
self.assertEquals(post.body.excerpt, self.post.body.excerpt)
def test_assign_to_body(self):
new_text = u'different\n\n<!-- split -->\n\nother'
self.post.body = new_text
self.post.save()
self.assertEquals(unicode(self.post.body), new_text)
def test_assign_to_content(self):
new_text = u'different\n\n<!-- split -->\n\nother'
self.post.body.content = new_text
self.post.save()
self.assertEquals(unicode(self.post.body), new_text)
def test_assign_to_excerpt(self):
def _invalid_assignment():
self.post.body.excerpt = 'this should fail'
self.assertRaises(AttributeError, _invalid_assignment)
def test_access_via_class(self):
def _invalid_access():
Article.body
self.assertRaises(AttributeError, _invalid_access)
def test_none(self):
a = Article(title='Some Title', body=None)
self.assertEquals(a.body, None)
def test_assign_splittext(self):
a = Article(title='Some Title')
a.body = self.post.body
self.assertEquals(a.body.excerpt, u'summary\n')
def test_value_to_string(self):
f = self.post._meta.get_field('body')
self.assertEquals(f.value_to_string(self.post), self.full_text)
def test_abstract_inheritance(self):
class Child(SplitFieldAbstractParent):
pass
self.assertEqual(
[f.name for f in Child._meta.fields],
["id", "content", "_content_excerpt"])
class MonitorFieldTests(TestCase):
def setUp(self):
self.instance = Monitored(name='Charlie')
self.created = self.instance.name_changed
def test_save_no_change(self):
self.instance.save()
self.assertEquals(self.instance.name_changed, self.created)
def test_save_changed(self):
self.instance.name = 'Maria'
self.instance.save()
self.failUnless(self.instance.name_changed > self.created)
def test_double_save(self):
self.instance.name = 'Jose'
self.instance.save()
changed = self.instance.name_changed
self.instance.save()
self.assertEquals(self.instance.name_changed, changed)
def test_no_monitor_arg(self):
self.assertRaises(TypeError, MonitorField)
class ChoicesTests(TestCase):
def setUp(self):
self.STATUS = Choices('DRAFT', 'PUBLISHED')
def test_getattr(self):
self.assertEquals(self.STATUS.DRAFT, 'DRAFT')
def test_indexing(self):
self.assertEquals(self.STATUS[1], ('PUBLISHED', 'PUBLISHED'))
def test_iteration(self):
self.assertEquals(tuple(self.STATUS), (('DRAFT', 'DRAFT'), ('PUBLISHED', 'PUBLISHED')))
def test_repr(self):
self.assertEquals(repr(self.STATUS),
"Choices("
"('DRAFT', 'DRAFT', 'DRAFT'), "
"('PUBLISHED', 'PUBLISHED', 'PUBLISHED'))")
def test_wrong_length_tuple(self):
self.assertRaises(ValueError, Choices, ('a',))
class LabelChoicesTests(ChoicesTests):
def setUp(self):
self.STATUS = Choices(
('DRAFT', 'is draft'),
('PUBLISHED', 'is published'),
'DELETED',
)
def test_iteration(self):
self.assertEquals(tuple(self.STATUS), (
('DRAFT', 'is draft'),
('PUBLISHED', 'is published'),
('DELETED', 'DELETED'))
)
def test_indexing(self):
self.assertEquals(self.STATUS[1], ('PUBLISHED', 'is published'))
def test_default(self):
self.assertEquals(self.STATUS.DELETED, 'DELETED')
def test_provided(self):
self.assertEquals(self.STATUS.DRAFT, 'DRAFT')
def test_repr(self):
self.assertEquals(repr(self.STATUS),
"Choices("
"('DRAFT', 'DRAFT', 'is draft'), "
"('PUBLISHED', 'PUBLISHED', 'is published'), "
"('DELETED', 'DELETED', 'DELETED'))")
class IdentifierChoicesTests(ChoicesTests):
def setUp(self):
self.STATUS = Choices(
(0, 'DRAFT', 'is draft'),
(1, 'PUBLISHED', 'is published'),
(2, 'DELETED', 'is deleted'))
def test_iteration(self):
self.assertEqual(tuple(self.STATUS), (
(0, 'is draft'),
(1, 'is published'),
(2, 'is deleted')))
def test_indexing(self):
self.assertEquals(self.STATUS[1], (1, 'is published'))
def test_getattr(self):
self.assertEquals(self.STATUS.DRAFT, 0)
def test_repr(self):
self.assertEquals(repr(self.STATUS),
"Choices("
"(0, 'DRAFT', 'is draft'), "
"(1, 'PUBLISHED', 'is published'), "
"(2, 'DELETED', 'is deleted'))")
class InheritanceCastModelTests(TestCase):
def setUp(self):
self.parent = InheritParent.objects.create()
self.child = InheritChild.objects.create()
def test_parent_real_type(self):
self.assertEquals(self.parent.real_type,
ContentType.objects.get_for_model(InheritParent))
def test_child_real_type(self):
self.assertEquals(self.child.real_type,
ContentType.objects.get_for_model(InheritChild))
def test_cast(self):
obj = InheritParent.objects.get(pk=self.child.pk).cast()
self.assertEquals(obj.__class__, InheritChild)
# @@@ Use proper test skipping once Django 1.2 is minimum supported version.
if sys.version_info >= (2, 6):
# @@@ catch_warnings only available in Python 2.6 and newer
def test_pending_deprecation(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
InheritParent()
self.assertEqual(len(w), 1)
assert issubclass(w[-1].category, PendingDeprecationWarning)
class InheritanceCastQuerysetTests(TestCase):
def setUp(self):
self.child = InheritChild.objects.create()
self.child2 = InheritChild2.objects.create()
def test_cast_manager(self):
self.assertEquals(set(InheritParent.objects.cast()),
set([self.child, self.child2]))
def test_cast(self):
parent = InheritParent.objects.create()
obj = InheritParent.objects.filter(pk=self.child.pk).cast()[0]
self.assertEquals(obj.__class__, InheritChild)
self.assertEquals(set(InheritChild2.objects.all().cast()),
set([self.child2]))
self.assertEquals(set(InheritParent.objects.all().cast()),
set([parent, self.child, self.child2]))
# @@@ Use proper test skipping once 1.2 is minimum supported version.
if django.VERSION >= (1, 2):
class InheritanceManagerTests(TestCase):
def setUp(self):
self.child1 = InheritanceManagerTestChild1.objects.create()
self.child2 = InheritanceManagerTestChild2.objects.create()
def get_manager(self):
return InheritanceManagerTestParent.objects
def test_normal(self):
self.assertEquals(set(self.get_manager().all()),
set([
InheritanceManagerTestParent(pk=self.child1.pk),
InheritanceManagerTestParent(pk=self.child2.pk),
]))
def test_select_all_subclasses(self):
self.assertEquals(
set(self.get_manager().select_subclasses()),
set([self.child1, self.child2]))
def test_select_specific_subclasses(self):
self.assertEquals(
set(self.get_manager().select_subclasses(
"inheritancemanagertestchild1")),
set([self.child1,
InheritanceManagerTestParent(pk=self.child2.pk)]))
class InheritanceManagerRelatedTests(InheritanceManagerTests):
def setUp(self):
self.related = InheritanceManagerTestRelated.objects.create()
self.child1 = InheritanceManagerTestChild1.objects.create(
related=self.related)
self.child2 = InheritanceManagerTestChild2.objects.create(
related=self.related)
def get_manager(self):
return self.related.imtests
class TimeStampedModelTests(TestCase):
def test_created(self):
t1 = TimeStamp.objects.create()
t2 = TimeStamp.objects.create()
self.assert_(t2.created > t1.created)
def test_modified(self):
t1 = TimeStamp.objects.create()
t2 = TimeStamp.objects.create()
t1.save()
self.assert_(t2.modified < t1.modified)
class TimeFramedModelTests(TestCase):
def setUp(self):
self.now = datetime.now()
def test_not_yet_begun(self):
TimeFrame.objects.create(start=self.now+timedelta(days=2))
self.assertEquals(TimeFrame.timeframed.count(), 0)
def test_finished(self):
TimeFrame.objects.create(end=self.now-timedelta(days=1))
self.assertEquals(TimeFrame.timeframed.count(), 0)
def test_no_end(self):
TimeFrame.objects.create(start=self.now-timedelta(days=10))
self.assertEquals(TimeFrame.timeframed.count(), 1)
def test_no_start(self):
TimeFrame.objects.create(end=self.now+timedelta(days=2))
self.assertEquals(TimeFrame.timeframed.count(), 1)
def test_within_range(self):
TimeFrame.objects.create(start=self.now-timedelta(days=1),
end=self.now+timedelta(days=1))
self.assertEquals(TimeFrame.timeframed.count(), 1)
class TimeFrameManagerAddedTests(TestCase):
def test_manager_available(self):
self.assert_(isinstance(TimeFrameManagerAdded.timeframed, QueryManager))
def test_conflict_error(self):
def _run():
class ErrorModel(TimeFramedModel):
timeframed = models.BooleanField()
self.assertRaises(ImproperlyConfigured, _run)
class StatusModelTests(TestCase):
def setUp(self):
self.model = Status
self.on_hold = Status.STATUS.on_hold
self.active = Status.STATUS.active
def test_created(self):
c1 = self.model.objects.create()
c2 = self.model.objects.create()
self.assert_(c2.status_changed > c1.status_changed)
self.assertEquals(self.model.active.count(), 2)
self.assertEquals(self.model.deleted.count(), 0)
def test_modification(self):
t1 = self.model.objects.create()
date_created = t1.status_changed
t1.status = self.on_hold
t1.save()
self.assertEquals(self.model.active.count(), 0)
self.assertEquals(self.model.on_hold.count(), 1)
self.assert_(t1.status_changed > date_created)
date_changed = t1.status_changed
t1.save()
self.assertEquals(t1.status_changed, date_changed)
date_active_again = t1.status_changed
t1.status = self.active
t1.save()
self.assert_(t1.status_changed > date_active_again)
class StatusModelPlainTupleTests(StatusModelTests):
def setUp(self):
self.model = StatusPlainTuple
self.on_hold = StatusPlainTuple.STATUS[2][0]
self.active = StatusPlainTuple.STATUS[0][0]
class StatusManagerAddedTests(TestCase):
def test_manager_available(self):
self.assert_(isinstance(StatusManagerAdded.active, QueryManager))
def test_conflict_error(self):
def _run():
class ErrorModel(StatusModel):
STATUS = (
('active', 'active'),
('deleted', 'deleted'),
)
active = models.BooleanField()
self.assertRaises(ImproperlyConfigured, _run)
class QueryManagerTests(TestCase):
def setUp(self):
data = ((True, True, 0),
(True, False, 4),
(False, False, 2),
(False, True, 3),
(True, True, 1),
(True, False, 5))
for p, c, o in data:
Post.objects.create(published=p, confirmed=c, order=o)
def test_passing_kwargs(self):
qs = Post.public.all()
self.assertEquals([p.order for p in qs], [0, 1, 4, 5])
def test_passing_Q(self):
qs = Post.public_confirmed.all()
self.assertEquals([p.order for p in qs], [0, 1])
def test_ordering(self):
qs = Post.public_reversed.all()
self.assertEquals([p.order for p in qs], [5, 4, 1, 0])
# @@@ Use proper test skipping once Django 1.2 is minimum supported version.
try:
from south.modelsinspector import introspector
except ImportError:
introspector = None
if introspector is not None:
class SouthFreezingTests(TestCase):
def test_introspector_adds_no_excerpt_field(self):
mf = Article._meta.get_field('body')
args, kwargs = introspector(mf)
self.assertEquals(kwargs['no_excerpt_field'], 'True')
def test_no_excerpt_field_works(self):
from models import NoRendered
self.assertRaises(FieldDoesNotExist,
NoRendered._meta.get_field,
'_body_excerpt')
class ManagerFromTests(TestCase):
def setUp(self):
Entry.objects.create(author='George', published=True)
Entry.objects.create(author='George', published=False)
Entry.objects.create(author='Paul', published=True, feature=True)
def test_chaining(self):
self.assertEqual(Entry.objects.by_author('George').published().count(),
1)
def test_function(self):
self.assertEqual(Entry.objects.unpublished().count(), 1)
def test_typecheck(self):
self.assertRaises(TypeError, manager_from, 'somestring')
def test_custom_get_query_set(self):
self.assertEqual(Entry.featured.published().count(), 1)
def test_cant_reconcile_qs_class(self):
self.assertRaises(TypeError, Entry.broken.all)
def test_queryset_pickling_fails(self):
qs = Entry.objects.all()
def dump_load():
pqs = pickle.dumps(qs)
pickle.loads(pqs)
self.assertRaises(pickle.PicklingError, dump_load)
# @@@ Use proper test skipping once Django 1.2 is minimum supported version.
if sys.version_info >= (2, 6):
# @@@ catch_warnings only available in Python 2.6 and newer
def test_pending_deprecation(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
manager_from()
self.assertEqual(len(w), 1)
assert issubclass(w[-1].category, PendingDeprecationWarning)
class PassThroughManagerTests(TestCase):
def setUp(self):
Dude.objects.create(name='The Dude', abides=True, has_rug=False)
Dude.objects.create(name='His Dudeness', abides=False, has_rug=True)
Dude.objects.create(name='Duder', abides=False, has_rug=False)
Dude.objects.create(name='El Duderino', abides=True, has_rug=True)
def test_chaining(self):
self.assertEqual(Dude.objects.by_name('Duder').count(), 1)
self.assertEqual(Dude.objects.all().by_name('Duder').count(), 1)
self.assertEqual(Dude.abiders.rug_positive().count(), 1)
self.assertEqual(Dude.abiders.all().rug_positive().count(), 1)
def test_manager_only_methods(self):
stats = Dude.abiders.get_stats()
self.assertEqual(stats['rug_count'], 1)
def notonqs():
Dude.abiders.all().get_stats()
self.assertRaises(AttributeError, notonqs)
def test_queryset_pickling(self):
qs = Dude.objects.all()
saltyqs = pickle.dumps(qs)
unqs = pickle.loads(saltyqs)
self.assertEqual(unqs.by_name('The Dude').count(), 1)
|
agpl-3.0
|
[
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
5927,
12,
984,
12,
3598,
199,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
646,
1639,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
29994,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
199,
504,
1402,
63,
1208,
492,
8802,
2370,
199,
504,
1402,
63,
1208,
14,
955,
492,
664,
63,
476,
2247,
541,
12,
26504,
792,
199,
504,
1402,
63,
1208,
14,
16259,
492,
8133,
2988,
12,
5256,
63,
504,
199,
504,
1402,
63,
1208,
14,
992,
492,
9795,
1685,
12,
4703,
3160,
68,
1685,
199,
504,
1402,
63,
1208,
14,
2219,
14,
992,
492,
334,
272,
27502,
6652,
12,
27502,
3493,
12,
27502,
3493,
18,
12,
27502,
554,
2988,
774,
13885,
12,
272,
27502,
554,
2988,
774,
6652,
12,
27502,
554,
2988,
774,
3493,
17,
12,
272,
27502,
554,
2988,
774,
3493,
18,
12,
4703,
16649,
12,
7711,
12,
8281,
12,
9795,
12,
272,
9795,
20711,
7075,
12,
4703,
3160,
12,
10953,
17043,
12,
9795,
2988,
20201,
12,
272,
4703,
3160,
2988,
20201,
12,
11855,
12,
577,
3786,
12,
11740,
792,
8458,
6652,
9,
4388,
199,
533,
2372,
920,
2247,
541,
2925,
8,
1746,
304,
272,
347,
511,
63,
1294,
8,
277,
304,
267,
325,
275,
664,
63,
476,
2247,
541,
480,
3972,
1564,
60,
78,
60,
78,
25273,
3715,
1553,
3072,
78,
60,
561,
1377,
1655,
531,
267,
291,
14,
2947,
8,
69,
12,
283,
3972,
1564,
60,
78,
358,
2378,
347,
511,
63,
2495,
63,
1294,
8,
277,
304,
267,
325,
275,
664,
63,
476,
2247,
541,
480,
12227,
1373,
60,
78,
60,
78,
12227,
2877,
60,
78,
60,
78,
12227,
7795,
531,
267,
291,
14,
2947,
8,
69,
12,
283,
12227,
1373,
60,
78,
60,
78,
12227,
2877,
358,
2378,
347,
511,
63,
14885,
63,
1618,
63,
12227,
8,
277,
304,
267,
325,
275,
664,
63,
476,
2247,
541,
480,
3972,
1318,
60,
78,
25273,
3715,
1553,
3072,
78,
6878,
1318,
531,
267,
291,
14,
2947,
8,
69,
12,
283,
3972,
1318,
358,
2378,
347,
511,
63,
14885,
63,
1618,
63,
604,
8,
277,
304,
267,
325,
275,
664,
63,
476,
2247,
541,
480,
3972,
1318,
28253,
3715,
10541,
1655,
1318,
531,
267,
291,
14,
2947,
8,
69,
12,
298,
3972,
1318,
28253,
3715,
10541,
1655,
1318,
531,
4388,
199,
533,
11740,
792,
2925,
8,
1746,
304,
272,
2615,
63,
505,
275,
399,
1159,
29309,
60,
78,
60,
78,
25273,
3715,
1553,
3072,
78,
60,
78,
6878,
7,
272,
444,
2247,
541,
275,
399,
1159,
29309,
60,
78,
7,
2378,
347,
3613,
8,
277,
304,
267,
291,
14,
1932,
275,
8281,
14,
1462,
14,
981,
8,
288,
2538,
534,
2694,
2963,
297,
2396,
29,
277,
14,
2861,
63,
505,
9,
2378,
347,
511,
63,
2975,
63,
1317,
8,
277,
304,
267,
291,
14,
2947,
8,
2975,
8,
277,
14,
1932,
14,
2030,
395,
291,
14,
2861,
63,
505,
9,
2378,
347,
511,
63,
476,
2247,
541,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
1932,
14,
2030,
14,
476,
2247,
541,
12,
291,
14,
476,
2247,
541,
9,
2378,
347,
511,
63,
1317,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
1932,
14,
2030,
14,
1317,
12,
291,
14,
2861,
63,
505,
9,
2378,
347,
511,
63,
1989,
63,
6878,
8,
277,
304,
267,
291,
14,
7589,
8,
277,
14,
1932,
14,
2030,
14,
1989,
63,
6878,
9,
2378,
347,
511,
63,
1397,
63,
1989,
63,
6878,
8,
277,
304,
267,
2963,
275,
8281,
14,
1462,
14,
981,
8,
1213,
534,
2694,
499,
297,
4228,
2396,
534,
3972,
1318,
60,
78,
60,
561,
1377,
1655,
60,
78,
358,
267,
291,
14,
19670,
8,
1932,
14,
2030,
14,
1989,
63,
6878,
9,
2378,
347,
511,
63,
912,
63,
894,
8,
277,
304,
267,
2963,
275,
8281,
14,
1462,
14,
362,
8,
2051,
29,
277,
14,
1932,
14,
2051,
9,
267,
291,
14,
2947,
8,
1932,
14,
2030,
14,
1317,
12,
291,
14,
1932,
14,
2030,
14,
1317,
9,
267,
291,
14,
2947,
8,
1932,
14,
2030,
14,
476,
2247,
541,
12,
291,
14,
1932,
14,
2030,
14,
476,
2247,
541,
9,
2378,
347,
511,
63,
5038,
63,
475,
63,
2030,
8,
277,
304,
267,
892,
63,
505,
275,
399,
5121,
73,
2026,
640,
60,
78,
60,
78,
25273,
3715,
1553,
3072,
78,
60,
15336,
7,
267,
291,
14,
1932,
14,
2030,
275,
892,
63,
505,
267,
291,
14,
1932,
14,
2117,
342,
267,
291,
14,
2947,
8,
2975,
8,
277,
14,
1932,
14,
2030,
395,
892,
63,
505,
9,
2378,
347,
511,
63,
5038,
63,
475,
63,
1317,
8,
277,
304,
267,
892,
63,
505,
275,
399,
5121,
73,
2026,
640,
60,
78,
60,
78,
25273,
3715,
1553,
3072,
78,
60,
15336,
7,
267,
291,
14,
1932,
14,
2030,
14,
1317,
275,
892,
63,
505,
267,
291,
14,
1932,
14,
2117,
342,
267,
291,
14,
2947,
8,
2975,
8,
277,
14,
1932,
14,
2030,
395,
892,
63,
505,
9,
2378,
347,
511,
63,
5038,
63,
475,
63,
476,
2247,
541,
8,
277,
304,
267,
347,
485,
3197,
63,
10861,
837,
288,
291,
14,
1932,
14,
2030,
14,
476,
2247,
541,
275,
283,
3749,
1077,
2449,
7,
267,
291,
14,
1855,
8,
10227,
12,
485,
3197,
63,
10861,
9,
2378,
347,
511,
63,
2732,
63,
12897,
63,
533,
8,
277,
304,
267,
347,
485,
3197,
63,
2732,
837,
288,
8281,
14,
2030,
267,
291,
14,
1855,
8,
10227,
12,
485,
3197,
63,
2732,
9,
2378,
347,
511,
63,
3592,
8,
277,
304,
267,
282,
275,
8281,
8,
1213,
534,
7700,
16881,
297,
2396,
29,
403,
9,
267,
291,
14,
2947,
8,
65,
14,
2030,
12,
488,
9,
2378,
347,
511,
63,
5038,
63,
1294,
505,
8,
277,
304,
267,
282,
275,
8281,
8,
1213,
534,
7700,
16881,
358,
267,
282,
14,
2030,
275,
291,
14,
1932,
14,
2030,
267,
291,
14,
2947,
8,
65,
14,
2030,
14,
476,
2247,
541,
12,
399,
1159,
29309,
60
] |
[
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
5927,
12,
984,
12,
3598,
199,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
646,
1639,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
29994,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
199,
504,
1402,
63,
1208,
492,
8802,
2370,
199,
504,
1402,
63,
1208,
14,
955,
492,
664,
63,
476,
2247,
541,
12,
26504,
792,
199,
504,
1402,
63,
1208,
14,
16259,
492,
8133,
2988,
12,
5256,
63,
504,
199,
504,
1402,
63,
1208,
14,
992,
492,
9795,
1685,
12,
4703,
3160,
68,
1685,
199,
504,
1402,
63,
1208,
14,
2219,
14,
992,
492,
334,
272,
27502,
6652,
12,
27502,
3493,
12,
27502,
3493,
18,
12,
27502,
554,
2988,
774,
13885,
12,
272,
27502,
554,
2988,
774,
6652,
12,
27502,
554,
2988,
774,
3493,
17,
12,
272,
27502,
554,
2988,
774,
3493,
18,
12,
4703,
16649,
12,
7711,
12,
8281,
12,
9795,
12,
272,
9795,
20711,
7075,
12,
4703,
3160,
12,
10953,
17043,
12,
9795,
2988,
20201,
12,
272,
4703,
3160,
2988,
20201,
12,
11855,
12,
577,
3786,
12,
11740,
792,
8458,
6652,
9,
4388,
199,
533,
2372,
920,
2247,
541,
2925,
8,
1746,
304,
272,
347,
511,
63,
1294,
8,
277,
304,
267,
325,
275,
664,
63,
476,
2247,
541,
480,
3972,
1564,
60,
78,
60,
78,
25273,
3715,
1553,
3072,
78,
60,
561,
1377,
1655,
531,
267,
291,
14,
2947,
8,
69,
12,
283,
3972,
1564,
60,
78,
358,
2378,
347,
511,
63,
2495,
63,
1294,
8,
277,
304,
267,
325,
275,
664,
63,
476,
2247,
541,
480,
12227,
1373,
60,
78,
60,
78,
12227,
2877,
60,
78,
60,
78,
12227,
7795,
531,
267,
291,
14,
2947,
8,
69,
12,
283,
12227,
1373,
60,
78,
60,
78,
12227,
2877,
358,
2378,
347,
511,
63,
14885,
63,
1618,
63,
12227,
8,
277,
304,
267,
325,
275,
664,
63,
476,
2247,
541,
480,
3972,
1318,
60,
78,
25273,
3715,
1553,
3072,
78,
6878,
1318,
531,
267,
291,
14,
2947,
8,
69,
12,
283,
3972,
1318,
358,
2378,
347,
511,
63,
14885,
63,
1618,
63,
604,
8,
277,
304,
267,
325,
275,
664,
63,
476,
2247,
541,
480,
3972,
1318,
28253,
3715,
10541,
1655,
1318,
531,
267,
291,
14,
2947,
8,
69,
12,
298,
3972,
1318,
28253,
3715,
10541,
1655,
1318,
531,
4388,
199,
533,
11740,
792,
2925,
8,
1746,
304,
272,
2615,
63,
505,
275,
399,
1159,
29309,
60,
78,
60,
78,
25273,
3715,
1553,
3072,
78,
60,
78,
6878,
7,
272,
444,
2247,
541,
275,
399,
1159,
29309,
60,
78,
7,
2378,
347,
3613,
8,
277,
304,
267,
291,
14,
1932,
275,
8281,
14,
1462,
14,
981,
8,
288,
2538,
534,
2694,
2963,
297,
2396,
29,
277,
14,
2861,
63,
505,
9,
2378,
347,
511,
63,
2975,
63,
1317,
8,
277,
304,
267,
291,
14,
2947,
8,
2975,
8,
277,
14,
1932,
14,
2030,
395,
291,
14,
2861,
63,
505,
9,
2378,
347,
511,
63,
476,
2247,
541,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
1932,
14,
2030,
14,
476,
2247,
541,
12,
291,
14,
476,
2247,
541,
9,
2378,
347,
511,
63,
1317,
8,
277,
304,
267,
291,
14,
2947,
8,
277,
14,
1932,
14,
2030,
14,
1317,
12,
291,
14,
2861,
63,
505,
9,
2378,
347,
511,
63,
1989,
63,
6878,
8,
277,
304,
267,
291,
14,
7589,
8,
277,
14,
1932,
14,
2030,
14,
1989,
63,
6878,
9,
2378,
347,
511,
63,
1397,
63,
1989,
63,
6878,
8,
277,
304,
267,
2963,
275,
8281,
14,
1462,
14,
981,
8,
1213,
534,
2694,
499,
297,
4228,
2396,
534,
3972,
1318,
60,
78,
60,
561,
1377,
1655,
60,
78,
358,
267,
291,
14,
19670,
8,
1932,
14,
2030,
14,
1989,
63,
6878,
9,
2378,
347,
511,
63,
912,
63,
894,
8,
277,
304,
267,
2963,
275,
8281,
14,
1462,
14,
362,
8,
2051,
29,
277,
14,
1932,
14,
2051,
9,
267,
291,
14,
2947,
8,
1932,
14,
2030,
14,
1317,
12,
291,
14,
1932,
14,
2030,
14,
1317,
9,
267,
291,
14,
2947,
8,
1932,
14,
2030,
14,
476,
2247,
541,
12,
291,
14,
1932,
14,
2030,
14,
476,
2247,
541,
9,
2378,
347,
511,
63,
5038,
63,
475,
63,
2030,
8,
277,
304,
267,
892,
63,
505,
275,
399,
5121,
73,
2026,
640,
60,
78,
60,
78,
25273,
3715,
1553,
3072,
78,
60,
15336,
7,
267,
291,
14,
1932,
14,
2030,
275,
892,
63,
505,
267,
291,
14,
1932,
14,
2117,
342,
267,
291,
14,
2947,
8,
2975,
8,
277,
14,
1932,
14,
2030,
395,
892,
63,
505,
9,
2378,
347,
511,
63,
5038,
63,
475,
63,
1317,
8,
277,
304,
267,
892,
63,
505,
275,
399,
5121,
73,
2026,
640,
60,
78,
60,
78,
25273,
3715,
1553,
3072,
78,
60,
15336,
7,
267,
291,
14,
1932,
14,
2030,
14,
1317,
275,
892,
63,
505,
267,
291,
14,
1932,
14,
2117,
342,
267,
291,
14,
2947,
8,
2975,
8,
277,
14,
1932,
14,
2030,
395,
892,
63,
505,
9,
2378,
347,
511,
63,
5038,
63,
475,
63,
476,
2247,
541,
8,
277,
304,
267,
347,
485,
3197,
63,
10861,
837,
288,
291,
14,
1932,
14,
2030,
14,
476,
2247,
541,
275,
283,
3749,
1077,
2449,
7,
267,
291,
14,
1855,
8,
10227,
12,
485,
3197,
63,
10861,
9,
2378,
347,
511,
63,
2732,
63,
12897,
63,
533,
8,
277,
304,
267,
347,
485,
3197,
63,
2732,
837,
288,
8281,
14,
2030,
267,
291,
14,
1855,
8,
10227,
12,
485,
3197,
63,
2732,
9,
2378,
347,
511,
63,
3592,
8,
277,
304,
267,
282,
275,
8281,
8,
1213,
534,
7700,
16881,
297,
2396,
29,
403,
9,
267,
291,
14,
2947,
8,
65,
14,
2030,
12,
488,
9,
2378,
347,
511,
63,
5038,
63,
1294,
505,
8,
277,
304,
267,
282,
275,
8281,
8,
1213,
534,
7700,
16881,
358,
267,
282,
14,
2030,
275,
291,
14,
1932,
14,
2030,
267,
291,
14,
2947,
8,
65,
14,
2030,
14,
476,
2247,
541,
12,
399,
1159,
29309,
60,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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1577
|
"""
The MIT License (MIT)
Copyright (c) 2016 Luca Ucciero
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
import requests
from bs4 import BeautifulSoup
url = 'https://ukpirate.click/top/all'
response = requests.get(url)
bersaglio = response.text
soup = BeautifulSoup(bersaglio)
links = soup.find_all('a', class_="detLink")
file = open("/your/path/to/the/directory/tpb_generator/data/top_all_five.txt", "w") #change with your path to the directory "tpb_generator"
for link in links[0:5]:
titoli = link.contents[0]
print >>file, titoli
print "operation completed"
file.close()
|
mit
|
[
624,
199,
1918,
10697,
844,
334,
13965,
9,
199,
7384,
334,
67,
9,
7800,
491,
8667,
738,
67,
559,
3478,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
624,
4388,
199,
646,
4145,
199,
504,
9922,
20,
492,
17132,
421,
199,
633,
275,
283,
2859,
921,
3210,
80,
723,
323,
14,
4891,
15,
2119,
15,
452,
7,
199,
1310,
275,
4145,
14,
362,
8,
633,
9,
199,
605,
83,
643,
14437,
275,
1177,
14,
505,
199,
9317,
275,
17132,
8,
605,
83,
643,
14437,
9,
199,
199,
4614,
275,
9108,
14,
1623,
63,
452,
360,
65,
297,
1021,
63,
628,
9886,
3834,
531,
199,
199,
493,
275,
1551,
4769,
12695,
15,
515,
15,
475,
15,
1589,
15,
3619,
15,
683,
66,
63,
4679,
15,
576,
15,
2119,
63,
452,
63,
23702,
14,
2424,
401,
298,
87,
531,
327,
1461,
543,
2195,
931,
370,
314,
2082,
298,
683,
66,
63,
4679,
2,
421,
199,
509,
2142,
315,
6220,
59,
16,
26,
21,
2189,
272,
3367,
475,
317,
275,
2142,
14,
4407,
59,
16,
61,
272,
870,
4331,
493,
12,
3367,
475,
317,
199,
199,
1361,
298,
5735,
9709,
2,
4388,
199,
493,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1918,
10697,
844,
334,
13965,
9,
199,
7384,
334,
67,
9,
7800,
491,
8667,
738,
67,
559,
3478,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
624,
4388,
199,
646,
4145,
199,
504,
9922,
20,
492,
17132,
421,
199,
633,
275,
283,
2859,
921,
3210,
80,
723,
323,
14,
4891,
15,
2119,
15,
452,
7,
199,
1310,
275,
4145,
14,
362,
8,
633,
9,
199,
605,
83,
643,
14437,
275,
1177,
14,
505,
199,
9317,
275,
17132,
8,
605,
83,
643,
14437,
9,
199,
199,
4614,
275,
9108,
14,
1623,
63,
452,
360,
65,
297,
1021,
63,
628,
9886,
3834,
531,
199,
199,
493,
275,
1551,
4769,
12695,
15,
515,
15,
475,
15,
1589,
15,
3619,
15,
683,
66,
63,
4679,
15,
576,
15,
2119,
63,
452,
63,
23702,
14,
2424,
401,
298,
87,
531,
327,
1461,
543,
2195,
931,
370,
314,
2082,
298,
683,
66,
63,
4679,
2,
421,
199,
509,
2142,
315,
6220,
59,
16,
26,
21,
2189,
272,
3367,
475,
317,
275,
2142,
14,
4407,
59,
16,
61,
272,
870,
4331,
493,
12,
3367,
475,
317,
199,
199,
1361,
298,
5735,
9709,
2,
4388,
199,
493,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
Konubinix/weboob
|
weboob/tools/date.py
|
1
|
13543
|
# -*- coding: utf-8 -*-
# Copyright(C) 2010-2013 Romain Bignon
#
# This file is part of weboob.
#
# weboob 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.
#
# weboob 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 weboob. If not, see <http://www.gnu.org/licenses/>.
import dateutil.parser
from datetime import date as real_date, datetime as real_datetime, timedelta
import time
import re
try:
from dateutil import tz
except ImportError:
raise ImportError('Please install python-dateutil')
__all__ = ['local2utc', 'utc2local', 'LinearDateGuesser', 'date', 'datetime', 'new_date', 'new_datetime', 'closest_date']
def local2utc(dateobj):
dateobj = dateobj.replace(tzinfo=tz.tzlocal())
dateobj = dateobj.astimezone(tz.tzutc())
return dateobj
def utc2local(dateobj):
dateobj = dateobj.replace(tzinfo=tz.tzutc())
dateobj = dateobj.astimezone(tz.tzlocal())
return dateobj
class date(real_date):
def strftime(self, fmt):
return strftime(self, fmt)
@classmethod
def from_date(cls, d):
return cls(d.year, d.month, d.day)
class datetime(real_datetime):
def strftime(self, fmt):
return strftime(self, fmt)
def combine(self, date, time):
return datetime(date.year, date.month, date.day, time.hour, time.minute, time.microsecond, time.tzinfo)
def date(self):
return date(self.year, self.month, self.day)
@classmethod
def from_datetime(cls, dt):
return cls(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo)
def new_date(d):
""" Generate a safe date from a datetime.date object """
return date(d.year, d.month, d.day)
def new_datetime(d):
"""
Generate a safe datetime from a datetime.date or datetime.datetime object
"""
kw = [d.year, d.month, d.day]
if isinstance(d, real_datetime):
kw.extend([d.hour, d.minute, d.second, d.microsecond, d.tzinfo])
return datetime(*kw)
# No support for strftime's "%s" or "%y".
# Allowed if there's an even number of "%"s because they are escaped.
_illegal_formatting = re.compile(r"((^|[^%])(%%)*%[sy])")
def _findall(text, substr):
# Also finds overlaps
sites = []
i = 0
while True:
j = text.find(substr, i)
if j == -1:
break
sites.append(j)
i = j+1
return sites
def strftime(dt, fmt):
if dt.year >= 1900:
return super(type(dt), dt).strftime(fmt)
illegal_formatting = _illegal_formatting.search(fmt)
if illegal_formatting:
raise TypeError("strftime of dates before 1900 does not handle" + illegal_formatting.group(0))
year = dt.year
# For every non-leap year century, advance by
# 6 years to get into the 28-year repeat cycle
delta = 2000 - year
off = 6*(delta // 100 + delta // 400)
year = year + off
# Move to around the year 2000
year = year + ((2000 - year)//28)*28
timetuple = dt.timetuple()
s1 = time.strftime(fmt, (year,) + timetuple[1:])
sites1 = _findall(s1, str(year))
s2 = time.strftime(fmt, (year+28,) + timetuple[1:])
sites2 = _findall(s2, str(year+28))
sites = []
for site in sites1:
if site in sites2:
sites.append(site)
s = s1
syear = "%4d" % (dt.year,)
for site in sites:
s = s[:site] + syear + s[site+4:]
return s
class LinearDateGuesser(object):
"""
The aim of this class is to guess the exact date object from
a day and a month, but not a year.
It works with a start date (default is today), and all dates must be
sorted from recent to older.
"""
def __init__(self, current_date=None, date_max_bump=timedelta(7)):
self.date_max_bump = date_max_bump
if current_date is None:
current_date = date.today()
self.current_date = current_date
def try_assigning_year(self, day, month, start_year, max_year):
"""
Tries to create a date object with day, month and start_year and returns
it.
If it fails due to the year not matching the day+month combination
(i.e. due to a ValueError -- TypeError and OverflowError are not
handled), the previous or next years are tried until max_year is
reached.
In case initialization still fails with max_year, this function raises
a ValueError.
"""
while True:
try:
return date(start_year, month, day)
except ValueError as e:
if start_year == max_year:
raise e
start_year += cmp(max_year, start_year)
def set_current_date(self, current_date):
self.current_date = current_date
def guess_date(self, day, month, change_current_date=True):
""" Returns a date object built from a given day/month pair. """
today = self.current_date
# The website only provides dates using the 'DD/MM' string, so we have to
# determine the most possible year by ourselves. This implies tracking
# the current date.
# However, we may also encounter "bumps" in the dates, e.g. "12/11,
# 10/11, 10/11, 12/11, 09/11", so we have to be, well, quite tolerant,
# by accepting dates in the near future (say, 7 days) of the current
# date. (Please, kill me...)
# We first try to keep the current year
naively_parsed_date = self.try_assigning_year(day, month, today.year, today.year - 5)
if (naively_parsed_date.year != today.year):
# we most likely hit a 29/02 leading to a change of year
if change_current_date:
self.set_current_date(naively_parsed_date)
return naively_parsed_date
if (naively_parsed_date > today + self.date_max_bump):
# if the date ends up too far in the future, consider it actually
# belongs to the previous year
parsed_date = date(today.year - 1, month, day)
if change_current_date:
self.set_current_date(parsed_date)
elif (naively_parsed_date > today and naively_parsed_date <= today + self.date_max_bump):
# if the date is in the near future, consider it is a bump
parsed_date = naively_parsed_date
# do not keep it as current date though
else:
# if the date is in the past, as expected, simply keep it
parsed_date = naively_parsed_date
# and make it the new current date
if change_current_date:
self.set_current_date(parsed_date)
return parsed_date
class ChaoticDateGuesser(LinearDateGuesser):
"""
This class aim to find the guess the date when you know the
day and month and the minimum year
"""
def __init__(self, min_date, current_date=None, date_max_bump=timedelta(7)):
if min_date is None:
raise ValueError("min_date is not set")
self.min_date = min_date
super(ChaoticDateGuesser, self).__init__(current_date, date_max_bump)
def guess_date(self, day, month):
"""Returns a possible date between min_date and current_date"""
parsed_date = super(ChaoticDateGuesser, self).guess_date(day, month, False)
if parsed_date >= self.min_date:
return parsed_date
else:
raise ValueError("%s is inferior to min_date %s" % (parsed_date, self.min_date))
DATE_TRANSLATE_FR = [(re.compile(ur'janvier', re.I), ur'january'),
(re.compile(ur'février', re.I), ur'february'),
(re.compile(ur'mars', re.I), ur'march'),
(re.compile(ur'avril', re.I), ur'april'),
(re.compile(ur'mai', re.I), ur'may'),
(re.compile(ur'juin', re.I), ur'june'),
(re.compile(ur'juillet', re.I), ur'july'),
(re.compile(ur'août?', re.I), ur'august'),
(re.compile(ur'septembre', re.I), ur'september'),
(re.compile(ur'octobre', re.I), ur'october'),
(re.compile(ur'novembre', re.I), ur'november'),
(re.compile(ur'décembre', re.I), ur'december'),
(re.compile(ur'jan\.', re.I), ur'january'),
(re.compile(ur'\bjan\b', re.I), ur'january'),
(re.compile(ur'fév\.', re.I), ur'february'),
(re.compile(ur'\bfév\b', re.I), ur'february'),
(re.compile(ur'avr\.', re.I), ur'april'),
(re.compile(ur'\bavr\b', re.I), ur'april'),
(re.compile(ur'juil\.', re.I), ur'july'),
(re.compile(ur'juill\.', re.I), ur'july'),
(re.compile(ur'\bjuil\b', re.I), ur'july'),
(re.compile(ur'sep\.', re.I), ur'september'),
(re.compile(ur'sept\.', re.I), ur'september'),
(re.compile(ur'\bsep\b', re.I), ur'september'),
(re.compile(ur'oct\.', re.I), ur'october'),
(re.compile(ur'\boct\b', re.I), ur'october'),
(re.compile(ur'nov\.', re.I), ur'november'),
(re.compile(ur'\bnov\b', re.I), ur'november'),
(re.compile(ur'déc\.', re.I), ur'december'),
(re.compile(ur'\bdéc\b', re.I), ur'december'),
(re.compile(ur'lundi', re.I), ur'monday'),
(re.compile(ur'mardi', re.I), ur'tuesday'),
(re.compile(ur'mercredi', re.I), ur'wednesday'),
(re.compile(ur'jeudi', re.I), ur'thursday'),
(re.compile(ur'vendredi', re.I), ur'friday'),
(re.compile(ur'samedi', re.I), ur'saturday'),
(re.compile(ur'dimanche', re.I), ur'sunday')]
def parse_french_date(date):
for fr, en in DATE_TRANSLATE_FR:
date = fr.sub(en, date)
return dateutil.parser.parse(date)
WEEK = {'MONDAY': 0,
'TUESDAY': 1,
'WEDNESDAY': 2,
'THURSDAY': 3,
'FRIDAY': 4,
'SATURDAY': 5,
'SUNDAY': 6,
'LUNDI': 0,
'MARDI': 1,
'MERCREDI': 2,
'JEUDI': 3,
'VENDREDI': 4,
'SAMEDI': 5,
'DIMANCHE': 6,
}
def get_date_from_day(day):
today = date.today()
today_day_number = today.weekday()
requested_day_number = WEEK[day.upper()]
if today_day_number < requested_day_number:
day_to_go = requested_day_number - today_day_number
else:
day_to_go = 7 - today_day_number + requested_day_number
requested_date = today + timedelta(day_to_go)
return date(requested_date.year, requested_date.month, requested_date.day)
def parse_date(string):
matches = re.search('\s*([012]?[0-9]|3[01])\s*/\s*(0?[1-9]|1[012])\s*/?(\d{2}|\d{4})?$', string)
if matches:
year = matches.group(3)
if not year:
year = date.today().year
elif len(year) == 2:
year = 2000 + int(year)
return date(int(year), int(matches.group(2)), int(matches.group(1)))
elif string.upper() in WEEK.keys():
return get_date_from_day(string)
elif string.upper() == "TODAY":
return date.today()
def closest_date(date, date_from, date_to):
"""
Adjusts year so that the date is closest to the given range.
Transactions dates in a statement usually contain only day and month.
Statement dates range have a year though.
Merge them all together to get a full transaction date.
"""
# If the date is within given range, we're done.
if date_from <= date <= date_to:
return date
dates = [real_datetime(year, date.month, date.day)
for year in xrange(date_from.year, date_to.year+1)]
# Ideally, pick the date within given range.
for d in dates:
if date_from <= d <= date_to:
return d
# Otherwise, return the most recent date in the past.
return min(dates, key=lambda d: abs(d-date_from))
def test():
dt = real_datetime
range1 = [dt(2012,12,20), dt(2013,1,10)]
assert closest_date(dt(2012,12,15), *range1) == dt(2012,12,15)
assert closest_date(dt(2000,12,15), *range1) == dt(2012,12,15)
assert closest_date(dt(2020,12,15), *range1) == dt(2012,12,15)
assert closest_date(dt(2013,1,15), *range1) == dt(2013,1,15)
assert closest_date(dt(2000,1,15), *range1) == dt(2013,1,15)
assert closest_date(dt(2020,1,15), *range1) == dt(2013,1,15)
assert closest_date(dt(2013,1,1), *range1) == dt(2013,1,1)
assert closest_date(dt(2000,1,1), *range1) == dt(2013,1,1)
assert closest_date(dt(2020,1,1), *range1) == dt(2013,1,1)
range2 = [dt(2012,12,20), dt(2014,1,10)]
assert closest_date(dt(2012,12,15), *range2) == dt(2013,12,15)
assert closest_date(dt(2014,1,15), *range2) == dt(2013,1,15)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
8,
35,
9,
7129,
13,
6965,
6848,
973,
699,
1030,
265,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
29896,
14,
199,
3,
199,
3,
29896,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
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,
29896,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
29896,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
22208,
14,
2087,
199,
504,
2197,
492,
1434,
465,
3363,
63,
602,
12,
2197,
465,
3363,
63,
2083,
12,
6871,
199,
646,
900,
199,
646,
295,
199,
893,
26,
272,
687,
22208,
492,
5823,
199,
2590,
3545,
26,
272,
746,
3545,
360,
8254,
3907,
2366,
13,
602,
1974,
358,
421,
199,
363,
452,
363,
275,
788,
1832,
18,
5834,
297,
283,
5834,
18,
1832,
297,
283,
10608,
2506,
39,
10138,
332,
297,
283,
602,
297,
283,
2083,
297,
283,
1222,
63,
602,
297,
283,
1222,
63,
2083,
297,
283,
22061,
63,
602,
418,
421,
199,
318,
2257,
18,
5834,
8,
602,
1113,
304,
272,
1434,
1113,
275,
1434,
1113,
14,
1814,
8,
9374,
29,
3903,
14,
3903,
1832,
1012,
272,
1434,
1113,
275,
1434,
1113,
14,
29648,
8,
3903,
14,
3903,
5834,
1012,
272,
372,
1434,
1113,
421,
199,
318,
19314,
18,
1832,
8,
602,
1113,
304,
272,
1434,
1113,
275,
1434,
1113,
14,
1814,
8,
9374,
29,
3903,
14,
3903,
5834,
1012,
272,
1434,
1113,
275,
1434,
1113,
14,
29648,
8,
3903,
14,
3903,
1832,
1012,
272,
372,
1434,
1113,
421,
199,
533,
1434,
8,
3093,
63,
602,
304,
272,
347,
14053,
8,
277,
12,
7104,
304,
267,
372,
14053,
8,
277,
12,
7104,
9,
339,
768,
3744,
272,
347,
687,
63,
602,
8,
1886,
12,
366,
304,
267,
372,
843,
8,
68,
14,
3403,
12,
366,
14,
4482,
12,
366,
14,
2977,
9,
421,
199,
533,
2197,
8,
3093,
63,
2083,
304,
272,
347,
14053,
8,
277,
12,
7104,
304,
267,
372,
14053,
8,
277,
12,
7104,
9,
339,
347,
13323,
8,
277,
12,
1434,
12,
900,
304,
267,
372,
2197,
8,
602,
14,
3403,
12,
1434,
14,
4482,
12,
1434,
14,
2977,
12,
900,
14,
5180,
12,
900,
14,
10698,
12,
900,
14,
16627,
12,
900,
14,
9374,
9,
339,
347,
1434,
8,
277,
304,
267,
372,
1434,
8,
277,
14,
3403,
12,
291,
14,
4482,
12,
291,
14,
2977,
9,
339,
768,
3744,
272,
347,
687,
63,
2083,
8,
1886,
12,
4487,
304,
267,
372,
843,
8,
3583,
14,
3403,
12,
4487,
14,
4482,
12,
4487,
14,
2977,
12,
4487,
14,
5180,
12,
4487,
14,
10698,
12,
4487,
14,
4375,
12,
4487,
14,
16627,
12,
4487,
14,
9374,
9,
421,
199,
318,
892,
63,
602,
8,
68,
304,
272,
408,
7958,
282,
5048,
1434,
687,
282,
2197,
14,
602,
909,
408,
272,
372,
1434,
8,
68,
14,
3403,
12,
366,
14,
4482,
12,
366,
14,
2977,
9,
421,
199,
318,
892,
63,
2083,
8,
68,
304,
272,
408,
272,
7958,
282,
5048,
2197,
687,
282,
2197,
14,
602,
503,
2197,
14,
2083,
909,
272,
408,
272,
4775,
275,
359,
68,
14,
3403,
12,
366,
14,
4482,
12,
366,
14,
2977,
61,
272,
340,
1228,
8,
68,
12,
3363,
63,
2083,
304,
267,
4775,
14,
2880,
779,
68,
14,
5180,
12,
366,
14,
10698,
12,
366,
14,
4375,
12,
366,
14,
16627,
12,
366,
14,
9374,
566,
272,
372,
2197,
2031,
829,
9,
421,
199,
3,
3091,
2291,
367,
14053,
1159,
2071,
83,
2,
503,
2071,
89,
1674,
199,
3,
27301,
340,
2337,
1159,
376,
2755,
1329,
402,
2071,
2,
83,
2952,
2985,
787,
11077,
14,
199,
63,
23375,
63,
20034,
275,
295,
14,
2014,
8,
82,
2,
1332,
62,
23629,
5,
566,
4042,
5,
3342,
5,
59,
1786,
566,
531,
421,
199,
318,
485,
6452,
8,
505,
12,
1007,
495,
304,
272,
327,
6121,
17651,
29755,
272,
15424,
275,
942,
272,
284,
275,
378,
272,
1830,
715,
26,
267,
1335,
275,
1318,
14,
1623,
8,
22668,
12,
284,
9,
267,
340,
1335,
508,
446,
17,
26,
288,
2059,
267,
15424,
14,
740,
8,
74,
9,
267,
284,
275,
1335,
11,
17,
272,
372,
15424,
421,
199,
318,
14053,
8,
3583,
12,
7104,
304,
272,
340,
4487,
14,
3403,
2356,
5851,
383,
26,
267,
372,
1613,
8,
466,
8,
3583,
395,
4487,
680,
6205,
8,
5045,
9,
272,
20282,
63,
20034,
275,
485,
23375,
63,
20034,
14,
1733,
8,
5045,
9,
272,
340,
20282,
63,
20034,
26,
267,
746,
3146,
480,
6205,
402,
10831,
2544,
5851,
383,
1630,
440,
2429,
2,
435,
20282,
63,
20034,
14,
923,
8,
16,
430,
339,
5361,
275,
4487,
14,
3403,
272,
327,
2104,
4036,
2222,
13,
28764,
5361,
13345,
18359,
12,
18695,
701,
272,
327,
1227,
17399,
370,
664,
1901,
314,
7294,
13,
3403,
11982,
8643,
272,
5762,
275,
12293,
446,
5361,
272,
2331,
275,
1227,
5830,
3136,
5001,
2948,
435,
5762,
5001,
8290,
9,
272,
5361,
275,
5361,
435,
2331,
339,
327,
14171,
370,
6818,
314,
5361,
12293,
272,
5361,
275,
5361,
435,
3666,
8269,
446,
5361,
28428,
1651,
3342,
1651,
272,
900,
2960,
275,
4487,
14,
22309,
342,
272,
308,
17,
275,
900,
14,
6205,
8,
5045,
12,
334,
3403,
4258,
435,
900,
2960,
59,
17,
5728,
272,
15424,
17,
275,
485,
6452,
8,
83,
17,
12,
620,
8,
3403,
430,
339,
308,
18,
275,
900,
14,
6205,
8,
5045,
12,
334,
3403,
11,
1651,
4258,
435,
900,
2960,
59,
17,
5728,
272,
15424,
18,
275,
485
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
8,
35,
9,
7129,
13,
6965,
6848,
973,
699,
1030,
265,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
29896,
14,
199,
3,
199,
3,
29896,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
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,
29896,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
29896,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
22208,
14,
2087,
199,
504,
2197,
492,
1434,
465,
3363,
63,
602,
12,
2197,
465,
3363,
63,
2083,
12,
6871,
199,
646,
900,
199,
646,
295,
199,
893,
26,
272,
687,
22208,
492,
5823,
199,
2590,
3545,
26,
272,
746,
3545,
360,
8254,
3907,
2366,
13,
602,
1974,
358,
421,
199,
363,
452,
363,
275,
788,
1832,
18,
5834,
297,
283,
5834,
18,
1832,
297,
283,
10608,
2506,
39,
10138,
332,
297,
283,
602,
297,
283,
2083,
297,
283,
1222,
63,
602,
297,
283,
1222,
63,
2083,
297,
283,
22061,
63,
602,
418,
421,
199,
318,
2257,
18,
5834,
8,
602,
1113,
304,
272,
1434,
1113,
275,
1434,
1113,
14,
1814,
8,
9374,
29,
3903,
14,
3903,
1832,
1012,
272,
1434,
1113,
275,
1434,
1113,
14,
29648,
8,
3903,
14,
3903,
5834,
1012,
272,
372,
1434,
1113,
421,
199,
318,
19314,
18,
1832,
8,
602,
1113,
304,
272,
1434,
1113,
275,
1434,
1113,
14,
1814,
8,
9374,
29,
3903,
14,
3903,
5834,
1012,
272,
1434,
1113,
275,
1434,
1113,
14,
29648,
8,
3903,
14,
3903,
1832,
1012,
272,
372,
1434,
1113,
421,
199,
533,
1434,
8,
3093,
63,
602,
304,
272,
347,
14053,
8,
277,
12,
7104,
304,
267,
372,
14053,
8,
277,
12,
7104,
9,
339,
768,
3744,
272,
347,
687,
63,
602,
8,
1886,
12,
366,
304,
267,
372,
843,
8,
68,
14,
3403,
12,
366,
14,
4482,
12,
366,
14,
2977,
9,
421,
199,
533,
2197,
8,
3093,
63,
2083,
304,
272,
347,
14053,
8,
277,
12,
7104,
304,
267,
372,
14053,
8,
277,
12,
7104,
9,
339,
347,
13323,
8,
277,
12,
1434,
12,
900,
304,
267,
372,
2197,
8,
602,
14,
3403,
12,
1434,
14,
4482,
12,
1434,
14,
2977,
12,
900,
14,
5180,
12,
900,
14,
10698,
12,
900,
14,
16627,
12,
900,
14,
9374,
9,
339,
347,
1434,
8,
277,
304,
267,
372,
1434,
8,
277,
14,
3403,
12,
291,
14,
4482,
12,
291,
14,
2977,
9,
339,
768,
3744,
272,
347,
687,
63,
2083,
8,
1886,
12,
4487,
304,
267,
372,
843,
8,
3583,
14,
3403,
12,
4487,
14,
4482,
12,
4487,
14,
2977,
12,
4487,
14,
5180,
12,
4487,
14,
10698,
12,
4487,
14,
4375,
12,
4487,
14,
16627,
12,
4487,
14,
9374,
9,
421,
199,
318,
892,
63,
602,
8,
68,
304,
272,
408,
7958,
282,
5048,
1434,
687,
282,
2197,
14,
602,
909,
408,
272,
372,
1434,
8,
68,
14,
3403,
12,
366,
14,
4482,
12,
366,
14,
2977,
9,
421,
199,
318,
892,
63,
2083,
8,
68,
304,
272,
408,
272,
7958,
282,
5048,
2197,
687,
282,
2197,
14,
602,
503,
2197,
14,
2083,
909,
272,
408,
272,
4775,
275,
359,
68,
14,
3403,
12,
366,
14,
4482,
12,
366,
14,
2977,
61,
272,
340,
1228,
8,
68,
12,
3363,
63,
2083,
304,
267,
4775,
14,
2880,
779,
68,
14,
5180,
12,
366,
14,
10698,
12,
366,
14,
4375,
12,
366,
14,
16627,
12,
366,
14,
9374,
566,
272,
372,
2197,
2031,
829,
9,
421,
199,
3,
3091,
2291,
367,
14053,
1159,
2071,
83,
2,
503,
2071,
89,
1674,
199,
3,
27301,
340,
2337,
1159,
376,
2755,
1329,
402,
2071,
2,
83,
2952,
2985,
787,
11077,
14,
199,
63,
23375,
63,
20034,
275,
295,
14,
2014,
8,
82,
2,
1332,
62,
23629,
5,
566,
4042,
5,
3342,
5,
59,
1786,
566,
531,
421,
199,
318,
485,
6452,
8,
505,
12,
1007,
495,
304,
272,
327,
6121,
17651,
29755,
272,
15424,
275,
942,
272,
284,
275,
378,
272,
1830,
715,
26,
267,
1335,
275,
1318,
14,
1623,
8,
22668,
12,
284,
9,
267,
340,
1335,
508,
446,
17,
26,
288,
2059,
267,
15424,
14,
740,
8,
74,
9,
267,
284,
275,
1335,
11,
17,
272,
372,
15424,
421,
199,
318,
14053,
8,
3583,
12,
7104,
304,
272,
340,
4487,
14,
3403,
2356,
5851,
383,
26,
267,
372,
1613,
8,
466,
8,
3583,
395,
4487,
680,
6205,
8,
5045,
9,
272,
20282,
63,
20034,
275,
485,
23375,
63,
20034,
14,
1733,
8,
5045,
9,
272,
340,
20282,
63,
20034,
26,
267,
746,
3146,
480,
6205,
402,
10831,
2544,
5851,
383,
1630,
440,
2429,
2,
435,
20282,
63,
20034,
14,
923,
8,
16,
430,
339,
5361,
275,
4487,
14,
3403,
272,
327,
2104,
4036,
2222,
13,
28764,
5361,
13345,
18359,
12,
18695,
701,
272,
327,
1227,
17399,
370,
664,
1901,
314,
7294,
13,
3403,
11982,
8643,
272,
5762,
275,
12293,
446,
5361,
272,
2331,
275,
1227,
5830,
3136,
5001,
2948,
435,
5762,
5001,
8290,
9,
272,
5361,
275,
5361,
435,
2331,
339,
327,
14171,
370,
6818,
314,
5361,
12293,
272,
5361,
275,
5361,
435,
3666,
8269,
446,
5361,
28428,
1651,
3342,
1651,
272,
900,
2960,
275,
4487,
14,
22309,
342,
272,
308,
17,
275,
900,
14,
6205,
8,
5045,
12,
334,
3403,
4258,
435,
900,
2960,
59,
17,
5728,
272,
15424,
17,
275,
485,
6452,
8,
83,
17,
12,
620,
8,
3403,
430,
339,
308,
18,
275,
900,
14,
6205,
8,
5045,
12,
334,
3403,
11,
1651,
4258,
435,
900,
2960,
59,
17,
5728,
272,
15424,
18,
275,
485,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,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.py
|
1
|
1208
|
import urllib2
from core import base
from core.auth import Auth
class IRCPaint(base.baseClass):
@classmethod
def get_drawing(cls, sid):
return urllib2.urlopen('http://ircpaint.randomlab.info/rawirc.php?q={}'.format(sid)).read()
def on_privmsg(self, address, target, text):
if target == self.irc.nickname and text.startswith('ircpaint'):
params = text.split()
if params[0] != 'ircpaint':
return
nickname = address.split('!')[0]
user = Auth.get_user_by_hostmask(self.irc.id, address)
if user is None or 'n' not in user.flags:
self.irc.notice(nickname, 'Insufficient privileges')
elif len(params) < 3:
self.irc.notice(nickname, 'Usage: ircpaint <target> <id>')
else:
try:
drawing = self.get_drawing(params[2])
except urllib2.HTTPError as e:
self.irc.notice(nickname, 'Unable to get drawing: {}'.format(e))
else:
drawing = drawing.split()
for line in drawing:
self.irc.msg(params[1], line.strip())
|
agpl-3.0
|
[
646,
4011,
18,
199,
504,
6170,
492,
1300,
199,
504,
6170,
14,
1178,
492,
3590,
199,
199,
533,
473,
50,
2890,
65,
442,
8,
1095,
14,
1095,
2543,
304,
272,
768,
3744,
272,
347,
664,
63,
25195,
8,
1886,
12,
15764,
304,
267,
372,
4011,
18,
14,
10890,
360,
1014,
921,
5958,
17486,
14,
2355,
5561,
14,
815,
15,
1773,
5958,
14,
8624,
31,
81,
27244,
908,
8,
4148,
4992,
739,
342,
339,
347,
641,
63,
10605,
1328,
8,
277,
12,
2287,
12,
1347,
12,
1318,
304,
267,
340,
1347,
508,
291,
14,
5958,
14,
18544,
436,
1318,
14,
2460,
360,
5958,
17486,
735,
288,
1862,
275,
1318,
14,
1294,
342,
288,
340,
1862,
59,
16,
61,
1137,
283,
5958,
17486,
356,
355,
372,
288,
24332,
275,
2287,
14,
1294,
16157,
5832,
16,
61,
288,
922,
275,
3590,
14,
362,
63,
751,
63,
991,
63,
1102,
2629,
8,
277,
14,
5958,
14,
344,
12,
2287,
9,
288,
340,
922,
365,
488,
503,
283,
78,
7,
440,
315,
922,
14,
2469,
26,
355,
291,
14,
5958,
14,
20556,
8,
18544,
12,
283,
13962,
12983,
20001,
358,
288,
916,
822,
8,
1162,
9,
665,
650,
26,
355,
291,
14,
5958,
14,
20556,
8,
18544,
12,
283,
7692,
26,
22157,
17486,
665,
1375,
30,
665,
344,
5971,
288,
587,
26,
355,
862,
26,
490,
17455,
275,
291,
14,
362,
63,
25195,
8,
1162,
59,
18,
566,
355,
871,
4011,
18,
14,
12815,
465,
325,
26,
490,
291,
14,
5958,
14,
20556,
8,
18544,
12,
283,
6005,
370,
664,
17455,
26,
9499,
908,
8,
69,
430,
355,
587,
26,
490,
17455,
275,
17455,
14,
1294,
342,
490,
367,
1004,
315,
17455,
26,
717,
291,
14,
5958,
14,
1328,
8,
1162,
59,
17,
467,
1004,
14,
1913,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4011,
18,
199,
504,
6170,
492,
1300,
199,
504,
6170,
14,
1178,
492,
3590,
199,
199,
533,
473,
50,
2890,
65,
442,
8,
1095,
14,
1095,
2543,
304,
272,
768,
3744,
272,
347,
664,
63,
25195,
8,
1886,
12,
15764,
304,
267,
372,
4011,
18,
14,
10890,
360,
1014,
921,
5958,
17486,
14,
2355,
5561,
14,
815,
15,
1773,
5958,
14,
8624,
31,
81,
27244,
908,
8,
4148,
4992,
739,
342,
339,
347,
641,
63,
10605,
1328,
8,
277,
12,
2287,
12,
1347,
12,
1318,
304,
267,
340,
1347,
508,
291,
14,
5958,
14,
18544,
436,
1318,
14,
2460,
360,
5958,
17486,
735,
288,
1862,
275,
1318,
14,
1294,
342,
288,
340,
1862,
59,
16,
61,
1137,
283,
5958,
17486,
356,
355,
372,
288,
24332,
275,
2287,
14,
1294,
16157,
5832,
16,
61,
288,
922,
275,
3590,
14,
362,
63,
751,
63,
991,
63,
1102,
2629,
8,
277,
14,
5958,
14,
344,
12,
2287,
9,
288,
340,
922,
365,
488,
503,
283,
78,
7,
440,
315,
922,
14,
2469,
26,
355,
291,
14,
5958,
14,
20556,
8,
18544,
12,
283,
13962,
12983,
20001,
358,
288,
916,
822,
8,
1162,
9,
665,
650,
26,
355,
291,
14,
5958,
14,
20556,
8,
18544,
12,
283,
7692,
26,
22157,
17486,
665,
1375,
30,
665,
344,
5971,
288,
587,
26,
355,
862,
26,
490,
17455,
275,
291,
14,
362,
63,
25195,
8,
1162,
59,
18,
566,
355,
871,
4011,
18,
14,
12815,
465,
325,
26,
490,
291,
14,
5958,
14,
20556,
8,
18544,
12,
283,
6005,
370,
664,
17455,
26,
9499,
908,
8,
69,
430,
355,
587,
26,
490,
17455,
275,
17455,
14,
1294,
342,
490,
367,
1004,
315,
17455,
26,
717,
291,
14,
5958,
14,
1328,
8,
1162,
59,
17,
467,
1004,
14,
1913,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
shubmit/shub-ltp
|
testcases/network/nfsv4/acl/test_long_acl.py
|
27
|
1337
|
'''
Access Control Lists testing based on newpynfs framework
Aurelien Charbon - Bull SA
'''
from random_gen import *
from optparse import OptionParser
import commands
import os
import threading
import time
import random
alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_-() ~'
t_alphabet=len(alphabet)
def test_longacl(l,path):
# mesures sur le getfacl
test = RandomGen()
u = commands.getoutput('rm ' + path + "/*") # clean directory
print "test acl getfacl\n"
for i in range(l):
test.getUserList()
testfile = 'testfile' + str(i)
u = commands.getoutput('touch ' + path + "/" + testfile)
print "setfacl with " + str(i) + " entries\n " + u
for j in range(i):
user = test.uList.pop()
mode = test.createRandomMode()
u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile)
if u != "":
print "setfacl -m u:" + user + ':' + mode + " " + path + "/" + testfile
print u
def main():
parser = OptionParser()
parser.add_option("-l", "--length", dest="length",type="int",help="max lentgh of ACL")
parser.add_option("-p", "--path", dest="path",help="path of test file")
(options, args) = parser.parse_args()
test_longacl(options.length,options.path)
main()
|
gpl-2.0
|
[
2344,
199,
198,
3946,
8612,
31289,
5343,
4079,
641,
892,
647,
19591,
10059,
199,
198,
33,
608,
317,
287,
6659,
13520,
446,
699,
979,
13950,
199,
2344,
199,
504,
2196,
63,
2268,
492,
627,
199,
504,
8691,
492,
13491,
199,
646,
3718,
199,
646,
747,
199,
646,
5796,
199,
646,
900,
199,
646,
2196,
199,
199,
31884,
534,
23459,
28114,
11272,
32069,
342,
6146,
7,
199,
84,
63,
31884,
29,
552,
8,
31884,
9,
4388,
199,
318,
511,
63,
2809,
5853,
8,
76,
12,
515,
304,
199,
198,
3,
26560,
1482,
6296,
1026,
664,
667,
429,
199,
198,
396,
275,
9571,
8168,
342,
421,
198,
85,
275,
3718,
14,
362,
1199,
360,
5682,
283,
435,
931,
435,
3286,
10,
531,
198,
3,
3633,
2082,
199,
198,
1361,
298,
396,
15316,
664,
667,
429,
60,
78,
2,
199,
198,
509,
284,
315,
1425,
8,
76,
304,
507,
198,
396,
14,
32627,
1296,
342,
507,
198,
21091,
275,
283,
21091,
7,
435,
620,
8,
73,
9,
507,
198,
85,
275,
3718,
14,
362,
1199,
360,
12376,
283,
435,
931,
435,
10609,
435,
30530,
9,
507,
198,
1361,
298,
409,
667,
429,
543,
298,
435,
620,
8,
73,
9,
435,
298,
4811,
60,
78,
298,
435,
399,
507,
198,
509,
1335,
315,
1425,
8,
73,
304,
686,
198,
751,
275,
511,
14,
85,
1296,
14,
1935,
342,
686,
198,
632,
275,
511,
14,
981,
3883,
1385,
342,
717,
399,
275,
3718,
14,
362,
1199,
360,
409,
667,
429,
446,
77,
399,
4881,
435,
922,
435,
10871,
435,
818,
435,
298,
298,
435,
931,
435,
10609,
435,
30530,
9,
507,
4483,
340,
399,
1137,
10812,
1816,
870,
298,
409,
667,
429,
446,
77,
399,
5424,
435,
922,
435,
10871,
435,
818,
435,
298,
298,
435,
931,
435,
10609,
435,
30530,
1816,
870,
399,
199,
318,
2446,
837,
199,
198,
2087,
275,
13491,
342,
199,
198,
2087,
14,
525,
63,
1422,
6096,
76,
401,
4320,
1267,
401,
2053,
628,
1267,
401,
466,
628,
442,
401,
3437,
628,
988,
1026,
343,
3561,
402,
16543,
531,
199,
198,
2087,
14,
525,
63,
1422,
6096,
80,
401,
4320,
515,
401,
2053,
628,
515,
401,
3437,
628,
515,
402,
511,
570,
531,
199,
198,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
198,
396,
63,
2809,
5853,
8,
1419,
14,
1267,
12,
1419,
14,
515,
9,
199,
973,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
198,
3946,
8612,
31289,
5343,
4079,
641,
892,
647,
19591,
10059,
199,
198,
33,
608,
317,
287,
6659,
13520,
446,
699,
979,
13950,
199,
2344,
199,
504,
2196,
63,
2268,
492,
627,
199,
504,
8691,
492,
13491,
199,
646,
3718,
199,
646,
747,
199,
646,
5796,
199,
646,
900,
199,
646,
2196,
199,
199,
31884,
534,
23459,
28114,
11272,
32069,
342,
6146,
7,
199,
84,
63,
31884,
29,
552,
8,
31884,
9,
4388,
199,
318,
511,
63,
2809,
5853,
8,
76,
12,
515,
304,
199,
198,
3,
26560,
1482,
6296,
1026,
664,
667,
429,
199,
198,
396,
275,
9571,
8168,
342,
421,
198,
85,
275,
3718,
14,
362,
1199,
360,
5682,
283,
435,
931,
435,
3286,
10,
531,
198,
3,
3633,
2082,
199,
198,
1361,
298,
396,
15316,
664,
667,
429,
60,
78,
2,
199,
198,
509,
284,
315,
1425,
8,
76,
304,
507,
198,
396,
14,
32627,
1296,
342,
507,
198,
21091,
275,
283,
21091,
7,
435,
620,
8,
73,
9,
507,
198,
85,
275,
3718,
14,
362,
1199,
360,
12376,
283,
435,
931,
435,
10609,
435,
30530,
9,
507,
198,
1361,
298,
409,
667,
429,
543,
298,
435,
620,
8,
73,
9,
435,
298,
4811,
60,
78,
298,
435,
399,
507,
198,
509,
1335,
315,
1425,
8,
73,
304,
686,
198,
751,
275,
511,
14,
85,
1296,
14,
1935,
342,
686,
198,
632,
275,
511,
14,
981,
3883,
1385,
342,
717,
399,
275,
3718,
14,
362,
1199,
360,
409,
667,
429,
446,
77,
399,
4881,
435,
922,
435,
10871,
435,
818,
435,
298,
298,
435,
931,
435,
10609,
435,
30530,
9,
507,
4483,
340,
399,
1137,
10812,
1816,
870,
298,
409,
667,
429,
446,
77,
399,
5424,
435,
922,
435,
10871,
435,
818,
435,
298,
298,
435,
931,
435,
10609,
435,
30530,
1816,
870,
399,
199,
318,
2446,
837,
199,
198,
2087,
275,
13491,
342,
199,
198,
2087,
14,
525,
63,
1422,
6096,
76,
401,
4320,
1267,
401,
2053,
628,
1267,
401,
466,
628,
442,
401,
3437,
628,
988,
1026,
343,
3561,
402,
16543,
531,
199,
198,
2087,
14,
525,
63,
1422,
6096,
80,
401,
4320,
515,
401,
2053,
628,
515,
401,
3437,
628,
515,
402,
511,
570,
531,
199,
198,
8,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
199,
198,
396,
63,
2809,
5853,
8,
1419,
14,
1267,
12,
1419,
14,
515,
9,
199,
973,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
broferek/ansible
|
lib/ansible/modules/network/fortios/fortios_switch_controller_network_monitor_settings.py
|
14
|
9049
|
#!/usr/bin/python
from __future__ import (absolute_import, division, print_function)
# Copyright 2019 Fortinet, Inc.
#
# 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 <https://www.gnu.org/licenses/>.
__metaclass__ = type
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'metadata_version': '1.1'}
DOCUMENTATION = '''
---
module: fortios_switch_controller_network_monitor_settings
short_description: Configure network monitor settings in Fortinet's FortiOS and FortiGate.
description:
- This module is able to configure a FortiGate or FortiOS (FOS) device by allowing the
user to set and modify switch_controller feature and network_monitor_settings category.
Examples include all parameters and values need to be adjusted to datasources before usage.
Tested with FOS v6.0.5
version_added: "2.8"
author:
- Miguel Angel Munoz (@mamunozgonzalez)
- Nicolas Thomas (@thomnico)
notes:
- Requires fortiosapi library developed by Fortinet
- Run as a local_action in your playbook
requirements:
- fortiosapi>=0.9.8
options:
host:
description:
- FortiOS or FortiGate IP address.
type: str
required: false
username:
description:
- FortiOS or FortiGate username.
type: str
required: false
password:
description:
- FortiOS or FortiGate password.
type: str
default: ""
vdom:
description:
- Virtual domain, among those defined previously. A vdom is a
virtual instance of the FortiGate that can be configured and
used as a different unit.
type: str
default: root
https:
description:
- Indicates if the requests towards FortiGate must use HTTPS protocol.
type: bool
default: true
ssl_verify:
description:
- Ensures FortiGate certificate must be verified by a proper CA.
type: bool
default: true
version_added: 2.9
switch_controller_network_monitor_settings:
description:
- Configure network monitor settings.
default: null
type: dict
suboptions:
network_monitoring:
description:
- Enable/disable passive gathering of information by FortiSwitch units concerning other network devices.
type: str
choices:
- enable
- disable
'''
EXAMPLES = '''
- hosts: localhost
vars:
host: "192.168.122.40"
username: "admin"
password: ""
vdom: "root"
ssl_verify: "False"
tasks:
- name: Configure network monitor settings.
fortios_switch_controller_network_monitor_settings:
host: "{{ host }}"
username: "{{ username }}"
password: "{{ password }}"
vdom: "{{ vdom }}"
https: "False"
switch_controller_network_monitor_settings:
network_monitoring: "enable"
'''
RETURN = '''
build:
description: Build number of the fortigate image
returned: always
type: str
sample: '1547'
http_method:
description: Last method used to provision the content into FortiGate
returned: always
type: str
sample: 'PUT'
http_status:
description: Last result given by FortiGate on last operation applied
returned: always
type: str
sample: "200"
mkey:
description: Master key (id) used in the last call to FortiGate
returned: success
type: str
sample: "id"
name:
description: Name of the table used to fulfill the request
returned: always
type: str
sample: "urlfilter"
path:
description: Path of the table used to fulfill the request
returned: always
type: str
sample: "webfilter"
revision:
description: Internal revision number
returned: always
type: str
sample: "17.0.2.10658"
serial:
description: Serial number of the unit
returned: always
type: str
sample: "FGVMEVYYQT3AB5352"
status:
description: Indication of the operation's result
returned: always
type: str
sample: "success"
vdom:
description: Virtual domain used
returned: always
type: str
sample: "root"
version:
description: Version of the FortiGate
returned: always
type: str
sample: "v5.6.3"
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import Connection
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
from ansible.module_utils.network.fortimanager.common import FAIL_SOCKET_MSG
def login(data, fos):
host = data['host']
username = data['username']
password = data['password']
ssl_verify = data['ssl_verify']
fos.debug('on')
if 'https' in data and not data['https']:
fos.https('off')
else:
fos.https('on')
fos.login(host, username, password, verify=ssl_verify)
def filter_switch_controller_network_monitor_settings_data(json):
option_list = ['network_monitoring']
dictionary = {}
for attribute in option_list:
if attribute in json and json[attribute] is not None:
dictionary[attribute] = json[attribute]
return dictionary
def underscore_to_hyphen(data):
if isinstance(data, list):
for elem in data:
elem = underscore_to_hyphen(elem)
elif isinstance(data, dict):
new_data = {}
for k, v in data.items():
new_data[k.replace('_', '-')] = underscore_to_hyphen(v)
data = new_data
return data
def switch_controller_network_monitor_settings(data, fos):
vdom = data['vdom']
switch_controller_network_monitor_settings_data = data['switch_controller_network_monitor_settings']
filtered_data = underscore_to_hyphen(filter_switch_controller_network_monitor_settings_data(switch_controller_network_monitor_settings_data))
return fos.set('switch-controller',
'network-monitor-settings',
data=filtered_data,
vdom=vdom)
def is_successful_status(status):
return status['status'] == "success" or \
status['http_method'] == "DELETE" and status['http_status'] == 404
def fortios_switch_controller(data, fos):
if data['switch_controller_network_monitor_settings']:
resp = switch_controller_network_monitor_settings(data, fos)
return not is_successful_status(resp), \
resp['status'] == "success", \
resp
def main():
fields = {
"host": {"required": False, "type": "str"},
"username": {"required": False, "type": "str"},
"password": {"required": False, "type": "str", "default": "", "no_log": True},
"vdom": {"required": False, "type": "str", "default": "root"},
"https": {"required": False, "type": "bool", "default": True},
"ssl_verify": {"required": False, "type": "bool", "default": True},
"switch_controller_network_monitor_settings": {
"required": False, "type": "dict", "default": None,
"options": {
"network_monitoring": {"required": False, "type": "str",
"choices": ["enable", "disable"]}
}
}
}
module = AnsibleModule(argument_spec=fields,
supports_check_mode=False)
# legacy_mode refers to using fortiosapi instead of HTTPAPI
legacy_mode = 'host' in module.params and module.params['host'] is not None and \
'username' in module.params and module.params['username'] is not None and \
'password' in module.params and module.params['password'] is not None
if not legacy_mode:
if module._socket_path:
connection = Connection(module._socket_path)
fos = FortiOSHandler(connection)
is_error, has_changed, result = fortios_switch_controller(module.params, fos)
else:
module.fail_json(**FAIL_SOCKET_MSG)
else:
try:
from fortiosapi import FortiOSAPI
except ImportError:
module.fail_json(msg="fortiosapi module is required")
fos = FortiOSAPI()
login(module.params, fos)
is_error, has_changed, result = fortios_switch_controller(module.params, fos)
fos.logout()
if not is_error:
module.exit_json(changed=has_changed, meta=result)
else:
module.fail_json(msg="Error in repo", meta=result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
3,
1898,
20312,
30205,
10811,
12,
3277,
14,
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,
2859,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
19516,
63,
5656,
63,
5538,
63,
1200,
63,
7157,
63,
1751,
199,
3612,
63,
1802,
26,
15453,
2784,
8372,
2202,
315,
30205,
10811,
1159,
22913,
436,
20306,
14,
199,
1802,
26,
272,
446,
961,
859,
365,
7688,
370,
7908,
282,
20306,
503,
22913,
334,
38,
3100,
9,
2243,
701,
17266,
314,
489,
922,
370,
663,
436,
2811,
6258,
63,
5538,
3878,
436,
2784,
63,
7157,
63,
1751,
4637,
14,
489,
6058,
2387,
1006,
2633,
436,
1338,
1929,
370,
506,
19477,
370,
29289,
83,
2544,
4503,
14,
489,
30568,
543,
481,
3100,
373,
22,
14,
16,
14,
21,
199,
1023,
63,
3270,
26,
298,
18,
14,
24,
2,
199,
2502,
26,
272,
446,
28195,
13086,
1626,
24920,
603,
324,
26051,
8593,
391,
32368,
26051,
27719,
90,
1895,
90,
9,
272,
446,
30650,
761,
305,
27864,
8593,
273,
676,
8445,
331,
9,
199,
5983,
26,
272,
446,
15127,
19516,
1246,
3555,
477,
27813,
701,
30205,
10811,
272,
446,
3378,
465,
282,
2257,
63,
1287,
315,
2195,
15695,
199,
7538,
26,
272,
446,
19516,
1246,
8119,
16,
14,
25,
14,
24,
199,
1419,
26,
272,
1591,
26,
267,
1369,
26,
288,
446,
22913,
503,
20306,
3531,
2287,
14,
267,
730,
26,
620,
267,
1415,
26,
3055,
272,
3434,
26,
267,
1369,
26,
288,
446,
22913,
503,
20306,
3434,
14,
267,
730,
26,
620,
267,
1415,
26,
3055,
272,
2505,
26,
267,
1369,
26,
288,
446,
22913,
503,
20306,
2505,
14,
267,
730,
26,
620,
267,
849,
26,
3087,
272,
20822,
26,
267,
1369,
26,
288,
446,
13311,
2881,
12,
16885,
5204,
3247,
10889,
14,
437,
20822,
365,
282,
1598,
5791,
1256,
402,
314,
20306,
626,
883,
506,
7526,
436,
1598,
1202,
465,
282,
3365,
4137,
14,
267,
730,
26,
620,
267,
849,
26,
1738,
272,
4178,
26,
267,
1369,
26,
288,
446,
19334,
340,
314,
4145,
28354,
20306,
1471,
675,
14147,
4113,
14,
267,
730,
26,
2155,
267,
849,
26,
2549,
272,
6149,
63,
4712,
26,
267,
1369,
26,
288,
446,
29652,
20306,
5897,
1471,
506,
16317,
701,
282,
5576,
7240,
14,
267,
730,
26,
2155,
267,
849,
26,
2549,
267,
1015,
63,
3270,
26,
499,
14,
25,
272,
6258,
63,
5538,
63,
1200,
63,
7157,
63,
1751,
26,
267,
1369,
26,
288,
446,
15453,
2784,
8372,
2202,
14,
267,
849,
26,
2973,
267,
730,
26,
1211,
267,
26265,
26,
288,
2784,
63,
20554,
26,
355,
1369,
26,
490,
446,
12030,
15,
5993,
21010,
13082,
316,
402,
2556,
701,
13694,
10167,
6204,
406,
2247,
1835,
1163,
2784,
7256,
14,
355,
730,
26,
620,
355,
3415,
26,
490,
446,
4756,
490,
446,
3507,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
7057,
26,
11667,
523,
6802,
26,
2043,
1591,
26,
298,
5756,
14,
6568,
14,
7507,
14,
2167,
2,
2043,
3434,
26,
298,
2113,
2,
2043,
2505,
26,
3087,
2043,
20822,
26,
298,
1231,
2,
2043,
6149,
63,
4712,
26,
298,
797,
2,
523,
6527,
26,
523,
446,
536,
26,
15453,
2784,
8372,
2202,
14,
272,
19516,
63,
5656,
63,
5538,
63,
1200,
63,
7157,
63,
1751,
26,
489,
1591,
26,
221,
7370,
1591,
7820,
489,
3434,
26,
7370,
3434,
7820,
489,
2505,
26,
7370,
2505,
7820,
489,
20822,
26,
221,
7370,
20822,
7820,
489,
4178,
26,
298,
797,
2,
489,
6258,
63,
5538,
63,
1200,
63,
7157,
63,
1751,
26,
267,
2784,
63,
20554,
26,
298,
4296,
2,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1506,
26,
523,
1369,
26,
6516,
1329,
402,
314,
367,
280,
3237,
1834,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
283,
1046,
2417,
7,
199,
1014,
63,
765,
26,
523,
1369,
26,
15237,
1083,
1202,
370,
15408,
314,
1564,
1901,
20306,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
283,
4013,
7,
199,
1014,
63,
1205,
26,
523,
1369,
26,
15237,
754,
1627,
701,
20306,
641,
2061,
3439,
6781,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
298,
1840,
2,
199,
77,
498,
26,
523,
1369,
26,
26728,
790,
334,
344,
9,
1202,
315,
314,
2061,
1240,
370,
20306,
523,
2138,
26,
3182,
523,
730,
26,
620,
523,
2690,
26,
298,
344,
2,
199,
354,
26,
523,
1369,
26,
2812,
402,
314,
1817,
1202,
370,
15632,
22503,
314,
1056,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
298,
300,
276,
3518,
2,
199,
515,
26,
523,
1369,
26,
6912,
402,
314,
1817,
1202,
370,
15632,
22503,
314,
1056,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
298,
2520,
1541,
2,
199,
5792,
26,
523,
1369,
26,
12624,
6974,
1329,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
298,
1196,
14,
16,
14,
18,
14,
7357,
2010,
2,
199,
2171,
26,
523,
1369,
26,
11973,
1329,
402,
314,
4137,
523
] |
[
2647,
15,
1393,
15,
1548,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
3,
1898,
20312,
30205,
10811,
12,
3277,
14,
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,
2859,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
19516,
63,
5656,
63,
5538,
63,
1200,
63,
7157,
63,
1751,
199,
3612,
63,
1802,
26,
15453,
2784,
8372,
2202,
315,
30205,
10811,
1159,
22913,
436,
20306,
14,
199,
1802,
26,
272,
446,
961,
859,
365,
7688,
370,
7908,
282,
20306,
503,
22913,
334,
38,
3100,
9,
2243,
701,
17266,
314,
489,
922,
370,
663,
436,
2811,
6258,
63,
5538,
3878,
436,
2784,
63,
7157,
63,
1751,
4637,
14,
489,
6058,
2387,
1006,
2633,
436,
1338,
1929,
370,
506,
19477,
370,
29289,
83,
2544,
4503,
14,
489,
30568,
543,
481,
3100,
373,
22,
14,
16,
14,
21,
199,
1023,
63,
3270,
26,
298,
18,
14,
24,
2,
199,
2502,
26,
272,
446,
28195,
13086,
1626,
24920,
603,
324,
26051,
8593,
391,
32368,
26051,
27719,
90,
1895,
90,
9,
272,
446,
30650,
761,
305,
27864,
8593,
273,
676,
8445,
331,
9,
199,
5983,
26,
272,
446,
15127,
19516,
1246,
3555,
477,
27813,
701,
30205,
10811,
272,
446,
3378,
465,
282,
2257,
63,
1287,
315,
2195,
15695,
199,
7538,
26,
272,
446,
19516,
1246,
8119,
16,
14,
25,
14,
24,
199,
1419,
26,
272,
1591,
26,
267,
1369,
26,
288,
446,
22913,
503,
20306,
3531,
2287,
14,
267,
730,
26,
620,
267,
1415,
26,
3055,
272,
3434,
26,
267,
1369,
26,
288,
446,
22913,
503,
20306,
3434,
14,
267,
730,
26,
620,
267,
1415,
26,
3055,
272,
2505,
26,
267,
1369,
26,
288,
446,
22913,
503,
20306,
2505,
14,
267,
730,
26,
620,
267,
849,
26,
3087,
272,
20822,
26,
267,
1369,
26,
288,
446,
13311,
2881,
12,
16885,
5204,
3247,
10889,
14,
437,
20822,
365,
282,
1598,
5791,
1256,
402,
314,
20306,
626,
883,
506,
7526,
436,
1598,
1202,
465,
282,
3365,
4137,
14,
267,
730,
26,
620,
267,
849,
26,
1738,
272,
4178,
26,
267,
1369,
26,
288,
446,
19334,
340,
314,
4145,
28354,
20306,
1471,
675,
14147,
4113,
14,
267,
730,
26,
2155,
267,
849,
26,
2549,
272,
6149,
63,
4712,
26,
267,
1369,
26,
288,
446,
29652,
20306,
5897,
1471,
506,
16317,
701,
282,
5576,
7240,
14,
267,
730,
26,
2155,
267,
849,
26,
2549,
267,
1015,
63,
3270,
26,
499,
14,
25,
272,
6258,
63,
5538,
63,
1200,
63,
7157,
63,
1751,
26,
267,
1369,
26,
288,
446,
15453,
2784,
8372,
2202,
14,
267,
849,
26,
2973,
267,
730,
26,
1211,
267,
26265,
26,
288,
2784,
63,
20554,
26,
355,
1369,
26,
490,
446,
12030,
15,
5993,
21010,
13082,
316,
402,
2556,
701,
13694,
10167,
6204,
406,
2247,
1835,
1163,
2784,
7256,
14,
355,
730,
26,
620,
355,
3415,
26,
490,
446,
4756,
490,
446,
3507,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
7057,
26,
11667,
523,
6802,
26,
2043,
1591,
26,
298,
5756,
14,
6568,
14,
7507,
14,
2167,
2,
2043,
3434,
26,
298,
2113,
2,
2043,
2505,
26,
3087,
2043,
20822,
26,
298,
1231,
2,
2043,
6149,
63,
4712,
26,
298,
797,
2,
523,
6527,
26,
523,
446,
536,
26,
15453,
2784,
8372,
2202,
14,
272,
19516,
63,
5656,
63,
5538,
63,
1200,
63,
7157,
63,
1751,
26,
489,
1591,
26,
221,
7370,
1591,
7820,
489,
3434,
26,
7370,
3434,
7820,
489,
2505,
26,
7370,
2505,
7820,
489,
20822,
26,
221,
7370,
20822,
7820,
489,
4178,
26,
298,
797,
2,
489,
6258,
63,
5538,
63,
1200,
63,
7157,
63,
1751,
26,
267,
2784,
63,
20554,
26,
298,
4296,
2,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1506,
26,
523,
1369,
26,
6516,
1329,
402,
314,
367,
280,
3237,
1834,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
283,
1046,
2417,
7,
199,
1014,
63,
765,
26,
523,
1369,
26,
15237,
1083,
1202,
370,
15408,
314,
1564,
1901,
20306,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
283,
4013,
7,
199,
1014,
63,
1205,
26,
523,
1369,
26,
15237,
754,
1627,
701,
20306,
641,
2061,
3439,
6781,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
298,
1840,
2,
199,
77,
498,
26,
523,
1369,
26,
26728,
790,
334,
344,
9,
1202,
315,
314,
2061,
1240,
370,
20306,
523,
2138,
26,
3182,
523,
730,
26,
620,
523,
2690,
26,
298,
344,
2,
199,
354,
26,
523,
1369,
26,
2812,
402,
314,
1817,
1202,
370,
15632,
22503,
314,
1056,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
298,
300,
276,
3518,
2,
199,
515,
26,
523,
1369,
26,
6912,
402,
314,
1817,
1202,
370,
15632,
22503,
314,
1056,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
298,
2520,
1541,
2,
199,
5792,
26,
523,
1369,
26,
12624,
6974,
1329,
523,
2138,
26,
3544,
523,
730,
26,
620,
523,
2690,
26,
298,
1196,
14,
16,
14,
18,
14,
7357,
2010,
2,
199,
2171,
26,
523,
1369,
26,
11973,
1329,
402,
314,
4137,
523,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
3L3N4/metagoofil
|
hachoir_core/field/fake_array.py
|
95
|
2294
|
import itertools
from hachoir_core.field import MissingField
class FakeArray:
"""
Simulate an array for GenericFieldSet.array(): fielset.array("item")[0] is
equivalent to fielset.array("item[0]").
It's possible to iterate over the items using::
for element in fieldset.array("item"):
...
And to get array size using len(fieldset.array("item")).
"""
def __init__(self, fieldset, name):
pos = name.rfind("/")
if pos != -1:
self.fieldset = fieldset[name[:pos]]
self.name = name[pos+1:]
else:
self.fieldset = fieldset
self.name = name
self._format = "%s[%%u]" % self.name
self._cache = {}
self._known_size = False
self._max_index = -1
def __nonzero__(self):
"Is the array empty or not?"
if self._cache:
return True
else:
return (0 in self)
def __len__(self):
"Number of fields in the array"
total = self._max_index+1
if not self._known_size:
for index in itertools.count(total):
try:
field = self[index]
total += 1
except MissingField:
break
return total
def __contains__(self, index):
try:
field = self[index]
return True
except MissingField:
return False
def __getitem__(self, index):
"""
Get a field of the array. Returns a field, or raise MissingField
exception if the field doesn't exist.
"""
try:
value = self._cache[index]
except KeyError:
try:
value = self.fieldset[self._format % index]
except MissingField:
self._known_size = True
raise
self._cache[index] = value
self._max_index = max(index, self._max_index)
return value
def __iter__(self):
"""
Iterate in the fields in their index order: field[0], field[1], ...
"""
for index in itertools.count(0):
try:
yield self[index]
except MissingField:
raise StopIteration()
|
gpl-2.0
|
[
646,
7975,
199,
504,
394,
21301,
63,
1018,
14,
698,
492,
15626,
792,
199,
199,
533,
7777,
3836,
26,
272,
408,
272,
10751,
5434,
376,
1625,
367,
8307,
23532,
14,
1144,
837,
5883,
352,
409,
14,
1144,
480,
1053,
9981,
16,
61,
365,
272,
7353,
370,
5883,
352,
409,
14,
1144,
480,
1053,
59,
16,
61,
3471,
339,
2779,
1159,
3962,
370,
13974,
1806,
314,
2974,
1808,
447,
398,
367,
1819,
315,
901,
409,
14,
1144,
480,
1053,
2349,
288,
2263,
339,
6061,
370,
664,
1625,
1568,
1808,
822,
8,
698,
409,
14,
1144,
480,
1053,
21688,
272,
408,
272,
347,
636,
826,
721,
277,
12,
901,
409,
12,
536,
304,
267,
2086,
275,
536,
14,
14542,
19031,
267,
340,
2086,
1137,
446,
17,
26,
288,
291,
14,
698,
409,
275,
901,
409,
59,
354,
1491,
1712,
2677,
288,
291,
14,
354,
275,
536,
59,
1712,
11,
17,
2938,
267,
587,
26,
288,
291,
14,
698,
409,
275,
901,
409,
288,
291,
14,
354,
275,
536,
267,
291,
423,
908,
275,
2071,
83,
59,
8530,
85,
8480,
450,
291,
14,
354,
267,
291,
423,
1637,
275,
1052,
267,
291,
423,
3159,
63,
890,
275,
756,
267,
291,
423,
988,
63,
1080,
275,
446,
17,
339,
347,
636,
10262,
721,
277,
304,
267,
298,
1831,
314,
1625,
2701,
503,
440,
13472,
267,
340,
291,
423,
1637,
26,
288,
372,
715,
267,
587,
26,
288,
372,
334,
16,
315,
291,
9,
339,
347,
636,
552,
721,
277,
304,
267,
298,
3259,
402,
1504,
315,
314,
1625,
2,
267,
3141,
275,
291,
423,
988,
63,
1080,
11,
17,
267,
340,
440,
291,
423,
3159,
63,
890,
26,
288,
367,
1478,
315,
7975,
14,
835,
8,
2923,
304,
355,
862,
26,
490,
901,
275,
291,
59,
1080,
61,
490,
3141,
847,
413,
355,
871,
15626,
792,
26,
490,
2059,
267,
372,
3141,
339,
347,
636,
6134,
721,
277,
12,
1478,
304,
267,
862,
26,
288,
901,
275,
291,
59,
1080,
61,
288,
372,
715,
267,
871,
15626,
792,
26,
288,
372,
756,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
408,
267,
2372,
282,
901,
402,
314,
1625,
14,
1803,
282,
901,
12,
503,
746,
15626,
792,
267,
1919,
340,
314,
901,
3181,
1133,
2187,
14,
267,
408,
267,
862,
26,
288,
574,
275,
291,
423,
1637,
59,
1080,
61,
267,
871,
4067,
26,
288,
862,
26,
355,
574,
275,
291,
14,
698,
409,
59,
277,
423,
908,
450,
1478,
61,
288,
871,
15626,
792,
26,
355,
291,
423,
3159,
63,
890,
275,
715,
355,
746,
288,
291,
423,
1637,
59,
1080,
61,
275,
574,
288,
291,
423,
988,
63,
1080,
275,
1390,
8,
1080,
12,
291,
423,
988,
63,
1080,
9,
267,
372,
574,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
267,
23989,
315,
314,
1504,
315,
3932,
1478,
1865,
26,
901,
59,
16,
467,
901,
59,
17,
467,
2263,
267,
408,
267,
367,
1478,
315,
7975,
14,
835,
8,
16,
304,
288,
862,
26,
355,
1995,
291,
59,
1080,
61,
288,
871,
15626,
792,
26,
355,
746,
10852,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7975,
199,
504,
394,
21301,
63,
1018,
14,
698,
492,
15626,
792,
199,
199,
533,
7777,
3836,
26,
272,
408,
272,
10751,
5434,
376,
1625,
367,
8307,
23532,
14,
1144,
837,
5883,
352,
409,
14,
1144,
480,
1053,
9981,
16,
61,
365,
272,
7353,
370,
5883,
352,
409,
14,
1144,
480,
1053,
59,
16,
61,
3471,
339,
2779,
1159,
3962,
370,
13974,
1806,
314,
2974,
1808,
447,
398,
367,
1819,
315,
901,
409,
14,
1144,
480,
1053,
2349,
288,
2263,
339,
6061,
370,
664,
1625,
1568,
1808,
822,
8,
698,
409,
14,
1144,
480,
1053,
21688,
272,
408,
272,
347,
636,
826,
721,
277,
12,
901,
409,
12,
536,
304,
267,
2086,
275,
536,
14,
14542,
19031,
267,
340,
2086,
1137,
446,
17,
26,
288,
291,
14,
698,
409,
275,
901,
409,
59,
354,
1491,
1712,
2677,
288,
291,
14,
354,
275,
536,
59,
1712,
11,
17,
2938,
267,
587,
26,
288,
291,
14,
698,
409,
275,
901,
409,
288,
291,
14,
354,
275,
536,
267,
291,
423,
908,
275,
2071,
83,
59,
8530,
85,
8480,
450,
291,
14,
354,
267,
291,
423,
1637,
275,
1052,
267,
291,
423,
3159,
63,
890,
275,
756,
267,
291,
423,
988,
63,
1080,
275,
446,
17,
339,
347,
636,
10262,
721,
277,
304,
267,
298,
1831,
314,
1625,
2701,
503,
440,
13472,
267,
340,
291,
423,
1637,
26,
288,
372,
715,
267,
587,
26,
288,
372,
334,
16,
315,
291,
9,
339,
347,
636,
552,
721,
277,
304,
267,
298,
3259,
402,
1504,
315,
314,
1625,
2,
267,
3141,
275,
291,
423,
988,
63,
1080,
11,
17,
267,
340,
440,
291,
423,
3159,
63,
890,
26,
288,
367,
1478,
315,
7975,
14,
835,
8,
2923,
304,
355,
862,
26,
490,
901,
275,
291,
59,
1080,
61,
490,
3141,
847,
413,
355,
871,
15626,
792,
26,
490,
2059,
267,
372,
3141,
339,
347,
636,
6134,
721,
277,
12,
1478,
304,
267,
862,
26,
288,
901,
275,
291,
59,
1080,
61,
288,
372,
715,
267,
871,
15626,
792,
26,
288,
372,
756,
339,
347,
636,
6095,
721,
277,
12,
1478,
304,
267,
408,
267,
2372,
282,
901,
402,
314,
1625,
14,
1803,
282,
901,
12,
503,
746,
15626,
792,
267,
1919,
340,
314,
901,
3181,
1133,
2187,
14,
267,
408,
267,
862,
26,
288,
574,
275,
291,
423,
1637,
59,
1080,
61,
267,
871,
4067,
26,
288,
862,
26,
355,
574,
275,
291,
14,
698,
409,
59,
277,
423,
908,
450,
1478,
61,
288,
871,
15626,
792,
26,
355,
291,
423,
3159,
63,
890,
275,
715,
355,
746,
288,
291,
423,
1637,
59,
1080,
61,
275,
574,
288,
291,
423,
988,
63,
1080,
275,
1390,
8,
1080,
12,
291,
423,
988,
63,
1080,
9,
267,
372,
574,
339,
347,
636,
1661,
721,
277,
304,
267,
408,
267,
23989,
315,
314,
1504,
315,
3932,
1478,
1865,
26,
901,
59,
16,
467,
901,
59,
17,
467,
2263,
267,
408,
267,
367,
1478,
315,
7975,
14,
835,
8,
16,
304,
288,
862,
26,
355,
1995,
291,
59,
1080,
61,
288,
871,
15626,
792,
26,
355,
746,
10852,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alan94jimenez/modified-shamu
|
Documentation/networking/cxacru-cf.py
|
14668
|
1626
|
#!/usr/bin/env python
# Copyright 2009 Simon Arlott
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Usage: cxacru-cf.py < cxacru-cf.bin
# Output: values string suitable for the sysfs adsl_config attribute
#
# Warning: cxacru-cf.bin with MD5 hash cdbac2689969d5ed5d4850f117702110
# contains mis-aligned values which will stop the modem from being able
# to make a connection. If the first and last two bytes are removed then
# the values become valid, but the modulation will be forced to ANSI
# T1.413 only which may not be appropriate.
#
# The original binary format is a packed list of le32 values.
import sys
import struct
i = 0
while True:
buf = sys.stdin.read(4)
if len(buf) == 0:
break
elif len(buf) != 4:
sys.stdout.write("\n")
sys.stderr.write("Error: read {0} not 4 bytes\n".format(len(buf)))
sys.exit(1)
if i > 0:
sys.stdout.write(" ")
sys.stdout.write("{0:x}={1}".format(i, struct.unpack("<I", buf)[0]))
i += 1
sys.stdout.write("\n")
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
8937,
10751,
265,
1952,
1653,
84,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8155,
199,
3,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
11028,
26,
286,
10104,
6558,
13,
2177,
14,
647,
665,
286,
10104,
6558,
13,
2177,
14,
1393,
199,
3,
7242,
26,
1338,
1059,
11233,
367,
314,
984,
2319,
282,
795,
76,
63,
888,
2225,
199,
3,
199,
3,
15902,
26,
286,
10104,
6558,
13,
2177,
14,
1393,
543,
15830,
21,
2631,
286,
697,
645,
13731,
1020,
1876,
68,
21,
379,
21,
68,
2006,
1400,
70,
845,
1138,
996,
6019,
199,
3,
3509,
3201,
13,
19175,
1338,
1314,
911,
3631,
314,
818,
77,
687,
3769,
7688,
199,
3,
370,
1852,
282,
1950,
14,
982,
314,
1642,
436,
2061,
2877,
2783,
787,
4829,
2066,
199,
3,
314,
1338,
8649,
1686,
12,
1325,
314,
3413,
5332,
911,
506,
19565,
370,
25600,
199,
3,
377,
17,
14,
23663,
1454,
1314,
1443,
440,
506,
5827,
14,
199,
3,
199,
3,
710,
3379,
3366,
1475,
365,
282,
13170,
769,
402,
1026,
708,
1338,
14,
199,
199,
646,
984,
199,
646,
2702,
199,
199,
73,
275,
378,
199,
6710,
715,
26,
199,
198,
1436,
275,
984,
14,
6626,
14,
739,
8,
20,
9,
421,
198,
692,
822,
8,
1436,
9,
508,
378,
26,
507,
198,
4785,
199,
198,
4164,
822,
8,
1436,
9,
1137,
841,
26,
507,
198,
1274,
14,
2703,
14,
952,
4582,
78,
531,
507,
198,
1274,
14,
3083,
14,
952,
480,
547,
26,
1586,
469,
16,
93,
440,
841,
2783,
60,
78,
1674,
908,
8,
552,
8,
1436,
1724,
507,
198,
1274,
14,
2224,
8,
17,
9,
421,
198,
692,
284,
690,
378,
26,
507,
198,
1274,
14,
2703,
14,
952,
480,
6099,
199,
198,
1274,
14,
2703,
14,
952,
13076,
16,
26,
88,
93,
3126,
17,
5469,
908,
8,
73,
12,
2702,
14,
5301,
6757,
41,
401,
4123,
2788,
16,
2459,
199,
198,
73,
847,
413,
199,
199,
1274,
14,
2703,
14,
952,
4582,
78,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
8937,
10751,
265,
1952,
1653,
84,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8155,
199,
3,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
11028,
26,
286,
10104,
6558,
13,
2177,
14,
647,
665,
286,
10104,
6558,
13,
2177,
14,
1393,
199,
3,
7242,
26,
1338,
1059,
11233,
367,
314,
984,
2319,
282,
795,
76,
63,
888,
2225,
199,
3,
199,
3,
15902,
26,
286,
10104,
6558,
13,
2177,
14,
1393,
543,
15830,
21,
2631,
286,
697,
645,
13731,
1020,
1876,
68,
21,
379,
21,
68,
2006,
1400,
70,
845,
1138,
996,
6019,
199,
3,
3509,
3201,
13,
19175,
1338,
1314,
911,
3631,
314,
818,
77,
687,
3769,
7688,
199,
3,
370,
1852,
282,
1950,
14,
982,
314,
1642,
436,
2061,
2877,
2783,
787,
4829,
2066,
199,
3,
314,
1338,
8649,
1686,
12,
1325,
314,
3413,
5332,
911,
506,
19565,
370,
25600,
199,
3,
377,
17,
14,
23663,
1454,
1314,
1443,
440,
506,
5827,
14,
199,
3,
199,
3,
710,
3379,
3366,
1475,
365,
282,
13170,
769,
402,
1026,
708,
1338,
14,
199,
199,
646,
984,
199,
646,
2702,
199,
199,
73,
275,
378,
199,
6710,
715,
26,
199,
198,
1436,
275,
984,
14,
6626,
14,
739,
8,
20,
9,
421,
198,
692,
822,
8,
1436,
9,
508,
378,
26,
507,
198,
4785,
199,
198,
4164,
822,
8,
1436,
9,
1137,
841,
26,
507,
198,
1274,
14,
2703,
14,
952,
4582,
78,
531,
507,
198,
1274,
14,
3083,
14,
952,
480,
547,
26,
1586,
469,
16,
93,
440,
841,
2783,
60,
78,
1674,
908,
8,
552,
8,
1436,
1724,
507,
198,
1274,
14,
2224,
8,
17,
9,
421,
198,
692,
284,
690,
378,
26,
507,
198,
1274,
14,
2703,
14,
952,
480,
6099,
199,
198,
1274,
14,
2703,
14,
952,
13076,
16,
26,
88,
93,
3126,
17,
5469,
908,
8,
73,
12,
2702,
14,
5301,
6757,
41,
401,
4123,
2788,
16,
2459,
199,
198,
73,
847,
413,
199,
199,
1274,
14,
2703,
14,
952,
4582,
78,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
epa/sqlalchemy
|
test/orm/test_bulk.py
|
11
|
15200
|
from sqlalchemy import testing
from sqlalchemy.testing import eq_
from sqlalchemy.testing.schema import Table, Column
from sqlalchemy.testing import fixtures
from sqlalchemy import Integer, String, ForeignKey, FetchedValue
from sqlalchemy.orm import mapper, Session
from sqlalchemy.testing.assertsql import CompiledSQL
from test.orm import _fixtures
class BulkTest(testing.AssertsExecutionResults):
run_inserts = None
run_define_tables = 'each'
class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest):
@classmethod
def setup_mappers(cls):
User, Address = cls.classes("User", "Address")
u, a = cls.tables("users", "addresses")
mapper(User, u)
mapper(Address, a)
def test_bulk_save_return_defaults(self):
User, = self.classes("User",)
s = Session()
objects = [
User(name="u1"),
User(name="u2"),
User(name="u3")
]
assert 'id' not in objects[0].__dict__
with self.sql_execution_asserter() as asserter:
s.bulk_save_objects(objects, return_defaults=True)
asserter.assert_(
CompiledSQL(
"INSERT INTO users (name) VALUES (:name)",
[{'name': 'u1'}]
),
CompiledSQL(
"INSERT INTO users (name) VALUES (:name)",
[{'name': 'u2'}]
),
CompiledSQL(
"INSERT INTO users (name) VALUES (:name)",
[{'name': 'u3'}]
),
)
eq_(objects[0].__dict__['id'], 1)
def test_bulk_save_no_defaults(self):
User, = self.classes("User",)
s = Session()
objects = [
User(name="u1"),
User(name="u2"),
User(name="u3")
]
assert 'id' not in objects[0].__dict__
with self.sql_execution_asserter() as asserter:
s.bulk_save_objects(objects)
asserter.assert_(
CompiledSQL(
"INSERT INTO users (name) VALUES (:name)",
[{'name': 'u1'}, {'name': 'u2'}, {'name': 'u3'}]
),
)
assert 'id' not in objects[0].__dict__
def test_bulk_save_updated_include_unchanged(self):
User, = self.classes("User",)
s = Session(expire_on_commit=False)
objects = [
User(name="u1"),
User(name="u2"),
User(name="u3")
]
s.add_all(objects)
s.commit()
objects[0].name = 'u1new'
objects[2].name = 'u3new'
s = Session()
with self.sql_execution_asserter() as asserter:
s.bulk_save_objects(objects, update_changed_only=False)
asserter.assert_(
CompiledSQL(
"UPDATE users SET name=:name WHERE "
"users.id = :users_id",
[{'users_id': 1, 'name': 'u1new'},
{'users_id': 2, 'name': 'u2'},
{'users_id': 3, 'name': 'u3new'}]
)
)
def test_bulk_update(self):
User, = self.classes("User",)
s = Session(expire_on_commit=False)
objects = [
User(name="u1"),
User(name="u2"),
User(name="u3")
]
s.add_all(objects)
s.commit()
s = Session()
with self.sql_execution_asserter() as asserter:
s.bulk_update_mappings(
User,
[{'id': 1, 'name': 'u1new'},
{'id': 2, 'name': 'u2'},
{'id': 3, 'name': 'u3new'}]
)
asserter.assert_(
CompiledSQL(
"UPDATE users SET name=:name WHERE users.id = :users_id",
[{'users_id': 1, 'name': 'u1new'},
{'users_id': 2, 'name': 'u2'},
{'users_id': 3, 'name': 'u3new'}]
)
)
def test_bulk_insert(self):
User, = self.classes("User",)
s = Session()
with self.sql_execution_asserter() as asserter:
s.bulk_insert_mappings(
User,
[{'id': 1, 'name': 'u1new'},
{'id': 2, 'name': 'u2'},
{'id': 3, 'name': 'u3new'}]
)
asserter.assert_(
CompiledSQL(
"INSERT INTO users (id, name) VALUES (:id, :name)",
[{'id': 1, 'name': 'u1new'},
{'id': 2, 'name': 'u2'},
{'id': 3, 'name': 'u3new'}]
)
)
class BulkUDPostfetchTest(BulkTest, fixtures.MappedTest):
@classmethod
def define_tables(cls, metadata):
Table(
'a', metadata,
Column(
'id', Integer,
primary_key=True,
test_needs_autoincrement=True),
Column('x', Integer),
Column('y', Integer,
server_default=FetchedValue(),
server_onupdate=FetchedValue()))
@classmethod
def setup_classes(cls):
class A(cls.Comparable):
pass
@classmethod
def setup_mappers(cls):
A = cls.classes.A
a = cls.tables.a
mapper(A, a)
def test_insert_w_fetch(self):
A = self.classes.A
s = Session()
a1 = A(x=1)
s.bulk_save_objects([a1])
s.commit()
def test_update_w_fetch(self):
A = self.classes.A
s = Session()
a1 = A(x=1, y=2)
s.add(a1)
s.commit()
eq_(a1.id, 1) # force a load
a1.x = 5
s.expire(a1, ['y'])
assert 'y' not in a1.__dict__
s.bulk_save_objects([a1])
s.commit()
eq_(a1.x, 5)
eq_(a1.y, 2)
class BulkInheritanceTest(BulkTest, fixtures.MappedTest):
@classmethod
def define_tables(cls, metadata):
Table(
'people', metadata,
Column(
'person_id', Integer,
primary_key=True,
test_needs_autoincrement=True),
Column('name', String(50)),
Column('type', String(30)))
Table(
'engineers', metadata,
Column(
'person_id', Integer,
ForeignKey('people.person_id'),
primary_key=True),
Column('status', String(30)),
Column('primary_language', String(50)))
Table(
'managers', metadata,
Column(
'person_id', Integer,
ForeignKey('people.person_id'),
primary_key=True),
Column('status', String(30)),
Column('manager_name', String(50)))
Table(
'boss', metadata,
Column(
'boss_id', Integer,
ForeignKey('managers.person_id'),
primary_key=True),
Column('golf_swing', String(30)))
@classmethod
def setup_classes(cls):
class Base(cls.Comparable):
pass
class Person(Base):
pass
class Engineer(Person):
pass
class Manager(Person):
pass
class Boss(Manager):
pass
@classmethod
def setup_mappers(cls):
Person, Engineer, Manager, Boss = \
cls.classes('Person', 'Engineer', 'Manager', 'Boss')
p, e, m, b = cls.tables('people', 'engineers', 'managers', 'boss')
mapper(
Person, p, polymorphic_on=p.c.type,
polymorphic_identity='person')
mapper(Engineer, e, inherits=Person, polymorphic_identity='engineer')
mapper(Manager, m, inherits=Person, polymorphic_identity='manager')
mapper(Boss, b, inherits=Manager, polymorphic_identity='boss')
def test_bulk_save_joined_inh_return_defaults(self):
Person, Engineer, Manager, Boss = \
self.classes('Person', 'Engineer', 'Manager', 'Boss')
s = Session()
objects = [
Manager(name='m1', status='s1', manager_name='mn1'),
Engineer(name='e1', status='s2', primary_language='l1'),
Engineer(name='e2', status='s3', primary_language='l2'),
Boss(
name='b1', status='s3', manager_name='mn2',
golf_swing='g1')
]
assert 'person_id' not in objects[0].__dict__
with self.sql_execution_asserter() as asserter:
s.bulk_save_objects(objects, return_defaults=True)
asserter.assert_(
CompiledSQL(
"INSERT INTO people (name, type) VALUES (:name, :type)",
[{'type': 'manager', 'name': 'm1'}]
),
CompiledSQL(
"INSERT INTO managers (person_id, status, manager_name) "
"VALUES (:person_id, :status, :manager_name)",
[{'person_id': 1, 'status': 's1', 'manager_name': 'mn1'}]
),
CompiledSQL(
"INSERT INTO people (name, type) VALUES (:name, :type)",
[{'type': 'engineer', 'name': 'e1'}]
),
CompiledSQL(
"INSERT INTO people (name, type) VALUES (:name, :type)",
[{'type': 'engineer', 'name': 'e2'}]
),
CompiledSQL(
"INSERT INTO engineers (person_id, status, primary_language) "
"VALUES (:person_id, :status, :primary_language)",
[{'person_id': 2, 'status': 's2', 'primary_language': 'l1'},
{'person_id': 3, 'status': 's3', 'primary_language': 'l2'}]
),
CompiledSQL(
"INSERT INTO people (name, type) VALUES (:name, :type)",
[{'type': 'boss', 'name': 'b1'}]
),
CompiledSQL(
"INSERT INTO managers (person_id, status, manager_name) "
"VALUES (:person_id, :status, :manager_name)",
[{'person_id': 4, 'status': 's3', 'manager_name': 'mn2'}]
),
CompiledSQL(
"INSERT INTO boss (boss_id, golf_swing) VALUES "
"(:boss_id, :golf_swing)",
[{'boss_id': 4, 'golf_swing': 'g1'}]
)
)
eq_(objects[0].__dict__['person_id'], 1)
eq_(objects[3].__dict__['person_id'], 4)
eq_(objects[3].__dict__['boss_id'], 4)
def test_bulk_save_joined_inh_no_defaults(self):
Person, Engineer, Manager, Boss = \
self.classes('Person', 'Engineer', 'Manager', 'Boss')
s = Session()
with self.sql_execution_asserter() as asserter:
s.bulk_save_objects([
Manager(
person_id=1,
name='m1', status='s1', manager_name='mn1'),
Engineer(
person_id=2,
name='e1', status='s2', primary_language='l1'),
Engineer(
person_id=3,
name='e2', status='s3', primary_language='l2'),
Boss(
person_id=4, boss_id=4,
name='b1', status='s3', manager_name='mn2',
golf_swing='g1')
],
)
# the only difference here is that common classes are grouped together.
# at the moment it doesn't lump all the "people" tables from
# different classes together.
asserter.assert_(
CompiledSQL(
"INSERT INTO people (person_id, name, type) VALUES "
"(:person_id, :name, :type)",
[{'person_id': 1, 'type': 'manager', 'name': 'm1'}]
),
CompiledSQL(
"INSERT INTO managers (person_id, status, manager_name) "
"VALUES (:person_id, :status, :manager_name)",
[{'status': 's1', 'person_id': 1, 'manager_name': 'mn1'}]
),
CompiledSQL(
"INSERT INTO people (person_id, name, type) VALUES "
"(:person_id, :name, :type)",
[{'person_id': 2, 'type': 'engineer', 'name': 'e1'},
{'person_id': 3, 'type': 'engineer', 'name': 'e2'}]
),
CompiledSQL(
"INSERT INTO engineers (person_id, status, primary_language) "
"VALUES (:person_id, :status, :primary_language)",
[{'person_id': 2, 'status': 's2', 'primary_language': 'l1'},
{'person_id': 3, 'status': 's3', 'primary_language': 'l2'}]
),
CompiledSQL(
"INSERT INTO people (person_id, name, type) VALUES "
"(:person_id, :name, :type)",
[{'person_id': 4, 'type': 'boss', 'name': 'b1'}]
),
CompiledSQL(
"INSERT INTO managers (person_id, status, manager_name) "
"VALUES (:person_id, :status, :manager_name)",
[{'status': 's3', 'person_id': 4, 'manager_name': 'mn2'}]
),
CompiledSQL(
"INSERT INTO boss (boss_id, golf_swing) VALUES "
"(:boss_id, :golf_swing)",
[{'boss_id': 4, 'golf_swing': 'g1'}]
)
)
def test_bulk_insert_joined_inh_return_defaults(self):
Person, Engineer, Manager, Boss = \
self.classes('Person', 'Engineer', 'Manager', 'Boss')
s = Session()
with self.sql_execution_asserter() as asserter:
s.bulk_insert_mappings(
Boss,
[
dict(
name='b1', status='s1', manager_name='mn1',
golf_swing='g1'
),
dict(
name='b2', status='s2', manager_name='mn2',
golf_swing='g2'
),
dict(
name='b3', status='s3', manager_name='mn3',
golf_swing='g3'
),
], return_defaults=True
)
asserter.assert_(
CompiledSQL(
"INSERT INTO people (name) VALUES (:name)",
[{'name': 'b1'}]
),
CompiledSQL(
"INSERT INTO people (name) VALUES (:name)",
[{'name': 'b2'}]
),
CompiledSQL(
"INSERT INTO people (name) VALUES (:name)",
[{'name': 'b3'}]
),
CompiledSQL(
"INSERT INTO managers (person_id, status, manager_name) "
"VALUES (:person_id, :status, :manager_name)",
[{'person_id': 1, 'status': 's1', 'manager_name': 'mn1'},
{'person_id': 2, 'status': 's2', 'manager_name': 'mn2'},
{'person_id': 3, 'status': 's3', 'manager_name': 'mn3'}]
),
CompiledSQL(
"INSERT INTO boss (boss_id, golf_swing) VALUES "
"(:boss_id, :golf_swing)",
[{'golf_swing': 'g1', 'boss_id': 1},
{'golf_swing': 'g2', 'boss_id': 2},
{'golf_swing': 'g3', 'boss_id': 3}]
)
)
|
mit
|
[
504,
8335,
492,
5343,
199,
504,
8335,
14,
4776,
492,
3850,
63,
199,
504,
8335,
14,
4776,
14,
3629,
492,
6957,
12,
4996,
199,
504,
8335,
14,
4776,
492,
15188,
199,
504,
8335,
492,
7225,
12,
2624,
12,
12718,
12,
481,
13534,
1110,
199,
504,
8335,
14,
1025,
492,
7796,
12,
8596,
199,
504,
8335,
14,
4776,
14,
479,
3009,
492,
3599,
1672,
4657,
199,
504,
511,
14,
1025,
492,
485,
8769,
421,
199,
533,
699,
6368,
774,
8,
4776,
14,
9699,
83,
11310,
6579,
304,
272,
1255,
63,
3176,
83,
275,
488,
272,
1255,
63,
4640,
63,
5987,
275,
283,
10885,
7,
421,
199,
533,
699,
6368,
9971,
4152,
774,
8,
26033,
774,
12,
485,
8769,
14,
12812,
774,
304,
339,
768,
3744,
272,
347,
3272,
63,
24469,
8,
1886,
304,
267,
2876,
12,
9906,
275,
843,
14,
2888,
480,
1899,
401,
298,
1476,
531,
267,
399,
12,
282,
275,
843,
14,
5987,
480,
3707,
401,
298,
7423,
531,
398,
7796,
8,
1899,
12,
399,
9,
267,
7796,
8,
1476,
12,
282,
9,
339,
347,
511,
63,
9377,
63,
2117,
63,
1107,
63,
4322,
8,
277,
304,
267,
2876,
12,
275,
291,
14,
2888,
480,
1899,
26360,
398,
308,
275,
8596,
342,
267,
2251,
275,
359,
288,
2876,
8,
354,
628,
85,
17,
1288,
288,
2876,
8,
354,
628,
85,
18,
1288,
288,
2876,
8,
354,
628,
85,
19,
531,
267,
1622,
267,
702,
283,
344,
7,
440,
315,
2251,
59,
16,
17979,
807,
363,
398,
543,
291,
14,
3009,
63,
9416,
63,
305,
332,
351,
342,
465,
465,
332,
351,
26,
288,
308,
14,
9377,
63,
2117,
63,
1462,
8,
1462,
12,
372,
63,
4322,
29,
549,
9,
398,
465,
332,
351,
14,
479,
2531,
288,
3599,
1672,
4657,
8,
355,
298,
10258,
12872,
4390,
334,
354,
9,
13992,
18479,
354,
4186,
355,
9016,
354,
356,
283,
85,
17,
20623,
288,
2318,
288,
3599,
1672,
4657,
8,
355,
298,
10258,
12872,
4390,
334,
354,
9,
13992,
18479,
354,
4186,
355,
9016,
354,
356,
283,
85,
18,
20623,
288,
2318,
288,
3599,
1672,
4657,
8,
355,
298,
10258,
12872,
4390,
334,
354,
9,
13992,
18479,
354,
4186,
355,
9016,
354,
356,
283,
85,
19,
20623,
288,
2318,
267,
776,
267,
3850,
2531,
1462,
59,
16,
17979,
807,
23010,
344,
995,
413,
9,
339,
347,
511,
63,
9377,
63,
2117,
63,
889,
63,
4322,
8,
277,
304,
267,
2876,
12,
275,
291,
14,
2888,
480,
1899,
26360,
398,
308,
275,
8596,
342,
267,
2251,
275,
359,
288,
2876,
8,
354,
628,
85,
17,
1288,
288,
2876,
8,
354,
628,
85,
18,
1288,
288,
2876,
8,
354,
628,
85,
19,
531,
267,
1622,
267,
702,
283,
344,
7,
440,
315,
2251,
59,
16,
17979,
807,
363,
398,
543,
291,
14,
3009,
63,
9416,
63,
305,
332,
351,
342,
465,
465,
332,
351,
26,
288,
308,
14,
9377,
63,
2117,
63,
1462,
8,
1462,
9,
398,
465,
332,
351,
14,
479,
2531,
288,
3599,
1672,
4657,
8,
355,
298,
10258,
12872,
4390,
334,
354,
9,
13992,
18479,
354,
4186,
355,
9016,
354,
356,
283,
85,
17,
2267,
791,
354,
356,
283,
85,
18,
2267,
791,
354,
356,
283,
85,
19,
20623,
288,
2318,
267,
776,
267,
702,
283,
344,
7,
440,
315,
2251,
59,
16,
17979,
807,
363,
339,
347,
511,
63,
9377,
63,
2117,
63,
5334,
63,
2613,
63,
16914,
8,
277,
304,
267,
2876,
12,
275,
291,
14,
2888,
480,
1899,
26360,
398,
308,
275,
8596,
8,
14691,
63,
265,
63,
3543,
29,
797,
9,
267,
2251,
275,
359,
288,
2876,
8,
354,
628,
85,
17,
1288,
288,
2876,
8,
354,
628,
85,
18,
1288,
288,
2876,
8,
354,
628,
85,
19,
531,
267,
1622,
267,
308,
14,
525,
63,
452,
8,
1462,
9,
267,
308,
14,
3543,
342,
398,
2251,
59,
16,
1055,
354,
275,
283,
85,
17,
1222,
7,
267,
2251,
59,
18,
1055,
354,
275,
283,
85,
19,
1222,
7,
398,
308,
275,
8596,
342,
267,
543,
291,
14,
3009,
63,
9416,
63,
305,
332,
351,
342,
465,
465,
332,
351,
26,
288,
308,
14,
9377,
63,
2117,
63,
1462,
8,
1462,
12,
1678,
63,
2489,
63,
2118,
29,
797,
9,
398,
465,
332,
351,
14,
479,
2531,
288,
3599,
1672,
4657,
8,
355,
298,
10383,
4390,
11543,
536,
29,
26,
354,
6038,
298,
355,
298,
3707,
14,
344,
275,
520,
3707,
63,
344,
401,
355,
9016,
3707,
63,
344,
356,
413,
12,
283,
354,
356,
283,
85,
17,
1222,
2267,
326,
791,
3707,
63,
344,
356,
499,
12,
283,
354,
356,
283,
85,
18,
2267,
326,
791,
3707,
63,
344,
356,
650,
12,
283,
354,
356,
283,
85,
19,
1222,
20623,
288,
776,
267,
776,
339,
347,
511,
63,
9377,
63,
873,
8,
277,
304,
267,
2876,
12,
275,
291,
14,
2888,
480,
1899,
26360,
398,
308,
275,
8596,
8,
14691,
63,
265,
63,
3543,
29,
797,
9,
267,
2251,
275,
359,
288,
2876,
8,
354,
628,
85,
17,
1288,
288,
2876,
8,
354,
628,
85,
18,
1288,
288,
2876,
8,
354,
628,
85,
19,
531,
267,
1622,
267,
308,
14,
525,
63,
452,
8,
1462,
9,
267,
308,
14,
3543,
342,
398,
308,
275,
8596,
342,
267,
543,
291,
14,
3009,
63,
9416,
63,
305,
332,
351,
342,
465,
465,
332,
351,
26,
288,
308,
14,
9377,
63,
873,
63,
14632,
8,
355,
2876,
12,
355,
9016,
344,
356,
413,
12,
283,
354,
356,
283,
85,
17,
1222,
2267,
326,
791,
344,
356,
499,
12,
283,
354,
356,
283,
85,
18,
2267,
326,
791,
344,
356,
650,
12,
283,
354,
356,
283,
85,
19,
1222,
20623,
288,
776,
398,
465,
332,
351,
14,
479,
2531,
288,
3599,
1672,
4657,
8,
355,
298,
10383,
4390,
11543,
536,
29,
26,
354,
6038,
4390,
14,
344,
275,
520,
3707,
63,
344,
401,
355,
9016,
3707,
63,
344,
356,
413,
12,
283,
354,
356,
283,
85,
17,
1222,
2267,
326,
791,
3707,
63,
344,
356,
499,
12,
283,
354,
356,
283,
85,
18,
2267,
326,
791,
3707,
63,
344,
356,
650,
12,
283,
354,
356,
283,
85,
19,
1222,
20623,
288,
776,
267,
776,
339,
347,
511,
63,
9377,
63,
3176,
8,
277
] |
[
8335,
492,
5343,
199,
504,
8335,
14,
4776,
492,
3850,
63,
199,
504,
8335,
14,
4776,
14,
3629,
492,
6957,
12,
4996,
199,
504,
8335,
14,
4776,
492,
15188,
199,
504,
8335,
492,
7225,
12,
2624,
12,
12718,
12,
481,
13534,
1110,
199,
504,
8335,
14,
1025,
492,
7796,
12,
8596,
199,
504,
8335,
14,
4776,
14,
479,
3009,
492,
3599,
1672,
4657,
199,
504,
511,
14,
1025,
492,
485,
8769,
421,
199,
533,
699,
6368,
774,
8,
4776,
14,
9699,
83,
11310,
6579,
304,
272,
1255,
63,
3176,
83,
275,
488,
272,
1255,
63,
4640,
63,
5987,
275,
283,
10885,
7,
421,
199,
533,
699,
6368,
9971,
4152,
774,
8,
26033,
774,
12,
485,
8769,
14,
12812,
774,
304,
339,
768,
3744,
272,
347,
3272,
63,
24469,
8,
1886,
304,
267,
2876,
12,
9906,
275,
843,
14,
2888,
480,
1899,
401,
298,
1476,
531,
267,
399,
12,
282,
275,
843,
14,
5987,
480,
3707,
401,
298,
7423,
531,
398,
7796,
8,
1899,
12,
399,
9,
267,
7796,
8,
1476,
12,
282,
9,
339,
347,
511,
63,
9377,
63,
2117,
63,
1107,
63,
4322,
8,
277,
304,
267,
2876,
12,
275,
291,
14,
2888,
480,
1899,
26360,
398,
308,
275,
8596,
342,
267,
2251,
275,
359,
288,
2876,
8,
354,
628,
85,
17,
1288,
288,
2876,
8,
354,
628,
85,
18,
1288,
288,
2876,
8,
354,
628,
85,
19,
531,
267,
1622,
267,
702,
283,
344,
7,
440,
315,
2251,
59,
16,
17979,
807,
363,
398,
543,
291,
14,
3009,
63,
9416,
63,
305,
332,
351,
342,
465,
465,
332,
351,
26,
288,
308,
14,
9377,
63,
2117,
63,
1462,
8,
1462,
12,
372,
63,
4322,
29,
549,
9,
398,
465,
332,
351,
14,
479,
2531,
288,
3599,
1672,
4657,
8,
355,
298,
10258,
12872,
4390,
334,
354,
9,
13992,
18479,
354,
4186,
355,
9016,
354,
356,
283,
85,
17,
20623,
288,
2318,
288,
3599,
1672,
4657,
8,
355,
298,
10258,
12872,
4390,
334,
354,
9,
13992,
18479,
354,
4186,
355,
9016,
354,
356,
283,
85,
18,
20623,
288,
2318,
288,
3599,
1672,
4657,
8,
355,
298,
10258,
12872,
4390,
334,
354,
9,
13992,
18479,
354,
4186,
355,
9016,
354,
356,
283,
85,
19,
20623,
288,
2318,
267,
776,
267,
3850,
2531,
1462,
59,
16,
17979,
807,
23010,
344,
995,
413,
9,
339,
347,
511,
63,
9377,
63,
2117,
63,
889,
63,
4322,
8,
277,
304,
267,
2876,
12,
275,
291,
14,
2888,
480,
1899,
26360,
398,
308,
275,
8596,
342,
267,
2251,
275,
359,
288,
2876,
8,
354,
628,
85,
17,
1288,
288,
2876,
8,
354,
628,
85,
18,
1288,
288,
2876,
8,
354,
628,
85,
19,
531,
267,
1622,
267,
702,
283,
344,
7,
440,
315,
2251,
59,
16,
17979,
807,
363,
398,
543,
291,
14,
3009,
63,
9416,
63,
305,
332,
351,
342,
465,
465,
332,
351,
26,
288,
308,
14,
9377,
63,
2117,
63,
1462,
8,
1462,
9,
398,
465,
332,
351,
14,
479,
2531,
288,
3599,
1672,
4657,
8,
355,
298,
10258,
12872,
4390,
334,
354,
9,
13992,
18479,
354,
4186,
355,
9016,
354,
356,
283,
85,
17,
2267,
791,
354,
356,
283,
85,
18,
2267,
791,
354,
356,
283,
85,
19,
20623,
288,
2318,
267,
776,
267,
702,
283,
344,
7,
440,
315,
2251,
59,
16,
17979,
807,
363,
339,
347,
511,
63,
9377,
63,
2117,
63,
5334,
63,
2613,
63,
16914,
8,
277,
304,
267,
2876,
12,
275,
291,
14,
2888,
480,
1899,
26360,
398,
308,
275,
8596,
8,
14691,
63,
265,
63,
3543,
29,
797,
9,
267,
2251,
275,
359,
288,
2876,
8,
354,
628,
85,
17,
1288,
288,
2876,
8,
354,
628,
85,
18,
1288,
288,
2876,
8,
354,
628,
85,
19,
531,
267,
1622,
267,
308,
14,
525,
63,
452,
8,
1462,
9,
267,
308,
14,
3543,
342,
398,
2251,
59,
16,
1055,
354,
275,
283,
85,
17,
1222,
7,
267,
2251,
59,
18,
1055,
354,
275,
283,
85,
19,
1222,
7,
398,
308,
275,
8596,
342,
267,
543,
291,
14,
3009,
63,
9416,
63,
305,
332,
351,
342,
465,
465,
332,
351,
26,
288,
308,
14,
9377,
63,
2117,
63,
1462,
8,
1462,
12,
1678,
63,
2489,
63,
2118,
29,
797,
9,
398,
465,
332,
351,
14,
479,
2531,
288,
3599,
1672,
4657,
8,
355,
298,
10383,
4390,
11543,
536,
29,
26,
354,
6038,
298,
355,
298,
3707,
14,
344,
275,
520,
3707,
63,
344,
401,
355,
9016,
3707,
63,
344,
356,
413,
12,
283,
354,
356,
283,
85,
17,
1222,
2267,
326,
791,
3707,
63,
344,
356,
499,
12,
283,
354,
356,
283,
85,
18,
2267,
326,
791,
3707,
63,
344,
356,
650,
12,
283,
354,
356,
283,
85,
19,
1222,
20623,
288,
776,
267,
776,
339,
347,
511,
63,
9377,
63,
873,
8,
277,
304,
267,
2876,
12,
275,
291,
14,
2888,
480,
1899,
26360,
398,
308,
275,
8596,
8,
14691,
63,
265,
63,
3543,
29,
797,
9,
267,
2251,
275,
359,
288,
2876,
8,
354,
628,
85,
17,
1288,
288,
2876,
8,
354,
628,
85,
18,
1288,
288,
2876,
8,
354,
628,
85,
19,
531,
267,
1622,
267,
308,
14,
525,
63,
452,
8,
1462,
9,
267,
308,
14,
3543,
342,
398,
308,
275,
8596,
342,
267,
543,
291,
14,
3009,
63,
9416,
63,
305,
332,
351,
342,
465,
465,
332,
351,
26,
288,
308,
14,
9377,
63,
873,
63,
14632,
8,
355,
2876,
12,
355,
9016,
344,
356,
413,
12,
283,
354,
356,
283,
85,
17,
1222,
2267,
326,
791,
344,
356,
499,
12,
283,
354,
356,
283,
85,
18,
2267,
326,
791,
344,
356,
650,
12,
283,
354,
356,
283,
85,
19,
1222,
20623,
288,
776,
398,
465,
332,
351,
14,
479,
2531,
288,
3599,
1672,
4657,
8,
355,
298,
10383,
4390,
11543,
536,
29,
26,
354,
6038,
4390,
14,
344,
275,
520,
3707,
63,
344,
401,
355,
9016,
3707,
63,
344,
356,
413,
12,
283,
354,
356,
283,
85,
17,
1222,
2267,
326,
791,
3707,
63,
344,
356,
499,
12,
283,
354,
356,
283,
85,
18,
2267,
326,
791,
3707,
63,
344,
356,
650,
12,
283,
354,
356,
283,
85,
19,
1222,
20623,
288,
776,
267,
776,
339,
347,
511,
63,
9377,
63,
3176,
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,
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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
] |
twz915/django
|
tests/m2m_multiple/tests.py
|
133
|
2329
|
from datetime import datetime
from django.test import TestCase
from .models import Article, Category
class M2MMultipleTests(TestCase):
def test_multiple(self):
c1, c2, c3, c4 = [
Category.objects.create(name=name)
for name in ["Sports", "News", "Crime", "Life"]
]
a1 = Article.objects.create(
headline="Parrot steals", pub_date=datetime(2005, 11, 27)
)
a1.primary_categories.add(c2, c3)
a1.secondary_categories.add(c4)
a2 = Article.objects.create(
headline="Parrot runs", pub_date=datetime(2005, 11, 28)
)
a2.primary_categories.add(c1, c2)
a2.secondary_categories.add(c4)
self.assertQuerysetEqual(
a1.primary_categories.all(), [
"Crime",
"News",
],
lambda c: c.name
)
self.assertQuerysetEqual(
a2.primary_categories.all(), [
"News",
"Sports",
],
lambda c: c.name
)
self.assertQuerysetEqual(
a1.secondary_categories.all(), [
"Life",
],
lambda c: c.name
)
self.assertQuerysetEqual(
c1.primary_article_set.all(), [
"Parrot runs",
],
lambda a: a.headline
)
self.assertQuerysetEqual(
c1.secondary_article_set.all(), []
)
self.assertQuerysetEqual(
c2.primary_article_set.all(), [
"Parrot steals",
"Parrot runs",
],
lambda a: a.headline
)
self.assertQuerysetEqual(
c2.secondary_article_set.all(), []
)
self.assertQuerysetEqual(
c3.primary_article_set.all(), [
"Parrot steals",
],
lambda a: a.headline
)
self.assertQuerysetEqual(
c3.secondary_article_set.all(), []
)
self.assertQuerysetEqual(
c4.primary_article_set.all(), []
)
self.assertQuerysetEqual(
c4.secondary_article_set.all(), [
"Parrot steals",
"Parrot runs",
],
lambda a: a.headline
)
|
bsd-3-clause
|
[
504,
2197,
492,
2197,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
8281,
12,
13573,
421,
199,
533,
603,
18,
3218,
2496,
2925,
8,
1746,
304,
272,
347,
511,
63,
6048,
8,
277,
304,
267,
286,
17,
12,
286,
18,
12,
286,
19,
12,
286,
20,
275,
359,
288,
13573,
14,
1462,
14,
981,
8,
354,
29,
354,
9,
288,
367,
536,
315,
2097,
51,
5203,
401,
298,
24730,
401,
298,
35,
322,
278,
401,
298,
22637,
937,
267,
1622,
398,
282,
17,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
1262,
4571,
20345,
2551,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
8087,
9,
267,
776,
267,
282,
17,
14,
3327,
63,
8906,
14,
525,
8,
67,
18,
12,
286,
19,
9,
267,
282,
17,
14,
12371,
63,
8906,
14,
525,
8,
67,
20,
9,
398,
282,
18,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
1262,
4571,
7858,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
7294,
9,
267,
776,
267,
282,
18,
14,
3327,
63,
8906,
14,
525,
8,
67,
17,
12,
286,
18,
9,
267,
282,
18,
14,
12371,
63,
8906,
14,
525,
8,
67,
20,
9,
398,
291,
14,
7108,
8,
288,
282,
17,
14,
3327,
63,
8906,
14,
452,
1062,
359,
355,
298,
35,
322,
278,
401,
355,
298,
24730,
401,
288,
2156,
288,
2400,
286,
26,
286,
14,
354,
267,
776,
267,
291,
14,
7108,
8,
288,
282,
18,
14,
3327,
63,
8906,
14,
452,
1062,
359,
355,
298,
24730,
401,
355,
298,
51,
5203,
401,
288,
2156,
288,
2400,
286,
26,
286,
14,
354,
267,
776,
267,
291,
14,
7108,
8,
288,
282,
17,
14,
12371,
63,
8906,
14,
452,
1062,
359,
355,
298,
22637,
401,
288,
2156,
288,
2400,
286,
26,
286,
14,
354,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
17,
14,
3327,
63,
6934,
63,
409,
14,
452,
1062,
359,
355,
298,
1262,
4571,
7858,
401,
288,
2156,
288,
2400,
282,
26,
282,
14,
11268,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
17,
14,
12371,
63,
6934,
63,
409,
14,
452,
1062,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
18,
14,
3327,
63,
6934,
63,
409,
14,
452,
1062,
359,
355,
298,
1262,
4571,
20345,
2551,
401,
355,
298,
1262,
4571,
7858,
401,
288,
2156,
288,
2400,
282,
26,
282,
14,
11268,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
18,
14,
12371,
63,
6934,
63,
409,
14,
452,
1062,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
19,
14,
3327,
63,
6934,
63,
409,
14,
452,
1062,
359,
355,
298,
1262,
4571,
20345,
2551,
401,
288,
2156,
288,
2400,
282,
26,
282,
14,
11268,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
19,
14,
12371,
63,
6934,
63,
409,
14,
452,
1062,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
20,
14,
3327,
63,
6934,
63,
409,
14,
452,
1062,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
20,
14,
12371,
63,
6934,
63,
409,
14,
452,
1062,
359,
355,
298,
1262,
4571,
20345,
2551,
401,
355,
298,
1262,
4571,
7858,
401,
288,
2156,
288,
2400,
282,
26,
282,
14,
11268,
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
] |
[
2197,
492,
2197,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
8281,
12,
13573,
421,
199,
533,
603,
18,
3218,
2496,
2925,
8,
1746,
304,
272,
347,
511,
63,
6048,
8,
277,
304,
267,
286,
17,
12,
286,
18,
12,
286,
19,
12,
286,
20,
275,
359,
288,
13573,
14,
1462,
14,
981,
8,
354,
29,
354,
9,
288,
367,
536,
315,
2097,
51,
5203,
401,
298,
24730,
401,
298,
35,
322,
278,
401,
298,
22637,
937,
267,
1622,
398,
282,
17,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
1262,
4571,
20345,
2551,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
8087,
9,
267,
776,
267,
282,
17,
14,
3327,
63,
8906,
14,
525,
8,
67,
18,
12,
286,
19,
9,
267,
282,
17,
14,
12371,
63,
8906,
14,
525,
8,
67,
20,
9,
398,
282,
18,
275,
8281,
14,
1462,
14,
981,
8,
288,
21250,
628,
1262,
4571,
7858,
401,
7974,
63,
602,
29,
2083,
8,
9397,
12,
4119,
12,
7294,
9,
267,
776,
267,
282,
18,
14,
3327,
63,
8906,
14,
525,
8,
67,
17,
12,
286,
18,
9,
267,
282,
18,
14,
12371,
63,
8906,
14,
525,
8,
67,
20,
9,
398,
291,
14,
7108,
8,
288,
282,
17,
14,
3327,
63,
8906,
14,
452,
1062,
359,
355,
298,
35,
322,
278,
401,
355,
298,
24730,
401,
288,
2156,
288,
2400,
286,
26,
286,
14,
354,
267,
776,
267,
291,
14,
7108,
8,
288,
282,
18,
14,
3327,
63,
8906,
14,
452,
1062,
359,
355,
298,
24730,
401,
355,
298,
51,
5203,
401,
288,
2156,
288,
2400,
286,
26,
286,
14,
354,
267,
776,
267,
291,
14,
7108,
8,
288,
282,
17,
14,
12371,
63,
8906,
14,
452,
1062,
359,
355,
298,
22637,
401,
288,
2156,
288,
2400,
286,
26,
286,
14,
354,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
17,
14,
3327,
63,
6934,
63,
409,
14,
452,
1062,
359,
355,
298,
1262,
4571,
7858,
401,
288,
2156,
288,
2400,
282,
26,
282,
14,
11268,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
17,
14,
12371,
63,
6934,
63,
409,
14,
452,
1062,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
18,
14,
3327,
63,
6934,
63,
409,
14,
452,
1062,
359,
355,
298,
1262,
4571,
20345,
2551,
401,
355,
298,
1262,
4571,
7858,
401,
288,
2156,
288,
2400,
282,
26,
282,
14,
11268,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
18,
14,
12371,
63,
6934,
63,
409,
14,
452,
1062,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
19,
14,
3327,
63,
6934,
63,
409,
14,
452,
1062,
359,
355,
298,
1262,
4571,
20345,
2551,
401,
288,
2156,
288,
2400,
282,
26,
282,
14,
11268,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
19,
14,
12371,
63,
6934,
63,
409,
14,
452,
1062,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
20,
14,
3327,
63,
6934,
63,
409,
14,
452,
1062,
942,
267,
776,
267,
291,
14,
7108,
8,
288,
286,
20,
14,
12371,
63,
6934,
63,
409,
14,
452,
1062,
359,
355,
298,
1262,
4571,
20345,
2551,
401,
355,
298,
1262,
4571,
7858,
401,
288,
2156,
288,
2400,
282,
26,
282,
14,
11268,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
saintdragon2/python-3-lecture-2015
|
civil-final/2nd_presentation/11조/pygame/tests/sprite_test.py
|
11
|
36714
|
#################################### IMPORTS ###################################
# -*- encoding: utf-8 -*-
if __name__ == '__main__':
import sys
import os
pkg_dir = os.path.split(os.path.abspath(__file__))[0]
parent_dir, pkg_name = os.path.split(pkg_dir)
is_pygame_pkg = (pkg_name == 'tests' and
os.path.split(parent_dir)[1] == 'pygame')
if not is_pygame_pkg:
sys.path.insert(0, parent_dir)
else:
is_pygame_pkg = __name__.startswith('pygame.tests.')
if is_pygame_pkg:
from pygame.tests.test_utils \
import test_not_implemented, unordered_equality, unittest
else:
from test.test_utils \
import test_not_implemented, unordered_equality, unittest
import pygame
from pygame import sprite
################################# MODULE LEVEL #################################
class SpriteModuleTest( unittest.TestCase ):
pass
######################### SPRITECOLLIDE FUNCTIONS TEST #########################
class SpriteCollideTest( unittest.TestCase ):
def setUp(self):
self.ag = sprite.AbstractGroup()
self.ag2 = sprite.AbstractGroup()
self.s1 = sprite.Sprite(self.ag)
self.s2 = sprite.Sprite(self.ag2)
self.s3 = sprite.Sprite(self.ag2)
self.s1.image = pygame.Surface((50,10), pygame.SRCALPHA, 32)
self.s2.image = pygame.Surface((10,10), pygame.SRCALPHA, 32)
self.s3.image = pygame.Surface((10,10), pygame.SRCALPHA, 32)
self.s1.rect = self.s1.image.get_rect()
self.s2.rect = self.s2.image.get_rect()
self.s3.rect = self.s3.image.get_rect()
self.s2.rect.move_ip(40, 0)
self.s3.rect.move_ip(100, 100)
def test_spritecollide__works_if_collided_cb_is_None(self):
# Test that sprites collide without collided function.
self.assertEqual (
sprite.spritecollide (
self.s1, self.ag2, dokill = False, collided = None
),
[self.s2]
)
def test_spritecollide__works_if_collided_cb_not_passed(self):
# Should also work when collided function isn't passed at all.
self.assertEqual(sprite.spritecollide (
self.s1, self.ag2, dokill = False),
[self.s2]
)
def test_spritecollide__collided_must_be_a_callable(self):
# Need to pass a callable.
self.assertRaises (
TypeError,
sprite.spritecollide, self.s1, self.ag2, dokill = False, collided = 1
)
def test_spritecollide__collided_defaults_to_collide_rect(self):
# collide_rect should behave the same as default.
self.assertEqual (
sprite.spritecollide (
self.s1, self.ag2, dokill = False, collided = sprite.collide_rect
),
[self.s2]
)
def test_collide_rect_ratio__ratio_of_one_like_default(self):
# collide_rect_ratio should behave the same as default at a 1.0 ratio.
self.assertEqual (
sprite.spritecollide (
self.s1, self.ag2, dokill = False,
collided = sprite.collide_rect_ratio(1.0)
),
[self.s2]
)
def test_collide_rect_ratio__collides_all_at_ratio_of_twenty(self):
# collide_rect_ratio should collide all at a 20.0 ratio.
self.assert_ (
unordered_equality (
sprite.spritecollide (
self.s1, self.ag2, dokill = False,
collided = sprite.collide_rect_ratio(20.0)
),
[self.s2, self.s3]
)
)
def test_collide_circle__no_radius_set(self):
# collide_circle with no radius set.
self.assertEqual (
sprite.spritecollide (
self.s1, self.ag2, dokill = False, collided = sprite.collide_circle
),
[self.s2]
)
def test_collide_circle_ratio__no_radius_and_ratio_of_one(self):
# collide_circle_ratio with no radius set, at a 1.0 ratio.
self.assertEqual (
sprite.spritecollide (
self.s1, self.ag2, dokill = False,
collided = sprite.collide_circle_ratio(1.0)
),
[self.s2]
)
def test_collide_circle_ratio__no_radius_and_ratio_of_twenty(self):
# collide_circle_ratio with no radius set, at a 20.0 ratio.
self.assert_ (
unordered_equality (
sprite.spritecollide (
self.s1, self.ag2, dokill = False,
collided = sprite.collide_circle_ratio(20.0)
),
[self.s2, self.s3]
)
)
def test_collide_circle__with_radii_set(self):
# collide_circle with a radius set.
self.s1.radius = 50
self.s2.radius = 10
self.s3.radius = 400
self.assert_ (
unordered_equality (
sprite.spritecollide (
self.s1, self.ag2, dokill = False,
collided = sprite.collide_circle
),
[self.s2, self.s3]
)
)
def test_collide_circle_ratio__with_radii_set(self):
self.s1.radius = 50
self.s2.radius = 10
self.s3.radius = 400
# collide_circle_ratio with a radius set.
self.assert_ (
unordered_equality (
sprite.spritecollide (
self.s1, self.ag2, dokill = False,
collided = sprite.collide_circle_ratio(0.5)
),
[self.s2, self.s3]
)
)
def test_collide_mask__opaque(self):
# make some fully opaque sprites that will collide with masks.
self.s1.image.fill((255,255,255,255))
self.s2.image.fill((255,255,255,255))
self.s3.image.fill((255,255,255,255))
# masks should be autogenerated from image if they don't exist.
self.assertEqual (
sprite.spritecollide (
self.s1, self.ag2, dokill = False,
collided = sprite.collide_mask
),
[self.s2]
)
self.s1.mask = pygame.mask.from_surface(self.s1.image)
self.s2.mask = pygame.mask.from_surface(self.s2.image)
self.s3.mask = pygame.mask.from_surface(self.s3.image)
# with set masks.
self.assertEqual (
sprite.spritecollide (
self.s1, self.ag2, dokill = False,
collided = sprite.collide_mask
),
[self.s2]
)
def test_collide_mask__transparent(self):
# make some sprites that are fully transparent, so they won't collide.
self.s1.image.fill((255,255,255,0))
self.s2.image.fill((255,255,255,0))
self.s3.image.fill((255,255,255,0))
self.s1.mask = pygame.mask.from_surface(self.s1.image, 255)
self.s2.mask = pygame.mask.from_surface(self.s2.image, 255)
self.s3.mask = pygame.mask.from_surface(self.s3.image, 255)
self.assertFalse (
sprite.spritecollide (
self.s1, self.ag2, dokill = False, collided = sprite.collide_mask
)
)
def test_spritecollideany__without_collided_callback(self):
# pygame.sprite.spritecollideany(sprite, group) -> sprite
# finds any sprites that collide
# if collided is not passed, all
# sprites must have a "rect" value, which is a
# rectangle of the sprite area, which will be used
# to calculate the collision.
# s2 in, s3 out
self.assert_(
sprite.spritecollideany(self.s1, self.ag2)
)
# s2 and s3 out
self.s2.rect.move_ip(0, 10)
self.assertFalse(sprite.spritecollideany(self.s1, self.ag2))
# s2 out, s3 in
self.s3.rect.move_ip(-105, -105)
self.assert_(sprite.spritecollideany(self.s1, self.ag2))
# s2 and s3 in
self.s2.rect.move_ip(0, -10)
self.assert_(sprite.spritecollideany(self.s1, self.ag2))
def test_spritecollideany__with_collided_callback(self):
# pygame.sprite.spritecollideany(sprite, group) -> sprite
# finds any sprites that collide
# collided is a callback function used to calculate if
# two sprites are colliding. it should take two sprites
# as values, and return a bool value indicating if
# they are colliding.
# This collision test can be faster than pygame.sprite.spritecollide()
# since it has less work to do.
arg_dict_a = {}
arg_dict_b = {}
return_container = [True]
# This function is configurable using the mutable default arguments!
def collided_callback(spr_a, spr_b,
arg_dict_a=arg_dict_a, arg_dict_b=arg_dict_b,
return_container=return_container):
count = arg_dict_a.get(spr_a, 0)
arg_dict_a[spr_a] = 1 + count
count = arg_dict_b.get(spr_b, 0)
arg_dict_b[spr_b] = 1 + count
return return_container[0]
# This should return True because return_container[0] is True
self.assert_(
sprite.spritecollideany(self.s1, self.ag2, collided_callback)
)
# The callback function should have been called only once, so self.s1
# should have only been passed as an argument once
self.assert_(len(arg_dict_a) == 1 and arg_dict_a[self.s1] == 1)
# The callback function should have been called only once, so self.s2
# exclusive-or self.s3 should have only been passed as an argument
# once
self.assert_(
len(arg_dict_b) == 1 and list(arg_dict_b.values())[0] == 1 and
(self.s2 in arg_dict_b or self.s3 in arg_dict_b)
)
arg_dict_a.clear()
arg_dict_b.clear()
return_container[0] = False
# This should return False because return_container[0] is False
self.assertFalse(
sprite.spritecollideany(self.s1, self.ag2, collided_callback)
)
# The callback function should have been called as many times as
# there are sprites in self.ag2
self.assert_(len(arg_dict_a) == 1 and arg_dict_a[self.s1] == 2)
# The callback function should have been twice because self.s2 and
# self.s3 should have been passed once each
self.assert_(
len(arg_dict_b) == 2 and
arg_dict_b[self.s2] == 1 and arg_dict_b[self.s3] == 1
)
def test_groupcollide__without_collided_callback(self):
# pygame.sprite.groupcollide(groupa, groupb, dokilla, dokillb) -> dict
# collision detection between group and group
# test no kill
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, False)
self.assert_(crashed == {self.s1: [self.s2]})
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, False)
self.assert_(crashed == {self.s1: [self.s2]})
# test killb
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, True)
self.assert_(crashed == {self.s1: [self.s2]})
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, False)
self.assert_(crashed == {})
# test killa
self.s3.rect.move_ip(-100, -100)
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, True, False)
self.assert_(crashed == {self.s1: [self.s3]})
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, False)
self.assert_(crashed == {})
def test_groupcollide__with_collided_callback(self):
collided_callback_true = lambda spr_a, spr_b: True
collided_callback_false = lambda spr_a, spr_b: False
# test no kill
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, False,
collided_callback_false)
self.assert_(crashed == {})
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, False,
collided_callback_true)
self.assert_(crashed == {self.s1: [self.s2, self.s3]} or
crashed == {self.s1: [self.s3, self.s2]})
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, False,
collided_callback_true)
self.assert_(crashed == {self.s1: [self.s2, self.s3]} or
crashed == {self.s1: [self.s3, self.s2]})
# test killb
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, True,
collided_callback_false)
self.assert_(crashed == {})
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, True,
collided_callback_true)
self.assert_(crashed == {self.s1: [self.s2, self.s3]} or
crashed == {self.s1: [self.s3, self.s2]})
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, False, True,
collided_callback_true)
self.assert_(crashed == {})
# test killa
self.ag.add(self.s2)
self.ag2.add(self.s3)
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, True, False,
collided_callback_false)
self.assert_(crashed == {})
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, True, False,
collided_callback_true)
self.assert_(crashed == {self.s1: [self.s3], self.s2: [self.s3]})
crashed = pygame.sprite.groupcollide(self.ag, self.ag2, True, False,
collided_callback_true)
self.assert_(crashed == {})
def test_collide_rect(self):
# Test colliding - some edges touching
self.assert_(pygame.sprite.collide_rect(self.s1, self.s2))
self.assert_(pygame.sprite.collide_rect(self.s2, self.s1))
# Test colliding - all edges touching
self.s2.rect.center = self.s3.rect.center
self.assert_(pygame.sprite.collide_rect(self.s2, self.s3))
self.assert_(pygame.sprite.collide_rect(self.s3, self.s2))
# Test colliding - no edges touching
self.s2.rect.inflate_ip(10, 10)
self.assert_(pygame.sprite.collide_rect(self.s2, self.s3))
self.assert_(pygame.sprite.collide_rect(self.s3, self.s2))
# Test colliding - some edges intersecting
self.s2.rect.center = (self.s1.rect.right, self.s1.rect.bottom)
self.assert_(pygame.sprite.collide_rect(self.s1, self.s2))
self.assert_(pygame.sprite.collide_rect(self.s2, self.s1))
# Test not colliding
self.assertFalse(pygame.sprite.collide_rect(self.s1, self.s3))
self.assertFalse(pygame.sprite.collide_rect(self.s3, self.s1))
################################################################################
class AbstractGroupTypeTest( unittest.TestCase ):
def setUp(self):
self.ag = sprite.AbstractGroup()
self.ag2 = sprite.AbstractGroup()
self.s1 = sprite.Sprite(self.ag)
self.s2 = sprite.Sprite(self.ag)
self.s3 = sprite.Sprite(self.ag2)
self.s4 = sprite.Sprite(self.ag2)
self.s1.image = pygame.Surface((10, 10))
self.s1.image.fill(pygame.Color('red'))
self.s1.rect = self.s1.image.get_rect()
self.s2.image = pygame.Surface((10, 10))
self.s2.image.fill(pygame.Color('green'))
self.s2.rect = self.s2.image.get_rect()
self.s2.rect.left = 10
self.s3.image = pygame.Surface((10, 10))
self.s3.image.fill(pygame.Color('blue'))
self.s3.rect = self.s3.image.get_rect()
self.s3.rect.top = 10
self.s4.image = pygame.Surface((10, 10))
self.s4.image.fill(pygame.Color('white'))
self.s4.rect = self.s4.image.get_rect()
self.s4.rect.left = 10
self.s4.rect.top = 10
self.bg = pygame.Surface((20, 20))
self.scr = pygame.Surface((20, 20))
self.scr.fill(pygame.Color('grey'))
def test_has( self ):
" See if AbstractGroup.has() works as expected. "
self.assertEqual(True, self.s1 in self.ag)
self.assertEqual(True, self.ag.has(self.s1))
self.assertEqual(True, self.ag.has([self.s1, self.s2]))
# see if one of them not being in there.
self.assertNotEqual(True, self.ag.has([self.s1, self.s2, self.s3]))
self.assertNotEqual(True, self.ag.has(self.s1, self.s2, self.s3))
self.assertNotEqual(True, self.ag.has(self.s1,
sprite.Group(self.s2, self.s3)))
self.assertNotEqual(True, self.ag.has(self.s1, [self.s2, self.s3]))
# test empty list processing
self.assertFalse(self.ag.has(*[]))
self.assertFalse(self.ag.has([]))
self.assertFalse(self.ag.has([[]]))
# see if a second AbstractGroup works.
self.assertEqual(True, self.ag2.has(self.s3))
def test_add(self):
ag3 = sprite.AbstractGroup()
self.assertFalse(self.s1 in ag3)
self.assertFalse(self.s2 in ag3)
self.assertFalse(self.s3 in ag3)
self.assertFalse(self.s4 in ag3)
ag3.add(self.s1, [self.s2], self.ag2)
self.assert_(self.s1 in ag3)
self.assert_(self.s2 in ag3)
self.assert_(self.s3 in ag3)
self.assert_(self.s4 in ag3)
def test_add_internal(self):
self.assertFalse(self.s1 in self.ag2)
self.ag2.add_internal(self.s1)
self.assert_(self.s1 in self.ag2)
def test_clear(self):
self.ag.draw(self.scr)
self.ag.clear(self.scr, self.bg)
self.assertEqual((0, 0, 0, 255),
self.scr.get_at((5, 5)))
self.assertEqual((0, 0, 0, 255),
self.scr.get_at((15, 5)))
def test_draw(self):
self.ag.draw(self.scr)
self.assertEqual((255, 0, 0, 255),
self.scr.get_at((5, 5)))
self.assertEqual((0, 255, 0, 255),
self.scr.get_at((15, 5)))
def test_empty(self):
self.ag.empty()
self.assertFalse(self.s1 in self.ag)
self.assertFalse(self.s2 in self.ag)
def test_has_internal(self):
self.assert_(self.ag.has_internal(self.s1))
self.assertFalse(self.ag.has_internal(self.s3))
def test_remove(self):
# Test removal of 1 sprite
self.ag.remove(self.s1)
self.assertFalse(self.ag in self.s1.groups())
self.assertFalse(self.ag.has(self.s1))
# Test removal of 2 sprites as 2 arguments
self.ag2.remove(self.s3, self.s4)
self.assertFalse(self.ag2 in self.s3.groups())
self.assertFalse(self.ag2 in self.s4.groups())
self.assertFalse(self.ag2.has(self.s3, self.s4))
# Test removal of 4 sprites as a list containing a sprite and a group
# containing a sprite and another group containing 2 sprites.
self.ag.add(self.s1, self.s3, self.s4)
self.ag2.add(self.s3, self.s4)
g = sprite.Group(self.s2)
self.ag.remove([self.s1, g], self.ag2)
self.assertFalse(self.ag in self.s1.groups())
self.assertFalse(self.ag in self.s2.groups())
self.assertFalse(self.ag in self.s3.groups())
self.assertFalse(self.ag in self.s4.groups())
self.assertFalse(self.ag.has(self.s1, self.s2, self.s3, self.s4))
def test_remove_internal(self):
self.ag.remove_internal(self.s1)
self.assertFalse(self.ag.has_internal(self.s1))
def test_sprites(self):
sprite_list = self.ag.sprites()
self.assert_(sprite_list == [self.s1, self.s2] or
sprite_list == [self.s2, self.s1])
def test_update(self):
class test_sprite(pygame.sprite.Sprite):
sink = []
def __init__(self, *groups):
pygame.sprite.Sprite.__init__(self, *groups)
def update(self, *args):
self.sink += args
s = test_sprite(self.ag)
self.ag.update(1, 2, 3)
self.assertEqual(test_sprite.sink, [1, 2, 3])
################################################################################
# A base class to share tests between similar classes
class LayeredGroupBase:
def test_get_layer_of_sprite(self):
self.assert_(len(self.LG._spritelist)==0)
spr = self.sprite()
self.LG.add(spr, layer=666)
self.assert_(len(self.LG._spritelist)==1)
self.assert_(self.LG.get_layer_of_sprite(spr)==666)
self.assert_(self.LG.get_layer_of_sprite(spr)==self.LG._spritelayers[spr])
def test_add(self):
self.assert_(len(self.LG._spritelist)==0)
spr = self.sprite()
self.LG.add(spr)
self.assert_(len(self.LG._spritelist)==1)
self.assert_(self.LG.get_layer_of_sprite(spr)==self.LG._default_layer)
def test_add__sprite_with_layer_attribute(self):
#test_add_sprite_with_layer_attribute
self.assert_(len(self.LG._spritelist)==0)
spr = self.sprite()
spr._layer = 100
self.LG.add(spr)
self.assert_(len(self.LG._spritelist)==1)
self.assert_(self.LG.get_layer_of_sprite(spr)==100)
def test_add__passing_layer_keyword(self):
# test_add_sprite_passing_layer
self.assert_(len(self.LG._spritelist)==0)
spr = self.sprite()
self.LG.add(spr, layer=100)
self.assert_(len(self.LG._spritelist)==1)
self.assert_(self.LG.get_layer_of_sprite(spr)==100)
def test_add__overriding_sprite_layer_attr(self):
# test_add_sprite_overriding_layer_attr
self.assert_(len(self.LG._spritelist)==0)
spr = self.sprite()
spr._layer = 100
self.LG.add(spr, layer=200)
self.assert_(len(self.LG._spritelist)==1)
self.assert_(self.LG.get_layer_of_sprite(spr)==200)
def test_add__adding_sprite_on_init(self):
# test_add_sprite_init
spr = self.sprite()
lrg2 = sprite.LayeredUpdates(spr)
self.assert_(len(lrg2._spritelist)==1)
self.assert_(lrg2._spritelayers[spr]==lrg2._default_layer)
def test_add__sprite_init_layer_attr(self):
# test_add_sprite_init_layer_attr
spr = self.sprite()
spr._layer = 20
lrg2 = sprite.LayeredUpdates(spr)
self.assert_(len(lrg2._spritelist)==1)
self.assert_(lrg2._spritelayers[spr]==20)
def test_add__sprite_init_passing_layer(self):
# test_add_sprite_init_passing_layer
spr = self.sprite()
lrg2 = sprite.LayeredUpdates(spr, layer=33)
self.assert_(len(lrg2._spritelist)==1)
self.assert_(lrg2._spritelayers[spr]==33)
def test_add__sprite_init_overiding_layer(self):
# test_add_sprite_init_overiding_layer
spr = self.sprite()
spr._layer = 55
lrg2 = sprite.LayeredUpdates(spr, layer=33)
self.assert_(len(lrg2._spritelist)==1)
self.assert_(lrg2._spritelayers[spr]==33)
def test_add__spritelist(self):
# test_add_spritelist
self.assert_(len(self.LG._spritelist)==0)
sprites = []
for i in range(10):
sprites.append(self.sprite())
self.LG.add(sprites)
self.assert_(len(self.LG._spritelist)==10)
for i in range(10):
self.assert_(self.LG.get_layer_of_sprite(sprites[i])==self.LG._default_layer)
def test_add__spritelist_with_layer_attr(self):
# test_add_spritelist_with_layer_attr
self.assert_(len(self.LG._spritelist)==0)
sprites = []
for i in range(10):
sprites.append(self.sprite())
sprites[-1]._layer = i
self.LG.add(sprites)
self.assert_(len(self.LG._spritelist)==10)
for i in range(10):
self.assert_(self.LG.get_layer_of_sprite(sprites[i])==i)
def test_add__spritelist_passing_layer(self):
# test_add_spritelist_passing_layer
self.assert_(len(self.LG._spritelist)==0)
sprites = []
for i in range(10):
sprites.append(self.sprite())
self.LG.add(sprites, layer=33)
self.assert_(len(self.LG._spritelist)==10)
for i in range(10):
self.assert_(self.LG.get_layer_of_sprite(sprites[i])==33)
def test_add__spritelist_overriding_layer(self):
# test_add_spritelist_overriding_layer
self.assert_(len(self.LG._spritelist)==0)
sprites = []
for i in range(10):
sprites.append(self.sprite())
sprites[-1].layer = i
self.LG.add(sprites, layer=33)
self.assert_(len(self.LG._spritelist)==10)
for i in range(10):
self.assert_(self.LG.get_layer_of_sprite(sprites[i])==33)
def test_add__spritelist_init(self):
# test_add_spritelist_init
self.assert_(len(self.LG._spritelist)==0)
sprites = []
for i in range(10):
sprites.append(self.sprite())
lrg2 = sprite.LayeredUpdates(sprites)
self.assert_(len(lrg2._spritelist)==10)
for i in range(10):
self.assert_(lrg2.get_layer_of_sprite(sprites[i])==self.LG._default_layer)
def test_remove__sprite(self):
# test_remove_sprite
self.assert_(len(self.LG._spritelist)==0)
sprites = []
for i in range(10):
sprites.append(self.sprite())
sprites[-1].rect = 0
self.LG.add(sprites)
self.assert_(len(self.LG._spritelist)==10)
for i in range(10):
self.LG.remove(sprites[i])
self.assert_(len(self.LG._spritelist)==0)
def test_sprites(self):
# test_sprites
self.assert_(len(self.LG._spritelist)==0)
sprites = []
for i in range(10):
sprites.append(self.sprite())
sprites[-1]._layer = 10-i
self.LG.add(sprites)
self.assert_(len(self.LG._spritelist)==10)
for idx,spr in enumerate(self.LG.sprites()):
self.assert_(spr == sprites[9-idx])
def test_layers(self):
# test_layers
self.assert_(len(self.LG._spritelist)==0)
sprites = []
for i in range(10):
for j in range(5):
sprites.append(self.sprite())
sprites[-1]._layer = i
self.LG.add(sprites)
lays = self.LG.layers()
for i in range(10):
self.assert_(lays[i] == i)
def test_add__layers_are_correct(self): #TODO
# test_layers2
self.assert_(len(self.LG)==0)
layers = [1,4,6,8,3,6,2,6,4,5,6,1,0,9,7,6,54,8,2,43,6,1]
for lay in layers:
self.LG.add(self.sprite(), layer=lay)
layers.sort()
for idx, spr in enumerate(self.LG.sprites()):
self.assert_(self.LG.get_layer_of_sprite(spr)==layers[idx])
def test_change_layer(self):
# test_change_layer
self.assert_(len(self.LG._spritelist)==0)
spr = self.sprite()
self.LG.add(spr, layer=99)
self.assert_(self.LG._spritelayers[spr] == 99)
self.LG.change_layer(spr, 44)
self.assert_(self.LG._spritelayers[spr] == 44)
spr2 = self.sprite()
spr2.layer = 55
self.LG.add(spr2)
self.LG.change_layer(spr2, 77)
self.assert_(spr2.layer == 77)
def test_get_top_layer(self):
# test_get_top_layer
layers = [1,5,2,8,4,5,3,88,23,0]
for i in layers:
self.LG.add(self.sprite(), layer=i)
self.assert_(self.LG.get_top_layer()==max(layers))
self.assert_(self.LG.get_top_layer()==max(self.LG._spritelayers.values()))
self.assert_(self.LG.get_top_layer()==self.LG._spritelayers[self.LG._spritelist[-1]])
def test_get_bottom_layer(self):
# test_get_bottom_layer
layers = [1,5,2,8,4,5,3,88,23,0]
for i in layers:
self.LG.add(self.sprite(), layer=i)
self.assert_(self.LG.get_bottom_layer()==min(layers))
self.assert_(self.LG.get_bottom_layer()==min(self.LG._spritelayers.values()))
self.assert_(self.LG.get_bottom_layer()==self.LG._spritelayers[self.LG._spritelist[0]])
def test_move_to_front(self):
# test_move_to_front
layers = [1,5,2,8,4,5,3,88,23,0]
for i in layers:
self.LG.add(self.sprite(), layer=i)
spr = self.sprite()
self.LG.add(spr, layer=3)
self.assert_(spr != self.LG._spritelist[-1])
self.LG.move_to_front(spr)
self.assert_(spr == self.LG._spritelist[-1])
def test_move_to_back(self):
# test_move_to_back
layers = [1,5,2,8,4,5,3,88,23,0]
for i in layers:
self.LG.add(self.sprite(), layer=i)
spr = self.sprite()
self.LG.add(spr, layer=55)
self.assert_(spr != self.LG._spritelist[0])
self.LG.move_to_back(spr)
self.assert_(spr == self.LG._spritelist[0])
def test_get_top_sprite(self):
# test_get_top_sprite
layers = [1,5,2,8,4,5,3,88,23,0]
for i in layers:
self.LG.add(self.sprite(), layer=i)
self.assert_(self.LG.get_layer_of_sprite(self.LG.get_top_sprite())== self.LG.get_top_layer())
def test_get_sprites_from_layer(self):
# test_get_sprites_from_layer
self.assert_(len(self.LG)==0)
sprites = {}
layers = [1,4,5,6,3,7,8,2,1,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,0,1,6,5,4,3,2]
for lay in layers:
spr = self.sprite()
spr._layer = lay
self.LG.add(spr)
if lay not in sprites:
sprites[lay] = []
sprites[lay].append(spr)
for lay in self.LG.layers():
for spr in self.LG.get_sprites_from_layer(lay):
self.assert_(spr in sprites[lay])
sprites[lay].remove(spr)
if len(sprites[lay]) == 0:
del sprites[lay]
self.assert_(len(sprites.values())==0)
def test_switch_layer(self):
# test_switch_layer
self.assert_(len(self.LG)==0)
sprites1 = []
sprites2 = []
layers = [3,2,3,2,3,3,2,2,3,2,3,2,3,2,3,2,3,3,2,2,3,2,3]
for lay in layers:
spr = self.sprite()
spr._layer = lay
self.LG.add(spr)
if lay==2:
sprites1.append(spr)
else:
sprites2.append(spr)
for spr in sprites1:
self.assert_(spr in self.LG.get_sprites_from_layer(2))
for spr in sprites2:
self.assert_(spr in self.LG.get_sprites_from_layer(3))
self.assert_(len(self.LG)==len(sprites1)+len(sprites2))
self.LG.switch_layer(2,3)
for spr in sprites1:
self.assert_(spr in self.LG.get_sprites_from_layer(3))
for spr in sprites2:
self.assert_(spr in self.LG.get_sprites_from_layer(2))
self.assert_(len(self.LG)==len(sprites1)+len(sprites2))
def test_copy(self):
self.LG.add(self.sprite())
spr = self.LG.sprites()[0]
lg_copy = self.LG.copy()
self.assert_(isinstance(lg_copy, type(self.LG)))
self.assert_(spr in lg_copy and lg_copy in spr.groups())
########################## LAYERED RENDER GROUP TESTS ##########################
class LayeredUpdatesTypeTest__SpriteTest(LayeredGroupBase, unittest.TestCase):
sprite = sprite.Sprite
def setUp(self):
self.LG = sprite.LayeredUpdates()
class LayeredUpdatesTypeTest__DirtySprite(LayeredGroupBase, unittest.TestCase):
sprite = sprite.DirtySprite
def setUp(self):
self.LG = sprite.LayeredUpdates()
class LayeredDirtyTypeTest__DirtySprite(LayeredGroupBase, unittest.TestCase):
sprite = sprite.DirtySprite
def setUp(self):
self.LG = sprite.LayeredDirty()
def test_repaint_rect(self):
group = self.LG
surface = pygame.Surface((100, 100))
group.repaint_rect(pygame.Rect(0, 0, 100, 100))
group.draw(surface)
def test_repaint_rect_with_clip(self):
group = self.LG
surface = pygame.Surface((100, 100))
group.set_clip(pygame.Rect(0, 0, 100, 100))
group.repaint_rect(pygame.Rect(0, 0, 100, 100))
group.draw(surface)
############################### SPRITE BASE CLASS ##############################
#
# tests common between sprite classes
class SpriteBase:
def setUp(self):
self.groups = []
for Group in self.Groups:
self.groups.append(Group())
self.sprite = self.Sprite()
def test_add_internal(self):
for g in self.groups:
self.sprite.add_internal(g)
for g in self.groups:
self.assert_(g in self.sprite.groups())
def test_remove_internal(self):
for g in self.groups:
self.sprite.add_internal(g)
for g in self.groups:
self.sprite.remove_internal(g)
for g in self.groups:
self.assertFalse(g in self.sprite.groups())
def test_update(self):
class test_sprite(pygame.sprite.Sprite):
sink = []
def __init__(self, *groups):
pygame.sprite.Sprite.__init__(self, *groups)
def update(self, *args):
self.sink += args
s = test_sprite()
s.update(1, 2, 3)
self.assertEqual(test_sprite.sink, [1, 2, 3])
def test___init____added_to_groups_passed(self):
self.sprite = self.Sprite(self.groups)
self.assert_(unordered_equality(
self.sprite.groups(),
self.groups
))
def test_add(self):
self.sprite.add(self.groups)
self.assert_(unordered_equality(
self.sprite.groups(),
self.groups
))
def test_alive(self):
self.assert_(
not self.sprite.alive(),
"Sprite should not be alive if in no groups"
)
self.sprite.add(self.groups)
self.assert_(self.sprite.alive())
def test_groups(self):
for i, g in enumerate(self.groups):
self.sprite.add(g)
groups = self.sprite.groups()
self.assert_( unordered_equality (
groups,
self.groups[:i+1],
))
def test_kill(self):
self.sprite.add(self.groups)
self.assert_(self.sprite.alive())
self.sprite.kill()
self.assert_(not self.sprite.groups() and not self.sprite.alive() )
def test_remove(self):
self.sprite.add(self.groups)
self.sprite.remove(self.groups)
self.assert_(not self.sprite.groups())
############################## SPRITE CLASS TESTS ##############################
class SpriteTypeTest(SpriteBase, unittest.TestCase):
Sprite = sprite.Sprite
Groups = [ sprite.Group,
sprite.LayeredUpdates,
sprite.RenderUpdates,
sprite.OrderedUpdates, ]
class DirtySpriteTypeTest(SpriteBase, unittest.TestCase):
Sprite = sprite.DirtySprite
Groups = [ sprite.Group,
sprite.LayeredUpdates,
sprite.RenderUpdates,
sprite.OrderedUpdates,
sprite.LayeredDirty, ]
############################## BUG TESTS #######################################
class SingleGroupBugsTest(unittest.TestCase):
def test_memoryleak_bug(self):
# For memoryleak bug posted to mailing list by Tobias Steinrücken on 16/11/10.
# Fixed in revision 2953.
import weakref
import gc
class MySprite(sprite.Sprite):
def __init__(self, *args, **kwargs):
sprite.Sprite.__init__(self, *args, **kwargs)
self.image = pygame.Surface( (2, 4), 0, 24 )
self.rect = self.image.get_rect()
g = sprite.GroupSingle()
screen = pygame.Surface((4, 8), 0, 24)
s = MySprite()
r = weakref.ref(s)
g.sprite = s
del s
gc.collect()
self.assert_(r() is not None)
g.update()
g.draw(screen)
g.sprite = MySprite()
gc.collect()
self.assert_(r() is None)
################################################################################
if __name__ == '__main__':
unittest.main()
|
mit
|
[
1371,
381,
5025,
2596,
51,
10371,
5680,
199,
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
984,
272,
492,
747,
272,
5496,
63,
694,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
59,
16,
61,
272,
1676,
63,
694,
12,
5496,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4600,
63,
694,
9,
272,
365,
63,
22278,
63,
4600,
275,
334,
4600,
63,
354,
508,
283,
2219,
7,
436,
2151,
747,
14,
515,
14,
1294,
8,
1708,
63,
694,
2788,
17,
61,
508,
283,
22278,
358,
272,
340,
440,
365,
63,
22278,
63,
4600,
26,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
1676,
63,
694,
9,
199,
2836,
26,
272,
365,
63,
22278,
63,
4600,
275,
636,
354,
4343,
2460,
360,
22278,
14,
2219,
2659,
199,
199,
692,
365,
63,
22278,
63,
4600,
26,
272,
687,
9193,
14,
2219,
14,
396,
63,
1208,
971,
268,
492,
511,
63,
1397,
63,
13825,
12,
31716,
63,
20982,
12,
2882,
199,
2836,
26,
272,
687,
511,
14,
396,
63,
1208,
971,
268,
492,
511,
63,
1397,
63,
13825,
12,
31716,
63,
20982,
12,
2882,
199,
646,
9193,
199,
504,
9193,
492,
17325,
199,
199,
1371,
3,
30223,
6124,
10429,
10371,
3,
199,
199,
533,
8360,
752,
2377,
774,
8,
2882,
14,
1746,
3461,
272,
986,
199,
199,
19054,
428,
3311,
4427,
3978,
44,
11259,
21498,
19560,
7393,
21186,
199,
199,
533,
8360,
752,
2001,
8409,
774,
8,
2882,
14,
1746,
3461,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
643,
275,
17325,
14,
8458,
2448,
342,
267,
291,
14,
643,
18,
275,
17325,
14,
8458,
2448,
342,
267,
291,
14,
83,
17,
275,
17325,
14,
30185,
8,
277,
14,
643,
9,
267,
291,
14,
83,
18,
275,
17325,
14,
30185,
8,
277,
14,
643,
18,
9,
267,
291,
14,
83,
19,
275,
17325,
14,
30185,
8,
277,
14,
643,
18,
9,
398,
291,
14,
83,
17,
14,
1569,
275,
9193,
14,
16923,
1332,
1400,
12,
709,
395,
9193,
14,
12447,
18554,
12,
4337,
9,
267,
291,
14,
83,
18,
14,
1569,
275,
9193,
14,
16923,
1332,
709,
12,
709,
395,
9193,
14,
12447,
18554,
12,
4337,
9,
267,
291,
14,
83,
19,
14,
1569,
275,
9193,
14,
16923,
1332,
709,
12,
709,
395,
9193,
14,
12447,
18554,
12,
4337,
9,
398,
291,
14,
83,
17,
14,
1201,
275,
291,
14,
83,
17,
14,
1569,
14,
362,
63,
1201,
342,
267,
291,
14,
83,
18,
14,
1201,
275,
291,
14,
83,
18,
14,
1569,
14,
362,
63,
1201,
342,
267,
291,
14,
83,
19,
14,
1201,
275,
291,
14,
83,
19,
14,
1569,
14,
362,
63,
1201,
342,
267,
291,
14,
83,
18,
14,
1201,
14,
1185,
63,
711,
8,
2167,
12,
378,
9,
267,
291,
14,
83,
19,
14,
1201,
14,
1185,
63,
711,
8,
1960,
12,
2948,
9,
339,
347,
511,
63,
15972,
761,
8409,
363,
12243,
63,
692,
63,
761,
317,
770,
63,
2894,
63,
374,
63,
403,
8,
277,
304,
267,
327,
1379,
626,
25328,
1048,
8409,
1928,
16233,
770,
805,
14,
267,
291,
14,
629,
334,
288,
17325,
14,
15972,
761,
8409,
334,
355,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
16233,
770,
275,
488,
288,
2318,
288,
359,
277,
14,
83,
18,
61,
267,
776,
339,
347,
511,
63,
15972,
761,
8409,
363,
12243,
63,
692,
63,
761,
317,
770,
63,
2894,
63,
1397,
63,
12070,
8,
277,
304,
267,
327,
7719,
2597,
1736,
1380,
16233,
770,
805,
5712,
1133,
3032,
737,
1006,
14,
267,
291,
14,
629,
8,
15972,
14,
15972,
761,
8409,
334,
288,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
395,
288,
359,
277,
14,
83,
18,
61,
267,
776,
339,
347,
511,
63,
15972,
761,
8409,
363,
761,
317,
770,
63,
7790,
63,
1235,
63,
65,
63,
8296,
8,
277,
304,
267,
327,
14012,
370,
986,
282,
4550,
14,
267,
291,
14,
1855,
334,
288,
3146,
12,
288,
17325,
14,
15972,
761,
8409,
12,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
16233,
770,
275,
413,
267,
776,
339,
347,
511,
63,
15972,
761,
8409,
363,
761,
317,
770,
63,
4322,
63,
475,
63,
761,
8409,
63,
1201,
8,
277,
304,
267,
327,
1048,
8409,
63,
1201,
1077,
24062,
314,
2011,
465,
849,
14,
267,
291,
14,
629,
334,
288,
17325,
14,
15972,
761,
8409,
334,
355,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
16233,
770,
275,
17325,
14,
761,
8409,
63,
1201,
288,
2318,
288,
359,
277,
14,
83,
18,
61,
267,
776,
339,
347,
511,
63,
761,
8409,
63,
1201,
63,
6884,
363,
6884,
63,
1618,
63,
368,
63,
2930,
63,
885,
8,
277,
304,
267,
327,
1048,
8409,
63,
1201,
63,
6884,
1077,
24062,
314,
2011,
465,
849,
737,
282,
413,
14,
16,
10463,
14,
267,
291,
14,
629,
334,
288,
17325,
14,
15972,
761,
8409,
334,
355,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
355,
16233,
770,
275,
17325,
14,
761,
8409,
63,
1201,
63,
6884,
8,
17,
14,
16,
9,
288,
2318,
288,
359,
277,
14,
83,
18,
61,
267,
776,
339,
347,
511,
63,
761,
8409,
63,
1201,
63,
6884,
363,
761,
317,
3424,
63,
452,
63,
292,
63,
6884,
63,
1618,
63,
8122,
287,
369,
8,
277,
304,
267,
327,
1048,
8409,
63,
1201,
63,
6884,
1077,
1048,
8409,
1006,
737,
282,
3388,
14,
16,
10463,
14,
267,
291,
14,
479,
63,
334,
288,
31716,
63,
20982,
334,
355,
17325,
14,
15972,
761,
8409,
334,
490,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
490,
16233,
770,
275,
17325,
14,
761,
8409,
63,
1201,
63,
6884,
8,
1165,
14,
16,
9,
355,
2318,
355,
359,
277,
14,
83,
18,
12,
291,
14,
83,
19,
61,
288,
776,
267,
776,
339,
347,
511,
63,
761,
8409,
63,
11001
] |
[
381,
5025,
2596,
51,
10371,
5680,
199,
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
984,
272,
492,
747,
272,
5496,
63,
694,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
59,
16,
61,
272,
1676,
63,
694,
12,
5496,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4600,
63,
694,
9,
272,
365,
63,
22278,
63,
4600,
275,
334,
4600,
63,
354,
508,
283,
2219,
7,
436,
2151,
747,
14,
515,
14,
1294,
8,
1708,
63,
694,
2788,
17,
61,
508,
283,
22278,
358,
272,
340,
440,
365,
63,
22278,
63,
4600,
26,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
1676,
63,
694,
9,
199,
2836,
26,
272,
365,
63,
22278,
63,
4600,
275,
636,
354,
4343,
2460,
360,
22278,
14,
2219,
2659,
199,
199,
692,
365,
63,
22278,
63,
4600,
26,
272,
687,
9193,
14,
2219,
14,
396,
63,
1208,
971,
268,
492,
511,
63,
1397,
63,
13825,
12,
31716,
63,
20982,
12,
2882,
199,
2836,
26,
272,
687,
511,
14,
396,
63,
1208,
971,
268,
492,
511,
63,
1397,
63,
13825,
12,
31716,
63,
20982,
12,
2882,
199,
646,
9193,
199,
504,
9193,
492,
17325,
199,
199,
1371,
3,
30223,
6124,
10429,
10371,
3,
199,
199,
533,
8360,
752,
2377,
774,
8,
2882,
14,
1746,
3461,
272,
986,
199,
199,
19054,
428,
3311,
4427,
3978,
44,
11259,
21498,
19560,
7393,
21186,
199,
199,
533,
8360,
752,
2001,
8409,
774,
8,
2882,
14,
1746,
3461,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
643,
275,
17325,
14,
8458,
2448,
342,
267,
291,
14,
643,
18,
275,
17325,
14,
8458,
2448,
342,
267,
291,
14,
83,
17,
275,
17325,
14,
30185,
8,
277,
14,
643,
9,
267,
291,
14,
83,
18,
275,
17325,
14,
30185,
8,
277,
14,
643,
18,
9,
267,
291,
14,
83,
19,
275,
17325,
14,
30185,
8,
277,
14,
643,
18,
9,
398,
291,
14,
83,
17,
14,
1569,
275,
9193,
14,
16923,
1332,
1400,
12,
709,
395,
9193,
14,
12447,
18554,
12,
4337,
9,
267,
291,
14,
83,
18,
14,
1569,
275,
9193,
14,
16923,
1332,
709,
12,
709,
395,
9193,
14,
12447,
18554,
12,
4337,
9,
267,
291,
14,
83,
19,
14,
1569,
275,
9193,
14,
16923,
1332,
709,
12,
709,
395,
9193,
14,
12447,
18554,
12,
4337,
9,
398,
291,
14,
83,
17,
14,
1201,
275,
291,
14,
83,
17,
14,
1569,
14,
362,
63,
1201,
342,
267,
291,
14,
83,
18,
14,
1201,
275,
291,
14,
83,
18,
14,
1569,
14,
362,
63,
1201,
342,
267,
291,
14,
83,
19,
14,
1201,
275,
291,
14,
83,
19,
14,
1569,
14,
362,
63,
1201,
342,
267,
291,
14,
83,
18,
14,
1201,
14,
1185,
63,
711,
8,
2167,
12,
378,
9,
267,
291,
14,
83,
19,
14,
1201,
14,
1185,
63,
711,
8,
1960,
12,
2948,
9,
339,
347,
511,
63,
15972,
761,
8409,
363,
12243,
63,
692,
63,
761,
317,
770,
63,
2894,
63,
374,
63,
403,
8,
277,
304,
267,
327,
1379,
626,
25328,
1048,
8409,
1928,
16233,
770,
805,
14,
267,
291,
14,
629,
334,
288,
17325,
14,
15972,
761,
8409,
334,
355,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
16233,
770,
275,
488,
288,
2318,
288,
359,
277,
14,
83,
18,
61,
267,
776,
339,
347,
511,
63,
15972,
761,
8409,
363,
12243,
63,
692,
63,
761,
317,
770,
63,
2894,
63,
1397,
63,
12070,
8,
277,
304,
267,
327,
7719,
2597,
1736,
1380,
16233,
770,
805,
5712,
1133,
3032,
737,
1006,
14,
267,
291,
14,
629,
8,
15972,
14,
15972,
761,
8409,
334,
288,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
395,
288,
359,
277,
14,
83,
18,
61,
267,
776,
339,
347,
511,
63,
15972,
761,
8409,
363,
761,
317,
770,
63,
7790,
63,
1235,
63,
65,
63,
8296,
8,
277,
304,
267,
327,
14012,
370,
986,
282,
4550,
14,
267,
291,
14,
1855,
334,
288,
3146,
12,
288,
17325,
14,
15972,
761,
8409,
12,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
16233,
770,
275,
413,
267,
776,
339,
347,
511,
63,
15972,
761,
8409,
363,
761,
317,
770,
63,
4322,
63,
475,
63,
761,
8409,
63,
1201,
8,
277,
304,
267,
327,
1048,
8409,
63,
1201,
1077,
24062,
314,
2011,
465,
849,
14,
267,
291,
14,
629,
334,
288,
17325,
14,
15972,
761,
8409,
334,
355,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
16233,
770,
275,
17325,
14,
761,
8409,
63,
1201,
288,
2318,
288,
359,
277,
14,
83,
18,
61,
267,
776,
339,
347,
511,
63,
761,
8409,
63,
1201,
63,
6884,
363,
6884,
63,
1618,
63,
368,
63,
2930,
63,
885,
8,
277,
304,
267,
327,
1048,
8409,
63,
1201,
63,
6884,
1077,
24062,
314,
2011,
465,
849,
737,
282,
413,
14,
16,
10463,
14,
267,
291,
14,
629,
334,
288,
17325,
14,
15972,
761,
8409,
334,
355,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
355,
16233,
770,
275,
17325,
14,
761,
8409,
63,
1201,
63,
6884,
8,
17,
14,
16,
9,
288,
2318,
288,
359,
277,
14,
83,
18,
61,
267,
776,
339,
347,
511,
63,
761,
8409,
63,
1201,
63,
6884,
363,
761,
317,
3424,
63,
452,
63,
292,
63,
6884,
63,
1618,
63,
8122,
287,
369,
8,
277,
304,
267,
327,
1048,
8409,
63,
1201,
63,
6884,
1077,
1048,
8409,
1006,
737,
282,
3388,
14,
16,
10463,
14,
267,
291,
14,
479,
63,
334,
288,
31716,
63,
20982,
334,
355,
17325,
14,
15972,
761,
8409,
334,
490,
291,
14,
83,
17,
12,
291,
14,
643,
18,
12,
366,
745,
778,
275,
756,
12,
490,
16233,
770,
275,
17325,
14,
761,
8409,
63,
1201,
63,
6884,
8,
1165,
14,
16,
9,
355,
2318,
355,
359,
277,
14,
83,
18,
12,
291,
14,
83,
19,
61,
288,
776,
267,
776,
339,
347,
511,
63,
761,
8409,
63,
11001,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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2499
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Handles builtins and other special functions."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import gast
from tensorflow.python.autograph.core import converter
from tensorflow.python.autograph.operators import py_builtins
from tensorflow.python.autograph.pyct import anno
from tensorflow.python.autograph.pyct import templates
class BuiltinFunctionTransformer(converter.Base):
"""Handles builtin functions.
This transformer only covers functions that are translated into a
TF equivalent, like `len`.
"""
def _convert_builtin(self, f, args, as_expression):
template = """
ag__.func(args)
"""
if as_expression:
return templates.replace_as_expression(
template, func=py_builtins.overload_of(f).__name__, args=args)
else:
return templates.replace(
template, func=py_builtins.overload_of(f).__name__, args=args)
def visit_Call(self, node):
node = self.generic_visit(node)
if anno.hasanno(node.func, 'live_val'):
live_val = anno.getanno(node.func, 'live_val')
try:
if live_val in py_builtins.SUPPORTED_BUILTINS:
node = self._convert_builtin(live_val, node.args, as_expression=True)
except TypeError:
# Not everything in Python is hashable. If it isn't then it's definitely
# not a supported built-in.
return node
return node
def visit_Print(self, node):
node = self.generic_visit(node)
args = node.values
# Following is the case when calling print(a, b)
if len(args) == 1 and isinstance(args[0], gast.Tuple):
args = args[0].elts
return self._convert_builtin(print, args, as_expression=False)
def transform(node, ctx):
return BuiltinFunctionTransformer(ctx).visit(node)
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
23555,
12963,
436,
1163,
4539,
3423,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
486,
1810,
199,
199,
504,
3228,
14,
1548,
14,
2495,
2180,
14,
1018,
492,
11109,
199,
504,
3228,
14,
1548,
14,
2495,
2180,
14,
12688,
492,
1134,
63,
10372,
199,
504,
3228,
14,
1548,
14,
2495,
2180,
14,
647,
319,
492,
22984,
199,
504,
3228,
14,
1548,
14,
2495,
2180,
14,
647,
319,
492,
7009,
421,
199,
533,
22422,
3481,
19761,
8,
11256,
14,
1563,
304,
523,
408,
23555,
6762,
3423,
14,
819,
961,
21484,
1454,
25858,
3423,
626,
787,
14598,
1901,
282,
523,
21721,
7353,
12,
2839,
658,
552,
2313,
523,
408,
819,
347,
485,
3916,
63,
5351,
8,
277,
12,
289,
12,
1249,
12,
465,
63,
5599,
304,
272,
1978,
275,
408,
489,
1839,
4343,
1532,
8,
589,
9,
272,
408,
272,
340,
465,
63,
5599,
26,
489,
372,
7009,
14,
1814,
63,
305,
63,
5599,
8,
881,
1978,
12,
2562,
29,
647,
63,
10372,
14,
1883,
912,
63,
1618,
8,
70,
2843,
354,
3108,
1249,
29,
589,
9,
272,
587,
26,
489,
372,
7009,
14,
1814,
8,
881,
1978,
12,
2562,
29,
647,
63,
10372,
14,
1883,
912,
63,
1618,
8,
70,
2843,
354,
3108,
1249,
29,
589,
9,
819,
347,
5684,
63,
2176,
8,
277,
12,
1031,
304,
272,
1031,
275,
291,
14,
6767,
63,
5427,
8,
932,
9,
272,
340,
22984,
14,
1989,
25264,
8,
932,
14,
1532,
12,
283,
6442,
63,
637,
735,
489,
12166,
63,
637,
275,
22984,
14,
362,
25264,
8,
932,
14,
1532,
12,
283,
6442,
63,
637,
358,
489,
862,
26,
267,
340,
12166,
63,
637,
315,
1134,
63,
10372,
14,
15925,
63,
18637,
52,
10789,
26,
881,
1031,
275,
291,
423,
3916,
63,
5351,
8,
6442,
63,
637,
12,
1031,
14,
589,
12,
465,
63,
5599,
29,
549,
9,
489,
871,
3146,
26,
267,
327,
2832,
8137,
315,
2018,
365,
21197,
14,
982,
652,
5712,
1133,
2066,
652,
1159,
28088,
590,
267,
327,
440,
282,
3748,
6137,
13,
262,
14,
267,
372,
1031,
272,
372,
1031,
819,
347,
5684,
63,
5375,
8,
277,
12,
1031,
304,
272,
1031,
275,
291,
14,
6767,
63,
5427,
8,
932,
9,
272,
1249,
275,
1031,
14,
1459,
272,
327,
21876,
316,
365,
314,
1930,
1380,
6358,
870,
8,
65,
12,
330,
9,
272,
340,
822,
8,
589,
9,
508,
413,
436,
1228,
8,
589,
59,
16,
467,
486,
1810,
14,
7075,
304,
489,
1249,
275,
1249,
59,
16,
1055,
352,
1086,
272,
372,
291,
423,
3916,
63,
5351,
8,
1361,
12,
1249,
12,
465,
63,
5599,
29,
797,
9,
421,
199,
318,
5793,
8,
932,
12,
4027,
304,
523,
372,
22422,
3481,
19761,
8,
3799,
680,
5427,
8,
932,
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
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
23555,
12963,
436,
1163,
4539,
3423,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
486,
1810,
199,
199,
504,
3228,
14,
1548,
14,
2495,
2180,
14,
1018,
492,
11109,
199,
504,
3228,
14,
1548,
14,
2495,
2180,
14,
12688,
492,
1134,
63,
10372,
199,
504,
3228,
14,
1548,
14,
2495,
2180,
14,
647,
319,
492,
22984,
199,
504,
3228,
14,
1548,
14,
2495,
2180,
14,
647,
319,
492,
7009,
421,
199,
533,
22422,
3481,
19761,
8,
11256,
14,
1563,
304,
523,
408,
23555,
6762,
3423,
14,
819,
961,
21484,
1454,
25858,
3423,
626,
787,
14598,
1901,
282,
523,
21721,
7353,
12,
2839,
658,
552,
2313,
523,
408,
819,
347,
485,
3916,
63,
5351,
8,
277,
12,
289,
12,
1249,
12,
465,
63,
5599,
304,
272,
1978,
275,
408,
489,
1839,
4343,
1532,
8,
589,
9,
272,
408,
272,
340,
465,
63,
5599,
26,
489,
372,
7009,
14,
1814,
63,
305,
63,
5599,
8,
881,
1978,
12,
2562,
29,
647,
63,
10372,
14,
1883,
912,
63,
1618,
8,
70,
2843,
354,
3108,
1249,
29,
589,
9,
272,
587,
26,
489,
372,
7009,
14,
1814,
8,
881,
1978,
12,
2562,
29,
647,
63,
10372,
14,
1883,
912,
63,
1618,
8,
70,
2843,
354,
3108,
1249,
29,
589,
9,
819,
347,
5684,
63,
2176,
8,
277,
12,
1031,
304,
272,
1031,
275,
291,
14,
6767,
63,
5427,
8,
932,
9,
272,
340,
22984,
14,
1989,
25264,
8,
932,
14,
1532,
12,
283,
6442,
63,
637,
735,
489,
12166,
63,
637,
275,
22984,
14,
362,
25264,
8,
932,
14,
1532,
12,
283,
6442,
63,
637,
358,
489,
862,
26,
267,
340,
12166,
63,
637,
315,
1134,
63,
10372,
14,
15925,
63,
18637,
52,
10789,
26,
881,
1031,
275,
291,
423,
3916,
63,
5351,
8,
6442,
63,
637,
12,
1031,
14,
589,
12,
465,
63,
5599,
29,
549,
9,
489,
871,
3146,
26,
267,
327,
2832,
8137,
315,
2018,
365,
21197,
14,
982,
652,
5712,
1133,
2066,
652,
1159,
28088,
590,
267,
327,
440,
282,
3748,
6137,
13,
262,
14,
267,
372,
1031,
272,
372,
1031,
819,
347,
5684,
63,
5375,
8,
277,
12,
1031,
304,
272,
1031,
275,
291,
14,
6767,
63,
5427,
8,
932,
9,
272,
1249,
275,
1031,
14,
1459,
272,
327,
21876,
316,
365,
314,
1930,
1380,
6358,
870,
8,
65,
12,
330,
9,
272,
340,
822,
8,
589,
9,
508,
413,
436,
1228,
8,
589,
59,
16,
467,
486,
1810,
14,
7075,
304,
489,
1249,
275,
1249,
59,
16,
1055,
352,
1086,
272,
372,
291,
423,
3916,
63,
5351,
8,
1361,
12,
1249,
12,
465,
63,
5599,
29,
797,
9,
421,
199,
318,
5793,
8,
932,
12,
4027,
304,
523,
372,
22422,
3481,
19761,
8,
3799,
680,
5427,
8,
932,
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,
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
] |
renyi533/tensorflow
|
tensorflow/lite/testing/op_tests/sparse_to_dense.py
|
17
|
3416
|
# Copyright 2019 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.
# ==============================================================================
"""Test configs for sparse_to_dense."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow.compat.v1 as tf
from tensorflow.lite.testing.zip_test_utils import create_scalar_data
from tensorflow.lite.testing.zip_test_utils import create_tensor_data
from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
from tensorflow.lite.testing.zip_test_utils import register_make_test_function
@register_make_test_function()
def make_sparse_to_dense_tests(options):
"""Make a set of tests to do sparse to dense."""
test_parameters = [{
"value_dtype": [tf.float32, tf.int32, tf.int64],
"index_dtype": [tf.int32, tf.int64],
"value_count": [1, 3, 6, 8],
"dense_shape": [[15], [3, 10], [4, 4, 4, 4], [7, 10, 9]],
"default_value": [0, -1],
"value_is_scalar": [True, False],
}]
# Return a single value for 1-D dense shape, but a tuple for other shapes.
def generate_index(dense_shape):
if len(dense_shape) == 1:
return np.random.randint(dense_shape[0])
else:
index = []
for shape in dense_shape:
index.append(np.random.randint(shape))
return tuple(index)
def build_graph(parameters):
"""Build the sparse_to_dense op testing graph."""
dense_shape = parameters["dense_shape"]
# Special handle for value_is_scalar case.
# value_count must be 1.
if parameters["value_is_scalar"] and parameters["value_count"] == 1:
value = tf.compat.v1.placeholder(
name="value", dtype=parameters["value_dtype"], shape=())
else:
value = tf.compat.v1.placeholder(
name="value",
dtype=parameters["value_dtype"],
shape=[parameters["value_count"]])
indices = set()
while len(indices) < parameters["value_count"]:
indices.add(generate_index(dense_shape))
indices = tf.constant(tuple(indices), dtype=parameters["index_dtype"])
# TODO(renjieliu): Add test for validate_indices case.
out = tf.sparse_to_dense(
indices,
dense_shape,
value,
parameters["default_value"],
validate_indices=False)
return [value], [out]
def build_inputs(parameters, sess, inputs, outputs):
if parameters["value_is_scalar"] and parameters["value_count"] == 1:
input_value = create_scalar_data(parameters["value_dtype"])
else:
input_value = create_tensor_data(parameters["value_dtype"],
[parameters["value_count"]])
return [input_value], sess.run(
outputs, feed_dict=dict(zip(inputs, [input_value])))
make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
|
apache-2.0
|
[
3,
1898,
20312,
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,
774,
11585,
367,
5178,
63,
475,
63,
7253,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
646,
3228,
14,
5819,
14,
86,
17,
465,
2833,
199,
504,
3228,
14,
5333,
14,
4776,
14,
3065,
63,
396,
63,
1208,
492,
1218,
63,
7033,
63,
576,
199,
504,
3228,
14,
5333,
14,
4776,
14,
3065,
63,
396,
63,
1208,
492,
1218,
63,
3128,
63,
576,
199,
504,
3228,
14,
5333,
14,
4776,
14,
3065,
63,
396,
63,
1208,
492,
1852,
63,
3065,
63,
1618,
63,
2219,
199,
504,
3228,
14,
5333,
14,
4776,
14,
3065,
63,
396,
63,
1208,
492,
2274,
63,
1875,
63,
396,
63,
1593,
421,
199,
32,
2683,
63,
1875,
63,
396,
63,
1593,
342,
199,
318,
1852,
63,
4421,
63,
475,
63,
7253,
63,
2219,
8,
1419,
304,
523,
408,
5483,
282,
663,
402,
2295,
370,
886,
5178,
370,
9363,
1041,
819,
511,
63,
3214,
275,
8910,
489,
298,
585,
63,
2271,
582,
359,
3249,
14,
1609,
708,
12,
2833,
14,
442,
708,
12,
2833,
14,
442,
772,
467,
489,
298,
1080,
63,
2271,
582,
359,
3249,
14,
442,
708,
12,
2833,
14,
442,
772,
467,
489,
298,
585,
63,
835,
582,
359,
17,
12,
650,
12,
1227,
12,
1695,
467,
489,
298,
7253,
63,
1392,
582,
3474,
1046,
467,
359,
19,
12,
1616,
467,
359,
20,
12,
841,
12,
841,
12,
841,
467,
359,
23,
12,
1616,
12,
1749,
2365,
489,
298,
885,
63,
585,
582,
359,
16,
12,
446,
17,
467,
489,
298,
585,
63,
374,
63,
7033,
582,
359,
549,
12,
756,
467,
523,
14877,
819,
327,
1432,
282,
2849,
574,
367,
413,
13,
36,
9363,
2215,
12,
1325,
282,
2008,
367,
1163,
11751,
14,
523,
347,
3550,
63,
1080,
8,
7253,
63,
1392,
304,
272,
340,
822,
8,
7253,
63,
1392,
9,
508,
413,
26,
489,
372,
980,
14,
2355,
14,
8393,
8,
7253,
63,
1392,
59,
16,
566,
272,
587,
26,
489,
1478,
275,
942,
489,
367,
2215,
315,
9363,
63,
1392,
26,
267,
1478,
14,
740,
8,
1590,
14,
2355,
14,
8393,
8,
1392,
430,
489,
372,
2008,
8,
1080,
9,
819,
347,
1900,
63,
2180,
8,
3214,
304,
272,
408,
3425,
314,
5178,
63,
475,
63,
7253,
1687,
5343,
3343,
1041,
272,
9363,
63,
1392,
275,
2633,
905,
7253,
63,
1392,
937,
339,
327,
12568,
2429,
367,
574,
63,
374,
63,
7033,
1930,
14,
272,
327,
574,
63,
835,
1471,
506,
413,
14,
272,
340,
2633,
905,
585,
63,
374,
63,
7033,
937,
436,
2633,
905,
585,
63,
835,
937,
508,
413,
26,
489,
574,
275,
2833,
14,
5819,
14,
86,
17,
14,
6199,
8,
881,
536,
628,
585,
401,
2152,
29,
3214,
905,
585,
63,
2271,
2255,
2215,
29,
1012,
272,
587,
26,
489,
574,
275,
2833,
14,
5819,
14,
86,
17,
14,
6199,
8,
881,
536,
628,
585,
401,
881,
2152,
29,
3214,
905,
585,
63,
2271,
2255,
881,
2215,
1524,
3214,
905,
585,
63,
835,
937,
566,
272,
4918,
275,
663,
342,
272,
1830,
822,
8,
4108,
9,
665,
2633,
905,
585,
63,
835,
6229,
489,
4918,
14,
525,
8,
4208,
63,
1080,
8,
7253,
63,
1392,
430,
272,
4918,
275,
2833,
14,
4083,
8,
2960,
8,
4108,
395,
2152,
29,
3214,
905,
1080,
63,
2271,
3135,
272,
327,
3254,
8,
828,
74,
1873,
317,
85,
304,
2654,
511,
367,
4107,
63,
4108,
1930,
14,
272,
734,
275,
2833,
14,
4421,
63,
475,
63,
7253,
8,
267,
4918,
12,
267,
9363,
63,
1392,
12,
267,
574,
12,
267,
2633,
905,
885,
63,
585,
2255,
267,
4107,
63,
4108,
29,
797,
9,
339,
372,
359,
585,
467,
359,
548,
61,
819,
347,
1900,
63,
3711,
8,
3214,
12,
4043,
12,
4153,
12,
4704,
304,
272,
340,
2633,
905,
585,
63,
374,
63,
7033,
937,
436,
2633,
905,
585,
63,
835,
937,
508,
413,
26,
489,
1324,
63,
585,
275,
1218,
63,
7033,
63,
576,
8,
3214,
905,
585,
63,
2271,
3135,
272,
587,
26,
489,
1324,
63,
585,
275,
1218,
63,
3128,
63,
576,
8,
3214,
905,
585,
63,
2271,
2255,
4318,
359,
3214,
905,
585,
63,
835,
937,
566,
272,
372,
359,
1210,
63,
585,
467,
4043,
14,
1065,
8,
267,
4704,
12,
4733,
63,
807,
29,
807,
8,
3065,
8,
3711,
12,
359,
1210,
63,
585,
11845,
819,
1852,
63,
3065,
63,
1618,
63,
2219,
8,
1419,
12,
511,
63,
3214,
12,
1900,
63,
2180,
12,
1900,
63,
3711,
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
] |
[
1898,
20312,
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,
774,
11585,
367,
5178,
63,
475,
63,
7253,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
646,
3228,
14,
5819,
14,
86,
17,
465,
2833,
199,
504,
3228,
14,
5333,
14,
4776,
14,
3065,
63,
396,
63,
1208,
492,
1218,
63,
7033,
63,
576,
199,
504,
3228,
14,
5333,
14,
4776,
14,
3065,
63,
396,
63,
1208,
492,
1218,
63,
3128,
63,
576,
199,
504,
3228,
14,
5333,
14,
4776,
14,
3065,
63,
396,
63,
1208,
492,
1852,
63,
3065,
63,
1618,
63,
2219,
199,
504,
3228,
14,
5333,
14,
4776,
14,
3065,
63,
396,
63,
1208,
492,
2274,
63,
1875,
63,
396,
63,
1593,
421,
199,
32,
2683,
63,
1875,
63,
396,
63,
1593,
342,
199,
318,
1852,
63,
4421,
63,
475,
63,
7253,
63,
2219,
8,
1419,
304,
523,
408,
5483,
282,
663,
402,
2295,
370,
886,
5178,
370,
9363,
1041,
819,
511,
63,
3214,
275,
8910,
489,
298,
585,
63,
2271,
582,
359,
3249,
14,
1609,
708,
12,
2833,
14,
442,
708,
12,
2833,
14,
442,
772,
467,
489,
298,
1080,
63,
2271,
582,
359,
3249,
14,
442,
708,
12,
2833,
14,
442,
772,
467,
489,
298,
585,
63,
835,
582,
359,
17,
12,
650,
12,
1227,
12,
1695,
467,
489,
298,
7253,
63,
1392,
582,
3474,
1046,
467,
359,
19,
12,
1616,
467,
359,
20,
12,
841,
12,
841,
12,
841,
467,
359,
23,
12,
1616,
12,
1749,
2365,
489,
298,
885,
63,
585,
582,
359,
16,
12,
446,
17,
467,
489,
298,
585,
63,
374,
63,
7033,
582,
359,
549,
12,
756,
467,
523,
14877,
819,
327,
1432,
282,
2849,
574,
367,
413,
13,
36,
9363,
2215,
12,
1325,
282,
2008,
367,
1163,
11751,
14,
523,
347,
3550,
63,
1080,
8,
7253,
63,
1392,
304,
272,
340,
822,
8,
7253,
63,
1392,
9,
508,
413,
26,
489,
372,
980,
14,
2355,
14,
8393,
8,
7253,
63,
1392,
59,
16,
566,
272,
587,
26,
489,
1478,
275,
942,
489,
367,
2215,
315,
9363,
63,
1392,
26,
267,
1478,
14,
740,
8,
1590,
14,
2355,
14,
8393,
8,
1392,
430,
489,
372,
2008,
8,
1080,
9,
819,
347,
1900,
63,
2180,
8,
3214,
304,
272,
408,
3425,
314,
5178,
63,
475,
63,
7253,
1687,
5343,
3343,
1041,
272,
9363,
63,
1392,
275,
2633,
905,
7253,
63,
1392,
937,
339,
327,
12568,
2429,
367,
574,
63,
374,
63,
7033,
1930,
14,
272,
327,
574,
63,
835,
1471,
506,
413,
14,
272,
340,
2633,
905,
585,
63,
374,
63,
7033,
937,
436,
2633,
905,
585,
63,
835,
937,
508,
413,
26,
489,
574,
275,
2833,
14,
5819,
14,
86,
17,
14,
6199,
8,
881,
536,
628,
585,
401,
2152,
29,
3214,
905,
585,
63,
2271,
2255,
2215,
29,
1012,
272,
587,
26,
489,
574,
275,
2833,
14,
5819,
14,
86,
17,
14,
6199,
8,
881,
536,
628,
585,
401,
881,
2152,
29,
3214,
905,
585,
63,
2271,
2255,
881,
2215,
1524,
3214,
905,
585,
63,
835,
937,
566,
272,
4918,
275,
663,
342,
272,
1830,
822,
8,
4108,
9,
665,
2633,
905,
585,
63,
835,
6229,
489,
4918,
14,
525,
8,
4208,
63,
1080,
8,
7253,
63,
1392,
430,
272,
4918,
275,
2833,
14,
4083,
8,
2960,
8,
4108,
395,
2152,
29,
3214,
905,
1080,
63,
2271,
3135,
272,
327,
3254,
8,
828,
74,
1873,
317,
85,
304,
2654,
511,
367,
4107,
63,
4108,
1930,
14,
272,
734,
275,
2833,
14,
4421,
63,
475,
63,
7253,
8,
267,
4918,
12,
267,
9363,
63,
1392,
12,
267,
574,
12,
267,
2633,
905,
885,
63,
585,
2255,
267,
4107,
63,
4108,
29,
797,
9,
339,
372,
359,
585,
467,
359,
548,
61,
819,
347,
1900,
63,
3711,
8,
3214,
12,
4043,
12,
4153,
12,
4704,
304,
272,
340,
2633,
905,
585,
63,
374,
63,
7033,
937,
436,
2633,
905,
585,
63,
835,
937,
508,
413,
26,
489,
1324,
63,
585,
275,
1218,
63,
7033,
63,
576,
8,
3214,
905,
585,
63,
2271,
3135,
272,
587,
26,
489,
1324,
63,
585,
275,
1218,
63,
3128,
63,
576,
8,
3214,
905,
585,
63,
2271,
2255,
4318,
359,
3214,
905,
585,
63,
835,
937,
566,
272,
372,
359,
1210,
63,
585,
467,
4043,
14,
1065,
8,
267,
4704,
12,
4733,
63,
807,
29,
807,
8,
3065,
8,
3711,
12,
359,
1210,
63,
585,
11845,
819,
1852,
63,
3065,
63,
1618,
63,
2219,
8,
1419,
12,
511,
63,
3214,
12,
1900,
63,
2180,
12,
1900,
63,
3711,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yoer/hue
|
desktop/core/ext-py/pycrypto-2.6.1/lib/Crypto/Util/py21compat.py
|
125
|
2779
|
# -*- coding: utf-8 -*-
#
# Util/py21compat.py : Compatibility code for Python 2.1
#
# Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
#
# ===================================================================
# The contents of this file are dedicated to the public domain. To
# the extent that dedication to the public domain is not available,
# everyone is granted a worldwide, perpetual, royalty-free,
# non-exclusive license to exercise all rights associated with the
# contents of this file for any purpose whatsoever.
# No rights are reserved.
#
# 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.
# ===================================================================
"""Compatibility code for Python 2.1
Currently, this just defines:
- True and False
- object
- isinstance
"""
__revision__ = "$Id$"
__all__ = []
import sys
import __builtin__
# 'True' and 'False' aren't defined in Python 2.1. Define them.
try:
True, False
except NameError:
(True, False) = (1, 0)
__all__ += ['True', 'False']
# New-style classes were introduced in Python 2.2. Defining "object" in Python
# 2.1 lets us use new-style classes in versions of Python that support them,
# while still maintaining backward compatibility with old-style classes
try:
object
except NameError:
class object: pass
__all__ += ['object']
# Starting with Python 2.2, isinstance allows a tuple for the second argument.
# Also, builtins like "tuple", "list", "str", "unicode", "int", and "long"
# became first-class types, rather than functions. We want to support
# constructs like:
# isinstance(x, (int, long))
# So we hack it for Python 2.1.
try:
isinstance(5, (int, long))
except TypeError:
__all__ += ['isinstance']
_builtin_type_map = {
tuple: type(()),
list: type([]),
str: type(""),
unicode: type(u""),
int: type(0),
long: type(0L),
}
def isinstance(obj, t):
if not __builtin__.isinstance(t, type(())):
# t is not a tuple
return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
else:
# t is a tuple
for typ in t:
if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
return True
return False
# vim:set ts=4 sw=4 sts=4 expandtab:
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
21248,
15,
647,
2025,
5819,
14,
647,
520,
3599,
5880,
1233,
367,
2018,
499,
14,
17,
199,
3,
199,
3,
27694,
315,
9079,
701,
577,
3316,
685,
445,
14,
491,
390,
5193,
605,
836,
665,
68,
29382,
32,
68,
29382,
14,
846,
30,
199,
3,
199,
3,
7819,
389,
199,
3,
710,
4072,
402,
642,
570,
787,
29711,
370,
314,
4575,
2881,
14,
221,
4005,
199,
3,
314,
13675,
626,
477,
21171,
370,
314,
4575,
2881,
365,
440,
2808,
12,
199,
3,
4036,
368,
365,
10009,
282,
6701,
13062,
12,
1126,
321,
1688,
12,
882,
89,
13248,
13,
4624,
12,
199,
3,
2222,
13,
12730,
4190,
370,
26511,
1006,
4481,
4568,
543,
314,
199,
3,
4072,
402,
642,
570,
367,
1263,
12016,
4052,
1152,
5907,
14,
199,
3,
3091,
4481,
787,
4644,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
199,
3,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
3,
7819,
389,
199,
199,
624,
2404,
5880,
1233,
367,
2018,
499,
14,
17,
199,
199,
31499,
12,
642,
2951,
7890,
26,
272,
446,
715,
436,
756,
272,
446,
909,
272,
446,
1228,
199,
624,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
363,
452,
363,
275,
942,
199,
199,
646,
984,
199,
646,
636,
5351,
363,
199,
199,
3,
283,
549,
7,
436,
283,
797,
7,
10621,
1133,
3247,
315,
2018,
499,
14,
17,
14,
221,
13930,
3062,
14,
199,
893,
26,
272,
715,
12,
756,
199,
2590,
12746,
26,
272,
334,
549,
12,
756,
9,
275,
334,
17,
12,
378,
9,
272,
636,
452,
363,
847,
788,
549,
297,
283,
797,
418,
199,
199,
3,
7053,
13,
2487,
3992,
4898,
21399,
315,
2018,
499,
14,
18,
14,
221,
1487,
2408,
316,
298,
785,
2,
315,
2018,
199,
3,
499,
14,
17,
19083,
2739,
675,
892,
13,
2487,
3992,
315,
5459,
402,
2018,
626,
2291,
3062,
12,
199,
3,
1830,
5139,
11075,
316,
13388,
7163,
543,
2269,
13,
2487,
3992,
199,
893,
26,
272,
909,
199,
2590,
12746,
26,
272,
1021,
909,
26,
986,
272,
636,
452,
363,
847,
788,
785,
418,
199,
199,
3,
24175,
543,
2018,
499,
14,
18,
12,
1228,
6127,
282,
2008,
367,
314,
3499,
1423,
14,
199,
3,
6121,
12,
12963,
2839,
298,
2960,
401,
298,
513,
401,
298,
495,
401,
298,
2975,
401,
298,
442,
401,
436,
298,
2809,
2,
199,
3,
506,
27467,
1642,
13,
533,
2943,
12,
7830,
2419,
3423,
14,
221,
2136,
2934,
370,
2291,
199,
3,
21638,
2839,
26,
199,
3,
257,
1228,
8,
88,
12,
334,
442,
12,
1846,
430,
199,
3,
2002,
781,
11176,
652,
367,
2018,
499,
14,
17,
14,
199,
893,
26,
272,
1228,
8,
21,
12,
334,
442,
12,
1846,
430,
199,
2590,
3146,
26,
272,
636,
452,
363,
847,
788,
6074,
418,
272,
485,
5351,
63,
466,
63,
1130,
275,
469,
267,
2008,
26,
730,
8,
4000,
267,
769,
26,
730,
25550,
267,
620,
26,
730,
11986,
395,
267,
2649,
26,
730,
8,
85,
341,
395,
267,
1109,
26,
730,
8,
16,
395,
267,
1846,
26,
730,
8,
16,
44,
395,
272,
789,
272,
347,
1228,
8,
1113,
12,
307,
304,
267,
340,
440,
636,
5351,
4343,
6074,
8,
84,
12,
730,
8,
28256,
288,
327,
307,
365,
440,
282,
2008,
288,
372,
636,
5351,
4343,
6074,
8,
1113,
12,
485,
5351,
63,
466,
63,
1130,
14,
362,
8,
84,
12,
307,
430,
267,
587,
26,
288,
327,
307,
365,
282,
2008,
288,
367,
6211,
315,
307,
26,
355,
340,
636,
5351,
4343,
6074,
8,
1113,
12,
485,
5351,
63,
466,
63,
1130,
14,
362,
8,
9749,
12,
6211,
2298,
490,
372,
715,
288,
372,
756,
199,
199,
3,
6695,
26,
409,
6714,
29,
20,
5584,
29,
20,
23014,
29,
20,
26414,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
21248,
15,
647,
2025,
5819,
14,
647,
520,
3599,
5880,
1233,
367,
2018,
499,
14,
17,
199,
3,
199,
3,
27694,
315,
9079,
701,
577,
3316,
685,
445,
14,
491,
390,
5193,
605,
836,
665,
68,
29382,
32,
68,
29382,
14,
846,
30,
199,
3,
199,
3,
7819,
389,
199,
3,
710,
4072,
402,
642,
570,
787,
29711,
370,
314,
4575,
2881,
14,
221,
4005,
199,
3,
314,
13675,
626,
477,
21171,
370,
314,
4575,
2881,
365,
440,
2808,
12,
199,
3,
4036,
368,
365,
10009,
282,
6701,
13062,
12,
1126,
321,
1688,
12,
882,
89,
13248,
13,
4624,
12,
199,
3,
2222,
13,
12730,
4190,
370,
26511,
1006,
4481,
4568,
543,
314,
199,
3,
4072,
402,
642,
570,
367,
1263,
12016,
4052,
1152,
5907,
14,
199,
3,
3091,
4481,
787,
4644,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
199,
3,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
3,
7819,
389,
199,
199,
624,
2404,
5880,
1233,
367,
2018,
499,
14,
17,
199,
199,
31499,
12,
642,
2951,
7890,
26,
272,
446,
715,
436,
756,
272,
446,
909,
272,
446,
1228,
199,
624,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
363,
452,
363,
275,
942,
199,
199,
646,
984,
199,
646,
636,
5351,
363,
199,
199,
3,
283,
549,
7,
436,
283,
797,
7,
10621,
1133,
3247,
315,
2018,
499,
14,
17,
14,
221,
13930,
3062,
14,
199,
893,
26,
272,
715,
12,
756,
199,
2590,
12746,
26,
272,
334,
549,
12,
756,
9,
275,
334,
17,
12,
378,
9,
272,
636,
452,
363,
847,
788,
549,
297,
283,
797,
418,
199,
199,
3,
7053,
13,
2487,
3992,
4898,
21399,
315,
2018,
499,
14,
18,
14,
221,
1487,
2408,
316,
298,
785,
2,
315,
2018,
199,
3,
499,
14,
17,
19083,
2739,
675,
892,
13,
2487,
3992,
315,
5459,
402,
2018,
626,
2291,
3062,
12,
199,
3,
1830,
5139,
11075,
316,
13388,
7163,
543,
2269,
13,
2487,
3992,
199,
893,
26,
272,
909,
199,
2590,
12746,
26,
272,
1021,
909,
26,
986,
272,
636,
452,
363,
847,
788,
785,
418,
199,
199,
3,
24175,
543,
2018,
499,
14,
18,
12,
1228,
6127,
282,
2008,
367,
314,
3499,
1423,
14,
199,
3,
6121,
12,
12963,
2839,
298,
2960,
401,
298,
513,
401,
298,
495,
401,
298,
2975,
401,
298,
442,
401,
436,
298,
2809,
2,
199,
3,
506,
27467,
1642,
13,
533,
2943,
12,
7830,
2419,
3423,
14,
221,
2136,
2934,
370,
2291,
199,
3,
21638,
2839,
26,
199,
3,
257,
1228,
8,
88,
12,
334,
442,
12,
1846,
430,
199,
3,
2002,
781,
11176,
652,
367,
2018,
499,
14,
17,
14,
199,
893,
26,
272,
1228,
8,
21,
12,
334,
442,
12,
1846,
430,
199,
2590,
3146,
26,
272,
636,
452,
363,
847,
788,
6074,
418,
272,
485,
5351,
63,
466,
63,
1130,
275,
469,
267,
2008,
26,
730,
8,
4000,
267,
769,
26,
730,
25550,
267,
620,
26,
730,
11986,
395,
267,
2649,
26,
730,
8,
85,
341,
395,
267,
1109,
26,
730,
8,
16,
395,
267,
1846,
26,
730,
8,
16,
44,
395,
272,
789,
272,
347,
1228,
8,
1113,
12,
307,
304,
267,
340,
440,
636,
5351,
4343,
6074,
8,
84,
12,
730,
8,
28256,
288,
327,
307,
365,
440,
282,
2008,
288,
372,
636,
5351,
4343,
6074,
8,
1113,
12,
485,
5351,
63,
466,
63,
1130,
14,
362,
8,
84,
12,
307,
430,
267,
587,
26,
288,
327,
307,
365,
282,
2008,
288,
367,
6211,
315,
307,
26,
355,
340,
636,
5351,
4343,
6074,
8,
1113,
12,
485,
5351,
63,
466,
63,
1130,
14,
362,
8,
9749,
12,
6211,
2298,
490,
372,
715,
288,
372,
756,
199,
199,
3,
6695,
26,
409,
6714,
29,
20,
5584,
29,
20,
23014,
29,
20,
26414,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
camilonova/sentry
|
src/sentry/web/frontend/create_team.py
|
15
|
6257
|
from __future__ import absolute_import
import logging
from django.contrib import messages
from django.core.urlresolvers import reverse
from sentry.models import OrganizationMemberType
from sentry.permissions import can_create_teams, Permissions
from sentry.web.forms.add_project import AddProjectForm
from sentry.web.forms.add_team import AddTeamForm
from sentry.web.frontend.base import OrganizationView
from sentry.web.frontend.generic import missing_perm
class Step(object):
def __init__(self, form, template, can_skip=False):
self.form = form
self.template = template
self.can_skip = can_skip
def __repr__(self):
return '<%s: form=%s template=%s>' % (
type(self).__name__, self.form.__name__, self.template
)
class CreateTeamView(OrganizationView):
required_access = OrganizationMemberType.ADMIN
session_key = 'ctwizard'
form_prefix = 'ctwizard'
steps = [
Step(form=AddTeamForm, template='create-team-step-team.html'),
Step(form=AddProjectForm, template='create-team-step-project.html', can_skip=True),
]
# A lot of this logic is inspired by Django's FormWizard, but unfortunately
# using that requires us to inherit from Django's base CBVs which is not
# acceptable due to the way we handle base view validation and ACLs.
def handle(self, request, organization):
if not can_create_teams(request.user, organization):
return missing_perm(request, Permissions.ADD_TEAM)
session_data = request.session.get(self.session_key, {})
if request.method == 'GET':
logging.debug('GET request; resetting create team form wizard')
current_step = 0
try:
del request.session[self.session_key]
except KeyError:
pass
else:
current_step = int(request.POST.get('step', 0))
last_step = len(self.steps) - 1
if current_step > last_step:
logging.debug('Invalid step passed; resetting create team form wizard')
return self.render_validation_error(request, organization)
op = request.POST.get('op')
if op != 'continue':
data = None
else:
data = request.POST or None
form = self.get_step_form(current_step, data)
if op == 'continue' and form.is_valid():
session_data['step%d' % current_step] = form.cleaned_data
request.session[self.session_key] = session_data
if current_step == last_step:
# no more steps, render done view
return self.render_done(request, organization, form)
else:
# proceed to the next step
return self.render_next_step(request, organization, current_step + 1)
elif op == 'back' and current_step > 0:
return self.render_next_step(request, organization, current_step - 1)
elif op == 'skip' and current_step > 0:
session_data['step%d' % current_step] = {}
request.session[self.session_key] = session_data
if current_step == last_step:
# no more steps, render done view
return self.render_done(request, organization, form)
else:
# proceed to the next step
return self.render_next_step(request, organization, current_step + 1)
return self.render(request, organization, current_step, form)
def get_step_form(self, step, data=None, with_prefix=True):
if with_prefix:
prefix = '%s-%d' % (self.form_prefix, step)
else:
prefix = None
return self.steps[step].form(
data=data,
prefix=prefix,
)
def render(self, request, organization, step, form):
template = self.steps[step].template
context = {
'current_step': step,
'step': step,
'form': form,
'first_step': 0,
}
return self.respond('sentry/%s' % (template,), context)
def render_next_step(self, request, organization, step):
form = self.get_step_form(step)
return self.render(request, organization, step, form)
def render_validation_error(self, request, organization):
try:
del request.session[self.session_key]
except KeyError:
pass
messages.error(request, 'There was an issue validating your input. Please try again.')
return self.redirect(request.get_full_path())
def render_done(self, request, organization, last_form):
all_forms = []
session_data = request.session[self.session_key]
last_index = len(self.steps) - 1
# revalidate previous steps
for index in range(len(self.steps)):
if index == last_index:
form = last_form
else:
form = self.get_step_form(
step=index,
data=session_data.get('step%d' % (index,), {}),
with_prefix=False,
)
if self.steps[index].can_skip and not form.data:
pass
elif not form.is_valid():
logging.warning('step %d (%s) did not validate; resetting create team wizard',
index, type(form).__name__)
return self.render_validation_error(request, organization)
all_forms.append(form)
try:
return self.save(request, organization, all_forms)
finally:
del request.session[self.session_key]
def save(self, request, organization, all_forms):
team = all_forms[0].save(request.user, organization, request.META['REMOTE_ADDR'])
if all_forms[1].is_valid():
project = all_forms[1].save(request.user, team, request.META['REMOTE_ADDR'])
url = reverse('sentry-stream', args=[organization.slug, project.slug]) + '?newinstall=1'
else:
messages.success(request, 'Your new team was created successfully.')
url = reverse('sentry-organization-home', args=[organization.slug])
return self.redirect(url)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
26230,
14,
992,
492,
18863,
7021,
804,
199,
504,
26230,
14,
6060,
492,
883,
63,
981,
63,
19048,
12,
28260,
199,
504,
26230,
14,
2520,
14,
3351,
14,
525,
63,
1715,
492,
2654,
4761,
2821,
199,
504,
26230,
14,
2520,
14,
3351,
14,
525,
63,
5969,
492,
2654,
13126,
2821,
199,
504,
26230,
14,
2520,
14,
18062,
14,
1095,
492,
18863,
2768,
199,
504,
26230,
14,
2520,
14,
18062,
14,
6767,
492,
4124,
63,
8220,
421,
199,
533,
13382,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1824,
12,
1978,
12,
883,
63,
2759,
29,
797,
304,
267,
291,
14,
964,
275,
1824,
267,
291,
14,
1160,
275,
1978,
267,
291,
14,
2425,
63,
2759,
275,
883,
63,
2759,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
26,
1824,
2458,
83,
1978,
2458,
83,
3524,
450,
334,
288,
730,
8,
277,
2843,
354,
3108,
291,
14,
964,
855,
354,
3108,
291,
14,
1160,
267,
776,
421,
199,
533,
2790,
13126,
2768,
8,
15928,
2768,
304,
272,
1415,
63,
2732,
275,
18863,
7021,
804,
14,
14288,
339,
2351,
63,
498,
275,
283,
319,
9819,
7,
339,
1824,
63,
1861,
275,
283,
319,
9819,
7,
339,
7124,
275,
359,
267,
13382,
8,
964,
29,
1123,
13126,
2821,
12,
1978,
534,
981,
13,
5969,
13,
2926,
13,
5969,
14,
1360,
659,
267,
13382,
8,
964,
29,
1123,
4761,
2821,
12,
1978,
534,
981,
13,
5969,
13,
2926,
13,
1715,
14,
1360,
297,
883,
63,
2759,
29,
549,
395,
272,
1622,
339,
327,
437,
13918,
402,
642,
9661,
365,
315,
8721,
581,
701,
5634,
1159,
8204,
20120,
12,
1325,
625,
21839,
272,
327,
1808,
626,
5074,
2739,
370,
8287,
687,
5634,
1159,
1300,
445,
34,
20343,
1314,
365,
440,
272,
327,
14712,
7037,
370,
314,
4340,
781,
2429,
1300,
2455,
6411,
436,
16543,
83,
14,
272,
347,
2429,
8,
277,
12,
1056,
12,
13237,
304,
267,
340,
440,
883,
63,
981,
63,
19048,
8,
1069,
14,
751,
12,
13237,
304,
288,
372,
4124,
63,
8220,
8,
1069,
12,
28260,
14,
9732,
63,
3727,
1156,
9,
398,
2351,
63,
576,
275,
1056,
14,
1730,
14,
362,
8,
277,
14,
1730,
63,
498,
12,
5009,
267,
340,
1056,
14,
765,
508,
283,
2970,
356,
288,
2050,
14,
1757,
360,
2970,
1056,
27,
5305,
1337,
1218,
8099,
1824,
12262,
358,
288,
1453,
63,
2926,
275,
378,
288,
862,
26,
355,
2150,
1056,
14,
1730,
59,
277,
14,
1730,
63,
498,
61,
288,
871,
4067,
26,
355,
986,
267,
587,
26,
288,
1453,
63,
2926,
275,
1109,
8,
1069,
14,
4030,
14,
362,
360,
2926,
297,
378,
430,
398,
2061,
63,
2926,
275,
822,
8,
277,
14,
5895,
9,
446,
413,
398,
340,
1453,
63,
2926,
690,
2061,
63,
2926,
26,
288,
2050,
14,
1757,
360,
3364,
3650,
3032,
27,
5305,
1337,
1218,
8099,
1824,
12262,
358,
288,
372,
291,
14,
3352,
63,
6136,
63,
705,
8,
1069,
12,
13237,
9,
398,
1687,
275,
1056,
14,
4030,
14,
362,
360,
411,
358,
267,
340,
1687,
1137,
283,
6958,
356,
288,
666,
275,
488,
267,
587,
26,
288,
666,
275,
1056,
14,
4030,
503,
488,
398,
1824,
275,
291,
14,
362,
63,
2926,
63,
964,
8,
1818,
63,
2926,
12,
666,
9,
267,
340,
1687,
508,
283,
6958,
7,
436,
1824,
14,
374,
63,
1078,
837,
288,
2351,
63,
576,
459,
2926,
5,
68,
7,
450,
1453,
63,
2926,
61,
275,
1824,
14,
8275,
63,
576,
288,
1056,
14,
1730,
59,
277,
14,
1730,
63,
498,
61,
275,
2351,
63,
576,
288,
340,
1453,
63,
2926,
508,
2061,
63,
2926,
26,
355,
327,
949,
1655,
7124,
12,
3795,
4224,
2455,
355,
372,
291,
14,
3352,
63,
4456,
8,
1069,
12,
13237,
12,
1824,
9,
288,
587,
26,
355,
327,
20320,
370,
314,
2163,
3650,
355,
372,
291,
14,
3352,
63,
2184,
63,
2926,
8,
1069,
12,
13237,
12,
1453,
63,
2926,
435,
413,
9,
398,
916,
1687,
508,
283,
894,
7,
436,
1453,
63,
2926,
690,
378,
26,
288,
372,
291,
14,
3352,
63,
2184,
63,
2926,
8,
1069,
12,
13237,
12,
1453,
63,
2926,
446,
413,
9,
398,
916,
1687,
508,
283,
2759,
7,
436,
1453,
63,
2926,
690,
378,
26,
288,
2351,
63,
576,
459,
2926,
5,
68,
7,
450,
1453,
63,
2926,
61,
275,
1052,
288,
1056,
14,
1730,
59,
277,
14,
1730,
63,
498,
61,
275,
2351,
63,
576,
288,
340,
1453,
63,
2926,
508,
2061,
63,
2926,
26,
355,
327,
949,
1655,
7124,
12,
3795,
4224,
2455,
355,
372,
291,
14,
3352,
63,
4456,
8,
1069,
12,
13237,
12,
1824,
9,
288,
587,
26,
355,
327,
20320,
370,
314,
2163,
3650,
355,
372,
291,
14,
3352,
63,
2184,
63,
2926,
8,
1069,
12,
13237,
12,
1453,
63,
2926,
435,
413,
9,
398,
372,
291,
14,
3352,
8,
1069,
12,
13237,
12,
1453,
63,
2926,
12,
1824,
9,
339,
347,
664,
63,
2926,
63,
964,
8,
277,
12,
3650,
12,
666,
29,
403,
12,
543,
63,
1861,
29,
549,
304,
267,
340,
543,
63,
1861,
26,
288,
2403,
275,
1543,
83,
3295,
68,
7,
450,
334,
277,
14,
964,
63,
1861,
12,
3650,
9,
267,
587,
26,
288,
2403,
275,
488,
398,
372,
291,
14,
5895,
59,
2926,
1055,
964,
8,
288,
666,
29,
576,
12,
288,
2403,
29,
1861,
12,
267,
776,
339,
347,
3795,
8,
277,
12,
1056,
12,
13237,
12,
3650,
12,
1824,
304,
267,
1978,
275,
291,
14,
5895,
59,
2926,
1055,
1160,
267,
1067,
275,
469,
288,
283,
1818,
63,
2926,
356,
3650,
12,
288,
283,
2926,
356,
3650,
12,
288,
283,
964,
356,
1824,
12,
288,
283,
2246,
63,
2926,
356,
378,
12,
267,
789,
267,
372,
291,
14,
22720,
360,
3870,
3149,
83,
7,
450,
334,
1160,
4706,
1067,
9,
339,
347,
3795,
63,
2184,
63,
2926,
8,
277,
12,
1056,
12,
13237,
12,
3650,
304,
267,
1824,
275,
291,
14,
362,
63,
2926,
63,
964,
8,
2926,
9,
267,
372,
291,
14,
3352,
8
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
26230,
14,
992,
492,
18863,
7021,
804,
199,
504,
26230,
14,
6060,
492,
883,
63,
981,
63,
19048,
12,
28260,
199,
504,
26230,
14,
2520,
14,
3351,
14,
525,
63,
1715,
492,
2654,
4761,
2821,
199,
504,
26230,
14,
2520,
14,
3351,
14,
525,
63,
5969,
492,
2654,
13126,
2821,
199,
504,
26230,
14,
2520,
14,
18062,
14,
1095,
492,
18863,
2768,
199,
504,
26230,
14,
2520,
14,
18062,
14,
6767,
492,
4124,
63,
8220,
421,
199,
533,
13382,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1824,
12,
1978,
12,
883,
63,
2759,
29,
797,
304,
267,
291,
14,
964,
275,
1824,
267,
291,
14,
1160,
275,
1978,
267,
291,
14,
2425,
63,
2759,
275,
883,
63,
2759,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
26,
1824,
2458,
83,
1978,
2458,
83,
3524,
450,
334,
288,
730,
8,
277,
2843,
354,
3108,
291,
14,
964,
855,
354,
3108,
291,
14,
1160,
267,
776,
421,
199,
533,
2790,
13126,
2768,
8,
15928,
2768,
304,
272,
1415,
63,
2732,
275,
18863,
7021,
804,
14,
14288,
339,
2351,
63,
498,
275,
283,
319,
9819,
7,
339,
1824,
63,
1861,
275,
283,
319,
9819,
7,
339,
7124,
275,
359,
267,
13382,
8,
964,
29,
1123,
13126,
2821,
12,
1978,
534,
981,
13,
5969,
13,
2926,
13,
5969,
14,
1360,
659,
267,
13382,
8,
964,
29,
1123,
4761,
2821,
12,
1978,
534,
981,
13,
5969,
13,
2926,
13,
1715,
14,
1360,
297,
883,
63,
2759,
29,
549,
395,
272,
1622,
339,
327,
437,
13918,
402,
642,
9661,
365,
315,
8721,
581,
701,
5634,
1159,
8204,
20120,
12,
1325,
625,
21839,
272,
327,
1808,
626,
5074,
2739,
370,
8287,
687,
5634,
1159,
1300,
445,
34,
20343,
1314,
365,
440,
272,
327,
14712,
7037,
370,
314,
4340,
781,
2429,
1300,
2455,
6411,
436,
16543,
83,
14,
272,
347,
2429,
8,
277,
12,
1056,
12,
13237,
304,
267,
340,
440,
883,
63,
981,
63,
19048,
8,
1069,
14,
751,
12,
13237,
304,
288,
372,
4124,
63,
8220,
8,
1069,
12,
28260,
14,
9732,
63,
3727,
1156,
9,
398,
2351,
63,
576,
275,
1056,
14,
1730,
14,
362,
8,
277,
14,
1730,
63,
498,
12,
5009,
267,
340,
1056,
14,
765,
508,
283,
2970,
356,
288,
2050,
14,
1757,
360,
2970,
1056,
27,
5305,
1337,
1218,
8099,
1824,
12262,
358,
288,
1453,
63,
2926,
275,
378,
288,
862,
26,
355,
2150,
1056,
14,
1730,
59,
277,
14,
1730,
63,
498,
61,
288,
871,
4067,
26,
355,
986,
267,
587,
26,
288,
1453,
63,
2926,
275,
1109,
8,
1069,
14,
4030,
14,
362,
360,
2926,
297,
378,
430,
398,
2061,
63,
2926,
275,
822,
8,
277,
14,
5895,
9,
446,
413,
398,
340,
1453,
63,
2926,
690,
2061,
63,
2926,
26,
288,
2050,
14,
1757,
360,
3364,
3650,
3032,
27,
5305,
1337,
1218,
8099,
1824,
12262,
358,
288,
372,
291,
14,
3352,
63,
6136,
63,
705,
8,
1069,
12,
13237,
9,
398,
1687,
275,
1056,
14,
4030,
14,
362,
360,
411,
358,
267,
340,
1687,
1137,
283,
6958,
356,
288,
666,
275,
488,
267,
587,
26,
288,
666,
275,
1056,
14,
4030,
503,
488,
398,
1824,
275,
291,
14,
362,
63,
2926,
63,
964,
8,
1818,
63,
2926,
12,
666,
9,
267,
340,
1687,
508,
283,
6958,
7,
436,
1824,
14,
374,
63,
1078,
837,
288,
2351,
63,
576,
459,
2926,
5,
68,
7,
450,
1453,
63,
2926,
61,
275,
1824,
14,
8275,
63,
576,
288,
1056,
14,
1730,
59,
277,
14,
1730,
63,
498,
61,
275,
2351,
63,
576,
288,
340,
1453,
63,
2926,
508,
2061,
63,
2926,
26,
355,
327,
949,
1655,
7124,
12,
3795,
4224,
2455,
355,
372,
291,
14,
3352,
63,
4456,
8,
1069,
12,
13237,
12,
1824,
9,
288,
587,
26,
355,
327,
20320,
370,
314,
2163,
3650,
355,
372,
291,
14,
3352,
63,
2184,
63,
2926,
8,
1069,
12,
13237,
12,
1453,
63,
2926,
435,
413,
9,
398,
916,
1687,
508,
283,
894,
7,
436,
1453,
63,
2926,
690,
378,
26,
288,
372,
291,
14,
3352,
63,
2184,
63,
2926,
8,
1069,
12,
13237,
12,
1453,
63,
2926,
446,
413,
9,
398,
916,
1687,
508,
283,
2759,
7,
436,
1453,
63,
2926,
690,
378,
26,
288,
2351,
63,
576,
459,
2926,
5,
68,
7,
450,
1453,
63,
2926,
61,
275,
1052,
288,
1056,
14,
1730,
59,
277,
14,
1730,
63,
498,
61,
275,
2351,
63,
576,
288,
340,
1453,
63,
2926,
508,
2061,
63,
2926,
26,
355,
327,
949,
1655,
7124,
12,
3795,
4224,
2455,
355,
372,
291,
14,
3352,
63,
4456,
8,
1069,
12,
13237,
12,
1824,
9,
288,
587,
26,
355,
327,
20320,
370,
314,
2163,
3650,
355,
372,
291,
14,
3352,
63,
2184,
63,
2926,
8,
1069,
12,
13237,
12,
1453,
63,
2926,
435,
413,
9,
398,
372,
291,
14,
3352,
8,
1069,
12,
13237,
12,
1453,
63,
2926,
12,
1824,
9,
339,
347,
664,
63,
2926,
63,
964,
8,
277,
12,
3650,
12,
666,
29,
403,
12,
543,
63,
1861,
29,
549,
304,
267,
340,
543,
63,
1861,
26,
288,
2403,
275,
1543,
83,
3295,
68,
7,
450,
334,
277,
14,
964,
63,
1861,
12,
3650,
9,
267,
587,
26,
288,
2403,
275,
488,
398,
372,
291,
14,
5895,
59,
2926,
1055,
964,
8,
288,
666,
29,
576,
12,
288,
2403,
29,
1861,
12,
267,
776,
339,
347,
3795,
8,
277,
12,
1056,
12,
13237,
12,
3650,
12,
1824,
304,
267,
1978,
275,
291,
14,
5895,
59,
2926,
1055,
1160,
267,
1067,
275,
469,
288,
283,
1818,
63,
2926,
356,
3650,
12,
288,
283,
2926,
356,
3650,
12,
288,
283,
964,
356,
1824,
12,
288,
283,
2246,
63,
2926,
356,
378,
12,
267,
789,
267,
372,
291,
14,
22720,
360,
3870,
3149,
83,
7,
450,
334,
1160,
4706,
1067,
9,
339,
347,
3795,
63,
2184,
63,
2926,
8,
277,
12,
1056,
12,
13237,
12,
3650,
304,
267,
1824,
275,
291,
14,
362,
63,
2926,
63,
964,
8,
2926,
9,
267,
372,
291,
14,
3352,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
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audio_files.py
|
1
|
2652
|
#!/bin/python2
from __future__ import division
import subprocess
from time import sleep
import os
# for generating sound files
import numpy as np
import matplotlib.pyplot as plt
import scipy.io.wavfile
import scipy.signal as sig
import scipy.stats as stats
master_volume = 1
sounds = {
'A':{'filename':'tick1.wav',
'volume': .9,
'freq': 10,
'length': .01,
'quality': 1,
'tone':'sawtooth',
'a': 2,
'b': 10,},
'W':{'filename':'tick2.wav',
'volume': .8,
'freq': 5,
'length': .01,
'quality': .8,
'tone':'sawtooth',
'a': 2,
'b': 5,},
'M':{'filename':'tick3.wav',
'volume': .8,
'freq': 10,
'length': .05,
'quality': .95,
'tone':'sawtooth',
'a': 2,
'b': 5,},
'S':{'filename':'tick4.wav',
'volume': .4,
'freq': 50,
'length': .04,
'quality': .6,
'tone':'sawtooth',
'a': 2,
'b': 5,},
'U':{'filename':'tick5.wav',
'volume': .5,
'freq': 40,
'length': .02,
'quality': .9,
'tone':'sawtooth',
'a': 2,
'b': 5,},
}
def construct_sound(params, plot_sound=False):
print "constructing sound: %s" % params['filename']
rate = 44100
N = int(rate*params['length'])
time = range(N)
if params['tone'] == 'sawtooth':
raw = sig.sawtooth(np.linspace(0,params['freq'],N))
elif params['tone'] == 'sine':
# not succesfully tested, try plotting
raw = np.sin(np.linspace(0,params['freq'],N))
else:
raise RuntimeError('unknown tone type')
noise = np.random.uniform(-1, 1, N) # 44100 random samples between -1 and 1
envelope = stats.beta(params['a'],params['b']).pdf([n/N for n in time])
data = raw*params['quality'] + noise*(1-params['quality'])
data *= envelope
save_wav(data, params['filename'], params['volume'])
if plot_sound:
figure()
plt.plot(time, raw)
plt.plot(time, envelope)
plt.plot(time, data)
plt.show()
def save_wav(data, filename, volume=1):
total_volume = volume * master_volume
if total_volume > 1 or total_volume < 0:
raise RuntimeError('volume out of range')
scaled_data = np.int16(data/np.max(np.abs(data)) * total_volume * 32767)
scipy.io.wavfile.write(filename, 44100, scaled_data)
def main():
data = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8] * 10000
save_wav(data, "test.wav")
# for code in sounds.keys():
# construct_sound(sounds[code])
main()
|
gpl-3.0
|
[
3381,
1393,
15,
1548,
18,
421,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
3873,
199,
504,
900,
492,
9435,
199,
646,
747,
199,
199,
3,
367,
12999,
20453,
1584,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
7026,
14,
2308,
14,
19118,
493,
199,
646,
7026,
14,
4653,
465,
5259,
199,
646,
7026,
14,
3200,
465,
5020,
199,
199,
4133,
63,
2405,
275,
413,
199,
14990,
83,
275,
469,
272,
283,
33,
3010,
1501,
5242,
8284,
17,
14,
19118,
297,
268,
283,
2405,
356,
1275,
25,
12,
268,
283,
5646,
356,
1616,
12,
268,
283,
1267,
356,
1275,
614,
12,
268,
283,
9161,
356,
413,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
1616,
12,
1386,
272,
283,
55,
3010,
1501,
5242,
8284,
18,
14,
19118,
297,
268,
283,
2405,
356,
1275,
24,
12,
268,
283,
5646,
356,
959,
12,
268,
283,
1267,
356,
1275,
614,
12,
268,
283,
9161,
356,
1275,
24,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
959,
12,
1386,
272,
283,
45,
3010,
1501,
5242,
8284,
19,
14,
19118,
297,
268,
283,
2405,
356,
1275,
24,
12,
268,
283,
5646,
356,
1616,
12,
268,
283,
1267,
356,
1275,
1717,
12,
268,
283,
9161,
356,
1275,
2720,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
959,
12,
1386,
272,
283,
51,
3010,
1501,
5242,
8284,
20,
14,
19118,
297,
268,
283,
2405,
356,
1275,
20,
12,
268,
283,
5646,
356,
5238,
12,
268,
283,
1267,
356,
1275,
966,
12,
268,
283,
9161,
356,
1275,
22,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
959,
12,
1386,
272,
283,
53,
3010,
1501,
5242,
8284,
21,
14,
19118,
297,
268,
283,
2405,
356,
1275,
21,
12,
268,
283,
5646,
356,
6335,
12,
268,
283,
1267,
356,
1275,
996,
12,
268,
283,
9161,
356,
1275,
25,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
959,
12,
1386,
199,
93,
199,
199,
318,
6982,
63,
14990,
8,
1162,
12,
5137,
63,
14990,
29,
797,
304,
272,
870,
298,
8514,
316,
20453,
26,
450,
83,
2,
450,
1862,
459,
1501,
418,
272,
6634,
275,
10868,
1960,
272,
653,
275,
1109,
8,
1866,
10,
1162,
459,
1267,
1105,
272,
900,
275,
1425,
8,
46,
9,
339,
340,
1862,
459,
84,
368,
418,
508,
283,
2231,
87,
16453,
356,
267,
3066,
275,
5259,
14,
2231,
87,
16453,
8,
1590,
14,
11649,
8,
16,
12,
1162,
459,
5646,
995,
46,
430,
272,
916,
1862,
459,
84,
368,
418,
508,
283,
83,
1132,
356,
267,
327,
440,
27028,
5836,
12470,
12,
862,
25174,
267,
3066,
275,
980,
14,
5911,
8,
1590,
14,
11649,
8,
16,
12,
1162,
459,
5646,
995,
46,
430,
272,
587,
26,
267,
746,
6064,
360,
5187,
307,
368,
730,
358,
339,
11145,
275,
980,
14,
2355,
14,
8830,
2801,
17,
12,
413,
12,
653,
9,
327,
10868,
1960,
2196,
5845,
3382,
446,
17,
436,
413,
272,
24631,
275,
5020,
14,
5683,
8,
1162,
459,
65,
995,
1162,
459,
66,
13227,
5607,
779,
78,
15,
46,
367,
302,
315,
900,
566,
339,
666,
275,
3066,
10,
1162,
459,
9161,
418,
435,
11145,
5830,
17,
13,
1162,
459,
9161,
1105,
272,
666,
9000,
24631,
272,
3354,
63,
19118,
8,
576,
12,
1862,
459,
1501,
995,
1862,
459,
2405,
1105,
272,
340,
5137,
63,
14990,
26,
267,
9658,
342,
267,
4488,
14,
2798,
8,
521,
12,
3066,
9,
267,
4488,
14,
2798,
8,
521,
12,
24631,
9,
267,
4488,
14,
2798,
8,
521,
12,
666,
9,
267,
4488,
14,
2384,
342,
421,
199,
318,
3354,
63,
19118,
8,
576,
12,
1788,
12,
3301,
29,
17,
304,
272,
3141,
63,
2405,
275,
3301,
627,
5288,
63,
2405,
272,
340,
3141,
63,
2405,
690,
413,
503,
3141,
63,
2405,
665,
378,
26,
267,
746,
6064,
360,
2405,
734,
402,
1425,
358,
272,
17923,
63,
576,
275,
980,
14,
442,
975,
8,
576,
15,
1590,
14,
988,
8,
1590,
14,
2101,
8,
576,
430,
627,
3141,
63,
2405,
627,
20939,
1822,
9,
272,
7026,
14,
2308,
14,
19118,
493,
14,
952,
8,
1501,
12,
10868,
1960,
12,
17923,
63,
576,
9,
421,
199,
318,
2446,
837,
272,
666,
275,
359,
16,
12,
378,
14,
17,
12,
378,
14,
18,
12,
378,
14,
19,
12,
378,
14,
20,
12,
378,
14,
21,
12,
378,
14,
22,
12,
378,
14,
23,
12,
378,
14,
24,
61,
627,
11630,
272,
3354,
63,
19118,
8,
576,
12,
298,
396,
14,
19118,
531,
272,
327,
367,
1233,
315,
20453,
83,
14,
1612,
837,
272,
327,
258,
6982,
63,
14990,
8,
14990,
83,
59,
600,
566,
199,
199,
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
] |
[
1393,
15,
1548,
18,
421,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
3873,
199,
504,
900,
492,
9435,
199,
646,
747,
199,
199,
3,
367,
12999,
20453,
1584,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
7026,
14,
2308,
14,
19118,
493,
199,
646,
7026,
14,
4653,
465,
5259,
199,
646,
7026,
14,
3200,
465,
5020,
199,
199,
4133,
63,
2405,
275,
413,
199,
14990,
83,
275,
469,
272,
283,
33,
3010,
1501,
5242,
8284,
17,
14,
19118,
297,
268,
283,
2405,
356,
1275,
25,
12,
268,
283,
5646,
356,
1616,
12,
268,
283,
1267,
356,
1275,
614,
12,
268,
283,
9161,
356,
413,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
1616,
12,
1386,
272,
283,
55,
3010,
1501,
5242,
8284,
18,
14,
19118,
297,
268,
283,
2405,
356,
1275,
24,
12,
268,
283,
5646,
356,
959,
12,
268,
283,
1267,
356,
1275,
614,
12,
268,
283,
9161,
356,
1275,
24,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
959,
12,
1386,
272,
283,
45,
3010,
1501,
5242,
8284,
19,
14,
19118,
297,
268,
283,
2405,
356,
1275,
24,
12,
268,
283,
5646,
356,
1616,
12,
268,
283,
1267,
356,
1275,
1717,
12,
268,
283,
9161,
356,
1275,
2720,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
959,
12,
1386,
272,
283,
51,
3010,
1501,
5242,
8284,
20,
14,
19118,
297,
268,
283,
2405,
356,
1275,
20,
12,
268,
283,
5646,
356,
5238,
12,
268,
283,
1267,
356,
1275,
966,
12,
268,
283,
9161,
356,
1275,
22,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
959,
12,
1386,
272,
283,
53,
3010,
1501,
5242,
8284,
21,
14,
19118,
297,
268,
283,
2405,
356,
1275,
21,
12,
268,
283,
5646,
356,
6335,
12,
268,
283,
1267,
356,
1275,
996,
12,
268,
283,
9161,
356,
1275,
25,
12,
268,
283,
84,
368,
5242,
2231,
87,
16453,
297,
268,
283,
65,
356,
499,
12,
268,
283,
66,
356,
959,
12,
1386,
199,
93,
199,
199,
318,
6982,
63,
14990,
8,
1162,
12,
5137,
63,
14990,
29,
797,
304,
272,
870,
298,
8514,
316,
20453,
26,
450,
83,
2,
450,
1862,
459,
1501,
418,
272,
6634,
275,
10868,
1960,
272,
653,
275,
1109,
8,
1866,
10,
1162,
459,
1267,
1105,
272,
900,
275,
1425,
8,
46,
9,
339,
340,
1862,
459,
84,
368,
418,
508,
283,
2231,
87,
16453,
356,
267,
3066,
275,
5259,
14,
2231,
87,
16453,
8,
1590,
14,
11649,
8,
16,
12,
1162,
459,
5646,
995,
46,
430,
272,
916,
1862,
459,
84,
368,
418,
508,
283,
83,
1132,
356,
267,
327,
440,
27028,
5836,
12470,
12,
862,
25174,
267,
3066,
275,
980,
14,
5911,
8,
1590,
14,
11649,
8,
16,
12,
1162,
459,
5646,
995,
46,
430,
272,
587,
26,
267,
746,
6064,
360,
5187,
307,
368,
730,
358,
339,
11145,
275,
980,
14,
2355,
14,
8830,
2801,
17,
12,
413,
12,
653,
9,
327,
10868,
1960,
2196,
5845,
3382,
446,
17,
436,
413,
272,
24631,
275,
5020,
14,
5683,
8,
1162,
459,
65,
995,
1162,
459,
66,
13227,
5607,
779,
78,
15,
46,
367,
302,
315,
900,
566,
339,
666,
275,
3066,
10,
1162,
459,
9161,
418,
435,
11145,
5830,
17,
13,
1162,
459,
9161,
1105,
272,
666,
9000,
24631,
272,
3354,
63,
19118,
8,
576,
12,
1862,
459,
1501,
995,
1862,
459,
2405,
1105,
272,
340,
5137,
63,
14990,
26,
267,
9658,
342,
267,
4488,
14,
2798,
8,
521,
12,
3066,
9,
267,
4488,
14,
2798,
8,
521,
12,
24631,
9,
267,
4488,
14,
2798,
8,
521,
12,
666,
9,
267,
4488,
14,
2384,
342,
421,
199,
318,
3354,
63,
19118,
8,
576,
12,
1788,
12,
3301,
29,
17,
304,
272,
3141,
63,
2405,
275,
3301,
627,
5288,
63,
2405,
272,
340,
3141,
63,
2405,
690,
413,
503,
3141,
63,
2405,
665,
378,
26,
267,
746,
6064,
360,
2405,
734,
402,
1425,
358,
272,
17923,
63,
576,
275,
980,
14,
442,
975,
8,
576,
15,
1590,
14,
988,
8,
1590,
14,
2101,
8,
576,
430,
627,
3141,
63,
2405,
627,
20939,
1822,
9,
272,
7026,
14,
2308,
14,
19118,
493,
14,
952,
8,
1501,
12,
10868,
1960,
12,
17923,
63,
576,
9,
421,
199,
318,
2446,
837,
272,
666,
275,
359,
16,
12,
378,
14,
17,
12,
378,
14,
18,
12,
378,
14,
19,
12,
378,
14,
20,
12,
378,
14,
21,
12,
378,
14,
22,
12,
378,
14,
23,
12,
378,
14,
24,
61,
627,
11630,
272,
3354,
63,
19118,
8,
576,
12,
298,
396,
14,
19118,
531,
272,
327,
367,
1233,
315,
20453,
83,
14,
1612,
837,
272,
327,
258,
6982,
63,
14990,
8,
14990,
83,
59,
600,
566,
199,
199,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
|
27
|
3592
|
# -*- coding: utf-8 -*-
"""
The following test performs a random series of reads, seeks, and
tells, and checks that the results are consistent.
"""
from __future__ import absolute_import, unicode_literals
import random
import functools
from io import BytesIO
from nltk.corpus.reader import SeekableUnicodeStreamReader
def check_reader(unicode_string, encoding, n=1000):
bytestr = unicode_string.encode(encoding)
strlen = len(unicode_string)
stream = BytesIO(bytestr)
reader = SeekableUnicodeStreamReader(stream, encoding)
# Find all character positions
chars = []
while True:
pos = reader.tell()
chars.append( (pos, reader.read(1)) )
if chars[-1][1] == '': break
# Find all strings
strings = dict( (pos,'') for (pos,c) in chars )
for pos1, char in chars:
for pos2, _ in chars:
if pos2 <= pos1:
strings[pos2] += char
while True:
op = random.choice('tsrr')
# Check our position?
if op == 't': # tell
reader.tell()
# Perform a seek?
if op == 's': # seek
new_pos = random.choice([p for (p,c) in chars])
reader.seek(new_pos)
# Perform a read?
if op == 'r': # read
if random.random() < .3: pos = reader.tell()
else: pos = None
if random.random() < .2: size = None
elif random.random() < .8:
size = random.randint(0, int(strlen/6))
else: size = random.randint(0, strlen+20)
if random.random() < .8:
s = reader.read(size)
else:
s = reader.readline(size)
# check that everything's consistent
if pos is not None:
assert pos in strings
assert strings[pos].startswith(s)
n -= 1
if n == 0:
return 'passed'
#Call the randomized test function `check_reader` with a variety of
#input strings and encodings.
ENCODINGS = ['ascii', 'latin1', 'greek', 'hebrew', 'utf-16', 'utf-8']
STRINGS = [
"""
This is a test file.
It is fairly short.
""",
"This file can be encoded with latin1. \x83",
"""\
This is a test file.
Here's a blank line:
And here's some unicode: \xee \u0123 \uffe3
""",
"""\
This is a test file.
Unicode characters: \xf3 \u2222 \u3333\u4444 \u5555
""",
]
def test_reader():
for string in STRINGS:
for encoding in ENCODINGS:
try:
# skip strings that can't be encoded with the current encoding
string.encode(encoding)
yield check_reader, string, encoding
except UnicodeEncodeError:
pass
# nose shows the whole string arguments in a verbose mode; this is annoying,
# so large string test is separated.
LARGE_STRING = """\
This is a larger file. It has some lines that are longer \
than 72 characters. It's got lots of repetition. Here's \
some unicode chars: \xee \u0123 \uffe3 \ueeee \u2345
How fun! Let's repeat it twenty times.
"""*10
def test_reader_on_large_string():
for encoding in ENCODINGS:
try:
# skip strings that can't be encoded with the current encoding
LARGE_STRING.encode(encoding)
def _check(encoding, n=1000):
check_reader(LARGE_STRING, encoding, n)
yield _check, encoding
except UnicodeEncodeError:
pass
def teardown_module(module=None):
import gc
gc.collect()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1918,
2569,
511,
18628,
282,
2196,
6779,
402,
11597,
12,
1937,
6080,
12,
436,
199,
14146,
478,
12,
436,
5920,
626,
314,
2058,
787,
12137,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
646,
2196,
199,
646,
9143,
199,
504,
5890,
492,
11808,
199,
504,
24706,
14,
16780,
14,
5503,
492,
1666,
75,
461,
7087,
16132,
199,
199,
318,
1104,
63,
5503,
8,
2975,
63,
875,
12,
2644,
12,
302,
29,
5279,
304,
272,
18792,
82,
275,
2649,
63,
875,
14,
2143,
8,
2991,
9,
272,
620,
552,
275,
822,
8,
2975,
63,
875,
9,
272,
2547,
275,
11808,
8,
991,
28792,
9,
272,
7002,
275,
1666,
75,
461,
7087,
16132,
8,
1745,
12,
2644,
9,
272,
327,
6668,
1006,
4528,
12266,
272,
8365,
275,
942,
272,
1830,
715,
26,
267,
2086,
275,
7002,
14,
9974,
342,
267,
8365,
14,
740,
8,
334,
1712,
12,
7002,
14,
739,
8,
17,
430,
776,
267,
340,
8365,
1988,
17,
1527,
17,
61,
508,
8061,
2059,
272,
327,
6668,
1006,
3326,
272,
3326,
275,
1211,
8,
334,
1712,
2584,
358,
367,
334,
1712,
12,
67,
9,
315,
8365,
776,
272,
367,
2086,
17,
12,
1495,
315,
8365,
26,
267,
367,
2086,
18,
12,
485,
315,
8365,
26,
288,
340,
2086,
18,
2695,
2086,
17,
26,
355,
3326,
59,
1712,
18,
61,
847,
1495,
272,
1830,
715,
26,
267,
1687,
275,
2196,
14,
5095,
360,
1086,
9734,
358,
267,
327,
2670,
4154,
3421,
31,
267,
340,
1687,
508,
283,
84,
356,
327,
11480,
288,
7002,
14,
9974,
342,
267,
327,
14795,
282,
12005,
31,
267,
340,
1687,
508,
283,
83,
356,
327,
12005,
288,
892,
63,
1712,
275,
2196,
14,
5095,
779,
80,
367,
334,
80,
12,
67,
9,
315,
8365,
566,
288,
7002,
14,
5507,
8,
1222,
63,
1712,
9,
267,
327,
14795,
282,
1586,
31,
267,
340,
1687,
508,
283,
82,
356,
327,
1586,
288,
340,
2196,
14,
2355,
342,
665,
1275,
19,
26,
2086,
275,
7002,
14,
9974,
342,
288,
587,
26,
2086,
275,
488,
288,
340,
2196,
14,
2355,
342,
665,
1275,
18,
26,
1568,
275,
488,
288,
916,
2196,
14,
2355,
342,
665,
1275,
24,
26,
355,
1568,
275,
2196,
14,
8393,
8,
16,
12,
1109,
8,
495,
552,
15,
22,
430,
288,
587,
26,
1568,
275,
2196,
14,
8393,
8,
16,
12,
620,
552,
11,
1165,
9,
288,
340,
2196,
14,
2355,
342,
665,
1275,
24,
26,
355,
308,
275,
7002,
14,
739,
8,
890,
9,
288,
587,
26,
355,
308,
275,
7002,
14,
6407,
8,
890,
9,
288,
327,
1104,
626,
8137,
1159,
12137,
288,
340,
2086,
365,
440,
488,
26,
355,
702,
2086,
315,
3326,
355,
702,
3326,
59,
1712,
1055,
2460,
8,
83,
9,
355,
302,
4862,
413,
355,
340,
302,
508,
378,
26,
490,
372,
283,
12070,
7,
421,
199,
3,
2176,
314,
2196,
1759,
511,
805,
658,
1074,
63,
5503,
64,
543,
282,
32246,
402,
199,
3,
1210,
3326,
436,
14134,
14,
199,
199,
742,
12592,
3881,
275,
788,
4371,
297,
283,
10378,
17,
297,
283,
32007,
297,
283,
14557,
297,
283,
1624,
13,
975,
297,
283,
1624,
13,
24,
418,
199,
199,
31271,
275,
359,
272,
408,
272,
961,
365,
282,
511,
570,
14,
272,
2779,
365,
28092,
590,
3974,
14,
272,
10327,
339,
298,
2765,
570,
883,
506,
5737,
543,
16899,
17,
14,
971,
88,
2658,
401,
339,
9638,
272,
961,
365,
282,
511,
570,
14,
272,
11842,
1159,
282,
4596,
1004,
26,
339,
6061,
2348,
1159,
2005,
2649,
26,
971,
11127,
971,
85,
29555,
971,
85,
2026,
19,
272,
10327,
339,
9638,
272,
961,
365,
282,
511,
570,
14,
272,
6140,
4110,
26,
971,
1949,
19,
971,
85,
9993,
971,
85,
6772,
60,
85,
22872,
971,
85,
19161,
272,
10327,
199,
199,
61,
199,
199,
318,
511,
63,
5503,
837,
272,
367,
1059,
315,
7553,
3881,
26,
267,
367,
2644,
315,
5070,
12592,
3881,
26,
288,
862,
26,
355,
327,
3372,
3326,
626,
883,
1133,
506,
5737,
543,
314,
1453,
2644,
355,
1059,
14,
2143,
8,
2991,
9,
355,
1995,
1104,
63,
5503,
12,
1059,
12,
2644,
288,
871,
24094,
26,
355,
986,
4388,
199,
3,
11354,
13703,
314,
8852,
1059,
2368,
315,
282,
3376,
818,
27,
642,
365,
22984,
22440,
12,
199,
3,
880,
7031,
1059,
511,
365,
11673,
14,
199,
199,
15806,
63,
5353,
275,
9638,
199,
2765,
365,
282,
12142,
570,
14,
221,
2779,
965,
2005,
2385,
626,
787,
8088,
971,
199,
13797,
15323,
4110,
14,
221,
2779,
1159,
4788,
24213,
402,
6375,
3348,
14,
221,
11842,
1159,
971,
199,
3972,
2649,
8365,
26,
971,
11127,
971,
85,
29555,
971,
85,
2026,
19,
971,
310,
18777,
971,
85,
5533,
21,
199,
199,
18335,
9627,
1,
221,
12230,
1159,
11982,
652,
8900,
287,
369,
5431,
14,
199,
624,
10,
709,
199,
199,
318,
511,
63,
5503,
63,
265,
63,
9629,
63,
875,
837,
272,
367,
2644,
315,
5070,
12592,
3881,
26,
267,
862,
26,
288,
327,
3372,
3326,
626,
883,
1133,
506,
5737,
543,
314,
1453,
2644,
288,
491,
689,
4962,
63,
5353,
14,
2143,
8,
2991,
9,
288,
347,
485,
1074,
8,
2991,
12,
302,
29,
5279,
304,
355,
1104,
63,
5503,
8,
15806,
63,
5353,
12,
2644,
12,
302,
9,
953,
1995,
485,
1074,
12,
2644,
398,
871,
24094,
26,
288,
986,
199,
199,
318,
17558,
63,
578,
8,
578,
29,
403,
304,
272,
492,
9486,
272,
9486,
14,
7112,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1918,
2569,
511,
18628,
282,
2196,
6779,
402,
11597,
12,
1937,
6080,
12,
436,
199,
14146,
478,
12,
436,
5920,
626,
314,
2058,
787,
12137,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
646,
2196,
199,
646,
9143,
199,
504,
5890,
492,
11808,
199,
504,
24706,
14,
16780,
14,
5503,
492,
1666,
75,
461,
7087,
16132,
199,
199,
318,
1104,
63,
5503,
8,
2975,
63,
875,
12,
2644,
12,
302,
29,
5279,
304,
272,
18792,
82,
275,
2649,
63,
875,
14,
2143,
8,
2991,
9,
272,
620,
552,
275,
822,
8,
2975,
63,
875,
9,
272,
2547,
275,
11808,
8,
991,
28792,
9,
272,
7002,
275,
1666,
75,
461,
7087,
16132,
8,
1745,
12,
2644,
9,
272,
327,
6668,
1006,
4528,
12266,
272,
8365,
275,
942,
272,
1830,
715,
26,
267,
2086,
275,
7002,
14,
9974,
342,
267,
8365,
14,
740,
8,
334,
1712,
12,
7002,
14,
739,
8,
17,
430,
776,
267,
340,
8365,
1988,
17,
1527,
17,
61,
508,
8061,
2059,
272,
327,
6668,
1006,
3326,
272,
3326,
275,
1211,
8,
334,
1712,
2584,
358,
367,
334,
1712,
12,
67,
9,
315,
8365,
776,
272,
367,
2086,
17,
12,
1495,
315,
8365,
26,
267,
367,
2086,
18,
12,
485,
315,
8365,
26,
288,
340,
2086,
18,
2695,
2086,
17,
26,
355,
3326,
59,
1712,
18,
61,
847,
1495,
272,
1830,
715,
26,
267,
1687,
275,
2196,
14,
5095,
360,
1086,
9734,
358,
267,
327,
2670,
4154,
3421,
31,
267,
340,
1687,
508,
283,
84,
356,
327,
11480,
288,
7002,
14,
9974,
342,
267,
327,
14795,
282,
12005,
31,
267,
340,
1687,
508,
283,
83,
356,
327,
12005,
288,
892,
63,
1712,
275,
2196,
14,
5095,
779,
80,
367,
334,
80,
12,
67,
9,
315,
8365,
566,
288,
7002,
14,
5507,
8,
1222,
63,
1712,
9,
267,
327,
14795,
282,
1586,
31,
267,
340,
1687,
508,
283,
82,
356,
327,
1586,
288,
340,
2196,
14,
2355,
342,
665,
1275,
19,
26,
2086,
275,
7002,
14,
9974,
342,
288,
587,
26,
2086,
275,
488,
288,
340,
2196,
14,
2355,
342,
665,
1275,
18,
26,
1568,
275,
488,
288,
916,
2196,
14,
2355,
342,
665,
1275,
24,
26,
355,
1568,
275,
2196,
14,
8393,
8,
16,
12,
1109,
8,
495,
552,
15,
22,
430,
288,
587,
26,
1568,
275,
2196,
14,
8393,
8,
16,
12,
620,
552,
11,
1165,
9,
288,
340,
2196,
14,
2355,
342,
665,
1275,
24,
26,
355,
308,
275,
7002,
14,
739,
8,
890,
9,
288,
587,
26,
355,
308,
275,
7002,
14,
6407,
8,
890,
9,
288,
327,
1104,
626,
8137,
1159,
12137,
288,
340,
2086,
365,
440,
488,
26,
355,
702,
2086,
315,
3326,
355,
702,
3326,
59,
1712,
1055,
2460,
8,
83,
9,
355,
302,
4862,
413,
355,
340,
302,
508,
378,
26,
490,
372,
283,
12070,
7,
421,
199,
3,
2176,
314,
2196,
1759,
511,
805,
658,
1074,
63,
5503,
64,
543,
282,
32246,
402,
199,
3,
1210,
3326,
436,
14134,
14,
199,
199,
742,
12592,
3881,
275,
788,
4371,
297,
283,
10378,
17,
297,
283,
32007,
297,
283,
14557,
297,
283,
1624,
13,
975,
297,
283,
1624,
13,
24,
418,
199,
199,
31271,
275,
359,
272,
408,
272,
961,
365,
282,
511,
570,
14,
272,
2779,
365,
28092,
590,
3974,
14,
272,
10327,
339,
298,
2765,
570,
883,
506,
5737,
543,
16899,
17,
14,
971,
88,
2658,
401,
339,
9638,
272,
961,
365,
282,
511,
570,
14,
272,
11842,
1159,
282,
4596,
1004,
26,
339,
6061,
2348,
1159,
2005,
2649,
26,
971,
11127,
971,
85,
29555,
971,
85,
2026,
19,
272,
10327,
339,
9638,
272,
961,
365,
282,
511,
570,
14,
272,
6140,
4110,
26,
971,
1949,
19,
971,
85,
9993,
971,
85,
6772,
60,
85,
22872,
971,
85,
19161,
272,
10327,
199,
199,
61,
199,
199,
318,
511,
63,
5503,
837,
272,
367,
1059,
315,
7553,
3881,
26,
267,
367,
2644,
315,
5070,
12592,
3881,
26,
288,
862,
26,
355,
327,
3372,
3326,
626,
883,
1133,
506,
5737,
543,
314,
1453,
2644,
355,
1059,
14,
2143,
8,
2991,
9,
355,
1995,
1104,
63,
5503,
12,
1059,
12,
2644,
288,
871,
24094,
26,
355,
986,
4388,
199,
3,
11354,
13703,
314,
8852,
1059,
2368,
315,
282,
3376,
818,
27,
642,
365,
22984,
22440,
12,
199,
3,
880,
7031,
1059,
511,
365,
11673,
14,
199,
199,
15806,
63,
5353,
275,
9638,
199,
2765,
365,
282,
12142,
570,
14,
221,
2779,
965,
2005,
2385,
626,
787,
8088,
971,
199,
13797,
15323,
4110,
14,
221,
2779,
1159,
4788,
24213,
402,
6375,
3348,
14,
221,
11842,
1159,
971,
199,
3972,
2649,
8365,
26,
971,
11127,
971,
85,
29555,
971,
85,
2026,
19,
971,
310,
18777,
971,
85,
5533,
21,
199,
199,
18335,
9627,
1,
221,
12230,
1159,
11982,
652,
8900,
287,
369,
5431,
14,
199,
624,
10,
709,
199,
199,
318,
511,
63,
5503,
63,
265,
63,
9629,
63,
875,
837,
272,
367,
2644,
315,
5070,
12592,
3881,
26,
267,
862,
26,
288,
327,
3372,
3326,
626,
883,
1133,
506,
5737,
543,
314,
1453,
2644,
288,
491,
689,
4962,
63,
5353,
14,
2143,
8,
2991,
9,
288,
347,
485,
1074,
8,
2991,
12,
302,
29,
5279,
304,
355,
1104,
63,
5503,
8,
15806,
63,
5353,
12,
2644,
12,
302,
9,
953,
1995,
485,
1074,
12,
2644,
398,
871,
24094,
26,
288,
986,
199,
199,
318,
17558,
63,
578,
8,
578,
29,
403,
304,
272,
492,
9486,
272,
9486,
14,
7112,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
CMU-Robotics-Club/roboticsclub.org
|
projects/templatetags/txt2img.py
|
2
|
1483
|
#
# Obtained from:
# https://djangosnippets.org/snippets/2737/
#
# TODO: move this out of projects app
from django.conf import settings
from django.template import Library
from PIL import Image, ImageDraw, ImageFont
from os import path
import hashlib
import os
register = Library()
@register.filter
def txt2img(text,font_size=14,bg="#ffffff",fg="#000000",font="Roboto-Light.ttf"):
'''
txt2img tag shows on the web text as images, helping to avoid get
indexed email address and some other information you don't want
to be on search engines. Fonts should reside in the same folder of txt2img.
Usage:
{{worker.email|txt2img:18|safe}}
'''
image_dir = settings.MEDIA_ROOT+"/txt2img/" # Set the directory to store the images
if not os.path.exists(image_dir):
os.makedirs(image_dir)
img_name="{}.jpg".format(hashlib.md5(text.encode('utf8')).hexdigest())
if path.exists(image_dir+img_name): # Make sure img doesn't exist already
pass
else:
font_path = "{}/fonts/{}".format(settings.STATIC_ROOT, font)
font = ImageFont.truetype(font_path, font_size)
w, h = font.getsize(text)
img = Image.new('RGBA', (w, int(1.2*h)), bg)
draw = ImageDraw.Draw(img)
draw.text((0,0), text, font=font, fill=fg)
img.save(image_dir+img_name,"JPEG",quality=100)
imgtag = '<img src="'+settings.MEDIA_URL+'txt2img/'+img_name+'" alt="'+text+'" />'
return imgtag
|
mit
|
[
3,
199,
3,
17985,
877,
379,
687,
26,
199,
3,
4178,
921,
12816,
736,
78,
15147,
14,
1308,
15,
32566,
15,
1465,
1401,
15,
199,
3,
199,
199,
3,
3254,
26,
4057,
642,
734,
402,
11336,
1145,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1160,
492,
11243,
199,
199,
504,
14937,
492,
6047,
12,
6047,
9654,
12,
6047,
6986,
199,
504,
747,
492,
931,
199,
646,
8337,
199,
646,
747,
199,
199,
2683,
275,
11243,
342,
199,
199,
32,
2683,
14,
1541,
199,
318,
9444,
18,
4060,
8,
505,
12,
4246,
63,
890,
29,
1079,
12,
6856,
13476,
12596,
401,
9681,
13476,
3273,
401,
4246,
628,
50,
2873,
3459,
13,
16393,
14,
32264,
2349,
272,
1449,
272,
9444,
18,
4060,
1947,
13703,
641,
314,
3330,
1318,
465,
5935,
12,
1720,
316,
370,
5126,
664,
272,
15235,
3031,
2287,
436,
258,
2005,
1163,
2556,
1265,
2793,
1133,
2934,
272,
370,
506,
641,
2754,
28156,
14,
481,
13366,
1077,
295,
2441,
315,
314,
2011,
4922,
402,
9444,
18,
4060,
14,
2286,
11028,
26,
272,
8448,
6599,
14,
2123,
92,
2424,
18,
4060,
26,
1085,
92,
3489,
4863,
272,
1449,
339,
1834,
63,
694,
275,
2202,
14,
13669,
63,
5441,
24792,
2424,
18,
4060,
6687,
257,
327,
2494,
314,
2082,
370,
3877,
314,
5935,
339,
340,
440,
747,
14,
515,
14,
2444,
8,
1569,
63,
694,
304,
267,
747,
14,
8347,
8,
1569,
63,
694,
9,
339,
6050,
63,
354,
628,
31270,
8476,
1674,
908,
8,
24722,
14,
1064,
21,
8,
505,
14,
2143,
360,
1624,
24,
11103,
11453,
1012,
339,
340,
931,
14,
2444,
8,
1569,
63,
694,
11,
4060,
63,
354,
304,
327,
4155,
3238,
6050,
3181,
1133,
2187,
2575,
267,
986,
272,
587,
26,
267,
5023,
63,
515,
275,
11491,
15,
19864,
15,
13536,
908,
8,
1751,
14,
10449,
63,
5441,
12,
5023,
9,
267,
5023,
275,
6047,
6986,
14,
2052,
466,
8,
4246,
63,
515,
12,
5023,
63,
890,
9,
398,
336,
12,
394,
275,
5023,
14,
20733,
8,
505,
9,
267,
6050,
275,
6047,
14,
1222,
360,
21631,
297,
334,
87,
12,
1109,
8,
17,
14,
18,
10,
72,
1826,
12994,
9,
267,
5954,
275,
6047,
9654,
14,
9654,
8,
4060,
9,
267,
5954,
14,
505,
1332,
16,
12,
16,
395,
1318,
12,
5023,
29,
4246,
12,
5554,
29,
9681,
9,
267,
6050,
14,
2117,
8,
1569,
63,
694,
11,
4060,
63,
354,
4589,
28412,
401,
9161,
29,
1960,
9,
257,
2286,
6050,
1450,
275,
2650,
4060,
2928,
628,
6828,
1751,
14,
13669,
63,
2632,
4786,
2424,
18,
4060,
19047,
4060,
63,
354,
11,
4065,
8791,
628,
6828,
505,
11,
4065,
22294,
272,
372,
6050,
1450,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
17985,
877,
379,
687,
26,
199,
3,
4178,
921,
12816,
736,
78,
15147,
14,
1308,
15,
32566,
15,
1465,
1401,
15,
199,
3,
199,
199,
3,
3254,
26,
4057,
642,
734,
402,
11336,
1145,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1160,
492,
11243,
199,
199,
504,
14937,
492,
6047,
12,
6047,
9654,
12,
6047,
6986,
199,
504,
747,
492,
931,
199,
646,
8337,
199,
646,
747,
199,
199,
2683,
275,
11243,
342,
199,
199,
32,
2683,
14,
1541,
199,
318,
9444,
18,
4060,
8,
505,
12,
4246,
63,
890,
29,
1079,
12,
6856,
13476,
12596,
401,
9681,
13476,
3273,
401,
4246,
628,
50,
2873,
3459,
13,
16393,
14,
32264,
2349,
272,
1449,
272,
9444,
18,
4060,
1947,
13703,
641,
314,
3330,
1318,
465,
5935,
12,
1720,
316,
370,
5126,
664,
272,
15235,
3031,
2287,
436,
258,
2005,
1163,
2556,
1265,
2793,
1133,
2934,
272,
370,
506,
641,
2754,
28156,
14,
481,
13366,
1077,
295,
2441,
315,
314,
2011,
4922,
402,
9444,
18,
4060,
14,
2286,
11028,
26,
272,
8448,
6599,
14,
2123,
92,
2424,
18,
4060,
26,
1085,
92,
3489,
4863,
272,
1449,
339,
1834,
63,
694,
275,
2202,
14,
13669,
63,
5441,
24792,
2424,
18,
4060,
6687,
257,
327,
2494,
314,
2082,
370,
3877,
314,
5935,
339,
340,
440,
747,
14,
515,
14,
2444,
8,
1569,
63,
694,
304,
267,
747,
14,
8347,
8,
1569,
63,
694,
9,
339,
6050,
63,
354,
628,
31270,
8476,
1674,
908,
8,
24722,
14,
1064,
21,
8,
505,
14,
2143,
360,
1624,
24,
11103,
11453,
1012,
339,
340,
931,
14,
2444,
8,
1569,
63,
694,
11,
4060,
63,
354,
304,
327,
4155,
3238,
6050,
3181,
1133,
2187,
2575,
267,
986,
272,
587,
26,
267,
5023,
63,
515,
275,
11491,
15,
19864,
15,
13536,
908,
8,
1751,
14,
10449,
63,
5441,
12,
5023,
9,
267,
5023,
275,
6047,
6986,
14,
2052,
466,
8,
4246,
63,
515,
12,
5023,
63,
890,
9,
398,
336,
12,
394,
275,
5023,
14,
20733,
8,
505,
9,
267,
6050,
275,
6047,
14,
1222,
360,
21631,
297,
334,
87,
12,
1109,
8,
17,
14,
18,
10,
72,
1826,
12994,
9,
267,
5954,
275,
6047,
9654,
14,
9654,
8,
4060,
9,
267,
5954,
14,
505,
1332,
16,
12,
16,
395,
1318,
12,
5023,
29,
4246,
12,
5554,
29,
9681,
9,
267,
6050,
14,
2117,
8,
1569,
63,
694,
11,
4060,
63,
354,
4589,
28412,
401,
9161,
29,
1960,
9,
257,
2286,
6050,
1450,
275,
2650,
4060,
2928,
628,
6828,
1751,
14,
13669,
63,
2632,
4786,
2424,
18,
4060,
19047,
4060,
63,
354,
11,
4065,
8791,
628,
6828,
505,
11,
4065,
22294,
272,
372,
6050,
1450,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
anryko/ansible
|
lib/ansible/modules/network/check_point/cp_mgmt_session_facts.py
|
20
|
3932
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Ansible module to manage Check Point Firewall (c) 2019
#
# 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
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = """
---
module: cp_mgmt_session_facts
short_description: Get session objects facts on Check Point over Web Services API
description:
- Get session objects facts on Check Point devices.
- All operations are performed over Web Services API.
- This module handles both operations, get a specific object and get several objects,
For getting a specific object use the parameter 'name'.
version_added: "2.9"
author: "Or Soffer (@chkp-orso)"
options:
limit:
description:
- No more than that many results will be returned.
This parameter is relevant only for getting few objects.
type: int
offset:
description:
- Skip that many results before beginning to return them.
This parameter is relevant only for getting few objects.
type: int
order:
description:
- Sorts results by the given field. By default the results are sorted in the descending order by the session publish time.
This parameter is relevant only for getting few objects.
type: list
suboptions:
ASC:
description:
- Sorts results by the given field in ascending order.
type: str
choices: ['name']
DESC:
description:
- Sorts results by the given field in descending order.
type: str
choices: ['name']
view_published_sessions:
description:
- Show a list of published sessions.
type: bool
details_level:
description:
- The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed
representation of the object.
type: str
choices: ['uid', 'standard', 'full']
extends_documentation_fragment: checkpoint_facts
"""
EXAMPLES = """
- name: show-session
cp_mgmt_session_facts:
- name: show-sessions
cp_mgmt_session_facts:
details_level: standard
limit: 50
offset: 0
"""
RETURN = """
ansible_facts:
description: The checkpoint object facts.
returned: always.
type: dict
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.checkpoint.checkpoint import checkpoint_argument_spec_for_facts, api_call_facts
def main():
argument_spec = dict(
limit=dict(type='int'),
offset=dict(type='int'),
order=dict(type='list', options=dict(
ASC=dict(type='str', choices=['name']),
DESC=dict(type='str', choices=['name'])
)),
view_published_sessions=dict(type='bool'),
details_level=dict(type='str', choices=['uid', 'standard', 'full'])
)
argument_spec.update(checkpoint_argument_spec_for_facts)
module = AnsibleModule(argument_spec=argument_spec)
api_call_object = "session"
api_call_object_plural_version = "sessions"
result = api_call_facts(module, api_call_object, api_call_object_plural_version)
module.exit_json(ansible_facts=result)
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,
2622,
859,
370,
9635,
2670,
7584,
15967,
7567,
334,
67,
9,
20312,
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,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
7667,
63,
9752,
63,
1730,
63,
5047,
199,
3612,
63,
1802,
26,
2372,
2351,
2251,
9036,
641,
2670,
7584,
1806,
6001,
21813,
3261,
199,
1802,
26,
523,
446,
2372,
2351,
2251,
9036,
641,
2670,
7584,
7256,
14,
523,
446,
2900,
5331,
787,
10585,
1806,
6001,
21813,
3261,
14,
523,
446,
961,
859,
10022,
3865,
5331,
12,
664,
282,
2488,
909,
436,
664,
9978,
2251,
12,
272,
2104,
10232,
282,
2488,
909,
675,
314,
2725,
283,
354,
1370,
199,
1023,
63,
3270,
26,
298,
18,
14,
25,
2,
199,
2502,
26,
298,
2844,
2002,
1260,
8593,
14823,
80,
13,
269,
1152,
2924,
199,
1419,
26,
523,
2304,
26,
272,
1369,
26,
489,
446,
3091,
1655,
2419,
626,
5002,
2058,
911,
506,
2138,
14,
267,
961,
2725,
365,
12082,
1454,
367,
10232,
9284,
2251,
14,
272,
730,
26,
1109,
523,
3268,
26,
272,
1369,
26,
489,
446,
8232,
626,
5002,
2058,
2544,
9608,
370,
372,
3062,
14,
267,
961,
2725,
365,
12082,
1454,
367,
10232,
9284,
2251,
14,
272,
730,
26,
1109,
523,
1865,
26,
272,
1369,
26,
489,
446,
16722,
83,
2058,
701,
314,
1627,
901,
14,
4885,
849,
314,
2058,
787,
3355,
315,
314,
27524,
1865,
701,
314,
2351,
2780,
900,
14,
267,
961,
2725,
365,
12082,
1454,
367,
10232,
9284,
2251,
14,
272,
730,
26,
769,
272,
26265,
26,
489,
20955,
26,
267,
1369,
26,
881,
446,
16722,
83,
2058,
701,
314,
1627,
901,
315,
24525,
1865,
14,
267,
730,
26,
620,
267,
3415,
26,
788,
354,
418,
489,
23915,
26,
267,
1369,
26,
881,
446,
16722,
83,
2058,
701,
314,
1627,
901,
315,
27524,
1865,
14,
267,
730,
26,
620,
267,
3415,
26,
788,
354,
418,
523,
2455,
63,
8987,
63,
11676,
26,
272,
1369,
26,
489,
446,
12968,
282,
769,
402,
3267,
12184,
14,
272,
730,
26,
2155,
523,
2436,
63,
1896,
26,
272,
1369,
26,
489,
446,
710,
2166,
402,
10093,
367,
2005,
402,
314,
1504,
315,
314,
1177,
883,
17083,
687,
21207,
1454,
314,
20746,
574,
402,
314,
909,
370,
282,
9999,
16212,
267,
6025,
402,
314,
909,
14,
272,
730,
26,
620,
272,
3415,
26,
788,
1535,
297,
283,
6807,
297,
283,
2861,
418,
199,
11036,
63,
9970,
63,
7677,
26,
9997,
63,
5047,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
2498,
13,
1730,
523,
7667,
63,
9752,
63,
1730,
63,
5047,
26,
199,
199,
13,
536,
26,
2498,
13,
11676,
523,
7667,
63,
9752,
63,
1730,
63,
5047,
26,
272,
2436,
63,
1896,
26,
4465,
272,
2304,
26,
5238,
272,
3268,
26,
378,
199,
624,
199,
199,
9677,
275,
408,
199,
4853,
63,
5047,
26,
523,
1369,
26,
710,
9997,
909,
9036,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
1211,
199,
624,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
10109,
14,
10109,
492,
9997,
63,
2094,
63,
1650,
63,
509,
63,
5047,
12,
2986,
63,
1250,
63,
5047,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
1211,
8,
267,
2304,
29,
807,
8,
466,
534,
442,
659,
267,
3268,
29,
807,
8,
466,
534,
442,
659,
267,
1865,
29,
807,
8,
466,
534,
513,
297,
1511,
29,
807,
8,
288,
20955,
29,
807,
8,
466,
534,
495,
297,
3415,
2968,
354,
3815,
288,
23915,
29,
807,
8,
466,
534,
495,
297,
3415,
2968,
354,
1105,
267,
22583,
267,
2455,
63,
8987,
63,
11676,
29,
807,
8,
466,
534,
2245,
659,
267,
2436,
63,
1896,
29,
807,
8,
466,
534,
495,
297,
3415,
2968,
1535,
297,
283,
6807,
297,
283,
2861,
1105,
272,
776,
272,
1423,
63,
1650,
14,
873,
8,
10109,
63,
2094,
63,
1650,
63,
509,
63,
5047,
9,
339,
859,
275,
6953,
8,
2094,
63,
1650,
29,
2094,
63,
1650,
9,
339,
2986,
63,
1250,
63,
785,
275,
298,
1730,
2,
272,
2986,
63,
1250,
63,
785,
63,
10019,
63,
1023,
275,
298,
11676,
2,
339,
754,
275,
2986,
63,
1250,
63,
5047,
8,
578,
12,
2986,
63,
1250,
63,
785,
12,
2986,
63,
1250,
63,
785,
63,
10019,
63,
1023,
9,
272,
859,
14,
2224,
63,
1001,
8,
4853,
63,
5047,
29,
1099,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
2622,
859,
370,
9635,
2670,
7584,
15967,
7567,
334,
67,
9,
20312,
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,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
7667,
63,
9752,
63,
1730,
63,
5047,
199,
3612,
63,
1802,
26,
2372,
2351,
2251,
9036,
641,
2670,
7584,
1806,
6001,
21813,
3261,
199,
1802,
26,
523,
446,
2372,
2351,
2251,
9036,
641,
2670,
7584,
7256,
14,
523,
446,
2900,
5331,
787,
10585,
1806,
6001,
21813,
3261,
14,
523,
446,
961,
859,
10022,
3865,
5331,
12,
664,
282,
2488,
909,
436,
664,
9978,
2251,
12,
272,
2104,
10232,
282,
2488,
909,
675,
314,
2725,
283,
354,
1370,
199,
1023,
63,
3270,
26,
298,
18,
14,
25,
2,
199,
2502,
26,
298,
2844,
2002,
1260,
8593,
14823,
80,
13,
269,
1152,
2924,
199,
1419,
26,
523,
2304,
26,
272,
1369,
26,
489,
446,
3091,
1655,
2419,
626,
5002,
2058,
911,
506,
2138,
14,
267,
961,
2725,
365,
12082,
1454,
367,
10232,
9284,
2251,
14,
272,
730,
26,
1109,
523,
3268,
26,
272,
1369,
26,
489,
446,
8232,
626,
5002,
2058,
2544,
9608,
370,
372,
3062,
14,
267,
961,
2725,
365,
12082,
1454,
367,
10232,
9284,
2251,
14,
272,
730,
26,
1109,
523,
1865,
26,
272,
1369,
26,
489,
446,
16722,
83,
2058,
701,
314,
1627,
901,
14,
4885,
849,
314,
2058,
787,
3355,
315,
314,
27524,
1865,
701,
314,
2351,
2780,
900,
14,
267,
961,
2725,
365,
12082,
1454,
367,
10232,
9284,
2251,
14,
272,
730,
26,
769,
272,
26265,
26,
489,
20955,
26,
267,
1369,
26,
881,
446,
16722,
83,
2058,
701,
314,
1627,
901,
315,
24525,
1865,
14,
267,
730,
26,
620,
267,
3415,
26,
788,
354,
418,
489,
23915,
26,
267,
1369,
26,
881,
446,
16722,
83,
2058,
701,
314,
1627,
901,
315,
27524,
1865,
14,
267,
730,
26,
620,
267,
3415,
26,
788,
354,
418,
523,
2455,
63,
8987,
63,
11676,
26,
272,
1369,
26,
489,
446,
12968,
282,
769,
402,
3267,
12184,
14,
272,
730,
26,
2155,
523,
2436,
63,
1896,
26,
272,
1369,
26,
489,
446,
710,
2166,
402,
10093,
367,
2005,
402,
314,
1504,
315,
314,
1177,
883,
17083,
687,
21207,
1454,
314,
20746,
574,
402,
314,
909,
370,
282,
9999,
16212,
267,
6025,
402,
314,
909,
14,
272,
730,
26,
620,
272,
3415,
26,
788,
1535,
297,
283,
6807,
297,
283,
2861,
418,
199,
11036,
63,
9970,
63,
7677,
26,
9997,
63,
5047,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
2498,
13,
1730,
523,
7667,
63,
9752,
63,
1730,
63,
5047,
26,
199,
199,
13,
536,
26,
2498,
13,
11676,
523,
7667,
63,
9752,
63,
1730,
63,
5047,
26,
272,
2436,
63,
1896,
26,
4465,
272,
2304,
26,
5238,
272,
3268,
26,
378,
199,
624,
199,
199,
9677,
275,
408,
199,
4853,
63,
5047,
26,
523,
1369,
26,
710,
9997,
909,
9036,
14,
523,
2138,
26,
3544,
14,
523,
730,
26,
1211,
199,
624,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
10109,
14,
10109,
492,
9997,
63,
2094,
63,
1650,
63,
509,
63,
5047,
12,
2986,
63,
1250,
63,
5047,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
1211,
8,
267,
2304,
29,
807,
8,
466,
534,
442,
659,
267,
3268,
29,
807,
8,
466,
534,
442,
659,
267,
1865,
29,
807,
8,
466,
534,
513,
297,
1511,
29,
807,
8,
288,
20955,
29,
807,
8,
466,
534,
495,
297,
3415,
2968,
354,
3815,
288,
23915,
29,
807,
8,
466,
534,
495,
297,
3415,
2968,
354,
1105,
267,
22583,
267,
2455,
63,
8987,
63,
11676,
29,
807,
8,
466,
534,
2245,
659,
267,
2436,
63,
1896,
29,
807,
8,
466,
534,
495,
297,
3415,
2968,
1535,
297,
283,
6807,
297,
283,
2861,
1105,
272,
776,
272,
1423,
63,
1650,
14,
873,
8,
10109,
63,
2094,
63,
1650,
63,
509,
63,
5047,
9,
339,
859,
275,
6953,
8,
2094,
63,
1650,
29,
2094,
63,
1650,
9,
339,
2986,
63,
1250,
63,
785,
275,
298,
1730,
2,
272,
2986,
63,
1250,
63,
785,
63,
10019,
63,
1023,
275,
298,
11676,
2,
339,
754,
275,
2986,
63,
1250,
63,
5047,
8,
578,
12,
2986,
63,
1250,
63,
785,
12,
2986,
63,
1250,
63,
785,
63,
10019,
63,
1023,
9,
272,
859,
14,
2224,
63,
1001,
8,
4853,
63,
5047,
29,
1099,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
arjunkhode/ASP
|
lectures/03-Fourier-properties/plots-code/symmetry-real-even.py
|
26
|
1150
|
import matplotlib.pyplot as plt
import numpy as np
import sys
import math
from scipy.signal import triang
from scipy.fftpack import fft, fftshift
M = 127
N = 128
hM1 = int(math.floor((M+1)/2))
hM2 = int(math.floor(M/2))
x = triang(M)
fftbuffer = np.zeros(N)
fftbuffer[:hM1] = x[hM2:]
fftbuffer[N-hM2:] = x[:hM2]
X = fftshift(fft(fftbuffer))
mX = abs(X)
pX = np.unwrap(np.angle(X))
plt.figure(1, figsize=(9.5, 4))
plt.subplot(311)
plt.title('x[n]')
plt.plot(np.arange(-hM2, hM1, 1.0), x, 'b', lw=1.5)
plt.axis([-hM2, hM1, 0, 1])
plt.subplot(323)
plt.title('real(X)')
plt.plot(np.arange(-N/2, N/2, 1.0), np.real(X), 'r', lw=1.5)
plt.axis([-N/2, N/2, min(np.real(X)), max(np.real(X))])
plt.subplot(324)
plt.title('im(X)')
plt.plot(np.arange(-N/2, N/2, 1.0), np.imag(X), 'c', lw=1.5)
plt.axis([-N/2, N/2, -1, 1])
plt.subplot(325)
plt.title('abs(X)')
plt.plot(np.arange(-N/2, N/2, 1.0), mX, 'r', lw=1.5)
plt.axis([-N/2,N/2,min(mX),max(mX)])
plt.subplot(326)
plt.title('angle(X)')
plt.plot(np.arange(-N/2, N/2, 1.0), pX, 'c', lw=1.5)
plt.axis([-N/2, N/2, -1, 1])
plt.tight_layout()
plt.savefig('symmetry-real-even.png')
plt.show()
|
agpl-3.0
|
[
646,
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
646,
984,
199,
646,
3473,
199,
504,
7026,
14,
4653,
492,
3229,
621,
199,
504,
7026,
14,
9996,
1389,
492,
18160,
12,
18160,
4723,
421,
199,
45,
275,
12792,
199,
46,
275,
7960,
199,
72,
45,
17,
275,
1109,
8,
3442,
14,
11289,
1332,
45,
11,
17,
2447,
18,
430,
221,
199,
72,
45,
18,
275,
1109,
8,
3442,
14,
11289,
8,
45,
15,
18,
430,
221,
199,
88,
275,
3229,
621,
8,
45,
9,
199,
9996,
2738,
275,
980,
14,
4250,
8,
46,
9,
199,
9996,
2738,
1491,
72,
45,
17,
61,
275,
671,
59,
72,
45,
18,
2938,
199,
9996,
2738,
59,
46,
13,
72,
45,
18,
2938,
275,
671,
1491,
72,
45,
18,
61,
221,
199,
56,
275,
18160,
4723,
8,
9996,
8,
9996,
2738,
430,
199,
77,
56,
275,
2853,
8,
56,
9,
258,
199,
80,
56,
275,
980,
14,
28896,
8,
1590,
14,
4593,
8,
56,
430,
199,
199,
6003,
14,
8941,
8,
17,
12,
6085,
890,
2687,
25,
14,
21,
12,
841,
430,
199,
6003,
14,
13334,
8,
17539,
9,
199,
6003,
14,
1213,
360,
88,
59,
78,
10374,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
72,
45,
18,
12,
394,
45,
17,
12,
413,
14,
16,
395,
671,
12,
283,
66,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
72,
45,
18,
12,
394,
45,
17,
12,
378,
12,
413,
566,
199,
199,
6003,
14,
13334,
8,
13905,
9,
199,
6003,
14,
1213,
360,
3093,
8,
56,
5942,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
46,
15,
18,
12,
653,
15,
18,
12,
413,
14,
16,
395,
980,
14,
3093,
8,
56,
395,
283,
82,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
46,
15,
18,
12,
653,
15,
18,
12,
1748,
8,
1590,
14,
3093,
8,
56,
1826,
1390,
8,
1590,
14,
3093,
8,
56,
18229,
199,
199,
6003,
14,
13334,
8,
12744,
9,
199,
6003,
14,
1213,
360,
1017,
8,
56,
5942,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
46,
15,
18,
12,
653,
15,
18,
12,
413,
14,
16,
395,
980,
14,
14688,
8,
56,
395,
283,
67,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
46,
15,
18,
12,
653,
15,
18,
12,
446,
17,
12,
413,
566,
420,
199,
199,
6003,
14,
13334,
8,
13288,
9,
199,
6003,
14,
1213,
360,
2101,
8,
56,
5942,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
46,
15,
18,
12,
653,
15,
18,
12,
413,
14,
16,
395,
333,
56,
12,
283,
82,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
46,
15,
18,
12,
46,
15,
18,
12,
827,
8,
77,
56,
395,
988,
8,
77,
56,
3948,
257,
199,
199,
6003,
14,
13334,
8,
8342,
9,
199,
6003,
14,
1213,
360,
4593,
8,
56,
5942,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
46,
15,
18,
12,
653,
15,
18,
12,
413,
14,
16,
395,
299,
56,
12,
283,
67,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
46,
15,
18,
12,
653,
15,
18,
12,
446,
17,
12,
413,
566,
259,
199,
199,
6003,
14,
23787,
63,
4209,
342,
199,
6003,
14,
19556,
360,
3840,
10987,
13,
3093,
13,
12056,
14,
4524,
358,
199,
6003,
14,
2384,
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
] |
[
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
646,
984,
199,
646,
3473,
199,
504,
7026,
14,
4653,
492,
3229,
621,
199,
504,
7026,
14,
9996,
1389,
492,
18160,
12,
18160,
4723,
421,
199,
45,
275,
12792,
199,
46,
275,
7960,
199,
72,
45,
17,
275,
1109,
8,
3442,
14,
11289,
1332,
45,
11,
17,
2447,
18,
430,
221,
199,
72,
45,
18,
275,
1109,
8,
3442,
14,
11289,
8,
45,
15,
18,
430,
221,
199,
88,
275,
3229,
621,
8,
45,
9,
199,
9996,
2738,
275,
980,
14,
4250,
8,
46,
9,
199,
9996,
2738,
1491,
72,
45,
17,
61,
275,
671,
59,
72,
45,
18,
2938,
199,
9996,
2738,
59,
46,
13,
72,
45,
18,
2938,
275,
671,
1491,
72,
45,
18,
61,
221,
199,
56,
275,
18160,
4723,
8,
9996,
8,
9996,
2738,
430,
199,
77,
56,
275,
2853,
8,
56,
9,
258,
199,
80,
56,
275,
980,
14,
28896,
8,
1590,
14,
4593,
8,
56,
430,
199,
199,
6003,
14,
8941,
8,
17,
12,
6085,
890,
2687,
25,
14,
21,
12,
841,
430,
199,
6003,
14,
13334,
8,
17539,
9,
199,
6003,
14,
1213,
360,
88,
59,
78,
10374,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
72,
45,
18,
12,
394,
45,
17,
12,
413,
14,
16,
395,
671,
12,
283,
66,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
72,
45,
18,
12,
394,
45,
17,
12,
378,
12,
413,
566,
199,
199,
6003,
14,
13334,
8,
13905,
9,
199,
6003,
14,
1213,
360,
3093,
8,
56,
5942,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
46,
15,
18,
12,
653,
15,
18,
12,
413,
14,
16,
395,
980,
14,
3093,
8,
56,
395,
283,
82,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
46,
15,
18,
12,
653,
15,
18,
12,
1748,
8,
1590,
14,
3093,
8,
56,
1826,
1390,
8,
1590,
14,
3093,
8,
56,
18229,
199,
199,
6003,
14,
13334,
8,
12744,
9,
199,
6003,
14,
1213,
360,
1017,
8,
56,
5942,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
46,
15,
18,
12,
653,
15,
18,
12,
413,
14,
16,
395,
980,
14,
14688,
8,
56,
395,
283,
67,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
46,
15,
18,
12,
653,
15,
18,
12,
446,
17,
12,
413,
566,
420,
199,
199,
6003,
14,
13334,
8,
13288,
9,
199,
6003,
14,
1213,
360,
2101,
8,
56,
5942,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
46,
15,
18,
12,
653,
15,
18,
12,
413,
14,
16,
395,
333,
56,
12,
283,
82,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
46,
15,
18,
12,
46,
15,
18,
12,
827,
8,
77,
56,
395,
988,
8,
77,
56,
3948,
257,
199,
199,
6003,
14,
13334,
8,
8342,
9,
199,
6003,
14,
1213,
360,
4593,
8,
56,
5942,
199,
6003,
14,
2798,
8,
1590,
14,
5605,
2801,
46,
15,
18,
12,
653,
15,
18,
12,
413,
14,
16,
395,
299,
56,
12,
283,
67,
297,
20482,
29,
17,
14,
21,
9,
199,
6003,
14,
3127,
11468,
46,
15,
18,
12,
653,
15,
18,
12,
446,
17,
12,
413,
566,
259,
199,
199,
6003,
14,
23787,
63,
4209,
342,
199,
6003,
14,
19556,
360,
3840,
10987,
13,
3093,
13,
12056,
14,
4524,
358,
199,
6003,
14,
2384,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kaarolch/ansible
|
lib/ansible/modules/files/ini_file.py
|
16
|
10123
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2012, Jan-Piet Mens <jpmens () gmail.com>
# (c) 2015, Ales Nosek <anosek.nosek () gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = '''
---
module: ini_file
short_description: Tweak settings in INI files
extends_documentation_fragment: files
description:
- Manage (add, remove, change) individual settings in an INI-style file without having
to manage the file as a whole with, say, M(template) or M(assemble). Adds missing
sections if they don't exist.
- Before version 2.0, comments are discarded when the source file is read, and therefore will not show up in the destination file.
version_added: "0.9"
options:
dest:
description:
- Path to the INI-style file; this file is created if required
required: true
default: null
section:
description:
- Section name in INI file. This is added if C(state=present) automatically when
a single value is being set.
required: true
default: null
option:
description:
- if set (required for changing a I(value)), this is the name of the option.
- May be omitted if adding/removing a whole I(section).
required: false
default: null
value:
description:
- the string value to be associated with an I(option). May be omitted when removing an I(option).
required: false
default: null
backup:
description:
- Create a backup file including the timestamp information so you can get
the original file back if you somehow clobbered it incorrectly.
required: false
default: "no"
choices: [ "yes", "no" ]
others:
description:
- all arguments accepted by the M(file) module also work here
required: false
state:
description:
- If set to C(absent) the option or section will be removed if present instead of created.
required: false
default: "present"
choices: [ "present", "absent" ]
no_extra_spaces:
description:
- do not insert spaces before and after '=' symbol
required: false
default: false
version_added: "2.1"
create:
required: false
choices: [ "yes", "no" ]
default: "yes"
description:
- If set to 'no', the module will fail if the file does not already exist.
By default it will create the file if it is missing.
version_added: "2.2"
notes:
- While it is possible to add an I(option) without specifying a I(value), this makes
no sense.
author:
- "Jan-Piet Mens (@jpmens)"
- "Ales Nosek (@noseka1)"
'''
EXAMPLES = '''
# Ensure "fav=lemonade is in section "[drinks]" in specified file
- ini_file:
dest: /etc/conf
section: drinks
option: fav
value: lemonade
mode: 0600
backup: yes
- ini_file:
dest: /etc/anotherconf
section: drinks
option: temperature
value: cold
backup: yes
'''
import os
import re
# ==============================================================
# match_opt
def match_opt(option, line):
option = re.escape(option)
return re.match(' *%s( |\t)*=' % option, line) \
or re.match('# *%s( |\t)*=' % option, line) \
or re.match('; *%s( |\t)*=' % option, line)
# ==============================================================
# match_active_opt
def match_active_opt(option, line):
option = re.escape(option)
return re.match(' *%s( |\t)*=' % option, line)
# ==============================================================
# do_ini
def do_ini(module, filename, section=None, option=None, value=None,
state='present', backup=False, no_extra_spaces=False, create=False):
diff = {'before': '',
'after': '',
'before_header': '%s (content)' % filename,
'after_header': '%s (content)' % filename}
if not os.path.exists(filename):
if not create:
module.fail_json(rc=257, msg='Destination %s does not exist !' % filename)
destpath = os.path.dirname(filename)
if not os.path.exists(destpath) and not module.check_mode:
os.makedirs(destpath)
ini_lines = []
else:
ini_file = open(filename, 'r')
try:
ini_lines = ini_file.readlines()
finally:
ini_file.close()
if module._diff:
diff['before'] = ''.join(ini_lines)
# append a fake section line to simplify the logic
ini_lines.append('[')
within_section = not section
section_start = 0
changed = False
msg = 'OK'
if no_extra_spaces:
assignment_format = '%s=%s\n'
else:
assignment_format = '%s = %s\n'
for index, line in enumerate(ini_lines):
if line.startswith('[%s]' % section):
within_section = True
section_start = index
elif line.startswith('['):
if within_section:
if state == 'present':
# insert missing option line at the end of the section
for i in range(index, 0, -1):
# search backwards for previous non-blank or non-comment line
if not re.match(r'^[ \t]*([#;].*)?$', ini_lines[i - 1]):
ini_lines.insert(i, assignment_format % (option, value))
msg = 'option added'
changed = True
break
elif state == 'absent' and not option:
# remove the entire section
del ini_lines[section_start:index]
msg = 'section removed'
changed = True
break
else:
if within_section and option:
if state == 'present':
# change the existing option line
if match_opt(option, line):
newline = assignment_format % (option, value)
changed = ini_lines[index] != newline
if changed:
msg = 'option changed'
ini_lines[index] = newline
if changed:
# remove all possible option occurrences from the rest of the section
index = index + 1
while index < len(ini_lines):
line = ini_lines[index]
if line.startswith('['):
break
if match_active_opt(option, line):
del ini_lines[index]
else:
index = index + 1
break
elif state == 'absent':
# delete the existing line
if match_active_opt(option, line):
del ini_lines[index]
changed = True
msg = 'option changed'
break
# remove the fake section line
del ini_lines[-1:]
if not within_section and option and state == 'present':
ini_lines.append('[%s]\n' % section)
ini_lines.append(assignment_format % (option, value))
changed = True
msg = 'section and option added'
if module._diff:
diff['after'] = ''.join(ini_lines)
backup_file = None
if changed and not module.check_mode:
if backup:
backup_file = module.backup_local(filename)
ini_file = open(filename, 'w')
try:
ini_file.writelines(ini_lines)
finally:
ini_file.close()
return (changed, backup_file, diff, msg)
# ==============================================================
# main
def main():
module = AnsibleModule(
argument_spec = dict(
dest = dict(required=True),
section = dict(required=True),
option = dict(required=False),
value = dict(required=False),
backup = dict(default='no', type='bool'),
state = dict(default='present', choices=['present', 'absent']),
no_extra_spaces = dict(required=False, default=False, type='bool'),
create=dict(default=True, type='bool')
),
add_file_common_args = True,
supports_check_mode = True
)
dest = os.path.expanduser(module.params['dest'])
section = module.params['section']
option = module.params['option']
value = module.params['value']
state = module.params['state']
backup = module.params['backup']
no_extra_spaces = module.params['no_extra_spaces']
create = module.params['create']
(changed,backup_file,diff,msg) = do_ini(module, dest, section, option, value, state, backup, no_extra_spaces, create)
if not module.check_mode and os.path.exists(dest):
file_args = module.load_file_common_arguments(module.params)
changed = module.set_fs_attributes_if_different(file_args, changed)
results = { 'changed': changed, 'msg': msg, 'dest': dest, 'diff': diff }
if backup_file is not None:
results['backup_file'] = backup_file
# Mission complete
module.exit_json(**results)
# import module snippets
from ansible.module_utils.basic 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,
6029,
12,
17474,
13,
10542,
386,
603,
8764,
665,
11538,
278,
561,
6248,
29712,
14,
957,
30,
199,
3,
334,
67,
9,
6900,
12,
437,
2978,
3091,
261,
75,
665,
290,
3362,
75,
14,
21085,
75,
6248,
29712,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
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,
20364,
63,
493,
199,
3612,
63,
1802,
26,
377,
10350,
2202,
315,
1621,
41,
1584,
199,
11036,
63,
9970,
63,
7677,
26,
1584,
199,
1802,
26,
1362,
446,
14944,
334,
525,
12,
2813,
12,
1570,
9,
8212,
2202,
315,
376,
1621,
41,
13,
2487,
570,
1928,
9445,
2126,
370,
9635,
314,
570,
465,
282,
8852,
543,
12,
14722,
12,
603,
8,
1160,
9,
503,
603,
8,
21263,
680,
15747,
4124,
2126,
10189,
340,
2985,
2793,
1133,
2187,
14,
1362,
446,
21467,
1015,
499,
14,
16,
12,
6786,
787,
22002,
1380,
314,
1350,
570,
365,
1586,
12,
436,
16119,
911,
440,
2498,
1536,
315,
314,
5724,
570,
14,
199,
1023,
63,
3270,
26,
298,
16,
14,
25,
2,
199,
1419,
26,
523,
2053,
26,
272,
1369,
26,
489,
446,
6912,
370,
314,
1621,
41,
13,
2487,
570,
27,
642,
570,
365,
2737,
340,
1415,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
3420,
26,
272,
1369,
26,
489,
446,
15247,
536,
315,
1621,
41,
570,
14,
961,
365,
3483,
340,
445,
8,
929,
29,
1881,
9,
5847,
1380,
267,
282,
2849,
574,
365,
3769,
663,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
945,
26,
272,
1369,
26,
489,
446,
340,
663,
334,
2427,
367,
13729,
282,
473,
8,
585,
1826,
642,
365,
314,
536,
402,
314,
945,
14,
489,
446,
10162,
506,
11684,
340,
7791,
15,
264,
7665,
282,
8852,
473,
8,
2792,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
574,
26,
272,
1369,
26,
1362,
446,
314,
1059,
574,
370,
506,
4568,
543,
376,
473,
8,
1422,
680,
10162,
506,
11684,
1380,
12881,
376,
473,
8,
1422,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
6902,
26,
272,
1369,
26,
489,
446,
2790,
282,
6902,
570,
5893,
314,
4913,
2556,
880,
1265,
883,
664,
267,
314,
3379,
570,
1771,
340,
1265,
29437,
286,
1191,
18897,
652,
22743,
14,
272,
1415,
26,
3055,
272,
849,
26,
298,
889,
2,
272,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
523,
11789,
26,
1362,
1369,
26,
2126,
446,
1006,
2368,
10226,
701,
314,
603,
8,
493,
9,
859,
2597,
1736,
2348,
1362,
1415,
26,
3055,
523,
1174,
26,
1362,
1369,
26,
2126,
446,
982,
663,
370,
445,
8,
5575,
9,
314,
945,
503,
3420,
911,
506,
4829,
340,
3451,
3140,
402,
2737,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
298,
1881,
2,
1362,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
523,
949,
63,
2911,
63,
10749,
26,
1362,
1369,
26,
2126,
446,
886,
440,
5518,
7883,
2544,
436,
2410,
14051,
5272,
1362,
1415,
26,
3055,
1362,
849,
26,
3055,
1362,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
523,
1218,
26,
1362,
1415,
26,
3055,
1362,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
1362,
849,
26,
298,
5066,
2,
1362,
1369,
26,
2126,
446,
982,
663,
370,
283,
889,
297,
314,
859,
911,
2449,
340,
314,
570,
1630,
440,
2575,
2187,
14,
268,
4885,
849,
652,
911,
1218,
314,
570,
340,
652,
365,
4124,
14,
1362,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
5983,
26,
2043,
446,
22117,
652,
365,
3962,
370,
1050,
376,
473,
8,
1422,
9,
1928,
9176,
282,
473,
8,
585,
395,
642,
7704,
1362,
949,
12249,
14,
199,
2502,
26,
272,
446,
298,
19825,
13,
10542,
386,
603,
8764,
8593,
11538,
278,
561,
2924,
272,
446,
298,
33,
2978,
3091,
261,
75,
8593,
21085,
7351,
17,
2924,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
7523,
298,
30763,
29,
274,
2106,
9587,
365,
315,
3420,
7369,
5012,
2292,
83,
8480,
315,
2013,
570,
199,
13,
20364,
63,
493,
26,
272,
2053,
26,
1182,
6839,
15,
2190,
272,
3420,
26,
366,
12465,
83,
272,
945,
26,
289,
1214,
272,
574,
26,
1026,
2106,
9587,
272,
818,
26,
378,
6683,
272,
6902,
26,
9456,
199,
199,
13,
20364,
63,
493,
26,
272,
2053,
26,
1182,
6839,
15,
13565,
2190,
272,
3420,
26,
366,
12465,
83,
272,
945,
26,
14843,
272,
574,
26,
1048,
68,
272,
6902,
26,
9456,
199,
2344,
199,
199,
646,
747,
199,
646,
295,
199,
199,
3,
19691,
9152,
199,
3,
1336,
63,
2992,
199,
199,
318,
1336,
63,
2992,
8,
1422,
12,
1004,
304,
523,
945,
275,
295,
14,
3765,
8,
1422,
9,
523,
372,
295,
14,
1431,
360,
627,
5,
83,
8,
12196,
84,
3342,
534,
450,
945,
12,
1004,
9,
971,
272,
503,
295,
14,
1431,
7863,
627,
5,
83,
8,
12196,
84,
3342,
534,
450,
945,
12,
1004,
9,
971,
272,
503,
295
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6029,
12,
17474,
13,
10542,
386,
603,
8764,
665,
11538,
278,
561,
6248,
29712,
14,
957,
30,
199,
3,
334,
67,
9,
6900,
12,
437,
2978,
3091,
261,
75,
665,
290,
3362,
75,
14,
21085,
75,
6248,
29712,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
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,
20364,
63,
493,
199,
3612,
63,
1802,
26,
377,
10350,
2202,
315,
1621,
41,
1584,
199,
11036,
63,
9970,
63,
7677,
26,
1584,
199,
1802,
26,
1362,
446,
14944,
334,
525,
12,
2813,
12,
1570,
9,
8212,
2202,
315,
376,
1621,
41,
13,
2487,
570,
1928,
9445,
2126,
370,
9635,
314,
570,
465,
282,
8852,
543,
12,
14722,
12,
603,
8,
1160,
9,
503,
603,
8,
21263,
680,
15747,
4124,
2126,
10189,
340,
2985,
2793,
1133,
2187,
14,
1362,
446,
21467,
1015,
499,
14,
16,
12,
6786,
787,
22002,
1380,
314,
1350,
570,
365,
1586,
12,
436,
16119,
911,
440,
2498,
1536,
315,
314,
5724,
570,
14,
199,
1023,
63,
3270,
26,
298,
16,
14,
25,
2,
199,
1419,
26,
523,
2053,
26,
272,
1369,
26,
489,
446,
6912,
370,
314,
1621,
41,
13,
2487,
570,
27,
642,
570,
365,
2737,
340,
1415,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
3420,
26,
272,
1369,
26,
489,
446,
15247,
536,
315,
1621,
41,
570,
14,
961,
365,
3483,
340,
445,
8,
929,
29,
1881,
9,
5847,
1380,
267,
282,
2849,
574,
365,
3769,
663,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
945,
26,
272,
1369,
26,
489,
446,
340,
663,
334,
2427,
367,
13729,
282,
473,
8,
585,
1826,
642,
365,
314,
536,
402,
314,
945,
14,
489,
446,
10162,
506,
11684,
340,
7791,
15,
264,
7665,
282,
8852,
473,
8,
2792,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
574,
26,
272,
1369,
26,
1362,
446,
314,
1059,
574,
370,
506,
4568,
543,
376,
473,
8,
1422,
680,
10162,
506,
11684,
1380,
12881,
376,
473,
8,
1422,
680,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
6902,
26,
272,
1369,
26,
489,
446,
2790,
282,
6902,
570,
5893,
314,
4913,
2556,
880,
1265,
883,
664,
267,
314,
3379,
570,
1771,
340,
1265,
29437,
286,
1191,
18897,
652,
22743,
14,
272,
1415,
26,
3055,
272,
849,
26,
298,
889,
2,
272,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
523,
11789,
26,
1362,
1369,
26,
2126,
446,
1006,
2368,
10226,
701,
314,
603,
8,
493,
9,
859,
2597,
1736,
2348,
1362,
1415,
26,
3055,
523,
1174,
26,
1362,
1369,
26,
2126,
446,
982,
663,
370,
445,
8,
5575,
9,
314,
945,
503,
3420,
911,
506,
4829,
340,
3451,
3140,
402,
2737,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
298,
1881,
2,
1362,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
523,
949,
63,
2911,
63,
10749,
26,
1362,
1369,
26,
2126,
446,
886,
440,
5518,
7883,
2544,
436,
2410,
14051,
5272,
1362,
1415,
26,
3055,
1362,
849,
26,
3055,
1362,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
523,
1218,
26,
1362,
1415,
26,
3055,
1362,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
1362,
849,
26,
298,
5066,
2,
1362,
1369,
26,
2126,
446,
982,
663,
370,
283,
889,
297,
314,
859,
911,
2449,
340,
314,
570,
1630,
440,
2575,
2187,
14,
268,
4885,
849,
652,
911,
1218,
314,
570,
340,
652,
365,
4124,
14,
1362,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
5983,
26,
2043,
446,
22117,
652,
365,
3962,
370,
1050,
376,
473,
8,
1422,
9,
1928,
9176,
282,
473,
8,
585,
395,
642,
7704,
1362,
949,
12249,
14,
199,
2502,
26,
272,
446,
298,
19825,
13,
10542,
386,
603,
8764,
8593,
11538,
278,
561,
2924,
272,
446,
298,
33,
2978,
3091,
261,
75,
8593,
21085,
7351,
17,
2924,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
7523,
298,
30763,
29,
274,
2106,
9587,
365,
315,
3420,
7369,
5012,
2292,
83,
8480,
315,
2013,
570,
199,
13,
20364,
63,
493,
26,
272,
2053,
26,
1182,
6839,
15,
2190,
272,
3420,
26,
366,
12465,
83,
272,
945,
26,
289,
1214,
272,
574,
26,
1026,
2106,
9587,
272,
818,
26,
378,
6683,
272,
6902,
26,
9456,
199,
199,
13,
20364,
63,
493,
26,
272,
2053,
26,
1182,
6839,
15,
13565,
2190,
272,
3420,
26,
366,
12465,
83,
272,
945,
26,
14843,
272,
574,
26,
1048,
68,
272,
6902,
26,
9456,
199,
2344,
199,
199,
646,
747,
199,
646,
295,
199,
199,
3,
19691,
9152,
199,
3,
1336,
63,
2992,
199,
199,
318,
1336,
63,
2992,
8,
1422,
12,
1004,
304,
523,
945,
275,
295,
14,
3765,
8,
1422,
9,
523,
372,
295,
14,
1431,
360,
627,
5,
83,
8,
12196,
84,
3342,
534,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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
] |
vetu11/piloco
|
cosas/objetos.py
|
1
|
4751
|
# coding=utf-8
import json, time, threading, random, logging
from .funciones import nuevosMensajes
class Partida:
partidasEnCurso = []
def finder(self, host):
posicionPartida = 0
for e in self.partidasEnCurso:
if e["host"] == host:
return posicionPartida
posicionPartida = posicionPartida + 1
def nuevaPartida(self, host, jugadores,listaDeMensajes,ajustesJugador):
logging.info("creando partida")
mensajes = nuevosMensajes(listaDeMensajes,ajustesJugador)
self.partidasEnCurso.append({"host": host, "jugadores": jugadores,"mensajes": mensajes,"siguiente":{"reap":False,"text":None}})
logging.info("partida creada")
class Usuario:
usuariosActivos = []
def __init__(self):
with open("usuarios") as f:
self.usuariosActivos = json.load(f)
def finder(self,idUsuario):
posicionUsuarioEnLista = 0
for e in self.usuariosActivos:
if e["id"] == idUsuario:
return posicionUsuarioEnLista
posicionUsuarioEnLista = posicionUsuarioEnLista + 1
return None
def actualizarUsuario(self,idUsuario,posicion):
posUsuLista = self.finder(idUsuario)
if posUsuLista != None:
self.usuariosActivos[posUsuLista]["ultimoUso"] = time.time()
self.usuariosActivos[posUsuLista]["posicion"] = posicion
else:
self.usuariosActivos.append({"id":idUsuario,"posicion":posicion,"ajustes":{"hastaElFondo":False,"picante":False,"rondas":30},"ultimoUso":time.time(),"editando":None})
def guardarUsuarios(self):
with open("usuarios","w") as f:
json.dump(self.usuariosActivos,f,indent=4)
def borrarUsuarios(self):
pos = 0
indice = 0
for e in self.usuariosActivos:
if e["ultimoUso"] < time.time() - 5184000:
self.usuariosActivos.pop(pos)
else:
pos = pos + 1
# hasta aquí borra los usuarios que no han usado el bot en los últimos 60 días
# lo siguiente es para evitar que ocurra un error que ocurríria (aunque nunca ha ocurrido) cuando el servido
#r se cierra mientras tiene usuarios activos, ya que al iniciar el bot estarían en posición y 2 sin partida.
if e["posicion"] == 2:
self.usuariosActivos[indice]["posicion"] = 0
indice = indice + 1
def actualizarMensaje(self, idUsuario, init=None, text=None):
"""Este método actuliza el mensaje que esté editando un usuario.
init: establecerá un mensaje vacío del tipo que se especifique, normal/RI/RNI
text: establecerá el texto del mensaje que esté editando el usuario
variante: cambiará el valor una de las variantes del mensaje que es esté editando, picante/hef
"""
posUsu = self.finder(idUsuario)
if init != None:
self.usuariosActivos[posUsu]["editando"] = {"id": hex(random.randint(0, 10 ** 8)).replace("0x", ""),
"variantes":[],
"revisar":{
"puntos":(0,0),
"revisado":[]}}
if init == "normal":
self.usuariosActivos[posUsu]["editando"]["tipo"] = "normal"
elif init == "RI":
self.usuariosActivos[posUsu]["editando"]["tipo"] = "RI"
else:
self.usuariosActivos[posUsu]["editando"]["tipo"] = "RNI"
elif text != None:
if self.usuariosActivos[posUsu]["editando"]["tipo"] == "normal":
self.usuariosActivos[posUsu]["editando"]["text"] = unicode(text, encoding="utf-8")
elif "text0" in self.usuariosActivos[posUsu]["editando"]:
self.usuariosActivos[posUsu]["editando"]["text1"] = unicode(text, encoding="utf-8")
else:
self.usuariosActivos[posUsu]["editando"]["text0"] = unicode(text, encoding="utf-8")
"""
POSICIONES:
POSICION = 0: fuera de partida, después de acabarla o de escribir /start
POSICION = 1: esperando lista de jugadores por parte de este usuario
POSICION = 2: en partida
POSICION = 3: en ajustes/personalizar.
POSICION = 4: esperando nuevo mensaje de tipo normal
POSICION = 5: esperando nuevo mensaje de tipo RI (reaparición instantánea)
POSICION = 6: esperando nuevo mensaje de tipo RNI (reaparicón no instantánea)
POSOCION = 7: esperando segundo mensaje para RI o RNI.
"""
|
gpl-3.0
|
[
3,
2803,
29,
1624,
13,
24,
202,
199,
646,
2022,
12,
900,
12,
5796,
12,
2196,
12,
2050,
202,
199,
504,
1275,
7036,
559,
4548,
492,
302,
310,
86,
736,
29230,
2231,
74,
397,
2999,
199,
533,
2235,
280,
983,
26,
1128,
623,
5700,
305,
1327,
3864,
1152,
275,
942,
2958,
347,
11569,
8,
277,
12,
1591,
304,
1039,
1115,
338,
9718,
1262,
280,
983,
275,
378,
1039,
367,
325,
315,
291,
14,
462,
5700,
305,
1327,
3864,
1152,
26,
1675,
340,
325,
905,
1102,
937,
508,
1591,
26,
2628,
372,
1115,
338,
9718,
1262,
280,
983,
1675,
1115,
338,
9718,
1262,
280,
983,
275,
1115,
338,
9718,
1262,
280,
983,
435,
413,
2958,
347,
302,
310,
3042,
1262,
280,
983,
8,
277,
12,
1591,
12,
1335,
1518,
5129,
470,
12,
513,
65,
872,
29230,
2231,
74,
397,
12,
9091,
527,
744,
42,
1518,
25453,
304,
1039,
2050,
14,
815,
480,
1353,
22066,
623,
280,
983,
531,
1039,
562,
561,
9091,
397,
275,
302,
310,
86,
736,
29230,
2231,
74,
397,
8,
513,
65,
872,
29230,
2231,
74,
397,
12,
9091,
527,
744,
42,
1518,
25453,
9,
1039,
291,
14,
462,
5700,
305,
1327,
3864,
1152,
14,
740,
6333,
1102,
582,
1591,
12,
298,
74,
1518,
5129,
470,
582,
1335,
1518,
5129,
470,
4589,
278,
561,
9091,
397,
582,
562,
561,
9091,
397,
4589,
4093,
1907,
27036,
18517,
264,
439,
582,
797,
4589,
505,
582,
403,
19575,
1039,
2050,
14,
815,
480,
23512,
983,
286,
739,
65,
531,
2999,
199,
533,
738,
9648,
6936,
26,
1128,
2739,
85,
17832,
13767,
86,
736,
275,
942,
2958,
347,
636,
826,
721,
277,
304,
1039,
543,
1551,
480,
527,
85,
17832,
531,
465,
289,
26,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
275,
2022,
14,
912,
8,
70,
9,
2958,
347,
11569,
8,
277,
12,
344,
53,
9648,
6936,
304,
1039,
1115,
338,
9718,
53,
9648,
6936,
1327,
1296,
65,
275,
378,
1039,
367,
325,
315,
291,
14,
527,
85,
17832,
13767,
86,
736,
26,
1675,
340,
325,
905,
344,
937,
508,
1305,
53,
9648,
6936,
26,
2628,
372,
1115,
338,
9718,
53,
9648,
6936,
1327,
1296,
65,
1675,
1115,
338,
9718,
53,
9648,
6936,
1327,
1296,
65,
275,
1115,
338,
9718,
53,
9648,
6936,
1327,
1296,
65,
435,
413,
1039,
372,
488,
2958,
347,
3503,
565,
285,
53,
9648,
6936,
8,
277,
12,
344,
53,
9648,
6936,
12,
555,
338,
9718,
304,
1039,
2086,
53,
9648,
1296,
65,
275,
291,
14,
11681,
8,
344,
53,
9648,
6936,
9,
1039,
340,
221,
2086,
53,
9648,
1296,
65,
1137,
488,
26,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
59,
1712,
53,
9648,
1296,
65,
7541,
1141,
573,
53,
1152,
937,
275,
900,
14,
521,
342,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
59,
1712,
53,
9648,
1296,
65,
7541,
555,
338,
9718,
937,
275,
1115,
338,
9718,
1039,
587,
26,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
14,
740,
6333,
344,
582,
344,
53,
9648,
6936,
4589,
555,
338,
9718,
582,
555,
338,
9718,
4589,
9091,
527,
744,
18517,
2411,
1207,
10420,
38,
265,
1117,
582,
797,
4589,
12475,
8949,
582,
797,
4589,
2641,
24315,
582,
1216,
1386,
2,
1141,
573,
53,
1152,
582,
521,
14,
521,
1062,
2,
3773,
22066,
582,
403,
1552,
2958,
347,
24453,
285,
53,
9648,
17832,
8,
277,
304,
1039,
543,
1551,
480,
527,
85,
17832,
2266,
87,
531,
465,
289,
26,
1675,
2022,
14,
2724,
8,
277,
14,
527,
85,
17832,
13767,
86,
736,
12,
70,
12,
3724,
29,
20,
9,
2958,
347,
330,
269,
26378,
53,
9648,
17832,
8,
277,
304,
1039,
2086,
275,
378,
1039,
2539,
301,
275,
378,
1039,
367,
325,
315,
291,
14,
527,
85,
17832,
13767,
86,
736,
26,
1675,
340,
325,
905,
1141,
573,
53,
1152,
937,
665,
900,
14,
521,
342,
446,
959,
10078,
1493,
26,
2628,
291,
14,
527,
85,
17832,
13767,
86,
736,
14,
1935,
8,
1712,
9,
1675,
587,
26,
2628,
2086,
275,
2086,
435,
413,
1675,
327,
18251,
1207,
282,
392,
13676,
330,
269,
345,
16406,
2739,
85,
17832,
17414,
949,
394,
290,
2739,
5129,
579,
5888,
655,
16406,
13333,
119,
21934,
16908,
5212,
366,
13676,
305,
11556,
327,
560,
5259,
1907,
27036,
9455,
12665,
8145,
390,
285,
17414,
312,
895,
345,
625,
1125,
17414,
312,
9808,
13676,
23714,
334,
65,
324,
544,
302,
324,
696,
18251,
312,
895,
322,
1117,
9,
30353,
22066,
579,
8926,
5017,
79,
1675,
327,
82,
542,
286,
4446,
345,
10684,
18626,
305,
3367,
6349,
2739,
85,
17832,
6633,
86,
736,
12,
612,
65,
17414,
741,
315,
530,
73,
285,
579,
5888,
4347,
285,
13676,
290,
655,
1115,
338,
27064,
612,
499,
9829,
623,
280,
983,
14,
11556,
340,
325,
905,
555,
338,
9718,
937,
508,
499,
26,
2628,
291,
14,
527,
85,
17832,
13767,
86,
736,
59,
3558,
301,
7541,
555,
338,
9718,
937,
275,
378,
1675,
2539,
301,
275,
2539,
301,
435,
413,
2958,
347,
3503,
565,
285,
29230,
2231,
6532,
8,
277,
12,
1305,
53,
9648,
6936,
12,
4205,
29,
403,
12,
1318,
29,
403,
304,
1039,
408,
37,
1597,
333,
5741,
11396,
2454,
13987,
8076,
579,
562,
561,
65,
6532,
17414,
4347,
5741,
5283,
22066,
625,
2739,
85,
6936,
14,
1039,
4205,
26,
4347,
461,
2247,
11302,
625,
562,
561,
65,
6532,
28898,
13676,
79,
2150,
3367,
555,
17414,
542,
325,
3017,
329,
544,
12,
3293,
15,
6129,
15,
15303,
41,
1039,
1318,
26,
4347,
461,
2247,
11302,
579,
1318,
79,
2150,
562,
561,
65,
6532,
17414,
4347,
5741,
5283,
22066,
579,
2739,
85,
6936,
1039,
4172,
8949,
26,
27570,
4492,
285,
11302,
579,
1139,
269,
32686,
477,
23325,
4172,
290,
744,
2150,
562,
561,
65,
6532,
17414,
9455,
4347,
5741,
5283,
22066,
12,
26559,
8949,
15,
426,
70,
1039,
408,
4341,
2086,
53,
9648,
275,
291,
14,
11681,
8,
344,
53,
9648,
6936,
9,
1223,
4341,
340,
4205,
1137,
488,
26,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
59,
1712,
53,
9648,
7541,
3773,
22066,
937,
275,
2420,
344,
582,
6318,
8,
2355,
14,
8393,
8,
16,
12,
1616,
1011,
1695,
4992,
1814,
480,
16,
88,
401,
16241,
202,
9144,
298
] |
[
2803,
29,
1624,
13,
24,
202,
199,
646,
2022,
12,
900,
12,
5796,
12,
2196,
12,
2050,
202,
199,
504,
1275,
7036,
559,
4548,
492,
302,
310,
86,
736,
29230,
2231,
74,
397,
2999,
199,
533,
2235,
280,
983,
26,
1128,
623,
5700,
305,
1327,
3864,
1152,
275,
942,
2958,
347,
11569,
8,
277,
12,
1591,
304,
1039,
1115,
338,
9718,
1262,
280,
983,
275,
378,
1039,
367,
325,
315,
291,
14,
462,
5700,
305,
1327,
3864,
1152,
26,
1675,
340,
325,
905,
1102,
937,
508,
1591,
26,
2628,
372,
1115,
338,
9718,
1262,
280,
983,
1675,
1115,
338,
9718,
1262,
280,
983,
275,
1115,
338,
9718,
1262,
280,
983,
435,
413,
2958,
347,
302,
310,
3042,
1262,
280,
983,
8,
277,
12,
1591,
12,
1335,
1518,
5129,
470,
12,
513,
65,
872,
29230,
2231,
74,
397,
12,
9091,
527,
744,
42,
1518,
25453,
304,
1039,
2050,
14,
815,
480,
1353,
22066,
623,
280,
983,
531,
1039,
562,
561,
9091,
397,
275,
302,
310,
86,
736,
29230,
2231,
74,
397,
8,
513,
65,
872,
29230,
2231,
74,
397,
12,
9091,
527,
744,
42,
1518,
25453,
9,
1039,
291,
14,
462,
5700,
305,
1327,
3864,
1152,
14,
740,
6333,
1102,
582,
1591,
12,
298,
74,
1518,
5129,
470,
582,
1335,
1518,
5129,
470,
4589,
278,
561,
9091,
397,
582,
562,
561,
9091,
397,
4589,
4093,
1907,
27036,
18517,
264,
439,
582,
797,
4589,
505,
582,
403,
19575,
1039,
2050,
14,
815,
480,
23512,
983,
286,
739,
65,
531,
2999,
199,
533,
738,
9648,
6936,
26,
1128,
2739,
85,
17832,
13767,
86,
736,
275,
942,
2958,
347,
636,
826,
721,
277,
304,
1039,
543,
1551,
480,
527,
85,
17832,
531,
465,
289,
26,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
275,
2022,
14,
912,
8,
70,
9,
2958,
347,
11569,
8,
277,
12,
344,
53,
9648,
6936,
304,
1039,
1115,
338,
9718,
53,
9648,
6936,
1327,
1296,
65,
275,
378,
1039,
367,
325,
315,
291,
14,
527,
85,
17832,
13767,
86,
736,
26,
1675,
340,
325,
905,
344,
937,
508,
1305,
53,
9648,
6936,
26,
2628,
372,
1115,
338,
9718,
53,
9648,
6936,
1327,
1296,
65,
1675,
1115,
338,
9718,
53,
9648,
6936,
1327,
1296,
65,
275,
1115,
338,
9718,
53,
9648,
6936,
1327,
1296,
65,
435,
413,
1039,
372,
488,
2958,
347,
3503,
565,
285,
53,
9648,
6936,
8,
277,
12,
344,
53,
9648,
6936,
12,
555,
338,
9718,
304,
1039,
2086,
53,
9648,
1296,
65,
275,
291,
14,
11681,
8,
344,
53,
9648,
6936,
9,
1039,
340,
221,
2086,
53,
9648,
1296,
65,
1137,
488,
26,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
59,
1712,
53,
9648,
1296,
65,
7541,
1141,
573,
53,
1152,
937,
275,
900,
14,
521,
342,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
59,
1712,
53,
9648,
1296,
65,
7541,
555,
338,
9718,
937,
275,
1115,
338,
9718,
1039,
587,
26,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
14,
740,
6333,
344,
582,
344,
53,
9648,
6936,
4589,
555,
338,
9718,
582,
555,
338,
9718,
4589,
9091,
527,
744,
18517,
2411,
1207,
10420,
38,
265,
1117,
582,
797,
4589,
12475,
8949,
582,
797,
4589,
2641,
24315,
582,
1216,
1386,
2,
1141,
573,
53,
1152,
582,
521,
14,
521,
1062,
2,
3773,
22066,
582,
403,
1552,
2958,
347,
24453,
285,
53,
9648,
17832,
8,
277,
304,
1039,
543,
1551,
480,
527,
85,
17832,
2266,
87,
531,
465,
289,
26,
1675,
2022,
14,
2724,
8,
277,
14,
527,
85,
17832,
13767,
86,
736,
12,
70,
12,
3724,
29,
20,
9,
2958,
347,
330,
269,
26378,
53,
9648,
17832,
8,
277,
304,
1039,
2086,
275,
378,
1039,
2539,
301,
275,
378,
1039,
367,
325,
315,
291,
14,
527,
85,
17832,
13767,
86,
736,
26,
1675,
340,
325,
905,
1141,
573,
53,
1152,
937,
665,
900,
14,
521,
342,
446,
959,
10078,
1493,
26,
2628,
291,
14,
527,
85,
17832,
13767,
86,
736,
14,
1935,
8,
1712,
9,
1675,
587,
26,
2628,
2086,
275,
2086,
435,
413,
1675,
327,
18251,
1207,
282,
392,
13676,
330,
269,
345,
16406,
2739,
85,
17832,
17414,
949,
394,
290,
2739,
5129,
579,
5888,
655,
16406,
13333,
119,
21934,
16908,
5212,
366,
13676,
305,
11556,
327,
560,
5259,
1907,
27036,
9455,
12665,
8145,
390,
285,
17414,
312,
895,
345,
625,
1125,
17414,
312,
9808,
13676,
23714,
334,
65,
324,
544,
302,
324,
696,
18251,
312,
895,
322,
1117,
9,
30353,
22066,
579,
8926,
5017,
79,
1675,
327,
82,
542,
286,
4446,
345,
10684,
18626,
305,
3367,
6349,
2739,
85,
17832,
6633,
86,
736,
12,
612,
65,
17414,
741,
315,
530,
73,
285,
579,
5888,
4347,
285,
13676,
290,
655,
1115,
338,
27064,
612,
499,
9829,
623,
280,
983,
14,
11556,
340,
325,
905,
555,
338,
9718,
937,
508,
499,
26,
2628,
291,
14,
527,
85,
17832,
13767,
86,
736,
59,
3558,
301,
7541,
555,
338,
9718,
937,
275,
378,
1675,
2539,
301,
275,
2539,
301,
435,
413,
2958,
347,
3503,
565,
285,
29230,
2231,
6532,
8,
277,
12,
1305,
53,
9648,
6936,
12,
4205,
29,
403,
12,
1318,
29,
403,
304,
1039,
408,
37,
1597,
333,
5741,
11396,
2454,
13987,
8076,
579,
562,
561,
65,
6532,
17414,
4347,
5741,
5283,
22066,
625,
2739,
85,
6936,
14,
1039,
4205,
26,
4347,
461,
2247,
11302,
625,
562,
561,
65,
6532,
28898,
13676,
79,
2150,
3367,
555,
17414,
542,
325,
3017,
329,
544,
12,
3293,
15,
6129,
15,
15303,
41,
1039,
1318,
26,
4347,
461,
2247,
11302,
579,
1318,
79,
2150,
562,
561,
65,
6532,
17414,
4347,
5741,
5283,
22066,
579,
2739,
85,
6936,
1039,
4172,
8949,
26,
27570,
4492,
285,
11302,
579,
1139,
269,
32686,
477,
23325,
4172,
290,
744,
2150,
562,
561,
65,
6532,
17414,
9455,
4347,
5741,
5283,
22066,
12,
26559,
8949,
15,
426,
70,
1039,
408,
4341,
2086,
53,
9648,
275,
291,
14,
11681,
8,
344,
53,
9648,
6936,
9,
1223,
4341,
340,
4205,
1137,
488,
26,
1675,
291,
14,
527,
85,
17832,
13767,
86,
736,
59,
1712,
53,
9648,
7541,
3773,
22066,
937,
275,
2420,
344,
582,
6318,
8,
2355,
14,
8393,
8,
16,
12,
1616,
1011,
1695,
4992,
1814,
480,
16,
88,
401,
16241,
202,
9144,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
jerryblakley/libcloud
|
libcloud/compute/drivers/ec2.py
|
21
|
198736
|
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Amazon EC2, Eucalyptus, Nimbus and Outscale drivers.
"""
import re
import sys
import base64
import copy
import warnings
try:
from lxml import etree as ET
except ImportError:
from xml.etree import ElementTree as ET
from libcloud.utils.py3 import b, basestring, ensure_string
from libcloud.utils.xml import fixxpath, findtext, findattr, findall
from libcloud.utils.publickey import get_pubkey_ssh2_fingerprint
from libcloud.utils.publickey import get_pubkey_comment
from libcloud.utils.iso8601 import parse_date
from libcloud.common.aws import AWSBaseResponse, SignedAWSConnection
from libcloud.common.aws import DEFAULT_SIGNATURE_VERSION
from libcloud.common.types import (InvalidCredsError, MalformedResponseError,
LibcloudError)
from libcloud.compute.providers import Provider
from libcloud.compute.base import Node, NodeDriver, NodeLocation, NodeSize
from libcloud.compute.base import NodeImage, StorageVolume, VolumeSnapshot
from libcloud.compute.base import KeyPair
from libcloud.compute.types import NodeState, KeyPairDoesNotExistError, \
StorageVolumeState
__all__ = [
'API_VERSION',
'NAMESPACE',
'INSTANCE_TYPES',
'OUTSCALE_INSTANCE_TYPES',
'OUTSCALE_SAS_REGION_DETAILS',
'OUTSCALE_INC_REGION_DETAILS',
'DEFAULT_EUCA_API_VERSION',
'EUCA_NAMESPACE',
'EC2NodeDriver',
'BaseEC2NodeDriver',
'NimbusNodeDriver',
'EucNodeDriver',
'OutscaleSASNodeDriver',
'OutscaleINCNodeDriver',
'EC2NodeLocation',
'EC2ReservedNode',
'EC2SecurityGroup',
'EC2PlacementGroup',
'EC2Network',
'EC2NetworkSubnet',
'EC2NetworkInterface',
'EC2RouteTable',
'EC2Route',
'EC2SubnetAssociation',
'ExEC2AvailabilityZone',
'IdempotentParamError'
]
API_VERSION = '2013-10-15'
NAMESPACE = 'http://ec2.amazonaws.com/doc/%s/' % (API_VERSION)
# Eucalyptus Constants
DEFAULT_EUCA_API_VERSION = '3.3.0'
EUCA_NAMESPACE = 'http://msgs.eucalyptus.com/%s' % (DEFAULT_EUCA_API_VERSION)
"""
Sizes must be hardcoded, because Amazon doesn't provide an API to fetch them.
From http://aws.amazon.com/ec2/instance-types/
"""
INSTANCE_TYPES = {
't1.micro': {
'id': 't1.micro',
'name': 'Micro Instance',
'ram': 613,
'disk': 15,
'bandwidth': None
},
'm1.small': {
'id': 'm1.small',
'name': 'Small Instance',
'ram': 1740,
'disk': 160,
'bandwidth': None
},
'm1.medium': {
'id': 'm1.medium',
'name': 'Medium Instance',
'ram': 3700,
'disk': 410,
'bandwidth': None
},
'm1.large': {
'id': 'm1.large',
'name': 'Large Instance',
'ram': 7680,
'disk': 850,
'bandwidth': None
},
'm1.xlarge': {
'id': 'm1.xlarge',
'name': 'Extra Large Instance',
'ram': 15360,
'disk': 1690,
'bandwidth': None
},
'c1.medium': {
'id': 'c1.medium',
'name': 'High-CPU Medium Instance',
'ram': 1740,
'disk': 350,
'bandwidth': None
},
'c1.xlarge': {
'id': 'c1.xlarge',
'name': 'High-CPU Extra Large Instance',
'ram': 7680,
'disk': 1690,
'bandwidth': None
},
'm2.xlarge': {
'id': 'm2.xlarge',
'name': 'High-Memory Extra Large Instance',
'ram': 17510,
'disk': 420,
'bandwidth': None
},
'm2.2xlarge': {
'id': 'm2.2xlarge',
'name': 'High-Memory Double Extra Large Instance',
'ram': 35021,
'disk': 850,
'bandwidth': None
},
'm2.4xlarge': {
'id': 'm2.4xlarge',
'name': 'High-Memory Quadruple Extra Large Instance',
'ram': 70042,
'disk': 1690,
'bandwidth': None
},
'm3.medium': {
'id': 'm3.medium',
'name': 'Medium Instance',
'ram': 3840,
'disk': 4000,
'bandwidth': None
},
'm3.large': {
'id': 'm3.large',
'name': 'Large Instance',
'ram': 7168,
'disk': 32000,
'bandwidth': None
},
'm3.xlarge': {
'id': 'm3.xlarge',
'name': 'Extra Large Instance',
'ram': 15360,
'disk': 80000,
'bandwidth': None
},
'm3.2xlarge': {
'id': 'm3.2xlarge',
'name': 'Double Extra Large Instance',
'ram': 30720,
'disk': 160000,
'bandwidth': None
},
'cg1.4xlarge': {
'id': 'cg1.4xlarge',
'name': 'Cluster GPU Quadruple Extra Large Instance',
'ram': 22528,
'disk': 1690,
'bandwidth': None
},
'g2.2xlarge': {
'id': 'g2.2xlarge',
'name': 'Cluster GPU G2 Double Extra Large Instance',
'ram': 15000,
'disk': 60,
'bandwidth': None,
},
'cc1.4xlarge': {
'id': 'cc1.4xlarge',
'name': 'Cluster Compute Quadruple Extra Large Instance',
'ram': 23552,
'disk': 1690,
'bandwidth': None
},
'cc2.8xlarge': {
'id': 'cc2.8xlarge',
'name': 'Cluster Compute Eight Extra Large Instance',
'ram': 63488,
'disk': 3370,
'bandwidth': None
},
# c3 instances have 2 SSDs of the specified disk size
'c3.large': {
'id': 'c3.large',
'name': 'Compute Optimized Large Instance',
'ram': 3750,
'disk': 32, # x2
'bandwidth': None
},
'c3.xlarge': {
'id': 'c3.xlarge',
'name': 'Compute Optimized Extra Large Instance',
'ram': 7500,
'disk': 80, # x2
'bandwidth': None
},
'c3.2xlarge': {
'id': 'c3.2xlarge',
'name': 'Compute Optimized Double Extra Large Instance',
'ram': 15000,
'disk': 160, # x2
'bandwidth': None
},
'c3.4xlarge': {
'id': 'c3.4xlarge',
'name': 'Compute Optimized Quadruple Extra Large Instance',
'ram': 30000,
'disk': 320, # x2
'bandwidth': None
},
'c3.8xlarge': {
'id': 'c3.8xlarge',
'name': 'Compute Optimized Eight Extra Large Instance',
'ram': 60000,
'disk': 640, # x2
'bandwidth': None
},
'cr1.8xlarge': {
'id': 'cr1.8xlarge',
'name': 'High Memory Cluster Eight Extra Large',
'ram': 244000,
'disk': 240,
'bandwidth': None
},
'hs1.4xlarge': {
'id': 'hs1.4xlarge',
'name': 'High Storage Quadruple Extra Large Instance',
'ram': 61952,
'disk': 2048,
'bandwidth': None
},
'hs1.8xlarge': {
'id': 'hs1.8xlarge',
'name': 'High Storage Eight Extra Large Instance',
'ram': 119808,
'disk': 48000,
'bandwidth': None
},
# i2 instances have up to eight SSD drives
'i2.xlarge': {
'id': 'i2.xlarge',
'name': 'High Storage Optimized Extra Large Instance',
'ram': 31232,
'disk': 800,
'bandwidth': None
},
'i2.2xlarge': {
'id': 'i2.2xlarge',
'name': 'High Storage Optimized Double Extra Large Instance',
'ram': 62464,
'disk': 1600,
'bandwidth': None
},
'i2.4xlarge': {
'id': 'i2.4xlarge',
'name': 'High Storage Optimized Quadruple Large Instance',
'ram': 124928,
'disk': 3200,
'bandwidth': None
},
'i2.8xlarge': {
'id': 'i2.8xlarge',
'name': 'High Storage Optimized Eight Extra Large Instance',
'ram': 249856,
'disk': 6400,
'bandwidth': None
},
'd2.xlarge': {
'id': 'd2.xlarge',
'name': 'High Storage Optimized Extra Large Instance',
'ram': 30050,
'disk': 6000, # 3 x 2 TB
'bandwidth': None
},
'd2.2xlarge': {
'id': 'd2.2xlarge',
'name': 'High Storage Optimized Double Extra Large Instance',
'ram': 61952,
'disk': 12000, # 6 x 2 TB
'bandwidth': None
},
'd2.4xlarge': {
'id': 'd2.4xlarge',
'name': 'High Storage Optimized Quadruple Extra Large Instance',
'ram': 122000,
'disk': 24000, # 12 x 2 TB
'bandwidth': None
},
'd2.8xlarge': {
'id': 'd2.8xlarge',
'name': 'High Storage Optimized Eight Extra Large Instance',
'ram': 244000,
'disk': 48000, # 24 x 2 TB
'bandwidth': None
},
# 1x SSD
'r3.large': {
'id': 'r3.large',
'name': 'Memory Optimized Large instance',
'ram': 15000,
'disk': 32,
'bandwidth': None
},
'r3.xlarge': {
'id': 'r3.xlarge',
'name': 'Memory Optimized Extra Large instance',
'ram': 30500,
'disk': 80,
'bandwidth': None
},
'r3.2xlarge': {
'id': 'r3.2xlarge',
'name': 'Memory Optimized Double Extra Large instance',
'ram': 61000,
'disk': 160,
'bandwidth': None
},
'r3.4xlarge': {
'id': 'r3.4xlarge',
'name': 'Memory Optimized Quadruple Extra Large instance',
'ram': 122000,
'disk': 320,
'bandwidth': None
},
'r3.8xlarge': {
'id': 'r3.8xlarge',
'name': 'Memory Optimized Eight Extra Large instance',
'ram': 244000,
'disk': 320, # x2
'bandwidth': None
},
't2.micro': {
'id': 't2.micro',
'name': 'Burstable Performance Micro Instance',
'ram': 1024,
'disk': 0, # EBS Only
'bandwidth': None,
'extra': {
'cpu': 1
}
},
# Burstable Performance General Purpose
't2.small': {
'id': 't2.small',
'name': 'Burstable Performance Small Instance',
'ram': 2048,
'disk': 0, # EBS Only
'bandwidth': None,
'extra': {
'cpu': 11
}
},
't2.medium': {
'id': 't2.medium',
'name': 'Burstable Performance Medium Instance',
'ram': 4028,
'disk': 0, # EBS Only
'bandwidth': None,
'extra': {
'cpu': 2
}
}
}
REGION_DETAILS = {
# US East (Northern Virginia) Region
'us-east-1': {
'endpoint': 'ec2.us-east-1.amazonaws.com',
'api_name': 'ec2_us_east',
'country': 'USA',
'signature_version': '2',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c1.medium',
'c1.xlarge',
'cc2.8xlarge',
'c3.large',
'c3.xlarge',
'c3.2xlarge',
'c3.4xlarge',
'c3.8xlarge',
'cg1.4xlarge',
'g2.2xlarge',
'cr1.8xlarge',
'hs1.8xlarge',
'i2.xlarge',
'i2.2xlarge',
'i2.4xlarge',
'i2.8xlarge',
'd2.xlarge',
'd2.2xlarge',
'd2.4xlarge',
'd2.8xlarge',
'r3.large',
'r3.xlarge',
'r3.2xlarge',
'r3.4xlarge',
'r3.8xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
# US West (Northern California) Region
'us-west-1': {
'endpoint': 'ec2.us-west-1.amazonaws.com',
'api_name': 'ec2_us_west',
'country': 'USA',
'signature_version': '2',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c1.medium',
'c1.xlarge',
'g2.2xlarge',
'c3.large',
'c3.xlarge',
'c3.2xlarge',
'c3.4xlarge',
'c3.8xlarge',
'i2.xlarge',
'i2.2xlarge',
'i2.4xlarge',
'i2.8xlarge',
'r3.large',
'r3.xlarge',
'r3.2xlarge',
'r3.4xlarge',
'r3.8xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
# US West (Oregon) Region
'us-west-2': {
'endpoint': 'ec2.us-west-2.amazonaws.com',
'api_name': 'ec2_us_west_oregon',
'country': 'US',
'signature_version': '2',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c1.medium',
'c1.xlarge',
'g2.2xlarge',
'c3.large',
'c3.xlarge',
'c3.2xlarge',
'c3.4xlarge',
'c3.8xlarge',
'hs1.8xlarge',
'cc2.8xlarge',
'i2.xlarge',
'i2.2xlarge',
'i2.4xlarge',
'i2.8xlarge',
'd2.xlarge',
'd2.2xlarge',
'd2.4xlarge',
'd2.8xlarge',
'r3.large',
'r3.xlarge',
'r3.2xlarge',
'r3.4xlarge',
'r3.8xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
# EU (Ireland) Region
'eu-west-1': {
'endpoint': 'ec2.eu-west-1.amazonaws.com',
'api_name': 'ec2_eu_west',
'country': 'Ireland',
'signature_version': '2',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c1.medium',
'c1.xlarge',
'g2.2xlarge',
'c3.large',
'c3.xlarge',
'c3.2xlarge',
'c3.4xlarge',
'c3.8xlarge',
'hs1.8xlarge',
'cc2.8xlarge',
'i2.xlarge',
'i2.2xlarge',
'i2.4xlarge',
'i2.8xlarge',
'd2.xlarge',
'd2.2xlarge',
'd2.4xlarge',
'd2.8xlarge',
'r3.large',
'r3.xlarge',
'r3.2xlarge',
'r3.4xlarge',
'r3.8xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
# EU (Frankfurt) Region
'eu-central-1': {
'endpoint': 'ec2.eu-central-1.amazonaws.com',
'api_name': 'ec2_eu_central',
'country': 'Frankfurt',
'signature_version': '4',
'instance_types': [
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c3.large',
'c3.xlarge',
'c3.2xlarge',
'c3.4xlarge',
'c3.8xlarge',
'i2.xlarge',
'i2.2xlarge',
'i2.4xlarge',
'i2.8xlarge',
'd2.xlarge',
'd2.2xlarge',
'd2.4xlarge',
'd2.8xlarge',
'r3.large',
'r3.xlarge',
'r3.2xlarge',
'r3.4xlarge',
'r3.8xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
# Asia Pacific (Singapore) Region
'ap-southeast-1': {
'endpoint': 'ec2.ap-southeast-1.amazonaws.com',
'api_name': 'ec2_ap_southeast',
'country': 'Singapore',
'signature_version': '2',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c1.medium',
'c1.xlarge',
'c3.large',
'c3.xlarge',
'c3.2xlarge',
'c3.4xlarge',
'c3.8xlarge',
'hs1.8xlarge',
'i2.xlarge',
'i2.2xlarge',
'i2.4xlarge',
'i2.8xlarge',
'd2.xlarge',
'd2.2xlarge',
'd2.4xlarge',
'd2.8xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
# Asia Pacific (Tokyo) Region
'ap-northeast-1': {
'endpoint': 'ec2.ap-northeast-1.amazonaws.com',
'api_name': 'ec2_ap_northeast',
'country': 'Japan',
'signature_version': '2',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c1.medium',
'g2.2xlarge',
'c1.xlarge',
'c3.large',
'c3.xlarge',
'c3.2xlarge',
'c3.4xlarge',
'c3.8xlarge',
'hs1.8xlarge',
'i2.xlarge',
'i2.2xlarge',
'i2.4xlarge',
'i2.8xlarge',
'd2.xlarge',
'd2.2xlarge',
'd2.4xlarge',
'd2.8xlarge',
'r3.large',
'r3.xlarge',
'r3.2xlarge',
'r3.4xlarge',
'r3.8xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
# South America (Sao Paulo) Region
'sa-east-1': {
'endpoint': 'ec2.sa-east-1.amazonaws.com',
'api_name': 'ec2_sa_east',
'country': 'Brazil',
'signature_version': '2',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c1.medium',
'c1.xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
# Asia Pacific (Sydney) Region
'ap-southeast-2': {
'endpoint': 'ec2.ap-southeast-2.amazonaws.com',
'api_name': 'ec2_ap_southeast_2',
'country': 'Australia',
'signature_version': '2',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c1.medium',
'c1.xlarge',
'c3.large',
'c3.xlarge',
'c3.2xlarge',
'c3.4xlarge',
'c3.8xlarge',
'hs1.8xlarge',
'i2.xlarge',
'i2.2xlarge',
'i2.4xlarge',
'i2.8xlarge',
'd2.xlarge',
'd2.2xlarge',
'd2.4xlarge',
'd2.8xlarge',
'r3.large',
'r3.xlarge',
'r3.2xlarge',
'r3.4xlarge',
'r3.8xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
'us-gov-west-1': {
'endpoint': 'ec2.us-gov-west-1.amazonaws.com',
'api_name': 'ec2_us_govwest',
'country': 'US',
'signature_version': '2',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'm3.medium',
'm3.large',
'm3.xlarge',
'm3.2xlarge',
'c1.medium',
'c1.xlarge',
'g2.2xlarge',
'c3.large',
'c3.xlarge',
'c3.2xlarge',
'c3.4xlarge',
'c3.8xlarge',
'hs1.4xlarge',
'hs1.8xlarge',
'i2.xlarge',
'i2.2xlarge',
'i2.4xlarge',
'i2.8xlarge',
'r3.large',
'r3.xlarge',
'r3.2xlarge',
'r3.4xlarge',
'r3.8xlarge',
't2.micro',
't2.small',
't2.medium'
]
},
'nimbus': {
# Nimbus clouds have 3 EC2-style instance types but their particular
# RAM allocations are configured by the admin
'country': 'custom',
'signature_version': '2',
'instance_types': [
'm1.small',
'm1.large',
'm1.xlarge'
]
}
}
"""
Sizes must be hardcoded because Outscale doesn't provide an API to fetch them.
Outscale cloud instances share some names with EC2 but have different
specifications so declare them in another constant.
"""
OUTSCALE_INSTANCE_TYPES = {
't1.micro': {
'id': 't1.micro',
'name': 'Micro Instance',
'ram': 615,
'disk': 0,
'bandwidth': None
},
'm1.small': {
'id': 'm1.small',
'name': 'Standard Small Instance',
'ram': 1740,
'disk': 150,
'bandwidth': None
},
'm1.medium': {
'id': 'm1.medium',
'name': 'Standard Medium Instance',
'ram': 3840,
'disk': 420,
'bandwidth': None
},
'm1.large': {
'id': 'm1.large',
'name': 'Standard Large Instance',
'ram': 7680,
'disk': 840,
'bandwidth': None
},
'm1.xlarge': {
'id': 'm1.xlarge',
'name': 'Standard Extra Large Instance',
'ram': 15360,
'disk': 1680,
'bandwidth': None
},
'c1.medium': {
'id': 'c1.medium',
'name': 'Compute Optimized Medium Instance',
'ram': 1740,
'disk': 340,
'bandwidth': None
},
'c1.xlarge': {
'id': 'c1.xlarge',
'name': 'Compute Optimized Extra Large Instance',
'ram': 7168,
'disk': 1680,
'bandwidth': None
},
'c3.large': {
'id': 'c3.large',
'name': 'Compute Optimized Large Instance',
'ram': 3840,
'disk': 32,
'bandwidth': None
},
'c3.xlarge': {
'id': 'c3.xlarge',
'name': 'Compute Optimized Extra Large Instance',
'ram': 7168,
'disk': 80,
'bandwidth': None
},
'c3.2xlarge': {
'id': 'c3.2xlarge',
'name': 'Compute Optimized Double Extra Large Instance',
'ram': 15359,
'disk': 160,
'bandwidth': None
},
'c3.4xlarge': {
'id': 'c3.4xlarge',
'name': 'Compute Optimized Quadruple Extra Large Instance',
'ram': 30720,
'disk': 320,
'bandwidth': None
},
'c3.8xlarge': {
'id': 'c3.8xlarge',
'name': 'Compute Optimized Eight Extra Large Instance',
'ram': 61440,
'disk': 640,
'bandwidth': None
},
'm2.xlarge': {
'id': 'm2.xlarge',
'name': 'High Memory Extra Large Instance',
'ram': 17510,
'disk': 420,
'bandwidth': None
},
'm2.2xlarge': {
'id': 'm2.2xlarge',
'name': 'High Memory Double Extra Large Instance',
'ram': 35020,
'disk': 840,
'bandwidth': None
},
'm2.4xlarge': {
'id': 'm2.4xlarge',
'name': 'High Memory Quadruple Extra Large Instance',
'ram': 70042,
'disk': 1680,
'bandwidth': None
},
'nv1.small': {
'id': 'nv1.small',
'name': 'GPU Small Instance',
'ram': 1739,
'disk': 150,
'bandwidth': None
},
'nv1.medium': {
'id': 'nv1.medium',
'name': 'GPU Medium Instance',
'ram': 3839,
'disk': 420,
'bandwidth': None
},
'nv1.large': {
'id': 'nv1.large',
'name': 'GPU Large Instance',
'ram': 7679,
'disk': 840,
'bandwidth': None
},
'nv1.xlarge': {
'id': 'nv1.xlarge',
'name': 'GPU Extra Large Instance',
'ram': 15358,
'disk': 1680,
'bandwidth': None
},
'g2.2xlarge': {
'id': 'g2.2xlarge',
'name': 'GPU Double Extra Large Instance',
'ram': 15360,
'disk': 60,
'bandwidth': None
},
'cc1.4xlarge': {
'id': 'cc1.4xlarge',
'name': 'Cluster Compute Quadruple Extra Large Instance',
'ram': 24576,
'disk': 1680,
'bandwidth': None
},
'cc2.8xlarge': {
'id': 'cc2.8xlarge',
'name': 'Cluster Compute Eight Extra Large Instance',
'ram': 65536,
'disk': 3360,
'bandwidth': None
},
'hi1.xlarge': {
'id': 'hi1.xlarge',
'name': 'High Storage Extra Large Instance',
'ram': 15361,
'disk': 1680,
'bandwidth': None
},
'm3.xlarge': {
'id': 'm3.xlarge',
'name': 'High Storage Optimized Extra Large Instance',
'ram': 15357,
'disk': 0,
'bandwidth': None
},
'm3.2xlarge': {
'id': 'm3.2xlarge',
'name': 'High Storage Optimized Double Extra Large Instance',
'ram': 30720,
'disk': 0,
'bandwidth': None
},
'm3s.xlarge': {
'id': 'm3s.xlarge',
'name': 'High Storage Optimized Extra Large Instance',
'ram': 15359,
'disk': 0,
'bandwidth': None
},
'm3s.2xlarge': {
'id': 'm3s.2xlarge',
'name': 'High Storage Optimized Double Extra Large Instance',
'ram': 30719,
'disk': 0,
'bandwidth': None
},
'cr1.8xlarge': {
'id': 'cr1.8xlarge',
'name': 'Memory Optimized Eight Extra Large Instance',
'ram': 249855,
'disk': 240,
'bandwidth': None
},
'os1.2xlarge': {
'id': 'os1.2xlarge',
'name': 'Memory Optimized, High Storage, Passthrough NIC Double Extra '
'Large Instance',
'ram': 65536,
'disk': 60,
'bandwidth': None
},
'os1.4xlarge': {
'id': 'os1.4xlarge',
'name': 'Memory Optimized, High Storage, Passthrough NIC Quadruple Ext'
'ra Large Instance',
'ram': 131072,
'disk': 120,
'bandwidth': None
},
'os1.8xlarge': {
'id': 'os1.8xlarge',
'name': 'Memory Optimized, High Storage, Passthrough NIC Eight Extra L'
'arge Instance',
'ram': 249856,
'disk': 500,
'bandwidth': None
},
'oc1.4xlarge': {
'id': 'oc1.4xlarge',
'name': 'Outscale Quadruple Extra Large Instance',
'ram': 24575,
'disk': 1680,
'bandwidth': None
},
'oc2.8xlarge': {
'id': 'oc2.8xlarge',
'name': 'Outscale Eight Extra Large Instance',
'ram': 65535,
'disk': 3360,
'bandwidth': None
}
}
"""
The function manipulating Outscale cloud regions will be overridden because
Outscale instances types are in a separate dict so also declare Outscale cloud
regions in some other constants.
"""
OUTSCALE_SAS_REGION_DETAILS = {
'eu-west-3': {
'endpoint': 'api-ppd.outscale.com',
'api_name': 'osc_sas_eu_west_3',
'country': 'FRANCE',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'c1.medium',
'c1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'nv1.small',
'nv1.medium',
'nv1.large',
'nv1.xlarge',
'cc1.4xlarge',
'cc2.8xlarge',
'm3.xlarge',
'm3.2xlarge',
'cr1.8xlarge',
'os1.8xlarge'
]
},
'eu-west-1': {
'endpoint': 'api.eu-west-1.outscale.com',
'api_name': 'osc_sas_eu_west_1',
'country': 'FRANCE',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'c1.medium',
'c1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'nv1.small',
'nv1.medium',
'nv1.large',
'nv1.xlarge',
'cc1.4xlarge',
'cc2.8xlarge',
'm3.xlarge',
'm3.2xlarge',
'cr1.8xlarge',
'os1.8xlarge'
]
},
'us-east-1': {
'endpoint': 'api.us-east-1.outscale.com',
'api_name': 'osc_sas_us_east_1',
'country': 'USA',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'c1.medium',
'c1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'nv1.small',
'nv1.medium',
'nv1.large',
'nv1.xlarge',
'cc1.4xlarge',
'cc2.8xlarge',
'm3.xlarge',
'm3.2xlarge',
'cr1.8xlarge',
'os1.8xlarge'
]
}
}
OUTSCALE_INC_REGION_DETAILS = {
'eu-west-1': {
'endpoint': 'api.eu-west-1.outscale.com',
'api_name': 'osc_inc_eu_west_1',
'country': 'FRANCE',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'c1.medium',
'c1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'nv1.small',
'nv1.medium',
'nv1.large',
'nv1.xlarge',
'cc1.4xlarge',
'cc2.8xlarge',
'm3.xlarge',
'm3.2xlarge',
'cr1.8xlarge',
'os1.8xlarge'
]
},
'eu-west-3': {
'endpoint': 'api-ppd.outscale.com',
'api_name': 'osc_inc_eu_west_3',
'country': 'FRANCE',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'c1.medium',
'c1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'nv1.small',
'nv1.medium',
'nv1.large',
'nv1.xlarge',
'cc1.4xlarge',
'cc2.8xlarge',
'm3.xlarge',
'm3.2xlarge',
'cr1.8xlarge',
'os1.8xlarge'
]
},
'us-east-1': {
'endpoint': 'api.us-east-1.outscale.com',
'api_name': 'osc_inc_us_east_1',
'country': 'USA',
'instance_types': [
't1.micro',
'm1.small',
'm1.medium',
'm1.large',
'm1.xlarge',
'c1.medium',
'c1.xlarge',
'm2.xlarge',
'm2.2xlarge',
'm2.4xlarge',
'nv1.small',
'nv1.medium',
'nv1.large',
'nv1.xlarge',
'cc1.4xlarge',
'cc2.8xlarge',
'm3.xlarge',
'm3.2xlarge',
'cr1.8xlarge',
'os1.8xlarge'
]
}
}
"""
Define the extra dictionary for specific resources
"""
RESOURCE_EXTRA_ATTRIBUTES_MAP = {
'ebs_volume': {
'snapshot_id': {
'xpath': 'ebs/snapshotId',
'transform_func': str
},
'volume_id': {
'xpath': 'ebs/volumeId',
'transform_func': str
},
'volume_size': {
'xpath': 'ebs/volumeSize',
'transform_func': int
},
'delete': {
'xpath': 'ebs/deleteOnTermination',
'transform_func': str
},
'volume_type': {
'xpath': 'ebs/volumeType',
'transform_func': str
},
'iops': {
'xpath': 'ebs/iops',
'transform_func': int
}
},
'elastic_ip': {
'allocation_id': {
'xpath': 'allocationId',
'transform_func': str,
},
'association_id': {
'xpath': 'associationId',
'transform_func': str,
},
'interface_id': {
'xpath': 'networkInterfaceId',
'transform_func': str,
},
'owner_id': {
'xpath': 'networkInterfaceOwnerId',
'transform_func': str,
},
'private_ip': {
'xpath': 'privateIp',
'transform_func': str,
}
},
'image': {
'state': {
'xpath': 'imageState',
'transform_func': str
},
'owner_id': {
'xpath': 'imageOwnerId',
'transform_func': str
},
'owner_alias': {
'xpath': 'imageOwnerAlias',
'transform_func': str
},
'is_public': {
'xpath': 'isPublic',
'transform_func': str
},
'architecture': {
'xpath': 'architecture',
'transform_func': str
},
'image_type': {
'xpath': 'imageType',
'transform_func': str
},
'image_location': {
'xpath': 'imageLocation',
'transform_func': str
},
'platform': {
'xpath': 'platform',
'transform_func': str
},
'description': {
'xpath': 'description',
'transform_func': str
},
'root_device_type': {
'xpath': 'rootDeviceType',
'transform_func': str
},
'virtualization_type': {
'xpath': 'virtualizationType',
'transform_func': str
},
'hypervisor': {
'xpath': 'hypervisor',
'transform_func': str
},
'kernel_id': {
'xpath': 'kernelId',
'transform_func': str
},
'ramdisk_id': {
'xpath': 'ramdiskId',
'transform_func': str
}
},
'network': {
'state': {
'xpath': 'state',
'transform_func': str
},
'dhcp_options_id': {
'xpath': 'dhcpOptionsId',
'transform_func': str
},
'instance_tenancy': {
'xpath': 'instanceTenancy',
'transform_func': str
},
'is_default': {
'xpath': 'isDefault',
'transform_func': str
}
},
'network_interface': {
'subnet_id': {
'xpath': 'subnetId',
'transform_func': str
},
'vpc_id': {
'xpath': 'vpcId',
'transform_func': str
},
'zone': {
'xpath': 'availabilityZone',
'transform_func': str
},
'description': {
'xpath': 'description',
'transform_func': str
},
'owner_id': {
'xpath': 'ownerId',
'transform_func': str
},
'mac_address': {
'xpath': 'macAddress',
'transform_func': str
},
'private_dns_name': {
'xpath': 'privateIpAddressesSet/privateDnsName',
'transform_func': str
},
'source_dest_check': {
'xpath': 'sourceDestCheck',
'transform_func': str
}
},
'network_interface_attachment': {
'attachment_id': {
'xpath': 'attachment/attachmentId',
'transform_func': str
},
'instance_id': {
'xpath': 'attachment/instanceId',
'transform_func': str
},
'owner_id': {
'xpath': 'attachment/instanceOwnerId',
'transform_func': str
},
'device_index': {
'xpath': 'attachment/deviceIndex',
'transform_func': int
},
'status': {
'xpath': 'attachment/status',
'transform_func': str
},
'attach_time': {
'xpath': 'attachment/attachTime',
'transform_func': parse_date
},
'delete': {
'xpath': 'attachment/deleteOnTermination',
'transform_func': str
}
},
'node': {
'availability': {
'xpath': 'placement/availabilityZone',
'transform_func': str
},
'architecture': {
'xpath': 'architecture',
'transform_func': str
},
'client_token': {
'xpath': 'clientToken',
'transform_func': str
},
'dns_name': {
'xpath': 'dnsName',
'transform_func': str
},
'hypervisor': {
'xpath': 'hypervisor',
'transform_func': str
},
'iam_profile': {
'xpath': 'iamInstanceProfile/id',
'transform_func': str
},
'image_id': {
'xpath': 'imageId',
'transform_func': str
},
'instance_id': {
'xpath': 'instanceId',
'transform_func': str
},
'instance_lifecycle': {
'xpath': 'instanceLifecycle',
'transform_func': str
},
'instance_tenancy': {
'xpath': 'placement/tenancy',
'transform_func': str
},
'instance_type': {
'xpath': 'instanceType',
'transform_func': str
},
'key_name': {
'xpath': 'keyName',
'transform_func': str
},
'launch_index': {
'xpath': 'amiLaunchIndex',
'transform_func': int
},
'launch_time': {
'xpath': 'launchTime',
'transform_func': str
},
'kernel_id': {
'xpath': 'kernelId',
'transform_func': str
},
'monitoring': {
'xpath': 'monitoring/state',
'transform_func': str
},
'platform': {
'xpath': 'platform',
'transform_func': str
},
'private_dns': {
'xpath': 'privateDnsName',
'transform_func': str
},
'ramdisk_id': {
'xpath': 'ramdiskId',
'transform_func': str
},
'root_device_type': {
'xpath': 'rootDeviceType',
'transform_func': str
},
'root_device_name': {
'xpath': 'rootDeviceName',
'transform_func': str
},
'reason': {
'xpath': 'reason',
'transform_func': str
},
'source_dest_check': {
'xpath': 'sourceDestCheck',
'transform_func': str
},
'status': {
'xpath': 'instanceState/name',
'transform_func': str
},
'subnet_id': {
'xpath': 'subnetId',
'transform_func': str
},
'virtualization_type': {
'xpath': 'virtualizationType',
'transform_func': str
},
'ebs_optimized': {
'xpath': 'ebsOptimized',
'transform_func': str
},
'vpc_id': {
'xpath': 'vpcId',
'transform_func': str
}
},
'reserved_node': {
'instance_type': {
'xpath': 'instanceType',
'transform_func': str
},
'availability': {
'xpath': 'availabilityZone',
'transform_func': str
},
'start': {
'xpath': 'start',
'transform_func': str
},
'duration': {
'xpath': 'duration',
'transform_func': int
},
'usage_price': {
'xpath': 'usagePrice',
'transform_func': float
},
'fixed_price': {
'xpath': 'fixedPrice',
'transform_func': float
},
'instance_count': {
'xpath': 'instanceCount',
'transform_func': int
},
'description': {
'xpath': 'productDescription',
'transform_func': str
},
'instance_tenancy': {
'xpath': 'instanceTenancy',
'transform_func': str
},
'currency_code': {
'xpath': 'currencyCode',
'transform_func': str
},
'offering_type': {
'xpath': 'offeringType',
'transform_func': str
}
},
'security_group': {
'vpc_id': {
'xpath': 'vpcId',
'transform_func': str
},
'description': {
'xpath': 'groupDescription',
'transform_func': str
},
'owner_id': {
'xpath': 'ownerId',
'transform_func': str
}
},
'snapshot': {
'volume_id': {
'xpath': 'volumeId',
'transform_func': str
},
'state': {
'xpath': 'status',
'transform_func': str
},
'description': {
'xpath': 'description',
'transform_func': str
},
'progress': {
'xpath': 'progress',
'transform_func': str
},
'start_time': {
'xpath': 'startTime',
'transform_func': parse_date
}
},
'subnet': {
'cidr_block': {
'xpath': 'cidrBlock',
'transform_func': str
},
'available_ips': {
'xpath': 'availableIpAddressCount',
'transform_func': int
},
'zone': {
'xpath': 'availabilityZone',
'transform_func': str
},
'vpc_id': {
'xpath': 'vpcId',
'transform_func': str
}
},
'volume': {
'device': {
'xpath': 'attachmentSet/item/device',
'transform_func': str
},
'snapshot_id': {
'xpath': 'snapshotId',
'transform_func': lambda v: str(v) or None
},
'iops': {
'xpath': 'iops',
'transform_func': int
},
'zone': {
'xpath': 'availabilityZone',
'transform_func': str
},
'create_time': {
'xpath': 'createTime',
'transform_func': parse_date
},
'state': {
'xpath': 'status',
'transform_func': str
},
'attach_time': {
'xpath': 'attachmentSet/item/attachTime',
'transform_func': parse_date
},
'attachment_status': {
'xpath': 'attachmentSet/item/status',
'transform_func': str
},
'instance_id': {
'xpath': 'attachmentSet/item/instanceId',
'transform_func': str
},
'delete': {
'xpath': 'attachmentSet/item/deleteOnTermination',
'transform_func': str
}
},
'route_table': {
'vpc_id': {
'xpath': 'vpcId',
'transform_func': str
}
}
}
VALID_EC2_REGIONS = REGION_DETAILS.keys()
VALID_EC2_REGIONS = [r for r in VALID_EC2_REGIONS if r != 'nimbus']
class EC2NodeLocation(NodeLocation):
def __init__(self, id, name, country, driver, availability_zone):
super(EC2NodeLocation, self).__init__(id, name, country, driver)
self.availability_zone = availability_zone
def __repr__(self):
return (('<EC2NodeLocation: id=%s, name=%s, country=%s, '
'availability_zone=%s driver=%s>')
% (self.id, self.name, self.country,
self.availability_zone, self.driver.name))
class EC2Response(AWSBaseResponse):
"""
EC2 specific response parsing and error handling.
"""
def parse_error(self):
err_list = []
# Okay, so for Eucalyptus, you can get a 403, with no body,
# if you are using the wrong user/password.
msg = "Failure: 403 Forbidden"
if self.status == 403 and self.body[:len(msg)] == msg:
raise InvalidCredsError(msg)
try:
body = ET.XML(self.body)
except:
raise MalformedResponseError("Failed to parse XML",
body=self.body, driver=EC2NodeDriver)
for err in body.findall('Errors/Error'):
code, message = err.getchildren()
err_list.append('%s: %s' % (code.text, message.text))
if code.text == 'InvalidClientTokenId':
raise InvalidCredsError(err_list[-1])
if code.text == 'SignatureDoesNotMatch':
raise InvalidCredsError(err_list[-1])
if code.text == 'AuthFailure':
raise InvalidCredsError(err_list[-1])
if code.text == 'OptInRequired':
raise InvalidCredsError(err_list[-1])
if code.text == 'IdempotentParameterMismatch':
raise IdempotentParamError(err_list[-1])
if code.text == 'InvalidKeyPair.NotFound':
# TODO: Use connection context instead
match = re.match(r'.*\'(.+?)\'.*', message.text)
if match:
name = match.groups()[0]
else:
name = None
raise KeyPairDoesNotExistError(name=name,
driver=self.connection.driver)
return '\n'.join(err_list)
class EC2Connection(SignedAWSConnection):
"""
Represents a single connection to the EC2 Endpoint.
"""
version = API_VERSION
host = REGION_DETAILS['us-east-1']['endpoint']
responseCls = EC2Response
service_name = 'ec2'
class ExEC2AvailabilityZone(object):
"""
Extension class which stores information about an EC2 availability zone.
Note: This class is EC2 specific.
"""
def __init__(self, name, zone_state, region_name):
self.name = name
self.zone_state = zone_state
self.region_name = region_name
def __repr__(self):
return (('<ExEC2AvailabilityZone: name=%s, zone_state=%s, '
'region_name=%s>')
% (self.name, self.zone_state, self.region_name))
class EC2ReservedNode(Node):
"""
Class which stores information about EC2 reserved instances/nodes
Inherits from Node and passes in None for name and private/public IPs
Note: This class is EC2 specific.
"""
def __init__(self, id, state, driver, size=None, image=None, extra=None):
super(EC2ReservedNode, self).__init__(id=id, name=None, state=state,
public_ips=None,
private_ips=None,
driver=driver, extra=extra)
def __repr__(self):
return (('<EC2ReservedNode: id=%s>') % (self.id))
class EC2SecurityGroup(object):
"""
Represents information about a Security group
Note: This class is EC2 specific.
"""
def __init__(self, id, name, ingress_rules, egress_rules, extra=None):
self.id = id
self.name = name
self.ingress_rules = ingress_rules
self.egress_rules = egress_rules
self.extra = extra or {}
def __repr__(self):
return (('<EC2SecurityGroup: id=%s, name=%s')
% (self.id, self.name))
class EC2PlacementGroup(object):
"""
Represents information about a Placement Grous
Note: This class is EC2 specific.
"""
def __init__(self, name, state, strategy='cluster', extra=None):
self.name = name
self.strategy = strategy
self.extra = extra or {}
def __repr__(self):
return '<EC2PlacementGroup: name=%s, state=%s>' % (self.name,
self.strategy)
class EC2Network(object):
"""
Represents information about a VPC (Virtual Private Cloud) network
Note: This class is EC2 specific.
"""
def __init__(self, id, name, cidr_block, extra=None):
self.id = id
self.name = name
self.cidr_block = cidr_block
self.extra = extra or {}
def __repr__(self):
return (('<EC2Network: id=%s, name=%s')
% (self.id, self.name))
class EC2NetworkSubnet(object):
"""
Represents information about a VPC (Virtual Private Cloud) subnet
Note: This class is EC2 specific.
"""
def __init__(self, id, name, state, extra=None):
self.id = id
self.name = name
self.state = state
self.extra = extra or {}
def __repr__(self):
return (('<EC2NetworkSubnet: id=%s, name=%s') % (self.id, self.name))
class EC2NetworkInterface(object):
"""
Represents information about a VPC network interface
Note: This class is EC2 specific. The state parameter denotes the current
status of the interface. Valid values for state are attaching, attached,
detaching and detached.
"""
def __init__(self, id, name, state, extra=None):
self.id = id
self.name = name
self.state = state
self.extra = extra or {}
def __repr__(self):
return (('<EC2NetworkInterface: id=%s, name=%s')
% (self.id, self.name))
class ElasticIP(object):
"""
Represents information about an elastic IP address
:param ip: The elastic IP address
:type ip: ``str``
:param domain: The domain that the IP resides in (EC2-Classic/VPC).
EC2 classic is represented with standard and VPC
is represented with vpc.
:type domain: ``str``
:param instance_id: The identifier of the instance which currently
has the IP associated.
:type instance_id: ``str``
Note: This class is used to support both EC2 and VPC IPs.
For VPC specific attributes are stored in the extra
dict to make promotion to the base API easier.
"""
def __init__(self, ip, domain, instance_id, extra=None):
self.ip = ip
self.domain = domain
self.instance_id = instance_id
self.extra = extra or {}
def __repr__(self):
return (('<ElasticIP: ip=%s, domain=%s, instance_id=%s>')
% (self.ip, self.domain, self.instance_id))
class VPCInternetGateway(object):
"""
Class which stores information about VPC Internet Gateways.
Note: This class is VPC specific.
"""
def __init__(self, id, name, vpc_id, state, driver, extra=None):
self.id = id
self.name = name
self.vpc_id = vpc_id
self.state = state
self.extra = extra or {}
def __repr__(self):
return (('<VPCInternetGateway: id=%s>') % (self.id))
class EC2RouteTable(object):
"""
Class which stores information about VPC Route Tables.
Note: This class is VPC specific.
"""
def __init__(self, id, name, routes, subnet_associations,
propagating_gateway_ids, extra=None):
"""
:param id: The ID of the route table.
:type id: ``str``
:param name: The name of the route table.
:type name: ``str``
:param routes: A list of routes in the route table.
:type routes: ``list`` of :class:`EC2Route`
:param subnet_associations: A list of associations between the
route table and one or more subnets.
:type subnet_associations: ``list`` of
:class:`EC2SubnetAssociation`
:param propagating_gateway_ids: The list of IDs of any virtual
private gateways propagating the
routes.
:type propagating_gateway_ids: ``list``
"""
self.id = id
self.name = name
self.routes = routes
self.subnet_associations = subnet_associations
self.propagating_gateway_ids = propagating_gateway_ids
self.extra = extra or {}
def __repr__(self):
return (('<EC2RouteTable: id=%s>') % (self.id))
class EC2Route(object):
"""
Class which stores information about a Route.
Note: This class is VPC specific.
"""
def __init__(self, cidr, gateway_id, instance_id, owner_id,
interface_id, state, origin, vpc_peering_connection_id):
"""
:param cidr: The CIDR block used for the destination match.
:type cidr: ``str``
:param gateway_id: The ID of a gateway attached to the VPC.
:type gateway_id: ``str``
:param instance_id: The ID of a NAT instance in the VPC.
:type instance_id: ``str``
:param owner_id: The AWS account ID of the owner of the instance.
:type owner_id: ``str``
:param interface_id: The ID of the network interface.
:type interface_id: ``str``
:param state: The state of the route (active | blackhole).
:type state: ``str``
:param origin: Describes how the route was created.
:type origin: ``str``
:param vpc_peering_connection_id: The ID of the VPC
peering connection.
:type vpc_peering_connection_id: ``str``
"""
self.cidr = cidr
self.gateway_id = gateway_id
self.instance_id = instance_id
self.owner_id = owner_id
self.interface_id = interface_id
self.state = state
self.origin = origin
self.vpc_peering_connection_id = vpc_peering_connection_id
def __repr__(self):
return (('<EC2Route: cidr=%s>') % (self.cidr))
class EC2SubnetAssociation(object):
"""
Class which stores information about Route Table associated with
a given Subnet in a VPC
Note: This class is VPC specific.
"""
def __init__(self, id, route_table_id, subnet_id, main=False):
"""
:param id: The ID of the subnet association in the VPC.
:type id: ``str``
:param route_table_id: The ID of a route table in the VPC.
:type route_table_id: ``str``
:param subnet_id: The ID of a subnet in the VPC.
:type subnet_id: ``str``
:param main: If true, means this is a main VPC route table.
:type main: ``bool``
"""
self.id = id
self.route_table_id = route_table_id
self.subnet_id = subnet_id
self.main = main
def __repr__(self):
return (('<EC2SubnetAssociation: id=%s>') % (self.id))
class BaseEC2NodeDriver(NodeDriver):
"""
Base Amazon EC2 node driver.
Used for main EC2 and other derivate driver classes to inherit from it.
"""
connectionCls = EC2Connection
features = {'create_node': ['ssh_key']}
path = '/'
signature_version = DEFAULT_SIGNATURE_VERSION
NODE_STATE_MAP = {
'pending': NodeState.PENDING,
'running': NodeState.RUNNING,
'shutting-down': NodeState.UNKNOWN,
'terminated': NodeState.TERMINATED
}
# http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_Volume.html
VOLUME_STATE_MAP = {
'available': StorageVolumeState.AVAILABLE,
'in-use': StorageVolumeState.INUSE,
'error': StorageVolumeState.ERROR,
'creating': StorageVolumeState.CREATING,
'deleting': StorageVolumeState.DELETING,
'deleted': StorageVolumeState.DELETED,
'error_deleting': StorageVolumeState.ERROR
}
def list_nodes(self, ex_node_ids=None, ex_filters=None):
"""
List all nodes
Ex_node_ids parameter is used to filter the list of
nodes that should be returned. Only the nodes
with the corresponding node ids will be returned.
:param ex_node_ids: List of ``node.id``
:type ex_node_ids: ``list`` of ``str``
:param ex_filters: The filters so that the response includes
information for only certain nodes.
:type ex_filters: ``dict``
:rtype: ``list`` of :class:`Node`
"""
params = {'Action': 'DescribeInstances'}
if ex_node_ids:
params.update(self._pathlist('InstanceId', ex_node_ids))
if ex_filters:
params.update(self._build_filters(ex_filters))
elem = self.connection.request(self.path, params=params).object
nodes = []
for rs in findall(element=elem, xpath='reservationSet/item',
namespace=NAMESPACE):
nodes += self._to_nodes(rs, 'instancesSet/item')
nodes_elastic_ips_mappings = self.ex_describe_addresses(nodes)
for node in nodes:
ips = nodes_elastic_ips_mappings[node.id]
node.public_ips.extend(ips)
return nodes
def list_sizes(self, location=None):
available_types = REGION_DETAILS[self.region_name]['instance_types']
sizes = []
for instance_type in available_types:
attributes = INSTANCE_TYPES[instance_type]
attributes = copy.deepcopy(attributes)
price = self._get_size_price(size_id=instance_type)
attributes.update({'price': price})
sizes.append(NodeSize(driver=self, **attributes))
return sizes
def list_images(self, location=None, ex_image_ids=None, ex_owner=None,
ex_executableby=None, ex_filters=None):
"""
List all images
@inherits: :class:`NodeDriver.list_images`
Ex_image_ids parameter is used to filter the list of
images that should be returned. Only the images
with the corresponding image ids will be returned.
Ex_owner parameter is used to filter the list of
images that should be returned. Only the images
with the corresponding owner will be returned.
Valid values: amazon|aws-marketplace|self|all|aws id
Ex_executableby parameter describes images for which
the specified user has explicit launch permissions.
The user can be an AWS account ID, self to return
images for which the sender of the request has
explicit launch permissions, or all to return
images with public launch permissions.
Valid values: all|self|aws id
Ex_filters parameter is used to filter the list of
images that should be returned. Only images matchind
the filter will be returned.
:param ex_image_ids: List of ``NodeImage.id``
:type ex_image_ids: ``list`` of ``str``
:param ex_owner: Owner name
:type ex_owner: ``str``
:param ex_executableby: Executable by
:type ex_executableby: ``str``
:param ex_filters: Filter by
:type ex_filters: ``dict``
:rtype: ``list`` of :class:`NodeImage`
"""
params = {'Action': 'DescribeImages'}
if ex_owner:
params.update({'Owner.1': ex_owner})
if ex_executableby:
params.update({'ExecutableBy.1': ex_executableby})
if ex_image_ids:
for index, image_id in enumerate(ex_image_ids):
index += 1
params.update({'ImageId.%s' % (index): image_id})
if ex_filters:
params.update(self._build_filters(ex_filters))
images = self._to_images(
self.connection.request(self.path, params=params).object
)
return images
def get_image(self, image_id):
"""
Get an image based on an image_id
:param image_id: Image identifier
:type image_id: ``str``
:return: A NodeImage object
:rtype: :class:`NodeImage`
"""
images = self.list_images(ex_image_ids=[image_id])
image = images[0]
return image
def list_locations(self):
locations = []
for index, availability_zone in \
enumerate(self.ex_list_availability_zones()):
locations.append(EC2NodeLocation(
index, availability_zone.name, self.country, self,
availability_zone)
)
return locations
def list_volumes(self, node=None):
params = {
'Action': 'DescribeVolumes',
}
if node:
filters = {'attachment.instance-id': node.id}
params.update(self._build_filters(filters))
response = self.connection.request(self.path, params=params).object
volumes = [self._to_volume(el) for el in response.findall(
fixxpath(xpath='volumeSet/item', namespace=NAMESPACE))
]
return volumes
def create_node(self, **kwargs):
"""
Create a new EC2 node.
Reference: http://bit.ly/8ZyPSy [docs.amazonwebservices.com]
@inherits: :class:`NodeDriver.create_node`
:keyword ex_keyname: The name of the key pair
:type ex_keyname: ``str``
:keyword ex_userdata: User data
:type ex_userdata: ``str``
:keyword ex_security_groups: A list of names of security groups to
assign to the node.
:type ex_security_groups: ``list``
:keyword ex_security_group_ids: A list of ids of security groups to
assign to the node.[for VPC nodes only]
:type ex_security_group_ids: ``list``
:keyword ex_metadata: Key/Value metadata to associate with a node
:type ex_metadata: ``dict``
:keyword ex_mincount: Minimum number of instances to launch
:type ex_mincount: ``int``
:keyword ex_maxcount: Maximum number of instances to launch
:type ex_maxcount: ``int``
:keyword ex_clienttoken: Unique identifier to ensure idempotency
:type ex_clienttoken: ``str``
:keyword ex_blockdevicemappings: ``list`` of ``dict`` block device
mappings.
:type ex_blockdevicemappings: ``list`` of ``dict``
:keyword ex_iamprofile: Name or ARN of IAM profile
:type ex_iamprofile: ``str``
:keyword ex_ebs_optimized: EBS-Optimized if True
:type ex_ebs_optimized: ``bool``
:keyword ex_subnet: The subnet to launch the instance into.
:type ex_subnet: :class:`.EC2Subnet`
:keyword ex_placement_group: The name of the placement group to
launch the instance into.
:type ex_placement_group: ``str``
"""
image = kwargs["image"]
size = kwargs["size"]
params = {
'Action': 'RunInstances',
'ImageId': image.id,
'MinCount': str(kwargs.get('ex_mincount', '1')),
'MaxCount': str(kwargs.get('ex_maxcount', '1')),
'InstanceType': size.id
}
if 'ex_security_groups' in kwargs and 'ex_securitygroup' in kwargs:
raise ValueError('You can only supply ex_security_groups or'
' ex_securitygroup')
# ex_securitygroup is here for backward compatibility
ex_security_groups = kwargs.get('ex_security_groups', None)
ex_securitygroup = kwargs.get('ex_securitygroup', None)
security_groups = ex_security_groups or ex_securitygroup
if security_groups:
if not isinstance(security_groups, (tuple, list)):
security_groups = [security_groups]
for sig in range(len(security_groups)):
params['SecurityGroup.%d' % (sig + 1,)] =\
security_groups[sig]
if 'ex_security_group_ids' in kwargs and 'ex_subnet' not in kwargs:
raise ValueError('You can only supply ex_security_group_ids'
' combinated with ex_subnet')
security_group_ids = kwargs.get('ex_security_group_ids', None)
if security_group_ids:
if not isinstance(security_group_ids, (tuple, list)):
security_group_ids = [security_group_ids]
for sig in range(len(security_group_ids)):
params['SecurityGroupId.%d' % (sig + 1,)] =\
security_group_ids[sig]
if 'location' in kwargs:
availability_zone = getattr(kwargs['location'],
'availability_zone', None)
if availability_zone:
if availability_zone.region_name != self.region_name:
raise AttributeError('Invalid availability zone: %s'
% (availability_zone.name))
params['Placement.AvailabilityZone'] = availability_zone.name
if 'auth' in kwargs and 'ex_keyname' in kwargs:
raise AttributeError('Cannot specify auth and ex_keyname together')
if 'auth' in kwargs:
auth = self._get_and_check_auth(kwargs['auth'])
key = self.ex_find_or_import_keypair_by_key_material(auth.pubkey)
params['KeyName'] = key['keyName']
if 'ex_keyname' in kwargs:
params['KeyName'] = kwargs['ex_keyname']
if 'ex_userdata' in kwargs:
params['UserData'] = base64.b64encode(b(kwargs['ex_userdata']))\
.decode('utf-8')
if 'ex_clienttoken' in kwargs:
params['ClientToken'] = kwargs['ex_clienttoken']
if 'ex_blockdevicemappings' in kwargs:
params.update(self._get_block_device_mapping_params(
kwargs['ex_blockdevicemappings']))
if 'ex_iamprofile' in kwargs:
if not isinstance(kwargs['ex_iamprofile'], basestring):
raise AttributeError('ex_iamprofile not string')
if kwargs['ex_iamprofile'].startswith('arn:aws:iam:'):
params['IamInstanceProfile.Arn'] = kwargs['ex_iamprofile']
else:
params['IamInstanceProfile.Name'] = kwargs['ex_iamprofile']
if 'ex_ebs_optimized' in kwargs:
params['EbsOptimized'] = kwargs['ex_ebs_optimized']
if 'ex_subnet' in kwargs:
params['SubnetId'] = kwargs['ex_subnet'].id
if 'ex_placement_group' in kwargs and kwargs['ex_placement_group']:
params['Placement.GroupName'] = kwargs['ex_placement_group']
object = self.connection.request(self.path, params=params).object
nodes = self._to_nodes(object, 'instancesSet/item')
for node in nodes:
tags = {'Name': kwargs['name']}
if 'ex_metadata' in kwargs:
tags.update(kwargs['ex_metadata'])
try:
self.ex_create_tags(resource=node, tags=tags)
except Exception:
continue
node.name = kwargs['name']
node.extra.update({'tags': tags})
if len(nodes) == 1:
return nodes[0]
else:
return nodes
def reboot_node(self, node):
params = {'Action': 'RebootInstances'}
params.update(self._pathlist('InstanceId', [node.id]))
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def destroy_node(self, node):
params = {'Action': 'TerminateInstances'}
params.update(self._pathlist('InstanceId', [node.id]))
res = self.connection.request(self.path, params=params).object
return self._get_terminate_boolean(res)
def create_volume(self, size, name, location=None, snapshot=None,
ex_volume_type='standard', ex_iops=None):
"""
Create a new volume.
:param size: Size of volume in gigabytes (required)
:type size: ``int``
:param name: Name of the volume to be created
:type name: ``str``
:param location: Which data center to create a volume in. If
empty, undefined behavior will be selected.
(optional)
:type location: :class:`.NodeLocation`
:param snapshot: Snapshot from which to create the new
volume. (optional)
:type snapshot: :class:`.VolumeSnapshot`
:param location: Datacenter in which to create a volume in.
:type location: :class:`.ExEC2AvailabilityZone`
:param ex_volume_type: Type of volume to create.
:type ex_volume_type: ``str``
:param iops: The number of I/O operations per second (IOPS)
that the volume supports. Only used if ex_volume_type
is io1.
:type iops: ``int``
:return: The newly created volume.
:rtype: :class:`StorageVolume`
"""
valid_volume_types = ['standard', 'io1', 'gp2']
params = {
'Action': 'CreateVolume',
'Size': str(size)}
if ex_volume_type and ex_volume_type not in valid_volume_types:
raise ValueError('Invalid volume type specified: %s' %
(ex_volume_type))
if snapshot:
params['SnapshotId'] = snapshot.id
if location is not None:
params['AvailabilityZone'] = location.availability_zone.name
if ex_volume_type:
params['VolumeType'] = ex_volume_type
if ex_volume_type == 'io1' and ex_iops:
params['Iops'] = ex_iops
volume = self._to_volume(
self.connection.request(self.path, params=params).object,
name=name)
if self.ex_create_tags(volume, {'Name': name}):
volume.extra['tags']['Name'] = name
return volume
def attach_volume(self, node, volume, device):
params = {
'Action': 'AttachVolume',
'VolumeId': volume.id,
'InstanceId': node.id,
'Device': device}
self.connection.request(self.path, params=params)
return True
def detach_volume(self, volume):
params = {
'Action': 'DetachVolume',
'VolumeId': volume.id}
self.connection.request(self.path, params=params)
return True
def destroy_volume(self, volume):
params = {
'Action': 'DeleteVolume',
'VolumeId': volume.id}
response = self.connection.request(self.path, params=params).object
return self._get_boolean(response)
def create_volume_snapshot(self, volume, name=None):
"""
Create snapshot from volume
:param volume: Instance of ``StorageVolume``
:type volume: ``StorageVolume``
:param name: Name of snapshot (optional)
:type name: ``str``
:rtype: :class:`VolumeSnapshot`
"""
params = {
'Action': 'CreateSnapshot',
'VolumeId': volume.id,
}
if name:
params.update({
'Description': name,
})
response = self.connection.request(self.path, params=params).object
snapshot = self._to_snapshot(response, name)
if name and self.ex_create_tags(snapshot, {'Name': name}):
snapshot.extra['tags']['Name'] = name
return snapshot
def list_volume_snapshots(self, volume):
return [snapshot for snapshot in self.list_snapshots(owner='self')
if snapshot.extra["volume_id"] == volume.id]
def list_snapshots(self, snapshot=None, owner=None):
"""
Describe all snapshots.
:param snapshot: If provided, only return snapshot information for the
provided snapshot.
:param owner: Owner for snapshot: self|amazon|ID
:type owner: ``str``
:rtype: ``list`` of :class:`VolumeSnapshot`
"""
params = {
'Action': 'DescribeSnapshots',
}
if snapshot:
params.update({
'SnapshotId.1': snapshot.id,
})
if owner:
params.update({
'Owner.1': owner,
})
response = self.connection.request(self.path, params=params).object
snapshots = self._to_snapshots(response)
return snapshots
def destroy_volume_snapshot(self, snapshot):
params = {
'Action': 'DeleteSnapshot',
'SnapshotId': snapshot.id
}
response = self.connection.request(self.path, params=params).object
return self._get_boolean(response)
# Key pair management methods
def list_key_pairs(self):
params = {
'Action': 'DescribeKeyPairs'
}
response = self.connection.request(self.path, params=params)
elems = findall(element=response.object, xpath='keySet/item',
namespace=NAMESPACE)
key_pairs = self._to_key_pairs(elems=elems)
return key_pairs
def get_key_pair(self, name):
params = {
'Action': 'DescribeKeyPairs',
'KeyName': name
}
response = self.connection.request(self.path, params=params)
elems = findall(element=response.object, xpath='keySet/item',
namespace=NAMESPACE)
key_pair = self._to_key_pairs(elems=elems)[0]
return key_pair
def create_key_pair(self, name):
params = {
'Action': 'CreateKeyPair',
'KeyName': name
}
response = self.connection.request(self.path, params=params)
elem = response.object
key_pair = self._to_key_pair(elem=elem)
return key_pair
def import_key_pair_from_string(self, name, key_material):
base64key = ensure_string(base64.b64encode(b(key_material)))
params = {
'Action': 'ImportKeyPair',
'KeyName': name,
'PublicKeyMaterial': base64key
}
response = self.connection.request(self.path, params=params)
elem = response.object
key_pair = self._to_key_pair(elem=elem)
return key_pair
def delete_key_pair(self, key_pair):
params = {
'Action': 'DeleteKeyPair',
'KeyName': key_pair.name
}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def copy_image(self, image, source_region, name=None, description=None):
"""
Copy an Amazon Machine Image from the specified source region
to the current region.
@inherits: :class:`NodeDriver.copy_image`
:param source_region: The region where the image resides
:type source_region: ``str``
:param image: Instance of class NodeImage
:type image: :class:`NodeImage`
:param name: The name of the new image
:type name: ``str``
:param description: The description of the new image
:type description: ``str``
:return: Instance of class ``NodeImage``
:rtype: :class:`NodeImage`
"""
params = {'Action': 'CopyImage',
'SourceRegion': source_region,
'SourceImageId': image.id}
if name is not None:
params['Name'] = name
if description is not None:
params['Description'] = description
image = self._to_image(
self.connection.request(self.path, params=params).object)
return image
def create_image(self, node, name, description=None, reboot=False,
block_device_mapping=None):
"""
Create an Amazon Machine Image based off of an EBS-backed instance.
@inherits: :class:`NodeDriver.create_image`
:param node: Instance of ``Node``
:type node: :class: `Node`
:param name: The name for the new image
:type name: ``str``
:param block_device_mapping: A dictionary of the disk layout
An example of this dict is included
below.
:type block_device_mapping: ``list`` of ``dict``
:param reboot: Whether or not to shutdown the instance before
creation. Amazon calls this NoReboot and
sets it to false by default to ensure a
clean image.
:type reboot: ``bool``
:param description: An optional description for the new image
:type description: ``str``
An example block device mapping dictionary is included:
mapping = [{'VirtualName': None,
'Ebs': {'VolumeSize': 10,
'VolumeType': 'standard',
'DeleteOnTermination': 'true'},
'DeviceName': '/dev/sda1'}]
:return: Instance of class ``NodeImage``
:rtype: :class:`NodeImage`
"""
params = {'Action': 'CreateImage',
'InstanceId': node.id,
'Name': name,
'NoReboot': not reboot}
if description is not None:
params['Description'] = description
if block_device_mapping is not None:
params.update(self._get_block_device_mapping_params(
block_device_mapping))
image = self._to_image(
self.connection.request(self.path, params=params).object)
return image
def delete_image(self, image):
"""
Deletes an image at Amazon given a NodeImage object
@inherits: :class:`NodeDriver.delete_image`
:param image: Instance of ``NodeImage``
:type image: :class: `NodeImage`
:rtype: ``bool``
"""
params = {'Action': 'DeregisterImage',
'ImageId': image.id}
response = self.connection.request(self.path, params=params).object
return self._get_boolean(response)
def ex_create_placement_group(self, name):
"""
Creates new Placement Group
:param name: Name for new placement Group
:type name: ``str``
:rtype: ``bool``
"""
params = {'Action': 'CreatePlacementGroup',
'Strategy': 'cluster',
'GroupName': name}
response = self.connection.request(self.path, params=params).object
return self._get_boolean(response)
def ex_delete_placement_group(self, name):
"""
Deletes Placement Group
:param name: Placement Group name
:type name: ``str``
:rtype: ``bool``
"""
params = {'Action': 'DeletePlacementGroup',
'GroupName': name}
response = self.connection.request(self.path, params=params).object
return self._get_boolean(response)
def ex_list_placement_groups(self, names=None):
"""
List Placement Groups
:param names: Placement Group names
:type names: ``list`` of ``str``
:rtype: ``list`` of :class:`.EC2PlacementGroup`
"""
names = names or []
params = {'Action': 'DescribePlacementGroups'}
for index, name in enumerate(names):
params['GroupName.%s' % index + 1] = name
response = self.connection.request(self.path, params=params).object
return self._to_placement_groups(response)
def ex_register_image(self, name, description=None, architecture=None,
image_location=None, root_device_name=None,
block_device_mapping=None, kernel_id=None,
ramdisk_id=None, virtualization_type=None):
"""
Registers an Amazon Machine Image based off of an EBS-backed instance.
Can also be used to create images from snapshots. More information
can be found at http://goo.gl/hqZq0a.
:param name: The name for the AMI being registered
:type name: ``str``
:param description: The description of the AMI (optional)
:type description: ``str``
:param architecture: The architecture of the AMI (i386/x86_64)
(optional)
:type architecture: ``str``
:param image_location: The location of the AMI within Amazon S3
Required if registering an instance
store-backed AMI
:type image_location: ``str``
:param root_device_name: The device name for the root device
Required if registering an EBS-backed AMI
:type root_device_name: ``str``
:param block_device_mapping: A dictionary of the disk layout
(optional)
:type block_device_mapping: ``dict``
:param kernel_id: Kernel id for AMI (optional)
:type kernel_id: ``str``
:param ramdisk_id: RAM disk for AMI (optional)
:type ramdisk_id: ``str``
:param virtualization_type: The type of virtualization for the
AMI you are registering, paravirt
or hvm (optional)
:type virtualization_type: ``str``
:rtype: :class:`NodeImage`
"""
params = {'Action': 'RegisterImage',
'Name': name}
if description is not None:
params['Description'] = description
if architecture is not None:
params['Architecture'] = architecture
if image_location is not None:
params['ImageLocation'] = image_location
if root_device_name is not None:
params['RootDeviceName'] = root_device_name
if block_device_mapping is not None:
params.update(self._get_block_device_mapping_params(
block_device_mapping))
if kernel_id is not None:
params['KernelId'] = kernel_id
if ramdisk_id is not None:
params['RamDiskId'] = ramdisk_id
if virtualization_type is not None:
params['VirtualizationType'] = virtualization_type
image = self._to_image(
self.connection.request(self.path, params=params).object
)
return image
def ex_list_networks(self, network_ids=None, filters=None):
"""
Return a list of :class:`EC2Network` objects for the
current region.
:param network_ids: Return only networks matching the provided
network IDs. If not specified, a list of all
the networks in the corresponding region
is returned.
:type network_ids: ``list``
:param filters: The filters so that the response includes
information for only certain networks.
:type filters: ``dict``
:rtype: ``list`` of :class:`EC2Network`
"""
params = {'Action': 'DescribeVpcs'}
if network_ids:
params.update(self._pathlist('VpcId', network_ids))
if filters:
params.update(self._build_filters(filters))
return self._to_networks(
self.connection.request(self.path, params=params).object
)
def ex_create_network(self, cidr_block, name=None,
instance_tenancy='default'):
"""
Create a network/VPC
:param cidr_block: The CIDR block assigned to the network
:type cidr_block: ``str``
:param name: An optional name for the network
:type name: ``str``
:param instance_tenancy: The allowed tenancy of instances launched
into the VPC.
Valid values: default/dedicated
:type instance_tenancy: ``str``
:return: Dictionary of network properties
:rtype: ``dict``
"""
params = {'Action': 'CreateVpc',
'CidrBlock': cidr_block,
'InstanceTenancy': instance_tenancy}
response = self.connection.request(self.path, params=params).object
element = response.findall(fixxpath(xpath='vpc',
namespace=NAMESPACE))[0]
network = self._to_network(element, name)
if name and self.ex_create_tags(network, {'Name': name}):
network.extra['tags']['Name'] = name
return network
def ex_delete_network(self, vpc):
"""
Deletes a network/VPC.
:param vpc: VPC to delete.
:type vpc: :class:`.EC2Network`
:rtype: ``bool``
"""
params = {'Action': 'DeleteVpc', 'VpcId': vpc.id}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_list_subnets(self, subnet_ids=None, filters=None):
"""
Return a list of :class:`EC2NetworkSubnet` objects for the
current region.
:param subnet_ids: Return only subnets matching the provided
subnet IDs. If not specified, a list of all
the subnets in the corresponding region
is returned.
:type subnet_ids: ``list``
:param filters: The filters so that the response includes
information for only certain subnets.
:type filters: ``dict``
:rtype: ``list`` of :class:`EC2NetworkSubnet`
"""
params = {'Action': 'DescribeSubnets'}
if subnet_ids:
params.update(self._pathlist('SubnetId', subnet_ids))
if filters:
params.update(self._build_filters(filters))
return self._to_subnets(
self.connection.request(self.path, params=params).object
)
def ex_create_subnet(self, vpc_id, cidr_block,
availability_zone, name=None):
"""
Create a network subnet within a VPC
:param vpc_id: The ID of the VPC that the subnet should be
associated with
:type vpc_id: ``str``
:param cidr_block: The CIDR block assigned to the subnet
:type cidr_block: ``str``
:param availability_zone: The availability zone where the subnet
should reside
:type availability_zone: ``str``
:param name: An optional name for the network
:type name: ``str``
:rtype: :class: `EC2NetworkSubnet`
"""
params = {'Action': 'CreateSubnet',
'VpcId': vpc_id,
'CidrBlock': cidr_block,
'AvailabilityZone': availability_zone}
response = self.connection.request(self.path, params=params).object
element = response.findall(fixxpath(xpath='subnet',
namespace=NAMESPACE))[0]
subnet = self._to_subnet(element, name)
if name and self.ex_create_tags(subnet, {'Name': name}):
subnet.extra['tags']['Name'] = name
return subnet
def ex_delete_subnet(self, subnet):
"""
Deletes a VPC subnet.
:param subnet: The subnet to delete
:type subnet: :class:`.EC2NetworkSubnet`
:rtype: ``bool``
"""
params = {'Action': 'DeleteSubnet', 'SubnetId': subnet.id}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_list_security_groups(self):
"""
List existing Security Groups.
@note: This is a non-standard extension API, and only works for EC2.
:rtype: ``list`` of ``str``
"""
params = {'Action': 'DescribeSecurityGroups'}
response = self.connection.request(self.path, params=params).object
groups = []
for group in findall(element=response, xpath='securityGroupInfo/item',
namespace=NAMESPACE):
name = findtext(element=group, xpath='groupName',
namespace=NAMESPACE)
groups.append(name)
return groups
def ex_get_security_groups(self, group_ids=None,
group_names=None, filters=None):
"""
Return a list of :class:`EC2SecurityGroup` objects for the
current region.
:param group_ids: Return only groups matching the provided
group IDs.
:type group_ids: ``list``
:param group_names: Return only groups matching the provided
group names.
:type group_ids: ``list``
:param filters: The filters so that the response includes
information for only specific security groups.
:type filters: ``dict``
:rtype: ``list`` of :class:`EC2SecurityGroup`
"""
params = {'Action': 'DescribeSecurityGroups'}
if group_ids:
params.update(self._pathlist('GroupId', group_ids))
if group_names:
for name_idx, group_name in enumerate(group_names):
name_idx += 1 # We want 1-based indexes
name_key = 'GroupName.%s' % (name_idx)
params[name_key] = group_name
if filters:
params.update(self._build_filters(filters))
response = self.connection.request(self.path, params=params)
return self._to_security_groups(response.object)
def ex_create_security_group(self, name, description, vpc_id=None):
"""
Creates a new Security Group in EC2-Classic or a targeted VPC.
:param name: The name of the security group to Create.
This must be unique.
:type name: ``str``
:param description: Human readable description of a Security
Group.
:type description: ``str``
:param vpc_id: Optional identifier for VPC networks
:type vpc_id: ``str``
:rtype: ``dict``
"""
params = {'Action': 'CreateSecurityGroup',
'GroupName': name,
'GroupDescription': description}
if vpc_id is not None:
params['VpcId'] = vpc_id
response = self.connection.request(self.path, params=params).object
group_id = findattr(element=response, xpath='groupId',
namespace=NAMESPACE)
return {
'group_id': group_id
}
def ex_delete_security_group_by_id(self, group_id):
"""
Deletes a new Security Group using the group id.
:param group_id: The ID of the security group
:type group_id: ``str``
:rtype: ``bool``
"""
params = {'Action': 'DeleteSecurityGroup', 'GroupId': group_id}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_delete_security_group_by_name(self, group_name):
"""
Deletes a new Security Group using the group name.
:param group_name: The name of the security group
:type group_name: ``str``
:rtype: ``bool``
"""
params = {'Action': 'DeleteSecurityGroup', 'GroupName': group_name}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_delete_security_group(self, name):
"""
Wrapper method which calls ex_delete_security_group_by_name.
:param name: The name of the security group
:type name: ``str``
:rtype: ``bool``
"""
return self.ex_delete_security_group_by_name(name)
def ex_authorize_security_group(self, name, from_port, to_port, cidr_ip,
protocol='tcp'):
"""
Edit a Security Group to allow specific traffic.
@note: This is a non-standard extension API, and only works for EC2.
:param name: The name of the security group to edit
:type name: ``str``
:param from_port: The beginning of the port range to open
:type from_port: ``str``
:param to_port: The end of the port range to open
:type to_port: ``str``
:param cidr_ip: The ip to allow traffic for.
:type cidr_ip: ``str``
:param protocol: tcp/udp/icmp
:type protocol: ``str``
:rtype: ``bool``
"""
params = {'Action': 'AuthorizeSecurityGroupIngress',
'GroupName': name,
'IpProtocol': protocol,
'FromPort': str(from_port),
'ToPort': str(to_port),
'CidrIp': cidr_ip}
try:
res = self.connection.request(
self.path, params=params.copy()).object
return self._get_boolean(res)
except Exception:
e = sys.exc_info()[1]
if e.args[0].find('InvalidPermission.Duplicate') == -1:
raise e
def ex_authorize_security_group_ingress(self, id, from_port, to_port,
cidr_ips=None, group_pairs=None,
protocol='tcp'):
"""
Edit a Security Group to allow specific ingress traffic using
CIDR blocks or either a group ID, group name or user ID (account).
:param id: The id of the security group to edit
:type id: ``str``
:param from_port: The beginning of the port range to open
:type from_port: ``int``
:param to_port: The end of the port range to open
:type to_port: ``int``
:param cidr_ips: The list of ip ranges to allow traffic for.
:type cidr_ips: ``list``
:param group_pairs: Source user/group pairs to allow traffic for.
More info can be found at http://goo.gl/stBHJF
EC2 Classic Example: To allow access from any system
associated with the default group on account 1234567890
[{'group_name': 'default', 'user_id': '1234567890'}]
VPC Example: Allow access from any system associated with
security group sg-47ad482e on your own account
[{'group_id': ' sg-47ad482e'}]
:type group_pairs: ``list`` of ``dict``
:param protocol: tcp/udp/icmp
:type protocol: ``str``
:rtype: ``bool``
"""
params = self._get_common_security_group_params(id,
protocol,
from_port,
to_port,
cidr_ips,
group_pairs)
params["Action"] = 'AuthorizeSecurityGroupIngress'
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_authorize_security_group_egress(self, id, from_port, to_port,
cidr_ips, group_pairs=None,
protocol='tcp'):
"""
Edit a Security Group to allow specific egress traffic using
CIDR blocks or either a group ID, group name or user ID (account).
This call is not supported for EC2 classic and only works for VPC
groups.
:param id: The id of the security group to edit
:type id: ``str``
:param from_port: The beginning of the port range to open
:type from_port: ``int``
:param to_port: The end of the port range to open
:type to_port: ``int``
:param cidr_ips: The list of ip ranges to allow traffic for.
:type cidr_ips: ``list``
:param group_pairs: Source user/group pairs to allow traffic for.
More info can be found at http://goo.gl/stBHJF
EC2 Classic Example: To allow access from any system
associated with the default group on account 1234567890
[{'group_name': 'default', 'user_id': '1234567890'}]
VPC Example: Allow access from any system associated with
security group sg-47ad482e on your own account
[{'group_id': ' sg-47ad482e'}]
:type group_pairs: ``list`` of ``dict``
:param protocol: tcp/udp/icmp
:type protocol: ``str``
:rtype: ``bool``
"""
params = self._get_common_security_group_params(id,
protocol,
from_port,
to_port,
cidr_ips,
group_pairs)
params["Action"] = 'AuthorizeSecurityGroupEgress'
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_revoke_security_group_ingress(self, id, from_port, to_port,
cidr_ips=None, group_pairs=None,
protocol='tcp'):
"""
Edit a Security Group to revoke specific ingress traffic using
CIDR blocks or either a group ID, group name or user ID (account).
:param id: The id of the security group to edit
:type id: ``str``
:param from_port: The beginning of the port range to open
:type from_port: ``int``
:param to_port: The end of the port range to open
:type to_port: ``int``
:param cidr_ips: The list of ip ranges to allow traffic for.
:type cidr_ips: ``list``
:param group_pairs: Source user/group pairs to allow traffic for.
More info can be found at http://goo.gl/stBHJF
EC2 Classic Example: To allow access from any system
associated with the default group on account 1234567890
[{'group_name': 'default', 'user_id': '1234567890'}]
VPC Example: Allow access from any system associated with
security group sg-47ad482e on your own account
[{'group_id': ' sg-47ad482e'}]
:type group_pairs: ``list`` of ``dict``
:param protocol: tcp/udp/icmp
:type protocol: ``str``
:rtype: ``bool``
"""
params = self._get_common_security_group_params(id,
protocol,
from_port,
to_port,
cidr_ips,
group_pairs)
params["Action"] = 'RevokeSecurityGroupIngress'
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_revoke_security_group_egress(self, id, from_port, to_port,
cidr_ips=None, group_pairs=None,
protocol='tcp'):
"""
Edit a Security Group to revoke specific egress traffic using
CIDR blocks or either a group ID, group name or user ID (account).
This call is not supported for EC2 classic and only works for
VPC groups.
:param id: The id of the security group to edit
:type id: ``str``
:param from_port: The beginning of the port range to open
:type from_port: ``int``
:param to_port: The end of the port range to open
:type to_port: ``int``
:param cidr_ips: The list of ip ranges to allow traffic for.
:type cidr_ips: ``list``
:param group_pairs: Source user/group pairs to allow traffic for.
More info can be found at http://goo.gl/stBHJF
EC2 Classic Example: To allow access from any system
associated with the default group on account 1234567890
[{'group_name': 'default', 'user_id': '1234567890'}]
VPC Example: Allow access from any system associated with
security group sg-47ad482e on your own account
[{'group_id': ' sg-47ad482e'}]
:type group_pairs: ``list`` of ``dict``
:param protocol: tcp/udp/icmp
:type protocol: ``str``
:rtype: ``bool``
"""
params = self._get_common_security_group_params(id,
protocol,
from_port,
to_port,
cidr_ips,
group_pairs)
params['Action'] = 'RevokeSecurityGroupEgress'
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_authorize_security_group_permissive(self, name):
"""
Edit a Security Group to allow all traffic.
@note: This is a non-standard extension API, and only works for EC2.
:param name: The name of the security group to edit
:type name: ``str``
:rtype: ``list`` of ``str``
"""
results = []
params = {'Action': 'AuthorizeSecurityGroupIngress',
'GroupName': name,
'IpProtocol': 'tcp',
'FromPort': '0',
'ToPort': '65535',
'CidrIp': '0.0.0.0/0'}
try:
results.append(
self.connection.request(self.path, params=params.copy()).object
)
except Exception:
e = sys.exc_info()[1]
if e.args[0].find("InvalidPermission.Duplicate") == -1:
raise e
params['IpProtocol'] = 'udp'
try:
results.append(
self.connection.request(self.path, params=params.copy()).object
)
except Exception:
e = sys.exc_info()[1]
if e.args[0].find("InvalidPermission.Duplicate") == -1:
raise e
params.update({'IpProtocol': 'icmp', 'FromPort': '-1', 'ToPort': '-1'})
try:
results.append(
self.connection.request(self.path, params=params.copy()).object
)
except Exception:
e = sys.exc_info()[1]
if e.args[0].find("InvalidPermission.Duplicate") == -1:
raise e
return results
def ex_list_availability_zones(self, only_available=True):
"""
Return a list of :class:`ExEC2AvailabilityZone` objects for the
current region.
Note: This is an extension method and is only available for EC2
driver.
:keyword only_available: If true, return only availability zones
with state 'available'
:type only_available: ``str``
:rtype: ``list`` of :class:`ExEC2AvailabilityZone`
"""
params = {'Action': 'DescribeAvailabilityZones'}
filters = {'region-name': self.region_name}
if only_available:
filters['state'] = 'available'
params.update(self._build_filters(filters))
result = self.connection.request(self.path,
params=params.copy()).object
availability_zones = []
for element in findall(element=result,
xpath='availabilityZoneInfo/item',
namespace=NAMESPACE):
name = findtext(element=element, xpath='zoneName',
namespace=NAMESPACE)
zone_state = findtext(element=element, xpath='zoneState',
namespace=NAMESPACE)
region_name = findtext(element=element, xpath='regionName',
namespace=NAMESPACE)
availability_zone = ExEC2AvailabilityZone(
name=name,
zone_state=zone_state,
region_name=region_name
)
availability_zones.append(availability_zone)
return availability_zones
def ex_describe_tags(self, resource):
"""
Return a dictionary of tags for a resource (e.g. Node or
StorageVolume).
:param resource: resource which should be used
:type resource: any resource class, such as :class:`Node,`
:class:`StorageVolume,` or :class:NodeImage`
:return: dict Node tags
:rtype: ``dict``
"""
params = {'Action': 'DescribeTags'}
filters = {
'resource-id': resource.id
}
params.update(self._build_filters(filters))
result = self.connection.request(self.path, params=params).object
return self._get_resource_tags(result)
def ex_create_tags(self, resource, tags):
"""
Create tags for a resource (Node or StorageVolume).
:param resource: Resource to be tagged
:type resource: :class:`Node` or :class:`StorageVolume` or
:class:`VolumeSnapshot`
:param tags: A dictionary or other mapping of strings to strings,
associating tag names with tag values.
:type tags: ``dict``
:rtype: ``bool``
"""
if not tags:
return
params = {'Action': 'CreateTags',
'ResourceId.0': resource.id}
for i, key in enumerate(tags):
params['Tag.%d.Key' % i] = key
params['Tag.%d.Value' % i] = tags[key]
res = self.connection.request(self.path,
params=params.copy()).object
return self._get_boolean(res)
def ex_delete_tags(self, resource, tags):
"""
Delete tags from a resource.
:param resource: Resource to be tagged
:type resource: :class:`Node` or :class:`StorageVolume`
:param tags: A dictionary or other mapping of strings to strings,
specifying the tag names and tag values to be deleted.
:type tags: ``dict``
:rtype: ``bool``
"""
if not tags:
return
params = {'Action': 'DeleteTags',
'ResourceId.0': resource.id}
for i, key in enumerate(tags):
params['Tag.%d.Key' % i] = key
params['Tag.%d.Value' % i] = tags[key]
res = self.connection.request(self.path,
params=params.copy()).object
return self._get_boolean(res)
def ex_get_metadata_for_node(self, node):
"""
Return the metadata associated with the node.
:param node: Node instance
:type node: :class:`Node`
:return: A dictionary or other mapping of strings to strings,
associating tag names with tag values.
:rtype tags: ``dict``
"""
return node.extra['tags']
def ex_allocate_address(self, domain='standard'):
"""
Allocate a new Elastic IP address for EC2 classic or VPC
:param domain: The domain to allocate the new address in
(standard/vpc)
:type domain: ``str``
:return: Instance of ElasticIP
:rtype: :class:`ElasticIP`
"""
params = {'Action': 'AllocateAddress'}
if domain == 'vpc':
params['Domain'] = domain
response = self.connection.request(self.path, params=params).object
return self._to_address(response, only_associated=False)
def ex_release_address(self, elastic_ip, domain=None):
"""
Release an Elastic IP address using the IP (EC2-Classic) or
using the allocation ID (VPC)
:param elastic_ip: Elastic IP instance
:type elastic_ip: :class:`ElasticIP`
:param domain: The domain where the IP resides (vpc only)
:type domain: ``str``
:return: True on success, False otherwise.
:rtype: ``bool``
"""
params = {'Action': 'ReleaseAddress'}
if domain is not None and domain != 'vpc':
raise AttributeError('Domain can only be set to vpc')
if domain is None:
params['PublicIp'] = elastic_ip.ip
else:
params['AllocationId'] = elastic_ip.extra['allocation_id']
response = self.connection.request(self.path, params=params).object
return self._get_boolean(response)
def ex_describe_all_addresses(self, only_associated=False):
"""
Return all the Elastic IP addresses for this account
optionally, return only addresses associated with nodes
:param only_associated: If true, return only those addresses
that are associated with an instance.
:type only_associated: ``bool``
:return: List of ElasticIP instances.
:rtype: ``list`` of :class:`ElasticIP`
"""
params = {'Action': 'DescribeAddresses'}
response = self.connection.request(self.path, params=params).object
# We will send our only_associated boolean over to
# shape how the return data is sent back
return self._to_addresses(response, only_associated)
def ex_associate_address_with_node(self, node, elastic_ip, domain=None):
"""
Associate an Elastic IP address with a particular node.
:param node: Node instance
:type node: :class:`Node`
:param elastic_ip: Elastic IP instance
:type elastic_ip: :class:`ElasticIP`
:param domain: The domain where the IP resides (vpc only)
:type domain: ``str``
:return: A string representation of the association ID which is
required for VPC disassociation. EC2/standard
addresses return None
:rtype: ``None`` or ``str``
"""
params = {'Action': 'AssociateAddress', 'InstanceId': node.id}
if domain is not None and domain != 'vpc':
raise AttributeError('Domain can only be set to vpc')
if domain is None:
params.update({'PublicIp': elastic_ip.ip})
else:
params.update({'AllocationId': elastic_ip.extra['allocation_id']})
response = self.connection.request(self.path, params=params).object
association_id = findtext(element=response,
xpath='associationId',
namespace=NAMESPACE)
return association_id
def ex_associate_addresses(self, node, elastic_ip, domain=None):
"""
Note: This method has been deprecated in favor of
the ex_associate_address_with_node method.
"""
return self.ex_associate_address_with_node(node=node,
elastic_ip=elastic_ip,
domain=domain)
def ex_disassociate_address(self, elastic_ip, domain=None):
"""
Disassociate an Elastic IP address using the IP (EC2-Classic)
or the association ID (VPC)
:param elastic_ip: ElasticIP instance
:type elastic_ip: :class:`ElasticIP`
:param domain: The domain where the IP resides (vpc only)
:type domain: ``str``
:return: True on success, False otherwise.
:rtype: ``bool``
"""
params = {'Action': 'DisassociateAddress'}
if domain is not None and domain != 'vpc':
raise AttributeError('Domain can only be set to vpc')
if domain is None:
params['PublicIp'] = elastic_ip.ip
else:
params['AssociationId'] = elastic_ip.extra['association_id']
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_describe_addresses(self, nodes):
"""
Return Elastic IP addresses for all the nodes in the provided list.
:param nodes: List of :class:`Node` instances
:type nodes: ``list`` of :class:`Node`
:return: Dictionary where a key is a node ID and the value is a
list with the Elastic IP addresses associated with
this node.
:rtype: ``dict``
"""
if not nodes:
return {}
params = {'Action': 'DescribeAddresses'}
if len(nodes) == 1:
self._add_instance_filter(params, nodes[0])
result = self.connection.request(self.path, params=params).object
node_instance_ids = [node.id for node in nodes]
nodes_elastic_ip_mappings = {}
# We will set only_associated to True so that we only get back
# IPs which are associated with instances
only_associated = True
for node_id in node_instance_ids:
nodes_elastic_ip_mappings.setdefault(node_id, [])
for addr in self._to_addresses(result,
only_associated):
instance_id = addr.instance_id
if node_id == instance_id:
nodes_elastic_ip_mappings[instance_id].append(
addr.ip)
return nodes_elastic_ip_mappings
def ex_describe_addresses_for_node(self, node):
"""
Return a list of Elastic IP addresses associated with this node.
:param node: Node instance
:type node: :class:`Node`
:return: list Elastic IP addresses attached to this node.
:rtype: ``list`` of ``str``
"""
node_elastic_ips = self.ex_describe_addresses([node])
return node_elastic_ips[node.id]
# Network interface management methods
def ex_list_network_interfaces(self):
"""
Return all network interfaces
:return: List of EC2NetworkInterface instances
:rtype: ``list`` of :class `EC2NetworkInterface`
"""
params = {'Action': 'DescribeNetworkInterfaces'}
return self._to_interfaces(
self.connection.request(self.path, params=params).object
)
def ex_create_network_interface(self, subnet, name=None,
description=None,
private_ip_address=None):
"""
Create a network interface within a VPC subnet.
:param subnet: EC2NetworkSubnet instance
:type subnet: :class:`EC2NetworkSubnet`
:param name: Optional name of the interface
:type name: ``str``
:param description: Optional description of the network interface
:type description: ``str``
:param private_ip_address: Optional address to assign as the
primary private IP address of the
interface. If one is not provided then
Amazon will automatically auto-assign
an available IP. EC2 allows assignment
of multiple IPs, but this will be
the primary.
:type private_ip_address: ``str``
:return: EC2NetworkInterface instance
:rtype: :class `EC2NetworkInterface`
"""
params = {'Action': 'CreateNetworkInterface',
'SubnetId': subnet.id}
if description:
params['Description'] = description
if private_ip_address:
params['PrivateIpAddress'] = private_ip_address
response = self.connection.request(self.path, params=params).object
element = response.findall(fixxpath(xpath='networkInterface',
namespace=NAMESPACE))[0]
interface = self._to_interface(element, name)
if name and self.ex_create_tags(interface, {'Name': name}):
interface.extra['tags']['Name'] = name
return interface
def ex_delete_network_interface(self, network_interface):
"""
Deletes a network interface.
:param network_interface: EC2NetworkInterface instance
:type network_interface: :class:`EC2NetworkInterface`
:rtype: ``bool``
"""
params = {'Action': 'DeleteNetworkInterface',
'NetworkInterfaceId': network_interface.id}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_attach_network_interface_to_node(self, network_interface,
node, device_index):
"""
Attach a network interface to an instance.
:param network_interface: EC2NetworkInterface instance
:type network_interface: :class:`EC2NetworkInterface`
:param node: Node instance
:type node: :class:`Node`
:param device_index: The interface device index
:type device_index: ``int``
:return: String representation of the attachment id.
This is required to detach the interface.
:rtype: ``str``
"""
params = {'Action': 'AttachNetworkInterface',
'NetworkInterfaceId': network_interface.id,
'InstanceId': node.id,
'DeviceIndex': device_index}
response = self.connection.request(self.path, params=params).object
attachment_id = findattr(element=response, xpath='attachmentId',
namespace=NAMESPACE)
return attachment_id
def ex_detach_network_interface(self, attachment_id, force=False):
"""
Detach a network interface from an instance.
:param attachment_id: The attachment ID associated with the
interface
:type attachment_id: ``str``
:param force: Forces the detachment.
:type force: ``bool``
:return: ``True`` on successful detachment, ``False`` otherwise.
:rtype: ``bool``
"""
params = {'Action': 'DetachNetworkInterface',
'AttachmentId': attachment_id}
if force:
params['Force'] = True
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_modify_instance_attribute(self, node, attributes):
"""
Modify node attributes.
A list of valid attributes can be found at http://goo.gl/gxcj8
:param node: Node instance
:type node: :class:`Node`
:param attributes: Dictionary with node attributes
:type attributes: ``dict``
:return: True on success, False otherwise.
:rtype: ``bool``
"""
attributes = attributes or {}
attributes.update({'InstanceId': node.id})
params = {'Action': 'ModifyInstanceAttribute'}
params.update(attributes)
res = self.connection.request(self.path,
params=params.copy()).object
return self._get_boolean(res)
def ex_modify_image_attribute(self, image, attributes):
"""
Modify image attributes.
:param image: NodeImage instance
:type image: :class:`NodeImage`
:param attributes: Dictionary with node attributes
:type attributes: ``dict``
:return: True on success, False otherwise.
:rtype: ``bool``
"""
attributes = attributes or {}
attributes.update({'ImageId': image.id})
params = {'Action': 'ModifyImageAttribute'}
params.update(attributes)
res = self.connection.request(self.path,
params=params.copy()).object
return self._get_boolean(res)
def ex_change_node_size(self, node, new_size):
"""
Change the node size.
Note: Node must be turned of before changing the size.
:param node: Node instance
:type node: :class:`Node`
:param new_size: NodeSize intance
:type new_size: :class:`NodeSize`
:return: True on success, False otherwise.
:rtype: ``bool``
"""
if 'instancetype' in node.extra:
current_instance_type = node.extra['instancetype']
if current_instance_type == new_size.id:
raise ValueError('New instance size is the same as' +
'the current one')
attributes = {'InstanceType.Value': new_size.id}
return self.ex_modify_instance_attribute(node, attributes)
def ex_start_node(self, node):
"""
Start the node by passing in the node object, does not work with
instance store backed instances
:param node: Node which should be used
:type node: :class:`Node`
:rtype: ``bool``
"""
params = {'Action': 'StartInstances'}
params.update(self._pathlist('InstanceId', [node.id]))
res = self.connection.request(self.path, params=params).object
return self._get_state_boolean(res)
def ex_stop_node(self, node):
"""
Stop the node by passing in the node object, does not work with
instance store backed instances
:param node: Node which should be used
:type node: :class:`Node`
:rtype: ``bool``
"""
params = {'Action': 'StopInstances'}
params.update(self._pathlist('InstanceId', [node.id]))
res = self.connection.request(self.path, params=params).object
return self._get_state_boolean(res)
def ex_get_console_output(self, node):
"""
Get console output for the node.
:param node: Node which should be used
:type node: :class:`Node`
:return: Dictionary with the following keys:
- instance_id (``str``)
- timestamp (``datetime.datetime``) - ts of the last output
- output (``str``) - console output
:rtype: ``dict``
"""
params = {
'Action': 'GetConsoleOutput',
'InstanceId': node.id
}
response = self.connection.request(self.path, params=params).object
timestamp = findattr(element=response,
xpath='timestamp',
namespace=NAMESPACE)
encoded_string = findattr(element=response,
xpath='output',
namespace=NAMESPACE)
timestamp = parse_date(timestamp)
if encoded_string:
output = base64.b64decode(b(encoded_string)).decode('utf-8')
else:
# No console output
output = None
return {'instance_id': node.id,
'timestamp': timestamp,
'output': output}
def ex_list_reserved_nodes(self):
"""
List all reserved instances/nodes which can be purchased from Amazon
for one or three year terms. Reservations are made at a region level
and reduce the hourly charge for instances.
More information can be found at http://goo.gl/ulXCC7.
:rtype: ``list`` of :class:`.EC2ReservedNode`
"""
params = {'Action': 'DescribeReservedInstances'}
response = self.connection.request(self.path, params=params).object
return self._to_reserved_nodes(response, 'reservedInstancesSet/item')
# Account specific methods
def ex_get_limits(self):
"""
Retrieve account resource limits.
:rtype: ``dict``
"""
attributes = ['max-instances', 'max-elastic-ips',
'vpc-max-elastic-ips']
params = {}
params['Action'] = 'DescribeAccountAttributes'
for index, attribute in enumerate(attributes):
params['AttributeName.%s' % (index)] = attribute
response = self.connection.request(self.path, params=params)
data = response.object
elems = data.findall(fixxpath(xpath='accountAttributeSet/item',
namespace=NAMESPACE))
result = {'resource': {}}
for elem in elems:
name = findtext(element=elem, xpath='attributeName',
namespace=NAMESPACE)
value = findtext(element=elem,
xpath='attributeValueSet/item/attributeValue',
namespace=NAMESPACE)
result['resource'][name] = int(value)
return result
# Deprecated extension methods
def ex_list_keypairs(self):
"""
Lists all the keypair names and fingerprints.
:rtype: ``list`` of ``dict``
"""
warnings.warn('This method has been deprecated in favor of '
'list_key_pairs method')
key_pairs = self.list_key_pairs()
result = []
for key_pair in key_pairs:
item = {
'keyName': key_pair.name,
'keyFingerprint': key_pair.fingerprint,
}
result.append(item)
return result
def ex_describe_all_keypairs(self):
"""
Return names for all the available key pairs.
@note: This is a non-standard extension API, and only works for EC2.
:rtype: ``list`` of ``str``
"""
names = [key_pair.name for key_pair in self.list_key_pairs()]
return names
def ex_describe_keypairs(self, name):
"""
Here for backward compatibility.
"""
return self.ex_describe_keypair(name=name)
def ex_describe_keypair(self, name):
"""
Describes a keypair by name.
@note: This is a non-standard extension API, and only works for EC2.
:param name: The name of the keypair to describe.
:type name: ``str``
:rtype: ``dict``
"""
params = {
'Action': 'DescribeKeyPairs',
'KeyName.1': name
}
response = self.connection.request(self.path, params=params).object
key_name = findattr(element=response, xpath='keySet/item/keyName',
namespace=NAMESPACE)
fingerprint = findattr(element=response,
xpath='keySet/item/keyFingerprint',
namespace=NAMESPACE).strip()
return {
'keyName': key_name,
'keyFingerprint': fingerprint
}
def ex_create_keypair(self, name):
"""
Creates a new keypair
@note: This is a non-standard extension API, and only works for EC2.
:param name: The name of the keypair to Create. This must be
unique, otherwise an InvalidKeyPair.Duplicate exception is raised.
:type name: ``str``
:rtype: ``dict``
"""
warnings.warn('This method has been deprecated in favor of '
'create_key_pair method')
key_pair = self.create_key_pair(name=name)
result = {
'keyMaterial': key_pair.private_key,
'keyFingerprint': key_pair.fingerprint
}
return result
def ex_delete_keypair(self, keypair):
"""
Delete a key pair by name.
@note: This is a non-standard extension API, and only works with EC2.
:param keypair: The name of the keypair to delete.
:type keypair: ``str``
:rtype: ``bool``
"""
warnings.warn('This method has been deprecated in favor of '
'delete_key_pair method')
keypair = KeyPair(name=keypair, public_key=None, fingerprint=None,
driver=self)
return self.delete_key_pair(keypair)
def ex_import_keypair_from_string(self, name, key_material):
"""
imports a new public key where the public key is passed in as a string
@note: This is a non-standard extension API, and only works for EC2.
:param name: The name of the public key to import. This must be
unique, otherwise an InvalidKeyPair.Duplicate exception is raised.
:type name: ``str``
:param key_material: The contents of a public key file.
:type key_material: ``str``
:rtype: ``dict``
"""
warnings.warn('This method has been deprecated in favor of '
'import_key_pair_from_string method')
key_pair = self.import_key_pair_from_string(name=name,
key_material=key_material)
result = {
'keyName': key_pair.name,
'keyFingerprint': key_pair.fingerprint
}
return result
def ex_import_keypair(self, name, keyfile):
"""
imports a new public key where the public key is passed via a filename
@note: This is a non-standard extension API, and only works for EC2.
:param name: The name of the public key to import. This must be
unique, otherwise an InvalidKeyPair.Duplicate exception is raised.
:type name: ``str``
:param keyfile: The filename with path of the public key to import.
:type keyfile: ``str``
:rtype: ``dict``
"""
warnings.warn('This method has been deprecated in favor of '
'import_key_pair_from_file method')
key_pair = self.import_key_pair_from_file(name=name,
key_file_path=keyfile)
result = {
'keyName': key_pair.name,
'keyFingerprint': key_pair.fingerprint
}
return result
def ex_find_or_import_keypair_by_key_material(self, pubkey):
"""
Given a public key, look it up in the EC2 KeyPair database. If it
exists, return any information we have about it. Otherwise, create it.
Keys that are created are named based on their comment and fingerprint.
:rtype: ``dict``
"""
key_fingerprint = get_pubkey_ssh2_fingerprint(pubkey)
key_comment = get_pubkey_comment(pubkey, default='unnamed')
key_name = '%s-%s' % (key_comment, key_fingerprint)
key_pairs = self.list_key_pairs()
key_pairs = [key_pair for key_pair in key_pairs if
key_pair.fingerprint == key_fingerprint]
if len(key_pairs) >= 1:
key_pair = key_pairs[0]
result = {
'keyName': key_pair.name,
'keyFingerprint': key_pair.fingerprint
}
else:
result = self.ex_import_keypair_from_string(key_name, pubkey)
return result
def ex_list_internet_gateways(self, gateway_ids=None, filters=None):
"""
Describes available Internet gateways and whether or not they are
attached to a VPC. These are required for VPC nodes to communicate
over the Internet.
:param gateway_ids: Return only intenet gateways matching the
provided internet gateway IDs. If not
specified, a list of all the internet
gateways in the corresponding region is
returned.
:type gateway_ids: ``list``
:param filters: The filters so that the response includes
information for only certain gateways.
:type filters: ``dict``
:rtype: ``list`` of :class:`.VPCInternetGateway`
"""
params = {'Action': 'DescribeInternetGateways'}
if gateway_ids:
params.update(self._pathlist('InternetGatewayId', gateway_ids))
if filters:
params.update(self._build_filters(filters))
response = self.connection.request(self.path, params=params).object
return self._to_internet_gateways(response, 'internetGatewaySet/item')
def ex_create_internet_gateway(self, name=None):
"""
Delete a VPC Internet gateway
:rtype: ``bool``
"""
params = {'Action': 'CreateInternetGateway'}
resp = self.connection.request(self.path, params=params).object
element = resp.findall(fixxpath(xpath='internetGateway',
namespace=NAMESPACE))
gateway = self._to_internet_gateway(element[0], name)
if name and self.ex_create_tags(gateway, {'Name': name}):
gateway.extra['tags']['Name'] = name
return gateway
def ex_delete_internet_gateway(self, gateway):
"""
Delete a VPC Internet gateway
:param gateway: The gateway to delete
:type gateway: :class:`.VPCInternetGateway`
:rtype: ``bool``
"""
params = {'Action': 'DeleteInternetGateway',
'InternetGatewayId': gateway.id}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_attach_internet_gateway(self, gateway, network):
"""
Attach an Internet gateway to a VPC
:param gateway: The gateway to attach
:type gateway: :class:`.VPCInternetGateway`
:param network: The VPC network to attach to
:type network: :class:`.EC2Network`
:rtype: ``bool``
"""
params = {'Action': 'AttachInternetGateway',
'InternetGatewayId': gateway.id,
'VpcId': network.id}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_detach_internet_gateway(self, gateway, network):
"""
Detach an Internet gateway from a VPC
:param gateway: The gateway to detach
:type gateway: :class:`.VPCInternetGateway`
:param network: The VPC network to detach from
:type network: :class:`.EC2Network`
:rtype: ``bool``
"""
params = {'Action': 'DetachInternetGateway',
'InternetGatewayId': gateway.id,
'VpcId': network.id}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_list_route_tables(self, route_table_ids=None, filters=None):
"""
Describes one or more of a VPC's route tables.
These are used to determine where network traffic is directed.
:param route_table_ids: Return only route tables matching the
provided route table IDs. If not specified,
a list of all the route tables in the
corresponding region is returned.
:type route_table_ids: ``list``
:param filters: The filters so that the response includes
information for only certain route tables.
:type filters: ``dict``
:rtype: ``list`` of :class:`.EC2RouteTable`
"""
params = {'Action': 'DescribeRouteTables'}
if route_table_ids:
params.update(self._pathlist('RouteTableId', route_table_ids))
if filters:
params.update(self._build_filters(filters))
response = self.connection.request(self.path, params=params)
return self._to_route_tables(response.object)
def ex_create_route_table(self, network, name=None):
"""
Create a route table within a VPC.
:param vpc_id: The VPC that the subnet should be created in.
:type vpc_id: :class:`.EC2Network`
:rtype: :class: `.EC2RouteTable`
"""
params = {'Action': 'CreateRouteTable',
'VpcId': network.id}
response = self.connection.request(self.path, params=params).object
element = response.findall(fixxpath(xpath='routeTable',
namespace=NAMESPACE))[0]
route_table = self._to_route_table(element, name=name)
if name and self.ex_create_tags(route_table, {'Name': name}):
route_table.extra['tags']['Name'] = name
return route_table
def ex_delete_route_table(self, route_table):
"""
Deletes a VPC route table.
:param route_table: The route table to delete.
:type route_table: :class:`.EC2RouteTable`
:rtype: ``bool``
"""
params = {'Action': 'DeleteRouteTable',
'RouteTableId': route_table.id}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_associate_route_table(self, route_table, subnet):
"""
Associates a route table with a subnet within a VPC.
Note: A route table can be associated with multiple subnets.
:param route_table: The route table to associate.
:type route_table: :class:`.EC2RouteTable`
:param subnet: The subnet to associate with.
:type subnet: :class:`.EC2Subnet`
:return: Route table association ID.
:rtype: ``str``
"""
params = {'Action': 'AssociateRouteTable',
'RouteTableId': route_table.id,
'SubnetId': subnet.id}
result = self.connection.request(self.path, params=params).object
association_id = findtext(element=result,
xpath='associationId',
namespace=NAMESPACE)
return association_id
def ex_dissociate_route_table(self, subnet_association):
"""
Dissociates a subnet from a route table.
:param subnet_association: The subnet association object or
subnet association ID.
:type subnet_association: :class:`.EC2SubnetAssociation` or
``str``
:rtype: ``bool``
"""
if isinstance(subnet_association, EC2SubnetAssociation):
subnet_association_id = subnet_association.id
else:
subnet_association_id = subnet_association
params = {'Action': 'DisassociateRouteTable',
'AssociationId': subnet_association_id}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_replace_route_table_association(self, subnet_association,
route_table):
"""
Changes the route table associated with a given subnet in a VPC.
Note: This method can be used to change which table is the main route
table in the VPC (Specify the main route table's association ID
and the route table to be the new main route table).
:param subnet_association: The subnet association object or
subnet association ID.
:type subnet_association: :class:`.EC2SubnetAssociation` or
``str``
:param route_table: The new route table to associate.
:type route_table: :class:`.EC2RouteTable`
:return: New route table association ID.
:rtype: ``str``
"""
if isinstance(subnet_association, EC2SubnetAssociation):
subnet_association_id = subnet_association.id
else:
subnet_association_id = subnet_association
params = {'Action': 'ReplaceRouteTableAssociation',
'AssociationId': subnet_association_id,
'RouteTableId': route_table.id}
result = self.connection.request(self.path, params=params).object
new_association_id = findtext(element=result,
xpath='newAssociationId',
namespace=NAMESPACE)
return new_association_id
def ex_create_route(self, route_table, cidr,
internet_gateway=None, node=None,
network_interface=None, vpc_peering_connection=None):
"""
Creates a route entry in the route table.
:param route_table: The route table to create the route in.
:type route_table: :class:`.EC2RouteTable`
:param cidr: The CIDR block used for the destination match.
:type cidr: ``str``
:param internet_gateway: The internet gateway to route
traffic through.
:type internet_gateway: :class:`.VPCInternetGateway`
:param node: The NAT instance to route traffic through.
:type node: :class:`Node`
:param network_interface: The network interface of the node
to route traffic through.
:type network_interface: :class:`.EC2NetworkInterface`
:param vpc_peering_connection: The VPC peering connection.
:type vpc_peering_connection: :class:`.VPCPeeringConnection`
:rtype: ``bool``
Note: You must specify one of the following: internet_gateway,
node, network_interface, vpc_peering_connection.
"""
params = {'Action': 'CreateRoute',
'RouteTableId': route_table.id,
'DestinationCidrBlock': cidr}
if internet_gateway:
params['GatewayId'] = internet_gateway.id
if node:
params['InstanceId'] = node.id
if network_interface:
params['NetworkInterfaceId'] = network_interface.id
if vpc_peering_connection:
params['VpcPeeringConnectionId'] = vpc_peering_connection.id
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_delete_route(self, route_table, cidr):
"""
Deletes a route entry from the route table.
:param route_table: The route table to delete the route from.
:type route_table: :class:`.EC2RouteTable`
:param cidr: The CIDR block used for the destination match.
:type cidr: ``str``
:rtype: ``bool``
"""
params = {'Action': 'DeleteRoute',
'RouteTableId': route_table.id,
'DestinationCidrBlock': cidr}
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def ex_replace_route(self, route_table, cidr,
internet_gateway=None, node=None,
network_interface=None, vpc_peering_connection=None):
"""
Replaces an existing route entry within a route table in a VPC.
:param route_table: The route table to replace the route in.
:type route_table: :class:`.EC2RouteTable`
:param cidr: The CIDR block used for the destination match.
:type cidr: ``str``
:param internet_gateway: The new internet gateway to route
traffic through.
:type internet_gateway: :class:`.VPCInternetGateway`
:param node: The new NAT instance to route traffic through.
:type node: :class:`Node`
:param network_interface: The new network interface of the node
to route traffic through.
:type network_interface: :class:`.EC2NetworkInterface`
:param vpc_peering_connection: The new VPC peering connection.
:type vpc_peering_connection: :class:`.VPCPeeringConnection`
:rtype: ``bool``
Note: You must specify one of the following: internet_gateway,
node, network_interface, vpc_peering_connection.
"""
params = {'Action': 'ReplaceRoute',
'RouteTableId': route_table.id,
'DestinationCidrBlock': cidr}
if internet_gateway:
params['GatewayId'] = internet_gateway.id
if node:
params['InstanceId'] = node.id
if network_interface:
params['NetworkInterfaceId'] = network_interface.id
if vpc_peering_connection:
params['VpcPeeringConnectionId'] = vpc_peering_connection.id
res = self.connection.request(self.path, params=params).object
return self._get_boolean(res)
def _ex_connection_class_kwargs(self):
kwargs = super(BaseEC2NodeDriver, self)._ex_connection_class_kwargs()
kwargs['signature_version'] = self.signature_version
return kwargs
def _to_nodes(self, object, xpath):
return [self._to_node(el)
for el in object.findall(fixxpath(xpath=xpath,
namespace=NAMESPACE))]
def _to_node(self, element):
try:
state = self.NODE_STATE_MAP[findattr(element=element,
xpath="instanceState/name",
namespace=NAMESPACE)
]
except KeyError:
state = NodeState.UNKNOWN
instance_id = findtext(element=element, xpath='instanceId',
namespace=NAMESPACE)
public_ip = findtext(element=element, xpath='ipAddress',
namespace=NAMESPACE)
public_ips = [public_ip] if public_ip else []
private_ip = findtext(element=element, xpath='privateIpAddress',
namespace=NAMESPACE)
private_ips = [private_ip] if private_ip else []
product_codes = []
for p in findall(element=element,
xpath="productCodesSet/item/productCode",
namespace=NAMESPACE):
product_codes.append(p)
# Get our tags
tags = self._get_resource_tags(element)
name = tags.get('Name', instance_id)
# Get our extra dictionary
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['node'])
# Add additional properties to our extra dictionary
extra['block_device_mapping'] = self._to_device_mappings(element)
extra['groups'] = self._get_security_groups(element)
extra['network_interfaces'] = self._to_interfaces(element)
extra['product_codes'] = product_codes
extra['tags'] = tags
return Node(id=instance_id, name=name, state=state,
public_ips=public_ips, private_ips=private_ips,
driver=self.connection.driver, extra=extra)
def _to_images(self, object):
return [self._to_image(el) for el in object.findall(
fixxpath(xpath='imagesSet/item', namespace=NAMESPACE))
]
def _to_image(self, element):
id = findtext(element=element, xpath='imageId', namespace=NAMESPACE)
name = findtext(element=element, xpath='name', namespace=NAMESPACE)
# Build block device mapping
block_device_mapping = self._to_device_mappings(element)
# Get our tags
tags = self._get_resource_tags(element)
# Get our extra dictionary
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['image'])
# Add our tags and block device mapping
extra['tags'] = tags
extra['block_device_mapping'] = block_device_mapping
return NodeImage(id=id, name=name, driver=self, extra=extra)
def _to_volume(self, element, name=None):
"""
Parse the XML element and return a StorageVolume object.
:param name: An optional name for the volume. If not provided
then either tag with a key "Name" or volume ID
will be used (which ever is available first in that
order).
:type name: ``str``
:rtype: :class:`StorageVolume`
"""
volId = findtext(element=element, xpath='volumeId',
namespace=NAMESPACE)
size = findtext(element=element, xpath='size', namespace=NAMESPACE)
raw_state = findtext(element=element, xpath='status',
namespace=NAMESPACE)
state = self.VOLUME_STATE_MAP.get(raw_state,
StorageVolumeState.UNKNOWN)
# Get our tags
tags = self._get_resource_tags(element)
# If name was not passed into the method then
# fall back then use the volume id
name = name if name else tags.get('Name', volId)
# Get our extra dictionary
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['volume'])
extra['tags'] = tags
return StorageVolume(id=volId,
name=name,
size=int(size),
driver=self,
state=state,
extra=extra)
def _to_snapshots(self, response):
return [self._to_snapshot(el) for el in response.findall(
fixxpath(xpath='snapshotSet/item', namespace=NAMESPACE))
]
def _to_snapshot(self, element, name=None):
snapId = findtext(element=element, xpath='snapshotId',
namespace=NAMESPACE)
size = findtext(element=element, xpath='volumeSize',
namespace=NAMESPACE)
created = parse_date(findtext(element=element, xpath='startTime',
namespace=NAMESPACE))
# Get our tags
tags = self._get_resource_tags(element)
# If name was not passed into the method then
# fall back then use the snapshot id
name = name if name else tags.get('Name', snapId)
# Get our extra dictionary
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['snapshot'])
# Add tags and name to the extra dict
extra['tags'] = tags
extra['name'] = name
return VolumeSnapshot(snapId, size=int(size),
driver=self, extra=extra, created=created)
def _to_key_pairs(self, elems):
key_pairs = [self._to_key_pair(elem=elem) for elem in elems]
return key_pairs
def _to_key_pair(self, elem):
name = findtext(element=elem, xpath='keyName', namespace=NAMESPACE)
fingerprint = findtext(element=elem, xpath='keyFingerprint',
namespace=NAMESPACE).strip()
private_key = findtext(element=elem, xpath='keyMaterial',
namespace=NAMESPACE)
key_pair = KeyPair(name=name,
public_key=None,
fingerprint=fingerprint,
private_key=private_key,
driver=self)
return key_pair
def _to_security_groups(self, response):
return [self._to_security_group(el) for el in response.findall(
fixxpath(xpath='securityGroupInfo/item', namespace=NAMESPACE))
]
def _to_security_group(self, element):
# security group id
sg_id = findtext(element=element,
xpath='groupId',
namespace=NAMESPACE)
# security group name
name = findtext(element=element,
xpath='groupName',
namespace=NAMESPACE)
# Get our tags
tags = self._get_resource_tags(element)
# Get our extra dictionary
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['security_group'])
# Add tags to the extra dict
extra['tags'] = tags
# Get ingress rules
ingress_rules = self._to_security_group_rules(
element, 'ipPermissions/item'
)
# Get egress rules
egress_rules = self._to_security_group_rules(
element, 'ipPermissionsEgress/item'
)
return EC2SecurityGroup(sg_id, name, ingress_rules,
egress_rules, extra=extra)
def _to_security_group_rules(self, element, xpath):
return [self._to_security_group_rule(el) for el in element.findall(
fixxpath(xpath=xpath, namespace=NAMESPACE))
]
def _to_security_group_rule(self, element):
"""
Parse the XML element and return a SecurityGroup object.
:rtype: :class:`EC2SecurityGroup`
"""
rule = {}
rule['protocol'] = findtext(element=element,
xpath='ipProtocol',
namespace=NAMESPACE)
rule['from_port'] = findtext(element=element,
xpath='fromPort',
namespace=NAMESPACE)
rule['to_port'] = findtext(element=element,
xpath='toPort',
namespace=NAMESPACE)
# get security groups
elements = element.findall(fixxpath(
xpath='groups/item',
namespace=NAMESPACE
))
rule['group_pairs'] = []
for element in elements:
item = {
'user_id': findtext(
element=element,
xpath='userId',
namespace=NAMESPACE),
'group_id': findtext(
element=element,
xpath='groupId',
namespace=NAMESPACE),
'group_name': findtext(
element=element,
xpath='groupName',
namespace=NAMESPACE)
}
rule['group_pairs'].append(item)
# get ip ranges
elements = element.findall(fixxpath(
xpath='ipRanges/item',
namespace=NAMESPACE
))
rule['cidr_ips'] = [
findtext(
element=element,
xpath='cidrIp',
namespace=NAMESPACE
) for element in elements]
return rule
def _to_networks(self, response):
return [self._to_network(el) for el in response.findall(
fixxpath(xpath='vpcSet/item', namespace=NAMESPACE))
]
def _to_network(self, element, name=None):
# Get the network id
vpc_id = findtext(element=element,
xpath='vpcId',
namespace=NAMESPACE)
# Get our tags
tags = self._get_resource_tags(element)
# Set our name if the Name key/value if available
# If we don't get anything back then use the vpc_id
name = name if name else tags.get('Name', vpc_id)
cidr_block = findtext(element=element,
xpath='cidrBlock',
namespace=NAMESPACE)
# Get our extra dictionary
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['network'])
# Add tags to the extra dict
extra['tags'] = tags
return EC2Network(vpc_id, name, cidr_block, extra=extra)
def _to_addresses(self, response, only_associated):
"""
Builds a list of dictionaries containing elastic IP properties.
:param only_associated: If true, return only those addresses
that are associated with an instance.
If false, return all addresses.
:type only_associated: ``bool``
:rtype: ``list`` of :class:`ElasticIP`
"""
addresses = []
for el in response.findall(fixxpath(xpath='addressesSet/item',
namespace=NAMESPACE)):
addr = self._to_address(el, only_associated)
if addr is not None:
addresses.append(addr)
return addresses
def _to_address(self, element, only_associated):
instance_id = findtext(element=element, xpath='instanceId',
namespace=NAMESPACE)
public_ip = findtext(element=element,
xpath='publicIp',
namespace=NAMESPACE)
domain = findtext(element=element,
xpath='domain',
namespace=NAMESPACE)
# Build our extra dict
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['elastic_ip'])
# Return NoneType if only associated IPs are requested
if only_associated and not instance_id:
return None
return ElasticIP(public_ip, domain, instance_id, extra=extra)
def _to_placement_groups(self, response):
return [self._to_placement_group(el)
for el in response.findall(
fixxpath(xpath='placementGroupSet/item',
namespace=NAMESPACE))]
def _to_placement_group(self, element):
name = findtext(element=element,
xpath='groupName',
namespace=NAMESPACE)
state = findtext(element=element,
xpath='state',
namespace=NAMESPACE)
strategy = findtext(element=element,
xpath='strategy',
namespace=NAMESPACE)
return EC2PlacementGroup(name, state, strategy)
def _to_subnets(self, response):
return [self._to_subnet(el) for el in response.findall(
fixxpath(xpath='subnetSet/item', namespace=NAMESPACE))
]
def _to_subnet(self, element, name=None):
# Get the subnet ID
subnet_id = findtext(element=element,
xpath='subnetId',
namespace=NAMESPACE)
# Get our tags
tags = self._get_resource_tags(element)
# If we don't get anything back then use the subnet_id
name = name if name else tags.get('Name', subnet_id)
state = findtext(element=element,
xpath='state',
namespace=NAMESPACE)
# Get our extra dictionary
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['subnet'])
# Also include our tags
extra['tags'] = tags
return EC2NetworkSubnet(subnet_id, name, state, extra=extra)
def _to_interfaces(self, response):
return [self._to_interface(el) for el in response.findall(
fixxpath(xpath='networkInterfaceSet/item', namespace=NAMESPACE))
]
def _to_interface(self, element, name=None):
"""
Parse the XML element and return an EC2NetworkInterface object.
:param name: An optional name for the interface. If not provided
then either tag with a key "Name" or the interface ID
will be used (whichever is available first in that
order).
:type name: ``str``
:rtype: :class: `EC2NetworkInterface`
"""
interface_id = findtext(element=element,
xpath='networkInterfaceId',
namespace=NAMESPACE)
state = findtext(element=element,
xpath='status',
namespace=NAMESPACE)
# Get tags
tags = self._get_resource_tags(element)
name = name if name else tags.get('Name', interface_id)
# Build security groups
groups = self._get_security_groups(element)
# Build private IPs
priv_ips = []
for item in findall(element=element,
xpath='privateIpAddressesSet/item',
namespace=NAMESPACE):
priv_ips.append({'private_ip': findtext(element=item,
xpath='privateIpAddress',
namespace=NAMESPACE),
'private_dns': findtext(element=item,
xpath='privateDnsName',
namespace=NAMESPACE),
'primary': findtext(element=item,
xpath='primary',
namespace=NAMESPACE)})
# Build our attachment dictionary which we will add into extra later
attributes_map = \
RESOURCE_EXTRA_ATTRIBUTES_MAP['network_interface_attachment']
attachment = self._get_extra_dict(element, attributes_map)
# Build our extra dict
attributes_map = RESOURCE_EXTRA_ATTRIBUTES_MAP['network_interface']
extra = self._get_extra_dict(element, attributes_map)
# Include our previously built items as well
extra['tags'] = tags
extra['attachment'] = attachment
extra['private_ips'] = priv_ips
extra['groups'] = groups
return EC2NetworkInterface(interface_id, name, state, extra=extra)
def _to_reserved_nodes(self, object, xpath):
return [self._to_reserved_node(el)
for el in object.findall(fixxpath(xpath=xpath,
namespace=NAMESPACE))]
def _to_reserved_node(self, element):
"""
Build an EC2ReservedNode object using the reserved instance properties.
Information on these properties can be found at http://goo.gl/ulXCC7.
"""
# Get our extra dictionary
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['reserved_node'])
try:
size = [size for size in self.list_sizes() if
size.id == extra['instance_type']][0]
except IndexError:
size = None
return EC2ReservedNode(id=findtext(element=element,
xpath='reservedInstancesId',
namespace=NAMESPACE),
state=findattr(element=element,
xpath='state',
namespace=NAMESPACE),
driver=self,
size=size,
extra=extra)
def _to_device_mappings(self, object):
return [self._to_device_mapping(el) for el in object.findall(
fixxpath(xpath='blockDeviceMapping/item', namespace=NAMESPACE))
]
def _to_device_mapping(self, element):
"""
Parse the XML element and return a dictionary of device properties.
Additional information can be found at http://goo.gl/GjWYBf.
@note: EBS volumes do not have a virtual name. Only ephemeral
disks use this property.
:rtype: ``dict``
"""
mapping = {}
mapping['device_name'] = findattr(element=element,
xpath='deviceName',
namespace=NAMESPACE)
mapping['virtual_name'] = findattr(element=element,
xpath='virtualName',
namespace=NAMESPACE)
# If virtual name does not exist then this is an EBS volume.
# Build the EBS dictionary leveraging the _get_extra_dict method.
if mapping['virtual_name'] is None:
mapping['ebs'] = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['ebs_volume'])
return mapping
def _to_internet_gateways(self, object, xpath):
return [self._to_internet_gateway(el)
for el in object.findall(fixxpath(xpath=xpath,
namespace=NAMESPACE))]
def _to_internet_gateway(self, element, name=None):
id = findtext(element=element,
xpath='internetGatewayId',
namespace=NAMESPACE)
vpc_id = findtext(element=element,
xpath='attachmentSet/item/vpcId',
namespace=NAMESPACE)
state = findtext(element=element,
xpath='attachmentSet/item/state',
namespace=NAMESPACE)
# If there's no attachment state, let's
# set it to available
if not state:
state = 'available'
# Get our tags
tags = self._get_resource_tags(element)
# If name was not passed into the method then
# fall back then use the gateway id
name = name if name else tags.get('Name', id)
return VPCInternetGateway(id=id, name=name, vpc_id=vpc_id,
state=state, driver=self.connection.driver,
extra={'tags': tags})
def _to_route_tables(self, response):
return [self._to_route_table(el) for el in response.findall(
fixxpath(xpath='routeTableSet/item', namespace=NAMESPACE))
]
def _to_route_table(self, element, name=None):
# route table id
route_table_id = findtext(element=element,
xpath='routeTableId',
namespace=NAMESPACE)
# Get our tags
tags = self._get_resource_tags(element)
# Get our extra dictionary
extra = self._get_extra_dict(
element, RESOURCE_EXTRA_ATTRIBUTES_MAP['route_table'])
# Add tags to the extra dict
extra['tags'] = tags
# Get routes
routes = self._to_routes(element, 'routeSet/item')
# Get subnet associations
subnet_associations = self._to_subnet_associations(
element, 'associationSet/item')
# Get propagating routes virtual private gateways (VGW) IDs
propagating_gateway_ids = []
for el in element.findall(fixxpath(xpath='propagatingVgwSet/item',
namespace=NAMESPACE)):
propagating_gateway_ids.append(findtext(element=el,
xpath='gatewayId',
namespace=NAMESPACE))
name = name if name else tags.get('Name', id)
return EC2RouteTable(route_table_id, name, routes, subnet_associations,
propagating_gateway_ids, extra=extra)
def _to_routes(self, element, xpath):
return [self._to_route(el) for el in element.findall(
fixxpath(xpath=xpath, namespace=NAMESPACE))
]
def _to_route(self, element):
"""
Parse the XML element and return a route object
:rtype: :class: `EC2Route`
"""
destination_cidr = findtext(element=element,
xpath='destinationCidrBlock',
namespace=NAMESPACE)
gateway_id = findtext(element=element,
xpath='gatewayId',
namespace=NAMESPACE)
instance_id = findtext(element=element,
xpath='instanceId',
namespace=NAMESPACE)
owner_id = findtext(element=element,
xpath='instanceOwnerId',
namespace=NAMESPACE)
interface_id = findtext(element=element,
xpath='networkInterfaceId',
namespace=NAMESPACE)
state = findtext(element=element,
xpath='state',
namespace=NAMESPACE)
origin = findtext(element=element,
xpath='origin',
namespace=NAMESPACE)
vpc_peering_connection_id = findtext(element=element,
xpath='vpcPeeringConnectionId',
namespace=NAMESPACE)
return EC2Route(destination_cidr, gateway_id, instance_id, owner_id,
interface_id, state, origin, vpc_peering_connection_id)
def _to_subnet_associations(self, element, xpath):
return [self._to_subnet_association(el) for el in element.findall(
fixxpath(xpath=xpath, namespace=NAMESPACE))
]
def _to_subnet_association(self, element):
"""
Parse the XML element and return a route table association object
:rtype: :class: `EC2SubnetAssociation`
"""
association_id = findtext(element=element,
xpath='routeTableAssociationId',
namespace=NAMESPACE)
route_table_id = findtext(element=element,
xpath='routeTableId',
namespace=NAMESPACE)
subnet_id = findtext(element=element,
xpath='subnetId',
namespace=NAMESPACE)
main = findtext(element=element,
xpath='main',
namespace=NAMESPACE)
main = True if main else False
return EC2SubnetAssociation(association_id, route_table_id,
subnet_id, main)
def _pathlist(self, key, arr):
"""
Converts a key and an array of values into AWS query param format.
"""
params = {}
i = 0
for value in arr:
i += 1
params['%s.%s' % (key, i)] = value
return params
def _get_boolean(self, element):
tag = '{%s}%s' % (NAMESPACE, 'return')
return element.findtext(tag) == 'true'
def _get_terminate_boolean(self, element):
status = element.findtext(".//{%s}%s" % (NAMESPACE, 'name'))
return any([term_status == status
for term_status
in ('shutting-down', 'terminated')])
def _add_instance_filter(self, params, node):
"""
Add instance filter to the provided params dictionary.
"""
filters = {'instance-id': node.id}
params.update(self._build_filters(filters))
return params
def _get_state_boolean(self, element):
"""
Checks for the instances's state
"""
state = findall(element=element,
xpath='instancesSet/item/currentState/name',
namespace=NAMESPACE)[0].text
return state in ('stopping', 'pending', 'starting')
def _get_extra_dict(self, element, mapping):
"""
Extract attributes from the element based on rules provided in the
mapping dictionary.
:param element: Element to parse the values from.
:type element: xml.etree.ElementTree.Element.
:param mapping: Dictionary with the extra layout
:type node: :class:`Node`
:rtype: ``dict``
"""
extra = {}
for attribute, values in mapping.items():
transform_func = values['transform_func']
value = findattr(element=element,
xpath=values['xpath'],
namespace=NAMESPACE)
if value is not None:
extra[attribute] = transform_func(value)
else:
extra[attribute] = None
return extra
def _get_resource_tags(self, element):
"""
Parse tags from the provided element and return a dictionary with
key/value pairs.
:rtype: ``dict``
"""
tags = {}
# Get our tag set by parsing the element
tag_set = findall(element=element,
xpath='tagSet/item',
namespace=NAMESPACE)
for tag in tag_set:
key = findtext(element=tag,
xpath='key',
namespace=NAMESPACE)
value = findtext(element=tag,
xpath='value',
namespace=NAMESPACE)
tags[key] = value
return tags
def _get_block_device_mapping_params(self, block_device_mapping):
"""
Return a list of dictionaries with query parameters for
a valid block device mapping.
:param mapping: List of dictionaries with the drive layout
:type mapping: ``list`` or ``dict``
:return: Dictionary representation of the drive mapping
:rtype: ``dict``
"""
if not isinstance(block_device_mapping, (list, tuple)):
raise AttributeError(
'block_device_mapping not list or tuple')
params = {}
for idx, mapping in enumerate(block_device_mapping):
idx += 1 # We want 1-based indexes
if not isinstance(mapping, dict):
raise AttributeError(
'mapping %s in block_device_mapping '
'not a dict' % mapping)
for k, v in mapping.items():
if not isinstance(v, dict):
params['BlockDeviceMapping.%d.%s' % (idx, k)] = str(v)
else:
for key, value in v.items():
params['BlockDeviceMapping.%d.%s.%s'
% (idx, k, key)] = str(value)
return params
def _get_common_security_group_params(self, group_id, protocol,
from_port, to_port, cidr_ips,
group_pairs):
"""
Return a dictionary with common query parameters which are used when
operating on security groups.
:rtype: ``dict``
"""
params = {'GroupId': group_id,
'IpPermissions.1.IpProtocol': protocol,
'IpPermissions.1.FromPort': from_port,
'IpPermissions.1.ToPort': to_port}
if cidr_ips is not None:
ip_ranges = {}
for index, cidr_ip in enumerate(cidr_ips):
index += 1
ip_ranges['IpPermissions.1.IpRanges.%s.CidrIp'
% (index)] = cidr_ip
params.update(ip_ranges)
if group_pairs is not None:
user_groups = {}
for index, group_pair in enumerate(group_pairs):
index += 1
if 'group_id' in group_pair.keys():
user_groups['IpPermissions.1.Groups.%s.GroupId'
% (index)] = group_pair['group_id']
if 'group_name' in group_pair.keys():
user_groups['IpPermissions.1.Groups.%s.GroupName'
% (index)] = group_pair['group_name']
if 'user_id' in group_pair.keys():
user_groups['IpPermissions.1.Groups.%s.UserId'
% (index)] = group_pair['user_id']
params.update(user_groups)
return params
def _get_security_groups(self, element):
"""
Parse security groups from the provided element and return a
list of security groups with the id ane name key/value pairs.
:rtype: ``list`` of ``dict``
"""
groups = []
for item in findall(element=element,
xpath='groupSet/item',
namespace=NAMESPACE):
groups.append({
'group_id': findtext(element=item,
xpath='groupId',
namespace=NAMESPACE),
'group_name': findtext(element=item,
xpath='groupName',
namespace=NAMESPACE)
})
return groups
def _build_filters(self, filters):
"""
Return a dictionary with filter query parameters which are used when
listing networks, security groups, etc.
:param filters: Dict of filter names and filter values
:type filters: ``dict``
:rtype: ``dict``
"""
filter_entries = {}
for filter_idx, filter_data in enumerate(filters.items()):
filter_idx += 1 # We want 1-based indexes
filter_name, filter_values = filter_data
filter_key = 'Filter.%s.Name' % (filter_idx)
filter_entries[filter_key] = filter_name
if isinstance(filter_values, list):
for value_idx, value in enumerate(filter_values):
value_idx += 1 # We want 1-based indexes
value_key = 'Filter.%s.Value.%s' % (filter_idx,
value_idx)
filter_entries[value_key] = value
else:
value_key = 'Filter.%s.Value.1' % (filter_idx)
filter_entries[value_key] = filter_values
return filter_entries
class EC2NodeDriver(BaseEC2NodeDriver):
"""
Amazon EC2 node driver.
"""
connectionCls = EC2Connection
type = Provider.EC2
name = 'Amazon EC2'
website = 'http://aws.amazon.com/ec2/'
path = '/'
NODE_STATE_MAP = {
'pending': NodeState.PENDING,
'running': NodeState.RUNNING,
'shutting-down': NodeState.UNKNOWN,
'terminated': NodeState.TERMINATED,
'stopped': NodeState.STOPPED
}
def __init__(self, key, secret=None, secure=True, host=None, port=None,
region='us-east-1', **kwargs):
if hasattr(self, '_region'):
region = self._region
if region not in VALID_EC2_REGIONS:
raise ValueError('Invalid region: %s' % (region))
details = REGION_DETAILS[region]
self.region_name = region
self.api_name = details['api_name']
self.country = details['country']
self.signature_version = details.get('signature_version',
DEFAULT_SIGNATURE_VERSION)
host = host or details['endpoint']
super(EC2NodeDriver, self).__init__(key=key, secret=secret,
secure=secure, host=host,
port=port, **kwargs)
class IdempotentParamError(LibcloudError):
"""
Request used the same client token as a previous,
but non-identical request.
"""
def __str__(self):
return repr(self.value)
class EC2EUNodeDriver(EC2NodeDriver):
"""
Driver class for EC2 in the Western Europe Region.
"""
name = 'Amazon EC2 (eu-west-1)'
_region = 'eu-west-1'
class EC2USWestNodeDriver(EC2NodeDriver):
"""
Driver class for EC2 in the Western US Region
"""
name = 'Amazon EC2 (us-west-1)'
_region = 'us-west-1'
class EC2USWestOregonNodeDriver(EC2NodeDriver):
"""
Driver class for EC2 in the US West Oregon region.
"""
name = 'Amazon EC2 (us-west-2)'
_region = 'us-west-2'
class EC2APSENodeDriver(EC2NodeDriver):
"""
Driver class for EC2 in the Southeast Asia Pacific Region.
"""
name = 'Amazon EC2 (ap-southeast-1)'
_region = 'ap-southeast-1'
class EC2APNENodeDriver(EC2NodeDriver):
"""
Driver class for EC2 in the Northeast Asia Pacific Region.
"""
name = 'Amazon EC2 (ap-northeast-1)'
_region = 'ap-northeast-1'
class EC2SAEastNodeDriver(EC2NodeDriver):
"""
Driver class for EC2 in the South America (Sao Paulo) Region.
"""
name = 'Amazon EC2 (sa-east-1)'
_region = 'sa-east-1'
class EC2APSESydneyNodeDriver(EC2NodeDriver):
"""
Driver class for EC2 in the Southeast Asia Pacific (Sydney) Region.
"""
name = 'Amazon EC2 (ap-southeast-2)'
_region = 'ap-southeast-2'
class EucConnection(EC2Connection):
"""
Connection class for Eucalyptus
"""
host = None
class EucNodeDriver(BaseEC2NodeDriver):
"""
Driver class for Eucalyptus
"""
name = 'Eucalyptus'
website = 'http://www.eucalyptus.com/'
api_name = 'ec2_us_east'
region_name = 'us-east-1'
connectionCls = EucConnection
signature_version = '2'
def __init__(self, key, secret=None, secure=True, host=None,
path=None, port=None, api_version=DEFAULT_EUCA_API_VERSION):
"""
@inherits: :class:`EC2NodeDriver.__init__`
:param path: The host where the API can be reached.
:type path: ``str``
:param api_version: The API version to extend support for
Eucalyptus proprietary API calls
:type api_version: ``str``
"""
super(EucNodeDriver, self).__init__(key, secret, secure, host, port)
if path is None:
path = '/services/Eucalyptus'
self.path = path
self.EUCA_NAMESPACE = 'http://msgs.eucalyptus.com/%s' % (api_version)
def list_locations(self):
raise NotImplementedError(
'list_locations not implemented for this driver')
def _to_sizes(self, response):
return [self._to_size(el) for el in response.findall(
fixxpath(xpath='instanceTypeDetails/item',
namespace=self.EUCA_NAMESPACE))]
def _to_size(self, el):
name = findtext(element=el,
xpath='name',
namespace=self.EUCA_NAMESPACE)
cpu = findtext(element=el,
xpath='cpu',
namespace=self.EUCA_NAMESPACE)
disk = findtext(element=el,
xpath='disk',
namespace=self.EUCA_NAMESPACE)
memory = findtext(element=el,
xpath='memory',
namespace=self.EUCA_NAMESPACE)
return NodeSize(id=name,
name=name,
ram=int(memory),
disk=int(disk),
bandwidth=None,
price=None,
driver=EucNodeDriver,
extra={
'cpu': int(cpu)
})
def list_sizes(self):
"""
List available instance flavors/sizes
:rtype: ``list`` of :class:`NodeSize`
"""
params = {'Action': 'DescribeInstanceTypes'}
response = self.connection.request(self.path, params=params).object
return self._to_sizes(response)
def _add_instance_filter(self, params, node):
"""
Eucalyptus driver doesn't support filtering on instance id so this is a
no-op.
"""
pass
class NimbusConnection(EC2Connection):
"""
Connection class for Nimbus
"""
host = None
class NimbusNodeDriver(BaseEC2NodeDriver):
"""
Driver class for Nimbus
"""
type = Provider.NIMBUS
name = 'Nimbus'
website = 'http://www.nimbusproject.org/'
country = 'Private'
api_name = 'nimbus'
region_name = 'nimbus'
friendly_name = 'Nimbus Private Cloud'
connectionCls = NimbusConnection
signature_version = '2'
def ex_describe_addresses(self, nodes):
"""
Nimbus doesn't support elastic IPs, so this is a pass-through.
@inherits: :class:`EC2NodeDriver.ex_describe_addresses`
"""
nodes_elastic_ip_mappings = {}
for node in nodes:
# empty list per node
nodes_elastic_ip_mappings[node.id] = []
return nodes_elastic_ip_mappings
def ex_create_tags(self, resource, tags):
"""
Nimbus doesn't support creating tags, so this is a pass-through.
@inherits: :class:`EC2NodeDriver.ex_create_tags`
"""
pass
class OutscaleConnection(EC2Connection):
"""
Connection class for Outscale
"""
host = None
class OutscaleNodeDriver(BaseEC2NodeDriver):
"""
Base Outscale FCU node driver.
Outscale per provider driver classes inherit from it.
"""
connectionCls = OutscaleConnection
name = 'Outscale'
website = 'http://www.outscale.com'
path = '/'
signature_version = '2'
NODE_STATE_MAP = {
'pending': NodeState.PENDING,
'running': NodeState.RUNNING,
'shutting-down': NodeState.UNKNOWN,
'terminated': NodeState.TERMINATED,
'stopped': NodeState.STOPPED
}
def __init__(self, key, secret=None, secure=True, host=None, port=None,
region='us-east-1', region_details=None, **kwargs):
if hasattr(self, '_region'):
region = self._region
if region_details is None:
raise ValueError('Invalid region_details argument')
if region not in region_details.keys():
raise ValueError('Invalid region: %s' % (region))
self.region_name = region
self.region_details = region_details
details = self.region_details[region]
self.api_name = details['api_name']
self.country = details['country']
self.connectionCls.host = details['endpoint']
self._not_implemented_msg =\
'This method is not supported in the Outscale driver'
super(BaseEC2NodeDriver, self).__init__(key=key, secret=secret,
secure=secure, host=host,
port=port, **kwargs)
def create_node(self, **kwargs):
"""
Create a new Outscale node. The ex_iamprofile keyword is not supported.
@inherits: :class:`BaseEC2NodeDriver.create_node`
:keyword ex_keyname: The name of the key pair
:type ex_keyname: ``str``
:keyword ex_userdata: User data
:type ex_userdata: ``str``
:keyword ex_security_groups: A list of names of security groups to
assign to the node.
:type ex_security_groups: ``list``
:keyword ex_metadata: Key/Value metadata to associate with a node
:type ex_metadata: ``dict``
:keyword ex_mincount: Minimum number of instances to launch
:type ex_mincount: ``int``
:keyword ex_maxcount: Maximum number of instances to launch
:type ex_maxcount: ``int``
:keyword ex_clienttoken: Unique identifier to ensure idempotency
:type ex_clienttoken: ``str``
:keyword ex_blockdevicemappings: ``list`` of ``dict`` block device
mappings.
:type ex_blockdevicemappings: ``list`` of ``dict``
:keyword ex_ebs_optimized: EBS-Optimized if True
:type ex_ebs_optimized: ``bool``
"""
if 'ex_iamprofile' in kwargs:
raise NotImplementedError("ex_iamprofile not implemented")
return super(OutscaleNodeDriver, self).create_node(**kwargs)
def ex_create_network(self, cidr_block, name=None):
"""
Create a network/VPC. Outscale does not support instance_tenancy.
:param cidr_block: The CIDR block assigned to the network
:type cidr_block: ``str``
:param name: An optional name for the network
:type name: ``str``
:return: Dictionary of network properties
:rtype: ``dict``
"""
return super(OutscaleNodeDriver, self).ex_create_network(cidr_block,
name=name)
def ex_modify_instance_attribute(self, node, disable_api_termination=None,
ebs_optimized=None, group_id=None,
source_dest_check=None, user_data=None,
instance_type=None):
"""
Modify node attributes.
Ouscale support the following attributes:
'DisableApiTermination.Value', 'EbsOptimized', 'GroupId.n',
'SourceDestCheck.Value', 'UserData.Value',
'InstanceType.Value'
:param node: Node instance
:type node: :class:`Node`
:param attributes: Dictionary with node attributes
:type attributes: ``dict``
:return: True on success, False otherwise.
:rtype: ``bool``
"""
attributes = {}
if disable_api_termination is not None:
attributes['DisableApiTermination.Value'] = disable_api_termination
if ebs_optimized is not None:
attributes['EbsOptimized'] = ebs_optimized
if group_id is not None:
attributes['GroupId.n'] = group_id
if source_dest_check is not None:
attributes['SourceDestCheck.Value'] = source_dest_check
if user_data is not None:
attributes['UserData.Value'] = user_data
if instance_type is not None:
attributes['InstanceType.Value'] = instance_type
return super(OutscaleNodeDriver, self).ex_modify_instance_attribute(
node, attributes)
def ex_register_image(self, name, description=None, architecture=None,
root_device_name=None, block_device_mapping=None):
"""
Registers a Machine Image based off of an EBS-backed instance.
Can also be used to create images from snapshots.
Outscale does not support image_location, kernel_id and ramdisk_id.
:param name: The name for the AMI being registered
:type name: ``str``
:param description: The description of the AMI (optional)
:type description: ``str``
:param architecture: The architecture of the AMI (i386/x86_64)
(optional)
:type architecture: ``str``
:param root_device_name: The device name for the root device
Required if registering an EBS-backed AMI
:type root_device_name: ``str``
:param block_device_mapping: A dictionary of the disk layout
(optional)
:type block_device_mapping: ``dict``
:rtype: :class:`NodeImage`
"""
return super(OutscaleNodeDriver, self).ex_register_image(
name, description=description, architecture=architecture,
root_device_name=root_device_name,
block_device_mapping=block_device_mapping)
def ex_copy_image(self, source_region, image, name=None, description=None):
"""
Outscale does not support copying images.
@inherits: :class:`EC2NodeDriver.ex_copy_image`
"""
raise NotImplementedError(self._not_implemented_msg)
def ex_get_limits(self):
"""
Outscale does not support getting limits.
@inherits: :class:`EC2NodeDriver.ex_get_limits`
"""
raise NotImplementedError(self._not_implemented_msg)
def ex_create_network_interface(self, subnet, name=None,
description=None,
private_ip_address=None):
"""
Outscale does not support creating a network interface within a VPC.
@inherits: :class:`EC2NodeDriver.ex_create_network_interface`
"""
raise NotImplementedError(self._not_implemented_msg)
def ex_delete_network_interface(self, network_interface):
"""
Outscale does not support deleting a network interface within a VPC.
@inherits: :class:`EC2NodeDriver.ex_delete_network_interface`
"""
raise NotImplementedError(self._not_implemented_msg)
def ex_attach_network_interface_to_node(self, network_interface,
node, device_index):
"""
Outscale does not support attaching a network interface.
@inherits: :class:`EC2NodeDriver.ex_attach_network_interface_to_node`
"""
raise NotImplementedError(self._not_implemented_msg)
def ex_detach_network_interface(self, attachment_id, force=False):
"""
Outscale does not support detaching a network interface
@inherits: :class:`EC2NodeDriver.ex_detach_network_interface`
"""
raise NotImplementedError(self._not_implemented_msg)
def list_sizes(self, location=None):
"""
List available instance flavors/sizes
This override the EC2 default method in order to use Outscale infos.
:rtype: ``list`` of :class:`NodeSize`
"""
available_types =\
self.region_details[self.region_name]['instance_types']
sizes = []
for instance_type in available_types:
attributes = OUTSCALE_INSTANCE_TYPES[instance_type]
attributes = copy.deepcopy(attributes)
price = self._get_size_price(size_id=instance_type)
attributes.update({'price': price})
sizes.append(NodeSize(driver=self, **attributes))
return sizes
class OutscaleSASNodeDriver(OutscaleNodeDriver):
"""
Outscale SAS node driver
"""
name = 'Outscale SAS'
type = Provider.OUTSCALE_SAS
def __init__(self, key, secret=None, secure=True, host=None, port=None,
region='us-east-1', region_details=None, **kwargs):
super(OutscaleSASNodeDriver, self).__init__(
key=key, secret=secret, secure=secure, host=host, port=port,
region=region, region_details=OUTSCALE_SAS_REGION_DETAILS,
**kwargs)
class OutscaleINCNodeDriver(OutscaleNodeDriver):
"""
Outscale INC node driver
"""
name = 'Outscale INC'
type = Provider.OUTSCALE_INC
def __init__(self, key, secret=None, secure=True, host=None, port=None,
region='us-east-1', region_details=None, **kwargs):
super(OutscaleINCNodeDriver, self).__init__(
key=key, secret=secret, secure=secure, host=host, port=port,
region=region, region_details=OUTSCALE_INC_REGION_DETAILS,
**kwargs)
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
199,
33,
8872,
15352,
18,
12,
662,
85,
915,
89,
541,
527,
12,
653,
1017,
5610,
436,
6219,
3467,
19016,
14,
199,
624,
199,
199,
646,
295,
199,
646,
984,
199,
646,
1300,
772,
199,
646,
1331,
199,
646,
3598,
199,
199,
893,
26,
272,
687,
14490,
492,
7559,
465,
12265,
199,
2590,
3545,
26,
272,
687,
2748,
14,
9464,
492,
13139,
465,
12265,
199,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
330,
12,
7116,
12,
4868,
63,
875,
199,
199,
504,
17069,
14,
1208,
14,
1652,
492,
5325,
8006,
12,
2342,
505,
12,
2342,
962,
12,
2342,
452,
199,
504,
17069,
14,
1208,
14,
5645,
8442,
14655,
492,
664,
63,
17178,
63,
5510,
18,
63,
15077,
199,
504,
17069,
14,
1208,
14,
5645,
8442,
14655,
492,
664,
63,
17178,
63,
3349,
199,
504,
17069,
14,
1208,
14,
4595,
15363,
492,
2198,
63,
602,
199,
504,
17069,
14,
2330,
14,
7231,
492,
10168,
1563,
2364,
12,
6632,
379,
13226,
3225,
199,
504,
17069,
14,
2330,
14,
7231,
492,
6186,
63,
26588,
63,
4612,
199,
504,
17069,
14,
2330,
14,
1313,
492,
334,
3364,
35,
10428,
547,
12,
603,
24012,
19712,
12,
3521,
8003,
4091,
547,
9,
199,
504,
17069,
14,
3357,
14,
9710,
492,
18489,
199,
504,
17069,
14,
3357,
14,
1095,
492,
5013,
12,
5013,
6158,
12,
5013,
6592,
12,
5013,
2320,
199,
504,
17069,
14,
3357,
14,
1095,
492,
5013,
3491,
12,
10533,
6464,
12,
15018,
12038,
199,
504,
17069,
14,
3357,
14,
1095,
492,
2606,
12882,
199,
504,
17069,
14,
3357,
14,
1313,
492,
5013,
2223,
12,
2606,
12882,
7400,
547,
12,
971,
272,
10533,
6464,
2223,
199,
199,
363,
452,
363,
275,
359,
272,
283,
3735,
63,
4612,
297,
272,
283,
13001,
297,
272,
283,
18235,
63,
7893,
297,
272,
283,
1877,
24333,
63,
18235,
63,
7893,
297,
272,
283,
1877,
24333,
63,
15319,
63,
23030,
63,
25081,
51,
297,
272,
283,
1877,
24333,
63,
25205,
63,
23030,
63,
25081,
51,
297,
272,
283,
3472,
63,
23539,
3263,
63,
3735,
63,
4612,
297,
272,
283,
23539,
3263,
63,
13001,
297,
339,
283,
4220,
18,
1716,
6158,
297,
272,
283,
1563,
4220,
18,
1716,
6158,
297,
339,
283,
46,
1017,
5610,
1716,
6158,
297,
272,
283,
37,
947,
1716,
6158,
297,
339,
283,
2204,
3467,
15319,
1716,
6158,
297,
272,
283,
2204,
3467,
25205,
1716,
6158,
297,
339,
283,
4220,
18,
1716,
6592,
297,
272,
283,
4220,
18,
10285,
1716,
297,
272,
283,
4220,
18,
19280,
297,
272,
283,
4220,
18,
32360,
2448,
297,
272,
283,
4220,
18,
4491,
297,
272,
283,
4220,
18,
4491,
15238,
297,
272,
283,
4220,
18,
4491,
4267,
297,
272,
283,
4220,
18,
7161,
3186,
297,
272,
283,
4220,
18,
7161,
297,
272,
283,
4220,
18,
15238,
18662,
297,
272,
283,
920,
4220,
18,
26462,
11860,
297,
339,
283,
41,
271,
16351,
4098,
547,
7,
199,
61,
199,
199,
3735,
63,
4612,
275,
283,
6965,
13,
709,
13,
1046,
7,
199,
13001,
275,
283,
1014,
921,
825,
18,
14,
21442,
14,
957,
15,
1301,
3149,
83,
4805,
450,
334,
3735,
63,
4612,
9,
199,
199,
3,
662,
85,
915,
89,
541,
527,
22296,
199,
3472,
63,
23539,
3263,
63,
3735,
63,
4612,
275,
283,
19,
14,
19,
14,
16,
7,
199,
23539,
3263,
63,
13001,
275,
283,
1014,
921,
13429,
14,
16913,
915,
89,
541,
527,
14,
957,
3149,
83,
7,
450,
334,
3472,
63,
23539,
3263,
63,
3735,
63,
4612,
9,
199,
199,
624,
199,
29790,
1471,
506,
7508,
15282,
12,
2952,
14347,
3181,
1133,
5647,
376,
3261,
370,
5267,
3062,
14,
199,
2532,
1455,
921,
7231,
14,
15144,
14,
957,
15,
825,
18,
15,
842,
13,
1313,
15,
199,
624,
199,
18235,
63,
7893,
275,
469,
272,
283,
84,
17,
14,
6453,
356,
469,
267,
283,
344,
356,
283,
84,
17,
14,
6453,
297,
267,
283,
354,
356,
283,
23990,
10066,
297,
267,
283,
5975,
356,
1227,
969,
12,
267,
283,
4032,
356,
4114,
12,
267,
283,
18358,
356,
488,
272,
1660,
272,
283,
77,
17,
14,
7241,
356,
469,
267,
283,
344,
356,
283,
77,
17,
14,
7241,
297,
267,
283,
354,
356,
283,
10712,
10066,
297,
267,
283,
5975,
356,
413,
17702,
12,
267,
283,
4032,
356,
21235,
12,
267,
283,
18358,
356,
488,
272,
1660,
272,
283,
77,
17,
14,
14345,
356,
469,
267,
283,
344,
356,
283,
77,
17,
14,
14345,
297,
267,
283,
354,
356,
283,
26139,
10066,
297,
267,
283,
5975,
356,
6877,
383,
12,
267,
283,
4032,
356,
32321,
12,
267,
283,
18358,
356,
488,
272,
1660,
272,
283,
77,
17,
14,
9629,
356,
469,
267,
283,
344,
356,
283,
77,
17,
14,
9629,
297,
267,
283,
354,
356,
283,
17149,
10066,
297,
267,
283,
5975,
356,
14646,
1257,
12,
267,
283,
4032,
356,
1695,
1400,
12,
267,
283,
18358,
356,
488,
272,
1660,
272,
283,
77,
17,
14,
28598,
356,
469,
267,
283,
344,
356,
283,
77,
17,
14,
28598,
297,
267,
283,
354,
356,
283,
7426,
29095,
10066,
297,
267,
283,
5975,
356,
4114,
11197,
12,
267,
283,
4032,
356,
20680,
16,
12,
267,
283,
18358
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
199,
33,
8872,
15352,
18,
12,
662,
85,
915,
89,
541,
527,
12,
653,
1017,
5610,
436,
6219,
3467,
19016,
14,
199,
624,
199,
199,
646,
295,
199,
646,
984,
199,
646,
1300,
772,
199,
646,
1331,
199,
646,
3598,
199,
199,
893,
26,
272,
687,
14490,
492,
7559,
465,
12265,
199,
2590,
3545,
26,
272,
687,
2748,
14,
9464,
492,
13139,
465,
12265,
199,
199,
504,
17069,
14,
1208,
14,
647,
19,
492,
330,
12,
7116,
12,
4868,
63,
875,
199,
199,
504,
17069,
14,
1208,
14,
1652,
492,
5325,
8006,
12,
2342,
505,
12,
2342,
962,
12,
2342,
452,
199,
504,
17069,
14,
1208,
14,
5645,
8442,
14655,
492,
664,
63,
17178,
63,
5510,
18,
63,
15077,
199,
504,
17069,
14,
1208,
14,
5645,
8442,
14655,
492,
664,
63,
17178,
63,
3349,
199,
504,
17069,
14,
1208,
14,
4595,
15363,
492,
2198,
63,
602,
199,
504,
17069,
14,
2330,
14,
7231,
492,
10168,
1563,
2364,
12,
6632,
379,
13226,
3225,
199,
504,
17069,
14,
2330,
14,
7231,
492,
6186,
63,
26588,
63,
4612,
199,
504,
17069,
14,
2330,
14,
1313,
492,
334,
3364,
35,
10428,
547,
12,
603,
24012,
19712,
12,
3521,
8003,
4091,
547,
9,
199,
504,
17069,
14,
3357,
14,
9710,
492,
18489,
199,
504,
17069,
14,
3357,
14,
1095,
492,
5013,
12,
5013,
6158,
12,
5013,
6592,
12,
5013,
2320,
199,
504,
17069,
14,
3357,
14,
1095,
492,
5013,
3491,
12,
10533,
6464,
12,
15018,
12038,
199,
504,
17069,
14,
3357,
14,
1095,
492,
2606,
12882,
199,
504,
17069,
14,
3357,
14,
1313,
492,
5013,
2223,
12,
2606,
12882,
7400,
547,
12,
971,
272,
10533,
6464,
2223,
199,
199,
363,
452,
363,
275,
359,
272,
283,
3735,
63,
4612,
297,
272,
283,
13001,
297,
272,
283,
18235,
63,
7893,
297,
272,
283,
1877,
24333,
63,
18235,
63,
7893,
297,
272,
283,
1877,
24333,
63,
15319,
63,
23030,
63,
25081,
51,
297,
272,
283,
1877,
24333,
63,
25205,
63,
23030,
63,
25081,
51,
297,
272,
283,
3472,
63,
23539,
3263,
63,
3735,
63,
4612,
297,
272,
283,
23539,
3263,
63,
13001,
297,
339,
283,
4220,
18,
1716,
6158,
297,
272,
283,
1563,
4220,
18,
1716,
6158,
297,
339,
283,
46,
1017,
5610,
1716,
6158,
297,
272,
283,
37,
947,
1716,
6158,
297,
339,
283,
2204,
3467,
15319,
1716,
6158,
297,
272,
283,
2204,
3467,
25205,
1716,
6158,
297,
339,
283,
4220,
18,
1716,
6592,
297,
272,
283,
4220,
18,
10285,
1716,
297,
272,
283,
4220,
18,
19280,
297,
272,
283,
4220,
18,
32360,
2448,
297,
272,
283,
4220,
18,
4491,
297,
272,
283,
4220,
18,
4491,
15238,
297,
272,
283,
4220,
18,
4491,
4267,
297,
272,
283,
4220,
18,
7161,
3186,
297,
272,
283,
4220,
18,
7161,
297,
272,
283,
4220,
18,
15238,
18662,
297,
272,
283,
920,
4220,
18,
26462,
11860,
297,
339,
283,
41,
271,
16351,
4098,
547,
7,
199,
61,
199,
199,
3735,
63,
4612,
275,
283,
6965,
13,
709,
13,
1046,
7,
199,
13001,
275,
283,
1014,
921,
825,
18,
14,
21442,
14,
957,
15,
1301,
3149,
83,
4805,
450,
334,
3735,
63,
4612,
9,
199,
199,
3,
662,
85,
915,
89,
541,
527,
22296,
199,
3472,
63,
23539,
3263,
63,
3735,
63,
4612,
275,
283,
19,
14,
19,
14,
16,
7,
199,
23539,
3263,
63,
13001,
275,
283,
1014,
921,
13429,
14,
16913,
915,
89,
541,
527,
14,
957,
3149,
83,
7,
450,
334,
3472,
63,
23539,
3263,
63,
3735,
63,
4612,
9,
199,
199,
624,
199,
29790,
1471,
506,
7508,
15282,
12,
2952,
14347,
3181,
1133,
5647,
376,
3261,
370,
5267,
3062,
14,
199,
2532,
1455,
921,
7231,
14,
15144,
14,
957,
15,
825,
18,
15,
842,
13,
1313,
15,
199,
624,
199,
18235,
63,
7893,
275,
469,
272,
283,
84,
17,
14,
6453,
356,
469,
267,
283,
344,
356,
283,
84,
17,
14,
6453,
297,
267,
283,
354,
356,
283,
23990,
10066,
297,
267,
283,
5975,
356,
1227,
969,
12,
267,
283,
4032,
356,
4114,
12,
267,
283,
18358,
356,
488,
272,
1660,
272,
283,
77,
17,
14,
7241,
356,
469,
267,
283,
344,
356,
283,
77,
17,
14,
7241,
297,
267,
283,
354,
356,
283,
10712,
10066,
297,
267,
283,
5975,
356,
413,
17702,
12,
267,
283,
4032,
356,
21235,
12,
267,
283,
18358,
356,
488,
272,
1660,
272,
283,
77,
17,
14,
14345,
356,
469,
267,
283,
344,
356,
283,
77,
17,
14,
14345,
297,
267,
283,
354,
356,
283,
26139,
10066,
297,
267,
283,
5975,
356,
6877,
383,
12,
267,
283,
4032,
356,
32321,
12,
267,
283,
18358,
356,
488,
272,
1660,
272,
283,
77,
17,
14,
9629,
356,
469,
267,
283,
344,
356,
283,
77,
17,
14,
9629,
297,
267,
283,
354,
356,
283,
17149,
10066,
297,
267,
283,
5975,
356,
14646,
1257,
12,
267,
283,
4032,
356,
1695,
1400,
12,
267,
283,
18358,
356,
488,
272,
1660,
272,
283,
77,
17,
14,
28598,
356,
469,
267,
283,
344,
356,
283,
77,
17,
14,
28598,
297,
267,
283,
354,
356,
283,
7426,
29095,
10066,
297,
267,
283,
5975,
356,
4114,
11197,
12,
267,
283,
4032,
356,
20680,
16,
12,
267,
283,
18358,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tegusi/shadowsocks
|
setup.py
|
929
|
1321
|
import codecs
from setuptools import setup
with codecs.open('README.rst', encoding='utf-8') as f:
long_description = f.read()
setup(
name="shadowsocks",
version="2.8.2",
license='http://www.apache.org/licenses/LICENSE-2.0',
description="A fast tunnel proxy that help you get through firewalls",
author='clowwindy',
author_email='clowwindy42@gmail.com',
url='https://github.com/shadowsocks/shadowsocks',
packages=['shadowsocks', 'shadowsocks.crypto'],
package_data={
'shadowsocks': ['README.rst', 'LICENSE']
},
install_requires=[],
entry_points="""
[console_scripts]
sslocal = shadowsocks.local:main
ssserver = shadowsocks.server:main
""",
classifiers=[
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Internet :: Proxy Servers',
],
long_description=long_description,
)
|
apache-2.0
|
[
646,
6010,
199,
504,
9116,
492,
3272,
421,
199,
1045,
6010,
14,
1490,
360,
18195,
14,
8332,
297,
2644,
534,
1624,
13,
24,
358,
465,
289,
26,
272,
1846,
63,
1802,
275,
289,
14,
739,
342,
199,
199,
2758,
8,
272,
536,
628,
14714,
21234,
401,
272,
1015,
628,
18,
14,
24,
14,
18,
401,
272,
4190,
534,
1014,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
297,
272,
1369,
628,
33,
7377,
21496,
4566,
626,
1720,
1265,
664,
4012,
12042,
83,
401,
272,
4132,
534,
67,
674,
11530,
89,
297,
272,
4132,
63,
2123,
534,
67,
674,
11530,
89,
2260,
32,
6799,
14,
957,
297,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
14714,
21234,
15,
14714,
21234,
297,
272,
6117,
2968,
14714,
21234,
297,
283,
14714,
21234,
14,
10316,
995,
272,
2559,
63,
576,
3126,
267,
283,
14714,
21234,
356,
788,
18195,
14,
8332,
297,
283,
3961,
418,
272,
1660,
272,
3907,
63,
6537,
6034,
272,
2397,
63,
3438,
11916,
272,
359,
6614,
63,
6429,
61,
272,
10110,
1832,
275,
15084,
21234,
14,
1832,
26,
973,
272,
10110,
1000,
275,
15084,
21234,
14,
1000,
26,
973,
272,
10327,
272,
19137,
1524,
267,
283,
3761,
3800,
25718,
26330,
3800,
3668,
2290,
844,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
22,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
19,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
20,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
24425,
3800,
25654,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
24425,
3800,
1611,
2713,
297,
267,
283,
12157,
3800,
22026,
3800,
12373,
7146,
83,
297,
272,
2156,
272,
1846,
63,
1802,
29,
2809,
63,
1802,
12,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6010,
199,
504,
9116,
492,
3272,
421,
199,
1045,
6010,
14,
1490,
360,
18195,
14,
8332,
297,
2644,
534,
1624,
13,
24,
358,
465,
289,
26,
272,
1846,
63,
1802,
275,
289,
14,
739,
342,
199,
199,
2758,
8,
272,
536,
628,
14714,
21234,
401,
272,
1015,
628,
18,
14,
24,
14,
18,
401,
272,
4190,
534,
1014,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
297,
272,
1369,
628,
33,
7377,
21496,
4566,
626,
1720,
1265,
664,
4012,
12042,
83,
401,
272,
4132,
534,
67,
674,
11530,
89,
297,
272,
4132,
63,
2123,
534,
67,
674,
11530,
89,
2260,
32,
6799,
14,
957,
297,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
14714,
21234,
15,
14714,
21234,
297,
272,
6117,
2968,
14714,
21234,
297,
283,
14714,
21234,
14,
10316,
995,
272,
2559,
63,
576,
3126,
267,
283,
14714,
21234,
356,
788,
18195,
14,
8332,
297,
283,
3961,
418,
272,
1660,
272,
3907,
63,
6537,
6034,
272,
2397,
63,
3438,
11916,
272,
359,
6614,
63,
6429,
61,
272,
10110,
1832,
275,
15084,
21234,
14,
1832,
26,
973,
272,
10110,
1000,
275,
15084,
21234,
14,
1000,
26,
973,
272,
10327,
272,
19137,
1524,
267,
283,
3761,
3800,
25718,
26330,
3800,
3668,
2290,
844,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
22,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
19,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
20,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
24425,
3800,
25654,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
24425,
3800,
1611,
2713,
297,
267,
283,
12157,
3800,
22026,
3800,
12373,
7146,
83,
297,
272,
2156,
272,
1846,
63,
1802,
29,
2809,
63,
1802,
12,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
vFense/vFenseAgent-nix
|
agent/deps/rpm6/Python-2.7.5/lib/python2.7/test/test_urllib.py
|
36
|
35463
|
"""Regresssion tests for urllib"""
import urllib
import httplib
import unittest
import os
import sys
import mimetools
import tempfile
import StringIO
from test import test_support
from base64 import b64encode
def hexescape(char):
"""Escape char as RFC 2396 specifies"""
hex_repr = hex(ord(char))[2:].upper()
if len(hex_repr) == 1:
hex_repr = "0%s" % hex_repr
return "%" + hex_repr
class FakeHTTPMixin(object):
def fakehttp(self, fakedata):
class FakeSocket(StringIO.StringIO):
def sendall(self, data):
FakeHTTPConnection.buf = data
def makefile(self, *args, **kwds):
return self
def read(self, amt=None):
if self.closed:
return ""
return StringIO.StringIO.read(self, amt)
def readline(self, length=None):
if self.closed:
return ""
return StringIO.StringIO.readline(self, length)
class FakeHTTPConnection(httplib.HTTPConnection):
# buffer to store data for verification in urlopen tests.
buf = ""
def connect(self):
self.sock = FakeSocket(fakedata)
assert httplib.HTTP._connection_class == httplib.HTTPConnection
httplib.HTTP._connection_class = FakeHTTPConnection
def unfakehttp(self):
httplib.HTTP._connection_class = httplib.HTTPConnection
class urlopen_FileTests(unittest.TestCase):
"""Test urlopen() opening a temporary file.
Try to test as much functionality as possible so as to cut down on reliance
on connecting to the Net for testing.
"""
def setUp(self):
"""Setup of a temp file to use for testing"""
self.text = "test_urllib: %s\n" % self.__class__.__name__
FILE = file(test_support.TESTFN, 'wb')
try:
FILE.write(self.text)
finally:
FILE.close()
self.pathname = test_support.TESTFN
self.returned_obj = urllib.urlopen("file:%s" % self.pathname)
def tearDown(self):
"""Shut down the open object"""
self.returned_obj.close()
os.remove(test_support.TESTFN)
def test_interface(self):
# Make sure object returned by urlopen() has the specified methods
for attr in ("read", "readline", "readlines", "fileno",
"close", "info", "geturl", "getcode", "__iter__"):
self.assertTrue(hasattr(self.returned_obj, attr),
"object returned by urlopen() lacks %s attribute" %
attr)
def test_read(self):
self.assertEqual(self.text, self.returned_obj.read())
def test_readline(self):
self.assertEqual(self.text, self.returned_obj.readline())
self.assertEqual('', self.returned_obj.readline(),
"calling readline() after exhausting the file did not"
" return an empty string")
def test_readlines(self):
lines_list = self.returned_obj.readlines()
self.assertEqual(len(lines_list), 1,
"readlines() returned the wrong number of lines")
self.assertEqual(lines_list[0], self.text,
"readlines() returned improper text")
def test_fileno(self):
file_num = self.returned_obj.fileno()
self.assertIsInstance(file_num, int, "fileno() did not return an int")
self.assertEqual(os.read(file_num, len(self.text)), self.text,
"Reading on the file descriptor returned by fileno() "
"did not return the expected text")
def test_close(self):
# Test close() by calling it hear and then having it be called again
# by the tearDown() method for the test
self.returned_obj.close()
def test_info(self):
self.assertIsInstance(self.returned_obj.info(), mimetools.Message)
def test_geturl(self):
self.assertEqual(self.returned_obj.geturl(), self.pathname)
def test_getcode(self):
self.assertEqual(self.returned_obj.getcode(), None)
def test_iter(self):
# Test iterator
# Don't need to count number of iterations since test would fail the
# instant it returned anything beyond the first line from the
# comparison
for line in self.returned_obj.__iter__():
self.assertEqual(line, self.text)
def test_relativelocalfile(self):
self.assertRaises(ValueError,urllib.urlopen,'./' + self.pathname)
class ProxyTests(unittest.TestCase):
def setUp(self):
# Records changes to env vars
self.env = test_support.EnvironmentVarGuard()
# Delete all proxy related env vars
for k in os.environ.keys():
if 'proxy' in k.lower():
self.env.unset(k)
def tearDown(self):
# Restore all proxy related env vars
self.env.__exit__()
del self.env
def test_getproxies_environment_keep_no_proxies(self):
self.env.set('NO_PROXY', 'localhost')
proxies = urllib.getproxies_environment()
# getproxies_environment use lowered case truncated (no '_proxy') keys
self.assertEqual('localhost', proxies['no'])
# List of no_proxies with space.
self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com')
self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com'))
class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin):
"""Test urlopen() opening a fake http connection."""
def test_read(self):
self.fakehttp('Hello!')
try:
fp = urllib.urlopen("http://python.org/")
self.assertEqual(fp.readline(), 'Hello!')
self.assertEqual(fp.readline(), '')
self.assertEqual(fp.geturl(), 'http://python.org/')
self.assertEqual(fp.getcode(), 200)
finally:
self.unfakehttp()
def test_url_fragment(self):
# Issue #11703: geturl() omits fragments in the original URL.
url = 'http://docs.python.org/library/urllib.html#OK'
self.fakehttp('Hello!')
try:
fp = urllib.urlopen(url)
self.assertEqual(fp.geturl(), url)
finally:
self.unfakehttp()
def test_read_bogus(self):
# urlopen() should raise IOError for many error codes.
self.fakehttp('''HTTP/1.1 401 Authentication Required
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Type: text/html; charset=iso-8859-1
''')
try:
self.assertRaises(IOError, urllib.urlopen, "http://python.org/")
finally:
self.unfakehttp()
def test_invalid_redirect(self):
# urlopen() should raise IOError for many error codes.
self.fakehttp("""HTTP/1.1 302 Found
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Location: file:README
Connection: close
Content-Type: text/html; charset=iso-8859-1
""")
try:
self.assertRaises(IOError, urllib.urlopen, "http://python.org/")
finally:
self.unfakehttp()
def test_empty_socket(self):
# urlopen() raises IOError if the underlying socket does not send any
# data. (#1680230)
self.fakehttp('')
try:
self.assertRaises(IOError, urllib.urlopen, 'http://something')
finally:
self.unfakehttp()
def test_missing_localfile(self):
self.assertRaises(IOError, urllib.urlopen,
'file://localhost/a/missing/file.py')
fd, tmp_file = tempfile.mkstemp()
tmp_fileurl = 'file://localhost/' + tmp_file.replace(os.path.sep, '/')
try:
self.assertTrue(os.path.exists(tmp_file))
fp = urllib.urlopen(tmp_fileurl)
finally:
os.close(fd)
fp.close()
os.unlink(tmp_file)
self.assertFalse(os.path.exists(tmp_file))
self.assertRaises(IOError, urllib.urlopen, tmp_fileurl)
def test_ftp_nonexisting(self):
self.assertRaises(IOError, urllib.urlopen,
'ftp://localhost/not/existing/file.py')
def test_userpass_inurl(self):
self.fakehttp('Hello!')
try:
fakehttp_wrapper = httplib.HTTP._connection_class
fp = urllib.urlopen("http://user:pass@python.org/")
authorization = ("Authorization: Basic %s\r\n" %
b64encode('user:pass'))
# The authorization header must be in place
self.assertIn(authorization, fakehttp_wrapper.buf)
self.assertEqual(fp.readline(), "Hello!")
self.assertEqual(fp.readline(), "")
self.assertEqual(fp.geturl(), 'http://user:pass@python.org/')
self.assertEqual(fp.getcode(), 200)
finally:
self.unfakehttp()
def test_userpass_with_spaces_inurl(self):
self.fakehttp('Hello!')
try:
url = "http://a b:c d@python.org/"
fakehttp_wrapper = httplib.HTTP._connection_class
authorization = ("Authorization: Basic %s\r\n" %
b64encode('a b:c d'))
fp = urllib.urlopen(url)
# The authorization header must be in place
self.assertIn(authorization, fakehttp_wrapper.buf)
self.assertEqual(fp.readline(), "Hello!")
self.assertEqual(fp.readline(), "")
# the spaces are quoted in URL so no match
self.assertNotEqual(fp.geturl(), url)
self.assertEqual(fp.getcode(), 200)
finally:
self.unfakehttp()
class urlretrieve_FileTests(unittest.TestCase):
"""Test urllib.urlretrieve() on local files"""
def setUp(self):
# Create a list of temporary files. Each item in the list is a file
# name (absolute path or relative to the current working directory).
# All files in this list will be deleted in the tearDown method. Note,
# this only helps to makes sure temporary files get deleted, but it
# does nothing about trying to close files that may still be open. It
# is the responsibility of the developer to properly close files even
# when exceptional conditions occur.
self.tempFiles = []
# Create a temporary file.
self.registerFileForCleanUp(test_support.TESTFN)
self.text = 'testing urllib.urlretrieve'
try:
FILE = file(test_support.TESTFN, 'wb')
FILE.write(self.text)
FILE.close()
finally:
try: FILE.close()
except: pass
def tearDown(self):
# Delete the temporary files.
for each in self.tempFiles:
try: os.remove(each)
except: pass
def constructLocalFileUrl(self, filePath):
return "file://%s" % urllib.pathname2url(os.path.abspath(filePath))
def createNewTempFile(self, data=""):
"""Creates a new temporary file containing the specified data,
registers the file for deletion during the test fixture tear down, and
returns the absolute path of the file."""
newFd, newFilePath = tempfile.mkstemp()
try:
self.registerFileForCleanUp(newFilePath)
newFile = os.fdopen(newFd, "wb")
newFile.write(data)
newFile.close()
finally:
try: newFile.close()
except: pass
return newFilePath
def registerFileForCleanUp(self, fileName):
self.tempFiles.append(fileName)
def test_basic(self):
# Make sure that a local file just gets its own location returned and
# a headers value is returned.
result = urllib.urlretrieve("file:%s" % test_support.TESTFN)
self.assertEqual(result[0], test_support.TESTFN)
self.assertIsInstance(result[1], mimetools.Message,
"did not get a mimetools.Message instance as "
"second returned value")
def test_copy(self):
# Test that setting the filename argument works.
second_temp = "%s.2" % test_support.TESTFN
self.registerFileForCleanUp(second_temp)
result = urllib.urlretrieve(self.constructLocalFileUrl(
test_support.TESTFN), second_temp)
self.assertEqual(second_temp, result[0])
self.assertTrue(os.path.exists(second_temp), "copy of the file was not "
"made")
FILE = file(second_temp, 'rb')
try:
text = FILE.read()
FILE.close()
finally:
try: FILE.close()
except: pass
self.assertEqual(self.text, text)
def test_reporthook(self):
# Make sure that the reporthook works.
def hooktester(count, block_size, total_size, count_holder=[0]):
self.assertIsInstance(count, int)
self.assertIsInstance(block_size, int)
self.assertIsInstance(total_size, int)
self.assertEqual(count, count_holder[0])
count_holder[0] = count_holder[0] + 1
second_temp = "%s.2" % test_support.TESTFN
self.registerFileForCleanUp(second_temp)
urllib.urlretrieve(self.constructLocalFileUrl(test_support.TESTFN),
second_temp, hooktester)
def test_reporthook_0_bytes(self):
# Test on zero length file. Should call reporthook only 1 time.
report = []
def hooktester(count, block_size, total_size, _report=report):
_report.append((count, block_size, total_size))
srcFileName = self.createNewTempFile()
urllib.urlretrieve(self.constructLocalFileUrl(srcFileName),
test_support.TESTFN, hooktester)
self.assertEqual(len(report), 1)
self.assertEqual(report[0][2], 0)
def test_reporthook_5_bytes(self):
# Test on 5 byte file. Should call reporthook only 2 times (once when
# the "network connection" is established and once when the block is
# read). Since the block size is 8192 bytes, only one block read is
# required to read the entire file.
report = []
def hooktester(count, block_size, total_size, _report=report):
_report.append((count, block_size, total_size))
srcFileName = self.createNewTempFile("x" * 5)
urllib.urlretrieve(self.constructLocalFileUrl(srcFileName),
test_support.TESTFN, hooktester)
self.assertEqual(len(report), 2)
self.assertEqual(report[0][1], 8192)
self.assertEqual(report[0][2], 5)
def test_reporthook_8193_bytes(self):
# Test on 8193 byte file. Should call reporthook only 3 times (once
# when the "network connection" is established, once for the next 8192
# bytes, and once for the last byte).
report = []
def hooktester(count, block_size, total_size, _report=report):
_report.append((count, block_size, total_size))
srcFileName = self.createNewTempFile("x" * 8193)
urllib.urlretrieve(self.constructLocalFileUrl(srcFileName),
test_support.TESTFN, hooktester)
self.assertEqual(len(report), 3)
self.assertEqual(report[0][1], 8192)
self.assertEqual(report[0][2], 8193)
class urlretrieve_HttpTests(unittest.TestCase, FakeHTTPMixin):
"""Test urllib.urlretrieve() using fake http connections"""
def test_short_content_raises_ContentTooShortError(self):
self.fakehttp('''HTTP/1.1 200 OK
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Length: 100
Content-Type: text/html; charset=iso-8859-1
FF
''')
def _reporthook(par1, par2, par3):
pass
try:
self.assertRaises(urllib.ContentTooShortError, urllib.urlretrieve,
'http://example.com', reporthook=_reporthook)
finally:
self.unfakehttp()
def test_short_content_raises_ContentTooShortError_without_reporthook(self):
self.fakehttp('''HTTP/1.1 200 OK
Date: Wed, 02 Jan 2008 03:03:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e
Connection: close
Content-Length: 100
Content-Type: text/html; charset=iso-8859-1
FF
''')
try:
self.assertRaises(urllib.ContentTooShortError, urllib.urlretrieve, 'http://example.com/')
finally:
self.unfakehttp()
class QuotingTests(unittest.TestCase):
"""Tests for urllib.quote() and urllib.quote_plus()
According to RFC 2396 ("Uniform Resource Identifiers), to escape a
character you write it as '%' + <2 character US-ASCII hex value>. The Python
code of ``'%' + hex(ord(<character>))[2:]`` escapes a character properly.
Case does not matter on the hex letters.
The various character sets specified are:
Reserved characters : ";/?:@&=+$,"
Have special meaning in URIs and must be escaped if not being used for
their special meaning
Data characters : letters, digits, and "-_.!~*'()"
Unreserved and do not need to be escaped; can be, though, if desired
Control characters : 0x00 - 0x1F, 0x7F
Have no use in URIs so must be escaped
space : 0x20
Must be escaped
Delimiters : '<>#%"'
Must be escaped
Unwise : "{}|\^[]`"
Must be escaped
"""
def test_never_quote(self):
# Make sure quote() does not quote letters, digits, and "_,.-"
do_not_quote = '' .join(["ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyz",
"0123456789",
"_.-"])
result = urllib.quote(do_not_quote)
self.assertEqual(do_not_quote, result,
"using quote(): %s != %s" % (do_not_quote, result))
result = urllib.quote_plus(do_not_quote)
self.assertEqual(do_not_quote, result,
"using quote_plus(): %s != %s" % (do_not_quote, result))
def test_default_safe(self):
# Test '/' is default value for 'safe' parameter
self.assertEqual(urllib.quote.func_defaults[0], '/')
def test_safe(self):
# Test setting 'safe' parameter does what it should do
quote_by_default = "<>"
result = urllib.quote(quote_by_default, safe=quote_by_default)
self.assertEqual(quote_by_default, result,
"using quote(): %s != %s" % (quote_by_default, result))
result = urllib.quote_plus(quote_by_default, safe=quote_by_default)
self.assertEqual(quote_by_default, result,
"using quote_plus(): %s != %s" %
(quote_by_default, result))
def test_default_quoting(self):
# Make sure all characters that should be quoted are by default sans
# space (separate test for that).
should_quote = [chr(num) for num in range(32)] # For 0x00 - 0x1F
should_quote.append('<>#%"{}|\^[]`')
should_quote.append(chr(127)) # For 0x7F
should_quote = ''.join(should_quote)
for char in should_quote:
result = urllib.quote(char)
self.assertEqual(hexescape(char), result,
"using quote(): %s should be escaped to %s, not %s" %
(char, hexescape(char), result))
result = urllib.quote_plus(char)
self.assertEqual(hexescape(char), result,
"using quote_plus(): "
"%s should be escapes to %s, not %s" %
(char, hexescape(char), result))
del should_quote
partial_quote = "ab[]cd"
expected = "ab%5B%5Dcd"
result = urllib.quote(partial_quote)
self.assertEqual(expected, result,
"using quote(): %s != %s" % (expected, result))
result = urllib.quote_plus(partial_quote)
self.assertEqual(expected, result,
"using quote_plus(): %s != %s" % (expected, result))
self.assertRaises(TypeError, urllib.quote, None)
def test_quoting_space(self):
# Make sure quote() and quote_plus() handle spaces as specified in
# their unique way
result = urllib.quote(' ')
self.assertEqual(result, hexescape(' '),
"using quote(): %s != %s" % (result, hexescape(' ')))
result = urllib.quote_plus(' ')
self.assertEqual(result, '+',
"using quote_plus(): %s != +" % result)
given = "a b cd e f"
expect = given.replace(' ', hexescape(' '))
result = urllib.quote(given)
self.assertEqual(expect, result,
"using quote(): %s != %s" % (expect, result))
expect = given.replace(' ', '+')
result = urllib.quote_plus(given)
self.assertEqual(expect, result,
"using quote_plus(): %s != %s" % (expect, result))
def test_quoting_plus(self):
self.assertEqual(urllib.quote_plus('alpha+beta gamma'),
'alpha%2Bbeta+gamma')
self.assertEqual(urllib.quote_plus('alpha+beta gamma', '+'),
'alpha+beta+gamma')
class UnquotingTests(unittest.TestCase):
"""Tests for unquote() and unquote_plus()
See the doc string for quoting_Tests for details on quoting and such.
"""
def test_unquoting(self):
# Make sure unquoting of all ASCII values works
escape_list = []
for num in range(128):
given = hexescape(chr(num))
expect = chr(num)
result = urllib.unquote(given)
self.assertEqual(expect, result,
"using unquote(): %s != %s" % (expect, result))
result = urllib.unquote_plus(given)
self.assertEqual(expect, result,
"using unquote_plus(): %s != %s" %
(expect, result))
escape_list.append(given)
escape_string = ''.join(escape_list)
del escape_list
result = urllib.unquote(escape_string)
self.assertEqual(result.count('%'), 1,
"using quote(): not all characters escaped; %s" %
result)
result = urllib.unquote(escape_string)
self.assertEqual(result.count('%'), 1,
"using unquote(): not all characters escaped: "
"%s" % result)
def test_unquoting_badpercent(self):
# Test unquoting on bad percent-escapes
given = '%xab'
expect = given
result = urllib.unquote(given)
self.assertEqual(expect, result, "using unquote(): %r != %r"
% (expect, result))
given = '%x'
expect = given
result = urllib.unquote(given)
self.assertEqual(expect, result, "using unquote(): %r != %r"
% (expect, result))
given = '%'
expect = given
result = urllib.unquote(given)
self.assertEqual(expect, result, "using unquote(): %r != %r"
% (expect, result))
def test_unquoting_mixed_case(self):
# Test unquoting on mixed-case hex digits in the percent-escapes
given = '%Ab%eA'
expect = '\xab\xea'
result = urllib.unquote(given)
self.assertEqual(expect, result, "using unquote(): %r != %r"
% (expect, result))
def test_unquoting_parts(self):
# Make sure unquoting works when have non-quoted characters
# interspersed
given = 'ab%sd' % hexescape('c')
expect = "abcd"
result = urllib.unquote(given)
self.assertEqual(expect, result,
"using quote(): %s != %s" % (expect, result))
result = urllib.unquote_plus(given)
self.assertEqual(expect, result,
"using unquote_plus(): %s != %s" % (expect, result))
def test_unquoting_plus(self):
# Test difference between unquote() and unquote_plus()
given = "are+there+spaces..."
expect = given
result = urllib.unquote(given)
self.assertEqual(expect, result,
"using unquote(): %s != %s" % (expect, result))
expect = given.replace('+', ' ')
result = urllib.unquote_plus(given)
self.assertEqual(expect, result,
"using unquote_plus(): %s != %s" % (expect, result))
def test_unquote_with_unicode(self):
r = urllib.unquote(u'br%C3%BCckner_sapporo_20050930.doc')
self.assertEqual(r, u'br\xc3\xbcckner_sapporo_20050930.doc')
class urlencode_Tests(unittest.TestCase):
"""Tests for urlencode()"""
def help_inputtype(self, given, test_type):
"""Helper method for testing different input types.
'given' must lead to only the pairs:
* 1st, 1
* 2nd, 2
* 3rd, 3
Test cannot assume anything about order. Docs make no guarantee and
have possible dictionary input.
"""
expect_somewhere = ["1st=1", "2nd=2", "3rd=3"]
result = urllib.urlencode(given)
for expected in expect_somewhere:
self.assertIn(expected, result,
"testing %s: %s not found in %s" %
(test_type, expected, result))
self.assertEqual(result.count('&'), 2,
"testing %s: expected 2 '&'s; got %s" %
(test_type, result.count('&')))
amp_location = result.index('&')
on_amp_left = result[amp_location - 1]
on_amp_right = result[amp_location + 1]
self.assertTrue(on_amp_left.isdigit() and on_amp_right.isdigit(),
"testing %s: '&' not located in proper place in %s" %
(test_type, result))
self.assertEqual(len(result), (5 * 3) + 2, #5 chars per thing and amps
"testing %s: "
"unexpected number of characters: %s != %s" %
(test_type, len(result), (5 * 3) + 2))
def test_using_mapping(self):
# Test passing in a mapping object as an argument.
self.help_inputtype({"1st":'1', "2nd":'2', "3rd":'3'},
"using dict as input type")
def test_using_sequence(self):
# Test passing in a sequence of two-item sequences as an argument.
self.help_inputtype([('1st', '1'), ('2nd', '2'), ('3rd', '3')],
"using sequence of two-item tuples as input")
def test_quoting(self):
# Make sure keys and values are quoted using quote_plus()
given = {"&":"="}
expect = "%s=%s" % (hexescape('&'), hexescape('='))
result = urllib.urlencode(given)
self.assertEqual(expect, result)
given = {"key name":"A bunch of pluses"}
expect = "key+name=A+bunch+of+pluses"
result = urllib.urlencode(given)
self.assertEqual(expect, result)
def test_doseq(self):
# Test that passing True for 'doseq' parameter works correctly
given = {'sequence':['1', '2', '3']}
expect = "sequence=%s" % urllib.quote_plus(str(['1', '2', '3']))
result = urllib.urlencode(given)
self.assertEqual(expect, result)
result = urllib.urlencode(given, True)
for value in given["sequence"]:
expect = "sequence=%s" % value
self.assertIn(expect, result)
self.assertEqual(result.count('&'), 2,
"Expected 2 '&'s, got %s" % result.count('&'))
class Pathname_Tests(unittest.TestCase):
"""Test pathname2url() and url2pathname()"""
def test_basic(self):
# Make sure simple tests pass
expected_path = os.path.join("parts", "of", "a", "path")
expected_url = "parts/of/a/path"
result = urllib.pathname2url(expected_path)
self.assertEqual(expected_url, result,
"pathname2url() failed; %s != %s" %
(result, expected_url))
result = urllib.url2pathname(expected_url)
self.assertEqual(expected_path, result,
"url2pathame() failed; %s != %s" %
(result, expected_path))
def test_quoting(self):
# Test automatic quoting and unquoting works for pathnam2url() and
# url2pathname() respectively
given = os.path.join("needs", "quot=ing", "here")
expect = "needs/%s/here" % urllib.quote("quot=ing")
result = urllib.pathname2url(given)
self.assertEqual(expect, result,
"pathname2url() failed; %s != %s" %
(expect, result))
expect = given
result = urllib.url2pathname(result)
self.assertEqual(expect, result,
"url2pathname() failed; %s != %s" %
(expect, result))
given = os.path.join("make sure", "using_quote")
expect = "%s/using_quote" % urllib.quote("make sure")
result = urllib.pathname2url(given)
self.assertEqual(expect, result,
"pathname2url() failed; %s != %s" %
(expect, result))
given = "make+sure/using_unquote"
expect = os.path.join("make+sure", "using_unquote")
result = urllib.url2pathname(given)
self.assertEqual(expect, result,
"url2pathname() failed; %s != %s" %
(expect, result))
@unittest.skipUnless(sys.platform == 'win32',
'test specific to the nturl2path library')
def test_ntpath(self):
given = ('/C:/', '///C:/', '/C|//')
expect = 'C:\\'
for url in given:
result = urllib.url2pathname(url)
self.assertEqual(expect, result,
'nturl2path.url2pathname() failed; %s != %s' %
(expect, result))
given = '///C|/path'
expect = 'C:\\path'
result = urllib.url2pathname(given)
self.assertEqual(expect, result,
'nturl2path.url2pathname() failed; %s != %s' %
(expect, result))
class Utility_Tests(unittest.TestCase):
"""Testcase to test the various utility functions in the urllib."""
def test_splitpasswd(self):
"""Some of the password examples are not sensible, but it is added to
confirming to RFC2617 and addressing issue4675.
"""
self.assertEqual(('user', 'ab'),urllib.splitpasswd('user:ab'))
self.assertEqual(('user', 'a\nb'),urllib.splitpasswd('user:a\nb'))
self.assertEqual(('user', 'a\tb'),urllib.splitpasswd('user:a\tb'))
self.assertEqual(('user', 'a\rb'),urllib.splitpasswd('user:a\rb'))
self.assertEqual(('user', 'a\fb'),urllib.splitpasswd('user:a\fb'))
self.assertEqual(('user', 'a\vb'),urllib.splitpasswd('user:a\vb'))
self.assertEqual(('user', 'a:b'),urllib.splitpasswd('user:a:b'))
self.assertEqual(('user', 'a b'),urllib.splitpasswd('user:a b'))
self.assertEqual(('user 2', 'ab'),urllib.splitpasswd('user 2:ab'))
self.assertEqual(('user+1', 'a+b'),urllib.splitpasswd('user+1:a+b'))
class URLopener_Tests(unittest.TestCase):
"""Testcase to test the open method of URLopener class."""
def test_quoted_open(self):
class DummyURLopener(urllib.URLopener):
def open_spam(self, url):
return url
self.assertEqual(DummyURLopener().open(
'spam://example/ /'),'//example/%20/')
# test the safe characters are not quoted by urlopen
self.assertEqual(DummyURLopener().open(
"spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"),
"//c:|windows%/:=&?~#+!$,;'@()*[]|/path/")
# Just commented them out.
# Can't really tell why keep failing in windows and sparc.
# Everywhere else they work ok, but on those machines, sometimes
# fail in one of the tests, sometimes in other. I have a linux, and
# the tests go ok.
# If anybody has one of the problematic enviroments, please help!
# . Facundo
#
# def server(evt):
# import socket, time
# serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# serv.settimeout(3)
# serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# serv.bind(("", 9093))
# serv.listen(5)
# try:
# conn, addr = serv.accept()
# conn.send("1 Hola mundo\n")
# cantdata = 0
# while cantdata < 13:
# data = conn.recv(13-cantdata)
# cantdata += len(data)
# time.sleep(.3)
# conn.send("2 No more lines\n")
# conn.close()
# except socket.timeout:
# pass
# finally:
# serv.close()
# evt.set()
#
# class FTPWrapperTests(unittest.TestCase):
#
# def setUp(self):
# import ftplib, time, threading
# ftplib.FTP.port = 9093
# self.evt = threading.Event()
# threading.Thread(target=server, args=(self.evt,)).start()
# time.sleep(.1)
#
# def tearDown(self):
# self.evt.wait()
#
# def testBasic(self):
# # connects
# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
# ftp.close()
#
# def testTimeoutNone(self):
# # global default timeout is ignored
# import socket
# self.assertTrue(socket.getdefaulttimeout() is None)
# socket.setdefaulttimeout(30)
# try:
# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
# finally:
# socket.setdefaulttimeout(None)
# self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
# ftp.close()
#
# def testTimeoutDefault(self):
# # global default timeout is used
# import socket
# self.assertTrue(socket.getdefaulttimeout() is None)
# socket.setdefaulttimeout(30)
# try:
# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [])
# finally:
# socket.setdefaulttimeout(None)
# self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
# ftp.close()
#
# def testTimeoutValue(self):
# ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [],
# timeout=30)
# self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
# ftp.close()
def test_main():
import warnings
with warnings.catch_warnings():
warnings.filterwarnings('ignore', ".*urllib\.urlopen.*Python 3.0",
DeprecationWarning)
test_support.run_unittest(
urlopen_FileTests,
urlopen_HttpTests,
urlretrieve_FileTests,
urlretrieve_HttpTests,
ProxyTests,
QuotingTests,
UnquotingTests,
urlencode_Tests,
Pathname_Tests,
Utility_Tests,
URLopener_Tests,
#FTPWrapperTests,
)
if __name__ == '__main__':
test_main()
|
lgpl-3.0
|
[
624,
2872,
753,
438,
2295,
367,
4011,
624,
199,
199,
646,
4011,
199,
646,
8809,
199,
646,
2882,
199,
646,
747,
199,
646,
984,
199,
646,
6660,
2537,
199,
646,
5549,
199,
646,
5228,
199,
199,
504,
511,
492,
511,
63,
4058,
199,
504,
1300,
772,
492,
330,
772,
2143,
421,
199,
318,
6318,
3765,
8,
1560,
304,
272,
408,
10260,
1495,
465,
7329,
499,
13443,
9314,
624,
272,
6318,
63,
2722,
275,
6318,
8,
2181,
8,
1560,
11515,
18,
11455,
4142,
342,
272,
340,
822,
8,
4097,
63,
2722,
9,
508,
413,
26,
267,
6318,
63,
2722,
275,
298,
16,
5,
83,
2,
450,
6318,
63,
2722,
272,
372,
2071,
2,
435,
6318,
63,
2722,
421,
199,
533,
7777,
2856,
4256,
8,
785,
304,
272,
347,
4026,
1014,
8,
277,
12,
289,
16702,
419,
304,
267,
1021,
7777,
3869,
8,
6424,
14,
6424,
304,
953,
347,
3222,
452,
8,
277,
12,
666,
304,
355,
7777,
19114,
14,
1436,
275,
666,
953,
347,
16818,
8,
277,
12,
627,
589,
12,
1011,
10340,
304,
355,
372,
291,
953,
347,
1586,
8,
277,
12,
23486,
29,
403,
304,
355,
340,
291,
14,
5938,
26,
490,
372,
3087,
355,
372,
5228,
14,
6424,
14,
739,
8,
277,
12,
23486,
9,
953,
347,
14441,
8,
277,
12,
2582,
29,
403,
304,
355,
340,
291,
14,
5938,
26,
490,
372,
3087,
355,
372,
5228,
14,
6424,
14,
6407,
8,
277,
12,
2582,
9,
398,
1021,
7777,
19114,
8,
12942,
14,
19114,
304,
953,
327,
3335,
370,
3877,
666,
367,
14786,
315,
18279,
2295,
14,
288,
4123,
275,
3087,
953,
347,
4907,
8,
277,
304,
355,
291,
14,
5096,
275,
7777,
3869,
8,
667,
25503,
419,
9,
398,
702,
8809,
14,
2856,
423,
2105,
63,
533,
508,
8809,
14,
19114,
398,
8809,
14,
2856,
423,
2105,
63,
533,
275,
7777,
19114,
339,
347,
625,
3183,
1014,
8,
277,
304,
267,
8809,
14,
2856,
423,
2105,
63,
533,
275,
8809,
14,
19114,
421,
199,
533,
18279,
63,
1173,
2925,
8,
2796,
14,
1746,
304,
272,
408,
774,
18279,
342,
13618,
282,
7937,
570,
14,
339,
7649,
370,
511,
465,
8298,
9330,
465,
3962,
880,
465,
370,
10415,
3224,
641,
295,
3636,
272,
641,
18170,
370,
314,
5365,
367,
5343,
14,
339,
408,
339,
347,
3613,
8,
277,
304,
267,
408,
8555,
402,
282,
2388,
570,
370,
675,
367,
5343,
624,
267,
291,
14,
505,
275,
298,
396,
63,
4078,
26,
450,
83,
60,
78,
2,
450,
291,
855,
533,
4914,
354,
363,
267,
13024,
275,
570,
8,
396,
63,
4058,
14,
10179,
12,
283,
6603,
358,
267,
862,
26,
288,
13024,
14,
952,
8,
277,
14,
505,
9,
267,
3753,
26,
288,
13024,
14,
1600,
342,
267,
291,
14,
12445,
275,
511,
63,
4058,
14,
10179,
267,
291,
14,
19065,
63,
1113,
275,
4011,
14,
10890,
480,
493,
2689,
83,
2,
450,
291,
14,
12445,
9,
339,
347,
6766,
8,
277,
304,
267,
408,
2662,
337,
3224,
314,
1551,
909,
624,
267,
291,
14,
19065,
63,
1113,
14,
1600,
342,
267,
747,
14,
2168,
8,
396,
63,
4058,
14,
10179,
9,
339,
347,
511,
63,
3266,
8,
277,
304,
267,
327,
4155,
3238,
909,
2138,
701,
18279,
342,
965,
314,
2013,
3102,
267,
367,
1921,
315,
1689,
739,
401,
298,
6407,
401,
298,
9684,
401,
298,
9843,
401,
2151,
298,
1600,
401,
298,
815,
401,
298,
32130,
401,
298,
362,
600,
401,
4396,
1661,
363,
2349,
288,
291,
14,
1815,
8,
11161,
8,
277,
14,
19065,
63,
1113,
12,
1921,
395,
586,
298,
785,
2138,
701,
18279,
342,
1127,
5618,
450,
83,
2225,
2,
450,
586,
1921,
9,
339,
347,
511,
63,
739,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
505,
12,
291,
14,
19065,
63,
1113,
14,
739,
1012,
339,
347,
511,
63,
6407,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
505,
12,
291,
14,
19065,
63,
1113,
14,
6407,
1012,
267,
291,
14,
629,
8594,
291,
14,
19065,
63,
1113,
14,
6407,
1062,
586,
298,
25566,
14441,
342,
2410,
21354,
833,
316,
314,
570,
8103,
440,
2,
586,
298,
372,
376,
2701,
1059,
531,
339,
347,
511,
63,
9684,
8,
277,
304,
267,
2385,
63,
513,
275,
291,
14,
19065,
63,
1113,
14,
9684,
342,
267,
291,
14,
629,
8,
552,
8,
1278,
63,
513,
395,
413,
12,
586,
298,
9684,
342,
2138,
314,
6835,
1329,
402,
2385,
531,
267,
291,
14,
629,
8,
1278,
63,
513,
59,
16,
467,
291,
14,
505,
12,
586,
298,
9684,
342,
2138,
1742,
9198,
1318,
531,
339,
347,
511,
63,
9843,
8,
277,
304,
267,
570,
63,
1507,
275,
291,
14,
19065,
63,
1113,
14,
9843,
342,
267,
291,
14,
6926,
8,
493,
63,
1507,
12,
1109,
12,
298,
9843,
342,
8103,
440,
372,
376,
1109,
531,
267,
291,
14,
629,
8,
736,
14,
739,
8,
493,
63,
1507,
12,
822,
8,
277,
14,
505,
1826,
291,
14,
505,
12,
586,
298,
20568,
641,
314,
570,
5872,
2138,
701,
25255,
342,
298,
586,
298,
14887,
440,
372,
314,
1420,
1318,
531,
339,
347,
511,
63,
1600,
8,
277,
304,
267,
327,
1379,
4002,
342,
701,
6358,
652,
946,
285,
436,
2066,
9445,
652,
506,
2797,
4020,
267,
327,
701,
314,
6766,
342,
1083,
367,
314,
511,
267,
291,
14,
19065,
63,
1113,
14,
1600,
342,
339,
347,
511,
63,
815,
8,
277,
304,
267,
291,
14,
6926,
8,
277,
14,
19065,
63,
1113,
14,
815,
1062,
6660,
2537,
14,
2209,
9,
339,
347,
511,
63,
32130,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
19065,
63,
1113,
14,
32130,
1062,
291,
14,
12445,
9,
339,
347,
511,
63,
362,
600,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
19065,
63,
1113,
14,
362,
600,
1062,
488,
9,
339,
347,
511,
63,
1661,
8,
277,
304,
267,
327,
1379,
6122,
267,
327,
7529,
1133,
1929,
370,
2338,
1329,
402,
10615,
3967,
511,
3955,
2449,
314,
267,
327,
2727,
867,
652,
2138,
7003,
20561,
314,
1642,
1004,
687,
314,
267,
327,
9132,
267,
367,
1004,
315,
291,
14,
19065,
63,
1113,
855,
1661,
721,
304,
288,
291,
14,
629,
8,
604,
12,
291,
14
] |
[
2872,
753,
438,
2295,
367,
4011,
624,
199,
199,
646,
4011,
199,
646,
8809,
199,
646,
2882,
199,
646,
747,
199,
646,
984,
199,
646,
6660,
2537,
199,
646,
5549,
199,
646,
5228,
199,
199,
504,
511,
492,
511,
63,
4058,
199,
504,
1300,
772,
492,
330,
772,
2143,
421,
199,
318,
6318,
3765,
8,
1560,
304,
272,
408,
10260,
1495,
465,
7329,
499,
13443,
9314,
624,
272,
6318,
63,
2722,
275,
6318,
8,
2181,
8,
1560,
11515,
18,
11455,
4142,
342,
272,
340,
822,
8,
4097,
63,
2722,
9,
508,
413,
26,
267,
6318,
63,
2722,
275,
298,
16,
5,
83,
2,
450,
6318,
63,
2722,
272,
372,
2071,
2,
435,
6318,
63,
2722,
421,
199,
533,
7777,
2856,
4256,
8,
785,
304,
272,
347,
4026,
1014,
8,
277,
12,
289,
16702,
419,
304,
267,
1021,
7777,
3869,
8,
6424,
14,
6424,
304,
953,
347,
3222,
452,
8,
277,
12,
666,
304,
355,
7777,
19114,
14,
1436,
275,
666,
953,
347,
16818,
8,
277,
12,
627,
589,
12,
1011,
10340,
304,
355,
372,
291,
953,
347,
1586,
8,
277,
12,
23486,
29,
403,
304,
355,
340,
291,
14,
5938,
26,
490,
372,
3087,
355,
372,
5228,
14,
6424,
14,
739,
8,
277,
12,
23486,
9,
953,
347,
14441,
8,
277,
12,
2582,
29,
403,
304,
355,
340,
291,
14,
5938,
26,
490,
372,
3087,
355,
372,
5228,
14,
6424,
14,
6407,
8,
277,
12,
2582,
9,
398,
1021,
7777,
19114,
8,
12942,
14,
19114,
304,
953,
327,
3335,
370,
3877,
666,
367,
14786,
315,
18279,
2295,
14,
288,
4123,
275,
3087,
953,
347,
4907,
8,
277,
304,
355,
291,
14,
5096,
275,
7777,
3869,
8,
667,
25503,
419,
9,
398,
702,
8809,
14,
2856,
423,
2105,
63,
533,
508,
8809,
14,
19114,
398,
8809,
14,
2856,
423,
2105,
63,
533,
275,
7777,
19114,
339,
347,
625,
3183,
1014,
8,
277,
304,
267,
8809,
14,
2856,
423,
2105,
63,
533,
275,
8809,
14,
19114,
421,
199,
533,
18279,
63,
1173,
2925,
8,
2796,
14,
1746,
304,
272,
408,
774,
18279,
342,
13618,
282,
7937,
570,
14,
339,
7649,
370,
511,
465,
8298,
9330,
465,
3962,
880,
465,
370,
10415,
3224,
641,
295,
3636,
272,
641,
18170,
370,
314,
5365,
367,
5343,
14,
339,
408,
339,
347,
3613,
8,
277,
304,
267,
408,
8555,
402,
282,
2388,
570,
370,
675,
367,
5343,
624,
267,
291,
14,
505,
275,
298,
396,
63,
4078,
26,
450,
83,
60,
78,
2,
450,
291,
855,
533,
4914,
354,
363,
267,
13024,
275,
570,
8,
396,
63,
4058,
14,
10179,
12,
283,
6603,
358,
267,
862,
26,
288,
13024,
14,
952,
8,
277,
14,
505,
9,
267,
3753,
26,
288,
13024,
14,
1600,
342,
267,
291,
14,
12445,
275,
511,
63,
4058,
14,
10179,
267,
291,
14,
19065,
63,
1113,
275,
4011,
14,
10890,
480,
493,
2689,
83,
2,
450,
291,
14,
12445,
9,
339,
347,
6766,
8,
277,
304,
267,
408,
2662,
337,
3224,
314,
1551,
909,
624,
267,
291,
14,
19065,
63,
1113,
14,
1600,
342,
267,
747,
14,
2168,
8,
396,
63,
4058,
14,
10179,
9,
339,
347,
511,
63,
3266,
8,
277,
304,
267,
327,
4155,
3238,
909,
2138,
701,
18279,
342,
965,
314,
2013,
3102,
267,
367,
1921,
315,
1689,
739,
401,
298,
6407,
401,
298,
9684,
401,
298,
9843,
401,
2151,
298,
1600,
401,
298,
815,
401,
298,
32130,
401,
298,
362,
600,
401,
4396,
1661,
363,
2349,
288,
291,
14,
1815,
8,
11161,
8,
277,
14,
19065,
63,
1113,
12,
1921,
395,
586,
298,
785,
2138,
701,
18279,
342,
1127,
5618,
450,
83,
2225,
2,
450,
586,
1921,
9,
339,
347,
511,
63,
739,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
505,
12,
291,
14,
19065,
63,
1113,
14,
739,
1012,
339,
347,
511,
63,
6407,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
505,
12,
291,
14,
19065,
63,
1113,
14,
6407,
1012,
267,
291,
14,
629,
8594,
291,
14,
19065,
63,
1113,
14,
6407,
1062,
586,
298,
25566,
14441,
342,
2410,
21354,
833,
316,
314,
570,
8103,
440,
2,
586,
298,
372,
376,
2701,
1059,
531,
339,
347,
511,
63,
9684,
8,
277,
304,
267,
2385,
63,
513,
275,
291,
14,
19065,
63,
1113,
14,
9684,
342,
267,
291,
14,
629,
8,
552,
8,
1278,
63,
513,
395,
413,
12,
586,
298,
9684,
342,
2138,
314,
6835,
1329,
402,
2385,
531,
267,
291,
14,
629,
8,
1278,
63,
513,
59,
16,
467,
291,
14,
505,
12,
586,
298,
9684,
342,
2138,
1742,
9198,
1318,
531,
339,
347,
511,
63,
9843,
8,
277,
304,
267,
570,
63,
1507,
275,
291,
14,
19065,
63,
1113,
14,
9843,
342,
267,
291,
14,
6926,
8,
493,
63,
1507,
12,
1109,
12,
298,
9843,
342,
8103,
440,
372,
376,
1109,
531,
267,
291,
14,
629,
8,
736,
14,
739,
8,
493,
63,
1507,
12,
822,
8,
277,
14,
505,
1826,
291,
14,
505,
12,
586,
298,
20568,
641,
314,
570,
5872,
2138,
701,
25255,
342,
298,
586,
298,
14887,
440,
372,
314,
1420,
1318,
531,
339,
347,
511,
63,
1600,
8,
277,
304,
267,
327,
1379,
4002,
342,
701,
6358,
652,
946,
285,
436,
2066,
9445,
652,
506,
2797,
4020,
267,
327,
701,
314,
6766,
342,
1083,
367,
314,
511,
267,
291,
14,
19065,
63,
1113,
14,
1600,
342,
339,
347,
511,
63,
815,
8,
277,
304,
267,
291,
14,
6926,
8,
277,
14,
19065,
63,
1113,
14,
815,
1062,
6660,
2537,
14,
2209,
9,
339,
347,
511,
63,
32130,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
19065,
63,
1113,
14,
32130,
1062,
291,
14,
12445,
9,
339,
347,
511,
63,
362,
600,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
19065,
63,
1113,
14,
362,
600,
1062,
488,
9,
339,
347,
511,
63,
1661,
8,
277,
304,
267,
327,
1379,
6122,
267,
327,
7529,
1133,
1929,
370,
2338,
1329,
402,
10615,
3967,
511,
3955,
2449,
314,
267,
327,
2727,
867,
652,
2138,
7003,
20561,
314,
1642,
1004,
687,
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
] |
omakk/servo
|
etc/patch-trace-template.py
|
113
|
3376
|
#!/usr/bin/env python
# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
import re
import subprocess
import sys
from xml.etree import ElementTree
from xml.etree.ElementTree import Element
if len(sys.argv) < 3:
sys.stderr.write("""usage: patch-trace-template.py components/profile_traits/time.rs path/to/my.tracetemplate
`time.rs` is usually located in `components/profile_traits/time.rs`.
Trace templates are typically located in `~/Library/Application Support/Instruments/Templates`.
The supplied trace template must contain the "Points of Interest" instrument.
Output is written to standard output and should typically be piped to a new `.tracetemplate` file.
Example:
patch-trace-template.py \\
components/profile_traits/time.rs \\
~/Library/Application\\ Support/Instruments/Templates/MyTemplate.tracetemplate > \\
~/Library/Application\\ Support/Instruments/Templates/MyServoTemplate.tracetemplate
""")
sys.exit(0)
rust_source = open(sys.argv[1], 'r')
lines = iter(rust_source)
for line in lines:
if line.lstrip().startswith("pub enum ProfilerCategory"):
break
code_pairs = []
regex = re.compile(r"\s*(\w+)\s*=\s*([0-9]+|0x[a-fA-F0-9]+),?\s*$")
for line in lines:
if line.lstrip().startswith("}"):
break
match = regex.match(line)
if match is None:
continue
code_pairs.append((match.group(2), match.group(1)))
xml = subprocess.check_output(["plutil", "-convert", "xml1", "-o", "-", sys.argv[2]])
plist = ElementTree.ElementTree(ElementTree.fromstring(xml))
elems = iter(plist.findall("./dict/*"))
for elem in elems:
if elem.tag != 'key' or elem.text != '$objects':
continue
array = elems.next()
break
elems = iter(array.findall("./*"))
for elem in elems:
if elem.tag != 'string' or elem.text != 'kdebugIntervalRule':
continue
dictionary = elems.next()
break
elems = iter(dictionary.findall("./*"))
for elem in elems:
if elem.tag != 'key' or elem.text != 'NS.objects':
continue
objects_array = elems.next()
break
child_count = sum(1 for _ in iter(array.findall("./*")))
for code_pair in code_pairs:
number_index = child_count
integer = Element('integer')
integer.text = str(int(code_pair[0], 0))
array.append(integer)
child_count += 1
string_index = child_count
string = Element('string')
string.text = code_pair[1]
array.append(string)
child_count += 1
dictionary = Element('dict')
key = Element('key')
key.text = "CF$UID"
dictionary.append(key)
integer = Element('integer')
integer.text = str(number_index)
dictionary.append(integer)
objects_array.append(dictionary)
dictionary = Element('dict')
key = Element('key')
key.text = "CF$UID"
dictionary.append(key)
integer = Element('integer')
integer.text = str(string_index)
dictionary.append(integer)
objects_array.append(dictionary)
plist.write(sys.stdout, encoding='utf-8', xml_declaration=True)
|
mpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6171,
710,
3739,
2392,
7290,
23493,
14,
1666,
314,
5877,
199,
3,
570,
737,
314,
2746,
13,
1896,
2082,
402,
642,
4084,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
665,
3961,
13,
1282,
33,
4576,
503,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
30,
503,
314,
10697,
4190,
199,
3,
665,
3961,
13,
13965,
503,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
6244,
737,
2195,
199,
3,
945,
14,
961,
570,
1443,
440,
506,
8876,
12,
6042,
12,
503,
1854,
199,
3,
871,
7182,
370,
5204,
2895,
14,
199,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
504,
2748,
14,
9464,
492,
13139,
199,
504,
2748,
14,
9464,
14,
15325,
492,
6566,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
665,
650,
26,
272,
984,
14,
3083,
14,
952,
4852,
3807,
26,
3371,
13,
3446,
13,
1160,
14,
647,
7323,
15,
2913,
63,
17668,
15,
521,
14,
2393,
931,
15,
475,
15,
1662,
14,
3446,
1160,
199,
199,
64,
521,
14,
2393,
64,
365,
9987,
16180,
315,
658,
4608,
15,
2913,
63,
17668,
15,
521,
14,
2393,
2313,
199,
3921,
7009,
787,
13609,
16180,
315,
28157,
15,
7424,
15,
5039,
12502,
15,
14915,
83,
15,
17969,
2313,
199,
1918,
6841,
3307,
1978,
1471,
1395,
314,
298,
10225,
402,
8883,
3911,
2,
14498,
14,
199,
2959,
365,
5313,
370,
4465,
1072,
436,
1077,
13609,
506,
6682,
1915,
370,
282,
892,
19853,
3446,
1160,
64,
570,
14,
199,
199,
9846,
26,
272,
3371,
13,
3446,
13,
1160,
14,
647,
8522,
272,
7323,
15,
2913,
63,
17668,
15,
521,
14,
2393,
8522,
267,
6146,
15,
7424,
15,
5039,
1103,
12502,
15,
14915,
83,
15,
17969,
15,
5713,
4231,
14,
3446,
1160,
690,
8522,
267,
6146,
15,
7424,
15,
5039,
1103,
12502,
15,
14915,
83,
15,
17969,
15,
5713,
1505,
2392,
4231,
14,
3446,
1160,
199,
6141,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
19622,
63,
1365,
275,
1551,
8,
1274,
14,
3020,
59,
17,
467,
283,
82,
358,
199,
1278,
275,
2740,
8,
19622,
63,
1365,
9,
199,
509,
1004,
315,
2385,
26,
272,
340,
1004,
14,
10124,
1252,
2460,
480,
5645,
4952,
14386,
82,
7841,
2349,
267,
2059,
199,
199,
600,
63,
7322,
275,
942,
199,
3821,
275,
295,
14,
2014,
8,
82,
3212,
83,
22588,
87,
13439,
83,
23440,
83,
10,
779,
16,
13,
25,
2807,
92,
16,
88,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
2807,
395,
8995,
83,
10,
22550,
199,
509,
1004,
315,
2385,
26,
272,
340,
1004,
14,
10124,
1252,
2460,
480,
93,
2349,
267,
2059,
339,
1336,
275,
5163,
14,
1431,
8,
604,
9,
272,
340,
1336,
365,
488,
26,
267,
1980,
272,
1233,
63,
7322,
14,
740,
1332,
1431,
14,
923,
8,
18,
395,
1336,
14,
923,
8,
17,
1724,
199,
199,
1652,
275,
3873,
14,
1074,
63,
1199,
5234,
1168,
1974,
401,
3905,
3916,
401,
298,
1652,
17,
401,
3905,
79,
401,
3905,
401,
984,
14,
3020,
59,
18,
3934,
199,
10265,
275,
13139,
14,
15325,
8,
15325,
14,
13521,
8,
1652,
430,
199,
199,
17482,
275,
2740,
8,
10265,
14,
6452,
28615,
807,
6331,
2237,
199,
509,
6193,
315,
20840,
26,
272,
340,
6193,
14,
1450,
1137,
283,
498,
7,
503,
6193,
14,
505,
1137,
4505,
1462,
356,
267,
1980,
272,
1625,
275,
20840,
14,
2184,
342,
272,
2059,
199,
199,
17482,
275,
2740,
8,
1144,
14,
6452,
9520,
6331,
2237,
199,
509,
6193,
315,
20840,
26,
272,
340,
6193,
14,
1450,
1137,
283,
875,
7,
503,
6193,
14,
505,
1137,
283,
75,
1757,
8227,
5065,
356,
267,
1980,
272,
2600,
275,
20840,
14,
2184,
342,
272,
2059,
199,
199,
17482,
275,
2740,
8,
9086,
14,
6452,
9520,
6331,
2237,
199,
509,
6193,
315,
20840,
26,
272,
340,
6193,
14,
1450,
1137,
283,
498,
7,
503,
6193,
14,
505,
1137,
283,
2709,
14,
1462,
356,
267,
1980,
272,
2251,
63,
1144,
275,
20840,
14,
2184,
342,
272,
2059,
199,
199,
1739,
63,
835,
275,
3089,
8,
17,
367,
485,
315,
2740,
8,
1144,
14,
6452,
9520,
6331,
13324,
199,
199,
509,
1233,
63,
3852,
315,
1233,
63,
7322,
26,
272,
1329,
63,
1080,
275,
1982,
63,
835,
272,
3000,
275,
6566,
360,
4115,
358,
272,
3000,
14,
505,
275,
620,
8,
442,
8,
600,
63,
3852,
59,
16,
467,
378,
430,
272,
1625,
14,
740,
8,
4115,
9,
272,
1982,
63,
835,
847,
413,
339,
1059,
63,
1080,
275,
1982,
63,
835,
272,
1059,
275,
6566,
360,
875,
358,
272,
1059,
14,
505,
275,
1233,
63,
3852,
59,
17,
61,
272,
1625,
14,
740,
8,
875,
9,
272,
1982,
63,
835,
847,
413,
339,
2600,
275,
6566,
360,
807,
358,
272,
790,
275,
6566,
360,
498,
358,
272,
790,
14,
505,
275,
298,
5487,
4,
6685,
2,
272,
2600,
14,
740,
8,
498,
9,
272,
3000,
275,
6566,
360,
4115,
358,
272,
3000,
14,
505,
275,
620,
8,
1955,
63,
1080,
9,
272,
2600,
14,
740,
8,
4115,
9,
272,
2251,
63,
1144,
14,
740,
8,
9086,
9,
339,
2600,
275,
6566,
360,
807,
358,
272,
790,
275,
6566,
360,
498,
358,
272,
790,
14,
505,
275,
298,
5487,
4,
6685,
2,
272,
2600,
14,
740,
8,
498,
9,
272,
3000,
275,
6566,
360,
4115,
358,
272,
3000,
14,
505,
275,
620,
8,
875,
63,
1080,
9,
272,
2600,
14,
740,
8,
4115,
9,
272,
2251,
63,
1144,
14,
740,
8,
9086,
9,
199,
199,
10265,
14,
952,
8,
1274,
14,
2703,
12,
2644,
534,
1624,
13,
24,
297,
2748,
63,
15477,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6171,
710,
3739,
2392,
7290,
23493,
14,
1666,
314,
5877,
199,
3,
570,
737,
314,
2746,
13,
1896,
2082,
402,
642,
4084,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
665,
3961,
13,
1282,
33,
4576,
503,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
30,
503,
314,
10697,
4190,
199,
3,
665,
3961,
13,
13965,
503,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
6244,
737,
2195,
199,
3,
945,
14,
961,
570,
1443,
440,
506,
8876,
12,
6042,
12,
503,
1854,
199,
3,
871,
7182,
370,
5204,
2895,
14,
199,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
504,
2748,
14,
9464,
492,
13139,
199,
504,
2748,
14,
9464,
14,
15325,
492,
6566,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
665,
650,
26,
272,
984,
14,
3083,
14,
952,
4852,
3807,
26,
3371,
13,
3446,
13,
1160,
14,
647,
7323,
15,
2913,
63,
17668,
15,
521,
14,
2393,
931,
15,
475,
15,
1662,
14,
3446,
1160,
199,
199,
64,
521,
14,
2393,
64,
365,
9987,
16180,
315,
658,
4608,
15,
2913,
63,
17668,
15,
521,
14,
2393,
2313,
199,
3921,
7009,
787,
13609,
16180,
315,
28157,
15,
7424,
15,
5039,
12502,
15,
14915,
83,
15,
17969,
2313,
199,
1918,
6841,
3307,
1978,
1471,
1395,
314,
298,
10225,
402,
8883,
3911,
2,
14498,
14,
199,
2959,
365,
5313,
370,
4465,
1072,
436,
1077,
13609,
506,
6682,
1915,
370,
282,
892,
19853,
3446,
1160,
64,
570,
14,
199,
199,
9846,
26,
272,
3371,
13,
3446,
13,
1160,
14,
647,
8522,
272,
7323,
15,
2913,
63,
17668,
15,
521,
14,
2393,
8522,
267,
6146,
15,
7424,
15,
5039,
1103,
12502,
15,
14915,
83,
15,
17969,
15,
5713,
4231,
14,
3446,
1160,
690,
8522,
267,
6146,
15,
7424,
15,
5039,
1103,
12502,
15,
14915,
83,
15,
17969,
15,
5713,
1505,
2392,
4231,
14,
3446,
1160,
199,
6141,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
19622,
63,
1365,
275,
1551,
8,
1274,
14,
3020,
59,
17,
467,
283,
82,
358,
199,
1278,
275,
2740,
8,
19622,
63,
1365,
9,
199,
509,
1004,
315,
2385,
26,
272,
340,
1004,
14,
10124,
1252,
2460,
480,
5645,
4952,
14386,
82,
7841,
2349,
267,
2059,
199,
199,
600,
63,
7322,
275,
942,
199,
3821,
275,
295,
14,
2014,
8,
82,
3212,
83,
22588,
87,
13439,
83,
23440,
83,
10,
779,
16,
13,
25,
2807,
92,
16,
88,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
2807,
395,
8995,
83,
10,
22550,
199,
509,
1004,
315,
2385,
26,
272,
340,
1004,
14,
10124,
1252,
2460,
480,
93,
2349,
267,
2059,
339,
1336,
275,
5163,
14,
1431,
8,
604,
9,
272,
340,
1336,
365,
488,
26,
267,
1980,
272,
1233,
63,
7322,
14,
740,
1332,
1431,
14,
923,
8,
18,
395,
1336,
14,
923,
8,
17,
1724,
199,
199,
1652,
275,
3873,
14,
1074,
63,
1199,
5234,
1168,
1974,
401,
3905,
3916,
401,
298,
1652,
17,
401,
3905,
79,
401,
3905,
401,
984,
14,
3020,
59,
18,
3934,
199,
10265,
275,
13139,
14,
15325,
8,
15325,
14,
13521,
8,
1652,
430,
199,
199,
17482,
275,
2740,
8,
10265,
14,
6452,
28615,
807,
6331,
2237,
199,
509,
6193,
315,
20840,
26,
272,
340,
6193,
14,
1450,
1137,
283,
498,
7,
503,
6193,
14,
505,
1137,
4505,
1462,
356,
267,
1980,
272,
1625,
275,
20840,
14,
2184,
342,
272,
2059,
199,
199,
17482,
275,
2740,
8,
1144,
14,
6452,
9520,
6331,
2237,
199,
509,
6193,
315,
20840,
26,
272,
340,
6193,
14,
1450,
1137,
283,
875,
7,
503,
6193,
14,
505,
1137,
283,
75,
1757,
8227,
5065,
356,
267,
1980,
272,
2600,
275,
20840,
14,
2184,
342,
272,
2059,
199,
199,
17482,
275,
2740,
8,
9086,
14,
6452,
9520,
6331,
2237,
199,
509,
6193,
315,
20840,
26,
272,
340,
6193,
14,
1450,
1137,
283,
498,
7,
503,
6193,
14,
505,
1137,
283,
2709,
14,
1462,
356,
267,
1980,
272,
2251,
63,
1144,
275,
20840,
14,
2184,
342,
272,
2059,
199,
199,
1739,
63,
835,
275,
3089,
8,
17,
367,
485,
315,
2740,
8,
1144,
14,
6452,
9520,
6331,
13324,
199,
199,
509,
1233,
63,
3852,
315,
1233,
63,
7322,
26,
272,
1329,
63,
1080,
275,
1982,
63,
835,
272,
3000,
275,
6566,
360,
4115,
358,
272,
3000,
14,
505,
275,
620,
8,
442,
8,
600,
63,
3852,
59,
16,
467,
378,
430,
272,
1625,
14,
740,
8,
4115,
9,
272,
1982,
63,
835,
847,
413,
339,
1059,
63,
1080,
275,
1982,
63,
835,
272,
1059,
275,
6566,
360,
875,
358,
272,
1059,
14,
505,
275,
1233,
63,
3852,
59,
17,
61,
272,
1625,
14,
740,
8,
875,
9,
272,
1982,
63,
835,
847,
413,
339,
2600,
275,
6566,
360,
807,
358,
272,
790,
275,
6566,
360,
498,
358,
272,
790,
14,
505,
275,
298,
5487,
4,
6685,
2,
272,
2600,
14,
740,
8,
498,
9,
272,
3000,
275,
6566,
360,
4115,
358,
272,
3000,
14,
505,
275,
620,
8,
1955,
63,
1080,
9,
272,
2600,
14,
740,
8,
4115,
9,
272,
2251,
63,
1144,
14,
740,
8,
9086,
9,
339,
2600,
275,
6566,
360,
807,
358,
272,
790,
275,
6566,
360,
498,
358,
272,
790,
14,
505,
275,
298,
5487,
4,
6685,
2,
272,
2600,
14,
740,
8,
498,
9,
272,
3000,
275,
6566,
360,
4115,
358,
272,
3000,
14,
505,
275,
620,
8,
875,
63,
1080,
9,
272,
2600,
14,
740,
8,
4115,
9,
272,
2251,
63,
1144,
14,
740,
8,
9086,
9,
199,
199,
10265,
14,
952,
8,
1274,
14,
2703,
12,
2644,
534,
1624,
13,
24,
297,
2748,
63,
15477,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
koson/MissionPlannerKMTI
|
Lib/lib2to3/fixes/fix_dict.py
|
326
|
3824
|
# Copyright 2007 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Fixer for dict methods.
d.keys() -> list(d.keys())
d.items() -> list(d.items())
d.values() -> list(d.values())
d.iterkeys() -> iter(d.keys())
d.iteritems() -> iter(d.items())
d.itervalues() -> iter(d.values())
d.viewkeys() -> d.keys()
d.viewitems() -> d.items()
d.viewvalues() -> d.values()
Except in certain very specific contexts: the iter() can be dropped
when the context is list(), sorted(), iter() or for...in; the list()
can be dropped when the context is list() or sorted() (but not iter()
or for...in!). Special contexts that apply to both: list(), sorted(), tuple()
set(), any(), all(), sum().
Note: iter(d.keys()) could be written as iter(d) but since the
original d.iterkeys() was also redundant we don't fix this. And there
are (rare) contexts where it makes a difference (e.g. when passing it
as an argument to a function that introspects the argument).
"""
# Local imports
from .. import pytree
from .. import patcomp
from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name, Call, LParen, RParen, ArgList, Dot
from .. import fixer_util
iter_exempt = fixer_util.consuming_calls | set(["iter"])
class FixDict(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """
power< head=any+
trailer< '.' method=('keys'|'items'|'values'|
'iterkeys'|'iteritems'|'itervalues'|
'viewkeys'|'viewitems'|'viewvalues') >
parens=trailer< '(' ')' >
tail=any*
>
"""
def transform(self, node, results):
head = results["head"]
method = results["method"][0] # Extract node for method name
tail = results["tail"]
syms = self.syms
method_name = method.value
isiter = method_name.startswith(u"iter")
isview = method_name.startswith(u"view")
if isiter or isview:
method_name = method_name[4:]
assert method_name in (u"keys", u"items", u"values"), repr(method)
head = [n.clone() for n in head]
tail = [n.clone() for n in tail]
special = not tail and self.in_special_context(node, isiter)
args = head + [pytree.Node(syms.trailer,
[Dot(),
Name(method_name,
prefix=method.prefix)]),
results["parens"].clone()]
new = pytree.Node(syms.power, args)
if not (special or isview):
new.prefix = u""
new = Call(Name(u"iter" if isiter else u"list"), [new])
if tail:
new = pytree.Node(syms.power, [new] + tail)
new.prefix = node.prefix
return new
P1 = "power< func=NAME trailer< '(' node=any ')' > any* >"
p1 = patcomp.compile_pattern(P1)
P2 = """for_stmt< 'for' any 'in' node=any ':' any* >
| comp_for< 'for' any 'in' node=any any* >
"""
p2 = patcomp.compile_pattern(P2)
def in_special_context(self, node, isiter):
if node.parent is None:
return False
results = {}
if (node.parent.parent is not None and
self.p1.match(node.parent.parent, results) and
results["node"] is node):
if isiter:
# iter(d.iterkeys()) -> iter(d.keys()), etc.
return results["func"].value in iter_exempt
else:
# list(d.keys()) -> list(d.keys()), etc.
return results["func"].value in fixer_util.consuming_calls
if not isiter:
return False
# for ... in d.iterkeys() -> for ... in d.keys(), etc.
return self.p2.match(node.parent, results) and results["node"] is node
|
gpl-3.0
|
[
3,
1898,
10219,
4475,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
11985,
281,
367,
1211,
3102,
14,
199,
199,
68,
14,
1612,
342,
1035,
769,
8,
68,
14,
1612,
1012,
199,
68,
14,
1744,
342,
1035,
769,
8,
68,
14,
1744,
1012,
199,
68,
14,
1459,
342,
1035,
769,
8,
68,
14,
1459,
1012,
199,
199,
68,
14,
16007,
342,
1035,
2740,
8,
68,
14,
1612,
1012,
199,
68,
14,
4611,
342,
1035,
2740,
8,
68,
14,
1744,
1012,
199,
68,
14,
13012,
342,
1035,
2740,
8,
68,
14,
1459,
1012,
199,
199,
68,
14,
1345,
1612,
342,
1035,
366,
14,
1612,
342,
199,
68,
14,
1345,
1744,
342,
1035,
366,
14,
1744,
342,
199,
68,
14,
1345,
1459,
342,
1035,
366,
14,
1459,
342,
199,
199,
920,
716,
315,
9842,
7437,
2488,
18191,
26,
314,
2740,
342,
883,
506,
17481,
199,
6526,
314,
1067,
365,
769,
1062,
3355,
1062,
2740,
342,
503,
367,
1396,
262,
27,
314,
769,
342,
199,
2425,
506,
17481,
1380,
314,
1067,
365,
769,
342,
503,
3355,
342,
334,
7911,
440,
2740,
342,
199,
269,
367,
1396,
262,
1,
680,
12568,
18191,
626,
4838,
370,
3865,
26,
769,
1062,
3355,
1062,
2008,
342,
199,
409,
1062,
1263,
1062,
1006,
1062,
3089,
1252,
199,
199,
7443,
26,
2740,
8,
68,
14,
1612,
1012,
4293,
506,
5313,
465,
2740,
8,
68,
9,
1325,
3967,
314,
199,
5043,
366,
14,
16007,
342,
1990,
2597,
22649,
781,
2793,
1133,
5325,
642,
14,
221,
6061,
2337,
199,
1530,
334,
345,
264,
9,
18191,
2382,
652,
7704,
282,
8865,
334,
69,
14,
71,
14,
1380,
9476,
652,
199,
305,
376,
1423,
370,
282,
805,
626,
1109,
21302,
83,
314,
1423,
680,
199,
624,
199,
199,
3,
10111,
8925,
199,
504,
2508,
492,
23353,
199,
504,
2508,
492,
12713,
863,
199,
504,
2508,
80,
2268,
18,
492,
1526,
199,
504,
2508,
492,
24739,
63,
1095,
199,
504,
2508,
25973,
63,
1974,
492,
2812,
12,
6523,
12,
491,
4232,
828,
12,
820,
4232,
828,
12,
29560,
1296,
12,
24716,
199,
504,
2508,
492,
24739,
63,
1974,
421,
199,
1661,
63,
25254,
275,
24739,
63,
1974,
14,
388,
26745,
63,
5352,
1204,
663,
5234,
1661,
3135,
421,
199,
533,
14811,
2141,
8,
25973,
63,
1095,
14,
1563,
11985,
304,
272,
699,
45,
63,
6490,
275,
715,
339,
31467,
7689,
275,
408,
272,
7074,
28,
4854,
29,
1629,
11,
268,
17357,
28,
7815,
1083,
7782,
1612,
26972,
1744,
26972,
1459,
17018,
2892,
283,
16007,
26972,
4611,
26972,
13012,
17018,
2892,
283,
1345,
1612,
26972,
1345,
1744,
26972,
1345,
1459,
358,
690,
268,
32029,
29,
21606,
28,
16746,
16107,
690,
268,
9483,
29,
1629,
10,
272,
690,
272,
408,
339,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
267,
4854,
275,
2058,
905,
2993,
937,
267,
1083,
275,
2058,
905,
765,
9210,
16,
61,
327,
12892,
1031,
367,
1083,
536,
267,
9483,
275,
2058,
905,
1521,
937,
267,
25308,
275,
291,
14,
13807,
267,
1083,
63,
354,
275,
1083,
14,
585,
267,
24353,
351,
275,
1083,
63,
354,
14,
2460,
8,
85,
2,
1661,
531,
267,
365,
1345,
275,
1083,
63,
354,
14,
2460,
8,
85,
2,
1345,
531,
267,
340,
24353,
351,
503,
365,
1345,
26,
288,
1083,
63,
354,
275,
1083,
63,
354,
59,
20,
2938,
267,
702,
1083,
63,
354,
315,
334,
85,
2,
1612,
401,
399,
2,
1744,
401,
399,
2,
1459,
1288,
4700,
8,
765,
9,
267,
4854,
275,
359,
78,
14,
6311,
342,
367,
302,
315,
4854,
61,
267,
9483,
275,
359,
78,
14,
6311,
342,
367,
302,
315,
9483,
61,
267,
4539,
275,
440,
9483,
436,
291,
14,
262,
63,
6664,
63,
1100,
8,
932,
12,
24353,
351,
9,
267,
1249,
275,
4854,
435,
359,
647,
2350,
14,
1716,
8,
13807,
14,
21606,
12,
3521,
359,
14004,
1062,
2511,
2812,
8,
765,
63,
354,
12,
1460,
2403,
29,
765,
14,
1861,
16636,
2432,
2058,
905,
31910,
4140,
6311,
5106,
267,
892,
275,
23353,
14,
1716,
8,
13807,
14,
5652,
12,
1249,
9,
267,
340,
440,
334,
6664,
503,
365,
1345,
304,
288,
892,
14,
1861,
275,
399,
341,
288,
892,
275,
6523,
8,
985,
8,
85,
2,
1661,
2,
340,
24353,
351,
587,
399,
2,
513,
1288,
359,
1222,
566,
267,
340,
9483,
26,
288,
892,
275,
23353,
14,
1716,
8,
13807,
14,
5652,
12,
359,
1222,
61,
435,
9483,
9,
267,
892,
14,
1861,
275,
1031,
14,
1861,
267,
372,
892,
339,
510,
17,
275,
298,
5652,
28,
2562,
29,
2339,
17357,
28,
16746,
1031,
29,
1629,
16107,
690,
1263,
10,
690,
2,
272,
299,
17,
275,
12713,
863,
14,
2014,
63,
3401,
8,
48,
17,
9,
339,
510,
18,
275,
408,
509,
63,
9649,
28,
283,
509,
7,
1263,
283,
262,
7,
1031,
29,
1629,
10871,
1263,
10,
690,
288,
1204,
1013,
63,
509,
28,
283,
509,
7,
1263,
283,
262,
7,
1031,
29,
1629,
1263,
10,
690,
268,
408,
272,
299,
18,
275,
12713,
863,
14,
2014,
63,
3401,
8,
48,
18,
9,
339,
347,
315,
63,
6664,
63,
1100,
8,
277,
12,
1031,
12,
24353,
351,
304,
267,
340,
1031,
14,
1708,
365,
488,
26,
288,
372,
756,
267,
2058,
275,
1052,
267,
340,
334,
932,
14,
1708,
14,
1708,
365,
440,
488,
436,
2049,
291,
14,
80,
17,
14,
1431,
8,
932,
14,
1708,
14,
1708,
12,
2058,
9,
436,
2049,
2058,
905,
932,
937,
365,
1031,
304,
288,
340,
24353,
351,
26,
355,
327,
2740,
8,
68,
14,
16007,
1012,
1035,
2740,
8,
68,
14,
1612,
4000,
5423,
14,
355,
372,
2058,
905,
1532,
4140,
585,
315,
2740,
63,
25254,
288,
587,
26,
355,
327,
769,
8,
68,
14,
1612,
1012,
1035,
769,
8,
68,
14,
1612,
4000,
5423,
14,
355,
372,
2058,
905,
1532,
4140,
585,
315,
24739,
63,
1974,
14,
388,
26745,
63,
5352,
267,
340,
440,
24353,
351,
26,
288,
372,
756,
267,
327,
367,
2263,
315,
366,
14,
16007,
342,
1035,
367,
2263,
315,
366,
14,
1612,
1062,
5423,
14,
267,
372,
291,
14,
80,
18,
14,
1431,
8,
932,
14,
1708,
12,
2058,
9,
436,
2058,
905,
932
] |
[
1898,
10219,
4475,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
11985,
281,
367,
1211,
3102,
14,
199,
199,
68,
14,
1612,
342,
1035,
769,
8,
68,
14,
1612,
1012,
199,
68,
14,
1744,
342,
1035,
769,
8,
68,
14,
1744,
1012,
199,
68,
14,
1459,
342,
1035,
769,
8,
68,
14,
1459,
1012,
199,
199,
68,
14,
16007,
342,
1035,
2740,
8,
68,
14,
1612,
1012,
199,
68,
14,
4611,
342,
1035,
2740,
8,
68,
14,
1744,
1012,
199,
68,
14,
13012,
342,
1035,
2740,
8,
68,
14,
1459,
1012,
199,
199,
68,
14,
1345,
1612,
342,
1035,
366,
14,
1612,
342,
199,
68,
14,
1345,
1744,
342,
1035,
366,
14,
1744,
342,
199,
68,
14,
1345,
1459,
342,
1035,
366,
14,
1459,
342,
199,
199,
920,
716,
315,
9842,
7437,
2488,
18191,
26,
314,
2740,
342,
883,
506,
17481,
199,
6526,
314,
1067,
365,
769,
1062,
3355,
1062,
2740,
342,
503,
367,
1396,
262,
27,
314,
769,
342,
199,
2425,
506,
17481,
1380,
314,
1067,
365,
769,
342,
503,
3355,
342,
334,
7911,
440,
2740,
342,
199,
269,
367,
1396,
262,
1,
680,
12568,
18191,
626,
4838,
370,
3865,
26,
769,
1062,
3355,
1062,
2008,
342,
199,
409,
1062,
1263,
1062,
1006,
1062,
3089,
1252,
199,
199,
7443,
26,
2740,
8,
68,
14,
1612,
1012,
4293,
506,
5313,
465,
2740,
8,
68,
9,
1325,
3967,
314,
199,
5043,
366,
14,
16007,
342,
1990,
2597,
22649,
781,
2793,
1133,
5325,
642,
14,
221,
6061,
2337,
199,
1530,
334,
345,
264,
9,
18191,
2382,
652,
7704,
282,
8865,
334,
69,
14,
71,
14,
1380,
9476,
652,
199,
305,
376,
1423,
370,
282,
805,
626,
1109,
21302,
83,
314,
1423,
680,
199,
624,
199,
199,
3,
10111,
8925,
199,
504,
2508,
492,
23353,
199,
504,
2508,
492,
12713,
863,
199,
504,
2508,
80,
2268,
18,
492,
1526,
199,
504,
2508,
492,
24739,
63,
1095,
199,
504,
2508,
25973,
63,
1974,
492,
2812,
12,
6523,
12,
491,
4232,
828,
12,
820,
4232,
828,
12,
29560,
1296,
12,
24716,
199,
504,
2508,
492,
24739,
63,
1974,
421,
199,
1661,
63,
25254,
275,
24739,
63,
1974,
14,
388,
26745,
63,
5352,
1204,
663,
5234,
1661,
3135,
421,
199,
533,
14811,
2141,
8,
25973,
63,
1095,
14,
1563,
11985,
304,
272,
699,
45,
63,
6490,
275,
715,
339,
31467,
7689,
275,
408,
272,
7074,
28,
4854,
29,
1629,
11,
268,
17357,
28,
7815,
1083,
7782,
1612,
26972,
1744,
26972,
1459,
17018,
2892,
283,
16007,
26972,
4611,
26972,
13012,
17018,
2892,
283,
1345,
1612,
26972,
1345,
1744,
26972,
1345,
1459,
358,
690,
268,
32029,
29,
21606,
28,
16746,
16107,
690,
268,
9483,
29,
1629,
10,
272,
690,
272,
408,
339,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
267,
4854,
275,
2058,
905,
2993,
937,
267,
1083,
275,
2058,
905,
765,
9210,
16,
61,
327,
12892,
1031,
367,
1083,
536,
267,
9483,
275,
2058,
905,
1521,
937,
267,
25308,
275,
291,
14,
13807,
267,
1083,
63,
354,
275,
1083,
14,
585,
267,
24353,
351,
275,
1083,
63,
354,
14,
2460,
8,
85,
2,
1661,
531,
267,
365,
1345,
275,
1083,
63,
354,
14,
2460,
8,
85,
2,
1345,
531,
267,
340,
24353,
351,
503,
365,
1345,
26,
288,
1083,
63,
354,
275,
1083,
63,
354,
59,
20,
2938,
267,
702,
1083,
63,
354,
315,
334,
85,
2,
1612,
401,
399,
2,
1744,
401,
399,
2,
1459,
1288,
4700,
8,
765,
9,
267,
4854,
275,
359,
78,
14,
6311,
342,
367,
302,
315,
4854,
61,
267,
9483,
275,
359,
78,
14,
6311,
342,
367,
302,
315,
9483,
61,
267,
4539,
275,
440,
9483,
436,
291,
14,
262,
63,
6664,
63,
1100,
8,
932,
12,
24353,
351,
9,
267,
1249,
275,
4854,
435,
359,
647,
2350,
14,
1716,
8,
13807,
14,
21606,
12,
3521,
359,
14004,
1062,
2511,
2812,
8,
765,
63,
354,
12,
1460,
2403,
29,
765,
14,
1861,
16636,
2432,
2058,
905,
31910,
4140,
6311,
5106,
267,
892,
275,
23353,
14,
1716,
8,
13807,
14,
5652,
12,
1249,
9,
267,
340,
440,
334,
6664,
503,
365,
1345,
304,
288,
892,
14,
1861,
275,
399,
341,
288,
892,
275,
6523,
8,
985,
8,
85,
2,
1661,
2,
340,
24353,
351,
587,
399,
2,
513,
1288,
359,
1222,
566,
267,
340,
9483,
26,
288,
892,
275,
23353,
14,
1716,
8,
13807,
14,
5652,
12,
359,
1222,
61,
435,
9483,
9,
267,
892,
14,
1861,
275,
1031,
14,
1861,
267,
372,
892,
339,
510,
17,
275,
298,
5652,
28,
2562,
29,
2339,
17357,
28,
16746,
1031,
29,
1629,
16107,
690,
1263,
10,
690,
2,
272,
299,
17,
275,
12713,
863,
14,
2014,
63,
3401,
8,
48,
17,
9,
339,
510,
18,
275,
408,
509,
63,
9649,
28,
283,
509,
7,
1263,
283,
262,
7,
1031,
29,
1629,
10871,
1263,
10,
690,
288,
1204,
1013,
63,
509,
28,
283,
509,
7,
1263,
283,
262,
7,
1031,
29,
1629,
1263,
10,
690,
268,
408,
272,
299,
18,
275,
12713,
863,
14,
2014,
63,
3401,
8,
48,
18,
9,
339,
347,
315,
63,
6664,
63,
1100,
8,
277,
12,
1031,
12,
24353,
351,
304,
267,
340,
1031,
14,
1708,
365,
488,
26,
288,
372,
756,
267,
2058,
275,
1052,
267,
340,
334,
932,
14,
1708,
14,
1708,
365,
440,
488,
436,
2049,
291,
14,
80,
17,
14,
1431,
8,
932,
14,
1708,
14,
1708,
12,
2058,
9,
436,
2049,
2058,
905,
932,
937,
365,
1031,
304,
288,
340,
24353,
351,
26,
355,
327,
2740,
8,
68,
14,
16007,
1012,
1035,
2740,
8,
68,
14,
1612,
4000,
5423,
14,
355,
372,
2058,
905,
1532,
4140,
585,
315,
2740,
63,
25254,
288,
587,
26,
355,
327,
769,
8,
68,
14,
1612,
1012,
1035,
769,
8,
68,
14,
1612,
4000,
5423,
14,
355,
372,
2058,
905,
1532,
4140,
585,
315,
24739,
63,
1974,
14,
388,
26745,
63,
5352,
267,
340,
440,
24353,
351,
26,
288,
372,
756,
267,
327,
367,
2263,
315,
366,
14,
16007,
342,
1035,
367,
2263,
315,
366,
14,
1612,
1062,
5423,
14,
267,
372,
291,
14,
80,
18,
14,
1431,
8,
932,
14,
1708,
12,
2058,
9,
436,
2058,
905,
932,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
android-ia/hardware_intel_parameter-framework
|
test/functional-tests/PfwTestCase/Types/tFP32_Q0_31.py
|
10
|
10926
|
# -*-coding:utf-8 -*
# Copyright (c) 2011-2015, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. 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.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Fixed-Point parameter type testcases - FP16_Q0.31
List of tested functions :
--------------------------
- [setParameter] function
- [getParameter] function
Initial Settings :
------------------
FP16_Q0.31 :
- size = 32 bits
- 0 integer bits, 31 fractionnal bits
- range : [-1, 0.9999999995343387126922607421875]
Test cases :
------------
- FP16_Q0.31 parameter min value = -1
- FP16_Q0.31 parameter min value out of bounds = -1.0000000001
- FP16_Q0.31 parameter max value = 0.9999999995
- FP16_Q0.31 parameter max value out of bounds = 1
- FP16_Q0.31 parameter in nominal case = 0.5000000000
"""
import commands
from Util.PfwUnitTestLib import PfwTestCase
from Util import ACTLogging
log=ACTLogging.Logger()
# Test of type FP32_Q0.31 - range [-1,0.9999999995343387126922607421875]
class TestCases(PfwTestCase):
def setUp(self):
self.param_name = "/Test/Test/TEST_DIR/FP32_Q0.31"
self.pfw.sendCmd("setTuningMode", "on")
def tearDown(self):
self.pfw.sendCmd("setTuningMode", "off")
def test_Nominal_Case(self):
"""
Testing FP16_Q0.31 in nominal case = 0.500000000
------------------------------------------------
Test case description :
~~~~~~~~~~~~~~~~~~~~~~~
- set FP16_Q0.31 parameter in nominal case = 0.500000000
Tested commands :
~~~~~~~~~~~~~~~~~
- [setParameter] function
Used commands :
~~~~~~~~~~~~~~~
- [getParameter] function
Expected result :
~~~~~~~~~~~~~~~~~
- FP16_Q0.31 parameter set to 0.500000000
- Blackboard and filesystem values checked
"""
log.D(self.test_Nominal_Case.__doc__)
log.I("FP32_Q0.31 parameter in nominal case = 0.500000000")
value = "0.5000000000"
hex_value = "0x40000000"
#Set parameter value
out, err = self.pfw.sendCmd("setParameter", self.param_name, value)
assert err == None, log.E("when setting parameter %s : %s" % (self.param_name, err))
assert out == "Done", log.F("when setting parameter %s : %s" % (self.param_name, out))
#Check parameter value on blackboard
out, err = self.pfw.sendCmd("getParameter", self.param_name, "")
assert err == None, log.E("when setting parameter %s : %s" % (self.param_name, err))
assert round(float(out),10) == round(float(value),10), log.F("BLACKBOARD : Incorrect value for %s, expected: %s, found: %s"
% (self.param_name, value, out))
#Check parameter value on filesystem
assert commands.getoutput('cat $PFW_RESULT/FP32_Q0.31') == hex_value, log.F("FILESYSTEM : parameter update error")
log.I("test OK")
def test_TypeMin(self):
"""
Testing FP16_Q0.31 minimal value = -1
-------------------------------------
Test case description :
~~~~~~~~~~~~~~~~~~~~~~~
- set FP16_Q0.31 parameter min value = -1
Tested commands :
~~~~~~~~~~~~~~~~~
- [setParameter] function
Used commands :
~~~~~~~~~~~~~~~
- [getParameter] function
Expected result :
~~~~~~~~~~~~~~~~~
- FP16_Q0.31 parameter set to -1
- Blackboard and filesystem values checked
"""
log.D(self.test_TypeMin.__doc__)
log.I("FP32_Q0.31 parameter min value = -1")
value = "-1"
hex_value = "0x80000000"
#Set parameter value
out, err = self.pfw.sendCmd("setParameter", self.param_name, value)
assert err == None, log.E("when setting parameter %s : %s" % (self.param_name, err))
assert out == "Done", log.F("when setting parameter %s : %s" % (self.param_name, out))
#Check parameter value on blackboard
out, err = self.pfw.sendCmd("getParameter", self.param_name, "")
assert err == None, log.E("when setting parameter %s : %s" % (self.param_name, err))
assert round(float(out),10) == round(float(value),10), log.F("BLACKBOARD : Incorrect value for %s, expected: %s, found: %s"
% (self.param_name, value, out))
#Check parameter value on filesystem
assert commands.getoutput('cat $PFW_RESULT/FP32_Q0.31') == hex_value, log.F("FILESYSTEM : parameter update error")
log.I("test OK")
def test_TypeMin_Overflow(self):
"""
Testing FP16_Q0.31 parameter value out of negative range
--------------------------------------------------------
Test case description :
~~~~~~~~~~~~~~~~~~~~~~~
- set FP16_Q0.31 to -1.000000001
Tested commands :
~~~~~~~~~~~~~~~~~
- [setParameter] function
Used commands :
~~~~~~~~~~~~~~~
- [getParameter] function
Expected result :
~~~~~~~~~~~~~~~~~
- error detected
- FP16_Q0.31 parameter not updated
- Blackboard and filesystem values checked
"""
log.D(self.test_TypeMin_Overflow.__doc__)
log.I("FP32_Q0.31 parameter min value out of bounds = -1.000000001")
value = "-1.0000000001"
param_check = commands.getoutput('cat $PFW_RESULT/FP32_Q0.31')
#Set parameter value
out, err = self.pfw.sendCmd("setParameter", self.param_name, value)
assert err == None, log.E("when setting parameter %s : %s" % (self.param_name, err))
assert out != "Done", log.F("PFW : Error not detected when setting parameter %s out of bounds"
% (self.param_name))
#Check parameter value on filesystem
assert commands.getoutput('cat $PFW_RESULT/FP32_Q0.31') == param_check, log.F("FILESYSTEM : Forbiden parameter change")
log.I("test OK")
def test_TypeMax(self):
"""
Testing FP16_Q0.31 parameter maximum value
------------------------------------------
Test case description :
~~~~~~~~~~~~~~~~~~~~~~~
- set FP16_Q0.31 to 0.9999999995
Tested commands :
~~~~~~~~~~~~~~~~~
- [setParameter] function
Used commands :
~~~~~~~~~~~~~~~
- [getParameter] function
Expected result :
~~~~~~~~~~~~~~~~~
- FP16_Q0.31 parameter set to 0.9999999995
- Blackboard and filesystem values checked
"""
log.D(self.test_TypeMax.__doc__)
log.I("FP32_Q0.31 parameter max value = 0.9999999995")
value = "0.9999999995"
hex_value = "0x7fffffff"
#Set parameter value
out, err = self.pfw.sendCmd("setParameter", self.param_name, value)
assert err == None, log.E("when setting parameter %s : %s" % (self.param_name, err))
assert out == "Done", log.F("when setting parameter %s : %s" % (self.param_name, out))
#Check parameter value on blackboard
out, err = self.pfw.sendCmd("getParameter", self.param_name, "")
assert err == None, log.E("when setting parameter %s : %s" % (self.param_name, err))
assert round(float(out),10) == round(float(value),10), log.F("BLACKBOARD : Incorrect value for %s, expected: %s, found: %s"
% (self.param_name, value, out))
#Check parameter value on filesystem
assert commands.getoutput('cat $PFW_RESULT/FP32_Q0.31') == hex_value, log.F("FILESYSTEM : parameter update error")
log.I("test OK")
def test_TypeMax_Overflow(self):
"""
Testing FP16_Q0.31 parameter value out of positive range
--------------------------------------------------------
Test case description :
~~~~~~~~~~~~~~~~~~~~~~~
- set FP16_Q0.31 to 1
Tested commands :
~~~~~~~~~~~~~~~~~
- [setParameter] function
Used commands :
~~~~~~~~~~~~~~~
- [getParameter] function
Expected result :
~~~~~~~~~~~~~~~~~
- error detected
- FP16_Q0.31 parameter not updated
- Blackboard and filesystem values checked
"""
log.D(self.test_TypeMax_Overflow.__doc__)
log.I("FP32_Q0.31 parameter max value out of bounds = 1")
value = "1"
param_check = commands.getoutput('cat $PFW_RESULT/FP32_Q0.31')
#Set parameter value
out, err = self.pfw.sendCmd("setParameter", self.param_name, value)
assert err == None, log.E("when setting parameter %s : %s"
% (self.param_name, err))
assert out != "Done", log.F("PFW : Error not detected when setting parameter %s out of bounds"
% (self.param_name))
#Check parameter value on filesystem
assert commands.getoutput('cat $PFW_RESULT/FP32_Q0.31') == param_check, log.F("FILESYSTEM : Forbiden parameter change")
log.I("test OK")
|
bsd-3-clause
|
[
3,
1882,
1523,
26,
1624,
13,
24,
446,
10,
199,
199,
3,
1898,
334,
67,
9,
7760,
13,
7806,
12,
20619,
11098,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
436,
15,
269,
199,
3,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
650,
14,
11443,
314,
536,
402,
314,
4248,
16712,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
199,
3,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
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,
9817,
2401,
5258,
199,
3,
1821,
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,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
199,
9515,
13,
3428,
2725,
730,
511,
9403,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
199,
199,
1296,
402,
12470,
3423,
520,
199,
777,
9460,
272,
446,
359,
409,
4720,
61,
221,
805,
272,
446,
359,
362,
4720,
61,
805,
199,
199,
5733,
13303,
520,
199,
777,
306,
272,
481,
48,
975,
63,
49,
16,
14,
2192,
520,
267,
446,
1568,
275,
4337,
5821,
267,
446,
378,
3000,
5821,
12,
7105,
12347,
78,
279,
5821,
267,
446,
1425,
520,
5243,
17,
12,
378,
14,
13453,
2720,
1082,
1153,
1555,
713,
1876,
1081,
2259,
1342,
9252,
2194,
61,
199,
199,
774,
5560,
520,
199,
4559,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
1748,
574,
275,
446,
17,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
1748,
574,
734,
402,
10461,
275,
446,
17,
14,
3607,
614,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
1390,
574,
275,
378,
14,
13453,
2720,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
1390,
574,
734,
402,
10461,
275,
413,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
315,
17468,
1582,
1930,
275,
378,
14,
21,
25464,
199,
624,
199,
646,
3718,
199,
504,
21248,
14,
48,
8835,
29037,
4728,
492,
510,
8835,
1746,
199,
504,
21248,
492,
21401,
14054,
199,
793,
29,
3036,
14054,
14,
4455,
342,
199,
199,
3,
1379,
402,
730,
481,
48,
708,
63,
49,
16,
14,
2192,
446,
1425,
5243,
17,
12,
16,
14,
13453,
2720,
1082,
1153,
1555,
713,
1876,
1081,
2259,
1342,
9252,
2194,
61,
199,
533,
7640,
83,
8,
48,
8835,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
635,
63,
354,
275,
3286,
774,
15,
774,
15,
2864,
63,
3022,
15,
17095,
708,
63,
49,
16,
14,
2192,
2,
267,
291,
14,
80,
8835,
14,
2254,
7874,
480,
409,
22664,
316,
1385,
401,
298,
265,
531,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
80,
8835,
14,
2254,
7874,
480,
409,
22664,
316,
1385,
401,
298,
1997,
531,
339,
347,
511,
63,
46,
676,
1582,
63,
1538,
8,
277,
304,
267,
408,
267,
11940,
481,
48,
975,
63,
49,
16,
14,
2192,
315,
17468,
1582,
1930,
275,
378,
14,
21,
3607,
267,
9527,
288,
1379,
1930,
1369,
520,
288,
18294,
2878,
23597,
355,
446,
663,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
315,
17468,
1582,
1930,
275,
378,
14,
21,
3607,
288,
30568,
3718,
520,
288,
18294,
94,
355,
446,
359,
409,
4720,
61,
805,
288,
8051,
3718,
520,
288,
32202,
23597,
355,
446,
359,
362,
4720,
61,
805,
288,
13796,
754,
520,
288,
18294,
94,
355,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
663,
370,
378,
14,
21,
3607,
355,
446,
30593,
3576,
436,
10036,
1338,
7923,
267,
408,
267,
943,
14,
36,
8,
277,
14,
396,
63,
46,
676,
1582,
63,
1538,
855,
1301,
3368,
267,
943,
14,
41,
480,
17095,
708,
63,
49,
16,
14,
2192,
2725,
315,
17468,
1582,
1930,
275,
378,
14,
21,
3607,
531,
267,
574,
275,
298,
16,
14,
21,
25464,
2,
267,
6318,
63,
585,
275,
298,
16,
88,
20,
9084,
2,
267,
327,
1084,
2725,
574,
267,
734,
12,
2329,
275,
291,
14,
80,
8835,
14,
2254,
7874,
480,
409,
4720,
401,
291,
14,
635,
63,
354,
12,
574,
9,
267,
702,
2329,
508,
488,
12,
943,
14,
37,
480,
6526,
4260,
2725,
450,
83,
520,
450,
83,
2,
450,
334,
277,
14,
635,
63,
354,
12,
2329,
430,
267,
702,
734,
508,
298,
10759,
401,
943,
14,
38,
480,
6526,
4260,
2725,
450,
83,
520,
450,
83,
2,
450,
334,
277,
14,
635,
63,
354,
12,
734,
430,
267,
327,
1799,
2725,
574,
641,
12136,
3576,
267,
734,
12,
2329,
275,
291,
14,
80,
8835,
14,
2254,
7874,
480,
362,
4720,
401,
291,
14,
635,
63,
354,
12,
6899,
267,
702,
2329,
508,
488,
12,
943,
14,
37,
480,
6526,
4260,
2725,
450,
83,
520,
450,
83,
2,
450,
334,
277,
14,
635,
63,
354,
12,
2329,
430,
267,
702,
6168,
8,
1609,
8,
548,
395,
709
] |
[
1882,
1523,
26,
1624,
13,
24,
446,
10,
199,
199,
3,
1898,
334,
67,
9,
7760,
13,
7806,
12,
20619,
11098,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
436,
15,
269,
199,
3,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
650,
14,
11443,
314,
536,
402,
314,
4248,
16712,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
199,
3,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
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,
9817,
2401,
5258,
199,
3,
1821,
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,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
199,
9515,
13,
3428,
2725,
730,
511,
9403,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
199,
199,
1296,
402,
12470,
3423,
520,
199,
777,
9460,
272,
446,
359,
409,
4720,
61,
221,
805,
272,
446,
359,
362,
4720,
61,
805,
199,
199,
5733,
13303,
520,
199,
777,
306,
272,
481,
48,
975,
63,
49,
16,
14,
2192,
520,
267,
446,
1568,
275,
4337,
5821,
267,
446,
378,
3000,
5821,
12,
7105,
12347,
78,
279,
5821,
267,
446,
1425,
520,
5243,
17,
12,
378,
14,
13453,
2720,
1082,
1153,
1555,
713,
1876,
1081,
2259,
1342,
9252,
2194,
61,
199,
199,
774,
5560,
520,
199,
4559,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
1748,
574,
275,
446,
17,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
1748,
574,
734,
402,
10461,
275,
446,
17,
14,
3607,
614,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
1390,
574,
275,
378,
14,
13453,
2720,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
1390,
574,
734,
402,
10461,
275,
413,
272,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
315,
17468,
1582,
1930,
275,
378,
14,
21,
25464,
199,
624,
199,
646,
3718,
199,
504,
21248,
14,
48,
8835,
29037,
4728,
492,
510,
8835,
1746,
199,
504,
21248,
492,
21401,
14054,
199,
793,
29,
3036,
14054,
14,
4455,
342,
199,
199,
3,
1379,
402,
730,
481,
48,
708,
63,
49,
16,
14,
2192,
446,
1425,
5243,
17,
12,
16,
14,
13453,
2720,
1082,
1153,
1555,
713,
1876,
1081,
2259,
1342,
9252,
2194,
61,
199,
533,
7640,
83,
8,
48,
8835,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
635,
63,
354,
275,
3286,
774,
15,
774,
15,
2864,
63,
3022,
15,
17095,
708,
63,
49,
16,
14,
2192,
2,
267,
291,
14,
80,
8835,
14,
2254,
7874,
480,
409,
22664,
316,
1385,
401,
298,
265,
531,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
80,
8835,
14,
2254,
7874,
480,
409,
22664,
316,
1385,
401,
298,
1997,
531,
339,
347,
511,
63,
46,
676,
1582,
63,
1538,
8,
277,
304,
267,
408,
267,
11940,
481,
48,
975,
63,
49,
16,
14,
2192,
315,
17468,
1582,
1930,
275,
378,
14,
21,
3607,
267,
9527,
288,
1379,
1930,
1369,
520,
288,
18294,
2878,
23597,
355,
446,
663,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
315,
17468,
1582,
1930,
275,
378,
14,
21,
3607,
288,
30568,
3718,
520,
288,
18294,
94,
355,
446,
359,
409,
4720,
61,
805,
288,
8051,
3718,
520,
288,
32202,
23597,
355,
446,
359,
362,
4720,
61,
805,
288,
13796,
754,
520,
288,
18294,
94,
355,
446,
481,
48,
975,
63,
49,
16,
14,
2192,
2725,
663,
370,
378,
14,
21,
3607,
355,
446,
30593,
3576,
436,
10036,
1338,
7923,
267,
408,
267,
943,
14,
36,
8,
277,
14,
396,
63,
46,
676,
1582,
63,
1538,
855,
1301,
3368,
267,
943,
14,
41,
480,
17095,
708,
63,
49,
16,
14,
2192,
2725,
315,
17468,
1582,
1930,
275,
378,
14,
21,
3607,
531,
267,
574,
275,
298,
16,
14,
21,
25464,
2,
267,
6318,
63,
585,
275,
298,
16,
88,
20,
9084,
2,
267,
327,
1084,
2725,
574,
267,
734,
12,
2329,
275,
291,
14,
80,
8835,
14,
2254,
7874,
480,
409,
4720,
401,
291,
14,
635,
63,
354,
12,
574,
9,
267,
702,
2329,
508,
488,
12,
943,
14,
37,
480,
6526,
4260,
2725,
450,
83,
520,
450,
83,
2,
450,
334,
277,
14,
635,
63,
354,
12,
2329,
430,
267,
702,
734,
508,
298,
10759,
401,
943,
14,
38,
480,
6526,
4260,
2725,
450,
83,
520,
450,
83,
2,
450,
334,
277,
14,
635,
63,
354,
12,
734,
430,
267,
327,
1799,
2725,
574,
641,
12136,
3576,
267,
734,
12,
2329,
275,
291,
14,
80,
8835,
14,
2254,
7874,
480,
362,
4720,
401,
291,
14,
635,
63,
354,
12,
6899,
267,
702,
2329,
508,
488,
12,
943,
14,
37,
480,
6526,
4260,
2725,
450,
83,
520,
450,
83,
2,
450,
334,
277,
14,
635,
63,
354,
12,
2329,
430,
267,
702,
6168,
8,
1609,
8,
548,
395,
709,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sassoftware/conary
|
conary/lib/epdb_embedded/epdb_stackutil.py
|
2
|
4928
|
#
# Copyright (c) SAS Institute 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.
#
""" Tools for printing out extended information about frame variables """
import inspect
import smtplib
import sys
import string
import tempfile
import traceback
import xmlrpclib
from repr import Repr
_repr = Repr()
_repr.maxstring = 3000
_saferepr = _repr.repr
def printTraceBack(tb=None, output=sys.stderr, exc_type=None, exc_msg=None):
if isinstance(output, str):
output = open(output, 'w')
exc_info = sys.exc_info()
if tb is None:
tb = exc_info[2]
if exc_type is None:
exc_type = exc_info[0]
if exc_msg is None:
exc_msg = exc_info[1]
if exc_type is not None:
output.write('Exception: ')
exc_info = '\n'.join(traceback.format_exception_only(exc_type, exc_msg))
output.write(exc_info)
output.write('\n\n')
lines = traceback.format_exception(exc_type, exc_msg, tb)
output.write(string.joinfields(lines, ""))
while tb:
_printFrame(tb.tb_frame, output=output)
tb = tb.tb_next
def printFrame(frame=0, output=sys.stderr):
# if output is a path, assume it is a writable one
# otherwise, it must be an already opened file
if isinstance(output, str):
output = open(output, 'w')
# skip this frame because who cares about the printFrame func?
if isinstance(frame, int):
# stack was given in depth form
# (skip the current frame when counting depth)
frame = sys._getframe(frame + 1)
_printFrame(frame, output)
def printStack(frame=0, output=sys.stderr):
if isinstance(output, str):
output = open(output, 'w')
if isinstance(frame, int):
# stack was given in depth form
# (skip the current frame when counting depth)
frame = sys._getframe(frame + 1)
while(frame):
output.write("*************************************\n")
_printFrame(frame, output)
frame = frame.f_back
def mailStack(frame, recips, sender, subject, extracontent=None):
file = tempfile.TemporaryFile()
file.write('Subject: ' + subject + '\n\n')
if extracontent:
file.write(extracontent)
printStack(frame, file)
server = smtplib.SMTP('localhost')
file.seek(0)
server.sendmail(sender,
recips,
file.read())
server.close()
file.close()
def _printFrame(f, output=sys.stderr):
c = f.f_code
argcount = c.co_argcount
varnames = c.co_varnames
args = varnames[:argcount]
locals = f.f_locals
globals = f.f_globals
output.write(">> %s:%s: %s.%s(%s)\n" % ( c.co_filename, f.f_lineno, globals['__name__'], c.co_name, ', '.join(args) ))
localkeys = [ l for l in f.f_locals.keys() if not inspect.ismodule(locals[l] ) ]
if argcount > 0:
output.write(" Params: \n")
for var in varnames[:argcount]:
if var in locals:
val = locals[var]
val = _getStringValue(val)
localkeys.remove(var)
else:
val = '<Unknown>'
output.write(" %s = %s\n" % (var, _saferepr(val)))
for hidden in ('__file__', '__name__', '__doc__'):
if hidden in localkeys:
localkeys.remove(hidden)
localkeys.sort()
if localkeys:
output.write(" Locals: \n")
for key in localkeys:
if key in locals:
val = locals[key]
val = _getStringValue(val)
else:
val = '<Unknown>'
output.write(" %s = %r\n" % (key, _saferepr(val)))
def _getStringValue(val):
try:
if isinstance(val, xmlrpclib.ServerProxy):
rval = "<Server Proxy>"
elif hasattr(val, 'asString'):
rval = val.asString()
elif inspect.isclass(val):
rval = '<Class %s.%s>' % (val.__module__, val.__name__)
elif not hasattr(val, '__str__'):
if hasattr(val, '__class__'):
rval = '<unprintable of class %s>' % val.__class__
else:
rval = '<unprintable>'
else:
rval = val
return rval
except Exception, e:
try:
return '<Exception occured while converting %s to string: %s' %(repr(val), e)
except Exception, e:
return '<Exception occured while converting to repr: %s' %(e)
|
apache-2.0
|
[
3,
199,
3,
1898,
334,
67,
9,
26124,
1010,
25585,
3277,
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,
421,
199,
624,
23228,
367,
16116,
734,
9243,
2556,
3595,
2787,
2860,
408,
199,
199,
646,
6485,
199,
646,
30475,
199,
646,
984,
199,
646,
1059,
199,
646,
5549,
199,
646,
5190,
199,
646,
19122,
199,
199,
504,
4700,
492,
799,
2700,
199,
63,
2722,
275,
799,
2700,
342,
199,
63,
2722,
14,
988,
875,
275,
29664,
199,
63,
3489,
2722,
275,
485,
2722,
14,
2722,
199,
199,
318,
870,
3921,
4540,
8,
5842,
29,
403,
12,
1072,
29,
1274,
14,
3083,
12,
3178,
63,
466,
29,
403,
12,
3178,
63,
1328,
29,
403,
304,
272,
340,
1228,
8,
1199,
12,
620,
304,
267,
1072,
275,
1551,
8,
1199,
12,
283,
87,
358,
339,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
272,
340,
7070,
365,
488,
26,
267,
7070,
275,
3178,
63,
815,
59,
18,
61,
339,
340,
3178,
63,
466,
365,
488,
26,
267,
3178,
63,
466,
275,
3178,
63,
815,
59,
16,
61,
339,
340,
3178,
63,
1328,
365,
488,
26,
267,
3178,
63,
1328,
275,
3178,
63,
815,
59,
17,
61,
339,
340,
3178,
63,
466,
365,
440,
488,
26,
267,
1072,
14,
952,
360,
1726,
26,
5320,
267,
3178,
63,
815,
275,
1557,
78,
1370,
904,
8,
6894,
14,
908,
63,
1971,
63,
2118,
8,
2804,
63,
466,
12,
3178,
63,
1328,
430,
267,
1072,
14,
952,
8,
2804,
63,
815,
9,
267,
1072,
14,
952,
2258,
78,
60,
78,
358,
339,
2385,
275,
5190,
14,
908,
63,
1971,
8,
2804,
63,
466,
12,
3178,
63,
1328,
12,
7070,
9,
272,
1072,
14,
952,
8,
875,
14,
904,
955,
8,
1278,
12,
25491,
339,
1830,
7070,
26,
267,
485,
1361,
3160,
8,
5842,
14,
5842,
63,
1943,
12,
1072,
29,
1199,
9,
267,
7070,
275,
7070,
14,
5842,
63,
2184,
199,
199,
318,
870,
3160,
8,
1943,
29,
16,
12,
1072,
29,
1274,
14,
3083,
304,
272,
327,
340,
1072,
365,
282,
931,
12,
5534,
652,
365,
282,
17267,
1373,
272,
327,
4257,
12,
652,
1471,
506,
376,
2575,
12123,
570,
272,
340,
1228,
8,
1199,
12,
620,
304,
267,
1072,
275,
1551,
8,
1199,
12,
283,
87,
358,
272,
327,
3372,
642,
2787,
2952,
3963,
1704,
470,
3595,
314,
870,
3160,
2562,
31,
272,
340,
1228,
8,
1943,
12,
1109,
304,
267,
327,
3464,
1990,
1627,
315,
5818,
1824,
267,
327,
334,
2759,
314,
1453,
2787,
1380,
23190,
5818,
9,
267,
2787,
275,
984,
423,
20912,
8,
1943,
435,
413,
9,
272,
485,
1361,
3160,
8,
1943,
12,
1072,
9,
199,
199,
318,
870,
4851,
8,
1943,
29,
16,
12,
1072,
29,
1274,
14,
3083,
304,
272,
340,
1228,
8,
1199,
12,
620,
304,
267,
1072,
275,
1551,
8,
1199,
12,
283,
87,
358,
272,
340,
1228,
8,
1943,
12,
1109,
304,
267,
327,
3464,
1990,
1627,
315,
5818,
1824,
267,
327,
334,
2759,
314,
1453,
2787,
1380,
23190,
5818,
9,
267,
2787,
275,
984,
423,
20912,
8,
1943,
435,
413,
9,
272,
1830,
8,
1943,
304,
267,
1072,
14,
952,
480,
5815,
1116,
7590,
78,
531,
267,
485,
1361,
3160,
8,
1943,
12,
1072,
9,
267,
2787,
275,
2787,
14,
70,
63,
894,
199,
199,
318,
6016,
4851,
8,
1943,
12,
295,
559,
1190,
12,
8904,
12,
5420,
12,
2402,
1317,
29,
403,
304,
272,
570,
275,
5549,
14,
13271,
342,
272,
570,
14,
952,
360,
13528,
26,
283,
435,
221,
5420,
435,
1557,
78,
60,
78,
358,
272,
340,
2402,
1317,
26,
267,
570,
14,
952,
8,
2911,
1317,
9,
272,
870,
4851,
8,
1943,
12,
570,
9,
272,
1654,
275,
30475,
14,
20927,
360,
5967,
358,
272,
570,
14,
5507,
8,
16,
9,
272,
1654,
14,
2254,
1198,
8,
8114,
12,
490,
295,
559,
1190,
12,
490,
570,
14,
739,
1012,
272,
1654,
14,
1600,
342,
272,
570,
14,
1600,
342,
199,
199,
318,
485,
1361,
3160,
8,
70,
12,
1072,
29,
1274,
14,
3083,
304,
272,
286,
275,
289,
14,
70,
63,
600,
272,
1680,
835,
275,
221,
286,
14,
331,
63,
30513,
272,
2729,
1247,
275,
286,
14,
331,
63,
1391,
1247,
272,
1249,
275,
2729,
1247,
1491,
30513,
61,
272,
9480,
275,
289,
14,
70,
63,
9350,
272,
7992,
275,
289,
14,
70,
63,
8473,
272,
1072,
14,
952,
480,
1140,
450,
83,
2689,
83,
26,
450,
83,
4111,
83,
4042,
83,
2862,
78,
2,
450,
334,
286,
14,
331,
63,
1501,
12,
289,
14,
70,
63,
3469,
12,
7992,
13742,
354,
363,
995,
286,
14,
331,
63,
354,
12,
1656,
1987,
904,
8,
589,
9,
5082,
339,
2257,
1612,
275,
359,
634,
367,
634,
315,
289,
14,
70,
63,
9350,
14,
1612,
342,
340,
440,
6485,
14,
374,
578,
8,
9350,
59,
76,
61,
776,
1622,
5591,
340,
1680,
835,
690,
378,
26,
267,
1072,
14,
952,
480,
221,
30370,
26,
971,
78,
531,
267,
367,
2729,
315,
2729,
1247,
1491,
30513,
2189,
288,
340,
2729,
315,
9480,
26,
355,
1139,
275,
9480,
59,
1391,
61,
355,
1139,
275,
485,
362,
1558,
1110,
8,
637,
9,
355,
2257,
1612,
14,
2168,
8,
1391,
9,
288,
587,
26,
355,
1139,
275,
2650,
5912,
3524,
953,
1072,
14,
952,
480,
259,
450,
83,
275,
450,
83,
60,
78,
2,
450,
334,
1391,
12,
485,
3489,
2722,
8,
637,
1724,
272,
367,
8752,
315,
25038,
493,
7500
] |
[
199,
3,
1898,
334,
67,
9,
26124,
1010,
25585,
3277,
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,
421,
199,
624,
23228,
367,
16116,
734,
9243,
2556,
3595,
2787,
2860,
408,
199,
199,
646,
6485,
199,
646,
30475,
199,
646,
984,
199,
646,
1059,
199,
646,
5549,
199,
646,
5190,
199,
646,
19122,
199,
199,
504,
4700,
492,
799,
2700,
199,
63,
2722,
275,
799,
2700,
342,
199,
63,
2722,
14,
988,
875,
275,
29664,
199,
63,
3489,
2722,
275,
485,
2722,
14,
2722,
199,
199,
318,
870,
3921,
4540,
8,
5842,
29,
403,
12,
1072,
29,
1274,
14,
3083,
12,
3178,
63,
466,
29,
403,
12,
3178,
63,
1328,
29,
403,
304,
272,
340,
1228,
8,
1199,
12,
620,
304,
267,
1072,
275,
1551,
8,
1199,
12,
283,
87,
358,
339,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
272,
340,
7070,
365,
488,
26,
267,
7070,
275,
3178,
63,
815,
59,
18,
61,
339,
340,
3178,
63,
466,
365,
488,
26,
267,
3178,
63,
466,
275,
3178,
63,
815,
59,
16,
61,
339,
340,
3178,
63,
1328,
365,
488,
26,
267,
3178,
63,
1328,
275,
3178,
63,
815,
59,
17,
61,
339,
340,
3178,
63,
466,
365,
440,
488,
26,
267,
1072,
14,
952,
360,
1726,
26,
5320,
267,
3178,
63,
815,
275,
1557,
78,
1370,
904,
8,
6894,
14,
908,
63,
1971,
63,
2118,
8,
2804,
63,
466,
12,
3178,
63,
1328,
430,
267,
1072,
14,
952,
8,
2804,
63,
815,
9,
267,
1072,
14,
952,
2258,
78,
60,
78,
358,
339,
2385,
275,
5190,
14,
908,
63,
1971,
8,
2804,
63,
466,
12,
3178,
63,
1328,
12,
7070,
9,
272,
1072,
14,
952,
8,
875,
14,
904,
955,
8,
1278,
12,
25491,
339,
1830,
7070,
26,
267,
485,
1361,
3160,
8,
5842,
14,
5842,
63,
1943,
12,
1072,
29,
1199,
9,
267,
7070,
275,
7070,
14,
5842,
63,
2184,
199,
199,
318,
870,
3160,
8,
1943,
29,
16,
12,
1072,
29,
1274,
14,
3083,
304,
272,
327,
340,
1072,
365,
282,
931,
12,
5534,
652,
365,
282,
17267,
1373,
272,
327,
4257,
12,
652,
1471,
506,
376,
2575,
12123,
570,
272,
340,
1228,
8,
1199,
12,
620,
304,
267,
1072,
275,
1551,
8,
1199,
12,
283,
87,
358,
272,
327,
3372,
642,
2787,
2952,
3963,
1704,
470,
3595,
314,
870,
3160,
2562,
31,
272,
340,
1228,
8,
1943,
12,
1109,
304,
267,
327,
3464,
1990,
1627,
315,
5818,
1824,
267,
327,
334,
2759,
314,
1453,
2787,
1380,
23190,
5818,
9,
267,
2787,
275,
984,
423,
20912,
8,
1943,
435,
413,
9,
272,
485,
1361,
3160,
8,
1943,
12,
1072,
9,
199,
199,
318,
870,
4851,
8,
1943,
29,
16,
12,
1072,
29,
1274,
14,
3083,
304,
272,
340,
1228,
8,
1199,
12,
620,
304,
267,
1072,
275,
1551,
8,
1199,
12,
283,
87,
358,
272,
340,
1228,
8,
1943,
12,
1109,
304,
267,
327,
3464,
1990,
1627,
315,
5818,
1824,
267,
327,
334,
2759,
314,
1453,
2787,
1380,
23190,
5818,
9,
267,
2787,
275,
984,
423,
20912,
8,
1943,
435,
413,
9,
272,
1830,
8,
1943,
304,
267,
1072,
14,
952,
480,
5815,
1116,
7590,
78,
531,
267,
485,
1361,
3160,
8,
1943,
12,
1072,
9,
267,
2787,
275,
2787,
14,
70,
63,
894,
199,
199,
318,
6016,
4851,
8,
1943,
12,
295,
559,
1190,
12,
8904,
12,
5420,
12,
2402,
1317,
29,
403,
304,
272,
570,
275,
5549,
14,
13271,
342,
272,
570,
14,
952,
360,
13528,
26,
283,
435,
221,
5420,
435,
1557,
78,
60,
78,
358,
272,
340,
2402,
1317,
26,
267,
570,
14,
952,
8,
2911,
1317,
9,
272,
870,
4851,
8,
1943,
12,
570,
9,
272,
1654,
275,
30475,
14,
20927,
360,
5967,
358,
272,
570,
14,
5507,
8,
16,
9,
272,
1654,
14,
2254,
1198,
8,
8114,
12,
490,
295,
559,
1190,
12,
490,
570,
14,
739,
1012,
272,
1654,
14,
1600,
342,
272,
570,
14,
1600,
342,
199,
199,
318,
485,
1361,
3160,
8,
70,
12,
1072,
29,
1274,
14,
3083,
304,
272,
286,
275,
289,
14,
70,
63,
600,
272,
1680,
835,
275,
221,
286,
14,
331,
63,
30513,
272,
2729,
1247,
275,
286,
14,
331,
63,
1391,
1247,
272,
1249,
275,
2729,
1247,
1491,
30513,
61,
272,
9480,
275,
289,
14,
70,
63,
9350,
272,
7992,
275,
289,
14,
70,
63,
8473,
272,
1072,
14,
952,
480,
1140,
450,
83,
2689,
83,
26,
450,
83,
4111,
83,
4042,
83,
2862,
78,
2,
450,
334,
286,
14,
331,
63,
1501,
12,
289,
14,
70,
63,
3469,
12,
7992,
13742,
354,
363,
995,
286,
14,
331,
63,
354,
12,
1656,
1987,
904,
8,
589,
9,
5082,
339,
2257,
1612,
275,
359,
634,
367,
634,
315,
289,
14,
70,
63,
9350,
14,
1612,
342,
340,
440,
6485,
14,
374,
578,
8,
9350,
59,
76,
61,
776,
1622,
5591,
340,
1680,
835,
690,
378,
26,
267,
1072,
14,
952,
480,
221,
30370,
26,
971,
78,
531,
267,
367,
2729,
315,
2729,
1247,
1491,
30513,
2189,
288,
340,
2729,
315,
9480,
26,
355,
1139,
275,
9480,
59,
1391,
61,
355,
1139,
275,
485,
362,
1558,
1110,
8,
637,
9,
355,
2257,
1612,
14,
2168,
8,
1391,
9,
288,
587,
26,
355,
1139,
275,
2650,
5912,
3524,
953,
1072,
14,
952,
480,
259,
450,
83,
275,
450,
83,
60,
78,
2,
450,
334,
1391,
12,
485,
3489,
2722,
8,
637,
1724,
272,
367,
8752,
315,
25038,
493,
7500,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jhawkesworth/ansible
|
lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py
|
47
|
17084
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2016, Olivier Boukili <boukili.olivier@gmail.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: apache2_mod_proxy
author: Olivier Boukili (@oboukili)
version_added: "2.2"
short_description: Set and/or get members' attributes of an Apache httpd 2.4 mod_proxy balancer pool
description:
- Set and/or get members' attributes of an Apache httpd 2.4 mod_proxy balancer
pool, using HTTP POST and GET requests. The httpd mod_proxy balancer-member
status page has to be enabled and accessible, as this module relies on parsing
this page. This module supports ansible check_mode, and requires BeautifulSoup
python module.
options:
balancer_url_suffix:
description:
- Suffix of the balancer pool url required to access the balancer pool
status page (e.g. balancer_vhost[:port]/balancer_url_suffix).
default: /balancer-manager/
balancer_vhost:
description:
- (ipv4|ipv6|fqdn):port of the Apache httpd 2.4 mod_proxy balancer pool.
required: true
member_host:
description:
- (ipv4|ipv6|fqdn) of the balancer member to get or to set attributes to.
Port number is autodetected and should not be specified here.
If undefined, apache2_mod_proxy module will return a members list of
dictionaries of all the current balancer pool members' attributes.
state:
description:
- Desired state of the member host.
(absent|disabled),drained,hot_standby,ignore_errors can be
simultaneously invoked by separating them with a comma (e.g. state=drained,ignore_errors).
choices: ["present", "absent", "enabled", "disabled", "drained", "hot_standby", "ignore_errors"]
tls:
description:
- Use https to access balancer management page.
type: bool
default: 'no'
validate_certs:
description:
- Validate ssl/tls certificates.
type: bool
default: 'yes'
'''
EXAMPLES = '''
# Get all current balancer pool members' attributes:
- apache2_mod_proxy:
balancer_vhost: 10.0.0.2
# Get a specific member's attributes:
- apache2_mod_proxy:
balancer_vhost: myws.mydomain.org
balancer_suffix: /lb/
member_host: node1.myws.mydomain.org
# Enable all balancer pool members:
- apache2_mod_proxy:
balancer_vhost: '{{ myloadbalancer_host }}'
register: result
- apache2_mod_proxy:
balancer_vhost: '{{ myloadbalancer_host }}'
member_host: '{{ item.host }}'
state: present
with_items: '{{ result.members }}'
# Gracefully disable a member from a loadbalancer node:
- apache2_mod_proxy:
balancer_vhost: '{{ vhost_host }}'
member_host: '{{ member.host }}'
state: drained
delegate_to: myloadbalancernode
- wait_for:
host: '{{ member.host }}'
port: '{{ member.port }}'
state: drained
delegate_to: myloadbalancernode
- apache2_mod_proxy:
balancer_vhost: '{{ vhost_host }}'
member_host: '{{ member.host }}'
state: absent
delegate_to: myloadbalancernode
'''
RETURN = '''
member:
description: specific balancer member information dictionary, returned when apache2_mod_proxy module is invoked with member_host parameter.
type: dict
returned: success
sample:
{"attributes":
{"Busy": "0",
"Elected": "42",
"Factor": "1",
"From": "136K",
"Load": "0",
"Route": null,
"RouteRedir": null,
"Set": "0",
"Status": "Init Ok ",
"To": " 47K",
"Worker URL": null
},
"balancer_url": "http://10.10.0.2/balancer-manager/",
"host": "10.10.0.20",
"management_url": "http://10.10.0.2/lb/?b=mywsbalancer&w=http://10.10.0.20:8080/ws&nonce=8925436c-79c6-4841-8936-e7d13b79239b",
"path": "/ws",
"port": 8080,
"protocol": "http",
"status": {
"disabled": false,
"drained": false,
"hot_standby": false,
"ignore_errors": false
}
}
members:
description: list of member (defined above) dictionaries, returned when apache2_mod_proxy is invoked with no member_host and state args.
returned: success
type: list
sample:
[{"attributes": {
"Busy": "0",
"Elected": "42",
"Factor": "1",
"From": "136K",
"Load": "0",
"Route": null,
"RouteRedir": null,
"Set": "0",
"Status": "Init Ok ",
"To": " 47K",
"Worker URL": null
},
"balancer_url": "http://10.10.0.2/balancer-manager/",
"host": "10.10.0.20",
"management_url": "http://10.10.0.2/lb/?b=mywsbalancer&w=http://10.10.0.20:8080/ws&nonce=8925436c-79c6-4841-8936-e7d13b79239b",
"path": "/ws",
"port": 8080,
"protocol": "http",
"status": {
"disabled": false,
"drained": false,
"hot_standby": false,
"ignore_errors": false
}
},
{"attributes": {
"Busy": "0",
"Elected": "42",
"Factor": "1",
"From": "136K",
"Load": "0",
"Route": null,
"RouteRedir": null,
"Set": "0",
"Status": "Init Ok ",
"To": " 47K",
"Worker URL": null
},
"balancer_url": "http://10.10.0.2/balancer-manager/",
"host": "10.10.0.21",
"management_url": "http://10.10.0.2/lb/?b=mywsbalancer&w=http://10.10.0.21:8080/ws&nonce=8925436c-79c6-4841-8936-e7d13b79239b",
"path": "/ws",
"port": 8080,
"protocol": "http",
"status": {
"disabled": false,
"drained": false,
"hot_standby": false,
"ignore_errors": false}
}
]
'''
import re
import traceback
BEAUTIFUL_SOUP_IMP_ERR = None
try:
from BeautifulSoup import BeautifulSoup
except ImportError:
BEAUTIFUL_SOUP_IMP_ERR = traceback.format_exc()
HAS_BEAUTIFULSOUP = False
else:
HAS_BEAUTIFULSOUP = True
# balancer member attributes extraction regexp:
EXPRESSION = r"(b=([\w\.\-]+)&w=(https?|ajp|wss?|ftp|[sf]cgi)://([\w\.\-]+):?(\d*)([/\w\.\-]*)&?[\w\-\=]*)"
# Apache2 server version extraction regexp:
APACHE_VERSION_EXPRESSION = r"SERVER VERSION: APACHE/([\d.]+)"
def regexp_extraction(string, _regexp, groups=1):
""" Returns the capture group (default=1) specified in the regexp, applied to the string """
regexp_search = re.search(string=str(string), pattern=str(_regexp))
if regexp_search:
if regexp_search.group(groups) != '':
return str(regexp_search.group(groups))
return None
class BalancerMember(object):
""" Apache 2.4 mod_proxy LB balancer member.
attributes:
read-only:
host -> member host (string),
management_url -> member management url (string),
protocol -> member protocol (string)
port -> member port (string),
path -> member location (string),
balancer_url -> url of this member's parent balancer (string),
attributes -> whole member attributes (dictionary)
module -> ansible module instance (AnsibleModule object).
writable:
status -> status of the member (dictionary)
"""
def __init__(self, management_url, balancer_url, module):
self.host = regexp_extraction(management_url, str(EXPRESSION), 4)
self.management_url = str(management_url)
self.protocol = regexp_extraction(management_url, EXPRESSION, 3)
self.port = regexp_extraction(management_url, EXPRESSION, 5)
self.path = regexp_extraction(management_url, EXPRESSION, 6)
self.balancer_url = str(balancer_url)
self.module = module
def get_member_attributes(self):
""" Returns a dictionary of a balancer member's attributes."""
balancer_member_page = fetch_url(self.module, self.management_url)
if balancer_member_page[1]['status'] != 200:
self.module.fail_json(msg="Could not get balancer_member_page, check for connectivity! " + balancer_member_page[1])
else:
try:
soup = BeautifulSoup(balancer_member_page[0])
except TypeError:
self.module.fail_json(msg="Cannot parse balancer_member_page HTML! " + str(soup))
else:
subsoup = soup.findAll('table')[1].findAll('tr')
keys = subsoup[0].findAll('th')
for valuesset in subsoup[1::1]:
if re.search(pattern=self.host, string=str(valuesset)):
values = valuesset.findAll('td')
return dict((keys[x].string, values[x].string) for x in range(0, len(keys)))
def get_member_status(self):
""" Returns a dictionary of a balancer member's status attributes."""
status_mapping = {'disabled': 'Dis',
'drained': 'Drn',
'hot_standby': 'Stby',
'ignore_errors': 'Ign'}
status = {}
actual_status = str(self.attributes['Status'])
for mode in status_mapping.keys():
if re.search(pattern=status_mapping[mode], string=actual_status):
status[mode] = True
else:
status[mode] = False
return status
def set_member_status(self, values):
""" Sets a balancer member's status attributes amongst pre-mapped values."""
values_mapping = {'disabled': '&w_status_D',
'drained': '&w_status_N',
'hot_standby': '&w_status_H',
'ignore_errors': '&w_status_I'}
request_body = regexp_extraction(self.management_url, EXPRESSION, 1)
for k in values_mapping.keys():
if values[str(k)]:
request_body = request_body + str(values_mapping[k]) + '=1'
else:
request_body = request_body + str(values_mapping[k]) + '=0'
response = fetch_url(self.module, self.management_url, data=str(request_body))
if response[1]['status'] != 200:
self.module.fail_json(msg="Could not set the member status! " + self.host + " " + response[1]['status'])
attributes = property(get_member_attributes)
status = property(get_member_status, set_member_status)
class Balancer(object):
""" Apache httpd 2.4 mod_proxy balancer object"""
def __init__(self, host, suffix, module, members=None, tls=False):
if tls:
self.base_url = str(str('https://') + str(host))
self.url = str(str('https://') + str(host) + str(suffix))
else:
self.base_url = str(str('http://') + str(host))
self.url = str(str('http://') + str(host) + str(suffix))
self.module = module
self.page = self.fetch_balancer_page()
if members is None:
self._members = []
def fetch_balancer_page(self):
""" Returns the balancer management html page as a string for later parsing."""
page = fetch_url(self.module, str(self.url))
if page[1]['status'] != 200:
self.module.fail_json(msg="Could not get balancer page! HTTP status response: " + str(page[1]['status']))
else:
content = page[0].read()
apache_version = regexp_extraction(content.upper(), APACHE_VERSION_EXPRESSION, 1)
if apache_version:
if not re.search(pattern=r"2\.4\.[\d]*", string=apache_version):
self.module.fail_json(msg="This module only acts on an Apache2 2.4+ instance, current Apache2 version: " + str(apache_version))
return content
else:
self.module.fail_json(msg="Could not get the Apache server version from the balancer-manager")
def get_balancer_members(self):
""" Returns members of the balancer as a generator object for later iteration."""
try:
soup = BeautifulSoup(self.page)
except TypeError:
self.module.fail_json(msg="Cannot parse balancer page HTML! " + str(self.page))
else:
for element in soup.findAll('a')[1::1]:
balancer_member_suffix = str(element.get('href'))
if not balancer_member_suffix:
self.module.fail_json(msg="Argument 'balancer_member_suffix' is empty!")
else:
yield BalancerMember(str(self.base_url + balancer_member_suffix), str(self.url), self.module)
members = property(get_balancer_members)
def main():
""" Initiates module."""
module = AnsibleModule(
argument_spec=dict(
balancer_vhost=dict(required=True, default=None, type='str'),
balancer_url_suffix=dict(default="/balancer-manager/", type='str'),
member_host=dict(type='str'),
state=dict(type='str'),
tls=dict(default=False, type='bool'),
validate_certs=dict(default=True, type='bool')
),
supports_check_mode=True
)
if HAS_BEAUTIFULSOUP is False:
module.fail_json(msg=missing_required_lib('BeautifulSoup'), exception=BEAUTIFUL_SOUP_IMP_ERR)
if module.params['state'] is not None:
states = module.params['state'].split(',')
if (len(states) > 1) and (("present" in states) or ("enabled" in states)):
module.fail_json(msg="state present/enabled is mutually exclusive with other states!")
else:
for _state in states:
if _state not in ['present', 'absent', 'enabled', 'disabled', 'drained', 'hot_standby', 'ignore_errors']:
module.fail_json(
msg="State can only take values amongst 'present', 'absent', 'enabled', 'disabled', 'drained', 'hot_standby', 'ignore_errors'."
)
else:
states = ['None']
mybalancer = Balancer(module.params['balancer_vhost'],
module.params['balancer_url_suffix'],
module=module,
tls=module.params['tls'])
if module.params['member_host'] is None:
json_output_list = []
for member in mybalancer.members:
json_output_list.append({
"host": member.host,
"status": member.status,
"protocol": member.protocol,
"port": member.port,
"path": member.path,
"attributes": member.attributes,
"management_url": member.management_url,
"balancer_url": member.balancer_url
})
module.exit_json(
changed=False,
members=json_output_list
)
else:
changed = False
member_exists = False
member_status = {'disabled': False, 'drained': False, 'hot_standby': False, 'ignore_errors': False}
for mode in member_status.keys():
for state in states:
if mode == state:
member_status[mode] = True
elif mode == 'disabled' and state == 'absent':
member_status[mode] = True
for member in mybalancer.members:
if str(member.host) == str(module.params['member_host']):
member_exists = True
if module.params['state'] is not None:
member_status_before = member.status
if not module.check_mode:
member_status_after = member.status = member_status
else:
member_status_after = member_status
if member_status_before != member_status_after:
changed = True
json_output = {
"host": member.host,
"status": member.status,
"protocol": member.protocol,
"port": member.port,
"path": member.path,
"attributes": member.attributes,
"management_url": member.management_url,
"balancer_url": member.balancer_url
}
if member_exists:
module.exit_json(
changed=changed,
member=json_output
)
else:
module.fail_json(msg=str(module.params['member_host']) + ' is not a member of the balancer ' + str(module.params['balancer_vhost']) + '!')
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.urls import fetch_url
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
7800,
12,
593,
317,
26645,
699,
810,
75,
1638,
665,
656,
3210,
1638,
14,
23711,
26645,
32,
6799,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
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,
17098,
18,
63,
1494,
63,
3280,
199,
2502,
26,
593,
317,
26645,
699,
810,
75,
1638,
8593,
79,
656,
3210,
1638,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
2494,
436,
15,
269,
664,
7556,
7,
3004,
402,
376,
3668,
23913,
499,
14,
20,
3413,
63,
3280,
17005,
4203,
199,
1802,
26,
523,
446,
2494,
436,
15,
269,
664,
7556,
7,
3004,
402,
376,
3668,
23913,
499,
14,
20,
3413,
63,
3280,
17005,
272,
4203,
12,
1808,
3101,
8761,
436,
9576,
4145,
14,
710,
23913,
3413,
63,
3280,
17005,
13,
1114,
272,
2004,
2034,
965,
370,
506,
5223,
436,
17909,
12,
465,
642,
859,
25749,
641,
6057,
272,
642,
2034,
14,
961,
859,
5171,
3242,
1104,
63,
632,
12,
436,
5074,
17132,
272,
2366,
859,
14,
199,
1419,
26,
523,
17005,
63,
633,
63,
4511,
26,
272,
1369,
26,
489,
446,
428,
2875,
402,
314,
17005,
4203,
1166,
1415,
370,
2879,
314,
17005,
4203,
267,
2004,
2034,
334,
69,
14,
71,
14,
17005,
63,
32071,
1491,
719,
12978,
11841,
63,
633,
63,
4511,
680,
272,
849,
26,
1182,
11841,
13,
2609,
15,
523,
17005,
63,
32071,
26,
272,
1369,
26,
489,
446,
334,
4774,
20,
92,
4774,
22,
92,
18364,
304,
719,
402,
314,
3668,
23913,
499,
14,
20,
3413,
63,
3280,
17005,
4203,
14,
272,
1415,
26,
2549,
523,
3653,
63,
1102,
26,
272,
1369,
26,
489,
446,
334,
4774,
20,
92,
4774,
22,
92,
18364,
9,
402,
314,
17005,
3653,
370,
664,
503,
370,
663,
3004,
370,
14,
267,
10977,
1329,
365,
28537,
4530,
436,
1077,
440,
506,
2013,
2348,
14,
267,
982,
10942,
12,
17098,
18,
63,
1494,
63,
3280,
859,
911,
372,
282,
7556,
769,
402,
267,
11196,
402,
1006,
314,
1453,
17005,
4203,
7556,
7,
3004,
14,
523,
1174,
26,
272,
1369,
26,
489,
446,
1487,
5381,
1174,
402,
314,
3653,
1591,
14,
267,
334,
5575,
92,
7011,
395,
68,
15546,
12,
8885,
63,
26071,
12,
4247,
63,
2550,
883,
506,
267,
27008,
590,
10302,
701,
4216,
1958,
3062,
543,
282,
10029,
334,
69,
14,
71,
14,
1174,
29,
68,
15546,
12,
4247,
63,
2550,
680,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
401,
298,
3827,
401,
298,
7011,
401,
298,
68,
15546,
401,
298,
8885,
63,
26071,
401,
298,
4247,
63,
2550,
937,
523,
15142,
26,
272,
1369,
26,
489,
446,
3645,
4178,
370,
2879,
17005,
10041,
2034,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
523,
4107,
63,
8356,
26,
272,
1369,
26,
489,
446,
12134,
6149,
15,
9945,
14512,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2372,
1006,
1453,
17005,
4203,
7556,
7,
3004,
26,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
1616,
14,
16,
14,
16,
14,
18,
199,
199,
3,
2372,
282,
2488,
3653,
1159,
3004,
26,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
3002,
3569,
14,
30945,
14,
1308,
272,
17005,
63,
4511,
26,
1182,
6374,
15,
272,
3653,
63,
1102,
26,
1031,
17,
14,
1662,
3569,
14,
30945,
14,
1308,
199,
199,
3,
12030,
1006,
17005,
4203,
7556,
26,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
11400,
3002,
26615,
63,
1102,
16339,
523,
2274,
26,
754,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
11400,
3002,
26615,
63,
1102,
16339,
272,
3653,
63,
1102,
26,
11400,
1242,
14,
1102,
16339,
272,
1174,
26,
3451,
523,
543,
63,
1744,
26,
11400,
754,
14,
6334,
16339,
199,
199,
3,
598,
5986,
5836,
3507,
282,
3653,
687,
282,
2248,
11841,
1031,
26,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
11400,
373,
1102,
63,
1102,
16339,
272,
3653,
63,
1102,
26,
11400,
3653,
14,
1102,
16339,
272,
1174,
26,
366,
15546,
523,
13080,
63,
475,
26,
3002,
26615,
932,
199,
13,
3618,
63,
509,
26,
272,
1591,
26,
11400,
3653,
14,
1102,
16339,
272,
1844,
26,
11400,
3653,
14,
719,
16339,
272,
1174,
26,
366,
15546,
523,
13080,
63,
475,
26,
3002,
26615,
932,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
11400,
373,
1102,
63,
1102,
16339,
272,
3653,
63,
1102,
26,
11400,
3653,
14,
1102,
16339,
272,
1174,
26,
9552,
523,
13080,
63,
475,
26,
3002,
26615,
932,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1114,
26,
272,
1369,
26,
2488,
17005,
3653,
2556,
2600,
12,
2138,
1380,
17098,
18,
63,
1494,
63,
3280,
859,
365,
10302,
543,
3653,
63,
1102,
2725,
14,
272,
730,
26,
1211,
272,
2138,
26,
3182,
272,
2690,
26,
489,
2420,
2987,
582,
288,
2420,
28759,
582,
298,
16,
401,
288,
298,
37,
2820,
582,
298,
2260,
401,
288,
298,
12666,
582,
298,
17,
401,
288,
298,
2532,
582,
298,
8138,
43,
401,
288,
298,
6200,
582,
298,
16,
401,
288,
298,
7161,
582,
2973,
12,
288,
298,
7161,
497,
694,
582,
2973,
12,
288,
298,
1084,
582,
298,
16,
401,
288,
298,
3694,
582,
298,
9346,
20049,
3872,
288,
298,
1378,
582,
298,
10954,
43,
401,
288,
298,
12678,
2851,
582,
2973,
267,
1660,
267,
298,
11841,
63,
633,
582,
298,
1014,
921
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
7800,
12,
593,
317,
26645,
699,
810,
75,
1638,
665,
656,
3210,
1638,
14,
23711,
26645,
32,
6799,
14,
957,
30,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
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,
17098,
18,
63,
1494,
63,
3280,
199,
2502,
26,
593,
317,
26645,
699,
810,
75,
1638,
8593,
79,
656,
3210,
1638,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
2494,
436,
15,
269,
664,
7556,
7,
3004,
402,
376,
3668,
23913,
499,
14,
20,
3413,
63,
3280,
17005,
4203,
199,
1802,
26,
523,
446,
2494,
436,
15,
269,
664,
7556,
7,
3004,
402,
376,
3668,
23913,
499,
14,
20,
3413,
63,
3280,
17005,
272,
4203,
12,
1808,
3101,
8761,
436,
9576,
4145,
14,
710,
23913,
3413,
63,
3280,
17005,
13,
1114,
272,
2004,
2034,
965,
370,
506,
5223,
436,
17909,
12,
465,
642,
859,
25749,
641,
6057,
272,
642,
2034,
14,
961,
859,
5171,
3242,
1104,
63,
632,
12,
436,
5074,
17132,
272,
2366,
859,
14,
199,
1419,
26,
523,
17005,
63,
633,
63,
4511,
26,
272,
1369,
26,
489,
446,
428,
2875,
402,
314,
17005,
4203,
1166,
1415,
370,
2879,
314,
17005,
4203,
267,
2004,
2034,
334,
69,
14,
71,
14,
17005,
63,
32071,
1491,
719,
12978,
11841,
63,
633,
63,
4511,
680,
272,
849,
26,
1182,
11841,
13,
2609,
15,
523,
17005,
63,
32071,
26,
272,
1369,
26,
489,
446,
334,
4774,
20,
92,
4774,
22,
92,
18364,
304,
719,
402,
314,
3668,
23913,
499,
14,
20,
3413,
63,
3280,
17005,
4203,
14,
272,
1415,
26,
2549,
523,
3653,
63,
1102,
26,
272,
1369,
26,
489,
446,
334,
4774,
20,
92,
4774,
22,
92,
18364,
9,
402,
314,
17005,
3653,
370,
664,
503,
370,
663,
3004,
370,
14,
267,
10977,
1329,
365,
28537,
4530,
436,
1077,
440,
506,
2013,
2348,
14,
267,
982,
10942,
12,
17098,
18,
63,
1494,
63,
3280,
859,
911,
372,
282,
7556,
769,
402,
267,
11196,
402,
1006,
314,
1453,
17005,
4203,
7556,
7,
3004,
14,
523,
1174,
26,
272,
1369,
26,
489,
446,
1487,
5381,
1174,
402,
314,
3653,
1591,
14,
267,
334,
5575,
92,
7011,
395,
68,
15546,
12,
8885,
63,
26071,
12,
4247,
63,
2550,
883,
506,
267,
27008,
590,
10302,
701,
4216,
1958,
3062,
543,
282,
10029,
334,
69,
14,
71,
14,
1174,
29,
68,
15546,
12,
4247,
63,
2550,
680,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
401,
298,
3827,
401,
298,
7011,
401,
298,
68,
15546,
401,
298,
8885,
63,
26071,
401,
298,
4247,
63,
2550,
937,
523,
15142,
26,
272,
1369,
26,
489,
446,
3645,
4178,
370,
2879,
17005,
10041,
2034,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
523,
4107,
63,
8356,
26,
272,
1369,
26,
489,
446,
12134,
6149,
15,
9945,
14512,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2372,
1006,
1453,
17005,
4203,
7556,
7,
3004,
26,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
1616,
14,
16,
14,
16,
14,
18,
199,
199,
3,
2372,
282,
2488,
3653,
1159,
3004,
26,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
3002,
3569,
14,
30945,
14,
1308,
272,
17005,
63,
4511,
26,
1182,
6374,
15,
272,
3653,
63,
1102,
26,
1031,
17,
14,
1662,
3569,
14,
30945,
14,
1308,
199,
199,
3,
12030,
1006,
17005,
4203,
7556,
26,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
11400,
3002,
26615,
63,
1102,
16339,
523,
2274,
26,
754,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
11400,
3002,
26615,
63,
1102,
16339,
272,
3653,
63,
1102,
26,
11400,
1242,
14,
1102,
16339,
272,
1174,
26,
3451,
523,
543,
63,
1744,
26,
11400,
754,
14,
6334,
16339,
199,
199,
3,
598,
5986,
5836,
3507,
282,
3653,
687,
282,
2248,
11841,
1031,
26,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
11400,
373,
1102,
63,
1102,
16339,
272,
3653,
63,
1102,
26,
11400,
3653,
14,
1102,
16339,
272,
1174,
26,
366,
15546,
523,
13080,
63,
475,
26,
3002,
26615,
932,
199,
13,
3618,
63,
509,
26,
272,
1591,
26,
11400,
3653,
14,
1102,
16339,
272,
1844,
26,
11400,
3653,
14,
719,
16339,
272,
1174,
26,
366,
15546,
523,
13080,
63,
475,
26,
3002,
26615,
932,
199,
13,
17098,
18,
63,
1494,
63,
3280,
26,
272,
17005,
63,
32071,
26,
11400,
373,
1102,
63,
1102,
16339,
272,
3653,
63,
1102,
26,
11400,
3653,
14,
1102,
16339,
272,
1174,
26,
9552,
523,
13080,
63,
475,
26,
3002,
26615,
932,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1114,
26,
272,
1369,
26,
2488,
17005,
3653,
2556,
2600,
12,
2138,
1380,
17098,
18,
63,
1494,
63,
3280,
859,
365,
10302,
543,
3653,
63,
1102,
2725,
14,
272,
730,
26,
1211,
272,
2138,
26,
3182,
272,
2690,
26,
489,
2420,
2987,
582,
288,
2420,
28759,
582,
298,
16,
401,
288,
298,
37,
2820,
582,
298,
2260,
401,
288,
298,
12666,
582,
298,
17,
401,
288,
298,
2532,
582,
298,
8138,
43,
401,
288,
298,
6200,
582,
298,
16,
401,
288,
298,
7161,
582,
2973,
12,
288,
298,
7161,
497,
694,
582,
2973,
12,
288,
298,
1084,
582,
298,
16,
401,
288,
298,
3694,
582,
298,
9346,
20049,
3872,
288,
298,
1378,
582,
298,
10954,
43,
401,
288,
298,
12678,
2851,
582,
2973,
267,
1660,
267,
298,
11841,
63,
633,
582,
298,
1014,
921,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
JohnReid/pybool
|
python/pybool/examples/neurogenesis.py
|
1
|
6857
|
#
# Copyright John Reid 2013
#
"""
Example to illustrate application of pybool. Based on regulatory network in paper
on robustness under functional constraint by Nakajima et al.
"""
import numpy as N, logging
from pybool.constraints import gene_off, gene_on
from pybool import network, constraints
class MetaData(constraints.MetaData):
"""
Meta-data for drosophila neurogenesis regulatory
networks in Nakajima paper.
All pybool configuration is done through attributes of this class.
"""
def __init__(self):
"Construct."
#
# Initialise the base class
#
super(MetaData, self).__init__()
#
# The number of time steps to realise.
#
self.T = 12
#
# Add the genes
#
SVP = self.add_external_input(
'svp',
color='purple',
position=( 1, 1.5),
input_function=svp_external_input,
input_params=(None,),
)
HB = self.add_gene(
'hb',
initial_state=1,
constitutive=(0, 1),
color='green',
position=( 0, 1.5),
)
KR = self.add_gene(
'Kr',
initial_state=0,
constitutive=(0, 1),
color='darkblue',
position=(-1, 1 ),
)
PDM = self.add_gene(
'pdm',
initial_state=0,
constitutive=(0, 1),
color='deepskyblue',
position=( 0, .5),
)
CAS = self.add_gene(
'cas',
initial_state=0,
constitutive=(0, 1),
color='#DD0000',
position=(-1, 0 ),
)
X = self.add_external_input(
'X',
color='black',
position=( 1, .5),
input_function=X_external_input,
input_params=N.arange(1, self.T),
)
#
# Add each condition as a dict mapping genes to states and a constraints function
#
wt = self.add_condition(
'wt',
{ },
constraints=(
(constraints.CHECK_ORDER_OF_EXPRESSION, (HB, KR, PDM, CAS)),
(constraints.CHECK_CONSECUTIVE_DIFFERENT, (HB, KR, PDM, CAS)),
(constraints.CHECK_ON_TO_OFF_SWITCH, X),
)
)
hb_ko = self.add_condition(
'hb-',
inputs={ HB : gene_off },
constraints=(
(constraints.CHECK_ORDER_OF_EXPRESSION, (KR, PDM, CAS)),
(constraints.CHECK_CONSECUTIVE_DIFFERENT, (KR, PDM, CAS)),
(constraints.CHECK_ON_TO_OFF_SWITCH, X),
)
)
kr_ko = self.add_condition(
'Kr-',
inputs={ KR : gene_off },
constraints=(
(constraints.CHECK_ORDER_OF_EXPRESSION, (HB, PDM, CAS)),
(constraints.CHECK_CONSECUTIVE_DIFFERENT, (HB, PDM, CAS)),
(constraints.CHECK_ON_TO_OFF_SWITCH, X),
)
)
pdm_ko = self.add_condition(
'pdm-',
inputs={ PDM : gene_off },
constraints=(
(constraints.CHECK_ORDER_OF_EXPRESSION, (HB, KR, CAS)),
(constraints.CHECK_CONSECUTIVE_DIFFERENT, (HB, KR, CAS)),
(constraints.CHECK_ON_TO_OFF_SWITCH, X),
)
)
cas_ko = self.add_condition(
'cas-',
inputs={ CAS : gene_off },
constraints=(
(constraints.CHECK_ORDER_OF_EXPRESSION, (HB, KR, PDM)),
(constraints.CHECK_CONSECUTIVE_DIFFERENT, (HB, KR, PDM)),
(constraints.CHECK_ON_TO_OFF_SWITCH, X),
)
)
hb_oe = self.add_condition(
'hb++',
inputs={ HB : gene_on },
constraints=(
(constraints.CHECK_ORDER_OF_EXPRESSION, (HB, KR)),
(constraints.CHECK_NULL_EXPRESSION, PDM),
(constraints.CHECK_NULL_EXPRESSION, CAS),
(constraints.CHECK_CONSECUTIVE_DIFFERENT, (HB, KR)),
(constraints.CHECK_ON_TO_OFF_SWITCH, X),
)
)
kr_oe = self.add_condition(
'Kr++' ,
inputs={ KR : gene_on },
constraints=(
(constraints.CHECK_ORDER_OF_EXPRESSION, (HB, KR, PDM)),
(constraints.CHECK_NULL_EXPRESSION, CAS),
(constraints.CHECK_CONSECUTIVE_DIFFERENT, (HB, KR, PDM)),
(constraints.CHECK_ON_TO_OFF_SWITCH, X),
)
)
pdm_oe = self.add_condition(
'pdm++',
inputs={ PDM : gene_on },
constraints=(
(constraints.CHECK_ORDER_OF_EXPRESSION, (HB, PDM, CAS)),
(constraints.CHECK_NULL_EXPRESSION, KR),
(constraints.CHECK_CONSECUTIVE_DIFFERENT, (HB, PDM, CAS)),
(constraints.CHECK_ON_TO_OFF_SWITCH, X),
)
)
cas_oe = self.add_condition(
'cas++',
inputs={ CAS : gene_on },
constraints=(
(constraints.CHECK_ORDER_OF_EXPRESSION, (HB, KR)),
(constraints.CHECK_NULL_EXPRESSION, PDM),
(constraints.CHECK_CONSECUTIVE_DIFFERENT, (HB, KR, CAS)),
(constraints.CHECK_ON_TO_OFF_SWITCH, X),
)
)
#
# The condition to use if none specified.
#
self.default_condition = wt
#
# set up the possible regulatory connections
#
unconstrained = (-5, 0, 1)
represses_or_none = (-5, 0)
activates = (1,)
represses = (-5,)
no_regulation = (0,)
# initialise all connections to no_regulation
for g1 in xrange(self.G):
for g2 in xrange(self.G):
self.possible_Js[g1, g2] = no_regulation
# X can regulate any of HB, KR, PDM and CAS
self.possible_Js[ X, HB] = unconstrained
self.possible_Js[ X, KR] = unconstrained
self.possible_Js[ X,PDM] = unconstrained
self.possible_Js[ X,CAS] = unconstrained
# from Figure 1 in Nakajima paper
self.possible_Js[SVP, HB] = represses
self.possible_Js[ HB, KR] = activates
self.possible_Js[ HB,PDM] = represses
self.possible_Js[ HB,CAS] = represses_or_none
self.possible_Js[ KR,PDM] = activates
self.possible_Js[ KR,CAS] = represses
self.possible_Js[PDM, KR] = represses
self.possible_Js[PDM,CAS] = activates
self.possible_Js[CAS,PDM] = represses
def svp_external_input(t, p):
"External input function for svp. svp is on when t = 1."
return 1 == t and 1 or 0
|
mit
|
[
3,
199,
3,
1898,
17815,
799,
344,
6171,
199,
3,
421,
199,
624,
199,
9846,
370,
22907,
11409,
323,
4223,
402,
1134,
2245,
14,
21311,
641,
1295,
6109,
89,
2784,
315,
15220,
199,
265,
23399,
4171,
1334,
22380,
5828,
701,
653,
24685,
8047,
391,
10844,
741,
14,
199,
624,
199,
199,
646,
2680,
465,
653,
12,
2050,
199,
504,
1134,
2245,
14,
9882,
492,
15599,
63,
1997,
12,
15599,
63,
265,
199,
504,
1134,
2245,
492,
2784,
12,
9565,
4388,
199,
533,
24905,
8,
9882,
14,
25285,
304,
272,
408,
272,
6288,
13,
576,
367,
366,
4796,
24316,
25330,
1279,
9129,
10654,
2316,
1295,
6109,
89,
5591,
11759,
315,
653,
24685,
8047,
391,
15220,
14,
2286,
2900,
1134,
2245,
2897,
365,
4224,
4012,
3004,
402,
642,
1021,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
298,
11493,
2122,
2728,
327,
267,
327,
6026,
572,
314,
1300,
1021,
267,
327,
267,
1613,
8,
25285,
12,
291,
2843,
826,
4533,
398,
327,
267,
327,
710,
1329,
402,
900,
7124,
370,
3363,
572,
14,
267,
327,
267,
291,
14,
52,
275,
3144,
523,
267,
327,
267,
327,
2654,
314,
3805,
397,
267,
327,
267,
14056,
48,
275,
291,
14,
525,
63,
5159,
63,
1210,
8,
288,
283,
2772,
80,
297,
288,
3164,
534,
6653,
11045,
297,
288,
3421,
2687,
413,
12,
413,
14,
21,
395,
288,
1324,
63,
1593,
29,
2772,
80,
63,
5159,
63,
1210,
12,
288,
1324,
63,
1162,
2687,
403,
4706,
267,
776,
267,
869,
34,
275,
291,
14,
525,
63,
10654,
8,
288,
283,
16168,
297,
288,
2536,
63,
929,
29,
17,
12,
288,
950,
390,
13441,
2687,
16,
12,
413,
395,
288,
3164,
534,
7731,
297,
288,
3421,
2687,
378,
12,
413,
14,
21,
395,
267,
776,
267,
1804,
50,
275,
291,
14,
525,
63,
10654,
8,
288,
283,
27399,
297,
288,
2536,
63,
929,
29,
16,
12,
288,
950,
390,
13441,
2687,
16,
12,
413,
395,
288,
3164,
534,
13625,
6304,
297,
288,
3421,
26154,
17,
12,
413,
221,
2318,
267,
776,
267,
510,
17751,
275,
291,
14,
525,
63,
10654,
8,
288,
283,
80,
6428,
297,
288,
2536,
63,
929,
29,
16,
12,
288,
950,
390,
13441,
2687,
16,
12,
413,
395,
288,
3164,
534,
271,
8277,
10562,
6304,
297,
288,
3421,
2687,
378,
12,
221,
1275,
21,
395,
267,
776,
267,
27751,
275,
291,
14,
525,
63,
10654,
8,
288,
283,
9765,
297,
288,
2536,
63,
929,
29,
16,
12,
288,
950,
390,
13441,
2687,
16,
12,
413,
395,
288,
3164,
26431,
5745,
993,
297,
288,
3421,
26154,
17,
12,
378,
221,
2318,
267,
776,
267,
1323,
275,
291,
14,
525,
63,
5159,
63,
1210,
8,
288,
283,
56,
297,
288,
3164,
534,
8399,
297,
288,
3421,
2687,
413,
12,
221,
1275,
21,
395,
288,
1324,
63,
1593,
29,
56,
63,
5159,
63,
1210,
12,
288,
1324,
63,
1162,
29,
46,
14,
5605,
8,
17,
12,
291,
14,
52,
395,
267,
776,
2728,
327,
267,
327,
2654,
1924,
5558,
465,
282,
1211,
4412,
3805,
397,
370,
6363,
436,
282,
9565,
805,
267,
327,
267,
24756,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
9115,
297,
288,
469,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
25262,
12,
1804,
50,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
25262,
12,
1804,
50,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
394,
66,
63,
7697,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
16168,
14382,
288,
4153,
3126,
221,
869,
34,
520,
15599,
63,
1997,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
23063,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
23063,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
1022,
82,
63,
7697,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
27399,
14382,
288,
4153,
3126,
221,
1804,
50,
520,
15599,
63,
1997,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
25262,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
25262,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
299,
6428,
63,
7697,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
80,
6428,
14382,
288,
4153,
3126,
510,
17751,
520,
15599,
63,
1997,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
25262,
12,
1804,
50,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
25262,
12,
1804,
50,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
14984,
63,
7697,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
9765,
14382,
288,
4153,
3126,
27751,
520,
15599,
63,
1997,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
25262,
12,
1804,
50,
12,
510,
17751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
25262,
12,
1804,
50,
12,
510,
17751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
394,
66,
63,
13361,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
16168,
31249,
288,
4153,
3126,
221,
869,
34,
520,
15599,
63,
265,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12
] |
[
199,
3,
1898,
17815,
799,
344,
6171,
199,
3,
421,
199,
624,
199,
9846,
370,
22907,
11409,
323,
4223,
402,
1134,
2245,
14,
21311,
641,
1295,
6109,
89,
2784,
315,
15220,
199,
265,
23399,
4171,
1334,
22380,
5828,
701,
653,
24685,
8047,
391,
10844,
741,
14,
199,
624,
199,
199,
646,
2680,
465,
653,
12,
2050,
199,
504,
1134,
2245,
14,
9882,
492,
15599,
63,
1997,
12,
15599,
63,
265,
199,
504,
1134,
2245,
492,
2784,
12,
9565,
4388,
199,
533,
24905,
8,
9882,
14,
25285,
304,
272,
408,
272,
6288,
13,
576,
367,
366,
4796,
24316,
25330,
1279,
9129,
10654,
2316,
1295,
6109,
89,
5591,
11759,
315,
653,
24685,
8047,
391,
15220,
14,
2286,
2900,
1134,
2245,
2897,
365,
4224,
4012,
3004,
402,
642,
1021,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
298,
11493,
2122,
2728,
327,
267,
327,
6026,
572,
314,
1300,
1021,
267,
327,
267,
1613,
8,
25285,
12,
291,
2843,
826,
4533,
398,
327,
267,
327,
710,
1329,
402,
900,
7124,
370,
3363,
572,
14,
267,
327,
267,
291,
14,
52,
275,
3144,
523,
267,
327,
267,
327,
2654,
314,
3805,
397,
267,
327,
267,
14056,
48,
275,
291,
14,
525,
63,
5159,
63,
1210,
8,
288,
283,
2772,
80,
297,
288,
3164,
534,
6653,
11045,
297,
288,
3421,
2687,
413,
12,
413,
14,
21,
395,
288,
1324,
63,
1593,
29,
2772,
80,
63,
5159,
63,
1210,
12,
288,
1324,
63,
1162,
2687,
403,
4706,
267,
776,
267,
869,
34,
275,
291,
14,
525,
63,
10654,
8,
288,
283,
16168,
297,
288,
2536,
63,
929,
29,
17,
12,
288,
950,
390,
13441,
2687,
16,
12,
413,
395,
288,
3164,
534,
7731,
297,
288,
3421,
2687,
378,
12,
413,
14,
21,
395,
267,
776,
267,
1804,
50,
275,
291,
14,
525,
63,
10654,
8,
288,
283,
27399,
297,
288,
2536,
63,
929,
29,
16,
12,
288,
950,
390,
13441,
2687,
16,
12,
413,
395,
288,
3164,
534,
13625,
6304,
297,
288,
3421,
26154,
17,
12,
413,
221,
2318,
267,
776,
267,
510,
17751,
275,
291,
14,
525,
63,
10654,
8,
288,
283,
80,
6428,
297,
288,
2536,
63,
929,
29,
16,
12,
288,
950,
390,
13441,
2687,
16,
12,
413,
395,
288,
3164,
534,
271,
8277,
10562,
6304,
297,
288,
3421,
2687,
378,
12,
221,
1275,
21,
395,
267,
776,
267,
27751,
275,
291,
14,
525,
63,
10654,
8,
288,
283,
9765,
297,
288,
2536,
63,
929,
29,
16,
12,
288,
950,
390,
13441,
2687,
16,
12,
413,
395,
288,
3164,
26431,
5745,
993,
297,
288,
3421,
26154,
17,
12,
378,
221,
2318,
267,
776,
267,
1323,
275,
291,
14,
525,
63,
5159,
63,
1210,
8,
288,
283,
56,
297,
288,
3164,
534,
8399,
297,
288,
3421,
2687,
413,
12,
221,
1275,
21,
395,
288,
1324,
63,
1593,
29,
56,
63,
5159,
63,
1210,
12,
288,
1324,
63,
1162,
29,
46,
14,
5605,
8,
17,
12,
291,
14,
52,
395,
267,
776,
2728,
327,
267,
327,
2654,
1924,
5558,
465,
282,
1211,
4412,
3805,
397,
370,
6363,
436,
282,
9565,
805,
267,
327,
267,
24756,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
9115,
297,
288,
469,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
25262,
12,
1804,
50,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
25262,
12,
1804,
50,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
394,
66,
63,
7697,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
16168,
14382,
288,
4153,
3126,
221,
869,
34,
520,
15599,
63,
1997,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
23063,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
23063,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
1022,
82,
63,
7697,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
27399,
14382,
288,
4153,
3126,
221,
1804,
50,
520,
15599,
63,
1997,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
25262,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
25262,
12,
510,
17751,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
299,
6428,
63,
7697,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
80,
6428,
14382,
288,
4153,
3126,
510,
17751,
520,
15599,
63,
1997,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
25262,
12,
1804,
50,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
25262,
12,
1804,
50,
12,
27751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
14984,
63,
7697,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
9765,
14382,
288,
4153,
3126,
27751,
520,
15599,
63,
1997,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
334,
25262,
12,
1804,
50,
12,
510,
17751,
1826,
355,
334,
9882,
14,
8936,
63,
1864,
15048,
934,
5399,
63,
10596,
540,
1309,
12,
334,
25262,
12,
1804,
50,
12,
510,
17751,
1826,
355,
334,
9882,
14,
8936,
63,
615,
63,
2566,
63,
7517,
63,
18079,
12,
1323,
395,
288,
776,
267,
776,
267,
394,
66,
63,
13361,
275,
291,
14,
525,
63,
5394,
8,
288,
283,
16168,
31249,
288,
4153,
3126,
221,
869,
34,
520,
15599,
63,
265,
1660,
288,
9565,
2687,
355,
334,
9882,
14,
8936,
63,
12125,
63,
3359,
63,
1438,
5786,
1075,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
bonitadecker77/python-for-android
|
python3-alpha/python3-src/Lib/distutils/tests/test_install_data.py
|
147
|
2603
|
"""Tests for distutils.command.install_data."""
import sys
import os
import unittest
import getpass
from distutils.command.install_data import install_data
from distutils.tests import support
from test.support import run_unittest
class InstallDataTestCase(support.TempdirManager,
support.LoggingSilencer,
support.EnvironGuard,
unittest.TestCase):
def test_simple_run(self):
pkg_dir, dist = self.create_dist()
cmd = install_data(dist)
cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
# data_files can contain
# - simple files
# - a tuple with a path, and a list of file
one = os.path.join(pkg_dir, 'one')
self.write_file(one, 'xxx')
inst2 = os.path.join(pkg_dir, 'inst2')
two = os.path.join(pkg_dir, 'two')
self.write_file(two, 'xxx')
cmd.data_files = [one, (inst2, [two])]
self.assertEqual(cmd.get_inputs(), [one, (inst2, [two])])
# let's run the command
cmd.ensure_finalized()
cmd.run()
# let's check the result
self.assertEqual(len(cmd.get_outputs()), 2)
rtwo = os.path.split(two)[-1]
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
rone = os.path.split(one)[-1]
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
cmd.outfiles = []
# let's try with warn_dir one
cmd.warn_dir = 1
cmd.ensure_finalized()
cmd.run()
# let's check the result
self.assertEqual(len(cmd.get_outputs()), 2)
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
cmd.outfiles = []
# now using root and empty dir
cmd.root = os.path.join(pkg_dir, 'root')
inst3 = os.path.join(cmd.install_dir, 'inst3')
inst4 = os.path.join(pkg_dir, 'inst4')
three = os.path.join(cmd.install_dir, 'three')
self.write_file(three, 'xx')
cmd.data_files = [one, (inst2, [two]),
('inst3', [three]),
(inst4, [])]
cmd.ensure_finalized()
cmd.run()
# let's check the result
self.assertEqual(len(cmd.get_outputs()), 4)
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
def test_suite():
return unittest.makeSuite(InstallDataTestCase)
if __name__ == "__main__":
run_unittest(test_suite())
|
apache-2.0
|
[
624,
2925,
367,
7065,
14,
1531,
14,
3174,
63,
576,
1041,
199,
646,
984,
199,
646,
747,
199,
646,
2882,
199,
646,
18354,
199,
199,
504,
7065,
14,
1531,
14,
3174,
63,
576,
492,
3907,
63,
576,
199,
504,
7065,
14,
2219,
492,
2291,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
199,
199,
533,
13276,
1451,
1746,
8,
4058,
14,
6530,
694,
2988,
12,
2079,
2291,
14,
14054,
51,
441,
78,
2247,
12,
2079,
2291,
14,
23027,
18183,
12,
2079,
2882,
14,
1746,
304,
339,
347,
511,
63,
4129,
63,
1065,
8,
277,
304,
267,
5496,
63,
694,
12,
2917,
275,
291,
14,
981,
63,
2686,
342,
267,
2088,
275,
3907,
63,
576,
8,
2686,
9,
267,
2088,
14,
3174,
63,
694,
275,
2727,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
3615,
358,
398,
327,
666,
63,
1725,
883,
1395,
267,
327,
221,
446,
3486,
1584,
267,
327,
221,
446,
282,
2008,
543,
282,
931,
12,
436,
282,
769,
402,
570,
267,
1373,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
368,
358,
267,
291,
14,
952,
63,
493,
8,
368,
12,
283,
10013,
358,
267,
2727,
18,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
3615,
18,
358,
267,
2877,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
5601,
358,
267,
291,
14,
952,
63,
493,
8,
5601,
12,
283,
10013,
358,
398,
2088,
14,
576,
63,
1725,
275,
359,
368,
12,
334,
3615,
18,
12,
359,
5601,
12457,
267,
291,
14,
629,
8,
1760,
14,
362,
63,
3711,
1062,
359,
368,
12,
334,
3615,
18,
12,
359,
5601,
24310,
398,
327,
4691,
1159,
1255,
314,
1414,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
398,
327,
4691,
1159,
1104,
314,
754,
267,
291,
14,
629,
8,
552,
8,
1760,
14,
362,
63,
4467,
4000,
499,
9,
267,
519,
5601,
275,
747,
14,
515,
14,
1294,
8,
5601,
15786,
17,
61,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
18,
12,
519,
5601,
1724,
267,
519,
368,
275,
747,
14,
515,
14,
1294,
8,
368,
15786,
17,
61,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
12,
519,
368,
1724,
267,
2088,
14,
548,
1725,
275,
942,
398,
327,
4691,
1159,
862,
543,
7987,
63,
694,
1373,
267,
2088,
14,
4050,
63,
694,
275,
413,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
398,
327,
4691,
1159,
1104,
314,
754,
267,
291,
14,
629,
8,
552,
8,
1760,
14,
362,
63,
4467,
4000,
499,
9,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
18,
12,
519,
5601,
1724,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
12,
519,
368,
1724,
267,
2088,
14,
548,
1725,
275,
942,
398,
327,
3063,
1808,
1738,
436,
2701,
2935,
267,
2088,
14,
1231,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
1231,
358,
267,
2727,
19,
275,
747,
14,
515,
14,
904,
8,
1760,
14,
3174,
63,
694,
12,
283,
3615,
19,
358,
267,
2727,
20,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
3615,
20,
358,
267,
7795,
275,
747,
14,
515,
14,
904,
8,
1760,
14,
3174,
63,
694,
12,
283,
10480,
358,
267,
291,
14,
952,
63,
493,
8,
10480,
12,
283,
2154,
358,
267,
2088,
14,
576,
63,
1725,
275,
359,
368,
12,
334,
3615,
18,
12,
359,
5601,
2522,
2079,
661,
3615,
19,
297,
359,
10480,
2522,
2079,
334,
3615,
20,
12,
3073,
61,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
398,
327,
4691,
1159,
1104,
314,
754,
267,
291,
14,
629,
8,
552,
8,
1760,
14,
362,
63,
4467,
4000,
841,
9,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
18,
12,
519,
5601,
1724,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
12,
519,
368,
1724,
199,
199,
318,
511,
63,
5768,
837,
272,
372,
2882,
14,
18275,
8,
8154,
1451,
1746,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
2796,
8,
396,
63,
5768,
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
] |
[
2925,
367,
7065,
14,
1531,
14,
3174,
63,
576,
1041,
199,
646,
984,
199,
646,
747,
199,
646,
2882,
199,
646,
18354,
199,
199,
504,
7065,
14,
1531,
14,
3174,
63,
576,
492,
3907,
63,
576,
199,
504,
7065,
14,
2219,
492,
2291,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
199,
199,
533,
13276,
1451,
1746,
8,
4058,
14,
6530,
694,
2988,
12,
2079,
2291,
14,
14054,
51,
441,
78,
2247,
12,
2079,
2291,
14,
23027,
18183,
12,
2079,
2882,
14,
1746,
304,
339,
347,
511,
63,
4129,
63,
1065,
8,
277,
304,
267,
5496,
63,
694,
12,
2917,
275,
291,
14,
981,
63,
2686,
342,
267,
2088,
275,
3907,
63,
576,
8,
2686,
9,
267,
2088,
14,
3174,
63,
694,
275,
2727,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
3615,
358,
398,
327,
666,
63,
1725,
883,
1395,
267,
327,
221,
446,
3486,
1584,
267,
327,
221,
446,
282,
2008,
543,
282,
931,
12,
436,
282,
769,
402,
570,
267,
1373,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
368,
358,
267,
291,
14,
952,
63,
493,
8,
368,
12,
283,
10013,
358,
267,
2727,
18,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
3615,
18,
358,
267,
2877,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
5601,
358,
267,
291,
14,
952,
63,
493,
8,
5601,
12,
283,
10013,
358,
398,
2088,
14,
576,
63,
1725,
275,
359,
368,
12,
334,
3615,
18,
12,
359,
5601,
12457,
267,
291,
14,
629,
8,
1760,
14,
362,
63,
3711,
1062,
359,
368,
12,
334,
3615,
18,
12,
359,
5601,
24310,
398,
327,
4691,
1159,
1255,
314,
1414,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
398,
327,
4691,
1159,
1104,
314,
754,
267,
291,
14,
629,
8,
552,
8,
1760,
14,
362,
63,
4467,
4000,
499,
9,
267,
519,
5601,
275,
747,
14,
515,
14,
1294,
8,
5601,
15786,
17,
61,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
18,
12,
519,
5601,
1724,
267,
519,
368,
275,
747,
14,
515,
14,
1294,
8,
368,
15786,
17,
61,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
12,
519,
368,
1724,
267,
2088,
14,
548,
1725,
275,
942,
398,
327,
4691,
1159,
862,
543,
7987,
63,
694,
1373,
267,
2088,
14,
4050,
63,
694,
275,
413,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
398,
327,
4691,
1159,
1104,
314,
754,
267,
291,
14,
629,
8,
552,
8,
1760,
14,
362,
63,
4467,
4000,
499,
9,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
18,
12,
519,
5601,
1724,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
12,
519,
368,
1724,
267,
2088,
14,
548,
1725,
275,
942,
398,
327,
3063,
1808,
1738,
436,
2701,
2935,
267,
2088,
14,
1231,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
1231,
358,
267,
2727,
19,
275,
747,
14,
515,
14,
904,
8,
1760,
14,
3174,
63,
694,
12,
283,
3615,
19,
358,
267,
2727,
20,
275,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
283,
3615,
20,
358,
267,
7795,
275,
747,
14,
515,
14,
904,
8,
1760,
14,
3174,
63,
694,
12,
283,
10480,
358,
267,
291,
14,
952,
63,
493,
8,
10480,
12,
283,
2154,
358,
267,
2088,
14,
576,
63,
1725,
275,
359,
368,
12,
334,
3615,
18,
12,
359,
5601,
2522,
2079,
661,
3615,
19,
297,
359,
10480,
2522,
2079,
334,
3615,
20,
12,
3073,
61,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
398,
327,
4691,
1159,
1104,
314,
754,
267,
291,
14,
629,
8,
552,
8,
1760,
14,
362,
63,
4467,
4000,
841,
9,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
18,
12,
519,
5601,
1724,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
3615,
12,
519,
368,
1724,
199,
199,
318,
511,
63,
5768,
837,
272,
372,
2882,
14,
18275,
8,
8154,
1451,
1746,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
2796,
8,
396,
63,
5768,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nacho/gedit
|
plugins/snippets/snippets/SubstitutionParser.py
|
2
|
7459
|
# Gedit snippets plugin
# Copyright (C) 2006-2007 Jesse van den Kieboom <jesse@icecrew.nl>
#
# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
import re
class ParseError(Exception):
def __str__(self):
return 'Parse error, resume next'
class Modifiers:
def _first_char(s):
first = (s != '' and s[0]) or ''
rest = (len(s) > 1 and s[1:]) or ''
return first, rest
def upper_first(s):
first, rest = Modifiers._first_char(s)
return '%s%s' % (first.upper(), rest)
def upper(s):
return s.upper()
def lower_first(s):
first, rest = Modifiers._first_char(s)
return '%s%s' % (first.lower(), rest)
def lower(s):
return s.lower()
def title(s):
return s.title()
upper_first = staticmethod(upper_first)
upper = staticmethod(upper)
lower_first = staticmethod(lower_first)
lower = staticmethod(lower)
title = staticmethod(title)
_first_char = staticmethod(_first_char)
class SubstitutionParser:
REG_ID = '[0-9]+'
REG_NAME = '[a-zA-Z_]+'
REG_MOD = '[a-zA-Z]+'
REG_ESCAPE = '\\\\|\\(\\?|,|\\)'
def __init__(self, pattern, groups = {}, modifiers = {}):
self.pattern = pattern
self.groups = groups
self.REG_GROUP = '(?:(%s)|<(%s|%s)(?:,(%s))?>)' % (self.REG_ID, self.REG_ID, self.REG_NAME, self.REG_MOD)
self.modifiers = {'u': Modifiers.upper_first,
'U': Modifiers.upper,
'l': Modifiers.lower_first,
'L': Modifiers.lower,
't': Modifiers.title}
for k, v in modifiers.items():
self.modifiers[k] = v
def parse(self):
result, tokens = self._parse(self.pattern, None)
return result
def _parse(self, tokens, terminator):
result = ''
while tokens != '':
if self._peek(tokens) == '' or self._peek(tokens) == terminator:
tokens = self._remains(tokens)
break
try:
res, tokens = self._expr(tokens, terminator)
except ParseError:
res, tokens = self._text(tokens)
result += res
return result, tokens
def _peek(self, tokens, num = 0):
return (num < len(tokens) and tokens[num])
def _token(self, tokens):
if tokens == '':
return '', '';
return tokens[0], (len(tokens) > 1 and tokens[1:]) or ''
def _remains(self, tokens, num = 1):
return (num < len(tokens) and tokens[num:]) or ''
def _expr(self, tokens, terminator):
if tokens == '':
return ''
try:
return {'\\': self._escape,
'(': self._condition}[self._peek(tokens)](tokens, terminator)
except KeyError:
raise ParseError
def _text(self, tokens):
return self._token(tokens)
def _substitute(self, group, modifiers = ''):
result = (self.groups.has_key(group) and self.groups[group]) or ''
for modifier in modifiers:
if self.modifiers.has_key(modifier):
result = self.modifiers[modifier](result)
return result
def _match_group(self, tokens):
match = re.match('\\\\%s' % self.REG_GROUP, tokens)
if not match:
return None, tokens
return self._substitute(match.group(1) or match.group(2), match.group(3) or ''), tokens[match.end():]
def _escape(self, tokens, terminator):
# Try to match a group
result, tokens = self._match_group(tokens)
if result != None:
return result, tokens
s = self.REG_GROUP
if terminator:
s += '|%s' % re.escape(terminator)
match = re.match('\\\\(\\\\%s|%s)' % (s, self.REG_ESCAPE), tokens)
if not match:
raise ParseError
return match.group(1), tokens[match.end():]
def _condition_value(self, tokens):
match = re.match('\\\\?%s\s*' % self.REG_GROUP, tokens)
if not match:
return None, tokens
groups = match.groups()
name = groups[0] or groups[1]
return self.groups.has_key(name) and self.groups[name] != None, tokens[match.end():]
def _condition(self, tokens, terminator):
# Match ? after (
if self._peek(tokens, 1) != '?':
raise ParseError
# Remove initial (? token
tokens = self._remains(tokens, 2)
condition, tokens = self._condition_value(tokens)
if condition == None or self._peek(tokens) != ',':
raise ParseError
truepart, tokens = self._parse(self._remains(tokens), ',')
if truepart == None:
raise ParseError
falsepart, tokens = self._parse(tokens, ')')
if falsepart == None:
raise ParseError
if condition:
return truepart, tokens
else:
return falsepart, tokens
def escape_substitution(substitution):
return re.sub('(%s|%s)' % (self.REG_GROUP, self.REG_ESCAPE), '\\\\\\1', substitution)
escapesubstitution = staticmethod(escape_substitution)
# ex:ts=8:et:
|
gpl-2.0
|
[
3,
259,
598,
3773,
19484,
3589,
199,
3,
259,
1898,
334,
35,
9,
8315,
13,
9488,
221,
1603,
397,
261,
20744,
5376,
1804,
1873,
656,
676,
665,
74,
397,
261,
32,
1885,
1353,
87,
14,
7530,
30,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
259,
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,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
259,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
199,
646,
295,
199,
199,
533,
21743,
8,
1726,
304,
267,
347,
636,
495,
721,
277,
304,
355,
372,
283,
4003,
1125,
12,
14604,
2163,
7,
199,
199,
533,
12972,
6069,
26,
267,
347,
485,
2246,
63,
1560,
8,
83,
304,
355,
1642,
275,
334,
83,
1137,
2125,
436,
308,
59,
16,
566,
503,
2125,
355,
4618,
275,
334,
552,
8,
83,
9,
690,
413,
436,
308,
59,
17,
5728,
503,
2125,
14977,
372,
1642,
12,
4618,
2728,
347,
7008,
63,
2246,
8,
83,
304,
355,
1642,
12,
4618,
275,
12972,
6069,
423,
2246,
63,
1560,
8,
83,
9,
2234,
372,
1543,
83,
5,
83,
7,
450,
334,
2246,
14,
4142,
1062,
4618,
9,
398,
347,
7008,
8,
83,
304,
355,
372,
308,
14,
4142,
342,
398,
347,
5117,
63,
2246,
8,
83,
304,
355,
1642,
12,
4618,
275,
12972,
6069,
423,
2246,
63,
1560,
8,
83,
9,
2234,
372,
1543,
83,
5,
83,
7,
450,
334,
2246,
14,
2325,
1062,
4618,
9,
21695,
347,
5117,
8,
83,
304,
355,
372,
308,
14,
2325,
342,
21695,
347,
2538,
8,
83,
304,
355,
372,
308,
14,
1213,
342,
2728,
7008,
63,
2246,
275,
12822,
8,
4142,
63,
2246,
9,
267,
7008,
275,
12822,
8,
4142,
9,
267,
5117,
63,
2246,
275,
12822,
8,
2325,
63,
2246,
9,
267,
5117,
275,
12822,
8,
2325,
9,
267,
2538,
275,
12822,
8,
1213,
9,
267,
485,
2246,
63,
1560,
275,
12822,
1547,
2246,
63,
1560,
9,
199,
199,
533,
4804,
26575,
2842,
26,
267,
14142,
63,
998,
275,
6730,
16,
13,
25,
28012,
267,
14142,
63,
2339,
275,
6730,
65,
13,
6353,
13,
58,
22155,
7,
267,
14142,
63,
8816,
275,
6730,
65,
13,
6353,
13,
58,
28012,
267,
14142,
63,
28879,
275,
31375,
17780,
27910,
31,
18712,
17780,
3171,
398,
347,
636,
826,
721,
277,
12,
3851,
12,
4652,
275,
5479,
9933,
275,
1052,
304,
355,
291,
14,
3401,
275,
3851,
355,
291,
14,
2634,
275,
4652,
14977,
291,
14,
5616,
63,
7823,
275,
283,
5169,
4042,
83,
8636,
28,
4042,
83,
15287,
83,
9,
5169,
12,
4042,
83,
22119,
30,
3171,
450,
334,
277,
14,
5616,
63,
998,
12,
291,
14,
5616,
63,
998,
12,
291,
14,
5616,
63,
2339,
12,
291,
14,
5616,
63,
8816,
9,
355,
291,
14,
17431,
275,
791,
85,
356,
12972,
6069,
14,
4142,
63,
2246,
12,
3303,
283,
53,
356,
12972,
6069,
14,
4142,
12,
3303,
283,
76,
356,
12972,
6069,
14,
2325,
63,
2246,
12,
3303,
283,
44,
356,
12972,
6069,
14,
2325,
12,
3303,
283,
84,
356,
12972,
6069,
14,
1213,
93,
14977,
367,
1022,
12,
373,
315,
9933,
14,
1744,
837,
717,
291,
14,
17431,
59,
75,
61,
275,
373,
2728,
347,
2198,
8,
277,
304,
355,
754,
12,
4645,
275,
291,
423,
1122,
8,
277,
14,
3401,
12,
488,
9,
14977,
372,
754,
2728,
347,
485,
1122,
8,
277,
12,
4645,
12,
31298,
304,
355,
754,
275,
2125,
2234,
1830,
4645,
1137,
8061,
717,
340,
291,
423,
13164,
8,
4504,
9,
508,
2125,
503,
291,
423,
13164,
8,
4504,
9,
508,
31298,
26,
1816,
4645,
275,
291,
423,
8902,
83,
8,
4504,
9,
1816,
2059,
9453,
862,
26,
1816,
522,
12,
4645,
275,
291,
423,
3684,
8,
4504,
12,
31298,
9,
717,
871,
21743,
26,
1816,
522,
12,
4645,
275,
291,
423,
505,
8,
4504,
9,
586,
717,
754,
847,
522,
639,
355,
372,
754,
12,
4645,
267,
267,
347,
485,
13164,
8,
277,
12,
4645,
12,
1967,
275,
378,
304,
355,
372,
334,
1507,
665,
822,
8,
4504,
9,
436,
4645,
59,
1507,
566,
2728,
347,
485,
1418,
8,
277,
12,
4645,
304,
355,
340,
4645,
508,
8061,
717,
372,
3260,
2125,
27,
2234,
372,
4645,
59,
16,
467,
334,
552,
8,
4504,
9,
690,
413,
436,
4645,
59,
17,
5728,
503,
2125,
2728,
347,
485,
8902,
83,
8,
277,
12,
4645,
12,
1967,
275,
413,
304,
355,
372,
334,
1507,
665,
822,
8,
4504,
9,
436,
4645,
59,
1507,
5728,
503,
2125,
398,
347,
485,
3684,
8,
277,
12,
4645,
12,
31298,
304,
463,
355,
340,
4645,
508,
8061,
717,
372,
2125,
2234,
862,
26,
717,
372,
791,
1103,
356,
291,
423,
3765,
12,
1816,
283,
6176,
291,
423,
5394,
22857,
277,
423,
13164,
8,
4504,
1874,
8,
4504,
12,
31298,
9,
355,
871,
4067,
26,
717,
746,
21743,
398,
347,
485,
505,
8,
277,
12,
4645,
304,
355,
372,
291,
423,
1418,
8,
4504,
9,
398,
347,
485,
20374,
8,
277,
12,
1572,
12,
9933,
275,
21019,
355,
754,
275,
334,
277,
14,
2634,
14,
1989,
63,
498,
8,
923,
9,
436,
291,
14,
2634,
59,
923,
566,
503,
2125,
14977,
367,
17880,
315,
9933,
26,
717,
340,
291,
14,
17431,
14,
1989,
63,
498,
8,
18156,
304,
1816,
754,
275,
291,
14,
17431,
59,
18156,
8738,
1099,
9,
14977,
372,
754,
21695,
347,
485,
1431,
63,
923,
8
] |
[
259,
598,
3773,
19484,
3589,
199,
3,
259,
1898,
334,
35,
9,
8315,
13,
9488,
221,
1603,
397,
261,
20744,
5376,
1804,
1873,
656,
676,
665,
74,
397,
261,
32,
1885,
1353,
87,
14,
7530,
30,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
259,
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,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
259,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
199,
646,
295,
199,
199,
533,
21743,
8,
1726,
304,
267,
347,
636,
495,
721,
277,
304,
355,
372,
283,
4003,
1125,
12,
14604,
2163,
7,
199,
199,
533,
12972,
6069,
26,
267,
347,
485,
2246,
63,
1560,
8,
83,
304,
355,
1642,
275,
334,
83,
1137,
2125,
436,
308,
59,
16,
566,
503,
2125,
355,
4618,
275,
334,
552,
8,
83,
9,
690,
413,
436,
308,
59,
17,
5728,
503,
2125,
14977,
372,
1642,
12,
4618,
2728,
347,
7008,
63,
2246,
8,
83,
304,
355,
1642,
12,
4618,
275,
12972,
6069,
423,
2246,
63,
1560,
8,
83,
9,
2234,
372,
1543,
83,
5,
83,
7,
450,
334,
2246,
14,
4142,
1062,
4618,
9,
398,
347,
7008,
8,
83,
304,
355,
372,
308,
14,
4142,
342,
398,
347,
5117,
63,
2246,
8,
83,
304,
355,
1642,
12,
4618,
275,
12972,
6069,
423,
2246,
63,
1560,
8,
83,
9,
2234,
372,
1543,
83,
5,
83,
7,
450,
334,
2246,
14,
2325,
1062,
4618,
9,
21695,
347,
5117,
8,
83,
304,
355,
372,
308,
14,
2325,
342,
21695,
347,
2538,
8,
83,
304,
355,
372,
308,
14,
1213,
342,
2728,
7008,
63,
2246,
275,
12822,
8,
4142,
63,
2246,
9,
267,
7008,
275,
12822,
8,
4142,
9,
267,
5117,
63,
2246,
275,
12822,
8,
2325,
63,
2246,
9,
267,
5117,
275,
12822,
8,
2325,
9,
267,
2538,
275,
12822,
8,
1213,
9,
267,
485,
2246,
63,
1560,
275,
12822,
1547,
2246,
63,
1560,
9,
199,
199,
533,
4804,
26575,
2842,
26,
267,
14142,
63,
998,
275,
6730,
16,
13,
25,
28012,
267,
14142,
63,
2339,
275,
6730,
65,
13,
6353,
13,
58,
22155,
7,
267,
14142,
63,
8816,
275,
6730,
65,
13,
6353,
13,
58,
28012,
267,
14142,
63,
28879,
275,
31375,
17780,
27910,
31,
18712,
17780,
3171,
398,
347,
636,
826,
721,
277,
12,
3851,
12,
4652,
275,
5479,
9933,
275,
1052,
304,
355,
291,
14,
3401,
275,
3851,
355,
291,
14,
2634,
275,
4652,
14977,
291,
14,
5616,
63,
7823,
275,
283,
5169,
4042,
83,
8636,
28,
4042,
83,
15287,
83,
9,
5169,
12,
4042,
83,
22119,
30,
3171,
450,
334,
277,
14,
5616,
63,
998,
12,
291,
14,
5616,
63,
998,
12,
291,
14,
5616,
63,
2339,
12,
291,
14,
5616,
63,
8816,
9,
355,
291,
14,
17431,
275,
791,
85,
356,
12972,
6069,
14,
4142,
63,
2246,
12,
3303,
283,
53,
356,
12972,
6069,
14,
4142,
12,
3303,
283,
76,
356,
12972,
6069,
14,
2325,
63,
2246,
12,
3303,
283,
44,
356,
12972,
6069,
14,
2325,
12,
3303,
283,
84,
356,
12972,
6069,
14,
1213,
93,
14977,
367,
1022,
12,
373,
315,
9933,
14,
1744,
837,
717,
291,
14,
17431,
59,
75,
61,
275,
373,
2728,
347,
2198,
8,
277,
304,
355,
754,
12,
4645,
275,
291,
423,
1122,
8,
277,
14,
3401,
12,
488,
9,
14977,
372,
754,
2728,
347,
485,
1122,
8,
277,
12,
4645,
12,
31298,
304,
355,
754,
275,
2125,
2234,
1830,
4645,
1137,
8061,
717,
340,
291,
423,
13164,
8,
4504,
9,
508,
2125,
503,
291,
423,
13164,
8,
4504,
9,
508,
31298,
26,
1816,
4645,
275,
291,
423,
8902,
83,
8,
4504,
9,
1816,
2059,
9453,
862,
26,
1816,
522,
12,
4645,
275,
291,
423,
3684,
8,
4504,
12,
31298,
9,
717,
871,
21743,
26,
1816,
522,
12,
4645,
275,
291,
423,
505,
8,
4504,
9,
586,
717,
754,
847,
522,
639,
355,
372,
754,
12,
4645,
267,
267,
347,
485,
13164,
8,
277,
12,
4645,
12,
1967,
275,
378,
304,
355,
372,
334,
1507,
665,
822,
8,
4504,
9,
436,
4645,
59,
1507,
566,
2728,
347,
485,
1418,
8,
277,
12,
4645,
304,
355,
340,
4645,
508,
8061,
717,
372,
3260,
2125,
27,
2234,
372,
4645,
59,
16,
467,
334,
552,
8,
4504,
9,
690,
413,
436,
4645,
59,
17,
5728,
503,
2125,
2728,
347,
485,
8902,
83,
8,
277,
12,
4645,
12,
1967,
275,
413,
304,
355,
372,
334,
1507,
665,
822,
8,
4504,
9,
436,
4645,
59,
1507,
5728,
503,
2125,
398,
347,
485,
3684,
8,
277,
12,
4645,
12,
31298,
304,
463,
355,
340,
4645,
508,
8061,
717,
372,
2125,
2234,
862,
26,
717,
372,
791,
1103,
356,
291,
423,
3765,
12,
1816,
283,
6176,
291,
423,
5394,
22857,
277,
423,
13164,
8,
4504,
1874,
8,
4504,
12,
31298,
9,
355,
871,
4067,
26,
717,
746,
21743,
398,
347,
485,
505,
8,
277,
12,
4645,
304,
355,
372,
291,
423,
1418,
8,
4504,
9,
398,
347,
485,
20374,
8,
277,
12,
1572,
12,
9933,
275,
21019,
355,
754,
275,
334,
277,
14,
2634,
14,
1989,
63,
498,
8,
923,
9,
436,
291,
14,
2634,
59,
923,
566,
503,
2125,
14977,
367,
17880,
315,
9933,
26,
717,
340,
291,
14,
17431,
14,
1989,
63,
498,
8,
18156,
304,
1816,
754,
275,
291,
14,
17431,
59,
18156,
8738,
1099,
9,
14977,
372,
754,
21695,
347,
485,
1431,
63,
923,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
chaicko/AlgorithmicToolbox
|
test/test_divide_and_conquer.py
|
1
|
8325
|
import divide_and_conquer.binary_search as binary_search
import divide_and_conquer.inversions as inversions
import divide_and_conquer.majority_element as majority_element
import divide_and_conquer.points_and_segments as points_and_segments
import divide_and_conquer.sorting as sorting
import pytest
@pytest.mark.timeout(10) # 10 seconds timeout for binary this tests
class TestBinarySearch:
@pytest.mark.parametrize("test_input,expected", [
(([5, 1, 5, 8, 12, 13], [5, 8, 1, 23, 1, 11]), "2 0 -1 0 -1")
])
def test_sample(self, test_input, expected, main_runner):
assert expected in main_runner(binary_search, test_input)
def test_worst_case(self):
a = [i for i in range(10 ** 5)]
assert len(a) - 1 == binary_search.binary_search(a, a[-1])
def test_middle_element_even(self):
a = [i for i in range(10 ** 5)]
assert len(a) // 2 == binary_search.binary_search(a, a[len(a) // 2])
def test_middle_element_odd(self):
a = [i for i in range(10 ** 5 - 1)]
assert len(a) // 2 == binary_search.binary_search(a, a[len(a) // 2])
def test_worst_problem_size(self):
a = [i for i in range(10 ** 5)]
for x in range(len(a), len(a) + 10 ** 5):
assert -1 == binary_search.binary_search(a, x)
def test_2_grader(self, main_runner):
test_input = ([10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
[12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
expected = "-1 0 1 2 3 4 5 6 7 8 9 -1"
assert expected in main_runner(binary_search, test_input)
def test_linear_vs_binary(self):
a = [i for i in range(20)]
for i, x in enumerate(a):
lin_r = binary_search.linear_search(a, x)
assert i == lin_r
bin_r = binary_search.binary_search(a, x)
assert i == bin_r
lin_r = binary_search.linear_search(a, a[-1] + 1)
assert -1 == lin_r
bin_r = binary_search.binary_search(a, a[-1] + 1)
assert -1 == bin_r
class TestInversions:
@pytest.mark.parametrize("test_input,expected", [
(([5], [2, 3, 9, 2, 9]), "2")
])
def test_samples(self, test_input, expected, main_runner):
assert expected in main_runner(inversions, test_input)
class TestMajorityElement:
@pytest.mark.parametrize("test_input,expected", [
(([5], [2, 3, 9, 2, 2]), "1"),
(([4], [1, 2, 3, 4]), "0"),
(([4], [1, 2, 3, 1]), "0")
])
def test_sample(self, test_input, expected, main_runner):
assert expected in main_runner(majority_element, test_input)
def test_3_grader(self, main_runner):
test_input = ([10],
[2, 124554847, 2, 941795895, 2, 2, 2, 2, 792755190,
756617003])
expected = "1"
assert expected in main_runner(majority_element, test_input)
def test_one_element(self, main_runner):
test_input = ([1], [1])
expected = "1"
assert expected in main_runner(majority_element, test_input)
def test_two_different_elements(self, main_runner):
test_input = ([2], [1, 2])
expected = "0"
assert expected in main_runner(majority_element, test_input)
def test_two_equal_elements(self, main_runner):
test_input = ([2], [2, 2])
expected = "1"
assert expected in main_runner(majority_element, test_input)
def test_worst_case_equals(self, main_runner):
l = [10 ** 9] * (10 ** 5)
test_input = (len(l), l)
expected = "1"
assert expected in main_runner(majority_element, test_input)
def test_big_input_majority_corner_case(self, main_runner):
import random
l = [random.randint(0, 10 ** 9) for _ in range((10 ** 5) // 2 - 1)] + \
([1] * ((10 ** 5) // 2 + 1))
assert len(l) == 10 ** 5
test_input = (len(l), l)
expected = "1"
assert expected in main_runner(majority_element, test_input)
def test_big_input_no_majority_corner_case(self, main_runner):
import random
l = [random.randint(0, 10 ** 9) for _ in range((10 ** 5) // 2)] + \
([1] * ((10 ** 5) // 2))
assert len(l) == 10 ** 5
test_input = (len(l), l)
expected = "0"
assert expected in main_runner(majority_element, test_input)
def test_majority_is_biggest(self, main_runner):
test_input = ([5], [0, 2, 0, 2, 2])
expected = "1"
assert expected in main_runner(majority_element, test_input)
def test_linear_basic_cases(self):
a = [1, 2]
res_lin = majority_element.get_majority_element_linear(a, 0, 1)
assert res_lin == a[0]
assert -1 == majority_element.get_majority_element_linear(a, 0, 0)
assert -1 == majority_element.get_majority_element_linear(a, 0, len(a))
def test_recursive_basic_cases(self):
a = [1, 2]
res_lin = majority_element.get_majority_element(a, 0, 1)
assert res_lin == a[0]
assert -1 == majority_element.get_majority_element(a, 0, 0)
assert -1 == majority_element.get_majority_element(a, 0, len(a))
def test_linear_vs_recursive(self):
a = (2, 124554847, 2, 941795895, 2, 2, 2, 2, 792755190, 756617003)
res_lin = majority_element.get_majority_element_linear(a, 0, len(a))
res_rec = majority_element.get_majority_element(a, 0, len(a))
assert res_lin == res_rec
@pytest.mark.timeout(15)
class TestPointsAndSegments:
@pytest.mark.parametrize("test_input,expected", [
(([2, 3], [0, 5], [7, 10], [1, 6, 11]), "1 0 0"),
(([1, 3], [-10, 10], [-100, 100, 0]), "0 0 1"),
(([3, 2], [0, 5], [-3, 2], [7, 10], [1, 6]), "2 0")
])
def test_samples(self, test_input, expected, main_runner):
assert expected in main_runner(points_and_segments, test_input)
@pytest.mark.timeout(10) # 10 seconds timeout for sorting tests
class TestSorting:
@pytest.mark.parametrize("test_input,expected", [
(([5], [2, 3, 9, 2, 2]), "2 2 2 3 9")
])
def test_samples(self, test_input, expected, main_runner):
assert expected in main_runner(sorting, test_input)
def test_should_sort_inverted_sequence(self, main_runner):
a = [x for x in reversed(range(1, 10 ** 5 + 1))]
test_input = (len(a), a)
expected = " ".join((str(x) for x in reversed(a)))
assert expected in main_runner(sorting, test_input)
def test_randomized_quick_sort2_inverted_sequence(self):
a = [x for x in reversed(range(1, 10 ** 5 + 1))]
expected = a[::-1]
sorting.randomized_quick_sort(a, 0, len(a) - 1)
assert expected == a
def test_randomized_quick_sort3_inverted_sequence(self):
a1 = [x for x in reversed(range(1, 10 ** 5 + 1))]
a2 = list(a1)
sorting.randomized_quick_sort(a1, 0, len(a1) - 1)
sorting.randomized_quick_sort3(a2, 0, len(a2) - 1)
assert a1 == a2
def test_all_equal_elements(self, main_runner):
a = [3] * 10 ** 5
test_input = (len(a), a)
expected = " ".join((str(x) for x in a))
assert expected in main_runner(sorting, test_input)
def test_partition3_basic(self):
a = [5, 4, 5, 5, 3, 5, 8, 1]
m1, m2 = sorting.partition3(a, 0, len(a) - 1)
assert m1 == 3
assert m2 == 6
assert a == [1, 4, 3, 5, 5, 5, 5, 8]
def test_partition3_three_simple(self):
a = [2, 3, 1]
expected = list(a)
m = sorting.partition2(expected, 0, len(expected) - 1)
m1, m2 = sorting.partition3(a, 0, len(a) - 1)
assert m1 == m
assert m2 == m
assert a == expected
def test_partition3_reversed(self):
a = [x for x in reversed(range(1, 10))]
expected = list(a)
expected[0], expected[-1] = expected[-1], expected[0]
m1, m2 = sorting.partition3(a, 0, len(a) - 1)
assert m1 == len(a) - 1
assert m2 == len(a) - 1
assert a == expected
def test_partition2_reversed(self):
a = [x for x in reversed(range(1, 10))]
expected = list(a)
expected[0], expected[-1] = expected[-1], expected[0]
m = sorting.partition2(a, 0, len(a) - 1)
assert m == len(a) - 1
assert a == expected
|
gpl-3.0
|
[
646,
23003,
63,
460,
63,
388,
16891,
14,
3008,
63,
1733,
465,
3366,
63,
1733,
199,
646,
23003,
63,
460,
63,
388,
16891,
14,
262,
6234,
465,
315,
6234,
199,
646,
23003,
63,
460,
63,
388,
16891,
14,
31611,
3822,
63,
2108,
465,
610,
74,
3822,
63,
2108,
199,
646,
23003,
63,
460,
63,
388,
16891,
14,
3438,
63,
460,
63,
13879,
465,
4501,
63,
460,
63,
13879,
199,
646,
23003,
63,
460,
63,
388,
16891,
14,
29411,
465,
13351,
199,
646,
4613,
421,
199,
32,
4462,
14,
1657,
14,
2593,
8,
709,
9,
221,
327,
1616,
4696,
2653,
367,
3366,
642,
2295,
199,
533,
1379,
6636,
5278,
26,
272,
768,
4462,
14,
1657,
14,
10396,
480,
396,
63,
1210,
12,
2062,
401,
359,
267,
334,
779,
21,
12,
413,
12,
959,
12,
1695,
12,
3144,
12,
4944,
467,
359,
21,
12,
1695,
12,
413,
12,
6546,
12,
413,
12,
4119,
2522,
298,
18,
378,
446,
17,
378,
446,
17,
531,
272,
4794,
272,
347,
511,
63,
3271,
8,
277,
12,
511,
63,
1210,
12,
1420,
12,
2446,
63,
5933,
304,
267,
702,
1420,
315,
2446,
63,
5933,
8,
3008,
63,
1733,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
584,
270,
63,
2546,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
709,
1011,
959,
1874,
267,
702,
822,
8,
65,
9,
446,
413,
508,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
282,
1988,
17,
566,
339,
347,
511,
63,
14885,
63,
2108,
63,
12056,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
709,
1011,
959,
1874,
267,
702,
822,
8,
65,
9,
5001,
499,
508,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
282,
59,
552,
8,
65,
9,
5001,
499,
566,
339,
347,
511,
63,
14885,
63,
2108,
63,
16216,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
709,
1011,
959,
446,
413,
1874,
267,
702,
822,
8,
65,
9,
5001,
499,
508,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
282,
59,
552,
8,
65,
9,
5001,
499,
566,
339,
347,
511,
63,
584,
270,
63,
6462,
63,
890,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
709,
1011,
959,
1874,
267,
367,
671,
315,
1425,
8,
552,
8,
65,
395,
822,
8,
65,
9,
435,
1616,
1011,
959,
304,
288,
702,
446,
17,
508,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
671,
9,
339,
347,
511,
63,
18,
63,
17556,
8,
277,
12,
2446,
63,
5933,
304,
267,
511,
63,
1210,
275,
7287,
709,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
467,
1993,
359,
713,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
12,
3144,
566,
267,
1420,
275,
3905,
17,
378,
413,
499,
650,
841,
959,
1227,
1520,
1695,
1749,
446,
17,
2,
267,
702,
1420,
315,
2446,
63,
5933,
8,
3008,
63,
1733,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
6676,
63,
3122,
63,
3008,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
1165,
1874,
267,
367,
284,
12,
671,
315,
3874,
8,
65,
304,
288,
7403,
63,
82,
275,
3366,
63,
1733,
14,
6676,
63,
1733,
8,
65,
12,
671,
9,
288,
702,
284,
508,
7403,
63,
82,
288,
2517,
63,
82,
275,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
671,
9,
288,
702,
284,
508,
2517,
63,
82,
267,
7403,
63,
82,
275,
3366,
63,
1733,
14,
6676,
63,
1733,
8,
65,
12,
282,
1988,
17,
61,
435,
413,
9,
267,
702,
446,
17,
508,
7403,
63,
82,
267,
2517,
63,
82,
275,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
282,
1988,
17,
61,
435,
413,
9,
267,
702,
446,
17,
508,
2517,
63,
82,
421,
199,
533,
1379,
607,
6234,
26,
272,
768,
4462,
14,
1657,
14,
10396,
480,
396,
63,
1210,
12,
2062,
401,
359,
267,
334,
779,
21,
467,
359,
18,
12,
650,
12,
1749,
12,
499,
12,
1749,
2522,
298,
18,
531,
272,
4794,
272,
347,
511,
63,
3356,
8,
277,
12,
511,
63,
1210,
12,
1420,
12,
2446,
63,
5933,
304,
267,
702,
1420,
315,
2446,
63,
5933,
8,
262,
6234,
12,
511,
63,
1210,
9,
421,
199,
533,
1379,
45,
9091,
3822,
2162,
26,
272,
768,
4462,
14,
1657,
14,
10396,
480,
396,
63,
1210,
12,
2062,
401,
359,
267,
334,
779,
21,
467,
359,
18,
12,
650,
12,
1749,
12,
499,
12,
499,
2522,
298,
17,
1288,
267,
334,
779,
20,
467,
359,
17,
12,
499,
12,
650,
12,
841,
2522,
298,
16,
1288,
267,
334,
779,
20,
467,
359,
17,
12,
499,
12,
650,
12,
413,
2522,
298,
16,
531,
272,
4794,
272,
347,
511,
63,
3271,
8,
277,
12,
511,
63,
1210,
12,
1420,
12,
2446,
63,
5933,
304,
267,
702,
1420,
315,
2446,
63,
5933,
8,
31611,
3822,
63,
2108,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
19,
63,
17556,
8,
277,
12,
2446,
63,
5933,
304,
267,
511,
63,
1210,
275,
7287,
709,
467,
1993,
359,
18,
12,
25442,
19264,
15883,
12,
499,
12,
18729,
1196,
2720,
11382,
12,
499,
12,
499,
12,
499,
12,
499,
12,
13734,
1465,
1229,
12205,
12,
2432,
13098,
1272,
1196,
8262,
566,
267,
1420,
275,
298,
17,
2,
267,
702,
1420,
315,
2446,
63,
5933,
8,
31611,
3822,
63,
2108,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
368,
63,
2108,
8,
277,
12,
2446,
63,
5933,
304,
267,
511,
63,
1210,
275,
7287,
17,
467,
359,
17,
566,
267,
1420,
275,
298,
17,
2,
267,
702,
1420,
315,
2446,
63,
5933,
8,
31611,
3822,
63,
2108,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
5601,
63,
14020,
63,
5527,
8,
277,
12,
2446,
63,
5933,
304,
267,
511,
63,
1210,
275,
7287,
18,
467,
359,
17,
12,
499,
566,
267,
1420,
275,
298,
16,
2,
267,
702,
1420,
315,
2446,
63,
5933,
8
] |
[
23003,
63,
460,
63,
388,
16891,
14,
3008,
63,
1733,
465,
3366,
63,
1733,
199,
646,
23003,
63,
460,
63,
388,
16891,
14,
262,
6234,
465,
315,
6234,
199,
646,
23003,
63,
460,
63,
388,
16891,
14,
31611,
3822,
63,
2108,
465,
610,
74,
3822,
63,
2108,
199,
646,
23003,
63,
460,
63,
388,
16891,
14,
3438,
63,
460,
63,
13879,
465,
4501,
63,
460,
63,
13879,
199,
646,
23003,
63,
460,
63,
388,
16891,
14,
29411,
465,
13351,
199,
646,
4613,
421,
199,
32,
4462,
14,
1657,
14,
2593,
8,
709,
9,
221,
327,
1616,
4696,
2653,
367,
3366,
642,
2295,
199,
533,
1379,
6636,
5278,
26,
272,
768,
4462,
14,
1657,
14,
10396,
480,
396,
63,
1210,
12,
2062,
401,
359,
267,
334,
779,
21,
12,
413,
12,
959,
12,
1695,
12,
3144,
12,
4944,
467,
359,
21,
12,
1695,
12,
413,
12,
6546,
12,
413,
12,
4119,
2522,
298,
18,
378,
446,
17,
378,
446,
17,
531,
272,
4794,
272,
347,
511,
63,
3271,
8,
277,
12,
511,
63,
1210,
12,
1420,
12,
2446,
63,
5933,
304,
267,
702,
1420,
315,
2446,
63,
5933,
8,
3008,
63,
1733,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
584,
270,
63,
2546,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
709,
1011,
959,
1874,
267,
702,
822,
8,
65,
9,
446,
413,
508,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
282,
1988,
17,
566,
339,
347,
511,
63,
14885,
63,
2108,
63,
12056,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
709,
1011,
959,
1874,
267,
702,
822,
8,
65,
9,
5001,
499,
508,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
282,
59,
552,
8,
65,
9,
5001,
499,
566,
339,
347,
511,
63,
14885,
63,
2108,
63,
16216,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
709,
1011,
959,
446,
413,
1874,
267,
702,
822,
8,
65,
9,
5001,
499,
508,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
282,
59,
552,
8,
65,
9,
5001,
499,
566,
339,
347,
511,
63,
584,
270,
63,
6462,
63,
890,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
709,
1011,
959,
1874,
267,
367,
671,
315,
1425,
8,
552,
8,
65,
395,
822,
8,
65,
9,
435,
1616,
1011,
959,
304,
288,
702,
446,
17,
508,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
671,
9,
339,
347,
511,
63,
18,
63,
17556,
8,
277,
12,
2446,
63,
5933,
304,
267,
511,
63,
1210,
275,
7287,
709,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
467,
1993,
359,
713,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
12,
3144,
566,
267,
1420,
275,
3905,
17,
378,
413,
499,
650,
841,
959,
1227,
1520,
1695,
1749,
446,
17,
2,
267,
702,
1420,
315,
2446,
63,
5933,
8,
3008,
63,
1733,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
6676,
63,
3122,
63,
3008,
8,
277,
304,
267,
282,
275,
359,
73,
367,
284,
315,
1425,
8,
1165,
1874,
267,
367,
284,
12,
671,
315,
3874,
8,
65,
304,
288,
7403,
63,
82,
275,
3366,
63,
1733,
14,
6676,
63,
1733,
8,
65,
12,
671,
9,
288,
702,
284,
508,
7403,
63,
82,
288,
2517,
63,
82,
275,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
671,
9,
288,
702,
284,
508,
2517,
63,
82,
267,
7403,
63,
82,
275,
3366,
63,
1733,
14,
6676,
63,
1733,
8,
65,
12,
282,
1988,
17,
61,
435,
413,
9,
267,
702,
446,
17,
508,
7403,
63,
82,
267,
2517,
63,
82,
275,
3366,
63,
1733,
14,
3008,
63,
1733,
8,
65,
12,
282,
1988,
17,
61,
435,
413,
9,
267,
702,
446,
17,
508,
2517,
63,
82,
421,
199,
533,
1379,
607,
6234,
26,
272,
768,
4462,
14,
1657,
14,
10396,
480,
396,
63,
1210,
12,
2062,
401,
359,
267,
334,
779,
21,
467,
359,
18,
12,
650,
12,
1749,
12,
499,
12,
1749,
2522,
298,
18,
531,
272,
4794,
272,
347,
511,
63,
3356,
8,
277,
12,
511,
63,
1210,
12,
1420,
12,
2446,
63,
5933,
304,
267,
702,
1420,
315,
2446,
63,
5933,
8,
262,
6234,
12,
511,
63,
1210,
9,
421,
199,
533,
1379,
45,
9091,
3822,
2162,
26,
272,
768,
4462,
14,
1657,
14,
10396,
480,
396,
63,
1210,
12,
2062,
401,
359,
267,
334,
779,
21,
467,
359,
18,
12,
650,
12,
1749,
12,
499,
12,
499,
2522,
298,
17,
1288,
267,
334,
779,
20,
467,
359,
17,
12,
499,
12,
650,
12,
841,
2522,
298,
16,
1288,
267,
334,
779,
20,
467,
359,
17,
12,
499,
12,
650,
12,
413,
2522,
298,
16,
531,
272,
4794,
272,
347,
511,
63,
3271,
8,
277,
12,
511,
63,
1210,
12,
1420,
12,
2446,
63,
5933,
304,
267,
702,
1420,
315,
2446,
63,
5933,
8,
31611,
3822,
63,
2108,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
19,
63,
17556,
8,
277,
12,
2446,
63,
5933,
304,
267,
511,
63,
1210,
275,
7287,
709,
467,
1993,
359,
18,
12,
25442,
19264,
15883,
12,
499,
12,
18729,
1196,
2720,
11382,
12,
499,
12,
499,
12,
499,
12,
499,
12,
13734,
1465,
1229,
12205,
12,
2432,
13098,
1272,
1196,
8262,
566,
267,
1420,
275,
298,
17,
2,
267,
702,
1420,
315,
2446,
63,
5933,
8,
31611,
3822,
63,
2108,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
368,
63,
2108,
8,
277,
12,
2446,
63,
5933,
304,
267,
511,
63,
1210,
275,
7287,
17,
467,
359,
17,
566,
267,
1420,
275,
298,
17,
2,
267,
702,
1420,
315,
2446,
63,
5933,
8,
31611,
3822,
63,
2108,
12,
511,
63,
1210,
9,
339,
347,
511,
63,
5601,
63,
14020,
63,
5527,
8,
277,
12,
2446,
63,
5933,
304,
267,
511,
63,
1210,
275,
7287,
18,
467,
359,
17,
12,
499,
566,
267,
1420,
275,
298,
16,
2,
267,
702,
1420,
315,
2446,
63,
5933,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
guillaume-philippon/aquilon
|
lib/aquilon/worker/commands/del_campus.py
|
2
|
1551
|
# -*- cpy-indent-level: 4; indent-tabs-mode: nil -*-
# ex: set expandtab softtabstop=4 shiftwidth=4:
#
# Copyright (C) 2008,2009,2010,2011,2012,2013,2016 Contributor
#
# 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.
"""Contains the logic for `aq del campus`."""
from aquilon.aqdb.model import Campus
from aquilon.worker.processes import DSDBRunner
from aquilon.worker.broker import BrokerCommand # pylint: disable=W0611
from aquilon.worker.commands.del_location import CommandDelLocation
class CommandDelCampus(CommandDelLocation):
required_parameters = ["campus"]
def render(self, session, logger, campus, **arguments):
dbcampus = Campus.get_unique(session, campus, compel=True)
name = dbcampus.name
result = CommandDelLocation.render(self, session=session, name=name,
type='campus', **arguments)
session.flush()
dsdb_runner = DSDBRunner(logger=logger)
dsdb_runner.del_campus(name)
dsdb_runner.commit_or_rollback()
return result
|
apache-2.0
|
[
3,
1882,
286,
647,
13,
3724,
13,
1896,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
1882,
199,
3,
444,
26,
663,
26414,
25966,
29,
20,
20105,
29,
20,
26,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
12,
8664,
12,
6542,
12,
8128,
12,
7409,
12,
6965,
12,
9261,
221,
17636,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
6906,
314,
9661,
367,
658,
30030,
2150,
1704,
311,
527,
17105,
199,
199,
504,
282,
392,
382,
265,
14,
30030,
697,
14,
1238,
492,
24569,
527,
199,
504,
282,
392,
382,
265,
14,
6599,
14,
11816,
492,
577,
51,
2846,
7446,
199,
504,
282,
392,
382,
265,
14,
6599,
14,
16620,
492,
27651,
3110,
221,
327,
4287,
26,
3507,
29,
55,
1690,
845,
199,
504,
282,
392,
382,
265,
14,
6599,
14,
4405,
14,
2264,
63,
1985,
492,
5817,
6994,
6592,
421,
199,
533,
5817,
6994,
3630,
311,
527,
8,
3110,
6994,
6592,
304,
339,
1415,
63,
3214,
275,
2097,
20290,
527,
937,
339,
347,
3795,
8,
277,
12,
2351,
12,
2512,
12,
1704,
311,
527,
12,
1011,
4958,
304,
267,
1592,
20290,
527,
275,
24569,
527,
14,
362,
63,
3235,
8,
1730,
12,
1704,
311,
527,
12,
1013,
352,
29,
549,
9,
267,
536,
275,
1592,
20290,
527,
14,
354,
398,
754,
275,
5817,
6994,
6592,
14,
3352,
8,
277,
12,
2351,
29,
1730,
12,
536,
29,
354,
12,
5644,
730,
534,
20290,
527,
297,
1011,
4958,
9,
267,
2351,
14,
4939,
342,
398,
6364,
697,
63,
5933,
275,
577,
51,
2846,
7446,
8,
2921,
29,
2921,
9,
267,
6364,
697,
63,
5933,
14,
2264,
63,
20290,
527,
8,
354,
9,
267,
6364,
697,
63,
5933,
14,
3543,
63,
269,
63,
10437,
342,
398,
372,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
286,
647,
13,
3724,
13,
1896,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
1882,
199,
3,
444,
26,
663,
26414,
25966,
29,
20,
20105,
29,
20,
26,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
12,
8664,
12,
6542,
12,
8128,
12,
7409,
12,
6965,
12,
9261,
221,
17636,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
6906,
314,
9661,
367,
658,
30030,
2150,
1704,
311,
527,
17105,
199,
199,
504,
282,
392,
382,
265,
14,
30030,
697,
14,
1238,
492,
24569,
527,
199,
504,
282,
392,
382,
265,
14,
6599,
14,
11816,
492,
577,
51,
2846,
7446,
199,
504,
282,
392,
382,
265,
14,
6599,
14,
16620,
492,
27651,
3110,
221,
327,
4287,
26,
3507,
29,
55,
1690,
845,
199,
504,
282,
392,
382,
265,
14,
6599,
14,
4405,
14,
2264,
63,
1985,
492,
5817,
6994,
6592,
421,
199,
533,
5817,
6994,
3630,
311,
527,
8,
3110,
6994,
6592,
304,
339,
1415,
63,
3214,
275,
2097,
20290,
527,
937,
339,
347,
3795,
8,
277,
12,
2351,
12,
2512,
12,
1704,
311,
527,
12,
1011,
4958,
304,
267,
1592,
20290,
527,
275,
24569,
527,
14,
362,
63,
3235,
8,
1730,
12,
1704,
311,
527,
12,
1013,
352,
29,
549,
9,
267,
536,
275,
1592,
20290,
527,
14,
354,
398,
754,
275,
5817,
6994,
6592,
14,
3352,
8,
277,
12,
2351,
29,
1730,
12,
536,
29,
354,
12,
5644,
730,
534,
20290,
527,
297,
1011,
4958,
9,
267,
2351,
14,
4939,
342,
398,
6364,
697,
63,
5933,
275,
577,
51,
2846,
7446,
8,
2921,
29,
2921,
9,
267,
6364,
697,
63,
5933,
14,
2264,
63,
20290,
527,
8,
354,
9,
267,
6364,
697,
63,
5933,
14,
3543,
63,
269,
63,
10437,
342,
398,
372,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zstackio/zstack-woodpecker
|
integrationtest/vm/multihosts/ha/test_smp_ls_vm_ha_force_stop_host_vm_status.py
|
2
|
5387
|
'''
New Integration Test for host where KVM VM ha located force stop and start again,
check vm self-start again. In addition, this test is sepcific for smp and local.
@author: SyZhao
'''
import zstackwoodpecker.test_util as test_util
import zstackwoodpecker.test_state as test_state
import zstackwoodpecker.test_lib as test_lib
import zstackwoodpecker.operations.resource_operations as res_ops
import zstackwoodpecker.operations.host_operations as host_ops
import zstackwoodpecker.zstack_test.zstack_test_vm as test_vm_header
import zstackwoodpecker.header.vm as vm_header
import zstackwoodpecker.operations.ha_operations as ha_ops
import zstackwoodpecker.operations.vm_operations as vm_ops
import apibinding.inventory as inventory
import time
import os
vm = None
host_uuid = None
host_ip = None
max_attempts = None
storagechecker_timeout = None
test_stub = test_lib.lib_get_test_stub()
test_host = None
def test():
global vm
global host_uuid
global test_host
global host_ip
global max_attempts
global storagechecker_timeout
must_ps_list = [inventory.LOCAL_STORAGE_TYPE, 'SharedMountPoint']
test_lib.skip_test_if_any_ps_not_deployed(must_ps_list)
if test_lib.lib_get_ha_enable() != 'true':
test_util.test_skip("vm ha not enabled. Skip test")
vm_creation_option = test_util.VmOption()
image_name = os.environ.get('imageName_net')
image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
l3_name = os.environ.get('l3VlanNetworkName1')
l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid
test_lib.clean_up_all_vr()
mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName
conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
conditions = res_ops.gen_query_conditions('state', '=', 'Enabled')
conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions)
conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip, conditions)
host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
vm_creation_option.set_host_uuid(host_uuid)
vm_creation_option.set_l3_uuids([l3_net_uuid])
vm_creation_option.set_image_uuid(image_uuid)
vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
vm_creation_option.set_name('ls_vm_ha_self_start')
vm = test_vm_header.ZstackTestVm()
vm.set_creation_option(vm_creation_option)
vm.create()
vr_hosts = test_stub.get_host_has_vr()
mn_hosts = test_stub.get_host_has_mn()
nfs_hosts = test_stub.get_host_has_nfs()
if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts):
test_util.test_fail("Not find out a suitable host")
#vm.check()
host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp
test_util.test_logger("host %s is disconnecting" %(host_ip))
ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop")
host_list = test_stub.get_sce_hosts(test_lib.all_scenario_config, test_lib.scenario_file)
for host in host_list:
if host.ip_ == host_ip:
test_host = host
break
if not test_host:
test_util.test_fail('there is no host with ip %s in scenario file.' %(host_ip))
test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold')
vm_stop_time = None
cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_ha_self_start')
cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond)
for i in range(0, 300):
vm_stop_time = i
if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped":
test_stub.start_host(test_host, test_lib.all_scenario_config)
test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config)
conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip)
kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
host_ops.reconnect_host(kvm_host_uuid)
break
time.sleep(1)
if vm_stop_time is None:
vm_stop_time = 300
for i in range(vm_stop_time, 300):
if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Starting":
break
time.sleep(1)
else:
test_util.test_fail("vm has not been changed to running as expected within 300s.")
vm.destroy()
test_util.test_pass('Test checking VM ha and none status when force stop vm Success.')
#Will be called only if exception happens in test().
def error_cleanup():
global vm
if vm:
try:
vm.destroy()
except:
pass
def env_recover():
global test_host
global host_ip
try:
test_stub.start_host(test_host, test_lib.all_scenario_config)
test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config)
except:
pass
conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip)
kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid
host_ops.reconnect_host(kvm_host_uuid)
|
apache-2.0
|
[
2344,
202,
199,
4665,
27561,
1379,
367,
1591,
2382,
1804,
6849,
7525,
18251,
16180,
3542,
3631,
436,
1343,
4020,
12,
202,
199,
1074,
4169,
291,
13,
928,
4020,
14,
1010,
10234,
12,
642,
511,
365,
7375,
18333,
367,
308,
311,
436,
2257,
14,
202,
199,
32,
2502,
26,
5515,
58,
2411,
79,
202,
199,
2344,
2999,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
396,
63,
1974,
465,
511,
63,
1974,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
396,
63,
929,
465,
511,
63,
929,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
396,
63,
773,
465,
511,
63,
773,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
8170,
14,
1927,
63,
8170,
465,
522,
63,
1483,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
8170,
14,
1102,
63,
8170,
465,
1591,
63,
1483,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
90,
2340,
63,
396,
14,
90,
2340,
63,
396,
63,
2611,
465,
511,
63,
2611,
63,
1291,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
1291,
14,
2611,
465,
4169,
63,
1291,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
8170,
14,
2411,
63,
8170,
465,
18251,
63,
1483,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
8170,
14,
2611,
63,
8170,
465,
4169,
63,
1483,
202,
199,
646,
2986,
9140,
14,
7212,
465,
8200,
202,
199,
646,
900,
202,
199,
646,
747,
2999,
199,
2611,
275,
488,
202,
199,
1102,
63,
2580,
275,
488,
202,
199,
1102,
63,
711,
275,
488,
202,
199,
988,
63,
13143,
275,
488,
202,
199,
3494,
6743,
63,
2593,
275,
488,
202,
199,
396,
63,
5811,
275,
511,
63,
773,
14,
773,
63,
362,
63,
396,
63,
5811,
342,
202,
199,
396,
63,
1102,
275,
488,
2999,
199,
318,
511,
837,
1128,
2288,
4169,
1128,
2288,
1591,
63,
2580,
1128,
2288,
511,
63,
1102,
1128,
2288,
1591,
63,
711,
1128,
2288,
1390,
63,
13143,
1128,
2288,
4887,
6743,
63,
2593,
2958,
1471,
63,
1190,
63,
513,
275,
359,
7212,
14,
7486,
63,
17467,
63,
2711,
12,
283,
12197,
24467,
3428,
418,
1128,
511,
63,
773,
14,
2759,
63,
396,
63,
692,
63,
1629,
63,
1190,
63,
1397,
63,
11060,
379,
8,
7790,
63,
1190,
63,
513,
9,
2958,
340,
511,
63,
773,
14,
773,
63,
362,
63,
2411,
63,
4296,
342,
1137,
283,
2052,
356,
1039,
511,
63,
1974,
14,
396,
63,
2759,
480,
2611,
18251,
440,
5223,
14,
8232,
511,
531,
2958,
4169,
63,
8782,
63,
1422,
275,
511,
63,
1974,
14,
17402,
2602,
342,
1128,
1834,
63,
354,
275,
747,
14,
2314,
14,
362,
360,
1569,
985,
63,
846,
358,
1128,
1834,
63,
2580,
275,
511,
63,
773,
14,
773,
63,
362,
63,
1569,
63,
991,
63,
354,
8,
1569,
63,
354,
680,
2580,
1128,
634,
19,
63,
354,
275,
747,
14,
2314,
14,
362,
360,
76,
19,
22657,
4491,
985,
17,
358,
1128,
634,
19,
63,
846,
63,
2580,
275,
511,
63,
773,
14,
773,
63,
362,
63,
76,
19,
63,
991,
63,
354,
8,
76,
19,
63,
354,
680,
2580,
1128,
511,
63,
773,
14,
3118,
63,
384,
63,
452,
63,
10922,
342,
2958,
21945,
63,
711,
275,
522,
63,
1483,
14,
1131,
63,
1927,
8,
470,
63,
1483,
14,
20600,
9591,
63,
8063,
2788,
16,
1055,
1102,
985,
1128,
3704,
275,
522,
63,
1483,
14,
2268,
63,
1131,
63,
9855,
360,
466,
297,
6291,
283,
1899,
17402,
358,
1128,
1256,
63,
19501,
63,
2580,
275,
522,
63,
1483,
14,
1131,
63,
1927,
8,
470,
63,
1483,
14,
18235,
63,
7517,
540,
1206,
12,
3704,
2788,
16,
1055,
2580,
1128,
3704,
275,
522,
63,
1483,
14,
2268,
63,
1131,
63,
9855,
360,
929,
297,
6291,
283,
6589,
358,
1128,
3704,
275,
522,
63,
1483,
14,
2268,
63,
1131,
63,
9855,
360,
1205,
297,
6291,
283,
16382,
297,
3704,
9,
1128,
3704,
275,
522,
63,
1483,
14,
2268,
63,
1131,
63,
9855,
360,
8110,
6583,
297,
31326,
21945,
63,
711,
12,
3704,
9,
1128,
1591,
63,
2580,
275,
522,
63,
1483,
14,
1131,
63,
1927,
8,
470,
63,
1483,
14,
5449,
12,
3704,
2788,
16,
1055,
2580,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
1102,
63,
2580,
8,
1102,
63,
2580,
9,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
76,
19,
63,
18401,
779,
76,
19,
63,
846,
63,
2580,
566,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
1569,
63,
2580,
8,
1569,
63,
2580,
9,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
842,
63,
19501,
63,
2580,
8,
842,
63,
19501,
63,
2580,
9,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
354,
360,
478,
63,
2611,
63,
2411,
63,
277,
63,
928,
358,
1128,
4169,
275,
511,
63,
2611,
63,
1291,
14,
58,
2340,
774,
17402,
342,
1128,
4169,
14,
409,
63,
8782,
63,
1422,
8,
2611,
63,
8782,
63,
1422,
9,
1128,
4169,
14,
981,
342,
2958,
21535,
63,
5146,
275,
511,
63,
5811,
14,
362,
63,
1102,
63,
1989,
63,
10922,
342,
1128,
21945,
63,
5146,
275,
511,
63,
5811,
14,
362,
63,
1102,
63,
1989,
63,
10344,
342,
1128,
31307,
63,
5146,
275,
511,
63,
5811,
14,
362,
63,
1102,
63,
1989,
63,
19591,
342,
1128,
340,
440,
511,
63,
5811,
14,
7505,
63,
2611,
63,
1397,
63,
265,
8,
2611,
14,
362,
63,
2611,
1252,
2580,
12,
4169,
14,
362,
63,
2611,
1252,
1102,
19557,
12,
21535,
63,
5146,
11,
10344,
63,
5146,
11,
19591,
63,
5146,
304,
1039,
511,
63,
1974,
14,
396,
63,
1633,
480,
1763,
2342,
734,
282,
11233,
1591,
531,
2958,
327,
2611,
14,
1074,
342,
1128,
1591,
63,
711,
275,
511,
63,
773,
14,
773,
63,
1623,
63,
1102,
63,
991,
63,
2611,
8,
2611,
14,
362,
63,
2611,
8801,
8110,
6583,
1128,
511,
63,
1974,
14,
396,
63,
2921,
480,
1102,
450,
83,
365,
17639,
316,
2,
2818,
1102,
63,
711,
430,
2958,
18251,
63,
1483,
14,
409,
63,
2611,
63,
842,
63,
2411,
63,
1896,
8,
2611,
14,
362,
63,
2611,
1252,
2580,
12,
298,
4698,
422,
6293,
531,
2958,
1591,
63,
513,
275,
511,
63,
5811,
14,
362,
63,
83,
301
] |
[
202,
199,
4665,
27561,
1379,
367,
1591,
2382,
1804,
6849,
7525,
18251,
16180,
3542,
3631,
436,
1343,
4020,
12,
202,
199,
1074,
4169,
291,
13,
928,
4020,
14,
1010,
10234,
12,
642,
511,
365,
7375,
18333,
367,
308,
311,
436,
2257,
14,
202,
199,
32,
2502,
26,
5515,
58,
2411,
79,
202,
199,
2344,
2999,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
396,
63,
1974,
465,
511,
63,
1974,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
396,
63,
929,
465,
511,
63,
929,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
396,
63,
773,
465,
511,
63,
773,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
8170,
14,
1927,
63,
8170,
465,
522,
63,
1483,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
8170,
14,
1102,
63,
8170,
465,
1591,
63,
1483,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
90,
2340,
63,
396,
14,
90,
2340,
63,
396,
63,
2611,
465,
511,
63,
2611,
63,
1291,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
1291,
14,
2611,
465,
4169,
63,
1291,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
8170,
14,
2411,
63,
8170,
465,
18251,
63,
1483,
202,
199,
646,
1315,
2340,
22736,
321,
22043,
14,
8170,
14,
2611,
63,
8170,
465,
4169,
63,
1483,
202,
199,
646,
2986,
9140,
14,
7212,
465,
8200,
202,
199,
646,
900,
202,
199,
646,
747,
2999,
199,
2611,
275,
488,
202,
199,
1102,
63,
2580,
275,
488,
202,
199,
1102,
63,
711,
275,
488,
202,
199,
988,
63,
13143,
275,
488,
202,
199,
3494,
6743,
63,
2593,
275,
488,
202,
199,
396,
63,
5811,
275,
511,
63,
773,
14,
773,
63,
362,
63,
396,
63,
5811,
342,
202,
199,
396,
63,
1102,
275,
488,
2999,
199,
318,
511,
837,
1128,
2288,
4169,
1128,
2288,
1591,
63,
2580,
1128,
2288,
511,
63,
1102,
1128,
2288,
1591,
63,
711,
1128,
2288,
1390,
63,
13143,
1128,
2288,
4887,
6743,
63,
2593,
2958,
1471,
63,
1190,
63,
513,
275,
359,
7212,
14,
7486,
63,
17467,
63,
2711,
12,
283,
12197,
24467,
3428,
418,
1128,
511,
63,
773,
14,
2759,
63,
396,
63,
692,
63,
1629,
63,
1190,
63,
1397,
63,
11060,
379,
8,
7790,
63,
1190,
63,
513,
9,
2958,
340,
511,
63,
773,
14,
773,
63,
362,
63,
2411,
63,
4296,
342,
1137,
283,
2052,
356,
1039,
511,
63,
1974,
14,
396,
63,
2759,
480,
2611,
18251,
440,
5223,
14,
8232,
511,
531,
2958,
4169,
63,
8782,
63,
1422,
275,
511,
63,
1974,
14,
17402,
2602,
342,
1128,
1834,
63,
354,
275,
747,
14,
2314,
14,
362,
360,
1569,
985,
63,
846,
358,
1128,
1834,
63,
2580,
275,
511,
63,
773,
14,
773,
63,
362,
63,
1569,
63,
991,
63,
354,
8,
1569,
63,
354,
680,
2580,
1128,
634,
19,
63,
354,
275,
747,
14,
2314,
14,
362,
360,
76,
19,
22657,
4491,
985,
17,
358,
1128,
634,
19,
63,
846,
63,
2580,
275,
511,
63,
773,
14,
773,
63,
362,
63,
76,
19,
63,
991,
63,
354,
8,
76,
19,
63,
354,
680,
2580,
1128,
511,
63,
773,
14,
3118,
63,
384,
63,
452,
63,
10922,
342,
2958,
21945,
63,
711,
275,
522,
63,
1483,
14,
1131,
63,
1927,
8,
470,
63,
1483,
14,
20600,
9591,
63,
8063,
2788,
16,
1055,
1102,
985,
1128,
3704,
275,
522,
63,
1483,
14,
2268,
63,
1131,
63,
9855,
360,
466,
297,
6291,
283,
1899,
17402,
358,
1128,
1256,
63,
19501,
63,
2580,
275,
522,
63,
1483,
14,
1131,
63,
1927,
8,
470,
63,
1483,
14,
18235,
63,
7517,
540,
1206,
12,
3704,
2788,
16,
1055,
2580,
1128,
3704,
275,
522,
63,
1483,
14,
2268,
63,
1131,
63,
9855,
360,
929,
297,
6291,
283,
6589,
358,
1128,
3704,
275,
522,
63,
1483,
14,
2268,
63,
1131,
63,
9855,
360,
1205,
297,
6291,
283,
16382,
297,
3704,
9,
1128,
3704,
275,
522,
63,
1483,
14,
2268,
63,
1131,
63,
9855,
360,
8110,
6583,
297,
31326,
21945,
63,
711,
12,
3704,
9,
1128,
1591,
63,
2580,
275,
522,
63,
1483,
14,
1131,
63,
1927,
8,
470,
63,
1483,
14,
5449,
12,
3704,
2788,
16,
1055,
2580,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
1102,
63,
2580,
8,
1102,
63,
2580,
9,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
76,
19,
63,
18401,
779,
76,
19,
63,
846,
63,
2580,
566,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
1569,
63,
2580,
8,
1569,
63,
2580,
9,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
842,
63,
19501,
63,
2580,
8,
842,
63,
19501,
63,
2580,
9,
1128,
4169,
63,
8782,
63,
1422,
14,
409,
63,
354,
360,
478,
63,
2611,
63,
2411,
63,
277,
63,
928,
358,
1128,
4169,
275,
511,
63,
2611,
63,
1291,
14,
58,
2340,
774,
17402,
342,
1128,
4169,
14,
409,
63,
8782,
63,
1422,
8,
2611,
63,
8782,
63,
1422,
9,
1128,
4169,
14,
981,
342,
2958,
21535,
63,
5146,
275,
511,
63,
5811,
14,
362,
63,
1102,
63,
1989,
63,
10922,
342,
1128,
21945,
63,
5146,
275,
511,
63,
5811,
14,
362,
63,
1102,
63,
1989,
63,
10344,
342,
1128,
31307,
63,
5146,
275,
511,
63,
5811,
14,
362,
63,
1102,
63,
1989,
63,
19591,
342,
1128,
340,
440,
511,
63,
5811,
14,
7505,
63,
2611,
63,
1397,
63,
265,
8,
2611,
14,
362,
63,
2611,
1252,
2580,
12,
4169,
14,
362,
63,
2611,
1252,
1102,
19557,
12,
21535,
63,
5146,
11,
10344,
63,
5146,
11,
19591,
63,
5146,
304,
1039,
511,
63,
1974,
14,
396,
63,
1633,
480,
1763,
2342,
734,
282,
11233,
1591,
531,
2958,
327,
2611,
14,
1074,
342,
1128,
1591,
63,
711,
275,
511,
63,
773,
14,
773,
63,
1623,
63,
1102,
63,
991,
63,
2611,
8,
2611,
14,
362,
63,
2611,
8801,
8110,
6583,
1128,
511,
63,
1974,
14,
396,
63,
2921,
480,
1102,
450,
83,
365,
17639,
316,
2,
2818,
1102,
63,
711,
430,
2958,
18251,
63,
1483,
14,
409,
63,
2611,
63,
842,
63,
2411,
63,
1896,
8,
2611,
14,
362,
63,
2611,
1252,
2580,
12,
298,
4698,
422,
6293,
531,
2958,
1591,
63,
513,
275,
511,
63,
5811,
14,
362,
63,
83,
301,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
naslanidis/ansible
|
lib/ansible/modules/network/f5/bigip_monitor_tcp.py
|
32
|
15297
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2013, serge van Ginderachter <serge@vanginderachter.be>
#
# 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/>.
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = '''
---
module: bigip_monitor_tcp
short_description: "Manages F5 BIG-IP LTM tcp monitors"
description:
- "Manages F5 BIG-IP LTM tcp monitors via iControl SOAP API"
version_added: "1.4"
author:
- Serge van Ginderachter (@srvg)
- Tim Rupp (@caphrim007)
notes:
- "Requires BIG-IP software version >= 11"
- "F5 developed module 'bigsuds' required (see http://devcentral.f5.com)"
- "Best run as a local_action in your playbook"
- "Monitor API documentation: https://devcentral.f5.com/wiki/iControl.LocalLB__Monitor.ashx"
requirements:
- bigsuds
options:
state:
description:
- Monitor state
required: false
default: 'present'
choices:
- present
- absent
name:
description:
- Monitor name
required: true
default: null
aliases:
- monitor
partition:
description:
- Partition for the monitor
required: false
default: 'Common'
type:
description:
- The template type of this monitor template
required: false
default: 'tcp'
choices:
- TTYPE_TCP
- TTYPE_TCP_ECHO
- TTYPE_TCP_HALF_OPEN
parent:
description:
- The parent template of this monitor template
required: false
default: 'tcp'
choices:
- tcp
- tcp_echo
- tcp_half_open
parent_partition:
description:
- Partition for the parent monitor
required: false
default: 'Common'
send:
description:
- The send string for the monitor call
required: true
default: none
receive:
description:
- The receive string for the monitor call
required: true
default: none
ip:
description:
- IP address part of the ipport definition. The default API setting
is "0.0.0.0".
required: false
default: none
port:
description:
- Port address part op the ipport definition. The default API
setting is 0.
required: false
default: none
interval:
description:
- The interval specifying how frequently the monitor instance
of this template will run. By default, this interval is used for up and
down states. The default API setting is 5.
required: false
default: none
timeout:
description:
- The number of seconds in which the node or service must respond to
the monitor request. If the target responds within the set time
period, it is considered up. If the target does not respond within
the set time period, it is considered down. You can change this
number to any number you want, however, it should be 3 times the
interval number of seconds plus 1 second. The default API setting
is 16.
required: false
default: none
time_until_up:
description:
- Specifies the amount of time in seconds after the first successful
response before a node will be marked up. A value of 0 will cause a
node to be marked up immediately after a valid response is received
from the node. The default API setting is 0.
required: false
default: none
extends_documentation_fragment: f5
'''
EXAMPLES = '''
- name: Create TCP Monitor
bigip_monitor_tcp:
state: "present"
server: "lb.mydomain.com"
user: "admin"
password: "secret"
name: "my_tcp_monitor"
type: "tcp"
send: "tcp string to send"
receive: "tcp string to receive"
delegate_to: localhost
- name: Create TCP half open Monitor
bigip_monitor_tcp:
state: "present"
server: "lb.mydomain.com"
user: "admin"
password: "secret"
name: "my_tcp_monitor"
type: "tcp"
send: "tcp string to send"
receive: "http string to receive"
delegate_to: localhost
- name: Remove TCP Monitor
bigip_monitor_tcp:
state: "absent"
server: "lb.mydomain.com"
user: "admin"
password: "secret"
name: "my_tcp_monitor"
'''
TEMPLATE_TYPE = DEFAULT_TEMPLATE_TYPE = 'TTYPE_TCP'
TEMPLATE_TYPE_CHOICES = ['tcp', 'tcp_echo', 'tcp_half_open']
DEFAULT_PARENT = DEFAULT_TEMPLATE_TYPE_CHOICE = DEFAULT_TEMPLATE_TYPE.replace('TTYPE_', '').lower()
def check_monitor_exists(module, api, monitor, parent):
# hack to determine if monitor exists
result = False
try:
ttype = api.LocalLB.Monitor.get_template_type(template_names=[monitor])[0]
parent2 = api.LocalLB.Monitor.get_parent_template(template_names=[monitor])[0]
if ttype == TEMPLATE_TYPE and parent == parent2:
result = True
else:
module.fail_json(msg='Monitor already exists, but has a different type (%s) or parent(%s)' % (ttype, parent))
except bigsuds.OperationFailed as e:
if "was not found" in str(e):
result = False
else:
# genuine exception
raise
return result
def create_monitor(api, monitor, template_attributes):
try:
api.LocalLB.Monitor.create_template(
templates=[{
'template_name': monitor,
'template_type': TEMPLATE_TYPE
}],
template_attributes=[template_attributes]
)
except bigsuds.OperationFailed as e:
if "already exists" in str(e):
return False
else:
# genuine exception
raise
return True
def delete_monitor(api, monitor):
try:
api.LocalLB.Monitor.delete_template(template_names=[monitor])
except bigsuds.OperationFailed as e:
# maybe it was deleted since we checked
if "was not found" in str(e):
return False
else:
# genuine exception
raise
return True
def check_string_property(api, monitor, str_property):
try:
template_prop = api.LocalLB.Monitor.get_template_string_property(
[monitor], [str_property['type']]
)[0]
return str_property == template_prop
except bigsuds.OperationFailed as e:
# happens in check mode if not created yet
if "was not found" in str(e):
return True
else:
# genuine exception
raise
def set_string_property(api, monitor, str_property):
api.LocalLB.Monitor.set_template_string_property(
template_names=[monitor],
values=[str_property]
)
def check_integer_property(api, monitor, int_property):
try:
return int_property == api.LocalLB.Monitor.get_template_integer_property(
[monitor], [int_property['type']]
)[0]
except bigsuds.OperationFailed as e:
# happens in check mode if not created yet
if "was not found" in str(e):
return True
else:
# genuine exception
raise
def set_integer_property(api, monitor, int_property):
api.LocalLB.Monitor.set_template_integer_property(
template_names=[monitor],
values=[int_property]
)
def update_monitor_properties(api, module, monitor, template_string_properties, template_integer_properties):
changed = False
for str_property in template_string_properties:
if str_property['value'] is not None and not check_string_property(api, monitor, str_property):
if not module.check_mode:
set_string_property(api, monitor, str_property)
changed = True
for int_property in template_integer_properties:
if int_property['value'] is not None and not check_integer_property(api, monitor, int_property):
if not module.check_mode:
set_integer_property(api, monitor, int_property)
changed = True
return changed
def get_ipport(api, monitor):
return api.LocalLB.Monitor.get_template_destination(template_names=[monitor])[0]
def set_ipport(api, monitor, ipport):
try:
api.LocalLB.Monitor.set_template_destination(
template_names=[monitor], destinations=[ipport]
)
return True, ""
except bigsuds.OperationFailed as e:
if "Cannot modify the address type of monitor" in str(e):
return False, "Cannot modify the address type of monitor if already assigned to a pool."
else:
# genuine exception
raise
def main():
argument_spec = f5_argument_spec()
meta_args = dict(
name=dict(required=True),
type=dict(default=DEFAULT_TEMPLATE_TYPE_CHOICE, choices=TEMPLATE_TYPE_CHOICES),
parent=dict(default=DEFAULT_PARENT),
parent_partition=dict(default='Common'),
send=dict(required=False),
receive=dict(required=False),
ip=dict(required=False),
port=dict(required=False, type='int'),
interval=dict(required=False, type='int'),
timeout=dict(required=False, type='int'),
time_until_up=dict(required=False, type='int', default=0)
)
argument_spec.update(meta_args)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True
)
if module.params['validate_certs']:
import ssl
if not hasattr(ssl, 'SSLContext'):
module.fail_json(msg='bigsuds does not support verifying certificates with python < 2.7.9. Either update python or set validate_certs=False on the task')
server = module.params['server']
server_port = module.params['server_port']
user = module.params['user']
password = module.params['password']
state = module.params['state']
partition = module.params['partition']
validate_certs = module.params['validate_certs']
parent_partition = module.params['parent_partition']
name = module.params['name']
type = 'TTYPE_' + module.params['type'].upper()
parent = fq_name(parent_partition, module.params['parent'])
monitor = fq_name(partition, name)
send = module.params['send']
receive = module.params['receive']
ip = module.params['ip']
port = module.params['port']
interval = module.params['interval']
timeout = module.params['timeout']
time_until_up = module.params['time_until_up']
# tcp monitor has multiple types, so overrule
global TEMPLATE_TYPE
TEMPLATE_TYPE = type
# end monitor specific stuff
api = bigip_api(server, user, password, validate_certs, port=server_port)
monitor_exists = check_monitor_exists(module, api, monitor, parent)
# ipport is a special setting
if monitor_exists:
# make sure to not update current settings if not asked
cur_ipport = get_ipport(api, monitor)
if ip is None:
ip = cur_ipport['ipport']['address']
if port is None:
port = cur_ipport['ipport']['port']
else:
# use API defaults if not defined to create it
if interval is None:
interval = 5
if timeout is None:
timeout = 16
if ip is None:
ip = '0.0.0.0'
if port is None:
port = 0
if send is None:
send = ''
if receive is None:
receive = ''
# define and set address type
if ip == '0.0.0.0' and port == 0:
address_type = 'ATYPE_STAR_ADDRESS_STAR_PORT'
elif ip == '0.0.0.0' and port != 0:
address_type = 'ATYPE_STAR_ADDRESS_EXPLICIT_PORT'
elif ip != '0.0.0.0' and port != 0:
address_type = 'ATYPE_EXPLICIT_ADDRESS_EXPLICIT_PORT'
else:
address_type = 'ATYPE_UNSET'
ipport = {
'address_type': address_type,
'ipport': {
'address': ip,
'port': port
}
}
template_attributes = {
'parent_template': parent,
'interval': interval,
'timeout': timeout,
'dest_ipport': ipport,
'is_read_only': False,
'is_directly_usable': True
}
# monitor specific stuff
if type == 'TTYPE_TCP':
template_string_properties = [
{
'type': 'STYPE_SEND',
'value': send
},
{
'type': 'STYPE_RECEIVE',
'value': receive
}
]
else:
template_string_properties = []
template_integer_properties = [
{
'type': 'ITYPE_INTERVAL',
'value': interval
},
{
'type': 'ITYPE_TIMEOUT',
'value': timeout
},
{
'type': 'ITYPE_TIME_UNTIL_UP',
'value': time_until_up
}
]
# main logic, monitor generic
try:
result = {'changed': False} # default
if state == 'absent':
if monitor_exists:
if not module.check_mode:
# possible race condition if same task
# on other node deleted it first
result['changed'] |= delete_monitor(api, monitor)
else:
result['changed'] |= True
else:
# check for monitor itself
if not monitor_exists:
if not module.check_mode:
# again, check changed status here b/c race conditions
# if other task already created it
result['changed'] |= create_monitor(api, monitor, template_attributes)
else:
result['changed'] |= True
# check for monitor parameters
# whether it already existed, or was just created, now update
# the update functions need to check for check mode but
# cannot update settings if it doesn't exist which happens in check mode
result['changed'] |= update_monitor_properties(api, module, monitor,
template_string_properties,
template_integer_properties)
# we just have to update the ipport if monitor already exists and it's different
if monitor_exists and cur_ipport != ipport:
set_ipport(api, monitor, ipport)
result['changed'] |= True
# else: monitor doesn't exist (check mode) or ipport is already ok
except Exception as e:
module.fail_json(msg="received exception: %s" % e)
module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.f5 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,
6171,
12,
8926,
303,
20744,
598,
262,
271,
345,
335,
351,
665,
332,
303,
32,
86,
621,
262,
271,
345,
335,
351,
14,
1235,
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,
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,
27281,
63,
7157,
63,
8815,
199,
3612,
63,
1802,
26,
298,
2395,
7441,
481,
21,
16524,
13,
1772,
491,
20690,
14719,
26862,
2,
199,
1802,
26,
523,
446,
298,
2395,
7441,
481,
21,
16524,
13,
1772,
491,
20690,
14719,
26862,
4799,
284,
3717,
26805,
3261,
2,
199,
1023,
63,
3270,
26,
298,
17,
14,
20,
2,
199,
2502,
26,
523,
446,
3739,
303,
20744,
598,
262,
271,
345,
335,
351,
8593,
5474,
10929,
9,
523,
446,
26244,
820,
384,
80,
8593,
2874,
72,
31898,
8255,
9,
199,
5983,
26,
523,
446,
298,
18153,
16524,
13,
1772,
2032,
1015,
2356,
4119,
2,
523,
446,
298,
38,
21,
477,
27813,
859,
283,
4492,
458,
14577,
7,
1415,
334,
3239,
1455,
921,
2374,
16067,
14,
70,
21,
14,
957,
2924,
523,
446,
298,
19478,
1255,
465,
282,
2257,
63,
1287,
315,
2195,
15695,
2,
523,
446,
298,
13189,
3261,
3794,
26,
4178,
921,
2374,
16067,
14,
70,
21,
14,
957,
15,
6797,
15,
73,
3717,
14,
24273,
363,
13189,
14,
1119,
88,
2,
199,
7538,
26,
523,
446,
12111,
458,
14577,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
26504,
1174,
272,
1415,
26,
3055,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
489,
446,
3451,
489,
446,
9552,
523,
536,
26,
272,
1369,
26,
489,
446,
26504,
536,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
5481,
26,
489,
446,
8372,
523,
6484,
26,
272,
1369,
26,
489,
446,
27353,
367,
314,
8372,
272,
1415,
26,
3055,
272,
849,
26,
283,
7844,
7,
523,
730,
26,
272,
1369,
26,
489,
446,
710,
1978,
730,
402,
642,
8372,
1978,
272,
1415,
26,
3055,
272,
849,
26,
283,
8815,
7,
272,
3415,
26,
489,
446,
377,
2711,
63,
9735,
489,
446,
377,
2711,
63,
9735,
63,
37,
10465,
489,
446,
377,
2711,
63,
9735,
63,
30323,
63,
9935,
523,
1676,
26,
272,
1369,
26,
489,
446,
710,
1676,
1978,
402,
642,
8372,
1978,
272,
1415,
26,
3055,
272,
849,
26,
283,
8815,
7,
272,
3415,
26,
489,
446,
14719,
489,
446,
14719,
63,
7878,
489,
446,
14719,
63,
10220,
63,
1490,
523,
1676,
63,
5312,
26,
272,
1369,
26,
489,
446,
27353,
367,
314,
1676,
8372,
272,
1415,
26,
3055,
272,
849,
26,
283,
7844,
7,
523,
3222,
26,
272,
1369,
26,
489,
446,
710,
3222,
1059,
367,
314,
8372,
1240,
272,
1415,
26,
2549,
272,
849,
26,
7179,
523,
9128,
26,
272,
1369,
26,
489,
446,
710,
9128,
1059,
367,
314,
8372,
1240,
272,
1415,
26,
2549,
272,
849,
26,
7179,
523,
3384,
26,
272,
1369,
26,
489,
446,
3531,
2287,
1777,
402,
314,
3384,
719,
5492,
14,
710,
849,
3261,
4260,
267,
365,
298,
16,
14,
16,
14,
16,
14,
16,
1674,
272,
1415,
26,
3055,
272,
849,
26,
7179,
523,
1844,
26,
272,
1369,
26,
489,
446,
10977,
2287,
1777,
1687,
314,
3384,
719,
5492,
14,
710,
849,
3261,
267,
4260,
365,
378,
14,
272,
1415,
26,
3055,
272,
849,
26,
7179,
523,
6252,
26,
272,
1369,
26,
489,
446,
710,
6252,
9176,
4212,
28914,
590,
314,
8372,
1256,
267,
402,
642,
1978,
911,
1255,
14,
4885,
849,
12,
642,
6252,
365,
1202,
367,
1536,
436,
267,
3224,
6363,
14,
710,
849,
3261,
4260,
365,
959,
14,
272,
1415,
26,
3055,
272,
849,
26,
7179,
523,
2653,
26,
272,
1369,
26,
489,
446,
710,
1329,
402,
4696,
315,
1314,
314,
1031,
503,
2435,
1471,
22722,
370,
267,
314,
8372,
1056,
14,
982,
314,
1347,
9163,
795,
4453,
314,
663,
900,
267,
6247,
12,
652,
365,
8652,
1536,
14,
982,
314,
1347,
1630,
440,
22722,
4453,
267,
314,
663,
900,
6247,
12,
652,
365,
8652,
3224,
14,
2047,
883,
1570,
642,
267,
1329,
370,
1263,
1329,
1265,
2934,
12,
13432,
12,
652,
1077,
506,
650,
5431,
314,
267,
6252,
1329,
402,
4696,
12254,
413,
3499,
14,
710,
849,
3261,
4260,
267,
365,
3193,
14,
272,
1415,
26,
3055,
272,
849,
26,
7179,
523,
900,
63,
8111,
63,
384,
26,
272,
1369,
26,
489,
446,
11015,
314,
5982,
402,
900,
315,
4696,
2410,
314,
1642,
9512,
267,
1177,
2544,
282,
1031,
911,
506,
11584,
1536,
14,
437,
574,
402,
378,
911,
7675,
282,
267,
1031,
370,
506,
11584,
1536,
9939,
2410,
282,
1686,
1177,
365,
3086,
267,
687,
314,
1031,
14,
710,
849,
3261,
4260,
365,
378,
14,
272,
1415,
26,
3055,
272,
849,
26,
7179,
199,
11036,
63,
9970,
63,
7677,
26,
289,
21,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2790,
13488,
26504,
523,
27281,
63,
7157,
63,
8815,
26,
272,
1174,
26,
298,
1881,
2,
272,
1654,
26,
298,
6374,
14,
30945,
14,
957,
2,
272,
922,
26,
298,
2113,
2
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6171,
12,
8926,
303,
20744,
598,
262,
271,
345,
335,
351,
665,
332,
303,
32,
86,
621,
262,
271,
345,
335,
351,
14,
1235,
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,
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,
27281,
63,
7157,
63,
8815,
199,
3612,
63,
1802,
26,
298,
2395,
7441,
481,
21,
16524,
13,
1772,
491,
20690,
14719,
26862,
2,
199,
1802,
26,
523,
446,
298,
2395,
7441,
481,
21,
16524,
13,
1772,
491,
20690,
14719,
26862,
4799,
284,
3717,
26805,
3261,
2,
199,
1023,
63,
3270,
26,
298,
17,
14,
20,
2,
199,
2502,
26,
523,
446,
3739,
303,
20744,
598,
262,
271,
345,
335,
351,
8593,
5474,
10929,
9,
523,
446,
26244,
820,
384,
80,
8593,
2874,
72,
31898,
8255,
9,
199,
5983,
26,
523,
446,
298,
18153,
16524,
13,
1772,
2032,
1015,
2356,
4119,
2,
523,
446,
298,
38,
21,
477,
27813,
859,
283,
4492,
458,
14577,
7,
1415,
334,
3239,
1455,
921,
2374,
16067,
14,
70,
21,
14,
957,
2924,
523,
446,
298,
19478,
1255,
465,
282,
2257,
63,
1287,
315,
2195,
15695,
2,
523,
446,
298,
13189,
3261,
3794,
26,
4178,
921,
2374,
16067,
14,
70,
21,
14,
957,
15,
6797,
15,
73,
3717,
14,
24273,
363,
13189,
14,
1119,
88,
2,
199,
7538,
26,
523,
446,
12111,
458,
14577,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
26504,
1174,
272,
1415,
26,
3055,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
489,
446,
3451,
489,
446,
9552,
523,
536,
26,
272,
1369,
26,
489,
446,
26504,
536,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
5481,
26,
489,
446,
8372,
523,
6484,
26,
272,
1369,
26,
489,
446,
27353,
367,
314,
8372,
272,
1415,
26,
3055,
272,
849,
26,
283,
7844,
7,
523,
730,
26,
272,
1369,
26,
489,
446,
710,
1978,
730,
402,
642,
8372,
1978,
272,
1415,
26,
3055,
272,
849,
26,
283,
8815,
7,
272,
3415,
26,
489,
446,
377,
2711,
63,
9735,
489,
446,
377,
2711,
63,
9735,
63,
37,
10465,
489,
446,
377,
2711,
63,
9735,
63,
30323,
63,
9935,
523,
1676,
26,
272,
1369,
26,
489,
446,
710,
1676,
1978,
402,
642,
8372,
1978,
272,
1415,
26,
3055,
272,
849,
26,
283,
8815,
7,
272,
3415,
26,
489,
446,
14719,
489,
446,
14719,
63,
7878,
489,
446,
14719,
63,
10220,
63,
1490,
523,
1676,
63,
5312,
26,
272,
1369,
26,
489,
446,
27353,
367,
314,
1676,
8372,
272,
1415,
26,
3055,
272,
849,
26,
283,
7844,
7,
523,
3222,
26,
272,
1369,
26,
489,
446,
710,
3222,
1059,
367,
314,
8372,
1240,
272,
1415,
26,
2549,
272,
849,
26,
7179,
523,
9128,
26,
272,
1369,
26,
489,
446,
710,
9128,
1059,
367,
314,
8372,
1240,
272,
1415,
26,
2549,
272,
849,
26,
7179,
523,
3384,
26,
272,
1369,
26,
489,
446,
3531,
2287,
1777,
402,
314,
3384,
719,
5492,
14,
710,
849,
3261,
4260,
267,
365,
298,
16,
14,
16,
14,
16,
14,
16,
1674,
272,
1415,
26,
3055,
272,
849,
26,
7179,
523,
1844,
26,
272,
1369,
26,
489,
446,
10977,
2287,
1777,
1687,
314,
3384,
719,
5492,
14,
710,
849,
3261,
267,
4260,
365,
378,
14,
272,
1415,
26,
3055,
272,
849,
26,
7179,
523,
6252,
26,
272,
1369,
26,
489,
446,
710,
6252,
9176,
4212,
28914,
590,
314,
8372,
1256,
267,
402,
642,
1978,
911,
1255,
14,
4885,
849,
12,
642,
6252,
365,
1202,
367,
1536,
436,
267,
3224,
6363,
14,
710,
849,
3261,
4260,
365,
959,
14,
272,
1415,
26,
3055,
272,
849,
26,
7179,
523,
2653,
26,
272,
1369,
26,
489,
446,
710,
1329,
402,
4696,
315,
1314,
314,
1031,
503,
2435,
1471,
22722,
370,
267,
314,
8372,
1056,
14,
982,
314,
1347,
9163,
795,
4453,
314,
663,
900,
267,
6247,
12,
652,
365,
8652,
1536,
14,
982,
314,
1347,
1630,
440,
22722,
4453,
267,
314,
663,
900,
6247,
12,
652,
365,
8652,
3224,
14,
2047,
883,
1570,
642,
267,
1329,
370,
1263,
1329,
1265,
2934,
12,
13432,
12,
652,
1077,
506,
650,
5431,
314,
267,
6252,
1329,
402,
4696,
12254,
413,
3499,
14,
710,
849,
3261,
4260,
267,
365,
3193,
14,
272,
1415,
26,
3055,
272,
849,
26,
7179,
523,
900,
63,
8111,
63,
384,
26,
272,
1369,
26,
489,
446,
11015,
314,
5982,
402,
900,
315,
4696,
2410,
314,
1642,
9512,
267,
1177,
2544,
282,
1031,
911,
506,
11584,
1536,
14,
437,
574,
402,
378,
911,
7675,
282,
267,
1031,
370,
506,
11584,
1536,
9939,
2410,
282,
1686,
1177,
365,
3086,
267,
687,
314,
1031,
14,
710,
849,
3261,
4260,
365,
378,
14,
272,
1415,
26,
3055,
272,
849,
26,
7179,
199,
11036,
63,
9970,
63,
7677,
26,
289,
21,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2790,
13488,
26504,
523,
27281,
63,
7157,
63,
8815,
26,
272,
1174,
26,
298,
1881,
2,
272,
1654,
26,
298,
6374,
14,
30945,
14,
957,
2,
272,
922,
26,
298,
2113,
2,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
toanalien/phantomjs
|
src/breakpad/src/third_party/protobuf/protobuf/python/google/protobuf/service_reflection.py
|
601
|
11010
|
# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc. All rights reserved.
# http://code.google.com/p/protobuf/
#
# 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.
"""Contains metaclasses used to create protocol service and service stub
classes from ServiceDescriptor objects at runtime.
The GeneratedServiceType and GeneratedServiceStubType metaclasses are used to
inject all useful functionality into the classes output by the protocol
compiler at compile-time.
"""
__author__ = 'petar@google.com (Petar Petrov)'
class GeneratedServiceType(type):
"""Metaclass for service classes created at runtime from ServiceDescriptors.
Implementations for all methods described in the Service class are added here
by this class. We also create properties to allow getting/setting all fields
in the protocol message.
The protocol compiler currently uses this metaclass to create protocol service
classes at runtime. Clients can also manually create their own classes at
runtime, as in this example:
mydescriptor = ServiceDescriptor(.....)
class MyProtoService(service.Service):
__metaclass__ = GeneratedServiceType
DESCRIPTOR = mydescriptor
myservice_instance = MyProtoService()
...
"""
_DESCRIPTOR_KEY = 'DESCRIPTOR'
def __init__(cls, name, bases, dictionary):
"""Creates a message service class.
Args:
name: Name of the class (ignored, but required by the metaclass
protocol).
bases: Base classes of the class being constructed.
dictionary: The class dictionary of the class being constructed.
dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object
describing this protocol service type.
"""
# Don't do anything if this class doesn't have a descriptor. This happens
# when a service class is subclassed.
if GeneratedServiceType._DESCRIPTOR_KEY not in dictionary:
return
descriptor = dictionary[GeneratedServiceType._DESCRIPTOR_KEY]
service_builder = _ServiceBuilder(descriptor)
service_builder.BuildService(cls)
class GeneratedServiceStubType(GeneratedServiceType):
"""Metaclass for service stubs created at runtime from ServiceDescriptors.
This class has similar responsibilities as GeneratedServiceType, except that
it creates the service stub classes.
"""
_DESCRIPTOR_KEY = 'DESCRIPTOR'
def __init__(cls, name, bases, dictionary):
"""Creates a message service stub class.
Args:
name: Name of the class (ignored, here).
bases: Base classes of the class being constructed.
dictionary: The class dictionary of the class being constructed.
dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object
describing this protocol service type.
"""
super(GeneratedServiceStubType, cls).__init__(name, bases, dictionary)
# Don't do anything if this class doesn't have a descriptor. This happens
# when a service stub is subclassed.
if GeneratedServiceStubType._DESCRIPTOR_KEY not in dictionary:
return
descriptor = dictionary[GeneratedServiceStubType._DESCRIPTOR_KEY]
service_stub_builder = _ServiceStubBuilder(descriptor)
service_stub_builder.BuildServiceStub(cls)
class _ServiceBuilder(object):
"""This class constructs a protocol service class using a service descriptor.
Given a service descriptor, this class constructs a class that represents
the specified service descriptor. One service builder instance constructs
exactly one service class. That means all instances of that class share the
same builder.
"""
def __init__(self, service_descriptor):
"""Initializes an instance of the service class builder.
Args:
service_descriptor: ServiceDescriptor to use when constructing the
service class.
"""
self.descriptor = service_descriptor
def BuildService(self, cls):
"""Constructs the service class.
Args:
cls: The class that will be constructed.
"""
# CallMethod needs to operate with an instance of the Service class. This
# internal wrapper function exists only to be able to pass the service
# instance to the method that does the real CallMethod work.
def _WrapCallMethod(srvc, method_descriptor,
rpc_controller, request, callback):
return self._CallMethod(srvc, method_descriptor,
rpc_controller, request, callback)
self.cls = cls
cls.CallMethod = _WrapCallMethod
cls.GetDescriptor = staticmethod(lambda: self.descriptor)
cls.GetDescriptor.__doc__ = "Returns the service descriptor."
cls.GetRequestClass = self._GetRequestClass
cls.GetResponseClass = self._GetResponseClass
for method in self.descriptor.methods:
setattr(cls, method.name, self._GenerateNonImplementedMethod(method))
def _CallMethod(self, srvc, method_descriptor,
rpc_controller, request, callback):
"""Calls the method described by a given method descriptor.
Args:
srvc: Instance of the service for which this method is called.
method_descriptor: Descriptor that represent the method to call.
rpc_controller: RPC controller to use for this method's execution.
request: Request protocol message.
callback: A callback to invoke after the method has completed.
"""
if method_descriptor.containing_service != self.descriptor:
raise RuntimeError(
'CallMethod() given method descriptor for wrong service type.')
method = getattr(srvc, method_descriptor.name)
return method(rpc_controller, request, callback)
def _GetRequestClass(self, method_descriptor):
"""Returns the class of the request protocol message.
Args:
method_descriptor: Descriptor of the method for which to return the
request protocol message class.
Returns:
A class that represents the input protocol message of the specified
method.
"""
if method_descriptor.containing_service != self.descriptor:
raise RuntimeError(
'GetRequestClass() given method descriptor for wrong service type.')
return method_descriptor.input_type._concrete_class
def _GetResponseClass(self, method_descriptor):
"""Returns the class of the response protocol message.
Args:
method_descriptor: Descriptor of the method for which to return the
response protocol message class.
Returns:
A class that represents the output protocol message of the specified
method.
"""
if method_descriptor.containing_service != self.descriptor:
raise RuntimeError(
'GetResponseClass() given method descriptor for wrong service type.')
return method_descriptor.output_type._concrete_class
def _GenerateNonImplementedMethod(self, method):
"""Generates and returns a method that can be set for a service methods.
Args:
method: Descriptor of the service method for which a method is to be
generated.
Returns:
A method that can be added to the service class.
"""
return lambda inst, rpc_controller, request, callback: (
self._NonImplementedMethod(method.name, rpc_controller, callback))
def _NonImplementedMethod(self, method_name, rpc_controller, callback):
"""The body of all methods in the generated service class.
Args:
method_name: Name of the method being executed.
rpc_controller: RPC controller used to execute this method.
callback: A callback which will be invoked when the method finishes.
"""
rpc_controller.SetFailed('Method %s not implemented.' % method_name)
callback(None)
class _ServiceStubBuilder(object):
"""Constructs a protocol service stub class using a service descriptor.
Given a service descriptor, this class constructs a suitable stub class.
A stub is just a type-safe wrapper around an RpcChannel which emulates a
local implementation of the service.
One service stub builder instance constructs exactly one class. It means all
instances of that class share the same service stub builder.
"""
def __init__(self, service_descriptor):
"""Initializes an instance of the service stub class builder.
Args:
service_descriptor: ServiceDescriptor to use when constructing the
stub class.
"""
self.descriptor = service_descriptor
def BuildServiceStub(self, cls):
"""Constructs the stub class.
Args:
cls: The class that will be constructed.
"""
def _ServiceStubInit(stub, rpc_channel):
stub.rpc_channel = rpc_channel
self.cls = cls
cls.__init__ = _ServiceStubInit
for method in self.descriptor.methods:
setattr(cls, method.name, self._GenerateStubMethod(method))
def _GenerateStubMethod(self, method):
return (lambda inst, rpc_controller, request, callback=None:
self._StubMethod(inst, method, rpc_controller, request, callback))
def _StubMethod(self, stub, method_descriptor,
rpc_controller, request, callback):
"""The body of all service methods in the generated stub class.
Args:
stub: Stub instance.
method_descriptor: Descriptor of the invoked method.
rpc_controller: Rpc controller to execute the method.
request: Request protocol message.
callback: A callback to execute when the method finishes.
Returns:
Response message (in case of blocking call).
"""
return stub.rpc_channel.CallMethod(
method_descriptor, rpc_controller, request,
method_descriptor.output_type._concrete_class, callback)
|
bsd-3-clause
|
[
3,
11557,
699,
3043,
1192,
446,
4475,
1159,
666,
1640,
1461,
1475,
199,
3,
1898,
9079,
4475,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
7204,
15,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
6906,
3404,
2888,
1202,
370,
1218,
4113,
2435,
436,
2435,
10098,
199,
2888,
687,
7591,
4311,
2251,
737,
8836,
14,
199,
199,
1918,
17065,
3167,
804,
436,
17065,
3167,
8067,
804,
3404,
2888,
787,
1202,
370,
199,
14815,
1006,
2997,
9330,
1901,
314,
3992,
1072,
701,
314,
4113,
199,
5772,
737,
6555,
13,
521,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
321,
5369,
32,
3098,
14,
957,
334,
48,
386,
285,
31449,
293,
86,
3171,
421,
199,
533,
17065,
3167,
804,
8,
466,
304,
819,
408,
29387,
367,
2435,
3992,
2737,
737,
8836,
687,
7591,
2586,
30547,
14,
819,
22467,
1298,
367,
1006,
3102,
11736,
315,
314,
7591,
1021,
787,
3483,
2348,
523,
701,
642,
1021,
14,
2136,
2597,
1218,
4382,
370,
2040,
10232,
15,
6031,
1006,
1504,
523,
315,
314,
4113,
1245,
14,
819,
710,
4113,
6365,
5544,
4440,
642,
17074,
370,
1218,
4113,
2435,
523,
3992,
737,
8836,
14,
6810,
83,
883,
2597,
10250,
1218,
3932,
5705,
3992,
737,
523,
8836,
12,
465,
315,
642,
2893,
26,
819,
3002,
4120,
275,
7591,
4311,
8,
703,
11965,
523,
1021,
4932,
8548,
3167,
8,
1364,
14,
3167,
304,
272,
636,
6577,
363,
275,
17065,
3167,
804,
272,
21034,
275,
3002,
4120,
523,
3002,
1364,
63,
842,
275,
4932,
8548,
3167,
342,
523,
2263,
523,
408,
819,
485,
7580,
63,
3078,
275,
283,
7580,
7,
819,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
2600,
304,
272,
408,
10607,
282,
1245,
2435,
1021,
14,
339,
3033,
26,
489,
536,
26,
2812,
402,
314,
1021,
334,
11996,
12,
1325,
1415,
701,
314,
17074,
267,
4113,
680,
489,
9768,
26,
3523,
3992,
402,
314,
1021,
3769,
14701,
14,
489,
2600,
26,
710,
1021,
2600,
402,
314,
1021,
3769,
14701,
14,
267,
2600,
13040,
7580,
63,
3078,
61,
1471,
1395,
282,
7591,
4311,
909,
267,
13660,
642,
4113,
2435,
730,
14,
272,
408,
272,
327,
7529,
1133,
886,
7003,
340,
642,
1021,
3181,
1133,
1172,
282,
5872,
14,
961,
10986,
272,
327,
1380,
282,
2435,
1021,
365,
1007,
28271,
14,
272,
340,
17065,
3167,
804,
423,
7580,
63,
3078,
440,
315,
2600,
26,
489,
372,
272,
5872,
275,
2600,
59,
12706,
3167,
804,
423,
7580,
63,
3078,
61,
272,
2435,
63,
5649,
275,
485,
3167,
6437,
8,
4120,
9,
272,
2435,
63,
5649,
14,
3425,
3167,
8,
1886,
9,
421,
199,
533,
17065,
3167,
8067,
804,
8,
12706,
3167,
804,
304,
819,
408,
29387,
367,
2435,
22312,
2737,
737,
8836,
687,
7591,
2586,
30547,
14,
819,
961,
1021,
965,
8545,
9163,
23422,
465,
17065,
3167,
804,
12,
871,
626,
523,
652,
8491,
314,
2435,
10098,
3992,
14,
523,
408,
819,
485,
7580,
63,
3078,
275,
283,
7580,
7,
819,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
2600,
304,
272,
408,
10607,
282,
1245,
2435,
10098,
1021,
14,
339,
3033,
26,
489,
536,
26,
2812,
402,
314,
1021,
334,
11996,
12,
2348,
680,
489,
9768,
26,
3523,
3992,
402,
314,
1021,
3769,
14701,
14,
489,
2600,
26,
710,
1021,
2600,
402,
314,
1021,
3769,
14701,
14,
267,
2600,
13040,
7580,
63,
3078,
61,
1471,
1395,
282,
7591,
4311,
909,
267,
13660,
642,
4113,
2435,
730,
14,
272,
408,
272,
1613,
8,
12706,
3167,
8067,
804,
12,
843,
2843,
826,
721,
354,
12,
9768,
12,
2600,
9,
272,
327,
7529,
1133,
886,
7003,
340,
642,
1021,
3181,
1133,
1172,
282,
5872,
14,
961,
10986,
272,
327,
1380,
282,
2435,
10098,
365,
1007,
28271,
14,
272,
340,
17065,
3167,
8067,
804,
423,
7580,
63,
3078,
440,
315,
2600,
26,
489,
372,
272,
5872,
275,
2600,
59,
12706,
3167,
8067,
804,
423,
7580,
63,
3078,
61,
272,
2435,
63,
5811,
63,
5649,
275,
485,
3167,
8067,
6437,
8,
4120,
9,
272,
2435,
63,
5811,
63,
5649,
14,
3425,
3167,
8067,
8,
1886,
9,
421,
199,
533,
485,
3167,
6437,
8,
785,
304,
819,
408,
2765,
1021,
21638,
282,
4113,
2435,
1021,
1808,
282,
2435,
5872,
14,
819,
9138,
282,
2435,
5872,
12,
642,
1021,
21638,
282,
1021,
626,
8469,
523,
314,
2013,
2435,
5872,
14,
7309
] |
[
11557,
699,
3043,
1192,
446,
4475,
1159,
666,
1640,
1461,
1475,
199,
3,
1898,
9079,
4475,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
7204,
15,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
6906,
3404,
2888,
1202,
370,
1218,
4113,
2435,
436,
2435,
10098,
199,
2888,
687,
7591,
4311,
2251,
737,
8836,
14,
199,
199,
1918,
17065,
3167,
804,
436,
17065,
3167,
8067,
804,
3404,
2888,
787,
1202,
370,
199,
14815,
1006,
2997,
9330,
1901,
314,
3992,
1072,
701,
314,
4113,
199,
5772,
737,
6555,
13,
521,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
321,
5369,
32,
3098,
14,
957,
334,
48,
386,
285,
31449,
293,
86,
3171,
421,
199,
533,
17065,
3167,
804,
8,
466,
304,
819,
408,
29387,
367,
2435,
3992,
2737,
737,
8836,
687,
7591,
2586,
30547,
14,
819,
22467,
1298,
367,
1006,
3102,
11736,
315,
314,
7591,
1021,
787,
3483,
2348,
523,
701,
642,
1021,
14,
2136,
2597,
1218,
4382,
370,
2040,
10232,
15,
6031,
1006,
1504,
523,
315,
314,
4113,
1245,
14,
819,
710,
4113,
6365,
5544,
4440,
642,
17074,
370,
1218,
4113,
2435,
523,
3992,
737,
8836,
14,
6810,
83,
883,
2597,
10250,
1218,
3932,
5705,
3992,
737,
523,
8836,
12,
465,
315,
642,
2893,
26,
819,
3002,
4120,
275,
7591,
4311,
8,
703,
11965,
523,
1021,
4932,
8548,
3167,
8,
1364,
14,
3167,
304,
272,
636,
6577,
363,
275,
17065,
3167,
804,
272,
21034,
275,
3002,
4120,
523,
3002,
1364,
63,
842,
275,
4932,
8548,
3167,
342,
523,
2263,
523,
408,
819,
485,
7580,
63,
3078,
275,
283,
7580,
7,
819,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
2600,
304,
272,
408,
10607,
282,
1245,
2435,
1021,
14,
339,
3033,
26,
489,
536,
26,
2812,
402,
314,
1021,
334,
11996,
12,
1325,
1415,
701,
314,
17074,
267,
4113,
680,
489,
9768,
26,
3523,
3992,
402,
314,
1021,
3769,
14701,
14,
489,
2600,
26,
710,
1021,
2600,
402,
314,
1021,
3769,
14701,
14,
267,
2600,
13040,
7580,
63,
3078,
61,
1471,
1395,
282,
7591,
4311,
909,
267,
13660,
642,
4113,
2435,
730,
14,
272,
408,
272,
327,
7529,
1133,
886,
7003,
340,
642,
1021,
3181,
1133,
1172,
282,
5872,
14,
961,
10986,
272,
327,
1380,
282,
2435,
1021,
365,
1007,
28271,
14,
272,
340,
17065,
3167,
804,
423,
7580,
63,
3078,
440,
315,
2600,
26,
489,
372,
272,
5872,
275,
2600,
59,
12706,
3167,
804,
423,
7580,
63,
3078,
61,
272,
2435,
63,
5649,
275,
485,
3167,
6437,
8,
4120,
9,
272,
2435,
63,
5649,
14,
3425,
3167,
8,
1886,
9,
421,
199,
533,
17065,
3167,
8067,
804,
8,
12706,
3167,
804,
304,
819,
408,
29387,
367,
2435,
22312,
2737,
737,
8836,
687,
7591,
2586,
30547,
14,
819,
961,
1021,
965,
8545,
9163,
23422,
465,
17065,
3167,
804,
12,
871,
626,
523,
652,
8491,
314,
2435,
10098,
3992,
14,
523,
408,
819,
485,
7580,
63,
3078,
275,
283,
7580,
7,
819,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
2600,
304,
272,
408,
10607,
282,
1245,
2435,
10098,
1021,
14,
339,
3033,
26,
489,
536,
26,
2812,
402,
314,
1021,
334,
11996,
12,
2348,
680,
489,
9768,
26,
3523,
3992,
402,
314,
1021,
3769,
14701,
14,
489,
2600,
26,
710,
1021,
2600,
402,
314,
1021,
3769,
14701,
14,
267,
2600,
13040,
7580,
63,
3078,
61,
1471,
1395,
282,
7591,
4311,
909,
267,
13660,
642,
4113,
2435,
730,
14,
272,
408,
272,
1613,
8,
12706,
3167,
8067,
804,
12,
843,
2843,
826,
721,
354,
12,
9768,
12,
2600,
9,
272,
327,
7529,
1133,
886,
7003,
340,
642,
1021,
3181,
1133,
1172,
282,
5872,
14,
961,
10986,
272,
327,
1380,
282,
2435,
10098,
365,
1007,
28271,
14,
272,
340,
17065,
3167,
8067,
804,
423,
7580,
63,
3078,
440,
315,
2600,
26,
489,
372,
272,
5872,
275,
2600,
59,
12706,
3167,
8067,
804,
423,
7580,
63,
3078,
61,
272,
2435,
63,
5811,
63,
5649,
275,
485,
3167,
8067,
6437,
8,
4120,
9,
272,
2435,
63,
5811,
63,
5649,
14,
3425,
3167,
8067,
8,
1886,
9,
421,
199,
533,
485,
3167,
6437,
8,
785,
304,
819,
408,
2765,
1021,
21638,
282,
4113,
2435,
1021,
1808,
282,
2435,
5872,
14,
819,
9138,
282,
2435,
5872,
12,
642,
1021,
21638,
282,
1021,
626,
8469,
523,
314,
2013,
2435,
5872,
14,
7309,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
w4/belle
|
dave/modules/weather.py
|
2
|
5156
|
# -*- coding: utf-8 -*-
"""Get the weather from an address using forecast.io."""
from __future__ import division
import dave.modules
import requests
import dave.config
import pickle
from urllib.parse import quote_plus
import arrow
from dave.models import Location
import socket
@dave.module.help("Syntax: weather [location]. Get the forecast in the specified location.")
@dave.module.command(["weather"], "?( .*)?$")
@dave.module.priority(dave.module.Priority.HIGHEST)
@dave.module.ratelimit(1, 5)
def weather(bot, args, sender, source):
location = args[0]
db_location = dave.config.session.query(Location).filter(Location.nick.ilike(sender)).first()
if not location:
if db_location:
location = db_location.location
else:
return
else:
location = location.strip()
if db_location:
db_location.location = location
else:
db_location = Location(nick=sender, location=location)
dave.config.session.add(db_location)
geocode = get_location(location)
if not geocode or not geocode["results"]:
return
formatted_address = get_address(geocode)
timezone = get_timezone(geocode)
weather = get_weather(geocode)
bot.reply(source, sender, u"{}: {}°C/{}°F (feels like {}°C/{}°F), {}. Wind: {}mph/{}km/h, humidity: {}% | Sun: {} - {} {}".format(
formatted_address,
int(round(weather["currently"]["temperature"])),
int(round(weather["currently"]["temperature"] * (9 / 5) + 32)),
int(round(weather["currently"]["apparentTemperature"])),
int(round(weather["currently"]["apparentTemperature"] * (9 / 5) + 32)),
weather["currently"]["summary"],
int(round(weather["currently"]["windSpeed"])),
int(round(weather["currently"]["windSpeed"] * 1.60934)),
int(round(weather["currently"]["humidity"] * 100)),
arrow.get(weather["daily"]["data"][0]["sunriseTime"]).to(timezone["zoneName"] or "UTC").strftime("%H:%M").lower(),
arrow.get(weather["daily"]["data"][0]["sunsetTime"]).to(timezone["zoneName"] or "UTC").strftime("%H:%M").lower(),
timezone["abbreviation"] or "UTC"
))
def get_location(location):
"""Get the lat/long of the location the user gave us."""
key = "location:{}".format(location.lower())
if not dave.config.redis.exists(key):
r = requests.get("https://maps.googleapis.com/maps/api/geocode/json?address={}&key={}".format(
quote_plus(location),
dave.config.config["api_keys"]["google_maps"]
))
geocode = r.json()
dave.config.redis.set(key, pickle.dumps(geocode))
else:
geocode = pickle.loads(dave.config.redis.get(key))
return geocode
def get_address(geocode):
"""Get a nicely formatted location to return."""
formatted_address = []
has_locality = False
for component in geocode["results"][0]["address_components"]:
if "locality" in component["types"]:
has_locality = True
formatted_address.append(component["short_name"])
if "country" in component["types"]:
formatted_address.append(component["short_name"])
if not has_locality:
for component in geocode["results"][0]["address_components"]:
if "postal_town" in component["types"]:
formatted_address.insert(0, component["short_name"])
if len(formatted_address) < 2:
formatted_address = [a["short_name"] for a in geocode["results"][0]["address_components"]]
return ", ".join(formatted_address)
def get_timezone(geocode):
"""Get the timezone of the location the user gave us"""
key = "timezone:{}_{}".format(geocode["results"][0]["geometry"]["location"]["lat"],
geocode["results"][0]["geometry"]["location"]["lng"])
if not dave.config.redis.exists(key):
r = requests.get("http://api.timezonedb.com/?key={}&lat={}&lng={}&format=json".format(
dave.config.config["api_keys"]["timezonedb"],
geocode["results"][0]["geometry"]["location"]["lat"],
geocode["results"][0]["geometry"]["location"]["lng"]
))
timezone = r.json()
dave.config.redis.set(key, pickle.dumps(timezone))
else:
timezone = pickle.loads(dave.config.redis.get(key))
return timezone
def get_weather(geocode):
"""Get the weather for the location the user gave us"""
key = "weather:{}_{}".format(geocode["results"][0]["geometry"]["location"]["lat"],
geocode["results"][0]["geometry"]["location"]["lng"])
if not dave.config.redis.exists(key):
r = requests.get("https://api.forecast.io/forecast/{}/{},{}?units=uk2".format(
dave.config.config["api_keys"]["forecast.io"],
geocode["results"][0]["geometry"]["location"]["lat"],
geocode["results"][0]["geometry"]["location"]["lng"]
))
json = r.json()
dave.config.redis.setex(key, 300, pickle.dumps(json))
else:
json = pickle.loads(dave.config.redis.get(key))
return json
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
1002,
314,
29643,
687,
376,
2287,
1808,
11257,
2931,
14,
2308,
1041,
199,
504,
636,
2443,
363,
492,
4629,
199,
646,
366,
811,
14,
3112,
199,
646,
4145,
199,
646,
366,
811,
14,
888,
199,
646,
5927,
199,
504,
4011,
14,
1122,
492,
6313,
63,
6666,
199,
646,
18800,
199,
504,
366,
811,
14,
992,
492,
12625,
199,
646,
2838,
421,
199,
32,
68,
811,
14,
578,
14,
3437,
480,
16626,
26,
29643,
359,
1985,
1055,
2372,
314,
11257,
2931,
315,
314,
2013,
2909,
2685,
199,
32,
68,
811,
14,
578,
14,
1531,
5234,
23026,
2255,
23665,
8,
23076,
5547,
22550,
199,
32,
68,
811,
14,
578,
14,
6693,
8,
68,
811,
14,
578,
14,
14354,
14,
31977,
9,
199,
32,
68,
811,
14,
578,
14,
1866,
3097,
8,
17,
12,
959,
9,
199,
318,
29643,
8,
3018,
12,
1249,
12,
8904,
12,
1350,
304,
272,
2909,
275,
1249,
59,
16,
61,
339,
1592,
63,
1985,
275,
366,
811,
14,
888,
14,
1730,
14,
1131,
8,
6592,
680,
1541,
8,
6592,
14,
11082,
14,
27774,
8,
8114,
4992,
2246,
342,
339,
340,
440,
2909,
26,
267,
340,
1592,
63,
1985,
26,
288,
2909,
275,
1592,
63,
1985,
14,
1985,
267,
587,
26,
288,
372,
272,
587,
26,
267,
2909,
275,
2909,
14,
1913,
342,
398,
340,
1592,
63,
1985,
26,
288,
1592,
63,
1985,
14,
1985,
275,
2909,
267,
587,
26,
288,
1592,
63,
1985,
275,
12625,
8,
11082,
29,
8114,
12,
2909,
29,
1985,
9,
288,
366,
811,
14,
888,
14,
1730,
14,
525,
8,
697,
63,
1985,
9,
339,
8509,
600,
275,
664,
63,
1985,
8,
1985,
9,
339,
340,
440,
8509,
600,
503,
440,
8509,
600,
905,
2604,
6229,
267,
372,
339,
7871,
63,
1562,
275,
664,
63,
1562,
8,
6721,
600,
9,
272,
7137,
275,
664,
63,
7145,
8,
6721,
600,
9,
272,
29643,
275,
664,
63,
23026,
8,
6721,
600,
9,
339,
5888,
14,
8102,
8,
1365,
12,
8904,
12,
399,
2,
2440,
26,
1052,
127,
109,
35,
14698,
127,
109,
38,
334,
771,
18099,
2839,
1052,
127,
109,
35,
14698,
127,
109,
38,
395,
30332,
644,
688,
26,
1052,
311,
72,
14698,
14595,
15,
72,
12,
394,
21704,
26,
1052,
5,
1204,
25625,
26,
1052,
446,
1052,
8352,
908,
8,
267,
7871,
63,
1562,
12,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
12954,
3135,
395,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
12954,
937,
627,
334,
25,
1182,
959,
9,
435,
4337,
1826,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
439,
1708,
27409,
3135,
395,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
439,
1708,
27409,
937,
627,
334,
25,
1182,
959,
9,
435,
4337,
1826,
267,
29643,
905,
19767,
6611,
4705,
2255,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
11530,
15146,
3135,
395,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
11530,
15146,
937,
627,
413,
14,
14520,
1082,
1826,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
31812,
937,
627,
2948,
1826,
267,
18800,
14,
362,
8,
23026,
905,
18621,
6611,
576,
9210,
16,
7541,
11846,
28479,
1366,
29126,
475,
8,
7145,
905,
2619,
985,
937,
503,
298,
11288,
3471,
6205,
3647,
40,
2689,
45,
3471,
2325,
1062,
267,
18800,
14,
362,
8,
23026,
905,
18621,
6611,
576,
9210,
16,
7541,
11846,
409,
1366,
29126,
475,
8,
7145,
905,
2619,
985,
937,
503,
298,
11288,
3471,
6205,
3647,
40,
2689,
45,
3471,
2325,
1062,
267,
7137,
905,
371,
30369,
937,
503,
298,
11288,
2,
272,
5082,
421,
199,
318,
664,
63,
1985,
8,
1985,
304,
272,
408,
1002,
314,
8396,
15,
2809,
402,
314,
2909,
314,
922,
486,
811,
2739,
1041,
272,
790,
275,
298,
1985,
26,
13536,
908,
8,
1985,
14,
2325,
1012,
339,
340,
440,
366,
811,
14,
888,
14,
15369,
14,
2444,
8,
498,
304,
267,
519,
275,
4145,
14,
362,
480,
2859,
921,
8919,
14,
17533,
14,
957,
15,
8919,
15,
1246,
15,
6721,
600,
15,
1001,
31,
1562,
7622,
6,
498,
7622,
1674,
908,
8,
288,
6313,
63,
6666,
8,
1985,
395,
288,
366,
811,
14,
888,
14,
888,
905,
1246,
63,
1612,
6611,
3098,
63,
8919,
937,
267,
5082,
398,
8509,
600,
275,
519,
14,
1001,
342,
398,
366,
811,
14,
888,
14,
15369,
14,
409,
8,
498,
12,
5927,
14,
4180,
8,
6721,
600,
430,
272,
587,
26,
267,
8509,
600,
275,
5927,
14,
3640,
8,
68,
811,
14,
888,
14,
15369,
14,
362,
8,
498,
430,
339,
372,
8509,
600,
421,
199,
318,
664,
63,
1562,
8,
6721,
600,
304,
272,
408,
1002,
282,
14213,
590,
7871,
2909,
370,
372,
1041,
272,
7871,
63,
1562,
275,
942,
339,
965,
63,
1832,
1209,
275,
756,
339,
367,
3931,
315,
8509,
600,
905,
2604,
9210,
16,
7541,
1562,
63,
4608,
6229,
267,
340,
298,
1832,
1209,
2,
315,
3931,
905,
1313,
6229,
288,
965,
63,
1832,
1209,
275,
715,
288,
7871,
63,
1562,
14,
740,
8,
3173,
905,
3612,
63,
354,
3135,
398,
340,
298,
6063,
2,
315,
3931,
905,
1313,
6229,
288,
7871,
63,
1562,
14,
740,
8,
3173,
905,
3612,
63,
354,
3135,
339,
340,
440,
965,
63,
1832,
1209,
26,
267,
367,
3931,
315,
8509,
600,
905,
2604,
9210,
16,
7541,
1562,
63,
4608,
6229,
288,
340,
298,
31580,
63,
16231,
2,
315,
3931,
905,
1313,
6229,
355,
7871,
63,
1562,
14,
3176,
8,
16,
12,
3931,
905,
3612,
63,
354,
3135,
339,
340,
822,
8,
15317,
63,
1562,
9,
665,
499,
26,
267,
7871,
63,
1562,
275,
359,
65,
905,
3612,
63,
354,
937,
367,
282,
315,
8509,
600,
905,
2604,
9210,
16,
7541,
1562,
63,
4608,
15261,
339,
372,
3872,
3680,
904,
8,
15317,
63,
1562,
9,
421,
199,
318,
664,
63,
7145,
8,
6721,
600,
304,
272,
408,
1002,
314,
7137,
402,
314,
2909,
314,
922,
486,
811,
2739,
624,
272,
790,
275,
298,
7145,
29930,
63,
13536,
908,
8,
6721,
600,
905,
2604,
9210,
16,
7541,
7660,
6611,
1985,
6611,
4452,
2255,
3303,
8509,
600,
905,
2604,
9210,
16,
7541,
7660,
6611,
1985,
6611,
23829,
3135,
339,
340,
440,
366,
811,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
1002,
314,
29643,
687,
376,
2287,
1808,
11257,
2931,
14,
2308,
1041,
199,
504,
636,
2443,
363,
492,
4629,
199,
646,
366,
811,
14,
3112,
199,
646,
4145,
199,
646,
366,
811,
14,
888,
199,
646,
5927,
199,
504,
4011,
14,
1122,
492,
6313,
63,
6666,
199,
646,
18800,
199,
504,
366,
811,
14,
992,
492,
12625,
199,
646,
2838,
421,
199,
32,
68,
811,
14,
578,
14,
3437,
480,
16626,
26,
29643,
359,
1985,
1055,
2372,
314,
11257,
2931,
315,
314,
2013,
2909,
2685,
199,
32,
68,
811,
14,
578,
14,
1531,
5234,
23026,
2255,
23665,
8,
23076,
5547,
22550,
199,
32,
68,
811,
14,
578,
14,
6693,
8,
68,
811,
14,
578,
14,
14354,
14,
31977,
9,
199,
32,
68,
811,
14,
578,
14,
1866,
3097,
8,
17,
12,
959,
9,
199,
318,
29643,
8,
3018,
12,
1249,
12,
8904,
12,
1350,
304,
272,
2909,
275,
1249,
59,
16,
61,
339,
1592,
63,
1985,
275,
366,
811,
14,
888,
14,
1730,
14,
1131,
8,
6592,
680,
1541,
8,
6592,
14,
11082,
14,
27774,
8,
8114,
4992,
2246,
342,
339,
340,
440,
2909,
26,
267,
340,
1592,
63,
1985,
26,
288,
2909,
275,
1592,
63,
1985,
14,
1985,
267,
587,
26,
288,
372,
272,
587,
26,
267,
2909,
275,
2909,
14,
1913,
342,
398,
340,
1592,
63,
1985,
26,
288,
1592,
63,
1985,
14,
1985,
275,
2909,
267,
587,
26,
288,
1592,
63,
1985,
275,
12625,
8,
11082,
29,
8114,
12,
2909,
29,
1985,
9,
288,
366,
811,
14,
888,
14,
1730,
14,
525,
8,
697,
63,
1985,
9,
339,
8509,
600,
275,
664,
63,
1985,
8,
1985,
9,
339,
340,
440,
8509,
600,
503,
440,
8509,
600,
905,
2604,
6229,
267,
372,
339,
7871,
63,
1562,
275,
664,
63,
1562,
8,
6721,
600,
9,
272,
7137,
275,
664,
63,
7145,
8,
6721,
600,
9,
272,
29643,
275,
664,
63,
23026,
8,
6721,
600,
9,
339,
5888,
14,
8102,
8,
1365,
12,
8904,
12,
399,
2,
2440,
26,
1052,
127,
109,
35,
14698,
127,
109,
38,
334,
771,
18099,
2839,
1052,
127,
109,
35,
14698,
127,
109,
38,
395,
30332,
644,
688,
26,
1052,
311,
72,
14698,
14595,
15,
72,
12,
394,
21704,
26,
1052,
5,
1204,
25625,
26,
1052,
446,
1052,
8352,
908,
8,
267,
7871,
63,
1562,
12,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
12954,
3135,
395,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
12954,
937,
627,
334,
25,
1182,
959,
9,
435,
4337,
1826,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
439,
1708,
27409,
3135,
395,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
439,
1708,
27409,
937,
627,
334,
25,
1182,
959,
9,
435,
4337,
1826,
267,
29643,
905,
19767,
6611,
4705,
2255,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
11530,
15146,
3135,
395,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
11530,
15146,
937,
627,
413,
14,
14520,
1082,
1826,
267,
1109,
8,
2363,
8,
23026,
905,
19767,
6611,
31812,
937,
627,
2948,
1826,
267,
18800,
14,
362,
8,
23026,
905,
18621,
6611,
576,
9210,
16,
7541,
11846,
28479,
1366,
29126,
475,
8,
7145,
905,
2619,
985,
937,
503,
298,
11288,
3471,
6205,
3647,
40,
2689,
45,
3471,
2325,
1062,
267,
18800,
14,
362,
8,
23026,
905,
18621,
6611,
576,
9210,
16,
7541,
11846,
409,
1366,
29126,
475,
8,
7145,
905,
2619,
985,
937,
503,
298,
11288,
3471,
6205,
3647,
40,
2689,
45,
3471,
2325,
1062,
267,
7137,
905,
371,
30369,
937,
503,
298,
11288,
2,
272,
5082,
421,
199,
318,
664,
63,
1985,
8,
1985,
304,
272,
408,
1002,
314,
8396,
15,
2809,
402,
314,
2909,
314,
922,
486,
811,
2739,
1041,
272,
790,
275,
298,
1985,
26,
13536,
908,
8,
1985,
14,
2325,
1012,
339,
340,
440,
366,
811,
14,
888,
14,
15369,
14,
2444,
8,
498,
304,
267,
519,
275,
4145,
14,
362,
480,
2859,
921,
8919,
14,
17533,
14,
957,
15,
8919,
15,
1246,
15,
6721,
600,
15,
1001,
31,
1562,
7622,
6,
498,
7622,
1674,
908,
8,
288,
6313,
63,
6666,
8,
1985,
395,
288,
366,
811,
14,
888,
14,
888,
905,
1246,
63,
1612,
6611,
3098,
63,
8919,
937,
267,
5082,
398,
8509,
600,
275,
519,
14,
1001,
342,
398,
366,
811,
14,
888,
14,
15369,
14,
409,
8,
498,
12,
5927,
14,
4180,
8,
6721,
600,
430,
272,
587,
26,
267,
8509,
600,
275,
5927,
14,
3640,
8,
68,
811,
14,
888,
14,
15369,
14,
362,
8,
498,
430,
339,
372,
8509,
600,
421,
199,
318,
664,
63,
1562,
8,
6721,
600,
304,
272,
408,
1002,
282,
14213,
590,
7871,
2909,
370,
372,
1041,
272,
7871,
63,
1562,
275,
942,
339,
965,
63,
1832,
1209,
275,
756,
339,
367,
3931,
315,
8509,
600,
905,
2604,
9210,
16,
7541,
1562,
63,
4608,
6229,
267,
340,
298,
1832,
1209,
2,
315,
3931,
905,
1313,
6229,
288,
965,
63,
1832,
1209,
275,
715,
288,
7871,
63,
1562,
14,
740,
8,
3173,
905,
3612,
63,
354,
3135,
398,
340,
298,
6063,
2,
315,
3931,
905,
1313,
6229,
288,
7871,
63,
1562,
14,
740,
8,
3173,
905,
3612,
63,
354,
3135,
339,
340,
440,
965,
63,
1832,
1209,
26,
267,
367,
3931,
315,
8509,
600,
905,
2604,
9210,
16,
7541,
1562,
63,
4608,
6229,
288,
340,
298,
31580,
63,
16231,
2,
315,
3931,
905,
1313,
6229,
355,
7871,
63,
1562,
14,
3176,
8,
16,
12,
3931,
905,
3612,
63,
354,
3135,
339,
340,
822,
8,
15317,
63,
1562,
9,
665,
499,
26,
267,
7871,
63,
1562,
275,
359,
65,
905,
3612,
63,
354,
937,
367,
282,
315,
8509,
600,
905,
2604,
9210,
16,
7541,
1562,
63,
4608,
15261,
339,
372,
3872,
3680,
904,
8,
15317,
63,
1562,
9,
421,
199,
318,
664,
63,
7145,
8,
6721,
600,
304,
272,
408,
1002,
314,
7137,
402,
314,
2909,
314,
922,
486,
811,
2739,
624,
272,
790,
275,
298,
7145,
29930,
63,
13536,
908,
8,
6721,
600,
905,
2604,
9210,
16,
7541,
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