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
|
|---|---|---|---|---|---|---|---|---|
r0fls/sanic
|
sanic/app.py
|
1
|
29389
|
import logging
import logging.config
import re
import warnings
from asyncio import get_event_loop, ensure_future, CancelledError
from collections import deque, defaultdict
from functools import partial
from inspect import isawaitable, stack, getmodulename
from traceback import format_exc
from urllib.parse import urlencode, urlunparse
from ssl import create_default_context, Purpose
from sanic.config import Config, LOGGING
from sanic.constants import HTTP_METHODS
from sanic.exceptions import ServerError, URLBuildError, SanicException
from sanic.handlers import ErrorHandler
from sanic.log import log
from sanic.response import HTTPResponse, StreamingHTTPResponse
from sanic.router import Router
from sanic.server import serve, serve_multiple, HttpProtocol, Signal
from sanic.static import register as static_register
from sanic.testing import SanicTestClient
from sanic.views import CompositionView
from sanic.websocket import WebSocketProtocol, ConnectionClosed
class Sanic:
def __init__(self, name=None, router=None, error_handler=None,
load_env=True, request_class=None,
log_config=LOGGING):
if log_config:
logging.config.dictConfig(log_config)
# Only set up a default log handler if the
# end-user application didn't set anything up.
if not (logging.root.handlers and
log.level == logging.NOTSET and
log_config):
formatter = logging.Formatter(
"%(asctime)s: %(levelname)s: %(message)s")
handler = logging.StreamHandler()
handler.setFormatter(formatter)
log.addHandler(handler)
log.setLevel(logging.INFO)
# Get name from previous stack frame
if name is None:
frame_records = stack()[1]
name = getmodulename(frame_records[1])
self.name = name
self.router = router or Router()
self.request_class = request_class
self.error_handler = error_handler or ErrorHandler()
self.config = Config(load_env=load_env)
self.log_config = log_config
self.request_middleware = deque()
self.response_middleware = deque()
self.blueprints = {}
self._blueprint_order = []
self.debug = None
self.sock = None
self.listeners = defaultdict(list)
self.is_running = False
self.is_request_stream = False
self.websocket_enabled = False
self.websocket_tasks = []
# Register alternative method names
self.go_fast = self.run
@property
def loop(self):
"""Synonymous with asyncio.get_event_loop().
Only supported when using the `app.run` method.
"""
if not self.is_running:
raise SanicException(
'Loop can only be retrieved after the app has started '
'running. Not supported with `create_server` function')
return get_event_loop()
# -------------------------------------------------------------------- #
# Registration
# -------------------------------------------------------------------- #
def add_task(self, task):
"""Schedule a task to run later, after the loop has started.
Different from asyncio.ensure_future in that it does not
also return a future, and the actual ensure_future call
is delayed until before server start.
:param task: future, couroutine or awaitable
"""
@self.listener('before_server_start')
def run(app, loop):
if callable(task):
loop.create_task(task())
else:
loop.create_task(task)
# Decorator
def listener(self, event):
"""Create a listener from a decorated function.
:param event: event to listen to
"""
def decorator(listener):
self.listeners[event].append(listener)
return listener
return decorator
# Decorator
def route(self, uri, methods=frozenset({'GET'}), host=None,
strict_slashes=False, stream=False, version=None):
"""Decorate a function to be registered as a route
:param uri: path of the URL
:param methods: list or tuple of methods allowed
:param host:
:param strict_slashes:
:param stream:
:return: decorated function
"""
# Fix case where the user did not prefix the URL with a /
# and will probably get confused as to why it's not working
if not uri.startswith('/'):
uri = '/' + uri
if stream:
self.is_request_stream = True
def response(handler):
if stream:
handler.is_stream = stream
self.router.add(uri=uri, methods=methods, handler=handler,
host=host, strict_slashes=strict_slashes,
version=version)
return handler
return response
# Shorthand method decorators
def get(self, uri, host=None, strict_slashes=False, version=None):
return self.route(uri, methods=frozenset({"GET"}), host=host,
strict_slashes=strict_slashes, version=version)
def post(self, uri, host=None, strict_slashes=False, stream=False,
version=None):
return self.route(uri, methods=frozenset({"POST"}), host=host,
strict_slashes=strict_slashes, stream=stream,
version=version)
def put(self, uri, host=None, strict_slashes=False, stream=False,
version=None):
return self.route(uri, methods=frozenset({"PUT"}), host=host,
strict_slashes=strict_slashes, stream=stream,
version=version)
def head(self, uri, host=None, strict_slashes=False, version=None):
return self.route(uri, methods=frozenset({"HEAD"}), host=host,
strict_slashes=strict_slashes, version=version)
def options(self, uri, host=None, strict_slashes=False, version=None):
return self.route(uri, methods=frozenset({"OPTIONS"}), host=host,
strict_slashes=strict_slashes, version=version)
def patch(self, uri, host=None, strict_slashes=False, stream=False,
version=None):
return self.route(uri, methods=frozenset({"PATCH"}), host=host,
strict_slashes=strict_slashes, stream=stream,
version=version)
def delete(self, uri, host=None, strict_slashes=False, version=None):
return self.route(uri, methods=frozenset({"DELETE"}), host=host,
strict_slashes=strict_slashes, version=version)
def add_route(self, handler, uri, methods=frozenset({'GET'}), host=None,
strict_slashes=False, version=None):
"""A helper method to register class instance or
functions as a handler to the application url
routes.
:param handler: function or class instance
:param uri: path of the URL
:param methods: list or tuple of methods allowed, these are overridden
if using a HTTPMethodView
:param host:
:return: function or class instance
"""
stream = False
# Handle HTTPMethodView differently
if hasattr(handler, 'view_class'):
methods = set()
for method in HTTP_METHODS:
_handler = getattr(handler.view_class, method.lower(), None)
if _handler:
methods.add(method)
if hasattr(_handler, 'is_stream'):
stream = True
# handle composition view differently
if isinstance(handler, CompositionView):
methods = handler.handlers.keys()
for _handler in handler.handlers.values():
if hasattr(_handler, 'is_stream'):
stream = True
break
self.route(uri=uri, methods=methods, host=host,
strict_slashes=strict_slashes, stream=stream,
version=version)(handler)
return handler
# Decorator
def websocket(self, uri, host=None, strict_slashes=False):
"""Decorate a function to be registered as a websocket route
:param uri: path of the URL
:param host:
:return: decorated function
"""
self.enable_websocket()
# Fix case where the user did not prefix the URL with a /
# and will probably get confused as to why it's not working
if not uri.startswith('/'):
uri = '/' + uri
def response(handler):
async def websocket_handler(request, *args, **kwargs):
request.app = self
try:
protocol = request.transport.get_protocol()
except AttributeError:
# On Python3.5 the Transport classes in asyncio do not
# have a get_protocol() method as in uvloop
protocol = request.transport._protocol
ws = await protocol.websocket_handshake(request)
# schedule the application handler
# its future is kept in self.websocket_tasks in case it
# needs to be cancelled due to the server being stopped
fut = ensure_future(handler(request, ws, *args, **kwargs))
self.websocket_tasks.append(fut)
try:
await fut
except (CancelledError, ConnectionClosed):
pass
self.websocket_tasks.remove(fut)
await ws.close()
self.router.add(uri=uri, handler=websocket_handler,
methods=frozenset({'GET'}), host=host,
strict_slashes=strict_slashes)
return handler
return response
def add_websocket_route(self, handler, uri, host=None,
strict_slashes=False):
"""A helper method to register a function as a websocket route."""
return self.websocket(uri, host=host,
strict_slashes=strict_slashes)(handler)
def enable_websocket(self, enable=True):
"""Enable or disable the support for websocket.
Websocket is enabled automatically if websocket routes are
added to the application.
"""
if not self.websocket_enabled:
# if the server is stopped, we want to cancel any ongoing
# websocket tasks, to allow the server to exit promptly
@self.listener('before_server_stop')
def cancel_websocket_tasks(app, loop):
for task in self.websocket_tasks:
task.cancel()
self.websocket_enabled = enable
def remove_route(self, uri, clean_cache=True, host=None):
self.router.remove(uri, clean_cache, host)
# Decorator
def exception(self, *exceptions):
"""Decorate a function to be registered as a handler for exceptions
:param exceptions: exceptions
:return: decorated function
"""
def response(handler):
for exception in exceptions:
if isinstance(exception, (tuple, list)):
for e in exception:
self.error_handler.add(e, handler)
else:
self.error_handler.add(exception, handler)
return handler
return response
def register_middleware(self, middleware, attach_to='request'):
if attach_to == 'request':
self.request_middleware.append(middleware)
if attach_to == 'response':
self.response_middleware.appendleft(middleware)
return middleware
# Decorator
def middleware(self, middleware_or_request):
"""Decorate and register middleware to be called before a request.
Can either be called as @app.middleware or @app.middleware('request')
"""
# Detect which way this was called, @middleware or @middleware('AT')
if callable(middleware_or_request):
return self.register_middleware(middleware_or_request)
else:
return partial(self.register_middleware,
attach_to=middleware_or_request)
# Static Files
def static(self, uri, file_or_directory, pattern=r'/?.+',
use_modified_since=True, use_content_range=False,
stream_large_files=False):
"""Register a root to serve files from. The input can either be a
file or a directory. See
"""
static_register(self, uri, file_or_directory, pattern,
use_modified_since, use_content_range,
stream_large_files)
def blueprint(self, blueprint, **options):
"""Register a blueprint on the application.
:param blueprint: Blueprint object
:param options: option dictionary with blueprint defaults
:return: Nothing
"""
if blueprint.name in self.blueprints:
assert self.blueprints[blueprint.name] is blueprint, \
'A blueprint with the name "%s" is already registered. ' \
'Blueprint names must be unique.' % \
(blueprint.name,)
else:
self.blueprints[blueprint.name] = blueprint
self._blueprint_order.append(blueprint)
blueprint.register(self, options)
def register_blueprint(self, *args, **kwargs):
# TODO: deprecate 1.0
if self.debug:
warnings.simplefilter('default')
warnings.warn("Use of register_blueprint will be deprecated in "
"version 1.0. Please use the blueprint method"
" instead",
DeprecationWarning)
return self.blueprint(*args, **kwargs)
def url_for(self, view_name: str, **kwargs):
"""Build a URL based on a view name and the values provided.
In order to build a URL, all request parameters must be supplied as
keyword arguments, and each parameter must pass the test for the
specified parameter type. If these conditions are not met, a
`URLBuildError` will be thrown.
Keyword arguments that are not request parameters will be included in
the output URL's query string.
:param view_name: string referencing the view name
:param \*\*kwargs: keys and values that are used to build request
parameters and query string arguments.
:return: the built URL
Raises:
URLBuildError
"""
# find the route by the supplied view name
uri, route = self.router.find_route_by_view_name(view_name)
if not uri or not route:
raise URLBuildError(
'Endpoint with name `{}` was not found'.format(
view_name))
if uri != '/' and uri.endswith('/'):
uri = uri[:-1]
out = uri
# find all the parameters we will need to build in the URL
matched_params = re.findall(
self.router.parameter_pattern, uri)
# _method is only a placeholder now, don't know how to support it
kwargs.pop('_method', None)
anchor = kwargs.pop('_anchor', '')
# _external need SERVER_NAME in config or pass _server arg
external = kwargs.pop('_external', False)
scheme = kwargs.pop('_scheme', '')
if scheme and not external:
raise ValueError('When specifying _scheme, _external must be True')
netloc = kwargs.pop('_server', None)
if netloc is None and external:
netloc = self.config.get('SERVER_NAME', '')
for match in matched_params:
name, _type, pattern = self.router.parse_parameter_string(
match)
# we only want to match against each individual parameter
specific_pattern = '^{}$'.format(pattern)
supplied_param = None
if kwargs.get(name):
supplied_param = kwargs.get(name)
del kwargs[name]
else:
raise URLBuildError(
'Required parameter `{}` was not passed to url_for'.format(
name))
supplied_param = str(supplied_param)
# determine if the parameter supplied by the caller passes the test
# in the URL
passes_pattern = re.match(specific_pattern, supplied_param)
if not passes_pattern:
if _type != str:
msg = (
'Value "{}" for parameter `{}` does not '
'match pattern for type `{}`: {}'.format(
supplied_param, name, _type.__name__, pattern))
else:
msg = (
'Value "{}" for parameter `{}` '
'does not satisfy pattern {}'.format(
supplied_param, name, pattern))
raise URLBuildError(msg)
# replace the parameter in the URL with the supplied value
replacement_regex = '(<{}.*?>)'.format(name)
out = re.sub(
replacement_regex, supplied_param, out)
# parse the remainder of the keyword arguments into a querystring
query_string = urlencode(kwargs, doseq=True) if kwargs else ''
# scheme://netloc/path;parameters?query#fragment
out = urlunparse((scheme, netloc, out, '', query_string, anchor))
return out
# -------------------------------------------------------------------- #
# Request Handling
# -------------------------------------------------------------------- #
def converted_response_type(self, response):
pass
async def handle_request(self, request, write_callback, stream_callback):
"""Take a request from the HTTP Server and return a response object
to be sent back The HTTP Server only expects a response object, so
exception handling must be done here
:param request: HTTP Request object
:param write_callback: Synchronous response function to be
called with the response as the only argument
:param stream_callback: Coroutine that handles streaming a
StreamingHTTPResponse if produced by the handler.
:return: Nothing
"""
try:
# -------------------------------------------- #
# Request Middleware
# -------------------------------------------- #
request.app = self
response = await self._run_request_middleware(request)
# No middleware results
if not response:
# -------------------------------------------- #
# Execute Handler
# -------------------------------------------- #
# Fetch handler from router
handler, args, kwargs, uri = self.router.get(request)
request.uri_template = uri
if handler is None:
raise ServerError(
("'None' was returned while requesting a "
"handler from the router"))
# Run response handler
response = handler(request, *args, **kwargs)
if isawaitable(response):
response = await response
except Exception as e:
# -------------------------------------------- #
# Response Generation Failed
# -------------------------------------------- #
try:
response = self.error_handler.response(request, e)
if isawaitable(response):
response = await response
except Exception as e:
if self.debug:
response = HTTPResponse(
"Error while handling error: {}\nStack: {}".format(
e, format_exc()))
else:
response = HTTPResponse(
"An error occurred while handling an error")
finally:
# -------------------------------------------- #
# Response Middleware
# -------------------------------------------- #
try:
response = await self._run_response_middleware(request,
response)
except:
log.exception(
'Exception occured in one of response middleware handlers'
)
# pass the response to the correct callback
if isinstance(response, StreamingHTTPResponse):
await stream_callback(response)
else:
write_callback(response)
# -------------------------------------------------------------------- #
# Testing
# -------------------------------------------------------------------- #
@property
def test_client(self):
return SanicTestClient(self)
# -------------------------------------------------------------------- #
# Execution
# -------------------------------------------------------------------- #
def run(self, host=None, port=None, debug=False, ssl=None,
sock=None, workers=1, protocol=None,
backlog=100, stop_event=None, register_sys_signals=True,
log_config=None):
"""Run the HTTP Server and listen until keyboard interrupt or term
signal. On termination, drain connections before closing.
:param host: Address to host on
:param port: Port to host on
:param debug: Enables debug output (slows server)
:param ssl: SSLContext, or location of certificate and key
for SSL encryption of worker(s)
:param sock: Socket for the server to accept connections from
:param workers: Number of processes
received before it is respected
:param backlog:
:param stop_event:
:param register_sys_signals:
:param protocol: Subclass of asyncio protocol class
:return: Nothing
"""
if sock is None:
host, port = host or "127.0.0.1", port or 8000
if log_config:
self.log_config = log_config
logging.config.dictConfig(log_config)
if protocol is None:
protocol = (WebSocketProtocol if self.websocket_enabled
else HttpProtocol)
if stop_event is not None:
if debug:
warnings.simplefilter('default')
warnings.warn("stop_event will be removed from future versions.",
DeprecationWarning)
server_settings = self._helper(
host=host, port=port, debug=debug, ssl=ssl, sock=sock,
workers=workers, protocol=protocol, backlog=backlog,
register_sys_signals=register_sys_signals,
has_log=self.log_config is not None)
try:
self.is_running = True
if workers == 1:
serve(**server_settings)
else:
serve_multiple(server_settings, workers)
except:
log.exception(
'Experienced exception while trying to serve')
raise
finally:
self.is_running = False
log.info("Server Stopped")
def stop(self):
"""This kills the Sanic"""
get_event_loop().stop()
def __call__(self):
"""gunicorn compatibility"""
return self
async def create_server(self, host=None, port=None, debug=False,
ssl=None, sock=None, protocol=None,
backlog=100, stop_event=None,
log_config=LOGGING):
"""Asynchronous version of `run`.
NOTE: This does not support multiprocessing and is not the preferred
way to run a Sanic application.
"""
if sock is None:
host, port = host or "127.0.0.1", port or 8000
if log_config:
logging.config.dictConfig(log_config)
if protocol is None:
protocol = (WebSocketProtocol if self.websocket_enabled
else HttpProtocol)
if stop_event is not None:
if debug:
warnings.simplefilter('default')
warnings.warn("stop_event will be removed from future versions.",
DeprecationWarning)
server_settings = self._helper(
host=host, port=port, debug=debug, ssl=ssl, sock=sock,
loop=get_event_loop(), protocol=protocol,
backlog=backlog, run_async=True,
has_log=log_config is not None)
return await serve(**server_settings)
async def _run_request_middleware(self, request):
# The if improves speed. I don't know why
if self.request_middleware:
for middleware in self.request_middleware:
response = middleware(request)
if isawaitable(response):
response = await response
if response:
return response
return None
async def _run_response_middleware(self, request, response):
if self.response_middleware:
for middleware in self.response_middleware:
_response = middleware(request, response)
if isawaitable(_response):
_response = await _response
if _response:
response = _response
break
return response
def _helper(self, host=None, port=None, debug=False,
ssl=None, sock=None, workers=1, loop=None,
protocol=HttpProtocol, backlog=100, stop_event=None,
register_sys_signals=True, run_async=False, has_log=True):
"""Helper function used by `run` and `create_server`."""
if isinstance(ssl, dict):
# try common aliaseses
cert = ssl.get('cert') or ssl.get('certificate')
key = ssl.get('key') or ssl.get('keyfile')
if cert is None or key is None:
raise ValueError("SSLContext or certificate and key required.")
context = create_default_context(purpose=Purpose.CLIENT_AUTH)
context.load_cert_chain(cert, keyfile=key)
ssl = context
if stop_event is not None:
if debug:
warnings.simplefilter('default')
warnings.warn("stop_event will be removed from future versions.",
DeprecationWarning)
self.error_handler.debug = debug
self.debug = debug
server_settings = {
'protocol': protocol,
'request_class': self.request_class,
'is_request_stream': self.is_request_stream,
'router': self.router,
'host': host,
'port': port,
'sock': sock,
'ssl': ssl,
'signal': Signal(),
'debug': debug,
'request_handler': self.handle_request,
'error_handler': self.error_handler,
'request_timeout': self.config.REQUEST_TIMEOUT,
'request_max_size': self.config.REQUEST_MAX_SIZE,
'keep_alive': self.config.KEEP_ALIVE,
'loop': loop,
'register_sys_signals': register_sys_signals,
'backlog': backlog,
'has_log': has_log,
'websocket_max_size': self.config.WEBSOCKET_MAX_SIZE,
'websocket_max_queue': self.config.WEBSOCKET_MAX_QUEUE,
'graceful_shutdown_timeout': self.config.GRACEFUL_SHUTDOWN_TIMEOUT
}
# -------------------------------------------- #
# Register start/stop events
# -------------------------------------------- #
for event_name, settings_name, reverse in (
("before_server_start", "before_start", False),
("after_server_start", "after_start", False),
("before_server_stop", "before_stop", True),
("after_server_stop", "after_stop", True),
):
listeners = self.listeners[event_name].copy()
if reverse:
listeners.reverse()
# Prepend sanic to the arguments when listeners are triggered
listeners = [partial(listener, self) for listener in listeners]
server_settings[settings_name] = listeners
if debug:
log.setLevel(logging.DEBUG)
if self.config.LOGO is not None:
log.debug(self.config.LOGO)
if run_async:
server_settings['run_async'] = True
# Serve
if host and port:
proto = "http"
if ssl is not None:
proto = "https"
log.info('Goin\' Fast @ {}://{}:{}'.format(proto, host, port))
return server_settings
|
mit
|
[
646,
2050,
199,
646,
2050,
14,
888,
199,
646,
295,
199,
646,
3598,
199,
504,
16195,
492,
664,
63,
1430,
63,
3813,
12,
4868,
63,
2443,
12,
28374,
1146,
547,
199,
504,
5055,
492,
15782,
12,
10018,
199,
504,
9143,
492,
7417,
199,
504,
6485,
492,
365,
32365,
461,
12,
3464,
12,
664,
22582,
199,
504,
5190,
492,
1475,
63,
2804,
199,
504,
4011,
14,
1122,
492,
16511,
12,
30111,
199,
504,
6149,
492,
1218,
63,
885,
63,
1100,
12,
23177,
4070,
199,
199,
504,
28698,
530,
14,
888,
492,
4094,
12,
3412,
22790,
199,
504,
28698,
530,
14,
5559,
492,
3101,
63,
18383,
199,
504,
28698,
530,
14,
3924,
492,
7146,
547,
12,
2851,
3425,
547,
12,
29359,
530,
1726,
199,
504,
28698,
530,
14,
5586,
492,
4520,
2461,
199,
504,
28698,
530,
14,
793,
492,
943,
199,
504,
28698,
530,
14,
1310,
492,
29034,
12,
28167,
27068,
199,
504,
28698,
530,
14,
4995,
492,
22708,
199,
504,
28698,
530,
14,
1000,
492,
14062,
12,
14062,
63,
6048,
12,
4760,
3658,
12,
18288,
199,
504,
28698,
530,
14,
1986,
492,
2274,
465,
2955,
63,
2683,
199,
504,
28698,
530,
14,
4776,
492,
29359,
530,
774,
3041,
199,
504,
28698,
530,
14,
4196,
492,
27506,
1588,
2768,
199,
504,
28698,
530,
14,
13508,
492,
18846,
3658,
12,
8113,
15190,
421,
199,
533,
29359,
530,
26,
339,
347,
636,
826,
721,
277,
12,
536,
29,
403,
12,
6197,
29,
403,
12,
1125,
63,
2232,
29,
403,
12,
326,
2248,
63,
1813,
29,
549,
12,
1056,
63,
533,
29,
403,
12,
326,
943,
63,
888,
29,
27896,
304,
267,
340,
943,
63,
888,
26,
288,
2050,
14,
888,
14,
807,
2028,
8,
793,
63,
888,
9,
267,
327,
5972,
663,
1536,
282,
849,
943,
3016,
340,
314,
267,
327,
1284,
13,
751,
4223,
9980,
1133,
663,
7003,
1536,
14,
267,
340,
440,
334,
4806,
14,
1231,
14,
5586,
436,
355,
943,
14,
1896,
508,
2050,
14,
4609,
3597,
436,
355,
943,
63,
888,
304,
288,
9698,
275,
2050,
14,
7772,
8,
355,
11792,
18331,
9,
83,
26,
2818,
20056,
9,
83,
26,
2818,
1188,
9,
83,
531,
288,
3016,
275,
2050,
14,
22482,
342,
288,
3016,
14,
26076,
8,
8911,
9,
288,
943,
14,
18826,
8,
2232,
9,
288,
943,
14,
13548,
8,
4806,
14,
4531,
9,
398,
327,
2372,
536,
687,
4136,
3464,
2787,
267,
340,
536,
365,
488,
26,
288,
2787,
63,
6502,
275,
3464,
3430,
17,
61,
288,
536,
275,
664,
22582,
8,
1943,
63,
6502,
59,
17,
566,
398,
291,
14,
354,
275,
536,
267,
291,
14,
4995,
275,
6197,
503,
22708,
342,
267,
291,
14,
1069,
63,
533,
275,
1056,
63,
533,
267,
291,
14,
705,
63,
2232,
275,
1125,
63,
2232,
503,
4520,
2461,
342,
267,
291,
14,
888,
275,
4094,
8,
912,
63,
1813,
29,
912,
63,
1813,
9,
267,
291,
14,
793,
63,
888,
275,
943,
63,
888,
267,
291,
14,
1069,
63,
5754,
275,
15782,
342,
267,
291,
14,
1310,
63,
5754,
275,
15782,
342,
267,
291,
14,
15918,
83,
275,
1052,
267,
291,
423,
15918,
63,
1648,
275,
942,
267,
291,
14,
1757,
275,
488,
267,
291,
14,
5096,
275,
488,
267,
291,
14,
17301,
275,
10018,
8,
513,
9,
267,
291,
14,
374,
63,
5720,
275,
756,
267,
291,
14,
374,
63,
1069,
63,
1745,
275,
756,
267,
291,
14,
13508,
63,
3827,
275,
756,
267,
291,
14,
13508,
63,
5054,
275,
942,
398,
327,
11828,
13943,
1083,
1561,
267,
291,
14,
1939,
63,
7015,
275,
291,
14,
1065,
339,
768,
1829,
272,
347,
4438,
8,
277,
304,
267,
408,
17746,
7607,
543,
16195,
14,
362,
63,
1430,
63,
3813,
1252,
398,
5972,
3748,
1380,
1808,
314,
658,
571,
14,
1065,
64,
1083,
14,
267,
408,
267,
340,
440,
291,
14,
374,
63,
5720,
26,
288,
746,
29359,
530,
1726,
8,
355,
283,
7382,
883,
1454,
506,
12396,
2410,
314,
1145,
965,
8239,
283,
355,
283,
5720,
14,
2832,
3748,
543,
658,
981,
63,
1000,
64,
805,
358,
267,
372,
664,
63,
1430,
63,
3813,
342,
339,
327,
23567,
327,
272,
327,
20764,
272,
327,
23567,
327,
339,
347,
1050,
63,
1765,
8,
277,
12,
2120,
304,
267,
408,
15535,
282,
2120,
370,
1255,
2945,
12,
2410,
314,
4438,
965,
8239,
14,
267,
18029,
640,
687,
16195,
14,
7505,
63,
2443,
315,
626,
652,
1630,
440,
267,
2597,
372,
282,
6466,
12,
436,
314,
3503,
4868,
63,
2443,
1240,
267,
365,
24725,
5133,
2544,
1654,
1343,
14,
398,
520,
635,
2120,
26,
6466,
12,
512,
9129,
337,
1132,
503,
5517,
461,
267,
408,
267,
768,
277,
14,
9799,
360,
5182,
63,
1000,
63,
928,
358,
267,
347,
1255,
8,
571,
12,
4438,
304,
288,
340,
4550,
8,
1765,
304,
355,
4438,
14,
981,
63,
1765,
8,
1765,
1012,
288,
587,
26,
355,
4438,
14,
981,
63,
1765,
8,
1765,
9,
339,
327,
30684,
272,
347,
11647,
8,
277,
12,
1566,
304,
267,
408,
2499,
282,
11647,
687,
282,
16225,
805,
14,
398,
520,
635,
1566,
26,
1566,
370,
6938,
370,
267,
408,
267,
347,
7531,
8,
9799,
304,
288,
291,
14,
17301,
59,
1430,
1055,
740,
8,
9799,
9,
288,
372,
11647,
267,
372,
7531,
339,
327,
30684,
272,
347,
7475,
8,
277,
12,
5108,
12,
3102,
29,
21362,
3252,
2970,
1604,
1591,
29,
403,
12,
1598,
7478,
63,
24032,
29,
797,
12,
2547,
29,
797,
12,
1015,
29,
403,
304,
267,
408,
8584,
269,
323,
282,
805,
370,
506,
7264,
465,
282,
7475,
398,
520,
635,
5108,
26,
931,
402,
314,
2851,
267,
520,
635,
3102,
26,
769,
503,
2008,
402,
3102,
4370,
267,
520,
635,
1591,
26,
267,
520,
635,
7478,
63,
24032,
26,
267,
520,
635,
2547,
26,
267,
520,
1107,
26,
16225,
805,
267,
408,
398,
327,
14811,
1930,
2382,
314,
922,
8103,
440,
2403,
314,
2851,
543,
282,
1182,
267,
327,
436,
911,
8646,
664,
3743,
2972,
465,
370,
10842,
652,
1159,
440,
6449,
267,
340,
440,
5108,
14,
2460,
18265,
288,
5108,
275,
7324,
435,
5108,
398,
340,
2547,
26,
288,
291,
14,
374,
63,
1069,
63,
1745,
275,
715,
398,
347,
1177,
8,
2232,
304,
288,
340,
2547
] |
[
2050,
199,
646,
2050,
14,
888,
199,
646,
295,
199,
646,
3598,
199,
504,
16195,
492,
664,
63,
1430,
63,
3813,
12,
4868,
63,
2443,
12,
28374,
1146,
547,
199,
504,
5055,
492,
15782,
12,
10018,
199,
504,
9143,
492,
7417,
199,
504,
6485,
492,
365,
32365,
461,
12,
3464,
12,
664,
22582,
199,
504,
5190,
492,
1475,
63,
2804,
199,
504,
4011,
14,
1122,
492,
16511,
12,
30111,
199,
504,
6149,
492,
1218,
63,
885,
63,
1100,
12,
23177,
4070,
199,
199,
504,
28698,
530,
14,
888,
492,
4094,
12,
3412,
22790,
199,
504,
28698,
530,
14,
5559,
492,
3101,
63,
18383,
199,
504,
28698,
530,
14,
3924,
492,
7146,
547,
12,
2851,
3425,
547,
12,
29359,
530,
1726,
199,
504,
28698,
530,
14,
5586,
492,
4520,
2461,
199,
504,
28698,
530,
14,
793,
492,
943,
199,
504,
28698,
530,
14,
1310,
492,
29034,
12,
28167,
27068,
199,
504,
28698,
530,
14,
4995,
492,
22708,
199,
504,
28698,
530,
14,
1000,
492,
14062,
12,
14062,
63,
6048,
12,
4760,
3658,
12,
18288,
199,
504,
28698,
530,
14,
1986,
492,
2274,
465,
2955,
63,
2683,
199,
504,
28698,
530,
14,
4776,
492,
29359,
530,
774,
3041,
199,
504,
28698,
530,
14,
4196,
492,
27506,
1588,
2768,
199,
504,
28698,
530,
14,
13508,
492,
18846,
3658,
12,
8113,
15190,
421,
199,
533,
29359,
530,
26,
339,
347,
636,
826,
721,
277,
12,
536,
29,
403,
12,
6197,
29,
403,
12,
1125,
63,
2232,
29,
403,
12,
326,
2248,
63,
1813,
29,
549,
12,
1056,
63,
533,
29,
403,
12,
326,
943,
63,
888,
29,
27896,
304,
267,
340,
943,
63,
888,
26,
288,
2050,
14,
888,
14,
807,
2028,
8,
793,
63,
888,
9,
267,
327,
5972,
663,
1536,
282,
849,
943,
3016,
340,
314,
267,
327,
1284,
13,
751,
4223,
9980,
1133,
663,
7003,
1536,
14,
267,
340,
440,
334,
4806,
14,
1231,
14,
5586,
436,
355,
943,
14,
1896,
508,
2050,
14,
4609,
3597,
436,
355,
943,
63,
888,
304,
288,
9698,
275,
2050,
14,
7772,
8,
355,
11792,
18331,
9,
83,
26,
2818,
20056,
9,
83,
26,
2818,
1188,
9,
83,
531,
288,
3016,
275,
2050,
14,
22482,
342,
288,
3016,
14,
26076,
8,
8911,
9,
288,
943,
14,
18826,
8,
2232,
9,
288,
943,
14,
13548,
8,
4806,
14,
4531,
9,
398,
327,
2372,
536,
687,
4136,
3464,
2787,
267,
340,
536,
365,
488,
26,
288,
2787,
63,
6502,
275,
3464,
3430,
17,
61,
288,
536,
275,
664,
22582,
8,
1943,
63,
6502,
59,
17,
566,
398,
291,
14,
354,
275,
536,
267,
291,
14,
4995,
275,
6197,
503,
22708,
342,
267,
291,
14,
1069,
63,
533,
275,
1056,
63,
533,
267,
291,
14,
705,
63,
2232,
275,
1125,
63,
2232,
503,
4520,
2461,
342,
267,
291,
14,
888,
275,
4094,
8,
912,
63,
1813,
29,
912,
63,
1813,
9,
267,
291,
14,
793,
63,
888,
275,
943,
63,
888,
267,
291,
14,
1069,
63,
5754,
275,
15782,
342,
267,
291,
14,
1310,
63,
5754,
275,
15782,
342,
267,
291,
14,
15918,
83,
275,
1052,
267,
291,
423,
15918,
63,
1648,
275,
942,
267,
291,
14,
1757,
275,
488,
267,
291,
14,
5096,
275,
488,
267,
291,
14,
17301,
275,
10018,
8,
513,
9,
267,
291,
14,
374,
63,
5720,
275,
756,
267,
291,
14,
374,
63,
1069,
63,
1745,
275,
756,
267,
291,
14,
13508,
63,
3827,
275,
756,
267,
291,
14,
13508,
63,
5054,
275,
942,
398,
327,
11828,
13943,
1083,
1561,
267,
291,
14,
1939,
63,
7015,
275,
291,
14,
1065,
339,
768,
1829,
272,
347,
4438,
8,
277,
304,
267,
408,
17746,
7607,
543,
16195,
14,
362,
63,
1430,
63,
3813,
1252,
398,
5972,
3748,
1380,
1808,
314,
658,
571,
14,
1065,
64,
1083,
14,
267,
408,
267,
340,
440,
291,
14,
374,
63,
5720,
26,
288,
746,
29359,
530,
1726,
8,
355,
283,
7382,
883,
1454,
506,
12396,
2410,
314,
1145,
965,
8239,
283,
355,
283,
5720,
14,
2832,
3748,
543,
658,
981,
63,
1000,
64,
805,
358,
267,
372,
664,
63,
1430,
63,
3813,
342,
339,
327,
23567,
327,
272,
327,
20764,
272,
327,
23567,
327,
339,
347,
1050,
63,
1765,
8,
277,
12,
2120,
304,
267,
408,
15535,
282,
2120,
370,
1255,
2945,
12,
2410,
314,
4438,
965,
8239,
14,
267,
18029,
640,
687,
16195,
14,
7505,
63,
2443,
315,
626,
652,
1630,
440,
267,
2597,
372,
282,
6466,
12,
436,
314,
3503,
4868,
63,
2443,
1240,
267,
365,
24725,
5133,
2544,
1654,
1343,
14,
398,
520,
635,
2120,
26,
6466,
12,
512,
9129,
337,
1132,
503,
5517,
461,
267,
408,
267,
768,
277,
14,
9799,
360,
5182,
63,
1000,
63,
928,
358,
267,
347,
1255,
8,
571,
12,
4438,
304,
288,
340,
4550,
8,
1765,
304,
355,
4438,
14,
981,
63,
1765,
8,
1765,
1012,
288,
587,
26,
355,
4438,
14,
981,
63,
1765,
8,
1765,
9,
339,
327,
30684,
272,
347,
11647,
8,
277,
12,
1566,
304,
267,
408,
2499,
282,
11647,
687,
282,
16225,
805,
14,
398,
520,
635,
1566,
26,
1566,
370,
6938,
370,
267,
408,
267,
347,
7531,
8,
9799,
304,
288,
291,
14,
17301,
59,
1430,
1055,
740,
8,
9799,
9,
288,
372,
11647,
267,
372,
7531,
339,
327,
30684,
272,
347,
7475,
8,
277,
12,
5108,
12,
3102,
29,
21362,
3252,
2970,
1604,
1591,
29,
403,
12,
1598,
7478,
63,
24032,
29,
797,
12,
2547,
29,
797,
12,
1015,
29,
403,
304,
267,
408,
8584,
269,
323,
282,
805,
370,
506,
7264,
465,
282,
7475,
398,
520,
635,
5108,
26,
931,
402,
314,
2851,
267,
520,
635,
3102,
26,
769,
503,
2008,
402,
3102,
4370,
267,
520,
635,
1591,
26,
267,
520,
635,
7478,
63,
24032,
26,
267,
520,
635,
2547,
26,
267,
520,
1107,
26,
16225,
805,
267,
408,
398,
327,
14811,
1930,
2382,
314,
922,
8103,
440,
2403,
314,
2851,
543,
282,
1182,
267,
327,
436,
911,
8646,
664,
3743,
2972,
465,
370,
10842,
652,
1159,
440,
6449,
267,
340,
440,
5108,
14,
2460,
18265,
288,
5108,
275,
7324,
435,
5108,
398,
340,
2547,
26,
288,
291,
14,
374,
63,
1069,
63,
1745,
275,
715,
398,
347,
1177,
8,
2232,
304,
288,
340,
2547,
0
] |
[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] |
knusbaum/incubator-storm
|
dev-tools/release_notes.py
|
20
|
5672
|
#!/usr/bin/env python
# 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.
"""Usage: release_notes.py <version> > RELEASE_NOTES.html
Depends on https://pypi.python.org/pypi/jira/, please use pip to install this module.
Generates release notes for a Storm release by generating an HTML doc containing some introductory information about the
release with links to the Storm docs followed by a list of issues resolved in the release. The script will fail if it finds
any unresolved issues still marked with the target release. You should run this script after either resolving all issues or
moving outstanding issues to a later release.
"""
from jira import JIRA
import itertools, sys
if len(sys.argv) < 2:
print >>sys.stderr, "Usage: release_notes.py <version>"
sys.exit(1)
version = sys.argv[1]
JIRA_BASE_URL = 'https://issues.apache.org/jira'
MAX_RESULTS = 100 # This is constrained for cloud instances so we need to fix this value
def get_issues(jira, query, **kwargs):
"""
Get all issues matching the JQL query from the JIRA instance. This handles expanding paginated results for you. Any additional keyword arguments are forwarded to the JIRA.search_issues call.
"""
results = []
startAt = 0
new_results = None
while new_results == None or len(new_results) == MAX_RESULTS:
new_results = jira.search_issues(query, startAt=startAt, maxResults=MAX_RESULTS, **kwargs)
results += new_results
startAt += len(new_results)
return results
def issue_link(issue):
return "%s/browse/%s" % (JIRA_BASE_URL, issue.key)
if __name__ == "__main__":
apache = JIRA(JIRA_BASE_URL)
issues = get_issues(apache, 'project=STORM and fixVersion=%s' % version)
if not issues:
print >>sys.stderr, "Didn't find any issues for the target fix version"
sys.exit(1)
# Some resolutions, including a lack of resolution, indicate that the bug hasn't actually been addressed and we shouldn't even be able to create a release until they are fixed
UNRESOLVED_RESOLUTIONS = [None,
"Unresolved",
"Duplicate",
"Invalid",
"Not A Problem",
"Not A Bug",
"Won't Fix",
"Incomplete",
"Cannot Reproduce",
"Later",
"Works for Me",
"Workaround",
"Information Provided"
]
unresolved_issues = [issue for issue in issues if issue.fields.resolution in UNRESOLVED_RESOLUTIONS or issue.fields.resolution.name in UNRESOLVED_RESOLUTIONS]
if unresolved_issues:
print >>sys.stderr, "The release is not completed since unresolved issues or improperly resolved issues were found still tagged with this release as the fix version:"
for issue in unresolved_issues:
print >>sys.stderr, "Unresolved issue: %15s %20s %s" % (issue.key, issue.fields.resolution, issue_link(issue))
print >>sys.stderr
print >>sys.stderr, "Note that for some resolutions, you should simply remove the fix version as they have not been truly fixed in this release."
sys.exit(1)
# Get list of (issue type, [issues]) sorted by the issue ID type, with each subset of issues sorted by their key so they
# are in increasing order of bug #. To get a nice ordering of the issue types we customize the key used to sort by issue
# type a bit to ensure features and improvements end up first.
def issue_type_key(issue):
if issue.fields.issuetype.name == 'New Feature':
return -2
if issue.fields.issuetype.name == 'Improvement':
return -1
return issue.fields.issuetype.id
by_group = [(k,sorted(g, key=lambda issue: issue.id)) for k,g in itertools.groupby(sorted(issues, key=issue_type_key), lambda issue: issue.fields.issuetype.name)]
print "<!DOCTYPE html>"
print "<html lang=\"en\">"
print "<head>"
print "<meta charset=\"utf-8\">"
print "<title>Storm %(version)s Release Notes</title>" % { 'version': version }
print "</head>"
print "<body>"
print "<h1>Release Notes for Storm %s</h1>" % version
print """<p>JIRA issues addressed in the %(version)s release of Storm. Documentation for this
release is available at the <a href="http://storm.apache.org/">Apache Storm
project site</a>.</p>""" % { 'version': version }
for itype, issues in by_group:
print "<h2>%s</h2>" % itype
print "<ul>"
for issue in issues:
print '<li>[<a href="%(link)s">%(key)s</a>] - %(summary)s</li>' % {'key': issue.key, 'link': issue_link(issue), 'summary': issue.fields.summary}
print "</ul>"
print "</body>"
print "</html>"
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
7692,
26,
4683,
63,
5983,
14,
647,
665,
1023,
30,
690,
5363,
17177,
63,
4609,
654,
14,
1360,
199,
199,
8598,
3198,
641,
4178,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
28097,
15,
12,
8749,
675,
7305,
370,
3907,
642,
859,
14,
199,
199,
20551,
4683,
12681,
367,
282,
1933,
1025,
4683,
701,
12999,
376,
4163,
1382,
3035,
2005,
13318,
2033,
1076,
2556,
3595,
314,
199,
4683,
543,
6220,
370,
314,
1933,
1025,
9149,
9437,
701,
282,
769,
402,
10876,
12152,
315,
314,
4683,
14,
710,
2884,
911,
2449,
340,
652,
17651,
199,
1263,
625,
13697,
10876,
5139,
11584,
543,
314,
1347,
4683,
14,
2047,
1077,
1255,
642,
2884,
2410,
1902,
30685,
1006,
10876,
503,
199,
12876,
734,
18126,
10876,
370,
282,
2945,
4683,
14,
199,
199,
624,
199,
199,
504,
1335,
20936,
492,
1603,
41,
2847,
199,
646,
7975,
12,
984,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
272,
870,
4331,
1274,
14,
3083,
12,
298,
7692,
26,
4683,
63,
5983,
14,
647,
665,
1023,
4335,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
1023,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
32126,
2847,
63,
5825,
63,
2632,
275,
283,
2859,
921,
10115,
14,
3796,
14,
1308,
15,
28097,
7,
199,
4283,
63,
23545,
275,
2948,
327,
961,
365,
28483,
367,
8002,
4454,
880,
781,
1929,
370,
5325,
642,
574,
199,
199,
318,
664,
63,
10115,
8,
28097,
12,
1827,
12,
1011,
958,
304,
272,
408,
272,
2372,
1006,
10876,
4877,
314,
1603,
2940,
1827,
687,
314,
1603,
41,
2847,
1256,
14,
961,
10022,
6544,
316,
9881,
23831,
2058,
367,
1265,
14,
6184,
4722,
4252,
2368,
787,
24172,
370,
314,
1603,
41,
2847,
14,
1733,
63,
10115,
1240,
14,
272,
408,
272,
2058,
275,
942,
272,
1343,
1271,
275,
378,
272,
892,
63,
2604,
275,
488,
272,
1830,
892,
63,
2604,
508,
488,
503,
822,
8,
1222,
63,
2604,
9,
508,
9141,
63,
23545,
26,
267,
892,
63,
2604,
275,
1335,
20936,
14,
1733,
63,
10115,
8,
1131,
12,
1343,
1271,
29,
928,
1271,
12,
1390,
6579,
29,
4283,
63,
23545,
12,
1011,
958,
9,
267,
2058,
847,
892,
63,
2604,
267,
1343,
1271,
847,
822,
8,
1222,
63,
2604,
9,
272,
372,
2058,
199,
199,
318,
4976,
63,
1073,
8,
5237,
304,
272,
372,
2071,
83,
15,
4570,
3149,
83,
2,
450,
334,
32126,
2847,
63,
5825,
63,
2632,
12,
4976,
14,
498,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
17098,
275,
1603,
41,
2847,
8,
32126,
2847,
63,
5825,
63,
2632,
9,
272,
10876,
275,
664,
63,
10115,
8,
3796,
12,
283,
1715,
29,
840,
8832,
436,
5325,
3353,
2458,
83,
7,
450,
1015,
9,
272,
340,
440,
10876,
26,
267,
870,
4331,
1274,
14,
3083,
12,
298,
17366,
78,
1133,
2342,
1263,
10876,
367,
314,
1347,
5325,
1015,
2,
267,
984,
14,
2224,
8,
17,
9,
339,
327,
6601,
17416,
8653,
12,
5893,
282,
29098,
402,
12401,
12,
6623,
626,
314,
6519,
18699,
1133,
5965,
2757,
1050,
5111,
436,
781,
9296,
1133,
2755,
506,
7688,
370,
1218,
282,
4683,
5133,
2985,
787,
6317,
272,
6778,
3830,
2228,
14112,
63,
3830,
2228,
934,
2823,
275,
359,
403,
12,
2892,
298,
1358,
13697,
401,
2892,
298,
14773,
401,
2892,
298,
3364,
401,
2892,
298,
1763,
437,
20980,
401,
2892,
298,
1763,
437,
21605,
401,
2892,
298,
55,
265,
1133,
14811,
401,
2892,
298,
31962,
401,
2892,
298,
6612,
799,
7832,
401,
2892,
298,
22028,
401,
2892,
298,
25348,
367,
3194,
401,
2892,
298,
6517,
11659,
401,
2892,
298,
4935,
2165,
11923,
2,
2892,
1622,
272,
625,
13697,
63,
10115,
275,
359,
5237,
367,
4976,
315,
10876,
340,
4976,
14,
955,
14,
12588,
315,
6778,
3830,
2228,
14112,
63,
3830,
2228,
934,
2823,
503,
4976,
14,
955,
14,
12588,
14,
354,
315,
6778,
3830,
2228,
14112,
63,
3830,
2228,
934,
2823,
61,
272,
340,
625,
13697,
63,
10115,
26,
267,
870,
4331,
1274,
14,
3083,
12,
298,
1918,
4683,
365,
440,
9709,
3967,
625,
13697,
10876,
503,
1742,
10567,
12152,
10876,
4898,
1911,
5139,
20018,
543,
642,
4683,
465,
314,
5325,
1015,
5424,
267,
367,
4976,
315,
625,
13697,
63,
10115,
26,
288,
870,
4331,
1274,
14,
3083,
12,
298,
1358,
13697,
4976,
26,
450,
1046,
83,
450,
1165,
83,
450,
83,
2,
450,
334,
5237,
14,
498,
12,
4976,
14,
955,
14,
12588,
12,
4976,
63,
1073,
8,
5237,
430,
267,
870,
4331,
1274,
14,
3083,
267,
870,
4331,
1274,
14,
3083,
12,
298,
7443,
626,
367,
2005,
17416,
8653,
12,
1265,
1077,
9329,
2813,
314,
5325,
1015,
465,
2985,
1172,
440,
2757,
5651,
21797,
6317,
315,
642,
4683,
2122,
267,
984,
14,
2224,
8,
17,
9,
339,
327,
2372,
769,
402,
334,
5237,
730,
12,
359,
10115,
566,
3355,
701,
314,
4976,
2870,
730,
12,
543,
1924,
10026,
402,
10876,
3355,
701,
3932,
790,
880,
2985,
272,
327,
787,
315,
22255,
1865,
402,
6519,
327,
14,
4005,
664,
282,
14213,
7794,
402,
314,
4976,
2943,
781,
17551,
314,
790,
1202
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
7692,
26,
4683,
63,
5983,
14,
647,
665,
1023,
30,
690,
5363,
17177,
63,
4609,
654,
14,
1360,
199,
199,
8598,
3198,
641,
4178,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
28097,
15,
12,
8749,
675,
7305,
370,
3907,
642,
859,
14,
199,
199,
20551,
4683,
12681,
367,
282,
1933,
1025,
4683,
701,
12999,
376,
4163,
1382,
3035,
2005,
13318,
2033,
1076,
2556,
3595,
314,
199,
4683,
543,
6220,
370,
314,
1933,
1025,
9149,
9437,
701,
282,
769,
402,
10876,
12152,
315,
314,
4683,
14,
710,
2884,
911,
2449,
340,
652,
17651,
199,
1263,
625,
13697,
10876,
5139,
11584,
543,
314,
1347,
4683,
14,
2047,
1077,
1255,
642,
2884,
2410,
1902,
30685,
1006,
10876,
503,
199,
12876,
734,
18126,
10876,
370,
282,
2945,
4683,
14,
199,
199,
624,
199,
199,
504,
1335,
20936,
492,
1603,
41,
2847,
199,
646,
7975,
12,
984,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
272,
870,
4331,
1274,
14,
3083,
12,
298,
7692,
26,
4683,
63,
5983,
14,
647,
665,
1023,
4335,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
1023,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
32126,
2847,
63,
5825,
63,
2632,
275,
283,
2859,
921,
10115,
14,
3796,
14,
1308,
15,
28097,
7,
199,
4283,
63,
23545,
275,
2948,
327,
961,
365,
28483,
367,
8002,
4454,
880,
781,
1929,
370,
5325,
642,
574,
199,
199,
318,
664,
63,
10115,
8,
28097,
12,
1827,
12,
1011,
958,
304,
272,
408,
272,
2372,
1006,
10876,
4877,
314,
1603,
2940,
1827,
687,
314,
1603,
41,
2847,
1256,
14,
961,
10022,
6544,
316,
9881,
23831,
2058,
367,
1265,
14,
6184,
4722,
4252,
2368,
787,
24172,
370,
314,
1603,
41,
2847,
14,
1733,
63,
10115,
1240,
14,
272,
408,
272,
2058,
275,
942,
272,
1343,
1271,
275,
378,
272,
892,
63,
2604,
275,
488,
272,
1830,
892,
63,
2604,
508,
488,
503,
822,
8,
1222,
63,
2604,
9,
508,
9141,
63,
23545,
26,
267,
892,
63,
2604,
275,
1335,
20936,
14,
1733,
63,
10115,
8,
1131,
12,
1343,
1271,
29,
928,
1271,
12,
1390,
6579,
29,
4283,
63,
23545,
12,
1011,
958,
9,
267,
2058,
847,
892,
63,
2604,
267,
1343,
1271,
847,
822,
8,
1222,
63,
2604,
9,
272,
372,
2058,
199,
199,
318,
4976,
63,
1073,
8,
5237,
304,
272,
372,
2071,
83,
15,
4570,
3149,
83,
2,
450,
334,
32126,
2847,
63,
5825,
63,
2632,
12,
4976,
14,
498,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
17098,
275,
1603,
41,
2847,
8,
32126,
2847,
63,
5825,
63,
2632,
9,
272,
10876,
275,
664,
63,
10115,
8,
3796,
12,
283,
1715,
29,
840,
8832,
436,
5325,
3353,
2458,
83,
7,
450,
1015,
9,
272,
340,
440,
10876,
26,
267,
870,
4331,
1274,
14,
3083,
12,
298,
17366,
78,
1133,
2342,
1263,
10876,
367,
314,
1347,
5325,
1015,
2,
267,
984,
14,
2224,
8,
17,
9,
339,
327,
6601,
17416,
8653,
12,
5893,
282,
29098,
402,
12401,
12,
6623,
626,
314,
6519,
18699,
1133,
5965,
2757,
1050,
5111,
436,
781,
9296,
1133,
2755,
506,
7688,
370,
1218,
282,
4683,
5133,
2985,
787,
6317,
272,
6778,
3830,
2228,
14112,
63,
3830,
2228,
934,
2823,
275,
359,
403,
12,
2892,
298,
1358,
13697,
401,
2892,
298,
14773,
401,
2892,
298,
3364,
401,
2892,
298,
1763,
437,
20980,
401,
2892,
298,
1763,
437,
21605,
401,
2892,
298,
55,
265,
1133,
14811,
401,
2892,
298,
31962,
401,
2892,
298,
6612,
799,
7832,
401,
2892,
298,
22028,
401,
2892,
298,
25348,
367,
3194,
401,
2892,
298,
6517,
11659,
401,
2892,
298,
4935,
2165,
11923,
2,
2892,
1622,
272,
625,
13697,
63,
10115,
275,
359,
5237,
367,
4976,
315,
10876,
340,
4976,
14,
955,
14,
12588,
315,
6778,
3830,
2228,
14112,
63,
3830,
2228,
934,
2823,
503,
4976,
14,
955,
14,
12588,
14,
354,
315,
6778,
3830,
2228,
14112,
63,
3830,
2228,
934,
2823,
61,
272,
340,
625,
13697,
63,
10115,
26,
267,
870,
4331,
1274,
14,
3083,
12,
298,
1918,
4683,
365,
440,
9709,
3967,
625,
13697,
10876,
503,
1742,
10567,
12152,
10876,
4898,
1911,
5139,
20018,
543,
642,
4683,
465,
314,
5325,
1015,
5424,
267,
367,
4976,
315,
625,
13697,
63,
10115,
26,
288,
870,
4331,
1274,
14,
3083,
12,
298,
1358,
13697,
4976,
26,
450,
1046,
83,
450,
1165,
83,
450,
83,
2,
450,
334,
5237,
14,
498,
12,
4976,
14,
955,
14,
12588,
12,
4976,
63,
1073,
8,
5237,
430,
267,
870,
4331,
1274,
14,
3083,
267,
870,
4331,
1274,
14,
3083,
12,
298,
7443,
626,
367,
2005,
17416,
8653,
12,
1265,
1077,
9329,
2813,
314,
5325,
1015,
465,
2985,
1172,
440,
2757,
5651,
21797,
6317,
315,
642,
4683,
2122,
267,
984,
14,
2224,
8,
17,
9,
339,
327,
2372,
769,
402,
334,
5237,
730,
12,
359,
10115,
566,
3355,
701,
314,
4976,
2870,
730,
12,
543,
1924,
10026,
402,
10876,
3355,
701,
3932,
790,
880,
2985,
272,
327,
787,
315,
22255,
1865,
402,
6519,
327,
14,
4005,
664,
282,
14213,
7794,
402,
314,
4976,
2943,
781,
17551,
314,
790,
1202,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jerbob92/CouchPotatoServer
|
couchpotato/core/notifications/email/main.py
|
2
|
1975
|
from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.helpers.variable import splitString
from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification
from couchpotato.environment import Env
from email.mime.text import MIMEText
import smtplib
import traceback
log = CPLog(__name__)
class Email(Notification):
def notify(self, message = '', data = None, listener = None):
if not data: data = {}
# Extract all the settings from settings
from_address = self.conf('from')
to_address = self.conf('to')
ssl = self.conf('ssl')
smtp_server = self.conf('smtp_server')
smtp_user = self.conf('smtp_user')
smtp_pass = self.conf('smtp_pass')
# Make the basic message
message = MIMEText(toUnicode(message), _charset = Env.get('encoding'))
message['Subject'] = self.default_title
message['From'] = from_address
message['To'] = to_address
try:
# Open the SMTP connection, via SSL if requested
log.debug("SMTP over SSL %s", ("enabled" if ssl == 1 else "disabled"))
mailserver = smtplib.SMTP_SSL(smtp_server) if ssl == 1 else smtplib.SMTP(smtp_server)
# Check too see if an login attempt should be attempted
if len(smtp_user) > 0:
log.debug("Logging on to SMTP server using username \'%s\'%s", (smtp_user, " and a password" if len(smtp_pass) > 0 else ""))
mailserver.login(smtp_user, smtp_pass)
# Send the e-mail
log.debug("Sending the email")
mailserver.sendmail(from_address, splitString(to_address), message.as_string())
# Close the SMTP connection
mailserver.quit()
log.info('Email notification sent')
return True
except:
log.error('E-mail failed: %s', traceback.format_exc())
return False
|
gpl-3.0
|
[
504,
28877,
30780,
14,
1018,
14,
7546,
14,
2991,
492,
370,
7087,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
1975,
492,
3715,
1558,
199,
504,
28877,
30780,
14,
1018,
14,
2921,
492,
19701,
2445,
199,
504,
28877,
30780,
14,
1018,
14,
12782,
14,
1095,
492,
23362,
199,
504,
28877,
30780,
14,
5418,
492,
31543,
199,
504,
3031,
14,
7626,
14,
505,
492,
603,
26567,
199,
646,
30475,
199,
646,
5190,
199,
199,
793,
275,
19701,
2445,
3460,
354,
3368,
421,
199,
533,
11426,
8,
11598,
304,
339,
347,
11705,
8,
277,
12,
1245,
275,
3260,
666,
275,
488,
12,
11647,
275,
488,
304,
267,
340,
440,
666,
26,
666,
275,
1052,
398,
327,
12892,
1006,
314,
2202,
687,
2202,
267,
687,
63,
1562,
275,
291,
14,
2190,
360,
504,
358,
267,
370,
63,
1562,
275,
291,
14,
2190,
360,
475,
358,
267,
6149,
275,
291,
14,
2190,
360,
4266,
358,
267,
14400,
63,
1000,
275,
291,
14,
2190,
360,
15592,
63,
1000,
358,
267,
14400,
63,
751,
275,
291,
14,
2190,
360,
15592,
63,
751,
358,
267,
14400,
63,
1529,
275,
291,
14,
2190,
360,
15592,
63,
1529,
358,
398,
327,
4155,
314,
5678,
1245,
267,
1245,
275,
603,
26567,
8,
475,
7087,
8,
1188,
395,
485,
6043,
275,
31543,
14,
362,
360,
2991,
1333,
267,
1245,
459,
13528,
418,
275,
291,
14,
885,
63,
1213,
267,
1245,
459,
2532,
418,
275,
687,
63,
1562,
267,
1245,
459,
1378,
418,
275,
370,
63,
1562,
398,
862,
26,
288,
327,
3232,
314,
19810,
1950,
12,
4799,
7799,
340,
5839,
288,
943,
14,
1757,
480,
20927,
1806,
7799,
450,
83,
401,
1689,
3827,
2,
340,
6149,
508,
413,
587,
298,
7011,
2237,
288,
6016,
1000,
275,
30475,
14,
20927,
63,
5413,
8,
15592,
63,
1000,
9,
340,
6149,
508,
413,
587,
30475,
14,
20927,
8,
15592,
63,
1000,
9,
953,
327,
2670,
4634,
1937,
340,
376,
4676,
7427,
1077,
506,
22040,
288,
340,
822,
8,
15592,
63,
751,
9,
690,
378,
26,
355,
943,
14,
1757,
480,
14054,
641,
370,
19810,
1654,
1808,
3434,
19095,
83,
3985,
5,
83,
401,
334,
15592,
63,
751,
12,
298,
436,
282,
2505,
2,
340,
822,
8,
15592,
63,
1529,
9,
690,
378,
587,
25491,
355,
6016,
1000,
14,
2886,
8,
15592,
63,
751,
12,
14400,
63,
1529,
9,
953,
327,
10217,
314,
325,
13,
1198,
288,
943,
14,
1757,
480,
27219,
314,
3031,
531,
288,
6016,
1000,
14,
2254,
1198,
8,
504,
63,
1562,
12,
3715,
1558,
8,
475,
63,
1562,
395,
1245,
14,
305,
63,
875,
1012,
953,
327,
15524,
314,
19810,
1950,
288,
6016,
1000,
14,
10589,
342,
953,
943,
14,
815,
360,
7035,
6955,
4847,
358,
953,
372,
715,
267,
871,
26,
288,
943,
14,
705,
360,
37,
13,
1198,
3405,
26,
450,
83,
297,
5190,
14,
908,
63,
2804,
1012,
398,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
28877,
30780,
14,
1018,
14,
7546,
14,
2991,
492,
370,
7087,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
1975,
492,
3715,
1558,
199,
504,
28877,
30780,
14,
1018,
14,
2921,
492,
19701,
2445,
199,
504,
28877,
30780,
14,
1018,
14,
12782,
14,
1095,
492,
23362,
199,
504,
28877,
30780,
14,
5418,
492,
31543,
199,
504,
3031,
14,
7626,
14,
505,
492,
603,
26567,
199,
646,
30475,
199,
646,
5190,
199,
199,
793,
275,
19701,
2445,
3460,
354,
3368,
421,
199,
533,
11426,
8,
11598,
304,
339,
347,
11705,
8,
277,
12,
1245,
275,
3260,
666,
275,
488,
12,
11647,
275,
488,
304,
267,
340,
440,
666,
26,
666,
275,
1052,
398,
327,
12892,
1006,
314,
2202,
687,
2202,
267,
687,
63,
1562,
275,
291,
14,
2190,
360,
504,
358,
267,
370,
63,
1562,
275,
291,
14,
2190,
360,
475,
358,
267,
6149,
275,
291,
14,
2190,
360,
4266,
358,
267,
14400,
63,
1000,
275,
291,
14,
2190,
360,
15592,
63,
1000,
358,
267,
14400,
63,
751,
275,
291,
14,
2190,
360,
15592,
63,
751,
358,
267,
14400,
63,
1529,
275,
291,
14,
2190,
360,
15592,
63,
1529,
358,
398,
327,
4155,
314,
5678,
1245,
267,
1245,
275,
603,
26567,
8,
475,
7087,
8,
1188,
395,
485,
6043,
275,
31543,
14,
362,
360,
2991,
1333,
267,
1245,
459,
13528,
418,
275,
291,
14,
885,
63,
1213,
267,
1245,
459,
2532,
418,
275,
687,
63,
1562,
267,
1245,
459,
1378,
418,
275,
370,
63,
1562,
398,
862,
26,
288,
327,
3232,
314,
19810,
1950,
12,
4799,
7799,
340,
5839,
288,
943,
14,
1757,
480,
20927,
1806,
7799,
450,
83,
401,
1689,
3827,
2,
340,
6149,
508,
413,
587,
298,
7011,
2237,
288,
6016,
1000,
275,
30475,
14,
20927,
63,
5413,
8,
15592,
63,
1000,
9,
340,
6149,
508,
413,
587,
30475,
14,
20927,
8,
15592,
63,
1000,
9,
953,
327,
2670,
4634,
1937,
340,
376,
4676,
7427,
1077,
506,
22040,
288,
340,
822,
8,
15592,
63,
751,
9,
690,
378,
26,
355,
943,
14,
1757,
480,
14054,
641,
370,
19810,
1654,
1808,
3434,
19095,
83,
3985,
5,
83,
401,
334,
15592,
63,
751,
12,
298,
436,
282,
2505,
2,
340,
822,
8,
15592,
63,
1529,
9,
690,
378,
587,
25491,
355,
6016,
1000,
14,
2886,
8,
15592,
63,
751,
12,
14400,
63,
1529,
9,
953,
327,
10217,
314,
325,
13,
1198,
288,
943,
14,
1757,
480,
27219,
314,
3031,
531,
288,
6016,
1000,
14,
2254,
1198,
8,
504,
63,
1562,
12,
3715,
1558,
8,
475,
63,
1562,
395,
1245,
14,
305,
63,
875,
1012,
953,
327,
15524,
314,
19810,
1950,
288,
6016,
1000,
14,
10589,
342,
953,
943,
14,
815,
360,
7035,
6955,
4847,
358,
953,
372,
715,
267,
871,
26,
288,
943,
14,
705,
360,
37,
13,
1198,
3405,
26,
450,
83,
297,
5190,
14,
908,
63,
2804,
1012,
398,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
petewarden/tensorflow
|
tensorflow/python/distribute/values_util.py
|
11
|
14810
|
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Utility functions used by values.py and ps_values.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.distribute import distribute_lib
from tensorflow.python.distribute import distribution_strategy_context as ds_context
from tensorflow.python.distribute import reduce_util
from tensorflow.python.eager import context
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_util
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import variable_scope as vs
from tensorflow.python.saved_model import save_context
from tensorflow.python.saved_model import save_options
from tensorflow.python.training.saving import saveable_object
def write_object_proto(var, proto, options):
"""Update a SavedObject proto for the caller.
If a DistributedVariable object supports this method, it will be called when
saving with a pre-built `SavedObject` proto representing the object, plus an
instance of `SaveOptions`. This method is then free to modify that proto
instance.
`DistributedVariable` with `AUTO` or `ON_WRITE` synchronization optionally
write out information about their components to the
`experimental_distributed_variable_components` field of a
`SavedVariable` (depending on the `SaveOptions` variable policy).
Args:
var: The DistributedVariable object.
proto: A pre-built `SavedObject` proto for this object. It is assumed this
will be a `SavedVariable` instance.
options: A `SaveOptions` instance.
"""
if options.experimental_variable_policy._expand_distributed_variables( # pylint: disable=protected-access
):
for var in var.values:
var_proto = (
proto.variable.experimental_distributed_variable_components.add())
var_proto.name = var.name.split(":")[0]
var_proto.device = var.device
def get_on_write_saveable(var, primary_var, name):
"""Return saveable spec for AUTO and ON_WRITE variables."""
# We use a callable so that we don't have to evaluate this expression
# in the case where we are trying to restore instead of save.
def tensor():
if context.executing_eagerly() and not primary_var.is_initialized():
# A SaveSpec tensor value of `None` indicates that the variable is
# uninitialized.
return None
strategy = var.distribute_strategy
return strategy.extended.read_var(var)
spec = saveable_object.SaveSpec(
tensor=tensor,
slice_spec="",
name=name,
dtype=var.dtype,
device=primary_var.device)
return tensor, [spec]
def get_on_write_restore_ops(var, tensor):
"""Return restore ops for AUTO and ON_WRITE variables."""
packed_var = var._packed_variable # pylint: disable=protected-access
if packed_var is not None:
return control_flow_ops.group(
tuple(
assign_on_device(d, packed_var, tensor)
for d in packed_var.devices))
return control_flow_ops.group(
tuple(
assign_on_device(v.device, v, tensor)
for v in var.values))
def get_on_read_saveable(var, primary_var, name):
"""Return saveables for ON_READ variable."""
# We use a callable so that we don't have to evaluate this expression
# in the case where we are trying to restore instead of save.
def tensor():
return var._get_cross_replica() # pylint: disable=protected-access
spec = saveable_object.SaveSpec(
tensor=tensor,
slice_spec="",
name=name,
dtype=var.dtype,
device=primary_var.device)
return tensor, [spec]
def get_on_read_restore_ops(var, tensor, aggregation):
"""Return restore ops for ON_READ variables."""
# To preserve the sum across save and restore, we have to divide the
# total across all devices when restoring a variable that was summed
# when saving.
if aggregation == vs.VariableAggregation.SUM:
strategy = var.distribute_strategy
tensor = math_ops.cast(tensor / strategy.num_replicas_in_sync,
var.dtype)
return control_flow_ops.group(
tuple(
assign_on_device(v.device, v, tensor)
for v in var.values))
# Utility function that indicates if you are in an UpdateContext when running
# in a replica fn.
def in_replica_update_context():
return distribute_lib.get_update_replica_id() is not None
def on_write_assign(var, value, use_locking=False, name=None, read_value=True):
assign_fn = lambda var, *a, **kw: var.assign(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=assign_fn,
value=value,
use_locking=use_locking,
name=name,
read_value=read_value)
def on_write_assign_add(var, value, use_locking=False, name=None,
read_value=True):
assign_add_fn = lambda var, *a, **kw: var.assign_add(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=assign_add_fn,
value=value,
use_locking=use_locking,
name=name,
read_value=read_value)
def on_write_assign_sub(var, value, use_locking=False, name=None,
read_value=True):
assign_sub_fn = lambda var, *a, **kw: var.assign_sub(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=assign_sub_fn,
value=value,
use_locking=use_locking,
name=name,
read_value=read_value)
def assign_on_each_device(var, assign_func, value, read_value):
"""Update the variable on each replica with the given assign_func and value."""
if var._packed_variable is not None: # pylint: disable=protected-access
update = control_flow_ops.group(
tuple(
assign_func(d, var._packed_variable, value) for d in var._devices)) # pylint: disable=protected-access
else:
update = control_flow_ops.group(
tuple(assign_func(v.device, v, value) for v in var._values)) # pylint: disable=protected-access
if not read_value:
return update
with ops.control_dependencies([update] if update else []):
return var.read_value()
def on_read_assign_sub_cross_replica(var, value, read_value=True):
with ds_context.enter_or_assert_strategy(var.distribute_strategy):
if ds_context.in_cross_replica_context():
if var.aggregation == vs.VariableAggregation.SUM:
raise ValueError(
"SyncOnReadVariable does not support `assign_sub` in "
"cross-replica context when aggregation is set to "
"`tf.VariableAggregation.SUM`.")
return assign_on_each_device(var, assign_sub_on_device,
value, read_value)
def on_read_assign_add_cross_replica(var, value, read_value=True):
with ds_context.enter_or_assert_strategy(var.distribute_strategy):
if ds_context.in_cross_replica_context():
if var.aggregation == vs.VariableAggregation.SUM:
raise ValueError(
"SyncOnReadVariable does not support `assign_add` in "
"cross-replica context when aggregation is set to "
"`tf.VariableAggregation.SUM`.")
return assign_on_each_device(var, assign_add_on_device,
value, read_value)
def on_read_assign_cross_replica(var, value, read_value=True):
"""Return the value of the variable in cross replica context."""
with ds_context.enter_or_assert_strategy(var.distribute_strategy):
if ds_context.in_cross_replica_context():
# To preserve the sum across save and restore, we have to divide the
# total across all devices when restoring a variable that was summed
# when saving.
tensor = value
if var.aggregation == vs.VariableAggregation.SUM:
strategy = var._distribute_strategy # pylint: disable=protected-access
tensor = math_ops.cast(tensor / strategy.num_replicas_in_sync,
var.dtype)
return assign_on_each_device(var, assign_on_device, tensor,
read_value)
def scatter_sub(var, sparse_delta, use_locking=False, name=None):
scatter_sub_fn = lambda var, *a, **kw: var.scatter_sub(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=scatter_sub_fn,
value=sparse_delta,
use_locking=use_locking,
name=name)
def scatter_add(var, sparse_delta, use_locking=False, name=None):
scatter_add_fn = lambda var, *a, **kw: var.scatter_add(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=scatter_add_fn,
value=sparse_delta,
use_locking=use_locking,
name=name)
def scatter_mul(var, sparse_delta, use_locking=False, name=None):
scatter_mul_fn = lambda var, *a, **kw: var.scatter_mul(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=scatter_mul_fn,
value=sparse_delta,
use_locking=use_locking,
name=name)
def scatter_div(var, sparse_delta, use_locking=False, name=None):
scatter_div_fn = lambda var, *a, **kw: var.scatter_div(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=scatter_div_fn,
value=sparse_delta,
use_locking=use_locking,
name=name)
def scatter_min(var, sparse_delta, use_locking=False, name=None):
scatter_min_fn = lambda var, *a, **kw: var.scatter_min(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=scatter_min_fn,
value=sparse_delta,
use_locking=use_locking,
name=name)
def scatter_max(var, sparse_delta, use_locking=False, name=None):
scatter_max_fn = lambda var, *a, **kw: var.scatter_max(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=scatter_max_fn,
value=sparse_delta,
use_locking=use_locking,
name=name)
def scatter_update(var, sparse_delta, use_locking=False, name=None):
scatter_update_fn = lambda var, *a, **kw: var.scatter_update(*a, **kw)
return var._update( # pylint: disable=protected-access
update_fn=scatter_update_fn,
value=sparse_delta,
use_locking=use_locking,
name=name)
def get_current_replica_id_as_int():
"""Returns the current replica ID as an integer, or `None`."""
replica_context = ds_context.get_replica_context()
if replica_context:
replica_id = replica_context._replica_id # pylint: disable=protected-access
if not isinstance(replica_id, int):
replica_id = tensor_util.constant_value(replica_id)
else:
replica_id = distribute_lib.get_update_replica_id()
return replica_id
def assign_on_device(device, variable, tensor):
with ops.device(device):
return variable.assign(tensor)
def assign_add_on_device(device, variable, tensor):
with ops.device(device):
return variable.assign_add(tensor)
def assign_sub_on_device(device, variable, tensor):
with ops.device(device):
return variable.assign_sub(tensor)
def assert_replica_context(strategy):
replica_context = ds_context.get_replica_context()
if not replica_context:
raise RuntimeError(
"Replica-local variables may only be assigned in a replica context.")
if replica_context.strategy is not strategy:
raise RuntimeError(
"Replica-local variables may only be assigned in a replica context.")
def apply_aggregation(strategy, value, aggregation, destinations):
if aggregation == vs.VariableAggregation.ONLY_FIRST_REPLICA:
return strategy.extended.broadcast_to(
strategy.experimental_local_results(value)[0],
destinations=destinations)
reduce_op = reduce_util.ReduceOp.from_variable_aggregation(aggregation)
return strategy.extended.reduce_to(reduce_op, value, destinations)
aggregation_error_msg = (
"You must specify an aggregation method to update a "
"{variable_type} in Replica Context. You can do so by passing "
"an explicit value for argument `aggregation` to tf.Variable(..)."
"e.g. `tf.Variable(..., aggregation=tf.VariableAggregation.SUM)`"
"`tf.VariableAggregation` lists the possible aggregation methods."
"This is required because {variable_type} should always be "
"kept in sync. When updating them or assigning to them in a "
"replica context, we automatically try to aggregate the values "
"before updating the variable. For this aggregation, we need to "
"know the aggregation method. "
"Another alternative is to not try to update such "
"{variable_type} in replica context, but in cross replica "
"context. You can enter cross replica context by calling "
"`tf.distribute.get_replica_context().merge_call(merge_fn, ..)`."
"Inside `merge_fn`, you can then update the {variable_type} "
"using `tf.distribute.StrategyExtended.update()`.")
scatter_error_msg = ("{op_name} is only supported for mirrored "
"variable (variable created within certain "
"`tf.distribute.Strategy` scope) with NONE or "
"`ONLY_FIRST_REPLICA` aggregation, got: {aggregation}.")
def is_saving_non_distributed():
"""Returns whether we're saving a non-distributed version of the model.
It returns True iff we are in saving context and are saving a non-distributed
version of the model. That is, SaveOptions.experimental_variable_policy is
NONE.
Returns:
A boolean.
"""
if not save_context.in_save_context():
return False
options = save_context.get_save_options()
return (options.experimental_variable_policy !=
save_options.VariablePolicy.EXPAND_DISTRIBUTED_VARIABLES)
def mark_as_unsaveable():
"""Marks the function as unsaveable if not inside save context."""
if ops.inside_function() and not save_context.in_save_context():
ops.get_default_graph().mark_as_unsaveable("""
ConcreteFunction that uses distributed variables in certain way cannot be saved.
If you're saving with
tf.saved_model.save(..., signatures=f.get_concrete_function())
do
@tf.function(input_signature=...)
def f_with_input_signature():
...
tf.saved_model.save(..., signatures=f_with_input_signature)`
instead.""")
|
apache-2.0
|
[
3,
1898,
25455,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
17505,
3423,
1202,
701,
1338,
14,
647,
436,
7347,
63,
1459,
14,
647,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
3470,
492,
11207,
63,
773,
199,
504,
3228,
14,
1548,
14,
3470,
492,
4084,
63,
8590,
63,
1100,
465,
6364,
63,
1100,
199,
504,
3228,
14,
1548,
14,
3470,
492,
7114,
63,
1974,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
465,
8118,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
3354,
63,
1100,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
3354,
63,
1419,
199,
504,
3228,
14,
1548,
14,
7588,
14,
30172,
492,
3354,
461,
63,
785,
421,
199,
318,
2218,
63,
785,
63,
2625,
8,
1391,
12,
4104,
12,
1511,
304,
523,
408,
4152,
282,
29026,
1692,
4104,
367,
314,
8025,
14,
819,
982,
282,
17484,
2773,
909,
5171,
642,
1083,
12,
652,
911,
506,
2797,
1380,
523,
13369,
543,
282,
876,
13,
11730,
658,
21969,
1692,
64,
4104,
6144,
314,
909,
12,
12254,
376,
523,
1256,
402,
658,
8229,
4558,
2313,
961,
1083,
365,
2066,
2867,
370,
2811,
626,
4104,
523,
1256,
14,
819,
658,
27398,
2773,
64,
543,
658,
13883,
64,
503,
658,
615,
63,
10387,
64,
29509,
14190,
2043,
2218,
734,
2556,
3595,
3932,
7323,
370,
314,
2043,
658,
18924,
63,
16832,
63,
1975,
63,
4608,
64,
901,
402,
282,
2043,
658,
21969,
2773,
64,
334,
2601,
3219,
641,
314,
658,
8229,
4558,
64,
1750,
4592,
680,
819,
3033,
26,
272,
2729,
26,
710,
17484,
2773,
909,
14,
272,
4104,
26,
437,
876,
13,
11730,
658,
21969,
1692,
64,
4104,
367,
642,
909,
14,
2779,
365,
10826,
642,
489,
911,
506,
282,
658,
21969,
2773,
64,
1256,
14,
272,
1511,
26,
437,
658,
8229,
4558,
64,
1256,
14,
523,
408,
523,
340,
1511,
14,
18924,
63,
1975,
63,
3185,
423,
4441,
63,
16832,
63,
3669,
8,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
523,
3461,
272,
367,
2729,
315,
2729,
14,
1459,
26,
489,
2729,
63,
2625,
275,
334,
881,
4104,
14,
1975,
14,
18924,
63,
16832,
63,
1975,
63,
4608,
14,
525,
1012,
489,
2729,
63,
2625,
14,
354,
275,
2729,
14,
354,
14,
1294,
20063,
59,
16,
61,
489,
2729,
63,
2625,
14,
1782,
275,
2729,
14,
1782,
421,
199,
318,
664,
63,
265,
63,
952,
63,
2117,
461,
8,
1391,
12,
5062,
63,
1391,
12,
536,
304,
523,
408,
1767,
3354,
461,
3158,
367,
25420,
436,
5258,
63,
10387,
2860,
1041,
523,
327,
2136,
675,
282,
4550,
880,
626,
781,
2793,
1133,
1172,
370,
9352,
642,
3965,
523,
327,
315,
314,
1930,
2382,
781,
787,
9936,
370,
9066,
3140,
402,
3354,
14,
523,
347,
2345,
837,
272,
340,
1067,
14,
23722,
63,
24377,
342,
436,
440,
5062,
63,
1391,
14,
374,
63,
12486,
837,
489,
327,
437,
11063,
5307,
2345,
574,
402,
658,
403,
64,
9126,
626,
314,
1750,
365,
489,
327,
625,
12486,
14,
489,
372,
488,
272,
10054,
275,
2729,
14,
3470,
63,
8590,
272,
372,
10054,
14,
10525,
14,
739,
63,
1391,
8,
1391,
9,
819,
3158,
275,
3354,
461,
63,
785,
14,
8229,
5307,
8,
489,
2345,
29,
3128,
12,
489,
6014,
63,
1650,
8772,
489,
536,
29,
354,
12,
489,
2152,
29,
1391,
14,
2271,
12,
489,
2243,
29,
3327,
63,
1391,
14,
1782,
9,
819,
372,
2345,
12,
359,
1650,
61,
421,
199,
318,
664,
63,
265,
63,
952,
63,
8011,
63,
1483,
8,
1391,
12,
2345,
304,
523,
408,
1767,
9066,
4156,
367,
25420,
436,
5258,
63,
10387,
2860,
1041,
523,
13170,
63,
1391,
275,
2729,
423,
12286,
63,
1975,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
523,
340,
13170,
63,
1391,
365,
440,
488,
26,
272,
372,
3304,
63,
1659,
63,
1483,
14,
923,
8,
267,
2008,
8,
288,
5090,
63,
265,
63,
1782,
8,
68,
12,
13170,
63,
1391,
12,
2345,
9,
288,
367,
366,
315,
13170,
63,
1391,
14,
6410,
430,
523,
372,
3304,
63,
1659,
63,
1483,
14,
923,
8,
489,
2008,
8,
881,
5090,
63,
265,
63,
1782,
8,
86,
14,
1782,
12,
373,
12,
2345,
9,
881,
367,
373,
315,
2729,
14,
1459,
430,
421,
199,
318,
664,
63,
265,
63,
739,
63,
2117,
461,
8,
1391,
12,
5062,
63,
1391,
12,
536,
304,
523,
408,
1767,
3354,
5921,
367,
5258,
63,
5670,
1750,
1041,
819,
327,
2136,
675,
282,
4550,
880,
626,
781,
2793,
1133,
1172,
370,
9352,
642,
3965,
523,
327,
315,
314,
1930,
2382,
781,
787,
9936,
370,
9066,
3140,
402,
3354,
14,
523,
347,
2345,
837,
272,
372,
2729,
423,
362,
63,
7925,
63,
12317,
342,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
819,
3158,
275,
3354,
461,
63,
785,
14,
8229,
5307,
8,
489,
2345,
29,
3128,
12,
489,
6014,
63,
1650,
8772,
489,
536,
29,
354
] |
[
1898,
25455,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
17505,
3423,
1202,
701,
1338,
14,
647,
436,
7347,
63,
1459,
14,
647,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
3470,
492,
11207,
63,
773,
199,
504,
3228,
14,
1548,
14,
3470,
492,
4084,
63,
8590,
63,
1100,
465,
6364,
63,
1100,
199,
504,
3228,
14,
1548,
14,
3470,
492,
7114,
63,
1974,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
465,
8118,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
3354,
63,
1100,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
3354,
63,
1419,
199,
504,
3228,
14,
1548,
14,
7588,
14,
30172,
492,
3354,
461,
63,
785,
421,
199,
318,
2218,
63,
785,
63,
2625,
8,
1391,
12,
4104,
12,
1511,
304,
523,
408,
4152,
282,
29026,
1692,
4104,
367,
314,
8025,
14,
819,
982,
282,
17484,
2773,
909,
5171,
642,
1083,
12,
652,
911,
506,
2797,
1380,
523,
13369,
543,
282,
876,
13,
11730,
658,
21969,
1692,
64,
4104,
6144,
314,
909,
12,
12254,
376,
523,
1256,
402,
658,
8229,
4558,
2313,
961,
1083,
365,
2066,
2867,
370,
2811,
626,
4104,
523,
1256,
14,
819,
658,
27398,
2773,
64,
543,
658,
13883,
64,
503,
658,
615,
63,
10387,
64,
29509,
14190,
2043,
2218,
734,
2556,
3595,
3932,
7323,
370,
314,
2043,
658,
18924,
63,
16832,
63,
1975,
63,
4608,
64,
901,
402,
282,
2043,
658,
21969,
2773,
64,
334,
2601,
3219,
641,
314,
658,
8229,
4558,
64,
1750,
4592,
680,
819,
3033,
26,
272,
2729,
26,
710,
17484,
2773,
909,
14,
272,
4104,
26,
437,
876,
13,
11730,
658,
21969,
1692,
64,
4104,
367,
642,
909,
14,
2779,
365,
10826,
642,
489,
911,
506,
282,
658,
21969,
2773,
64,
1256,
14,
272,
1511,
26,
437,
658,
8229,
4558,
64,
1256,
14,
523,
408,
523,
340,
1511,
14,
18924,
63,
1975,
63,
3185,
423,
4441,
63,
16832,
63,
3669,
8,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
523,
3461,
272,
367,
2729,
315,
2729,
14,
1459,
26,
489,
2729,
63,
2625,
275,
334,
881,
4104,
14,
1975,
14,
18924,
63,
16832,
63,
1975,
63,
4608,
14,
525,
1012,
489,
2729,
63,
2625,
14,
354,
275,
2729,
14,
354,
14,
1294,
20063,
59,
16,
61,
489,
2729,
63,
2625,
14,
1782,
275,
2729,
14,
1782,
421,
199,
318,
664,
63,
265,
63,
952,
63,
2117,
461,
8,
1391,
12,
5062,
63,
1391,
12,
536,
304,
523,
408,
1767,
3354,
461,
3158,
367,
25420,
436,
5258,
63,
10387,
2860,
1041,
523,
327,
2136,
675,
282,
4550,
880,
626,
781,
2793,
1133,
1172,
370,
9352,
642,
3965,
523,
327,
315,
314,
1930,
2382,
781,
787,
9936,
370,
9066,
3140,
402,
3354,
14,
523,
347,
2345,
837,
272,
340,
1067,
14,
23722,
63,
24377,
342,
436,
440,
5062,
63,
1391,
14,
374,
63,
12486,
837,
489,
327,
437,
11063,
5307,
2345,
574,
402,
658,
403,
64,
9126,
626,
314,
1750,
365,
489,
327,
625,
12486,
14,
489,
372,
488,
272,
10054,
275,
2729,
14,
3470,
63,
8590,
272,
372,
10054,
14,
10525,
14,
739,
63,
1391,
8,
1391,
9,
819,
3158,
275,
3354,
461,
63,
785,
14,
8229,
5307,
8,
489,
2345,
29,
3128,
12,
489,
6014,
63,
1650,
8772,
489,
536,
29,
354,
12,
489,
2152,
29,
1391,
14,
2271,
12,
489,
2243,
29,
3327,
63,
1391,
14,
1782,
9,
819,
372,
2345,
12,
359,
1650,
61,
421,
199,
318,
664,
63,
265,
63,
952,
63,
8011,
63,
1483,
8,
1391,
12,
2345,
304,
523,
408,
1767,
9066,
4156,
367,
25420,
436,
5258,
63,
10387,
2860,
1041,
523,
13170,
63,
1391,
275,
2729,
423,
12286,
63,
1975,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
523,
340,
13170,
63,
1391,
365,
440,
488,
26,
272,
372,
3304,
63,
1659,
63,
1483,
14,
923,
8,
267,
2008,
8,
288,
5090,
63,
265,
63,
1782,
8,
68,
12,
13170,
63,
1391,
12,
2345,
9,
288,
367,
366,
315,
13170,
63,
1391,
14,
6410,
430,
523,
372,
3304,
63,
1659,
63,
1483,
14,
923,
8,
489,
2008,
8,
881,
5090,
63,
265,
63,
1782,
8,
86,
14,
1782,
12,
373,
12,
2345,
9,
881,
367,
373,
315,
2729,
14,
1459,
430,
421,
199,
318,
664,
63,
265,
63,
739,
63,
2117,
461,
8,
1391,
12,
5062,
63,
1391,
12,
536,
304,
523,
408,
1767,
3354,
5921,
367,
5258,
63,
5670,
1750,
1041,
819,
327,
2136,
675,
282,
4550,
880,
626,
781,
2793,
1133,
1172,
370,
9352,
642,
3965,
523,
327,
315,
314,
1930,
2382,
781,
787,
9936,
370,
9066,
3140,
402,
3354,
14,
523,
347,
2345,
837,
272,
372,
2729,
423,
362,
63,
7925,
63,
12317,
342,
221,
327,
4287,
26,
3507,
29,
6798,
13,
2732,
819,
3158,
275,
3354,
461,
63,
785,
14,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
WeAreCloudar/troposphere
|
troposphere/cloudformation.py
|
22
|
5724
|
# Copyright (c) 2013, Mark Peek <mark@peek.org>
# All rights reserved.
#
# See LICENSE file for full license.
from . import AWSHelperFn, AWSObject, AWSProperty, Ref, BaseAWSObject
from .validators import integer, boolean, encoding
class Stack(AWSObject):
resource_type = "AWS::CloudFormation::Stack"
props = {
'NotificationARNs': ([basestring], False),
'Parameters': (dict, False),
'TemplateURL': (basestring, True),
'TimeoutInMinutes': (integer, False),
}
class AWSCustomObject(BaseAWSObject):
dictname = 'Properties'
class CustomResource(AWSCustomObject):
resource_type = "AWS::CloudFormation::CustomResource"
props = {
'ServiceToken': (basestring, True)
}
class WaitCondition(AWSObject):
resource_type = "AWS::CloudFormation::WaitCondition"
props = {
'Count': (integer, False),
'Handle': (Ref, True),
'Timeout': (integer, True),
}
class WaitConditionHandle(AWSObject):
resource_type = "AWS::CloudFormation::WaitConditionHandle"
props = {}
class Metadata(AWSHelperFn):
def __init__(self, *args):
self.data = args
def JSONrepr(self):
t = []
for i in self.data:
t += i.JSONrepr().items()
return dict(t)
class InitFileContext(AWSHelperFn):
def __init__(self, data):
self.data = data
def JSONrepr(self):
return self.data
class InitFile(AWSProperty):
props = {
'content': (basestring, False),
'mode': (basestring, False),
'owner': (basestring, False),
'encoding': (encoding, False),
'group': (basestring, False),
'source': (basestring, False),
'authentication': (basestring, False),
'context': (InitFileContext, False)
}
class InitFiles(AWSHelperFn):
def __init__(self, data):
self.validate(data)
self.data = data
def validate(self, data):
for k in data:
if not isinstance(data[k], InitFile):
raise ValueError("File '" + k + "' must be of type InitFile")
def JSONrepr(self):
return self.data
class InitService(AWSProperty):
props = {
'ensureRunning': (boolean, False),
'enabled': (boolean, False),
'files': (list, False),
'packages': (dict, False),
'sources': (list, False),
'commands': (list, False)
}
class InitServices(AWSHelperFn):
def __init__(self, data):
self.validate(data)
self.data = data
def validate(self, data):
for k in data:
if not isinstance(data[k], InitService):
raise ValueError(
"Service '" + k + "' must be of type InitService"
)
def JSONrepr(self):
return self.data
class InitConfigSets(AWSHelperFn):
def __init__(self, **kwargs):
self.validate(dict(kwargs))
self.data = kwargs
def validate(self, config_sets):
for k, v in config_sets.iteritems():
if not isinstance(v, list):
raise ValueError('configSets values must be of type list')
def JSONrepr(self):
return self.data
class InitConfig(AWSProperty):
props = {
'groups': (dict, False),
'users': (dict, False),
'sources': (dict, False),
'packages': (dict, False),
'files': (dict, False),
'commands': (dict, False),
'services': (dict, False)
}
def validate_authentication_type(auth_type):
valid_types = ['S3', 'basic']
if auth_type not in valid_types:
raise ValueError('Type needs to be one of %r' % valid_types)
return auth_type
class AuthenticationBlock(AWSProperty):
props = {
"accessKeyId": (basestring, False),
"buckets": ([basestring], False),
"password": (basestring, False),
"secretKey": (basestring, False),
"type": (validate_authentication_type, False),
"uris": ([basestring], False),
"username": (basestring, False),
"roleName": (basestring, False)
}
class Authentication(AWSHelperFn):
def __init__(self, data):
self.validate(data)
self.data = {"AWS::CloudFormation::Authentication": data}
def validate(self, data):
for k, v in data.iteritems():
if not isinstance(v, AuthenticationBlock):
raise ValueError(
'authentication block must be of type'
' cloudformation.AuthenticationBlock'
)
def JSONrepr(self):
return self.data
class Init(AWSHelperFn):
def __init__(self, data, **kwargs):
self.validate(data, dict(kwargs))
if isinstance(data, InitConfigSets):
self.data = {
'AWS::CloudFormation::Init': dict({'configSets': data},
**kwargs)
}
else:
self.data = {'AWS::CloudFormation::Init': data}
def validate(self, data, config_sets):
if isinstance(data, InitConfigSets):
for k, v in sorted(config_sets.iteritems()):
if not isinstance(v, InitConfig):
raise ValueError(
'init configs must of type ',
'cloudformation.InitConfigSet'
)
else:
if 'config' not in data:
raise ValueError('config property is required')
if not isinstance(data['config'], InitConfig):
raise ValueError(
'config property must be of type cloudformation.InitConfig'
)
def JSONrepr(self):
return self.data
|
bsd-2-clause
|
[
3,
1898,
334,
67,
9,
6171,
12,
7173,
510,
4374,
665,
1657,
32,
13164,
14,
1308,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
1666,
5113,
570,
367,
2615,
4190,
14,
199,
199,
504,
1275,
492,
437,
55,
3234,
2096,
9656,
12,
10168,
1692,
12,
10168,
3697,
12,
15397,
12,
3523,
13226,
1692,
199,
504,
1275,
11346,
492,
3000,
12,
5046,
12,
2644,
421,
199,
533,
13894,
8,
13226,
1692,
304,
272,
2073,
63,
466,
275,
298,
13226,
447,
9089,
1858,
1615,
447,
4851,
2,
339,
10792,
275,
469,
267,
283,
11598,
689,
2438,
356,
7287,
17628,
467,
756,
395,
267,
283,
5976,
356,
334,
807,
12,
756,
395,
267,
283,
4231,
2632,
356,
334,
17628,
12,
715,
395,
267,
283,
6372,
607,
4649,
3862,
356,
334,
4115,
12,
756,
395,
272,
789,
421,
199,
533,
10168,
7223,
1692,
8,
1563,
13226,
1692,
304,
272,
1211,
354,
275,
283,
8516,
7,
421,
199,
533,
8388,
4031,
8,
13226,
7223,
1692,
304,
272,
2073,
63,
466,
275,
298,
13226,
447,
9089,
1858,
1615,
447,
7223,
4031,
2,
339,
10792,
275,
469,
267,
283,
3167,
3264,
356,
334,
17628,
12,
715,
9,
272,
789,
421,
199,
533,
13144,
9558,
8,
13226,
1692,
304,
272,
2073,
63,
466,
275,
298,
13226,
447,
9089,
1858,
1615,
447,
7536,
9558,
2,
339,
10792,
275,
469,
267,
283,
2353,
356,
334,
4115,
12,
756,
395,
267,
283,
5940,
356,
334,
2891,
12,
715,
395,
267,
283,
6372,
356,
334,
4115,
12,
715,
395,
272,
789,
421,
199,
533,
13144,
9558,
5940,
8,
13226,
1692,
304,
272,
2073,
63,
466,
275,
298,
13226,
447,
9089,
1858,
1615,
447,
7536,
9558,
5940,
2,
339,
10792,
275,
1052,
421,
199,
533,
16160,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
291,
14,
576,
275,
1249,
339,
347,
4840,
2722,
8,
277,
304,
267,
307,
275,
942,
267,
367,
284,
315,
291,
14,
576,
26,
288,
307,
847,
284,
14,
6243,
2722,
1252,
1744,
342,
267,
372,
1211,
8,
84,
9,
421,
199,
533,
21026,
1173,
2998,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
666,
304,
267,
291,
14,
576,
275,
666,
339,
347,
4840,
2722,
8,
277,
304,
267,
372,
291,
14,
576,
421,
199,
533,
21026,
1173,
8,
13226,
3697,
304,
272,
10792,
275,
469,
267,
283,
1317,
356,
334,
17628,
12,
756,
395,
267,
283,
632,
356,
334,
17628,
12,
756,
395,
267,
283,
4597,
356,
334,
17628,
12,
756,
395,
267,
283,
2991,
356,
334,
2991,
12,
756,
395,
267,
283,
923,
356,
334,
17628,
12,
756,
395,
267,
283,
1365,
356,
334,
17628,
12,
756,
395,
267,
283,
11725,
356,
334,
17628,
12,
756,
395,
267,
283,
1100,
356,
334,
9346,
1173,
2998,
12,
756,
9,
272,
789,
421,
199,
533,
21026,
5535,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
666,
304,
267,
291,
14,
3502,
8,
576,
9,
267,
291,
14,
576,
275,
666,
339,
347,
4107,
8,
277,
12,
666,
304,
267,
367,
1022,
315,
666,
26,
288,
340,
440,
1228,
8,
576,
59,
75,
467,
21026,
1173,
304,
355,
746,
1722,
480,
1173,
5522,
435,
1022,
435,
3546,
1471,
506,
402,
730,
21026,
1173,
531,
339,
347,
4840,
2722,
8,
277,
304,
267,
372,
291,
14,
576,
421,
199,
533,
21026,
3167,
8,
13226,
3697,
304,
272,
10792,
275,
469,
267,
283,
7505,
9602,
356,
334,
4871,
12,
756,
395,
267,
283,
3827,
356,
334,
4871,
12,
756,
395,
267,
283,
1725,
356,
334,
513,
12,
756,
395,
267,
283,
5154,
356,
334,
807,
12,
756,
395,
267,
283,
4553,
356,
334,
513,
12,
756,
395,
267,
283,
4405,
356,
334,
513,
12,
756,
9,
272,
789,
421,
199,
533,
21026,
15803,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
666,
304,
267,
291,
14,
3502,
8,
576,
9,
267,
291,
14,
576,
275,
666,
339,
347,
4107,
8,
277,
12,
666,
304,
267,
367,
1022,
315,
666,
26,
288,
340,
440,
1228,
8,
576,
59,
75,
467,
21026,
3167,
304,
355,
746,
1722,
8,
490,
298,
3167,
5522,
435,
1022,
435,
3546,
1471,
506,
402,
730,
21026,
3167,
2,
355,
776,
339,
347,
4840,
2722,
8,
277,
304,
267,
372,
291,
14,
576,
421,
199,
533,
21026,
2028,
9899,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3502,
8,
807,
8,
958,
430,
267,
291,
14,
576,
275,
2074,
339,
347,
4107,
8,
277,
12,
1101,
63,
2193,
304,
267,
367,
1022,
12,
373,
315,
1101,
63,
2193,
14,
4611,
837,
288,
340,
440,
1228,
8,
86,
12,
769,
304,
355,
746,
1722,
360,
888,
9899,
1338,
1471,
506,
402,
730,
769,
358,
339,
347,
4840,
2722,
8,
277,
304,
267,
372,
291,
14,
576,
421,
199,
533,
21026,
2028,
8,
13226,
3697,
304,
272,
10792,
275,
469,
267,
283,
2634,
356,
334,
807,
12,
756,
395,
267,
283,
3707,
356,
334,
807,
12,
756,
395,
267,
283,
4553,
356,
334,
807,
12,
756,
395,
267,
283,
5154,
356,
334,
807,
12,
756,
395,
267,
283,
1725,
356,
334,
807,
12,
756,
395,
267,
283,
4405,
356,
334,
807,
12,
756,
395,
267,
283,
5950,
356,
334,
807,
12,
756,
9,
272,
789,
421,
199,
318,
4107,
63,
11725,
63,
466,
8,
1178,
63,
466,
304,
272,
1686,
63,
1313,
275,
788,
51,
19,
297,
283,
4316,
418,
272,
340,
1790,
63,
466,
440,
315,
1686,
63,
1313,
26,
267,
746,
1722,
360,
804,
4839,
370,
506,
1373,
402,
450,
82,
7,
450,
1686,
63,
1313,
9,
272,
372,
1790,
63,
466,
421,
199,
533,
15995,
3142,
8,
13226,
3697,
304,
272,
10792,
275,
469,
267,
298,
2732,
1197,
1304,
582,
334,
17628,
12,
756,
395,
267,
298,
15065,
582,
7287,
17628,
467,
756,
395,
267,
298,
2060,
582,
334,
17628,
12,
756,
395,
267,
298,
4731,
1197,
582,
334,
17628,
12,
756,
395,
267,
298,
466,
582,
334,
3502,
63,
11725,
63,
466,
12,
756,
395,
267,
298,
17656,
582,
7287,
17628,
467,
756
] |
[
1898,
334,
67,
9,
6171,
12,
7173,
510,
4374,
665,
1657,
32,
13164,
14,
1308,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
1666,
5113,
570,
367,
2615,
4190,
14,
199,
199,
504,
1275,
492,
437,
55,
3234,
2096,
9656,
12,
10168,
1692,
12,
10168,
3697,
12,
15397,
12,
3523,
13226,
1692,
199,
504,
1275,
11346,
492,
3000,
12,
5046,
12,
2644,
421,
199,
533,
13894,
8,
13226,
1692,
304,
272,
2073,
63,
466,
275,
298,
13226,
447,
9089,
1858,
1615,
447,
4851,
2,
339,
10792,
275,
469,
267,
283,
11598,
689,
2438,
356,
7287,
17628,
467,
756,
395,
267,
283,
5976,
356,
334,
807,
12,
756,
395,
267,
283,
4231,
2632,
356,
334,
17628,
12,
715,
395,
267,
283,
6372,
607,
4649,
3862,
356,
334,
4115,
12,
756,
395,
272,
789,
421,
199,
533,
10168,
7223,
1692,
8,
1563,
13226,
1692,
304,
272,
1211,
354,
275,
283,
8516,
7,
421,
199,
533,
8388,
4031,
8,
13226,
7223,
1692,
304,
272,
2073,
63,
466,
275,
298,
13226,
447,
9089,
1858,
1615,
447,
7223,
4031,
2,
339,
10792,
275,
469,
267,
283,
3167,
3264,
356,
334,
17628,
12,
715,
9,
272,
789,
421,
199,
533,
13144,
9558,
8,
13226,
1692,
304,
272,
2073,
63,
466,
275,
298,
13226,
447,
9089,
1858,
1615,
447,
7536,
9558,
2,
339,
10792,
275,
469,
267,
283,
2353,
356,
334,
4115,
12,
756,
395,
267,
283,
5940,
356,
334,
2891,
12,
715,
395,
267,
283,
6372,
356,
334,
4115,
12,
715,
395,
272,
789,
421,
199,
533,
13144,
9558,
5940,
8,
13226,
1692,
304,
272,
2073,
63,
466,
275,
298,
13226,
447,
9089,
1858,
1615,
447,
7536,
9558,
5940,
2,
339,
10792,
275,
1052,
421,
199,
533,
16160,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
291,
14,
576,
275,
1249,
339,
347,
4840,
2722,
8,
277,
304,
267,
307,
275,
942,
267,
367,
284,
315,
291,
14,
576,
26,
288,
307,
847,
284,
14,
6243,
2722,
1252,
1744,
342,
267,
372,
1211,
8,
84,
9,
421,
199,
533,
21026,
1173,
2998,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
666,
304,
267,
291,
14,
576,
275,
666,
339,
347,
4840,
2722,
8,
277,
304,
267,
372,
291,
14,
576,
421,
199,
533,
21026,
1173,
8,
13226,
3697,
304,
272,
10792,
275,
469,
267,
283,
1317,
356,
334,
17628,
12,
756,
395,
267,
283,
632,
356,
334,
17628,
12,
756,
395,
267,
283,
4597,
356,
334,
17628,
12,
756,
395,
267,
283,
2991,
356,
334,
2991,
12,
756,
395,
267,
283,
923,
356,
334,
17628,
12,
756,
395,
267,
283,
1365,
356,
334,
17628,
12,
756,
395,
267,
283,
11725,
356,
334,
17628,
12,
756,
395,
267,
283,
1100,
356,
334,
9346,
1173,
2998,
12,
756,
9,
272,
789,
421,
199,
533,
21026,
5535,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
666,
304,
267,
291,
14,
3502,
8,
576,
9,
267,
291,
14,
576,
275,
666,
339,
347,
4107,
8,
277,
12,
666,
304,
267,
367,
1022,
315,
666,
26,
288,
340,
440,
1228,
8,
576,
59,
75,
467,
21026,
1173,
304,
355,
746,
1722,
480,
1173,
5522,
435,
1022,
435,
3546,
1471,
506,
402,
730,
21026,
1173,
531,
339,
347,
4840,
2722,
8,
277,
304,
267,
372,
291,
14,
576,
421,
199,
533,
21026,
3167,
8,
13226,
3697,
304,
272,
10792,
275,
469,
267,
283,
7505,
9602,
356,
334,
4871,
12,
756,
395,
267,
283,
3827,
356,
334,
4871,
12,
756,
395,
267,
283,
1725,
356,
334,
513,
12,
756,
395,
267,
283,
5154,
356,
334,
807,
12,
756,
395,
267,
283,
4553,
356,
334,
513,
12,
756,
395,
267,
283,
4405,
356,
334,
513,
12,
756,
9,
272,
789,
421,
199,
533,
21026,
15803,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
666,
304,
267,
291,
14,
3502,
8,
576,
9,
267,
291,
14,
576,
275,
666,
339,
347,
4107,
8,
277,
12,
666,
304,
267,
367,
1022,
315,
666,
26,
288,
340,
440,
1228,
8,
576,
59,
75,
467,
21026,
3167,
304,
355,
746,
1722,
8,
490,
298,
3167,
5522,
435,
1022,
435,
3546,
1471,
506,
402,
730,
21026,
3167,
2,
355,
776,
339,
347,
4840,
2722,
8,
277,
304,
267,
372,
291,
14,
576,
421,
199,
533,
21026,
2028,
9899,
8,
15088,
3234,
2096,
9656,
304,
272,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
291,
14,
3502,
8,
807,
8,
958,
430,
267,
291,
14,
576,
275,
2074,
339,
347,
4107,
8,
277,
12,
1101,
63,
2193,
304,
267,
367,
1022,
12,
373,
315,
1101,
63,
2193,
14,
4611,
837,
288,
340,
440,
1228,
8,
86,
12,
769,
304,
355,
746,
1722,
360,
888,
9899,
1338,
1471,
506,
402,
730,
769,
358,
339,
347,
4840,
2722,
8,
277,
304,
267,
372,
291,
14,
576,
421,
199,
533,
21026,
2028,
8,
13226,
3697,
304,
272,
10792,
275,
469,
267,
283,
2634,
356,
334,
807,
12,
756,
395,
267,
283,
3707,
356,
334,
807,
12,
756,
395,
267,
283,
4553,
356,
334,
807,
12,
756,
395,
267,
283,
5154,
356,
334,
807,
12,
756,
395,
267,
283,
1725,
356,
334,
807,
12,
756,
395,
267,
283,
4405,
356,
334,
807,
12,
756,
395,
267,
283,
5950,
356,
334,
807,
12,
756,
9,
272,
789,
421,
199,
318,
4107,
63,
11725,
63,
466,
8,
1178,
63,
466,
304,
272,
1686,
63,
1313,
275,
788,
51,
19,
297,
283,
4316,
418,
272,
340,
1790,
63,
466,
440,
315,
1686,
63,
1313,
26,
267,
746,
1722,
360,
804,
4839,
370,
506,
1373,
402,
450,
82,
7,
450,
1686,
63,
1313,
9,
272,
372,
1790,
63,
466,
421,
199,
533,
15995,
3142,
8,
13226,
3697,
304,
272,
10792,
275,
469,
267,
298,
2732,
1197,
1304,
582,
334,
17628,
12,
756,
395,
267,
298,
15065,
582,
7287,
17628,
467,
756,
395,
267,
298,
2060,
582,
334,
17628,
12,
756,
395,
267,
298,
4731,
1197,
582,
334,
17628,
12,
756,
395,
267,
298,
466,
582,
334,
3502,
63,
11725,
63,
466,
12,
756,
395,
267,
298,
17656,
582,
7287,
17628,
467,
756,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
grdlok/UStar-dl
|
src/youtube_dl/extractor/auengine.py
|
4
|
1708
|
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
compat_urllib_parse,
determine_ext,
ExtractorError,
)
class AUEngineIE(InfoExtractor):
_VALID_URL = r'http://(?:www\.)?auengine\.com/embed\.php\?.*?file=(?P<id>[^&]+).*?'
_TEST = {
'url': 'http://auengine.com/embed.php?file=lfvlytY6&w=650&h=370',
'md5': '48972bdbcf1a3a2f5533e62425b41d4f',
'info_dict': {
'id': 'lfvlytY6',
'ext': 'mp4',
'title': '[Commie]The Legend of the Legendary Heroes - 03 - Replication Eye (Alpha Stigma)[F9410F5A]'
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
title = self._html_search_regex(r'<title>(?P<title>.+?)</title>', webpage, 'title')
title = title.strip()
links = re.findall(r'\s(?:file|url):\s*["\']([^\'"]+)["\']', webpage)
links = map(compat_urllib_parse.unquote, links)
thumbnail = None
video_url = None
for link in links:
if link.endswith('.png'):
thumbnail = link
elif '/videos/' in link:
video_url = link
if not video_url:
raise ExtractorError('Could not find video URL')
ext = '.' + determine_ext(video_url)
if ext == title[-len(ext):]:
title = title[:-len(ext)]
return {
'id': video_id,
'url': video_url,
'title': title,
'thumbnail': thumbnail,
'http_referer': 'http://www.auengine.com/flowplayer/flowplayer.commercial-3.2.14.swf',
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
272,
6705,
63,
832,
12,
272,
19783,
12,
199,
9,
421,
199,
533,
437,
53,
8524,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
1014,
921,
5169,
1544,
20316,
3844,
3908,
4537,
957,
15,
6427,
4537,
8624,
29635,
6697,
493,
29,
2229,
48,
28,
344,
13489,
6,
2807,
680,
10,
14069,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
3844,
3908,
14,
957,
15,
6427,
14,
8624,
31,
493,
29,
276,
86,
590,
84,
57,
22,
6,
87,
29,
25125,
6,
72,
29,
13812,
297,
267,
283,
1064,
21,
356,
283,
29743,
2819,
27178,
2177,
17,
65,
19,
65,
18,
70,
1229,
1153,
69,
28062,
821,
66,
2953,
68,
20,
70,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
276,
86,
590,
84,
57,
22,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
6730,
5150,
1873,
61,
1918,
26357,
402,
314,
26357,
695,
869,
3478,
397,
446,
30569,
446,
16000,
1863,
662,
8048,
334,
16192,
428,
17277,
391,
2788,
38,
2635,
709,
38,
21,
33,
6616,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
267,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
82,
7601,
1213,
30,
2229,
48,
28,
1213,
29587,
15939,
1213,
4206,
9248,
12,
283,
1213,
358,
267,
2538,
275,
2538,
14,
1913,
342,
267,
6220,
275,
295,
14,
6452,
8,
82,
1154,
83,
5169,
493,
92,
633,
17211,
83,
10,
905,
26889,
7059,
3985,
937,
8771,
905,
26889,
297,
9248,
9,
267,
6220,
275,
2341,
8,
5819,
63,
4078,
63,
1122,
14,
12240,
12,
6220,
9,
398,
10062,
275,
488,
267,
3991,
63,
633,
275,
488,
267,
367,
2142,
315,
6220,
26,
288,
340,
2142,
14,
4130,
5175,
4524,
735,
355,
10062,
275,
2142,
288,
916,
1994,
11418,
4805,
315,
2142,
26,
355,
3991,
63,
633,
275,
2142,
267,
340,
440,
3991,
63,
633,
26,
288,
746,
19783,
360,
6531,
440,
2342,
3991,
2851,
358,
267,
1599,
275,
7815,
435,
6705,
63,
832,
8,
3722,
63,
633,
9,
267,
340,
1599,
508,
2538,
1988,
552,
8,
832,
304,
2189,
288,
2538,
275,
2538,
4439,
552,
8,
832,
1874,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
3991,
63,
633,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
1014,
63,
20996,
356,
283,
1014,
921,
1544,
14,
3844,
3908,
14,
957,
15,
1659,
6147,
15,
1659,
6147,
14,
957,
23012,
13,
19,
14,
18,
14,
1079,
14,
20426,
297,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
8434,
63,
4078,
63,
1122,
12,
272,
6705,
63,
832,
12,
272,
19783,
12,
199,
9,
421,
199,
533,
437,
53,
8524,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
1014,
921,
5169,
1544,
20316,
3844,
3908,
4537,
957,
15,
6427,
4537,
8624,
29635,
6697,
493,
29,
2229,
48,
28,
344,
13489,
6,
2807,
680,
10,
14069,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
3844,
3908,
14,
957,
15,
6427,
14,
8624,
31,
493,
29,
276,
86,
590,
84,
57,
22,
6,
87,
29,
25125,
6,
72,
29,
13812,
297,
267,
283,
1064,
21,
356,
283,
29743,
2819,
27178,
2177,
17,
65,
19,
65,
18,
70,
1229,
1153,
69,
28062,
821,
66,
2953,
68,
20,
70,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
276,
86,
590,
84,
57,
22,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
6730,
5150,
1873,
61,
1918,
26357,
402,
314,
26357,
695,
869,
3478,
397,
446,
30569,
446,
16000,
1863,
662,
8048,
334,
16192,
428,
17277,
391,
2788,
38,
2635,
709,
38,
21,
33,
6616,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
267,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
82,
7601,
1213,
30,
2229,
48,
28,
1213,
29587,
15939,
1213,
4206,
9248,
12,
283,
1213,
358,
267,
2538,
275,
2538,
14,
1913,
342,
267,
6220,
275,
295,
14,
6452,
8,
82,
1154,
83,
5169,
493,
92,
633,
17211,
83,
10,
905,
26889,
7059,
3985,
937,
8771,
905,
26889,
297,
9248,
9,
267,
6220,
275,
2341,
8,
5819,
63,
4078,
63,
1122,
14,
12240,
12,
6220,
9,
398,
10062,
275,
488,
267,
3991,
63,
633,
275,
488,
267,
367,
2142,
315,
6220,
26,
288,
340,
2142,
14,
4130,
5175,
4524,
735,
355,
10062,
275,
2142,
288,
916,
1994,
11418,
4805,
315,
2142,
26,
355,
3991,
63,
633,
275,
2142,
267,
340,
440,
3991,
63,
633,
26,
288,
746,
19783,
360,
6531,
440,
2342,
3991,
2851,
358,
267,
1599,
275,
7815,
435,
6705,
63,
832,
8,
3722,
63,
633,
9,
267,
340,
1599,
508,
2538,
1988,
552,
8,
832,
304,
2189,
288,
2538,
275,
2538,
4439,
552,
8,
832,
1874,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
3991,
63,
633,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
1014,
63,
20996,
356,
283,
1014,
921,
1544,
14,
3844,
3908,
14,
957,
15,
1659,
6147,
15,
1659,
6147,
14,
957,
23012,
13,
19,
14,
18,
14,
1079,
14,
20426,
297,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
richhaase/kafka
|
tests/kafkatest/tests/core/consumer_group_command_test.py
|
4
|
4585
|
# 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.
from ducktape.utils.util import wait_until
from ducktape.tests.test import Test
from ducktape.mark import matrix
from ducktape.mark.resource import cluster
from kafkatest.services.zookeeper import ZookeeperService
from kafkatest.services.kafka import KafkaService
from kafkatest.services.console_consumer import ConsoleConsumer
from kafkatest.services.security.security_config import SecurityConfig
import os
import re
TOPIC = "topic-consumer-group-command"
class ConsumerGroupCommandTest(Test):
"""
Tests ConsumerGroupCommand
"""
# Root directory for persistent output
PERSISTENT_ROOT = "/mnt/consumer_group_command"
COMMAND_CONFIG_FILE = os.path.join(PERSISTENT_ROOT, "command.properties")
def __init__(self, test_context):
super(ConsumerGroupCommandTest, self).__init__(test_context)
self.num_zk = 1
self.num_brokers = 1
self.topics = {
TOPIC: {'partitions': 1, 'replication-factor': 1}
}
self.zk = ZookeeperService(test_context, self.num_zk)
def setUp(self):
self.zk.start()
def start_kafka(self, security_protocol, interbroker_security_protocol):
self.kafka = KafkaService(
self.test_context, self.num_brokers,
self.zk, security_protocol=security_protocol,
interbroker_security_protocol=interbroker_security_protocol, topics=self.topics)
self.kafka.start()
def start_consumer(self):
self.consumer = ConsoleConsumer(self.test_context, num_nodes=self.num_brokers, kafka=self.kafka, topic=TOPIC,
consumer_timeout_ms=None)
self.consumer.start()
def setup_and_verify(self, security_protocol, group=None):
self.start_kafka(security_protocol, security_protocol)
self.start_consumer()
consumer_node = self.consumer.nodes[0]
wait_until(lambda: self.consumer.alive(consumer_node),
timeout_sec=10, backoff_sec=.2, err_msg="Consumer was too slow to start")
kafka_node = self.kafka.nodes[0]
if security_protocol is not SecurityConfig.PLAINTEXT:
prop_file = str(self.kafka.security_config.client_config())
self.logger.debug(prop_file)
kafka_node.account.ssh("mkdir -p %s" % self.PERSISTENT_ROOT, allow_fail=False)
kafka_node.account.create_file(self.COMMAND_CONFIG_FILE, prop_file)
# Verify ConsumerGroupCommand lists expected consumer groups
command_config_file = self.COMMAND_CONFIG_FILE
if group:
wait_until(lambda: re.search("topic-consumer-group-command",self.kafka.describe_consumer_group(group=group, node=kafka_node, command_config=command_config_file)), timeout_sec=10,
err_msg="Timed out waiting to list expected consumer groups.")
else:
wait_until(lambda: "test-consumer-group" in self.kafka.list_consumer_groups(node=kafka_node, command_config=command_config_file), timeout_sec=10,
err_msg="Timed out waiting to list expected consumer groups.")
self.consumer.stop()
@cluster(num_nodes=3)
@matrix(security_protocol=['PLAINTEXT', 'SSL'])
def test_list_consumer_groups(self, security_protocol='PLAINTEXT'):
"""
Tests if ConsumerGroupCommand is listing correct consumer groups
:return: None
"""
self.setup_and_verify(security_protocol)
@cluster(num_nodes=3)
@matrix(security_protocol=['PLAINTEXT', 'SSL'])
def test_describe_consumer_group(self, security_protocol='PLAINTEXT'):
"""
Tests if ConsumerGroupCommand is describing a consumer group correctly
:return: None
"""
self.setup_and_verify(security_protocol, group="test-consumer-group")
|
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,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
504,
366,
10112,
502,
321,
14,
1208,
14,
1974,
492,
3618,
63,
8111,
199,
504,
366,
10112,
502,
321,
14,
2219,
14,
396,
492,
1379,
199,
504,
366,
10112,
502,
321,
14,
1657,
492,
3634,
199,
504,
366,
10112,
502,
321,
14,
1657,
14,
1927,
492,
4350,
199,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
90,
23479,
492,
3107,
23479,
3167,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
26186,
492,
1804,
15294,
3167,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
6614,
63,
8542,
492,
19809,
18186,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
4416,
14,
4416,
63,
888,
492,
13863,
2028,
199,
199,
646,
747,
199,
646,
295,
199,
199,
23740,
275,
298,
5746,
13,
8542,
13,
923,
13,
1531,
2,
421,
199,
533,
1448,
5391,
2448,
3110,
774,
8,
774,
304,
272,
408,
272,
6496,
1448,
5391,
2448,
3110,
272,
408,
272,
327,
12826,
2082,
367,
16149,
1072,
272,
13873,
29367,
1309,
63,
5441,
275,
3286,
20481,
15,
8542,
63,
923,
63,
1531,
2,
272,
25965,
63,
5569,
63,
3817,
275,
747,
14,
515,
14,
904,
8,
4227,
29367,
1309,
63,
5441,
12,
298,
1531,
14,
3282,
531,
339,
347,
636,
826,
721,
277,
12,
511,
63,
1100,
304,
267,
1613,
8,
18186,
2448,
3110,
774,
12,
291,
2843,
826,
721,
396,
63,
1100,
9,
267,
291,
14,
1507,
63,
20344,
275,
413,
267,
291,
14,
1507,
63,
20670,
75,
1192,
275,
413,
267,
291,
14,
11299,
275,
469,
288,
32582,
948,
26,
791,
12553,
356,
413,
12,
283,
17144,
13,
4778,
356,
413,
93,
267,
789,
267,
291,
14,
20344,
275,
3107,
23479,
3167,
8,
396,
63,
1100,
12,
291,
14,
1507,
63,
20344,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
20344,
14,
928,
342,
339,
347,
1343,
63,
26186,
8,
277,
12,
6391,
63,
3922,
12,
1640,
16620,
63,
4416,
63,
3922,
304,
267,
291,
14,
26186,
275,
1804,
15294,
3167,
8,
288,
291,
14,
396,
63,
1100,
12,
291,
14,
1507,
63,
20670,
75,
1192,
12,
288,
291,
14,
20344,
12,
6391,
63,
3922,
29,
4416,
63,
3922,
12,
288,
1640,
16620,
63,
4416,
63,
3922,
29,
1058,
16620,
63,
4416,
63,
3922,
12,
17398,
29,
277,
14,
11299,
9,
267,
291,
14,
26186,
14,
928,
342,
339,
347,
1343,
63,
8542,
8,
277,
304,
267,
291,
14,
8542,
275,
19809,
18186,
8,
277,
14,
396,
63,
1100,
12,
1967,
63,
2415,
29,
277,
14,
1507,
63,
20670,
75,
1192,
12,
29576,
29,
277,
14,
26186,
12,
7482,
29,
23740,
12,
3147,
9790,
63,
2593,
63,
706,
29,
403,
9,
267,
291,
14,
8542,
14,
928,
342,
339,
347,
3272,
63,
460,
63,
4712,
8,
277,
12,
6391,
63,
3922,
12,
1572,
29,
403,
304,
267,
291,
14,
928,
63,
26186,
8,
4416,
63,
3922,
12,
6391,
63,
3922,
9,
267,
291,
14,
928,
63,
8542,
342,
267,
9790,
63,
932,
275,
291,
14,
8542,
14,
2415,
59,
16,
61,
267,
3618,
63,
8111,
8,
2734,
26,
291,
14,
8542,
14,
9631,
8,
8542,
63,
932,
395,
673,
2653,
63,
3321,
29,
709,
12,
22735,
63,
3321,
15856,
18,
12,
2329,
63,
1328,
628,
18186,
1990,
4634,
11999,
370,
1343,
531,
267,
29576,
63,
932,
275,
291,
14,
26186,
14,
2415,
59,
16,
61,
267,
340,
6391,
63,
3922,
365,
440,
13863,
2028,
14,
2749,
33,
2919,
2472,
26,
288,
5931,
63,
493,
275,
620,
8,
277,
14,
26186,
14,
4416,
63,
888,
14,
1258,
63,
888,
1012,
288,
291,
14,
2921,
14,
1757,
8,
4469,
63,
493,
9,
288,
29576,
63,
932,
14,
2048,
14,
5510,
480,
8215,
446,
80,
450,
83,
2,
450,
291,
14,
4227,
29367,
1309,
63,
5441,
12,
2040,
63,
1633,
29,
797,
9,
288,
29576,
63,
932,
14,
2048,
14,
981,
63,
493,
8,
277,
14,
10761,
63,
5569,
63,
3817,
12,
5931,
63,
493,
9,
398,
327,
7635,
1448,
5391,
2448,
3110,
5548,
1420,
9790,
4652,
267,
1414,
63,
888,
63,
493,
275,
291,
14,
10761,
63,
5569,
63,
3817,
398,
340,
1572,
26,
288,
3618,
63,
8111,
8,
2734,
26,
295,
14,
1733,
480,
5746,
13,
8542,
13,
923,
13,
1531,
401,
277,
14,
26186,
14,
11935,
63,
8542,
63,
923,
8,
923,
29,
923,
12,
1031,
29,
26186,
63,
932,
12,
1414,
63,
888,
29,
1531,
63,
888,
63,
493,
1826,
2653,
63,
3321,
29,
709,
12,
2432,
2329,
63,
1328,
628,
28682,
734,
10923,
370,
769,
1420,
9790,
4652,
2685,
267,
587,
26,
288,
3618,
63,
8111,
8,
2734,
26,
298,
396,
13,
8542,
13,
923,
2,
315,
291,
14,
26186,
14,
513,
63,
8542,
63,
2634,
8,
932,
29,
26186,
63,
932,
12,
1414,
63,
888,
29,
1531,
63,
888,
63,
493,
395,
2653,
63,
3321,
29,
709,
12,
2432,
2329,
63,
1328,
628,
28682,
734,
10923,
370,
769,
1420,
9790,
4652,
2685,
398,
291,
14,
8542,
14,
2379,
342,
339,
768,
4201,
8,
1507,
63,
2415,
29,
19,
9,
272,
768,
3642,
8,
4416,
63,
3922,
2968,
2749,
33,
2919,
2472,
297,
283,
5413,
1105,
272,
347,
511,
63,
513,
63
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
504,
366,
10112,
502,
321,
14,
1208,
14,
1974,
492,
3618,
63,
8111,
199,
504,
366,
10112,
502,
321,
14,
2219,
14,
396,
492,
1379,
199,
504,
366,
10112,
502,
321,
14,
1657,
492,
3634,
199,
504,
366,
10112,
502,
321,
14,
1657,
14,
1927,
492,
4350,
199,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
90,
23479,
492,
3107,
23479,
3167,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
26186,
492,
1804,
15294,
3167,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
6614,
63,
8542,
492,
19809,
18186,
199,
504,
1022,
2756,
75,
27126,
14,
5950,
14,
4416,
14,
4416,
63,
888,
492,
13863,
2028,
199,
199,
646,
747,
199,
646,
295,
199,
199,
23740,
275,
298,
5746,
13,
8542,
13,
923,
13,
1531,
2,
421,
199,
533,
1448,
5391,
2448,
3110,
774,
8,
774,
304,
272,
408,
272,
6496,
1448,
5391,
2448,
3110,
272,
408,
272,
327,
12826,
2082,
367,
16149,
1072,
272,
13873,
29367,
1309,
63,
5441,
275,
3286,
20481,
15,
8542,
63,
923,
63,
1531,
2,
272,
25965,
63,
5569,
63,
3817,
275,
747,
14,
515,
14,
904,
8,
4227,
29367,
1309,
63,
5441,
12,
298,
1531,
14,
3282,
531,
339,
347,
636,
826,
721,
277,
12,
511,
63,
1100,
304,
267,
1613,
8,
18186,
2448,
3110,
774,
12,
291,
2843,
826,
721,
396,
63,
1100,
9,
267,
291,
14,
1507,
63,
20344,
275,
413,
267,
291,
14,
1507,
63,
20670,
75,
1192,
275,
413,
267,
291,
14,
11299,
275,
469,
288,
32582,
948,
26,
791,
12553,
356,
413,
12,
283,
17144,
13,
4778,
356,
413,
93,
267,
789,
267,
291,
14,
20344,
275,
3107,
23479,
3167,
8,
396,
63,
1100,
12,
291,
14,
1507,
63,
20344,
9,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
20344,
14,
928,
342,
339,
347,
1343,
63,
26186,
8,
277,
12,
6391,
63,
3922,
12,
1640,
16620,
63,
4416,
63,
3922,
304,
267,
291,
14,
26186,
275,
1804,
15294,
3167,
8,
288,
291,
14,
396,
63,
1100,
12,
291,
14,
1507,
63,
20670,
75,
1192,
12,
288,
291,
14,
20344,
12,
6391,
63,
3922,
29,
4416,
63,
3922,
12,
288,
1640,
16620,
63,
4416,
63,
3922,
29,
1058,
16620,
63,
4416,
63,
3922,
12,
17398,
29,
277,
14,
11299,
9,
267,
291,
14,
26186,
14,
928,
342,
339,
347,
1343,
63,
8542,
8,
277,
304,
267,
291,
14,
8542,
275,
19809,
18186,
8,
277,
14,
396,
63,
1100,
12,
1967,
63,
2415,
29,
277,
14,
1507,
63,
20670,
75,
1192,
12,
29576,
29,
277,
14,
26186,
12,
7482,
29,
23740,
12,
3147,
9790,
63,
2593,
63,
706,
29,
403,
9,
267,
291,
14,
8542,
14,
928,
342,
339,
347,
3272,
63,
460,
63,
4712,
8,
277,
12,
6391,
63,
3922,
12,
1572,
29,
403,
304,
267,
291,
14,
928,
63,
26186,
8,
4416,
63,
3922,
12,
6391,
63,
3922,
9,
267,
291,
14,
928,
63,
8542,
342,
267,
9790,
63,
932,
275,
291,
14,
8542,
14,
2415,
59,
16,
61,
267,
3618,
63,
8111,
8,
2734,
26,
291,
14,
8542,
14,
9631,
8,
8542,
63,
932,
395,
673,
2653,
63,
3321,
29,
709,
12,
22735,
63,
3321,
15856,
18,
12,
2329,
63,
1328,
628,
18186,
1990,
4634,
11999,
370,
1343,
531,
267,
29576,
63,
932,
275,
291,
14,
26186,
14,
2415,
59,
16,
61,
267,
340,
6391,
63,
3922,
365,
440,
13863,
2028,
14,
2749,
33,
2919,
2472,
26,
288,
5931,
63,
493,
275,
620,
8,
277,
14,
26186,
14,
4416,
63,
888,
14,
1258,
63,
888,
1012,
288,
291,
14,
2921,
14,
1757,
8,
4469,
63,
493,
9,
288,
29576,
63,
932,
14,
2048,
14,
5510,
480,
8215,
446,
80,
450,
83,
2,
450,
291,
14,
4227,
29367,
1309,
63,
5441,
12,
2040,
63,
1633,
29,
797,
9,
288,
29576,
63,
932,
14,
2048,
14,
981,
63,
493,
8,
277,
14,
10761,
63,
5569,
63,
3817,
12,
5931,
63,
493,
9,
398,
327,
7635,
1448,
5391,
2448,
3110,
5548,
1420,
9790,
4652,
267,
1414,
63,
888,
63,
493,
275,
291,
14,
10761,
63,
5569,
63,
3817,
398,
340,
1572,
26,
288,
3618,
63,
8111,
8,
2734,
26,
295,
14,
1733,
480,
5746,
13,
8542,
13,
923,
13,
1531,
401,
277,
14,
26186,
14,
11935,
63,
8542,
63,
923,
8,
923,
29,
923,
12,
1031,
29,
26186,
63,
932,
12,
1414,
63,
888,
29,
1531,
63,
888,
63,
493,
1826,
2653,
63,
3321,
29,
709,
12,
2432,
2329,
63,
1328,
628,
28682,
734,
10923,
370,
769,
1420,
9790,
4652,
2685,
267,
587,
26,
288,
3618,
63,
8111,
8,
2734,
26,
298,
396,
13,
8542,
13,
923,
2,
315,
291,
14,
26186,
14,
513,
63,
8542,
63,
2634,
8,
932,
29,
26186,
63,
932,
12,
1414,
63,
888,
29,
1531,
63,
888,
63,
493,
395,
2653,
63,
3321,
29,
709,
12,
2432,
2329,
63,
1328,
628,
28682,
734,
10923,
370,
769,
1420,
9790,
4652,
2685,
398,
291,
14,
8542,
14,
2379,
342,
339,
768,
4201,
8,
1507,
63,
2415,
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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
] |
Metaswitch/calico-neutron
|
neutron/tests/unit/cisco/cfg_agent/test_csr1kv_routing_driver.py
|
17
|
12132
|
# Copyright 2014 Cisco Systems, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import sys
import mock
import netaddr
from neutron.common import constants as l3_constants
from neutron.openstack.common import uuidutils
from neutron.tests import base
from neutron.plugins.cisco.cfg_agent.device_drivers.csr1kv import (
cisco_csr1kv_snippets as snippets)
sys.modules['ncclient'] = mock.MagicMock()
sys.modules['ciscoconfparse'] = mock.MagicMock()
from neutron.plugins.cisco.cfg_agent.device_drivers.csr1kv import (
csr1kv_routing_driver as csr_driver)
from neutron.plugins.cisco.cfg_agent.service_helpers import routing_svc_helper
_uuid = uuidutils.generate_uuid
FAKE_ID = _uuid()
PORT_ID = _uuid()
class TestCSR1kvRouting(base.BaseTestCase):
def setUp(self):
super(TestCSR1kvRouting, self).setUp()
device_params = {'management_ip_address': 'fake_ip',
'protocol_port': 22,
'credentials': {"username": "stack",
"password": "cisco"},
}
self.driver = csr_driver.CSR1kvRoutingDriver(
**device_params)
self.mock_conn = mock.MagicMock()
self.driver._csr_conn = self.mock_conn
self.driver._check_response = mock.MagicMock(return_value=True)
self.vrf = ('nrouter-' + FAKE_ID)[:csr_driver.CSR1kvRoutingDriver.
DEV_NAME_LEN]
self.driver._get_vrfs = mock.Mock(return_value=[self.vrf])
self.ex_gw_ip = '20.0.0.30'
self.ex_gw_cidr = '20.0.0.30/24'
self.ex_gw_vlan = 1000
self.ex_gw_gateway_ip = '20.0.0.1'
self.ex_gw_port = {'id': _uuid(),
'network_id': _uuid(),
'fixed_ips': [{'ip_address': self.ex_gw_ip,
'subnet_id': _uuid()}],
'subnet': {'cidr': self.ex_gw_cidr,
'gateway_ip': self.ex_gw_gateway_ip},
'ip_cidr': self.ex_gw_cidr,
'mac_address': 'ca:fe:de:ad:be:ef',
'hosting_info': {'segmentation_id': self.ex_gw_vlan,
'hosting_port_name': 't2_p:0'}}
self.vlan_no = 500
self.gw_ip_cidr = '10.0.0.1/16'
self.gw_ip = '10.0.0.1'
self.hosting_port = 't1_p:0'
self.port = {'id': PORT_ID,
'ip_cidr': self.gw_ip_cidr,
'fixed_ips': [{'ip_address': self.gw_ip}],
'hosting_info': {'segmentation_id': self.vlan_no,
'hosting_port_name': self.hosting_port}}
int_ports = [self.port]
self.router = {
'id': FAKE_ID,
l3_constants.INTERFACE_KEY: int_ports,
'enable_snat': True,
'routes': [],
'gw_port': self.ex_gw_port}
self.ri = routing_svc_helper.RouterInfo(FAKE_ID, self.router)
self.ri.internal_ports = int_ports
def test_csr_get_vrf_name(self):
self.assertEqual(self.driver._csr_get_vrf_name(self.ri), self.vrf)
def test_create_vrf(self):
confstr = snippets.CREATE_VRF % self.vrf
self.driver._create_vrf(self.vrf)
self.assertTrue(self.driver._csr_conn.edit_config.called)
self.driver._csr_conn.edit_config.assert_called_with(target='running',
config=confstr)
def test_remove_vrf(self):
confstr = snippets.REMOVE_VRF % self.vrf
self.driver._remove_vrf(self.vrf)
self.assertTrue(self.driver._csr_conn.edit_config.called)
self.driver._csr_conn.edit_config.assert_called_with(target='running',
config=confstr)
def test_router_added(self):
confstr = snippets.CREATE_VRF % self.vrf
self.driver.router_added(self.ri)
self.assertTrue(self.driver._csr_conn.edit_config.called)
self.driver._csr_conn.edit_config.assert_called_with(target='running',
config=confstr)
def test_router_removed(self):
confstr = snippets.REMOVE_VRF % self.vrf
self.driver._remove_vrf(self.vrf)
self.assertTrue(self.driver._csr_conn.edit_config.called)
self.driver._csr_conn.edit_config.assert_called_once_with(
target='running', config=confstr)
def test_internal_network_added(self):
self.driver._create_subinterface = mock.MagicMock()
interface = 'GigabitEthernet0' + '.' + str(self.vlan_no)
self.driver.internal_network_added(self.ri, self.port)
args = (interface, self.vlan_no, self.vrf, self.gw_ip,
netaddr.IPAddress('255.255.0.0'))
self.driver._create_subinterface.assert_called_once_with(*args)
def test_internal_network_removed(self):
self.driver._remove_subinterface = mock.MagicMock()
interface = 'GigabitEthernet0' + '.' + str(self.vlan_no)
self.driver.internal_network_removed(self.ri, self.port)
self.driver._remove_subinterface.assert_called_once_with(interface)
def test_routes_updated(self):
dest_net = '20.0.0.0/16'
next_hop = '10.0.0.255'
route = {'destination': dest_net,
'nexthop': next_hop}
dest = netaddr.IPAddress('20.0.0.0')
destmask = netaddr.IPNetwork(dest_net).netmask
self.driver._add_static_route = mock.MagicMock()
self.driver._remove_static_route = mock.MagicMock()
self.driver.routes_updated(self.ri, 'replace', route)
self.driver._add_static_route.assert_called_once_with(
dest, destmask, next_hop, self.vrf)
self.driver.routes_updated(self.ri, 'delete', route)
self.driver._remove_static_route.assert_called_once_with(
dest, destmask, next_hop, self.vrf)
def test_floatingip(self):
floating_ip = '15.1.2.3'
fixed_ip = '10.0.0.3'
self.driver._add_floating_ip = mock.MagicMock()
self.driver._remove_floating_ip = mock.MagicMock()
self.driver._add_interface_nat = mock.MagicMock()
self.driver._remove_dyn_nat_translations = mock.MagicMock()
self.driver._remove_interface_nat = mock.MagicMock()
self.driver.floating_ip_added(self.ri, self.ex_gw_port,
floating_ip, fixed_ip)
self.driver._add_floating_ip.assert_called_once_with(
floating_ip, fixed_ip, self.vrf)
self.driver.floating_ip_removed(self.ri, self.ex_gw_port,
floating_ip, fixed_ip)
self.driver._remove_interface_nat.assert_called_once_with(
'GigabitEthernet1.1000', 'outside')
self.driver._remove_dyn_nat_translations.assert_called_once_with()
self.driver._remove_floating_ip.assert_called_once_with(
floating_ip, fixed_ip, self.vrf)
self.driver._add_interface_nat.assert_called_once_with(
'GigabitEthernet1.1000', 'outside')
def test_external_gateway_added(self):
self.driver._create_subinterface = mock.MagicMock()
self.driver._add_default_static_route = mock.MagicMock()
ext_interface = 'GigabitEthernet1' + '.' + str(1000)
args = (ext_interface, self.ex_gw_vlan, self.vrf, self.ex_gw_ip,
netaddr.IPAddress('255.255.255.0'))
self.driver.external_gateway_added(self.ri, self.ex_gw_port)
self.driver._create_subinterface.assert_called_once_with(*args)
self.driver._add_default_static_route.assert_called_once_with(
self.ex_gw_gateway_ip, self.vrf)
def test_enable_internal_network_NAT(self):
self.driver._nat_rules_for_internet_access = mock.MagicMock()
int_interface = ('GigabitEthernet0' + '.' + str(self.vlan_no))
ext_interface = 'GigabitEthernet1' + '.' + str(1000)
args = (('acl_' + str(self.vlan_no)),
netaddr.IPNetwork(self.gw_ip_cidr).network,
netaddr.IPNetwork(self.gw_ip_cidr).hostmask,
int_interface,
ext_interface,
self.vrf)
self.driver.enable_internal_network_NAT(self.ri, self.port,
self.ex_gw_port)
self.driver._nat_rules_for_internet_access.assert_called_once_with(
*args)
def test_enable_internal_network_NAT_with_confstring(self):
self.driver._csr_conn.reset_mock()
self.driver._check_acl = mock.Mock(return_value=False)
int_interface = ('GigabitEthernet0' + '.' + str(self.vlan_no))
ext_interface = 'GigabitEthernet1' + '.' + str(1000)
acl_no = ('acl_' + str(self.vlan_no))
int_network = netaddr.IPNetwork(self.gw_ip_cidr).network
int_net_mask = netaddr.IPNetwork(self.gw_ip_cidr).hostmask
self.driver.enable_internal_network_NAT(self.ri, self.port,
self.ex_gw_port)
self.assert_edit_running_config(
snippets.CREATE_ACL, (acl_no, int_network, int_net_mask))
self.assert_edit_running_config(
snippets.SET_DYN_SRC_TRL_INTFC, (acl_no, ext_interface, self.vrf))
self.assert_edit_running_config(
snippets.SET_NAT, (int_interface, 'inside'))
self.assert_edit_running_config(
snippets.SET_NAT, (ext_interface, 'outside'))
def test_disable_internal_network_NAT(self):
self.driver._remove_interface_nat = mock.MagicMock()
self.driver._remove_dyn_nat_translations = mock.MagicMock()
self.driver._remove_dyn_nat_rule = mock.MagicMock()
int_interface = ('GigabitEthernet0' + '.' + str(self.vlan_no))
ext_interface = 'GigabitEthernet1' + '.' + str(1000)
self.driver.disable_internal_network_NAT(self.ri, self.port,
self.ex_gw_port)
args = (('acl_' + str(self.vlan_no)), ext_interface, self.vrf)
self.driver._remove_interface_nat.assert_called_once_with(
int_interface, 'inside')
self.driver._remove_dyn_nat_translations.assert_called_once_with()
self.driver._remove_dyn_nat_rule.assert_called_once_with(*args)
def assert_edit_running_config(self, snippet_name, args):
if args:
confstr = snippet_name % args
else:
confstr = snippet_name
self.driver._csr_conn.edit_config.assert_any_call(
target='running', config=confstr)
def test_disable_internal_network_NAT_with_confstring(self):
self.driver._cfg_exists = mock.Mock(return_value=True)
int_interface = ('GigabitEthernet0' + '.' + str(self.vlan_no))
ext_interface = 'GigabitEthernet1' + '.' + str(1000)
acl_no = 'acl_' + str(self.vlan_no)
self.driver.disable_internal_network_NAT(self.ri, self.port,
self.ex_gw_port)
self.assert_edit_running_config(
snippets.REMOVE_NAT, (int_interface, 'inside'))
self.assert_edit_running_config(snippets.CLEAR_DYN_NAT_TRANS, None)
self.assert_edit_running_config(
snippets.REMOVE_DYN_SRC_TRL_INTFC, (acl_no, ext_interface,
self.vrf))
self.assert_edit_running_config(snippets.REMOVE_ACL, acl_no)
|
apache-2.0
|
[
3,
1898,
6927,
28356,
15285,
12,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
646,
1683,
199,
646,
25798,
199,
199,
504,
8224,
14,
2330,
492,
5262,
465,
634,
19,
63,
5559,
199,
504,
8224,
14,
8512,
14,
2330,
492,
5377,
1208,
199,
504,
8224,
14,
2219,
492,
1300,
199,
199,
504,
8224,
14,
5265,
14,
19597,
14,
4128,
63,
4054,
14,
1782,
63,
13337,
14,
10101,
17,
11475,
492,
334,
272,
286,
10081,
63,
10101,
17,
11475,
63,
32566,
465,
19484,
9,
199,
1274,
14,
3112,
459,
7966,
1258,
418,
275,
1683,
14,
11988,
342,
199,
1274,
14,
3112,
459,
19597,
2190,
1122,
418,
275,
1683,
14,
11988,
342,
199,
504,
8224,
14,
5265,
14,
19597,
14,
4128,
63,
4054,
14,
1782,
63,
13337,
14,
10101,
17,
11475,
492,
334,
272,
22258,
17,
11475,
63,
9492,
63,
3090,
465,
22258,
63,
3090,
9,
199,
504,
8224,
14,
5265,
14,
19597,
14,
4128,
63,
4054,
14,
1364,
63,
7546,
492,
14870,
63,
10599,
63,
3676,
199,
199,
63,
2580,
275,
5377,
1208,
14,
4208,
63,
2580,
199,
14623,
63,
998,
275,
485,
2580,
342,
199,
3657,
63,
998,
275,
485,
2580,
342,
421,
199,
533,
1379,
32085,
17,
11475,
8056,
8,
1095,
14,
20760,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
32085,
17,
11475,
8056,
12,
291,
680,
5996,
342,
398,
2243,
63,
1162,
275,
791,
8110,
63,
711,
63,
1562,
356,
283,
3183,
63,
711,
297,
586,
283,
3922,
63,
719,
356,
6928,
12,
586,
283,
6942,
356,
2420,
2473,
582,
298,
2340,
401,
1460,
298,
2060,
582,
298,
19597,
6018,
586,
789,
267,
291,
14,
3090,
275,
22258,
63,
3090,
14,
32085,
17,
11475,
8056,
6158,
8,
288,
1011,
1782,
63,
1162,
9,
267,
291,
14,
1805,
63,
1631,
275,
1683,
14,
11988,
342,
267,
291,
14,
3090,
423,
10101,
63,
1631,
275,
291,
14,
1805,
63,
1631,
267,
291,
14,
3090,
423,
1074,
63,
1310,
275,
1683,
14,
11988,
8,
1107,
63,
585,
29,
549,
9,
398,
291,
14,
11863,
275,
661,
78,
4995,
15668,
435,
25699,
63,
998,
18562,
10101,
63,
3090,
14,
32085,
17,
11475,
8056,
6158,
14,
5101,
3265,
54,
63,
2339,
63,
5304,
61,
267,
291,
14,
3090,
423,
362,
63,
10922,
2319,
275,
1683,
14,
3346,
8,
1107,
63,
585,
1524,
277,
14,
11863,
566,
267,
291,
14,
476,
63,
8392,
63,
711,
275,
283,
1165,
14,
16,
14,
16,
14,
1216,
7,
267,
291,
14,
476,
63,
8392,
63,
10509,
275,
283,
1165,
14,
16,
14,
16,
14,
1216,
15,
1194,
7,
267,
291,
14,
476,
63,
8392,
63,
7175,
275,
5198,
267,
291,
14,
476,
63,
8392,
63,
7019,
63,
711,
275,
283,
1165,
14,
16,
14,
16,
14,
17,
7,
267,
291,
14,
476,
63,
8392,
63,
719,
275,
791,
344,
356,
485,
2580,
1062,
2574,
283,
1200,
63,
344,
356,
485,
2580,
1062,
2574,
283,
5964,
63,
6142,
356,
9016,
711,
63,
1562,
356,
291,
14,
476,
63,
8392,
63,
711,
12,
5101,
283,
5327,
63,
344,
356,
485,
2580,
12737,
467,
2574,
283,
5327,
356,
791,
10509,
356,
291,
14,
476,
63,
8392,
63,
10509,
12,
4228,
283,
7019,
63,
711,
356,
291,
14,
476,
63,
8392,
63,
7019,
63,
711,
1386,
2574,
283,
711,
63,
10509,
356,
291,
14,
476,
63,
8392,
63,
10509,
12,
2574,
283,
3088,
63,
1562,
356,
283,
696,
26,
771,
26,
271,
26,
350,
26,
1235,
26,
2829,
297,
2574,
283,
29138,
63,
815,
356,
791,
26926,
63,
344,
356,
291,
14,
476,
63,
8392,
63,
7175,
12,
5101,
283,
29138,
63,
719,
63,
354,
356,
283,
84,
18,
63,
80,
26,
16,
18620,
267,
291,
14,
7175,
63,
889,
275,
6891,
267,
291,
14,
8392,
63,
711,
63,
10509,
275,
283,
709,
14,
16,
14,
16,
14,
17,
15,
975,
7,
267,
291,
14,
8392,
63,
711,
275,
283,
709,
14,
16,
14,
16,
14,
17,
7,
267,
291,
14,
29138,
63,
719,
275,
283,
84,
17,
63,
80,
26,
16,
7,
267,
291,
14,
719,
275,
791,
344,
356,
25562,
63,
998,
12,
2151,
283,
711,
63,
10509,
356,
291,
14,
8392,
63,
711,
63,
10509,
12,
2151,
283,
5964,
63,
6142,
356,
9016,
711,
63,
1562,
356,
291,
14,
8392,
63,
711,
22140,
2151,
283,
29138,
63,
815,
356,
791,
26926,
63,
344,
356,
291,
14,
7175,
63,
889,
12,
4228,
283,
29138,
63,
719,
63,
354,
356,
291,
14,
29138,
63,
719,
4863,
267,
1109,
63,
5203,
275,
359,
277,
14,
719,
61,
398,
291,
14,
4995,
275,
469,
288,
283,
344,
356,
25699,
63,
998,
12,
288,
634,
19,
63,
5559,
14,
17598,
63,
3078,
26,
1109,
63,
5203,
12,
288,
283,
4296,
63,
23774,
356,
715,
12,
288,
283,
13243,
356,
990,
288,
283,
8392,
63,
719,
356,
291,
14,
476,
63,
8392,
63,
719,
93,
398,
291,
14,
322,
275,
14870,
63,
10599,
63,
3676,
14,
11691,
2354,
8,
14623,
63,
998,
12,
291,
14,
4995,
9,
267,
291,
14,
322,
14,
4672,
63,
5203,
275,
1109,
63,
5203,
339,
347,
511,
63,
10101,
63,
362,
63,
11863,
63,
354,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
3090,
423,
10101,
63,
362,
63,
11863,
63,
354,
8,
277,
14,
322,
395,
291,
14,
11863,
9,
339,
347
] |
[
1898,
6927,
28356,
15285,
12,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
646,
1683,
199,
646,
25798,
199,
199,
504,
8224,
14,
2330,
492,
5262,
465,
634,
19,
63,
5559,
199,
504,
8224,
14,
8512,
14,
2330,
492,
5377,
1208,
199,
504,
8224,
14,
2219,
492,
1300,
199,
199,
504,
8224,
14,
5265,
14,
19597,
14,
4128,
63,
4054,
14,
1782,
63,
13337,
14,
10101,
17,
11475,
492,
334,
272,
286,
10081,
63,
10101,
17,
11475,
63,
32566,
465,
19484,
9,
199,
1274,
14,
3112,
459,
7966,
1258,
418,
275,
1683,
14,
11988,
342,
199,
1274,
14,
3112,
459,
19597,
2190,
1122,
418,
275,
1683,
14,
11988,
342,
199,
504,
8224,
14,
5265,
14,
19597,
14,
4128,
63,
4054,
14,
1782,
63,
13337,
14,
10101,
17,
11475,
492,
334,
272,
22258,
17,
11475,
63,
9492,
63,
3090,
465,
22258,
63,
3090,
9,
199,
504,
8224,
14,
5265,
14,
19597,
14,
4128,
63,
4054,
14,
1364,
63,
7546,
492,
14870,
63,
10599,
63,
3676,
199,
199,
63,
2580,
275,
5377,
1208,
14,
4208,
63,
2580,
199,
14623,
63,
998,
275,
485,
2580,
342,
199,
3657,
63,
998,
275,
485,
2580,
342,
421,
199,
533,
1379,
32085,
17,
11475,
8056,
8,
1095,
14,
20760,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
32085,
17,
11475,
8056,
12,
291,
680,
5996,
342,
398,
2243,
63,
1162,
275,
791,
8110,
63,
711,
63,
1562,
356,
283,
3183,
63,
711,
297,
586,
283,
3922,
63,
719,
356,
6928,
12,
586,
283,
6942,
356,
2420,
2473,
582,
298,
2340,
401,
1460,
298,
2060,
582,
298,
19597,
6018,
586,
789,
267,
291,
14,
3090,
275,
22258,
63,
3090,
14,
32085,
17,
11475,
8056,
6158,
8,
288,
1011,
1782,
63,
1162,
9,
267,
291,
14,
1805,
63,
1631,
275,
1683,
14,
11988,
342,
267,
291,
14,
3090,
423,
10101,
63,
1631,
275,
291,
14,
1805,
63,
1631,
267,
291,
14,
3090,
423,
1074,
63,
1310,
275,
1683,
14,
11988,
8,
1107,
63,
585,
29,
549,
9,
398,
291,
14,
11863,
275,
661,
78,
4995,
15668,
435,
25699,
63,
998,
18562,
10101,
63,
3090,
14,
32085,
17,
11475,
8056,
6158,
14,
5101,
3265,
54,
63,
2339,
63,
5304,
61,
267,
291,
14,
3090,
423,
362,
63,
10922,
2319,
275,
1683,
14,
3346,
8,
1107,
63,
585,
1524,
277,
14,
11863,
566,
267,
291,
14,
476,
63,
8392,
63,
711,
275,
283,
1165,
14,
16,
14,
16,
14,
1216,
7,
267,
291,
14,
476,
63,
8392,
63,
10509,
275,
283,
1165,
14,
16,
14,
16,
14,
1216,
15,
1194,
7,
267,
291,
14,
476,
63,
8392,
63,
7175,
275,
5198,
267,
291,
14,
476,
63,
8392,
63,
7019,
63,
711,
275,
283,
1165,
14,
16,
14,
16,
14,
17,
7,
267,
291,
14,
476,
63,
8392,
63,
719,
275,
791,
344,
356,
485,
2580,
1062,
2574,
283,
1200,
63,
344,
356,
485,
2580,
1062,
2574,
283,
5964,
63,
6142,
356,
9016,
711,
63,
1562,
356,
291,
14,
476,
63,
8392,
63,
711,
12,
5101,
283,
5327,
63,
344,
356,
485,
2580,
12737,
467,
2574,
283,
5327,
356,
791,
10509,
356,
291,
14,
476,
63,
8392,
63,
10509,
12,
4228,
283,
7019,
63,
711,
356,
291,
14,
476,
63,
8392,
63,
7019,
63,
711,
1386,
2574,
283,
711,
63,
10509,
356,
291,
14,
476,
63,
8392,
63,
10509,
12,
2574,
283,
3088,
63,
1562,
356,
283,
696,
26,
771,
26,
271,
26,
350,
26,
1235,
26,
2829,
297,
2574,
283,
29138,
63,
815,
356,
791,
26926,
63,
344,
356,
291,
14,
476,
63,
8392,
63,
7175,
12,
5101,
283,
29138,
63,
719,
63,
354,
356,
283,
84,
18,
63,
80,
26,
16,
18620,
267,
291,
14,
7175,
63,
889,
275,
6891,
267,
291,
14,
8392,
63,
711,
63,
10509,
275,
283,
709,
14,
16,
14,
16,
14,
17,
15,
975,
7,
267,
291,
14,
8392,
63,
711,
275,
283,
709,
14,
16,
14,
16,
14,
17,
7,
267,
291,
14,
29138,
63,
719,
275,
283,
84,
17,
63,
80,
26,
16,
7,
267,
291,
14,
719,
275,
791,
344,
356,
25562,
63,
998,
12,
2151,
283,
711,
63,
10509,
356,
291,
14,
8392,
63,
711,
63,
10509,
12,
2151,
283,
5964,
63,
6142,
356,
9016,
711,
63,
1562,
356,
291,
14,
8392,
63,
711,
22140,
2151,
283,
29138,
63,
815,
356,
791,
26926,
63,
344,
356,
291,
14,
7175,
63,
889,
12,
4228,
283,
29138,
63,
719,
63,
354,
356,
291,
14,
29138,
63,
719,
4863,
267,
1109,
63,
5203,
275,
359,
277,
14,
719,
61,
398,
291,
14,
4995,
275,
469,
288,
283,
344,
356,
25699,
63,
998,
12,
288,
634,
19,
63,
5559,
14,
17598,
63,
3078,
26,
1109,
63,
5203,
12,
288,
283,
4296,
63,
23774,
356,
715,
12,
288,
283,
13243,
356,
990,
288,
283,
8392,
63,
719,
356,
291,
14,
476,
63,
8392,
63,
719,
93,
398,
291,
14,
322,
275,
14870,
63,
10599,
63,
3676,
14,
11691,
2354,
8,
14623,
63,
998,
12,
291,
14,
4995,
9,
267,
291,
14,
322,
14,
4672,
63,
5203,
275,
1109,
63,
5203,
339,
347,
511,
63,
10101,
63,
362,
63,
11863,
63,
354,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
3090,
423,
10101,
63,
362,
63,
11863,
63,
354,
8,
277,
14,
322,
395,
291,
14,
11863,
9,
339,
347,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DarkFenX/Pyfa
|
eos/db/migrations/upgrade18.py
|
4
|
2933
|
"""
Migration 8
- Converts modules from old Warfare Links to Command Modules
"""
CONVERSIONS = {
42526: ( # Armor Command Burst I
20069, # Armored Warfare Link - Damage Control I
20409, # Armored Warfare Link - Passive Defense I
22227, # Armored Warfare Link - Rapid Repair I
),
43552: ( # Armor Command Burst II
4264, # Armored Warfare Link - Damage Control II
4266, # Armored Warfare Link - Passive Defense II
4266, # Armored Warfare Link - Rapid Repair II
),
42527: ( # Information Command Burst I
11052, # Information Warfare Link - Sensor Integrity I
20405, # Information Warfare Link - Recon Operation I
20406, # Information Warfare Link - Electronic Superiority I
),
43554: ( # Information Command Burst II
4268, # Information Warfare Link - Electronic Superiority II
4270, # Information Warfare Link - Recon Operation II
4272, # Information Warfare Link - Sensor Integrity II
),
42529: ( # Shield Command Burst I
20124, # Siege Warfare Link - Active Shielding I
20514, # Siege Warfare Link - Shield Harmonizing I
22228, # Siege Warfare Link - Shield Efficiency I
),
43555: ( # Shield Command Burst II
4280, # Siege Warfare Link - Active Shielding II
4282, # Siege Warfare Link - Shield Efficiency II
4284 # Siege Warfare Link - Shield Harmonizing II
),
42530: ( # Skirmish Command Burst I
11017, # Skirmish Warfare Link - Interdiction Maneuvers I
20070, # Skirmish Warfare Link - Evasive Maneuvers I
20408, # Skirmish Warfare Link - Rapid Deployment I
),
43556: ( # Skirmish Command Burst II
4286, # Skirmish Warfare Link - Evasive Maneuvers II
4288, # Skirmish Warfare Link - Interdiction Maneuvers II
4290 # Skirmish Warfare Link - Rapid Deployment II
),
42528: ( # Mining Foreman Burst I
22553, # Mining Foreman Link - Harvester Capacitor Efficiency I
22555, # Mining Foreman Link - Mining Laser Field Enhancement I
22557, # Mining Foreman Link - Laser Optimization I
),
43551: ( # Mining Foreman Burst II
4274, # Mining Foreman Link - Harvester Capacitor Efficiency II
4276, # Mining Foreman Link - Laser Optimization II
4278 # Mining Foreman Link - Mining Laser Field Enhancement II
),
}
def upgrade(saveddata_engine):
# Convert modules
for replacement_item, list in CONVERSIONS.items():
for retired_item in list:
saveddata_engine.execute('UPDATE "modules" SET "itemID" = ? WHERE "itemID" = ?',
(replacement_item, retired_item))
saveddata_engine.execute('UPDATE "cargo" SET "itemID" = ? WHERE "itemID" = ?',
(replacement_item, retired_item))
|
gpl-3.0
|
[
624,
199,
9816,
1695,
199,
199,
13,
19107,
4621,
687,
2269,
644,
285,
667,
264,
10967,
83,
370,
5817,
18167,
199,
624,
199,
199,
1864,
26358,
275,
469,
272,
841,
821,
1479,
26,
334,
221,
327,
1952,
12416,
5817,
699,
13305,
473,
267,
1926,
1876,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
577,
65,
960,
8612,
473,
267,
14785,
1643,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
510,
13202,
11391,
677,
473,
267,
26485,
1465,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
820,
27703,
799,
3852,
473,
272,
2318,
272,
841,
10156,
18,
26,
334,
221,
327,
1952,
12416,
5817,
699,
13305,
473,
41,
267,
5685,
772,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
577,
65,
960,
8612,
473,
41,
267,
5685,
1272,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
510,
13202,
11391,
677,
473,
41,
267,
5685,
1272,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
820,
27703,
799,
3852,
473,
41,
272,
2318,
272,
841,
821,
1465,
26,
334,
221,
327,
17064,
5817,
699,
13305,
473,
267,
16814,
2528,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
18474,
8883,
12997,
473,
267,
14785,
1717,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
799,
388,
17954,
473,
267,
14785,
1690,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
662,
16728,
530,
17897,
73,
3822,
473,
272,
2318,
272,
841,
10156,
20,
26,
334,
221,
327,
17064,
5817,
699,
13305,
473,
41,
267,
841,
13731,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
662,
16728,
530,
17897,
73,
3822,
473,
41,
267,
841,
13299,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
799,
388,
17954,
473,
41,
267,
841,
12900,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
18474,
8883,
12997,
473,
41,
272,
2318,
272,
841,
821,
1398,
26,
334,
221,
327,
5244,
553,
5817,
699,
13305,
473,
267,
1784,
1194,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
23241,
5244,
553,
316,
473,
267,
24005,
1079,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
5244,
553,
25378,
2106,
9147,
473,
267,
26485,
1651,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
5244,
553,
662,
70,
17750,
473,
272,
2318,
272,
841,
10156,
21,
26,
334,
221,
327,
5244,
553,
5817,
699,
13305,
473,
41,
267,
5685,
1257,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
23241,
5244,
553,
316,
473,
41,
267,
841,
16450,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
5244,
553,
662,
70,
17750,
473,
41,
267,
5685,
1349,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
5244,
553,
25378,
2106,
9147,
473,
41,
272,
2318,
272,
841,
821,
1216,
26,
334,
221,
327,
29201,
723,
1292,
72,
5817,
699,
13305,
473,
267,
4119,
9570,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
6551,
26382,
4688,
16913,
14895,
473,
267,
1926,
2760,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
662,
4755,
1912,
4688,
16913,
14895,
473,
267,
14785,
2036,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
820,
27703,
21588,
7775,
473,
272,
2318,
272,
841,
10156,
22,
26,
334,
221,
327,
29201,
723,
1292,
72,
5817,
699,
13305,
473,
41,
267,
5685,
1184,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
662,
4755,
1912,
4688,
16913,
14895,
473,
41,
267,
5685,
1299,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
6551,
26382,
4688,
16913,
14895,
473,
41,
267,
841,
15117,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
820,
27703,
21588,
7775,
473,
41,
272,
2318,
272,
841,
821,
1651,
26,
334,
221,
327,
603,
7969,
21684,
1237,
699,
13305,
473,
267,
499,
2299,
19,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
25378,
26691,
8790,
28582,
4330,
662,
70,
17750,
473,
267,
28842,
1229,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
603,
7969,
7964,
332,
5024,
3447,
14666,
434,
473,
267,
499,
28656,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
7964,
332,
19246,
2072,
473,
272,
2318,
272,
841,
10156,
17,
26,
334,
221,
327,
603,
7969,
21684,
1237,
699,
13305,
473,
41,
267,
5685,
1342,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
25378,
26691,
8790,
28582,
4330,
662,
70,
17750,
473,
41,
267,
841,
13319,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
7964,
332,
19246,
2072,
473,
41,
267,
841,
13909,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
603,
7969,
7964,
332,
5024,
3447,
14666,
434,
473,
41,
272,
2318,
199,
93,
421,
199,
318,
10754,
8,
8420,
576,
63,
3908,
304,
272,
327,
7905,
4621,
272,
367,
8343,
63,
1053,
12,
769,
315,
1868,
26358,
14,
1744,
837,
267,
367,
295,
280,
581,
63,
1053,
315,
769,
26,
288,
6290,
576,
63,
3908,
14,
2526,
360,
10383,
298,
3112,
2,
11543,
298,
1053,
998,
2,
275,
5805,
6038,
298,
1053,
998,
2,
275,
5805,
297,
3660,
334,
15895,
63,
1053,
12,
295,
280,
581,
63,
1053,
430,
288,
6290,
576,
63,
3908,
14,
2526,
360,
10383,
298,
67,
16308,
2,
11543,
298,
1053,
998,
2,
275,
5805,
6038,
298,
1053,
998,
2,
275,
5805,
297,
3660,
334,
15895,
63,
1053,
12,
295,
280,
581,
63,
1053,
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
] |
[
199,
9816,
1695,
199,
199,
13,
19107,
4621,
687,
2269,
644,
285,
667,
264,
10967,
83,
370,
5817,
18167,
199,
624,
199,
199,
1864,
26358,
275,
469,
272,
841,
821,
1479,
26,
334,
221,
327,
1952,
12416,
5817,
699,
13305,
473,
267,
1926,
1876,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
577,
65,
960,
8612,
473,
267,
14785,
1643,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
510,
13202,
11391,
677,
473,
267,
26485,
1465,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
820,
27703,
799,
3852,
473,
272,
2318,
272,
841,
10156,
18,
26,
334,
221,
327,
1952,
12416,
5817,
699,
13305,
473,
41,
267,
5685,
772,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
577,
65,
960,
8612,
473,
41,
267,
5685,
1272,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
510,
13202,
11391,
677,
473,
41,
267,
5685,
1272,
12,
221,
327,
1952,
573,
581,
644,
285,
667,
264,
10967,
446,
820,
27703,
799,
3852,
473,
41,
272,
2318,
272,
841,
821,
1465,
26,
334,
221,
327,
17064,
5817,
699,
13305,
473,
267,
16814,
2528,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
18474,
8883,
12997,
473,
267,
14785,
1717,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
799,
388,
17954,
473,
267,
14785,
1690,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
662,
16728,
530,
17897,
73,
3822,
473,
272,
2318,
272,
841,
10156,
20,
26,
334,
221,
327,
17064,
5817,
699,
13305,
473,
41,
267,
841,
13731,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
662,
16728,
530,
17897,
73,
3822,
473,
41,
267,
841,
13299,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
799,
388,
17954,
473,
41,
267,
841,
12900,
12,
221,
327,
17064,
644,
285,
667,
264,
10967,
446,
18474,
8883,
12997,
473,
41,
272,
2318,
272,
841,
821,
1398,
26,
334,
221,
327,
5244,
553,
5817,
699,
13305,
473,
267,
1784,
1194,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
23241,
5244,
553,
316,
473,
267,
24005,
1079,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
5244,
553,
25378,
2106,
9147,
473,
267,
26485,
1651,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
5244,
553,
662,
70,
17750,
473,
272,
2318,
272,
841,
10156,
21,
26,
334,
221,
327,
5244,
553,
5817,
699,
13305,
473,
41,
267,
5685,
1257,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
23241,
5244,
553,
316,
473,
41,
267,
841,
16450,
12,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
5244,
553,
662,
70,
17750,
473,
41,
267,
5685,
1349,
221,
327,
428,
1873,
303,
644,
285,
667,
264,
10967,
446,
5244,
553,
25378,
2106,
9147,
473,
41,
272,
2318,
272,
841,
821,
1216,
26,
334,
221,
327,
29201,
723,
1292,
72,
5817,
699,
13305,
473,
267,
4119,
9570,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
6551,
26382,
4688,
16913,
14895,
473,
267,
1926,
2760,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
662,
4755,
1912,
4688,
16913,
14895,
473,
267,
14785,
2036,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
820,
27703,
21588,
7775,
473,
272,
2318,
272,
841,
10156,
22,
26,
334,
221,
327,
29201,
723,
1292,
72,
5817,
699,
13305,
473,
41,
267,
5685,
1184,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
662,
4755,
1912,
4688,
16913,
14895,
473,
41,
267,
5685,
1299,
12,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
6551,
26382,
4688,
16913,
14895,
473,
41,
267,
841,
15117,
221,
327,
29201,
723,
1292,
72,
644,
285,
667,
264,
10967,
446,
820,
27703,
21588,
7775,
473,
41,
272,
2318,
272,
841,
821,
1651,
26,
334,
221,
327,
603,
7969,
21684,
1237,
699,
13305,
473,
267,
499,
2299,
19,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
25378,
26691,
8790,
28582,
4330,
662,
70,
17750,
473,
267,
28842,
1229,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
603,
7969,
7964,
332,
5024,
3447,
14666,
434,
473,
267,
499,
28656,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
7964,
332,
19246,
2072,
473,
272,
2318,
272,
841,
10156,
17,
26,
334,
221,
327,
603,
7969,
21684,
1237,
699,
13305,
473,
41,
267,
5685,
1342,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
25378,
26691,
8790,
28582,
4330,
662,
70,
17750,
473,
41,
267,
841,
13319,
12,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
7964,
332,
19246,
2072,
473,
41,
267,
841,
13909,
221,
327,
603,
7969,
21684,
1237,
10967,
446,
603,
7969,
7964,
332,
5024,
3447,
14666,
434,
473,
41,
272,
2318,
199,
93,
421,
199,
318,
10754,
8,
8420,
576,
63,
3908,
304,
272,
327,
7905,
4621,
272,
367,
8343,
63,
1053,
12,
769,
315,
1868,
26358,
14,
1744,
837,
267,
367,
295,
280,
581,
63,
1053,
315,
769,
26,
288,
6290,
576,
63,
3908,
14,
2526,
360,
10383,
298,
3112,
2,
11543,
298,
1053,
998,
2,
275,
5805,
6038,
298,
1053,
998,
2,
275,
5805,
297,
3660,
334,
15895,
63,
1053,
12,
295,
280,
581,
63,
1053,
430,
288,
6290,
576,
63,
3908,
14,
2526,
360,
10383,
298,
67,
16308,
2,
11543,
298,
1053,
998,
2,
275,
5805,
6038,
298,
1053,
998,
2,
275,
5805,
297,
3660,
334,
15895,
63,
1053,
12,
295,
280,
581,
63,
1053,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mattmccarthy11/vidly-development
|
mediadrop/migrations/versions/003-4d27ff5680e5-normalize_comment_approval_setting.py
|
10
|
2516
|
# This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2015 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) any later version.
# See LICENSE.txt in the main project directory, for more information.
"""Normalize comment approval setting
normalize value for comment approval setting so that it can be used a boolean
directly. This migration can not be run offline.
added: 2011-03-13 (v0.9.1)
previously migrate script v053
Revision ID: 4d27ff5680e5
Revises: 432df7befe8d
Create Date: 2013-05-14 22:36:27.130301
"""
# revision identifiers, used by Alembic.
revision = '4d27ff5680e5'
down_revision = '432df7befe8d'
from alembic import context
from alembic.op import execute, inline_literal
from sqlalchemy import Integer, Unicode, UnicodeText
from sqlalchemy import Column, MetaData, Table
# -- table definition ---------------------------------------------------------
metadata = MetaData()
settings = Table('settings', metadata,
Column('id', Integer, autoincrement=True, primary_key=True),
Column('key', Unicode(255), nullable=False, unique=True),
Column('value', UnicodeText),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
# -- helpers ------------------------------------------------------------------
def insert_setting(key, value):
execute(
settings.insert().\
values({
'key': inline_literal(key),
'value': inline_literal(value),
})
)
def delete_setting(key):
execute(
settings.delete().\
where(settings.c.key==inline_literal(key))
)
# -----------------------------------------------------------------------------
SETTING_KEY = u'req_comment_approval'
def upgrade():
if context.is_offline_mode():
raise AssertionError('This migration can not be run in offline mode.')
connection = context.get_context().connection
query = settings.select(settings.c.key == SETTING_KEY)
result = connection.execute(query).fetchone()
current_value = result.value
if current_value == u'true':
new_value = u'True'
else:
new_value = u''
execute(
settings.update().\
where(settings.c.key==inline_literal(SETTING_KEY)).\
values({
'value': inline_literal(new_value),
})
)
def downgrade():
# no action necessary
pass
|
gpl-3.0
|
[
3,
961,
570,
365,
282,
1777,
402,
12300,
11070,
334,
1014,
921,
1544,
14,
3700,
350,
2675,
14,
846,
395,
199,
3,
1898,
8937,
13,
7806,
12300,
11070,
8417,
199,
3,
2104,
314,
5835,
406,
15980,
7994,
12,
1937,
314,
6135,
6974,
943,
14,
199,
3,
710,
1350,
1233,
10470,
315,
642,
570,
365,
18233,
1334,
314,
14629,
86,
19,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
1666,
5113,
14,
2424,
315,
314,
2446,
2199,
2082,
12,
367,
1655,
2556,
14,
199,
624,
22580,
3721,
4286,
637,
4260,
199,
199,
7721,
574,
367,
3721,
4286,
637,
4260,
880,
626,
652,
883,
506,
1202,
282,
5046,
221,
199,
2275,
590,
14,
961,
8367,
883,
440,
506,
1255,
26302,
14,
199,
199,
3270,
26,
7760,
13,
1644,
13,
969,
334,
86,
16,
14,
25,
14,
17,
9,
199,
6352,
590,
12810,
2884,
373,
20454,
199,
199,
12714,
2870,
26,
841,
68,
1465,
556,
1367,
1257,
69,
21,
199,
497,
433,
874,
26,
841,
708,
1587,
23,
1235,
771,
24,
68,
199,
2499,
6148,
26,
6171,
13,
1717,
13,
1079,
6928,
26,
1344,
26,
1465,
14,
969,
1644,
614,
199,
624,
199,
199,
3,
6974,
14154,
12,
1202,
701,
6832,
20596,
14,
199,
5792,
275,
283,
20,
68,
1465,
556,
1367,
1257,
69,
21,
7,
199,
2110,
63,
5792,
275,
283,
10657,
1587,
23,
1235,
771,
24,
68,
7,
199,
199,
504,
30960,
20596,
492,
1067,
199,
504,
30960,
20596,
14,
411,
492,
5341,
12,
8308,
63,
8939,
199,
504,
8335,
492,
7225,
12,
6140,
12,
6140,
1872,
199,
504,
8335,
492,
4996,
12,
24905,
12,
221,
6957,
199,
199,
3,
1553,
1817,
5492,
9527,
9960,
199,
2343,
275,
24905,
342,
199,
1751,
275,
6957,
360,
1751,
297,
3341,
12,
272,
4996,
360,
344,
297,
7225,
12,
32497,
29,
549,
12,
5062,
63,
498,
29,
549,
395,
272,
4996,
360,
498,
297,
6140,
8,
2299,
395,
7854,
29,
797,
12,
3747,
29,
549,
395,
272,
4996,
360,
585,
297,
6140,
1872,
395,
272,
12896,
63,
3908,
534,
607,
889,
2846,
297,
272,
12896,
63,
6043,
534,
1624,
24,
297,
199,
9,
199,
199,
3,
1553,
10897,
5620,
306,
199,
318,
5518,
63,
6031,
8,
498,
12,
574,
304,
272,
5341,
8,
267,
2202,
14,
3176,
1252,
60,
288,
1338,
2561,
355,
283,
498,
356,
8308,
63,
8939,
8,
498,
395,
355,
283,
585,
356,
8308,
63,
8939,
8,
585,
395,
288,
3828,
272,
776,
199,
199,
318,
3145,
63,
6031,
8,
498,
304,
272,
5341,
8,
267,
2202,
14,
1807,
1252,
60,
288,
2382,
8,
1751,
14,
67,
14,
498,
389,
6460,
63,
8939,
8,
498,
430,
272,
776,
199,
3,
13722,
199,
199,
12490,
1206,
63,
3078,
275,
399,
3984,
81,
63,
3349,
63,
28302,
7,
421,
199,
318,
10754,
837,
272,
340,
1067,
14,
374,
63,
18430,
63,
632,
837,
267,
746,
9070,
360,
2765,
8367,
883,
440,
506,
1255,
315,
26302,
818,
2659,
272,
1950,
275,
1067,
14,
362,
63,
1100,
1252,
2105,
272,
1827,
275,
2202,
14,
2416,
8,
1751,
14,
67,
14,
498,
508,
11543,
52,
1206,
63,
3078,
9,
272,
754,
275,
1950,
14,
2526,
8,
1131,
680,
11591,
342,
2286,
1453,
63,
585,
275,
754,
14,
585,
272,
340,
1453,
63,
585,
508,
399,
1133,
431,
356,
267,
892,
63,
585,
275,
399,
7,
549,
7,
272,
587,
26,
267,
892,
63,
585,
275,
399,
891,
272,
5341,
8,
267,
2202,
14,
873,
1252,
60,
288,
2382,
8,
1751,
14,
67,
14,
498,
389,
6460,
63,
8939,
8,
12490,
1206,
63,
3078,
430,
3134,
288,
1338,
2561,
355,
283,
585,
356,
8308,
63,
8939,
8,
1222,
63,
585,
395,
288,
3828,
272,
776,
199,
199,
318,
32498,
837,
272,
327,
949,
1595,
5784,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
570,
365,
282,
1777,
402,
12300,
11070,
334,
1014,
921,
1544,
14,
3700,
350,
2675,
14,
846,
395,
199,
3,
1898,
8937,
13,
7806,
12300,
11070,
8417,
199,
3,
2104,
314,
5835,
406,
15980,
7994,
12,
1937,
314,
6135,
6974,
943,
14,
199,
3,
710,
1350,
1233,
10470,
315,
642,
570,
365,
18233,
1334,
314,
14629,
86,
19,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
1666,
5113,
14,
2424,
315,
314,
2446,
2199,
2082,
12,
367,
1655,
2556,
14,
199,
624,
22580,
3721,
4286,
637,
4260,
199,
199,
7721,
574,
367,
3721,
4286,
637,
4260,
880,
626,
652,
883,
506,
1202,
282,
5046,
221,
199,
2275,
590,
14,
961,
8367,
883,
440,
506,
1255,
26302,
14,
199,
199,
3270,
26,
7760,
13,
1644,
13,
969,
334,
86,
16,
14,
25,
14,
17,
9,
199,
6352,
590,
12810,
2884,
373,
20454,
199,
199,
12714,
2870,
26,
841,
68,
1465,
556,
1367,
1257,
69,
21,
199,
497,
433,
874,
26,
841,
708,
1587,
23,
1235,
771,
24,
68,
199,
2499,
6148,
26,
6171,
13,
1717,
13,
1079,
6928,
26,
1344,
26,
1465,
14,
969,
1644,
614,
199,
624,
199,
199,
3,
6974,
14154,
12,
1202,
701,
6832,
20596,
14,
199,
5792,
275,
283,
20,
68,
1465,
556,
1367,
1257,
69,
21,
7,
199,
2110,
63,
5792,
275,
283,
10657,
1587,
23,
1235,
771,
24,
68,
7,
199,
199,
504,
30960,
20596,
492,
1067,
199,
504,
30960,
20596,
14,
411,
492,
5341,
12,
8308,
63,
8939,
199,
504,
8335,
492,
7225,
12,
6140,
12,
6140,
1872,
199,
504,
8335,
492,
4996,
12,
24905,
12,
221,
6957,
199,
199,
3,
1553,
1817,
5492,
9527,
9960,
199,
2343,
275,
24905,
342,
199,
1751,
275,
6957,
360,
1751,
297,
3341,
12,
272,
4996,
360,
344,
297,
7225,
12,
32497,
29,
549,
12,
5062,
63,
498,
29,
549,
395,
272,
4996,
360,
498,
297,
6140,
8,
2299,
395,
7854,
29,
797,
12,
3747,
29,
549,
395,
272,
4996,
360,
585,
297,
6140,
1872,
395,
272,
12896,
63,
3908,
534,
607,
889,
2846,
297,
272,
12896,
63,
6043,
534,
1624,
24,
297,
199,
9,
199,
199,
3,
1553,
10897,
5620,
306,
199,
318,
5518,
63,
6031,
8,
498,
12,
574,
304,
272,
5341,
8,
267,
2202,
14,
3176,
1252,
60,
288,
1338,
2561,
355,
283,
498,
356,
8308,
63,
8939,
8,
498,
395,
355,
283,
585,
356,
8308,
63,
8939,
8,
585,
395,
288,
3828,
272,
776,
199,
199,
318,
3145,
63,
6031,
8,
498,
304,
272,
5341,
8,
267,
2202,
14,
1807,
1252,
60,
288,
2382,
8,
1751,
14,
67,
14,
498,
389,
6460,
63,
8939,
8,
498,
430,
272,
776,
199,
3,
13722,
199,
199,
12490,
1206,
63,
3078,
275,
399,
3984,
81,
63,
3349,
63,
28302,
7,
421,
199,
318,
10754,
837,
272,
340,
1067,
14,
374,
63,
18430,
63,
632,
837,
267,
746,
9070,
360,
2765,
8367,
883,
440,
506,
1255,
315,
26302,
818,
2659,
272,
1950,
275,
1067,
14,
362,
63,
1100,
1252,
2105,
272,
1827,
275,
2202,
14,
2416,
8,
1751,
14,
67,
14,
498,
508,
11543,
52,
1206,
63,
3078,
9,
272,
754,
275,
1950,
14,
2526,
8,
1131,
680,
11591,
342,
2286,
1453,
63,
585,
275,
754,
14,
585,
272,
340,
1453,
63,
585,
508,
399,
1133,
431,
356,
267,
892,
63,
585,
275,
399,
7,
549,
7,
272,
587,
26,
267,
892,
63,
585,
275,
399,
891,
272,
5341,
8,
267,
2202,
14,
873,
1252,
60,
288,
2382,
8,
1751,
14,
67,
14,
498,
389,
6460,
63,
8939,
8,
12490,
1206,
63,
3078,
430,
3134,
288,
1338,
2561,
355,
283,
585,
356,
8308,
63,
8939,
8,
1222,
63,
585,
395,
288,
3828,
272,
776,
199,
199,
318,
32498,
837,
272,
327,
949,
1595,
5784,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
carlye566/IoT-POX
|
pox/py.py
|
41
|
3883
|
# Copyright 2012 James McCauley
#
# 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.
"""
Provides a Python interpreter while running POX
"""
from __future__ import print_function
from pox.core import core
from pox.lib.util import str_to_bool
import time
def _monkeypatch_console ():
"""
The readline in pypy (which is the readline from pyrepl) turns off output
postprocessing, which disables normal NL->CRLF translation. An effect of
this is that output *from other threads* (like log messages) which try to
print newlines end up just getting linefeeds and the output is all stair-
stepped. We monkeypatch the function in pyrepl which disables OPOST to
turn OPOST back on again. This doesn't immediately seem to break
anything in the simple cases, and makes the console reasonable to use
in pypy.
"""
try:
import termios
import sys
import pyrepl.unix_console
uc = pyrepl.unix_console.UnixConsole
old = uc.prepare
def prep (self):
old(self)
f = sys.stdin.fileno()
a = termios.tcgetattr(f)
a[1] |= 1 # Turn on postprocessing (OPOST)
termios.tcsetattr(f, termios.TCSANOW, a)
uc.prepare = prep
except:
pass
class Interactive (object):
"""
This is how other applications can interact with the interpreter.
At the moment, it's really limited.
"""
def __init__ (self):
core.register("Interactive", self)
self.enabled = False
self.completion = False
#import pox.license
import sys
self.variables = dict(locals())
self.variables['core'] = core
class pox_exit (object):
def __call__ (self, code = 0):
core.quit()
sys.exit(code)
def __repr__ (self):
return "Use exit() or Ctrl-D (i.e. EOF) to exit POX"
self.variables['exit'] = pox_exit()
self.running = False
# def start (event):
# if core.Interactive.enabled is not True: return
# import threading
# t = threading.Thread(target=self.interact)
# t.start()
# core.addListenerByName("UpEvent", start)
def interact (self):
""" Begin user interaction """
if self.completion:
import readline, rlcompleter
ns = globals().copy()
ns.update(self.variables)
# Note that things added to self.variables later won't be available.
# To fix this, make a dict proxy that actually reads from self.variables
# *and* globals().
readline.set_completer(rlcompleter.Completer(ns).complete)
readline.parse_and_bind("tab: complete")
_monkeypatch_console()
#print("This program comes with ABSOLUTELY NO WARRANTY. This program " \
# "is free software,")
#print("and you are welcome to redistribute it under certain conditions.")
#print("Type 'help(pox.license)' for details.")
time.sleep(1)
import code
import sys
sys.ps1 = "POX> "
sys.ps2 = " ... "
self.running = True
code.interact('Ready.', local=self.variables)
self.running = False
core.quit()
def launch (disable = False, completion = None, __INSTANCE__ = None):
if not core.hasComponent("Interactive"):
Interactive()
import boot
if not disable:
boot.set_main_function(core.Interactive.interact)
else:
boot.set_main_function(None)
core.Interactive.enabled = not disable
if completion is not None:
core.Interactive.completion = str_to_bool(completion)
|
apache-2.0
|
[
3,
1898,
6029,
1603,
14015,
22895,
3630,
443,
89,
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,
26,
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,
17473,
282,
2018,
12693,
1830,
3879,
3625,
56,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
1115,
88,
14,
1018,
492,
6170,
199,
504,
1115,
88,
14,
773,
14,
1974,
492,
620,
63,
475,
63,
2245,
199,
646,
900,
199,
199,
318,
485,
20372,
2068,
63,
6614,
23390,
523,
408,
523,
710,
14441,
315,
1134,
647,
334,
6777,
365,
314,
14441,
687,
1134,
16349,
9,
25449,
2331,
1072,
523,
2963,
6338,
12,
1314,
28421,
3293,
24719,
5118,
35,
20190,
7761,
14,
221,
1626,
7763,
402,
523,
642,
365,
626,
1072,
627,
504,
1163,
7183,
10,
334,
2930,
943,
3788,
9,
1314,
862,
370,
523,
870,
14930,
1284,
1536,
2951,
10232,
1004,
11522,
436,
314,
1072,
365,
1006,
2612,
723,
13,
523,
3650,
1915,
14,
221,
2136,
17309,
314,
805,
315,
1134,
16349,
1314,
28421,
593,
4030,
370,
523,
7485,
593,
4030,
1771,
641,
4020,
14,
221,
961,
3181,
1133,
9939,
17021,
370,
2059,
523,
7003,
315,
314,
3486,
5560,
12,
436,
7704,
314,
8559,
23255,
370,
675,
523,
315,
1134,
647,
14,
523,
408,
523,
862,
26,
272,
492,
28725,
272,
492,
984,
272,
492,
1134,
16349,
14,
11864,
63,
6614,
272,
399,
67,
275,
1134,
16349,
14,
11864,
63,
6614,
14,
21607,
9270,
272,
2269,
275,
399,
67,
14,
6726,
272,
347,
19986,
334,
277,
304,
489,
2269,
8,
277,
9,
489,
289,
275,
984,
14,
6626,
14,
9843,
342,
489,
282,
275,
28725,
14,
3641,
5675,
8,
70,
9,
489,
282,
59,
17,
61,
8901,
413,
327,
16147,
641,
2963,
6338,
334,
47,
4030,
9,
489,
28725,
14,
3641,
10202,
8,
70,
12,
28725,
14,
52,
3298,
879,
19716,
12,
282,
9,
272,
399,
67,
14,
6726,
275,
19986,
523,
871,
26,
272,
986,
421,
199,
533,
1010,
7502,
334,
785,
304,
523,
408,
523,
961,
365,
4212,
1163,
13103,
883,
17232,
543,
314,
12693,
14,
819,
2854,
314,
12427,
12,
652,
1159,
7710,
13988,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
304,
272,
6170,
14,
2683,
480,
23879,
401,
291,
9,
272,
291,
14,
3827,
275,
756,
272,
291,
14,
13207,
275,
756,
339,
327,
646,
1115,
88,
14,
1682,
272,
492,
984,
272,
291,
14,
3669,
275,
1211,
8,
9350,
1012,
272,
291,
14,
3669,
459,
1018,
418,
275,
6170,
339,
1021,
1115,
88,
63,
2224,
334,
785,
304,
489,
347,
636,
1250,
363,
334,
277,
12,
1233,
275,
378,
304,
267,
6170,
14,
10589,
342,
267,
984,
14,
2224,
8,
600,
9,
489,
347,
636,
2722,
363,
334,
277,
304,
267,
372,
298,
6119,
4458,
342,
503,
445,
7245,
13,
36,
334,
73,
14,
69,
14,
9027,
9,
370,
4458,
3625,
56,
2,
272,
291,
14,
3669,
459,
2224,
418,
275,
1115,
88,
63,
2224,
342,
339,
291,
14,
5720,
275,
756,
199,
199,
3,
259,
347,
1343,
334,
1430,
304,
199,
3,
420,
340,
6170,
14,
23879,
14,
3827,
365,
440,
715,
26,
372,
199,
3,
420,
492,
5796,
199,
3,
420,
307,
275,
5796,
14,
4436,
8,
1375,
29,
277,
14,
25850,
9,
199,
3,
420,
307,
14,
928,
342,
199,
3,
259,
6170,
14,
525,
10464,
11190,
480,
1721,
2390,
401,
1343,
9,
819,
347,
17232,
334,
277,
304,
272,
408,
25754,
922,
18752,
408,
339,
340,
291,
14,
13207,
26,
489,
492,
14441,
12,
25717,
18452,
489,
700,
275,
7992,
1252,
1574,
342,
489,
700,
14,
873,
8,
277,
14,
3669,
9,
489,
327,
3390,
626,
7645,
3483,
370,
291,
14,
3669,
2945,
7859,
1133,
506,
2808,
14,
489,
327,
4005,
5325,
642,
12,
1852,
282,
1211,
4566,
626,
5965,
11597,
687,
291,
14,
3669,
489,
327,
627,
460,
10,
7992,
1252,
489,
14441,
14,
409,
63,
18452,
8,
4308,
18452,
14,
6600,
351,
8,
561,
680,
4883,
9,
489,
14441,
14,
1122,
63,
460,
63,
3409,
480,
2902,
26,
4890,
531,
339,
485,
20372,
2068,
63,
6614,
342,
339,
327,
1361,
480,
2765,
2240,
12477,
543,
437,
11087,
2228,
934,
2901,
57,
4825,
3408,
14,
221,
961,
2240,
298,
971,
272,
327,
420,
298,
374,
2867,
2032,
12,
531,
272,
327,
1361,
480,
460,
1265,
787,
336,
14628,
370,
3604,
652,
1334,
9842,
3704,
2685,
272,
327,
1361,
480,
804,
283,
3437,
8,
555,
88,
14,
1682,
3171,
367,
2436,
2685,
272,
900,
14,
4532,
8,
17,
9,
339,
492,
1233,
272,
492,
984,
272,
984,
14,
1190,
17,
275,
298,
1512,
56,
30,
298,
272,
984,
14,
1190,
18,
275,
298,
2263,
298,
272,
291,
14,
5720,
275,
715,
272,
1233,
14,
25850,
360,
17960,
3130,
2257,
29,
277,
14,
3669,
9,
272,
291,
14,
5720,
275,
756,
272,
6170,
14,
10589,
342,
421,
199,
318,
10623,
334,
5993,
275,
756,
12,
13659,
275,
488,
12,
636,
18235,
363,
275,
488,
304,
523,
340,
440,
6170,
14,
1989,
7004,
480,
23879,
2349,
272,
1010,
7502,
342,
819,
492,
8498,
523,
340,
440,
3507,
26,
272,
8498,
14,
409,
63,
973,
63,
1593,
8,
1018,
14,
23879,
14,
25850,
9,
523,
587,
26,
272,
8498,
14,
409,
63,
973,
63,
1593,
8,
403,
9,
523,
6170,
14,
23879,
14,
3827,
275,
440,
3507,
523,
340,
13659,
365,
440,
488,
26,
272,
6170,
14,
23879,
14,
13207,
275,
620,
63,
475,
63,
2245,
8,
13207,
9,
199,
32768,
32768,
32768
] |
[
1898,
6029,
1603,
14015,
22895,
3630,
443,
89,
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,
26,
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,
17473,
282,
2018,
12693,
1830,
3879,
3625,
56,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
1115,
88,
14,
1018,
492,
6170,
199,
504,
1115,
88,
14,
773,
14,
1974,
492,
620,
63,
475,
63,
2245,
199,
646,
900,
199,
199,
318,
485,
20372,
2068,
63,
6614,
23390,
523,
408,
523,
710,
14441,
315,
1134,
647,
334,
6777,
365,
314,
14441,
687,
1134,
16349,
9,
25449,
2331,
1072,
523,
2963,
6338,
12,
1314,
28421,
3293,
24719,
5118,
35,
20190,
7761,
14,
221,
1626,
7763,
402,
523,
642,
365,
626,
1072,
627,
504,
1163,
7183,
10,
334,
2930,
943,
3788,
9,
1314,
862,
370,
523,
870,
14930,
1284,
1536,
2951,
10232,
1004,
11522,
436,
314,
1072,
365,
1006,
2612,
723,
13,
523,
3650,
1915,
14,
221,
2136,
17309,
314,
805,
315,
1134,
16349,
1314,
28421,
593,
4030,
370,
523,
7485,
593,
4030,
1771,
641,
4020,
14,
221,
961,
3181,
1133,
9939,
17021,
370,
2059,
523,
7003,
315,
314,
3486,
5560,
12,
436,
7704,
314,
8559,
23255,
370,
675,
523,
315,
1134,
647,
14,
523,
408,
523,
862,
26,
272,
492,
28725,
272,
492,
984,
272,
492,
1134,
16349,
14,
11864,
63,
6614,
272,
399,
67,
275,
1134,
16349,
14,
11864,
63,
6614,
14,
21607,
9270,
272,
2269,
275,
399,
67,
14,
6726,
272,
347,
19986,
334,
277,
304,
489,
2269,
8,
277,
9,
489,
289,
275,
984,
14,
6626,
14,
9843,
342,
489,
282,
275,
28725,
14,
3641,
5675,
8,
70,
9,
489,
282,
59,
17,
61,
8901,
413,
327,
16147,
641,
2963,
6338,
334,
47,
4030,
9,
489,
28725,
14,
3641,
10202,
8,
70,
12,
28725,
14,
52,
3298,
879,
19716,
12,
282,
9,
272,
399,
67,
14,
6726,
275,
19986,
523,
871,
26,
272,
986,
421,
199,
533,
1010,
7502,
334,
785,
304,
523,
408,
523,
961,
365,
4212,
1163,
13103,
883,
17232,
543,
314,
12693,
14,
819,
2854,
314,
12427,
12,
652,
1159,
7710,
13988,
14,
523,
408,
523,
347,
636,
826,
363,
334,
277,
304,
272,
6170,
14,
2683,
480,
23879,
401,
291,
9,
272,
291,
14,
3827,
275,
756,
272,
291,
14,
13207,
275,
756,
339,
327,
646,
1115,
88,
14,
1682,
272,
492,
984,
272,
291,
14,
3669,
275,
1211,
8,
9350,
1012,
272,
291,
14,
3669,
459,
1018,
418,
275,
6170,
339,
1021,
1115,
88,
63,
2224,
334,
785,
304,
489,
347,
636,
1250,
363,
334,
277,
12,
1233,
275,
378,
304,
267,
6170,
14,
10589,
342,
267,
984,
14,
2224,
8,
600,
9,
489,
347,
636,
2722,
363,
334,
277,
304,
267,
372,
298,
6119,
4458,
342,
503,
445,
7245,
13,
36,
334,
73,
14,
69,
14,
9027,
9,
370,
4458,
3625,
56,
2,
272,
291,
14,
3669,
459,
2224,
418,
275,
1115,
88,
63,
2224,
342,
339,
291,
14,
5720,
275,
756,
199,
199,
3,
259,
347,
1343,
334,
1430,
304,
199,
3,
420,
340,
6170,
14,
23879,
14,
3827,
365,
440,
715,
26,
372,
199,
3,
420,
492,
5796,
199,
3,
420,
307,
275,
5796,
14,
4436,
8,
1375,
29,
277,
14,
25850,
9,
199,
3,
420,
307,
14,
928,
342,
199,
3,
259,
6170,
14,
525,
10464,
11190,
480,
1721,
2390,
401,
1343,
9,
819,
347,
17232,
334,
277,
304,
272,
408,
25754,
922,
18752,
408,
339,
340,
291,
14,
13207,
26,
489,
492,
14441,
12,
25717,
18452,
489,
700,
275,
7992,
1252,
1574,
342,
489,
700,
14,
873,
8,
277,
14,
3669,
9,
489,
327,
3390,
626,
7645,
3483,
370,
291,
14,
3669,
2945,
7859,
1133,
506,
2808,
14,
489,
327,
4005,
5325,
642,
12,
1852,
282,
1211,
4566,
626,
5965,
11597,
687,
291,
14,
3669,
489,
327,
627,
460,
10,
7992,
1252,
489,
14441,
14,
409,
63,
18452,
8,
4308,
18452,
14,
6600,
351,
8,
561,
680,
4883,
9,
489,
14441,
14,
1122,
63,
460,
63,
3409,
480,
2902,
26,
4890,
531,
339,
485,
20372,
2068,
63,
6614,
342,
339,
327,
1361,
480,
2765,
2240,
12477,
543,
437,
11087,
2228,
934,
2901,
57,
4825,
3408,
14,
221,
961,
2240,
298,
971,
272,
327,
420,
298,
374,
2867,
2032,
12,
531,
272,
327,
1361,
480,
460,
1265,
787,
336,
14628,
370,
3604,
652,
1334,
9842,
3704,
2685,
272,
327,
1361,
480,
804,
283,
3437,
8,
555,
88,
14,
1682,
3171,
367,
2436,
2685,
272,
900,
14,
4532,
8,
17,
9,
339,
492,
1233,
272,
492,
984,
272,
984,
14,
1190,
17,
275,
298,
1512,
56,
30,
298,
272,
984,
14,
1190,
18,
275,
298,
2263,
298,
272,
291,
14,
5720,
275,
715,
272,
1233,
14,
25850,
360,
17960,
3130,
2257,
29,
277,
14,
3669,
9,
272,
291,
14,
5720,
275,
756,
272,
6170,
14,
10589,
342,
421,
199,
318,
10623,
334,
5993,
275,
756,
12,
13659,
275,
488,
12,
636,
18235,
363,
275,
488,
304,
523,
340,
440,
6170,
14,
1989,
7004,
480,
23879,
2349,
272,
1010,
7502,
342,
819,
492,
8498,
523,
340,
440,
3507,
26,
272,
8498,
14,
409,
63,
973,
63,
1593,
8,
1018,
14,
23879,
14,
25850,
9,
523,
587,
26,
272,
8498,
14,
409,
63,
973,
63,
1593,
8,
403,
9,
523,
6170,
14,
23879,
14,
3827,
275,
440,
3507,
523,
340,
13659,
365,
440,
488,
26,
272,
6170,
14,
23879,
14,
13207,
275,
620,
63,
475,
63,
2245,
8,
13207,
9,
199,
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,
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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,
0,
0,
0
] |
gwpy/gwpy
|
gwpy/timeseries/tests/test_io_gwf_lalframe.py
|
3
|
4751
|
# -*- coding: utf-8 -*-
# Copyright (C) Duncan Macleod (2014-2020)
#
# This file is part of GWpy.
#
# GWpy 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.
#
# GWpy 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 GWpy. If not, see <http://www.gnu.org/licenses/>.
"""Tests for :mod:`gwpy.timeseries.io.gwf.lalframe`
"""
from pathlib import Path
from urllib.parse import urlparse
import pytest
from gwdatafind.utils import file_segment
from ...io.cache import write_cache
from ...testing.utils import (
assert_dict_equal,
assert_quantity_sub_equal,
skip_missing_dependency,
TemporaryFilename,
TEST_GWF_FILE,
)
from ...timeseries import TimeSeries
# import optional dependencies
lal_utils = pytest.importorskip("lal.utils")
lalframe = pytest.importorskip("lalframe")
gwpy_lalframe = pytest.importorskip("gwpy.timeseries.io.gwf.lalframe")
# get URI to test against
TEST_GWF_PATH = Path(TEST_GWF_FILE).absolute()
TEST_GWF_URL = TEST_GWF_PATH.as_uri()
# get epoch corresponding to this file
TEST_GWF_SEGMENT = file_segment(TEST_GWF_FILE)
# channels to read
CHANNELS = ["H1:LDAS-STRAIN", "L1:LDAS-STRAIN", "V1:h_16384Hz"]
@pytest.fixture
def stream():
return lalframe.FrStreamOpen(str(TEST_GWF_PATH.parent), TEST_GWF_PATH.name)
def _test_open_data_source(source):
"""This function actually performs the test
"""
stream = gwpy_lalframe.open_data_source(source)
assert stream.epoch == TEST_GWF_SEGMENT[0]
assert TEST_GWF_PATH == Path(
urlparse(stream.cache.list.url).path
).absolute()
@pytest.mark.parametrize("source", [
TEST_GWF_FILE,
TEST_GWF_URL,
[TEST_GWF_FILE],
lal_utils.CacheEntry.from_T050017(TEST_GWF_FILE),
])
def test_open_data_source(source):
return _test_open_data_source(source)
@skip_missing_dependency("glue.lal")
def test_open_data_source_glue():
from glue.lal import Cache
Cache.entry_class = lal_utils.CacheEntry
cache = Cache.from_urls([TEST_GWF_FILE])
return _test_open_data_source(cache)
def test_open_data_source_cache():
with TemporaryFilename(".lcf") as cache:
write_cache([TEST_GWF_FILE], cache, format="lal")
return _test_open_data_source(cache)
def test_open_data_source_error():
with pytest.raises(ValueError) as exc:
gwpy_lalframe.open_data_source(None)
assert str(exc.value) == (
"Don't know how to open data source of type {}".format(type(None))
)
def test_get_stream_duration(stream):
assert gwpy_lalframe.get_stream_duration(stream) == 1.
@pytest.mark.parametrize("start, end", [
(None, None),
(None, TEST_GWF_SEGMENT[0] + .5),
(TEST_GWF_SEGMENT[0] + .5, None),
(TEST_GWF_SEGMENT[0] + .25, TEST_GWF_SEGMENT[1] - .25)
])
def test_read(start, end):
data = gwpy_lalframe.read(
TEST_GWF_FILE,
CHANNELS,
start=start,
end=end,
)
assert isinstance(data, dict)
start = TEST_GWF_SEGMENT[0] if start is None else start
end = TEST_GWF_SEGMENT[1] if end is None else end
for name in CHANNELS:
ts = data[name]
# check basic parameters
assert ts.sample_rate.value == 16384
assert ts.name == name
assert ts.channel.name == name
# check data span is what we asked for
assert ts.xspan == (start, end)
def test_read_channel_error():
with pytest.raises(RuntimeError) as exc:
gwpy_lalframe.read(TEST_GWF_FILE, ["bad"])
assert str(exc.value) == "channel 'bad' not found"
def test_read_deprecated_scaled():
with pytest.warns(UserWarning):
gwpy_lalframe.read(
TEST_GWF_FILE,
["L1:LDAS-STRAIN"],
scaled=True,
)
def test_write():
# read the data first
data = gwpy_lalframe.read(TEST_GWF_FILE, CHANNELS)
with TemporaryFilename() as tmp:
# write the data
gwpy_lalframe.write(
data,
tmp,
)
# read it back and check things
data2 = gwpy_lalframe.read(tmp, CHANNELS)
assert_dict_equal(data, data2, assert_quantity_sub_equal)
def test_write_no_ifo():
# create timeseries with no IFO
data = TimeSeries([1, 2, 3, 4, 5])
with TemporaryFilename() as tmp:
gwpy_lalframe.write(
{None: data},
tmp
)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
35,
9,
577,
1097,
290,
10444,
274,
364,
334,
7280,
13,
13934,
9,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
598,
55,
647,
14,
199,
3,
199,
3,
598,
55,
647,
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,
598,
55,
647,
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,
598,
55,
647,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
2925,
367,
520,
1494,
1705,
8392,
647,
14,
28551,
14,
2308,
14,
8392,
70,
14,
416,
276,
1186,
64,
199,
624,
199,
199,
504,
32212,
492,
6912,
199,
504,
4011,
14,
1122,
492,
7097,
199,
199,
646,
4613,
199,
199,
504,
22192,
576,
1623,
14,
1208,
492,
570,
63,
9255,
199,
199,
504,
2263,
2308,
14,
1637,
492,
2218,
63,
1637,
199,
504,
2263,
4776,
14,
1208,
492,
334,
272,
702,
63,
807,
63,
1452,
12,
272,
702,
63,
10577,
63,
954,
63,
1452,
12,
272,
3372,
63,
4752,
63,
8575,
12,
272,
21791,
8117,
12,
272,
7393,
63,
19674,
38,
63,
3817,
12,
199,
9,
199,
504,
2263,
28551,
492,
4703,
9641,
199,
199,
3,
492,
2716,
5124,
199,
76,
279,
63,
1208,
275,
4613,
14,
646,
269,
2759,
480,
76,
279,
14,
1208,
531,
199,
416,
276,
1186,
275,
4613,
14,
646,
269,
2759,
480,
416,
276,
1186,
531,
199,
8392,
647,
63,
416,
276,
1186,
275,
4613,
14,
646,
269,
2759,
480,
8392,
647,
14,
28551,
14,
2308,
14,
8392,
70,
14,
416,
276,
1186,
531,
199,
199,
3,
664,
9022,
370,
511,
6169,
199,
2864,
63,
19674,
38,
63,
3243,
275,
6912,
8,
2864,
63,
19674,
38,
63,
3817,
680,
6116,
342,
199,
2864,
63,
19674,
38,
63,
2632,
275,
7393,
63,
19674,
38,
63,
3243,
14,
305,
63,
2302,
342,
199,
199,
3,
664,
9463,
5226,
370,
642,
570,
199,
2864,
63,
19674,
38,
63,
27001,
275,
570,
63,
9255,
8,
2864,
63,
19674,
38,
63,
3817,
9,
199,
199,
3,
9245,
370,
1586,
199,
14833,
51,
275,
2097,
40,
17,
26,
6533,
1179,
13,
840,
21715,
401,
298,
44,
17,
26,
6533,
1179,
13,
840,
21715,
401,
298,
54,
17,
26,
72,
63,
975,
8188,
13026,
937,
421,
199,
32,
4462,
14,
5997,
199,
318,
2547,
837,
272,
372,
1127,
276,
1186,
14,
13848,
3296,
4299,
8,
495,
8,
2864,
63,
19674,
38,
63,
3243,
14,
1708,
395,
7393,
63,
19674,
38,
63,
3243,
14,
354,
9,
421,
199,
318,
485,
396,
63,
1490,
63,
576,
63,
1365,
8,
1365,
304,
272,
408,
2765,
805,
5965,
18628,
314,
511,
272,
408,
272,
2547,
275,
22192,
647,
63,
416,
276,
1186,
14,
1490,
63,
576,
63,
1365,
8,
1365,
9,
272,
702,
2547,
14,
7367,
508,
7393,
63,
19674,
38,
63,
27001,
59,
16,
61,
272,
702,
7393,
63,
19674,
38,
63,
3243,
508,
6912,
8,
267,
7097,
8,
1745,
14,
1637,
14,
513,
14,
633,
680,
515,
272,
7092,
6116,
342,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1365,
401,
359,
272,
7393,
63,
19674,
38,
63,
3817,
12,
272,
7393,
63,
19674,
38,
63,
2632,
12,
272,
359,
2864,
63,
19674,
38,
63,
3817,
467,
272,
634,
279,
63,
1208,
14,
4437,
3900,
14,
504,
63,
52,
1717,
24938,
8,
2864,
63,
19674,
38,
63,
3817,
395,
199,
566,
199,
318,
511,
63,
1490,
63,
576,
63,
1365,
8,
1365,
304,
272,
372,
485,
396,
63,
1490,
63,
576,
63,
1365,
8,
1365,
9,
421,
199,
32,
2759,
63,
4752,
63,
8575,
480,
3528,
310,
14,
76,
279,
531,
199,
318,
511,
63,
1490,
63,
576,
63,
1365,
63,
3528,
310,
837,
272,
687,
6482,
310,
14,
76,
279,
492,
11977,
272,
11977,
14,
2373,
63,
533,
275,
634,
279,
63,
1208,
14,
4437,
3900,
272,
2581,
275,
11977,
14,
504,
63,
3603,
779,
2864,
63,
19674,
38,
63,
3817,
566,
272,
372,
485,
396,
63,
1490,
63,
576,
63,
1365,
8,
1637,
9,
421,
199,
318,
511,
63,
1490,
63,
576,
63,
1365,
63,
1637,
837,
272,
543,
21791,
8117,
9520,
76,
2177,
531,
465,
2581,
26,
267,
2218,
63,
1637,
779,
2864,
63,
19674,
38,
63,
3817,
467,
2581,
12,
1475,
628,
76,
279,
531,
267,
372,
485,
396,
63,
1490,
63,
576,
63,
1365,
8,
1637,
9,
421,
199,
318,
511,
63,
1490,
63,
576,
63,
1365,
63,
705,
837,
272,
543,
4613,
14,
3536,
8,
3393,
9,
465,
3178,
26,
267,
22192,
647,
63,
416,
276,
1186,
14,
1490,
63,
576,
63,
1365,
8,
403,
9,
272,
702,
620,
8,
2804,
14,
585,
9,
508,
334,
267,
298,
16932,
1133,
5715,
4212,
370,
1551,
666,
1350,
402,
730,
8352,
908,
8,
466,
8,
403,
430,
272,
776,
421,
199,
318,
511,
63,
362,
63,
1745,
63,
5553,
8,
1745,
304,
272,
702,
22192,
647,
63,
416,
276,
1186,
14,
362,
63,
1745,
63,
5553,
8,
1745,
9,
508,
413,
14,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
928,
12,
1284,
401,
359,
272,
334,
403,
12,
488,
395,
272,
334,
403,
12,
7393,
63,
19674,
38,
63,
27001,
59,
16,
61,
435,
1275,
21,
395,
272,
334,
2864,
63,
19674,
38,
63,
27001,
59,
16,
61,
435,
1275,
21,
12,
488,
395,
272,
334,
2864,
63,
19674,
38,
63,
27001,
59,
16,
61,
435,
1275,
821,
12,
7393,
63,
19674,
38,
63,
27001,
59,
17,
61,
446,
1275,
821,
9,
199,
566,
199,
318
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
35,
9,
577,
1097,
290,
10444,
274,
364,
334,
7280,
13,
13934,
9,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
598,
55,
647,
14,
199,
3,
199,
3,
598,
55,
647,
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,
598,
55,
647,
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,
598,
55,
647,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
2925,
367,
520,
1494,
1705,
8392,
647,
14,
28551,
14,
2308,
14,
8392,
70,
14,
416,
276,
1186,
64,
199,
624,
199,
199,
504,
32212,
492,
6912,
199,
504,
4011,
14,
1122,
492,
7097,
199,
199,
646,
4613,
199,
199,
504,
22192,
576,
1623,
14,
1208,
492,
570,
63,
9255,
199,
199,
504,
2263,
2308,
14,
1637,
492,
2218,
63,
1637,
199,
504,
2263,
4776,
14,
1208,
492,
334,
272,
702,
63,
807,
63,
1452,
12,
272,
702,
63,
10577,
63,
954,
63,
1452,
12,
272,
3372,
63,
4752,
63,
8575,
12,
272,
21791,
8117,
12,
272,
7393,
63,
19674,
38,
63,
3817,
12,
199,
9,
199,
504,
2263,
28551,
492,
4703,
9641,
199,
199,
3,
492,
2716,
5124,
199,
76,
279,
63,
1208,
275,
4613,
14,
646,
269,
2759,
480,
76,
279,
14,
1208,
531,
199,
416,
276,
1186,
275,
4613,
14,
646,
269,
2759,
480,
416,
276,
1186,
531,
199,
8392,
647,
63,
416,
276,
1186,
275,
4613,
14,
646,
269,
2759,
480,
8392,
647,
14,
28551,
14,
2308,
14,
8392,
70,
14,
416,
276,
1186,
531,
199,
199,
3,
664,
9022,
370,
511,
6169,
199,
2864,
63,
19674,
38,
63,
3243,
275,
6912,
8,
2864,
63,
19674,
38,
63,
3817,
680,
6116,
342,
199,
2864,
63,
19674,
38,
63,
2632,
275,
7393,
63,
19674,
38,
63,
3243,
14,
305,
63,
2302,
342,
199,
199,
3,
664,
9463,
5226,
370,
642,
570,
199,
2864,
63,
19674,
38,
63,
27001,
275,
570,
63,
9255,
8,
2864,
63,
19674,
38,
63,
3817,
9,
199,
199,
3,
9245,
370,
1586,
199,
14833,
51,
275,
2097,
40,
17,
26,
6533,
1179,
13,
840,
21715,
401,
298,
44,
17,
26,
6533,
1179,
13,
840,
21715,
401,
298,
54,
17,
26,
72,
63,
975,
8188,
13026,
937,
421,
199,
32,
4462,
14,
5997,
199,
318,
2547,
837,
272,
372,
1127,
276,
1186,
14,
13848,
3296,
4299,
8,
495,
8,
2864,
63,
19674,
38,
63,
3243,
14,
1708,
395,
7393,
63,
19674,
38,
63,
3243,
14,
354,
9,
421,
199,
318,
485,
396,
63,
1490,
63,
576,
63,
1365,
8,
1365,
304,
272,
408,
2765,
805,
5965,
18628,
314,
511,
272,
408,
272,
2547,
275,
22192,
647,
63,
416,
276,
1186,
14,
1490,
63,
576,
63,
1365,
8,
1365,
9,
272,
702,
2547,
14,
7367,
508,
7393,
63,
19674,
38,
63,
27001,
59,
16,
61,
272,
702,
7393,
63,
19674,
38,
63,
3243,
508,
6912,
8,
267,
7097,
8,
1745,
14,
1637,
14,
513,
14,
633,
680,
515,
272,
7092,
6116,
342,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1365,
401,
359,
272,
7393,
63,
19674,
38,
63,
3817,
12,
272,
7393,
63,
19674,
38,
63,
2632,
12,
272,
359,
2864,
63,
19674,
38,
63,
3817,
467,
272,
634,
279,
63,
1208,
14,
4437,
3900,
14,
504,
63,
52,
1717,
24938,
8,
2864,
63,
19674,
38,
63,
3817,
395,
199,
566,
199,
318,
511,
63,
1490,
63,
576,
63,
1365,
8,
1365,
304,
272,
372,
485,
396,
63,
1490,
63,
576,
63,
1365,
8,
1365,
9,
421,
199,
32,
2759,
63,
4752,
63,
8575,
480,
3528,
310,
14,
76,
279,
531,
199,
318,
511,
63,
1490,
63,
576,
63,
1365,
63,
3528,
310,
837,
272,
687,
6482,
310,
14,
76,
279,
492,
11977,
272,
11977,
14,
2373,
63,
533,
275,
634,
279,
63,
1208,
14,
4437,
3900,
272,
2581,
275,
11977,
14,
504,
63,
3603,
779,
2864,
63,
19674,
38,
63,
3817,
566,
272,
372,
485,
396,
63,
1490,
63,
576,
63,
1365,
8,
1637,
9,
421,
199,
318,
511,
63,
1490,
63,
576,
63,
1365,
63,
1637,
837,
272,
543,
21791,
8117,
9520,
76,
2177,
531,
465,
2581,
26,
267,
2218,
63,
1637,
779,
2864,
63,
19674,
38,
63,
3817,
467,
2581,
12,
1475,
628,
76,
279,
531,
267,
372,
485,
396,
63,
1490,
63,
576,
63,
1365,
8,
1637,
9,
421,
199,
318,
511,
63,
1490,
63,
576,
63,
1365,
63,
705,
837,
272,
543,
4613,
14,
3536,
8,
3393,
9,
465,
3178,
26,
267,
22192,
647,
63,
416,
276,
1186,
14,
1490,
63,
576,
63,
1365,
8,
403,
9,
272,
702,
620,
8,
2804,
14,
585,
9,
508,
334,
267,
298,
16932,
1133,
5715,
4212,
370,
1551,
666,
1350,
402,
730,
8352,
908,
8,
466,
8,
403,
430,
272,
776,
421,
199,
318,
511,
63,
362,
63,
1745,
63,
5553,
8,
1745,
304,
272,
702,
22192,
647,
63,
416,
276,
1186,
14,
362,
63,
1745,
63,
5553,
8,
1745,
9,
508,
413,
14,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
928,
12,
1284,
401,
359,
272,
334,
403,
12,
488,
395,
272,
334,
403,
12,
7393,
63,
19674,
38,
63,
27001,
59,
16,
61,
435,
1275,
21,
395,
272,
334,
2864,
63,
19674,
38,
63,
27001,
59,
16,
61,
435,
1275,
21,
12,
488,
395,
272,
334,
2864,
63,
19674,
38,
63,
27001,
59,
16,
61,
435,
1275,
821,
12,
7393,
63,
19674,
38,
63,
27001,
59,
17,
61,
446,
1275,
821,
9,
199,
566,
199,
318,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kaichogami/scikit-learn
|
examples/cluster/plot_ward_structured_vs_unstructured.py
|
320
|
3369
|
"""
===========================================================
Hierarchical clustering: structured vs unstructured ward
===========================================================
Example builds a swiss roll dataset and runs
hierarchical clustering on their position.
For more information, see :ref:`hierarchical_clustering`.
In a first step, the hierarchical clustering is performed without connectivity
constraints on the structure and is solely based on distance, whereas in
a second step the clustering is restricted to the k-Nearest Neighbors
graph: it's a hierarchical clustering with structure prior.
Some of the clusters learned without connectivity constraints do not
respect the structure of the swiss roll and extend across different folds of
the manifolds. On the opposite, when opposing connectivity constraints,
the clusters form a nice parcellation of the swiss roll.
"""
# Authors : Vincent Michel, 2010
# Alexandre Gramfort, 2010
# Gael Varoquaux, 2010
# License: BSD 3 clause
print(__doc__)
import time as time
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
from sklearn.cluster import AgglomerativeClustering
from sklearn.datasets.samples_generator import make_swiss_roll
###############################################################################
# Generate data (swiss roll dataset)
n_samples = 1500
noise = 0.05
X, _ = make_swiss_roll(n_samples, noise)
# Make it thinner
X[:, 1] *= .5
###############################################################################
# Compute clustering
print("Compute unstructured hierarchical clustering...")
st = time.time()
ward = AgglomerativeClustering(n_clusters=6, linkage='ward').fit(X)
elapsed_time = time.time() - st
label = ward.labels_
print("Elapsed time: %.2fs" % elapsed_time)
print("Number of points: %i" % label.size)
###############################################################################
# Plot result
fig = plt.figure()
ax = p3.Axes3D(fig)
ax.view_init(7, -80)
for l in np.unique(label):
ax.plot3D(X[label == l, 0], X[label == l, 1], X[label == l, 2],
'o', color=plt.cm.jet(np.float(l) / np.max(label + 1)))
plt.title('Without connectivity constraints (time %.2fs)' % elapsed_time)
###############################################################################
# Define the structure A of the data. Here a 10 nearest neighbors
from sklearn.neighbors import kneighbors_graph
connectivity = kneighbors_graph(X, n_neighbors=10, include_self=False)
###############################################################################
# Compute clustering
print("Compute structured hierarchical clustering...")
st = time.time()
ward = AgglomerativeClustering(n_clusters=6, connectivity=connectivity,
linkage='ward').fit(X)
elapsed_time = time.time() - st
label = ward.labels_
print("Elapsed time: %.2fs" % elapsed_time)
print("Number of points: %i" % label.size)
###############################################################################
# Plot result
fig = plt.figure()
ax = p3.Axes3D(fig)
ax.view_init(7, -80)
for l in np.unique(label):
ax.plot3D(X[label == l, 0], X[label == l, 1], X[label == l, 2],
'o', color=plt.cm.jet(float(l) / np.max(label + 1)))
plt.title('With connectivity constraints (time %.2fs)' % elapsed_time)
plt.show()
|
bsd-3-clause
|
[
624,
199,
12813,
21326,
199,
40,
16437,
19454,
26,
21781,
8118,
625,
15774,
336,
1005,
199,
12813,
21326,
199,
199,
9846,
14723,
282,
5584,
19857,
11848,
4789,
436,
7858,
199,
72,
16437,
19454,
641,
3932,
3421,
14,
199,
199,
1858,
1655,
2556,
12,
1937,
520,
1121,
1705,
72,
16437,
63,
25802,
2313,
199,
199,
607,
282,
1642,
3650,
12,
314,
24787,
19454,
365,
10585,
1928,
20170,
199,
9882,
641,
314,
5523,
436,
365,
30869,
590,
4079,
641,
6033,
12,
29781,
315,
199,
65,
3499,
3650,
314,
19454,
365,
15297,
370,
314,
1022,
13,
4698,
9540,
5612,
7398,
199,
2180,
26,
652,
1159,
282,
24787,
19454,
543,
5523,
6791,
14,
199,
199,
7700,
402,
314,
13865,
12537,
379,
1928,
20170,
9565,
886,
440,
199,
27872,
314,
5523,
402,
314,
5584,
19857,
11848,
436,
12247,
9371,
3365,
1699,
795,
402,
199,
1589,
2169,
692,
8250,
14,
4068,
314,
26912,
12,
1380,
1687,
555,
1044,
20170,
9565,
12,
199,
1589,
13865,
1824,
282,
14213,
623,
6067,
2212,
402,
314,
5584,
19857,
11848,
14,
199,
624,
199,
199,
3,
6642,
520,
28882,
2946,
603,
1158,
352,
12,
7129,
199,
3,
3698,
22986,
28547,
27211,
10279,
12,
7129,
199,
3,
3698,
9647,
352,
21084,
79,
392,
10962,
12,
7129,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
1361,
3460,
1301,
3368,
199,
199,
646,
900,
465,
900,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
22513,
63,
3557,
75,
1405,
14,
311,
1653,
19,
68,
14,
6402,
19,
68,
465,
299,
19,
199,
504,
6357,
14,
4201,
492,
18693,
320,
278,
30498,
31174,
199,
504,
6357,
14,
12281,
14,
3356,
63,
4679,
492,
1852,
63,
3519,
19857,
63,
2827,
199,
199,
11490,
199,
3,
7958,
666,
334,
3519,
19857,
11848,
4789,
9,
199,
78,
63,
3356,
275,
24970,
199,
11838,
275,
378,
14,
1717,
199,
56,
12,
485,
275,
1852,
63,
3519,
19857,
63,
2827,
8,
78,
63,
3356,
12,
11145,
9,
199,
3,
4155,
652,
294,
5216,
199,
56,
3981,
413,
61,
9000,
1275,
21,
199,
199,
11490,
199,
3,
8354,
19454,
199,
1361,
480,
8564,
625,
15774,
24787,
19454,
12594,
199,
270,
275,
900,
14,
521,
342,
199,
3079,
275,
18693,
320,
278,
30498,
31174,
8,
78,
63,
9170,
29,
22,
12,
26087,
534,
3079,
1959,
3269,
8,
56,
9,
199,
16691,
63,
521,
275,
900,
14,
521,
342,
446,
410,
199,
1302,
275,
336,
1005,
14,
3512,
63,
199,
1361,
480,
37,
9982,
900,
26,
10536,
18,
2319,
2,
450,
14439,
63,
521,
9,
199,
1361,
480,
3259,
402,
4501,
26,
450,
73,
2,
450,
1768,
14,
890,
9,
199,
199,
11490,
199,
3,
14794,
754,
199,
592,
275,
4488,
14,
8941,
342,
199,
1219,
275,
299,
19,
14,
20386,
19,
36,
8,
592,
9,
199,
1219,
14,
1345,
63,
826,
8,
23,
12,
446,
1257,
9,
199,
509,
634,
315,
980,
14,
3235,
8,
1302,
304,
272,
2185,
14,
2798,
19,
36,
8,
56,
59,
1302,
508,
634,
12,
378,
467,
1323,
59,
1302,
508,
634,
12,
413,
467,
1323,
59,
1302,
508,
634,
12,
499,
467,
1598,
283,
79,
297,
3164,
29,
6003,
14,
4400,
14,
74,
386,
8,
1590,
14,
1609,
8,
76,
9,
1182,
980,
14,
988,
8,
1302,
435,
413,
1724,
199,
6003,
14,
1213,
360,
12450,
20170,
9565,
334,
521,
10536,
18,
2319,
3171,
450,
14439,
63,
521,
9,
421,
199,
11490,
199,
3,
13930,
314,
5523,
437,
402,
314,
666,
14,
11842,
282,
1616,
17173,
15845,
199,
504,
6357,
14,
11113,
492,
1022,
11113,
63,
2180,
199,
22344,
275,
1022,
11113,
63,
2180,
8,
56,
12,
302,
63,
11113,
29,
709,
12,
2387,
63,
277,
29,
797,
9,
199,
199,
11490,
199,
3,
8354,
19454,
199,
1361,
480,
8564,
21781,
24787,
19454,
12594,
199,
270,
275,
900,
14,
521,
342,
199,
3079,
275,
18693,
320,
278,
30498,
31174,
8,
78,
63,
9170,
29,
22,
12,
20170,
29,
22344,
12,
3044,
26087,
534,
3079,
1959,
3269,
8,
56,
9,
199,
16691,
63,
521,
275,
900,
14,
521,
342,
446,
410,
199,
1302,
275,
336,
1005,
14,
3512,
63,
199,
1361,
480,
37,
9982,
900,
26,
10536,
18,
2319,
2,
450,
14439,
63,
521,
9,
199,
1361,
480,
3259,
402,
4501,
26,
450,
73,
2,
450,
1768,
14,
890,
9,
199,
199,
11490,
199,
3,
14794,
754,
199,
592,
275,
4488,
14,
8941,
342,
199,
1219,
275,
299,
19,
14,
20386,
19,
36,
8,
592,
9,
199,
1219,
14,
1345,
63,
826,
8,
23,
12,
446,
1257,
9,
199,
509,
634,
315,
980,
14,
3235,
8,
1302,
304,
272,
2185,
14,
2798,
19,
36,
8,
56,
59,
1302,
508,
634,
12,
378,
467,
1323,
59,
1302,
508,
634,
12,
413,
467,
1323,
59,
1302,
508,
634,
12,
499,
467,
1598,
283,
79,
297,
3164,
29,
6003,
14,
4400,
14,
74,
386,
8,
1609,
8,
76,
9,
1182,
980,
14,
988,
8,
1302,
435,
413,
1724,
199,
6003,
14,
1213,
360,
3007,
20170,
9565,
334,
521,
10536,
18,
2319,
3171,
450,
14439,
63,
521,
9,
199,
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
] |
[
199,
12813,
21326,
199,
40,
16437,
19454,
26,
21781,
8118,
625,
15774,
336,
1005,
199,
12813,
21326,
199,
199,
9846,
14723,
282,
5584,
19857,
11848,
4789,
436,
7858,
199,
72,
16437,
19454,
641,
3932,
3421,
14,
199,
199,
1858,
1655,
2556,
12,
1937,
520,
1121,
1705,
72,
16437,
63,
25802,
2313,
199,
199,
607,
282,
1642,
3650,
12,
314,
24787,
19454,
365,
10585,
1928,
20170,
199,
9882,
641,
314,
5523,
436,
365,
30869,
590,
4079,
641,
6033,
12,
29781,
315,
199,
65,
3499,
3650,
314,
19454,
365,
15297,
370,
314,
1022,
13,
4698,
9540,
5612,
7398,
199,
2180,
26,
652,
1159,
282,
24787,
19454,
543,
5523,
6791,
14,
199,
199,
7700,
402,
314,
13865,
12537,
379,
1928,
20170,
9565,
886,
440,
199,
27872,
314,
5523,
402,
314,
5584,
19857,
11848,
436,
12247,
9371,
3365,
1699,
795,
402,
199,
1589,
2169,
692,
8250,
14,
4068,
314,
26912,
12,
1380,
1687,
555,
1044,
20170,
9565,
12,
199,
1589,
13865,
1824,
282,
14213,
623,
6067,
2212,
402,
314,
5584,
19857,
11848,
14,
199,
624,
199,
199,
3,
6642,
520,
28882,
2946,
603,
1158,
352,
12,
7129,
199,
3,
3698,
22986,
28547,
27211,
10279,
12,
7129,
199,
3,
3698,
9647,
352,
21084,
79,
392,
10962,
12,
7129,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
1361,
3460,
1301,
3368,
199,
199,
646,
900,
465,
900,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
22513,
63,
3557,
75,
1405,
14,
311,
1653,
19,
68,
14,
6402,
19,
68,
465,
299,
19,
199,
504,
6357,
14,
4201,
492,
18693,
320,
278,
30498,
31174,
199,
504,
6357,
14,
12281,
14,
3356,
63,
4679,
492,
1852,
63,
3519,
19857,
63,
2827,
199,
199,
11490,
199,
3,
7958,
666,
334,
3519,
19857,
11848,
4789,
9,
199,
78,
63,
3356,
275,
24970,
199,
11838,
275,
378,
14,
1717,
199,
56,
12,
485,
275,
1852,
63,
3519,
19857,
63,
2827,
8,
78,
63,
3356,
12,
11145,
9,
199,
3,
4155,
652,
294,
5216,
199,
56,
3981,
413,
61,
9000,
1275,
21,
199,
199,
11490,
199,
3,
8354,
19454,
199,
1361,
480,
8564,
625,
15774,
24787,
19454,
12594,
199,
270,
275,
900,
14,
521,
342,
199,
3079,
275,
18693,
320,
278,
30498,
31174,
8,
78,
63,
9170,
29,
22,
12,
26087,
534,
3079,
1959,
3269,
8,
56,
9,
199,
16691,
63,
521,
275,
900,
14,
521,
342,
446,
410,
199,
1302,
275,
336,
1005,
14,
3512,
63,
199,
1361,
480,
37,
9982,
900,
26,
10536,
18,
2319,
2,
450,
14439,
63,
521,
9,
199,
1361,
480,
3259,
402,
4501,
26,
450,
73,
2,
450,
1768,
14,
890,
9,
199,
199,
11490,
199,
3,
14794,
754,
199,
592,
275,
4488,
14,
8941,
342,
199,
1219,
275,
299,
19,
14,
20386,
19,
36,
8,
592,
9,
199,
1219,
14,
1345,
63,
826,
8,
23,
12,
446,
1257,
9,
199,
509,
634,
315,
980,
14,
3235,
8,
1302,
304,
272,
2185,
14,
2798,
19,
36,
8,
56,
59,
1302,
508,
634,
12,
378,
467,
1323,
59,
1302,
508,
634,
12,
413,
467,
1323,
59,
1302,
508,
634,
12,
499,
467,
1598,
283,
79,
297,
3164,
29,
6003,
14,
4400,
14,
74,
386,
8,
1590,
14,
1609,
8,
76,
9,
1182,
980,
14,
988,
8,
1302,
435,
413,
1724,
199,
6003,
14,
1213,
360,
12450,
20170,
9565,
334,
521,
10536,
18,
2319,
3171,
450,
14439,
63,
521,
9,
421,
199,
11490,
199,
3,
13930,
314,
5523,
437,
402,
314,
666,
14,
11842,
282,
1616,
17173,
15845,
199,
504,
6357,
14,
11113,
492,
1022,
11113,
63,
2180,
199,
22344,
275,
1022,
11113,
63,
2180,
8,
56,
12,
302,
63,
11113,
29,
709,
12,
2387,
63,
277,
29,
797,
9,
199,
199,
11490,
199,
3,
8354,
19454,
199,
1361,
480,
8564,
21781,
24787,
19454,
12594,
199,
270,
275,
900,
14,
521,
342,
199,
3079,
275,
18693,
320,
278,
30498,
31174,
8,
78,
63,
9170,
29,
22,
12,
20170,
29,
22344,
12,
3044,
26087,
534,
3079,
1959,
3269,
8,
56,
9,
199,
16691,
63,
521,
275,
900,
14,
521,
342,
446,
410,
199,
1302,
275,
336,
1005,
14,
3512,
63,
199,
1361,
480,
37,
9982,
900,
26,
10536,
18,
2319,
2,
450,
14439,
63,
521,
9,
199,
1361,
480,
3259,
402,
4501,
26,
450,
73,
2,
450,
1768,
14,
890,
9,
199,
199,
11490,
199,
3,
14794,
754,
199,
592,
275,
4488,
14,
8941,
342,
199,
1219,
275,
299,
19,
14,
20386,
19,
36,
8,
592,
9,
199,
1219,
14,
1345,
63,
826,
8,
23,
12,
446,
1257,
9,
199,
509,
634,
315,
980,
14,
3235,
8,
1302,
304,
272,
2185,
14,
2798,
19,
36,
8,
56,
59,
1302,
508,
634,
12,
378,
467,
1323,
59,
1302,
508,
634,
12,
413,
467,
1323,
59,
1302,
508,
634,
12,
499,
467,
1598,
283,
79,
297,
3164,
29,
6003,
14,
4400,
14,
74,
386,
8,
1609,
8,
76,
9,
1182,
980,
14,
988,
8,
1302,
435,
413,
1724,
199,
6003,
14,
1213,
360,
3007,
20170,
9565,
334,
521,
10536,
18,
2319,
3171,
450,
14439,
63,
521,
9,
199,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
georgestarcher/TA-SyncKVStore
|
bin/ta_synckvstore/cloudconnectlib/splunktalib/credentials.py
|
4
|
11063
|
"""
Handles credentials related stuff
"""
import re
import xml.dom.minidom as xdm
from . import rest
from .common import util
from .common import xml_dom_parser as xdp
# Splunk can only encrypt string when length <=255
SPLUNK_CRED_LEN_LIMIT = 255
class CredException(Exception):
pass
class CredNotFound(CredException):
"""
Credential information not exists
"""
pass
def create_credential_manager(username, password, splunkd_uri,
app, owner, realm):
session_key = CredentialManager.get_session_key(
username, password, splunkd_uri)
return CredentialManager(splunkd_uri, session_key, app, owner, realm)
class CredentialManager(object):
"""
Credential related interfaces
"""
def __init__(self, splunkd_uri, session_key,
app="-", owner="nobody", realm=None):
"""
:app: when creating/upating/deleting app is required
"""
self._app = app
self._splunkd_uri = splunkd_uri
self._owner = owner
self._sep = "``splunk_cred_sep``"
if realm:
self._realm = realm
else:
self._realm = app
self._session_key = session_key
def set_appname(self, app):
"""
This are cases we need edit/remove/create confs in different app
context. call this interface to switch app context before manipulate
the confs in different app context
"""
self._app = app
@staticmethod
def get_session_key(username, password,
splunkd_uri="https://localhost:8089"):
"""
Get session key by using login username and passwrod
:return: session_key if successful, None if failed
"""
eid = "".join((splunkd_uri, "/services/auth/login"))
postargs = {
"username": username,
"password": password,
}
response, content = rest.splunkd_request(
eid, None, method="POST", data=postargs)
if response is None and content is None:
raise CredException("Get session key failed.")
xml_obj = xdm.parseString(content)
session_nodes = xml_obj.getElementsByTagName("sessionKey")
if not session_nodes:
raise CredException("Invalid username or password.")
session_key = session_nodes[0].firstChild.nodeValue
if not session_key:
raise CredException("Get session key failed.")
return session_key
def update(self, stanza):
"""
Update or Create credentials based on the stanza
:stanza: nested dict object. The outlayer keys are stanza name, and
inner dict is user/pass key/value pair to be encrypted
{
"stanza_name": {"tommy": "tommypasswod", "jerry": "jerrypassword"}
}
:return: raise on failure
"""
for name, encr_dict in stanza.items():
encrypts = []
for key, val in encr_dict.items():
encrypts.append(key)
encrypts.append(val)
self._update(name, self._sep.join(encrypts))
def _update(self, name, str_to_encrypt):
"""
Update the string for the name.
:return: raise on failure
"""
self.delete(name)
if len(str_to_encrypt) <= SPLUNK_CRED_LEN_LIMIT:
self._create(name, str_to_encrypt)
return
# split the str_to_encrypt when len > 255
length = SPLUNK_CRED_LEN_LIMIT
i = 0
while length < len(str_to_encrypt) + SPLUNK_CRED_LEN_LIMIT:
curr_str = str_to_encrypt[length - SPLUNK_CRED_LEN_LIMIT:length]
length += SPLUNK_CRED_LEN_LIMIT
stanza_name = self._sep.join((name, str(i)))
self._create(stanza_name, curr_str)
i += 1
def _create(self, name, str_to_encrypt):
"""
Create a new stored credential.
:return: raise on failure
"""
payload = {
"name": name,
"password": str_to_encrypt,
"realm": self._realm,
}
endpoint = self._get_endpoint(name)
resp, content = rest.splunkd_request(endpoint, self._session_key,
method="POST", data=payload)
if not resp or resp.status not in (200, 201, "200", "201"):
raise CredException("Failed to encrypt username {}".format(name))
def delete(self, name, throw=False):
"""
Delete the encrypted entry
"""
try:
self._delete(name, throw=True)
except CredNotFound:
# try to delete the split stanzas
try:
stanzas = self._get_all_passwords()
except Exception:
raise
ent_regx = "%s:(%s%s\d+):" % (self._realm, name, self._sep)
ent_pattern = re.compile(ent_regx)
for stanza in stanzas:
stanza_name = stanza.get("name")
match = ent_pattern.match(stanza_name)
if match:
try:
delete_name = match.group(1)
self._delete(delete_name, throw=True)
except CredNotFound:
pass
except CredException:
raise
except CredException:
raise
def _delete(self, name, throw=False):
"""
Delete the encrypted entry
"""
endpoint = self._get_endpoint(name)
response, content = rest.splunkd_request(
endpoint, self._session_key, method="DELETE")
if response is not None and response.status in (404, "404"):
if throw:
raise CredNotFound(
"Credential stanza not exits - {}".format(name))
elif not response or response.status not in (200, 201, "200", "201"):
if throw:
raise CredException(
"Failed to delete credential stanza {}".format(name))
def get_all_passwords(self):
results = {}
all_stanzas = self._get_all_passwords()
for stanza in all_stanzas:
name = stanza.get("name")
match = re.match(r"(.+){}(\d+)".format(self._sep), name)
if match:
actual_name = match.group(1) + ":"
index = int(match.group(2))
if results.get(actual_name):
exist_stanza = results.get(actual_name)
else:
exist_stanza = stanza
exist_stanza['name'] = actual_name
exist_stanza['username'] = \
exist_stanza['username'].split(self._sep)[0]
exist_stanza['clears'] = {}
exist_stanza['encrs'] = {}
try:
exist_stanza['clears'][index] = stanza.get('clear_password')
exist_stanza['encrs'][index] = stanza.get('encr_password')
except KeyError:
exist_stanza['clears'] = {}
exist_stanza['encrs'] = {}
exist_stanza['clears'][index] = stanza.get('clear_password')
exist_stanza['encrs'][index] = stanza.get('encr_password')
results[actual_name] = exist_stanza
else:
results[name] = stanza
# merge the stanzas by index
for name, stanza in results.items():
field_clear = stanza.get('clears')
field_encr = stanza.get('encrs')
if isinstance(field_clear, dict):
clear_password = ""
encr_password = ""
for index in sorted(field_clear.keys()):
clear_password += field_clear.get(index)
encr_password += field_encr.get(index)
stanza['clear_password'] = clear_password
stanza['encr_password'] = encr_password
del stanza['clears']
del stanza['encrs']
return results.values()
def _get_all_passwords(self):
"""
:return: a list of dict when successful, None when failed.
the dict at least contains
{
"realm": xxx,
"username": yyy,
"clear_password": zzz,
}
"""
endpoint = self._get_endpoint()
response, content = rest.splunkd_request(
endpoint, self._session_key, method="GET")
if response and response.status in (200, 201, "200", "201") and content:
return xdp.parse_conf_xml_dom(content)
raise CredException("Failed to get credentials")
def get_clear_password(self, name=None):
"""
:return: clear password(s)
{
stanza_name: {"user": pass}
}
"""
return self._get_credentials("clear_password", name)
def get_encrypted_password(self, name=None):
"""
:return: encyrpted password(s)
"""
return self._get_credentials("encr_password", name)
def _get_credentials(self, prop, name=None):
"""
:return: clear or encrypted password for specified realm, user
"""
all_stanzas = self.get_all_passwords()
results = {}
for stanza in all_stanzas:
if name and not stanza.get("name").endswith(":" + name + ":"):
continue
if stanza.get("realm") == self._realm:
values = stanza[prop].split(self._sep)
if len(values) % 2 == 1:
continue
result = {values[i]: values[i + 1]
for i in range(0, len(values), 2)}
results[stanza.get("username")] = result
return results
@staticmethod
def _build_name(realm, name):
return util.format_stanza_name(
"".join((CredentialManager._escape_string(realm), ":",
CredentialManager._escape_string(name), ":")))
@staticmethod
def _escape_string(string_to_escape):
r"""
Splunk secure credential storage actually requires a custom style of
escaped string where all the :'s are escaped by a single \.
But don't escape the control : in the stanza name.
"""
return string_to_escape.replace(":", "\\:")
def _get_endpoint(self, name=None, query=False):
app = self._app
owner = self._owner
if query:
app = "-"
owner = "-"
if name:
realm_user = self._build_name(self._realm, name)
rest_endpoint = "{}/servicesNS/{}/{}/storage/passwords/{}".format(
self._splunkd_uri, owner, app, realm_user)
else:
rest_endpoint = "{}/servicesNS/{}/{}/storage/passwords?count=-1" \
"".format(self._splunkd_uri, owner, app)
return rest_endpoint
|
mit
|
[
624,
199,
23555,
6235,
4048,
8292,
199,
624,
199,
199,
646,
295,
199,
646,
2748,
14,
4556,
14,
21827,
465,
671,
6428,
199,
199,
504,
1275,
492,
4618,
199,
504,
1275,
2330,
492,
4884,
199,
504,
1275,
2330,
492,
2748,
63,
4556,
63,
2087,
465,
671,
5780,
199,
199,
3,
428,
1168,
1778,
883,
1454,
14645,
1059,
1380,
2582,
2695,
2299,
199,
24933,
8019,
63,
30553,
63,
5304,
63,
13387,
275,
5450,
421,
199,
533,
445,
581,
1726,
8,
1726,
304,
272,
986,
421,
199,
533,
445,
581,
4667,
8,
35,
581,
1726,
304,
272,
408,
272,
9750,
3256,
2556,
440,
3495,
272,
408,
272,
986,
421,
199,
318,
1218,
63,
15591,
63,
2609,
8,
2473,
12,
2505,
12,
23168,
1778,
68,
63,
2302,
12,
2892,
1145,
12,
5771,
12,
10482,
304,
272,
2351,
63,
498,
275,
9750,
3256,
2988,
14,
362,
63,
1730,
63,
498,
8,
267,
3434,
12,
2505,
12,
23168,
1778,
68,
63,
2302,
9,
272,
372,
9750,
3256,
2988,
8,
15276,
1778,
68,
63,
2302,
12,
2351,
63,
498,
12,
1145,
12,
5771,
12,
10482,
9,
421,
199,
533,
9750,
3256,
2988,
8,
785,
304,
272,
408,
272,
9750,
3256,
4048,
8386,
272,
408,
339,
347,
636,
826,
721,
277,
12,
23168,
1778,
68,
63,
2302,
12,
2351,
63,
498,
12,
326,
1145,
27295,
401,
5771,
628,
889,
2030,
401,
10482,
29,
403,
304,
267,
408,
267,
520,
571,
26,
1380,
6425,
15,
384,
1958,
15,
7346,
1337,
1145,
365,
1415,
267,
408,
398,
291,
423,
571,
275,
1145,
267,
291,
423,
15276,
1778,
68,
63,
2302,
275,
23168,
1778,
68,
63,
2302,
267,
291,
423,
4597,
275,
5771,
267,
291,
423,
4127,
275,
298,
1040,
15276,
1778,
63,
18639,
63,
4127,
1040,
2,
398,
340,
10482,
26,
288,
291,
423,
7728,
275,
10482,
267,
587,
26,
288,
291,
423,
7728,
275,
1145,
398,
291,
423,
1730,
63,
498,
275,
2351,
63,
498,
339,
347,
663,
63,
21653,
8,
277,
12,
1145,
304,
267,
408,
267,
961,
787,
5560,
781,
1929,
5283,
15,
2168,
15,
981,
406,
2319,
315,
3365,
1145,
267,
1067,
14,
1240,
642,
3217,
370,
6258,
1145,
1067,
2544,
27232,
267,
314,
406,
2319,
315,
3365,
1145,
1067,
267,
408,
398,
291,
423,
571,
275,
1145,
339,
768,
4639,
272,
347,
664,
63,
1730,
63,
498,
8,
2473,
12,
2505,
12,
717,
23168,
1778,
68,
63,
2302,
628,
2859,
921,
5967,
26,
1257,
1407,
2349,
267,
408,
267,
2372,
2351,
790,
701,
1808,
4676,
3434,
436,
986,
87,
19402,
267,
520,
1107,
26,
2351,
63,
498,
340,
9512,
12,
488,
340,
3405,
267,
408,
398,
325,
344,
275,
10587,
904,
1332,
15276,
1778,
68,
63,
2302,
12,
3286,
5950,
15,
1178,
15,
2886,
2237,
267,
2963,
589,
275,
469,
288,
298,
2473,
582,
3434,
12,
288,
298,
2060,
582,
2505,
12,
267,
789,
398,
1177,
12,
1564,
275,
4618,
14,
15276,
1778,
68,
63,
1069,
8,
288,
325,
344,
12,
488,
12,
1083,
628,
4030,
401,
666,
29,
32714,
9,
398,
340,
1177,
365,
488,
436,
1564,
365,
488,
26,
288,
746,
445,
581,
1726,
480,
1002,
2351,
790,
3405,
2685,
398,
2748,
63,
1113,
275,
671,
6428,
14,
14934,
8,
1317,
9,
267,
2351,
63,
2415,
275,
2748,
63,
1113,
14,
15045,
480,
1730,
1197,
531,
267,
340,
440,
2351,
63,
2415,
26,
288,
746,
445,
581,
1726,
480,
3364,
3434,
503,
2505,
2685,
267,
2351,
63,
498,
275,
2351,
63,
2415,
59,
16,
1055,
22262,
14,
17240,
267,
340,
440,
2351,
63,
498,
26,
288,
746,
445,
581,
1726,
480,
1002,
2351,
790,
3405,
2685,
267,
372,
2351,
63,
498,
339,
347,
1678,
8,
277,
12,
24267,
304,
267,
408,
267,
6162,
503,
2790,
6235,
4079,
641,
314,
24267,
267,
520,
29455,
26,
6032,
1211,
909,
14,
710,
734,
1897,
2883,
787,
24267,
536,
12,
436,
326,
6506,
1211,
365,
922,
15,
1529,
790,
15,
585,
4092,
370,
506,
14862,
268,
469,
268,
298,
29455,
63,
354,
582,
2420,
475,
31155,
582,
298,
475,
31155,
1529,
87,
364,
401,
298,
74,
281,
651,
582,
298,
74,
281,
651,
2060,
3570,
268,
789,
267,
520,
1107,
26,
746,
641,
5988,
267,
408,
398,
367,
536,
12,
655,
1556,
63,
807,
315,
24267,
14,
1744,
837,
288,
14645,
83,
275,
942,
288,
367,
790,
12,
1139,
315,
655,
1556,
63,
807,
14,
1744,
837,
355,
14645,
83,
14,
740,
8,
498,
9,
355,
14645,
83,
14,
740,
8,
637,
9,
288,
291,
423,
873,
8,
354,
12,
291,
423,
4127,
14,
904,
8,
11929,
83,
430,
339,
347,
485,
873,
8,
277,
12,
536,
12,
620,
63,
475,
63,
11929,
304,
267,
408,
267,
6162,
314,
1059,
367,
314,
536,
14,
267,
520,
1107,
26,
746,
641,
5988,
267,
408,
398,
291,
14,
1807,
8,
354,
9,
398,
340,
822,
8,
495,
63,
475,
63,
11929,
9,
2695,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
26,
288,
291,
423,
981,
8,
354,
12,
620,
63,
475,
63,
11929,
9,
288,
372,
398,
327,
3715,
314,
620,
63,
475,
63,
11929,
1380,
822,
690,
5450,
267,
2582,
275,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
267,
284,
275,
378,
267,
1830,
2582,
665,
822,
8,
495,
63,
475,
63,
11929,
9,
435,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
26,
288,
8230,
63,
495,
275,
620,
63,
475,
63,
11929,
59,
1267,
446,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
26,
1267,
61,
288,
2582,
847,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
953,
24267,
63,
354,
275,
291,
423,
4127,
14,
904,
1332,
354,
12,
620,
8,
73,
1724,
288,
291,
423,
981,
8,
29455,
63,
354,
12,
8230,
63,
495,
9,
288,
284,
847,
413,
339,
347,
485,
981,
8,
277,
12,
536,
12,
620,
63,
475,
63,
11929,
304,
267,
408,
267,
2790,
282,
892,
5489,
16338,
14,
267,
520,
1107,
26,
746,
641,
5988,
267,
408,
398,
4886,
275,
469,
288,
298,
354,
582,
536,
12,
288,
298,
2060,
582,
620,
63,
475,
63,
11929,
12,
288,
298,
7728,
582,
291,
423,
7728,
12,
267,
789,
398,
6037,
275,
291,
423,
362,
63,
6520
] |
[
199,
23555,
6235,
4048,
8292,
199,
624,
199,
199,
646,
295,
199,
646,
2748,
14,
4556,
14,
21827,
465,
671,
6428,
199,
199,
504,
1275,
492,
4618,
199,
504,
1275,
2330,
492,
4884,
199,
504,
1275,
2330,
492,
2748,
63,
4556,
63,
2087,
465,
671,
5780,
199,
199,
3,
428,
1168,
1778,
883,
1454,
14645,
1059,
1380,
2582,
2695,
2299,
199,
24933,
8019,
63,
30553,
63,
5304,
63,
13387,
275,
5450,
421,
199,
533,
445,
581,
1726,
8,
1726,
304,
272,
986,
421,
199,
533,
445,
581,
4667,
8,
35,
581,
1726,
304,
272,
408,
272,
9750,
3256,
2556,
440,
3495,
272,
408,
272,
986,
421,
199,
318,
1218,
63,
15591,
63,
2609,
8,
2473,
12,
2505,
12,
23168,
1778,
68,
63,
2302,
12,
2892,
1145,
12,
5771,
12,
10482,
304,
272,
2351,
63,
498,
275,
9750,
3256,
2988,
14,
362,
63,
1730,
63,
498,
8,
267,
3434,
12,
2505,
12,
23168,
1778,
68,
63,
2302,
9,
272,
372,
9750,
3256,
2988,
8,
15276,
1778,
68,
63,
2302,
12,
2351,
63,
498,
12,
1145,
12,
5771,
12,
10482,
9,
421,
199,
533,
9750,
3256,
2988,
8,
785,
304,
272,
408,
272,
9750,
3256,
4048,
8386,
272,
408,
339,
347,
636,
826,
721,
277,
12,
23168,
1778,
68,
63,
2302,
12,
2351,
63,
498,
12,
326,
1145,
27295,
401,
5771,
628,
889,
2030,
401,
10482,
29,
403,
304,
267,
408,
267,
520,
571,
26,
1380,
6425,
15,
384,
1958,
15,
7346,
1337,
1145,
365,
1415,
267,
408,
398,
291,
423,
571,
275,
1145,
267,
291,
423,
15276,
1778,
68,
63,
2302,
275,
23168,
1778,
68,
63,
2302,
267,
291,
423,
4597,
275,
5771,
267,
291,
423,
4127,
275,
298,
1040,
15276,
1778,
63,
18639,
63,
4127,
1040,
2,
398,
340,
10482,
26,
288,
291,
423,
7728,
275,
10482,
267,
587,
26,
288,
291,
423,
7728,
275,
1145,
398,
291,
423,
1730,
63,
498,
275,
2351,
63,
498,
339,
347,
663,
63,
21653,
8,
277,
12,
1145,
304,
267,
408,
267,
961,
787,
5560,
781,
1929,
5283,
15,
2168,
15,
981,
406,
2319,
315,
3365,
1145,
267,
1067,
14,
1240,
642,
3217,
370,
6258,
1145,
1067,
2544,
27232,
267,
314,
406,
2319,
315,
3365,
1145,
1067,
267,
408,
398,
291,
423,
571,
275,
1145,
339,
768,
4639,
272,
347,
664,
63,
1730,
63,
498,
8,
2473,
12,
2505,
12,
717,
23168,
1778,
68,
63,
2302,
628,
2859,
921,
5967,
26,
1257,
1407,
2349,
267,
408,
267,
2372,
2351,
790,
701,
1808,
4676,
3434,
436,
986,
87,
19402,
267,
520,
1107,
26,
2351,
63,
498,
340,
9512,
12,
488,
340,
3405,
267,
408,
398,
325,
344,
275,
10587,
904,
1332,
15276,
1778,
68,
63,
2302,
12,
3286,
5950,
15,
1178,
15,
2886,
2237,
267,
2963,
589,
275,
469,
288,
298,
2473,
582,
3434,
12,
288,
298,
2060,
582,
2505,
12,
267,
789,
398,
1177,
12,
1564,
275,
4618,
14,
15276,
1778,
68,
63,
1069,
8,
288,
325,
344,
12,
488,
12,
1083,
628,
4030,
401,
666,
29,
32714,
9,
398,
340,
1177,
365,
488,
436,
1564,
365,
488,
26,
288,
746,
445,
581,
1726,
480,
1002,
2351,
790,
3405,
2685,
398,
2748,
63,
1113,
275,
671,
6428,
14,
14934,
8,
1317,
9,
267,
2351,
63,
2415,
275,
2748,
63,
1113,
14,
15045,
480,
1730,
1197,
531,
267,
340,
440,
2351,
63,
2415,
26,
288,
746,
445,
581,
1726,
480,
3364,
3434,
503,
2505,
2685,
267,
2351,
63,
498,
275,
2351,
63,
2415,
59,
16,
1055,
22262,
14,
17240,
267,
340,
440,
2351,
63,
498,
26,
288,
746,
445,
581,
1726,
480,
1002,
2351,
790,
3405,
2685,
267,
372,
2351,
63,
498,
339,
347,
1678,
8,
277,
12,
24267,
304,
267,
408,
267,
6162,
503,
2790,
6235,
4079,
641,
314,
24267,
267,
520,
29455,
26,
6032,
1211,
909,
14,
710,
734,
1897,
2883,
787,
24267,
536,
12,
436,
326,
6506,
1211,
365,
922,
15,
1529,
790,
15,
585,
4092,
370,
506,
14862,
268,
469,
268,
298,
29455,
63,
354,
582,
2420,
475,
31155,
582,
298,
475,
31155,
1529,
87,
364,
401,
298,
74,
281,
651,
582,
298,
74,
281,
651,
2060,
3570,
268,
789,
267,
520,
1107,
26,
746,
641,
5988,
267,
408,
398,
367,
536,
12,
655,
1556,
63,
807,
315,
24267,
14,
1744,
837,
288,
14645,
83,
275,
942,
288,
367,
790,
12,
1139,
315,
655,
1556,
63,
807,
14,
1744,
837,
355,
14645,
83,
14,
740,
8,
498,
9,
355,
14645,
83,
14,
740,
8,
637,
9,
288,
291,
423,
873,
8,
354,
12,
291,
423,
4127,
14,
904,
8,
11929,
83,
430,
339,
347,
485,
873,
8,
277,
12,
536,
12,
620,
63,
475,
63,
11929,
304,
267,
408,
267,
6162,
314,
1059,
367,
314,
536,
14,
267,
520,
1107,
26,
746,
641,
5988,
267,
408,
398,
291,
14,
1807,
8,
354,
9,
398,
340,
822,
8,
495,
63,
475,
63,
11929,
9,
2695,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
26,
288,
291,
423,
981,
8,
354,
12,
620,
63,
475,
63,
11929,
9,
288,
372,
398,
327,
3715,
314,
620,
63,
475,
63,
11929,
1380,
822,
690,
5450,
267,
2582,
275,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
267,
284,
275,
378,
267,
1830,
2582,
665,
822,
8,
495,
63,
475,
63,
11929,
9,
435,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
26,
288,
8230,
63,
495,
275,
620,
63,
475,
63,
11929,
59,
1267,
446,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
26,
1267,
61,
288,
2582,
847,
428,
2749,
8019,
63,
30553,
63,
5304,
63,
13387,
953,
24267,
63,
354,
275,
291,
423,
4127,
14,
904,
1332,
354,
12,
620,
8,
73,
1724,
288,
291,
423,
981,
8,
29455,
63,
354,
12,
8230,
63,
495,
9,
288,
284,
847,
413,
339,
347,
485,
981,
8,
277,
12,
536,
12,
620,
63,
475,
63,
11929,
304,
267,
408,
267,
2790,
282,
892,
5489,
16338,
14,
267,
520,
1107,
26,
746,
641,
5988,
267,
408,
398,
4886,
275,
469,
288,
298,
354,
582,
536,
12,
288,
298,
2060,
582,
620,
63,
475,
63,
11929,
12,
288,
298,
7728,
582,
291,
423,
7728,
12,
267,
789,
398,
6037,
275,
291,
423,
362,
63,
6520,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
impedimentToProgress/Ratchet
|
llvm/utils/llvm-build/llvmbuild/configutil.py
|
121
|
2084
|
"""
Defines utilities useful for performing standard "configuration" style tasks.
"""
import re
import os
def configure_file(input_path, output_path, substitutions):
"""configure_file(input_path, output_path, substitutions) -> bool
Given an input and output path, "configure" the file at the given input path
by replacing variables in the file with those given in the substitutions
list. Returns true if the output file was written.
The substitutions list should be given as a list of tuples (regex string,
replacement), where the regex and replacement will be used as in 're.sub' to
execute the variable replacement.
The output path's parent directory need not exist (it will be created).
If the output path does exist and the configured data is not different than
it's current contents, the output file will not be modified. This is
designed to limit the impact of configured files on build dependencies.
"""
# Read in the input data.
f = open(input_path, "rb")
try:
data = f.read()
finally:
f.close()
# Perform the substitutions.
for regex_string,replacement in substitutions:
regex = re.compile(regex_string)
data = regex.sub(replacement, data)
# Ensure the output parent directory exists.
output_parent_path = os.path.dirname(os.path.abspath(output_path))
if not os.path.exists(output_parent_path):
os.makedirs(output_parent_path)
# If the output path exists, load it and compare to the configured contents.
if os.path.exists(output_path):
current_data = None
try:
f = open(output_path, "rb")
try:
current_data = f.read()
except:
current_data = None
f.close()
except:
current_data = None
if current_data is not None and current_data == data:
return False
# Write the output contents.
f = open(output_path, "wb")
try:
f.write(data)
finally:
f.close()
return True
|
mit
|
[
624,
199,
23891,
15841,
2997,
367,
19203,
4465,
298,
4758,
2,
3449,
6527,
14,
199,
624,
199,
199,
646,
295,
199,
646,
747,
199,
199,
318,
7908,
63,
493,
8,
1210,
63,
515,
12,
1072,
63,
515,
12,
20873,
304,
272,
408,
6472,
63,
493,
8,
1210,
63,
515,
12,
1072,
63,
515,
12,
20873,
9,
1035,
2155,
339,
9138,
376,
1324,
436,
1072,
931,
12,
298,
6472,
2,
314,
570,
737,
314,
1627,
1324,
931,
272,
701,
15810,
2860,
315,
314,
570,
543,
5204,
1627,
315,
314,
20873,
272,
769,
14,
1803,
2549,
340,
314,
1072,
570,
1990,
5313,
14,
339,
710,
20873,
769,
1077,
506,
1627,
465,
282,
769,
402,
6346,
334,
3821,
1059,
12,
272,
8343,
395,
2382,
314,
5163,
436,
8343,
911,
506,
1202,
465,
315,
283,
264,
14,
954,
7,
370,
272,
5341,
314,
1750,
8343,
14,
339,
710,
1072,
931,
1159,
1676,
2082,
1929,
440,
2187,
334,
390,
911,
506,
2737,
680,
339,
982,
314,
1072,
931,
1630,
2187,
436,
314,
7526,
666,
365,
440,
3365,
2419,
272,
652,
1159,
1453,
4072,
12,
314,
1072,
570,
911,
440,
506,
6042,
14,
961,
365,
272,
19829,
370,
2304,
314,
25568,
402,
7526,
1584,
641,
1900,
5124,
14,
272,
408,
339,
327,
5574,
315,
314,
1324,
666,
14,
272,
289,
275,
1551,
8,
1210,
63,
515,
12,
298,
4848,
531,
272,
862,
26,
267,
666,
275,
289,
14,
739,
342,
272,
3753,
26,
267,
289,
14,
1600,
342,
339,
327,
14795,
314,
20873,
14,
272,
367,
5163,
63,
875,
12,
15895,
315,
20873,
26,
267,
5163,
275,
295,
14,
2014,
8,
3821,
63,
875,
9,
267,
666,
275,
5163,
14,
954,
8,
15895,
12,
666,
9,
339,
327,
7523,
314,
1072,
1676,
2082,
3495,
14,
272,
1072,
63,
1708,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1199,
63,
515,
430,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
1199,
63,
1708,
63,
515,
304,
267,
747,
14,
8347,
8,
1199,
63,
1708,
63,
515,
9,
339,
327,
982,
314,
1072,
931,
3495,
12,
2248,
652,
436,
6540,
370,
314,
7526,
4072,
14,
272,
340,
747,
14,
515,
14,
2444,
8,
1199,
63,
515,
304,
267,
1453,
63,
576,
275,
488,
267,
862,
26,
288,
289,
275,
1551,
8,
1199,
63,
515,
12,
298,
4848,
531,
288,
862,
26,
355,
1453,
63,
576,
275,
289,
14,
739,
342,
288,
871,
26,
355,
1453,
63,
576,
275,
488,
288,
289,
14,
1600,
342,
267,
871,
26,
288,
1453,
63,
576,
275,
488,
398,
340,
1453,
63,
576,
365,
440,
488,
436,
1453,
63,
576,
508,
666,
26,
288,
372,
756,
339,
327,
6990,
314,
1072,
4072,
14,
272,
289,
275,
1551,
8,
1199,
63,
515,
12,
298,
6603,
531,
272,
862,
26,
267,
289,
14,
952,
8,
576,
9,
272,
3753,
26,
267,
289,
14,
1600,
342,
339,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
23891,
15841,
2997,
367,
19203,
4465,
298,
4758,
2,
3449,
6527,
14,
199,
624,
199,
199,
646,
295,
199,
646,
747,
199,
199,
318,
7908,
63,
493,
8,
1210,
63,
515,
12,
1072,
63,
515,
12,
20873,
304,
272,
408,
6472,
63,
493,
8,
1210,
63,
515,
12,
1072,
63,
515,
12,
20873,
9,
1035,
2155,
339,
9138,
376,
1324,
436,
1072,
931,
12,
298,
6472,
2,
314,
570,
737,
314,
1627,
1324,
931,
272,
701,
15810,
2860,
315,
314,
570,
543,
5204,
1627,
315,
314,
20873,
272,
769,
14,
1803,
2549,
340,
314,
1072,
570,
1990,
5313,
14,
339,
710,
20873,
769,
1077,
506,
1627,
465,
282,
769,
402,
6346,
334,
3821,
1059,
12,
272,
8343,
395,
2382,
314,
5163,
436,
8343,
911,
506,
1202,
465,
315,
283,
264,
14,
954,
7,
370,
272,
5341,
314,
1750,
8343,
14,
339,
710,
1072,
931,
1159,
1676,
2082,
1929,
440,
2187,
334,
390,
911,
506,
2737,
680,
339,
982,
314,
1072,
931,
1630,
2187,
436,
314,
7526,
666,
365,
440,
3365,
2419,
272,
652,
1159,
1453,
4072,
12,
314,
1072,
570,
911,
440,
506,
6042,
14,
961,
365,
272,
19829,
370,
2304,
314,
25568,
402,
7526,
1584,
641,
1900,
5124,
14,
272,
408,
339,
327,
5574,
315,
314,
1324,
666,
14,
272,
289,
275,
1551,
8,
1210,
63,
515,
12,
298,
4848,
531,
272,
862,
26,
267,
666,
275,
289,
14,
739,
342,
272,
3753,
26,
267,
289,
14,
1600,
342,
339,
327,
14795,
314,
20873,
14,
272,
367,
5163,
63,
875,
12,
15895,
315,
20873,
26,
267,
5163,
275,
295,
14,
2014,
8,
3821,
63,
875,
9,
267,
666,
275,
5163,
14,
954,
8,
15895,
12,
666,
9,
339,
327,
7523,
314,
1072,
1676,
2082,
3495,
14,
272,
1072,
63,
1708,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1199,
63,
515,
430,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
1199,
63,
1708,
63,
515,
304,
267,
747,
14,
8347,
8,
1199,
63,
1708,
63,
515,
9,
339,
327,
982,
314,
1072,
931,
3495,
12,
2248,
652,
436,
6540,
370,
314,
7526,
4072,
14,
272,
340,
747,
14,
515,
14,
2444,
8,
1199,
63,
515,
304,
267,
1453,
63,
576,
275,
488,
267,
862,
26,
288,
289,
275,
1551,
8,
1199,
63,
515,
12,
298,
4848,
531,
288,
862,
26,
355,
1453,
63,
576,
275,
289,
14,
739,
342,
288,
871,
26,
355,
1453,
63,
576,
275,
488,
288,
289,
14,
1600,
342,
267,
871,
26,
288,
1453,
63,
576,
275,
488,
398,
340,
1453,
63,
576,
365,
440,
488,
436,
1453,
63,
576,
508,
666,
26,
288,
372,
756,
339,
327,
6990,
314,
1072,
4072,
14,
272,
289,
275,
1551,
8,
1199,
63,
515,
12,
298,
6603,
531,
272,
862,
26,
267,
289,
14,
952,
8,
576,
9,
272,
3753,
26,
267,
289,
14,
1600,
342,
339,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
barykaed/Pelican-Test
|
fsp_env/Lib/site-packages/pip/_vendor/__init__.py
|
84
|
3423
|
"""
pip._vendor is for vendoring dependencies of pip to prevent needing pip to
depend on something external.
Files inside of pip._vendor should be considered immutable and should only be
updated to versions from upstream.
"""
from __future__ import absolute_import
import glob
import os.path
import sys
# By default, look in this directory for a bunch of .whl files which we will
# add to the beginning of sys.path before attempting to import anything. This
# is done to support downstream re-distributors like Debian and Fedora who
# wish to create their own Wheels for our dependencies to aid in debundling.
WHEEL_DIR = os.path.abspath(os.path.dirname(__file__))
# Actually look inside of WHEEL_DIR to find .whl files and add them to the
# front of our sys.path.
sys.path = glob.glob(os.path.join(WHEEL_DIR, "*.whl")) + sys.path
class VendorAlias(object):
def __init__(self):
self._vendor_name = __name__
self._vendor_pkg = self._vendor_name + "."
def find_module(self, fullname, path=None):
if fullname.startswith(self._vendor_pkg):
return self
def load_module(self, name):
# Ensure that this only works for the vendored name
if not name.startswith(self._vendor_pkg):
raise ImportError(
"Cannot import %s, must be a subpackage of '%s'." % (
name, self._vendor_name,
)
)
# Check to see if we already have this item in sys.modules, if we do
# then simply return that.
if name in sys.modules:
return sys.modules[name]
# Check to see if we can import the vendor name
try:
# We do this dance here because we want to try and import this
# module without hitting a recursion error because of a bunch of
# VendorAlias instances on sys.meta_path
real_meta_path = sys.meta_path[:]
try:
sys.meta_path = [
m for m in sys.meta_path
if not isinstance(m, VendorAlias)
]
__import__(name)
module = sys.modules[name]
finally:
# Re-add any additions to sys.meta_path that were made while
# during the import we just did, otherwise things like
# pip._vendor.six.moves will fail.
for m in sys.meta_path:
if m not in real_meta_path:
real_meta_path.append(m)
# Restore sys.meta_path with any new items.
sys.meta_path = real_meta_path
except ImportError:
# We can't import the vendor name, so we'll try to import the
# "real" name.
real_name = name[len(self._vendor_pkg):]
try:
__import__(real_name)
module = sys.modules[real_name]
except ImportError:
raise ImportError("No module named '%s'" % (name,))
# If we've gotten here we've found the module we're looking for, either
# as part of our vendored package, or as the real name, so we'll add
# it to sys.modules as the vendored name so that we don't have to do
# the lookup again.
sys.modules[name] = module
# Finally, return the loaded module
return module
sys.meta_path.append(VendorAlias())
|
mit
|
[
624,
199,
9983,
423,
9884,
365,
367,
373,
500,
6854,
5124,
402,
7305,
370,
7981,
1929,
316,
7305,
370,
199,
26434,
641,
6020,
5957,
14,
199,
199,
5535,
6272,
402,
7305,
423,
9884,
1077,
506,
8652,
17092,
436,
1077,
1454,
506,
199,
5334,
370,
5459,
687,
18932,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
5739,
199,
646,
747,
14,
515,
199,
646,
984,
421,
199,
3,
4885,
849,
12,
3648,
315,
642,
2082,
367,
282,
22219,
402,
1275,
2191,
76,
1584,
1314,
781,
911,
199,
3,
1050,
370,
314,
9608,
402,
984,
14,
515,
2544,
19595,
370,
492,
7003,
14,
961,
199,
3,
365,
4224,
370,
2291,
3224,
1745,
295,
13,
20231,
6622,
2839,
30445,
436,
481,
379,
11131,
3963,
199,
3,
13809,
370,
1218,
3932,
5705,
26161,
83,
367,
4154,
5124,
370,
23939,
315,
32610,
725,
2983,
14,
199,
31588,
2901,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
199,
3,
18982,
3163,
3648,
6272,
402,
644,
1645,
2901,
63,
3022,
370,
2342,
1275,
2191,
76,
1584,
436,
1050,
3062,
370,
314,
199,
3,
13738,
402,
4154,
984,
14,
515,
14,
199,
1274,
14,
515,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
31588,
2901,
63,
3022,
12,
298,
4856,
2191,
76,
2237,
435,
984,
14,
515,
421,
199,
533,
812,
7454,
14149,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
9884,
63,
354,
275,
636,
354,
363,
267,
291,
423,
9884,
63,
4600,
275,
291,
423,
9884,
63,
354,
435,
14530,
339,
347,
2342,
63,
578,
8,
277,
12,
11064,
12,
931,
29,
403,
304,
267,
340,
11064,
14,
2460,
8,
277,
423,
9884,
63,
4600,
304,
288,
372,
291,
339,
347,
2248,
63,
578,
8,
277,
12,
536,
304,
267,
327,
7523,
626,
642,
1454,
5419,
367,
314,
373,
500,
2908,
536,
267,
340,
440,
536,
14,
2460,
8,
277,
423,
9884,
63,
4600,
304,
288,
746,
3545,
8,
355,
298,
6612,
492,
450,
83,
12,
1471,
506,
282,
1007,
2491,
402,
1543,
83,
16669,
450,
334,
490,
536,
12,
291,
423,
9884,
63,
354,
12,
355,
776,
288,
776,
398,
327,
2670,
370,
1937,
340,
781,
2575,
1172,
642,
1242,
315,
984,
14,
3112,
12,
340,
781,
886,
267,
327,
2066,
9329,
372,
626,
14,
267,
340,
536,
315,
984,
14,
3112,
26,
288,
372,
984,
14,
3112,
59,
354,
61,
398,
327,
2670,
370,
1937,
340,
781,
883,
492,
314,
20868,
536,
267,
862,
26,
288,
327,
2136,
886,
642,
366,
554,
2348,
2952,
781,
2934,
370,
862,
436,
492,
642,
288,
327,
859,
1928,
9793,
1337,
282,
16189,
1125,
2952,
402,
282,
22219,
402,
288,
327,
812,
7454,
14149,
4454,
641,
984,
14,
2024,
63,
515,
288,
3363,
63,
2024,
63,
515,
275,
984,
14,
2024,
63,
515,
5873,
288,
862,
26,
355,
984,
14,
2024,
63,
515,
275,
359,
490,
333,
367,
333,
315,
984,
14,
2024,
63,
515,
490,
340,
440,
1228,
8,
77,
12,
812,
7454,
14149,
9,
355,
1622,
355,
636,
646,
721,
354,
9,
355,
859,
275,
984,
14,
3112,
59,
354,
61,
288,
3753,
26,
355,
327,
799,
13,
525,
1263,
32113,
370,
984,
14,
2024,
63,
515,
626,
4898,
6326,
1830,
355,
327,
5309,
314,
492,
781,
2951,
8103,
12,
4257,
7645,
2839,
355,
327,
7305,
423,
9884,
14,
4174,
14,
4912,
911,
2449,
14,
355,
367,
333,
315,
984,
14,
2024,
63,
515,
26,
490,
340,
333,
440,
315,
3363,
63,
2024,
63,
515,
26,
717,
3363,
63,
2024,
63,
515,
14,
740,
8,
77,
9,
2234,
327,
22379,
984,
14,
2024,
63,
515,
543,
1263,
892,
2974,
14,
355,
984,
14,
2024,
63,
515,
275,
3363,
63,
2024,
63,
515,
267,
871,
3545,
26,
288,
327,
2136,
883,
1133,
492,
314,
20868,
536,
12,
880,
781,
7171,
862,
370,
492,
314,
288,
327,
298,
3093,
2,
536,
14,
288,
3363,
63,
354,
275,
536,
59,
552,
8,
277,
423,
9884,
63,
4600,
15405,
288,
862,
26,
355,
636,
646,
721,
3093,
63,
354,
9,
355,
859,
275,
984,
14,
3112,
59,
3093,
63,
354,
61,
288,
871,
3545,
26,
355,
746,
3545,
480,
1944,
859,
4310,
1543,
83,
4065,
450,
334,
354,
4641,
398,
327,
982,
781,
9064,
4788,
724,
2348,
781,
9064,
1911,
314,
859,
781,
3984,
10023,
367,
12,
1902,
267,
327,
465,
1777,
402,
4154,
373,
500,
2908,
2559,
12,
503,
465,
314,
3363,
536,
12,
880,
781,
7171,
1050,
267,
327,
652,
370,
984,
14,
3112,
465,
314,
373,
500,
2908,
536,
880,
626,
781,
2793,
1133,
1172,
370,
886,
267,
327,
314,
4237,
4020,
14,
267,
984,
14,
3112,
59,
354,
61,
275,
859,
398,
327,
19177,
12,
372,
314,
6511,
859,
267,
372,
859,
421,
199,
1274,
14,
2024,
63,
515,
14,
740,
8,
27111,
14149,
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
] |
[
199,
9983,
423,
9884,
365,
367,
373,
500,
6854,
5124,
402,
7305,
370,
7981,
1929,
316,
7305,
370,
199,
26434,
641,
6020,
5957,
14,
199,
199,
5535,
6272,
402,
7305,
423,
9884,
1077,
506,
8652,
17092,
436,
1077,
1454,
506,
199,
5334,
370,
5459,
687,
18932,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
5739,
199,
646,
747,
14,
515,
199,
646,
984,
421,
199,
3,
4885,
849,
12,
3648,
315,
642,
2082,
367,
282,
22219,
402,
1275,
2191,
76,
1584,
1314,
781,
911,
199,
3,
1050,
370,
314,
9608,
402,
984,
14,
515,
2544,
19595,
370,
492,
7003,
14,
961,
199,
3,
365,
4224,
370,
2291,
3224,
1745,
295,
13,
20231,
6622,
2839,
30445,
436,
481,
379,
11131,
3963,
199,
3,
13809,
370,
1218,
3932,
5705,
26161,
83,
367,
4154,
5124,
370,
23939,
315,
32610,
725,
2983,
14,
199,
31588,
2901,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
199,
3,
18982,
3163,
3648,
6272,
402,
644,
1645,
2901,
63,
3022,
370,
2342,
1275,
2191,
76,
1584,
436,
1050,
3062,
370,
314,
199,
3,
13738,
402,
4154,
984,
14,
515,
14,
199,
1274,
14,
515,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
31588,
2901,
63,
3022,
12,
298,
4856,
2191,
76,
2237,
435,
984,
14,
515,
421,
199,
533,
812,
7454,
14149,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
9884,
63,
354,
275,
636,
354,
363,
267,
291,
423,
9884,
63,
4600,
275,
291,
423,
9884,
63,
354,
435,
14530,
339,
347,
2342,
63,
578,
8,
277,
12,
11064,
12,
931,
29,
403,
304,
267,
340,
11064,
14,
2460,
8,
277,
423,
9884,
63,
4600,
304,
288,
372,
291,
339,
347,
2248,
63,
578,
8,
277,
12,
536,
304,
267,
327,
7523,
626,
642,
1454,
5419,
367,
314,
373,
500,
2908,
536,
267,
340,
440,
536,
14,
2460,
8,
277,
423,
9884,
63,
4600,
304,
288,
746,
3545,
8,
355,
298,
6612,
492,
450,
83,
12,
1471,
506,
282,
1007,
2491,
402,
1543,
83,
16669,
450,
334,
490,
536,
12,
291,
423,
9884,
63,
354,
12,
355,
776,
288,
776,
398,
327,
2670,
370,
1937,
340,
781,
2575,
1172,
642,
1242,
315,
984,
14,
3112,
12,
340,
781,
886,
267,
327,
2066,
9329,
372,
626,
14,
267,
340,
536,
315,
984,
14,
3112,
26,
288,
372,
984,
14,
3112,
59,
354,
61,
398,
327,
2670,
370,
1937,
340,
781,
883,
492,
314,
20868,
536,
267,
862,
26,
288,
327,
2136,
886,
642,
366,
554,
2348,
2952,
781,
2934,
370,
862,
436,
492,
642,
288,
327,
859,
1928,
9793,
1337,
282,
16189,
1125,
2952,
402,
282,
22219,
402,
288,
327,
812,
7454,
14149,
4454,
641,
984,
14,
2024,
63,
515,
288,
3363,
63,
2024,
63,
515,
275,
984,
14,
2024,
63,
515,
5873,
288,
862,
26,
355,
984,
14,
2024,
63,
515,
275,
359,
490,
333,
367,
333,
315,
984,
14,
2024,
63,
515,
490,
340,
440,
1228,
8,
77,
12,
812,
7454,
14149,
9,
355,
1622,
355,
636,
646,
721,
354,
9,
355,
859,
275,
984,
14,
3112,
59,
354,
61,
288,
3753,
26,
355,
327,
799,
13,
525,
1263,
32113,
370,
984,
14,
2024,
63,
515,
626,
4898,
6326,
1830,
355,
327,
5309,
314,
492,
781,
2951,
8103,
12,
4257,
7645,
2839,
355,
327,
7305,
423,
9884,
14,
4174,
14,
4912,
911,
2449,
14,
355,
367,
333,
315,
984,
14,
2024,
63,
515,
26,
490,
340,
333,
440,
315,
3363,
63,
2024,
63,
515,
26,
717,
3363,
63,
2024,
63,
515,
14,
740,
8,
77,
9,
2234,
327,
22379,
984,
14,
2024,
63,
515,
543,
1263,
892,
2974,
14,
355,
984,
14,
2024,
63,
515,
275,
3363,
63,
2024,
63,
515,
267,
871,
3545,
26,
288,
327,
2136,
883,
1133,
492,
314,
20868,
536,
12,
880,
781,
7171,
862,
370,
492,
314,
288,
327,
298,
3093,
2,
536,
14,
288,
3363,
63,
354,
275,
536,
59,
552,
8,
277,
423,
9884,
63,
4600,
15405,
288,
862,
26,
355,
636,
646,
721,
3093,
63,
354,
9,
355,
859,
275,
984,
14,
3112,
59,
3093,
63,
354,
61,
288,
871,
3545,
26,
355,
746,
3545,
480,
1944,
859,
4310,
1543,
83,
4065,
450,
334,
354,
4641,
398,
327,
982,
781,
9064,
4788,
724,
2348,
781,
9064,
1911,
314,
859,
781,
3984,
10023,
367,
12,
1902,
267,
327,
465,
1777,
402,
4154,
373,
500,
2908,
2559,
12,
503,
465,
314,
3363,
536,
12,
880,
781,
7171,
1050,
267,
327,
652,
370,
984,
14,
3112,
465,
314,
373,
500,
2908,
536,
880,
626,
781,
2793,
1133,
1172,
370,
886,
267,
327,
314,
4237,
4020,
14,
267,
984,
14,
3112,
59,
354,
61,
275,
859,
398,
327,
19177,
12,
372,
314,
6511,
859,
267,
372,
859,
421,
199,
1274,
14,
2024,
63,
515,
14,
740,
8,
27111,
14149,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
joshuajan/odoo
|
addons/purchase_analytic_plans/__init__.py
|
441
|
1220
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#----------------------------------------------------------
# Init Sales
#----------------------------------------------------------
import purchase_analytic_plans
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
30346,
199,
3,
21026,
428,
7098,
199,
30346,
199,
199,
646,
15932,
63,
9782,
63,
1168,
796,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
30346,
199,
3,
21026,
428,
7098,
199,
30346,
199,
199,
646,
15932,
63,
9782,
63,
1168,
796,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lmanul/awty
|
deletesubproject.py
|
1
|
2264
|
# -*- coding: utf-8 -*- #
# Copyright 2011 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import webapp
import urllib
import webapp2
from models import *
from util import *
class DeleteSubprojectHandler(webapp2.RequestHandler):
def get(self, projectCodeParam):
projectCode = urllib.unquote(projectCodeParam)
project = Project.gql("WHERE code = '" + projectCode + "'").get()
if project == None:
self.response.headers['Status'] = 403
self.response.out.write('No project with code ' + projectCode)
return
code = self.request.GET.get('code');
if code == None:
code = ''
subproject = Subproject.gql("WHERE code ='" + code + "'").get()
if subproject == None:
self.response.headers['Status'] = 403
self.response.out.write('No subproject with code ' + code)
return
if not Util.getUsernameFromEmail(users.get_current_user().email()) in subproject.admins and \
not Util.getUsernameFromEmail(users.get_current_user().email()) in project.admins:
self.response.headers['Status'] = 403
self.response.out.write('Only admins of a subproject can delete it')
return
subproject.delete()
# Also delete all features and tasks related to this subproject.
allRelatedFeatures = Feature.gql("WHERE subprojectCode = '" +
subproject.code + "'")
for f in allRelatedFeatures:
allRelatedTasks = Task.gql("WHERE featureCode = '" + f.code + "'")
for t in allRelatedTasks:
t.delete()
f.delete()
app = webapp2.WSGIApplication(
[
('/(.*)/deletesubproject', DeleteSubprojectHandler),
], debug=True)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
327,
199,
3,
1898,
7760,
4475,
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,
259,
1455,
15596,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
4390,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
1592,
199,
504,
6233,
14,
15358,
14,
832,
492,
24812,
523,
199,
199,
646,
4011,
199,
646,
24812,
18,
199,
199,
504,
1709,
492,
627,
199,
504,
4884,
492,
627,
199,
199,
533,
8496,
2610,
1715,
2461,
8,
22632,
18,
14,
11149,
304,
523,
347,
664,
8,
277,
12,
2199,
3034,
4098,
304,
272,
2199,
3034,
275,
4011,
14,
12240,
8,
1715,
3034,
4098,
9,
272,
2199,
275,
7290,
14,
71,
1710,
480,
17688,
1233,
275,
5522,
435,
2199,
3034,
435,
3546,
3471,
362,
342,
272,
340,
2199,
508,
488,
26,
489,
291,
14,
1310,
14,
2139,
459,
3694,
418,
275,
13269,
489,
291,
14,
1310,
14,
548,
14,
952,
360,
1944,
2199,
543,
1233,
283,
435,
2199,
3034,
9,
489,
372,
339,
1233,
275,
291,
14,
1069,
14,
2970,
14,
362,
360,
600,
11339,
272,
340,
1233,
508,
488,
26,
489,
1233,
275,
2125,
272,
1007,
1715,
275,
4804,
1715,
14,
71,
1710,
480,
17688,
1233,
275,
4065,
435,
1233,
435,
3546,
3471,
362,
342,
272,
340,
1007,
1715,
508,
488,
26,
489,
291,
14,
1310,
14,
2139,
459,
3694,
418,
275,
13269,
489,
291,
14,
1310,
14,
548,
14,
952,
360,
1944,
1007,
1715,
543,
1233,
283,
435,
1233,
9,
489,
372,
339,
340,
440,
21248,
14,
362,
13355,
2532,
7035,
8,
3707,
14,
362,
63,
1818,
63,
751,
1252,
2123,
1012,
315,
1007,
1715,
14,
23121,
436,
971,
2126,
440,
21248,
14,
362,
13355,
2532,
7035,
8,
3707,
14,
362,
63,
1818,
63,
751,
1252,
2123,
1012,
315,
2199,
14,
23121,
26,
489,
291,
14,
1310,
14,
2139,
459,
3694,
418,
275,
13269,
489,
291,
14,
1310,
14,
548,
14,
952,
360,
5903,
4628,
83,
402,
282,
1007,
1715,
883,
3145,
652,
358,
489,
372,
272,
1007,
1715,
14,
1807,
342,
339,
327,
6121,
3145,
1006,
4534,
436,
6527,
4048,
370,
642,
1007,
1715,
14,
272,
1006,
13885,
10807,
275,
13407,
14,
71,
1710,
480,
17688,
1007,
1715,
3034,
275,
5522,
435,
267,
1007,
1715,
14,
600,
435,
3546,
531,
272,
367,
289,
315,
1006,
13885,
10807,
26,
489,
1006,
13885,
19295,
275,
8495,
14,
71,
1710,
480,
17688,
3878,
3034,
275,
5522,
435,
289,
14,
600,
435,
3546,
531,
489,
367,
307,
315,
1006,
13885,
19295,
26,
267,
307,
14,
1807,
342,
489,
289,
14,
1807,
342,
421,
199,
571,
275,
24812,
18,
14,
16828,
5039,
8,
267,
359,
881,
661,
7985,
2795,
2447,
26289,
456,
1715,
297,
8496,
2610,
1715,
2461,
395,
267,
2156,
3105,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
327,
199,
3,
1898,
7760,
4475,
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,
259,
1455,
15596,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
4390,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
1592,
199,
504,
6233,
14,
15358,
14,
832,
492,
24812,
523,
199,
199,
646,
4011,
199,
646,
24812,
18,
199,
199,
504,
1709,
492,
627,
199,
504,
4884,
492,
627,
199,
199,
533,
8496,
2610,
1715,
2461,
8,
22632,
18,
14,
11149,
304,
523,
347,
664,
8,
277,
12,
2199,
3034,
4098,
304,
272,
2199,
3034,
275,
4011,
14,
12240,
8,
1715,
3034,
4098,
9,
272,
2199,
275,
7290,
14,
71,
1710,
480,
17688,
1233,
275,
5522,
435,
2199,
3034,
435,
3546,
3471,
362,
342,
272,
340,
2199,
508,
488,
26,
489,
291,
14,
1310,
14,
2139,
459,
3694,
418,
275,
13269,
489,
291,
14,
1310,
14,
548,
14,
952,
360,
1944,
2199,
543,
1233,
283,
435,
2199,
3034,
9,
489,
372,
339,
1233,
275,
291,
14,
1069,
14,
2970,
14,
362,
360,
600,
11339,
272,
340,
1233,
508,
488,
26,
489,
1233,
275,
2125,
272,
1007,
1715,
275,
4804,
1715,
14,
71,
1710,
480,
17688,
1233,
275,
4065,
435,
1233,
435,
3546,
3471,
362,
342,
272,
340,
1007,
1715,
508,
488,
26,
489,
291,
14,
1310,
14,
2139,
459,
3694,
418,
275,
13269,
489,
291,
14,
1310,
14,
548,
14,
952,
360,
1944,
1007,
1715,
543,
1233,
283,
435,
1233,
9,
489,
372,
339,
340,
440,
21248,
14,
362,
13355,
2532,
7035,
8,
3707,
14,
362,
63,
1818,
63,
751,
1252,
2123,
1012,
315,
1007,
1715,
14,
23121,
436,
971,
2126,
440,
21248,
14,
362,
13355,
2532,
7035,
8,
3707,
14,
362,
63,
1818,
63,
751,
1252,
2123,
1012,
315,
2199,
14,
23121,
26,
489,
291,
14,
1310,
14,
2139,
459,
3694,
418,
275,
13269,
489,
291,
14,
1310,
14,
548,
14,
952,
360,
5903,
4628,
83,
402,
282,
1007,
1715,
883,
3145,
652,
358,
489,
372,
272,
1007,
1715,
14,
1807,
342,
339,
327,
6121,
3145,
1006,
4534,
436,
6527,
4048,
370,
642,
1007,
1715,
14,
272,
1006,
13885,
10807,
275,
13407,
14,
71,
1710,
480,
17688,
1007,
1715,
3034,
275,
5522,
435,
267,
1007,
1715,
14,
600,
435,
3546,
531,
272,
367,
289,
315,
1006,
13885,
10807,
26,
489,
1006,
13885,
19295,
275,
8495,
14,
71,
1710,
480,
17688,
3878,
3034,
275,
5522,
435,
289,
14,
600,
435,
3546,
531,
489,
367,
307,
315,
1006,
13885,
19295,
26,
267,
307,
14,
1807,
342,
489,
289,
14,
1807,
342,
421,
199,
571,
275,
24812,
18,
14,
16828,
5039,
8,
267,
359,
881,
661,
7985,
2795,
2447,
26289,
456,
1715,
297,
8496,
2610,
1715,
2461,
395,
267,
2156,
3105,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Obus/scikit-learn
|
benchmarks/bench_glmnet.py
|
297
|
3848
|
"""
To run this, you'll need to have installed.
* glmnet-python
* scikit-learn (of course)
Does two benchmarks
First, we fix a training set and increase the number of
samples. Then we plot the computation time as function of
the number of samples.
In the second benchmark, we increase the number of dimensions of the
training set. Then we plot the computation time as function of
the number of dimensions.
In both cases, only 10% of the features are informative.
"""
import numpy as np
import gc
from time import time
from sklearn.datasets.samples_generator import make_regression
alpha = 0.1
# alpha = 0.01
def rmse(a, b):
return np.sqrt(np.mean((a - b) ** 2))
def bench(factory, X, Y, X_test, Y_test, ref_coef):
gc.collect()
# start time
tstart = time()
clf = factory(alpha=alpha).fit(X, Y)
delta = (time() - tstart)
# stop time
print("duration: %0.3fs" % delta)
print("rmse: %f" % rmse(Y_test, clf.predict(X_test)))
print("mean coef abs diff: %f" % abs(ref_coef - clf.coef_.ravel()).mean())
return delta
if __name__ == '__main__':
from glmnet.elastic_net import Lasso as GlmnetLasso
from sklearn.linear_model import Lasso as ScikitLasso
# Delayed import of pylab
import pylab as pl
scikit_results = []
glmnet_results = []
n = 20
step = 500
n_features = 1000
n_informative = n_features / 10
n_test_samples = 1000
for i in range(1, n + 1):
print('==================')
print('Iteration %s of %s' % (i, n))
print('==================')
X, Y, coef_ = make_regression(
n_samples=(i * step) + n_test_samples, n_features=n_features,
noise=0.1, n_informative=n_informative, coef=True)
X_test = X[-n_test_samples:]
Y_test = Y[-n_test_samples:]
X = X[:(i * step)]
Y = Y[:(i * step)]
print("benchmarking scikit-learn: ")
scikit_results.append(bench(ScikitLasso, X, Y, X_test, Y_test, coef_))
print("benchmarking glmnet: ")
glmnet_results.append(bench(GlmnetLasso, X, Y, X_test, Y_test, coef_))
pl.clf()
xx = range(0, n * step, step)
pl.title('Lasso regression on sample dataset (%d features)' % n_features)
pl.plot(xx, scikit_results, 'b-', label='scikit-learn')
pl.plot(xx, glmnet_results, 'r-', label='glmnet')
pl.legend()
pl.xlabel('number of samples to classify')
pl.ylabel('Time (s)')
pl.show()
# now do a benchmark where the number of points is fixed
# and the variable is the number of features
scikit_results = []
glmnet_results = []
n = 20
step = 100
n_samples = 500
for i in range(1, n + 1):
print('==================')
print('Iteration %02d of %02d' % (i, n))
print('==================')
n_features = i * step
n_informative = n_features / 10
X, Y, coef_ = make_regression(
n_samples=(i * step) + n_test_samples, n_features=n_features,
noise=0.1, n_informative=n_informative, coef=True)
X_test = X[-n_test_samples:]
Y_test = Y[-n_test_samples:]
X = X[:n_samples]
Y = Y[:n_samples]
print("benchmarking scikit-learn: ")
scikit_results.append(bench(ScikitLasso, X, Y, X_test, Y_test, coef_))
print("benchmarking glmnet: ")
glmnet_results.append(bench(GlmnetLasso, X, Y, X_test, Y_test, coef_))
xx = np.arange(100, 100 + n * step, step)
pl.figure('scikit-learn vs. glmnet benchmark results')
pl.title('Regression in high dimensional spaces (%d samples)' % n_samples)
pl.plot(xx, scikit_results, 'b-', label='scikit-learn')
pl.plot(xx, glmnet_results, 'r-', label='glmnet')
pl.legend()
pl.xlabel('number of features')
pl.ylabel('Time (s)')
pl.axis('tight')
pl.show()
|
bsd-3-clause
|
[
624,
199,
1378,
1255,
642,
12,
1265,
7171,
1929,
370,
1172,
4903,
14,
819,
627,
6482,
77,
846,
13,
1548,
523,
627,
6276,
6065,
13,
4643,
334,
1618,
2518,
9,
199,
199,
6586,
2877,
12338,
83,
199,
199,
7147,
12,
781,
5325,
282,
6093,
663,
436,
19781,
314,
1329,
402,
199,
3356,
14,
9442,
781,
5137,
314,
14009,
900,
465,
805,
402,
199,
1589,
1329,
402,
5845,
14,
199,
199,
607,
314,
3499,
12338,
12,
781,
19781,
314,
1329,
402,
7365,
402,
314,
199,
7588,
663,
14,
9442,
781,
5137,
314,
14009,
900,
465,
805,
402,
199,
1589,
1329,
402,
7365,
14,
199,
199,
607,
3865,
5560,
12,
1454,
1616,
5,
402,
314,
4534,
787,
315,
20889,
14,
199,
624,
199,
646,
2680,
465,
980,
199,
646,
9486,
199,
504,
900,
492,
900,
199,
504,
6357,
14,
12281,
14,
3356,
63,
4679,
492,
1852,
63,
12513,
199,
199,
4468,
275,
378,
14,
17,
199,
3,
5131,
275,
378,
14,
614,
421,
199,
318,
14267,
261,
8,
65,
12,
330,
304,
272,
372,
980,
14,
5079,
8,
1590,
14,
3670,
1332,
65,
446,
330,
9,
1011,
499,
430,
421,
199,
318,
26456,
8,
3702,
12,
1323,
12,
1488,
12,
1323,
63,
396,
12,
1488,
63,
396,
12,
2984,
63,
8009,
304,
272,
9486,
14,
7112,
342,
339,
327,
1343,
900,
272,
29921,
275,
900,
342,
272,
6975,
275,
6434,
8,
4468,
29,
4468,
680,
3269,
8,
56,
12,
1488,
9,
272,
5762,
275,
334,
521,
342,
446,
29921,
9,
272,
327,
3631,
900,
339,
870,
480,
5553,
26,
450,
16,
14,
19,
2319,
2,
450,
5762,
9,
272,
870,
480,
5682,
261,
26,
450,
70,
2,
450,
14267,
261,
8,
57,
63,
396,
12,
6975,
14,
6892,
8,
56,
63,
396,
1724,
272,
870,
480,
3670,
7355,
2853,
3915,
26,
450,
70,
2,
450,
2853,
8,
1121,
63,
8009,
446,
6975,
14,
8009,
3754,
11186,
8801,
3670,
1012,
272,
372,
5762,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
687,
6482,
77,
846,
14,
15565,
63,
846,
492,
29029,
465,
598,
14344,
846,
27537,
272,
687,
6357,
14,
6676,
63,
1238,
492,
29029,
465,
16578,
6065,
27537,
272,
327,
18464,
1187,
379,
492,
402,
19199,
272,
492,
19199,
465,
1620,
339,
6276,
6065,
63,
2604,
275,
942,
272,
6482,
77,
846,
63,
2604,
275,
942,
272,
302,
275,
3388,
272,
3650,
275,
6891,
272,
302,
63,
3179,
275,
5198,
272,
302,
63,
27666,
275,
302,
63,
3179,
1182,
1616,
272,
302,
63,
396,
63,
3356,
275,
5198,
272,
367,
284,
315,
1425,
8,
17,
12,
302,
435,
413,
304,
267,
870,
360,
1280,
18900,
267,
870,
360,
8666,
450,
83,
402,
450,
83,
7,
450,
334,
73,
12,
302,
430,
267,
870,
360,
1280,
18900,
398,
1323,
12,
1488,
12,
7355,
63,
275,
1852,
63,
12513,
8,
288,
302,
63,
3356,
2687,
73,
627,
3650,
9,
435,
302,
63,
396,
63,
3356,
12,
302,
63,
3179,
29,
78,
63,
3179,
12,
288,
11145,
29,
16,
14,
17,
12,
302,
63,
27666,
29,
78,
63,
27666,
12,
7355,
29,
549,
9,
398,
1323,
63,
396,
275,
1323,
1988,
78,
63,
396,
63,
3356,
2938,
267,
1488,
63,
396,
275,
1488,
1988,
78,
63,
396,
63,
3356,
2938,
267,
1323,
275,
1323,
1491,
8,
73,
627,
3650,
1874,
267,
1488,
275,
1488,
1491,
8,
73,
627,
3650,
1874,
398,
870,
480,
11861,
316,
6276,
6065,
13,
4643,
26,
6099,
267,
6276,
6065,
63,
2604,
14,
740,
8,
16571,
8,
29231,
6065,
27537,
12,
1323,
12,
1488,
12,
1323,
63,
396,
12,
1488,
63,
396,
12,
7355,
13309,
267,
870,
480,
11861,
316,
6482,
77,
846,
26,
6099,
267,
6482,
77,
846,
63,
2604,
14,
740,
8,
16571,
8,
39,
14344,
846,
27537,
12,
1323,
12,
1488,
12,
1323,
63,
396,
12,
1488,
63,
396,
12,
7355,
13309,
339,
1620,
14,
9694,
342,
272,
19379,
275,
1425,
8,
16,
12,
302,
627,
3650,
12,
3650,
9,
272,
1620,
14,
1213,
360,
27537,
10864,
641,
2690,
4789,
4366,
68,
4534,
3171,
450,
302,
63,
3179,
9,
272,
1620,
14,
2798,
8,
2154,
12,
6276,
6065,
63,
2604,
12,
283,
66,
14382,
1768,
534,
551,
3258,
390,
13,
4643,
358,
272,
1620,
14,
2798,
8,
2154,
12,
6482,
77,
846,
63,
2604,
12,
283,
82,
14382,
1768,
534,
3528,
77,
846,
358,
272,
1620,
14,
10231,
342,
272,
1620,
14,
14168,
360,
1955,
402,
5845,
370,
28837,
358,
272,
1620,
14,
13849,
360,
1366,
334,
83,
5942,
272,
1620,
14,
2384,
342,
339,
327,
3063,
886,
282,
12338,
2382,
314,
1329,
402,
4501,
365,
6317,
272,
327,
436,
314,
1750,
365,
314,
1329,
402,
4534,
339,
6276,
6065,
63,
2604,
275,
942,
272,
6482,
77,
846,
63,
2604,
275,
942,
272,
302,
275,
3388,
272,
3650,
275,
2948,
272,
302,
63,
3356,
275,
6891,
339,
367,
284,
315,
1425,
8,
17,
12,
302,
435,
413,
304,
267,
870,
360,
1280,
18900,
267,
870,
360,
8666,
450,
996,
68,
402,
450,
996,
68,
7,
450,
334,
73,
12,
302,
430,
267,
870,
360,
1280,
18900,
267,
302,
63,
3179,
275,
284,
627,
3650,
267,
302,
63,
27666,
275,
302,
63,
3179,
1182,
1616,
398,
1323,
12,
1488,
12,
7355,
63,
275,
1852,
63,
12513,
8,
288,
302,
63,
3356,
2687,
73,
627,
3650,
9,
435,
302,
63,
396,
63,
3356,
12,
302,
63,
3179,
29,
78,
63,
3179,
12,
288,
11145,
29,
16,
14,
17,
12,
302,
63,
27666,
29,
78,
63,
27666,
12,
7355,
29,
549,
9,
398,
1323,
63,
396,
275,
1323,
1988,
78,
63,
396,
63,
3356,
2938,
267,
1488,
63,
396,
275,
1488,
1988,
78,
63,
396,
63,
3356,
2938,
267,
1323,
275,
1323,
1491,
78,
63,
3356,
61,
267,
1488,
275,
1488,
1491,
78,
63,
3356,
61,
398,
870,
480,
11861,
316,
6276,
6065,
13,
4643,
26,
6099,
267,
6276,
6065,
63,
2604,
14,
740,
8,
16571,
8,
29231,
6065,
27537,
12,
1323,
12,
1488,
12,
1323,
63,
396,
12,
1488,
63,
396,
12,
7355,
13309,
267,
870,
480,
11861,
316,
6482,
77,
846,
26,
6099,
267,
6482,
77,
846,
63,
2604,
14,
740,
8,
16571,
8,
39,
14344,
846,
27537,
12,
1323
] |
[
199,
1378,
1255,
642,
12,
1265,
7171,
1929,
370,
1172,
4903,
14,
819,
627,
6482,
77,
846,
13,
1548,
523,
627,
6276,
6065,
13,
4643,
334,
1618,
2518,
9,
199,
199,
6586,
2877,
12338,
83,
199,
199,
7147,
12,
781,
5325,
282,
6093,
663,
436,
19781,
314,
1329,
402,
199,
3356,
14,
9442,
781,
5137,
314,
14009,
900,
465,
805,
402,
199,
1589,
1329,
402,
5845,
14,
199,
199,
607,
314,
3499,
12338,
12,
781,
19781,
314,
1329,
402,
7365,
402,
314,
199,
7588,
663,
14,
9442,
781,
5137,
314,
14009,
900,
465,
805,
402,
199,
1589,
1329,
402,
7365,
14,
199,
199,
607,
3865,
5560,
12,
1454,
1616,
5,
402,
314,
4534,
787,
315,
20889,
14,
199,
624,
199,
646,
2680,
465,
980,
199,
646,
9486,
199,
504,
900,
492,
900,
199,
504,
6357,
14,
12281,
14,
3356,
63,
4679,
492,
1852,
63,
12513,
199,
199,
4468,
275,
378,
14,
17,
199,
3,
5131,
275,
378,
14,
614,
421,
199,
318,
14267,
261,
8,
65,
12,
330,
304,
272,
372,
980,
14,
5079,
8,
1590,
14,
3670,
1332,
65,
446,
330,
9,
1011,
499,
430,
421,
199,
318,
26456,
8,
3702,
12,
1323,
12,
1488,
12,
1323,
63,
396,
12,
1488,
63,
396,
12,
2984,
63,
8009,
304,
272,
9486,
14,
7112,
342,
339,
327,
1343,
900,
272,
29921,
275,
900,
342,
272,
6975,
275,
6434,
8,
4468,
29,
4468,
680,
3269,
8,
56,
12,
1488,
9,
272,
5762,
275,
334,
521,
342,
446,
29921,
9,
272,
327,
3631,
900,
339,
870,
480,
5553,
26,
450,
16,
14,
19,
2319,
2,
450,
5762,
9,
272,
870,
480,
5682,
261,
26,
450,
70,
2,
450,
14267,
261,
8,
57,
63,
396,
12,
6975,
14,
6892,
8,
56,
63,
396,
1724,
272,
870,
480,
3670,
7355,
2853,
3915,
26,
450,
70,
2,
450,
2853,
8,
1121,
63,
8009,
446,
6975,
14,
8009,
3754,
11186,
8801,
3670,
1012,
272,
372,
5762,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
687,
6482,
77,
846,
14,
15565,
63,
846,
492,
29029,
465,
598,
14344,
846,
27537,
272,
687,
6357,
14,
6676,
63,
1238,
492,
29029,
465,
16578,
6065,
27537,
272,
327,
18464,
1187,
379,
492,
402,
19199,
272,
492,
19199,
465,
1620,
339,
6276,
6065,
63,
2604,
275,
942,
272,
6482,
77,
846,
63,
2604,
275,
942,
272,
302,
275,
3388,
272,
3650,
275,
6891,
272,
302,
63,
3179,
275,
5198,
272,
302,
63,
27666,
275,
302,
63,
3179,
1182,
1616,
272,
302,
63,
396,
63,
3356,
275,
5198,
272,
367,
284,
315,
1425,
8,
17,
12,
302,
435,
413,
304,
267,
870,
360,
1280,
18900,
267,
870,
360,
8666,
450,
83,
402,
450,
83,
7,
450,
334,
73,
12,
302,
430,
267,
870,
360,
1280,
18900,
398,
1323,
12,
1488,
12,
7355,
63,
275,
1852,
63,
12513,
8,
288,
302,
63,
3356,
2687,
73,
627,
3650,
9,
435,
302,
63,
396,
63,
3356,
12,
302,
63,
3179,
29,
78,
63,
3179,
12,
288,
11145,
29,
16,
14,
17,
12,
302,
63,
27666,
29,
78,
63,
27666,
12,
7355,
29,
549,
9,
398,
1323,
63,
396,
275,
1323,
1988,
78,
63,
396,
63,
3356,
2938,
267,
1488,
63,
396,
275,
1488,
1988,
78,
63,
396,
63,
3356,
2938,
267,
1323,
275,
1323,
1491,
8,
73,
627,
3650,
1874,
267,
1488,
275,
1488,
1491,
8,
73,
627,
3650,
1874,
398,
870,
480,
11861,
316,
6276,
6065,
13,
4643,
26,
6099,
267,
6276,
6065,
63,
2604,
14,
740,
8,
16571,
8,
29231,
6065,
27537,
12,
1323,
12,
1488,
12,
1323,
63,
396,
12,
1488,
63,
396,
12,
7355,
13309,
267,
870,
480,
11861,
316,
6482,
77,
846,
26,
6099,
267,
6482,
77,
846,
63,
2604,
14,
740,
8,
16571,
8,
39,
14344,
846,
27537,
12,
1323,
12,
1488,
12,
1323,
63,
396,
12,
1488,
63,
396,
12,
7355,
13309,
339,
1620,
14,
9694,
342,
272,
19379,
275,
1425,
8,
16,
12,
302,
627,
3650,
12,
3650,
9,
272,
1620,
14,
1213,
360,
27537,
10864,
641,
2690,
4789,
4366,
68,
4534,
3171,
450,
302,
63,
3179,
9,
272,
1620,
14,
2798,
8,
2154,
12,
6276,
6065,
63,
2604,
12,
283,
66,
14382,
1768,
534,
551,
3258,
390,
13,
4643,
358,
272,
1620,
14,
2798,
8,
2154,
12,
6482,
77,
846,
63,
2604,
12,
283,
82,
14382,
1768,
534,
3528,
77,
846,
358,
272,
1620,
14,
10231,
342,
272,
1620,
14,
14168,
360,
1955,
402,
5845,
370,
28837,
358,
272,
1620,
14,
13849,
360,
1366,
334,
83,
5942,
272,
1620,
14,
2384,
342,
339,
327,
3063,
886,
282,
12338,
2382,
314,
1329,
402,
4501,
365,
6317,
272,
327,
436,
314,
1750,
365,
314,
1329,
402,
4534,
339,
6276,
6065,
63,
2604,
275,
942,
272,
6482,
77,
846,
63,
2604,
275,
942,
272,
302,
275,
3388,
272,
3650,
275,
2948,
272,
302,
63,
3356,
275,
6891,
339,
367,
284,
315,
1425,
8,
17,
12,
302,
435,
413,
304,
267,
870,
360,
1280,
18900,
267,
870,
360,
8666,
450,
996,
68,
402,
450,
996,
68,
7,
450,
334,
73,
12,
302,
430,
267,
870,
360,
1280,
18900,
267,
302,
63,
3179,
275,
284,
627,
3650,
267,
302,
63,
27666,
275,
302,
63,
3179,
1182,
1616,
398,
1323,
12,
1488,
12,
7355,
63,
275,
1852,
63,
12513,
8,
288,
302,
63,
3356,
2687,
73,
627,
3650,
9,
435,
302,
63,
396,
63,
3356,
12,
302,
63,
3179,
29,
78,
63,
3179,
12,
288,
11145,
29,
16,
14,
17,
12,
302,
63,
27666,
29,
78,
63,
27666,
12,
7355,
29,
549,
9,
398,
1323,
63,
396,
275,
1323,
1988,
78,
63,
396,
63,
3356,
2938,
267,
1488,
63,
396,
275,
1488,
1988,
78,
63,
396,
63,
3356,
2938,
267,
1323,
275,
1323,
1491,
78,
63,
3356,
61,
267,
1488,
275,
1488,
1491,
78,
63,
3356,
61,
398,
870,
480,
11861,
316,
6276,
6065,
13,
4643,
26,
6099,
267,
6276,
6065,
63,
2604,
14,
740,
8,
16571,
8,
29231,
6065,
27537,
12,
1323,
12,
1488,
12,
1323,
63,
396,
12,
1488,
63,
396,
12,
7355,
13309,
267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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
] |
windy1/headerman.py
|
headerman/headerman.py
|
1
|
5997
|
"""
Copyright (c) 2014 Walker Crouse
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 sys
import argparse
import glob
import os
import time
import re
# Cache extension headers so we don't need to create them each time
headers = {}
# multiline comment openers for different file extensions
openmulti = {
"/*": ["java", "c", "cc", "h", "hh", "hpp", "cpp", "php", "js", "m", "cs"],
'"""': ["py"],
": '": ["sh"],
"=begin": ['rb'],
}
# closers mapped to the openers
closemulti = {
"/*": " */",
'"""': '"""',
": '": "'",
"=begin": "=end"
}
# prefixes before each line between opener and closers
prefixes = {
"/*": " * ",
'"""': "",
": '": "",
"=begin": ""
}
def main(argv):
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("-rm", "--remove", action="store_true",
help="whether the headers should be removed instead of added")
parser.add_argument("-i", "--input-file", help="file to read header from", dest="header")
parser.add_argument("-o", "--output-dir", help="directory to search for file in", dest="directory")
parser.add_argument("-r", "--recursive", action="store_true",
help="whether to update headers in the directory recursively")
parser.add_argument("-e", "--extensions", action="append", default=[], help="the extensions to update")
opts = parser.parse_args(argv)
# no directory?
if opts.directory is None:
print("provide a directory")
parser.parse_args(["-h"])
if opts.remove:
remove_headers(opts.directory, opts.recursive, opts.extensions)
elif opts.header is None:
# trying to add headers but has no input
print("provide an input header")
parser.parse_args(["-h"])
else:
add_headers(opts.header, opts.directory, opts.extensions, opts.recursive)
def add_headers(file, outdir, exts, recursive):
# get the header
with open(file) as f:
header = f.read()
f.close()
files = get_files(outdir, exts, recursive)
# try to write_header to each file
operate(files, header, write_header)
def remove_headers(dir, recursive, exts):
files = get_files(dir, exts, recursive)
operate(files, None, remove_header)
def operate(files, header, op):
confirm(len(files))
modified = 0
for i in xrange(len(files)):
if op(files[i], header):
modified += 1
pcent = float(i+1) / len(files)
update_progress(pcent*100, files[i])
print("\n" + str(modified) + " files modified.")
def confirm(amt):
while True:
a = raw_input("This operation could potentially modify " + str(amt) + " files. Continue? [y/n]: ")
if a == 'y':
break
elif a == 'n':
sys.exit()
def write_header(file, header):
# get the extension
ext = get_ext(file)
if ext in headers:
# check if we have a version cached for this extension
header = headers[ext]
else:
# create header according to the multiline comment in that lang
newheader = []
lns = header.split("\n")
opener, prefix, closer = get_comment_container(ext)
newheader.append(opener)
newheader.extend([prefix + ln for ln in lns])
headers[ext] = header = "\n".join(newheader).rstrip("\r\n") + "\n" + closer
with open(file, 'r+') as f:
content = f.read()
if content.startswith(header):
# Already has header
f.close()
return False
# Add header + existing content
f.seek(0, 0)
f.write(header.rstrip("\r\n") + "\n" + content)
f.close()
return True
def remove_header(file, header):
ext = get_ext(file)
with open(file, 'r') as f:
content = f.read()
opener, prefix, closer = get_comment_container(ext)
if opener == "" or not content.startswith(opener):
f.close()
return False
begin = 0
end = content.find(closer)
if end == -1:
return False
end = content.find(closer, len(closer)) if opener == closer else end
if end == -1:
return False
content = content[end+len(closer):].lstrip()
f.close()
with open(file, 'w') as f:
f.write(content)
f.close()
return True
def get_ext(file):
return os.path.splitext(file)[1][1:]
def update_progress(pcent, msg):
sys.stdout.write("%d%% [%s] \r" % (pcent, msg))
sys.stdout.flush()
time.sleep(0.1)
def get_comment_container(ext):
for key in openmulti:
# find opener
if ext in openmulti[key]:
# return opener, prefix, then closer
return key, prefixes[key], closemulti[key]
return "", "", ""
def get_files(dir, exts, recursive):
files = []
exts = ["." + e for e in exts]
if not recursive:
if len(exts) > 0:
for ext in exts:
files.extend(glob.glob(os.path.join(dir, "*" + ext)))
else:
files.extend(glob.glob(os.path.join(dir, "*")))
else:
for root, subdirs, fls in os.walk(dir):
files.extend([os.path.join(root, f) for f in fls])
if len(exts) > 0:
files = [f for f in files if f.endswith(tuple(exts))]
return files
if __name__ == "__main__":
main(sys.argv[1:])
|
mit
|
[
624,
199,
7384,
334,
67,
9,
6927,
644,
14976,
445,
293,
1180,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
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,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
624,
199,
646,
984,
199,
646,
7534,
199,
646,
5739,
199,
646,
747,
199,
646,
900,
199,
646,
295,
421,
199,
3,
11977,
3329,
2323,
880,
781,
2793,
1133,
1929,
370,
1218,
3062,
1924,
900,
199,
2139,
275,
1052,
199,
199,
3,
21838,
3721,
16088,
83,
367,
3365,
570,
5478,
199,
1490,
3029,
275,
469,
523,
3286,
10,
582,
2097,
6138,
401,
298,
67,
401,
298,
2055,
401,
298,
72,
401,
298,
12156,
401,
298,
72,
802,
401,
298,
5910,
401,
298,
8624,
401,
298,
3596,
401,
298,
77,
401,
298,
1259,
2255,
523,
283,
624,
356,
2097,
647,
2255,
523,
7244,
283,
582,
2097,
609,
2255,
523,
298,
29,
5037,
582,
788,
4848,
995,
199,
93,
199,
199,
3,
2463,
21317,
9994,
370,
314,
16088,
83,
199,
1600,
3029,
275,
469,
523,
3286,
10,
582,
298,
627,
10665,
523,
283,
624,
356,
283,
624,
297,
523,
7244,
283,
582,
3546,
401,
523,
298,
29,
5037,
582,
298,
29,
500,
2,
199,
93,
199,
199,
3,
13158,
2544,
1924,
1004,
3382,
16088,
436,
2463,
21317,
199,
14124,
275,
469,
523,
3286,
10,
582,
298,
627,
3872,
523,
283,
624,
356,
4873,
523,
7244,
283,
582,
4873,
523,
298,
29,
5037,
582,
3087,
199,
93,
421,
199,
318,
2446,
8,
3020,
304,
523,
327,
2198,
2368,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
6096,
5682,
401,
4320,
2168,
401,
1595,
628,
1617,
63,
2052,
401,
221,
1993,
1720,
628,
87,
3081,
314,
2323,
1077,
506,
4829,
3140,
402,
3483,
531,
523,
1798,
14,
525,
63,
2094,
6096,
73,
401,
4320,
1210,
13,
493,
401,
1720,
628,
493,
370,
1586,
1406,
687,
401,
2053,
628,
1291,
531,
523,
1798,
14,
525,
63,
2094,
6096,
79,
401,
4320,
1199,
13,
694,
401,
1720,
628,
3619,
370,
2754,
367,
570,
315,
401,
2053,
628,
3619,
531,
16421,
1798,
14,
525,
63,
2094,
6096,
82,
401,
4320,
9931,
401,
1595,
628,
1617,
63,
2052,
401,
221,
1993,
1720,
628,
87,
3081,
370,
1678,
2323,
315,
314,
2082,
15035,
531,
523,
1798,
14,
525,
63,
2094,
6096,
69,
401,
4320,
5359,
401,
1595,
628,
740,
401,
849,
6034,
1720,
628,
1589,
5478,
370,
1678,
531,
819,
3999,
275,
1798,
14,
1122,
63,
589,
8,
3020,
9,
819,
327,
949,
2082,
31,
523,
340,
3999,
14,
3619,
365,
488,
26,
272,
870,
480,
20824,
282,
2082,
531,
272,
1798,
14,
1122,
63,
589,
5234,
13,
72,
3135,
819,
340,
3999,
14,
2168,
26,
272,
2813,
63,
2139,
8,
3291,
14,
3619,
12,
3999,
14,
9931,
12,
3999,
14,
5359,
9,
523,
916,
3999,
14,
1291,
365,
488,
26,
272,
327,
9936,
370,
1050,
2323,
1325,
965,
949,
1324,
272,
870,
480,
20824,
376,
1324,
1406,
531,
272,
1798,
14,
1122,
63,
589,
5234,
13,
72,
3135,
523,
587,
26,
272,
1050,
63,
2139,
8,
3291,
14,
1291,
12,
3999,
14,
3619,
12,
3999,
14,
5359,
12,
3999,
14,
9931,
9,
421,
199,
318,
1050,
63,
2139,
8,
493,
12,
24670,
12,
27688,
12,
9133,
304,
523,
327,
664,
314,
1406,
523,
543,
1551,
8,
493,
9,
465,
289,
26,
272,
1406,
275,
289,
14,
739,
342,
272,
289,
14,
1600,
342,
523,
1584,
275,
664,
63,
1725,
8,
18091,
12,
27688,
12,
9133,
9,
523,
327,
862,
370,
2218,
63,
1291,
370,
1924,
570,
523,
19218,
8,
1725,
12,
1406,
12,
2218,
63,
1291,
9,
421,
199,
318,
2813,
63,
2139,
8,
694,
12,
9133,
12,
27688,
304,
523,
1584,
275,
664,
63,
1725,
8,
694,
12,
27688,
12,
9133,
9,
523,
19218,
8,
1725,
12,
488,
12,
2813,
63,
1291,
9,
421,
199,
318,
19218,
8,
1725,
12,
1406,
12,
1687,
304,
523,
12679,
8,
552,
8,
1725,
430,
523,
6042,
275,
378,
523,
367,
284,
315,
4945,
8,
552,
8,
1725,
2298,
272,
340,
1687,
8,
1725,
59,
73,
467,
1406,
304,
489,
6042,
847,
413,
272,
299,
2946,
275,
2069,
8,
73,
11,
17,
9,
1182,
822,
8,
1725,
9,
272,
1678,
63,
5734,
8,
2352,
484,
10,
1960,
12,
1584,
59,
73,
566,
523,
870,
4582,
78,
2,
435,
620,
8,
5540,
9,
435,
298,
1584,
6042,
2685,
421,
199,
318,
12679,
8,
19582,
304,
523,
1830,
715,
26,
272,
282,
275,
3066,
63,
1210,
480,
2765,
3439,
4293,
18994,
2811,
298,
435,
620,
8,
19582,
9,
435,
298,
1584,
14,
1448,
1781,
31,
359,
89,
15,
78,
2189,
6099,
272,
340,
282,
508,
283,
89,
356,
489,
2059,
272,
916,
282,
508,
283,
78,
356,
489,
984,
14,
2224,
342,
421,
199,
318,
2218,
63,
1291,
8,
493,
12,
1406,
304,
523,
327,
664,
314,
3329,
523,
1599,
275,
664,
63,
832,
8,
493,
9,
523,
340,
1599,
315,
2323,
26,
272,
327,
1104,
340,
781,
1172,
282,
1015,
6328,
367
] |
[
199,
7384,
334,
67,
9,
6927,
644,
14976,
445,
293,
1180,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
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,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
624,
199,
646,
984,
199,
646,
7534,
199,
646,
5739,
199,
646,
747,
199,
646,
900,
199,
646,
295,
421,
199,
3,
11977,
3329,
2323,
880,
781,
2793,
1133,
1929,
370,
1218,
3062,
1924,
900,
199,
2139,
275,
1052,
199,
199,
3,
21838,
3721,
16088,
83,
367,
3365,
570,
5478,
199,
1490,
3029,
275,
469,
523,
3286,
10,
582,
2097,
6138,
401,
298,
67,
401,
298,
2055,
401,
298,
72,
401,
298,
12156,
401,
298,
72,
802,
401,
298,
5910,
401,
298,
8624,
401,
298,
3596,
401,
298,
77,
401,
298,
1259,
2255,
523,
283,
624,
356,
2097,
647,
2255,
523,
7244,
283,
582,
2097,
609,
2255,
523,
298,
29,
5037,
582,
788,
4848,
995,
199,
93,
199,
199,
3,
2463,
21317,
9994,
370,
314,
16088,
83,
199,
1600,
3029,
275,
469,
523,
3286,
10,
582,
298,
627,
10665,
523,
283,
624,
356,
283,
624,
297,
523,
7244,
283,
582,
3546,
401,
523,
298,
29,
5037,
582,
298,
29,
500,
2,
199,
93,
199,
199,
3,
13158,
2544,
1924,
1004,
3382,
16088,
436,
2463,
21317,
199,
14124,
275,
469,
523,
3286,
10,
582,
298,
627,
3872,
523,
283,
624,
356,
4873,
523,
7244,
283,
582,
4873,
523,
298,
29,
5037,
582,
3087,
199,
93,
421,
199,
318,
2446,
8,
3020,
304,
523,
327,
2198,
2368,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
6096,
5682,
401,
4320,
2168,
401,
1595,
628,
1617,
63,
2052,
401,
221,
1993,
1720,
628,
87,
3081,
314,
2323,
1077,
506,
4829,
3140,
402,
3483,
531,
523,
1798,
14,
525,
63,
2094,
6096,
73,
401,
4320,
1210,
13,
493,
401,
1720,
628,
493,
370,
1586,
1406,
687,
401,
2053,
628,
1291,
531,
523,
1798,
14,
525,
63,
2094,
6096,
79,
401,
4320,
1199,
13,
694,
401,
1720,
628,
3619,
370,
2754,
367,
570,
315,
401,
2053,
628,
3619,
531,
16421,
1798,
14,
525,
63,
2094,
6096,
82,
401,
4320,
9931,
401,
1595,
628,
1617,
63,
2052,
401,
221,
1993,
1720,
628,
87,
3081,
370,
1678,
2323,
315,
314,
2082,
15035,
531,
523,
1798,
14,
525,
63,
2094,
6096,
69,
401,
4320,
5359,
401,
1595,
628,
740,
401,
849,
6034,
1720,
628,
1589,
5478,
370,
1678,
531,
819,
3999,
275,
1798,
14,
1122,
63,
589,
8,
3020,
9,
819,
327,
949,
2082,
31,
523,
340,
3999,
14,
3619,
365,
488,
26,
272,
870,
480,
20824,
282,
2082,
531,
272,
1798,
14,
1122,
63,
589,
5234,
13,
72,
3135,
819,
340,
3999,
14,
2168,
26,
272,
2813,
63,
2139,
8,
3291,
14,
3619,
12,
3999,
14,
9931,
12,
3999,
14,
5359,
9,
523,
916,
3999,
14,
1291,
365,
488,
26,
272,
327,
9936,
370,
1050,
2323,
1325,
965,
949,
1324,
272,
870,
480,
20824,
376,
1324,
1406,
531,
272,
1798,
14,
1122,
63,
589,
5234,
13,
72,
3135,
523,
587,
26,
272,
1050,
63,
2139,
8,
3291,
14,
1291,
12,
3999,
14,
3619,
12,
3999,
14,
5359,
12,
3999,
14,
9931,
9,
421,
199,
318,
1050,
63,
2139,
8,
493,
12,
24670,
12,
27688,
12,
9133,
304,
523,
327,
664,
314,
1406,
523,
543,
1551,
8,
493,
9,
465,
289,
26,
272,
1406,
275,
289,
14,
739,
342,
272,
289,
14,
1600,
342,
523,
1584,
275,
664,
63,
1725,
8,
18091,
12,
27688,
12,
9133,
9,
523,
327,
862,
370,
2218,
63,
1291,
370,
1924,
570,
523,
19218,
8,
1725,
12,
1406,
12,
2218,
63,
1291,
9,
421,
199,
318,
2813,
63,
2139,
8,
694,
12,
9133,
12,
27688,
304,
523,
1584,
275,
664,
63,
1725,
8,
694,
12,
27688,
12,
9133,
9,
523,
19218,
8,
1725,
12,
488,
12,
2813,
63,
1291,
9,
421,
199,
318,
19218,
8,
1725,
12,
1406,
12,
1687,
304,
523,
12679,
8,
552,
8,
1725,
430,
523,
6042,
275,
378,
523,
367,
284,
315,
4945,
8,
552,
8,
1725,
2298,
272,
340,
1687,
8,
1725,
59,
73,
467,
1406,
304,
489,
6042,
847,
413,
272,
299,
2946,
275,
2069,
8,
73,
11,
17,
9,
1182,
822,
8,
1725,
9,
272,
1678,
63,
5734,
8,
2352,
484,
10,
1960,
12,
1584,
59,
73,
566,
523,
870,
4582,
78,
2,
435,
620,
8,
5540,
9,
435,
298,
1584,
6042,
2685,
421,
199,
318,
12679,
8,
19582,
304,
523,
1830,
715,
26,
272,
282,
275,
3066,
63,
1210,
480,
2765,
3439,
4293,
18994,
2811,
298,
435,
620,
8,
19582,
9,
435,
298,
1584,
14,
1448,
1781,
31,
359,
89,
15,
78,
2189,
6099,
272,
340,
282,
508,
283,
89,
356,
489,
2059,
272,
916,
282,
508,
283,
78,
356,
489,
984,
14,
2224,
342,
421,
199,
318,
2218,
63,
1291,
8,
493,
12,
1406,
304,
523,
327,
664,
314,
3329,
523,
1599,
275,
664,
63,
832,
8,
493,
9,
523,
340,
1599,
315,
2323,
26,
272,
327,
1104,
340,
781,
1172,
282,
1015,
6328,
367,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
catapult-project/catapult
|
third_party/google-endpoints/apitools/base/protorpclite/descriptor.py
|
30
|
19703
|
#!/usr/bin/env python
#
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Services descriptor definitions.
Contains message definitions and functions for converting
service classes into transmittable message format.
Describing an Enum instance, Enum class, Field class or Message class will
generate an appropriate descriptor object that describes that class.
This message can itself be used to transmit information to clients wishing
to know the description of an enum value, enum, field or message without
needing to download the source code. This format is also compatible with
other, non-Python languages.
The descriptors are modeled to be binary compatible with
https://github.com/google/protobuf
NOTE: The names of types and fields are not always the same between these
descriptors and the ones defined in descriptor.proto. This was done in order
to make source code files that use these descriptors easier to read. For
example, it is not necessary to prefix TYPE to all the values in
FieldDescriptor.Variant as is done in descriptor.proto
FieldDescriptorProto.Type.
Example:
class Pixel(messages.Message):
x = messages.IntegerField(1, required=True)
y = messages.IntegerField(2, required=True)
color = messages.BytesField(3)
# Describe Pixel class using message descriptor.
fields = []
field = FieldDescriptor()
field.name = 'x'
field.number = 1
field.label = FieldDescriptor.Label.REQUIRED
field.variant = FieldDescriptor.Variant.INT64
fields.append(field)
field = FieldDescriptor()
field.name = 'y'
field.number = 2
field.label = FieldDescriptor.Label.REQUIRED
field.variant = FieldDescriptor.Variant.INT64
fields.append(field)
field = FieldDescriptor()
field.name = 'color'
field.number = 3
field.label = FieldDescriptor.Label.OPTIONAL
field.variant = FieldDescriptor.Variant.BYTES
fields.append(field)
message = MessageDescriptor()
message.name = 'Pixel'
message.fields = fields
# Describing is the equivalent of building the above message.
message == describe_message(Pixel)
Public Classes:
EnumValueDescriptor: Describes Enum values.
EnumDescriptor: Describes Enum classes.
FieldDescriptor: Describes field instances.
FileDescriptor: Describes a single 'file' unit.
FileSet: Describes a collection of file descriptors.
MessageDescriptor: Describes Message classes.
Public Functions:
describe_enum_value: Describe an individual enum-value.
describe_enum: Describe an Enum class.
describe_field: Describe a Field definition.
describe_file: Describe a 'file' unit from a Python module or object.
describe_file_set: Describe a file set from a list of modules or objects.
describe_message: Describe a Message definition.
"""
import codecs
import types
import six
from apitools.base.protorpclite import messages
from apitools.base.protorpclite import util
__all__ = [
'EnumDescriptor',
'EnumValueDescriptor',
'FieldDescriptor',
'MessageDescriptor',
'FileDescriptor',
'FileSet',
'DescriptorLibrary',
'describe_enum',
'describe_enum_value',
'describe_field',
'describe_message',
'describe_file',
'describe_file_set',
'describe',
'import_descriptor_loader',
]
# NOTE: MessageField is missing because message fields cannot have
# a default value at this time.
# TODO(rafek): Support default message values.
#
# Map to functions that convert default values of fields of a given type
# to a string. The function must return a value that is compatible with
# FieldDescriptor.default_value and therefore a unicode string.
_DEFAULT_TO_STRING_MAP = {
messages.IntegerField: six.text_type,
messages.FloatField: six.text_type,
messages.BooleanField: lambda value: value and u'true' or u'false',
messages.BytesField: lambda value: codecs.escape_encode(value)[0],
messages.StringField: lambda value: value,
messages.EnumField: lambda value: six.text_type(value.number),
}
_DEFAULT_FROM_STRING_MAP = {
messages.IntegerField: int,
messages.FloatField: float,
messages.BooleanField: lambda value: value == u'true',
messages.BytesField: lambda value: codecs.escape_decode(value)[0],
messages.StringField: lambda value: value,
messages.EnumField: int,
}
class EnumValueDescriptor(messages.Message):
"""Enum value descriptor.
Fields:
name: Name of enumeration value.
number: Number of enumeration value.
"""
# TODO(rafek): Why are these listed as optional in descriptor.proto.
# Harmonize?
name = messages.StringField(1, required=True)
number = messages.IntegerField(2,
required=True,
variant=messages.Variant.INT32)
class EnumDescriptor(messages.Message):
"""Enum class descriptor.
Fields:
name: Name of Enum without any qualification.
values: Values defined by Enum class.
"""
name = messages.StringField(1)
values = messages.MessageField(EnumValueDescriptor, 2, repeated=True)
class FieldDescriptor(messages.Message):
"""Field definition descriptor.
Enums:
Variant: Wire format hint sub-types for field.
Label: Values for optional, required and repeated fields.
Fields:
name: Name of field.
number: Number of field.
variant: Variant of field.
type_name: Type name for message and enum fields.
default_value: String representation of default value.
"""
Variant = messages.Variant # pylint:disable=invalid-name
class Label(messages.Enum):
"""Field label."""
OPTIONAL = 1
REQUIRED = 2
REPEATED = 3
name = messages.StringField(1, required=True)
number = messages.IntegerField(3,
required=True,
variant=messages.Variant.INT32)
label = messages.EnumField(Label, 4, default=Label.OPTIONAL)
variant = messages.EnumField(Variant, 5)
type_name = messages.StringField(6)
# For numeric types, contains the original text representation of
# the value.
# For booleans, "true" or "false".
# For strings, contains the default text contents (not escaped in any
# way).
# For bytes, contains the C escaped value. All bytes < 128 are that are
# traditionally considered unprintable are also escaped.
default_value = messages.StringField(7)
class MessageDescriptor(messages.Message):
"""Message definition descriptor.
Fields:
name: Name of Message without any qualification.
fields: Fields defined for message.
message_types: Nested Message classes defined on message.
enum_types: Nested Enum classes defined on message.
"""
name = messages.StringField(1)
fields = messages.MessageField(FieldDescriptor, 2, repeated=True)
message_types = messages.MessageField(
'apitools.base.protorpclite.descriptor.MessageDescriptor', 3,
repeated=True)
enum_types = messages.MessageField(EnumDescriptor, 4, repeated=True)
class FileDescriptor(messages.Message):
"""Description of file containing protobuf definitions.
Fields:
package: Fully qualified name of package that definitions belong to.
message_types: Message definitions contained in file.
enum_types: Enum definitions contained in file.
"""
package = messages.StringField(2)
# TODO(rafek): Add dependency field
message_types = messages.MessageField(MessageDescriptor, 4, repeated=True)
enum_types = messages.MessageField(EnumDescriptor, 5, repeated=True)
class FileSet(messages.Message):
"""A collection of FileDescriptors.
Fields:
files: Files in file-set.
"""
files = messages.MessageField(FileDescriptor, 1, repeated=True)
def describe_enum_value(enum_value):
"""Build descriptor for Enum instance.
Args:
enum_value: Enum value to provide descriptor for.
Returns:
Initialized EnumValueDescriptor instance describing the Enum instance.
"""
enum_value_descriptor = EnumValueDescriptor()
enum_value_descriptor.name = six.text_type(enum_value.name)
enum_value_descriptor.number = enum_value.number
return enum_value_descriptor
def describe_enum(enum_definition):
"""Build descriptor for Enum class.
Args:
enum_definition: Enum class to provide descriptor for.
Returns:
Initialized EnumDescriptor instance describing the Enum class.
"""
enum_descriptor = EnumDescriptor()
enum_descriptor.name = enum_definition.definition_name().split('.')[-1]
values = []
for number in enum_definition.numbers():
value = enum_definition.lookup_by_number(number)
values.append(describe_enum_value(value))
if values:
enum_descriptor.values = values
return enum_descriptor
def describe_field(field_definition):
"""Build descriptor for Field instance.
Args:
field_definition: Field instance to provide descriptor for.
Returns:
Initialized FieldDescriptor instance describing the Field instance.
"""
field_descriptor = FieldDescriptor()
field_descriptor.name = field_definition.name
field_descriptor.number = field_definition.number
field_descriptor.variant = field_definition.variant
if isinstance(field_definition, messages.EnumField):
field_descriptor.type_name = field_definition.type.definition_name()
if isinstance(field_definition, messages.MessageField):
field_descriptor.type_name = (
field_definition.message_type.definition_name())
if field_definition.default is not None:
field_descriptor.default_value = _DEFAULT_TO_STRING_MAP[
type(field_definition)](field_definition.default)
# Set label.
if field_definition.repeated:
field_descriptor.label = FieldDescriptor.Label.REPEATED
elif field_definition.required:
field_descriptor.label = FieldDescriptor.Label.REQUIRED
else:
field_descriptor.label = FieldDescriptor.Label.OPTIONAL
return field_descriptor
def describe_message(message_definition):
"""Build descriptor for Message class.
Args:
message_definition: Message class to provide descriptor for.
Returns:
Initialized MessageDescriptor instance describing the Message class.
"""
message_descriptor = MessageDescriptor()
message_descriptor.name = message_definition.definition_name().split(
'.')[-1]
fields = sorted(message_definition.all_fields(),
key=lambda v: v.number)
if fields:
message_descriptor.fields = [describe_field(field) for field in fields]
try:
nested_messages = message_definition.__messages__
except AttributeError:
pass
else:
message_descriptors = []
for name in nested_messages:
value = getattr(message_definition, name)
message_descriptors.append(describe_message(value))
message_descriptor.message_types = message_descriptors
try:
nested_enums = message_definition.__enums__
except AttributeError:
pass
else:
enum_descriptors = []
for name in nested_enums:
value = getattr(message_definition, name)
enum_descriptors.append(describe_enum(value))
message_descriptor.enum_types = enum_descriptors
return message_descriptor
def describe_file(module):
"""Build a file from a specified Python module.
Args:
module: Python module to describe.
Returns:
Initialized FileDescriptor instance describing the module.
"""
descriptor = FileDescriptor()
descriptor.package = util.get_package_for_module(module)
if not descriptor.package:
descriptor.package = None
message_descriptors = []
enum_descriptors = []
# Need to iterate over all top level attributes of the module looking for
# message and enum definitions. Each definition must be itself described.
for name in sorted(dir(module)):
value = getattr(module, name)
if isinstance(value, type):
if issubclass(value, messages.Message):
message_descriptors.append(describe_message(value))
elif issubclass(value, messages.Enum):
enum_descriptors.append(describe_enum(value))
if message_descriptors:
descriptor.message_types = message_descriptors
if enum_descriptors:
descriptor.enum_types = enum_descriptors
return descriptor
def describe_file_set(modules):
"""Build a file set from a specified Python modules.
Args:
modules: Iterable of Python module to describe.
Returns:
Initialized FileSet instance describing the modules.
"""
descriptor = FileSet()
file_descriptors = []
for module in modules:
file_descriptors.append(describe_file(module))
if file_descriptors:
descriptor.files = file_descriptors
return descriptor
def describe(value):
"""Describe any value as a descriptor.
Helper function for describing any object with an appropriate descriptor
object.
Args:
value: Value to describe as a descriptor.
Returns:
Descriptor message class if object is describable as a descriptor, else
None.
"""
if isinstance(value, types.ModuleType):
return describe_file(value)
elif isinstance(value, messages.Field):
return describe_field(value)
elif isinstance(value, messages.Enum):
return describe_enum_value(value)
elif isinstance(value, type):
if issubclass(value, messages.Message):
return describe_message(value)
elif issubclass(value, messages.Enum):
return describe_enum(value)
return None
@util.positional(1)
def import_descriptor_loader(definition_name, importer=__import__):
"""Find objects by importing modules as needed.
A definition loader is a function that resolves a definition name to a
descriptor.
The import finder resolves definitions to their names by importing modules
when necessary.
Args:
definition_name: Name of definition to find.
importer: Import function used for importing new modules.
Returns:
Appropriate descriptor for any describable type located by name.
Raises:
DefinitionNotFoundError when a name does not refer to either a definition
or a module.
"""
# Attempt to import descriptor as a module.
if definition_name.startswith('.'):
definition_name = definition_name[1:]
if not definition_name.startswith('.'):
leaf = definition_name.split('.')[-1]
if definition_name:
try:
module = importer(definition_name, '', '', [leaf])
except ImportError:
pass
else:
return describe(module)
try:
# Attempt to use messages.find_definition to find item.
return describe(messages.find_definition(definition_name,
importer=__import__))
except messages.DefinitionNotFoundError as err:
# There are things that find_definition will not find, but if
# the parent is loaded, its children can be searched for a
# match.
split_name = definition_name.rsplit('.', 1)
if len(split_name) > 1:
parent, child = split_name
try:
parent_definition = import_descriptor_loader(
parent, importer=importer)
except messages.DefinitionNotFoundError:
# Fall through to original error.
pass
else:
# Check the parent definition for a matching descriptor.
if isinstance(parent_definition, EnumDescriptor):
search_list = parent_definition.values or []
elif isinstance(parent_definition, MessageDescriptor):
search_list = parent_definition.fields or []
else:
search_list = []
for definition in search_list:
if definition.name == child:
return definition
# Still didn't find. Reraise original exception.
raise err
class DescriptorLibrary(object):
"""A descriptor library is an object that contains known definitions.
A descriptor library contains a cache of descriptor objects mapped by
definition name. It contains all types of descriptors except for
file sets.
When a definition name is requested that the library does not know about
it can be provided with a descriptor loader which attempt to resolve the
missing descriptor.
"""
@util.positional(1)
def __init__(self,
descriptors=None,
descriptor_loader=import_descriptor_loader):
"""Constructor.
Args:
descriptors: A dictionary or dictionary-like object that can be used
to store and cache descriptors by definition name.
definition_loader: A function used for resolving missing descriptors.
The function takes a definition name as its parameter and returns
an appropriate descriptor. It may raise DefinitionNotFoundError.
"""
self.__descriptor_loader = descriptor_loader
self.__descriptors = descriptors or {}
def lookup_descriptor(self, definition_name):
"""Lookup descriptor by name.
Get descriptor from library by name. If descriptor is not found will
attempt to find via descriptor loader if provided.
Args:
definition_name: Definition name to find.
Returns:
Descriptor that describes definition name.
Raises:
DefinitionNotFoundError if not descriptor exists for definition name.
"""
try:
return self.__descriptors[definition_name]
except KeyError:
pass
if self.__descriptor_loader:
definition = self.__descriptor_loader(definition_name)
self.__descriptors[definition_name] = definition
return definition
else:
raise messages.DefinitionNotFoundError(
'Could not find definition for %s' % definition_name)
def lookup_package(self, definition_name):
"""Determines the package name for any definition.
Determine the package that any definition name belongs to. May
check parent for package name and will resolve missing
descriptors if provided descriptor loader.
Args:
definition_name: Definition name to find package for.
"""
while True:
descriptor = self.lookup_descriptor(definition_name)
if isinstance(descriptor, FileDescriptor):
return descriptor.package
else:
index = definition_name.rfind('.')
if index < 0:
return None
definition_name = definition_name[:index]
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7129,
4475,
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,
199,
199,
624,
15803,
5872,
10269,
14,
199,
199,
6906,
1245,
10269,
436,
3423,
367,
13806,
199,
1364,
3992,
1901,
27754,
1224,
1245,
1475,
14,
199,
199,
16320,
10911,
376,
11305,
1256,
12,
11305,
1021,
12,
5024,
1021,
503,
6430,
1021,
911,
199,
4208,
376,
5827,
5872,
909,
626,
23369,
626,
1021,
14,
199,
2765,
1245,
883,
6337,
506,
1202,
370,
27754,
2556,
370,
13431,
13809,
316,
199,
475,
5715,
314,
1369,
402,
376,
4952,
574,
12,
4952,
12,
901,
503,
1245,
1928,
199,
9321,
316,
370,
5235,
314,
1350,
1233,
14,
221,
961,
1475,
365,
2597,
9025,
543,
199,
1848,
12,
2222,
13,
4718,
10815,
14,
199,
199,
1918,
15428,
787,
818,
1146,
370,
506,
3366,
9025,
543,
523,
4178,
921,
5031,
14,
957,
15,
3098,
15,
7204,
199,
199,
19855,
26,
710,
1561,
402,
2943,
436,
1504,
787,
440,
3544,
314,
2011,
3382,
3520,
199,
17752,
436,
314,
7869,
3247,
315,
5872,
14,
2625,
14,
221,
961,
1990,
4224,
315,
1865,
199,
475,
1852,
1350,
1233,
1584,
626,
675,
3520,
15428,
14905,
370,
1586,
14,
221,
2104,
199,
2694,
12,
652,
365,
440,
5784,
370,
2403,
11511,
370,
1006,
314,
1338,
315,
199,
8510,
14,
12935,
465,
365,
4224,
315,
5872,
14,
2625,
199,
8510,
8548,
14,
804,
14,
199,
199,
9846,
26,
819,
1021,
510,
5887,
8,
3431,
14,
2209,
304,
339,
671,
275,
3788,
14,
3901,
8,
17,
12,
1415,
29,
549,
9,
272,
612,
275,
3788,
14,
3901,
8,
18,
12,
1415,
29,
549,
9,
339,
3164,
275,
3788,
14,
5571,
792,
8,
19,
9,
819,
327,
28571,
1235,
510,
5887,
1021,
1808,
1245,
5872,
14,
523,
1504,
275,
942,
819,
901,
275,
5024,
4311,
342,
523,
901,
14,
354,
275,
283,
88,
7,
523,
901,
14,
1955,
275,
413,
523,
901,
14,
1302,
275,
5024,
4311,
14,
4314,
14,
12496,
523,
901,
14,
8759,
275,
5024,
4311,
14,
12935,
14,
2919,
772,
523,
1504,
14,
740,
8,
698,
9,
819,
901,
275,
5024,
4311,
342,
523,
901,
14,
354,
275,
283,
89,
7,
523,
901,
14,
1955,
275,
499,
523,
901,
14,
1302,
275,
5024,
4311,
14,
4314,
14,
12496,
523,
901,
14,
8759,
275,
5024,
4311,
14,
12935,
14,
2919,
772,
523,
1504,
14,
740,
8,
698,
9,
819,
901,
275,
5024,
4311,
342,
523,
901,
14,
354,
275,
283,
2326,
7,
523,
901,
14,
1955,
275,
650,
523,
901,
14,
1302,
275,
5024,
4311,
14,
4314,
14,
21008,
523,
901,
14,
8759,
275,
5024,
4311,
14,
12935,
14,
20352,
523,
1504,
14,
740,
8,
698,
9,
819,
1245,
275,
6430,
4311,
342,
523,
1245,
14,
354,
275,
283,
14383,
7,
523,
1245,
14,
955,
275,
1504,
819,
327,
28571,
10911,
365,
314,
7353,
402,
10015,
314,
3432,
1245,
14,
523,
1245,
508,
13743,
63,
1188,
8,
14383,
9,
199,
199,
9885,
27939,
26,
523,
11305,
1110,
4311,
26,
28571,
11562,
11305,
1338,
14,
523,
11305,
4311,
26,
28571,
11562,
11305,
3992,
14,
523,
5024,
4311,
26,
28571,
11562,
901,
4454,
14,
523,
3814,
4311,
26,
28571,
11562,
282,
2849,
283,
493,
7,
4137,
14,
523,
3814,
1084,
26,
28571,
11562,
282,
3245,
402,
570,
15428,
14,
523,
6430,
4311,
26,
28571,
11562,
6430,
3992,
14,
199,
199,
9885,
17471,
26,
523,
13743,
63,
4869,
63,
585,
26,
28571,
1235,
376,
8212,
4952,
13,
585,
14,
523,
13743,
63,
4869,
26,
28571,
1235,
376,
11305,
1021,
14,
523,
13743,
63,
698,
26,
28571,
1235,
282,
5024,
5492,
14,
523,
13743,
63,
493,
26,
28571,
1235,
282,
283,
493,
7,
4137,
687,
282,
2018,
859,
503,
909,
14,
523,
13743,
63,
493,
63,
409,
26,
28571,
1235,
282,
570,
663,
687,
282,
769,
402,
4621,
503,
2251,
14,
523,
13743,
63,
1188,
26,
28571,
1235,
282,
6430,
5492,
14,
199,
624,
199,
646,
6010,
199,
646,
2943,
199,
199,
646,
3816,
199,
199,
504,
2771,
390,
5998,
14,
1095,
14,
2745,
30786,
5333,
492,
3788,
199,
504,
2771,
390,
5998,
14,
1095,
14,
2745,
30786,
5333,
492,
4884,
421,
199,
363,
452,
363,
275,
359,
272,
283,
5081,
4311,
297,
272,
283,
19629,
297,
272,
283,
8510,
297,
272,
283,
2209,
4311,
297,
272,
283,
23859,
297,
272,
283,
1173,
1084,
297,
272,
283,
4311,
7424,
297,
339,
283,
11935,
63,
4869,
297,
272,
283,
11935,
63,
4869,
63,
585,
297,
272,
283,
11935,
63,
698,
297,
272,
283,
11935,
63,
1188,
297,
272,
283,
11935,
63,
493,
297,
272,
283,
11935,
63,
493,
63,
409,
297,
272,
283,
11935,
297,
272,
283,
646,
63,
4120,
63,
3422,
297,
199,
61,
421,
199,
3,
6944,
26,
6430,
792,
365,
4124,
2952,
1245,
1504,
3913,
1172,
199,
3,
282,
849,
574,
737,
642,
900,
14,
199,
3,
3254,
8,
345,
771,
75,
304,
12502,
849,
1245,
1338,
14,
199,
3,
199,
3,
9672,
370,
3423,
626,
3957,
849,
1338,
402,
1504,
402,
282,
1627,
730,
199,
3,
370,
282,
1059,
14,
221,
710,
805,
1471,
372,
282,
574,
626,
365,
9025,
543,
199,
3,
5024,
4311,
14,
885,
63,
585,
436,
16119,
282,
2649,
1059,
14,
199,
63,
3472,
63,
2566,
63,
5353,
63,
5443,
275,
469,
272,
3788,
14,
3901,
26,
3816,
14,
505,
63,
466,
12,
272,
3788,
14,
13019,
26,
3816,
14,
505,
63,
466,
12,
272
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7129,
4475,
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,
199,
199,
624,
15803,
5872,
10269,
14,
199,
199,
6906,
1245,
10269,
436,
3423,
367,
13806,
199,
1364,
3992,
1901,
27754,
1224,
1245,
1475,
14,
199,
199,
16320,
10911,
376,
11305,
1256,
12,
11305,
1021,
12,
5024,
1021,
503,
6430,
1021,
911,
199,
4208,
376,
5827,
5872,
909,
626,
23369,
626,
1021,
14,
199,
2765,
1245,
883,
6337,
506,
1202,
370,
27754,
2556,
370,
13431,
13809,
316,
199,
475,
5715,
314,
1369,
402,
376,
4952,
574,
12,
4952,
12,
901,
503,
1245,
1928,
199,
9321,
316,
370,
5235,
314,
1350,
1233,
14,
221,
961,
1475,
365,
2597,
9025,
543,
199,
1848,
12,
2222,
13,
4718,
10815,
14,
199,
199,
1918,
15428,
787,
818,
1146,
370,
506,
3366,
9025,
543,
523,
4178,
921,
5031,
14,
957,
15,
3098,
15,
7204,
199,
199,
19855,
26,
710,
1561,
402,
2943,
436,
1504,
787,
440,
3544,
314,
2011,
3382,
3520,
199,
17752,
436,
314,
7869,
3247,
315,
5872,
14,
2625,
14,
221,
961,
1990,
4224,
315,
1865,
199,
475,
1852,
1350,
1233,
1584,
626,
675,
3520,
15428,
14905,
370,
1586,
14,
221,
2104,
199,
2694,
12,
652,
365,
440,
5784,
370,
2403,
11511,
370,
1006,
314,
1338,
315,
199,
8510,
14,
12935,
465,
365,
4224,
315,
5872,
14,
2625,
199,
8510,
8548,
14,
804,
14,
199,
199,
9846,
26,
819,
1021,
510,
5887,
8,
3431,
14,
2209,
304,
339,
671,
275,
3788,
14,
3901,
8,
17,
12,
1415,
29,
549,
9,
272,
612,
275,
3788,
14,
3901,
8,
18,
12,
1415,
29,
549,
9,
339,
3164,
275,
3788,
14,
5571,
792,
8,
19,
9,
819,
327,
28571,
1235,
510,
5887,
1021,
1808,
1245,
5872,
14,
523,
1504,
275,
942,
819,
901,
275,
5024,
4311,
342,
523,
901,
14,
354,
275,
283,
88,
7,
523,
901,
14,
1955,
275,
413,
523,
901,
14,
1302,
275,
5024,
4311,
14,
4314,
14,
12496,
523,
901,
14,
8759,
275,
5024,
4311,
14,
12935,
14,
2919,
772,
523,
1504,
14,
740,
8,
698,
9,
819,
901,
275,
5024,
4311,
342,
523,
901,
14,
354,
275,
283,
89,
7,
523,
901,
14,
1955,
275,
499,
523,
901,
14,
1302,
275,
5024,
4311,
14,
4314,
14,
12496,
523,
901,
14,
8759,
275,
5024,
4311,
14,
12935,
14,
2919,
772,
523,
1504,
14,
740,
8,
698,
9,
819,
901,
275,
5024,
4311,
342,
523,
901,
14,
354,
275,
283,
2326,
7,
523,
901,
14,
1955,
275,
650,
523,
901,
14,
1302,
275,
5024,
4311,
14,
4314,
14,
21008,
523,
901,
14,
8759,
275,
5024,
4311,
14,
12935,
14,
20352,
523,
1504,
14,
740,
8,
698,
9,
819,
1245,
275,
6430,
4311,
342,
523,
1245,
14,
354,
275,
283,
14383,
7,
523,
1245,
14,
955,
275,
1504,
819,
327,
28571,
10911,
365,
314,
7353,
402,
10015,
314,
3432,
1245,
14,
523,
1245,
508,
13743,
63,
1188,
8,
14383,
9,
199,
199,
9885,
27939,
26,
523,
11305,
1110,
4311,
26,
28571,
11562,
11305,
1338,
14,
523,
11305,
4311,
26,
28571,
11562,
11305,
3992,
14,
523,
5024,
4311,
26,
28571,
11562,
901,
4454,
14,
523,
3814,
4311,
26,
28571,
11562,
282,
2849,
283,
493,
7,
4137,
14,
523,
3814,
1084,
26,
28571,
11562,
282,
3245,
402,
570,
15428,
14,
523,
6430,
4311,
26,
28571,
11562,
6430,
3992,
14,
199,
199,
9885,
17471,
26,
523,
13743,
63,
4869,
63,
585,
26,
28571,
1235,
376,
8212,
4952,
13,
585,
14,
523,
13743,
63,
4869,
26,
28571,
1235,
376,
11305,
1021,
14,
523,
13743,
63,
698,
26,
28571,
1235,
282,
5024,
5492,
14,
523,
13743,
63,
493,
26,
28571,
1235,
282,
283,
493,
7,
4137,
687,
282,
2018,
859,
503,
909,
14,
523,
13743,
63,
493,
63,
409,
26,
28571,
1235,
282,
570,
663,
687,
282,
769,
402,
4621,
503,
2251,
14,
523,
13743,
63,
1188,
26,
28571,
1235,
282,
6430,
5492,
14,
199,
624,
199,
646,
6010,
199,
646,
2943,
199,
199,
646,
3816,
199,
199,
504,
2771,
390,
5998,
14,
1095,
14,
2745,
30786,
5333,
492,
3788,
199,
504,
2771,
390,
5998,
14,
1095,
14,
2745,
30786,
5333,
492,
4884,
421,
199,
363,
452,
363,
275,
359,
272,
283,
5081,
4311,
297,
272,
283,
19629,
297,
272,
283,
8510,
297,
272,
283,
2209,
4311,
297,
272,
283,
23859,
297,
272,
283,
1173,
1084,
297,
272,
283,
4311,
7424,
297,
339,
283,
11935,
63,
4869,
297,
272,
283,
11935,
63,
4869,
63,
585,
297,
272,
283,
11935,
63,
698,
297,
272,
283,
11935,
63,
1188,
297,
272,
283,
11935,
63,
493,
297,
272,
283,
11935,
63,
493,
63,
409,
297,
272,
283,
11935,
297,
272,
283,
646,
63,
4120,
63,
3422,
297,
199,
61,
421,
199,
3,
6944,
26,
6430,
792,
365,
4124,
2952,
1245,
1504,
3913,
1172,
199,
3,
282,
849,
574,
737,
642,
900,
14,
199,
3,
3254,
8,
345,
771,
75,
304,
12502,
849,
1245,
1338,
14,
199,
3,
199,
3,
9672,
370,
3423,
626,
3957,
849,
1338,
402,
1504,
402,
282,
1627,
730,
199,
3,
370,
282,
1059,
14,
221,
710,
805,
1471,
372,
282,
574,
626,
365,
9025,
543,
199,
3,
5024,
4311,
14,
885,
63,
585,
436,
16119,
282,
2649,
1059,
14,
199,
63,
3472,
63,
2566,
63,
5353,
63,
5443,
275,
469,
272,
3788,
14,
3901,
26,
3816,
14,
505,
63,
466,
12,
272,
3788,
14,
13019,
26,
3816,
14,
505,
63,
466,
12,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
docmeth02/CouchPotatoServer
|
libs/subliminal/services/addic7ed.py
|
105
|
5549
|
# -*- coding: utf-8 -*-
# Copyright 2012 Olivier Leveau <olifozzy@gmail.com>
# Copyright 2012 Antoine Bertin <diaoulael@gmail.com>
#
# This file is part of subliminal.
#
# subliminal is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# subliminal 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 subliminal. If not, see <http://www.gnu.org/licenses/>.
from . import ServiceBase
from ..cache import cachedmethod
from ..exceptions import DownloadFailedError
from ..language import Language, language_set
from ..subtitles import get_subtitle_path, ResultSubtitle
from ..utils import get_keywords, split_keyword
from ..videos import Episode
from bs4 import BeautifulSoup
import logging
import os
import re
logger = logging.getLogger(__name__)
class Addic7ed(ServiceBase):
server_url = 'http://www.addic7ed.com'
api_based = False
#TODO: Complete this
languages = language_set(['ar', 'ca', 'de', 'el', 'en', 'es', 'eu', 'fr', 'ga', 'gl', 'he', 'hr', 'hu',
'it', 'pl', 'pt', 'ro', 'ru', 'se', 'pt-br'])
language_map = {'Portuguese (Brazilian)': Language('por-BR'), 'Greek': Language('gre'),
'Spanish (Latin America)': Language('spa'), 'Galego': Language('glg'),
u'Català': Language('cat')}
videos = [Episode]
require_video = False
required_features = ['permissive']
@cachedmethod
def get_series_id(self, name):
"""Get the show page and cache every show found in it"""
r = self.session.get('%s/shows.php' % self.server_url)
soup = BeautifulSoup(r.content, self.required_features)
for html_series in soup.select('h3 > a'):
series_name = html_series.text.lower()
match = re.search('show/([0-9]+)', html_series['href'])
if match is None:
continue
series_id = int(match.group(1))
self.cache_for(self.get_series_id, args=(series_name,), result=series_id)
return self.cached_value(self.get_series_id, args=(name,))
def list_checked(self, video, languages):
return self.query(video.path or video.release, languages, get_keywords(video.guess), video.series, video.season, video.episode)
def query(self, filepath, languages, keywords, series, season, episode):
logger.debug(u'Getting subtitles for %s season %d episode %d with languages %r' % (series, season, episode, languages))
self.init_cache()
try:
series_id = self.get_series_id(series.lower())
except KeyError:
logger.debug(u'Could not find series id for %s' % series)
return []
r = self.session.get('%s/show/%d&season=%d' % (self.server_url, series_id, season))
soup = BeautifulSoup(r.content, self.required_features)
subtitles = []
for row in soup('tr', {'class': 'epeven completed'}):
cells = row('td')
if int(cells[0].text.strip()) != season or int(cells[1].text.strip()) != episode:
continue
if cells[6].text.strip():
logger.debug(u'Skipping hearing impaired')
continue
sub_status = cells[5].text.strip()
if sub_status != 'Completed':
logger.debug(u'Wrong subtitle status %s' % sub_status)
continue
sub_language = self.get_language(cells[3].text.strip())
if sub_language not in languages:
logger.debug(u'Language %r not in wanted languages %r' % (sub_language, languages))
continue
sub_keywords = split_keyword(cells[4].text.strip().lower())
#TODO: Maybe allow empty keywords here? (same in Subtitulos)
if not keywords & sub_keywords:
logger.debug(u'None of subtitle keywords %r in %r' % (sub_keywords, keywords))
continue
sub_link = '%s/%s' % (self.server_url, cells[9].a['href'])
sub_path = get_subtitle_path(filepath, sub_language, self.config.multi)
subtitle = ResultSubtitle(sub_path, sub_language, self.__class__.__name__.lower(), sub_link, keywords=sub_keywords)
subtitles.append(subtitle)
return subtitles
def download(self, subtitle):
logger.info(u'Downloading %s in %s' % (subtitle.link, subtitle.path))
try:
r = self.session.get(subtitle.link, headers={'Referer': subtitle.link, 'User-Agent': self.user_agent})
soup = BeautifulSoup(r.content, self.required_features)
if soup.title is not None and u'Addic7ed.com' in soup.title.text.strip():
raise DownloadFailedError('Download limit exceeded')
with open(subtitle.path, 'wb') as f:
f.write(r.content)
except Exception as e:
logger.error(u'Download failed: %s' % e)
if os.path.exists(subtitle.path):
os.remove(subtitle.path)
raise DownloadFailedError(str(e))
logger.debug(u'Download finished')
return subtitle
Service = Addic7ed
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6029,
593,
317,
26645,
491,
4754,
3844,
665,
23711,
545,
90,
3605,
32,
6799,
14,
957,
30,
199,
3,
1898,
6029,
437,
29680,
1132,
23207,
1346,
665,
2391,
79,
7586,
352,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1007,
13769,
279,
14,
199,
3,
199,
3,
1007,
13769,
279,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1007,
13769,
279,
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,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
1007,
13769,
279,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
504,
1275,
492,
7591,
1563,
199,
504,
2508,
1637,
492,
6328,
765,
199,
504,
2508,
3924,
492,
17955,
4276,
547,
199,
504,
2508,
3671,
492,
8466,
12,
2637,
63,
409,
199,
504,
2508,
16858,
492,
664,
63,
14348,
63,
515,
12,
10695,
29907,
199,
504,
2508,
1208,
492,
664,
63,
7511,
12,
3715,
63,
6691,
199,
504,
2508,
11418,
492,
27255,
6045,
199,
504,
9922,
20,
492,
17132,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
4431,
5000,
23,
379,
8,
3167,
1563,
304,
272,
1654,
63,
633,
275,
283,
1014,
921,
1544,
14,
350,
5000,
23,
379,
14,
957,
7,
272,
2986,
63,
6788,
275,
756,
272,
327,
11768,
26,
28393,
642,
272,
10815,
275,
2637,
63,
409,
2941,
285,
297,
283,
696,
297,
283,
271,
297,
283,
352,
297,
283,
287,
297,
283,
397,
297,
283,
16913,
297,
283,
4391,
297,
283,
5294,
297,
283,
3528,
297,
283,
426,
297,
283,
6271,
297,
283,
10616,
297,
2892,
283,
390,
297,
283,
1168,
297,
283,
541,
297,
283,
293,
297,
283,
6558,
297,
283,
261,
297,
283,
541,
13,
3289,
1105,
272,
2637,
63,
1130,
275,
791,
4313,
1518,
310,
261,
334,
17171,
90,
1638,
290,
11862,
8466,
360,
7314,
13,
7184,
659,
283,
29480,
356,
8466,
360,
9157,
659,
490,
283,
23717,
2453,
334,
27317,
437,
8534,
11862,
8466,
360,
3770,
659,
283,
39,
1895,
1939,
356,
8466,
360,
3528,
71,
659,
490,
399,
7,
35,
7539,
26482,
356,
8466,
360,
3385,
21004,
272,
22010,
275,
359,
22887,
61,
272,
4409,
63,
3722,
275,
756,
272,
1415,
63,
3179,
275,
788,
529,
32237,
418,
339,
768,
5245,
765,
272,
347,
664,
63,
5602,
63,
344,
8,
277,
12,
536,
304,
267,
408,
1002,
314,
2498,
2034,
436,
2581,
4036,
2498,
1911,
315,
652,
624,
267,
519,
275,
291,
14,
1730,
14,
362,
3508,
83,
15,
23866,
14,
8624,
7,
450,
291,
14,
1000,
63,
633,
9,
267,
9108,
275,
17132,
8,
82,
14,
1317,
12,
291,
14,
2427,
63,
3179,
9,
267,
367,
3517,
63,
5602,
315,
9108,
14,
2416,
360,
72,
19,
690,
282,
735,
288,
6779,
63,
354,
275,
3517,
63,
5602,
14,
505,
14,
2325,
342,
288,
1336,
275,
295,
14,
1733,
360,
2384,
15,
779,
16,
13,
25,
28798,
3517,
63,
5602,
459,
6399,
1105,
288,
340,
1336,
365,
488,
26,
355,
1980,
288,
6779,
63,
344,
275,
1109,
8,
1431,
14,
923,
8,
17,
430,
288,
291,
14,
1637,
63,
509,
8,
277,
14,
362,
63,
5602,
63,
344,
12,
1249,
2687,
5602,
63,
354,
4706,
754,
29,
5602,
63,
344,
9,
267,
372,
291,
14,
5245,
63,
585,
8,
277,
14,
362,
63,
5602,
63,
344,
12,
1249,
2687,
354,
4641,
339,
347,
769,
63,
10718,
8,
277,
12,
3991,
12,
10815,
304,
267,
372,
291,
14,
1131,
8,
3722,
14,
515,
503,
3991,
14,
3221,
12,
10815,
12,
664,
63,
7511,
8,
3722,
14,
11636,
395,
3991,
14,
5602,
12,
3991,
14,
12605,
12,
3991,
14,
9544,
9,
339,
347,
1827,
8,
277,
12,
9911,
12,
10815,
12,
7681,
12,
6779,
12,
14718,
12,
11052,
304,
267,
2512,
14,
1757,
8,
85,
7,
28277,
19297,
367,
450,
83,
14718,
450,
68,
11052,
450,
68,
543,
10815,
450,
82,
7,
450,
334,
5602,
12,
14718,
12,
11052,
12,
10815,
430,
267,
291,
14,
826,
63,
1637,
342,
267,
862,
26,
288,
6779,
63,
344,
275,
291,
14,
362,
63,
5602,
63,
344,
8,
5602,
14,
2325,
1012,
267,
871,
4067,
26,
288,
2512,
14,
1757,
8,
85,
7,
6531,
440,
2342,
6779,
1305,
367,
450,
83,
7,
450,
6779,
9,
288,
372,
942,
267,
519,
275,
291,
14,
1730,
14,
362,
3508,
83,
15,
2384,
3149,
68,
6,
12605,
2458,
68,
7,
450,
334,
277,
14,
1000,
63,
633,
12,
6779,
63,
344,
12,
14718,
430,
267,
9108,
275,
17132,
8,
82,
14,
1317,
12,
291,
14,
2427,
63,
3179,
9,
267,
19297,
275,
942,
267,
367,
1962,
315,
9108,
360,
454,
297,
791,
533,
356,
283,
69,
321,
1856,
9709,
936,
304,
288,
10106,
275,
1962,
360,
2076,
358,
288,
340,
1109,
8,
9041,
59,
16,
1055,
505,
14,
1913,
1012,
1137,
14718,
503,
1109,
8,
9041,
59,
17,
1055,
505,
14,
1913,
1012,
1137,
11052,
26,
355,
1980,
288,
340,
10106,
59,
22,
1055,
505,
14,
1913,
837,
355,
2512,
14,
1757,
8,
85,
7,
18297,
946,
9332,
1742,
5789,
581,
358,
355,
1980,
288,
1007,
63,
1205,
275,
10106,
59,
21,
1055,
505,
14,
1913,
342,
288,
340,
1007,
63,
1205,
1137,
283,
19908,
356,
355,
2512,
14,
1757,
8,
85,
7,
14858,
18197,
2004,
450,
83,
7,
450,
1007,
63,
1205,
9,
355,
1980,
288,
1007,
63,
3671,
275,
291,
14,
362,
63,
3671,
8,
9041,
59,
19,
1055,
505
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6029,
593,
317,
26645,
491,
4754,
3844,
665,
23711,
545,
90,
3605,
32,
6799,
14,
957,
30,
199,
3,
1898,
6029,
437,
29680,
1132,
23207,
1346,
665,
2391,
79,
7586,
352,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1007,
13769,
279,
14,
199,
3,
199,
3,
1007,
13769,
279,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1007,
13769,
279,
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,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
1007,
13769,
279,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
504,
1275,
492,
7591,
1563,
199,
504,
2508,
1637,
492,
6328,
765,
199,
504,
2508,
3924,
492,
17955,
4276,
547,
199,
504,
2508,
3671,
492,
8466,
12,
2637,
63,
409,
199,
504,
2508,
16858,
492,
664,
63,
14348,
63,
515,
12,
10695,
29907,
199,
504,
2508,
1208,
492,
664,
63,
7511,
12,
3715,
63,
6691,
199,
504,
2508,
11418,
492,
27255,
6045,
199,
504,
9922,
20,
492,
17132,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
4431,
5000,
23,
379,
8,
3167,
1563,
304,
272,
1654,
63,
633,
275,
283,
1014,
921,
1544,
14,
350,
5000,
23,
379,
14,
957,
7,
272,
2986,
63,
6788,
275,
756,
272,
327,
11768,
26,
28393,
642,
272,
10815,
275,
2637,
63,
409,
2941,
285,
297,
283,
696,
297,
283,
271,
297,
283,
352,
297,
283,
287,
297,
283,
397,
297,
283,
16913,
297,
283,
4391,
297,
283,
5294,
297,
283,
3528,
297,
283,
426,
297,
283,
6271,
297,
283,
10616,
297,
2892,
283,
390,
297,
283,
1168,
297,
283,
541,
297,
283,
293,
297,
283,
6558,
297,
283,
261,
297,
283,
541,
13,
3289,
1105,
272,
2637,
63,
1130,
275,
791,
4313,
1518,
310,
261,
334,
17171,
90,
1638,
290,
11862,
8466,
360,
7314,
13,
7184,
659,
283,
29480,
356,
8466,
360,
9157,
659,
490,
283,
23717,
2453,
334,
27317,
437,
8534,
11862,
8466,
360,
3770,
659,
283,
39,
1895,
1939,
356,
8466,
360,
3528,
71,
659,
490,
399,
7,
35,
7539,
26482,
356,
8466,
360,
3385,
21004,
272,
22010,
275,
359,
22887,
61,
272,
4409,
63,
3722,
275,
756,
272,
1415,
63,
3179,
275,
788,
529,
32237,
418,
339,
768,
5245,
765,
272,
347,
664,
63,
5602,
63,
344,
8,
277,
12,
536,
304,
267,
408,
1002,
314,
2498,
2034,
436,
2581,
4036,
2498,
1911,
315,
652,
624,
267,
519,
275,
291,
14,
1730,
14,
362,
3508,
83,
15,
23866,
14,
8624,
7,
450,
291,
14,
1000,
63,
633,
9,
267,
9108,
275,
17132,
8,
82,
14,
1317,
12,
291,
14,
2427,
63,
3179,
9,
267,
367,
3517,
63,
5602,
315,
9108,
14,
2416,
360,
72,
19,
690,
282,
735,
288,
6779,
63,
354,
275,
3517,
63,
5602,
14,
505,
14,
2325,
342,
288,
1336,
275,
295,
14,
1733,
360,
2384,
15,
779,
16,
13,
25,
28798,
3517,
63,
5602,
459,
6399,
1105,
288,
340,
1336,
365,
488,
26,
355,
1980,
288,
6779,
63,
344,
275,
1109,
8,
1431,
14,
923,
8,
17,
430,
288,
291,
14,
1637,
63,
509,
8,
277,
14,
362,
63,
5602,
63,
344,
12,
1249,
2687,
5602,
63,
354,
4706,
754,
29,
5602,
63,
344,
9,
267,
372,
291,
14,
5245,
63,
585,
8,
277,
14,
362,
63,
5602,
63,
344,
12,
1249,
2687,
354,
4641,
339,
347,
769,
63,
10718,
8,
277,
12,
3991,
12,
10815,
304,
267,
372,
291,
14,
1131,
8,
3722,
14,
515,
503,
3991,
14,
3221,
12,
10815,
12,
664,
63,
7511,
8,
3722,
14,
11636,
395,
3991,
14,
5602,
12,
3991,
14,
12605,
12,
3991,
14,
9544,
9,
339,
347,
1827,
8,
277,
12,
9911,
12,
10815,
12,
7681,
12,
6779,
12,
14718,
12,
11052,
304,
267,
2512,
14,
1757,
8,
85,
7,
28277,
19297,
367,
450,
83,
14718,
450,
68,
11052,
450,
68,
543,
10815,
450,
82,
7,
450,
334,
5602,
12,
14718,
12,
11052,
12,
10815,
430,
267,
291,
14,
826,
63,
1637,
342,
267,
862,
26,
288,
6779,
63,
344,
275,
291,
14,
362,
63,
5602,
63,
344,
8,
5602,
14,
2325,
1012,
267,
871,
4067,
26,
288,
2512,
14,
1757,
8,
85,
7,
6531,
440,
2342,
6779,
1305,
367,
450,
83,
7,
450,
6779,
9,
288,
372,
942,
267,
519,
275,
291,
14,
1730,
14,
362,
3508,
83,
15,
2384,
3149,
68,
6,
12605,
2458,
68,
7,
450,
334,
277,
14,
1000,
63,
633,
12,
6779,
63,
344,
12,
14718,
430,
267,
9108,
275,
17132,
8,
82,
14,
1317,
12,
291,
14,
2427,
63,
3179,
9,
267,
19297,
275,
942,
267,
367,
1962,
315,
9108,
360,
454,
297,
791,
533,
356,
283,
69,
321,
1856,
9709,
936,
304,
288,
10106,
275,
1962,
360,
2076,
358,
288,
340,
1109,
8,
9041,
59,
16,
1055,
505,
14,
1913,
1012,
1137,
14718,
503,
1109,
8,
9041,
59,
17,
1055,
505,
14,
1913,
1012,
1137,
11052,
26,
355,
1980,
288,
340,
10106,
59,
22,
1055,
505,
14,
1913,
837,
355,
2512,
14,
1757,
8,
85,
7,
18297,
946,
9332,
1742,
5789,
581,
358,
355,
1980,
288,
1007,
63,
1205,
275,
10106,
59,
21,
1055,
505,
14,
1913,
342,
288,
340,
1007,
63,
1205,
1137,
283,
19908,
356,
355,
2512,
14,
1757,
8,
85,
7,
14858,
18197,
2004,
450,
83,
7,
450,
1007,
63,
1205,
9,
355,
1980,
288,
1007,
63,
3671,
275,
291,
14,
362,
63,
3671,
8,
9041,
59,
19,
1055,
505,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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|
#########################################################################
#
# Copyright (c) 2003-2004 Danny Brewer d29583@groovegarden.com
# Copyright (C) 2004-2010 OpenERP SA (<http://openerp.com>).
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# See: http://www.gnu.org/licenses/lgpl.html
#
#############################################################################
import uno
import string
import unohelper
import xmlrpclib
import base64, tempfile
from com.sun.star.task import XJobExecutor
import os
import sys
if __name__<>'package':
from lib.gui import *
from lib.error import *
from LoginTest import *
from lib.logreport import *
from lib.rpc import *
database="test"
uid = 3
class ModifyExistingReport(unohelper.Base, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
self.module = "openerp_report"
self.version = "0.1"
LoginTest()
if not loginstatus and __name__=="package":
exit(1)
self.win = DBModalDialog(60, 50, 180, 120, "Modify Existing Report")
self.win.addFixedText("lblReport", 2, 3, 60, 15, "Report Selection")
self.win.addComboListBox("lstReport", -1,15,178,80 , False )
self.lstReport = self.win.getControl( "lstReport" )
desktop=getDesktop()
doc = desktop.getCurrentComponent()
docinfo=doc.getDocumentInfo()
self.logobj=Logger()
self.hostname = docinfo.getUserFieldValue(0)
global passwd
self.password = passwd
global url
self.sock=RPCSession(url)
# Open a new connexion to the server
ids = self.sock.execute(database, uid, self.password, 'ir.module.module', 'search', [('name','=','base_report_designer'),('state', '=', 'installed')])
if not len(ids):
ErrorDialog("Please install base_report_designer module.", "", "Module Uninstalled Error!")
exit(1)
ids = self.sock.execute(database, uid, self.password, 'ir.actions.report.xml', 'search', [('report_xsl', '=', False),('report_xml', '=', False)])
fields=['id', 'name','report_name','model']
self.reports = self.sock.execute(database, uid, self.password, 'ir.actions.report.xml', 'read', ids, fields)
self.report_with_id = []
for report in self.reports:
if report['name']<>"":
model_ids = self.sock.execute(database, uid, self.password, 'ir.model' , 'search', [('model','=', report['model'])])
model_res_other =self.sock.execute(database, uid, self.password, 'ir.model', 'read', model_ids, [ 'name', 'model' ] )
if model_res_other <> []:
name = model_res_other[0]['name'] + " - " + report['name']
else:
name = report['name'] + " - " + report['model']
self.report_with_id.append( (report['id'], name, report['model'] ) )
self.report_with_id.sort( lambda x, y: cmp( x[1], y[1] ) )
for id, report_name, model_name in self.report_with_id:
self.lstReport.addItem( report_name, self.lstReport.getItemCount() )
self.win.addButton('btnSave',10,-5,50,15,'Open Report' ,actionListenerProc = self.btnOk_clicked )
self.win.addButton('btnCancel',-10 ,-5,50,15,'Cancel' ,actionListenerProc = self.btnCancel_clicked )
self.win.addButton('btnDelete',15 -80 ,-5,50,15,'Delete Report',actionListenerProc = self.btnDelete_clicked)
self.win.doModalDialog("lstReport",self.report_with_id[0][1] )
def btnOk_clicked(self, oActionEvent):
try:
desktop=getDesktop()
doc = desktop.getCurrentComponent()
docinfo=doc.getDocumentInfo()
selectedItemPos = self.win.getListBoxSelectedItemPos( "lstReport" )
id = self.report_with_id[ selectedItemPos ][0]
res = self.sock.execute(database, uid, self.password, 'ir.actions.report.xml', 'report_get', id)
if res['file_type'] in ['sxw','odt'] :
file_type = res['file_type']
else :
file_type = 'sxw'
fp_name = tempfile.mktemp('.'+file_type)
fp_name1="r"+fp_name
fp_path=os.path.join(fp_name1).replace("\\","/")
fp_win=fp_path[1:]
filename = ( os.name == 'nt' and fp_win or fp_name )
if res['report_sxw_content']:
write_data_to_file( filename, base64.decodestring(res['report_sxw_content']))
url = "file:///%s" % filename
arr=Array(makePropertyValue("MediaType","application/vnd.sun.xml.writer"),)
oDoc2 = desktop.loadComponentFromURL(url, "openerp", 55, arr)
docinfo2=oDoc2.getDocumentInfo()
docinfo2.setUserFieldValue(0, self.hostname)
docinfo2.setUserFieldValue(1,self.password)
docinfo2.setUserFieldValue(2,id)
docinfo2.setUserFieldValue(3,self.report_with_id[selectedItemPos][2])
oParEnum = oDoc2.getTextFields().createEnumeration()
while oParEnum.hasMoreElements():
oPar = oParEnum.nextElement()
if oPar.supportsService("com.sun.star.text.TextField.DropDown"):
oPar.SelectedItem = oPar.Items[0]
oPar.update()
if oDoc2.isModified():
if oDoc2.hasLocation() and not oDoc2.isReadonly():
oDoc2.store()
ErrorDialog("Download is completed.","Your file has been placed here :\n ."+ fp_name,"Download Message !")
obj=Logger()
obj.log_write('Modify Existing Report',LOG_INFO, ':successful download report %s using database %s' % (self.report_with_id[selectedItemPos][2], database))
except Exception, e:
ErrorDialog("The report could not be downloaded.", "Report: %s\nDetails: %s" % ( fp_name, str(e) ),"Download Message !")
import traceback,sys
info = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
self.logobj.log_write('ModifyExistingReport', LOG_ERROR, info)
self.win.endExecute()
def btnCancel_clicked(self, oActionEvent):
self.win.endExecute()
def btnDelete_clicked(self, oActionEvent):
desktop=getDesktop()
doc = desktop.getCurrentComponent()
docinfo=doc.getDocumentInfo()
selectedItemPos = self.win.getListBoxSelectedItemPos( "lstReport" )
name=self.win.getListBoxSelectedItem ("lstReport")
id = self.report_with_id[ selectedItemPos ][0]
temp = self.sock.execute(database, uid, self.password, 'ir.actions.report.xml', 'unlink', id,)
str_value='ir.actions.report.xml,'+str(id)
ids = self.sock.execute(database, uid, self.password, 'ir.values' , 'search',[('value','=',str_value)])
if ids:
rec = self.sock.execute(database, uid, self.password, 'ir.values', 'unlink', ids,)
else :
pass
if temp:
ErrorDialog("Report", "The report could not be deleted:\n"+name+".", "Message !")
self.logobj.log_write('Delete Report', LOG_INFO, ': report %s successfully deleted using database %s.' % (name, database))
else:
ErrorDialog("Report", "The report could not be deleted:\n"+name+".", "Message !")
self.win.endExecute()
if __name__<>"package" and __name__=="__main__":
ModifyExistingReport(None)
elif __name__=="package":
g_ImplementationHelper.addImplementation( ModifyExistingReport, "org.openoffice.openerp.report.modifyreport", ("com.sun.star.task.Job",),)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3949,
3,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
13004,
13,
15431,
577,
1189,
89,
699,
264,
2135,
366,
1398,
16793,
32,
23260,
79,
432,
23909,
848,
14,
957,
199,
3,
221,
1898,
334,
35,
9,
8353,
13,
6542,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
221,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
221,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
221,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
221,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
221,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
221,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
221,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
3,
221,
1666,
26,
221,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
199,
3,
199,
31635,
199,
199,
646,
625,
79,
199,
646,
1059,
199,
646,
625,
79,
3676,
199,
646,
19122,
199,
646,
1300,
772,
12,
5549,
421,
199,
504,
2414,
14,
11846,
14,
7848,
14,
1765,
492,
1323,
6694,
16752,
199,
646,
747,
199,
646,
984,
199,
692,
636,
354,
363,
28,
3524,
2491,
356,
272,
687,
1973,
14,
5885,
492,
627,
272,
687,
1973,
14,
705,
492,
627,
272,
687,
16430,
774,
492,
627,
272,
687,
1973,
14,
793,
3070,
492,
627,
272,
687,
1973,
14,
4354,
492,
627,
272,
3050,
628,
396,
2,
272,
1747,
275,
650,
199,
199,
533,
22520,
23490,
7457,
8,
324,
79,
3676,
14,
1563,
12,
1323,
6694,
16752,
304,
272,
347,
636,
826,
721,
277,
12,
4027,
304,
267,
291,
14,
3799,
258,
275,
4027,
267,
291,
14,
578,
221,
275,
298,
11267,
63,
3070,
2,
267,
291,
14,
1023,
275,
298,
16,
14,
17,
2,
398,
16430,
774,
342,
267,
340,
440,
4676,
1205,
436,
636,
354,
363,
11800,
2491,
582,
288,
4458,
8,
17,
9,
398,
291,
14,
2676,
275,
6249,
23689,
5619,
8,
2259,
12,
5238,
12,
13576,
12,
13960,
12,
298,
18357,
1316,
26958,
11774,
531,
267,
291,
14,
2676,
14,
525,
9515,
1872,
480,
18842,
7457,
401,
499,
12,
650,
12,
5212,
12,
4114,
12,
298,
7457,
3240,
1486,
531,
267,
291,
14,
2676,
14,
525,
12413,
26764,
480,
6916,
7457,
401,
446,
17,
12,
1046,
12,
11175,
12,
1257,
2360,
756,
776,
267,
291,
14,
6916,
7457,
275,
291,
14,
2676,
14,
25117,
8,
298,
6916,
7457,
2,
776,
267,
19763,
29,
362,
20436,
342,
267,
1382,
275,
19763,
14,
16662,
7004,
342,
267,
1382,
815,
29,
1301,
14,
362,
5564,
2354,
342,
267,
291,
14,
793,
1113,
29,
4455,
342,
267,
291,
14,
4269,
275,
1382,
815,
14,
32627,
792,
1110,
8,
16,
9,
267,
2288,
15081,
267,
291,
14,
2060,
275,
15081,
267,
2288,
1166,
267,
291,
14,
5096,
29,
18612,
3298,
3552,
8,
633,
9,
267,
327,
3232,
282,
892,
2557,
476,
1636,
370,
314,
1654,
7318,
2762,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
578,
14,
578,
297,
283,
1733,
297,
4274,
354,
1673,
29511,
1095,
63,
3070,
63,
14748,
281,
8157,
929,
297,
6291,
283,
7657,
2023,
267,
340,
440,
822,
8,
1580,
304,
288,
4520,
5619,
480,
8254,
3907,
1300,
63,
3070,
63,
14748,
281,
859,
4765,
4873,
298,
2377,
1910,
7657,
4520,
9124,
288,
4458,
8,
17,
9,
398,
2762,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
3723,
14,
3070,
14,
1652,
297,
283,
1733,
297,
4274,
3070,
63,
19324,
297,
6291,
756,
11169,
3070,
63,
1652,
297,
6291,
756,
3948,
398,
1504,
2968,
344,
297,
283,
354,
1673,
3070,
63,
354,
1673,
1238,
418,
398,
291,
14,
15629,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
3723,
14,
3070,
14,
1652,
297,
283,
739,
297,
2762,
12,
1504,
9,
267,
291,
14,
3070,
63,
1045,
63,
344,
275,
942,
398,
367,
3622,
315,
291,
14,
15629,
26,
288,
340,
3622,
459,
354,
418,
16137,
29679,
355,
1402,
63,
1580,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
1238,
7,
2360,
221,
283,
1733,
297,
4274,
1238,
18937,
3622,
459,
1238,
31161,
355,
1402,
63,
470,
63,
1848,
275,
277,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
1238,
297,
283,
739,
297,
1402,
63,
1580,
12,
359,
283,
354,
297,
283,
1238,
7,
1622,
776,
355,
340,
1402,
63,
470,
63,
1848,
20941,
18410,
490,
536,
275,
1402,
63,
470,
63,
1848,
59,
16,
2733,
354,
418,
435,
298,
446,
298,
435,
3622,
459,
354,
418,
355,
587,
26,
490,
536,
275,
3622,
459,
354,
418,
435,
298,
446,
298,
435,
3622,
459,
1238,
418,
355,
291,
14,
3070,
63,
1045,
63,
344,
14,
740,
8,
334,
3070,
459,
344,
995,
536,
12,
3622,
459,
1238,
418,
776,
776,
398,
291,
14,
3070,
63,
1045,
63,
344,
14,
3191,
8,
2400,
671,
12,
612,
26,
10467,
8,
671,
59,
17,
467,
612,
59,
17,
61,
776,
776,
398,
367,
1305,
12,
3622,
63,
354,
12,
1402,
63,
354,
315,
291,
14,
3070,
63,
1045,
63,
344,
26,
288,
291,
14,
6916,
7457,
14,
19798,
8,
3622,
63,
354,
12,
291,
14,
6916,
7457,
14,
362,
2081,
2353,
342,
776,
398,
291,
14,
2676,
14,
525,
4259,
360,
9633,
8229,
297
] |
[
3,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
13004,
13,
15431,
577,
1189,
89,
699,
264,
2135,
366,
1398,
16793,
32,
23260,
79,
432,
23909,
848,
14,
957,
199,
3,
221,
1898,
334,
35,
9,
8353,
13,
6542,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
221,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
221,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
221,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
221,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
221,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
221,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
221,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
221,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
3,
221,
1666,
26,
221,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
199,
3,
199,
31635,
199,
199,
646,
625,
79,
199,
646,
1059,
199,
646,
625,
79,
3676,
199,
646,
19122,
199,
646,
1300,
772,
12,
5549,
421,
199,
504,
2414,
14,
11846,
14,
7848,
14,
1765,
492,
1323,
6694,
16752,
199,
646,
747,
199,
646,
984,
199,
692,
636,
354,
363,
28,
3524,
2491,
356,
272,
687,
1973,
14,
5885,
492,
627,
272,
687,
1973,
14,
705,
492,
627,
272,
687,
16430,
774,
492,
627,
272,
687,
1973,
14,
793,
3070,
492,
627,
272,
687,
1973,
14,
4354,
492,
627,
272,
3050,
628,
396,
2,
272,
1747,
275,
650,
199,
199,
533,
22520,
23490,
7457,
8,
324,
79,
3676,
14,
1563,
12,
1323,
6694,
16752,
304,
272,
347,
636,
826,
721,
277,
12,
4027,
304,
267,
291,
14,
3799,
258,
275,
4027,
267,
291,
14,
578,
221,
275,
298,
11267,
63,
3070,
2,
267,
291,
14,
1023,
275,
298,
16,
14,
17,
2,
398,
16430,
774,
342,
267,
340,
440,
4676,
1205,
436,
636,
354,
363,
11800,
2491,
582,
288,
4458,
8,
17,
9,
398,
291,
14,
2676,
275,
6249,
23689,
5619,
8,
2259,
12,
5238,
12,
13576,
12,
13960,
12,
298,
18357,
1316,
26958,
11774,
531,
267,
291,
14,
2676,
14,
525,
9515,
1872,
480,
18842,
7457,
401,
499,
12,
650,
12,
5212,
12,
4114,
12,
298,
7457,
3240,
1486,
531,
267,
291,
14,
2676,
14,
525,
12413,
26764,
480,
6916,
7457,
401,
446,
17,
12,
1046,
12,
11175,
12,
1257,
2360,
756,
776,
267,
291,
14,
6916,
7457,
275,
291,
14,
2676,
14,
25117,
8,
298,
6916,
7457,
2,
776,
267,
19763,
29,
362,
20436,
342,
267,
1382,
275,
19763,
14,
16662,
7004,
342,
267,
1382,
815,
29,
1301,
14,
362,
5564,
2354,
342,
267,
291,
14,
793,
1113,
29,
4455,
342,
267,
291,
14,
4269,
275,
1382,
815,
14,
32627,
792,
1110,
8,
16,
9,
267,
2288,
15081,
267,
291,
14,
2060,
275,
15081,
267,
2288,
1166,
267,
291,
14,
5096,
29,
18612,
3298,
3552,
8,
633,
9,
267,
327,
3232,
282,
892,
2557,
476,
1636,
370,
314,
1654,
7318,
2762,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
578,
14,
578,
297,
283,
1733,
297,
4274,
354,
1673,
29511,
1095,
63,
3070,
63,
14748,
281,
8157,
929,
297,
6291,
283,
7657,
2023,
267,
340,
440,
822,
8,
1580,
304,
288,
4520,
5619,
480,
8254,
3907,
1300,
63,
3070,
63,
14748,
281,
859,
4765,
4873,
298,
2377,
1910,
7657,
4520,
9124,
288,
4458,
8,
17,
9,
398,
2762,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
3723,
14,
3070,
14,
1652,
297,
283,
1733,
297,
4274,
3070,
63,
19324,
297,
6291,
756,
11169,
3070,
63,
1652,
297,
6291,
756,
3948,
398,
1504,
2968,
344,
297,
283,
354,
1673,
3070,
63,
354,
1673,
1238,
418,
398,
291,
14,
15629,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
3723,
14,
3070,
14,
1652,
297,
283,
739,
297,
2762,
12,
1504,
9,
267,
291,
14,
3070,
63,
1045,
63,
344,
275,
942,
398,
367,
3622,
315,
291,
14,
15629,
26,
288,
340,
3622,
459,
354,
418,
16137,
29679,
355,
1402,
63,
1580,
275,
291,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
1238,
7,
2360,
221,
283,
1733,
297,
4274,
1238,
18937,
3622,
459,
1238,
31161,
355,
1402,
63,
470,
63,
1848,
275,
277,
14,
5096,
14,
2526,
8,
4659,
12,
1747,
12,
291,
14,
2060,
12,
283,
723,
14,
1238,
297,
283,
739,
297,
1402,
63,
1580,
12,
359,
283,
354,
297,
283,
1238,
7,
1622,
776,
355,
340,
1402,
63,
470,
63,
1848,
20941,
18410,
490,
536,
275,
1402,
63,
470,
63,
1848,
59,
16,
2733,
354,
418,
435,
298,
446,
298,
435,
3622,
459,
354,
418,
355,
587,
26,
490,
536,
275,
3622,
459,
354,
418,
435,
298,
446,
298,
435,
3622,
459,
1238,
418,
355,
291,
14,
3070,
63,
1045,
63,
344,
14,
740,
8,
334,
3070,
459,
344,
995,
536,
12,
3622,
459,
1238,
418,
776,
776,
398,
291,
14,
3070,
63,
1045,
63,
344,
14,
3191,
8,
2400,
671,
12,
612,
26,
10467,
8,
671,
59,
17,
467,
612,
59,
17,
61,
776,
776,
398,
367,
1305,
12,
3622,
63,
354,
12,
1402,
63,
354,
315,
291,
14,
3070,
63,
1045,
63,
344,
26,
288,
291,
14,
6916,
7457,
14,
19798,
8,
3622,
63,
354,
12,
291,
14,
6916,
7457,
14,
362,
2081,
2353,
342,
776,
398,
291,
14,
2676,
14,
525,
4259,
360,
9633,
8229,
297,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kurttheviking/agileid-py
|
tests/test_to_hexstring.py
|
1
|
1201
|
from bson.objectid import ObjectId
import os
import sys
import unittest
sys.path.insert(0, os.path.abspath('..'))
import agileid
def to_hexstring_invalid():
return agileid.to_hexstring('rar')
def to_hexstring_invalid_oid():
oid = str(ObjectId())
return agileid.to_hexstring('user!' + oid)
class Test(unittest.TestCase):
def setUp(self):
pass
def test_cast_aid(self):
aid = 'VUKNcId-tiJpAMRH'
oid = '55428d70877eb6226900c447'
self.assertEqual(agileid.to_hexstring(aid), oid)
def test_cast_aid_scoped(self):
aid = 'user!VUKNcId-tiJpAMRH'
oid = '55428d70877eb6226900c447'
self.assertEqual(agileid.to_hexstring(aid), oid)
def test_cast_oid(self):
oid = ObjectId()
self.assertEqual(agileid.to_hexstring(oid), str(oid))
def test_cast_oid_str(self):
oid = str(ObjectId())
self.assertEqual(agileid.to_hexstring(oid), oid)
def test_cast_aid_invalid(self):
self.assertRaises(ValueError, to_hexstring_invalid)
def test_cast_aid_invalid_oid(self):
self.assertRaises(ValueError, to_hexstring_invalid_oid)
if __name__ == '__main__':
unittest.main()
|
isc
|
[
504,
330,
834,
14,
1113,
31157,
492,
6935,
1304,
199,
646,
747,
199,
646,
984,
199,
646,
2882,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24893,
1333,
199,
199,
646,
1839,
441,
344,
421,
199,
318,
370,
63,
4097,
875,
63,
3197,
837,
272,
372,
1839,
441,
344,
14,
475,
63,
4097,
875,
360,
26378,
358,
421,
199,
318,
370,
63,
4097,
875,
63,
3197,
63,
1170,
837,
272,
20109,
275,
620,
8,
1692,
1304,
1012,
272,
372,
1839,
441,
344,
14,
475,
63,
4097,
875,
360,
751,
11213,
435,
20109,
9,
421,
199,
533,
1379,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
986,
339,
347,
511,
63,
2931,
63,
21745,
8,
277,
304,
267,
23939,
275,
283,
54,
26667,
46,
67,
1304,
13,
280,
42,
80,
1156,
31809,
7,
267,
20109,
275,
283,
19264,
1651,
68,
23,
2036,
1138,
2871,
30603,
1876,
383,
67,
20773,
7,
398,
291,
14,
629,
8,
643,
441,
344,
14,
475,
63,
4097,
875,
8,
21745,
395,
20109,
9,
339,
347,
511,
63,
2931,
63,
21745,
63,
23254,
8,
277,
304,
267,
23939,
275,
283,
751,
1,
54,
26667,
46,
67,
1304,
13,
280,
42,
80,
1156,
31809,
7,
267,
20109,
275,
283,
19264,
1651,
68,
23,
2036,
1138,
2871,
30603,
1876,
383,
67,
20773,
7,
398,
291,
14,
629,
8,
643,
441,
344,
14,
475,
63,
4097,
875,
8,
21745,
395,
20109,
9,
339,
347,
511,
63,
2931,
63,
1170,
8,
277,
304,
267,
20109,
275,
6935,
1304,
342,
267,
291,
14,
629,
8,
643,
441,
344,
14,
475,
63,
4097,
875,
8,
1170,
395,
620,
8,
1170,
430,
339,
347,
511,
63,
2931,
63,
1170,
63,
495,
8,
277,
304,
267,
20109,
275,
620,
8,
1692,
1304,
1012,
267,
291,
14,
629,
8,
643,
441,
344,
14,
475,
63,
4097,
875,
8,
1170,
395,
20109,
9,
339,
347,
511,
63,
2931,
63,
21745,
63,
3197,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
370,
63,
4097,
875,
63,
3197,
9,
339,
347,
511,
63,
2931,
63,
21745,
63,
3197,
63,
1170,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
370,
63,
4097,
875,
63,
3197,
63,
1170,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
330,
834,
14,
1113,
31157,
492,
6935,
1304,
199,
646,
747,
199,
646,
984,
199,
646,
2882,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24893,
1333,
199,
199,
646,
1839,
441,
344,
421,
199,
318,
370,
63,
4097,
875,
63,
3197,
837,
272,
372,
1839,
441,
344,
14,
475,
63,
4097,
875,
360,
26378,
358,
421,
199,
318,
370,
63,
4097,
875,
63,
3197,
63,
1170,
837,
272,
20109,
275,
620,
8,
1692,
1304,
1012,
272,
372,
1839,
441,
344,
14,
475,
63,
4097,
875,
360,
751,
11213,
435,
20109,
9,
421,
199,
533,
1379,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
986,
339,
347,
511,
63,
2931,
63,
21745,
8,
277,
304,
267,
23939,
275,
283,
54,
26667,
46,
67,
1304,
13,
280,
42,
80,
1156,
31809,
7,
267,
20109,
275,
283,
19264,
1651,
68,
23,
2036,
1138,
2871,
30603,
1876,
383,
67,
20773,
7,
398,
291,
14,
629,
8,
643,
441,
344,
14,
475,
63,
4097,
875,
8,
21745,
395,
20109,
9,
339,
347,
511,
63,
2931,
63,
21745,
63,
23254,
8,
277,
304,
267,
23939,
275,
283,
751,
1,
54,
26667,
46,
67,
1304,
13,
280,
42,
80,
1156,
31809,
7,
267,
20109,
275,
283,
19264,
1651,
68,
23,
2036,
1138,
2871,
30603,
1876,
383,
67,
20773,
7,
398,
291,
14,
629,
8,
643,
441,
344,
14,
475,
63,
4097,
875,
8,
21745,
395,
20109,
9,
339,
347,
511,
63,
2931,
63,
1170,
8,
277,
304,
267,
20109,
275,
6935,
1304,
342,
267,
291,
14,
629,
8,
643,
441,
344,
14,
475,
63,
4097,
875,
8,
1170,
395,
620,
8,
1170,
430,
339,
347,
511,
63,
2931,
63,
1170,
63,
495,
8,
277,
304,
267,
20109,
275,
620,
8,
1692,
1304,
1012,
267,
291,
14,
629,
8,
643,
441,
344,
14,
475,
63,
4097,
875,
8,
1170,
395,
20109,
9,
339,
347,
511,
63,
2931,
63,
21745,
63,
3197,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
370,
63,
4097,
875,
63,
3197,
9,
339,
347,
511,
63,
2931,
63,
21745,
63,
3197,
63,
1170,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
370,
63,
4097,
875,
63,
3197,
63,
1170,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
masami256/Anaconda-for-ore-ore-kernel
|
pyanaconda/textw/language_text.py
|
1
|
2653
|
#
# language_text.py: text mode language selection dialog
#
# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
# All rights reserved.
#
# 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, see <http://www.gnu.org/licenses/>.
#
from snack import *
from constants_text import *
from pyanaconda.constants import *
import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
import logging
log = logging.getLogger("anaconda")
class LanguageWindow:
def __call__(self, screen, anaconda):
languages = anaconda.instLanguage.available ()
languages.sort()
current = anaconda.instLanguage.instLang
height = min((8, len(languages)))
buttons = [TEXT_OK_BUTTON, TEXT_BACK_BUTTON]
translated = []
for lang in languages:
translated.append ((_(lang), anaconda.instLanguage.getLangByName(lang)))
(button, choice) = \
ListboxChoiceWindow(screen, _("Language Selection"),
_("What language would you like to use during the "
"installation process?"), translated,
buttons, width = 30, default = _(current), scroll = 1,
height = height, help = "lang")
if button == TEXT_BACK_CHECK:
return INSTALL_BACK
if anaconda.instLanguage.getFontFile(choice) == "none":
ButtonChoiceWindow(screen, "Language Unavailable",
"%s display is unavailable in text mode. The "
"installation will continue in English." % (choice,),
buttons=[TEXT_OK_BUTTON])
anaconda.instLanguage.instLang = choice
anaconda.instLanguage.systemLang = choice
anaconda.timezone.setTimezoneInfo(anaconda.instLanguage.getDefaultTimeZone(anaconda.rootPath))
return INSTALL_OK
anaconda.instLanguage.instLang = choice
anaconda.instLanguage.systemLang = choice
anaconda.timezone.setTimezoneInfo(anaconda.instLanguage.getDefaultTimeZone(anaconda.rootPath))
anaconda.intf.drawFrame()
return INSTALL_OK
|
gpl-2.0
|
[
3,
199,
3,
2637,
63,
505,
14,
647,
26,
1318,
818,
2637,
7267,
9592,
199,
3,
199,
3,
1898,
334,
35,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
221,
9572,
13002,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
504,
6895,
564,
492,
627,
199,
504,
5262,
63,
505,
492,
627,
199,
199,
504,
1134,
28299,
14,
5559,
492,
627,
199,
646,
9796,
199,
63,
275,
2400,
671,
26,
9796,
14,
1447,
5152,
480,
28299,
401,
671,
9,
199,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
480,
28299,
531,
199,
199,
533,
8466,
4301,
26,
272,
347,
636,
1250,
721,
277,
12,
6426,
12,
376,
16928,
983,
304,
267,
10815,
275,
376,
16928,
983,
14,
3615,
8493,
14,
4561,
6248,
267,
10815,
14,
3191,
342,
398,
1453,
275,
376,
16928,
983,
14,
3615,
8493,
14,
3615,
14654,
398,
4569,
275,
1748,
1332,
24,
12,
822,
8,
13209,
1724,
199,
198,
15687,
275,
359,
3876,
63,
3593,
63,
13272,
12,
11951,
63,
7111,
63,
13272,
61,
398,
14598,
275,
942,
267,
367,
6339,
315,
10815,
26,
288,
14598,
14,
740,
334,
27594,
4159,
395,
376,
16928,
983,
14,
3615,
8493,
14,
362,
14654,
11190,
8,
4159,
1724,
267,
334,
3887,
12,
7141,
9,
275,
971,
288,
3820,
1977,
9054,
4301,
8,
5410,
12,
3824,
8493,
3240,
1486,
1288,
686,
198,
14332,
21015,
2637,
3955,
1265,
2839,
370,
675,
5309,
314,
298,
1585,
221,
298,
23048,
2112,
31,
1288,
14598,
12,
20866,
198,
15687,
12,
3462,
275,
4233,
12,
849,
275,
12561,
1818,
395,
13704,
275,
413,
12,
1816,
4569,
275,
4569,
12,
1720,
275,
298,
4159,
531,
398,
340,
5528,
508,
11951,
63,
7111,
63,
8936,
26,
288,
372,
20514,
1761,
63,
7111,
398,
340,
376,
16928,
983,
14,
3615,
8493,
14,
362,
6986,
1173,
8,
5095,
9,
508,
298,
3592,
582,
288,
16005,
9054,
4301,
8,
5410,
12,
298,
8493,
1910,
4561,
401,
3044,
2071,
83,
2929,
365,
18735,
315,
1318,
818,
14,
221,
710,
298,
3044,
298,
23048,
911,
1980,
315,
20144,
2122,
450,
334,
5095,
4706,
3044,
15766,
1524,
3876,
63,
3593,
63,
13272,
566,
288,
376,
16928,
983,
14,
3615,
8493,
14,
3615,
14654,
275,
7141,
288,
376,
16928,
983,
14,
3615,
8493,
14,
2253,
14654,
275,
7141,
288,
376,
16928,
983,
14,
7145,
14,
409,
28705,
2354,
8,
28299,
14,
3615,
8493,
14,
362,
2698,
32515,
8,
28299,
14,
1231,
2042,
430,
288,
372,
20514,
1761,
63,
3593,
398,
376,
16928,
983,
14,
3615,
8493,
14,
3615,
14654,
275,
7141,
267,
376,
16928,
983,
14,
3615,
8493,
14,
2253,
14654,
275,
7141,
267,
376,
16928,
983,
14,
7145,
14,
409,
28705,
2354,
8,
28299,
14,
3615,
8493,
14,
362,
2698,
32515,
8,
28299,
14,
1231,
2042,
430,
421,
198,
28299,
14,
21100,
14,
5485,
3160,
342,
398,
372,
20514,
1761,
63,
3593,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2637,
63,
505,
14,
647,
26,
1318,
818,
2637,
7267,
9592,
199,
3,
199,
3,
1898,
334,
35,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
221,
9572,
13002,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
504,
6895,
564,
492,
627,
199,
504,
5262,
63,
505,
492,
627,
199,
199,
504,
1134,
28299,
14,
5559,
492,
627,
199,
646,
9796,
199,
63,
275,
2400,
671,
26,
9796,
14,
1447,
5152,
480,
28299,
401,
671,
9,
199,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
480,
28299,
531,
199,
199,
533,
8466,
4301,
26,
272,
347,
636,
1250,
721,
277,
12,
6426,
12,
376,
16928,
983,
304,
267,
10815,
275,
376,
16928,
983,
14,
3615,
8493,
14,
4561,
6248,
267,
10815,
14,
3191,
342,
398,
1453,
275,
376,
16928,
983,
14,
3615,
8493,
14,
3615,
14654,
398,
4569,
275,
1748,
1332,
24,
12,
822,
8,
13209,
1724,
199,
198,
15687,
275,
359,
3876,
63,
3593,
63,
13272,
12,
11951,
63,
7111,
63,
13272,
61,
398,
14598,
275,
942,
267,
367,
6339,
315,
10815,
26,
288,
14598,
14,
740,
334,
27594,
4159,
395,
376,
16928,
983,
14,
3615,
8493,
14,
362,
14654,
11190,
8,
4159,
1724,
267,
334,
3887,
12,
7141,
9,
275,
971,
288,
3820,
1977,
9054,
4301,
8,
5410,
12,
3824,
8493,
3240,
1486,
1288,
686,
198,
14332,
21015,
2637,
3955,
1265,
2839,
370,
675,
5309,
314,
298,
1585,
221,
298,
23048,
2112,
31,
1288,
14598,
12,
20866,
198,
15687,
12,
3462,
275,
4233,
12,
849,
275,
12561,
1818,
395,
13704,
275,
413,
12,
1816,
4569,
275,
4569,
12,
1720,
275,
298,
4159,
531,
398,
340,
5528,
508,
11951,
63,
7111,
63,
8936,
26,
288,
372,
20514,
1761,
63,
7111,
398,
340,
376,
16928,
983,
14,
3615,
8493,
14,
362,
6986,
1173,
8,
5095,
9,
508,
298,
3592,
582,
288,
16005,
9054,
4301,
8,
5410,
12,
298,
8493,
1910,
4561,
401,
3044,
2071,
83,
2929,
365,
18735,
315,
1318,
818,
14,
221,
710,
298,
3044,
298,
23048,
911,
1980,
315,
20144,
2122,
450,
334,
5095,
4706,
3044,
15766,
1524,
3876,
63,
3593,
63,
13272,
566,
288,
376,
16928,
983,
14,
3615,
8493,
14,
3615,
14654,
275,
7141,
288,
376,
16928,
983,
14,
3615,
8493,
14,
2253,
14654,
275,
7141,
288,
376,
16928,
983,
14,
7145,
14,
409,
28705,
2354,
8,
28299,
14,
3615,
8493,
14,
362,
2698,
32515,
8,
28299,
14,
1231,
2042,
430,
288,
372,
20514,
1761,
63,
3593,
398,
376,
16928,
983,
14,
3615,
8493,
14,
3615,
14654,
275,
7141,
267,
376,
16928,
983,
14,
3615,
8493,
14,
2253,
14654,
275,
7141,
267,
376,
16928,
983,
14,
7145,
14,
409,
28705,
2354,
8,
28299,
14,
3615,
8493,
14,
362,
2698,
32515,
8,
28299,
14,
1231,
2042,
430,
421,
198,
28299,
14,
21100,
14,
5485,
3160,
342,
398,
372,
20514,
1761,
63,
3593,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
wangyum/spark
|
examples/src/main/python/ml/tokenizer_example.py
|
27
|
2044
|
#
# 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.
#
# $example on$
from pyspark.ml.feature import Tokenizer, RegexTokenizer
from pyspark.sql.functions import col, udf
from pyspark.sql.types import IntegerType
# $example off$
from pyspark.sql import SparkSession
if __name__ == "__main__":
spark = SparkSession\
.builder\
.appName("TokenizerExample")\
.getOrCreate()
# $example on$
sentenceDataFrame = spark.createDataFrame([
(0, "Hi I heard about Spark"),
(1, "I wish Java could use case classes"),
(2, "Logistic,regression,models,are,neat")
], ["id", "sentence"])
tokenizer = Tokenizer(inputCol="sentence", outputCol="words")
regexTokenizer = RegexTokenizer(inputCol="sentence", outputCol="words", pattern="\\W")
# alternatively, pattern="\\w+", gaps(False)
countTokens = udf(lambda words: len(words), IntegerType())
tokenized = tokenizer.transform(sentenceDataFrame)
tokenized.select("sentence", "words")\
.withColumn("tokens", countTokens(col("words"))).show(truncate=False)
regexTokenized = regexTokenizer.transform(sentenceDataFrame)
regexTokenized.select("sentence", "words") \
.withColumn("tokens", countTokens(col("words"))).show(truncate=False)
# $example off$
spark.stop()
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
3,
2672,
2694,
641,
4,
199,
504,
15847,
14,
757,
14,
4445,
492,
8767,
1793,
12,
12939,
21782,
199,
504,
15847,
14,
3009,
14,
5777,
492,
1048,
12,
399,
1587,
199,
504,
15847,
14,
3009,
14,
1313,
492,
7225,
804,
199,
3,
2672,
2694,
2331,
4,
199,
504,
15847,
14,
3009,
492,
13932,
4434,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
15442,
275,
13932,
4434,
60,
267,
1275,
5649,
60,
267,
1275,
571,
985,
480,
21782,
9846,
27681,
267,
1275,
30457,
2499,
342,
339,
327,
2672,
2694,
641,
4,
272,
14537,
9205,
275,
15442,
14,
25482,
779,
267,
334,
16,
12,
298,
16106,
473,
946,
1005,
3595,
13932,
1288,
267,
334,
17,
12,
298,
41,
13809,
9586,
4293,
675,
1930,
3992,
1288,
267,
334,
18,
12,
298,
2445,
6937,
12,
12513,
12,
992,
12,
1530,
12,
685,
292,
531,
272,
2156,
2097,
344,
401,
298,
17727,
3135,
339,
14803,
275,
8767,
1793,
8,
1210,
2001,
628,
17727,
401,
1072,
2001,
628,
3148,
531,
339,
5163,
21782,
275,
12939,
21782,
8,
1210,
2001,
628,
17727,
401,
1072,
2001,
628,
3148,
401,
3851,
628,
1103,
55,
531,
272,
327,
8679,
17330,
12,
3851,
628,
1103,
87,
22758,
486,
7461,
8,
797,
9,
339,
2338,
16419,
275,
399,
1587,
8,
2734,
5932,
26,
822,
8,
3148,
395,
7225,
804,
1012,
339,
1526,
1759,
275,
14803,
14,
4711,
8,
17727,
9205,
9,
272,
1526,
1759,
14,
2416,
480,
17727,
401,
298,
3148,
27681,
267,
1275,
1045,
4547,
480,
4504,
401,
2338,
16419,
8,
761,
480,
3148,
2237,
680,
2384,
8,
12517,
29,
797,
9,
339,
5163,
3264,
1759,
275,
5163,
21782,
14,
4711,
8,
17727,
9205,
9,
272,
5163,
3264,
1759,
14,
2416,
480,
17727,
401,
298,
3148,
531,
971,
267,
1275,
1045,
4547,
480,
4504,
401,
2338,
16419,
8,
761,
480,
3148,
2237,
680,
2384,
8,
12517,
29,
797,
9,
272,
327,
2672,
2694,
2331,
4,
339,
15442,
14,
2379,
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
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
3,
2672,
2694,
641,
4,
199,
504,
15847,
14,
757,
14,
4445,
492,
8767,
1793,
12,
12939,
21782,
199,
504,
15847,
14,
3009,
14,
5777,
492,
1048,
12,
399,
1587,
199,
504,
15847,
14,
3009,
14,
1313,
492,
7225,
804,
199,
3,
2672,
2694,
2331,
4,
199,
504,
15847,
14,
3009,
492,
13932,
4434,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
15442,
275,
13932,
4434,
60,
267,
1275,
5649,
60,
267,
1275,
571,
985,
480,
21782,
9846,
27681,
267,
1275,
30457,
2499,
342,
339,
327,
2672,
2694,
641,
4,
272,
14537,
9205,
275,
15442,
14,
25482,
779,
267,
334,
16,
12,
298,
16106,
473,
946,
1005,
3595,
13932,
1288,
267,
334,
17,
12,
298,
41,
13809,
9586,
4293,
675,
1930,
3992,
1288,
267,
334,
18,
12,
298,
2445,
6937,
12,
12513,
12,
992,
12,
1530,
12,
685,
292,
531,
272,
2156,
2097,
344,
401,
298,
17727,
3135,
339,
14803,
275,
8767,
1793,
8,
1210,
2001,
628,
17727,
401,
1072,
2001,
628,
3148,
531,
339,
5163,
21782,
275,
12939,
21782,
8,
1210,
2001,
628,
17727,
401,
1072,
2001,
628,
3148,
401,
3851,
628,
1103,
55,
531,
272,
327,
8679,
17330,
12,
3851,
628,
1103,
87,
22758,
486,
7461,
8,
797,
9,
339,
2338,
16419,
275,
399,
1587,
8,
2734,
5932,
26,
822,
8,
3148,
395,
7225,
804,
1012,
339,
1526,
1759,
275,
14803,
14,
4711,
8,
17727,
9205,
9,
272,
1526,
1759,
14,
2416,
480,
17727,
401,
298,
3148,
27681,
267,
1275,
1045,
4547,
480,
4504,
401,
2338,
16419,
8,
761,
480,
3148,
2237,
680,
2384,
8,
12517,
29,
797,
9,
339,
5163,
3264,
1759,
275,
5163,
21782,
14,
4711,
8,
17727,
9205,
9,
272,
5163,
3264,
1759,
14,
2416,
480,
17727,
401,
298,
3148,
531,
971,
267,
1275,
1045,
4547,
480,
4504,
401,
2338,
16419,
8,
761,
480,
3148,
2237,
680,
2384,
8,
12517,
29,
797,
9,
272,
327,
2672,
2694,
2331,
4,
339,
15442,
14,
2379,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Dandandan/wikiprogramming
|
jsrepl/extern/python/unclosured/lib/python2.7/lib2to3/fixes/fix_print.py
|
326
|
2865
|
# Copyright 2006 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Fixer for print.
Change:
'print' into 'print()'
'print ...' into 'print(...)'
'print ... ,' into 'print(..., end=" ")'
'print >>x, ...' into 'print(..., file=x)'
No changes are applied if print_function is imported from __future__
"""
# Local imports
from .. import patcomp
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name, Call, Comma, String, is_tuple
parend_expr = patcomp.compile_pattern(
"""atom< '(' [atom|STRING|NAME] ')' >"""
)
class FixPrint(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """
simple_stmt< any* bare='print' any* > | print_stmt
"""
def transform(self, node, results):
assert results
bare_print = results.get("bare")
if bare_print:
# Special-case print all by itself
bare_print.replace(Call(Name(u"print"), [],
prefix=bare_print.prefix))
return
assert node.children[0] == Name(u"print")
args = node.children[1:]
if len(args) == 1 and parend_expr.match(args[0]):
# We don't want to keep sticking parens around an
# already-parenthesised expression.
return
sep = end = file = None
if args and args[-1] == Comma():
args = args[:-1]
end = " "
if args and args[0] == pytree.Leaf(token.RIGHTSHIFT, u">>"):
assert len(args) >= 2
file = args[1].clone()
args = args[3:] # Strip a possible comma after the file expression
# Now synthesize a print(args, sep=..., end=..., file=...) node.
l_args = [arg.clone() for arg in args]
if l_args:
l_args[0].prefix = u""
if sep is not None or end is not None or file is not None:
if sep is not None:
self.add_kwarg(l_args, u"sep", String(repr(sep)))
if end is not None:
self.add_kwarg(l_args, u"end", String(repr(end)))
if file is not None:
self.add_kwarg(l_args, u"file", file)
n_stmt = Call(Name(u"print"), l_args)
n_stmt.prefix = node.prefix
return n_stmt
def add_kwarg(self, l_nodes, s_kwd, n_expr):
# XXX All this prefix-setting may lose comments (though rarely)
n_expr.prefix = u""
n_argument = pytree.Node(self.syms.argument,
(Name(s_kwd),
pytree.Leaf(token.EQUAL, u"="),
n_expr))
if l_nodes:
l_nodes.append(Comma())
n_argument.prefix = u" "
l_nodes.append(n_argument)
|
mit
|
[
3,
1898,
8315,
4475,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
11985,
281,
367,
870,
14,
199,
199,
4001,
26,
272,
283,
1361,
7,
3515,
1901,
283,
1361,
11716,
272,
283,
1361,
2263,
7,
420,
1901,
283,
1361,
29195,
3171,
272,
283,
1361,
2263,
20606,
259,
1901,
283,
1361,
8,
11577,
1284,
628,
298,
3171,
272,
283,
1361,
4331,
88,
12,
2263,
7,
1901,
283,
1361,
8,
11577,
570,
29,
88,
3171,
199,
199,
1944,
4493,
787,
6781,
340,
870,
63,
1593,
365,
8439,
687,
636,
2443,
363,
199,
199,
624,
199,
199,
3,
10111,
8925,
199,
504,
2508,
492,
12713,
863,
199,
504,
2508,
492,
23353,
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,
5429,
391,
12,
2624,
12,
365,
63,
2960,
421,
199,
9575,
68,
63,
3684,
275,
12713,
863,
14,
2014,
63,
3401,
8,
1598,
408,
4188,
28,
16746,
359,
4188,
92,
5353,
92,
2339,
61,
16107,
690,
624,
1598,
776,
421,
199,
533,
14811,
5375,
8,
25973,
63,
1095,
14,
1563,
11985,
304,
339,
699,
45,
63,
6490,
275,
715,
339,
31467,
7689,
275,
408,
1598,
3486,
63,
9649,
28,
1263,
10,
18753,
534,
1361,
7,
1263,
10,
690,
1204,
870,
63,
9649,
1598,
408,
339,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
267,
702,
2058,
398,
18753,
63,
1361,
275,
2058,
14,
362,
480,
14890,
531,
398,
340,
18753,
63,
1361,
26,
288,
327,
12568,
13,
2546,
870,
1006,
701,
6337,
288,
18753,
63,
1361,
14,
1814,
8,
2176,
8,
985,
8,
85,
2,
1361,
1288,
990,
3044,
2403,
29,
14890,
63,
1361,
14,
1861,
430,
288,
372,
267,
702,
1031,
14,
3223,
59,
16,
61,
508,
2812,
8,
85,
2,
1361,
531,
267,
1249,
275,
1031,
14,
3223,
59,
17,
2938,
267,
340,
822,
8,
589,
9,
508,
413,
436,
13566,
68,
63,
3684,
14,
1431,
8,
589,
59,
16,
4682,
288,
327,
2136,
2793,
1133,
2934,
370,
4215,
29404,
316,
32029,
6818,
376,
288,
327,
2575,
13,
9575,
1589,
338,
939,
3965,
14,
288,
372,
398,
7375,
275,
1284,
275,
570,
275,
488,
267,
340,
1249,
436,
1249,
1988,
17,
61,
508,
5429,
391,
837,
288,
1249,
275,
1249,
4439,
17,
61,
288,
1284,
275,
298,
298,
267,
340,
1249,
436,
1249,
59,
16,
61,
508,
23353,
14,
20475,
8,
1418,
14,
12811,
18013,
12,
399,
2,
1140,
2349,
288,
702,
822,
8,
589,
9,
2356,
499,
288,
570,
275,
1249,
59,
17,
1055,
6311,
342,
288,
1249,
275,
1249,
59,
19,
2938,
327,
19828,
282,
3962,
10029,
2410,
314,
570,
3965,
267,
327,
7356,
9560,
1589,
890,
282,
870,
8,
589,
12,
7375,
29,
11577,
1284,
29,
11577,
570,
29,
11965,
1031,
14,
267,
634,
63,
589,
275,
359,
1273,
14,
6311,
342,
367,
1680,
315,
1249,
61,
267,
340,
634,
63,
589,
26,
288,
634,
63,
589,
59,
16,
1055,
1861,
275,
399,
341,
267,
340,
7375,
365,
440,
488,
503,
1284,
365,
440,
488,
503,
570,
365,
440,
488,
26,
288,
340,
7375,
365,
440,
488,
26,
355,
291,
14,
525,
63,
12745,
8,
76,
63,
589,
12,
399,
2,
4127,
401,
2624,
8,
2722,
8,
4127,
1724,
288,
340,
1284,
365,
440,
488,
26,
355,
291,
14,
525,
63,
12745,
8,
76,
63,
589,
12,
399,
2,
500,
401,
2624,
8,
2722,
8,
500,
1724,
288,
340,
570,
365,
440,
488,
26,
355,
291,
14,
525,
63,
12745,
8,
76,
63,
589,
12,
399,
2,
493,
401,
570,
9,
267,
302,
63,
9649,
275,
6523,
8,
985,
8,
85,
2,
1361,
1288,
634,
63,
589,
9,
267,
302,
63,
9649,
14,
1861,
275,
1031,
14,
1861,
267,
372,
302,
63,
9649,
339,
347,
1050,
63,
12745,
8,
277,
12,
634,
63,
2415,
12,
308,
63,
829,
68,
12,
302,
63,
3684,
304,
267,
327,
5787,
2900,
642,
2403,
13,
6031,
1443,
27332,
6786,
334,
15401,
24063,
590,
9,
267,
302,
63,
3684,
14,
1861,
275,
399,
341,
267,
302,
63,
2094,
275,
23353,
14,
1716,
8,
277,
14,
13807,
14,
2094,
12,
639,
334,
985,
8,
83,
63,
829,
68,
395,
3303,
23353,
14,
20475,
8,
1418,
14,
16352,
12,
399,
2,
628,
395,
3303,
302,
63,
3684,
430,
267,
340,
634,
63,
2415,
26,
288,
634,
63,
2415,
14,
740,
8,
25732,
1012,
288,
302,
63,
2094,
14,
1861,
275,
399,
2,
298,
267,
634,
63,
2415,
14,
740,
8,
78,
63,
2094,
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
] |
[
1898,
8315,
4475,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
11985,
281,
367,
870,
14,
199,
199,
4001,
26,
272,
283,
1361,
7,
3515,
1901,
283,
1361,
11716,
272,
283,
1361,
2263,
7,
420,
1901,
283,
1361,
29195,
3171,
272,
283,
1361,
2263,
20606,
259,
1901,
283,
1361,
8,
11577,
1284,
628,
298,
3171,
272,
283,
1361,
4331,
88,
12,
2263,
7,
1901,
283,
1361,
8,
11577,
570,
29,
88,
3171,
199,
199,
1944,
4493,
787,
6781,
340,
870,
63,
1593,
365,
8439,
687,
636,
2443,
363,
199,
199,
624,
199,
199,
3,
10111,
8925,
199,
504,
2508,
492,
12713,
863,
199,
504,
2508,
492,
23353,
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,
5429,
391,
12,
2624,
12,
365,
63,
2960,
421,
199,
9575,
68,
63,
3684,
275,
12713,
863,
14,
2014,
63,
3401,
8,
1598,
408,
4188,
28,
16746,
359,
4188,
92,
5353,
92,
2339,
61,
16107,
690,
624,
1598,
776,
421,
199,
533,
14811,
5375,
8,
25973,
63,
1095,
14,
1563,
11985,
304,
339,
699,
45,
63,
6490,
275,
715,
339,
31467,
7689,
275,
408,
1598,
3486,
63,
9649,
28,
1263,
10,
18753,
534,
1361,
7,
1263,
10,
690,
1204,
870,
63,
9649,
1598,
408,
339,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
267,
702,
2058,
398,
18753,
63,
1361,
275,
2058,
14,
362,
480,
14890,
531,
398,
340,
18753,
63,
1361,
26,
288,
327,
12568,
13,
2546,
870,
1006,
701,
6337,
288,
18753,
63,
1361,
14,
1814,
8,
2176,
8,
985,
8,
85,
2,
1361,
1288,
990,
3044,
2403,
29,
14890,
63,
1361,
14,
1861,
430,
288,
372,
267,
702,
1031,
14,
3223,
59,
16,
61,
508,
2812,
8,
85,
2,
1361,
531,
267,
1249,
275,
1031,
14,
3223,
59,
17,
2938,
267,
340,
822,
8,
589,
9,
508,
413,
436,
13566,
68,
63,
3684,
14,
1431,
8,
589,
59,
16,
4682,
288,
327,
2136,
2793,
1133,
2934,
370,
4215,
29404,
316,
32029,
6818,
376,
288,
327,
2575,
13,
9575,
1589,
338,
939,
3965,
14,
288,
372,
398,
7375,
275,
1284,
275,
570,
275,
488,
267,
340,
1249,
436,
1249,
1988,
17,
61,
508,
5429,
391,
837,
288,
1249,
275,
1249,
4439,
17,
61,
288,
1284,
275,
298,
298,
267,
340,
1249,
436,
1249,
59,
16,
61,
508,
23353,
14,
20475,
8,
1418,
14,
12811,
18013,
12,
399,
2,
1140,
2349,
288,
702,
822,
8,
589,
9,
2356,
499,
288,
570,
275,
1249,
59,
17,
1055,
6311,
342,
288,
1249,
275,
1249,
59,
19,
2938,
327,
19828,
282,
3962,
10029,
2410,
314,
570,
3965,
267,
327,
7356,
9560,
1589,
890,
282,
870,
8,
589,
12,
7375,
29,
11577,
1284,
29,
11577,
570,
29,
11965,
1031,
14,
267,
634,
63,
589,
275,
359,
1273,
14,
6311,
342,
367,
1680,
315,
1249,
61,
267,
340,
634,
63,
589,
26,
288,
634,
63,
589,
59,
16,
1055,
1861,
275,
399,
341,
267,
340,
7375,
365,
440,
488,
503,
1284,
365,
440,
488,
503,
570,
365,
440,
488,
26,
288,
340,
7375,
365,
440,
488,
26,
355,
291,
14,
525,
63,
12745,
8,
76,
63,
589,
12,
399,
2,
4127,
401,
2624,
8,
2722,
8,
4127,
1724,
288,
340,
1284,
365,
440,
488,
26,
355,
291,
14,
525,
63,
12745,
8,
76,
63,
589,
12,
399,
2,
500,
401,
2624,
8,
2722,
8,
500,
1724,
288,
340,
570,
365,
440,
488,
26,
355,
291,
14,
525,
63,
12745,
8,
76,
63,
589,
12,
399,
2,
493,
401,
570,
9,
267,
302,
63,
9649,
275,
6523,
8,
985,
8,
85,
2,
1361,
1288,
634,
63,
589,
9,
267,
302,
63,
9649,
14,
1861,
275,
1031,
14,
1861,
267,
372,
302,
63,
9649,
339,
347,
1050,
63,
12745,
8,
277,
12,
634,
63,
2415,
12,
308,
63,
829,
68,
12,
302,
63,
3684,
304,
267,
327,
5787,
2900,
642,
2403,
13,
6031,
1443,
27332,
6786,
334,
15401,
24063,
590,
9,
267,
302,
63,
3684,
14,
1861,
275,
399,
341,
267,
302,
63,
2094,
275,
23353,
14,
1716,
8,
277,
14,
13807,
14,
2094,
12,
639,
334,
985,
8,
83,
63,
829,
68,
395,
3303,
23353,
14,
20475,
8,
1418,
14,
16352,
12,
399,
2,
628,
395,
3303,
302,
63,
3684,
430,
267,
340,
634,
63,
2415,
26,
288,
634,
63,
2415,
14,
740,
8,
25732,
1012,
288,
302,
63,
2094,
14,
1861,
275,
399,
2,
298,
267,
634,
63,
2415,
14,
740,
8,
78,
63,
2094,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jfantom/incubator-airflow
|
airflow/utils/decorators.py
|
66
|
3194
|
# -*- coding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
# inspect.signature is only available in Python 3. funcsigs.signature is
# a backport.
try:
import inspect
signature = inspect.signature
except AttributeError:
import funcsigs
signature = funcsigs.signature
from copy import copy
from functools import wraps
from airflow.exceptions import AirflowException
def apply_defaults(func):
"""
Function decorator that Looks for an argument named "default_args", and
fills the unspecified arguments from it.
Since python2.* isn't clear about which arguments are missing when
calling a function, and that this can be quite confusing with multi-level
inheritance and argument defaults, this decorator also alerts with
specific information about the missing arguments.
"""
@wraps(func)
def wrapper(*args, **kwargs):
if len(args) > 1:
raise AirflowException(
"Use keyword arguments when initializing operators")
dag_args = {}
dag_params = {}
import airflow.models
if kwargs.get('dag', None) or airflow.models._CONTEXT_MANAGER_DAG:
dag = kwargs.get('dag', None) or airflow.models._CONTEXT_MANAGER_DAG
dag_args = copy(dag.default_args) or {}
dag_params = copy(dag.params) or {}
params = {}
if 'params' in kwargs:
params = kwargs['params']
dag_params.update(params)
default_args = {}
if 'default_args' in kwargs:
default_args = kwargs['default_args']
if 'params' in default_args:
dag_params.update(default_args['params'])
del default_args['params']
dag_args.update(default_args)
default_args = dag_args
sig = signature(func)
non_optional_args = [
name for (name, param) in sig.parameters.items()
if param.default == param.empty and
param.name != 'self' and
param.kind not in (param.VAR_POSITIONAL, param.VAR_KEYWORD)]
for arg in sig.parameters:
if arg in default_args and arg not in kwargs:
kwargs[arg] = default_args[arg]
missing_args = list(set(non_optional_args) - set(kwargs))
if missing_args:
msg = "Argument {0} is required".format(missing_args)
raise AirflowException(msg)
kwargs['params'] = dag_params
result = func(*args, **kwargs)
return result
return wrapper
if 'BUILDING_AIRFLOW_DOCS' in os.environ:
# Monkey patch hook to get good function headers while building docs
apply_defaults = lambda x: x
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
646,
747,
199,
199,
3,
6485,
14,
5233,
365,
1454,
2808,
315,
2018,
650,
14,
2562,
25093,
14,
5233,
365,
199,
3,
282,
1771,
719,
14,
199,
893,
26,
272,
492,
6485,
272,
4955,
275,
6485,
14,
5233,
199,
2590,
4281,
26,
272,
492,
2562,
25093,
272,
4955,
275,
2562,
25093,
14,
5233,
199,
199,
504,
1331,
492,
1331,
199,
504,
9143,
492,
14018,
199,
199,
504,
16321,
14,
3924,
492,
31040,
1726,
421,
199,
318,
4838,
63,
4322,
8,
1532,
304,
272,
408,
272,
6801,
7531,
626,
12077,
83,
367,
376,
1423,
4310,
298,
885,
63,
589,
401,
436,
272,
1794,
478,
314,
21994,
2368,
687,
652,
14,
339,
9336,
2366,
18,
2795,
5712,
1133,
5436,
3595,
1314,
2368,
787,
4124,
1380,
272,
6358,
282,
805,
12,
436,
626,
642,
883,
506,
18794,
3743,
4941,
543,
3510,
13,
1896,
272,
15433,
436,
1423,
4243,
12,
642,
7531,
2597,
31529,
543,
272,
2488,
2556,
3595,
314,
4124,
2368,
14,
272,
408,
272,
768,
13582,
8,
1532,
9,
272,
347,
4975,
2031,
589,
12,
1011,
958,
304,
267,
340,
822,
8,
589,
9,
690,
413,
26,
288,
746,
31040,
1726,
8,
355,
298,
6119,
4252,
2368,
1380,
29141,
10211,
531,
267,
10158,
63,
589,
275,
1052,
267,
10158,
63,
1162,
275,
1052,
267,
492,
16321,
14,
992,
267,
340,
2074,
14,
362,
360,
7406,
297,
488,
9,
503,
16321,
14,
992,
423,
9059,
63,
28541,
63,
28211,
26,
288,
10158,
275,
2074,
14,
362,
360,
7406,
297,
488,
9,
503,
16321,
14,
992,
423,
9059,
63,
28541,
63,
28211,
288,
10158,
63,
589,
275,
1331,
8,
7406,
14,
885,
63,
589,
9,
503,
1052,
288,
10158,
63,
1162,
275,
1331,
8,
7406,
14,
1162,
9,
503,
1052,
398,
1862,
275,
1052,
267,
340,
283,
1162,
7,
315,
2074,
26,
288,
1862,
275,
2074,
459,
1162,
418,
267,
10158,
63,
1162,
14,
873,
8,
1162,
9,
398,
849,
63,
589,
275,
1052,
267,
340,
283,
885,
63,
589,
7,
315,
2074,
26,
288,
849,
63,
589,
275,
2074,
459,
885,
63,
589,
418,
288,
340,
283,
1162,
7,
315,
849,
63,
589,
26,
355,
10158,
63,
1162,
14,
873,
8,
885,
63,
589,
459,
1162,
1105,
355,
2150,
849,
63,
589,
459,
1162,
418,
398,
10158,
63,
589,
14,
873,
8,
885,
63,
589,
9,
267,
849,
63,
589,
275,
10158,
63,
589,
398,
5259,
275,
4955,
8,
1532,
9,
267,
2222,
63,
4144,
63,
589,
275,
359,
288,
536,
367,
334,
354,
12,
1215,
9,
315,
5259,
14,
3214,
14,
1744,
342,
288,
340,
1215,
14,
885,
508,
1215,
14,
1667,
436,
288,
1215,
14,
354,
1137,
283,
277,
7,
436,
288,
1215,
14,
5091,
440,
315,
334,
635,
14,
5568,
63,
31175,
12,
1215,
14,
5568,
63,
17714,
1874,
267,
367,
1680,
315,
5259,
14,
3214,
26,
288,
340,
1680,
315,
849,
63,
589,
436,
1680,
440,
315,
2074,
26,
355,
2074,
59,
1273,
61,
275,
849,
63,
589,
59,
1273,
61,
267,
4124,
63,
589,
275,
769,
8,
409,
8,
2865,
63,
4144,
63,
589,
9,
446,
663,
8,
958,
430,
267,
340,
4124,
63,
589,
26,
288,
1499,
275,
298,
5201,
469,
16,
93,
365,
1415,
1674,
908,
8,
4752,
63,
589,
9,
288,
746,
31040,
1726,
8,
1328,
9,
398,
2074,
459,
1162,
418,
275,
10158,
63,
1162,
398,
754,
275,
2562,
2031,
589,
12,
1011,
958,
9,
267,
372,
754,
272,
372,
4975,
199,
199,
692,
283,
8248,
1206,
63,
33,
3927,
17114,
63,
30072,
7,
315,
747,
14,
2314,
26,
272,
327,
10953,
498,
3371,
5759,
370,
664,
6954,
805,
2323,
1830,
10015,
9149,
272,
4838,
63,
4322,
275,
2400,
671,
26,
671,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
646,
747,
199,
199,
3,
6485,
14,
5233,
365,
1454,
2808,
315,
2018,
650,
14,
2562,
25093,
14,
5233,
365,
199,
3,
282,
1771,
719,
14,
199,
893,
26,
272,
492,
6485,
272,
4955,
275,
6485,
14,
5233,
199,
2590,
4281,
26,
272,
492,
2562,
25093,
272,
4955,
275,
2562,
25093,
14,
5233,
199,
199,
504,
1331,
492,
1331,
199,
504,
9143,
492,
14018,
199,
199,
504,
16321,
14,
3924,
492,
31040,
1726,
421,
199,
318,
4838,
63,
4322,
8,
1532,
304,
272,
408,
272,
6801,
7531,
626,
12077,
83,
367,
376,
1423,
4310,
298,
885,
63,
589,
401,
436,
272,
1794,
478,
314,
21994,
2368,
687,
652,
14,
339,
9336,
2366,
18,
2795,
5712,
1133,
5436,
3595,
1314,
2368,
787,
4124,
1380,
272,
6358,
282,
805,
12,
436,
626,
642,
883,
506,
18794,
3743,
4941,
543,
3510,
13,
1896,
272,
15433,
436,
1423,
4243,
12,
642,
7531,
2597,
31529,
543,
272,
2488,
2556,
3595,
314,
4124,
2368,
14,
272,
408,
272,
768,
13582,
8,
1532,
9,
272,
347,
4975,
2031,
589,
12,
1011,
958,
304,
267,
340,
822,
8,
589,
9,
690,
413,
26,
288,
746,
31040,
1726,
8,
355,
298,
6119,
4252,
2368,
1380,
29141,
10211,
531,
267,
10158,
63,
589,
275,
1052,
267,
10158,
63,
1162,
275,
1052,
267,
492,
16321,
14,
992,
267,
340,
2074,
14,
362,
360,
7406,
297,
488,
9,
503,
16321,
14,
992,
423,
9059,
63,
28541,
63,
28211,
26,
288,
10158,
275,
2074,
14,
362,
360,
7406,
297,
488,
9,
503,
16321,
14,
992,
423,
9059,
63,
28541,
63,
28211,
288,
10158,
63,
589,
275,
1331,
8,
7406,
14,
885,
63,
589,
9,
503,
1052,
288,
10158,
63,
1162,
275,
1331,
8,
7406,
14,
1162,
9,
503,
1052,
398,
1862,
275,
1052,
267,
340,
283,
1162,
7,
315,
2074,
26,
288,
1862,
275,
2074,
459,
1162,
418,
267,
10158,
63,
1162,
14,
873,
8,
1162,
9,
398,
849,
63,
589,
275,
1052,
267,
340,
283,
885,
63,
589,
7,
315,
2074,
26,
288,
849,
63,
589,
275,
2074,
459,
885,
63,
589,
418,
288,
340,
283,
1162,
7,
315,
849,
63,
589,
26,
355,
10158,
63,
1162,
14,
873,
8,
885,
63,
589,
459,
1162,
1105,
355,
2150,
849,
63,
589,
459,
1162,
418,
398,
10158,
63,
589,
14,
873,
8,
885,
63,
589,
9,
267,
849,
63,
589,
275,
10158,
63,
589,
398,
5259,
275,
4955,
8,
1532,
9,
267,
2222,
63,
4144,
63,
589,
275,
359,
288,
536,
367,
334,
354,
12,
1215,
9,
315,
5259,
14,
3214,
14,
1744,
342,
288,
340,
1215,
14,
885,
508,
1215,
14,
1667,
436,
288,
1215,
14,
354,
1137,
283,
277,
7,
436,
288,
1215,
14,
5091,
440,
315,
334,
635,
14,
5568,
63,
31175,
12,
1215,
14,
5568,
63,
17714,
1874,
267,
367,
1680,
315,
5259,
14,
3214,
26,
288,
340,
1680,
315,
849,
63,
589,
436,
1680,
440,
315,
2074,
26,
355,
2074,
59,
1273,
61,
275,
849,
63,
589,
59,
1273,
61,
267,
4124,
63,
589,
275,
769,
8,
409,
8,
2865,
63,
4144,
63,
589,
9,
446,
663,
8,
958,
430,
267,
340,
4124,
63,
589,
26,
288,
1499,
275,
298,
5201,
469,
16,
93,
365,
1415,
1674,
908,
8,
4752,
63,
589,
9,
288,
746,
31040,
1726,
8,
1328,
9,
398,
2074,
459,
1162,
418,
275,
10158,
63,
1162,
398,
754,
275,
2562,
2031,
589,
12,
1011,
958,
9,
267,
372,
754,
272,
372,
4975,
199,
199,
692,
283,
8248,
1206,
63,
33,
3927,
17114,
63,
30072,
7,
315,
747,
14,
2314,
26,
272,
327,
10953,
498,
3371,
5759,
370,
664,
6954,
805,
2323,
1830,
10015,
9149,
272,
4838,
63,
4322,
275,
2400,
671,
26,
671,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
barseghyanartur/django-extensions
|
tests/test_clean_pyc.py
|
12
|
2392
|
import fnmatch
import os
import shutil
import six
from django.core.management import call_command
from django.test import TestCase
from django_extensions.management.utils import get_project_root
class CleanPycTests(TestCase):
def setUp(self):
self._settings = os.environ.get('DJANGO_SETTINGS_MODULE')
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_extensions.settings'
def tearDown(self):
if self._settings:
os.environ['DJANGO_SETTINGS_MODULE'] = self._settings
def _find_pyc(self, path):
pyc_glob = []
for root, dirnames, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, '*.pyc'):
pyc_glob.append(os.path.join(root, filename))
return pyc_glob
def test_removes_pyc_files(self):
with self.settings(BASE_DIR=get_project_root()):
call_command('compile_pyc')
pyc_glob = self._find_pyc(get_project_root())
self.assertTrue(len(pyc_glob) > 0)
with self.settings(BASE_DIR=get_project_root()):
call_command('clean_pyc')
pyc_glob = self._find_pyc(get_project_root())
self.assertEqual(len(pyc_glob), 0)
def test_takes_path(self):
out = six.StringIO()
project_root = os.path.join('tests', 'testapp')
call_command('compile_pyc', path=project_root)
pyc_glob = self._find_pyc(project_root)
self.assertTrue(len(pyc_glob) > 0)
call_command('clean_pyc', verbosity=2, path=project_root, stdout=out)
output = out.getvalue().splitlines()
self.assertEqual(sorted(pyc_glob), sorted(output))
def test_removes_pyo_files(self):
out = six.StringIO()
project_root = os.path.join('tests', 'testapp')
call_command('compile_pyc', path=project_root)
pyc_glob = self._find_pyc(project_root)
self.assertTrue(len(pyc_glob) > 0)
# Create some fake .pyo files since we can't force them to be created.
pyo_glob = []
for fn in pyc_glob:
pyo = '%s.pyo' % os.path.splitext(fn)[0]
shutil.copyfile(fn, pyo)
pyo_glob.append(pyo)
call_command('clean_pyc', verbosity=2, path=project_root,
optimize=True, stdout=out)
output = out.getvalue().splitlines()
self.assertEqual(sorted(pyc_glob + pyo_glob), sorted(output))
|
mit
|
[
646,
15951,
199,
646,
747,
199,
646,
5145,
199,
199,
646,
3816,
199,
504,
1639,
14,
1018,
14,
8110,
492,
1240,
63,
1531,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1639,
63,
5359,
14,
8110,
14,
1208,
492,
664,
63,
1715,
63,
1231,
421,
199,
533,
12762,
2713,
67,
2925,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
423,
1751,
275,
747,
14,
2314,
14,
362,
360,
22848,
63,
13931,
63,
10001,
358,
267,
747,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
418,
275,
283,
1176,
63,
5359,
14,
1751,
7,
339,
347,
6766,
8,
277,
304,
267,
340,
291,
423,
1751,
26,
288,
747,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
418,
275,
291,
423,
1751,
339,
347,
485,
1623,
63,
11357,
8,
277,
12,
931,
304,
267,
28968,
63,
6463,
275,
942,
267,
367,
1738,
12,
22310,
12,
6203,
315,
747,
14,
7757,
8,
515,
304,
288,
367,
1788,
315,
15951,
14,
1541,
8,
10309,
12,
11937,
11357,
735,
355,
28968,
63,
6463,
14,
740,
8,
736,
14,
515,
14,
904,
8,
1231,
12,
1788,
430,
267,
372,
28968,
63,
6463,
339,
347,
511,
63,
264,
4912,
63,
11357,
63,
1725,
8,
277,
304,
267,
543,
291,
14,
1751,
8,
5825,
63,
3022,
29,
362,
63,
1715,
63,
1231,
5109,
288,
1240,
63,
1531,
360,
2014,
63,
11357,
358,
267,
28968,
63,
6463,
275,
291,
423,
1623,
63,
11357,
8,
362,
63,
1715,
63,
1231,
1012,
267,
291,
14,
1815,
8,
552,
8,
11357,
63,
6463,
9,
690,
378,
9,
267,
543,
291,
14,
1751,
8,
5825,
63,
3022,
29,
362,
63,
1715,
63,
1231,
5109,
288,
1240,
63,
1531,
360,
3118,
63,
11357,
358,
267,
28968,
63,
6463,
275,
291,
423,
1623,
63,
11357,
8,
362,
63,
1715,
63,
1231,
1012,
267,
291,
14,
629,
8,
552,
8,
11357,
63,
6463,
395,
378,
9,
339,
347,
511,
63,
31613,
63,
515,
8,
277,
304,
267,
734,
275,
3816,
14,
6424,
342,
267,
2199,
63,
1231,
275,
747,
14,
515,
14,
904,
360,
2219,
297,
283,
19700,
358,
267,
1240,
63,
1531,
360,
2014,
63,
11357,
297,
931,
29,
1715,
63,
1231,
9,
267,
28968,
63,
6463,
275,
291,
423,
1623,
63,
11357,
8,
1715,
63,
1231,
9,
267,
291,
14,
1815,
8,
552,
8,
11357,
63,
6463,
9,
690,
378,
9,
267,
1240,
63,
1531,
360,
3118,
63,
11357,
297,
8661,
29,
18,
12,
931,
29,
1715,
63,
1231,
12,
3839,
29,
548,
9,
267,
1072,
275,
734,
14,
7150,
1252,
7644,
342,
267,
291,
14,
629,
8,
5917,
8,
11357,
63,
6463,
395,
3355,
8,
1199,
430,
339,
347,
511,
63,
264,
4912,
63,
22345,
63,
1725,
8,
277,
304,
267,
734,
275,
3816,
14,
6424,
342,
267,
2199,
63,
1231,
275,
747,
14,
515,
14,
904,
360,
2219,
297,
283,
19700,
358,
267,
1240,
63,
1531,
360,
2014,
63,
11357,
297,
931,
29,
1715,
63,
1231,
9,
267,
28968,
63,
6463,
275,
291,
423,
1623,
63,
11357,
8,
1715,
63,
1231,
9,
267,
291,
14,
1815,
8,
552,
8,
11357,
63,
6463,
9,
690,
378,
9,
267,
327,
2790,
2005,
4026,
1275,
22345,
1584,
3967,
781,
883,
1133,
3542,
3062,
370,
506,
2737,
14,
267,
1134,
79,
63,
6463,
275,
942,
267,
367,
4325,
315,
28968,
63,
6463,
26,
288,
1134,
79,
275,
1543,
83,
14,
22345,
7,
450,
747,
14,
515,
14,
7973,
8,
2324,
2788,
16,
61,
288,
5145,
14,
21997,
8,
2324,
12,
1134,
79,
9,
288,
1134,
79,
63,
6463,
14,
740,
8,
22345,
9,
267,
1240,
63,
1531,
360,
3118,
63,
11357,
297,
8661,
29,
18,
12,
931,
29,
1715,
63,
1231,
12,
2151,
13497,
29,
549,
12,
3839,
29,
548,
9,
267,
1072,
275,
734,
14,
7150,
1252,
7644,
342,
267,
291,
14,
629,
8,
5917,
8,
11357,
63,
6463,
435,
1134,
79,
63,
6463,
395,
3355,
8,
1199,
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
] |
[
15951,
199,
646,
747,
199,
646,
5145,
199,
199,
646,
3816,
199,
504,
1639,
14,
1018,
14,
8110,
492,
1240,
63,
1531,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1639,
63,
5359,
14,
8110,
14,
1208,
492,
664,
63,
1715,
63,
1231,
421,
199,
533,
12762,
2713,
67,
2925,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
423,
1751,
275,
747,
14,
2314,
14,
362,
360,
22848,
63,
13931,
63,
10001,
358,
267,
747,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
418,
275,
283,
1176,
63,
5359,
14,
1751,
7,
339,
347,
6766,
8,
277,
304,
267,
340,
291,
423,
1751,
26,
288,
747,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
418,
275,
291,
423,
1751,
339,
347,
485,
1623,
63,
11357,
8,
277,
12,
931,
304,
267,
28968,
63,
6463,
275,
942,
267,
367,
1738,
12,
22310,
12,
6203,
315,
747,
14,
7757,
8,
515,
304,
288,
367,
1788,
315,
15951,
14,
1541,
8,
10309,
12,
11937,
11357,
735,
355,
28968,
63,
6463,
14,
740,
8,
736,
14,
515,
14,
904,
8,
1231,
12,
1788,
430,
267,
372,
28968,
63,
6463,
339,
347,
511,
63,
264,
4912,
63,
11357,
63,
1725,
8,
277,
304,
267,
543,
291,
14,
1751,
8,
5825,
63,
3022,
29,
362,
63,
1715,
63,
1231,
5109,
288,
1240,
63,
1531,
360,
2014,
63,
11357,
358,
267,
28968,
63,
6463,
275,
291,
423,
1623,
63,
11357,
8,
362,
63,
1715,
63,
1231,
1012,
267,
291,
14,
1815,
8,
552,
8,
11357,
63,
6463,
9,
690,
378,
9,
267,
543,
291,
14,
1751,
8,
5825,
63,
3022,
29,
362,
63,
1715,
63,
1231,
5109,
288,
1240,
63,
1531,
360,
3118,
63,
11357,
358,
267,
28968,
63,
6463,
275,
291,
423,
1623,
63,
11357,
8,
362,
63,
1715,
63,
1231,
1012,
267,
291,
14,
629,
8,
552,
8,
11357,
63,
6463,
395,
378,
9,
339,
347,
511,
63,
31613,
63,
515,
8,
277,
304,
267,
734,
275,
3816,
14,
6424,
342,
267,
2199,
63,
1231,
275,
747,
14,
515,
14,
904,
360,
2219,
297,
283,
19700,
358,
267,
1240,
63,
1531,
360,
2014,
63,
11357,
297,
931,
29,
1715,
63,
1231,
9,
267,
28968,
63,
6463,
275,
291,
423,
1623,
63,
11357,
8,
1715,
63,
1231,
9,
267,
291,
14,
1815,
8,
552,
8,
11357,
63,
6463,
9,
690,
378,
9,
267,
1240,
63,
1531,
360,
3118,
63,
11357,
297,
8661,
29,
18,
12,
931,
29,
1715,
63,
1231,
12,
3839,
29,
548,
9,
267,
1072,
275,
734,
14,
7150,
1252,
7644,
342,
267,
291,
14,
629,
8,
5917,
8,
11357,
63,
6463,
395,
3355,
8,
1199,
430,
339,
347,
511,
63,
264,
4912,
63,
22345,
63,
1725,
8,
277,
304,
267,
734,
275,
3816,
14,
6424,
342,
267,
2199,
63,
1231,
275,
747,
14,
515,
14,
904,
360,
2219,
297,
283,
19700,
358,
267,
1240,
63,
1531,
360,
2014,
63,
11357,
297,
931,
29,
1715,
63,
1231,
9,
267,
28968,
63,
6463,
275,
291,
423,
1623,
63,
11357,
8,
1715,
63,
1231,
9,
267,
291,
14,
1815,
8,
552,
8,
11357,
63,
6463,
9,
690,
378,
9,
267,
327,
2790,
2005,
4026,
1275,
22345,
1584,
3967,
781,
883,
1133,
3542,
3062,
370,
506,
2737,
14,
267,
1134,
79,
63,
6463,
275,
942,
267,
367,
4325,
315,
28968,
63,
6463,
26,
288,
1134,
79,
275,
1543,
83,
14,
22345,
7,
450,
747,
14,
515,
14,
7973,
8,
2324,
2788,
16,
61,
288,
5145,
14,
21997,
8,
2324,
12,
1134,
79,
9,
288,
1134,
79,
63,
6463,
14,
740,
8,
22345,
9,
267,
1240,
63,
1531,
360,
3118,
63,
11357,
297,
8661,
29,
18,
12,
931,
29,
1715,
63,
1231,
12,
2151,
13497,
29,
549,
12,
3839,
29,
548,
9,
267,
1072,
275,
734,
14,
7150,
1252,
7644,
342,
267,
291,
14,
629,
8,
5917,
8,
11357,
63,
6463,
435,
1134,
79,
63,
6463,
395,
3355,
8,
1199,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
igemsoftware/SYSU-Software2013
|
project/Python27_32/Lib/test/test_marshal.py
|
29
|
10569
|
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
from test import test_support
import marshal
import sys
import unittest
import os
class IntTestCase(unittest.TestCase):
def test_ints(self):
# Test the full range of Python ints.
n = sys.maxint
while n:
for expected in (-n, n):
s = marshal.dumps(expected)
got = marshal.loads(s)
self.assertEqual(expected, got)
marshal.dump(expected, file(test_support.TESTFN, "wb"))
got = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(expected, got)
n = n >> 1
os.unlink(test_support.TESTFN)
def test_int64(self):
# Simulate int marshaling on a 64-bit box. This is most interesting if
# we're running the test on a 32-bit box, of course.
def to_little_endian_string(value, nbytes):
bytes = []
for i in range(nbytes):
bytes.append(chr(value & 0xff))
value >>= 8
return ''.join(bytes)
maxint64 = (1L << 63) - 1
minint64 = -maxint64-1
for base in maxint64, minint64, -maxint64, -(minint64 >> 1):
while base:
s = 'I' + to_little_endian_string(base, 8)
got = marshal.loads(s)
self.assertEqual(base, got)
if base == -1: # a fixed-point for shifting right 1
base = 0
else:
base >>= 1
def test_bool(self):
for b in (True, False):
new = marshal.loads(marshal.dumps(b))
self.assertEqual(b, new)
self.assertEqual(type(b), type(new))
marshal.dump(b, file(test_support.TESTFN, "wb"))
new = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(b, new)
self.assertEqual(type(b), type(new))
class FloatTestCase(unittest.TestCase):
def test_floats(self):
# Test a few floats
small = 1e-25
n = sys.maxint * 3.7e250
while n > small:
for expected in (-n, n):
f = float(expected)
s = marshal.dumps(f)
got = marshal.loads(s)
self.assertEqual(f, got)
marshal.dump(f, file(test_support.TESTFN, "wb"))
got = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(f, got)
n /= 123.4567
f = 0.0
s = marshal.dumps(f, 2)
got = marshal.loads(s)
self.assertEqual(f, got)
# and with version <= 1 (floats marshalled differently then)
s = marshal.dumps(f, 1)
got = marshal.loads(s)
self.assertEqual(f, got)
n = sys.maxint * 3.7e-250
while n < small:
for expected in (-n, n):
f = float(expected)
s = marshal.dumps(f)
got = marshal.loads(s)
self.assertEqual(f, got)
s = marshal.dumps(f, 1)
got = marshal.loads(s)
self.assertEqual(f, got)
marshal.dump(f, file(test_support.TESTFN, "wb"))
got = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(f, got)
marshal.dump(f, file(test_support.TESTFN, "wb"), 1)
got = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(f, got)
n *= 123.4567
os.unlink(test_support.TESTFN)
class StringTestCase(unittest.TestCase):
def test_unicode(self):
for s in [u"", u"Andrè Previn", u"abc", u" "*10000]:
new = marshal.loads(marshal.dumps(s))
self.assertEqual(s, new)
self.assertEqual(type(s), type(new))
marshal.dump(s, file(test_support.TESTFN, "wb"))
new = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(s, new)
self.assertEqual(type(s), type(new))
os.unlink(test_support.TESTFN)
def test_string(self):
for s in ["", "Andrè Previn", "abc", " "*10000]:
new = marshal.loads(marshal.dumps(s))
self.assertEqual(s, new)
self.assertEqual(type(s), type(new))
marshal.dump(s, file(test_support.TESTFN, "wb"))
new = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(s, new)
self.assertEqual(type(s), type(new))
os.unlink(test_support.TESTFN)
def test_buffer(self):
for s in ["", "Andrè Previn", "abc", " "*10000]:
with test_support.check_py3k_warnings(("buffer.. not supported",
DeprecationWarning)):
b = buffer(s)
new = marshal.loads(marshal.dumps(b))
self.assertEqual(s, new)
marshal.dump(b, file(test_support.TESTFN, "wb"))
new = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(s, new)
os.unlink(test_support.TESTFN)
class ExceptionTestCase(unittest.TestCase):
def test_exceptions(self):
new = marshal.loads(marshal.dumps(StopIteration))
self.assertEqual(StopIteration, new)
class CodeTestCase(unittest.TestCase):
def test_code(self):
co = ExceptionTestCase.test_exceptions.func_code
new = marshal.loads(marshal.dumps(co))
self.assertEqual(co, new)
class ContainerTestCase(unittest.TestCase):
d = {'astring': 'foo@bar.baz.spam',
'afloat': 7283.43,
'anint': 2**20,
'ashortlong': 2L,
'alist': ['.zyx.41'],
'atuple': ('.zyx.41',)*10,
'aboolean': False,
'aunicode': u"Andrè Previn"
}
def test_dict(self):
new = marshal.loads(marshal.dumps(self.d))
self.assertEqual(self.d, new)
marshal.dump(self.d, file(test_support.TESTFN, "wb"))
new = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(self.d, new)
os.unlink(test_support.TESTFN)
def test_list(self):
lst = self.d.items()
new = marshal.loads(marshal.dumps(lst))
self.assertEqual(lst, new)
marshal.dump(lst, file(test_support.TESTFN, "wb"))
new = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(lst, new)
os.unlink(test_support.TESTFN)
def test_tuple(self):
t = tuple(self.d.keys())
new = marshal.loads(marshal.dumps(t))
self.assertEqual(t, new)
marshal.dump(t, file(test_support.TESTFN, "wb"))
new = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(t, new)
os.unlink(test_support.TESTFN)
def test_sets(self):
for constructor in (set, frozenset):
t = constructor(self.d.keys())
new = marshal.loads(marshal.dumps(t))
self.assertEqual(t, new)
self.assertTrue(isinstance(new, constructor))
self.assertNotEqual(id(t), id(new))
marshal.dump(t, file(test_support.TESTFN, "wb"))
new = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(t, new)
os.unlink(test_support.TESTFN)
class BugsTestCase(unittest.TestCase):
def test_bug_5888452(self):
# Simple-minded check for SF 588452: Debug build crashes
marshal.dumps([128] * 1000)
def test_patch_873224(self):
self.assertRaises(Exception, marshal.loads, '0')
self.assertRaises(Exception, marshal.loads, 'f')
self.assertRaises(Exception, marshal.loads, marshal.dumps(5L)[:-1])
def test_version_argument(self):
# Python 2.4.0 crashes for any call to marshal.dumps(x, y)
self.assertEqual(marshal.loads(marshal.dumps(5, 0)), 5)
self.assertEqual(marshal.loads(marshal.dumps(5, 1)), 5)
def test_fuzz(self):
# simple test that it's at least not *totally* trivial to
# crash from bad marshal data
for c in [chr(i) for i in range(256)]:
try:
marshal.loads(c)
except Exception:
pass
def test_loads_recursion(self):
s = 'c' + ('X' * 4*4) + '{' * 2**20
self.assertRaises(ValueError, marshal.loads, s)
def test_recursion_limit(self):
# Create a deeply nested structure.
head = last = []
# The max stack depth should match the value in Python/marshal.c.
MAX_MARSHAL_STACK_DEPTH = 2000
for i in range(MAX_MARSHAL_STACK_DEPTH - 2):
last.append([0])
last = last[-1]
# Verify we don't blow out the stack with dumps/load.
data = marshal.dumps(head)
new_head = marshal.loads(data)
# Don't use == to compare objects, it can exceed the recursion limit.
self.assertEqual(len(new_head), len(head))
self.assertEqual(len(new_head[0]), len(head[0]))
self.assertEqual(len(new_head[-1]), len(head[-1]))
last.append([0])
self.assertRaises(ValueError, marshal.dumps, head)
def test_exact_type_match(self):
# Former bug:
# >>> class Int(int): pass
# >>> type(loads(dumps(Int())))
# <type 'int'>
for typ in (int, long, float, complex, tuple, list, dict, set, frozenset):
# Note: str and unicode subclasses are not tested because they get handled
# by marshal's routines for objects supporting the buffer API.
subtyp = type('subtyp', (typ,), {})
self.assertRaises(ValueError, marshal.dumps, subtyp())
# Issue #1792 introduced a change in how marshal increases the size of its
# internal buffer; this test ensures that the new code is exercised.
def test_large_marshal(self):
size = int(1e6)
testString = 'abc' * size
marshal.dumps(testString)
def test_invalid_longs(self):
# Issue #7019: marshal.loads shouldn't produce unnormalized PyLongs
invalid_string = 'l\x02\x00\x00\x00\x00\x00\x00\x00'
self.assertRaises(ValueError, marshal.loads, invalid_string)
def test_main():
test_support.run_unittest(IntTestCase,
FloatTestCase,
StringTestCase,
CodeTestCase,
ContainerTestCase,
ExceptionTestCase,
BugsTestCase)
if __name__ == "__main__":
test_main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
11601,
13,
4830,
13,
17,
1882,
199,
199,
504,
511,
492,
511,
63,
4058,
199,
646,
21985,
199,
646,
984,
199,
646,
2882,
199,
646,
747,
199,
199,
533,
9805,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
13141,
8,
277,
304,
267,
327,
1379,
314,
2615,
1425,
402,
2018,
14526,
14,
267,
302,
275,
984,
14,
21411,
267,
1830,
302,
26,
288,
367,
1420,
315,
5868,
78,
12,
302,
304,
355,
308,
275,
21985,
14,
4180,
8,
2062,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
2062,
12,
4788,
9,
355,
21985,
14,
2724,
8,
2062,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
355,
4788,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
355,
291,
14,
629,
8,
2062,
12,
4788,
9,
288,
302,
275,
302,
4331,
413,
267,
747,
14,
7162,
8,
396,
63,
4058,
14,
10179,
9,
339,
347,
511,
63,
442,
772,
8,
277,
304,
267,
327,
10751,
5434,
1109,
21985,
316,
641,
282,
5049,
13,
2075,
5689,
14,
221,
961,
365,
4750,
19604,
340,
267,
327,
781,
3984,
3879,
314,
511,
641,
282,
4337,
13,
2075,
5689,
12,
402,
2518,
14,
398,
347,
370,
63,
10182,
63,
15009,
63,
875,
8,
585,
12,
302,
2394,
304,
288,
2783,
275,
942,
288,
367,
284,
315,
1425,
8,
31417,
304,
355,
2783,
14,
740,
8,
10194,
8,
585,
1253,
378,
3581,
430,
355,
574,
4331,
29,
1695,
288,
372,
6522,
904,
8,
2394,
9,
398,
1390,
442,
772,
275,
334,
17,
44,
5213,
13668,
9,
446,
413,
267,
1748,
442,
772,
275,
446,
21411,
772,
13,
17,
398,
367,
1300,
315,
1390,
442,
772,
12,
1748,
442,
772,
12,
446,
21411,
772,
12,
24953,
827,
442,
772,
4331,
413,
304,
288,
1830,
1300,
26,
355,
308,
275,
283,
41,
7,
435,
370,
63,
10182,
63,
15009,
63,
875,
8,
1095,
12,
1695,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
1095,
12,
4788,
9,
355,
340,
1300,
508,
446,
17,
26,
221,
327,
282,
6317,
13,
1403,
367,
20863,
1337,
2451,
413,
490,
1300,
275,
378,
355,
587,
26,
490,
1300,
4331,
29,
413,
339,
347,
511,
63,
2245,
8,
277,
304,
267,
367,
330,
315,
334,
549,
12,
756,
304,
288,
892,
275,
21985,
14,
3640,
8,
18376,
14,
4180,
8,
66,
430,
288,
291,
14,
629,
8,
66,
12,
892,
9,
288,
291,
14,
629,
8,
466,
8,
66,
395,
730,
8,
1222,
430,
288,
21985,
14,
2724,
8,
66,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
288,
892,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
288,
291,
14,
629,
8,
66,
12,
892,
9,
288,
291,
14,
629,
8,
466,
8,
66,
395,
730,
8,
1222,
430,
199,
199,
533,
11140,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1609,
83,
8,
277,
304,
267,
327,
1379,
282,
9284,
15657,
267,
7425,
275,
413,
69,
13,
821,
267,
302,
275,
984,
14,
21411,
627,
650,
14,
23,
69,
7991,
267,
1830,
302,
690,
7425,
26,
288,
367,
1420,
315,
5868,
78,
12,
302,
304,
355,
289,
275,
2069,
8,
2062,
9,
355,
308,
275,
21985,
14,
4180,
8,
70,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
355,
21985,
14,
2724,
8,
70,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
355,
4788,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
288,
302,
12257,
11869,
14,
20,
5308,
398,
289,
275,
378,
14,
16,
267,
308,
275,
21985,
14,
4180,
8,
70,
12,
499,
9,
267,
4788,
275,
21985,
14,
3640,
8,
83,
9,
267,
291,
14,
629,
8,
70,
12,
4788,
9,
267,
327,
436,
543,
1015,
2695,
413,
334,
1609,
83,
7557,
609,
1843,
23142,
2066,
9,
267,
308,
275,
21985,
14,
4180,
8,
70,
12,
413,
9,
267,
4788,
275,
21985,
14,
3640,
8,
83,
9,
267,
291,
14,
629,
8,
70,
12,
4788,
9,
398,
302,
275,
984,
14,
21411,
627,
650,
14,
23,
69,
13,
7991,
267,
1830,
302,
665,
7425,
26,
288,
367,
1420,
315,
5868,
78,
12,
302,
304,
355,
289,
275,
2069,
8,
2062,
9,
2234,
308,
275,
21985,
14,
4180,
8,
70,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
2234,
308,
275,
21985,
14,
4180,
8,
70,
12,
413,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
2234,
21985,
14,
2724,
8,
70,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
355,
4788,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
2234,
21985,
14,
2724,
8,
70,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
1288,
413,
9,
355,
4788,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
288,
302,
9000,
11869,
14,
20,
5308,
267,
747,
14,
7162,
8,
396,
63,
4058,
14,
10179,
9,
199,
199,
533,
2624,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
2975,
8,
277,
304,
267,
367,
308,
315,
359,
85,
5151,
399,
2,
3325,
82,
18631,
510,
4964,
262,
401,
399,
2,
3175,
401,
399,
2,
8969,
9943,
2189,
288,
892,
275,
21985,
14,
3640,
8,
18376,
14,
4180,
8,
83,
430,
288,
291,
14,
629,
8,
83,
12,
892,
9,
288,
291,
14,
629,
8,
466,
8,
83,
395,
730,
8,
1222,
430,
288,
21985,
14,
2724,
8,
83,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
288,
892,
275,
21985
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
11601,
13,
4830,
13,
17,
1882,
199,
199,
504,
511,
492,
511,
63,
4058,
199,
646,
21985,
199,
646,
984,
199,
646,
2882,
199,
646,
747,
199,
199,
533,
9805,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
13141,
8,
277,
304,
267,
327,
1379,
314,
2615,
1425,
402,
2018,
14526,
14,
267,
302,
275,
984,
14,
21411,
267,
1830,
302,
26,
288,
367,
1420,
315,
5868,
78,
12,
302,
304,
355,
308,
275,
21985,
14,
4180,
8,
2062,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
2062,
12,
4788,
9,
355,
21985,
14,
2724,
8,
2062,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
355,
4788,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
355,
291,
14,
629,
8,
2062,
12,
4788,
9,
288,
302,
275,
302,
4331,
413,
267,
747,
14,
7162,
8,
396,
63,
4058,
14,
10179,
9,
339,
347,
511,
63,
442,
772,
8,
277,
304,
267,
327,
10751,
5434,
1109,
21985,
316,
641,
282,
5049,
13,
2075,
5689,
14,
221,
961,
365,
4750,
19604,
340,
267,
327,
781,
3984,
3879,
314,
511,
641,
282,
4337,
13,
2075,
5689,
12,
402,
2518,
14,
398,
347,
370,
63,
10182,
63,
15009,
63,
875,
8,
585,
12,
302,
2394,
304,
288,
2783,
275,
942,
288,
367,
284,
315,
1425,
8,
31417,
304,
355,
2783,
14,
740,
8,
10194,
8,
585,
1253,
378,
3581,
430,
355,
574,
4331,
29,
1695,
288,
372,
6522,
904,
8,
2394,
9,
398,
1390,
442,
772,
275,
334,
17,
44,
5213,
13668,
9,
446,
413,
267,
1748,
442,
772,
275,
446,
21411,
772,
13,
17,
398,
367,
1300,
315,
1390,
442,
772,
12,
1748,
442,
772,
12,
446,
21411,
772,
12,
24953,
827,
442,
772,
4331,
413,
304,
288,
1830,
1300,
26,
355,
308,
275,
283,
41,
7,
435,
370,
63,
10182,
63,
15009,
63,
875,
8,
1095,
12,
1695,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
1095,
12,
4788,
9,
355,
340,
1300,
508,
446,
17,
26,
221,
327,
282,
6317,
13,
1403,
367,
20863,
1337,
2451,
413,
490,
1300,
275,
378,
355,
587,
26,
490,
1300,
4331,
29,
413,
339,
347,
511,
63,
2245,
8,
277,
304,
267,
367,
330,
315,
334,
549,
12,
756,
304,
288,
892,
275,
21985,
14,
3640,
8,
18376,
14,
4180,
8,
66,
430,
288,
291,
14,
629,
8,
66,
12,
892,
9,
288,
291,
14,
629,
8,
466,
8,
66,
395,
730,
8,
1222,
430,
288,
21985,
14,
2724,
8,
66,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
288,
892,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
288,
291,
14,
629,
8,
66,
12,
892,
9,
288,
291,
14,
629,
8,
466,
8,
66,
395,
730,
8,
1222,
430,
199,
199,
533,
11140,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1609,
83,
8,
277,
304,
267,
327,
1379,
282,
9284,
15657,
267,
7425,
275,
413,
69,
13,
821,
267,
302,
275,
984,
14,
21411,
627,
650,
14,
23,
69,
7991,
267,
1830,
302,
690,
7425,
26,
288,
367,
1420,
315,
5868,
78,
12,
302,
304,
355,
289,
275,
2069,
8,
2062,
9,
355,
308,
275,
21985,
14,
4180,
8,
70,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
355,
21985,
14,
2724,
8,
70,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
355,
4788,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
288,
302,
12257,
11869,
14,
20,
5308,
398,
289,
275,
378,
14,
16,
267,
308,
275,
21985,
14,
4180,
8,
70,
12,
499,
9,
267,
4788,
275,
21985,
14,
3640,
8,
83,
9,
267,
291,
14,
629,
8,
70,
12,
4788,
9,
267,
327,
436,
543,
1015,
2695,
413,
334,
1609,
83,
7557,
609,
1843,
23142,
2066,
9,
267,
308,
275,
21985,
14,
4180,
8,
70,
12,
413,
9,
267,
4788,
275,
21985,
14,
3640,
8,
83,
9,
267,
291,
14,
629,
8,
70,
12,
4788,
9,
398,
302,
275,
984,
14,
21411,
627,
650,
14,
23,
69,
13,
7991,
267,
1830,
302,
665,
7425,
26,
288,
367,
1420,
315,
5868,
78,
12,
302,
304,
355,
289,
275,
2069,
8,
2062,
9,
2234,
308,
275,
21985,
14,
4180,
8,
70,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
2234,
308,
275,
21985,
14,
4180,
8,
70,
12,
413,
9,
355,
4788,
275,
21985,
14,
3640,
8,
83,
9,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
2234,
21985,
14,
2724,
8,
70,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
355,
4788,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
2234,
21985,
14,
2724,
8,
70,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
1288,
413,
9,
355,
4788,
275,
21985,
14,
912,
8,
493,
8,
396,
63,
4058,
14,
10179,
12,
298,
4848,
2237,
355,
291,
14,
629,
8,
70,
12,
4788,
9,
288,
302,
9000,
11869,
14,
20,
5308,
267,
747,
14,
7162,
8,
396,
63,
4058,
14,
10179,
9,
199,
199,
533,
2624,
1746,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
2975,
8,
277,
304,
267,
367,
308,
315,
359,
85,
5151,
399,
2,
3325,
82,
18631,
510,
4964,
262,
401,
399,
2,
3175,
401,
399,
2,
8969,
9943,
2189,
288,
892,
275,
21985,
14,
3640,
8,
18376,
14,
4180,
8,
83,
430,
288,
291,
14,
629,
8,
83,
12,
892,
9,
288,
291,
14,
629,
8,
466,
8,
83,
395,
730,
8,
1222,
430,
288,
21985,
14,
2724,
8,
83,
12,
570,
8,
396,
63,
4058,
14,
10179,
12,
298,
6603,
2237,
288,
892,
275,
21985,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jianghuaw/nova
|
nova/cells/scheduler.py
|
3
|
10939
|
# Copyright (c) 2012 Rackspace Hosting
# 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.
"""
Cells Scheduler
"""
import copy
import time
from oslo_log import log as logging
from six.moves import range
from nova.cells import filters
from nova.cells import weights
from nova import compute
from nova.compute import instance_actions
from nova.compute import vm_states
from nova import conductor
import nova.conf
from nova.db import base
from nova import exception
from nova import objects
from nova.objects import base as obj_base
from nova.scheduler import utils as scheduler_utils
from nova import utils
LOG = logging.getLogger(__name__)
CONF = nova.conf.CONF
class CellsScheduler(base.Base):
"""The cells scheduler."""
def __init__(self, msg_runner):
super(CellsScheduler, self).__init__()
self.msg_runner = msg_runner
self.state_manager = msg_runner.state_manager
self.compute_api = compute.API()
self.compute_task_api = conductor.ComputeTaskAPI()
self.filter_handler = filters.CellFilterHandler()
filter_classes = self.filter_handler.get_matching_classes(
CONF.cells.scheduler_filter_classes)
self.filters = [cls() for cls in filter_classes]
self.weight_handler = weights.CellWeightHandler()
weigher_classes = self.weight_handler.get_matching_classes(
CONF.cells.scheduler_weight_classes)
self.weighers = [cls() for cls in weigher_classes]
def _create_instances_here(self, ctxt, instance_uuids, instance_properties,
instance_type, image, security_groups, block_device_mapping):
instance_values = copy.copy(instance_properties)
# The parent may pass these metadata values as lists, and the
# create call expects it to be a dict.
instance_values['metadata'] = utils.instance_meta(instance_values)
# Pop out things that will get set properly when re-creating the
# instance record.
instance_values.pop('id')
instance_values.pop('name')
instance_values.pop('info_cache')
instance_values.pop('security_groups')
instance_values.pop('flavor')
# FIXME(danms): The instance was brutally serialized before being
# sent over RPC to us. Thus, the pci_requests value wasn't really
# sent in a useful form. Since it was getting ignored for cells
# before it was part of the Instance, skip it now until cells RPC
# is sending proper instance objects.
instance_values.pop('pci_requests', None)
# FIXME(danms): Same for ec2_ids
instance_values.pop('ec2_ids', None)
# FIXME(danms): Same for keypairs
instance_values.pop('keypairs', None)
instances = []
num_instances = len(instance_uuids)
security_groups = (
self.compute_api.security_group_api.populate_security_groups(
security_groups))
for i, instance_uuid in enumerate(instance_uuids):
instance = objects.Instance(context=ctxt)
instance.update(instance_values)
instance.uuid = instance_uuid
instance.flavor = instance_type
instance.old_flavor = None
instance.new_flavor = None
instance = self.compute_api.create_db_entry_for_new_instance(
ctxt,
instance_type,
image,
instance,
security_groups,
block_device_mapping,
num_instances, i)
block_device_mapping = (
self.compute_api._bdm_validate_set_size_and_instance(
ctxt, instance, instance_type, block_device_mapping))
self.compute_api._create_block_device_mapping(block_device_mapping)
instances.append(instance)
self.msg_runner.instance_update_at_top(ctxt, instance)
return instances
def _create_action_here(self, ctxt, instance_uuids):
for instance_uuid in instance_uuids:
objects.InstanceAction.action_start(
ctxt,
instance_uuid,
instance_actions.CREATE,
want_result=False)
def _get_possible_cells(self):
cells = self.state_manager.get_child_cells()
our_cell = self.state_manager.get_my_state()
# Include our cell in the list, if we have any capacity info
if not cells or our_cell.capacities:
cells.append(our_cell)
return cells
def _grab_target_cells(self, filter_properties):
cells = self._get_possible_cells()
cells = self.filter_handler.get_filtered_objects(self.filters, cells,
filter_properties)
# NOTE(comstud): I know this reads weird, but the 'if's are nested
# this way to optimize for the common case where 'cells' is a list
# containing at least 1 entry.
if not cells:
if cells is None:
# None means to bypass further scheduling as a filter
# took care of everything.
return
raise exception.NoCellsAvailable()
weighted_cells = self.weight_handler.get_weighed_objects(
self.weighers, cells, filter_properties)
LOG.debug("Weighted cells: %(weighted_cells)s",
{'weighted_cells': weighted_cells})
target_cells = [cell.obj for cell in weighted_cells]
return target_cells
def _build_instances(self, message, target_cells, instance_uuids,
build_inst_kwargs):
"""Attempt to build instance(s) or send msg to child cell."""
ctxt = message.ctxt
instance_properties = obj_base.obj_to_primitive(
build_inst_kwargs['instances'][0])
filter_properties = build_inst_kwargs['filter_properties']
instance_type = filter_properties['instance_type']
image = build_inst_kwargs['image']
security_groups = build_inst_kwargs['security_groups']
block_device_mapping = build_inst_kwargs['block_device_mapping']
LOG.debug("Building instances with routing_path=%(routing_path)s",
{'routing_path': message.routing_path})
for target_cell in target_cells:
try:
if target_cell.is_me:
# Need to create instance DB entries as the conductor
# expects that the instance(s) already exists.
instances = self._create_instances_here(ctxt,
instance_uuids, instance_properties, instance_type,
image, security_groups, block_device_mapping)
build_inst_kwargs['instances'] = instances
# Need to record the create action in the db as the
# conductor expects it to already exist.
self._create_action_here(ctxt, instance_uuids)
self.compute_task_api.build_instances(ctxt,
**build_inst_kwargs)
return
self.msg_runner.build_instances(ctxt, target_cell,
build_inst_kwargs)
return
except Exception:
LOG.exception("Couldn't communicate with cell '%s'",
target_cell.name)
# FIXME(comstud): Would be nice to kick this back up so that
# the parent cell could retry, if we had a parent.
LOG.error("Couldn't communicate with any cells")
raise exception.NoCellsAvailable()
def build_instances(self, message, build_inst_kwargs):
image = build_inst_kwargs['image']
instance_uuids = [inst['uuid'] for inst in
build_inst_kwargs['instances']]
instances = build_inst_kwargs['instances']
request_spec = scheduler_utils.build_request_spec(message.ctxt,
image, instances)
filter_properties = copy.copy(build_inst_kwargs['filter_properties'])
filter_properties.update({'context': message.ctxt,
'scheduler': self,
'routing_path': message.routing_path,
'host_sched_kwargs': build_inst_kwargs,
'request_spec': request_spec})
self._schedule_build_to_cells(message, instance_uuids,
filter_properties, self._build_instances, build_inst_kwargs)
def _schedule_build_to_cells(self, message, instance_uuids,
filter_properties, method, method_kwargs):
"""Pick a cell where we should create a new instance(s)."""
try:
for i in range(max(0, CONF.cells.scheduler_retries) + 1):
try:
target_cells = self._grab_target_cells(filter_properties)
if target_cells is None:
# a filter took care of scheduling. skip.
return
return method(message, target_cells, instance_uuids,
method_kwargs)
except exception.NoCellsAvailable:
if i == max(0, CONF.cells.scheduler_retries):
raise
sleep_time = max(1, CONF.cells.scheduler_retry_delay)
LOG.info("No cells available when scheduling. Will "
"retry in %(sleep_time)s second(s)",
{'sleep_time': sleep_time})
time.sleep(sleep_time)
continue
except Exception:
LOG.exception("Error scheduling instances %(instance_uuids)s",
{'instance_uuids': instance_uuids})
ctxt = message.ctxt
for instance_uuid in instance_uuids:
instance = objects.Instance(context=ctxt, uuid=instance_uuid,
vm_state=vm_states.ERROR)
self.msg_runner.instance_update_at_top(ctxt, instance)
try:
instance.vm_state = vm_states.ERROR
instance.save()
except Exception:
pass
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6029,
32679,
10891,
316,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
199,
16852,
32051,
199,
624,
199,
646,
1331,
199,
646,
900,
199,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
504,
3816,
14,
4912,
492,
1425,
199,
199,
504,
5913,
14,
9041,
492,
4766,
199,
504,
5913,
14,
9041,
492,
4931,
199,
504,
5913,
492,
4526,
199,
504,
5913,
14,
3357,
492,
1256,
63,
3723,
199,
504,
5913,
14,
3357,
492,
4169,
63,
4981,
199,
504,
5913,
492,
406,
19966,
199,
646,
5913,
14,
2190,
199,
504,
5913,
14,
697,
492,
1300,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
1462,
492,
1300,
465,
1559,
63,
1095,
199,
504,
5913,
14,
8874,
492,
3778,
465,
11899,
63,
1208,
199,
504,
5913,
492,
3778,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3103,
275,
5913,
14,
2190,
14,
3103,
421,
199,
533,
445,
6840,
11251,
8,
1095,
14,
1563,
304,
272,
408,
1918,
10106,
11899,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
63,
5933,
304,
267,
1613,
8,
16852,
11251,
12,
291,
2843,
826,
4533,
267,
291,
14,
1328,
63,
5933,
275,
1499,
63,
5933,
267,
291,
14,
929,
63,
2609,
275,
1499,
63,
5933,
14,
929,
63,
2609,
267,
291,
14,
3357,
63,
1246,
275,
4526,
14,
3735,
342,
267,
291,
14,
3357,
63,
1765,
63,
1246,
275,
406,
19966,
14,
8564,
4476,
3735,
342,
267,
291,
14,
1541,
63,
2232,
275,
4766,
14,
8108,
4131,
2461,
342,
267,
2457,
63,
2888,
275,
291,
14,
1541,
63,
2232,
14,
362,
63,
9467,
63,
2888,
8,
355,
6392,
14,
9041,
14,
8874,
63,
1541,
63,
2888,
9,
267,
291,
14,
4273,
275,
359,
1886,
342,
367,
843,
315,
2457,
63,
2888,
61,
267,
291,
14,
3463,
63,
2232,
275,
4931,
14,
8108,
16359,
2461,
342,
267,
781,
2056,
281,
63,
2888,
275,
291,
14,
3463,
63,
2232,
14,
362,
63,
9467,
63,
2888,
8,
355,
6392,
14,
9041,
14,
8874,
63,
3463,
63,
2888,
9,
267,
291,
14,
1129,
2056,
1192,
275,
359,
1886,
342,
367,
843,
315,
781,
2056,
281,
63,
2888,
61,
339,
347,
485,
981,
63,
5990,
63,
1681,
8,
277,
12,
11216,
12,
1256,
63,
18401,
12,
1256,
63,
3282,
12,
288,
1256,
63,
466,
12,
1834,
12,
6391,
63,
2634,
12,
1853,
63,
1782,
63,
4745,
304,
267,
1256,
63,
1459,
275,
1331,
14,
1574,
8,
842,
63,
3282,
9,
267,
327,
710,
1676,
1443,
986,
3520,
3341,
1338,
465,
5548,
12,
436,
314,
267,
327,
1218,
1240,
14292,
652,
370,
506,
282,
1211,
14,
267,
1256,
63,
1459,
459,
2343,
418,
275,
3778,
14,
842,
63,
2024,
8,
842,
63,
1459,
9,
267,
327,
13244,
734,
7645,
626,
911,
664,
663,
7684,
1380,
295,
13,
20358,
314,
267,
327,
1256,
2777,
14,
267,
1256,
63,
1459,
14,
1935,
360,
344,
358,
267,
1256,
63,
1459,
14,
1935,
360,
354,
358,
267,
1256,
63,
1459,
14,
1935,
360,
815,
63,
1637,
358,
267,
1256,
63,
1459,
14,
1935,
360,
4416,
63,
2634,
358,
267,
1256,
63,
1459,
14,
1935,
360,
6081,
358,
398,
327,
7600,
8,
24863,
706,
304,
710,
1256,
1990,
11665,
337,
1183,
6380,
2544,
3769,
267,
327,
4847,
1806,
11785,
370,
2739,
14,
20227,
12,
314,
19950,
63,
6615,
574,
17373,
1133,
7710,
267,
327,
4847,
315,
282,
2997,
1824,
14,
9336,
652,
1990,
10232,
5525,
367,
10106,
267,
327,
2544,
652,
1990,
1777,
402,
314,
10066,
12,
3372,
652,
3063,
5133,
10106,
11785,
267,
327,
365,
10209,
5576,
1256,
2251,
14,
267,
1256,
63,
1459,
14,
1935,
360,
12024,
63,
6615,
297,
488,
9,
398,
327,
7600,
8,
24863,
706,
304,
14766,
367,
7062,
18,
63,
1580,
267,
1256,
63,
1459,
14,
1935,
360,
825,
18,
63,
1580,
297,
488,
9,
398,
327,
7600,
8,
24863,
706,
304,
14766,
367,
790,
7322,
267,
1256,
63,
1459,
14,
1935,
360,
30825,
297,
488,
9,
398,
4454,
275,
942,
267,
1967,
63,
5990,
275,
822,
8,
842,
63,
18401,
9,
267,
6391,
63,
2634,
275,
334,
288,
291,
14,
3357,
63,
1246,
14,
4416,
63,
923,
63,
1246,
14,
13817,
63,
4416,
63,
2634,
8,
355,
6391,
63,
2634,
430,
267,
367,
284,
12,
1256,
63,
2580,
315,
3874,
8,
842,
63,
18401,
304,
288,
1256,
275,
2251,
14,
3244,
8,
1100,
29,
6725,
9,
288,
1256,
14,
873,
8,
842,
63,
1459,
9,
288,
1256,
14,
2580,
275,
1256,
63,
2580,
288,
1256,
14,
6081,
275,
1256,
63,
466,
288,
1256,
14,
1753,
63,
6081,
275,
488,
288,
1256,
14,
1222,
63,
6081,
275,
488,
288,
1256,
275,
291,
14,
3357,
63,
1246,
14,
981,
63,
697,
63,
2373,
63,
509,
63,
1222,
63,
842,
8,
490,
11216,
12,
490,
1256,
63,
466,
12,
490,
1834,
12,
490,
1256,
12,
490,
6391,
63,
2634,
12,
490,
1853,
63,
1782,
63,
4745,
12,
490,
1967,
63,
5990,
12,
284,
9,
288,
1853,
63,
1782,
63,
4745,
275,
334,
355,
291,
14,
3357,
63,
1246,
423,
21520,
63,
3502,
63,
409,
63,
890,
63,
460,
63,
842,
8,
490,
11216,
12,
1256,
12,
1256,
63,
466,
12,
1853,
63,
1782,
63,
4745,
430,
288,
291,
14,
3357,
63,
1246,
423,
981,
63,
1457,
63,
1782,
63,
4745,
8
] |
[
1898,
334,
67,
9,
6029,
32679,
10891,
316,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
199,
16852,
32051,
199,
624,
199,
646,
1331,
199,
646,
900,
199,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
504,
3816,
14,
4912,
492,
1425,
199,
199,
504,
5913,
14,
9041,
492,
4766,
199,
504,
5913,
14,
9041,
492,
4931,
199,
504,
5913,
492,
4526,
199,
504,
5913,
14,
3357,
492,
1256,
63,
3723,
199,
504,
5913,
14,
3357,
492,
4169,
63,
4981,
199,
504,
5913,
492,
406,
19966,
199,
646,
5913,
14,
2190,
199,
504,
5913,
14,
697,
492,
1300,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
1462,
492,
1300,
465,
1559,
63,
1095,
199,
504,
5913,
14,
8874,
492,
3778,
465,
11899,
63,
1208,
199,
504,
5913,
492,
3778,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3103,
275,
5913,
14,
2190,
14,
3103,
421,
199,
533,
445,
6840,
11251,
8,
1095,
14,
1563,
304,
272,
408,
1918,
10106,
11899,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
63,
5933,
304,
267,
1613,
8,
16852,
11251,
12,
291,
2843,
826,
4533,
267,
291,
14,
1328,
63,
5933,
275,
1499,
63,
5933,
267,
291,
14,
929,
63,
2609,
275,
1499,
63,
5933,
14,
929,
63,
2609,
267,
291,
14,
3357,
63,
1246,
275,
4526,
14,
3735,
342,
267,
291,
14,
3357,
63,
1765,
63,
1246,
275,
406,
19966,
14,
8564,
4476,
3735,
342,
267,
291,
14,
1541,
63,
2232,
275,
4766,
14,
8108,
4131,
2461,
342,
267,
2457,
63,
2888,
275,
291,
14,
1541,
63,
2232,
14,
362,
63,
9467,
63,
2888,
8,
355,
6392,
14,
9041,
14,
8874,
63,
1541,
63,
2888,
9,
267,
291,
14,
4273,
275,
359,
1886,
342,
367,
843,
315,
2457,
63,
2888,
61,
267,
291,
14,
3463,
63,
2232,
275,
4931,
14,
8108,
16359,
2461,
342,
267,
781,
2056,
281,
63,
2888,
275,
291,
14,
3463,
63,
2232,
14,
362,
63,
9467,
63,
2888,
8,
355,
6392,
14,
9041,
14,
8874,
63,
3463,
63,
2888,
9,
267,
291,
14,
1129,
2056,
1192,
275,
359,
1886,
342,
367,
843,
315,
781,
2056,
281,
63,
2888,
61,
339,
347,
485,
981,
63,
5990,
63,
1681,
8,
277,
12,
11216,
12,
1256,
63,
18401,
12,
1256,
63,
3282,
12,
288,
1256,
63,
466,
12,
1834,
12,
6391,
63,
2634,
12,
1853,
63,
1782,
63,
4745,
304,
267,
1256,
63,
1459,
275,
1331,
14,
1574,
8,
842,
63,
3282,
9,
267,
327,
710,
1676,
1443,
986,
3520,
3341,
1338,
465,
5548,
12,
436,
314,
267,
327,
1218,
1240,
14292,
652,
370,
506,
282,
1211,
14,
267,
1256,
63,
1459,
459,
2343,
418,
275,
3778,
14,
842,
63,
2024,
8,
842,
63,
1459,
9,
267,
327,
13244,
734,
7645,
626,
911,
664,
663,
7684,
1380,
295,
13,
20358,
314,
267,
327,
1256,
2777,
14,
267,
1256,
63,
1459,
14,
1935,
360,
344,
358,
267,
1256,
63,
1459,
14,
1935,
360,
354,
358,
267,
1256,
63,
1459,
14,
1935,
360,
815,
63,
1637,
358,
267,
1256,
63,
1459,
14,
1935,
360,
4416,
63,
2634,
358,
267,
1256,
63,
1459,
14,
1935,
360,
6081,
358,
398,
327,
7600,
8,
24863,
706,
304,
710,
1256,
1990,
11665,
337,
1183,
6380,
2544,
3769,
267,
327,
4847,
1806,
11785,
370,
2739,
14,
20227,
12,
314,
19950,
63,
6615,
574,
17373,
1133,
7710,
267,
327,
4847,
315,
282,
2997,
1824,
14,
9336,
652,
1990,
10232,
5525,
367,
10106,
267,
327,
2544,
652,
1990,
1777,
402,
314,
10066,
12,
3372,
652,
3063,
5133,
10106,
11785,
267,
327,
365,
10209,
5576,
1256,
2251,
14,
267,
1256,
63,
1459,
14,
1935,
360,
12024,
63,
6615,
297,
488,
9,
398,
327,
7600,
8,
24863,
706,
304,
14766,
367,
7062,
18,
63,
1580,
267,
1256,
63,
1459,
14,
1935,
360,
825,
18,
63,
1580,
297,
488,
9,
398,
327,
7600,
8,
24863,
706,
304,
14766,
367,
790,
7322,
267,
1256,
63,
1459,
14,
1935,
360,
30825,
297,
488,
9,
398,
4454,
275,
942,
267,
1967,
63,
5990,
275,
822,
8,
842,
63,
18401,
9,
267,
6391,
63,
2634,
275,
334,
288,
291,
14,
3357,
63,
1246,
14,
4416,
63,
923,
63,
1246,
14,
13817,
63,
4416,
63,
2634,
8,
355,
6391,
63,
2634,
430,
267,
367,
284,
12,
1256,
63,
2580,
315,
3874,
8,
842,
63,
18401,
304,
288,
1256,
275,
2251,
14,
3244,
8,
1100,
29,
6725,
9,
288,
1256,
14,
873,
8,
842,
63,
1459,
9,
288,
1256,
14,
2580,
275,
1256,
63,
2580,
288,
1256,
14,
6081,
275,
1256,
63,
466,
288,
1256,
14,
1753,
63,
6081,
275,
488,
288,
1256,
14,
1222,
63,
6081,
275,
488,
288,
1256,
275,
291,
14,
3357,
63,
1246,
14,
981,
63,
697,
63,
2373,
63,
509,
63,
1222,
63,
842,
8,
490,
11216,
12,
490,
1256,
63,
466,
12,
490,
1834,
12,
490,
1256,
12,
490,
6391,
63,
2634,
12,
490,
1853,
63,
1782,
63,
4745,
12,
490,
1967,
63,
5990,
12,
284,
9,
288,
1853,
63,
1782,
63,
4745,
275,
334,
355,
291,
14,
3357,
63,
1246,
423,
21520,
63,
3502,
63,
409,
63,
890,
63,
460,
63,
842,
8,
490,
11216,
12,
1256,
12,
1256,
63,
466,
12,
1853,
63,
1782,
63,
4745,
430,
288,
291,
14,
3357,
63,
1246,
423,
981,
63,
1457,
63,
1782,
63,
4745,
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,
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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
] |
sekikn/incubator-airflow
|
airflow/contrib/operators/sagemaker_endpoint_operator.py
|
7
|
1212
|
#
# 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.
"""This module is deprecated. Please use `airflow.providers.amazon.aws.operators.sagemaker_endpoint`."""
import warnings
# pylint: disable=unused-import
from airflow.providers.amazon.aws.operators.sagemaker_endpoint import SageMakerEndpointOperator # noqa
warnings.warn(
"This module is deprecated. Please use `airflow.providers.amazon.aws.operators.sagemaker_endpoint`.",
DeprecationWarning,
stacklevel=2,
)
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
624,
2765,
859,
365,
5906,
14,
7754,
675,
658,
15815,
14,
9710,
14,
15144,
14,
7231,
14,
12688,
14,
5648,
14367,
63,
6520,
17105,
199,
199,
646,
3598,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
16321,
14,
9710,
14,
15144,
14,
7231,
14,
12688,
14,
5648,
14367,
63,
6520,
492,
428,
474,
23560,
11442,
7961,
221,
327,
8151,
199,
199,
5451,
14,
4050,
8,
272,
298,
2765,
859,
365,
5906,
14,
7754,
675,
658,
15815,
14,
9710,
14,
15144,
14,
7231,
14,
12688,
14,
5648,
14367,
63,
6520,
2313,
401,
272,
13413,
12,
272,
13232,
29,
18,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
624,
2765,
859,
365,
5906,
14,
7754,
675,
658,
15815,
14,
9710,
14,
15144,
14,
7231,
14,
12688,
14,
5648,
14367,
63,
6520,
17105,
199,
199,
646,
3598,
199,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
16321,
14,
9710,
14,
15144,
14,
7231,
14,
12688,
14,
5648,
14367,
63,
6520,
492,
428,
474,
23560,
11442,
7961,
221,
327,
8151,
199,
199,
5451,
14,
4050,
8,
272,
298,
2765,
859,
365,
5906,
14,
7754,
675,
658,
15815,
14,
9710,
14,
15144,
14,
7231,
14,
12688,
14,
5648,
14367,
63,
6520,
2313,
401,
272,
13413,
12,
272,
13232,
29,
18,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
miguelparaiso/PracticaOdoo
|
openerp/addons/test_converter/tests/test_html.py
|
257
|
13533
|
# -*- encoding: utf-8 -*-
import json
import os
import datetime
from lxml import etree
from openerp.tests import common
from openerp.tools import html_escape as e
from openerp.addons.base.ir import ir_qweb
directory = os.path.dirname(__file__)
class TestExport(common.TransactionCase):
_model = None
def setUp(self):
super(TestExport, self).setUp()
self.Model = self.registry(self._model)
def get_field(self, name):
return self.Model._fields[name]
def get_converter(self, name, type=None):
field = self.get_field(name)
for postfix in type, field.type, '':
fs = ['ir', 'qweb', 'field']
if postfix is None: continue
if postfix: fs.append(postfix)
try:
model = self.registry('.'.join(fs))
break
except KeyError: pass
return lambda value, options=None, context=None: e(model.value_to_html(
self.cr, self.uid, value, field, options=options, context=context))
class TestBasicExport(TestExport):
_model = 'test_converter.test_model'
class TestCharExport(TestBasicExport):
def test_char(self):
converter = self.get_converter('char')
value = converter('foo')
self.assertEqual(value, 'foo')
value = converter("foo<bar>")
self.assertEqual(value, "foo<bar>")
class TestIntegerExport(TestBasicExport):
def test_integer(self):
converter = self.get_converter('integer')
value = converter(42)
self.assertEqual(value, "42")
class TestFloatExport(TestBasicExport):
def setUp(self):
super(TestFloatExport, self).setUp()
self.registry('res.lang').write(self.cr, self.uid, [1], {
'grouping': '[3,0]'
})
def test_float(self):
converter = self.get_converter('float')
value = converter(42.0)
self.assertEqual(value, "42.0")
value = converter(42.0100)
self.assertEqual(value, "42.01")
value = converter(42.01234)
self.assertEqual(value, "42.01234")
value = converter(1234567.89)
self.assertEqual(value, '1,234,567.89')
def test_numeric(self):
converter = self.get_converter('numeric')
value = converter(42.0)
self.assertEqual(value, '42.00')
value = converter(42.01234)
self.assertEqual(value, '42.01')
class TestCurrencyExport(TestExport):
_model = 'test_converter.monetary'
def setUp(self):
super(TestCurrencyExport, self).setUp()
self.Currency = self.registry('res.currency')
self.base = self.create(self.Currency, name="Source", symbol=u'source')
def create(self, model, context=None, **values):
return model.browse(
self.cr, self.uid,
model.create(self.cr, self.uid, values, context=context),
context=context)
def convert(self, obj, dest):
converter = self.registry('ir.qweb.field.monetary')
options = {
'widget': 'monetary',
'display_currency': 'c2'
}
context = dict(inherit_branding=True)
converted = converter.to_html(
self.cr, self.uid, 'value', obj, options,
etree.Element('span'),
{'field': 'obj.value', 'field-options': json.dumps(options)},
'', ir_qweb.QWebContext(self.cr, self.uid, {'obj': obj, 'c2': dest, }),
context=context,
)
return converted
def test_currency_post(self):
currency = self.create(self.Currency, name="Test", symbol=u"test")
obj = self.create(self.Model, value=0.12)
converted = self.convert(obj, dest=currency)
self.assertEqual(
converted,
'<span data-oe-model="{obj._model._name}" data-oe-id="{obj.id}" '
'data-oe-field="value" data-oe-type="monetary" '
'data-oe-expression="obj.value">'
'<span class="oe_currency_value">0.12</span>'
u'\N{NO-BREAK SPACE}{symbol}</span>'.format(
obj=obj,
symbol=currency.symbol.encode('utf-8')
).encode('utf-8'),)
def test_currency_pre(self):
currency = self.create(
self.Currency, name="Test", symbol=u"test", position='before')
obj = self.create(self.Model, value=0.12)
converted = self.convert(obj, dest=currency)
self.assertEqual(
converted,
'<span data-oe-model="{obj._model._name}" data-oe-id="{obj.id}" '
'data-oe-field="value" data-oe-type="monetary" '
'data-oe-expression="obj.value">'
u'{symbol}\N{NO-BREAK SPACE}'
'<span class="oe_currency_value">0.12</span>'
'</span>'.format(
obj=obj,
symbol=currency.symbol.encode('utf-8')
).encode('utf-8'),)
def test_currency_precision(self):
""" Precision should be the currency's, not the float field's
"""
currency = self.create(self.Currency, name="Test", symbol=u"test",)
obj = self.create(self.Model, value=0.1234567)
converted = self.convert(obj, dest=currency)
self.assertEqual(
converted,
'<span data-oe-model="{obj._model._name}" data-oe-id="{obj.id}" '
'data-oe-field="value" data-oe-type="monetary" '
'data-oe-expression="obj.value">'
'<span class="oe_currency_value">0.12</span>'
u'\N{NO-BREAK SPACE}{symbol}</span>'.format(
obj=obj,
symbol=currency.symbol.encode('utf-8')
).encode('utf-8'),)
class TestTextExport(TestBasicExport):
def test_text(self):
converter = self.get_converter('text')
value = converter("This is my text-kai")
self.assertEqual(value, "This is my text-kai")
value = converter("""
. The current line (address) in the buffer.
$ The last line in the buffer.
n The nth, line in the buffer where n is a number in the range [0,$].
$ The last line in the buffer.
- The previous line. This is equivalent to -1 and may be repeated with cumulative effect.
-n The nth previous line, where n is a non-negative number.
+ The next line. This is equivalent to +1 and may be repeated with cumulative effect.
""")
self.assertEqual(value, """<br>
. The current line (address) in the buffer.<br>
$ The last line in the buffer.<br>
n The nth, line in the buffer where n is a number in the range [0,$].<br>
$ The last line in the buffer.<br>
- The previous line. This is equivalent to -1 and may be repeated with cumulative effect.<br>
-n The nth previous line, where n is a non-negative number.<br>
+ The next line. This is equivalent to +1 and may be repeated with cumulative effect.<br>
""")
value = converter("""
fgdkls;hjas;lj <b>fdslkj</b> d;lasjfa lkdja <a href=http://spam.com>lfks</a>
fldkjsfhs <i style="color: red"><a href="http://spamspam.com">fldskjh</a></i>
""")
self.assertEqual(value, """<br>
fgdkls;hjas;lj <b>fdslkj</b> d;lasjfa lkdja <a href=http://spam.com>lfks</a><br>
fldkjsfhs <i style="color: red"><a href="http://spamspam.com">fldskjh</a></i><br>
""")
class TestMany2OneExport(TestBasicExport):
def test_many2one(self):
Sub = self.registry('test_converter.test_model.sub')
id0 = self.Model.create(self.cr, self.uid, {
'many2one': Sub.create(self.cr, self.uid, {'name': "Foo"})
})
id1 = self.Model.create(self.cr, self.uid, {
'many2one': Sub.create(self.cr, self.uid, {'name': "Fo<b>o</b>"})
})
def converter(record):
model = self.registry('ir.qweb.field.many2one')
return e(model.record_to_html(self.cr, self.uid, 'many2one', record))
value = converter(self.Model.browse(self.cr, self.uid, id0))
self.assertEqual(value, "Foo")
value = converter(self.Model.browse(self.cr, self.uid, id1))
self.assertEqual(value, "Fo<b>o</b>")
class TestBinaryExport(TestBasicExport):
def test_image(self):
field = self.get_field('binary')
converter = self.registry('ir.qweb.field.image')
with open(os.path.join(directory, 'test_vectors', 'image'), 'rb') as f:
content = f.read()
encoded_content = content.encode('base64')
value = e(converter.value_to_html(
self.cr, self.uid, encoded_content, field))
self.assertEqual(
value, '<img src="data:image/jpeg;base64,%s">' % (
encoded_content
))
with open(os.path.join(directory, 'test_vectors', 'pdf'), 'rb') as f:
content = f.read()
with self.assertRaises(ValueError):
e(converter.value_to_html(
self.cr, self.uid, 'binary', content.encode('base64'), field))
with open(os.path.join(directory, 'test_vectors', 'pptx'), 'rb') as f:
content = f.read()
with self.assertRaises(ValueError):
e(converter.value_to_html(
self.cr, self.uid, 'binary', content.encode('base64'), field))
class TestSelectionExport(TestBasicExport):
def test_selection(self):
[record] = self.Model.browse(self.cr, self.uid, [self.Model.create(self.cr, self.uid, {
'selection': 2,
'selection_str': 'C',
})])
converter = self.registry('ir.qweb.field.selection')
field_name = 'selection'
value = converter.record_to_html(self.cr, self.uid, field_name, record)
self.assertEqual(value, "réponse B")
field_name = 'selection_str'
value = converter.record_to_html(self.cr, self.uid, field_name, record)
self.assertEqual(value, "Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?")
class TestHTMLExport(TestBasicExport):
def test_html(self):
converter = self.get_converter('html')
input = '<span>span</span>'
value = converter(input)
self.assertEqual(value, input)
class TestDatetimeExport(TestBasicExport):
def setUp(self):
super(TestDatetimeExport, self).setUp()
# set user tz to known value
Users = self.registry('res.users')
Users.write(self.cr, self.uid, self.uid, {
'tz': 'Pacific/Niue'
}, context=None)
def test_date(self):
converter = self.get_converter('date')
value = converter('2011-05-03')
# default lang/format is US
self.assertEqual(value, '05/03/2011')
def test_datetime(self):
converter = self.get_converter('datetime')
value = converter('2011-05-03 11:12:13')
# default lang/format is US
self.assertEqual(value, '05/03/2011 00:12:13')
def test_custom_format(self):
converter = self.get_converter('datetime')
converter2 = self.get_converter('date')
opts = {'format': 'MMMM d'}
value = converter('2011-03-02 11:12:13', options=opts)
value2 = converter2('2001-03-02', options=opts)
self.assertEqual(
value,
'March 2'
)
self.assertEqual(
value2,
'March 2'
)
class TestDurationExport(TestBasicExport):
def setUp(self):
super(TestDurationExport, self).setUp()
# needs to have lang installed otherwise falls back on en_US
self.registry('res.lang').load_lang(self.cr, self.uid, 'fr_FR')
def test_negative(self):
converter = self.get_converter('float', 'duration')
with self.assertRaises(ValueError):
converter(-4)
def test_missing_unit(self):
converter = self.get_converter('float', 'duration')
with self.assertRaises(ValueError):
converter(4)
def test_basic(self):
converter = self.get_converter('float', 'duration')
result = converter(4, {'unit': 'hour'}, {'lang': 'fr_FR'})
self.assertEqual(result, u'4 heures')
result = converter(50, {'unit': 'second'}, {'lang': 'fr_FR'})
self.assertEqual(result, u'50 secondes')
def test_multiple(self):
converter = self.get_converter('float', 'duration')
result = converter(1.5, {'unit': 'hour'}, {'lang': 'fr_FR'})
self.assertEqual(result, u"1 heure 30 minutes")
result = converter(72, {'unit': 'second'}, {'lang': 'fr_FR'})
self.assertEqual(result, u"1 minute 12 secondes")
class TestRelativeDatetime(TestBasicExport):
# not sure how a test based on "current time" should be tested. Even less
# so as it would mostly be a test of babel...
def setUp(self):
super(TestRelativeDatetime, self).setUp()
# needs to have lang installed otherwise falls back on en_US
self.registry('res.lang').load_lang(self.cr, self.uid, 'fr_FR')
def test_basic(self):
converter = self.get_converter('datetime', 'relative')
t = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
result = converter(t, context={'lang': 'fr_FR'})
self.assertEqual(result, u"il y a 1 heure")
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
646,
2022,
199,
646,
747,
199,
646,
2197,
199,
199,
504,
14490,
492,
7559,
199,
199,
504,
5166,
14,
2219,
492,
2863,
199,
504,
5166,
14,
2537,
492,
3517,
63,
3765,
465,
325,
199,
504,
5166,
14,
10788,
14,
1095,
14,
723,
492,
8190,
63,
22600,
199,
199,
3619,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
533,
1379,
11399,
8,
2330,
14,
10161,
1538,
304,
272,
485,
1238,
275,
488,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
11399,
12,
291,
680,
5996,
342,
267,
291,
14,
1685,
275,
291,
14,
5189,
8,
277,
423,
1238,
9,
339,
347,
664,
63,
698,
8,
277,
12,
536,
304,
267,
372,
291,
14,
1685,
423,
955,
59,
354,
61,
339,
347,
664,
63,
11256,
8,
277,
12,
536,
12,
730,
29,
403,
304,
267,
901,
275,
291,
14,
362,
63,
698,
8,
354,
9,
398,
367,
31478,
315,
730,
12,
901,
14,
466,
12,
8061,
288,
7449,
275,
788,
723,
297,
283,
22600,
297,
283,
698,
418,
288,
340,
31478,
365,
488,
26,
1980,
288,
340,
31478,
26,
7449,
14,
740,
8,
24791,
9,
953,
862,
26,
355,
1402,
275,
291,
14,
5189,
5175,
1370,
904,
8,
2319,
430,
355,
2059,
288,
871,
4067,
26,
986,
398,
372,
2400,
574,
12,
1511,
29,
403,
12,
1067,
29,
403,
26,
325,
8,
1238,
14,
585,
63,
475,
63,
1360,
8,
288,
291,
14,
1556,
12,
291,
14,
1535,
12,
574,
12,
901,
12,
1511,
29,
1419,
12,
1067,
29,
1100,
430,
199,
199,
533,
1379,
6845,
11399,
8,
774,
11399,
304,
272,
485,
1238,
275,
283,
396,
63,
11256,
14,
396,
63,
1238,
7,
199,
199,
533,
1379,
1610,
11399,
8,
774,
6845,
11399,
304,
272,
347,
511,
63,
1560,
8,
277,
304,
267,
11109,
275,
291,
14,
362,
63,
11256,
360,
1560,
358,
398,
574,
275,
11109,
360,
1421,
358,
267,
291,
14,
629,
8,
585,
12,
283,
1421,
358,
398,
574,
275,
11109,
480,
1421,
28,
1700,
9579,
267,
291,
14,
629,
8,
585,
12,
298,
1421,
6,
4116,
27,
1700,
6,
3308,
15027,
199,
199,
533,
1379,
2674,
11399,
8,
774,
6845,
11399,
304,
272,
347,
511,
63,
4115,
8,
277,
304,
267,
11109,
275,
291,
14,
362,
63,
11256,
360,
4115,
358,
398,
574,
275,
11109,
8,
2260,
9,
267,
291,
14,
629,
8,
585,
12,
298,
2260,
531,
199,
199,
533,
1379,
5136,
11399,
8,
774,
6845,
11399,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
5136,
11399,
12,
291,
680,
5996,
342,
267,
291,
14,
5189,
360,
470,
14,
4159,
1959,
952,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
359,
17,
467,
469,
288,
283,
22390,
356,
6730,
19,
12,
16,
6616,
267,
3828,
339,
347,
511,
63,
1609,
8,
277,
304,
267,
11109,
275,
291,
14,
362,
63,
11256,
360,
1609,
358,
398,
574,
275,
11109,
8,
2260,
14,
16,
9,
267,
291,
14,
629,
8,
585,
12,
298,
2260,
14,
16,
531,
398,
574,
275,
11109,
8,
2260,
14,
16569,
9,
267,
291,
14,
629,
8,
585,
12,
298,
2260,
14,
614,
531,
398,
574,
275,
11109,
8,
2260,
14,
9461,
9,
267,
291,
14,
629,
8,
585,
12,
298,
2260,
14,
9461,
531,
398,
574,
275,
11109,
8,
30217,
14,
1407,
9,
267,
291,
14,
629,
8,
585,
12,
283,
17,
12,
5533,
12,
5308,
14,
1407,
358,
339,
347,
511,
63,
6677,
8,
277,
304,
267,
11109,
275,
291,
14,
362,
63,
11256,
360,
6677,
358,
398,
574,
275,
11109,
8,
2260,
14,
16,
9,
267,
291,
14,
629,
8,
585,
12,
283,
2260,
14,
383,
358,
398,
574,
275,
11109,
8,
2260,
14,
9461,
9,
267,
291,
14,
629,
8,
585,
12,
283,
2260,
14,
614,
358,
199,
199,
533,
1379,
19567,
11399,
8,
774,
11399,
304,
272,
485,
1238,
275,
283,
396,
63,
11256,
14,
77,
25759,
695,
7,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
19567,
11399,
12,
291,
680,
5996,
342,
267,
291,
14,
19567,
275,
291,
14,
5189,
360,
470,
14,
4968,
358,
267,
291,
14,
1095,
275,
291,
14,
981,
8,
277,
14,
19567,
12,
536,
628,
2980,
401,
5272,
29,
85,
1159,
616,
358,
339,
347,
1218,
8,
277,
12,
1402,
12,
1067,
29,
403,
12,
1011,
1459,
304,
267,
372,
1402,
14,
4570,
8,
288,
291,
14,
1556,
12,
291,
14,
1535,
12,
288,
1402,
14,
981,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1338,
12,
1067,
29,
1100,
395,
288,
1067,
29,
1100,
9,
339,
347,
3957,
8,
277,
12,
1559,
12,
2053,
304,
267,
11109,
275,
291,
14,
5189,
360,
723,
14,
22600,
14,
698,
14,
77,
25759,
695,
358,
267,
1511,
275,
469,
288,
283,
3440,
356,
283,
77,
25759,
695,
297,
288,
283,
2918,
63,
4968,
356,
283,
67,
18,
7,
267,
789,
267,
1067,
275,
1211,
8,
6486,
63,
19026,
316,
29,
549,
9,
267,
6702,
275,
11109,
14,
475,
63,
1360,
8,
288,
291,
14,
1556,
12,
291,
14,
1535,
12,
283,
585,
297,
1559,
12,
1511,
12,
288,
7559,
14,
2162,
360,
3751,
659,
288,
791,
698,
356,
283,
1113,
14,
585,
297,
283,
698,
13,
1419,
356,
2022,
14,
4180,
8,
1419,
16658,
288,
3260,
8190,
63,
22600,
14,
49,
5926,
2998,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
791,
1113,
356,
1559,
12,
283,
67,
18,
356,
2053,
12,
9998,
288,
1067,
29,
1100,
12,
267,
776,
267,
372,
6702,
339,
347,
511,
63,
4968,
63,
1932,
8,
277,
304,
267,
9952,
275,
291,
14,
981,
8,
277,
14,
19567,
12,
536,
628,
774,
401,
5272,
29,
85,
2,
396,
531,
267,
1559,
275,
291,
14,
981,
8,
277,
14,
1685,
12,
574,
29,
16,
14,
713,
9,
398,
6702,
275,
291,
14,
3916,
8,
1113,
12,
2053,
29,
4968,
9,
398,
291,
14,
629,
8,
288,
6702,
12,
288,
2650,
3751,
666,
13,
13361,
13,
1238,
18448,
1113,
423,
1238,
423,
354,
7063,
666,
13,
13361,
13,
344,
18448,
1113,
14,
344,
7063,
283,
2116,
283,
576,
13,
13361,
13,
698,
628
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
646,
2022,
199,
646,
747,
199,
646,
2197,
199,
199,
504,
14490,
492,
7559,
199,
199,
504,
5166,
14,
2219,
492,
2863,
199,
504,
5166,
14,
2537,
492,
3517,
63,
3765,
465,
325,
199,
504,
5166,
14,
10788,
14,
1095,
14,
723,
492,
8190,
63,
22600,
199,
199,
3619,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
533,
1379,
11399,
8,
2330,
14,
10161,
1538,
304,
272,
485,
1238,
275,
488,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
11399,
12,
291,
680,
5996,
342,
267,
291,
14,
1685,
275,
291,
14,
5189,
8,
277,
423,
1238,
9,
339,
347,
664,
63,
698,
8,
277,
12,
536,
304,
267,
372,
291,
14,
1685,
423,
955,
59,
354,
61,
339,
347,
664,
63,
11256,
8,
277,
12,
536,
12,
730,
29,
403,
304,
267,
901,
275,
291,
14,
362,
63,
698,
8,
354,
9,
398,
367,
31478,
315,
730,
12,
901,
14,
466,
12,
8061,
288,
7449,
275,
788,
723,
297,
283,
22600,
297,
283,
698,
418,
288,
340,
31478,
365,
488,
26,
1980,
288,
340,
31478,
26,
7449,
14,
740,
8,
24791,
9,
953,
862,
26,
355,
1402,
275,
291,
14,
5189,
5175,
1370,
904,
8,
2319,
430,
355,
2059,
288,
871,
4067,
26,
986,
398,
372,
2400,
574,
12,
1511,
29,
403,
12,
1067,
29,
403,
26,
325,
8,
1238,
14,
585,
63,
475,
63,
1360,
8,
288,
291,
14,
1556,
12,
291,
14,
1535,
12,
574,
12,
901,
12,
1511,
29,
1419,
12,
1067,
29,
1100,
430,
199,
199,
533,
1379,
6845,
11399,
8,
774,
11399,
304,
272,
485,
1238,
275,
283,
396,
63,
11256,
14,
396,
63,
1238,
7,
199,
199,
533,
1379,
1610,
11399,
8,
774,
6845,
11399,
304,
272,
347,
511,
63,
1560,
8,
277,
304,
267,
11109,
275,
291,
14,
362,
63,
11256,
360,
1560,
358,
398,
574,
275,
11109,
360,
1421,
358,
267,
291,
14,
629,
8,
585,
12,
283,
1421,
358,
398,
574,
275,
11109,
480,
1421,
28,
1700,
9579,
267,
291,
14,
629,
8,
585,
12,
298,
1421,
6,
4116,
27,
1700,
6,
3308,
15027,
199,
199,
533,
1379,
2674,
11399,
8,
774,
6845,
11399,
304,
272,
347,
511,
63,
4115,
8,
277,
304,
267,
11109,
275,
291,
14,
362,
63,
11256,
360,
4115,
358,
398,
574,
275,
11109,
8,
2260,
9,
267,
291,
14,
629,
8,
585,
12,
298,
2260,
531,
199,
199,
533,
1379,
5136,
11399,
8,
774,
6845,
11399,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
5136,
11399,
12,
291,
680,
5996,
342,
267,
291,
14,
5189,
360,
470,
14,
4159,
1959,
952,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
359,
17,
467,
469,
288,
283,
22390,
356,
6730,
19,
12,
16,
6616,
267,
3828,
339,
347,
511,
63,
1609,
8,
277,
304,
267,
11109,
275,
291,
14,
362,
63,
11256,
360,
1609,
358,
398,
574,
275,
11109,
8,
2260,
14,
16,
9,
267,
291,
14,
629,
8,
585,
12,
298,
2260,
14,
16,
531,
398,
574,
275,
11109,
8,
2260,
14,
16569,
9,
267,
291,
14,
629,
8,
585,
12,
298,
2260,
14,
614,
531,
398,
574,
275,
11109,
8,
2260,
14,
9461,
9,
267,
291,
14,
629,
8,
585,
12,
298,
2260,
14,
9461,
531,
398,
574,
275,
11109,
8,
30217,
14,
1407,
9,
267,
291,
14,
629,
8,
585,
12,
283,
17,
12,
5533,
12,
5308,
14,
1407,
358,
339,
347,
511,
63,
6677,
8,
277,
304,
267,
11109,
275,
291,
14,
362,
63,
11256,
360,
6677,
358,
398,
574,
275,
11109,
8,
2260,
14,
16,
9,
267,
291,
14,
629,
8,
585,
12,
283,
2260,
14,
383,
358,
398,
574,
275,
11109,
8,
2260,
14,
9461,
9,
267,
291,
14,
629,
8,
585,
12,
283,
2260,
14,
614,
358,
199,
199,
533,
1379,
19567,
11399,
8,
774,
11399,
304,
272,
485,
1238,
275,
283,
396,
63,
11256,
14,
77,
25759,
695,
7,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
19567,
11399,
12,
291,
680,
5996,
342,
267,
291,
14,
19567,
275,
291,
14,
5189,
360,
470,
14,
4968,
358,
267,
291,
14,
1095,
275,
291,
14,
981,
8,
277,
14,
19567,
12,
536,
628,
2980,
401,
5272,
29,
85,
1159,
616,
358,
339,
347,
1218,
8,
277,
12,
1402,
12,
1067,
29,
403,
12,
1011,
1459,
304,
267,
372,
1402,
14,
4570,
8,
288,
291,
14,
1556,
12,
291,
14,
1535,
12,
288,
1402,
14,
981,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1338,
12,
1067,
29,
1100,
395,
288,
1067,
29,
1100,
9,
339,
347,
3957,
8,
277,
12,
1559,
12,
2053,
304,
267,
11109,
275,
291,
14,
5189,
360,
723,
14,
22600,
14,
698,
14,
77,
25759,
695,
358,
267,
1511,
275,
469,
288,
283,
3440,
356,
283,
77,
25759,
695,
297,
288,
283,
2918,
63,
4968,
356,
283,
67,
18,
7,
267,
789,
267,
1067,
275,
1211,
8,
6486,
63,
19026,
316,
29,
549,
9,
267,
6702,
275,
11109,
14,
475,
63,
1360,
8,
288,
291,
14,
1556,
12,
291,
14,
1535,
12,
283,
585,
297,
1559,
12,
1511,
12,
288,
7559,
14,
2162,
360,
3751,
659,
288,
791,
698,
356,
283,
1113,
14,
585,
297,
283,
698,
13,
1419,
356,
2022,
14,
4180,
8,
1419,
16658,
288,
3260,
8190,
63,
22600,
14,
49,
5926,
2998,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
791,
1113,
356,
1559,
12,
283,
67,
18,
356,
2053,
12,
9998,
288,
1067,
29,
1100,
12,
267,
776,
267,
372,
6702,
339,
347,
511,
63,
4968,
63,
1932,
8,
277,
304,
267,
9952,
275,
291,
14,
981,
8,
277,
14,
19567,
12,
536,
628,
774,
401,
5272,
29,
85,
2,
396,
531,
267,
1559,
275,
291,
14,
981,
8,
277,
14,
1685,
12,
574,
29,
16,
14,
713,
9,
398,
6702,
275,
291,
14,
3916,
8,
1113,
12,
2053,
29,
4968,
9,
398,
291,
14,
629,
8,
288,
6702,
12,
288,
2650,
3751,
666,
13,
13361,
13,
1238,
18448,
1113,
423,
1238,
423,
354,
7063,
666,
13,
13361,
13,
344,
18448,
1113,
14,
344,
7063,
283,
2116,
283,
576,
13,
13361,
13,
698,
628,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hfp/tensorflow-xsmm
|
tensorflow/contrib/proto/python/ops/decode_proto_op.py
|
37
|
1155
|
# =============================================================================
# Copyright 2018 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.
# =============================================================================
# pylint: disable=wildcard-import,unused-import
"""Protocol Buffer decoding from tensors."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.proto.python.ops.gen_decode_proto_op import decode_proto_v2 as decode_proto
from tensorflow.python.framework import ops
ops.NotDifferentiable("DecodeProtoV2")
|
apache-2.0
|
[
3,
26237,
199,
3,
1898,
14894,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
26237,
199,
199,
3,
4287,
26,
3507,
29,
16692,
13,
646,
12,
8618,
13,
646,
199,
624,
3658,
26661,
15952,
687,
10519,
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,
504,
3228,
14,
2828,
14,
2625,
14,
1548,
14,
1483,
14,
2268,
63,
2708,
63,
2625,
63,
411,
492,
4849,
63,
2625,
63,
86,
18,
465,
4849,
63,
2625,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
1483,
14,
1763,
16384,
30906,
461,
480,
9400,
8548,
54,
18,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
26237,
199,
3,
1898,
14894,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
26237,
199,
199,
3,
4287,
26,
3507,
29,
16692,
13,
646,
12,
8618,
13,
646,
199,
624,
3658,
26661,
15952,
687,
10519,
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,
504,
3228,
14,
2828,
14,
2625,
14,
1548,
14,
1483,
14,
2268,
63,
2708,
63,
2625,
63,
411,
492,
4849,
63,
2625,
63,
86,
18,
465,
4849,
63,
2625,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
1483,
14,
1763,
16384,
30906,
461,
480,
9400,
8548,
54,
18,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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AR = 1
LIKE = 2
LIKE_FOLLOW = 3
UNFOLLOW = 4
#Choose the tag you want to like based on, keep the word in double quotes, do not put a # sign in front of the tag
TAGS = ["beach", "lolcats", "kerry", "tree"]
#IF YOU WANT THE ACTION TO FOLLOW OR LIKE SOMEONE BASED ON THE CHOSEN TAG CHANGE IT TO EITHER
# ACTION=POPULAR - Popular follows people who have liked an image on the popular page (this means they are active users)
# ACTION=LIKE
# ACTION=LIKE_FOLLOW
ACTION = UNFOLLOW
#CHANGE THE NUMBER OF LIKES OR FOLLOWS YOU WANT TO OCCUR, e.g. NO MORE THEN 100 is the current setting
MAX_COUNT = 100
#MAX seconds is the number of seconds to randomly wait between doing your next follow or like (this helps to avoid acting like a crazy spam bot)
MAX_SECS = 2
#Hit the URL below, the returned GET request will give you an auth token from Instagram.
#
#THE AUTH TOKEN IS THE KEY THAT YOU GET WHEN YOU SIGN IN WITH THE FOLLOWING CLIENT URL.
#DOES NOT NEED TO CHANGE UNLESS AUTH TOKEN EXPIRES
#
#
# https://api.instagram.com/oauth/authorize/?client_id=1627c123e3fc481791e0d6be16ff57a0&redirect_uri=http://yoururl.com&response_type=token&display=touch&scope=likes+relationships
#
auth_token = "asdfasfdsafsadfreafdafs"
client_id = '1627c123e3fc481791e0d6be16ff57a0'
######DO NOT TOUCH ANYTHING UNDER HERE UNLESS YOU KNOW WHAT YOU ARE DOING, DANGER DANGER, SERIOUS PROBLEMS IF YOU TOUCH ###########
print "FOLLOW PIE BEGINS - GRAB A SLICE AND SIT BACK"
print ""
print "The script will now proceed"
print ""
print ""
import time, random
import urllib,json,urllib2
user_agent = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7'
headers = { 'User-Agent' : user_agent,
"Content-type": "application/x-www-form-urlencoded"
}
likedDict = {}
def likePicture(pictureId):
liked = 0
try:
urlLike = "https://api.instagram.com/v1/media/%s/likes"
values = {'access_token' : auth_token,
'client_id' : client_id}
newLike = urlLike % (pictureId)
print newLike
data = urllib.urlencode(values)
req = urllib2.Request(newLike,data,headers)
response = urllib2.urlopen(req)
result = response.read()
dataObj = json.loads(result)
liked = 1
except Exception, e:
print e
return liked
FOLLOWS = 1
DOES_NOT_FOLLOW = 0
PENDING = 2
#unfollow users who don't follow you.
def unfollow_users(next_url=None, num_unfollows=0):
if next_url == None:
urlUserMedia = "https://api.instagram.com/v1/users/self/follows?access_token=%s" % (auth_token)
else:
urlUserMedia = next_url
values = {
'client_id' : client_id}
try:
data = urllib.urlencode(values)
req = urllib2.Request(urlUserMedia,None,headers)
response = urllib2.urlopen(req)
result = response.read()
dataObj = json.loads(result)
next_url = None
if dataObj.get('pagination') is not None:
next_url = dataObj.get('pagination')["next_url"]
for user in dataObj['data']:
for k, v in user.iteritems():
if k == "id":
userId = v
relationship = get_relationship(userId)
if relationship == DOES_NOT_FOLLOW:
result = unfollow_user(userId)
num_unfollows = num_unfollows+result
seconds=random.randint(1, MAX_SECS)
time.sleep(seconds)
print num_unfollows
if num_unfollows % 10 == 0:
print "Unfollowed %s users " % num_unfollows
if next_url is not None:
unfollow_users(next_url, num_unfollows)
except Exception, e:
print e
return num_unfollows
def get_relationship(userId):
unfollowed=0
followUrl = "https://api.instagram.com/v1/users/%s/relationship?access_token=%s&client_id=%s" % (userId, auth_token, client_id)
values = {'access_token' : auth_token,
'client_id' : client_id}
try:
data = urllib.urlencode(values)
req = urllib2.Request(followUrl,None,headers)
response = urllib2.urlopen(req)
result = response.read()
dataObj = json.loads(result)
status = dataObj["data"]
incoming = status["incoming_status"]
print '%s - %s ' % (userId, incoming)
if incoming != "followed_by":
return DOES_NOT_FOLLOW
else:
return FOLLOWS
except Exception, e:
print e
return unfollowed
def unfollow_user(userId):
unfollowed=0
followUrl = "https://api.instagram.com/v1/users/%s/relationship?action=allow"
values = {'access_token' : auth_token,
'action' : 'unfollow',
'client_id' : client_id}
try:
newFollow = followUrl % (userId)
data = urllib.urlencode(values)
req = urllib2.Request(newFollow,data,headers)
response = urllib2.urlopen(req)
result = response.read()
dataObj = json.loads(result)
unfollowed = 1
except Exception, e:
print e
return unfollowed
def followUser(userId):
followed=0
followUrl = "https://api.instagram.com/v1/users/%s/relationship?action=allow"
values = {'access_token' : auth_token,
'action' : 'follow',
'client_id' : client_id}
try:
newFollow = followUrl % (userId)
print newFollow
data = urllib.urlencode(values)
req = urllib2.Request(newFollow,data,headers)
response = urllib2.urlopen(req)
result = response.read()
print result
dataObj = json.loads(result);
followed = 1
except Exception, e:
print e
return followed
def likeAndFollowUser(userId):
numLikesFollows=0
urlUserMedia = "https://api.instagram.com/v1/users/%s/media/recent/?access_token=%s" % (userId,auth_token)
values = {
'client_id' : client_id}
try:
print urlUserMedia
data = urllib.urlencode(values)
req = urllib2.Request(urlUserMedia,None,headers)
response = urllib2.urlopen(req)
result = response.read()
dataObj = json.loads(result);
picsToLike = random.randint(1, 3)
print "Liking %s pics for user %s" % (picsToLike, userId)
countPicViews=0
for picture in dataObj['data']:
print "Liking picture %s " % picture['id']
likePicture(picture['id'])
countPicViews = countPicViews+1
numLikesFollows = numLikesFollows+1
if(countPicViews == picsToLike):
break
followed=1
except Exception, e:
print e
followUser(userId)
return numLikesFollows
if(ACTION == LIKE or ACTION == LIKE_FOLLOW):
def likeUsers(max_results,max_id,tag,c,fllw):
urlFindLike="https://api.instagram.com/v1/tags/%s/media/recent?client_id=%s&access_token=%s" % (tag,client_id, auth_token);
urlLike="https://api.instagram.com/v1/media/%s/likes"
values = {'access_token' : auth_token,
'client_id' : client_id,
'max_id' : max_id}
f = urllib.urlopen(urlFindLike)
dataObj = json.loads(f.read())
f.close()
numResults = len(dataObj['data'])
pictureId=0
for likeObj in dataObj['data']:
print ''
pictureId = likeObj['id']
paginationId = dataObj["pagination"]['next_max_id']
user = likeObj['user']
userId = user['id']
try:
numLikes = likedDict[pictureId]
numLikes = numLikes+1
likedDict[pictureId] = numLikes
except:
numLikes = 1
likedDict[pictureId] = numLikes
try:
result = likePicture(pictureId)
if(ACTION==LIKE_FOLLOW):
print "Following user %s" % userId
fresult=followUser(userId)
fllw=fllw+fresult
c=c+result
seconds=random.randint(1, MAX_SECS)
time.sleep(seconds)
if(c%10==0):
print "Liked %s: %s" % (tag,c)
if(fllw%10==0 and fllw!=0):
print "Followed %s: %s" % (tag,fllw)
if(c==max_results):
break
except Exception, e:
print e
if(c!=max_results):
likeUsers(max_results,paginationId,tag,c,fllw)
return c,fllw
print ''
for tag in TAGS:
c=0
f=0
c,f=likeUsers(MAX_COUNT,0,tag,c,f)
print "Liked %s: Followed %s: for tag %s" %(c,f,tag)
for likes in likedDict:
print "%s = %s" % (likes, likedDict[likes])
elif(ACTION==POPULAR):
urlPopular="https://api.instagram.com/v1/media/popular?client_id=%s" % (client_id,);
f = urllib.urlopen(urlPopular)
dataObj=json.loads(f.read())
f.close()
i=0
c=0
l=0
for obj in dataObj['data']:
for comment in obj['likes']['data']:
myid=comment['id']
try:
result=likeAndFollowUser(myid)
if(result>0):
c=c+1
l=l+result
if(c%10==0):
print "Followed %s" % c
seconds=random.randint(1, MAX_SECS)
time.sleep(seconds)
except Exception, e:
print e
if(c==MAX_COUNT):
break
if(c==MAX_COUNT):
break
""
print ""
print "Followed %s" % (c);
print "Liked %s" % (l);
elif(ACTION==UNFOLLOW):
num_unfollows = unfollow_users()
print "Number of users unfollowed is %s " % num_unfollows
print "FOLLOW PIE ENDS - HAPPY DIGESTING"
|
mit
|
[
3,
3506,
2845,
2296,
53,
1244,
4221,
654,
37,
16296,
21803,
30098,
17041,
199,
13531,
3038,
275,
413,
199,
21929,
275,
499,
199,
21929,
63,
38,
29905,
275,
650,
199,
1734,
38,
29905,
275,
841,
199,
199,
3,
23932,
314,
1947,
1265,
2934,
370,
2839,
4079,
641,
12,
4215,
314,
4349,
315,
4270,
9344,
12,
886,
440,
5324,
282,
327,
2070,
315,
13738,
402,
314,
1947,
199,
17626,
275,
2097,
1235,
1225,
401,
298,
320,
10181,
1956,
401,
298,
2570,
651,
401,
298,
2350,
937,
199,
199,
3,
4656,
1488,
22050,
644,
1441,
2334,
9612,
2296,
481,
29905,
1549,
29369,
3562,
3635,
4817,
19721,
36,
5258,
2334,
445,
2979,
51,
742,
18395,
6624,
9011,
473,
52,
2296,
662,
1571,
540,
199,
3,
257,
9612,
29,
13531,
3038,
257,
446,
13244,
2238,
11924,
13135,
3963,
1172,
1212,
25503,
376,
1834,
641,
314,
4560,
2238,
2034,
334,
3749,
4910,
2985,
787,
4702,
4390,
9,
199,
3,
257,
9612,
29,
21929,
199,
3,
257,
9612,
29,
21929,
63,
38,
29905,
199,
10052,
275,
6778,
38,
29905,
199,
199,
3,
16062,
2334,
18122,
1634,
3782,
43,
654,
1549,
481,
2228,
1484,
5035,
1488,
22050,
644,
1441,
2296,
593,
2571,
1230,
12,
325,
14,
71,
14,
4825,
603,
5788,
27299,
2948,
365,
314,
1453,
4260,
199,
4283,
63,
8760,
275,
2948,
199,
199,
3,
4283,
4696,
365,
314,
1329,
402,
4696,
370,
19311,
3618,
3382,
9689,
2195,
2163,
2035,
503,
2839,
334,
3749,
22577,
370,
5126,
2454,
316,
2839,
282,
286,
30566,
14909,
5888,
9,
199,
4283,
63,
28466,
275,
499,
199,
199,
3,
26852,
314,
2851,
5084,
12,
314,
2138,
9576,
1056,
911,
8120,
1265,
376,
1790,
1526,
687,
14089,
32208,
14,
199,
3,
199,
3,
18061,
7560,
18243,
2281,
2334,
9301,
4221,
619,
1488,
22050,
9576,
27802,
1488,
22050,
5056,
1621,
1663,
2334,
481,
29905,
1206,
14214,
1309,
2851,
14,
199,
3,
1649,
654,
2845,
7110,
1149,
2296,
6624,
9011,
6778,
30928,
7560,
18243,
3651,
2252,
3830,
199,
3,
199,
3,
199,
3,
257,
4178,
921,
1246,
14,
3615,
32208,
14,
957,
15,
6126,
15,
14204,
10197,
1258,
63,
344,
29,
975,
1465,
67,
4288,
69,
19,
3003,
2006,
1196,
3328,
69,
16,
68,
22,
1235,
975,
556,
1641,
65,
16,
6,
4876,
63,
2302,
29,
1014,
921,
12695,
633,
14,
957,
6,
1310,
63,
466,
29,
1418,
6,
2918,
29,
12376,
6,
2645,
29,
29572,
11,
24034,
199,
3,
199,
1178,
63,
1418,
275,
298,
18196,
305,
14240,
65,
2319,
350,
20153,
2756,
983,
2319,
2,
199,
1258,
63,
344,
275,
283,
975,
1465,
67,
4288,
69,
19,
3003,
2006,
1196,
3328,
69,
16,
68,
22,
1235,
975,
556,
1641,
65,
16,
7,
199,
199,
3726,
1649,
2845,
2296,
53,
1244,
1821,
2080,
1206,
6778,
11733,
869,
28106,
6778,
30928,
1488,
22050,
1804,
14283,
28752,
1488,
22050,
9315,
3506,
1206,
12,
577,
3986,
540,
577,
3986,
540,
12,
7017,
25657,
3611,
34,
906,
3053,
8036,
1488,
22050,
2296,
53,
1244,
21937,
5680,
199,
199,
1361,
298,
38,
29905,
510,
4332,
16427,
51,
446,
21772,
1217,
437,
428,
2507,
37,
2401,
428,
649,
22658,
2,
199,
1361,
3087,
199,
1361,
298,
1918,
2884,
911,
3063,
20320,
2,
199,
1361,
3087,
199,
1361,
3087,
199,
199,
646,
900,
12,
2196,
199,
646,
4011,
12,
1001,
12,
4078,
18,
199,
199,
751,
63,
4054,
275,
283,
22285,
15,
21,
14,
16,
334,
73,
15199,
27,
738,
27,
11952,
284,
15199,
4403,
841,
63,
16,
2839,
10444,
4403,
1323,
27,
655,
13,
527,
9,
21257,
21666,
15,
30102,
14,
25,
334,
43,
4943,
12,
2839,
30506,
9,
3394,
15,
20,
14,
16,
14,
21,
29724,
15,
24,
33,
16417,
428,
2756,
759,
15,
2182,
2192,
14,
1081,
14,
23,
7,
199,
2139,
275,
469,
283,
1899,
13,
7788,
7,
520,
922,
63,
4054,
12,
288,
298,
2714,
13,
466,
582,
298,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
2,
288,
789,
199,
317,
25503,
2141,
275,
1052,
421,
199,
318,
2839,
29439,
8,
12538,
1304,
304,
272,
1212,
25503,
275,
378,
272,
862,
26,
267,
1166,
12545,
275,
298,
2859,
921,
1246,
14,
3615,
32208,
14,
957,
15,
86,
17,
15,
4603,
3149,
83,
15,
29572,
2,
267,
1338,
275,
791,
2732,
63,
1418,
7,
520,
1790,
63,
1418,
12,
2116,
283,
1258,
63,
344,
7,
520,
1890,
63,
344,
93,
267,
892,
12545,
275,
1166,
12545,
450,
334,
12538,
1304,
9,
267,
870,
892,
12545,
267,
666,
275,
4011,
14,
10738,
8,
1459,
9,
267,
2648,
275,
4011,
18,
14,
2017,
8,
1222,
12545,
12,
576,
12,
2139,
9,
267,
1177,
275,
4011,
18,
14,
10890,
8,
2103,
9,
267,
754,
275,
1177,
14,
739,
342,
267,
666,
5665,
275,
2022,
14,
3640,
8,
1099,
9,
267,
1212,
25503,
275,
413,
272,
871,
2186,
12,
325,
26,
267,
870,
325,
272,
372,
1212,
25503,
199,
199,
38,
2228,
1484,
5035,
275,
413,
199,
1649,
654,
63,
4609,
63,
38,
29905,
275,
378,
199,
21243,
275,
499,
421,
199,
3,
324,
7207,
4390,
3963,
2793,
1133,
2035,
1265,
14,
199,
318,
625,
7207,
63,
3707,
8,
2184,
63,
633,
29,
403,
12,
1967,
63,
324,
7207,
83,
29,
16,
304,
272,
340,
2163,
63,
633,
508,
488,
26,
267,
1166,
1899,
11398,
275,
298,
2859,
921,
1246,
14,
3615,
32208,
14,
957,
15,
86,
17,
15,
3707,
15,
277,
15,
7207,
83,
31,
2732,
63,
1418,
2458,
83,
2,
450,
334,
1178,
63,
1418,
9,
272,
587,
26,
267,
1166,
1899,
11398,
275,
2163,
63,
633,
339,
1338,
275,
469,
1598,
283,
1258,
63,
344,
7,
520,
1890,
63,
344,
93,
272,
862,
26,
267,
666,
275,
4011,
14,
10738,
8,
1459,
9,
267,
2648,
275,
4011,
18,
14,
2017,
8,
633,
1899,
11398,
12,
403,
12,
2139,
9,
267,
1177,
275,
4011,
18,
14,
10890,
8,
2103,
9,
267,
754,
275,
1177,
14,
739,
342,
267,
666,
5665,
275,
2022,
14,
3640,
8,
1099,
9,
267,
2163,
63,
633,
275,
488,
267,
340,
666,
5665,
14,
362,
360,
22793,
358,
365,
440,
488,
26,
288,
2163,
63,
633,
275,
666,
5665,
14,
362,
360,
22793,
358,
905,
2184,
63,
633,
937,
398,
367,
922,
315,
666,
5665
] |
[
3506,
2845,
2296,
53,
1244,
4221,
654,
37,
16296,
21803,
30098,
17041,
199,
13531,
3038,
275,
413,
199,
21929,
275,
499,
199,
21929,
63,
38,
29905,
275,
650,
199,
1734,
38,
29905,
275,
841,
199,
199,
3,
23932,
314,
1947,
1265,
2934,
370,
2839,
4079,
641,
12,
4215,
314,
4349,
315,
4270,
9344,
12,
886,
440,
5324,
282,
327,
2070,
315,
13738,
402,
314,
1947,
199,
17626,
275,
2097,
1235,
1225,
401,
298,
320,
10181,
1956,
401,
298,
2570,
651,
401,
298,
2350,
937,
199,
199,
3,
4656,
1488,
22050,
644,
1441,
2334,
9612,
2296,
481,
29905,
1549,
29369,
3562,
3635,
4817,
19721,
36,
5258,
2334,
445,
2979,
51,
742,
18395,
6624,
9011,
473,
52,
2296,
662,
1571,
540,
199,
3,
257,
9612,
29,
13531,
3038,
257,
446,
13244,
2238,
11924,
13135,
3963,
1172,
1212,
25503,
376,
1834,
641,
314,
4560,
2238,
2034,
334,
3749,
4910,
2985,
787,
4702,
4390,
9,
199,
3,
257,
9612,
29,
21929,
199,
3,
257,
9612,
29,
21929,
63,
38,
29905,
199,
10052,
275,
6778,
38,
29905,
199,
199,
3,
16062,
2334,
18122,
1634,
3782,
43,
654,
1549,
481,
2228,
1484,
5035,
1488,
22050,
644,
1441,
2296,
593,
2571,
1230,
12,
325,
14,
71,
14,
4825,
603,
5788,
27299,
2948,
365,
314,
1453,
4260,
199,
4283,
63,
8760,
275,
2948,
199,
199,
3,
4283,
4696,
365,
314,
1329,
402,
4696,
370,
19311,
3618,
3382,
9689,
2195,
2163,
2035,
503,
2839,
334,
3749,
22577,
370,
5126,
2454,
316,
2839,
282,
286,
30566,
14909,
5888,
9,
199,
4283,
63,
28466,
275,
499,
199,
199,
3,
26852,
314,
2851,
5084,
12,
314,
2138,
9576,
1056,
911,
8120,
1265,
376,
1790,
1526,
687,
14089,
32208,
14,
199,
3,
199,
3,
18061,
7560,
18243,
2281,
2334,
9301,
4221,
619,
1488,
22050,
9576,
27802,
1488,
22050,
5056,
1621,
1663,
2334,
481,
29905,
1206,
14214,
1309,
2851,
14,
199,
3,
1649,
654,
2845,
7110,
1149,
2296,
6624,
9011,
6778,
30928,
7560,
18243,
3651,
2252,
3830,
199,
3,
199,
3,
199,
3,
257,
4178,
921,
1246,
14,
3615,
32208,
14,
957,
15,
6126,
15,
14204,
10197,
1258,
63,
344,
29,
975,
1465,
67,
4288,
69,
19,
3003,
2006,
1196,
3328,
69,
16,
68,
22,
1235,
975,
556,
1641,
65,
16,
6,
4876,
63,
2302,
29,
1014,
921,
12695,
633,
14,
957,
6,
1310,
63,
466,
29,
1418,
6,
2918,
29,
12376,
6,
2645,
29,
29572,
11,
24034,
199,
3,
199,
1178,
63,
1418,
275,
298,
18196,
305,
14240,
65,
2319,
350,
20153,
2756,
983,
2319,
2,
199,
1258,
63,
344,
275,
283,
975,
1465,
67,
4288,
69,
19,
3003,
2006,
1196,
3328,
69,
16,
68,
22,
1235,
975,
556,
1641,
65,
16,
7,
199,
199,
3726,
1649,
2845,
2296,
53,
1244,
1821,
2080,
1206,
6778,
11733,
869,
28106,
6778,
30928,
1488,
22050,
1804,
14283,
28752,
1488,
22050,
9315,
3506,
1206,
12,
577,
3986,
540,
577,
3986,
540,
12,
7017,
25657,
3611,
34,
906,
3053,
8036,
1488,
22050,
2296,
53,
1244,
21937,
5680,
199,
199,
1361,
298,
38,
29905,
510,
4332,
16427,
51,
446,
21772,
1217,
437,
428,
2507,
37,
2401,
428,
649,
22658,
2,
199,
1361,
3087,
199,
1361,
298,
1918,
2884,
911,
3063,
20320,
2,
199,
1361,
3087,
199,
1361,
3087,
199,
199,
646,
900,
12,
2196,
199,
646,
4011,
12,
1001,
12,
4078,
18,
199,
199,
751,
63,
4054,
275,
283,
22285,
15,
21,
14,
16,
334,
73,
15199,
27,
738,
27,
11952,
284,
15199,
4403,
841,
63,
16,
2839,
10444,
4403,
1323,
27,
655,
13,
527,
9,
21257,
21666,
15,
30102,
14,
25,
334,
43,
4943,
12,
2839,
30506,
9,
3394,
15,
20,
14,
16,
14,
21,
29724,
15,
24,
33,
16417,
428,
2756,
759,
15,
2182,
2192,
14,
1081,
14,
23,
7,
199,
2139,
275,
469,
283,
1899,
13,
7788,
7,
520,
922,
63,
4054,
12,
288,
298,
2714,
13,
466,
582,
298,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
2,
288,
789,
199,
317,
25503,
2141,
275,
1052,
421,
199,
318,
2839,
29439,
8,
12538,
1304,
304,
272,
1212,
25503,
275,
378,
272,
862,
26,
267,
1166,
12545,
275,
298,
2859,
921,
1246,
14,
3615,
32208,
14,
957,
15,
86,
17,
15,
4603,
3149,
83,
15,
29572,
2,
267,
1338,
275,
791,
2732,
63,
1418,
7,
520,
1790,
63,
1418,
12,
2116,
283,
1258,
63,
344,
7,
520,
1890,
63,
344,
93,
267,
892,
12545,
275,
1166,
12545,
450,
334,
12538,
1304,
9,
267,
870,
892,
12545,
267,
666,
275,
4011,
14,
10738,
8,
1459,
9,
267,
2648,
275,
4011,
18,
14,
2017,
8,
1222,
12545,
12,
576,
12,
2139,
9,
267,
1177,
275,
4011,
18,
14,
10890,
8,
2103,
9,
267,
754,
275,
1177,
14,
739,
342,
267,
666,
5665,
275,
2022,
14,
3640,
8,
1099,
9,
267,
1212,
25503,
275,
413,
272,
871,
2186,
12,
325,
26,
267,
870,
325,
272,
372,
1212,
25503,
199,
199,
38,
2228,
1484,
5035,
275,
413,
199,
1649,
654,
63,
4609,
63,
38,
29905,
275,
378,
199,
21243,
275,
499,
421,
199,
3,
324,
7207,
4390,
3963,
2793,
1133,
2035,
1265,
14,
199,
318,
625,
7207,
63,
3707,
8,
2184,
63,
633,
29,
403,
12,
1967,
63,
324,
7207,
83,
29,
16,
304,
272,
340,
2163,
63,
633,
508,
488,
26,
267,
1166,
1899,
11398,
275,
298,
2859,
921,
1246,
14,
3615,
32208,
14,
957,
15,
86,
17,
15,
3707,
15,
277,
15,
7207,
83,
31,
2732,
63,
1418,
2458,
83,
2,
450,
334,
1178,
63,
1418,
9,
272,
587,
26,
267,
1166,
1899,
11398,
275,
2163,
63,
633,
339,
1338,
275,
469,
1598,
283,
1258,
63,
344,
7,
520,
1890,
63,
344,
93,
272,
862,
26,
267,
666,
275,
4011,
14,
10738,
8,
1459,
9,
267,
2648,
275,
4011,
18,
14,
2017,
8,
633,
1899,
11398,
12,
403,
12,
2139,
9,
267,
1177,
275,
4011,
18,
14,
10890,
8,
2103,
9,
267,
754,
275,
1177,
14,
739,
342,
267,
666,
5665,
275,
2022,
14,
3640,
8,
1099,
9,
267,
2163,
63,
633,
275,
488,
267,
340,
666,
5665,
14,
362,
360,
22793,
358,
365,
440,
488,
26,
288,
2163,
63,
633,
275,
666,
5665,
14,
362,
360,
22793,
358,
905,
2184,
63,
633,
937,
398,
367,
922,
315,
666,
5665,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aequitas/home-assistant
|
homeassistant/components/epsonworkforce/sensor.py
|
2
|
2653
|
"""Support for Epson Workforce Printer."""
from datetime import timedelta
import logging
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_HOST, CONF_MONITORED_CONDITIONS
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['epsonprinter==0.0.9']
_LOGGER = logging.getLogger(__name__)
MONITORED_CONDITIONS = {
'black': ['Ink level Black', '%', 'mdi:water'],
'photoblack': ['Ink level Photoblack', '%', 'mdi:water'],
'magenta': ['Ink level Magenta', '%', 'mdi:water'],
'cyan': ['Ink level Cyan', '%', 'mdi:water'],
'yellow': ['Ink level Yellow', '%', 'mdi:water'],
'clean': ['Cleaning level', '%', 'mdi:water'],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_MONITORED_CONDITIONS):
vol.All(cv.ensure_list, [vol.In(MONITORED_CONDITIONS)]),
})
SCAN_INTERVAL = timedelta(minutes=60)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the cartridge sensor."""
host = config.get(CONF_HOST)
from epsonprinter_pkg.epsonprinterapi import EpsonPrinterAPI
api = EpsonPrinterAPI(host)
if not api.available:
raise PlatformNotReady()
sensors = [EpsonPrinterCartridge(api, condition)
for condition in config[CONF_MONITORED_CONDITIONS]]
add_devices(sensors, True)
class EpsonPrinterCartridge(Entity):
"""Representation of a cartridge sensor."""
def __init__(self, api, cartridgeidx):
"""Initialize a cartridge sensor."""
self._api = api
self._id = cartridgeidx
self._name = MONITORED_CONDITIONS[self._id][0]
self._unit = MONITORED_CONDITIONS[self._id][1]
self._icon = MONITORED_CONDITIONS[self._id][2]
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def icon(self):
"""Icon to use in the frontend, if any."""
return self._icon
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit
@property
def state(self):
"""Return the state of the device."""
return self._api.getSensorValue(self._id)
@property
def available(self):
"""Could the device be accessed during the last update call."""
return self._api.available
def update(self):
"""Get the latest data from the Epson printer."""
self._api.update()
|
apache-2.0
|
[
624,
11532,
367,
27255,
834,
9361,
3990,
25716,
1058,
1041,
199,
504,
2197,
492,
6871,
199,
646,
2050,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1297,
492,
6392,
63,
5449,
12,
6392,
63,
32387,
25517,
63,
1864,
4150,
199,
504,
8846,
14,
3924,
492,
16078,
1763,
17960,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
199,
29168,
20967,
275,
788,
1545,
834,
11835,
389,
16,
14,
16,
14,
25,
418,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
32387,
25517,
63,
1864,
4150,
275,
469,
272,
283,
8399,
356,
788,
607,
75,
2166,
30593,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
838,
357,
2873,
5143,
356,
788,
607,
75,
2166,
510,
8885,
2873,
5143,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
5615,
21335,
356,
788,
607,
75,
2166,
603,
4054,
65,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
28291,
356,
788,
607,
75,
2166,
18461,
290,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
14514,
356,
788,
607,
75,
2166,
1488,
10723,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
3118,
356,
788,
6580,
316,
2166,
297,
1543,
297,
283,
20208,
26,
17217,
995,
199,
93,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
5449,
304,
6277,
14,
875,
12,
272,
5236,
14,
8030,
8,
3103,
63,
32387,
25517,
63,
1864,
4150,
304,
267,
5236,
14,
2422,
8,
5107,
14,
7505,
63,
513,
12,
359,
5650,
14,
607,
8,
32387,
25517,
63,
1864,
4150,
16636,
199,
1552,
199,
24078,
63,
17359,
275,
6871,
8,
10430,
29,
2259,
9,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
6410,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
16942,
5562,
8778,
1041,
272,
1591,
275,
1101,
14,
362,
8,
3103,
63,
5449,
9,
339,
687,
5442,
834,
11835,
63,
4600,
14,
1545,
834,
2700,
262,
2967,
1038,
492,
27255,
834,
14131,
3735,
272,
2986,
275,
27255,
834,
14131,
3735,
8,
1102,
9,
272,
340,
440,
2986,
14,
4561,
26,
267,
746,
16078,
1763,
17960,
342,
339,
19678,
275,
359,
14057,
834,
14131,
31667,
5562,
8,
1246,
12,
5558,
9,
2049,
367,
5558,
315,
1101,
59,
3103,
63,
32387,
25517,
63,
1864,
4150,
2677,
339,
1050,
63,
6410,
8,
22675,
12,
715,
9,
421,
199,
533,
27255,
834,
14131,
31667,
5562,
8,
7302,
304,
272,
408,
20609,
402,
282,
16942,
5562,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
2986,
12,
16942,
5562,
2996,
304,
267,
408,
9345,
282,
16942,
5562,
8778,
1041,
267,
291,
423,
1246,
275,
2986,
398,
291,
423,
344,
275,
16942,
5562,
2996,
267,
291,
423,
354,
275,
603,
615,
649,
25517,
63,
1864,
4150,
59,
277,
423,
344,
1527,
16,
61,
267,
291,
423,
3248,
275,
603,
615,
649,
25517,
63,
1864,
4150,
59,
277,
423,
344,
1527,
17,
61,
267,
291,
423,
4677,
275,
603,
615,
649,
25517,
63,
1864,
4150,
59,
277,
423,
344,
1527,
18,
61,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
8778,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
7016,
8,
277,
304,
267,
408,
8954,
370,
675,
315,
314,
22523,
12,
340,
1263,
1041,
267,
372,
291,
423,
4677,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
314,
574,
365,
19147,
315,
1041,
267,
372,
291,
423,
3248,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
2243,
1041,
267,
372,
291,
423,
1246,
14,
362,
10160,
1110,
8,
277,
423,
344,
9,
339,
768,
1829,
272,
347,
2808,
8,
277,
304,
267,
408,
6531,
314,
2243,
506,
13810,
5309,
314,
2061,
1678,
1240,
1041,
267,
372,
291,
423,
1246,
14,
4561,
339,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
8839,
666,
687,
314,
27255,
834,
16639,
1041,
267,
291,
423,
1246,
14,
873,
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
] |
[
11532,
367,
27255,
834,
9361,
3990,
25716,
1058,
1041,
199,
504,
2197,
492,
6871,
199,
646,
2050,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1297,
492,
6392,
63,
5449,
12,
6392,
63,
32387,
25517,
63,
1864,
4150,
199,
504,
8846,
14,
3924,
492,
16078,
1763,
17960,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
199,
29168,
20967,
275,
788,
1545,
834,
11835,
389,
16,
14,
16,
14,
25,
418,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
32387,
25517,
63,
1864,
4150,
275,
469,
272,
283,
8399,
356,
788,
607,
75,
2166,
30593,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
838,
357,
2873,
5143,
356,
788,
607,
75,
2166,
510,
8885,
2873,
5143,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
5615,
21335,
356,
788,
607,
75,
2166,
603,
4054,
65,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
28291,
356,
788,
607,
75,
2166,
18461,
290,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
14514,
356,
788,
607,
75,
2166,
1488,
10723,
297,
1543,
297,
283,
20208,
26,
17217,
995,
272,
283,
3118,
356,
788,
6580,
316,
2166,
297,
1543,
297,
283,
20208,
26,
17217,
995,
199,
93,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
5449,
304,
6277,
14,
875,
12,
272,
5236,
14,
8030,
8,
3103,
63,
32387,
25517,
63,
1864,
4150,
304,
267,
5236,
14,
2422,
8,
5107,
14,
7505,
63,
513,
12,
359,
5650,
14,
607,
8,
32387,
25517,
63,
1864,
4150,
16636,
199,
1552,
199,
24078,
63,
17359,
275,
6871,
8,
10430,
29,
2259,
9,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
6410,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
16942,
5562,
8778,
1041,
272,
1591,
275,
1101,
14,
362,
8,
3103,
63,
5449,
9,
339,
687,
5442,
834,
11835,
63,
4600,
14,
1545,
834,
2700,
262,
2967,
1038,
492,
27255,
834,
14131,
3735,
272,
2986,
275,
27255,
834,
14131,
3735,
8,
1102,
9,
272,
340,
440,
2986,
14,
4561,
26,
267,
746,
16078,
1763,
17960,
342,
339,
19678,
275,
359,
14057,
834,
14131,
31667,
5562,
8,
1246,
12,
5558,
9,
2049,
367,
5558,
315,
1101,
59,
3103,
63,
32387,
25517,
63,
1864,
4150,
2677,
339,
1050,
63,
6410,
8,
22675,
12,
715,
9,
421,
199,
533,
27255,
834,
14131,
31667,
5562,
8,
7302,
304,
272,
408,
20609,
402,
282,
16942,
5562,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
2986,
12,
16942,
5562,
2996,
304,
267,
408,
9345,
282,
16942,
5562,
8778,
1041,
267,
291,
423,
1246,
275,
2986,
398,
291,
423,
344,
275,
16942,
5562,
2996,
267,
291,
423,
354,
275,
603,
615,
649,
25517,
63,
1864,
4150,
59,
277,
423,
344,
1527,
16,
61,
267,
291,
423,
3248,
275,
603,
615,
649,
25517,
63,
1864,
4150,
59,
277,
423,
344,
1527,
17,
61,
267,
291,
423,
4677,
275,
603,
615,
649,
25517,
63,
1864,
4150,
59,
277,
423,
344,
1527,
18,
61,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
8778,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
7016,
8,
277,
304,
267,
408,
8954,
370,
675,
315,
314,
22523,
12,
340,
1263,
1041,
267,
372,
291,
423,
4677,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
314,
574,
365,
19147,
315,
1041,
267,
372,
291,
423,
3248,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
2243,
1041,
267,
372,
291,
423,
1246,
14,
362,
10160,
1110,
8,
277,
423,
344,
9,
339,
768,
1829,
272,
347,
2808,
8,
277,
304,
267,
408,
6531,
314,
2243,
506,
13810,
5309,
314,
2061,
1678,
1240,
1041,
267,
372,
291,
423,
1246,
14,
4561,
339,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
8839,
666,
687,
314,
27255,
834,
16639,
1041,
267,
291,
423,
1246,
14,
873,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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# Copyright (c) D.Djokic, 2013
# This code is released under GNU General Public Licence, Version 2
# No Warranties, whatsoever
''' List of functions in "Building Blocks file":
flow(H,A,B) - calculates flow for given Headloss
par_lines(A1, B1,A2, B2) - calculates resultant of parallel connected pipes
ser_lines(A1,B1, A2,B2) - calculates resultant of pipes connected in series
eq_pump (APump,BPump,ASuction,BSuction) - calculates curve of equivalent pump - pump curve minus suction pipe curve
curve_intersection(APump, BPump, APipe, BPipe) - calcultes intersection of two curves - used system curve
and pump curve, result is working point of the system
Q=Intersection[0], Headloss=Intersection[1], Error=Intersection[2]
decomp_serial(Flow, AS1,BS1, AS2,BS2) - calculates Headloss in each of pipes in serial connestion, based on given Headloss
decomp_parallel(Headloss, AP1,BP1, AP2,BP2) - calculates Flow in each of pipes in serial connestion, based on given Headloss
Reynolds(flow, ARe) - calculates Reynolds number for a pipe, and given flow
velocity(flow, Avel) - calculates Velocity of fluid in pipe for given flow
write_res_head_csv(filename) - writes headers of result table in specified file
write_res_num_csv(filename, PipeTag, Flow, Headloss, Reynolds, Velocity)- writes results table to file - one pipe per row
par_flow(Flow, A1, B1, A2,B2)-calculates Flow and Headloss through each pipeline in parallel loop for given total Flow which entering loop
'''
## Note: difference between example1.py and example11.py is in line 86, where par_flow() is called in this script, while in example1.py is called decomp_parallel()
## Results are not the same. Function par_flow() gives correct flow and headloss
import numpy as np
import hydrobb as bb
# HeadlossCoef = A and B coefs in Headloss=A*FLow**2+B
# ReVelCoef = ARe and AVel coef in: Reynolds=ARe*Flow and Velocity=AVel*Flow
inpfilename=raw_input("Input Filename: ")
HeadlossCoef=np.loadtxt(inpfilename, dtype=float, comments="#", delimiter=',', converters=None, skiprows=1, usecols=(1,2), unpack=False, ndmin=0)
ReVelCoef=np.loadtxt(inpfilename, dtype=float, comments="#", delimiter=',', converters=None, skiprows=1, usecols=(3,4), unpack=False, ndmin=0)
outfilename=raw_input("Output Filename: ")
# creating empty arrays to store data
AH=[]
BH=[]
ARe=[]
Avel=[]
npt=len(HeadlossCoef) # total number of pipelines in system
# store input data in python arrays
for element in range (0, npt):
AH.append(HeadlossCoef[element, 0])
BH.append(HeadlossCoef[element,1])
ARe.append(ReVelCoef[element,0])
Avel.append(ReVelCoef[element,1])
# your code/functions calls go below this line
# calculating paralel comp. line
res_par0_1=bb.par_lines(AH[0],BH[0],AH[1],BH[1])
# coefs of paralel comp. curve
AH0_1=res_par0_1[0]
BH0_1=res_par0_1[1]
# calculating serial comp.lines
res_ser2_3=bb.ser_lines(AH[2],BH[2], AH[3],BH[3])
# coef of serial lines
AH2_3=res_ser2_3[0]
BH2_3=res_ser2_3[1]
# calculating whole system curve
total_res=bb.ser_lines(AH0_1,BH0_1, AH2_3,BH2_3)
AHtot=total_res[0]
BHtot=total_res[1]
#calculating working point of the system - pump is curve 4
WP=bb.curve_intersection(AH[4],BH[4], AHtot,BHtot)
QSys=WP[0]
HSys=WP[1]
print(WP)
#rolling back!
# calculating headlosses in loop total_ser Flow=cal[0], HS1=cal[1], HS2=cal[2]
res_tot_ser=bb.decomp_serial(QSys, AH0_1,BH0_1, AH2_3,BH2_3)
Qres_tot=res_tot_ser[0]
H0_1=res_tot_ser[1]
H2_3=res_tot_ser[2]
Q=[]
H=[]
#calculating headlosses in loop res_ser2_3
loop_ser2_3=bb.decomp_serial(Qres_tot,AH[2],BH[2], AH[3],BH[3])
Q.append(loop_ser2_3[0])
H.append(loop_ser2_3[1])
Q.append(loop_ser2_3[0])
H.append(loop_ser2_3[2])
#calculating flows in loop res_par0_1
#loop_par0_1=bb.decomp_parallel(H0_1, AH[0],BH[0], AH[1],BH[1])
loop_par0_1=bb.par_flow(loop_ser2_3[0], AH[0],BH[0], AH[1],BH[1])
Q.append(loop_par0_1[0])
H.append(loop_par0_1[1])
Q.append(loop_par0_1[2])
H.append(loop_par0_1[3])
# writting results
bb.write_res_head_csv(outfilename)
for i in range(0,4):
bb.write_res_num_csv(outfilename, str(i), Q[i], H[i], 0, 0)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
15232,
570,
446,
2195,
15232,
1233,
17262,
5084,
1004,
14106,
14,
10416,
199,
3,
1898,
334,
67,
9,
577,
14,
36,
743,
75,
530,
12,
6171,
199,
3,
961,
1233,
365,
14286,
1334,
1664,
1696,
1684,
491,
530,
4894,
12,
3394,
499,
199,
3,
3091,
644,
285,
1312,
1417,
12,
4052,
1152,
5907,
199,
199,
2344,
3820,
402,
3423,
315,
298,
16461,
8651,
83,
570,
582,
199,
1659,
8,
40,
12,
33,
12,
34,
9,
446,
6966,
2335,
6369,
367,
1627,
5311,
350,
4358,
199,
462,
63,
1278,
8,
33,
17,
12,
699,
17,
12,
33,
18,
12,
699,
18,
9,
446,
6966,
2335,
754,
867,
402,
9861,
8539,
20988,
199,
332,
63,
1278,
8,
33,
17,
12,
34,
17,
12,
437,
18,
12,
34,
18,
9,
446,
6966,
2335,
754,
867,
402,
20988,
8539,
315,
6779,
199,
4077,
63,
29547,
334,
1282,
1220,
12,
24408,
1220,
12,
1179,
85,
414,
12,
11087,
85,
414,
9,
446,
6966,
2335,
15318,
402,
7353,
31741,
446,
31741,
15318,
21357,
18741,
414,
5200,
15318,
199,
11895,
63,
12569,
8,
1282,
1220,
12,
699,
48,
1220,
12,
10319,
3662,
12,
699,
11867,
9,
446,
6966,
744,
16223,
402,
2877,
1094,
2310,
446,
1202,
2656,
15318,
221,
5264,
27997,
198,
460,
31741,
15318,
12,
754,
365,
6449,
2376,
402,
314,
2656,
5264,
27997,
198,
49,
29,
29821,
59,
16,
467,
5311,
350,
4358,
29,
29821,
59,
17,
467,
4520,
29,
29821,
59,
18,
61,
199,
271,
863,
63,
2171,
8,
5060,
12,
4319,
17,
12,
11087,
17,
12,
4319,
18,
12,
11087,
18,
9,
446,
6966,
2335,
5311,
350,
4358,
315,
1924,
402,
20988,
315,
3012,
2557,
597,
1636,
12,
4079,
641,
1627,
5311,
350,
4358,
199,
271,
863,
63,
11887,
8,
11664,
4358,
12,
10319,
17,
12,
24408,
17,
12,
10319,
18,
12,
24408,
18,
9,
446,
6966,
2335,
20823,
315,
1924,
402,
20988,
315,
3012,
2557,
597,
1636,
12,
4079,
641,
1627,
5311,
350,
4358,
199,
497,
1236,
8250,
8,
1659,
12,
437,
497,
9,
446,
6966,
2335,
799,
1236,
8250,
1329,
367,
282,
5200,
12,
436,
1627,
6369,
199,
16350,
8,
1659,
12,
437,
1090,
9,
446,
6966,
2335,
25777,
14284,
402,
25462,
315,
5200,
367,
1627,
6369,
199,
952,
63,
470,
63,
2993,
63,
4737,
8,
1501,
9,
446,
14511,
2323,
402,
754,
1817,
315,
2013,
570,
199,
952,
63,
470,
63,
1507,
63,
4737,
8,
1501,
12,
16850,
1931,
12,
20823,
12,
5311,
350,
4358,
12,
799,
1236,
8250,
12,
25777,
14284,
7216,
14511,
2058,
1817,
370,
570,
446,
1373,
5200,
1126,
1962,
199,
462,
63,
1659,
8,
5060,
12,
437,
17,
12,
699,
17,
12,
437,
18,
12,
34,
18,
7216,
13494,
2335,
20823,
436,
5311,
350,
4358,
4012,
1924,
7679,
315,
9861,
4438,
367,
1627,
3141,
20823,
1314,
9509,
316,
4438,
199,
2344,
199,
309,
3390,
26,
8865,
3382,
2893,
17,
14,
647,
436,
2893,
845,
14,
647,
365,
315,
1004,
10300,
12,
2382,
623,
63,
1659,
342,
365,
2797,
315,
642,
2884,
12,
1830,
315,
2893,
17,
14,
647,
365,
2797,
477,
863,
63,
11887,
342,
199,
309,
24288,
787,
440,
314,
2011,
14,
6801,
623,
63,
1659,
342,
10557,
3211,
6369,
436,
4854,
4358,
199,
646,
2680,
465,
980,
199,
646,
7188,
17264,
2501,
465,
14027,
199,
3,
5311,
350,
4358,
967,
2829,
275,
437,
436,
699,
29879,
315,
5311,
350,
4358,
29,
33,
10,
3143,
583,
538,
18,
11,
34,
199,
3,
799,
54,
352,
967,
2829,
275,
437,
497,
436,
437,
54,
352,
7355,
315,
26,
799,
1236,
8250,
29,
33,
497,
10,
5060,
436,
25777,
14284,
29,
6087,
352,
10,
5060,
199,
11416,
1501,
29,
1773,
63,
1210,
480,
3205,
31167,
26,
6099,
199,
11664,
4358,
967,
2829,
29,
1590,
14,
27992,
8,
11416,
1501,
12,
2152,
29,
1609,
12,
6786,
13476,
401,
11172,
4009,
297,
23172,
29,
403,
12,
2386,
73,
496,
3569,
29,
17,
12,
675,
4574,
2687,
17,
12,
18,
395,
7787,
29,
797,
12,
5222,
827,
29,
16,
9,
199,
497,
54,
352,
967,
2829,
29,
1590,
14,
27992,
8,
11416,
1501,
12,
2152,
29,
1609,
12,
6786,
13476,
401,
11172,
4009,
297,
23172,
29,
403,
12,
2386,
73,
496,
3569,
29,
17,
12,
675,
4574,
2687,
19,
12,
20,
395,
7787,
29,
797,
12,
5222,
827,
29,
16,
9,
199,
548,
1501,
29,
1773,
63,
1210,
480,
2959,
31167,
26,
6099,
199,
199,
3,
6425,
2701,
6572,
370,
3877,
666,
199,
20755,
9811,
199,
29931,
9811,
199,
33,
497,
9811,
199,
33,
1090,
9811,
199,
78,
541,
29,
552,
8,
11664,
4358,
967,
2829,
9,
221,
327,
3141,
1329,
402,
5200,
1278,
315,
2656,
199,
199,
3,
3877,
1324,
666,
315,
2366,
6572,
199,
509,
1819,
315,
1425,
334,
16,
12,
29340,
304,
199,
198,
20755,
14,
740,
8,
11664,
4358,
967,
2829,
59,
2108,
12,
378,
566,
199,
198,
29931,
14,
740,
8,
11664,
4358,
967,
2829,
59,
2108,
12,
17,
566,
199,
198,
33,
497,
14,
740,
8,
497,
54,
352,
967,
2829,
59,
2108,
12,
16,
566,
199,
198,
33,
1090,
14,
740,
8,
497,
54,
352,
967,
2829,
59,
2108,
12,
17,
566,
199,
199,
3,
2195,
1233,
15,
5777,
4882,
2621,
5084,
642,
1004,
199,
199,
3,
26079,
623,
1895,
76,
1013,
14,
1004,
199,
470,
63,
462,
16,
63,
17,
29,
2501,
14,
462,
63,
1278,
8,
20755,
59,
16,
467,
29931,
59,
16,
467,
20755,
59,
17,
467,
29931,
59,
17,
566,
199,
3,
29879,
402,
623,
1895,
76,
1013,
14,
15318,
199,
20755,
16,
63,
17,
29,
470,
63,
462,
16,
63,
17,
59,
16,
61,
199,
29931,
16,
63,
17,
29,
470,
63,
462,
16,
63,
17,
59,
17,
61,
199,
199,
3,
26079,
3012,
1013,
14,
1278,
199,
470,
63,
332,
18,
63,
19,
29,
2501,
14,
332,
63,
1278,
8,
20755,
59,
18,
467,
29931,
59,
18,
467,
437,
40,
59,
19,
467,
29931,
59,
19,
566,
199,
3,
7355,
402,
3012,
2385,
199,
20755,
18,
63,
19,
29,
470,
63,
332,
18,
63,
19,
59,
16,
61,
199,
29931,
18,
63,
19,
29,
470,
63,
332,
18,
63,
19,
59,
17
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
15232,
570,
446,
2195,
15232,
1233,
17262,
5084,
1004,
14106,
14,
10416,
199,
3,
1898,
334,
67,
9,
577,
14,
36,
743,
75,
530,
12,
6171,
199,
3,
961,
1233,
365,
14286,
1334,
1664,
1696,
1684,
491,
530,
4894,
12,
3394,
499,
199,
3,
3091,
644,
285,
1312,
1417,
12,
4052,
1152,
5907,
199,
199,
2344,
3820,
402,
3423,
315,
298,
16461,
8651,
83,
570,
582,
199,
1659,
8,
40,
12,
33,
12,
34,
9,
446,
6966,
2335,
6369,
367,
1627,
5311,
350,
4358,
199,
462,
63,
1278,
8,
33,
17,
12,
699,
17,
12,
33,
18,
12,
699,
18,
9,
446,
6966,
2335,
754,
867,
402,
9861,
8539,
20988,
199,
332,
63,
1278,
8,
33,
17,
12,
34,
17,
12,
437,
18,
12,
34,
18,
9,
446,
6966,
2335,
754,
867,
402,
20988,
8539,
315,
6779,
199,
4077,
63,
29547,
334,
1282,
1220,
12,
24408,
1220,
12,
1179,
85,
414,
12,
11087,
85,
414,
9,
446,
6966,
2335,
15318,
402,
7353,
31741,
446,
31741,
15318,
21357,
18741,
414,
5200,
15318,
199,
11895,
63,
12569,
8,
1282,
1220,
12,
699,
48,
1220,
12,
10319,
3662,
12,
699,
11867,
9,
446,
6966,
744,
16223,
402,
2877,
1094,
2310,
446,
1202,
2656,
15318,
221,
5264,
27997,
198,
460,
31741,
15318,
12,
754,
365,
6449,
2376,
402,
314,
2656,
5264,
27997,
198,
49,
29,
29821,
59,
16,
467,
5311,
350,
4358,
29,
29821,
59,
17,
467,
4520,
29,
29821,
59,
18,
61,
199,
271,
863,
63,
2171,
8,
5060,
12,
4319,
17,
12,
11087,
17,
12,
4319,
18,
12,
11087,
18,
9,
446,
6966,
2335,
5311,
350,
4358,
315,
1924,
402,
20988,
315,
3012,
2557,
597,
1636,
12,
4079,
641,
1627,
5311,
350,
4358,
199,
271,
863,
63,
11887,
8,
11664,
4358,
12,
10319,
17,
12,
24408,
17,
12,
10319,
18,
12,
24408,
18,
9,
446,
6966,
2335,
20823,
315,
1924,
402,
20988,
315,
3012,
2557,
597,
1636,
12,
4079,
641,
1627,
5311,
350,
4358,
199,
497,
1236,
8250,
8,
1659,
12,
437,
497,
9,
446,
6966,
2335,
799,
1236,
8250,
1329,
367,
282,
5200,
12,
436,
1627,
6369,
199,
16350,
8,
1659,
12,
437,
1090,
9,
446,
6966,
2335,
25777,
14284,
402,
25462,
315,
5200,
367,
1627,
6369,
199,
952,
63,
470,
63,
2993,
63,
4737,
8,
1501,
9,
446,
14511,
2323,
402,
754,
1817,
315,
2013,
570,
199,
952,
63,
470,
63,
1507,
63,
4737,
8,
1501,
12,
16850,
1931,
12,
20823,
12,
5311,
350,
4358,
12,
799,
1236,
8250,
12,
25777,
14284,
7216,
14511,
2058,
1817,
370,
570,
446,
1373,
5200,
1126,
1962,
199,
462,
63,
1659,
8,
5060,
12,
437,
17,
12,
699,
17,
12,
437,
18,
12,
34,
18,
7216,
13494,
2335,
20823,
436,
5311,
350,
4358,
4012,
1924,
7679,
315,
9861,
4438,
367,
1627,
3141,
20823,
1314,
9509,
316,
4438,
199,
2344,
199,
309,
3390,
26,
8865,
3382,
2893,
17,
14,
647,
436,
2893,
845,
14,
647,
365,
315,
1004,
10300,
12,
2382,
623,
63,
1659,
342,
365,
2797,
315,
642,
2884,
12,
1830,
315,
2893,
17,
14,
647,
365,
2797,
477,
863,
63,
11887,
342,
199,
309,
24288,
787,
440,
314,
2011,
14,
6801,
623,
63,
1659,
342,
10557,
3211,
6369,
436,
4854,
4358,
199,
646,
2680,
465,
980,
199,
646,
7188,
17264,
2501,
465,
14027,
199,
3,
5311,
350,
4358,
967,
2829,
275,
437,
436,
699,
29879,
315,
5311,
350,
4358,
29,
33,
10,
3143,
583,
538,
18,
11,
34,
199,
3,
799,
54,
352,
967,
2829,
275,
437,
497,
436,
437,
54,
352,
7355,
315,
26,
799,
1236,
8250,
29,
33,
497,
10,
5060,
436,
25777,
14284,
29,
6087,
352,
10,
5060,
199,
11416,
1501,
29,
1773,
63,
1210,
480,
3205,
31167,
26,
6099,
199,
11664,
4358,
967,
2829,
29,
1590,
14,
27992,
8,
11416,
1501,
12,
2152,
29,
1609,
12,
6786,
13476,
401,
11172,
4009,
297,
23172,
29,
403,
12,
2386,
73,
496,
3569,
29,
17,
12,
675,
4574,
2687,
17,
12,
18,
395,
7787,
29,
797,
12,
5222,
827,
29,
16,
9,
199,
497,
54,
352,
967,
2829,
29,
1590,
14,
27992,
8,
11416,
1501,
12,
2152,
29,
1609,
12,
6786,
13476,
401,
11172,
4009,
297,
23172,
29,
403,
12,
2386,
73,
496,
3569,
29,
17,
12,
675,
4574,
2687,
19,
12,
20,
395,
7787,
29,
797,
12,
5222,
827,
29,
16,
9,
199,
548,
1501,
29,
1773,
63,
1210,
480,
2959,
31167,
26,
6099,
199,
199,
3,
6425,
2701,
6572,
370,
3877,
666,
199,
20755,
9811,
199,
29931,
9811,
199,
33,
497,
9811,
199,
33,
1090,
9811,
199,
78,
541,
29,
552,
8,
11664,
4358,
967,
2829,
9,
221,
327,
3141,
1329,
402,
5200,
1278,
315,
2656,
199,
199,
3,
3877,
1324,
666,
315,
2366,
6572,
199,
509,
1819,
315,
1425,
334,
16,
12,
29340,
304,
199,
198,
20755,
14,
740,
8,
11664,
4358,
967,
2829,
59,
2108,
12,
378,
566,
199,
198,
29931,
14,
740,
8,
11664,
4358,
967,
2829,
59,
2108,
12,
17,
566,
199,
198,
33,
497,
14,
740,
8,
497,
54,
352,
967,
2829,
59,
2108,
12,
16,
566,
199,
198,
33,
1090,
14,
740,
8,
497,
54,
352,
967,
2829,
59,
2108,
12,
17,
566,
199,
199,
3,
2195,
1233,
15,
5777,
4882,
2621,
5084,
642,
1004,
199,
199,
3,
26079,
623,
1895,
76,
1013,
14,
1004,
199,
470,
63,
462,
16,
63,
17,
29,
2501,
14,
462,
63,
1278,
8,
20755,
59,
16,
467,
29931,
59,
16,
467,
20755,
59,
17,
467,
29931,
59,
17,
566,
199,
3,
29879,
402,
623,
1895,
76,
1013,
14,
15318,
199,
20755,
16,
63,
17,
29,
470,
63,
462,
16,
63,
17,
59,
16,
61,
199,
29931,
16,
63,
17,
29,
470,
63,
462,
16,
63,
17,
59,
17,
61,
199,
199,
3,
26079,
3012,
1013,
14,
1278,
199,
470,
63,
332,
18,
63,
19,
29,
2501,
14,
332,
63,
1278,
8,
20755,
59,
18,
467,
29931,
59,
18,
467,
437,
40,
59,
19,
467,
29931,
59,
19,
566,
199,
3,
7355,
402,
3012,
2385,
199,
20755,
18,
63,
19,
29,
470,
63,
332,
18,
63,
19,
59,
16,
61,
199,
29931,
18,
63,
19,
29,
470,
63,
332,
18,
63,
19,
59,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ossdemura/django-miniblog
|
src/Lib/site-packages/pip/_vendor/html5lib/filters/whitespace.py
|
353
|
1139
|
from __future__ import absolute_import, division, unicode_literals
import re
from . import base
from ..constants import rcdataElements, spaceCharacters
spaceCharacters = "".join(spaceCharacters)
SPACES_REGEX = re.compile("[%s]+" % spaceCharacters)
class Filter(base.Filter):
spacePreserveElements = frozenset(["pre", "textarea"] + list(rcdataElements))
def __iter__(self):
preserve = 0
for token in base.Filter.__iter__(self):
type = token["type"]
if type == "StartTag" \
and (preserve or token["name"] in self.spacePreserveElements):
preserve += 1
elif type == "EndTag" and preserve:
preserve -= 1
elif not preserve and type == "SpaceCharacters" and token["data"]:
# Test on token["data"] above to not introduce spaces where there were not
token["data"] = " "
elif not preserve and type == "Characters":
token["data"] = collapse_spaces(token["data"])
yield token
def collapse_spaces(text):
return SPACES_REGEX.sub(' ', text)
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
492,
1300,
199,
504,
2508,
5559,
492,
4819,
576,
6255,
12,
25431,
199,
2638,
9272,
275,
10587,
904,
8,
2638,
9272,
9,
199,
199,
5763,
21287,
63,
10710,
275,
295,
14,
2014,
480,
9722,
83,
2807,
2,
450,
25431,
9,
421,
199,
533,
9388,
8,
1095,
14,
4131,
304,
339,
4601,
2398,
4909,
6255,
275,
9522,
5234,
657,
401,
298,
20895,
937,
435,
769,
8,
1195,
576,
6255,
430,
339,
347,
636,
1661,
721,
277,
304,
267,
11211,
275,
378,
267,
367,
1526,
315,
1300,
14,
4131,
855,
1661,
721,
277,
304,
288,
730,
275,
1526,
905,
466,
937,
288,
340,
730,
508,
298,
17697,
2,
971,
490,
436,
334,
17053,
503,
1526,
905,
354,
937,
315,
291,
14,
2638,
2398,
4909,
6255,
304,
355,
11211,
847,
413,
953,
916,
730,
508,
298,
16906,
2,
436,
11211,
26,
355,
11211,
4862,
413,
953,
916,
440,
11211,
436,
730,
508,
298,
28501,
2,
436,
1526,
905,
576,
6229,
355,
327,
1379,
641,
1526,
905,
576,
937,
3432,
370,
440,
13318,
3402,
7883,
2382,
2337,
4898,
440,
355,
1526,
905,
576,
937,
275,
298,
298,
953,
916,
440,
11211,
436,
730,
508,
298,
9272,
582,
355,
1526,
905,
576,
937,
275,
24311,
63,
10749,
8,
1418,
905,
576,
3135,
953,
1995,
1526,
421,
199,
318,
24311,
63,
10749,
8,
505,
304,
272,
372,
6988,
21287,
63,
10710,
14,
954,
360,
1656,
1318,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
492,
1300,
199,
504,
2508,
5559,
492,
4819,
576,
6255,
12,
25431,
199,
2638,
9272,
275,
10587,
904,
8,
2638,
9272,
9,
199,
199,
5763,
21287,
63,
10710,
275,
295,
14,
2014,
480,
9722,
83,
2807,
2,
450,
25431,
9,
421,
199,
533,
9388,
8,
1095,
14,
4131,
304,
339,
4601,
2398,
4909,
6255,
275,
9522,
5234,
657,
401,
298,
20895,
937,
435,
769,
8,
1195,
576,
6255,
430,
339,
347,
636,
1661,
721,
277,
304,
267,
11211,
275,
378,
267,
367,
1526,
315,
1300,
14,
4131,
855,
1661,
721,
277,
304,
288,
730,
275,
1526,
905,
466,
937,
288,
340,
730,
508,
298,
17697,
2,
971,
490,
436,
334,
17053,
503,
1526,
905,
354,
937,
315,
291,
14,
2638,
2398,
4909,
6255,
304,
355,
11211,
847,
413,
953,
916,
730,
508,
298,
16906,
2,
436,
11211,
26,
355,
11211,
4862,
413,
953,
916,
440,
11211,
436,
730,
508,
298,
28501,
2,
436,
1526,
905,
576,
6229,
355,
327,
1379,
641,
1526,
905,
576,
937,
3432,
370,
440,
13318,
3402,
7883,
2382,
2337,
4898,
440,
355,
1526,
905,
576,
937,
275,
298,
298,
953,
916,
440,
11211,
436,
730,
508,
298,
9272,
582,
355,
1526,
905,
576,
937,
275,
24311,
63,
10749,
8,
1418,
905,
576,
3135,
953,
1995,
1526,
421,
199,
318,
24311,
63,
10749,
8,
505,
304,
272,
372,
6988,
21287,
63,
10710,
14,
954,
360,
1656,
1318,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
creativcoder/servo
|
tests/wpt/harness/wptrunner/tests/test_chunker.py
|
59
|
2807
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import unittest
import sys
from os.path import join, dirname
from mozlog import structured
import pytest
sys.path.insert(0, join(dirname(__file__), "..", ".."))
from wptrunner.testloader import EqualTimeChunker
structured.set_default_logger(structured.structuredlog.StructuredLogger("TestChunker"))
class MockTest(object):
def __init__(self, id, timeout=10):
self.id = id
self.item_type = "testharness"
self.timeout = timeout
def make_mock_manifest(*items):
rv = []
for dir_path, num_tests in items:
for i in range(num_tests):
rv.append((dir_path + "/%i.test" % i, set([MockTest(i)])))
return rv
class TestEqualTimeChunker(unittest.TestCase):
def test_include_all(self):
tests = make_mock_manifest(("a", 10), ("a/b", 10), ("c", 10))
chunk_1 = list(EqualTimeChunker(3, 1)(tests))
chunk_2 = list(EqualTimeChunker(3, 2)(tests))
chunk_3 = list(EqualTimeChunker(3, 3)(tests))
self.assertEquals(tests[:10], chunk_1)
self.assertEquals(tests[10:20], chunk_2)
self.assertEquals(tests[20:], chunk_3)
def test_include_all_1(self):
tests = make_mock_manifest(("a", 5), ("a/b", 5), ("c", 10), ("d", 10))
chunk_1 = list(EqualTimeChunker(3, 1)(tests))
chunk_2 = list(EqualTimeChunker(3, 2)(tests))
chunk_3 = list(EqualTimeChunker(3, 3)(tests))
self.assertEquals(tests[:10], chunk_1)
self.assertEquals(tests[10:20], chunk_2)
self.assertEquals(tests[20:], chunk_3)
def test_long(self):
tests = make_mock_manifest(("a", 100), ("a/b", 1), ("c", 1))
chunk_1 = list(EqualTimeChunker(3, 1)(tests))
chunk_2 = list(EqualTimeChunker(3, 2)(tests))
chunk_3 = list(EqualTimeChunker(3, 3)(tests))
self.assertEquals(tests[:100], chunk_1)
self.assertEquals(tests[100:101], chunk_2)
self.assertEquals(tests[101:102], chunk_3)
def test_long_1(self):
tests = make_mock_manifest(("a", 1), ("a/b", 100), ("c", 1))
chunk_1 = list(EqualTimeChunker(3, 1)(tests))
chunk_2 = list(EqualTimeChunker(3, 2)(tests))
chunk_3 = list(EqualTimeChunker(3, 3)(tests))
self.assertEquals(tests[:1], chunk_1)
self.assertEquals(tests[1:101], chunk_2)
self.assertEquals(tests[101:102], chunk_3)
def test_too_few_dirs(self):
with self.assertRaises(ValueError):
tests = make_mock_manifest(("a", 1), ("a/b", 100), ("c", 1))
list(EqualTimeChunker(4, 1)(tests))
if __name__ == "__main__":
unittest.main()
|
mpl-2.0
|
[
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
2882,
199,
646,
984,
199,
504,
747,
14,
515,
492,
4263,
12,
9017,
199,
504,
1303,
90,
793,
492,
21781,
199,
199,
646,
4613,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
4263,
8,
3475,
3460,
493,
10139,
21777,
401,
21777,
2237,
199,
199,
504,
336,
4695,
324,
1372,
14,
396,
3422,
492,
221,
591,
1366,
9856,
281,
199,
199,
15774,
14,
409,
63,
885,
63,
2921,
8,
15774,
14,
15774,
793,
14,
27486,
4455,
480,
774,
9856,
281,
2237,
199,
199,
533,
4420,
774,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1305,
12,
2653,
29,
709,
304,
267,
291,
14,
344,
275,
1305,
267,
291,
14,
1053,
63,
466,
275,
298,
396,
23569,
2,
267,
291,
14,
2593,
275,
2653,
421,
199,
318,
1852,
63,
1805,
63,
6418,
2031,
1744,
304,
272,
4336,
275,
942,
272,
367,
2935,
63,
515,
12,
1967,
63,
2219,
315,
2974,
26,
267,
367,
284,
315,
1425,
8,
1507,
63,
2219,
304,
288,
4336,
14,
740,
1332,
694,
63,
515,
435,
298,
3149,
73,
14,
396,
2,
450,
284,
12,
663,
779,
3346,
774,
8,
73,
1874,
1724,
272,
372,
4336,
421,
199,
533,
1379,
591,
1366,
9856,
281,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
2613,
63,
452,
8,
277,
304,
267,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
1616,
395,
1689,
65,
15,
66,
401,
1616,
395,
1689,
67,
401,
1616,
430,
398,
3728,
63,
17,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
413,
5130,
2219,
430,
267,
3728,
63,
18,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
499,
5130,
2219,
430,
267,
3728,
63,
19,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
650,
5130,
2219,
430,
398,
291,
14,
2947,
8,
2219,
1491,
709,
467,
3728,
63,
17,
9,
267,
291,
14,
2947,
8,
2219,
59,
709,
26,
1165,
467,
3728,
63,
18,
9,
267,
291,
14,
2947,
8,
2219,
59,
1165,
8429,
3728,
63,
19,
9,
339,
347,
511,
63,
2613,
63,
452,
63,
17,
8,
277,
304,
267,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
959,
395,
1689,
65,
15,
66,
401,
959,
395,
1689,
67,
401,
1616,
395,
1689,
68,
401,
1616,
430,
398,
3728,
63,
17,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
413,
5130,
2219,
430,
267,
3728,
63,
18,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
499,
5130,
2219,
430,
267,
3728,
63,
19,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
650,
5130,
2219,
430,
398,
291,
14,
2947,
8,
2219,
1491,
709,
467,
3728,
63,
17,
9,
267,
291,
14,
2947,
8,
2219,
59,
709,
26,
1165,
467,
3728,
63,
18,
9,
267,
291,
14,
2947,
8,
2219,
59,
1165,
8429,
3728,
63,
19,
9,
339,
347,
511,
63,
2809,
8,
277,
304,
267,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
2948,
395,
1689,
65,
15,
66,
401,
413,
395,
1689,
67,
401,
413,
430,
398,
3728,
63,
17,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
413,
5130,
2219,
430,
267,
3728,
63,
18,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
499,
5130,
2219,
430,
267,
3728,
63,
19,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
650,
5130,
2219,
430,
398,
291,
14,
2947,
8,
2219,
1491,
1960,
467,
3728,
63,
17,
9,
267,
291,
14,
2947,
8,
2219,
59,
1960,
26,
4893,
467,
3728,
63,
18,
9,
267,
291,
14,
2947,
8,
2219,
59,
4893,
26,
7759,
467,
3728,
63,
19,
9,
339,
347,
511,
63,
2809,
63,
17,
8,
277,
304,
267,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
413,
395,
1689,
65,
15,
66,
401,
2948,
395,
1689,
67,
401,
413,
430,
398,
3728,
63,
17,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
413,
5130,
2219,
430,
267,
3728,
63,
18,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
499,
5130,
2219,
430,
267,
3728,
63,
19,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
650,
5130,
2219,
430,
398,
291,
14,
2947,
8,
2219,
1491,
17,
467,
3728,
63,
17,
9,
267,
291,
14,
2947,
8,
2219,
59,
17,
26,
4893,
467,
3728,
63,
18,
9,
267,
291,
14,
2947,
8,
2219,
59,
4893,
26,
7759,
467,
3728,
63,
19,
9,
339,
347,
511,
63,
7354,
63,
70,
546,
63,
3220,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
413,
395,
1689,
65,
15,
66,
401,
2948,
395,
1689,
67,
401,
413,
430,
288,
769,
8,
591,
1366,
9856,
281,
8,
20,
12,
413,
5130,
2219,
430,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
2882,
199,
646,
984,
199,
504,
747,
14,
515,
492,
4263,
12,
9017,
199,
504,
1303,
90,
793,
492,
21781,
199,
199,
646,
4613,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
4263,
8,
3475,
3460,
493,
10139,
21777,
401,
21777,
2237,
199,
199,
504,
336,
4695,
324,
1372,
14,
396,
3422,
492,
221,
591,
1366,
9856,
281,
199,
199,
15774,
14,
409,
63,
885,
63,
2921,
8,
15774,
14,
15774,
793,
14,
27486,
4455,
480,
774,
9856,
281,
2237,
199,
199,
533,
4420,
774,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1305,
12,
2653,
29,
709,
304,
267,
291,
14,
344,
275,
1305,
267,
291,
14,
1053,
63,
466,
275,
298,
396,
23569,
2,
267,
291,
14,
2593,
275,
2653,
421,
199,
318,
1852,
63,
1805,
63,
6418,
2031,
1744,
304,
272,
4336,
275,
942,
272,
367,
2935,
63,
515,
12,
1967,
63,
2219,
315,
2974,
26,
267,
367,
284,
315,
1425,
8,
1507,
63,
2219,
304,
288,
4336,
14,
740,
1332,
694,
63,
515,
435,
298,
3149,
73,
14,
396,
2,
450,
284,
12,
663,
779,
3346,
774,
8,
73,
1874,
1724,
272,
372,
4336,
421,
199,
533,
1379,
591,
1366,
9856,
281,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
2613,
63,
452,
8,
277,
304,
267,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
1616,
395,
1689,
65,
15,
66,
401,
1616,
395,
1689,
67,
401,
1616,
430,
398,
3728,
63,
17,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
413,
5130,
2219,
430,
267,
3728,
63,
18,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
499,
5130,
2219,
430,
267,
3728,
63,
19,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
650,
5130,
2219,
430,
398,
291,
14,
2947,
8,
2219,
1491,
709,
467,
3728,
63,
17,
9,
267,
291,
14,
2947,
8,
2219,
59,
709,
26,
1165,
467,
3728,
63,
18,
9,
267,
291,
14,
2947,
8,
2219,
59,
1165,
8429,
3728,
63,
19,
9,
339,
347,
511,
63,
2613,
63,
452,
63,
17,
8,
277,
304,
267,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
959,
395,
1689,
65,
15,
66,
401,
959,
395,
1689,
67,
401,
1616,
395,
1689,
68,
401,
1616,
430,
398,
3728,
63,
17,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
413,
5130,
2219,
430,
267,
3728,
63,
18,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
499,
5130,
2219,
430,
267,
3728,
63,
19,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
650,
5130,
2219,
430,
398,
291,
14,
2947,
8,
2219,
1491,
709,
467,
3728,
63,
17,
9,
267,
291,
14,
2947,
8,
2219,
59,
709,
26,
1165,
467,
3728,
63,
18,
9,
267,
291,
14,
2947,
8,
2219,
59,
1165,
8429,
3728,
63,
19,
9,
339,
347,
511,
63,
2809,
8,
277,
304,
267,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
2948,
395,
1689,
65,
15,
66,
401,
413,
395,
1689,
67,
401,
413,
430,
398,
3728,
63,
17,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
413,
5130,
2219,
430,
267,
3728,
63,
18,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
499,
5130,
2219,
430,
267,
3728,
63,
19,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
650,
5130,
2219,
430,
398,
291,
14,
2947,
8,
2219,
1491,
1960,
467,
3728,
63,
17,
9,
267,
291,
14,
2947,
8,
2219,
59,
1960,
26,
4893,
467,
3728,
63,
18,
9,
267,
291,
14,
2947,
8,
2219,
59,
4893,
26,
7759,
467,
3728,
63,
19,
9,
339,
347,
511,
63,
2809,
63,
17,
8,
277,
304,
267,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
413,
395,
1689,
65,
15,
66,
401,
2948,
395,
1689,
67,
401,
413,
430,
398,
3728,
63,
17,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
413,
5130,
2219,
430,
267,
3728,
63,
18,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
499,
5130,
2219,
430,
267,
3728,
63,
19,
275,
769,
8,
591,
1366,
9856,
281,
8,
19,
12,
650,
5130,
2219,
430,
398,
291,
14,
2947,
8,
2219,
1491,
17,
467,
3728,
63,
17,
9,
267,
291,
14,
2947,
8,
2219,
59,
17,
26,
4893,
467,
3728,
63,
18,
9,
267,
291,
14,
2947,
8,
2219,
59,
4893,
26,
7759,
467,
3728,
63,
19,
9,
339,
347,
511,
63,
7354,
63,
70,
546,
63,
3220,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
2295,
275,
1852,
63,
1805,
63,
6418,
9313,
65,
401,
413,
395,
1689,
65,
15,
66,
401,
2948,
395,
1689,
67,
401,
413,
430,
288,
769,
8,
591,
1366,
9856,
281,
8,
20,
12,
413,
5130,
2219,
430,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
|
10080
|
# coding: utf8
{
'!langcode!': 'zh-tw',
'!langname!': '中文',
'"update" is an optional expression like "field1=\'newvalue\'". You cannot update or delete the results of a JOIN': '"更新" 是選擇性的條件式, 格式就像 "欄位1=\'值\'". 但是 JOIN 的資料不可以使用 update 或是 delete"',
'%s %%{row} deleted': '已刪除 %s 筆',
'%s %%{row} updated': '已更新 %s 筆',
'%s selected': '%s 已選擇',
'%Y-%m-%d': '%Y-%m-%d',
'%Y-%m-%d %H:%M:%S': '%Y-%m-%d %H:%M:%S',
'(something like "it-it")': '(格式類似 "zh-tw")',
'A new version of web2py is available': '新版的 web2py 已發行',
'A new version of web2py is available: %s': '新版的 web2py 已發行: %s',
'about': '關於',
'About': '關於',
'About application': '關於本應用程式',
'Access Control': 'Access Control',
'Admin is disabled because insecure channel': '管理功能(Admin)在不安全連線環境下自動關閉',
'Admin is disabled because unsecure channel': '管理功能(Admin)在不安全連線環境下自動關閉',
'Administrative Interface': 'Administrative Interface',
'Administrative interface': '點此處進入管理介面',
'Administrator Password:': '管理員密碼:',
'Ajax Recipes': 'Ajax Recipes',
'appadmin is disabled because insecure channel': '因為來自非安全通道,管理介面關閉',
'Are you sure you want to delete file "%s"?': '確定要刪除檔案"%s"?',
'Are you sure you want to delete this object?': 'Are you sure you want to delete this object?',
'Are you sure you want to uninstall application "%s"': '確定要移除應用程式 "%s"',
'Are you sure you want to uninstall application "%s"?': '確定要移除應用程式 "%s"',
'ATTENTION: Login requires a secure (HTTPS) connection or running on localhost.': '注意: 登入管理帳號需要安全連線(HTTPS)或是在本機連線(localhost).',
'ATTENTION: TESTING IS NOT THREAD SAFE SO DO NOT PERFORM MULTIPLE TESTS CONCURRENTLY.': '注意: 因為在測試模式不保證多執行緒安全性,也就是說不可以同時執行多個測試案例',
'ATTENTION: you cannot edit the running application!': '注意:不可編輯正在執行的應用程式!',
'Authentication': '驗證',
'Available Databases and Tables': '可提供的資料庫和資料表',
'Buy this book': 'Buy this book',
'cache': '快取記憶體',
'Cache': 'Cache',
'Cache Keys': 'Cache Keys',
'Cannot be empty': '不可空白',
'Cannot compile: there are errors in your app. Debug it, correct errors and try again.': '無法編譯:應用程式中含有錯誤,請除錯後再試一次.',
'Change Password': '變更密碼',
'change password': '變更密碼',
'Check to delete': '打勾代表刪除',
'Check to delete:': '點選以示刪除:',
'Clear CACHE?': 'Clear CACHE?',
'Clear DISK': 'Clear DISK',
'Clear RAM': 'Clear RAM',
'Client IP': '客戶端網址(IP)',
'Community': 'Community',
'Components and Plugins': 'Components and Plugins',
'Controller': '控件',
'Controllers': '控件',
'Copyright': '版權所有',
'Create new application': '創建應用程式',
'Current request': '目前網路資料要求(request)',
'Current response': '目前網路資料回應(response)',
'Current session': '目前網路連線資訊(session)',
'customize me!': '請調整我!',
'data uploaded': '資料已上傳',
'Database': '資料庫',
'Database %s select': '已選擇 %s 資料庫',
'Date and Time': '日期和時間',
'db': 'db',
'DB Model': '資料庫模組',
'Delete': '刪除',
'Delete:': '刪除:',
'Demo': 'Demo',
'Deploy on Google App Engine': '配置到 Google App Engine',
'Deployment Recipes': 'Deployment Recipes',
'Description': '描述',
'DESIGN': '設計',
'design': '設計',
'Design for': '設計為了',
'DISK': 'DISK',
'Disk Cache Keys': 'Disk Cache Keys',
'Disk Cleared': 'Disk Cleared',
'Documentation': 'Documentation',
"Don't know what to do?": "Don't know what to do?",
'done!': '完成!',
'Download': 'Download',
'E-mail': '電子郵件',
'EDIT': '編輯',
'Edit': '編輯',
'Edit application': '編輯應用程式',
'Edit current record': '編輯當前紀錄',
'edit profile': '編輯設定檔',
'Edit Profile': '編輯設定檔',
'Edit This App': '編輯本應用程式',
'Editing file': '編輯檔案',
'Editing file "%s"': '編輯檔案"%s"',
'Email and SMS': 'Email and SMS',
'Error logs for "%(app)s"': '"%(app)s"的錯誤紀錄',
'Errors': 'Errors',
'export as csv file': '以逗號分隔檔(csv)格式匯出',
'FAQ': 'FAQ',
'First name': '名',
'Forms and Validators': 'Forms and Validators',
'Free Applications': 'Free Applications',
'Functions with no doctests will result in [passed] tests.': '沒有 doctests 的函式會顯示 [passed].',
'Group ID': '群組編號',
'Groups': 'Groups',
'Hello World': '嗨! 世界',
'Home': 'Home',
'How did you get here?': 'How did you get here?',
'import': 'import',
'Import/Export': '匯入/匯出',
'Index': '索引',
'insert new': '插入新資料',
'insert new %s': '插入新資料 %s',
'Installed applications': '已安裝應用程式',
'Internal State': '內部狀態',
'Introduction': 'Introduction',
'Invalid action': '不合法的動作(action)',
'Invalid email': '不合法的電子郵件',
'Invalid Query': '不合法的查詢',
'invalid request': '不合法的網路要求(request)',
'Key': 'Key',
'Language files (static strings) updated': '語言檔已更新',
'Languages': '各國語言',
'Last name': '姓',
'Last saved on:': '最後儲存時間:',
'Layout': '網頁配置',
'Layout Plugins': 'Layout Plugins',
'Layouts': 'Layouts',
'License for': '軟體版權為',
'Live Chat': 'Live Chat',
'login': '登入',
'Login': '登入',
'Login to the Administrative Interface': '登入到管理員介面',
'logout': '登出',
'Logout': '登出',
'Lost Password': '密碼遺忘',
'Main Menu': '主選單',
'Manage Cache': 'Manage Cache',
'Menu Model': '選單模組(menu)',
'Models': '資料模組',
'Modules': '程式模組',
'My Sites': 'My Sites',
'Name': '名字',
'New Record': '新紀錄',
'new record inserted': '已插入新紀錄',
'next 100 rows': '往後 100 筆',
'NO': '否',
'No databases in this application': '這應用程式不含資料庫',
'Online examples': '點此處進入線上範例',
'or import from csv file': '或是從逗號分隔檔(CSV)匯入',
'Origin': '原文',
'Original/Translation': '原文/翻譯',
'Other Plugins': 'Other Plugins',
'Other Recipes': 'Other Recipes',
'Overview': 'Overview',
'Password': '密碼',
"Password fields don't match": '密碼欄不匹配',
'Peeking at file': '選擇檔案',
'Plugins': 'Plugins',
'Powered by': '基於以下技術構建:',
'Preface': 'Preface',
'previous 100 rows': '往前 100 筆',
'Python': 'Python',
'Query:': '查詢:',
'Quick Examples': 'Quick Examples',
'RAM': 'RAM',
'RAM Cache Keys': 'RAM Cache Keys',
'Ram Cleared': 'Ram Cleared',
'Recipes': 'Recipes',
'Record': '紀錄',
'record does not exist': '紀錄不存在',
'Record ID': '紀錄編號',
'Record id': '紀錄編號',
'Register': '註冊',
'register': '註冊',
'Registration key': '註冊金鑰',
'Remember me (for 30 days)': '記住我(30 天)',
'Reset Password key': '重設密碼',
'Resolve Conflict file': '解決衝突檔案',
'Role': '角色',
'Rows in Table': '在資料表裏的資料',
'Rows selected': '筆資料被選擇',
'Saved file hash:': '檔案雜湊值已紀錄:',
'Semantic': 'Semantic',
'Services': 'Services',
'Size of cache:': 'Size of cache:',
'state': '狀態',
'Static files': '靜態檔案',
'Statistics': 'Statistics',
'Stylesheet': '網頁風格檔',
'submit': 'submit',
'Submit': '傳送',
'Support': 'Support',
'Sure you want to delete this object?': '確定要刪除此物件?',
'Table': '資料表',
'Table name': '資料表名稱',
'Testing application': '測試中的應用程式',
'The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.': '"查詢"是一個像 "db.表1.欄位1==\'值\'" 的條件式. 以"db.表1.欄位1==db.表2.欄位2"方式則相當於執行 JOIN SQL.',
'The Core': 'The Core',
'The output of the file is a dictionary that was rendered by the view %s': 'The output of the file is a dictionary that was rendered by the view %s',
'The Views': 'The Views',
'There are no controllers': '沒有控件(controllers)',
'There are no models': '沒有資料庫模組(models)',
'There are no modules': '沒有程式模組(modules)',
'There are no static files': '沒有靜態檔案',
'There are no translators, only default language is supported': '沒有翻譯檔,只支援原始語言',
'There are no views': '沒有視圖',
'This App': 'This App',
'This is the %(filename)s template': '這是%(filename)s檔案的樣板(template)',
'Ticket': '問題單',
'Time in Cache (h:m:s)': 'Time in Cache (h:m:s)',
'Timestamp': '時間標記',
'Twitter': 'Twitter',
'Unable to check for upgrades': '無法做升級檢查',
'Unable to download': '無法下載',
'Unable to download app': '無法下載應用程式',
'unable to parse csv file': '無法解析逗號分隔檔(csv)',
'Update:': '更新:',
'Upload existing application': '更新存在的應用程式',
'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...) for NOT to build more complex queries.': '使用下列方式來組合更複雜的條件式, (...)&(...) 代表同時存在的條件, (...)|(...) 代表擇一的條件, ~(...)則代表反向條件.',
'User %(id)s Logged-in': '使用者 %(id)s 已登入',
'User %(id)s Registered': '使用者 %(id)s 已註冊',
'User ID': '使用者編號',
'Verify Password': '驗證密碼',
'Videos': 'Videos',
'View': '視圖',
'Views': '視圖',
'Welcome %s': '歡迎 %s',
'Welcome to web2py': '歡迎使用 web2py',
'Welcome to web2py!': 'Welcome to web2py!',
'Which called the function %s located in the file %s': 'Which called the function %s located in the file %s',
'YES': '是',
'You are successfully running web2py': 'You are successfully running web2py',
'You can modify this application and adapt it to your needs': 'You can modify this application and adapt it to your needs',
'You visited the url %s': 'You visited the url %s',
}
|
mit
|
[
3,
2803,
26,
2774,
24,
199,
91,
199,
7,
1,
4159,
600,
27676,
283,
3951,
13,
8122,
297,
199,
7,
1,
4159,
354,
27676,
283,
17088,
20918,
297,
199,
4065,
873,
2,
365,
376,
2716,
3965,
2839,
298,
698,
17,
25641,
1222,
585,
3985,
1674,
2047,
3913,
1678,
503,
3145,
314,
2058,
402,
282,
10593,
356,
5522,
31845,
22737,
2,
221,
9729,
24744,
117,
24070,
230,
17182,
101,
8106,
163,
96,
252,
15054,
21041,
12,
8853,
255,
121,
21041,
15348,
110,
162,
226,
238,
298,
23974,
227,
30555,
17,
25641,
32678,
3985,
1674,
221,
11046,
229,
9729,
10593,
221,
8106,
29273,
230,
10310,
248,
19594,
25521,
23681,
30026,
1678,
8853,
231,
245,
9729,
3145,
6949,
199,
5956,
83,
11539,
91,
1143,
93,
5463,
356,
283,
28913,
9051,
104,
31459,
450,
83,
9112,
256,
229,
297,
199,
5956,
83,
11539,
91,
1143,
93,
4588,
356,
283,
28913,
31845,
22737,
450,
83,
9112,
256,
229,
297,
199,
5956,
83,
4895,
356,
1543,
83,
7094,
116,
111,
24744,
117,
24070,
230,
297,
199,
5956,
57,
3295,
77,
3295,
68,
356,
1543,
57,
3295,
77,
3295,
68,
297,
199,
5956,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
356,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
297,
199,
6774,
10297,
2839,
298,
390,
13,
390,
531,
356,
8189,
13750,
121,
21041,
27513,
253,
17848,
121,
298,
3951,
13,
8122,
30901,
199,
7,
33,
892,
1015,
402,
3330,
18,
647,
365,
2808,
356,
283,
22737,
19431,
231,
8106,
3330,
18,
647,
7094,
116,
111,
23460,
121,
12609,
297,
199,
7,
33,
892,
1015,
402,
3330,
18,
647,
365,
2808,
26,
450,
83,
356,
283,
22737,
19431,
231,
8106,
3330,
18,
647,
7094,
116,
111,
23460,
121,
12609,
26,
450,
83,
297,
199,
7,
10254,
356,
283,
19248,
251,
10310,
121,
297,
199,
7,
18816,
356,
283,
19248,
251,
10310,
121,
297,
199,
7,
18816,
4223,
356,
283,
19248,
251,
10310,
121,
26304,
163,
230,
232,
11428,
30664,
21041,
297,
199,
7,
3946,
8612,
356,
283,
3946,
8612,
297,
199,
7,
4880,
365,
6980,
2952,
26097,
3623,
356,
283,
16716,
95,
24946,
12163,
254,
28371,
8,
4880,
9,
21448,
19594,
10270,
232,
8379,
102,
14333,
97,
27035,
249,
164,
241,
109,
162,
96,
226,
24233,
27345,
104,
162,
234,
244,
19248,
251,
31834,
232,
297,
199,
7,
4880,
365,
6980,
2952,
625,
7817,
3623,
356,
283,
16716,
95,
24946,
12163,
254,
28371,
8,
4880,
9,
21448,
19594,
10270,
232,
8379,
102,
14333,
97,
27035,
249,
164,
241,
109,
162,
96,
226,
24233,
27345,
104,
162,
234,
244,
19248,
251,
31834,
232,
297,
199,
7,
4880,
25124,
14816,
356,
283,
4880,
25124,
14816,
297,
199,
7,
4880,
25124,
3217,
356,
283,
28931,
253,
17627,
98,
165,
248,
244,
14333,
111,
18236,
16716,
95,
24946,
5498,
234,
26398,
96,
297,
199,
7,
31972,
13635,
25156,
283,
16716,
95,
24946,
22747,
95,
26505,
164,
96,
121,
6536,
199,
7,
33,
15863,
799,
8233,
83,
356,
283,
33,
15863,
799,
8233,
83,
297,
199,
7,
571,
2113,
365,
6980,
2952,
26097,
3623,
356,
283,
14339,
255,
24889,
25439,
229,
27345,
104,
26398,
253,
10270,
232,
8379,
102,
14333,
249,
24744,
242,
12,
16716,
95,
24946,
5498,
234,
26398,
96,
19248,
251,
31834,
232,
297,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
3145,
570,
2071,
83,
14863,
356,
283,
164,
96,
119,
20766,
22274,
9051,
104,
31459,
163,
104,
243,
31333,
231,
6808,
83,
2,
7044,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
3145,
642,
909,
28867,
283,
17683,
1265,
3238,
1265,
2934,
370,
3145,
642,
909,
7044,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
22199,
4223,
2071,
83,
2,
356,
283,
164,
96,
119,
20766,
22274,
19012,
120,
31459,
163,
230,
232,
11428,
30664,
21041,
2071,
83,
6949,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
22199,
4223,
2071,
83,
14863,
356,
283,
164,
96,
119,
20766,
22274,
19012,
120,
31459,
163,
230,
232,
11428,
30664,
21041,
2071,
83,
6949,
199,
7,
11712,
1309,
1075,
26,
16430,
5074,
282,
11153,
334,
14921,
9,
1950,
503,
3879,
641,
11667,
10586,
283,
20021,
102,
163,
227,
238,
26,
9112,
248,
120,
18236,
16716,
95,
24946,
15280,
112,
165,
248,
254,
166,
251,
223,
22274,
10270,
232,
8379,
102,
14333,
97,
27035,
249,
8,
14921,
9,
9077,
245,
9729,
21448,
26304,
163,
103,
254,
14333,
97,
27035,
249,
8,
5967,
680,
297,
199,
7,
11712,
1309,
1075,
26,
7393,
1206,
2281,
2845,
4221,
5670,
13950,
5100,
3562,
3506,
2845,
13873,
3516,
24895,
1772,
906,
7393,
51,
1868,
14211,
6084,
10586,
283,
20021,
102,
163,
227,
238,
26,
7094,
250,
255,
24889,
21448,
163,
117,
106,
165,
103,
100,
29887,
21041,
19594,
22244,
165,
256,
232,
11546,
249,
25056,
116,
12609,
27035,
241,
10270,
232,
8379,
102,
17182,
101,
12356,
17837,
254,
15348,
110,
9729,
165,
104,
104,
19594,
25521,
23681,
28956,
163,
248,
225,
25056,
116,
12609,
11546,
249,
20757,
234,
163,
117,
106,
165,
103,
100,
31333,
231,
25439,
234,
297,
199,
7,
11712,
1309,
1075,
26,
1265,
3913,
5283,
314,
3879,
4223,
27676,
283,
20021,
102,
163,
227,
238,
26,
19594,
25521,
27035,
102,
25624,
108,
17627,
97,
21448,
25056,
116,
12609,
8106,
163,
230,
232,
11428,
30664,
21041,
12389,
199,
7,
10348,
356,
283,
166,
103,
246,
165,
256,
232,
297,
199,
7,
11464,
8692,
83,
436,
377,
5921,
356,
283,
25521,
22843,
239,
25439,
250,
8106,
29273,
230,
10310,
248,
15013,
105,
30557,
29273,
230,
10310,
248,
23243,
297,
199,
7,
1713,
89,
642,
6719,
356,
283,
1713,
89,
642,
6719,
297,
199,
7,
1637,
356,
283,
16989,
105,
22924,
20278,
247,
163,
229,
115,
166,
105,
243,
297,
199,
7,
4437,
356,
283,
4437,
297,
199,
7,
4437,
17276,
356,
283,
4437,
17276,
297,
199,
7,
6612,
506,
2701,
356,
283,
19594,
25521,
30413,
119,
23460,
122,
297,
199,
7,
6612,
6555,
26,
2337,
787,
2552,
315,
2195,
1145,
14,
263,
14245,
652,
12,
3211,
2552,
436,
862,
4020,
10586,
283,
164,
227,
95,
27397,
27035,
102,
165,
256,
108,
26,
163,
230,
232,
11428,
30664,
21041,
17088,
8197,
105,
20916,
166,
235,
108,
165,
104,
98,
12356,
165,
105,
234
] |
[
2803,
26,
2774,
24,
199,
91,
199,
7,
1,
4159,
600,
27676,
283,
3951,
13,
8122,
297,
199,
7,
1,
4159,
354,
27676,
283,
17088,
20918,
297,
199,
4065,
873,
2,
365,
376,
2716,
3965,
2839,
298,
698,
17,
25641,
1222,
585,
3985,
1674,
2047,
3913,
1678,
503,
3145,
314,
2058,
402,
282,
10593,
356,
5522,
31845,
22737,
2,
221,
9729,
24744,
117,
24070,
230,
17182,
101,
8106,
163,
96,
252,
15054,
21041,
12,
8853,
255,
121,
21041,
15348,
110,
162,
226,
238,
298,
23974,
227,
30555,
17,
25641,
32678,
3985,
1674,
221,
11046,
229,
9729,
10593,
221,
8106,
29273,
230,
10310,
248,
19594,
25521,
23681,
30026,
1678,
8853,
231,
245,
9729,
3145,
6949,
199,
5956,
83,
11539,
91,
1143,
93,
5463,
356,
283,
28913,
9051,
104,
31459,
450,
83,
9112,
256,
229,
297,
199,
5956,
83,
11539,
91,
1143,
93,
4588,
356,
283,
28913,
31845,
22737,
450,
83,
9112,
256,
229,
297,
199,
5956,
83,
4895,
356,
1543,
83,
7094,
116,
111,
24744,
117,
24070,
230,
297,
199,
5956,
57,
3295,
77,
3295,
68,
356,
1543,
57,
3295,
77,
3295,
68,
297,
199,
5956,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
356,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
297,
199,
6774,
10297,
2839,
298,
390,
13,
390,
531,
356,
8189,
13750,
121,
21041,
27513,
253,
17848,
121,
298,
3951,
13,
8122,
30901,
199,
7,
33,
892,
1015,
402,
3330,
18,
647,
365,
2808,
356,
283,
22737,
19431,
231,
8106,
3330,
18,
647,
7094,
116,
111,
23460,
121,
12609,
297,
199,
7,
33,
892,
1015,
402,
3330,
18,
647,
365,
2808,
26,
450,
83,
356,
283,
22737,
19431,
231,
8106,
3330,
18,
647,
7094,
116,
111,
23460,
121,
12609,
26,
450,
83,
297,
199,
7,
10254,
356,
283,
19248,
251,
10310,
121,
297,
199,
7,
18816,
356,
283,
19248,
251,
10310,
121,
297,
199,
7,
18816,
4223,
356,
283,
19248,
251,
10310,
121,
26304,
163,
230,
232,
11428,
30664,
21041,
297,
199,
7,
3946,
8612,
356,
283,
3946,
8612,
297,
199,
7,
4880,
365,
6980,
2952,
26097,
3623,
356,
283,
16716,
95,
24946,
12163,
254,
28371,
8,
4880,
9,
21448,
19594,
10270,
232,
8379,
102,
14333,
97,
27035,
249,
164,
241,
109,
162,
96,
226,
24233,
27345,
104,
162,
234,
244,
19248,
251,
31834,
232,
297,
199,
7,
4880,
365,
6980,
2952,
625,
7817,
3623,
356,
283,
16716,
95,
24946,
12163,
254,
28371,
8,
4880,
9,
21448,
19594,
10270,
232,
8379,
102,
14333,
97,
27035,
249,
164,
241,
109,
162,
96,
226,
24233,
27345,
104,
162,
234,
244,
19248,
251,
31834,
232,
297,
199,
7,
4880,
25124,
14816,
356,
283,
4880,
25124,
14816,
297,
199,
7,
4880,
25124,
3217,
356,
283,
28931,
253,
17627,
98,
165,
248,
244,
14333,
111,
18236,
16716,
95,
24946,
5498,
234,
26398,
96,
297,
199,
7,
31972,
13635,
25156,
283,
16716,
95,
24946,
22747,
95,
26505,
164,
96,
121,
6536,
199,
7,
33,
15863,
799,
8233,
83,
356,
283,
33,
15863,
799,
8233,
83,
297,
199,
7,
571,
2113,
365,
6980,
2952,
26097,
3623,
356,
283,
14339,
255,
24889,
25439,
229,
27345,
104,
26398,
253,
10270,
232,
8379,
102,
14333,
249,
24744,
242,
12,
16716,
95,
24946,
5498,
234,
26398,
96,
19248,
251,
31834,
232,
297,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
3145,
570,
2071,
83,
14863,
356,
283,
164,
96,
119,
20766,
22274,
9051,
104,
31459,
163,
104,
243,
31333,
231,
6808,
83,
2,
7044,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
3145,
642,
909,
28867,
283,
17683,
1265,
3238,
1265,
2934,
370,
3145,
642,
909,
7044,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
22199,
4223,
2071,
83,
2,
356,
283,
164,
96,
119,
20766,
22274,
19012,
120,
31459,
163,
230,
232,
11428,
30664,
21041,
2071,
83,
6949,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
22199,
4223,
2071,
83,
14863,
356,
283,
164,
96,
119,
20766,
22274,
19012,
120,
31459,
163,
230,
232,
11428,
30664,
21041,
2071,
83,
6949,
199,
7,
11712,
1309,
1075,
26,
16430,
5074,
282,
11153,
334,
14921,
9,
1950,
503,
3879,
641,
11667,
10586,
283,
20021,
102,
163,
227,
238,
26,
9112,
248,
120,
18236,
16716,
95,
24946,
15280,
112,
165,
248,
254,
166,
251,
223,
22274,
10270,
232,
8379,
102,
14333,
97,
27035,
249,
8,
14921,
9,
9077,
245,
9729,
21448,
26304,
163,
103,
254,
14333,
97,
27035,
249,
8,
5967,
680,
297,
199,
7,
11712,
1309,
1075,
26,
7393,
1206,
2281,
2845,
4221,
5670,
13950,
5100,
3562,
3506,
2845,
13873,
3516,
24895,
1772,
906,
7393,
51,
1868,
14211,
6084,
10586,
283,
20021,
102,
163,
227,
238,
26,
7094,
250,
255,
24889,
21448,
163,
117,
106,
165,
103,
100,
29887,
21041,
19594,
22244,
165,
256,
232,
11546,
249,
25056,
116,
12609,
27035,
241,
10270,
232,
8379,
102,
17182,
101,
12356,
17837,
254,
15348,
110,
9729,
165,
104,
104,
19594,
25521,
23681,
28956,
163,
248,
225,
25056,
116,
12609,
11546,
249,
20757,
234,
163,
117,
106,
165,
103,
100,
31333,
231,
25439,
234,
297,
199,
7,
11712,
1309,
1075,
26,
1265,
3913,
5283,
314,
3879,
4223,
27676,
283,
20021,
102,
163,
227,
238,
26,
19594,
25521,
27035,
102,
25624,
108,
17627,
97,
21448,
25056,
116,
12609,
8106,
163,
230,
232,
11428,
30664,
21041,
12389,
199,
7,
10348,
356,
283,
166,
103,
246,
165,
256,
232,
297,
199,
7,
11464,
8692,
83,
436,
377,
5921,
356,
283,
25521,
22843,
239,
25439,
250,
8106,
29273,
230,
10310,
248,
15013,
105,
30557,
29273,
230,
10310,
248,
23243,
297,
199,
7,
1713,
89,
642,
6719,
356,
283,
1713,
89,
642,
6719,
297,
199,
7,
1637,
356,
283,
16989,
105,
22924,
20278,
247,
163,
229,
115,
166,
105,
243,
297,
199,
7,
4437,
356,
283,
4437,
297,
199,
7,
4437,
17276,
356,
283,
4437,
17276,
297,
199,
7,
6612,
506,
2701,
356,
283,
19594,
25521,
30413,
119,
23460,
122,
297,
199,
7,
6612,
6555,
26,
2337,
787,
2552,
315,
2195,
1145,
14,
263,
14245,
652,
12,
3211,
2552,
436,
862,
4020,
10586,
283,
164,
227,
95,
27397,
27035,
102,
165,
256,
108,
26,
163,
230,
232,
11428,
30664,
21041,
17088,
8197,
105,
20916,
166,
235,
108,
165,
104,
98,
12356,
165,
105,
234,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
waseem18/oh-mainline
|
vendor/packages/twill/twill/other_packages/pyparsing.py
|
19
|
99305
|
# module pyparsing.py
#
# Copyright (c) 2003-2006 Paul T. McGuire
#
# 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.
#
# Todo:
# - add pprint() - pretty-print output of defined BNF
#
#from __future__ import generators
__doc__ = \
"""
pyparsing module - Classes and methods to define and execute parsing grammars
The pyparsing module is an alternative approach to creating and executing simple grammars,
vs. the traditional lex/yacc approach, or the use of regular expressions. With pyparsing, you
don't need to learn a new syntax for defining grammars or matching expressions - the parsing module
provides a library of classes that you use to construct the grammar directly in Python.
Here is a program to parse "Hello, World!" (or any greeting of the form "<salutation>, <addressee>!")::
from pyparsing import Word, alphas
# define grammar of a greeting
greet = Word( alphas ) + "," + Word( alphas ) + "!"
hello = "Hello, World!"
print hello, "->", greet.parseString( hello )
The program outputs the following::
Hello, World! -> ['Hello', ',', 'World', '!']
The Python representation of the grammar is quite readable, owing to the self-explanatory
class names, and the use of '+', '|' and '^' operators.
The parsed results returned from parseString() can be accessed as a nested list, a dictionary, or an
object with named attributes.
The pyparsing module handles some of the problems that are typically vexing when writing text parsers:
- extra or missing whitespace (the above program will also handle "Hello,World!", "Hello , World !", etc.)
- quoted strings
- embedded comments
"""
__version__ = "1.4.1"
__versionTime__ = "05 February 2006 12:24"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
import copy,sys
import warnings
import re
#~ sys.stderr.write( "testing pyparsing module, version %s, %s\n" % (__version__,__versionTime__ ) )
def _ustr(obj):
"""Drop-in replacement for str(obj) that tries to be Unicode friendly. It first tries
str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
then < returns the unicode object | encodes it with the default encoding | ... >.
"""
try:
# If this works, then _ustr(obj) has the same behaviour as str(obj), so
# it won't break any existing code.
return str(obj)
except UnicodeEncodeError, e:
# The Python docs (http://docs.python.org/ref/customization.html#l2h-182)
# state that "The return value must be a string object". However, does a
# unicode object (being a subclass of basestring) count as a "string
# object"?
# If so, then return a unicode object:
return unicode(obj)
# Else encode it... but how? There are many choices... :)
# Replace unprintables with escape codes?
#return unicode(obj).encode(sys.getdefaultencoding(), 'backslashreplace_errors')
# Replace unprintables with question marks?
#return unicode(obj).encode(sys.getdefaultencoding(), 'replace')
# ...
def _str2dict(strg):
return dict( [(c,0) for c in strg] )
alphas = string.lowercase + string.uppercase
nums = string.digits
hexnums = nums + "ABCDEFabcdef"
alphanums = alphas + nums
class ParseBaseException(Exception):
"""base exception class for all parsing runtime exceptions"""
__slots__ = ( "loc","msg","pstr","parserElement" )
# Performance tuning: we construct a *lot* of these, so keep this
# constructor as small and fast as possible
def __init__( self, pstr, loc, msg, elem=None ):
self.loc = loc
self.msg = msg
self.pstr = pstr
self.parserElement = elem
def __getattr__( self, aname ):
"""supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text
"""
if( aname == "lineno" ):
return lineno( self.loc, self.pstr )
elif( aname in ("col", "column") ):
return col( self.loc, self.pstr )
elif( aname == "line" ):
return line( self.loc, self.pstr )
else:
raise AttributeError, aname
def __str__( self ):
return "%s (at char %d), (line:%d, col:%d)" % ( self.msg, self.loc, self.lineno, self.column )
def __repr__( self ):
return _ustr(self)
def markInputline( self, markerString = ">!<" ):
"""Extracts the exception line from the input string, and marks
the location of the exception with a special symbol.
"""
line_str = self.line
line_column = self.column - 1
if markerString:
line_str = "".join( [line_str[:line_column], markerString, line_str[line_column:]])
return line_str.strip()
class ParseException(ParseBaseException):
"""exception thrown when parse expressions don't match class"""
"""supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text
"""
pass
class ParseFatalException(ParseBaseException):
"""user-throwable exception thrown when inconsistent parse content
is found; stops all parsing immediately"""
pass
class RecursiveGrammarException(Exception):
"""exception thrown by validate() if the grammar could be improperly recursive"""
def __init__( self, parseElementList ):
self.parseElementTrace = parseElementList
def __str__( self ):
return "RecursiveGrammarException: %s" % self.parseElementTrace
class ParseResults(object):
"""Structured parse results, to provide multiple means of access to the parsed data:
- as a list (len(results))
- by list index (results[0], results[1], etc.)
- by attribute (results.<resultsName>)
"""
__slots__ = ( "__toklist", "__tokdict", "__doinit", "__name", "__parent", "__modal" )
def __new__(cls, toklist, name=None, asList=True, modal=True ):
if isinstance(toklist, cls):
return toklist
retobj = object.__new__(cls)
retobj.__doinit = True
return retobj
# Performance tuning: we construct a *lot* of these, so keep this
# constructor as small and fast as possible
def __init__( self, toklist, name=None, asList=True, modal=True ):
if self.__doinit:
self.__doinit = False
self.__name = None
self.__parent = None
self.__modal = modal
if isinstance(toklist, list):
self.__toklist = toklist[:]
else:
self.__toklist = [toklist]
self.__tokdict = dict()
if name:
if not self.__name:
self.__modal = self.__modal and modal
if isinstance(name,int):
name = _ustr(name) # will always return a str, but use _ustr for consistency
self.__name = name
if not toklist in (None,'',[]):
if isinstance(toklist,basestring):
toklist = [ toklist ]
if asList:
if isinstance(toklist,ParseResults):
self[name] = (toklist.copy(),-1)
else:
self[name] = (ParseResults(toklist[0]),-1)
self[name].__name = name
else:
try:
self[name] = toklist[0]
except TypeError:
self[name] = toklist
def __getitem__( self, i ):
if isinstance( i, (int,slice) ):
return self.__toklist[i]
else:
if self.__modal:
return self.__tokdict[i][-1][0]
else:
return ParseResults([ v[0] for v in self.__tokdict[i] ])
def __setitem__( self, k, v ):
if isinstance(v,tuple):
self.__tokdict[k] = self.__tokdict.get(k,list()) + [v]
sub = v[0]
else:
self.__tokdict[k] = self.__tokdict.get(k,list()) + [(v,0)]
sub = v
if isinstance(sub,ParseResults):
sub.__parent = self
def __delitem__( self, i ):
del self.__toklist[i]
def __contains__( self, k ):
return self.__tokdict.has_key(k)
def __len__( self ): return len( self.__toklist )
def __iter__( self ): return iter( self.__toklist )
def keys( self ):
"""Returns all named result keys."""
return self.__tokdict.keys()
def items( self ):
"""Returns all named result keys and values as a list of tuples."""
return [(k,v[-1][0]) for k,v in self.__tokdict.items()]
def values( self ):
"""Returns all named result values."""
return [ v[-1][0] for v in self.__tokdict.values() ]
def __getattr__( self, name ):
if name not in self.__slots__:
if self.__tokdict.has_key( name ):
if self.__modal:
return self.__tokdict[name][-1][0]
else:
return ParseResults([ v[0] for v in self.__tokdict[name] ])
else:
return ""
return None
def __iadd__( self, other ):
if other.__tokdict:
offset = len(self.__toklist)
addoffset = ( lambda a: (a<0 and offset) or (a+offset) )
otherdictitems = [(k,(v[0],addoffset(v[1])) ) for (k,vlist) in other.__tokdict.items() for v in vlist]
for k,v in otherdictitems:
self[k] = v
if isinstance(v[0],ParseResults):
v[0].__parent = self
self.__toklist += other.__toklist
del other
return self
def __repr__( self ):
return "(%s, %s)" % ( repr( self.__toklist ), repr( self.__tokdict ) )
def __str__( self ):
out = "["
sep = ""
for i in self.__toklist:
if isinstance(i, ParseResults):
out += sep + _ustr(i)
else:
out += sep + repr(i)
sep = ", "
out += "]"
return out
def _asStringList( self, sep='' ):
out = []
for item in self.__toklist:
if out and sep:
out.append(sep)
if isinstance( item, ParseResults ):
out += item._asStringList()
else:
out.append( _ustr(item) )
return out
def asList( self ):
"""Returns the parse results as a nested list of matching tokens, all converted to strings."""
out = []
for res in self.__toklist:
if isinstance(res,ParseResults):
out.append( res.asList() )
else:
out.append( res )
return out
def asDict( self ):
"""Returns the named parse results as dictionary."""
return dict( self.items() )
def copy( self ):
"""Returns a new copy of a ParseResults object."""
ret = ParseResults( self.__toklist )
ret.__tokdict = self.__tokdict.copy()
ret.__parent = self.__parent
ret.__modal = self.__modal
ret.__name = self.__name
return ret
def asXML( self, doctag=None, namedItemsOnly=False, indent="", formatted=True ):
"""Returns the parse results as XML. Tags are created for tokens and lists that have defined results names."""
nl = "\n"
out = []
namedItems = dict( [ (v[1],k) for (k,vlist) in self.__tokdict.items() for v in vlist ] )
nextLevelIndent = indent + " "
# collapse out indents if formatting is not desired
if not formatted:
indent = ""
nextLevelIndent = ""
nl = ""
selfTag = None
if doctag is not None:
selfTag = doctag
else:
if self.__name:
selfTag = self.__name
if not selfTag:
if namedItemsOnly:
return ""
else:
selfTag = "ITEM"
out += [ nl, indent, "<", selfTag, ">" ]
worklist = self.__toklist
for i,res in enumerate(worklist):
if isinstance(res,ParseResults):
if i in namedItems:
out += [ res.asXML(namedItems[i], namedItemsOnly and doctag is None, nextLevelIndent,formatted)]
else:
out += [ res.asXML(None, namedItemsOnly and doctag is None, nextLevelIndent,formatted)]
else:
# individual token, see if there is a name for it
resTag = None
if i in namedItems:
resTag = namedItems[i]
if not resTag:
if namedItemsOnly:
continue
else:
resTag = "ITEM"
out += [ nl, nextLevelIndent, "<", resTag, ">", _ustr(res), "</", resTag, ">" ]
out += [ nl, indent, "</", selfTag, ">" ]
return "".join(out)
def __lookup(self,sub):
for k,vlist in self.__tokdict.items():
for v,loc in vlist:
if sub is v:
return k
return None
def getName(self):
"""Returns the results name for this token expression."""
if self.__name:
return self.__name
elif self.__parent:
par = self.__parent
if par:
return par.__lookup(self)
else:
return None
elif (len(self) == 1 and
len(self.__tokdict) == 1 and
self.__tokdict.values()[0][0][1] in (0,-1)):
return self.__tokdict.keys()[0]
else:
return None
def col (loc,strg):
"""Returns current column within a string, counting newlines as line separators.
The first column is number 1.
"""
return loc - strg.rfind("\n", 0, loc)
def lineno(loc,strg):
"""Returns current line number within a string, counting newlines as line separators.
The first line is number 1.
"""
return strg.count("\n",0,loc) + 1
def line( loc, strg ):
"""Returns the line of text containing loc within a string, counting newlines as line separators.
"""
lastCR = strg.rfind("\n", 0, loc)
nextCR = strg.find("\n", loc)
if nextCR > 0:
return strg[lastCR+1:nextCR]
else:
return strg[lastCR+1:]
def _defaultStartDebugAction( instring, loc, expr ):
print "Match",expr,"at loc",loc,"(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )
def _defaultSuccessDebugAction( instring, startloc, endloc, expr, toks ):
print "Matched",expr,"->",toks.asList()
def _defaultExceptionDebugAction( instring, loc, expr, exc ):
print "Exception raised:", exc
def nullDebugAction(*args):
"""'Do-nothing' debug action, to suppress debugging output during parsing."""
pass
class ParserElement(object):
"""Abstract base level parser element class."""
DEFAULT_WHITE_CHARS = " \n\t\r"
def setDefaultWhitespaceChars( chars ):
"""Overrides the default whitespace chars
"""
ParserElement.DEFAULT_WHITE_CHARS = chars
setDefaultWhitespaceChars = staticmethod(setDefaultWhitespaceChars)
def __init__( self, savelist=False ):
self.parseAction = None
#~ self.name = "<unknown>" # don't define self.name, let subclasses try/except upcall
self.strRepr = None
self.resultsName = None
self.saveAsList = savelist
self.skipWhitespace = True
self.whiteChars = ParserElement.DEFAULT_WHITE_CHARS
self.mayReturnEmpty = False
self.keepTabs = False
self.ignoreExprs = []
self.debug = False
self.streamlined = False
self.mayIndexError = True
self.errmsg = ""
self.modalResults = True
self.debugActions = ( None, None, None )
self.re = None
def copy( self ):
"""Make a copy of this ParserElement. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element."""
cpy = copy.copy( self )
cpy.whiteChars = ParserElement.DEFAULT_WHITE_CHARS
return cpy
def setName( self, name ):
"""Define name for this expression, for use in debugging."""
self.name = name
self.errmsg = "Expected " + self.name
return self
def setResultsName( self, name, listAllMatches=False ):
"""Define name for referencing matching tokens as a nested attribute
of the returned parse results.
NOTE: this returns a *copy* of the original ParserElement object;
this is so that the client can define a basic element, such as an
integer, and reference it in multiple places with different names.
"""
newself = self.copy()
newself.resultsName = name
newself.modalResults = not listAllMatches
return newself
def setParseAction( self, fn ):
"""Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with the arguments (s, loc, toks) where:
- s = the original string being parsed
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a ParseResults object
If the function fn modifies the tokens, it can return them as the return
value from fn, and the modified list of tokens will replace the original.
Otherwise, fn does not need to return any value.
"""
self.parseAction = fn
return self
def skipIgnorables( self, instring, loc ):
exprsFound = True
while exprsFound:
exprsFound = False
for e in self.ignoreExprs:
try:
while 1:
loc,dummy = e.parse( instring, loc )
exprsFound = True
except ParseException:
pass
return loc
def preParse( self, instring, loc ):
if self.ignoreExprs:
loc = self.skipIgnorables( instring, loc )
if self.skipWhitespace:
wt = self.whiteChars
instrlen = len(instring)
while loc < instrlen and instring[loc] in wt:
loc += 1
return loc
def parseImpl( self, instring, loc, doActions=True ):
return loc, []
def postParse( self, instring, loc, tokenlist ):
return tokenlist
#~ @profile
def parse( self, instring, loc, doActions=True, callPreParse=True ):
debugging = ( self.debug ) #and doActions )
if debugging:
#~ print "Match",self,"at loc",loc,"(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )
if (self.debugActions[0] ):
self.debugActions[0]( instring, loc, self )
if callPreParse:
loc = self.preParse( instring, loc )
tokensStart = loc
try:
try:
loc,tokens = self.parseImpl( instring, loc, doActions )
except IndexError:
raise ParseException, ( instring, len(instring), self.errmsg, self )
except ParseException, err:
#~ print "Exception raised:", err
if (self.debugActions[2] ):
self.debugActions[2]( instring, tokensStart, self, err )
raise
else:
if callPreParse:
loc = self.preParse( instring, loc )
tokensStart = loc
if self.mayIndexError or loc >= len(instring):
try:
loc,tokens = self.parseImpl( instring, loc, doActions )
except IndexError:
raise ParseException, ( instring, len(instring), self.errmsg, self )
else:
loc,tokens = self.parseImpl( instring, loc, doActions )
tokens = self.postParse( instring, loc, tokens )
retTokens = ParseResults( tokens, self.resultsName, asList=self.saveAsList, modal=self.modalResults )
if self.parseAction and doActions:
if debugging:
try:
tokens = self.parseAction( instring, tokensStart, retTokens )
if tokens is not None:
if isinstance(tokens,tuple):
tokens = tokens[1]
retTokens = ParseResults( tokens,
self.resultsName,
asList=self.saveAsList and isinstance(tokens,(ParseResults,list)),
modal=self.modalResults )
except ParseException, err:
#~ print "Exception raised in user parse action:", err
if (self.debugActions[2] ):
self.debugActions[2]( instring, tokensStart, self, err )
raise
else:
tokens = self.parseAction( instring, tokensStart, retTokens )
if tokens is not None:
if isinstance(tokens,tuple):
tokens = tokens[1]
retTokens = ParseResults( tokens,
self.resultsName,
asList=self.saveAsList and isinstance(tokens,(ParseResults,list)),
modal=self.modalResults )
if debugging:
#~ print "Matched",self,"->",retTokens.asList()
if (self.debugActions[1] ):
self.debugActions[1]( instring, tokensStart, loc, self, retTokens )
return loc, retTokens
def tryParse( self, instring, loc ):
return self.parse( instring, loc, doActions=False )[0]
def parseString( self, instring ):
"""Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
"""
if not self.streamlined:
self.streamline()
self.saveAsList = True
for e in self.ignoreExprs:
e.streamline()
if self.keepTabs:
loc, tokens = self.parse( instring, 0 )
else:
loc, tokens = self.parse( instring.expandtabs(), 0 )
return tokens
def scanString( self, instring ):
"""Scan the input string for expression matches. Each match will return the matching tokens, start location, and end location."""
if not self.streamlined:
self.streamline()
for e in self.ignoreExprs:
e.streamline()
if not self.keepTabs:
instring = instring.expandtabs()
instrlen = len(instring)
loc = 0
preparseFn = self.preParse
parseFn = self.parse
while loc < instrlen:
try:
loc = preparseFn( instring, loc )
nextLoc,tokens = parseFn( instring, loc, callPreParse=False )
except ParseException:
loc += 1
else:
yield tokens, loc, nextLoc
loc = nextLoc
def transformString( self, instring ):
"""Extension to scanString, to modify matching text with modified tokens that may
be returned from a parse action. To use transformString, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking transformString() on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. transformString() returns the resulting transformed string."""
out = []
lastE = 0
# force preservation of <TAB>s, to minimize unwanted transformation of string, and to
# keep string locs straight between transformString and scanString
self.keepTabs = True
for t,s,e in self.scanString( instring ):
out.append( instring[lastE:s] )
if t:
if isinstance(t,ParseResults):
out += t.asList()
elif isinstance(t,list):
out += t
else:
out.append(t)
lastE = e
out.append(instring[lastE:])
return "".join(out)
def searchString( self, instring ):
"""Another extension to scanString, simplifying the access to the tokens found
to match the given parse expression.
"""
return [ t[0] for t,s,e in self.scanString( instring ) ]
def __add__(self, other ):
"""Implementation of + operator - returns And"""
if isinstance( other, basestring ):
other = Literal( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot add element of type %s to ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return And( [ self, other ] )
def __radd__(self, other ):
"""Implementation of += operator"""
if isinstance( other, basestring ):
other = Literal( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot add element of type %s to ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return other + self
def __or__(self, other ):
"""Implementation of | operator - returns MatchFirst"""
if isinstance( other, basestring ):
other = Literal( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot add element of type %s to ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return MatchFirst( [ self, other ] )
def __ror__(self, other ):
"""Implementation of |= operator"""
if isinstance( other, basestring ):
other = Literal( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot add element of type %s to ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return other | self
def __xor__(self, other ):
"""Implementation of ^ operator - returns Or"""
if isinstance( other, basestring ):
other = Literal( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot add element of type %s to ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return Or( [ self, other ] )
def __rxor__(self, other ):
"""Implementation of ^= operator"""
if isinstance( other, basestring ):
other = Literal( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot add element of type %s to ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return other ^ self
def __and__(self, other ):
"""Implementation of & operator - returns Each"""
if isinstance( other, basestring ):
other = Literal( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot add element of type %s to ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return Each( [ self, other ] )
def __rand__(self, other ):
"""Implementation of right-& operator"""
if isinstance( other, basestring ):
other = Literal( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot add element of type %s to ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return other & self
def __invert__( self ):
"""Implementation of ~ operator - returns NotAny"""
return NotAny( self )
def suppress( self ):
"""Suppresses the output of this ParserElement; useful to keep punctuation from
cluttering up returned output.
"""
return Suppress( self )
def leaveWhitespace( self ):
"""Disables the skipping of whitespace before matching the characters in the
ParserElement's defined pattern. This is normally only used internally by
the pyparsing module, but may be needed in some whitespace-sensitive grammars.
"""
self.skipWhitespace = False
return self
def setWhitespaceChars( self, chars ):
"""Overrides the default whitespace chars
"""
self.skipWhitespace = True
self.whiteChars = chars
def parseWithTabs( self ):
"""Overrides default behavior to expand <TAB>s to spaces before parsing the input string.
Must be called before parseString when the input grammar contains elements that
match <TAB> characters."""
self.keepTabs = True
return self
def ignore( self, other ):
"""Define expression to be ignored (e.g., comments) while doing pattern
matching; may be called repeatedly, to define multiple comment or other
ignorable patterns.
"""
if isinstance( other, Suppress ):
if other not in self.ignoreExprs:
self.ignoreExprs.append( other )
else:
self.ignoreExprs.append( Suppress( other ) )
return self
def setDebugActions( self, startAction, successAction, exceptionAction ):
"""Enable display of debugging messages while doing pattern matching."""
self.debugActions = (startAction or _defaultStartDebugAction,
successAction or _defaultSuccessDebugAction,
exceptionAction or _defaultExceptionDebugAction)
self.debug = True
return self
def setDebug( self, flag=True ):
"""Enable display of debugging messages while doing pattern matching."""
if flag:
self.setDebugActions( _defaultStartDebugAction, _defaultSuccessDebugAction, _defaultExceptionDebugAction )
else:
self.debug = False
return self
def __str__( self ):
return self.name
def __repr__( self ):
return _ustr(self)
def streamline( self ):
self.streamlined = True
self.strRepr = None
return self
def checkRecursion( self, parseElementList ):
pass
def validate( self, validateTrace=[] ):
"""Check defined expressions for valid structure, check for infinite recursive definitions."""
self.checkRecursion( [] )
def parseFile( self, file_or_filename ):
"""Execute the parse expression on the given file or filename.
If a filename is specified (instead of a file object),
the entire file is opened, read, and closed before parsing.
"""
try:
file_contents = file_or_filename.read()
except AttributeError:
f = open(file_or_filename, "rb")
file_contents = f.read()
f.close()
return self.parseString(file_contents)
class Token(ParserElement):
"""Abstract ParserElement subclass, for defining atomic matching patterns."""
def __init__( self ):
super(Token,self).__init__( savelist=False )
self.myException = ParseException("",0,"",self)
def setName(self, name):
s = super(Token,self).setName(name)
self.errmsg = "Expected " + self.name
s.myException.msg = self.errmsg
return s
class Empty(Token):
"""An empty token, will always match."""
def __init__( self ):
super(Empty,self).__init__()
self.name = "Empty"
self.mayReturnEmpty = True
self.mayIndexError = False
class NoMatch(Token):
"""A token that will never match."""
def __init__( self ):
super(NoMatch,self).__init__()
self.name = "NoMatch"
self.mayReturnEmpty = True
self.mayIndexError = False
self.errmsg = "Unmatchable token"
self.myException.msg = self.errmsg
def parseImpl( self, instring, loc, doActions=True ):
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
class Literal(Token):
"""Token to exactly match a specified string."""
def __init__( self, matchString ):
super(Literal,self).__init__()
self.match = matchString
self.matchLen = len(matchString)
try:
self.firstMatchChar = matchString[0]
except IndexError:
warnings.warn("null string passed to Literal; use Empty() instead",
SyntaxWarning, stacklevel=2)
self.__class__ = Empty
self.name = '"%s"' % self.match
self.errmsg = "Expected " + self.name
self.mayReturnEmpty = False
self.myException.msg = self.errmsg
self.mayIndexError = False
# Performance tuning: this routine gets called a *lot*
# if this is a single character match string and the first character matches,
# short-circuit as quickly as possible, and avoid calling startswith
#~ @profile
def parseImpl( self, instring, loc, doActions=True ):
if (instring[loc] == self.firstMatchChar and
(self.matchLen==1 or instring.startswith(self.match,loc)) ):
return loc+self.matchLen, self.match
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
class Keyword(Token):
"""Token to exactly match a specified string as a keyword, that is, it must be
immediately followed by a non-keyword character. Compare with Literal::
Literal("if") will match the leading 'if' in 'ifAndOnlyIf'.
Keyword("if") will not; it will only match the leading 'if in 'if x=1', or 'if(y==2)'
Accepts two optional constructor arguments in addition to the keyword string:
identChars is a string of characters that would be valid identifier characters,
defaulting to all alphanumerics + "_" and "$"; caseless allows case-insensitive
matching, default is False.
"""
DEFAULT_KEYWORD_CHARS = alphanums+"_$"
def __init__( self, matchString, identChars=DEFAULT_KEYWORD_CHARS, caseless=False ):
super(Keyword,self).__init__()
self.match = matchString
self.matchLen = len(matchString)
try:
self.firstMatchChar = matchString[0]
except IndexError:
warnings.warn("null string passed to Keyword; use Empty() instead",
SyntaxWarning, stacklevel=2)
self.name = '"%s"' % self.match
self.errmsg = "Expected " + self.name
self.mayReturnEmpty = False
self.myException.msg = self.errmsg
self.mayIndexError = False
self.caseless = caseless
if caseless:
self.caselessmatch = matchString.upper()
identChars = identChars.upper()
self.identChars = _str2dict(identChars)
def parseImpl( self, instring, loc, doActions=True ):
if self.caseless:
if ( (instring[ loc:loc+self.matchLen ].upper() == self.caselessmatch) and
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen].upper() not in self.identChars) and
(loc == 0 or instring[loc-1].upper() not in self.identChars) ):
return loc+self.matchLen, self.match
else:
if (instring[loc] == self.firstMatchChar and
(self.matchLen==1 or instring.startswith(self.match,loc)) and
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen] not in self.identChars) and
(loc == 0 or instring[loc-1] not in self.identChars) ):
return loc+self.matchLen, self.match
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
def copy(self):
c = super(Keyword,self).copy()
c.identChars = Keyword.DEFAULT_KEYWORD_CHARS
return c
def setDefaultKeywordChars( chars ):
"""Overrides the default Keyword chars
"""
Keyword.DEFAULT_KEYWORD_CHARS = chars
setDefaultKeywordChars = staticmethod(setDefaultKeywordChars)
class CaselessLiteral(Literal):
"""Token to match a specified string, ignoring case of letters.
Note: the matched results will always be in the case of the given
match string, NOT the case of the input text.
"""
def __init__( self, matchString ):
super(CaselessLiteral,self).__init__( matchString.upper() )
# Preserve the defining literal.
self.returnString = matchString
self.name = "'%s'" % self.returnString
self.errmsg = "Expected " + self.name
self.myException.msg = self.errmsg
def parseImpl( self, instring, loc, doActions=True ):
if instring[ loc:loc+self.matchLen ].upper() == self.match:
return loc+self.matchLen, self.returnString
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
class CaselessKeyword(Keyword):
def __init__( self, matchString, identChars=Keyword.DEFAULT_KEYWORD_CHARS ):
super(CaselessKeyword,self).__init__( matchString, identCars, caseless=True )
def parseImpl( self, instring, loc, doActions=True ):
if ( (instring[ loc:loc+self.matchLen ].upper() == self.caselessmatch) and
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen].upper() not in self.identChars) ):
return loc+self.matchLen, self.match
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
class Word(Token):
"""Token for matching words composed of allowed character sets.
Defined with string containing all allowed initial characters,
an optional string containing allowed body characters (if omitted,
defaults to the initial character set), and an optional minimum,
maximum, and/or exact length.
"""
def __init__( self, initChars, bodyChars=None, min=1, max=0, exact=0 ):
super(Word,self).__init__()
self.initCharsOrig = initChars
self.initChars = _str2dict(initChars)
if bodyChars :
self.bodyCharsOrig = bodyChars
self.bodyChars = _str2dict(bodyChars)
else:
self.bodyCharsOrig = initChars
self.bodyChars = _str2dict(initChars)
self.maxSpecified = max > 0
self.minLen = min
if max > 0:
self.maxLen = max
else:
self.maxLen = sys.maxint
if exact > 0:
self.maxLen = exact
self.minLen = exact
self.name = _ustr(self)
self.errmsg = "Expected " + self.name
self.myException.msg = self.errmsg
self.mayIndexError = False
if ' ' not in self.initCharsOrig+self.bodyCharsOrig and (min==1 and max==0 and exact==0):
if self.bodyCharsOrig == self.initCharsOrig:
self.reString = "[%s]+" % _escapeRegexRangeChars(self.initCharsOrig)
elif len(self.bodyCharsOrig) == 1:
self.reString = "%s[%s]*" % \
(re.escape(self.initCharsOrig),
_escapeRegexRangeChars(self.bodyCharsOrig),)
else:
self.reString = "[%s][%s]*" % \
(_escapeRegexRangeChars(self.initCharsOrig),
_escapeRegexRangeChars(self.bodyCharsOrig),)
try:
self.re = re.compile( self.reString )
except:
self.re = None
def parseImpl( self, instring, loc, doActions=True ):
if self.re:
result = self.re.match(instring,loc)
if not result:
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
loc = result.end()
return loc,result.group()
if not(instring[ loc ] in self.initChars):
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
start = loc
loc += 1
instrlen = len(instring)
bodychars = self.bodyChars
maxloc = start + self.maxLen
maxloc = min( maxloc, instrlen )
while loc < maxloc and instring[loc] in bodychars:
loc += 1
throwException = False
if loc - start < self.minLen:
throwException = True
if self.maxSpecified and loc < instrlen and instring[loc] in bodychars:
throwException = True
if throwException:
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
return loc, instring[start:loc]
def __str__( self ):
try:
return super(Word,self).__str__()
except:
pass
if self.strRepr is None:
def charsAsStr(s):
if len(s)>4:
return s[:4]+"..."
else:
return s
if ( self.initCharsOrig != self.bodyCharsOrig ):
self.strRepr = "W:(%s,%s)" % ( charsAsStr(self.initCharsOrig), charsAsStr(self.bodyCharsOrig) )
else:
self.strRepr = "W:(%s)" % charsAsStr(self.initCharsOrig)
return self.strRepr
class Regex(Token):
"""Token for matching strings that match a given regular expression.
Defined with string specifying the regular expression in a form recognized by the inbuilt Python re module.
"""
def __init__( self, pattern, flags=0):
"""The parameters pattern and flags are passed to the re.compile() function as-is. See the Python re module for an explanation of the acceptable patterns and flags."""
super(Regex,self).__init__()
if len(pattern) == 0:
warnings.warn("null string passed to Regex; use Empty() instead",
SyntaxWarning, stacklevel=2)
self.pattern = pattern
self.flags = flags
try:
self.re = re.compile(self.pattern, self.flags)
self.reString = self.pattern
except Exception,e:
warnings.warn("invalid pattern (%s) passed to Regex" % pattern,
SyntaxWarning, stacklevel=2)
raise
self.name = _ustr(self)
self.errmsg = "Expected " + self.name
self.myException.msg = self.errmsg
self.mayIndexError = False
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
result = self.re.match(instring,loc)
if not result:
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
loc = result.end()
d = result.groupdict()
ret = ParseResults(result.group())
if d:
for k in d.keys():
ret[k] = d[k]
return loc,ret
def __str__( self ):
try:
return super(Regex,self).__str__()
except:
pass
if self.strRepr is None:
self.strRepr = "Re:(%s)" % repr(self.pattern)
return self.strRepr
class QuotedString(Token):
"""Token for matching strings that are delimited by quoting characters.
"""
def __init__( self, quoteChar, escChar=None, escQuote=None, multiline=False, unquoteResults=True):
"""
Defined with the following parameters:
- quoteCharacter - string of one or more characters defining the quote delimiting string
- escapeCharacter - character to escape quotes, typically backslash (default=None)
- escapedQuote - special quote sequence to escape an embedded quote string (such as SQL's "" to escape and embedded ") (default=None)
- multiline - boolean indicating whether quotes can span multiple lines (default=False)
- unquoteResults - boolean indicating whether the matched text should be unquoted (default=True)
"""
super(QuotedString,self).__init__()
# remove white space from quote char - wont work anyway
quoteChar = quoteChar.strip()
if len(quoteChar) == 0:
warnings.warn("quoteChar cannot be the empty string",SyntaxWarning,stacklevel=2)
raise SyntaxError()
self.quoteChar = quoteChar
self.quoteCharLen = len(quoteChar)
self.firstQuoteChar = quoteChar[0]
self.escChar = escChar
self.escQuote = escQuote
self.unquoteResults = unquoteResults
if multiline:
self.flags = re.MULTILINE | re.DOTALL
self.pattern = r'%s([^%s%s]' % \
( re.escape(self.quoteChar),
_escapeRegexRangeChars(self.quoteChar[0]),
(escChar is not None and _escapeRegexRangeChars(escChar) or '') )
else:
self.flags = 0
self.pattern = r'%s([^%s\n\r%s]' % \
( re.escape(self.quoteChar),
_escapeRegexRangeChars(self.quoteChar[0]),
(escChar is not None and _escapeRegexRangeChars(escChar) or '') )
if len(self.quoteChar) > 1:
self.pattern += (
'|(' + ')|('.join(["%s[^%s]" % (re.escape(self.quoteChar[:i]),
_escapeRegexRangeChars(self.quoteChar[i]))
for i in range(len(self.quoteChar)-1,0,-1)]) + ')'
)
if escQuote:
self.pattern += (r'|(%s)' % re.escape(escQuote))
if escChar:
self.pattern += (r'|(%s.)' % re.escape(escChar))
self.escCharReplacePattern = re.escape(self.escChar)+"(.)"
self.pattern += (r')*%s' % re.escape(self.quoteChar))
try:
self.re = re.compile(self.pattern, self.flags)
self.reString = self.pattern
except Exception,e:
warnings.warn("invalid pattern (%s) passed to Regex" % self.pattern,
SyntaxWarning, stacklevel=2)
raise
self.name = _ustr(self)
self.errmsg = "Expected " + self.name
self.myException.msg = self.errmsg
self.mayIndexError = False
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
result = instring[loc] == self.firstQuoteChar and self.re.match(instring,loc) or None
if not result:
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
loc = result.end()
ret = result.group()
if self.unquoteResults:
# strip off quotes
ret = ret[self.quoteCharLen:-self.quoteCharLen]
if isinstance(ret,basestring):
# replace escaped characters
if self.escChar:
ret = re.sub(self.escCharReplacePattern,"\g<1>",ret)
# replace escaped quotes
if self.escQuote:
ret = ret.replace(self.escQuote, self.quoteChar)
return loc, ret
def __str__( self ):
try:
return super(QuotedString,self).__str__()
except:
pass
if self.strRepr is None:
self.strRepr = "quoted string, delimited by %s characters" % self.quoteChar
return self.strRepr
class CharsNotIn(Token):
"""Token for matching words composed of characters *not* in a given set.
Defined with string containing all disallowed characters, and an optional
minimum, maximum, and/or exact length.
"""
def __init__( self, notChars, min=1, max=0, exact=0 ):
super(CharsNotIn,self).__init__()
self.skipWhitespace = False
self.notChars = notChars
self.minLen = min
if max > 0:
self.maxLen = max
else:
self.maxLen = sys.maxint
if exact > 0:
self.maxLen = exact
self.minLen = exact
self.name = _ustr(self)
self.errmsg = "Expected " + self.name
self.mayReturnEmpty = ( self.minLen == 0 )
self.myException.msg = self.errmsg
self.mayIndexError = False
def parseImpl( self, instring, loc, doActions=True ):
if instring[loc] in self.notChars:
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
start = loc
loc += 1
notchars = self.notChars
maxlen = min( start+self.maxLen, len(instring) )
while loc < maxlen and \
(instring[loc] not in notchars):
loc += 1
if loc - start < self.minLen:
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
return loc, instring[start:loc]
def __str__( self ):
try:
return super(CharsNotIn, self).__str__()
except:
pass
if self.strRepr is None:
if len(self.notChars) > 4:
self.strRepr = "!W:(%s...)" % self.notChars[:4]
else:
self.strRepr = "!W:(%s)" % self.notChars
return self.strRepr
class White(Token):
"""Special matching class for matching whitespace. Normally, whitespace is ignored
by pyparsing grammars. This class is included when some whitespace structures
are significant. Define with a string containing the whitespace characters to be
matched; default is " \\t\\n". Also takes optional min, max, and exact arguments,
as defined for the Word class."""
whiteStrs = {
" " : "<SPC>",
"\t": "<TAB>",
"\n": "<LF>",
"\r": "<CR>",
"\f": "<FF>",
}
def __init__(self, ws=" \t\r\n", min=1, max=0, exact=0):
super(White,self).__init__()
self.matchWhite = ws
self.whiteChars = "".join([c for c in self.whiteChars if c not in self.matchWhite])
#~ self.leaveWhitespace()
self.name = ("".join([White.whiteStrs[c] for c in self.matchWhite]))
self.mayReturnEmpty = True
self.errmsg = "Expected " + self.name
self.myException.msg = self.errmsg
self.minLen = min
if max > 0:
self.maxLen = max
else:
self.maxLen = sys.maxint
if exact > 0:
self.maxLen = exact
self.minLen = exact
def parseImpl( self, instring, loc, doActions=True ):
if not(instring[ loc ] in self.matchWhite):
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
start = loc
loc += 1
maxloc = start + self.maxLen
maxloc = min( maxloc, len(instring) )
while loc < maxloc and instring[loc] in self.matchWhite:
loc += 1
if loc - start < self.minLen:
#~ raise ParseException, ( instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
return loc, instring[start:loc]
class PositionToken(Token):
def __init__( self ):
super(PositionToken,self).__init__()
self.name=self.__class__.__name__
self.mayReturnEmpty = True
class GoToColumn(PositionToken):
"""Token to advance to a specific column of input text; useful for tabular report scraping."""
def __init__( self, colno ):
super(GoToColumn,self).__init__()
self.col = colno
def preParse( self, instring, loc ):
if col(loc,instring) != self.col:
instrlen = len(instring)
if self.ignoreExprs:
loc = self.skipIgnorables( instring, loc )
while loc < instrlen and instring[loc].isspace() and col( loc, instring ) != self.col :
loc += 1
return loc
def parseImpl( self, instring, loc, doActions=True ):
thiscol = col( loc, instring )
if thiscol > self.col:
raise ParseException, ( instring, loc, "Text not in expected column", self )
newloc = loc + self.col - thiscol
ret = instring[ loc: newloc ]
return newloc, ret
class LineStart(PositionToken):
"""Matches if current position is at the beginning of a line within the parse string"""
def __init__( self ):
super(LineStart,self).__init__()
self.whiteChars = " \t"
self.errmsg = "Expected start of line"
self.myException.msg = self.errmsg
def preParse( self, instring, loc ):
loc = super(LineStart,self).preParse(instring,loc)
if instring[loc] == "\n":
loc += 1
return loc
def parseImpl( self, instring, loc, doActions=True ):
if not( loc==0 or ( loc<len(instring) and instring[loc-1] == "\n" ) ): #col(loc, instring) != 1:
#~ raise ParseException, ( instring, loc, "Expected start of line" )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
return loc, []
class LineEnd(PositionToken):
"""Matches if current position is at the end of a line within the parse string"""
def __init__( self ):
super(LineEnd,self).__init__()
self.whiteChars = " \t"
self.errmsg = "Expected end of line"
self.myException.msg = self.errmsg
def parseImpl( self, instring, loc, doActions=True ):
if loc<len(instring):
if instring[loc] == "\n":
return loc+1, "\n"
else:
#~ raise ParseException, ( instring, loc, "Expected end of line" )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
else:
return loc, []
class StringStart(PositionToken):
"""Matches if current position is at the beginning of the parse string"""
def __init__( self ):
super(StringStart,self).__init__()
self.errmsg = "Expected start of text"
self.myException.msg = self.errmsg
def parseImpl( self, instring, loc, doActions=True ):
if loc != 0:
# see if entire string up to here is just whitespace and ignoreables
if loc != self.preParse( instring, 0 ):
#~ raise ParseException, ( instring, loc, "Expected start of text" )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
return loc, []
class StringEnd(PositionToken):
"""Matches if current position is at the end of the parse string"""
def __init__( self ):
super(StringEnd,self).__init__()
self.errmsg = "Expected end of text"
self.myException.msg = self.errmsg
def parseImpl( self, instring, loc, doActions=True ):
if loc < len(instring):
#~ raise ParseException, ( instring, loc, "Expected end of text" )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
return loc, []
class ParseExpression(ParserElement):
"""Abstract subclass of ParserElement, for combining and post-processing parsed tokens."""
def __init__( self, exprs, savelist = False ):
super(ParseExpression,self).__init__(savelist)
if isinstance( exprs, list ):
self.exprs = exprs
elif isinstance( exprs, basestring ):
self.exprs = [ Literal( exprs ) ]
else:
self.exprs = [ exprs ]
def __getitem__( self, i ):
return self.exprs[i]
def append( self, other ):
self.exprs.append( other )
self.strRepr = None
return self
def leaveWhitespace( self ):
"""Extends leaveWhitespace defined in base class, and also invokes leaveWhitespace on
all contained expressions."""
self.skipWhitespace = False
self.exprs = [ copy.copy(e) for e in self.exprs ]
for e in self.exprs:
e.leaveWhitespace()
return self
def ignore( self, other ):
if isinstance( other, Suppress ):
if other not in self.ignoreExprs:
super( ParseExpression, self).ignore( other )
for e in self.exprs:
e.ignore( self.ignoreExprs[-1] )
else:
super( ParseExpression, self).ignore( other )
for e in self.exprs:
e.ignore( self.ignoreExprs[-1] )
return self
def __str__( self ):
try:
return super(ParseExpression,self).__str__()
except:
pass
if self.strRepr is None:
self.strRepr = "%s:(%s)" % ( self.__class__.__name__, _ustr(self.exprs) )
return self.strRepr
def streamline( self ):
super(ParseExpression,self).streamline()
for e in self.exprs:
e.streamline()
# collapse nested And's of the form And( And( And( a,b), c), d) to And( a,b,c,d )
# but only if there are no parse actions or resultsNames on the nested And's
# (likewise for Or's and MatchFirst's)
if ( len(self.exprs) == 2 ):
other = self.exprs[0]
if ( isinstance( other, self.__class__ ) and
other.parseAction is None and
other.resultsName is None and
not other.debug ):
self.exprs = other.exprs[:] + [ self.exprs[1] ]
self.strRepr = None
other = self.exprs[-1]
if ( isinstance( other, self.__class__ ) and
other.parseAction is None and
other.resultsName is None and
not other.debug ):
self.exprs = self.exprs[:-1] + other.exprs[:]
self.strRepr = None
return self
def setResultsName( self, name, listAllMatches=False ):
ret = super(ParseExpression,self).setResultsName(name,listAllMatches)
#~ ret.saveAsList = True
return ret
def validate( self, validateTrace=[] ):
tmp = validateTrace[:]+[self]
for e in self.exprs:
e.validate(tmp)
self.checkRecursion( [] )
class And(ParseExpression):
"""Requires all given ParseExpressions to be found in the given order.
Expressions may be separated by whitespace.
May be constructed using the '+' operator.
"""
def __init__( self, exprs, savelist = True ):
super(And,self).__init__(exprs, savelist)
self.mayReturnEmpty = True
for e in exprs:
if not e.mayReturnEmpty:
self.mayReturnEmpty = False
break
self.skipWhitespace = exprs[0].skipWhitespace
self.whiteChars = exprs[0].whiteChars
def parseImpl( self, instring, loc, doActions=True ):
loc, resultlist = self.exprs[0].parse( instring, loc, doActions )
for e in self.exprs[1:]:
loc, exprtokens = e.parse( instring, loc, doActions )
if exprtokens or exprtokens.keys():
resultlist += exprtokens
return loc, resultlist
def __iadd__(self, other ):
if isinstance( other, basestring ):
other = Literal( other )
return self.append( other ) #And( [ self, other ] )
def checkRecursion( self, parseElementList ):
subRecCheckList = parseElementList[:] + [ self ]
for e in self.exprs:
e.checkRecursion( subRecCheckList )
if not e.mayReturnEmpty:
break
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + " ".join( [ _ustr(e) for e in self.exprs ] ) + "}"
return self.strRepr
class Or(ParseExpression):
"""Requires that at least one ParseExpression is found.
If two expressions match, the expression that matches the longest string will be used.
May be constructed using the '^' operator.
"""
def __init__( self, exprs, savelist = False ):
super(Or,self).__init__(exprs, savelist)
self.mayReturnEmpty = False
for e in exprs:
if e.mayReturnEmpty:
self.mayReturnEmpty = True
break
def parseImpl( self, instring, loc, doActions=True ):
maxExcLoc = -1
maxMatchLoc = -1
for e in self.exprs:
try:
loc2 = e.tryParse( instring, loc )
except ParseException, err:
if err.loc > maxExcLoc:
maxException = err
maxExcLoc = err.loc
except IndexError, err:
if len(instring) > maxExcLoc:
maxException = ParseException(instring,len(instring),e.errmsg,self)
maxExcLoc = len(instring)
else:
if loc2 > maxMatchLoc:
maxMatchLoc = loc2
maxMatchExp = e
if maxMatchLoc < 0:
if self.exprs:
raise maxException
else:
raise ParseException(instring, loc, "no defined alternatives to match", self)
return maxMatchExp.parse( instring, loc, doActions )
def __ixor__(self, other ):
if isinstance( other, basestring ):
other = Literal( other )
return self.append( other ) #Or( [ self, other ] )
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + " ^ ".join( [ _ustr(e) for e in self.exprs ] ) + "}"
return self.strRepr
def checkRecursion( self, parseElementList ):
subRecCheckList = parseElementList[:] + [ self ]
for e in self.exprs:
e.checkRecursion( subRecCheckList )
class MatchFirst(ParseExpression):
"""Requires that at least one ParseExpression is found.
If two expressions match, the first one listed is the one that will match.
May be constructed using the '|' operator.
"""
def __init__( self, exprs, savelist = False ):
super(MatchFirst,self).__init__(exprs, savelist)
if exprs:
self.mayReturnEmpty = False
for e in exprs:
if e.mayReturnEmpty:
self.mayReturnEmpty = True
break
else:
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
maxExcLoc = -1
for e in self.exprs:
try:
ret = e.parse( instring, loc, doActions )
return ret
except ParseException, err:
if err.loc > maxExcLoc:
maxException = err
maxExcLoc = err.loc
except IndexError, err:
if len(instring) > maxExcLoc:
maxException = ParseException(instring,len(instring),e.errmsg,self)
maxExcLoc = len(instring)
# only got here if no expression matched, raise exception for match that made it the furthest
else:
if self.exprs:
raise maxException
else:
raise ParseException(instring, loc, "no defined alternatives to match", self)
def __ior__(self, other ):
if isinstance( other, basestring ):
other = Literal( other )
return self.append( other ) #MatchFirst( [ self, other ] )
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + " | ".join( [ _ustr(e) for e in self.exprs ] ) + "}"
return self.strRepr
def checkRecursion( self, parseElementList ):
subRecCheckList = parseElementList[:] + [ self ]
for e in self.exprs:
e.checkRecursion( subRecCheckList )
class Each(ParseExpression):
"""Requires all given ParseExpressions to be found, but in any order.
Expressions may be separated by whitespace.
May be constructed using the '&' operator.
"""
def __init__( self, exprs, savelist = True ):
super(Each,self).__init__(exprs, savelist)
self.mayReturnEmpty = True
for e in exprs:
if not e.mayReturnEmpty:
self.mayReturnEmpty = False
break
self.skipWhitespace = True
self.optionals = [ e.expr for e in exprs if isinstance(e,Optional) ]
self.multioptionals = [ e.expr for e in exprs if isinstance(e,ZeroOrMore) ]
self.multirequired = [ e.expr for e in exprs if isinstance(e,OneOrMore) ]
self.required = [ e for e in exprs if not isinstance(e,(Optional,ZeroOrMore,OneOrMore)) ]
self.required += self.multirequired
def parseImpl( self, instring, loc, doActions=True ):
tmpLoc = loc
tmpReqd = self.required[:]
tmpOpt = self.optionals[:]
matchOrder = []
keepMatching = True
while keepMatching:
tmpExprs = tmpReqd + tmpOpt + self.multioptionals + self.multirequired
failed = []
for e in tmpExprs:
try:
tmpLoc = e.tryParse( instring, tmpLoc )
except ParseException:
failed.append(e)
else:
matchOrder.append(e)
if e in tmpReqd:
tmpReqd.remove(e)
elif e in tmpOpt:
tmpOpt.remove(e)
if len(failed) == len(tmpExprs):
keepMatching = False
if tmpReqd:
missing = ", ".join( [ str(e) for e in tmpReqd ] )
raise ParseException(instring,loc,"Missing one or more required elements (%s)" % missing )
resultlist = []
for e in matchOrder:
loc,results = e.parse(instring,loc,doActions)
resultlist.append(results)
finalResults = ParseResults([])
for r in resultlist:
dups = {}
for k in r.keys():
if k in finalResults.keys():
tmp = ParseResults(finalResults[k])
tmp += ParseResults(r[k])
dups[k] = tmp
finalResults += ParseResults(r)
for k,v in dups.items():
finalResults[k] = v
return loc, finalResults
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + " & ".join( [ _ustr(e) for e in self.exprs ] ) + "}"
return self.strRepr
def checkRecursion( self, parseElementList ):
subRecCheckList = parseElementList[:] + [ self ]
for e in self.exprs:
e.checkRecursion( subRecCheckList )
class ParseElementEnhance(ParserElement):
"""Abstract subclass of ParserElement, for combining and post-processing parsed tokens."""
def __init__( self, expr, savelist=False ):
super(ParseElementEnhance,self).__init__(savelist)
if isinstance( expr, basestring ):
expr = Literal(expr)
self.expr = expr
self.strRepr = None
if expr is not None:
self.mayIndexError = expr.mayIndexError
self.skipWhitespace = expr.skipWhitespace
self.whiteChars = expr.whiteChars
def parseImpl( self, instring, loc, doActions=True ):
if self.expr is not None:
return self.expr.parse( instring, loc, doActions )
else:
raise ParseException(instring,loc,"",self)
def leaveWhitespace( self ):
self.skipWhitespace = False
self.expr = copy.copy(self.expr)
if self.expr is not None:
self.expr.leaveWhitespace()
return self
def ignore( self, other ):
if isinstance( other, Suppress ):
if other not in self.ignoreExprs:
super( ParseElementEnhance, self).ignore( other )
if self.expr is not None:
self.expr.ignore( self.ignoreExprs[-1] )
else:
super( ParseElementEnhance, self).ignore( other )
if self.expr is not None:
self.expr.ignore( self.ignoreExprs[-1] )
return self
def streamline( self ):
super(ParseElementEnhance,self).streamline()
if self.expr is not None:
self.expr.streamline()
return self
def checkRecursion( self, parseElementList ):
if self in parseElementList:
raise RecursiveGrammarException( parseElementList+[self] )
subRecCheckList = parseElementList[:] + [ self ]
if self.expr is not None:
self.expr.checkRecursion( subRecCheckList )
def validate( self, validateTrace=[] ):
tmp = validateTrace[:]+[self]
if self.expr is not None:
self.expr.validate(tmp)
self.checkRecursion( [] )
def __str__( self ):
try:
return super(ParseElementEnhance,self).__str__()
except:
pass
if self.strRepr is None and self.expr is not None:
self.strRepr = "%s:(%s)" % ( self.__class__.__name__, _ustr(self.expr) )
return self.strRepr
class FollowedBy(ParseElementEnhance):
"""Lookahead matching of the given parse expression. FollowedBy
does *not* advance the parsing position within the input string, it only
verifies that the specified parse expression matches at the current
position. FollowedBy always returns a null token list."""
def __init__( self, expr ):
super(FollowedBy,self).__init__(expr)
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
self.expr.tryParse( instring, loc )
return loc, []
class NotAny(ParseElementEnhance):
"""Lookahead to disallow matching with the given parse expression. NotAny
does *not* advance the parsing position within the input string, it only
verifies that the specified parse expression does *not* match at the current
position. Also, NotAny does *not* skip over leading whitespace. NotAny
always returns a null token list. May be constructed using the '~' operator."""
def __init__( self, expr ):
super(NotAny,self).__init__(expr)
#~ self.leaveWhitespace()
self.skipWhitespace = False # do NOT use self.leaveWhitespace(), don't want to propagate to exprs
self.mayReturnEmpty = True
self.errmsg = "Found unexpected token, "+_ustr(self.expr)
self.myException = ParseException("",0,self.errmsg,self)
def parseImpl( self, instring, loc, doActions=True ):
try:
self.expr.tryParse( instring, loc )
except (ParseException,IndexError):
pass
else:
#~ raise ParseException, (instring, loc, self.errmsg )
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
return loc, []
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "~{" + _ustr(self.expr) + "}"
return self.strRepr
class ZeroOrMore(ParseElementEnhance):
"""Optional repetition of zero or more of the given expression."""
def __init__( self, expr ):
super(ZeroOrMore,self).__init__(expr)
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
tokens = []
try:
loc, tokens = self.expr.parse( instring, loc, doActions )
hasIgnoreExprs = ( len(self.ignoreExprs) > 0 )
while 1:
if hasIgnoreExprs:
loc = self.skipIgnorables( instring, loc )
loc, tmptokens = self.expr.parse( instring, loc, doActions )
if tmptokens or tmptokens.keys():
tokens += tmptokens
except (ParseException,IndexError):
pass
return loc, tokens
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "[" + _ustr(self.expr) + "]..."
return self.strRepr
def setResultsName( self, name, listAllMatches=False ):
ret = super(ZeroOrMore,self).setResultsName(name,listAllMatches)
ret.saveAsList = True
return ret
class OneOrMore(ParseElementEnhance):
"""Repetition of one or more of the given expression."""
def parseImpl( self, instring, loc, doActions=True ):
# must be at least one
loc, tokens = self.expr.parse( instring, loc, doActions )
try:
hasIgnoreExprs = ( len(self.ignoreExprs) > 0 )
while 1:
if hasIgnoreExprs:
loc = self.skipIgnorables( instring, loc )
loc, tmptokens = self.expr.parse( instring, loc, doActions )
if tmptokens or tmptokens.keys():
tokens += tmptokens
except (ParseException,IndexError):
pass
return loc, tokens
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + _ustr(self.expr) + "}..."
return self.strRepr
def setResultsName( self, name, listAllMatches=False ):
ret = super(OneOrMore,self).setResultsName(name,listAllMatches)
ret.saveAsList = True
return ret
class Optional(ParseElementEnhance):
"""Optional matching of the given expression.
A default return string can also be specified, if the optional expression
is not found.
"""
def __init__( self, exprs, default=None ):
super(Optional,self).__init__( exprs, savelist=False )
self.defaultValue = default
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
try:
loc, tokens = self.expr.parse( instring, loc, doActions )
except (ParseException,IndexError):
if self.defaultValue is not None:
tokens = [ self.defaultValue ]
else:
tokens = []
return loc, tokens
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "[" + _ustr(self.expr) + "]"
return self.strRepr
class SkipTo(ParseElementEnhance):
"""Token for skipping over all undefined text until the matched expression is found.
If include is set to true, the matched expression is also consumed. The ignore
argument is used to define grammars (typically quoted strings and comments) that
might contain false matches.
"""
def __init__( self, other, include=False, ignore=None ):
super( SkipTo, self ).__init__( other )
if ignore is not None:
self.expr = copy.copy( self.expr )
self.expr.ignore(ignore)
self.mayReturnEmpty = True
self.mayIndexError = False
self.includeMatch = include
self.errmsg = "No match found for "+_ustr(self.expr)
self.myException = ParseException("",0,self.errmsg,self)
def parseImpl( self, instring, loc, doActions=True ):
startLoc = loc
instrlen = len(instring)
expr = self.expr
while loc < instrlen:
try:
loc = expr.skipIgnorables( instring, loc )
expr.parse( instring, loc, doActions=False, callPreParse=False )
if self.includeMatch:
skipText = instring[startLoc:loc]
loc,mat = expr.parse(instring,loc)
if mat:
return loc, [ skipText, mat ]
else:
return loc, [ skipText ]
else:
return loc, [ instring[startLoc:loc] ]
except (ParseException,IndexError):
loc += 1
exc = self.myException
exc.loc = loc
exc.pstr = instring
raise exc
class Forward(ParseElementEnhance):
"""Forward declaration of an expression to be defined later -
used for recursive grammars, such as algebraic infix notation.
When the expression is known, it is assigned to the Forward variable using the '<<' operator.
Note: take care when assigning to Forward to not overlook precedence of operators.
Specifically, '|' has a lower precedence than '<<', so that::
fwdExpr << a | b | c
will actually be evaluated as::
(fwdExpr << a) | b | c
thereby leaving b and c out as parseable alternatives. It is recommended that you
explicitly group the values inserted into the Forward::
fwdExpr << (a | b | c)
"""
def __init__( self, other=None ):
super(Forward,self).__init__( other, savelist=False )
def __lshift__( self, other ):
self.expr = other
self.mayReturnEmpty = other.mayReturnEmpty
self.strRepr = None
return self
def leaveWhitespace( self ):
self.skipWhitespace = False
return self
def streamline( self ):
if not self.streamlined:
self.streamlined = True
if self.expr is not None:
self.expr.streamline()
return self
def validate( self, validateTrace=[] ):
if self not in validateTrace:
tmp = validateTrace[:]+[self]
if self.expr is not None:
self.expr.validate(tmp)
self.checkRecursion([])
def __str__( self ):
if hasattr(self,"name"):
return self.name
self.__class__ = _ForwardNoRecurse
try:
if self.expr is not None:
retString = _ustr(self.expr)
else:
retString = "None"
finally:
self.__class__ = Forward
return "Forward: "+retString
class _ForwardNoRecurse(Forward):
def __str__( self ):
return "..."
class TokenConverter(ParseElementEnhance):
"""Abstract subclass of ParseExpression, for converting parsed results."""
def __init__( self, expr, savelist=False ):
super(TokenConverter,self).__init__( expr )#, savelist )
class Upcase(TokenConverter):
"""Converter to upper case all matching tokens."""
def __init__(self, *args):
super(Upcase,self).__init__(*args)
warnings.warn("Upcase class is deprecated, use upcaseTokens parse action instead",
DeprecationWarning,stacklevel=2)
def postParse( self, instring, loc, tokenlist ):
return map( string.upper, tokenlist )
class Combine(TokenConverter):
"""Converter to concatenate all matching tokens to a single string.
By default, the matching patterns must also be contiguous in the input string;
this can be disabled by specifying 'adjacent=False' in the constructor.
"""
def __init__( self, expr, joinString="", adjacent=True ):
super(Combine,self).__init__( expr )
# suppress whitespace-stripping in contained parse expressions, but re-enable it on the Combine itself
if adjacent:
self.leaveWhitespace()
self.adjacent = adjacent
self.skipWhitespace = True
self.joinString = joinString
def ignore( self, other ):
if self.adjacent:
ParserElement.ignore(self, other)
else:
super( Combine, self).ignore( other )
return self
def postParse( self, instring, loc, tokenlist ):
retToks = tokenlist.copy()
del retToks[:]
retToks += ParseResults([ "".join(tokenlist._asStringList(self.joinString)) ], modal=self.modalResults)
if self.resultsName and len(retToks.keys())>0:
return [ retToks ]
else:
return retToks
class Group(TokenConverter):
"""Converter to return the matched tokens as a list - useful for returning tokens of ZeroOrMore and OneOrMore expressions."""
def __init__( self, expr ):
super(Group,self).__init__( expr )
self.saveAsList = True
def postParse( self, instring, loc, tokenlist ):
return [ tokenlist ]
class Dict(TokenConverter):
"""Converter to return a repetitive expression as a list, but also as a dictionary.
Each element can also be referenced using the first token in the expression as its key.
Useful for tabular report scraping when the first column can be used as a item key.
"""
def __init__( self, exprs ):
super(Dict,self).__init__( exprs )
self.saveAsList = True
def postParse( self, instring, loc, tokenlist ):
for i,tok in enumerate(tokenlist):
ikey = _ustr(tok[0]).strip()
if len(tok)==1:
tokenlist[ikey] = ("",i)
elif len(tok)==2 and not isinstance(tok[1],ParseResults):
tokenlist[ikey] = (tok[1],i)
else:
dictvalue = tok.copy() #ParseResults(i)
del dictvalue[0]
if len(dictvalue)!= 1 or (isinstance(dictvalue,ParseResults) and dictvalue.keys()):
tokenlist[ikey] = (dictvalue,i)
else:
tokenlist[ikey] = (dictvalue[0],i)
if self.resultsName:
return [ tokenlist ]
else:
return tokenlist
class Suppress(TokenConverter):
"""Converter for ignoring the results of a parsed expression."""
def postParse( self, instring, loc, tokenlist ):
return []
def suppress( self ):
return self
#
# global helpers
#
def delimitedList( expr, delim=",", combine=False ):
"""Helper to define a delimited list of expressions - the delimiter defaults to ','.
By default, the list elements and delimiters can have intervening whitespace, and
comments, but this can be overridden by passing 'combine=True' in the constructor.
If combine is set to True, the matching tokens are returned as a single token
string, with the delimiters included; otherwise, the matching tokens are returned
as a list of tokens, with the delimiters suppressed.
"""
if combine:
return Combine( expr + ZeroOrMore( delim + expr ) ).setName(_ustr(expr)+_ustr(delim)+"...")
else:
return ( expr + ZeroOrMore( Suppress( delim ) + expr ) ).setName(_ustr(expr)+_ustr(delim)+"...")
def _escapeRegexRangeChars(s):
#~ escape these chars: ^-]
for c in r"\^-]":
s = s.replace(c,"\\"+c)
s = s.replace("\n",r"\n")
s = s.replace("\t",r"\t")
return _ustr(s)
def oneOf( strs, caseless=False, useRegex=True ):
"""Helper to quickly define a set of alternative Literals, and makes sure to do
longest-first testing when there is a conflict, regardless of the input order,
but returns a MatchFirst for best performance.
Parameters:
- strs - a string of space-delimited literals, or a list of string literals
- caseless - (default=False) - treat all literals as caseless
- useRegex - (default=True) - as an optimization, will generate a Regex
object; otherwise, will generate a MatchFirst object (if caseless=True, or
if creating a Regex raises an exception)
"""
if caseless:
isequal = ( lambda a,b: a.upper() == b.upper() )
masks = ( lambda a,b: b.upper().startswith(a.upper()) )
parseElementClass = CaselessLiteral
else:
isequal = ( lambda a,b: a == b )
masks = ( lambda a,b: b.startswith(a) )
parseElementClass = Literal
if isinstance(strs,list):
symbols = strs[:]
elif isinstance(strs,basestring):
symbols = strs.split()
else:
warnings.warn("Invalid argument to oneOf, expected string or list",
SyntaxWarning, stacklevel=2)
i = 0
while i < len(symbols)-1:
cur = symbols[i]
for j,other in enumerate(symbols[i+1:]):
if ( isequal(other, cur) ):
del symbols[i+j+1]
break
elif ( masks(cur, other) ):
del symbols[i+j+1]
symbols.insert(i,other)
cur = other
break
else:
i += 1
if not caseless and useRegex:
#~ print strs,"->", "|".join( [ _escapeRegexChars(sym) for sym in symbols] )
try:
if len(symbols)==len("".join(symbols)):
return Regex( "[%s]" % "".join( [ _escapeRegexRangeChars(sym) for sym in symbols] ) )
else:
return Regex( "|".join( [ re.escape(sym) for sym in symbols] ) )
except:
warnings.warn("Exception creating Regex for oneOf, building MatchFirst",
SyntaxWarning, stacklevel=2)
# last resort, just use MatchFirst
return MatchFirst( [ parseElementClass(sym) for sym in symbols ] )
def dictOf( key, value ):
"""Helper to easily and clearly define a dictionary by specifying the respective patterns
for the key and value. Takes care of defining the Dict, ZeroOrMore, and Group tokens
in the proper order. The key pattern can include delimiting markers or punctuation,
as long as they are suppressed, thereby leaving the significant key text. The value
pattern can include named results, so that the Dict results can include named token
fields.
"""
return Dict( ZeroOrMore( Group ( key + value ) ) )
_bslash = "\\"
printables = "".join( [ c for c in string.printable if c not in string.whitespace ] )
# convenience constants for positional expressions
empty = Empty().setName("empty")
lineStart = LineStart().setName("lineStart")
lineEnd = LineEnd().setName("lineEnd")
stringStart = StringStart().setName("stringStart")
stringEnd = StringEnd().setName("stringEnd")
_escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
_printables_less_backslash = "".join([ c for c in printables if c not in r"\]" ])
_escapedHexChar = Combine( Suppress(_bslash + "0x") + Word(hexnums) ).setParseAction(lambda s,l,t:unichr(int(t[0],16)))
_escapedOctChar = Combine( Suppress(_bslash) + Word("0","01234567") ).setParseAction(lambda s,l,t:unichr(int(t[0],8)))
_singleChar = _escapedPunc | _escapedHexChar | _escapedOctChar | Word(_printables_less_backslash,exact=1)
_charRange = Group(_singleChar + Suppress("-") + _singleChar)
_reBracketExpr = "[" + Optional("^").setResultsName("negate") + Group( OneOrMore( _charRange | _singleChar ) ).setResultsName("body") + "]"
_expanded = lambda p: (isinstance(p,ParseResults) and ''.join([ unichr(c) for c in range(ord(p[0]),ord(p[1])+1) ]) or p)
def srange(s):
r"""Helper to easily define string ranges for use in Word construction. Borrows
syntax from regexp '[]' string range definitions::
srange("[0-9]") -> "0123456789"
srange("[a-z]") -> "abcdefghijklmnopqrstuvwxyz"
srange("[a-z$_]") -> "abcdefghijklmnopqrstuvwxyz$_"
The input string must be enclosed in []'s, and the returned string is the expanded
character set joined into a single string.
The values enclosed in the []'s may be::
a single character
an escaped character with a leading backslash (such as \- or \])
an escaped hex character with a leading '\0x' (\0x21, which is a '!' character)
an escaped octal character with a leading '\0' (\041, which is a '!' character)
a range of any of the above, separated by a dash ('a-z', etc.)
any combination of the above ('aeiouy', 'a-zA-Z0-9_$', etc.)
"""
try:
return "".join([_expanded(part) for part in _reBracketExpr.parseString(s).body])
except:
return ""
def replaceWith(replStr):
"""Helper method for common parse actions that simply return a literal value. Especially
useful when used with transformString().
"""
def _replFunc(*args):
return [replStr]
return _replFunc
def removeQuotes(s,l,t):
"""Helper parse action for removing quotation marks from parsed quoted strings.
To use, add this parse action to quoted string using::
quotedString.setParseAction( removeQuotes )
"""
return t[0][1:-1]
def upcaseTokens(s,l,t):
"""Helper parse action to convert tokens to upper case."""
return map( str.upper, t )
def downcaseTokens(s,l,t):
"""Helper parse action to convert tokens to lower case."""
return map( str.lower, t )
def _makeTags(tagStr, xml):
"""Internal helper to construct opening and closing tag expressions, given a tag name"""
tagAttrName = Word(alphanums)
if (xml):
tagAttrValue = dblQuotedString.copy().setParseAction( removeQuotes )
openTag = Suppress("<") + Keyword(tagStr) + \
Dict(ZeroOrMore(Group( tagAttrName + Suppress("=") + tagAttrValue ))) + \
Optional("/",default=[False]).setResultsName("empty").setParseAction(lambda s,l,t:t[0]=='/') + Suppress(">")
else:
printablesLessRAbrack = "".join( [ c for c in printables if c not in ">" ] )
tagAttrValue = quotedString.copy().setParseAction( removeQuotes ) | Word(printablesLessRAbrack)
openTag = Suppress("<") + Keyword(tagStr,caseless=True) + \
Dict(ZeroOrMore(Group( tagAttrName.setParseAction(downcaseTokens) + \
Suppress("=") + tagAttrValue ))) + \
Optional("/",default=[False]).setResultsName("empty").setParseAction(lambda s,l,t:t[0]=='/') + Suppress(">")
closeTag = Combine("</" + Keyword(tagStr,caseless=not xml) + ">")
openTag = openTag.setResultsName("start"+"".join(tagStr.replace(":"," ").title().split())).setName("<%s>" % tagStr)
closeTag = closeTag.setResultsName("end"+"".join(tagStr.replace(":"," ").title().split())).setName("</%s>" % tagStr)
return openTag, closeTag
def makeHTMLTags(tagStr):
"""Helper to construct opening and closing tag expressions for HTML, given a tag name"""
return _makeTags( tagStr, False )
def makeXMLTags(tagStr):
"""Helper to construct opening and closing tag expressions for XML, given a tag name"""
return _makeTags( tagStr, True )
alphas8bit = srange(r"[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xfe]")
_escapedChar = Regex(r"\\.")
dblQuotedString = Regex(r'"([^"\n\r\\]|("")|(\\.))*"').setName("string enclosed in double quotes")
sglQuotedString = Regex(r"'([^'\n\r\\]|('')|(\\.))*'").setName("string enclosed in single quotes")
quotedString = Regex(r'''("([^"\n\r\\]|("")|(\\.))*")|('([^'\n\r\\]|('')|(\\.))*')''').setName("quotedString using single or double quotes")
# it's easy to get these comment structures wrong - they're very common, so may as well make them available
cStyleComment = Regex(r"\/\*[\s\S]*?\*\/").setName("C style comment")
htmlComment = Regex(r"<!--[\s\S]*?-->")
restOfLine = Regex(r".*").leaveWhitespace()
dblSlashComment = Regex(r"\/\/.*").setName("// comment")
cppStyleComment = Regex(r"(\/\*[\s\S]*?\*\/)|(\/\/.*)").setName("C++ style comment")
javaStyleComment = cppStyleComment
pythonStyleComment = Regex(r"#.*").setName("Python style comment")
_noncomma = "".join( [ c for c in printables if c != "," ] )
_commasepitem = Combine(OneOrMore(Word(_noncomma) +
Optional( Word(" \t") +
~Literal(",") + ~LineEnd() ) ) ).streamline().setName("commaItem")
commaSeparatedList = delimitedList( Optional( quotedString | _commasepitem, default="") ).setName("commaSeparatedList")
if __name__ == "__main__":
def test( teststring ):
print teststring,"->",
try:
tokens = simpleSQL.parseString( teststring )
tokenlist = tokens.asList()
print tokenlist
print "tokens = ", tokens
print "tokens.columns =", tokens.columns
print "tokens.tables =", tokens.tables
print tokens.asXML("SQL",True)
except ParseException, err:
print err.line
print " "*(err.column-1) + "^"
print err
print
selectToken = CaselessLiteral( "select" )
fromToken = CaselessLiteral( "from" )
ident = Word( alphas, alphanums + "_$" )
columnName = delimitedList( ident, ".", combine=True ).setParseAction( upcaseTokens )
columnNameList = Group( delimitedList( columnName ) )#.setName("columns")
tableName = delimitedList( ident, ".", combine=True ).setParseAction( upcaseTokens )
tableNameList = Group( delimitedList( tableName ) )#.setName("tables")
simpleSQL = ( selectToken + \
( '*' | columnNameList ).setResultsName( "columns" ) + \
fromToken + \
tableNameList.setResultsName( "tables" ) )
test( "SELECT * from XYZZY, ABC" )
test( "select * from SYS.XYZZY" )
test( "Select A from Sys.dual" )
test( "Select AA,BB,CC from Sys.dual" )
test( "Select A, B, C from Sys.dual" )
test( "Select A, B, C from Sys.dual" )
test( "Xelect A, B, C from Sys.dual" )
test( "Select A, B, C frox Sys.dual" )
test( "Select" )
test( "Select ^^^ frox Sys.dual" )
test( "Select A, B, C from Sys.dual, Table2 " )
|
agpl-3.0
|
[
3,
859,
23943,
14,
647,
202,
199,
3,
202,
199,
3,
1898,
334,
67,
9,
13004,
13,
7968,
221,
28574,
377,
14,
22895,
4324,
264,
202,
199,
3,
202,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
202,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
202,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
202,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
202,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
202,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
202,
199,
3,
314,
2569,
3704,
26,
202,
199,
3,
202,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
202,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
202,
199,
3,
202,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
202,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
202,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
202,
199,
3,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
202,
199,
3,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
202,
199,
3,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
202,
199,
3,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
202,
199,
3,
202,
199,
3,
221,
377,
19657,
26,
202,
199,
3,
221,
446,
1050,
10933,
342,
446,
7268,
13,
1361,
1072,
402,
3247,
699,
19749,
202,
199,
3,
202,
199,
3,
504,
636,
2443,
363,
492,
16952,
2999,
199,
363,
1301,
363,
275,
971,
202,
199,
624,
202,
199,
647,
11059,
859,
446,
27939,
436,
3102,
370,
5627,
436,
5341,
6057,
1999,
596,
4291,
2999,
199,
1918,
23943,
859,
365,
376,
13943,
18140,
370,
6425,
436,
14043,
3486,
1999,
596,
4291,
12,
20712,
199,
3122,
14,
314,
1468,
2603,
7103,
15,
27319,
18140,
12,
503,
314,
675,
402,
5578,
8455,
14,
221,
8777,
23943,
12,
1265,
202,
199,
13196,
1133,
1929,
370,
12537,
282,
892,
6302,
367,
12669,
1999,
596,
4291,
503,
4877,
8455,
446,
314,
6057,
859,
20712,
199,
20121,
282,
3555,
402,
3992,
626,
1265,
675,
370,
6982,
314,
12528,
5370,
315,
2018,
14,
2999,
199,
21741,
365,
282,
2240,
370,
2198,
298,
6257,
12,
13064,
9539,
334,
269,
1263,
486,
23457,
402,
314,
1824,
3886,
6327,
10326,
6244,
665,
525,
470,
3239,
30,
1,
2349,
26,
2958,
687,
23943,
492,
14644,
12,
25363,
11787,
327,
5627,
12528,
402,
282,
486,
23457,
1128,
486,
7936,
275,
14644,
8,
25363,
776,
435,
21147,
435,
14644,
8,
25363,
776,
435,
298,
9539,
221,
11787,
16509,
275,
298,
6257,
12,
13064,
9539,
1128,
870,
16509,
12,
3905,
7166,
486,
7936,
14,
14934,
8,
16509,
776,
2999,
199,
1918,
2240,
4704,
314,
2569,
447,
2958,
23833,
12,
13064,
1,
1035,
788,
6257,
297,
30048,
283,
15943,
297,
14597,
418,
2999,
199,
1918,
2018,
6025,
402,
314,
12528,
365,
18794,
12701,
12,
22182,
316,
370,
314,
291,
13,
476,
5140,
8658,
20712,
199,
533,
1561,
12,
436,
314,
675,
402,
32278,
24628,
436,
14452,
7,
10211,
14,
2999,
199,
1918,
4565,
2058,
2138,
687,
2198,
1558,
342,
883,
506,
13810,
465,
282,
6032,
769,
12,
282,
2600,
12,
503,
376,
20712,
199,
785,
543,
4310,
3004,
14,
2999,
199,
1918,
23943,
859,
10022,
2005,
402,
314,
8826,
626,
787,
13609,
373,
476,
316,
1380,
3575,
1318,
21295,
26,
1223,
446,
2402,
503,
4124,
8139,
334,
1589,
3432,
2240,
911,
2597,
2429,
298,
6257,
12,
15943,
17716,
298,
6257,
221,
2360,
221,
13064,
221,
8546,
401,
5423,
4959,
1223,
446,
10999,
3326,
1223,
446,
12169,
6786,
202,
199,
624,
202,
199,
363,
1023,
363,
275,
298,
17,
14,
20,
14,
17,
2,
202,
199,
363,
1023,
1366,
363,
275,
298,
1717,
21141,
26709,
8315,
3144,
26,
1194,
2,
202,
199,
363,
2502,
363,
275,
298,
28282,
22895,
4324,
264,
665,
541,
5466,
71,
32,
3707,
14,
22943,
14,
846,
4335,
2999,
199,
646,
1059,
202,
199,
646,
1331,
12,
1274,
202,
199,
646,
3598,
202,
199,
646,
295,
202,
199,
32169,
984,
14,
3083,
14,
952,
8,
298,
4776,
23943,
859,
12,
1015,
450,
83,
12,
450,
83,
60,
78,
2,
450,
25373,
1023,
3108,
363,
1023,
1366,
363,
776,
776,
2999,
199,
318,
485,
11409,
8,
1113,
304,
1128,
408,
11070,
13,
262,
8343,
367,
620,
8,
1113,
9,
626,
11275,
370,
506,
6140,
21428,
14,
2779,
1642,
11275,
22132,
620,
8,
1113,
680,
982,
626,
6918,
543,
282,
24094,
12,
2066,
652,
11275,
2649,
8,
1113,
680,
2779,
22132,
2066,
665,
2529,
314,
2649,
909,
1204,
3752,
83,
652,
543,
314,
849,
2644,
1204,
2263,
690,
14,
1128,
408,
1128,
862,
26,
1039,
327,
982,
642,
5419,
12,
2066,
485,
11409,
8,
1113,
9,
965,
314,
2011,
13942,
465,
620,
8,
1113,
395,
880,
1039,
327,
652,
7859,
1133,
2059,
1263,
3411,
1233,
14,
1039,
372,
620,
8,
1113,
9,
26016,
871,
24094,
12,
325,
26,
1039,
327,
710,
2018,
9149,
334,
1014,
921,
4757,
14,
1548,
14,
1308,
15,
1121,
15,
4229,
2072,
14,
1360,
3,
76,
18,
72,
13,
12894,
9,
1039,
327,
1174,
626,
298,
1918,
372,
574,
1471,
506,
282,
1059,
909,
1674,
9738,
12,
1630,
282,
1039,
327,
2649,
909,
334,
1235,
316,
282,
5516,
402,
7116,
9,
2338,
465,
282,
298,
875,
1039,
327,
909,
14863,
1039,
327,
982,
880,
12,
2066,
372,
282,
2649,
909,
26,
1039,
372,
2649,
8,
1113,
9,
1039,
327,
19524,
3752,
652,
1396,
1325,
4212,
31,
6006,
787,
5002,
3415,
1396,
32428,
1039,
327,
14402,
625,
1361,
5921,
543,
4772,
9479,
31,
1039,
327,
1107,
2649,
8,
1113,
680,
2143,
8,
1274,
14,
362,
27205,
28139,
1062,
283,
21509,
1814,
63,
2550,
358,
1039,
327,
14402,
625,
1361,
5921,
543,
7894,
17370,
31,
1039,
327,
1107,
2649
] |
[
859,
23943,
14,
647,
202,
199,
3,
202,
199,
3,
1898,
334,
67,
9,
13004,
13,
7968,
221,
28574,
377,
14,
22895,
4324,
264,
202,
199,
3,
202,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
202,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
202,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
202,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
202,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
202,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
202,
199,
3,
314,
2569,
3704,
26,
202,
199,
3,
202,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
202,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
202,
199,
3,
202,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
202,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
202,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
202,
199,
3,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
202,
199,
3,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
202,
199,
3,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
202,
199,
3,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
202,
199,
3,
202,
199,
3,
221,
377,
19657,
26,
202,
199,
3,
221,
446,
1050,
10933,
342,
446,
7268,
13,
1361,
1072,
402,
3247,
699,
19749,
202,
199,
3,
202,
199,
3,
504,
636,
2443,
363,
492,
16952,
2999,
199,
363,
1301,
363,
275,
971,
202,
199,
624,
202,
199,
647,
11059,
859,
446,
27939,
436,
3102,
370,
5627,
436,
5341,
6057,
1999,
596,
4291,
2999,
199,
1918,
23943,
859,
365,
376,
13943,
18140,
370,
6425,
436,
14043,
3486,
1999,
596,
4291,
12,
20712,
199,
3122,
14,
314,
1468,
2603,
7103,
15,
27319,
18140,
12,
503,
314,
675,
402,
5578,
8455,
14,
221,
8777,
23943,
12,
1265,
202,
199,
13196,
1133,
1929,
370,
12537,
282,
892,
6302,
367,
12669,
1999,
596,
4291,
503,
4877,
8455,
446,
314,
6057,
859,
20712,
199,
20121,
282,
3555,
402,
3992,
626,
1265,
675,
370,
6982,
314,
12528,
5370,
315,
2018,
14,
2999,
199,
21741,
365,
282,
2240,
370,
2198,
298,
6257,
12,
13064,
9539,
334,
269,
1263,
486,
23457,
402,
314,
1824,
3886,
6327,
10326,
6244,
665,
525,
470,
3239,
30,
1,
2349,
26,
2958,
687,
23943,
492,
14644,
12,
25363,
11787,
327,
5627,
12528,
402,
282,
486,
23457,
1128,
486,
7936,
275,
14644,
8,
25363,
776,
435,
21147,
435,
14644,
8,
25363,
776,
435,
298,
9539,
221,
11787,
16509,
275,
298,
6257,
12,
13064,
9539,
1128,
870,
16509,
12,
3905,
7166,
486,
7936,
14,
14934,
8,
16509,
776,
2999,
199,
1918,
2240,
4704,
314,
2569,
447,
2958,
23833,
12,
13064,
1,
1035,
788,
6257,
297,
30048,
283,
15943,
297,
14597,
418,
2999,
199,
1918,
2018,
6025,
402,
314,
12528,
365,
18794,
12701,
12,
22182,
316,
370,
314,
291,
13,
476,
5140,
8658,
20712,
199,
533,
1561,
12,
436,
314,
675,
402,
32278,
24628,
436,
14452,
7,
10211,
14,
2999,
199,
1918,
4565,
2058,
2138,
687,
2198,
1558,
342,
883,
506,
13810,
465,
282,
6032,
769,
12,
282,
2600,
12,
503,
376,
20712,
199,
785,
543,
4310,
3004,
14,
2999,
199,
1918,
23943,
859,
10022,
2005,
402,
314,
8826,
626,
787,
13609,
373,
476,
316,
1380,
3575,
1318,
21295,
26,
1223,
446,
2402,
503,
4124,
8139,
334,
1589,
3432,
2240,
911,
2597,
2429,
298,
6257,
12,
15943,
17716,
298,
6257,
221,
2360,
221,
13064,
221,
8546,
401,
5423,
4959,
1223,
446,
10999,
3326,
1223,
446,
12169,
6786,
202,
199,
624,
202,
199,
363,
1023,
363,
275,
298,
17,
14,
20,
14,
17,
2,
202,
199,
363,
1023,
1366,
363,
275,
298,
1717,
21141,
26709,
8315,
3144,
26,
1194,
2,
202,
199,
363,
2502,
363,
275,
298,
28282,
22895,
4324,
264,
665,
541,
5466,
71,
32,
3707,
14,
22943,
14,
846,
4335,
2999,
199,
646,
1059,
202,
199,
646,
1331,
12,
1274,
202,
199,
646,
3598,
202,
199,
646,
295,
202,
199,
32169,
984,
14,
3083,
14,
952,
8,
298,
4776,
23943,
859,
12,
1015,
450,
83,
12,
450,
83,
60,
78,
2,
450,
25373,
1023,
3108,
363,
1023,
1366,
363,
776,
776,
2999,
199,
318,
485,
11409,
8,
1113,
304,
1128,
408,
11070,
13,
262,
8343,
367,
620,
8,
1113,
9,
626,
11275,
370,
506,
6140,
21428,
14,
2779,
1642,
11275,
22132,
620,
8,
1113,
680,
982,
626,
6918,
543,
282,
24094,
12,
2066,
652,
11275,
2649,
8,
1113,
680,
2779,
22132,
2066,
665,
2529,
314,
2649,
909,
1204,
3752,
83,
652,
543,
314,
849,
2644,
1204,
2263,
690,
14,
1128,
408,
1128,
862,
26,
1039,
327,
982,
642,
5419,
12,
2066,
485,
11409,
8,
1113,
9,
965,
314,
2011,
13942,
465,
620,
8,
1113,
395,
880,
1039,
327,
652,
7859,
1133,
2059,
1263,
3411,
1233,
14,
1039,
372,
620,
8,
1113,
9,
26016,
871,
24094,
12,
325,
26,
1039,
327,
710,
2018,
9149,
334,
1014,
921,
4757,
14,
1548,
14,
1308,
15,
1121,
15,
4229,
2072,
14,
1360,
3,
76,
18,
72,
13,
12894,
9,
1039,
327,
1174,
626,
298,
1918,
372,
574,
1471,
506,
282,
1059,
909,
1674,
9738,
12,
1630,
282,
1039,
327,
2649,
909,
334,
1235,
316,
282,
5516,
402,
7116,
9,
2338,
465,
282,
298,
875,
1039,
327,
909,
14863,
1039,
327,
982,
880,
12,
2066,
372,
282,
2649,
909,
26,
1039,
372,
2649,
8,
1113,
9,
1039,
327,
19524,
3752,
652,
1396,
1325,
4212,
31,
6006,
787,
5002,
3415,
1396,
32428,
1039,
327,
14402,
625,
1361,
5921,
543,
4772,
9479,
31,
1039,
327,
1107,
2649,
8,
1113,
680,
2143,
8,
1274,
14,
362,
27205,
28139,
1062,
283,
21509,
1814,
63,
2550,
358,
1039,
327,
14402,
625,
1361,
5921,
543,
7894,
17370,
31,
1039,
327,
1107,
2649,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vitaly4uk/django
|
tests/resolve_url/tests.py
|
199
|
3167
|
from __future__ import unicode_literals
from django.contrib.auth.views import logout
from django.core.urlresolvers import NoReverseMatch, reverse_lazy
from django.shortcuts import resolve_url
from django.test import SimpleTestCase, ignore_warnings, override_settings
from django.utils import six
from django.utils.deprecation import RemovedInDjango110Warning
from .models import UnimportantThing
@override_settings(ROOT_URLCONF='resolve_url.urls')
class ResolveUrlTests(SimpleTestCase):
"""
Tests for the ``resolve_url`` function.
"""
def test_url_path(self):
"""
Tests that passing a URL path to ``resolve_url`` will result in the
same url.
"""
self.assertEqual('/something/', resolve_url('/something/'))
def test_relative_path(self):
"""
Tests that passing a relative URL path to ``resolve_url`` will result
in the same url.
"""
self.assertEqual('../', resolve_url('../'))
self.assertEqual('../relative/', resolve_url('../relative/'))
self.assertEqual('./', resolve_url('./'))
self.assertEqual('./relative/', resolve_url('./relative/'))
def test_full_url(self):
"""
Tests that passing a full URL to ``resolve_url`` will result in the
same url.
"""
url = 'http://example.com/'
self.assertEqual(url, resolve_url(url))
def test_model(self):
"""
Tests that passing a model to ``resolve_url`` will result in
``get_absolute_url`` being called on that model instance.
"""
m = UnimportantThing(importance=1)
self.assertEqual(m.get_absolute_url(), resolve_url(m))
def test_view_function(self):
"""
Tests that passing a view name to ``resolve_url`` will result in the
URL path mapping to that view name.
"""
resolved_url = resolve_url(logout)
self.assertEqual('/accounts/logout/', resolved_url)
def test_lazy_reverse(self):
"""
Tests that passing the result of reverse_lazy is resolved to a real URL
string.
"""
resolved_url = resolve_url(reverse_lazy('logout'))
self.assertIsInstance(resolved_url, six.text_type)
self.assertEqual('/accounts/logout/', resolved_url)
@ignore_warnings(category=RemovedInDjango110Warning)
def test_valid_view_name(self):
"""
Tests that passing a view function to ``resolve_url`` will result in
the URL path mapping to that view.
"""
resolved_url = resolve_url('django.contrib.auth.views.logout')
self.assertEqual('/accounts/logout/', resolved_url)
def test_domain(self):
"""
Tests that passing a domain to ``resolve_url`` returns the same domain.
"""
self.assertEqual(resolve_url('example.com'), 'example.com')
def test_non_view_callable_raises_no_reverse_match(self):
"""
Tests that passing a non-view callable into ``resolve_url`` raises a
``NoReverseMatch`` exception.
"""
with self.assertRaises(NoReverseMatch):
resolve_url(lambda: 'asdf')
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4196,
492,
22079,
199,
504,
1639,
14,
1018,
14,
16522,
492,
32036,
12,
3837,
63,
6395,
199,
504,
1639,
14,
17469,
492,
7512,
63,
633,
199,
504,
1639,
14,
396,
492,
24424,
12,
3686,
63,
5451,
12,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
6019,
3849,
199,
199,
504,
1275,
992,
492,
1910,
19559,
32218,
421,
199,
32,
4415,
63,
1751,
8,
5441,
63,
18125,
534,
6983,
63,
633,
14,
3603,
358,
199,
533,
31096,
6417,
2925,
8,
17968,
304,
272,
408,
272,
6496,
367,
314,
1124,
6983,
63,
633,
1040,
805,
14,
272,
408,
339,
347,
511,
63,
633,
63,
515,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2851,
931,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
314,
267,
2011,
1166,
14,
267,
408,
267,
291,
14,
629,
2336,
10297,
3678,
7512,
63,
633,
2336,
10297,
15,
1333,
339,
347,
511,
63,
6188,
63,
515,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
3847,
2851,
931,
370,
1124,
6983,
63,
633,
1040,
911,
754,
267,
315,
314,
2011,
1166,
14,
267,
408,
267,
291,
14,
629,
24893,
3678,
7512,
63,
633,
24592,
1333,
267,
291,
14,
629,
24592,
6188,
3678,
7512,
63,
633,
24592,
6188,
15,
1333,
267,
291,
14,
629,
5175,
3678,
7512,
63,
633,
17371,
1333,
267,
291,
14,
629,
17371,
6188,
3678,
7512,
63,
633,
17371,
6188,
15,
1333,
339,
347,
511,
63,
2861,
63,
633,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2615,
2851,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
314,
267,
2011,
1166,
14,
267,
408,
267,
1166,
275,
283,
1014,
921,
2694,
14,
957,
4805,
267,
291,
14,
629,
8,
633,
12,
7512,
63,
633,
8,
633,
430,
339,
347,
511,
63,
1238,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
1402,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
267,
1124,
362,
63,
6116,
63,
633,
1040,
3769,
2797,
641,
626,
1402,
1256,
14,
267,
408,
267,
333,
275,
1910,
19559,
32218,
8,
646,
554,
29,
17,
9,
267,
291,
14,
629,
8,
77,
14,
362,
63,
6116,
63,
633,
1062,
7512,
63,
633,
8,
77,
430,
339,
347,
511,
63,
1345,
63,
1593,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2455,
536,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
314,
267,
2851,
931,
4412,
370,
626,
2455,
536,
14,
267,
408,
267,
12152,
63,
633,
275,
7512,
63,
633,
8,
11646,
9,
267,
291,
14,
629,
2336,
8370,
15,
11646,
3678,
12152,
63,
633,
9,
339,
347,
511,
63,
6395,
63,
4471,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
314,
754,
402,
3837,
63,
6395,
365,
12152,
370,
282,
3363,
2851,
267,
1059,
14,
267,
408,
267,
12152,
63,
633,
275,
7512,
63,
633,
8,
4471,
63,
6395,
360,
11646,
1333,
267,
291,
14,
6926,
8,
13697,
63,
633,
12,
3816,
14,
505,
63,
466,
9,
267,
291,
14,
629,
2336,
8370,
15,
11646,
3678,
12152,
63,
633,
9,
339,
768,
4247,
63,
5451,
8,
3710,
29,
497,
19797,
6019,
3849,
9,
272,
347,
511,
63,
1078,
63,
1345,
63,
354,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2455,
805,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
267,
314,
2851,
931,
4412,
370,
626,
2455,
14,
267,
408,
267,
12152,
63,
633,
275,
7512,
63,
633,
360,
1176,
14,
2828,
14,
1178,
14,
4196,
14,
11646,
358,
267,
291,
14,
629,
2336,
8370,
15,
11646,
3678,
12152,
63,
633,
9,
339,
347,
511,
63,
2261,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2881,
370,
1124,
6983,
63,
633,
1040,
2529,
314,
2011,
2881,
14,
267,
408,
267,
291,
14,
629,
8,
6983,
63,
633,
360,
2694,
14,
957,
659,
283,
2694,
14,
957,
358,
339,
347,
511,
63,
2865,
63,
1345,
63,
8296,
63,
3536,
63,
889,
63,
4471,
63,
1431,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2222,
13,
1345,
4550,
1901,
1124,
6983,
63,
633,
1040,
6534,
282,
267,
1124,
1944,
25249,
1040,
1919,
14,
267,
408,
267,
543,
291,
14,
1855,
8,
1944,
25249,
304,
288,
7512,
63,
633,
8,
2734,
26,
283,
18196,
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
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
4196,
492,
22079,
199,
504,
1639,
14,
1018,
14,
16522,
492,
32036,
12,
3837,
63,
6395,
199,
504,
1639,
14,
17469,
492,
7512,
63,
633,
199,
504,
1639,
14,
396,
492,
24424,
12,
3686,
63,
5451,
12,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
6019,
3849,
199,
199,
504,
1275,
992,
492,
1910,
19559,
32218,
421,
199,
32,
4415,
63,
1751,
8,
5441,
63,
18125,
534,
6983,
63,
633,
14,
3603,
358,
199,
533,
31096,
6417,
2925,
8,
17968,
304,
272,
408,
272,
6496,
367,
314,
1124,
6983,
63,
633,
1040,
805,
14,
272,
408,
339,
347,
511,
63,
633,
63,
515,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2851,
931,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
314,
267,
2011,
1166,
14,
267,
408,
267,
291,
14,
629,
2336,
10297,
3678,
7512,
63,
633,
2336,
10297,
15,
1333,
339,
347,
511,
63,
6188,
63,
515,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
3847,
2851,
931,
370,
1124,
6983,
63,
633,
1040,
911,
754,
267,
315,
314,
2011,
1166,
14,
267,
408,
267,
291,
14,
629,
24893,
3678,
7512,
63,
633,
24592,
1333,
267,
291,
14,
629,
24592,
6188,
3678,
7512,
63,
633,
24592,
6188,
15,
1333,
267,
291,
14,
629,
5175,
3678,
7512,
63,
633,
17371,
1333,
267,
291,
14,
629,
17371,
6188,
3678,
7512,
63,
633,
17371,
6188,
15,
1333,
339,
347,
511,
63,
2861,
63,
633,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2615,
2851,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
314,
267,
2011,
1166,
14,
267,
408,
267,
1166,
275,
283,
1014,
921,
2694,
14,
957,
4805,
267,
291,
14,
629,
8,
633,
12,
7512,
63,
633,
8,
633,
430,
339,
347,
511,
63,
1238,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
1402,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
267,
1124,
362,
63,
6116,
63,
633,
1040,
3769,
2797,
641,
626,
1402,
1256,
14,
267,
408,
267,
333,
275,
1910,
19559,
32218,
8,
646,
554,
29,
17,
9,
267,
291,
14,
629,
8,
77,
14,
362,
63,
6116,
63,
633,
1062,
7512,
63,
633,
8,
77,
430,
339,
347,
511,
63,
1345,
63,
1593,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2455,
536,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
314,
267,
2851,
931,
4412,
370,
626,
2455,
536,
14,
267,
408,
267,
12152,
63,
633,
275,
7512,
63,
633,
8,
11646,
9,
267,
291,
14,
629,
2336,
8370,
15,
11646,
3678,
12152,
63,
633,
9,
339,
347,
511,
63,
6395,
63,
4471,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
314,
754,
402,
3837,
63,
6395,
365,
12152,
370,
282,
3363,
2851,
267,
1059,
14,
267,
408,
267,
12152,
63,
633,
275,
7512,
63,
633,
8,
4471,
63,
6395,
360,
11646,
1333,
267,
291,
14,
6926,
8,
13697,
63,
633,
12,
3816,
14,
505,
63,
466,
9,
267,
291,
14,
629,
2336,
8370,
15,
11646,
3678,
12152,
63,
633,
9,
339,
768,
4247,
63,
5451,
8,
3710,
29,
497,
19797,
6019,
3849,
9,
272,
347,
511,
63,
1078,
63,
1345,
63,
354,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2455,
805,
370,
1124,
6983,
63,
633,
1040,
911,
754,
315,
267,
314,
2851,
931,
4412,
370,
626,
2455,
14,
267,
408,
267,
12152,
63,
633,
275,
7512,
63,
633,
360,
1176,
14,
2828,
14,
1178,
14,
4196,
14,
11646,
358,
267,
291,
14,
629,
2336,
8370,
15,
11646,
3678,
12152,
63,
633,
9,
339,
347,
511,
63,
2261,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2881,
370,
1124,
6983,
63,
633,
1040,
2529,
314,
2011,
2881,
14,
267,
408,
267,
291,
14,
629,
8,
6983,
63,
633,
360,
2694,
14,
957,
659,
283,
2694,
14,
957,
358,
339,
347,
511,
63,
2865,
63,
1345,
63,
8296,
63,
3536,
63,
889,
63,
4471,
63,
1431,
8,
277,
304,
267,
408,
267,
6496,
626,
9476,
282,
2222,
13,
1345,
4550,
1901,
1124,
6983,
63,
633,
1040,
6534,
282,
267,
1124,
1944,
25249,
1040,
1919,
14,
267,
408,
267,
543,
291,
14,
1855,
8,
1944,
25249,
304,
288,
7512,
63,
633,
8,
2734,
26,
283,
18196,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
camilonova/django
|
tests/template_tests/templatetags/inclusion.py
|
65
|
8486
|
import operator
from django.template import Engine, Library
engine = Engine(app_dirs=True)
register = Library()
@register.inclusion_tag('inclusion.html')
def inclusion_no_params():
"""Expected inclusion_no_params __doc__"""
return {"result": "inclusion_no_params - Expected result"}
inclusion_no_params.anything = "Expected inclusion_no_params __dict__"
@register.inclusion_tag(engine.get_template('inclusion.html'))
def inclusion_no_params_from_template():
"""Expected inclusion_no_params_from_template __doc__"""
return {"result": "inclusion_no_params_from_template - Expected result"}
inclusion_no_params_from_template.anything = "Expected inclusion_no_params_from_template __dict__"
@register.inclusion_tag('inclusion.html')
def inclusion_one_param(arg):
"""Expected inclusion_one_param __doc__"""
return {"result": "inclusion_one_param - Expected result: %s" % arg}
inclusion_one_param.anything = "Expected inclusion_one_param __dict__"
@register.inclusion_tag(engine.get_template('inclusion.html'))
def inclusion_one_param_from_template(arg):
"""Expected inclusion_one_param_from_template __doc__"""
return {"result": "inclusion_one_param_from_template - Expected result: %s" % arg}
inclusion_one_param_from_template.anything = "Expected inclusion_one_param_from_template __dict__"
@register.inclusion_tag('inclusion.html', takes_context=False)
def inclusion_explicit_no_context(arg):
"""Expected inclusion_explicit_no_context __doc__"""
return {"result": "inclusion_explicit_no_context - Expected result: %s" % arg}
inclusion_explicit_no_context.anything = "Expected inclusion_explicit_no_context __dict__"
@register.inclusion_tag(engine.get_template('inclusion.html'), takes_context=False)
def inclusion_explicit_no_context_from_template(arg):
"""Expected inclusion_explicit_no_context_from_template __doc__"""
return {"result": "inclusion_explicit_no_context_from_template - Expected result: %s" % arg}
inclusion_explicit_no_context_from_template.anything = "Expected inclusion_explicit_no_context_from_template __dict__"
@register.inclusion_tag('inclusion.html', takes_context=True)
def inclusion_no_params_with_context(context):
"""Expected inclusion_no_params_with_context __doc__"""
return {"result": "inclusion_no_params_with_context - Expected result (context value: %s)" % context['value']}
inclusion_no_params_with_context.anything = "Expected inclusion_no_params_with_context __dict__"
@register.inclusion_tag(engine.get_template('inclusion.html'), takes_context=True)
def inclusion_no_params_with_context_from_template(context):
"""Expected inclusion_no_params_with_context_from_template __doc__"""
return {
"result": (
"inclusion_no_params_with_context_from_template - Expected result (context value: %s)" % context['value']
)
}
inclusion_no_params_with_context_from_template.anything = (
"Expected inclusion_no_params_with_context_from_template __dict__"
)
@register.inclusion_tag('inclusion.html', takes_context=True)
def inclusion_params_and_context(context, arg):
"""Expected inclusion_params_and_context __doc__"""
return {
"result": "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
}
inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"
@register.inclusion_tag(engine.get_template('inclusion.html'), takes_context=True)
def inclusion_params_and_context_from_template(context, arg):
"""Expected inclusion_params_and_context_from_template __doc__"""
return {
"result": (
"inclusion_params_and_context_from_template - Expected result "
"(context value: %s): %s" % (context['value'], arg)
)
}
inclusion_params_and_context_from_template.anything = "Expected inclusion_params_and_context_from_template __dict__"
@register.inclusion_tag('inclusion.html')
def inclusion_two_params(one, two):
"""Expected inclusion_two_params __doc__"""
return {"result": "inclusion_two_params - Expected result: %s, %s" % (one, two)}
inclusion_two_params.anything = "Expected inclusion_two_params __dict__"
@register.inclusion_tag(engine.get_template('inclusion.html'))
def inclusion_two_params_from_template(one, two):
"""Expected inclusion_two_params_from_template __doc__"""
return {"result": "inclusion_two_params_from_template - Expected result: %s, %s" % (one, two)}
inclusion_two_params_from_template.anything = "Expected inclusion_two_params_from_template __dict__"
@register.inclusion_tag('inclusion.html')
def inclusion_one_default(one, two='hi'):
"""Expected inclusion_one_default __doc__"""
return {"result": "inclusion_one_default - Expected result: %s, %s" % (one, two)}
inclusion_one_default.anything = "Expected inclusion_one_default __dict__"
@register.inclusion_tag(engine.get_template('inclusion.html'))
def inclusion_one_default_from_template(one, two='hi'):
"""Expected inclusion_one_default_from_template __doc__"""
return {"result": "inclusion_one_default_from_template - Expected result: %s, %s" % (one, two)}
inclusion_one_default_from_template.anything = "Expected inclusion_one_default_from_template __dict__"
@register.inclusion_tag('inclusion.html')
def inclusion_unlimited_args(one, two='hi', *args):
"""Expected inclusion_unlimited_args __doc__"""
return {
"result": (
"inclusion_unlimited_args - Expected result: %s" % (
', '.join(str(arg) for arg in [one, two] + list(args))
)
)
}
inclusion_unlimited_args.anything = "Expected inclusion_unlimited_args __dict__"
@register.inclusion_tag(engine.get_template('inclusion.html'))
def inclusion_unlimited_args_from_template(one, two='hi', *args):
"""Expected inclusion_unlimited_args_from_template __doc__"""
return {
"result": (
"inclusion_unlimited_args_from_template - Expected result: %s" % (
', '.join(str(arg) for arg in [one, two] + list(args))
)
)
}
inclusion_unlimited_args_from_template.anything = "Expected inclusion_unlimited_args_from_template __dict__"
@register.inclusion_tag('inclusion.html')
def inclusion_only_unlimited_args(*args):
"""Expected inclusion_only_unlimited_args __doc__"""
return {
"result": "inclusion_only_unlimited_args - Expected result: %s" % (
', '.join(str(arg) for arg in args)
)
}
inclusion_only_unlimited_args.anything = "Expected inclusion_only_unlimited_args __dict__"
@register.inclusion_tag(engine.get_template('inclusion.html'))
def inclusion_only_unlimited_args_from_template(*args):
"""Expected inclusion_only_unlimited_args_from_template __doc__"""
return {
"result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % (
', '.join(str(arg) for arg in args)
)
}
inclusion_only_unlimited_args_from_template.anything = "Expected inclusion_only_unlimited_args_from_template __dict__"
@register.inclusion_tag('test_incl_tag_use_l10n.html', takes_context=True)
def inclusion_tag_use_l10n(context):
"""Expected inclusion_tag_use_l10n __doc__"""
return {}
inclusion_tag_use_l10n.anything = "Expected inclusion_tag_use_l10n __dict__"
@register.inclusion_tag('inclusion.html')
def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
"""Expected inclusion_unlimited_args_kwargs __doc__"""
# Sort the dictionary by key to guarantee the order for testing.
sorted_kwarg = sorted(kwargs.items(), key=operator.itemgetter(0))
return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % (
', '.join(str(arg) for arg in [one, two] + list(args)),
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
)}
inclusion_unlimited_args_kwargs.anything = "Expected inclusion_unlimited_args_kwargs __dict__"
@register.inclusion_tag('inclusion.html', takes_context=True)
def inclusion_tag_without_context_parameter(arg):
"""Expected inclusion_tag_without_context_parameter __doc__"""
return {}
inclusion_tag_without_context_parameter.anything = "Expected inclusion_tag_without_context_parameter __dict__"
@register.inclusion_tag('inclusion_extends1.html')
def inclusion_extends1():
return {}
@register.inclusion_tag('inclusion_extends2.html')
def inclusion_extends2():
return {}
|
bsd-3-clause
|
[
646,
4182,
199,
199,
504,
1639,
14,
1160,
492,
12580,
12,
11243,
199,
199,
3908,
275,
12580,
8,
571,
63,
3220,
29,
549,
9,
199,
2683,
275,
11243,
342,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
358,
199,
318,
20396,
63,
889,
63,
1162,
837,
272,
408,
6964,
20396,
63,
889,
63,
1162,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
889,
63,
1162,
446,
13796,
754,
3570,
421,
199,
24265,
63,
889,
63,
1162,
14,
25058,
275,
298,
6964,
20396,
63,
889,
63,
1162,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
1333,
199,
318,
20396,
63,
889,
63,
1162,
63,
504,
63,
1160,
837,
272,
408,
6964,
20396,
63,
889,
63,
1162,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
889,
63,
1162,
63,
504,
63,
1160,
446,
13796,
754,
3570,
421,
199,
24265,
63,
889,
63,
1162,
63,
504,
63,
1160,
14,
25058,
275,
298,
6964,
20396,
63,
889,
63,
1162,
63,
504,
63,
1160,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
358,
199,
318,
20396,
63,
368,
63,
635,
8,
1273,
304,
272,
408,
6964,
20396,
63,
368,
63,
635,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
368,
63,
635,
446,
13796,
754,
26,
450,
83,
2,
450,
1680,
93,
421,
199,
24265,
63,
368,
63,
635,
14,
25058,
275,
298,
6964,
20396,
63,
368,
63,
635,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
1333,
199,
318,
20396,
63,
368,
63,
635,
63,
504,
63,
1160,
8,
1273,
304,
272,
408,
6964,
20396,
63,
368,
63,
635,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
368,
63,
635,
63,
504,
63,
1160,
446,
13796,
754,
26,
450,
83,
2,
450,
1680,
93,
421,
199,
24265,
63,
368,
63,
635,
63,
504,
63,
1160,
14,
25058,
275,
298,
6964,
20396,
63,
368,
63,
635,
63,
504,
63,
1160,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
297,
6181,
63,
1100,
29,
797,
9,
199,
318,
20396,
63,
10306,
63,
889,
63,
1100,
8,
1273,
304,
272,
408,
6964,
20396,
63,
10306,
63,
889,
63,
1100,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
10306,
63,
889,
63,
1100,
446,
13796,
754,
26,
450,
83,
2,
450,
1680,
93,
421,
199,
24265,
63,
10306,
63,
889,
63,
1100,
14,
25058,
275,
298,
6964,
20396,
63,
10306,
63,
889,
63,
1100,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
659,
6181,
63,
1100,
29,
797,
9,
199,
318,
20396,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
8,
1273,
304,
272,
408,
6964,
20396,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
446,
13796,
754,
26,
450,
83,
2,
450,
1680,
93,
421,
199,
24265,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
14,
25058,
275,
298,
6964,
20396,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
8,
1100,
304,
272,
408,
6964,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
889,
63,
1162,
63,
1045,
63,
1100,
446,
13796,
754,
334,
1100,
574,
26,
450,
83,
2924,
450,
1067,
459,
585,
12074,
421,
199,
24265,
63,
889,
63,
1162,
63,
1045,
63,
1100,
14,
25058,
275,
298,
6964,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
659,
6181,
63,
1100,
29,
549,
9,
199,
318,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
8,
1100,
304,
272,
408,
6964,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
469,
267,
298,
1099,
582,
334,
288,
298,
24265,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
446,
13796,
754,
334,
1100,
574,
26,
450,
83,
2924,
450,
1067,
459,
585,
418,
267,
776,
272,
789,
421,
199,
24265,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
14,
25058,
275,
334,
272,
298,
6964,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
636,
807,
16526,
199,
9,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
20396,
63,
1162,
63,
460,
63,
1100,
8,
1100,
12,
1680,
304,
272,
408,
6964,
20396,
63,
1162,
63,
460,
63,
1100,
636,
1301,
363,
624,
272,
372,
469,
267,
298,
1099,
582,
298,
24265,
63,
1162,
63,
460,
63,
1100,
446,
13796,
754,
334,
1100,
574,
26,
450,
83,
304,
450,
83,
2,
450,
334,
1100,
459,
585,
995,
1680,
9,
272,
789,
421,
199,
24265,
63,
1162,
63,
460,
63,
1100,
14,
25058,
275,
298,
6964,
20396,
63,
1162,
63,
460,
63,
1100,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
659,
6181,
63,
1100,
29,
549,
9,
199,
318,
20396,
63,
1162,
63,
460,
63,
1100,
63,
504,
63,
1160,
8,
1100,
12,
1680,
304,
272,
408,
6964,
20396,
63,
1162,
63,
460,
63,
1100,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
469,
267,
298,
1099,
582,
334,
288,
298,
24265,
63,
1162,
63,
460,
63,
1100,
63,
504,
63,
1160,
446,
13796
] |
[
4182,
199,
199,
504,
1639,
14,
1160,
492,
12580,
12,
11243,
199,
199,
3908,
275,
12580,
8,
571,
63,
3220,
29,
549,
9,
199,
2683,
275,
11243,
342,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
358,
199,
318,
20396,
63,
889,
63,
1162,
837,
272,
408,
6964,
20396,
63,
889,
63,
1162,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
889,
63,
1162,
446,
13796,
754,
3570,
421,
199,
24265,
63,
889,
63,
1162,
14,
25058,
275,
298,
6964,
20396,
63,
889,
63,
1162,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
1333,
199,
318,
20396,
63,
889,
63,
1162,
63,
504,
63,
1160,
837,
272,
408,
6964,
20396,
63,
889,
63,
1162,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
889,
63,
1162,
63,
504,
63,
1160,
446,
13796,
754,
3570,
421,
199,
24265,
63,
889,
63,
1162,
63,
504,
63,
1160,
14,
25058,
275,
298,
6964,
20396,
63,
889,
63,
1162,
63,
504,
63,
1160,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
358,
199,
318,
20396,
63,
368,
63,
635,
8,
1273,
304,
272,
408,
6964,
20396,
63,
368,
63,
635,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
368,
63,
635,
446,
13796,
754,
26,
450,
83,
2,
450,
1680,
93,
421,
199,
24265,
63,
368,
63,
635,
14,
25058,
275,
298,
6964,
20396,
63,
368,
63,
635,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
1333,
199,
318,
20396,
63,
368,
63,
635,
63,
504,
63,
1160,
8,
1273,
304,
272,
408,
6964,
20396,
63,
368,
63,
635,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
368,
63,
635,
63,
504,
63,
1160,
446,
13796,
754,
26,
450,
83,
2,
450,
1680,
93,
421,
199,
24265,
63,
368,
63,
635,
63,
504,
63,
1160,
14,
25058,
275,
298,
6964,
20396,
63,
368,
63,
635,
63,
504,
63,
1160,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
297,
6181,
63,
1100,
29,
797,
9,
199,
318,
20396,
63,
10306,
63,
889,
63,
1100,
8,
1273,
304,
272,
408,
6964,
20396,
63,
10306,
63,
889,
63,
1100,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
10306,
63,
889,
63,
1100,
446,
13796,
754,
26,
450,
83,
2,
450,
1680,
93,
421,
199,
24265,
63,
10306,
63,
889,
63,
1100,
14,
25058,
275,
298,
6964,
20396,
63,
10306,
63,
889,
63,
1100,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
659,
6181,
63,
1100,
29,
797,
9,
199,
318,
20396,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
8,
1273,
304,
272,
408,
6964,
20396,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
446,
13796,
754,
26,
450,
83,
2,
450,
1680,
93,
421,
199,
24265,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
14,
25058,
275,
298,
6964,
20396,
63,
10306,
63,
889,
63,
1100,
63,
504,
63,
1160,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
8,
1100,
304,
272,
408,
6964,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
636,
1301,
363,
624,
272,
372,
2420,
1099,
582,
298,
24265,
63,
889,
63,
1162,
63,
1045,
63,
1100,
446,
13796,
754,
334,
1100,
574,
26,
450,
83,
2924,
450,
1067,
459,
585,
12074,
421,
199,
24265,
63,
889,
63,
1162,
63,
1045,
63,
1100,
14,
25058,
275,
298,
6964,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
659,
6181,
63,
1100,
29,
549,
9,
199,
318,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
8,
1100,
304,
272,
408,
6964,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
469,
267,
298,
1099,
582,
334,
288,
298,
24265,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
446,
13796,
754,
334,
1100,
574,
26,
450,
83,
2924,
450,
1067,
459,
585,
418,
267,
776,
272,
789,
421,
199,
24265,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
14,
25058,
275,
334,
272,
298,
6964,
20396,
63,
889,
63,
1162,
63,
1045,
63,
1100,
63,
504,
63,
1160,
636,
807,
16526,
199,
9,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
24265,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
20396,
63,
1162,
63,
460,
63,
1100,
8,
1100,
12,
1680,
304,
272,
408,
6964,
20396,
63,
1162,
63,
460,
63,
1100,
636,
1301,
363,
624,
272,
372,
469,
267,
298,
1099,
582,
298,
24265,
63,
1162,
63,
460,
63,
1100,
446,
13796,
754,
334,
1100,
574,
26,
450,
83,
304,
450,
83,
2,
450,
334,
1100,
459,
585,
995,
1680,
9,
272,
789,
421,
199,
24265,
63,
1162,
63,
460,
63,
1100,
14,
25058,
275,
298,
6964,
20396,
63,
1162,
63,
460,
63,
1100,
636,
807,
16526,
421,
199,
32,
2683,
14,
24265,
63,
1450,
8,
3908,
14,
362,
63,
1160,
360,
24265,
14,
1360,
659,
6181,
63,
1100,
29,
549,
9,
199,
318,
20396,
63,
1162,
63,
460,
63,
1100,
63,
504,
63,
1160,
8,
1100,
12,
1680,
304,
272,
408,
6964,
20396,
63,
1162,
63,
460,
63,
1100,
63,
504,
63,
1160,
636,
1301,
363,
624,
272,
372,
469,
267,
298,
1099,
582,
334,
288,
298,
24265,
63,
1162,
63,
460,
63,
1100,
63,
504,
63,
1160,
446,
13796,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DolphinDream/sverchok
|
nodes/curve/blend_curves.py
|
2
|
10315
|
import numpy as np
import bpy
from bpy.props import FloatProperty, EnumProperty, BoolProperty, IntProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import (updateNode, zip_long_repeat, ensure_nesting_level,
repeat_last_for_length, throttle_and_update_node)
from sverchok.utils.curve import SvCurve, SvCubicBezierCurve, SvBezierCurve, SvLine
from sverchok.utils.curve.algorithms import concatenate_curves
from sverchok.utils.curve.biarc import SvBiArc
class SvBlendCurvesMk2Node(bpy.types.Node, SverchCustomTreeNode):
"""
Triggers: Blend curves
Tooltip: Blend two or more curves by use of Bezier curve segment
"""
bl_idname = 'SvExBlendCurvesMk2Node'
bl_label = 'Blend Curves'
bl_icon = 'CURVE_NCURVE'
sv_icon = 'SV_BLEND_CURVE'
factor1 : FloatProperty(
name = "Factor 1",
description = "Bulge factor for the first curve",
default = 1.0,
update = updateNode)
factor2 : FloatProperty(
name = "Factor 2",
description = "Bulge factor for the second curve",
default = 1.0,
update = updateNode)
parameter : FloatProperty(
name = "Parameter",
description = "P parameter for the family of biarcs",
default = 1.0,
update = updateNode)
@throttle_and_update_node
def update_sockets(self, context):
self.inputs['Curve1'].hide_safe = self.mode != 'TWO'
self.inputs['Curve2'].hide_safe = self.mode != 'TWO'
self.inputs['Curves'].hide_safe = self.mode != 'N'
self.inputs['Factor1'].hide_safe = self.smooth_mode != '1'
self.inputs['Factor2'].hide_safe = self.smooth_mode != '1'
self.inputs['Parameter'].hide_safe = self.smooth_mode != '1b'
modes = [
('TWO', "Two curves", "Blend two curves", 0),
('N', "List of curves", "Blend several curves", 1)
]
mode : EnumProperty(
name = "Blend",
items = modes,
default = 'TWO',
update = update_sockets)
smooth_modes = [
('0', "0 - Position", "Connect ends of curves with straight line segment", 0),
('1', "1 - Tangency", "Connect curves such that their tangents are smoothly joined", 1),
('1b', "1 - Bi Arc", "Connect curves with Bi Arc, such that tangents are smoothly joined", 2),
('2', "2 - Normals", "Connect curves such that their normals (second derivatives) are smoothly joined", 3),
('3', "3 - Curvature", "Connect curves such that their curvatures (third derivatives) are smoothly joined", 4)
]
smooth_mode : EnumProperty(
name = "Continuity",
description = "How smooth should be the blending; bigger value give more smooth curves",
items = smooth_modes,
default = '1',
update = update_sockets)
cyclic : BoolProperty(
name = "Cyclic",
default = False,
update = updateNode)
output_src : BoolProperty(
name = "Output source curves",
default = True,
update = updateNode)
concat : BoolProperty(
name = "Concatenate",
description = "Concatenate source curves and blending curves into one curve",
default = True,
update = updateNode)
planar_tolerance : FloatProperty(
name = "Planar Tolerance",
description = "Tolerance value for checking if the curve is planar",
default = 1e-6,
precision = 8,
update = updateNode)
def draw_buttons(self, context, layout):
layout.label(text="Continuity:")
layout.prop(self, 'smooth_mode', text='')
layout.prop(self, "mode", text='')
layout.prop(self, 'concat', toggle=True)
if self.mode == 'N':
layout.prop(self, 'cyclic', toggle=True)
if not self.concat:
layout.prop(self, 'output_src', toggle=True)
def draw_buttons_ext(self, context, layout):
self.draw_buttons(context, layout)
layout.prop(self, 'planar_tolerance')
def sv_init(self, context):
self.inputs.new('SvCurveSocket', 'Curve1')
self.inputs.new('SvCurveSocket', 'Curve2')
self.inputs.new('SvCurveSocket', 'Curves')
self.inputs.new('SvStringsSocket', "Factor1").prop_name = 'factor1'
self.inputs.new('SvStringsSocket', "Factor2").prop_name = 'factor2'
self.inputs.new('SvStringsSocket', "Parameter").prop_name = 'parameter'
self.outputs.new('SvCurveSocket', 'Curve')
self.outputs.new('SvVerticesSocket', "ControlPoints")
self.update_sockets(context)
def get_inputs(self):
factor1_s = self.inputs['Factor1'].sv_get()
factor2_s = self.inputs['Factor2'].sv_get()
params_s = self.inputs['Parameter'].sv_get()
factor1_s = ensure_nesting_level(factor1_s, 2)
factor2_s = ensure_nesting_level(factor2_s, 2)
params_s = ensure_nesting_level(params_s, 2)
if self.mode == 'TWO':
curve1_s = self.inputs['Curve1'].sv_get()
curve2_s = self.inputs['Curve2'].sv_get()
if isinstance(curve1_s[0], SvCurve):
curve1_s = [curve1_s]
if isinstance(curve2_s[0], SvCurve):
curve2_s = [curve2_s]
for inputs in zip_long_repeat(curve1_s, curve2_s, factor1_s, factor2_s, params_s):
for curve1, curve2, factor1, factor2, parameter in zip_long_repeat(*inputs):
yield curve1, curve2, factor1, factor2, parameter
else:
curves_s = self.inputs['Curves'].sv_get()
if isinstance(curves_s[0], SvCurve):
curves_s = [curves_s]
for curves, factor1s, factor2s, params in zip_long_repeat(curves_s, factor1_s, factor2_s, params_s):
factor1s = repeat_last_for_length(factor1s, len(curves))
factor2s = repeat_last_for_length(factor2s, len(curves))
params = repeat_last_for_length(params, len(curves))
for curve1, curve2, factor1, factor2, parameter in zip(curves, curves[1:], factor1s, factor2s, params):
yield curve1, curve2, factor1, factor2, parameter
if self.cyclic:
yield curves[-1], curves[0], factor1s[-1], factor2s[-1], params[-1]
def process(self):
if not any(socket.is_linked for socket in self.outputs):
return
output_src = self.output_src or self.concat
curves_out = []
controls_out = []
is_first = True
for curve1, curve2, factor1, factor2, parameter in self.get_inputs():
_, t_max_1 = curve1.get_u_bounds()
t_min_2, _ = curve2.get_u_bounds()
curve1_end = curve1.evaluate(t_max_1)
curve2_begin = curve2.evaluate(t_min_2)
smooth = self.smooth_mode
if smooth == '0':
new_curve = SvLine.from_two_points(curve1_end, curve2_begin)
new_controls = [curve1_end, curve2_begin]
elif smooth == '1':
tangent_1_end = curve1.tangent(t_max_1)
tangent_2_begin = curve2.tangent(t_min_2)
tangent1 = factor1 * tangent_1_end
tangent2 = factor2 * tangent_2_begin
new_curve = SvCubicBezierCurve(
curve1_end,
curve1_end + tangent1 / 3.0,
curve2_begin - tangent2 / 3.0,
curve2_begin
)
new_controls = [new_curve.p0.tolist(), new_curve.p1.tolist(),
new_curve.p2.tolist(), new_curve.p3.tolist()]
elif smooth == '1b':
tangent_1_end = curve1.tangent(t_max_1)
tangent_2_begin = curve2.tangent(t_min_2)
new_curve = SvBiArc.calc(
curve1_end, curve2_begin,
tangent_1_end, tangent_2_begin,
parameter,
planar_tolerance = self.planar_tolerance)
new_controls = [new_curve.junction.tolist()]
elif smooth == '2':
tangent_1_end = curve1.tangent(t_max_1)
tangent_2_begin = curve2.tangent(t_min_2)
second_1_end = curve1.second_derivative(t_max_1)
second_2_begin = curve2.second_derivative(t_min_2)
new_curve = SvBezierCurve.blend_second_derivatives(
curve1_end, tangent_1_end, second_1_end,
curve2_begin, tangent_2_begin, second_2_begin)
new_controls = [p.tolist() for p in new_curve.points]
elif smooth == '3':
tangent_1_end = curve1.tangent(t_max_1)
tangent_2_begin = curve2.tangent(t_min_2)
second_1_end = curve1.second_derivative(t_max_1)
second_2_begin = curve2.second_derivative(t_min_2)
third_1_end = curve1.third_derivative_array(np.array([t_max_1]))[0]
third_2_begin = curve2.third_derivative_array(np.array([t_min_2]))[0]
new_curve = SvBezierCurve.blend_third_derivatives(
curve1_end, tangent_1_end, second_1_end, third_1_end,
curve2_begin, tangent_2_begin, second_2_begin, third_2_begin)
new_controls = [p.tolist() for p in new_curve.points]
else:
raise Exception("Unsupported smooth level")
if self.mode == 'N' and not self.cyclic and output_src and is_first:
curves_out.append(curve1)
curves_out.append(new_curve)
if self.mode == 'N' and output_src:
curves_out.append(curve2)
controls_out.append(new_controls)
is_first = False
if self.concat:
curves_out = [concatenate_curves(curves_out)]
self.outputs['Curve'].sv_set(curves_out)
self.outputs['ControlPoints'].sv_set(controls_out)
def register():
bpy.utils.register_class(SvBlendCurvesMk2Node)
def unregister():
bpy.utils.unregister_class(SvBlendCurvesMk2Node)
|
gpl-3.0
|
[
199,
646,
2680,
465,
980,
199,
199,
646,
20575,
199,
504,
20575,
14,
6750,
492,
11140,
3697,
12,
11305,
3697,
12,
19287,
3697,
12,
9805,
3697,
199,
199,
504,
308,
422,
335,
745,
14,
932,
63,
2350,
492,
428,
422,
335,
7223,
26749,
199,
504,
308,
422,
335,
745,
14,
576,
63,
6976,
492,
334,
873,
1716,
12,
3482,
63,
2809,
63,
8755,
12,
4868,
63,
15272,
316,
63,
1896,
12,
3660,
11982,
63,
2019,
63,
509,
63,
1267,
12,
27048,
63,
460,
63,
873,
63,
932,
9,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
11895,
492,
428,
86,
20966,
12,
428,
86,
35,
456,
530,
3655,
90,
4446,
20966,
12,
428,
86,
3655,
90,
4446,
20966,
12,
428,
86,
3049,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
11895,
14,
24365,
492,
24788,
63,
31559,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
11895,
14,
4492,
9912,
492,
428,
86,
17975,
27604,
199,
199,
533,
428,
86,
30755,
3864,
2310,
31506,
18,
1716,
8,
66,
647,
14,
1313,
14,
1716,
12,
428,
422,
335,
7223,
26749,
304,
272,
408,
272,
24015,
83,
26,
699,
12944,
1094,
2310,
272,
15650,
8996,
26,
699,
12944,
2877,
503,
1655,
1094,
2310,
701,
675,
402,
6423,
90,
4446,
15318,
8135,
272,
408,
272,
6826,
63,
344,
354,
275,
283,
51,
86,
920,
30755,
3864,
2310,
31506,
18,
1716,
7,
272,
6826,
63,
1302,
275,
283,
30755,
7319,
2310,
7,
272,
6826,
63,
4677,
275,
283,
7013,
2524,
63,
6389,
1230,
2524,
7,
272,
19291,
63,
4677,
275,
283,
4985,
63,
7847,
3902,
63,
7013,
2524,
7,
339,
6535,
17,
520,
11140,
3697,
8,
267,
536,
275,
298,
12666,
413,
401,
267,
1369,
275,
298,
34,
348,
303,
6535,
367,
314,
1642,
15318,
401,
267,
849,
275,
413,
14,
16,
12,
267,
1678,
275,
1678,
1716,
9,
339,
6535,
18,
520,
11140,
3697,
8,
267,
536,
275,
298,
12666,
499,
401,
267,
1369,
275,
298,
34,
348,
303,
6535,
367,
314,
3499,
15318,
401,
267,
849,
275,
413,
14,
16,
12,
267,
1678,
275,
1678,
1716,
9,
339,
2725,
520,
11140,
3697,
8,
267,
536,
275,
298,
4720,
401,
267,
1369,
275,
298,
48,
2725,
367,
314,
9614,
402,
12111,
20672,
401,
267,
849,
275,
413,
14,
16,
12,
267,
1678,
275,
1678,
1716,
9,
339,
768,
20086,
63,
460,
63,
873,
63,
932,
272,
347,
1678,
63,
20517,
8,
277,
12,
1067,
304,
267,
291,
14,
3711,
459,
20966,
17,
2278,
8191,
63,
3489,
275,
291,
14,
632,
1137,
283,
52,
11325,
7,
267,
291,
14,
3711,
459,
20966,
18,
2278,
8191,
63,
3489,
275,
291,
14,
632,
1137,
283,
52,
11325,
7,
267,
291,
14,
3711,
459,
3864,
2310,
2278,
8191,
63,
3489,
275,
291,
14,
632,
1137,
283,
46,
7,
267,
291,
14,
3711,
459,
12666,
17,
2278,
8191,
63,
3489,
275,
291,
14,
19169,
63,
632,
1137,
283,
17,
7,
267,
291,
14,
3711,
459,
12666,
18,
2278,
8191,
63,
3489,
275,
291,
14,
19169,
63,
632,
1137,
283,
17,
7,
267,
291,
14,
3711,
459,
4720,
2278,
8191,
63,
3489,
275,
291,
14,
19169,
63,
632,
1137,
283,
17,
66,
7,
339,
12404,
275,
359,
267,
661,
52,
11325,
297,
298,
11467,
1094,
2310,
401,
298,
30755,
2877,
1094,
2310,
401,
378,
395,
267,
661,
46,
297,
298,
1296,
402,
1094,
2310,
401,
298,
30755,
9978,
1094,
2310,
401,
413,
9,
272,
1622,
339,
818,
520,
11305,
3697,
8,
267,
536,
275,
298,
30755,
401,
267,
2974,
275,
12404,
12,
267,
849,
275,
283,
52,
11325,
297,
267,
1678,
275,
1678,
63,
20517,
9,
339,
19608,
63,
10433,
275,
359,
288,
661,
16,
297,
298,
16,
446,
15483,
401,
298,
8631,
11187,
402,
1094,
2310,
543,
23669,
1004,
8135,
401,
378,
395,
288,
661,
17,
297,
298,
17,
446,
377,
621,
9501,
401,
298,
8631,
1094,
2310,
4066,
626,
3932,
307,
621,
24871,
787,
19608,
590,
16538,
401,
413,
395,
288,
661,
17,
66,
297,
298,
17,
446,
31012,
437,
1195,
401,
298,
8631,
1094,
2310,
543,
31012,
437,
1195,
12,
4066,
626,
307,
621,
24871,
787,
19608,
590,
16538,
401,
499,
395,
288,
661,
18,
297,
298,
18,
446,
11514,
83,
401,
298,
8631,
1094,
2310,
4066,
626,
3932,
27421,
334,
4375,
28059,
9,
787,
19608,
590,
16538,
401,
650,
395,
288,
661,
19,
297,
298,
19,
446,
7319,
86,
1463,
401,
298,
8631,
1094,
2310,
4066,
626,
3932,
1094,
86,
2093,
334,
11470,
28059,
9,
787,
19608,
590,
16538,
401,
841,
9,
267,
1622,
339,
19608,
63,
632,
520,
11305,
3697,
8,
267,
536,
275,
298,
24593,
24180,
401,
267,
1369,
275,
298,
18335,
19608,
1077,
506,
314,
330,
552,
1098,
27,
29416,
574,
8120,
1655,
19608,
1094,
2310,
401,
267,
2974,
275,
19608,
63,
10433,
12,
267,
849,
275,
283,
17,
297,
267,
1678,
275,
1678,
63,
20517,
9,
339,
32637,
520,
19287,
3697,
8,
267,
536,
275,
298,
9156,
17542,
401,
267,
849,
275,
756,
12,
267,
1678,
275,
1678,
1716,
9,
339,
1072,
63,
2164,
520,
19287,
3697,
8,
267,
536,
275,
298,
2959,
1350,
1094,
2310,
401,
267,
849,
275,
715,
12,
267,
1678,
275,
1678,
1716,
9,
339,
17159,
520,
19287,
3697,
8,
267,
536,
275,
298,
714,
10592,
401,
267,
1369,
275,
298,
714,
10592,
1350,
1094,
2310,
436,
330,
552,
1098,
1094,
2310,
1901,
1373,
15318,
401,
267,
849,
275,
715,
12,
267,
1678,
275,
1678,
1716,
9,
339,
8683,
285,
63,
16312,
520,
11140,
3697,
8,
288,
536,
275,
298,
13375,
285,
4005,
8807,
401,
288,
1369,
275,
298,
1378,
8807,
574,
367,
7907,
340,
314,
15318,
365,
8683,
285,
401,
288,
849,
275,
413,
69,
13,
22,
12,
288,
7151,
275,
1695,
12,
288,
1678,
275,
1678,
1716,
9,
339,
347,
5954,
63,
15687,
8,
277,
12,
1067,
12,
7054,
304,
267,
7054,
14,
1302,
8,
505,
628,
24593,
24180,
9107,
267,
7054,
14,
4469,
8,
277,
12,
283,
19169,
63,
632,
297,
1318,
13275,
267,
7054,
14,
4469,
8,
277,
12,
298,
632,
401,
1318,
13275,
267,
7054,
14,
4469,
8,
277,
12,
283,
9419,
297,
19420,
29,
549,
9,
267,
340,
291,
14,
632,
508,
283
] |
[
646,
2680,
465,
980,
199,
199,
646,
20575,
199,
504,
20575,
14,
6750,
492,
11140,
3697,
12,
11305,
3697,
12,
19287,
3697,
12,
9805,
3697,
199,
199,
504,
308,
422,
335,
745,
14,
932,
63,
2350,
492,
428,
422,
335,
7223,
26749,
199,
504,
308,
422,
335,
745,
14,
576,
63,
6976,
492,
334,
873,
1716,
12,
3482,
63,
2809,
63,
8755,
12,
4868,
63,
15272,
316,
63,
1896,
12,
3660,
11982,
63,
2019,
63,
509,
63,
1267,
12,
27048,
63,
460,
63,
873,
63,
932,
9,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
11895,
492,
428,
86,
20966,
12,
428,
86,
35,
456,
530,
3655,
90,
4446,
20966,
12,
428,
86,
3655,
90,
4446,
20966,
12,
428,
86,
3049,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
11895,
14,
24365,
492,
24788,
63,
31559,
199,
504,
308,
422,
335,
745,
14,
1208,
14,
11895,
14,
4492,
9912,
492,
428,
86,
17975,
27604,
199,
199,
533,
428,
86,
30755,
3864,
2310,
31506,
18,
1716,
8,
66,
647,
14,
1313,
14,
1716,
12,
428,
422,
335,
7223,
26749,
304,
272,
408,
272,
24015,
83,
26,
699,
12944,
1094,
2310,
272,
15650,
8996,
26,
699,
12944,
2877,
503,
1655,
1094,
2310,
701,
675,
402,
6423,
90,
4446,
15318,
8135,
272,
408,
272,
6826,
63,
344,
354,
275,
283,
51,
86,
920,
30755,
3864,
2310,
31506,
18,
1716,
7,
272,
6826,
63,
1302,
275,
283,
30755,
7319,
2310,
7,
272,
6826,
63,
4677,
275,
283,
7013,
2524,
63,
6389,
1230,
2524,
7,
272,
19291,
63,
4677,
275,
283,
4985,
63,
7847,
3902,
63,
7013,
2524,
7,
339,
6535,
17,
520,
11140,
3697,
8,
267,
536,
275,
298,
12666,
413,
401,
267,
1369,
275,
298,
34,
348,
303,
6535,
367,
314,
1642,
15318,
401,
267,
849,
275,
413,
14,
16,
12,
267,
1678,
275,
1678,
1716,
9,
339,
6535,
18,
520,
11140,
3697,
8,
267,
536,
275,
298,
12666,
499,
401,
267,
1369,
275,
298,
34,
348,
303,
6535,
367,
314,
3499,
15318,
401,
267,
849,
275,
413,
14,
16,
12,
267,
1678,
275,
1678,
1716,
9,
339,
2725,
520,
11140,
3697,
8,
267,
536,
275,
298,
4720,
401,
267,
1369,
275,
298,
48,
2725,
367,
314,
9614,
402,
12111,
20672,
401,
267,
849,
275,
413,
14,
16,
12,
267,
1678,
275,
1678,
1716,
9,
339,
768,
20086,
63,
460,
63,
873,
63,
932,
272,
347,
1678,
63,
20517,
8,
277,
12,
1067,
304,
267,
291,
14,
3711,
459,
20966,
17,
2278,
8191,
63,
3489,
275,
291,
14,
632,
1137,
283,
52,
11325,
7,
267,
291,
14,
3711,
459,
20966,
18,
2278,
8191,
63,
3489,
275,
291,
14,
632,
1137,
283,
52,
11325,
7,
267,
291,
14,
3711,
459,
3864,
2310,
2278,
8191,
63,
3489,
275,
291,
14,
632,
1137,
283,
46,
7,
267,
291,
14,
3711,
459,
12666,
17,
2278,
8191,
63,
3489,
275,
291,
14,
19169,
63,
632,
1137,
283,
17,
7,
267,
291,
14,
3711,
459,
12666,
18,
2278,
8191,
63,
3489,
275,
291,
14,
19169,
63,
632,
1137,
283,
17,
7,
267,
291,
14,
3711,
459,
4720,
2278,
8191,
63,
3489,
275,
291,
14,
19169,
63,
632,
1137,
283,
17,
66,
7,
339,
12404,
275,
359,
267,
661,
52,
11325,
297,
298,
11467,
1094,
2310,
401,
298,
30755,
2877,
1094,
2310,
401,
378,
395,
267,
661,
46,
297,
298,
1296,
402,
1094,
2310,
401,
298,
30755,
9978,
1094,
2310,
401,
413,
9,
272,
1622,
339,
818,
520,
11305,
3697,
8,
267,
536,
275,
298,
30755,
401,
267,
2974,
275,
12404,
12,
267,
849,
275,
283,
52,
11325,
297,
267,
1678,
275,
1678,
63,
20517,
9,
339,
19608,
63,
10433,
275,
359,
288,
661,
16,
297,
298,
16,
446,
15483,
401,
298,
8631,
11187,
402,
1094,
2310,
543,
23669,
1004,
8135,
401,
378,
395,
288,
661,
17,
297,
298,
17,
446,
377,
621,
9501,
401,
298,
8631,
1094,
2310,
4066,
626,
3932,
307,
621,
24871,
787,
19608,
590,
16538,
401,
413,
395,
288,
661,
17,
66,
297,
298,
17,
446,
31012,
437,
1195,
401,
298,
8631,
1094,
2310,
543,
31012,
437,
1195,
12,
4066,
626,
307,
621,
24871,
787,
19608,
590,
16538,
401,
499,
395,
288,
661,
18,
297,
298,
18,
446,
11514,
83,
401,
298,
8631,
1094,
2310,
4066,
626,
3932,
27421,
334,
4375,
28059,
9,
787,
19608,
590,
16538,
401,
650,
395,
288,
661,
19,
297,
298,
19,
446,
7319,
86,
1463,
401,
298,
8631,
1094,
2310,
4066,
626,
3932,
1094,
86,
2093,
334,
11470,
28059,
9,
787,
19608,
590,
16538,
401,
841,
9,
267,
1622,
339,
19608,
63,
632,
520,
11305,
3697,
8,
267,
536,
275,
298,
24593,
24180,
401,
267,
1369,
275,
298,
18335,
19608,
1077,
506,
314,
330,
552,
1098,
27,
29416,
574,
8120,
1655,
19608,
1094,
2310,
401,
267,
2974,
275,
19608,
63,
10433,
12,
267,
849,
275,
283,
17,
297,
267,
1678,
275,
1678,
63,
20517,
9,
339,
32637,
520,
19287,
3697,
8,
267,
536,
275,
298,
9156,
17542,
401,
267,
849,
275,
756,
12,
267,
1678,
275,
1678,
1716,
9,
339,
1072,
63,
2164,
520,
19287,
3697,
8,
267,
536,
275,
298,
2959,
1350,
1094,
2310,
401,
267,
849,
275,
715,
12,
267,
1678,
275,
1678,
1716,
9,
339,
17159,
520,
19287,
3697,
8,
267,
536,
275,
298,
714,
10592,
401,
267,
1369,
275,
298,
714,
10592,
1350,
1094,
2310,
436,
330,
552,
1098,
1094,
2310,
1901,
1373,
15318,
401,
267,
849,
275,
715,
12,
267,
1678,
275,
1678,
1716,
9,
339,
8683,
285,
63,
16312,
520,
11140,
3697,
8,
288,
536,
275,
298,
13375,
285,
4005,
8807,
401,
288,
1369,
275,
298,
1378,
8807,
574,
367,
7907,
340,
314,
15318,
365,
8683,
285,
401,
288,
849,
275,
413,
69,
13,
22,
12,
288,
7151,
275,
1695,
12,
288,
1678,
275,
1678,
1716,
9,
339,
347,
5954,
63,
15687,
8,
277,
12,
1067,
12,
7054,
304,
267,
7054,
14,
1302,
8,
505,
628,
24593,
24180,
9107,
267,
7054,
14,
4469,
8,
277,
12,
283,
19169,
63,
632,
297,
1318,
13275,
267,
7054,
14,
4469,
8,
277,
12,
298,
632,
401,
1318,
13275,
267,
7054,
14,
4469,
8,
277,
12,
283,
9419,
297,
19420,
29,
549,
9,
267,
340,
291,
14,
632,
508,
283,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
motion2015/edx-platform
|
common/djangoapps/external_auth/tests/test_ssl.py
|
116
|
18120
|
"""
Provides unit tests for SSL based authentication portions
of the external_auth app.
"""
import copy
import unittest
from django.conf import settings
from django.contrib.auth import SESSION_KEY
from django.contrib.auth.models import AnonymousUser, User
from django.contrib.sessions.middleware import SessionMiddleware
from django.core.urlresolvers import reverse
from django.test.client import Client
from django.test.client import RequestFactory
from django.test.utils import override_settings
from edxmako.middleware import MakoMiddleware
from external_auth.models import ExternalAuthMap
import external_auth.views
from mock import Mock
from student.models import CourseEnrollment
from student.roles import CourseStaffRole
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
FEATURES_WITH_SSL_AUTH = settings.FEATURES.copy()
FEATURES_WITH_SSL_AUTH['AUTH_USE_CERTIFICATES'] = True
FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP = FEATURES_WITH_SSL_AUTH.copy()
FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP['AUTH_USE_CERTIFICATES_IMMEDIATE_SIGNUP'] = True
FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE = FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP.copy()
FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE['BYPASS_ACTIVATION_EMAIL_FOR_EXTAUTH'] = True
FEATURES_WITHOUT_SSL_AUTH = settings.FEATURES.copy()
FEATURES_WITHOUT_SSL_AUTH['AUTH_USE_CERTIFICATES'] = False
CACHES_ENABLE_GENERAL = copy.deepcopy(settings.CACHES)
CACHES_ENABLE_GENERAL['general']['BACKEND'] = 'django.core.cache.backends.locmem.LocMemCache'
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH)
@override_settings(CACHES=CACHES_ENABLE_GENERAL)
class SSLClientTest(ModuleStoreTestCase):
"""
Tests SSL Authentication code sections of external_auth
"""
AUTH_DN = '/C=US/ST=Massachusetts/O=Massachusetts Institute of Technology/OU=Client CA v1/CN={0}/emailAddress={1}'
USER_NAME = 'test_user_ssl'
USER_EMAIL = 'test_user_ssl@EDX.ORG'
MOCK_URL = '/'
def _create_ssl_request(self, url):
"""Creates a basic request for SSL use."""
request = self.factory.get(url)
request.META['SSL_CLIENT_S_DN'] = self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL)
request.user = AnonymousUser()
middleware = SessionMiddleware()
middleware.process_request(request)
request.session.save()
MakoMiddleware().process_request(request)
return request
def _create_normal_request(self, url):
"""Creates sessioned request without SSL headers"""
request = self.factory.get(url)
request.user = AnonymousUser()
middleware = SessionMiddleware()
middleware.process_request(request)
request.session.save()
MakoMiddleware().process_request(request)
return request
def setUp(self):
"""Setup test case by adding primary user."""
super(SSLClientTest, self).setUp()
self.client = Client()
self.factory = RequestFactory()
self.mock = Mock()
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_ssl_login_with_signup_lms(self):
"""
Validate that an SSL login creates an eamap user and
redirects them to the signup page.
"""
response = external_auth.views.ssl_login(self._create_ssl_request('/'))
# Response should contain template for signup form, eamap should have user, and internal
# auth should not have a user
self.assertIn('<form role="form" id="register-form" method="post"', response.content)
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
self.fail('User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
with self.assertRaises(User.DoesNotExist):
User.objects.get(email=self.USER_EMAIL)
@unittest.skipUnless(settings.ROOT_URLCONF == 'cms.urls', 'Test only valid in cms')
def test_ssl_login_with_signup_cms(self):
"""
Validate that an SSL login creates an eamap user and
redirects them to the signup page on CMS.
"""
self.client.get(
reverse('contentstore.views.login_page'),
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL)
)
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
self.fail('User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
with self.assertRaises(User.DoesNotExist):
User.objects.get(email=self.USER_EMAIL)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP)
def test_ssl_login_without_signup_lms(self):
"""
Test IMMEDIATE_SIGNUP feature flag and ensure the user account is automatically created
and the user is redirected to slash.
"""
external_auth.views.ssl_login(self._create_ssl_request('/'))
# Assert our user exists in both eamap and Users, and that we are logged in
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
self.fail('User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
try:
User.objects.get(email=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
self.fail('User did not get properly added to internal users, exception was {0}'.format(str(ex)))
@unittest.skipUnless(settings.ROOT_URLCONF == 'cms.urls', 'Test only valid in cms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP)
def test_ssl_login_without_signup_cms(self):
"""
Test IMMEDIATE_SIGNUP feature flag and ensure the user account is
automatically created on CMS, and that we are redirected
to courses.
"""
response = self.client.get(
reverse('contentstore.views.login_page'),
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL)
)
self.assertEqual(response.status_code, 302)
self.assertIn('/course', response['location'])
# Assert our user exists in both eamap and Users, and that we are logged in
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
self.fail('User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
try:
User.objects.get(email=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
self.fail('User did not get properly added to internal users, exception was {0}'.format(str(ex)))
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP)
def test_default_login_decorator_ssl(self):
"""
Make sure that SSL login happens if it is enabled on protected
views instead of showing the login form.
"""
response = self.client.get(reverse('dashboard'), follows=True)
self.assertEqual(response.status_code, 302)
self.assertIn(reverse('signin_user'), response['location'])
response = self.client.get(
reverse('dashboard'), follow=True,
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL))
self.assertEquals(('http://testserver/dashboard', 302),
response.redirect_chain[-1])
self.assertIn(SESSION_KEY, self.client.session)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP)
def test_registration_page_bypass(self):
"""
This tests to make sure when immediate signup is on that
the user doesn't get presented with the registration page.
"""
response = self.client.get(
reverse('register_user'), follow=True,
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL))
self.assertEquals(('http://testserver/dashboard', 302),
response.redirect_chain[-1])
self.assertIn(SESSION_KEY, self.client.session)
@unittest.skipUnless(settings.ROOT_URLCONF == 'cms.urls', 'Test only valid in cms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP)
def test_cms_registration_page_bypass(self):
"""
This tests to make sure when immediate signup is on that
the user doesn't get presented with the registration page.
"""
response = self.client.get(
reverse('signup'), follow=True,
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL)
)
self.assertEqual(response.status_code, 404)
# assert that we are logged in
self.assertIn(SESSION_KEY, self.client.session)
# Now that we are logged in, make sure we don't see the registration page
response = self.client.get(reverse('signup'), follow=True)
self.assertEqual(response.status_code, 404)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP)
def test_signin_page_bypass(self):
"""
This tests to make sure when ssl authentication is on
that user doesn't get presented with the login page if they
have a certificate.
"""
# Test that they do signin if they don't have a cert
response = self.client.get(reverse('signin_user'))
self.assertEqual(200, response.status_code)
self.assertTrue('login-and-registration-container' in response.content)
# And get directly logged in otherwise
response = self.client.get(
reverse('signin_user'), follow=True,
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL))
self.assertEquals(('http://testserver/dashboard', 302),
response.redirect_chain[-1])
self.assertIn(SESSION_KEY, self.client.session)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP)
def test_ssl_bad_eamap(self):
"""
This tests the response when a user exists but their eamap
password doesn't match their internal password.
The internal password use for certificates has been removed
and this should not fail.
"""
# Create account, break internal password, and activate account
external_auth.views.ssl_login(self._create_ssl_request('/'))
user = User.objects.get(email=self.USER_EMAIL)
user.set_password('not autogenerated')
user.is_active = True
user.save()
# Make sure we can still login
self.client.get(
reverse('signin_user'), follow=True,
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL))
self.assertIn(SESSION_KEY, self.client.session)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITHOUT_SSL_AUTH)
def test_ssl_decorator_no_certs(self):
"""Make sure no external auth happens without SSL enabled"""
dec_mock = external_auth.views.ssl_login_shortcut(self.mock)
request = self._create_normal_request(self.MOCK_URL)
request.user = AnonymousUser()
# Call decorated mock function to make sure it passes
# the call through without hitting the external_auth functions and
# thereby creating an external auth map object.
dec_mock(request)
self.assertTrue(self.mock.called)
self.assertEqual(0, len(ExternalAuthMap.objects.all()))
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_ssl_login_decorator(self):
"""Create mock function to test ssl login decorator"""
dec_mock = external_auth.views.ssl_login_shortcut(self.mock)
# Test that anonymous without cert doesn't create authmap
request = self._create_normal_request(self.MOCK_URL)
dec_mock(request)
self.assertTrue(self.mock.called)
self.assertEqual(0, len(ExternalAuthMap.objects.all()))
# Test valid user
self.mock.reset_mock()
request = self._create_ssl_request(self.MOCK_URL)
dec_mock(request)
self.assertFalse(self.mock.called)
self.assertEqual(1, len(ExternalAuthMap.objects.all()))
# Test logged in user gets called
self.mock.reset_mock()
request = self._create_ssl_request(self.MOCK_URL)
request.user = UserFactory()
dec_mock(request)
self.assertTrue(self.mock.called)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_IMMEDIATE_SIGNUP)
def test_ssl_decorator_auto_signup(self):
"""
Test that with auto signup the decorator
will bypass registration and call retfun.
"""
dec_mock = external_auth.views.ssl_login_shortcut(self.mock)
request = self._create_ssl_request(self.MOCK_URL)
dec_mock(request)
# Assert our user exists in both eamap and Users
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
self.fail('User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
try:
User.objects.get(email=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
self.fail('User did not get properly added to internal users, exception was {0}'.format(str(ex)))
self.assertEqual(1, len(ExternalAuthMap.objects.all()))
self.assertTrue(self.mock.called)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE)
def test_ssl_lms_redirection(self):
"""
Auto signup auth user and ensure they return to the original
url they visited after being logged in.
"""
course = CourseFactory.create(
org='MITx',
number='999',
display_name='Robot Super Course'
)
external_auth.views.ssl_login(self._create_ssl_request('/'))
user = User.objects.get(email=self.USER_EMAIL)
CourseEnrollment.enroll(user, course.id)
course_private_url = '/courses/MITx/999/Robot_Super_Course/courseware'
self.assertFalse(SESSION_KEY in self.client.session)
response = self.client.get(
course_private_url,
follow=True,
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL),
HTTP_ACCEPT='text/html'
)
self.assertEqual(('http://testserver{0}'.format(course_private_url), 302),
response.redirect_chain[-1])
self.assertIn(SESSION_KEY, self.client.session)
@unittest.skipUnless(settings.ROOT_URLCONF == 'cms.urls', 'Test only valid in cms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE)
def test_ssl_cms_redirection(self):
"""
Auto signup auth user and ensure they return to the original
url they visited after being logged in.
"""
course = CourseFactory.create(
org='MITx',
number='999',
display_name='Robot Super Course'
)
external_auth.views.ssl_login(self._create_ssl_request('/'))
user = User.objects.get(email=self.USER_EMAIL)
CourseEnrollment.enroll(user, course.id)
CourseStaffRole(course.id).add_users(user)
course_private_url = reverse('course_handler', args=(unicode(course.id),))
self.assertFalse(SESSION_KEY in self.client.session)
response = self.client.get(
course_private_url,
follow=True,
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL),
HTTP_ACCEPT='text/html'
)
self.assertEqual(('http://testserver{0}'.format(course_private_url), 302),
response.redirect_chain[-1])
self.assertIn(SESSION_KEY, self.client.session)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@override_settings(FEATURES=FEATURES_WITH_SSL_AUTH_AUTO_ACTIVATE)
def test_ssl_logout(self):
"""
Because the branding view is cached for anonymous users and we
use that to login users, the browser wasn't actually making the
request to that view as the redirect was being cached. This caused
a redirect loop, and this test confirms that that won't happen.
Test is only in LMS because we don't use / in studio to login SSL users.
"""
response = self.client.get(
reverse('dashboard'), follow=True,
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL))
self.assertEquals(('http://testserver/dashboard', 302),
response.redirect_chain[-1])
self.assertIn(SESSION_KEY, self.client.session)
response = self.client.get(
reverse('logout'), follow=True,
SSL_CLIENT_S_DN=self.AUTH_DN.format(self.USER_NAME, self.USER_EMAIL)
)
# Make sure that even though we logged out, we have logged back in
self.assertIn(SESSION_KEY, self.client.session)
|
agpl-3.0
|
[
624,
199,
17473,
4137,
2295,
367,
7799,
4079,
6299,
12468,
199,
1618,
314,
5957,
63,
1178,
1145,
14,
199,
624,
199,
646,
1331,
199,
646,
2882,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
428,
9577,
63,
3078,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
12,
2876,
199,
504,
1639,
14,
2828,
14,
11676,
14,
5754,
492,
8596,
6608,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
1639,
14,
396,
14,
1258,
492,
18638,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
22435,
19491,
14,
5754,
492,
603,
23564,
6608,
199,
504,
5957,
63,
1178,
14,
992,
492,
18802,
2817,
2956,
199,
646,
5957,
63,
1178,
14,
4196,
199,
504,
1683,
492,
4420,
199,
199,
504,
6474,
14,
992,
492,
18946,
199,
504,
6474,
14,
8050,
492,
5531,
18963,
7422,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
275,
2202,
14,
13313,
14,
1574,
342,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
459,
5580,
63,
4701,
63,
11163,
14456,
16601,
418,
275,
715,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
63,
1469,
19464,
63,
7864,
1440,
48,
275,
16012,
619,
10799,
63,
9139,
63,
5413,
63,
5580,
14,
1574,
342,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
63,
1469,
19464,
63,
7864,
1440,
48,
459,
5580,
63,
4701,
63,
11163,
14456,
16601,
63,
1469,
19464,
63,
7864,
1440,
48,
418,
275,
715,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
63,
13883,
63,
20425,
1951,
275,
16012,
619,
10799,
63,
9139,
63,
5413,
63,
5580,
63,
1469,
19464,
63,
7864,
1440,
48,
14,
1574,
342,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
63,
13883,
63,
20425,
1951,
459,
8285,
6909,
63,
20425,
2594,
63,
10089,
63,
2707,
63,
2472,
5580,
418,
275,
715,
199,
13313,
63,
29946,
63,
5413,
63,
5580,
275,
2202,
14,
13313,
14,
1574,
342,
199,
13313,
63,
29946,
63,
5413,
63,
5580,
459,
5580,
63,
4701,
63,
11163,
14456,
16601,
418,
275,
756,
199,
3263,
1244,
654,
63,
8898,
63,
31548,
275,
1331,
14,
8293,
8,
1751,
14,
3263,
1244,
654,
9,
199,
3263,
1244,
654,
63,
8898,
63,
31548,
459,
10706,
2545,
18145,
418,
275,
283,
1176,
14,
1018,
14,
1637,
14,
7765,
14,
2102,
5286,
14,
3040,
14169,
4437,
7,
421,
199,
32,
4415,
63,
1751,
8,
13313,
29,
13313,
63,
9139,
63,
5413,
63,
5580,
9,
199,
32,
4415,
63,
1751,
8,
3263,
1244,
654,
29,
3263,
1244,
654,
63,
8898,
63,
31548,
9,
199,
533,
7799,
3041,
774,
8,
27863,
304,
272,
408,
272,
6496,
7799,
15995,
1233,
10189,
402,
5957,
63,
1178,
272,
408,
339,
7560,
63,
10872,
275,
1994,
35,
29,
1668,
15,
840,
29,
27218,
1225,
29589,
1086,
15,
47,
29,
27218,
1225,
29589,
1086,
1010,
25585,
402,
21580,
15,
22050,
29,
3041,
7240,
373,
17,
15,
12874,
3126,
16,
5995,
2123,
1476,
3126,
17,
6834,
272,
13044,
63,
2339,
275,
283,
396,
63,
751,
63,
4266,
7,
272,
13044,
63,
10089,
275,
283,
396,
63,
751,
63,
4266,
32,
1149,
56,
14,
25797,
7,
272,
10362,
2504,
63,
2632,
275,
7324,
339,
347,
485,
981,
63,
4266,
63,
1069,
8,
277,
12,
1166,
304,
267,
408,
10607,
282,
5678,
1056,
367,
7799,
675,
1041,
267,
1056,
275,
291,
14,
3702,
14,
362,
8,
633,
9,
267,
1056,
14,
10614,
459,
5413,
63,
9901,
63,
51,
63,
10872,
418,
275,
291,
14,
5580,
63,
10872,
14,
908,
8,
277,
14,
3791,
63,
2339,
12,
291,
14,
3791,
63,
10089,
9,
267,
1056,
14,
751,
275,
29952,
342,
267,
10816,
275,
8596,
6608,
342,
267,
10816,
14,
1412,
63,
1069,
8,
1069,
9,
267,
1056,
14,
1730,
14,
2117,
342,
267,
603,
23564,
6608,
1252,
1412,
63,
1069,
8,
1069,
9,
267,
372,
1056,
339,
347,
485,
981,
63,
3302,
63,
1069,
8,
277,
12,
1166,
304,
267,
408,
10607,
2217,
12308,
1056,
1928,
7799,
2323,
624,
267,
1056,
275,
291,
14,
3702,
14,
362,
8,
633,
9,
267,
1056,
14,
751,
275,
29952,
342,
267,
10816,
275,
8596,
6608,
342,
267,
10816,
14,
1412,
63,
1069,
8,
1069,
9,
267,
1056,
14,
1730,
14,
2117,
342,
267,
603,
23564,
6608,
1252,
1412,
63,
1069,
8,
1069,
9,
267,
372,
1056,
339,
347,
3613,
8,
277,
304,
267,
408,
8555,
511,
1930,
701,
7791,
5062,
922,
1041,
267,
1613,
8,
5413,
3041,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
1258,
275,
6810,
342,
267,
291,
14,
3702,
275,
18638,
342,
267,
291,
14,
1805,
275,
4420,
342,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
4266,
63,
2886,
63,
1045,
63,
19799,
63,
15807,
8,
277,
304,
267,
408,
267,
12134,
626,
376,
7799,
4676,
8491,
376,
24867,
1130,
922,
436,
267,
17784,
3062,
370,
314,
2070,
384,
2034,
14,
267,
408,
398,
1177,
275,
5957,
63,
1178,
14,
4196,
14,
4266,
63,
2886,
8,
277,
423,
981,
63,
4266,
63,
1069,
28684,
398,
327,
7232,
1077,
1395,
1978,
367,
2070,
384,
1824,
12,
24867,
1130,
1077,
1172,
922,
12,
436,
5007,
267,
327,
1790,
1077,
440,
1172,
282,
922,
267,
291,
14,
4080,
4827,
964,
4719,
628,
964,
2,
1305,
628,
2683,
13,
964,
2,
1083,
628,
1932,
6949,
1177,
14,
1317,
9,
267,
862,
26,
288,
18802,
2817,
2956,
14,
1462,
14,
362,
8,
5159,
63,
344,
29,
277,
14,
3791,
63,
10089,
9,
267,
871,
18802,
2817,
2956,
14,
7400,
12,
444,
26,
288,
291,
14,
1633,
360,
1899,
8103,
440,
664,
7684,
3483,
370,
5957,
1790,
2341,
12,
1919,
1990,
469,
16,
5285,
908,
8,
495,
8,
476,
1724,
398,
543,
291,
14,
1855,
8,
1899,
14,
7400,
304,
288,
2876,
14,
1462,
14,
362,
8,
2123,
29,
277,
14
] |
[
199,
17473,
4137,
2295,
367,
7799,
4079,
6299,
12468,
199,
1618,
314,
5957,
63,
1178,
1145,
14,
199,
624,
199,
646,
1331,
199,
646,
2882,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
428,
9577,
63,
3078,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
12,
2876,
199,
504,
1639,
14,
2828,
14,
11676,
14,
5754,
492,
8596,
6608,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
1639,
14,
396,
14,
1258,
492,
18638,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
22435,
19491,
14,
5754,
492,
603,
23564,
6608,
199,
504,
5957,
63,
1178,
14,
992,
492,
18802,
2817,
2956,
199,
646,
5957,
63,
1178,
14,
4196,
199,
504,
1683,
492,
4420,
199,
199,
504,
6474,
14,
992,
492,
18946,
199,
504,
6474,
14,
8050,
492,
5531,
18963,
7422,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
275,
2202,
14,
13313,
14,
1574,
342,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
459,
5580,
63,
4701,
63,
11163,
14456,
16601,
418,
275,
715,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
63,
1469,
19464,
63,
7864,
1440,
48,
275,
16012,
619,
10799,
63,
9139,
63,
5413,
63,
5580,
14,
1574,
342,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
63,
1469,
19464,
63,
7864,
1440,
48,
459,
5580,
63,
4701,
63,
11163,
14456,
16601,
63,
1469,
19464,
63,
7864,
1440,
48,
418,
275,
715,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
63,
13883,
63,
20425,
1951,
275,
16012,
619,
10799,
63,
9139,
63,
5413,
63,
5580,
63,
1469,
19464,
63,
7864,
1440,
48,
14,
1574,
342,
199,
13313,
63,
9139,
63,
5413,
63,
5580,
63,
13883,
63,
20425,
1951,
459,
8285,
6909,
63,
20425,
2594,
63,
10089,
63,
2707,
63,
2472,
5580,
418,
275,
715,
199,
13313,
63,
29946,
63,
5413,
63,
5580,
275,
2202,
14,
13313,
14,
1574,
342,
199,
13313,
63,
29946,
63,
5413,
63,
5580,
459,
5580,
63,
4701,
63,
11163,
14456,
16601,
418,
275,
756,
199,
3263,
1244,
654,
63,
8898,
63,
31548,
275,
1331,
14,
8293,
8,
1751,
14,
3263,
1244,
654,
9,
199,
3263,
1244,
654,
63,
8898,
63,
31548,
459,
10706,
2545,
18145,
418,
275,
283,
1176,
14,
1018,
14,
1637,
14,
7765,
14,
2102,
5286,
14,
3040,
14169,
4437,
7,
421,
199,
32,
4415,
63,
1751,
8,
13313,
29,
13313,
63,
9139,
63,
5413,
63,
5580,
9,
199,
32,
4415,
63,
1751,
8,
3263,
1244,
654,
29,
3263,
1244,
654,
63,
8898,
63,
31548,
9,
199,
533,
7799,
3041,
774,
8,
27863,
304,
272,
408,
272,
6496,
7799,
15995,
1233,
10189,
402,
5957,
63,
1178,
272,
408,
339,
7560,
63,
10872,
275,
1994,
35,
29,
1668,
15,
840,
29,
27218,
1225,
29589,
1086,
15,
47,
29,
27218,
1225,
29589,
1086,
1010,
25585,
402,
21580,
15,
22050,
29,
3041,
7240,
373,
17,
15,
12874,
3126,
16,
5995,
2123,
1476,
3126,
17,
6834,
272,
13044,
63,
2339,
275,
283,
396,
63,
751,
63,
4266,
7,
272,
13044,
63,
10089,
275,
283,
396,
63,
751,
63,
4266,
32,
1149,
56,
14,
25797,
7,
272,
10362,
2504,
63,
2632,
275,
7324,
339,
347,
485,
981,
63,
4266,
63,
1069,
8,
277,
12,
1166,
304,
267,
408,
10607,
282,
5678,
1056,
367,
7799,
675,
1041,
267,
1056,
275,
291,
14,
3702,
14,
362,
8,
633,
9,
267,
1056,
14,
10614,
459,
5413,
63,
9901,
63,
51,
63,
10872,
418,
275,
291,
14,
5580,
63,
10872,
14,
908,
8,
277,
14,
3791,
63,
2339,
12,
291,
14,
3791,
63,
10089,
9,
267,
1056,
14,
751,
275,
29952,
342,
267,
10816,
275,
8596,
6608,
342,
267,
10816,
14,
1412,
63,
1069,
8,
1069,
9,
267,
1056,
14,
1730,
14,
2117,
342,
267,
603,
23564,
6608,
1252,
1412,
63,
1069,
8,
1069,
9,
267,
372,
1056,
339,
347,
485,
981,
63,
3302,
63,
1069,
8,
277,
12,
1166,
304,
267,
408,
10607,
2217,
12308,
1056,
1928,
7799,
2323,
624,
267,
1056,
275,
291,
14,
3702,
14,
362,
8,
633,
9,
267,
1056,
14,
751,
275,
29952,
342,
267,
10816,
275,
8596,
6608,
342,
267,
10816,
14,
1412,
63,
1069,
8,
1069,
9,
267,
1056,
14,
1730,
14,
2117,
342,
267,
603,
23564,
6608,
1252,
1412,
63,
1069,
8,
1069,
9,
267,
372,
1056,
339,
347,
3613,
8,
277,
304,
267,
408,
8555,
511,
1930,
701,
7791,
5062,
922,
1041,
267,
1613,
8,
5413,
3041,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
1258,
275,
6810,
342,
267,
291,
14,
3702,
275,
18638,
342,
267,
291,
14,
1805,
275,
4420,
342,
339,
768,
2796,
14,
11278,
8,
1751,
14,
5441,
63,
18125,
508,
283,
15807,
14,
3603,
297,
283,
774,
1454,
1686,
315,
21577,
358,
272,
347,
511,
63,
4266,
63,
2886,
63,
1045,
63,
19799,
63,
15807,
8,
277,
304,
267,
408,
267,
12134,
626,
376,
7799,
4676,
8491,
376,
24867,
1130,
922,
436,
267,
17784,
3062,
370,
314,
2070,
384,
2034,
14,
267,
408,
398,
1177,
275,
5957,
63,
1178,
14,
4196,
14,
4266,
63,
2886,
8,
277,
423,
981,
63,
4266,
63,
1069,
28684,
398,
327,
7232,
1077,
1395,
1978,
367,
2070,
384,
1824,
12,
24867,
1130,
1077,
1172,
922,
12,
436,
5007,
267,
327,
1790,
1077,
440,
1172,
282,
922,
267,
291,
14,
4080,
4827,
964,
4719,
628,
964,
2,
1305,
628,
2683,
13,
964,
2,
1083,
628,
1932,
6949,
1177,
14,
1317,
9,
267,
862,
26,
288,
18802,
2817,
2956,
14,
1462,
14,
362,
8,
5159,
63,
344,
29,
277,
14,
3791,
63,
10089,
9,
267,
871,
18802,
2817,
2956,
14,
7400,
12,
444,
26,
288,
291,
14,
1633,
360,
1899,
8103,
440,
664,
7684,
3483,
370,
5957,
1790,
2341,
12,
1919,
1990,
469,
16,
5285,
908,
8,
495,
8,
476,
1724,
398,
543,
291,
14,
1855,
8,
1899,
14,
7400,
304,
288,
2876,
14,
1462,
14,
362,
8,
2123,
29,
277,
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,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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
] |
kzhong1991/Flight-AR.Drone-2
|
src/3rdparty/Qt4.8.4/src/3rdparty/webkit/Source/ThirdParty/gyp/test/library/gyptest-shared-obj-install-path.py
|
20
|
1077
|
#!/usr/bin/env python
# Copyright (c) 2010 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that .so files that are order only dependencies are specified by
their install location rather than by their alias.
"""
# Python 2.5 needs this for the with statement.
from __future__ import with_statement
import os
import TestGyp
test = TestGyp.TestGyp(formats=['make'])
test.run_gyp('shared_dependency.gyp',
chdir='src')
test.relocate('src', 'relocate/src')
test.build('shared_dependency.gyp', test.ALL, chdir='relocate/src')
with open('relocate/src/Makefile') as makefile:
make_contents = makefile.read()
# If we remove the code to generate lib1, Make should still be able
# to build lib2 since lib1.so already exists.
make_contents = make_contents.replace('include lib1.target.mk', '')
with open('relocate/src/Makefile', 'w') as makefile:
makefile.write(make_contents)
test.build('shared_dependency.gyp', test.ALL, chdir='relocate/src')
test.pass_test()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
626,
1275,
1152,
1584,
626,
787,
1865,
1454,
5124,
787,
2013,
701,
199,
1589,
723,
3907,
2909,
7830,
2419,
701,
3932,
5162,
14,
199,
624,
199,
199,
3,
2018,
499,
14,
21,
4839,
642,
367,
314,
543,
5164,
14,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
25688,
199,
199,
396,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
1875,
1105,
199,
199,
396,
14,
1065,
63,
6179,
360,
5555,
63,
8575,
14,
6179,
297,
1467,
13097,
534,
2164,
358,
199,
396,
14,
18919,
360,
2164,
297,
283,
18919,
15,
2164,
358,
199,
199,
396,
14,
1506,
360,
5555,
63,
8575,
14,
6179,
297,
511,
14,
1761,
12,
13097,
534,
18919,
15,
2164,
358,
199,
199,
1045,
1551,
360,
18919,
15,
2164,
15,
19878,
358,
465,
16818,
26,
523,
1852,
63,
4407,
275,
16818,
14,
739,
342,
199,
199,
3,
982,
781,
2813,
314,
1233,
370,
3550,
1973,
17,
12,
4155,
1077,
5139,
506,
7688,
199,
3,
370,
1900,
1973,
18,
3967,
1973,
17,
14,
1152,
2575,
3495,
14,
199,
1875,
63,
4407,
275,
1852,
63,
4407,
14,
1814,
360,
2613,
1973,
17,
14,
1375,
14,
3880,
297,
4074,
199,
1045,
1551,
360,
18919,
15,
2164,
15,
19878,
297,
283,
87,
358,
465,
16818,
26,
523,
16818,
14,
952,
8,
1875,
63,
4407,
9,
199,
199,
396,
14,
1506,
360,
5555,
63,
8575,
14,
6179,
297,
511,
14,
1761,
12,
13097,
534,
18919,
15,
2164,
358,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
626,
1275,
1152,
1584,
626,
787,
1865,
1454,
5124,
787,
2013,
701,
199,
1589,
723,
3907,
2909,
7830,
2419,
701,
3932,
5162,
14,
199,
624,
199,
199,
3,
2018,
499,
14,
21,
4839,
642,
367,
314,
543,
5164,
14,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
25688,
199,
199,
396,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
1875,
1105,
199,
199,
396,
14,
1065,
63,
6179,
360,
5555,
63,
8575,
14,
6179,
297,
1467,
13097,
534,
2164,
358,
199,
396,
14,
18919,
360,
2164,
297,
283,
18919,
15,
2164,
358,
199,
199,
396,
14,
1506,
360,
5555,
63,
8575,
14,
6179,
297,
511,
14,
1761,
12,
13097,
534,
18919,
15,
2164,
358,
199,
199,
1045,
1551,
360,
18919,
15,
2164,
15,
19878,
358,
465,
16818,
26,
523,
1852,
63,
4407,
275,
16818,
14,
739,
342,
199,
199,
3,
982,
781,
2813,
314,
1233,
370,
3550,
1973,
17,
12,
4155,
1077,
5139,
506,
7688,
199,
3,
370,
1900,
1973,
18,
3967,
1973,
17,
14,
1152,
2575,
3495,
14,
199,
1875,
63,
4407,
275,
1852,
63,
4407,
14,
1814,
360,
2613,
1973,
17,
14,
1375,
14,
3880,
297,
4074,
199,
1045,
1551,
360,
18919,
15,
2164,
15,
19878,
297,
283,
87,
358,
465,
16818,
26,
523,
16818,
14,
952,
8,
1875,
63,
4407,
9,
199,
199,
396,
14,
1506,
360,
5555,
63,
8575,
14,
6179,
297,
511,
14,
1761,
12,
13097,
534,
18919,
15,
2164,
358,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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Microsoft Visual C++ compilers.
Known supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64)
Microsoft Windows SDK 6.1 (x86, x64, ia64)
Microsoft Windows SDK 7.0 (x86, x64, ia64)
Microsoft Visual C++ 10.0:
Microsoft Windows SDK 7.1 (x86, x64, ia64)
Microsoft Visual C++ 14.0:
Microsoft Visual C++ Build Tools 2015 (x86, x64, arm)
Microsoft Visual Studio 2017 (x86, x64, arm, arm64)
Microsoft Visual Studio Build Tools 2017 (x86, x64, arm, arm64)
"""
import os
import sys
import platform
import itertools
import distutils.errors
from setuptools.extern.packaging.version import LegacyVersion
from setuptools.extern.six.moves import filterfalse
from .monkey import get_unpatched
if platform.system() == 'Windows':
from setuptools.extern.six.moves import winreg
safe_env = os.environ
else:
"""
Mock winreg and environ so the module can be imported
on this platform.
"""
class winreg:
HKEY_USERS = None
HKEY_CURRENT_USER = None
HKEY_LOCAL_MACHINE = None
HKEY_CLASSES_ROOT = None
safe_env = dict()
_msvc9_suppress_errors = (
# msvc9compiler isn't available on some platforms
ImportError,
# msvc9compiler raises DistutilsPlatformError in some
# environments. See #1118.
distutils.errors.DistutilsPlatformError,
)
try:
from distutils.msvc9compiler import Reg
except _msvc9_suppress_errors:
pass
def msvc9_find_vcvarsall(version):
"""
Patched "distutils.msvc9compiler.find_vcvarsall" to use the standalone
compiler build for Python (VCForPython). Fall back to original behavior
when the standalone compiler is not available.
Redirect the path of "vcvarsall.bat".
Known supported compilers
-------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64)
Parameters
----------
version: float
Required Microsoft Visual C++ version.
Return
------
vcvarsall.bat path: str
"""
VC_BASE = r'Software\%sMicrosoft\DevDiv\VCForPython\%0.1f'
key = VC_BASE % ('', version)
try:
# Per-user installs register the compiler path here
productdir = Reg.get_value(key, "installdir")
except KeyError:
try:
# All-user installs on a 64-bit system register here
key = VC_BASE % ('Wow6432Node\\', version)
productdir = Reg.get_value(key, "installdir")
except KeyError:
productdir = None
if productdir:
vcvarsall = os.path.os.path.join(productdir, "vcvarsall.bat")
if os.path.isfile(vcvarsall):
return vcvarsall
return get_unpatched(msvc9_find_vcvarsall)(version)
def msvc9_query_vcvarsall(ver, arch='x86', *args, **kwargs):
"""
Patched "distutils.msvc9compiler.query_vcvarsall" for support extra
compilers.
Set environment without use of "vcvarsall.bat".
Known supported compilers
-------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64)
Microsoft Windows SDK 6.1 (x86, x64, ia64)
Microsoft Windows SDK 7.0 (x86, x64, ia64)
Microsoft Visual C++ 10.0:
Microsoft Windows SDK 7.1 (x86, x64, ia64)
Parameters
----------
ver: float
Required Microsoft Visual C++ version.
arch: str
Target architecture.
Return
------
environment: dict
"""
# Try to get environement from vcvarsall.bat (Classical way)
try:
orig = get_unpatched(msvc9_query_vcvarsall)
return orig(ver, arch, *args, **kwargs)
except distutils.errors.DistutilsPlatformError:
# Pass error if Vcvarsall.bat is missing
pass
except ValueError:
# Pass error if environment not set after executing vcvarsall.bat
pass
# If error, try to set environment directly
try:
return EnvironmentInfo(arch, ver).return_env()
except distutils.errors.DistutilsPlatformError as exc:
_augment_exception(exc, ver, arch)
raise
def msvc14_get_vc_env(plat_spec):
"""
Patched "distutils._msvccompiler._get_vc_env" for support extra
compilers.
Set environment without use of "vcvarsall.bat".
Known supported compilers
-------------------------
Microsoft Visual C++ 14.0:
Microsoft Visual C++ Build Tools 2015 (x86, x64, arm)
Microsoft Visual Studio 2017 (x86, x64, arm, arm64)
Microsoft Visual Studio Build Tools 2017 (x86, x64, arm, arm64)
Parameters
----------
plat_spec: str
Target architecture.
Return
------
environment: dict
"""
# Try to get environment from vcvarsall.bat (Classical way)
try:
return get_unpatched(msvc14_get_vc_env)(plat_spec)
except distutils.errors.DistutilsPlatformError:
# Pass error Vcvarsall.bat is missing
pass
# If error, try to set environment directly
try:
return EnvironmentInfo(plat_spec, vc_min_ver=14.0).return_env()
except distutils.errors.DistutilsPlatformError as exc:
_augment_exception(exc, 14.0)
raise
def msvc14_gen_lib_options(*args, **kwargs):
"""
Patched "distutils._msvccompiler.gen_lib_options" for fix
compatibility between "numpy.distutils" and "distutils._msvccompiler"
(for Numpy < 1.11.2)
"""
if "numpy.distutils" in sys.modules:
import numpy as np
if LegacyVersion(np.__version__) < LegacyVersion('1.11.2'):
return np.distutils.ccompiler.gen_lib_options(*args, **kwargs)
return get_unpatched(msvc14_gen_lib_options)(*args, **kwargs)
def _augment_exception(exc, version, arch=''):
"""
Add details to the exception message to help guide the user
as to what action will resolve it.
"""
# Error if MSVC++ directory not found or environment not set
message = exc.args[0]
if "vcvarsall" in message.lower() or "visual c" in message.lower():
# Special error message if MSVC++ not installed
tmpl = 'Microsoft Visual C++ {version:0.1f} is required.'
message = tmpl.format(**locals())
msdownload = 'www.microsoft.com/download/details.aspx?id=%d'
if version == 9.0:
if arch.lower().find('ia64') > -1:
# For VC++ 9.0, if IA64 support is needed, redirect user
# to Windows SDK 7.0
message += ' Get it with "Microsoft Windows SDK 7.0": '
message += msdownload % 3138
else:
# For VC++ 9.0 redirect user to Vc++ for Python 2.7 :
# This redirection link is maintained by Microsoft.
# Contact vspython@microsoft.com if it needs updating.
message += ' Get it from http://aka.ms/vcpython27'
elif version == 10.0:
# For VC++ 10.0 Redirect user to Windows SDK 7.1
message += ' Get it with "Microsoft Windows SDK 7.1": '
message += msdownload % 8279
elif version >= 14.0:
# For VC++ 14.0 Redirect user to Visual C++ Build Tools
message += (' Get it with "Microsoft Visual C++ Build Tools": '
r'https://visualstudio.microsoft.com/downloads/')
exc.args = (message, )
class PlatformInfo:
"""
Current and Target Architectures informations.
Parameters
----------
arch: str
Target architecture.
"""
current_cpu = safe_env.get('processor_architecture', '').lower()
def __init__(self, arch):
self.arch = arch.lower().replace('x64', 'amd64')
@property
def target_cpu(self):
return self.arch[self.arch.find('_') + 1:]
def target_is_x86(self):
return self.target_cpu == 'x86'
def current_is_x86(self):
return self.current_cpu == 'x86'
def current_dir(self, hidex86=False, x64=False):
"""
Current platform specific subfolder.
Parameters
----------
hidex86: bool
return '' and not '\x86' if architecture is x86.
x64: bool
return '\x64' and not '\amd64' if architecture is amd64.
Return
------
subfolder: str
'\target', or '' (see hidex86 parameter)
"""
return (
'' if (self.current_cpu == 'x86' and hidex86) else
r'\x64' if (self.current_cpu == 'amd64' and x64) else
r'\%s' % self.current_cpu
)
def target_dir(self, hidex86=False, x64=False):
r"""
Target platform specific subfolder.
Parameters
----------
hidex86: bool
return '' and not '\x86' if architecture is x86.
x64: bool
return '\x64' and not '\amd64' if architecture is amd64.
Return
------
subfolder: str
'\current', or '' (see hidex86 parameter)
"""
return (
'' if (self.target_cpu == 'x86' and hidex86) else
r'\x64' if (self.target_cpu == 'amd64' and x64) else
r'\%s' % self.target_cpu
)
def cross_dir(self, forcex86=False):
r"""
Cross platform specific subfolder.
Parameters
----------
forcex86: bool
Use 'x86' as current architecture even if current acritecture is
not x86.
Return
------
subfolder: str
'' if target architecture is current architecture,
'\current_target' if not.
"""
current = 'x86' if forcex86 else self.current_cpu
return (
'' if self.target_cpu == current else
self.target_dir().replace('\\', '\\%s_' % current)
)
class RegistryInfo:
"""
Microsoft Visual Studio related registry informations.
Parameters
----------
platform_info: PlatformInfo
"PlatformInfo" instance.
"""
HKEYS = (winreg.HKEY_USERS,
winreg.HKEY_CURRENT_USER,
winreg.HKEY_LOCAL_MACHINE,
winreg.HKEY_CLASSES_ROOT)
def __init__(self, platform_info):
self.pi = platform_info
@property
def visualstudio(self):
"""
Microsoft Visual Studio root registry key.
"""
return 'VisualStudio'
@property
def sxs(self):
"""
Microsoft Visual Studio SxS registry key.
"""
return os.path.join(self.visualstudio, 'SxS')
@property
def vc(self):
"""
Microsoft Visual C++ VC7 registry key.
"""
return os.path.join(self.sxs, 'VC7')
@property
def vs(self):
"""
Microsoft Visual Studio VS7 registry key.
"""
return os.path.join(self.sxs, 'VS7')
@property
def vc_for_python(self):
"""
Microsoft Visual C++ for Python registry key.
"""
return r'DevDiv\VCForPython'
@property
def microsoft_sdk(self):
"""
Microsoft SDK registry key.
"""
return 'Microsoft SDKs'
@property
def windows_sdk(self):
"""
Microsoft Windows/Platform SDK registry key.
"""
return os.path.join(self.microsoft_sdk, 'Windows')
@property
def netfx_sdk(self):
"""
Microsoft .NET Framework SDK registry key.
"""
return os.path.join(self.microsoft_sdk, 'NETFXSDK')
@property
def windows_kits_roots(self):
"""
Microsoft Windows Kits Roots registry key.
"""
return r'Windows Kits\Installed Roots'
def microsoft(self, key, x86=False):
"""
Return key in Microsoft software registry.
Parameters
----------
key: str
Registry key path where look.
x86: str
Force x86 software registry.
Return
------
str: value
"""
node64 = '' if self.pi.current_is_x86() or x86 else 'Wow6432Node'
return os.path.join('Software', node64, 'Microsoft', key)
def lookup(self, key, name):
"""
Look for values in registry in Microsoft software registry.
Parameters
----------
key: str
Registry key path where look.
name: str
Value name to find.
Return
------
str: value
"""
KEY_READ = winreg.KEY_READ
openkey = winreg.OpenKey
ms = self.microsoft
for hkey in self.HKEYS:
try:
bkey = openkey(hkey, ms(key), 0, KEY_READ)
except (OSError, IOError):
if not self.pi.current_is_x86():
try:
bkey = openkey(hkey, ms(key, True), 0, KEY_READ)
except (OSError, IOError):
continue
else:
continue
try:
return winreg.QueryValueEx(bkey, name)[0]
except (OSError, IOError):
pass
class SystemInfo:
"""
Microsoft Windows and Visual Studio related system inormations.
Parameters
----------
registry_info: RegistryInfo
"RegistryInfo" instance.
vc_ver: float
Required Microsoft Visual C++ version.
"""
# Variables and properties in this class use originals CamelCase variables
# names from Microsoft source files for more easy comparaison.
WinDir = safe_env.get('WinDir', '')
ProgramFiles = safe_env.get('ProgramFiles', '')
ProgramFilesx86 = safe_env.get('ProgramFiles(x86)', ProgramFiles)
def __init__(self, registry_info, vc_ver=None):
self.ri = registry_info
self.pi = self.ri.pi
self.vc_ver = vc_ver or self._find_latest_available_vc_ver()
def _find_latest_available_vc_ver(self):
try:
return self.find_available_vc_vers()[-1]
except IndexError:
err = 'No Microsoft Visual C++ version found'
raise distutils.errors.DistutilsPlatformError(err)
def find_available_vc_vers(self):
"""
Find all available Microsoft Visual C++ versions.
"""
ms = self.ri.microsoft
vckeys = (self.ri.vc, self.ri.vc_for_python, self.ri.vs)
vc_vers = []
for hkey in self.ri.HKEYS:
for key in vckeys:
try:
bkey = winreg.OpenKey(hkey, ms(key), 0, winreg.KEY_READ)
except (OSError, IOError):
continue
subkeys, values, _ = winreg.QueryInfoKey(bkey)
for i in range(values):
try:
ver = float(winreg.EnumValue(bkey, i)[0])
if ver not in vc_vers:
vc_vers.append(ver)
except ValueError:
pass
for i in range(subkeys):
try:
ver = float(winreg.EnumKey(bkey, i))
if ver not in vc_vers:
vc_vers.append(ver)
except ValueError:
pass
return sorted(vc_vers)
@property
def VSInstallDir(self):
"""
Microsoft Visual Studio directory.
"""
# Default path
name = 'Microsoft Visual Studio %0.1f' % self.vc_ver
default = os.path.join(self.ProgramFilesx86, name)
# Try to get path from registry, if fail use default path
return self.ri.lookup(self.ri.vs, '%0.1f' % self.vc_ver) or default
@property
def VCInstallDir(self):
"""
Microsoft Visual C++ directory.
"""
self.VSInstallDir
guess_vc = self._guess_vc() or self._guess_vc_legacy()
# Try to get "VC++ for Python" path from registry as default path
reg_path = os.path.join(self.ri.vc_for_python, '%0.1f' % self.vc_ver)
python_vc = self.ri.lookup(reg_path, 'installdir')
default_vc = os.path.join(python_vc, 'VC') if python_vc else guess_vc
# Try to get path from registry, if fail use default path
path = self.ri.lookup(self.ri.vc, '%0.1f' % self.vc_ver) or default_vc
if not os.path.isdir(path):
msg = 'Microsoft Visual C++ directory not found'
raise distutils.errors.DistutilsPlatformError(msg)
return path
def _guess_vc(self):
"""
Locate Visual C for 2017
"""
if self.vc_ver <= 14.0:
return
default = r'VC\Tools\MSVC'
guess_vc = os.path.join(self.VSInstallDir, default)
# Subdir with VC exact version as name
try:
vc_exact_ver = os.listdir(guess_vc)[-1]
return os.path.join(guess_vc, vc_exact_ver)
except (OSError, IOError, IndexError):
pass
def _guess_vc_legacy(self):
"""
Locate Visual C for versions prior to 2017
"""
default = r'Microsoft Visual Studio %0.1f\VC' % self.vc_ver
return os.path.join(self.ProgramFilesx86, default)
@property
def WindowsSdkVersion(self):
"""
Microsoft Windows SDK versions for specified MSVC++ version.
"""
if self.vc_ver <= 9.0:
return ('7.0', '6.1', '6.0a')
elif self.vc_ver == 10.0:
return ('7.1', '7.0a')
elif self.vc_ver == 11.0:
return ('8.0', '8.0a')
elif self.vc_ver == 12.0:
return ('8.1', '8.1a')
elif self.vc_ver >= 14.0:
return ('10.0', '8.1')
@property
def WindowsSdkLastVersion(self):
"""
Microsoft Windows SDK last version
"""
return self._use_last_dir_name(os.path.join(
self.WindowsSdkDir, 'lib'))
@property
def WindowsSdkDir(self):
"""
Microsoft Windows SDK directory.
"""
sdkdir = ''
for ver in self.WindowsSdkVersion:
# Try to get it from registry
loc = os.path.join(self.ri.windows_sdk, 'v%s' % ver)
sdkdir = self.ri.lookup(loc, 'installationfolder')
if sdkdir:
break
if not sdkdir or not os.path.isdir(sdkdir):
# Try to get "VC++ for Python" version from registry
path = os.path.join(self.ri.vc_for_python, '%0.1f' % self.vc_ver)
install_base = self.ri.lookup(path, 'installdir')
if install_base:
sdkdir = os.path.join(install_base, 'WinSDK')
if not sdkdir or not os.path.isdir(sdkdir):
# If fail, use default new path
for ver in self.WindowsSdkVersion:
intver = ver[:ver.rfind('.')]
path = r'Microsoft SDKs\Windows Kits\%s' % (intver)
d = os.path.join(self.ProgramFiles, path)
if os.path.isdir(d):
sdkdir = d
if not sdkdir or not os.path.isdir(sdkdir):
# If fail, use default old path
for ver in self.WindowsSdkVersion:
path = r'Microsoft SDKs\Windows\v%s' % ver
d = os.path.join(self.ProgramFiles, path)
if os.path.isdir(d):
sdkdir = d
if not sdkdir:
# If fail, use Platform SDK
sdkdir = os.path.join(self.VCInstallDir, 'PlatformSDK')
return sdkdir
@property
def WindowsSDKExecutablePath(self):
"""
Microsoft Windows SDK executable directory.
"""
# Find WinSDK NetFx Tools registry dir name
if self.vc_ver <= 11.0:
netfxver = 35
arch = ''
else:
netfxver = 40
hidex86 = True if self.vc_ver <= 12.0 else False
arch = self.pi.current_dir(x64=True, hidex86=hidex86)
fx = 'WinSDK-NetFx%dTools%s' % (netfxver, arch.replace('\\', '-'))
# liste all possibles registry paths
regpaths = []
if self.vc_ver >= 14.0:
for ver in self.NetFxSdkVersion:
regpaths += [os.path.join(self.ri.netfx_sdk, ver, fx)]
for ver in self.WindowsSdkVersion:
regpaths += [os.path.join(self.ri.windows_sdk, 'v%sA' % ver, fx)]
# Return installation folder from the more recent path
for path in regpaths:
execpath = self.ri.lookup(path, 'installationfolder')
if execpath:
break
return execpath
@property
def FSharpInstallDir(self):
"""
Microsoft Visual F# directory.
"""
path = r'%0.1f\Setup\F#' % self.vc_ver
path = os.path.join(self.ri.visualstudio, path)
return self.ri.lookup(path, 'productdir') or ''
@property
def UniversalCRTSdkDir(self):
"""
Microsoft Universal CRT SDK directory.
"""
# Set Kit Roots versions for specified MSVC++ version
if self.vc_ver >= 14.0:
vers = ('10', '81')
else:
vers = ()
# Find path of the more recent Kit
for ver in vers:
sdkdir = self.ri.lookup(self.ri.windows_kits_roots,
'kitsroot%s' % ver)
if sdkdir:
break
return sdkdir or ''
@property
def UniversalCRTSdkLastVersion(self):
"""
Microsoft Universal C Runtime SDK last version
"""
return self._use_last_dir_name(os.path.join(
self.UniversalCRTSdkDir, 'lib'))
@property
def NetFxSdkVersion(self):
"""
Microsoft .NET Framework SDK versions.
"""
# Set FxSdk versions for specified MSVC++ version
if self.vc_ver >= 14.0:
return ('4.6.1', '4.6')
else:
return ()
@property
def NetFxSdkDir(self):
"""
Microsoft .NET Framework SDK directory.
"""
for ver in self.NetFxSdkVersion:
loc = os.path.join(self.ri.netfx_sdk, ver)
sdkdir = self.ri.lookup(loc, 'kitsinstallationfolder')
if sdkdir:
break
return sdkdir or ''
@property
def FrameworkDir32(self):
"""
Microsoft .NET Framework 32bit directory.
"""
# Default path
guess_fw = os.path.join(self.WinDir, r'Microsoft.NET\Framework')
# Try to get path from registry, if fail use default path
return self.ri.lookup(self.ri.vc, 'frameworkdir32') or guess_fw
@property
def FrameworkDir64(self):
"""
Microsoft .NET Framework 64bit directory.
"""
# Default path
guess_fw = os.path.join(self.WinDir, r'Microsoft.NET\Framework64')
# Try to get path from registry, if fail use default path
return self.ri.lookup(self.ri.vc, 'frameworkdir64') or guess_fw
@property
def FrameworkVersion32(self):
"""
Microsoft .NET Framework 32bit versions.
"""
return self._find_dot_net_versions(32)
@property
def FrameworkVersion64(self):
"""
Microsoft .NET Framework 64bit versions.
"""
return self._find_dot_net_versions(64)
def _find_dot_net_versions(self, bits):
"""
Find Microsoft .NET Framework versions.
Parameters
----------
bits: int
Platform number of bits: 32 or 64.
"""
# Find actual .NET version in registry
reg_ver = self.ri.lookup(self.ri.vc, 'frameworkver%d' % bits)
dot_net_dir = getattr(self, 'FrameworkDir%d' % bits)
ver = reg_ver or self._use_last_dir_name(dot_net_dir, 'v') or ''
# Set .NET versions for specified MSVC++ version
if self.vc_ver >= 12.0:
frameworkver = (ver, 'v4.0')
elif self.vc_ver >= 10.0:
frameworkver = ('v4.0.30319' if ver.lower()[:2] != 'v4' else ver,
'v3.5')
elif self.vc_ver == 9.0:
frameworkver = ('v3.5', 'v2.0.50727')
if self.vc_ver == 8.0:
frameworkver = ('v3.0', 'v2.0.50727')
return frameworkver
def _use_last_dir_name(self, path, prefix=''):
"""
Return name of the last dir in path or '' if no dir found.
Parameters
----------
path: str
Use dirs in this path
prefix: str
Use only dirs startings by this prefix
"""
matching_dirs = (
dir_name
for dir_name in reversed(os.listdir(path))
if os.path.isdir(os.path.join(path, dir_name)) and
dir_name.startswith(prefix)
)
return next(matching_dirs, None) or ''
class EnvironmentInfo:
"""
Return environment variables for specified Microsoft Visual C++ version
and platform : Lib, Include, Path and libpath.
This function is compatible with Microsoft Visual C++ 9.0 to 14.0.
Script created by analysing Microsoft environment configuration files like
"vcvars[...].bat", "SetEnv.Cmd", "vcbuildtools.bat", ...
Parameters
----------
arch: str
Target architecture.
vc_ver: float
Required Microsoft Visual C++ version. If not set, autodetect the last
version.
vc_min_ver: float
Minimum Microsoft Visual C++ version.
"""
# Variables and properties in this class use originals CamelCase variables
# names from Microsoft source files for more easy comparaison.
def __init__(self, arch, vc_ver=None, vc_min_ver=0):
self.pi = PlatformInfo(arch)
self.ri = RegistryInfo(self.pi)
self.si = SystemInfo(self.ri, vc_ver)
if self.vc_ver < vc_min_ver:
err = 'No suitable Microsoft Visual C++ version found'
raise distutils.errors.DistutilsPlatformError(err)
@property
def vc_ver(self):
"""
Microsoft Visual C++ version.
"""
return self.si.vc_ver
@property
def VSTools(self):
"""
Microsoft Visual Studio Tools
"""
paths = [r'Common7\IDE', r'Common7\Tools']
if self.vc_ver >= 14.0:
arch_subdir = self.pi.current_dir(hidex86=True, x64=True)
paths += [r'Common7\IDE\CommonExtensions\Microsoft\TestWindow']
paths += [r'Team Tools\Performance Tools']
paths += [r'Team Tools\Performance Tools%s' % arch_subdir]
return [os.path.join(self.si.VSInstallDir, path) for path in paths]
@property
def VCIncludes(self):
"""
Microsoft Visual C++ & Microsoft Foundation Class Includes
"""
return [os.path.join(self.si.VCInstallDir, 'Include'),
os.path.join(self.si.VCInstallDir, r'ATLMFC\Include')]
@property
def VCLibraries(self):
"""
Microsoft Visual C++ & Microsoft Foundation Class Libraries
"""
if self.vc_ver >= 15.0:
arch_subdir = self.pi.target_dir(x64=True)
else:
arch_subdir = self.pi.target_dir(hidex86=True)
paths = ['Lib%s' % arch_subdir, r'ATLMFC\Lib%s' % arch_subdir]
if self.vc_ver >= 14.0:
paths += [r'Lib\store%s' % arch_subdir]
return [os.path.join(self.si.VCInstallDir, path) for path in paths]
@property
def VCStoreRefs(self):
"""
Microsoft Visual C++ store references Libraries
"""
if self.vc_ver < 14.0:
return []
return [os.path.join(self.si.VCInstallDir, r'Lib\store\references')]
@property
def VCTools(self):
"""
Microsoft Visual C++ Tools
"""
si = self.si
tools = [os.path.join(si.VCInstallDir, 'VCPackages')]
forcex86 = True if self.vc_ver <= 10.0 else False
arch_subdir = self.pi.cross_dir(forcex86)
if arch_subdir:
tools += [os.path.join(si.VCInstallDir, 'Bin%s' % arch_subdir)]
if self.vc_ver == 14.0:
path = 'Bin%s' % self.pi.current_dir(hidex86=True)
tools += [os.path.join(si.VCInstallDir, path)]
elif self.vc_ver >= 15.0:
host_dir = (r'bin\HostX86%s' if self.pi.current_is_x86() else
r'bin\HostX64%s')
tools += [os.path.join(
si.VCInstallDir, host_dir % self.pi.target_dir(x64=True))]
if self.pi.current_cpu != self.pi.target_cpu:
tools += [os.path.join(
si.VCInstallDir, host_dir % self.pi.current_dir(x64=True))]
else:
tools += [os.path.join(si.VCInstallDir, 'Bin')]
return tools
@property
def OSLibraries(self):
"""
Microsoft Windows SDK Libraries
"""
if self.vc_ver <= 10.0:
arch_subdir = self.pi.target_dir(hidex86=True, x64=True)
return [os.path.join(self.si.WindowsSdkDir, 'Lib%s' % arch_subdir)]
else:
arch_subdir = self.pi.target_dir(x64=True)
lib = os.path.join(self.si.WindowsSdkDir, 'lib')
libver = self._sdk_subdir
return [os.path.join(lib, '%sum%s' % (libver , arch_subdir))]
@property
def OSIncludes(self):
"""
Microsoft Windows SDK Include
"""
include = os.path.join(self.si.WindowsSdkDir, 'include')
if self.vc_ver <= 10.0:
return [include, os.path.join(include, 'gl')]
else:
if self.vc_ver >= 14.0:
sdkver = self._sdk_subdir
else:
sdkver = ''
return [os.path.join(include, '%sshared' % sdkver),
os.path.join(include, '%sum' % sdkver),
os.path.join(include, '%swinrt' % sdkver)]
@property
def OSLibpath(self):
"""
Microsoft Windows SDK Libraries Paths
"""
ref = os.path.join(self.si.WindowsSdkDir, 'References')
libpath = []
if self.vc_ver <= 9.0:
libpath += self.OSLibraries
if self.vc_ver >= 11.0:
libpath += [os.path.join(ref, r'CommonConfiguration\Neutral')]
if self.vc_ver >= 14.0:
libpath += [
ref,
os.path.join(self.si.WindowsSdkDir, 'UnionMetadata'),
os.path.join(
ref,
'Windows.Foundation.UniversalApiContract',
'1.0.0.0',
),
os.path.join(
ref,
'Windows.Foundation.FoundationContract',
'1.0.0.0',
),
os.path.join(
ref,
'Windows.Networking.Connectivity.WwanContract',
'1.0.0.0',
),
os.path.join(
self.si.WindowsSdkDir,
'ExtensionSDKs',
'Microsoft.VCLibs',
'%0.1f' % self.vc_ver,
'References',
'CommonConfiguration',
'neutral',
),
]
return libpath
@property
def SdkTools(self):
"""
Microsoft Windows SDK Tools
"""
return list(self._sdk_tools())
def _sdk_tools(self):
"""
Microsoft Windows SDK Tools paths generator
"""
if self.vc_ver < 15.0:
bin_dir = 'Bin' if self.vc_ver <= 11.0 else r'Bin\x86'
yield os.path.join(self.si.WindowsSdkDir, bin_dir)
if not self.pi.current_is_x86():
arch_subdir = self.pi.current_dir(x64=True)
path = 'Bin%s' % arch_subdir
yield os.path.join(self.si.WindowsSdkDir, path)
if self.vc_ver == 10.0 or self.vc_ver == 11.0:
if self.pi.target_is_x86():
arch_subdir = ''
else:
arch_subdir = self.pi.current_dir(hidex86=True, x64=True)
path = r'Bin\NETFX 4.0 Tools%s' % arch_subdir
yield os.path.join(self.si.WindowsSdkDir, path)
elif self.vc_ver >= 15.0:
path = os.path.join(self.si.WindowsSdkDir, 'Bin')
arch_subdir = self.pi.current_dir(x64=True)
sdkver = self.si.WindowsSdkLastVersion
yield os.path.join(path, '%s%s' % (sdkver, arch_subdir))
if self.si.WindowsSDKExecutablePath:
yield self.si.WindowsSDKExecutablePath
@property
def _sdk_subdir(self):
"""
Microsoft Windows SDK version subdir
"""
ucrtver = self.si.WindowsSdkLastVersion
return ('%s\\' % ucrtver) if ucrtver else ''
@property
def SdkSetup(self):
"""
Microsoft Windows SDK Setup
"""
if self.vc_ver > 9.0:
return []
return [os.path.join(self.si.WindowsSdkDir, 'Setup')]
@property
def FxTools(self):
"""
Microsoft .NET Framework Tools
"""
pi = self.pi
si = self.si
if self.vc_ver <= 10.0:
include32 = True
include64 = not pi.target_is_x86() and not pi.current_is_x86()
else:
include32 = pi.target_is_x86() or pi.current_is_x86()
include64 = pi.current_cpu == 'amd64' or pi.target_cpu == 'amd64'
tools = []
if include32:
tools += [os.path.join(si.FrameworkDir32, ver)
for ver in si.FrameworkVersion32]
if include64:
tools += [os.path.join(si.FrameworkDir64, ver)
for ver in si.FrameworkVersion64]
return tools
@property
def NetFxSDKLibraries(self):
"""
Microsoft .Net Framework SDK Libraries
"""
if self.vc_ver < 14.0 or not self.si.NetFxSdkDir:
return []
arch_subdir = self.pi.target_dir(x64=True)
return [os.path.join(self.si.NetFxSdkDir, r'lib\um%s' % arch_subdir)]
@property
def NetFxSDKIncludes(self):
"""
Microsoft .Net Framework SDK Includes
"""
if self.vc_ver < 14.0 or not self.si.NetFxSdkDir:
return []
return [os.path.join(self.si.NetFxSdkDir, r'include\um')]
@property
def VsTDb(self):
"""
Microsoft Visual Studio Team System Database
"""
return [os.path.join(self.si.VSInstallDir, r'VSTSDB\Deploy')]
@property
def MSBuild(self):
"""
Microsoft Build Engine
"""
if self.vc_ver < 12.0:
return []
elif self.vc_ver < 15.0:
base_path = self.si.ProgramFilesx86
arch_subdir = self.pi.current_dir(hidex86=True)
else:
base_path = self.si.VSInstallDir
arch_subdir = ''
path = r'MSBuild\%0.1f\bin%s' % (self.vc_ver, arch_subdir)
build = [os.path.join(base_path, path)]
if self.vc_ver >= 15.0:
# Add Roslyn C# & Visual Basic Compiler
build += [os.path.join(base_path, path, 'Roslyn')]
return build
@property
def HTMLHelpWorkshop(self):
"""
Microsoft HTML Help Workshop
"""
if self.vc_ver < 11.0:
return []
return [os.path.join(self.si.ProgramFilesx86, 'HTML Help Workshop')]
@property
def UCRTLibraries(self):
"""
Microsoft Universal C Runtime SDK Libraries
"""
if self.vc_ver < 14.0:
return []
arch_subdir = self.pi.target_dir(x64=True)
lib = os.path.join(self.si.UniversalCRTSdkDir, 'lib')
ucrtver = self._ucrt_subdir
return [os.path.join(lib, '%sucrt%s' % (ucrtver, arch_subdir))]
@property
def UCRTIncludes(self):
"""
Microsoft Universal C Runtime SDK Include
"""
if self.vc_ver < 14.0:
return []
include = os.path.join(self.si.UniversalCRTSdkDir, 'include')
return [os.path.join(include, '%sucrt' % self._ucrt_subdir)]
@property
def _ucrt_subdir(self):
"""
Microsoft Universal C Runtime SDK version subdir
"""
ucrtver = self.si.UniversalCRTSdkLastVersion
return ('%s\\' % ucrtver) if ucrtver else ''
@property
def FSharp(self):
"""
Microsoft Visual F#
"""
if self.vc_ver < 11.0 and self.vc_ver > 12.0:
return []
return self.si.FSharpInstallDir
@property
def VCRuntimeRedist(self):
"""
Microsoft Visual C++ runtime redistribuable dll
"""
arch_subdir = self.pi.target_dir(x64=True)
if self.vc_ver < 15:
redist_path = self.si.VCInstallDir
vcruntime = 'redist%s\\Microsoft.VC%d0.CRT\\vcruntime%d0.dll'
else:
redist_path = self.si.VCInstallDir.replace('\\Tools', '\\Redist')
vcruntime = 'onecore%s\\Microsoft.VC%d0.CRT\\vcruntime%d0.dll'
# Visual Studio 2017 is still Visual C++ 14.0
dll_ver = 14.0 if self.vc_ver == 15 else self.vc_ver
vcruntime = vcruntime % (arch_subdir, self.vc_ver, dll_ver)
return os.path.join(redist_path, vcruntime)
def return_env(self, exists=True):
"""
Return environment dict.
Parameters
----------
exists: bool
It True, only return existing paths.
"""
env = dict(
include=self._build_paths('include',
[self.VCIncludes,
self.OSIncludes,
self.UCRTIncludes,
self.NetFxSDKIncludes],
exists),
lib=self._build_paths('lib',
[self.VCLibraries,
self.OSLibraries,
self.FxTools,
self.UCRTLibraries,
self.NetFxSDKLibraries],
exists),
libpath=self._build_paths('libpath',
[self.VCLibraries,
self.FxTools,
self.VCStoreRefs,
self.OSLibpath],
exists),
path=self._build_paths('path',
[self.VCTools,
self.VSTools,
self.VsTDb,
self.SdkTools,
self.SdkSetup,
self.FxTools,
self.MSBuild,
self.HTMLHelpWorkshop,
self.FSharp],
exists),
)
if self.vc_ver >= 14 and os.path.isfile(self.VCRuntimeRedist):
env['py_vcruntime_redist'] = self.VCRuntimeRedist
return env
def _build_paths(self, name, spec_path_lists, exists):
"""
Given an environment variable name and specified paths,
return a pathsep-separated string of paths containing
unique, extant, directories from those paths and from
the environment variable. Raise an error if no paths
are resolved.
"""
# flatten spec_path_lists
spec_paths = itertools.chain.from_iterable(spec_path_lists)
env_paths = safe_env.get(name, '').split(os.pathsep)
paths = itertools.chain(spec_paths, env_paths)
extant_paths = list(filter(os.path.isdir, paths)) if exists else paths
if not extant_paths:
msg = "%s environment variable is empty" % name.upper()
raise distutils.errors.DistutilsPlatformError(msg)
unique_paths = self._unique_everseen(extant_paths)
return os.pathsep.join(unique_paths)
# from Python docs
def _unique_everseen(self, iterable, key=None):
"""
List unique elements, preserving order.
Remember all elements ever seen.
_unique_everseen('AAAABBBCCDAABBB') --> A B C D
_unique_everseen('ABBCcAD', str.lower) --> A B C D
"""
seen = set()
seen_add = seen.add
if key is None:
for element in filterfalse(seen.__contains__, iterable):
seen_add(element)
yield element
else:
for element in iterable:
k = key(element)
if k not in seen:
seen_add(k)
yield element
|
apache-2.0
|
[
624,
199,
8499,
26429,
2291,
367,
15332,
14702,
445,
4176,
29784,
14,
199,
199,
24574,
3748,
29784,
26,
199,
777,
9460,
199,
12940,
14702,
445,
4176,
1749,
14,
16,
26,
272,
15332,
14702,
445,
4176,
27154,
367,
2018,
499,
14,
23,
334,
88,
1184,
12,
282,
1064,
772,
9,
272,
15332,
5417,
15610,
1227,
14,
17,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
272,
15332,
5417,
15610,
1520,
14,
16,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
199,
199,
12940,
14702,
445,
4176,
1616,
14,
16,
26,
272,
15332,
5417,
15610,
1520,
14,
17,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
199,
199,
12940,
14702,
445,
4176,
4329,
14,
16,
26,
272,
15332,
14702,
445,
4176,
6516,
23228,
6900,
334,
88,
1184,
12,
671,
772,
12,
30701,
9,
272,
15332,
14702,
13225,
9708,
334,
88,
1184,
12,
671,
772,
12,
30701,
12,
30701,
772,
9,
272,
15332,
14702,
13225,
6516,
23228,
9708,
334,
88,
1184,
12,
671,
772,
12,
30701,
12,
30701,
772,
9,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
646,
4298,
199,
646,
7975,
199,
646,
7065,
14,
2550,
199,
504,
9116,
14,
18587,
14,
27796,
14,
1023,
492,
26251,
3353,
199,
199,
504,
9116,
14,
18587,
14,
4174,
14,
4912,
492,
2457,
3910,
199,
199,
504,
1275,
20372,
492,
664,
63,
324,
22631,
199,
199,
692,
4298,
14,
2253,
342,
508,
283,
8647,
356,
272,
687,
9116,
14,
18587,
14,
4174,
14,
4912,
492,
30748,
272,
5048,
63,
1813,
275,
747,
14,
2314,
199,
2836,
26,
272,
408,
272,
4420,
30748,
436,
6160,
880,
314,
859,
883,
506,
8439,
272,
641,
642,
4298,
14,
272,
408,
339,
1021,
30748,
26,
267,
869,
3078,
63,
28164,
275,
488,
267,
869,
3078,
63,
14211,
63,
3791,
275,
488,
267,
869,
3078,
63,
7486,
63,
20890,
275,
488,
267,
869,
3078,
63,
13748,
63,
5441,
275,
488,
339,
5048,
63,
1813,
275,
1211,
342,
199,
199,
63,
19875,
25,
63,
17381,
63,
2550,
275,
334,
272,
327,
333,
10599,
25,
5772,
5712,
1133,
2808,
641,
2005,
10677,
272,
3545,
12,
339,
327,
333,
10599,
25,
5772,
6534,
12577,
10397,
547,
315,
2005,
272,
327,
22196,
14,
1666,
327,
845,
1085,
14,
272,
7065,
14,
2550,
14,
12012,
1208,
10397,
547,
12,
199,
9,
199,
199,
893,
26,
272,
687,
7065,
14,
19875,
25,
5772,
492,
5044,
199,
2590,
485,
19875,
25,
63,
17381,
63,
2550,
26,
272,
986,
421,
199,
318,
333,
10599,
25,
63,
1623,
63,
6737,
2936,
452,
8,
1023,
304,
272,
408,
272,
19292,
379,
298,
13350,
14,
19875,
25,
5772,
14,
1623,
63,
6737,
2936,
452,
2,
370,
675,
314,
18042,
272,
6365,
1900,
367,
2018,
334,
9454,
1858,
4718,
680,
481,
452,
1771,
370,
3379,
5953,
272,
1380,
314,
18042,
6365,
365,
440,
2808,
14,
339,
18532,
314,
931,
402,
298,
6737,
2936,
452,
14,
13475,
1674,
339,
31862,
3748,
29784,
272,
10652,
9960,
272,
15332,
14702,
445,
4176,
1749,
14,
16,
26,
267,
15332,
14702,
445,
4176,
27154,
367,
2018,
499,
14,
23,
334,
88,
1184,
12,
282,
1064,
772,
9,
339,
3897,
272,
4143,
272,
1015,
26,
2069,
267,
11105,
15332,
14702,
445,
4176,
1015,
14,
339,
1432,
272,
21397,
272,
16548,
2936,
452,
14,
13475,
931,
26,
620,
272,
408,
272,
24955,
63,
5825,
275,
519,
7,
10337,
60,
5,
83,
12940,
60,
12680,
24305,
60,
9454,
1858,
4718,
60,
5,
16,
14,
17,
70,
7,
272,
790,
275,
24955,
63,
5825,
450,
13134,
1015,
9,
272,
862,
26,
267,
327,
3492,
13,
751,
25801,
2274,
314,
6365,
931,
2348,
267,
3336,
694,
275,
5044,
14,
362,
63,
585,
8,
498,
12,
298,
3174,
694,
531,
272,
871,
4067,
26,
267,
862,
26,
288,
327,
2900,
13,
751,
25801,
641,
282,
5049,
13,
2075,
2656,
2274,
2348,
288,
790,
275,
24955,
63,
5825,
450,
661,
55,
583,
23313,
1716,
1103,
297,
1015,
9,
288,
3336,
694,
275,
5044,
14,
362,
63,
585,
8,
498,
12,
298,
3174,
694,
531,
267,
871,
4067,
26,
288,
3336,
694,
275,
488,
339,
340,
3336,
694,
26,
267,
16548,
2936,
452,
275,
747,
14,
515,
14,
736,
14,
515,
14,
904,
8,
2558,
694,
12,
298,
6737,
2936,
452,
14,
13475,
531,
267,
340,
747,
14,
515,
14,
6292,
8,
6737,
2936,
452,
304,
288,
372,
16548,
2936,
452,
339,
372,
664,
63,
324,
22631,
8,
19875,
25,
63,
1623,
63,
6737,
2936,
452,
5130,
1023,
9,
421,
199,
318,
333,
10599,
25,
63,
1131,
63,
6737,
2936,
452,
8,
422,
12,
3819,
534,
88,
1184,
297,
627,
589,
12,
1011,
958,
304,
272,
408,
272,
19292,
379,
298,
13350,
14,
19875,
25,
5772,
14,
1131,
63,
6737,
2936,
452,
2,
367,
2291,
2402,
272,
29784,
14,
339,
2494,
3734,
1928,
675,
402,
298,
6737,
2936,
452,
14,
13475,
1674,
339,
31862,
3748,
29784,
272,
10652,
9960,
272,
15332,
14702,
445,
4176,
1749,
14,
16,
26,
267,
15332,
14702,
445,
4176,
27154,
367,
2018,
499,
14,
23,
334,
88,
1184,
12,
282,
1064,
772,
9,
267,
15332,
5417,
15610,
1227,
14,
17,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
267,
15332,
5417,
15610,
1520,
14,
16,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
339,
15332,
14702,
445,
4176,
1616,
14,
16,
26,
267,
15332,
5417,
15610,
1520,
14,
17,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
339,
3897,
272,
4143,
272,
809,
26,
2069,
267,
11105,
15332,
14702,
445,
4176,
1015,
14,
272,
3819,
26,
620,
267,
10256,
15931,
14,
339,
1432,
272,
21397,
272,
3734,
26,
1211,
272,
408,
272,
327,
7649,
370,
664,
655,
1042,
368,
434,
687,
16548,
2936,
452,
14,
13475,
334,
30722,
915,
4340,
9,
272,
862,
26,
267,
2306,
275,
664,
63,
324,
22631,
8,
19875,
25,
63,
1131,
63,
6737,
2936,
452,
9,
267,
372,
2306,
8,
422,
12,
3819,
12,
627,
589,
12,
1011,
958,
9,
272,
871,
7065,
14,
2550,
14,
12012,
1208,
10397,
547,
26,
267,
327,
8325,
1125,
340,
812,
67,
2936,
452,
14,
13475,
365,
4124,
267,
986,
272,
871,
1722
] |
[
199,
8499,
26429,
2291,
367,
15332,
14702,
445,
4176,
29784,
14,
199,
199,
24574,
3748,
29784,
26,
199,
777,
9460,
199,
12940,
14702,
445,
4176,
1749,
14,
16,
26,
272,
15332,
14702,
445,
4176,
27154,
367,
2018,
499,
14,
23,
334,
88,
1184,
12,
282,
1064,
772,
9,
272,
15332,
5417,
15610,
1227,
14,
17,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
272,
15332,
5417,
15610,
1520,
14,
16,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
199,
199,
12940,
14702,
445,
4176,
1616,
14,
16,
26,
272,
15332,
5417,
15610,
1520,
14,
17,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
199,
199,
12940,
14702,
445,
4176,
4329,
14,
16,
26,
272,
15332,
14702,
445,
4176,
6516,
23228,
6900,
334,
88,
1184,
12,
671,
772,
12,
30701,
9,
272,
15332,
14702,
13225,
9708,
334,
88,
1184,
12,
671,
772,
12,
30701,
12,
30701,
772,
9,
272,
15332,
14702,
13225,
6516,
23228,
9708,
334,
88,
1184,
12,
671,
772,
12,
30701,
12,
30701,
772,
9,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
646,
4298,
199,
646,
7975,
199,
646,
7065,
14,
2550,
199,
504,
9116,
14,
18587,
14,
27796,
14,
1023,
492,
26251,
3353,
199,
199,
504,
9116,
14,
18587,
14,
4174,
14,
4912,
492,
2457,
3910,
199,
199,
504,
1275,
20372,
492,
664,
63,
324,
22631,
199,
199,
692,
4298,
14,
2253,
342,
508,
283,
8647,
356,
272,
687,
9116,
14,
18587,
14,
4174,
14,
4912,
492,
30748,
272,
5048,
63,
1813,
275,
747,
14,
2314,
199,
2836,
26,
272,
408,
272,
4420,
30748,
436,
6160,
880,
314,
859,
883,
506,
8439,
272,
641,
642,
4298,
14,
272,
408,
339,
1021,
30748,
26,
267,
869,
3078,
63,
28164,
275,
488,
267,
869,
3078,
63,
14211,
63,
3791,
275,
488,
267,
869,
3078,
63,
7486,
63,
20890,
275,
488,
267,
869,
3078,
63,
13748,
63,
5441,
275,
488,
339,
5048,
63,
1813,
275,
1211,
342,
199,
199,
63,
19875,
25,
63,
17381,
63,
2550,
275,
334,
272,
327,
333,
10599,
25,
5772,
5712,
1133,
2808,
641,
2005,
10677,
272,
3545,
12,
339,
327,
333,
10599,
25,
5772,
6534,
12577,
10397,
547,
315,
2005,
272,
327,
22196,
14,
1666,
327,
845,
1085,
14,
272,
7065,
14,
2550,
14,
12012,
1208,
10397,
547,
12,
199,
9,
199,
199,
893,
26,
272,
687,
7065,
14,
19875,
25,
5772,
492,
5044,
199,
2590,
485,
19875,
25,
63,
17381,
63,
2550,
26,
272,
986,
421,
199,
318,
333,
10599,
25,
63,
1623,
63,
6737,
2936,
452,
8,
1023,
304,
272,
408,
272,
19292,
379,
298,
13350,
14,
19875,
25,
5772,
14,
1623,
63,
6737,
2936,
452,
2,
370,
675,
314,
18042,
272,
6365,
1900,
367,
2018,
334,
9454,
1858,
4718,
680,
481,
452,
1771,
370,
3379,
5953,
272,
1380,
314,
18042,
6365,
365,
440,
2808,
14,
339,
18532,
314,
931,
402,
298,
6737,
2936,
452,
14,
13475,
1674,
339,
31862,
3748,
29784,
272,
10652,
9960,
272,
15332,
14702,
445,
4176,
1749,
14,
16,
26,
267,
15332,
14702,
445,
4176,
27154,
367,
2018,
499,
14,
23,
334,
88,
1184,
12,
282,
1064,
772,
9,
339,
3897,
272,
4143,
272,
1015,
26,
2069,
267,
11105,
15332,
14702,
445,
4176,
1015,
14,
339,
1432,
272,
21397,
272,
16548,
2936,
452,
14,
13475,
931,
26,
620,
272,
408,
272,
24955,
63,
5825,
275,
519,
7,
10337,
60,
5,
83,
12940,
60,
12680,
24305,
60,
9454,
1858,
4718,
60,
5,
16,
14,
17,
70,
7,
272,
790,
275,
24955,
63,
5825,
450,
13134,
1015,
9,
272,
862,
26,
267,
327,
3492,
13,
751,
25801,
2274,
314,
6365,
931,
2348,
267,
3336,
694,
275,
5044,
14,
362,
63,
585,
8,
498,
12,
298,
3174,
694,
531,
272,
871,
4067,
26,
267,
862,
26,
288,
327,
2900,
13,
751,
25801,
641,
282,
5049,
13,
2075,
2656,
2274,
2348,
288,
790,
275,
24955,
63,
5825,
450,
661,
55,
583,
23313,
1716,
1103,
297,
1015,
9,
288,
3336,
694,
275,
5044,
14,
362,
63,
585,
8,
498,
12,
298,
3174,
694,
531,
267,
871,
4067,
26,
288,
3336,
694,
275,
488,
339,
340,
3336,
694,
26,
267,
16548,
2936,
452,
275,
747,
14,
515,
14,
736,
14,
515,
14,
904,
8,
2558,
694,
12,
298,
6737,
2936,
452,
14,
13475,
531,
267,
340,
747,
14,
515,
14,
6292,
8,
6737,
2936,
452,
304,
288,
372,
16548,
2936,
452,
339,
372,
664,
63,
324,
22631,
8,
19875,
25,
63,
1623,
63,
6737,
2936,
452,
5130,
1023,
9,
421,
199,
318,
333,
10599,
25,
63,
1131,
63,
6737,
2936,
452,
8,
422,
12,
3819,
534,
88,
1184,
297,
627,
589,
12,
1011,
958,
304,
272,
408,
272,
19292,
379,
298,
13350,
14,
19875,
25,
5772,
14,
1131,
63,
6737,
2936,
452,
2,
367,
2291,
2402,
272,
29784,
14,
339,
2494,
3734,
1928,
675,
402,
298,
6737,
2936,
452,
14,
13475,
1674,
339,
31862,
3748,
29784,
272,
10652,
9960,
272,
15332,
14702,
445,
4176,
1749,
14,
16,
26,
267,
15332,
14702,
445,
4176,
27154,
367,
2018,
499,
14,
23,
334,
88,
1184,
12,
282,
1064,
772,
9,
267,
15332,
5417,
15610,
1227,
14,
17,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
267,
15332,
5417,
15610,
1520,
14,
16,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
339,
15332,
14702,
445,
4176,
1616,
14,
16,
26,
267,
15332,
5417,
15610,
1520,
14,
17,
334,
88,
1184,
12,
671,
772,
12,
284,
65,
772,
9,
339,
3897,
272,
4143,
272,
809,
26,
2069,
267,
11105,
15332,
14702,
445,
4176,
1015,
14,
272,
3819,
26,
620,
267,
10256,
15931,
14,
339,
1432,
272,
21397,
272,
3734,
26,
1211,
272,
408,
272,
327,
7649,
370,
664,
655,
1042,
368,
434,
687,
16548,
2936,
452,
14,
13475,
334,
30722,
915,
4340,
9,
272,
862,
26,
267,
2306,
275,
664,
63,
324,
22631,
8,
19875,
25,
63,
1131,
63,
6737,
2936,
452,
9,
267,
372,
2306,
8,
422,
12,
3819,
12,
627,
589,
12,
1011,
958,
9,
272,
871,
7065,
14,
2550,
14,
12012,
1208,
10397,
547,
26,
267,
327,
8325,
1125,
340,
812,
67,
2936,
452,
14,
13475,
365,
4124,
267,
986,
272,
871,
1722,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MBARIMike/stoqs
|
stoqs/contrib/parquet/extract_columns.py
|
2
|
11789
|
#!/usr/bin/env python
"""
Pull all the temperature and salinity data out of a STOQS database no
matter what platform and write it out in Parquet file format.
This is a companion to select_data_in_columns_for_data_science.ipynb
where we operationalize the explorations demonstrated in this Notebook:
https://nbviewer.jupyter.org/github/stoqs/stoqs/blob/master/stoqs/contrib/notebooks/select_data_in_columns_for_data_science.ipynb
Sample command line executions:
(base) ➜ docker git:(master) ✗ docker-compose exec stoqs stoqs/contrib/parquet/extract_columns.py --db stoqs_canon_october2020 --platforms dorado -o dorado.parquet -v
INFO 2021-02-24 21:35:53,588 extract_columns.py _estimate_memory():161 Estimated required_memory = 146584085.76
INFO 2021-02-24 21:35:53,588 extract_columns.py _sql_to_df():65 Reading from SQL query into DataFrame...
INFO 2021-02-24 21:36:11,430 extract_columns.py _sql_to_df():77 df.shape: (2245467, 8) - read_sql_query() in 17.8 sec
INFO 2021-02-24 21:36:11,433 extract_columns.py _sql_to_df():78 df.memory_usage().sum(): 143710016
INFO 2021-02-24 21:36:13,876 extract_columns.py pivot_table_to_parquet():172 Writing data to file dorado.parquet...
INFO 2021-02-24 21:36:14,378 extract_columns.py pivot_table_to_parquet():176 dfp.shape: (169159, 16) - to_parquet() in 0.5 sec
INFO 2021-02-24 21:36:14,378 extract_columns.py pivot_table_to_parquet():177 Done
stoqs container peak memory usage: 2.1 GB
(base) ➜ docker git:(master) ✗ docker-compose exec stoqs stoqs/contrib/parquet/extract_columns.py --db stoqs_canon_october2020 --platforms pontus makai -o lrauv.parquet -v
INFO 2021-02-24 21:38:42,623 extract_columns.py _estimate_memory():161 Estimated required_memory = 645795521.28
INFO 2021-02-24 21:38:42,624 extract_columns.py _sql_to_df():65 Reading from SQL query into DataFrame...
INFO 2021-02-24 21:40:13,936 extract_columns.py _sql_to_df():77 df.shape: (9892701, 8) - read_sql_query() in 91.3 sec
INFO 2021-02-24 21:40:13,938 extract_columns.py _sql_to_df():78 df.memory_usage().sum(): 633132992
INFO 2021-02-24 21:40:30,517 extract_columns.py pivot_table_to_parquet():172 Writing data to file lrauv.parquet...
INFO 2021-02-24 21:40:31,798 extract_columns.py pivot_table_to_parquet():176 dfp.shape: (744662, 25) - to_parquet() in 1.3 sec
INFO 2021-02-24 21:40:31,798 extract_columns.py pivot_table_to_parquet():177 Done
stoqs container peak memory usage: 7.9 GB
(base) ➜ docker git:(master) ✗ docker-compose exec stoqs stoqs/contrib/parquet/extract_columns.py --db stoqs_canon_october2020 -o all_plats.parquet -v
INFO 2021-02-24 21:41:53,151 extract_columns.py _estimate_memory():161 Estimated required_memory = 896823624.96
INFO 2021-02-24 21:41:53,153 extract_columns.py _sql_to_df():65 Reading from SQL query into DataFrame...
INFO 2021-02-24 21:43:56,723 extract_columns.py _sql_to_df():77 df.shape: (13738107, 8) - read_sql_query() in 123.6 sec
INFO 2021-02-24 21:43:56,725 extract_columns.py _sql_to_df():78 df.memory_usage().sum(): 879238976
INFO 2021-02-24 21:44:20,578 extract_columns.py pivot_table_to_parquet():172 Writing data to file all_plats.parquet...
INFO 2021-02-24 21:44:23,349 extract_columns.py pivot_table_to_parquet():176 dfp.shape: (1123909, 61) - to_parquet() in 2.8 sec
INFO 2021-02-24 21:44:23,349 extract_columns.py pivot_table_to_parquet():177 Done
stoqs container peak memory usage: 11 GB
A regression of estimated df size to container memory usage gives a factor of 12.3
Mike McCann
MBARI 29 January 2021
"""
import os
import sys
# Insert Django App directory (parent of config) into python path
sys.path.insert(0, os.path.abspath(os.path.join(
os.path.dirname(__file__), "../../")))
if 'DJANGO_SETTINGS_MODULE' not in os.environ:
os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings.local'
# django >=1.7
try:
import django
django.setup()
except AttributeError:
pass
import argparse
import logging
import pandas as pd
from django.db import connections
from stoqs.models import Platform
from time import time
class Columnar():
logger = logging.getLogger(__name__)
_handler = logging.StreamHandler()
_formatter = logging.Formatter('%(levelname)s %(asctime)s %(filename)s '
'%(funcName)s():%(lineno)d %(message)s')
_handler.setFormatter(_formatter)
_log_levels = (logging.WARN, logging.INFO, logging.DEBUG)
logger.addHandler(_handler)
# Set to GB of RAM that have been resourced to the Docker engine
MAX_CONTAINER_MEMORY = 16
DF_TO_RAM_FACTOR = 12.3
def _set_platforms(self):
'''Set plats and plat_list member variables
'''
platforms = (self.args.platforms or
Platform.objects.using(self.args.db).all()
.values_list('name', flat=True).order_by('name'))
self.logger.debug(platforms)
self.plats = ''
self.plat_list = []
for platform in platforms:
if platform in self.args.platforms_omit:
# Omit some platforms for shorter execution times
continue
self.plats += f"'{platform}',"
self.plat_list.append(platform)
self.plats = self.plats[:-2] + "'"
def _sql_to_df(self, sql, extract=False):
if extract:
self.logger.info('Reading from SQL query into DataFrame...')
# More than 10 GB of RAM is needed in Docker Desktop for reading data
# from stoqs_canon_october2020. The chunksize option in read_sql_query()
# does not help reduce the server side memory usage.
# See: https://stackoverflow.com/a/31843091/1281657
# https://github.com/pandas-dev/pandas/issues/12265#issuecomment-181809005
# https://github.com/pandas-dev/pandas/issues/35689
stime = time()
df = pd.read_sql_query(sql, connections[self.args.db])
etime = time() - stime
if extract:
self.logger.info(f"df.shape: {df.shape} <- read_sql_query() in {etime:.1f} sec")
self.logger.info(f"Actual df.memory_usage().sum():"
f" {(df.memory_usage().sum()/1.e9):.3f} GB")
self.logger.debug(f"Head of original df:\n{df.head()}")
return df
def _build_sql(self, limit=None, order=True, count=False):
self._set_platforms()
# Base query that's similar to the one behind the api/measuredparameter.csv request
sql = f'''\nFROM public.stoqs_measuredparameter
INNER JOIN stoqs_measurement ON (stoqs_measuredparameter.measurement_id = stoqs_measurement.id)
INNER JOIN stoqs_instantpoint ON (stoqs_measurement.instantpoint_id = stoqs_instantpoint.id)
INNER JOIN stoqs_activity ON (stoqs_instantpoint.activity_id = stoqs_activity.id)
INNER JOIN stoqs_platform ON (stoqs_activity.platform_id = stoqs_platform.id)
INNER JOIN stoqs_parameter ON (stoqs_measuredparameter.parameter_id = stoqs_parameter.id)
WHERE stoqs_platform.name IN ({self.plats})
AND stoqs_parameter.{self.args.collect} is not null'''
if count:
sql = 'SELECT count(*) ' + sql
else:
sql = f'''SELECT stoqs_platform.name as platform,
stoqs_instantpoint.timevalue, stoqs_measurement.depth,
ST_X(stoqs_measurement.geom) as longitude,
ST_Y(stoqs_measurement.geom) as latitude,
stoqs_parameter.{self.args.collect},
stoqs_measuredparameter.datavalue {sql}'''
if order:
sql += ('\nORDER BY stoqs_platform.name, stoqs_instantpoint.timevalue,'
' stoqs_measurement.depth, stoqs_parameter.name')
if limit:
sql += f"\nLIMIT {limit}"
self.logger.debug(f'sql = {sql}')
return sql
def _estimate_memory(self):
'''Perform a small query on the selection and extrapolate
to estimate the server-side memory required for the full extraction.
'''
SAMPLE_SIZE = 100
sql = self._build_sql(limit=SAMPLE_SIZE, order=False)
df = self._sql_to_df(sql)
sample_memory = df.memory_usage().sum()
self.logger.debug(f"{sample_memory} B for {SAMPLE_SIZE} records")
total_recs = self._sql_to_df(self._build_sql(count=True))['count'][0]
self.logger.debug(f"total_recs = {total_recs}")
required_memory = total_recs * sample_memory / SAMPLE_SIZE / 1.e9
container_memory = self.DF_TO_RAM_FACTOR * required_memory
self.logger.info(f"Estimated required_memory:"
f" {required_memory:.3f} GB for DataFrame,"
f" {container_memory:.3f} GB for container RAM,")
if container_memory > self.MAX_CONTAINER_MEMORY:
self.logger.exception(f"Request of {container_memory:.3f} GB would"
f" exceed {self.MAX_CONTAINER_MEMORY} GB"
f" of RAM available")
sys.exit(-1)
def pivot_table_to_parquet(self):
'''Approach 4. Use Pandas do a pivot on data read into a DataFrame
'''
self._estimate_memory()
sql = self._build_sql()
df = self._sql_to_df(sql, extract=True)
context = ['platform', 'timevalue', 'depth', 'latitude', 'longitude']
dfp = df.pivot_table(index=context, columns=self.args.collect, values='datavalue')
self.logger.debug(dfp.shape)
self.logger.info(f'Writing data to file {self.args.output}...')
stime = time()
dfp.to_parquet(self.args.output)
etime = time() - stime
self.logger.info(f"dfp.shape: {dfp.shape} -> to_parquet() in {etime:.1f} sec")
self.logger.debug(f"Head of pivoted df:\n{dfp.head()}")
self.logger.info('Done')
def process_command_line(self):
parser = argparse.ArgumentParser(description='Transform STOQS data into columnar Parquet file format')
parser.add_argument('--platforms', action='store', nargs='*',
help='Restrict to just these platforms')
parser.add_argument('--platforms_omit', action='store', nargs='*', default=[],
help='Restrict to all but these platforms')
parser.add_argument('--collect', action='store', default='name',
choices=['name', 'standard_name'],
help='The column to collect: name or standard_name')
parser.add_argument('--db', action='store', required=True,
help='Database alias, e.g. stoqs_canon_october2020')
parser.add_argument('-o', '--output', action='store', required=True,
help='Output file name')
parser.add_argument('--start', action='store', help='Start time in YYYYMMDDTHHMMSS format',
default='19000101T000000')
parser.add_argument('--end', action='store', help='End time in YYYYMMDDTHHMMSS format',
default='22000101T000000')
parser.add_argument('-v', '--verbose', type=int, choices=range(3),
action='store', default=0, const=1, nargs='?',
help="verbosity level: " + ', '.join(
[f"{i}: {v}" for i, v, in enumerate(('WARN', 'INFO', 'DEBUG'))]))
self.args = parser.parse_args()
self.commandline = ' '.join(sys.argv)
self.logger.setLevel(self._log_levels[self.args.verbose])
self.logger.debug(f"Using databases at DATABASE_URL ="
f" {os.environ['DATABASE_URL']}")
if __name__ == '__main__':
c = Columnar()
c.process_command_line()
c.pivot_table_to_parquet()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
27318,
1006,
314,
14843,
436,
18641,
9624,
666,
734,
402,
282,
428,
2566,
23298,
3050,
949,
199,
569,
351,
4052,
4298,
436,
2218,
652,
734,
315,
2235,
17917,
570,
1475,
14,
199,
199,
2765,
365,
282,
1013,
32012,
370,
3504,
63,
576,
63,
262,
63,
3406,
63,
509,
63,
576,
63,
9907,
4894,
14,
73,
647,
4994,
199,
4509,
781,
3439,
279,
794,
314,
29278,
269,
1298,
23789,
495,
972,
315,
642,
3390,
2706,
26,
199,
199,
2859,
921,
4994,
16645,
14,
74,
28022,
351,
14,
1308,
15,
5031,
15,
14308,
6177,
15,
14308,
6177,
15,
6582,
15,
4133,
15,
14308,
6177,
15,
2828,
15,
4610,
8858,
15,
2416,
63,
576,
63,
262,
63,
3406,
63,
509,
63,
576,
63,
9907,
4894,
14,
73,
647,
4994,
199,
199,
8176,
1414,
1004,
2146,
8653,
26,
199,
199,
8,
1095,
9,
22410,
253,
251,
221,
12424,
6135,
20334,
4133,
9,
22410,
251,
246,
12424,
13,
12607,
2146,
26123,
6177,
26123,
6177,
15,
2828,
15,
462,
17917,
15,
5005,
63,
3406,
14,
647,
1553,
697,
26123,
6177,
63,
2425,
265,
63,
15560,
22459,
13934,
1553,
19601,
366,
269,
5129,
446,
79,
366,
269,
5129,
14,
462,
17917,
446,
86,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1276,
26,
2481,
12,
29043,
5536,
63,
3406,
14,
647,
485,
21196,
63,
4844,
837,
12285,
15896,
12754,
1415,
63,
4844,
275,
4329,
2182,
1349,
17494,
14,
2114,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1276,
26,
2481,
12,
29043,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2182,
799,
5384,
687,
5385,
1827,
1901,
10071,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
845,
12,
25473,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
1138,
4051,
14,
1392,
26,
334,
8731,
1477,
1822,
12,
1695,
9,
446,
1586,
63,
3009,
63,
1131,
342,
315,
5557,
14,
24,
6513,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
845,
12,
23404,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2277,
4051,
14,
4844,
63,
3807,
1252,
1838,
837,
4329,
1401,
1960,
975,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
969,
12,
14690,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
10419,
12859,
1337,
666,
370,
570,
366,
269,
5129,
14,
462,
17917,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
1079,
12,
12046,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
10216,
366,
3997,
14,
1392,
26,
334,
10143,
9327,
12,
3193,
9,
446,
370,
63,
462,
17917,
342,
315,
378,
14,
21,
6513,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
1079,
12,
12046,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
8881,
23541,
199,
14308,
6177,
3970,
21441,
4402,
4503,
26,
499,
14,
17,
18553,
199,
199,
8,
1095,
9,
22410,
253,
251,
221,
12424,
6135,
20334,
4133,
9,
22410,
251,
246,
12424,
13,
12607,
2146,
26123,
6177,
26123,
6177,
15,
2828,
15,
462,
17917,
15,
5005,
63,
3406,
14,
647,
1553,
697,
26123,
6177,
63,
2425,
265,
63,
15560,
22459,
13934,
1553,
19601,
299,
1888,
527,
5475,
5789,
446,
79,
634,
345,
9154,
14,
462,
17917,
446,
86,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1703,
26,
2260,
12,
31353,
5536,
63,
3406,
14,
647,
485,
21196,
63,
4844,
837,
12285,
15896,
12754,
1415,
63,
4844,
275,
5049,
14003,
1229,
2025,
14,
1651,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1703,
26,
2260,
12,
28062,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2182,
799,
5384,
687,
5385,
1827,
1901,
10071,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
969,
12,
29959,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
1138,
4051,
14,
1392,
26,
334,
30924,
1465,
614,
12,
1695,
9,
446,
1586,
63,
3009,
63,
1131,
342,
315,
21358,
14,
19,
6513,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
969,
12,
25,
1703,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2277,
4051,
14,
4844,
63,
3807,
1252,
1838,
837,
1227,
1153,
6557,
16544,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
1216,
12,
27696,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
10419,
12859,
1337,
666,
370,
570,
634,
345,
9154,
14,
462,
17917,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
2192,
12,
16564,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
10216,
366,
3997,
14,
1392,
26,
334,
15839,
19243,
12,
5661,
9,
446,
370,
63,
462,
17917,
342,
315,
413,
14,
19,
6513,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
2192,
12,
16564,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
8881,
23541,
199,
14308,
6177,
3970,
21441,
4402,
4503,
26,
1520,
14,
25,
18553,
199,
199,
8,
1095,
9,
22410,
253,
251,
221,
12424,
6135,
20334,
4133,
9,
22410,
251,
246,
12424,
13,
12607,
2146,
26123,
6177,
26123,
6177,
15,
2828,
15,
462,
17917,
15,
5005,
63,
3406,
14,
647,
1553,
697,
26123,
6177,
63,
2425,
265,
63,
15560,
22459,
13934,
446,
79,
1006,
63,
1168,
1956,
14,
462,
17917,
446,
86,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2953,
26,
2481,
12,
12768,
5536,
63,
3406,
14,
647,
485,
21196,
63,
4844,
837,
12285,
15896,
12754,
1415,
63,
4844,
275,
17838,
2333,
10008,
1194,
14,
2534,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2953,
26,
2481,
12,
12034,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2182,
799,
5384,
687,
5385,
1827,
1901,
10071,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2824,
26,
1367,
12,
23,
1789
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
27318,
1006,
314,
14843,
436,
18641,
9624,
666,
734,
402,
282,
428,
2566,
23298,
3050,
949,
199,
569,
351,
4052,
4298,
436,
2218,
652,
734,
315,
2235,
17917,
570,
1475,
14,
199,
199,
2765,
365,
282,
1013,
32012,
370,
3504,
63,
576,
63,
262,
63,
3406,
63,
509,
63,
576,
63,
9907,
4894,
14,
73,
647,
4994,
199,
4509,
781,
3439,
279,
794,
314,
29278,
269,
1298,
23789,
495,
972,
315,
642,
3390,
2706,
26,
199,
199,
2859,
921,
4994,
16645,
14,
74,
28022,
351,
14,
1308,
15,
5031,
15,
14308,
6177,
15,
14308,
6177,
15,
6582,
15,
4133,
15,
14308,
6177,
15,
2828,
15,
4610,
8858,
15,
2416,
63,
576,
63,
262,
63,
3406,
63,
509,
63,
576,
63,
9907,
4894,
14,
73,
647,
4994,
199,
199,
8176,
1414,
1004,
2146,
8653,
26,
199,
199,
8,
1095,
9,
22410,
253,
251,
221,
12424,
6135,
20334,
4133,
9,
22410,
251,
246,
12424,
13,
12607,
2146,
26123,
6177,
26123,
6177,
15,
2828,
15,
462,
17917,
15,
5005,
63,
3406,
14,
647,
1553,
697,
26123,
6177,
63,
2425,
265,
63,
15560,
22459,
13934,
1553,
19601,
366,
269,
5129,
446,
79,
366,
269,
5129,
14,
462,
17917,
446,
86,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1276,
26,
2481,
12,
29043,
5536,
63,
3406,
14,
647,
485,
21196,
63,
4844,
837,
12285,
15896,
12754,
1415,
63,
4844,
275,
4329,
2182,
1349,
17494,
14,
2114,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1276,
26,
2481,
12,
29043,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2182,
799,
5384,
687,
5385,
1827,
1901,
10071,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
845,
12,
25473,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
1138,
4051,
14,
1392,
26,
334,
8731,
1477,
1822,
12,
1695,
9,
446,
1586,
63,
3009,
63,
1131,
342,
315,
5557,
14,
24,
6513,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
845,
12,
23404,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2277,
4051,
14,
4844,
63,
3807,
1252,
1838,
837,
4329,
1401,
1960,
975,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
969,
12,
14690,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
10419,
12859,
1337,
666,
370,
570,
366,
269,
5129,
14,
462,
17917,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
1079,
12,
12046,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
10216,
366,
3997,
14,
1392,
26,
334,
10143,
9327,
12,
3193,
9,
446,
370,
63,
462,
17917,
342,
315,
378,
14,
21,
6513,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1344,
26,
1079,
12,
12046,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
8881,
23541,
199,
14308,
6177,
3970,
21441,
4402,
4503,
26,
499,
14,
17,
18553,
199,
199,
8,
1095,
9,
22410,
253,
251,
221,
12424,
6135,
20334,
4133,
9,
22410,
251,
246,
12424,
13,
12607,
2146,
26123,
6177,
26123,
6177,
15,
2828,
15,
462,
17917,
15,
5005,
63,
3406,
14,
647,
1553,
697,
26123,
6177,
63,
2425,
265,
63,
15560,
22459,
13934,
1553,
19601,
299,
1888,
527,
5475,
5789,
446,
79,
634,
345,
9154,
14,
462,
17917,
446,
86,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1703,
26,
2260,
12,
31353,
5536,
63,
3406,
14,
647,
485,
21196,
63,
4844,
837,
12285,
15896,
12754,
1415,
63,
4844,
275,
5049,
14003,
1229,
2025,
14,
1651,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
1703,
26,
2260,
12,
28062,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2182,
799,
5384,
687,
5385,
1827,
1901,
10071,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
969,
12,
29959,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
1138,
4051,
14,
1392,
26,
334,
30924,
1465,
614,
12,
1695,
9,
446,
1586,
63,
3009,
63,
1131,
342,
315,
21358,
14,
19,
6513,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
969,
12,
25,
1703,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2277,
4051,
14,
4844,
63,
3807,
1252,
1838,
837,
1227,
1153,
6557,
16544,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
1216,
12,
27696,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
10419,
12859,
1337,
666,
370,
570,
634,
345,
9154,
14,
462,
17917,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
2192,
12,
16564,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
10216,
366,
3997,
14,
1392,
26,
334,
15839,
19243,
12,
5661,
9,
446,
370,
63,
462,
17917,
342,
315,
413,
14,
19,
6513,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2167,
26,
2192,
12,
16564,
5536,
63,
3406,
14,
647,
22292,
63,
1224,
63,
475,
63,
462,
17917,
837,
8881,
23541,
199,
14308,
6177,
3970,
21441,
4402,
4503,
26,
1520,
14,
25,
18553,
199,
199,
8,
1095,
9,
22410,
253,
251,
221,
12424,
6135,
20334,
4133,
9,
22410,
251,
246,
12424,
13,
12607,
2146,
26123,
6177,
26123,
6177,
15,
2828,
15,
462,
17917,
15,
5005,
63,
3406,
14,
647,
1553,
697,
26123,
6177,
63,
2425,
265,
63,
15560,
22459,
13934,
446,
79,
1006,
63,
1168,
1956,
14,
462,
17917,
446,
86,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2953,
26,
2481,
12,
12768,
5536,
63,
3406,
14,
647,
485,
21196,
63,
4844,
837,
12285,
15896,
12754,
1415,
63,
4844,
275,
17838,
2333,
10008,
1194,
14,
2534,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2953,
26,
2481,
12,
12034,
5536,
63,
3406,
14,
647,
485,
3009,
63,
475,
63,
1587,
837,
2182,
799,
5384,
687,
5385,
1827,
1901,
10071,
1396,
199,
4531,
499,
15385,
13,
996,
13,
1194,
7829,
26,
2824,
26,
1367,
12,
23,
1789,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,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Ensemble_Rfamplitude_prediction.py
|
2
|
11411
|
# Stacked Ensemble RfAmp Prediction Model
# Multiple ML regressors are individually trained and then combined via meta-regressor.
# Hyperparameters are tuned via GridSearchCV
# coding: utf-8
from __future__ import division
import optparse
import numpy as np
import pandas as pd
import os
if not os.getenv("DISPLAY", None):
import matplotlib
matplotlib.use("agg", warn=False)
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import matplotlib.cm as cm
from sklearn.model_selection import train_test_split
from sklearn import preprocessing
from sklearn.externals import joblib
from mlxtend.regressor import StackingCVRegressor
from sklearn.datasets import load_boston
from sklearn.linear_model import Lasso
from sklearn.linear_model import Ridge
from sklearn.ensemble import RandomForestRegressor
from sklearn.svm import SVR
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import GridSearchCV
from keras.models import Sequential, model_from_json
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD, Adagrad, Adadelta, RMSprop, Adam
from keras import losses
from keras import callbacks
from keras.utils import plot_model
import pickle
__author__ = "Nikhil Mukund <nikhil.mukund@ligo.org>, Michael Coughlin <michael.coughlin.ligo.org>"
__version__ = 1.0
__date__ = "11/26/2017"
def parse_commandline():
"""@parse the options given on the command-line.
"""
parser = optparse.OptionParser(usage=__doc__,version=__version__)
parser.add_option("-f", "--earthquakesFile", help="Seismon earthquakes file.",default ="/home/mcoughlin/Seismon/Predictions/L1O1O2_CMT_GPR/earthquakes.txt")
parser.add_option("-o", "--outputDirectory", help="output folder.",default ="/home/mcoughlin/Seismon/MLA/L1O1O2/")
parser.add_option("-r", "--runType", help="run type (original, lowlatency, cmt)", default ="lowlatency")
parser.add_option("-m", "--minMagnitude", help="Minimum earthquake magnitude.", default=5.0,type=float)
parser.add_option("-N", "--Nepoch", help="number of epochs", default =10, type=int)
parser.add_option("--doPlots", action="store_true", default=False)
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Run verbosely. (Default: False)")
opts, args = parser.parse_args()
# show parameters
if opts.verbose:
print >> sys.stderr, ""
print >> sys.stderr, "running network_eqmon..."
print >> sys.stderr, "version: %s"%__version__
print >> sys.stderr, ""
print >> sys.stderr, "***************** PARAMETERS ********************"
for o in opts.__dict__.items():
print >> sys.stderr, o[0]+":"
print >> sys.stderr, o[1]
print >> sys.stderr, ""
return opts
'''
0: earthquake gps time
1: earthquake mag
2: p gps time
3: s gps time
4: r (2 km/s)
5: r (3.5 km/s)
6: r (5 km/s)
7: predicted ground motion (m/s)
8: lower bounding time
9: upper bounding time
10: latitude
11: longitude
12: distance
13: depth (m)
14: azimuth (deg)
15: nodalPlane1_strike
16: nodalPlane1_rake
17: nodalPlane1_dip
18: momentTensor_Mrt
19: momentTensor_Mtp
20: momentTensor_Mrp
21: momentTensor_Mtt
22: momentTensor_Mrr
23: momentTensor_Mpp
24: peak ground velocity gps time
25: peak ground velocity (m/s)
26: peak ground acceleration gps time
27: peak ground acceleration (m/s^2)
28: peak ground displacement gps time
29: peak ground displacement (m)
30: Lockloss time
31: Detector Status
'''
# Parse command line
opts = parse_commandline()
outputDirectory = os.path.join(opts.outputDirectory,opts.runType)
if not os.path.isdir(outputDirectory):
os.makedirs(outputDirectory)
data = pd.read_csv(opts.earthquakesFile,delimiter=' ',header=None)
neqs, ncols = data.shape
if ncols == 32:
fileType = "seismon"
elif ncols == 27:
fileType = "usarray"
data = data.drop(data.columns[[24]], 1)
data = data.rename(index=int, columns={25: 24, 26: 25})
else:
print("I do not understand the file type...")
exit(0)
# find magnitudes greater than minimum magnitude
index = data[1] > opts.minMagnitude
data = data[:][index]
# find depth = 0
index = np.where(data[[13]] == 0)[0]
data.iloc[index,13] = 1.0
# shuffle data
data = data.reindex(np.random.permutation(data.index))
Mag_idx = 1
Dist_idx = 12
Depth_idx = 13
Rf_Amp_idx = 25
# Mag threshold
Rf_Amp_thresh = 1e-8;
index = data[Rf_Amp_idx] > Rf_Amp_thresh
data = data[:][index]
if opts.runType == "cmt":
# Select features
FeatSet_index = [1,10,11,12,13,14,15,16,17,18,19,20,21,22,23]
elif opts.runType == "lowlatency":
#FeatSet_index = [1,7,10,11,12,13,14,15,16,17] # these lower set paramaters makes sense
FeatSet_index = [1,10,11,12,13,14] # these lower set paramaters makes sense
elif opts.runType == "original":
FeatSet_index = [1,12,13] # Just Mag, Dist, Depth
else:
print("--runType must be original, lowlatency, and cmt")
exit(0)
Target_index = [Rf_Amp_idx]
# Artificially increase samples
data_temp = data
copy_num = 6
noise_level = 1e-2 # 1e-2
Rfamp_orig = data_temp[Target_index];
data_orig = data_temp
def boost_samples(x_samples,y_samples,copy_num=3,noise_level=1e-2):
# Artificially increase samples
data_x_temp = x_samples
data_y_temp = y_samples
for i in range(copy_num):
data_x_temp = np.vstack((data_x_temp,data_x_temp))
data_y_temp = np.vstack((data_y_temp,data_y_temp))
data_x_orig = data_x_temp
data_y_orig = data_y_temp
x1 = data_x_temp
x2 = np.random.randn(*data_x_temp.shape)*noise_level
x_samples_boosted = x1 + np.multiply(x1,x2)
y1 = data_y_temp
y2 = np.random.randn(*data_y_temp.shape)*noise_level
y_samples_boosted = y1 + np.multiply(y1,y2)
# Shuffle samples
#IDX = np.random.permutation(y_samples_boosted.index)
IDX = np.random.permutation(np.arange(0,len(y_samples_boosted)))
x_samples_boosted = x_samples_boosted[IDX,:]
y_samples_boosted = y_samples_boosted[IDX,:]
return x_samples_boosted, y_samples_boosted
data = data_temp
# Take Log10 of certain features (Mag, Dist, Depth)
data[[Dist_idx, Depth_idx]] = np.log10(data[[Dist_idx, Depth_idx]])
data[Target_index] = np.log10(data[Target_index])
X = np.asarray(data[FeatSet_index])
Y = np.asarray(data[Target_index])
# Normalize samples
x_scaler = preprocessing.MinMaxScaler()
#x_scaler = preprocessing.data.QuantileTransformer()
X = x_scaler.fit_transform(X)
y_scaler = preprocessing.MinMaxScaler()
#y_scaler = preprocessing.data.QuantileTransformer()
Y = y_scaler.fit_transform(Y)
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.3,random_state=42)
x_train, x_val, y_train, y_val = train_test_split(x_train, y_train, test_size=0.3,random_state=42)
# boost_samples + normalize + shuffle them
TUPLE1 = boost_samples(x_train,y_train,copy_num,noise_level)
TUPLE2 = boost_samples(x_val,y_val,copy_num,noise_level)
TUPLE3 = boost_samples(x_test,y_test,copy_num,noise_level)
x_train = TUPLE1[0]
y_train = TUPLE1[1]
x_val = TUPLE2[0]
y_val = TUPLE2[1]
x_test = TUPLE3[0]
y_test = TUPLE3[1]
#############################################
# Construct Stacked Ensemble Model #
#############################################
RANDOM_SEED = 42
ridge = Ridge()
lasso = Lasso()
svr_lin = SVR(kernel='linear')
svr_rbf = SVR(kernel='rbf')
lr = LinearRegression()
rf = RandomForestRegressor(random_state=RANDOM_SEED)
np.random.seed(RANDOM_SEED)
regressors = [svr_lin, svr_rbf, lr, ridge, lasso]
stack = StackingCVRegressor(regressors=regressors,
meta_regressor=rf,
use_features_in_secondary=True)
'''params = {'lasso__alpha': [0.1, 1.0, 10.0],
'ridge__alpha': [0.1, 1.0, 10.0],
'svr__C': [0.1, 1.0, 10.0],
'meta-svr__C': [0.1, 1.0, 10.0, 100.0],
'meta-svr__gamma': [0.1, 1.0, 10.0]}
params = {'lasso__alpha': [0.1, 1.0, 10.0],
'ridge__alpha': [0.1, 1.0, 10.0]}'''
model = GridSearchCV(
estimator=stack,
param_grid={
'lasso__alpha': [x/5.0 for x in range(1, 10)],
'ridge__alpha': [x/20.0 for x in range(1, 10)],
'meta-randomforestregressor__n_estimators': [10, 100]
},
cv=5,
refit=True,
verbose=10,
n_jobs=8,
)
###################################################
model.fit(x_train, y_train.ravel())
print("Best: %f using %s" % (grid.best_score_, grid.best_params_))
###################################################
y_pred = model.predict(x_test)
y_pred = np.expand_dims(y_pred,axis=1)
# Rescale Back
y_pred = 10**y_scaler.inverse_transform(y_pred)
y_test = 10**y_scaler.inverse_transform(y_test)
# Reject test samples below certain threshold
Rf_thresh = 0.5*1e-7 # 0.5*1e-6
ijk = y_test > Rf_thresh
y_test = y_test[ijk]
y_pred = y_pred[ijk]
x_test = x_test[ijk.flatten(),:]
# Add bias
#y_pred = y_pred + 0.1*y_pred
# sort results in Ascending order
y_test_sort = np.sort(y_test,axis=0)
y_pred_sort = y_pred[np.argsort(y_test,axis=0)]
## Percentage within the specified factor
Fac = 2
IDX = y_pred_sort/(y_test_sort+np.finfo(float).eps) >= 1
K = y_pred_sort[IDX]
Q = y_test_sort[IDX]
L = y_pred_sort[~IDX]
M = y_test_sort[~IDX]
Upper_indices = [i for i, x in enumerate(K <= Fac*Q) if x == True]
Lower_indices = [i for i, x in enumerate(L >= M/Fac) if x == True]
Percent_within_Fac = (len(Upper_indices) + len(Lower_indices))/len(y_pred)*100
print("Percentage captured within a factor of {} = {:.2f}".format(Fac,Percent_within_Fac))
Diff = abs(y_pred_sort - y_test_sort)
# Errorbar values
yerr_lower = y_test_sort - y_test_sort/Fac
yerr_upper = Fac*y_test_sort - y_test_sort
idx = np.arange(0,len(y_test_sort))
if opts.doPlots:
font = {'weight' : 'bold',
'size' : 15}
plt.rc('font', **font)
plt.rc('legend',**{'fontsize':15})
plt.figure(figsize=(10,8))
plt.style.use('dark_background')
#plt.style.use('ggplot')
diff_plt = plt.scatter(idx,Diff,color='lightgreen',alpha=0.1)
errorbar_plt = plt.errorbar(idx,y_test_sort,yerr=[yerr_lower,yerr_upper], alpha=0.05 ,color='lightgrey')
actual_plt = plt.scatter(idx,y_test_sort,color='#1f77b4',alpha=0.9)
idx2 = np.arange(0,len(y_pred_sort))
pred_plt = plt.scatter(idx2,y_pred_sort,color='#d62728',alpha=0.2)
plt.yscale('log')
plt.grid()
plt.ylim([1e-7, 1e-3])
#plt.ylim([0, 1])
#plt.ylabel('Rf Amplitude (m/s) \n (Normalized to 1)',fontsize=25)
plt.ylabel('Rf Amplitude (m/s) ',fontsize=25)
plt.xlabel('Samples',fontsize=25)
plt.title("Percentage captured within a factor of {} = {:.2f}".format(Fac,Percent_within_Fac))
legend_plt = plt.legend([pred_plt,actual_plt, diff_plt],['Prediction', 'Actual', 'Difference'],loc=2,markerscale=2., scatterpoints=100)
plt.autoscale(enable=True, axis='x', tight=True)
plt.grid(linestyle=':')
plt.savefig(os.path.join(outputDirectory,'performance.pdf'),bbox_inches='tight')
plt.close()
# Save Model
# serialize model & pickle
pickle.dump(model, open("%s/model.p"%outputDirectory, "wb"))
print("Saved model to disk")
'''
# Load Saved Model
# load pickle
pickle_file = open('%s/model.p'%outputDirectory, 'rb')
loaded_model_pickle = pickle.load(pickle_file)
print("Loaded model from disk")
'''
|
gpl-3.0
|
[
3,
13894,
379,
3447,
8834,
820,
13753,
311,
5543,
26382,
5822,
199,
3,
14326,
28007,
1295,
753,
1384,
787,
7814,
3163,
28161,
436,
2066,
12149,
4799,
3404,
13,
1135,
11686,
14,
221,
199,
3,
21344,
3214,
787,
15486,
379,
4799,
32570,
199,
199,
3,
2803,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
8691,
199,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
646,
747,
199,
199,
692,
440,
747,
14,
12959,
480,
20993,
401,
488,
304,
272,
492,
8027,
272,
8027,
14,
1180,
480,
13452,
401,
7987,
29,
797,
9,
199,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
8027,
14,
1278,
465,
333,
1278,
199,
646,
8027,
14,
4400,
465,
6904,
199,
199,
504,
6357,
14,
1238,
63,
5592,
492,
3560,
63,
396,
63,
1294,
199,
504,
6357,
492,
26471,
199,
504,
6357,
14,
24688,
492,
3906,
773,
199,
504,
19184,
88,
7169,
14,
1135,
11686,
492,
13894,
316,
12847,
15155,
199,
504,
6357,
14,
12281,
492,
2248,
63,
28275,
199,
504,
6357,
14,
6676,
63,
1238,
492,
29029,
199,
504,
6357,
14,
6676,
63,
1238,
492,
31196,
199,
504,
6357,
14,
15628,
492,
9571,
21668,
15155,
199,
504,
6357,
14,
16820,
492,
14056,
50,
199,
504,
6357,
14,
6676,
63,
1238,
492,
12489,
13013,
199,
504,
6357,
14,
1238,
63,
5592,
492,
32570,
199,
199,
504,
11708,
14,
992,
492,
3240,
9092,
12,
1402,
63,
504,
63,
1001,
199,
504,
11708,
14,
4359,
492,
20847,
12,
18110,
548,
12,
29441,
199,
504,
11708,
14,
6433,
6315,
492,
18868,
36,
12,
4431,
27707,
12,
437,
983,
3136,
12,
820,
3053,
4469,
12,
4431,
455,
199,
504,
11708,
492,
21289,
199,
504,
11708,
492,
13484,
199,
504,
11708,
14,
1208,
492,
5137,
63,
1238,
199,
199,
646,
5927,
199,
199,
363,
2502,
363,
275,
298,
46,
3258,
72,
382,
603,
3210,
725,
665,
22998,
72,
382,
14,
77,
3210,
725,
32,
317,
1939,
14,
1308,
6244,
16922,
445,
4937,
472,
665,
22333,
14,
331,
3080,
472,
14,
317,
1939,
14,
1308,
4335,
199,
363,
1023,
363,
275,
413,
14,
16,
199,
363,
602,
363,
275,
298,
845,
15,
1479,
15,
10680,
2,
199,
199,
318,
2198,
63,
1531,
604,
837,
272,
408,
32,
1122,
314,
1511,
1627,
641,
314,
1414,
13,
604,
14,
272,
408,
272,
1798,
275,
8691,
14,
14553,
8,
3807,
18971,
1301,
3108,
1023,
18971,
1023,
3368,
339,
1798,
14,
525,
63,
1422,
6096,
70,
401,
4320,
2210,
273,
392,
4364,
1173,
401,
1720,
628,
1513,
374,
2106,
8413,
273,
392,
4364,
570,
4765,
885,
275,
15313,
4219,
15,
77,
331,
3080,
472,
15,
1513,
374,
2106,
15,
14730,
2452,
15,
44,
17,
47,
17,
47,
18,
63,
35,
5747,
63,
39,
3311,
15,
2210,
273,
392,
4364,
14,
2424,
531,
272,
1798,
14,
525,
63,
1422,
6096,
79,
401,
4320,
1199,
6231,
401,
1720,
628,
1199,
4922,
4765,
885,
275,
15313,
4219,
15,
77,
331,
3080,
472,
15,
1513,
374,
2106,
15,
1698,
33,
15,
44,
17,
47,
17,
47,
18,
13589,
272,
1798,
14,
525,
63,
1422,
6096,
82,
401,
4320,
1065,
804,
401,
1720,
628,
1065,
730,
334,
5043,
12,
6465,
19645,
12,
286,
2037,
4186,
849,
29049,
674,
19645,
531,
272,
1798,
14,
525,
63,
1422,
6096,
77,
401,
4320,
827,
22745,
78,
7779,
401,
1720,
628,
12092,
8413,
273,
392,
1728,
22877,
4765,
849,
29,
21,
14,
16,
12,
466,
29,
1609,
9,
272,
1798,
14,
525,
63,
1422,
6096,
46,
401,
4320,
4698,
5132,
401,
1720,
628,
1955,
402,
18463,
401,
849,
275,
709,
12,
730,
29,
442,
9,
272,
1798,
14,
525,
63,
1422,
6739,
1117,
48,
4555,
401,
221,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
272,
1798,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
1993,
1720,
628,
2540,
3376,
590,
14,
334,
2698,
26,
756,
6320,
339,
3999,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
327,
2498,
2633,
272,
340,
3999,
14,
3832,
26,
267,
870,
4331,
984,
14,
3083,
12,
3087,
267,
870,
4331,
984,
14,
3083,
12,
298,
5720,
2784,
63,
4077,
2106,
11500,
267,
870,
4331,
984,
14,
3083,
12,
298,
1023,
26,
450,
83,
6808,
363,
1023,
363,
267,
870,
4331,
984,
14,
3083,
12,
3087,
267,
870,
4331,
984,
14,
3083,
12,
298,
3096,
10,
23710,
1011,
3096,
538,
2,
267,
367,
312,
315,
3999,
855,
807,
4343,
1744,
837,
881,
870,
4331,
984,
14,
3083,
12,
312,
59,
16,
2807,
5122,
881,
870,
4331,
984,
14,
3083,
12,
312,
59,
17,
61,
267,
870,
4331,
984,
14,
3083,
12,
3087,
339,
372,
3999,
199,
199,
2344,
199,
16,
26,
8413,
273,
392,
1728,
486,
1190,
900,
199,
17,
26,
8413,
273,
392,
1728,
8127,
199,
18,
26,
299,
486,
1190,
900,
199,
19,
26,
308,
486,
1190,
900,
199,
20,
26,
519,
334,
18,
16155,
15,
83,
9,
199,
21,
26,
519,
334,
19,
14,
21,
16155,
15,
83,
9,
199,
22,
26,
519,
334,
21,
16155,
15,
83,
9,
199,
23,
26,
14746,
19252,
25134,
334,
77,
15,
83,
9,
199,
24,
26,
5117,
16842,
900,
199,
25,
26,
7008,
16842,
900,
199,
709,
26,
18896,
199,
845,
26,
18154,
199,
713,
26,
6033,
199,
969,
26,
5818,
334,
77,
9,
199,
1079,
26,
24978,
26720,
334,
6458,
9,
199,
1046,
26,
302,
364,
279,
23363,
17,
63,
26845,
199,
975,
26,
302,
364,
279,
23363,
17,
63,
345,
415,
199,
1196,
26,
302,
364,
279,
23363,
17,
63,
21846,
199,
1085,
26,
12427,
3861,
63,
45,
2591,
199,
1167,
26,
12427,
3861,
63,
45,
683,
199,
1165,
26,
12427,
3861,
63,
45,
4599,
199,
2025,
26,
12427,
3861,
63,
45,
6215,
199,
1081,
26,
12427,
3861,
63,
45,
9734,
199,
1789,
26,
12427,
3861,
63,
45,
802,
199,
1194,
26,
21441,
19252,
20508,
486,
1190,
900,
199,
821,
26,
21441,
19252,
20508,
334,
77,
15,
83,
9,
199,
1479,
26,
21441,
19252,
1066,
29765,
486,
1190,
900,
199,
1465,
26,
21441,
19252,
1066,
29765,
334,
77,
15,
83,
62,
18,
9,
199,
1651
] |
[
13894,
379,
3447,
8834,
820,
13753,
311,
5543,
26382,
5822,
199,
3,
14326,
28007,
1295,
753,
1384,
787,
7814,
3163,
28161,
436,
2066,
12149,
4799,
3404,
13,
1135,
11686,
14,
221,
199,
3,
21344,
3214,
787,
15486,
379,
4799,
32570,
199,
199,
3,
2803,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
8691,
199,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
646,
747,
199,
199,
692,
440,
747,
14,
12959,
480,
20993,
401,
488,
304,
272,
492,
8027,
272,
8027,
14,
1180,
480,
13452,
401,
7987,
29,
797,
9,
199,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
8027,
14,
1278,
465,
333,
1278,
199,
646,
8027,
14,
4400,
465,
6904,
199,
199,
504,
6357,
14,
1238,
63,
5592,
492,
3560,
63,
396,
63,
1294,
199,
504,
6357,
492,
26471,
199,
504,
6357,
14,
24688,
492,
3906,
773,
199,
504,
19184,
88,
7169,
14,
1135,
11686,
492,
13894,
316,
12847,
15155,
199,
504,
6357,
14,
12281,
492,
2248,
63,
28275,
199,
504,
6357,
14,
6676,
63,
1238,
492,
29029,
199,
504,
6357,
14,
6676,
63,
1238,
492,
31196,
199,
504,
6357,
14,
15628,
492,
9571,
21668,
15155,
199,
504,
6357,
14,
16820,
492,
14056,
50,
199,
504,
6357,
14,
6676,
63,
1238,
492,
12489,
13013,
199,
504,
6357,
14,
1238,
63,
5592,
492,
32570,
199,
199,
504,
11708,
14,
992,
492,
3240,
9092,
12,
1402,
63,
504,
63,
1001,
199,
504,
11708,
14,
4359,
492,
20847,
12,
18110,
548,
12,
29441,
199,
504,
11708,
14,
6433,
6315,
492,
18868,
36,
12,
4431,
27707,
12,
437,
983,
3136,
12,
820,
3053,
4469,
12,
4431,
455,
199,
504,
11708,
492,
21289,
199,
504,
11708,
492,
13484,
199,
504,
11708,
14,
1208,
492,
5137,
63,
1238,
199,
199,
646,
5927,
199,
199,
363,
2502,
363,
275,
298,
46,
3258,
72,
382,
603,
3210,
725,
665,
22998,
72,
382,
14,
77,
3210,
725,
32,
317,
1939,
14,
1308,
6244,
16922,
445,
4937,
472,
665,
22333,
14,
331,
3080,
472,
14,
317,
1939,
14,
1308,
4335,
199,
363,
1023,
363,
275,
413,
14,
16,
199,
363,
602,
363,
275,
298,
845,
15,
1479,
15,
10680,
2,
199,
199,
318,
2198,
63,
1531,
604,
837,
272,
408,
32,
1122,
314,
1511,
1627,
641,
314,
1414,
13,
604,
14,
272,
408,
272,
1798,
275,
8691,
14,
14553,
8,
3807,
18971,
1301,
3108,
1023,
18971,
1023,
3368,
339,
1798,
14,
525,
63,
1422,
6096,
70,
401,
4320,
2210,
273,
392,
4364,
1173,
401,
1720,
628,
1513,
374,
2106,
8413,
273,
392,
4364,
570,
4765,
885,
275,
15313,
4219,
15,
77,
331,
3080,
472,
15,
1513,
374,
2106,
15,
14730,
2452,
15,
44,
17,
47,
17,
47,
18,
63,
35,
5747,
63,
39,
3311,
15,
2210,
273,
392,
4364,
14,
2424,
531,
272,
1798,
14,
525,
63,
1422,
6096,
79,
401,
4320,
1199,
6231,
401,
1720,
628,
1199,
4922,
4765,
885,
275,
15313,
4219,
15,
77,
331,
3080,
472,
15,
1513,
374,
2106,
15,
1698,
33,
15,
44,
17,
47,
17,
47,
18,
13589,
272,
1798,
14,
525,
63,
1422,
6096,
82,
401,
4320,
1065,
804,
401,
1720,
628,
1065,
730,
334,
5043,
12,
6465,
19645,
12,
286,
2037,
4186,
849,
29049,
674,
19645,
531,
272,
1798,
14,
525,
63,
1422,
6096,
77,
401,
4320,
827,
22745,
78,
7779,
401,
1720,
628,
12092,
8413,
273,
392,
1728,
22877,
4765,
849,
29,
21,
14,
16,
12,
466,
29,
1609,
9,
272,
1798,
14,
525,
63,
1422,
6096,
46,
401,
4320,
4698,
5132,
401,
1720,
628,
1955,
402,
18463,
401,
849,
275,
709,
12,
730,
29,
442,
9,
272,
1798,
14,
525,
63,
1422,
6739,
1117,
48,
4555,
401,
221,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
9,
272,
1798,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
1993,
1720,
628,
2540,
3376,
590,
14,
334,
2698,
26,
756,
6320,
339,
3999,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
327,
2498,
2633,
272,
340,
3999,
14,
3832,
26,
267,
870,
4331,
984,
14,
3083,
12,
3087,
267,
870,
4331,
984,
14,
3083,
12,
298,
5720,
2784,
63,
4077,
2106,
11500,
267,
870,
4331,
984,
14,
3083,
12,
298,
1023,
26,
450,
83,
6808,
363,
1023,
363,
267,
870,
4331,
984,
14,
3083,
12,
3087,
267,
870,
4331,
984,
14,
3083,
12,
298,
3096,
10,
23710,
1011,
3096,
538,
2,
267,
367,
312,
315,
3999,
855,
807,
4343,
1744,
837,
881,
870,
4331,
984,
14,
3083,
12,
312,
59,
16,
2807,
5122,
881,
870,
4331,
984,
14,
3083,
12,
312,
59,
17,
61,
267,
870,
4331,
984,
14,
3083,
12,
3087,
339,
372,
3999,
199,
199,
2344,
199,
16,
26,
8413,
273,
392,
1728,
486,
1190,
900,
199,
17,
26,
8413,
273,
392,
1728,
8127,
199,
18,
26,
299,
486,
1190,
900,
199,
19,
26,
308,
486,
1190,
900,
199,
20,
26,
519,
334,
18,
16155,
15,
83,
9,
199,
21,
26,
519,
334,
19,
14,
21,
16155,
15,
83,
9,
199,
22,
26,
519,
334,
21,
16155,
15,
83,
9,
199,
23,
26,
14746,
19252,
25134,
334,
77,
15,
83,
9,
199,
24,
26,
5117,
16842,
900,
199,
25,
26,
7008,
16842,
900,
199,
709,
26,
18896,
199,
845,
26,
18154,
199,
713,
26,
6033,
199,
969,
26,
5818,
334,
77,
9,
199,
1079,
26,
24978,
26720,
334,
6458,
9,
199,
1046,
26,
302,
364,
279,
23363,
17,
63,
26845,
199,
975,
26,
302,
364,
279,
23363,
17,
63,
345,
415,
199,
1196,
26,
302,
364,
279,
23363,
17,
63,
21846,
199,
1085,
26,
12427,
3861,
63,
45,
2591,
199,
1167,
26,
12427,
3861,
63,
45,
683,
199,
1165,
26,
12427,
3861,
63,
45,
4599,
199,
2025,
26,
12427,
3861,
63,
45,
6215,
199,
1081,
26,
12427,
3861,
63,
45,
9734,
199,
1789,
26,
12427,
3861,
63,
45,
802,
199,
1194,
26,
21441,
19252,
20508,
486,
1190,
900,
199,
821,
26,
21441,
19252,
20508,
334,
77,
15,
83,
9,
199,
1479,
26,
21441,
19252,
1066,
29765,
486,
1190,
900,
199,
1465,
26,
21441,
19252,
1066,
29765,
334,
77,
15,
83,
62,
18,
9,
199,
1651,
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
1,
1
] |
RubenKelevra/rethinkdb
|
external/v8_3.30.33.16/testing/gtest/test/gtest_xml_outfiles_test.py
|
2526
|
5340
|
#!/usr/bin/env python
#
# Copyright 2008, 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.
"""Unit test for the gtest_xml_output module."""
__author__ = "keith.ray@gmail.com (Keith Ray)"
import os
from xml.dom import minidom, Node
import gtest_test_utils
import gtest_xml_test_utils
GTEST_OUTPUT_SUBDIR = "xml_outfiles"
GTEST_OUTPUT_1_TEST = "gtest_xml_outfile1_test_"
GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_"
EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
<testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne" SetUpProp="1" TestSomeProperty="1" TearDownProp="1" />
</testsuite>
</testsuites>
"""
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
<testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo" SetUpProp="2" TestSomeProperty="2" TearDownProp="2" />
</testsuite>
</testsuites>
"""
class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
"""Unit test for Google Test's XML output functionality."""
def setUp(self):
# We want the trailing '/' that the last "" provides in os.path.join, for
# telling Google Test to create an output directory instead of a single file
# for xml output.
self.output_dir_ = os.path.join(gtest_test_utils.GetTempDir(),
GTEST_OUTPUT_SUBDIR, "")
self.DeleteFilesAndDir()
def tearDown(self):
self.DeleteFilesAndDir()
def DeleteFilesAndDir(self):
try:
os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_1_TEST + ".xml"))
except os.error:
pass
try:
os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_2_TEST + ".xml"))
except os.error:
pass
try:
os.rmdir(self.output_dir_)
except os.error:
pass
def testOutfile1(self):
self._TestOutFile(GTEST_OUTPUT_1_TEST, EXPECTED_XML_1)
def testOutfile2(self):
self._TestOutFile(GTEST_OUTPUT_2_TEST, EXPECTED_XML_2)
def _TestOutFile(self, test_name, expected_xml):
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name)
command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_]
p = gtest_test_utils.Subprocess(command,
working_dir=gtest_test_utils.GetTempDir())
self.assert_(p.exited)
self.assertEquals(0, p.exit_code)
# TODO(wan@google.com): libtool causes the built test binary to be
# named lt-gtest_xml_outfiles_test_ instead of
# gtest_xml_outfiles_test_. To account for this possibillity, we
# allow both names in the following code. We should remove this
# hack when Chandler Carruth's libtool replacement tool is ready.
output_file_name1 = test_name + ".xml"
output_file1 = os.path.join(self.output_dir_, output_file_name1)
output_file_name2 = 'lt-' + output_file_name1
output_file2 = os.path.join(self.output_dir_, output_file_name2)
self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2),
output_file1)
expected = minidom.parseString(expected_xml)
if os.path.isfile(output_file1):
actual = minidom.parse(output_file1)
else:
actual = minidom.parse(output_file2)
self.NormalizeXml(actual.documentElement)
self.AssertEquivalentNodes(expected.documentElement,
actual.documentElement)
expected.unlink()
actual.unlink()
if __name__ == "__main__":
os.environ["GTEST_STACK_TRACE_DEPTH"] = "0"
gtest_test_utils.Main()
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
5072,
511,
367,
314,
9088,
63,
1652,
63,
1199,
859,
1041,
199,
199,
363,
2502,
363,
275,
298,
415,
448,
14,
803,
32,
6799,
14,
957,
334,
1136,
448,
30703,
2924,
199,
199,
646,
747,
199,
504,
2748,
14,
4556,
492,
19165,
12,
5013,
199,
199,
646,
9088,
63,
396,
63,
1208,
199,
646,
9088,
63,
1652,
63,
396,
63,
1208,
421,
199,
16151,
63,
8414,
63,
6348,
3022,
275,
298,
1652,
63,
548,
1725,
2,
199,
16151,
63,
8414,
63,
17,
63,
2864,
275,
298,
8385,
63,
1652,
63,
4984,
17,
63,
396,
12172,
199,
16151,
63,
8414,
63,
18,
63,
2864,
275,
298,
8385,
63,
1652,
63,
4984,
18,
63,
396,
12172,
199,
199,
22358,
63,
4317,
63,
17,
275,
31501,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
199,
28,
2219,
11650,
2295,
628,
17,
2,
9081,
628,
16,
2,
6980,
628,
16,
2,
2552,
628,
16,
2,
900,
21437,
4913,
21437,
536,
628,
2422,
2925,
1743,
523,
665,
14239,
536,
628,
3697,
4395,
2,
2295,
628,
17,
2,
9081,
628,
16,
2,
6980,
628,
16,
2,
2552,
628,
16,
2,
900,
32103,
1743,
272,
665,
10847,
536,
628,
774,
7700,
8516,
2,
2004,
628,
1065,
2,
900,
21437,
15876,
628,
3697,
4395,
2,
2494,
1721,
9955,
628,
17,
2,
1379,
7700,
3697,
628,
17,
2,
377,
25236,
9955,
628,
17,
2,
7082,
523,
3068,
14239,
30,
199,
1108,
2219,
11650,
30,
199,
624,
199,
199,
22358,
63,
4317,
63,
18,
275,
31501,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
199,
28,
2219,
11650,
2295,
628,
17,
2,
9081,
628,
16,
2,
6980,
628,
16,
2,
2552,
628,
16,
2,
900,
21437,
4913,
21437,
536,
628,
2422,
2925,
1743,
523,
665,
14239,
536,
628,
3697,
11467,
2,
2295,
628,
17,
2,
9081,
628,
16,
2,
6980,
628,
16,
2,
2552,
628,
16,
2,
900,
32103,
1743,
272,
665,
10847,
536,
628,
774,
7700,
8516,
2,
2004,
628,
1065,
2,
900,
21437,
15876,
628,
3697,
11467,
2,
2494,
1721,
9955,
628,
18,
2,
1379,
7700,
3697,
628,
18,
2,
377,
25236,
9955,
628,
18,
2,
7082,
523,
3068,
14239,
30,
199,
1108,
2219,
11650,
30,
199,
624,
421,
199,
533,
598,
774,
13901,
1484,
337,
5535,
774,
8,
8385,
63,
1652,
63,
396,
63,
1208,
14,
39,
774,
4317,
1746,
304,
523,
408,
5072,
511,
367,
4475,
1379,
1159,
4692,
1072,
9330,
1041,
819,
347,
3613,
8,
277,
304,
272,
327,
2136,
2934,
314,
8520,
7324,
626,
314,
2061,
3087,
6571,
315,
747,
14,
515,
14,
904,
12,
367,
272,
327,
1565,
10564,
4475,
1379,
370,
1218,
376,
1072,
2082,
3140,
402,
282,
2849,
570,
272,
327,
367,
2748,
1072,
14,
272,
291,
14,
1199,
63,
694,
63,
275,
747,
14,
515,
14,
904,
8,
8385,
63,
396,
63,
1208,
14,
1002,
29008,
1062,
2511,
18652,
63,
8414,
63,
6348,
3022,
12,
6899,
272,
291,
14,
5392,
5535,
3325,
3567,
342,
819,
347,
6766,
8,
277,
304,
272,
291,
14,
5392,
5535,
3325,
3567,
342,
819,
347,
8496,
5535,
3325,
3567,
8,
277,
304,
272,
862,
26,
489,
747,
14,
2168,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1199,
63,
694,
3131,
18652,
63,
8414,
63,
17,
63,
2864,
435,
3680,
1652,
2237,
272,
871,
747,
14,
705,
26,
489,
986,
272,
862,
26,
489,
747,
14,
2168,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1199,
63,
694,
3131,
18652,
63,
8414,
63,
18,
63,
2864,
435,
3680,
1652,
2237,
272,
871,
747,
14,
705,
26,
489,
986,
272,
862,
26,
489,
747,
14,
19405,
8,
277,
14,
1199,
63,
694,
4602,
272,
871,
747,
14,
705,
26,
489,
986,
819,
347,
511,
2204,
493,
17,
8,
277,
304,
272,
291,
423,
774,
2204,
1173,
8,
16151,
63,
8414,
63,
17,
63,
2864,
12,
20464,
1149,
63,
4317,
63,
17,
9,
819,
347,
511,
2204,
493,
18,
8,
277,
304,
272,
291,
423,
774,
2204,
1173,
8,
16151,
63,
8414,
63,
18,
63,
2864,
12,
20464,
1149,
63,
4317,
63,
18,
9,
819,
347,
485,
774,
2204,
1173,
8,
277,
12,
511,
63,
354
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
5072,
511,
367,
314,
9088,
63,
1652,
63,
1199,
859,
1041,
199,
199,
363,
2502,
363,
275,
298,
415,
448,
14,
803,
32,
6799,
14,
957,
334,
1136,
448,
30703,
2924,
199,
199,
646,
747,
199,
504,
2748,
14,
4556,
492,
19165,
12,
5013,
199,
199,
646,
9088,
63,
396,
63,
1208,
199,
646,
9088,
63,
1652,
63,
396,
63,
1208,
421,
199,
16151,
63,
8414,
63,
6348,
3022,
275,
298,
1652,
63,
548,
1725,
2,
199,
16151,
63,
8414,
63,
17,
63,
2864,
275,
298,
8385,
63,
1652,
63,
4984,
17,
63,
396,
12172,
199,
16151,
63,
8414,
63,
18,
63,
2864,
275,
298,
8385,
63,
1652,
63,
4984,
18,
63,
396,
12172,
199,
199,
22358,
63,
4317,
63,
17,
275,
31501,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
199,
28,
2219,
11650,
2295,
628,
17,
2,
9081,
628,
16,
2,
6980,
628,
16,
2,
2552,
628,
16,
2,
900,
21437,
4913,
21437,
536,
628,
2422,
2925,
1743,
523,
665,
14239,
536,
628,
3697,
4395,
2,
2295,
628,
17,
2,
9081,
628,
16,
2,
6980,
628,
16,
2,
2552,
628,
16,
2,
900,
32103,
1743,
272,
665,
10847,
536,
628,
774,
7700,
8516,
2,
2004,
628,
1065,
2,
900,
21437,
15876,
628,
3697,
4395,
2,
2494,
1721,
9955,
628,
17,
2,
1379,
7700,
3697,
628,
17,
2,
377,
25236,
9955,
628,
17,
2,
7082,
523,
3068,
14239,
30,
199,
1108,
2219,
11650,
30,
199,
624,
199,
199,
22358,
63,
4317,
63,
18,
275,
31501,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
199,
28,
2219,
11650,
2295,
628,
17,
2,
9081,
628,
16,
2,
6980,
628,
16,
2,
2552,
628,
16,
2,
900,
21437,
4913,
21437,
536,
628,
2422,
2925,
1743,
523,
665,
14239,
536,
628,
3697,
11467,
2,
2295,
628,
17,
2,
9081,
628,
16,
2,
6980,
628,
16,
2,
2552,
628,
16,
2,
900,
32103,
1743,
272,
665,
10847,
536,
628,
774,
7700,
8516,
2,
2004,
628,
1065,
2,
900,
21437,
15876,
628,
3697,
11467,
2,
2494,
1721,
9955,
628,
18,
2,
1379,
7700,
3697,
628,
18,
2,
377,
25236,
9955,
628,
18,
2,
7082,
523,
3068,
14239,
30,
199,
1108,
2219,
11650,
30,
199,
624,
421,
199,
533,
598,
774,
13901,
1484,
337,
5535,
774,
8,
8385,
63,
1652,
63,
396,
63,
1208,
14,
39,
774,
4317,
1746,
304,
523,
408,
5072,
511,
367,
4475,
1379,
1159,
4692,
1072,
9330,
1041,
819,
347,
3613,
8,
277,
304,
272,
327,
2136,
2934,
314,
8520,
7324,
626,
314,
2061,
3087,
6571,
315,
747,
14,
515,
14,
904,
12,
367,
272,
327,
1565,
10564,
4475,
1379,
370,
1218,
376,
1072,
2082,
3140,
402,
282,
2849,
570,
272,
327,
367,
2748,
1072,
14,
272,
291,
14,
1199,
63,
694,
63,
275,
747,
14,
515,
14,
904,
8,
8385,
63,
396,
63,
1208,
14,
1002,
29008,
1062,
2511,
18652,
63,
8414,
63,
6348,
3022,
12,
6899,
272,
291,
14,
5392,
5535,
3325,
3567,
342,
819,
347,
6766,
8,
277,
304,
272,
291,
14,
5392,
5535,
3325,
3567,
342,
819,
347,
8496,
5535,
3325,
3567,
8,
277,
304,
272,
862,
26,
489,
747,
14,
2168,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1199,
63,
694,
3131,
18652,
63,
8414,
63,
17,
63,
2864,
435,
3680,
1652,
2237,
272,
871,
747,
14,
705,
26,
489,
986,
272,
862,
26,
489,
747,
14,
2168,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1199,
63,
694,
3131,
18652,
63,
8414,
63,
18,
63,
2864,
435,
3680,
1652,
2237,
272,
871,
747,
14,
705,
26,
489,
986,
272,
862,
26,
489,
747,
14,
19405,
8,
277,
14,
1199,
63,
694,
4602,
272,
871,
747,
14,
705,
26,
489,
986,
819,
347,
511,
2204,
493,
17,
8,
277,
304,
272,
291,
423,
774,
2204,
1173,
8,
16151,
63,
8414,
63,
17,
63,
2864,
12,
20464,
1149,
63,
4317,
63,
17,
9,
819,
347,
511,
2204,
493,
18,
8,
277,
304,
272,
291,
423,
774,
2204,
1173,
8,
16151,
63,
8414,
63,
18,
63,
2864,
12,
20464,
1149,
63,
4317,
63,
18,
9,
819,
347,
485,
774,
2204,
1173,
8,
277,
12,
511,
63,
354,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bmanojlovic/ansible
|
lib/ansible/modules/cloud/amazon/rds_subnet_group.py
|
25
|
5369
|
#!/usr/bin/python
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'status': ['stableinterface'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = '''
---
module: rds_subnet_group
version_added: "1.5"
short_description: manage RDS database subnet groups
description:
- Creates, modifies, and deletes RDS database subnet groups. This module has a dependency on python-boto >= 2.5.
options:
state:
description:
- Specifies whether the subnet should be present or absent.
required: true
default: present
aliases: []
choices: [ 'present' , 'absent' ]
name:
description:
- Database subnet group identifier.
required: true
default: null
aliases: []
description:
description:
- Database subnet group description. Only set when a new group is added.
required: false
default: null
aliases: []
subnets:
description:
- List of subnet IDs that make up the database subnet group.
required: false
default: null
aliases: []
author: "Scott Anderson (@tastychutney)"
extends_documentation_fragment:
- aws
- ec2
'''
EXAMPLES = '''
# Add or change a subnet group
- rds_subnet_group:
state: present
name: norwegian-blue
description: My Fancy Ex Parrot Subnet Group
subnets:
- subnet-aaaaaaaa
- subnet-bbbbbbbb
# Remove a subnet group
- rds_subnet_group:
state: absent
name: norwegian-blue
'''
try:
import boto.rds
from boto.exception import BotoServerError
HAS_BOTO = True
except ImportError:
HAS_BOTO = False
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(dict(
state = dict(required=True, choices=['present', 'absent']),
name = dict(required=True),
description = dict(required=False),
subnets = dict(required=False, type='list'),
)
)
module = AnsibleModule(argument_spec=argument_spec)
if not HAS_BOTO:
module.fail_json(msg='boto required for this module')
state = module.params.get('state')
group_name = module.params.get('name').lower()
group_description = module.params.get('description')
group_subnets = module.params.get('subnets') or {}
if state == 'present':
for required in ['name', 'description', 'subnets']:
if not module.params.get(required):
module.fail_json(msg = str("Parameter %s required for state='present'" % required))
else:
for not_allowed in ['description', 'subnets']:
if module.params.get(not_allowed):
module.fail_json(msg = str("Parameter %s not allowed for state='absent'" % not_allowed))
# Retrieve any AWS settings from the environment.
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
if not region:
module.fail_json(msg = str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set."))
try:
conn = connect_to_aws(boto.rds, region, **aws_connect_kwargs)
except boto.exception.BotoServerError as e:
module.fail_json(msg = e.error_message)
try:
changed = False
exists = False
try:
matching_groups = conn.get_all_db_subnet_groups(group_name, max_records=100)
exists = len(matching_groups) > 0
except BotoServerError as e:
if e.error_code != 'DBSubnetGroupNotFoundFault':
module.fail_json(msg = e.error_message)
if state == 'absent':
if exists:
conn.delete_db_subnet_group(group_name)
changed = True
else:
if not exists:
new_group = conn.create_db_subnet_group(group_name, desc=group_description, subnet_ids=group_subnets)
changed = True
else:
# Sort the subnet groups before we compare them
matching_groups[0].subnet_ids.sort()
group_subnets.sort()
if ( (matching_groups[0].name != group_name) or (matching_groups[0].description != group_description) or (matching_groups[0].subnet_ids != group_subnets) ):
changed_group = conn.modify_db_subnet_group(group_name, description=group_description, subnet_ids=group_subnets)
changed = True
except BotoServerError as e:
module.fail_json(msg = e.error_message)
module.exit_json(changed=changed)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
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,
11989,
3266,
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,
519,
795,
63,
5327,
63,
923,
199,
1023,
63,
3270,
26,
298,
17,
14,
21,
2,
199,
3612,
63,
1802,
26,
9635,
820,
3177,
3050,
6303,
4652,
199,
1802,
26,
1362,
446,
10560,
12,
26473,
12,
436,
21812,
820,
3177,
3050,
6303,
4652,
14,
961,
859,
965,
282,
5936,
641,
2366,
13,
10914,
2356,
499,
14,
21,
14,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
11015,
3775,
314,
6303,
1077,
506,
3451,
503,
9552,
14,
272,
1415,
26,
2549,
272,
849,
26,
3451,
272,
5481,
26,
942,
272,
3415,
26,
359,
283,
1881,
7,
2360,
283,
5575,
7,
1622,
523,
536,
26,
272,
1369,
26,
489,
446,
8692,
6303,
1572,
5148,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
5481,
26,
942,
523,
1369,
26,
272,
1369,
26,
489,
446,
8692,
6303,
1572,
1369,
14,
5972,
663,
1380,
282,
892,
1572,
365,
3483,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
942,
523,
18709,
26,
272,
1369,
26,
489,
446,
3820,
402,
6303,
11449,
626,
1852,
1536,
314,
3050,
6303,
1572,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
942,
199,
2502,
26,
298,
51,
331,
6215,
1626,
424,
834,
8593,
502,
28352,
335,
337,
23263,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
11488,
272,
446,
7062,
18,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2654,
503,
1570,
282,
6303,
1572,
199,
13,
519,
795,
63,
5327,
63,
923,
26,
272,
1174,
26,
3451,
272,
536,
26,
6590,
1129,
71,
5653,
13,
6304,
272,
1369,
26,
4932,
481,
9844,
1316,
2235,
4571,
4804,
846,
5611,
272,
18709,
26,
489,
446,
6303,
13,
10980,
489,
446,
6303,
13,
31703,
199,
199,
3,
5852,
282,
6303,
1572,
199,
13,
519,
795,
63,
5327,
63,
923,
26,
272,
1174,
26,
9552,
272,
536,
26,
6590,
1129,
71,
5653,
13,
6304,
199,
2344,
199,
199,
893,
26,
272,
492,
6055,
14,
23098,
272,
687,
6055,
14,
1971,
492,
24411,
17692,
272,
7509,
63,
21373,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
21373,
275,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
7062,
18,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
807,
8,
267,
1174,
3777,
275,
1211,
8,
2427,
29,
549,
12,
221,
3415,
2968,
1881,
297,
283,
5575,
3815,
267,
536,
4519,
275,
1211,
8,
2427,
29,
549,
395,
267,
1369,
755,
275,
1211,
8,
2427,
29,
797,
395,
267,
18709,
3698,
275,
1211,
8,
2427,
29,
797,
12,
730,
534,
513,
659,
272,
776,
272,
776,
272,
859,
275,
6953,
8,
2094,
63,
1650,
29,
2094,
63,
1650,
9,
339,
340,
440,
7509,
63,
21373,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
10914,
1415,
367,
642,
859,
358,
339,
1174,
7861,
275,
859,
14,
1162,
14,
362,
360,
929,
358,
272,
1572,
63,
354,
4519,
275,
859,
14,
1162,
14,
362,
360,
354,
1959,
2325,
342,
272,
1572,
63,
1802,
755,
275,
859,
14,
1162,
14,
362,
360,
1802,
358,
272,
1572,
63,
14967,
3698,
275,
859,
14,
1162,
14,
362,
360,
14967,
358,
503,
1052,
339,
340,
1174,
508,
283,
1881,
356,
267,
367,
1415,
315,
788,
354,
297,
283,
1802,
297,
283,
14967,
2565,
288,
340,
440,
859,
14,
1162,
14,
362,
8,
2427,
304,
355,
859,
14,
1633,
63,
1001,
8,
1328,
275,
620,
480,
4720,
450,
83,
1415,
367,
1174,
534,
1881,
4065,
450,
1415,
430,
272,
587,
26,
267,
367,
440,
63,
6541,
315,
788,
1802,
297,
283,
14967,
2565,
288,
340,
859,
14,
1162,
14,
362,
8,
1397,
63,
6541,
304,
355,
859,
14,
1633,
63,
1001,
8,
1328,
275,
620,
480,
4720,
450,
83,
440,
4370,
367,
1174,
534,
5575,
4065,
450,
440,
63,
6541,
430,
339,
327,
13939,
1263,
10168,
2202,
687,
314,
3734,
14,
272,
4897,
12,
7062,
18,
63,
633,
12,
11488,
63,
2242,
63,
958,
275,
664,
63,
7231,
63,
2105,
63,
815,
8,
578,
9,
339,
340,
440,
4897,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
620,
480,
37,
1711,
4897,
503,
10168,
63,
23030,
503,
15352,
18,
63,
23030,
3734,
1750,
503,
6055,
1101,
11488,
63,
4551,
503,
7062,
18,
63,
4551,
1471,
506,
663,
13853,
339,
862,
26,
267,
2557,
275,
4907,
63,
475,
63,
7231,
8,
10914,
14,
23098,
12,
4897,
12,
1011,
7231,
63,
2242,
63,
958,
9,
272,
871,
6055,
14,
1971,
14,
20380,
17692,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
325,
14,
705,
63,
1188,
9,
339,
862,
26,
267,
2896,
275,
756,
267,
3495,
275,
756,
398,
862,
26,
288,
4877,
63,
2634,
275,
2557,
14,
362,
63,
452,
63,
697,
63,
5327,
63,
2634,
8,
923,
63,
354,
12,
1390,
63,
6502,
29,
1960,
9,
288,
3495,
275,
822,
8,
9467,
63,
2634,
9,
690,
378,
267,
871,
24411,
17692,
465,
325
] |
[
2647,
15,
1393,
15,
1548,
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,
11989,
3266,
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,
519,
795,
63,
5327,
63,
923,
199,
1023,
63,
3270,
26,
298,
17,
14,
21,
2,
199,
3612,
63,
1802,
26,
9635,
820,
3177,
3050,
6303,
4652,
199,
1802,
26,
1362,
446,
10560,
12,
26473,
12,
436,
21812,
820,
3177,
3050,
6303,
4652,
14,
961,
859,
965,
282,
5936,
641,
2366,
13,
10914,
2356,
499,
14,
21,
14,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
11015,
3775,
314,
6303,
1077,
506,
3451,
503,
9552,
14,
272,
1415,
26,
2549,
272,
849,
26,
3451,
272,
5481,
26,
942,
272,
3415,
26,
359,
283,
1881,
7,
2360,
283,
5575,
7,
1622,
523,
536,
26,
272,
1369,
26,
489,
446,
8692,
6303,
1572,
5148,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
272,
5481,
26,
942,
523,
1369,
26,
272,
1369,
26,
489,
446,
8692,
6303,
1572,
1369,
14,
5972,
663,
1380,
282,
892,
1572,
365,
3483,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
942,
523,
18709,
26,
272,
1369,
26,
489,
446,
3820,
402,
6303,
11449,
626,
1852,
1536,
314,
3050,
6303,
1572,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
942,
199,
2502,
26,
298,
51,
331,
6215,
1626,
424,
834,
8593,
502,
28352,
335,
337,
23263,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
11488,
272,
446,
7062,
18,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2654,
503,
1570,
282,
6303,
1572,
199,
13,
519,
795,
63,
5327,
63,
923,
26,
272,
1174,
26,
3451,
272,
536,
26,
6590,
1129,
71,
5653,
13,
6304,
272,
1369,
26,
4932,
481,
9844,
1316,
2235,
4571,
4804,
846,
5611,
272,
18709,
26,
489,
446,
6303,
13,
10980,
489,
446,
6303,
13,
31703,
199,
199,
3,
5852,
282,
6303,
1572,
199,
13,
519,
795,
63,
5327,
63,
923,
26,
272,
1174,
26,
9552,
272,
536,
26,
6590,
1129,
71,
5653,
13,
6304,
199,
2344,
199,
199,
893,
26,
272,
492,
6055,
14,
23098,
272,
687,
6055,
14,
1971,
492,
24411,
17692,
272,
7509,
63,
21373,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
21373,
275,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
7062,
18,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
807,
8,
267,
1174,
3777,
275,
1211,
8,
2427,
29,
549,
12,
221,
3415,
2968,
1881,
297,
283,
5575,
3815,
267,
536,
4519,
275,
1211,
8,
2427,
29,
549,
395,
267,
1369,
755,
275,
1211,
8,
2427,
29,
797,
395,
267,
18709,
3698,
275,
1211,
8,
2427,
29,
797,
12,
730,
534,
513,
659,
272,
776,
272,
776,
272,
859,
275,
6953,
8,
2094,
63,
1650,
29,
2094,
63,
1650,
9,
339,
340,
440,
7509,
63,
21373,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
10914,
1415,
367,
642,
859,
358,
339,
1174,
7861,
275,
859,
14,
1162,
14,
362,
360,
929,
358,
272,
1572,
63,
354,
4519,
275,
859,
14,
1162,
14,
362,
360,
354,
1959,
2325,
342,
272,
1572,
63,
1802,
755,
275,
859,
14,
1162,
14,
362,
360,
1802,
358,
272,
1572,
63,
14967,
3698,
275,
859,
14,
1162,
14,
362,
360,
14967,
358,
503,
1052,
339,
340,
1174,
508,
283,
1881,
356,
267,
367,
1415,
315,
788,
354,
297,
283,
1802,
297,
283,
14967,
2565,
288,
340,
440,
859,
14,
1162,
14,
362,
8,
2427,
304,
355,
859,
14,
1633,
63,
1001,
8,
1328,
275,
620,
480,
4720,
450,
83,
1415,
367,
1174,
534,
1881,
4065,
450,
1415,
430,
272,
587,
26,
267,
367,
440,
63,
6541,
315,
788,
1802,
297,
283,
14967,
2565,
288,
340,
859,
14,
1162,
14,
362,
8,
1397,
63,
6541,
304,
355,
859,
14,
1633,
63,
1001,
8,
1328,
275,
620,
480,
4720,
450,
83,
440,
4370,
367,
1174,
534,
5575,
4065,
450,
440,
63,
6541,
430,
339,
327,
13939,
1263,
10168,
2202,
687,
314,
3734,
14,
272,
4897,
12,
7062,
18,
63,
633,
12,
11488,
63,
2242,
63,
958,
275,
664,
63,
7231,
63,
2105,
63,
815,
8,
578,
9,
339,
340,
440,
4897,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
620,
480,
37,
1711,
4897,
503,
10168,
63,
23030,
503,
15352,
18,
63,
23030,
3734,
1750,
503,
6055,
1101,
11488,
63,
4551,
503,
7062,
18,
63,
4551,
1471,
506,
663,
13853,
339,
862,
26,
267,
2557,
275,
4907,
63,
475,
63,
7231,
8,
10914,
14,
23098,
12,
4897,
12,
1011,
7231,
63,
2242,
63,
958,
9,
272,
871,
6055,
14,
1971,
14,
20380,
17692,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
325,
14,
705,
63,
1188,
9,
339,
862,
26,
267,
2896,
275,
756,
267,
3495,
275,
756,
398,
862,
26,
288,
4877,
63,
2634,
275,
2557,
14,
362,
63,
452,
63,
697,
63,
5327,
63,
2634,
8,
923,
63,
354,
12,
1390,
63,
6502,
29,
1960,
9,
288,
3495,
275,
822,
8,
9467,
63,
2634,
9,
690,
378,
267,
871,
24411,
17692,
465,
325,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
raviflipsyde/servo
|
tests/wpt/web-platform-tests/old-tests/webdriver/command_contexts/open_and_close_window_test.py
|
141
|
2529
|
import os
import sys
import random
import unittest
sys.path.insert(1, os.path.abspath(os.path.join(__file__, "../..")))
import base_test
repo_root = os.path.abspath(os.path.join(__file__, "../../.."))
sys.path.insert(1, os.path.join(repo_root, "tools", "webdriver"))
from webdriver import exceptions
class OpenAndCloseWindowTest(base_test.WebDriverBaseTest):
def setUp(self):
self.driver.get(self.webserver.where_is("command_contexts/res/first-page.html"))
def tearDown(self):
handles = self.driver.get_window_handles()
for i in range(len(handles) - 1):
self.driver.switch_to_window(handles[i])
self.driver.close()
self.driver.switch_to_window(self.driver.get_window_handles()[0])
def test_open_new_window(self):
handles = self.driver.get_window_handles()
self.driver.find_element_by_id("open_new_window").click()
self.assertEquals(len(handles) + 1, len(self.driver.get_window_handles()))
def test_get_window_handles_returns_the_windows_that_have_been_opened(self):
self.driver.find_element_by_id("open_new_window").click()
handles = self.driver.get_window_handles()
self.driver.switch_to_window(handles[0])
url1 = self.driver.get_current_url()
self.driver.switch_to_window(handles[1])
url2 = self.driver.get_current_url()
if url1 == self.webserver.where_is("controlling_windows/res/other-page.html"):
self.assertEquals(url2, self.webserver.where_is("controlling_windows/res/first-page.html"))
elif url1 == self.webserver.where_is("controlling_windows/res/first-page.html"):
self.assertEquals(url2, self.webserver.where_is("controlling_windows/res/other-page.html"))
else:
self.fail("The wrong set of URLs were returned")
def test_close_window(self):
open_windows = len(self.driver.get_window_handles())
self.driver.find_element_by_id("open_new_window").click()
self.assertEquals(1 + open_windows, len(self.driver.get_window_handles()))
self.driver.close()
self.assertEquals(open_windows, len(self.driver.get_window_handles()))
def test_command_sent_to_closed_window_returns_no_such_window_exception(self):
self.driver.find_element_by_id("open_new_window").click()
self.driver.close()
with self.assertRaises(exceptions.NoSuchWindowException):
self.driver.get_window_handle()
if __name__ == "__main__":
unittest.main()
|
mpl-2.0
|
[
172,
120,
124,
646,
747,
199,
646,
984,
199,
646,
2196,
199,
646,
2882,
199,
199,
1274,
14,
515,
14,
3176,
8,
17,
12,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
3460,
493,
3108,
29024,
703,
13324,
199,
646,
1300,
63,
396,
199,
199,
3417,
63,
1231,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
3460,
493,
3108,
298,
9707,
703,
2237,
199,
1274,
14,
515,
14,
3176,
8,
17,
12,
747,
14,
515,
14,
904,
8,
3417,
63,
1231,
12,
298,
2537,
401,
298,
17946,
2237,
199,
504,
28094,
492,
4967,
421,
199,
533,
3232,
3325,
4724,
4301,
774,
8,
1095,
63,
396,
14,
27009,
23170,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
1531,
63,
19010,
15,
470,
15,
2246,
13,
1606,
14,
1360,
2237,
339,
347,
6766,
8,
277,
304,
267,
10022,
275,
291,
14,
3090,
14,
362,
63,
3806,
63,
16947,
342,
398,
367,
284,
315,
1425,
8,
552,
8,
16947,
9,
446,
413,
304,
288,
291,
14,
3090,
14,
5656,
63,
475,
63,
3806,
8,
16947,
59,
73,
566,
288,
291,
14,
3090,
14,
1600,
342,
398,
291,
14,
3090,
14,
5656,
63,
475,
63,
3806,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
3430,
16,
566,
339,
347,
511,
63,
1490,
63,
1222,
63,
3806,
8,
277,
304,
267,
10022,
275,
291,
14,
3090,
14,
362,
63,
3806,
63,
16947,
342,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1490,
63,
1222,
63,
3806,
3471,
4891,
342,
267,
291,
14,
2947,
8,
552,
8,
16947,
9,
435,
413,
12,
822,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
4059,
339,
347,
511,
63,
362,
63,
3806,
63,
16947,
63,
5808,
63,
1589,
63,
8258,
63,
9099,
63,
7804,
63,
1235,
287,
63,
19234,
8,
277,
304,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1490,
63,
1222,
63,
3806,
3471,
4891,
342,
267,
10022,
275,
291,
14,
3090,
14,
362,
63,
3806,
63,
16947,
342,
267,
291,
14,
3090,
14,
5656,
63,
475,
63,
3806,
8,
16947,
59,
16,
566,
267,
1166,
17,
275,
291,
14,
3090,
14,
362,
63,
1818,
63,
633,
342,
267,
291,
14,
3090,
14,
5656,
63,
475,
63,
3806,
8,
16947,
59,
17,
566,
267,
1166,
18,
275,
291,
14,
3090,
14,
362,
63,
1818,
63,
633,
342,
398,
340,
1166,
17,
508,
291,
14,
29819,
14,
4509,
63,
374,
480,
31215,
10564,
63,
8258,
15,
470,
15,
1848,
13,
1606,
14,
1360,
2349,
288,
291,
14,
2947,
8,
633,
18,
12,
291,
14,
29819,
14,
4509,
63,
374,
480,
31215,
10564,
63,
8258,
15,
470,
15,
2246,
13,
1606,
14,
1360,
2237,
267,
916,
1166,
17,
508,
291,
14,
29819,
14,
4509,
63,
374,
480,
31215,
10564,
63,
8258,
15,
470,
15,
2246,
13,
1606,
14,
1360,
2349,
288,
291,
14,
2947,
8,
633,
18,
12,
291,
14,
29819,
14,
4509,
63,
374,
480,
31215,
10564,
63,
8258,
15,
470,
15,
1848,
13,
1606,
14,
1360,
2237,
267,
587,
26,
288,
291,
14,
1633,
480,
1918,
6835,
663,
402,
10867,
4898,
2138,
531,
339,
347,
511,
63,
1600,
63,
3806,
8,
277,
304,
267,
1551,
63,
8258,
275,
822,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
1012,
398,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1490,
63,
1222,
63,
3806,
3471,
4891,
342,
267,
291,
14,
2947,
8,
17,
435,
1551,
63,
8258,
12,
822,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
4059,
398,
291,
14,
3090,
14,
1600,
342,
267,
291,
14,
2947,
8,
1490,
63,
8258,
12,
822,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
4059,
339,
347,
511,
63,
1531,
63,
1150,
63,
475,
63,
5938,
63,
3806,
63,
5808,
63,
889,
63,
10180,
63,
3806,
63,
1971,
8,
277,
304,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1490,
63,
1222,
63,
3806,
3471,
4891,
342,
267,
291,
14,
3090,
14,
1600,
342,
398,
543,
291,
14,
1855,
8,
3924,
14,
30049,
4301,
1726,
304,
288,
291,
14,
3090,
14,
362,
63,
3806,
63,
2479,
342,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
120,
124,
646,
747,
199,
646,
984,
199,
646,
2196,
199,
646,
2882,
199,
199,
1274,
14,
515,
14,
3176,
8,
17,
12,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
3460,
493,
3108,
29024,
703,
13324,
199,
646,
1300,
63,
396,
199,
199,
3417,
63,
1231,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
3460,
493,
3108,
298,
9707,
703,
2237,
199,
1274,
14,
515,
14,
3176,
8,
17,
12,
747,
14,
515,
14,
904,
8,
3417,
63,
1231,
12,
298,
2537,
401,
298,
17946,
2237,
199,
504,
28094,
492,
4967,
421,
199,
533,
3232,
3325,
4724,
4301,
774,
8,
1095,
63,
396,
14,
27009,
23170,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
3090,
14,
362,
8,
277,
14,
29819,
14,
4509,
63,
374,
480,
1531,
63,
19010,
15,
470,
15,
2246,
13,
1606,
14,
1360,
2237,
339,
347,
6766,
8,
277,
304,
267,
10022,
275,
291,
14,
3090,
14,
362,
63,
3806,
63,
16947,
342,
398,
367,
284,
315,
1425,
8,
552,
8,
16947,
9,
446,
413,
304,
288,
291,
14,
3090,
14,
5656,
63,
475,
63,
3806,
8,
16947,
59,
73,
566,
288,
291,
14,
3090,
14,
1600,
342,
398,
291,
14,
3090,
14,
5656,
63,
475,
63,
3806,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
3430,
16,
566,
339,
347,
511,
63,
1490,
63,
1222,
63,
3806,
8,
277,
304,
267,
10022,
275,
291,
14,
3090,
14,
362,
63,
3806,
63,
16947,
342,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1490,
63,
1222,
63,
3806,
3471,
4891,
342,
267,
291,
14,
2947,
8,
552,
8,
16947,
9,
435,
413,
12,
822,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
4059,
339,
347,
511,
63,
362,
63,
3806,
63,
16947,
63,
5808,
63,
1589,
63,
8258,
63,
9099,
63,
7804,
63,
1235,
287,
63,
19234,
8,
277,
304,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1490,
63,
1222,
63,
3806,
3471,
4891,
342,
267,
10022,
275,
291,
14,
3090,
14,
362,
63,
3806,
63,
16947,
342,
267,
291,
14,
3090,
14,
5656,
63,
475,
63,
3806,
8,
16947,
59,
16,
566,
267,
1166,
17,
275,
291,
14,
3090,
14,
362,
63,
1818,
63,
633,
342,
267,
291,
14,
3090,
14,
5656,
63,
475,
63,
3806,
8,
16947,
59,
17,
566,
267,
1166,
18,
275,
291,
14,
3090,
14,
362,
63,
1818,
63,
633,
342,
398,
340,
1166,
17,
508,
291,
14,
29819,
14,
4509,
63,
374,
480,
31215,
10564,
63,
8258,
15,
470,
15,
1848,
13,
1606,
14,
1360,
2349,
288,
291,
14,
2947,
8,
633,
18,
12,
291,
14,
29819,
14,
4509,
63,
374,
480,
31215,
10564,
63,
8258,
15,
470,
15,
2246,
13,
1606,
14,
1360,
2237,
267,
916,
1166,
17,
508,
291,
14,
29819,
14,
4509,
63,
374,
480,
31215,
10564,
63,
8258,
15,
470,
15,
2246,
13,
1606,
14,
1360,
2349,
288,
291,
14,
2947,
8,
633,
18,
12,
291,
14,
29819,
14,
4509,
63,
374,
480,
31215,
10564,
63,
8258,
15,
470,
15,
1848,
13,
1606,
14,
1360,
2237,
267,
587,
26,
288,
291,
14,
1633,
480,
1918,
6835,
663,
402,
10867,
4898,
2138,
531,
339,
347,
511,
63,
1600,
63,
3806,
8,
277,
304,
267,
1551,
63,
8258,
275,
822,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
1012,
398,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1490,
63,
1222,
63,
3806,
3471,
4891,
342,
267,
291,
14,
2947,
8,
17,
435,
1551,
63,
8258,
12,
822,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
4059,
398,
291,
14,
3090,
14,
1600,
342,
267,
291,
14,
2947,
8,
1490,
63,
8258,
12,
822,
8,
277,
14,
3090,
14,
362,
63,
3806,
63,
16947,
4059,
339,
347,
511,
63,
1531,
63,
1150,
63,
475,
63,
5938,
63,
3806,
63,
5808,
63,
889,
63,
10180,
63,
3806,
63,
1971,
8,
277,
304,
267,
291,
14,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
1490,
63,
1222,
63,
3806,
3471,
4891,
342,
267,
291,
14,
3090,
14,
1600,
342,
398,
543,
291,
14,
1855,
8,
3924,
14,
30049,
4301,
1726,
304,
288,
291,
14,
3090,
14,
362,
63,
3806,
63,
2479,
342,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ryfx/modrana
|
core/backports/collections.py
|
2
|
6302
|
## {{{ http://code.activestate.com/recipes/500261/ (r15)
from operator import itemgetter as _itemgetter
from keyword import iskeyword as _iskeyword
import sys as _sys
from core.backports.six import string_types as basestring
def namedtuple(typename, field_names, verbose=False, rename=False):
"""Returns a new subclass of tuple with named fields.
>>> Point = namedtuple('Point', 'x y')
>>> Point.__doc__ # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22) # instantiate with positional args or keywords
>>> p[0] + p[1] # indexable like a plain tuple
33
>>> x, y = p # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y # fields also accessable by name
33
>>> d = p._asdict() # convert to a dictionary
>>> d['x']
11
>>> Point(**d) # convert from a dictionary
Point(x=11, y=22)
>>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
"""
# Parse and validate the field names. Validation serves two purposes,
# generating informative error messages and preventing template injection attacks.
if isinstance(field_names, basestring):
field_names = field_names.replace(',', ' ').split() # names separated by whitespace and/or commas
field_names = tuple(map(str, field_names))
if rename:
names = list(field_names)
seen = set()
for i, name in enumerate(names):
if (not min(c.isalnum() or c=='_' for c in name) or _iskeyword(name)
or not name or name[0].isdigit() or name.startswith('_')
or name in seen):
names[i] = '_%d' % i
seen.add(name)
field_names = tuple(names)
for name in (typename,) + field_names:
if not min(c.isalnum() or c=='_' for c in name):
raise ValueError('Type names and field names can only contain alphanumeric characters and underscores: %r' % name)
if _iskeyword(name):
raise ValueError('Type names and field names cannot be a keyword: %r' % name)
if name[0].isdigit():
raise ValueError('Type names and field names cannot start with a number: %r' % name)
seen_names = set()
for name in field_names:
if name.startswith('_') and not rename:
raise ValueError('Field names cannot start with an underscore: %r' % name)
if name in seen_names:
raise ValueError('Encountered duplicate field name: %r' % name)
seen_names.add(name)
# Create and fill-in the class template
numfields = len(field_names)
argtxt = repr(field_names).replace("'", "")[1:-1] # tuple repr without parens or quotes
reprtxt = ', '.join('%s=%%r' % name for name in field_names)
template = '''class %(typename)s(tuple):
'%(typename)s(%(argtxt)s)' \n
__slots__ = () \n
_fields = %(field_names)r \n
def __new__(_cls, %(argtxt)s):
return _tuple.__new__(_cls, (%(argtxt)s)) \n
@classmethod
def _make(cls, iterable, new=tuple.__new__, len=len):
'Make a new %(typename)s object from a sequence or iterable'
result = new(cls, iterable)
if len(result) != %(numfields)d:
raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result))
return result \n
def __repr__(self):
return '%(typename)s(%(reprtxt)s)' %% self \n
def _asdict(self):
'Return a new dict which maps field names to their values'
return dict(zip(self._fields, self)) \n
def _replace(_self, **kwds):
'Return a new %(typename)s object replacing specified fields with new values'
result = _self._make(map(kwds.pop, %(field_names)r, _self))
if kwds:
raise ValueError('Got unexpected field names: %%r' %% kwds.keys())
return result \n
def __getnewargs__(self):
return tuple(self) \n\n''' % locals()
for i, name in enumerate(field_names):
template += ' %s = _property(_itemgetter(%d))\n' % (name, i)
if verbose:
print(template)
# Execute the template string in a temporary namespace
namespace = dict(_itemgetter=_itemgetter, __name__='namedtuple_%s' % typename,
_property=property, _tuple=tuple)
try:
exec(template, namespace)
except SyntaxError:
e = _sys.exc_info()[1]
raise SyntaxError(e.message + ':\n' + template)
result = namespace[typename]
# For pickling to work, the __module__ variable needs to be set to the frame
# where the named tuple is created. Bypass this step in enviroments where
# sys._getframe is not defined (Jython for example) or sys._getframe is not
# defined for arguments greater than 0 (IronPython).
try:
result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
except (AttributeError, ValueError):
pass
return result
if __name__ == '__main__':
# verify that instances can be pickled
from cPickle import loads, dumps
Point = namedtuple('Point', 'x, y', True)
p = Point(x=10, y=20)
assert p == loads(dumps(p, -1))
# test and demonstrate ability to override methods
class Point(namedtuple('Point', 'x y')):
@property
def hypot(self):
return (self.x ** 2 + self.y ** 2) ** 0.5
def __str__(self):
return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y, self.hypot)
for p in Point(3,4), Point(14,5), Point(9./7,6):
print(p)
class Point(namedtuple('Point', 'x y')):
'Point class with optimized _make() and _replace() without error-checking'
_make = classmethod(tuple.__new__)
def _replace(self, _map=map, **kwds):
return self._make(_map(kwds.get, ('x', 'y'), self))
print(Point(11, 22)._replace(x=100))
import doctest
TestResults = namedtuple('TestResults', 'failed attempted')
print(TestResults(*doctest.testmod()))
## end of http://code.activestate.com/recipes/500261/ }}}
|
gpl-3.0
|
[
309,
469,
3638,
1455,
921,
600,
14,
32595,
14,
957,
15,
25200,
15,
5783,
15128,
15,
334,
82,
1046,
9,
199,
504,
4182,
492,
1242,
7416,
465,
485,
20832,
199,
504,
4252,
492,
365,
6691,
465,
485,
374,
6691,
199,
646,
984,
465,
485,
1274,
199,
504,
6170,
14,
894,
5203,
14,
4174,
492,
1059,
63,
1313,
465,
7116,
199,
199,
318,
12863,
8,
18596,
12,
901,
63,
1247,
12,
3376,
29,
797,
12,
11441,
29,
797,
304,
272,
408,
3407,
282,
892,
5516,
402,
2008,
543,
4310,
1504,
14,
339,
1306,
7584,
275,
12863,
360,
3428,
297,
283,
88,
612,
358,
272,
1306,
7584,
855,
1301,
363,
7861,
327,
9214,
367,
314,
892,
1021,
272,
283,
3428,
8,
88,
12,
612,
3171,
272,
1306,
299,
275,
7584,
8,
845,
12,
612,
29,
1081,
9,
3777,
327,
17321,
543,
11333,
1249,
503,
7681,
272,
1306,
299,
59,
16,
61,
435,
299,
59,
17,
61,
9326,
327,
1478,
461,
2839,
282,
8971,
2008,
272,
9404,
272,
1306,
671,
12,
612,
275,
299,
12788,
327,
7787,
2839,
282,
5578,
2008,
272,
1306,
671,
12,
612,
272,
334,
845,
12,
6928,
9,
272,
1306,
299,
14,
88,
435,
299,
14,
89,
9668,
327,
1504,
2597,
2879,
461,
701,
536,
272,
9404,
272,
1306,
366,
275,
299,
423,
305,
807,
342,
463,
327,
3957,
370,
282,
2600,
272,
1306,
366,
459,
88,
418,
272,
4119,
272,
1306,
7584,
3682,
68,
9,
10473,
327,
3957,
687,
282,
2600,
272,
7584,
8,
88,
29,
845,
12,
612,
29,
1081,
9,
272,
1306,
299,
423,
1814,
8,
88,
29,
1960,
9,
5185,
327,
485,
1814,
342,
365,
2839,
620,
14,
1814,
342,
1325,
4545,
4310,
1504,
272,
7584,
8,
88,
29,
1960,
12,
612,
29,
1081,
9,
339,
408,
339,
327,
6077,
436,
4107,
314,
901,
1561,
14,
221,
19381,
23739,
2877,
12901,
12,
272,
327,
12999,
315,
20889,
1125,
3788,
436,
7981,
316,
1978,
315,
8923,
28140,
14,
272,
340,
1228,
8,
698,
63,
1247,
12,
7116,
304,
267,
901,
63,
1247,
275,
901,
63,
1247,
14,
1814,
32718,
283,
27274,
1294,
342,
327,
1561,
11673,
701,
8139,
436,
15,
269,
24476,
272,
901,
63,
1247,
275,
2008,
8,
1130,
8,
495,
12,
901,
63,
1247,
430,
272,
340,
11441,
26,
267,
1561,
275,
769,
8,
698,
63,
1247,
9,
267,
6775,
275,
663,
342,
267,
367,
284,
12,
536,
315,
3874,
8,
1247,
304,
288,
340,
334,
1397,
1748,
8,
67,
14,
28235,
1507,
342,
503,
286,
6803,
8650,
367,
286,
315,
536,
9,
503,
485,
374,
6691,
8,
354,
9,
355,
503,
440,
536,
503,
536,
59,
16,
1055,
13896,
342,
503,
536,
14,
2460,
26341,
355,
503,
536,
315,
6775,
304,
490,
1561,
59,
73,
61,
275,
2513,
5,
68,
7,
450,
284,
288,
6775,
14,
525,
8,
354,
9,
267,
901,
63,
1247,
275,
2008,
8,
1247,
9,
272,
367,
536,
315,
334,
18596,
4258,
435,
901,
63,
1247,
26,
267,
340,
440,
1748,
8,
67,
14,
28235,
1507,
342,
503,
286,
6803,
8650,
367,
286,
315,
536,
304,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
883,
1454,
1395,
27964,
4110,
436,
23998,
26,
450,
82,
7,
450,
536,
9,
267,
340,
485,
374,
6691,
8,
354,
304,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
3913,
506,
282,
4252,
26,
450,
82,
7,
450,
536,
9,
267,
340,
536,
59,
16,
1055,
13896,
837,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
3913,
1343,
543,
282,
1329,
26,
450,
82,
7,
450,
536,
9,
272,
6775,
63,
1247,
275,
663,
342,
272,
367,
536,
315,
901,
63,
1247,
26,
267,
340,
536,
14,
2460,
26341,
436,
440,
11441,
26,
288,
746,
1722,
360,
792,
1561,
3913,
1343,
543,
376,
18888,
26,
450,
82,
7,
450,
536,
9,
267,
340,
536,
315,
6775,
63,
1247,
26,
288,
746,
1722,
360,
1327,
12613,
9250,
901,
536,
26,
450,
82,
7,
450,
536,
9,
267,
6775,
63,
1247,
14,
525,
8,
354,
9,
339,
327,
2790,
436,
5554,
13,
262,
314,
1021,
1978,
272,
1967,
955,
275,
822,
8,
698,
63,
1247,
9,
272,
1680,
2424,
275,
4700,
8,
698,
63,
1247,
680,
1814,
27769,
6899,
59,
17,
6809,
17,
61,
257,
327,
2008,
4700,
1928,
32029,
503,
9344,
272,
4700,
2424,
275,
1656,
1987,
904,
3508,
83,
2458,
5,
82,
7,
450,
536,
367,
536,
315,
901,
63,
1247,
9,
272,
1978,
275,
1449,
533,
2818,
18596,
9,
83,
8,
2960,
304,
267,
9487,
18596,
9,
83,
12473,
1273,
2424,
9,
83,
3171,
971,
78,
267,
636,
7257,
363,
275,
6248,
971,
78,
267,
485,
955,
275,
2818,
698,
63,
1247,
9,
82,
971,
78,
267,
347,
636,
1222,
721,
63,
1886,
12,
2818,
1273,
2424,
9,
83,
304,
288,
372,
485,
2960,
855,
1222,
721,
63,
1886,
12,
17753,
1273,
2424,
9,
83,
430,
971,
78,
267,
768,
3744,
267,
347,
485,
1875,
8,
1886,
12,
6076,
12,
892,
29,
2960,
855,
1222,
3108,
822,
29,
552,
304,
288,
283,
5483,
282,
892,
2818,
18596,
9,
83,
909,
687,
282,
3414,
503,
6076,
7,
288,
754,
275,
892,
8,
1886,
12,
6076,
9,
288,
340,
822,
8,
1099,
9,
1137,
2818,
1507,
955,
9,
68,
26,
355,
746,
3146,
360,
6964,
2818,
1507,
955,
9,
68,
2368,
12,
4788,
11539,
68,
7,
11539,
822,
8,
1099,
430,
288,
372,
754,
971,
78,
267,
347,
636,
2722,
721,
277,
304,
288,
372,
9487,
18596,
9,
83,
12473,
2722,
2424,
9,
83,
3171,
11539,
291,
971,
78,
267,
347,
485,
305,
807,
8,
277,
304,
288,
283,
1767,
282,
892,
1211,
1314,
9033,
901,
1561,
370,
3932,
1338,
7,
288,
372,
1211,
8,
3065,
8,
277,
423,
955,
12,
291,
430,
971,
78,
267,
347,
485,
1814,
1547,
277,
12,
1011,
10340,
304,
288,
283,
1767,
282,
892,
2818,
18596,
9,
83,
909,
15810,
2013,
1504,
543,
892,
1338,
7,
288,
754,
275,
485,
277,
423,
1875,
8,
1130,
8,
10340,
14,
1935,
12,
2818,
698,
63,
1247,
9,
82,
12,
485,
277,
430,
288,
340,
16286,
26,
355,
746,
1722,
360,
13662,
10537,
901,
1561,
26,
11539,
82,
7,
11539,
16286,
14,
1612
] |
[
469,
3638,
1455,
921,
600,
14,
32595,
14,
957,
15,
25200,
15,
5783,
15128,
15,
334,
82,
1046,
9,
199,
504,
4182,
492,
1242,
7416,
465,
485,
20832,
199,
504,
4252,
492,
365,
6691,
465,
485,
374,
6691,
199,
646,
984,
465,
485,
1274,
199,
504,
6170,
14,
894,
5203,
14,
4174,
492,
1059,
63,
1313,
465,
7116,
199,
199,
318,
12863,
8,
18596,
12,
901,
63,
1247,
12,
3376,
29,
797,
12,
11441,
29,
797,
304,
272,
408,
3407,
282,
892,
5516,
402,
2008,
543,
4310,
1504,
14,
339,
1306,
7584,
275,
12863,
360,
3428,
297,
283,
88,
612,
358,
272,
1306,
7584,
855,
1301,
363,
7861,
327,
9214,
367,
314,
892,
1021,
272,
283,
3428,
8,
88,
12,
612,
3171,
272,
1306,
299,
275,
7584,
8,
845,
12,
612,
29,
1081,
9,
3777,
327,
17321,
543,
11333,
1249,
503,
7681,
272,
1306,
299,
59,
16,
61,
435,
299,
59,
17,
61,
9326,
327,
1478,
461,
2839,
282,
8971,
2008,
272,
9404,
272,
1306,
671,
12,
612,
275,
299,
12788,
327,
7787,
2839,
282,
5578,
2008,
272,
1306,
671,
12,
612,
272,
334,
845,
12,
6928,
9,
272,
1306,
299,
14,
88,
435,
299,
14,
89,
9668,
327,
1504,
2597,
2879,
461,
701,
536,
272,
9404,
272,
1306,
366,
275,
299,
423,
305,
807,
342,
463,
327,
3957,
370,
282,
2600,
272,
1306,
366,
459,
88,
418,
272,
4119,
272,
1306,
7584,
3682,
68,
9,
10473,
327,
3957,
687,
282,
2600,
272,
7584,
8,
88,
29,
845,
12,
612,
29,
1081,
9,
272,
1306,
299,
423,
1814,
8,
88,
29,
1960,
9,
5185,
327,
485,
1814,
342,
365,
2839,
620,
14,
1814,
342,
1325,
4545,
4310,
1504,
272,
7584,
8,
88,
29,
1960,
12,
612,
29,
1081,
9,
339,
408,
339,
327,
6077,
436,
4107,
314,
901,
1561,
14,
221,
19381,
23739,
2877,
12901,
12,
272,
327,
12999,
315,
20889,
1125,
3788,
436,
7981,
316,
1978,
315,
8923,
28140,
14,
272,
340,
1228,
8,
698,
63,
1247,
12,
7116,
304,
267,
901,
63,
1247,
275,
901,
63,
1247,
14,
1814,
32718,
283,
27274,
1294,
342,
327,
1561,
11673,
701,
8139,
436,
15,
269,
24476,
272,
901,
63,
1247,
275,
2008,
8,
1130,
8,
495,
12,
901,
63,
1247,
430,
272,
340,
11441,
26,
267,
1561,
275,
769,
8,
698,
63,
1247,
9,
267,
6775,
275,
663,
342,
267,
367,
284,
12,
536,
315,
3874,
8,
1247,
304,
288,
340,
334,
1397,
1748,
8,
67,
14,
28235,
1507,
342,
503,
286,
6803,
8650,
367,
286,
315,
536,
9,
503,
485,
374,
6691,
8,
354,
9,
355,
503,
440,
536,
503,
536,
59,
16,
1055,
13896,
342,
503,
536,
14,
2460,
26341,
355,
503,
536,
315,
6775,
304,
490,
1561,
59,
73,
61,
275,
2513,
5,
68,
7,
450,
284,
288,
6775,
14,
525,
8,
354,
9,
267,
901,
63,
1247,
275,
2008,
8,
1247,
9,
272,
367,
536,
315,
334,
18596,
4258,
435,
901,
63,
1247,
26,
267,
340,
440,
1748,
8,
67,
14,
28235,
1507,
342,
503,
286,
6803,
8650,
367,
286,
315,
536,
304,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
883,
1454,
1395,
27964,
4110,
436,
23998,
26,
450,
82,
7,
450,
536,
9,
267,
340,
485,
374,
6691,
8,
354,
304,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
3913,
506,
282,
4252,
26,
450,
82,
7,
450,
536,
9,
267,
340,
536,
59,
16,
1055,
13896,
837,
288,
746,
1722,
360,
804,
1561,
436,
901,
1561,
3913,
1343,
543,
282,
1329,
26,
450,
82,
7,
450,
536,
9,
272,
6775,
63,
1247,
275,
663,
342,
272,
367,
536,
315,
901,
63,
1247,
26,
267,
340,
536,
14,
2460,
26341,
436,
440,
11441,
26,
288,
746,
1722,
360,
792,
1561,
3913,
1343,
543,
376,
18888,
26,
450,
82,
7,
450,
536,
9,
267,
340,
536,
315,
6775,
63,
1247,
26,
288,
746,
1722,
360,
1327,
12613,
9250,
901,
536,
26,
450,
82,
7,
450,
536,
9,
267,
6775,
63,
1247,
14,
525,
8,
354,
9,
339,
327,
2790,
436,
5554,
13,
262,
314,
1021,
1978,
272,
1967,
955,
275,
822,
8,
698,
63,
1247,
9,
272,
1680,
2424,
275,
4700,
8,
698,
63,
1247,
680,
1814,
27769,
6899,
59,
17,
6809,
17,
61,
257,
327,
2008,
4700,
1928,
32029,
503,
9344,
272,
4700,
2424,
275,
1656,
1987,
904,
3508,
83,
2458,
5,
82,
7,
450,
536,
367,
536,
315,
901,
63,
1247,
9,
272,
1978,
275,
1449,
533,
2818,
18596,
9,
83,
8,
2960,
304,
267,
9487,
18596,
9,
83,
12473,
1273,
2424,
9,
83,
3171,
971,
78,
267,
636,
7257,
363,
275,
6248,
971,
78,
267,
485,
955,
275,
2818,
698,
63,
1247,
9,
82,
971,
78,
267,
347,
636,
1222,
721,
63,
1886,
12,
2818,
1273,
2424,
9,
83,
304,
288,
372,
485,
2960,
855,
1222,
721,
63,
1886,
12,
17753,
1273,
2424,
9,
83,
430,
971,
78,
267,
768,
3744,
267,
347,
485,
1875,
8,
1886,
12,
6076,
12,
892,
29,
2960,
855,
1222,
3108,
822,
29,
552,
304,
288,
283,
5483,
282,
892,
2818,
18596,
9,
83,
909,
687,
282,
3414,
503,
6076,
7,
288,
754,
275,
892,
8,
1886,
12,
6076,
9,
288,
340,
822,
8,
1099,
9,
1137,
2818,
1507,
955,
9,
68,
26,
355,
746,
3146,
360,
6964,
2818,
1507,
955,
9,
68,
2368,
12,
4788,
11539,
68,
7,
11539,
822,
8,
1099,
430,
288,
372,
754,
971,
78,
267,
347,
636,
2722,
721,
277,
304,
288,
372,
9487,
18596,
9,
83,
12473,
2722,
2424,
9,
83,
3171,
11539,
291,
971,
78,
267,
347,
485,
305,
807,
8,
277,
304,
288,
283,
1767,
282,
892,
1211,
1314,
9033,
901,
1561,
370,
3932,
1338,
7,
288,
372,
1211,
8,
3065,
8,
277,
423,
955,
12,
291,
430,
971,
78,
267,
347,
485,
1814,
1547,
277,
12,
1011,
10340,
304,
288,
283,
1767,
282,
892,
2818,
18596,
9,
83,
909,
15810,
2013,
1504,
543,
892,
1338,
7,
288,
754,
275,
485,
277,
423,
1875,
8,
1130,
8,
10340,
14,
1935,
12,
2818,
698,
63,
1247,
9,
82,
12,
485,
277,
430,
288,
340,
16286,
26,
355,
746,
1722,
360,
13662,
10537,
901,
1561,
26,
11539,
82,
7,
11539,
16286,
14,
1612,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aisthesis/mfstockmkt
|
options/db/trackpuller.py
|
1
|
1181
|
"""
.. Copyright (c) 2016 Marshall Farrier
license http://opensource.org/licenses/MIT
Get options to be tracked
"""
import datetime as dt
from bson.codec_options import CodecOptions
import config
import constants
from dbwrapper import job
class TrackPuller(object):
def __init__(self, logger):
self.logger = logger
def get(self):
"""
Get a dictionary of options to track.
"""
return job(self.logger, _getactive)
def _getactive(logger, client):
totrack = {}
dbname = constants.DB[config.ENV]['name']
_db = client[dbname]
c_opts = CodecOptions(tz_aware=True)
trackcoll = _db.get_collection('track', codec_options=c_opts)
utcnow = dt.datetime.utcnow()
for entry in trackcoll.find({'Expiry': {'$gt': utcnow}}):
_addentry(totrack, entry)
logger.info('found active track entries for {} equities'.format(len(totrack)))
return totrack
def _addentry(totrack, entry):
if entry['Underlying'] not in totrack:
totrack[entry['Underlying']] = []
totrack[entry['Underlying']].append({'Opt_Type': entry['Opt_Type'],
'Strike': entry['Strike'], 'Expiry': entry['Expiry']})
|
mit
|
[
624,
199,
703,
1898,
334,
67,
9,
7800,
16794,
609,
452,
481,
285,
10742,
2043,
4190,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
199,
199,
1002,
1511,
370,
506,
23268,
199,
624,
199,
199,
646,
2197,
465,
4487,
199,
504,
330,
834,
14,
9276,
63,
1419,
492,
13732,
4558,
199,
199,
646,
1101,
199,
646,
5262,
199,
504,
1592,
5029,
492,
3906,
199,
199,
533,
17507,
48,
348,
1435,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2512,
304,
267,
291,
14,
2921,
275,
2512,
339,
347,
664,
8,
277,
304,
267,
408,
267,
2372,
282,
2600,
402,
1511,
370,
4426,
14,
267,
408,
267,
372,
3906,
8,
277,
14,
2921,
12,
485,
362,
2682,
9,
199,
199,
318,
485,
362,
2682,
8,
2921,
12,
1890,
304,
272,
12657,
8085,
275,
1052,
272,
21842,
275,
5262,
14,
2846,
59,
888,
14,
9984,
2733,
354,
418,
272,
485,
697,
275,
1890,
59,
13238,
61,
272,
286,
63,
3291,
275,
13732,
4558,
8,
3903,
63,
14600,
29,
549,
9,
272,
4426,
15772,
275,
485,
697,
14,
362,
63,
3627,
360,
3885,
297,
9076,
63,
1419,
29,
67,
63,
3291,
9,
272,
221,
10779,
275,
4487,
14,
2083,
14,
10779,
342,
272,
367,
2397,
315,
4426,
15772,
14,
1623,
3252,
14000,
651,
356,
30108,
3308,
356,
221,
10779,
4863,
304,
267,
485,
350,
1326,
651,
8,
13280,
8085,
12,
2397,
9,
272,
2512,
14,
815,
360,
4214,
4702,
4426,
4811,
367,
1052,
325,
783,
1417,
1370,
908,
8,
552,
8,
13280,
8085,
1724,
272,
372,
12657,
8085,
199,
199,
318,
485,
350,
1326,
651,
8,
13280,
8085,
12,
2397,
304,
272,
340,
2397,
459,
26104,
418,
440,
315,
12657,
8085,
26,
267,
12657,
8085,
59,
2373,
459,
26104,
6538,
275,
942,
272,
12657,
8085,
59,
2373,
459,
26104,
418,
1055,
740,
3252,
9985,
63,
804,
356,
2397,
459,
9985,
63,
804,
995,
267,
283,
24125,
415,
356,
2397,
459,
24125,
415,
995,
283,
14000,
651,
356,
2397,
459,
14000,
651,
13678,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
703,
1898,
334,
67,
9,
7800,
16794,
609,
452,
481,
285,
10742,
2043,
4190,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
199,
199,
1002,
1511,
370,
506,
23268,
199,
624,
199,
199,
646,
2197,
465,
4487,
199,
504,
330,
834,
14,
9276,
63,
1419,
492,
13732,
4558,
199,
199,
646,
1101,
199,
646,
5262,
199,
504,
1592,
5029,
492,
3906,
199,
199,
533,
17507,
48,
348,
1435,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2512,
304,
267,
291,
14,
2921,
275,
2512,
339,
347,
664,
8,
277,
304,
267,
408,
267,
2372,
282,
2600,
402,
1511,
370,
4426,
14,
267,
408,
267,
372,
3906,
8,
277,
14,
2921,
12,
485,
362,
2682,
9,
199,
199,
318,
485,
362,
2682,
8,
2921,
12,
1890,
304,
272,
12657,
8085,
275,
1052,
272,
21842,
275,
5262,
14,
2846,
59,
888,
14,
9984,
2733,
354,
418,
272,
485,
697,
275,
1890,
59,
13238,
61,
272,
286,
63,
3291,
275,
13732,
4558,
8,
3903,
63,
14600,
29,
549,
9,
272,
4426,
15772,
275,
485,
697,
14,
362,
63,
3627,
360,
3885,
297,
9076,
63,
1419,
29,
67,
63,
3291,
9,
272,
221,
10779,
275,
4487,
14,
2083,
14,
10779,
342,
272,
367,
2397,
315,
4426,
15772,
14,
1623,
3252,
14000,
651,
356,
30108,
3308,
356,
221,
10779,
4863,
304,
267,
485,
350,
1326,
651,
8,
13280,
8085,
12,
2397,
9,
272,
2512,
14,
815,
360,
4214,
4702,
4426,
4811,
367,
1052,
325,
783,
1417,
1370,
908,
8,
552,
8,
13280,
8085,
1724,
272,
372,
12657,
8085,
199,
199,
318,
485,
350,
1326,
651,
8,
13280,
8085,
12,
2397,
304,
272,
340,
2397,
459,
26104,
418,
440,
315,
12657,
8085,
26,
267,
12657,
8085,
59,
2373,
459,
26104,
6538,
275,
942,
272,
12657,
8085,
59,
2373,
459,
26104,
418,
1055,
740,
3252,
9985,
63,
804,
356,
2397,
459,
9985,
63,
804,
995,
267,
283,
24125,
415,
356,
2397,
459,
24125,
415,
995,
283,
14000,
651,
356,
2397,
459,
14000,
651,
13678,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jtl999/certbot
|
acme/acme/fields_test.py
|
62
|
2083
|
"""Tests for acme.fields."""
import datetime
import unittest
import pytz
from acme import jose
class FixedTest(unittest.TestCase):
"""Tests for acme.fields.Fixed."""
def setUp(self):
from acme.fields import Fixed
self.field = Fixed('name', 'x')
def test_decode(self):
self.assertEqual('x', self.field.decode('x'))
def test_decode_bad(self):
self.assertRaises(jose.DeserializationError, self.field.decode, 'y')
def test_encode(self):
self.assertEqual('x', self.field.encode('x'))
def test_encode_override(self):
self.assertEqual('y', self.field.encode('y'))
class RFC3339FieldTest(unittest.TestCase):
"""Tests for acme.fields.RFC3339Field."""
def setUp(self):
self.decoded = datetime.datetime(2015, 3, 27, tzinfo=pytz.utc)
self.encoded = '2015-03-27T00:00:00Z'
def test_default_encoder(self):
from acme.fields import RFC3339Field
self.assertEqual(
self.encoded, RFC3339Field.default_encoder(self.decoded))
def test_default_encoder_naive_fails(self):
from acme.fields import RFC3339Field
self.assertRaises(
ValueError, RFC3339Field.default_encoder, datetime.datetime.now())
def test_default_decoder(self):
from acme.fields import RFC3339Field
self.assertEqual(
self.decoded, RFC3339Field.default_decoder(self.encoded))
def test_default_decoder_raises_deserialization_error(self):
from acme.fields import RFC3339Field
self.assertRaises(
jose.DeserializationError, RFC3339Field.default_decoder, '')
class ResourceTest(unittest.TestCase):
"""Tests for acme.fields.Resource."""
def setUp(self):
from acme.fields import Resource
self.field = Resource('x')
def test_decode_good(self):
self.assertEqual('x', self.field.decode('x'))
def test_decode_wrong(self):
self.assertRaises(jose.DeserializationError, self.field.decode, 'y')
if __name__ == '__main__':
unittest.main() # pragma: no cover
|
apache-2.0
|
[
624,
2925,
367,
32433,
14,
955,
1041,
199,
646,
2197,
199,
646,
2882,
199,
199,
646,
15444,
199,
199,
504,
32433,
492,
5225,
261,
421,
199,
533,
18659,
774,
8,
2796,
14,
1746,
304,
272,
408,
2925,
367,
32433,
14,
955,
14,
9515,
1041,
339,
347,
3613,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
18659,
267,
291,
14,
698,
275,
18659,
360,
354,
297,
283,
88,
358,
339,
347,
511,
63,
2708,
8,
277,
304,
267,
291,
14,
629,
360,
88,
297,
291,
14,
698,
14,
2708,
360,
88,
1333,
339,
347,
511,
63,
2708,
63,
4087,
8,
277,
304,
267,
291,
14,
1855,
8,
743,
261,
14,
872,
12161,
547,
12,
291,
14,
698,
14,
2708,
12,
283,
89,
358,
339,
347,
511,
63,
2143,
8,
277,
304,
267,
291,
14,
629,
360,
88,
297,
291,
14,
698,
14,
2143,
360,
88,
1333,
339,
347,
511,
63,
2143,
63,
4415,
8,
277,
304,
267,
291,
14,
629,
360,
89,
297,
291,
14,
698,
14,
2143,
360,
89,
1333,
421,
199,
533,
7329,
29536,
792,
774,
8,
2796,
14,
1746,
304,
272,
408,
2925,
367,
32433,
14,
955,
14,
14468,
29536,
792,
1041,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
16167,
275,
2197,
14,
2083,
8,
7806,
12,
650,
12,
8087,
12,
10313,
29,
21948,
14,
5834,
9,
267,
291,
14,
8167,
275,
283,
7806,
13,
1644,
13,
1465,
52,
383,
26,
383,
26,
383,
58,
7,
339,
347,
511,
63,
885,
63,
9347,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7329,
29536,
792,
267,
291,
14,
629,
8,
288,
291,
14,
8167,
12,
7329,
29536,
792,
14,
885,
63,
9347,
8,
277,
14,
16167,
430,
339,
347,
511,
63,
885,
63,
9347,
63,
21578,
63,
15762,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7329,
29536,
792,
267,
291,
14,
1855,
8,
288,
1722,
12,
7329,
29536,
792,
14,
885,
63,
9347,
12,
2197,
14,
2083,
14,
2131,
1012,
339,
347,
511,
63,
885,
63,
8813,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7329,
29536,
792,
267,
291,
14,
629,
8,
288,
291,
14,
16167,
12,
7329,
29536,
792,
14,
885,
63,
8813,
8,
277,
14,
8167,
430,
339,
347,
511,
63,
885,
63,
8813,
63,
3536,
63,
271,
12161,
63,
705,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7329,
29536,
792,
267,
291,
14,
1855,
8,
288,
5225,
261,
14,
872,
12161,
547,
12,
7329,
29536,
792,
14,
885,
63,
8813,
12,
4074,
421,
199,
533,
7337,
774,
8,
2796,
14,
1746,
304,
272,
408,
2925,
367,
32433,
14,
955,
14,
4031,
1041,
339,
347,
3613,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7337,
267,
291,
14,
698,
275,
7337,
360,
88,
358,
339,
347,
511,
63,
2708,
63,
8302,
8,
277,
304,
267,
291,
14,
629,
360,
88,
297,
291,
14,
698,
14,
2708,
360,
88,
1333,
339,
347,
511,
63,
2708,
63,
10603,
8,
277,
304,
267,
291,
14,
1855,
8,
743,
261,
14,
872,
12161,
547,
12,
291,
14,
698,
14,
2708,
12,
283,
89,
358,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
221,
327,
11942,
26,
949,
8486,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
32433,
14,
955,
1041,
199,
646,
2197,
199,
646,
2882,
199,
199,
646,
15444,
199,
199,
504,
32433,
492,
5225,
261,
421,
199,
533,
18659,
774,
8,
2796,
14,
1746,
304,
272,
408,
2925,
367,
32433,
14,
955,
14,
9515,
1041,
339,
347,
3613,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
18659,
267,
291,
14,
698,
275,
18659,
360,
354,
297,
283,
88,
358,
339,
347,
511,
63,
2708,
8,
277,
304,
267,
291,
14,
629,
360,
88,
297,
291,
14,
698,
14,
2708,
360,
88,
1333,
339,
347,
511,
63,
2708,
63,
4087,
8,
277,
304,
267,
291,
14,
1855,
8,
743,
261,
14,
872,
12161,
547,
12,
291,
14,
698,
14,
2708,
12,
283,
89,
358,
339,
347,
511,
63,
2143,
8,
277,
304,
267,
291,
14,
629,
360,
88,
297,
291,
14,
698,
14,
2143,
360,
88,
1333,
339,
347,
511,
63,
2143,
63,
4415,
8,
277,
304,
267,
291,
14,
629,
360,
89,
297,
291,
14,
698,
14,
2143,
360,
89,
1333,
421,
199,
533,
7329,
29536,
792,
774,
8,
2796,
14,
1746,
304,
272,
408,
2925,
367,
32433,
14,
955,
14,
14468,
29536,
792,
1041,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
16167,
275,
2197,
14,
2083,
8,
7806,
12,
650,
12,
8087,
12,
10313,
29,
21948,
14,
5834,
9,
267,
291,
14,
8167,
275,
283,
7806,
13,
1644,
13,
1465,
52,
383,
26,
383,
26,
383,
58,
7,
339,
347,
511,
63,
885,
63,
9347,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7329,
29536,
792,
267,
291,
14,
629,
8,
288,
291,
14,
8167,
12,
7329,
29536,
792,
14,
885,
63,
9347,
8,
277,
14,
16167,
430,
339,
347,
511,
63,
885,
63,
9347,
63,
21578,
63,
15762,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7329,
29536,
792,
267,
291,
14,
1855,
8,
288,
1722,
12,
7329,
29536,
792,
14,
885,
63,
9347,
12,
2197,
14,
2083,
14,
2131,
1012,
339,
347,
511,
63,
885,
63,
8813,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7329,
29536,
792,
267,
291,
14,
629,
8,
288,
291,
14,
16167,
12,
7329,
29536,
792,
14,
885,
63,
8813,
8,
277,
14,
8167,
430,
339,
347,
511,
63,
885,
63,
8813,
63,
3536,
63,
271,
12161,
63,
705,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7329,
29536,
792,
267,
291,
14,
1855,
8,
288,
5225,
261,
14,
872,
12161,
547,
12,
7329,
29536,
792,
14,
885,
63,
8813,
12,
4074,
421,
199,
533,
7337,
774,
8,
2796,
14,
1746,
304,
272,
408,
2925,
367,
32433,
14,
955,
14,
4031,
1041,
339,
347,
3613,
8,
277,
304,
267,
687,
32433,
14,
955,
492,
7337,
267,
291,
14,
698,
275,
7337,
360,
88,
358,
339,
347,
511,
63,
2708,
63,
8302,
8,
277,
304,
267,
291,
14,
629,
360,
88,
297,
291,
14,
698,
14,
2708,
360,
88,
1333,
339,
347,
511,
63,
2708,
63,
10603,
8,
277,
304,
267,
291,
14,
1855,
8,
743,
261,
14,
872,
12161,
547,
12,
291,
14,
698,
14,
2708,
12,
283,
89,
358,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
221,
327,
11942,
26,
949,
8486,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0
] |
kenwang815/KodiPlugins
|
script.module.oceanktv/lib/youtube_dl/extractor/videofyme.py
|
111
|
1750
|
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import (
int_or_none,
parse_iso8601,
)
class VideofyMeIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.videofy\.me/.+?|p\.videofy\.me/v)/(?P<id>\d+)(&|#|$)'
IE_NAME = 'videofy.me'
_TEST = {
'url': 'http://www.videofy.me/thisisvideofyme/1100701',
'md5': 'c77d700bdc16ae2e9f3c26019bd96143',
'info_dict': {
'id': '1100701',
'ext': 'mp4',
'title': 'This is VideofyMe',
'description': '',
'upload_date': '20130326',
'timestamp': 1364288959,
'uploader': 'VideofyMe',
'uploader_id': 'thisisvideofyme',
'view_count': int,
'likes': int,
'comment_count': int,
},
}
def _real_extract(self, url):
video_id = self._match_id(url)
config = self._download_json('http://vf-player-info-loader.herokuapp.com/%s.json' % video_id, video_id)['videoinfo']
video = config.get('video')
blog = config.get('blog', {})
return {
'id': video_id,
'title': video['title'],
'url': video['sources']['source']['url'],
'thumbnail': video.get('thumb'),
'description': video.get('description'),
'timestamp': parse_iso8601(video.get('date')),
'uploader': blog.get('name'),
'uploader_id': blog.get('identifier'),
'view_count': int_or_none(self._search_regex(r'([0-9]+)', video.get('views'), 'view count', fatal=False)),
'likes': int_or_none(video.get('likes')),
'comment_count': int_or_none(video.get('nrOfComments')),
}
|
gpl-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
4595,
15363,
12,
199,
9,
421,
199,
533,
15709,
1399,
1352,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
4537,
3722,
1399,
4537,
278,
15,
11198,
92,
80,
4537,
3722,
1399,
4537,
278,
15,
86,
2447,
2229,
48,
28,
344,
3072,
68,
29653,
6,
92,
3,
92,
4,
3171,
272,
15292,
63,
2339,
275,
283,
3722,
1399,
14,
278,
7,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
3722,
1399,
14,
278,
15,
273,
9200,
3722,
1399,
278,
15,
845,
8255,
614,
297,
267,
283,
1064,
21,
356,
283,
67,
1138,
68,
15946,
3691,
67,
975,
3624,
18,
69,
25,
70,
19,
67,
1479,
12512,
3691,
2534,
12289,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
845,
8255,
614,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2765,
365,
15709,
1399,
1352,
297,
288,
283,
1802,
356,
3260,
288,
283,
5064,
63,
602,
356,
283,
1797,
1216,
8342,
297,
288,
283,
3954,
356,
4944,
772,
10740,
28892,
12,
288,
283,
13671,
356,
283,
9166,
1399,
1352,
297,
288,
283,
13671,
63,
344,
356,
283,
273,
9200,
3722,
1399,
278,
297,
288,
283,
1345,
63,
835,
356,
1109,
12,
288,
283,
29572,
356,
1109,
12,
288,
283,
3349,
63,
835,
356,
1109,
12,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
398,
1101,
275,
291,
423,
4249,
63,
1001,
360,
1014,
921,
19963,
13,
6147,
13,
815,
13,
3422,
14,
2523,
745,
85,
571,
14,
957,
3149,
83,
14,
1001,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
11820,
3722,
815,
418,
398,
3991,
275,
1101,
14,
362,
360,
3722,
358,
267,
19936,
275,
1101,
14,
362,
360,
11486,
297,
5009,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
3991,
459,
1213,
995,
288,
283,
633,
356,
3991,
459,
4553,
2545,
1365,
2545,
633,
995,
288,
283,
8311,
356,
3991,
14,
362,
360,
16534,
659,
288,
283,
1802,
356,
3991,
14,
362,
360,
1802,
659,
288,
283,
3954,
356,
2198,
63,
4595,
15363,
8,
3722,
14,
362,
360,
602,
3855,
288,
283,
13671,
356,
19936,
14,
362,
360,
354,
659,
288,
283,
13671,
63,
344,
356,
19936,
14,
362,
360,
5364,
659,
288,
283,
1345,
63,
835,
356,
1109,
63,
269,
63,
3592,
8,
277,
423,
1733,
63,
3821,
8,
82,
21731,
16,
13,
25,
28798,
3991,
14,
362,
360,
4196,
659,
283,
1345,
2338,
297,
14294,
29,
797,
1826,
288,
283,
29572,
356,
1109,
63,
269,
63,
3592,
8,
3722,
14,
362,
360,
29572,
3855,
288,
283,
3349,
63,
835,
356,
1109,
63,
269,
63,
3592,
8,
3722,
14,
362,
360,
7865,
3466,
18929,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
4595,
15363,
12,
199,
9,
421,
199,
533,
15709,
1399,
1352,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
4537,
3722,
1399,
4537,
278,
15,
11198,
92,
80,
4537,
3722,
1399,
4537,
278,
15,
86,
2447,
2229,
48,
28,
344,
3072,
68,
29653,
6,
92,
3,
92,
4,
3171,
272,
15292,
63,
2339,
275,
283,
3722,
1399,
14,
278,
7,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
3722,
1399,
14,
278,
15,
273,
9200,
3722,
1399,
278,
15,
845,
8255,
614,
297,
267,
283,
1064,
21,
356,
283,
67,
1138,
68,
15946,
3691,
67,
975,
3624,
18,
69,
25,
70,
19,
67,
1479,
12512,
3691,
2534,
12289,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
845,
8255,
614,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2765,
365,
15709,
1399,
1352,
297,
288,
283,
1802,
356,
3260,
288,
283,
5064,
63,
602,
356,
283,
1797,
1216,
8342,
297,
288,
283,
3954,
356,
4944,
772,
10740,
28892,
12,
288,
283,
13671,
356,
283,
9166,
1399,
1352,
297,
288,
283,
13671,
63,
344,
356,
283,
273,
9200,
3722,
1399,
278,
297,
288,
283,
1345,
63,
835,
356,
1109,
12,
288,
283,
29572,
356,
1109,
12,
288,
283,
3349,
63,
835,
356,
1109,
12,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
398,
1101,
275,
291,
423,
4249,
63,
1001,
360,
1014,
921,
19963,
13,
6147,
13,
815,
13,
3422,
14,
2523,
745,
85,
571,
14,
957,
3149,
83,
14,
1001,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
11820,
3722,
815,
418,
398,
3991,
275,
1101,
14,
362,
360,
3722,
358,
267,
19936,
275,
1101,
14,
362,
360,
11486,
297,
5009,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
3991,
459,
1213,
995,
288,
283,
633,
356,
3991,
459,
4553,
2545,
1365,
2545,
633,
995,
288,
283,
8311,
356,
3991,
14,
362,
360,
16534,
659,
288,
283,
1802,
356,
3991,
14,
362,
360,
1802,
659,
288,
283,
3954,
356,
2198,
63,
4595,
15363,
8,
3722,
14,
362,
360,
602,
3855,
288,
283,
13671,
356,
19936,
14,
362,
360,
354,
659,
288,
283,
13671,
63,
344,
356,
19936,
14,
362,
360,
5364,
659,
288,
283,
1345,
63,
835,
356,
1109,
63,
269,
63,
3592,
8,
277,
423,
1733,
63,
3821,
8,
82,
21731,
16,
13,
25,
28798,
3991,
14,
362,
360,
4196,
659,
283,
1345,
2338,
297,
14294,
29,
797,
1826,
288,
283,
29572,
356,
1109,
63,
269,
63,
3592,
8,
3722,
14,
362,
360,
29572,
3855,
288,
283,
3349,
63,
835,
356,
1109,
63,
269,
63,
3592,
8,
3722,
14,
362,
360,
7865,
3466,
18929,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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 datetime import timedelta
from tornado import gen, locks
from tornado.gen import TimeoutError
from tornado.testing import gen_test, AsyncTestCase
from tornado.test.util import unittest
class ConditionTest(AsyncTestCase):
def setUp(self):
super(ConditionTest, self).setUp()
self.history = []
def record_done(self, future, key):
"""Record the resolution of a Future returned by Condition.wait."""
def callback(_):
if not future.result():
# wait() resolved to False, meaning it timed out.
self.history.append('timeout')
else:
self.history.append(key)
future.add_done_callback(callback)
def test_repr(self):
c = locks.Condition()
self.assertIn('Condition', repr(c))
self.assertNotIn('waiters', repr(c))
c.wait()
self.assertIn('waiters', repr(c))
@gen_test
def test_notify(self):
c = locks.Condition()
self.io_loop.call_later(0.01, c.notify)
yield c.wait()
def test_notify_1(self):
c = locks.Condition()
self.record_done(c.wait(), 'wait1')
self.record_done(c.wait(), 'wait2')
c.notify(1)
self.history.append('notify1')
c.notify(1)
self.history.append('notify2')
self.assertEqual(['wait1', 'notify1', 'wait2', 'notify2'],
self.history)
def test_notify_n(self):
c = locks.Condition()
for i in range(6):
self.record_done(c.wait(), i)
c.notify(3)
# Callbacks execute in the order they were registered.
self.assertEqual(list(range(3)), self.history)
c.notify(1)
self.assertEqual(list(range(4)), self.history)
c.notify(2)
self.assertEqual(list(range(6)), self.history)
def test_notify_all(self):
c = locks.Condition()
for i in range(4):
self.record_done(c.wait(), i)
c.notify_all()
self.history.append('notify_all')
# Callbacks execute in the order they were registered.
self.assertEqual(
list(range(4)) + ['notify_all'],
self.history)
@gen_test
def test_wait_timeout(self):
c = locks.Condition()
wait = c.wait(timedelta(seconds=0.01))
self.io_loop.call_later(0.02, c.notify) # Too late.
yield gen.sleep(0.03)
self.assertFalse((yield wait))
@gen_test
def test_wait_timeout_preempted(self):
c = locks.Condition()
# This fires before the wait times out.
self.io_loop.call_later(0.01, c.notify)
wait = c.wait(timedelta(seconds=0.02))
yield gen.sleep(0.03)
yield wait # No TimeoutError.
@gen_test
def test_notify_n_with_timeout(self):
# Register callbacks 0, 1, 2, and 3. Callback 1 has a timeout.
# Wait for that timeout to expire, then do notify(2) and make
# sure everyone runs. Verifies that a timed-out callback does
# not count against the 'n' argument to notify().
c = locks.Condition()
self.record_done(c.wait(), 0)
self.record_done(c.wait(timedelta(seconds=0.01)), 1)
self.record_done(c.wait(), 2)
self.record_done(c.wait(), 3)
# Wait for callback 1 to time out.
yield gen.sleep(0.02)
self.assertEqual(['timeout'], self.history)
c.notify(2)
yield gen.sleep(0.01)
self.assertEqual(['timeout', 0, 2], self.history)
self.assertEqual(['timeout', 0, 2], self.history)
c.notify()
self.assertEqual(['timeout', 0, 2, 3], self.history)
@gen_test
def test_notify_all_with_timeout(self):
c = locks.Condition()
self.record_done(c.wait(), 0)
self.record_done(c.wait(timedelta(seconds=0.01)), 1)
self.record_done(c.wait(), 2)
# Wait for callback 1 to time out.
yield gen.sleep(0.02)
self.assertEqual(['timeout'], self.history)
c.notify_all()
self.assertEqual(['timeout', 0, 2], self.history)
@gen_test
def test_nested_notify(self):
# Ensure no notifications lost, even if notify() is reentered by a
# waiter calling notify().
c = locks.Condition()
# Three waiters.
futures = [c.wait() for _ in range(3)]
# First and second futures resolved. Second future reenters notify(),
# resolving third future.
futures[1].add_done_callback(lambda _: c.notify())
c.notify(2)
self.assertTrue(all(f.done() for f in futures))
@gen_test
def test_garbage_collection(self):
# Test that timed-out waiters are occasionally cleaned from the queue.
c = locks.Condition()
for _ in range(101):
c.wait(timedelta(seconds=0.01))
future = c.wait()
self.assertEqual(102, len(c._waiters))
# Let first 101 waiters time out, triggering a collection.
yield gen.sleep(0.02)
self.assertEqual(1, len(c._waiters))
# Final waiter is still active.
self.assertFalse(future.done())
c.notify()
self.assertTrue(future.done())
class EventTest(AsyncTestCase):
def test_repr(self):
event = locks.Event()
self.assertTrue('clear' in str(event))
self.assertFalse('set' in str(event))
event.set()
self.assertFalse('clear' in str(event))
self.assertTrue('set' in str(event))
def test_event(self):
e = locks.Event()
future_0 = e.wait()
e.set()
future_1 = e.wait()
e.clear()
future_2 = e.wait()
self.assertTrue(future_0.done())
self.assertTrue(future_1.done())
self.assertFalse(future_2.done())
@gen_test
def test_event_timeout(self):
e = locks.Event()
with self.assertRaises(TimeoutError):
yield e.wait(timedelta(seconds=0.01))
# After a timed-out waiter, normal operation works.
self.io_loop.add_timeout(timedelta(seconds=0.01), e.set)
yield e.wait(timedelta(seconds=1))
def test_event_set_multiple(self):
e = locks.Event()
e.set()
e.set()
self.assertTrue(e.is_set())
def test_event_wait_clear(self):
e = locks.Event()
f0 = e.wait()
e.clear()
f1 = e.wait()
e.set()
self.assertTrue(f0.done())
self.assertTrue(f1.done())
class SemaphoreTest(AsyncTestCase):
def test_negative_value(self):
self.assertRaises(ValueError, locks.Semaphore, value=-1)
def test_repr(self):
sem = locks.Semaphore()
self.assertIn('Semaphore', repr(sem))
self.assertIn('unlocked,value:1', repr(sem))
sem.acquire()
self.assertIn('locked', repr(sem))
self.assertNotIn('waiters', repr(sem))
sem.acquire()
self.assertIn('waiters', repr(sem))
def test_acquire(self):
sem = locks.Semaphore()
f0 = sem.acquire()
self.assertTrue(f0.done())
# Wait for release().
f1 = sem.acquire()
self.assertFalse(f1.done())
f2 = sem.acquire()
sem.release()
self.assertTrue(f1.done())
self.assertFalse(f2.done())
sem.release()
self.assertTrue(f2.done())
sem.release()
# Now acquire() is instant.
self.assertTrue(sem.acquire().done())
self.assertEqual(0, len(sem._waiters))
@gen_test
def test_acquire_timeout(self):
sem = locks.Semaphore(2)
yield sem.acquire()
yield sem.acquire()
acquire = sem.acquire(timedelta(seconds=0.01))
self.io_loop.call_later(0.02, sem.release) # Too late.
yield gen.sleep(0.3)
with self.assertRaises(gen.TimeoutError):
yield acquire
sem.acquire()
f = sem.acquire()
self.assertFalse(f.done())
sem.release()
self.assertTrue(f.done())
@gen_test
def test_acquire_timeout_preempted(self):
sem = locks.Semaphore(1)
yield sem.acquire()
# This fires before the wait times out.
self.io_loop.call_later(0.01, sem.release)
acquire = sem.acquire(timedelta(seconds=0.02))
yield gen.sleep(0.03)
yield acquire # No TimeoutError.
def test_release_unacquired(self):
# Unbounded releases are allowed, and increment the semaphore's value.
sem = locks.Semaphore()
sem.release()
sem.release()
# Now the counter is 3. We can acquire three times before blocking.
self.assertTrue(sem.acquire().done())
self.assertTrue(sem.acquire().done())
self.assertTrue(sem.acquire().done())
self.assertFalse(sem.acquire().done())
@gen_test
def test_garbage_collection(self):
# Test that timed-out waiters are occasionally cleaned from the queue.
sem = locks.Semaphore(value=0)
futures = [sem.acquire(timedelta(seconds=0.01)) for _ in range(101)]
future = sem.acquire()
self.assertEqual(102, len(sem._waiters))
# Let first 101 waiters time out, triggering a collection.
yield gen.sleep(0.02)
self.assertEqual(1, len(sem._waiters))
# Final waiter is still active.
self.assertFalse(future.done())
sem.release()
self.assertTrue(future.done())
# Prevent "Future exception was never retrieved" messages.
for future in futures:
self.assertRaises(TimeoutError, future.result)
class SemaphoreContextManagerTest(AsyncTestCase):
@gen_test
def test_context_manager(self):
sem = locks.Semaphore()
with (yield sem.acquire()) as yielded:
self.assertTrue(yielded is None)
# Semaphore was released and can be acquired again.
self.assertTrue(sem.acquire().done())
@gen_test
def test_context_manager_exception(self):
sem = locks.Semaphore()
with self.assertRaises(ZeroDivisionError):
with (yield sem.acquire()):
1 / 0
# Semaphore was released and can be acquired again.
self.assertTrue(sem.acquire().done())
@gen_test
def test_context_manager_timeout(self):
sem = locks.Semaphore()
with (yield sem.acquire(timedelta(seconds=0.01))):
pass
# Semaphore was released and can be acquired again.
self.assertTrue(sem.acquire().done())
@gen_test
def test_context_manager_timeout_error(self):
sem = locks.Semaphore(value=0)
with self.assertRaises(gen.TimeoutError):
with (yield sem.acquire(timedelta(seconds=0.01))):
pass
# Counter is still 0.
self.assertFalse(sem.acquire().done())
@gen_test
def test_context_manager_contended(self):
sem = locks.Semaphore()
history = []
@gen.coroutine
def f(index):
with (yield sem.acquire()):
history.append('acquired %d' % index)
yield gen.sleep(0.01)
history.append('release %d' % index)
yield [f(i) for i in range(2)]
expected_history = []
for i in range(2):
expected_history.extend(['acquired %d' % i, 'release %d' % i])
self.assertEqual(expected_history, history)
@gen_test
def test_yield_sem(self):
# Ensure we catch a "with (yield sem)", which should be
# "with (yield sem.acquire())".
with self.assertRaises(gen.BadYieldError):
with (yield locks.Semaphore()):
pass
def test_context_manager_misuse(self):
# Ensure we catch a "with sem", which should be
# "with (yield sem.acquire())".
with self.assertRaises(RuntimeError):
with locks.Semaphore():
pass
class BoundedSemaphoreTest(AsyncTestCase):
def test_release_unacquired(self):
sem = locks.BoundedSemaphore()
self.assertRaises(ValueError, sem.release)
# Value is 0.
sem.acquire()
# Block on acquire().
future = sem.acquire()
self.assertFalse(future.done())
sem.release()
self.assertTrue(future.done())
# Value is 1.
sem.release()
self.assertRaises(ValueError, sem.release)
class LockTests(AsyncTestCase):
def test_repr(self):
lock = locks.Lock()
# No errors.
repr(lock)
lock.acquire()
repr(lock)
def test_acquire_release(self):
lock = locks.Lock()
self.assertTrue(lock.acquire().done())
future = lock.acquire()
self.assertFalse(future.done())
lock.release()
self.assertTrue(future.done())
@gen_test
def test_acquire_fifo(self):
lock = locks.Lock()
self.assertTrue(lock.acquire().done())
N = 5
history = []
@gen.coroutine
def f(idx):
with (yield lock.acquire()):
history.append(idx)
futures = [f(i) for i in range(N)]
self.assertFalse(any(future.done() for future in futures))
lock.release()
yield futures
self.assertEqual(list(range(N)), history)
@gen_test
def test_acquire_timeout(self):
lock = locks.Lock()
lock.acquire()
with self.assertRaises(gen.TimeoutError):
yield lock.acquire(timeout=timedelta(seconds=0.01))
# Still locked.
self.assertFalse(lock.acquire().done())
def test_multi_release(self):
lock = locks.Lock()
self.assertRaises(RuntimeError, lock.release)
lock.acquire()
lock.release()
self.assertRaises(RuntimeError, lock.release)
@gen_test
def test_yield_lock(self):
# Ensure we catch a "with (yield lock)", which should be
# "with (yield lock.acquire())".
with self.assertRaises(gen.BadYieldError):
with (yield locks.Lock()):
pass
def test_context_manager_misuse(self):
# Ensure we catch a "with lock", which should be
# "with (yield lock.acquire())".
with self.assertRaises(RuntimeError):
with locks.Lock():
pass
if __name__ == '__main__':
unittest.main()
|
gpl-3.0
|
[
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,
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,
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,
504,
2197,
492,
6871,
199,
199,
504,
12148,
492,
3805,
12,
23340,
199,
504,
12148,
14,
2268,
492,
31886,
199,
504,
12148,
14,
4776,
492,
3805,
63,
396,
12,
15223,
1746,
199,
504,
12148,
14,
396,
14,
1974,
492,
2882,
421,
199,
533,
28401,
774,
8,
12807,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
9558,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
5570,
275,
942,
339,
347,
2777,
63,
4456,
8,
277,
12,
6466,
12,
790,
304,
267,
408,
5433,
314,
12401,
402,
282,
20799,
2138,
701,
28401,
14,
2573,
1041,
267,
347,
3233,
1547,
304,
288,
340,
440,
6466,
14,
1099,
837,
355,
327,
3618,
342,
12152,
370,
756,
12,
11150,
652,
18590,
734,
14,
355,
291,
14,
5570,
14,
740,
360,
2593,
358,
288,
587,
26,
355,
291,
14,
5570,
14,
740,
8,
498,
9,
267,
6466,
14,
525,
63,
4456,
63,
3058,
8,
3058,
9,
339,
347,
511,
63,
2722,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
291,
14,
4080,
360,
9558,
297,
4700,
8,
67,
430,
267,
291,
14,
8795,
360,
758,
15266,
297,
4700,
8,
67,
430,
267,
286,
14,
2573,
342,
267,
291,
14,
4080,
360,
758,
15266,
297,
4700,
8,
67,
430,
339,
768,
2268,
63,
396,
272,
347,
511,
63,
6814,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
291,
14,
2308,
63,
3813,
14,
1250,
63,
18103,
8,
16,
14,
614,
12,
286,
14,
6814,
9,
267,
1995,
286,
14,
2573,
342,
339,
347,
511,
63,
6814,
63,
17,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
283,
2573,
17,
358,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
283,
2573,
18,
358,
267,
286,
14,
6814,
8,
17,
9,
267,
291,
14,
5570,
14,
740,
360,
6814,
17,
358,
267,
286,
14,
6814,
8,
17,
9,
267,
291,
14,
5570,
14,
740,
360,
6814,
18,
358,
267,
291,
14,
629,
2941,
2573,
17,
297,
283,
6814,
17,
297,
283,
2573,
18,
297,
283,
6814,
18,
995,
586,
291,
14,
5570,
9,
339,
347,
511,
63,
6814,
63,
78,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
367,
284,
315,
1425,
8,
22,
304,
288,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
284,
9,
398,
286,
14,
6814,
8,
19,
9,
398,
327,
17555,
83,
5341,
315,
314,
1865,
2985,
4898,
7264,
14,
267,
291,
14,
629,
8,
513,
8,
1842,
8,
19,
1826,
291,
14,
5570,
9,
267,
286,
14,
6814,
8,
17,
9,
267,
291,
14,
629,
8,
513,
8,
1842,
8,
20,
1826,
291,
14,
5570,
9,
267,
286,
14,
6814,
8,
18,
9,
267,
291,
14,
629,
8,
513,
8,
1842,
8,
22,
1826,
291,
14,
5570,
9,
339,
347,
511,
63,
6814,
63,
452,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
367,
284,
315,
1425,
8,
20,
304,
288,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
284,
9,
398,
286,
14,
6814,
63,
452,
342,
267,
291,
14,
5570,
14,
740,
360,
6814,
63,
452,
358,
398,
327,
17555,
83,
5341,
315,
314,
1865,
2985,
4898,
7264,
14,
267,
291,
14,
629,
8,
288,
769,
8,
1842,
8,
20,
430,
435,
788,
6814,
63,
452,
995,
288,
291,
14,
5570,
9,
339,
768,
2268,
63,
396,
272,
347,
511,
63,
2573,
63,
2593,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
3618,
275,
286,
14,
2573,
8,
7473,
8,
4515,
29,
16,
14,
614,
430,
267,
291,
14,
2308,
63,
3813,
14,
1250,
63,
18103,
8,
16,
14,
996,
12,
286,
14,
6814,
9,
221,
327,
22893,
2465,
14,
267,
1995,
3805,
14,
4532,
8,
16,
14,
1644,
9,
267,
291,
14,
3334,
1332,
11481,
3618,
430,
339,
768,
2268,
63,
396,
272,
347,
511,
63,
2573,
63,
2593,
63,
657,
2109,
471,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
398,
327,
961,
28887,
2544,
314,
3618,
5431,
734,
14,
267,
291,
14,
2308,
63,
3813,
14,
1250,
63,
18103,
8,
16,
14,
614,
12,
286,
14,
6814,
9,
267,
3618,
275,
286,
14,
2573,
8,
7473,
8,
4515,
29,
16,
14,
996,
430,
267,
1995,
3805,
14,
4532,
8,
16,
14,
1644,
9,
267,
1995,
3618,
221,
327,
3091,
31886,
14,
339,
768,
2268,
63,
396,
272,
347,
511,
63,
6814,
63,
78,
63,
1045,
63,
2593,
8,
277,
304,
267,
327,
11828,
13484,
378,
12,
413,
12,
499,
12,
436,
650,
14,
17555,
413,
965,
282,
2653,
14,
267,
327,
13144,
367,
626,
2653,
370,
16667,
12,
2066,
886,
11705,
8,
18,
9,
436,
1852,
267,
327,
3238,
4036,
368,
7858,
14,
26114,
626,
282,
18590,
13,
548,
3233,
1630,
267,
327,
440,
2338,
6169,
314,
283,
78,
7,
1423,
370,
11705,
1252,
267,
286,
275,
23340,
14,
9558,
342,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
378,
9,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
8,
7473,
8,
4515,
29,
16,
14,
614,
1826,
413,
9,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
499,
9,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
650,
9,
398,
327,
13144,
367,
3233,
413,
370,
900,
734,
14
] |
[
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,
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,
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,
504,
2197,
492,
6871,
199,
199,
504,
12148,
492,
3805,
12,
23340,
199,
504,
12148,
14,
2268,
492,
31886,
199,
504,
12148,
14,
4776,
492,
3805,
63,
396,
12,
15223,
1746,
199,
504,
12148,
14,
396,
14,
1974,
492,
2882,
421,
199,
533,
28401,
774,
8,
12807,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
9558,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
5570,
275,
942,
339,
347,
2777,
63,
4456,
8,
277,
12,
6466,
12,
790,
304,
267,
408,
5433,
314,
12401,
402,
282,
20799,
2138,
701,
28401,
14,
2573,
1041,
267,
347,
3233,
1547,
304,
288,
340,
440,
6466,
14,
1099,
837,
355,
327,
3618,
342,
12152,
370,
756,
12,
11150,
652,
18590,
734,
14,
355,
291,
14,
5570,
14,
740,
360,
2593,
358,
288,
587,
26,
355,
291,
14,
5570,
14,
740,
8,
498,
9,
267,
6466,
14,
525,
63,
4456,
63,
3058,
8,
3058,
9,
339,
347,
511,
63,
2722,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
291,
14,
4080,
360,
9558,
297,
4700,
8,
67,
430,
267,
291,
14,
8795,
360,
758,
15266,
297,
4700,
8,
67,
430,
267,
286,
14,
2573,
342,
267,
291,
14,
4080,
360,
758,
15266,
297,
4700,
8,
67,
430,
339,
768,
2268,
63,
396,
272,
347,
511,
63,
6814,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
291,
14,
2308,
63,
3813,
14,
1250,
63,
18103,
8,
16,
14,
614,
12,
286,
14,
6814,
9,
267,
1995,
286,
14,
2573,
342,
339,
347,
511,
63,
6814,
63,
17,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
283,
2573,
17,
358,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
283,
2573,
18,
358,
267,
286,
14,
6814,
8,
17,
9,
267,
291,
14,
5570,
14,
740,
360,
6814,
17,
358,
267,
286,
14,
6814,
8,
17,
9,
267,
291,
14,
5570,
14,
740,
360,
6814,
18,
358,
267,
291,
14,
629,
2941,
2573,
17,
297,
283,
6814,
17,
297,
283,
2573,
18,
297,
283,
6814,
18,
995,
586,
291,
14,
5570,
9,
339,
347,
511,
63,
6814,
63,
78,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
367,
284,
315,
1425,
8,
22,
304,
288,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
284,
9,
398,
286,
14,
6814,
8,
19,
9,
398,
327,
17555,
83,
5341,
315,
314,
1865,
2985,
4898,
7264,
14,
267,
291,
14,
629,
8,
513,
8,
1842,
8,
19,
1826,
291,
14,
5570,
9,
267,
286,
14,
6814,
8,
17,
9,
267,
291,
14,
629,
8,
513,
8,
1842,
8,
20,
1826,
291,
14,
5570,
9,
267,
286,
14,
6814,
8,
18,
9,
267,
291,
14,
629,
8,
513,
8,
1842,
8,
22,
1826,
291,
14,
5570,
9,
339,
347,
511,
63,
6814,
63,
452,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
367,
284,
315,
1425,
8,
20,
304,
288,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
284,
9,
398,
286,
14,
6814,
63,
452,
342,
267,
291,
14,
5570,
14,
740,
360,
6814,
63,
452,
358,
398,
327,
17555,
83,
5341,
315,
314,
1865,
2985,
4898,
7264,
14,
267,
291,
14,
629,
8,
288,
769,
8,
1842,
8,
20,
430,
435,
788,
6814,
63,
452,
995,
288,
291,
14,
5570,
9,
339,
768,
2268,
63,
396,
272,
347,
511,
63,
2573,
63,
2593,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
267,
3618,
275,
286,
14,
2573,
8,
7473,
8,
4515,
29,
16,
14,
614,
430,
267,
291,
14,
2308,
63,
3813,
14,
1250,
63,
18103,
8,
16,
14,
996,
12,
286,
14,
6814,
9,
221,
327,
22893,
2465,
14,
267,
1995,
3805,
14,
4532,
8,
16,
14,
1644,
9,
267,
291,
14,
3334,
1332,
11481,
3618,
430,
339,
768,
2268,
63,
396,
272,
347,
511,
63,
2573,
63,
2593,
63,
657,
2109,
471,
8,
277,
304,
267,
286,
275,
23340,
14,
9558,
342,
398,
327,
961,
28887,
2544,
314,
3618,
5431,
734,
14,
267,
291,
14,
2308,
63,
3813,
14,
1250,
63,
18103,
8,
16,
14,
614,
12,
286,
14,
6814,
9,
267,
3618,
275,
286,
14,
2573,
8,
7473,
8,
4515,
29,
16,
14,
996,
430,
267,
1995,
3805,
14,
4532,
8,
16,
14,
1644,
9,
267,
1995,
3618,
221,
327,
3091,
31886,
14,
339,
768,
2268,
63,
396,
272,
347,
511,
63,
6814,
63,
78,
63,
1045,
63,
2593,
8,
277,
304,
267,
327,
11828,
13484,
378,
12,
413,
12,
499,
12,
436,
650,
14,
17555,
413,
965,
282,
2653,
14,
267,
327,
13144,
367,
626,
2653,
370,
16667,
12,
2066,
886,
11705,
8,
18,
9,
436,
1852,
267,
327,
3238,
4036,
368,
7858,
14,
26114,
626,
282,
18590,
13,
548,
3233,
1630,
267,
327,
440,
2338,
6169,
314,
283,
78,
7,
1423,
370,
11705,
1252,
267,
286,
275,
23340,
14,
9558,
342,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
378,
9,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
8,
7473,
8,
4515,
29,
16,
14,
614,
1826,
413,
9,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
499,
9,
267,
291,
14,
3059,
63,
4456,
8,
67,
14,
2573,
1062,
650,
9,
398,
327,
13144,
367,
3233,
413,
370,
900,
734,
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,
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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
] |
adiyengar/Spirit
|
spirit/topic/poll/forms.py
|
7
|
5605
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
from django.forms.models import inlineformset_factory, BaseInlineFormSet
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_text
from django.core.exceptions import ValidationError
from .models import TopicPollChoice, TopicPoll, TopicPollVote
class TopicPollForm(forms.ModelForm):
class Meta:
model = TopicPoll
fields = ['choice_limit', ]
def __init__(self, topic=None, *args, **kwargs):
super(TopicPollForm, self).__init__(*args, **kwargs)
self.topic = topic
def clean_choice_limit(self):
choice_limit = self.cleaned_data['choice_limit']
if choice_limit < 1:
raise forms.ValidationError(_("Choice's limit must be greater than zero"))
return choice_limit
def save(self, commit=True):
if not self.instance.pk:
self.instance.topic = self.topic
return super(TopicPollForm, self).save(commit)
class TopicPollChoiceForm(forms.ModelForm):
class Meta:
model = TopicPollChoice
fields = ['description', ]
def is_filled(self):
description = self.cleaned_data.get('description')
is_marked_as_delete = self.cleaned_data.get('DELETE', False)
if description and not is_marked_as_delete:
return True
return False
class TopicPollChoiceInlineFormSet(BaseInlineFormSet):
def __init__(self, can_delete=None, *args, **kwargs):
super(TopicPollChoiceInlineFormSet, self).__init__(*args, **kwargs)
self._is_filled_cache = None
if can_delete is not None:
# Adds the *delete* checkbox or not
self.can_delete = can_delete
def _is_filled(self):
if self.instance.pk:
return True
return any([form.is_filled() for form in self.forms])
def is_filled(self):
if self._is_filled_cache is None:
self._is_filled_cache = self._is_filled()
return self._is_filled_cache
def has_errors(self):
return any(self.errors) or self.non_form_errors()
def clean(self):
# Stores in formset.non_field_errors
super(TopicPollChoiceInlineFormSet, self).clean()
if not self.is_filled():
return
forms_filled = [form for form in self.forms if form.is_filled()]
if len(forms_filled) < 2:
raise ValidationError(_("There must be 2 or more choices"))
def save(self, commit=True):
if not self.is_filled():
raise Exception("You should check and save if is_filled is True")
return super(TopicPollChoiceInlineFormSet, self).save(commit=commit)
TopicPollChoiceFormSet = inlineformset_factory(TopicPollForm._meta.model, TopicPollChoiceForm._meta.model,
form=TopicPollChoiceForm, formset=TopicPollChoiceInlineFormSet,
max_num=20, validate_max=True, extra=2)
class TopicPollVoteManyForm(forms.Form):
"""
This special form allows single vote and multi vote as well.
Its beauty is that it doesn't care if the choice_limit is increased or decreased later.
"""
def __init__(self, user=None, poll=None, *args, **kwargs):
super(TopicPollVoteManyForm, self).__init__(*args, **kwargs)
self.user = user
self.poll = poll
choices = TopicPollChoice.objects.filter(poll=poll)
if poll.is_multiple_choice:
self.fields['choices'] = forms.ModelMultipleChoiceField(queryset=choices,
widget=forms.CheckboxSelectMultiple,
label=_("Poll choices"))
else:
self.fields['choices'] = forms.ModelChoiceField(queryset=choices,
widget=forms.RadioSelect,
label=_("Poll choices"),
empty_label=None)
self.fields['choices'].label_from_instance = lambda obj: smart_text(obj.description)
def load_initial(self):
selected_choices = list(TopicPollChoice.objects.filter(poll=self.poll, votes__user=self.user))
if not selected_choices:
return
if not self.poll.is_multiple_choice:
selected_choices = selected_choices[0]
self.initial = {'choices': selected_choices, }
def clean_choices(self):
choices = self.cleaned_data['choices']
if (self.poll.is_multiple_choice and
len(choices) > self.poll.choice_limit):
raise forms.ValidationError(_("Too many selected choices. Limit is %s")
% self.poll.choice_limit)
return choices
def clean(self):
cleaned_data = super(TopicPollVoteManyForm, self).clean()
if self.poll.is_closed:
raise forms.ValidationError(_("This poll is closed"))
return cleaned_data
def save_m2m(self):
choices = self.cleaned_data['choices']
if not self.poll.is_multiple_choice:
choices = [choices, ]
TopicPollVote.objects.filter(user=self.user, choice__poll=self.poll)\
.delete()
return TopicPollVote.objects.bulk_create([TopicPollVote(user=self.user, choice=choice)
for choice in choices])
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
3351,
14,
992,
492,
8308,
10724,
63,
3702,
12,
3523,
10307,
14736,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
505,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
199,
504,
1275,
992,
492,
32166,
24022,
9054,
12,
32166,
24022,
12,
32166,
24022,
54,
1583,
421,
199,
533,
32166,
24022,
2821,
8,
3351,
14,
15937,
304,
339,
1021,
6288,
26,
267,
1402,
275,
32166,
24022,
267,
1504,
275,
788,
5095,
63,
3097,
297,
1622,
339,
347,
636,
826,
721,
277,
12,
7482,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
12157,
24022,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
5746,
275,
7482,
339,
347,
3633,
63,
5095,
63,
3097,
8,
277,
304,
267,
7141,
63,
3097,
275,
291,
14,
8275,
63,
576,
459,
5095,
63,
3097,
418,
398,
340,
7141,
63,
3097,
665,
413,
26,
288,
746,
4513,
14,
8172,
6115,
9054,
1159,
2304,
1471,
506,
8932,
2419,
4697,
2237,
398,
372,
7141,
63,
3097,
339,
347,
3354,
8,
277,
12,
5532,
29,
549,
304,
267,
340,
440,
291,
14,
842,
14,
2051,
26,
288,
291,
14,
842,
14,
5746,
275,
291,
14,
5746,
398,
372,
1613,
8,
12157,
24022,
2821,
12,
291,
680,
2117,
8,
3543,
9,
421,
199,
533,
32166,
24022,
9054,
2821,
8,
3351,
14,
15937,
304,
339,
1021,
6288,
26,
267,
1402,
275,
32166,
24022,
9054,
267,
1504,
275,
788,
1802,
297,
1622,
339,
347,
365,
63,
17647,
8,
277,
304,
267,
1369,
275,
291,
14,
8275,
63,
576,
14,
362,
360,
1802,
358,
267,
365,
63,
17938,
63,
305,
63,
1807,
275,
291,
14,
8275,
63,
576,
14,
362,
360,
7014,
297,
756,
9,
398,
340,
1369,
436,
440,
365,
63,
17938,
63,
305,
63,
1807,
26,
288,
372,
715,
398,
372,
756,
421,
199,
533,
32166,
24022,
9054,
10307,
14736,
8,
1563,
10307,
14736,
304,
339,
347,
636,
826,
721,
277,
12,
883,
63,
1807,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
12157,
24022,
9054,
10307,
14736,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
423,
374,
63,
17647,
63,
1637,
275,
488,
398,
340,
883,
63,
1807,
365,
440,
488,
26,
288,
327,
15747,
314,
627,
1807,
10,
24190,
503,
440,
288,
291,
14,
2425,
63,
1807,
275,
883,
63,
1807,
339,
347,
485,
374,
63,
17647,
8,
277,
304,
267,
340,
291,
14,
842,
14,
2051,
26,
288,
372,
715,
398,
372,
1263,
779,
964,
14,
374,
63,
17647,
342,
367,
1824,
315,
291,
14,
3351,
566,
339,
347,
365,
63,
17647,
8,
277,
304,
267,
340,
291,
423,
374,
63,
17647,
63,
1637,
365,
488,
26,
288,
291,
423,
374,
63,
17647,
63,
1637,
275,
291,
423,
374,
63,
17647,
342,
398,
372,
291,
423,
374,
63,
17647,
63,
1637,
339,
347,
965,
63,
2550,
8,
277,
304,
267,
372,
1263,
8,
277,
14,
2550,
9,
503,
291,
14,
2865,
63,
964,
63,
2550,
342,
339,
347,
3633,
8,
277,
304,
267,
327,
31299,
315,
11068,
14,
2865,
63,
698,
63,
2550,
267,
1613,
8,
12157,
24022,
9054,
10307,
14736,
12,
291,
680,
3118,
342,
398,
340,
440,
291,
14,
374,
63,
17647,
837,
288,
372,
398,
4513,
63,
17647,
275,
359,
964,
367,
1824,
315,
291,
14,
3351,
340,
1824,
14,
374,
63,
17647,
5106,
398,
340,
822,
8,
3351,
63,
17647,
9,
665,
499,
26,
288,
746,
8505,
6115,
10924,
1471,
506,
499,
503,
1655,
3415,
2237,
339,
347,
3354,
8,
277,
12,
5532,
29,
549,
304,
267,
340,
440,
291,
14,
374,
63,
17647,
837,
288,
746,
2186,
480,
5556,
1077,
1104,
436,
3354,
340,
365,
63,
17647,
365,
715,
531,
398,
372,
1613,
8,
12157,
24022,
9054,
10307,
14736,
12,
291,
680,
2117,
8,
3543,
29,
3543,
9,
421,
199,
12157,
24022,
9054,
14736,
275,
8308,
10724,
63,
3702,
8,
12157,
24022,
2821,
423,
2024,
14,
1238,
12,
32166,
24022,
9054,
2821,
423,
2024,
14,
1238,
12,
6901,
1824,
29,
12157,
24022,
9054,
2821,
12,
11068,
29,
12157,
24022,
9054,
10307,
14736,
12,
6901,
1390,
63,
1507,
29,
1165,
12,
4107,
63,
988,
29,
549,
12,
2402,
29,
18,
9,
421,
199,
533,
32166,
24022,
54,
1583,
4089,
2821,
8,
3351,
14,
2821,
304,
272,
408,
272,
961,
4539,
1824,
6127,
2849,
24337,
436,
3510,
24337,
465,
5521,
14,
272,
22940,
506,
6898,
89,
365,
626,
652,
3181,
1133,
10296,
340,
314,
7141,
63,
3097,
365,
10035,
11185,
503,
477,
1353,
11185,
2945,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
922,
29,
403,
12,
11271,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
12157,
24022,
54,
1583,
4089,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
751,
275,
922,
267,
291,
14,
6843,
275,
11271,
267,
3415,
275,
32166,
24022,
9054,
14,
1462,
14,
1541,
8,
6843,
29,
6843,
9,
398,
340,
11271,
14,
374,
63,
6048,
63,
5095,
26,
288,
291,
14,
955,
459,
4577,
418,
275,
4513,
14,
1685,
8433,
15792,
8,
7924,
29,
4577,
12,
25405,
3938,
29,
3351,
14,
26366,
32331,
12,
25405,
1768,
9384,
24022,
3415,
2237,
267,
587,
26,
288,
291,
14,
955,
459,
4577,
418,
275,
4513,
14,
1685,
15792,
8,
7924,
29,
4577,
12,
14663,
3938,
29,
3351,
14,
16065,
5446,
12,
14663,
1768,
9384,
24022,
3415,
1288,
14663,
2701,
63,
1302,
29,
403,
9,
398,
291,
14,
955,
459,
4577,
2278,
1302,
63,
504,
63,
842,
275,
2400,
1559,
26,
11179,
63,
505,
8,
1113,
14,
1802,
9,
339,
347,
2248,
63,
2747,
8,
277,
304,
267,
4895,
63,
4577,
275,
769,
8,
12157,
24022,
9054,
14,
1462,
14,
1541,
8,
6843,
29,
277,
14,
6843,
12,
373,
6510,
363,
751,
29,
277,
14,
751,
430,
398,
340,
440,
4895,
63,
4577,
26,
288,
372,
398,
340,
440,
291,
14,
6843,
14,
374,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
3351,
14,
992,
492,
8308,
10724,
63,
3702,
12,
3523,
10307,
14736,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
505,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
199,
504,
1275,
992,
492,
32166,
24022,
9054,
12,
32166,
24022,
12,
32166,
24022,
54,
1583,
421,
199,
533,
32166,
24022,
2821,
8,
3351,
14,
15937,
304,
339,
1021,
6288,
26,
267,
1402,
275,
32166,
24022,
267,
1504,
275,
788,
5095,
63,
3097,
297,
1622,
339,
347,
636,
826,
721,
277,
12,
7482,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
12157,
24022,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
5746,
275,
7482,
339,
347,
3633,
63,
5095,
63,
3097,
8,
277,
304,
267,
7141,
63,
3097,
275,
291,
14,
8275,
63,
576,
459,
5095,
63,
3097,
418,
398,
340,
7141,
63,
3097,
665,
413,
26,
288,
746,
4513,
14,
8172,
6115,
9054,
1159,
2304,
1471,
506,
8932,
2419,
4697,
2237,
398,
372,
7141,
63,
3097,
339,
347,
3354,
8,
277,
12,
5532,
29,
549,
304,
267,
340,
440,
291,
14,
842,
14,
2051,
26,
288,
291,
14,
842,
14,
5746,
275,
291,
14,
5746,
398,
372,
1613,
8,
12157,
24022,
2821,
12,
291,
680,
2117,
8,
3543,
9,
421,
199,
533,
32166,
24022,
9054,
2821,
8,
3351,
14,
15937,
304,
339,
1021,
6288,
26,
267,
1402,
275,
32166,
24022,
9054,
267,
1504,
275,
788,
1802,
297,
1622,
339,
347,
365,
63,
17647,
8,
277,
304,
267,
1369,
275,
291,
14,
8275,
63,
576,
14,
362,
360,
1802,
358,
267,
365,
63,
17938,
63,
305,
63,
1807,
275,
291,
14,
8275,
63,
576,
14,
362,
360,
7014,
297,
756,
9,
398,
340,
1369,
436,
440,
365,
63,
17938,
63,
305,
63,
1807,
26,
288,
372,
715,
398,
372,
756,
421,
199,
533,
32166,
24022,
9054,
10307,
14736,
8,
1563,
10307,
14736,
304,
339,
347,
636,
826,
721,
277,
12,
883,
63,
1807,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
12157,
24022,
9054,
10307,
14736,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
423,
374,
63,
17647,
63,
1637,
275,
488,
398,
340,
883,
63,
1807,
365,
440,
488,
26,
288,
327,
15747,
314,
627,
1807,
10,
24190,
503,
440,
288,
291,
14,
2425,
63,
1807,
275,
883,
63,
1807,
339,
347,
485,
374,
63,
17647,
8,
277,
304,
267,
340,
291,
14,
842,
14,
2051,
26,
288,
372,
715,
398,
372,
1263,
779,
964,
14,
374,
63,
17647,
342,
367,
1824,
315,
291,
14,
3351,
566,
339,
347,
365,
63,
17647,
8,
277,
304,
267,
340,
291,
423,
374,
63,
17647,
63,
1637,
365,
488,
26,
288,
291,
423,
374,
63,
17647,
63,
1637,
275,
291,
423,
374,
63,
17647,
342,
398,
372,
291,
423,
374,
63,
17647,
63,
1637,
339,
347,
965,
63,
2550,
8,
277,
304,
267,
372,
1263,
8,
277,
14,
2550,
9,
503,
291,
14,
2865,
63,
964,
63,
2550,
342,
339,
347,
3633,
8,
277,
304,
267,
327,
31299,
315,
11068,
14,
2865,
63,
698,
63,
2550,
267,
1613,
8,
12157,
24022,
9054,
10307,
14736,
12,
291,
680,
3118,
342,
398,
340,
440,
291,
14,
374,
63,
17647,
837,
288,
372,
398,
4513,
63,
17647,
275,
359,
964,
367,
1824,
315,
291,
14,
3351,
340,
1824,
14,
374,
63,
17647,
5106,
398,
340,
822,
8,
3351,
63,
17647,
9,
665,
499,
26,
288,
746,
8505,
6115,
10924,
1471,
506,
499,
503,
1655,
3415,
2237,
339,
347,
3354,
8,
277,
12,
5532,
29,
549,
304,
267,
340,
440,
291,
14,
374,
63,
17647,
837,
288,
746,
2186,
480,
5556,
1077,
1104,
436,
3354,
340,
365,
63,
17647,
365,
715,
531,
398,
372,
1613,
8,
12157,
24022,
9054,
10307,
14736,
12,
291,
680,
2117,
8,
3543,
29,
3543,
9,
421,
199,
12157,
24022,
9054,
14736,
275,
8308,
10724,
63,
3702,
8,
12157,
24022,
2821,
423,
2024,
14,
1238,
12,
32166,
24022,
9054,
2821,
423,
2024,
14,
1238,
12,
6901,
1824,
29,
12157,
24022,
9054,
2821,
12,
11068,
29,
12157,
24022,
9054,
10307,
14736,
12,
6901,
1390,
63,
1507,
29,
1165,
12,
4107,
63,
988,
29,
549,
12,
2402,
29,
18,
9,
421,
199,
533,
32166,
24022,
54,
1583,
4089,
2821,
8,
3351,
14,
2821,
304,
272,
408,
272,
961,
4539,
1824,
6127,
2849,
24337,
436,
3510,
24337,
465,
5521,
14,
272,
22940,
506,
6898,
89,
365,
626,
652,
3181,
1133,
10296,
340,
314,
7141,
63,
3097,
365,
10035,
11185,
503,
477,
1353,
11185,
2945,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
922,
29,
403,
12,
11271,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
12157,
24022,
54,
1583,
4089,
2821,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
751,
275,
922,
267,
291,
14,
6843,
275,
11271,
267,
3415,
275,
32166,
24022,
9054,
14,
1462,
14,
1541,
8,
6843,
29,
6843,
9,
398,
340,
11271,
14,
374,
63,
6048,
63,
5095,
26,
288,
291,
14,
955,
459,
4577,
418,
275,
4513,
14,
1685,
8433,
15792,
8,
7924,
29,
4577,
12,
25405,
3938,
29,
3351,
14,
26366,
32331,
12,
25405,
1768,
9384,
24022,
3415,
2237,
267,
587,
26,
288,
291,
14,
955,
459,
4577,
418,
275,
4513,
14,
1685,
15792,
8,
7924,
29,
4577,
12,
14663,
3938,
29,
3351,
14,
16065,
5446,
12,
14663,
1768,
9384,
24022,
3415,
1288,
14663,
2701,
63,
1302,
29,
403,
9,
398,
291,
14,
955,
459,
4577,
2278,
1302,
63,
504,
63,
842,
275,
2400,
1559,
26,
11179,
63,
505,
8,
1113,
14,
1802,
9,
339,
347,
2248,
63,
2747,
8,
277,
304,
267,
4895,
63,
4577,
275,
769,
8,
12157,
24022,
9054,
14,
1462,
14,
1541,
8,
6843,
29,
277,
14,
6843,
12,
373,
6510,
363,
751,
29,
277,
14,
751,
430,
398,
340,
440,
4895,
63,
4577,
26,
288,
372,
398,
340,
440,
291,
14,
6843,
14,
374,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jwhui/openthread
|
tests/scripts/thread-cert/pktverify/layer_fields.py
|
3
|
26574
|
#!/usr/bin/env python3
#
# Copyright (c) 2019, The OpenThread Authors.
# 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.
#
import datetime
import sys
import time
from typing import Any, Union
from pyshark.packet.fields import LayerFieldsContainer, LayerField
from pyshark.packet.packet import Packet as RawPacket
from pktverify.addrs import EthAddr, ExtAddr, Ipv6Addr
from pktverify.bytes import Bytes
from pktverify.consts import VALID_LAYER_NAMES
from pktverify.null_field import nullField
def _auto(v: Union[LayerFieldsContainer, LayerField]):
"""parse the layer field automatically according to its format"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1 or v.get_default_value() is not None, v.fields
dv = v.get_default_value()
rv = v.raw_value
if dv.startswith('0x'):
return int(dv, 16)
try:
if dv == rv:
return int(dv)
elif int(dv) == int(rv, 16):
return int(dv)
except (ValueError, TypeError):
pass
if rv is None:
try:
return int(dv)
except (ValueError, TypeError):
pass
if ':' in dv and '::' not in dv and dv.replace(':', '') == rv: # '88:00', '8800'
return int(rv, 16)
# timestamp: 'Jan 1, 1970 08:00:00.000000000 CST', '0000000000000000'
# convert to seconds from 1970, ignore the nanosecond for now since
# there are integer seconds applied in the test cases
try:
time_str = datetime.datetime.strptime(dv, "%b %d, %Y %H:%M:%S.%f000 %Z")
time_in_sec = time.mktime(time_str.utctimetuple())
return int(time_in_sec)
except (ValueError, TypeError):
pass
try:
int(rv, 16)
return int(dv)
except Exception:
pass
raise ValueError((v, v.get_default_value(), v.raw_value))
def _payload(v: Union[LayerFieldsContainer, LayerField]) -> bytearray:
"""parse the layer field as a bytearray"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
hex_value = v.raw_value
assert len(hex_value) % 2 == 0
s = bytearray()
for i in range(0, len(hex_value), 2):
s.append(int(hex_value[i:i + 2], 16))
return s
def _hex(v: Union[LayerFieldsContainer, LayerField]) -> int:
"""parse the layer field as a hex string"""
# split v into octets and reverse the order
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
return int(v.get_default_value(), 16)
def _raw_hex(v: Union[LayerFieldsContainer, LayerField]) -> int:
"""parse the layer field as a raw hex string"""
# split v into octets and reverse the order
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
iv = v.hex_value
try:
int(v.get_default_value())
assert int(v.get_default_value()) == iv, (v.get_default_value(), v.raw_value)
except ValueError:
pass
try:
int(v.get_default_value(), 16)
assert int(v.get_default_value(), 16) == iv, (v.get_default_value(), v.raw_value)
except ValueError:
pass
return iv
def _raw_hex_rev(v: Union[LayerFieldsContainer, LayerField]) -> int:
"""parse the layer field as a reversed raw hex string"""
# split v into octets and reverse the order
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
rv = v.raw_value
octets = [rv[i:i + 2] for i in range(0, len(rv), 2)]
iv = int(''.join(reversed(octets)), 16)
try:
int(v.get_default_value())
assert int(v.get_default_value()) == iv, (v.get_default_value(), v.raw_value)
except ValueError:
pass
try:
int(v.get_default_value(), 16)
assert int(v.get_default_value(), 16) == iv, (v.get_default_value(), v.raw_value)
except ValueError:
pass
return iv
def _dec(v: Union[LayerFieldsContainer, LayerField]) -> int:
"""parse the layer field as a decimal"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
return int(v.get_default_value())
def _float(v: Union[LayerFieldsContainer, LayerField]) -> float:
"""parse the layer field as a float"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
return float(v.get_default_value())
def _str(v: Union[LayerFieldsContainer, LayerField]) -> str:
"""parse the layer field as a string"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
return str(v.get_default_value())
def _bytes(v: Union[LayerFieldsContainer, LayerField]) -> Bytes:
"""parse the layer field as raw bytes"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
return Bytes(v.raw_value)
def _ext_addr(v: Union[LayerFieldsContainer, LayerField]) -> ExtAddr:
"""parse the layer field as an extended address"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
return ExtAddr(v.get_default_value())
def _ipv6_addr(v: Union[LayerFieldsContainer, LayerField]) -> Ipv6Addr:
"""parse the layer field as an IPv6 address"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
return Ipv6Addr(v.get_default_value())
def _eth_addr(v: Union[LayerFieldsContainer, LayerField]) -> EthAddr:
"""parse the layer field as an Ethernet MAC address"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1, v.fields
return EthAddr(v.get_default_value())
def _routerid_set(v: Union[LayerFieldsContainer, LayerField]) -> set:
"""parse the layer field as a set of router ids
Notes: the router ID mask in wireshark is a
hexadecimal string separated by ':'
"""
assert not isinstance(v, LayerFieldsContainer) or len(v.fields) == 1
try:
ridmask = str(v.get_default_value())
assert isinstance(ridmask, str), ridmask
ridmask_int = int(ridmask.replace(':', ''), base=16)
rid_set = set()
count = 0
while ridmask_int:
count += 1
if ridmask_int & 1:
rid_set.add(64 - count)
ridmask_int = ridmask_int >> 1
except ValueError:
pass
return rid_set
class _first(object):
"""parse the first layer field"""
def __init__(self, sub_parse):
self._sub_parse = sub_parse
def __call__(self, v: Union[LayerFieldsContainer, LayerField]):
return self._sub_parse(v.fields[0])
class _list(object):
"""parse all layer fields into a list"""
def __init__(self, sub_parse):
self._sub_parse = sub_parse
def __call__(self, v: Union[LayerFieldsContainer, LayerField]):
return [self._sub_parse(f) for f in v.fields]
_LAYER_FIELDS = {
# WPAN
'wpan.fcf': _raw_hex_rev,
'wpan.cmd': _auto,
'wpan.security': _auto,
'wpan.frame_type': _auto,
'wpan.pending': _auto,
'wpan.ack_request': _auto,
'wpan.pan_id_compression': _auto,
'wpan.seqno_suppression': _auto,
'wpan.ie_present': _auto,
'wpan.dst_addr_mode': _auto,
'wpan.version': _auto,
'wpan.src_addr_mode': _auto,
'wpan.dst_pan': _auto,
'wpan.seq_no': _auto,
'wpan.src16': _auto,
'wpan.dst16': _auto,
'wpan.src64': _ext_addr,
'wpan.dst64': _ext_addr,
'wpan.fcs': _raw_hex_rev,
'wpan.fcs_ok': _auto,
'wpan.frame_length': _dec,
'wpan.key_number': _auto,
'wpan.aux_sec.sec_suite': _auto,
'wpan.aux_sec.security_control_field': _auto,
'wpan.aux_sec.sec_level': _auto,
'wpan.aux_sec.key_id_mode': _auto,
'wpan.aux_sec.frame_counter_suppression': _auto,
'wpan.aux_sec.asn_in_nonce': _auto,
'wpan.aux_sec.reserved': _auto,
'wpan.aux_sec.frame_counter': _auto,
'wpan.aux_sec.key_source': _auto,
'wpan.aux_sec.key_index': _auto,
'wpan.aux_sec.hdr': _str,
'wpan.mic': _auto,
'wpan.channel': _auto,
'wpan.header_ie.id': _list(_auto),
'wpan.header_ie.csl.period': _auto,
'wpan.payload_ie.vendor.oui': _auto,
# MLE
'mle.cmd': _auto,
'mle.sec_suite': _hex,
'mle.tlv.type': _list(_dec),
'mle.tlv.len': _list(_dec),
'mle.tlv.mode.receiver_on_idle': _auto,
'mle.tlv.mode.reserved1': _auto,
'mle.tlv.mode.reserved2': _auto,
'mle.tlv.mode.device_type_bit': _auto,
'mle.tlv.mode.network_data': _auto,
'mle.tlv.challenge': _bytes,
'mle.tlv.scan_mask.r': _auto,
'mle.tlv.scan_mask.e': _auto,
'mle.tlv.version': _auto,
'mle.tlv.source_addr': _auto,
'mle.tlv.active_tstamp': _auto,
'mle.tlv.pending_tstamp': _auto,
'mle.tlv.leader_data.partition_id': _auto,
'mle.tlv.leader_data.weighting': _auto,
'mle.tlv.leader_data.data_version': _auto,
'mle.tlv.leader_data.stable_data_version': _auto,
'mle.tlv.leader_data.router_id': _auto,
'mle.tlv.route64.nbr_out': _list(_auto),
'mle.tlv.route64.nbr_in': _list(_auto),
'mle.tlv.route64.id_seq': _auto,
'mle.tlv.route64.id_mask': _routerid_set,
'mle.tlv.route64.cost': _list(_auto),
'mle.tlv.response': _bytes,
'mle.tlv.mle_frm_cntr': _auto,
'mle.tlv.ll_frm_cntr': _auto,
'mle.tlv.link_margin': _auto,
'mle.tlv.conn.sed_dgram_cnt': _auto,
'mle.tlv.conn.sed_buf_size': _auto,
'mle.tlv.conn.lq3': _auto,
'mle.tlv.conn.lq2': _auto,
'mle.tlv.conn.lq1': _auto,
'mle.tlv.conn.leader_cost': _auto,
'mle.tlv.conn.id_seq': _auto,
'mle.tlv.conn.flags.pp': _auto,
'mle.tlv.conn.active_rtrs': _auto,
'mle.tlv.timeout': _auto,
'mle.tlv.addr16': _auto,
'mle.tlv.channel': _auto,
'mle.tlv.addr_reg_iid': _list(_auto),
'mle.tlv.link_enh_ack_flags': _auto,
'mle.tlv.link_forward_series': _list(_auto),
'mle.tlv.link_requested_type_id_flags': _list(_hex),
'mle.tlv.link_sub_tlv': _auto,
'mle.tlv.link_status_sub_tlv': _auto,
'mle.tlv.query_id': _auto,
'mle.tlv.metric_type_id_flags.type': _list(_hex),
'mle.tlv.metric_type_id_flags.metric': _list(_hex),
'mle.tlv.metric_type_id_flags.l': _list(_hex),
'mle.tlv.link_requested_type_id_flags': _bytes,
# IP
'ip.version': _auto,
'ip.src': _str,
'ip.src_host': _str,
'ip.dst': _str,
'ip.dst_host': _str,
'ip.ttl': _auto,
'ip.proto': _auto,
'ip.len': _auto,
'ip.id': _auto,
'ip.host': _list(_str),
'ip.hdr_len': _dec,
'ip.frag_offset': _auto,
'ip.flags.rb': _auto,
'ip.flags.mf': _auto,
'ip.flags.df': _auto,
'ip.dsfield.ecn': _auto,
'ip.dsfield.dscp': _auto,
'ip.checksum.status': _auto,
'ip.addr': _list(_str),
'ip.options.routeralert': _bytes,
'ip.opt.type.number': _auto,
'ip.opt.type.copy': _auto,
'ip.opt.type.class': _auto,
'ip.opt.ra': _auto,
'ip.opt.len': _auto,
# UDP
'udp.stream': _auto,
'udp.srcport': _auto,
'udp.dstport': _auto,
'udp.length': _auto,
'udp.port': _list(_dec),
'udp.checksum.status': _auto,
# IPv6
'ipv6.version': _auto,
'ipv6.src': _ipv6_addr,
'ipv6.src_host': _ipv6_addr,
'ipv6.dst': _ipv6_addr,
'ipv6.dst_host': _ipv6_addr,
'ipv6.addr': _list(_ipv6_addr),
'ipv6.tclass.dscp': _auto,
'ipv6.tclass.ecn': _auto,
'ipv6.flow': _auto,
'ipv6.hlim': _auto,
'ipv6.nxt': _auto,
'ipv6.hopopts.len': _auto,
'ipv6.hopopts.nxt': _auto,
'ipv6.hopopts.len_oct': _dec,
'ipv6.host': _list(_ipv6_addr),
'ipv6.plen': _auto,
'ipv6.opt.type.rest': _list(_auto),
'ipv6.opt.type.change': _list(_auto),
'ipv6.opt.type.action': _list(_auto),
'ipv6.opt.router_alert': _auto,
'ipv6.opt.padn': _str,
'ipv6.opt.length': _list(_auto),
'ipv6.opt.mpl.seed_id': _bytes,
'ipv6.opt.mpl.sequence': _auto,
'ipv6.opt.mpl.flag.v': _auto,
'ipv6.opt.mpl.flag.s': _auto,
'ipv6.opt.mpl.flag.rsv': _auto,
'ipv6.opt.mpl.flag.m': _auto,
# Eth
'eth.src': _eth_addr,
'eth.src_resolved': _eth_addr,
'eth.dst': _eth_addr,
'eth.dst_resolved': _eth_addr,
'eth.type': _auto,
'eth.addr': _list(_eth_addr),
'eth.addr_resolved': _list(_eth_addr),
'eth.ig': _list(_auto),
'eth.lg': _list(_auto),
# 6LOWPAN
'6lowpan.src': _ipv6_addr,
'6lowpan.dst': _ipv6_addr,
'6lowpan.udp.src': _auto,
'6lowpan.udp.dst': _auto,
'6lowpan.udp.checksum': _auto,
'6lowpan.frag.offset': _auto,
'6lowpan.frag.tag': _auto,
'6lowpan.frag.size': _auto,
'6lowpan.pattern': _list(_auto),
'6lowpan.hops': _auto,
'6lowpan.padding': _auto,
'6lowpan.next': _auto,
'6lowpan.flow': _auto,
'6lowpan.ecn': _auto,
'6lowpan.iphc.tf': _auto,
'6lowpan.iphc.m': _auto,
'6lowpan.iphc.nh': _auto,
'6lowpan.iphc.hlim': _auto,
'6lowpan.iphc.cid': _auto,
'6lowpan.iphc.sac': _auto,
'6lowpan.iphc.sam': _auto,
'6lowpan.iphc.dac': _auto,
'6lowpan.iphc.dam': _auto,
'6lowpan.iphc.sci': _auto,
'6lowpan.iphc.dci': _auto,
'6lowpan.iphc.sctx.prefix': _ipv6_addr,
'6lowpan.iphc.dctx.prefix': _ipv6_addr,
'6lowpan.mesh.v': _auto,
'6lowpan.nhc.pattern': _list(_auto),
'6lowpan.nhc.udp.checksum': _auto,
'6lowpan.nhc.udp.ports': _auto,
'6lowpan.nhc.ext.nh': _auto,
'6lowpan.nhc.ext.length': _auto,
'6lowpan.nhc.ext.eid': _auto,
'6lowpan.reassembled.length': _auto,
'6lowpan.fragments': _str,
'6lowpan.fragment.count': _auto,
'6lowpan.mesh.orig16': _auto,
'6lowpan.mesh.hops8': _auto,
'6lowpan.mesh.hops': _auto,
'6lowpan.mesh.f': _auto,
'6lowpan.mesh.dest16': _auto,
# ICMPv6
'icmpv6.type': _first(_auto),
'icmpv6.code': _first(_auto),
'icmpv6.checksum': _first(_auto),
'icmpv6.reserved': _raw_hex,
'icmpv6.resptime': _float,
'icmpv6.resp_to': _auto,
'icmpv6.mldr.nb_mcast_records': _auto,
'icmpv6.nd.ra.cur_hop_limit': _auto,
'icmpv6.nd.ns.target_address': _ipv6_addr,
'icmpv6.nd.na.target_address': _ipv6_addr,
'icmpv6.nd.na.flag.s': _auto,
'icmpv6.nd.na.flag.o': _auto,
'icmpv6.nd.na.flag.r': _auto,
'icmpv6.nd.na.flag.rsv': _auto,
'icmpv6.mldr.mar.record_type': _list(_auto),
'icmpv6.mldr.mar.aux_data_len': _list(_auto),
'icmpv6.mldr.mar.nb_sources': _list(_auto),
'icmpv6.mldr.mar.multicast_address': _list(_ipv6_addr),
'icmpv6.opt.type': _list(_auto),
'icmpv6.opt.nonce': _bytes,
'icmpv6.opt.linkaddr': _eth_addr,
'icmpv6.opt.src_linkaddr': _eth_addr,
'icmpv6.opt.target_linkaddr': _eth_addr,
'icmpv6.opt.route_lifetime': _auto,
'icmpv6.opt.route_info.flag.route_preference': _auto,
'icmpv6.opt.route_info.flag.reserved': _auto,
'icmpv6.opt.prefix.valid_lifetime': _auto,
'icmpv6.opt.prefix.preferred_lifetime': _auto,
'icmpv6.opt.prefix.length': _list(_auto),
'icmpv6.opt.prefix.flag.reserved': _auto,
'icmpv6.opt.prefix.flag.r': _auto,
'icmpv6.opt.prefix.flag.l': _auto,
'icmpv6.opt.prefix.flag.a': _auto,
'icmpv6.opt.length': _list(_auto),
'icmpv6.opt.reserved': _str,
'icmpv6.nd.ra.router_lifetime': _auto,
'icmpv6.nd.ra.retrans_timer': _auto,
'icmpv6.nd.ra.reachable_time': _auto,
'icmpv6.nd.ra.flag.rsv': _auto,
'icmpv6.nd.ra.flag.prf': _auto,
'icmpv6.nd.ra.flag.p': _auto,
'icmpv6.nd.ra.flag.o': _auto,
'icmpv6.nd.ra.flag.m': _auto,
'icmpv6.nd.ra.flag.h': _auto,
'icmpv6.echo.sequence_number': _auto,
'icmpv6.echo.identifier': _auto,
'icmpv6.data.len': _auto,
# COAP
'coap.code': _auto,
'coap.version': _auto,
'coap.type': _auto,
'coap.mid': _auto,
'coap.token_len': _auto,
'coap.token': _auto,
'coap.opt.uri_path': _list(_str),
'coap.opt.name': _list(_str),
'coap.opt.length': _list(_auto),
'coap.opt.uri_path_recon': _str,
'coap.payload': _payload,
'coap.payload_length': _auto,
'coap.payload_desc': _str,
'coap.opt.end_marker': _auto,
'coap.opt.desc': _list(_str),
'coap.opt.delta': _list(_auto),
'coap.response_to': _auto,
'coap.response_time': _float,
# COAP TLVS
'coap.tlv.type': _list(_auto),
'coap.tlv.status': _auto,
'coap.tlv.target_eid': _ipv6_addr,
'coap.tlv.ml_eid': _ext_addr,
'coap.tlv.last_transaction_time': _auto,
'coap.tlv.rloc16': _auto,
'coap.tlv.net_name': _str,
'coap.tlv.ext_mac_addr': _ext_addr,
'coap.tlv.router_mask_assigned': _auto,
'coap.tlv.router_mask_id_seq': _auto,
# dtls
'dtls.handshake.type': _list(_auto),
'dtls.handshake.cookie': _auto,
'dtls.record.content_type': _list(_auto),
'dtls.alert_message.desc': _auto,
# thread beacon
'thread_bcn.protocol': _auto,
'thread_bcn.version': _auto,
'thread_bcn.network_name': _str,
'thread_bcn.epid': _ext_addr,
# thread_address
'thread_address.tlv.len': _list(_auto),
'thread_address.tlv.type': _list(_auto),
'thread_address.tlv.status': _auto,
'thread_address.tlv.target_eid': _ipv6_addr,
'thread_address.tlv.ext_mac_addr': _ext_addr,
'thread_address.tlv.router_mask_id_seq': _auto,
'thread_address.tlv.router_mask_assigned': _bytes,
'thread_address.tlv.rloc16': _hex,
'thread_address.tlv.target_eid': _ipv6_addr,
'thread_address.tlv.ml_eid': _ext_addr,
# thread bl
'thread_bl.tlv.type': _list(_auto),
'thread_bl.tlv.len': _list(_auto),
'thread_bl.tlv.target_eid': _ipv6_addr,
'thread_bl.tlv.ml_eid': _ext_addr,
'thread_bl.tlv.last_transaction_time': _auto,
'thread_bl.tlv.timeout': _auto,
# THEAD NM
'thread_nm.tlv.type': _list(_auto),
'thread_nm.tlv.ml_eid': _ext_addr,
'thread_nm.tlv.target_eid': _ipv6_addr,
'thread_nm.tlv.status': _auto,
'thread_nm.tlv.timeout': _auto,
# thread_meshcop is not a real layer
'thread_meshcop.len_size_mismatch': _str,
'thread_meshcop.tlv.type': _list(_auto),
'thread_meshcop.tlv.len8': _list(_auto),
'thread_meshcop.tlv.net_name': _list(_str), # from thread_bl
'thread_meshcop.tlv.commissioner_id': _str,
'thread_meshcop.tlv.commissioner_sess_id': _auto, # from mle
"thread_meshcop.tlv.channel_page": _auto, # from ble
"thread_meshcop.tlv.channel": _list(_auto), # from ble
"thread_meshcop.tlv.chan_mask": _str, # from ble
'thread_meshcop.tlv.chan_mask_page': _auto,
'thread_meshcop.tlv.chan_mask_len': _auto,
'thread_meshcop.tlv.chan_mask_mask': _bytes,
'thread_meshcop.tlv.discovery_req_ver': _auto,
'thread_meshcop.tlv.discovery_rsp_ver': _auto,
'thread_meshcop.tlv.discovery_rsp_n': _auto,
'thread_meshcop.tlv.energy_list': _list(_auto),
'thread_meshcop.tlv.pan_id': _list(_auto),
'thread_meshcop.tlv.xpan_id': _bytes,
'thread_meshcop.tlv.ml_prefix': _bytes,
'thread_meshcop.tlv.master_key': _bytes,
'thread_meshcop.tlv.pskc': _bytes,
'thread_meshcop.tlv.sec_policy_rot': _auto,
'thread_meshcop.tlv.sec_policy_o': _auto,
'thread_meshcop.tlv.sec_policy_n': _auto,
'thread_meshcop.tlv.sec_policy_r': _auto,
'thread_meshcop.tlv.sec_policy_c': _auto,
'thread_meshcop.tlv.sec_policy_b': _auto,
'thread_meshcop.tlv.state': _auto,
'thread_meshcop.tlv.steering_data': _bytes,
'thread_meshcop.tlv.unknown': _bytes,
'thread_meshcop.tlv.udp_port': _list(_auto),
'thread_meshcop.tlv.ba_locator': _auto,
'thread_meshcop.tlv.jr_locator': _auto,
'thread_meshcop.tlv.active_tstamp': _auto,
'thread_meshcop.tlv.pending_tstamp': _auto,
'thread_meshcop.tlv.delay_timer': _auto,
'thread_meshcop.tlv.ipv6_addr': _list(_ipv6_addr),
# THREAD NWD
'thread_nwd.tlv.type': _list(_auto),
'thread_nwd.tlv.len': _list(_auto),
'thread_nwd.tlv.stable': _list(_auto),
'thread_nwd.tlv.service.t': _auto,
'thread_nwd.tlv.service.s_id': _auto,
'thread_nwd.tlv.service.s_data_len': _auto,
'thread_nwd.tlv.service.s_data.seqno': _auto,
'thread_nwd.tlv.service.s_data.rrdelay': _auto,
'thread_nwd.tlv.service.s_data.mlrtimeout': _auto,
'thread_nwd.tlv.server_16': _list(_auto),
'thread_nwd.tlv.border_router_16': _list(_auto),
'thread_nwd.tlv.sub_tlvs': _list(_str),
# TODO: support thread_nwd.tlv.prefix.length and thread_nwd.tlv.prefix.domain_id
'thread_nwd.tlv.prefix': _list(_ipv6_addr),
'thread_nwd.tlv.border_router.pref': _auto,
'thread_nwd.tlv.border_router.flag.s': _list(_auto),
'thread_nwd.tlv.border_router.flag.r': _list(_auto),
'thread_nwd.tlv.border_router.flag.p': _list(_auto),
'thread_nwd.tlv.border_router.flag.o': _list(_auto),
'thread_nwd.tlv.border_router.flag.n': _list(_auto),
'thread_nwd.tlv.border_router.flag.dp': _list(_auto),
'thread_nwd.tlv.border_router.flag.d': _list(_auto),
'thread_nwd.tlv.border_router.flag.c': _list(_auto),
'thread_nwd.tlv.6co.flag.reserved': _auto,
'thread_nwd.tlv.6co.flag.cid': _auto,
'thread_nwd.tlv.6co.flag.c': _list(_auto),
'thread_nwd.tlv.6co.context_length': _auto,
# Thread Diagnostic
'thread_diagnostic.tlv.type': _list(_auto),
'thread_diagnostic.tlv.len8': _list(_auto),
'thread_diagnostic.tlv.general': _list(_str)
}
_layer_containers = set()
for key in _LAYER_FIELDS:
assert key.strip() == key and ' ' not in key, key
secs = key.split('.')
assert len(secs) >= 2
assert secs[0] in VALID_LAYER_NAMES, secs[0]
for i in range(len(secs) - 2):
path = secs[0] + '.' + '.'.join(secs[1:i + 2])
assert path not in _LAYER_FIELDS, '%s can not be both field and path' % path
_layer_containers.add(path)
def is_layer_field(uri: str) -> bool:
"""
Returns if the URI is a valid layer field.
:param uri: The layer field URI.
"""
return uri in _LAYER_FIELDS
def is_layer_field_container(uri: str) -> bool:
"""
Returns if the URI is a valid layer field container.
:param uri: The layer field container URI.
"""
return uri in _layer_containers
def get_layer_field(packet: RawPacket, field_uri: str) -> Any:
"""
Get a given layer field from the packet.
:param packet: The packet.
:param field_uri: The layer field URI.
:return: The specified layer field.
"""
assert isinstance(packet, RawPacket)
secs = field_uri.split('.')
layer_depth = 0
layer_name = secs[0]
if layer_name.endswith('inner'):
layer_name = layer_name[:-len('inner')]
field_uri = '.'.join([layer_name] + secs[1:])
layer_depth = 1
if is_layer_field(field_uri):
candidate_layers = _get_candidate_layers(packet, layer_name)
for layers in candidate_layers:
if layer_depth >= len(layers):
continue
layer = layers[layer_depth]
v = layer.get_field(field_uri)
if v is not None:
try:
v = _LAYER_FIELDS[field_uri](v)
print("[%s = %r] " % (field_uri, v), file=sys.stderr)
return v
except Exception as ex:
raise ValueError('can not parse field %s = %r' % (field_uri,
(v.get_default_value(), v.raw_value))) from ex
print("[%s = %s] " % (field_uri, "null"), file=sys.stderr)
return nullField
elif is_layer_field_container(field_uri):
from pktverify.layer_fields_container import LayerFieldsContainer
return LayerFieldsContainer(packet, field_uri)
else:
raise NotImplementedError('Field %s is not valid, please add it to `_LAYER_FIELDS`' % field_uri)
def check_layer_field_exists(packet, field_uri):
"""
Check if a given layer field URI exists in the packet.
:param packet: The packet to check.
:param field_uri: The layer field URI.
:return: Whether the layer field URI exists in the packet.
"""
assert isinstance(packet, RawPacket)
secs = field_uri.split('.')
layer_name = secs[0]
if not is_layer_field(field_uri) and not is_layer_field_container(field_uri):
raise NotImplementedError('%s is neither a field or field container' % field_uri)
candidate_layers = _get_candidate_layers(packet, layer_name)
for layers in candidate_layers:
for layer in layers:
for k, v in layer._all_fields.items():
if k == field_uri or k.startswith(field_uri + '.'):
return True
return False
def _get_candidate_layers(packet, layer_name):
if layer_name == 'thread_meshcop':
candidate_layer_names = ['thread_meshcop', 'mle', 'coap', 'thread_bl', 'thread_nm']
elif layer_name == 'thread_nwd':
candidate_layer_names = ['mle', 'thread_address', 'thread_diagnostic']
elif layer_name == 'wpan':
candidate_layer_names = ['wpan', 'mle']
elif layer_name == 'ip':
candidate_layer_names = ['ip', 'ipv6']
elif layer_name == 'thread_bcn':
candidate_layer_names = ['thread_bcn']
else:
candidate_layer_names = [layer_name]
layers = []
for ln in candidate_layer_names:
if hasattr(packet, ln):
layers.append(packet.get_multiple_layers(ln))
return layers
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
20312,
12,
710,
3232,
4436,
6642,
14,
199,
3,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
221,
650,
14,
11443,
314,
536,
402,
314,
4248,
16712,
6590,
314,
199,
3,
258,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
258,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
221,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
221,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
221,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
199,
3,
221,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
221,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
221,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
221,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
221,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
221,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
221,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
646,
2197,
199,
646,
984,
199,
646,
900,
199,
504,
14090,
492,
6184,
12,
15961,
199,
199,
504,
10382,
72,
1096,
14,
6253,
14,
955,
492,
11915,
7304,
4076,
12,
11915,
792,
199,
504,
10382,
72,
1096,
14,
6253,
14,
6253,
492,
31782,
465,
13480,
2726,
199,
199,
504,
19927,
4712,
14,
18942,
492,
662,
273,
11404,
12,
7255,
11404,
12,
473,
1381,
22,
11404,
199,
504,
19927,
4712,
14,
2394,
492,
9879,
199,
504,
19927,
4712,
14,
20473,
492,
22049,
63,
24167,
63,
14546,
199,
504,
19927,
4712,
14,
2307,
63,
698,
492,
2973,
792,
421,
199,
318,
485,
2495,
8,
86,
26,
15961,
59,
5003,
7304,
4076,
12,
11915,
792,
4682,
272,
408,
1122,
314,
4045,
901,
5847,
7182,
370,
2399,
1475,
624,
272,
702,
440,
1228,
8,
86,
12,
11915,
7304,
4076,
9,
503,
822,
8,
86,
14,
955,
9,
508,
413,
503,
373,
14,
362,
63,
885,
63,
585,
342,
365,
440,
488,
12,
373,
14,
955,
272,
26869,
275,
373,
14,
362,
63,
885,
63,
585,
342,
272,
4336,
275,
373,
14,
1773,
63,
585,
339,
340,
26869,
14,
2460,
360,
16,
88,
735,
267,
372,
1109,
8,
8398,
12,
3193,
9,
339,
862,
26,
267,
340,
26869,
508,
4336,
26,
288,
372,
1109,
8,
8398,
9,
267,
916,
1109,
8,
8398,
9,
508,
1109,
8,
6310,
12,
3193,
304,
288,
372,
1109,
8,
8398,
9,
272,
871,
334,
3393,
12,
3146,
304,
267,
986,
339,
340,
4336,
365,
488,
26,
267,
862,
26,
288,
372,
1109,
8,
8398,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
986,
339,
340,
10871,
315,
26869,
436,
19069,
7,
440,
315,
26869,
436,
26869,
14,
1814,
16451,
4074,
508,
4336,
26,
221,
327,
283,
1299,
26,
383,
297,
283,
1299,
383,
7,
267,
372,
1109,
8,
6310,
12,
3193,
9,
339,
327,
4913,
26,
283,
19825,
221,
413,
12,
413,
20598,
19363,
26,
383,
26,
383,
14,
25464,
445,
840,
297,
283,
9409,
7,
272,
327,
3957,
370,
4696,
687,
413,
20598,
12,
3686,
314,
12055,
3362,
2067,
367,
3063,
3967,
272,
327,
2337,
787,
3000,
4696,
6781,
315,
314,
511,
5560,
272,
862,
26,
267,
900,
63,
495,
275,
2197,
14,
2083,
14,
9866,
8,
8398,
12,
2071,
66,
221,
450,
68,
12,
450,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
1493,
450,
58,
531,
267,
900,
63,
262,
63,
3321,
275,
900,
14,
23456,
8,
521,
63,
495,
14,
5834,
22309,
1012,
267,
372,
1109,
8,
521,
63,
262,
63,
3321,
9,
272,
871,
334,
3393,
12,
3146,
304,
267,
986,
339,
862,
26,
267,
1109,
8,
6310,
12,
3193,
9,
267,
372,
1109,
8,
8398,
9,
272,
871,
2186,
26,
267,
986,
339,
746,
1722,
1332,
86,
12,
373,
14,
362,
63,
885,
63,
585,
1062,
373,
14,
1773,
63,
585,
430,
421,
199,
318,
485,
4749,
8,
86,
26,
15961,
59,
5003,
7304,
4076,
12,
11915,
792,
566,
1035,
11640,
26,
272,
408,
1122,
314,
4045,
901,
465,
282,
11640,
624,
272,
702,
440,
1228,
8,
86,
12,
11915,
7304,
4076,
9,
503,
822,
8,
86,
14,
955,
9,
508,
413,
272,
6318,
63,
585,
275,
373,
14,
1773,
63,
585,
272,
702,
822,
8,
4097,
63,
585,
9,
450,
499,
508,
378,
272,
308,
275,
11640,
342,
272,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
4097,
63,
585,
395,
499,
304,
267,
308,
14,
740,
8,
442,
8,
4097,
63,
585,
59,
73,
26,
73,
435,
499,
467,
3193,
430,
339,
372,
308,
421,
199,
318,
485,
4097,
8,
86,
26,
15961,
59,
5003,
7304,
4076,
12,
11915,
792,
566,
1035,
1109,
26,
272,
408,
1122,
314,
4045,
901,
465,
282,
6318,
1059,
624,
272,
327,
3715,
373,
1901,
27135,
436,
3837,
314,
1865,
272,
702,
440,
1228,
8,
86,
12,
11915,
7304,
4076,
9,
503,
822,
8,
86,
14,
955,
9,
508,
413,
272,
372,
1109,
8,
86,
14,
362,
63,
885,
63,
585,
1062,
3193,
9,
421,
199,
318,
485,
1773,
63,
4097,
8
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
20312,
12,
710,
3232,
4436,
6642,
14,
199,
3,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
221,
650,
14,
11443,
314,
536,
402,
314,
4248,
16712,
6590,
314,
199,
3,
258,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
258,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
221,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
221,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
221,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
199,
3,
221,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
221,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
221,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
221,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
221,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
221,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
221,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
646,
2197,
199,
646,
984,
199,
646,
900,
199,
504,
14090,
492,
6184,
12,
15961,
199,
199,
504,
10382,
72,
1096,
14,
6253,
14,
955,
492,
11915,
7304,
4076,
12,
11915,
792,
199,
504,
10382,
72,
1096,
14,
6253,
14,
6253,
492,
31782,
465,
13480,
2726,
199,
199,
504,
19927,
4712,
14,
18942,
492,
662,
273,
11404,
12,
7255,
11404,
12,
473,
1381,
22,
11404,
199,
504,
19927,
4712,
14,
2394,
492,
9879,
199,
504,
19927,
4712,
14,
20473,
492,
22049,
63,
24167,
63,
14546,
199,
504,
19927,
4712,
14,
2307,
63,
698,
492,
2973,
792,
421,
199,
318,
485,
2495,
8,
86,
26,
15961,
59,
5003,
7304,
4076,
12,
11915,
792,
4682,
272,
408,
1122,
314,
4045,
901,
5847,
7182,
370,
2399,
1475,
624,
272,
702,
440,
1228,
8,
86,
12,
11915,
7304,
4076,
9,
503,
822,
8,
86,
14,
955,
9,
508,
413,
503,
373,
14,
362,
63,
885,
63,
585,
342,
365,
440,
488,
12,
373,
14,
955,
272,
26869,
275,
373,
14,
362,
63,
885,
63,
585,
342,
272,
4336,
275,
373,
14,
1773,
63,
585,
339,
340,
26869,
14,
2460,
360,
16,
88,
735,
267,
372,
1109,
8,
8398,
12,
3193,
9,
339,
862,
26,
267,
340,
26869,
508,
4336,
26,
288,
372,
1109,
8,
8398,
9,
267,
916,
1109,
8,
8398,
9,
508,
1109,
8,
6310,
12,
3193,
304,
288,
372,
1109,
8,
8398,
9,
272,
871,
334,
3393,
12,
3146,
304,
267,
986,
339,
340,
4336,
365,
488,
26,
267,
862,
26,
288,
372,
1109,
8,
8398,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
986,
339,
340,
10871,
315,
26869,
436,
19069,
7,
440,
315,
26869,
436,
26869,
14,
1814,
16451,
4074,
508,
4336,
26,
221,
327,
283,
1299,
26,
383,
297,
283,
1299,
383,
7,
267,
372,
1109,
8,
6310,
12,
3193,
9,
339,
327,
4913,
26,
283,
19825,
221,
413,
12,
413,
20598,
19363,
26,
383,
26,
383,
14,
25464,
445,
840,
297,
283,
9409,
7,
272,
327,
3957,
370,
4696,
687,
413,
20598,
12,
3686,
314,
12055,
3362,
2067,
367,
3063,
3967,
272,
327,
2337,
787,
3000,
4696,
6781,
315,
314,
511,
5560,
272,
862,
26,
267,
900,
63,
495,
275,
2197,
14,
2083,
14,
9866,
8,
8398,
12,
2071,
66,
221,
450,
68,
12,
450,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
1493,
450,
58,
531,
267,
900,
63,
262,
63,
3321,
275,
900,
14,
23456,
8,
521,
63,
495,
14,
5834,
22309,
1012,
267,
372,
1109,
8,
521,
63,
262,
63,
3321,
9,
272,
871,
334,
3393,
12,
3146,
304,
267,
986,
339,
862,
26,
267,
1109,
8,
6310,
12,
3193,
9,
267,
372,
1109,
8,
8398,
9,
272,
871,
2186,
26,
267,
986,
339,
746,
1722,
1332,
86,
12,
373,
14,
362,
63,
885,
63,
585,
1062,
373,
14,
1773,
63,
585,
430,
421,
199,
318,
485,
4749,
8,
86,
26,
15961,
59,
5003,
7304,
4076,
12,
11915,
792,
566,
1035,
11640,
26,
272,
408,
1122,
314,
4045,
901,
465,
282,
11640,
624,
272,
702,
440,
1228,
8,
86,
12,
11915,
7304,
4076,
9,
503,
822,
8,
86,
14,
955,
9,
508,
413,
272,
6318,
63,
585,
275,
373,
14,
1773,
63,
585,
272,
702,
822,
8,
4097,
63,
585,
9,
450,
499,
508,
378,
272,
308,
275,
11640,
342,
272,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
4097,
63,
585,
395,
499,
304,
267,
308,
14,
740,
8,
442,
8,
4097,
63,
585,
59,
73,
26,
73,
435,
499,
467,
3193,
430,
339,
372,
308,
421,
199,
318,
485,
4097,
8,
86,
26,
15961,
59,
5003,
7304,
4076,
12,
11915,
792,
566,
1035,
1109,
26,
272,
408,
1122,
314,
4045,
901,
465,
282,
6318,
1059,
624,
272,
327,
3715,
373,
1901,
27135,
436,
3837,
314,
1865,
272,
702,
440,
1228,
8,
86,
12,
11915,
7304,
4076,
9,
503,
822,
8,
86,
14,
955,
9,
508,
413,
272,
372,
1109,
8,
86,
14,
362,
63,
885,
63,
585,
1062,
3193,
9,
421,
199,
318,
485,
1773,
63,
4097,
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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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
] |
Lukas0907/feeds
|
feeds/spiders/wienerlinien_at.py
|
2
|
1970
|
import scrapy
from scrapy.http import HtmlResponse
from feeds.loaders import FeedEntryItemLoader
from feeds.spiders import FeedsSpider
class WienerLinienAtSpider(FeedsSpider):
name = "wienerlinien.at"
custom_settings = {
"DEFAULT_REQUEST_HEADERS": {
"Accept": "text/html",
# Don't include Accept-Language so the datetime in the HTML
# response includes the time.
}
}
start_urls = [
"https://www.wienerlinien.at/eportal3/ep/scrollingListView.do?"
"scrolling=true&startIndex=0&channelId=-47186&programId=74577"
]
feed_title = "Wiener Linien"
feed_subtitle = "Aktuelle Meldungen"
def parse(self, response):
# Wiener Linien returns HTML with an XML content type which creates an
# XmlResponse.
response = HtmlResponse(url=response.url, body=response.body)
for item in response.css(".block-news-item"):
il = FeedEntryItemLoader(
response=response,
timezone="Europe/Vienna",
ignoretz=True,
base_url="https://www.{}".format(self.name),
)
link = response.urljoin(item.css("a::attr(href)").extract_first())
il.add_value("link", link)
il.add_value("title", item.css("h3::text").extract_first())
il.add_value("updated", item.css(".date::text").extract_first())
yield scrapy.Request(link, self.parse_item, meta={"il": il})
def parse_item(self, response):
remove_elems = ["h1", ".delayed-image-load"]
change_tags = {"noscript": "div"}
il = FeedEntryItemLoader(
response=response,
parent=response.meta["il"],
remove_elems=remove_elems,
change_tags=change_tags,
base_url="https://www.{}".format(self.name),
)
il.add_xpath("content_html", '//div[@id="main-inner"]')
return il.load_item()
|
agpl-3.0
|
[
646,
18918,
199,
504,
18918,
14,
1014,
492,
20880,
2364,
199,
199,
504,
22295,
14,
16370,
492,
16261,
3900,
2081,
5455,
199,
504,
22295,
14,
8721,
7735,
492,
7949,
5923,
25157,
421,
199,
533,
644,
73,
727,
44,
2730,
287,
1271,
25157,
8,
3456,
5923,
25157,
304,
272,
536,
275,
298,
14249,
727,
472,
24555,
14,
292,
2,
272,
3537,
63,
1751,
275,
469,
267,
298,
3472,
63,
6780,
63,
21178,
582,
469,
288,
298,
8422,
582,
298,
505,
15,
1360,
401,
288,
327,
7529,
1133,
2387,
15506,
13,
8493,
880,
314,
2197,
315,
314,
4163,
288,
327,
1177,
6952,
314,
900,
14,
267,
789,
272,
789,
272,
1343,
63,
3603,
275,
359,
267,
298,
2859,
921,
1544,
14,
14249,
727,
472,
24555,
14,
292,
15,
69,
8707,
19,
15,
1545,
15,
6755,
316,
23239,
14,
1117,
13472,
267,
298,
6755,
316,
29,
2052,
6,
928,
2681,
29,
16,
6,
2775,
1304,
4022,
2417,
11656,
6,
6815,
1304,
29,
1342,
13539,
2,
272,
1622,
339,
4733,
63,
1213,
275,
298,
55,
73,
727,
491,
2730,
287,
2,
272,
4733,
63,
14348,
275,
298,
33,
5973,
13086,
274,
603,
457,
324,
2268,
2,
339,
347,
2198,
8,
277,
12,
1177,
304,
267,
327,
644,
73,
727,
491,
2730,
287,
2529,
4163,
543,
376,
4692,
1564,
730,
1314,
8491,
376,
267,
327,
24881,
2364,
14,
267,
1177,
275,
20880,
2364,
8,
633,
29,
1310,
14,
633,
12,
2396,
29,
1310,
14,
2030,
9,
267,
367,
1242,
315,
1177,
14,
3919,
9520,
1457,
13,
13224,
13,
1053,
2349,
288,
21179,
275,
16261,
3900,
2081,
5455,
8,
355,
1177,
29,
1310,
12,
355,
7137,
628,
15201,
15,
2201,
287,
3540,
401,
355,
3686,
3903,
29,
549,
12,
355,
1300,
63,
633,
628,
2859,
921,
1544,
14,
13536,
908,
8,
277,
14,
354,
395,
288,
776,
288,
2142,
275,
1177,
14,
17755,
8,
1053,
14,
3919,
480,
65,
447,
962,
8,
6399,
9,
3471,
5005,
63,
2246,
1012,
288,
21179,
14,
525,
63,
585,
480,
1073,
401,
2142,
9,
288,
21179,
14,
525,
63,
585,
480,
1213,
401,
1242,
14,
3919,
480,
72,
19,
447,
505,
3471,
5005,
63,
2246,
1012,
288,
21179,
14,
525,
63,
585,
480,
5334,
401,
1242,
14,
3919,
9520,
602,
447,
505,
3471,
5005,
63,
2246,
1012,
288,
1995,
18918,
14,
2017,
8,
1073,
12,
291,
14,
1122,
63,
1053,
12,
3404,
8871,
382,
582,
21179,
1552,
339,
347,
2198,
63,
1053,
8,
277,
12,
1177,
304,
267,
2813,
63,
17482,
275,
2097,
72,
17,
401,
3680,
21830,
13,
1569,
13,
912,
937,
267,
1570,
63,
2969,
275,
2420,
889,
1579,
582,
298,
3015,
3570,
267,
21179,
275,
16261,
3900,
2081,
5455,
8,
288,
1177,
29,
1310,
12,
288,
1676,
29,
1310,
14,
2024,
905,
382,
2255,
288,
2813,
63,
17482,
29,
2168,
63,
17482,
12,
288,
1570,
63,
2969,
29,
1461,
63,
2969,
12,
288,
1300,
63,
633,
628,
2859,
921,
1544,
14,
13536,
908,
8,
277,
14,
354,
395,
267,
776,
267,
21179,
14,
525,
63,
8006,
480,
1317,
63,
1360,
401,
18290,
3015,
14251,
344,
628,
973,
13,
5216,
937,
358,
267,
372,
21179,
14,
912,
63,
1053,
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
] |
[
18918,
199,
504,
18918,
14,
1014,
492,
20880,
2364,
199,
199,
504,
22295,
14,
16370,
492,
16261,
3900,
2081,
5455,
199,
504,
22295,
14,
8721,
7735,
492,
7949,
5923,
25157,
421,
199,
533,
644,
73,
727,
44,
2730,
287,
1271,
25157,
8,
3456,
5923,
25157,
304,
272,
536,
275,
298,
14249,
727,
472,
24555,
14,
292,
2,
272,
3537,
63,
1751,
275,
469,
267,
298,
3472,
63,
6780,
63,
21178,
582,
469,
288,
298,
8422,
582,
298,
505,
15,
1360,
401,
288,
327,
7529,
1133,
2387,
15506,
13,
8493,
880,
314,
2197,
315,
314,
4163,
288,
327,
1177,
6952,
314,
900,
14,
267,
789,
272,
789,
272,
1343,
63,
3603,
275,
359,
267,
298,
2859,
921,
1544,
14,
14249,
727,
472,
24555,
14,
292,
15,
69,
8707,
19,
15,
1545,
15,
6755,
316,
23239,
14,
1117,
13472,
267,
298,
6755,
316,
29,
2052,
6,
928,
2681,
29,
16,
6,
2775,
1304,
4022,
2417,
11656,
6,
6815,
1304,
29,
1342,
13539,
2,
272,
1622,
339,
4733,
63,
1213,
275,
298,
55,
73,
727,
491,
2730,
287,
2,
272,
4733,
63,
14348,
275,
298,
33,
5973,
13086,
274,
603,
457,
324,
2268,
2,
339,
347,
2198,
8,
277,
12,
1177,
304,
267,
327,
644,
73,
727,
491,
2730,
287,
2529,
4163,
543,
376,
4692,
1564,
730,
1314,
8491,
376,
267,
327,
24881,
2364,
14,
267,
1177,
275,
20880,
2364,
8,
633,
29,
1310,
14,
633,
12,
2396,
29,
1310,
14,
2030,
9,
267,
367,
1242,
315,
1177,
14,
3919,
9520,
1457,
13,
13224,
13,
1053,
2349,
288,
21179,
275,
16261,
3900,
2081,
5455,
8,
355,
1177,
29,
1310,
12,
355,
7137,
628,
15201,
15,
2201,
287,
3540,
401,
355,
3686,
3903,
29,
549,
12,
355,
1300,
63,
633,
628,
2859,
921,
1544,
14,
13536,
908,
8,
277,
14,
354,
395,
288,
776,
288,
2142,
275,
1177,
14,
17755,
8,
1053,
14,
3919,
480,
65,
447,
962,
8,
6399,
9,
3471,
5005,
63,
2246,
1012,
288,
21179,
14,
525,
63,
585,
480,
1073,
401,
2142,
9,
288,
21179,
14,
525,
63,
585,
480,
1213,
401,
1242,
14,
3919,
480,
72,
19,
447,
505,
3471,
5005,
63,
2246,
1012,
288,
21179,
14,
525,
63,
585,
480,
5334,
401,
1242,
14,
3919,
9520,
602,
447,
505,
3471,
5005,
63,
2246,
1012,
288,
1995,
18918,
14,
2017,
8,
1073,
12,
291,
14,
1122,
63,
1053,
12,
3404,
8871,
382,
582,
21179,
1552,
339,
347,
2198,
63,
1053,
8,
277,
12,
1177,
304,
267,
2813,
63,
17482,
275,
2097,
72,
17,
401,
3680,
21830,
13,
1569,
13,
912,
937,
267,
1570,
63,
2969,
275,
2420,
889,
1579,
582,
298,
3015,
3570,
267,
21179,
275,
16261,
3900,
2081,
5455,
8,
288,
1177,
29,
1310,
12,
288,
1676,
29,
1310,
14,
2024,
905,
382,
2255,
288,
2813,
63,
17482,
29,
2168,
63,
17482,
12,
288,
1570,
63,
2969,
29,
1461,
63,
2969,
12,
288,
1300,
63,
633,
628,
2859,
921,
1544,
14,
13536,
908,
8,
277,
14,
354,
395,
267,
776,
267,
21179,
14,
525,
63,
8006,
480,
1317,
63,
1360,
401,
18290,
3015,
14251,
344,
628,
973,
13,
5216,
937,
358,
267,
372,
21179,
14,
912,
63,
1053,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SimpleAOSP-Kernel/kernel_flo
|
scripts/tracing/draw_functrace.py
|
14676
|
3560
|
#!/usr/bin/python
"""
Copyright 2008 (c) Frederic Weisbecker <fweisbec@gmail.com>
Licensed under the terms of the GNU GPL License version 2
This script parses a trace provided by the function tracer in
kernel/trace/trace_functions.c
The resulted trace is processed into a tree to produce a more human
view of the call stack by drawing textual but hierarchical tree of
calls. Only the functions's names and the the call time are provided.
Usage:
Be sure that you have CONFIG_FUNCTION_TRACER
# mount -t debugfs nodev /sys/kernel/debug
# echo function > /sys/kernel/debug/tracing/current_tracer
$ cat /sys/kernel/debug/tracing/trace_pipe > ~/raw_trace_func
Wait some times but not too much, the script is a bit slow.
Break the pipe (Ctrl + Z)
$ scripts/draw_functrace.py < raw_trace_func > draw_functrace
Then you have your drawn trace in draw_functrace
"""
import sys, re
class CallTree:
""" This class provides a tree representation of the functions
call stack. If a function has no parent in the kernel (interrupt,
syscall, kernel thread...) then it is attached to a virtual parent
called ROOT.
"""
ROOT = None
def __init__(self, func, time = None, parent = None):
self._func = func
self._time = time
if parent is None:
self._parent = CallTree.ROOT
else:
self._parent = parent
self._children = []
def calls(self, func, calltime):
""" If a function calls another one, call this method to insert it
into the tree at the appropriate place.
@return: A reference to the newly created child node.
"""
child = CallTree(func, calltime, self)
self._children.append(child)
return child
def getParent(self, func):
""" Retrieve the last parent of the current node that
has the name given by func. If this function is not
on a parent, then create it as new child of root
@return: A reference to the parent.
"""
tree = self
while tree != CallTree.ROOT and tree._func != func:
tree = tree._parent
if tree == CallTree.ROOT:
child = CallTree.ROOT.calls(func, None)
return child
return tree
def __repr__(self):
return self.__toString("", True)
def __toString(self, branch, lastChild):
if self._time is not None:
s = "%s----%s (%s)\n" % (branch, self._func, self._time)
else:
s = "%s----%s\n" % (branch, self._func)
i = 0
if lastChild:
branch = branch[:-1] + " "
while i < len(self._children):
if i != len(self._children) - 1:
s += "%s" % self._children[i].__toString(branch +\
" |", False)
else:
s += "%s" % self._children[i].__toString(branch +\
" |", True)
i += 1
return s
class BrokenLineException(Exception):
"""If the last line is not complete because of the pipe breakage,
we want to stop the processing and ignore this line.
"""
pass
class CommentLineException(Exception):
""" If the line is a comment (as in the beginning of the trace file),
just ignore it.
"""
pass
def parseLine(line):
line = line.strip()
if line.startswith("#"):
raise CommentLineException
m = re.match("[^]]+?\\] +([0-9.]+): (\\w+) <-(\\w+)", line)
if m is None:
raise BrokenLineException
return (m.group(1), m.group(2), m.group(3))
def main():
CallTree.ROOT = CallTree("Root (Nowhere)", None, None)
tree = CallTree.ROOT
for line in sys.stdin:
try:
calltime, callee, caller = parseLine(line)
except BrokenLineException:
break
except CommentLineException:
continue
tree = tree.getParent(caller)
tree = tree.calls(callee, calltime)
print CallTree.ROOT
if __name__ == "__main__":
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
624,
199,
7384,
9079,
334,
67,
9,
481,
21919,
1567,
2136,
374,
1235,
22043,
665,
70,
1129,
374,
24554,
32,
6799,
14,
957,
30,
199,
31661,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
199,
2765,
2884,
19953,
282,
3307,
2741,
701,
314,
805,
29140,
315,
199,
4989,
15,
3446,
15,
3446,
63,
5777,
14,
67,
199,
1918,
522,
30355,
3307,
365,
7686,
1901,
282,
3123,
370,
7389,
282,
1655,
11779,
199,
1345,
402,
314,
1240,
3464,
701,
17455,
25884,
1325,
24787,
3123,
402,
199,
5352,
14,
5972,
314,
3423,
1159,
1561,
436,
314,
314,
1240,
900,
787,
2741,
14,
199,
199,
7692,
26,
199,
198,
3655,
3238,
626,
1265,
1172,
15869,
63,
15476,
63,
1766,
1348,
540,
199,
198,
3,
10760,
446,
84,
3105,
2319,
1031,
86,
1182,
1274,
15,
4989,
15,
1757,
199,
198,
3,
11343,
805,
690,
1182,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
1818,
63,
16825,
199,
198,
4,
6230,
1182,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
3446,
63,
4990,
690,
6146,
15,
1773,
63,
3446,
63,
1532,
199,
198,
7536,
2005,
5431,
1325,
440,
4634,
8298,
12,
314,
2884,
365,
282,
4546,
11999,
14,
199,
198,
13948,
314,
5200,
334,
9778,
435,
3107,
9,
199,
198,
4,
10554,
15,
5485,
63,
31939,
5986,
14,
647,
665,
3066,
63,
3446,
63,
1532,
690,
5954,
63,
31939,
5986,
199,
198,
28226,
1265,
1172,
2195,
19341,
3307,
315,
5954,
63,
31939,
5986,
199,
624,
421,
199,
646,
984,
12,
295,
199,
199,
533,
23491,
26,
199,
198,
624,
961,
1021,
6571,
282,
3123,
6025,
402,
314,
3423,
507,
198,
1250,
3464,
14,
982,
282,
805,
965,
949,
1676,
315,
314,
5114,
334,
20172,
12,
507,
198,
19444,
12,
5114,
2462,
11965,
2066,
652,
365,
10102,
370,
282,
5791,
1676,
507,
198,
3527,
16547,
14,
199,
198,
624,
199,
198,
5441,
275,
488,
421,
198,
318,
636,
826,
721,
277,
12,
2562,
12,
900,
275,
488,
12,
1676,
275,
488,
304,
507,
198,
277,
423,
1532,
275,
2562,
507,
198,
277,
423,
521,
275,
900,
507,
198,
692,
1676,
365,
488,
26,
686,
198,
277,
423,
1708,
275,
23491,
14,
5441,
507,
198,
2836,
26,
686,
198,
277,
423,
1708,
275,
1676,
507,
198,
277,
423,
3223,
275,
942,
421,
198,
318,
4882,
8,
277,
12,
2562,
12,
1240,
521,
304,
507,
198,
624,
982,
282,
805,
4882,
4573,
1373,
12,
1240,
642,
1083,
370,
5518,
652,
686,
198,
9924,
314,
3123,
737,
314,
5827,
4192,
14,
686,
198,
32,
1107,
26,
437,
3659,
370,
314,
13903,
2737,
1982,
1031,
14,
507,
198,
624,
507,
198,
1739,
275,
23491,
8,
1532,
12,
1240,
521,
12,
291,
9,
507,
198,
277,
423,
3223,
14,
740,
8,
1739,
9,
507,
198,
1107,
1982,
421,
198,
318,
664,
6652,
8,
277,
12,
2562,
304,
507,
198,
624,
13939,
314,
2061,
1676,
402,
314,
1453,
1031,
626,
686,
198,
1989,
314,
536,
1627,
701,
2562,
14,
982,
642,
805,
365,
440,
686,
198,
265,
282,
1676,
12,
2066,
1218,
652,
465,
892,
1982,
402,
1738,
686,
198,
32,
1107,
26,
437,
3659,
370,
314,
1676,
14,
507,
198,
624,
507,
198,
2350,
275,
291,
507,
198,
6710,
3123,
1137,
23491,
14,
5441,
436,
3123,
423,
1532,
1137,
2562,
26,
686,
198,
2350,
275,
3123,
423,
1708,
507,
198,
692,
3123,
508,
23491,
14,
5441,
26,
686,
198,
1739,
275,
23491,
14,
5441,
14,
5352,
8,
1532,
12,
488,
9,
686,
198,
1107,
1982,
507,
198,
1107,
3123,
421,
198,
318,
636,
2722,
721,
277,
304,
507,
198,
1107,
291,
855,
16695,
12398,
715,
9,
421,
198,
318,
636,
16695,
8,
277,
12,
5246,
12,
2061,
3493,
304,
507,
198,
692,
291,
423,
521,
365,
440,
488,
26,
686,
198,
83,
275,
2071,
83,
375,
5,
83,
4366,
83,
2862,
78,
2,
450,
334,
4694,
12,
291,
423,
1532,
12,
291,
423,
521,
9,
507,
198,
2836,
26,
686,
198,
83,
275,
2071,
83,
375,
5,
83,
60,
78,
2,
450,
334,
4694,
12,
291,
423,
1532,
9,
2742,
198,
73,
275,
378,
507,
198,
692,
2061,
3493,
26,
686,
198,
4694,
275,
5246,
4439,
17,
61,
435,
298,
298,
507,
198,
6710,
284,
665,
822,
8,
277,
423,
3223,
304,
686,
198,
692,
284,
1137,
822,
8,
277,
423,
3223,
9,
446,
413,
26,
1585,
198,
83,
847,
2071,
83,
2,
450,
291,
423,
3223,
59,
73,
17979,
16695,
8,
4694,
17992,
11674,
198,
2,
259,
1204,
401,
756,
9,
686,
198,
2836,
26,
1585,
198,
83,
847,
2071,
83,
2,
450,
291,
423,
3223,
59,
73,
17979,
16695,
8,
4694,
17992,
11674,
198,
2,
259,
1204,
401,
715,
9,
686,
198,
73,
847,
413,
507,
198,
1107,
308,
199,
199,
533,
23804,
29969,
8,
1726,
304,
199,
198,
624,
3917,
314,
2061,
1004,
365,
440,
4890,
2952,
402,
314,
5200,
2059,
474,
12,
21979,
781,
2934,
370,
3631,
314,
6661,
436,
3686,
642,
1004,
14,
199,
198,
624,
199,
198,
1529,
199,
199,
533,
6819,
29969,
8,
1726,
304,
199,
198,
624,
982,
314,
1004,
365,
282,
3721,
334,
305,
315,
314,
9608,
402,
314,
3307,
570,
395,
6722,
2951,
3686,
652,
14,
199,
198,
624,
199,
198,
1529,
421,
199,
318,
2198,
3049,
8,
604,
304,
199,
198,
604,
275,
1004,
14,
1913,
342,
199,
198,
692,
1004,
14,
2460,
10064,
2349,
507,
198,
3730,
6819,
29969,
199,
198,
77,
275,
295,
14,
1431,
480,
4735,
2677,
23778,
1103,
61,
435,
779,
16,
13,
25,
32455,
304,
334,
1103,
87,
8771,
665,
15426,
1103,
87,
11,
4186,
1004,
9,
199,
198,
692,
333,
365,
488,
26,
507,
198,
3730,
23804,
29969,
199,
198,
1107,
334,
77,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
395,
333,
14,
923,
8,
19,
430,
421,
199,
318,
2446,
837,
199,
198,
2176,
3987,
14,
5441,
275,
23491,
480,
6405,
334,
14351,
1681,
4186,
488,
12,
488,
9,
199,
198,
2350,
275,
23491,
14,
5441,
421,
198,
509,
1004,
315,
984,
14,
6626,
26,
507,
198,
893,
26,
686,
198,
1250,
521,
12,
3213,
18387,
12,
8025,
275,
2198,
3049,
8,
604
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
624,
199,
7384,
9079,
334,
67,
9,
481,
21919,
1567,
2136,
374,
1235,
22043,
665,
70,
1129,
374,
24554,
32,
6799,
14,
957,
30,
199,
31661,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
199,
2765,
2884,
19953,
282,
3307,
2741,
701,
314,
805,
29140,
315,
199,
4989,
15,
3446,
15,
3446,
63,
5777,
14,
67,
199,
1918,
522,
30355,
3307,
365,
7686,
1901,
282,
3123,
370,
7389,
282,
1655,
11779,
199,
1345,
402,
314,
1240,
3464,
701,
17455,
25884,
1325,
24787,
3123,
402,
199,
5352,
14,
5972,
314,
3423,
1159,
1561,
436,
314,
314,
1240,
900,
787,
2741,
14,
199,
199,
7692,
26,
199,
198,
3655,
3238,
626,
1265,
1172,
15869,
63,
15476,
63,
1766,
1348,
540,
199,
198,
3,
10760,
446,
84,
3105,
2319,
1031,
86,
1182,
1274,
15,
4989,
15,
1757,
199,
198,
3,
11343,
805,
690,
1182,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
1818,
63,
16825,
199,
198,
4,
6230,
1182,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
3446,
63,
4990,
690,
6146,
15,
1773,
63,
3446,
63,
1532,
199,
198,
7536,
2005,
5431,
1325,
440,
4634,
8298,
12,
314,
2884,
365,
282,
4546,
11999,
14,
199,
198,
13948,
314,
5200,
334,
9778,
435,
3107,
9,
199,
198,
4,
10554,
15,
5485,
63,
31939,
5986,
14,
647,
665,
3066,
63,
3446,
63,
1532,
690,
5954,
63,
31939,
5986,
199,
198,
28226,
1265,
1172,
2195,
19341,
3307,
315,
5954,
63,
31939,
5986,
199,
624,
421,
199,
646,
984,
12,
295,
199,
199,
533,
23491,
26,
199,
198,
624,
961,
1021,
6571,
282,
3123,
6025,
402,
314,
3423,
507,
198,
1250,
3464,
14,
982,
282,
805,
965,
949,
1676,
315,
314,
5114,
334,
20172,
12,
507,
198,
19444,
12,
5114,
2462,
11965,
2066,
652,
365,
10102,
370,
282,
5791,
1676,
507,
198,
3527,
16547,
14,
199,
198,
624,
199,
198,
5441,
275,
488,
421,
198,
318,
636,
826,
721,
277,
12,
2562,
12,
900,
275,
488,
12,
1676,
275,
488,
304,
507,
198,
277,
423,
1532,
275,
2562,
507,
198,
277,
423,
521,
275,
900,
507,
198,
692,
1676,
365,
488,
26,
686,
198,
277,
423,
1708,
275,
23491,
14,
5441,
507,
198,
2836,
26,
686,
198,
277,
423,
1708,
275,
1676,
507,
198,
277,
423,
3223,
275,
942,
421,
198,
318,
4882,
8,
277,
12,
2562,
12,
1240,
521,
304,
507,
198,
624,
982,
282,
805,
4882,
4573,
1373,
12,
1240,
642,
1083,
370,
5518,
652,
686,
198,
9924,
314,
3123,
737,
314,
5827,
4192,
14,
686,
198,
32,
1107,
26,
437,
3659,
370,
314,
13903,
2737,
1982,
1031,
14,
507,
198,
624,
507,
198,
1739,
275,
23491,
8,
1532,
12,
1240,
521,
12,
291,
9,
507,
198,
277,
423,
3223,
14,
740,
8,
1739,
9,
507,
198,
1107,
1982,
421,
198,
318,
664,
6652,
8,
277,
12,
2562,
304,
507,
198,
624,
13939,
314,
2061,
1676,
402,
314,
1453,
1031,
626,
686,
198,
1989,
314,
536,
1627,
701,
2562,
14,
982,
642,
805,
365,
440,
686,
198,
265,
282,
1676,
12,
2066,
1218,
652,
465,
892,
1982,
402,
1738,
686,
198,
32,
1107,
26,
437,
3659,
370,
314,
1676,
14,
507,
198,
624,
507,
198,
2350,
275,
291,
507,
198,
6710,
3123,
1137,
23491,
14,
5441,
436,
3123,
423,
1532,
1137,
2562,
26,
686,
198,
2350,
275,
3123,
423,
1708,
507,
198,
692,
3123,
508,
23491,
14,
5441,
26,
686,
198,
1739,
275,
23491,
14,
5441,
14,
5352,
8,
1532,
12,
488,
9,
686,
198,
1107,
1982,
507,
198,
1107,
3123,
421,
198,
318,
636,
2722,
721,
277,
304,
507,
198,
1107,
291,
855,
16695,
12398,
715,
9,
421,
198,
318,
636,
16695,
8,
277,
12,
5246,
12,
2061,
3493,
304,
507,
198,
692,
291,
423,
521,
365,
440,
488,
26,
686,
198,
83,
275,
2071,
83,
375,
5,
83,
4366,
83,
2862,
78,
2,
450,
334,
4694,
12,
291,
423,
1532,
12,
291,
423,
521,
9,
507,
198,
2836,
26,
686,
198,
83,
275,
2071,
83,
375,
5,
83,
60,
78,
2,
450,
334,
4694,
12,
291,
423,
1532,
9,
2742,
198,
73,
275,
378,
507,
198,
692,
2061,
3493,
26,
686,
198,
4694,
275,
5246,
4439,
17,
61,
435,
298,
298,
507,
198,
6710,
284,
665,
822,
8,
277,
423,
3223,
304,
686,
198,
692,
284,
1137,
822,
8,
277,
423,
3223,
9,
446,
413,
26,
1585,
198,
83,
847,
2071,
83,
2,
450,
291,
423,
3223,
59,
73,
17979,
16695,
8,
4694,
17992,
11674,
198,
2,
259,
1204,
401,
756,
9,
686,
198,
2836,
26,
1585,
198,
83,
847,
2071,
83,
2,
450,
291,
423,
3223,
59,
73,
17979,
16695,
8,
4694,
17992,
11674,
198,
2,
259,
1204,
401,
715,
9,
686,
198,
73,
847,
413,
507,
198,
1107,
308,
199,
199,
533,
23804,
29969,
8,
1726,
304,
199,
198,
624,
3917,
314,
2061,
1004,
365,
440,
4890,
2952,
402,
314,
5200,
2059,
474,
12,
21979,
781,
2934,
370,
3631,
314,
6661,
436,
3686,
642,
1004,
14,
199,
198,
624,
199,
198,
1529,
199,
199,
533,
6819,
29969,
8,
1726,
304,
199,
198,
624,
982,
314,
1004,
365,
282,
3721,
334,
305,
315,
314,
9608,
402,
314,
3307,
570,
395,
6722,
2951,
3686,
652,
14,
199,
198,
624,
199,
198,
1529,
421,
199,
318,
2198,
3049,
8,
604,
304,
199,
198,
604,
275,
1004,
14,
1913,
342,
199,
198,
692,
1004,
14,
2460,
10064,
2349,
507,
198,
3730,
6819,
29969,
199,
198,
77,
275,
295,
14,
1431,
480,
4735,
2677,
23778,
1103,
61,
435,
779,
16,
13,
25,
32455,
304,
334,
1103,
87,
8771,
665,
15426,
1103,
87,
11,
4186,
1004,
9,
199,
198,
692,
333,
365,
488,
26,
507,
198,
3730,
23804,
29969,
199,
198,
1107,
334,
77,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
395,
333,
14,
923,
8,
19,
430,
421,
199,
318,
2446,
837,
199,
198,
2176,
3987,
14,
5441,
275,
23491,
480,
6405,
334,
14351,
1681,
4186,
488,
12,
488,
9,
199,
198,
2350,
275,
23491,
14,
5441,
421,
198,
509,
1004,
315,
984,
14,
6626,
26,
507,
198,
893,
26,
686,
198,
1250,
521,
12,
3213,
18387,
12,
8025,
275,
2198,
3049,
8,
604,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
thresholdsoftware/asylum
|
openerp/addons/project_long_term/wizard/project_compute_phases.py
|
46
|
3290
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tools.translate import _
from openerp.osv import fields, osv
class project_compute_phases(osv.osv_memory):
_name = 'project.compute.phases'
_description = 'Project Compute Phases'
_columns = {
'target_project': fields.selection([
('all', 'Compute All My Projects'),
('one', 'Compute a Single Project'),
], 'Action', required=True),
'project_id': fields.many2one('project.project', 'Project')
}
_defaults = {
'target_project': 'one'
}
def check_selection(self, cr, uid, ids, context=None):
return self.compute_date(cr, uid, ids, context=context)
def compute_date(self, cr, uid, ids, context=None):
"""
Compute the phases for scheduling.
"""
project_pool = self.pool.get('project.project')
data = self.read(cr, uid, ids, [], context=context)[0]
if not data['project_id'] and data['target_project'] == 'one':
raise osv.except_osv(_('Error!'), _('Please specify a project to schedule.'))
if data['target_project'] == 'one':
project_ids = [data['project_id'][0]]
else:
project_ids = project_pool.search(cr, uid, [('user_id','=',uid)], context=context)
if project_ids:
project_pool.schedule_phases(cr, uid, project_ids, context=context)
return self._open_phases_list(cr, uid, data, context=context)
def _open_phases_list(self, cr, uid, data, context=None):
"""
Return the scheduled phases list.
"""
if context is None:
context = {}
mod_obj = self.pool.get('ir.model.data')
act_obj = self.pool.get('ir.actions.act_window')
result = mod_obj._get_id(cr, uid, 'project_long_term', 'act_project_phase')
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id], context=context)[0]
result['target'] = 'current'
project_id = data.get('project_id') and data.get('project_id')[0] or False
result['context'] = {"search_default_project_id":project_id, "default_project_id":project_id, "search_default_current": 1}
return result
project_compute_phases()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
2199,
63,
3357,
63,
14236,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
1715,
14,
3357,
14,
14236,
7,
272,
485,
1802,
275,
283,
4761,
8354,
11308,
3274,
7,
272,
485,
3406,
275,
469,
267,
283,
1375,
63,
1715,
356,
1504,
14,
5592,
779,
288,
661,
452,
297,
283,
8564,
2900,
4932,
7290,
83,
659,
288,
661,
368,
297,
283,
8564,
282,
13050,
7290,
659,
288,
2156,
283,
3310,
297,
1415,
29,
549,
395,
267,
283,
1715,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
1715,
14,
1715,
297,
283,
4761,
358,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
1375,
63,
1715,
356,
283,
368,
7,
272,
789,
339,
347,
1104,
63,
5592,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
3357,
63,
602,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
339,
347,
4526,
63,
602,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
408,
267,
8354,
314,
22587,
367,
23800,
14,
267,
408,
267,
2199,
63,
2293,
275,
291,
14,
2293,
14,
362,
360,
1715,
14,
1715,
358,
267,
666,
275,
291,
14,
739,
8,
1556,
12,
1747,
12,
2762,
12,
990,
1067,
29,
1100,
2788,
16,
61,
267,
340,
440,
666,
459,
1715,
63,
344,
418,
436,
666,
459,
1375,
63,
1715,
418,
508,
283,
368,
356,
288,
746,
9506,
14,
2590,
63,
4795,
6723,
547,
15659,
4018,
8254,
4165,
282,
2199,
370,
8732,
12459,
398,
340,
666,
459,
1375,
63,
1715,
418,
508,
283,
368,
356,
288,
2199,
63,
1580,
275,
359,
576,
459,
1715,
63,
344,
3488,
16,
2677,
267,
587,
26,
288,
2199,
63,
1580,
275,
2199,
63,
2293,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
751,
63,
344,
18937,
1535,
4360,
1067,
29,
1100,
9,
398,
340,
2199,
63,
1580,
26,
288,
2199,
63,
2293,
14,
7211,
63,
14236,
8,
1556,
12,
1747,
12,
2199,
63,
1580,
12,
1067,
29,
1100,
9,
267,
372,
291,
423,
1490,
63,
14236,
63,
513,
8,
1556,
12,
1747,
12,
666,
12,
1067,
29,
1100,
9,
339,
347,
485,
1490,
63,
14236,
63,
513,
8,
277,
12,
2467,
12,
1747,
12,
666,
12,
1067,
29,
403,
304,
267,
408,
267,
1432,
314,
18416,
22587,
769,
14,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
3413,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
358,
267,
2454,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
3723,
14,
2442,
63,
3806,
358,
267,
754,
275,
3413,
63,
1113,
423,
362,
63,
344,
8,
1556,
12,
1747,
12,
283,
1715,
63,
2809,
63,
5125,
297,
283,
2442,
63,
1715,
63,
6971,
358,
267,
1305,
275,
3413,
63,
1113,
14,
739,
8,
1556,
12,
1747,
12,
359,
1099,
467,
788,
470,
63,
344,
25945,
16,
2733,
470,
63,
344,
418,
267,
754,
275,
2454,
63,
1113,
14,
739,
8,
1556,
12,
1747,
12,
359,
344,
467,
1067,
29,
1100,
2788,
16,
61,
267,
754,
459,
1375,
418,
275,
283,
1818,
7,
267,
2199,
63,
344,
275,
666,
14,
362,
360,
1715,
63,
344,
358,
436,
666,
14,
362,
360,
1715,
63,
344,
5832,
16,
61,
503,
756,
267,
754,
459,
1100,
418,
275,
2420,
1733,
63,
885,
63,
1715,
63,
344,
582,
1715,
63,
344,
12,
298,
885,
63,
1715,
63,
344,
582,
1715,
63,
344,
12,
298,
1733,
63,
885,
63,
1818,
582,
413,
93,
267,
372,
754,
199,
199,
1715,
63,
3357,
63,
14236,
342,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
2199,
63,
3357,
63,
14236,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
1715,
14,
3357,
14,
14236,
7,
272,
485,
1802,
275,
283,
4761,
8354,
11308,
3274,
7,
272,
485,
3406,
275,
469,
267,
283,
1375,
63,
1715,
356,
1504,
14,
5592,
779,
288,
661,
452,
297,
283,
8564,
2900,
4932,
7290,
83,
659,
288,
661,
368,
297,
283,
8564,
282,
13050,
7290,
659,
288,
2156,
283,
3310,
297,
1415,
29,
549,
395,
267,
283,
1715,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
1715,
14,
1715,
297,
283,
4761,
358,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
1375,
63,
1715,
356,
283,
368,
7,
272,
789,
339,
347,
1104,
63,
5592,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
3357,
63,
602,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
339,
347,
4526,
63,
602,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
408,
267,
8354,
314,
22587,
367,
23800,
14,
267,
408,
267,
2199,
63,
2293,
275,
291,
14,
2293,
14,
362,
360,
1715,
14,
1715,
358,
267,
666,
275,
291,
14,
739,
8,
1556,
12,
1747,
12,
2762,
12,
990,
1067,
29,
1100,
2788,
16,
61,
267,
340,
440,
666,
459,
1715,
63,
344,
418,
436,
666,
459,
1375,
63,
1715,
418,
508,
283,
368,
356,
288,
746,
9506,
14,
2590,
63,
4795,
6723,
547,
15659,
4018,
8254,
4165,
282,
2199,
370,
8732,
12459,
398,
340,
666,
459,
1375,
63,
1715,
418,
508,
283,
368,
356,
288,
2199,
63,
1580,
275,
359,
576,
459,
1715,
63,
344,
3488,
16,
2677,
267,
587,
26,
288,
2199,
63,
1580,
275,
2199,
63,
2293,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
751,
63,
344,
18937,
1535,
4360,
1067,
29,
1100,
9,
398,
340,
2199,
63,
1580,
26,
288,
2199,
63,
2293,
14,
7211,
63,
14236,
8,
1556,
12,
1747,
12,
2199,
63,
1580,
12,
1067,
29,
1100,
9,
267,
372,
291,
423,
1490,
63,
14236,
63,
513,
8,
1556,
12,
1747,
12,
666,
12,
1067,
29,
1100,
9,
339,
347,
485,
1490,
63,
14236,
63,
513,
8,
277,
12,
2467,
12,
1747,
12,
666,
12,
1067,
29,
403,
304,
267,
408,
267,
1432,
314,
18416,
22587,
769,
14,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
3413,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
358,
267,
2454,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
3723,
14,
2442,
63,
3806,
358,
267,
754,
275,
3413,
63,
1113,
423,
362,
63,
344,
8,
1556,
12,
1747,
12,
283,
1715,
63,
2809,
63,
5125,
297,
283,
2442,
63,
1715,
63,
6971,
358,
267,
1305,
275,
3413,
63,
1113,
14,
739,
8,
1556,
12,
1747,
12,
359,
1099,
467,
788,
470,
63,
344,
25945,
16,
2733,
470,
63,
344,
418,
267,
754,
275,
2454,
63,
1113,
14,
739,
8,
1556,
12,
1747,
12,
359,
344,
467,
1067,
29,
1100,
2788,
16,
61,
267,
754,
459,
1375,
418,
275,
283,
1818,
7,
267,
2199,
63,
344,
275,
666,
14,
362,
360,
1715,
63,
344,
358,
436,
666,
14,
362,
360,
1715,
63,
344,
5832,
16,
61,
503,
756,
267,
754,
459,
1100,
418,
275,
2420,
1733,
63,
885,
63,
1715,
63,
344,
582,
1715,
63,
344,
12,
298,
885,
63,
1715,
63,
344,
582,
1715,
63,
344,
12,
298,
1733,
63,
885,
63,
1818,
582,
413,
93,
267,
372,
754,
199,
199,
1715,
63,
3357,
63,
14236,
342,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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|
8492
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 Lenovo, Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
# Module to send conditional template to Lenovo Switches
# Lenovo Networking
#
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: cnos_conditional_template
author: "Dave Kasberg (@dkasberg)"
short_description: Manage switch configuration using templates based on condition on devices running Lenovo CNOS
description:
- This module allows you to work with the running configuration of a switch. It provides a way to
execute a set of CNOS commands on a switch by evaluating the current running configuration and
executing the commands only if the specific settings have not been already configured.
The configuration source can be a set of commands or a template written in the Jinja2 templating language.
This module functions the same as the cnos_template module.
The only exception is that the following inventory variable can be specified
[“condition = <flag string>”]
When this inventory variable is specified as the variable of a task, the template is executed for
the network element that matches the flag string. Usually, templates are used when commands are the
same across a group of network devices. When there is a requirement to skip the execution of the
template on one or more devices, it is recommended to use this module.
This module uses SSH to manage network device configuration.
For more information about this module from Lenovo and customizing it usage for your
use cases, please visit U(http://systemx.lenovofiles.com/help/index.jsp?topic=%2Fcom.lenovo.switchmgt.ansible.doc%2Fcnos_conditional_template.html)
version_added: "2.3"
extends_documentation_fragment: cnos
options:
commandfile:
description:
- This specifies the path to the CNOS command file which needs to be applied. This usually
comes from the commands folder. Generally this file is the output of the variables applied
on a template file. So this command is preceded by a template module.
The command file must contain the Ansible keyword {{ inventory_hostname }} and the condition
flag in its filename to ensure that the command file is unique for each switch and condition.
If this is omitted, the command file will be overwritten during iteration. For example,
commandfile=./commands/clos_leaf_bgp_{{ inventory_hostname }}_LP21_commands.txt
required: true
default: Null
condition:
description:
- If you specify condition=<flag string> in the inventory file against any device, the template
execution is done for that device in case it matches the flag setting for that task.
required: true
default: Null
flag:
description:
- If a task needs to be executed, you have to set the flag the same as it is specified in
the inventory for that device.
required: true
default: Null
'''
EXAMPLES = '''
Tasks : The following are examples of using the module cnos_conditional_template. These are written in the main.yml file of the tasks directory.
---
- name: Applying CLI template on VLAG Tier1 Leaf Switch1
cnos_conditional_template:
host: "{{ inventory_hostname }}"
username: "{{ hostvars[inventory_hostname]['username'] }}"
password: "{{ hostvars[inventory_hostname]['password'] }}"
deviceType: "{{ hostvars[inventory_hostname]['deviceType'] }}"
outputfile: "./results/vlag_1tier_leaf_switch1_{{ inventory_hostname }}_output.txt"
condition: "{{ hostvars[inventory_hostname]['condition']}}"
flag: "leaf_switch1"
commandfile: "./commands/vlag_1tier_leaf_switch1_{{ inventory_hostname }}_commands.txt"
enablePassword: "anil"
stp_mode1: "disable"
port_range1: "17,18,29,30"
portchannel_interface_number1: 1001
portchannel_mode1: active
slot_chassis_number1: 1/48
switchport_mode1: trunk
'''
RETURN = '''
msg:
description: Success or failure message
returned: always
type: string
sample: "Template Applied."
'''
import sys
import paramiko
import time
import argparse
import socket
import array
import json
import time
import re
try:
from ansible.module_utils import cnos
HAS_LIB = True
except:
HAS_LIB = False
from ansible.module_utils.basic import AnsibleModule
from collections import defaultdict
def main():
module = AnsibleModule(
argument_spec=dict(
commandfile=dict(required=True),
outputfile=dict(required=True),
condition=dict(required=True),
flag=dict(required=True),
host=dict(required=True),
deviceType=dict(required=True),
username=dict(required=True),
password=dict(required=True, no_log=True),
enablePassword=dict(required=False, no_log=True),),
supports_check_mode=False)
username = module.params['username']
password = module.params['password']
enablePassword = module.params['enablePassword']
condition = module.params['condition']
flag = module.params['flag']
commandfile = module.params['commandfile']
deviceType = module.params['deviceType']
outputfile = module.params['outputfile']
hostIP = module.params['host']
output = ""
# Here comes the logic against which a template is
# conditionally executed for right Network element.
if (condition != flag):
module.exit_json(changed=True, msg="Template Skipped for this value")
return " "
# Create instance of SSHClient object
remote_conn_pre = paramiko.SSHClient()
# Automatically add untrusted hosts (make sure okay for security policy in your environment)
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# initiate SSH connection with the switch
remote_conn_pre.connect(hostIP, username=username, password=password)
time.sleep(2)
# Use invoke_shell to establish an 'interactive session'
remote_conn = remote_conn_pre.invoke_shell()
time.sleep(2)
# Enable and enter configure terminal then send command
output = output + cnos.waitForDeviceResponse("\n", ">", 2, remote_conn)
output = output + cnos.enterEnableModeForDevice(enablePassword, 3, remote_conn)
# Make terminal length = 0
output = output + cnos.waitForDeviceResponse("terminal length 0\n", "#", 2, remote_conn)
# Go to config mode
output = output + cnos.waitForDeviceResponse("configure d\n", "(config)#", 2, remote_conn)
# Send commands one by one
#with open(commandfile, "r") as f:
f = open(commandfile, "r")
for line in f:
# Omit the comment lines in template file
if not line.startswith("#"):
# cnos.debugOutput(line)
command = line
if not line.endswith("\n"):
command = command+"\n"
response = cnos.waitForDeviceResponse(command, "#", 2, remote_conn)
errorMsg = cnos.checkOutputForError(response)
output = output + response
if(errorMsg is not None):
break
# To cater to Mufti case
# Write to memory
output = output + cnos.waitForDeviceResponse("save\n", "#", 3, remote_conn)
# Write output to file
file = open(outputfile, "a")
file.write(output)
file.close()
# Logic to check when changes occur or not
errorMsg = cnos.checkOutputForError(output)
if(errorMsg is None):
module.exit_json(changed=True, msg="Template Applied")
else:
module.fail_json(msg=errorMsg)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
15757,
31445,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
5673,
370,
3222,
12303,
1978,
370,
15757,
31445,
17711,
397,
199,
3,
15757,
31445,
7220,
316,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
32535,
63,
14353,
63,
1160,
199,
2502,
26,
298,
36,
811,
1804,
305,
14630,
8593,
6341,
305,
14630,
2924,
199,
3612,
63,
1802,
26,
14944,
6258,
2897,
1808,
7009,
4079,
641,
5558,
641,
7256,
3879,
15757,
31445,
445,
23141,
199,
1802,
26,
272,
446,
961,
859,
6127,
1265,
370,
1736,
543,
314,
3879,
2897,
402,
282,
6258,
14,
2779,
6571,
282,
4340,
370,
1362,
5341,
282,
663,
402,
445,
23141,
3718,
641,
282,
6258,
701,
27083,
314,
1453,
3879,
2897,
436,
1362,
14043,
314,
3718,
1454,
340,
314,
2488,
2202,
1172,
440,
2757,
2575,
7526,
14,
1362,
710,
2897,
1350,
883,
506,
282,
663,
402,
3718,
503,
282,
1978,
5313,
315,
314,
17300,
18,
2388,
24615,
2637,
14,
1362,
961,
859,
3423,
314,
2011,
465,
314,
32535,
63,
1160,
859,
14,
1362,
710,
1454,
1919,
365,
626,
314,
2569,
8200,
1750,
883,
506,
2013,
1362,
359,
8477,
251,
5394,
275,
665,
4173,
1059,
30,
8477,
252,
61,
1362,
3979,
642,
8200,
1750,
365,
2013,
465,
314,
1750,
402,
282,
2120,
12,
314,
1978,
365,
7934,
367,
1362,
314,
2784,
1819,
626,
4450,
314,
3305,
1059,
14,
24612,
12,
7009,
787,
1202,
1380,
3718,
787,
314,
1362,
2011,
9371,
282,
1572,
402,
2784,
7256,
14,
3979,
2337,
365,
282,
10685,
370,
3372,
314,
6451,
402,
314,
1362,
1978,
641,
1373,
503,
1655,
7256,
12,
652,
365,
14318,
370,
675,
642,
859,
14,
1362,
961,
859,
4440,
12027,
370,
9635,
2784,
2243,
2897,
14,
1362,
2104,
1655,
2556,
3595,
642,
859,
687,
15757,
31445,
436,
3537,
9147,
652,
4503,
367,
2195,
1362,
675,
5560,
12,
8749,
5684,
738,
8,
1014,
921,
2253,
88,
14,
552,
31445,
1725,
14,
957,
15,
3437,
15,
1080,
14,
74,
681,
31,
5746,
2458,
18,
38,
957,
14,
552,
31445,
14,
5656,
77,
3308,
14,
4853,
14,
1301,
5,
18,
38,
6413,
736,
63,
14353,
63,
1160,
14,
1360,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
11036,
63,
9970,
63,
7677,
26,
32535,
199,
1419,
26,
272,
1414,
493,
26,
267,
1369,
26,
288,
446,
961,
9314,
314,
931,
370,
314,
445,
23141,
1414,
570,
1314,
4839,
370,
506,
6781,
14,
961,
9987,
1467,
12477,
687,
314,
3718,
4922,
14,
1464,
1183,
642,
570,
365,
314,
1072,
402,
314,
2860,
6781,
1467,
641,
282,
1978,
570,
14,
2002,
642,
1414,
365,
9222,
770,
701,
282,
1978,
859,
14,
1467,
710,
1414,
570,
1471,
1395,
314,
2622,
4252,
8448,
8200,
63,
4269,
3586,
436,
314,
5558,
1467,
3305,
315,
2399,
1788,
370,
4868,
626,
314,
1414,
570,
365,
3747,
367,
1924,
6258,
436,
5558,
14,
1467,
982,
642,
365,
11684,
12,
314,
1414,
570,
911,
506,
20200,
5309,
8494,
14,
2104,
2893,
12,
1467,
1414,
493,
29,
13186,
4405,
15,
1251,
83,
63,
8914,
63,
10132,
63,
3638,
8200,
63,
4269,
3586,
63,
9257,
2025,
63,
4405,
14,
2424,
267,
1415,
26,
2549,
267,
849,
26,
12119,
272,
5558,
26,
267,
1369,
26,
288,
446,
982,
1265,
4165,
5558,
18987,
4173,
1059,
30,
315,
314,
8200,
570,
6169,
1263,
2243,
12,
314,
1978,
1467,
6451,
365,
4224,
367,
626,
2243,
315,
1930,
652,
4450,
314,
3305,
4260,
367,
626,
2120,
14,
267,
1415,
26,
2549,
267,
849,
26,
12119,
272,
3305,
26,
267,
1369,
26,
288,
446,
982,
282,
2120,
4839,
370,
506,
7934,
12,
1265,
1172,
370,
663,
314,
3305,
314,
2011,
465,
652,
365,
2013,
315,
1467,
314,
8200,
367,
626,
2243,
14,
267,
1415,
26,
2549,
267,
849,
26,
12119,
199,
2344,
199,
8918,
275,
1449,
199,
19295,
520,
710,
2569,
787,
7251,
402,
1808,
314,
859,
32535,
63,
14353,
63,
1160,
14,
5723,
787,
5313,
315,
314,
2446,
14,
11714,
570,
402,
314,
6527,
2082,
14,
199,
2595,
199,
13,
536,
26,
4693,
6670,
14214,
1978,
641,
812,
44,
1254,
377,
4446,
17,
27836,
17711,
17,
523,
32535,
63,
14353,
63,
1160,
26,
489,
1591,
26,
7370,
8200,
63,
4269,
7820,
489,
3434,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
2473,
418,
7820,
489,
2505,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
2060,
418,
7820,
489,
31343,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
1782,
804,
418,
7820,
489,
32513,
26,
26069,
2604,
15,
86,
1823,
63,
17,
13949,
63,
8914,
63,
5656,
17,
63,
3638,
8200,
63,
4269,
3586,
63,
1199,
14,
2424,
2,
489,
5558,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
5394,
418,
30618,
489,
3305,
26,
298,
8914,
63,
5656,
17,
2,
489,
1414,
493,
26,
26069,
4405,
15,
86,
1823,
63,
17,
13949,
63,
8914,
63,
5656,
17,
63,
3638,
8200,
63,
4269,
3586,
63,
4405,
14,
2424,
2,
489,
4756,
6139,
26
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
15757,
31445,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
5673,
370,
3222,
12303,
1978,
370,
15757,
31445,
17711,
397,
199,
3,
15757,
31445,
7220,
316,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
32535,
63,
14353,
63,
1160,
199,
2502,
26,
298,
36,
811,
1804,
305,
14630,
8593,
6341,
305,
14630,
2924,
199,
3612,
63,
1802,
26,
14944,
6258,
2897,
1808,
7009,
4079,
641,
5558,
641,
7256,
3879,
15757,
31445,
445,
23141,
199,
1802,
26,
272,
446,
961,
859,
6127,
1265,
370,
1736,
543,
314,
3879,
2897,
402,
282,
6258,
14,
2779,
6571,
282,
4340,
370,
1362,
5341,
282,
663,
402,
445,
23141,
3718,
641,
282,
6258,
701,
27083,
314,
1453,
3879,
2897,
436,
1362,
14043,
314,
3718,
1454,
340,
314,
2488,
2202,
1172,
440,
2757,
2575,
7526,
14,
1362,
710,
2897,
1350,
883,
506,
282,
663,
402,
3718,
503,
282,
1978,
5313,
315,
314,
17300,
18,
2388,
24615,
2637,
14,
1362,
961,
859,
3423,
314,
2011,
465,
314,
32535,
63,
1160,
859,
14,
1362,
710,
1454,
1919,
365,
626,
314,
2569,
8200,
1750,
883,
506,
2013,
1362,
359,
8477,
251,
5394,
275,
665,
4173,
1059,
30,
8477,
252,
61,
1362,
3979,
642,
8200,
1750,
365,
2013,
465,
314,
1750,
402,
282,
2120,
12,
314,
1978,
365,
7934,
367,
1362,
314,
2784,
1819,
626,
4450,
314,
3305,
1059,
14,
24612,
12,
7009,
787,
1202,
1380,
3718,
787,
314,
1362,
2011,
9371,
282,
1572,
402,
2784,
7256,
14,
3979,
2337,
365,
282,
10685,
370,
3372,
314,
6451,
402,
314,
1362,
1978,
641,
1373,
503,
1655,
7256,
12,
652,
365,
14318,
370,
675,
642,
859,
14,
1362,
961,
859,
4440,
12027,
370,
9635,
2784,
2243,
2897,
14,
1362,
2104,
1655,
2556,
3595,
642,
859,
687,
15757,
31445,
436,
3537,
9147,
652,
4503,
367,
2195,
1362,
675,
5560,
12,
8749,
5684,
738,
8,
1014,
921,
2253,
88,
14,
552,
31445,
1725,
14,
957,
15,
3437,
15,
1080,
14,
74,
681,
31,
5746,
2458,
18,
38,
957,
14,
552,
31445,
14,
5656,
77,
3308,
14,
4853,
14,
1301,
5,
18,
38,
6413,
736,
63,
14353,
63,
1160,
14,
1360,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
11036,
63,
9970,
63,
7677,
26,
32535,
199,
1419,
26,
272,
1414,
493,
26,
267,
1369,
26,
288,
446,
961,
9314,
314,
931,
370,
314,
445,
23141,
1414,
570,
1314,
4839,
370,
506,
6781,
14,
961,
9987,
1467,
12477,
687,
314,
3718,
4922,
14,
1464,
1183,
642,
570,
365,
314,
1072,
402,
314,
2860,
6781,
1467,
641,
282,
1978,
570,
14,
2002,
642,
1414,
365,
9222,
770,
701,
282,
1978,
859,
14,
1467,
710,
1414,
570,
1471,
1395,
314,
2622,
4252,
8448,
8200,
63,
4269,
3586,
436,
314,
5558,
1467,
3305,
315,
2399,
1788,
370,
4868,
626,
314,
1414,
570,
365,
3747,
367,
1924,
6258,
436,
5558,
14,
1467,
982,
642,
365,
11684,
12,
314,
1414,
570,
911,
506,
20200,
5309,
8494,
14,
2104,
2893,
12,
1467,
1414,
493,
29,
13186,
4405,
15,
1251,
83,
63,
8914,
63,
10132,
63,
3638,
8200,
63,
4269,
3586,
63,
9257,
2025,
63,
4405,
14,
2424,
267,
1415,
26,
2549,
267,
849,
26,
12119,
272,
5558,
26,
267,
1369,
26,
288,
446,
982,
1265,
4165,
5558,
18987,
4173,
1059,
30,
315,
314,
8200,
570,
6169,
1263,
2243,
12,
314,
1978,
1467,
6451,
365,
4224,
367,
626,
2243,
315,
1930,
652,
4450,
314,
3305,
4260,
367,
626,
2120,
14,
267,
1415,
26,
2549,
267,
849,
26,
12119,
272,
3305,
26,
267,
1369,
26,
288,
446,
982,
282,
2120,
4839,
370,
506,
7934,
12,
1265,
1172,
370,
663,
314,
3305,
314,
2011,
465,
652,
365,
2013,
315,
1467,
314,
8200,
367,
626,
2243,
14,
267,
1415,
26,
2549,
267,
849,
26,
12119,
199,
2344,
199,
8918,
275,
1449,
199,
19295,
520,
710,
2569,
787,
7251,
402,
1808,
314,
859,
32535,
63,
14353,
63,
1160,
14,
5723,
787,
5313,
315,
314,
2446,
14,
11714,
570,
402,
314,
6527,
2082,
14,
199,
2595,
199,
13,
536,
26,
4693,
6670,
14214,
1978,
641,
812,
44,
1254,
377,
4446,
17,
27836,
17711,
17,
523,
32535,
63,
14353,
63,
1160,
26,
489,
1591,
26,
7370,
8200,
63,
4269,
7820,
489,
3434,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
2473,
418,
7820,
489,
2505,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
2060,
418,
7820,
489,
31343,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
1782,
804,
418,
7820,
489,
32513,
26,
26069,
2604,
15,
86,
1823,
63,
17,
13949,
63,
8914,
63,
5656,
17,
63,
3638,
8200,
63,
4269,
3586,
63,
1199,
14,
2424,
2,
489,
5558,
26,
7370,
21835,
59,
7212,
63,
4269,
2733,
5394,
418,
30618,
489,
3305,
26,
298,
8914,
63,
5656,
17,
2,
489,
1414,
493,
26,
26069,
4405,
15,
86,
1823,
63,
17,
13949,
63,
8914,
63,
5656,
17,
63,
3638,
8200,
63,
4269,
3586,
63,
4405,
14,
2424,
2,
489,
4756,
6139,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
rafaelcor/turtleclick
|
Xlib/support/lock.py
|
2
|
1591
|
# $Id: lock.py,v 1.2 2007/06/10 14:11:58 mggrant Exp $
#
# Xlib.support.lock -- allocate a lock
#
# Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
#
# 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
class _DummyLock:
def __init__(self):
# This might be nerdy, but by assigning methods like this
# instead of defining them all, we create a single bound
# method object once instead of one each time one of the
# methods is called.
# This gives some speed improvements which should reduce the
# impact of the threading infrastructure in the regular code,
# when not using threading.
self.acquire = self.release = self.locked = self.__noop
def __noop(self, *args):
return
# More optimisations: we use a single lock for all lock instances
_dummy_lock = _DummyLock()
def allocate_lock():
return _dummy_lock
|
gpl-2.0
|
[
3,
2672,
1304,
26,
4650,
14,
647,
12,
86,
413,
14,
18,
10219,
15,
1690,
15,
709,
4329,
26,
845,
26,
2010,
32581,
17362,
7910,
2672,
199,
3,
199,
3,
1323,
773,
14,
4058,
14,
831,
1553,
18310,
282,
4650,
199,
3,
199,
3,
259,
1898,
334,
35,
9,
12293,
22912,
491,
382,
74,
287,
14630,
665,
8096,
317,
32,
12476,
13,
67,
14,
317,
85,
14,
261,
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,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
199,
533,
485,
11324,
6432,
26,
272,
347,
636,
826,
721,
277,
304,
398,
327,
961,
5594,
506,
302,
281,
8161,
12,
1325,
701,
26694,
3102,
2839,
642,
267,
327,
3140,
402,
12669,
3062,
1006,
12,
781,
1218,
282,
2849,
3914,
267,
327,
1083,
909,
5403,
3140,
402,
1373,
1924,
900,
1373,
402,
314,
267,
327,
3102,
365,
2797,
14,
398,
327,
961,
10557,
2005,
8112,
19053,
1470,
1314,
1077,
7114,
314,
267,
327,
25568,
402,
314,
5796,
28890,
6976,
315,
314,
5578,
1233,
12,
267,
327,
1380,
440,
1808,
5796,
14,
398,
291,
14,
8174,
275,
291,
14,
3221,
275,
291,
14,
9325,
275,
291,
855,
12921,
339,
347,
636,
12921,
8,
277,
12,
627,
589,
304,
267,
372,
421,
199,
3,
16917,
1687,
280,
1292,
1298,
26,
781,
675,
282,
2849,
4650,
367,
1006,
4650,
4454,
199,
63,
5869,
63,
831,
275,
485,
11324,
6432,
342,
199,
199,
318,
18310,
63,
831,
837,
272,
372,
485,
5869,
63,
831,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2672,
1304,
26,
4650,
14,
647,
12,
86,
413,
14,
18,
10219,
15,
1690,
15,
709,
4329,
26,
845,
26,
2010,
32581,
17362,
7910,
2672,
199,
3,
199,
3,
1323,
773,
14,
4058,
14,
831,
1553,
18310,
282,
4650,
199,
3,
199,
3,
259,
1898,
334,
35,
9,
12293,
22912,
491,
382,
74,
287,
14630,
665,
8096,
317,
32,
12476,
13,
67,
14,
317,
85,
14,
261,
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,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
199,
533,
485,
11324,
6432,
26,
272,
347,
636,
826,
721,
277,
304,
398,
327,
961,
5594,
506,
302,
281,
8161,
12,
1325,
701,
26694,
3102,
2839,
642,
267,
327,
3140,
402,
12669,
3062,
1006,
12,
781,
1218,
282,
2849,
3914,
267,
327,
1083,
909,
5403,
3140,
402,
1373,
1924,
900,
1373,
402,
314,
267,
327,
3102,
365,
2797,
14,
398,
327,
961,
10557,
2005,
8112,
19053,
1470,
1314,
1077,
7114,
314,
267,
327,
25568,
402,
314,
5796,
28890,
6976,
315,
314,
5578,
1233,
12,
267,
327,
1380,
440,
1808,
5796,
14,
398,
291,
14,
8174,
275,
291,
14,
3221,
275,
291,
14,
9325,
275,
291,
855,
12921,
339,
347,
636,
12921,
8,
277,
12,
627,
589,
304,
267,
372,
421,
199,
3,
16917,
1687,
280,
1292,
1298,
26,
781,
675,
282,
2849,
4650,
367,
1006,
4650,
4454,
199,
63,
5869,
63,
831,
275,
485,
11324,
6432,
342,
199,
199,
318,
18310,
63,
831,
837,
272,
372,
485,
5869,
63,
831,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tkdchen/nitrate-xmlrpc
|
nitratexmlrpc/api/testcaserun.py
|
1
|
23763
|
# -*- coding: utf-8 -*-
#
# Nitrate is copyright 2010 Red Hat, Inc.
#
# Nitrate 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 warranties of TITLE, NON-INFRINGEMENT,
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# The GPL text is available in the file COPYING that accompanies this
# distribution and at <http://www.gnu.org/licenses>.
#
# Authors:
# Xuqing Kuang <xkuang@redhat.com>
from kobo.django.xmlrpc.decorators import user_passes_test, login_required, log_call
from nitrate.apps.testruns.models import TestCaseRun, TestCaseRunStatus
from utils import pre_process_ids
from nitrate.core.utils.xmlrpc import XMLRPCSerializer
from nitrate.core.contrib.linkreference.models import create_link, LinkReference
__all__ = (
'add_comment',
'attach_bug',
'attach_log',
'check_case_run_status',
'create',
'detach_bug',
'detach_log',
'filter',
'filter_count',
'get',
'get_s',
'get_bugs',
'get_bugs_s',
'get_case_run_status',
'get_completion_time',
'get_completion_time_s',
'get_history',
'get_history_s',
'get_logs',
'lookup_status_name_by_id',
'lookup_status_id_by_name',
'update',
)
class GetCaseRun(object):
def pre_process_tcr(self, case_run_id):
return TestCaseRun.objects.get(pk = case_run_id)
def pre_process_tcr_s(self, run_id, case_id, build_id, environment_id = 0):
query = {
'run__pk': run_id,
'case__pk': case_id,
'build__pk': build_id
}
if environment_id:
query['environment_id'] = environment_id
return TestCaseRun.objects.get(**query)
return TestCaseRun.objects.get(**query)
gcr = GetCaseRun()
@log_call
def add_comment(request, case_run_ids, comment):
"""
Description: Adds comments to selected test case runs.
Params: $case_run_ids - Integer/Array/String: An integer representing the ID in the database,
an array of case_run_ids, or a string of comma separated case_run_ids.
$comment - String - The comment
Returns: Array: empty on success or an array of hashes with failure
codes if a failure occured.
Example:
# Add comment 'foobar' to case run 1234
>>> TestCaseRun.add_comment(1234, 'foobar')
# Add 'foobar' to case runs list [56789, 12345]
>>> TestCaseRun.add_comment([56789, 12345], 'foobar')
# Add 'foobar' to case runs list '56789, 12345' with String
>>> TestCaseRun.add_comment('56789, 12345', 'foobar')
"""
from utils import Comment
object_pks = pre_process_ids(value = case_run_ids)
c = Comment(
request = request,
content_type = 'testruns.testcaserun',
object_pks = object_pks,
comment = comment
)
return c.add()
@log_call
@user_passes_test(lambda u: u.has_perm('testcases.add_testcasebug'))
def attach_bug(request, values):
"""
Description: Add one or more bugs to the selected test cases.
Params: $values - Array/Hash: A reference to a hash or array of hashes with keys and values
matching the fields of the test case bug to be created.
+-------------------+----------------+-----------+------------------------+
| Field | Type | Null | Description |
+-------------------+----------------+-----------+------------------------+
| case_run_id | Integer | Required | ID of Case |
| bug_id | Integer | Required | ID of Bug |
| bug_system_id | Integer | Required | ID of Bug system |
| summary | String | Required | Bug summary |
| description | String | Required | Bug description |
+-------------------+----------------+-----------+------------------------+
Returns: Array: empty on success or an array of hashes with failure
codes if a failure occured.
Example:
>>> TestCaseRun.attach_bug({
'case_run_id': 12345,
'bug_id': 67890,
'bug_system_id': 1,
'summary': 'Testing TCMS',
'description': 'Just foo and bar',
})
"""
from nitrate.apps.testcases.models import TestCaseBugSystem
if isinstance(values, dict):
values = [values, ]
for value in values:
if not value.get('case_run_id'):
continue
if not value.get('bug_system_id'):
value['bug_system_id'] = 1
try:
bug_system = TestCaseBugSystem.objects.get(id = value['bug_system_id'])
except:
raise
try:
tcr = TestCaseRun.objects.get(case_run_id = value['case_run_id'])
tcr.add_bug(
bug_id = value['bug_id'],
bug_system = bug_system,
summary = value.get('summary'),
description = value.get('description')
)
except:
raise
return
def check_case_run_status(request, name):
"""
Params: $name - String: the status name.
Returns: Hash: Matching case run status object hash or error if not found.
Example:
>>> TestCaseRun.check_case_run_status('idle')
"""
return TestCaseRunStatus.objects.get(name = name).serialize()
@log_call
@user_passes_test(lambda u: u.has_perm('testruns.add_testcaserun'))
def create(request, values):
"""
*** It always report - ValueError: invalid literal for int() with base 10: '' ***
Description: Creates a new Test Case Run object and stores it in the database.
Params: $values - Hash: A reference to a hash with keys and values
matching the fields of the test case to be created.
+--------------------+----------------+-----------+------------------------------------------------+
| Field | Type | Null | Description |
+--------------------+----------------+-----------+------------------------------------------------+
| run | Integer | Required | ID of Test Run |
| case | Integer | Required | ID of test case |
| build | Integer | Required | ID of a Build in plan's product |
| assignee | Integer | Optional | ID of assignee |
| case_run_status | Integer | Optional | Defaults to "IDLE" |
| case_text_version | Integer | Optional | Default to latest case text version |
| notes | String | Optional | |
| sortkey | Integer | Optional | a.k.a. Index, Default to 0 |
+--------------------+----------------+-----------+------------------------------------------------+
Returns: The newly created object hash.
Example:
# Minimal test case parameters
>>> values = {
'run': 1990,
'case': 12345,
'build': 123,
}
>>> TestCaseRun.create(values)
"""
from nitrate.core import forms
from nitrate.apps.testcases.models import TestCase
from nitrate.apps.testruns.models import TestRun
from nitrate.apps.testruns.forms import XMLRPCNewCaseRunForm
form = XMLRPCNewCaseRunForm(values)
if form.is_valid():
tr = form.cleaned_data['run']
tcr = tr.add_case_run(
case = form.cleaned_data['case'],
build = form.cleaned_data['build'],
assignee = form.cleaned_data['assignee'],
case_run_status = form.cleaned_data['case_run_status'],
case_text_version = form.cleaned_data['case_text_version'],
notes = form.cleaned_data['notes'],
sortkey = form.cleaned_data['sortkey']
)
else:
return forms.errors_to_list(form)
return tcr.serialize()
@log_call
@user_passes_test(lambda u: u.has_perm('testcases.delete_testcasebug'))
def detach_bug(request, case_run_ids, bug_ids):
"""
Description: Remove one or more bugs to the selected test case-runs.
Params: $case_run_ids - Integer/Array/String: An integer or alias representing the ID in the database,
an array of case_run_ids, or a string of comma separated case_run_ids.
$bug_ids - Integer/Array/String: An integer representing the ID in the database,
an array of bug_ids, or a string of comma separated primary key of bug_ids.
Returns: Array: empty on success or an array of hashes with failure
codes if a failure occured.
Example:
# Remove bug id 54321 from case 1234
>>> TestCaseRun.detach_bug(1234, 54321)
# Remove bug ids list [1234, 5678] from cases list [56789, 12345]
>>> TestCaseRun.detach_bug([56789, 12345], [1234, 5678])
# Remove bug ids list '1234, 5678' from cases list '56789, 12345' with String
>>> TestCaseRun.detach_bug('56789, 12345', '1234, 5678')
"""
tcrs = TestCaseRun.objects.filter(
case_run_id__in = pre_process_ids(case_run_ids)
)
bug_ids = pre_process_ids(bug_ids)
for tcr in tcrs:
case_run_id = tcr.case_run_id
for opk in bug_ids:
try:
tcr.remove_bug(bug_id=opk, run_id=case_run_id)
except ObjectDoesNotExist, error:
pass
return
def filter(request, values = {}):
"""
Description: Performs a search and returns the resulting list of test cases.
Params: $values - Hash: keys must match valid search fields.
+----------------------------------------------------------------+
| Case-Run Search Parameters |
+----------------------------------------------------------------+
| Key | Valid Values |
| case_run_id | Integer |
| assignee | ForeignKey: Auth.User |
| build | ForeignKey: Build |
| case | ForeignKey: Test Case |
| case_run_status | ForeignKey: Case Run Status |
| is_current | 1: Only show current 0: show not current |
| notes | String |
| run | ForeignKey: Test Run |
| tested_by | ForeignKey: Auth.User |
| running_date | Datetime |
| close_date | Datetime |
+----------------------------------------------------------------+
Returns: Object: Matching test cases are retuned in a list of hashes.
Example:
# Get all case runs contain 'TCMS' in case summary
>>> TestCaseRun.filter({'case__summary__icontain': 'TCMS'})
"""
return TestCaseRun.to_xmlrpc(values)
def filter_count(request, values = {}):
"""
Description: Performs a search and returns the resulting count of cases.
Params: $query - Hash: keys must match valid search fields (see filter).
Returns: Integer - total matching cases.
Example:
# See TestCaseRun.filter()
"""
from nitrate.apps.testruns.models import TestCaseRun
return TestCaseRun.objects.filter(**values).count()
def get(request, case_run_id):
"""
Description: Used to load an existing test case-run from the database.
Params: $case_run_id - Integer: An integer representing the ID in
the database for this case-run.
Returns: A blessed TestCaseRun object hash
Example:
>>> TestCaseRun.get(1193)
"""
return gcr.pre_process_tcr(case_run_id = case_run_id).serialize()
def get_s(request, case_id, run_id, build_id, environment_id = 0):
"""
Description: Used to load an existing test case from the database.
Params: $case_id - Integer: An integer representing the ID of the test case in the database.
$run_id - Integer: An integer representing the ID of the test run in the database.
$build_id - Integer: An integer representing the ID of the test build in the database.
$environment_id - Optional Integer: An integer representing the ID of the environment in the database.
Returns: A blessed TestCaseRun object hash
Example:
>>> TestCaseRun.get_s(3113, 565, 72, 90)
"""
return gcr.pre_process_tcr_s(run_id, case_id, build_id, environment_id).serialize()
def get_bugs(request, case_run_id):
"""
Description: Get the list of bugs that are associated with this test case.
Params: $case_run_ids - Integer: An integer representing the ID in
the database for this case-run.
Returns: Array: An array of bug object hashes.
Example:
>>> TestCase.get_bugs(12345)
"""
from nitrate.apps.testcases.models import TestCaseBug
try:
tcr = gcr.pre_process_tcr(case_run_id = case_run_id)
except:
raise
query = {'case_run__case_run_id': tcr.case_run_id}
return TestCaseBug.to_xmlrpc(query)
def get_bugs_s(request, run_id, case_id, build_id, environment_id = 0):
"""
Description: Get the list of bugs that are associated with this test case.
Params: $case_id - Integer: An integer representing the ID of the test case in the database.
$run_id - Integer: An integer representing the ID of the test run in the database.
$build_id - Integer: An integer representing the ID of the test build in the database.
$environment_id - Optional Integer: An integer representing the ID of the environment in the database.
Returns: Array: An array of bug object hashes.
Example:
>>> TestCaseRun.get_bugs_s(3113, 565, 72, 90)
"""
from nitrate.apps.testcases.models import TestCaseBug
try:
tcr = gcr.pre_process_tcr_s(
run_id = run_id,
case_id = case_id,
build_id = build_id,
environment_id = environment_id,
)
except:
raise
query = {'case_run__case_run_id': tcr.case_run_id}
return TestCaseBug.to_xmlrpc(query)
def get_case_run_status(request, id = None):
"""
Params: $case_run_status_id - Integer(Optional): ID of the status to return
Returns: Hash: Matching case run status object hash when your specific the case_run_status_id
or return all of case run status.
It will return error the case run status you specific id not found.
Example:
# Get all of case run status
>>> TestCaseRun.get_case_run_status()
# Get case run status by ID 1
>>> TestCaseRun.get_case_run_status(1)
"""
if id:
return TestCaseRunStatus.objects.get(id = id).serialize()
return TestCaseRunStatus.to_xmlrpc()
def get_completion_time(request, case_run_id):
"""
Description: Returns the time in seconds that it took for this case to complete.
Params: $case_run_id - Integer: An integer representing the ID in
the database for this case-run.
Returns: Integer: Seconds since run was started till this case was completed.
Or empty hash for insufficent data.
Example:
>>> TestCaseRun.get_completion_time(1193)
"""
from nitrate.core.forms.widgets import SECONDS_PER_DAY
tcr = gcr.pre_process_tcr(case_run_id = case_run_id)
if not tcr.running_date or not tcr.close_date:
return
time = tcr.close_date - tcr.running_date
time = time.days * SECONDS_PER_DAY + time.seconds
return time
def get_completion_time_s(request, run_id, case_id, build_id, environment_id = 0):
"""
Description: Returns the time in seconds that it took for this case to complete.
Params: $case_id - Integer: An integer representing the ID of the test case in the database.
$run_id - Integer: An integer representing the ID of the test run in the database.
$build_id - Integer: An integer representing the ID of the test build in the database.
$environment_id - Optional Integer: An integer representing the ID of the environment in the database.
Returns: Integer: Seconds since run was started till this case was completed.
Or empty hash for insufficent data.
Example:
>>> TestCaseRun.get_completion_time_s(3113, 565, 72, 90)
"""
from nitrate.core.forms.widgets import SECONDS_PER_DAY
tcr = gcr.pre_process_tcr_s(
run_id = run_id,
case_id = case_id,
build_id = build_id,
environment_id = environment_id,
)
if not tcr.running_date or not tcr.close_date:
return
time = tcr.close_date - tcr.running_date
time = time.days * SECONDS_PER_DAY + time.seconds
return time
def get_history(request, case_run_id):
"""
*** FIXME: NOT IMPLEMENTED - Case history is different than before ***
Description: Get the list of case-runs for all runs this case appears in.
To limit this list by build or other attribute, see TestCaseRun.query
Params: $caserun_id - Integer: An integer representing the ID in
the database for this case-run.
Returns: Array: An array of case-run object hashes.
"""
pass
def get_history_s(request, run_id, build_id, environment_id):
"""
*** FIXME: NOT IMPLEMENTED - Case history is different than before ***
Description: Get the list of case-runs for all runs this case appears in.
To limit this list by build or other attribute, see TestCaseRun.filter.
Params: $case_id - Integer: An integer representing the ID of the test case in the database.
$run_id - Integer: An integer representing the ID of the test run in the database.
$build_id - Integer: An integer representing the ID of the test build in the database.
$environment_id - Integer: An integer representing the ID of the environment in the database.
Returns: Array: An array of case-run object hashes.
"""
raise NotImplementedError
def lookup_status_name_by_id(request, id):
"""
DEPRECATED - CONSIDERED HARMFUL Use TestCaseRun.get_case_run_status instead
"""
return get_case_run_status(request = request, id = id)
def lookup_status_id_by_name(request, name):
"""
DEPRECATED - CONSIDERED HARMFUL Use TestCaseRun.check_case_run_status instead
"""
return check_case_run_status(request = request, name = name)
@log_call
@user_passes_test(lambda u: u.has_perm('testruns.change_testcaserun'))
def update(request, case_run_ids, values):
"""
Description: Updates the fields of the selected case-runs.
Params: $caserun_ids - Integer/String/Array
Integer: A single TestCaseRun ID.
String: A comma separates string of TestCaseRun IDs for batch
processing.
Array: An array of TestCaseRun IDs for batch mode processing
$values - Hash of keys matching TestCaseRun fields and the new values
to set each field to.
+--------------------+----------------+
| Field | Type |
+--------------------+----------------+
| build | Integer |
| assignee | Integer |
| case_run_status | Integer |
| notes | String |
| sortkey | Integer |
+--------------------+----------------+
Returns: Hash/Array: In the case of a single object, it is returned. If a
list was passed, it returns an array of object hashes. If the
update on any particular object failed, the hash will contain a
ERROR key and the message as to why it failed.
Example:
# Update alias to 'tcms' for case 12345 and 23456
>>> TestCaseRun.update([12345, 23456], {'assignee': 2206})
"""
from datetime import datetime
from nitrate.core import forms
from nitrate.apps.testruns.forms import XMLRPCUpdateCaseRunForm
tcrs = TestCaseRun.objects.filter(
pk__in = pre_process_ids(case_run_ids)
)
form = XMLRPCUpdateCaseRunForm(values)
if form.is_valid():
if form.cleaned_data['build']:
tcrs.update(build = form.cleaned_data['build'])
if form.cleaned_data['assignee']:
tcrs.update(assignee = form.cleaned_data['assignee'])
if form.cleaned_data['case_run_status']:
tcrs.update(case_run_status = form.cleaned_data['case_run_status'])
tcrs.update(tested_by = request.user)
tcrs.update(close_date = datetime.now())
if values.has_key('notes'):
if values['notes'] in (None, ''):
tcrs.update(notes = values['notes'])
if form.cleaned_data['notes']:
tcrs.update(notes = form.cleaned_data['notes'])
if form.cleaned_data['sortkey']:
tcrs.update(sortkey = form.cleaned_data['sortkey'])
else:
return forms.errors_to_list(form)
query = {'pk__in': tcrs.values_list('pk', flat = True)}
return TestCaseRun.to_xmlrpc(query)
def attach_log(request, case_run_id, name, url):
"""
Description: Add new log link to TestCaseRun
Params: $caserun_id - Integer
$name - String: A short description to this new link, and accept 64 characters at most.
$url - String: The actual URL.
"""
try:
test_case_run = TestCaseRun.objects.get(pk=case_run_id)
except ObjectDoesNotExist, error:
raise
create_link(name=name, url=url, link_to=test_case_run)
return
def detach_log(request, case_run_id, link_id):
"""
Description: Remove log link to TestCaseRun
Params: $case_run_id - Integer
$link_id - Integer: Id of LinkReference instance
"""
try:
test_case_run = TestCaseRun.objects.get(pk=case_run_id)
except ObjectDoesNotExist, error:
raise
try:
LinkReference.unlink(link_id)
except:
raise
return
def get_logs(request, case_run_id):
"""
Description: Get log links to TestCaseRun
Params: $case_run_id - Integer:
"""
try:
test_case_run = TestCaseRun.objects.get(pk=case_run_id)
except ObjectDoesNotExist, error:
raise
links = LinkReference.get_from(test_case_run)
s = XMLRPCSerializer(links)
return s.serialize_queryset()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
653,
390,
1866,
365,
4248,
7129,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
653,
390,
1866,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
961,
2240,
365,
1854,
315,
199,
3,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
199,
3,
2755,
314,
2478,
3712,
1417,
402,
377,
16507,
12,
11214,
13,
12799,
12,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
199,
3,
710,
14629,
1318,
365,
2808,
315,
314,
570,
9685,
626,
1066,
863,
23461,
642,
199,
3,
4084,
436,
737,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
10827,
199,
3,
199,
3,
6642,
26,
199,
3,
257,
1323,
85,
81,
316,
1804,
85,
621,
665,
88,
20661,
621,
32,
17164,
14,
957,
30,
199,
199,
504,
20817,
656,
14,
1176,
14,
17596,
14,
11582,
492,
922,
63,
16027,
63,
396,
12,
4676,
63,
2427,
12,
943,
63,
1250,
199,
504,
302,
390,
1866,
14,
5181,
14,
396,
10802,
14,
992,
492,
7640,
2540,
12,
7640,
2540,
3694,
199,
504,
3778,
492,
876,
63,
1412,
63,
1580,
199,
504,
302,
390,
1866,
14,
1018,
14,
1208,
14,
17596,
492,
4692,
8171,
7299,
199,
504,
302,
390,
1866,
14,
1018,
14,
2828,
14,
1073,
4443,
14,
992,
492,
1218,
63,
1073,
12,
10967,
5083,
4388,
199,
363,
452,
363,
275,
334,
272,
283,
525,
63,
3349,
297,
272,
283,
5040,
63,
1266,
297,
272,
283,
5040,
63,
793,
297,
272,
283,
1074,
63,
2546,
63,
1065,
63,
1205,
297,
272,
283,
981,
297,
272,
283,
14481,
63,
1266,
297,
272,
283,
14481,
63,
793,
297,
272,
283,
1541,
297,
272,
283,
1541,
63,
835,
297,
272,
283,
362,
297,
272,
283,
362,
63,
83,
297,
272,
283,
362,
63,
13017,
297,
272,
283,
362,
63,
13017,
63,
83,
297,
272,
283,
362,
63,
2546,
63,
1065,
63,
1205,
297,
272,
283,
362,
63,
13207,
63,
521,
297,
272,
283,
362,
63,
13207,
63,
521,
63,
83,
297,
272,
283,
362,
63,
5570,
297,
272,
283,
362,
63,
5570,
63,
83,
297,
272,
283,
362,
63,
7270,
297,
272,
283,
3892,
63,
1205,
63,
354,
63,
991,
63,
344,
297,
272,
283,
3892,
63,
1205,
63,
344,
63,
991,
63,
354,
297,
272,
283,
873,
297,
199,
9,
199,
199,
533,
2372,
1538,
2540,
8,
785,
304,
272,
347,
876,
63,
1412,
63,
84,
1556,
8,
277,
12,
1930,
63,
1065,
63,
344,
304,
267,
372,
7640,
2540,
14,
1462,
14,
362,
8,
2051,
275,
1930,
63,
1065,
63,
344,
9,
339,
347,
876,
63,
1412,
63,
84,
1556,
63,
83,
8,
277,
12,
1255,
63,
344,
12,
1930,
63,
344,
12,
1900,
63,
344,
12,
3734,
63,
344,
275,
378,
304,
267,
1827,
275,
469,
288,
283,
1065,
363,
2051,
356,
1255,
63,
344,
12,
288,
283,
2546,
363,
2051,
356,
1930,
63,
344,
12,
288,
283,
1506,
363,
2051,
356,
1900,
63,
344,
267,
789,
398,
340,
3734,
63,
344,
26,
288,
1827,
459,
5418,
63,
344,
418,
275,
3734,
63,
344,
288,
372,
7640,
2540,
14,
1462,
14,
362,
3682,
1131,
9,
398,
372,
7640,
2540,
14,
1462,
14,
362,
3682,
1131,
9,
199,
199,
71,
1556,
275,
2372,
1538,
2540,
342,
421,
199,
32,
793,
63,
1250,
199,
318,
1050,
63,
3349,
8,
1069,
12,
1930,
63,
1065,
63,
1580,
12,
3721,
304,
272,
408,
272,
11994,
26,
15747,
6786,
370,
4895,
511,
1930,
7858,
14,
339,
30370,
26,
420,
2672,
2546,
63,
1065,
63,
1580,
446,
7225,
15,
3836,
15,
1558,
26,
1626,
3000,
6144,
314,
2870,
315,
314,
3050,
12,
2490,
376,
1625,
402,
1930,
63,
1065,
63,
1580,
12,
503,
282,
1059,
402,
10029,
11673,
1930,
63,
1065,
63,
1580,
14,
199,
326,
2672,
3349,
446,
2624,
446,
710,
3721,
339,
1803,
26,
258,
8725,
26,
2701,
641,
3182,
503,
376,
1625,
402,
14647,
543,
5988,
717,
9479,
340,
282,
5988,
28408,
14,
339,
5679,
26,
272,
327,
2654,
3721,
283,
9664,
7,
370,
1930,
1255,
14763,
272,
1306,
7640,
2540,
14,
525,
63,
3349,
8,
4321,
12,
283,
9664,
358,
272,
327,
2654,
283,
9664,
7,
370,
1930,
7858,
769,
359,
6690,
12,
25538,
61,
272,
1306,
7640,
2540,
14,
525,
63,
3349,
779,
6690,
12,
25538,
467,
283,
9664,
358,
272,
327,
2654,
283,
9664,
7,
370,
1930,
7858,
769,
283,
6690,
12,
25538,
7,
543,
2624,
272,
1306,
7640,
2540,
14,
525,
63,
3349,
360,
6690,
12,
25538,
297,
283,
9664,
358,
272,
408,
272,
687,
3778,
492,
6819,
272,
909,
63,
27323,
275,
876,
63,
1412,
63,
1580,
8,
585,
275,
1930,
63,
1065,
63,
1580,
9,
272,
286,
275,
6819,
8,
267,
1056,
275,
1056,
12,
267,
1564,
63,
466,
275,
283,
396,
10802,
14,
396,
696,
332,
324,
297,
267,
909,
63,
27323,
275,
909,
63,
27323,
12,
267,
3721,
275,
3721,
272,
776,
339,
372,
286,
14,
525,
342,
199,
199,
32,
793,
63,
1250,
199,
32,
751,
63,
16027,
63,
396,
8,
2734,
399,
26,
399,
14,
1989,
63,
8220,
360,
396,
9403,
14,
525,
63,
10847,
1266,
1333,
199,
318,
6554,
63,
1266,
8,
1069,
12,
1338,
304,
272,
408,
272,
11994,
26,
2654,
1373,
503,
1655,
18227,
370,
314,
4895,
511,
5560,
14,
339,
30370,
26,
258,
2672,
1459,
446,
8725,
15,
3476,
26,
437,
3659,
370,
282,
2631,
503,
1625,
402,
14647,
543,
2883,
436,
1338,
4228,
4877,
314,
1504,
402,
314,
511,
1930,
6519,
370,
506,
2737,
14,
2541,
24680,
9018,
777,
11,
27592,
777,
518,
11,
489,
1204,
5024,
3777,
1204,
2434,
3698,
1204,
12119,
420,
1204,
11994,
3322,
1204,
489,
24680,
9018,
777,
11,
27592,
777,
518,
11,
489,
1204,
1930,
63,
1065,
63,
344,
755,
1204,
7225,
263,
1204,
11105,
221,
1204,
2870,
402,
12425,
3777,
1204,
489,
1204,
6519
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
653,
390,
1866,
365,
4248,
7129,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
653,
390,
1866,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
961,
2240,
365,
1854,
315,
199,
3,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
199,
3,
2755,
314,
2478,
3712,
1417,
402,
377,
16507,
12,
11214,
13,
12799,
12,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
199,
3,
710,
14629,
1318,
365,
2808,
315,
314,
570,
9685,
626,
1066,
863,
23461,
642,
199,
3,
4084,
436,
737,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
10827,
199,
3,
199,
3,
6642,
26,
199,
3,
257,
1323,
85,
81,
316,
1804,
85,
621,
665,
88,
20661,
621,
32,
17164,
14,
957,
30,
199,
199,
504,
20817,
656,
14,
1176,
14,
17596,
14,
11582,
492,
922,
63,
16027,
63,
396,
12,
4676,
63,
2427,
12,
943,
63,
1250,
199,
504,
302,
390,
1866,
14,
5181,
14,
396,
10802,
14,
992,
492,
7640,
2540,
12,
7640,
2540,
3694,
199,
504,
3778,
492,
876,
63,
1412,
63,
1580,
199,
504,
302,
390,
1866,
14,
1018,
14,
1208,
14,
17596,
492,
4692,
8171,
7299,
199,
504,
302,
390,
1866,
14,
1018,
14,
2828,
14,
1073,
4443,
14,
992,
492,
1218,
63,
1073,
12,
10967,
5083,
4388,
199,
363,
452,
363,
275,
334,
272,
283,
525,
63,
3349,
297,
272,
283,
5040,
63,
1266,
297,
272,
283,
5040,
63,
793,
297,
272,
283,
1074,
63,
2546,
63,
1065,
63,
1205,
297,
272,
283,
981,
297,
272,
283,
14481,
63,
1266,
297,
272,
283,
14481,
63,
793,
297,
272,
283,
1541,
297,
272,
283,
1541,
63,
835,
297,
272,
283,
362,
297,
272,
283,
362,
63,
83,
297,
272,
283,
362,
63,
13017,
297,
272,
283,
362,
63,
13017,
63,
83,
297,
272,
283,
362,
63,
2546,
63,
1065,
63,
1205,
297,
272,
283,
362,
63,
13207,
63,
521,
297,
272,
283,
362,
63,
13207,
63,
521,
63,
83,
297,
272,
283,
362,
63,
5570,
297,
272,
283,
362,
63,
5570,
63,
83,
297,
272,
283,
362,
63,
7270,
297,
272,
283,
3892,
63,
1205,
63,
354,
63,
991,
63,
344,
297,
272,
283,
3892,
63,
1205,
63,
344,
63,
991,
63,
354,
297,
272,
283,
873,
297,
199,
9,
199,
199,
533,
2372,
1538,
2540,
8,
785,
304,
272,
347,
876,
63,
1412,
63,
84,
1556,
8,
277,
12,
1930,
63,
1065,
63,
344,
304,
267,
372,
7640,
2540,
14,
1462,
14,
362,
8,
2051,
275,
1930,
63,
1065,
63,
344,
9,
339,
347,
876,
63,
1412,
63,
84,
1556,
63,
83,
8,
277,
12,
1255,
63,
344,
12,
1930,
63,
344,
12,
1900,
63,
344,
12,
3734,
63,
344,
275,
378,
304,
267,
1827,
275,
469,
288,
283,
1065,
363,
2051,
356,
1255,
63,
344,
12,
288,
283,
2546,
363,
2051,
356,
1930,
63,
344,
12,
288,
283,
1506,
363,
2051,
356,
1900,
63,
344,
267,
789,
398,
340,
3734,
63,
344,
26,
288,
1827,
459,
5418,
63,
344,
418,
275,
3734,
63,
344,
288,
372,
7640,
2540,
14,
1462,
14,
362,
3682,
1131,
9,
398,
372,
7640,
2540,
14,
1462,
14,
362,
3682,
1131,
9,
199,
199,
71,
1556,
275,
2372,
1538,
2540,
342,
421,
199,
32,
793,
63,
1250,
199,
318,
1050,
63,
3349,
8,
1069,
12,
1930,
63,
1065,
63,
1580,
12,
3721,
304,
272,
408,
272,
11994,
26,
15747,
6786,
370,
4895,
511,
1930,
7858,
14,
339,
30370,
26,
420,
2672,
2546,
63,
1065,
63,
1580,
446,
7225,
15,
3836,
15,
1558,
26,
1626,
3000,
6144,
314,
2870,
315,
314,
3050,
12,
2490,
376,
1625,
402,
1930,
63,
1065,
63,
1580,
12,
503,
282,
1059,
402,
10029,
11673,
1930,
63,
1065,
63,
1580,
14,
199,
326,
2672,
3349,
446,
2624,
446,
710,
3721,
339,
1803,
26,
258,
8725,
26,
2701,
641,
3182,
503,
376,
1625,
402,
14647,
543,
5988,
717,
9479,
340,
282,
5988,
28408,
14,
339,
5679,
26,
272,
327,
2654,
3721,
283,
9664,
7,
370,
1930,
1255,
14763,
272,
1306,
7640,
2540,
14,
525,
63,
3349,
8,
4321,
12,
283,
9664,
358,
272,
327,
2654,
283,
9664,
7,
370,
1930,
7858,
769,
359,
6690,
12,
25538,
61,
272,
1306,
7640,
2540,
14,
525,
63,
3349,
779,
6690,
12,
25538,
467,
283,
9664,
358,
272,
327,
2654,
283,
9664,
7,
370,
1930,
7858,
769,
283,
6690,
12,
25538,
7,
543,
2624,
272,
1306,
7640,
2540,
14,
525,
63,
3349,
360,
6690,
12,
25538,
297,
283,
9664,
358,
272,
408,
272,
687,
3778,
492,
6819,
272,
909,
63,
27323,
275,
876,
63,
1412,
63,
1580,
8,
585,
275,
1930,
63,
1065,
63,
1580,
9,
272,
286,
275,
6819,
8,
267,
1056,
275,
1056,
12,
267,
1564,
63,
466,
275,
283,
396,
10802,
14,
396,
696,
332,
324,
297,
267,
909,
63,
27323,
275,
909,
63,
27323,
12,
267,
3721,
275,
3721,
272,
776,
339,
372,
286,
14,
525,
342,
199,
199,
32,
793,
63,
1250,
199,
32,
751,
63,
16027,
63,
396,
8,
2734,
399,
26,
399,
14,
1989,
63,
8220,
360,
396,
9403,
14,
525,
63,
10847,
1266,
1333,
199,
318,
6554,
63,
1266,
8,
1069,
12,
1338,
304,
272,
408,
272,
11994,
26,
2654,
1373,
503,
1655,
18227,
370,
314,
4895,
511,
5560,
14,
339,
30370,
26,
258,
2672,
1459,
446,
8725,
15,
3476,
26,
437,
3659,
370,
282,
2631,
503,
1625,
402,
14647,
543,
2883,
436,
1338,
4228,
4877,
314,
1504,
402,
314,
511,
1930,
6519,
370,
506,
2737,
14,
2541,
24680,
9018,
777,
11,
27592,
777,
518,
11,
489,
1204,
5024,
3777,
1204,
2434,
3698,
1204,
12119,
420,
1204,
11994,
3322,
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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
] |
tntraina/aff4
|
scons-local-1.2.0/SCons/Tool/mingw.py
|
12
|
5682
|
"""SCons.Tool.gcc
Tool-specific initialization for MinGW (http://www.mingw.org/)
There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.
"""
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
#
# 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.
#
__revision__ = "src/engine/SCons/Tool/mingw.py 3842 2008/12/20 22:59:52 scons"
import os
import os.path
import string
import SCons.Action
import SCons.Builder
import SCons.Defaults
import SCons.Tool
import SCons.Util
# This is what we search for to find mingw:
key_program = 'mingw32-gcc'
def find(env):
# First search in the SCons path and then the OS path:
return env.WhereIs(key_program) or SCons.Util.WhereIs(key_program)
def shlib_generator(target, source, env, for_signature):
cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
if dll: cmd.extend(['-o', dll])
cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
return [cmd]
def shlib_emitter(target, source, env):
dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
no_import_lib = env.get('no_import_lib', 0)
if not dll:
raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
if not no_import_lib and \
not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
# Append an import library to the list of targets.
target.append(env.ReplaceIxes(dll,
'SHLIBPREFIX', 'SHLIBSUFFIX',
'LIBPREFIX', 'LIBSUFFIX'))
# Append a def file target if there isn't already a def file target
# or a def file source. There is no option to disable def file
# target emitting, because I can't figure out why someone would ever
# want to turn it off.
def_source = env.FindIxes(source, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
if not def_source and not def_target:
target.append(env.ReplaceIxes(dll,
'SHLIBPREFIX', 'SHLIBSUFFIX',
'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX'))
return (target, source)
shlib_action = SCons.Action.Action(shlib_generator, generator=1)
res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
source_scanner=SCons.Tool.SourceFileScanner)
SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
def generate(env):
mingw = find(env)
if mingw:
dir = os.path.dirname(mingw)
env.PrependENVPath('PATH', dir )
# Most of mingw is the same as gcc and friends...
gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'm4']
for tool in gnu_tools:
SCons.Tool.Tool(tool)(env)
#... but a few things differ:
env['CC'] = 'gcc'
env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
env['CXX'] = 'g++'
env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
env['SHLINKCOM'] = shlib_action
env['LDMODULECOM'] = shlib_action
env.Append(SHLIBEMITTER = [shlib_emitter])
env['AS'] = 'as'
env['WIN32DEFPREFIX'] = ''
env['WIN32DEFSUFFIX'] = '.def'
env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
env['SHOBJSUFFIX'] = '.o'
env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
env['RC'] = 'windres'
env['RCFLAGS'] = SCons.Util.CLVar('')
env['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, RCINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
env['RCINCPREFIX'] = '--include-dir '
env['RCINCSUFFIX'] = ''
env['RCCOM'] = '$RC $_CPPDEFFLAGS $RCINCFLAGS ${RCINCPREFIX} ${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
env['BUILDERS']['RES'] = res_builder
# Some setting from the platform also have to be overridden:
env['OBJSUFFIX'] = '.o'
env['LIBPREFIX'] = 'lib'
env['LIBSUFFIX'] = '.a'
def exists(env):
return find(env)
|
gpl-3.0
|
[
624,
18521,
14,
5157,
14,
13112,
199,
199,
5157,
13,
6100,
11097,
367,
10195,
19674,
334,
1014,
921,
1544,
14,
14566,
87,
14,
1308,
24793,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
199,
624,
199,
199,
3,
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,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
14566,
87,
14,
647,
650,
18931,
9079,
15,
713,
15,
1165,
6928,
26,
1427,
26,
2528,
31551,
2,
199,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
1059,
199,
199,
646,
8218,
14,
3310,
199,
646,
8218,
14,
6437,
199,
646,
8218,
14,
16986,
199,
646,
8218,
14,
5157,
199,
646,
8218,
14,
9562,
199,
199,
3,
961,
365,
4052,
781,
2754,
367,
370,
2342,
333,
316,
87,
26,
199,
498,
63,
6815,
275,
283,
14566,
87,
708,
13,
13112,
7,
199,
199,
318,
2342,
8,
1813,
304,
272,
327,
7758,
2754,
315,
314,
8218,
931,
436,
2066,
314,
4403,
931,
26,
272,
372,
2589,
14,
26493,
1831,
8,
498,
63,
6815,
9,
503,
8218,
14,
9562,
14,
26493,
1831,
8,
498,
63,
6815,
9,
199,
199,
318,
1033,
773,
63,
4679,
8,
1375,
12,
1350,
12,
2589,
12,
367,
63,
5233,
304,
272,
2088,
275,
8218,
14,
9562,
14,
1981,
5894,
2941,
4,
3234,
7916,
297,
4505,
3234,
30388,
1105,
18407,
17112,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
3234,
5617,
6351,
297,
283,
3234,
5617,
12273,
358,
272,
340,
17112,
26,
2088,
14,
2880,
24829,
79,
297,
17112,
566,
339,
2088,
14,
2880,
2941,
4,
25744,
297,
4505,
63,
5617,
3022,
4831,
297,
4505,
63,
5617,
4831,
1105,
339,
1742,
773,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
5617,
6351,
297,
283,
5617,
12273,
358,
272,
340,
1742,
773,
26,
2088,
14,
740,
3654,
16239,
28925,
548,
13,
3236,
773,
2584,
11,
3236,
773,
14,
362,
63,
875,
8,
509,
63,
5233,
430,
339,
347,
63,
1375,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
20509,
5638,
6351,
297,
283,
20509,
5638,
12273,
358,
272,
340,
347,
63,
1375,
26,
2088,
14,
740,
3654,
16239,
28925,
1199,
13,
318,
2584,
11,
318,
63,
1375,
14,
362,
63,
875,
8,
509,
63,
5233,
430,
339,
372,
359,
1760,
61,
199,
199,
318,
1033,
773,
63,
8159,
351,
8,
1375,
12,
1350,
12,
2589,
304,
272,
17112,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
3234,
5617,
6351,
297,
283,
3234,
5617,
12273,
358,
272,
949,
63,
646,
63,
773,
275,
2589,
14,
362,
360,
889,
63,
646,
63,
773,
297,
378,
9,
339,
340,
440,
17112,
26,
267,
746,
8218,
14,
9298,
14,
1899,
547,
12,
298,
33,
5709,
3555,
1077,
1172,
8840,
1373,
1347,
543,
314,
4739,
26,
450,
83,
2,
450,
2589,
14,
16747,
21506,
3234,
5617,
12273,
531,
2286,
340,
440,
949,
63,
646,
63,
773,
436,
971,
2126,
440,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
5617,
6351,
297,
283,
5617,
12273,
735,
398,
327,
18726,
376,
492,
3555,
370,
314,
769,
402,
4545,
14,
267,
1347,
14,
740,
8,
1813,
14,
11328,
41,
12908,
8,
9259,
12,
257,
4228,
283,
3234,
5617,
6351,
297,
283,
3234,
5617,
12273,
297,
4228,
283,
5617,
6351,
297,
283,
5617,
12273,
1333,
339,
327,
18726,
282,
347,
570,
1347,
340,
2337,
5712,
1133,
2575,
282,
347,
570,
1347,
272,
327,
503,
282,
347,
570,
1350,
14,
6006,
365,
949,
945,
370,
3507,
347,
570,
272,
327,
1347,
8689,
1337,
12,
2952,
473,
883,
1133,
9658,
734,
10842,
17122,
3955,
14433,
272,
327,
2934,
370,
7485,
652,
2331,
14,
272,
347,
63,
1365,
275,
2589,
14,
6591,
41,
12908,
8,
1365,
12,
283,
20509,
5638,
6351,
297,
283,
20509,
5638,
12273,
358,
272,
347,
63,
1375,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
20509,
5638,
6351,
297,
283,
20509,
5638,
12273,
358,
272,
340,
440,
347,
63,
1365,
436,
440,
347,
63,
1375,
26,
267,
1347,
14,
740,
8,
1813,
14,
11328,
41,
12908,
8,
9259,
12,
257,
4228,
283,
3234,
5617,
6351,
297,
283,
3234,
5617,
12273,
297,
4228,
283,
20509,
5638,
6351,
297,
283,
20509,
5638,
12273,
1333,
2286,
372,
334,
1375,
12,
1350,
9,
2079,
199,
199,
609,
773,
63,
1287,
275,
8218,
14,
3310,
14,
3310,
8,
609,
773,
63,
4679,
12,
4306,
29,
17,
9,
199,
199,
470,
63,
1287,
275,
8218,
14,
3310,
14,
3310,
14676,
8205,
11265,
297,
4505,
8205,
11265,
3027
] |
[
18521,
14,
5157,
14,
13112,
199,
199,
5157,
13,
6100,
11097,
367,
10195,
19674,
334,
1014,
921,
1544,
14,
14566,
87,
14,
1308,
24793,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
199,
624,
199,
199,
3,
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,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
14566,
87,
14,
647,
650,
18931,
9079,
15,
713,
15,
1165,
6928,
26,
1427,
26,
2528,
31551,
2,
199,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
1059,
199,
199,
646,
8218,
14,
3310,
199,
646,
8218,
14,
6437,
199,
646,
8218,
14,
16986,
199,
646,
8218,
14,
5157,
199,
646,
8218,
14,
9562,
199,
199,
3,
961,
365,
4052,
781,
2754,
367,
370,
2342,
333,
316,
87,
26,
199,
498,
63,
6815,
275,
283,
14566,
87,
708,
13,
13112,
7,
199,
199,
318,
2342,
8,
1813,
304,
272,
327,
7758,
2754,
315,
314,
8218,
931,
436,
2066,
314,
4403,
931,
26,
272,
372,
2589,
14,
26493,
1831,
8,
498,
63,
6815,
9,
503,
8218,
14,
9562,
14,
26493,
1831,
8,
498,
63,
6815,
9,
199,
199,
318,
1033,
773,
63,
4679,
8,
1375,
12,
1350,
12,
2589,
12,
367,
63,
5233,
304,
272,
2088,
275,
8218,
14,
9562,
14,
1981,
5894,
2941,
4,
3234,
7916,
297,
4505,
3234,
30388,
1105,
18407,
17112,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
3234,
5617,
6351,
297,
283,
3234,
5617,
12273,
358,
272,
340,
17112,
26,
2088,
14,
2880,
24829,
79,
297,
17112,
566,
339,
2088,
14,
2880,
2941,
4,
25744,
297,
4505,
63,
5617,
3022,
4831,
297,
4505,
63,
5617,
4831,
1105,
339,
1742,
773,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
5617,
6351,
297,
283,
5617,
12273,
358,
272,
340,
1742,
773,
26,
2088,
14,
740,
3654,
16239,
28925,
548,
13,
3236,
773,
2584,
11,
3236,
773,
14,
362,
63,
875,
8,
509,
63,
5233,
430,
339,
347,
63,
1375,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
20509,
5638,
6351,
297,
283,
20509,
5638,
12273,
358,
272,
340,
347,
63,
1375,
26,
2088,
14,
740,
3654,
16239,
28925,
1199,
13,
318,
2584,
11,
318,
63,
1375,
14,
362,
63,
875,
8,
509,
63,
5233,
430,
339,
372,
359,
1760,
61,
199,
199,
318,
1033,
773,
63,
8159,
351,
8,
1375,
12,
1350,
12,
2589,
304,
272,
17112,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
3234,
5617,
6351,
297,
283,
3234,
5617,
12273,
358,
272,
949,
63,
646,
63,
773,
275,
2589,
14,
362,
360,
889,
63,
646,
63,
773,
297,
378,
9,
339,
340,
440,
17112,
26,
267,
746,
8218,
14,
9298,
14,
1899,
547,
12,
298,
33,
5709,
3555,
1077,
1172,
8840,
1373,
1347,
543,
314,
4739,
26,
450,
83,
2,
450,
2589,
14,
16747,
21506,
3234,
5617,
12273,
531,
2286,
340,
440,
949,
63,
646,
63,
773,
436,
971,
2126,
440,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
5617,
6351,
297,
283,
5617,
12273,
735,
398,
327,
18726,
376,
492,
3555,
370,
314,
769,
402,
4545,
14,
267,
1347,
14,
740,
8,
1813,
14,
11328,
41,
12908,
8,
9259,
12,
257,
4228,
283,
3234,
5617,
6351,
297,
283,
3234,
5617,
12273,
297,
4228,
283,
5617,
6351,
297,
283,
5617,
12273,
1333,
339,
327,
18726,
282,
347,
570,
1347,
340,
2337,
5712,
1133,
2575,
282,
347,
570,
1347,
272,
327,
503,
282,
347,
570,
1350,
14,
6006,
365,
949,
945,
370,
3507,
347,
570,
272,
327,
1347,
8689,
1337,
12,
2952,
473,
883,
1133,
9658,
734,
10842,
17122,
3955,
14433,
272,
327,
2934,
370,
7485,
652,
2331,
14,
272,
347,
63,
1365,
275,
2589,
14,
6591,
41,
12908,
8,
1365,
12,
283,
20509,
5638,
6351,
297,
283,
20509,
5638,
12273,
358,
272,
347,
63,
1375,
275,
2589,
14,
6591,
41,
12908,
8,
1375,
12,
283,
20509,
5638,
6351,
297,
283,
20509,
5638,
12273,
358,
272,
340,
440,
347,
63,
1365,
436,
440,
347,
63,
1375,
26,
267,
1347,
14,
740,
8,
1813,
14,
11328,
41,
12908,
8,
9259,
12,
257,
4228,
283,
3234,
5617,
6351,
297,
283,
3234,
5617,
12273,
297,
4228,
283,
20509,
5638,
6351,
297,
283,
20509,
5638,
12273,
1333,
2286,
372,
334,
1375,
12,
1350,
9,
2079,
199,
199,
609,
773,
63,
1287,
275,
8218,
14,
3310,
14,
3310,
8,
609,
773,
63,
4679,
12,
4306,
29,
17,
9,
199,
199,
470,
63,
1287,
275,
8218,
14,
3310,
14,
3310,
14676,
8205,
11265,
297,
4505,
8205,
11265,
3027,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yawnosnorous/python-for-android
|
python3-alpha/extra_modules/gdata/youtube/service.py
|
46
|
58047
|
#!/usr/bin/python
#
# Copyright (C) 2008 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""YouTubeService extends GDataService to streamline YouTube operations.
YouTubeService: Provides methods to perform CRUD operations on YouTube feeds.
Extends GDataService.
"""
__author__ = ('api.stephaniel@gmail.com (Stephanie Liu), '
'api.jhartmann@gmail.com (Jochen Hartmann)')
try:
from xml.etree import cElementTree as ElementTree
except ImportError:
try:
import cElementTree as ElementTree
except ImportError:
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
import os
import atom
import gdata
import gdata.service
import gdata.youtube
YOUTUBE_SERVER = 'gdata.youtube.com'
YOUTUBE_SERVICE = 'youtube'
YOUTUBE_CLIENTLOGIN_AUTHENTICATION_URL = 'https://www.google.com/youtube/accounts/ClientLogin'
YOUTUBE_SUPPORTED_UPLOAD_TYPES = ('mov', 'avi', 'wmv', 'mpg', 'quicktime',
'flv', 'mp4', 'x-flv')
YOUTUBE_QUERY_VALID_TIME_PARAMETERS = ('today', 'this_week', 'this_month',
'all_time')
YOUTUBE_QUERY_VALID_ORDERBY_PARAMETERS = ('published', 'viewCount', 'rating',
'relevance')
YOUTUBE_QUERY_VALID_RACY_PARAMETERS = ('include', 'exclude')
YOUTUBE_QUERY_VALID_FORMAT_PARAMETERS = ('1', '5', '6')
YOUTUBE_STANDARDFEEDS = ('most_recent', 'recently_featured',
'top_rated', 'most_viewed','watch_on_mobile')
YOUTUBE_UPLOAD_URI = 'https://uploads.gdata.youtube.com/feeds/api/users'
YOUTUBE_UPLOAD_TOKEN_URI = 'https://gdata.youtube.com/action/GetUploadToken'
YOUTUBE_VIDEO_URI = 'https://gdata.youtube.com/feeds/api/videos'
YOUTUBE_USER_FEED_URI = 'https://gdata.youtube.com/feeds/api/users'
YOUTUBE_PLAYLIST_FEED_URI = 'https://gdata.youtube.com/feeds/api/playlists'
YOUTUBE_STANDARD_FEEDS = 'https://gdata.youtube.com/feeds/api/standardfeeds'
YOUTUBE_STANDARD_TOP_RATED_URI = '%s/%s' % (YOUTUBE_STANDARD_FEEDS, 'top_rated')
YOUTUBE_STANDARD_MOST_VIEWED_URI = '%s/%s' % (YOUTUBE_STANDARD_FEEDS,
'most_viewed')
YOUTUBE_STANDARD_RECENTLY_FEATURED_URI = '%s/%s' % (YOUTUBE_STANDARD_FEEDS,
'recently_featured')
YOUTUBE_STANDARD_WATCH_ON_MOBILE_URI = '%s/%s' % (YOUTUBE_STANDARD_FEEDS,
'watch_on_mobile')
YOUTUBE_STANDARD_TOP_FAVORITES_URI = '%s/%s' % (YOUTUBE_STANDARD_FEEDS,
'top_favorites')
YOUTUBE_STANDARD_MOST_RECENT_URI = '%s/%s' % (YOUTUBE_STANDARD_FEEDS,
'most_recent')
YOUTUBE_STANDARD_MOST_DISCUSSED_URI = '%s/%s' % (YOUTUBE_STANDARD_FEEDS,
'most_discussed')
YOUTUBE_STANDARD_MOST_LINKED_URI = '%s/%s' % (YOUTUBE_STANDARD_FEEDS,
'most_linked')
YOUTUBE_STANDARD_MOST_RESPONDED_URI = '%s/%s' % (YOUTUBE_STANDARD_FEEDS,
'most_responded')
YOUTUBE_SCHEMA = 'http://gdata.youtube.com/schemas'
YOUTUBE_RATING_LINK_REL = '%s#video.ratings' % YOUTUBE_SCHEMA
YOUTUBE_COMPLAINT_CATEGORY_SCHEME = '%s/%s' % (YOUTUBE_SCHEMA,
'complaint-reasons.cat')
YOUTUBE_SUBSCRIPTION_CATEGORY_SCHEME = '%s/%s' % (YOUTUBE_SCHEMA,
'subscriptiontypes.cat')
YOUTUBE_COMPLAINT_CATEGORY_TERMS = ('PORN', 'VIOLENCE', 'HATE', 'DANGEROUS',
'RIGHTS', 'SPAM')
YOUTUBE_CONTACT_STATUS = ('accepted', 'rejected')
YOUTUBE_CONTACT_CATEGORY = ('Friends', 'Family')
UNKOWN_ERROR = 1000
YOUTUBE_BAD_REQUEST = 400
YOUTUBE_CONFLICT = 409
YOUTUBE_INTERNAL_SERVER_ERROR = 500
YOUTUBE_INVALID_ARGUMENT = 601
YOUTUBE_INVALID_CONTENT_TYPE = 602
YOUTUBE_NOT_A_VIDEO = 603
YOUTUBE_INVALID_KIND = 604
class Error(Exception):
"""Base class for errors within the YouTube service."""
pass
class RequestError(Error):
"""Error class that is thrown in response to an invalid HTTP Request."""
pass
class YouTubeError(Error):
"""YouTube service specific error class."""
pass
class YouTubeService(gdata.service.GDataService):
"""Client for the YouTube service.
Performs all documented Google Data YouTube API functions, such as inserting,
updating and deleting videos, comments, playlist, subscriptions etc.
YouTube Service requires authentication for any write, update or delete
actions.
Attributes:
email: An optional string identifying the user. Required only for
authenticated actions.
password: An optional string identifying the user's password.
source: An optional string identifying the name of your application.
server: An optional address of the YouTube API server. gdata.youtube.com
is provided as the default value.
additional_headers: An optional dictionary containing additional headers
to be passed along with each request. Use to store developer key.
client_id: An optional string identifying your application, required for
authenticated requests, along with a developer key.
developer_key: An optional string value. Register your application at
http://code.google.com/apis/youtube/dashboard to obtain a (free) key.
"""
ssl = True
def __init__(self, email=None, password=None, source=None,
server=YOUTUBE_SERVER, additional_headers=None, client_id=None,
developer_key=None, **kwargs):
"""Creates a client for the YouTube service.
Args:
email: string (optional) The user's email address, used for
authentication.
password: string (optional) The user's password.
source: string (optional) The name of the user's application.
server: string (optional) The name of the server to which a connection
will be opened. Default value: 'gdata.youtube.com'.
client_id: string (optional) Identifies your application, required for
authenticated requests, along with a developer key.
developer_key: string (optional) Register your application at
http://code.google.com/apis/youtube/dashboard to obtain a (free) key.
**kwargs: The other parameters to pass to gdata.service.GDataService
constructor.
"""
gdata.service.GDataService.__init__(
self, email=email, password=password, service=YOUTUBE_SERVICE,
source=source, server=server, additional_headers=additional_headers,
**kwargs)
if client_id is not None:
self.additional_headers['X-Gdata-Client'] = client_id
if developer_key is not None:
self.additional_headers['X-GData-Key'] = 'key=%s' % developer_key
self.auth_service_url = YOUTUBE_CLIENTLOGIN_AUTHENTICATION_URL
def GetYouTubeVideoFeed(self, uri):
"""Retrieve a YouTubeVideoFeed.
Args:
uri: A string representing the URI of the feed that is to be retrieved.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.Get(uri, converter=gdata.youtube.YouTubeVideoFeedFromString)
def GetYouTubeVideoEntry(self, uri=None, video_id=None):
"""Retrieve a YouTubeVideoEntry.
Either a uri or a video_id must be provided.
Args:
uri: An optional string representing the URI of the entry that is to
be retrieved.
video_id: An optional string representing the ID of the video.
Returns:
A YouTubeVideoFeed if successfully retrieved.
Raises:
YouTubeError: You must provide at least a uri or a video_id to the
GetYouTubeVideoEntry() method.
"""
if uri is None and video_id is None:
raise YouTubeError('You must provide at least a uri or a video_id '
'to the GetYouTubeVideoEntry() method')
elif video_id and not uri:
uri = '%s/%s' % (YOUTUBE_VIDEO_URI, video_id)
return self.Get(uri, converter=gdata.youtube.YouTubeVideoEntryFromString)
def GetYouTubeContactFeed(self, uri=None, username='default'):
"""Retrieve a YouTubeContactFeed.
Either a uri or a username must be provided.
Args:
uri: An optional string representing the URI of the contact feed that
is to be retrieved.
username: An optional string representing the username. Defaults to the
currently authenticated user.
Returns:
A YouTubeContactFeed if successfully retrieved.
Raises:
YouTubeError: You must provide at least a uri or a username to the
GetYouTubeContactFeed() method.
"""
if uri is None:
uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, username, 'contacts')
return self.Get(uri, converter=gdata.youtube.YouTubeContactFeedFromString)
def GetYouTubeContactEntry(self, uri):
"""Retrieve a YouTubeContactEntry.
Args:
uri: A string representing the URI of the contact entry that is to
be retrieved.
Returns:
A YouTubeContactEntry if successfully retrieved.
"""
return self.Get(uri, converter=gdata.youtube.YouTubeContactEntryFromString)
def GetYouTubeVideoCommentFeed(self, uri=None, video_id=None):
"""Retrieve a YouTubeVideoCommentFeed.
Either a uri or a video_id must be provided.
Args:
uri: An optional string representing the URI of the comment feed that
is to be retrieved.
video_id: An optional string representing the ID of the video for which
to retrieve the comment feed.
Returns:
A YouTubeVideoCommentFeed if successfully retrieved.
Raises:
YouTubeError: You must provide at least a uri or a video_id to the
GetYouTubeVideoCommentFeed() method.
"""
if uri is None and video_id is None:
raise YouTubeError('You must provide at least a uri or a video_id '
'to the GetYouTubeVideoCommentFeed() method')
elif video_id and not uri:
uri = '%s/%s/%s' % (YOUTUBE_VIDEO_URI, video_id, 'comments')
return self.Get(
uri, converter=gdata.youtube.YouTubeVideoCommentFeedFromString)
def GetYouTubeVideoCommentEntry(self, uri):
"""Retrieve a YouTubeVideoCommentEntry.
Args:
uri: A string representing the URI of the comment entry that is to
be retrieved.
Returns:
A YouTubeCommentEntry if successfully retrieved.
"""
return self.Get(
uri, converter=gdata.youtube.YouTubeVideoCommentEntryFromString)
def GetYouTubeUserFeed(self, uri=None, username=None):
"""Retrieve a YouTubeVideoFeed of user uploaded videos
Either a uri or a username must be provided. This will retrieve list
of videos uploaded by specified user. The uri will be of format
"http://gdata.youtube.com/feeds/api/users/{username}/uploads".
Args:
uri: An optional string representing the URI of the user feed that is
to be retrieved.
username: An optional string representing the username.
Returns:
A YouTubeUserFeed if successfully retrieved.
Raises:
YouTubeError: You must provide at least a uri or a username to the
GetYouTubeUserFeed() method.
"""
if uri is None and username is None:
raise YouTubeError('You must provide at least a uri or a username '
'to the GetYouTubeUserFeed() method')
elif username and not uri:
uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, username, 'uploads')
return self.Get(uri, converter=gdata.youtube.YouTubeUserFeedFromString)
def GetYouTubeUserEntry(self, uri=None, username=None):
"""Retrieve a YouTubeUserEntry.
Either a uri or a username must be provided.
Args:
uri: An optional string representing the URI of the user entry that is
to be retrieved.
username: An optional string representing the username.
Returns:
A YouTubeUserEntry if successfully retrieved.
Raises:
YouTubeError: You must provide at least a uri or a username to the
GetYouTubeUserEntry() method.
"""
if uri is None and username is None:
raise YouTubeError('You must provide at least a uri or a username '
'to the GetYouTubeUserEntry() method')
elif username and not uri:
uri = '%s/%s' % (YOUTUBE_USER_FEED_URI, username)
return self.Get(uri, converter=gdata.youtube.YouTubeUserEntryFromString)
def GetYouTubePlaylistFeed(self, uri=None, username='default'):
"""Retrieve a YouTubePlaylistFeed (a feed of playlists for a user).
Either a uri or a username must be provided.
Args:
uri: An optional string representing the URI of the playlist feed that
is to be retrieved.
username: An optional string representing the username. Defaults to the
currently authenticated user.
Returns:
A YouTubePlaylistFeed if successfully retrieved.
Raises:
YouTubeError: You must provide at least a uri or a username to the
GetYouTubePlaylistFeed() method.
"""
if uri is None:
uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, username, 'playlists')
return self.Get(uri, converter=gdata.youtube.YouTubePlaylistFeedFromString)
def GetYouTubePlaylistEntry(self, uri):
"""Retrieve a YouTubePlaylistEntry.
Args:
uri: A string representing the URI of the playlist feed that is to
be retrieved.
Returns:
A YouTubePlaylistEntry if successfully retrieved.
"""
return self.Get(uri, converter=gdata.youtube.YouTubePlaylistEntryFromString)
def GetYouTubePlaylistVideoFeed(self, uri=None, playlist_id=None):
"""Retrieve a YouTubePlaylistVideoFeed (a feed of videos on a playlist).
Either a uri or a playlist_id must be provided.
Args:
uri: An optional string representing the URI of the playlist video feed
that is to be retrieved.
playlist_id: An optional string representing the Id of the playlist whose
playlist video feed is to be retrieved.
Returns:
A YouTubePlaylistVideoFeed if successfully retrieved.
Raises:
YouTubeError: You must provide at least a uri or a playlist_id to the
GetYouTubePlaylistVideoFeed() method.
"""
if uri is None and playlist_id is None:
raise YouTubeError('You must provide at least a uri or a playlist_id '
'to the GetYouTubePlaylistVideoFeed() method')
elif playlist_id and not uri:
uri = '%s/%s' % (YOUTUBE_PLAYLIST_FEED_URI, playlist_id)
return self.Get(
uri, converter=gdata.youtube.YouTubePlaylistVideoFeedFromString)
def GetYouTubeVideoResponseFeed(self, uri=None, video_id=None):
"""Retrieve a YouTubeVideoResponseFeed.
Either a uri or a playlist_id must be provided.
Args:
uri: An optional string representing the URI of the video response feed
that is to be retrieved.
video_id: An optional string representing the ID of the video whose
response feed is to be retrieved.
Returns:
A YouTubeVideoResponseFeed if successfully retrieved.
Raises:
YouTubeError: You must provide at least a uri or a video_id to the
GetYouTubeVideoResponseFeed() method.
"""
if uri is None and video_id is None:
raise YouTubeError('You must provide at least a uri or a video_id '
'to the GetYouTubeVideoResponseFeed() method')
elif video_id and not uri:
uri = '%s/%s/%s' % (YOUTUBE_VIDEO_URI, video_id, 'responses')
return self.Get(
uri, converter=gdata.youtube.YouTubeVideoResponseFeedFromString)
def GetYouTubeVideoResponseEntry(self, uri):
"""Retrieve a YouTubeVideoResponseEntry.
Args:
uri: A string representing the URI of the video response entry that
is to be retrieved.
Returns:
A YouTubeVideoResponseEntry if successfully retrieved.
"""
return self.Get(
uri, converter=gdata.youtube.YouTubeVideoResponseEntryFromString)
def GetYouTubeSubscriptionFeed(self, uri=None, username='default'):
"""Retrieve a YouTubeSubscriptionFeed.
Either the uri of the feed or a username must be provided.
Args:
uri: An optional string representing the URI of the feed that is to
be retrieved.
username: An optional string representing the username whose subscription
feed is to be retrieved. Defaults to the currently authenticted user.
Returns:
A YouTubeVideoSubscriptionFeed if successfully retrieved.
"""
if uri is None:
uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, username, 'subscriptions')
return self.Get(
uri, converter=gdata.youtube.YouTubeSubscriptionFeedFromString)
def GetYouTubeSubscriptionEntry(self, uri):
"""Retrieve a YouTubeSubscriptionEntry.
Args:
uri: A string representing the URI of the entry that is to be retrieved.
Returns:
A YouTubeVideoSubscriptionEntry if successfully retrieved.
"""
return self.Get(
uri, converter=gdata.youtube.YouTubeSubscriptionEntryFromString)
def GetYouTubeRelatedVideoFeed(self, uri=None, video_id=None):
"""Retrieve a YouTubeRelatedVideoFeed.
Either a uri for the feed or a video_id is required.
Args:
uri: An optional string representing the URI of the feed that is to
be retrieved.
video_id: An optional string representing the ID of the video for which
to retrieve the related video feed.
Returns:
A YouTubeRelatedVideoFeed if successfully retrieved.
Raises:
YouTubeError: You must provide at least a uri or a video_id to the
GetYouTubeRelatedVideoFeed() method.
"""
if uri is None and video_id is None:
raise YouTubeError('You must provide at least a uri or a video_id '
'to the GetYouTubeRelatedVideoFeed() method')
elif video_id and not uri:
uri = '%s/%s/%s' % (YOUTUBE_VIDEO_URI, video_id, 'related')
return self.Get(
uri, converter=gdata.youtube.YouTubeVideoFeedFromString)
def GetTopRatedVideoFeed(self):
"""Retrieve the 'top_rated' standard video feed.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.GetYouTubeVideoFeed(YOUTUBE_STANDARD_TOP_RATED_URI)
def GetMostViewedVideoFeed(self):
"""Retrieve the 'most_viewed' standard video feed.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.GetYouTubeVideoFeed(YOUTUBE_STANDARD_MOST_VIEWED_URI)
def GetRecentlyFeaturedVideoFeed(self):
"""Retrieve the 'recently_featured' standard video feed.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.GetYouTubeVideoFeed(YOUTUBE_STANDARD_RECENTLY_FEATURED_URI)
def GetWatchOnMobileVideoFeed(self):
"""Retrieve the 'watch_on_mobile' standard video feed.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.GetYouTubeVideoFeed(YOUTUBE_STANDARD_WATCH_ON_MOBILE_URI)
def GetTopFavoritesVideoFeed(self):
"""Retrieve the 'top_favorites' standard video feed.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.GetYouTubeVideoFeed(YOUTUBE_STANDARD_TOP_FAVORITES_URI)
def GetMostRecentVideoFeed(self):
"""Retrieve the 'most_recent' standard video feed.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.GetYouTubeVideoFeed(YOUTUBE_STANDARD_MOST_RECENT_URI)
def GetMostDiscussedVideoFeed(self):
"""Retrieve the 'most_discussed' standard video feed.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.GetYouTubeVideoFeed(YOUTUBE_STANDARD_MOST_DISCUSSED_URI)
def GetMostLinkedVideoFeed(self):
"""Retrieve the 'most_linked' standard video feed.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.GetYouTubeVideoFeed(YOUTUBE_STANDARD_MOST_LINKED_URI)
def GetMostRespondedVideoFeed(self):
"""Retrieve the 'most_responded' standard video feed.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
return self.GetYouTubeVideoFeed(YOUTUBE_STANDARD_MOST_RESPONDED_URI)
def GetUserFavoritesFeed(self, username='default'):
"""Retrieve the favorites feed for a given user.
Args:
username: An optional string representing the username whose favorites
feed is to be retrieved. Defaults to the currently authenticated user.
Returns:
A YouTubeVideoFeed if successfully retrieved.
"""
favorites_feed_uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, username,
'favorites')
return self.GetYouTubeVideoFeed(favorites_feed_uri)
def InsertVideoEntry(self, video_entry, filename_or_handle,
youtube_username='default',
content_type='video/quicktime'):
"""Upload a new video to YouTube using the direct upload mechanism.
Needs authentication.
Args:
video_entry: The YouTubeVideoEntry to upload.
filename_or_handle: A file-like object or file name where the video
will be read from.
youtube_username: An optional string representing the username into whose
account this video is to be uploaded to. Defaults to the currently
authenticated user.
content_type: An optional string representing internet media type
(a.k.a. mime type) of the media object. Currently the YouTube API
supports these types:
o video/mpeg
o video/quicktime
o video/x-msvideo
o video/mp4
o video/x-flv
Returns:
The newly created YouTubeVideoEntry if successful.
Raises:
AssertionError: video_entry must be a gdata.youtube.VideoEntry instance.
YouTubeError: An error occurred trying to read the video file provided.
gdata.service.RequestError: An error occurred trying to upload the video
to the API server.
"""
# We need to perform a series of checks on the video_entry and on the
# file that we plan to upload, such as checking whether we have a valid
# video_entry and that the file is the correct type and readable, prior
# to performing the actual POST request.
try:
assert(isinstance(video_entry, gdata.youtube.YouTubeVideoEntry))
except AssertionError:
raise YouTubeError({'status':YOUTUBE_INVALID_ARGUMENT,
'body':'`video_entry` must be a gdata.youtube.VideoEntry instance',
'reason':'Found %s, not VideoEntry' % type(video_entry)
})
#majtype, mintype = content_type.split('/')
#
#try:
# assert(mintype in YOUTUBE_SUPPORTED_UPLOAD_TYPES)
#except (ValueError, AssertionError):
# raise YouTubeError({'status':YOUTUBE_INVALID_CONTENT_TYPE,
# 'body':'This is not a valid content type: %s' % content_type,
# 'reason':'Accepted content types: %s' %
# ['video/%s' % (t) for t in YOUTUBE_SUPPORTED_UPLOAD_TYPES]})
if (isinstance(filename_or_handle, str)
and os.path.exists(filename_or_handle)):
mediasource = gdata.MediaSource()
mediasource.setFile(filename_or_handle, content_type)
elif hasattr(filename_or_handle, 'read'):
import io
if hasattr(filename_or_handle, 'seek'):
filename_or_handle.seek(0)
file_handle = filename_or_handle
name = 'video'
if hasattr(filename_or_handle, 'name'):
name = filename_or_handle.name
mediasource = gdata.MediaSource(file_handle, content_type,
content_length=file_handle.len, file_name=name)
else:
raise YouTubeError({'status':YOUTUBE_INVALID_ARGUMENT, 'body':
'`filename_or_handle` must be a path name or a file-like object',
'reason': ('Found %s, not path name or object '
'with a .read() method' % type(filename_or_handle))})
upload_uri = '%s/%s/%s' % (YOUTUBE_UPLOAD_URI, youtube_username,
'uploads')
self.additional_headers['Slug'] = mediasource.file_name
# Using a nested try statement to retain Python 2.4 compatibility
try:
try:
return self.Post(video_entry, uri=upload_uri, media_source=mediasource,
converter=gdata.youtube.YouTubeVideoEntryFromString)
except gdata.service.RequestError as e:
raise YouTubeError(e.args[0])
finally:
del(self.additional_headers['Slug'])
def CheckUploadStatus(self, video_entry=None, video_id=None):
"""Check upload status on a recently uploaded video entry.
Needs authentication. Either video_entry or video_id must be provided.
Args:
video_entry: An optional YouTubeVideoEntry whose upload status to check
video_id: An optional string representing the ID of the uploaded video
whose status is to be checked.
Returns:
A tuple containing (video_upload_state, detailed_message) or None if
no status information is found.
Raises:
YouTubeError: You must provide at least a video_entry or a video_id to the
CheckUploadStatus() method.
"""
if video_entry is None and video_id is None:
raise YouTubeError('You must provide at least a uri or a video_id '
'to the CheckUploadStatus() method')
elif video_id and not video_entry:
video_entry = self.GetYouTubeVideoEntry(video_id=video_id)
control = video_entry.control
if control is not None:
draft = control.draft
if draft is not None:
if draft.text == 'yes':
yt_state = control.extension_elements[0]
if yt_state is not None:
state_value = yt_state.attributes['name']
message = ''
if yt_state.text is not None:
message = yt_state.text
return (state_value, message)
def GetFormUploadToken(self, video_entry, uri=YOUTUBE_UPLOAD_TOKEN_URI):
"""Receives a YouTube Token and a YouTube PostUrl from a YouTubeVideoEntry.
Needs authentication.
Args:
video_entry: The YouTubeVideoEntry to upload (meta-data only).
uri: An optional string representing the URI from where to fetch the
token information. Defaults to the YOUTUBE_UPLOADTOKEN_URI.
Returns:
A tuple containing the URL to which to post your video file, along
with the youtube token that must be included with your upload in the
form of: (post_url, youtube_token).
"""
try:
response = self.Post(video_entry, uri)
except gdata.service.RequestError as e:
raise YouTubeError(e.args[0])
tree = ElementTree.fromstring(response)
for child in tree:
if child.tag == 'url':
post_url = child.text
elif child.tag == 'token':
youtube_token = child.text
return (post_url, youtube_token)
def UpdateVideoEntry(self, video_entry):
"""Updates a video entry's meta-data.
Needs authentication.
Args:
video_entry: The YouTubeVideoEntry to update, containing updated
meta-data.
Returns:
An updated YouTubeVideoEntry on success or None.
"""
for link in video_entry.link:
if link.rel == 'edit':
edit_uri = link.href
return self.Put(video_entry, uri=edit_uri,
converter=gdata.youtube.YouTubeVideoEntryFromString)
def DeleteVideoEntry(self, video_entry):
"""Deletes a video entry.
Needs authentication.
Args:
video_entry: The YouTubeVideoEntry to be deleted.
Returns:
True if entry was deleted successfully.
"""
for link in video_entry.link:
if link.rel == 'edit':
edit_uri = link.href
return self.Delete(edit_uri)
def AddRating(self, rating_value, video_entry):
"""Add a rating to a video entry.
Needs authentication.
Args:
rating_value: The integer value for the rating (between 1 and 5).
video_entry: The YouTubeVideoEntry to be rated.
Returns:
True if the rating was added successfully.
Raises:
YouTubeError: rating_value must be between 1 and 5 in AddRating().
"""
if rating_value < 1 or rating_value > 5:
raise YouTubeError('rating_value must be between 1 and 5 in AddRating()')
entry = gdata.GDataEntry()
rating = gdata.youtube.Rating(min='1', max='5')
rating.extension_attributes['name'] = 'value'
rating.extension_attributes['value'] = str(rating_value)
entry.extension_elements.append(rating)
for link in video_entry.link:
if link.rel == YOUTUBE_RATING_LINK_REL:
rating_uri = link.href
return self.Post(entry, uri=rating_uri)
def AddComment(self, comment_text, video_entry):
"""Add a comment to a video entry.
Needs authentication. Note that each comment that is posted must contain
the video entry that it is to be posted to.
Args:
comment_text: A string representing the text of the comment.
video_entry: The YouTubeVideoEntry to be commented on.
Returns:
True if the comment was added successfully.
"""
content = atom.Content(text=comment_text)
comment_entry = gdata.youtube.YouTubeVideoCommentEntry(content=content)
comment_post_uri = video_entry.comments.feed_link[0].href
return self.Post(comment_entry, uri=comment_post_uri)
def AddVideoResponse(self, video_id_to_respond_to, video_response):
"""Add a video response.
Needs authentication.
Args:
video_id_to_respond_to: A string representing the ID of the video to be
responded to.
video_response: YouTubeVideoEntry to be posted as a response.
Returns:
True if video response was posted successfully.
"""
post_uri = '%s/%s/%s' % (YOUTUBE_VIDEO_URI, video_id_to_respond_to,
'responses')
return self.Post(video_response, uri=post_uri)
def DeleteVideoResponse(self, video_id, response_video_id):
"""Delete a video response.
Needs authentication.
Args:
video_id: A string representing the ID of video that contains the
response.
response_video_id: A string representing the ID of the video that was
posted as a response.
Returns:
True if video response was deleted succcessfully.
"""
delete_uri = '%s/%s/%s/%s' % (YOUTUBE_VIDEO_URI, video_id, 'responses',
response_video_id)
return self.Delete(delete_uri)
def AddComplaint(self, complaint_text, complaint_term, video_id):
"""Add a complaint for a particular video entry.
Needs authentication.
Args:
complaint_text: A string representing the complaint text.
complaint_term: A string representing the complaint category term.
video_id: A string representing the ID of YouTubeVideoEntry to
complain about.
Returns:
True if posted successfully.
Raises:
YouTubeError: Your complaint_term is not valid.
"""
if complaint_term not in YOUTUBE_COMPLAINT_CATEGORY_TERMS:
raise YouTubeError('Your complaint_term is not valid')
content = atom.Content(text=complaint_text)
category = atom.Category(term=complaint_term,
scheme=YOUTUBE_COMPLAINT_CATEGORY_SCHEME)
complaint_entry = gdata.GDataEntry(content=content, category=[category])
post_uri = '%s/%s/%s' % (YOUTUBE_VIDEO_URI, video_id, 'complaints')
return self.Post(complaint_entry, post_uri)
def AddVideoEntryToFavorites(self, video_entry, username='default'):
"""Add a video entry to a users favorite feed.
Needs authentication.
Args:
video_entry: The YouTubeVideoEntry to add.
username: An optional string representing the username to whose favorite
feed you wish to add the entry. Defaults to the currently
authenticated user.
Returns:
The posted YouTubeVideoEntry if successfully posted.
"""
post_uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, username, 'favorites')
return self.Post(video_entry, post_uri,
converter=gdata.youtube.YouTubeVideoEntryFromString)
def DeleteVideoEntryFromFavorites(self, video_id, username='default'):
"""Delete a video entry from the users favorite feed.
Needs authentication.
Args:
video_id: A string representing the ID of the video that is to be removed
username: An optional string representing the username of the user's
favorite feed. Defaults to the currently authenticated user.
Returns:
True if entry was successfully deleted.
"""
edit_link = '%s/%s/%s/%s' % (YOUTUBE_USER_FEED_URI, username, 'favorites',
video_id)
return self.Delete(edit_link)
def AddPlaylist(self, playlist_title, playlist_description,
playlist_private=None):
"""Add a new playlist to the currently authenticated users account.
Needs authentication.
Args:
playlist_title: A string representing the title for the new playlist.
playlist_description: A string representing the description of the
playlist.
playlist_private: An optional boolean, set to True if the playlist is
to be private.
Returns:
The YouTubePlaylistEntry if successfully posted.
"""
playlist_entry = gdata.youtube.YouTubePlaylistEntry(
title=atom.Title(text=playlist_title),
description=gdata.youtube.Description(text=playlist_description))
if playlist_private:
playlist_entry.private = gdata.youtube.Private()
playlist_post_uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, 'default',
'playlists')
return self.Post(playlist_entry, playlist_post_uri,
converter=gdata.youtube.YouTubePlaylistEntryFromString)
def UpdatePlaylist(self, playlist_id, new_playlist_title,
new_playlist_description, playlist_private=None,
username='default'):
"""Update a playlist with new meta-data.
Needs authentication.
Args:
playlist_id: A string representing the ID of the playlist to be updated.
new_playlist_title: A string representing a new title for the playlist.
new_playlist_description: A string representing a new description for the
playlist.
playlist_private: An optional boolean, set to True if the playlist is
to be private.
username: An optional string representing the username whose playlist is
to be updated. Defaults to the currently authenticated user.
Returns:
A YouTubePlaylistEntry if the update was successful.
"""
updated_playlist = gdata.youtube.YouTubePlaylistEntry(
title=atom.Title(text=new_playlist_title),
description=gdata.youtube.Description(text=new_playlist_description))
if playlist_private:
updated_playlist.private = gdata.youtube.Private()
playlist_put_uri = '%s/%s/playlists/%s' % (YOUTUBE_USER_FEED_URI, username,
playlist_id)
return self.Put(updated_playlist, playlist_put_uri,
converter=gdata.youtube.YouTubePlaylistEntryFromString)
def DeletePlaylist(self, playlist_uri):
"""Delete a playlist from the currently authenticated users playlists.
Needs authentication.
Args:
playlist_uri: A string representing the URI of the playlist that is
to be deleted.
Returns:
True if successfully deleted.
"""
return self.Delete(playlist_uri)
def AddPlaylistVideoEntryToPlaylist(
self, playlist_uri, video_id, custom_video_title=None,
custom_video_description=None):
"""Add a video entry to a playlist, optionally providing a custom title
and description.
Needs authentication.
Args:
playlist_uri: A string representing the URI of the playlist to which this
video entry is to be added.
video_id: A string representing the ID of the video entry to add.
custom_video_title: An optional string representing a custom title for
the video (only shown on the playlist).
custom_video_description: An optional string representing a custom
description for the video (only shown on the playlist).
Returns:
A YouTubePlaylistVideoEntry if successfully posted.
"""
playlist_video_entry = gdata.youtube.YouTubePlaylistVideoEntry(
atom_id=atom.Id(text=video_id))
if custom_video_title:
playlist_video_entry.title = atom.Title(text=custom_video_title)
if custom_video_description:
playlist_video_entry.description = gdata.youtube.Description(
text=custom_video_description)
return self.Post(playlist_video_entry, playlist_uri,
converter=gdata.youtube.YouTubePlaylistVideoEntryFromString)
def UpdatePlaylistVideoEntryMetaData(
self, playlist_uri, playlist_entry_id, new_video_title,
new_video_description, new_video_position):
"""Update the meta data for a YouTubePlaylistVideoEntry.
Needs authentication.
Args:
playlist_uri: A string representing the URI of the playlist that contains
the entry to be updated.
playlist_entry_id: A string representing the ID of the entry to be
updated.
new_video_title: A string representing the new title for the video entry.
new_video_description: A string representing the new description for
the video entry.
new_video_position: An integer representing the new position on the
playlist for the video.
Returns:
A YouTubePlaylistVideoEntry if the update was successful.
"""
playlist_video_entry = gdata.youtube.YouTubePlaylistVideoEntry(
title=atom.Title(text=new_video_title),
description=gdata.youtube.Description(text=new_video_description),
position=gdata.youtube.Position(text=str(new_video_position)))
playlist_put_uri = playlist_uri + '/' + playlist_entry_id
return self.Put(playlist_video_entry, playlist_put_uri,
converter=gdata.youtube.YouTubePlaylistVideoEntryFromString)
def DeletePlaylistVideoEntry(self, playlist_uri, playlist_video_entry_id):
"""Delete a playlist video entry from a playlist.
Needs authentication.
Args:
playlist_uri: A URI representing the playlist from which the playlist
video entry is to be removed from.
playlist_video_entry_id: A string representing id of the playlist video
entry that is to be removed.
Returns:
True if entry was successfully deleted.
"""
delete_uri = '%s/%s' % (playlist_uri, playlist_video_entry_id)
return self.Delete(delete_uri)
def AddSubscriptionToChannel(self, username_to_subscribe_to,
my_username = 'default'):
"""Add a new channel subscription to the currently authenticated users
account.
Needs authentication.
Args:
username_to_subscribe_to: A string representing the username of the
channel to which we want to subscribe to.
my_username: An optional string representing the name of the user which
we want to subscribe. Defaults to currently authenticated user.
Returns:
A new YouTubeSubscriptionEntry if successfully posted.
"""
subscription_category = atom.Category(
scheme=YOUTUBE_SUBSCRIPTION_CATEGORY_SCHEME,
term='channel')
subscription_username = gdata.youtube.Username(
text=username_to_subscribe_to)
subscription_entry = gdata.youtube.YouTubeSubscriptionEntry(
category=subscription_category,
username=subscription_username)
post_uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, my_username,
'subscriptions')
return self.Post(subscription_entry, post_uri,
converter=gdata.youtube.YouTubeSubscriptionEntryFromString)
def AddSubscriptionToFavorites(self, username, my_username = 'default'):
"""Add a new subscription to a users favorites to the currently
authenticated user's account.
Needs authentication
Args:
username: A string representing the username of the user's favorite feed
to subscribe to.
my_username: An optional string representing the username of the user
that is to be subscribed. Defaults to currently authenticated user.
Returns:
A new YouTubeSubscriptionEntry if successful.
"""
subscription_category = atom.Category(
scheme=YOUTUBE_SUBSCRIPTION_CATEGORY_SCHEME,
term='favorites')
subscription_username = gdata.youtube.Username(text=username)
subscription_entry = gdata.youtube.YouTubeSubscriptionEntry(
category=subscription_category,
username=subscription_username)
post_uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, my_username,
'subscriptions')
return self.Post(subscription_entry, post_uri,
converter=gdata.youtube.YouTubeSubscriptionEntryFromString)
def AddSubscriptionToQuery(self, query, my_username = 'default'):
"""Add a new subscription to a specific keyword query to the currently
authenticated user's account.
Needs authentication
Args:
query: A string representing the keyword query to subscribe to.
my_username: An optional string representing the username of the user
that is to be subscribed. Defaults to currently authenticated user.
Returns:
A new YouTubeSubscriptionEntry if successful.
"""
subscription_category = atom.Category(
scheme=YOUTUBE_SUBSCRIPTION_CATEGORY_SCHEME,
term='query')
subscription_query_string = gdata.youtube.QueryString(text=query)
subscription_entry = gdata.youtube.YouTubeSubscriptionEntry(
category=subscription_category,
query_string=subscription_query_string)
post_uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, my_username,
'subscriptions')
return self.Post(subscription_entry, post_uri,
converter=gdata.youtube.YouTubeSubscriptionEntryFromString)
def DeleteSubscription(self, subscription_uri):
"""Delete a subscription from the currently authenticated user's account.
Needs authentication.
Args:
subscription_uri: A string representing the URI of the subscription that
is to be deleted.
Returns:
True if deleted successfully.
"""
return self.Delete(subscription_uri)
def AddContact(self, contact_username, my_username='default'):
"""Add a new contact to the currently authenticated user's contact feed.
Needs authentication.
Args:
contact_username: A string representing the username of the contact
that you wish to add.
my_username: An optional string representing the username to whose
contact the new contact is to be added.
Returns:
A YouTubeContactEntry if added successfully.
"""
contact_category = atom.Category(
scheme = 'http://gdata.youtube.com/schemas/2007/contact.cat',
term = 'Friends')
contact_username = gdata.youtube.Username(text=contact_username)
contact_entry = gdata.youtube.YouTubeContactEntry(
category=contact_category,
username=contact_username)
contact_post_uri = '%s/%s/%s' % (YOUTUBE_USER_FEED_URI, my_username,
'contacts')
return self.Post(contact_entry, contact_post_uri,
converter=gdata.youtube.YouTubeContactEntryFromString)
def UpdateContact(self, contact_username, new_contact_status,
new_contact_category, my_username='default'):
"""Update a contact, providing a new status and a new category.
Needs authentication.
Args:
contact_username: A string representing the username of the contact
that is to be updated.
new_contact_status: A string representing the new status of the contact.
This can either be set to 'accepted' or 'rejected'.
new_contact_category: A string representing the new category for the
contact, either 'Friends' or 'Family'.
my_username: An optional string representing the username of the user
whose contact feed we are modifying. Defaults to the currently
authenticated user.
Returns:
A YouTubeContactEntry if updated succesfully.
Raises:
YouTubeError: New contact status must be within the accepted values. Or
new contact category must be within the accepted categories.
"""
if new_contact_status not in YOUTUBE_CONTACT_STATUS:
raise YouTubeError('New contact status must be one of %s' %
(' '.join(YOUTUBE_CONTACT_STATUS)))
if new_contact_category not in YOUTUBE_CONTACT_CATEGORY:
raise YouTubeError('New contact category must be one of %s' %
(' '.join(YOUTUBE_CONTACT_CATEGORY)))
contact_category = atom.Category(
scheme='http://gdata.youtube.com/schemas/2007/contact.cat',
term=new_contact_category)
contact_status = gdata.youtube.Status(text=new_contact_status)
contact_entry = gdata.youtube.YouTubeContactEntry(
category=contact_category,
status=contact_status)
contact_put_uri = '%s/%s/%s/%s' % (YOUTUBE_USER_FEED_URI, my_username,
'contacts', contact_username)
return self.Put(contact_entry, contact_put_uri,
converter=gdata.youtube.YouTubeContactEntryFromString)
def DeleteContact(self, contact_username, my_username='default'):
"""Delete a contact from a users contact feed.
Needs authentication.
Args:
contact_username: A string representing the username of the contact
that is to be deleted.
my_username: An optional string representing the username of the user's
contact feed from which to delete the contact. Defaults to the
currently authenticated user.
Returns:
True if the contact was deleted successfully
"""
contact_edit_uri = '%s/%s/%s/%s' % (YOUTUBE_USER_FEED_URI, my_username,
'contacts', contact_username)
return self.Delete(contact_edit_uri)
def _GetDeveloperKey(self):
"""Getter for Developer Key property.
Returns:
If the developer key has been set, a string representing the developer key
is returned or None.
"""
if 'X-GData-Key' in self.additional_headers:
return self.additional_headers['X-GData-Key'][4:]
else:
return None
def _SetDeveloperKey(self, developer_key):
"""Setter for Developer Key property.
Sets the developer key in the 'X-GData-Key' header. The actual value that
is set is 'key=' plus the developer_key that was passed.
"""
self.additional_headers['X-GData-Key'] = 'key=' + developer_key
developer_key = property(_GetDeveloperKey, _SetDeveloperKey,
doc="""The Developer Key property""")
def _GetClientId(self):
"""Getter for Client Id property.
Returns:
If the client_id has been set, a string representing it is returned
or None.
"""
if 'X-Gdata-Client' in self.additional_headers:
return self.additional_headers['X-Gdata-Client']
else:
return None
def _SetClientId(self, client_id):
"""Setter for Client Id property.
Sets the 'X-Gdata-Client' header.
"""
self.additional_headers['X-Gdata-Client'] = client_id
client_id = property(_GetClientId, _SetClientId,
doc="""The ClientId property""")
def Query(self, uri):
"""Performs a query and returns a resulting feed or entry.
Args:
uri: A string representing the URI of the feed that is to be queried.
Returns:
On success, a tuple in the form:
(boolean succeeded=True, ElementTree._Element result)
On failure, a tuple in the form:
(boolean succeeded=False, {'status': HTTP status code from server,
'reason': HTTP reason from the server,
'body': HTTP body of the server's response})
"""
result = self.Get(uri)
return result
def YouTubeQuery(self, query):
"""Performs a YouTube specific query and returns a resulting feed or entry.
Args:
query: A Query object or one if its sub-classes (YouTubeVideoQuery,
YouTubeUserQuery or YouTubePlaylistQuery).
Returns:
Depending on the type of Query object submitted returns either a
YouTubeVideoFeed, a YouTubeUserFeed, a YouTubePlaylistFeed. If the
Query object provided was not YouTube-related, a tuple is returned.
On success the tuple will be in this form:
(boolean succeeded=True, ElementTree._Element result)
On failure, the tuple will be in this form:
(boolean succeeded=False, {'status': HTTP status code from server,
'reason': HTTP reason from the server,
'body': HTTP body of the server response})
"""
result = self.Query(query.ToUri())
if isinstance(query, YouTubeUserQuery):
return gdata.youtube.YouTubeUserFeedFromString(result.ToString())
elif isinstance(query, YouTubePlaylistQuery):
return gdata.youtube.YouTubePlaylistFeedFromString(result.ToString())
elif isinstance(query, YouTubeVideoQuery):
return gdata.youtube.YouTubeVideoFeedFromString(result.ToString())
else:
return result
class YouTubeVideoQuery(gdata.service.Query):
"""Subclasses gdata.service.Query to represent a YouTube Data API query.
Attributes are set dynamically via properties. Properties correspond to
the standard Google Data API query parameters with YouTube Data API
extensions. Please refer to the API documentation for details.
Attributes:
vq: The vq parameter, which is only supported for video feeds, specifies a
search query term. Refer to API documentation for further details.
orderby: The orderby parameter, which is only supported for video feeds,
specifies the value that will be used to sort videos in the search
result set. Valid values for this parameter are relevance, published,
viewCount and rating.
time: The time parameter, which is only available for the top_rated,
top_favorites, most_viewed, most_discussed, most_linked and
most_responded standard feeds, restricts the search to videos uploaded
within the specified time. Valid values for this parameter are today
(1 day), this_week (7 days), this_month (1 month) and all_time.
The default value for this parameter is all_time.
format: The format parameter specifies that videos must be available in a
particular video format. Refer to the API documentation for details.
racy: The racy parameter allows a search result set to include restricted
content as well as standard content. Valid values for this parameter
are include and exclude. By default, restricted content is excluded.
lr: The lr parameter restricts the search to videos that have a title,
description or keywords in a specific language. Valid values for the lr
parameter are ISO 639-1 two-letter language codes.
restriction: The restriction parameter identifies the IP address that
should be used to filter videos that can only be played in specific
countries.
location: A string of geo coordinates. Note that this is not used when the
search is performed but rather to filter the returned videos for ones
that match to the location entered.
feed: str (optional) The base URL which is the beginning of the query URL.
defaults to 'http://%s/feeds/videos' % (YOUTUBE_SERVER)
"""
def __init__(self, video_id=None, feed_type=None, text_query=None,
params=None, categories=None, feed=None):
if feed_type in YOUTUBE_STANDARDFEEDS and feed is None:
feed = 'http://%s/feeds/standardfeeds/%s' % (YOUTUBE_SERVER, feed_type)
elif (feed_type is 'responses' or feed_type is 'comments' and video_id
and feed is None):
feed = 'http://%s/feeds/videos/%s/%s' % (YOUTUBE_SERVER, video_id,
feed_type)
elif feed is None:
feed = 'http://%s/feeds/videos' % (YOUTUBE_SERVER)
gdata.service.Query.__init__(self, feed, text_query=text_query,
params=params, categories=categories)
def _GetVideoQuery(self):
if 'vq' in self:
return self['vq']
else:
return None
def _SetVideoQuery(self, val):
self['vq'] = val
vq = property(_GetVideoQuery, _SetVideoQuery,
doc="""The video query (vq) query parameter""")
def _GetOrderBy(self):
if 'orderby' in self:
return self['orderby']
else:
return None
def _SetOrderBy(self, val):
if val not in YOUTUBE_QUERY_VALID_ORDERBY_PARAMETERS:
if val.startswith('relevance_lang_') is False:
raise YouTubeError('OrderBy must be one of: %s ' %
' '.join(YOUTUBE_QUERY_VALID_ORDERBY_PARAMETERS))
self['orderby'] = val
orderby = property(_GetOrderBy, _SetOrderBy,
doc="""The orderby query parameter""")
def _GetTime(self):
if 'time' in self:
return self['time']
else:
return None
def _SetTime(self, val):
if val not in YOUTUBE_QUERY_VALID_TIME_PARAMETERS:
raise YouTubeError('Time must be one of: %s ' %
' '.join(YOUTUBE_QUERY_VALID_TIME_PARAMETERS))
self['time'] = val
time = property(_GetTime, _SetTime,
doc="""The time query parameter""")
def _GetFormat(self):
if 'format' in self:
return self['format']
else:
return None
def _SetFormat(self, val):
if val not in YOUTUBE_QUERY_VALID_FORMAT_PARAMETERS:
raise YouTubeError('Format must be one of: %s ' %
' '.join(YOUTUBE_QUERY_VALID_FORMAT_PARAMETERS))
self['format'] = val
format = property(_GetFormat, _SetFormat,
doc="""The format query parameter""")
def _GetRacy(self):
if 'racy' in self:
return self['racy']
else:
return None
def _SetRacy(self, val):
if val not in YOUTUBE_QUERY_VALID_RACY_PARAMETERS:
raise YouTubeError('Racy must be one of: %s ' %
' '.join(YOUTUBE_QUERY_VALID_RACY_PARAMETERS))
self['racy'] = val
racy = property(_GetRacy, _SetRacy,
doc="""The racy query parameter""")
def _GetLanguageRestriction(self):
if 'lr' in self:
return self['lr']
else:
return None
def _SetLanguageRestriction(self, val):
self['lr'] = val
lr = property(_GetLanguageRestriction, _SetLanguageRestriction,
doc="""The lr (language restriction) query parameter""")
def _GetIPRestriction(self):
if 'restriction' in self:
return self['restriction']
else:
return None
def _SetIPRestriction(self, val):
self['restriction'] = val
restriction = property(_GetIPRestriction, _SetIPRestriction,
doc="""The restriction query parameter""")
def _GetLocation(self):
if 'location' in self:
return self['location']
else:
return None
def _SetLocation(self, val):
self['location'] = val
location = property(_GetLocation, _SetLocation,
doc="""The location query parameter""")
class YouTubeUserQuery(YouTubeVideoQuery):
"""Subclasses YouTubeVideoQuery to perform user-specific queries.
Attributes are set dynamically via properties. Properties correspond to
the standard Google Data API query parameters with YouTube Data API
extensions.
"""
def __init__(self, username=None, feed_type=None, subscription_id=None,
text_query=None, params=None, categories=None):
uploads_favorites_playlists = ('uploads', 'favorites', 'playlists')
if feed_type is 'subscriptions' and subscription_id and username:
feed = "http://%s/feeds/users/%s/%s/%s" % (YOUTUBE_SERVER, username,
feed_type, subscription_id)
elif feed_type is 'subscriptions' and not subscription_id and username:
feed = "http://%s/feeds/users/%s/%s" % (YOUTUBE_SERVER, username,
feed_type)
elif feed_type in uploads_favorites_playlists:
feed = "http://%s/feeds/users/%s/%s" % (YOUTUBE_SERVER, username,
feed_type)
else:
feed = "http://%s/feeds/users" % (YOUTUBE_SERVER)
YouTubeVideoQuery.__init__(self, feed=feed, text_query=text_query,
params=params, categories=categories)
class YouTubePlaylistQuery(YouTubeVideoQuery):
"""Subclasses YouTubeVideoQuery to perform playlist-specific queries.
Attributes are set dynamically via properties. Properties correspond to
the standard Google Data API query parameters with YouTube Data API
extensions.
"""
def __init__(self, playlist_id, text_query=None, params=None,
categories=None):
if playlist_id:
feed = "http://%s/feeds/playlists/%s" % (YOUTUBE_SERVER, playlist_id)
else:
feed = "http://%s/feeds/playlists" % (YOUTUBE_SERVER)
YouTubeVideoQuery.__init__(self, feed=feed, text_query=text_query,
params=params, categories=categories)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
4475,
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,
420,
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,
30852,
3167,
16879,
598,
1451,
3167,
370,
2547,
604,
23534,
5331,
14,
819,
23534,
3167,
26,
21552,
3102,
370,
5147,
17101,
3383,
5331,
641,
23534,
22295,
14,
523,
11524,
795,
598,
1451,
3167,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
661,
1246,
14,
1597,
16014,
14769,
32,
6799,
14,
957,
334,
26696,
16014,
1873,
24157,
85,
395,
283,
1598,
283,
1246,
14,
31623,
580,
20059,
32,
6799,
14,
957,
334,
5691,
24604,
869,
580,
20059,
5942,
199,
199,
893,
26,
523,
687,
2748,
14,
9464,
492,
286,
15325,
465,
13139,
199,
2590,
3545,
26,
523,
862,
26,
272,
492,
286,
15325,
465,
13139,
523,
871,
3545,
26,
272,
862,
26,
489,
687,
2748,
14,
9464,
492,
13139,
272,
871,
3545,
26,
489,
687,
1819,
2350,
492,
13139,
199,
646,
747,
199,
646,
6222,
199,
646,
11006,
199,
646,
11006,
14,
1364,
199,
646,
11006,
14,
9788,
199,
199,
57,
29470,
63,
6613,
275,
283,
15275,
14,
9788,
14,
957,
7,
199,
57,
29470,
63,
10486,
275,
283,
9788,
7,
199,
57,
29470,
63,
9901,
17208,
63,
29599,
63,
2632,
275,
283,
2859,
921,
1544,
14,
3098,
14,
957,
15,
9788,
15,
8370,
15,
3041,
8880,
7,
199,
57,
29470,
63,
15925,
63,
16418,
63,
7893,
275,
661,
14469,
297,
283,
7194,
297,
283,
87,
12393,
297,
283,
311,
71,
297,
283,
13239,
521,
297,
3303,
283,
22753,
297,
283,
311,
20,
297,
283,
88,
13,
22753,
358,
199,
57,
29470,
63,
11938,
63,
5600,
63,
4961,
63,
24014,
275,
661,
8136,
297,
283,
3749,
63,
6419,
297,
283,
3749,
63,
4482,
297,
4318,
283,
452,
63,
521,
358,
199,
57,
29470,
63,
11938,
63,
5600,
63,
12125,
8285,
63,
24014,
275,
661,
8987,
297,
283,
1345,
2353,
297,
283,
10417,
297,
5101,
283,
264,
28791,
358,
199,
57,
29470,
63,
11938,
63,
5600,
63,
50,
22114,
63,
24014,
275,
661,
2613,
297,
283,
5473,
358,
199,
57,
29470,
63,
11938,
63,
5600,
63,
4807,
63,
24014,
275,
661,
17,
297,
283,
21,
297,
283,
22,
358,
199,
57,
29470,
63,
840,
3649,
689,
3888,
37,
1149,
51,
275,
661,
2786,
63,
14951,
297,
283,
14951,
590,
63,
30779,
297,
586,
283,
2119,
63,
12601,
297,
283,
2786,
63,
1345,
379,
1673,
6821,
63,
265,
63,
11375,
358,
199,
57,
29470,
63,
16418,
63,
7639,
275,
283,
2859,
921,
21725,
14,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
3707,
7,
199,
57,
29470,
63,
16418,
63,
8803,
63,
7639,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
1287,
15,
1002,
10301,
3264,
7,
199,
57,
29470,
63,
20142,
63,
7639,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
11418,
7,
199,
57,
29470,
63,
3791,
63,
18068,
63,
7639,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
3707,
7,
199,
57,
29470,
63,
11625,
4924,
63,
18068,
63,
7639,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
2802,
6717,
7,
199,
199,
57,
29470,
63,
19547,
63,
18068,
51,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
6807,
11522,
7,
199,
57,
29470,
63,
19547,
63,
11422,
63,
50,
6989,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
283,
2119,
63,
12601,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
12058,
1149,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
1345,
379,
358,
199,
57,
29470,
63,
19547,
63,
9481,
1309,
6084,
63,
22884,
36,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
14951,
590,
63,
30779,
358,
199,
57,
29470,
63,
19547,
63,
55,
8078,
63,
615,
63,
2679,
34,
8453,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
6821,
63,
265,
63,
11375,
358,
199,
57,
29470,
63,
19547,
63,
11422,
63,
2078,
54,
726,
649,
654,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2119,
63,
17520,
4033,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
9481,
1309,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
14951,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
6178,
35,
1668,
10934,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
6409,
527,
939,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
7916,
1149,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
12751,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
11073,
615,
8280,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
3853,
770,
358,
199,
57,
29470,
63,
10926,
275,
283,
1014,
921,
15275,
14,
9788
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
4475,
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,
420,
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,
30852,
3167,
16879,
598,
1451,
3167,
370,
2547,
604,
23534,
5331,
14,
819,
23534,
3167,
26,
21552,
3102,
370,
5147,
17101,
3383,
5331,
641,
23534,
22295,
14,
523,
11524,
795,
598,
1451,
3167,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
661,
1246,
14,
1597,
16014,
14769,
32,
6799,
14,
957,
334,
26696,
16014,
1873,
24157,
85,
395,
283,
1598,
283,
1246,
14,
31623,
580,
20059,
32,
6799,
14,
957,
334,
5691,
24604,
869,
580,
20059,
5942,
199,
199,
893,
26,
523,
687,
2748,
14,
9464,
492,
286,
15325,
465,
13139,
199,
2590,
3545,
26,
523,
862,
26,
272,
492,
286,
15325,
465,
13139,
523,
871,
3545,
26,
272,
862,
26,
489,
687,
2748,
14,
9464,
492,
13139,
272,
871,
3545,
26,
489,
687,
1819,
2350,
492,
13139,
199,
646,
747,
199,
646,
6222,
199,
646,
11006,
199,
646,
11006,
14,
1364,
199,
646,
11006,
14,
9788,
199,
199,
57,
29470,
63,
6613,
275,
283,
15275,
14,
9788,
14,
957,
7,
199,
57,
29470,
63,
10486,
275,
283,
9788,
7,
199,
57,
29470,
63,
9901,
17208,
63,
29599,
63,
2632,
275,
283,
2859,
921,
1544,
14,
3098,
14,
957,
15,
9788,
15,
8370,
15,
3041,
8880,
7,
199,
57,
29470,
63,
15925,
63,
16418,
63,
7893,
275,
661,
14469,
297,
283,
7194,
297,
283,
87,
12393,
297,
283,
311,
71,
297,
283,
13239,
521,
297,
3303,
283,
22753,
297,
283,
311,
20,
297,
283,
88,
13,
22753,
358,
199,
57,
29470,
63,
11938,
63,
5600,
63,
4961,
63,
24014,
275,
661,
8136,
297,
283,
3749,
63,
6419,
297,
283,
3749,
63,
4482,
297,
4318,
283,
452,
63,
521,
358,
199,
57,
29470,
63,
11938,
63,
5600,
63,
12125,
8285,
63,
24014,
275,
661,
8987,
297,
283,
1345,
2353,
297,
283,
10417,
297,
5101,
283,
264,
28791,
358,
199,
57,
29470,
63,
11938,
63,
5600,
63,
50,
22114,
63,
24014,
275,
661,
2613,
297,
283,
5473,
358,
199,
57,
29470,
63,
11938,
63,
5600,
63,
4807,
63,
24014,
275,
661,
17,
297,
283,
21,
297,
283,
22,
358,
199,
57,
29470,
63,
840,
3649,
689,
3888,
37,
1149,
51,
275,
661,
2786,
63,
14951,
297,
283,
14951,
590,
63,
30779,
297,
586,
283,
2119,
63,
12601,
297,
283,
2786,
63,
1345,
379,
1673,
6821,
63,
265,
63,
11375,
358,
199,
57,
29470,
63,
16418,
63,
7639,
275,
283,
2859,
921,
21725,
14,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
3707,
7,
199,
57,
29470,
63,
16418,
63,
8803,
63,
7639,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
1287,
15,
1002,
10301,
3264,
7,
199,
57,
29470,
63,
20142,
63,
7639,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
11418,
7,
199,
57,
29470,
63,
3791,
63,
18068,
63,
7639,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
3707,
7,
199,
57,
29470,
63,
11625,
4924,
63,
18068,
63,
7639,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
2802,
6717,
7,
199,
199,
57,
29470,
63,
19547,
63,
18068,
51,
275,
283,
2859,
921,
15275,
14,
9788,
14,
957,
15,
11522,
15,
1246,
15,
6807,
11522,
7,
199,
57,
29470,
63,
19547,
63,
11422,
63,
50,
6989,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
283,
2119,
63,
12601,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
12058,
1149,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
1345,
379,
358,
199,
57,
29470,
63,
19547,
63,
9481,
1309,
6084,
63,
22884,
36,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
14951,
590,
63,
30779,
358,
199,
57,
29470,
63,
19547,
63,
55,
8078,
63,
615,
63,
2679,
34,
8453,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
6821,
63,
265,
63,
11375,
358,
199,
57,
29470,
63,
19547,
63,
11422,
63,
2078,
54,
726,
649,
654,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2119,
63,
17520,
4033,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
9481,
1309,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
14951,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
6178,
35,
1668,
10934,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
6409,
527,
939,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
7916,
1149,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
12751,
358,
199,
57,
29470,
63,
19547,
63,
2679,
840,
63,
11073,
615,
8280,
63,
7639,
275,
1543,
83,
3149,
83,
7,
450,
334,
57,
29470,
63,
19547,
63,
18068,
51,
12,
272,
283,
2786,
63,
3853,
770,
358,
199,
57,
29470,
63,
10926,
275,
283,
1014,
921,
15275,
14,
9788,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mfherbst/spack
|
var/spack/repos/builtin/packages/r-tsne/package.py
|
5
|
1760
|
##############################################################################
# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# 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 terms and
# conditions of 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 program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *
class RTsne(RPackage):
"""A "pure R" implementation of the t-SNE algorithm."""
homepage = "https://cran.r-project.org/web/packages/tsne/index.html"
url = "https://cran.r-project.org/src/contrib/tsne_0.1-3.tar.gz"
list_url = "https://cran.rstudio.com/src/contrib/Archive/tnse"
version('0.1-3', '00974d4b3fd5f1100d0ebd24e03b0af9')
version('0.1-2', 'd96d8dce6ffeda68e2b25ec1ff52ea61')
version('0.1-1', '8197e5c61dec916b7a31b74e658b632d')
depends_on('r@3.4.0:3.4.9')
|
lgpl-2.1
|
[
4605,
199,
3,
1898,
334,
67,
9,
6171,
13,
12682,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
820,
23433,
685,
8,
50,
8599,
304,
272,
408,
33,
298,
5115,
820,
2,
4514,
402,
314,
307,
13,
51,
6388,
5563,
1041,
339,
26586,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2520,
15,
5154,
15,
1086,
685,
15,
1080,
14,
1360,
2,
272,
1166,
420,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
1086,
685,
63,
16,
14,
17,
13,
19,
14,
5369,
14,
6838,
2,
272,
769,
63,
633,
275,
298,
2859,
921,
67,
1312,
14,
8332,
5208,
14,
957,
15,
2164,
15,
2828,
15,
13042,
15,
5889,
261,
2,
339,
1015,
360,
16,
14,
17,
13,
19,
297,
283,
8581,
1342,
68,
20,
66,
19,
2592,
21,
70,
26451,
68,
16,
2871,
68,
1194,
69,
1644,
66,
16,
2756,
25,
358,
272,
1015,
360,
16,
14,
17,
13,
18,
297,
283,
68,
2534,
68,
24,
68,
301,
22,
556,
379,
65,
2333,
69,
18,
66,
821,
825,
17,
556,
2528,
4489,
2976,
358,
272,
1015,
360,
16,
14,
17,
13,
17,
297,
283,
24,
11165,
69,
21,
67,
2976,
7778,
25,
975,
66,
23,
65,
2192,
66,
1342,
69,
28133,
66,
27250,
68,
358,
339,
8350,
63,
265,
360,
82,
32,
19,
14,
20,
14,
16,
26,
19,
14,
20,
14,
25,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
334,
67,
9,
6171,
13,
12682,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
820,
23433,
685,
8,
50,
8599,
304,
272,
408,
33,
298,
5115,
820,
2,
4514,
402,
314,
307,
13,
51,
6388,
5563,
1041,
339,
26586,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2520,
15,
5154,
15,
1086,
685,
15,
1080,
14,
1360,
2,
272,
1166,
420,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
1086,
685,
63,
16,
14,
17,
13,
19,
14,
5369,
14,
6838,
2,
272,
769,
63,
633,
275,
298,
2859,
921,
67,
1312,
14,
8332,
5208,
14,
957,
15,
2164,
15,
2828,
15,
13042,
15,
5889,
261,
2,
339,
1015,
360,
16,
14,
17,
13,
19,
297,
283,
8581,
1342,
68,
20,
66,
19,
2592,
21,
70,
26451,
68,
16,
2871,
68,
1194,
69,
1644,
66,
16,
2756,
25,
358,
272,
1015,
360,
16,
14,
17,
13,
18,
297,
283,
68,
2534,
68,
24,
68,
301,
22,
556,
379,
65,
2333,
69,
18,
66,
821,
825,
17,
556,
2528,
4489,
2976,
358,
272,
1015,
360,
16,
14,
17,
13,
17,
297,
283,
24,
11165,
69,
21,
67,
2976,
7778,
25,
975,
66,
23,
65,
2192,
66,
1342,
69,
28133,
66,
27250,
68,
358,
339,
8350,
63,
265,
360,
82,
32,
19,
14,
20,
14,
16,
26,
19,
14,
20,
14,
25,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gchq/gaffer-tools
|
python-shell/src/test/test_gaffer_functions_it.py
|
1
|
2491
|
#
# Copyright 2016-2019 Crown Copyright
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import json
import unittest
from gafferpy import gaffer as g
from gafferpy import gaffer_connector
class GafferFunctionsIntegrationTest(unittest.TestCase):
def test_all_functions_have_classes(self):
gc = gaffer_connector.GafferConnector(
'http://localhost:8080/rest/latest')
functions = gc.execute_get(
g.GetTransformFunctions()
)
functions = json.loads(functions)
ignore_functions = [
'uk.gov.gchq.gaffer.operation.data.generator.EdgeIdExtractor',
'uk.gov.gchq.gaffer.store.util.AggregatorUtil$ToIngestElementKey',
'uk.gov.gchq.gaffer.rest.example.ExampleDomainObjectGenerator',
'uk.gov.gchq.gaffer.data.element.function.ElementTransformer',
'uk.gov.gchq.gaffer.traffic.generator.RoadTrafficCsvElementGenerator',
'uk.gov.gchq.gaffer.store.util.AggregatorUtil$ToElementKey',
'uk.gov.gchq.koryphe.function.FunctionComposite',
'uk.gov.gchq.gaffer.rest.example.ExampleTransformFunction',
'uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop',
'uk.gov.gchq.gaffer.traffic.transform.DescriptionTransform',
'uk.gov.gchq.gaffer.store.util.AggregatorUtil$ToQueryElementKey',
'uk.gov.gchq.koryphe.tuple.TupleInputAdapter',
'uk.gov.gchq.gaffer.operation.data.generator.EntityIdExtractor',
'uk.gov.gchq.gaffer.traffic.generator.RoadTrafficStringElementGenerator',
'uk.gov.gchq.gaffer.rest.example.ExampleElementGenerator',
]
for i in ignore_functions:
if i in functions: functions.remove(i)
for op in functions:
self.assertTrue(op in g.JsonConverter.GENERIC_JSON_CONVERTERS,
'Missing transform function class: ' + op)
if __name__ == "__main__":
unittest.main()
|
apache-2.0
|
[
3,
199,
3,
1898,
7800,
13,
14982,
445,
18406,
1898,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
283,
3761,
11339,
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,
283,
1179,
2281,
7,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
2022,
199,
646,
2882,
199,
199,
504,
16072,
1260,
647,
492,
16072,
1260,
465,
486,
199,
504,
16072,
1260,
647,
492,
16072,
1260,
63,
11815,
421,
199,
533,
16600,
13967,
20405,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
452,
63,
5777,
63,
7804,
63,
2888,
8,
277,
304,
267,
9486,
275,
16072,
1260,
63,
11815,
14,
17295,
1260,
20476,
8,
288,
283,
1014,
921,
5967,
26,
15844,
15,
3911,
15,
7410,
358,
267,
3423,
275,
9486,
14,
2526,
63,
362,
8,
288,
486,
14,
1002,
6939,
13967,
342,
267,
776,
267,
3423,
275,
2022,
14,
3640,
8,
5777,
9,
398,
3686,
63,
5777,
275,
359,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
5735,
14,
576,
14,
4679,
14,
12886,
1304,
11039,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
1617,
14,
1974,
14,
23933,
9562,
4,
1378,
607,
3199,
2162,
1197,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
3911,
14,
2694,
14,
9846,
7705,
1692,
7599,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
576,
14,
2108,
14,
1593,
14,
2162,
19761,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
17297,
14,
4679,
14,
3863,
350,
29759,
35,
2772,
2162,
7599,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
1617,
14,
1974,
14,
23933,
9562,
4,
1378,
2162,
1197,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
75,
1089,
80,
426,
14,
1593,
14,
3481,
24039,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
3911,
14,
2694,
14,
9846,
6939,
3481,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
576,
14,
2180,
14,
1593,
14,
7757,
14,
12147,
31491,
24121,
2532,
13378,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
17297,
14,
4711,
14,
5831,
6939,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
1617,
14,
1974,
14,
23933,
9562,
4,
1378,
3227,
2162,
1197,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
75,
1089,
80,
426,
14,
2960,
14,
7075,
3205,
10200,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
5735,
14,
576,
14,
4679,
14,
7302,
1304,
11039,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
17297,
14,
4679,
14,
3863,
350,
29759,
1558,
2162,
7599,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
3911,
14,
2694,
14,
9846,
2162,
7599,
297,
267,
1622,
398,
367,
284,
315,
3686,
63,
5777,
26,
288,
340,
284,
315,
3423,
26,
3423,
14,
2168,
8,
73,
9,
398,
367,
1687,
315,
3423,
26,
288,
291,
14,
1815,
8,
411,
315,
486,
14,
9653,
11907,
14,
29395,
63,
6243,
63,
1864,
2111,
1157,
51,
12,
1169,
283,
7718,
5793,
805,
1021,
26,
283,
435,
1687,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
7800,
13,
14982,
445,
18406,
1898,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
283,
3761,
11339,
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,
283,
1179,
2281,
7,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
2022,
199,
646,
2882,
199,
199,
504,
16072,
1260,
647,
492,
16072,
1260,
465,
486,
199,
504,
16072,
1260,
647,
492,
16072,
1260,
63,
11815,
421,
199,
533,
16600,
13967,
20405,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
452,
63,
5777,
63,
7804,
63,
2888,
8,
277,
304,
267,
9486,
275,
16072,
1260,
63,
11815,
14,
17295,
1260,
20476,
8,
288,
283,
1014,
921,
5967,
26,
15844,
15,
3911,
15,
7410,
358,
267,
3423,
275,
9486,
14,
2526,
63,
362,
8,
288,
486,
14,
1002,
6939,
13967,
342,
267,
776,
267,
3423,
275,
2022,
14,
3640,
8,
5777,
9,
398,
3686,
63,
5777,
275,
359,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
5735,
14,
576,
14,
4679,
14,
12886,
1304,
11039,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
1617,
14,
1974,
14,
23933,
9562,
4,
1378,
607,
3199,
2162,
1197,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
3911,
14,
2694,
14,
9846,
7705,
1692,
7599,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
576,
14,
2108,
14,
1593,
14,
2162,
19761,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
17297,
14,
4679,
14,
3863,
350,
29759,
35,
2772,
2162,
7599,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
1617,
14,
1974,
14,
23933,
9562,
4,
1378,
2162,
1197,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
75,
1089,
80,
426,
14,
1593,
14,
3481,
24039,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
3911,
14,
2694,
14,
9846,
6939,
3481,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
576,
14,
2180,
14,
1593,
14,
7757,
14,
12147,
31491,
24121,
2532,
13378,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
17297,
14,
4711,
14,
5831,
6939,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
1617,
14,
1974,
14,
23933,
9562,
4,
1378,
3227,
2162,
1197,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
75,
1089,
80,
426,
14,
2960,
14,
7075,
3205,
10200,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
5735,
14,
576,
14,
4679,
14,
7302,
1304,
11039,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
17297,
14,
4679,
14,
3863,
350,
29759,
1558,
2162,
7599,
297,
288,
283,
3210,
14,
16294,
14,
71,
335,
81,
14,
5294,
1260,
14,
3911,
14,
2694,
14,
9846,
2162,
7599,
297,
267,
1622,
398,
367,
284,
315,
3686,
63,
5777,
26,
288,
340,
284,
315,
3423,
26,
3423,
14,
2168,
8,
73,
9,
398,
367,
1687,
315,
3423,
26,
288,
291,
14,
1815,
8,
411,
315,
486,
14,
9653,
11907,
14,
29395,
63,
6243,
63,
1864,
2111,
1157,
51,
12,
1169,
283,
7718,
5793,
805,
1021,
26,
283,
435,
1687,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
jmcarbo/openerp7
|
openerp/addons/crm_partner_assign/__openerp__.py
|
48
|
2297
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Partners Geo-Localization',
'version': '1.0',
'category': 'Customer Relationship Management',
'description': """
This is the module used by OpenERP SA to redirect customers to its partners, based on geolocalization.
======================================================================================================
You can geolocalize your opportunities by using this module.
Use geolocalization when assigning opportunities to partners.
Determine the GPS coordinates according to the address of the partner.
The most appropriate partner can be assigned.
You can also use the geolocalization without using the GPS coordinates.
""",
'author': 'OpenERP SA',
'depends': ['crm', 'account'],
'demo': ['res_partner_demo.xml'],
'data': [
'security/ir.model.access.csv',
'res_partner_view.xml',
'wizard/crm_forward_to_partner_view.xml',
'crm_lead_view.xml',
'crm_partner_assign_data.xml',
'report/crm_lead_report_view.xml',
'report/crm_partner_report_view.xml',
],
'test': ['test/partner_assign.yml'],
'installable': True,
'auto_install': False,
'images': ['images/partner_geo_localization.jpeg','images/partner_grade.jpeg'],
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
8416,
8715,
8875,
13,
5339,
2072,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
17025,
23230,
3319,
8259,
297,
272,
283,
1802,
356,
408,
199,
2765,
365,
314,
859,
1202,
701,
7653,
13950,
370,
4660,
286,
28078,
370,
2399,
18943,
12,
4079,
641,
8509,
1832,
2072,
14,
199,
5695,
2486,
23476,
199,
199,
5556,
883,
8509,
21279,
2195,
1687,
719,
22047,
701,
1808,
642,
859,
14,
199,
199,
6119,
8509,
1832,
2072,
1380,
26694,
1687,
719,
22047,
370,
18943,
14,
199,
21767,
314,
598,
5067,
8983,
7182,
370,
314,
2287,
402,
314,
5854,
14,
199,
199,
1918,
4750,
5827,
5854,
883,
506,
7943,
14,
199,
5556,
883,
2597,
675,
314,
8509,
1832,
2072,
1928,
1808,
314,
598,
5067,
8983,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
15213,
297,
283,
2048,
995,
272,
283,
8768,
356,
788,
470,
63,
3899,
63,
8768,
14,
1652,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
470,
63,
3899,
63,
1345,
14,
1652,
297,
267,
283,
9819,
15,
15213,
63,
6688,
63,
475,
63,
3899,
63,
1345,
14,
1652,
297,
267,
283,
15213,
63,
13799,
63,
1345,
14,
1652,
297,
267,
283,
15213,
63,
3899,
63,
5038,
63,
576,
14,
1652,
297,
267,
283,
3070,
15,
15213,
63,
13799,
63,
3070,
63,
1345,
14,
1652,
297,
267,
283,
3070,
15,
15213,
63,
3899,
63,
3070,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
396,
356,
788,
396,
15,
3899,
63,
5038,
14,
11714,
995,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
4782,
356,
788,
4782,
15,
3899,
63,
6721,
63,
1832,
2072,
14,
14230,
1673,
4782,
15,
3899,
63,
4523,
14,
14230,
995,
199,
93,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
8416,
8715,
8875,
13,
5339,
2072,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
17025,
23230,
3319,
8259,
297,
272,
283,
1802,
356,
408,
199,
2765,
365,
314,
859,
1202,
701,
7653,
13950,
370,
4660,
286,
28078,
370,
2399,
18943,
12,
4079,
641,
8509,
1832,
2072,
14,
199,
5695,
2486,
23476,
199,
199,
5556,
883,
8509,
21279,
2195,
1687,
719,
22047,
701,
1808,
642,
859,
14,
199,
199,
6119,
8509,
1832,
2072,
1380,
26694,
1687,
719,
22047,
370,
18943,
14,
199,
21767,
314,
598,
5067,
8983,
7182,
370,
314,
2287,
402,
314,
5854,
14,
199,
199,
1918,
4750,
5827,
5854,
883,
506,
7943,
14,
199,
5556,
883,
2597,
675,
314,
8509,
1832,
2072,
1928,
1808,
314,
598,
5067,
8983,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
15213,
297,
283,
2048,
995,
272,
283,
8768,
356,
788,
470,
63,
3899,
63,
8768,
14,
1652,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
470,
63,
3899,
63,
1345,
14,
1652,
297,
267,
283,
9819,
15,
15213,
63,
6688,
63,
475,
63,
3899,
63,
1345,
14,
1652,
297,
267,
283,
15213,
63,
13799,
63,
1345,
14,
1652,
297,
267,
283,
15213,
63,
3899,
63,
5038,
63,
576,
14,
1652,
297,
267,
283,
3070,
15,
15213,
63,
13799,
63,
3070,
63,
1345,
14,
1652,
297,
267,
283,
3070,
15,
15213,
63,
3899,
63,
3070,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
396,
356,
788,
396,
15,
3899,
63,
5038,
14,
11714,
995,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
4782,
356,
788,
4782,
15,
3899,
63,
6721,
63,
1832,
2072,
14,
14230,
1673,
4782,
15,
3899,
63,
4523,
14,
14230,
995,
199,
93,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dudepare/django
|
django/core/management/base.py
|
31
|
23960
|
# -*- coding: utf-8 -*-
"""
Base classes for writing management commands (named commands which can
be executed through ``django-admin`` or ``manage.py``).
"""
from __future__ import unicode_literals
import os
import sys
import warnings
from argparse import ArgumentParser
from optparse import OptionParser
import django
from django.core import checks
from django.core.management.color import color_style, no_style
from django.db import connections
from django.utils.deprecation import RemovedInDjango110Warning
from django.utils.encoding import force_str
class CommandError(Exception):
"""
Exception class indicating a problem while executing a management
command.
If this exception is raised during the execution of a management
command, it will be caught and turned into a nicely-printed error
message to the appropriate output stream (i.e., stderr); as a
result, raising this exception (with a sensible description of the
error) is the preferred way to indicate that something has gone
wrong in the execution of a command.
"""
pass
class SystemCheckError(CommandError):
"""
The system check framework detected unrecoverable errors.
"""
pass
class CommandParser(ArgumentParser):
"""
Customized ArgumentParser class to improve some error messages and prevent
SystemExit in several occasions, as SystemExit is unacceptable when a
command is called programmatically.
"""
def __init__(self, cmd, **kwargs):
self.cmd = cmd
super(CommandParser, self).__init__(**kwargs)
def parse_args(self, args=None, namespace=None):
# Catch missing argument for a better error message
if (hasattr(self.cmd, 'missing_args_message') and
not (args or any(not arg.startswith('-') for arg in args))):
self.error(self.cmd.missing_args_message)
return super(CommandParser, self).parse_args(args, namespace)
def error(self, message):
if self.cmd._called_from_command_line:
super(CommandParser, self).error(message)
else:
raise CommandError("Error: %s" % message)
def handle_default_options(options):
"""
Include any default options that all commands should accept here
so that ManagementUtility can handle them before searching for
user commands.
"""
if options.settings:
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
if options.pythonpath:
sys.path.insert(0, options.pythonpath)
class OutputWrapper(object):
"""
Wrapper around stdout/stderr
"""
@property
def style_func(self):
return self._style_func
@style_func.setter
def style_func(self, style_func):
if style_func and self.isatty():
self._style_func = style_func
else:
self._style_func = lambda x: x
def __init__(self, out, style_func=None, ending='\n'):
self._out = out
self.style_func = None
self.ending = ending
def __getattr__(self, name):
return getattr(self._out, name)
def isatty(self):
return hasattr(self._out, 'isatty') and self._out.isatty()
def write(self, msg, style_func=None, ending=None):
ending = self.ending if ending is None else ending
if ending and not msg.endswith(ending):
msg += ending
style_func = style_func or self.style_func
self._out.write(force_str(style_func(msg)))
class BaseCommand(object):
"""
The base class from which all management commands ultimately
derive.
Use this class if you want access to all of the mechanisms which
parse the command-line arguments and work out what code to call in
response; if you don't need to change any of that behavior,
consider using one of the subclasses defined in this file.
If you are interested in overriding/customizing various aspects of
the command-parsing and -execution behavior, the normal flow works
as follows:
1. ``django-admin`` or ``manage.py`` loads the command class
and calls its ``run_from_argv()`` method.
2. The ``run_from_argv()`` method calls ``create_parser()`` to get
an ``ArgumentParser`` for the arguments, parses them, performs
any environment changes requested by options like
``pythonpath``, and then calls the ``execute()`` method,
passing the parsed arguments.
3. The ``execute()`` method attempts to carry out the command by
calling the ``handle()`` method with the parsed arguments; any
output produced by ``handle()`` will be printed to standard
output and, if the command is intended to produce a block of
SQL statements, will be wrapped in ``BEGIN`` and ``COMMIT``.
4. If ``handle()`` or ``execute()`` raised any exception (e.g.
``CommandError``), ``run_from_argv()`` will instead print an error
message to ``stderr``.
Thus, the ``handle()`` method is typically the starting point for
subclasses; many built-in commands and command types either place
all of their logic in ``handle()``, or perform some additional
parsing work in ``handle()`` and then delegate from it to more
specialized methods as needed.
Several attributes affect behavior at various steps along the way:
``args``
A string listing the arguments accepted by the command,
suitable for use in help messages; e.g., a command which takes
a list of application names might set this to '<app_label
app_label ...>'.
``can_import_settings``
A boolean indicating whether the command needs to be able to
import Django settings; if ``True``, ``execute()`` will verify
that this is possible before proceeding. Default value is
``True``.
``help``
A short description of the command, which will be printed in
help messages.
``option_list``
This is the list of ``optparse`` options which will be fed
into the command's ``OptionParser`` for parsing arguments.
Deprecated and will be removed in Django 1.10.
Use ``add_arguments`` instead.
``output_transaction``
A boolean indicating whether the command outputs SQL
statements; if ``True``, the output will automatically be
wrapped with ``BEGIN;`` and ``COMMIT;``. Default value is
``False``.
``requires_system_checks``
A boolean; if ``True``, entire Django project will be checked for errors
prior to executing the command. Default value is ``True``.
To validate an individual application's models
rather than all applications' models, call
``self.check(app_configs)`` from ``handle()``, where ``app_configs``
is the list of application's configuration provided by the
app registry.
``leave_locale_alone``
A boolean indicating whether the locale set in settings should be
preserved during the execution of the command instead of translations
being deactivated.
Default value is ``False``.
Make sure you know what you are doing if you decide to change the value
of this option in your custom command if it creates database content
that is locale-sensitive and such content shouldn't contain any
translations (like it happens e.g. with django.contrib.auth
permissions) as activating any locale might cause unintended effects.
This option can't be False when the can_import_settings option is set
to False too because attempting to deactivate translations needs access
to settings. This condition will generate a CommandError.
"""
# Metadata about this command.
option_list = ()
help = ''
args = ''
# Configuration shortcuts that alter various logic.
_called_from_command_line = False
can_import_settings = True
output_transaction = False # Whether to wrap the output in a "BEGIN; COMMIT;"
leave_locale_alone = False
requires_system_checks = True
def __init__(self, stdout=None, stderr=None, no_color=False):
self.stdout = OutputWrapper(stdout or sys.stdout)
self.stderr = OutputWrapper(stderr or sys.stderr)
if no_color:
self.style = no_style()
else:
self.style = color_style()
self.stderr.style_func = self.style.ERROR
@property
def use_argparse(self):
return not bool(self.option_list)
def get_version(self):
"""
Return the Django version, which should be correct for all
built-in Django commands. User-supplied commands should
override this method.
"""
return django.get_version()
def usage(self, subcommand):
"""
Return a brief description of how to use this command, by
default from the attribute ``self.help``.
"""
usage = '%%prog %s [options] %s' % (subcommand, self.args)
if self.help:
return '%s\n\n%s' % (usage, self.help)
else:
return usage
def create_parser(self, prog_name, subcommand):
"""
Create and return the ``ArgumentParser`` which will be used to
parse the arguments to this command.
"""
if not self.use_argparse:
def store_as_int(option, opt_str, value, parser):
setattr(parser.values, option.dest, int(value))
# Backwards compatibility: use deprecated optparse module
warnings.warn("OptionParser usage for Django management commands "
"is deprecated, use ArgumentParser instead",
RemovedInDjango110Warning)
parser = OptionParser(prog=prog_name,
usage=self.usage(subcommand),
version=self.get_version())
parser.add_option('-v', '--verbosity', action='callback', dest='verbosity', default=1,
type='choice', choices=['0', '1', '2', '3'], callback=store_as_int,
help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output')
parser.add_option('--settings',
help=(
'The Python path to a settings module, e.g. '
'"myproject.settings.main". If this isn\'t provided, the '
'DJANGO_SETTINGS_MODULE environment variable will be used.'
),
)
parser.add_option('--pythonpath',
help='A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".'),
parser.add_option('--traceback', action='store_true',
help='Raise on CommandError exceptions')
parser.add_option('--no-color', action='store_true', dest='no_color', default=False,
help="Don't colorize the command output.")
for opt in self.option_list:
parser.add_option(opt)
else:
parser = CommandParser(self, prog="%s %s" % (os.path.basename(prog_name), subcommand),
description=self.help or None)
parser.add_argument('--version', action='version', version=self.get_version())
parser.add_argument('-v', '--verbosity', action='store', dest='verbosity', default='1',
type=int, choices=[0, 1, 2, 3],
help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output')
parser.add_argument('--settings',
help=(
'The Python path to a settings module, e.g. '
'"myproject.settings.main". If this isn\'t provided, the '
'DJANGO_SETTINGS_MODULE environment variable will be used.'
),
)
parser.add_argument('--pythonpath',
help='A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".')
parser.add_argument('--traceback', action='store_true',
help='Raise on CommandError exceptions')
parser.add_argument('--no-color', action='store_true', dest='no_color', default=False,
help="Don't colorize the command output.")
if self.args:
# Keep compatibility and always accept positional arguments, like optparse when args is set
parser.add_argument('args', nargs='*')
self.add_arguments(parser)
return parser
def add_arguments(self, parser):
"""
Entry point for subclassed commands to add custom arguments.
"""
pass
def print_help(self, prog_name, subcommand):
"""
Print the help message for this command, derived from
``self.usage()``.
"""
parser = self.create_parser(prog_name, subcommand)
parser.print_help()
def run_from_argv(self, argv):
"""
Set up any environment changes requested (e.g., Python path
and Django settings), then run this command. If the
command raises a ``CommandError``, intercept it and print it sensibly
to stderr. If the ``--traceback`` option is present or the raised
``Exception`` is not ``CommandError``, raise it.
"""
self._called_from_command_line = True
parser = self.create_parser(argv[0], argv[1])
if self.use_argparse:
options = parser.parse_args(argv[2:])
cmd_options = vars(options)
# Move positional args out of options to mimic legacy optparse
args = cmd_options.pop('args', ())
else:
options, args = parser.parse_args(argv[2:])
cmd_options = vars(options)
handle_default_options(options)
try:
self.execute(*args, **cmd_options)
except Exception as e:
if options.traceback or not isinstance(e, CommandError):
raise
# SystemCheckError takes care of its own formatting.
if isinstance(e, SystemCheckError):
self.stderr.write(str(e), lambda x: x)
else:
self.stderr.write('%s: %s' % (e.__class__.__name__, e))
sys.exit(1)
finally:
connections.close_all()
def execute(self, *args, **options):
"""
Try to execute this command, performing system checks if needed (as
controlled by the ``requires_system_checks`` attribute, except if
force-skipped).
"""
if options.get('no_color'):
self.style = no_style()
self.stderr.style_func = None
if options.get('stdout'):
self.stdout = OutputWrapper(options['stdout'])
if options.get('stderr'):
self.stderr = OutputWrapper(options.get('stderr'), self.stderr.style_func)
saved_locale = None
if not self.leave_locale_alone:
# Only mess with locales if we can assume we have a working
# settings file, because django.utils.translation requires settings
# (The final saying about whether the i18n machinery is active will be
# found in the value of the USE_I18N setting)
if not self.can_import_settings:
raise CommandError("Incompatible values of 'leave_locale_alone' "
"(%s) and 'can_import_settings' (%s) command "
"options." % (self.leave_locale_alone,
self.can_import_settings))
# Deactivate translations, because django-admin creates database
# content like permissions, and those shouldn't contain any
# translations.
from django.utils import translation
saved_locale = translation.get_language()
translation.deactivate_all()
try:
if (self.requires_system_checks and
not options.get('skip_validation') and # Remove at the end of deprecation for `skip_validation`.
not options.get('skip_checks')):
self.check()
output = self.handle(*args, **options)
if output:
if self.output_transaction:
# This needs to be imported here, because it relies on
# settings.
from django.db import connections, DEFAULT_DB_ALIAS
connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
if connection.ops.start_transaction_sql():
self.stdout.write(self.style.SQL_KEYWORD(connection.ops.start_transaction_sql()))
self.stdout.write(output)
if self.output_transaction:
self.stdout.write('\n' + self.style.SQL_KEYWORD(connection.ops.end_transaction_sql()))
finally:
if saved_locale is not None:
translation.activate(saved_locale)
def check(self, app_configs=None, tags=None, display_num_errors=False,
include_deployment_checks=False):
"""
Uses the system check framework to validate entire Django project.
Raises CommandError for any serious message (error or critical errors).
If there are only light messages (like warnings), they are printed to
stderr and no exception is raised.
"""
all_issues = checks.run_checks(
app_configs=app_configs,
tags=tags,
include_deployment_checks=include_deployment_checks,
)
header, body, footer = "", "", ""
visible_issue_count = 0 # excludes silenced warnings
if all_issues:
debugs = [e for e in all_issues if e.level < checks.INFO and not e.is_silenced()]
infos = [e for e in all_issues if checks.INFO <= e.level < checks.WARNING and not e.is_silenced()]
warnings = [e for e in all_issues if checks.WARNING <= e.level < checks.ERROR and not e.is_silenced()]
errors = [e for e in all_issues if checks.ERROR <= e.level < checks.CRITICAL and not e.is_silenced()]
criticals = [e for e in all_issues if checks.CRITICAL <= e.level and not e.is_silenced()]
sorted_issues = [
(criticals, 'CRITICALS'),
(errors, 'ERRORS'),
(warnings, 'WARNINGS'),
(infos, 'INFOS'),
(debugs, 'DEBUGS'),
]
for issues, group_name in sorted_issues:
if issues:
visible_issue_count += len(issues)
formatted = (
self.style.ERROR(force_str(e))
if e.is_serious()
else self.style.WARNING(force_str(e))
for e in issues)
formatted = "\n".join(sorted(formatted))
body += '\n%s:\n%s\n' % (group_name, formatted)
if visible_issue_count:
header = "System check identified some issues:\n"
if display_num_errors:
if visible_issue_count:
footer += '\n'
footer += "System check identified %s (%s silenced)." % (
"no issues" if visible_issue_count == 0 else
"1 issue" if visible_issue_count == 1 else
"%s issues" % visible_issue_count,
len(all_issues) - visible_issue_count,
)
if any(e.is_serious() and not e.is_silenced() for e in all_issues):
msg = self.style.ERROR("SystemCheckError: %s" % header) + body + footer
raise SystemCheckError(msg)
else:
msg = header + body + footer
if msg:
if visible_issue_count:
self.stderr.write(msg, lambda x: x)
else:
self.stdout.write(msg)
def handle(self, *args, **options):
"""
The actual logic of the command. Subclasses must implement
this method.
"""
raise NotImplementedError('subclasses of BaseCommand must provide a handle() method')
class AppCommand(BaseCommand):
"""
A management command which takes one or more installed application labels
as arguments, and does something with each of them.
Rather than implementing ``handle()``, subclasses must implement
``handle_app_config()``, which will be called once for each application.
"""
missing_args_message = "Enter at least one application label."
def add_arguments(self, parser):
parser.add_argument('args', metavar='app_label', nargs='+',
help='One or more application label.')
def handle(self, *app_labels, **options):
from django.apps import apps
try:
app_configs = [apps.get_app_config(app_label) for app_label in app_labels]
except (LookupError, ImportError) as e:
raise CommandError("%s. Are you sure your INSTALLED_APPS setting is correct?" % e)
output = []
for app_config in app_configs:
app_output = self.handle_app_config(app_config, **options)
if app_output:
output.append(app_output)
return '\n'.join(output)
def handle_app_config(self, app_config, **options):
"""
Perform the command's actions for app_config, an AppConfig instance
corresponding to an application label given on the command line.
"""
raise NotImplementedError(
"Subclasses of AppCommand must provide"
"a handle_app_config() method.")
class LabelCommand(BaseCommand):
"""
A management command which takes one or more arbitrary arguments
(labels) on the command line, and does something with each of
them.
Rather than implementing ``handle()``, subclasses must implement
``handle_label()``, which will be called once for each label.
If the arguments should be names of installed applications, use
``AppCommand`` instead.
"""
label = 'label'
missing_args_message = "Enter at least one %s." % label
def add_arguments(self, parser):
parser.add_argument('args', metavar=self.label, nargs='+')
def handle(self, *labels, **options):
output = []
for label in labels:
label_output = self.handle_label(label, **options)
if label_output:
output.append(label_output)
return '\n'.join(output)
def handle_label(self, label, **options):
"""
Perform the command's actions for ``label``, which will be the
string as given on the command line.
"""
raise NotImplementedError('subclasses of LabelCommand must provide a handle_label() method')
class NoArgsCommand(BaseCommand):
"""
A command which takes no arguments on the command line.
Rather than implementing ``handle()``, subclasses must implement
``handle_noargs()``; ``handle()`` itself is overridden to ensure
no arguments are passed to the command.
Attempting to pass arguments will raise ``CommandError``.
"""
args = ''
def __init__(self):
warnings.warn(
"NoArgsCommand class is deprecated and will be removed in Django 1.10. "
"Use BaseCommand instead, which takes no arguments by default.",
RemovedInDjango110Warning
)
super(NoArgsCommand, self).__init__()
def handle(self, *args, **options):
if args:
raise CommandError("Command doesn't accept any arguments")
return self.handle_noargs(**options)
def handle_noargs(self, **options):
"""
Perform this command's actions.
"""
raise NotImplementedError('subclasses of NoArgsCommand must provide a handle_noargs() method')
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1563,
3992,
367,
3575,
10041,
3718,
334,
4579,
3718,
1314,
883,
199,
1235,
7934,
4012,
1124,
1176,
13,
2113,
1040,
503,
1124,
9053,
14,
647,
20008,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
984,
199,
646,
3598,
199,
504,
7534,
492,
27615,
199,
504,
8691,
492,
13491,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
492,
5920,
199,
504,
1639,
14,
1018,
14,
8110,
14,
2326,
492,
3164,
63,
2487,
12,
949,
63,
2487,
199,
504,
1639,
14,
697,
492,
6947,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
6019,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
421,
199,
533,
14393,
8,
1726,
304,
272,
408,
272,
2186,
1021,
9297,
282,
5160,
1830,
14043,
282,
10041,
272,
1414,
14,
339,
982,
642,
1919,
365,
4915,
5309,
314,
6451,
402,
282,
10041,
272,
1414,
12,
652,
911,
506,
15604,
436,
19136,
1901,
282,
14213,
590,
13,
27131,
1125,
272,
1245,
370,
314,
5827,
1072,
2547,
334,
73,
14,
69,
2020,
4635,
2736,
465,
282,
272,
754,
12,
17026,
642,
1919,
334,
1045,
282,
27962,
1369,
402,
314,
272,
1125,
9,
365,
314,
14388,
4340,
370,
6623,
626,
6020,
965,
21737,
272,
6835,
315,
314,
6451,
402,
282,
1414,
14,
272,
408,
272,
986,
421,
199,
533,
6187,
1799,
547,
8,
31542,
304,
272,
408,
272,
710,
2656,
1104,
10059,
10501,
625,
23131,
461,
2552,
14,
272,
408,
272,
986,
421,
199,
533,
5817,
2842,
8,
10730,
304,
272,
408,
272,
8388,
1759,
27615,
1021,
370,
19053,
2005,
1125,
3788,
436,
7981,
272,
14838,
315,
9978,
14706,
305,
15293,
12,
465,
14838,
365,
625,
28751,
1380,
282,
272,
1414,
365,
2797,
2240,
17174,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2088,
12,
1011,
958,
304,
267,
291,
14,
1760,
275,
2088,
267,
1613,
8,
3110,
2842,
12,
291,
2843,
826,
14155,
958,
9,
339,
347,
2198,
63,
589,
8,
277,
12,
1249,
29,
403,
12,
3231,
29,
403,
304,
267,
327,
32754,
4124,
1423,
367,
282,
8034,
1125,
1245,
267,
340,
334,
11161,
8,
277,
14,
1760,
12,
283,
4752,
63,
589,
63,
1188,
358,
436,
355,
440,
334,
589,
503,
1263,
8,
1397,
1680,
14,
2460,
21950,
367,
1680,
315,
1249,
15206,
288,
291,
14,
705,
8,
277,
14,
1760,
14,
4752,
63,
589,
63,
1188,
9,
267,
372,
1613,
8,
3110,
2842,
12,
291,
680,
1122,
63,
589,
8,
589,
12,
3231,
9,
339,
347,
1125,
8,
277,
12,
1245,
304,
267,
340,
291,
14,
1760,
423,
3527,
63,
504,
63,
1531,
63,
604,
26,
288,
1613,
8,
3110,
2842,
12,
291,
680,
705,
8,
1188,
9,
267,
587,
26,
288,
746,
14393,
480,
547,
26,
450,
83,
2,
450,
1245,
9,
421,
199,
318,
2429,
63,
885,
63,
1419,
8,
1419,
304,
272,
408,
272,
15783,
1263,
849,
1511,
626,
1006,
3718,
1077,
4729,
2348,
272,
880,
626,
8259,
17505,
883,
2429,
3062,
2544,
18112,
367,
272,
922,
3718,
14,
272,
408,
272,
340,
1511,
14,
1751,
26,
267,
747,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
418,
275,
1511,
14,
1751,
272,
340,
1511,
14,
1548,
515,
26,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
1511,
14,
1548,
515,
9,
421,
199,
533,
7242,
4590,
8,
785,
304,
272,
408,
272,
21947,
6818,
3839,
15,
3083,
272,
408,
272,
768,
1829,
272,
347,
3449,
63,
1532,
8,
277,
304,
267,
372,
291,
423,
2487,
63,
1532,
339,
768,
2487,
63,
1532,
14,
8345,
272,
347,
3449,
63,
1532,
8,
277,
12,
3449,
63,
1532,
304,
267,
340,
3449,
63,
1532,
436,
291,
14,
21122,
837,
288,
291,
423,
2487,
63,
1532,
275,
3449,
63,
1532,
267,
587,
26,
288,
291,
423,
2487,
63,
1532,
275,
2400,
671,
26,
671,
339,
347,
636,
826,
721,
277,
12,
734,
12,
3449,
63,
1532,
29,
403,
12,
13401,
17115,
78,
735,
267,
291,
423,
548,
275,
734,
267,
291,
14,
2487,
63,
1532,
275,
488,
267,
291,
14,
3219,
275,
13401,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
372,
2519,
8,
277,
423,
548,
12,
536,
9,
339,
347,
365,
16623,
8,
277,
304,
267,
372,
2688,
8,
277,
423,
548,
12,
283,
21122,
358,
436,
291,
423,
548,
14,
21122,
342,
339,
347,
2218,
8,
277,
12,
1499,
12,
3449,
63,
1532,
29,
403,
12,
13401,
29,
403,
304,
267,
13401,
275,
291,
14,
3219,
340,
13401,
365,
488,
587,
13401,
267,
340,
13401,
436,
440,
1499,
14,
4130,
8,
3219,
304,
288,
1499,
847,
13401,
267,
3449,
63,
1532,
275,
3449,
63,
1532,
503,
291,
14,
2487,
63,
1532,
267,
291,
423,
548,
14,
952,
8,
3990,
63,
495,
8,
2487,
63,
1532,
8,
1328,
1724,
421,
199,
533,
22239,
8,
785,
304,
272,
408,
272,
710,
1300,
1021,
687,
1314,
1006,
10041,
3718,
221,
1141,
77,
13824,
272,
23519,
14,
339,
3645,
642,
1021,
340,
1265,
2934,
2879,
370,
1006,
402,
314,
562,
10832,
706,
1314,
272,
2198,
314,
1414,
13,
604,
2368,
436,
1736,
734,
4052,
1233,
370,
1240,
315,
272,
1177,
27,
340,
1265,
2793,
1133,
1929,
370,
1570,
1263,
402,
626,
5953,
12,
272,
11201,
1808,
1373,
402,
314,
9180,
3247,
315,
642,
570,
14,
339,
982,
1265,
787,
22201,
315,
18972,
15,
4229,
9147,
7750,
17435,
83,
402,
272,
314,
1414,
13,
11059,
436,
446,
9416,
5953,
12,
314,
3293,
6369,
5419,
272,
465,
11924,
26,
339,
413,
14,
1124,
1176,
13,
2113,
1040,
503,
1124,
9053,
14,
647,
1040,
14404,
314,
1414,
1021,
2126,
436,
4882,
2399,
1124,
1065,
63,
504,
63,
3020,
8497,
1083,
14,
339,
499,
14,
710,
1124,
1065,
63,
504,
63,
3020,
8497,
1083,
4882,
1124,
981,
63,
2087,
8497,
370,
664,
2126,
376,
1124,
10730,
1040,
367,
314,
2368,
12,
19953,
3062,
12,
18628,
2126,
1263,
3734,
4493,
5839,
701,
1511,
2839,
2126,
1124,
1548,
515,
4542,
436,
2066,
4882,
314,
1124,
2526,
8497,
1083,
12,
2126,
9476,
314,
4565,
2368,
14,
339,
650,
14,
710,
1124,
2526,
8497,
1083,
12454,
370,
25176,
734,
314
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1563,
3992,
367,
3575,
10041,
3718,
334,
4579,
3718,
1314,
883,
199,
1235,
7934,
4012,
1124,
1176,
13,
2113,
1040,
503,
1124,
9053,
14,
647,
20008,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
984,
199,
646,
3598,
199,
504,
7534,
492,
27615,
199,
504,
8691,
492,
13491,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
492,
5920,
199,
504,
1639,
14,
1018,
14,
8110,
14,
2326,
492,
3164,
63,
2487,
12,
949,
63,
2487,
199,
504,
1639,
14,
697,
492,
6947,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
6019,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
421,
199,
533,
14393,
8,
1726,
304,
272,
408,
272,
2186,
1021,
9297,
282,
5160,
1830,
14043,
282,
10041,
272,
1414,
14,
339,
982,
642,
1919,
365,
4915,
5309,
314,
6451,
402,
282,
10041,
272,
1414,
12,
652,
911,
506,
15604,
436,
19136,
1901,
282,
14213,
590,
13,
27131,
1125,
272,
1245,
370,
314,
5827,
1072,
2547,
334,
73,
14,
69,
2020,
4635,
2736,
465,
282,
272,
754,
12,
17026,
642,
1919,
334,
1045,
282,
27962,
1369,
402,
314,
272,
1125,
9,
365,
314,
14388,
4340,
370,
6623,
626,
6020,
965,
21737,
272,
6835,
315,
314,
6451,
402,
282,
1414,
14,
272,
408,
272,
986,
421,
199,
533,
6187,
1799,
547,
8,
31542,
304,
272,
408,
272,
710,
2656,
1104,
10059,
10501,
625,
23131,
461,
2552,
14,
272,
408,
272,
986,
421,
199,
533,
5817,
2842,
8,
10730,
304,
272,
408,
272,
8388,
1759,
27615,
1021,
370,
19053,
2005,
1125,
3788,
436,
7981,
272,
14838,
315,
9978,
14706,
305,
15293,
12,
465,
14838,
365,
625,
28751,
1380,
282,
272,
1414,
365,
2797,
2240,
17174,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2088,
12,
1011,
958,
304,
267,
291,
14,
1760,
275,
2088,
267,
1613,
8,
3110,
2842,
12,
291,
2843,
826,
14155,
958,
9,
339,
347,
2198,
63,
589,
8,
277,
12,
1249,
29,
403,
12,
3231,
29,
403,
304,
267,
327,
32754,
4124,
1423,
367,
282,
8034,
1125,
1245,
267,
340,
334,
11161,
8,
277,
14,
1760,
12,
283,
4752,
63,
589,
63,
1188,
358,
436,
355,
440,
334,
589,
503,
1263,
8,
1397,
1680,
14,
2460,
21950,
367,
1680,
315,
1249,
15206,
288,
291,
14,
705,
8,
277,
14,
1760,
14,
4752,
63,
589,
63,
1188,
9,
267,
372,
1613,
8,
3110,
2842,
12,
291,
680,
1122,
63,
589,
8,
589,
12,
3231,
9,
339,
347,
1125,
8,
277,
12,
1245,
304,
267,
340,
291,
14,
1760,
423,
3527,
63,
504,
63,
1531,
63,
604,
26,
288,
1613,
8,
3110,
2842,
12,
291,
680,
705,
8,
1188,
9,
267,
587,
26,
288,
746,
14393,
480,
547,
26,
450,
83,
2,
450,
1245,
9,
421,
199,
318,
2429,
63,
885,
63,
1419,
8,
1419,
304,
272,
408,
272,
15783,
1263,
849,
1511,
626,
1006,
3718,
1077,
4729,
2348,
272,
880,
626,
8259,
17505,
883,
2429,
3062,
2544,
18112,
367,
272,
922,
3718,
14,
272,
408,
272,
340,
1511,
14,
1751,
26,
267,
747,
14,
2314,
459,
22848,
63,
13931,
63,
10001,
418,
275,
1511,
14,
1751,
272,
340,
1511,
14,
1548,
515,
26,
267,
984,
14,
515,
14,
3176,
8,
16,
12,
1511,
14,
1548,
515,
9,
421,
199,
533,
7242,
4590,
8,
785,
304,
272,
408,
272,
21947,
6818,
3839,
15,
3083,
272,
408,
272,
768,
1829,
272,
347,
3449,
63,
1532,
8,
277,
304,
267,
372,
291,
423,
2487,
63,
1532,
339,
768,
2487,
63,
1532,
14,
8345,
272,
347,
3449,
63,
1532,
8,
277,
12,
3449,
63,
1532,
304,
267,
340,
3449,
63,
1532,
436,
291,
14,
21122,
837,
288,
291,
423,
2487,
63,
1532,
275,
3449,
63,
1532,
267,
587,
26,
288,
291,
423,
2487,
63,
1532,
275,
2400,
671,
26,
671,
339,
347,
636,
826,
721,
277,
12,
734,
12,
3449,
63,
1532,
29,
403,
12,
13401,
17115,
78,
735,
267,
291,
423,
548,
275,
734,
267,
291,
14,
2487,
63,
1532,
275,
488,
267,
291,
14,
3219,
275,
13401,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
372,
2519,
8,
277,
423,
548,
12,
536,
9,
339,
347,
365,
16623,
8,
277,
304,
267,
372,
2688,
8,
277,
423,
548,
12,
283,
21122,
358,
436,
291,
423,
548,
14,
21122,
342,
339,
347,
2218,
8,
277,
12,
1499,
12,
3449,
63,
1532,
29,
403,
12,
13401,
29,
403,
304,
267,
13401,
275,
291,
14,
3219,
340,
13401,
365,
488,
587,
13401,
267,
340,
13401,
436,
440,
1499,
14,
4130,
8,
3219,
304,
288,
1499,
847,
13401,
267,
3449,
63,
1532,
275,
3449,
63,
1532,
503,
291,
14,
2487,
63,
1532,
267,
291,
423,
548,
14,
952,
8,
3990,
63,
495,
8,
2487,
63,
1532,
8,
1328,
1724,
421,
199,
533,
22239,
8,
785,
304,
272,
408,
272,
710,
1300,
1021,
687,
1314,
1006,
10041,
3718,
221,
1141,
77,
13824,
272,
23519,
14,
339,
3645,
642,
1021,
340,
1265,
2934,
2879,
370,
1006,
402,
314,
562,
10832,
706,
1314,
272,
2198,
314,
1414,
13,
604,
2368,
436,
1736,
734,
4052,
1233,
370,
1240,
315,
272,
1177,
27,
340,
1265,
2793,
1133,
1929,
370,
1570,
1263,
402,
626,
5953,
12,
272,
11201,
1808,
1373,
402,
314,
9180,
3247,
315,
642,
570,
14,
339,
982,
1265,
787,
22201,
315,
18972,
15,
4229,
9147,
7750,
17435,
83,
402,
272,
314,
1414,
13,
11059,
436,
446,
9416,
5953,
12,
314,
3293,
6369,
5419,
272,
465,
11924,
26,
339,
413,
14,
1124,
1176,
13,
2113,
1040,
503,
1124,
9053,
14,
647,
1040,
14404,
314,
1414,
1021,
2126,
436,
4882,
2399,
1124,
1065,
63,
504,
63,
3020,
8497,
1083,
14,
339,
499,
14,
710,
1124,
1065,
63,
504,
63,
3020,
8497,
1083,
4882,
1124,
981,
63,
2087,
8497,
370,
664,
2126,
376,
1124,
10730,
1040,
367,
314,
2368,
12,
19953,
3062,
12,
18628,
2126,
1263,
3734,
4493,
5839,
701,
1511,
2839,
2126,
1124,
1548,
515,
4542,
436,
2066,
4882,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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
] |
cytec/Sick-Beard
|
sickbeard/versionChecker.py
|
2
|
18662
|
# Author: Nic Wolfe <nic@wolfeden.ca>
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of Sick Beard.
#
# Sick Beard 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.
#
# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>.
import sickbeard
from sickbeard import version, ui
from sickbeard import logger
from sickbeard import scene_exceptions
from sickbeard.exceptions import ex
import os, platform, shutil
import subprocess, re
import urllib, urllib2
import zipfile, tarfile
from urllib2 import URLError
import gh_api as github
class CheckVersion():
"""
Version check class meant to run as a thread object with the SB scheduler.
"""
def __init__(self):
self.install_type = self.find_install_type()
if self.install_type == 'win':
self.updater = WindowsUpdateManager()
elif self.install_type == 'git':
self.updater = GitUpdateManager()
elif self.install_type == 'source':
self.updater = SourceUpdateManager()
else:
self.updater = None
def run(self):
self.check_for_new_version()
# refresh scene exceptions too
scene_exceptions.retrieve_exceptions()
def find_install_type(self):
"""
Determines how this copy of SB was installed.
returns: type of installation. Possible values are:
'win': any compiled windows build
'git': running from source using git
'source': running from source without git
"""
# check if we're a windows build
if version.SICKBEARD_VERSION.startswith('build '):
install_type = 'win'
elif os.path.isdir(os.path.join(sickbeard.PROG_DIR, '.git')):
install_type = 'git'
else:
install_type = 'source'
return install_type
def check_for_new_version(self, force=False):
"""
Checks the internet for a newer version.
returns: bool, True for new version or False for no new version.
force: if true the VERSION_NOTIFY setting will be ignored and a check will be forced
"""
if not sickbeard.VERSION_NOTIFY and not force:
logger.log(u"Version checking is disabled, not checking for the newest version")
return False
logger.log(u"Checking if "+self.install_type+" needs an update")
if not self.updater.need_update():
logger.log(u"No update needed")
if force:
ui.notifications.message('No update needed')
return False
self.updater.set_newest_text()
return True
def update(self):
if self.updater.need_update():
return self.updater.update()
class UpdateManager():
def get_update_url(self):
return sickbeard.WEB_ROOT+"/home/update/?pid="+str(sickbeard.PID)
class WindowsUpdateManager(UpdateManager):
def __init__(self):
self._cur_version = None
self._cur_commit_hash = None
self._newest_version = None
self.gc_url = 'http://code.google.com/p/sickbeard/downloads/list'
self.version_url = 'https://raw.github.com/cytec/Sick-Beard/windows_binaries/updates.txt'
def _find_installed_version(self):
return int(sickbeard.version.SICKBEARD_VERSION[6:])
def _find_newest_version(self, whole_link=False):
"""
Checks git for the newest Windows binary build. Returns either the
build number or the entire build URL depending on whole_link's value.
whole_link: If True, returns the entire URL to the release. If False, it returns
only the build number. default: False
"""
regex = ".*SickBeard\-win32\-alpha\-build(\d+)(?:\.\d+)?\.zip"
svnFile = urllib.urlopen(self.version_url)
for curLine in svnFile.readlines():
logger.log(u"checking line "+curLine, logger.DEBUG)
match = re.match(regex, curLine)
if match:
logger.log(u"found a match", logger.DEBUG)
if whole_link:
return curLine.strip()
else:
return int(match.group(1))
return None
def need_update(self):
self._cur_version = self._find_installed_version()
self._newest_version = self._find_newest_version()
logger.log(u"newest version: "+repr(self._newest_version), logger.DEBUG)
if self._newest_version and self._newest_version > self._cur_version:
return True
def set_newest_text(self):
new_str = 'There is a <a href="'+self.gc_url+'" onclick="window.open(this.href); return false;">newer version available</a> (build '+str(self._newest_version)+')'
new_str += "— <a href=\""+self.get_update_url()+"\">Update Now</a>"
sickbeard.NEWEST_VERSION_STRING = new_str
def update(self):
new_link = self._find_newest_version(True)
logger.log(u"new_link: " + repr(new_link), logger.DEBUG)
if not new_link:
logger.log(u"Unable to find a new version link on google code, not updating")
return False
# download the zip
try:
logger.log(u"Downloading update file from "+str(new_link))
(filename, headers) = urllib.urlretrieve(new_link) #@UnusedVariable
# prepare the update dir
sb_update_dir = os.path.join(sickbeard.PROG_DIR, 'sb-update')
logger.log(u"Clearing out update folder "+sb_update_dir+" before unzipping")
if os.path.isdir(sb_update_dir):
shutil.rmtree(sb_update_dir)
# unzip it to sb-update
logger.log(u"Unzipping from "+str(filename)+" to "+sb_update_dir)
update_zip = zipfile.ZipFile(filename, 'r')
update_zip.extractall(sb_update_dir)
update_zip.close()
# find update dir name
update_dir_contents = os.listdir(sb_update_dir)
if len(update_dir_contents) != 1:
logger.log("Invalid update data, update failed. Maybe try deleting your sb-update folder?", logger.ERROR)
return False
content_dir = os.path.join(sb_update_dir, update_dir_contents[0])
old_update_path = os.path.join(content_dir, 'updater.exe')
new_update_path = os.path.join(sickbeard.PROG_DIR, 'updater.exe')
logger.log(u"Copying new update.exe file from "+old_update_path+" to "+new_update_path)
shutil.move(old_update_path, new_update_path)
# delete the zip
logger.log(u"Deleting zip file from "+str(filename))
os.remove(filename)
except Exception, e:
logger.log(u"Error while trying to update: "+ex(e), logger.ERROR)
return False
return True
class GitUpdateManager(UpdateManager):
def __init__(self):
self._cur_commit_hash = None
self._newest_commit_hash = None
self._num_commits_behind = 0
self.git_url = 'http://code.google.com/p/sickbeard/downloads/list'
self.branch = self._find_git_branch()
def _git_error(self):
error_message = 'Unable to find your git executable - either delete your .git folder and run from source OR <a href="http://code.google.com/p/sickbeard/wiki/AdvancedSettings" onclick="window.open(this.href); return false;">set git_path in your config.ini</a> to enable updates.'
sickbeard.NEWEST_VERSION_STRING = error_message
return None
def _run_git(self, args):
if sickbeard.GIT_PATH:
git_locations = ['"'+sickbeard.GIT_PATH+'"']
else:
git_locations = ['git']
# osx people who start SB from launchd have a broken path, so try a hail-mary attempt for them
if platform.system().lower() == 'darwin':
git_locations.append('/usr/local/git/bin/git')
output = err = None
for cur_git in git_locations:
cmd = cur_git+' '+args
try:
logger.log(u"Executing "+cmd+" with your shell in "+sickbeard.PROG_DIR, logger.DEBUG)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=sickbeard.PROG_DIR)
output, err = p.communicate()
logger.log(u"git output: "+output, logger.DEBUG)
except OSError:
logger.log(u"Command "+cmd+" didn't work, couldn't find git.")
continue
if p.returncode != 0 or 'not found' in output or "not recognized as an internal or external command" in output:
logger.log(u"Unable to find git with command "+cmd, logger.DEBUG)
output = None
elif 'fatal:' in output or err:
logger.log(u"Git returned bad info, are you sure this is a git installation?", logger.ERROR)
output = None
elif output:
break
return (output, err)
def _find_installed_version(self):
"""
Attempts to find the currently installed version of Sick Beard.
Uses git show to get commit version.
Returns: True for success or False for failure
"""
output, err = self._run_git('rev-parse HEAD') #@UnusedVariable
if not output:
return self._git_error()
logger.log(u"Git output: "+str(output), logger.DEBUG)
cur_commit_hash = output.strip()
if not re.match('^[a-z0-9]+$', cur_commit_hash):
logger.log(u"Output doesn't look like a hash, not using it", logger.ERROR)
return self._git_error()
self._cur_commit_hash = cur_commit_hash
return True
def _find_git_branch(self):
branch_info = self._run_git('symbolic-ref -q HEAD')
if not branch_info or not branch_info[0]:
return 'master'
branch = branch_info[0].strip().replace('refs/heads/', '', 1)
return branch or 'master'
def _check_github_for_update(self):
"""
Uses pygithub to ask github if there is a newer version that the provided
commit hash. If there is a newer version it sets Sick Beard's version text.
commit_hash: hash that we're checking against
"""
self._num_commits_behind = 0
self._newest_commit_hash = None
gh = github.GitHub()
# find newest commit
for curCommit in gh.commits('cytec', 'Sick-Beard', self.branch):
if not self._newest_commit_hash:
self._newest_commit_hash = curCommit['sha']
if not self._cur_commit_hash:
break
if curCommit['sha'] == self._cur_commit_hash:
break
self._num_commits_behind += 1
logger.log(u"newest: "+str(self._newest_commit_hash)+" and current: "+str(self._cur_commit_hash)+" and num_commits: "+str(self._num_commits_behind), logger.DEBUG)
def set_newest_text(self):
# if we're up to date then don't set this
if self._num_commits_behind == 100:
message = "or else you're ahead of master"
elif self._num_commits_behind > 0:
message = "you're %d commit" % self._num_commits_behind
if self._num_commits_behind > 1: message += 's'
message += ' behind'
else:
return
if self._newest_commit_hash:
url = 'http://github.com/cytec/Sick-Beard/compare/'+self._cur_commit_hash+'...'+self._newest_commit_hash
else:
url = 'http://github.com/cytec/Sick-Beard/commits/'
new_str = 'There is a <a href="'+url+'" onclick="window.open(this.href); return false;">newer version available</a> ('+message+')'
new_str += "— <a href=\""+self.get_update_url()+"\">Update Now</a>"
sickbeard.NEWEST_VERSION_STRING = new_str
def need_update(self):
self._find_installed_version()
try:
self._check_github_for_update()
except Exception, e:
logger.log(u"Unable to contact github, can't check for update: "+repr(e), logger.ERROR)
return False
logger.log(u"After checking, cur_commit = "+str(self._cur_commit_hash)+", newest_commit = "+str(self._newest_commit_hash)+", num_commits_behind = "+str(self._num_commits_behind), logger.DEBUG)
if self._num_commits_behind > 0:
return True
return False
def update(self):
"""
Calls git pull origin <branch> in order to update Sick Beard. Returns a bool depending
on the call's success.
"""
output, err = self._run_git('pull origin '+self.branch) #@UnusedVariable
if not output:
return self._git_error()
pull_regex = '(\d+) .+,.+(\d+).+\(\+\),.+(\d+) .+\(\-\)'
(files, insertions, deletions) = (None, None, None)
for line in output.split('\n'):
if 'Already up-to-date.' in line:
logger.log(u"No update available, not updating")
logger.log(u"Output: "+str(output))
return False
elif line.endswith('Aborting.'):
logger.log(u"Unable to update from git: "+line, logger.ERROR)
logger.log(u"Output: "+str(output))
return False
match = re.search(pull_regex, line)
if match:
(files, insertions, deletions) = match.groups()
break
if None in (files, insertions, deletions):
logger.log(u"Didn't find indication of success in output, assuming git pull failed", logger.ERROR)
logger.log(u"Output: "+str(output))
return False
return True
class SourceUpdateManager(GitUpdateManager):
def _find_installed_version(self):
version_file = os.path.join(sickbeard.PROG_DIR, 'version.txt')
if not os.path.isfile(version_file):
self._cur_commit_hash = None
return
fp = open(version_file, 'r')
self._cur_commit_hash = fp.read().strip(' \n\r')
fp.close()
if not self._cur_commit_hash:
self._cur_commit_hash = None
def need_update(self):
parent_result = GitUpdateManager.need_update(self)
if not self._cur_commit_hash:
return True
else:
return parent_result
def set_newest_text(self):
if not self._cur_commit_hash:
logger.log(u"Unknown current version, don't know if we should update or not", logger.DEBUG)
new_str = "Unknown version: If you've never used the Sick Beard upgrade system then I don't know what version you have."
new_str += "— <a href=\""+self.get_update_url()+"\">Update Now</a>"
sickbeard.NEWEST_VERSION_STRING = new_str
else:
GitUpdateManager.set_newest_text(self)
def update(self):
"""
Downloads the latest source tarball from github and installs it over the existing version.
"""
tar_download_url = 'https://github.com/cytec/Sick-Beard/tarball/'+version.SICKBEARD_VERSION
sb_update_dir = os.path.join(sickbeard.PROG_DIR, 'sb-update')
version_path = os.path.join(sickbeard.PROG_DIR, 'version.txt')
# retrieve file
try:
logger.log(u"Downloading update from "+tar_download_url)
data = urllib2.urlopen(tar_download_url)
except (IOError, URLError):
logger.log(u"Unable to retrieve new version from "+tar_download_url+", can't update", logger.ERROR)
return False
download_name = data.geturl().split('/')[-1].split('?')[0]
tar_download_path = os.path.join(sickbeard.PROG_DIR, download_name)
# save to disk
f = open(tar_download_path, 'wb')
f.write(data.read())
f.close()
# extract to temp folder
logger.log(u"Extracting file "+tar_download_path)
tar = tarfile.open(tar_download_path)
tar.extractall(sb_update_dir)
tar.close()
# delete .tar.gz
logger.log(u"Deleting file "+tar_download_path)
os.remove(tar_download_path)
# find update dir name
update_dir_contents = [x for x in os.listdir(sb_update_dir) if os.path.isdir(os.path.join(sb_update_dir, x))]
if len(update_dir_contents) != 1:
logger.log(u"Invalid update data, update failed: "+str(update_dir_contents), logger.ERROR)
return False
content_dir = os.path.join(sb_update_dir, update_dir_contents[0])
# walk temp folder and move files to main folder
for dirname, dirnames, filenames in os.walk(content_dir): #@UnusedVariable
dirname = dirname[len(content_dir)+1:]
for curfile in filenames:
old_path = os.path.join(content_dir, dirname, curfile)
new_path = os.path.join(sickbeard.PROG_DIR, dirname, curfile)
if os.path.isfile(new_path):
os.remove(new_path)
os.renames(old_path, new_path)
# update version.txt with commit hash
try:
ver_file = open(version_path, 'w')
ver_file.write(self._newest_commit_hash)
ver_file.close()
except IOError, e:
logger.log(u"Unable to write version file, update not complete: "+ex(e), logger.ERROR)
return False
return True
|
gpl-3.0
|
[
3,
6529,
26,
653,
530,
644,
79,
276,
69,
665,
12165,
32,
28070,
69,
848,
14,
696,
30,
202,
199,
3,
2851,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
32370,
15283,
15,
202,
199,
3,
202,
199,
3,
961,
570,
365,
1777,
402,
28964,
6423,
1005,
14,
202,
199,
3,
202,
199,
3,
28964,
6423,
1005,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
202,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
202,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
202,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
28964,
6423,
1005,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
202,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
202,
199,
3,
3180,
543,
28964,
6423,
1005,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
2999,
199,
646,
17898,
202,
199,
504,
17898,
492,
1015,
12,
8574,
202,
199,
504,
17898,
492,
2512,
202,
199,
504,
17898,
492,
13856,
63,
3924,
202,
199,
504,
17898,
14,
3924,
492,
444,
2999,
199,
646,
747,
12,
4298,
12,
5145,
202,
199,
646,
3873,
12,
295,
202,
199,
646,
4011,
12,
4011,
18,
202,
199,
646,
10392,
12,
13608,
2999,
199,
504,
4011,
18,
492,
30794,
202,
199,
646,
23310,
63,
1246,
465,
12869,
2999,
199,
533,
2670,
3353,
837,
1128,
408,
1128,
3394,
1104,
1021,
18329,
370,
1255,
465,
282,
2462,
909,
543,
314,
26811,
11899,
14,
1128,
408,
2958,
347,
636,
826,
721,
277,
304,
1039,
291,
14,
3174,
63,
466,
275,
291,
14,
1623,
63,
3174,
63,
466,
342,
4341,
340,
291,
14,
3174,
63,
466,
508,
283,
2676,
356,
1675,
291,
14,
29645,
275,
5417,
4152,
2988,
342,
1039,
916,
291,
14,
3174,
63,
466,
508,
283,
3187,
356,
1675,
291,
14,
29645,
275,
12579,
4152,
2988,
342,
1039,
916,
291,
14,
3174,
63,
466,
508,
283,
1365,
356,
1675,
291,
14,
29645,
275,
5800,
4152,
2988,
342,
1039,
587,
26,
1675,
291,
14,
29645,
275,
488,
2958,
347,
1255,
8,
277,
304,
1039,
291,
14,
1074,
63,
509,
63,
1222,
63,
1023,
342,
13594,
327,
9236,
13856,
4967,
4634,
1039,
13856,
63,
3924,
14,
14270,
63,
3924,
342,
2958,
347,
2342,
63,
3174,
63,
466,
8,
277,
304,
1039,
408,
1039,
22391,
4212,
642,
1331,
402,
26811,
1990,
4903,
14,
13594,
2529,
26,
730,
402,
12096,
14,
18558,
1338,
787,
26,
1675,
283,
2676,
356,
1263,
10311,
10061,
1900,
1675,
283,
3187,
356,
3879,
687,
1350,
1808,
6135,
1675,
283,
1365,
356,
3879,
687,
1350,
1928,
6135,
1039,
408,
4341,
327,
1104,
340,
781,
3984,
282,
10061,
1900,
1039,
340,
1015,
14,
51,
13884,
6773,
7816,
63,
4612,
14,
2460,
360,
1506,
18927,
1675,
3907,
63,
466,
275,
283,
2676,
7,
1039,
916,
747,
14,
515,
14,
6027,
8,
736,
14,
515,
14,
904,
8,
32370,
15283,
14,
2514,
39,
63,
3022,
12,
1987,
3187,
8109,
1675,
3907,
63,
466,
275,
283,
3187,
7,
1039,
587,
26,
1675,
3907,
63,
466,
275,
283,
1365,
7,
4341,
372,
3907,
63,
466,
2958,
347,
1104,
63,
509,
63,
1222,
63,
1023,
8,
277,
12,
3542,
29,
797,
304,
1039,
408,
1039,
13813,
314,
21408,
367,
282,
15666,
1015,
14,
13594,
2529,
26,
2155,
12,
715,
367,
892,
1015,
503,
756,
367,
949,
892,
1015,
14,
13594,
3542,
26,
340,
2549,
314,
15945,
63,
24972,
4260,
911,
506,
5525,
436,
282,
1104,
911,
506,
19565,
1039,
408,
4341,
340,
440,
17898,
14,
4612,
63,
24972,
436,
440,
3542,
26,
1675,
2512,
14,
793,
8,
85,
2,
3353,
7907,
365,
6980,
12,
440,
7907,
367,
314,
29608,
1015,
531,
1675,
372,
756,
4341,
2512,
14,
793,
8,
85,
2,
14740,
340,
7210,
277,
14,
3174,
63,
466,
5207,
4839,
376,
1678,
531,
1039,
340,
440,
291,
14,
29645,
14,
9321,
63,
873,
837,
1675,
2512,
14,
793,
8,
85,
2,
1944,
1678,
4346,
531,
1675,
340,
3542,
26,
2628,
8574,
14,
12782,
14,
1188,
360,
1944,
1678,
4346,
358,
1675,
372,
756,
4341,
291,
14,
29645,
14,
409,
63,
1222,
597,
63,
505,
342,
1039,
372,
715,
2958,
347,
1678,
8,
277,
304,
1039,
340,
291,
14,
29645,
14,
9321,
63,
873,
837,
1675,
372,
291,
14,
29645,
14,
873,
342,
2999,
199,
533,
6162,
2988,
837,
1128,
347,
664,
63,
873,
63,
633,
8,
277,
304,
1039,
372,
17898,
14,
13166,
63,
5441,
24792,
4219,
15,
873,
10197,
3150,
16368,
495,
8,
32370,
15283,
14,
16098,
9,
2999,
199,
533,
5417,
4152,
2988,
8,
4152,
2988,
304,
2958,
347,
636,
826,
721,
277,
304,
1039,
291,
423,
895,
63,
1023,
275,
488,
1039,
291,
423,
895,
63,
3543,
63,
2227,
275,
488,
1039,
291,
423,
1222,
597,
63,
1023,
275,
488,
4341,
291,
14,
9493,
63,
633,
275,
283,
1014,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
32370,
15283,
15,
20373,
15,
513,
7,
1039,
291,
14,
1023,
63,
633,
275,
283,
2859,
921,
1773,
14,
5031,
14,
957,
15,
1480,
266,
67,
15,
51,
2000,
13,
3655,
1005,
15,
8258,
63,
27542,
15,
7618,
14,
2424,
7,
2958,
347,
485,
1623,
63,
7657,
63,
1023,
8,
277,
304,
1039,
372,
1109,
8,
32370,
15283,
14,
1023,
14,
51,
13884,
6773,
7816,
63,
4612,
59,
22,
5728,
2958,
347,
485,
1623,
63,
1222,
597,
63,
1023,
8,
277,
12,
8852,
63,
1073,
29,
797,
304,
1039,
408,
1039,
13813,
6135,
367,
314,
29608,
5417,
3366,
1900,
14,
1803,
1902,
314,
1039,
1900,
1329,
503,
314,
8039,
1900,
2851,
10298,
641,
8852,
63,
1073,
1159,
574,
14,
4341,
8852,
63,
1073,
26,
982,
715,
12,
2529,
314,
8039,
2851,
370,
314,
4683,
14,
982,
756,
12,
652,
2529,
4906,
1454,
314
] |
[
6529,
26,
653,
530,
644,
79,
276,
69,
665,
12165,
32,
28070,
69,
848,
14,
696,
30,
202,
199,
3,
2851,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
32370,
15283,
15,
202,
199,
3,
202,
199,
3,
961,
570,
365,
1777,
402,
28964,
6423,
1005,
14,
202,
199,
3,
202,
199,
3,
28964,
6423,
1005,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
202,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
202,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
202,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
28964,
6423,
1005,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
202,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
202,
199,
3,
3180,
543,
28964,
6423,
1005,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
2999,
199,
646,
17898,
202,
199,
504,
17898,
492,
1015,
12,
8574,
202,
199,
504,
17898,
492,
2512,
202,
199,
504,
17898,
492,
13856,
63,
3924,
202,
199,
504,
17898,
14,
3924,
492,
444,
2999,
199,
646,
747,
12,
4298,
12,
5145,
202,
199,
646,
3873,
12,
295,
202,
199,
646,
4011,
12,
4011,
18,
202,
199,
646,
10392,
12,
13608,
2999,
199,
504,
4011,
18,
492,
30794,
202,
199,
646,
23310,
63,
1246,
465,
12869,
2999,
199,
533,
2670,
3353,
837,
1128,
408,
1128,
3394,
1104,
1021,
18329,
370,
1255,
465,
282,
2462,
909,
543,
314,
26811,
11899,
14,
1128,
408,
2958,
347,
636,
826,
721,
277,
304,
1039,
291,
14,
3174,
63,
466,
275,
291,
14,
1623,
63,
3174,
63,
466,
342,
4341,
340,
291,
14,
3174,
63,
466,
508,
283,
2676,
356,
1675,
291,
14,
29645,
275,
5417,
4152,
2988,
342,
1039,
916,
291,
14,
3174,
63,
466,
508,
283,
3187,
356,
1675,
291,
14,
29645,
275,
12579,
4152,
2988,
342,
1039,
916,
291,
14,
3174,
63,
466,
508,
283,
1365,
356,
1675,
291,
14,
29645,
275,
5800,
4152,
2988,
342,
1039,
587,
26,
1675,
291,
14,
29645,
275,
488,
2958,
347,
1255,
8,
277,
304,
1039,
291,
14,
1074,
63,
509,
63,
1222,
63,
1023,
342,
13594,
327,
9236,
13856,
4967,
4634,
1039,
13856,
63,
3924,
14,
14270,
63,
3924,
342,
2958,
347,
2342,
63,
3174,
63,
466,
8,
277,
304,
1039,
408,
1039,
22391,
4212,
642,
1331,
402,
26811,
1990,
4903,
14,
13594,
2529,
26,
730,
402,
12096,
14,
18558,
1338,
787,
26,
1675,
283,
2676,
356,
1263,
10311,
10061,
1900,
1675,
283,
3187,
356,
3879,
687,
1350,
1808,
6135,
1675,
283,
1365,
356,
3879,
687,
1350,
1928,
6135,
1039,
408,
4341,
327,
1104,
340,
781,
3984,
282,
10061,
1900,
1039,
340,
1015,
14,
51,
13884,
6773,
7816,
63,
4612,
14,
2460,
360,
1506,
18927,
1675,
3907,
63,
466,
275,
283,
2676,
7,
1039,
916,
747,
14,
515,
14,
6027,
8,
736,
14,
515,
14,
904,
8,
32370,
15283,
14,
2514,
39,
63,
3022,
12,
1987,
3187,
8109,
1675,
3907,
63,
466,
275,
283,
3187,
7,
1039,
587,
26,
1675,
3907,
63,
466,
275,
283,
1365,
7,
4341,
372,
3907,
63,
466,
2958,
347,
1104,
63,
509,
63,
1222,
63,
1023,
8,
277,
12,
3542,
29,
797,
304,
1039,
408,
1039,
13813,
314,
21408,
367,
282,
15666,
1015,
14,
13594,
2529,
26,
2155,
12,
715,
367,
892,
1015,
503,
756,
367,
949,
892,
1015,
14,
13594,
3542,
26,
340,
2549,
314,
15945,
63,
24972,
4260,
911,
506,
5525,
436,
282,
1104,
911,
506,
19565,
1039,
408,
4341,
340,
440,
17898,
14,
4612,
63,
24972,
436,
440,
3542,
26,
1675,
2512,
14,
793,
8,
85,
2,
3353,
7907,
365,
6980,
12,
440,
7907,
367,
314,
29608,
1015,
531,
1675,
372,
756,
4341,
2512,
14,
793,
8,
85,
2,
14740,
340,
7210,
277,
14,
3174,
63,
466,
5207,
4839,
376,
1678,
531,
1039,
340,
440,
291,
14,
29645,
14,
9321,
63,
873,
837,
1675,
2512,
14,
793,
8,
85,
2,
1944,
1678,
4346,
531,
1675,
340,
3542,
26,
2628,
8574,
14,
12782,
14,
1188,
360,
1944,
1678,
4346,
358,
1675,
372,
756,
4341,
291,
14,
29645,
14,
409,
63,
1222,
597,
63,
505,
342,
1039,
372,
715,
2958,
347,
1678,
8,
277,
304,
1039,
340,
291,
14,
29645,
14,
9321,
63,
873,
837,
1675,
372,
291,
14,
29645,
14,
873,
342,
2999,
199,
533,
6162,
2988,
837,
1128,
347,
664,
63,
873,
63,
633,
8,
277,
304,
1039,
372,
17898,
14,
13166,
63,
5441,
24792,
4219,
15,
873,
10197,
3150,
16368,
495,
8,
32370,
15283,
14,
16098,
9,
2999,
199,
533,
5417,
4152,
2988,
8,
4152,
2988,
304,
2958,
347,
636,
826,
721,
277,
304,
1039,
291,
423,
895,
63,
1023,
275,
488,
1039,
291,
423,
895,
63,
3543,
63,
2227,
275,
488,
1039,
291,
423,
1222,
597,
63,
1023,
275,
488,
4341,
291,
14,
9493,
63,
633,
275,
283,
1014,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
32370,
15283,
15,
20373,
15,
513,
7,
1039,
291,
14,
1023,
63,
633,
275,
283,
2859,
921,
1773,
14,
5031,
14,
957,
15,
1480,
266,
67,
15,
51,
2000,
13,
3655,
1005,
15,
8258,
63,
27542,
15,
7618,
14,
2424,
7,
2958,
347,
485,
1623,
63,
7657,
63,
1023,
8,
277,
304,
1039,
372,
1109,
8,
32370,
15283,
14,
1023,
14,
51,
13884,
6773,
7816,
63,
4612,
59,
22,
5728,
2958,
347,
485,
1623,
63,
1222,
597,
63,
1023,
8,
277,
12,
8852,
63,
1073,
29,
797,
304,
1039,
408,
1039,
13813,
6135,
367,
314,
29608,
5417,
3366,
1900,
14,
1803,
1902,
314,
1039,
1900,
1329,
503,
314,
8039,
1900,
2851,
10298,
641,
8852,
63,
1073,
1159,
574,
14,
4341,
8852,
63,
1073,
26,
982,
715,
12,
2529,
314,
8039,
2851,
370,
314,
4683,
14,
982,
756,
12,
652,
2529,
4906,
1454,
314,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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ypes.
'''
from llvm.core import Type, Module
import llvm.ee as le
import ctypes as ct
MAP_CTYPES = {
'void' : None,
'bool' : ct.c_bool,
'char' : ct.c_char,
'uchar' : ct.c_ubyte,
'short' : ct.c_short,
'ushort' : ct.c_ushort,
'int' : ct.c_int,
'uint' : ct.c_uint,
'long' : ct.c_long,
'ulong' : ct.c_ulong,
'int8' : ct.c_int8,
'uint8' : ct.c_uint8,
'int16' : ct.c_int16,
'uint16' : ct.c_uint16,
'int32' : ct.c_int32,
'uint32' : ct.c_uint32,
'int64' : ct.c_int64,
'uint64' : ct.c_uint64,
'float' : ct.c_float,
'double' : ct.c_double,
'longdouble' : ct.c_longdouble,
}
class CExecutor(object):
'''a convenient class for creating ctype functions from LLVM modules
'''
def __init__(self, mod_or_engine):
if isinstance(mod_or_engine, Module):
self.engine = le.EngineBuilder.new(mod_or_engine).opt(3).create()
else:
self.engine = mod_or_engine
def get_ctype_function(self, fn, *typeinfo):
'''create a ctype function from a LLVM function
typeinfo : string of types (see `MAP_CTYPES`) or
list of ctypes datatype.
First value is the return type.
A function that takes no argument and return nothing
should use `"void"` or `None`.
'''
if len(typeinfo)==1 and isinstance(typeinfo[0], str):
types = [ MAP_CTYPES[s.strip()] for s in typeinfo[0].split(',') ]
if not types:
retty = None
argtys = []
else:
retty = types[0]
argtys = types[1:]
else:
retty = typeinfo[0]
argtys = typeinfo[1:]
prototype = ct.CFUNCTYPE(retty, *argtys)
fnptr = self.engine.get_pointer_to_function(fn)
return prototype(fnptr)
|
bsd-3-clause
|
[
2344,
199,
2765,
365,
19762,
282,
16777,
859,
367,
5343,
543,
5577,
14,
199,
2344,
199,
199,
504,
18338,
2611,
14,
1018,
492,
2434,
12,
5673,
199,
646,
18338,
2611,
14,
1024,
465,
1026,
199,
646,
5577,
465,
9428,
199,
199,
5443,
63,
1028,
24583,
275,
469,
199,
7,
1647,
7,
755,
520,
257,
488,
12,
199,
7,
2245,
7,
755,
520,
257,
9428,
14,
67,
63,
2245,
12,
199,
7,
1560,
7,
755,
520,
257,
9428,
14,
67,
63,
1560,
12,
199,
7,
85,
1560,
7,
420,
520,
257,
9428,
14,
67,
63,
20790,
12,
199,
1159,
7222,
7,
420,
520,
257,
9428,
14,
67,
63,
3612,
12,
199,
7,
27170,
7,
258,
520,
257,
9428,
14,
67,
63,
27170,
12,
199,
7,
442,
7,
263,
520,
257,
9428,
14,
67,
63,
442,
12,
199,
7,
1635,
7,
755,
520,
257,
9428,
14,
67,
63,
1635,
12,
199,
7,
2809,
7,
755,
520,
257,
9428,
14,
67,
63,
2809,
12,
199,
7,
15688,
7,
420,
520,
257,
9428,
14,
67,
63,
15688,
12,
199,
199,
7,
442,
24,
7,
755,
520,
257,
9428,
14,
67,
63,
442,
24,
12,
199,
7,
1635,
24,
7,
420,
520,
257,
9428,
14,
67,
63,
1635,
24,
12,
199,
7,
442,
975,
7,
420,
520,
257,
9428,
14,
67,
63,
442,
975,
12,
199,
7,
1635,
975,
7,
258,
520,
257,
9428,
14,
67,
63,
1635,
975,
12,
199,
7,
442,
708,
7,
420,
520,
257,
9428,
14,
67,
63,
442,
708,
12,
199,
7,
1635,
708,
7,
258,
520,
257,
9428,
14,
67,
63,
1635,
708,
12,
199,
7,
442,
772,
7,
420,
520,
257,
9428,
14,
67,
63,
442,
772,
12,
199,
7,
1635,
772,
7,
258,
520,
257,
9428,
14,
67,
63,
1635,
772,
12,
199,
199,
7,
1609,
7,
420,
520,
257,
9428,
14,
67,
63,
1609,
12,
199,
5121,
79,
2016,
7,
258,
520,
257,
9428,
14,
67,
63,
3157,
12,
199,
7,
2809,
3157,
7,
520,
257,
9428,
14,
67,
63,
2809,
3157,
12,
199,
93,
199,
199,
533,
445,
16752,
8,
785,
304,
272,
1449,
65,
22700,
1021,
367,
6425,
16360,
3423,
687,
491,
28631,
4621,
272,
1449,
272,
347,
636,
826,
721,
277,
12,
3413,
63,
269,
63,
3908,
304,
267,
340,
1228,
8,
1494,
63,
269,
63,
3908,
12,
5673,
304,
288,
291,
14,
3908,
275,
1026,
14,
8524,
6437,
14,
1222,
8,
1494,
63,
269,
63,
3908,
680,
2992,
8,
19,
680,
981,
342,
267,
587,
26,
288,
291,
14,
3908,
275,
3413,
63,
269,
63,
3908,
339,
347,
664,
63,
3667,
63,
1593,
8,
277,
12,
4325,
12,
627,
466,
815,
304,
267,
1449,
981,
282,
16360,
805,
687,
282,
491,
28631,
805,
398,
730,
815,
520,
1059,
402,
2943,
334,
3239,
658,
5443,
63,
1028,
24583,
10522,
503,
673,
769,
402,
5577,
16048,
14,
673,
7758,
574,
365,
314,
372,
730,
14,
673,
437,
805,
626,
6181,
949,
1423,
436,
372,
6548,
673,
1077,
675,
28531,
1647,
2,
64,
503,
658,
403,
2313,
267,
1449,
267,
340,
822,
8,
466,
815,
12694,
17,
436,
1228,
8,
466,
815,
59,
16,
467,
620,
304,
288,
2943,
275,
359,
603,
1282,
63,
1028,
24583,
59,
83,
14,
1913,
5106,
367,
308,
315,
730,
815,
59,
16,
1055,
1294,
11917,
1622,
288,
340,
440,
2943,
26,
355,
2203,
369,
275,
488,
355,
1680,
369,
83,
275,
942,
288,
587,
26,
355,
2203,
369,
275,
2943,
59,
16,
61,
355,
1680,
369,
83,
275,
2943,
59,
17,
2938,
267,
587,
26,
288,
2203,
369,
275,
730,
815,
59,
16,
61,
288,
1680,
369,
83,
275,
730,
815,
59,
17,
2938,
267,
19393,
275,
9428,
14,
5487,
10637,
8,
21958,
12,
627,
1273,
369,
83,
9,
267,
289,
1590,
454,
275,
291,
14,
3908,
14,
362,
63,
3929,
63,
475,
63,
1593,
8,
2324,
9,
267,
372,
19393,
8,
70,
1590,
454,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
2765,
365,
19762,
282,
16777,
859,
367,
5343,
543,
5577,
14,
199,
2344,
199,
199,
504,
18338,
2611,
14,
1018,
492,
2434,
12,
5673,
199,
646,
18338,
2611,
14,
1024,
465,
1026,
199,
646,
5577,
465,
9428,
199,
199,
5443,
63,
1028,
24583,
275,
469,
199,
7,
1647,
7,
755,
520,
257,
488,
12,
199,
7,
2245,
7,
755,
520,
257,
9428,
14,
67,
63,
2245,
12,
199,
7,
1560,
7,
755,
520,
257,
9428,
14,
67,
63,
1560,
12,
199,
7,
85,
1560,
7,
420,
520,
257,
9428,
14,
67,
63,
20790,
12,
199,
1159,
7222,
7,
420,
520,
257,
9428,
14,
67,
63,
3612,
12,
199,
7,
27170,
7,
258,
520,
257,
9428,
14,
67,
63,
27170,
12,
199,
7,
442,
7,
263,
520,
257,
9428,
14,
67,
63,
442,
12,
199,
7,
1635,
7,
755,
520,
257,
9428,
14,
67,
63,
1635,
12,
199,
7,
2809,
7,
755,
520,
257,
9428,
14,
67,
63,
2809,
12,
199,
7,
15688,
7,
420,
520,
257,
9428,
14,
67,
63,
15688,
12,
199,
199,
7,
442,
24,
7,
755,
520,
257,
9428,
14,
67,
63,
442,
24,
12,
199,
7,
1635,
24,
7,
420,
520,
257,
9428,
14,
67,
63,
1635,
24,
12,
199,
7,
442,
975,
7,
420,
520,
257,
9428,
14,
67,
63,
442,
975,
12,
199,
7,
1635,
975,
7,
258,
520,
257,
9428,
14,
67,
63,
1635,
975,
12,
199,
7,
442,
708,
7,
420,
520,
257,
9428,
14,
67,
63,
442,
708,
12,
199,
7,
1635,
708,
7,
258,
520,
257,
9428,
14,
67,
63,
1635,
708,
12,
199,
7,
442,
772,
7,
420,
520,
257,
9428,
14,
67,
63,
442,
772,
12,
199,
7,
1635,
772,
7,
258,
520,
257,
9428,
14,
67,
63,
1635,
772,
12,
199,
199,
7,
1609,
7,
420,
520,
257,
9428,
14,
67,
63,
1609,
12,
199,
5121,
79,
2016,
7,
258,
520,
257,
9428,
14,
67,
63,
3157,
12,
199,
7,
2809,
3157,
7,
520,
257,
9428,
14,
67,
63,
2809,
3157,
12,
199,
93,
199,
199,
533,
445,
16752,
8,
785,
304,
272,
1449,
65,
22700,
1021,
367,
6425,
16360,
3423,
687,
491,
28631,
4621,
272,
1449,
272,
347,
636,
826,
721,
277,
12,
3413,
63,
269,
63,
3908,
304,
267,
340,
1228,
8,
1494,
63,
269,
63,
3908,
12,
5673,
304,
288,
291,
14,
3908,
275,
1026,
14,
8524,
6437,
14,
1222,
8,
1494,
63,
269,
63,
3908,
680,
2992,
8,
19,
680,
981,
342,
267,
587,
26,
288,
291,
14,
3908,
275,
3413,
63,
269,
63,
3908,
339,
347,
664,
63,
3667,
63,
1593,
8,
277,
12,
4325,
12,
627,
466,
815,
304,
267,
1449,
981,
282,
16360,
805,
687,
282,
491,
28631,
805,
398,
730,
815,
520,
1059,
402,
2943,
334,
3239,
658,
5443,
63,
1028,
24583,
10522,
503,
673,
769,
402,
5577,
16048,
14,
673,
7758,
574,
365,
314,
372,
730,
14,
673,
437,
805,
626,
6181,
949,
1423,
436,
372,
6548,
673,
1077,
675,
28531,
1647,
2,
64,
503,
658,
403,
2313,
267,
1449,
267,
340,
822,
8,
466,
815,
12694,
17,
436,
1228,
8,
466,
815,
59,
16,
467,
620,
304,
288,
2943,
275,
359,
603,
1282,
63,
1028,
24583,
59,
83,
14,
1913,
5106,
367,
308,
315,
730,
815,
59,
16,
1055,
1294,
11917,
1622,
288,
340,
440,
2943,
26,
355,
2203,
369,
275,
488,
355,
1680,
369,
83,
275,
942,
288,
587,
26,
355,
2203,
369,
275,
2943,
59,
16,
61,
355,
1680,
369,
83,
275,
2943,
59,
17,
2938,
267,
587,
26,
288,
2203,
369,
275,
730,
815,
59,
16,
61,
288,
1680,
369,
83,
275,
730,
815,
59,
17,
2938,
267,
19393,
275,
9428,
14,
5487,
10637,
8,
21958,
12,
627,
1273,
369,
83,
9,
267,
289,
1590,
454,
275,
291,
14,
3908,
14,
362,
63,
3929,
63,
475,
63,
1593,
8,
2324,
9,
267,
372,
19393,
8,
70,
1590,
454,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bigswitch/horizon
|
openstack_dashboard/test/integration_tests/pages/admin/system/routerspage.py
|
9
|
1652
|
# 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 openstack_dashboard.test.integration_tests.pages.project.network \
import routerspage
from openstack_dashboard.test.integration_tests.regions import forms
from openstack_dashboard.test.integration_tests.regions import tables
class RoutersTable(routerspage.RoutersTable):
EDIT_ROUTER_FORM_FIELDS = ("name", "admin_state", "router_id")
@tables.bind_row_action('update')
def edit_router(self, edit_button, row):
edit_button.click()
return forms.FormRegion(self.driver, self.conf, None,
self.EDIT_ROUTER_FORM_FIELDS)
class RoutersPage(routerspage.RoutersPage):
@property
def routers_table(self):
return RoutersTable(self.driver, self.conf)
def edit_router(self, name, new_name, admin_state=None):
row = self._get_row_with_router_name(name)
edit_router_form = self.routers_table.edit_router(row)
edit_router_form.name.text = new_name
if admin_state is not None:
edit_router_form.admin_state.text = admin_state
edit_router_form.submit()
|
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,
13869,
63,
9743,
14,
396,
14,
15092,
63,
2219,
14,
5856,
14,
1715,
14,
1200,
971,
272,
492,
24464,
1606,
199,
504,
13869,
63,
9743,
14,
396,
14,
15092,
63,
2219,
14,
11963,
492,
4513,
199,
504,
13869,
63,
9743,
14,
396,
14,
15092,
63,
2219,
14,
11963,
492,
6716,
421,
199,
533,
19776,
878,
3186,
8,
17292,
1606,
14,
5407,
878,
3186,
304,
272,
24981,
63,
19281,
63,
3516,
63,
12767,
275,
1689,
354,
401,
298,
2113,
63,
929,
401,
298,
4995,
63,
344,
531,
339,
768,
5987,
14,
3409,
63,
1143,
63,
1287,
360,
873,
358,
272,
347,
5283,
63,
4995,
8,
277,
12,
5283,
63,
3887,
12,
1962,
304,
267,
5283,
63,
3887,
14,
4891,
342,
267,
372,
4513,
14,
2821,
10708,
8,
277,
14,
3090,
12,
291,
14,
2190,
12,
488,
12,
1816,
291,
14,
17929,
63,
19281,
63,
3516,
63,
12767,
9,
421,
199,
533,
19776,
878,
3276,
8,
17292,
1606,
14,
5407,
878,
3276,
304,
339,
768,
1829,
272,
347,
24464,
63,
1224,
8,
277,
304,
267,
372,
19776,
878,
3186,
8,
277,
14,
3090,
12,
291,
14,
2190,
9,
339,
347,
5283,
63,
4995,
8,
277,
12,
536,
12,
892,
63,
354,
12,
4628,
63,
929,
29,
403,
304,
267,
1962,
275,
291,
423,
362,
63,
1143,
63,
1045,
63,
4995,
63,
354,
8,
354,
9,
267,
5283,
63,
4995,
63,
964,
275,
291,
14,
17292,
63,
1224,
14,
3773,
63,
4995,
8,
1143,
9,
267,
5283,
63,
4995,
63,
964,
14,
354,
14,
505,
275,
892,
63,
354,
267,
340,
4628,
63,
929,
365,
440,
488,
26,
288,
5283,
63,
4995,
63,
964,
14,
2113,
63,
929,
14,
505,
275,
4628,
63,
929,
267,
5283,
63,
4995,
63,
964,
14,
7275,
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
] |
[
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,
13869,
63,
9743,
14,
396,
14,
15092,
63,
2219,
14,
5856,
14,
1715,
14,
1200,
971,
272,
492,
24464,
1606,
199,
504,
13869,
63,
9743,
14,
396,
14,
15092,
63,
2219,
14,
11963,
492,
4513,
199,
504,
13869,
63,
9743,
14,
396,
14,
15092,
63,
2219,
14,
11963,
492,
6716,
421,
199,
533,
19776,
878,
3186,
8,
17292,
1606,
14,
5407,
878,
3186,
304,
272,
24981,
63,
19281,
63,
3516,
63,
12767,
275,
1689,
354,
401,
298,
2113,
63,
929,
401,
298,
4995,
63,
344,
531,
339,
768,
5987,
14,
3409,
63,
1143,
63,
1287,
360,
873,
358,
272,
347,
5283,
63,
4995,
8,
277,
12,
5283,
63,
3887,
12,
1962,
304,
267,
5283,
63,
3887,
14,
4891,
342,
267,
372,
4513,
14,
2821,
10708,
8,
277,
14,
3090,
12,
291,
14,
2190,
12,
488,
12,
1816,
291,
14,
17929,
63,
19281,
63,
3516,
63,
12767,
9,
421,
199,
533,
19776,
878,
3276,
8,
17292,
1606,
14,
5407,
878,
3276,
304,
339,
768,
1829,
272,
347,
24464,
63,
1224,
8,
277,
304,
267,
372,
19776,
878,
3186,
8,
277,
14,
3090,
12,
291,
14,
2190,
9,
339,
347,
5283,
63,
4995,
8,
277,
12,
536,
12,
892,
63,
354,
12,
4628,
63,
929,
29,
403,
304,
267,
1962,
275,
291,
423,
362,
63,
1143,
63,
1045,
63,
4995,
63,
354,
8,
354,
9,
267,
5283,
63,
4995,
63,
964,
275,
291,
14,
17292,
63,
1224,
14,
3773,
63,
4995,
8,
1143,
9,
267,
5283,
63,
4995,
63,
964,
14,
354,
14,
505,
275,
892,
63,
354,
267,
340,
4628,
63,
929,
365,
440,
488,
26,
288,
5283,
63,
4995,
63,
964,
14,
2113,
63,
929,
14,
505,
275,
4628,
63,
929,
267,
5283,
63,
4995,
63,
964,
14,
7275,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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ccess.Entities.BiologicalMeasureType import BiologicalMeasureType
from Src.Core.Entity.EntityBase import EntityBase
class MicroRnaExpressionLevel(BiologicalMeasureType, EntityBase):
"""description of class"""
def __init__(self, **kargs):
"""
:param kargs:
"""
super().__init__(**kargs)
self.__symbol = kargs.get('symbol')
def __hash__(self):
return hash(self.__symbol)
def __eq__(self, other):
return isinstance(other, MicroRnaExpressionLevel) and \
self.__symbol == other.symbol
@property
def symbol(self) -> str:
"""description of property"""
return self.__symbol
@symbol.setter
def symbol(self, value: str):
"""
:param value:
:return:
"""
self.__symbol = value
def validate(self):
super().validate()
if not self.__symbol:
raise ValueError('symbol is required.')
def as_dict(self)-> Dict:
obj_dict = super().as_dict()
obj_dict.update({'symbol': self.__symbol})
return obj_dict
|
bsd-3-clause
|
[
504,
14090,
492,
7448,
199,
199,
504,
428,
1195,
14,
34,
2308,
1451,
14552,
14,
1451,
3946,
14,
24672,
14,
34,
2308,
7954,
18611,
804,
492,
699,
2308,
7954,
18611,
804,
199,
504,
428,
1195,
14,
5402,
14,
7302,
14,
7302,
1563,
492,
17680,
1563,
421,
199,
533,
27022,
50,
3540,
9093,
4670,
8,
34,
2308,
7954,
18611,
804,
12,
17680,
1563,
304,
272,
408,
1802,
402,
1021,
624,
339,
347,
636,
826,
721,
277,
12,
1011,
24459,
304,
267,
408,
398,
520,
635,
1022,
589,
26,
4960,
408,
267,
1613,
11027,
826,
14155,
24459,
9,
267,
291,
855,
5155,
275,
1022,
589,
14,
362,
360,
5155,
358,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
855,
5155,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
27022,
50,
3540,
9093,
4670,
9,
436,
971,
2049,
291,
855,
5155,
508,
1163,
14,
5155,
339,
768,
1829,
272,
347,
5272,
8,
277,
9,
1035,
620,
26,
267,
408,
1802,
402,
3324,
624,
267,
372,
291,
855,
5155,
339,
768,
5155,
14,
8345,
272,
347,
5272,
8,
277,
12,
574,
26,
620,
304,
267,
408,
398,
520,
635,
574,
26,
4960,
520,
1107,
26,
4960,
408,
267,
291,
855,
5155,
275,
574,
339,
347,
4107,
8,
277,
304,
267,
1613,
1252,
3502,
342,
398,
340,
440,
291,
855,
5155,
26,
288,
746,
1722,
360,
5155,
365,
1415,
2659,
339,
347,
465,
63,
807,
8,
277,
20844,
7448,
26,
267,
1559,
63,
807,
275,
1613,
1252,
305,
63,
807,
342,
267,
1559,
63,
807,
14,
873,
3252,
5155,
356,
291,
855,
5155,
1552,
267,
372,
1559,
63,
807,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
14090,
492,
7448,
199,
199,
504,
428,
1195,
14,
34,
2308,
1451,
14552,
14,
1451,
3946,
14,
24672,
14,
34,
2308,
7954,
18611,
804,
492,
699,
2308,
7954,
18611,
804,
199,
504,
428,
1195,
14,
5402,
14,
7302,
14,
7302,
1563,
492,
17680,
1563,
421,
199,
533,
27022,
50,
3540,
9093,
4670,
8,
34,
2308,
7954,
18611,
804,
12,
17680,
1563,
304,
272,
408,
1802,
402,
1021,
624,
339,
347,
636,
826,
721,
277,
12,
1011,
24459,
304,
267,
408,
398,
520,
635,
1022,
589,
26,
4960,
408,
267,
1613,
11027,
826,
14155,
24459,
9,
267,
291,
855,
5155,
275,
1022,
589,
14,
362,
360,
5155,
358,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
855,
5155,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
27022,
50,
3540,
9093,
4670,
9,
436,
971,
2049,
291,
855,
5155,
508,
1163,
14,
5155,
339,
768,
1829,
272,
347,
5272,
8,
277,
9,
1035,
620,
26,
267,
408,
1802,
402,
3324,
624,
267,
372,
291,
855,
5155,
339,
768,
5155,
14,
8345,
272,
347,
5272,
8,
277,
12,
574,
26,
620,
304,
267,
408,
398,
520,
635,
574,
26,
4960,
520,
1107,
26,
4960,
408,
267,
291,
855,
5155,
275,
574,
339,
347,
4107,
8,
277,
304,
267,
1613,
1252,
3502,
342,
398,
340,
440,
291,
855,
5155,
26,
288,
746,
1722,
360,
5155,
365,
1415,
2659,
339,
347,
465,
63,
807,
8,
277,
20844,
7448,
26,
267,
1559,
63,
807,
275,
1613,
1252,
305,
63,
807,
342,
267,
1559,
63,
807,
14,
873,
3252,
5155,
356,
291,
855,
5155,
1552,
267,
372,
1559,
63,
807,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
moves-rwth/storm
|
resources/3rdparty/googletest/googlemock/test/gmock_output_test.py
|
66
|
6154
|
#!/usr/bin/env python
#
# Copyright 2008, 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.
r"""Tests the text output of Google C++ Mocking Framework.
To update the golden file:
gmock_output_test.py --build_dir=BUILD/DIR --gengolden
where BUILD/DIR contains the built gmock_output_test_ file.
gmock_output_test.py --gengolden
gmock_output_test.py
"""
from io import open # pylint: disable=redefined-builtin, g-importing-member
import os
import re
import sys
import gmock_test_utils
# The flag for generating the golden file
GENGOLDEN_FLAG = '--gengolden'
PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_output_test_')
COMMAND = [PROGRAM_PATH, '--gtest_stack_trace_depth=0', '--gtest_print_time=0']
GOLDEN_NAME = 'gmock_output_test_golden.txt'
GOLDEN_PATH = os.path.join(gmock_test_utils.GetSourceDir(), GOLDEN_NAME)
def ToUnixLineEnding(s):
"""Changes all Windows/Mac line endings in s to UNIX line endings."""
return s.replace('\r\n', '\n').replace('\r', '\n')
def RemoveReportHeaderAndFooter(output):
"""Removes Google Test result report's header and footer from the output."""
output = re.sub(r'.*gtest_main.*\n', '', output)
output = re.sub(r'\[.*\d+ tests.*\n', '', output)
output = re.sub(r'\[.* test environment .*\n', '', output)
output = re.sub(r'\[=+\] \d+ tests .* ran.*', '', output)
output = re.sub(r'.* FAILED TESTS\n', '', output)
return output
def RemoveLocations(output):
"""Removes all file location info from a Google Test program's output.
Args:
output: the output of a Google Test program.
Returns:
output with all file location info (in the form of
'DIRECTORY/FILE_NAME:LINE_NUMBER: 'or
'DIRECTORY\\FILE_NAME(LINE_NUMBER): ') replaced by
'FILE:#: '.
"""
return re.sub(r'.*[/\\](.+)(\:\d+|\(\d+\))\:', 'FILE:#:', output)
def NormalizeErrorMarker(output):
"""Normalizes the error marker, which is different on Windows vs on Linux."""
return re.sub(r' error: ', ' Failure\n', output)
def RemoveMemoryAddresses(output):
"""Removes memory addresses from the test output."""
return re.sub(r'@\w+', '@0x#', output)
def RemoveTestNamesOfLeakedMocks(output):
"""Removes the test names of leaked mock objects from the test output."""
return re.sub(r'\(used in test .+\) ', '', output)
def GetLeakyTests(output):
"""Returns a list of test names that leak mock objects."""
# findall() returns a list of all matches of the regex in output.
# For example, if '(used in test FooTest.Bar)' is in output, the
# list will contain 'FooTest.Bar'.
return re.findall(r'\(used in test (.+)\)', output)
def GetNormalizedOutputAndLeakyTests(output):
"""Normalizes the output of gmock_output_test_.
Args:
output: The test output.
Returns:
A tuple (the normalized test output, the list of test names that have
leaked mocks).
"""
output = ToUnixLineEnding(output)
output = RemoveReportHeaderAndFooter(output)
output = NormalizeErrorMarker(output)
output = RemoveLocations(output)
output = RemoveMemoryAddresses(output)
return (RemoveTestNamesOfLeakedMocks(output), GetLeakyTests(output))
def GetShellCommandOutput(cmd):
"""Runs a command in a sub-process, and returns its STDOUT in a string."""
return gmock_test_utils.Subprocess(cmd, capture_stderr=False).output
def GetNormalizedCommandOutputAndLeakyTests(cmd):
"""Runs a command and returns its normalized output and a list of leaky tests.
Args:
cmd: the shell command.
"""
# Disables exception pop-ups on Windows.
os.environ['GTEST_CATCH_EXCEPTIONS'] = '1'
return GetNormalizedOutputAndLeakyTests(GetShellCommandOutput(cmd))
class GMockOutputTest(gmock_test_utils.TestCase):
def testOutput(self):
(output, leaky_tests) = GetNormalizedCommandOutputAndLeakyTests(COMMAND)
golden_file = open(GOLDEN_PATH, 'rb')
golden = golden_file.read().decode('utf-8')
golden_file.close()
# The normalized output should match the golden file.
self.assertEquals(golden, output)
# The raw output should contain 2 leaked mock object errors for
# test GMockOutputTest.CatchesLeakedMocks.
self.assertEquals(['GMockOutputTest.CatchesLeakedMocks',
'GMockOutputTest.CatchesLeakedMocks'],
leaky_tests)
if __name__ == '__main__':
if sys.argv[1:] == [GENGOLDEN_FLAG]:
(output, _) = GetNormalizedCommandOutputAndLeakyTests(COMMAND)
golden_file = open(GOLDEN_PATH, 'wb')
golden_file.write(output)
golden_file.close()
# Suppress the error "googletest was imported but a call to its main()
# was never detected."
os._exit(0)
else:
gmock_test_utils.Main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
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,
82,
624,
2925,
314,
1318,
1072,
402,
4475,
445,
4176,
4420,
316,
22545,
14,
199,
199,
1378,
1678,
314,
17631,
570,
26,
199,
71,
1805,
63,
1199,
63,
396,
14,
647,
1553,
1506,
63,
694,
29,
8248,
15,
3022,
1553,
2268,
19440,
199,
4509,
22974,
15,
3022,
3509,
314,
6137,
486,
1805,
63,
1199,
63,
396,
63,
570,
14,
199,
71,
1805,
63,
1199,
63,
396,
14,
647,
1553,
2268,
19440,
199,
71,
1805,
63,
1199,
63,
396,
14,
647,
199,
199,
624,
199,
199,
504,
5890,
492,
1551,
259,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
12,
486,
13,
646,
316,
13,
1114,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
486,
1805,
63,
396,
63,
1208,
421,
199,
3,
710,
3305,
367,
12999,
314,
17631,
570,
199,
9289,
39,
5104,
742,
63,
3719,
275,
2850,
2268,
19440,
7,
199,
199,
15605,
63,
3243,
275,
486,
1805,
63,
396,
63,
1208,
14,
28967,
27602,
360,
71,
1805,
63,
1199,
63,
396,
15452,
199,
10761,
275,
359,
15605,
63,
3243,
12,
2850,
8385,
63,
2340,
63,
3446,
63,
4631,
29,
16,
297,
2850,
8385,
63,
1361,
63,
521,
29,
16,
418,
199,
39,
5104,
742,
63,
2339,
275,
283,
71,
1805,
63,
1199,
63,
396,
63,
19440,
14,
2424,
7,
199,
39,
5104,
742,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
71,
1805,
63,
396,
63,
1208,
14,
1002,
2980,
3567,
1062,
598,
5104,
742,
63,
2339,
9,
421,
199,
318,
4005,
21607,
3049,
3005,
316,
8,
83,
304,
523,
408,
13907,
1006,
5417,
15,
3399,
1004,
1284,
780,
315,
308,
370,
22242,
1004,
1284,
780,
1041,
819,
372,
308,
14,
1814,
2258,
82,
60,
78,
297,
1557,
78,
1959,
1814,
2258,
82,
297,
1557,
78,
358,
421,
199,
318,
5852,
7457,
2567,
3325,
5686,
351,
8,
1199,
304,
523,
408,
22948,
4475,
1379,
754,
3622,
1159,
1406,
436,
14178,
687,
314,
1072,
1041,
819,
1072,
275,
295,
14,
954,
8,
82,
24898,
8385,
63,
973,
17910,
78,
297,
3260,
1072,
9,
523,
1072,
275,
295,
14,
954,
8,
82,
30181,
17910,
68,
11,
2295,
17910,
78,
297,
3260,
1072,
9,
523,
1072,
275,
295,
14,
954,
8,
82,
30181,
2795,
511,
3734,
1275,
7590,
78,
297,
3260,
1072,
9,
523,
1072,
275,
295,
14,
954,
8,
82,
30181,
29,
7896,
61,
971,
68,
11,
2295,
23076,
21471,
16110,
3260,
1072,
9,
523,
1072,
275,
295,
14,
954,
8,
82,
24898,
26892,
7393,
51,
60,
78,
297,
3260,
1072,
9,
523,
372,
1072,
421,
199,
318,
5852,
27727,
8,
1199,
304,
523,
408,
22948,
1006,
570,
2909,
2256,
687,
282,
4475,
1379,
2240,
1159,
1072,
14,
819,
3033,
26,
2126,
1072,
26,
221,
314,
1072,
402,
282,
4475,
1379,
2240,
14,
819,
1803,
26,
2126,
1072,
543,
1006,
570,
2909,
2256,
334,
262,
314,
1824,
402,
2126,
283,
16436,
15,
3817,
63,
2339,
26,
6174,
63,
9190,
26,
283,
269,
2126,
283,
16436,
1103,
3817,
63,
2339,
8,
6174,
63,
9190,
304,
5320,
8717,
701,
2126,
283,
3817,
26,
12573,
1987,
523,
408,
819,
372,
295,
14,
954,
8,
82,
1370,
23033,
15,
1103,
8738,
6977,
10127,
3427,
68,
11,
6113,
2961,
68,
7896,
25105,
6536,
283,
3817,
15596,
6536,
1072,
9,
421,
199,
318,
21017,
547,
12825,
8,
1199,
304,
523,
408,
6241,
6491,
314,
1125,
3608,
12,
1314,
365,
3365,
641,
5417,
8118,
641,
10130,
1041,
819,
372,
295,
14,
954,
8,
82,
7,
1125,
26,
1656,
283,
20367,
60,
78,
297,
1072,
9,
421,
199,
318,
5852,
8628,
20826,
8,
1199,
304,
523,
408,
22948,
4402,
7149,
687,
314,
511,
1072,
1041,
819,
372,
295,
14,
954,
8,
82,
20812,
60,
87,
7386,
10267,
16,
88,
23470,
1072,
9,
421,
199,
318,
5852,
774,
5866,
3466,
2553,
16702,
3346,
83,
8,
1199,
304,
523,
408,
22948,
314,
511,
1561,
402,
1026,
16702,
1683,
2251,
687,
314,
511,
1072,
1041,
819,
372,
295,
14,
954,
8,
82,
1154,
8,
2972,
315,
511,
1275,
7896,
9,
1656,
3260,
1072,
9,
421,
199,
318,
2372,
2553,
1151,
89,
2925,
8,
1199,
304,
523,
408,
3407,
282,
769,
402,
511,
1561,
626,
25831,
1683,
2251,
1041,
819
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
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,
82,
624,
2925,
314,
1318,
1072,
402,
4475,
445,
4176,
4420,
316,
22545,
14,
199,
199,
1378,
1678,
314,
17631,
570,
26,
199,
71,
1805,
63,
1199,
63,
396,
14,
647,
1553,
1506,
63,
694,
29,
8248,
15,
3022,
1553,
2268,
19440,
199,
4509,
22974,
15,
3022,
3509,
314,
6137,
486,
1805,
63,
1199,
63,
396,
63,
570,
14,
199,
71,
1805,
63,
1199,
63,
396,
14,
647,
1553,
2268,
19440,
199,
71,
1805,
63,
1199,
63,
396,
14,
647,
199,
199,
624,
199,
199,
504,
5890,
492,
1551,
259,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
12,
486,
13,
646,
316,
13,
1114,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
486,
1805,
63,
396,
63,
1208,
421,
199,
3,
710,
3305,
367,
12999,
314,
17631,
570,
199,
9289,
39,
5104,
742,
63,
3719,
275,
2850,
2268,
19440,
7,
199,
199,
15605,
63,
3243,
275,
486,
1805,
63,
396,
63,
1208,
14,
28967,
27602,
360,
71,
1805,
63,
1199,
63,
396,
15452,
199,
10761,
275,
359,
15605,
63,
3243,
12,
2850,
8385,
63,
2340,
63,
3446,
63,
4631,
29,
16,
297,
2850,
8385,
63,
1361,
63,
521,
29,
16,
418,
199,
39,
5104,
742,
63,
2339,
275,
283,
71,
1805,
63,
1199,
63,
396,
63,
19440,
14,
2424,
7,
199,
39,
5104,
742,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
71,
1805,
63,
396,
63,
1208,
14,
1002,
2980,
3567,
1062,
598,
5104,
742,
63,
2339,
9,
421,
199,
318,
4005,
21607,
3049,
3005,
316,
8,
83,
304,
523,
408,
13907,
1006,
5417,
15,
3399,
1004,
1284,
780,
315,
308,
370,
22242,
1004,
1284,
780,
1041,
819,
372,
308,
14,
1814,
2258,
82,
60,
78,
297,
1557,
78,
1959,
1814,
2258,
82,
297,
1557,
78,
358,
421,
199,
318,
5852,
7457,
2567,
3325,
5686,
351,
8,
1199,
304,
523,
408,
22948,
4475,
1379,
754,
3622,
1159,
1406,
436,
14178,
687,
314,
1072,
1041,
819,
1072,
275,
295,
14,
954,
8,
82,
24898,
8385,
63,
973,
17910,
78,
297,
3260,
1072,
9,
523,
1072,
275,
295,
14,
954,
8,
82,
30181,
17910,
68,
11,
2295,
17910,
78,
297,
3260,
1072,
9,
523,
1072,
275,
295,
14,
954,
8,
82,
30181,
2795,
511,
3734,
1275,
7590,
78,
297,
3260,
1072,
9,
523,
1072,
275,
295,
14,
954,
8,
82,
30181,
29,
7896,
61,
971,
68,
11,
2295,
23076,
21471,
16110,
3260,
1072,
9,
523,
1072,
275,
295,
14,
954,
8,
82,
24898,
26892,
7393,
51,
60,
78,
297,
3260,
1072,
9,
523,
372,
1072,
421,
199,
318,
5852,
27727,
8,
1199,
304,
523,
408,
22948,
1006,
570,
2909,
2256,
687,
282,
4475,
1379,
2240,
1159,
1072,
14,
819,
3033,
26,
2126,
1072,
26,
221,
314,
1072,
402,
282,
4475,
1379,
2240,
14,
819,
1803,
26,
2126,
1072,
543,
1006,
570,
2909,
2256,
334,
262,
314,
1824,
402,
2126,
283,
16436,
15,
3817,
63,
2339,
26,
6174,
63,
9190,
26,
283,
269,
2126,
283,
16436,
1103,
3817,
63,
2339,
8,
6174,
63,
9190,
304,
5320,
8717,
701,
2126,
283,
3817,
26,
12573,
1987,
523,
408,
819,
372,
295,
14,
954,
8,
82,
1370,
23033,
15,
1103,
8738,
6977,
10127,
3427,
68,
11,
6113,
2961,
68,
7896,
25105,
6536,
283,
3817,
15596,
6536,
1072,
9,
421,
199,
318,
21017,
547,
12825,
8,
1199,
304,
523,
408,
6241,
6491,
314,
1125,
3608,
12,
1314,
365,
3365,
641,
5417,
8118,
641,
10130,
1041,
819,
372,
295,
14,
954,
8,
82,
7,
1125,
26,
1656,
283,
20367,
60,
78,
297,
1072,
9,
421,
199,
318,
5852,
8628,
20826,
8,
1199,
304,
523,
408,
22948,
4402,
7149,
687,
314,
511,
1072,
1041,
819,
372,
295,
14,
954,
8,
82,
20812,
60,
87,
7386,
10267,
16,
88,
23470,
1072,
9,
421,
199,
318,
5852,
774,
5866,
3466,
2553,
16702,
3346,
83,
8,
1199,
304,
523,
408,
22948,
314,
511,
1561,
402,
1026,
16702,
1683,
2251,
687,
314,
511,
1072,
1041,
819,
372,
295,
14,
954,
8,
82,
1154,
8,
2972,
315,
511,
1275,
7896,
9,
1656,
3260,
1072,
9,
421,
199,
318,
2372,
2553,
1151,
89,
2925,
8,
1199,
304,
523,
408,
3407,
282,
769,
402,
511,
1561,
626,
25831,
1683,
2251,
1041,
819,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rtnews/rtsfnt
|
node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py
|
1789
|
10585
|
# Copyright (c) 2014 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Xcode-ninja wrapper project file generator.
This updates the data structures passed to the Xcode gyp generator to build
with ninja instead. The Xcode project itself is transformed into a list of
executable targets, each with a build step to build with ninja, and a target
with every source and resource file. This appears to sidestep some of the
major performance headaches experienced using complex projects and large number
of targets within Xcode.
"""
import errno
import gyp.generator.ninja
import os
import re
import xml.sax.saxutils
def _WriteWorkspace(main_gyp, sources_gyp, params):
""" Create a workspace to wrap main and sources gyp paths. """
(build_file_root, build_file_ext) = os.path.splitext(main_gyp)
workspace_path = build_file_root + '.xcworkspace'
options = params['options']
if options.generator_output:
workspace_path = os.path.join(options.generator_output, workspace_path)
try:
os.makedirs(workspace_path)
except OSError, e:
if e.errno != errno.EEXIST:
raise
output_string = '<?xml version="1.0" encoding="UTF-8"?>\n' + \
'<Workspace version = "1.0">\n'
for gyp_name in [main_gyp, sources_gyp]:
name = os.path.splitext(os.path.basename(gyp_name))[0] + '.xcodeproj'
name = xml.sax.saxutils.quoteattr("group:" + name)
output_string += ' <FileRef location = %s></FileRef>\n' % name
output_string += '</Workspace>\n'
workspace_file = os.path.join(workspace_path, "contents.xcworkspacedata")
try:
with open(workspace_file, 'r') as input_file:
input_string = input_file.read()
if input_string == output_string:
return
except IOError:
# Ignore errors if the file doesn't exist.
pass
with open(workspace_file, 'w') as output_file:
output_file.write(output_string)
def _TargetFromSpec(old_spec, params):
""" Create fake target for xcode-ninja wrapper. """
# Determine ninja top level build dir (e.g. /path/to/out).
ninja_toplevel = None
jobs = 0
if params:
options = params['options']
ninja_toplevel = \
os.path.join(options.toplevel_dir,
gyp.generator.ninja.ComputeOutputDir(params))
jobs = params.get('generator_flags', {}).get('xcode_ninja_jobs', 0)
target_name = old_spec.get('target_name')
product_name = old_spec.get('product_name', target_name)
product_extension = old_spec.get('product_extension')
ninja_target = {}
ninja_target['target_name'] = target_name
ninja_target['product_name'] = product_name
if product_extension:
ninja_target['product_extension'] = product_extension
ninja_target['toolset'] = old_spec.get('toolset')
ninja_target['default_configuration'] = old_spec.get('default_configuration')
ninja_target['configurations'] = {}
# Tell Xcode to look in |ninja_toplevel| for build products.
new_xcode_settings = {}
if ninja_toplevel:
new_xcode_settings['CONFIGURATION_BUILD_DIR'] = \
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" % ninja_toplevel
if 'configurations' in old_spec:
for config in old_spec['configurations'].iterkeys():
old_xcode_settings = \
old_spec['configurations'][config].get('xcode_settings', {})
if 'IPHONEOS_DEPLOYMENT_TARGET' in old_xcode_settings:
new_xcode_settings['CODE_SIGNING_REQUIRED'] = "NO"
new_xcode_settings['IPHONEOS_DEPLOYMENT_TARGET'] = \
old_xcode_settings['IPHONEOS_DEPLOYMENT_TARGET']
ninja_target['configurations'][config] = {}
ninja_target['configurations'][config]['xcode_settings'] = \
new_xcode_settings
ninja_target['mac_bundle'] = old_spec.get('mac_bundle', 0)
ninja_target['ios_app_extension'] = old_spec.get('ios_app_extension', 0)
ninja_target['ios_watchkit_extension'] = \
old_spec.get('ios_watchkit_extension', 0)
ninja_target['ios_watchkit_app'] = old_spec.get('ios_watchkit_app', 0)
ninja_target['type'] = old_spec['type']
if ninja_toplevel:
ninja_target['actions'] = [
{
'action_name': 'Compile and copy %s via ninja' % target_name,
'inputs': [],
'outputs': [],
'action': [
'env',
'PATH=%s' % os.environ['PATH'],
'ninja',
'-C',
new_xcode_settings['CONFIGURATION_BUILD_DIR'],
target_name,
],
'message': 'Compile and copy %s via ninja' % target_name,
},
]
if jobs > 0:
ninja_target['actions'][0]['action'].extend(('-j', jobs))
return ninja_target
def IsValidTargetForWrapper(target_extras, executable_target_pattern, spec):
"""Limit targets for Xcode wrapper.
Xcode sometimes performs poorly with too many targets, so only include
proper executable targets, with filters to customize.
Arguments:
target_extras: Regular expression to always add, matching any target.
executable_target_pattern: Regular expression limiting executable targets.
spec: Specifications for target.
"""
target_name = spec.get('target_name')
# Always include targets matching target_extras.
if target_extras is not None and re.search(target_extras, target_name):
return True
# Otherwise just show executable targets.
if spec.get('type', '') == 'executable' and \
spec.get('product_extension', '') != 'bundle':
# If there is a filter and the target does not match, exclude the target.
if executable_target_pattern is not None:
if not re.search(executable_target_pattern, target_name):
return False
return True
return False
def CreateWrapper(target_list, target_dicts, data, params):
"""Initialize targets for the ninja wrapper.
This sets up the necessary variables in the targets to generate Xcode projects
that use ninja as an external builder.
Arguments:
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
data: Dict of flattened build files keyed on gyp path.
params: Dict of global options for gyp.
"""
orig_gyp = params['build_files'][0]
for gyp_name, gyp_dict in data.iteritems():
if gyp_name == orig_gyp:
depth = gyp_dict['_DEPTH']
# Check for custom main gyp name, otherwise use the default CHROMIUM_GYP_FILE
# and prepend .ninja before the .gyp extension.
generator_flags = params.get('generator_flags', {})
main_gyp = generator_flags.get('xcode_ninja_main_gyp', None)
if main_gyp is None:
(build_file_root, build_file_ext) = os.path.splitext(orig_gyp)
main_gyp = build_file_root + ".ninja" + build_file_ext
# Create new |target_list|, |target_dicts| and |data| data structures.
new_target_list = []
new_target_dicts = {}
new_data = {}
# Set base keys needed for |data|.
new_data[main_gyp] = {}
new_data[main_gyp]['included_files'] = []
new_data[main_gyp]['targets'] = []
new_data[main_gyp]['xcode_settings'] = \
data[orig_gyp].get('xcode_settings', {})
# Normally the xcode-ninja generator includes only valid executable targets.
# If |xcode_ninja_executable_target_pattern| is set, that list is reduced to
# executable targets that match the pattern. (Default all)
executable_target_pattern = \
generator_flags.get('xcode_ninja_executable_target_pattern', None)
# For including other non-executable targets, add the matching target name
# to the |xcode_ninja_target_pattern| regular expression. (Default none)
target_extras = generator_flags.get('xcode_ninja_target_pattern', None)
for old_qualified_target in target_list:
spec = target_dicts[old_qualified_target]
if IsValidTargetForWrapper(target_extras, executable_target_pattern, spec):
# Add to new_target_list.
target_name = spec.get('target_name')
new_target_name = '%s:%s#target' % (main_gyp, target_name)
new_target_list.append(new_target_name)
# Add to new_target_dicts.
new_target_dicts[new_target_name] = _TargetFromSpec(spec, params)
# Add to new_data.
for old_target in data[old_qualified_target.split(':')[0]]['targets']:
if old_target['target_name'] == target_name:
new_data_target = {}
new_data_target['target_name'] = old_target['target_name']
new_data_target['toolset'] = old_target['toolset']
new_data[main_gyp]['targets'].append(new_data_target)
# Create sources target.
sources_target_name = 'sources_for_indexing'
sources_target = _TargetFromSpec(
{ 'target_name' : sources_target_name,
'toolset': 'target',
'default_configuration': 'Default',
'mac_bundle': '0',
'type': 'executable'
}, None)
# Tell Xcode to look everywhere for headers.
sources_target['configurations'] = {'Default': { 'include_dirs': [ depth ] } }
sources = []
for target, target_dict in target_dicts.iteritems():
base = os.path.dirname(target)
files = target_dict.get('sources', []) + \
target_dict.get('mac_bundle_resources', [])
for action in target_dict.get('actions', []):
files.extend(action.get('inputs', []))
# Remove files starting with $. These are mostly intermediate files for the
# build system.
files = [ file for file in files if not file.startswith('$')]
# Make sources relative to root build file.
relative_path = os.path.dirname(main_gyp)
sources += [ os.path.relpath(os.path.join(base, file), relative_path)
for file in files ]
sources_target['sources'] = sorted(set(sources))
# Put sources_to_index in it's own gyp.
sources_gyp = \
os.path.join(os.path.dirname(main_gyp), sources_target_name + ".gyp")
fully_qualified_target_name = \
'%s:%s#target' % (sources_gyp, sources_target_name)
# Add to new_target_list, new_target_dicts and new_data.
new_target_list.append(fully_qualified_target_name)
new_target_dicts[fully_qualified_target_name] = sources_target
new_data_target = {}
new_data_target['target_name'] = sources_target['target_name']
new_data_target['_DEPTH'] = depth
new_data_target['toolset'] = "target"
new_data[sources_gyp] = {}
new_data[sources_gyp]['targets'] = []
new_data[sources_gyp]['included_files'] = []
new_data[sources_gyp]['xcode_settings'] = \
data[orig_gyp].get('xcode_settings', {})
new_data[sources_gyp]['targets'].append(new_data_target)
# Write workspace to file.
_WriteWorkspace(main_gyp, sources_gyp, params)
return (new_target_list, new_target_dicts, new_data)
|
mit
|
[
3,
1898,
334,
67,
9,
6927,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
18442,
13,
8675,
4975,
2199,
570,
4306,
14,
199,
199,
2765,
7029,
314,
666,
13955,
3032,
370,
314,
10602,
4902,
4306,
370,
1900,
199,
1045,
14822,
3140,
14,
710,
10602,
2199,
6337,
365,
14834,
1901,
282,
769,
402,
199,
5904,
4545,
12,
1924,
543,
282,
1900,
3650,
370,
1900,
543,
14822,
12,
436,
282,
1347,
199,
1045,
4036,
1350,
436,
2073,
570,
14,
221,
961,
11337,
370,
5366,
2926,
2005,
402,
314,
199,
8452,
10238,
4854,
1225,
397,
444,
24242,
68,
1808,
6114,
11336,
436,
7031,
1329,
199,
1618,
4545,
4453,
10602,
14,
199,
624,
199,
199,
646,
7554,
199,
646,
4902,
14,
4679,
14,
8675,
199,
646,
747,
199,
646,
295,
199,
646,
2748,
14,
14338,
14,
14338,
1208,
421,
199,
318,
485,
3534,
21058,
8,
973,
63,
6179,
12,
5274,
63,
6179,
12,
1862,
304,
523,
408,
2790,
282,
14466,
370,
4816,
2446,
436,
5274,
4902,
3792,
14,
408,
523,
334,
1506,
63,
493,
63,
1231,
12,
1900,
63,
493,
63,
832,
9,
275,
747,
14,
515,
14,
7973,
8,
973,
63,
6179,
9,
523,
14466,
63,
515,
275,
1900,
63,
493,
63,
1231,
435,
1987,
1812,
13249,
7,
523,
1511,
275,
1862,
459,
1419,
418,
523,
340,
1511,
14,
4679,
63,
1199,
26,
272,
14466,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1419,
14,
4679,
63,
1199,
12,
14466,
63,
515,
9,
523,
862,
26,
272,
747,
14,
8347,
8,
13249,
63,
515,
9,
523,
871,
6440,
12,
325,
26,
272,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
489,
746,
523,
1072,
63,
875,
275,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
14863,
3072,
78,
7,
435,
971,
2116,
2650,
21058,
1015,
275,
298,
17,
14,
16,
14559,
78,
7,
523,
367,
4902,
63,
354,
315,
359,
973,
63,
6179,
12,
5274,
63,
6179,
2189,
272,
536,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
6179,
63,
354,
11515,
16,
61,
435,
1987,
29286,
7,
272,
536,
275,
2748,
14,
14338,
14,
14338,
1208,
14,
3513,
962,
480,
923,
5424,
435,
536,
9,
272,
1072,
63,
875,
847,
283,
221,
665,
1173,
2891,
2909,
275,
450,
83,
2957,
1173,
2891,
3072,
78,
7,
450,
536,
523,
1072,
63,
875,
847,
11936,
21058,
3072,
78,
7,
819,
14466,
63,
493,
275,
747,
14,
515,
14,
904,
8,
13249,
63,
515,
12,
298,
4407,
14,
1812,
13249,
576,
531,
819,
862,
26,
272,
543,
1551,
8,
13249,
63,
493,
12,
283,
82,
358,
465,
1324,
63,
493,
26,
489,
1324,
63,
875,
275,
1324,
63,
493,
14,
739,
342,
489,
340,
1324,
63,
875,
508,
1072,
63,
875,
26,
267,
372,
523,
871,
5925,
26,
272,
327,
14092,
2552,
340,
314,
570,
3181,
1133,
2187,
14,
272,
986,
819,
543,
1551,
8,
13249,
63,
493,
12,
283,
87,
358,
465,
1072,
63,
493,
26,
272,
1072,
63,
493,
14,
952,
8,
1199,
63,
875,
9,
199,
199,
318,
485,
4277,
2532,
5307,
8,
1753,
63,
1650,
12,
1862,
304,
523,
408,
2790,
4026,
1347,
367,
13592,
13,
8675,
4975,
14,
408,
523,
327,
14703,
14822,
2746,
2166,
1900,
2935,
334,
69,
14,
71,
14,
1182,
515,
15,
475,
15,
548,
680,
523,
14822,
63,
13517,
275,
488,
523,
9643,
275,
378,
523,
340,
1862,
26,
272,
1511,
275,
1862,
459,
1419,
418,
272,
14822,
63,
13517,
275,
971,
267,
747,
14,
515,
14,
904,
8,
1419,
14,
13517,
63,
694,
12,
2151,
4902,
14,
4679,
14,
8675,
14,
8564,
2959,
3567,
8,
1162,
430,
272,
9643,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
13056,
362,
360,
8701,
63,
8675,
63,
6920,
297,
378,
9,
819,
1347,
63,
354,
275,
2269,
63,
1650,
14,
362,
360,
1375,
63,
354,
358,
523,
3336,
63,
354,
275,
2269,
63,
1650,
14,
362,
360,
2558,
63,
354,
297,
1347,
63,
354,
9,
523,
3336,
63,
3435,
275,
2269,
63,
1650,
14,
362,
360,
2558,
63,
3435,
358,
819,
14822,
63,
1375,
275,
1052,
523,
14822,
63,
1375,
459,
1375,
63,
354,
418,
275,
1347,
63,
354,
523,
14822,
63,
1375,
459,
2558,
63,
354,
418,
275,
3336,
63,
354,
523,
340,
3336,
63,
3435,
26,
272,
14822,
63,
1375,
459,
2558,
63,
3435,
418,
275,
3336,
63,
3435,
523,
14822,
63,
1375,
459,
12081,
418,
275,
2269,
63,
1650,
14,
362,
360,
12081,
358,
523,
14822,
63,
1375,
459,
885,
63,
4758,
418,
275,
2269,
63,
1650,
14,
362,
360,
885,
63,
4758,
358,
523,
14822,
63,
1375,
459,
10057,
418,
275,
1052,
819,
327,
30528,
10602,
370,
3648,
315,
1204,
8675,
63,
13517,
92,
367,
1900,
7585,
14,
523,
892,
63,
8701,
63,
1751,
275,
1052,
523,
340,
14822,
63,
13517,
26,
272,
892,
63,
8701,
63,
1751,
459,
22212,
63,
8248,
63,
3022,
418,
275,
971,
267,
2071,
83,
15,
6629,
22212,
9,
6629,
29512,
3582,
5399,
63,
17805,
63,
2339,
2924,
450,
14822,
63,
13517,
819,
340,
283,
10057,
7,
315,
2269,
63,
1650,
26,
272,
367,
1101,
315,
2269,
63,
1650,
459,
10057,
2278,
16007,
837,
489,
2269,
63,
8701,
63,
1751,
275,
971,
267,
2269,
63,
1650,
459,
10057,
3488,
888,
1055,
362,
360,
8701,
63,
1751,
297,
5009,
489,
340,
283,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
7,
315,
2269,
63,
8701,
63,
1751,
26,
267,
892,
63,
8701,
63,
1751,
459,
6012,
63,
9396,
1206,
63,
12496,
418,
275,
298,
2826,
2,
267,
892,
63,
8701,
63,
1751,
459,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
418,
275,
971,
288,
2269,
63,
8701,
63,
1751,
459,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
418,
489,
14822,
63,
1375,
459,
10057,
3488,
888,
61,
275,
1052,
489,
14822,
63,
1375,
459,
10057,
3488,
888,
2733,
8701,
63,
1751,
418,
275,
971,
881,
892,
63,
8701,
63,
1751,
819,
14822,
63,
1375,
459,
3088,
63,
6469,
418,
275
] |
[
1898,
334,
67,
9,
6927,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
18442,
13,
8675,
4975,
2199,
570,
4306,
14,
199,
199,
2765,
7029,
314,
666,
13955,
3032,
370,
314,
10602,
4902,
4306,
370,
1900,
199,
1045,
14822,
3140,
14,
710,
10602,
2199,
6337,
365,
14834,
1901,
282,
769,
402,
199,
5904,
4545,
12,
1924,
543,
282,
1900,
3650,
370,
1900,
543,
14822,
12,
436,
282,
1347,
199,
1045,
4036,
1350,
436,
2073,
570,
14,
221,
961,
11337,
370,
5366,
2926,
2005,
402,
314,
199,
8452,
10238,
4854,
1225,
397,
444,
24242,
68,
1808,
6114,
11336,
436,
7031,
1329,
199,
1618,
4545,
4453,
10602,
14,
199,
624,
199,
199,
646,
7554,
199,
646,
4902,
14,
4679,
14,
8675,
199,
646,
747,
199,
646,
295,
199,
646,
2748,
14,
14338,
14,
14338,
1208,
421,
199,
318,
485,
3534,
21058,
8,
973,
63,
6179,
12,
5274,
63,
6179,
12,
1862,
304,
523,
408,
2790,
282,
14466,
370,
4816,
2446,
436,
5274,
4902,
3792,
14,
408,
523,
334,
1506,
63,
493,
63,
1231,
12,
1900,
63,
493,
63,
832,
9,
275,
747,
14,
515,
14,
7973,
8,
973,
63,
6179,
9,
523,
14466,
63,
515,
275,
1900,
63,
493,
63,
1231,
435,
1987,
1812,
13249,
7,
523,
1511,
275,
1862,
459,
1419,
418,
523,
340,
1511,
14,
4679,
63,
1199,
26,
272,
14466,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1419,
14,
4679,
63,
1199,
12,
14466,
63,
515,
9,
523,
862,
26,
272,
747,
14,
8347,
8,
13249,
63,
515,
9,
523,
871,
6440,
12,
325,
26,
272,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
489,
746,
523,
1072,
63,
875,
275,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
14863,
3072,
78,
7,
435,
971,
2116,
2650,
21058,
1015,
275,
298,
17,
14,
16,
14559,
78,
7,
523,
367,
4902,
63,
354,
315,
359,
973,
63,
6179,
12,
5274,
63,
6179,
2189,
272,
536,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
6179,
63,
354,
11515,
16,
61,
435,
1987,
29286,
7,
272,
536,
275,
2748,
14,
14338,
14,
14338,
1208,
14,
3513,
962,
480,
923,
5424,
435,
536,
9,
272,
1072,
63,
875,
847,
283,
221,
665,
1173,
2891,
2909,
275,
450,
83,
2957,
1173,
2891,
3072,
78,
7,
450,
536,
523,
1072,
63,
875,
847,
11936,
21058,
3072,
78,
7,
819,
14466,
63,
493,
275,
747,
14,
515,
14,
904,
8,
13249,
63,
515,
12,
298,
4407,
14,
1812,
13249,
576,
531,
819,
862,
26,
272,
543,
1551,
8,
13249,
63,
493,
12,
283,
82,
358,
465,
1324,
63,
493,
26,
489,
1324,
63,
875,
275,
1324,
63,
493,
14,
739,
342,
489,
340,
1324,
63,
875,
508,
1072,
63,
875,
26,
267,
372,
523,
871,
5925,
26,
272,
327,
14092,
2552,
340,
314,
570,
3181,
1133,
2187,
14,
272,
986,
819,
543,
1551,
8,
13249,
63,
493,
12,
283,
87,
358,
465,
1072,
63,
493,
26,
272,
1072,
63,
493,
14,
952,
8,
1199,
63,
875,
9,
199,
199,
318,
485,
4277,
2532,
5307,
8,
1753,
63,
1650,
12,
1862,
304,
523,
408,
2790,
4026,
1347,
367,
13592,
13,
8675,
4975,
14,
408,
523,
327,
14703,
14822,
2746,
2166,
1900,
2935,
334,
69,
14,
71,
14,
1182,
515,
15,
475,
15,
548,
680,
523,
14822,
63,
13517,
275,
488,
523,
9643,
275,
378,
523,
340,
1862,
26,
272,
1511,
275,
1862,
459,
1419,
418,
272,
14822,
63,
13517,
275,
971,
267,
747,
14,
515,
14,
904,
8,
1419,
14,
13517,
63,
694,
12,
2151,
4902,
14,
4679,
14,
8675,
14,
8564,
2959,
3567,
8,
1162,
430,
272,
9643,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
13056,
362,
360,
8701,
63,
8675,
63,
6920,
297,
378,
9,
819,
1347,
63,
354,
275,
2269,
63,
1650,
14,
362,
360,
1375,
63,
354,
358,
523,
3336,
63,
354,
275,
2269,
63,
1650,
14,
362,
360,
2558,
63,
354,
297,
1347,
63,
354,
9,
523,
3336,
63,
3435,
275,
2269,
63,
1650,
14,
362,
360,
2558,
63,
3435,
358,
819,
14822,
63,
1375,
275,
1052,
523,
14822,
63,
1375,
459,
1375,
63,
354,
418,
275,
1347,
63,
354,
523,
14822,
63,
1375,
459,
2558,
63,
354,
418,
275,
3336,
63,
354,
523,
340,
3336,
63,
3435,
26,
272,
14822,
63,
1375,
459,
2558,
63,
3435,
418,
275,
3336,
63,
3435,
523,
14822,
63,
1375,
459,
12081,
418,
275,
2269,
63,
1650,
14,
362,
360,
12081,
358,
523,
14822,
63,
1375,
459,
885,
63,
4758,
418,
275,
2269,
63,
1650,
14,
362,
360,
885,
63,
4758,
358,
523,
14822,
63,
1375,
459,
10057,
418,
275,
1052,
819,
327,
30528,
10602,
370,
3648,
315,
1204,
8675,
63,
13517,
92,
367,
1900,
7585,
14,
523,
892,
63,
8701,
63,
1751,
275,
1052,
523,
340,
14822,
63,
13517,
26,
272,
892,
63,
8701,
63,
1751,
459,
22212,
63,
8248,
63,
3022,
418,
275,
971,
267,
2071,
83,
15,
6629,
22212,
9,
6629,
29512,
3582,
5399,
63,
17805,
63,
2339,
2924,
450,
14822,
63,
13517,
819,
340,
283,
10057,
7,
315,
2269,
63,
1650,
26,
272,
367,
1101,
315,
2269,
63,
1650,
459,
10057,
2278,
16007,
837,
489,
2269,
63,
8701,
63,
1751,
275,
971,
267,
2269,
63,
1650,
459,
10057,
3488,
888,
1055,
362,
360,
8701,
63,
1751,
297,
5009,
489,
340,
283,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
7,
315,
2269,
63,
8701,
63,
1751,
26,
267,
892,
63,
8701,
63,
1751,
459,
6012,
63,
9396,
1206,
63,
12496,
418,
275,
298,
2826,
2,
267,
892,
63,
8701,
63,
1751,
459,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
418,
275,
971,
288,
2269,
63,
8701,
63,
1751,
459,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
418,
489,
14822,
63,
1375,
459,
10057,
3488,
888,
61,
275,
1052,
489,
14822,
63,
1375,
459,
10057,
3488,
888,
2733,
8701,
63,
1751,
418,
275,
971,
881,
892,
63,
8701,
63,
1751,
819,
14822,
63,
1375,
459,
3088,
63,
6469,
418,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
Adward-R/InfoVis
|
Wang/xlsx2json.py
|
1
|
3582
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import sys
import xlrd
import xlwt
def parse_sheet(sheet, filename, root):
'''Parse the sheet and tranfer it to a json file'''
output = file(filename, 'w')
header = []
data = []
for col in range(sheet.ncols):
header.append(sheet.cell_value(0, col))
for row in range(1, sheet.nrows):
line = []
for col in range(sheet.ncols):
cell = sheet.cell(row, col)
pair = (header[col], cell)
line.append(pair)
data.append(line)
cnt = 0
output.write('{ "' + root + '" : [\n')
pattern = re.compile(r'Date')
for line in data[:-1]:
output.write('\t{\n')
for it in range(len(line)):
name = line[it][0]
value = line[it][1]
output.write('\t\t"' + name + '" : ')
if value is xlrd.empty_cell or value.value == '':
output.write('"",\n')
elif pattern.search(name) is not None:
date = xlrd.xldate_as_tuple(value.value, sheet.book.datemode)
output.write('"' + str(date[0]) + '-' + str(date[1]) + '-' + str(date[2]) + '",\n')
elif isinstance(value.value, unicode):
output.write('"' + value.value + '",\n')
else:
output.write('"' + str(value.value) + '",\n')
else:
number = cnt
cnt = cnt + 1
output.write('\t\t"Number" : "' + str(number) + '"\n')
output.write('\t},\n')
'''
name = line[-1][0]
value = line[-1][1]
output.write('\t\t"' + name + '" : ')
if value is xlrd.empty_cell or value.value == '':
output.write('""\n')
elif pattern.search(name) is not None:
date = xlrd.xldate_as_tuple(value.value, sheet.book.datemode)
output.write('"' + str(date[0]) + '-' + str(date[1]) + '-' + str(date[2]) + '"\n')
elif isinstance(value.value, unicode):
output.write('"' + value.value + '"\n')
else:
output.write('"' + str(value.value) + '"\n')
output.write('\t},\n')
'''
else:
output.write('\t{\n')
for it in range(len(line)):
name = line[it][0]
value = line[it][1]
output.write('\t\t"' + name + '" : ')
if value is xlrd.empty_cell or value.value == '':
output.write('"",\n')
elif pattern.search(name) is not None:
date = xlrd.xldate_as_tuple(value.value, sheet.book.datemode)
output.write('"' + str(date[0]) + '-' + str(date[1]) + '-' + str(date[2]) + '",\n')
elif isinstance(value.value, unicode):
output.write('"' + value.value + '",\n')
else:
output.write('"' + str(value.value) + '",\n')
else:
number = cnt
cnt = cnt + 1
output.write('\t\t"Number" : "' + str(number) + '"\n')
output.write('\t}\n')
'''
name = line[-1][0]
value = line[-1][1]
output.write('\t\t"' + name + '" : ')
if value is xlrd.empty_cell or value.value == '':
output.write('""\n')
elif pattern.search(name) is not None:
date = xlrd.xldate_as_tuple(value.value, sheet.book.datemode)
output.write('"' + str(date[0]) + '-' + str(date[1]) + '-' + str(date[2]) + '"\n')
elif isinstance(value.value, unicode):
output.write('"' + value.value + '"\n')
else:
output.write('"' + str(value.value) + '"\n')
'''
output.write(']}\n')
output.close()
filename = sys.argv[1]
workbook = xlrd.open_workbook(filename)
workbook.sheet_names()
# Parse the first sheet 'Employee Records'
sheet = workbook.sheet_by_index(0)
outputname = workbook.sheet_names()[0]
outputname += '.json'
parse_sheet(sheet, outputname, 'nodes')
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
295,
199,
646,
984,
199,
646,
25077,
6883,
199,
646,
25077,
9115,
199,
199,
318,
2198,
63,
5069,
8,
5069,
12,
1788,
12,
1738,
304,
523,
1449,
4003,
314,
12083,
436,
7115,
2412,
652,
370,
282,
2022,
570,
2344,
819,
1072,
275,
570,
8,
1501,
12,
283,
87,
358,
523,
1406,
275,
942,
523,
666,
275,
942,
523,
367,
1048,
315,
1425,
8,
5069,
14,
78,
4574,
304,
272,
1406,
14,
740,
8,
5069,
14,
3890,
63,
585,
8,
16,
12,
1048,
430,
523,
367,
1962,
315,
1425,
8,
17,
12,
12083,
14,
24590,
304,
272,
1004,
275,
942,
272,
367,
1048,
315,
1425,
8,
5069,
14,
78,
4574,
304,
489,
4917,
275,
12083,
14,
3890,
8,
1143,
12,
1048,
9,
489,
4092,
275,
334,
1291,
59,
761,
467,
4917,
9,
489,
1004,
14,
740,
8,
3852,
9,
272,
666,
14,
740,
8,
604,
9,
819,
12703,
275,
378,
523,
1072,
14,
952,
11117,
3546,
435,
1738,
435,
5522,
520,
359,
60,
78,
358,
523,
3851,
275,
295,
14,
2014,
8,
82,
7,
2506,
358,
523,
367,
1004,
315,
666,
4439,
17,
2189,
272,
1072,
14,
952,
2258,
84,
12911,
78,
358,
272,
367,
652,
315,
1425,
8,
552,
8,
604,
2298,
489,
536,
275,
1004,
59,
390,
1527,
16,
61,
489,
574,
275,
1004,
59,
390,
1527,
17,
61,
489,
1072,
14,
952,
2258,
84,
60,
84,
4507,
435,
536,
435,
5522,
520,
5320,
489,
340,
574,
365,
25077,
6883,
14,
1667,
63,
3890,
503,
574,
14,
585,
508,
8061,
267,
1072,
14,
952,
360,
341,
4202,
78,
358,
489,
916,
3851,
14,
1733,
8,
354,
9,
365,
440,
488,
26,
267,
1434,
275,
25077,
6883,
14,
15455,
602,
63,
305,
63,
2960,
8,
585,
14,
585,
12,
12083,
14,
2706,
14,
602,
632,
9,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
602,
59,
16,
566,
435,
10791,
435,
620,
8,
602,
59,
17,
566,
435,
10791,
435,
620,
8,
602,
59,
18,
566,
435,
283,
22260,
78,
358,
489,
916,
1228,
8,
585,
14,
585,
12,
2649,
304,
267,
1072,
14,
952,
360,
4507,
435,
574,
14,
585,
435,
283,
22260,
78,
358,
489,
587,
26,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
585,
14,
585,
9,
435,
283,
22260,
78,
358,
272,
587,
26,
489,
1329,
275,
12703,
489,
12703,
275,
12703,
435,
413,
489,
1072,
14,
952,
2258,
84,
60,
84,
2,
3259,
2,
520,
3546,
435,
620,
8,
1955,
9,
435,
283,
3212,
78,
358,
489,
1072,
14,
952,
2258,
84,
1386,
60,
78,
358,
489,
1449,
489,
536,
275,
1004,
1988,
17,
1527,
16,
61,
489,
574,
275,
1004,
1988,
17,
1527,
17,
61,
489,
1072,
14,
952,
2258,
84,
60,
84,
4507,
435,
536,
435,
5522,
520,
5320,
489,
340,
574,
365,
25077,
6883,
14,
1667,
63,
3890,
503,
574,
14,
585,
508,
8061,
267,
1072,
14,
952,
360,
341,
60,
78,
358,
489,
916,
3851,
14,
1733,
8,
354,
9,
365,
440,
488,
26,
267,
1434,
275,
25077,
6883,
14,
15455,
602,
63,
305,
63,
2960,
8,
585,
14,
585,
12,
12083,
14,
2706,
14,
602,
632,
9,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
602,
59,
16,
566,
435,
10791,
435,
620,
8,
602,
59,
17,
566,
435,
10791,
435,
620,
8,
602,
59,
18,
566,
435,
283,
3212,
78,
358,
489,
916,
1228,
8,
585,
14,
585,
12,
2649,
304,
267,
1072,
14,
952,
360,
4507,
435,
574,
14,
585,
435,
283,
3212,
78,
358,
489,
587,
26,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
585,
14,
585,
9,
435,
283,
3212,
78,
358,
272,
1072,
14,
952,
2258,
84,
1386,
60,
78,
358,
272,
1449,
523,
587,
26,
272,
1072,
14,
952,
2258,
84,
12911,
78,
358,
272,
367,
652,
315,
1425,
8,
552,
8,
604,
2298,
489,
536,
275,
1004,
59,
390,
1527,
16,
61,
489,
574,
275,
1004,
59,
390,
1527,
17,
61,
489,
1072,
14,
952,
2258,
84,
60,
84,
4507,
435,
536,
435,
5522,
520,
5320,
489,
340,
574,
365,
25077,
6883,
14,
1667,
63,
3890,
503,
574,
14,
585,
508,
8061,
267,
1072,
14,
952,
360,
341,
4202,
78,
358,
489,
916,
3851,
14,
1733,
8,
354,
9,
365,
440,
488,
26,
267,
1434,
275,
25077,
6883,
14,
15455,
602,
63,
305,
63,
2960,
8,
585,
14,
585,
12,
12083,
14,
2706,
14,
602,
632,
9,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
602,
59,
16,
566,
435,
10791,
435,
620,
8,
602,
59,
17,
566,
435,
10791,
435,
620,
8,
602,
59,
18,
566,
435,
283,
22260,
78,
358,
489,
916,
1228,
8,
585,
14,
585,
12,
2649,
304,
267,
1072,
14,
952,
360,
4507,
435,
574,
14,
585,
435,
283,
22260,
78,
358,
489,
587,
26,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
585,
14,
585,
9,
435,
283,
22260,
78,
358,
272,
587,
26,
489,
1329,
275,
12703,
489,
12703,
275,
12703,
435,
413,
489,
1072,
14,
952,
2258,
84,
60,
84,
2,
3259,
2,
520,
3546,
435,
620,
8,
1955,
9,
435,
283,
3212,
78,
358,
489,
1072,
14,
952,
2258,
84,
4988,
78,
358,
489,
1449,
489,
536,
275,
1004,
1988,
17,
1527,
16,
61,
489,
574,
275,
1004,
1988,
17,
1527,
17,
61,
489,
1072,
14,
952,
2258,
84,
60,
84,
4507,
435,
536,
435,
5522,
520,
5320,
489,
340,
574,
365,
25077,
6883,
14,
1667,
63,
3890,
503,
574,
14,
585,
508,
8061,
267,
1072,
14,
952,
360,
341,
60,
78,
358,
489,
916,
3851,
14,
1733,
8,
354,
9,
365,
440,
488,
26,
267,
1434,
275,
25077,
6883,
14,
15455,
602,
63,
305,
63,
2960,
8,
585,
14,
585,
12,
12083,
14,
2706,
14,
602,
632,
9,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
602,
59,
16,
566,
435,
10791,
435,
620,
8,
602,
59,
17,
566,
435,
10791,
435,
620,
8,
602,
59,
18,
566,
435,
283,
3212,
78,
358,
489,
916,
1228,
8,
585,
14,
585,
12,
2649,
304,
267,
1072,
14,
952,
360,
4507,
435,
574
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
295,
199,
646,
984,
199,
646,
25077,
6883,
199,
646,
25077,
9115,
199,
199,
318,
2198,
63,
5069,
8,
5069,
12,
1788,
12,
1738,
304,
523,
1449,
4003,
314,
12083,
436,
7115,
2412,
652,
370,
282,
2022,
570,
2344,
819,
1072,
275,
570,
8,
1501,
12,
283,
87,
358,
523,
1406,
275,
942,
523,
666,
275,
942,
523,
367,
1048,
315,
1425,
8,
5069,
14,
78,
4574,
304,
272,
1406,
14,
740,
8,
5069,
14,
3890,
63,
585,
8,
16,
12,
1048,
430,
523,
367,
1962,
315,
1425,
8,
17,
12,
12083,
14,
24590,
304,
272,
1004,
275,
942,
272,
367,
1048,
315,
1425,
8,
5069,
14,
78,
4574,
304,
489,
4917,
275,
12083,
14,
3890,
8,
1143,
12,
1048,
9,
489,
4092,
275,
334,
1291,
59,
761,
467,
4917,
9,
489,
1004,
14,
740,
8,
3852,
9,
272,
666,
14,
740,
8,
604,
9,
819,
12703,
275,
378,
523,
1072,
14,
952,
11117,
3546,
435,
1738,
435,
5522,
520,
359,
60,
78,
358,
523,
3851,
275,
295,
14,
2014,
8,
82,
7,
2506,
358,
523,
367,
1004,
315,
666,
4439,
17,
2189,
272,
1072,
14,
952,
2258,
84,
12911,
78,
358,
272,
367,
652,
315,
1425,
8,
552,
8,
604,
2298,
489,
536,
275,
1004,
59,
390,
1527,
16,
61,
489,
574,
275,
1004,
59,
390,
1527,
17,
61,
489,
1072,
14,
952,
2258,
84,
60,
84,
4507,
435,
536,
435,
5522,
520,
5320,
489,
340,
574,
365,
25077,
6883,
14,
1667,
63,
3890,
503,
574,
14,
585,
508,
8061,
267,
1072,
14,
952,
360,
341,
4202,
78,
358,
489,
916,
3851,
14,
1733,
8,
354,
9,
365,
440,
488,
26,
267,
1434,
275,
25077,
6883,
14,
15455,
602,
63,
305,
63,
2960,
8,
585,
14,
585,
12,
12083,
14,
2706,
14,
602,
632,
9,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
602,
59,
16,
566,
435,
10791,
435,
620,
8,
602,
59,
17,
566,
435,
10791,
435,
620,
8,
602,
59,
18,
566,
435,
283,
22260,
78,
358,
489,
916,
1228,
8,
585,
14,
585,
12,
2649,
304,
267,
1072,
14,
952,
360,
4507,
435,
574,
14,
585,
435,
283,
22260,
78,
358,
489,
587,
26,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
585,
14,
585,
9,
435,
283,
22260,
78,
358,
272,
587,
26,
489,
1329,
275,
12703,
489,
12703,
275,
12703,
435,
413,
489,
1072,
14,
952,
2258,
84,
60,
84,
2,
3259,
2,
520,
3546,
435,
620,
8,
1955,
9,
435,
283,
3212,
78,
358,
489,
1072,
14,
952,
2258,
84,
1386,
60,
78,
358,
489,
1449,
489,
536,
275,
1004,
1988,
17,
1527,
16,
61,
489,
574,
275,
1004,
1988,
17,
1527,
17,
61,
489,
1072,
14,
952,
2258,
84,
60,
84,
4507,
435,
536,
435,
5522,
520,
5320,
489,
340,
574,
365,
25077,
6883,
14,
1667,
63,
3890,
503,
574,
14,
585,
508,
8061,
267,
1072,
14,
952,
360,
341,
60,
78,
358,
489,
916,
3851,
14,
1733,
8,
354,
9,
365,
440,
488,
26,
267,
1434,
275,
25077,
6883,
14,
15455,
602,
63,
305,
63,
2960,
8,
585,
14,
585,
12,
12083,
14,
2706,
14,
602,
632,
9,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
602,
59,
16,
566,
435,
10791,
435,
620,
8,
602,
59,
17,
566,
435,
10791,
435,
620,
8,
602,
59,
18,
566,
435,
283,
3212,
78,
358,
489,
916,
1228,
8,
585,
14,
585,
12,
2649,
304,
267,
1072,
14,
952,
360,
4507,
435,
574,
14,
585,
435,
283,
3212,
78,
358,
489,
587,
26,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
585,
14,
585,
9,
435,
283,
3212,
78,
358,
272,
1072,
14,
952,
2258,
84,
1386,
60,
78,
358,
272,
1449,
523,
587,
26,
272,
1072,
14,
952,
2258,
84,
12911,
78,
358,
272,
367,
652,
315,
1425,
8,
552,
8,
604,
2298,
489,
536,
275,
1004,
59,
390,
1527,
16,
61,
489,
574,
275,
1004,
59,
390,
1527,
17,
61,
489,
1072,
14,
952,
2258,
84,
60,
84,
4507,
435,
536,
435,
5522,
520,
5320,
489,
340,
574,
365,
25077,
6883,
14,
1667,
63,
3890,
503,
574,
14,
585,
508,
8061,
267,
1072,
14,
952,
360,
341,
4202,
78,
358,
489,
916,
3851,
14,
1733,
8,
354,
9,
365,
440,
488,
26,
267,
1434,
275,
25077,
6883,
14,
15455,
602,
63,
305,
63,
2960,
8,
585,
14,
585,
12,
12083,
14,
2706,
14,
602,
632,
9,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
602,
59,
16,
566,
435,
10791,
435,
620,
8,
602,
59,
17,
566,
435,
10791,
435,
620,
8,
602,
59,
18,
566,
435,
283,
22260,
78,
358,
489,
916,
1228,
8,
585,
14,
585,
12,
2649,
304,
267,
1072,
14,
952,
360,
4507,
435,
574,
14,
585,
435,
283,
22260,
78,
358,
489,
587,
26,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
585,
14,
585,
9,
435,
283,
22260,
78,
358,
272,
587,
26,
489,
1329,
275,
12703,
489,
12703,
275,
12703,
435,
413,
489,
1072,
14,
952,
2258,
84,
60,
84,
2,
3259,
2,
520,
3546,
435,
620,
8,
1955,
9,
435,
283,
3212,
78,
358,
489,
1072,
14,
952,
2258,
84,
4988,
78,
358,
489,
1449,
489,
536,
275,
1004,
1988,
17,
1527,
16,
61,
489,
574,
275,
1004,
1988,
17,
1527,
17,
61,
489,
1072,
14,
952,
2258,
84,
60,
84,
4507,
435,
536,
435,
5522,
520,
5320,
489,
340,
574,
365,
25077,
6883,
14,
1667,
63,
3890,
503,
574,
14,
585,
508,
8061,
267,
1072,
14,
952,
360,
341,
60,
78,
358,
489,
916,
3851,
14,
1733,
8,
354,
9,
365,
440,
488,
26,
267,
1434,
275,
25077,
6883,
14,
15455,
602,
63,
305,
63,
2960,
8,
585,
14,
585,
12,
12083,
14,
2706,
14,
602,
632,
9,
267,
1072,
14,
952,
360,
4507,
435,
620,
8,
602,
59,
16,
566,
435,
10791,
435,
620,
8,
602,
59,
17,
566,
435,
10791,
435,
620,
8,
602,
59,
18,
566,
435,
283,
3212,
78,
358,
489,
916,
1228,
8,
585,
14,
585,
12,
2649,
304,
267,
1072,
14,
952,
360,
4507,
435,
574,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SerpentCS/odoo
|
addons/crm_partner_assign/crm_lead.py
|
221
|
3039
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import osv
from openerp.tools.translate import _
from openerp.tools.safe_eval import safe_eval as eval
class crm_lead(osv.osv):
_inherit = 'crm.lead'
def get_interested_action(self, cr, uid, interested, context=None):
try:
model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm_partner_assign', 'crm_lead_channel_interested_act')
except ValueError:
raise osv.except_osv(_('Error!'), _("The CRM Channel Interested Action is missing"))
action = self.pool[model].read(cr, uid, [action_id], context=context)[0]
action_context = eval(action['context'])
action_context['interested'] = interested
action['context'] = str(action_context)
return action
def case_interested(self, cr, uid, ids, context=None):
return self.get_interested_action(cr, uid, True, context=context)
def case_disinterested(self, cr, uid, ids, context=None):
return self.get_interested_action(cr, uid, False, context=context)
def assign_salesman_of_assigned_partner(self, cr, uid, ids, context=None):
salesmans_leads = {}
for lead in self.browse(cr, uid, ids, context=context):
if (lead.stage_id.probability > 0 and lead.stage_id.probability < 100) or lead.stage_id.sequence == 1:
if lead.partner_assigned_id and lead.partner_assigned_id.user_id and lead.partner_assigned_id.user_id != lead.user_id:
salesman_id = lead.partner_assigned_id.user_id.id
if salesmans_leads.get(salesman_id):
salesmans_leads[salesman_id].append(lead.id)
else:
salesmans_leads[salesman_id] = [lead.id]
for salesman_id, lead_ids in salesmans_leads.items():
salesteam_id = self.on_change_user(cr, uid, lead_ids, salesman_id, context=None)['value'].get('section_id')
self.write(cr, uid, lead_ids, {'user_id': salesman_id, 'section_id': salesteam_id}, context=context)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
465,
3468,
421,
199,
533,
2467,
77,
63,
13799,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
15213,
14,
13799,
7,
339,
347,
664,
63,
5707,
20032,
63,
1287,
8,
277,
12,
2467,
12,
1747,
12,
22201,
12,
1067,
29,
403,
304,
267,
862,
26,
288,
1402,
12,
1595,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
1959,
362,
63,
785,
63,
4443,
8,
1556,
12,
1747,
12,
283,
15213,
63,
3899,
63,
5038,
297,
283,
15213,
63,
13799,
63,
2775,
63,
5707,
20032,
63,
2442,
358,
267,
871,
1722,
26,
288,
746,
9506,
14,
2590,
63,
4795,
6723,
547,
15659,
3824,
1918,
445,
11026,
17270,
8883,
20032,
10033,
365,
4124,
2237,
267,
1595,
275,
291,
14,
2293,
59,
1238,
1055,
739,
8,
1556,
12,
1747,
12,
359,
1287,
63,
344,
467,
1067,
29,
1100,
2788,
16,
61,
267,
1595,
63,
1100,
275,
3468,
8,
1287,
459,
1100,
1105,
267,
1595,
63,
1100,
459,
5707,
20032,
418,
275,
22201,
267,
1595,
459,
1100,
418,
275,
620,
8,
1287,
63,
1100,
9,
267,
372,
1595,
339,
347,
1930,
63,
5707,
20032,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
362,
63,
5707,
20032,
63,
1287,
8,
1556,
12,
1747,
12,
715,
12,
1067,
29,
1100,
9,
339,
347,
1930,
63,
2297,
5707,
20032,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
362,
63,
5707,
20032,
63,
1287,
8,
1556,
12,
1747,
12,
756,
12,
1067,
29,
1100,
9,
339,
347,
5090,
63,
16175,
1237,
63,
1618,
63,
12941,
63,
3899,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
13590,
3300,
796,
63,
274,
9402,
275,
1052,
267,
367,
12690,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
340,
334,
13799,
14,
8614,
63,
344,
14,
17210,
690,
378,
436,
12690,
14,
8614,
63,
344,
14,
17210,
665,
2948,
9,
503,
12690,
14,
8614,
63,
344,
14,
4041,
508,
413,
26,
8892,
340,
12690,
14,
3899,
63,
12941,
63,
344,
436,
12690,
14,
3899,
63,
12941,
63,
344,
14,
751,
63,
344,
436,
12690,
14,
3899,
63,
12941,
63,
344,
14,
751,
63,
344,
1137,
12690,
14,
751,
63,
344,
26,
490,
21702,
1237,
63,
344,
275,
12690,
14,
3899,
63,
12941,
63,
344,
14,
751,
63,
344,
14,
344,
490,
340,
13590,
3300,
796,
63,
274,
9402,
14,
362,
8,
16175,
1237,
63,
344,
304,
717,
13590,
3300,
796,
63,
274,
9402,
59,
16175,
1237,
63,
344,
1055,
740,
8,
13799,
14,
344,
9,
490,
587,
26,
717,
13590,
3300,
796,
63,
274,
9402,
59,
16175,
1237,
63,
344,
61,
275,
359,
13799,
14,
344,
61,
267,
367,
21702,
1237,
63,
344,
12,
12690,
63,
1580,
315,
13590,
3300,
796,
63,
274,
9402,
14,
1744,
837,
288,
13590,
1597,
455,
63,
344,
275,
291,
14,
265,
63,
1461,
63,
751,
8,
1556,
12,
1747,
12,
12690,
63,
1580,
12,
21702,
1237,
63,
344,
12,
1067,
29,
403,
11820,
585,
2278,
362,
360,
2792,
63,
344,
358,
288,
291,
14,
952,
8,
1556,
12,
1747,
12,
12690,
63,
1580,
12,
791,
751,
63,
344,
356,
21702,
1237,
63,
344,
12,
283,
2792,
63,
344,
356,
13590,
1597,
455,
63,
344,
1386,
1067,
29,
1100,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
465,
3468,
421,
199,
533,
2467,
77,
63,
13799,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
15213,
14,
13799,
7,
339,
347,
664,
63,
5707,
20032,
63,
1287,
8,
277,
12,
2467,
12,
1747,
12,
22201,
12,
1067,
29,
403,
304,
267,
862,
26,
288,
1402,
12,
1595,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
1959,
362,
63,
785,
63,
4443,
8,
1556,
12,
1747,
12,
283,
15213,
63,
3899,
63,
5038,
297,
283,
15213,
63,
13799,
63,
2775,
63,
5707,
20032,
63,
2442,
358,
267,
871,
1722,
26,
288,
746,
9506,
14,
2590,
63,
4795,
6723,
547,
15659,
3824,
1918,
445,
11026,
17270,
8883,
20032,
10033,
365,
4124,
2237,
267,
1595,
275,
291,
14,
2293,
59,
1238,
1055,
739,
8,
1556,
12,
1747,
12,
359,
1287,
63,
344,
467,
1067,
29,
1100,
2788,
16,
61,
267,
1595,
63,
1100,
275,
3468,
8,
1287,
459,
1100,
1105,
267,
1595,
63,
1100,
459,
5707,
20032,
418,
275,
22201,
267,
1595,
459,
1100,
418,
275,
620,
8,
1287,
63,
1100,
9,
267,
372,
1595,
339,
347,
1930,
63,
5707,
20032,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
362,
63,
5707,
20032,
63,
1287,
8,
1556,
12,
1747,
12,
715,
12,
1067,
29,
1100,
9,
339,
347,
1930,
63,
2297,
5707,
20032,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
362,
63,
5707,
20032,
63,
1287,
8,
1556,
12,
1747,
12,
756,
12,
1067,
29,
1100,
9,
339,
347,
5090,
63,
16175,
1237,
63,
1618,
63,
12941,
63,
3899,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
13590,
3300,
796,
63,
274,
9402,
275,
1052,
267,
367,
12690,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
340,
334,
13799,
14,
8614,
63,
344,
14,
17210,
690,
378,
436,
12690,
14,
8614,
63,
344,
14,
17210,
665,
2948,
9,
503,
12690,
14,
8614,
63,
344,
14,
4041,
508,
413,
26,
8892,
340,
12690,
14,
3899,
63,
12941,
63,
344,
436,
12690,
14,
3899,
63,
12941,
63,
344,
14,
751,
63,
344,
436,
12690,
14,
3899,
63,
12941,
63,
344,
14,
751,
63,
344,
1137,
12690,
14,
751,
63,
344,
26,
490,
21702,
1237,
63,
344,
275,
12690,
14,
3899,
63,
12941,
63,
344,
14,
751,
63,
344,
14,
344,
490,
340,
13590,
3300,
796,
63,
274,
9402,
14,
362,
8,
16175,
1237,
63,
344,
304,
717,
13590,
3300,
796,
63,
274,
9402,
59,
16175,
1237,
63,
344,
1055,
740,
8,
13799,
14,
344,
9,
490,
587,
26,
717,
13590,
3300,
796,
63,
274,
9402,
59,
16175,
1237,
63,
344,
61,
275,
359,
13799,
14,
344,
61,
267,
367,
21702,
1237,
63,
344,
12,
12690,
63,
1580,
315,
13590,
3300,
796,
63,
274,
9402,
14,
1744,
837,
288,
13590,
1597,
455,
63,
344,
275,
291,
14,
265,
63,
1461,
63,
751,
8,
1556,
12,
1747,
12,
12690,
63,
1580,
12,
21702,
1237,
63,
344,
12,
1067,
29,
403,
11820,
585,
2278,
362,
360,
2792,
63,
344,
358,
288,
291,
14,
952,
8,
1556,
12,
1747,
12,
12690,
63,
1580,
12,
791,
751,
63,
344,
356,
21702,
1237,
63,
344,
12,
283,
2792,
63,
344,
356,
13590,
1597,
455,
63,
344,
1386,
1067,
29,
1100,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
NathanW2/QGIS
|
python/plugins/processing/algs/qgis/TextToFloat.py
|
4
|
3145
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
TextToFloat.py
---------------------
Date : May 2010
Copyright : (C) 2010 by Michael Minn
Email : pyqgis at michaelminn dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Michael Minn'
__date__ = 'May 2010'
__copyright__ = '(C) 2010, Michael Minn'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsProcessing,
QgsProcessingParameterField)
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm
class TextToFloat(QgisFeatureBasedAlgorithm):
FIELD = 'FIELD'
def group(self):
return self.tr('Vector table')
def groupId(self):
return 'vectortable'
def __init__(self):
super().__init__()
self.field_name = None
self.field_idx = -1
def initParameters(self, config=None):
self.addParameter(QgsProcessingParameterField(self.FIELD,
self.tr('Text attribute to convert to float'),
parentLayerParameterName='INPUT',
type=QgsProcessingParameterField.String
))
def name(self):
return 'texttofloat'
def displayName(self):
return self.tr('Text to float')
def outputName(self):
return self.tr('Float from text')
def inputLayerTypes(self):
return [QgsProcessing.TypeVector]
def outputFields(self, inputFields):
self.field_idx = inputFields.lookupField(self.field_name)
if self.field_idx >= 0:
inputFields[self.field_idx] = QgsField(self.field_name, QVariant.Double, '', 24, 15)
return inputFields
def prepareAlgorithm(self, parameters, context, feedback):
self.field_name = self.parameterAsString(parameters, self.FIELD, context)
return True
def processFeature(self, feature, context, feedback):
value = feature[self.field_idx]
try:
if '%' in value:
feature[self.field_idx] = float(value.replace('%', '')) / 100.0
else:
feature[self.field_idx] = float(value)
except:
feature[self.field_idx] = None
return [feature]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
4516,
1378,
5136,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
10162,
7129,
272,
1898,
3322,
520,
334,
35,
9,
7129,
701,
16922,
10195,
78,
272,
11426,
4483,
520,
1134,
25325,
737,
333,
11781,
827,
78,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
45,
11781,
10195,
78,
7,
199,
363,
602,
363,
275,
283,
15586,
7129,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
7129,
12,
16922,
10195,
78,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
504,
15640,
14,
24107,
14,
10901,
492,
27875,
199,
504,
15640,
14,
1018,
492,
334,
7350,
792,
12,
2432,
17214,
12,
2432,
23764,
792,
9,
199,
504,
6661,
14,
31128,
14,
25325,
14,
49,
5668,
11570,
492,
1413,
5668,
5968,
20409,
11570,
421,
199,
533,
4516,
1378,
5136,
8,
49,
5668,
5968,
20409,
11570,
304,
339,
26130,
275,
283,
8609,
7,
339,
347,
1572,
8,
277,
304,
267,
372,
291,
14,
454,
360,
3646,
1817,
358,
339,
347,
1572,
1304,
8,
277,
304,
267,
372,
283,
28122,
361,
461,
7,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
698,
63,
354,
275,
488,
267,
291,
14,
698,
63,
2996,
275,
446,
17,
339,
347,
4205,
5976,
8,
277,
12,
1101,
29,
403,
304,
267,
291,
14,
26895,
8,
28559,
4720,
792,
8,
277,
14,
8609,
12,
10028,
291,
14,
454,
360,
1872,
2225,
370,
3957,
370,
2069,
659,
10028,
1676,
5003,
4720,
985,
534,
7321,
297,
10028,
730,
29,
28559,
4720,
792,
14,
1558,
10028,
5082,
339,
347,
536,
8,
277,
304,
267,
372,
283,
505,
475,
1609,
7,
339,
347,
2929,
985,
8,
277,
304,
267,
372,
291,
14,
454,
360,
1872,
370,
2069,
358,
339,
347,
1072,
985,
8,
277,
304,
267,
372,
291,
14,
454,
360,
5136,
687,
1318,
358,
339,
347,
1324,
5003,
4100,
8,
277,
304,
267,
372,
359,
28559,
14,
804,
3646,
61,
339,
347,
1072,
7304,
8,
277,
12,
1324,
7304,
304,
267,
291,
14,
698,
63,
2996,
275,
1324,
7304,
14,
3892,
792,
8,
277,
14,
698,
63,
354,
9,
267,
340,
291,
14,
698,
63,
2996,
2356,
378,
26,
288,
1324,
7304,
59,
277,
14,
698,
63,
2996,
61,
275,
4888,
792,
8,
277,
14,
698,
63,
354,
12,
27875,
14,
7281,
12,
3260,
5504,
12,
4114,
9,
267,
372,
1324,
7304,
339,
347,
9275,
11570,
8,
277,
12,
2633,
12,
1067,
12,
17145,
304,
267,
291,
14,
698,
63,
354,
275,
291,
14,
5329,
2822,
1558,
8,
3214,
12,
291,
14,
8609,
12,
1067,
9,
267,
372,
715,
339,
347,
2112,
5968,
8,
277,
12,
3878,
12,
1067,
12,
17145,
304,
267,
574,
275,
3878,
59,
277,
14,
698,
63,
2996,
61,
267,
862,
26,
288,
340,
26386,
315,
574,
26,
355,
3878,
59,
277,
14,
698,
63,
2996,
61,
275,
2069,
8,
585,
14,
1814,
3508,
297,
12381,
1182,
2948,
14,
16,
288,
587,
26,
355,
3878,
59,
277,
14,
698,
63,
2996,
61,
275,
2069,
8,
585,
9,
267,
871,
26,
288,
3878,
59,
277,
14,
698,
63,
2996,
61,
275,
488,
267,
372,
359,
4445,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
4516,
1378,
5136,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
10162,
7129,
272,
1898,
3322,
520,
334,
35,
9,
7129,
701,
16922,
10195,
78,
272,
11426,
4483,
520,
1134,
25325,
737,
333,
11781,
827,
78,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
45,
11781,
10195,
78,
7,
199,
363,
602,
363,
275,
283,
15586,
7129,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
7129,
12,
16922,
10195,
78,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
504,
15640,
14,
24107,
14,
10901,
492,
27875,
199,
504,
15640,
14,
1018,
492,
334,
7350,
792,
12,
2432,
17214,
12,
2432,
23764,
792,
9,
199,
504,
6661,
14,
31128,
14,
25325,
14,
49,
5668,
11570,
492,
1413,
5668,
5968,
20409,
11570,
421,
199,
533,
4516,
1378,
5136,
8,
49,
5668,
5968,
20409,
11570,
304,
339,
26130,
275,
283,
8609,
7,
339,
347,
1572,
8,
277,
304,
267,
372,
291,
14,
454,
360,
3646,
1817,
358,
339,
347,
1572,
1304,
8,
277,
304,
267,
372,
283,
28122,
361,
461,
7,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
698,
63,
354,
275,
488,
267,
291,
14,
698,
63,
2996,
275,
446,
17,
339,
347,
4205,
5976,
8,
277,
12,
1101,
29,
403,
304,
267,
291,
14,
26895,
8,
28559,
4720,
792,
8,
277,
14,
8609,
12,
10028,
291,
14,
454,
360,
1872,
2225,
370,
3957,
370,
2069,
659,
10028,
1676,
5003,
4720,
985,
534,
7321,
297,
10028,
730,
29,
28559,
4720,
792,
14,
1558,
10028,
5082,
339,
347,
536,
8,
277,
304,
267,
372,
283,
505,
475,
1609,
7,
339,
347,
2929,
985,
8,
277,
304,
267,
372,
291,
14,
454,
360,
1872,
370,
2069,
358,
339,
347,
1072,
985,
8,
277,
304,
267,
372,
291,
14,
454,
360,
5136,
687,
1318,
358,
339,
347,
1324,
5003,
4100,
8,
277,
304,
267,
372,
359,
28559,
14,
804,
3646,
61,
339,
347,
1072,
7304,
8,
277,
12,
1324,
7304,
304,
267,
291,
14,
698,
63,
2996,
275,
1324,
7304,
14,
3892,
792,
8,
277,
14,
698,
63,
354,
9,
267,
340,
291,
14,
698,
63,
2996,
2356,
378,
26,
288,
1324,
7304,
59,
277,
14,
698,
63,
2996,
61,
275,
4888,
792,
8,
277,
14,
698,
63,
354,
12,
27875,
14,
7281,
12,
3260,
5504,
12,
4114,
9,
267,
372,
1324,
7304,
339,
347,
9275,
11570,
8,
277,
12,
2633,
12,
1067,
12,
17145,
304,
267,
291,
14,
698,
63,
354,
275,
291,
14,
5329,
2822,
1558,
8,
3214,
12,
291,
14,
8609,
12,
1067,
9,
267,
372,
715,
339,
347,
2112,
5968,
8,
277,
12,
3878,
12,
1067,
12,
17145,
304,
267,
574,
275,
3878,
59,
277,
14,
698,
63,
2996,
61,
267,
862,
26,
288,
340,
26386,
315,
574,
26,
355,
3878,
59,
277,
14,
698,
63,
2996,
61,
275,
2069,
8,
585,
14,
1814,
3508,
297,
12381,
1182,
2948,
14,
16,
288,
587,
26,
355,
3878,
59,
277,
14,
698,
63,
2996,
61,
275,
2069,
8,
585,
9,
267,
871,
26,
288,
3878,
59,
277,
14,
698,
63,
2996,
61,
275,
488,
267,
372,
359,
4445,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
daizhengy/RDS
|
trove/tests/api/mgmt/accounts.py
|
5
|
8097
|
# Copyright 2011 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from troveclient.compat import exceptions
from nose.plugins.skip import SkipTest
from proboscis import after_class
from proboscis import before_class
from proboscis import test
from proboscis import asserts
from proboscis.decorators import time_out
from trove import tests
from trove.tests.api.instances import instance_info
from trove.tests.util import test_config
from trove.tests.util import create_dbaas_client
from trove.common.utils import poll_until
from trove.tests.config import CONFIG
from trove.tests.util.users import Requirements
GROUP = "dbaas.api.mgmt.accounts"
@test(groups=[tests.DBAAS_API, GROUP, tests.PRE_INSTANCES],
depends_on_groups=["services.initialize"])
class AccountsBeforeInstanceCreation(object):
@before_class
def setUp(self):
self.user = test_config.users.find_user(Requirements(is_admin=True))
self.client = create_dbaas_client(self.user)
@test
def test_invalid_account_fails(self):
account_info = self.client.accounts.show("badaccount")
asserts.assert_not_equal(self.user.tenant_id, account_info.id)
@test(groups=[tests.INSTANCES, GROUP], depends_on_groups=["dbaas.listing"])
class AccountsAfterInstanceCreation(object):
@before_class
def setUp(self):
self.user = test_config.users.find_user(Requirements(is_admin=True))
self.client = create_dbaas_client(self.user)
@test
def test_account_details_available(self):
if CONFIG.fake_mode:
raise SkipTest("Skipping this as auth is faked anyway.")
account_info = self.client.accounts.show(instance_info.user.tenant_id)
# Now check the results.
expected = instance_info.user.tenant_id
if expected is None:
expected = "None"
print("account_id.id = '%s'" % account_info.id)
print("expected = '%s'" % expected)
asserts.assert_equal(expected, account_info.id)
# Instances: there should at least be one instance
asserts.assert_true(len(account_info.instance_ids) > 0)
# The instance id should be one of the instances for the account
asserts.assert_true(instance_info.id in account_info.instance_ids)
@test
def test_list_accounts(self):
if CONFIG.fake_mode:
raise SkipTest("Skipping this as auth is faked anyway.")
accounts_info = self.client.accounts.index()
asserts.assert_equal(1, len(accounts_info.accounts))
account = accounts_info.accounts[0]
asserts.assert_true(account['num_instances'] > 0)
asserts.assert_equal(instance_info.user.tenant_id, account['id'])
@test(groups=[tests.POST_INSTANCES, GROUP],
depends_on_groups=["dbaas.guest.shutdown"])
class AccountsAfterInstanceDeletion(object):
@before_class
def setUp(self):
self.user = test_config.users.find_user(Requirements(is_admin=True))
self.client = create_dbaas_client(self.user)
@test
def test_instance_id_removed_from_account(self):
account_info = self.client.accounts.show(instance_info.user.tenant_id)
asserts.assert_true(instance_info.id not in account_info.instance_ids)
@test(groups=["fake.dbaas.api.mgmt.allaccounts"],
depends_on_groups=["services.initialize"])
class AllAccounts(object):
max = 5
def _delete_instances_for_users(self):
for user in self.users:
user_client = create_dbaas_client(user)
while True:
deleted_count = 0
user_instances = user_client.instances.list()
for instance in user_instances:
try:
instance.delete()
except exceptions.NotFound:
deleted_count += 1
except Exception:
print("Failed to delete instance")
if deleted_count == len(user_instances):
break
def _create_instances_for_users(self):
for user in self.users:
user_client = create_dbaas_client(user)
for index in range(self.max):
name = "instance-%s-%03d" % (user.auth_user, index)
user_client.instances.create(name, 1, {'size': 1}, [], [])
@before_class
def setUp(self):
admin_req = Requirements(is_admin=True)
self.admin_user = test_config.users.find_user(admin_req)
self.admin_client = create_dbaas_client(self.admin_user)
user_req = Requirements(is_admin=False)
self.users = test_config.users.find_all_users_who_satisfy(user_req)
self.user_tenant_ids = [user.tenant_id for user in self.users]
self._create_instances_for_users()
@test
def test_list_accounts_with_multiple_users(self):
accounts_info = self.admin_client.accounts.index()
for account in accounts_info.accounts:
asserts.assert_true(account['id'] in self.user_tenant_ids)
asserts.assert_equal(self.max, account['num_instances'])
@after_class(always_run=True)
@time_out(60)
def tear_down(self):
self._delete_instances_for_users()
@test(groups=["fake.%s.broken" % GROUP],
depends_on_groups=["services.initialize"],
runs_after_groups=["dbaas.guest.shutdown"])
class AccountWithBrokenInstance(object):
@before_class
def setUpACCR(self):
from trove.taskmanager.models import CONF
self.old_dns_support = CONF.trove_dns_support
CONF.trove_dns_support = False
self.user = test_config.users.find_user(Requirements(is_admin=True))
self.client = create_dbaas_client(self.user)
self.name = 'test_SERVER_ERROR'
# Create an instance with a broken compute instance.
volume = None
if CONFIG.trove_volume_support:
volume = {'size': 1}
self.response = self.client.instances.create(
self.name,
instance_info.dbaas_flavor_href,
volume,
[])
poll_until(lambda: self.client.instances.get(self.response.id),
lambda instance: instance.status == 'ERROR',
time_out=10)
self.instance = self.client.instances.get(self.response.id)
print("Status: %s" % self.instance.status)
msg = "Instance did not drop to error after server prov failure."
asserts.assert_equal(self.instance.status, "ERROR", msg)
@test
def no_compute_instance_no_problem(self):
"""Get account by ID shows even instances lacking computes."""
if test_config.auth_strategy == "fake":
raise SkipTest("Skipping this as auth is faked anyway.")
account_info = self.client.accounts.show(self.user.tenant_id)
# All we care about is that accounts.show doesn't 500 on us
# for having a broken instance in the roster.
asserts.assert_equal(len(account_info.instances), 1)
instance = account_info.instances[0]
asserts.assert_true(isinstance(instance['id'], basestring))
asserts.assert_equal(len(instance['id']), 36)
asserts.assert_equal(instance['name'], self.name)
asserts.assert_equal(instance['status'], "ERROR")
assert_is_none(instance['host'])
@after_class
def tear_down(self):
self.client.instances.delete(self.response.id)
@after_class
def restore_dns(self):
from trove.taskmanager.models import CONF
CONF.trove_dns_support = self.old_dns_support
|
apache-2.0
|
[
3,
259,
1898,
7760,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
307,
11750,
1258,
14,
5819,
492,
4967,
199,
199,
504,
11354,
14,
5265,
14,
2759,
492,
18795,
199,
199,
504,
557,
656,
551,
374,
492,
2410,
63,
533,
199,
504,
557,
656,
551,
374,
492,
2544,
63,
533,
199,
504,
557,
656,
551,
374,
492,
511,
199,
504,
557,
656,
551,
374,
492,
702,
83,
199,
504,
557,
656,
551,
374,
14,
11582,
492,
900,
63,
548,
199,
199,
504,
307,
11750,
492,
2295,
199,
504,
307,
11750,
14,
2219,
14,
1246,
14,
5990,
492,
1256,
63,
815,
199,
504,
307,
11750,
14,
2219,
14,
1974,
492,
511,
63,
888,
199,
504,
307,
11750,
14,
2219,
14,
1974,
492,
1218,
63,
27634,
305,
63,
1258,
199,
504,
307,
11750,
14,
2330,
14,
1208,
492,
11271,
63,
8111,
199,
504,
307,
11750,
14,
2219,
14,
888,
492,
15869,
199,
504,
307,
11750,
14,
2219,
14,
1974,
14,
3707,
492,
18513,
1470,
421,
199,
7823,
275,
298,
27634,
305,
14,
1246,
14,
9752,
14,
8370,
2,
421,
199,
32,
396,
8,
2634,
1524,
2219,
14,
2846,
33,
1179,
63,
3735,
12,
15443,
12,
2295,
14,
4225,
63,
7834,
879,
16734,
467,
489,
8350,
63,
265,
63,
2634,
6270,
5950,
14,
8489,
3135,
199,
533,
4473,
6851,
13569,
3244,
13921,
8,
785,
304,
339,
768,
5182,
63,
533,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
511,
63,
888,
14,
3707,
14,
1623,
63,
751,
8,
13902,
1470,
8,
374,
63,
2113,
29,
549,
430,
267,
291,
14,
1258,
275,
1218,
63,
27634,
305,
63,
1258,
8,
277,
14,
751,
9,
339,
768,
396,
272,
347,
511,
63,
3197,
63,
2048,
63,
15762,
8,
277,
304,
267,
2933,
63,
815,
275,
291,
14,
1258,
14,
8370,
14,
2384,
480,
4087,
2048,
531,
267,
702,
83,
14,
479,
63,
1397,
63,
1452,
8,
277,
14,
751,
14,
4647,
63,
344,
12,
2933,
63,
815,
14,
344,
9,
421,
199,
32,
396,
8,
2634,
1524,
2219,
14,
7834,
879,
16734,
12,
15443,
467,
8350,
63,
265,
63,
2634,
6270,
27634,
305,
14,
16115,
3135,
199,
533,
4473,
6851,
10881,
3244,
13921,
8,
785,
304,
339,
768,
5182,
63,
533,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
511,
63,
888,
14,
3707,
14,
1623,
63,
751,
8,
13902,
1470,
8,
374,
63,
2113,
29,
549,
430,
267,
291,
14,
1258,
275,
1218,
63,
27634,
305,
63,
1258,
8,
277,
14,
751,
9,
339,
768,
396,
272,
347,
511,
63,
2048,
63,
5087,
63,
4561,
8,
277,
304,
267,
340,
15869,
14,
3183,
63,
632,
26,
288,
746,
18795,
480,
18297,
642,
465,
1790,
365,
289,
16702,
15988,
2685,
267,
2933,
63,
815,
275,
291,
14,
1258,
14,
8370,
14,
2384,
8,
842,
63,
815,
14,
751,
14,
4647,
63,
344,
9,
267,
327,
7356,
1104,
314,
2058,
14,
267,
1420,
275,
1256,
63,
815,
14,
751,
14,
4647,
63,
344,
267,
340,
1420,
365,
488,
26,
288,
1420,
275,
298,
403,
2,
267,
870,
480,
2048,
63,
344,
14,
344,
275,
1543,
83,
4065,
450,
2933,
63,
815,
14,
344,
9,
267,
870,
480,
2062,
275,
1543,
83,
4065,
450,
1420,
9,
267,
702,
83,
14,
479,
63,
1452,
8,
2062,
12,
2933,
63,
815,
14,
344,
9,
267,
327,
10066,
83,
26,
2337,
1077,
737,
5210,
506,
1373,
1256,
267,
702,
83,
14,
479,
63,
2052,
8,
552,
8,
2048,
63,
815,
14,
842,
63,
1580,
9,
690,
378,
9,
267,
327,
710,
1256,
1305,
1077,
506,
1373,
402,
314,
4454,
367,
314,
2933,
267,
702,
83,
14,
479,
63,
2052,
8,
842,
63,
815,
14,
344,
315,
2933,
63,
815,
14,
842,
63,
1580,
9,
339,
768,
396,
272,
347,
511,
63,
513,
63,
8370,
8,
277,
304,
267,
340,
15869,
14,
3183,
63,
632,
26,
288,
746,
18795,
480,
18297,
642,
465,
1790,
365,
289,
16702,
15988,
2685,
267,
12639,
63,
815,
275,
291,
14,
1258,
14,
8370,
14,
1080,
342,
267,
702,
83,
14,
479,
63,
1452,
8,
17,
12,
822,
8,
8370,
63,
815,
14,
8370,
430,
267,
2933,
275,
12639,
63,
815,
14,
8370,
59,
16,
61,
267,
702,
83,
14,
479,
63,
2052,
8,
2048,
459,
1507,
63,
5990,
418,
690,
378,
9,
267,
702,
83,
14,
479,
63,
1452,
8,
842,
63,
815,
14,
751,
14,
4647,
63,
344,
12,
2933,
459,
344,
1105,
421,
199,
32,
396,
8,
2634,
1524,
2219,
14,
4030,
63,
7834,
879,
16734,
12,
15443,
467,
489,
8350,
63,
265,
63,
2634,
6270,
27634,
305,
14,
10409,
14,
8831,
3135,
199,
533,
4473,
6851,
10881,
3244,
3896,
296,
8,
785,
304,
339,
768,
5182,
63,
533,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
511,
63,
888,
14,
3707,
14,
1623,
63,
751,
8,
13902,
1470,
8,
374,
63,
2113,
29,
549,
430,
267,
291,
14,
1258,
275,
1218,
63,
27634,
305,
63,
1258,
8,
277,
14,
751,
9,
339,
768,
396,
272,
347,
511,
63,
842,
63,
344,
63,
10649,
63,
504,
63,
2048,
8,
277,
304,
267,
2933,
63,
815,
275,
291,
14,
1258,
14,
8370,
14,
2384,
8,
842,
63,
815,
14,
751,
14,
4647,
63,
344,
9,
267,
702,
83,
14,
479,
63,
2052,
8,
842,
63,
815,
14,
344,
440,
315,
2933,
63,
815
] |
[
259,
1898,
7760,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
307,
11750,
1258,
14,
5819,
492,
4967,
199,
199,
504,
11354,
14,
5265,
14,
2759,
492,
18795,
199,
199,
504,
557,
656,
551,
374,
492,
2410,
63,
533,
199,
504,
557,
656,
551,
374,
492,
2544,
63,
533,
199,
504,
557,
656,
551,
374,
492,
511,
199,
504,
557,
656,
551,
374,
492,
702,
83,
199,
504,
557,
656,
551,
374,
14,
11582,
492,
900,
63,
548,
199,
199,
504,
307,
11750,
492,
2295,
199,
504,
307,
11750,
14,
2219,
14,
1246,
14,
5990,
492,
1256,
63,
815,
199,
504,
307,
11750,
14,
2219,
14,
1974,
492,
511,
63,
888,
199,
504,
307,
11750,
14,
2219,
14,
1974,
492,
1218,
63,
27634,
305,
63,
1258,
199,
504,
307,
11750,
14,
2330,
14,
1208,
492,
11271,
63,
8111,
199,
504,
307,
11750,
14,
2219,
14,
888,
492,
15869,
199,
504,
307,
11750,
14,
2219,
14,
1974,
14,
3707,
492,
18513,
1470,
421,
199,
7823,
275,
298,
27634,
305,
14,
1246,
14,
9752,
14,
8370,
2,
421,
199,
32,
396,
8,
2634,
1524,
2219,
14,
2846,
33,
1179,
63,
3735,
12,
15443,
12,
2295,
14,
4225,
63,
7834,
879,
16734,
467,
489,
8350,
63,
265,
63,
2634,
6270,
5950,
14,
8489,
3135,
199,
533,
4473,
6851,
13569,
3244,
13921,
8,
785,
304,
339,
768,
5182,
63,
533,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
511,
63,
888,
14,
3707,
14,
1623,
63,
751,
8,
13902,
1470,
8,
374,
63,
2113,
29,
549,
430,
267,
291,
14,
1258,
275,
1218,
63,
27634,
305,
63,
1258,
8,
277,
14,
751,
9,
339,
768,
396,
272,
347,
511,
63,
3197,
63,
2048,
63,
15762,
8,
277,
304,
267,
2933,
63,
815,
275,
291,
14,
1258,
14,
8370,
14,
2384,
480,
4087,
2048,
531,
267,
702,
83,
14,
479,
63,
1397,
63,
1452,
8,
277,
14,
751,
14,
4647,
63,
344,
12,
2933,
63,
815,
14,
344,
9,
421,
199,
32,
396,
8,
2634,
1524,
2219,
14,
7834,
879,
16734,
12,
15443,
467,
8350,
63,
265,
63,
2634,
6270,
27634,
305,
14,
16115,
3135,
199,
533,
4473,
6851,
10881,
3244,
13921,
8,
785,
304,
339,
768,
5182,
63,
533,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
511,
63,
888,
14,
3707,
14,
1623,
63,
751,
8,
13902,
1470,
8,
374,
63,
2113,
29,
549,
430,
267,
291,
14,
1258,
275,
1218,
63,
27634,
305,
63,
1258,
8,
277,
14,
751,
9,
339,
768,
396,
272,
347,
511,
63,
2048,
63,
5087,
63,
4561,
8,
277,
304,
267,
340,
15869,
14,
3183,
63,
632,
26,
288,
746,
18795,
480,
18297,
642,
465,
1790,
365,
289,
16702,
15988,
2685,
267,
2933,
63,
815,
275,
291,
14,
1258,
14,
8370,
14,
2384,
8,
842,
63,
815,
14,
751,
14,
4647,
63,
344,
9,
267,
327,
7356,
1104,
314,
2058,
14,
267,
1420,
275,
1256,
63,
815,
14,
751,
14,
4647,
63,
344,
267,
340,
1420,
365,
488,
26,
288,
1420,
275,
298,
403,
2,
267,
870,
480,
2048,
63,
344,
14,
344,
275,
1543,
83,
4065,
450,
2933,
63,
815,
14,
344,
9,
267,
870,
480,
2062,
275,
1543,
83,
4065,
450,
1420,
9,
267,
702,
83,
14,
479,
63,
1452,
8,
2062,
12,
2933,
63,
815,
14,
344,
9,
267,
327,
10066,
83,
26,
2337,
1077,
737,
5210,
506,
1373,
1256,
267,
702,
83,
14,
479,
63,
2052,
8,
552,
8,
2048,
63,
815,
14,
842,
63,
1580,
9,
690,
378,
9,
267,
327,
710,
1256,
1305,
1077,
506,
1373,
402,
314,
4454,
367,
314,
2933,
267,
702,
83,
14,
479,
63,
2052,
8,
842,
63,
815,
14,
344,
315,
2933,
63,
815,
14,
842,
63,
1580,
9,
339,
768,
396,
272,
347,
511,
63,
513,
63,
8370,
8,
277,
304,
267,
340,
15869,
14,
3183,
63,
632,
26,
288,
746,
18795,
480,
18297,
642,
465,
1790,
365,
289,
16702,
15988,
2685,
267,
12639,
63,
815,
275,
291,
14,
1258,
14,
8370,
14,
1080,
342,
267,
702,
83,
14,
479,
63,
1452,
8,
17,
12,
822,
8,
8370,
63,
815,
14,
8370,
430,
267,
2933,
275,
12639,
63,
815,
14,
8370,
59,
16,
61,
267,
702,
83,
14,
479,
63,
2052,
8,
2048,
459,
1507,
63,
5990,
418,
690,
378,
9,
267,
702,
83,
14,
479,
63,
1452,
8,
842,
63,
815,
14,
751,
14,
4647,
63,
344,
12,
2933,
459,
344,
1105,
421,
199,
32,
396,
8,
2634,
1524,
2219,
14,
4030,
63,
7834,
879,
16734,
12,
15443,
467,
489,
8350,
63,
265,
63,
2634,
6270,
27634,
305,
14,
10409,
14,
8831,
3135,
199,
533,
4473,
6851,
10881,
3244,
3896,
296,
8,
785,
304,
339,
768,
5182,
63,
533,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
511,
63,
888,
14,
3707,
14,
1623,
63,
751,
8,
13902,
1470,
8,
374,
63,
2113,
29,
549,
430,
267,
291,
14,
1258,
275,
1218,
63,
27634,
305,
63,
1258,
8,
277,
14,
751,
9,
339,
768,
396,
272,
347,
511,
63,
842,
63,
344,
63,
10649,
63,
504,
63,
2048,
8,
277,
304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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
] |
piluke/BasicEventEngineFrontend
|
ui/eventdialog.py
|
1
|
1539
|
# Copyright (c) 2017-18 Luke Montalvo <lukemontalvo@gmail.com>
#
# This file is part of BEEF.
# BEEF is free software and comes with ABSOLUTELY NO WARANTY.
# See LICENSE for more details.
try:
import wx
except ImportError:
raise ImportError("The wxPython module is required to run this program")
from resources.enum import EEvent
class BEEFEventDialog(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self)
self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
self.Create(parent, -1, "New Event", wx.DefaultPosition, wx.DefaultSize, wx.DEFAULT_DIALOG_STYLE)
sizer = wx.BoxSizer(wx.VERTICAL)
label = wx.StaticText(self, -1, "Event Type:")
sizer.Add(label, 0, wx.ALL, 5)
self.list = wx.ListBox(self, -1, wx.DefaultPosition, wx.DefaultSize, EEvent._events)
self.list.SetSelection(1)
self.Bind(wx.EVT_LISTBOX_DCLICK, self.doubleClick, self.list)
sizer.Add(self.list, 0, wx.ALL, 5)
line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)
sizer.Add(line, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5)
buttons = wx.StdDialogButtonSizer()
btn = wx.Button(self, wx.ID_OK)
btn.SetDefault()
buttons.Add(btn)
btn = wx.Button(self, wx.ID_CANCEL)
buttons.Add(btn)
buttons.Realize()
sizer.Add(buttons, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
self.SetSizer(sizer)
sizer.Fit(self)
self.CenterOnScreen()
def doubleClick(self, event):
self.EndModal(wx.ID_OK)
def getEvent(self):
return self.list.GetSelection()
def getEventStr(self):
return EEvent.get(self.getEvent())
|
mit
|
[
3,
1898,
334,
67,
9,
9708,
13,
1085,
30936,
415,
603,
1888,
279,
2392,
665,
10836,
415,
77,
1888,
279,
2392,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
6262,
14153,
14,
199,
3,
6262,
14153,
365,
2867,
2032,
436,
12477,
543,
437,
11087,
2228,
934,
2901,
57,
4825,
13253,
1441,
57,
14,
199,
3,
1666,
5113,
367,
1655,
2436,
14,
199,
199,
893,
26,
199,
198,
646,
4818,
199,
2590,
3545,
26,
199,
198,
3730,
3545,
480,
1918,
4818,
4718,
859,
365,
1415,
370,
1255,
642,
2240,
531,
199,
199,
504,
5944,
14,
4869,
492,
662,
2390,
199,
199,
533,
6262,
14153,
2390,
5619,
8,
6323,
14,
5619,
304,
199,
198,
318,
636,
826,
721,
277,
12,
1676,
304,
507,
198,
6323,
14,
5619,
855,
826,
721,
277,
9,
507,
198,
277,
14,
1084,
7426,
6609,
8,
6323,
14,
1914,
23622,
63,
1438,
63,
9059,
17930,
9,
507,
198,
277,
14,
2499,
8,
1708,
12,
446,
17,
12,
298,
4665,
6763,
401,
4818,
14,
2698,
5625,
12,
4818,
14,
2698,
2320,
12,
4818,
14,
3472,
63,
1914,
23622,
63,
18466,
9,
2742,
198,
19158,
275,
4818,
14,
28072,
8,
6323,
14,
22634,
9,
2742,
198,
1302,
275,
4818,
14,
25289,
8,
277,
12,
446,
17,
12,
298,
2390,
2434,
9107,
507,
198,
19158,
14,
1123,
8,
1302,
12,
378,
12,
4818,
14,
1761,
12,
959,
9,
2742,
198,
277,
14,
513,
275,
4818,
14,
26764,
8,
277,
12,
446,
17,
12,
4818,
14,
2698,
5625,
12,
4818,
14,
2698,
2320,
12,
662,
2390,
423,
4368,
9,
507,
198,
277,
14,
513,
14,
1084,
7713,
8,
17,
9,
507,
198,
277,
14,
8198,
8,
6323,
14,
12093,
63,
4924,
15694,
63,
36,
1981,
13884,
12,
291,
14,
3157,
12040,
12,
291,
14,
513,
9,
507,
198,
19158,
14,
1123,
8,
277,
14,
513,
12,
378,
12,
4818,
14,
1761,
12,
959,
9,
2742,
198,
604,
275,
4818,
14,
9278,
3049,
8,
277,
12,
446,
17,
12,
3449,
29,
6323,
14,
2673,
63,
25968,
9,
507,
198,
19158,
14,
1123,
8,
604,
12,
378,
12,
4818,
14,
39,
11415,
1204,
4818,
14,
15255,
63,
17611,
63,
22634,
1204,
4818,
14,
12811,
1204,
4818,
14,
11422,
12,
959,
9,
2742,
198,
15687,
275,
4818,
14,
11976,
5619,
4259,
12017,
342,
507,
198,
9633,
275,
4818,
14,
4259,
8,
277,
12,
4818,
14,
998,
63,
3593,
9,
507,
198,
9633,
14,
1084,
2698,
342,
507,
198,
15687,
14,
1123,
8,
9633,
9,
2742,
198,
9633,
275,
4818,
14,
4259,
8,
277,
12,
4818,
14,
998,
63,
20707,
9,
507,
198,
15687,
14,
1123,
8,
9633,
9,
507,
198,
15687,
14,
10099,
794,
342,
507,
198,
19158,
14,
1123,
8,
15687,
12,
378,
12,
4818,
14,
15255,
63,
17611,
63,
22634,
1204,
4818,
14,
1761,
12,
959,
9,
2742,
198,
277,
14,
1084,
12017,
8,
19158,
9,
507,
198,
19158,
14,
13776,
8,
277,
9,
2742,
198,
277,
14,
13551,
3314,
9616,
342,
421,
198,
318,
4270,
12040,
8,
277,
12,
1566,
304,
507,
198,
277,
14,
3005,
23689,
8,
6323,
14,
998,
63,
3593,
9,
421,
198,
318,
664,
2390,
8,
277,
304,
507,
198,
1107,
291,
14,
513,
14,
1002,
7713,
342,
199,
198,
318,
664,
2390,
2848,
8,
277,
304,
507,
198,
1107,
662,
2390,
14,
362,
8,
277,
14,
362,
2390,
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
] |
[
1898,
334,
67,
9,
9708,
13,
1085,
30936,
415,
603,
1888,
279,
2392,
665,
10836,
415,
77,
1888,
279,
2392,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
6262,
14153,
14,
199,
3,
6262,
14153,
365,
2867,
2032,
436,
12477,
543,
437,
11087,
2228,
934,
2901,
57,
4825,
13253,
1441,
57,
14,
199,
3,
1666,
5113,
367,
1655,
2436,
14,
199,
199,
893,
26,
199,
198,
646,
4818,
199,
2590,
3545,
26,
199,
198,
3730,
3545,
480,
1918,
4818,
4718,
859,
365,
1415,
370,
1255,
642,
2240,
531,
199,
199,
504,
5944,
14,
4869,
492,
662,
2390,
199,
199,
533,
6262,
14153,
2390,
5619,
8,
6323,
14,
5619,
304,
199,
198,
318,
636,
826,
721,
277,
12,
1676,
304,
507,
198,
6323,
14,
5619,
855,
826,
721,
277,
9,
507,
198,
277,
14,
1084,
7426,
6609,
8,
6323,
14,
1914,
23622,
63,
1438,
63,
9059,
17930,
9,
507,
198,
277,
14,
2499,
8,
1708,
12,
446,
17,
12,
298,
4665,
6763,
401,
4818,
14,
2698,
5625,
12,
4818,
14,
2698,
2320,
12,
4818,
14,
3472,
63,
1914,
23622,
63,
18466,
9,
2742,
198,
19158,
275,
4818,
14,
28072,
8,
6323,
14,
22634,
9,
2742,
198,
1302,
275,
4818,
14,
25289,
8,
277,
12,
446,
17,
12,
298,
2390,
2434,
9107,
507,
198,
19158,
14,
1123,
8,
1302,
12,
378,
12,
4818,
14,
1761,
12,
959,
9,
2742,
198,
277,
14,
513,
275,
4818,
14,
26764,
8,
277,
12,
446,
17,
12,
4818,
14,
2698,
5625,
12,
4818,
14,
2698,
2320,
12,
662,
2390,
423,
4368,
9,
507,
198,
277,
14,
513,
14,
1084,
7713,
8,
17,
9,
507,
198,
277,
14,
8198,
8,
6323,
14,
12093,
63,
4924,
15694,
63,
36,
1981,
13884,
12,
291,
14,
3157,
12040,
12,
291,
14,
513,
9,
507,
198,
19158,
14,
1123,
8,
277,
14,
513,
12,
378,
12,
4818,
14,
1761,
12,
959,
9,
2742,
198,
604,
275,
4818,
14,
9278,
3049,
8,
277,
12,
446,
17,
12,
3449,
29,
6323,
14,
2673,
63,
25968,
9,
507,
198,
19158,
14,
1123,
8,
604,
12,
378,
12,
4818,
14,
39,
11415,
1204,
4818,
14,
15255,
63,
17611,
63,
22634,
1204,
4818,
14,
12811,
1204,
4818,
14,
11422,
12,
959,
9,
2742,
198,
15687,
275,
4818,
14,
11976,
5619,
4259,
12017,
342,
507,
198,
9633,
275,
4818,
14,
4259,
8,
277,
12,
4818,
14,
998,
63,
3593,
9,
507,
198,
9633,
14,
1084,
2698,
342,
507,
198,
15687,
14,
1123,
8,
9633,
9,
2742,
198,
9633,
275,
4818,
14,
4259,
8,
277,
12,
4818,
14,
998,
63,
20707,
9,
507,
198,
15687,
14,
1123,
8,
9633,
9,
507,
198,
15687,
14,
10099,
794,
342,
507,
198,
19158,
14,
1123,
8,
15687,
12,
378,
12,
4818,
14,
15255,
63,
17611,
63,
22634,
1204,
4818,
14,
1761,
12,
959,
9,
2742,
198,
277,
14,
1084,
12017,
8,
19158,
9,
507,
198,
19158,
14,
13776,
8,
277,
9,
2742,
198,
277,
14,
13551,
3314,
9616,
342,
421,
198,
318,
4270,
12040,
8,
277,
12,
1566,
304,
507,
198,
277,
14,
3005,
23689,
8,
6323,
14,
998,
63,
3593,
9,
421,
198,
318,
664,
2390,
8,
277,
304,
507,
198,
1107,
291,
14,
513,
14,
1002,
7713,
342,
199,
198,
318,
664,
2390,
2848,
8,
277,
304,
507,
198,
1107,
662,
2390,
14,
362,
8,
277,
14,
362,
2390,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mhaessig/servo
|
tests/wpt/css-tests/css21_dev/html4/reference/support/fonts/makegsubfonts.py
|
1616
|
14125
|
import os
import textwrap
from xml.etree import ElementTree
from fontTools.ttLib import TTFont, newTable
from fontTools.misc.psCharStrings import T2CharString
from fontTools.ttLib.tables.otTables import GSUB,\
ScriptList, ScriptRecord, Script, DefaultLangSys,\
FeatureList, FeatureRecord, Feature,\
LookupList, Lookup, AlternateSubst, SingleSubst
# paths
directory = os.path.dirname(__file__)
shellSourcePath = os.path.join(directory, "gsubtest-shell.ttx")
shellTempPath = os.path.join(directory, "gsubtest-shell.otf")
featureList = os.path.join(directory, "gsubtest-features.txt")
javascriptData = os.path.join(directory, "gsubtest-features.js")
outputPath = os.path.join(os.path.dirname(directory), "gsubtest-lookup%d")
baseCodepoint = 0xe000
# -------
# Features
# -------
f = open(featureList, "rb")
text = f.read()
f.close()
mapping = []
for line in text.splitlines():
line = line.strip()
if not line:
continue
if line.startswith("#"):
continue
# parse
values = line.split("\t")
tag = values.pop(0)
mapping.append(tag);
# --------
# Outlines
# --------
def addGlyphToCFF(glyphName=None, program=None, private=None, globalSubrs=None, charStringsIndex=None, topDict=None, charStrings=None):
charString = T2CharString(program=program, private=private, globalSubrs=globalSubrs)
charStringsIndex.append(charString)
glyphID = len(topDict.charset)
charStrings.charStrings[glyphName] = glyphID
topDict.charset.append(glyphName)
def makeLookup1():
# make a variation of the shell TTX data
f = open(shellSourcePath)
ttxData = f.read()
f.close()
ttxData = ttxData.replace("__familyName__", "gsubtest-lookup1")
tempShellSourcePath = shellSourcePath + ".temp"
f = open(tempShellSourcePath, "wb")
f.write(ttxData)
f.close()
# compile the shell
shell = TTFont(sfntVersion="OTTO")
shell.importXML(tempShellSourcePath)
shell.save(shellTempPath)
os.remove(tempShellSourcePath)
# load the shell
shell = TTFont(shellTempPath)
# grab the PASS and FAIL data
hmtx = shell["hmtx"]
glyphSet = shell.getGlyphSet()
failGlyph = glyphSet["F"]
failGlyph.decompile()
failGlyphProgram = list(failGlyph.program)
failGlyphMetrics = hmtx["F"]
passGlyph = glyphSet["P"]
passGlyph.decompile()
passGlyphProgram = list(passGlyph.program)
passGlyphMetrics = hmtx["P"]
# grab some tables
hmtx = shell["hmtx"]
cmap = shell["cmap"]
# start the glyph order
existingGlyphs = [".notdef", "space", "F", "P"]
glyphOrder = list(existingGlyphs)
# start the CFF
cff = shell["CFF "].cff
globalSubrs = cff.GlobalSubrs
topDict = cff.topDictIndex[0]
topDict.charset = existingGlyphs
private = topDict.Private
charStrings = topDict.CharStrings
charStringsIndex = charStrings.charStringsIndex
features = sorted(mapping)
# build the outline, hmtx and cmap data
cp = baseCodepoint
for index, tag in enumerate(features):
# tag.pass
glyphName = "%s.pass" % tag
glyphOrder.append(glyphName)
addGlyphToCFF(
glyphName=glyphName,
program=passGlyphProgram,
private=private,
globalSubrs=globalSubrs,
charStringsIndex=charStringsIndex,
topDict=topDict,
charStrings=charStrings
)
hmtx[glyphName] = passGlyphMetrics
for table in cmap.tables:
if table.format == 4:
table.cmap[cp] = glyphName
else:
raise NotImplementedError, "Unsupported cmap table format: %d" % table.format
cp += 1
# tag.fail
glyphName = "%s.fail" % tag
glyphOrder.append(glyphName)
addGlyphToCFF(
glyphName=glyphName,
program=failGlyphProgram,
private=private,
globalSubrs=globalSubrs,
charStringsIndex=charStringsIndex,
topDict=topDict,
charStrings=charStrings
)
hmtx[glyphName] = failGlyphMetrics
for table in cmap.tables:
if table.format == 4:
table.cmap[cp] = glyphName
else:
raise NotImplementedError, "Unsupported cmap table format: %d" % table.format
# bump this up so that the sequence is the same as the lookup 3 font
cp += 3
# set the glyph order
shell.setGlyphOrder(glyphOrder)
# start the GSUB
shell["GSUB"] = newTable("GSUB")
gsub = shell["GSUB"].table = GSUB()
gsub.Version = 1.0
# make a list of all the features we will make
featureCount = len(features)
# set up the script list
scriptList = gsub.ScriptList = ScriptList()
scriptList.ScriptCount = 1
scriptList.ScriptRecord = []
scriptRecord = ScriptRecord()
scriptList.ScriptRecord.append(scriptRecord)
scriptRecord.ScriptTag = "DFLT"
script = scriptRecord.Script = Script()
defaultLangSys = script.DefaultLangSys = DefaultLangSys()
defaultLangSys.FeatureCount = featureCount
defaultLangSys.FeatureIndex = range(defaultLangSys.FeatureCount)
defaultLangSys.ReqFeatureIndex = 65535
defaultLangSys.LookupOrder = None
script.LangSysCount = 0
script.LangSysRecord = []
# set up the feature list
featureList = gsub.FeatureList = FeatureList()
featureList.FeatureCount = featureCount
featureList.FeatureRecord = []
for index, tag in enumerate(features):
# feature record
featureRecord = FeatureRecord()
featureRecord.FeatureTag = tag
feature = featureRecord.Feature = Feature()
featureList.FeatureRecord.append(featureRecord)
# feature
feature.FeatureParams = None
feature.LookupCount = 1
feature.LookupListIndex = [index]
# write the lookups
lookupList = gsub.LookupList = LookupList()
lookupList.LookupCount = featureCount
lookupList.Lookup = []
for tag in features:
# lookup
lookup = Lookup()
lookup.LookupType = 1
lookup.LookupFlag = 0
lookup.SubTableCount = 1
lookup.SubTable = []
lookupList.Lookup.append(lookup)
# subtable
subtable = SingleSubst()
subtable.Format = 2
subtable.LookupType = 1
subtable.mapping = {
"%s.pass" % tag : "%s.fail" % tag,
"%s.fail" % tag : "%s.pass" % tag,
}
lookup.SubTable.append(subtable)
path = outputPath % 1 + ".otf"
if os.path.exists(path):
os.remove(path)
shell.save(path)
# get rid of the shell
if os.path.exists(shellTempPath):
os.remove(shellTempPath)
def makeLookup3():
# make a variation of the shell TTX data
f = open(shellSourcePath)
ttxData = f.read()
f.close()
ttxData = ttxData.replace("__familyName__", "gsubtest-lookup3")
tempShellSourcePath = shellSourcePath + ".temp"
f = open(tempShellSourcePath, "wb")
f.write(ttxData)
f.close()
# compile the shell
shell = TTFont(sfntVersion="OTTO")
shell.importXML(tempShellSourcePath)
shell.save(shellTempPath)
os.remove(tempShellSourcePath)
# load the shell
shell = TTFont(shellTempPath)
# grab the PASS and FAIL data
hmtx = shell["hmtx"]
glyphSet = shell.getGlyphSet()
failGlyph = glyphSet["F"]
failGlyph.decompile()
failGlyphProgram = list(failGlyph.program)
failGlyphMetrics = hmtx["F"]
passGlyph = glyphSet["P"]
passGlyph.decompile()
passGlyphProgram = list(passGlyph.program)
passGlyphMetrics = hmtx["P"]
# grab some tables
hmtx = shell["hmtx"]
cmap = shell["cmap"]
# start the glyph order
existingGlyphs = [".notdef", "space", "F", "P"]
glyphOrder = list(existingGlyphs)
# start the CFF
cff = shell["CFF "].cff
globalSubrs = cff.GlobalSubrs
topDict = cff.topDictIndex[0]
topDict.charset = existingGlyphs
private = topDict.Private
charStrings = topDict.CharStrings
charStringsIndex = charStrings.charStringsIndex
features = sorted(mapping)
# build the outline, hmtx and cmap data
cp = baseCodepoint
for index, tag in enumerate(features):
# tag.pass
glyphName = "%s.pass" % tag
glyphOrder.append(glyphName)
addGlyphToCFF(
glyphName=glyphName,
program=passGlyphProgram,
private=private,
globalSubrs=globalSubrs,
charStringsIndex=charStringsIndex,
topDict=topDict,
charStrings=charStrings
)
hmtx[glyphName] = passGlyphMetrics
# tag.fail
glyphName = "%s.fail" % tag
glyphOrder.append(glyphName)
addGlyphToCFF(
glyphName=glyphName,
program=failGlyphProgram,
private=private,
globalSubrs=globalSubrs,
charStringsIndex=charStringsIndex,
topDict=topDict,
charStrings=charStrings
)
hmtx[glyphName] = failGlyphMetrics
# tag.default
glyphName = "%s.default" % tag
glyphOrder.append(glyphName)
addGlyphToCFF(
glyphName=glyphName,
program=passGlyphProgram,
private=private,
globalSubrs=globalSubrs,
charStringsIndex=charStringsIndex,
topDict=topDict,
charStrings=charStrings
)
hmtx[glyphName] = passGlyphMetrics
for table in cmap.tables:
if table.format == 4:
table.cmap[cp] = glyphName
else:
raise NotImplementedError, "Unsupported cmap table format: %d" % table.format
cp += 1
# tag.alt1,2,3
for i in range(1,4):
glyphName = "%s.alt%d" % (tag, i)
glyphOrder.append(glyphName)
addGlyphToCFF(
glyphName=glyphName,
program=failGlyphProgram,
private=private,
globalSubrs=globalSubrs,
charStringsIndex=charStringsIndex,
topDict=topDict,
charStrings=charStrings
)
hmtx[glyphName] = failGlyphMetrics
for table in cmap.tables:
if table.format == 4:
table.cmap[cp] = glyphName
else:
raise NotImplementedError, "Unsupported cmap table format: %d" % table.format
cp += 1
# set the glyph order
shell.setGlyphOrder(glyphOrder)
# start the GSUB
shell["GSUB"] = newTable("GSUB")
gsub = shell["GSUB"].table = GSUB()
gsub.Version = 1.0
# make a list of all the features we will make
featureCount = len(features)
# set up the script list
scriptList = gsub.ScriptList = ScriptList()
scriptList.ScriptCount = 1
scriptList.ScriptRecord = []
scriptRecord = ScriptRecord()
scriptList.ScriptRecord.append(scriptRecord)
scriptRecord.ScriptTag = "DFLT"
script = scriptRecord.Script = Script()
defaultLangSys = script.DefaultLangSys = DefaultLangSys()
defaultLangSys.FeatureCount = featureCount
defaultLangSys.FeatureIndex = range(defaultLangSys.FeatureCount)
defaultLangSys.ReqFeatureIndex = 65535
defaultLangSys.LookupOrder = None
script.LangSysCount = 0
script.LangSysRecord = []
# set up the feature list
featureList = gsub.FeatureList = FeatureList()
featureList.FeatureCount = featureCount
featureList.FeatureRecord = []
for index, tag in enumerate(features):
# feature record
featureRecord = FeatureRecord()
featureRecord.FeatureTag = tag
feature = featureRecord.Feature = Feature()
featureList.FeatureRecord.append(featureRecord)
# feature
feature.FeatureParams = None
feature.LookupCount = 1
feature.LookupListIndex = [index]
# write the lookups
lookupList = gsub.LookupList = LookupList()
lookupList.LookupCount = featureCount
lookupList.Lookup = []
for tag in features:
# lookup
lookup = Lookup()
lookup.LookupType = 3
lookup.LookupFlag = 0
lookup.SubTableCount = 1
lookup.SubTable = []
lookupList.Lookup.append(lookup)
# subtable
subtable = AlternateSubst()
subtable.Format = 1
subtable.LookupType = 3
subtable.alternates = {
"%s.default" % tag : ["%s.fail" % tag, "%s.fail" % tag, "%s.fail" % tag],
"%s.alt1" % tag : ["%s.pass" % tag, "%s.fail" % tag, "%s.fail" % tag],
"%s.alt2" % tag : ["%s.fail" % tag, "%s.pass" % tag, "%s.fail" % tag],
"%s.alt3" % tag : ["%s.fail" % tag, "%s.fail" % tag, "%s.pass" % tag]
}
lookup.SubTable.append(subtable)
path = outputPath % 3 + ".otf"
if os.path.exists(path):
os.remove(path)
shell.save(path)
# get rid of the shell
if os.path.exists(shellTempPath):
os.remove(shellTempPath)
def makeJavascriptData():
features = sorted(mapping)
outStr = []
outStr.append("")
outStr.append("/* This file is autogenerated by makegsubfonts.py */")
outStr.append("")
outStr.append("/* ")
outStr.append(" Features defined in gsubtest fonts with associated base")
outStr.append(" codepoints for each feature:")
outStr.append("")
outStr.append(" cp = codepoint for feature featX")
outStr.append("")
outStr.append(" cp default PASS")
outStr.append(" cp featX=1 FAIL")
outStr.append(" cp featX=2 FAIL")
outStr.append("")
outStr.append(" cp+1 default FAIL")
outStr.append(" cp+1 featX=1 PASS")
outStr.append(" cp+1 featX=2 FAIL")
outStr.append("")
outStr.append(" cp+2 default FAIL")
outStr.append(" cp+2 featX=1 FAIL")
outStr.append(" cp+2 featX=2 PASS")
outStr.append("")
outStr.append("*/")
outStr.append("")
outStr.append("var gFeatures = {");
cp = baseCodepoint
taglist = []
for tag in features:
taglist.append("\"%s\": 0x%x" % (tag, cp))
cp += 4
outStr.append(textwrap.fill(", ".join(taglist), initial_indent=" ", subsequent_indent=" "))
outStr.append("};");
outStr.append("");
if os.path.exists(javascriptData):
os.remove(javascriptData)
f = open(javascriptData, "wb")
f.write("\n".join(outStr))
f.close()
# build fonts
print "Making lookup type 1 font..."
makeLookup1()
print "Making lookup type 3 font..."
makeLookup3()
# output javascript data
print "Making javascript data file..."
makeJavascriptData()
|
mpl-2.0
|
[
199,
646,
747,
199,
646,
13390,
199,
504,
2748,
14,
9464,
492,
13139,
199,
504,
5023,
11654,
14,
6215,
4728,
492,
377,
6145,
1888,
12,
892,
3186,
199,
504,
5023,
11654,
14,
9923,
14,
1190,
1610,
12672,
492,
377,
18,
1610,
1558,
199,
504,
5023,
11654,
14,
6215,
4728,
14,
5987,
14,
357,
18845,
492,
598,
6348,
4202,
272,
14914,
1296,
12,
14914,
5433,
12,
14914,
12,
3758,
14654,
11319,
4202,
272,
13407,
1296,
12,
13407,
5433,
12,
13407,
4202,
272,
12785,
1296,
12,
12785,
12,
17669,
323,
2610,
270,
12,
13050,
2610,
270,
199,
199,
3,
3792,
199,
3619,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
5641,
2980,
2042,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
298,
458,
456,
396,
13,
5641,
14,
84,
2347,
531,
199,
5641,
6530,
2042,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
298,
458,
456,
396,
13,
5641,
14,
357,
70,
531,
199,
4445,
1296,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
298,
458,
456,
396,
13,
3179,
14,
2424,
531,
199,
9554,
1451,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
298,
458,
456,
396,
13,
3179,
14,
3596,
531,
199,
1199,
2042,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
3619,
395,
298,
458,
456,
396,
13,
3892,
5,
68,
531,
199,
199,
1095,
3034,
1403,
275,
378,
1845,
1493,
199,
199,
3,
5514,
199,
3,
7949,
2093,
199,
3,
5514,
199,
199,
70,
275,
1551,
8,
4445,
1296,
12,
298,
4848,
531,
199,
505,
275,
289,
14,
739,
342,
199,
70,
14,
1600,
342,
199,
4745,
275,
942,
199,
509,
1004,
315,
1318,
14,
7644,
837,
272,
1004,
275,
1004,
14,
1913,
342,
272,
340,
440,
1004,
26,
267,
1980,
272,
340,
1004,
14,
2460,
10064,
2349,
267,
1980,
272,
327,
2198,
272,
1338,
275,
1004,
14,
1294,
4582,
84,
531,
272,
1947,
275,
1338,
14,
1935,
8,
16,
9,
272,
4412,
14,
740,
8,
1450,
2736,
199,
199,
3,
3001,
199,
3,
6219,
1278,
199,
3,
3001,
199,
199,
318,
1050,
15533,
1378,
35,
1665,
8,
26768,
29,
403,
12,
2240,
29,
403,
12,
5726,
29,
403,
12,
2288,
2610,
2393,
29,
403,
12,
1495,
12672,
2681,
29,
403,
12,
2746,
2141,
29,
403,
12,
1495,
12672,
29,
403,
304,
272,
1495,
1558,
275,
377,
18,
1610,
1558,
8,
6815,
29,
6815,
12,
5726,
29,
4239,
12,
2288,
2610,
2393,
29,
2966,
2610,
2393,
9,
272,
1495,
12672,
2681,
14,
740,
8,
1560,
1558,
9,
272,
14165,
998,
275,
822,
8,
2119,
2141,
14,
6043,
9,
272,
1495,
12672,
14,
1560,
12672,
59,
26768,
61,
275,
14165,
998,
272,
2746,
2141,
14,
6043,
14,
740,
8,
26768,
9,
199,
199,
318,
1852,
7521,
17,
837,
272,
327,
1852,
282,
29844,
402,
314,
5218,
377,
10051,
666,
272,
289,
275,
1551,
8,
5641,
2980,
2042,
9,
272,
307,
2347,
1451,
275,
289,
14,
739,
342,
272,
289,
14,
1600,
342,
272,
307,
2347,
1451,
275,
307,
2347,
1451,
14,
1814,
16232,
6606,
985,
13915,
298,
458,
456,
396,
13,
3892,
17,
531,
272,
2388,
8529,
2980,
2042,
275,
5218,
2980,
2042,
435,
3680,
808,
2,
272,
289,
275,
1551,
8,
808,
8529,
2980,
2042,
12,
298,
6603,
531,
272,
289,
14,
952,
8,
84,
2347,
1451,
9,
272,
289,
14,
1600,
342,
339,
327,
6555,
314,
5218,
272,
5218,
275,
377,
6145,
1888,
8,
7646,
343,
3353,
628,
1387,
2566,
531,
272,
5218,
14,
646,
4317,
8,
808,
8529,
2980,
2042,
9,
272,
5218,
14,
2117,
8,
5641,
6530,
2042,
9,
272,
747,
14,
2168,
8,
808,
8529,
2980,
2042,
9,
339,
327,
2248,
314,
5218,
272,
5218,
275,
377,
6145,
1888,
8,
5641,
6530,
2042,
9,
339,
327,
18200,
314,
21705,
436,
10341,
666,
272,
394,
26029,
275,
5218,
905,
72,
26029,
937,
272,
14165,
1084,
275,
5218,
14,
362,
15533,
1084,
342,
339,
2449,
15533,
275,
14165,
1084,
905,
38,
937,
272,
2449,
15533,
14,
271,
2014,
342,
272,
2449,
15533,
9184,
275,
769,
8,
1633,
15533,
14,
6815,
9,
272,
2449,
15533,
17213,
275,
394,
26029,
905,
38,
937,
339,
986,
15533,
275,
14165,
1084,
905,
48,
937,
272,
986,
15533,
14,
271,
2014,
342,
272,
986,
15533,
9184,
275,
769,
8,
1529,
15533,
14,
6815,
9,
272,
986,
15533,
17213,
275,
394,
26029,
905,
48,
937,
339,
327,
18200,
2005,
6716,
272,
394,
26029,
275,
5218,
905,
72,
26029,
937,
272,
14920,
275,
5218,
905,
16513,
937,
339,
327,
1343,
314,
14165,
1865,
272,
3411,
15533,
83,
275,
359,
1674,
1397,
318,
401,
298,
2638,
401,
298,
38,
401,
298,
48,
937,
272,
14165,
4738,
275,
769,
8,
5952,
15533,
83,
9,
339,
327,
1343,
314,
445,
1665,
272,
286,
556,
275,
5218,
905,
35,
1665,
298,
1055,
28667,
272,
2288,
2610,
2393,
275,
286,
556,
14,
7025,
2610,
2393,
272,
2746,
2141,
275,
286,
556,
14,
2119,
2141,
2681,
59,
16,
61,
272,
2746,
2141,
14,
6043,
275,
3411,
15533,
83,
272,
5726,
275,
2746,
2141,
14,
12185,
272,
1495,
12672,
275,
2746,
2141,
14,
1610,
12672,
272,
1495,
12672,
2681,
275,
1495,
12672,
14,
1560,
12672,
2681,
339,
4534,
275,
3355,
8,
4745,
9,
339,
327,
1900,
314,
17964,
12,
394,
26029,
436,
14920,
666,
272,
7667,
275,
1300,
3034,
1403,
272,
367,
1478,
12,
1947,
315,
3874,
8,
3179,
304,
10813,
198,
3,
1947,
14,
1529,
1362,
198,
26768,
275,
2071,
83,
14,
1529,
2,
450,
1947,
1362,
198,
13723,
4738,
14,
740,
8,
26768,
9,
1362,
198,
525,
15533,
1378,
35,
1665,
8,
19066,
198,
26768,
29,
26768,
12,
19066,
198,
6815,
29,
1529,
15533,
9184,
12,
19066,
198,
4239,
29,
4239,
12,
19066,
198,
2966,
2610,
2393,
29,
2966,
2610,
2393,
12,
19066,
198,
1560,
12672,
2681,
29,
1560,
12672,
2681,
12,
19066,
198,
2119,
2141,
29,
2119,
2141,
12,
288,
1495,
12672,
29,
1560,
12672,
1362,
198,
9,
1362,
198,
72,
26029,
59,
26768,
61,
275,
986,
15533,
17213,
10813,
198,
509,
1817,
315,
14920,
14,
5987,
26,
19066,
198,
692,
1817,
14,
908,
508,
841,
26,
1362,
1057,
198,
1224,
14,
16513,
59,
1850,
61,
275,
14165,
985,
19066
] |
[
646,
747,
199,
646,
13390,
199,
504,
2748,
14,
9464,
492,
13139,
199,
504,
5023,
11654,
14,
6215,
4728,
492,
377,
6145,
1888,
12,
892,
3186,
199,
504,
5023,
11654,
14,
9923,
14,
1190,
1610,
12672,
492,
377,
18,
1610,
1558,
199,
504,
5023,
11654,
14,
6215,
4728,
14,
5987,
14,
357,
18845,
492,
598,
6348,
4202,
272,
14914,
1296,
12,
14914,
5433,
12,
14914,
12,
3758,
14654,
11319,
4202,
272,
13407,
1296,
12,
13407,
5433,
12,
13407,
4202,
272,
12785,
1296,
12,
12785,
12,
17669,
323,
2610,
270,
12,
13050,
2610,
270,
199,
199,
3,
3792,
199,
3619,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
5641,
2980,
2042,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
298,
458,
456,
396,
13,
5641,
14,
84,
2347,
531,
199,
5641,
6530,
2042,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
298,
458,
456,
396,
13,
5641,
14,
357,
70,
531,
199,
4445,
1296,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
298,
458,
456,
396,
13,
3179,
14,
2424,
531,
199,
9554,
1451,
275,
747,
14,
515,
14,
904,
8,
3619,
12,
298,
458,
456,
396,
13,
3179,
14,
3596,
531,
199,
1199,
2042,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
3619,
395,
298,
458,
456,
396,
13,
3892,
5,
68,
531,
199,
199,
1095,
3034,
1403,
275,
378,
1845,
1493,
199,
199,
3,
5514,
199,
3,
7949,
2093,
199,
3,
5514,
199,
199,
70,
275,
1551,
8,
4445,
1296,
12,
298,
4848,
531,
199,
505,
275,
289,
14,
739,
342,
199,
70,
14,
1600,
342,
199,
4745,
275,
942,
199,
509,
1004,
315,
1318,
14,
7644,
837,
272,
1004,
275,
1004,
14,
1913,
342,
272,
340,
440,
1004,
26,
267,
1980,
272,
340,
1004,
14,
2460,
10064,
2349,
267,
1980,
272,
327,
2198,
272,
1338,
275,
1004,
14,
1294,
4582,
84,
531,
272,
1947,
275,
1338,
14,
1935,
8,
16,
9,
272,
4412,
14,
740,
8,
1450,
2736,
199,
199,
3,
3001,
199,
3,
6219,
1278,
199,
3,
3001,
199,
199,
318,
1050,
15533,
1378,
35,
1665,
8,
26768,
29,
403,
12,
2240,
29,
403,
12,
5726,
29,
403,
12,
2288,
2610,
2393,
29,
403,
12,
1495,
12672,
2681,
29,
403,
12,
2746,
2141,
29,
403,
12,
1495,
12672,
29,
403,
304,
272,
1495,
1558,
275,
377,
18,
1610,
1558,
8,
6815,
29,
6815,
12,
5726,
29,
4239,
12,
2288,
2610,
2393,
29,
2966,
2610,
2393,
9,
272,
1495,
12672,
2681,
14,
740,
8,
1560,
1558,
9,
272,
14165,
998,
275,
822,
8,
2119,
2141,
14,
6043,
9,
272,
1495,
12672,
14,
1560,
12672,
59,
26768,
61,
275,
14165,
998,
272,
2746,
2141,
14,
6043,
14,
740,
8,
26768,
9,
199,
199,
318,
1852,
7521,
17,
837,
272,
327,
1852,
282,
29844,
402,
314,
5218,
377,
10051,
666,
272,
289,
275,
1551,
8,
5641,
2980,
2042,
9,
272,
307,
2347,
1451,
275,
289,
14,
739,
342,
272,
289,
14,
1600,
342,
272,
307,
2347,
1451,
275,
307,
2347,
1451,
14,
1814,
16232,
6606,
985,
13915,
298,
458,
456,
396,
13,
3892,
17,
531,
272,
2388,
8529,
2980,
2042,
275,
5218,
2980,
2042,
435,
3680,
808,
2,
272,
289,
275,
1551,
8,
808,
8529,
2980,
2042,
12,
298,
6603,
531,
272,
289,
14,
952,
8,
84,
2347,
1451,
9,
272,
289,
14,
1600,
342,
339,
327,
6555,
314,
5218,
272,
5218,
275,
377,
6145,
1888,
8,
7646,
343,
3353,
628,
1387,
2566,
531,
272,
5218,
14,
646,
4317,
8,
808,
8529,
2980,
2042,
9,
272,
5218,
14,
2117,
8,
5641,
6530,
2042,
9,
272,
747,
14,
2168,
8,
808,
8529,
2980,
2042,
9,
339,
327,
2248,
314,
5218,
272,
5218,
275,
377,
6145,
1888,
8,
5641,
6530,
2042,
9,
339,
327,
18200,
314,
21705,
436,
10341,
666,
272,
394,
26029,
275,
5218,
905,
72,
26029,
937,
272,
14165,
1084,
275,
5218,
14,
362,
15533,
1084,
342,
339,
2449,
15533,
275,
14165,
1084,
905,
38,
937,
272,
2449,
15533,
14,
271,
2014,
342,
272,
2449,
15533,
9184,
275,
769,
8,
1633,
15533,
14,
6815,
9,
272,
2449,
15533,
17213,
275,
394,
26029,
905,
38,
937,
339,
986,
15533,
275,
14165,
1084,
905,
48,
937,
272,
986,
15533,
14,
271,
2014,
342,
272,
986,
15533,
9184,
275,
769,
8,
1529,
15533,
14,
6815,
9,
272,
986,
15533,
17213,
275,
394,
26029,
905,
48,
937,
339,
327,
18200,
2005,
6716,
272,
394,
26029,
275,
5218,
905,
72,
26029,
937,
272,
14920,
275,
5218,
905,
16513,
937,
339,
327,
1343,
314,
14165,
1865,
272,
3411,
15533,
83,
275,
359,
1674,
1397,
318,
401,
298,
2638,
401,
298,
38,
401,
298,
48,
937,
272,
14165,
4738,
275,
769,
8,
5952,
15533,
83,
9,
339,
327,
1343,
314,
445,
1665,
272,
286,
556,
275,
5218,
905,
35,
1665,
298,
1055,
28667,
272,
2288,
2610,
2393,
275,
286,
556,
14,
7025,
2610,
2393,
272,
2746,
2141,
275,
286,
556,
14,
2119,
2141,
2681,
59,
16,
61,
272,
2746,
2141,
14,
6043,
275,
3411,
15533,
83,
272,
5726,
275,
2746,
2141,
14,
12185,
272,
1495,
12672,
275,
2746,
2141,
14,
1610,
12672,
272,
1495,
12672,
2681,
275,
1495,
12672,
14,
1560,
12672,
2681,
339,
4534,
275,
3355,
8,
4745,
9,
339,
327,
1900,
314,
17964,
12,
394,
26029,
436,
14920,
666,
272,
7667,
275,
1300,
3034,
1403,
272,
367,
1478,
12,
1947,
315,
3874,
8,
3179,
304,
10813,
198,
3,
1947,
14,
1529,
1362,
198,
26768,
275,
2071,
83,
14,
1529,
2,
450,
1947,
1362,
198,
13723,
4738,
14,
740,
8,
26768,
9,
1362,
198,
525,
15533,
1378,
35,
1665,
8,
19066,
198,
26768,
29,
26768,
12,
19066,
198,
6815,
29,
1529,
15533,
9184,
12,
19066,
198,
4239,
29,
4239,
12,
19066,
198,
2966,
2610,
2393,
29,
2966,
2610,
2393,
12,
19066,
198,
1560,
12672,
2681,
29,
1560,
12672,
2681,
12,
19066,
198,
2119,
2141,
29,
2119,
2141,
12,
288,
1495,
12672,
29,
1560,
12672,
1362,
198,
9,
1362,
198,
72,
26029,
59,
26768,
61,
275,
986,
15533,
17213,
10813,
198,
509,
1817,
315,
14920,
14,
5987,
26,
19066,
198,
692,
1817,
14,
908,
508,
841,
26,
1362,
1057,
198,
1224,
14,
16513,
59,
1850,
61,
275,
14165,
985,
19066,
0
] |
[
1,
1,
1,
1,
1,
1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wts/tests/csp/csp_font-src_none_blocked_int-manual.py
|
30
|
2712
|
def main(request, response):
import simplejson as json
f = file('config.json')
source = f.read()
s = json.JSONDecoder().decode(source)
url1 = "http://" + s['host'] + ":" + str(s['ports']['http'][1])
url2 = "http://" + s['host'] + ":" + str(s['ports']['http'][0])
response.headers.set("Content-Security-Policy", "font-src 'none'")
response.headers.set("X-Content-Security-Policy", "font-src 'none'")
response.headers.set("X-WebKit-CSP", "font-src 'none'")
return """<!DOCTYPE html>
<!--
Copyright (c) 2013 Intel Corporation.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of works must retain the original copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the original copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this work without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors:
Hao, Yunfei <yunfeix.hao@intel.com>
-->
<html>
<head>
<title>CSP Test: csp_font-src_none_blocked_int</title>
<link rel="author" title="Intel" href="http://www.intel.com"/>
<link rel="help" href="http://www.w3.org/TR/2012/CR-CSP-20121115/#font-src"/>
<meta name="flags" content=""/>
<meta name="assert" content="font-src 'none'"/>
<meta charset="utf-8"/>
<style>
@font-face {
font-family: Canvas;
src: url("support/w3c/CanvasTest.ttf");
}
#test {
font-family: Canvas;
}
</style>
</head>
<body>
<p>Test passes if the two lines are the same in font</p>
<div id="test">1234 ABCD</div>
<div>1234 ABCD</div>
</body>
</html> """
|
bsd-3-clause
|
[
318,
2446,
8,
1069,
12,
1177,
304,
272,
492,
13804,
465,
2022,
272,
289,
275,
570,
360,
888,
14,
1001,
358,
272,
1350,
275,
289,
14,
739,
342,
272,
308,
275,
2022,
14,
6243,
8326,
1252,
2708,
8,
1365,
9,
272,
1166,
17,
275,
298,
1014,
30443,
435,
308,
459,
1102,
418,
435,
14725,
435,
620,
8,
83,
459,
5203,
2545,
1014,
3488,
17,
566,
272,
1166,
18,
275,
298,
1014,
30443,
435,
308,
459,
1102,
418,
435,
14725,
435,
620,
8,
83,
459,
5203,
2545,
1014,
3488,
16,
566,
272,
1177,
14,
2139,
14,
409,
480,
2714,
13,
7676,
13,
4845,
401,
298,
4246,
13,
2164,
283,
3592,
9859,
272,
1177,
14,
2139,
14,
409,
480,
56,
13,
2714,
13,
7676,
13,
4845,
401,
298,
4246,
13,
2164,
283,
3592,
9859,
272,
1177,
14,
2139,
14,
409,
480,
56,
13,
21666,
13,
30635,
401,
298,
4246,
13,
2164,
283,
3592,
9859,
272,
372,
8894,
1,
16556,
3517,
30,
199,
25273,
199,
7384,
334,
67,
9,
6171,
20619,
11098,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
1530,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
199,
10,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
769,
523,
402,
3704,
436,
314,
2569,
6450,
14,
199,
10,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
4248,
4245,
12,
523,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
523,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
10,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
523,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
523,
2488,
6791,
5313,
4983,
14,
199,
199,
24571,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3649,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
8947,
5177,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
8693,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
568,
6098,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
12728,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3998,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3359,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
6388,
9179,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
37,
8253,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
2817,
1384,
26,
267,
869,
8035,
12,
1488,
324,
771,
73,
665,
89,
324,
771,
1148,
14,
2411,
79,
32,
22264,
14,
957,
30,
199,
199,
31647,
199,
199,
28,
1360,
30,
523,
665,
2993,
30,
272,
665,
1213,
30,
30635,
1379,
26,
286,
681,
63,
4246,
13,
2164,
63,
3592,
63,
17726,
63,
442,
1108,
1213,
30,
272,
665,
1073,
4668,
628,
2502,
2,
2538,
628,
27528,
2,
4369,
628,
1014,
921,
1544,
14,
22264,
14,
957,
7897,
272,
665,
1073,
4668,
628,
3437,
2,
4369,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
7409,
15,
2944,
13,
30635,
13,
7409,
845,
1046,
12645,
4246,
13,
2164,
7897,
272,
665,
2024,
536,
628,
2469,
2,
1564,
9287,
3133,
272,
665,
2024,
536,
628,
479,
2,
1564,
628,
4246,
13,
2164,
283,
3592,
4065,
3133,
272,
665,
2024,
5960,
628,
1624,
13,
24,
7897,
272,
665,
2487,
30,
267,
768,
4246,
13,
1409,
469,
288,
5023,
13,
6606,
26,
29349,
27,
288,
2928,
26,
1166,
480,
4058,
15,
87,
19,
67,
15,
15174,
774,
14,
32264,
3547,
267,
789,
267,
327,
396,
469,
288,
5023,
13,
6606,
26,
29349,
27,
267,
789,
272,
3068,
2487,
30,
523,
3068,
2993,
30,
523,
665,
2030,
30,
272,
665,
80,
30,
774,
14933,
340,
314,
2877,
2385,
787,
314,
2011,
315,
5023,
1108,
80,
30,
272,
665,
3015,
1305,
628,
396,
1743,
4321,
17281,
36,
1108,
3015,
30,
272,
665,
3015,
30,
4321,
17281,
36,
1108,
3015,
30,
199,
3068,
2030,
30,
199,
1108,
1360,
30,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2446,
8,
1069,
12,
1177,
304,
272,
492,
13804,
465,
2022,
272,
289,
275,
570,
360,
888,
14,
1001,
358,
272,
1350,
275,
289,
14,
739,
342,
272,
308,
275,
2022,
14,
6243,
8326,
1252,
2708,
8,
1365,
9,
272,
1166,
17,
275,
298,
1014,
30443,
435,
308,
459,
1102,
418,
435,
14725,
435,
620,
8,
83,
459,
5203,
2545,
1014,
3488,
17,
566,
272,
1166,
18,
275,
298,
1014,
30443,
435,
308,
459,
1102,
418,
435,
14725,
435,
620,
8,
83,
459,
5203,
2545,
1014,
3488,
16,
566,
272,
1177,
14,
2139,
14,
409,
480,
2714,
13,
7676,
13,
4845,
401,
298,
4246,
13,
2164,
283,
3592,
9859,
272,
1177,
14,
2139,
14,
409,
480,
56,
13,
2714,
13,
7676,
13,
4845,
401,
298,
4246,
13,
2164,
283,
3592,
9859,
272,
1177,
14,
2139,
14,
409,
480,
56,
13,
21666,
13,
30635,
401,
298,
4246,
13,
2164,
283,
3592,
9859,
272,
372,
8894,
1,
16556,
3517,
30,
199,
25273,
199,
7384,
334,
67,
9,
6171,
20619,
11098,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
1530,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
199,
10,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
769,
523,
402,
3704,
436,
314,
2569,
6450,
14,
199,
10,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
4248,
4245,
12,
523,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
523,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
10,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
523,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
523,
2488,
6791,
5313,
4983,
14,
199,
199,
24571,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3649,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
8947,
5177,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
8693,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
568,
6098,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
12728,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3998,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3359,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
6388,
9179,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
37,
8253,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
2817,
1384,
26,
267,
869,
8035,
12,
1488,
324,
771,
73,
665,
89,
324,
771,
1148,
14,
2411,
79,
32,
22264,
14,
957,
30,
199,
199,
31647,
199,
199,
28,
1360,
30,
523,
665,
2993,
30,
272,
665,
1213,
30,
30635,
1379,
26,
286,
681,
63,
4246,
13,
2164,
63,
3592,
63,
17726,
63,
442,
1108,
1213,
30,
272,
665,
1073,
4668,
628,
2502,
2,
2538,
628,
27528,
2,
4369,
628,
1014,
921,
1544,
14,
22264,
14,
957,
7897,
272,
665,
1073,
4668,
628,
3437,
2,
4369,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
7409,
15,
2944,
13,
30635,
13,
7409,
845,
1046,
12645,
4246,
13,
2164,
7897,
272,
665,
2024,
536,
628,
2469,
2,
1564,
9287,
3133,
272,
665,
2024,
536,
628,
479,
2,
1564,
628,
4246,
13,
2164,
283,
3592,
4065,
3133,
272,
665,
2024,
5960,
628,
1624,
13,
24,
7897,
272,
665,
2487,
30,
267,
768,
4246,
13,
1409,
469,
288,
5023,
13,
6606,
26,
29349,
27,
288,
2928,
26,
1166,
480,
4058,
15,
87,
19,
67,
15,
15174,
774,
14,
32264,
3547,
267,
789,
267,
327,
396,
469,
288,
5023,
13,
6606,
26,
29349,
27,
267,
789,
272,
3068,
2487,
30,
523,
3068,
2993,
30,
523,
665,
2030,
30,
272,
665,
80,
30,
774,
14933,
340,
314,
2877,
2385,
787,
314,
2011,
315,
5023,
1108,
80,
30,
272,
665,
3015,
1305,
628,
396,
1743,
4321,
17281,
36,
1108,
3015,
30,
272,
665,
3015,
30,
4321,
17281,
36,
1108,
3015,
30,
199,
3068,
2030,
30,
199,
1108,
1360,
30,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
rofolel/DonjonMasterExploder-
|
DD/combat.py
|
1
|
1449
|
import random
import console.Combat
import DD.person
class battle(object):
class hit(object):
def __init__(self,value,attacker,attackee):
self.value = value
self.attacker = attacker
self.attackee = attackee
def __str__(self):
return "%s hit %s for %i"%(self.attacker, self.attackee,int(self.value))
def __init__(self,participants):
self.participants = participants
self.hits = list()
self.current = 0
def popCurrent(self):
self.current += 1
if self.current >= len(self.participants):
self.current = 0
print "NEW TURN"
return self.participants[self.current]
def generateCombatOrder(self):
class roll(object):
def __init__(self,obj):
assert isinstance(obj,DD.person.Person)
self.obj = obj
self.value = random.randint(1,8) + i.initiative
def get(obj):
return obj.value
print "Combat order:"
tmp = list()
ok = False
score = -1
current = None
for i in self.participants:
tmp.append(roll(i))
self.participants = list()
tmp.sort(key = get)
incr = 0
for i in tmp :
self.participants.append(i.obj)
print console.Combat.printout("%i) %s"%(incr,i.obj.name), i.obj.color)
incr += 1
|
mit
|
[
646,
2196,
199,
646,
8559,
14,
4373,
13475,
199,
646,
29662,
14,
5484,
199,
533,
330,
29274,
8,
785,
304,
272,
1021,
9793,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
585,
12,
24171,
281,
12,
24171,
1024,
304,
288,
291,
14,
585,
275,
574,
288,
291,
14,
24171,
281,
275,
23326,
281,
288,
291,
14,
24171,
1024,
275,
23326,
1024,
267,
347,
636,
495,
721,
277,
304,
288,
372,
2071,
83,
9793,
450,
83,
367,
450,
73,
14007,
277,
14,
24171,
281,
12,
291,
14,
24171,
1024,
12,
442,
8,
277,
14,
585,
430,
2378,
347,
636,
826,
721,
277,
12,
31790,
304,
267,
291,
14,
31790,
275,
623,
20989,
267,
291,
14,
16595,
275,
769,
342,
267,
291,
14,
1818,
275,
378,
272,
347,
4560,
5639,
8,
277,
304,
267,
291,
14,
1818,
847,
413,
267,
340,
291,
14,
1818,
2356,
822,
8,
277,
14,
31790,
304,
288,
291,
14,
1818,
275,
378,
288,
870,
298,
11365,
377,
7648,
2,
267,
372,
291,
14,
31790,
59,
277,
14,
1818,
61,
2378,
347,
3550,
4373,
13475,
4738,
8,
277,
304,
267,
1021,
11848,
8,
785,
304,
288,
347,
636,
826,
721,
277,
12,
1113,
304,
355,
702,
1228,
8,
1113,
12,
5745,
14,
5484,
14,
7344,
9,
355,
291,
14,
1113,
275,
1559,
355,
291,
14,
585,
275,
2196,
14,
8393,
8,
17,
12,
24,
9,
435,
284,
14,
14188,
1905,
267,
347,
664,
8,
1113,
304,
355,
372,
1559,
14,
585,
398,
870,
298,
4373,
13475,
1865,
5424,
267,
3529,
275,
769,
342,
267,
4112,
275,
756,
267,
5396,
275,
446,
17,
267,
1453,
275,
488,
267,
367,
284,
315,
291,
14,
31790,
26,
288,
3529,
14,
740,
8,
2827,
8,
73,
430,
267,
291,
14,
31790,
275,
769,
342,
267,
3529,
14,
3191,
8,
498,
275,
664,
9,
267,
315,
1556,
275,
378,
267,
367,
284,
315,
3529,
520,
288,
291,
14,
31790,
14,
740,
8,
73,
14,
1113,
9,
288,
870,
8559,
14,
4373,
13475,
14,
1361,
548,
3647,
73,
9,
450,
83,
14007,
19362,
12,
73,
14,
1113,
14,
354,
395,
284,
14,
1113,
14,
2326,
9,
288,
315,
1556,
847,
413,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2196,
199,
646,
8559,
14,
4373,
13475,
199,
646,
29662,
14,
5484,
199,
533,
330,
29274,
8,
785,
304,
272,
1021,
9793,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
585,
12,
24171,
281,
12,
24171,
1024,
304,
288,
291,
14,
585,
275,
574,
288,
291,
14,
24171,
281,
275,
23326,
281,
288,
291,
14,
24171,
1024,
275,
23326,
1024,
267,
347,
636,
495,
721,
277,
304,
288,
372,
2071,
83,
9793,
450,
83,
367,
450,
73,
14007,
277,
14,
24171,
281,
12,
291,
14,
24171,
1024,
12,
442,
8,
277,
14,
585,
430,
2378,
347,
636,
826,
721,
277,
12,
31790,
304,
267,
291,
14,
31790,
275,
623,
20989,
267,
291,
14,
16595,
275,
769,
342,
267,
291,
14,
1818,
275,
378,
272,
347,
4560,
5639,
8,
277,
304,
267,
291,
14,
1818,
847,
413,
267,
340,
291,
14,
1818,
2356,
822,
8,
277,
14,
31790,
304,
288,
291,
14,
1818,
275,
378,
288,
870,
298,
11365,
377,
7648,
2,
267,
372,
291,
14,
31790,
59,
277,
14,
1818,
61,
2378,
347,
3550,
4373,
13475,
4738,
8,
277,
304,
267,
1021,
11848,
8,
785,
304,
288,
347,
636,
826,
721,
277,
12,
1113,
304,
355,
702,
1228,
8,
1113,
12,
5745,
14,
5484,
14,
7344,
9,
355,
291,
14,
1113,
275,
1559,
355,
291,
14,
585,
275,
2196,
14,
8393,
8,
17,
12,
24,
9,
435,
284,
14,
14188,
1905,
267,
347,
664,
8,
1113,
304,
355,
372,
1559,
14,
585,
398,
870,
298,
4373,
13475,
1865,
5424,
267,
3529,
275,
769,
342,
267,
4112,
275,
756,
267,
5396,
275,
446,
17,
267,
1453,
275,
488,
267,
367,
284,
315,
291,
14,
31790,
26,
288,
3529,
14,
740,
8,
2827,
8,
73,
430,
267,
291,
14,
31790,
275,
769,
342,
267,
3529,
14,
3191,
8,
498,
275,
664,
9,
267,
315,
1556,
275,
378,
267,
367,
284,
315,
3529,
520,
288,
291,
14,
31790,
14,
740,
8,
73,
14,
1113,
9,
288,
870,
8559,
14,
4373,
13475,
14,
1361,
548,
3647,
73,
9,
450,
83,
14007,
19362,
12,
73,
14,
1113,
14,
354,
395,
284,
14,
1113,
14,
2326,
9,
288,
315,
1556,
847,
413,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
andrecunha/coh-metrix-dementia
|
coh/tools/syllable/tonic.py
|
1
|
6223
|
#-*- encoding:utf-8 -*-
# tonic.py - Tonic vowel finding using the algorithm described in Silva [2011].
# Copyright (C) 2014 Alessandro Bokan
#
# 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/>.
#
# Authors: Alessandro Bokan <alessandro.bokan@gmail.com>
from __future__ import unicode_literals, print_function, division
import re
import codecs
from sys import argv
def tonic_vowel(word):
"""Implements the tonic vowel finding algorithm presented in
the third chapther of the PhD thesis:
Silva, D.C. (2011) Algoritmos de Processamento da Linguagem e Síntese
de Voz com Emoções Aplicados a um Conversor Text-Fala Baseado
em HMM. PhD dissertation, COPPE, UFRJ.
"""
# Regra 1: Se existe acento, a vogal marcada é tônica
match = re.search('á|é|í|ó|ú|â|ê|ô|à|ã|õ', word, re.UNICODE)
if match:
return match.start()
# TODO PALAVRA MARIOR A 2
# Rule 2: if ^(0) = {r,l,z,x,n} then T = 1
if re.search('[rlzxn]$', word, re.UNICODE):
return len(word) - 2
# Rule 3:
# if ^(0) = {m} & ^(1) = {i,o,u} then T = 1
if re.search('[iou]m$', word, re.UNICODE):
return len(word) - 2
# Rule 4:
# if ^(0) = {s} & ^(1) = {n} & ^(2) = {i,o,u} then T = 1
if re.search('[iou]ns$', word, re.UNICODE):
return len(word) - 3
# Rule 5:
# if ^(0) = {i} & ^(1) = {u,ü} & ^(2) = {q,g} then T = 0
if re.search('[qg][uü]i$', word, re.UNICODE):
return len(word) - 1
# Rule 6:
# if ^(0) = {s} & ^(1) = {i} & ^(2) = {u,ü} & ^(3) = {q,g} then T = 1
if re.search('[qg][uü]is$', word, re.UNICODE):
return len(word) - 2
# Rule 7:
# if ^(0) = {i,u} & ^(1) = {a,e,i,o,u} then T = 1
if re.search('[aeiou][iu]$', word, re.UNICODE):
return len(word) - 2
# if ^(0) = {i,u} & ^(1) != {a,e,i,o,u} then T = 0
if re.search('[^aeiou][iu]$', word, re.UNICODE):
return len(word) - 1
# Rule 8:
# if ^(0) = {s} & ^(1) = {i,u} & ^(2) = {a,e,i,o,u} then T = 2
if re.search('[aeiou][iu]s$', word, re.UNICODE):
return len(word) - 3
# Rule 9:
# if ^(0) = {s} & ^(1) = {i,u} & ^(2) != {a,e,i,o,u} then T = 2
if re.search('[^aeiou][iu]s$', word, re.UNICODE):
return len(word) - 2
# Rule 10:
# if ^(0) = {e} & ^(1) = {u} & ^(2) = {q} & ^(3) = {r} & ^(4) = {o} &
# ^(4) = {p} then T = 0
if word == "porque":
return len(word) - 1
# Rule 11
# if ^(0) = {e} & ^(1) = {u} & ^(2) = {qg} & ^(3) = {a,e,i,o,u} then T = 3
if re.search('[aeiou][qg]ue$', word, re.UNICODE):
return len(word) - 4
# if ^(0) = {e} & ^(1) = {u} & ^(2) = {qg} & ^(3) != {a,e,i,o,u} then T = 4
if re.search('[^aeiou][qg]ue$', word, re.UNICODE):
return len(word) - 5
# Rule 12
# if ^(0)={e} & ^(1)={e} & ^(2)={u} & ^(3)={qg} & ^(4)={aeiou} then T = 4
if re.search('[aeiou][qg]ues$', word, re.UNICODE):
return len(word) - 5
# if ^(0)={e} & ^(1)={e} & ^(2)={u} & ^(3)={qg} & ^(4)!={aeiou} then T = 5
if re.search('[^aeiou][qg]ues$', word, re.UNICODE):
return len(word) - 6
# Rule 13:
# if ^(0) = {a,e,i,o,u} & ^(2) = {i,u} & ^(3) = {a,e,i,o,u} then T = 2
if re.search('[aeiou][iu][aeiou]$', word, re.UNICODE):
return len(word) - 3
# Rule 14:
# if ^(0) & ^(3) = {a,e,i,o,u} & ^(2) = {i,u} & ^(1) != {a,e,i,o,u} &
# ^(4) != {q,g} then T = 3
if re.search('[^qg][aeiou][iu][^aeiou][aeiou]$', word, re.UNICODE):
return len(word) - 4
# Rule 15:
# if ^(0) = {s} & ^(1) & ^(4) = {a,e,i,o,u} & ^(3) = {i,u} &
# ^(2) != {a,e,i,o,u} & ^(5) != {q,g} then T = 4
if re.search('[^qg][aeiou][iu][^aeiou][aeiou]s$', word, re.UNICODE):
return len(word) - 5
# Rule 16:
# if ^(0) = {a,e,o} & ^(1) = cons & ^(2) = {n} & ^(3) = {i,u} &
# ^(4) = {a,e,i,o,u} then T = 3
consts = 'bdfghjklmnñpqrstvxyz'
if re.search('[aeiou][iu]n[' + consts + '][aeo]$', word, re.UNICODE):
return len(word) - 4
# Rule 17:
matches = [m.start() for m in re.finditer('a|e|i|o|u', word, re.UNICODE)]
if len(matches) >= 2:
k = matches[-2]
v = ['a', 'e', 'i', 'o', 'u']
if word[k] in ['i', 'u'] and word[k - 1] in v and not word[k + 1] in v:
if k - 2 < 0:
return 0
if not word[k - 2] in ['q', 'g']:
return k - 1
# Rule 18:
# if ^(0) = {m} & ^(1) = {e} & ^(2) = {u} & ^(3) = {q} then T = 1
if word == "quem":
return len(word) - 2
# Rule 19:
# Penultimate vowel of the word
matches = [m.start() for m in re.finditer('a|e|i|o|u', word, re.UNICODE)]
if len(matches) >= 2:
return matches[-2]
return -1
def word_format(word, position):
tonic = word + " -> "
for i in range(len(word)):
if i == position:
tonic = tonic + "[']"
tonic = tonic + word[i]
return tonic
def read_file(filename):
f = codecs.open(filename, mode='r', encoding='utf8')
output = codecs.open("output", mode='w', encoding='utf8')
errors = codecs.open("errors", mode='w', encoding='utf8')
for word in f.readlines():
word = word.strip().lower()
# TODO Filtrado de palavras com REGEX
T = tonic_vowel(word)
if T >= 0:
output.write(word_format(word, T) + '\n')
else:
errors.write(word + '\n')
f.close()
output.close()
errors.close()
def read_word(word):
print(word_format(word, tonic_vowel(word.lower())))
if __name__ == '__main__':
print(argv[1], tonic_vowel(argv[1].lower()))
|
gpl-3.0
|
[
3,
13,
1837,
2644,
26,
1624,
13,
24,
1882,
199,
3,
307,
12732,
14,
647,
446,
377,
12732,
373,
11797,
17196,
1808,
314,
5563,
11736,
315,
428,
382,
3042,
359,
8128,
1055,
199,
3,
1898,
334,
35,
9,
6927,
221,
437,
2003,
460,
293,
699,
745,
290,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
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,
12,
1902,
1015,
650,
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,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
6642,
26,
221,
437,
2003,
460,
293,
699,
745,
290,
665,
1895,
385,
460,
293,
14,
656,
29305,
32,
6799,
14,
957,
30,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
12,
870,
63,
1593,
12,
4629,
199,
646,
295,
199,
646,
6010,
199,
504,
984,
492,
9238,
421,
199,
318,
307,
12732,
63,
28597,
8,
1027,
304,
272,
408,
29452,
314,
307,
12732,
373,
11797,
17196,
5563,
26568,
315,
272,
314,
10919,
682,
439,
728,
402,
314,
11308,
36,
314,
2316,
26,
398,
428,
382,
3042,
12,
577,
14,
35,
14,
334,
8128,
9,
4580,
2904,
390,
16908,
477,
7132,
14040,
79,
12927,
491,
316,
1718,
77,
325,
428,
13676,
78,
266,
261,
267,
477,
812,
26051,
2414,
662,
573,
15368,
128,
114,
397,
13450,
606,
20257,
282,
28236,
11801,
1509,
4516,
13,
38,
14774,
3523,
5129,
267,
18564,
869,
3218,
14,
11308,
36,
2153,
407,
425,
12,
4658,
1510,
12,
738,
5372,
42,
14,
272,
408,
272,
327,
799,
926,
413,
26,
3240,
444,
29729,
1066,
287,
475,
12,
282,
373,
974,
279,
7557,
67,
10641,
26785,
307,
128,
113,
12165,
65,
272,
1336,
275,
295,
14,
1733,
360,
11302,
92,
5741,
92,
13676,
92,
11980,
92,
24602,
92,
128,
96,
92,
28413,
92,
128,
113,
92,
26482,
92,
15948,
92,
128,
114,
297,
4349,
12,
295,
14,
12819,
9,
272,
340,
1336,
26,
267,
372,
1336,
14,
928,
342,
339,
327,
3254,
510,
748,
6087,
2847,
603,
689,
41,
726,
437,
499,
339,
327,
11949,
499,
26,
340,
7167,
8,
16,
9,
275,
469,
82,
12,
76,
12,
90,
12,
88,
12,
78,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
4308,
90,
5032,
61,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
499,
339,
327,
11949,
650,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
77,
93,
1253,
7167,
8,
17,
9,
275,
469,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
73,
810,
61,
77,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
499,
339,
327,
11949,
841,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
83,
93,
1253,
7167,
8,
17,
9,
275,
469,
78,
93,
1253,
7167,
8,
18,
9,
275,
469,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
73,
810,
61,
561,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
650,
339,
327,
11949,
959,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
73,
93,
1253,
7167,
8,
17,
9,
275,
469,
85,
12,
17709,
93,
1253,
7167,
8,
18,
9,
275,
469,
81,
12,
71,
93,
2066,
377,
275,
378,
272,
340,
295,
14,
1733,
11894,
81,
71,
1527,
85,
17709,
61,
73,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
413,
339,
327,
11949,
1227,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
83,
93,
1253,
7167,
8,
17,
9,
275,
469,
73,
93,
1253,
7167,
8,
18,
9,
275,
469,
85,
12,
17709,
93,
1253,
7167,
8,
19,
9,
275,
469,
81,
12,
71,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
81,
71,
1527,
85,
17709,
61,
374,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
499,
339,
327,
11949,
1520,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
73,
12,
85,
93,
1253,
7167,
8,
17,
9,
275,
469,
65,
12,
69,
12,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
3624,
73,
810,
1527,
73,
85,
61,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
499,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
73,
12,
85,
93,
1253,
7167,
8,
17,
9,
1137,
469,
65,
12,
69,
12,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
378,
272,
340,
295,
14,
1733,
360,
4735,
3624,
73,
810,
1527,
73,
85,
61,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
413,
339,
327,
11949,
1695,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
83,
93,
1253,
7167,
8,
17,
9,
275,
469,
73,
12,
85,
93,
1253,
7167,
8,
18,
9,
275,
469,
65,
12,
69,
12,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
499,
272,
340,
295,
14,
1733,
11894,
3624,
73,
810,
1527,
73,
85,
61,
83,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
650,
339,
327,
11949,
1749,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
83,
93,
1253,
7167,
8,
17,
9,
275,
469,
73,
12,
85,
93,
1253,
7167,
8,
18,
9,
1137,
469,
65,
12,
69,
12,
73,
12,
79,
12,
85
] |
[
13,
1837,
2644,
26,
1624,
13,
24,
1882,
199,
3,
307,
12732,
14,
647,
446,
377,
12732,
373,
11797,
17196,
1808,
314,
5563,
11736,
315,
428,
382,
3042,
359,
8128,
1055,
199,
3,
1898,
334,
35,
9,
6927,
221,
437,
2003,
460,
293,
699,
745,
290,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
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,
12,
1902,
1015,
650,
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,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
6642,
26,
221,
437,
2003,
460,
293,
699,
745,
290,
665,
1895,
385,
460,
293,
14,
656,
29305,
32,
6799,
14,
957,
30,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
12,
870,
63,
1593,
12,
4629,
199,
646,
295,
199,
646,
6010,
199,
504,
984,
492,
9238,
421,
199,
318,
307,
12732,
63,
28597,
8,
1027,
304,
272,
408,
29452,
314,
307,
12732,
373,
11797,
17196,
5563,
26568,
315,
272,
314,
10919,
682,
439,
728,
402,
314,
11308,
36,
314,
2316,
26,
398,
428,
382,
3042,
12,
577,
14,
35,
14,
334,
8128,
9,
4580,
2904,
390,
16908,
477,
7132,
14040,
79,
12927,
491,
316,
1718,
77,
325,
428,
13676,
78,
266,
261,
267,
477,
812,
26051,
2414,
662,
573,
15368,
128,
114,
397,
13450,
606,
20257,
282,
28236,
11801,
1509,
4516,
13,
38,
14774,
3523,
5129,
267,
18564,
869,
3218,
14,
11308,
36,
2153,
407,
425,
12,
4658,
1510,
12,
738,
5372,
42,
14,
272,
408,
272,
327,
799,
926,
413,
26,
3240,
444,
29729,
1066,
287,
475,
12,
282,
373,
974,
279,
7557,
67,
10641,
26785,
307,
128,
113,
12165,
65,
272,
1336,
275,
295,
14,
1733,
360,
11302,
92,
5741,
92,
13676,
92,
11980,
92,
24602,
92,
128,
96,
92,
28413,
92,
128,
113,
92,
26482,
92,
15948,
92,
128,
114,
297,
4349,
12,
295,
14,
12819,
9,
272,
340,
1336,
26,
267,
372,
1336,
14,
928,
342,
339,
327,
3254,
510,
748,
6087,
2847,
603,
689,
41,
726,
437,
499,
339,
327,
11949,
499,
26,
340,
7167,
8,
16,
9,
275,
469,
82,
12,
76,
12,
90,
12,
88,
12,
78,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
4308,
90,
5032,
61,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
499,
339,
327,
11949,
650,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
77,
93,
1253,
7167,
8,
17,
9,
275,
469,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
73,
810,
61,
77,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
499,
339,
327,
11949,
841,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
83,
93,
1253,
7167,
8,
17,
9,
275,
469,
78,
93,
1253,
7167,
8,
18,
9,
275,
469,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
73,
810,
61,
561,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
650,
339,
327,
11949,
959,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
73,
93,
1253,
7167,
8,
17,
9,
275,
469,
85,
12,
17709,
93,
1253,
7167,
8,
18,
9,
275,
469,
81,
12,
71,
93,
2066,
377,
275,
378,
272,
340,
295,
14,
1733,
11894,
81,
71,
1527,
85,
17709,
61,
73,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
413,
339,
327,
11949,
1227,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
83,
93,
1253,
7167,
8,
17,
9,
275,
469,
73,
93,
1253,
7167,
8,
18,
9,
275,
469,
85,
12,
17709,
93,
1253,
7167,
8,
19,
9,
275,
469,
81,
12,
71,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
81,
71,
1527,
85,
17709,
61,
374,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
499,
339,
327,
11949,
1520,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
73,
12,
85,
93,
1253,
7167,
8,
17,
9,
275,
469,
65,
12,
69,
12,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
413,
272,
340,
295,
14,
1733,
11894,
3624,
73,
810,
1527,
73,
85,
61,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
499,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
73,
12,
85,
93,
1253,
7167,
8,
17,
9,
1137,
469,
65,
12,
69,
12,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
378,
272,
340,
295,
14,
1733,
360,
4735,
3624,
73,
810,
1527,
73,
85,
61,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
413,
339,
327,
11949,
1695,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
83,
93,
1253,
7167,
8,
17,
9,
275,
469,
73,
12,
85,
93,
1253,
7167,
8,
18,
9,
275,
469,
65,
12,
69,
12,
73,
12,
79,
12,
85,
93,
2066,
377,
275,
499,
272,
340,
295,
14,
1733,
11894,
3624,
73,
810,
1527,
73,
85,
61,
83,
4268,
4349,
12,
295,
14,
12819,
304,
267,
372,
822,
8,
1027,
9,
446,
650,
339,
327,
11949,
1749,
26,
272,
327,
340,
7167,
8,
16,
9,
275,
469,
83,
93,
1253,
7167,
8,
17,
9,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
rabitt/motif
|
motif/feature_extractors/melodia.py
|
1
|
2442
|
"""Melodia feature extractor.
"""
import numpy as np
from motif.core import FeatureExtractor
from motif.feature_extractors import utils
class MelodiaFeatures(FeatureExtractor):
'''Melodia feature extractor
Attributes
----------
ref_hz : float
Reference frequency (Hz) for converting to cents.
'''
def __init__(self, ref_hz=55.0):
'''Init method
Parameters
----------
ref_hz : float
Reference frequency (Hz) for converting to cents.
'''
self.ref_hz = ref_hz
FeatureExtractor.__init__(self)
def get_feature_vector(self, times, freqs_hz, salience, sample_rate):
"""Get feature vector for a contour.
Parameters
----------
times : np.array
Contour times
freqs_hz : np.array
Contour frequencies (Hz)
salience : np.array
Contour salience
sample_rate : float
Contour sample rate.
Returns
-------
feature_vector : np.array
Feature vector.
"""
freqs_cents = utils.hz_to_cents(freqs_hz, ref_hz=self.ref_hz)
features = [
utils.get_contour_onset(times),
utils.get_contour_offset(times),
utils.get_contour_duration(times),
utils.get_mean(freqs_cents),
utils.get_std(freqs_cents),
utils.get_mean(salience),
utils.get_std(salience),
utils.get_sum(salience),
utils.vibrato_essentia(freqs_cents, sample_rate) # dimension 4
]
return np.concatenate(features)
@property
def feature_names(self):
"""Get feature names.
Returns
-------
feature_names : list
List of feature names.
"""
feature_names = [
'onset',
'offset',
'duration',
'pitch mean (cents)',
'pitch stddev (cents)',
'salience mean',
'salience stdev',
'salience total',
'vibrato',
'vibrato rate',
'vibrato extent (cents)',
'vibrato coverage'
]
return feature_names
@classmethod
def get_id(cls):
""" The FeatureExtractor identifier
Returns
-------
id : string
class identifier
"""
return 'melodia'
|
mit
|
[
624,
1352,
320,
2391,
3878,
31295,
14,
199,
624,
199,
646,
2680,
465,
980,
199,
199,
504,
1303,
9142,
14,
1018,
492,
13407,
11039,
199,
504,
1303,
9142,
14,
4445,
63,
2911,
13451,
492,
3778,
421,
199,
533,
3194,
320,
2391,
10807,
8,
5968,
11039,
304,
272,
1449,
1352,
320,
2391,
3878,
31295,
339,
9382,
272,
4143,
272,
2984,
63,
19552,
520,
2069,
267,
10944,
9857,
334,
13026,
9,
367,
13806,
370,
13345,
83,
14,
339,
1449,
272,
347,
636,
826,
721,
277,
12,
2984,
63,
19552,
29,
1229,
14,
16,
304,
267,
1449,
9346,
1083,
398,
3897,
267,
4143,
267,
2984,
63,
19552,
520,
2069,
288,
10944,
9857,
334,
13026,
9,
367,
13806,
370,
13345,
83,
14,
398,
1449,
267,
291,
14,
1121,
63,
19552,
275,
2984,
63,
19552,
267,
13407,
11039,
855,
826,
721,
277,
9,
339,
347,
664,
63,
4445,
63,
4106,
8,
277,
12,
5431,
12,
9220,
83,
63,
19552,
12,
308,
10874,
4894,
12,
2690,
63,
1866,
304,
267,
408,
1002,
3878,
5477,
367,
282,
23176,
14,
398,
3897,
267,
4143,
267,
5431,
520,
980,
14,
1144,
288,
1448,
10808,
5431,
267,
9220,
83,
63,
19552,
520,
980,
14,
1144,
288,
1448,
10808,
22411,
334,
13026,
9,
267,
308,
10874,
4894,
520,
980,
14,
1144,
288,
1448,
10808,
308,
10874,
4894,
267,
2690,
63,
1866,
520,
2069,
288,
1448,
10808,
2690,
6634,
14,
398,
1803,
267,
5514,
267,
3878,
63,
4106,
520,
980,
14,
1144,
288,
13407,
5477,
14,
398,
408,
267,
9220,
83,
63,
2946,
83,
275,
3778,
14,
19552,
63,
475,
63,
2946,
83,
8,
28557,
63,
19552,
12,
2984,
63,
19552,
29,
277,
14,
1121,
63,
19552,
9,
398,
4534,
275,
359,
288,
3778,
14,
362,
63,
17798,
63,
265,
409,
8,
4508,
395,
288,
3778,
14,
362,
63,
17798,
63,
2743,
8,
4508,
395,
288,
3778,
14,
362,
63,
17798,
63,
5553,
8,
4508,
395,
288,
3778,
14,
362,
63,
3670,
8,
28557,
63,
2946,
83,
395,
288,
3778,
14,
362,
63,
1516,
8,
28557,
63,
2946,
83,
395,
288,
3778,
14,
362,
63,
3670,
8,
6327,
12837,
395,
288,
3778,
14,
362,
63,
1516,
8,
6327,
12837,
395,
288,
3778,
14,
362,
63,
1838,
8,
6327,
12837,
395,
288,
3778,
14,
433,
3289,
11318,
63,
397,
2464,
14037,
8,
28557,
63,
2946,
83,
12,
2690,
63,
1866,
9,
221,
327,
6240,
841,
267,
1622,
398,
372,
980,
14,
13433,
8,
3179,
9,
339,
768,
1829,
272,
347,
3878,
63,
1247,
8,
277,
304,
267,
408,
1002,
3878,
1561,
14,
398,
1803,
267,
5514,
267,
3878,
63,
1247,
520,
769,
288,
3820,
402,
3878,
1561,
14,
398,
408,
267,
3878,
63,
1247,
275,
359,
288,
283,
265,
409,
297,
288,
283,
2743,
297,
288,
283,
5553,
297,
288,
283,
16966,
4615,
334,
2946,
83,
3196,
288,
283,
16966,
28052,
334,
2946,
83,
3196,
288,
283,
6327,
12837,
4615,
297,
288,
283,
6327,
12837,
410,
2374,
297,
288,
283,
6327,
12837,
3141,
297,
288,
283,
433,
3289,
11318,
297,
288,
283,
433,
3289,
11318,
6634,
297,
288,
283,
433,
3289,
11318,
13675,
334,
2946,
83,
3196,
288,
283,
433,
3289,
11318,
11745,
7,
267,
1622,
267,
372,
3878,
63,
1247,
339,
768,
3744,
272,
347,
664,
63,
344,
8,
1886,
304,
267,
408,
710,
13407,
11039,
5148,
398,
1803,
267,
5514,
267,
1305,
520,
1059,
288,
1021,
5148,
267,
408,
267,
372,
283,
278,
320,
2391,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1352,
320,
2391,
3878,
31295,
14,
199,
624,
199,
646,
2680,
465,
980,
199,
199,
504,
1303,
9142,
14,
1018,
492,
13407,
11039,
199,
504,
1303,
9142,
14,
4445,
63,
2911,
13451,
492,
3778,
421,
199,
533,
3194,
320,
2391,
10807,
8,
5968,
11039,
304,
272,
1449,
1352,
320,
2391,
3878,
31295,
339,
9382,
272,
4143,
272,
2984,
63,
19552,
520,
2069,
267,
10944,
9857,
334,
13026,
9,
367,
13806,
370,
13345,
83,
14,
339,
1449,
272,
347,
636,
826,
721,
277,
12,
2984,
63,
19552,
29,
1229,
14,
16,
304,
267,
1449,
9346,
1083,
398,
3897,
267,
4143,
267,
2984,
63,
19552,
520,
2069,
288,
10944,
9857,
334,
13026,
9,
367,
13806,
370,
13345,
83,
14,
398,
1449,
267,
291,
14,
1121,
63,
19552,
275,
2984,
63,
19552,
267,
13407,
11039,
855,
826,
721,
277,
9,
339,
347,
664,
63,
4445,
63,
4106,
8,
277,
12,
5431,
12,
9220,
83,
63,
19552,
12,
308,
10874,
4894,
12,
2690,
63,
1866,
304,
267,
408,
1002,
3878,
5477,
367,
282,
23176,
14,
398,
3897,
267,
4143,
267,
5431,
520,
980,
14,
1144,
288,
1448,
10808,
5431,
267,
9220,
83,
63,
19552,
520,
980,
14,
1144,
288,
1448,
10808,
22411,
334,
13026,
9,
267,
308,
10874,
4894,
520,
980,
14,
1144,
288,
1448,
10808,
308,
10874,
4894,
267,
2690,
63,
1866,
520,
2069,
288,
1448,
10808,
2690,
6634,
14,
398,
1803,
267,
5514,
267,
3878,
63,
4106,
520,
980,
14,
1144,
288,
13407,
5477,
14,
398,
408,
267,
9220,
83,
63,
2946,
83,
275,
3778,
14,
19552,
63,
475,
63,
2946,
83,
8,
28557,
63,
19552,
12,
2984,
63,
19552,
29,
277,
14,
1121,
63,
19552,
9,
398,
4534,
275,
359,
288,
3778,
14,
362,
63,
17798,
63,
265,
409,
8,
4508,
395,
288,
3778,
14,
362,
63,
17798,
63,
2743,
8,
4508,
395,
288,
3778,
14,
362,
63,
17798,
63,
5553,
8,
4508,
395,
288,
3778,
14,
362,
63,
3670,
8,
28557,
63,
2946,
83,
395,
288,
3778,
14,
362,
63,
1516,
8,
28557,
63,
2946,
83,
395,
288,
3778,
14,
362,
63,
3670,
8,
6327,
12837,
395,
288,
3778,
14,
362,
63,
1516,
8,
6327,
12837,
395,
288,
3778,
14,
362,
63,
1838,
8,
6327,
12837,
395,
288,
3778,
14,
433,
3289,
11318,
63,
397,
2464,
14037,
8,
28557,
63,
2946,
83,
12,
2690,
63,
1866,
9,
221,
327,
6240,
841,
267,
1622,
398,
372,
980,
14,
13433,
8,
3179,
9,
339,
768,
1829,
272,
347,
3878,
63,
1247,
8,
277,
304,
267,
408,
1002,
3878,
1561,
14,
398,
1803,
267,
5514,
267,
3878,
63,
1247,
520,
769,
288,
3820,
402,
3878,
1561,
14,
398,
408,
267,
3878,
63,
1247,
275,
359,
288,
283,
265,
409,
297,
288,
283,
2743,
297,
288,
283,
5553,
297,
288,
283,
16966,
4615,
334,
2946,
83,
3196,
288,
283,
16966,
28052,
334,
2946,
83,
3196,
288,
283,
6327,
12837,
4615,
297,
288,
283,
6327,
12837,
410,
2374,
297,
288,
283,
6327,
12837,
3141,
297,
288,
283,
433,
3289,
11318,
297,
288,
283,
433,
3289,
11318,
6634,
297,
288,
283,
433,
3289,
11318,
13675,
334,
2946,
83,
3196,
288,
283,
433,
3289,
11318,
11745,
7,
267,
1622,
267,
372,
3878,
63,
1247,
339,
768,
3744,
272,
347,
664,
63,
344,
8,
1886,
304,
267,
408,
710,
13407,
11039,
5148,
398,
1803,
267,
5514,
267,
1305,
520,
1059,
288,
1021,
5148,
267,
408,
267,
372,
283,
278,
320,
2391,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ngugi/geonode
|
geonode/services/tests.py
|
5
|
4297
|
# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright (C) 2012 OpenPlans
#
# 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 json
import sys
import traceback
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse
from .models import Service
class ServicesTests(TestCase):
"""Tests geonode.services app/module
"""
fixtures = ['initial_data.json', 'bobby.json', 'people_data.json']
def setUp(self):
self.user = 'admin'
self.passwd = 'admin'
def test_register_indexed_wms(self):
"""Test registering an indexed WMS
"""
c = Client()
c.login(username='admin', password='admin')
response = c.post(reverse('register_service'),
{
'type': 'WMS',
'url': 'http://metaspatial.net/cgi-bin/ogc-wms.xml',
})
self.assertEqual(response.status_code, 200)
service_dict = json.loads(response.content)[0]
try:
service = Service.objects.get(id=service_dict['service_id'])
# Harvested some layers
self.assertTrue(service.layer_set.count() > 0)
self.assertEqual(service.method, "I")
self.assertEqual(service.type, "WMS")
self.assertEqual(service.ptype, 'gxp_wmscsource')
except Exception, e:
traceback.print_exc(file=sys.stdout)
self.fail("Service not created: %s" % str(e))
def test_register_arcrest(self):
"""Test registering an arcrest service
"""
c = Client()
c.login(username='admin', password='admin')
response = c.post(reverse('register_service'),
{
'type': 'REST',
'url': 'http://maps1.arcgisonline.com/ArcGIS/rest/services/EPA_Facilities/MapServer',
})
self.assertEqual(response.status_code, 200)
service_dict = json.loads(response.content)[0]
try:
service = Service.objects.get(id=service_dict['service_id'])
# Harvested some layers
self.assertTrue(service.layer_set.count() > 0)
self.assertEqual(service.method, "I")
self.assertEqual(service.type, "REST")
self.assertEqual(service.ptype, 'gxp_arcrestsource')
except Exception, e:
self.fail("Service not created: %s" % str(e))
# Disabled the test below because it uses an external service and fails randomly.
# def test_register_csw(self):
# c = Client()
# c.login(username='admin', password='admin')
# response = c.post(reverse('register_service'),
# {
# 'type':'CSW',
# 'url':'http://demo.pycsw.org/cite/csw',
#
# })
# self.assertEqual(response.status_code, 200)
# service_dict = json.loads(response.content)[0]
# try:
# service = Service.objects.get(id=service_dict['service_id'])
# except Exception, e:
# self.fail("Service not created: %s" % str(e))
# self.assertEqual(service.method, "H")
# self.assertEqual(service.type, "CSW")
# self.assertEqual(service.base_url, 'http://demo.pycsw.org/cite/csw')
# TODO: Use CSW or make mock CSW containing just a few small WMS & ESRI service records
# self.assertEquals(service.service_set.all().count(), 0) #No WMS/REST services
# self.assertEquals(service.layers.count(),0) # No Layers for this one
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3949,
3,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
3232,
3714,
796,
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,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3949,
3,
199,
199,
646,
2022,
199,
646,
984,
199,
646,
5190,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1275,
992,
492,
7591,
421,
199,
533,
21813,
2925,
8,
1746,
304,
339,
408,
2925,
2312,
29118,
14,
5950,
1145,
15,
578,
272,
408,
339,
15188,
275,
788,
2747,
63,
576,
14,
1001,
297,
283,
7913,
991,
14,
1001,
297,
283,
13562,
63,
576,
14,
1001,
418,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
283,
2113,
7,
267,
291,
14,
12671,
275,
283,
2113,
7,
339,
347,
511,
63,
2683,
63,
16821,
63,
30297,
8,
277,
304,
267,
408,
774,
2274,
316,
376,
15235,
644,
3053,
267,
408,
267,
286,
275,
6810,
342,
267,
286,
14,
2886,
8,
2473,
534,
2113,
297,
2505,
534,
2113,
358,
398,
1177,
275,
286,
14,
1932,
8,
4471,
360,
2683,
63,
1364,
659,
2079,
469,
288,
283,
466,
356,
283,
55,
3053,
297,
490,
283,
633,
356,
283,
1014,
921,
10207,
305,
9491,
14,
846,
15,
13814,
13,
1393,
15,
29238,
13,
30297,
14,
1652,
297,
267,
3828,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
2435,
63,
807,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
2788,
16,
61,
398,
862,
26,
288,
2435,
275,
7591,
14,
1462,
14,
362,
8,
344,
29,
1364,
63,
807,
459,
1364,
63,
344,
1105,
288,
327,
25378,
2310,
471,
2005,
9393,
288,
291,
14,
1815,
8,
1364,
14,
1897,
63,
409,
14,
835,
342,
690,
378,
9,
288,
291,
14,
629,
8,
1364,
14,
765,
12,
298,
41,
531,
288,
291,
14,
629,
8,
1364,
14,
466,
12,
298,
55,
3053,
531,
288,
291,
14,
629,
8,
1364,
14,
29707,
12,
283,
71,
9290,
63,
16240,
551,
1365,
358,
267,
871,
2186,
12,
325,
26,
288,
5190,
14,
1361,
63,
2804,
8,
493,
29,
1274,
14,
2703,
9,
288,
291,
14,
1633,
480,
3167,
440,
2737,
26,
450,
83,
2,
450,
620,
8,
69,
430,
339,
347,
511,
63,
2683,
63,
285,
1353,
270,
8,
277,
304,
267,
408,
774,
2274,
316,
376,
601,
1353,
270,
2435,
267,
408,
267,
286,
275,
6810,
342,
267,
286,
14,
2886,
8,
2473,
534,
2113,
297,
2505,
534,
2113,
358,
267,
1177,
275,
286,
14,
1932,
8,
4471,
360,
2683,
63,
1364,
659,
2079,
469,
2892,
283,
466,
356,
283,
15740,
297,
2892,
283,
633,
356,
283,
1014,
921,
8919,
17,
14,
9912,
5668,
15178,
14,
957,
15,
27604,
11092,
15,
3911,
15,
5950,
15,
6102,
33,
63,
1906,
559,
7999,
15,
2956,
3120,
297,
267,
3828,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
2435,
63,
807,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
2788,
16,
61,
398,
862,
26,
288,
2435,
275,
7591,
14,
1462,
14,
362,
8,
344,
29,
1364,
63,
807,
459,
1364,
63,
344,
1105,
288,
327,
25378,
2310,
471,
2005,
9393,
288,
291,
14,
1815,
8,
1364,
14,
1897,
63,
409,
14,
835,
342,
690,
378,
9,
288,
291,
14,
629,
8,
1364,
14,
765,
12,
298,
41,
531,
288,
291,
14,
629,
8,
1364,
14,
466,
12,
298,
15740,
531,
288,
291,
14,
629,
8,
1364,
14,
29707,
12,
283,
71,
9290,
63,
285,
1353,
270,
1365,
358,
267,
871,
2186,
12,
325,
26,
288,
291,
14,
1633,
480,
3167,
440,
2737,
26,
450,
83,
2,
450,
620,
8,
69,
430,
339,
327,
5289,
1909,
314,
511,
5084,
2952,
652,
4440,
376,
5957,
2435,
436,
6918,
19311,
14,
272,
327,
347,
511,
63,
2683,
63,
29735,
8,
277,
304,
272,
327,
259,
286,
275,
6810,
342,
272,
327,
259,
286,
14,
2886,
8,
2473,
534,
2113,
297,
2505,
534,
2113,
358,
272,
327,
259,
1177,
275,
286,
14,
1932,
8,
4471,
360,
2683,
63,
1364,
659,
272,
327,
8295,
469,
272,
327,
10473,
283,
466,
5242,
3298,
55,
297,
272,
327,
10473,
283,
633,
5242,
1014,
921,
8768,
14,
647,
29735,
14,
1308,
15,
25171,
15,
29735,
297,
272,
327,
272,
327,
259,
3828,
272,
327,
259,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
272,
327,
259,
2435,
63,
807,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
2788,
16,
61,
272,
327,
259,
862,
26,
272,
327,
263,
2435,
275,
7591,
14,
1462,
14,
362,
8,
344,
29,
1364,
63,
807,
459,
1364,
63,
344,
1105,
272,
327,
259,
871,
2186,
12,
325,
26,
272,
327,
263,
291,
14,
1633,
480,
3167,
440,
2737,
26,
450,
83,
2,
450,
620,
8,
69,
430,
272,
327,
259,
291,
14,
629,
8,
1364,
14,
765,
12,
298,
40,
531,
272,
327,
259,
291,
14,
629,
8,
1364,
14,
466,
12,
298,
3298,
55,
531,
272,
327,
259,
291,
14,
629,
8,
1364,
14,
1095,
63,
633,
12,
283,
1014,
921,
8768,
14,
647,
29735,
14,
1308,
15,
25171,
15,
29735,
358,
272,
327,
3254,
26,
3645,
445,
8745,
503,
1852,
1683,
445,
8745,
3035,
2951,
282,
9284,
7425,
644,
3053
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3949,
3,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
3232,
3714,
796,
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,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3949,
3,
199,
199,
646,
2022,
199,
646,
984,
199,
646,
5190,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1275,
992,
492,
7591,
421,
199,
533,
21813,
2925,
8,
1746,
304,
339,
408,
2925,
2312,
29118,
14,
5950,
1145,
15,
578,
272,
408,
339,
15188,
275,
788,
2747,
63,
576,
14,
1001,
297,
283,
7913,
991,
14,
1001,
297,
283,
13562,
63,
576,
14,
1001,
418,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
283,
2113,
7,
267,
291,
14,
12671,
275,
283,
2113,
7,
339,
347,
511,
63,
2683,
63,
16821,
63,
30297,
8,
277,
304,
267,
408,
774,
2274,
316,
376,
15235,
644,
3053,
267,
408,
267,
286,
275,
6810,
342,
267,
286,
14,
2886,
8,
2473,
534,
2113,
297,
2505,
534,
2113,
358,
398,
1177,
275,
286,
14,
1932,
8,
4471,
360,
2683,
63,
1364,
659,
2079,
469,
288,
283,
466,
356,
283,
55,
3053,
297,
490,
283,
633,
356,
283,
1014,
921,
10207,
305,
9491,
14,
846,
15,
13814,
13,
1393,
15,
29238,
13,
30297,
14,
1652,
297,
267,
3828,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
2435,
63,
807,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
2788,
16,
61,
398,
862,
26,
288,
2435,
275,
7591,
14,
1462,
14,
362,
8,
344,
29,
1364,
63,
807,
459,
1364,
63,
344,
1105,
288,
327,
25378,
2310,
471,
2005,
9393,
288,
291,
14,
1815,
8,
1364,
14,
1897,
63,
409,
14,
835,
342,
690,
378,
9,
288,
291,
14,
629,
8,
1364,
14,
765,
12,
298,
41,
531,
288,
291,
14,
629,
8,
1364,
14,
466,
12,
298,
55,
3053,
531,
288,
291,
14,
629,
8,
1364,
14,
29707,
12,
283,
71,
9290,
63,
16240,
551,
1365,
358,
267,
871,
2186,
12,
325,
26,
288,
5190,
14,
1361,
63,
2804,
8,
493,
29,
1274,
14,
2703,
9,
288,
291,
14,
1633,
480,
3167,
440,
2737,
26,
450,
83,
2,
450,
620,
8,
69,
430,
339,
347,
511,
63,
2683,
63,
285,
1353,
270,
8,
277,
304,
267,
408,
774,
2274,
316,
376,
601,
1353,
270,
2435,
267,
408,
267,
286,
275,
6810,
342,
267,
286,
14,
2886,
8,
2473,
534,
2113,
297,
2505,
534,
2113,
358,
267,
1177,
275,
286,
14,
1932,
8,
4471,
360,
2683,
63,
1364,
659,
2079,
469,
2892,
283,
466,
356,
283,
15740,
297,
2892,
283,
633,
356,
283,
1014,
921,
8919,
17,
14,
9912,
5668,
15178,
14,
957,
15,
27604,
11092,
15,
3911,
15,
5950,
15,
6102,
33,
63,
1906,
559,
7999,
15,
2956,
3120,
297,
267,
3828,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
2435,
63,
807,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
2788,
16,
61,
398,
862,
26,
288,
2435,
275,
7591,
14,
1462,
14,
362,
8,
344,
29,
1364,
63,
807,
459,
1364,
63,
344,
1105,
288,
327,
25378,
2310,
471,
2005,
9393,
288,
291,
14,
1815,
8,
1364,
14,
1897,
63,
409,
14,
835,
342,
690,
378,
9,
288,
291,
14,
629,
8,
1364,
14,
765,
12,
298,
41,
531,
288,
291,
14,
629,
8,
1364,
14,
466,
12,
298,
15740,
531,
288,
291,
14,
629,
8,
1364,
14,
29707,
12,
283,
71,
9290,
63,
285,
1353,
270,
1365,
358,
267,
871,
2186,
12,
325,
26,
288,
291,
14,
1633,
480,
3167,
440,
2737,
26,
450,
83,
2,
450,
620,
8,
69,
430,
339,
327,
5289,
1909,
314,
511,
5084,
2952,
652,
4440,
376,
5957,
2435,
436,
6918,
19311,
14,
272,
327,
347,
511,
63,
2683,
63,
29735,
8,
277,
304,
272,
327,
259,
286,
275,
6810,
342,
272,
327,
259,
286,
14,
2886,
8,
2473,
534,
2113,
297,
2505,
534,
2113,
358,
272,
327,
259,
1177,
275,
286,
14,
1932,
8,
4471,
360,
2683,
63,
1364,
659,
272,
327,
8295,
469,
272,
327,
10473,
283,
466,
5242,
3298,
55,
297,
272,
327,
10473,
283,
633,
5242,
1014,
921,
8768,
14,
647,
29735,
14,
1308,
15,
25171,
15,
29735,
297,
272,
327,
272,
327,
259,
3828,
272,
327,
259,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
272,
327,
259,
2435,
63,
807,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
2788,
16,
61,
272,
327,
259,
862,
26,
272,
327,
263,
2435,
275,
7591,
14,
1462,
14,
362,
8,
344,
29,
1364,
63,
807,
459,
1364,
63,
344,
1105,
272,
327,
259,
871,
2186,
12,
325,
26,
272,
327,
263,
291,
14,
1633,
480,
3167,
440,
2737,
26,
450,
83,
2,
450,
620,
8,
69,
430,
272,
327,
259,
291,
14,
629,
8,
1364,
14,
765,
12,
298,
40,
531,
272,
327,
259,
291,
14,
629,
8,
1364,
14,
466,
12,
298,
3298,
55,
531,
272,
327,
259,
291,
14,
629,
8,
1364,
14,
1095,
63,
633,
12,
283,
1014,
921,
8768,
14,
647,
29735,
14,
1308,
15,
25171,
15,
29735,
358,
272,
327,
3254,
26,
3645,
445,
8745,
503,
1852,
1683,
445,
8745,
3035,
2951,
282,
9284,
7425,
644,
3053,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
endlessm/chromium-browser
|
build/android/gyp/zip.py
|
3
|
2376
|
#!/usr/bin/env python
#
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Archives a set of files."""
import argparse
import os
import sys
import zipfile
from util import build_utils
def main(args):
args = build_utils.ExpandFileArgs(args)
parser = argparse.ArgumentParser(args)
parser.add_argument('--input-files', help='GN-list of files to zip.')
parser.add_argument(
'--input-files-base-dir',
help='Paths in the archive will be relative to this directory')
parser.add_argument('--input-zips', help='GN-list of zips to merge.')
parser.add_argument(
'--input-zips-excluded-globs',
help='GN-list of globs for paths to exclude.')
parser.add_argument('--output', required=True, help='Path to output archive.')
compress_group = parser.add_mutually_exclusive_group()
compress_group.add_argument(
'--compress', action='store_true', help='Compress entries')
compress_group.add_argument(
'--no-compress',
action='store_false',
dest='compress',
help='Do not compress entries')
build_utils.AddDepfileOption(parser)
options = parser.parse_args(args)
with build_utils.AtomicOutput(options.output) as f:
with zipfile.ZipFile(f.name, 'w') as out_zip:
depfile_deps = None
if options.input_files:
files = build_utils.ParseGnList(options.input_files)
build_utils.DoZip(
files,
out_zip,
base_dir=options.input_files_base_dir,
compress_fn=lambda _: options.compress)
if options.input_zips:
files = build_utils.ParseGnList(options.input_zips)
depfile_deps = files
path_transform = None
if options.input_zips_excluded_globs:
globs = build_utils.ParseGnList(options.input_zips_excluded_globs)
path_transform = (
lambda p: None if build_utils.MatchesGlob(p, globs) else p)
build_utils.MergeZips(
out_zip,
files,
path_transform=path_transform,
compress=options.compress)
# Depfile used only by dist_jar().
if options.depfile:
build_utils.WriteDepfile(
options.depfile, options.output, inputs=depfile_deps, add_pydeps=False)
if __name__ == '__main__':
main(sys.argv[1:])
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
624,
8438,
7602,
282,
663,
402,
1584,
1041,
199,
199,
646,
7534,
199,
646,
747,
199,
646,
984,
199,
646,
10392,
199,
199,
504,
4884,
492,
1900,
63,
1208,
421,
199,
318,
2446,
8,
589,
304,
523,
1249,
275,
1900,
63,
1208,
14,
12839,
1173,
6213,
8,
589,
9,
523,
1798,
275,
7534,
14,
10730,
8,
589,
9,
523,
1798,
14,
525,
63,
2094,
4517,
1210,
13,
1725,
297,
1720,
534,
15306,
13,
513,
402,
1584,
370,
3482,
2659,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
1210,
13,
1725,
13,
1095,
13,
694,
297,
489,
1720,
534,
11804,
315,
314,
6359,
911,
506,
3847,
370,
642,
2082,
358,
523,
1798,
14,
525,
63,
2094,
4517,
1210,
13,
3065,
83,
297,
1720,
534,
15306,
13,
513,
402,
3482,
83,
370,
5389,
2659,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
1210,
13,
3065,
83,
13,
12144,
13,
15581,
297,
489,
1720,
534,
15306,
13,
513,
402,
13977,
367,
3792,
370,
5760,
2659,
523,
1798,
14,
525,
63,
2094,
4517,
1199,
297,
1415,
29,
549,
12,
1720,
534,
2042,
370,
1072,
6359,
2659,
523,
11029,
63,
923,
275,
1798,
14,
525,
63,
25024,
63,
12730,
63,
923,
342,
523,
11029,
63,
923,
14,
525,
63,
2094,
8,
489,
2850,
6447,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
2404,
753,
4811,
358,
523,
11029,
63,
923,
14,
525,
63,
2094,
8,
489,
2850,
889,
13,
6447,
297,
489,
1595,
534,
1617,
63,
3910,
297,
489,
2053,
534,
6447,
297,
489,
1720,
534,
2585,
440,
11029,
4811,
358,
523,
1900,
63,
1208,
14,
1123,
8598,
493,
2602,
8,
2087,
9,
523,
1511,
275,
1798,
14,
1122,
63,
589,
8,
589,
9,
819,
543,
1900,
63,
1208,
14,
31931,
2959,
8,
1419,
14,
1199,
9,
465,
289,
26,
272,
543,
10392,
14,
15016,
8,
70,
14,
354,
12,
283,
87,
358,
465,
734,
63,
3065,
26,
489,
2657,
493,
63,
5846,
275,
488,
489,
340,
1511,
14,
1210,
63,
1725,
26,
267,
1584,
275,
1900,
63,
1208,
14,
4003,
39,
78,
1296,
8,
1419,
14,
1210,
63,
1725,
9,
267,
1900,
63,
1208,
14,
2585,
8674,
8,
288,
1584,
12,
288,
734,
63,
3065,
12,
288,
1300,
63,
694,
29,
1419,
14,
1210,
63,
1725,
63,
1095,
63,
694,
12,
288,
11029,
63,
2324,
29,
2734,
24700,
1511,
14,
6447,
9,
2541,
340,
1511,
14,
1210,
63,
3065,
83,
26,
267,
1584,
275,
1900,
63,
1208,
14,
4003,
39,
78,
1296,
8,
1419,
14,
1210,
63,
3065,
83,
9,
267,
2657,
493,
63,
5846,
275,
1584,
267,
931,
63,
4711,
275,
488,
267,
340,
1511,
14,
1210,
63,
3065,
83,
63,
12144,
63,
15581,
26,
881,
13977,
275,
1900,
63,
1208,
14,
4003,
39,
78,
1296,
8,
1419,
14,
1210,
63,
3065,
83,
63,
12144,
63,
15581,
9,
881,
931,
63,
4711,
275,
334,
1598,
2400,
299,
26,
488,
340,
1900,
63,
1208,
14,
12962,
25954,
8,
80,
12,
13977,
9,
587,
299,
9,
267,
1900,
63,
1208,
14,
11359,
58,
6142,
8,
288,
734,
63,
3065,
12,
288,
1584,
12,
288,
931,
63,
4711,
29,
515,
63,
4711,
12,
288,
11029,
29,
1419,
14,
6447,
9,
819,
327,
21588,
493,
1202,
1454,
701,
2917,
63,
7338,
1252,
523,
340,
1511,
14,
2601,
493,
26,
272,
1900,
63,
1208,
14,
3534,
8598,
493,
8,
267,
1511,
14,
2601,
493,
12,
1511,
14,
1199,
12,
4153,
29,
2601,
493,
63,
5846,
12,
1050,
63,
647,
5846,
29,
797,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2446,
8,
1274,
14,
3020,
59,
17,
5728,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
624,
8438,
7602,
282,
663,
402,
1584,
1041,
199,
199,
646,
7534,
199,
646,
747,
199,
646,
984,
199,
646,
10392,
199,
199,
504,
4884,
492,
1900,
63,
1208,
421,
199,
318,
2446,
8,
589,
304,
523,
1249,
275,
1900,
63,
1208,
14,
12839,
1173,
6213,
8,
589,
9,
523,
1798,
275,
7534,
14,
10730,
8,
589,
9,
523,
1798,
14,
525,
63,
2094,
4517,
1210,
13,
1725,
297,
1720,
534,
15306,
13,
513,
402,
1584,
370,
3482,
2659,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
1210,
13,
1725,
13,
1095,
13,
694,
297,
489,
1720,
534,
11804,
315,
314,
6359,
911,
506,
3847,
370,
642,
2082,
358,
523,
1798,
14,
525,
63,
2094,
4517,
1210,
13,
3065,
83,
297,
1720,
534,
15306,
13,
513,
402,
3482,
83,
370,
5389,
2659,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
1210,
13,
3065,
83,
13,
12144,
13,
15581,
297,
489,
1720,
534,
15306,
13,
513,
402,
13977,
367,
3792,
370,
5760,
2659,
523,
1798,
14,
525,
63,
2094,
4517,
1199,
297,
1415,
29,
549,
12,
1720,
534,
2042,
370,
1072,
6359,
2659,
523,
11029,
63,
923,
275,
1798,
14,
525,
63,
25024,
63,
12730,
63,
923,
342,
523,
11029,
63,
923,
14,
525,
63,
2094,
8,
489,
2850,
6447,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
2404,
753,
4811,
358,
523,
11029,
63,
923,
14,
525,
63,
2094,
8,
489,
2850,
889,
13,
6447,
297,
489,
1595,
534,
1617,
63,
3910,
297,
489,
2053,
534,
6447,
297,
489,
1720,
534,
2585,
440,
11029,
4811,
358,
523,
1900,
63,
1208,
14,
1123,
8598,
493,
2602,
8,
2087,
9,
523,
1511,
275,
1798,
14,
1122,
63,
589,
8,
589,
9,
819,
543,
1900,
63,
1208,
14,
31931,
2959,
8,
1419,
14,
1199,
9,
465,
289,
26,
272,
543,
10392,
14,
15016,
8,
70,
14,
354,
12,
283,
87,
358,
465,
734,
63,
3065,
26,
489,
2657,
493,
63,
5846,
275,
488,
489,
340,
1511,
14,
1210,
63,
1725,
26,
267,
1584,
275,
1900,
63,
1208,
14,
4003,
39,
78,
1296,
8,
1419,
14,
1210,
63,
1725,
9,
267,
1900,
63,
1208,
14,
2585,
8674,
8,
288,
1584,
12,
288,
734,
63,
3065,
12,
288,
1300,
63,
694,
29,
1419,
14,
1210,
63,
1725,
63,
1095,
63,
694,
12,
288,
11029,
63,
2324,
29,
2734,
24700,
1511,
14,
6447,
9,
2541,
340,
1511,
14,
1210,
63,
3065,
83,
26,
267,
1584,
275,
1900,
63,
1208,
14,
4003,
39,
78,
1296,
8,
1419,
14,
1210,
63,
3065,
83,
9,
267,
2657,
493,
63,
5846,
275,
1584,
267,
931,
63,
4711,
275,
488,
267,
340,
1511,
14,
1210,
63,
3065,
83,
63,
12144,
63,
15581,
26,
881,
13977,
275,
1900,
63,
1208,
14,
4003,
39,
78,
1296,
8,
1419,
14,
1210,
63,
3065,
83,
63,
12144,
63,
15581,
9,
881,
931,
63,
4711,
275,
334,
1598,
2400,
299,
26,
488,
340,
1900,
63,
1208,
14,
12962,
25954,
8,
80,
12,
13977,
9,
587,
299,
9,
267,
1900,
63,
1208,
14,
11359,
58,
6142,
8,
288,
734,
63,
3065,
12,
288,
1584,
12,
288,
931,
63,
4711,
29,
515,
63,
4711,
12,
288,
11029,
29,
1419,
14,
6447,
9,
819,
327,
21588,
493,
1202,
1454,
701,
2917,
63,
7338,
1252,
523,
340,
1511,
14,
2601,
493,
26,
272,
1900,
63,
1208,
14,
3534,
8598,
493,
8,
267,
1511,
14,
2601,
493,
12,
1511,
14,
1199,
12,
4153,
29,
2601,
493,
63,
5846,
12,
1050,
63,
647,
5846,
29,
797,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2446,
8,
1274,
14,
3020,
59,
17,
5728,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bubenkoff/pylama
|
dummy.py
|
3
|
3314
|
#!/usr/bin/env python
# coding: utf-8
# (c) 2005 Divmod, Inc. See LICENSE file for details
class Message(object):
message = ''
message_args = ()
def __init__(self, filename, loc, use_column=True):
self.filename = filename
self.lineno = loc.lineno
self.col = getattr(loc, 'col_offset', None) if use_column else None
def __str__(self):
return '%s:%s: %s' % (self.filename, self.lineno, self.message % self.message_args)
class UnusedImport(Message):
message = 'W402 %r imported but unused'
def __init__(self, filename, lineno, name):
Message.__init__(self, filename, lineno)
self.message_args = (name,)
class RedefinedWhileUnused(Message):
message = 'W801 redefinition of unused %r from line %r'
def __init__(self, filename, lineno, name, orig_lineno):
Message.__init__(self, filename, lineno)
self.message_args = (name, orig_lineno)
class ImportShadowedByLoopVar(Message):
message = 'W403 import %r from line %r shadowed by loop variable'
def __init__(self, filename, lineno, name, orig_lineno):
Message.__init__(self, filename, lineno)
self.message_args = (name, orig_lineno)
class ImportStarUsed(Message):
message = "W404 'from %s import *' used; unable to detect undefined names"
def __init__(self, filename, lineno, modname):
Message.__init__(self, filename, lineno)
self.message_args = (modname,)
class UndefinedName(Message):
message = 'W802 undefined name %r'
def __init__(self, filename, lineno, name):
Message.__init__(self, filename, lineno)
self.message_args = (name,)
class UndefinedExport(Message):
message = 'W803 undefined name %r in __all__'
def __init__(self, filename, lineno, name):
Message.__init__(self, filename, lineno)
self.message_args = (name,)
class UndefinedLocal(Message):
message = "W804 local variable %r (defined in enclosing scope on line " \
"%r) referenced before assignment"
def __init__(self, filename, lineno, name, orig_lineno):
Message.__init__(self, filename, lineno)
self.message_args = (name, orig_lineno)
class DuplicateArgument(Message):
message = 'W805 duplicate argument %r in function definition'
def __init__(self, filename, lineno, name):
Message.__init__(self, filename, lineno)
self.message_args = (name,)
class RedefinedFunction(Message):
message = 'W806 redefinition of function %r from line %r'
def __init__(self, filename, lineno, name, orig_lineno):
Message.__init__(self, filename, lineno)
self.message_args = (name, orig_lineno)
class LateFutureImport(Message):
message = 'W405 future import(s) %r after other statements'
def __init__(self, filename, lineno, names):
Message.__init__(self, filename, lineno)
self.message_args = (names,)
class UnusedVariable(Message):
"""
Indicates that a variable has been explicity assigned to but not actually
used.
"""
message = 'W806 local variable %r is assigned to but never used'
def __init__(self, filename, lineno, names):
Message.__init__(self, filename, lineno)
self.message_args = (names,)
error = 1 # noQa and some comments
|
lgpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2803,
26,
2774,
13,
24,
199,
3,
334,
67,
9,
11811,
32077,
1494,
12,
3277,
14,
221,
1666,
5113,
570,
367,
2436,
421,
199,
533,
6430,
8,
785,
304,
272,
1245,
275,
2125,
272,
1245,
63,
589,
275,
6248,
272,
347,
636,
826,
721,
277,
12,
1788,
12,
4355,
12,
675,
63,
2301,
29,
549,
304,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
3469,
275,
4355,
14,
3469,
267,
291,
14,
761,
275,
2519,
8,
2102,
12,
283,
761,
63,
2743,
297,
488,
9,
340,
675,
63,
2301,
587,
488,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
2689,
83,
26,
450,
83,
7,
450,
334,
277,
14,
1501,
12,
291,
14,
3469,
12,
291,
14,
1188,
450,
291,
14,
1188,
63,
589,
9,
421,
199,
533,
1910,
2972,
6295,
8,
2209,
304,
272,
1245,
275,
283,
55,
13314,
450,
82,
8439,
1325,
9563,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
4258,
421,
199,
533,
799,
4037,
25215,
20782,
8,
2209,
304,
272,
1245,
275,
283,
55,
26172,
295,
7463,
402,
9563,
450,
82,
687,
1004,
450,
82,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
12,
2306,
63,
3469,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
12,
2306,
63,
3469,
9,
421,
199,
533,
3161,
23574,
379,
2175,
7382,
5894,
8,
2209,
304,
272,
1245,
275,
283,
55,
13353,
492,
450,
82,
687,
1004,
450,
82,
15084,
379,
701,
4438,
1750,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
12,
2306,
63,
3469,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
12,
2306,
63,
3469,
9,
421,
199,
533,
3161,
23197,
9167,
8,
2209,
304,
272,
1245,
275,
298,
55,
5188,
283,
504,
450,
83,
492,
627,
7,
1202,
27,
17329,
370,
9696,
10942,
1561,
2,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
13526,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
14789,
4258,
421,
199,
533,
25868,
985,
8,
2209,
304,
272,
1245,
275,
283,
55,
11366,
10942,
536,
450,
82,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
4258,
421,
199,
533,
25868,
11399,
8,
2209,
304,
272,
1245,
275,
283,
55,
14187,
10942,
536,
450,
82,
315,
636,
452,
12217,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
4258,
421,
199,
533,
25868,
5339,
8,
2209,
304,
272,
1245,
275,
298,
55,
26073,
2257,
1750,
450,
82,
334,
4037,
315,
25188,
4194,
641,
1004,
298,
971,
288,
2071,
82,
9,
11812,
2544,
9801,
2,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
12,
2306,
63,
3469,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
12,
2306,
63,
3469,
9,
421,
199,
533,
23942,
5201,
8,
2209,
304,
272,
1245,
275,
283,
55,
13027,
9250,
1423,
450,
82,
315,
805,
5492,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
4258,
421,
199,
533,
799,
4037,
3481,
8,
2209,
304,
272,
1245,
275,
283,
55,
11901,
295,
7463,
402,
805,
450,
82,
687,
1004,
450,
82,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
12,
2306,
63,
3469,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
12,
2306,
63,
3469,
9,
421,
199,
533,
491,
323,
14224,
6295,
8,
2209,
304,
272,
1245,
275,
283,
55,
15770,
6466,
492,
8,
83,
9,
450,
82,
2410,
1163,
9834,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
1561,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
1247,
4258,
421,
199,
533,
1910,
2972,
2773,
8,
2209,
304,
272,
408,
272,
19334,
626,
282,
1750,
965,
2757,
1437,
20976,
7943,
370,
1325,
440,
5965,
272,
1202,
14,
272,
408,
339,
1245,
275,
283,
55,
11901,
2257,
1750,
450,
82,
365,
7943,
370,
1325,
7078,
1202,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
1561,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
1247,
4258,
267,
1125,
275,
413,
327,
949,
49,
65,
436,
2005,
6786,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2803,
26,
2774,
13,
24,
199,
3,
334,
67,
9,
11811,
32077,
1494,
12,
3277,
14,
221,
1666,
5113,
570,
367,
2436,
421,
199,
533,
6430,
8,
785,
304,
272,
1245,
275,
2125,
272,
1245,
63,
589,
275,
6248,
272,
347,
636,
826,
721,
277,
12,
1788,
12,
4355,
12,
675,
63,
2301,
29,
549,
304,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
3469,
275,
4355,
14,
3469,
267,
291,
14,
761,
275,
2519,
8,
2102,
12,
283,
761,
63,
2743,
297,
488,
9,
340,
675,
63,
2301,
587,
488,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
2689,
83,
26,
450,
83,
7,
450,
334,
277,
14,
1501,
12,
291,
14,
3469,
12,
291,
14,
1188,
450,
291,
14,
1188,
63,
589,
9,
421,
199,
533,
1910,
2972,
6295,
8,
2209,
304,
272,
1245,
275,
283,
55,
13314,
450,
82,
8439,
1325,
9563,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
4258,
421,
199,
533,
799,
4037,
25215,
20782,
8,
2209,
304,
272,
1245,
275,
283,
55,
26172,
295,
7463,
402,
9563,
450,
82,
687,
1004,
450,
82,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
12,
2306,
63,
3469,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
12,
2306,
63,
3469,
9,
421,
199,
533,
3161,
23574,
379,
2175,
7382,
5894,
8,
2209,
304,
272,
1245,
275,
283,
55,
13353,
492,
450,
82,
687,
1004,
450,
82,
15084,
379,
701,
4438,
1750,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
12,
2306,
63,
3469,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
12,
2306,
63,
3469,
9,
421,
199,
533,
3161,
23197,
9167,
8,
2209,
304,
272,
1245,
275,
298,
55,
5188,
283,
504,
450,
83,
492,
627,
7,
1202,
27,
17329,
370,
9696,
10942,
1561,
2,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
13526,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
14789,
4258,
421,
199,
533,
25868,
985,
8,
2209,
304,
272,
1245,
275,
283,
55,
11366,
10942,
536,
450,
82,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
4258,
421,
199,
533,
25868,
11399,
8,
2209,
304,
272,
1245,
275,
283,
55,
14187,
10942,
536,
450,
82,
315,
636,
452,
12217,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
4258,
421,
199,
533,
25868,
5339,
8,
2209,
304,
272,
1245,
275,
298,
55,
26073,
2257,
1750,
450,
82,
334,
4037,
315,
25188,
4194,
641,
1004,
298,
971,
288,
2071,
82,
9,
11812,
2544,
9801,
2,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
12,
2306,
63,
3469,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
12,
2306,
63,
3469,
9,
421,
199,
533,
23942,
5201,
8,
2209,
304,
272,
1245,
275,
283,
55,
13027,
9250,
1423,
450,
82,
315,
805,
5492,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
4258,
421,
199,
533,
799,
4037,
3481,
8,
2209,
304,
272,
1245,
275,
283,
55,
11901,
295,
7463,
402,
805,
450,
82,
687,
1004,
450,
82,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
536,
12,
2306,
63,
3469,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
354,
12,
2306,
63,
3469,
9,
421,
199,
533,
491,
323,
14224,
6295,
8,
2209,
304,
272,
1245,
275,
283,
55,
15770,
6466,
492,
8,
83,
9,
450,
82,
2410,
1163,
9834,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
1561,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
1247,
4258,
421,
199,
533,
1910,
2972,
2773,
8,
2209,
304,
272,
408,
272,
19334,
626,
282,
1750,
965,
2757,
1437,
20976,
7943,
370,
1325,
440,
5965,
272,
1202,
14,
272,
408,
339,
1245,
275,
283,
55,
11901,
2257,
1750,
450,
82,
365,
7943,
370,
1325,
7078,
1202,
7,
339,
347,
636,
826,
721,
277,
12,
1788,
12,
5874,
12,
1561,
304,
267,
6430,
855,
826,
721,
277,
12,
1788,
12,
5874,
9,
267,
291,
14,
1188,
63,
589,
275,
334,
1247,
4258,
267,
1125,
275,
413,
327,
949,
49,
65,
436,
2005,
6786,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
firerszd/kbengine
|
kbe/src/lib/python/Lib/encodings/cp273.py
|
212
|
14132
|
""" Python Character Mapping Codec cp273 generated from 'python-mappings/CP273.TXT' with gencodec.py.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_table)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_table)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='cp273',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
### Decoding Table
decoding_table = (
'\x00' # 0x00 -> NULL (NUL)
'\x01' # 0x01 -> START OF HEADING (SOH)
'\x02' # 0x02 -> START OF TEXT (STX)
'\x03' # 0x03 -> END OF TEXT (ETX)
'\x9c' # 0x04 -> STRING TERMINATOR (ST)
'\t' # 0x05 -> CHARACTER TABULATION (HT)
'\x86' # 0x06 -> START OF SELECTED AREA (SSA)
'\x7f' # 0x07 -> DELETE (DEL)
'\x97' # 0x08 -> END OF GUARDED AREA (EPA)
'\x8d' # 0x09 -> REVERSE LINE FEED (RI)
'\x8e' # 0x0A -> SINGLE-SHIFT TWO (SS2)
'\x0b' # 0x0B -> LINE TABULATION (VT)
'\x0c' # 0x0C -> FORM FEED (FF)
'\r' # 0x0D -> CARRIAGE RETURN (CR)
'\x0e' # 0x0E -> SHIFT OUT (SO)
'\x0f' # 0x0F -> SHIFT IN (SI)
'\x10' # 0x10 -> DATALINK ESCAPE (DLE)
'\x11' # 0x11 -> DEVICE CONTROL ONE (DC1)
'\x12' # 0x12 -> DEVICE CONTROL TWO (DC2)
'\x13' # 0x13 -> DEVICE CONTROL THREE (DC3)
'\x9d' # 0x14 -> OPERATING SYSTEM COMMAND (OSC)
'\x85' # 0x15 -> NEXT LINE (NEL)
'\x08' # 0x16 -> BACKSPACE (BS)
'\x87' # 0x17 -> END OF SELECTED AREA (ESA)
'\x18' # 0x18 -> CANCEL (CAN)
'\x19' # 0x19 -> END OF MEDIUM (EM)
'\x92' # 0x1A -> PRIVATE USE TWO (PU2)
'\x8f' # 0x1B -> SINGLE-SHIFT THREE (SS3)
'\x1c' # 0x1C -> FILE SEPARATOR (IS4)
'\x1d' # 0x1D -> GROUP SEPARATOR (IS3)
'\x1e' # 0x1E -> RECORD SEPARATOR (IS2)
'\x1f' # 0x1F -> UNIT SEPARATOR (IS1)
'\x80' # 0x20 -> PADDING CHARACTER (PAD)
'\x81' # 0x21 -> HIGH OCTET PRESET (HOP)
'\x82' # 0x22 -> BREAK PERMITTED HERE (BPH)
'\x83' # 0x23 -> NO BREAK HERE (NBH)
'\x84' # 0x24 -> INDEX (IND)
'\n' # 0x25 -> LINE FEED (LF)
'\x17' # 0x26 -> END OF TRANSMISSION BLOCK (ETB)
'\x1b' # 0x27 -> ESCAPE (ESC)
'\x88' # 0x28 -> CHARACTER TABULATION SET (HTS)
'\x89' # 0x29 -> CHARACTER TABULATION WITH JUSTIFICATION (HTJ)
'\x8a' # 0x2A -> LINE TABULATION SET (VTS)
'\x8b' # 0x2B -> PARTIAL LINE FORWARD (PLD)
'\x8c' # 0x2C -> PARTIAL LINE BACKWARD (PLU)
'\x05' # 0x2D -> ENQUIRY (ENQ)
'\x06' # 0x2E -> ACKNOWLEDGE (ACK)
'\x07' # 0x2F -> BELL (BEL)
'\x90' # 0x30 -> DEVICE CONTROL STRING (DCS)
'\x91' # 0x31 -> PRIVATE USE ONE (PU1)
'\x16' # 0x32 -> SYNCHRONOUS IDLE (SYN)
'\x93' # 0x33 -> SET TRANSMIT STATE (STS)
'\x94' # 0x34 -> CANCEL CHARACTER (CCH)
'\x95' # 0x35 -> MESSAGE WAITING (MW)
'\x96' # 0x36 -> START OF GUARDED AREA (SPA)
'\x04' # 0x37 -> END OF TRANSMISSION (EOT)
'\x98' # 0x38 -> START OF STRING (SOS)
'\x99' # 0x39 -> SINGLE GRAPHIC CHARACTER INTRODUCER (SGCI)
'\x9a' # 0x3A -> SINGLE CHARACTER INTRODUCER (SCI)
'\x9b' # 0x3B -> CONTROL SEQUENCE INTRODUCER (CSI)
'\x14' # 0x3C -> DEVICE CONTROL FOUR (DC4)
'\x15' # 0x3D -> NEGATIVE ACKNOWLEDGE (NAK)
'\x9e' # 0x3E -> PRIVACY MESSAGE (PM)
'\x1a' # 0x3F -> SUBSTITUTE (SUB)
' ' # 0x40 -> SPACE
'\xa0' # 0x41 -> NO-BREAK SPACE
'\xe2' # 0x42 -> LATIN SMALL LETTER A WITH CIRCUMFLEX
'{' # 0x43 -> LEFT CURLY BRACKET
'\xe0' # 0x44 -> LATIN SMALL LETTER A WITH GRAVE
'\xe1' # 0x45 -> LATIN SMALL LETTER A WITH ACUTE
'\xe3' # 0x46 -> LATIN SMALL LETTER A WITH TILDE
'\xe5' # 0x47 -> LATIN SMALL LETTER A WITH RING ABOVE
'\xe7' # 0x48 -> LATIN SMALL LETTER C WITH CEDILLA
'\xf1' # 0x49 -> LATIN SMALL LETTER N WITH TILDE
'\xc4' # 0x4A -> LATIN CAPITAL LETTER A WITH DIAERESIS
'.' # 0x4B -> FULL STOP
'<' # 0x4C -> LESS-THAN SIGN
'(' # 0x4D -> LEFT PARENTHESIS
'+' # 0x4E -> PLUS SIGN
'!' # 0x4F -> EXCLAMATION MARK
'&' # 0x50 -> AMPERSAND
'\xe9' # 0x51 -> LATIN SMALL LETTER E WITH ACUTE
'\xea' # 0x52 -> LATIN SMALL LETTER E WITH CIRCUMFLEX
'\xeb' # 0x53 -> LATIN SMALL LETTER E WITH DIAERESIS
'\xe8' # 0x54 -> LATIN SMALL LETTER E WITH GRAVE
'\xed' # 0x55 -> LATIN SMALL LETTER I WITH ACUTE
'\xee' # 0x56 -> LATIN SMALL LETTER I WITH CIRCUMFLEX
'\xef' # 0x57 -> LATIN SMALL LETTER I WITH DIAERESIS
'\xec' # 0x58 -> LATIN SMALL LETTER I WITH GRAVE
'~' # 0x59 -> TILDE
'\xdc' # 0x5A -> LATIN CAPITAL LETTER U WITH DIAERESIS
'$' # 0x5B -> DOLLAR SIGN
'*' # 0x5C -> ASTERISK
')' # 0x5D -> RIGHT PARENTHESIS
';' # 0x5E -> SEMICOLON
'^' # 0x5F -> CIRCUMFLEX ACCENT
'-' # 0x60 -> HYPHEN-MINUS
'/' # 0x61 -> SOLIDUS
'\xc2' # 0x62 -> LATIN CAPITAL LETTER A WITH CIRCUMFLEX
'[' # 0x63 -> LEFT SQUARE BRACKET
'\xc0' # 0x64 -> LATIN CAPITAL LETTER A WITH GRAVE
'\xc1' # 0x65 -> LATIN CAPITAL LETTER A WITH ACUTE
'\xc3' # 0x66 -> LATIN CAPITAL LETTER A WITH TILDE
'\xc5' # 0x67 -> LATIN CAPITAL LETTER A WITH RING ABOVE
'\xc7' # 0x68 -> LATIN CAPITAL LETTER C WITH CEDILLA
'\xd1' # 0x69 -> LATIN CAPITAL LETTER N WITH TILDE
'\xf6' # 0x6A -> LATIN SMALL LETTER O WITH DIAERESIS
',' # 0x6B -> COMMA
'%' # 0x6C -> PERCENT SIGN
'_' # 0x6D -> LOW LINE
'>' # 0x6E -> GREATER-THAN SIGN
'?' # 0x6F -> QUESTION MARK
'\xf8' # 0x70 -> LATIN SMALL LETTER O WITH STROKE
'\xc9' # 0x71 -> LATIN CAPITAL LETTER E WITH ACUTE
'\xca' # 0x72 -> LATIN CAPITAL LETTER E WITH CIRCUMFLEX
'\xcb' # 0x73 -> LATIN CAPITAL LETTER E WITH DIAERESIS
'\xc8' # 0x74 -> LATIN CAPITAL LETTER E WITH GRAVE
'\xcd' # 0x75 -> LATIN CAPITAL LETTER I WITH ACUTE
'\xce' # 0x76 -> LATIN CAPITAL LETTER I WITH CIRCUMFLEX
'\xcf' # 0x77 -> LATIN CAPITAL LETTER I WITH DIAERESIS
'\xcc' # 0x78 -> LATIN CAPITAL LETTER I WITH GRAVE
'`' # 0x79 -> GRAVE ACCENT
':' # 0x7A -> COLON
'#' # 0x7B -> NUMBER SIGN
'\xa7' # 0x7C -> SECTION SIGN
"'" # 0x7D -> APOSTROPHE
'=' # 0x7E -> EQUALS SIGN
'"' # 0x7F -> QUOTATION MARK
'\xd8' # 0x80 -> LATIN CAPITAL LETTER O WITH STROKE
'a' # 0x81 -> LATIN SMALL LETTER A
'b' # 0x82 -> LATIN SMALL LETTER B
'c' # 0x83 -> LATIN SMALL LETTER C
'd' # 0x84 -> LATIN SMALL LETTER D
'e' # 0x85 -> LATIN SMALL LETTER E
'f' # 0x86 -> LATIN SMALL LETTER F
'g' # 0x87 -> LATIN SMALL LETTER G
'h' # 0x88 -> LATIN SMALL LETTER H
'i' # 0x89 -> LATIN SMALL LETTER I
'\xab' # 0x8A -> LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
'\xbb' # 0x8B -> RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
'\xf0' # 0x8C -> LATIN SMALL LETTER ETH (Icelandic)
'\xfd' # 0x8D -> LATIN SMALL LETTER Y WITH ACUTE
'\xfe' # 0x8E -> LATIN SMALL LETTER THORN (Icelandic)
'\xb1' # 0x8F -> PLUS-MINUS SIGN
'\xb0' # 0x90 -> DEGREE SIGN
'j' # 0x91 -> LATIN SMALL LETTER J
'k' # 0x92 -> LATIN SMALL LETTER K
'l' # 0x93 -> LATIN SMALL LETTER L
'm' # 0x94 -> LATIN SMALL LETTER M
'n' # 0x95 -> LATIN SMALL LETTER N
'o' # 0x96 -> LATIN SMALL LETTER O
'p' # 0x97 -> LATIN SMALL LETTER P
'q' # 0x98 -> LATIN SMALL LETTER Q
'r' # 0x99 -> LATIN SMALL LETTER R
'\xaa' # 0x9A -> FEMININE ORDINAL INDICATOR
'\xba' # 0x9B -> MASCULINE ORDINAL INDICATOR
'\xe6' # 0x9C -> LATIN SMALL LETTER AE
'\xb8' # 0x9D -> CEDILLA
'\xc6' # 0x9E -> LATIN CAPITAL LETTER AE
'\xa4' # 0x9F -> CURRENCY SIGN
'\xb5' # 0xA0 -> MICRO SIGN
'\xdf' # 0xA1 -> LATIN SMALL LETTER SHARP S (German)
's' # 0xA2 -> LATIN SMALL LETTER S
't' # 0xA3 -> LATIN SMALL LETTER T
'u' # 0xA4 -> LATIN SMALL LETTER U
'v' # 0xA5 -> LATIN SMALL LETTER V
'w' # 0xA6 -> LATIN SMALL LETTER W
'x' # 0xA7 -> LATIN SMALL LETTER X
'y' # 0xA8 -> LATIN SMALL LETTER Y
'z' # 0xA9 -> LATIN SMALL LETTER Z
'\xa1' # 0xAA -> INVERTED EXCLAMATION MARK
'\xbf' # 0xAB -> INVERTED QUESTION MARK
'\xd0' # 0xAC -> LATIN CAPITAL LETTER ETH (Icelandic)
'\xdd' # 0xAD -> LATIN CAPITAL LETTER Y WITH ACUTE
'\xde' # 0xAE -> LATIN CAPITAL LETTER THORN (Icelandic)
'\xae' # 0xAF -> REGISTERED SIGN
'\xa2' # 0xB0 -> CENT SIGN
'\xa3' # 0xB1 -> POUND SIGN
'\xa5' # 0xB2 -> YEN SIGN
'\xb7' # 0xB3 -> MIDDLE DOT
'\xa9' # 0xB4 -> COPYRIGHT SIGN
'@' # 0xB5 -> COMMERCIAL AT
'\xb6' # 0xB6 -> PILCROW SIGN
'\xbc' # 0xB7 -> VULGAR FRACTION ONE QUARTER
'\xbd' # 0xB8 -> VULGAR FRACTION ONE HALF
'\xbe' # 0xB9 -> VULGAR FRACTION THREE QUARTERS
'\xac' # 0xBA -> NOT SIGN
'|' # 0xBB -> VERTICAL LINE
'\u203e' # 0xBC -> OVERLINE
'\xa8' # 0xBD -> DIAERESIS
'\xb4' # 0xBE -> ACUTE ACCENT
'\xd7' # 0xBF -> MULTIPLICATION SIGN
'\xe4' # 0xC0 -> LATIN SMALL LETTER A WITH DIAERESIS
'A' # 0xC1 -> LATIN CAPITAL LETTER A
'B' # 0xC2 -> LATIN CAPITAL LETTER B
'C' # 0xC3 -> LATIN CAPITAL LETTER C
'D' # 0xC4 -> LATIN CAPITAL LETTER D
'E' # 0xC5 -> LATIN CAPITAL LETTER E
'F' # 0xC6 -> LATIN CAPITAL LETTER F
'G' # 0xC7 -> LATIN CAPITAL LETTER G
'H' # 0xC8 -> LATIN CAPITAL LETTER H
'I' # 0xC9 -> LATIN CAPITAL LETTER I
'\xad' # 0xCA -> SOFT HYPHEN
'\xf4' # 0xCB -> LATIN SMALL LETTER O WITH CIRCUMFLEX
'\xa6' # 0xCC -> BROKEN BAR
'\xf2' # 0xCD -> LATIN SMALL LETTER O WITH GRAVE
'\xf3' # 0xCE -> LATIN SMALL LETTER O WITH ACUTE
'\xf5' # 0xCF -> LATIN SMALL LETTER O WITH TILDE
'\xfc' # 0xD0 -> LATIN SMALL LETTER U WITH DIAERESIS
'J' # 0xD1 -> LATIN CAPITAL LETTER J
'K' # 0xD2 -> LATIN CAPITAL LETTER K
'L' # 0xD3 -> LATIN CAPITAL LETTER L
'M' # 0xD4 -> LATIN CAPITAL LETTER M
'N' # 0xD5 -> LATIN CAPITAL LETTER N
'O' # 0xD6 -> LATIN CAPITAL LETTER O
'P' # 0xD7 -> LATIN CAPITAL LETTER P
'Q' # 0xD8 -> LATIN CAPITAL LETTER Q
'R' # 0xD9 -> LATIN CAPITAL LETTER R
'\xb9' # 0xDA -> SUPERSCRIPT ONE
'\xfb' # 0xDB -> LATIN SMALL LETTER U WITH CIRCUMFLEX
'}' # 0xDC -> RIGHT CURLY BRACKET
'\xf9' # 0xDD -> LATIN SMALL LETTER U WITH GRAVE
'\xfa' # 0xDE -> LATIN SMALL LETTER U WITH ACUTE
'\xff' # 0xDF -> LATIN SMALL LETTER Y WITH DIAERESIS
'\xd6' # 0xE0 -> LATIN CAPITAL LETTER O WITH DIAERESIS
'\xf7' # 0xE1 -> DIVISION SIGN
'S' # 0xE2 -> LATIN CAPITAL LETTER S
'T' # 0xE3 -> LATIN CAPITAL LETTER T
'U' # 0xE4 -> LATIN CAPITAL LETTER U
'V' # 0xE5 -> LATIN CAPITAL LETTER V
'W' # 0xE6 -> LATIN CAPITAL LETTER W
'X' # 0xE7 -> LATIN CAPITAL LETTER X
'Y' # 0xE8 -> LATIN CAPITAL LETTER Y
'Z' # 0xE9 -> LATIN CAPITAL LETTER Z
'\xb2' # 0xEA -> SUPERSCRIPT TWO
'\xd4' # 0xEB -> LATIN CAPITAL LETTER O WITH CIRCUMFLEX
'\\' # 0xEC -> REVERSE SOLIDUS
'\xd2' # 0xED -> LATIN CAPITAL LETTER O WITH GRAVE
'\xd3' # 0xEE -> LATIN CAPITAL LETTER O WITH ACUTE
'\xd5' # 0xEF -> LATIN CAPITAL LETTER O WITH TILDE
'0' # 0xF0 -> DIGIT ZERO
'1' # 0xF1 -> DIGIT ONE
'2' # 0xF2 -> DIGIT TWO
'3' # 0xF3 -> DIGIT THREE
'4' # 0xF4 -> DIGIT FOUR
'5' # 0xF5 -> DIGIT FIVE
'6' # 0xF6 -> DIGIT SIX
'7' # 0xF7 -> DIGIT SEVEN
'8' # 0xF8 -> DIGIT EIGHT
'9' # 0xF9 -> DIGIT NINE
'\xb3' # 0xFA -> SUPERSCRIPT THREE
'\xdb' # 0xFB -> LATIN CAPITAL LETTER U WITH CIRCUMFLEX
']' # 0xFC -> RIGHT SQUARE BRACKET
'\xd9' # 0xFD -> LATIN CAPITAL LETTER U WITH GRAVE
'\xda' # 0xFE -> LATIN CAPITAL LETTER U WITH ACUTE
'\x9f' # 0xFF -> APPLICATION PROGRAM COMMAND (APC)
)
### Encoding table
encoding_table=codecs.charmap_build(decoding_table)
|
lgpl-3.0
|
[
624,
2018,
17660,
12340,
13732,
7667,
15000,
4046,
687,
283,
1548,
13,
14632,
15,
2890,
15000,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1850,
15000,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
421,
199,
5680,
27368,
6957,
199,
199,
12796,
63,
1224,
275,
334,
272,
1557,
88,
383,
7,
420,
327,
221,
378,
88,
383,
1035,
5962,
334,
46,
1293,
9,
272,
1557,
88,
614,
7,
420,
327,
221,
378,
88,
614,
1035,
13910,
1634,
32674,
334,
4118,
40,
9,
272,
1557,
88,
996,
7,
420,
327,
221,
378,
88,
996,
1035,
13910,
1634,
11951,
334,
840,
56,
9,
272,
1557,
88,
1644,
7,
420,
327,
221,
378,
88,
1644,
1035,
7729,
1634,
11951,
334,
775,
56,
9,
272,
1557,
88,
25,
67,
7,
420,
327,
221,
378,
88,
966,
1035,
18661,
31510,
4896,
6467,
334,
840,
9,
272,
1557,
84,
7,
263,
327,
221,
378,
88,
1717,
1035,
9502,
22450,
334,
2148,
9,
272,
1557,
88,
1184,
7,
420,
327,
221,
378,
88,
1690,
1035,
13910,
1634,
10468,
1149,
9315,
33,
334,
2300,
33,
9,
272,
1557,
88,
23,
70,
7,
420,
327,
221,
378,
88,
1780,
1035,
15137,
334,
4424,
9,
272,
1557,
88,
2576,
7,
420,
327,
221,
378,
88,
2036,
1035,
7729,
1634,
598,
53,
689,
8280,
9315,
33,
334,
6102,
33,
9,
272,
1557,
88,
24,
68,
7,
420,
327,
221,
378,
88,
1643,
1035,
28229,
13587,
21567,
334,
6129,
9,
272,
1557,
88,
24,
69,
7,
420,
327,
221,
378,
88,
16,
33,
1035,
8655,
13,
18013,
16562,
334,
2300,
18,
9,
272,
1557,
88,
16,
66,
7,
420,
327,
221,
378,
88,
16,
34,
1035,
13587,
22450,
334,
8156,
9,
272,
1557,
88,
16,
67,
7,
420,
327,
221,
378,
88,
16,
35,
1035,
11295,
21567,
334,
1665,
9,
272,
1557,
82,
7,
263,
327,
221,
378,
88,
16,
36,
1035,
445,
32622,
24646,
334,
2944,
9,
272,
1557,
88,
16,
69,
7,
420,
327,
221,
378,
88,
16,
37,
1035,
20754,
5738,
334,
4118,
9,
272,
1557,
88,
16,
70,
7,
420,
327,
221,
378,
88,
16,
38,
1035,
20754,
1621,
334,
2684,
9,
272,
1557,
88,
709,
7,
420,
327,
221,
378,
88,
709,
1035,
17971,
748,
12394,
17682,
334,
36,
906,
9,
272,
1557,
88,
845,
7,
420,
327,
221,
378,
88,
845,
1035,
11643,
8098,
13051,
334,
5196,
17,
9,
272,
1557,
88,
713,
7,
420,
327,
221,
378,
88,
713,
1035,
11643,
8098,
16562,
334,
5196,
18,
9,
272,
1557,
88,
969,
7,
420,
327,
221,
378,
88,
969,
1035,
11643,
8098,
16296,
334,
5196,
19,
9,
272,
1557,
88,
25,
68,
7,
420,
327,
221,
378,
88,
1079,
1035,
29771,
27186,
20859,
25965,
334,
31799,
9,
272,
1557,
88,
2426,
7,
420,
327,
221,
378,
88,
1046,
1035,
653,
2472,
13587,
334,
11301,
9,
272,
1557,
88,
2036,
7,
420,
327,
221,
378,
88,
975,
1035,
22658,
11658,
334,
11087,
9,
272,
1557,
88,
1555,
7,
420,
327,
221,
378,
88,
1196,
1035,
7729,
1634,
10468,
1149,
9315,
33,
334,
654,
33,
9,
272,
1557,
88,
1085,
7,
420,
327,
221,
378,
88,
1085,
1035,
27385,
334,
18988,
9,
272,
1557,
88,
1167,
7,
420,
327,
221,
378,
88,
1167,
1035,
7729,
1634,
22650,
334,
2769,
9,
272,
1557,
88,
2942,
7,
420,
327,
221,
378,
88,
17,
33,
1035,
28644,
1951,
4815,
16562,
334,
6903,
18,
9,
272,
1557,
88,
24,
70,
7,
420,
327,
221,
378,
88,
17,
34,
1035,
8655,
13,
18013,
16296,
334,
2300,
19,
9,
272,
1557,
88,
17,
67,
7,
420,
327,
221,
378,
88,
17,
35,
1035,
13024,
14782,
334,
1311,
20,
9,
272,
1557,
88,
17,
68,
7,
420,
327,
221,
378,
88,
17,
36,
1035,
15443,
14782,
334,
1311,
19,
9,
272,
1557,
88,
17,
69,
7,
420,
327,
221,
378,
88,
17,
37,
1035,
24973,
14782,
334,
1311,
18,
9,
272,
1557,
88,
17,
70,
7,
420,
327,
221,
378,
88,
17,
38,
1035,
25836,
14782,
334,
1311,
17,
9,
272,
1557,
88,
1257,
7,
420,
327,
221,
378,
88,
1165,
1035,
510,
9732,
1206,
9502,
334,
32420,
9,
272,
1557,
88,
2835,
7,
420,
327,
221,
378,
88,
2025,
1035,
869,
13454,
593,
1028,
775,
510,
18066,
334,
40,
1938,
9,
272,
1557,
88,
2564,
7,
420,
327,
221,
378,
88,
1081,
1035,
31902,
7872,
13873,
13965,
52,
1149,
869,
28106,
334,
34,
9791,
9,
272,
1557,
88,
2658,
7,
420,
327,
221,
378,
88,
1789,
1035,
4825,
31902,
7872,
869,
28106,
334,
16170,
40,
9,
272,
1557,
88,
1349,
7,
420,
327,
221,
378,
88,
1194,
1035,
17055,
334,
3192,
9,
272,
1557,
78,
7,
263,
327,
221,
378,
88,
821,
1035,
13587,
21567,
334,
15965,
9,
272,
1557,
88
] |
[
2018,
17660,
12340,
13732,
7667,
15000,
4046,
687,
283,
1548,
13,
14632,
15,
2890,
15000,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
1850,
15000,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
421,
199,
5680,
27368,
6957,
199,
199,
12796,
63,
1224,
275,
334,
272,
1557,
88,
383,
7,
420,
327,
221,
378,
88,
383,
1035,
5962,
334,
46,
1293,
9,
272,
1557,
88,
614,
7,
420,
327,
221,
378,
88,
614,
1035,
13910,
1634,
32674,
334,
4118,
40,
9,
272,
1557,
88,
996,
7,
420,
327,
221,
378,
88,
996,
1035,
13910,
1634,
11951,
334,
840,
56,
9,
272,
1557,
88,
1644,
7,
420,
327,
221,
378,
88,
1644,
1035,
7729,
1634,
11951,
334,
775,
56,
9,
272,
1557,
88,
25,
67,
7,
420,
327,
221,
378,
88,
966,
1035,
18661,
31510,
4896,
6467,
334,
840,
9,
272,
1557,
84,
7,
263,
327,
221,
378,
88,
1717,
1035,
9502,
22450,
334,
2148,
9,
272,
1557,
88,
1184,
7,
420,
327,
221,
378,
88,
1690,
1035,
13910,
1634,
10468,
1149,
9315,
33,
334,
2300,
33,
9,
272,
1557,
88,
23,
70,
7,
420,
327,
221,
378,
88,
1780,
1035,
15137,
334,
4424,
9,
272,
1557,
88,
2576,
7,
420,
327,
221,
378,
88,
2036,
1035,
7729,
1634,
598,
53,
689,
8280,
9315,
33,
334,
6102,
33,
9,
272,
1557,
88,
24,
68,
7,
420,
327,
221,
378,
88,
1643,
1035,
28229,
13587,
21567,
334,
6129,
9,
272,
1557,
88,
24,
69,
7,
420,
327,
221,
378,
88,
16,
33,
1035,
8655,
13,
18013,
16562,
334,
2300,
18,
9,
272,
1557,
88,
16,
66,
7,
420,
327,
221,
378,
88,
16,
34,
1035,
13587,
22450,
334,
8156,
9,
272,
1557,
88,
16,
67,
7,
420,
327,
221,
378,
88,
16,
35,
1035,
11295,
21567,
334,
1665,
9,
272,
1557,
82,
7,
263,
327,
221,
378,
88,
16,
36,
1035,
445,
32622,
24646,
334,
2944,
9,
272,
1557,
88,
16,
69,
7,
420,
327,
221,
378,
88,
16,
37,
1035,
20754,
5738,
334,
4118,
9,
272,
1557,
88,
16,
70,
7,
420,
327,
221,
378,
88,
16,
38,
1035,
20754,
1621,
334,
2684,
9,
272,
1557,
88,
709,
7,
420,
327,
221,
378,
88,
709,
1035,
17971,
748,
12394,
17682,
334,
36,
906,
9,
272,
1557,
88,
845,
7,
420,
327,
221,
378,
88,
845,
1035,
11643,
8098,
13051,
334,
5196,
17,
9,
272,
1557,
88,
713,
7,
420,
327,
221,
378,
88,
713,
1035,
11643,
8098,
16562,
334,
5196,
18,
9,
272,
1557,
88,
969,
7,
420,
327,
221,
378,
88,
969,
1035,
11643,
8098,
16296,
334,
5196,
19,
9,
272,
1557,
88,
25,
68,
7,
420,
327,
221,
378,
88,
1079,
1035,
29771,
27186,
20859,
25965,
334,
31799,
9,
272,
1557,
88,
2426,
7,
420,
327,
221,
378,
88,
1046,
1035,
653,
2472,
13587,
334,
11301,
9,
272,
1557,
88,
2036,
7,
420,
327,
221,
378,
88,
975,
1035,
22658,
11658,
334,
11087,
9,
272,
1557,
88,
1555,
7,
420,
327,
221,
378,
88,
1196,
1035,
7729,
1634,
10468,
1149,
9315,
33,
334,
654,
33,
9,
272,
1557,
88,
1085,
7,
420,
327,
221,
378,
88,
1085,
1035,
27385,
334,
18988,
9,
272,
1557,
88,
1167,
7,
420,
327,
221,
378,
88,
1167,
1035,
7729,
1634,
22650,
334,
2769,
9,
272,
1557,
88,
2942,
7,
420,
327,
221,
378,
88,
17,
33,
1035,
28644,
1951,
4815,
16562,
334,
6903,
18,
9,
272,
1557,
88,
24,
70,
7,
420,
327,
221,
378,
88,
17,
34,
1035,
8655,
13,
18013,
16296,
334,
2300,
19,
9,
272,
1557,
88,
17,
67,
7,
420,
327,
221,
378,
88,
17,
35,
1035,
13024,
14782,
334,
1311,
20,
9,
272,
1557,
88,
17,
68,
7,
420,
327,
221,
378,
88,
17,
36,
1035,
15443,
14782,
334,
1311,
19,
9,
272,
1557,
88,
17,
69,
7,
420,
327,
221,
378,
88,
17,
37,
1035,
24973,
14782,
334,
1311,
18,
9,
272,
1557,
88,
17,
70,
7,
420,
327,
221,
378,
88,
17,
38,
1035,
25836,
14782,
334,
1311,
17,
9,
272,
1557,
88,
1257,
7,
420,
327,
221,
378,
88,
1165,
1035,
510,
9732,
1206,
9502,
334,
32420,
9,
272,
1557,
88,
2835,
7,
420,
327,
221,
378,
88,
2025,
1035,
869,
13454,
593,
1028,
775,
510,
18066,
334,
40,
1938,
9,
272,
1557,
88,
2564,
7,
420,
327,
221,
378,
88,
1081,
1035,
31902,
7872,
13873,
13965,
52,
1149,
869,
28106,
334,
34,
9791,
9,
272,
1557,
88,
2658,
7,
420,
327,
221,
378,
88,
1789,
1035,
4825,
31902,
7872,
869,
28106,
334,
16170,
40,
9,
272,
1557,
88,
1349,
7,
420,
327,
221,
378,
88,
1194,
1035,
17055,
334,
3192,
9,
272,
1557,
78,
7,
263,
327,
221,
378,
88,
821,
1035,
13587,
21567,
334,
15965,
9,
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,
1,
1,
1,
1,
1
] |
redbear/micropython
|
esp8266/scripts/onewire.py
|
8
|
3338
|
# 1-Wire driver for MicroPython on ESP8266
# MIT license; Copyright (c) 2016 Damien P. George
import _onewire as _ow
class OneWireError(Exception):
pass
class OneWire:
SEARCH_ROM = const(0xf0)
MATCH_ROM = const(0x55)
SKIP_ROM = const(0xcc)
def __init__(self, pin):
self.pin = pin
self.pin.init(pin.OPEN_DRAIN)
def reset(self):
return _ow.reset(self.pin)
def readbit(self):
return _ow.readbit(self.pin)
def readbyte(self):
return _ow.readbyte(self.pin)
def read(self, count):
buf = bytearray(count)
for i in range(count):
buf[i] = _ow.readbyte(self.pin)
return buf
def writebit(self, value):
return _ow.writebit(self.pin, value)
def writebyte(self, value):
return _ow.writebyte(self.pin, value)
def write(self, buf):
for b in buf:
_ow.writebyte(self.pin, b)
def select_rom(self, rom):
self.reset()
self.writebyte(MATCH_ROM)
self.write(rom)
def scan(self):
devices = []
diff = 65
rom = False
for i in range(0xff):
rom, diff = self._search_rom(rom, diff)
if rom:
devices += [rom]
if diff == 0:
break
return devices
def _search_rom(self, l_rom, diff):
if not self.reset():
return None, 0
self.writebyte(SEARCH_ROM)
if not l_rom:
l_rom = bytearray(8)
rom = bytearray(8)
next_diff = 0
i = 64
for byte in range(8):
r_b = 0
for bit in range(8):
b = self.readbit()
if self.readbit():
if b: # there are no devices or there is an error on the bus
return None, 0
else:
if not b: # collision, two devices with different bit meaning
if diff > i or ((l_rom[byte] & (1 << bit)) and diff != i):
b = 1
next_diff = i
self.writebit(b)
if b:
r_b |= 1 << bit
i -= 1
rom[byte] = r_b
return rom, next_diff
def crc8(self, data):
return _ow.crc8(data)
class DS18B20:
CONVERT = const(0x44)
RD_SCRATCH = const(0xbe)
WR_SCRATCH = const(0x4e)
def __init__(self, onewire):
self.ow = onewire
def scan(self):
return [rom for rom in self.ow.scan() if rom[0] == 0x28]
def convert_temp(self):
if not self.ow.reset():
raise OneWireError
self.ow.writebyte(SKIP_ROM)
self.ow.writebyte(CONVERT)
def read_scratch(self, rom):
if not self.ow.reset():
raise OneWireError
self.ow.select_rom(rom)
self.ow.writebyte(RD_SCRATCH)
buf = self.ow.read(9)
if self.ow.crc8(buf):
raise OneWireError
return buf
def write_scratch(self, rom, buf):
if not self.ow.reset():
raise OneWireError
self.ow.select_rom(rom)
self.ow.writebyte(WR_SCRATCH)
self.ow.write(buf)
def read_temp(self, rom):
buf = self.read_scratch(rom)
return (buf[1] << 8 | buf[0]) / 16
|
mit
|
[
3,
413,
13,
25791,
5253,
367,
27022,
4718,
641,
31334,
2564,
1272,
199,
3,
10697,
4190,
27,
1898,
334,
67,
9,
7800,
577,
13496,
287,
510,
14,
5346,
24591,
199,
199,
646,
485,
368,
11239,
465,
485,
583,
199,
199,
533,
7309,
25791,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
7309,
25791,
26,
272,
5795,
7762,
63,
3810,
275,
950,
8,
16,
1949,
16,
9,
272,
603,
8078,
63,
3810,
275,
950,
8,
16,
88,
1229,
9,
272,
27885,
63,
3810,
275,
950,
8,
16,
11022,
9,
339,
347,
636,
826,
721,
277,
12,
10713,
304,
267,
291,
14,
7751,
275,
10713,
267,
291,
14,
7751,
14,
826,
8,
7751,
14,
9935,
63,
36,
21715,
9,
339,
347,
5305,
8,
277,
304,
267,
372,
485,
583,
14,
3958,
8,
277,
14,
7751,
9,
339,
347,
1586,
2075,
8,
277,
304,
267,
372,
485,
583,
14,
739,
2075,
8,
277,
14,
7751,
9,
339,
347,
1586,
4414,
8,
277,
304,
267,
372,
485,
583,
14,
739,
4414,
8,
277,
14,
7751,
9,
339,
347,
1586,
8,
277,
12,
2338,
304,
267,
4123,
275,
11640,
8,
835,
9,
267,
367,
284,
315,
1425,
8,
835,
304,
288,
4123,
59,
73,
61,
275,
485,
583,
14,
739,
4414,
8,
277,
14,
7751,
9,
267,
372,
4123,
339,
347,
2218,
2075,
8,
277,
12,
574,
304,
267,
372,
485,
583,
14,
952,
2075,
8,
277,
14,
7751,
12,
574,
9,
339,
347,
2218,
4414,
8,
277,
12,
574,
304,
267,
372,
485,
583,
14,
952,
4414,
8,
277,
14,
7751,
12,
574,
9,
339,
347,
2218,
8,
277,
12,
4123,
304,
267,
367,
330,
315,
4123,
26,
288,
485,
583,
14,
952,
4414,
8,
277,
14,
7751,
12,
330,
9,
339,
347,
3504,
63,
417,
8,
277,
12,
221,
417,
304,
267,
291,
14,
3958,
342,
267,
291,
14,
952,
4414,
8,
14747,
63,
3810,
9,
267,
291,
14,
952,
8,
417,
9,
339,
347,
8000,
8,
277,
304,
267,
7256,
275,
942,
267,
3915,
275,
11738,
267,
221,
417,
275,
756,
267,
367,
284,
315,
1425,
8,
16,
3581,
304,
288,
221,
417,
12,
3915,
275,
291,
423,
1733,
63,
417,
8,
417,
12,
3915,
9,
288,
340,
221,
417,
26,
355,
7256,
847,
359,
417,
61,
288,
340,
3915,
508,
378,
26,
355,
2059,
267,
372,
7256,
339,
347,
485,
1733,
63,
417,
8,
277,
12,
634,
63,
417,
12,
3915,
304,
267,
340,
440,
291,
14,
3958,
837,
288,
372,
488,
12,
378,
267,
291,
14,
952,
4414,
8,
15962,
63,
3810,
9,
267,
340,
440,
634,
63,
417,
26,
288,
634,
63,
417,
275,
11640,
8,
24,
9,
267,
221,
417,
275,
11640,
8,
24,
9,
267,
2163,
63,
3028,
275,
378,
267,
284,
275,
5049,
267,
367,
3696,
315,
1425,
8,
24,
304,
288,
519,
63,
66,
275,
378,
288,
367,
4546,
315,
1425,
8,
24,
304,
355,
330,
275,
291,
14,
739,
2075,
342,
355,
340,
291,
14,
739,
2075,
837,
490,
340,
330,
26,
327,
2337,
787,
949,
7256,
503,
2337,
365,
376,
1125,
641,
314,
10414,
717,
372,
488,
12,
378,
355,
587,
26,
490,
340,
440,
330,
26,
327,
25061,
12,
2877,
7256,
543,
3365,
4546,
11150,
717,
340,
3915,
690,
284,
503,
3666,
76,
63,
417,
59,
4414,
61,
1253,
334,
17,
5213,
4546,
430,
436,
3915,
1137,
284,
304,
1169,
330,
275,
413,
1169,
2163,
63,
3028,
275,
284,
355,
291,
14,
952,
2075,
8,
66,
9,
355,
340,
330,
26,
490,
519,
63,
66,
8901,
413,
5213,
4546,
355,
284,
4862,
413,
288,
221,
417,
59,
4414,
61,
275,
519,
63,
66,
267,
372,
221,
417,
12,
2163,
63,
3028,
339,
347,
18080,
24,
8,
277,
12,
666,
304,
267,
372,
485,
583,
14,
13258,
24,
8,
576,
9,
199,
199,
533,
577,
51,
1085,
34,
1165,
26,
272,
1868,
8851,
275,
950,
8,
16,
88,
1602,
9,
272,
820,
36,
63,
51,
2944,
8078,
275,
950,
8,
16,
9957,
9,
272,
16573,
63,
51,
2944,
8078,
275,
950,
8,
16,
88,
20,
69,
9,
339,
347,
636,
826,
721,
277,
12,
1373,
11239,
304,
267,
291,
14,
583,
275,
1373,
11239,
339,
347,
8000,
8,
277,
304,
267,
372,
359,
417,
367,
221,
417,
315,
291,
14,
583,
14,
6282,
342,
340,
221,
417,
59,
16,
61,
508,
378,
88,
1651,
61,
339,
347,
3957,
63,
808,
8,
277,
304,
267,
340,
440,
291,
14,
583,
14,
3958,
837,
288,
746,
7309,
25791,
547,
267,
291,
14,
583,
14,
952,
4414,
8,
13525,
63,
3810,
9,
267,
291,
14,
583,
14,
952,
4414,
8,
1864,
8851,
9,
339,
347,
1586,
63,
27393,
8,
277,
12,
221,
417,
304,
267,
340,
440,
291,
14,
583,
14,
3958,
837,
288,
746,
7309,
25791,
547,
267,
291,
14,
583,
14,
2416,
63,
417,
8,
417,
9,
267,
291,
14,
583,
14,
952,
4414,
8,
15543,
63,
51,
2944,
8078,
9,
267,
4123,
275,
291,
14,
583,
14,
739,
8,
25,
9,
267,
340,
291,
14,
583,
14,
13258,
24,
8,
1436,
304,
288,
746,
7309,
25791,
547,
267,
372,
4123,
339,
347,
2218,
63,
27393,
8,
277,
12,
221,
417,
12,
4123,
304,
267,
340,
440,
291,
14,
583,
14,
3958,
837,
288,
746,
7309,
25791,
547,
267,
291,
14,
583,
14,
2416,
63,
417,
8,
417,
9,
267,
291,
14,
583,
14,
952,
4414,
8,
6524,
63,
51,
2944,
8078,
9,
267,
291,
14,
583,
14,
952,
8,
1436,
9,
339,
347,
1586,
63,
808,
8,
277,
12,
221,
417,
304,
267,
4123,
275,
291,
14,
739,
63,
27393,
8,
417,
9,
267,
372,
334,
1436,
59,
17,
61,
5213,
1695,
1204,
4123,
59,
16,
566,
1182,
3193,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
413,
13,
25791,
5253,
367,
27022,
4718,
641,
31334,
2564,
1272,
199,
3,
10697,
4190,
27,
1898,
334,
67,
9,
7800,
577,
13496,
287,
510,
14,
5346,
24591,
199,
199,
646,
485,
368,
11239,
465,
485,
583,
199,
199,
533,
7309,
25791,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
7309,
25791,
26,
272,
5795,
7762,
63,
3810,
275,
950,
8,
16,
1949,
16,
9,
272,
603,
8078,
63,
3810,
275,
950,
8,
16,
88,
1229,
9,
272,
27885,
63,
3810,
275,
950,
8,
16,
11022,
9,
339,
347,
636,
826,
721,
277,
12,
10713,
304,
267,
291,
14,
7751,
275,
10713,
267,
291,
14,
7751,
14,
826,
8,
7751,
14,
9935,
63,
36,
21715,
9,
339,
347,
5305,
8,
277,
304,
267,
372,
485,
583,
14,
3958,
8,
277,
14,
7751,
9,
339,
347,
1586,
2075,
8,
277,
304,
267,
372,
485,
583,
14,
739,
2075,
8,
277,
14,
7751,
9,
339,
347,
1586,
4414,
8,
277,
304,
267,
372,
485,
583,
14,
739,
4414,
8,
277,
14,
7751,
9,
339,
347,
1586,
8,
277,
12,
2338,
304,
267,
4123,
275,
11640,
8,
835,
9,
267,
367,
284,
315,
1425,
8,
835,
304,
288,
4123,
59,
73,
61,
275,
485,
583,
14,
739,
4414,
8,
277,
14,
7751,
9,
267,
372,
4123,
339,
347,
2218,
2075,
8,
277,
12,
574,
304,
267,
372,
485,
583,
14,
952,
2075,
8,
277,
14,
7751,
12,
574,
9,
339,
347,
2218,
4414,
8,
277,
12,
574,
304,
267,
372,
485,
583,
14,
952,
4414,
8,
277,
14,
7751,
12,
574,
9,
339,
347,
2218,
8,
277,
12,
4123,
304,
267,
367,
330,
315,
4123,
26,
288,
485,
583,
14,
952,
4414,
8,
277,
14,
7751,
12,
330,
9,
339,
347,
3504,
63,
417,
8,
277,
12,
221,
417,
304,
267,
291,
14,
3958,
342,
267,
291,
14,
952,
4414,
8,
14747,
63,
3810,
9,
267,
291,
14,
952,
8,
417,
9,
339,
347,
8000,
8,
277,
304,
267,
7256,
275,
942,
267,
3915,
275,
11738,
267,
221,
417,
275,
756,
267,
367,
284,
315,
1425,
8,
16,
3581,
304,
288,
221,
417,
12,
3915,
275,
291,
423,
1733,
63,
417,
8,
417,
12,
3915,
9,
288,
340,
221,
417,
26,
355,
7256,
847,
359,
417,
61,
288,
340,
3915,
508,
378,
26,
355,
2059,
267,
372,
7256,
339,
347,
485,
1733,
63,
417,
8,
277,
12,
634,
63,
417,
12,
3915,
304,
267,
340,
440,
291,
14,
3958,
837,
288,
372,
488,
12,
378,
267,
291,
14,
952,
4414,
8,
15962,
63,
3810,
9,
267,
340,
440,
634,
63,
417,
26,
288,
634,
63,
417,
275,
11640,
8,
24,
9,
267,
221,
417,
275,
11640,
8,
24,
9,
267,
2163,
63,
3028,
275,
378,
267,
284,
275,
5049,
267,
367,
3696,
315,
1425,
8,
24,
304,
288,
519,
63,
66,
275,
378,
288,
367,
4546,
315,
1425,
8,
24,
304,
355,
330,
275,
291,
14,
739,
2075,
342,
355,
340,
291,
14,
739,
2075,
837,
490,
340,
330,
26,
327,
2337,
787,
949,
7256,
503,
2337,
365,
376,
1125,
641,
314,
10414,
717,
372,
488,
12,
378,
355,
587,
26,
490,
340,
440,
330,
26,
327,
25061,
12,
2877,
7256,
543,
3365,
4546,
11150,
717,
340,
3915,
690,
284,
503,
3666,
76,
63,
417,
59,
4414,
61,
1253,
334,
17,
5213,
4546,
430,
436,
3915,
1137,
284,
304,
1169,
330,
275,
413,
1169,
2163,
63,
3028,
275,
284,
355,
291,
14,
952,
2075,
8,
66,
9,
355,
340,
330,
26,
490,
519,
63,
66,
8901,
413,
5213,
4546,
355,
284,
4862,
413,
288,
221,
417,
59,
4414,
61,
275,
519,
63,
66,
267,
372,
221,
417,
12,
2163,
63,
3028,
339,
347,
18080,
24,
8,
277,
12,
666,
304,
267,
372,
485,
583,
14,
13258,
24,
8,
576,
9,
199,
199,
533,
577,
51,
1085,
34,
1165,
26,
272,
1868,
8851,
275,
950,
8,
16,
88,
1602,
9,
272,
820,
36,
63,
51,
2944,
8078,
275,
950,
8,
16,
9957,
9,
272,
16573,
63,
51,
2944,
8078,
275,
950,
8,
16,
88,
20,
69,
9,
339,
347,
636,
826,
721,
277,
12,
1373,
11239,
304,
267,
291,
14,
583,
275,
1373,
11239,
339,
347,
8000,
8,
277,
304,
267,
372,
359,
417,
367,
221,
417,
315,
291,
14,
583,
14,
6282,
342,
340,
221,
417,
59,
16,
61,
508,
378,
88,
1651,
61,
339,
347,
3957,
63,
808,
8,
277,
304,
267,
340,
440,
291,
14,
583,
14,
3958,
837,
288,
746,
7309,
25791,
547,
267,
291,
14,
583,
14,
952,
4414,
8,
13525,
63,
3810,
9,
267,
291,
14,
583,
14,
952,
4414,
8,
1864,
8851,
9,
339,
347,
1586,
63,
27393,
8,
277,
12,
221,
417,
304,
267,
340,
440,
291,
14,
583,
14,
3958,
837,
288,
746,
7309,
25791,
547,
267,
291,
14,
583,
14,
2416,
63,
417,
8,
417,
9,
267,
291,
14,
583,
14,
952,
4414,
8,
15543,
63,
51,
2944,
8078,
9,
267,
4123,
275,
291,
14,
583,
14,
739,
8,
25,
9,
267,
340,
291,
14,
583,
14,
13258,
24,
8,
1436,
304,
288,
746,
7309,
25791,
547,
267,
372,
4123,
339,
347,
2218,
63,
27393,
8,
277,
12,
221,
417,
12,
4123,
304,
267,
340,
440,
291,
14,
583,
14,
3958,
837,
288,
746,
7309,
25791,
547,
267,
291,
14,
583,
14,
2416,
63,
417,
8,
417,
9,
267,
291,
14,
583,
14,
952,
4414,
8,
6524,
63,
51,
2944,
8078,
9,
267,
291,
14,
583,
14,
952,
8,
1436,
9,
339,
347,
1586,
63,
808,
8,
277,
12,
221,
417,
304,
267,
4123,
275,
291,
14,
739,
63,
27393,
8,
417,
9,
267,
372,
334,
1436,
59,
17,
61,
5213,
1695,
1204,
4123,
59,
16,
566,
1182,
3193,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
blindroot/django
|
django/db/backends/base/base.py
|
41
|
23063
|
import copy
import time
import warnings
from collections import deque
from contextlib import contextmanager
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db import DEFAULT_DB_ALIAS
from django.db.backends import utils
from django.db.backends.signals import connection_created
from django.db.transaction import TransactionManagementError
from django.db.utils import DatabaseError, DatabaseErrorWrapper
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.six.moves import _thread as thread
try:
import pytz
except ImportError:
pytz = None
NO_DB_ALIAS = '__no_db__'
class BaseDatabaseWrapper(object):
"""
Represents a database connection.
"""
# Mapping of Field objects to their column types.
data_types = {}
# Mapping of Field objects to their SQL suffix such as AUTOINCREMENT.
data_types_suffix = {}
# Mapping of Field objects to their SQL for CHECK constraints.
data_type_check_constraints = {}
ops = None
vendor = 'unknown'
SchemaEditorClass = None
queries_limit = 9000
def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS,
allow_thread_sharing=False):
# Connection related attributes.
# The underlying database connection.
self.connection = None
# `settings_dict` should be a dictionary containing keys such as
# NAME, USER, etc. It's called `settings_dict` instead of `settings`
# to disambiguate it from Django settings modules.
self.settings_dict = settings_dict
self.alias = alias
# Query logging in debug mode or when explicitly enabled.
self.queries_log = deque(maxlen=self.queries_limit)
self.force_debug_cursor = False
# Transaction related attributes.
# Tracks if the connection is in autocommit mode. Per PEP 249, by
# default, it isn't.
self.autocommit = False
# Tracks if the connection is in a transaction managed by 'atomic'.
self.in_atomic_block = False
# Increment to generate unique savepoint ids.
self.savepoint_state = 0
# List of savepoints created by 'atomic'.
self.savepoint_ids = []
# Tracks if the outermost 'atomic' block should commit on exit,
# ie. if autocommit was active on entry.
self.commit_on_exit = True
# Tracks if the transaction should be rolled back to the next
# available savepoint because of an exception in an inner block.
self.needs_rollback = False
# Connection termination related attributes.
self.close_at = None
self.closed_in_transaction = False
self.errors_occurred = False
# Thread-safety related attributes.
self.allow_thread_sharing = allow_thread_sharing
self._thread_ident = thread.get_ident()
# A list of no-argument functions to run when the transaction commits.
# Each entry is an (sids, func) tuple, where sids is a set of the
# active savepoint IDs when this function was registered.
self.run_on_commit = []
# Should we run the on-commit hooks the next time set_autocommit(True)
# is called?
self.run_commit_hooks_on_set_autocommit_on = False
@cached_property
def timezone(self):
"""
Time zone for datetimes stored as naive values in the database.
Returns a tzinfo object or None.
This is only needed when time zone support is enabled and the database
doesn't support time zones. (When the database supports time zones,
the adapter handles aware datetimes so Django doesn't need to.)
"""
if not settings.USE_TZ:
return None
elif self.features.supports_timezones:
return None
elif self.settings_dict['TIME_ZONE'] is None:
return timezone.utc
else:
# Only this branch requires pytz.
return pytz.timezone(self.settings_dict['TIME_ZONE'])
@cached_property
def timezone_name(self):
"""
Name of the time zone of the database connection.
"""
if not settings.USE_TZ:
return settings.TIME_ZONE
elif self.settings_dict['TIME_ZONE'] is None:
return 'UTC'
else:
return self.settings_dict['TIME_ZONE']
@property
def queries_logged(self):
return self.force_debug_cursor or settings.DEBUG
@property
def queries(self):
if len(self.queries_log) == self.queries_log.maxlen:
warnings.warn(
"Limit for query logging exceeded, only the last {} queries "
"will be returned.".format(self.queries_log.maxlen))
return list(self.queries_log)
# ##### Backend-specific methods for creating connections and cursors #####
def get_connection_params(self):
"""Returns a dict of parameters suitable for get_new_connection."""
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a get_connection_params() method')
def get_new_connection(self, conn_params):
"""Opens a connection to the database."""
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a get_new_connection() method')
def init_connection_state(self):
"""Initializes the database connection settings."""
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require an init_connection_state() method')
def create_cursor(self):
"""Creates a cursor. Assumes that a connection is established."""
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a create_cursor() method')
# ##### Backend-specific methods for creating connections #####
def connect(self):
"""Connects to the database. Assumes that the connection is closed."""
# Check for invalid configurations.
self.check_settings()
# In case the previous connection was closed while in an atomic block
self.in_atomic_block = False
self.savepoint_ids = []
self.needs_rollback = False
# Reset parameters defining when to close the connection
max_age = self.settings_dict['CONN_MAX_AGE']
self.close_at = None if max_age is None else time.time() + max_age
self.closed_in_transaction = False
self.errors_occurred = False
# Establish the connection
conn_params = self.get_connection_params()
self.connection = self.get_new_connection(conn_params)
self.set_autocommit(self.settings_dict['AUTOCOMMIT'])
self.init_connection_state()
connection_created.send(sender=self.__class__, connection=self)
self.run_on_commit = []
def check_settings(self):
if self.settings_dict['TIME_ZONE'] is not None:
if not settings.USE_TZ:
raise ImproperlyConfigured(
"Connection '%s' cannot set TIME_ZONE because USE_TZ is "
"False." % self.alias)
elif self.features.supports_timezones:
raise ImproperlyConfigured(
"Connection '%s' cannot set TIME_ZONE because its engine "
"handles time zones conversions natively." % self.alias)
elif pytz is None:
raise ImproperlyConfigured(
"Connection '%s' cannot set TIME_ZONE because pytz isn't "
"installed." % self.alias)
def ensure_connection(self):
"""
Guarantees that a connection to the database is established.
"""
if self.connection is None:
with self.wrap_database_errors:
self.connect()
# ##### Backend-specific wrappers for PEP-249 connection methods #####
def _cursor(self):
self.ensure_connection()
with self.wrap_database_errors:
return self.create_cursor()
def _commit(self):
if self.connection is not None:
with self.wrap_database_errors:
return self.connection.commit()
def _rollback(self):
if self.connection is not None:
with self.wrap_database_errors:
return self.connection.rollback()
def _close(self):
if self.connection is not None:
with self.wrap_database_errors:
return self.connection.close()
# ##### Generic wrappers for PEP-249 connection methods #####
def cursor(self):
"""
Creates a cursor, opening a connection if necessary.
"""
self.validate_thread_sharing()
if self.queries_logged:
cursor = self.make_debug_cursor(self._cursor())
else:
cursor = self.make_cursor(self._cursor())
return cursor
def commit(self):
"""
Commits a transaction and resets the dirty flag.
"""
self.validate_thread_sharing()
self.validate_no_atomic_block()
self._commit()
# A successful commit means that the database connection works.
self.errors_occurred = False
self.run_commit_hooks_on_set_autocommit_on = True
def rollback(self):
"""
Rolls back a transaction and resets the dirty flag.
"""
self.validate_thread_sharing()
self.validate_no_atomic_block()
self._rollback()
# A successful rollback means that the database connection works.
self.errors_occurred = False
self.run_on_commit = []
def close(self):
"""
Closes the connection to the database.
"""
self.validate_thread_sharing()
self.run_on_commit = []
# Don't call validate_no_atomic_block() to avoid making it difficult
# to get rid of a connection in an invalid state. The next connect()
# will reset the transaction state anyway.
if self.closed_in_transaction or self.connection is None:
return
try:
self._close()
finally:
if self.in_atomic_block:
self.closed_in_transaction = True
self.needs_rollback = True
else:
self.connection = None
# ##### Backend-specific savepoint management methods #####
def _savepoint(self, sid):
with self.cursor() as cursor:
cursor.execute(self.ops.savepoint_create_sql(sid))
def _savepoint_rollback(self, sid):
with self.cursor() as cursor:
cursor.execute(self.ops.savepoint_rollback_sql(sid))
def _savepoint_commit(self, sid):
with self.cursor() as cursor:
cursor.execute(self.ops.savepoint_commit_sql(sid))
def _savepoint_allowed(self):
# Savepoints cannot be created outside a transaction
return self.features.uses_savepoints and not self.get_autocommit()
# ##### Generic savepoint management methods #####
def savepoint(self):
"""
Creates a savepoint inside the current transaction. Returns an
identifier for the savepoint that will be used for the subsequent
rollback or commit. Does nothing if savepoints are not supported.
"""
if not self._savepoint_allowed():
return
thread_ident = thread.get_ident()
tid = str(thread_ident).replace('-', '')
self.savepoint_state += 1
sid = "s%s_x%d" % (tid, self.savepoint_state)
self.validate_thread_sharing()
self._savepoint(sid)
return sid
def savepoint_rollback(self, sid):
"""
Rolls back to a savepoint. Does nothing if savepoints are not supported.
"""
if not self._savepoint_allowed():
return
self.validate_thread_sharing()
self._savepoint_rollback(sid)
# Remove any callbacks registered while this savepoint was active.
self.run_on_commit = [
(sids, func) for (sids, func) in self.run_on_commit if sid not in sids
]
def savepoint_commit(self, sid):
"""
Releases a savepoint. Does nothing if savepoints are not supported.
"""
if not self._savepoint_allowed():
return
self.validate_thread_sharing()
self._savepoint_commit(sid)
def clean_savepoints(self):
"""
Resets the counter used to generate unique savepoint ids in this thread.
"""
self.savepoint_state = 0
# ##### Backend-specific transaction management methods #####
def _set_autocommit(self, autocommit):
"""
Backend-specific implementation to enable or disable autocommit.
"""
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a _set_autocommit() method')
# ##### Generic transaction management methods #####
def get_autocommit(self):
"""
Check the autocommit state.
"""
self.ensure_connection()
return self.autocommit
def set_autocommit(self, autocommit, force_begin_transaction_with_broken_autocommit=False):
"""
Enable or disable autocommit.
The usual way to start a transaction is to turn autocommit off.
SQLite does not properly start a transaction when disabling
autocommit. To avoid this buggy behavior and to actually enter a new
transaction, an explcit BEGIN is required. Using
force_begin_transaction_with_broken_autocommit=True will issue an
explicit BEGIN with SQLite. This option will be ignored for other
backends.
"""
self.validate_no_atomic_block()
self.ensure_connection()
start_transaction_under_autocommit = (
force_begin_transaction_with_broken_autocommit and not autocommit and
self.features.autocommits_when_autocommit_is_off
)
if start_transaction_under_autocommit:
self._start_transaction_under_autocommit()
else:
self._set_autocommit(autocommit)
self.autocommit = autocommit
if autocommit and self.run_commit_hooks_on_set_autocommit_on:
self.run_and_clear_commit_hooks()
self.run_commit_hooks_on_set_autocommit_on = False
def get_rollback(self):
"""
Get the "needs rollback" flag -- for *advanced use* only.
"""
if not self.in_atomic_block:
raise TransactionManagementError(
"The rollback flag doesn't work outside of an 'atomic' block.")
return self.needs_rollback
def set_rollback(self, rollback):
"""
Set or unset the "needs rollback" flag -- for *advanced use* only.
"""
if not self.in_atomic_block:
raise TransactionManagementError(
"The rollback flag doesn't work outside of an 'atomic' block.")
self.needs_rollback = rollback
def validate_no_atomic_block(self):
"""
Raise an error if an atomic block is active.
"""
if self.in_atomic_block:
raise TransactionManagementError(
"This is forbidden when an 'atomic' block is active.")
def validate_no_broken_transaction(self):
if self.needs_rollback:
raise TransactionManagementError(
"An error occurred in the current transaction. You can't "
"execute queries until the end of the 'atomic' block.")
# ##### Foreign key constraints checks handling #####
@contextmanager
def constraint_checks_disabled(self):
"""
Context manager that disables foreign key constraint checking.
"""
disabled = self.disable_constraint_checking()
try:
yield
finally:
if disabled:
self.enable_constraint_checking()
def disable_constraint_checking(self):
"""
Backends can implement as needed to temporarily disable foreign key
constraint checking. Should return True if the constraints were
disabled and will need to be reenabled.
"""
return False
def enable_constraint_checking(self):
"""
Backends can implement as needed to re-enable foreign key constraint
checking.
"""
pass
def check_constraints(self, table_names=None):
"""
Backends can override this method if they can apply constraint
checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE"). Should raise an
IntegrityError if any invalid foreign key references are encountered.
"""
pass
# ##### Connection termination handling #####
def is_usable(self):
"""
Tests if the database connection is usable.
This function may assume that self.connection is not None.
Actual implementations should take care not to raise exceptions
as that may prevent Django from recycling unusable connections.
"""
raise NotImplementedError(
"subclasses of BaseDatabaseWrapper may require an is_usable() method")
def close_if_unusable_or_obsolete(self):
"""
Closes the current connection if unrecoverable errors have occurred,
or if it outlived its maximum age.
"""
if self.connection is not None:
# If the application didn't restore the original autocommit setting,
# don't take chances, drop the connection.
if self.get_autocommit() != self.settings_dict['AUTOCOMMIT']:
self.close()
return
# If an exception other than DataError or IntegrityError occurred
# since the last commit / rollback, check if the connection works.
if self.errors_occurred:
if self.is_usable():
self.errors_occurred = False
else:
self.close()
return
if self.close_at is not None and time.time() >= self.close_at:
self.close()
return
# ##### Thread safety handling #####
def validate_thread_sharing(self):
"""
Validates that the connection isn't accessed by another thread than the
one which originally created it, unless the connection was explicitly
authorized to be shared between threads (via the `allow_thread_sharing`
property). Raises an exception if the validation fails.
"""
if not (self.allow_thread_sharing or self._thread_ident == thread.get_ident()):
raise DatabaseError(
"DatabaseWrapper objects created in a "
"thread can only be used in that same thread. The object "
"with alias '%s' was created in thread id %s and this is "
"thread id %s."
% (self.alias, self._thread_ident, thread.get_ident())
)
# ##### Miscellaneous #####
def prepare_database(self):
"""
Hook to do any database check or preparation, generally called before
migrating a project or an app.
"""
pass
@cached_property
def wrap_database_errors(self):
"""
Context manager and decorator that re-throws backend-specific database
exceptions using Django's common wrappers.
"""
return DatabaseErrorWrapper(self)
def make_debug_cursor(self, cursor):
"""
Creates a cursor that logs all queries in self.queries_log.
"""
return utils.CursorDebugWrapper(cursor, self)
def make_cursor(self, cursor):
"""
Creates a cursor without debug logging.
"""
return utils.CursorWrapper(cursor, self)
@contextmanager
def temporary_connection(self):
"""
Context manager that ensures that a connection is established, and
if it opened one, closes it to avoid leaving a dangling connection.
This is useful for operations outside of the request-response cycle.
Provides a cursor: with self.temporary_connection() as cursor: ...
"""
must_close = self.connection is None
cursor = self.cursor()
try:
yield cursor
finally:
cursor.close()
if must_close:
self.close()
@property
def _nodb_connection(self):
"""
Return an alternative connection to be used when there is no need to access
the main database, specifically for test db creation/deletion.
This also prevents the production database from being exposed to
potential child threads while (or after) the test database is destroyed.
Refs #10868, #17786, #16969.
"""
settings_dict = self.settings_dict.copy()
settings_dict['NAME'] = None
nodb_connection = self.__class__(
settings_dict,
alias=NO_DB_ALIAS,
allow_thread_sharing=False)
return nodb_connection
def _start_transaction_under_autocommit(self):
"""
Only required when autocommits_when_autocommit_is_off = True.
"""
raise NotImplementedError(
'subclasses of BaseDatabaseWrapper may require a '
'_start_transaction_under_autocommit() method'
)
def schema_editor(self, *args, **kwargs):
"""
Returns a new instance of this backend's SchemaEditor.
"""
if self.SchemaEditorClass is None:
raise NotImplementedError(
'The SchemaEditorClass attribute of this database wrapper is still None')
return self.SchemaEditorClass(self, *args, **kwargs)
def on_commit(self, func):
if self.in_atomic_block:
# Transaction in progress; save for execution on commit.
self.run_on_commit.append((set(self.savepoint_ids), func))
elif not self.get_autocommit():
raise TransactionManagementError('on_commit() cannot be used in manual transaction management')
else:
# No transaction in progress and in autocommit mode; execute
# immediately.
func()
def run_and_clear_commit_hooks(self):
self.validate_no_atomic_block()
current_run_on_commit = self.run_on_commit
self.run_on_commit = []
while current_run_on_commit:
sids, func = current_run_on_commit.pop(0)
func()
def copy(self, alias=None, allow_thread_sharing=None):
"""
Return a copy of this connection.
For tests that require two connections to the same database.
"""
settings_dict = copy.deepcopy(self.settings_dict)
if alias is None:
alias = self.alias
if allow_thread_sharing is None:
allow_thread_sharing = self.allow_thread_sharing
return type(self)(settings_dict, alias, allow_thread_sharing)
|
bsd-3-clause
|
[
646,
1331,
199,
646,
900,
199,
646,
3598,
199,
504,
5055,
492,
15782,
199,
504,
15502,
492,
27608,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
492,
6186,
63,
2846,
63,
12644,
199,
504,
1639,
14,
697,
14,
7765,
492,
3778,
199,
504,
1639,
14,
697,
14,
7765,
14,
10458,
492,
1950,
63,
3966,
199,
504,
1639,
14,
697,
14,
5945,
492,
18244,
14552,
547,
199,
504,
1639,
14,
697,
14,
1208,
492,
27728,
12,
27728,
4590,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
485,
2671,
465,
2462,
199,
199,
893,
26,
272,
492,
15444,
199,
2590,
3545,
26,
272,
15444,
275,
488,
199,
199,
2826,
63,
2846,
63,
12644,
275,
2560,
889,
63,
697,
12217,
421,
199,
533,
29103,
4590,
8,
785,
304,
272,
408,
272,
21591,
282,
3050,
1950,
14,
272,
408,
272,
327,
12340,
402,
5024,
2251,
370,
3932,
2763,
2943,
14,
272,
666,
63,
1313,
275,
1052,
272,
327,
12340,
402,
5024,
2251,
370,
3932,
5385,
4739,
4066,
465,
20331,
8975,
31431,
14,
272,
666,
63,
1313,
63,
4511,
275,
1052,
272,
327,
12340,
402,
5024,
2251,
370,
3932,
5385,
367,
17654,
9565,
14,
272,
666,
63,
466,
63,
1074,
63,
9882,
275,
1052,
272,
4156,
275,
488,
272,
20868,
275,
283,
5187,
7,
272,
13268,
10423,
2543,
275,
488,
339,
9212,
63,
3097,
275,
1749,
1493,
339,
347,
636,
826,
721,
277,
12,
2202,
63,
807,
12,
5162,
29,
3472,
63,
2846,
63,
12644,
12,
326,
2040,
63,
2671,
63,
29122,
29,
797,
304,
267,
327,
8113,
4048,
3004,
14,
267,
327,
710,
8793,
3050,
1950,
14,
267,
291,
14,
2105,
275,
488,
267,
327,
658,
1751,
63,
807,
64,
1077,
506,
282,
2600,
3035,
2883,
4066,
465,
267,
327,
13637,
12,
13044,
12,
5423,
14,
2779,
1159,
2797,
658,
1751,
63,
807,
64,
3140,
402,
658,
1751,
64,
267,
327,
370,
2153,
16902,
4767,
652,
687,
5634,
2202,
4621,
14,
267,
291,
14,
1751,
63,
807,
275,
2202,
63,
807,
267,
291,
14,
3620,
275,
5162,
267,
327,
8133,
2050,
315,
3105,
818,
503,
1380,
7662,
5223,
14,
267,
291,
14,
10590,
63,
793,
275,
15782,
8,
29078,
29,
277,
14,
10590,
63,
3097,
9,
267,
291,
14,
3990,
63,
1757,
63,
3937,
275,
756,
398,
327,
18244,
4048,
3004,
14,
267,
327,
12643,
5618,
340,
314,
1950,
365,
315,
24845,
818,
14,
3492,
13663,
499,
1887,
12,
701,
267,
327,
849,
12,
652,
5712,
1133,
14,
267,
291,
14,
17881,
275,
756,
267,
327,
12643,
5618,
340,
314,
1950,
365,
315,
282,
6008,
12883,
701,
283,
10910,
1370,
267,
291,
14,
262,
63,
10910,
63,
1457,
275,
756,
267,
327,
1010,
4062,
370,
3550,
3747,
27069,
2762,
14,
267,
291,
14,
25992,
63,
929,
275,
378,
267,
327,
3820,
402,
3354,
3438,
2737,
701,
283,
10910,
1370,
267,
291,
14,
25992,
63,
1580,
275,
942,
267,
327,
12643,
5618,
340,
314,
6890,
2786,
283,
10910,
7,
1853,
1077,
5532,
641,
4458,
12,
267,
327,
13446,
14,
340,
24845,
1990,
4702,
641,
2397,
14,
267,
291,
14,
3543,
63,
265,
63,
2224,
275,
715,
267,
327,
12643,
5618,
340,
314,
6008,
1077,
506,
20182,
1146,
1771,
370,
314,
2163,
267,
327,
2808,
27069,
2952,
402,
376,
1919,
315,
376,
6506,
1853,
14,
267,
291,
14,
10065,
63,
10437,
275,
756,
398,
327,
8113,
23868,
4048,
3004,
14,
267,
291,
14,
1600,
63,
292,
275,
488,
267,
291,
14,
5938,
63,
262,
63,
5945,
275,
756,
267,
291,
14,
2550,
63,
20051,
581,
275,
756,
398,
327,
11086,
13,
3489,
369,
4048,
3004,
14,
267,
291,
14,
3306,
63,
2671,
63,
29122,
275,
2040,
63,
2671,
63,
29122,
267,
291,
423,
2671,
63,
5425,
275,
2462,
14,
362,
63,
5425,
342,
398,
327,
437,
769,
402,
949,
13,
2094,
3423,
370,
1255,
1380,
314,
6008,
20835,
14,
267,
327,
7048,
2397,
365,
376,
334,
338,
795,
12,
2562,
9,
2008,
12,
2382,
308,
1580,
365,
282,
663,
402,
314,
267,
327,
4702,
27069,
11449,
1380,
642,
805,
1990,
7264,
14,
267,
291,
14,
1065,
63,
265,
63,
3543,
275,
942,
398,
327,
7719,
781,
1255,
314,
641,
13,
3543,
12604,
314,
2163,
900,
663,
63,
17881,
8,
549,
9,
267,
327,
365,
2797,
31,
267,
291,
14,
1065,
63,
3543,
63,
7922,
63,
265,
63,
409,
63,
17881,
63,
265,
275,
756,
339,
768,
5245,
63,
1829,
272,
347,
7137,
8,
277,
304,
267,
408,
267,
4703,
5718,
367,
29297,
5489,
465,
19995,
1338,
315,
314,
3050,
14,
398,
1803,
282,
10313,
909,
503,
488,
14,
398,
961,
365,
1454,
4346,
1380,
900,
5718,
2291,
365,
5223,
436,
314,
3050,
267,
3181,
1133,
2291,
900,
18666,
14,
334,
11423,
314,
3050,
5171,
900,
18666,
12,
267,
314,
12146,
10022,
20381,
29297,
880,
5634,
3181,
1133,
1929,
370,
4959,
267,
408,
267,
340,
440,
2202,
14,
4701,
63,
14226,
26,
288,
372,
488,
267,
916,
291,
14,
3179,
14,
9823,
63,
7145,
83,
26,
288,
372,
488,
267,
916,
291,
14,
1751,
63,
807,
459,
4961,
63,
15353,
418,
365,
488,
26,
288,
372,
7137,
14,
5834,
267,
587,
26,
288,
327,
5972,
642,
5246,
5074,
15444,
14,
288,
372,
15444,
14,
7145,
8,
277,
14,
1751,
63,
807,
459,
4961,
63,
15353,
1105,
339,
768,
5245,
63,
1829,
272,
347,
7137,
63,
354,
8,
277,
304,
267,
408,
267,
2812,
402,
314,
900,
5718,
402,
314,
3050,
1950,
14,
267,
408,
267,
340,
440,
2202,
14,
4701,
63,
14226,
26,
288,
372,
2202,
14,
4961,
63,
15353,
267,
916,
291,
14,
1751,
63,
807,
459,
4961,
63,
15353,
418,
365,
488,
26,
288,
372,
283,
11288,
7,
267,
587,
26,
288,
372,
291,
14,
1751,
63,
807,
459,
4961,
63,
15353,
418,
339,
768,
1829,
272,
347,
9212,
63,
12419,
8,
277,
304,
267,
372,
291,
14,
3990,
63,
1757,
63,
3937,
503,
2202,
14,
5287,
339,
768,
1829,
272,
347,
9212,
8,
277,
304,
267,
340,
822,
8,
277,
14,
10590,
63,
793
] |
[
1331,
199,
646,
900,
199,
646,
3598,
199,
504,
5055,
492,
15782,
199,
504,
15502,
492,
27608,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
492,
6186,
63,
2846,
63,
12644,
199,
504,
1639,
14,
697,
14,
7765,
492,
3778,
199,
504,
1639,
14,
697,
14,
7765,
14,
10458,
492,
1950,
63,
3966,
199,
504,
1639,
14,
697,
14,
5945,
492,
18244,
14552,
547,
199,
504,
1639,
14,
697,
14,
1208,
492,
27728,
12,
27728,
4590,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
485,
2671,
465,
2462,
199,
199,
893,
26,
272,
492,
15444,
199,
2590,
3545,
26,
272,
15444,
275,
488,
199,
199,
2826,
63,
2846,
63,
12644,
275,
2560,
889,
63,
697,
12217,
421,
199,
533,
29103,
4590,
8,
785,
304,
272,
408,
272,
21591,
282,
3050,
1950,
14,
272,
408,
272,
327,
12340,
402,
5024,
2251,
370,
3932,
2763,
2943,
14,
272,
666,
63,
1313,
275,
1052,
272,
327,
12340,
402,
5024,
2251,
370,
3932,
5385,
4739,
4066,
465,
20331,
8975,
31431,
14,
272,
666,
63,
1313,
63,
4511,
275,
1052,
272,
327,
12340,
402,
5024,
2251,
370,
3932,
5385,
367,
17654,
9565,
14,
272,
666,
63,
466,
63,
1074,
63,
9882,
275,
1052,
272,
4156,
275,
488,
272,
20868,
275,
283,
5187,
7,
272,
13268,
10423,
2543,
275,
488,
339,
9212,
63,
3097,
275,
1749,
1493,
339,
347,
636,
826,
721,
277,
12,
2202,
63,
807,
12,
5162,
29,
3472,
63,
2846,
63,
12644,
12,
326,
2040,
63,
2671,
63,
29122,
29,
797,
304,
267,
327,
8113,
4048,
3004,
14,
267,
327,
710,
8793,
3050,
1950,
14,
267,
291,
14,
2105,
275,
488,
267,
327,
658,
1751,
63,
807,
64,
1077,
506,
282,
2600,
3035,
2883,
4066,
465,
267,
327,
13637,
12,
13044,
12,
5423,
14,
2779,
1159,
2797,
658,
1751,
63,
807,
64,
3140,
402,
658,
1751,
64,
267,
327,
370,
2153,
16902,
4767,
652,
687,
5634,
2202,
4621,
14,
267,
291,
14,
1751,
63,
807,
275,
2202,
63,
807,
267,
291,
14,
3620,
275,
5162,
267,
327,
8133,
2050,
315,
3105,
818,
503,
1380,
7662,
5223,
14,
267,
291,
14,
10590,
63,
793,
275,
15782,
8,
29078,
29,
277,
14,
10590,
63,
3097,
9,
267,
291,
14,
3990,
63,
1757,
63,
3937,
275,
756,
398,
327,
18244,
4048,
3004,
14,
267,
327,
12643,
5618,
340,
314,
1950,
365,
315,
24845,
818,
14,
3492,
13663,
499,
1887,
12,
701,
267,
327,
849,
12,
652,
5712,
1133,
14,
267,
291,
14,
17881,
275,
756,
267,
327,
12643,
5618,
340,
314,
1950,
365,
315,
282,
6008,
12883,
701,
283,
10910,
1370,
267,
291,
14,
262,
63,
10910,
63,
1457,
275,
756,
267,
327,
1010,
4062,
370,
3550,
3747,
27069,
2762,
14,
267,
291,
14,
25992,
63,
929,
275,
378,
267,
327,
3820,
402,
3354,
3438,
2737,
701,
283,
10910,
1370,
267,
291,
14,
25992,
63,
1580,
275,
942,
267,
327,
12643,
5618,
340,
314,
6890,
2786,
283,
10910,
7,
1853,
1077,
5532,
641,
4458,
12,
267,
327,
13446,
14,
340,
24845,
1990,
4702,
641,
2397,
14,
267,
291,
14,
3543,
63,
265,
63,
2224,
275,
715,
267,
327,
12643,
5618,
340,
314,
6008,
1077,
506,
20182,
1146,
1771,
370,
314,
2163,
267,
327,
2808,
27069,
2952,
402,
376,
1919,
315,
376,
6506,
1853,
14,
267,
291,
14,
10065,
63,
10437,
275,
756,
398,
327,
8113,
23868,
4048,
3004,
14,
267,
291,
14,
1600,
63,
292,
275,
488,
267,
291,
14,
5938,
63,
262,
63,
5945,
275,
756,
267,
291,
14,
2550,
63,
20051,
581,
275,
756,
398,
327,
11086,
13,
3489,
369,
4048,
3004,
14,
267,
291,
14,
3306,
63,
2671,
63,
29122,
275,
2040,
63,
2671,
63,
29122,
267,
291,
423,
2671,
63,
5425,
275,
2462,
14,
362,
63,
5425,
342,
398,
327,
437,
769,
402,
949,
13,
2094,
3423,
370,
1255,
1380,
314,
6008,
20835,
14,
267,
327,
7048,
2397,
365,
376,
334,
338,
795,
12,
2562,
9,
2008,
12,
2382,
308,
1580,
365,
282,
663,
402,
314,
267,
327,
4702,
27069,
11449,
1380,
642,
805,
1990,
7264,
14,
267,
291,
14,
1065,
63,
265,
63,
3543,
275,
942,
398,
327,
7719,
781,
1255,
314,
641,
13,
3543,
12604,
314,
2163,
900,
663,
63,
17881,
8,
549,
9,
267,
327,
365,
2797,
31,
267,
291,
14,
1065,
63,
3543,
63,
7922,
63,
265,
63,
409,
63,
17881,
63,
265,
275,
756,
339,
768,
5245,
63,
1829,
272,
347,
7137,
8,
277,
304,
267,
408,
267,
4703,
5718,
367,
29297,
5489,
465,
19995,
1338,
315,
314,
3050,
14,
398,
1803,
282,
10313,
909,
503,
488,
14,
398,
961,
365,
1454,
4346,
1380,
900,
5718,
2291,
365,
5223,
436,
314,
3050,
267,
3181,
1133,
2291,
900,
18666,
14,
334,
11423,
314,
3050,
5171,
900,
18666,
12,
267,
314,
12146,
10022,
20381,
29297,
880,
5634,
3181,
1133,
1929,
370,
4959,
267,
408,
267,
340,
440,
2202,
14,
4701,
63,
14226,
26,
288,
372,
488,
267,
916,
291,
14,
3179,
14,
9823,
63,
7145,
83,
26,
288,
372,
488,
267,
916,
291,
14,
1751,
63,
807,
459,
4961,
63,
15353,
418,
365,
488,
26,
288,
372,
7137,
14,
5834,
267,
587,
26,
288,
327,
5972,
642,
5246,
5074,
15444,
14,
288,
372,
15444,
14,
7145,
8,
277,
14,
1751,
63,
807,
459,
4961,
63,
15353,
1105,
339,
768,
5245,
63,
1829,
272,
347,
7137,
63,
354,
8,
277,
304,
267,
408,
267,
2812,
402,
314,
900,
5718,
402,
314,
3050,
1950,
14,
267,
408,
267,
340,
440,
2202,
14,
4701,
63,
14226,
26,
288,
372,
2202,
14,
4961,
63,
15353,
267,
916,
291,
14,
1751,
63,
807,
459,
4961,
63,
15353,
418,
365,
488,
26,
288,
372,
283,
11288,
7,
267,
587,
26,
288,
372,
291,
14,
1751,
63,
807,
459,
4961,
63,
15353,
418,
339,
768,
1829,
272,
347,
9212,
63,
12419,
8,
277,
304,
267,
372,
291,
14,
3990,
63,
1757,
63,
3937,
503,
2202,
14,
5287,
339,
768,
1829,
272,
347,
9212,
8,
277,
304,
267,
340,
822,
8,
277,
14,
10590,
63,
793,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
luci/recipes-py
|
recipe_modules/runtime/api.py
|
2
|
2238
|
# Copyright 2017 The LUCI Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
from recipe_engine import recipe_api
from recipe_engine.internal.global_shutdown import GLOBAL_SHUTDOWN
class RuntimeApi(recipe_api.RecipeApi):
"""This module assists in experimenting with production recipes.
For example, when migrating builders from Buildbot to pure LUCI stack.
"""
def __init__(self, properties, **kwargs):
super(RuntimeApi, self).__init__(**kwargs)
self._properties = properties
@property
def is_experimental(self):
"""True if this recipe is currently running in experimental mode.
Typical usage is to modify steps which produce external side-effects so that
non-production runs of the recipe do not affect production data.
Examples:
* Uploading to an alternate google storage file name when in non-prod mode
* Appending a 'non-production' tag to external RPCs
"""
return self._properties.is_experimental
@property
def in_global_shutdown(self):
"""True iff this recipe is currently in the 'grace_period' specified by
`LUCI_CONTEXT['deadline']`.
This can occur when:
* The LUCI_CONTEXT has hit the 'soft_deadline'; OR
* The LUCI_CONTEXT has been 'canceled' and the recipe_engine has recieved
a SIGTERM (on *nix) or Ctrl-Break (on Windows).
As of 2021Q2, while the recipe is in the grace_period, it can do anything
_except_ for starting new steps (but it can e.g. update presentation of open
steps, or return RawResult from RunSteps). Attempting to start a step while
in the grace_period will cause the step to skip execution. When a signal is
recieved or the soft_deadline is hit, all currently running steps will be
signaled in turn (according to the `LUCI_CONTEXT['deadline']` protocol).
It is good practice to ensure that recipes exit cleanly when canceled or
time out, and this could be used anywhere to skip 'cleanup' behavior in
'finally' clauses or context managers.
https://chromium.googlesource.com/infra/luci/luci-py/+/HEAD/client/LUCI_CONTEXT.md
"""
return GLOBAL_SHUTDOWN.ready()
|
apache-2.0
|
[
3,
1898,
9708,
710,
491,
53,
3553,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
626,
883,
506,
1911,
315,
314,
5113,
570,
14,
199,
199,
504,
17121,
63,
3908,
492,
17121,
63,
1246,
199,
199,
504,
17121,
63,
3908,
14,
4672,
14,
2966,
63,
8831,
492,
598,
12667,
63,
24340,
8819,
421,
199,
533,
19103,
7394,
8,
13191,
63,
1246,
14,
25879,
7394,
304,
523,
408,
2765,
859,
465,
338,
10329,
315,
11805,
316,
543,
9920,
17121,
83,
14,
819,
2104,
2893,
12,
1380,
3952,
10417,
27378,
687,
6516,
3018,
370,
15111,
491,
53,
3553,
3464,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
4382,
12,
1011,
958,
304,
272,
1613,
8,
14357,
7394,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
423,
3282,
275,
4382,
819,
768,
1829,
523,
347,
365,
63,
18924,
8,
277,
304,
272,
408,
549,
340,
642,
17121,
365,
5544,
3879,
315,
22820,
818,
14,
339,
29267,
4503,
365,
370,
2811,
7124,
1314,
7389,
5957,
5366,
13,
27626,
880,
626,
272,
2222,
13,
10777,
7858,
402,
314,
17121,
886,
440,
12787,
9920,
666,
14,
339,
6058,
26,
489,
627,
4949,
8786,
370,
376,
18034,
6233,
4887,
570,
536,
1380,
315,
2222,
13,
8788,
818,
489,
627,
4693,
3219,
282,
283,
2865,
13,
10777,
7,
1947,
370,
5957,
11785,
83,
272,
408,
272,
372,
291,
423,
3282,
14,
374,
63,
18924,
819,
768,
1829,
523,
347,
315,
63,
2966,
63,
8831,
8,
277,
304,
272,
408,
549,
17963,
642,
17121,
365,
5544,
315,
314,
283,
20631,
63,
5191,
7,
2013,
701,
272,
658,
20237,
3553,
63,
9059,
459,
22357,
418,
2313,
339,
961,
883,
4781,
1380,
26,
489,
627,
710,
491,
53,
3553,
63,
9059,
965,
9793,
314,
283,
4617,
63,
22357,
13619,
1549,
489,
627,
710,
491,
53,
3553,
63,
9059,
965,
2757,
283,
67,
18959,
7,
436,
314,
17121,
63,
3908,
965,
295,
559,
27986,
267,
282,
15522,
16718,
334,
265,
627,
78,
1148,
9,
503,
445,
7245,
13,
13948,
334,
265,
5417,
680,
339,
3709,
402,
499,
15385,
49,
18,
12,
1830,
314,
17121,
365,
315,
314,
19756,
63,
5191,
12,
652,
883,
886,
7003,
272,
485,
2590,
63,
367,
6617,
892,
7124,
334,
7911,
652,
883,
325,
14,
71,
14,
1678,
3451,
425,
402,
1551,
272,
7124,
12,
503,
372,
13480,
2889,
687,
3378,
20960,
680,
17413,
1337,
370,
1343,
282,
3650,
1830,
272,
315,
314,
19756,
63,
5191,
911,
7675,
314,
3650,
370,
3372,
6451,
14,
3979,
282,
4673,
365,
272,
295,
559,
27986,
503,
314,
11620,
63,
22357,
365,
9793,
12,
1006,
5544,
3879,
7124,
911,
506,
272,
2070,
65,
1146,
315,
7485,
334,
645,
5422,
370,
314,
658,
20237,
3553,
63,
9059,
459,
22357,
418,
64,
4113,
680,
339,
2779,
365,
6954,
24471,
370,
4868,
626,
17121,
83,
4458,
3633,
590,
1380,
286,
18959,
503,
272,
900,
734,
12,
436,
642,
4293,
506,
1202,
26523,
370,
3372,
283,
7661,
7,
5953,
315,
272,
283,
15172,
7,
25089,
503,
1067,
19680,
14,
339,
4178,
921,
13211,
14,
3098,
1365,
14,
957,
15,
19505,
15,
10836,
559,
15,
10836,
559,
13,
647,
15,
19616,
5211,
15,
1258,
15,
20237,
3553,
63,
9059,
14,
1064,
272,
408,
272,
372,
598,
12667,
63,
24340,
8819,
14,
2179,
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
] |
[
1898,
9708,
710,
491,
53,
3553,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
626,
883,
506,
1911,
315,
314,
5113,
570,
14,
199,
199,
504,
17121,
63,
3908,
492,
17121,
63,
1246,
199,
199,
504,
17121,
63,
3908,
14,
4672,
14,
2966,
63,
8831,
492,
598,
12667,
63,
24340,
8819,
421,
199,
533,
19103,
7394,
8,
13191,
63,
1246,
14,
25879,
7394,
304,
523,
408,
2765,
859,
465,
338,
10329,
315,
11805,
316,
543,
9920,
17121,
83,
14,
819,
2104,
2893,
12,
1380,
3952,
10417,
27378,
687,
6516,
3018,
370,
15111,
491,
53,
3553,
3464,
14,
523,
408,
819,
347,
636,
826,
721,
277,
12,
4382,
12,
1011,
958,
304,
272,
1613,
8,
14357,
7394,
12,
291,
2843,
826,
14155,
958,
9,
272,
291,
423,
3282,
275,
4382,
819,
768,
1829,
523,
347,
365,
63,
18924,
8,
277,
304,
272,
408,
549,
340,
642,
17121,
365,
5544,
3879,
315,
22820,
818,
14,
339,
29267,
4503,
365,
370,
2811,
7124,
1314,
7389,
5957,
5366,
13,
27626,
880,
626,
272,
2222,
13,
10777,
7858,
402,
314,
17121,
886,
440,
12787,
9920,
666,
14,
339,
6058,
26,
489,
627,
4949,
8786,
370,
376,
18034,
6233,
4887,
570,
536,
1380,
315,
2222,
13,
8788,
818,
489,
627,
4693,
3219,
282,
283,
2865,
13,
10777,
7,
1947,
370,
5957,
11785,
83,
272,
408,
272,
372,
291,
423,
3282,
14,
374,
63,
18924,
819,
768,
1829,
523,
347,
315,
63,
2966,
63,
8831,
8,
277,
304,
272,
408,
549,
17963,
642,
17121,
365,
5544,
315,
314,
283,
20631,
63,
5191,
7,
2013,
701,
272,
658,
20237,
3553,
63,
9059,
459,
22357,
418,
2313,
339,
961,
883,
4781,
1380,
26,
489,
627,
710,
491,
53,
3553,
63,
9059,
965,
9793,
314,
283,
4617,
63,
22357,
13619,
1549,
489,
627,
710,
491,
53,
3553,
63,
9059,
965,
2757,
283,
67,
18959,
7,
436,
314,
17121,
63,
3908,
965,
295,
559,
27986,
267,
282,
15522,
16718,
334,
265,
627,
78,
1148,
9,
503,
445,
7245,
13,
13948,
334,
265,
5417,
680,
339,
3709,
402,
499,
15385,
49,
18,
12,
1830,
314,
17121,
365,
315,
314,
19756,
63,
5191,
12,
652,
883,
886,
7003,
272,
485,
2590,
63,
367,
6617,
892,
7124,
334,
7911,
652,
883,
325,
14,
71,
14,
1678,
3451,
425,
402,
1551,
272,
7124,
12,
503,
372,
13480,
2889,
687,
3378,
20960,
680,
17413,
1337,
370,
1343,
282,
3650,
1830,
272,
315,
314,
19756,
63,
5191,
911,
7675,
314,
3650,
370,
3372,
6451,
14,
3979,
282,
4673,
365,
272,
295,
559,
27986,
503,
314,
11620,
63,
22357,
365,
9793,
12,
1006,
5544,
3879,
7124,
911,
506,
272,
2070,
65,
1146,
315,
7485,
334,
645,
5422,
370,
314,
658,
20237,
3553,
63,
9059,
459,
22357,
418,
64,
4113,
680,
339,
2779,
365,
6954,
24471,
370,
4868,
626,
17121,
83,
4458,
3633,
590,
1380,
286,
18959,
503,
272,
900,
734,
12,
436,
642,
4293,
506,
1202,
26523,
370,
3372,
283,
7661,
7,
5953,
315,
272,
283,
15172,
7,
25089,
503,
1067,
19680,
14,
339,
4178,
921,
13211,
14,
3098,
1365,
14,
957,
15,
19505,
15,
10836,
559,
15,
10836,
559,
13,
647,
15,
19616,
5211,
15,
1258,
15,
20237,
3553,
63,
9059,
14,
1064,
272,
408,
272,
372,
598,
12667,
63,
24340,
8819,
14,
2179,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
HealthAPI/helmet
|
node_modules/grunt-sass/node_modules/node-sass/node_modules/pangyp/gyp/pylib/gyp/__init__.py
|
574
|
21473
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import copy
import gyp.input
import optparse
import os.path
import re
import shlex
import sys
import traceback
from gyp.common import GypError
# Default debug modes for GYP
debug = {}
# List of "official" debug modes, but you can use anything you like.
DEBUG_GENERAL = 'general'
DEBUG_VARIABLES = 'variables'
DEBUG_INCLUDES = 'includes'
def DebugOutput(mode, message, *args):
if 'all' in gyp.debug or mode in gyp.debug:
ctx = ('unknown', 0, 'unknown')
try:
f = traceback.extract_stack(limit=2)
if f:
ctx = f[0][:3]
except:
pass
if args:
message %= args
print '%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]),
ctx[1], ctx[2], message)
def FindBuildFiles():
extension = '.gyp'
files = os.listdir(os.getcwd())
build_files = []
for file in files:
if file.endswith(extension):
build_files.append(file)
return build_files
def Load(build_files, format, default_variables={},
includes=[], depth='.', params=None, check=False,
circular_check=True):
"""
Loads one or more specified build files.
default_variables and includes will be copied before use.
Returns the generator for the specified format and the
data returned by loading the specified build files.
"""
if params is None:
params = {}
flavor = None
if '-' in format:
format, params['flavor'] = format.split('-', 1)
default_variables = copy.copy(default_variables)
# Default variables provided by this program and its modules should be
# named WITH_CAPITAL_LETTERS to provide a distinct "best practice" namespace,
# avoiding collisions with user and automatic variables.
default_variables['GENERATOR'] = format
# Format can be a custom python file, or by default the name of a module
# within gyp.generator.
if format.endswith('.py'):
generator_name = os.path.splitext(format)[0]
path, generator_name = os.path.split(generator_name)
# Make sure the path to the custom generator is in sys.path
# Don't worry about removing it once we are done. Keeping the path
# to each generator that is used in sys.path is likely harmless and
# arguably a good idea.
path = os.path.abspath(path)
if path not in sys.path:
sys.path.insert(0, path)
else:
generator_name = 'gyp.generator.' + format
# These parameters are passed in order (as opposed to by key)
# because ActivePython cannot handle key parameters to __import__.
generator = __import__(generator_name, globals(), locals(), generator_name)
for (key, val) in generator.generator_default_variables.items():
default_variables.setdefault(key, val)
# Give the generator the opportunity to set additional variables based on
# the params it will receive in the output phase.
if getattr(generator, 'CalculateVariables', None):
generator.CalculateVariables(default_variables, params)
# Give the generator the opportunity to set generator_input_info based on
# the params it will receive in the output phase.
if getattr(generator, 'CalculateGeneratorInputInfo', None):
generator.CalculateGeneratorInputInfo(params)
# Fetch the generator specific info that gets fed to input, we use getattr
# so we can default things and the generators only have to provide what
# they need.
generator_input_info = {
'non_configuration_keys':
getattr(generator, 'generator_additional_non_configuration_keys', []),
'path_sections':
getattr(generator, 'generator_additional_path_sections', []),
'extra_sources_for_rules':
getattr(generator, 'generator_extra_sources_for_rules', []),
'generator_supports_multiple_toolsets':
getattr(generator, 'generator_supports_multiple_toolsets', False),
'generator_wants_static_library_dependencies_adjusted':
getattr(generator,
'generator_wants_static_library_dependencies_adjusted', True),
'generator_wants_sorted_dependencies':
getattr(generator, 'generator_wants_sorted_dependencies', False),
'generator_filelist_paths':
getattr(generator, 'generator_filelist_paths', None),
}
# Process the input specific to this generator.
result = gyp.input.Load(build_files, default_variables, includes[:],
depth, generator_input_info, check, circular_check,
params['parallel'], params['root_targets'])
return [generator] + result
def NameValueListToDict(name_value_list):
"""
Takes an array of strings of the form 'NAME=VALUE' and creates a dictionary
of the pairs. If a string is simply NAME, then the value in the dictionary
is set to True. If VALUE can be converted to an integer, it is.
"""
result = { }
for item in name_value_list:
tokens = item.split('=', 1)
if len(tokens) == 2:
# If we can make it an int, use that, otherwise, use the string.
try:
token_value = int(tokens[1])
except ValueError:
token_value = tokens[1]
# Set the variable to the supplied value.
result[tokens[0]] = token_value
else:
# No value supplied, treat it as a boolean and set it.
result[tokens[0]] = True
return result
def ShlexEnv(env_name):
flags = os.environ.get(env_name, [])
if flags:
flags = shlex.split(flags)
return flags
def FormatOpt(opt, value):
if opt.startswith('--'):
return '%s=%s' % (opt, value)
return opt + value
def RegenerateAppendFlag(flag, values, predicate, env_name, options):
"""Regenerate a list of command line flags, for an option of action='append'.
The |env_name|, if given, is checked in the environment and used to generate
an initial list of options, then the options that were specified on the
command line (given in |values|) are appended. This matches the handling of
environment variables and command line flags where command line flags override
the environment, while not requiring the environment to be set when the flags
are used again.
"""
flags = []
if options.use_environment and env_name:
for flag_value in ShlexEnv(env_name):
value = FormatOpt(flag, predicate(flag_value))
if value in flags:
flags.remove(value)
flags.append(value)
if values:
for flag_value in values:
flags.append(FormatOpt(flag, predicate(flag_value)))
return flags
def RegenerateFlags(options):
"""Given a parsed options object, and taking the environment variables into
account, returns a list of flags that should regenerate an equivalent options
object (even in the absence of the environment variables.)
Any path options will be normalized relative to depth.
The format flag is not included, as it is assumed the calling generator will
set that as appropriate.
"""
def FixPath(path):
path = gyp.common.FixIfRelativePath(path, options.depth)
if not path:
return os.path.curdir
return path
def Noop(value):
return value
# We always want to ignore the environment when regenerating, to avoid
# duplicate or changed flags in the environment at the time of regeneration.
flags = ['--ignore-environment']
for name, metadata in options._regeneration_metadata.iteritems():
opt = metadata['opt']
value = getattr(options, name)
value_predicate = metadata['type'] == 'path' and FixPath or Noop
action = metadata['action']
env_name = metadata['env_name']
if action == 'append':
flags.extend(RegenerateAppendFlag(opt, value, value_predicate,
env_name, options))
elif action in ('store', None): # None is a synonym for 'store'.
if value:
flags.append(FormatOpt(opt, value_predicate(value)))
elif options.use_environment and env_name and os.environ.get(env_name):
flags.append(FormatOpt(opt, value_predicate(os.environ.get(env_name))))
elif action in ('store_true', 'store_false'):
if ((action == 'store_true' and value) or
(action == 'store_false' and not value)):
flags.append(opt)
elif options.use_environment and env_name:
print >>sys.stderr, ('Warning: environment regeneration unimplemented '
'for %s flag %r env_name %r' % (action, opt,
env_name))
else:
print >>sys.stderr, ('Warning: regeneration unimplemented for action %r '
'flag %r' % (action, opt))
return flags
class RegeneratableOptionParser(optparse.OptionParser):
def __init__(self):
self.__regeneratable_options = {}
optparse.OptionParser.__init__(self)
def add_option(self, *args, **kw):
"""Add an option to the parser.
This accepts the same arguments as OptionParser.add_option, plus the
following:
regenerate: can be set to False to prevent this option from being included
in regeneration.
env_name: name of environment variable that additional values for this
option come from.
type: adds type='path', to tell the regenerator that the values of
this option need to be made relative to options.depth
"""
env_name = kw.pop('env_name', None)
if 'dest' in kw and kw.pop('regenerate', True):
dest = kw['dest']
# The path type is needed for regenerating, for optparse we can just treat
# it as a string.
type = kw.get('type')
if type == 'path':
kw['type'] = 'string'
self.__regeneratable_options[dest] = {
'action': kw.get('action'),
'type': type,
'env_name': env_name,
'opt': args[0],
}
optparse.OptionParser.add_option(self, *args, **kw)
def parse_args(self, *args):
values, args = optparse.OptionParser.parse_args(self, *args)
values._regeneration_metadata = self.__regeneratable_options
return values, args
def gyp_main(args):
my_name = os.path.basename(sys.argv[0])
parser = RegeneratableOptionParser()
usage = 'usage: %s [options ...] [build_file ...]'
parser.set_usage(usage.replace('%s', '%prog'))
parser.add_option('--build', dest='configs', action='append',
help='configuration for build after project generation')
parser.add_option('--check', dest='check', action='store_true',
help='check format of gyp files')
parser.add_option('--config-dir', dest='config_dir', action='store',
env_name='GYP_CONFIG_DIR', default=None,
help='The location for configuration files like '
'include.gypi.')
parser.add_option('-d', '--debug', dest='debug', metavar='DEBUGMODE',
action='append', default=[], help='turn on a debugging '
'mode for debugging GYP. Supported modes are "variables", '
'"includes" and "general" or "all" for all of them.')
parser.add_option('-D', dest='defines', action='append', metavar='VAR=VAL',
env_name='GYP_DEFINES',
help='sets variable VAR to value VAL')
parser.add_option('--depth', dest='depth', metavar='PATH', type='path',
help='set DEPTH gyp variable to a relative path to PATH')
parser.add_option('-f', '--format', dest='formats', action='append',
env_name='GYP_GENERATORS', regenerate=False,
help='output formats to generate')
parser.add_option('-G', dest='generator_flags', action='append', default=[],
metavar='FLAG=VAL', env_name='GYP_GENERATOR_FLAGS',
help='sets generator flag FLAG to VAL')
parser.add_option('--generator-output', dest='generator_output',
action='store', default=None, metavar='DIR', type='path',
env_name='GYP_GENERATOR_OUTPUT',
help='puts generated build files under DIR')
parser.add_option('--ignore-environment', dest='use_environment',
action='store_false', default=True, regenerate=False,
help='do not read options from environment variables')
parser.add_option('-I', '--include', dest='includes', action='append',
metavar='INCLUDE', type='path',
help='files to include in all loaded .gyp files')
# --no-circular-check disables the check for circular relationships between
# .gyp files. These relationships should not exist, but they've only been
# observed to be harmful with the Xcode generator. Chromium's .gyp files
# currently have some circular relationships on non-Mac platforms, so this
# option allows the strict behavior to be used on Macs and the lenient
# behavior to be used elsewhere.
# TODO(mark): Remove this option when http://crbug.com/35878 is fixed.
parser.add_option('--no-circular-check', dest='circular_check',
action='store_false', default=True, regenerate=False,
help="don't check for circular relationships between files")
parser.add_option('--no-parallel', action='store_true', default=False,
help='Disable multiprocessing')
parser.add_option('-S', '--suffix', dest='suffix', default='',
help='suffix to add to generated files')
parser.add_option('--toplevel-dir', dest='toplevel_dir', action='store',
default=None, metavar='DIR', type='path',
help='directory to use as the root of the source tree')
parser.add_option('-R', '--root-target', dest='root_targets',
action='append', metavar='TARGET',
help='include only TARGET and its deep dependencies')
options, build_files_arg = parser.parse_args(args)
build_files = build_files_arg
# Set up the configuration directory (defaults to ~/.gyp)
if not options.config_dir:
home = None
home_dot_gyp = None
if options.use_environment:
home_dot_gyp = os.environ.get('GYP_CONFIG_DIR', None)
if home_dot_gyp:
home_dot_gyp = os.path.expanduser(home_dot_gyp)
if not home_dot_gyp:
home_vars = ['HOME']
if sys.platform in ('cygwin', 'win32'):
home_vars.append('USERPROFILE')
for home_var in home_vars:
home = os.getenv(home_var)
if home != None:
home_dot_gyp = os.path.join(home, '.gyp')
if not os.path.exists(home_dot_gyp):
home_dot_gyp = None
else:
break
else:
home_dot_gyp = os.path.expanduser(options.config_dir)
if home_dot_gyp and not os.path.exists(home_dot_gyp):
home_dot_gyp = None
if not options.formats:
# If no format was given on the command line, then check the env variable.
generate_formats = []
if options.use_environment:
generate_formats = os.environ.get('GYP_GENERATORS', [])
if generate_formats:
generate_formats = re.split('[\s,]', generate_formats)
if generate_formats:
options.formats = generate_formats
else:
# Nothing in the variable, default based on platform.
if sys.platform == 'darwin':
options.formats = ['xcode']
elif sys.platform in ('win32', 'cygwin'):
options.formats = ['msvs']
else:
options.formats = ['make']
if not options.generator_output and options.use_environment:
g_o = os.environ.get('GYP_GENERATOR_OUTPUT')
if g_o:
options.generator_output = g_o
options.parallel = not options.no_parallel
for mode in options.debug:
gyp.debug[mode] = 1
# Do an extra check to avoid work when we're not debugging.
if DEBUG_GENERAL in gyp.debug:
DebugOutput(DEBUG_GENERAL, 'running with these options:')
for option, value in sorted(options.__dict__.items()):
if option[0] == '_':
continue
if isinstance(value, basestring):
DebugOutput(DEBUG_GENERAL, " %s: '%s'", option, value)
else:
DebugOutput(DEBUG_GENERAL, " %s: %s", option, value)
if not build_files:
build_files = FindBuildFiles()
if not build_files:
raise GypError((usage + '\n\n%s: error: no build_file') %
(my_name, my_name))
# TODO(mark): Chromium-specific hack!
# For Chromium, the gyp "depth" variable should always be a relative path
# to Chromium's top-level "src" directory. If no depth variable was set
# on the command line, try to find a "src" directory by looking at the
# absolute path to each build file's directory. The first "src" component
# found will be treated as though it were the path used for --depth.
if not options.depth:
for build_file in build_files:
build_file_dir = os.path.abspath(os.path.dirname(build_file))
build_file_dir_components = build_file_dir.split(os.path.sep)
components_len = len(build_file_dir_components)
for index in xrange(components_len - 1, -1, -1):
if build_file_dir_components[index] == 'src':
options.depth = os.path.sep.join(build_file_dir_components)
break
del build_file_dir_components[index]
# If the inner loop found something, break without advancing to another
# build file.
if options.depth:
break
if not options.depth:
raise GypError('Could not automatically locate src directory. This is'
'a temporary Chromium feature that will be removed. Use'
'--depth as a workaround.')
# If toplevel-dir is not set, we assume that depth is the root of our source
# tree.
if not options.toplevel_dir:
options.toplevel_dir = options.depth
# -D on the command line sets variable defaults - D isn't just for define,
# it's for default. Perhaps there should be a way to force (-F?) a
# variable's value so that it can't be overridden by anything else.
cmdline_default_variables = {}
defines = []
if options.use_environment:
defines += ShlexEnv('GYP_DEFINES')
if options.defines:
defines += options.defines
cmdline_default_variables = NameValueListToDict(defines)
if DEBUG_GENERAL in gyp.debug:
DebugOutput(DEBUG_GENERAL,
"cmdline_default_variables: %s", cmdline_default_variables)
# Set up includes.
includes = []
# If ~/.gyp/include.gypi exists, it'll be forcibly included into every
# .gyp file that's loaded, before anything else is included.
if home_dot_gyp != None:
default_include = os.path.join(home_dot_gyp, 'include.gypi')
if os.path.exists(default_include):
print 'Using overrides found in ' + default_include
includes.append(default_include)
# Command-line --include files come after the default include.
if options.includes:
includes.extend(options.includes)
# Generator flags should be prefixed with the target generator since they
# are global across all generator runs.
gen_flags = []
if options.use_environment:
gen_flags += ShlexEnv('GYP_GENERATOR_FLAGS')
if options.generator_flags:
gen_flags += options.generator_flags
generator_flags = NameValueListToDict(gen_flags)
if DEBUG_GENERAL in gyp.debug.keys():
DebugOutput(DEBUG_GENERAL, "generator_flags: %s", generator_flags)
# Generate all requested formats (use a set in case we got one format request
# twice)
for format in set(options.formats):
params = {'options': options,
'build_files': build_files,
'generator_flags': generator_flags,
'cwd': os.getcwd(),
'build_files_arg': build_files_arg,
'gyp_binary': sys.argv[0],
'home_dot_gyp': home_dot_gyp,
'parallel': options.parallel,
'root_targets': options.root_targets}
# Start with the default variables from the command line.
[generator, flat_list, targets, data] = Load(build_files, format,
cmdline_default_variables,
includes, options.depth,
params, options.check,
options.circular_check)
# TODO(mark): Pass |data| for now because the generator needs a list of
# build files that came in. In the future, maybe it should just accept
# a list, and not the whole data dict.
# NOTE: flat_list is the flattened dependency graph specifying the order
# that targets may be built. Build systems that operate serially or that
# need to have dependencies defined before dependents reference them should
# generate targets in the order specified in flat_list.
generator.GenerateOutput(flat_list, targets, data, params)
if options.configs:
valid_configs = targets[flat_list[0]]['configurations'].keys()
for conf in options.configs:
if conf not in valid_configs:
raise GypError('Invalid config specified via --build: %s' % conf)
generator.PerformBuild(data, options.configs, params)
# Done
return 0
def main(args):
try:
return gyp_main(args)
except GypError, e:
sys.stderr.write("gyp: %s\n" % e)
return 1
# NOTE: setuptools generated console_scripts calls function with no arguments
def script_main():
return main(sys.argv[1:])
if __name__ == '__main__':
sys.exit(script_main())
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
4902,
14,
1210,
199,
646,
8691,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
16701,
199,
646,
984,
199,
646,
5190,
199,
504,
4902,
14,
2330,
492,
18151,
199,
199,
3,
3758,
3105,
12404,
367,
25686,
199,
1757,
275,
1052,
199,
199,
3,
3820,
402,
298,
29260,
2,
3105,
12404,
12,
1325,
1265,
883,
675,
7003,
1265,
2839,
14,
199,
5287,
63,
31548,
275,
283,
10706,
7,
199,
5287,
63,
21161,
275,
283,
3669,
7,
199,
5287,
63,
568,
29992,
275,
283,
9441,
7,
421,
199,
318,
14245,
2959,
8,
632,
12,
1245,
12,
627,
589,
304,
523,
340,
283,
452,
7,
315,
4902,
14,
1757,
503,
818,
315,
4902,
14,
1757,
26,
272,
4027,
275,
661,
5187,
297,
378,
12,
283,
5187,
358,
272,
862,
26,
489,
289,
275,
5190,
14,
5005,
63,
2340,
8,
3097,
29,
18,
9,
489,
340,
289,
26,
267,
4027,
275,
289,
59,
16,
19663,
19,
61,
272,
871,
26,
489,
986,
272,
340,
1249,
26,
489,
1245,
450,
29,
1249,
272,
870,
1543,
83,
2689,
83,
2689,
68,
2689,
83,
450,
83,
7,
450,
334,
632,
14,
4142,
1062,
747,
14,
515,
14,
4846,
8,
3799,
59,
16,
2522,
2892,
4027,
59,
17,
467,
4027,
59,
18,
467,
1245,
9,
199,
199,
318,
6668,
3425,
5535,
837,
523,
3329,
275,
1987,
6179,
7,
523,
1584,
275,
747,
14,
7374,
8,
736,
14,
9458,
1012,
523,
1900,
63,
1725,
275,
942,
523,
367,
570,
315,
1584,
26,
272,
340,
570,
14,
4130,
8,
3435,
304,
489,
1900,
63,
1725,
14,
740,
8,
493,
9,
523,
372,
1900,
63,
1725,
421,
199,
318,
7190,
8,
1506,
63,
1725,
12,
1475,
12,
849,
63,
3669,
10324,
268,
6952,
6034,
5818,
534,
3130,
1862,
29,
403,
12,
1104,
29,
797,
12,
268,
15032,
63,
1074,
29,
549,
304,
523,
408,
523,
30367,
1373,
503,
1655,
2013,
1900,
1584,
14,
523,
849,
63,
3669,
436,
6952,
911,
506,
8876,
2544,
675,
14,
523,
1803,
314,
4306,
367,
314,
2013,
1475,
436,
314,
523,
666,
2138,
701,
8697,
314,
2013,
1900,
1584,
14,
523,
408,
523,
340,
1862,
365,
488,
26,
272,
1862,
275,
1052,
819,
8541,
275,
488,
523,
340,
10791,
315,
1475,
26,
272,
1475,
12,
1862,
459,
6081,
418,
275,
1475,
14,
1294,
13858,
413,
9,
819,
849,
63,
3669,
275,
1331,
14,
1574,
8,
885,
63,
3669,
9,
819,
327,
3758,
2860,
2741,
701,
642,
2240,
436,
2399,
4621,
1077,
506,
523,
327,
4310,
1663,
63,
35,
2669,
63,
44,
1573,
51,
370,
5647,
282,
15392,
298,
7010,
24471,
2,
3231,
12,
523,
327,
5126,
316,
30063,
543,
922,
436,
4834,
2860,
14,
523,
849,
63,
3669,
459,
12795,
6467,
418,
275,
1475,
819,
327,
9701,
883,
506,
282,
3537,
2366,
570,
12,
503,
701,
849,
314,
536,
402,
282,
859,
523,
327,
4453,
4902,
14,
4679,
14,
523,
340,
1475,
14,
4130,
5175,
647,
735,
272,
4306,
63,
354,
275,
747,
14,
515,
14,
7973,
8,
908,
2788,
16,
61,
272,
931,
12,
4306,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4679,
63,
354,
9,
339,
327,
4155,
3238,
314,
931,
370,
314,
3537,
4306,
365,
315,
984,
14,
515,
272,
327,
7529,
1133,
30944,
3595,
12881,
652,
5403,
781,
787,
4224,
14,
221,
1804,
1024,
4073,
314,
931,
272,
327,
370,
1924,
4306,
626,
365,
1202,
315,
984,
14,
515,
365,
12060,
394,
5362,
2003,
436,
272,
327,
1680,
85,
6665,
282,
6954,
16819,
14,
272,
931,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
272,
340,
931,
440,
315,
984,
14,
515,
26,
489,
984,
14,
515,
14,
3176,
8,
16,
12,
931,
9,
523,
587,
26,
272,
4306,
63,
354,
275,
283,
6179,
14,
4679,
3530,
435,
1475,
819,
327,
5723,
2633,
787,
3032,
315,
1865,
334,
305,
25068,
370,
701,
790,
9,
523,
327,
2952,
23241,
4718,
3913,
2429,
790,
2633,
370,
636,
646,
4343,
523,
4306,
275,
636,
646,
721,
4679,
63,
354,
12,
7992,
1062,
9480,
1062,
4306,
63,
354,
9,
523,
367,
334,
498,
12,
1139,
9,
315,
4306,
14,
4679,
63,
885,
63,
3669,
14,
1744,
837,
272,
849,
63,
3669,
14,
5486,
8,
498,
12,
1139,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4722,
2860,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
11458,
297,
488,
304,
272,
4306,
14,
14860,
11458,
8,
885,
63,
3669,
12,
1862,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4306,
63,
1210,
63,
815,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
7599,
3205,
2354,
297,
488,
304,
272,
4306,
14,
14860,
7599,
3205,
2354,
8,
1162,
9,
819,
327,
16347,
314,
4306,
2488,
2256,
626,
7545,
23036,
370,
1324,
12,
781,
675,
2519,
523,
327,
880,
781,
883,
849,
7645,
436,
314,
16952,
1454,
1172,
370,
5647,
4052,
523,
327,
2985,
1929,
14,
523,
4306,
63,
1210,
63,
815,
275,
469,
272,
283,
2865,
63,
4758,
63,
1612,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
297,
14431,
272,
283,
515,
63,
7786,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
515,
63,
7786,
297,
14431,
272,
283,
2911,
63,
4553,
63,
509,
63,
4423,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
297,
14431,
272,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
297,
756,
395,
272,
283,
4679,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
356,
267,
2519,
8,
4679,
12,
355,
283,
4679,
63,
28789,
63,
1986,
63,
4342,
63
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
4902,
14,
1210,
199,
646,
8691,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
16701,
199,
646,
984,
199,
646,
5190,
199,
504,
4902,
14,
2330,
492,
18151,
199,
199,
3,
3758,
3105,
12404,
367,
25686,
199,
1757,
275,
1052,
199,
199,
3,
3820,
402,
298,
29260,
2,
3105,
12404,
12,
1325,
1265,
883,
675,
7003,
1265,
2839,
14,
199,
5287,
63,
31548,
275,
283,
10706,
7,
199,
5287,
63,
21161,
275,
283,
3669,
7,
199,
5287,
63,
568,
29992,
275,
283,
9441,
7,
421,
199,
318,
14245,
2959,
8,
632,
12,
1245,
12,
627,
589,
304,
523,
340,
283,
452,
7,
315,
4902,
14,
1757,
503,
818,
315,
4902,
14,
1757,
26,
272,
4027,
275,
661,
5187,
297,
378,
12,
283,
5187,
358,
272,
862,
26,
489,
289,
275,
5190,
14,
5005,
63,
2340,
8,
3097,
29,
18,
9,
489,
340,
289,
26,
267,
4027,
275,
289,
59,
16,
19663,
19,
61,
272,
871,
26,
489,
986,
272,
340,
1249,
26,
489,
1245,
450,
29,
1249,
272,
870,
1543,
83,
2689,
83,
2689,
68,
2689,
83,
450,
83,
7,
450,
334,
632,
14,
4142,
1062,
747,
14,
515,
14,
4846,
8,
3799,
59,
16,
2522,
2892,
4027,
59,
17,
467,
4027,
59,
18,
467,
1245,
9,
199,
199,
318,
6668,
3425,
5535,
837,
523,
3329,
275,
1987,
6179,
7,
523,
1584,
275,
747,
14,
7374,
8,
736,
14,
9458,
1012,
523,
1900,
63,
1725,
275,
942,
523,
367,
570,
315,
1584,
26,
272,
340,
570,
14,
4130,
8,
3435,
304,
489,
1900,
63,
1725,
14,
740,
8,
493,
9,
523,
372,
1900,
63,
1725,
421,
199,
318,
7190,
8,
1506,
63,
1725,
12,
1475,
12,
849,
63,
3669,
10324,
268,
6952,
6034,
5818,
534,
3130,
1862,
29,
403,
12,
1104,
29,
797,
12,
268,
15032,
63,
1074,
29,
549,
304,
523,
408,
523,
30367,
1373,
503,
1655,
2013,
1900,
1584,
14,
523,
849,
63,
3669,
436,
6952,
911,
506,
8876,
2544,
675,
14,
523,
1803,
314,
4306,
367,
314,
2013,
1475,
436,
314,
523,
666,
2138,
701,
8697,
314,
2013,
1900,
1584,
14,
523,
408,
523,
340,
1862,
365,
488,
26,
272,
1862,
275,
1052,
819,
8541,
275,
488,
523,
340,
10791,
315,
1475,
26,
272,
1475,
12,
1862,
459,
6081,
418,
275,
1475,
14,
1294,
13858,
413,
9,
819,
849,
63,
3669,
275,
1331,
14,
1574,
8,
885,
63,
3669,
9,
819,
327,
3758,
2860,
2741,
701,
642,
2240,
436,
2399,
4621,
1077,
506,
523,
327,
4310,
1663,
63,
35,
2669,
63,
44,
1573,
51,
370,
5647,
282,
15392,
298,
7010,
24471,
2,
3231,
12,
523,
327,
5126,
316,
30063,
543,
922,
436,
4834,
2860,
14,
523,
849,
63,
3669,
459,
12795,
6467,
418,
275,
1475,
819,
327,
9701,
883,
506,
282,
3537,
2366,
570,
12,
503,
701,
849,
314,
536,
402,
282,
859,
523,
327,
4453,
4902,
14,
4679,
14,
523,
340,
1475,
14,
4130,
5175,
647,
735,
272,
4306,
63,
354,
275,
747,
14,
515,
14,
7973,
8,
908,
2788,
16,
61,
272,
931,
12,
4306,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4679,
63,
354,
9,
339,
327,
4155,
3238,
314,
931,
370,
314,
3537,
4306,
365,
315,
984,
14,
515,
272,
327,
7529,
1133,
30944,
3595,
12881,
652,
5403,
781,
787,
4224,
14,
221,
1804,
1024,
4073,
314,
931,
272,
327,
370,
1924,
4306,
626,
365,
1202,
315,
984,
14,
515,
365,
12060,
394,
5362,
2003,
436,
272,
327,
1680,
85,
6665,
282,
6954,
16819,
14,
272,
931,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
272,
340,
931,
440,
315,
984,
14,
515,
26,
489,
984,
14,
515,
14,
3176,
8,
16,
12,
931,
9,
523,
587,
26,
272,
4306,
63,
354,
275,
283,
6179,
14,
4679,
3530,
435,
1475,
819,
327,
5723,
2633,
787,
3032,
315,
1865,
334,
305,
25068,
370,
701,
790,
9,
523,
327,
2952,
23241,
4718,
3913,
2429,
790,
2633,
370,
636,
646,
4343,
523,
4306,
275,
636,
646,
721,
4679,
63,
354,
12,
7992,
1062,
9480,
1062,
4306,
63,
354,
9,
523,
367,
334,
498,
12,
1139,
9,
315,
4306,
14,
4679,
63,
885,
63,
3669,
14,
1744,
837,
272,
849,
63,
3669,
14,
5486,
8,
498,
12,
1139,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4722,
2860,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
11458,
297,
488,
304,
272,
4306,
14,
14860,
11458,
8,
885,
63,
3669,
12,
1862,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4306,
63,
1210,
63,
815,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
7599,
3205,
2354,
297,
488,
304,
272,
4306,
14,
14860,
7599,
3205,
2354,
8,
1162,
9,
819,
327,
16347,
314,
4306,
2488,
2256,
626,
7545,
23036,
370,
1324,
12,
781,
675,
2519,
523,
327,
880,
781,
883,
849,
7645,
436,
314,
16952,
1454,
1172,
370,
5647,
4052,
523,
327,
2985,
1929,
14,
523,
4306,
63,
1210,
63,
815,
275,
469,
272,
283,
2865,
63,
4758,
63,
1612,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
297,
14431,
272,
283,
515,
63,
7786,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
515,
63,
7786,
297,
14431,
272,
283,
2911,
63,
4553,
63,
509,
63,
4423,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
297,
14431,
272,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
297,
756,
395,
272,
283,
4679,
63,
28789,
63,
1986,
63,
4342,
63,
5714,
63,
23395,
356,
267,
2519,
8,
4679,
12,
355,
283,
4679,
63,
28789,
63,
1986,
63,
4342,
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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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
] |
ujdhesa/unisubs
|
apps/teams/migrations/0118_teammember_created.py
|
5
|
41404
|
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models
class Migration(DataMigration):
def forwards(self, orm):
"Write your forwards methods here."
for tm in orm['teams.TeamMember'].objects.all():
try:
activity = orm['videos.Action'].objects.filter(team=tm.team,
user=tm.user, member=tm)[0]
except IndexError:
# This includes TeamMember instances created through the admin
print 'Skipping TeamMember pk %s' % tm.pk
continue
tm.created = activity.created
tm.save()
def backwards(self, orm):
"Write your backwards methods here."
pass
models = {
'accountlinker.thirdpartyaccount': {
'Meta': {'unique_together': "(('type', 'username'),)", 'object_name': 'ThirdPartyAccount'},
'full_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'oauth_access_token': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'oauth_refresh_token': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
'username': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'})
},
'auth.customuser': {
'Meta': {'object_name': 'CustomUser', '_ormbases': ['auth.User']},
'autoplay_preferences': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
'award_points': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'biography': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'can_send_messages': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'full_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '63', 'blank': 'True'}),
'homepage': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
'is_partner': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'last_ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}),
'notify_by_email': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'notify_by_message': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'partner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Partner']", 'null': 'True', 'blank': 'True'}),
'picture': ('utils.amazon.fields.S3EnabledImageField', [], {'thumb_options': "{'upscale': True, 'crop': 'smart'}", 'max_length': '100', 'blank': 'True'}),
'preferred_language': ('django.db.models.fields.CharField', [], {'max_length': '16', 'blank': 'True'}),
'third_party_accounts': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'users'", 'symmetrical': 'False', 'to': "orm['accountlinker.ThirdPartyAccount']"}),
'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'}),
'valid_email': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'videos': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['videos.Video']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'comments.comment': {
'Meta': {'object_name': 'Comment'},
'content': ('django.db.models.fields.TextField', [], {'max_length': '3000'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'content_type_set_for_comment'", 'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'object_pk': ('django.db.models.fields.TextField', [], {}),
'reply_to': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['comments.Comment']", 'null': 'True', 'blank': 'True'}),
'submit_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']"})
},
'contenttypes.contenttype': {
'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'teams.application': {
'Meta': {'unique_together': "(('team', 'user', 'status'),)", 'object_name': 'Application'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'history': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'note': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'status': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'applications'", 'to': "orm['teams.Team']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'team_applications'", 'to': "orm['auth.CustomUser']"})
},
'teams.billingrecord': {
'Meta': {'unique_together': "(('video', 'subtitle_language'),)", 'object_name': 'BillingRecord'},
'created': ('django.db.models.fields.DateTimeField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_original': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'minutes': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
'source': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'subtitle_language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.SubtitleLanguage']"}),
'subtitle_version': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.SubtitleVersion']"}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Team']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']"}),
'video': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.Video']"})
},
'teams.billingreport': {
'Meta': {'object_name': 'BillingReport'},
'csv_file': ('utils.amazon.fields.S3EnabledFileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'end_date': ('django.db.models.fields.DateField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'processed': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'start_date': ('django.db.models.fields.DateField', [], {}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Team']"})
},
'teams.invite': {
'Meta': {'object_name': 'Invite'},
'approved': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'note': ('django.db.models.fields.TextField', [], {'max_length': '200', 'blank': 'True'}),
'role': ('django.db.models.fields.CharField', [], {'default': "'contributor'", 'max_length': '16'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'invitations'", 'to': "orm['teams.Team']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'team_invitations'", 'to': "orm['auth.CustomUser']"})
},
'teams.membershipnarrowing': {
'Meta': {'object_name': 'MembershipNarrowing'},
'added_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'narrowing_includer'", 'null': 'True', 'to': "orm['teams.TeamMember']"}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.CharField', [], {'max_length': '24', 'blank': 'True'}),
'member': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'narrowings'", 'to': "orm['teams.TeamMember']"}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Project']", 'null': 'True', 'blank': 'True'})
},
'teams.partner': {
'Meta': {'object_name': 'Partner'},
'admins': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'managed_partners'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['auth.CustomUser']"}),
'can_request_paid_captions': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '250'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'})
},
'teams.project': {
'Meta': {'unique_together': "(('team', 'name'), ('team', 'slug'))", 'object_name': 'Project'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'max_length': '2048', 'null': 'True', 'blank': 'True'}),
'guidelines': ('django.db.models.fields.TextField', [], {'max_length': '2048', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'order': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
'slug': ('django.db.models.fields.SlugField', [], {'db_index': 'True', 'max_length': '50', 'blank': 'True'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Team']"}),
'workflow_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'})
},
'teams.setting': {
'Meta': {'unique_together': "(('key', 'team'),)", 'object_name': 'Setting'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'data': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.PositiveIntegerField', [], {}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'settings'", 'to': "orm['teams.Team']"})
},
'teams.task': {
'Meta': {'object_name': 'Task'},
'approved': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
'assignee': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']", 'null': 'True', 'blank': 'True'}),
'body': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'completed': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'expiration_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '16', 'blank': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'priority': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0', 'db_index': 'True', 'blank': 'True'}),
'public': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'review_base_version': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'tasks_based_on'", 'null': 'True', 'to': "orm['videos.SubtitleVersion']"}),
'subtitle_version': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.SubtitleVersion']", 'null': 'True', 'blank': 'True'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Team']"}),
'team_video': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.TeamVideo']"}),
'type': ('django.db.models.fields.PositiveIntegerField', [], {})
},
'teams.team': {
'Meta': {'object_name': 'Team'},
'applicants': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'applicated_teams'", 'symmetrical': 'False', 'through': "orm['teams.Application']", 'to': "orm['auth.CustomUser']"}),
'application_text': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'auth_provider_code': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '24', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'header_html_text': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'highlight': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_moderated': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'is_visible': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'last_notification_time': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'logo': ('utils.amazon.fields.S3EnabledImageField', [], {'thumb_options': "{'upscale': True, 'autocrop': True}", 'max_length': '100', 'blank': 'True'}),
'max_tasks_per_member': ('django.db.models.fields.PositiveIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
'membership_policy': ('django.db.models.fields.IntegerField', [], {'default': '4'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '250'}),
'page_content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'partner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'teams'", 'null': 'True', 'to': "orm['teams.Partner']"}),
'points': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'projects_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
'subtitle_policy': ('django.db.models.fields.IntegerField', [], {'default': '10'}),
'task_assign_policy': ('django.db.models.fields.IntegerField', [], {'default': '10'}),
'task_expiration': ('django.db.models.fields.PositiveIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
'third_party_accounts': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'teams'", 'symmetrical': 'False', 'to': "orm['accountlinker.ThirdPartyAccount']"}),
'translate_policy': ('django.db.models.fields.IntegerField', [], {'default': '10'}),
'users': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'teams'", 'symmetrical': 'False', 'through': "orm['teams.TeamMember']", 'to': "orm['auth.CustomUser']"}),
'video': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'intro_for_teams'", 'null': 'True', 'to': "orm['videos.Video']"}),
'video_policy': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
'videos': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['videos.Video']", 'through': "orm['teams.TeamVideo']", 'symmetrical': 'False'}),
'workflow_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'})
},
'teams.teamlanguagepreference': {
'Meta': {'unique_together': "(('team', 'language_code'),)", 'object_name': 'TeamLanguagePreference'},
'allow_reads': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'allow_writes': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language_code': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
'preferred': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'lang_preferences'", 'to': "orm['teams.Team']"})
},
'teams.teammember': {
'Meta': {'unique_together': "(('team', 'user'),)", 'object_name': 'TeamMember'},
'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'role': ('django.db.models.fields.CharField', [], {'default': "'contributor'", 'max_length': '16', 'db_index': 'True'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'members'", 'to': "orm['teams.Team']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'team_members'", 'to': "orm['auth.CustomUser']"})
},
'teams.teamnotificationsetting': {
'Meta': {'object_name': 'TeamNotificationSetting'},
'basic_auth_password': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'basic_auth_username': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'notification_class': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
'partner': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'related_name': "'notification_settings'", 'unique': 'True', 'null': 'True', 'to': "orm['teams.Partner']"}),
'request_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'team': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'related_name': "'notification_settings'", 'unique': 'True', 'null': 'True', 'to': "orm['teams.Team']"})
},
'teams.teamvideo': {
'Meta': {'unique_together': "(('team', 'video'),)", 'object_name': 'TeamVideo'},
'added_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']"}),
'all_languages': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'completed_languages': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['videos.SubtitleLanguage']", 'symmetrical': 'False', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'partner_id': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '100', 'blank': 'True'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Project']"}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Team']"}),
'thumbnail': ('utils.amazon.fields.S3EnabledImageField', [], {'max_length': '100', 'thumb_options': "{'upscale': True, 'crop': 'smart'}", 'null': 'True', 'thumb_sizes': '((290, 165), (120, 90))', 'blank': 'True'}),
'video': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['videos.Video']", 'unique': 'True'})
},
'teams.workflow': {
'Meta': {'unique_together': "(('team', 'project', 'team_video'),)", 'object_name': 'Workflow'},
'approve_allowed': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
'autocreate_subtitle': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'autocreate_translate': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Project']", 'null': 'True', 'blank': 'True'}),
'review_allowed': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Team']"}),
'team_video': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.TeamVideo']", 'null': 'True', 'blank': 'True'})
},
'videos.action': {
'Meta': {'object_name': 'Action'},
'action_type': ('django.db.models.fields.IntegerField', [], {}),
'comment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['comments.Comment']", 'null': 'True', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.SubtitleLanguage']", 'null': 'True', 'blank': 'True'}),
'member': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.TeamMember']", 'null': 'True', 'blank': 'True'}),
'new_video_title': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'blank': 'True'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Team']", 'null': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']", 'null': 'True', 'blank': 'True'}),
'video': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.Video']", 'null': 'True', 'blank': 'True'})
},
'videos.subtitle': {
'Meta': {'unique_together': "(('version', 'subtitle_id'),)", 'object_name': 'Subtitle'},
'end_time': ('django.db.models.fields.IntegerField', [], {'default': 'None', 'null': 'True', 'db_column': "'end_time_ms'"}),
'end_time_seconds': ('django.db.models.fields.FloatField', [], {'null': 'True', 'db_column': "'end_time'"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'start_of_paragraph': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'start_time': ('django.db.models.fields.IntegerField', [], {'default': 'None', 'null': 'True', 'db_column': "'start_time_ms'"}),
'start_time_seconds': ('django.db.models.fields.FloatField', [], {'null': 'True', 'db_column': "'start_time'"}),
'subtitle_id': ('django.db.models.fields.CharField', [], {'max_length': '32', 'blank': 'True'}),
'subtitle_order': ('django.db.models.fields.FloatField', [], {'null': 'True'}),
'subtitle_text': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'blank': 'True'}),
'version': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.SubtitleVersion']", 'null': 'True'})
},
'videos.subtitlelanguage': {
'Meta': {'unique_together': "(('video', 'language', 'standard_language'),)", 'object_name': 'SubtitleLanguage'},
'created': ('django.db.models.fields.DateTimeField', [], {}),
'followers': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'followed_languages'", 'blank': 'True', 'to': "orm['auth.CustomUser']"}),
'had_version': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'has_version': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_complete': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'is_forked': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'is_original': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'language': ('django.db.models.fields.CharField', [], {'max_length': '16', 'blank': 'True'}),
'percent_done': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'standard_language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.SubtitleLanguage']", 'null': 'True', 'blank': 'True'}),
'subtitle_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'subtitles_fetched_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'video': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.Video']"}),
'writelock_owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']", 'null': 'True', 'blank': 'True'}),
'writelock_session_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'writelock_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True'})
},
'videos.subtitlemetadata': {
'Meta': {'object_name': 'SubtitleMetadata'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'data': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.PositiveIntegerField', [], {}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'subtitle': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.Subtitle']"})
},
'videos.subtitleversion': {
'Meta': {'unique_together': "(('language', 'version_no'),)", 'object_name': 'SubtitleVersion'},
'datetime_started': ('django.db.models.fields.DateTimeField', [], {}),
'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'forked_from': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.SubtitleVersion']", 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_forked': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.SubtitleLanguage']"}),
'moderation_status': ('django.db.models.fields.CharField', [], {'default': "'not__under_moderation'", 'max_length': '32', 'db_index': 'True'}),
'note': ('django.db.models.fields.CharField', [], {'max_length': '512', 'blank': 'True'}),
'notification_sent': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'result_of_rollback': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'text_change': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
'time_change': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']"}),
'version_no': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'})
},
'videos.subtitleversionmetadata': {
'Meta': {'unique_together': "(('key', 'subtitle_version'),)", 'object_name': 'SubtitleVersionMetadata'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'data': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.PositiveIntegerField', [], {}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'subtitle_version': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'metadata'", 'to': "orm['videos.SubtitleVersion']"})
},
'videos.usertestresult': {
'Meta': {'object_name': 'UserTestResult'},
'browser': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'get_updates': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'task1': ('django.db.models.fields.TextField', [], {}),
'task2': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'task3': ('django.db.models.fields.TextField', [], {'blank': 'True'})
},
'videos.video': {
'Meta': {'object_name': 'Video'},
'allow_community_edits': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'allow_video_urls_edit': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'complete_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'duration': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
'edited': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'featured': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'followers': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'followed_videos'", 'blank': 'True', 'to': "orm['auth.CustomUser']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
'is_subtitled': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'languages_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0', 'db_index': 'True'}),
'moderated_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'moderating'", 'null': 'True', 'to': "orm['teams.Team']"}),
's3_thumbnail': ('utils.amazon.fields.S3EnabledImageField', [], {'thumb_options': "{'upscale': True, 'crop': 'smart'}", 'max_length': '100', 'thumb_sizes': '((290, 165), (120, 90))', 'blank': 'True'}),
'small_thumbnail': ('django.db.models.fields.CharField', [], {'max_length': '500', 'blank': 'True'}),
'subtitles_fetched_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
'thumbnail': ('django.db.models.fields.CharField', [], {'max_length': '500', 'blank': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '2048', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']", 'null': 'True', 'blank': 'True'}),
'video_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'view_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0', 'db_index': 'True'}),
'was_subtitled': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True', 'blank': 'True'}),
'widget_views_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
'writelock_owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'writelock_owners'", 'null': 'True', 'to': "orm['auth.CustomUser']"}),
'writelock_session_key': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'writelock_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True'})
},
'videos.videofeed': {
'Meta': {'object_name': 'VideoFeed'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'last_link': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']", 'null': 'True', 'blank': 'True'})
},
'videos.videometadata': {
'Meta': {'object_name': 'VideoMetadata'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'data': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.PositiveIntegerField', [], {}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'video': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.Video']"})
},
'videos.videourl': {
'Meta': {'object_name': 'VideoUrl'},
'added_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.CustomUser']", 'null': 'True', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'original': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'owner_username': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'primary': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
'url': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '255'}),
'video': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['videos.Video']"}),
'videoid': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'})
}
}
complete_apps = ['videos', 'teams']
|
agpl-3.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
3918,
9816,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
533,
12090,
8,
1451,
9816,
304,
2286,
347,
17465,
8,
277,
12,
9813,
304,
267,
298,
3534,
2195,
17465,
3102,
2348,
2122,
398,
367,
7352,
315,
9813,
459,
19048,
14,
13126,
7021,
2278,
1462,
14,
452,
837,
288,
862,
26,
355,
10679,
275,
9813,
459,
11418,
14,
3310,
2278,
1462,
14,
1541,
8,
5969,
29,
7574,
14,
5969,
12,
717,
922,
29,
7574,
14,
751,
12,
3653,
29,
7574,
2788,
16,
61,
288,
871,
7888,
26,
355,
327,
961,
6952,
11682,
7021,
4454,
2737,
4012,
314,
4628,
355,
870,
283,
18297,
11682,
7021,
3803,
450,
83,
7,
450,
7352,
14,
2051,
355,
1980,
953,
7352,
14,
3966,
275,
10679,
14,
3966,
288,
7352,
14,
2117,
342,
2286,
347,
8552,
8,
277,
12,
9813,
304,
267,
298,
3534,
2195,
8552,
3102,
2348,
2122,
267,
986,
2286,
1709,
275,
469,
267,
283,
2048,
20311,
14,
11470,
7522,
2048,
356,
469,
288,
283,
3396,
356,
791,
3235,
63,
6314,
356,
9510,
466,
297,
283,
2473,
9878,
283,
785,
63,
354,
356,
283,
28611,
25233,
6009,
2267,
288,
283,
2861,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
19605,
283,
988,
63,
1267,
356,
283,
2299,
297,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
6126,
63,
2732,
63,
1418,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
1604,
288,
283,
6126,
63,
6635,
63,
1418,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
1604,
288,
283,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
709,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
4229,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
31482,
297,
2513,
31525,
356,
788,
1178,
14,
1899,
14949,
288,
283,
29582,
817,
63,
18063,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
17,
1604,
288,
283,
65,
3079,
63,
3438,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
16,
1604,
288,
283,
17614,
9773,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
791,
2500,
356,
283,
549,
1604,
288,
283,
2425,
63,
2254,
63,
3431,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2861,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
19605,
283,
988,
63,
1267,
356,
283,
2766,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
25539,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
17363,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
374,
63,
3899,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2019,
63,
711,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
26969,
297,
990,
791,
988,
63,
1267,
356,
283,
1046,
297,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
6814,
63,
991,
63,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
6814,
63,
991,
63,
1188,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
3899,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
19048,
14,
24120,
6256,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
12538,
356,
661,
1208,
14,
15144,
14,
955,
14,
51,
19,
6589,
21910,
297,
990,
791,
16534,
63,
1419,
356,
298,
1445,
384,
3467,
356,
715,
12,
283,
15816,
356,
283,
7853,
936,
401,
283,
988,
63,
1267,
356,
283,
1960,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
17477,
63,
3671,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
975,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
11470,
63,
7522,
63,
8370,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
2407,
63,
354,
356,
3546,
3707,
4662,
283,
10247,
356,
283,
797,
297,
283,
475,
356,
298,
1025,
459,
2048,
20311,
14,
28611,
25233,
6009,
6097,
288,
283,
751,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1078,
63,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
11418,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
11418,
14,
9166,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178
] |
[
2644,
26,
2774,
13,
24,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
3918,
9816,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
533,
12090,
8,
1451,
9816,
304,
2286,
347,
17465,
8,
277,
12,
9813,
304,
267,
298,
3534,
2195,
17465,
3102,
2348,
2122,
398,
367,
7352,
315,
9813,
459,
19048,
14,
13126,
7021,
2278,
1462,
14,
452,
837,
288,
862,
26,
355,
10679,
275,
9813,
459,
11418,
14,
3310,
2278,
1462,
14,
1541,
8,
5969,
29,
7574,
14,
5969,
12,
717,
922,
29,
7574,
14,
751,
12,
3653,
29,
7574,
2788,
16,
61,
288,
871,
7888,
26,
355,
327,
961,
6952,
11682,
7021,
4454,
2737,
4012,
314,
4628,
355,
870,
283,
18297,
11682,
7021,
3803,
450,
83,
7,
450,
7352,
14,
2051,
355,
1980,
953,
7352,
14,
3966,
275,
10679,
14,
3966,
288,
7352,
14,
2117,
342,
2286,
347,
8552,
8,
277,
12,
9813,
304,
267,
298,
3534,
2195,
8552,
3102,
2348,
2122,
267,
986,
2286,
1709,
275,
469,
267,
283,
2048,
20311,
14,
11470,
7522,
2048,
356,
469,
288,
283,
3396,
356,
791,
3235,
63,
6314,
356,
9510,
466,
297,
283,
2473,
9878,
283,
785,
63,
354,
356,
283,
28611,
25233,
6009,
2267,
288,
283,
2861,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
19605,
283,
988,
63,
1267,
356,
283,
2299,
297,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
6126,
63,
2732,
63,
1418,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
1604,
288,
283,
6126,
63,
6635,
63,
1418,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
1604,
288,
283,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
709,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
4229,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
31482,
297,
2513,
31525,
356,
788,
1178,
14,
1899,
14949,
288,
283,
29582,
817,
63,
18063,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
17,
1604,
288,
283,
65,
3079,
63,
3438,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
16,
1604,
288,
283,
17614,
9773,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
791,
2500,
356,
283,
549,
1604,
288,
283,
2425,
63,
2254,
63,
3431,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2861,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
19605,
283,
988,
63,
1267,
356,
283,
2766,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
25539,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
17363,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
374,
63,
3899,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2019,
63,
711,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
26969,
297,
990,
791,
988,
63,
1267,
356,
283,
1046,
297,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
6814,
63,
991,
63,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
6814,
63,
991,
63,
1188,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
3899,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
19048,
14,
24120,
6256,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
12538,
356,
661,
1208,
14,
15144,
14,
955,
14,
51,
19,
6589,
21910,
297,
990,
791,
16534,
63,
1419,
356,
298,
1445,
384,
3467,
356,
715,
12,
283,
15816,
356,
283,
7853,
936,
401,
283,
988,
63,
1267,
356,
283,
1960,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
17477,
63,
3671,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
975,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
11470,
63,
7522,
63,
8370,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
2407,
63,
354,
356,
3546,
3707,
4662,
283,
10247,
356,
283,
797,
297,
283,
475,
356,
298,
1025,
459,
2048,
20311,
14,
28611,
25233,
6009,
6097,
288,
283,
751,
63,
4695,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6256,
283,
3235,
356,
283,
549,
297,
283,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1078,
63,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
11418,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
11418,
14,
9166,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bob-the-hamster/commandergenius
|
project/jni/python/src/Lib/test/test_iter.py
|
80
|
28003
|
# Test iterators.
import unittest
from test.test_support import run_unittest, TESTFN, unlink, have_unicode
# Test result of triple loop (too big to inline)
TRIPLETS = [(0, 0, 0), (0, 0, 1), (0, 0, 2),
(0, 1, 0), (0, 1, 1), (0, 1, 2),
(0, 2, 0), (0, 2, 1), (0, 2, 2),
(1, 0, 0), (1, 0, 1), (1, 0, 2),
(1, 1, 0), (1, 1, 1), (1, 1, 2),
(1, 2, 0), (1, 2, 1), (1, 2, 2),
(2, 0, 0), (2, 0, 1), (2, 0, 2),
(2, 1, 0), (2, 1, 1), (2, 1, 2),
(2, 2, 0), (2, 2, 1), (2, 2, 2)]
# Helper classes
class BasicIterClass:
def __init__(self, n):
self.n = n
self.i = 0
def next(self):
res = self.i
if res >= self.n:
raise StopIteration
self.i = res + 1
return res
class IteratingSequenceClass:
def __init__(self, n):
self.n = n
def __iter__(self):
return BasicIterClass(self.n)
class SequenceClass:
def __init__(self, n):
self.n = n
def __getitem__(self, i):
if 0 <= i < self.n:
return i
else:
raise IndexError
# Main test suite
class TestCase(unittest.TestCase):
# Helper to check that an iterator returns a given sequence
def check_iterator(self, it, seq):
res = []
while 1:
try:
val = it.next()
except StopIteration:
break
res.append(val)
self.assertEqual(res, seq)
# Helper to check that a for loop generates a given sequence
def check_for_loop(self, expr, seq):
res = []
for val in expr:
res.append(val)
self.assertEqual(res, seq)
# Test basic use of iter() function
def test_iter_basic(self):
self.check_iterator(iter(range(10)), range(10))
# Test that iter(iter(x)) is the same as iter(x)
def test_iter_idempotency(self):
seq = range(10)
it = iter(seq)
it2 = iter(it)
self.assert_(it is it2)
# Test that for loops over iterators work
def test_iter_for_loop(self):
self.check_for_loop(iter(range(10)), range(10))
# Test several independent iterators over the same list
def test_iter_independence(self):
seq = range(3)
res = []
for i in iter(seq):
for j in iter(seq):
for k in iter(seq):
res.append((i, j, k))
self.assertEqual(res, TRIPLETS)
# Test triple list comprehension using iterators
def test_nested_comprehensions_iter(self):
seq = range(3)
res = [(i, j, k)
for i in iter(seq) for j in iter(seq) for k in iter(seq)]
self.assertEqual(res, TRIPLETS)
# Test triple list comprehension without iterators
def test_nested_comprehensions_for(self):
seq = range(3)
res = [(i, j, k) for i in seq for j in seq for k in seq]
self.assertEqual(res, TRIPLETS)
# Test a class with __iter__ in a for loop
def test_iter_class_for(self):
self.check_for_loop(IteratingSequenceClass(10), range(10))
# Test a class with __iter__ with explicit iter()
def test_iter_class_iter(self):
self.check_iterator(iter(IteratingSequenceClass(10)), range(10))
# Test for loop on a sequence class without __iter__
def test_seq_class_for(self):
self.check_for_loop(SequenceClass(10), range(10))
# Test iter() on a sequence class without __iter__
def test_seq_class_iter(self):
self.check_iterator(iter(SequenceClass(10)), range(10))
# Test two-argument iter() with callable instance
def test_iter_callable(self):
class C:
def __init__(self):
self.i = 0
def __call__(self):
i = self.i
self.i = i + 1
if i > 100:
raise IndexError # Emergency stop
return i
self.check_iterator(iter(C(), 10), range(10))
# Test two-argument iter() with function
def test_iter_function(self):
def spam(state=[0]):
i = state[0]
state[0] = i+1
return i
self.check_iterator(iter(spam, 10), range(10))
# Test two-argument iter() with function that raises StopIteration
def test_iter_function_stop(self):
def spam(state=[0]):
i = state[0]
if i == 10:
raise StopIteration
state[0] = i+1
return i
self.check_iterator(iter(spam, 20), range(10))
# Test exception propagation through function iterator
def test_exception_function(self):
def spam(state=[0]):
i = state[0]
state[0] = i+1
if i == 10:
raise RuntimeError
return i
res = []
try:
for x in iter(spam, 20):
res.append(x)
except RuntimeError:
self.assertEqual(res, range(10))
else:
self.fail("should have raised RuntimeError")
# Test exception propagation through sequence iterator
def test_exception_sequence(self):
class MySequenceClass(SequenceClass):
def __getitem__(self, i):
if i == 10:
raise RuntimeError
return SequenceClass.__getitem__(self, i)
res = []
try:
for x in MySequenceClass(20):
res.append(x)
except RuntimeError:
self.assertEqual(res, range(10))
else:
self.fail("should have raised RuntimeError")
# Test for StopIteration from __getitem__
def test_stop_sequence(self):
class MySequenceClass(SequenceClass):
def __getitem__(self, i):
if i == 10:
raise StopIteration
return SequenceClass.__getitem__(self, i)
self.check_for_loop(MySequenceClass(20), range(10))
# Test a big range
def test_iter_big_range(self):
self.check_for_loop(iter(range(10000)), range(10000))
# Test an empty list
def test_iter_empty(self):
self.check_for_loop(iter([]), [])
# Test a tuple
def test_iter_tuple(self):
self.check_for_loop(iter((0,1,2,3,4,5,6,7,8,9)), range(10))
# Test an xrange
def test_iter_xrange(self):
self.check_for_loop(iter(xrange(10)), range(10))
# Test a string
def test_iter_string(self):
self.check_for_loop(iter("abcde"), ["a", "b", "c", "d", "e"])
# Test a Unicode string
if have_unicode:
def test_iter_unicode(self):
self.check_for_loop(iter(unicode("abcde")),
[unicode("a"), unicode("b"), unicode("c"),
unicode("d"), unicode("e")])
# Test a directory
def test_iter_dict(self):
dict = {}
for i in range(10):
dict[i] = None
self.check_for_loop(dict, dict.keys())
# Test a file
def test_iter_file(self):
f = open(TESTFN, "w")
try:
for i in range(5):
f.write("%d\n" % i)
finally:
f.close()
f = open(TESTFN, "r")
try:
self.check_for_loop(f, ["0\n", "1\n", "2\n", "3\n", "4\n"])
self.check_for_loop(f, [])
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
# Test list()'s use of iterators.
def test_builtin_list(self):
self.assertEqual(list(SequenceClass(5)), range(5))
self.assertEqual(list(SequenceClass(0)), [])
self.assertEqual(list(()), [])
self.assertEqual(list(range(10, -1, -1)), range(10, -1, -1))
d = {"one": 1, "two": 2, "three": 3}
self.assertEqual(list(d), d.keys())
self.assertRaises(TypeError, list, list)
self.assertRaises(TypeError, list, 42)
f = open(TESTFN, "w")
try:
for i in range(5):
f.write("%d\n" % i)
finally:
f.close()
f = open(TESTFN, "r")
try:
self.assertEqual(list(f), ["0\n", "1\n", "2\n", "3\n", "4\n"])
f.seek(0, 0)
self.assertEqual(list(f),
["0\n", "1\n", "2\n", "3\n", "4\n"])
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
# Test tuples()'s use of iterators.
def test_builtin_tuple(self):
self.assertEqual(tuple(SequenceClass(5)), (0, 1, 2, 3, 4))
self.assertEqual(tuple(SequenceClass(0)), ())
self.assertEqual(tuple([]), ())
self.assertEqual(tuple(()), ())
self.assertEqual(tuple("abc"), ("a", "b", "c"))
d = {"one": 1, "two": 2, "three": 3}
self.assertEqual(tuple(d), tuple(d.keys()))
self.assertRaises(TypeError, tuple, list)
self.assertRaises(TypeError, tuple, 42)
f = open(TESTFN, "w")
try:
for i in range(5):
f.write("%d\n" % i)
finally:
f.close()
f = open(TESTFN, "r")
try:
self.assertEqual(tuple(f), ("0\n", "1\n", "2\n", "3\n", "4\n"))
f.seek(0, 0)
self.assertEqual(tuple(f),
("0\n", "1\n", "2\n", "3\n", "4\n"))
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
# Test filter()'s use of iterators.
def test_builtin_filter(self):
self.assertEqual(filter(None, SequenceClass(5)), range(1, 5))
self.assertEqual(filter(None, SequenceClass(0)), [])
self.assertEqual(filter(None, ()), ())
self.assertEqual(filter(None, "abc"), "abc")
d = {"one": 1, "two": 2, "three": 3}
self.assertEqual(filter(None, d), d.keys())
self.assertRaises(TypeError, filter, None, list)
self.assertRaises(TypeError, filter, None, 42)
class Boolean:
def __init__(self, truth):
self.truth = truth
def __nonzero__(self):
return self.truth
bTrue = Boolean(1)
bFalse = Boolean(0)
class Seq:
def __init__(self, *args):
self.vals = args
def __iter__(self):
class SeqIter:
def __init__(self, vals):
self.vals = vals
self.i = 0
def __iter__(self):
return self
def next(self):
i = self.i
self.i = i + 1
if i < len(self.vals):
return self.vals[i]
else:
raise StopIteration
return SeqIter(self.vals)
seq = Seq(*([bTrue, bFalse] * 25))
self.assertEqual(filter(lambda x: not x, seq), [bFalse]*25)
self.assertEqual(filter(lambda x: not x, iter(seq)), [bFalse]*25)
# Test max() and min()'s use of iterators.
def test_builtin_max_min(self):
self.assertEqual(max(SequenceClass(5)), 4)
self.assertEqual(min(SequenceClass(5)), 0)
self.assertEqual(max(8, -1), 8)
self.assertEqual(min(8, -1), -1)
d = {"one": 1, "two": 2, "three": 3}
self.assertEqual(max(d), "two")
self.assertEqual(min(d), "one")
self.assertEqual(max(d.itervalues()), 3)
self.assertEqual(min(iter(d.itervalues())), 1)
f = open(TESTFN, "w")
try:
f.write("medium line\n")
f.write("xtra large line\n")
f.write("itty-bitty line\n")
finally:
f.close()
f = open(TESTFN, "r")
try:
self.assertEqual(min(f), "itty-bitty line\n")
f.seek(0, 0)
self.assertEqual(max(f), "xtra large line\n")
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
# Test map()'s use of iterators.
def test_builtin_map(self):
self.assertEqual(map(None, SequenceClass(5)), range(5))
self.assertEqual(map(lambda x: x+1, SequenceClass(5)), range(1, 6))
d = {"one": 1, "two": 2, "three": 3}
self.assertEqual(map(None, d), d.keys())
self.assertEqual(map(lambda k, d=d: (k, d[k]), d), d.items())
dkeys = d.keys()
expected = [(i < len(d) and dkeys[i] or None,
i,
i < len(d) and dkeys[i] or None)
for i in range(5)]
self.assertEqual(map(None, d,
SequenceClass(5),
iter(d.iterkeys())),
expected)
f = open(TESTFN, "w")
try:
for i in range(10):
f.write("xy" * i + "\n") # line i has len 2*i+1
finally:
f.close()
f = open(TESTFN, "r")
try:
self.assertEqual(map(len, f), range(1, 21, 2))
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
# Test zip()'s use of iterators.
def test_builtin_zip(self):
self.assertEqual(zip(), [])
self.assertEqual(zip(*[]), [])
self.assertEqual(zip(*[(1, 2), 'ab']), [(1, 'a'), (2, 'b')])
self.assertRaises(TypeError, zip, None)
self.assertRaises(TypeError, zip, range(10), 42)
self.assertRaises(TypeError, zip, range(10), zip)
self.assertEqual(zip(IteratingSequenceClass(3)),
[(0,), (1,), (2,)])
self.assertEqual(zip(SequenceClass(3)),
[(0,), (1,), (2,)])
d = {"one": 1, "two": 2, "three": 3}
self.assertEqual(d.items(), zip(d, d.itervalues()))
# Generate all ints starting at constructor arg.
class IntsFrom:
def __init__(self, start):
self.i = start
def __iter__(self):
return self
def next(self):
i = self.i
self.i = i+1
return i
f = open(TESTFN, "w")
try:
f.write("a\n" "bbb\n" "cc\n")
finally:
f.close()
f = open(TESTFN, "r")
try:
self.assertEqual(zip(IntsFrom(0), f, IntsFrom(-100)),
[(0, "a\n", -100),
(1, "bbb\n", -99),
(2, "cc\n", -98)])
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
self.assertEqual(zip(xrange(5)), [(i,) for i in range(5)])
# Classes that lie about their lengths.
class NoGuessLen5:
def __getitem__(self, i):
if i >= 5:
raise IndexError
return i
class Guess3Len5(NoGuessLen5):
def __len__(self):
return 3
class Guess30Len5(NoGuessLen5):
def __len__(self):
return 30
self.assertEqual(len(Guess3Len5()), 3)
self.assertEqual(len(Guess30Len5()), 30)
self.assertEqual(zip(NoGuessLen5()), zip(range(5)))
self.assertEqual(zip(Guess3Len5()), zip(range(5)))
self.assertEqual(zip(Guess30Len5()), zip(range(5)))
expected = [(i, i) for i in range(5)]
for x in NoGuessLen5(), Guess3Len5(), Guess30Len5():
for y in NoGuessLen5(), Guess3Len5(), Guess30Len5():
self.assertEqual(zip(x, y), expected)
# Test reduces()'s use of iterators.
def test_builtin_reduce(self):
from operator import add
self.assertEqual(reduce(add, SequenceClass(5)), 10)
self.assertEqual(reduce(add, SequenceClass(5), 42), 52)
self.assertRaises(TypeError, reduce, add, SequenceClass(0))
self.assertEqual(reduce(add, SequenceClass(0), 42), 42)
self.assertEqual(reduce(add, SequenceClass(1)), 0)
self.assertEqual(reduce(add, SequenceClass(1), 42), 42)
d = {"one": 1, "two": 2, "three": 3}
self.assertEqual(reduce(add, d), "".join(d.keys()))
# This test case will be removed if we don't have Unicode
def test_unicode_join_endcase(self):
# This class inserts a Unicode object into its argument's natural
# iteration, in the 3rd position.
class OhPhooey:
def __init__(self, seq):
self.it = iter(seq)
self.i = 0
def __iter__(self):
return self
def next(self):
i = self.i
self.i = i+1
if i == 2:
return unicode("fooled you!")
return self.it.next()
f = open(TESTFN, "w")
try:
f.write("a\n" + "b\n" + "c\n")
finally:
f.close()
f = open(TESTFN, "r")
# Nasty: string.join(s) can't know whether unicode.join() is needed
# until it's seen all of s's elements. But in this case, f's
# iterator cannot be restarted. So what we're testing here is
# whether string.join() can manage to remember everything it's seen
# and pass that on to unicode.join().
try:
got = " - ".join(OhPhooey(f))
self.assertEqual(got, unicode("a\n - b\n - fooled you! - c\n"))
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
if not have_unicode:
def test_unicode_join_endcase(self): pass
# Test iterators with 'x in y' and 'x not in y'.
def test_in_and_not_in(self):
for sc5 in IteratingSequenceClass(5), SequenceClass(5):
for i in range(5):
self.assert_(i in sc5)
for i in "abc", -1, 5, 42.42, (3, 4), [], {1: 1}, 3-12j, sc5:
self.assert_(i not in sc5)
self.assertRaises(TypeError, lambda: 3 in 12)
self.assertRaises(TypeError, lambda: 3 not in map)
d = {"one": 1, "two": 2, "three": 3, 1j: 2j}
for k in d:
self.assert_(k in d)
self.assert_(k not in d.itervalues())
for v in d.values():
self.assert_(v in d.itervalues())
self.assert_(v not in d)
for k, v in d.iteritems():
self.assert_((k, v) in d.iteritems())
self.assert_((v, k) not in d.iteritems())
f = open(TESTFN, "w")
try:
f.write("a\n" "b\n" "c\n")
finally:
f.close()
f = open(TESTFN, "r")
try:
for chunk in "abc":
f.seek(0, 0)
self.assert_(chunk not in f)
f.seek(0, 0)
self.assert_((chunk + "\n") in f)
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
# Test iterators with operator.countOf (PySequence_Count).
def test_countOf(self):
from operator import countOf
self.assertEqual(countOf([1,2,2,3,2,5], 2), 3)
self.assertEqual(countOf((1,2,2,3,2,5), 2), 3)
self.assertEqual(countOf("122325", "2"), 3)
self.assertEqual(countOf("122325", "6"), 0)
self.assertRaises(TypeError, countOf, 42, 1)
self.assertRaises(TypeError, countOf, countOf, countOf)
d = {"one": 3, "two": 3, "three": 3, 1j: 2j}
for k in d:
self.assertEqual(countOf(d, k), 1)
self.assertEqual(countOf(d.itervalues(), 3), 3)
self.assertEqual(countOf(d.itervalues(), 2j), 1)
self.assertEqual(countOf(d.itervalues(), 1j), 0)
f = open(TESTFN, "w")
try:
f.write("a\n" "b\n" "c\n" "b\n")
finally:
f.close()
f = open(TESTFN, "r")
try:
for letter, count in ("a", 1), ("b", 2), ("c", 1), ("d", 0):
f.seek(0, 0)
self.assertEqual(countOf(f, letter + "\n"), count)
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
# Test iterators with operator.indexOf (PySequence_Index).
def test_indexOf(self):
from operator import indexOf
self.assertEqual(indexOf([1,2,2,3,2,5], 1), 0)
self.assertEqual(indexOf((1,2,2,3,2,5), 2), 1)
self.assertEqual(indexOf((1,2,2,3,2,5), 3), 3)
self.assertEqual(indexOf((1,2,2,3,2,5), 5), 5)
self.assertRaises(ValueError, indexOf, (1,2,2,3,2,5), 0)
self.assertRaises(ValueError, indexOf, (1,2,2,3,2,5), 6)
self.assertEqual(indexOf("122325", "2"), 1)
self.assertEqual(indexOf("122325", "5"), 5)
self.assertRaises(ValueError, indexOf, "122325", "6")
self.assertRaises(TypeError, indexOf, 42, 1)
self.assertRaises(TypeError, indexOf, indexOf, indexOf)
f = open(TESTFN, "w")
try:
f.write("a\n" "b\n" "c\n" "d\n" "e\n")
finally:
f.close()
f = open(TESTFN, "r")
try:
fiter = iter(f)
self.assertEqual(indexOf(fiter, "b\n"), 1)
self.assertEqual(indexOf(fiter, "d\n"), 1)
self.assertEqual(indexOf(fiter, "e\n"), 0)
self.assertRaises(ValueError, indexOf, fiter, "a\n")
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
iclass = IteratingSequenceClass(3)
for i in range(3):
self.assertEqual(indexOf(iclass, i), i)
self.assertRaises(ValueError, indexOf, iclass, -1)
# Test iterators with file.writelines().
def test_writelines(self):
f = file(TESTFN, "w")
try:
self.assertRaises(TypeError, f.writelines, None)
self.assertRaises(TypeError, f.writelines, 42)
f.writelines(["1\n", "2\n"])
f.writelines(("3\n", "4\n"))
f.writelines({'5\n': None})
f.writelines({})
# Try a big chunk too.
class Iterator:
def __init__(self, start, finish):
self.start = start
self.finish = finish
self.i = self.start
def next(self):
if self.i >= self.finish:
raise StopIteration
result = str(self.i) + '\n'
self.i += 1
return result
def __iter__(self):
return self
class Whatever:
def __init__(self, start, finish):
self.start = start
self.finish = finish
def __iter__(self):
return Iterator(self.start, self.finish)
f.writelines(Whatever(6, 6+2000))
f.close()
f = file(TESTFN)
expected = [str(i) + "\n" for i in range(1, 2006)]
self.assertEqual(list(f), expected)
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
# Test iterators on RHS of unpacking assignments.
def test_unpack_iter(self):
a, b = 1, 2
self.assertEqual((a, b), (1, 2))
a, b, c = IteratingSequenceClass(3)
self.assertEqual((a, b, c), (0, 1, 2))
try: # too many values
a, b = IteratingSequenceClass(3)
except ValueError:
pass
else:
self.fail("should have raised ValueError")
try: # not enough values
a, b, c = IteratingSequenceClass(2)
except ValueError:
pass
else:
self.fail("should have raised ValueError")
try: # not iterable
a, b, c = len
except TypeError:
pass
else:
self.fail("should have raised TypeError")
a, b, c = {1: 42, 2: 42, 3: 42}.itervalues()
self.assertEqual((a, b, c), (42, 42, 42))
f = open(TESTFN, "w")
lines = ("a\n", "bb\n", "ccc\n")
try:
for line in lines:
f.write(line)
finally:
f.close()
f = open(TESTFN, "r")
try:
a, b, c = f
self.assertEqual((a, b, c), lines)
finally:
f.close()
try:
unlink(TESTFN)
except OSError:
pass
(a, b), (c,) = IteratingSequenceClass(2), {42: 24}
self.assertEqual((a, b, c), (0, 1, 42))
# Test reference count behavior
class C(object):
count = 0
def __new__(cls):
cls.count += 1
return object.__new__(cls)
def __del__(self):
cls = self.__class__
assert cls.count > 0
cls.count -= 1
x = C()
self.assertEqual(C.count, 1)
del x
self.assertEqual(C.count, 0)
l = [C(), C(), C()]
self.assertEqual(C.count, 3)
try:
a, b = iter(l)
except ValueError:
pass
del l
self.assertEqual(C.count, 0)
# Make sure StopIteration is a "sink state".
# This tests various things that weren't sink states in Python 2.2.1,
# plus various things that always were fine.
def test_sinkstate_list(self):
# This used to fail
a = range(5)
b = iter(a)
self.assertEqual(list(b), range(5))
a.extend(range(5, 10))
self.assertEqual(list(b), [])
def test_sinkstate_tuple(self):
a = (0, 1, 2, 3, 4)
b = iter(a)
self.assertEqual(list(b), range(5))
self.assertEqual(list(b), [])
def test_sinkstate_string(self):
a = "abcde"
b = iter(a)
self.assertEqual(list(b), ['a', 'b', 'c', 'd', 'e'])
self.assertEqual(list(b), [])
def test_sinkstate_sequence(self):
# This used to fail
a = SequenceClass(5)
b = iter(a)
self.assertEqual(list(b), range(5))
a.n = 10
self.assertEqual(list(b), [])
def test_sinkstate_callable(self):
# This used to fail
def spam(state=[0]):
i = state[0]
state[0] = i+1
if i == 10:
raise AssertionError, "shouldn't have gotten this far"
return i
b = iter(spam, 5)
self.assertEqual(list(b), range(5))
self.assertEqual(list(b), [])
def test_sinkstate_dict(self):
# XXX For a more thorough test, see towards the end of:
# http://mail.python.org/pipermail/python-dev/2002-July/026512.html
a = {1:1, 2:2, 0:0, 4:4, 3:3}
for b in iter(a), a.iterkeys(), a.iteritems(), a.itervalues():
b = iter(a)
self.assertEqual(len(list(b)), 5)
self.assertEqual(list(b), [])
def test_sinkstate_yield(self):
def gen():
for i in range(5):
yield i
b = gen()
self.assertEqual(list(b), range(5))
self.assertEqual(list(b), [])
def test_sinkstate_range(self):
a = xrange(5)
b = iter(a)
self.assertEqual(list(b), range(5))
self.assertEqual(list(b), [])
def test_sinkstate_enumerate(self):
a = range(5)
e = enumerate(a)
b = iter(e)
self.assertEqual(list(b), zip(range(5), range(5)))
self.assertEqual(list(b), [])
def test_main():
run_unittest(TestCase)
if __name__ == "__main__":
test_main()
|
lgpl-2.1
|
[
3,
1379,
28241,
14,
199,
199,
646,
2882,
199,
504,
511,
14,
396,
63,
4058,
492,
1255,
63,
2796,
12,
25788,
12,
17002,
12,
1172,
63,
2975,
199,
199,
3,
1379,
754,
402,
19671,
4438,
334,
7354,
7282,
370,
8308,
9,
199,
1766,
1772,
44,
30416,
275,
3842,
16,
12,
378,
12,
378,
395,
334,
16,
12,
378,
12,
413,
395,
334,
16,
12,
378,
12,
499,
395,
288,
334,
16,
12,
413,
12,
378,
395,
334,
16,
12,
413,
12,
413,
395,
334,
16,
12,
413,
12,
499,
395,
288,
334,
16,
12,
499,
12,
378,
395,
334,
16,
12,
499,
12,
413,
395,
334,
16,
12,
499,
12,
499,
395,
953,
334,
17,
12,
378,
12,
378,
395,
334,
17,
12,
378,
12,
413,
395,
334,
17,
12,
378,
12,
499,
395,
288,
334,
17,
12,
413,
12,
378,
395,
334,
17,
12,
413,
12,
413,
395,
334,
17,
12,
413,
12,
499,
395,
288,
334,
17,
12,
499,
12,
378,
395,
334,
17,
12,
499,
12,
413,
395,
334,
17,
12,
499,
12,
499,
395,
953,
334,
18,
12,
378,
12,
378,
395,
334,
18,
12,
378,
12,
413,
395,
334,
18,
12,
378,
12,
499,
395,
288,
334,
18,
12,
413,
12,
378,
395,
334,
18,
12,
413,
12,
413,
395,
334,
18,
12,
413,
12,
499,
395,
288,
334,
18,
12,
499,
12,
378,
395,
334,
18,
12,
499,
12,
413,
395,
334,
18,
12,
499,
12,
499,
1874,
199,
199,
3,
11642,
3992,
199,
199,
533,
10082,
3315,
2543,
26,
272,
347,
636,
826,
721,
277,
12,
302,
304,
267,
291,
14,
78,
275,
302,
267,
291,
14,
73,
275,
378,
272,
347,
2163,
8,
277,
304,
267,
522,
275,
291,
14,
73,
267,
340,
522,
2356,
291,
14,
78,
26,
288,
746,
10852,
267,
291,
14,
73,
275,
522,
435,
413,
267,
372,
522,
199,
199,
533,
11953,
1958,
5826,
2543,
26,
272,
347,
636,
826,
721,
277,
12,
302,
304,
267,
291,
14,
78,
275,
302,
272,
347,
636,
1661,
721,
277,
304,
267,
372,
10082,
3315,
2543,
8,
277,
14,
78,
9,
199,
199,
533,
10975,
2543,
26,
272,
347,
636,
826,
721,
277,
12,
302,
304,
267,
291,
14,
78,
275,
302,
272,
347,
636,
6095,
721,
277,
12,
284,
304,
267,
340,
378,
2695,
284,
665,
291,
14,
78,
26,
288,
372,
284,
267,
587,
26,
288,
746,
7888,
199,
199,
3,
11298,
511,
5241,
199,
199,
533,
7640,
8,
2796,
14,
1746,
304,
339,
327,
11642,
370,
1104,
626,
376,
6122,
2529,
282,
1627,
3414,
272,
347,
1104,
63,
5778,
8,
277,
12,
652,
12,
5412,
304,
267,
522,
275,
942,
267,
1830,
413,
26,
288,
862,
26,
355,
1139,
275,
652,
14,
2184,
342,
288,
871,
10852,
26,
355,
2059,
288,
522,
14,
740,
8,
637,
9,
267,
291,
14,
629,
8,
470,
12,
5412,
9,
339,
327,
11642,
370,
1104,
626,
282,
367,
4438,
12821,
282,
1627,
3414,
272,
347,
1104,
63,
509,
63,
3813,
8,
277,
12,
5348,
12,
5412,
304,
267,
522,
275,
942,
267,
367,
1139,
315,
5348,
26,
288,
522,
14,
740,
8,
637,
9,
267,
291,
14,
629,
8,
470,
12,
5412,
9,
339,
327,
1379,
5678,
675,
402,
2740,
342,
805,
272,
347,
511,
63,
1661,
63,
4316,
8,
277,
304,
267,
291,
14,
1074,
63,
5778,
8,
1661,
8,
1842,
8,
709,
1826,
1425,
8,
709,
430,
339,
327,
1379,
626,
2740,
8,
1661,
8,
88,
430,
365,
314,
2011,
465,
2740,
8,
88,
9,
272,
347,
511,
63,
1661,
63,
2655,
9613,
9447,
8,
277,
304,
267,
5412,
275,
1425,
8,
709,
9,
267,
652,
275,
2740,
8,
3610,
9,
267,
652,
18,
275,
2740,
8,
390,
9,
267,
291,
14,
479,
2531,
390,
365,
652,
18,
9,
339,
327,
1379,
626,
367,
17222,
1806,
28241,
1736,
272,
347,
511,
63,
1661,
63,
509,
63,
3813,
8,
277,
304,
267,
291,
14,
1074,
63,
509,
63,
3813,
8,
1661,
8,
1842,
8,
709,
1826,
1425,
8,
709,
430,
339,
327,
1379,
9978,
12717,
28241,
1806,
314,
2011,
769,
272,
347,
511,
63,
1661,
63,
262,
271,
29578,
8,
277,
304,
267,
5412,
275,
1425,
8,
19,
9,
267,
522,
275,
942,
267,
367,
284,
315,
2740,
8,
3610,
304,
288,
367,
1335,
315,
2740,
8,
3610,
304,
355,
367,
1022,
315,
2740,
8,
3610,
304,
490,
522,
14,
740,
1332,
73,
12,
1335,
12,
1022,
430,
267,
291,
14,
629,
8,
470,
12,
9074,
1772,
44,
30416,
9,
339,
327,
1379,
19671,
769,
1013,
31379,
1808,
28241,
272,
347,
511,
63,
6376,
63,
863,
22868,
1356,
63,
1661,
8,
277,
304,
267,
5412,
275,
1425,
8,
19,
9,
267,
522,
275,
3842,
73,
12,
1335,
12,
1022,
9,
2049,
367,
284,
315,
2740,
8,
3610,
9,
367,
1335,
315,
2740,
8,
3610,
9,
367,
1022,
315,
2740,
8,
3610,
1874,
267,
291,
14,
629,
8,
470,
12,
9074,
1772,
44,
30416,
9,
339,
327,
1379,
19671,
769,
1013,
31379,
1928,
28241,
272,
347,
511,
63,
6376,
63,
863,
22868,
1356,
63,
509,
8,
277,
304,
267,
5412,
275,
1425,
8,
19,
9,
267,
522,
275,
3842,
73,
12,
1335,
12,
1022,
9,
367,
284,
315,
5412,
367,
1335,
315,
5412,
367,
1022,
315,
5412,
61,
267,
291,
14,
629,
8,
470,
12,
9074,
1772,
44,
30416,
9,
339,
327,
1379,
282,
1021,
543,
636,
1661,
363,
315,
282,
367,
4438,
272,
347,
511,
63,
1661,
63,
533,
63,
509,
8,
277,
304,
267,
291,
14,
1074,
63,
509,
63,
3813,
8,
3315,
1958,
5826,
2543,
8,
709,
395,
1425,
8,
709,
430,
339,
327,
1379,
282,
1021,
543,
636,
1661,
363,
543,
5027,
2740,
342,
272,
347,
511,
63,
1661,
63,
533,
63,
1661,
8,
277,
304,
267,
291,
14,
1074,
63,
5778,
8,
1661,
8,
3315,
1958,
5826,
2543,
8,
709,
1826,
1425,
8,
709,
430,
339,
327,
1379,
367,
4438,
641,
282,
3414,
1021,
1928,
636,
1661,
363,
272,
347,
511,
63,
3610,
63,
533,
63,
509,
8,
277,
304,
267,
291,
14,
1074,
63,
509,
63,
3813,
8,
5826,
2543,
8,
709,
395,
1425,
8,
709,
430,
339,
327
] |
[
1379,
28241,
14,
199,
199,
646,
2882,
199,
504,
511,
14,
396,
63,
4058,
492,
1255,
63,
2796,
12,
25788,
12,
17002,
12,
1172,
63,
2975,
199,
199,
3,
1379,
754,
402,
19671,
4438,
334,
7354,
7282,
370,
8308,
9,
199,
1766,
1772,
44,
30416,
275,
3842,
16,
12,
378,
12,
378,
395,
334,
16,
12,
378,
12,
413,
395,
334,
16,
12,
378,
12,
499,
395,
288,
334,
16,
12,
413,
12,
378,
395,
334,
16,
12,
413,
12,
413,
395,
334,
16,
12,
413,
12,
499,
395,
288,
334,
16,
12,
499,
12,
378,
395,
334,
16,
12,
499,
12,
413,
395,
334,
16,
12,
499,
12,
499,
395,
953,
334,
17,
12,
378,
12,
378,
395,
334,
17,
12,
378,
12,
413,
395,
334,
17,
12,
378,
12,
499,
395,
288,
334,
17,
12,
413,
12,
378,
395,
334,
17,
12,
413,
12,
413,
395,
334,
17,
12,
413,
12,
499,
395,
288,
334,
17,
12,
499,
12,
378,
395,
334,
17,
12,
499,
12,
413,
395,
334,
17,
12,
499,
12,
499,
395,
953,
334,
18,
12,
378,
12,
378,
395,
334,
18,
12,
378,
12,
413,
395,
334,
18,
12,
378,
12,
499,
395,
288,
334,
18,
12,
413,
12,
378,
395,
334,
18,
12,
413,
12,
413,
395,
334,
18,
12,
413,
12,
499,
395,
288,
334,
18,
12,
499,
12,
378,
395,
334,
18,
12,
499,
12,
413,
395,
334,
18,
12,
499,
12,
499,
1874,
199,
199,
3,
11642,
3992,
199,
199,
533,
10082,
3315,
2543,
26,
272,
347,
636,
826,
721,
277,
12,
302,
304,
267,
291,
14,
78,
275,
302,
267,
291,
14,
73,
275,
378,
272,
347,
2163,
8,
277,
304,
267,
522,
275,
291,
14,
73,
267,
340,
522,
2356,
291,
14,
78,
26,
288,
746,
10852,
267,
291,
14,
73,
275,
522,
435,
413,
267,
372,
522,
199,
199,
533,
11953,
1958,
5826,
2543,
26,
272,
347,
636,
826,
721,
277,
12,
302,
304,
267,
291,
14,
78,
275,
302,
272,
347,
636,
1661,
721,
277,
304,
267,
372,
10082,
3315,
2543,
8,
277,
14,
78,
9,
199,
199,
533,
10975,
2543,
26,
272,
347,
636,
826,
721,
277,
12,
302,
304,
267,
291,
14,
78,
275,
302,
272,
347,
636,
6095,
721,
277,
12,
284,
304,
267,
340,
378,
2695,
284,
665,
291,
14,
78,
26,
288,
372,
284,
267,
587,
26,
288,
746,
7888,
199,
199,
3,
11298,
511,
5241,
199,
199,
533,
7640,
8,
2796,
14,
1746,
304,
339,
327,
11642,
370,
1104,
626,
376,
6122,
2529,
282,
1627,
3414,
272,
347,
1104,
63,
5778,
8,
277,
12,
652,
12,
5412,
304,
267,
522,
275,
942,
267,
1830,
413,
26,
288,
862,
26,
355,
1139,
275,
652,
14,
2184,
342,
288,
871,
10852,
26,
355,
2059,
288,
522,
14,
740,
8,
637,
9,
267,
291,
14,
629,
8,
470,
12,
5412,
9,
339,
327,
11642,
370,
1104,
626,
282,
367,
4438,
12821,
282,
1627,
3414,
272,
347,
1104,
63,
509,
63,
3813,
8,
277,
12,
5348,
12,
5412,
304,
267,
522,
275,
942,
267,
367,
1139,
315,
5348,
26,
288,
522,
14,
740,
8,
637,
9,
267,
291,
14,
629,
8,
470,
12,
5412,
9,
339,
327,
1379,
5678,
675,
402,
2740,
342,
805,
272,
347,
511,
63,
1661,
63,
4316,
8,
277,
304,
267,
291,
14,
1074,
63,
5778,
8,
1661,
8,
1842,
8,
709,
1826,
1425,
8,
709,
430,
339,
327,
1379,
626,
2740,
8,
1661,
8,
88,
430,
365,
314,
2011,
465,
2740,
8,
88,
9,
272,
347,
511,
63,
1661,
63,
2655,
9613,
9447,
8,
277,
304,
267,
5412,
275,
1425,
8,
709,
9,
267,
652,
275,
2740,
8,
3610,
9,
267,
652,
18,
275,
2740,
8,
390,
9,
267,
291,
14,
479,
2531,
390,
365,
652,
18,
9,
339,
327,
1379,
626,
367,
17222,
1806,
28241,
1736,
272,
347,
511,
63,
1661,
63,
509,
63,
3813,
8,
277,
304,
267,
291,
14,
1074,
63,
509,
63,
3813,
8,
1661,
8,
1842,
8,
709,
1826,
1425,
8,
709,
430,
339,
327,
1379,
9978,
12717,
28241,
1806,
314,
2011,
769,
272,
347,
511,
63,
1661,
63,
262,
271,
29578,
8,
277,
304,
267,
5412,
275,
1425,
8,
19,
9,
267,
522,
275,
942,
267,
367,
284,
315,
2740,
8,
3610,
304,
288,
367,
1335,
315,
2740,
8,
3610,
304,
355,
367,
1022,
315,
2740,
8,
3610,
304,
490,
522,
14,
740,
1332,
73,
12,
1335,
12,
1022,
430,
267,
291,
14,
629,
8,
470,
12,
9074,
1772,
44,
30416,
9,
339,
327,
1379,
19671,
769,
1013,
31379,
1808,
28241,
272,
347,
511,
63,
6376,
63,
863,
22868,
1356,
63,
1661,
8,
277,
304,
267,
5412,
275,
1425,
8,
19,
9,
267,
522,
275,
3842,
73,
12,
1335,
12,
1022,
9,
2049,
367,
284,
315,
2740,
8,
3610,
9,
367,
1335,
315,
2740,
8,
3610,
9,
367,
1022,
315,
2740,
8,
3610,
1874,
267,
291,
14,
629,
8,
470,
12,
9074,
1772,
44,
30416,
9,
339,
327,
1379,
19671,
769,
1013,
31379,
1928,
28241,
272,
347,
511,
63,
6376,
63,
863,
22868,
1356,
63,
509,
8,
277,
304,
267,
5412,
275,
1425,
8,
19,
9,
267,
522,
275,
3842,
73,
12,
1335,
12,
1022,
9,
367,
284,
315,
5412,
367,
1335,
315,
5412,
367,
1022,
315,
5412,
61,
267,
291,
14,
629,
8,
470,
12,
9074,
1772,
44,
30416,
9,
339,
327,
1379,
282,
1021,
543,
636,
1661,
363,
315,
282,
367,
4438,
272,
347,
511,
63,
1661,
63,
533,
63,
509,
8,
277,
304,
267,
291,
14,
1074,
63,
509,
63,
3813,
8,
3315,
1958,
5826,
2543,
8,
709,
395,
1425,
8,
709,
430,
339,
327,
1379,
282,
1021,
543,
636,
1661,
363,
543,
5027,
2740,
342,
272,
347,
511,
63,
1661,
63,
533,
63,
1661,
8,
277,
304,
267,
291,
14,
1074,
63,
5778,
8,
1661,
8,
3315,
1958,
5826,
2543,
8,
709,
1826,
1425,
8,
709,
430,
339,
327,
1379,
367,
4438,
641,
282,
3414,
1021,
1928,
636,
1661,
363,
272,
347,
511,
63,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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
] |
robhudson/django
|
django/template/response.py
|
84
|
5682
|
from django.http import HttpResponse
from django.utils import six
from .loader import get_template, select_template
class ContentNotRenderedError(Exception):
pass
class SimpleTemplateResponse(HttpResponse):
rendering_attrs = ['template_name', 'context_data', '_post_render_callbacks']
def __init__(self, template, context=None, content_type=None, status=None,
charset=None, using=None):
# It would seem obvious to call these next two members 'template' and
# 'context', but those names are reserved as part of the test Client
# API. To avoid the name collision, we use different names.
self.template_name = template
self.context_data = context
self.using = using
self._post_render_callbacks = []
# _request stores the current request object in subclasses that know
# about requests, like TemplateResponse. It's defined in the base class
# to minimize code duplication.
# It's called self._request because self.request gets overwritten by
# django.test.client.Client. Unlike template_name and context_data,
# _request should not be considered part of the public API.
self._request = None
# content argument doesn't make sense here because it will be replaced
# with rendered template so we always pass empty string in order to
# prevent errors and provide shorter signature.
super(SimpleTemplateResponse, self).__init__('', content_type, status, charset)
# _is_rendered tracks whether the template and context has been baked
# into a final response.
# Super __init__ doesn't know any better than to set self.content to
# the empty string we just gave it, which wrongly sets _is_rendered
# True, so we initialize it to False after the call to super __init__.
self._is_rendered = False
def __getstate__(self):
"""Pickling support function.
Ensures that the object can't be pickled before it has been
rendered, and that the pickled state only includes rendered
data, not the data used to construct the response.
"""
obj_dict = self.__dict__.copy()
if not self._is_rendered:
raise ContentNotRenderedError('The response content must be '
'rendered before it can be pickled.')
for attr in self.rendering_attrs:
if attr in obj_dict:
del obj_dict[attr]
return obj_dict
def resolve_template(self, template):
"Accepts a template object, path-to-template or list of paths"
if isinstance(template, (list, tuple)):
return select_template(template, using=self.using)
elif isinstance(template, six.string_types):
return get_template(template, using=self.using)
else:
return template
def resolve_context(self, context):
return context
@property
def rendered_content(self):
"""Returns the freshly rendered content for the template and context
described by the TemplateResponse.
This *does not* set the final content of the response. To set the
response content, you must either call render(), or set the
content explicitly using the value of this property.
"""
template = self.resolve_template(self.template_name)
context = self.resolve_context(self.context_data)
content = template.render(context, self._request)
return content
def add_post_render_callback(self, callback):
"""Adds a new post-rendering callback.
If the response has already been rendered,
invoke the callback immediately.
"""
if self._is_rendered:
callback(self)
else:
self._post_render_callbacks.append(callback)
def render(self):
"""Renders (thereby finalizing) the content of the response.
If the content has already been rendered, this is a no-op.
Returns the baked response instance.
"""
retval = self
if not self._is_rendered:
self.content = self.rendered_content
for post_callback in self._post_render_callbacks:
newretval = post_callback(retval)
if newretval is not None:
retval = newretval
return retval
@property
def is_rendered(self):
return self._is_rendered
def __iter__(self):
if not self._is_rendered:
raise ContentNotRenderedError('The response content must be '
'rendered before it can be iterated over.')
return super(SimpleTemplateResponse, self).__iter__()
@property
def content(self):
if not self._is_rendered:
raise ContentNotRenderedError('The response content must be '
'rendered before it can be accessed.')
return super(SimpleTemplateResponse, self).content
@content.setter
def content(self, value):
"""Sets the content for the response
"""
HttpResponse.content.fset(self, value)
self._is_rendered = True
class TemplateResponse(SimpleTemplateResponse):
rendering_attrs = SimpleTemplateResponse.rendering_attrs + ['_request']
def __init__(self, request, template, context=None, content_type=None,
status=None, charset=None, using=None):
super(TemplateResponse, self).__init__(
template, context, content_type, status, charset, using)
self._request = request
|
bsd-3-clause
|
[
504,
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
504,
1275,
3422,
492,
664,
63,
1160,
12,
3504,
63,
1160,
421,
199,
533,
6646,
1763,
5349,
2995,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
5870,
31036,
8,
16287,
304,
272,
14066,
63,
3288,
275,
788,
1160,
63,
354,
297,
283,
1100,
63,
576,
297,
2513,
1932,
63,
3352,
63,
11948,
418,
339,
347,
636,
826,
721,
277,
12,
1978,
12,
1067,
29,
403,
12,
1564,
63,
466,
29,
403,
12,
2004,
29,
403,
12,
326,
5960,
29,
403,
12,
1808,
29,
403,
304,
267,
327,
2779,
3955,
17021,
25259,
370,
1240,
3520,
2163,
2877,
7556,
283,
1160,
7,
436,
267,
327,
283,
1100,
297,
1325,
5204,
1561,
787,
4644,
465,
1777,
402,
314,
511,
6810,
267,
327,
3261,
14,
4005,
5126,
314,
536,
25061,
12,
781,
675,
3365,
1561,
14,
267,
291,
14,
1160,
63,
354,
275,
1978,
267,
291,
14,
1100,
63,
576,
275,
1067,
398,
291,
14,
4941,
275,
1808,
398,
291,
423,
1932,
63,
3352,
63,
11948,
275,
942,
398,
327,
485,
1069,
14086,
314,
1453,
1056,
909,
315,
9180,
626,
5715,
267,
327,
3595,
4145,
12,
2839,
29264,
14,
2779,
1159,
3247,
315,
314,
1300,
1021,
267,
327,
370,
24720,
1233,
11866,
1863,
14,
267,
327,
2779,
1159,
2797,
291,
423,
1069,
2952,
291,
14,
1069,
7545,
20200,
701,
267,
327,
1639,
14,
396,
14,
1258,
14,
3041,
14,
25059,
1978,
63,
354,
436,
1067,
63,
576,
12,
267,
327,
485,
1069,
1077,
440,
506,
8652,
1777,
402,
314,
4575,
3261,
14,
267,
291,
423,
1069,
275,
488,
398,
327,
1564,
1423,
3181,
1133,
1852,
12249,
2348,
2952,
652,
911,
506,
8717,
267,
327,
543,
8018,
1978,
880,
781,
3544,
986,
2701,
1059,
315,
1865,
370,
267,
327,
7981,
2552,
436,
5647,
18299,
4955,
14,
267,
1613,
8,
3184,
31036,
12,
291,
2843,
826,
363,
8594,
1564,
63,
466,
12,
2004,
12,
5960,
9,
398,
327,
485,
374,
63,
16841,
18917,
3775,
314,
1978,
436,
1067,
965,
2757,
330,
16702,
267,
327,
1901,
282,
4242,
1177,
14,
267,
327,
17897,
636,
826,
363,
3181,
1133,
5715,
1263,
8034,
2419,
370,
663,
291,
14,
1317,
370,
267,
327,
314,
2701,
1059,
781,
2951,
486,
811,
652,
12,
1314,
6835,
590,
5951,
485,
374,
63,
16841,
267,
327,
715,
12,
880,
781,
8265,
652,
370,
756,
2410,
314,
1240,
370,
1613,
636,
826,
4343,
267,
291,
423,
374,
63,
16841,
275,
756,
339,
347,
636,
16011,
721,
277,
304,
267,
408,
8587,
2983,
2291,
805,
14,
398,
29652,
626,
314,
909,
883,
1133,
506,
18731,
2544,
652,
965,
2757,
267,
8018,
12,
436,
626,
314,
18731,
1174,
1454,
6952,
8018,
267,
666,
12,
440,
314,
666,
1202,
370,
6982,
314,
1177,
14,
267,
408,
267,
1559,
63,
807,
275,
291,
855,
807,
4343,
1574,
342,
267,
340,
440,
291,
423,
374,
63,
16841,
26,
288,
746,
6646,
1763,
5349,
2995,
547,
360,
1918,
1177,
1564,
1471,
506,
283,
5101,
283,
16841,
2544,
652,
883,
506,
18731,
2659,
267,
367,
1921,
315,
291,
14,
28228,
63,
3288,
26,
288,
340,
1921,
315,
1559,
63,
807,
26,
355,
2150,
1559,
63,
807,
59,
962,
61,
398,
372,
1559,
63,
807,
339,
347,
7512,
63,
1160,
8,
277,
12,
1978,
304,
267,
298,
8422,
83,
282,
1978,
909,
12,
931,
13,
475,
13,
1160,
503,
769,
402,
3792,
2,
267,
340,
1228,
8,
1160,
12,
334,
513,
12,
2008,
2298,
288,
372,
3504,
63,
1160,
8,
1160,
12,
1808,
29,
277,
14,
4941,
9,
267,
916,
1228,
8,
1160,
12,
3816,
14,
875,
63,
1313,
304,
288,
372,
664,
63,
1160,
8,
1160,
12,
1808,
29,
277,
14,
4941,
9,
267,
587,
26,
288,
372,
1978,
339,
347,
7512,
63,
1100,
8,
277,
12,
1067,
304,
267,
372,
1067,
339,
768,
1829,
272,
347,
8018,
63,
1317,
8,
277,
304,
267,
408,
3407,
314,
17480,
590,
8018,
1564,
367,
314,
1978,
436,
1067,
267,
11736,
701,
314,
29264,
14,
398,
961,
627,
9105,
440,
10,
663,
314,
4242,
1564,
402,
314,
1177,
14,
4005,
663,
314,
267,
1177,
1564,
12,
1265,
1471,
1902,
1240,
3795,
1062,
503,
663,
314,
267,
1564,
7662,
1808,
314,
574,
402,
642,
3324,
14,
267,
408,
267,
1978,
275,
291,
14,
6983,
63,
1160,
8,
277,
14,
1160,
63,
354,
9,
267,
1067,
275,
291,
14,
6983,
63,
1100,
8,
277,
14,
1100,
63,
576,
9,
267,
1564,
275,
1978,
14,
3352,
8,
1100,
12,
291,
423,
1069,
9,
267,
372,
1564,
339,
347,
1050,
63,
1932,
63,
3352,
63,
3058,
8,
277,
12,
3233,
304,
267,
408,
14995,
282,
892,
2963,
13,
28228,
3233,
14,
398,
982,
314,
1177,
965,
2575,
2757,
8018,
12,
267,
12677,
314,
3233,
9939,
14,
267,
408,
267,
340,
291,
423,
374,
63,
16841,
26,
288,
3233,
8,
277,
9,
267,
587,
26,
288,
291,
423,
1932,
63,
3352,
63,
11948,
14,
740,
8,
3058,
9,
339,
347,
3795,
8,
277,
304,
267,
408,
5349,
7735,
334,
16990,
991,
4242,
9147,
9,
314,
1564,
402,
314,
1177,
14,
398,
982,
314,
1564,
965,
2575,
2757,
8018,
12,
642,
365,
282,
949,
13,
411,
14,
398,
1803,
314,
330,
16702,
1177,
1256,
14,
267,
408,
267,
9151,
275,
291,
267,
340,
440,
291,
423,
374,
63,
16841,
26,
288,
291,
14,
1317,
275,
291,
14,
16841,
63,
1317,
288,
367,
2963,
63,
3058,
315,
291,
423,
1932,
63,
3352,
63,
11948,
26,
355,
892,
18476,
275,
2963,
63,
3058,
8,
18476,
9,
355,
340,
892,
18476,
365,
440,
488,
26,
490,
9151,
275,
892,
18476,
267,
372,
9151,
339,
768,
1829,
272,
347,
365,
63,
16841,
8,
277,
304,
267,
372,
291,
423,
374,
63,
16841,
339,
347,
636,
1661,
721,
277,
304,
267,
340,
440,
291,
423,
374,
63,
16841,
26,
288,
746,
6646,
1763,
5349,
2995,
547,
360,
1918,
1177,
1564,
1471,
506,
283,
5101,
283,
16841,
2544,
652,
883,
506,
27924,
1806,
2659,
267,
372,
1613,
8,
3184,
31036,
12,
291,
2843,
1661,
4533,
339,
768,
1829,
272,
347,
1564,
8,
277,
304,
267,
340,
440,
291,
423,
374,
63,
16841,
26,
288,
746
] |
[
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
1208,
492,
3816,
199,
199,
504,
1275,
3422,
492,
664,
63,
1160,
12,
3504,
63,
1160,
421,
199,
533,
6646,
1763,
5349,
2995,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
5870,
31036,
8,
16287,
304,
272,
14066,
63,
3288,
275,
788,
1160,
63,
354,
297,
283,
1100,
63,
576,
297,
2513,
1932,
63,
3352,
63,
11948,
418,
339,
347,
636,
826,
721,
277,
12,
1978,
12,
1067,
29,
403,
12,
1564,
63,
466,
29,
403,
12,
2004,
29,
403,
12,
326,
5960,
29,
403,
12,
1808,
29,
403,
304,
267,
327,
2779,
3955,
17021,
25259,
370,
1240,
3520,
2163,
2877,
7556,
283,
1160,
7,
436,
267,
327,
283,
1100,
297,
1325,
5204,
1561,
787,
4644,
465,
1777,
402,
314,
511,
6810,
267,
327,
3261,
14,
4005,
5126,
314,
536,
25061,
12,
781,
675,
3365,
1561,
14,
267,
291,
14,
1160,
63,
354,
275,
1978,
267,
291,
14,
1100,
63,
576,
275,
1067,
398,
291,
14,
4941,
275,
1808,
398,
291,
423,
1932,
63,
3352,
63,
11948,
275,
942,
398,
327,
485,
1069,
14086,
314,
1453,
1056,
909,
315,
9180,
626,
5715,
267,
327,
3595,
4145,
12,
2839,
29264,
14,
2779,
1159,
3247,
315,
314,
1300,
1021,
267,
327,
370,
24720,
1233,
11866,
1863,
14,
267,
327,
2779,
1159,
2797,
291,
423,
1069,
2952,
291,
14,
1069,
7545,
20200,
701,
267,
327,
1639,
14,
396,
14,
1258,
14,
3041,
14,
25059,
1978,
63,
354,
436,
1067,
63,
576,
12,
267,
327,
485,
1069,
1077,
440,
506,
8652,
1777,
402,
314,
4575,
3261,
14,
267,
291,
423,
1069,
275,
488,
398,
327,
1564,
1423,
3181,
1133,
1852,
12249,
2348,
2952,
652,
911,
506,
8717,
267,
327,
543,
8018,
1978,
880,
781,
3544,
986,
2701,
1059,
315,
1865,
370,
267,
327,
7981,
2552,
436,
5647,
18299,
4955,
14,
267,
1613,
8,
3184,
31036,
12,
291,
2843,
826,
363,
8594,
1564,
63,
466,
12,
2004,
12,
5960,
9,
398,
327,
485,
374,
63,
16841,
18917,
3775,
314,
1978,
436,
1067,
965,
2757,
330,
16702,
267,
327,
1901,
282,
4242,
1177,
14,
267,
327,
17897,
636,
826,
363,
3181,
1133,
5715,
1263,
8034,
2419,
370,
663,
291,
14,
1317,
370,
267,
327,
314,
2701,
1059,
781,
2951,
486,
811,
652,
12,
1314,
6835,
590,
5951,
485,
374,
63,
16841,
267,
327,
715,
12,
880,
781,
8265,
652,
370,
756,
2410,
314,
1240,
370,
1613,
636,
826,
4343,
267,
291,
423,
374,
63,
16841,
275,
756,
339,
347,
636,
16011,
721,
277,
304,
267,
408,
8587,
2983,
2291,
805,
14,
398,
29652,
626,
314,
909,
883,
1133,
506,
18731,
2544,
652,
965,
2757,
267,
8018,
12,
436,
626,
314,
18731,
1174,
1454,
6952,
8018,
267,
666,
12,
440,
314,
666,
1202,
370,
6982,
314,
1177,
14,
267,
408,
267,
1559,
63,
807,
275,
291,
855,
807,
4343,
1574,
342,
267,
340,
440,
291,
423,
374,
63,
16841,
26,
288,
746,
6646,
1763,
5349,
2995,
547,
360,
1918,
1177,
1564,
1471,
506,
283,
5101,
283,
16841,
2544,
652,
883,
506,
18731,
2659,
267,
367,
1921,
315,
291,
14,
28228,
63,
3288,
26,
288,
340,
1921,
315,
1559,
63,
807,
26,
355,
2150,
1559,
63,
807,
59,
962,
61,
398,
372,
1559,
63,
807,
339,
347,
7512,
63,
1160,
8,
277,
12,
1978,
304,
267,
298,
8422,
83,
282,
1978,
909,
12,
931,
13,
475,
13,
1160,
503,
769,
402,
3792,
2,
267,
340,
1228,
8,
1160,
12,
334,
513,
12,
2008,
2298,
288,
372,
3504,
63,
1160,
8,
1160,
12,
1808,
29,
277,
14,
4941,
9,
267,
916,
1228,
8,
1160,
12,
3816,
14,
875,
63,
1313,
304,
288,
372,
664,
63,
1160,
8,
1160,
12,
1808,
29,
277,
14,
4941,
9,
267,
587,
26,
288,
372,
1978,
339,
347,
7512,
63,
1100,
8,
277,
12,
1067,
304,
267,
372,
1067,
339,
768,
1829,
272,
347,
8018,
63,
1317,
8,
277,
304,
267,
408,
3407,
314,
17480,
590,
8018,
1564,
367,
314,
1978,
436,
1067,
267,
11736,
701,
314,
29264,
14,
398,
961,
627,
9105,
440,
10,
663,
314,
4242,
1564,
402,
314,
1177,
14,
4005,
663,
314,
267,
1177,
1564,
12,
1265,
1471,
1902,
1240,
3795,
1062,
503,
663,
314,
267,
1564,
7662,
1808,
314,
574,
402,
642,
3324,
14,
267,
408,
267,
1978,
275,
291,
14,
6983,
63,
1160,
8,
277,
14,
1160,
63,
354,
9,
267,
1067,
275,
291,
14,
6983,
63,
1100,
8,
277,
14,
1100,
63,
576,
9,
267,
1564,
275,
1978,
14,
3352,
8,
1100,
12,
291,
423,
1069,
9,
267,
372,
1564,
339,
347,
1050,
63,
1932,
63,
3352,
63,
3058,
8,
277,
12,
3233,
304,
267,
408,
14995,
282,
892,
2963,
13,
28228,
3233,
14,
398,
982,
314,
1177,
965,
2575,
2757,
8018,
12,
267,
12677,
314,
3233,
9939,
14,
267,
408,
267,
340,
291,
423,
374,
63,
16841,
26,
288,
3233,
8,
277,
9,
267,
587,
26,
288,
291,
423,
1932,
63,
3352,
63,
11948,
14,
740,
8,
3058,
9,
339,
347,
3795,
8,
277,
304,
267,
408,
5349,
7735,
334,
16990,
991,
4242,
9147,
9,
314,
1564,
402,
314,
1177,
14,
398,
982,
314,
1564,
965,
2575,
2757,
8018,
12,
642,
365,
282,
949,
13,
411,
14,
398,
1803,
314,
330,
16702,
1177,
1256,
14,
267,
408,
267,
9151,
275,
291,
267,
340,
440,
291,
423,
374,
63,
16841,
26,
288,
291,
14,
1317,
275,
291,
14,
16841,
63,
1317,
288,
367,
2963,
63,
3058,
315,
291,
423,
1932,
63,
3352,
63,
11948,
26,
355,
892,
18476,
275,
2963,
63,
3058,
8,
18476,
9,
355,
340,
892,
18476,
365,
440,
488,
26,
490,
9151,
275,
892,
18476,
267,
372,
9151,
339,
768,
1829,
272,
347,
365,
63,
16841,
8,
277,
304,
267,
372,
291,
423,
374,
63,
16841,
339,
347,
636,
1661,
721,
277,
304,
267,
340,
440,
291,
423,
374,
63,
16841,
26,
288,
746,
6646,
1763,
5349,
2995,
547,
360,
1918,
1177,
1564,
1471,
506,
283,
5101,
283,
16841,
2544,
652,
883,
506,
27924,
1806,
2659,
267,
372,
1613,
8,
3184,
31036,
12,
291,
2843,
1661,
4533,
339,
768,
1829,
272,
347,
1564,
8,
277,
304,
267,
340,
440,
291,
423,
374,
63,
16841,
26,
288,
746,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shanemcd/ansible
|
lib/ansible/modules/system/locale_gen.py
|
26
|
7451
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# 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: locale_gen
short_description: Creates or removes locales.
description:
- Manages locales by editing /etc/locale.gen and invoking locale-gen.
version_added: "1.6"
author: "Augustus Kling (@AugustusKling)"
options:
name:
description:
- Name and encoding of the locale, such as "en_GB.UTF-8".
required: true
default: null
aliases: []
state:
description:
- Whether the locale shall be present.
required: false
choices: ["present", "absent"]
default: "present"
'''
EXAMPLES = '''
# Ensure a locale exists.
- locale_gen:
name: de_CH.UTF-8
state: present
'''
import os
import os.path
from subprocess import Popen, PIPE, call
import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native
LOCALE_NORMALIZATION = {
".utf8": ".UTF-8",
".eucjp": ".EUC-JP",
".iso885915": ".ISO-8859-15",
".cp1251": ".CP1251",
".koi8r": ".KOI8-R",
".armscii8": ".ARMSCII-8",
".euckr": ".EUC-KR",
".gbk": ".GBK",
".gb18030": ".GB18030",
".euctw": ".EUC-TW",
}
# ===========================================
# location module specific support methods.
#
def is_available(name, ubuntuMode):
"""Check if the given locale is available on the system. This is done by
checking either :
* if the locale is present in /etc/locales.gen
* or if the locale is present in /usr/share/i18n/SUPPORTED"""
if ubuntuMode:
__regexp = '^(?P<locale>\S+_\S+) (?P<charset>\S+)\s*$'
__locales_available = '/usr/share/i18n/SUPPORTED'
else:
__regexp = '^#{0,1}\s*(?P<locale>\S+_\S+) (?P<charset>\S+)\s*$'
__locales_available = '/etc/locale.gen'
re_compiled = re.compile(__regexp)
fd = open(__locales_available, 'r')
for line in fd:
result = re_compiled.match(line)
if result and result.group('locale') == name:
return True
fd.close()
return False
def is_present(name):
"""Checks if the given locale is currently installed."""
output = Popen(["locale", "-a"], stdout=PIPE).communicate()[0]
output = to_native(output)
return any(fix_case(name) == fix_case(line) for line in output.splitlines())
def fix_case(name):
"""locale -a might return the encoding in either lower or upper case.
Passing through this function makes them uniform for comparisons."""
for s, r in LOCALE_NORMALIZATION.items():
name = name.replace(s, r)
return name
def replace_line(existing_line, new_line):
"""Replaces lines in /etc/locale.gen"""
try:
f = open("/etc/locale.gen", "r")
lines = [line.replace(existing_line, new_line) for line in f]
finally:
f.close()
try:
f = open("/etc/locale.gen", "w")
f.write("".join(lines))
finally:
f.close()
def set_locale(name, enabled=True):
""" Sets the state of the locale. Defaults to enabled. """
search_string = '#{0,1}\s*%s (?P<charset>.+)' % name
if enabled:
new_string = '%s \g<charset>' % (name)
else:
new_string = '# %s \g<charset>' % (name)
try:
f = open("/etc/locale.gen", "r")
lines = [re.sub(search_string, new_string, line) for line in f]
finally:
f.close()
try:
f = open("/etc/locale.gen", "w")
f.write("".join(lines))
finally:
f.close()
def apply_change(targetState, name):
"""Create or remove locale.
Keyword arguments:
targetState -- Desired state, either present or absent.
name -- Name including encoding such as de_CH.UTF-8.
"""
if targetState=="present":
# Create locale.
set_locale(name, enabled=True)
else:
# Delete locale.
set_locale(name, enabled=False)
localeGenExitValue = call("locale-gen")
if localeGenExitValue!=0:
raise EnvironmentError(localeGenExitValue, "locale.gen failed to execute, it returned "+str(localeGenExitValue))
def apply_change_ubuntu(targetState, name):
"""Create or remove locale.
Keyword arguments:
targetState -- Desired state, either present or absent.
name -- Name including encoding such as de_CH.UTF-8.
"""
if targetState=="present":
# Create locale.
# Ubuntu's patched locale-gen automatically adds the new locale to /var/lib/locales/supported.d/local
localeGenExitValue = call(["locale-gen", name])
else:
# Delete locale involves discarding the locale from /var/lib/locales/supported.d/local and regenerating all locales.
try:
f = open("/var/lib/locales/supported.d/local", "r")
content = f.readlines()
finally:
f.close()
try:
f = open("/var/lib/locales/supported.d/local", "w")
for line in content:
locale, charset = line.split(' ')
if locale != name:
f.write(line)
finally:
f.close()
# Purge locales and regenerate.
# Please provide a patch if you know how to avoid regenerating the locales to keep!
localeGenExitValue = call(["locale-gen", "--purge"])
if localeGenExitValue!=0:
raise EnvironmentError(localeGenExitValue, "locale.gen failed to execute, it returned "+str(localeGenExitValue))
# ==============================================================
# main
def main():
module = AnsibleModule(
argument_spec = dict(
name = dict(required=True),
state = dict(choices=['present','absent'], default='present'),
),
supports_check_mode=True
)
name = module.params['name']
state = module.params['state']
if not os.path.exists("/etc/locale.gen"):
if os.path.exists("/var/lib/locales/supported.d/"):
# Ubuntu created its own system to manage locales.
ubuntuMode = True
else:
module.fail_json(msg="/etc/locale.gen and /var/lib/locales/supported.d/local are missing. Is the package \"locales\" installed?")
else:
# We found the common way to manage locales.
ubuntuMode = False
if not is_available(name, ubuntuMode):
module.fail_json(msg="The locales you've entered is not available "
"on your system.")
if is_present(name):
prev_state = "present"
else:
prev_state = "absent"
changed = (prev_state!=state)
if module.check_mode:
module.exit_json(changed=changed)
else:
if changed:
try:
if ubuntuMode is False:
apply_change(state, name)
else:
apply_change_ubuntu(state, name)
except EnvironmentError:
e = get_exception()
module.fail_json(msg=e.strerror, exitValue=e.errno)
module.exit_json(name=name, changed=changed, msg="OK")
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,
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,
5867,
63,
2268,
199,
3612,
63,
1802,
26,
10560,
503,
14185,
24847,
14,
199,
1802,
26,
1362,
446,
21612,
24847,
701,
20401,
1182,
6839,
15,
5508,
14,
2268,
436,
26750,
5867,
13,
2268,
14,
199,
1023,
63,
3270,
26,
298,
17,
14,
22,
2,
199,
2502,
26,
298,
21640,
833,
527,
1804,
2983,
8593,
21640,
833,
527,
43,
2983,
2924,
199,
1419,
26,
272,
536,
26,
267,
1369,
26,
1467,
446,
2812,
436,
2644,
402,
314,
5867,
12,
4066,
465,
298,
287,
63,
6487,
14,
6610,
13,
24,
1674,
267,
1415,
26,
2549,
267,
849,
26,
2973,
267,
5481,
26,
942,
272,
1174,
26,
489,
1369,
26,
1779,
446,
7480,
314,
5867,
10989,
506,
3451,
14,
489,
1415,
26,
3055,
489,
3415,
26,
2097,
1881,
401,
298,
5575,
937,
489,
849,
26,
298,
1881,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
7523,
282,
5867,
3495,
14,
199,
13,
5867,
63,
2268,
26,
272,
536,
26,
477,
63,
1244,
14,
6610,
13,
24,
272,
1174,
26,
3451,
199,
2344,
199,
199,
646,
747,
199,
646,
747,
14,
515,
199,
504,
3873,
492,
13995,
12,
22773,
12,
1240,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
647,
5819,
1194,
492,
664,
63,
1971,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
199,
20828,
63,
10765,
22800,
275,
469,
272,
3680,
1624,
24,
582,
3680,
6610,
13,
24,
401,
272,
3680,
15149,
11538,
582,
3680,
37,
13371,
13,
15819,
401,
272,
3680,
4595,
4830,
1046,
582,
3680,
7336,
13,
4830,
13,
1046,
401,
272,
3680,
1850,
21381,
582,
3680,
2890,
21381,
401,
272,
3680,
7697,
73,
24,
82,
582,
3680,
24839,
41,
24,
13,
50,
401,
272,
3680,
5362,
551,
5908,
24,
582,
3680,
689,
3053,
7364,
13,
24,
401,
272,
3680,
69,
10112,
82,
582,
3680,
37,
13371,
13,
23063,
401,
272,
3680,
4908,
75,
582,
3680,
6487,
43,
401,
272,
3680,
4908,
7663,
1216,
582,
3680,
6487,
7663,
1216,
401,
272,
3680,
69,
918,
87,
582,
3680,
37,
13371,
13,
16491,
401,
199,
93,
199,
199,
3,
19469,
17575,
199,
3,
2909,
859,
2488,
2291,
3102,
14,
199,
3,
199,
199,
318,
365,
63,
4561,
8,
354,
12,
399,
19313,
1385,
304,
272,
408,
1799,
340,
314,
1627,
5867,
365,
2808,
641,
314,
2656,
14,
961,
365,
4224,
701,
272,
7907,
1902,
520,
272,
627,
340,
314,
5867,
365,
3451,
315,
1182,
6839,
15,
24763,
14,
2268,
272,
627,
503,
340,
314,
5867,
365,
3451,
315,
1182,
2647,
15,
6251,
15,
73,
1085,
78,
15,
15925,
624,
272,
340,
399,
19313,
1385,
26,
267,
636,
11191,
275,
14452,
2229,
48,
28,
5508,
3072,
51,
6416,
60,
51,
8771,
7558,
48,
28,
6043,
3072,
51,
13439,
83,
10,
12913,
267,
636,
24763,
63,
4561,
275,
1994,
2647,
15,
6251,
15,
73,
1085,
78,
15,
15925,
7,
272,
587,
26,
267,
636,
11191,
275,
14452,
3,
91,
16,
12,
17,
4988,
83,
30957,
48,
28,
5508,
3072,
51,
6416,
60,
51,
8771,
7558,
48,
28,
6043,
3072,
51,
13439,
83,
10,
12913,
267,
636,
24763,
63,
4561,
275,
1994,
6839,
15,
5508,
14,
2268,
7,
339,
295,
63,
8427,
275,
295,
14,
2014,
3460,
11191,
9,
272,
6111,
275,
1551,
3460,
24763,
63,
4561,
12,
283,
82,
358,
272,
367,
1004,
315,
6111,
26,
267,
754,
275,
295,
63,
8427,
14,
1431,
8,
604,
9,
267,
340,
754,
436,
754,
14,
923,
360,
5508,
358,
508,
536,
26,
288,
372,
715,
272,
6111,
14,
1600,
342,
272,
372,
756,
199,
199,
318,
365,
63,
1881,
8,
354,
304,
272,
408,
11834,
340,
314,
1627,
5867,
365,
5544,
4903,
1041,
272,
1072,
275,
13995,
5234,
5508,
401,
3905,
65,
2255,
3839,
29,
6089,
680,
10664,
3430,
16,
61,
272,
1072,
275,
370,
63,
6106,
8,
1199,
9,
272,
372,
1263,
8,
970,
63,
2546,
8,
354,
9,
508,
5325,
63,
2546,
8,
604,
9,
367,
1004,
315,
1072,
14,
7644,
1012,
199,
199,
318,
5325,
63,
2546,
8,
354,
304,
272,
408,
5508,
446,
65,
5594,
372,
314,
2644,
315,
1902,
5117,
503,
7008,
1930,
14,
272,
31755,
4012,
642,
805,
7704,
3062,
14818,
367,
20448,
1041,
272,
367,
308,
12,
519,
315,
20639,
37,
63,
10765,
22800,
14,
1744,
837,
267,
536,
275,
536,
14,
1814,
8,
83,
12,
519,
9,
272,
372,
536,
199,
199,
318,
3350,
63,
604,
8,
5952,
63,
604,
12,
892,
63,
604,
304,
272,
408,
6875,
5862,
2385,
315,
1182,
6839,
15,
5508,
14,
2268,
624,
272,
862,
26,
267,
289,
275,
1551,
4769,
6839,
15,
5508,
14,
2268,
401,
298,
82,
531,
267,
2385,
275,
359,
604,
14,
1814,
8,
5952,
63,
604,
12,
892,
63,
604,
9,
367,
1004,
315,
289,
61,
272,
3753,
26,
267,
289,
14,
1600,
342,
272,
862,
26,
267,
289,
275,
1551,
4769,
6839,
15,
5508,
14,
2268,
401,
298,
87,
531,
267,
289,
14,
952,
31059,
904,
8,
1278,
430,
272,
3753,
26,
267,
289,
14,
1600,
342,
199,
199,
318,
663,
63,
5508,
8,
354,
12,
5223,
29,
549,
304,
272,
408,
10729,
314,
1174,
402,
314,
5867,
14,
7827,
370,
5223,
14,
408,
272,
2754,
63,
875,
275,
3943,
91,
16,
12,
17,
4988,
83,
32639,
83,
7558,
48,
28,
6043,
31411,
3171,
450,
536,
272,
340,
5223,
26,
267,
892,
63,
875,
275,
1543,
83,
971,
71,
28,
6043,
3524,
450,
334
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
5867,
63,
2268,
199,
3612,
63,
1802,
26,
10560,
503,
14185,
24847,
14,
199,
1802,
26,
1362,
446,
21612,
24847,
701,
20401,
1182,
6839,
15,
5508,
14,
2268,
436,
26750,
5867,
13,
2268,
14,
199,
1023,
63,
3270,
26,
298,
17,
14,
22,
2,
199,
2502,
26,
298,
21640,
833,
527,
1804,
2983,
8593,
21640,
833,
527,
43,
2983,
2924,
199,
1419,
26,
272,
536,
26,
267,
1369,
26,
1467,
446,
2812,
436,
2644,
402,
314,
5867,
12,
4066,
465,
298,
287,
63,
6487,
14,
6610,
13,
24,
1674,
267,
1415,
26,
2549,
267,
849,
26,
2973,
267,
5481,
26,
942,
272,
1174,
26,
489,
1369,
26,
1779,
446,
7480,
314,
5867,
10989,
506,
3451,
14,
489,
1415,
26,
3055,
489,
3415,
26,
2097,
1881,
401,
298,
5575,
937,
489,
849,
26,
298,
1881,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
7523,
282,
5867,
3495,
14,
199,
13,
5867,
63,
2268,
26,
272,
536,
26,
477,
63,
1244,
14,
6610,
13,
24,
272,
1174,
26,
3451,
199,
2344,
199,
199,
646,
747,
199,
646,
747,
14,
515,
199,
504,
3873,
492,
13995,
12,
22773,
12,
1240,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
647,
5819,
1194,
492,
664,
63,
1971,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
199,
20828,
63,
10765,
22800,
275,
469,
272,
3680,
1624,
24,
582,
3680,
6610,
13,
24,
401,
272,
3680,
15149,
11538,
582,
3680,
37,
13371,
13,
15819,
401,
272,
3680,
4595,
4830,
1046,
582,
3680,
7336,
13,
4830,
13,
1046,
401,
272,
3680,
1850,
21381,
582,
3680,
2890,
21381,
401,
272,
3680,
7697,
73,
24,
82,
582,
3680,
24839,
41,
24,
13,
50,
401,
272,
3680,
5362,
551,
5908,
24,
582,
3680,
689,
3053,
7364,
13,
24,
401,
272,
3680,
69,
10112,
82,
582,
3680,
37,
13371,
13,
23063,
401,
272,
3680,
4908,
75,
582,
3680,
6487,
43,
401,
272,
3680,
4908,
7663,
1216,
582,
3680,
6487,
7663,
1216,
401,
272,
3680,
69,
918,
87,
582,
3680,
37,
13371,
13,
16491,
401,
199,
93,
199,
199,
3,
19469,
17575,
199,
3,
2909,
859,
2488,
2291,
3102,
14,
199,
3,
199,
199,
318,
365,
63,
4561,
8,
354,
12,
399,
19313,
1385,
304,
272,
408,
1799,
340,
314,
1627,
5867,
365,
2808,
641,
314,
2656,
14,
961,
365,
4224,
701,
272,
7907,
1902,
520,
272,
627,
340,
314,
5867,
365,
3451,
315,
1182,
6839,
15,
24763,
14,
2268,
272,
627,
503,
340,
314,
5867,
365,
3451,
315,
1182,
2647,
15,
6251,
15,
73,
1085,
78,
15,
15925,
624,
272,
340,
399,
19313,
1385,
26,
267,
636,
11191,
275,
14452,
2229,
48,
28,
5508,
3072,
51,
6416,
60,
51,
8771,
7558,
48,
28,
6043,
3072,
51,
13439,
83,
10,
12913,
267,
636,
24763,
63,
4561,
275,
1994,
2647,
15,
6251,
15,
73,
1085,
78,
15,
15925,
7,
272,
587,
26,
267,
636,
11191,
275,
14452,
3,
91,
16,
12,
17,
4988,
83,
30957,
48,
28,
5508,
3072,
51,
6416,
60,
51,
8771,
7558,
48,
28,
6043,
3072,
51,
13439,
83,
10,
12913,
267,
636,
24763,
63,
4561,
275,
1994,
6839,
15,
5508,
14,
2268,
7,
339,
295,
63,
8427,
275,
295,
14,
2014,
3460,
11191,
9,
272,
6111,
275,
1551,
3460,
24763,
63,
4561,
12,
283,
82,
358,
272,
367,
1004,
315,
6111,
26,
267,
754,
275,
295,
63,
8427,
14,
1431,
8,
604,
9,
267,
340,
754,
436,
754,
14,
923,
360,
5508,
358,
508,
536,
26,
288,
372,
715,
272,
6111,
14,
1600,
342,
272,
372,
756,
199,
199,
318,
365,
63,
1881,
8,
354,
304,
272,
408,
11834,
340,
314,
1627,
5867,
365,
5544,
4903,
1041,
272,
1072,
275,
13995,
5234,
5508,
401,
3905,
65,
2255,
3839,
29,
6089,
680,
10664,
3430,
16,
61,
272,
1072,
275,
370,
63,
6106,
8,
1199,
9,
272,
372,
1263,
8,
970,
63,
2546,
8,
354,
9,
508,
5325,
63,
2546,
8,
604,
9,
367,
1004,
315,
1072,
14,
7644,
1012,
199,
199,
318,
5325,
63,
2546,
8,
354,
304,
272,
408,
5508,
446,
65,
5594,
372,
314,
2644,
315,
1902,
5117,
503,
7008,
1930,
14,
272,
31755,
4012,
642,
805,
7704,
3062,
14818,
367,
20448,
1041,
272,
367,
308,
12,
519,
315,
20639,
37,
63,
10765,
22800,
14,
1744,
837,
267,
536,
275,
536,
14,
1814,
8,
83,
12,
519,
9,
272,
372,
536,
199,
199,
318,
3350,
63,
604,
8,
5952,
63,
604,
12,
892,
63,
604,
304,
272,
408,
6875,
5862,
2385,
315,
1182,
6839,
15,
5508,
14,
2268,
624,
272,
862,
26,
267,
289,
275,
1551,
4769,
6839,
15,
5508,
14,
2268,
401,
298,
82,
531,
267,
2385,
275,
359,
604,
14,
1814,
8,
5952,
63,
604,
12,
892,
63,
604,
9,
367,
1004,
315,
289,
61,
272,
3753,
26,
267,
289,
14,
1600,
342,
272,
862,
26,
267,
289,
275,
1551,
4769,
6839,
15,
5508,
14,
2268,
401,
298,
87,
531,
267,
289,
14,
952,
31059,
904,
8,
1278,
430,
272,
3753,
26,
267,
289,
14,
1600,
342,
199,
199,
318,
663,
63,
5508,
8,
354,
12,
5223,
29,
549,
304,
272,
408,
10729,
314,
1174,
402,
314,
5867,
14,
7827,
370,
5223,
14,
408,
272,
2754,
63,
875,
275,
3943,
91,
16,
12,
17,
4988,
83,
32639,
83,
7558,
48,
28,
6043,
31411,
3171,
450,
536,
272,
340,
5223,
26,
267,
892,
63,
875,
275,
1543,
83,
971,
71,
28,
6043,
3524,
450,
334,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
g1o/trinityrnaseq
|
util/misc/TPM_weighted_gene_length.py
|
1
|
4564
|
#!/usr/bin/env python
# encoding: utf-8
from __future__ import (absolute_import, division,
print_function, unicode_literals)
import os, sys, re
import logging
import argparse
import collections
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
logger = logging.getLogger(__file__)
def main():
parser = argparse.ArgumentParser(description="estimates gene length as isoform lengths weighted by TPM expression values")
parser.add_argument("--gene_trans_map", dest="gene_trans_map_file", type=str, default="",
required=True, help="gene-to-transcript mapping file, format: gene_id(tab)transcript_id")
parser.add_argument("--trans_lengths", dest="trans_lengths_file", type=str, required=True,
help="transcript length file, format: trans_id(tab)length")
parser.add_argument("--TPM_matrix", dest="TPM_matrix_file", type=str, default="",
required=True, help="TPM expression matrix")
parser.add_argument("--debug", required=False, action="store_true", default=False, help="debug mode")
args = parser.parse_args()
if args.debug:
logger.setLevel(logging.DEBUG)
trans_to_gene_id_dict = parse_gene_trans_map(args.gene_trans_map_file)
trans_lengths_dict = parse_trans_lengths_file(args.trans_lengths_file)
trans_to_TPM_vals_dict = parse_TPM_matrix(args.TPM_matrix_file)
weighted_gene_lengths = compute_weighted_gene_lengths(trans_to_gene_id_dict,
trans_lengths_dict,
trans_to_TPM_vals_dict)
print("#gene_id\tlength")
for gene_id,length in weighted_gene_lengths.items():
print("\t".join([gene_id,str(length)]))
sys.exit(0)
def compute_weighted_gene_lengths(trans_to_gene_id_dict, trans_lengths_dict, trans_to_TPM_vals_dict):
gene_id_to_trans_list = collections.defaultdict(list)
gene_id_to_length = {}
pseudocount = 1
for trans_id,gene_id in trans_to_gene_id_dict.items():
gene_id_to_trans_list[gene_id].append(trans_id)
for gene_id,trans_list in gene_id_to_trans_list.items():
if len(trans_list) == 1:
gene_id_to_length[gene_id] = trans_lengths_dict[ trans_list[0] ]
else:
sum_length_x_expr = 0
sum_expr = 0
trans_expr_lengths = []
for trans_id in trans_list:
trans_len = trans_lengths_dict[trans_id]
expr_vals = trans_to_TPM_vals_dict[trans_id]
trans_sum_expr = sum(expr_vals) + pseudocount
trans_expr_lengths.append((trans_len, trans_sum_expr))
sum_length_x_expr += trans_sum_expr * trans_len
sum_expr += trans_sum_expr
weighted_gene_length = sum_length_x_expr / sum_expr
gene_id_to_length[gene_id] = int(round(weighted_gene_length))
logger.debug("Computing weighted length of {}: {} => {}".format(gene_id,
trans_expr_lengths,
weighted_gene_length))
return gene_id_to_length
def parse_TPM_matrix(TPM_matrix_file):
trans_to_TPM_vals_dict = {}
with open(TPM_matrix_file) as f:
header = f.next()
for line in f:
line = line.rstrip()
vals = line.split("\t")
trans_id = vals[0]
expr_vals_list = vals[1:]
expr_vals_list = [float(x) for x in expr_vals_list]
trans_to_TPM_vals_dict[trans_id] = expr_vals_list
return trans_to_TPM_vals_dict
def parse_trans_lengths_file(trans_lengths_file):
trans_id_to_length = {}
with open(trans_lengths_file) as f:
for line in f:
line = line.rstrip()
if line[0] == '#':
continue
(trans_id, length) = line.split("\t")
trans_id_to_length[trans_id] = int(length)
return trans_id_to_length
def parse_gene_trans_map(gene_trans_map_file):
trans_to_gene_id = {}
with open(gene_trans_map_file) as f:
for line in f:
line = line.rstrip()
(gene_id, trans_id) = line.split("\t")
trans_to_gene_id[trans_id] = gene_id;
return trans_to_gene_id
####################
if __name__ == "__main__":
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
717,
870,
63,
1593,
12,
2649,
63,
5955,
9,
199,
646,
747,
12,
984,
12,
295,
199,
646,
2050,
199,
646,
7534,
199,
646,
5055,
199,
199,
4806,
14,
19602,
8,
1745,
29,
1274,
14,
3083,
12,
2166,
29,
4806,
14,
4531,
9,
199,
2921,
275,
2050,
14,
5572,
3460,
493,
3368,
523,
199,
318,
2446,
837,
339,
1798,
275,
7534,
14,
10730,
8,
1802,
628,
597,
18187,
15599,
2582,
465,
11601,
964,
17464,
14609,
701,
377,
10793,
3965,
1338,
531,
2286,
1798,
14,
525,
63,
2094,
6739,
10654,
63,
1515,
63,
1130,
401,
2053,
628,
10654,
63,
1515,
63,
1130,
63,
493,
401,
730,
29,
495,
12,
849,
8772,
717,
1415,
29,
549,
12,
1720,
628,
10654,
13,
475,
13,
21656,
4412,
570,
12,
1475,
26,
15599,
63,
344,
8,
2902,
9,
21656,
63,
344,
531,
339,
1798,
14,
525,
63,
2094,
6739,
1515,
63,
14563,
401,
2053,
628,
1515,
63,
14563,
63,
493,
401,
730,
29,
495,
12,
1415,
29,
549,
12,
717,
1720,
628,
21656,
2582,
570,
12,
1475,
26,
1752,
63,
344,
8,
2902,
9,
1267,
531,
339,
1798,
14,
525,
63,
2094,
6739,
6495,
45,
63,
3642,
401,
2053,
628,
6495,
45,
63,
3642,
63,
493,
401,
730,
29,
495,
12,
849,
8772,
717,
1415,
29,
549,
12,
1720,
628,
6495,
45,
3965,
3634,
531,
339,
1798,
14,
525,
63,
2094,
6739,
1757,
401,
1415,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
1720,
628,
1757,
818,
531,
2378,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
340,
1249,
14,
1757,
26,
267,
2512,
14,
13548,
8,
4806,
14,
5287,
9,
1362,
339,
1752,
63,
475,
63,
10654,
63,
344,
63,
807,
275,
2198,
63,
10654,
63,
1515,
63,
1130,
8,
589,
14,
10654,
63,
1515,
63,
1130,
63,
493,
9,
339,
1752,
63,
14563,
63,
807,
275,
2198,
63,
1515,
63,
14563,
63,
493,
8,
589,
14,
1515,
63,
14563,
63,
493,
9,
339,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
275,
2198,
63,
6495,
45,
63,
3642,
8,
589,
14,
6495,
45,
63,
3642,
63,
493,
9,
339,
14609,
63,
10654,
63,
14563,
275,
4526,
63,
13522,
63,
10654,
63,
14563,
8,
1515,
63,
475,
63,
10654,
63,
344,
63,
807,
12,
12933,
1752,
63,
14563,
63,
807,
12,
12933,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
9,
339,
870,
10064,
10654,
63,
344,
60,
84,
1267,
531,
272,
367,
15599,
63,
344,
12,
1267,
315,
14609,
63,
10654,
63,
14563,
14,
1744,
837,
267,
870,
4582,
84,
1674,
904,
779,
10654,
63,
344,
12,
495,
8,
1267,
19563,
2378,
984,
14,
2224,
8,
16,
9,
1362,
421,
199,
318,
4526,
63,
13522,
63,
10654,
63,
14563,
8,
1515,
63,
475,
63,
10654,
63,
344,
63,
807,
12,
1752,
63,
14563,
63,
807,
12,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
304,
339,
15599,
63,
344,
63,
475,
63,
1515,
63,
513,
275,
5055,
14,
21501,
8,
513,
9,
339,
15599,
63,
344,
63,
475,
63,
1267,
275,
1052,
339,
15984,
835,
275,
413,
339,
367,
1752,
63,
344,
12,
10654,
63,
344,
315,
1752,
63,
475,
63,
10654,
63,
344,
63,
807,
14,
1744,
837,
267,
15599,
63,
344,
63,
475,
63,
1515,
63,
513,
59,
10654,
63,
344,
1055,
740,
8,
1515,
63,
344,
9,
339,
367,
15599,
63,
344,
12,
1515,
63,
513,
315,
15599,
63,
344,
63,
475,
63,
1515,
63,
513,
14,
1744,
837,
398,
340,
822,
8,
1515,
63,
513,
9,
508,
413,
26,
953,
15599,
63,
344,
63,
475,
63,
1267,
59,
10654,
63,
344,
61,
275,
1752,
63,
14563,
63,
807,
59,
1752,
63,
513,
59,
16,
61,
1622,
267,
587,
26,
7846,
3089,
63,
1267,
63,
88,
63,
3684,
275,
378,
288,
3089,
63,
3684,
275,
378,
953,
1752,
63,
3684,
63,
14563,
275,
942,
953,
367,
1752,
63,
344,
315,
1752,
63,
513,
26,
355,
1752,
63,
552,
275,
1752,
63,
14563,
63,
807,
59,
1515,
63,
344,
61,
355,
5348,
63,
3643,
275,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
59,
1515,
63,
344,
61,
355,
1752,
63,
1838,
63,
3684,
275,
3089,
8,
3684,
63,
3643,
9,
435,
15984,
835,
2234,
1752,
63,
3684,
63,
14563,
14,
740,
1332,
1515,
63,
552,
12,
1752,
63,
1838,
63,
3684,
430,
2234,
3089,
63,
1267,
63,
88,
63,
3684,
847,
1752,
63,
1838,
63,
3684,
627,
1752,
63,
552,
355,
3089,
63,
3684,
847,
1752,
63,
1838,
63,
3684,
22919,
14609,
63,
10654,
63,
1267,
275,
3089,
63,
1267,
63,
88,
63,
3684,
1182,
3089,
63,
3684,
288,
15599,
63,
344,
63,
475,
63,
1267,
59,
10654,
63,
344,
61,
275,
1109,
8,
2363,
8,
13522,
63,
10654,
63,
1267,
430,
953,
2512,
14,
1757,
480,
2404,
4655,
14609,
2582,
402,
24702,
1052,
9265,
8352,
908,
8,
10654,
63,
344,
12,
6684,
3322,
1752,
63,
3684,
63,
14563,
12,
6684,
3322,
14609,
63,
10654,
63,
1267,
430,
15567,
372,
15599,
63,
344,
63,
475,
63,
1267,
1467,
421,
199,
318,
2198,
63,
6495,
45,
63,
3642,
8,
6495,
45,
63,
3642,
63,
493,
304,
339,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
275,
1052,
2286,
543,
1551,
8,
6495,
45,
63,
3642,
63,
493,
9,
465,
289,
26,
267,
1406,
275,
289,
14,
2184,
342,
267,
367,
1004,
315,
289,
26,
288,
1004,
275,
1004,
14,
6735,
342,
288,
5322,
275,
1004,
14,
1294,
4582,
84,
531,
288,
1752,
63,
344,
275,
5322,
59,
16,
61,
288,
5348,
63,
3643,
63,
513,
275,
5322,
59,
17,
2938,
288,
5348,
63,
3643,
63,
513,
275,
359,
1609,
8,
88,
9,
367,
671,
315,
5348,
63,
3643,
63,
513,
61,
288,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
59,
1515,
63,
344,
61,
275,
5348,
63,
3643,
63,
513,
339,
372,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
421,
199,
318,
2198,
63,
1515
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
717,
870,
63,
1593,
12,
2649,
63,
5955,
9,
199,
646,
747,
12,
984,
12,
295,
199,
646,
2050,
199,
646,
7534,
199,
646,
5055,
199,
199,
4806,
14,
19602,
8,
1745,
29,
1274,
14,
3083,
12,
2166,
29,
4806,
14,
4531,
9,
199,
2921,
275,
2050,
14,
5572,
3460,
493,
3368,
523,
199,
318,
2446,
837,
339,
1798,
275,
7534,
14,
10730,
8,
1802,
628,
597,
18187,
15599,
2582,
465,
11601,
964,
17464,
14609,
701,
377,
10793,
3965,
1338,
531,
2286,
1798,
14,
525,
63,
2094,
6739,
10654,
63,
1515,
63,
1130,
401,
2053,
628,
10654,
63,
1515,
63,
1130,
63,
493,
401,
730,
29,
495,
12,
849,
8772,
717,
1415,
29,
549,
12,
1720,
628,
10654,
13,
475,
13,
21656,
4412,
570,
12,
1475,
26,
15599,
63,
344,
8,
2902,
9,
21656,
63,
344,
531,
339,
1798,
14,
525,
63,
2094,
6739,
1515,
63,
14563,
401,
2053,
628,
1515,
63,
14563,
63,
493,
401,
730,
29,
495,
12,
1415,
29,
549,
12,
717,
1720,
628,
21656,
2582,
570,
12,
1475,
26,
1752,
63,
344,
8,
2902,
9,
1267,
531,
339,
1798,
14,
525,
63,
2094,
6739,
6495,
45,
63,
3642,
401,
2053,
628,
6495,
45,
63,
3642,
63,
493,
401,
730,
29,
495,
12,
849,
8772,
717,
1415,
29,
549,
12,
1720,
628,
6495,
45,
3965,
3634,
531,
339,
1798,
14,
525,
63,
2094,
6739,
1757,
401,
1415,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
1720,
628,
1757,
818,
531,
2378,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
340,
1249,
14,
1757,
26,
267,
2512,
14,
13548,
8,
4806,
14,
5287,
9,
1362,
339,
1752,
63,
475,
63,
10654,
63,
344,
63,
807,
275,
2198,
63,
10654,
63,
1515,
63,
1130,
8,
589,
14,
10654,
63,
1515,
63,
1130,
63,
493,
9,
339,
1752,
63,
14563,
63,
807,
275,
2198,
63,
1515,
63,
14563,
63,
493,
8,
589,
14,
1515,
63,
14563,
63,
493,
9,
339,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
275,
2198,
63,
6495,
45,
63,
3642,
8,
589,
14,
6495,
45,
63,
3642,
63,
493,
9,
339,
14609,
63,
10654,
63,
14563,
275,
4526,
63,
13522,
63,
10654,
63,
14563,
8,
1515,
63,
475,
63,
10654,
63,
344,
63,
807,
12,
12933,
1752,
63,
14563,
63,
807,
12,
12933,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
9,
339,
870,
10064,
10654,
63,
344,
60,
84,
1267,
531,
272,
367,
15599,
63,
344,
12,
1267,
315,
14609,
63,
10654,
63,
14563,
14,
1744,
837,
267,
870,
4582,
84,
1674,
904,
779,
10654,
63,
344,
12,
495,
8,
1267,
19563,
2378,
984,
14,
2224,
8,
16,
9,
1362,
421,
199,
318,
4526,
63,
13522,
63,
10654,
63,
14563,
8,
1515,
63,
475,
63,
10654,
63,
344,
63,
807,
12,
1752,
63,
14563,
63,
807,
12,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
304,
339,
15599,
63,
344,
63,
475,
63,
1515,
63,
513,
275,
5055,
14,
21501,
8,
513,
9,
339,
15599,
63,
344,
63,
475,
63,
1267,
275,
1052,
339,
15984,
835,
275,
413,
339,
367,
1752,
63,
344,
12,
10654,
63,
344,
315,
1752,
63,
475,
63,
10654,
63,
344,
63,
807,
14,
1744,
837,
267,
15599,
63,
344,
63,
475,
63,
1515,
63,
513,
59,
10654,
63,
344,
1055,
740,
8,
1515,
63,
344,
9,
339,
367,
15599,
63,
344,
12,
1515,
63,
513,
315,
15599,
63,
344,
63,
475,
63,
1515,
63,
513,
14,
1744,
837,
398,
340,
822,
8,
1515,
63,
513,
9,
508,
413,
26,
953,
15599,
63,
344,
63,
475,
63,
1267,
59,
10654,
63,
344,
61,
275,
1752,
63,
14563,
63,
807,
59,
1752,
63,
513,
59,
16,
61,
1622,
267,
587,
26,
7846,
3089,
63,
1267,
63,
88,
63,
3684,
275,
378,
288,
3089,
63,
3684,
275,
378,
953,
1752,
63,
3684,
63,
14563,
275,
942,
953,
367,
1752,
63,
344,
315,
1752,
63,
513,
26,
355,
1752,
63,
552,
275,
1752,
63,
14563,
63,
807,
59,
1515,
63,
344,
61,
355,
5348,
63,
3643,
275,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
59,
1515,
63,
344,
61,
355,
1752,
63,
1838,
63,
3684,
275,
3089,
8,
3684,
63,
3643,
9,
435,
15984,
835,
2234,
1752,
63,
3684,
63,
14563,
14,
740,
1332,
1515,
63,
552,
12,
1752,
63,
1838,
63,
3684,
430,
2234,
3089,
63,
1267,
63,
88,
63,
3684,
847,
1752,
63,
1838,
63,
3684,
627,
1752,
63,
552,
355,
3089,
63,
3684,
847,
1752,
63,
1838,
63,
3684,
22919,
14609,
63,
10654,
63,
1267,
275,
3089,
63,
1267,
63,
88,
63,
3684,
1182,
3089,
63,
3684,
288,
15599,
63,
344,
63,
475,
63,
1267,
59,
10654,
63,
344,
61,
275,
1109,
8,
2363,
8,
13522,
63,
10654,
63,
1267,
430,
953,
2512,
14,
1757,
480,
2404,
4655,
14609,
2582,
402,
24702,
1052,
9265,
8352,
908,
8,
10654,
63,
344,
12,
6684,
3322,
1752,
63,
3684,
63,
14563,
12,
6684,
3322,
14609,
63,
10654,
63,
1267,
430,
15567,
372,
15599,
63,
344,
63,
475,
63,
1267,
1467,
421,
199,
318,
2198,
63,
6495,
45,
63,
3642,
8,
6495,
45,
63,
3642,
63,
493,
304,
339,
1752,
63,
475,
63,
6495,
45,
63,
3643,
63,
807,
275,
1052,
2286,
543,
1551,
8,
6495,
45,
63,
3642,
63,
493,
9,
465,
289,
26,
267,
1406,
275,
289,
14,
2184,
342,
267,
367,
1004,
315,
289,
26,
288,
1004,
275,
1004,
14,
6735,
342,
288,
5322,
275,
1004,
14,
1294,
4582,
84,
531,
288,
1752,
63,
344,
275,
5322,
59,
16,
61,
288,
5348,
63,
3643,
63,
513,
275,
5322,
59,
17,
2938,
288,
5348,
63,
3643,
63,
513,
275,
359,
1609,
8,
88,
9,
367,
671,
315,
5348,
63,
3643,
63,
513,
61,
288,
1752,
63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