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
boto/botocore
botocore/hooks.py
4
24573
# Copyright 2012-2014 Amazon.com, Inc. or its affiliates. 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. A copy of # the License is located at # # http://aws.amazon.com/apache2.0/ # # or in the "license" file accompanying this file. This file is # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. import copy import logging from collections import defaultdict, deque, namedtuple from botocore.compat import accepts_kwargs, six from botocore.utils import EVENT_ALIASES logger = logging.getLogger(__name__) _NodeList = namedtuple('NodeList', ['first', 'middle', 'last']) _FIRST = 0 _MIDDLE = 1 _LAST = 2 class NodeList(_NodeList): def __copy__(self): first_copy = copy.copy(self.first) middle_copy = copy.copy(self.middle) last_copy = copy.copy(self.last) copied = NodeList(first_copy, middle_copy, last_copy) return copied def first_non_none_response(responses, default=None): """Find first non None response in a list of tuples. This function can be used to find the first non None response from handlers connected to an event. This is useful if you are interested in the returned responses from event handlers. Example usage:: print(first_non_none_response([(func1, None), (func2, 'foo'), (func3, 'bar')])) # This will print 'foo' :type responses: list of tuples :param responses: The responses from the ``EventHooks.emit`` method. This is a list of tuples, and each tuple is (handler, handler_response). :param default: If no non-None responses are found, then this default value will be returned. :return: The first non-None response in the list of tuples. """ for response in responses: if response[1] is not None: return response[1] return default class BaseEventHooks(object): def emit(self, event_name, **kwargs): """Call all handlers subscribed to an event. :type event_name: str :param event_name: The name of the event to emit. :type **kwargs: dict :param **kwargs: Arbitrary kwargs to pass through to the subscribed handlers. The ``event_name`` will be injected into the kwargs so it's not necesary to add this to **kwargs. :rtype: list of tuples :return: A list of ``(handler_func, handler_func_return_value)`` """ return [] def register(self, event_name, handler, unique_id=None, unique_id_uses_count=False): """Register an event handler for a given event. If a ``unique_id`` is given, the handler will not be registered if a handler with the ``unique_id`` has already been registered. Handlers are called in the order they have been registered. Note handlers can also be registered with ``register_first()`` and ``register_last()``. All handlers registered with ``register_first()`` are called before handlers registered with ``register()`` which are called before handlers registered with ``register_last()``. """ self._verify_and_register(event_name, handler, unique_id, register_method=self._register, unique_id_uses_count=unique_id_uses_count) def register_first(self, event_name, handler, unique_id=None, unique_id_uses_count=False): """Register an event handler to be called first for an event. All event handlers registered with ``register_first()`` will be called before handlers registered with ``register()`` and ``register_last()``. """ self._verify_and_register(event_name, handler, unique_id, register_method=self._register_first, unique_id_uses_count=unique_id_uses_count) def register_last(self, event_name, handler, unique_id=None, unique_id_uses_count=False): """Register an event handler to be called last for an event. All event handlers registered with ``register_last()`` will be called after handlers registered with ``register_first()`` and ``register()``. """ self._verify_and_register(event_name, handler, unique_id, register_method=self._register_last, unique_id_uses_count=unique_id_uses_count) def _verify_and_register(self, event_name, handler, unique_id, register_method, unique_id_uses_count): self._verify_is_callable(handler) self._verify_accept_kwargs(handler) register_method(event_name, handler, unique_id, unique_id_uses_count) def unregister(self, event_name, handler=None, unique_id=None, unique_id_uses_count=False): """Unregister an event handler for a given event. If no ``unique_id`` was given during registration, then the first instance of the event handler is removed (if the event handler has been registered multiple times). """ pass def _verify_is_callable(self, func): if not six.callable(func): raise ValueError("Event handler %s must be callable." % func) def _verify_accept_kwargs(self, func): """Verifies a callable accepts kwargs :type func: callable :param func: A callable object. :returns: True, if ``func`` accepts kwargs, otherwise False. """ try: if not accepts_kwargs(func): raise ValueError("Event handler %s must accept keyword " "arguments (**kwargs)" % func) except TypeError: return False class HierarchicalEmitter(BaseEventHooks): def __init__(self): # We keep a reference to the handlers for quick # read only access (we never modify self._handlers). # A cache of event name to handler list. self._lookup_cache = {} self._handlers = _PrefixTrie() # This is used to ensure that unique_id's are only # registered once. self._unique_id_handlers = {} def _emit(self, event_name, kwargs, stop_on_response=False): """ Emit an event with optional keyword arguments. :type event_name: string :param event_name: Name of the event :type kwargs: dict :param kwargs: Arguments to be passed to the handler functions. :type stop_on_response: boolean :param stop_on_response: Whether to stop on the first non-None response. If False, then all handlers will be called. This is especially useful to handlers which mutate data and then want to stop propagation of the event. :rtype: list :return: List of (handler, response) tuples from all processed handlers. """ responses = [] # Invoke the event handlers from most specific # to least specific, each time stripping off a dot. handlers_to_call = self._lookup_cache.get(event_name) if handlers_to_call is None: handlers_to_call = self._handlers.prefix_search(event_name) self._lookup_cache[event_name] = handlers_to_call elif not handlers_to_call: # Short circuit and return an empty response is we have # no handlers to call. This is the common case where # for the majority of signals, nothing is listening. return [] kwargs['event_name'] = event_name responses = [] for handler in handlers_to_call: logger.debug('Event %s: calling handler %s', event_name, handler) response = handler(**kwargs) responses.append((handler, response)) if stop_on_response and response is not None: return responses return responses def emit(self, event_name, **kwargs): """ Emit an event by name with arguments passed as keyword args. >>> responses = emitter.emit( ... 'my-event.service.operation', arg1='one', arg2='two') :rtype: list :return: List of (handler, response) tuples from all processed handlers. """ return self._emit(event_name, kwargs) def emit_until_response(self, event_name, **kwargs): """ Emit an event by name with arguments passed as keyword args, until the first non-``None`` response is received. This method prevents subsequent handlers from being invoked. >>> handler, response = emitter.emit_until_response( 'my-event.service.operation', arg1='one', arg2='two') :rtype: tuple :return: The first (handler, response) tuple where the response is not ``None``, otherwise (``None``, ``None``). """ responses = self._emit(event_name, kwargs, stop_on_response=True) if responses: return responses[-1] else: return (None, None) def _register(self, event_name, handler, unique_id=None, unique_id_uses_count=False): self._register_section(event_name, handler, unique_id, unique_id_uses_count, section=_MIDDLE) def _register_first(self, event_name, handler, unique_id=None, unique_id_uses_count=False): self._register_section(event_name, handler, unique_id, unique_id_uses_count, section=_FIRST) def _register_last(self, event_name, handler, unique_id, unique_id_uses_count=False): self._register_section(event_name, handler, unique_id, unique_id_uses_count, section=_LAST) def _register_section(self, event_name, handler, unique_id, unique_id_uses_count, section): if unique_id is not None: if unique_id in self._unique_id_handlers: # We've already registered a handler using this unique_id # so we don't need to register it again. count = self._unique_id_handlers[unique_id].get('count', None) if unique_id_uses_count: if not count: raise ValueError( "Initial registration of unique id %s was " "specified to use a counter. Subsequent register " "calls to unique id must specify use of a counter " "as well." % unique_id) else: self._unique_id_handlers[unique_id]['count'] += 1 else: if count: raise ValueError( "Initial registration of unique id %s was " "specified to not use a counter. Subsequent " "register calls to unique id must specify not to " "use a counter as well." % unique_id) return else: # Note that the trie knows nothing about the unique # id. We track uniqueness in this class via the # _unique_id_handlers. self._handlers.append_item(event_name, handler, section=section) unique_id_handler_item = {'handler': handler} if unique_id_uses_count: unique_id_handler_item['count'] = 1 self._unique_id_handlers[unique_id] = unique_id_handler_item else: self._handlers.append_item(event_name, handler, section=section) # Super simple caching strategy for now, if we change the registrations # clear the cache. This has the opportunity for smarter invalidations. self._lookup_cache = {} def unregister(self, event_name, handler=None, unique_id=None, unique_id_uses_count=False): if unique_id is not None: try: count = self._unique_id_handlers[unique_id].get('count', None) except KeyError: # There's no handler matching that unique_id so we have # nothing to unregister. return if unique_id_uses_count: if count is None: raise ValueError( "Initial registration of unique id %s was specified to " "use a counter. Subsequent unregister calls to unique " "id must specify use of a counter as well." % unique_id) elif count == 1: handler = self._unique_id_handlers.pop(unique_id)['handler'] else: self._unique_id_handlers[unique_id]['count'] -= 1 return else: if count: raise ValueError( "Initial registration of unique id %s was specified " "to not use a counter. Subsequent unregister calls " "to unique id must specify not to use a counter as " "well." % unique_id) handler = self._unique_id_handlers.pop(unique_id)['handler'] try: self._handlers.remove_item(event_name, handler) self._lookup_cache = {} except ValueError: pass def __copy__(self): new_instance = self.__class__() new_state = self.__dict__.copy() new_state['_handlers'] = copy.copy(self._handlers) new_state['_unique_id_handlers'] = copy.copy(self._unique_id_handlers) new_instance.__dict__ = new_state return new_instance class EventAliaser(BaseEventHooks): def __init__(self, event_emitter, event_aliases=None): self._event_aliases = event_aliases if event_aliases is None: self._event_aliases = EVENT_ALIASES self._emitter = event_emitter def emit(self, event_name, **kwargs): aliased_event_name = self._alias_event_name(event_name) return self._emitter.emit(aliased_event_name, **kwargs) def emit_until_response(self, event_name, **kwargs): aliased_event_name = self._alias_event_name(event_name) return self._emitter.emit_until_response(aliased_event_name, **kwargs) def register(self, event_name, handler, unique_id=None, unique_id_uses_count=False): aliased_event_name = self._alias_event_name(event_name) return self._emitter.register( aliased_event_name, handler, unique_id, unique_id_uses_count ) def register_first(self, event_name, handler, unique_id=None, unique_id_uses_count=False): aliased_event_name = self._alias_event_name(event_name) return self._emitter.register_first( aliased_event_name, handler, unique_id, unique_id_uses_count ) def register_last(self, event_name, handler, unique_id=None, unique_id_uses_count=False): aliased_event_name = self._alias_event_name(event_name) return self._emitter.register_last( aliased_event_name, handler, unique_id, unique_id_uses_count ) def unregister(self, event_name, handler=None, unique_id=None, unique_id_uses_count=False): aliased_event_name = self._alias_event_name(event_name) return self._emitter.unregister( aliased_event_name, handler, unique_id, unique_id_uses_count ) def _alias_event_name(self, event_name): for old_part, new_part in self._event_aliases.items(): # We can't simply do a string replace for everything, otherwise we # might end up translating substrings that we never intended to # translate. When there aren't any dots in the old event name # part, then we can quickly replace the item in the list if it's # there. event_parts = event_name.split('.') if '.' not in old_part: try: # Theoretically a given event name could have the same part # repeated, but in practice this doesn't happen event_parts[event_parts.index(old_part)] = new_part except ValueError: continue # If there's dots in the name, it gets more complicated. Now we # have to replace multiple sections of the original event. elif old_part in event_name: old_parts = old_part.split('.') self._replace_subsection(event_parts, old_parts, new_part) else: continue new_name = '.'.join(event_parts) logger.debug("Changing event name from %s to %s" % ( event_name, new_name )) return new_name return event_name def _replace_subsection(self, sections, old_parts, new_part): for i in range(len(sections)): if sections[i] == old_parts[0] and \ sections[i:i+len(old_parts)] == old_parts: sections[i:i+len(old_parts)] = [new_part] return def __copy__(self): return self.__class__( copy.copy(self._emitter), copy.copy(self._event_aliases) ) class _PrefixTrie(object): """Specialized prefix trie that handles wildcards. The prefixes in this case are based on dot separated names so 'foo.bar.baz' is:: foo -> bar -> baz Wildcard support just means that having a key such as 'foo.bar.*.baz' will be matched with a call to ``get_items(key='foo.bar.ANYTHING.baz')``. You can think of this prefix trie as the equivalent as defaultdict(list), except that it can do prefix searches: foo.bar.baz -> A foo.bar -> B foo -> C Calling ``get_items('foo.bar.baz')`` will return [A + B + C], from most specific to least specific. """ def __init__(self): # Each dictionary can be though of as a node, where a node # has values associated with the node, and children is a link # to more nodes. So 'foo.bar' would have a 'foo' node with # a 'bar' node as a child of foo. # {'foo': {'children': {'bar': {...}}}}. self._root = {'chunk': None, 'children': {}, 'values': None} def append_item(self, key, value, section=_MIDDLE): """Add an item to a key. If a value is already associated with that key, the new value is appended to the list for the key. """ key_parts = key.split('.') current = self._root for part in key_parts: if part not in current['children']: new_child = {'chunk': part, 'values': None, 'children': {}} current['children'][part] = new_child current = new_child else: current = current['children'][part] if current['values'] is None: current['values'] = NodeList([], [], []) current['values'][section].append(value) def prefix_search(self, key): """Collect all items that are prefixes of key. Prefix in this case are delineated by '.' characters so 'foo.bar.baz' is a 3 chunk sequence of 3 "prefixes" ( "foo", "bar", and "baz"). """ collected = deque() key_parts = key.split('.') current = self._root self._get_items(current, key_parts, collected, 0) return collected def _get_items(self, starting_node, key_parts, collected, starting_index): stack = [(starting_node, starting_index)] key_parts_len = len(key_parts) # Traverse down the nodes, where at each level we add the # next part from key_parts as well as the wildcard element '*'. # This means for each node we see we potentially add two more # elements to our stack. while stack: current_node, index = stack.pop() if current_node['values']: # We're using extendleft because we want # the values associated with the node furthest # from the root to come before nodes closer # to the root. extendleft() also adds its items # in right-left order so .extendleft([1, 2, 3]) # will result in final_list = [3, 2, 1], which is # why we reverse the lists. node_list = current_node['values'] complete_order = (node_list.first + node_list.middle + node_list.last) collected.extendleft(reversed(complete_order)) if not index == key_parts_len: children = current_node['children'] directs = children.get(key_parts[index]) wildcard = children.get('*') next_index = index + 1 if wildcard is not None: stack.append((wildcard, next_index)) if directs is not None: stack.append((directs, next_index)) def remove_item(self, key, value): """Remove an item associated with a key. If the value is not associated with the key a ``ValueError`` will be raised. If the key does not exist in the trie, a ``ValueError`` will be raised. """ key_parts = key.split('.') current = self._root self._remove_item(current, key_parts, value, index=0) def _remove_item(self, current_node, key_parts, value, index): if current_node is None: return elif index < len(key_parts): next_node = current_node['children'].get(key_parts[index]) if next_node is not None: self._remove_item(next_node, key_parts, value, index + 1) if index == len(key_parts) - 1: node_list = next_node['values'] if value in node_list.first: node_list.first.remove(value) elif value in node_list.middle: node_list.middle.remove(value) elif value in node_list.last: node_list.last.remove(value) if not next_node['children'] and not next_node['values']: # Then this is a leaf node with no values so # we can just delete this link from the parent node. # This makes subsequent search faster in the case # where a key does not exist. del current_node['children'][key_parts[index]] else: raise ValueError( "key is not in trie: %s" % '.'.join(key_parts)) def __copy__(self): # The fact that we're using a nested dict under the covers # is an implementation detail, and the user shouldn't have # to know that they'd normally need a deepcopy so we expose # __copy__ instead of __deepcopy__. new_copy = self.__class__() copied_attrs = self._recursive_copy(self.__dict__) new_copy.__dict__ = copied_attrs return new_copy def _recursive_copy(self, node): # We can't use copy.deepcopy because we actually only want to copy # the structure of the trie, not the handlers themselves. # Each node has a chunk, children, and values. copied_node = {} for key, value in node.items(): if isinstance(value, NodeList): copied_node[key] = copy.copy(value) elif isinstance(value, dict): copied_node[key] = self._recursive_copy(value) else: copied_node[key] = value return copied_node
apache-2.0
[ 3, 1898, 6029, 13, 7280, 14347, 14, 957, 12, 3277, 14, 503, 2399, 29172, 2335, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3471, 2047, 199, 3, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 437, 1331, 402, 199, 3, 314, 844, 365, 16180, 737, 199, 3, 199, 3, 1455, 921, 7231, 14, 15144, 14, 957, 15, 3796, 18, 14, 16, 15, 199, 3, 199, 3, 503, 315, 314, 298, 1682, 2, 570, 23073, 642, 570, 14, 961, 570, 365, 199, 3, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 199, 3, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 844, 367, 314, 2488, 199, 3, 2637, 4210, 3443, 436, 4204, 1334, 314, 844, 14, 199, 646, 1331, 199, 646, 2050, 199, 504, 5055, 492, 10018, 12, 15782, 12, 12863, 199, 504, 21199, 14, 5819, 492, 11479, 63, 958, 12, 3816, 199, 504, 21199, 14, 1208, 492, 6461, 63, 12644, 654, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 63, 29166, 275, 12863, 360, 29166, 297, 788, 2246, 297, 283, 14885, 297, 283, 2019, 1105, 199, 63, 12903, 275, 378, 199, 63, 45, 13016, 275, 413, 199, 63, 16901, 275, 499, 421, 199, 533, 5013, 1296, 1547, 29166, 304, 339, 347, 636, 1574, 721, 277, 304, 267, 1642, 63, 1574, 275, 1331, 14, 1574, 8, 277, 14, 2246, 9, 267, 12180, 63, 1574, 275, 1331, 14, 1574, 8, 277, 14, 14885, 9, 267, 2061, 63, 1574, 275, 1331, 14, 1574, 8, 277, 14, 2019, 9, 267, 8876, 275, 5013, 1296, 8, 2246, 63, 1574, 12, 12180, 63, 1574, 12, 2061, 63, 1574, 9, 267, 372, 8876, 421, 199, 318, 1642, 63, 2865, 63, 3592, 63, 1310, 8, 10360, 12, 849, 29, 403, 304, 272, 408, 6591, 1642, 2222, 488, 1177, 315, 282, 769, 402, 6346, 14, 339, 961, 805, 883, 506, 1202, 370, 2342, 314, 1642, 2222, 488, 1177, 687, 272, 8297, 8539, 370, 376, 1566, 14, 221, 961, 365, 2997, 340, 1265, 787, 22201, 272, 315, 314, 2138, 9320, 687, 1566, 8297, 14, 5679, 4503, 447, 398, 870, 8, 2246, 63, 2865, 63, 3592, 63, 1310, 7694, 1532, 17, 12, 488, 395, 334, 1532, 18, 12, 283, 1421, 659, 4318, 334, 1532, 19, 12, 283, 1700, 358, 2459, 267, 327, 961, 911, 870, 283, 1421, 7, 339, 520, 466, 9320, 26, 769, 402, 6346, 272, 520, 635, 9320, 26, 710, 9320, 687, 314, 1124, 2390, 8481, 83, 14, 8159, 1040, 1083, 14, 267, 961, 365, 282, 769, 402, 6346, 12, 436, 1924, 2008, 365, 267, 334, 2232, 12, 3016, 63, 1310, 680, 339, 520, 635, 849, 26, 982, 949, 2222, 13, 403, 9320, 787, 1911, 12, 2066, 642, 849, 267, 574, 911, 506, 2138, 14, 339, 520, 1107, 26, 710, 1642, 2222, 13, 403, 1177, 315, 314, 769, 402, 6346, 14, 339, 408, 272, 367, 1177, 315, 9320, 26, 267, 340, 1177, 59, 17, 61, 365, 440, 488, 26, 288, 372, 1177, 59, 17, 61, 272, 372, 849, 421, 199, 533, 3523, 2390, 8481, 83, 8, 785, 304, 272, 347, 8689, 8, 277, 12, 1566, 63, 354, 12, 1011, 958, 304, 267, 408, 2176, 1006, 8297, 30400, 370, 376, 1566, 14, 398, 520, 466, 1566, 63, 354, 26, 620, 267, 520, 635, 1566, 63, 354, 26, 710, 536, 402, 314, 1566, 370, 8689, 14, 398, 520, 466, 1011, 958, 26, 1211, 267, 520, 635, 1011, 958, 26, 1952, 8734, 2074, 370, 986, 4012, 370, 314, 288, 30400, 8297, 14, 221, 710, 1124, 1430, 63, 354, 1040, 911, 506, 26121, 288, 1901, 314, 2074, 880, 652, 1159, 440, 1279, 823, 695, 370, 1050, 642, 370, 1011, 958, 14, 398, 520, 4500, 26, 769, 402, 6346, 267, 520, 1107, 26, 437, 769, 402, 15475, 2232, 63, 1532, 12, 3016, 63, 1532, 63, 1107, 63, 585, 9719, 398, 408, 267, 372, 942, 339, 347, 2274, 8, 277, 12, 1566, 63, 354, 12, 3016, 12, 3747, 63, 344, 29, 403, 12, 326, 3747, 63, 344, 63, 5589, 63, 835, 29, 797, 304, 267, 408, 7099, 376, 1566, 3016, 367, 282, 1627, 1566, 14, 398, 982, 282, 1124, 3235, 63, 344, 1040, 365, 1627, 12, 314, 3016, 911, 440, 506, 7264, 267, 340, 282, 3016, 543, 314, 1124, 3235, 63, 344, 1040, 965, 2575, 2757, 7264, 14, 398, 18599, 83, 787, 2797, 315, 314, 1865, 2985, 1172, 2757, 7264, 14, 267, 3390, 8297, 883, 2597, 506, 7264, 543, 1124, 2683, 63, 2246, 8497, 267, 436, 1124, 2683, 63, 2019, 28566, 221, 2900, 8297, 7264, 543, 267, 1124, 2683, 63, 2246, 8497, 787, 2797, 2544, 8297, 7264, 267, 543, 1124, 2683, 8497, 1314, 787, 2797, 2544, 8297, 7264, 267, 543, 1124, 2683, 63, 2019, 28566, 398, 408, 267, 291, 423, 4712, 63, 460, 63, 2683, 8, 1430, 63, 354, 12, 3016, 12, 3747, 63, 344, 12, 3303, 2274, 63, 765, 29, 277, 423, 2683, 12, 3303, 3747, 63, 344, 63, 5589, 63, 835, 29, 3235, 63, 344, 63, 5589, 63, 835, 9, 339, 347, 2274, 63, 2246, 8, 277, 12, 1566, 63, 354, 12, 3016, 12, 3747, 63, 344, 29, 403, 12, 2432, 3747, 63, 344, 63, 5589, 63, 835, 29, 797, 304, 267, 408, 7099, 376, 1566, 3016, 370, 506, 2797, 1642, 367, 376, 1566, 14, 398, 2900, 1566, 8297, 7264, 543, 1124, 2683, 63, 2246, 8497, 911, 267, 506, 2797, 2544, 8297, 7264, 543, 1124, 2683, 8497, 436, 267, 1124, 2683, 63, 2019, 28566, 398, 408, 267, 291, 423, 4712, 63, 460, 63, 2683, 8, 1430, 63, 354, 12, 3016, 12, 3747, 63, 344, 12, 3303, 2274, 63, 765, 29, 277, 423, 2683, 63, 2246, 12, 3303, 3747, 63, 344, 63, 5589, 63, 835, 29, 3235, 63, 344, 63, 5589, 63, 835, 9, 339, 347, 2274, 63, 2019, 8, 277, 12, 1566, 63, 354, 12, 3016, 12, 3747, 63, 344, 29, 403, 12, 1993, 3747, 63, 344, 63, 5589, 63, 835, 29, 797, 304, 267, 408, 7099, 376, 1566, 3016, 370, 506, 2797, 2061, 367, 376, 1566, 14, 398, 2900, 1566, 8297, 7264, 543, 1124, 2683 ]
[ 1898, 6029, 13, 7280, 14347, 14, 957, 12, 3277, 14, 503, 2399, 29172, 2335, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3471, 2047, 199, 3, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 437, 1331, 402, 199, 3, 314, 844, 365, 16180, 737, 199, 3, 199, 3, 1455, 921, 7231, 14, 15144, 14, 957, 15, 3796, 18, 14, 16, 15, 199, 3, 199, 3, 503, 315, 314, 298, 1682, 2, 570, 23073, 642, 570, 14, 961, 570, 365, 199, 3, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 199, 3, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 844, 367, 314, 2488, 199, 3, 2637, 4210, 3443, 436, 4204, 1334, 314, 844, 14, 199, 646, 1331, 199, 646, 2050, 199, 504, 5055, 492, 10018, 12, 15782, 12, 12863, 199, 504, 21199, 14, 5819, 492, 11479, 63, 958, 12, 3816, 199, 504, 21199, 14, 1208, 492, 6461, 63, 12644, 654, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 63, 29166, 275, 12863, 360, 29166, 297, 788, 2246, 297, 283, 14885, 297, 283, 2019, 1105, 199, 63, 12903, 275, 378, 199, 63, 45, 13016, 275, 413, 199, 63, 16901, 275, 499, 421, 199, 533, 5013, 1296, 1547, 29166, 304, 339, 347, 636, 1574, 721, 277, 304, 267, 1642, 63, 1574, 275, 1331, 14, 1574, 8, 277, 14, 2246, 9, 267, 12180, 63, 1574, 275, 1331, 14, 1574, 8, 277, 14, 14885, 9, 267, 2061, 63, 1574, 275, 1331, 14, 1574, 8, 277, 14, 2019, 9, 267, 8876, 275, 5013, 1296, 8, 2246, 63, 1574, 12, 12180, 63, 1574, 12, 2061, 63, 1574, 9, 267, 372, 8876, 421, 199, 318, 1642, 63, 2865, 63, 3592, 63, 1310, 8, 10360, 12, 849, 29, 403, 304, 272, 408, 6591, 1642, 2222, 488, 1177, 315, 282, 769, 402, 6346, 14, 339, 961, 805, 883, 506, 1202, 370, 2342, 314, 1642, 2222, 488, 1177, 687, 272, 8297, 8539, 370, 376, 1566, 14, 221, 961, 365, 2997, 340, 1265, 787, 22201, 272, 315, 314, 2138, 9320, 687, 1566, 8297, 14, 5679, 4503, 447, 398, 870, 8, 2246, 63, 2865, 63, 3592, 63, 1310, 7694, 1532, 17, 12, 488, 395, 334, 1532, 18, 12, 283, 1421, 659, 4318, 334, 1532, 19, 12, 283, 1700, 358, 2459, 267, 327, 961, 911, 870, 283, 1421, 7, 339, 520, 466, 9320, 26, 769, 402, 6346, 272, 520, 635, 9320, 26, 710, 9320, 687, 314, 1124, 2390, 8481, 83, 14, 8159, 1040, 1083, 14, 267, 961, 365, 282, 769, 402, 6346, 12, 436, 1924, 2008, 365, 267, 334, 2232, 12, 3016, 63, 1310, 680, 339, 520, 635, 849, 26, 982, 949, 2222, 13, 403, 9320, 787, 1911, 12, 2066, 642, 849, 267, 574, 911, 506, 2138, 14, 339, 520, 1107, 26, 710, 1642, 2222, 13, 403, 1177, 315, 314, 769, 402, 6346, 14, 339, 408, 272, 367, 1177, 315, 9320, 26, 267, 340, 1177, 59, 17, 61, 365, 440, 488, 26, 288, 372, 1177, 59, 17, 61, 272, 372, 849, 421, 199, 533, 3523, 2390, 8481, 83, 8, 785, 304, 272, 347, 8689, 8, 277, 12, 1566, 63, 354, 12, 1011, 958, 304, 267, 408, 2176, 1006, 8297, 30400, 370, 376, 1566, 14, 398, 520, 466, 1566, 63, 354, 26, 620, 267, 520, 635, 1566, 63, 354, 26, 710, 536, 402, 314, 1566, 370, 8689, 14, 398, 520, 466, 1011, 958, 26, 1211, 267, 520, 635, 1011, 958, 26, 1952, 8734, 2074, 370, 986, 4012, 370, 314, 288, 30400, 8297, 14, 221, 710, 1124, 1430, 63, 354, 1040, 911, 506, 26121, 288, 1901, 314, 2074, 880, 652, 1159, 440, 1279, 823, 695, 370, 1050, 642, 370, 1011, 958, 14, 398, 520, 4500, 26, 769, 402, 6346, 267, 520, 1107, 26, 437, 769, 402, 15475, 2232, 63, 1532, 12, 3016, 63, 1532, 63, 1107, 63, 585, 9719, 398, 408, 267, 372, 942, 339, 347, 2274, 8, 277, 12, 1566, 63, 354, 12, 3016, 12, 3747, 63, 344, 29, 403, 12, 326, 3747, 63, 344, 63, 5589, 63, 835, 29, 797, 304, 267, 408, 7099, 376, 1566, 3016, 367, 282, 1627, 1566, 14, 398, 982, 282, 1124, 3235, 63, 344, 1040, 365, 1627, 12, 314, 3016, 911, 440, 506, 7264, 267, 340, 282, 3016, 543, 314, 1124, 3235, 63, 344, 1040, 965, 2575, 2757, 7264, 14, 398, 18599, 83, 787, 2797, 315, 314, 1865, 2985, 1172, 2757, 7264, 14, 267, 3390, 8297, 883, 2597, 506, 7264, 543, 1124, 2683, 63, 2246, 8497, 267, 436, 1124, 2683, 63, 2019, 28566, 221, 2900, 8297, 7264, 543, 267, 1124, 2683, 63, 2246, 8497, 787, 2797, 2544, 8297, 7264, 267, 543, 1124, 2683, 8497, 1314, 787, 2797, 2544, 8297, 7264, 267, 543, 1124, 2683, 63, 2019, 28566, 398, 408, 267, 291, 423, 4712, 63, 460, 63, 2683, 8, 1430, 63, 354, 12, 3016, 12, 3747, 63, 344, 12, 3303, 2274, 63, 765, 29, 277, 423, 2683, 12, 3303, 3747, 63, 344, 63, 5589, 63, 835, 29, 3235, 63, 344, 63, 5589, 63, 835, 9, 339, 347, 2274, 63, 2246, 8, 277, 12, 1566, 63, 354, 12, 3016, 12, 3747, 63, 344, 29, 403, 12, 2432, 3747, 63, 344, 63, 5589, 63, 835, 29, 797, 304, 267, 408, 7099, 376, 1566, 3016, 370, 506, 2797, 1642, 367, 376, 1566, 14, 398, 2900, 1566, 8297, 7264, 543, 1124, 2683, 63, 2246, 8497, 911, 267, 506, 2797, 2544, 8297, 7264, 543, 1124, 2683, 8497, 436, 267, 1124, 2683, 63, 2019, 28566, 398, 408, 267, 291, 423, 4712, 63, 460, 63, 2683, 8, 1430, 63, 354, 12, 3016, 12, 3747, 63, 344, 12, 3303, 2274, 63, 765, 29, 277, 423, 2683, 63, 2246, 12, 3303, 3747, 63, 344, 63, 5589, 63, 835, 29, 3235, 63, 344, 63, 5589, 63, 835, 9, 339, 347, 2274, 63, 2019, 8, 277, 12, 1566, 63, 354, 12, 3016, 12, 3747, 63, 344, 29, 403, 12, 1993, 3747, 63, 344, 63, 5589, 63, 835, 29, 797, 304, 267, 408, 7099, 376, 1566, 3016, 370, 506, 2797, 2061, 367, 376, 1566, 14, 398, 2900, 1566, 8297, 7264, 543, 1124, 2683, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
jonparrott/gcloud-python
storage/tests/unit/test_blob.py
2
123557
# Copyright 2014 Google LLC # # 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 base64 import datetime import hashlib import io import json import os import tempfile import unittest import google.cloud.storage.blob import mock import six from six.moves import http_client def _make_credentials(): import google.auth.credentials return mock.Mock(spec=google.auth.credentials.Credentials) class Test_Blob(unittest.TestCase): @staticmethod def _make_one(*args, **kw): from google.cloud.storage.blob import Blob properties = kw.pop('properties', {}) blob = Blob(*args, **kw) blob._properties.update(properties) return blob def test_ctor_wo_encryption_key(self): BLOB_NAME = 'blob-name' bucket = _Bucket() properties = {'key': 'value'} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertIs(blob.bucket, bucket) self.assertEqual(blob.name, BLOB_NAME) self.assertEqual(blob._properties, properties) self.assertFalse(blob._acl.loaded) self.assertIs(blob._acl.blob, blob) self.assertEqual(blob._encryption_key, None) self.assertEqual(blob.kms_key_name, None) def test_ctor_with_encoded_unicode(self): blob_name = b'wet \xe2\x9b\xb5' blob = self._make_one(blob_name, bucket=None) unicode_name = u'wet \N{sailboat}' self.assertNotIsInstance(blob.name, bytes) self.assertIsInstance(blob.name, six.text_type) self.assertEqual(blob.name, unicode_name) def test_ctor_w_encryption_key(self): KEY = b'01234567890123456789012345678901' # 32 bytes BLOB_NAME = 'blob-name' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket, encryption_key=KEY) self.assertEqual(blob._encryption_key, KEY) self.assertEqual(blob.kms_key_name, None) def test_ctor_w_kms_key_name_and_encryption_key(self): KEY = b'01234567890123456789012345678901' # 32 bytes KMS_RESOURCE = ( "projects/test-project-123/" "locations/us/" "keyRings/test-ring/" "cryptoKeys/test-key" ) BLOB_NAME = 'blob-name' bucket = _Bucket() with self.assertRaises(ValueError): self._make_one( BLOB_NAME, bucket=bucket, encryption_key=KEY, kms_key_name=KMS_RESOURCE) def test_ctor_w_kms_key_name(self): KMS_RESOURCE = ( "projects/test-project-123/" "locations/us/" "keyRings/test-ring/" "cryptoKeys/test-key" ) BLOB_NAME = 'blob-name' bucket = _Bucket() blob = self._make_one( BLOB_NAME, bucket=bucket, kms_key_name=KMS_RESOURCE) self.assertEqual(blob._encryption_key, None) self.assertEqual(blob.kms_key_name, KMS_RESOURCE) def _set_properties_helper(self, kms_key_name=None): import datetime from google.cloud._helpers import UTC from google.cloud._helpers import _RFC3339_MICROS now = datetime.datetime.utcnow().replace(tzinfo=UTC) NOW = now.strftime(_RFC3339_MICROS) BLOB_NAME = 'blob-name' GENERATION = 12345 BLOB_ID = 'name/{}/{}'.format(BLOB_NAME, GENERATION) SELF_LINK = 'http://example.com/self/' METAGENERATION = 23456 SIZE = 12345 MD5_HASH = 'DEADBEEF' MEDIA_LINK = 'http://example.com/media/' ENTITY = 'project-owner-12345' ENTITY_ID = '23456' CRC32C = 'FACE0DAC' COMPONENT_COUNT = 2 ETAG = 'ETAG' resource = { 'id': BLOB_ID, 'selfLink': SELF_LINK, 'generation': GENERATION, 'metageneration': METAGENERATION, 'contentType': 'text/plain', 'timeCreated': NOW, 'updated': NOW, 'timeDeleted': NOW, 'storageClass': 'NEARLINE', 'timeStorageClassUpdated': NOW, 'size': SIZE, 'md5Hash': MD5_HASH, 'mediaLink': MEDIA_LINK, 'contentEncoding': 'gzip', 'contentDisposition': 'inline', 'contentLanguage': 'en-US', 'cacheControl': 'private', 'metadata': { 'foo': 'Foo', }, 'owner': { 'entity': ENTITY, 'entityId': ENTITY_ID, }, 'crc32c': CRC32C, 'componentCount': COMPONENT_COUNT, 'etag': ETAG, } if kms_key_name is not None: resource['kmsKeyName'] = kms_key_name bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) blob._set_properties(resource) self.assertEqual(blob.id, BLOB_ID) self.assertEqual(blob.self_link, SELF_LINK) self.assertEqual(blob.generation, GENERATION) self.assertEqual(blob.metageneration, METAGENERATION) self.assertEqual(blob.content_type, 'text/plain') self.assertEqual(blob.time_created, now) self.assertEqual(blob.updated, now) self.assertEqual(blob.time_deleted, now) self.assertEqual(blob.storage_class, 'NEARLINE') self.assertEqual(blob.size, SIZE) self.assertEqual(blob.md5_hash, MD5_HASH) self.assertEqual(blob.media_link, MEDIA_LINK) self.assertEqual(blob.content_encoding, 'gzip') self.assertEqual(blob.content_disposition, 'inline') self.assertEqual(blob.content_language, 'en-US') self.assertEqual(blob.cache_control, 'private') self.assertEqual(blob.metadata, {'foo': 'Foo'}) self.assertEqual(blob.owner, {'entity': ENTITY, 'entityId': ENTITY_ID}) self.assertEqual(blob.crc32c, CRC32C) self.assertEqual(blob.component_count, COMPONENT_COUNT) self.assertEqual(blob.etag, ETAG) if kms_key_name is not None: self.assertEqual(blob.kms_key_name, kms_key_name) else: self.assertIsNone(blob.kms_key_name) def test__set_properties_wo_kms_key_name(self): self._set_properties_helper() def test__set_properties_w_kms_key_name(self): kms_resource = ( "projects/test-project-123/" "locations/us/" "keyRings/test-ring/" "cryptoKeys/test-key" ) self._set_properties_helper(kms_key_name=kms_resource) def test_chunk_size_ctor(self): from google.cloud.storage.blob import Blob BLOB_NAME = 'blob-name' BUCKET = object() chunk_size = 10 * Blob._CHUNK_SIZE_MULTIPLE blob = self._make_one(BLOB_NAME, bucket=BUCKET, chunk_size=chunk_size) self.assertEqual(blob._chunk_size, chunk_size) def test_chunk_size_getter(self): BLOB_NAME = 'blob-name' BUCKET = object() blob = self._make_one(BLOB_NAME, bucket=BUCKET) self.assertIsNone(blob.chunk_size) VALUE = object() blob._chunk_size = VALUE self.assertIs(blob.chunk_size, VALUE) def test_chunk_size_setter(self): BLOB_NAME = 'blob-name' BUCKET = object() blob = self._make_one(BLOB_NAME, bucket=BUCKET) self.assertIsNone(blob._chunk_size) blob._CHUNK_SIZE_MULTIPLE = 10 blob.chunk_size = 20 self.assertEqual(blob._chunk_size, 20) def test_chunk_size_setter_bad_value(self): BLOB_NAME = 'blob-name' BUCKET = object() blob = self._make_one(BLOB_NAME, bucket=BUCKET) self.assertIsNone(blob._chunk_size) blob._CHUNK_SIZE_MULTIPLE = 10 with self.assertRaises(ValueError): blob.chunk_size = 11 def test_acl_property(self): from google.cloud.storage.acl import ObjectACL fake_bucket = _Bucket() blob = self._make_one(u'name', bucket=fake_bucket) acl = blob.acl self.assertIsInstance(acl, ObjectACL) self.assertIs(acl, blob._acl) def test_path_bad_bucket(self): fake_bucket = object() name = u'blob-name' blob = self._make_one(name, bucket=fake_bucket) self.assertRaises(AttributeError, getattr, blob, 'path') def test_path_no_name(self): bucket = _Bucket() blob = self._make_one(u'', bucket=bucket) self.assertRaises(ValueError, getattr, blob, 'path') def test_path_normal(self): BLOB_NAME = 'blob-name' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertEqual(blob.path, '/b/name/o/%s' % BLOB_NAME) def test_path_w_slash_in_name(self): BLOB_NAME = 'parent/child' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertEqual(blob.path, '/b/name/o/parent%2Fchild') def test_path_with_non_ascii(self): blob_name = u'Caf\xe9' bucket = _Bucket() blob = self._make_one(blob_name, bucket=bucket) self.assertEqual(blob.path, '/b/name/o/Caf%C3%A9') def test_client(self): blob_name = 'BLOB' bucket = _Bucket() blob = self._make_one(blob_name, bucket=bucket) self.assertIs(blob.client, bucket.client) def test_user_project(self): user_project = 'user-project-123' blob_name = 'BLOB' bucket = _Bucket(user_project=user_project) blob = self._make_one(blob_name, bucket=bucket) self.assertEqual(blob.user_project, user_project) def test_public_url(self): BLOB_NAME = 'blob-name' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertEqual(blob.public_url, 'https://storage.googleapis.com/name/%s' % BLOB_NAME) def test_public_url_w_slash_in_name(self): BLOB_NAME = 'parent/child' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertEqual( blob.public_url, 'https://storage.googleapis.com/name/parent/child') def test_public_url_with_non_ascii(self): blob_name = u'winter \N{snowman}' bucket = _Bucket() blob = self._make_one(blob_name, bucket=bucket) expected_url = 'https://storage.googleapis.com/name/winter%20%E2%98%83' self.assertEqual(blob.public_url, expected_url) def _basic_generate_signed_url_helper(self, credentials=None): BLOB_NAME = 'blob-name' EXPIRATION = '2014-10-16T20:34:37.000Z' connection = _Connection() client = _Client(connection) bucket = _Bucket(client) blob = self._make_one(BLOB_NAME, bucket=bucket) URI = ('http://example.com/abucket/a-blob-name?Signature=DEADBEEF' '&Expiration=2014-10-16T20:34:37.000Z') SIGNER = _Signer() with mock.patch('google.cloud.storage.blob.generate_signed_url', new=SIGNER): signed_uri = blob.generate_signed_url(EXPIRATION, credentials=credentials) self.assertEqual(signed_uri, URI) PATH = '/name/%s' % (BLOB_NAME,) if credentials is None: EXPECTED_ARGS = (_Connection.credentials,) else: EXPECTED_ARGS = (credentials,) EXPECTED_KWARGS = { 'api_access_endpoint': 'https://storage.googleapis.com', 'expiration': EXPIRATION, 'method': 'GET', 'resource': PATH, 'content_type': None, 'response_type': None, 'response_disposition': None, 'generation': None, } self.assertEqual(SIGNER._signed, [(EXPECTED_ARGS, EXPECTED_KWARGS)]) def test_generate_signed_url_w_default_method(self): self._basic_generate_signed_url_helper() def test_generate_signed_url_w_content_type(self): BLOB_NAME = 'blob-name' EXPIRATION = '2014-10-16T20:34:37.000Z' connection = _Connection() client = _Client(connection) bucket = _Bucket(client) blob = self._make_one(BLOB_NAME, bucket=bucket) URI = ('http://example.com/abucket/a-blob-name?Signature=DEADBEEF' '&Expiration=2014-10-16T20:34:37.000Z') SIGNER = _Signer() CONTENT_TYPE = "text/html" with mock.patch('google.cloud.storage.blob.generate_signed_url', new=SIGNER): signed_url = blob.generate_signed_url(EXPIRATION, content_type=CONTENT_TYPE) self.assertEqual(signed_url, URI) PATH = '/name/%s' % (BLOB_NAME,) EXPECTED_ARGS = (_Connection.credentials,) EXPECTED_KWARGS = { 'api_access_endpoint': 'https://storage.googleapis.com', 'expiration': EXPIRATION, 'method': 'GET', 'resource': PATH, 'content_type': CONTENT_TYPE, 'response_type': None, 'response_disposition': None, 'generation': None, } self.assertEqual(SIGNER._signed, [(EXPECTED_ARGS, EXPECTED_KWARGS)]) def test_generate_signed_url_w_credentials(self): credentials = object() self._basic_generate_signed_url_helper(credentials=credentials) def test_generate_signed_url_lowercase_method(self): BLOB_NAME = 'blob-name' EXPIRATION = '2014-10-16T20:34:37.000Z' connection = _Connection() client = _Client(connection) bucket = _Bucket(client) blob = self._make_one(BLOB_NAME, bucket=bucket) URI = (u'http://example.com/abucket/a-blob-name?Signature=DEADBEEF' u'&Expiration=2014-10-16T20:34:37.000Z') SIGNER = _Signer() with mock.patch('google.cloud.storage.blob.generate_signed_url', new=SIGNER): signed_url = blob.generate_signed_url(EXPIRATION, method='get') self.assertEqual(signed_url, URI) PATH = '/name/%s' % (BLOB_NAME,) EXPECTED_ARGS = (_Connection.credentials,) EXPECTED_KWARGS = { 'api_access_endpoint': 'https://storage.googleapis.com', 'expiration': EXPIRATION, 'method': 'GET', 'resource': PATH, 'content_type': None, 'response_type': None, 'response_disposition': None, 'generation': None, } self.assertEqual(SIGNER._signed, [(EXPECTED_ARGS, EXPECTED_KWARGS)]) def test_generate_signed_url_non_ascii(self): BLOB_NAME = u'\u0410\u043a\u043a\u043e\u0440\u0434\u044b.txt' EXPIRATION = '2014-10-16T20:34:37.000Z' connection = _Connection() client = _Client(connection) bucket = _Bucket(client) blob = self._make_one(BLOB_NAME, bucket=bucket) URI = (u'http://example.com/abucket/a-blob-name?Signature=DEADBEEF' u'&Expiration=2014-10-16T20:34:37.000Z') SIGNER = _Signer() with mock.patch('google.cloud.storage.blob.generate_signed_url', new=SIGNER): signed_url = blob.generate_signed_url(EXPIRATION) self.assertEqual(signed_url, URI) EXPECTED_ARGS = (_Connection.credentials,) EXPECTED_KWARGS = { 'api_access_endpoint': 'https://storage.googleapis.com', 'expiration': EXPIRATION, 'method': 'GET', 'resource': '/name/%D0%90%D0%BA%D0%BA%D0%BE%D1%80%D0%B4%D1%8B.txt', 'content_type': None, 'response_type': None, 'response_disposition': None, 'generation': None, } self.assertEqual(SIGNER._signed, [(EXPECTED_ARGS, EXPECTED_KWARGS)]) def test_generate_signed_url_w_slash_in_name(self): BLOB_NAME = 'parent/child' EXPIRATION = '2014-10-16T20:34:37.000Z' connection = _Connection() client = _Client(connection) bucket = _Bucket(client) blob = self._make_one(BLOB_NAME, bucket=bucket) URI = ('http://example.com/abucket/a-blob-name?Signature=DEADBEEF' '&Expiration=2014-10-16T20:34:37.000Z') SIGNER = _Signer() with mock.patch('google.cloud.storage.blob.generate_signed_url', new=SIGNER): signed_url = blob.generate_signed_url(EXPIRATION) self.assertEqual(signed_url, URI) EXPECTED_ARGS = (_Connection.credentials,) EXPECTED_KWARGS = { 'api_access_endpoint': 'https://storage.googleapis.com', 'expiration': EXPIRATION, 'method': 'GET', 'resource': '/name/parent/child', 'content_type': None, 'response_type': None, 'response_disposition': None, 'generation': None, } self.assertEqual(SIGNER._signed, [(EXPECTED_ARGS, EXPECTED_KWARGS)]) def test_generate_signed_url_w_method_arg(self): BLOB_NAME = 'blob-name' EXPIRATION = '2014-10-16T20:34:37.000Z' connection = _Connection() client = _Client(connection) bucket = _Bucket(client) blob = self._make_one(BLOB_NAME, bucket=bucket) URI = ('http://example.com/abucket/a-blob-name?Signature=DEADBEEF' '&Expiration=2014-10-16T20:34:37.000Z') SIGNER = _Signer() with mock.patch('google.cloud.storage.blob.generate_signed_url', new=SIGNER): signed_uri = blob.generate_signed_url(EXPIRATION, method='POST') self.assertEqual(signed_uri, URI) PATH = '/name/%s' % (BLOB_NAME,) EXPECTED_ARGS = (_Connection.credentials,) EXPECTED_KWARGS = { 'api_access_endpoint': 'https://storage.googleapis.com', 'expiration': EXPIRATION, 'method': 'POST', 'resource': PATH, 'content_type': None, 'response_type': None, 'response_disposition': None, 'generation': None, } self.assertEqual(SIGNER._signed, [(EXPECTED_ARGS, EXPECTED_KWARGS)]) @mock.patch('google.cloud.storage._signing.get_signed_query_params', return_value={ 'GoogleAccessId': 'service-account-name', 'Expires': 12345, 'Signature': 'signed-data', }) def test_generate_resumable_signed_url(self, mock_get_signed_query_params): """ Verify correct behavior of resumable upload URL generation """ from google.cloud.storage._signing import get_expiration_seconds from google.cloud.storage._signing import generate_signed_url expiry = get_expiration_seconds(datetime.timedelta(hours=1)) signed_url = generate_signed_url( _make_credentials(), 'a-bucket', expiry, method='RESUMABLE' ) self.assertTrue(mock_get_signed_query_params.called) self.assertGreater(len(signed_url), 0) self.assertIn('a-bucket', signed_url) self.assertIn('GoogleAccessId', signed_url) self.assertIn('Expires', signed_url) self.assertIn('Signature', signed_url) def test_exists_miss(self): NONESUCH = 'nonesuch' not_found_response = ({'status': http_client.NOT_FOUND}, b'') connection = _Connection(not_found_response) client = _Client(connection) bucket = _Bucket(client) blob = self._make_one(NONESUCH, bucket=bucket) self.assertFalse(blob.exists()) self.assertEqual(len(connection._requested), 1) self.assertEqual(connection._requested[0], { 'method': 'GET', 'path': '/b/name/o/{}'.format(NONESUCH), 'query_params': {'fields': 'name'}, '_target_object': None, }) def test_exists_hit_w_user_project(self): BLOB_NAME = 'blob-name' USER_PROJECT = 'user-project-123' found_response = ({'status': http_client.OK}, b'') connection = _Connection(found_response) client = _Client(connection) bucket = _Bucket(client, user_project=USER_PROJECT) blob = self._make_one(BLOB_NAME, bucket=bucket) bucket._blobs[BLOB_NAME] = 1 self.assertTrue(blob.exists()) self.assertEqual(len(connection._requested), 1) self.assertEqual(connection._requested[0], { 'method': 'GET', 'path': '/b/name/o/{}'.format(BLOB_NAME), 'query_params': {'fields': 'name', 'userProject': USER_PROJECT}, '_target_object': None, }) def test_delete(self): BLOB_NAME = 'blob-name' not_found_response = ({'status': http_client.NOT_FOUND}, b'') connection = _Connection(not_found_response) client = _Client(connection) bucket = _Bucket(client) blob = self._make_one(BLOB_NAME, bucket=bucket) bucket._blobs[BLOB_NAME] = 1 blob.delete() self.assertFalse(blob.exists()) self.assertEqual(bucket._deleted, [(BLOB_NAME, None)]) def test__get_transport(self): client = mock.Mock(spec=[u'_credentials', '_http']) client._http = mock.sentinel.transport blob = self._make_one(u'blob-name', bucket=None) transport = blob._get_transport(client) self.assertIs(transport, mock.sentinel.transport) def test__get_download_url_with_media_link(self): blob_name = 'something.txt' bucket = _Bucket(name='IRRELEVANT') blob = self._make_one(blob_name, bucket=bucket) media_link = 'http://test.invalid' # Set the media link on the blob blob._properties['mediaLink'] = media_link download_url = blob._get_download_url() self.assertEqual(download_url, media_link) def test__get_download_url_with_media_link_w_user_project(self): blob_name = 'something.txt' user_project = 'user-project-123' bucket = _Bucket(name='IRRELEVANT', user_project=user_project) blob = self._make_one(blob_name, bucket=bucket) media_link = 'http://test.invalid' # Set the media link on the blob blob._properties['mediaLink'] = media_link download_url = blob._get_download_url() self.assertEqual( download_url, '{}?userProject={}'.format(media_link, user_project)) def test__get_download_url_on_the_fly(self): blob_name = 'bzzz-fly.txt' bucket = _Bucket(name='buhkit') blob = self._make_one(blob_name, bucket=bucket) self.assertIsNone(blob.media_link) download_url = blob._get_download_url() expected_url = ( 'https://www.googleapis.com/download/storage/v1/b/' 'buhkit/o/bzzz-fly.txt?alt=media') self.assertEqual(download_url, expected_url) def test__get_download_url_on_the_fly_with_generation(self): blob_name = 'pretend.txt' bucket = _Bucket(name='fictional') blob = self._make_one(blob_name, bucket=bucket) generation = 1493058489532987 # Set the media link on the blob blob._properties['generation'] = str(generation) self.assertIsNone(blob.media_link) download_url = blob._get_download_url() expected_url = ( 'https://www.googleapis.com/download/storage/v1/b/' 'fictional/o/pretend.txt?alt=media&generation=1493058489532987') self.assertEqual(download_url, expected_url) def test__get_download_url_on_the_fly_with_user_project(self): blob_name = 'pretend.txt' user_project = 'user-project-123' bucket = _Bucket(name='fictional', user_project=user_project) blob = self._make_one(blob_name, bucket=bucket) self.assertIsNone(blob.media_link) download_url = blob._get_download_url() expected_url = ( 'https://www.googleapis.com/download/storage/v1/b/' 'fictional/o/pretend.txt?alt=media&userProject={}'.format( user_project)) self.assertEqual(download_url, expected_url) def test__get_download_url_on_the_fly_with_kms_key_name(self): kms_resource = ( "projects/test-project-123/" "locations/us/" "keyRings/test-ring/" "cryptoKeys/test-key" ) blob_name = 'bzzz-fly.txt' bucket = _Bucket(name='buhkit') blob = self._make_one( blob_name, bucket=bucket, kms_key_name=kms_resource) self.assertIsNone(blob.media_link) download_url = blob._get_download_url() expected_url = ( 'https://www.googleapis.com/download/storage/v1/b/' 'buhkit/o/bzzz-fly.txt?alt=media') self.assertEqual(download_url, expected_url) @staticmethod def _mock_requests_response( status_code, headers, content=b'', stream=False): import requests response = requests.Response() response.status_code = status_code response.headers.update(headers) if stream: raw = io.BytesIO(content) raw.headers = headers response.raw = raw response._content = False else: response.raw = None response._content = content response.request = requests.Request( 'POST', 'http://example.com').prepare() return response def _mock_download_transport(self): fake_transport = mock.Mock(spec=['request']) # Give the transport two fake responses. chunk1_response = self._mock_requests_response( http_client.PARTIAL_CONTENT, {'content-length': '3', 'content-range': 'bytes 0-2/6'}, content=b'abc') chunk2_response = self._mock_requests_response( http_client.PARTIAL_CONTENT, {'content-length': '3', 'content-range': 'bytes 3-5/6'}, content=b'def') fake_transport.request.side_effect = [chunk1_response, chunk2_response] return fake_transport def _mock_download_transport_range(self): fake_transport = mock.Mock(spec=['request']) # Give the transport two fake responses. chunk1_response = self._mock_requests_response( http_client.PARTIAL_CONTENT, {'content-length': '2', 'content-range': 'bytes 1-2/6'}, content=b'bc') chunk2_response = self._mock_requests_response( http_client.PARTIAL_CONTENT, {'content-length': '2', 'content-range': 'bytes 3-4/6'}, content=b'de') fake_transport.request.side_effect = [chunk1_response, chunk2_response] return fake_transport def _check_session_mocks(self, client, transport, expected_url, headers=None): # Check that the transport was called exactly twice. self.assertEqual(transport.request.call_count, 2) if headers is None: headers = {} # NOTE: bytes=0-2 never shows up because the mock was called with # **MUTABLE** headers and it was mutated before the # second request. headers['range'] = 'bytes=3-5' headers['accept-encoding'] = 'gzip' call = mock.call( 'GET', expected_url, data=None, headers=headers) self.assertEqual(transport.request.mock_calls, [call, call]) def test__do_download_simple(self): blob_name = 'blob-name' # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock( _credentials=_make_credentials(), spec=['_credentials']) bucket = _Bucket(client) blob = self._make_one(blob_name, bucket=bucket) # Make sure this will not be chunked. self.assertIsNone(blob.chunk_size) transport = mock.Mock(spec=['request']) transport.request.return_value = self._mock_requests_response( http_client.OK, {'content-length': '6', 'content-range': 'bytes 0-5/6'}, content=b'abcdef', stream=True, ) file_obj = io.BytesIO() download_url = 'http://test.invalid' headers = {} blob._do_download(transport, file_obj, download_url, headers) # Make sure the download was as expected. self.assertEqual(file_obj.getvalue(), b'abcdef') transport.request.assert_called_once_with( 'GET', download_url, data=None, headers=headers, stream=True) def test__do_download_simple_with_range(self): blob_name = 'blob-name' # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock( _credentials=_make_credentials(), spec=['_credentials']) bucket = _Bucket(client) blob = self._make_one(blob_name, bucket=bucket) # Make sure this will not be chunked. self.assertIsNone(blob.chunk_size) transport = mock.Mock(spec=['request']) transport.request.return_value = self._mock_requests_response( http_client.OK, {'content-length': '3', 'content-range': 'bytes 1-3'}, content=b'bcd', stream=True, ) file_obj = io.BytesIO() download_url = 'http://test.invalid' headers = {} blob._do_download( transport, file_obj, download_url, headers, start=1, end=3) # Make sure the download was as expected. self.assertEqual(file_obj.getvalue(), b'bcd') self.assertEqual(headers['range'], 'bytes=1-3') transport.request.assert_called_once_with( 'GET', download_url, data=None, headers=headers, stream=True) def test__do_download_chunked(self): blob_name = 'blob-name' # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock( _credentials=_make_credentials(), spec=['_credentials']) bucket = _Bucket(client) blob = self._make_one(blob_name, bucket=bucket) # Modify the blob so there there will be 2 chunks of size 3. blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 3 transport = self._mock_download_transport() file_obj = io.BytesIO() download_url = 'http://test.invalid' headers = {} blob._do_download(transport, file_obj, download_url, headers) # Make sure the download was as expected. self.assertEqual(file_obj.getvalue(), b'abcdef') # Check that the transport was called exactly twice. self.assertEqual(transport.request.call_count, 2) # ``headers`` was modified (in place) once for each API call. self.assertEqual(headers, {'range': 'bytes=3-5'}) call = mock.call( 'GET', download_url, data=None, headers=headers) self.assertEqual(transport.request.mock_calls, [call, call]) def test__do_download_chunked_with_range(self): blob_name = 'blob-name' # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock( _credentials=_make_credentials(), spec=['_credentials']) bucket = _Bucket(client) blob = self._make_one(blob_name, bucket=bucket) # Modify the blob so there there will be 2 chunks of size 2. blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 2 transport = self._mock_download_transport_range() file_obj = io.BytesIO() download_url = 'http://test.invalid' headers = {} blob._do_download( transport, file_obj, download_url, headers, start=1, end=4) # Make sure the download was as expected. self.assertEqual(file_obj.getvalue(), b'bcde') # Check that the transport was called exactly twice. self.assertEqual(transport.request.call_count, 2) # ``headers`` was modified (in place) once for each API call. self.assertEqual(headers, {'range': 'bytes=3-4'}) call = mock.call( 'GET', download_url, data=None, headers=headers) self.assertEqual(transport.request.mock_calls, [call, call]) def test_download_to_file_with_failure(self): from google.cloud import exceptions blob_name = 'blob-name' transport = mock.Mock(spec=['request']) bad_response_headers = { 'Content-Length': '9', 'Content-Type': 'text/html; charset=UTF-8', } transport.request.return_value = self._mock_requests_response( http_client.NOT_FOUND, bad_response_headers, content=b'Not found') # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock(_http=transport, spec=[u'_http']) bucket = _Bucket(client) blob = self._make_one(blob_name, bucket=bucket) # Set the media link on the blob blob._properties['mediaLink'] = 'http://test.invalid' file_obj = io.BytesIO() with self.assertRaises(exceptions.NotFound): blob.download_to_file(file_obj) self.assertEqual(file_obj.tell(), 0) # Check that the transport was called once. transport.request.assert_called_once_with( 'GET', blob.media_link, data=None, headers={'accept-encoding': 'gzip'}, stream=True) def test_download_to_file_wo_media_link(self): blob_name = 'blob-name' transport = self._mock_download_transport() # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock(_http=transport, spec=[u'_http']) bucket = _Bucket(client) blob = self._make_one(blob_name, bucket=bucket) # Modify the blob so there there will be 2 chunks of size 3. blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 3 file_obj = io.BytesIO() blob.download_to_file(file_obj) self.assertEqual(file_obj.getvalue(), b'abcdef') # Make sure the media link is still unknown. self.assertIsNone(blob.media_link) expected_url = ( 'https://www.googleapis.com/download/storage/v1/b/' 'name/o/blob-name?alt=media') self._check_session_mocks(client, transport, expected_url) def _download_to_file_helper(self, use_chunks=False): blob_name = 'blob-name' transport = self._mock_download_transport() # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock(_http=transport, spec=[u'_http']) bucket = _Bucket(client) media_link = 'http://example.com/media/' properties = {'mediaLink': media_link} blob = self._make_one(blob_name, bucket=bucket, properties=properties) if use_chunks: # Modify the blob so there there will be 2 chunks of size 3. blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 3 else: # Modify the response. single_chunk_response = self._mock_requests_response( http_client.OK, {'content-length': '6', 'content-range': 'bytes 0-5/6'}, content=b'abcdef', stream=True, ) transport.request.side_effect = [single_chunk_response] file_obj = io.BytesIO() blob.download_to_file(file_obj) self.assertEqual(file_obj.getvalue(), b'abcdef') if use_chunks: self._check_session_mocks(client, transport, media_link) else: transport.request.assert_called_once_with( 'GET', media_link, data=None, headers={'accept-encoding': 'gzip'}, stream=True) def test_download_to_file_default(self): self._download_to_file_helper() def test_download_to_file_with_chunk_size(self): self._download_to_file_helper(use_chunks=True) def _download_to_filename_helper(self, updated=None): import os import time from google.cloud._testing import _NamedTemporaryFile blob_name = 'blob-name' transport = self._mock_download_transport() # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock(_http=transport, spec=['_http']) bucket = _Bucket(client) media_link = 'http://example.com/media/' properties = {'mediaLink': media_link} if updated is not None: properties['updated'] = updated blob = self._make_one(blob_name, bucket=bucket, properties=properties) # Modify the blob so there there will be 2 chunks of size 3. blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 3 with _NamedTemporaryFile() as temp: blob.download_to_filename(temp.name) with open(temp.name, 'rb') as file_obj: wrote = file_obj.read() if updated is None: self.assertIsNone(blob.updated) else: mtime = os.path.getmtime(temp.name) updated_time = time.mktime(blob.updated.timetuple()) self.assertEqual(mtime, updated_time) self.assertEqual(wrote, b'abcdef') self._check_session_mocks(client, transport, media_link) def test_download_to_filename(self): updated = '2014-12-06T13:13:50.690Z' self._download_to_filename_helper(updated=updated) def test_download_to_filename_wo_updated(self): self._download_to_filename_helper() def test_download_to_filename_corrupted(self): from google.resumable_media import DataCorruption from google.resumable_media.requests.download import _CHECKSUM_MISMATCH blob_name = 'blob-name' transport = mock.Mock(spec=['request']) empty_hash = base64.b64encode( hashlib.md5(b'').digest()).decode(u'utf-8') headers = {'x-goog-hash': 'md5=' + empty_hash} mock_raw = mock.Mock(headers=headers, spec=['headers']) response = mock.MagicMock( headers=headers, status_code=http_client.OK, raw=mock_raw, spec=[ '__enter__', '__exit__', 'headers', 'iter_content', 'status_code', 'raw', ], ) # i.e. context manager returns ``self``. response.__enter__.return_value = response response.__exit__.return_value = None chunks = (b'noms1', b'coooookies2') response.iter_content.return_value = iter(chunks) transport.request.return_value = response # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock(_http=transport, spec=['_http']) bucket = mock.Mock( client=client, user_project=None, spec=['client', 'user_project'], ) media_link = 'http://example.com/media/' properties = {'mediaLink': media_link} blob = self._make_one(blob_name, bucket=bucket, properties=properties) # Make sure the download is **not** chunked. self.assertIsNone(blob.chunk_size) # Make sure the hash will be wrong. content = b''.join(chunks) expected_hash = base64.b64encode( hashlib.md5(content).digest()).decode(u'utf-8') self.assertNotEqual(empty_hash, expected_hash) # Try to download into a temporary file (don't use # `_NamedTemporaryFile` it will try to remove after the file is # already removed) filehandle, filename = tempfile.mkstemp() os.close(filehandle) with self.assertRaises(DataCorruption) as exc_info: blob.download_to_filename(filename) msg = _CHECKSUM_MISMATCH.format(media_link, empty_hash, expected_hash) self.assertEqual(exc_info.exception.args, (msg,)) # Make sure the file was cleaned up. self.assertFalse(os.path.exists(filename)) # Check the mocks. response.__enter__.assert_called_once_with() response.__exit__.assert_called_once_with(None, None, None) response.iter_content.assert_called_once_with( chunk_size=8192, decode_unicode=False) transport.request.assert_called_once_with( 'GET', media_link, data=None, headers={'accept-encoding': 'gzip'}, stream=True, ) def test_download_to_filename_w_key(self): import os import time from google.cloud._testing import _NamedTemporaryFile blob_name = 'blob-name' transport = self._mock_download_transport() # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock(_http=transport, spec=['_http']) bucket = _Bucket(client) media_link = 'http://example.com/media/' properties = {'mediaLink': media_link, 'updated': '2014-12-06T13:13:50.690Z'} key = b'aa426195405adee2c8081bb9e7e74b19' blob = self._make_one( blob_name, bucket=bucket, properties=properties, encryption_key=key) # Modify the blob so there there will be 2 chunks of size 3. blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 3 with _NamedTemporaryFile() as temp: blob.download_to_filename(temp.name) with open(temp.name, 'rb') as file_obj: wrote = file_obj.read() mtime = os.path.getmtime(temp.name) updated_time = time.mktime(blob.updated.timetuple()) self.assertEqual(wrote, b'abcdef') self.assertEqual(mtime, updated_time) header_key_value = 'YWE0MjYxOTU0MDVhZGVlMmM4MDgxYmI5ZTdlNzRiMTk=' header_key_hash_value = 'V3Kwe46nKc3xLv96+iJ707YfZfFvlObta8TQcx2gpm0=' key_headers = { 'X-Goog-Encryption-Key-Sha256': header_key_hash_value, 'X-Goog-Encryption-Algorithm': 'AES256', 'X-Goog-Encryption-Key': header_key_value, 'accept-encoding': 'gzip', } self._check_session_mocks( client, transport, media_link, headers=key_headers) def test_download_as_string(self): blob_name = 'blob-name' transport = self._mock_download_transport() # Create a fake client/bucket and use them in the Blob() constructor. client = mock.Mock(_http=transport, spec=['_http']) bucket = _Bucket(client) media_link = 'http://example.com/media/' properties = {'mediaLink': media_link} blob = self._make_one(blob_name, bucket=bucket, properties=properties) # Modify the blob so there there will be 2 chunks of size 3. blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 3 fetched = blob.download_as_string() self.assertEqual(fetched, b'abcdef') self._check_session_mocks(client, transport, media_link) def test__get_content_type_explicit(self): blob = self._make_one(u'blob-name', bucket=None) content_type = u'text/plain' return_value = blob._get_content_type(content_type) self.assertEqual(return_value, content_type) def test__get_content_type_from_blob(self): blob = self._make_one(u'blob-name', bucket=None) blob.content_type = u'video/mp4' return_value = blob._get_content_type(None) self.assertEqual(return_value, blob.content_type) def test__get_content_type_from_filename(self): blob = self._make_one(u'blob-name', bucket=None) return_value = blob._get_content_type(None, filename='archive.tar') self.assertEqual(return_value, 'application/x-tar') def test__get_content_type_default(self): blob = self._make_one(u'blob-name', bucket=None) return_value = blob._get_content_type(None) self.assertEqual(return_value, u'application/octet-stream') def test__get_writable_metadata_no_changes(self): name = u'blob-name' blob = self._make_one(name, bucket=None) object_metadata = blob._get_writable_metadata() expected = {'name': name} self.assertEqual(object_metadata, expected) def test__get_writable_metadata_with_changes(self): name = u'blob-name' blob = self._make_one(name, bucket=None) blob.storage_class = 'NEARLINE' blob.cache_control = 'max-age=3600' blob.metadata = {'color': 'red'} object_metadata = blob._get_writable_metadata() expected = { 'cacheControl': blob.cache_control, 'metadata': blob.metadata, 'name': name, 'storageClass': blob.storage_class, } self.assertEqual(object_metadata, expected) def test__get_writable_metadata_unwritable_field(self): name = u'blob-name' properties = {'updated': '2016-10-16T18:18:18.181Z'} blob = self._make_one(name, bucket=None, properties=properties) # Fake that `updated` is in changes. blob._changes.add('updated') object_metadata = blob._get_writable_metadata() expected = {'name': name} self.assertEqual(object_metadata, expected) def test__get_upload_arguments(self): name = u'blob-name' key = b'[pXw@,p@@AfBfrR3x-2b2SCHR,.?YwRO' blob = self._make_one(name, bucket=None, encryption_key=key) blob.content_disposition = 'inline' content_type = u'image/jpeg' info = blob._get_upload_arguments(content_type) headers, object_metadata, new_content_type = info header_key_value = 'W3BYd0AscEBAQWZCZnJSM3gtMmIyU0NIUiwuP1l3Uk8=' header_key_hash_value = 'G0++dxF4q5rG4o9kE8gvEKn15RH6wLm0wXV1MgAlXOg=' expected_headers = { 'X-Goog-Encryption-Algorithm': 'AES256', 'X-Goog-Encryption-Key': header_key_value, 'X-Goog-Encryption-Key-Sha256': header_key_hash_value, } self.assertEqual(headers, expected_headers) expected_metadata = { 'contentDisposition': blob.content_disposition, 'name': name, } self.assertEqual(object_metadata, expected_metadata) self.assertEqual(new_content_type, content_type) def _mock_transport(self, status_code, headers, content=b''): fake_transport = mock.Mock(spec=['request']) fake_response = self._mock_requests_response( status_code, headers, content=content) fake_transport.request.return_value = fake_response return fake_transport def _do_multipart_success(self, mock_get_boundary, size=None, num_retries=None, user_project=None, predefined_acl=None, kms_key_name=None): from six.moves.urllib.parse import urlencode bucket = _Bucket(name='w00t', user_project=user_project) blob = self._make_one( u'blob-name', bucket=bucket, kms_key_name=kms_key_name) self.assertIsNone(blob.chunk_size) # Create mocks to be checked for doing transport. transport = self._mock_transport(http_client.OK, {}) # Create some mock arguments. client = mock.Mock(_http=transport, spec=['_http']) data = b'data here hear hier' stream = io.BytesIO(data) content_type = u'application/xml' response = blob._do_multipart_upload( client, stream, content_type, size, num_retries, predefined_acl) # Check the mocks and the returned value. self.assertIs(response, transport.request.return_value) if size is None: data_read = data self.assertEqual(stream.tell(), len(data)) else: data_read = data[:size] self.assertEqual(stream.tell(), size) mock_get_boundary.assert_called_once_with() upload_url = ( 'https://www.googleapis.com/upload/storage/v1' + bucket.path + '/o') qs_params = [('uploadType', 'multipart')] if user_project is not None: qs_params.append(('userProject', user_project)) if predefined_acl is not None: qs_params.append(('predefinedAcl', predefined_acl)) if kms_key_name is not None: qs_params.append(('kmsKeyName', kms_key_name)) upload_url += '?' + urlencode(qs_params) payload = ( b'--==0==\r\n' + b'content-type: application/json; charset=UTF-8\r\n\r\n' + b'{"name": "blob-name"}\r\n' + b'--==0==\r\n' + b'content-type: application/xml\r\n\r\n' + data_read + b'\r\n--==0==--') headers = {'content-type': b'multipart/related; boundary="==0=="'} transport.request.assert_called_once_with( 'POST', upload_url, data=payload, headers=headers) @mock.patch(u'google.resumable_media._upload.get_boundary', return_value=b'==0==') def test__do_multipart_upload_no_size(self, mock_get_boundary): self._do_multipart_success(mock_get_boundary, predefined_acl='private') @mock.patch(u'google.resumable_media._upload.get_boundary', return_value=b'==0==') def test__do_multipart_upload_with_size(self, mock_get_boundary): self._do_multipart_success(mock_get_boundary, size=10) @mock.patch(u'google.resumable_media._upload.get_boundary', return_value=b'==0==') def test__do_multipart_upload_with_user_project(self, mock_get_boundary): user_project = 'user-project-123' self._do_multipart_success( mock_get_boundary, user_project=user_project) @mock.patch(u'google.resumable_media._upload.get_boundary', return_value=b'==0==') def test__do_multipart_upload_with_kms(self, mock_get_boundary): kms_resource = ( "projects/test-project-123/" "locations/us/" "keyRings/test-ring/" "cryptoKeys/test-key" ) self._do_multipart_success( mock_get_boundary, kms_key_name=kms_resource) @mock.patch(u'google.resumable_media._upload.get_boundary', return_value=b'==0==') def test__do_multipart_upload_with_retry(self, mock_get_boundary): self._do_multipart_success(mock_get_boundary, num_retries=8) def test__do_multipart_upload_bad_size(self): blob = self._make_one(u'blob-name', bucket=None) data = b'data here hear hier' stream = io.BytesIO(data) size = 50 self.assertGreater(size, len(data)) with self.assertRaises(ValueError) as exc_info: blob._do_multipart_upload(None, stream, None, size, None, None) exc_contents = str(exc_info.exception) self.assertIn( 'was specified but the file-like object only had', exc_contents) self.assertEqual(stream.tell(), len(data)) def _initiate_resumable_helper( self, size=None, extra_headers=None, chunk_size=None, num_retries=None, user_project=None, predefined_acl=None, blob_chunk_size=786432, kms_key_name=None): from six.moves.urllib.parse import urlencode from google.resumable_media.requests import ResumableUpload bucket = _Bucket(name='whammy', user_project=user_project) blob = self._make_one( u'blob-name', bucket=bucket, kms_key_name=kms_key_name) blob.metadata = {'rook': 'takes knight'} blob.chunk_size = blob_chunk_size if blob_chunk_size is not None: self.assertIsNotNone(blob.chunk_size) else: self.assertIsNone(blob.chunk_size) # Need to make sure **same** dict is used because ``json.dumps()`` # will depend on the hash order. object_metadata = blob._get_writable_metadata() blob._get_writable_metadata = mock.Mock( return_value=object_metadata, spec=[]) # Create mocks to be checked for doing transport. resumable_url = 'http://test.invalid?upload_id=hey-you' response_headers = {'location': resumable_url} transport = self._mock_transport(http_client.OK, response_headers) # Create some mock arguments and call the method under test. client = mock.Mock(_http=transport, spec=[u'_http']) data = b'hello hallo halo hi-low' stream = io.BytesIO(data) content_type = u'text/plain' upload, transport = blob._initiate_resumable_upload( client, stream, content_type, size, num_retries, extra_headers=extra_headers, chunk_size=chunk_size, predefined_acl=predefined_acl) # Check the returned values. self.assertIsInstance(upload, ResumableUpload) upload_url = ( 'https://www.googleapis.com/upload/storage/v1' + bucket.path + '/o') qs_params = [('uploadType', 'resumable')] if user_project is not None: qs_params.append(('userProject', user_project)) if predefined_acl is not None: qs_params.append(('predefinedAcl', predefined_acl)) if kms_key_name is not None: qs_params.append(('kmsKeyName', kms_key_name)) upload_url += '?' + urlencode(qs_params) self.assertEqual(upload.upload_url, upload_url) if extra_headers is None: self.assertEqual(upload._headers, {}) else: self.assertEqual(upload._headers, extra_headers) self.assertIsNot(upload._headers, extra_headers) self.assertFalse(upload.finished) if chunk_size is None: if blob_chunk_size is None: self.assertEqual(upload._chunk_size, google.cloud.storage.blob._DEFAULT_CHUNKSIZE) else: self.assertEqual(upload._chunk_size, blob.chunk_size) else: self.assertNotEqual(blob.chunk_size, chunk_size) self.assertEqual(upload._chunk_size, chunk_size) self.assertIs(upload._stream, stream) if size is None: self.assertIsNone(upload._total_bytes) else: self.assertEqual(upload._total_bytes, size) self.assertEqual(upload._content_type, content_type) self.assertEqual(upload.resumable_url, resumable_url) retry_strategy = upload._retry_strategy self.assertEqual(retry_strategy.max_sleep, 64.0) if num_retries is None: self.assertEqual(retry_strategy.max_cumulative_retry, 600.0) self.assertIsNone(retry_strategy.max_retries) else: self.assertIsNone(retry_strategy.max_cumulative_retry) self.assertEqual(retry_strategy.max_retries, num_retries) self.assertIs(transport, transport) # Make sure we never read from the stream. self.assertEqual(stream.tell(), 0) # Check the mocks. blob._get_writable_metadata.assert_called_once_with() payload = json.dumps(object_metadata).encode('utf-8') expected_headers = { 'content-type': 'application/json; charset=UTF-8', 'x-upload-content-type': content_type, } if size is not None: expected_headers['x-upload-content-length'] = str(size) if extra_headers is not None: expected_headers.update(extra_headers) transport.request.assert_called_once_with( 'POST', upload_url, data=payload, headers=expected_headers) def test__initiate_resumable_upload_no_size(self): self._initiate_resumable_helper() def test__initiate_resumable_upload_with_size(self): self._initiate_resumable_helper(size=10000) def test__initiate_resumable_upload_with_user_project(self): user_project = 'user-project-123' self._initiate_resumable_helper(user_project=user_project) def test__initiate_resumable_upload_with_kms(self): kms_resource = ( "projects/test-project-123/" "locations/us/" "keyRings/test-ring/" "cryptoKeys/test-key" ) self._initiate_resumable_helper(kms_key_name=kms_resource) def test__initiate_resumable_upload_without_chunk_size(self): self._initiate_resumable_helper(blob_chunk_size=None) def test__initiate_resumable_upload_with_chunk_size(self): one_mb = 1048576 self._initiate_resumable_helper(chunk_size=one_mb) def test__initiate_resumable_upload_with_extra_headers(self): extra_headers = {'origin': 'http://not-in-kansas-anymore.invalid'} self._initiate_resumable_helper(extra_headers=extra_headers) def test__initiate_resumable_upload_with_retry(self): self._initiate_resumable_helper(num_retries=11) def test__initiate_resumable_upload_with_predefined_acl(self): self._initiate_resumable_helper(predefined_acl='private') def _make_resumable_transport(self, headers1, headers2, headers3, total_bytes): from google import resumable_media fake_transport = mock.Mock(spec=['request']) fake_response1 = self._mock_requests_response( http_client.OK, headers1) fake_response2 = self._mock_requests_response( resumable_media.PERMANENT_REDIRECT, headers2) json_body = '{{"size": "{:d}"}}'.format(total_bytes) fake_response3 = self._mock_requests_response( http_client.OK, headers3, content=json_body.encode('utf-8')) responses = [fake_response1, fake_response2, fake_response3] fake_transport.request.side_effect = responses return fake_transport, responses @staticmethod def _do_resumable_upload_call0( blob, content_type, size=None, predefined_acl=None): # First mock transport.request() does initiates upload. upload_url = ( 'https://www.googleapis.com/upload/storage/v1' + blob.bucket.path + '/o?uploadType=resumable') if predefined_acl is not None: upload_url += '&predefinedAcl={}'.format(predefined_acl) expected_headers = { 'content-type': 'application/json; charset=UTF-8', 'x-upload-content-type': content_type, } if size is not None: expected_headers['x-upload-content-length'] = str(size) payload = json.dumps({'name': blob.name}).encode('utf-8') return mock.call( 'POST', upload_url, data=payload, headers=expected_headers) @staticmethod def _do_resumable_upload_call1( blob, content_type, data, resumable_url, size=None, predefined_acl=None): # Second mock transport.request() does sends first chunk. if size is None: content_range = 'bytes 0-{:d}/*'.format(blob.chunk_size - 1) else: content_range = 'bytes 0-{:d}/{:d}'.format( blob.chunk_size - 1, size) expected_headers = { 'content-type': content_type, 'content-range': content_range, } payload = data[:blob.chunk_size] return mock.call( 'PUT', resumable_url, data=payload, headers=expected_headers) @staticmethod def _do_resumable_upload_call2( blob, content_type, data, resumable_url, total_bytes, predefined_acl=None): # Third mock transport.request() does sends last chunk. content_range = 'bytes {:d}-{:d}/{:d}'.format( blob.chunk_size, total_bytes - 1, total_bytes) expected_headers = { 'content-type': content_type, 'content-range': content_range, } payload = data[blob.chunk_size:] return mock.call( 'PUT', resumable_url, data=payload, headers=expected_headers) def _do_resumable_helper( self, use_size=False, num_retries=None, predefined_acl=None): bucket = _Bucket(name='yesterday') blob = self._make_one(u'blob-name', bucket=bucket) blob.chunk_size = blob._CHUNK_SIZE_MULTIPLE self.assertIsNotNone(blob.chunk_size) # Data to be uploaded. data = b'<html>' + (b'A' * blob.chunk_size) + b'</html>' total_bytes = len(data) if use_size: size = total_bytes else: size = None # Create mocks to be checked for doing transport. resumable_url = 'http://test.invalid?upload_id=and-then-there-was-1' headers1 = {'location': resumable_url} headers2 = {'range': 'bytes=0-{:d}'.format(blob.chunk_size - 1)} transport, responses = self._make_resumable_transport( headers1, headers2, {}, total_bytes) # Create some mock arguments and call the method under test. client = mock.Mock(_http=transport, spec=['_http']) stream = io.BytesIO(data) content_type = u'text/html' response = blob._do_resumable_upload( client, stream, content_type, size, num_retries, predefined_acl) # Check the returned values. self.assertIs(response, responses[2]) self.assertEqual(stream.tell(), total_bytes) # Check the mocks. call0 = self._do_resumable_upload_call0( blob, content_type, size=size, predefined_acl=predefined_acl) call1 = self._do_resumable_upload_call1( blob, content_type, data, resumable_url, size=size, predefined_acl=predefined_acl) call2 = self._do_resumable_upload_call2( blob, content_type, data, resumable_url, total_bytes, predefined_acl=predefined_acl) self.assertEqual( transport.request.mock_calls, [call0, call1, call2]) def test__do_resumable_upload_no_size(self): self._do_resumable_helper() def test__do_resumable_upload_with_size(self): self._do_resumable_helper(use_size=True) def test__do_resumable_upload_with_retry(self): self._do_resumable_helper(num_retries=6) def test__do_resumable_upload_with_predefined_acl(self): self._do_resumable_helper(predefined_acl='private') def _do_upload_helper( self, chunk_size=None, num_retries=None, predefined_acl=None, size=None): blob = self._make_one(u'blob-name', bucket=None) # Create a fake response. response = mock.Mock(spec=[u'json']) response.json.return_value = mock.sentinel.json # Mock **both** helpers. blob._do_multipart_upload = mock.Mock(return_value=response, spec=[]) blob._do_resumable_upload = mock.Mock(return_value=response, spec=[]) if chunk_size is None: self.assertIsNone(blob.chunk_size) else: blob.chunk_size = chunk_size self.assertIsNotNone(blob.chunk_size) client = mock.sentinel.client stream = mock.sentinel.stream content_type = u'video/mp4' if size is None: size = 12345654321 # Make the request and check the mocks. created_json = blob._do_upload( client, stream, content_type, size, num_retries, predefined_acl) self.assertIs(created_json, mock.sentinel.json) response.json.assert_called_once_with() if size is not None and \ size <= google.cloud.storage.blob._MAX_MULTIPART_SIZE: blob._do_multipart_upload.assert_called_once_with( client, stream, content_type, size, num_retries, predefined_acl) blob._do_resumable_upload.assert_not_called() else: blob._do_multipart_upload.assert_not_called() blob._do_resumable_upload.assert_called_once_with( client, stream, content_type, size, num_retries, predefined_acl) def test__do_upload_uses_multipart(self): self._do_upload_helper( size=google.cloud.storage.blob._MAX_MULTIPART_SIZE) def test__do_upload_uses_resumable(self): self._do_upload_helper( chunk_size=256 * 1024, # 256KB size=google.cloud.storage.blob._MAX_MULTIPART_SIZE + 1) def test__do_upload_with_retry(self): self._do_upload_helper(num_retries=20) def _upload_from_file_helper(self, side_effect=None, **kwargs): from google.cloud._helpers import UTC blob = self._make_one('blob-name', bucket=None) # Mock low-level upload helper on blob (it is tested elsewhere). created_json = {'updated': '2017-01-01T09:09:09.081Z'} blob._do_upload = mock.Mock(return_value=created_json, spec=[]) if side_effect is not None: blob._do_upload.side_effect = side_effect # Make sure `updated` is empty before the request. self.assertIsNone(blob.updated) data = b'data is here' stream = io.BytesIO(data) stream.seek(2) # Not at zero. content_type = u'font/woff' client = mock.sentinel.client predefined_acl = kwargs.get('predefined_acl', None) ret_val = blob.upload_from_file( stream, size=len(data), content_type=content_type, client=client, **kwargs) # Check the response and side-effects. self.assertIsNone(ret_val) new_updated = datetime.datetime( 2017, 1, 1, 9, 9, 9, 81000, tzinfo=UTC) self.assertEqual(blob.updated, new_updated) # Check the mock. num_retries = kwargs.get('num_retries') blob._do_upload.assert_called_once_with( client, stream, content_type, len(data), num_retries, predefined_acl) return stream def test_upload_from_file_success(self): stream = self._upload_from_file_helper(predefined_acl='private') assert stream.tell() == 2 @mock.patch('warnings.warn') def test_upload_from_file_with_retries(self, mock_warn): from google.cloud.storage import blob as blob_module self._upload_from_file_helper(num_retries=20) mock_warn.assert_called_once_with( blob_module._NUM_RETRIES_MESSAGE, DeprecationWarning, stacklevel=2) def test_upload_from_file_with_rewind(self): stream = self._upload_from_file_helper(rewind=True) assert stream.tell() == 0 def test_upload_from_file_failure(self): import requests from google.resumable_media import InvalidResponse from google.cloud import exceptions message = 'Someone is already in this spot.' response = requests.Response() response.status_code = http_client.CONFLICT response.request = requests.Request( 'POST', 'http://example.com').prepare() side_effect = InvalidResponse(response, message) with self.assertRaises(exceptions.Conflict) as exc_info: self._upload_from_file_helper(side_effect=side_effect) self.assertIn(message, exc_info.exception.message) self.assertEqual(exc_info.exception.errors, []) def _do_upload_mock_call_helper(self, blob, client, content_type, size): self.assertEqual(blob._do_upload.call_count, 1) mock_call = blob._do_upload.mock_calls[0] call_name, pos_args, kwargs = mock_call self.assertEqual(call_name, '') self.assertEqual(len(pos_args), 6) self.assertEqual(pos_args[0], client) self.assertEqual(pos_args[2], content_type) self.assertEqual(pos_args[3], size) self.assertIsNone(pos_args[4]) # num_retries self.assertIsNone(pos_args[5]) # predefined_acl self.assertEqual(kwargs, {}) return pos_args[1] def test_upload_from_filename(self): from google.cloud._testing import _NamedTemporaryFile blob = self._make_one('blob-name', bucket=None) # Mock low-level upload helper on blob (it is tested elsewhere). created_json = {'metadata': {'mint': 'ice-cream'}} blob._do_upload = mock.Mock(return_value=created_json, spec=[]) # Make sure `metadata` is empty before the request. self.assertIsNone(blob.metadata) data = b'soooo much data' content_type = u'image/svg+xml' client = mock.sentinel.client with _NamedTemporaryFile() as temp: with open(temp.name, 'wb') as file_obj: file_obj.write(data) ret_val = blob.upload_from_filename( temp.name, content_type=content_type, client=client) # Check the response and side-effects. self.assertIsNone(ret_val) self.assertEqual(blob.metadata, created_json['metadata']) # Check the mock. stream = self._do_upload_mock_call_helper( blob, client, content_type, len(data)) self.assertTrue(stream.closed) self.assertEqual(stream.mode, 'rb') self.assertEqual(stream.name, temp.name) def _upload_from_string_helper(self, data, **kwargs): from google.cloud._helpers import _to_bytes blob = self._make_one('blob-name', bucket=None) # Mock low-level upload helper on blob (it is tested elsewhere). created_json = {'componentCount': '5'} blob._do_upload = mock.Mock(return_value=created_json, spec=[]) # Make sure `metadata` is empty before the request. self.assertIsNone(blob.component_count) client = mock.sentinel.client ret_val = blob.upload_from_string(data, client=client, **kwargs) # Check the response and side-effects. self.assertIsNone(ret_val) self.assertEqual(blob.component_count, 5) # Check the mock. payload = _to_bytes(data, encoding='utf-8') stream = self._do_upload_mock_call_helper( blob, client, 'text/plain', len(payload)) self.assertIsInstance(stream, io.BytesIO) self.assertEqual(stream.getvalue(), payload) def test_upload_from_string_w_bytes(self): data = b'XB]jb\xb8tad\xe0' self._upload_from_string_helper(data) def test_upload_from_string_w_text(self): data = u'\N{snowman} \N{sailboat}' self._upload_from_string_helper(data) def _create_resumable_upload_session_helper(self, origin=None, side_effect=None): bucket = _Bucket(name='alex-trebek') blob = self._make_one('blob-name', bucket=bucket) chunk_size = 99 * blob._CHUNK_SIZE_MULTIPLE blob.chunk_size = chunk_size # Create mocks to be checked for doing transport. resumable_url = 'http://test.invalid?upload_id=clean-up-everybody' response_headers = {'location': resumable_url} transport = self._mock_transport( http_client.OK, response_headers) if side_effect is not None: transport.request.side_effect = side_effect # Create some mock arguments and call the method under test. content_type = u'text/plain' size = 10000 client = mock.Mock(_http=transport, spec=[u'_http']) new_url = blob.create_resumable_upload_session( content_type=content_type, size=size, origin=origin, client=client) # Check the returned value and (lack of) side-effect. self.assertEqual(new_url, resumable_url) self.assertEqual(blob.chunk_size, chunk_size) # Check the mocks. upload_url = ( 'https://www.googleapis.com/upload/storage/v1' + bucket.path + '/o?uploadType=resumable') payload = b'{"name": "blob-name"}' expected_headers = { 'content-type': 'application/json; charset=UTF-8', 'x-upload-content-length': str(size), 'x-upload-content-type': content_type, } if origin is not None: expected_headers['Origin'] = origin transport.request.assert_called_once_with( 'POST', upload_url, data=payload, headers=expected_headers) def test_create_resumable_upload_session(self): self._create_resumable_upload_session_helper() def test_create_resumable_upload_session_with_origin(self): self._create_resumable_upload_session_helper( origin='http://google.com') def test_create_resumable_upload_session_with_failure(self): from google.resumable_media import InvalidResponse from google.cloud import exceptions message = '5-oh-3 woe is me.' response = self._mock_requests_response( status_code=http_client.SERVICE_UNAVAILABLE, headers={}) side_effect = InvalidResponse(response, message) with self.assertRaises(exceptions.ServiceUnavailable) as exc_info: self._create_resumable_upload_session_helper( side_effect=side_effect) self.assertIn(message, exc_info.exception.message) self.assertEqual(exc_info.exception.errors, []) def test_get_iam_policy(self): from google.cloud.storage.iam import STORAGE_OWNER_ROLE from google.cloud.storage.iam import STORAGE_EDITOR_ROLE from google.cloud.storage.iam import STORAGE_VIEWER_ROLE from google.cloud.iam import Policy BLOB_NAME = 'blob-name' PATH = '/b/name/o/%s' % (BLOB_NAME,) ETAG = 'DEADBEEF' VERSION = 17 OWNER1 = 'user:phred@example.com' OWNER2 = 'group:cloud-logs@google.com' EDITOR1 = 'domain:google.com' EDITOR2 = 'user:phred@example.com' VIEWER1 = 'serviceAccount:1234-abcdef@service.example.com' VIEWER2 = 'user:phred@example.com' RETURNED = { 'resourceId': PATH, 'etag': ETAG, 'version': VERSION, 'bindings': [ {'role': STORAGE_OWNER_ROLE, 'members': [OWNER1, OWNER2]}, {'role': STORAGE_EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]}, {'role': STORAGE_VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}, ], } after = ({'status': http_client.OK}, RETURNED) EXPECTED = { binding['role']: set(binding['members']) for binding in RETURNED['bindings']} connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client) blob = self._make_one(BLOB_NAME, bucket=bucket) policy = blob.get_iam_policy() self.assertIsInstance(policy, Policy) self.assertEqual(policy.etag, RETURNED['etag']) self.assertEqual(policy.version, RETURNED['version']) self.assertEqual(dict(policy), EXPECTED) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0], { 'method': 'GET', 'path': '%s/iam' % (PATH,), 'query_params': {}, '_target_object': None, }) def test_get_iam_policy_w_user_project(self): from google.cloud.iam import Policy BLOB_NAME = 'blob-name' USER_PROJECT = 'user-project-123' PATH = '/b/name/o/%s' % (BLOB_NAME,) ETAG = 'DEADBEEF' VERSION = 17 RETURNED = { 'resourceId': PATH, 'etag': ETAG, 'version': VERSION, 'bindings': [], } after = ({'status': http_client.OK}, RETURNED) EXPECTED = {} connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client, user_project=USER_PROJECT) blob = self._make_one(BLOB_NAME, bucket=bucket) policy = blob.get_iam_policy() self.assertIsInstance(policy, Policy) self.assertEqual(policy.etag, RETURNED['etag']) self.assertEqual(policy.version, RETURNED['version']) self.assertEqual(dict(policy), EXPECTED) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0], { 'method': 'GET', 'path': '%s/iam' % (PATH,), 'query_params': {'userProject': USER_PROJECT}, '_target_object': None, }) def test_set_iam_policy(self): import operator from google.cloud.storage.iam import STORAGE_OWNER_ROLE from google.cloud.storage.iam import STORAGE_EDITOR_ROLE from google.cloud.storage.iam import STORAGE_VIEWER_ROLE from google.cloud.iam import Policy BLOB_NAME = 'blob-name' PATH = '/b/name/o/%s' % (BLOB_NAME,) ETAG = 'DEADBEEF' VERSION = 17 OWNER1 = 'user:phred@example.com' OWNER2 = 'group:cloud-logs@google.com' EDITOR1 = 'domain:google.com' EDITOR2 = 'user:phred@example.com' VIEWER1 = 'serviceAccount:1234-abcdef@service.example.com' VIEWER2 = 'user:phred@example.com' BINDINGS = [ {'role': STORAGE_OWNER_ROLE, 'members': [OWNER1, OWNER2]}, {'role': STORAGE_EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]}, {'role': STORAGE_VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}, ] RETURNED = { 'etag': ETAG, 'version': VERSION, 'bindings': BINDINGS, } after = ({'status': http_client.OK}, RETURNED) policy = Policy() for binding in BINDINGS: policy[binding['role']] = binding['members'] connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client) blob = self._make_one(BLOB_NAME, bucket=bucket) returned = blob.set_iam_policy(policy) self.assertEqual(returned.etag, ETAG) self.assertEqual(returned.version, VERSION) self.assertEqual(dict(returned), dict(policy)) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'PUT') self.assertEqual(kw[0]['path'], '%s/iam' % (PATH,)) self.assertEqual(kw[0]['query_params'], {}) sent = kw[0]['data'] self.assertEqual(sent['resourceId'], PATH) self.assertEqual(len(sent['bindings']), len(BINDINGS)) key = operator.itemgetter('role') for found, expected in zip( sorted(sent['bindings'], key=key), sorted(BINDINGS, key=key)): self.assertEqual(found['role'], expected['role']) self.assertEqual( sorted(found['members']), sorted(expected['members'])) def test_set_iam_policy_w_user_project(self): from google.cloud.iam import Policy BLOB_NAME = 'blob-name' USER_PROJECT = 'user-project-123' PATH = '/b/name/o/%s' % (BLOB_NAME,) ETAG = 'DEADBEEF' VERSION = 17 BINDINGS = [] RETURNED = { 'etag': ETAG, 'version': VERSION, 'bindings': BINDINGS, } after = ({'status': http_client.OK}, RETURNED) policy = Policy() connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client, user_project=USER_PROJECT) blob = self._make_one(BLOB_NAME, bucket=bucket) returned = blob.set_iam_policy(policy) self.assertEqual(returned.etag, ETAG) self.assertEqual(returned.version, VERSION) self.assertEqual(dict(returned), dict(policy)) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'PUT') self.assertEqual(kw[0]['path'], '%s/iam' % (PATH,)) self.assertEqual(kw[0]['query_params'], {'userProject': USER_PROJECT}) self.assertEqual(kw[0]['data'], {'resourceId': PATH}) def test_test_iam_permissions(self): from google.cloud.storage.iam import STORAGE_OBJECTS_LIST from google.cloud.storage.iam import STORAGE_BUCKETS_GET from google.cloud.storage.iam import STORAGE_BUCKETS_UPDATE BLOB_NAME = 'blob-name' PATH = '/b/name/o/%s' % (BLOB_NAME,) PERMISSIONS = [ STORAGE_OBJECTS_LIST, STORAGE_BUCKETS_GET, STORAGE_BUCKETS_UPDATE, ] ALLOWED = PERMISSIONS[1:] RETURNED = {'permissions': ALLOWED} after = ({'status': http_client.OK}, RETURNED) connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client) blob = self._make_one(BLOB_NAME, bucket=bucket) allowed = blob.test_iam_permissions(PERMISSIONS) self.assertEqual(allowed, ALLOWED) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'GET') self.assertEqual(kw[0]['path'], '%s/iam/testPermissions' % (PATH,)) self.assertEqual(kw[0]['query_params'], {'permissions': PERMISSIONS}) def test_test_iam_permissions_w_user_project(self): from google.cloud.storage.iam import STORAGE_OBJECTS_LIST from google.cloud.storage.iam import STORAGE_BUCKETS_GET from google.cloud.storage.iam import STORAGE_BUCKETS_UPDATE BLOB_NAME = 'blob-name' USER_PROJECT = 'user-project-123' PATH = '/b/name/o/%s' % (BLOB_NAME,) PERMISSIONS = [ STORAGE_OBJECTS_LIST, STORAGE_BUCKETS_GET, STORAGE_BUCKETS_UPDATE, ] ALLOWED = PERMISSIONS[1:] RETURNED = {'permissions': ALLOWED} after = ({'status': http_client.OK}, RETURNED) connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client, user_project=USER_PROJECT) blob = self._make_one(BLOB_NAME, bucket=bucket) allowed = blob.test_iam_permissions(PERMISSIONS) self.assertEqual(allowed, ALLOWED) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'GET') self.assertEqual(kw[0]['path'], '%s/iam/testPermissions' % (PATH,)) self.assertEqual( kw[0]['query_params'], {'permissions': PERMISSIONS, 'userProject': USER_PROJECT}) def test_make_public(self): from google.cloud.storage.acl import _ACLEntity BLOB_NAME = 'blob-name' permissive = [{'entity': 'allUsers', 'role': _ACLEntity.READER_ROLE}] after = ({'status': http_client.OK}, {'acl': permissive}) connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client) blob = self._make_one(BLOB_NAME, bucket=bucket) blob.acl.loaded = True blob.make_public() self.assertEqual(list(blob.acl), permissive) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'PATCH') self.assertEqual(kw[0]['path'], '/b/name/o/%s' % BLOB_NAME) self.assertEqual(kw[0]['data'], {'acl': permissive}) self.assertEqual(kw[0]['query_params'], {'projection': 'full'}) def test_make_private(self): BLOB_NAME = 'blob-name' no_permissions = [] after = ({'status': http_client.OK}, {'acl': no_permissions}) connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client) blob = self._make_one(BLOB_NAME, bucket=bucket) blob.acl.loaded = True blob.make_private() self.assertEqual(list(blob.acl), no_permissions) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'PATCH') self.assertEqual(kw[0]['path'], '/b/name/o/%s' % BLOB_NAME) self.assertEqual(kw[0]['data'], {'acl': no_permissions}) self.assertEqual(kw[0]['query_params'], {'projection': 'full'}) def test_compose_wo_content_type_set(self): SOURCE_1 = 'source-1' SOURCE_2 = 'source-2' DESTINATION = 'destinaton' RESOURCE = {} after = ({'status': http_client.OK}, RESOURCE) connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client) source_1 = self._make_one(SOURCE_1, bucket=bucket) source_2 = self._make_one(SOURCE_2, bucket=bucket) destination = self._make_one(DESTINATION, bucket=bucket) # no destination.content_type set destination.compose(sources=[source_1, source_2]) self.assertIsNone(destination.content_type) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0], { 'method': 'POST', 'path': '/b/name/o/%s/compose' % DESTINATION, 'query_params': {}, 'data': { 'sourceObjects': [ {'name': source_1.name}, {'name': source_2.name}, ], 'destination': {}, }, '_target_object': destination, }) def test_compose_minimal_w_user_project(self): SOURCE_1 = 'source-1' SOURCE_2 = 'source-2' DESTINATION = 'destinaton' RESOURCE = { 'etag': 'DEADBEEF' } USER_PROJECT = 'user-project-123' after = ({'status': http_client.OK}, RESOURCE) connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client, user_project=USER_PROJECT) source_1 = self._make_one(SOURCE_1, bucket=bucket) source_2 = self._make_one(SOURCE_2, bucket=bucket) destination = self._make_one(DESTINATION, bucket=bucket) destination.content_type = 'text/plain' destination.compose(sources=[source_1, source_2]) self.assertEqual(destination.etag, 'DEADBEEF') kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0], { 'method': 'POST', 'path': '/b/name/o/%s/compose' % DESTINATION, 'query_params': {'userProject': USER_PROJECT}, 'data': { 'sourceObjects': [ {'name': source_1.name}, {'name': source_2.name}, ], 'destination': { 'contentType': 'text/plain', }, }, '_target_object': destination, }) def test_compose_w_additional_property_changes(self): SOURCE_1 = 'source-1' SOURCE_2 = 'source-2' DESTINATION = 'destinaton' RESOURCE = { 'etag': 'DEADBEEF' } after = ({'status': http_client.OK}, RESOURCE) connection = _Connection(after) client = _Client(connection) bucket = _Bucket(client=client) source_1 = self._make_one(SOURCE_1, bucket=bucket) source_2 = self._make_one(SOURCE_2, bucket=bucket) destination = self._make_one(DESTINATION, bucket=bucket) destination.content_type = 'text/plain' destination.content_language = 'en-US' destination.metadata = {'my-key': 'my-value'} destination.compose(sources=[source_1, source_2]) self.assertEqual(destination.etag, 'DEADBEEF') kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0], { 'method': 'POST', 'path': '/b/name/o/%s/compose' % DESTINATION, 'query_params': {}, 'data': { 'sourceObjects': [ {'name': source_1.name}, {'name': source_2.name}, ], 'destination': { 'contentType': 'text/plain', 'contentLanguage': 'en-US', 'metadata': { 'my-key': 'my-value', } }, }, '_target_object': destination, }) def test_rewrite_response_without_resource(self): SOURCE_BLOB = 'source' DEST_BLOB = 'dest' DEST_BUCKET = 'other-bucket' TOKEN = 'TOKEN' RESPONSE = { 'totalBytesRewritten': 33, 'objectSize': 42, 'done': False, 'rewriteToken': TOKEN, } response = ({'status': http_client.OK}, RESPONSE) connection = _Connection(response) client = _Client(connection) source_bucket = _Bucket(client=client) source_blob = self._make_one(SOURCE_BLOB, bucket=source_bucket) dest_bucket = _Bucket(client=client, name=DEST_BUCKET) dest_blob = self._make_one(DEST_BLOB, bucket=dest_bucket) token, rewritten, size = dest_blob.rewrite(source_blob) self.assertEqual(token, TOKEN) self.assertEqual(rewritten, 33) self.assertEqual(size, 42) def test_rewrite_other_bucket_other_name_no_encryption_partial(self): SOURCE_BLOB = 'source' DEST_BLOB = 'dest' DEST_BUCKET = 'other-bucket' TOKEN = 'TOKEN' RESPONSE = { 'totalBytesRewritten': 33, 'objectSize': 42, 'done': False, 'rewriteToken': TOKEN, 'resource': {'etag': 'DEADBEEF'}, } response = ({'status': http_client.OK}, RESPONSE) connection = _Connection(response) client = _Client(connection) source_bucket = _Bucket(client=client) source_blob = self._make_one(SOURCE_BLOB, bucket=source_bucket) dest_bucket = _Bucket(client=client, name=DEST_BUCKET) dest_blob = self._make_one(DEST_BLOB, bucket=dest_bucket) token, rewritten, size = dest_blob.rewrite(source_blob) self.assertEqual(token, TOKEN) self.assertEqual(rewritten, 33) self.assertEqual(size, 42) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'POST') PATH = '/b/name/o/%s/rewriteTo/b/%s/o/%s' % ( SOURCE_BLOB, DEST_BUCKET, DEST_BLOB) self.assertEqual(kw[0]['path'], PATH) self.assertEqual(kw[0]['query_params'], {}) SENT = {} self.assertEqual(kw[0]['data'], SENT) headers = { key.title(): str(value) for key, value in kw[0]['headers'].items()} self.assertNotIn('X-Goog-Copy-Source-Encryption-Algorithm', headers) self.assertNotIn('X-Goog-Copy-Source-Encryption-Key', headers) self.assertNotIn('X-Goog-Copy-Source-Encryption-Key-Sha256', headers) self.assertNotIn('X-Goog-Encryption-Algorithm', headers) self.assertNotIn('X-Goog-Encryption-Key', headers) self.assertNotIn('X-Goog-Encryption-Key-Sha256', headers) def test_rewrite_same_name_no_old_key_new_key_done_w_user_project(self): import base64 import hashlib KEY = b'01234567890123456789012345678901' # 32 bytes KEY_B64 = base64.b64encode(KEY).rstrip().decode('ascii') KEY_HASH = hashlib.sha256(KEY).digest() KEY_HASH_B64 = base64.b64encode(KEY_HASH).rstrip().decode('ascii') BLOB_NAME = 'blob' USER_PROJECT = 'user-project-123' RESPONSE = { 'totalBytesRewritten': 42, 'objectSize': 42, 'done': True, 'resource': {'etag': 'DEADBEEF'}, } response = ({'status': http_client.OK}, RESPONSE) connection = _Connection(response) client = _Client(connection) bucket = _Bucket(client=client, user_project=USER_PROJECT) plain = self._make_one(BLOB_NAME, bucket=bucket) encrypted = self._make_one(BLOB_NAME, bucket=bucket, encryption_key=KEY) token, rewritten, size = encrypted.rewrite(plain) self.assertIsNone(token) self.assertEqual(rewritten, 42) self.assertEqual(size, 42) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'POST') PATH = '/b/name/o/%s/rewriteTo/b/name/o/%s' % (BLOB_NAME, BLOB_NAME) self.assertEqual(kw[0]['path'], PATH) self.assertEqual(kw[0]['query_params'], {'userProject': USER_PROJECT}) SENT = {} self.assertEqual(kw[0]['data'], SENT) headers = { key.title(): str(value) for key, value in kw[0]['headers'].items()} self.assertNotIn('X-Goog-Copy-Source-Encryption-Algorithm', headers) self.assertNotIn('X-Goog-Copy-Source-Encryption-Key', headers) self.assertNotIn('X-Goog-Copy-Source-Encryption-Key-Sha256', headers) self.assertEqual(headers['X-Goog-Encryption-Algorithm'], 'AES256') self.assertEqual(headers['X-Goog-Encryption-Key'], KEY_B64) self.assertEqual(headers['X-Goog-Encryption-Key-Sha256'], KEY_HASH_B64) def test_rewrite_same_name_no_key_new_key_w_token(self): import base64 import hashlib SOURCE_KEY = b'01234567890123456789012345678901' # 32 bytes SOURCE_KEY_B64 = base64.b64encode(SOURCE_KEY).rstrip().decode('ascii') SOURCE_KEY_HASH = hashlib.sha256(SOURCE_KEY).digest() SOURCE_KEY_HASH_B64 = base64.b64encode( SOURCE_KEY_HASH).rstrip().decode('ascii') DEST_KEY = b'90123456789012345678901234567890' # 32 bytes DEST_KEY_B64 = base64.b64encode(DEST_KEY).rstrip().decode('ascii') DEST_KEY_HASH = hashlib.sha256(DEST_KEY).digest() DEST_KEY_HASH_B64 = base64.b64encode( DEST_KEY_HASH).rstrip().decode('ascii') BLOB_NAME = 'blob' TOKEN = 'TOKEN' RESPONSE = { 'totalBytesRewritten': 42, 'objectSize': 42, 'done': True, 'resource': {'etag': 'DEADBEEF'}, } response = ({'status': http_client.OK}, RESPONSE) connection = _Connection(response) client = _Client(connection) bucket = _Bucket(client=client) source = self._make_one( BLOB_NAME, bucket=bucket, encryption_key=SOURCE_KEY) dest = self._make_one(BLOB_NAME, bucket=bucket, encryption_key=DEST_KEY) token, rewritten, size = dest.rewrite(source, token=TOKEN) self.assertIsNone(token) self.assertEqual(rewritten, 42) self.assertEqual(size, 42) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'POST') PATH = '/b/name/o/%s/rewriteTo/b/name/o/%s' % (BLOB_NAME, BLOB_NAME) self.assertEqual(kw[0]['path'], PATH) self.assertEqual(kw[0]['query_params'], {'rewriteToken': TOKEN}) SENT = {} self.assertEqual(kw[0]['data'], SENT) headers = { key.title(): str(value) for key, value in kw[0]['headers'].items()} self.assertEqual( headers['X-Goog-Copy-Source-Encryption-Algorithm'], 'AES256') self.assertEqual( headers['X-Goog-Copy-Source-Encryption-Key'], SOURCE_KEY_B64) self.assertEqual( headers['X-Goog-Copy-Source-Encryption-Key-Sha256'], SOURCE_KEY_HASH_B64) self.assertEqual( headers['X-Goog-Encryption-Algorithm'], 'AES256') self.assertEqual( headers['X-Goog-Encryption-Key'], DEST_KEY_B64) self.assertEqual( headers['X-Goog-Encryption-Key-Sha256'], DEST_KEY_HASH_B64) def test_rewrite_same_name_w_old_key_new_kms_key(self): import base64 import hashlib SOURCE_KEY = b'01234567890123456789012345678901' # 32 bytes SOURCE_KEY_B64 = base64.b64encode(SOURCE_KEY).rstrip().decode('ascii') SOURCE_KEY_HASH = hashlib.sha256(SOURCE_KEY).digest() SOURCE_KEY_HASH_B64 = base64.b64encode( SOURCE_KEY_HASH).rstrip().decode('ascii') DEST_KMS_RESOURCE = ( "projects/test-project-123/" "locations/us/" "keyRings/test-ring/" "cryptoKeys/test-key" ) BLOB_NAME = 'blob' RESPONSE = { 'totalBytesRewritten': 42, 'objectSize': 42, 'done': True, 'resource': {'etag': 'DEADBEEF'}, } response = ({'status': http_client.OK}, RESPONSE) connection = _Connection(response) client = _Client(connection) bucket = _Bucket(client=client) source = self._make_one( BLOB_NAME, bucket=bucket, encryption_key=SOURCE_KEY) dest = self._make_one(BLOB_NAME, bucket=bucket, kms_key_name=DEST_KMS_RESOURCE) token, rewritten, size = dest.rewrite(source) self.assertIsNone(token) self.assertEqual(rewritten, 42) self.assertEqual(size, 42) kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'POST') PATH = '/b/name/o/%s/rewriteTo/b/name/o/%s' % (BLOB_NAME, BLOB_NAME) self.assertEqual(kw[0]['path'], PATH) self.assertEqual(kw[0]['query_params'], {'destinationKmsKeyName': DEST_KMS_RESOURCE}) SENT = { 'kmsKeyName': DEST_KMS_RESOURCE, } self.assertEqual(kw[0]['data'], SENT) headers = { key.title(): str(value) for key, value in kw[0]['headers'].items()} self.assertEqual( headers['X-Goog-Copy-Source-Encryption-Algorithm'], 'AES256') self.assertEqual( headers['X-Goog-Copy-Source-Encryption-Key'], SOURCE_KEY_B64) self.assertEqual( headers['X-Goog-Copy-Source-Encryption-Key-Sha256'], SOURCE_KEY_HASH_B64) def test_update_storage_class_invalid(self): BLOB_NAME = 'blob-name' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) with self.assertRaises(ValueError): blob.update_storage_class(u'BOGUS') def test_update_storage_class_wo_encryption_key(self): BLOB_NAME = 'blob-name' STORAGE_CLASS = u'NEARLINE' RESPONSE = { 'resource': {'storageClass': STORAGE_CLASS}, } response = ({'status': http_client.OK}, RESPONSE) connection = _Connection(response) client = _Client(connection) bucket = _Bucket(client=client) blob = self._make_one(BLOB_NAME, bucket=bucket) blob.update_storage_class('NEARLINE') self.assertEqual(blob.storage_class, 'NEARLINE') kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'POST') PATH = '/b/name/o/%s/rewriteTo/b/name/o/%s' % (BLOB_NAME, BLOB_NAME) self.assertEqual(kw[0]['path'], PATH) self.assertEqual(kw[0]['query_params'], {}) SENT = {'storageClass': STORAGE_CLASS} self.assertEqual(kw[0]['data'], SENT) headers = { key.title(): str(value) for key, value in kw[0]['headers'].items()} # Blob has no key, and therefore the relevant headers are not sent. self.assertNotIn('X-Goog-Copy-Source-Encryption-Algorithm', headers) self.assertNotIn('X-Goog-Copy-Source-Encryption-Key', headers) self.assertNotIn('X-Goog-Copy-Source-Encryption-Key-Sha256', headers) self.assertNotIn('X-Goog-Encryption-Algorithm', headers) self.assertNotIn('X-Goog-Encryption-Key', headers) self.assertNotIn('X-Goog-Encryption-Key-Sha256', headers) def test_update_storage_class_w_encryption_key_w_user_project(self): import base64 import hashlib BLOB_NAME = 'blob-name' BLOB_KEY = b'01234567890123456789012345678901' # 32 bytes BLOB_KEY_B64 = base64.b64encode(BLOB_KEY).rstrip().decode('ascii') BLOB_KEY_HASH = hashlib.sha256(BLOB_KEY).digest() BLOB_KEY_HASH_B64 = base64.b64encode( BLOB_KEY_HASH).rstrip().decode('ascii') STORAGE_CLASS = u'NEARLINE' USER_PROJECT = 'user-project-123' RESPONSE = { 'resource': {'storageClass': STORAGE_CLASS}, } response = ({'status': http_client.OK}, RESPONSE) connection = _Connection(response) client = _Client(connection) bucket = _Bucket(client=client, user_project=USER_PROJECT) blob = self._make_one( BLOB_NAME, bucket=bucket, encryption_key=BLOB_KEY) blob.update_storage_class('NEARLINE') self.assertEqual(blob.storage_class, 'NEARLINE') kw = connection._requested self.assertEqual(len(kw), 1) self.assertEqual(kw[0]['method'], 'POST') PATH = '/b/name/o/%s/rewriteTo/b/name/o/%s' % (BLOB_NAME, BLOB_NAME) self.assertEqual(kw[0]['path'], PATH) self.assertEqual(kw[0]['query_params'], {'userProject': USER_PROJECT}) SENT = {'storageClass': STORAGE_CLASS} self.assertEqual(kw[0]['data'], SENT) headers = { key.title(): str(value) for key, value in kw[0]['headers'].items()} # Blob has key, and therefore the relevant headers are sent. self.assertEqual( headers['X-Goog-Copy-Source-Encryption-Algorithm'], 'AES256') self.assertEqual( headers['X-Goog-Copy-Source-Encryption-Key'], BLOB_KEY_B64) self.assertEqual( headers['X-Goog-Copy-Source-Encryption-Key-Sha256'], BLOB_KEY_HASH_B64) self.assertEqual( headers['X-Goog-Encryption-Algorithm'], 'AES256') self.assertEqual( headers['X-Goog-Encryption-Key'], BLOB_KEY_B64) self.assertEqual( headers['X-Goog-Encryption-Key-Sha256'], BLOB_KEY_HASH_B64) def test_cache_control_getter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() CACHE_CONTROL = 'no-cache' properties = {'cacheControl': CACHE_CONTROL} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.cache_control, CACHE_CONTROL) def test_cache_control_setter(self): BLOB_NAME = 'blob-name' CACHE_CONTROL = 'no-cache' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.cache_control) blob.cache_control = CACHE_CONTROL self.assertEqual(blob.cache_control, CACHE_CONTROL) def test_component_count(self): BUCKET = object() COMPONENT_COUNT = 42 blob = self._make_one('blob-name', bucket=BUCKET, properties={'componentCount': COMPONENT_COUNT}) self.assertEqual(blob.component_count, COMPONENT_COUNT) def test_component_count_unset(self): BUCKET = object() blob = self._make_one('blob-name', bucket=BUCKET) self.assertIsNone(blob.component_count) def test_component_count_string_val(self): BUCKET = object() COMPONENT_COUNT = 42 blob = self._make_one( 'blob-name', bucket=BUCKET, properties={'componentCount': str(COMPONENT_COUNT)}) self.assertEqual(blob.component_count, COMPONENT_COUNT) def test_content_disposition_getter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() CONTENT_DISPOSITION = 'Attachment; filename=example.jpg' properties = {'contentDisposition': CONTENT_DISPOSITION} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.content_disposition, CONTENT_DISPOSITION) def test_content_disposition_setter(self): BLOB_NAME = 'blob-name' CONTENT_DISPOSITION = 'Attachment; filename=example.jpg' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.content_disposition) blob.content_disposition = CONTENT_DISPOSITION self.assertEqual(blob.content_disposition, CONTENT_DISPOSITION) def test_content_encoding_getter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() CONTENT_ENCODING = 'gzip' properties = {'contentEncoding': CONTENT_ENCODING} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.content_encoding, CONTENT_ENCODING) def test_content_encoding_setter(self): BLOB_NAME = 'blob-name' CONTENT_ENCODING = 'gzip' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.content_encoding) blob.content_encoding = CONTENT_ENCODING self.assertEqual(blob.content_encoding, CONTENT_ENCODING) def test_content_language_getter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() CONTENT_LANGUAGE = 'pt-BR' properties = {'contentLanguage': CONTENT_LANGUAGE} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.content_language, CONTENT_LANGUAGE) def test_content_language_setter(self): BLOB_NAME = 'blob-name' CONTENT_LANGUAGE = 'pt-BR' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.content_language) blob.content_language = CONTENT_LANGUAGE self.assertEqual(blob.content_language, CONTENT_LANGUAGE) def test_content_type_getter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() CONTENT_TYPE = 'image/jpeg' properties = {'contentType': CONTENT_TYPE} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.content_type, CONTENT_TYPE) def test_content_type_setter(self): BLOB_NAME = 'blob-name' CONTENT_TYPE = 'image/jpeg' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.content_type) blob.content_type = CONTENT_TYPE self.assertEqual(blob.content_type, CONTENT_TYPE) def test_crc32c_getter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() CRC32C = 'DEADBEEF' properties = {'crc32c': CRC32C} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.crc32c, CRC32C) def test_crc32c_setter(self): BLOB_NAME = 'blob-name' CRC32C = 'DEADBEEF' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.crc32c) blob.crc32c = CRC32C self.assertEqual(blob.crc32c, CRC32C) def test_etag(self): BLOB_NAME = 'blob-name' bucket = _Bucket() ETAG = 'ETAG' properties = {'etag': ETAG} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.etag, ETAG) def test_event_based_hold_getter_missing(self): BLOB_NAME = 'blob-name' bucket = _Bucket() properties = {} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertIsNone(blob.event_based_hold) def test_event_based_hold_getter_false(self): BLOB_NAME = 'blob-name' bucket = _Bucket() properties = {'eventBasedHold': False} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertFalse(blob.event_based_hold) def test_event_based_hold_getter_true(self): BLOB_NAME = 'blob-name' bucket = _Bucket() properties = {'eventBasedHold': True} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertTrue(blob.event_based_hold) def test_event_based_hold_setter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.event_based_hold) blob.event_based_hold = True self.assertEqual(blob.event_based_hold, True) def test_generation(self): BUCKET = object() GENERATION = 42 blob = self._make_one('blob-name', bucket=BUCKET, properties={'generation': GENERATION}) self.assertEqual(blob.generation, GENERATION) def test_generation_unset(self): BUCKET = object() blob = self._make_one('blob-name', bucket=BUCKET) self.assertIsNone(blob.generation) def test_generation_string_val(self): BUCKET = object() GENERATION = 42 blob = self._make_one('blob-name', bucket=BUCKET, properties={'generation': str(GENERATION)}) self.assertEqual(blob.generation, GENERATION) def test_id(self): BLOB_NAME = 'blob-name' bucket = _Bucket() ID = 'ID' properties = {'id': ID} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.id, ID) def test_md5_hash_getter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() MD5_HASH = 'DEADBEEF' properties = {'md5Hash': MD5_HASH} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.md5_hash, MD5_HASH) def test_md5_hash_setter(self): BLOB_NAME = 'blob-name' MD5_HASH = 'DEADBEEF' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.md5_hash) blob.md5_hash = MD5_HASH self.assertEqual(blob.md5_hash, MD5_HASH) def test_media_link(self): BLOB_NAME = 'blob-name' bucket = _Bucket() MEDIA_LINK = 'http://example.com/media/' properties = {'mediaLink': MEDIA_LINK} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.media_link, MEDIA_LINK) def test_metadata_getter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() METADATA = {'foo': 'Foo'} properties = {'metadata': METADATA} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.metadata, METADATA) def test_metadata_setter(self): BLOB_NAME = 'blob-name' METADATA = {'foo': 'Foo'} bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.metadata) blob.metadata = METADATA self.assertEqual(blob.metadata, METADATA) def test_metageneration(self): BUCKET = object() METAGENERATION = 42 blob = self._make_one('blob-name', bucket=BUCKET, properties={'metageneration': METAGENERATION}) self.assertEqual(blob.metageneration, METAGENERATION) def test_metageneration_unset(self): BUCKET = object() blob = self._make_one('blob-name', bucket=BUCKET) self.assertIsNone(blob.metageneration) def test_metageneration_string_val(self): BUCKET = object() METAGENERATION = 42 blob = self._make_one( 'blob-name', bucket=BUCKET, properties={'metageneration': str(METAGENERATION)}) self.assertEqual(blob.metageneration, METAGENERATION) def test_owner(self): BLOB_NAME = 'blob-name' bucket = _Bucket() OWNER = {'entity': 'project-owner-12345', 'entityId': '23456'} properties = {'owner': OWNER} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) owner = blob.owner self.assertEqual(owner['entity'], 'project-owner-12345') self.assertEqual(owner['entityId'], '23456') def test_retention_expiration_time(self): from google.cloud._helpers import _RFC3339_MICROS from google.cloud._helpers import UTC BLOB_NAME = 'blob-name' bucket = _Bucket() TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37, tzinfo=UTC) TIME_CREATED = TIMESTAMP.strftime(_RFC3339_MICROS) properties = {'retentionExpirationTime': TIME_CREATED} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.retention_expiration_time, TIMESTAMP) def test_retention_expiration_time_unset(self): BUCKET = object() blob = self._make_one('blob-name', bucket=BUCKET) self.assertIsNone(blob.retention_expiration_time) def test_self_link(self): BLOB_NAME = 'blob-name' bucket = _Bucket() SELF_LINK = 'http://example.com/self/' properties = {'selfLink': SELF_LINK} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.self_link, SELF_LINK) def test_size(self): BUCKET = object() SIZE = 42 blob = self._make_one('blob-name', bucket=BUCKET, properties={'size': SIZE}) self.assertEqual(blob.size, SIZE) def test_size_unset(self): BUCKET = object() blob = self._make_one('blob-name', bucket=BUCKET) self.assertIsNone(blob.size) def test_size_string_val(self): BUCKET = object() SIZE = 42 blob = self._make_one('blob-name', bucket=BUCKET, properties={'size': str(SIZE)}) self.assertEqual(blob.size, SIZE) def test_storage_class_getter(self): blob_name = 'blob-name' bucket = _Bucket() storage_class = 'MULTI_REGIONAL' properties = {'storageClass': storage_class} blob = self._make_one(blob_name, bucket=bucket, properties=properties) self.assertEqual(blob.storage_class, storage_class) def test_storage_class_setter(self): blob_name = 'blob-name' bucket = _Bucket() storage_class = 'COLDLINE' blob = self._make_one(blob_name, bucket=bucket) self.assertIsNone(blob.storage_class) blob.storage_class = storage_class self.assertEqual(blob.storage_class, storage_class) self.assertEqual(blob._properties, {'storageClass': storage_class}) def test_temporary_hold_getter_missing(self): BLOB_NAME = 'blob-name' bucket = _Bucket() properties = {} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertIsNone(blob.temporary_hold) def test_temporary_hold_getter_false(self): BLOB_NAME = 'blob-name' bucket = _Bucket() properties = {'temporaryHold': False} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertFalse(blob.temporary_hold) def test_temporary_hold_getter_true(self): BLOB_NAME = 'blob-name' bucket = _Bucket() properties = {'temporaryHold': True} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertTrue(blob.temporary_hold) def test_temporary_hold_setter(self): BLOB_NAME = 'blob-name' bucket = _Bucket() blob = self._make_one(BLOB_NAME, bucket=bucket) self.assertIsNone(blob.temporary_hold) blob.temporary_hold = True self.assertEqual(blob.temporary_hold, True) def test_time_deleted(self): from google.cloud._helpers import _RFC3339_MICROS from google.cloud._helpers import UTC BLOB_NAME = 'blob-name' bucket = _Bucket() TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37, tzinfo=UTC) TIME_DELETED = TIMESTAMP.strftime(_RFC3339_MICROS) properties = {'timeDeleted': TIME_DELETED} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.time_deleted, TIMESTAMP) def test_time_deleted_unset(self): BUCKET = object() blob = self._make_one('blob-name', bucket=BUCKET) self.assertIsNone(blob.time_deleted) def test_time_created(self): from google.cloud._helpers import _RFC3339_MICROS from google.cloud._helpers import UTC BLOB_NAME = 'blob-name' bucket = _Bucket() TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37, tzinfo=UTC) TIME_CREATED = TIMESTAMP.strftime(_RFC3339_MICROS) properties = {'timeCreated': TIME_CREATED} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.time_created, TIMESTAMP) def test_time_created_unset(self): BUCKET = object() blob = self._make_one('blob-name', bucket=BUCKET) self.assertIsNone(blob.time_created) def test_updated(self): from google.cloud._helpers import _RFC3339_MICROS from google.cloud._helpers import UTC BLOB_NAME = 'blob-name' bucket = _Bucket() TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37, tzinfo=UTC) UPDATED = TIMESTAMP.strftime(_RFC3339_MICROS) properties = {'updated': UPDATED} blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties) self.assertEqual(blob.updated, TIMESTAMP) def test_updated_unset(self): BUCKET = object() blob = self._make_one('blob-name', bucket=BUCKET) self.assertIsNone(blob.updated) class Test__quote(unittest.TestCase): @staticmethod def _call_fut(value): from google.cloud.storage.blob import _quote return _quote(value) def test_bytes(self): quoted = self._call_fut(b'\xDE\xAD\xBE\xEF') self.assertEqual(quoted, '%DE%AD%BE%EF') def test_unicode(self): helicopter = u'\U0001f681' quoted = self._call_fut(helicopter) self.assertEqual(quoted, '%F0%9F%9A%81') def test_bad_type(self): with self.assertRaises(TypeError): self._call_fut(None) class Test__maybe_rewind(unittest.TestCase): @staticmethod def _call_fut(*args, **kwargs): from google.cloud.storage.blob import _maybe_rewind return _maybe_rewind(*args, **kwargs) def test_default(self): stream = mock.Mock(spec=[u'seek']) ret_val = self._call_fut(stream) self.assertIsNone(ret_val) stream.seek.assert_not_called() def test_do_not_rewind(self): stream = mock.Mock(spec=[u'seek']) ret_val = self._call_fut(stream, rewind=False) self.assertIsNone(ret_val) stream.seek.assert_not_called() def test_do_rewind(self): stream = mock.Mock(spec=[u'seek']) ret_val = self._call_fut(stream, rewind=True) self.assertIsNone(ret_val) stream.seek.assert_called_once_with(0, os.SEEK_SET) class Test__raise_from_invalid_response(unittest.TestCase): @staticmethod def _call_fut(error): from google.cloud.storage.blob import _raise_from_invalid_response return _raise_from_invalid_response(error) def _helper(self, message, code=http_client.BAD_REQUEST, args=()): import requests from google.resumable_media import InvalidResponse from google.api_core import exceptions response = requests.Response() response.request = requests.Request( 'GET', 'http://example.com').prepare() response.status_code = code error = InvalidResponse(response, message, *args) with self.assertRaises(exceptions.GoogleAPICallError) as exc_info: self._call_fut(error) return exc_info def test_default(self): message = 'Failure' exc_info = self._helper(message) expected = 'GET http://example.com/: {}'.format(message) self.assertEqual(exc_info.exception.message, expected) self.assertEqual(exc_info.exception.errors, []) def test_w_206_and_args(self): message = 'Failure' args = ('one', 'two') exc_info = self._helper( message, code=http_client.PARTIAL_CONTENT, args=args) expected = 'GET http://example.com/: {}'.format((message,) + args) self.assertEqual(exc_info.exception.message, expected) self.assertEqual(exc_info.exception.errors, []) class Test__add_query_parameters(unittest.TestCase): @staticmethod def _call_fut(*args, **kwargs): from google.cloud.storage.blob import _add_query_parameters return _add_query_parameters(*args, **kwargs) def test_w_empty_list(self): BASE_URL = 'https://test.example.com/base' self.assertEqual(self._call_fut(BASE_URL, []), BASE_URL) def test_wo_existing_qs(self): BASE_URL = 'https://test.example.com/base' NV_LIST = [('one', 'One'), ('two', 'Two')] expected = '&'.join([ '{}={}'.format(name, value) for name, value in NV_LIST]) self.assertEqual( self._call_fut(BASE_URL, NV_LIST), '{}?{}'.format(BASE_URL, expected)) def test_w_existing_qs(self): BASE_URL = 'https://test.example.com/base?one=Three' NV_LIST = [('one', 'One'), ('two', 'Two')] expected = '&'.join([ '{}={}'.format(name, value) for name, value in NV_LIST]) self.assertEqual( self._call_fut(BASE_URL, NV_LIST), '{}&{}'.format(BASE_URL, expected)) class _Connection(object): API_BASE_URL = 'http://example.com' USER_AGENT = 'testing 1.2.3' credentials = object() def __init__(self, *responses): self._responses = responses[:] self._requested = [] self._signed = [] def _respond(self, **kw): self._requested.append(kw) response, self._responses = self._responses[0], self._responses[1:] return response def api_request(self, **kw): from google.cloud.exceptions import NotFound info, content = self._respond(**kw) if info.get('status') == http_client.NOT_FOUND: raise NotFound(info) return content class _Bucket(object): def __init__(self, client=None, name='name', user_project=None): if client is None: connection = _Connection() client = _Client(connection) self.client = client self._blobs = {} self._copied = [] self._deleted = [] self.name = name self.path = '/b/' + name self.user_project = user_project def delete_blob(self, blob_name, client=None): del self._blobs[blob_name] self._deleted.append((blob_name, client)) class _Signer(object): def __init__(self): self._signed = [] def __call__(self, *args, **kwargs): self._signed.append((args, kwargs)) return ('http://example.com/abucket/a-blob-name?Signature=DEADBEEF' '&Expiration=%s' % kwargs.get('expiration')) class _Client(object): def __init__(self, connection): self._base_connection = connection @property def _connection(self): return self._base_connection @property def _credentials(self): return self._base_connection.credentials
apache-2.0
[ 3, 1898, 6927, 4475, 20376, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 646, 1300, 772, 199, 646, 2197, 199, 646, 8337, 199, 646, 5890, 199, 646, 2022, 199, 646, 747, 199, 646, 5549, 199, 646, 2882, 199, 199, 646, 6233, 14, 4091, 14, 3494, 14, 6582, 199, 646, 1683, 199, 646, 3816, 199, 504, 3816, 14, 4912, 492, 1455, 63, 1258, 421, 199, 318, 485, 1875, 63, 6942, 837, 272, 492, 6233, 14, 1178, 14, 6942, 339, 372, 1683, 14, 3346, 8, 1650, 29, 3098, 14, 1178, 14, 6942, 14, 13428, 9, 421, 199, 533, 1379, 63, 16799, 8, 2796, 14, 1746, 304, 339, 768, 4639, 272, 347, 485, 1875, 63, 368, 2031, 589, 12, 1011, 829, 304, 267, 687, 6233, 14, 4091, 14, 3494, 14, 6582, 492, 31745, 398, 4382, 275, 4775, 14, 1935, 360, 3282, 297, 5009, 267, 9182, 275, 31745, 2031, 589, 12, 1011, 829, 9, 267, 9182, 423, 3282, 14, 873, 8, 3282, 9, 267, 372, 9182, 339, 347, 511, 63, 630, 63, 2027, 63, 15113, 63, 498, 8, 277, 304, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 5315, 275, 485, 12311, 342, 267, 4382, 275, 791, 498, 356, 283, 585, 936, 267, 9182, 275, 291, 423, 1875, 63, 368, 8, 26275, 63, 2339, 12, 5315, 29, 4623, 12, 4382, 29, 3282, 9, 267, 291, 14, 3436, 8, 6582, 14, 4623, 12, 5315, 9, 267, 291, 14, 629, 8, 6582, 14, 354, 12, 699, 9376, 63, 2339, 9, 267, 291, 14, 629, 8, 6582, 423, 3282, 12, 4382, 9, 267, 291, 14, 3334, 8, 6582, 423, 5853, 14, 4591, 9, 267, 291, 14, 3436, 8, 6582, 423, 5853, 14, 6582, 12, 9182, 9, 267, 291, 14, 629, 8, 6582, 423, 15113, 63, 498, 12, 488, 9, 267, 291, 14, 629, 8, 6582, 14, 75, 706, 63, 498, 63, 354, 12, 488, 9, 339, 347, 511, 63, 630, 63, 1045, 63, 8167, 63, 2975, 8, 277, 304, 267, 9182, 63, 354, 275, 330, 7, 87, 386, 971, 1845, 18, 60, 88, 25, 66, 60, 1774, 21, 7, 267, 9182, 275, 291, 423, 1875, 63, 368, 8, 6582, 63, 354, 12, 5315, 29, 403, 9, 267, 2649, 63, 354, 275, 399, 7, 87, 386, 971, 46, 91, 83, 1054, 656, 292, 6834, 267, 291, 14, 4809, 1831, 3244, 8, 6582, 14, 354, 12, 2783, 9, 267, 291, 14, 6926, 8, 6582, 14, 354, 12, 3816, 14, 505, 63, 466, 9, 267, 291, 14, 629, 8, 6582, 14, 354, 12, 2649, 63, 354, 9, 339, 347, 511, 63, 630, 63, 87, 63, 15113, 63, 498, 8, 277, 304, 267, 9301, 275, 330, 7, 25588, 11371, 614, 7, 221, 327, 4337, 2783, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 5315, 275, 485, 12311, 342, 267, 9182, 275, 291, 423, 1875, 63, 368, 8, 26275, 63, 2339, 12, 5315, 29, 4623, 12, 14396, 63, 498, 29, 3078, 9, 267, 291, 14, 629, 8, 6582, 423, 15113, 63, 498, 12, 9301, 9, 267, 291, 14, 629, 8, 6582, 14, 75, 706, 63, 498, 63, 354, 12, 488, 9, 339, 347, 511, 63, 630, 63, 87, 63, 75, 706, 63, 498, 63, 354, 63, 460, 63, 15113, 63, 498, 8, 277, 304, 267, 9301, 275, 330, 7, 25588, 11371, 614, 7, 221, 327, 4337, 2783, 267, 1804, 3053, 63, 14110, 275, 334, 288, 298, 6776, 15, 396, 13, 1715, 13, 4288, 6687, 288, 298, 8022, 15, 527, 6687, 288, 298, 498, 50, 780, 15, 396, 13, 5985, 6687, 288, 298, 10316, 6340, 15, 396, 13, 498, 2, 267, 776, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 5315, 275, 485, 12311, 342, 398, 543, 291, 14, 1855, 8, 3393, 304, 288, 291, 423, 1875, 63, 368, 8, 355, 699, 9376, 63, 2339, 12, 5315, 29, 4623, 12, 355, 14396, 63, 498, 29, 3078, 12, 355, 1022, 706, 63, 498, 63, 354, 29, 43, 3053, 63, 14110, 9, 339, 347, 511, 63, 630, 63, 87, 63, 75, 706, 63, 498, 63, 354, 8, 277, 304, 267, 1804, 3053, 63, 14110, 275, 334, 288, 298, 6776, 15, 396, 13, 1715, 13, 4288, 6687, 288, 298, 8022, 15, 527, 6687, 288, 298, 498, 50, 780, 15, 396, 13, 5985, 6687, 288, 298, 10316, 6340, 15, 396, 13, 498, 2, 267, 776, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 5315, 275, 485, 12311, 342, 267, 9182, 275, 291, 423, 1875, 63, 368, 8, 288, 699, 9376, 63, 2339, 12, 5315, 29, 4623, 12, 1022, 706, 63, 498, 63, 354, 29, 43, 3053, 63, 14110, 9, 267, 291, 14, 629, 8, 6582, 423, 15113, 63, 498, 12, 488, 9, 267, 291, 14, 629, 8, 6582, 14, 75, 706, 63, 498, 63, 354, 12, 1804, 3053, 63, 14110, 9, 339, 347, 485, 409, 63, 3282, 63, 3676, 8, 277, 12, 1022, 706, 63, 498, 63, 354, 29, 403, 304, 267, 492, 2197, 267, 687, 6233, 14, 4091, 423, 7546, 492, 12174, 267, 687, 6233, 14, 4091, 423, 7546, 492, 485, 14468, 29536, 63, 29112, 51, 267, 3063, 275, 2197, 14, 2083, 14, 10779, 1252, 1814, 8, 9374, 29, 11288, 9, 267, 4825, 55, 275, 3063, 14, 6205, 1547, 14468, 29536, 63, 29112, 51, 9, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 29087, 2594, 275, 25538, 267, 699, 9376, 63, 998, 275, 283, 354 ]
[ 1898, 6927, 4475, 20376, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 646, 1300, 772, 199, 646, 2197, 199, 646, 8337, 199, 646, 5890, 199, 646, 2022, 199, 646, 747, 199, 646, 5549, 199, 646, 2882, 199, 199, 646, 6233, 14, 4091, 14, 3494, 14, 6582, 199, 646, 1683, 199, 646, 3816, 199, 504, 3816, 14, 4912, 492, 1455, 63, 1258, 421, 199, 318, 485, 1875, 63, 6942, 837, 272, 492, 6233, 14, 1178, 14, 6942, 339, 372, 1683, 14, 3346, 8, 1650, 29, 3098, 14, 1178, 14, 6942, 14, 13428, 9, 421, 199, 533, 1379, 63, 16799, 8, 2796, 14, 1746, 304, 339, 768, 4639, 272, 347, 485, 1875, 63, 368, 2031, 589, 12, 1011, 829, 304, 267, 687, 6233, 14, 4091, 14, 3494, 14, 6582, 492, 31745, 398, 4382, 275, 4775, 14, 1935, 360, 3282, 297, 5009, 267, 9182, 275, 31745, 2031, 589, 12, 1011, 829, 9, 267, 9182, 423, 3282, 14, 873, 8, 3282, 9, 267, 372, 9182, 339, 347, 511, 63, 630, 63, 2027, 63, 15113, 63, 498, 8, 277, 304, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 5315, 275, 485, 12311, 342, 267, 4382, 275, 791, 498, 356, 283, 585, 936, 267, 9182, 275, 291, 423, 1875, 63, 368, 8, 26275, 63, 2339, 12, 5315, 29, 4623, 12, 4382, 29, 3282, 9, 267, 291, 14, 3436, 8, 6582, 14, 4623, 12, 5315, 9, 267, 291, 14, 629, 8, 6582, 14, 354, 12, 699, 9376, 63, 2339, 9, 267, 291, 14, 629, 8, 6582, 423, 3282, 12, 4382, 9, 267, 291, 14, 3334, 8, 6582, 423, 5853, 14, 4591, 9, 267, 291, 14, 3436, 8, 6582, 423, 5853, 14, 6582, 12, 9182, 9, 267, 291, 14, 629, 8, 6582, 423, 15113, 63, 498, 12, 488, 9, 267, 291, 14, 629, 8, 6582, 14, 75, 706, 63, 498, 63, 354, 12, 488, 9, 339, 347, 511, 63, 630, 63, 1045, 63, 8167, 63, 2975, 8, 277, 304, 267, 9182, 63, 354, 275, 330, 7, 87, 386, 971, 1845, 18, 60, 88, 25, 66, 60, 1774, 21, 7, 267, 9182, 275, 291, 423, 1875, 63, 368, 8, 6582, 63, 354, 12, 5315, 29, 403, 9, 267, 2649, 63, 354, 275, 399, 7, 87, 386, 971, 46, 91, 83, 1054, 656, 292, 6834, 267, 291, 14, 4809, 1831, 3244, 8, 6582, 14, 354, 12, 2783, 9, 267, 291, 14, 6926, 8, 6582, 14, 354, 12, 3816, 14, 505, 63, 466, 9, 267, 291, 14, 629, 8, 6582, 14, 354, 12, 2649, 63, 354, 9, 339, 347, 511, 63, 630, 63, 87, 63, 15113, 63, 498, 8, 277, 304, 267, 9301, 275, 330, 7, 25588, 11371, 614, 7, 221, 327, 4337, 2783, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 5315, 275, 485, 12311, 342, 267, 9182, 275, 291, 423, 1875, 63, 368, 8, 26275, 63, 2339, 12, 5315, 29, 4623, 12, 14396, 63, 498, 29, 3078, 9, 267, 291, 14, 629, 8, 6582, 423, 15113, 63, 498, 12, 9301, 9, 267, 291, 14, 629, 8, 6582, 14, 75, 706, 63, 498, 63, 354, 12, 488, 9, 339, 347, 511, 63, 630, 63, 87, 63, 75, 706, 63, 498, 63, 354, 63, 460, 63, 15113, 63, 498, 8, 277, 304, 267, 9301, 275, 330, 7, 25588, 11371, 614, 7, 221, 327, 4337, 2783, 267, 1804, 3053, 63, 14110, 275, 334, 288, 298, 6776, 15, 396, 13, 1715, 13, 4288, 6687, 288, 298, 8022, 15, 527, 6687, 288, 298, 498, 50, 780, 15, 396, 13, 5985, 6687, 288, 298, 10316, 6340, 15, 396, 13, 498, 2, 267, 776, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 5315, 275, 485, 12311, 342, 398, 543, 291, 14, 1855, 8, 3393, 304, 288, 291, 423, 1875, 63, 368, 8, 355, 699, 9376, 63, 2339, 12, 5315, 29, 4623, 12, 355, 14396, 63, 498, 29, 3078, 12, 355, 1022, 706, 63, 498, 63, 354, 29, 43, 3053, 63, 14110, 9, 339, 347, 511, 63, 630, 63, 87, 63, 75, 706, 63, 498, 63, 354, 8, 277, 304, 267, 1804, 3053, 63, 14110, 275, 334, 288, 298, 6776, 15, 396, 13, 1715, 13, 4288, 6687, 288, 298, 8022, 15, 527, 6687, 288, 298, 498, 50, 780, 15, 396, 13, 5985, 6687, 288, 298, 10316, 6340, 15, 396, 13, 498, 2, 267, 776, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 5315, 275, 485, 12311, 342, 267, 9182, 275, 291, 423, 1875, 63, 368, 8, 288, 699, 9376, 63, 2339, 12, 5315, 29, 4623, 12, 1022, 706, 63, 498, 63, 354, 29, 43, 3053, 63, 14110, 9, 267, 291, 14, 629, 8, 6582, 423, 15113, 63, 498, 12, 488, 9, 267, 291, 14, 629, 8, 6582, 14, 75, 706, 63, 498, 63, 354, 12, 1804, 3053, 63, 14110, 9, 339, 347, 485, 409, 63, 3282, 63, 3676, 8, 277, 12, 1022, 706, 63, 498, 63, 354, 29, 403, 304, 267, 492, 2197, 267, 687, 6233, 14, 4091, 423, 7546, 492, 12174, 267, 687, 6233, 14, 4091, 423, 7546, 492, 485, 14468, 29536, 63, 29112, 51, 267, 3063, 275, 2197, 14, 2083, 14, 10779, 1252, 1814, 8, 9374, 29, 11288, 9, 267, 4825, 55, 275, 3063, 14, 6205, 1547, 14468, 29536, 63, 29112, 51, 9, 267, 699, 9376, 63, 2339, 275, 283, 6582, 13, 354, 7, 267, 29087, 2594, 275, 25538, 267, 699, 9376, 63, 998, 275, 283, 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, 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 ]
Universal-Model-Converter/UMC3.0a
data/Python/x86/Lib/site-packages/OpenGL/raw/GL/ARB/shader_objects.py
3
17124
'''OpenGL extension ARB.shader_objects Automatically generated by the get_gl_extensions script, do not edit! ''' from OpenGL import platform, constants, constant, arrays from OpenGL import extensions from OpenGL.GL import glget import ctypes EXTENSION_NAME = 'GL_ARB_shader_objects' _DEPRECATED = False GL_PROGRAM_OBJECT_ARB = constant.Constant( 'GL_PROGRAM_OBJECT_ARB', 0x8B40 ) GL_SHADER_OBJECT_ARB = constant.Constant( 'GL_SHADER_OBJECT_ARB', 0x8B48 ) GL_OBJECT_TYPE_ARB = constant.Constant( 'GL_OBJECT_TYPE_ARB', 0x8B4E ) GL_OBJECT_SUBTYPE_ARB = constant.Constant( 'GL_OBJECT_SUBTYPE_ARB', 0x8B4F ) GL_FLOAT_VEC2_ARB = constant.Constant( 'GL_FLOAT_VEC2_ARB', 0x8B50 ) GL_FLOAT_VEC3_ARB = constant.Constant( 'GL_FLOAT_VEC3_ARB', 0x8B51 ) GL_FLOAT_VEC4_ARB = constant.Constant( 'GL_FLOAT_VEC4_ARB', 0x8B52 ) GL_INT_VEC2_ARB = constant.Constant( 'GL_INT_VEC2_ARB', 0x8B53 ) GL_INT_VEC3_ARB = constant.Constant( 'GL_INT_VEC3_ARB', 0x8B54 ) GL_INT_VEC4_ARB = constant.Constant( 'GL_INT_VEC4_ARB', 0x8B55 ) GL_BOOL_ARB = constant.Constant( 'GL_BOOL_ARB', 0x8B56 ) GL_BOOL_VEC2_ARB = constant.Constant( 'GL_BOOL_VEC2_ARB', 0x8B57 ) GL_BOOL_VEC3_ARB = constant.Constant( 'GL_BOOL_VEC3_ARB', 0x8B58 ) GL_BOOL_VEC4_ARB = constant.Constant( 'GL_BOOL_VEC4_ARB', 0x8B59 ) GL_FLOAT_MAT2_ARB = constant.Constant( 'GL_FLOAT_MAT2_ARB', 0x8B5A ) GL_FLOAT_MAT3_ARB = constant.Constant( 'GL_FLOAT_MAT3_ARB', 0x8B5B ) GL_FLOAT_MAT4_ARB = constant.Constant( 'GL_FLOAT_MAT4_ARB', 0x8B5C ) GL_SAMPLER_1D_ARB = constant.Constant( 'GL_SAMPLER_1D_ARB', 0x8B5D ) GL_SAMPLER_2D_ARB = constant.Constant( 'GL_SAMPLER_2D_ARB', 0x8B5E ) GL_SAMPLER_3D_ARB = constant.Constant( 'GL_SAMPLER_3D_ARB', 0x8B5F ) GL_SAMPLER_CUBE_ARB = constant.Constant( 'GL_SAMPLER_CUBE_ARB', 0x8B60 ) GL_SAMPLER_1D_SHADOW_ARB = constant.Constant( 'GL_SAMPLER_1D_SHADOW_ARB', 0x8B61 ) GL_SAMPLER_2D_SHADOW_ARB = constant.Constant( 'GL_SAMPLER_2D_SHADOW_ARB', 0x8B62 ) GL_SAMPLER_2D_RECT_ARB = constant.Constant( 'GL_SAMPLER_2D_RECT_ARB', 0x8B63 ) GL_SAMPLER_2D_RECT_SHADOW_ARB = constant.Constant( 'GL_SAMPLER_2D_RECT_SHADOW_ARB', 0x8B64 ) GL_OBJECT_DELETE_STATUS_ARB = constant.Constant( 'GL_OBJECT_DELETE_STATUS_ARB', 0x8B80 ) GL_OBJECT_COMPILE_STATUS_ARB = constant.Constant( 'GL_OBJECT_COMPILE_STATUS_ARB', 0x8B81 ) GL_OBJECT_LINK_STATUS_ARB = constant.Constant( 'GL_OBJECT_LINK_STATUS_ARB', 0x8B82 ) GL_OBJECT_VALIDATE_STATUS_ARB = constant.Constant( 'GL_OBJECT_VALIDATE_STATUS_ARB', 0x8B83 ) GL_OBJECT_INFO_LOG_LENGTH_ARB = constant.Constant( 'GL_OBJECT_INFO_LOG_LENGTH_ARB', 0x8B84 ) GL_OBJECT_ATTACHED_OBJECTS_ARB = constant.Constant( 'GL_OBJECT_ATTACHED_OBJECTS_ARB', 0x8B85 ) GL_OBJECT_ACTIVE_UNIFORMS_ARB = constant.Constant( 'GL_OBJECT_ACTIVE_UNIFORMS_ARB', 0x8B86 ) GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB = constant.Constant( 'GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB', 0x8B87 ) GL_OBJECT_SHADER_SOURCE_LENGTH_ARB = constant.Constant( 'GL_OBJECT_SHADER_SOURCE_LENGTH_ARB', 0x8B88 ) glDeleteObjectARB = platform.createExtensionFunction( 'glDeleteObjectARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,), doc='glDeleteObjectARB(GLhandleARB(obj)) -> None', argNames=('obj',), deprecated=_DEPRECATED, ) glGetHandleARB = platform.createExtensionFunction( 'glGetHandleARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=constants.GLhandleARB, argTypes=(constants.GLenum,), doc='glGetHandleARB(GLenum(pname)) -> constants.GLhandleARB', argNames=('pname',), deprecated=_DEPRECATED, ) glDetachObjectARB = platform.createExtensionFunction( 'glDetachObjectARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLhandleARB,), doc='glDetachObjectARB(GLhandleARB(containerObj), GLhandleARB(attachedObj)) -> None', argNames=('containerObj','attachedObj',), deprecated=_DEPRECATED, ) glCreateShaderObjectARB = platform.createExtensionFunction( 'glCreateShaderObjectARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=constants.GLhandleARB, argTypes=(constants.GLenum,), doc='glCreateShaderObjectARB(GLenum(shaderType)) -> constants.GLhandleARB', argNames=('shaderType',), deprecated=_DEPRECATED, ) glShaderSourceARB = platform.createExtensionFunction( 'glShaderSourceARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLsizei,ctypes.POINTER( ctypes.POINTER( constants.GLchar )),arrays.GLintArray,), doc='glShaderSourceARB(GLhandleARB(shaderObj), GLsizei(count), POINTER( ctypes.POINTER( constants.GLchar ))(string), GLintArray(length)) -> None', argNames=('shaderObj','count','string','length',), deprecated=_DEPRECATED, ) glCompileShaderARB = platform.createExtensionFunction( 'glCompileShaderARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,), doc='glCompileShaderARB(GLhandleARB(shaderObj)) -> None', argNames=('shaderObj',), deprecated=_DEPRECATED, ) glCreateProgramObjectARB = platform.createExtensionFunction( 'glCreateProgramObjectARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=constants.GLhandleARB, argTypes=(), doc='glCreateProgramObjectARB() -> constants.GLhandleARB', argNames=(), deprecated=_DEPRECATED, ) glAttachObjectARB = platform.createExtensionFunction( 'glAttachObjectARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLhandleARB,), doc='glAttachObjectARB(GLhandleARB(containerObj), GLhandleARB(obj)) -> None', argNames=('containerObj','obj',), deprecated=_DEPRECATED, ) glLinkProgramARB = platform.createExtensionFunction( 'glLinkProgramARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,), doc='glLinkProgramARB(GLhandleARB(programObj)) -> None', argNames=('programObj',), deprecated=_DEPRECATED, ) glUseProgramObjectARB = platform.createExtensionFunction( 'glUseProgramObjectARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,), doc='glUseProgramObjectARB(GLhandleARB(programObj)) -> None', argNames=('programObj',), deprecated=_DEPRECATED, ) glValidateProgramARB = platform.createExtensionFunction( 'glValidateProgramARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,), doc='glValidateProgramARB(GLhandleARB(programObj)) -> None', argNames=('programObj',), deprecated=_DEPRECATED, ) glUniform1fARB = platform.createExtensionFunction( 'glUniform1fARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLfloat,), doc='glUniform1fARB(GLint(location), GLfloat(v0)) -> None', argNames=('location','v0',), deprecated=_DEPRECATED, ) glUniform2fARB = platform.createExtensionFunction( 'glUniform2fARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLfloat,constants.GLfloat,), doc='glUniform2fARB(GLint(location), GLfloat(v0), GLfloat(v1)) -> None', argNames=('location','v0','v1',), deprecated=_DEPRECATED, ) glUniform3fARB = platform.createExtensionFunction( 'glUniform3fARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLfloat,constants.GLfloat,constants.GLfloat,), doc='glUniform3fARB(GLint(location), GLfloat(v0), GLfloat(v1), GLfloat(v2)) -> None', argNames=('location','v0','v1','v2',), deprecated=_DEPRECATED, ) glUniform4fARB = platform.createExtensionFunction( 'glUniform4fARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLfloat,constants.GLfloat,constants.GLfloat,constants.GLfloat,), doc='glUniform4fARB(GLint(location), GLfloat(v0), GLfloat(v1), GLfloat(v2), GLfloat(v3)) -> None', argNames=('location','v0','v1','v2','v3',), deprecated=_DEPRECATED, ) glUniform1iARB = platform.createExtensionFunction( 'glUniform1iARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLint,), doc='glUniform1iARB(GLint(location), GLint(v0)) -> None', argNames=('location','v0',), deprecated=_DEPRECATED, ) glUniform2iARB = platform.createExtensionFunction( 'glUniform2iARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLint,constants.GLint,), doc='glUniform2iARB(GLint(location), GLint(v0), GLint(v1)) -> None', argNames=('location','v0','v1',), deprecated=_DEPRECATED, ) glUniform3iARB = platform.createExtensionFunction( 'glUniform3iARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLint,constants.GLint,constants.GLint,), doc='glUniform3iARB(GLint(location), GLint(v0), GLint(v1), GLint(v2)) -> None', argNames=('location','v0','v1','v2',), deprecated=_DEPRECATED, ) glUniform4iARB = platform.createExtensionFunction( 'glUniform4iARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLint,constants.GLint,constants.GLint,constants.GLint,), doc='glUniform4iARB(GLint(location), GLint(v0), GLint(v1), GLint(v2), GLint(v3)) -> None', argNames=('location','v0','v1','v2','v3',), deprecated=_DEPRECATED, ) glUniform1fvARB = platform.createExtensionFunction( 'glUniform1fvARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,arrays.GLfloatArray,), doc='glUniform1fvARB(GLint(location), GLsizei(count), GLfloatArray(value)) -> None', argNames=('location','count','value',), deprecated=_DEPRECATED, ) glUniform2fvARB = platform.createExtensionFunction( 'glUniform2fvARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,arrays.GLfloatArray,), doc='glUniform2fvARB(GLint(location), GLsizei(count), GLfloatArray(value)) -> None', argNames=('location','count','value',), deprecated=_DEPRECATED, ) glUniform3fvARB = platform.createExtensionFunction( 'glUniform3fvARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,arrays.GLfloatArray,), doc='glUniform3fvARB(GLint(location), GLsizei(count), GLfloatArray(value)) -> None', argNames=('location','count','value',), deprecated=_DEPRECATED, ) glUniform4fvARB = platform.createExtensionFunction( 'glUniform4fvARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,arrays.GLfloatArray,), doc='glUniform4fvARB(GLint(location), GLsizei(count), GLfloatArray(value)) -> None', argNames=('location','count','value',), deprecated=_DEPRECATED, ) glUniform1ivARB = platform.createExtensionFunction( 'glUniform1ivARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,arrays.GLintArray,), doc='glUniform1ivARB(GLint(location), GLsizei(count), GLintArray(value)) -> None', argNames=('location','count','value',), deprecated=_DEPRECATED, ) glUniform2ivARB = platform.createExtensionFunction( 'glUniform2ivARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,arrays.GLintArray,), doc='glUniform2ivARB(GLint(location), GLsizei(count), GLintArray(value)) -> None', argNames=('location','count','value',), deprecated=_DEPRECATED, ) glUniform3ivARB = platform.createExtensionFunction( 'glUniform3ivARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,arrays.GLintArray,), doc='glUniform3ivARB(GLint(location), GLsizei(count), GLintArray(value)) -> None', argNames=('location','count','value',), deprecated=_DEPRECATED, ) glUniform4ivARB = platform.createExtensionFunction( 'glUniform4ivARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,arrays.GLintArray,), doc='glUniform4ivARB(GLint(location), GLsizei(count), GLintArray(value)) -> None', argNames=('location','count','value',), deprecated=_DEPRECATED, ) glUniformMatrix2fvARB = platform.createExtensionFunction( 'glUniformMatrix2fvARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,constants.GLboolean,arrays.GLfloatArray,), doc='glUniformMatrix2fvARB(GLint(location), GLsizei(count), GLboolean(transpose), GLfloatArray(value)) -> None', argNames=('location','count','transpose','value',), deprecated=_DEPRECATED, ) glUniformMatrix3fvARB = platform.createExtensionFunction( 'glUniformMatrix3fvARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,constants.GLboolean,arrays.GLfloatArray,), doc='glUniformMatrix3fvARB(GLint(location), GLsizei(count), GLboolean(transpose), GLfloatArray(value)) -> None', argNames=('location','count','transpose','value',), deprecated=_DEPRECATED, ) glUniformMatrix4fvARB = platform.createExtensionFunction( 'glUniformMatrix4fvARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLint,constants.GLsizei,constants.GLboolean,arrays.GLfloatArray,), doc='glUniformMatrix4fvARB(GLint(location), GLsizei(count), GLboolean(transpose), GLfloatArray(value)) -> None', argNames=('location','count','transpose','value',), deprecated=_DEPRECATED, ) glGetObjectParameterfvARB = platform.createExtensionFunction( 'glGetObjectParameterfvARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLenum,arrays.GLfloatArray,), doc='glGetObjectParameterfvARB(GLhandleARB(obj), GLenum(pname), GLfloatArray(params)) -> None', argNames=('obj','pname','params',), deprecated=_DEPRECATED, ) glGetObjectParameterivARB = platform.createExtensionFunction( 'glGetObjectParameterivARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLenum,arrays.GLintArray,), doc='glGetObjectParameterivARB(GLhandleARB(obj), GLenum(pname), GLintArray(params)) -> None', argNames=('obj','pname','params',), deprecated=_DEPRECATED, ) glGetInfoLogARB = platform.createExtensionFunction( 'glGetInfoLogARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLsizei,arrays.GLsizeiArray,arrays.GLcharARBArray,), doc='glGetInfoLogARB(GLhandleARB(obj), GLsizei(maxLength), GLsizeiArray(length), GLcharARBArray(infoLog)) -> None', argNames=('obj','maxLength','length','infoLog',), deprecated=_DEPRECATED, ) glGetAttachedObjectsARB = platform.createExtensionFunction( 'glGetAttachedObjectsARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLsizei,arrays.GLsizeiArray,arrays.GLuintArray,), doc='glGetAttachedObjectsARB(GLhandleARB(containerObj), GLsizei(maxCount), GLsizeiArray(count), GLuintArray(obj)) -> None', argNames=('containerObj','maxCount','count','obj',), deprecated=_DEPRECATED, ) glGetUniformLocationARB = platform.createExtensionFunction( 'glGetUniformLocationARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=constants.GLint, argTypes=(constants.GLhandleARB,arrays.GLcharARBArray,), doc='glGetUniformLocationARB(GLhandleARB(programObj), GLcharARBArray(name)) -> constants.GLint', argNames=('programObj','name',), deprecated=_DEPRECATED, ) glGetActiveUniformARB = platform.createExtensionFunction( 'glGetActiveUniformARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLuint,constants.GLsizei,arrays.GLsizeiArray,arrays.GLintArray,arrays.GLuintArray,arrays.GLcharARBArray,), doc='glGetActiveUniformARB(GLhandleARB(programObj), GLuint(index), GLsizei(maxLength), GLsizeiArray(length), GLintArray(size), GLuintArray(type), GLcharARBArray(name)) -> None', argNames=('programObj','index','maxLength','length','size','type','name',), deprecated=_DEPRECATED, ) glGetUniformfvARB = platform.createExtensionFunction( 'glGetUniformfvARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLint,arrays.GLfloatArray,), doc='glGetUniformfvARB(GLhandleARB(programObj), GLint(location), GLfloatArray(params)) -> None', argNames=('programObj','location','params',), deprecated=_DEPRECATED, ) glGetUniformivARB = platform.createExtensionFunction( 'glGetUniformivARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLint,arrays.GLintArray,), doc='glGetUniformivARB(GLhandleARB(programObj), GLint(location), GLintArray(params)) -> None', argNames=('programObj','location','params',), deprecated=_DEPRECATED, ) glGetShaderSourceARB = platform.createExtensionFunction( 'glGetShaderSourceARB',dll=platform.GL, extension=EXTENSION_NAME, resultType=None, argTypes=(constants.GLhandleARB,constants.GLsizei,arrays.GLsizeiArray,arrays.GLcharARBArray,), doc='glGetShaderSourceARB(GLhandleARB(obj), GLsizei(maxLength), GLsizeiArray(length), GLcharARBArray(source)) -> None', argNames=('obj','maxLength','length','source',), deprecated=_DEPRECATED, ) def glInitShaderObjectsARB(): '''Return boolean indicating whether this extension is available''' return extensions.hasGLExtension( EXTENSION_NAME )
mit
[ 2344, 4299, 2226, 3329, 4160, 34, 14, 18116, 63, 1462, 199, 199, 3358, 17174, 4046, 701, 314, 664, 63, 3528, 63, 5359, 2884, 12, 886, 440, 5283, 1, 199, 2344, 199, 504, 24374, 492, 4298, 12, 5262, 12, 4413, 12, 6572, 199, 504, 24374, 492, 5478, 199, 504, 24374, 14, 2226, 492, 6482, 362, 199, 646, 5577, 199, 15498, 63, 2339, 275, 283, 2226, 63, 8611, 63, 18116, 63, 1462, 7, 199, 63, 25832, 275, 756, 199, 2226, 63, 15605, 63, 9868, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 15605, 63, 9868, 63, 8611, 297, 378, 88, 24, 34, 2167, 776, 199, 2226, 63, 3234, 21372, 63, 9868, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 3234, 21372, 63, 9868, 63, 8611, 297, 378, 88, 24, 34, 2006, 776, 199, 2226, 63, 9868, 63, 2711, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 2711, 63, 8611, 297, 378, 88, 24, 34, 20, 37, 776, 199, 2226, 63, 9868, 63, 6348, 2711, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 6348, 2711, 63, 8611, 297, 378, 88, 24, 34, 20, 38, 776, 199, 2226, 63, 11783, 63, 2524, 35, 18, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 2524, 35, 18, 63, 8611, 297, 378, 88, 24, 34, 1400, 776, 199, 2226, 63, 11783, 63, 2524, 35, 19, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 2524, 35, 19, 63, 8611, 297, 378, 88, 24, 34, 2869, 776, 199, 2226, 63, 11783, 63, 2524, 35, 20, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 2524, 35, 20, 63, 8611, 297, 378, 88, 24, 34, 2528, 776, 199, 2226, 63, 2919, 63, 2524, 35, 18, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 2919, 63, 2524, 35, 18, 63, 8611, 297, 378, 88, 24, 34, 2481, 776, 199, 2226, 63, 2919, 63, 2524, 35, 19, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 2919, 63, 2524, 35, 19, 63, 8611, 297, 378, 88, 24, 34, 1477, 776, 199, 2226, 63, 2919, 63, 2524, 35, 20, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 2919, 63, 2524, 35, 20, 63, 8611, 297, 378, 88, 24, 34, 1229, 776, 199, 2226, 63, 16026, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 16026, 63, 8611, 297, 378, 88, 24, 34, 1367, 776, 199, 2226, 63, 16026, 63, 2524, 35, 18, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 16026, 63, 2524, 35, 18, 63, 8611, 297, 378, 88, 24, 34, 1641, 776, 199, 2226, 63, 16026, 63, 2524, 35, 19, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 16026, 63, 2524, 35, 19, 63, 8611, 297, 378, 88, 24, 34, 2010, 776, 199, 2226, 63, 16026, 63, 2524, 35, 20, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 16026, 63, 2524, 35, 20, 63, 8611, 297, 378, 88, 24, 34, 1427, 776, 199, 2226, 63, 11783, 63, 16996, 18, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 16996, 18, 63, 8611, 297, 378, 88, 24, 34, 21, 33, 776, 199, 2226, 63, 11783, 63, 16996, 19, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 16996, 19, 63, 8611, 297, 378, 88, 24, 34, 21, 34, 776, 199, 2226, 63, 11783, 63, 16996, 20, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 16996, 20, 63, 8611, 297, 378, 88, 24, 34, 21, 35, 776, 199, 2226, 63, 51, 7855, 540, 63, 17, 36, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 17, 36, 63, 8611, 297, 378, 88, 24, 34, 21, 36, 776, 199, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 8611, 297, 378, 88, 24, 34, 21, 37, 776, 199, 2226, 63, 51, 7855, 540, 63, 19, 36, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 19, 36, 63, 8611, 297, 378, 88, 24, 34, 21, 38, 776, 199, 2226, 63, 51, 7855, 540, 63, 35, 21857, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 35, 21857, 63, 8611, 297, 378, 88, 24, 34, 2259, 776, 199, 2226, 63, 51, 7855, 540, 63, 17, 36, 63, 3234, 1554, 19716, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 17, 36, 63, 3234, 1554, 19716, 63, 8611, 297, 378, 88, 24, 34, 2976, 776, 199, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 3234, 1554, 19716, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 3234, 1554, 19716, 63, 8611, 297, 378, 88, 24, 34, 2789, 776, 199, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 4168, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 4168, 63, 8611, 297, 378, 88, 24, 34, 2766, 776, 199, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 4168, 63, 3234, 1554, 19716, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 4168, 63, 3234, 1554, 19716, 63, 8611, 297, 378, 88, 24, 34, 772, 776, 199, 2226, 63, 9868, 63, 7014, 63, 6305, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 7014, 63, 6305, 63, 8611, 297, 378, 88, 24, 34, 1257, 776, 199, 2226, 63, 9868, 63, 29911, 63, 6305, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 29911, 63, 6305, 63, 8611, 297, 378, 88, 24, 34, 2835, 776, 199, 2226, 63, 9868, 63, 7916, 63, 6305, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 7916, 63, 6305, 63, 8611, 297, 378, 88, 24, 34, 2564, 776, 199, 2226, 63, 9868, 63, 5600, 1951, 63, 6305, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 5600 ]
[ 4299, 2226, 3329, 4160, 34, 14, 18116, 63, 1462, 199, 199, 3358, 17174, 4046, 701, 314, 664, 63, 3528, 63, 5359, 2884, 12, 886, 440, 5283, 1, 199, 2344, 199, 504, 24374, 492, 4298, 12, 5262, 12, 4413, 12, 6572, 199, 504, 24374, 492, 5478, 199, 504, 24374, 14, 2226, 492, 6482, 362, 199, 646, 5577, 199, 15498, 63, 2339, 275, 283, 2226, 63, 8611, 63, 18116, 63, 1462, 7, 199, 63, 25832, 275, 756, 199, 2226, 63, 15605, 63, 9868, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 15605, 63, 9868, 63, 8611, 297, 378, 88, 24, 34, 2167, 776, 199, 2226, 63, 3234, 21372, 63, 9868, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 3234, 21372, 63, 9868, 63, 8611, 297, 378, 88, 24, 34, 2006, 776, 199, 2226, 63, 9868, 63, 2711, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 2711, 63, 8611, 297, 378, 88, 24, 34, 20, 37, 776, 199, 2226, 63, 9868, 63, 6348, 2711, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 6348, 2711, 63, 8611, 297, 378, 88, 24, 34, 20, 38, 776, 199, 2226, 63, 11783, 63, 2524, 35, 18, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 2524, 35, 18, 63, 8611, 297, 378, 88, 24, 34, 1400, 776, 199, 2226, 63, 11783, 63, 2524, 35, 19, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 2524, 35, 19, 63, 8611, 297, 378, 88, 24, 34, 2869, 776, 199, 2226, 63, 11783, 63, 2524, 35, 20, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 2524, 35, 20, 63, 8611, 297, 378, 88, 24, 34, 2528, 776, 199, 2226, 63, 2919, 63, 2524, 35, 18, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 2919, 63, 2524, 35, 18, 63, 8611, 297, 378, 88, 24, 34, 2481, 776, 199, 2226, 63, 2919, 63, 2524, 35, 19, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 2919, 63, 2524, 35, 19, 63, 8611, 297, 378, 88, 24, 34, 1477, 776, 199, 2226, 63, 2919, 63, 2524, 35, 20, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 2919, 63, 2524, 35, 20, 63, 8611, 297, 378, 88, 24, 34, 1229, 776, 199, 2226, 63, 16026, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 16026, 63, 8611, 297, 378, 88, 24, 34, 1367, 776, 199, 2226, 63, 16026, 63, 2524, 35, 18, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 16026, 63, 2524, 35, 18, 63, 8611, 297, 378, 88, 24, 34, 1641, 776, 199, 2226, 63, 16026, 63, 2524, 35, 19, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 16026, 63, 2524, 35, 19, 63, 8611, 297, 378, 88, 24, 34, 2010, 776, 199, 2226, 63, 16026, 63, 2524, 35, 20, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 16026, 63, 2524, 35, 20, 63, 8611, 297, 378, 88, 24, 34, 1427, 776, 199, 2226, 63, 11783, 63, 16996, 18, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 16996, 18, 63, 8611, 297, 378, 88, 24, 34, 21, 33, 776, 199, 2226, 63, 11783, 63, 16996, 19, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 16996, 19, 63, 8611, 297, 378, 88, 24, 34, 21, 34, 776, 199, 2226, 63, 11783, 63, 16996, 20, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 11783, 63, 16996, 20, 63, 8611, 297, 378, 88, 24, 34, 21, 35, 776, 199, 2226, 63, 51, 7855, 540, 63, 17, 36, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 17, 36, 63, 8611, 297, 378, 88, 24, 34, 21, 36, 776, 199, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 8611, 297, 378, 88, 24, 34, 21, 37, 776, 199, 2226, 63, 51, 7855, 540, 63, 19, 36, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 19, 36, 63, 8611, 297, 378, 88, 24, 34, 21, 38, 776, 199, 2226, 63, 51, 7855, 540, 63, 35, 21857, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 35, 21857, 63, 8611, 297, 378, 88, 24, 34, 2259, 776, 199, 2226, 63, 51, 7855, 540, 63, 17, 36, 63, 3234, 1554, 19716, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 17, 36, 63, 3234, 1554, 19716, 63, 8611, 297, 378, 88, 24, 34, 2976, 776, 199, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 3234, 1554, 19716, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 3234, 1554, 19716, 63, 8611, 297, 378, 88, 24, 34, 2789, 776, 199, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 4168, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 4168, 63, 8611, 297, 378, 88, 24, 34, 2766, 776, 199, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 4168, 63, 3234, 1554, 19716, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 51, 7855, 540, 63, 18, 36, 63, 4168, 63, 3234, 1554, 19716, 63, 8611, 297, 378, 88, 24, 34, 772, 776, 199, 2226, 63, 9868, 63, 7014, 63, 6305, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 7014, 63, 6305, 63, 8611, 297, 378, 88, 24, 34, 1257, 776, 199, 2226, 63, 9868, 63, 29911, 63, 6305, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 29911, 63, 6305, 63, 8611, 297, 378, 88, 24, 34, 2835, 776, 199, 2226, 63, 9868, 63, 7916, 63, 6305, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 7916, 63, 6305, 63, 8611, 297, 378, 88, 24, 34, 2564, 776, 199, 2226, 63, 9868, 63, 5600, 1951, 63, 6305, 63, 8611, 275, 4413, 14, 9737, 8, 283, 2226, 63, 9868, 63, 5600, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
powerjg/gem5-ci-test
src/python/m5/internal/params.py
8
2361
# Copyright (c) 2017 ARM Limited # All rights reserved. # # The license below extends only to copyright in the software and shall # not be construed as granting a license to any other intellectual # property including but not limited to intellectual property relating # to a hardware implementation of the functionality of the software # licensed hereunder. You may use the software subject to the license # terms below provided that you ensure that this notice is replicated # unmodified and in its entirety in all distributions of the software, # modified or unmodified, in source code or in binary form. # # Copyright (c) 2010 The Hewlett-Packard Development Company # 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 the copyright holders 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. # # Authors: Nathan Binkert import inspect import _m5 for name, module in inspect.getmembers(_m5): if name.startswith('param_') or name.startswith('enum_'): exec "from _m5.%s import *" % name
bsd-3-clause
[ 3, 1898, 334, 67, 9, 9708, 27155, 23954, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 710, 4190, 5084, 16879, 1454, 370, 4248, 315, 314, 2032, 436, 10989, 199, 3, 440, 506, 950, 431, 68, 465, 16085, 316, 282, 4190, 370, 1263, 1163, 27925, 1264, 1061, 199, 3, 3324, 5893, 1325, 440, 13988, 370, 27925, 1264, 1061, 3324, 4668, 1958, 199, 3, 370, 282, 14991, 4514, 402, 314, 9330, 402, 314, 2032, 199, 3, 18233, 2348, 7138, 14, 221, 2047, 1443, 675, 314, 2032, 5420, 370, 314, 4190, 199, 3, 2895, 5084, 2741, 626, 1265, 4868, 626, 642, 4245, 365, 32436, 199, 3, 24214, 436, 315, 2399, 8039, 369, 315, 1006, 10208, 402, 314, 2032, 12, 199, 3, 6042, 503, 24214, 12, 315, 1350, 1233, 503, 315, 3366, 1824, 14, 199, 3, 199, 3, 1898, 334, 67, 9, 7129, 710, 27849, 13, 29471, 15290, 15878, 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, 26771, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 27, 199, 3, 26771, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 27, 199, 3, 15564, 314, 536, 402, 314, 4248, 31976, 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, 3, 199, 3, 6642, 26, 653, 1619, 290, 699, 2292, 15299, 199, 199, 646, 6485, 199, 646, 485, 77, 21, 199, 199, 509, 536, 12, 859, 315, 6485, 14, 28719, 1547, 77, 21, 304, 272, 340, 536, 14, 2460, 360, 635, 15452, 503, 536, 14, 2460, 360, 4869, 25865, 267, 2146, 298, 504, 485, 77, 21, 4111, 83, 492, 14390, 450, 536, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 27155, 23954, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 710, 4190, 5084, 16879, 1454, 370, 4248, 315, 314, 2032, 436, 10989, 199, 3, 440, 506, 950, 431, 68, 465, 16085, 316, 282, 4190, 370, 1263, 1163, 27925, 1264, 1061, 199, 3, 3324, 5893, 1325, 440, 13988, 370, 27925, 1264, 1061, 3324, 4668, 1958, 199, 3, 370, 282, 14991, 4514, 402, 314, 9330, 402, 314, 2032, 199, 3, 18233, 2348, 7138, 14, 221, 2047, 1443, 675, 314, 2032, 5420, 370, 314, 4190, 199, 3, 2895, 5084, 2741, 626, 1265, 4868, 626, 642, 4245, 365, 32436, 199, 3, 24214, 436, 315, 2399, 8039, 369, 315, 1006, 10208, 402, 314, 2032, 12, 199, 3, 6042, 503, 24214, 12, 315, 1350, 1233, 503, 315, 3366, 1824, 14, 199, 3, 199, 3, 1898, 334, 67, 9, 7129, 710, 27849, 13, 29471, 15290, 15878, 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, 26771, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 27, 199, 3, 26771, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 27, 199, 3, 15564, 314, 536, 402, 314, 4248, 31976, 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, 3, 199, 3, 6642, 26, 653, 1619, 290, 699, 2292, 15299, 199, 199, 646, 6485, 199, 646, 485, 77, 21, 199, 199, 509, 536, 12, 859, 315, 6485, 14, 28719, 1547, 77, 21, 304, 272, 340, 536, 14, 2460, 360, 635, 15452, 503, 536, 14, 2460, 360, 4869, 25865, 267, 2146, 298, 504, 485, 77, 21, 4111, 83, 492, 14390, 450, 536, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
jiangzhuo/kbengine
kbe/src/lib/python/Lib/encodings/tis_620.py
272
12300
""" Python Character Mapping Codec tis_620 generated from 'python-mappings/TIS-620.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='tis-620', encode=Codec().encode, decode=Codec().decode, incrementalencoder=IncrementalEncoder, incrementaldecoder=IncrementalDecoder, streamreader=StreamReader, streamwriter=StreamWriter, ) ### Decoding Table decoding_table = ( '\x00' # 0x00 -> NULL '\x01' # 0x01 -> START OF HEADING '\x02' # 0x02 -> START OF TEXT '\x03' # 0x03 -> END OF TEXT '\x04' # 0x04 -> END OF TRANSMISSION '\x05' # 0x05 -> ENQUIRY '\x06' # 0x06 -> ACKNOWLEDGE '\x07' # 0x07 -> BELL '\x08' # 0x08 -> BACKSPACE '\t' # 0x09 -> HORIZONTAL TABULATION '\n' # 0x0A -> LINE FEED '\x0b' # 0x0B -> VERTICAL TABULATION '\x0c' # 0x0C -> FORM FEED '\r' # 0x0D -> CARRIAGE RETURN '\x0e' # 0x0E -> SHIFT OUT '\x0f' # 0x0F -> SHIFT IN '\x10' # 0x10 -> DATA LINK ESCAPE '\x11' # 0x11 -> DEVICE CONTROL ONE '\x12' # 0x12 -> DEVICE CONTROL TWO '\x13' # 0x13 -> DEVICE CONTROL THREE '\x14' # 0x14 -> DEVICE CONTROL FOUR '\x15' # 0x15 -> NEGATIVE ACKNOWLEDGE '\x16' # 0x16 -> SYNCHRONOUS IDLE '\x17' # 0x17 -> END OF TRANSMISSION BLOCK '\x18' # 0x18 -> CANCEL '\x19' # 0x19 -> END OF MEDIUM '\x1a' # 0x1A -> SUBSTITUTE '\x1b' # 0x1B -> ESCAPE '\x1c' # 0x1C -> FILE SEPARATOR '\x1d' # 0x1D -> GROUP SEPARATOR '\x1e' # 0x1E -> RECORD SEPARATOR '\x1f' # 0x1F -> UNIT SEPARATOR ' ' # 0x20 -> SPACE '!' # 0x21 -> EXCLAMATION MARK '"' # 0x22 -> QUOTATION MARK '#' # 0x23 -> NUMBER SIGN '$' # 0x24 -> DOLLAR SIGN '%' # 0x25 -> PERCENT SIGN '&' # 0x26 -> AMPERSAND "'" # 0x27 -> APOSTROPHE '(' # 0x28 -> LEFT PARENTHESIS ')' # 0x29 -> RIGHT PARENTHESIS '*' # 0x2A -> ASTERISK '+' # 0x2B -> PLUS SIGN ',' # 0x2C -> COMMA '-' # 0x2D -> HYPHEN-MINUS '.' # 0x2E -> FULL STOP '/' # 0x2F -> SOLIDUS '0' # 0x30 -> DIGIT ZERO '1' # 0x31 -> DIGIT ONE '2' # 0x32 -> DIGIT TWO '3' # 0x33 -> DIGIT THREE '4' # 0x34 -> DIGIT FOUR '5' # 0x35 -> DIGIT FIVE '6' # 0x36 -> DIGIT SIX '7' # 0x37 -> DIGIT SEVEN '8' # 0x38 -> DIGIT EIGHT '9' # 0x39 -> DIGIT NINE ':' # 0x3A -> COLON ';' # 0x3B -> SEMICOLON '<' # 0x3C -> LESS-THAN SIGN '=' # 0x3D -> EQUALS SIGN '>' # 0x3E -> GREATER-THAN SIGN '?' # 0x3F -> QUESTION MARK '@' # 0x40 -> COMMERCIAL AT 'A' # 0x41 -> LATIN CAPITAL LETTER A 'B' # 0x42 -> LATIN CAPITAL LETTER B 'C' # 0x43 -> LATIN CAPITAL LETTER C 'D' # 0x44 -> LATIN CAPITAL LETTER D 'E' # 0x45 -> LATIN CAPITAL LETTER E 'F' # 0x46 -> LATIN CAPITAL LETTER F 'G' # 0x47 -> LATIN CAPITAL LETTER G 'H' # 0x48 -> LATIN CAPITAL LETTER H 'I' # 0x49 -> LATIN CAPITAL LETTER I 'J' # 0x4A -> LATIN CAPITAL LETTER J 'K' # 0x4B -> LATIN CAPITAL LETTER K 'L' # 0x4C -> LATIN CAPITAL LETTER L 'M' # 0x4D -> LATIN CAPITAL LETTER M 'N' # 0x4E -> LATIN CAPITAL LETTER N 'O' # 0x4F -> LATIN CAPITAL LETTER O 'P' # 0x50 -> LATIN CAPITAL LETTER P 'Q' # 0x51 -> LATIN CAPITAL LETTER Q 'R' # 0x52 -> LATIN CAPITAL LETTER R 'S' # 0x53 -> LATIN CAPITAL LETTER S 'T' # 0x54 -> LATIN CAPITAL LETTER T 'U' # 0x55 -> LATIN CAPITAL LETTER U 'V' # 0x56 -> LATIN CAPITAL LETTER V 'W' # 0x57 -> LATIN CAPITAL LETTER W 'X' # 0x58 -> LATIN CAPITAL LETTER X 'Y' # 0x59 -> LATIN CAPITAL LETTER Y 'Z' # 0x5A -> LATIN CAPITAL LETTER Z '[' # 0x5B -> LEFT SQUARE BRACKET '\\' # 0x5C -> REVERSE SOLIDUS ']' # 0x5D -> RIGHT SQUARE BRACKET '^' # 0x5E -> CIRCUMFLEX ACCENT '_' # 0x5F -> LOW LINE '`' # 0x60 -> GRAVE ACCENT 'a' # 0x61 -> LATIN SMALL LETTER A 'b' # 0x62 -> LATIN SMALL LETTER B 'c' # 0x63 -> LATIN SMALL LETTER C 'd' # 0x64 -> LATIN SMALL LETTER D 'e' # 0x65 -> LATIN SMALL LETTER E 'f' # 0x66 -> LATIN SMALL LETTER F 'g' # 0x67 -> LATIN SMALL LETTER G 'h' # 0x68 -> LATIN SMALL LETTER H 'i' # 0x69 -> LATIN SMALL LETTER I 'j' # 0x6A -> LATIN SMALL LETTER J 'k' # 0x6B -> LATIN SMALL LETTER K 'l' # 0x6C -> LATIN SMALL LETTER L 'm' # 0x6D -> LATIN SMALL LETTER M 'n' # 0x6E -> LATIN SMALL LETTER N 'o' # 0x6F -> LATIN SMALL LETTER O 'p' # 0x70 -> LATIN SMALL LETTER P 'q' # 0x71 -> LATIN SMALL LETTER Q 'r' # 0x72 -> LATIN SMALL LETTER R 's' # 0x73 -> LATIN SMALL LETTER S 't' # 0x74 -> LATIN SMALL LETTER T 'u' # 0x75 -> LATIN SMALL LETTER U 'v' # 0x76 -> LATIN SMALL LETTER V 'w' # 0x77 -> LATIN SMALL LETTER W 'x' # 0x78 -> LATIN SMALL LETTER X 'y' # 0x79 -> LATIN SMALL LETTER Y 'z' # 0x7A -> LATIN SMALL LETTER Z '{' # 0x7B -> LEFT CURLY BRACKET '|' # 0x7C -> VERTICAL LINE '}' # 0x7D -> RIGHT CURLY BRACKET '~' # 0x7E -> TILDE '\x7f' # 0x7F -> DELETE '\x80' # 0x80 -> <control> '\x81' # 0x81 -> <control> '\x82' # 0x82 -> <control> '\x83' # 0x83 -> <control> '\x84' # 0x84 -> <control> '\x85' # 0x85 -> <control> '\x86' # 0x86 -> <control> '\x87' # 0x87 -> <control> '\x88' # 0x88 -> <control> '\x89' # 0x89 -> <control> '\x8a' # 0x8A -> <control> '\x8b' # 0x8B -> <control> '\x8c' # 0x8C -> <control> '\x8d' # 0x8D -> <control> '\x8e' # 0x8E -> <control> '\x8f' # 0x8F -> <control> '\x90' # 0x90 -> <control> '\x91' # 0x91 -> <control> '\x92' # 0x92 -> <control> '\x93' # 0x93 -> <control> '\x94' # 0x94 -> <control> '\x95' # 0x95 -> <control> '\x96' # 0x96 -> <control> '\x97' # 0x97 -> <control> '\x98' # 0x98 -> <control> '\x99' # 0x99 -> <control> '\x9a' # 0x9A -> <control> '\x9b' # 0x9B -> <control> '\x9c' # 0x9C -> <control> '\x9d' # 0x9D -> <control> '\x9e' # 0x9E -> <control> '\x9f' # 0x9F -> <control> '\ufffe' '\u0e01' # 0xA1 -> THAI CHARACTER KO KAI '\u0e02' # 0xA2 -> THAI CHARACTER KHO KHAI '\u0e03' # 0xA3 -> THAI CHARACTER KHO KHUAT '\u0e04' # 0xA4 -> THAI CHARACTER KHO KHWAI '\u0e05' # 0xA5 -> THAI CHARACTER KHO KHON '\u0e06' # 0xA6 -> THAI CHARACTER KHO RAKHANG '\u0e07' # 0xA7 -> THAI CHARACTER NGO NGU '\u0e08' # 0xA8 -> THAI CHARACTER CHO CHAN '\u0e09' # 0xA9 -> THAI CHARACTER CHO CHING '\u0e0a' # 0xAA -> THAI CHARACTER CHO CHANG '\u0e0b' # 0xAB -> THAI CHARACTER SO SO '\u0e0c' # 0xAC -> THAI CHARACTER CHO CHOE '\u0e0d' # 0xAD -> THAI CHARACTER YO YING '\u0e0e' # 0xAE -> THAI CHARACTER DO CHADA '\u0e0f' # 0xAF -> THAI CHARACTER TO PATAK '\u0e10' # 0xB0 -> THAI CHARACTER THO THAN '\u0e11' # 0xB1 -> THAI CHARACTER THO NANGMONTHO '\u0e12' # 0xB2 -> THAI CHARACTER THO PHUTHAO '\u0e13' # 0xB3 -> THAI CHARACTER NO NEN '\u0e14' # 0xB4 -> THAI CHARACTER DO DEK '\u0e15' # 0xB5 -> THAI CHARACTER TO TAO '\u0e16' # 0xB6 -> THAI CHARACTER THO THUNG '\u0e17' # 0xB7 -> THAI CHARACTER THO THAHAN '\u0e18' # 0xB8 -> THAI CHARACTER THO THONG '\u0e19' # 0xB9 -> THAI CHARACTER NO NU '\u0e1a' # 0xBA -> THAI CHARACTER BO BAIMAI '\u0e1b' # 0xBB -> THAI CHARACTER PO PLA '\u0e1c' # 0xBC -> THAI CHARACTER PHO PHUNG '\u0e1d' # 0xBD -> THAI CHARACTER FO FA '\u0e1e' # 0xBE -> THAI CHARACTER PHO PHAN '\u0e1f' # 0xBF -> THAI CHARACTER FO FAN '\u0e20' # 0xC0 -> THAI CHARACTER PHO SAMPHAO '\u0e21' # 0xC1 -> THAI CHARACTER MO MA '\u0e22' # 0xC2 -> THAI CHARACTER YO YAK '\u0e23' # 0xC3 -> THAI CHARACTER RO RUA '\u0e24' # 0xC4 -> THAI CHARACTER RU '\u0e25' # 0xC5 -> THAI CHARACTER LO LING '\u0e26' # 0xC6 -> THAI CHARACTER LU '\u0e27' # 0xC7 -> THAI CHARACTER WO WAEN '\u0e28' # 0xC8 -> THAI CHARACTER SO SALA '\u0e29' # 0xC9 -> THAI CHARACTER SO RUSI '\u0e2a' # 0xCA -> THAI CHARACTER SO SUA '\u0e2b' # 0xCB -> THAI CHARACTER HO HIP '\u0e2c' # 0xCC -> THAI CHARACTER LO CHULA '\u0e2d' # 0xCD -> THAI CHARACTER O ANG '\u0e2e' # 0xCE -> THAI CHARACTER HO NOKHUK '\u0e2f' # 0xCF -> THAI CHARACTER PAIYANNOI '\u0e30' # 0xD0 -> THAI CHARACTER SARA A '\u0e31' # 0xD1 -> THAI CHARACTER MAI HAN-AKAT '\u0e32' # 0xD2 -> THAI CHARACTER SARA AA '\u0e33' # 0xD3 -> THAI CHARACTER SARA AM '\u0e34' # 0xD4 -> THAI CHARACTER SARA I '\u0e35' # 0xD5 -> THAI CHARACTER SARA II '\u0e36' # 0xD6 -> THAI CHARACTER SARA UE '\u0e37' # 0xD7 -> THAI CHARACTER SARA UEE '\u0e38' # 0xD8 -> THAI CHARACTER SARA U '\u0e39' # 0xD9 -> THAI CHARACTER SARA UU '\u0e3a' # 0xDA -> THAI CHARACTER PHINTHU '\ufffe' '\ufffe' '\ufffe' '\ufffe' '\u0e3f' # 0xDF -> THAI CURRENCY SYMBOL BAHT '\u0e40' # 0xE0 -> THAI CHARACTER SARA E '\u0e41' # 0xE1 -> THAI CHARACTER SARA AE '\u0e42' # 0xE2 -> THAI CHARACTER SARA O '\u0e43' # 0xE3 -> THAI CHARACTER SARA AI MAIMUAN '\u0e44' # 0xE4 -> THAI CHARACTER SARA AI MAIMALAI '\u0e45' # 0xE5 -> THAI CHARACTER LAKKHANGYAO '\u0e46' # 0xE6 -> THAI CHARACTER MAIYAMOK '\u0e47' # 0xE7 -> THAI CHARACTER MAITAIKHU '\u0e48' # 0xE8 -> THAI CHARACTER MAI EK '\u0e49' # 0xE9 -> THAI CHARACTER MAI THO '\u0e4a' # 0xEA -> THAI CHARACTER MAI TRI '\u0e4b' # 0xEB -> THAI CHARACTER MAI CHATTAWA '\u0e4c' # 0xEC -> THAI CHARACTER THANTHAKHAT '\u0e4d' # 0xED -> THAI CHARACTER NIKHAHIT '\u0e4e' # 0xEE -> THAI CHARACTER YAMAKKAN '\u0e4f' # 0xEF -> THAI CHARACTER FONGMAN '\u0e50' # 0xF0 -> THAI DIGIT ZERO '\u0e51' # 0xF1 -> THAI DIGIT ONE '\u0e52' # 0xF2 -> THAI DIGIT TWO '\u0e53' # 0xF3 -> THAI DIGIT THREE '\u0e54' # 0xF4 -> THAI DIGIT FOUR '\u0e55' # 0xF5 -> THAI DIGIT FIVE '\u0e56' # 0xF6 -> THAI DIGIT SIX '\u0e57' # 0xF7 -> THAI DIGIT SEVEN '\u0e58' # 0xF8 -> THAI DIGIT EIGHT '\u0e59' # 0xF9 -> THAI DIGIT NINE '\u0e5a' # 0xFA -> THAI CHARACTER ANGKHANKHU '\u0e5b' # 0xFB -> THAI CHARACTER KHOMUT '\ufffe' '\ufffe' '\ufffe' '\ufffe' ) ### Encoding table encoding_table=codecs.charmap_build(decoding_table)
lgpl-3.0
[ 624, 2018, 17660, 12340, 13732, 3367, 83, 63, 22085, 4046, 687, 283, 1548, 13, 14632, 15, 52, 1311, 13, 22085, 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, 16753, 13, 22085, 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, 258, 327, 221, 378, 88, 383, 1035, 5962, 272, 1557, 88, 614, 7, 258, 327, 221, 378, 88, 614, 1035, 13910, 1634, 32674, 272, 1557, 88, 996, 7, 258, 327, 221, 378, 88, 996, 1035, 13910, 1634, 11951, 272, 1557, 88, 1644, 7, 258, 327, 221, 378, 88, 1644, 1035, 7729, 1634, 11951, 272, 1557, 88, 966, 7, 258, 327, 221, 378, 88, 966, 1035, 7729, 1634, 22499, 272, 1557, 88, 1717, 7, 258, 327, 221, 378, 88, 1717, 1035, 5070, 31115, 57, 272, 1557, 88, 1690, 7, 258, 327, 221, 378, 88, 1690, 1035, 22549, 272, 1557, 88, 1780, 7, 258, 327, 221, 378, 88, 1780, 1035, 699, 14952, 272, 1557, 88, 2036, 7, 258, 327, 221, 378, 88, 2036, 1035, 22658, 11658, 272, 1557, 84, 7, 755, 327, 221, 378, 88, 1643, 1035, 8724, 22450, 272, 1557, 78, 7, 755, 327, 221, 378, 88, 16, 33, 1035, 13587, 21567, 272, 1557, 88, 16, 66, 7, 258, 327, 221, 378, 88, 16, 34, 1035, 8267, 22450, 272, 1557, 88, 16, 67, 7, 258, 327, 221, 378, 88, 16, 35, 1035, 11295, 21567, 272, 1557, 82, 7, 755, 327, 221, 378, 88, 16, 36, 1035, 445, 32622, 24646, 272, 1557, 88, 16, 69, 7, 258, 327, 221, 378, 88, 16, 37, 1035, 20754, 5738, 272, 1557, 88, 16, 70, 7, 258, 327, 221, 378, 88, 16, 38, 1035, 20754, 1621, 272, 1557, 88, 709, 7, 258, 327, 221, 378, 88, 709, 1035, 7126, 19774, 17682, 272, 1557, 88, 845, 7, 258, 327, 221, 378, 88, 845, 1035, 11643, 8098, 13051, 272, 1557, 88, 713, 7, 258, 327, 221, 378, 88, 713, 1035, 11643, 8098, 16562, 272, 1557, 88, 969, 7, 258, 327, 221, 378, 88, 969, 1035, 11643, 8098, 16296, 272, 1557, 88, 1079, 7, 258, 327, 221, 378, 88, 1079, 1035, 11643, 8098, 14473, 272, 1557, 88, 1046, 7, 258, 327, 221, 378, 88, 1046, 1035, 29837, 22549, 272, 1557, 88, 975, 7, 258, 327, 221, 378, 88, 975, 1035, 10046, 30782, 23240, 272, 1557, 88, 1196, 7, 258, 327, 221, 378, 88, 1196, 1035, 7729, 1634, 22499, 8068, 272, 1557, 88, 1085, 7, 258, 327, 221, 378, 88, 1085, 1035, 27385, 272, 1557, 88, 1167, 7, 258, 327, 221, 378, 88, 1167, 1035, 7729, 1634, 22650, 272, 1557, 88, 17, 65, 7, 258, 327, 221, 378, 88, 17, 33, 1035, 9103, 272, 1557, 88, 17, 66, 7, 258, 327, 221, 378, 88, 17, 34, 1035, 17682, 272, 1557, 88, 17, 67, 7, 258, 327, 221, 378, 88, 17, 35, 1035, 13024, 14782, 272, 1557, 88, 17, 68, 7, 258, 327, 221, 378, 88, 17, 36, 1035, 15443, 14782, 272, 1557, 88, 17, 69, 7, 258, 327, 221, 378, 88, 17, 37, 1035, 24973, 14782, 272, 1557, 88, 17, 70, 7, 258, 327, 221, 378, 88, 17, 38, 1035, 25836, 14782, 272, 283, 283, 263, 327, 221, 378, 88, 1165, 1035, 16796, 272, 29376, 263, 327, 221, 378, 88, 2025, 1035, 24232, 8132, 272, 14788, 263, 327, 221, 378, 88, 1081, 1035, 11830, 8132, 272, 19619, 263, 327, 221, 378, 88, 1789, 1035, 18122, 5056, 272, 25271, 263, 327, 221, 378, 88, 1194, 1035, 30857, 5056, 272, 26386, 263, 327, 221, 378, 88, 821, 1035, 26684, 5056, 272, 29285, 263, 327, 221, 378, 88, 1479, 1035, 30602, 272, 21673, 263, 327, 221, 378, 88, 1465, 1035, 30876, 272, 16746, 263, 327, 221, 378, 88, 1651, 1035, 6578, 20570, 272, 16107, 263, 327, 221, 378, 88, 1398, 1035, 7052, 20570, 272, 13626, 263, 327, 221, 378, 88, 18, 33, 1035, 29725, 272, 20246, 263, 327, 221, 378, 88, 18, 34, 1035, 18807, 5056, 272, 13647, 263, 327, 221, 378, 88, 18, 35, 1035, 22849, 272, 10791, 263, 327, 221, 378, 88, 18, 36, 1035, 22553, 13, 18004, 272, 7815, 263, 327, 221, 378, 88, 18, 37, 1035, 18530, 22348, 272, 7324, 263, 327, 221, 378, 88, 18, 38, 1035, 20585, 272, 283, 16, 7, 263, 327, 221, 378, 88, 1216, 1035, 7298, 20348, 272, 283, 17, 7, 263, 327, 221, 378, 88, 2192, 1035, 7298, 13051, 272, 283, 18, 7, 263, 327, 221, 378, 88, 708, 1035, 7298, 16562, 272, 283, 19, 7, 263, 327, 221, 378, 88, 1153, 1035, 7298, 16296, 272, 283, 20, 7, 263, 327, 221, 378, 88, 1082, 1035, 7298, 14473, 272, 283, 21, 7, 263, 327, 221, 378, 88, 1276, 1035, 7298, 28194, 272, 283, 22 ]
[ 2018, 17660, 12340, 13732, 3367, 83, 63, 22085, 4046, 687, 283, 1548, 13, 14632, 15, 52, 1311, 13, 22085, 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, 16753, 13, 22085, 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, 258, 327, 221, 378, 88, 383, 1035, 5962, 272, 1557, 88, 614, 7, 258, 327, 221, 378, 88, 614, 1035, 13910, 1634, 32674, 272, 1557, 88, 996, 7, 258, 327, 221, 378, 88, 996, 1035, 13910, 1634, 11951, 272, 1557, 88, 1644, 7, 258, 327, 221, 378, 88, 1644, 1035, 7729, 1634, 11951, 272, 1557, 88, 966, 7, 258, 327, 221, 378, 88, 966, 1035, 7729, 1634, 22499, 272, 1557, 88, 1717, 7, 258, 327, 221, 378, 88, 1717, 1035, 5070, 31115, 57, 272, 1557, 88, 1690, 7, 258, 327, 221, 378, 88, 1690, 1035, 22549, 272, 1557, 88, 1780, 7, 258, 327, 221, 378, 88, 1780, 1035, 699, 14952, 272, 1557, 88, 2036, 7, 258, 327, 221, 378, 88, 2036, 1035, 22658, 11658, 272, 1557, 84, 7, 755, 327, 221, 378, 88, 1643, 1035, 8724, 22450, 272, 1557, 78, 7, 755, 327, 221, 378, 88, 16, 33, 1035, 13587, 21567, 272, 1557, 88, 16, 66, 7, 258, 327, 221, 378, 88, 16, 34, 1035, 8267, 22450, 272, 1557, 88, 16, 67, 7, 258, 327, 221, 378, 88, 16, 35, 1035, 11295, 21567, 272, 1557, 82, 7, 755, 327, 221, 378, 88, 16, 36, 1035, 445, 32622, 24646, 272, 1557, 88, 16, 69, 7, 258, 327, 221, 378, 88, 16, 37, 1035, 20754, 5738, 272, 1557, 88, 16, 70, 7, 258, 327, 221, 378, 88, 16, 38, 1035, 20754, 1621, 272, 1557, 88, 709, 7, 258, 327, 221, 378, 88, 709, 1035, 7126, 19774, 17682, 272, 1557, 88, 845, 7, 258, 327, 221, 378, 88, 845, 1035, 11643, 8098, 13051, 272, 1557, 88, 713, 7, 258, 327, 221, 378, 88, 713, 1035, 11643, 8098, 16562, 272, 1557, 88, 969, 7, 258, 327, 221, 378, 88, 969, 1035, 11643, 8098, 16296, 272, 1557, 88, 1079, 7, 258, 327, 221, 378, 88, 1079, 1035, 11643, 8098, 14473, 272, 1557, 88, 1046, 7, 258, 327, 221, 378, 88, 1046, 1035, 29837, 22549, 272, 1557, 88, 975, 7, 258, 327, 221, 378, 88, 975, 1035, 10046, 30782, 23240, 272, 1557, 88, 1196, 7, 258, 327, 221, 378, 88, 1196, 1035, 7729, 1634, 22499, 8068, 272, 1557, 88, 1085, 7, 258, 327, 221, 378, 88, 1085, 1035, 27385, 272, 1557, 88, 1167, 7, 258, 327, 221, 378, 88, 1167, 1035, 7729, 1634, 22650, 272, 1557, 88, 17, 65, 7, 258, 327, 221, 378, 88, 17, 33, 1035, 9103, 272, 1557, 88, 17, 66, 7, 258, 327, 221, 378, 88, 17, 34, 1035, 17682, 272, 1557, 88, 17, 67, 7, 258, 327, 221, 378, 88, 17, 35, 1035, 13024, 14782, 272, 1557, 88, 17, 68, 7, 258, 327, 221, 378, 88, 17, 36, 1035, 15443, 14782, 272, 1557, 88, 17, 69, 7, 258, 327, 221, 378, 88, 17, 37, 1035, 24973, 14782, 272, 1557, 88, 17, 70, 7, 258, 327, 221, 378, 88, 17, 38, 1035, 25836, 14782, 272, 283, 283, 263, 327, 221, 378, 88, 1165, 1035, 16796, 272, 29376, 263, 327, 221, 378, 88, 2025, 1035, 24232, 8132, 272, 14788, 263, 327, 221, 378, 88, 1081, 1035, 11830, 8132, 272, 19619, 263, 327, 221, 378, 88, 1789, 1035, 18122, 5056, 272, 25271, 263, 327, 221, 378, 88, 1194, 1035, 30857, 5056, 272, 26386, 263, 327, 221, 378, 88, 821, 1035, 26684, 5056, 272, 29285, 263, 327, 221, 378, 88, 1479, 1035, 30602, 272, 21673, 263, 327, 221, 378, 88, 1465, 1035, 30876, 272, 16746, 263, 327, 221, 378, 88, 1651, 1035, 6578, 20570, 272, 16107, 263, 327, 221, 378, 88, 1398, 1035, 7052, 20570, 272, 13626, 263, 327, 221, 378, 88, 18, 33, 1035, 29725, 272, 20246, 263, 327, 221, 378, 88, 18, 34, 1035, 18807, 5056, 272, 13647, 263, 327, 221, 378, 88, 18, 35, 1035, 22849, 272, 10791, 263, 327, 221, 378, 88, 18, 36, 1035, 22553, 13, 18004, 272, 7815, 263, 327, 221, 378, 88, 18, 37, 1035, 18530, 22348, 272, 7324, 263, 327, 221, 378, 88, 18, 38, 1035, 20585, 272, 283, 16, 7, 263, 327, 221, 378, 88, 1216, 1035, 7298, 20348, 272, 283, 17, 7, 263, 327, 221, 378, 88, 2192, 1035, 7298, 13051, 272, 283, 18, 7, 263, 327, 221, 378, 88, 708, 1035, 7298, 16562, 272, 283, 19, 7, 263, 327, 221, 378, 88, 1153, 1035, 7298, 16296, 272, 283, 20, 7, 263, 327, 221, 378, 88, 1082, 1035, 7298, 14473, 272, 283, 21, 7, 263, 327, 221, 378, 88, 1276, 1035, 7298, 28194, 272, 283, 22, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
pfnet/chainer
chainer/links/normalization/decorrelated_batch_normalization.py
5
7674
import functools import warnings import numpy import chainer from chainer import configuration from chainer import functions from chainer import link import chainer.serializer as serializer_mod from chainer.utils import argument class DecorrelatedBatchNormalization(link.Link): """Decorrelated batch normalization layer. This link wraps the :func:`~chainer.functions.decorrelated_batch_normalization` and :func:`~chainer.functions.fixed_decorrelated_batch_normalization` functions. It works on outputs of linear or convolution functions. It runs in three modes: training mode, fine-tuning mode, and testing mode. In training mode, it normalizes the input by *batch statistics*. It also maintains approximated population statistics by moving averages, which can be used for instant evaluation in testing mode. In fine-tuning mode, it accumulates the input to compute *population statistics*. In order to correctly compute the population statistics, a user must use this mode to feed mini-batches running through whole training dataset. In testing mode, it uses pre-computed population statistics to normalize the input variable. The population statistics is approximated if it is computed by training mode, or accurate if it is correctly computed by fine-tuning mode. Args: size (int or tuple of ints): Size (or shape) of channel dimensions. groups (int): Number of groups to use for group whitening. decay (float): Decay rate of moving average which is used during training. eps (float): Epsilon value for numerical stability. dtype (numpy.dtype): Type to use in computing. See: `Decorrelated Batch Normalization <https://arxiv.org/abs/1804.08450>`_ .. seealso:: :func:`~chainer.functions.decorrelated_batch_normalization`, :func:`~chainer.functions.fixed_decorrelated_batch_normalization` Attributes: avg_mean (:ref:`ndarray`): Population mean. avg_projection (:ref:`ndarray`): Population projection. groups (int): Number of groups to use for group whitening. N (int): Count of batches given for fine-tuning. decay (float): Decay rate of moving average which is used during training. ~DecorrelatedBatchNormalization.eps (float): Epsilon value for numerical stability. This value is added to the batch variances. """ def __init__(self, size, groups=16, decay=0.9, eps=2e-5, dtype=numpy.float32): super(DecorrelatedBatchNormalization, self).__init__() C = size // groups self.avg_mean = numpy.zeros((groups, C), dtype=dtype) self.register_persistent('avg_mean') avg_projection = numpy.zeros((groups, C, C), dtype=dtype) arange_C = numpy.arange(C) avg_projection[:, arange_C, arange_C] = 1 self.avg_projection = avg_projection self.register_persistent('avg_projection') self.N = 0 self.register_persistent('N') self.decay = decay self.eps = eps self.groups = groups def serialize(self, serializer): if isinstance(serializer, serializer_mod.Deserializer): serializer = _PatchedDeserializer(serializer, { 'avg_mean': functools.partial( fix_avg_mean, groups=self.groups), 'avg_projection': functools.partial( fix_avg_projection, groups=self.groups), }) super(DecorrelatedBatchNormalization, self).serialize(serializer) def forward(self, x, **kwargs): """forward(self, x, *, finetune=False) Invokes the forward propagation of DecorrelatedBatchNormalization. In training mode, the DecorrelatedBatchNormalization computes moving averages of the mean and projection for evaluation during training, and normalizes the input using batch statistics. Args: x (:class:`~chainer.Variable`): Input variable. finetune (bool): If it is in the training mode and ``finetune`` is ``True``, DecorrelatedBatchNormalization runs in fine-tuning mode; it accumulates the input array to compute population statistics for normalization, and normalizes the input using batch statistics. """ finetune, = argument.parse_kwargs(kwargs, ('finetune', False)) if configuration.config.train: if finetune: self.N += 1 decay = 1. - 1. / self.N else: decay = self.decay avg_mean = self.avg_mean avg_projection = self.avg_projection if configuration.config.in_recomputing: # Do not update statistics when extra forward computation is # called. if finetune: self.N -= 1 avg_mean = None avg_projection = None ret = functions.decorrelated_batch_normalization( x, groups=self.groups, eps=self.eps, running_mean=avg_mean, running_projection=avg_projection, decay=decay) else: # Use running average statistics or fine-tuned statistics. mean = self.avg_mean projection = self.avg_projection ret = functions.fixed_decorrelated_batch_normalization( x, mean, projection, groups=self.groups) return ret def start_finetuning(self): """Resets the population count for collecting population statistics. This method can be skipped if it is the first time to use the fine-tuning mode. Otherwise, this method should be called before starting the fine-tuning mode again. """ self.N = 0 class _PatchedDeserializer(serializer_mod.Deserializer): def __init__(self, base, patches): self.base = base self.patches = patches def __repr__(self): return '_PatchedDeserializer({}, {})'.format( repr(self.base), repr(self.patches)) def __call__(self, key, value): if key not in self.patches: return self.base(key, value) arr = self.base(key, None) arr = self.patches[key](arr) if value is None: return arr chainer.backend.copyto(value, arr) return value def _warn_old_model(): msg = ( 'Found moving statistics of old DecorrelatedBatchNormalization, whose ' 'algorithm was different from the paper.') warnings.warn(msg) def fix_avg_mean(avg_mean, groups): if avg_mean.ndim == 2: # OK return avg_mean elif avg_mean.ndim == 1: # Issue #7706 if groups != 1: _warn_old_model() return _broadcast_to(avg_mean, (groups,) + avg_mean.shape) raise ValueError('unexpected shape of avg_mean') def fix_avg_projection(avg_projection, groups): if avg_projection.ndim == 3: # OK return avg_projection elif avg_projection.ndim == 2: # Issue #7706 if groups != 1: _warn_old_model() return _broadcast_to( avg_projection, (groups,) + avg_projection.shape) raise ValueError('unexpected shape of avg_projection') def _broadcast_to(array, shape): if hasattr(numpy, 'broadcast_to'): return numpy.broadcast_to(array, shape) else: # numpy 1.9 doesn't support broadcast_to method dummy = numpy.empty(shape) bx, _ = numpy.broadcast_arrays(array, dummy) return bx
mit
[ 646, 9143, 199, 646, 3598, 199, 199, 646, 2680, 199, 199, 646, 20333, 199, 504, 20333, 492, 2897, 199, 504, 20333, 492, 3423, 199, 504, 20333, 492, 2142, 199, 646, 20333, 14, 8349, 465, 9146, 63, 1494, 199, 504, 20333, 14, 1208, 492, 1423, 421, 199, 533, 13966, 269, 2407, 8842, 29169, 8, 1073, 14, 3834, 304, 339, 408, 8584, 269, 2407, 3522, 16973, 4045, 14, 339, 961, 2142, 14018, 314, 272, 520, 1532, 6054, 27243, 14, 5777, 14, 6518, 2407, 63, 2912, 63, 22384, 64, 436, 272, 520, 1532, 6054, 27243, 14, 5777, 14, 5964, 63, 6518, 2407, 63, 2912, 63, 22384, 64, 272, 3423, 14, 2779, 5419, 641, 4704, 402, 7798, 503, 17461, 3423, 14, 339, 2779, 7858, 315, 7795, 12404, 26, 6093, 818, 12, 15701, 13, 10032, 316, 818, 12, 436, 5343, 818, 14, 339, 1010, 6093, 818, 12, 652, 3293, 6491, 314, 1324, 701, 627, 2912, 11076, 4856, 2779, 2597, 272, 11075, 83, 14106, 12754, 16423, 11076, 701, 12876, 8095, 83, 12, 1314, 883, 272, 506, 1202, 367, 2727, 867, 11735, 315, 5343, 818, 14, 339, 1010, 15701, 13, 10032, 316, 818, 12, 652, 11162, 15409, 314, 1324, 370, 4526, 627, 16003, 272, 11076, 4856, 1010, 1865, 370, 6657, 4526, 314, 16423, 11076, 12, 282, 272, 922, 1471, 675, 642, 818, 370, 4733, 20536, 13, 14896, 3879, 4012, 8852, 6093, 272, 4789, 14, 339, 1010, 5343, 818, 12, 652, 4440, 876, 13, 14378, 16423, 11076, 370, 7666, 272, 314, 1324, 1750, 14, 710, 16423, 11076, 365, 14106, 12754, 340, 652, 365, 272, 9235, 701, 6093, 818, 12, 503, 23189, 340, 652, 365, 6657, 9235, 701, 272, 15701, 13, 10032, 316, 818, 14, 339, 3033, 26, 267, 1568, 334, 442, 503, 2008, 402, 14526, 304, 14579, 334, 269, 2215, 9, 402, 3623, 288, 7365, 14, 267, 4652, 334, 442, 304, 4860, 402, 4652, 370, 675, 367, 1572, 704, 25840, 316, 14, 267, 16696, 334, 1609, 304, 1487, 9972, 6634, 402, 12876, 8095, 288, 1314, 365, 1202, 5309, 6093, 14, 267, 10245, 334, 1609, 304, 27255, 8746, 574, 367, 15470, 410, 3616, 14, 267, 2152, 334, 4714, 14, 2271, 304, 2434, 370, 675, 315, 17226, 14, 339, 1666, 26, 658, 8584, 269, 2407, 17206, 11514, 2072, 665, 2859, 921, 27290, 14, 1308, 15, 2101, 15, 1085, 966, 14, 26107, 1400, 18740, 339, 2508, 19352, 447, 2126, 520, 1532, 6054, 27243, 14, 5777, 14, 6518, 2407, 63, 2912, 63, 22384, 3559, 2126, 520, 1532, 6054, 27243, 14, 5777, 14, 5964, 63, 6518, 2407, 63, 2912, 63, 22384, 64, 339, 9382, 26, 267, 12402, 63, 3670, 18479, 1121, 1705, 8237, 25452, 13244, 5332, 4615, 14, 267, 12402, 63, 16539, 18479, 1121, 1705, 8237, 25452, 13244, 5332, 288, 14777, 14, 267, 4652, 334, 442, 304, 4860, 402, 4652, 370, 675, 367, 1572, 704, 25840, 316, 14, 267, 653, 334, 442, 304, 14826, 402, 19593, 1627, 367, 15701, 13, 10032, 316, 14, 267, 16696, 334, 1609, 304, 1487, 9972, 6634, 402, 12876, 8095, 288, 1314, 365, 1202, 5309, 6093, 14, 267, 6146, 8584, 269, 2407, 8842, 29169, 14, 8277, 334, 1609, 304, 27255, 8746, 574, 367, 288, 15470, 410, 3616, 14, 961, 574, 365, 3483, 370, 314, 3522, 11773, 83, 14, 339, 408, 339, 347, 636, 826, 721, 277, 12, 1568, 12, 4652, 29, 975, 12, 16696, 29, 16, 14, 25, 12, 10245, 29, 18, 69, 13, 21, 12, 326, 2152, 29, 4714, 14, 1609, 708, 304, 267, 1613, 8, 8584, 269, 2407, 8842, 29169, 12, 291, 2843, 826, 4533, 267, 445, 275, 1568, 5001, 4652, 267, 291, 14, 8595, 63, 3670, 275, 2680, 14, 4250, 1332, 2634, 12, 445, 395, 2152, 29, 2271, 9, 267, 291, 14, 2683, 63, 18539, 360, 8595, 63, 3670, 358, 267, 12402, 63, 16539, 275, 2680, 14, 4250, 1332, 2634, 12, 445, 12, 445, 395, 2152, 29, 2271, 9, 267, 20461, 63, 35, 275, 2680, 14, 5605, 8, 35, 9, 267, 12402, 63, 16539, 3981, 20461, 63, 35, 12, 20461, 63, 35, 61, 275, 413, 267, 291, 14, 8595, 63, 16539, 275, 12402, 63, 16539, 267, 291, 14, 2683, 63, 18539, 360, 8595, 63, 16539, 358, 267, 291, 14, 46, 275, 378, 267, 291, 14, 2683, 63, 18539, 360, 46, 358, 267, 291, 14, 16889, 275, 16696, 267, 291, 14, 8277, 275, 10245, 267, 291, 14, 2634, 275, 4652, 339, 347, 8437, 8, 277, 12, 9146, 304, 267, 340, 1228, 8, 8349, 12, 9146, 63, 1494, 14, 872, 8349, 304, 288, 9146, 275, 485, 11173, 379, 872, 8349, 8, 8349, 12, 469, 355, 283, 8595, 63, 3670, 356, 9143, 14, 6672, 8, 490, 5325, 63, 8595, 63, 3670, 12, 4652, 29, 277, 14, 2634, 395, 355, 283, 8595, 63, 16539, 356, 9143, 14, 6672, 8, 490, 5325, 63, 8595, 63, 16539, 12, 4652, 29, 277, 14, 2634, 395, 288, 3828, 267, 1613, 8, 8584, 269, 2407, 8842, 29169, 12, 291, 680, 3549, 8, 8349, 9, 339, 347, 7568, 8, 277, 12, 671, 12, 1011, 958, 304, 267, 408, 6688, 8, 277, 12, 671, 12, 9889, 2583, 386, 11474, 29, 797, 9, 398, 30110, 22652, 314, 7568, 17012, 402, 13966, 269, 2407, 8842, 29169, 14, 398, 1010, 6093, 818, 12, 314, 13966, 269, 2407, 8842, 29169, 21445, 12876, 267, 8095, 83, 402, 314, 4615, 436, 14777, 367, 11735, 5309, 6093, 12, 267, 436, 3293, 6491, 314, 1324, 1808, 3522, 11076, 14, 398, 3033, 26, 288, 671, 18479, 533, 6054, 27243, 14, 2773, 25452, 6924, 1750, 14, 288, 2583, 386, 11474, 334, 2245, 304, 982, 652, 365, 315, 314, 6093, 818, 436, 1124, 2408, 386, 11474, 1040, 365, 355, 1124, 549, 4542, 13966, 269, 2407, 8842, 29169, 7858, 315, 15701, 13, 10032, 316, 355, 818, 27, 652, 11162, 15409, 314, 1324, 1625, 370, 4526, 16423, 355, 11076, 367, 16973, 12, 436, 3293, 6491, 314, 1324, 1808, 355, 3522, 11076, 14, 398, 408, 267, 2583, 386, 11474, 12, 275, 1423, 14, 1122, 63, 958, 8, 958, 12, 661, 2408, 386, 11474, 297, 756, 430, 398, 340, 2897, 14, 888, 14, 2834, 26, 288, 340, 2583, 386, 11474, 26, 355, 291, 14, 46, 847, 413, 355, 16696, 275, 413, 14, 446, 413, 14, 1182, 291, 14, 46, 288, 587, 26, 355, 16696, 275, 291 ]
[ 9143, 199, 646, 3598, 199, 199, 646, 2680, 199, 199, 646, 20333, 199, 504, 20333, 492, 2897, 199, 504, 20333, 492, 3423, 199, 504, 20333, 492, 2142, 199, 646, 20333, 14, 8349, 465, 9146, 63, 1494, 199, 504, 20333, 14, 1208, 492, 1423, 421, 199, 533, 13966, 269, 2407, 8842, 29169, 8, 1073, 14, 3834, 304, 339, 408, 8584, 269, 2407, 3522, 16973, 4045, 14, 339, 961, 2142, 14018, 314, 272, 520, 1532, 6054, 27243, 14, 5777, 14, 6518, 2407, 63, 2912, 63, 22384, 64, 436, 272, 520, 1532, 6054, 27243, 14, 5777, 14, 5964, 63, 6518, 2407, 63, 2912, 63, 22384, 64, 272, 3423, 14, 2779, 5419, 641, 4704, 402, 7798, 503, 17461, 3423, 14, 339, 2779, 7858, 315, 7795, 12404, 26, 6093, 818, 12, 15701, 13, 10032, 316, 818, 12, 436, 5343, 818, 14, 339, 1010, 6093, 818, 12, 652, 3293, 6491, 314, 1324, 701, 627, 2912, 11076, 4856, 2779, 2597, 272, 11075, 83, 14106, 12754, 16423, 11076, 701, 12876, 8095, 83, 12, 1314, 883, 272, 506, 1202, 367, 2727, 867, 11735, 315, 5343, 818, 14, 339, 1010, 15701, 13, 10032, 316, 818, 12, 652, 11162, 15409, 314, 1324, 370, 4526, 627, 16003, 272, 11076, 4856, 1010, 1865, 370, 6657, 4526, 314, 16423, 11076, 12, 282, 272, 922, 1471, 675, 642, 818, 370, 4733, 20536, 13, 14896, 3879, 4012, 8852, 6093, 272, 4789, 14, 339, 1010, 5343, 818, 12, 652, 4440, 876, 13, 14378, 16423, 11076, 370, 7666, 272, 314, 1324, 1750, 14, 710, 16423, 11076, 365, 14106, 12754, 340, 652, 365, 272, 9235, 701, 6093, 818, 12, 503, 23189, 340, 652, 365, 6657, 9235, 701, 272, 15701, 13, 10032, 316, 818, 14, 339, 3033, 26, 267, 1568, 334, 442, 503, 2008, 402, 14526, 304, 14579, 334, 269, 2215, 9, 402, 3623, 288, 7365, 14, 267, 4652, 334, 442, 304, 4860, 402, 4652, 370, 675, 367, 1572, 704, 25840, 316, 14, 267, 16696, 334, 1609, 304, 1487, 9972, 6634, 402, 12876, 8095, 288, 1314, 365, 1202, 5309, 6093, 14, 267, 10245, 334, 1609, 304, 27255, 8746, 574, 367, 15470, 410, 3616, 14, 267, 2152, 334, 4714, 14, 2271, 304, 2434, 370, 675, 315, 17226, 14, 339, 1666, 26, 658, 8584, 269, 2407, 17206, 11514, 2072, 665, 2859, 921, 27290, 14, 1308, 15, 2101, 15, 1085, 966, 14, 26107, 1400, 18740, 339, 2508, 19352, 447, 2126, 520, 1532, 6054, 27243, 14, 5777, 14, 6518, 2407, 63, 2912, 63, 22384, 3559, 2126, 520, 1532, 6054, 27243, 14, 5777, 14, 5964, 63, 6518, 2407, 63, 2912, 63, 22384, 64, 339, 9382, 26, 267, 12402, 63, 3670, 18479, 1121, 1705, 8237, 25452, 13244, 5332, 4615, 14, 267, 12402, 63, 16539, 18479, 1121, 1705, 8237, 25452, 13244, 5332, 288, 14777, 14, 267, 4652, 334, 442, 304, 4860, 402, 4652, 370, 675, 367, 1572, 704, 25840, 316, 14, 267, 653, 334, 442, 304, 14826, 402, 19593, 1627, 367, 15701, 13, 10032, 316, 14, 267, 16696, 334, 1609, 304, 1487, 9972, 6634, 402, 12876, 8095, 288, 1314, 365, 1202, 5309, 6093, 14, 267, 6146, 8584, 269, 2407, 8842, 29169, 14, 8277, 334, 1609, 304, 27255, 8746, 574, 367, 288, 15470, 410, 3616, 14, 961, 574, 365, 3483, 370, 314, 3522, 11773, 83, 14, 339, 408, 339, 347, 636, 826, 721, 277, 12, 1568, 12, 4652, 29, 975, 12, 16696, 29, 16, 14, 25, 12, 10245, 29, 18, 69, 13, 21, 12, 326, 2152, 29, 4714, 14, 1609, 708, 304, 267, 1613, 8, 8584, 269, 2407, 8842, 29169, 12, 291, 2843, 826, 4533, 267, 445, 275, 1568, 5001, 4652, 267, 291, 14, 8595, 63, 3670, 275, 2680, 14, 4250, 1332, 2634, 12, 445, 395, 2152, 29, 2271, 9, 267, 291, 14, 2683, 63, 18539, 360, 8595, 63, 3670, 358, 267, 12402, 63, 16539, 275, 2680, 14, 4250, 1332, 2634, 12, 445, 12, 445, 395, 2152, 29, 2271, 9, 267, 20461, 63, 35, 275, 2680, 14, 5605, 8, 35, 9, 267, 12402, 63, 16539, 3981, 20461, 63, 35, 12, 20461, 63, 35, 61, 275, 413, 267, 291, 14, 8595, 63, 16539, 275, 12402, 63, 16539, 267, 291, 14, 2683, 63, 18539, 360, 8595, 63, 16539, 358, 267, 291, 14, 46, 275, 378, 267, 291, 14, 2683, 63, 18539, 360, 46, 358, 267, 291, 14, 16889, 275, 16696, 267, 291, 14, 8277, 275, 10245, 267, 291, 14, 2634, 275, 4652, 339, 347, 8437, 8, 277, 12, 9146, 304, 267, 340, 1228, 8, 8349, 12, 9146, 63, 1494, 14, 872, 8349, 304, 288, 9146, 275, 485, 11173, 379, 872, 8349, 8, 8349, 12, 469, 355, 283, 8595, 63, 3670, 356, 9143, 14, 6672, 8, 490, 5325, 63, 8595, 63, 3670, 12, 4652, 29, 277, 14, 2634, 395, 355, 283, 8595, 63, 16539, 356, 9143, 14, 6672, 8, 490, 5325, 63, 8595, 63, 16539, 12, 4652, 29, 277, 14, 2634, 395, 288, 3828, 267, 1613, 8, 8584, 269, 2407, 8842, 29169, 12, 291, 680, 3549, 8, 8349, 9, 339, 347, 7568, 8, 277, 12, 671, 12, 1011, 958, 304, 267, 408, 6688, 8, 277, 12, 671, 12, 9889, 2583, 386, 11474, 29, 797, 9, 398, 30110, 22652, 314, 7568, 17012, 402, 13966, 269, 2407, 8842, 29169, 14, 398, 1010, 6093, 818, 12, 314, 13966, 269, 2407, 8842, 29169, 21445, 12876, 267, 8095, 83, 402, 314, 4615, 436, 14777, 367, 11735, 5309, 6093, 12, 267, 436, 3293, 6491, 314, 1324, 1808, 3522, 11076, 14, 398, 3033, 26, 288, 671, 18479, 533, 6054, 27243, 14, 2773, 25452, 6924, 1750, 14, 288, 2583, 386, 11474, 334, 2245, 304, 982, 652, 365, 315, 314, 6093, 818, 436, 1124, 2408, 386, 11474, 1040, 365, 355, 1124, 549, 4542, 13966, 269, 2407, 8842, 29169, 7858, 315, 15701, 13, 10032, 316, 355, 818, 27, 652, 11162, 15409, 314, 1324, 1625, 370, 4526, 16423, 355, 11076, 367, 16973, 12, 436, 3293, 6491, 314, 1324, 1808, 355, 3522, 11076, 14, 398, 408, 267, 2583, 386, 11474, 12, 275, 1423, 14, 1122, 63, 958, 8, 958, 12, 661, 2408, 386, 11474, 297, 756, 430, 398, 340, 2897, 14, 888, 14, 2834, 26, 288, 340, 2583, 386, 11474, 26, 355, 291, 14, 46, 847, 413, 355, 16696, 275, 413, 14, 446, 413, 14, 1182, 291, 14,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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
leansoft/edx-platform
cms/djangoapps/contentstore/views/tests/test_group_configurations.py
65
37638
#-*- coding: utf-8 -*- """ Group Configuration Tests. """ import json from mock import patch from contentstore.utils import reverse_course_url, reverse_usage_url from contentstore.views.component import SPLIT_TEST_COMPONENT_TYPE from contentstore.course_group_config import GroupConfiguration from contentstore.tests.utils import CourseTestCase from xmodule.partitions.partitions import Group, UserPartition from xmodule.modulestore.tests.factories import ItemFactory from xmodule.validation import StudioValidation, StudioValidationMessage from xmodule.modulestore.django import modulestore from xmodule.modulestore import ModuleStoreEnum GROUP_CONFIGURATION_JSON = { u'name': u'Test name', u'scheme': u'random', u'description': u'Test description', u'version': UserPartition.VERSION, u'groups': [ { u'name': u'Group A', u'version': 1, }, { u'name': u'Group B', u'version': 1, }, ], } # pylint: disable=no-member class HelperMethods(object): """ Mixin that provides useful methods for Group Configuration tests. """ def _create_content_experiment(self, cid=-1, name_suffix='', special_characters=''): """ Create content experiment. Assign Group Configuration to the experiment if cid is provided. """ vertical = ItemFactory.create( category='vertical', parent_location=self.course.location, display_name='Test Unit {}'.format(name_suffix) ) c0_url = self.course.id.make_usage_key("vertical", "split_test_cond0") c1_url = self.course.id.make_usage_key("vertical", "split_test_cond1") c2_url = self.course.id.make_usage_key("vertical", "split_test_cond2") split_test = ItemFactory.create( category='split_test', parent_location=vertical.location, user_partition_id=cid, display_name=u"Test Content Experiment {}{}".format(name_suffix, special_characters), group_id_to_child={"0": c0_url, "1": c1_url, "2": c2_url} ) ItemFactory.create( parent_location=split_test.location, category="vertical", display_name="Condition 0 vertical", location=c0_url, ) ItemFactory.create( parent_location=split_test.location, category="vertical", display_name="Condition 1 vertical", location=c1_url, ) ItemFactory.create( parent_location=split_test.location, category="vertical", display_name="Condition 2 vertical", location=c2_url, ) partitions_json = [p.to_json() for p in self.course.user_partitions] self.client.ajax_post( reverse_usage_url("xblock_handler", split_test.location), data={'metadata': {'user_partitions': partitions_json}} ) self.save_course() return (vertical, split_test) def _create_problem_with_content_group(self, cid, group_id, name_suffix='', special_characters=''): """ Create a problem Assign content group to the problem. """ vertical = ItemFactory.create( category='vertical', parent_location=self.course.location, display_name="Test Unit {}".format(name_suffix) ) problem = ItemFactory.create( category='problem', parent_location=vertical.location, display_name=u"Test Problem {}{}".format(name_suffix, special_characters) ) group_access_content = {'group_access': {cid: [group_id]}} self.client.ajax_post( reverse_usage_url("xblock_handler", problem.location), data={'metadata': group_access_content} ) self.save_course() return vertical, problem def _add_user_partitions(self, count=1, scheme_id="random"): """ Create user partitions for the course. """ partitions = [ UserPartition( i, 'Name ' + str(i), 'Description ' + str(i), [Group(0, 'Group A'), Group(1, 'Group B'), Group(2, 'Group C')], scheme=None, scheme_id=scheme_id ) for i in xrange(count) ] self.course.user_partitions = partitions self.save_course() # pylint: disable=no-member class GroupConfigurationsBaseTestCase(object): """ Mixin with base test cases for the group configurations. """ def _remove_ids(self, content): """ Remove ids from the response. We cannot predict IDs, because they're generated randomly. We use this method to clean up response when creating new group configurations. Returns a tuple that contains removed group configuration ID and group IDs. """ configuration_id = content.pop("id") group_ids = [group.pop("id") for group in content["groups"]] return (configuration_id, group_ids) def test_required_fields_are_absent(self): """ Test required fields are absent. """ bad_jsons = [ # must have name of the configuration { u'description': 'Test description', u'groups': [ {u'name': u'Group A'}, {u'name': u'Group B'}, ], }, # must have at least one group { u'name': u'Test name', u'description': u'Test description', u'groups': [], }, # an empty json {}, ] for bad_json in bad_jsons: response = self.client.post( self._url(), data=json.dumps(bad_json), content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) self.assertEqual(response.status_code, 400) self.assertNotIn("Location", response) content = json.loads(response.content) self.assertIn("error", content) def test_invalid_json(self): """ Test invalid json handling. """ # No property name. invalid_json = "{u'name': 'Test Name', []}" response = self.client.post( self._url(), data=invalid_json, content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) self.assertEqual(response.status_code, 400) self.assertNotIn("Location", response) content = json.loads(response.content) self.assertIn("error", content) class GroupConfigurationsListHandlerTestCase(CourseTestCase, GroupConfigurationsBaseTestCase, HelperMethods): """ Test cases for group_configurations_list_handler. """ def setUp(self): """ Set up GroupConfigurationsListHandlerTestCase. """ super(GroupConfigurationsListHandlerTestCase, self).setUp() def _url(self): """ Return url for the handler. """ return reverse_course_url('group_configurations_list_handler', self.course.id) def test_view_index_ok(self): """ Basic check that the groups configuration page responds correctly. """ self.course.user_partitions = [ UserPartition(0, 'First name', 'First description', [Group(0, 'Group A'), Group(1, 'Group B'), Group(2, 'Group C')]), ] self.save_course() if SPLIT_TEST_COMPONENT_TYPE not in self.course.advanced_modules: self.course.advanced_modules.append(SPLIT_TEST_COMPONENT_TYPE) self.store.update_item(self.course, self.user.id) response = self.client.get(self._url()) self.assertEqual(response.status_code, 200) self.assertContains(response, 'First name') self.assertContains(response, 'Group C') self.assertContains(response, 'Content Group Configuration') def test_unsupported_http_accept_header(self): """ Test if not allowed header present in request. """ response = self.client.get( self._url(), HTTP_ACCEPT="text/plain", ) self.assertEqual(response.status_code, 406) def test_can_create_group_configuration(self): """ Test that you can create a group configuration. """ expected = { u'description': u'Test description', u'name': u'Test name', u'scheme': u'random', u'version': UserPartition.VERSION, u'groups': [ {u'name': u'Group A', u'version': 1}, {u'name': u'Group B', u'version': 1}, ], u'parameters': {}, u'active': True } response = self.client.ajax_post( self._url(), data=GROUP_CONFIGURATION_JSON ) self.assertEqual(response.status_code, 201) self.assertIn("Location", response) content = json.loads(response.content) configuration_id, group_ids = self._remove_ids(content) # pylint: disable=unused-variable self.assertEqual(content, expected) # IDs are unique self.assertEqual(len(group_ids), len(set(group_ids))) self.assertEqual(len(group_ids), 2) self.reload_course() # Verify that user_partitions in the course contains the new group configuration. user_partititons = self.course.user_partitions self.assertEqual(len(user_partititons), 1) self.assertEqual(user_partititons[0].name, u'Test name') self.assertEqual(len(user_partititons[0].groups), 2) self.assertEqual(user_partititons[0].groups[0].name, u'Group A') self.assertEqual(user_partititons[0].groups[1].name, u'Group B') self.assertEqual(user_partititons[0].parameters, {}) def test_lazily_creates_cohort_configuration(self): """ Test that a cohort schemed user partition is NOT created by default for the user. """ self.assertEqual(len(self.course.user_partitions), 0) self.client.get(self._url()) self.reload_course() self.assertEqual(len(self.course.user_partitions), 0) class GroupConfigurationsDetailHandlerTestCase(CourseTestCase, GroupConfigurationsBaseTestCase, HelperMethods): """ Test cases for group_configurations_detail_handler. """ ID = 0 def _url(self, cid=-1): """ Return url for the handler. """ cid = cid if cid > 0 else self.ID return reverse_course_url( 'group_configurations_detail_handler', self.course.id, kwargs={'group_configuration_id': cid}, ) def test_can_create_new_content_group_if_it_does_not_exist(self): """ PUT new content group. """ expected = { u'id': 666, u'name': u'Test name', u'scheme': u'cohort', u'description': u'Test description', u'version': UserPartition.VERSION, u'groups': [ {u'id': 0, u'name': u'Group A', u'version': 1, u'usage': []}, {u'id': 1, u'name': u'Group B', u'version': 1, u'usage': []}, ], u'parameters': {}, u'active': True, } response = self.client.put( self._url(cid=666), data=json.dumps(expected), content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) content = json.loads(response.content) self.assertEqual(content, expected) self.reload_course() # Verify that user_partitions in the course contains the new group configuration. user_partitions = self.course.user_partitions self.assertEqual(len(user_partitions), 1) self.assertEqual(user_partitions[0].name, u'Test name') self.assertEqual(len(user_partitions[0].groups), 2) self.assertEqual(user_partitions[0].groups[0].name, u'Group A') self.assertEqual(user_partitions[0].groups[1].name, u'Group B') self.assertEqual(user_partitions[0].parameters, {}) def test_can_edit_content_group(self): """ Edit content group and check its id and modified fields. """ self._add_user_partitions(scheme_id='cohort') self.save_course() expected = { u'id': self.ID, u'name': u'New Test name', u'scheme': u'cohort', u'description': u'New Test description', u'version': UserPartition.VERSION, u'groups': [ {u'id': 0, u'name': u'New Group Name', u'version': 1, u'usage': []}, {u'id': 2, u'name': u'Group C', u'version': 1, u'usage': []}, ], u'parameters': {}, u'active': True, } response = self.client.put( self._url(), data=json.dumps(expected), content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) content = json.loads(response.content) self.assertEqual(content, expected) self.reload_course() # Verify that user_partitions is properly updated in the course. user_partititons = self.course.user_partitions self.assertEqual(len(user_partititons), 1) self.assertEqual(user_partititons[0].name, u'New Test name') self.assertEqual(len(user_partititons[0].groups), 2) self.assertEqual(user_partititons[0].groups[0].name, u'New Group Name') self.assertEqual(user_partititons[0].groups[1].name, u'Group C') self.assertEqual(user_partititons[0].parameters, {}) def test_can_delete_content_group(self): """ Delete content group and check user partitions. """ self._add_user_partitions(count=1, scheme_id='cohort') self.save_course() details_url_with_group_id = self._url(cid=0) + '/1' response = self.client.delete( details_url_with_group_id, content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) self.assertEqual(response.status_code, 204) self.reload_course() # Verify that group and partition is properly updated in the course. user_partititons = self.course.user_partitions self.assertEqual(len(user_partititons), 1) self.assertEqual(user_partititons[0].name, 'Name 0') self.assertEqual(len(user_partititons[0].groups), 2) self.assertEqual(user_partititons[0].groups[1].name, 'Group C') def test_cannot_delete_used_content_group(self): """ Cannot delete content group if it is in use. """ self._add_user_partitions(count=1, scheme_id='cohort') self._create_problem_with_content_group(cid=0, group_id=1) details_url_with_group_id = self._url(cid=0) + '/1' response = self.client.delete( details_url_with_group_id, content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) self.assertEqual(response.status_code, 400) content = json.loads(response.content) self.assertTrue(content['error']) self.reload_course() # Verify that user_partitions and groups are still the same. user_partititons = self.course.user_partitions self.assertEqual(len(user_partititons), 1) self.assertEqual(len(user_partititons[0].groups), 3) self.assertEqual(user_partititons[0].groups[1].name, 'Group B') def test_cannot_delete_non_existent_content_group(self): """ Cannot delete content group if it is doesn't exist. """ self._add_user_partitions(count=1, scheme_id='cohort') details_url_with_group_id = self._url(cid=0) + '/90' response = self.client.delete( details_url_with_group_id, content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) self.assertEqual(response.status_code, 404) # Verify that user_partitions is still the same. user_partititons = self.course.user_partitions self.assertEqual(len(user_partititons), 1) self.assertEqual(len(user_partititons[0].groups), 3) def test_can_create_new_group_configuration_if_it_does_not_exist(self): """ PUT new group configuration when no configurations exist in the course. """ expected = { u'id': 999, u'name': u'Test name', u'scheme': u'random', u'description': u'Test description', u'version': UserPartition.VERSION, u'groups': [ {u'id': 0, u'name': u'Group A', u'version': 1}, {u'id': 1, u'name': u'Group B', u'version': 1}, ], u'usage': [], u'parameters': {}, u'active': True, } response = self.client.put( self._url(cid=999), data=json.dumps(expected), content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) content = json.loads(response.content) self.assertEqual(content, expected) self.reload_course() # Verify that user_partitions in the course contains the new group configuration. user_partitions = self.course.user_partitions self.assertEqual(len(user_partitions), 1) self.assertEqual(user_partitions[0].name, u'Test name') self.assertEqual(len(user_partitions[0].groups), 2) self.assertEqual(user_partitions[0].groups[0].name, u'Group A') self.assertEqual(user_partitions[0].groups[1].name, u'Group B') self.assertEqual(user_partitions[0].parameters, {}) def test_can_edit_group_configuration(self): """ Edit group configuration and check its id and modified fields. """ self._add_user_partitions() self.save_course() expected = { u'id': self.ID, u'name': u'New Test name', u'scheme': u'random', u'description': u'New Test description', u'version': UserPartition.VERSION, u'groups': [ {u'id': 0, u'name': u'New Group Name', u'version': 1}, {u'id': 2, u'name': u'Group C', u'version': 1}, ], u'usage': [], u'parameters': {}, u'active': True, } response = self.client.put( self._url(), data=json.dumps(expected), content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) content = json.loads(response.content) self.assertEqual(content, expected) self.reload_course() # Verify that user_partitions is properly updated in the course. user_partititons = self.course.user_partitions self.assertEqual(len(user_partititons), 1) self.assertEqual(user_partititons[0].name, u'New Test name') self.assertEqual(len(user_partititons[0].groups), 2) self.assertEqual(user_partititons[0].groups[0].name, u'New Group Name') self.assertEqual(user_partititons[0].groups[1].name, u'Group C') self.assertEqual(user_partititons[0].parameters, {}) def test_can_delete_group_configuration(self): """ Delete group configuration and check user partitions. """ self._add_user_partitions(count=2) self.save_course() response = self.client.delete( self._url(cid=0), content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) self.assertEqual(response.status_code, 204) self.reload_course() # Verify that user_partitions is properly updated in the course. user_partititons = self.course.user_partitions self.assertEqual(len(user_partititons), 1) self.assertEqual(user_partititons[0].name, 'Name 1') def test_cannot_delete_used_group_configuration(self): """ Cannot delete group configuration if it is in use. """ self._add_user_partitions(count=2) self._create_content_experiment(cid=0) response = self.client.delete( self._url(cid=0), content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) self.assertEqual(response.status_code, 400) content = json.loads(response.content) self.assertTrue(content['error']) self.reload_course() # Verify that user_partitions is still the same. user_partititons = self.course.user_partitions self.assertEqual(len(user_partititons), 2) self.assertEqual(user_partititons[0].name, 'Name 0') def test_cannot_delete_non_existent_group_configuration(self): """ Cannot delete group configuration if it is doesn't exist. """ self._add_user_partitions(count=2) response = self.client.delete( self._url(cid=999), content_type="application/json", HTTP_ACCEPT="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) self.assertEqual(response.status_code, 404) # Verify that user_partitions is still the same. user_partititons = self.course.user_partitions self.assertEqual(len(user_partititons), 2) self.assertEqual(user_partititons[0].name, 'Name 0') class GroupConfigurationsUsageInfoTestCase(CourseTestCase, HelperMethods): """ Tests for usage information of configurations and content groups. """ def setUp(self): super(GroupConfigurationsUsageInfoTestCase, self).setUp() def _get_expected_content_group(self, usage_for_group): """ Returns the expected configuration with particular usage. """ return { 'id': 0, 'name': 'Name 0', 'scheme': 'cohort', 'description': 'Description 0', 'version': UserPartition.VERSION, 'groups': [ {'id': 0, 'name': 'Group A', 'version': 1, 'usage': []}, {'id': 1, 'name': 'Group B', 'version': 1, 'usage': usage_for_group}, {'id': 2, 'name': 'Group C', 'version': 1, 'usage': []}, ], u'parameters': {}, u'active': True, } def test_content_group_not_used(self): """ Test that right data structure will be created if content group is not used. """ self._add_user_partitions(scheme_id='cohort') actual = GroupConfiguration.get_or_create_content_group(self.store, self.course) expected = self._get_expected_content_group(usage_for_group=[]) self.assertEqual(actual, expected) def test_can_get_correct_usage_info_when_special_characters_are_in_content(self): """ Test if content group json updated successfully with usage information. """ self._add_user_partitions(count=1, scheme_id='cohort') vertical, __ = self._create_problem_with_content_group( cid=0, group_id=1, name_suffix='0', special_characters=u"JOSÉ ANDRÉS" ) actual = GroupConfiguration.get_or_create_content_group(self.store, self.course) expected = self._get_expected_content_group( usage_for_group=[ { 'url': u"/container/{}".format(vertical.location), 'label': u"Test Unit 0 / Test Problem 0JOSÉ ANDRÉS" } ] ) self.assertEqual(actual, expected) def test_can_get_correct_usage_info_for_content_groups(self): """ Test if content group json updated successfully with usage information. """ self._add_user_partitions(count=1, scheme_id='cohort') vertical, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0') actual = GroupConfiguration.get_or_create_content_group(self.store, self.course) expected = self._get_expected_content_group(usage_for_group=[ { 'url': '/container/{}'.format(vertical.location), 'label': 'Test Unit 0 / Test Problem 0' } ]) self.assertEqual(actual, expected) def test_can_use_one_content_group_in_multiple_problems(self): """ Test if multiple problems are present in usage info when they use same content group. """ self._add_user_partitions(scheme_id='cohort') vertical, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0') vertical1, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='1') actual = GroupConfiguration.get_or_create_content_group(self.store, self.course) expected = self._get_expected_content_group(usage_for_group=[ { 'url': '/container/{}'.format(vertical.location), 'label': 'Test Unit 0 / Test Problem 0' }, { 'url': '/container/{}'.format(vertical1.location), 'label': 'Test Unit 1 / Test Problem 1' } ]) self.assertEqual(actual, expected) def test_group_configuration_not_used(self): """ Test that right data structure will be created if group configuration is not used. """ self._add_user_partitions() actual = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course) expected = [{ 'id': 0, 'name': 'Name 0', 'scheme': 'random', 'description': 'Description 0', 'version': UserPartition.VERSION, 'groups': [ {'id': 0, 'name': 'Group A', 'version': 1}, {'id': 1, 'name': 'Group B', 'version': 1}, {'id': 2, 'name': 'Group C', 'version': 1}, ], 'usage': [], 'parameters': {}, 'active': True, }] self.assertEqual(actual, expected) def test_can_get_correct_usage_info(self): """ Test if group configurations json updated successfully with usage information. """ self._add_user_partitions(count=2) vertical, __ = self._create_content_experiment(cid=0, name_suffix='0') self._create_content_experiment(name_suffix='1') actual = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course) expected = [{ 'id': 0, 'name': 'Name 0', 'scheme': 'random', 'description': 'Description 0', 'version': UserPartition.VERSION, 'groups': [ {'id': 0, 'name': 'Group A', 'version': 1}, {'id': 1, 'name': 'Group B', 'version': 1}, {'id': 2, 'name': 'Group C', 'version': 1}, ], 'usage': [{ 'url': '/container/{}'.format(vertical.location), 'label': 'Test Unit 0 / Test Content Experiment 0', 'validation': None, }], 'parameters': {}, 'active': True, }, { 'id': 1, 'name': 'Name 1', 'scheme': 'random', 'description': 'Description 1', 'version': UserPartition.VERSION, 'groups': [ {'id': 0, 'name': 'Group A', 'version': 1}, {'id': 1, 'name': 'Group B', 'version': 1}, {'id': 2, 'name': 'Group C', 'version': 1}, ], 'usage': [], 'parameters': {}, 'active': True, }] self.assertEqual(actual, expected) def test_can_get_usage_info_when_special_characters_are_used(self): """ Test if group configurations json updated successfully when special characters are being used in content experiment """ self._add_user_partitions(count=1) vertical, __ = self._create_content_experiment(cid=0, name_suffix='0', special_characters=u"JOSÉ ANDRÉS") actual = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course, ) expected = [{ 'id': 0, 'name': 'Name 0', 'scheme': 'random', 'description': 'Description 0', 'version': UserPartition.VERSION, 'groups': [ {'id': 0, 'name': 'Group A', 'version': 1}, {'id': 1, 'name': 'Group B', 'version': 1}, {'id': 2, 'name': 'Group C', 'version': 1}, ], 'usage': [{ 'url': '/container/{}'.format(vertical.location), 'label': u"Test Unit 0 / Test Content Experiment 0JOSÉ ANDRÉS", 'validation': None, }], 'parameters': {}, 'active': True, }] self.assertEqual(actual, expected) def test_can_use_one_configuration_in_multiple_experiments(self): """ Test if multiple experiments are present in usage info when they use same group configuration. """ self._add_user_partitions() vertical, __ = self._create_content_experiment(cid=0, name_suffix='0') vertical1, __ = self._create_content_experiment(cid=0, name_suffix='1') actual = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course) expected = [{ 'id': 0, 'name': 'Name 0', 'scheme': 'random', 'description': 'Description 0', 'version': UserPartition.VERSION, 'groups': [ {'id': 0, 'name': 'Group A', 'version': 1}, {'id': 1, 'name': 'Group B', 'version': 1}, {'id': 2, 'name': 'Group C', 'version': 1}, ], 'usage': [{ 'url': '/container/{}'.format(vertical.location), 'label': 'Test Unit 0 / Test Content Experiment 0', 'validation': None, }, { 'url': '/container/{}'.format(vertical1.location), 'label': 'Test Unit 1 / Test Content Experiment 1', 'validation': None, }], 'parameters': {}, 'active': True, }] self.assertEqual(actual, expected) def test_can_handle_without_parent(self): """ Test if it possible to handle case when split_test has no parent. """ self._add_user_partitions() # Create split test without parent. with modulestore().branch_setting(ModuleStoreEnum.Branch.published_only): orphan = modulestore().create_item( ModuleStoreEnum.UserID.test, self.course.id, 'split_test', ) orphan.user_partition_id = 0 orphan.display_name = 'Test Content Experiment' modulestore().update_item(orphan, ModuleStoreEnum.UserID.test) self.save_course() actual = GroupConfiguration.get_content_experiment_usage_info(self.store, self.course) self.assertEqual(actual, {0: []}) def test_can_handle_multiple_partitions(self): # Create the user partitions self.course.user_partitions = [ UserPartition( id=0, name='Cohort user partition', scheme=UserPartition.get_scheme('cohort'), description='Cohorted user partition', groups=[ Group(id=0, name="Group A"), Group(id=1, name="Group B"), ], ), UserPartition( id=1, name='Random user partition', scheme=UserPartition.get_scheme('random'), description='Random user partition', groups=[ Group(id=0, name="Group A"), Group(id=1, name="Group B"), ], ), ] self.store.update_item(self.course, ModuleStoreEnum.UserID.test) # Assign group access rules for multiple partitions, one of which is a cohorted partition __, problem = self._create_problem_with_content_group(0, 1) problem.group_access = { 0: [0], 1: [1], } self.store.update_item(problem, ModuleStoreEnum.UserID.test) # This used to cause an exception since the code assumed that # only one partition would be available. actual = GroupConfiguration.get_content_groups_usage_info(self.store, self.course) self.assertEqual(actual.keys(), [0]) actual = GroupConfiguration.get_content_groups_items_usage_info(self.store, self.course) self.assertEqual(actual.keys(), [0]) class GroupConfigurationsValidationTestCase(CourseTestCase, HelperMethods): """ Tests for validation in Group Configurations. """ def setUp(self): super(GroupConfigurationsValidationTestCase, self).setUp() @patch('xmodule.split_test_module.SplitTestDescriptor.validate_split_test') def verify_validation_add_usage_info(self, expected_result, mocked_message, mocked_validation_messages): """ Helper method for testing validation information present after add_usage_info. """ self._add_user_partitions() split_test = self._create_content_experiment(cid=0, name_suffix='0')[1] validation = StudioValidation(split_test.location) validation.add(mocked_message) mocked_validation_messages.return_value = validation group_configuration = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course)[0] self.assertEqual(expected_result.to_json(), group_configuration['usage'][0]['validation']) def test_error_message_present(self): """ Tests if validation message is present (error case). """ mocked_message = StudioValidationMessage(StudioValidationMessage.ERROR, u"Validation message") expected_result = StudioValidationMessage( StudioValidationMessage.ERROR, u"This content experiment has issues that affect content visibility." ) self.verify_validation_add_usage_info(expected_result, mocked_message) # pylint: disable=no-value-for-parameter def test_warning_message_present(self): """ Tests if validation message is present (warning case). """ mocked_message = StudioValidationMessage(StudioValidationMessage.WARNING, u"Validation message") expected_result = StudioValidationMessage( StudioValidationMessage.WARNING, u"This content experiment has issues that affect content visibility." ) self.verify_validation_add_usage_info(expected_result, mocked_message) # pylint: disable=no-value-for-parameter @patch('xmodule.split_test_module.SplitTestDescriptor.validate_split_test') def verify_validation_update_usage_info(self, expected_result, mocked_message, mocked_validation_messages): """ Helper method for testing validation information present after update_usage_info. """ self._add_user_partitions() split_test = self._create_content_experiment(cid=0, name_suffix='0')[1] validation = StudioValidation(split_test.location) if mocked_message is not None: validation.add(mocked_message) mocked_validation_messages.return_value = validation group_configuration = GroupConfiguration.update_usage_info( self.store, self.course, self.course.user_partitions[0] ) self.assertEqual( expected_result.to_json() if expected_result is not None else None, group_configuration['usage'][0]['validation'] ) def test_update_usage_info(self): """ Tests if validation message is present when updating usage info. """ mocked_message = StudioValidationMessage(StudioValidationMessage.WARNING, u"Validation message") expected_result = StudioValidationMessage( StudioValidationMessage.WARNING, u"This content experiment has issues that affect content visibility." ) # pylint: disable=no-value-for-parameter self.verify_validation_update_usage_info(expected_result, mocked_message) def test_update_usage_info_no_message(self): """ Tests if validation message is not present when updating usage info. """ self.verify_validation_update_usage_info(None, None) # pylint: disable=no-value-for-parameter
agpl-3.0
[ 3, 13, 1837, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 2448, 11595, 6496, 14, 199, 624, 199, 646, 2022, 199, 504, 1683, 492, 3371, 199, 504, 23061, 14, 1208, 492, 3837, 63, 1972, 63, 633, 12, 3837, 63, 3807, 63, 633, 199, 504, 23061, 14, 4196, 14, 3173, 492, 428, 2749, 649, 63, 2864, 63, 20360, 63, 2711, 199, 504, 23061, 14, 1972, 63, 923, 63, 888, 492, 5611, 5688, 199, 504, 23061, 14, 2219, 14, 1208, 492, 5531, 1746, 199, 504, 9872, 14, 12553, 14, 12553, 492, 5611, 12, 2876, 13068, 199, 504, 9872, 14, 10012, 14, 2219, 14, 15406, 492, 19319, 199, 504, 9872, 14, 6136, 492, 13225, 13816, 12, 13225, 13816, 2209, 199, 504, 9872, 14, 10012, 14, 1176, 492, 10996, 199, 504, 9872, 14, 10012, 492, 23431, 199, 199, 7823, 63, 22212, 63, 6243, 275, 469, 272, 399, 7, 354, 356, 399, 7, 774, 536, 297, 272, 399, 1159, 3453, 356, 399, 7, 2355, 297, 272, 399, 5121, 397, 4802, 356, 399, 7, 774, 1369, 297, 272, 399, 9064, 82, 438, 356, 2876, 13068, 14, 4612, 12, 272, 399, 7, 2634, 356, 359, 267, 469, 288, 399, 7, 354, 356, 399, 7, 2448, 437, 297, 288, 399, 9064, 82, 438, 356, 413, 12, 267, 1660, 469, 288, 399, 7, 354, 356, 399, 7, 2448, 699, 297, 288, 399, 9064, 82, 438, 356, 413, 12, 267, 1660, 272, 2156, 199, 93, 421, 199, 3, 4287, 26, 3507, 29, 889, 13, 1114, 199, 533, 11642, 10385, 8, 785, 304, 272, 408, 272, 28438, 626, 6571, 2997, 3102, 367, 5611, 11595, 2295, 14, 272, 408, 272, 347, 485, 981, 63, 1317, 63, 10873, 8, 277, 12, 12229, 4022, 17, 12, 536, 63, 4511, 4581, 4539, 63, 16516, 9280, 267, 408, 267, 2790, 1564, 11805, 14, 398, 16927, 5611, 11595, 370, 314, 11805, 340, 12229, 365, 2741, 14, 267, 408, 267, 13763, 275, 19319, 14, 981, 8, 288, 4637, 534, 7870, 297, 288, 1676, 63, 1985, 29, 277, 14, 1972, 14, 1985, 12, 288, 2929, 63, 354, 534, 774, 12008, 9499, 908, 8, 354, 63, 4511, 9, 267, 776, 267, 286, 16, 63, 633, 275, 291, 14, 1972, 14, 344, 14, 1875, 63, 3807, 63, 498, 480, 7870, 401, 298, 1294, 63, 396, 63, 2067, 16, 531, 267, 286, 17, 63, 633, 275, 291, 14, 1972, 14, 344, 14, 1875, 63, 3807, 63, 498, 480, 7870, 401, 298, 1294, 63, 396, 63, 2067, 17, 531, 267, 286, 18, 63, 633, 275, 291, 14, 1972, 14, 344, 14, 1875, 63, 3807, 63, 498, 480, 7870, 401, 298, 1294, 63, 396, 63, 2067, 18, 531, 267, 3715, 63, 396, 275, 19319, 14, 981, 8, 288, 4637, 534, 1294, 63, 396, 297, 288, 1676, 63, 1985, 29, 7870, 14, 1985, 12, 288, 922, 63, 5312, 63, 344, 29, 7504, 12, 288, 2929, 63, 354, 29, 85, 2, 774, 6646, 23997, 1052, 13536, 908, 8, 354, 63, 4511, 12, 4539, 63, 16516, 395, 288, 1572, 63, 344, 63, 475, 63, 1739, 8871, 16, 582, 286, 16, 63, 633, 12, 298, 17, 582, 286, 17, 63, 633, 12, 298, 18, 582, 286, 18, 63, 633, 93, 267, 776, 267, 19319, 14, 981, 8, 288, 1676, 63, 1985, 29, 1294, 63, 396, 14, 1985, 12, 288, 4637, 628, 7870, 401, 288, 2929, 63, 354, 628, 9558, 378, 13763, 401, 288, 2909, 29, 67, 16, 63, 633, 12, 267, 776, 267, 19319, 14, 981, 8, 288, 1676, 63, 1985, 29, 1294, 63, 396, 14, 1985, 12, 288, 4637, 628, 7870, 401, 288, 2929, 63, 354, 628, 9558, 413, 13763, 401, 288, 2909, 29, 67, 17, 63, 633, 12, 267, 776, 267, 19319, 14, 981, 8, 288, 1676, 63, 1985, 29, 1294, 63, 396, 14, 1985, 12, 288, 4637, 628, 7870, 401, 288, 2929, 63, 354, 628, 9558, 499, 13763, 401, 288, 2909, 29, 67, 18, 63, 633, 12, 267, 776, 398, 16394, 63, 1001, 275, 359, 80, 14, 475, 63, 1001, 342, 367, 299, 315, 291, 14, 1972, 14, 751, 63, 12553, 61, 398, 291, 14, 1258, 14, 12774, 63, 1932, 8, 288, 3837, 63, 3807, 63, 633, 480, 11283, 63, 2232, 401, 3715, 63, 396, 14, 1985, 395, 288, 666, 3713, 2343, 356, 791, 751, 63, 12553, 356, 16394, 63, 1001, 4863, 267, 776, 398, 291, 14, 2117, 63, 1972, 342, 267, 372, 334, 7870, 12, 3715, 63, 396, 9, 339, 347, 485, 981, 63, 6462, 63, 1045, 63, 1317, 63, 923, 8, 277, 12, 12229, 12, 1572, 63, 344, 12, 536, 63, 4511, 4581, 4539, 63, 16516, 9280, 267, 408, 267, 2790, 282, 5160, 267, 16927, 1564, 1572, 370, 314, 5160, 14, 267, 408, 267, 13763, 275, 19319, 14, 981, 8, 288, 4637, 534, 7870, 297, 288, 1676, 63, 1985, 29, 277, 14, 1972, 14, 1985, 12, 288, 2929, 63, 354, 628, 774, 12008, 8352, 908, 8, 354, 63, 4511, 9, 267, 776, 398, 5160, 275, 19319, 14, 981, 8, 288, 4637, 534, 6462, 297, 288, 1676, 63, 1985, 29, 7870, 14, 1985, 12, 288, 2929, 63, 354, 29, 85, 2, 774, 20980, 1052, 13536, 908, 8, 354, 63, 4511, 12, 4539, 63, 16516, 9, 267, 776, 398, 1572, 63, 2732, 63, 1317, 275, 791, 923, 63, 2732, 356, 469, 7504, 26, 359, 923, 63, 344, 61, 4863, 398, 291, 14, 1258, 14, 12774, 63, 1932, 8, 288, 3837, 63, 3807, 63, 633, 480, 11283, 63, 2232, 401, 5160, 14, 1985, 395, 288, 666, 3713, 2343, 356, 1572, 63, 2732, 63, 1317, 93, 267, 776, 398, 291, 14, 2117, 63, 1972, 342, 398, 372, 13763, 12, 5160, 339, 347, 485, 525, 63, 751, 63, 12553, 8, 277, 12, 2338, 29, 17, 12, 5687, 63, 344, 628, 2355, 2349, 267, 408, 267, 2790, 922, 16394, 367, 314, 2518, 14, 267, 408, 267, 16394, 275, 359, 288, 2876, 13068, 8, 355, 284, 12, 283, 985, 283, 435, 620, 8, 73, 395, 283, 5831, 283, 435, 620, 8, 73, 395, 355, 359, 2448, 8, 16, 12, 283, 2448, 437, 659, 5611, 8, 17, 12, 283, 2448, 699, 659, 5611, 8, 18, 12, 283, 2448, 445, 2665, 355, 5687, 29, 403, 12, 5687, 63, 344, 29, 5512, 63, 344, 288 ]
[ 13, 1837, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 2448, 11595, 6496, 14, 199, 624, 199, 646, 2022, 199, 504, 1683, 492, 3371, 199, 504, 23061, 14, 1208, 492, 3837, 63, 1972, 63, 633, 12, 3837, 63, 3807, 63, 633, 199, 504, 23061, 14, 4196, 14, 3173, 492, 428, 2749, 649, 63, 2864, 63, 20360, 63, 2711, 199, 504, 23061, 14, 1972, 63, 923, 63, 888, 492, 5611, 5688, 199, 504, 23061, 14, 2219, 14, 1208, 492, 5531, 1746, 199, 504, 9872, 14, 12553, 14, 12553, 492, 5611, 12, 2876, 13068, 199, 504, 9872, 14, 10012, 14, 2219, 14, 15406, 492, 19319, 199, 504, 9872, 14, 6136, 492, 13225, 13816, 12, 13225, 13816, 2209, 199, 504, 9872, 14, 10012, 14, 1176, 492, 10996, 199, 504, 9872, 14, 10012, 492, 23431, 199, 199, 7823, 63, 22212, 63, 6243, 275, 469, 272, 399, 7, 354, 356, 399, 7, 774, 536, 297, 272, 399, 1159, 3453, 356, 399, 7, 2355, 297, 272, 399, 5121, 397, 4802, 356, 399, 7, 774, 1369, 297, 272, 399, 9064, 82, 438, 356, 2876, 13068, 14, 4612, 12, 272, 399, 7, 2634, 356, 359, 267, 469, 288, 399, 7, 354, 356, 399, 7, 2448, 437, 297, 288, 399, 9064, 82, 438, 356, 413, 12, 267, 1660, 469, 288, 399, 7, 354, 356, 399, 7, 2448, 699, 297, 288, 399, 9064, 82, 438, 356, 413, 12, 267, 1660, 272, 2156, 199, 93, 421, 199, 3, 4287, 26, 3507, 29, 889, 13, 1114, 199, 533, 11642, 10385, 8, 785, 304, 272, 408, 272, 28438, 626, 6571, 2997, 3102, 367, 5611, 11595, 2295, 14, 272, 408, 272, 347, 485, 981, 63, 1317, 63, 10873, 8, 277, 12, 12229, 4022, 17, 12, 536, 63, 4511, 4581, 4539, 63, 16516, 9280, 267, 408, 267, 2790, 1564, 11805, 14, 398, 16927, 5611, 11595, 370, 314, 11805, 340, 12229, 365, 2741, 14, 267, 408, 267, 13763, 275, 19319, 14, 981, 8, 288, 4637, 534, 7870, 297, 288, 1676, 63, 1985, 29, 277, 14, 1972, 14, 1985, 12, 288, 2929, 63, 354, 534, 774, 12008, 9499, 908, 8, 354, 63, 4511, 9, 267, 776, 267, 286, 16, 63, 633, 275, 291, 14, 1972, 14, 344, 14, 1875, 63, 3807, 63, 498, 480, 7870, 401, 298, 1294, 63, 396, 63, 2067, 16, 531, 267, 286, 17, 63, 633, 275, 291, 14, 1972, 14, 344, 14, 1875, 63, 3807, 63, 498, 480, 7870, 401, 298, 1294, 63, 396, 63, 2067, 17, 531, 267, 286, 18, 63, 633, 275, 291, 14, 1972, 14, 344, 14, 1875, 63, 3807, 63, 498, 480, 7870, 401, 298, 1294, 63, 396, 63, 2067, 18, 531, 267, 3715, 63, 396, 275, 19319, 14, 981, 8, 288, 4637, 534, 1294, 63, 396, 297, 288, 1676, 63, 1985, 29, 7870, 14, 1985, 12, 288, 922, 63, 5312, 63, 344, 29, 7504, 12, 288, 2929, 63, 354, 29, 85, 2, 774, 6646, 23997, 1052, 13536, 908, 8, 354, 63, 4511, 12, 4539, 63, 16516, 395, 288, 1572, 63, 344, 63, 475, 63, 1739, 8871, 16, 582, 286, 16, 63, 633, 12, 298, 17, 582, 286, 17, 63, 633, 12, 298, 18, 582, 286, 18, 63, 633, 93, 267, 776, 267, 19319, 14, 981, 8, 288, 1676, 63, 1985, 29, 1294, 63, 396, 14, 1985, 12, 288, 4637, 628, 7870, 401, 288, 2929, 63, 354, 628, 9558, 378, 13763, 401, 288, 2909, 29, 67, 16, 63, 633, 12, 267, 776, 267, 19319, 14, 981, 8, 288, 1676, 63, 1985, 29, 1294, 63, 396, 14, 1985, 12, 288, 4637, 628, 7870, 401, 288, 2929, 63, 354, 628, 9558, 413, 13763, 401, 288, 2909, 29, 67, 17, 63, 633, 12, 267, 776, 267, 19319, 14, 981, 8, 288, 1676, 63, 1985, 29, 1294, 63, 396, 14, 1985, 12, 288, 4637, 628, 7870, 401, 288, 2929, 63, 354, 628, 9558, 499, 13763, 401, 288, 2909, 29, 67, 18, 63, 633, 12, 267, 776, 398, 16394, 63, 1001, 275, 359, 80, 14, 475, 63, 1001, 342, 367, 299, 315, 291, 14, 1972, 14, 751, 63, 12553, 61, 398, 291, 14, 1258, 14, 12774, 63, 1932, 8, 288, 3837, 63, 3807, 63, 633, 480, 11283, 63, 2232, 401, 3715, 63, 396, 14, 1985, 395, 288, 666, 3713, 2343, 356, 791, 751, 63, 12553, 356, 16394, 63, 1001, 4863, 267, 776, 398, 291, 14, 2117, 63, 1972, 342, 267, 372, 334, 7870, 12, 3715, 63, 396, 9, 339, 347, 485, 981, 63, 6462, 63, 1045, 63, 1317, 63, 923, 8, 277, 12, 12229, 12, 1572, 63, 344, 12, 536, 63, 4511, 4581, 4539, 63, 16516, 9280, 267, 408, 267, 2790, 282, 5160, 267, 16927, 1564, 1572, 370, 314, 5160, 14, 267, 408, 267, 13763, 275, 19319, 14, 981, 8, 288, 4637, 534, 7870, 297, 288, 1676, 63, 1985, 29, 277, 14, 1972, 14, 1985, 12, 288, 2929, 63, 354, 628, 774, 12008, 8352, 908, 8, 354, 63, 4511, 9, 267, 776, 398, 5160, 275, 19319, 14, 981, 8, 288, 4637, 534, 6462, 297, 288, 1676, 63, 1985, 29, 7870, 14, 1985, 12, 288, 2929, 63, 354, 29, 85, 2, 774, 20980, 1052, 13536, 908, 8, 354, 63, 4511, 12, 4539, 63, 16516, 9, 267, 776, 398, 1572, 63, 2732, 63, 1317, 275, 791, 923, 63, 2732, 356, 469, 7504, 26, 359, 923, 63, 344, 61, 4863, 398, 291, 14, 1258, 14, 12774, 63, 1932, 8, 288, 3837, 63, 3807, 63, 633, 480, 11283, 63, 2232, 401, 5160, 14, 1985, 395, 288, 666, 3713, 2343, 356, 1572, 63, 2732, 63, 1317, 93, 267, 776, 398, 291, 14, 2117, 63, 1972, 342, 398, 372, 13763, 12, 5160, 339, 347, 485, 525, 63, 751, 63, 12553, 8, 277, 12, 2338, 29, 17, 12, 5687, 63, 344, 628, 2355, 2349, 267, 408, 267, 2790, 922, 16394, 367, 314, 2518, 14, 267, 408, 267, 16394, 275, 359, 288, 2876, 13068, 8, 355, 284, 12, 283, 985, 283, 435, 620, 8, 73, 395, 283, 5831, 283, 435, 620,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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 ]
matthew-tucker/mne-python
mne/viz/tests/test_topo.py
7
4728
# Authors: Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr> # Denis Engemann <denis.engemann@gmail.com> # Martin Luessi <mluessi@nmr.mgh.harvard.edu> # Eric Larson <larson.eric.d@gmail.com> # # License: Simplified BSD import os.path as op import warnings from collections import namedtuple import numpy as np from numpy.testing import assert_raises from mne import io, read_events, Epochs from mne import pick_channels_evoked from mne.channels import read_layout from mne.time_frequency.tfr import AverageTFR from mne.utils import run_tests_if_main from mne.viz import (plot_topo, plot_topo_image_epochs, _get_presser, mne_analyze_colormap) from mne.viz.topo import _plot_update_evoked_topo # Set our plotters to test mode import matplotlib matplotlib.use('Agg') # for testing don't use X server warnings.simplefilter('always') # enable b/c these tests throw warnings base_dir = op.join(op.dirname(__file__), '..', '..', 'io', 'tests', 'data') evoked_fname = op.join(base_dir, 'test-ave.fif') raw_fname = op.join(base_dir, 'test_raw.fif') event_name = op.join(base_dir, 'test-eve.fif') event_id, tmin, tmax = 1, -0.2, 0.2 layout = read_layout('Vectorview-all') def _get_raw(): return io.Raw(raw_fname, preload=False) def _get_events(): return read_events(event_name) def _get_picks(raw): return [0, 1, 2, 6, 7, 8, 340, 341, 342] # take a only few channels def _get_epochs(): raw = _get_raw() events = _get_events() picks = _get_picks(raw) epochs = Epochs(raw, events[:10], event_id, tmin, tmax, picks=picks, baseline=(None, 0)) return epochs def _get_epochs_delayed_ssp(): raw = _get_raw() events = _get_events() picks = _get_picks(raw) reject = dict(mag=4e-12) epochs_delayed_ssp = Epochs(raw, events[:10], event_id, tmin, tmax, picks=picks, baseline=(None, 0), proj='delayed', reject=reject) return epochs_delayed_ssp def test_plot_topo(): """Test plotting of ERP topography """ import matplotlib.pyplot as plt # Show topography evoked = _get_epochs().average() plot_topo(evoked) # should auto-find layout warnings.simplefilter('always', UserWarning) picked_evoked = evoked.pick_channels(evoked.ch_names[:3], copy=True) picked_evoked_eeg = evoked.pick_types(meg=False, eeg=True, copy=True) picked_evoked_eeg.pick_channels(picked_evoked_eeg.ch_names[:3]) # test scaling with warnings.catch_warnings(record=True): for ylim in [dict(mag=[-600, 600]), None]: plot_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: assert_raises(ValueError, plot_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked(evoked_delayed_ssp, ch_names) fig = plot_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', 'inaxes') func(event(inaxes=fig.axes[0])) params = dict(evokeds=[picked_evoked_delayed_ssp], times=picked_evoked_delayed_ssp.times, fig=fig, projs=picked_evoked_delayed_ssp.info['projs']) bools = [True] * len(params['projs']) _plot_update_evoked_topo(params, bools) # should auto-generate layout plot_topo(picked_evoked_eeg.copy(), fig_background=np.zeros((4, 3, 3)), proj=True) plt.close('all') def test_plot_topo_image_epochs(): """Test plotting of epochs image topography """ import matplotlib.pyplot as plt title = 'ERF images - MNE sample data' epochs = _get_epochs() cmap = mne_analyze_colormap(format='matplotlib') plot_topo_image_epochs(epochs, sigma=0.5, vmin=-200, vmax=200, colorbar=True, title=title, cmap=cmap) plt.close('all') def test_plot_tfr_topo(): """Test plotting of TFR data """ epochs = _get_epochs() n_freqs = 3 nave = 1 data = np.random.RandomState(0).randn(len(epochs.ch_names), n_freqs, len(epochs.times)) tfr = AverageTFR(epochs.info, data, epochs.times, np.arange(n_freqs), nave) tfr.plot_topo(baseline=(None, 0), mode='ratio', title='Average power', vmin=0., vmax=14., show=False) tfr.plot([4], baseline=(None, 0), mode='ratio', show=False, title='foo') run_tests_if_main()
bsd-3-clause
[ 3, 6642, 26, 22986, 28547, 27211, 10279, 665, 24421, 28547, 14, 1679, 10279, 32, 15253, 957, 13, 462, 374, 15970, 14, 4391, 30, 199, 3, 3515, 25187, 374, 3447, 303, 20059, 665, 848, 374, 14, 287, 303, 20059, 32, 6799, 14, 957, 30, 199, 3, 3515, 603, 26788, 491, 10138, 338, 665, 757, 10138, 338, 32, 10756, 82, 14, 77, 3561, 14, 8210, 86, 1005, 14, 8654, 30, 199, 3, 3515, 662, 1567, 491, 285, 834, 665, 9828, 834, 14, 281, 530, 14, 68, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 844, 26, 29094, 30200, 6289, 199, 199, 646, 747, 14, 515, 465, 1687, 199, 646, 3598, 199, 504, 5055, 492, 12863, 199, 199, 646, 2680, 465, 980, 199, 504, 2680, 14, 4776, 492, 702, 63, 3536, 421, 199, 504, 18250, 492, 5890, 12, 1586, 63, 4368, 12, 662, 5132, 83, 199, 504, 18250, 492, 3732, 63, 6324, 63, 6857, 7620, 199, 504, 18250, 14, 6324, 492, 1586, 63, 4209, 199, 504, 18250, 14, 521, 63, 11132, 14, 3249, 82, 492, 437, 3652, 52, 5372, 199, 504, 18250, 14, 1208, 492, 1255, 63, 2219, 63, 692, 63, 973, 199, 199, 504, 18250, 14, 17249, 492, 334, 2798, 63, 16851, 12, 5137, 63, 16851, 63, 1569, 63, 13161, 12, 485, 362, 63, 24919, 332, 12, 2151, 18250, 63, 21184, 63, 2326, 1130, 9, 199, 504, 18250, 14, 17249, 14, 16851, 492, 485, 2798, 63, 873, 63, 6857, 7620, 63, 16851, 199, 199, 3, 2494, 4154, 5137, 878, 370, 511, 818, 199, 646, 8027, 199, 16440, 14, 1180, 360, 7248, 358, 221, 327, 367, 5343, 2793, 1133, 675, 1323, 1654, 199, 199, 5451, 14, 18815, 360, 9223, 358, 221, 327, 4756, 330, 15, 67, 3520, 2295, 7978, 3598, 421, 199, 1095, 63, 694, 275, 1687, 14, 904, 8, 411, 14, 3475, 3460, 493, 10139, 19155, 19155, 283, 2308, 297, 283, 2219, 297, 283, 576, 358, 199, 6857, 7620, 63, 5252, 275, 1687, 14, 904, 8, 1095, 63, 694, 12, 283, 396, 13, 811, 14, 25533, 358, 199, 1773, 63, 5252, 275, 1687, 14, 904, 8, 1095, 63, 694, 12, 283, 396, 63, 1773, 14, 25533, 358, 199, 1430, 63, 354, 275, 1687, 14, 904, 8, 1095, 63, 694, 12, 283, 396, 13, 4754, 14, 25533, 358, 199, 1430, 63, 344, 12, 307, 827, 12, 307, 988, 275, 413, 12, 446, 16, 14, 18, 12, 378, 14, 18, 199, 4209, 275, 1586, 63, 4209, 360, 3646, 1345, 13, 452, 358, 421, 199, 318, 485, 362, 63, 1773, 837, 272, 372, 5890, 14, 7963, 8, 1773, 63, 5252, 12, 32511, 29, 797, 9, 421, 199, 318, 485, 362, 63, 4368, 837, 272, 372, 1586, 63, 4368, 8, 1430, 63, 354, 9, 421, 199, 318, 485, 362, 63, 4510, 83, 8, 1773, 304, 272, 372, 359, 16, 12, 413, 12, 499, 12, 1227, 12, 1520, 12, 1695, 12, 650, 2167, 12, 650, 2953, 12, 650, 2260, 61, 221, 327, 5452, 282, 1454, 9284, 9245, 421, 199, 318, 485, 362, 63, 13161, 837, 272, 3066, 275, 485, 362, 63, 1773, 342, 272, 4474, 275, 485, 362, 63, 4368, 342, 272, 31055, 275, 485, 362, 63, 4510, 83, 8, 1773, 9, 272, 18463, 275, 662, 5132, 83, 8, 1773, 12, 4474, 1491, 709, 467, 1566, 63, 344, 12, 307, 827, 12, 307, 988, 12, 31055, 29, 4510, 83, 12, 490, 18828, 2687, 403, 12, 378, 430, 272, 372, 18463, 421, 199, 318, 485, 362, 63, 13161, 63, 21830, 63, 385, 80, 837, 272, 3066, 275, 485, 362, 63, 1773, 342, 272, 4474, 275, 485, 362, 63, 4368, 342, 272, 31055, 275, 485, 362, 63, 4510, 83, 8, 1773, 9, 272, 17100, 275, 1211, 8, 5615, 29, 20, 69, 13, 713, 9, 272, 18463, 63, 21830, 63, 385, 80, 275, 662, 5132, 83, 8, 1773, 12, 4474, 1491, 709, 467, 1566, 63, 344, 12, 307, 827, 12, 307, 988, 12, 1816, 31055, 29, 4510, 83, 12, 18828, 2687, 403, 12, 378, 395, 1816, 13523, 534, 21830, 297, 17100, 29, 16857, 9, 272, 372, 18463, 63, 21830, 63, 385, 80, 421, 199, 318, 511, 63, 2798, 63, 16851, 837, 272, 408, 774, 25174, 402, 221, 6758, 11111, 9773, 272, 408, 272, 492, 8027, 14, 13563, 465, 4488, 272, 327, 12968, 11111, 9773, 272, 8145, 7620, 275, 485, 362, 63, 13161, 1252, 8536, 342, 272, 5137, 63, 16851, 8, 6857, 7620, 9, 221, 327, 1077, 2599, 13, 1623, 7054, 272, 3598, 14, 18815, 360, 9223, 297, 2876, 3849, 9, 272, 29438, 63, 6857, 7620, 275, 8145, 7620, 14, 4510, 63, 6324, 8, 6857, 7620, 14, 335, 63, 1247, 1491, 19, 467, 1331, 29, 549, 9, 272, 29438, 63, 6857, 7620, 63, 1024, 71, 275, 8145, 7620, 14, 4510, 63, 1313, 8, 32177, 29, 797, 12, 325, 5902, 29, 549, 12, 1331, 29, 549, 9, 272, 29438, 63, 6857, 7620, 63, 1024, 71, 14, 4510, 63, 6324, 8, 4510, 379, 63, 6857, 7620, 63, 1024, 71, 14, 335, 63, 1247, 1491, 19, 566, 339, 327, 511, 13690, 272, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 304, 267, 367, 612, 4175, 315, 359, 807, 8, 5615, 1524, 13, 6683, 12, 11624, 2522, 488, 2189, 288, 5137, 63, 16851, 779, 4510, 379, 63, 6857, 7620, 61, 627, 499, 12, 7054, 12, 612, 4175, 29, 18123, 9, 398, 367, 325, 2392, 315, 359, 6857, 7620, 12, 359, 6857, 7620, 12, 29438, 63, 6857, 7620, 27589, 288, 702, 63, 3536, 8, 3393, 12, 5137, 63, 16851, 12, 325, 2392, 12, 7054, 12, 3164, 2968, 89, 297, 283, 66, 1105, 398, 8145, 7620, 63, 21830, 63, 385, 80, 275, 485, 362, 63, 13161, 63, 21830, 63, 385, 80, 1252, 8536, 342, 267, 682, 63, 1247, 275, 8145, 7620, 63, 21830, 63, 385, 80, 14, 335, 63, 1247, 1491, 19, 61, 221, 327, 1852, 652, 12930, 267, 29438, 63, 6857, 7620, 63, 21830, 63, 385, 80, 275, 3732, 63, 6324, 63, 6857, 7620, 8, 6857, 7620, 63, 21830, 63, 385, 80, 12, 12740, 682, 63, 1247, 9, 267, 6085, 275, 5137, 63, 16851, 8, 4510, 379, 63, 6857, 7620, 63, 21830, 63, 385, 80, 12, 7054, 12, 13523, 534, 13543, 358, 267, 2562, 275, 485, 362 ]
[ 6642, 26, 22986, 28547, 27211, 10279, 665, 24421, 28547, 14, 1679, 10279, 32, 15253, 957, 13, 462, 374, 15970, 14, 4391, 30, 199, 3, 3515, 25187, 374, 3447, 303, 20059, 665, 848, 374, 14, 287, 303, 20059, 32, 6799, 14, 957, 30, 199, 3, 3515, 603, 26788, 491, 10138, 338, 665, 757, 10138, 338, 32, 10756, 82, 14, 77, 3561, 14, 8210, 86, 1005, 14, 8654, 30, 199, 3, 3515, 662, 1567, 491, 285, 834, 665, 9828, 834, 14, 281, 530, 14, 68, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 844, 26, 29094, 30200, 6289, 199, 199, 646, 747, 14, 515, 465, 1687, 199, 646, 3598, 199, 504, 5055, 492, 12863, 199, 199, 646, 2680, 465, 980, 199, 504, 2680, 14, 4776, 492, 702, 63, 3536, 421, 199, 504, 18250, 492, 5890, 12, 1586, 63, 4368, 12, 662, 5132, 83, 199, 504, 18250, 492, 3732, 63, 6324, 63, 6857, 7620, 199, 504, 18250, 14, 6324, 492, 1586, 63, 4209, 199, 504, 18250, 14, 521, 63, 11132, 14, 3249, 82, 492, 437, 3652, 52, 5372, 199, 504, 18250, 14, 1208, 492, 1255, 63, 2219, 63, 692, 63, 973, 199, 199, 504, 18250, 14, 17249, 492, 334, 2798, 63, 16851, 12, 5137, 63, 16851, 63, 1569, 63, 13161, 12, 485, 362, 63, 24919, 332, 12, 2151, 18250, 63, 21184, 63, 2326, 1130, 9, 199, 504, 18250, 14, 17249, 14, 16851, 492, 485, 2798, 63, 873, 63, 6857, 7620, 63, 16851, 199, 199, 3, 2494, 4154, 5137, 878, 370, 511, 818, 199, 646, 8027, 199, 16440, 14, 1180, 360, 7248, 358, 221, 327, 367, 5343, 2793, 1133, 675, 1323, 1654, 199, 199, 5451, 14, 18815, 360, 9223, 358, 221, 327, 4756, 330, 15, 67, 3520, 2295, 7978, 3598, 421, 199, 1095, 63, 694, 275, 1687, 14, 904, 8, 411, 14, 3475, 3460, 493, 10139, 19155, 19155, 283, 2308, 297, 283, 2219, 297, 283, 576, 358, 199, 6857, 7620, 63, 5252, 275, 1687, 14, 904, 8, 1095, 63, 694, 12, 283, 396, 13, 811, 14, 25533, 358, 199, 1773, 63, 5252, 275, 1687, 14, 904, 8, 1095, 63, 694, 12, 283, 396, 63, 1773, 14, 25533, 358, 199, 1430, 63, 354, 275, 1687, 14, 904, 8, 1095, 63, 694, 12, 283, 396, 13, 4754, 14, 25533, 358, 199, 1430, 63, 344, 12, 307, 827, 12, 307, 988, 275, 413, 12, 446, 16, 14, 18, 12, 378, 14, 18, 199, 4209, 275, 1586, 63, 4209, 360, 3646, 1345, 13, 452, 358, 421, 199, 318, 485, 362, 63, 1773, 837, 272, 372, 5890, 14, 7963, 8, 1773, 63, 5252, 12, 32511, 29, 797, 9, 421, 199, 318, 485, 362, 63, 4368, 837, 272, 372, 1586, 63, 4368, 8, 1430, 63, 354, 9, 421, 199, 318, 485, 362, 63, 4510, 83, 8, 1773, 304, 272, 372, 359, 16, 12, 413, 12, 499, 12, 1227, 12, 1520, 12, 1695, 12, 650, 2167, 12, 650, 2953, 12, 650, 2260, 61, 221, 327, 5452, 282, 1454, 9284, 9245, 421, 199, 318, 485, 362, 63, 13161, 837, 272, 3066, 275, 485, 362, 63, 1773, 342, 272, 4474, 275, 485, 362, 63, 4368, 342, 272, 31055, 275, 485, 362, 63, 4510, 83, 8, 1773, 9, 272, 18463, 275, 662, 5132, 83, 8, 1773, 12, 4474, 1491, 709, 467, 1566, 63, 344, 12, 307, 827, 12, 307, 988, 12, 31055, 29, 4510, 83, 12, 490, 18828, 2687, 403, 12, 378, 430, 272, 372, 18463, 421, 199, 318, 485, 362, 63, 13161, 63, 21830, 63, 385, 80, 837, 272, 3066, 275, 485, 362, 63, 1773, 342, 272, 4474, 275, 485, 362, 63, 4368, 342, 272, 31055, 275, 485, 362, 63, 4510, 83, 8, 1773, 9, 272, 17100, 275, 1211, 8, 5615, 29, 20, 69, 13, 713, 9, 272, 18463, 63, 21830, 63, 385, 80, 275, 662, 5132, 83, 8, 1773, 12, 4474, 1491, 709, 467, 1566, 63, 344, 12, 307, 827, 12, 307, 988, 12, 1816, 31055, 29, 4510, 83, 12, 18828, 2687, 403, 12, 378, 395, 1816, 13523, 534, 21830, 297, 17100, 29, 16857, 9, 272, 372, 18463, 63, 21830, 63, 385, 80, 421, 199, 318, 511, 63, 2798, 63, 16851, 837, 272, 408, 774, 25174, 402, 221, 6758, 11111, 9773, 272, 408, 272, 492, 8027, 14, 13563, 465, 4488, 272, 327, 12968, 11111, 9773, 272, 8145, 7620, 275, 485, 362, 63, 13161, 1252, 8536, 342, 272, 5137, 63, 16851, 8, 6857, 7620, 9, 221, 327, 1077, 2599, 13, 1623, 7054, 272, 3598, 14, 18815, 360, 9223, 297, 2876, 3849, 9, 272, 29438, 63, 6857, 7620, 275, 8145, 7620, 14, 4510, 63, 6324, 8, 6857, 7620, 14, 335, 63, 1247, 1491, 19, 467, 1331, 29, 549, 9, 272, 29438, 63, 6857, 7620, 63, 1024, 71, 275, 8145, 7620, 14, 4510, 63, 1313, 8, 32177, 29, 797, 12, 325, 5902, 29, 549, 12, 1331, 29, 549, 9, 272, 29438, 63, 6857, 7620, 63, 1024, 71, 14, 4510, 63, 6324, 8, 4510, 379, 63, 6857, 7620, 63, 1024, 71, 14, 335, 63, 1247, 1491, 19, 566, 339, 327, 511, 13690, 272, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 304, 267, 367, 612, 4175, 315, 359, 807, 8, 5615, 1524, 13, 6683, 12, 11624, 2522, 488, 2189, 288, 5137, 63, 16851, 779, 4510, 379, 63, 6857, 7620, 61, 627, 499, 12, 7054, 12, 612, 4175, 29, 18123, 9, 398, 367, 325, 2392, 315, 359, 6857, 7620, 12, 359, 6857, 7620, 12, 29438, 63, 6857, 7620, 27589, 288, 702, 63, 3536, 8, 3393, 12, 5137, 63, 16851, 12, 325, 2392, 12, 7054, 12, 3164, 2968, 89, 297, 283, 66, 1105, 398, 8145, 7620, 63, 21830, 63, 385, 80, 275, 485, 362, 63, 13161, 63, 21830, 63, 385, 80, 1252, 8536, 342, 267, 682, 63, 1247, 275, 8145, 7620, 63, 21830, 63, 385, 80, 14, 335, 63, 1247, 1491, 19, 61, 221, 327, 1852, 652, 12930, 267, 29438, 63, 6857, 7620, 63, 21830, 63, 385, 80, 275, 3732, 63, 6324, 63, 6857, 7620, 8, 6857, 7620, 63, 21830, 63, 385, 80, 12, 12740, 682, 63, 1247, 9, 267, 6085, 275, 5137, 63, 16851, 8, 4510, 379, 63, 6857, 7620, 63, 21830, 63, 385, 80, 12, 7054, 12, 13523, 534, 13543, 358, 267, 2562, 275, 485, 362, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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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 ]
ict-felix/stack
vt_manager_kvm/src/python/vt_manager_kvm/communication/sfa/trust/auth.py
1
11404
# # SfaAPI authentication # import sys from vt_manager_kvm.communication.sfa.util.faults import InsufficientRights, MissingCallerGID, MissingTrustedRoots, PermissionError, \ BadRequestHash, ConnectionKeyGIDMismatch, SfaPermissionDenied #from vt_manager_kvm.communication.sfa.util.config import Config from vt_manager_kvm.communication.sfa.util.xrn import get_authority from vt_manager_kvm.communication.sfa.trust.gid import GID from vt_manager_kvm.communication.sfa.trust.rights import Rights from vt_manager_kvm.communication.sfa.trust.certificate import Keypair, Certificate from vt_manager_kvm.communication.sfa.trust.credential import Credential from vt_manager_kvm.communication.sfa.trust.trustedroots import TrustedRoots from vt_manager_kvm.communication.sfa.trust.hierarchy import Hierarchy from vt_manager_kvm.communication.sfa.trust.sfaticket import SfaTicket from vt_manager_kvm.communication.sfa.sfa_config import config as CONFIG class Auth: """ Credential based authentication """ def __init__(self, peer_cert = None, config = None ): self.peer_cert = peer_cert self.hierarchy = Hierarchy() #if not config: self.config = CONFIG#Config() self.load_trusted_certs() def load_trusted_certs(self): self.trusted_cert_list = TrustedRoots(self.config.TRUSTED_ROOTS_DIR).get_list() self.trusted_cert_file_list = TrustedRoots(self.config.TRUSTED_ROOTS_DIR).get_file_list() def checkCredentials(self, creds, operation, hrn = None): valid = [] error = None if not isinstance(creds, list): creds = [creds] for cred in creds: try: self.check(cred, operation, hrn) valid.append(cred) except Exception as e: cred_obj=Credential(string=cred) error = e#sys.exc_info()[:2] continue if not len(valid): if not error: error = "No valid credentials found" raise InsufficientRights('Access denied: %s' % (str(error))) return valid def check(self, cred, operation, hrn = None): """ Check the credential against the peer cert (callerGID included in the credential matches the caller that is connected to the HTTPS connection, check if the credential was signed by a trusted cert and check if the credential is allowed to perform the specified operation. """ self.client_cred = Credential(string = cred) self.client_gid = self.client_cred.get_gid_caller() self.object_gid = self.client_cred.get_gid_object() # make sure the client_gid is not blank if not self.client_gid: raise MissingCallerGID(self.client_cred.get_subject()) # validate the client cert if it exists if self.peer_cert: self.verifyPeerCert(self.peer_cert, self.client_gid) # make sure the client is allowed to perform the operation if operation: if not self.client_cred.can_perform(operation): raise InsufficientRights(operation) if self.trusted_cert_list: self.client_cred.verify(self.trusted_cert_file_list, self.config.SFA_CREDENTIAL_SCHEMA) else: raise MissingTrustedRoots(self.config.get_trustedroots_dir()) # Make sure the credential's target matches the specified hrn. # This check does not apply to trusted peers trusted_peers = [gid.get_hrn() for gid in self.trusted_cert_list] if hrn and self.client_gid.get_hrn() not in trusted_peers: target_hrn = self.object_gid.get_hrn() if not hrn == target_hrn: raise PermissionError("Target hrn: %s doesn't match specified hrn: %s " % \ (target_hrn, hrn) ) return True def check_ticket(self, ticket): """ Check if the tickt was signed by a trusted cert """ if self.trusted_cert_list: client_ticket = SfaTicket(string=ticket) client_ticket.verify_chain(self.trusted_cert_list) else: raise MissingTrustedRoots(self.config.get_trustedroots_dir()) return True def verifyPeerCert(self, cert, gid): # make sure the client_gid matches client's certificate if not cert.is_pubkey(gid.get_pubkey()): raise ConnectionKeyGIDMismatch(gid.get_subject()+":"+cert.get_subject()) def verifyGidRequestHash(self, gid, hash, arglist): key = gid.get_pubkey() if not key.verify_string(str(arglist), hash): raise BadRequestHash(hash) def verifyCredRequestHash(self, cred, hash, arglist): gid = cred.get_gid_caller() self.verifyGidRequestHash(gid, hash, arglist) def validateGid(self, gid): if self.trusted_cert_list: gid.verify_chain(self.trusted_cert_list) def validateCred(self, cred): if self.trusted_cert_list: cred.verify(self.trusted_cert_file_list) def authenticateGid(self, gidStr, argList, requestHash=None): gid = GID(string = gidStr) self.validateGid(gid) # request_hash is optional if requestHash: self.verifyGidRequestHash(gid, requestHash, argList) return gid def authenticateCred(self, credStr, argList, requestHash=None): cred = Credential(string = credStr) self.validateCred(cred) # request hash is optional if requestHash: self.verifyCredRequestHash(cred, requestHash, argList) return cred def authenticateCert(self, certStr, requestHash): cert = Certificate(string=certStr) # xxx should be validateCred ?? self.validateCred(cert) def gidNoop(self, gidStr, value, requestHash): self.authenticateGid(gidStr, [gidStr, value], requestHash) return value def credNoop(self, credStr, value, requestHash): self.authenticateCred(credStr, [credStr, value], requestHash) return value def verify_cred_is_me(self, credential): is_me = False cred = Credential(string=credential) caller_gid = cred.get_gid_caller() caller_hrn = caller_gid.get_hrn() if caller_hrn != self.config.SFA_INTERFACE_HRN: raise SfaPermissionDenied(self.config.SFA_INTEFACE_HRN) return def get_auth_info(self, auth_hrn): """ Given an authority name, return the information for that authority. This is basically a stub that calls the hierarchy module. @param auth_hrn human readable name of authority """ return self.hierarchy.get_auth_info(auth_hrn) def veriry_auth_belongs_to_me(self, name): """ Verify that an authority belongs to our hierarchy. This is basically left up to the implementation of the hierarchy module. If the specified name does not belong, ane exception is thrown indicating the caller should contact someone else. @param auth_name human readable name of authority """ # get auth info will throw an exception if the authority doesnt exist self.get_auth_info(name) def verify_object_belongs_to_me(self, name): """ Verify that an object belongs to our hierarchy. By extension, this implies that the authority that owns the object belongs to our hierarchy. If it does not an exception is thrown. @param name human readable name of object """ auth_name = self.get_authority(name) if not auth_name: auth_name = name if name == self.config.SFA_INTERFACE_HRN: return self.verify_auth_belongs_to_me(auth_name) def verify_auth_belongs_to_me(self, name): # get auth info will throw an exception if the authority doesnt exist self.get_auth_info(name) def verify_object_permission(self, name): """ Verify that the object gid that was specified in the credential allows permission to the object 'name'. This is done by a simple prefix test. For example, an object_gid for plc.arizona would match the objects plc.arizona.slice1 and plc.arizona. @param name human readable name to test """ object_hrn = self.object_gid.get_hrn() if object_hrn == name: return if name.startswith(object_hrn + "."): return #if name.startswith(get_authority(name)): #return raise PermissionError(name) def determine_user_rights(self, caller_hrn, reg_record): """ Given a user credential and a record, determine what set of rights the user should have to that record. This is intended to replace determine_user_rights() and verify_cancreate_credential() """ rl = Rights() type = reg_record.type if type == 'slice': # researchers in the slice are in the DB as-is researcher_hrns = [ user.hrn for user in reg_record.reg_researchers ] # locating PIs attached to that slice slice_pis=reg_record.get_pis() pi_hrns = [ user.hrn for user in slice_pis ] if (caller_hrn in researcher_hrns + pi_hrns): rl.add('refresh') rl.add('embed') rl.add('bind') rl.add('control') rl.add('info') elif type == 'authority': pi_hrns = [ user.hrn for user in reg_record.reg_pis ] if (caller_hrn == self.config.SFA_INTERFACE_HRN): rl.add('authority') rl.add('sa') rl.add('ma') if (caller_hrn in pi_hrns): rl.add('authority') rl.add('sa') # NOTE: for the PL implementation, this 'operators' list # amounted to users with 'tech' role in that site # it seems like this is not needed any longer, so for now I just drop that # operator_hrns = reg_record.get('operator',[]) # if (caller_hrn in operator_hrns): # rl.add('authority') # rl.add('ma') elif type == 'user': rl.add('refresh') rl.add('resolve') rl.add('info') elif type == 'node': rl.add('operator') return rl def get_authority(self, hrn): return get_authority(hrn) def filter_creds_by_caller(self, creds, caller_hrn_list): """ Returns a list of creds who's gid caller matches the specified caller hrn """ if not isinstance(creds, list): creds = [creds] creds = [] if not isinstance(caller_hrn_list, list): caller_hrn_list = [caller_hrn_list] for cred in creds: try: tmp_cred = Credential(string=cred) if tmp_cred.get_gid_caller().get_hrn() in [caller_hrn_list]: creds.append(cred) except: pass return creds
apache-2.0
[ 3, 199, 3, 428, 667, 3735, 6299, 221, 199, 3, 199, 646, 984, 199, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 1974, 14, 1879, 83, 492, 12062, 12983, 50, 2492, 12, 15626, 6584, 1435, 39, 998, 12, 15626, 14064, 7274, 6405, 83, 12, 8779, 547, 12, 971, 272, 8857, 2017, 3476, 12, 8113, 1197, 39, 998, 23055, 12, 428, 667, 7980, 15729, 199, 3, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 1974, 14, 888, 492, 4094, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 1974, 14, 88, 11641, 492, 664, 63, 23635, 199, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 8787, 492, 598, 998, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 17307, 492, 5924, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 6999, 492, 2606, 3852, 12, 12904, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 15591, 492, 9750, 3256, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 17549, 12065, 492, 28814, 7274, 6405, 83, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 14861, 492, 869, 8641, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 83, 667, 9201, 492, 428, 667, 25813, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 83, 667, 63, 888, 492, 1101, 465, 15869, 199, 199, 533, 3590, 26, 272, 408, 272, 9750, 3256, 4079, 6299, 272, 408, 339, 347, 636, 826, 721, 277, 12, 9104, 63, 4736, 275, 488, 12, 1101, 275, 488, 3461, 267, 291, 14, 7866, 63, 4736, 275, 9104, 63, 4736, 267, 291, 14, 14861, 275, 869, 8641, 342, 267, 327, 692, 440, 1101, 26, 267, 291, 14, 888, 275, 15869, 3, 2028, 342, 267, 291, 14, 912, 63, 17549, 63, 8356, 342, 339, 347, 2248, 63, 17549, 63, 8356, 8, 277, 304, 267, 291, 14, 17549, 63, 4736, 63, 513, 275, 28814, 7274, 6405, 83, 8, 277, 14, 888, 14, 1766, 7698, 1149, 63, 5441, 51, 63, 3022, 680, 362, 63, 513, 342, 267, 291, 14, 17549, 63, 4736, 63, 493, 63, 513, 275, 28814, 7274, 6405, 83, 8, 277, 14, 888, 14, 1766, 7698, 1149, 63, 5441, 51, 63, 3022, 680, 362, 63, 493, 63, 513, 342, 881, 5493, 347, 1104, 13428, 8, 277, 12, 20023, 12, 3439, 12, 394, 11641, 275, 488, 304, 267, 1686, 275, 942, 267, 1125, 275, 488, 267, 340, 440, 1228, 8, 15226, 12, 769, 304, 288, 20023, 275, 359, 15226, 61, 267, 367, 22314, 315, 20023, 26, 288, 862, 26, 355, 291, 14, 1074, 8, 18639, 12, 3439, 12, 394, 11641, 9, 355, 1686, 14, 740, 8, 18639, 9, 288, 871, 2186, 465, 325, 26, 355, 22314, 63, 1113, 29, 23330, 8, 875, 29, 18639, 9, 355, 1125, 275, 325, 3, 1274, 14, 2804, 63, 815, 20523, 18, 61, 355, 1980, 267, 340, 440, 822, 8, 1078, 304, 288, 340, 440, 1125, 26, 355, 1125, 275, 298, 1944, 1686, 6235, 1911, 2, 7205, 746, 12062, 12983, 50, 2492, 360, 3946, 23355, 26, 450, 83, 7, 450, 334, 495, 8, 705, 1724, 2728, 372, 1686, 268, 5493, 347, 1104, 8, 277, 12, 22314, 12, 3439, 12, 394, 11641, 275, 488, 304, 267, 408, 267, 2670, 314, 16338, 6169, 314, 9104, 6250, 334, 11219, 39, 998, 5120, 4960, 315, 314, 16338, 4450, 314, 8025, 626, 365, 8539, 370, 314, 4960, 14147, 1950, 12, 1104, 340, 314, 16338, 1990, 10514, 701, 282, 4960, 19427, 6250, 436, 1104, 340, 314, 16338, 365, 4370, 370, 5147, 4960, 314, 2013, 3439, 14, 27144, 408, 267, 291, 14, 1258, 63, 18639, 275, 9750, 3256, 8, 875, 275, 22314, 9, 267, 291, 14, 1258, 63, 8787, 275, 291, 14, 1258, 63, 18639, 14, 362, 63, 8787, 63, 11219, 342, 267, 291, 14, 785, 63, 8787, 275, 291, 14, 1258, 63, 18639, 14, 362, 63, 8787, 63, 785, 342, 2728, 327, 1852, 3238, 314, 1890, 63, 8787, 365, 440, 4596, 267, 340, 440, 291, 14, 1258, 63, 8787, 26, 288, 746, 15626, 6584, 1435, 39, 998, 8, 277, 14, 1258, 63, 18639, 14, 362, 63, 5875, 1012, 267, 267, 327, 4107, 314, 1890, 6250, 340, 652, 3495, 267, 340, 291, 14, 7866, 63, 4736, 26, 288, 291, 14, 4712, 12566, 14768, 8, 277, 14, 7866, 63, 4736, 12, 291, 14, 1258, 63, 8787, 9, 2043, 267, 327, 1852, 3238, 314, 1890, 365, 4370, 370, 5147, 314, 3439, 267, 340, 3439, 26, 288, 340, 440, 291, 14, 1258, 63, 18639, 14, 2425, 63, 15795, 8, 5735, 304, 355, 746, 12062, 12983, 50, 2492, 8, 5735, 9, 267, 340, 291, 14, 17549, 63, 4736, 63, 513, 26, 288, 291, 14, 1258, 63, 18639, 14, 4712, 8, 277, 14, 17549, 63, 4736, 63, 493, 63, 513, 12, 291, 14, 888, 14, 51, 2078, 63, 30553, 8246, 63, 10926, 9, 267, 587, 26, 1779, 746, 15626, 14064, 7274, 6405, 83, 8, 277, 14, 888, 14, 362, 63, 17549, 12065, 63, 694, 1012, 267, 267, 327, 4155, 3238, 314, 16338, 1159, 1347, 4450, 314, 2013, 394, 11641, 14, 4960, 327, 961, 1104, 1630, 440, 4838, 370, 19427, 28166, 4960, 19427, 63, 22416, 275, 359, 8787, 14, 362, 63, 6271, 78, 342, 367, 15122, 315, 291, 14, 17549, 63, 4736, 63, 513, 61, 267, 340, 394, 11641, 436, 291, 14, 1258, 63, 8787, 14, 362, 63, 6271, 78, 342, 440, 315, 19427, 63, 22416, 26, 288, 1347, 63, 6271, 78, 275, 291, 14, 785, 63, 8787, 14, 362, 63, 6271, 78, 342, 288, 340, 440, 394, 11641, 508, 1347, 63, 6271, 78, 26, 355, 746, 8779, 547, 480, 4277, 394, 11641, 26, 450, 83, 3181, 1133, 1336, 2013, 394, 11641, 26, 450, 83, 298, 450, 971, 4318, 334, 1375, 63, 6271, 78, 12, 394, 11641, 9, 776, 27144, 372, 715, 339, 347, 1104, 63, 9201, 8, 277, 12, 12052, 304, 267, 408, 267, 2670, 340, 314, 11748, 84, 1990, 10514, 701 ]
[ 199, 3, 428, 667, 3735, 6299, 221, 199, 3, 199, 646, 984, 199, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 1974, 14, 1879, 83, 492, 12062, 12983, 50, 2492, 12, 15626, 6584, 1435, 39, 998, 12, 15626, 14064, 7274, 6405, 83, 12, 8779, 547, 12, 971, 272, 8857, 2017, 3476, 12, 8113, 1197, 39, 998, 23055, 12, 428, 667, 7980, 15729, 199, 3, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 1974, 14, 888, 492, 4094, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 1974, 14, 88, 11641, 492, 664, 63, 23635, 199, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 8787, 492, 598, 998, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 17307, 492, 5924, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 6999, 492, 2606, 3852, 12, 12904, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 15591, 492, 9750, 3256, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 17549, 12065, 492, 28814, 7274, 6405, 83, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 14861, 492, 869, 8641, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 15756, 14, 83, 667, 9201, 492, 428, 667, 25813, 199, 504, 18585, 63, 2609, 63, 29272, 14, 29351, 14, 83, 667, 14, 83, 667, 63, 888, 492, 1101, 465, 15869, 199, 199, 533, 3590, 26, 272, 408, 272, 9750, 3256, 4079, 6299, 272, 408, 339, 347, 636, 826, 721, 277, 12, 9104, 63, 4736, 275, 488, 12, 1101, 275, 488, 3461, 267, 291, 14, 7866, 63, 4736, 275, 9104, 63, 4736, 267, 291, 14, 14861, 275, 869, 8641, 342, 267, 327, 692, 440, 1101, 26, 267, 291, 14, 888, 275, 15869, 3, 2028, 342, 267, 291, 14, 912, 63, 17549, 63, 8356, 342, 339, 347, 2248, 63, 17549, 63, 8356, 8, 277, 304, 267, 291, 14, 17549, 63, 4736, 63, 513, 275, 28814, 7274, 6405, 83, 8, 277, 14, 888, 14, 1766, 7698, 1149, 63, 5441, 51, 63, 3022, 680, 362, 63, 513, 342, 267, 291, 14, 17549, 63, 4736, 63, 493, 63, 513, 275, 28814, 7274, 6405, 83, 8, 277, 14, 888, 14, 1766, 7698, 1149, 63, 5441, 51, 63, 3022, 680, 362, 63, 493, 63, 513, 342, 881, 5493, 347, 1104, 13428, 8, 277, 12, 20023, 12, 3439, 12, 394, 11641, 275, 488, 304, 267, 1686, 275, 942, 267, 1125, 275, 488, 267, 340, 440, 1228, 8, 15226, 12, 769, 304, 288, 20023, 275, 359, 15226, 61, 267, 367, 22314, 315, 20023, 26, 288, 862, 26, 355, 291, 14, 1074, 8, 18639, 12, 3439, 12, 394, 11641, 9, 355, 1686, 14, 740, 8, 18639, 9, 288, 871, 2186, 465, 325, 26, 355, 22314, 63, 1113, 29, 23330, 8, 875, 29, 18639, 9, 355, 1125, 275, 325, 3, 1274, 14, 2804, 63, 815, 20523, 18, 61, 355, 1980, 267, 340, 440, 822, 8, 1078, 304, 288, 340, 440, 1125, 26, 355, 1125, 275, 298, 1944, 1686, 6235, 1911, 2, 7205, 746, 12062, 12983, 50, 2492, 360, 3946, 23355, 26, 450, 83, 7, 450, 334, 495, 8, 705, 1724, 2728, 372, 1686, 268, 5493, 347, 1104, 8, 277, 12, 22314, 12, 3439, 12, 394, 11641, 275, 488, 304, 267, 408, 267, 2670, 314, 16338, 6169, 314, 9104, 6250, 334, 11219, 39, 998, 5120, 4960, 315, 314, 16338, 4450, 314, 8025, 626, 365, 8539, 370, 314, 4960, 14147, 1950, 12, 1104, 340, 314, 16338, 1990, 10514, 701, 282, 4960, 19427, 6250, 436, 1104, 340, 314, 16338, 365, 4370, 370, 5147, 4960, 314, 2013, 3439, 14, 27144, 408, 267, 291, 14, 1258, 63, 18639, 275, 9750, 3256, 8, 875, 275, 22314, 9, 267, 291, 14, 1258, 63, 8787, 275, 291, 14, 1258, 63, 18639, 14, 362, 63, 8787, 63, 11219, 342, 267, 291, 14, 785, 63, 8787, 275, 291, 14, 1258, 63, 18639, 14, 362, 63, 8787, 63, 785, 342, 2728, 327, 1852, 3238, 314, 1890, 63, 8787, 365, 440, 4596, 267, 340, 440, 291, 14, 1258, 63, 8787, 26, 288, 746, 15626, 6584, 1435, 39, 998, 8, 277, 14, 1258, 63, 18639, 14, 362, 63, 5875, 1012, 267, 267, 327, 4107, 314, 1890, 6250, 340, 652, 3495, 267, 340, 291, 14, 7866, 63, 4736, 26, 288, 291, 14, 4712, 12566, 14768, 8, 277, 14, 7866, 63, 4736, 12, 291, 14, 1258, 63, 8787, 9, 2043, 267, 327, 1852, 3238, 314, 1890, 365, 4370, 370, 5147, 314, 3439, 267, 340, 3439, 26, 288, 340, 440, 291, 14, 1258, 63, 18639, 14, 2425, 63, 15795, 8, 5735, 304, 355, 746, 12062, 12983, 50, 2492, 8, 5735, 9, 267, 340, 291, 14, 17549, 63, 4736, 63, 513, 26, 288, 291, 14, 1258, 63, 18639, 14, 4712, 8, 277, 14, 17549, 63, 4736, 63, 493, 63, 513, 12, 291, 14, 888, 14, 51, 2078, 63, 30553, 8246, 63, 10926, 9, 267, 587, 26, 1779, 746, 15626, 14064, 7274, 6405, 83, 8, 277, 14, 888, 14, 362, 63, 17549, 12065, 63, 694, 1012, 267, 267, 327, 4155, 3238, 314, 16338, 1159, 1347, 4450, 314, 2013, 394, 11641, 14, 4960, 327, 961, 1104, 1630, 440, 4838, 370, 19427, 28166, 4960, 19427, 63, 22416, 275, 359, 8787, 14, 362, 63, 6271, 78, 342, 367, 15122, 315, 291, 14, 17549, 63, 4736, 63, 513, 61, 267, 340, 394, 11641, 436, 291, 14, 1258, 63, 8787, 14, 362, 63, 6271, 78, 342, 440, 315, 19427, 63, 22416, 26, 288, 1347, 63, 6271, 78, 275, 291, 14, 785, 63, 8787, 14, 362, 63, 6271, 78, 342, 288, 340, 440, 394, 11641, 508, 1347, 63, 6271, 78, 26, 355, 746, 8779, 547, 480, 4277, 394, 11641, 26, 450, 83, 3181, 1133, 1336, 2013, 394, 11641, 26, 450, 83, 298, 450, 971, 4318, 334, 1375, 63, 6271, 78, 12, 394, 11641, 9, 776, 27144, 372, 715, 339, 347, 1104, 63, 9201, 8, 277, 12, 12052, 304, 267, 408, 267, 2670, 340, 314, 11748, 84, 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 1, 1, 1, 1, 1, 1 ]
lexus24/40223224final
static/Brython3.1.1-20150328-091302/Lib/unittest/test/testmock/testmagicmethods.py
737
12145
import unittest import inspect import sys from unittest.mock import Mock, MagicMock, _magics class TestMockingMagicMethods(unittest.TestCase): def test_deleting_magic_methods(self): mock = Mock() self.assertFalse(hasattr(mock, '__getitem__')) mock.__getitem__ = Mock() self.assertTrue(hasattr(mock, '__getitem__')) del mock.__getitem__ self.assertFalse(hasattr(mock, '__getitem__')) def test_magicmock_del(self): mock = MagicMock() # before using getitem del mock.__getitem__ self.assertRaises(TypeError, lambda: mock['foo']) mock = MagicMock() # this time use it first mock['foo'] del mock.__getitem__ self.assertRaises(TypeError, lambda: mock['foo']) def test_magic_method_wrapping(self): mock = Mock() def f(self, name): return self, 'fish' mock.__getitem__ = f self.assertFalse(mock.__getitem__ is f) self.assertEqual(mock['foo'], (mock, 'fish')) self.assertEqual(mock.__getitem__('foo'), (mock, 'fish')) mock.__getitem__ = mock self.assertTrue(mock.__getitem__ is mock) def test_magic_methods_isolated_between_mocks(self): mock1 = Mock() mock2 = Mock() mock1.__iter__ = Mock(return_value=iter([])) self.assertEqual(list(mock1), []) self.assertRaises(TypeError, lambda: list(mock2)) def test_repr(self): mock = Mock() self.assertEqual(repr(mock), "<Mock id='%s'>" % id(mock)) mock.__repr__ = lambda s: 'foo' self.assertEqual(repr(mock), 'foo') def test_str(self): mock = Mock() self.assertEqual(str(mock), object.__str__(mock)) mock.__str__ = lambda s: 'foo' self.assertEqual(str(mock), 'foo') def test_dict_methods(self): mock = Mock() self.assertRaises(TypeError, lambda: mock['foo']) def _del(): del mock['foo'] def _set(): mock['foo'] = 3 self.assertRaises(TypeError, _del) self.assertRaises(TypeError, _set) _dict = {} def getitem(s, name): return _dict[name] def setitem(s, name, value): _dict[name] = value def delitem(s, name): del _dict[name] mock.__setitem__ = setitem mock.__getitem__ = getitem mock.__delitem__ = delitem self.assertRaises(KeyError, lambda: mock['foo']) mock['foo'] = 'bar' self.assertEqual(_dict, {'foo': 'bar'}) self.assertEqual(mock['foo'], 'bar') del mock['foo'] self.assertEqual(_dict, {}) def test_numeric(self): original = mock = Mock() mock.value = 0 self.assertRaises(TypeError, lambda: mock + 3) def add(self, other): mock.value += other return self mock.__add__ = add self.assertEqual(mock + 3, mock) self.assertEqual(mock.value, 3) del mock.__add__ def iadd(mock): mock += 3 self.assertRaises(TypeError, iadd, mock) mock.__iadd__ = add mock += 6 self.assertEqual(mock, original) self.assertEqual(mock.value, 9) self.assertRaises(TypeError, lambda: 3 + mock) mock.__radd__ = add self.assertEqual(7 + mock, mock) self.assertEqual(mock.value, 16) def test_hash(self): mock = Mock() # test delegation self.assertEqual(hash(mock), Mock.__hash__(mock)) def _hash(s): return 3 mock.__hash__ = _hash self.assertEqual(hash(mock), 3) def test_nonzero(self): m = Mock() self.assertTrue(bool(m)) m.__bool__ = lambda s: False self.assertFalse(bool(m)) def test_comparison(self): mock = Mock() def comp(s, o): return True mock.__lt__ = mock.__gt__ = mock.__le__ = mock.__ge__ = comp self. assertTrue(mock < 3) self. assertTrue(mock > 3) self. assertTrue(mock <= 3) self. assertTrue(mock >= 3) self.assertRaises(TypeError, lambda: MagicMock() < object()) self.assertRaises(TypeError, lambda: object() < MagicMock()) self.assertRaises(TypeError, lambda: MagicMock() < MagicMock()) self.assertRaises(TypeError, lambda: MagicMock() > object()) self.assertRaises(TypeError, lambda: object() > MagicMock()) self.assertRaises(TypeError, lambda: MagicMock() > MagicMock()) self.assertRaises(TypeError, lambda: MagicMock() <= object()) self.assertRaises(TypeError, lambda: object() <= MagicMock()) self.assertRaises(TypeError, lambda: MagicMock() <= MagicMock()) self.assertRaises(TypeError, lambda: MagicMock() >= object()) self.assertRaises(TypeError, lambda: object() >= MagicMock()) self.assertRaises(TypeError, lambda: MagicMock() >= MagicMock()) def test_equality(self): for mock in Mock(), MagicMock(): self.assertEqual(mock == mock, True) self.assertIsInstance(mock == mock, bool) self.assertEqual(mock != mock, False) self.assertIsInstance(mock != mock, bool) self.assertEqual(mock == object(), False) self.assertEqual(mock != object(), True) def eq(self, other): return other == 3 mock.__eq__ = eq self.assertTrue(mock == 3) self.assertFalse(mock == 4) def ne(self, other): return other == 3 mock.__ne__ = ne self.assertTrue(mock != 3) self.assertFalse(mock != 4) mock = MagicMock() mock.__eq__.return_value = True self.assertIsInstance(mock == 3, bool) self.assertEqual(mock == 3, True) mock.__ne__.return_value = False self.assertIsInstance(mock != 3, bool) self.assertEqual(mock != 3, False) def test_len_contains_iter(self): mock = Mock() self.assertRaises(TypeError, len, mock) self.assertRaises(TypeError, iter, mock) self.assertRaises(TypeError, lambda: 'foo' in mock) mock.__len__ = lambda s: 6 self.assertEqual(len(mock), 6) mock.__contains__ = lambda s, o: o == 3 self.assertTrue(3 in mock) self.assertFalse(6 in mock) mock.__iter__ = lambda s: iter('foobarbaz') self.assertEqual(list(mock), list('foobarbaz')) def test_magicmock(self): mock = MagicMock() mock.__iter__.return_value = iter([1, 2, 3]) self.assertEqual(list(mock), [1, 2, 3]) getattr(mock, '__bool__').return_value = False self.assertFalse(hasattr(mock, '__nonzero__')) self.assertFalse(bool(mock)) for entry in _magics: self.assertTrue(hasattr(mock, entry)) self.assertFalse(hasattr(mock, '__imaginery__')) def test_magic_mock_equality(self): mock = MagicMock() self.assertIsInstance(mock == object(), bool) self.assertIsInstance(mock != object(), bool) self.assertEqual(mock == object(), False) self.assertEqual(mock != object(), True) self.assertEqual(mock == mock, True) self.assertEqual(mock != mock, False) def test_magicmock_defaults(self): mock = MagicMock() self.assertEqual(int(mock), 1) self.assertEqual(complex(mock), 1j) self.assertEqual(float(mock), 1.0) self.assertNotIn(object(), mock) self.assertEqual(len(mock), 0) self.assertEqual(list(mock), []) self.assertEqual(hash(mock), object.__hash__(mock)) self.assertEqual(str(mock), object.__str__(mock)) self.assertTrue(bool(mock)) # in Python 3 oct and hex use __index__ # so these tests are for __index__ in py3k self.assertEqual(oct(mock), '0o1') self.assertEqual(hex(mock), '0x1') # how to test __sizeof__ ? def test_magic_methods_and_spec(self): class Iterable(object): def __iter__(self): pass mock = Mock(spec=Iterable) self.assertRaises(AttributeError, lambda: mock.__iter__) mock.__iter__ = Mock(return_value=iter([])) self.assertEqual(list(mock), []) class NonIterable(object): pass mock = Mock(spec=NonIterable) self.assertRaises(AttributeError, lambda: mock.__iter__) def set_int(): mock.__int__ = Mock(return_value=iter([])) self.assertRaises(AttributeError, set_int) mock = MagicMock(spec=Iterable) self.assertEqual(list(mock), []) self.assertRaises(AttributeError, set_int) def test_magic_methods_and_spec_set(self): class Iterable(object): def __iter__(self): pass mock = Mock(spec_set=Iterable) self.assertRaises(AttributeError, lambda: mock.__iter__) mock.__iter__ = Mock(return_value=iter([])) self.assertEqual(list(mock), []) class NonIterable(object): pass mock = Mock(spec_set=NonIterable) self.assertRaises(AttributeError, lambda: mock.__iter__) def set_int(): mock.__int__ = Mock(return_value=iter([])) self.assertRaises(AttributeError, set_int) mock = MagicMock(spec_set=Iterable) self.assertEqual(list(mock), []) self.assertRaises(AttributeError, set_int) def test_setting_unsupported_magic_method(self): mock = MagicMock() def set_setattr(): mock.__setattr__ = lambda self, name: None self.assertRaisesRegex(AttributeError, "Attempting to set unsupported magic method '__setattr__'.", set_setattr ) def test_attributes_and_return_value(self): mock = MagicMock() attr = mock.foo def _get_type(obj): # the type of every mock (or magicmock) is a custom subclass # so the real type is the second in the mro return type(obj).__mro__[1] self.assertEqual(_get_type(attr), MagicMock) returned = mock() self.assertEqual(_get_type(returned), MagicMock) def test_magic_methods_are_magic_mocks(self): mock = MagicMock() self.assertIsInstance(mock.__getitem__, MagicMock) mock[1][2].__getitem__.return_value = 3 self.assertEqual(mock[1][2][3], 3) def test_magic_method_reset_mock(self): mock = MagicMock() str(mock) self.assertTrue(mock.__str__.called) mock.reset_mock() self.assertFalse(mock.__str__.called) def test_dir(self): # overriding the default implementation for mock in Mock(), MagicMock(): def _dir(self): return ['foo'] mock.__dir__ = _dir self.assertEqual(dir(mock), ['foo']) @unittest.skipIf('PyPy' in sys.version, "This fails differently on pypy") def test_bound_methods(self): m = Mock() # XXXX should this be an expected failure instead? # this seems like it should work, but is hard to do without introducing # other api inconsistencies. Failure message could be better though. m.__iter__ = [3].__iter__ self.assertRaises(TypeError, iter, m) def test_magic_method_type(self): class Foo(MagicMock): pass foo = Foo() self.assertIsInstance(foo.__int__, Foo) def test_descriptor_from_class(self): m = MagicMock() type(m).__str__.return_value = 'foo' self.assertEqual(str(m), 'foo') def test_iterable_as_iter_return_value(self): m = MagicMock() m.__iter__.return_value = [1, 2, 3] self.assertEqual(list(m), [1, 2, 3]) self.assertEqual(list(m), [1, 2, 3]) m.__iter__.return_value = iter([4, 5, 6]) self.assertEqual(list(m), [4, 5, 6]) self.assertEqual(list(m), []) if __name__ == '__main__': unittest.main()
gpl-3.0
[ 646, 2882, 199, 646, 6485, 199, 646, 984, 199, 504, 2882, 14, 1805, 492, 4420, 12, 10079, 12, 485, 5615, 2932, 4388, 199, 533, 1379, 3346, 316, 45, 6573, 10385, 8, 2796, 14, 1746, 304, 339, 347, 511, 63, 7346, 1337, 63, 11523, 63, 2474, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 291, 14, 3334, 8, 11161, 8, 1805, 12, 2560, 6095, 363, 1333, 398, 1683, 855, 6095, 363, 275, 4420, 342, 267, 291, 14, 1815, 8, 11161, 8, 1805, 12, 2560, 6095, 363, 1333, 398, 2150, 1683, 855, 6095, 363, 267, 291, 14, 3334, 8, 11161, 8, 1805, 12, 2560, 6095, 363, 1333, 2378, 347, 511, 63, 11523, 1805, 63, 2264, 8, 277, 304, 267, 1683, 275, 10079, 342, 267, 327, 2544, 1808, 2312, 4484, 267, 2150, 1683, 855, 6095, 363, 267, 291, 14, 1855, 8, 4333, 12, 2400, 26, 1683, 459, 1421, 1105, 398, 1683, 275, 10079, 342, 267, 327, 642, 900, 675, 652, 1642, 267, 1683, 459, 1421, 418, 267, 2150, 1683, 855, 6095, 363, 267, 291, 14, 1855, 8, 4333, 12, 2400, 26, 1683, 459, 1421, 1105, 2378, 347, 511, 63, 11523, 63, 765, 63, 87, 15521, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 347, 289, 8, 277, 12, 536, 304, 288, 372, 291, 12, 283, 16056, 7, 398, 1683, 855, 6095, 363, 275, 289, 267, 291, 14, 3334, 8, 1805, 855, 6095, 363, 365, 289, 9, 267, 291, 14, 629, 8, 1805, 459, 1421, 995, 334, 1805, 12, 283, 16056, 1333, 267, 291, 14, 629, 8, 1805, 855, 6095, 19734, 1421, 659, 334, 1805, 12, 283, 16056, 1333, 398, 1683, 855, 6095, 363, 275, 1683, 267, 291, 14, 1815, 8, 1805, 855, 6095, 363, 365, 1683, 9, 2378, 347, 511, 63, 11523, 63, 2474, 63, 21748, 63, 13007, 63, 25191, 8, 277, 304, 267, 1683, 17, 275, 4420, 342, 267, 1683, 18, 275, 4420, 342, 398, 1683, 17, 855, 1661, 363, 275, 4420, 8, 1107, 63, 585, 29, 1661, 26064, 267, 291, 14, 629, 8, 513, 8, 1805, 17, 395, 3073, 267, 291, 14, 1855, 8, 4333, 12, 2400, 26, 769, 8, 1805, 18, 430, 2378, 347, 511, 63, 2722, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 291, 14, 629, 8, 2722, 8, 1805, 395, 3886, 3346, 1305, 9569, 83, 7, 4335, 450, 1305, 8, 1805, 430, 267, 1683, 855, 2722, 363, 275, 2400, 308, 26, 283, 1421, 7, 267, 291, 14, 629, 8, 2722, 8, 1805, 395, 283, 1421, 358, 2378, 347, 511, 63, 495, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 291, 14, 629, 8, 495, 8, 1805, 395, 909, 855, 495, 721, 1805, 430, 267, 1683, 855, 495, 363, 275, 2400, 308, 26, 283, 1421, 7, 267, 291, 14, 629, 8, 495, 8, 1805, 395, 283, 1421, 358, 2378, 347, 511, 63, 807, 63, 2474, 8, 277, 304, 267, 1683, 275, 4420, 342, 398, 291, 14, 1855, 8, 4333, 12, 2400, 26, 1683, 459, 1421, 1105, 267, 347, 485, 2264, 837, 288, 2150, 1683, 459, 1421, 418, 267, 347, 485, 409, 837, 288, 1683, 459, 1421, 418, 275, 650, 267, 291, 14, 1855, 8, 4333, 12, 485, 2264, 9, 267, 291, 14, 1855, 8, 4333, 12, 485, 409, 9, 398, 485, 807, 275, 1052, 267, 347, 2312, 4484, 8, 83, 12, 536, 304, 288, 372, 485, 807, 59, 354, 61, 267, 347, 542, 4484, 8, 83, 12, 536, 12, 574, 304, 288, 485, 807, 59, 354, 61, 275, 574, 267, 347, 9122, 563, 8, 83, 12, 536, 304, 288, 2150, 485, 807, 59, 354, 61, 398, 1683, 855, 8617, 363, 275, 542, 4484, 267, 1683, 855, 6095, 363, 275, 2312, 4484, 267, 1683, 855, 13228, 363, 275, 9122, 563, 398, 291, 14, 1855, 8, 10230, 12, 2400, 26, 1683, 459, 1421, 1105, 267, 1683, 459, 1421, 418, 275, 283, 1700, 7, 267, 291, 14, 629, 1547, 807, 12, 791, 1421, 356, 283, 1700, 3071, 267, 291, 14, 629, 8, 1805, 459, 1421, 995, 283, 1700, 358, 267, 2150, 1683, 459, 1421, 418, 267, 291, 14, 629, 1547, 807, 12, 5009, 2378, 347, 511, 63, 6677, 8, 277, 304, 267, 3379, 275, 1683, 275, 4420, 342, 267, 1683, 14, 585, 275, 378, 398, 291, 14, 1855, 8, 4333, 12, 2400, 26, 1683, 435, 650, 9, 398, 347, 1050, 8, 277, 12, 1163, 304, 288, 1683, 14, 585, 847, 1163, 288, 372, 291, 267, 1683, 855, 525, 363, 275, 1050, 267, 291, 14, 629, 8, 1805, 435, 650, 12, 1683, 9, 267, 291, 14, 629, 8, 1805, 14, 585, 12, 650, 9, 398, 2150, 1683, 855, 525, 363, 267, 347, 284, 525, 8, 1805, 304, 288, 1683, 847, 650, 267, 291, 14, 1855, 8, 4333, 12, 284, 525, 12, 1683, 9, 267, 1683, 855, 28788, 363, 275, 1050, 267, 1683, 847, 1227, 267, 291, 14, 629, 8, 1805, 12, 3379, 9, 267, 291, 14, 629, 8, 1805, 14, 585, 12, 1749, 9, 398, 291, 14, 1855, 8, 4333, 12, 2400, 26, 650, 435, 1683, 9, 267, 1683, 855, 22958, 363, 275, 1050, 267, 291, 14, 629, 8, 23, 435, 1683, 12, 1683, 9, 267, 291, 14, 629, 8, 1805, 14, 585, 12, 3193, 9, 2378, 347, 511, 63, 2227, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 327, 511, 18703, 425, 267, 291, 14, 629, 8, 2227, 8, 1805, 395, 4420, 855, 2227, 721, 1805, 430, 398, 347, 485, 2227, 8, 83, 304, 288, 372, 650, 267, 1683, 855, 2227, 363, 275, 485, 2227, 267, 291, 14, 629, 8, 2227, 8, 1805, 395, 650, 9, 2378, 347, 511, 63, 10262, 8, 277, 304, 267, 333, 275, 4420, 342, 267, 291, 14, 1815, 8, 2245, 8, 77, 430, 398, 333, 855, 2245, 363, 275, 2400, 308, 26, 756, 267, 291, 14, 3334, 8, 2245, 8, 77, 430, 2378, 347, 511, 63, 8547, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 347, 1013, 8, 83, 12, 312, 304, 288, 372, 715, 267, 1683, 855, 4116, 363, 275, 1683, 855, 3308, 363, 275, 1683, 855, 274, 363, 275, 1683, 855, 303, 363, 275, 1013, 267, 291, 14, 702, 549, 8, 1805, 665, 650, 9, 267, 291, 14, 702, 549, 8, 1805 ]
[ 2882, 199, 646, 6485, 199, 646, 984, 199, 504, 2882, 14, 1805, 492, 4420, 12, 10079, 12, 485, 5615, 2932, 4388, 199, 533, 1379, 3346, 316, 45, 6573, 10385, 8, 2796, 14, 1746, 304, 339, 347, 511, 63, 7346, 1337, 63, 11523, 63, 2474, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 291, 14, 3334, 8, 11161, 8, 1805, 12, 2560, 6095, 363, 1333, 398, 1683, 855, 6095, 363, 275, 4420, 342, 267, 291, 14, 1815, 8, 11161, 8, 1805, 12, 2560, 6095, 363, 1333, 398, 2150, 1683, 855, 6095, 363, 267, 291, 14, 3334, 8, 11161, 8, 1805, 12, 2560, 6095, 363, 1333, 2378, 347, 511, 63, 11523, 1805, 63, 2264, 8, 277, 304, 267, 1683, 275, 10079, 342, 267, 327, 2544, 1808, 2312, 4484, 267, 2150, 1683, 855, 6095, 363, 267, 291, 14, 1855, 8, 4333, 12, 2400, 26, 1683, 459, 1421, 1105, 398, 1683, 275, 10079, 342, 267, 327, 642, 900, 675, 652, 1642, 267, 1683, 459, 1421, 418, 267, 2150, 1683, 855, 6095, 363, 267, 291, 14, 1855, 8, 4333, 12, 2400, 26, 1683, 459, 1421, 1105, 2378, 347, 511, 63, 11523, 63, 765, 63, 87, 15521, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 347, 289, 8, 277, 12, 536, 304, 288, 372, 291, 12, 283, 16056, 7, 398, 1683, 855, 6095, 363, 275, 289, 267, 291, 14, 3334, 8, 1805, 855, 6095, 363, 365, 289, 9, 267, 291, 14, 629, 8, 1805, 459, 1421, 995, 334, 1805, 12, 283, 16056, 1333, 267, 291, 14, 629, 8, 1805, 855, 6095, 19734, 1421, 659, 334, 1805, 12, 283, 16056, 1333, 398, 1683, 855, 6095, 363, 275, 1683, 267, 291, 14, 1815, 8, 1805, 855, 6095, 363, 365, 1683, 9, 2378, 347, 511, 63, 11523, 63, 2474, 63, 21748, 63, 13007, 63, 25191, 8, 277, 304, 267, 1683, 17, 275, 4420, 342, 267, 1683, 18, 275, 4420, 342, 398, 1683, 17, 855, 1661, 363, 275, 4420, 8, 1107, 63, 585, 29, 1661, 26064, 267, 291, 14, 629, 8, 513, 8, 1805, 17, 395, 3073, 267, 291, 14, 1855, 8, 4333, 12, 2400, 26, 769, 8, 1805, 18, 430, 2378, 347, 511, 63, 2722, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 291, 14, 629, 8, 2722, 8, 1805, 395, 3886, 3346, 1305, 9569, 83, 7, 4335, 450, 1305, 8, 1805, 430, 267, 1683, 855, 2722, 363, 275, 2400, 308, 26, 283, 1421, 7, 267, 291, 14, 629, 8, 2722, 8, 1805, 395, 283, 1421, 358, 2378, 347, 511, 63, 495, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 291, 14, 629, 8, 495, 8, 1805, 395, 909, 855, 495, 721, 1805, 430, 267, 1683, 855, 495, 363, 275, 2400, 308, 26, 283, 1421, 7, 267, 291, 14, 629, 8, 495, 8, 1805, 395, 283, 1421, 358, 2378, 347, 511, 63, 807, 63, 2474, 8, 277, 304, 267, 1683, 275, 4420, 342, 398, 291, 14, 1855, 8, 4333, 12, 2400, 26, 1683, 459, 1421, 1105, 267, 347, 485, 2264, 837, 288, 2150, 1683, 459, 1421, 418, 267, 347, 485, 409, 837, 288, 1683, 459, 1421, 418, 275, 650, 267, 291, 14, 1855, 8, 4333, 12, 485, 2264, 9, 267, 291, 14, 1855, 8, 4333, 12, 485, 409, 9, 398, 485, 807, 275, 1052, 267, 347, 2312, 4484, 8, 83, 12, 536, 304, 288, 372, 485, 807, 59, 354, 61, 267, 347, 542, 4484, 8, 83, 12, 536, 12, 574, 304, 288, 485, 807, 59, 354, 61, 275, 574, 267, 347, 9122, 563, 8, 83, 12, 536, 304, 288, 2150, 485, 807, 59, 354, 61, 398, 1683, 855, 8617, 363, 275, 542, 4484, 267, 1683, 855, 6095, 363, 275, 2312, 4484, 267, 1683, 855, 13228, 363, 275, 9122, 563, 398, 291, 14, 1855, 8, 10230, 12, 2400, 26, 1683, 459, 1421, 1105, 267, 1683, 459, 1421, 418, 275, 283, 1700, 7, 267, 291, 14, 629, 1547, 807, 12, 791, 1421, 356, 283, 1700, 3071, 267, 291, 14, 629, 8, 1805, 459, 1421, 995, 283, 1700, 358, 267, 2150, 1683, 459, 1421, 418, 267, 291, 14, 629, 1547, 807, 12, 5009, 2378, 347, 511, 63, 6677, 8, 277, 304, 267, 3379, 275, 1683, 275, 4420, 342, 267, 1683, 14, 585, 275, 378, 398, 291, 14, 1855, 8, 4333, 12, 2400, 26, 1683, 435, 650, 9, 398, 347, 1050, 8, 277, 12, 1163, 304, 288, 1683, 14, 585, 847, 1163, 288, 372, 291, 267, 1683, 855, 525, 363, 275, 1050, 267, 291, 14, 629, 8, 1805, 435, 650, 12, 1683, 9, 267, 291, 14, 629, 8, 1805, 14, 585, 12, 650, 9, 398, 2150, 1683, 855, 525, 363, 267, 347, 284, 525, 8, 1805, 304, 288, 1683, 847, 650, 267, 291, 14, 1855, 8, 4333, 12, 284, 525, 12, 1683, 9, 267, 1683, 855, 28788, 363, 275, 1050, 267, 1683, 847, 1227, 267, 291, 14, 629, 8, 1805, 12, 3379, 9, 267, 291, 14, 629, 8, 1805, 14, 585, 12, 1749, 9, 398, 291, 14, 1855, 8, 4333, 12, 2400, 26, 650, 435, 1683, 9, 267, 1683, 855, 22958, 363, 275, 1050, 267, 291, 14, 629, 8, 23, 435, 1683, 12, 1683, 9, 267, 291, 14, 629, 8, 1805, 14, 585, 12, 3193, 9, 2378, 347, 511, 63, 2227, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 327, 511, 18703, 425, 267, 291, 14, 629, 8, 2227, 8, 1805, 395, 4420, 855, 2227, 721, 1805, 430, 398, 347, 485, 2227, 8, 83, 304, 288, 372, 650, 267, 1683, 855, 2227, 363, 275, 485, 2227, 267, 291, 14, 629, 8, 2227, 8, 1805, 395, 650, 9, 2378, 347, 511, 63, 10262, 8, 277, 304, 267, 333, 275, 4420, 342, 267, 291, 14, 1815, 8, 2245, 8, 77, 430, 398, 333, 855, 2245, 363, 275, 2400, 308, 26, 756, 267, 291, 14, 3334, 8, 2245, 8, 77, 430, 2378, 347, 511, 63, 8547, 8, 277, 304, 267, 1683, 275, 4420, 342, 267, 347, 1013, 8, 83, 12, 312, 304, 288, 372, 715, 267, 1683, 855, 4116, 363, 275, 1683, 855, 3308, 363, 275, 1683, 855, 274, 363, 275, 1683, 855, 303, 363, 275, 1013, 267, 291, 14, 702, 549, 8, 1805, 665, 650, 9, 267, 291, 14, 702, 549, 8, 1805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 1, 1, 1 ]
qpython-android/QPypi-numpy
numpy/lib/tests/test__iotools.py
4
6114
import StringIO import numpy as np from numpy.lib._iotools import LineSplitter, NameValidator, StringConverter,\ has_nested_fields from numpy.testing import * class TestLineSplitter(TestCase): "Tests the LineSplitter class." # def test_no_delimiter(self): "Test LineSplitter w/o delimiter" strg = " 1 2 3 4 5 # test" test = LineSplitter()(strg) assert_equal(test, ['1', '2', '3', '4', '5']) test = LineSplitter('')(strg) assert_equal(test, ['1', '2', '3', '4', '5']) def test_space_delimiter(self): "Test space delimiter" strg = " 1 2 3 4 5 # test" test = LineSplitter(' ')(strg) assert_equal(test, ['1', '2', '3', '4', '', '5']) test = LineSplitter(' ')(strg) assert_equal(test, ['1 2 3 4', '5']) def test_tab_delimiter(self): "Test tab delimiter" strg= " 1\t 2\t 3\t 4\t 5 6" test = LineSplitter('\t')(strg) assert_equal(test, ['1', '2', '3', '4', '5 6']) strg= " 1 2\t 3 4\t 5 6" test = LineSplitter('\t')(strg) assert_equal(test, ['1 2', '3 4', '5 6']) def test_other_delimiter(self): "Test LineSplitter on delimiter" strg = "1,2,3,4,,5" test = LineSplitter(',')(strg) assert_equal(test, ['1', '2', '3', '4', '', '5']) # strg = " 1,2,3,4,,5 # test" test = LineSplitter(',')(strg) assert_equal(test, ['1', '2', '3', '4', '', '5']) def test_constant_fixed_width(self): "Test LineSplitter w/ fixed-width fields" strg = " 1 2 3 4 5 # test" test = LineSplitter(3)(strg) assert_equal(test, ['1', '2', '3', '4', '', '5', '']) # strg = " 1 3 4 5 6# test" test = LineSplitter(20)(strg) assert_equal(test, ['1 3 4 5 6']) # strg = " 1 3 4 5 6# test" test = LineSplitter(30)(strg) assert_equal(test, ['1 3 4 5 6']) def test_variable_fixed_width(self): strg = " 1 3 4 5 6# test" test = LineSplitter((3,6,6,3))(strg) assert_equal(test, ['1', '3', '4 5', '6']) # strg = " 1 3 4 5 6# test" test = LineSplitter((6,6,9))(strg) assert_equal(test, ['1', '3 4', '5 6']) #------------------------------------------------------------------------------- class TestNameValidator(TestCase): # def test_case_sensitivity(self): "Test case sensitivity" names = ['A', 'a', 'b', 'c'] test = NameValidator().validate(names) assert_equal(test, ['A', 'a', 'b', 'c']) test = NameValidator(case_sensitive=False).validate(names) assert_equal(test, ['A', 'A_1', 'B', 'C']) test = NameValidator(case_sensitive='upper').validate(names) assert_equal(test, ['A', 'A_1', 'B', 'C']) test = NameValidator(case_sensitive='lower').validate(names) assert_equal(test, ['a', 'a_1', 'b', 'c']) # def test_excludelist(self): "Test excludelist" names = ['dates', 'data', 'Other Data', 'mask'] validator = NameValidator(excludelist = ['dates', 'data', 'mask']) test = validator.validate(names) assert_equal(test, ['dates_', 'data_', 'Other_Data', 'mask_']) #------------------------------------------------------------------------------- class TestStringConverter(TestCase): "Test StringConverter" # def test_creation(self): "Test creation of a StringConverter" converter = StringConverter(int, -99999) assert_equal(converter._status, 1) assert_equal(converter.default, -99999) # def test_upgrade(self): "Tests the upgrade method." converter = StringConverter() assert_equal(converter._status, 0) converter.upgrade('0') assert_equal(converter._status, 1) converter.upgrade('0.') assert_equal(converter._status, 2) converter.upgrade('0j') assert_equal(converter._status, 3) converter.upgrade('a') assert_equal(converter._status, len(converter._mapper)-1) # def test_missing(self): "Tests the use of missing values." converter = StringConverter(missing_values=('missing','missed')) converter.upgrade('0') assert_equal(converter('0'), 0) assert_equal(converter(''), converter.default) assert_equal(converter('missing'), converter.default) assert_equal(converter('missed'), converter.default) try: converter('miss') except ValueError: pass # def test_upgrademapper(self): "Tests updatemapper" from datetime import date import time dateparser = lambda s : date(*time.strptime(s, "%Y-%m-%d")[:3]) StringConverter.upgrade_mapper(dateparser, date(2000,1,1)) convert = StringConverter(dateparser, date(2000, 1, 1)) test = convert('2001-01-01') assert_equal(test, date(2001, 01, 01)) test = convert('2009-01-01') assert_equal(test, date(2009, 01, 01)) test = convert('') assert_equal(test, date(2000, 01, 01)) # def test_string_to_object(self): "Make sure that string-to-object functions are properly recognized" from datetime import date import time conv = StringConverter(lambda s: date(*(time.strptime(s)[:3]))) assert_equal(conv._mapper[-2][0](0), 0j) assert(hasattr(conv, 'default')) #------------------------------------------------------------------------------- class TestMiscFunctions(TestCase): # def test_has_nested_dtype(self): "Test has_nested_dtype" ndtype = np.dtype(np.float) assert_equal(has_nested_fields(ndtype), False) ndtype = np.dtype([('A', '|S3'), ('B', float)]) assert_equal(has_nested_fields(ndtype), False) ndtype = np.dtype([('A', int), ('B', [('BA', float), ('BB', '|S1')])]) assert_equal(has_nested_fields(ndtype), True)
bsd-3-clause
[ 199, 646, 5228, 199, 199, 646, 2680, 465, 980, 199, 504, 2680, 14, 773, 423, 73, 3459, 1446, 492, 7030, 26407, 12, 2812, 8640, 12, 2624, 11907, 4202, 3044, 965, 63, 6376, 63, 955, 199, 504, 2680, 14, 4776, 492, 627, 199, 199, 533, 1379, 3049, 26407, 8, 1746, 304, 272, 298, 2925, 314, 7030, 26407, 1021, 2122, 272, 327, 272, 347, 511, 63, 889, 63, 15104, 8, 277, 304, 267, 298, 774, 7030, 26407, 336, 15, 79, 11172, 2, 267, 620, 71, 275, 298, 413, 499, 650, 841, 221, 959, 327, 511, 2, 267, 511, 275, 7030, 26407, 24851, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 283, 21, 1105, 267, 511, 275, 7030, 26407, 360, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 283, 21, 1105, 339, 347, 511, 63, 2638, 63, 15104, 8, 277, 304, 267, 298, 774, 4601, 11172, 2, 267, 620, 71, 275, 298, 413, 499, 650, 841, 221, 959, 327, 511, 2, 267, 511, 275, 7030, 26407, 360, 283, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 3260, 283, 21, 1105, 267, 511, 275, 7030, 26407, 360, 221, 283, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 499, 650, 841, 297, 283, 21, 1105, 339, 347, 511, 63, 2902, 63, 15104, 8, 277, 304, 267, 298, 774, 5174, 11172, 2, 267, 620, 71, 29, 298, 413, 60, 84, 499, 60, 84, 650, 60, 84, 841, 60, 84, 959, 221, 1227, 2, 267, 511, 275, 7030, 26407, 2258, 84, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 283, 21, 221, 1227, 1105, 267, 620, 71, 29, 298, 413, 221, 499, 60, 84, 650, 221, 841, 60, 84, 959, 221, 1227, 2, 267, 511, 275, 7030, 26407, 2258, 84, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 221, 499, 297, 283, 19, 221, 841, 297, 283, 21, 221, 1227, 1105, 339, 347, 511, 63, 1848, 63, 15104, 8, 277, 304, 267, 298, 774, 7030, 26407, 641, 11172, 2, 267, 620, 71, 275, 298, 17, 12, 18, 12, 19, 12, 20, 10573, 21, 2, 267, 511, 275, 7030, 26407, 5102, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 3260, 283, 21, 1105, 267, 327, 267, 620, 71, 275, 298, 413, 12, 18, 12, 19, 12, 20, 10573, 21, 327, 511, 2, 267, 511, 275, 7030, 26407, 5102, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 3260, 283, 21, 1105, 339, 347, 511, 63, 4083, 63, 5964, 63, 2063, 8, 277, 304, 267, 298, 774, 7030, 26407, 336, 15, 6317, 13, 2063, 1504, 2, 267, 620, 71, 275, 298, 221, 413, 221, 499, 221, 650, 221, 841, 258, 959, 257, 327, 511, 2, 267, 511, 275, 7030, 26407, 8, 19, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 3260, 283, 21, 297, 283, 1105, 267, 327, 267, 620, 71, 275, 298, 221, 413, 258, 650, 221, 841, 221, 959, 221, 1227, 3, 511, 2, 267, 511, 275, 7030, 26407, 8, 1165, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 258, 650, 221, 841, 221, 959, 221, 1227, 1105, 267, 327, 267, 620, 71, 275, 298, 221, 413, 258, 650, 221, 841, 221, 959, 221, 1227, 3, 511, 2, 267, 511, 275, 7030, 26407, 8, 1216, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 258, 650, 221, 841, 221, 959, 221, 1227, 1105, 339, 347, 511, 63, 1975, 63, 5964, 63, 2063, 8, 277, 304, 267, 620, 71, 275, 298, 221, 413, 258, 650, 221, 841, 221, 959, 221, 1227, 3, 511, 2, 267, 511, 275, 7030, 26407, 1332, 19, 12, 22, 12, 22, 12, 19, 430, 8, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 19, 297, 283, 20, 221, 959, 297, 283, 22, 1105, 267, 327, 267, 620, 71, 275, 298, 221, 413, 258, 650, 221, 841, 221, 959, 221, 1227, 3, 511, 2, 267, 511, 275, 7030, 26407, 1332, 22, 12, 22, 12, 25, 430, 8, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 19, 221, 841, 297, 283, 21, 221, 1227, 1105, 421, 199, 7656, 18964, 199, 199, 533, 1379, 985, 8640, 8, 1746, 304, 272, 327, 272, 347, 511, 63, 2546, 63, 2464, 20635, 8, 277, 304, 267, 298, 774, 1930, 4334, 20635, 2, 267, 1561, 275, 788, 33, 297, 283, 65, 297, 283, 66, 297, 283, 67, 418, 267, 511, 275, 2812, 8640, 1252, 3502, 8, 1247, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 33, 297, 283, 65, 297, 283, 66, 297, 283, 67, 1105, 267, 511, 275, 2812, 8640, 8, 2546, 63, 7361, 29, 797, 680, 3502, 8, 1247, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 33, 297, 283, 33, 63, 17, 297, 283, 34, 297, 283, 35, 1105, 267, 511, 275, 2812, 8640, 8, 2546, 63, 7361, 534, 4142, 1959, 3502, 8, 1247, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 33, 297, 283, 33, 63, 17, 297, 283, 34, 297, 283, 35, 1105, 267, 511, 275, 2812, 8640, 8, 2546, 63, 7361, 534, 2325, 1959, 3502, 8, 1247, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 65, 297, 283, 65, 63, 17, 297, 283, 66, 297, 283, 67, 1105, 272, 327, 272, 347, 511, 63, 5473, 513, 8, 277, 304, 267, 298, 774, 5760, 513, 2, 267, 1561, 275, 788, 9356, 297, 283, 576, 297, 283, 8632, 3918, 297, 283, 2629, 418, 267, 11822, 275, 2812, 8640, 8, 5473, 513, 275, 788 ]
[ 646, 5228, 199, 199, 646, 2680, 465, 980, 199, 504, 2680, 14, 773, 423, 73, 3459, 1446, 492, 7030, 26407, 12, 2812, 8640, 12, 2624, 11907, 4202, 3044, 965, 63, 6376, 63, 955, 199, 504, 2680, 14, 4776, 492, 627, 199, 199, 533, 1379, 3049, 26407, 8, 1746, 304, 272, 298, 2925, 314, 7030, 26407, 1021, 2122, 272, 327, 272, 347, 511, 63, 889, 63, 15104, 8, 277, 304, 267, 298, 774, 7030, 26407, 336, 15, 79, 11172, 2, 267, 620, 71, 275, 298, 413, 499, 650, 841, 221, 959, 327, 511, 2, 267, 511, 275, 7030, 26407, 24851, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 283, 21, 1105, 267, 511, 275, 7030, 26407, 360, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 283, 21, 1105, 339, 347, 511, 63, 2638, 63, 15104, 8, 277, 304, 267, 298, 774, 4601, 11172, 2, 267, 620, 71, 275, 298, 413, 499, 650, 841, 221, 959, 327, 511, 2, 267, 511, 275, 7030, 26407, 360, 283, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 3260, 283, 21, 1105, 267, 511, 275, 7030, 26407, 360, 221, 283, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 499, 650, 841, 297, 283, 21, 1105, 339, 347, 511, 63, 2902, 63, 15104, 8, 277, 304, 267, 298, 774, 5174, 11172, 2, 267, 620, 71, 29, 298, 413, 60, 84, 499, 60, 84, 650, 60, 84, 841, 60, 84, 959, 221, 1227, 2, 267, 511, 275, 7030, 26407, 2258, 84, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 283, 21, 221, 1227, 1105, 267, 620, 71, 29, 298, 413, 221, 499, 60, 84, 650, 221, 841, 60, 84, 959, 221, 1227, 2, 267, 511, 275, 7030, 26407, 2258, 84, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 221, 499, 297, 283, 19, 221, 841, 297, 283, 21, 221, 1227, 1105, 339, 347, 511, 63, 1848, 63, 15104, 8, 277, 304, 267, 298, 774, 7030, 26407, 641, 11172, 2, 267, 620, 71, 275, 298, 17, 12, 18, 12, 19, 12, 20, 10573, 21, 2, 267, 511, 275, 7030, 26407, 5102, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 3260, 283, 21, 1105, 267, 327, 267, 620, 71, 275, 298, 413, 12, 18, 12, 19, 12, 20, 10573, 21, 327, 511, 2, 267, 511, 275, 7030, 26407, 5102, 7533, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 3260, 283, 21, 1105, 339, 347, 511, 63, 4083, 63, 5964, 63, 2063, 8, 277, 304, 267, 298, 774, 7030, 26407, 336, 15, 6317, 13, 2063, 1504, 2, 267, 620, 71, 275, 298, 221, 413, 221, 499, 221, 650, 221, 841, 258, 959, 257, 327, 511, 2, 267, 511, 275, 7030, 26407, 8, 19, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 18, 297, 283, 19, 297, 283, 20, 297, 3260, 283, 21, 297, 283, 1105, 267, 327, 267, 620, 71, 275, 298, 221, 413, 258, 650, 221, 841, 221, 959, 221, 1227, 3, 511, 2, 267, 511, 275, 7030, 26407, 8, 1165, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 258, 650, 221, 841, 221, 959, 221, 1227, 1105, 267, 327, 267, 620, 71, 275, 298, 221, 413, 258, 650, 221, 841, 221, 959, 221, 1227, 3, 511, 2, 267, 511, 275, 7030, 26407, 8, 1216, 5130, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 258, 650, 221, 841, 221, 959, 221, 1227, 1105, 339, 347, 511, 63, 1975, 63, 5964, 63, 2063, 8, 277, 304, 267, 620, 71, 275, 298, 221, 413, 258, 650, 221, 841, 221, 959, 221, 1227, 3, 511, 2, 267, 511, 275, 7030, 26407, 1332, 19, 12, 22, 12, 22, 12, 19, 430, 8, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 19, 297, 283, 20, 221, 959, 297, 283, 22, 1105, 267, 327, 267, 620, 71, 275, 298, 221, 413, 258, 650, 221, 841, 221, 959, 221, 1227, 3, 511, 2, 267, 511, 275, 7030, 26407, 1332, 22, 12, 22, 12, 25, 430, 8, 495, 71, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 17, 297, 283, 19, 221, 841, 297, 283, 21, 221, 1227, 1105, 421, 199, 7656, 18964, 199, 199, 533, 1379, 985, 8640, 8, 1746, 304, 272, 327, 272, 347, 511, 63, 2546, 63, 2464, 20635, 8, 277, 304, 267, 298, 774, 1930, 4334, 20635, 2, 267, 1561, 275, 788, 33, 297, 283, 65, 297, 283, 66, 297, 283, 67, 418, 267, 511, 275, 2812, 8640, 1252, 3502, 8, 1247, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 33, 297, 283, 65, 297, 283, 66, 297, 283, 67, 1105, 267, 511, 275, 2812, 8640, 8, 2546, 63, 7361, 29, 797, 680, 3502, 8, 1247, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 33, 297, 283, 33, 63, 17, 297, 283, 34, 297, 283, 35, 1105, 267, 511, 275, 2812, 8640, 8, 2546, 63, 7361, 534, 4142, 1959, 3502, 8, 1247, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 33, 297, 283, 33, 63, 17, 297, 283, 34, 297, 283, 35, 1105, 267, 511, 275, 2812, 8640, 8, 2546, 63, 7361, 534, 2325, 1959, 3502, 8, 1247, 9, 267, 702, 63, 1452, 8, 396, 12, 788, 65, 297, 283, 65, 63, 17, 297, 283, 66, 297, 283, 67, 1105, 272, 327, 272, 347, 511, 63, 5473, 513, 8, 277, 304, 267, 298, 774, 5760, 513, 2, 267, 1561, 275, 788, 9356, 297, 283, 576, 297, 283, 8632, 3918, 297, 283, 2629, 418, 267, 11822, 275, 2812, 8640, 8, 5473, 513, 275, 788, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Stolas/vim-exploit
plugin/templates/python_file.py
1
1431
#!/usr/bin/env python # $$COPYRIGHT$$ # Author: $$AUTHOR$$ from struct import pack, unpack from subprocess import call ### The Exploit buff = "AAAA" buff += "\x42\x42\x42\x42" buff += pack("<L", 0x43434343) # exploit += $$SHELLCODE$$ ## The delivery script def exploit(filename, binary, shellcode=None): if shellcode: pass # TODO: Set / Replace the shellcode in the exploit print("[+] Writing file: %s" % filename) fd = open(filename, "w") print("[+] Writing %d bytes" % len(buff)) fd.write(buff) fd.close() print("[+] File Closed") if binary: print("[+] Launching Target.") try: call([binary, filename]) except OSError as ex: print("[!] Failed to call %s." % target) print("[+] Exploit Done.") if __name__ == '__main__': import argparse parser = argparse.ArgumentParser() parser.add_argument('--no-banner', action='store_false') parser.add_argument('-f', '--filename', action='store', default='exploit.bin') parser.add_argument('-b', '--bin', '--binary', action='store') parser.add_argument('-s', '--shellcode', action='store') args = parser.parse_args() if args.no_banner: print("$$BANNER$$") shellcode = None if args.shellcode: fd = open(args.shellcode, 'r') shellcode = fd.read() fd.close() exploit(args.filename, args.bin, shellcode)
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 2672, 4, 32324, 5716, 23174, 199, 3, 6529, 26, 2672, 4, 27938, 23174, 199, 199, 504, 2702, 492, 1706, 12, 7787, 199, 504, 3873, 492, 1240, 199, 199, 5680, 710, 7910, 320, 390, 199, 16830, 275, 298, 6151, 2, 199, 16830, 847, 1867, 88, 2260, 60, 88, 2260, 60, 88, 2260, 60, 88, 2260, 2, 199, 16830, 847, 1706, 6757, 44, 401, 378, 88, 26274, 1082, 14761, 9, 199, 3, 15868, 390, 847, 2672, 4, 29085, 6012, 23174, 421, 199, 309, 710, 18719, 2884, 199, 318, 15868, 390, 8, 1501, 12, 3366, 12, 5218, 600, 29, 403, 304, 339, 340, 5218, 600, 26, 267, 986, 267, 327, 3254, 26, 2494, 1182, 14402, 314, 5218, 600, 315, 314, 15868, 390, 339, 870, 10994, 11, 61, 12859, 1337, 570, 26, 450, 83, 2, 450, 1788, 9, 272, 6111, 275, 1551, 8, 1501, 12, 298, 87, 531, 272, 870, 10994, 11, 61, 12859, 1337, 450, 68, 2783, 2, 450, 822, 8, 16830, 430, 272, 6111, 14, 952, 8, 16830, 9, 272, 6111, 14, 1600, 342, 272, 870, 10994, 11, 61, 3814, 5980, 939, 531, 339, 340, 3366, 26, 267, 870, 10994, 11, 61, 23615, 316, 10256, 2685, 267, 862, 26, 288, 1240, 779, 3008, 12, 1788, 566, 267, 871, 6440, 465, 444, 26, 288, 870, 10994, 1, 61, 16277, 370, 1240, 450, 83, 2122, 450, 1347, 9, 267, 870, 10994, 11, 61, 7910, 320, 390, 23541, 2685, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 492, 7534, 272, 1798, 275, 7534, 14, 10730, 342, 272, 1798, 14, 525, 63, 2094, 4517, 889, 13, 13066, 297, 1595, 534, 1617, 63, 3910, 358, 272, 1798, 14, 525, 63, 2094, 3654, 70, 297, 2850, 1501, 297, 1595, 534, 1617, 297, 849, 534, 16971, 390, 14, 1393, 358, 272, 1798, 14, 525, 63, 2094, 3654, 66, 297, 2850, 1393, 297, 2850, 3008, 297, 1595, 534, 1617, 358, 272, 1798, 14, 525, 63, 2094, 3654, 83, 297, 2850, 31973, 297, 1595, 534, 1617, 358, 272, 1249, 275, 1798, 14, 1122, 63, 589, 342, 339, 340, 1249, 14, 889, 63, 13066, 26, 267, 870, 21506, 4, 34, 879, 15215, 4, 22550, 339, 5218, 600, 275, 488, 272, 340, 1249, 14, 31973, 26, 267, 6111, 275, 1551, 8, 589, 14, 31973, 12, 283, 82, 358, 267, 5218, 600, 275, 6111, 14, 739, 342, 267, 6111, 14, 1600, 342, 339, 15868, 390, 8, 589, 14, 1501, 12, 1249, 14, 1393, 12, 5218, 600, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 2672, 4, 32324, 5716, 23174, 199, 3, 6529, 26, 2672, 4, 27938, 23174, 199, 199, 504, 2702, 492, 1706, 12, 7787, 199, 504, 3873, 492, 1240, 199, 199, 5680, 710, 7910, 320, 390, 199, 16830, 275, 298, 6151, 2, 199, 16830, 847, 1867, 88, 2260, 60, 88, 2260, 60, 88, 2260, 60, 88, 2260, 2, 199, 16830, 847, 1706, 6757, 44, 401, 378, 88, 26274, 1082, 14761, 9, 199, 3, 15868, 390, 847, 2672, 4, 29085, 6012, 23174, 421, 199, 309, 710, 18719, 2884, 199, 318, 15868, 390, 8, 1501, 12, 3366, 12, 5218, 600, 29, 403, 304, 339, 340, 5218, 600, 26, 267, 986, 267, 327, 3254, 26, 2494, 1182, 14402, 314, 5218, 600, 315, 314, 15868, 390, 339, 870, 10994, 11, 61, 12859, 1337, 570, 26, 450, 83, 2, 450, 1788, 9, 272, 6111, 275, 1551, 8, 1501, 12, 298, 87, 531, 272, 870, 10994, 11, 61, 12859, 1337, 450, 68, 2783, 2, 450, 822, 8, 16830, 430, 272, 6111, 14, 952, 8, 16830, 9, 272, 6111, 14, 1600, 342, 272, 870, 10994, 11, 61, 3814, 5980, 939, 531, 339, 340, 3366, 26, 267, 870, 10994, 11, 61, 23615, 316, 10256, 2685, 267, 862, 26, 288, 1240, 779, 3008, 12, 1788, 566, 267, 871, 6440, 465, 444, 26, 288, 870, 10994, 1, 61, 16277, 370, 1240, 450, 83, 2122, 450, 1347, 9, 267, 870, 10994, 11, 61, 7910, 320, 390, 23541, 2685, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 492, 7534, 272, 1798, 275, 7534, 14, 10730, 342, 272, 1798, 14, 525, 63, 2094, 4517, 889, 13, 13066, 297, 1595, 534, 1617, 63, 3910, 358, 272, 1798, 14, 525, 63, 2094, 3654, 70, 297, 2850, 1501, 297, 1595, 534, 1617, 297, 849, 534, 16971, 390, 14, 1393, 358, 272, 1798, 14, 525, 63, 2094, 3654, 66, 297, 2850, 1393, 297, 2850, 3008, 297, 1595, 534, 1617, 358, 272, 1798, 14, 525, 63, 2094, 3654, 83, 297, 2850, 31973, 297, 1595, 534, 1617, 358, 272, 1249, 275, 1798, 14, 1122, 63, 589, 342, 339, 340, 1249, 14, 889, 63, 13066, 26, 267, 870, 21506, 4, 34, 879, 15215, 4, 22550, 339, 5218, 600, 275, 488, 272, 340, 1249, 14, 31973, 26, 267, 6111, 275, 1551, 8, 589, 14, 31973, 12, 283, 82, 358, 267, 5218, 600, 275, 6111, 14, 739, 342, 267, 6111, 14, 1600, 342, 339, 15868, 390, 8, 589, 14, 1501, 12, 1249, 14, 1393, 12, 5218, 600, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
haad/ansible
lib/ansible/plugins/action/sros.py
10
3128
# # (c) 2016 Red Hat Inc. # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # from __future__ import (absolute_import, division, print_function) __metaclass__ = type import sys import copy from ansible import constants as C from ansible.plugins.action.normal import ActionModule as _ActionModule from ansible.module_utils.network.sros.sros import sros_provider_spec from ansible.module_utils.network.common.utils import load_provider try: from __main__ import display except ImportError: from ansible.utils.display import Display display = Display() class ActionModule(_ActionModule): def run(self, tmp=None, task_vars=None): if self._play_context.connection == 'network_cli': provider = self._task.args.get('provider', {}) if any(provider.values()): display.warning('provider is unnecessary when using network_cli and will be ignored') elif self._play_context.connection == 'local': provider = load_provider(sros_provider_spec, self._task.args) pc = copy.deepcopy(self._play_context) pc.connection = 'network_cli' pc.network_os = 'sros' pc.remote_addr = provider['host'] or self._play_context.remote_addr pc.port = int(provider['port'] or self._play_context.port or 22) pc.remote_user = provider['username'] or self._play_context.connection_user pc.password = provider['password'] or self._play_context.password pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file pc.timeout = int(provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT) display.vvv('using connection plugin %s (was local)' % pc.connection, pc.remote_addr) connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin) socket_path = connection.run() display.vvvv('socket_path: %s' % socket_path, pc.remote_addr) if not socket_path: return {'failed': True, 'msg': 'unable to open shell. Please see: ' + 'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'} task_vars['ansible_socket'] = socket_path else: return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection} result = super(ActionModule, self).run(tmp, task_vars) return result
gpl-3.0
[ 3, 199, 3, 334, 67, 9, 7800, 9572, 13002, 3277, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 646, 984, 199, 646, 1331, 199, 199, 504, 3242, 492, 5262, 465, 445, 199, 504, 3242, 14, 5265, 14, 1287, 14, 3302, 492, 10033, 2377, 465, 485, 3310, 2377, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 83, 4796, 14, 83, 4796, 492, 308, 4796, 63, 3780, 63, 1650, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 2330, 14, 1208, 492, 2248, 63, 3780, 199, 199, 893, 26, 272, 687, 636, 973, 363, 492, 2929, 199, 2590, 3545, 26, 272, 687, 3242, 14, 1208, 14, 2918, 492, 12175, 272, 2929, 275, 12175, 342, 421, 199, 533, 10033, 2377, 1547, 3310, 2377, 304, 339, 347, 1255, 8, 277, 12, 3529, 29, 403, 12, 2120, 63, 2936, 29, 403, 304, 398, 340, 291, 423, 2802, 63, 1100, 14, 2105, 508, 283, 1200, 63, 2764, 356, 288, 5022, 275, 291, 423, 1765, 14, 589, 14, 362, 360, 3780, 297, 5009, 288, 340, 1263, 8, 3780, 14, 1459, 5109, 355, 2929, 14, 3764, 360, 3780, 365, 23361, 1380, 1808, 2784, 63, 2764, 436, 911, 506, 5525, 358, 267, 916, 291, 423, 2802, 63, 1100, 14, 2105, 508, 283, 1832, 356, 288, 5022, 275, 2248, 63, 3780, 8, 83, 4796, 63, 3780, 63, 1650, 12, 291, 423, 1765, 14, 589, 9, 953, 13171, 275, 1331, 14, 8293, 8, 277, 423, 2802, 63, 1100, 9, 288, 13171, 14, 2105, 275, 283, 1200, 63, 2764, 7, 288, 13171, 14, 1200, 63, 736, 275, 283, 83, 4796, 7, 288, 13171, 14, 3846, 63, 2697, 275, 5022, 459, 1102, 418, 503, 291, 423, 2802, 63, 1100, 14, 3846, 63, 2697, 288, 13171, 14, 719, 275, 1109, 8, 3780, 459, 719, 418, 503, 291, 423, 2802, 63, 1100, 14, 719, 503, 6928, 9, 288, 13171, 14, 3846, 63, 751, 275, 5022, 459, 2473, 418, 503, 291, 423, 2802, 63, 1100, 14, 2105, 63, 751, 288, 13171, 14, 2060, 275, 5022, 459, 2060, 418, 503, 291, 423, 2802, 63, 1100, 14, 2060, 288, 13171, 14, 4239, 63, 498, 63, 493, 275, 5022, 459, 5510, 63, 21856, 418, 503, 291, 423, 2802, 63, 1100, 14, 4239, 63, 498, 63, 493, 288, 13171, 14, 2593, 275, 1109, 8, 3780, 459, 2593, 418, 503, 445, 14, 4227, 29367, 1309, 63, 10761, 63, 8899, 9, 953, 2929, 14, 24622, 360, 4941, 1950, 3589, 450, 83, 334, 10274, 2257, 3171, 450, 13171, 14, 2105, 12, 13171, 14, 3846, 63, 2697, 9, 288, 1950, 275, 291, 423, 5555, 63, 3422, 63, 1113, 14, 2105, 63, 3422, 14, 362, 360, 18539, 297, 13171, 12, 984, 14, 6626, 9, 953, 2838, 63, 515, 275, 1950, 14, 1065, 342, 288, 2929, 14, 30448, 360, 3450, 63, 515, 26, 450, 83, 7, 450, 2838, 63, 515, 12, 13171, 14, 3846, 63, 2697, 9, 288, 340, 440, 2838, 63, 515, 26, 355, 372, 791, 4892, 356, 715, 12, 717, 283, 1328, 356, 283, 17200, 370, 1551, 5218, 14, 7754, 1937, 26, 283, 435, 717, 283, 2859, 921, 4757, 14, 4853, 14, 957, 15, 4853, 15, 1200, 63, 1757, 63, 1374, 2016, 13927, 15866, 14, 1360, 3, 17200, 13, 475, 13, 1490, 13, 5641, 936, 953, 2120, 63, 2936, 459, 4853, 63, 3450, 418, 275, 2838, 63, 515, 267, 587, 26, 288, 372, 791, 4892, 356, 715, 12, 283, 1328, 356, 283, 3225, 730, 450, 83, 365, 440, 1686, 367, 642, 859, 7, 450, 291, 423, 2802, 63, 1100, 14, 2105, 93, 398, 754, 275, 1613, 8, 3310, 2377, 12, 291, 680, 1065, 8, 2791, 12, 2120, 63, 2936, 9, 267, 372, 754, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 3, 334, 67, 9, 7800, 9572, 13002, 3277, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 646, 984, 199, 646, 1331, 199, 199, 504, 3242, 492, 5262, 465, 445, 199, 504, 3242, 14, 5265, 14, 1287, 14, 3302, 492, 10033, 2377, 465, 485, 3310, 2377, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 83, 4796, 14, 83, 4796, 492, 308, 4796, 63, 3780, 63, 1650, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 2330, 14, 1208, 492, 2248, 63, 3780, 199, 199, 893, 26, 272, 687, 636, 973, 363, 492, 2929, 199, 2590, 3545, 26, 272, 687, 3242, 14, 1208, 14, 2918, 492, 12175, 272, 2929, 275, 12175, 342, 421, 199, 533, 10033, 2377, 1547, 3310, 2377, 304, 339, 347, 1255, 8, 277, 12, 3529, 29, 403, 12, 2120, 63, 2936, 29, 403, 304, 398, 340, 291, 423, 2802, 63, 1100, 14, 2105, 508, 283, 1200, 63, 2764, 356, 288, 5022, 275, 291, 423, 1765, 14, 589, 14, 362, 360, 3780, 297, 5009, 288, 340, 1263, 8, 3780, 14, 1459, 5109, 355, 2929, 14, 3764, 360, 3780, 365, 23361, 1380, 1808, 2784, 63, 2764, 436, 911, 506, 5525, 358, 267, 916, 291, 423, 2802, 63, 1100, 14, 2105, 508, 283, 1832, 356, 288, 5022, 275, 2248, 63, 3780, 8, 83, 4796, 63, 3780, 63, 1650, 12, 291, 423, 1765, 14, 589, 9, 953, 13171, 275, 1331, 14, 8293, 8, 277, 423, 2802, 63, 1100, 9, 288, 13171, 14, 2105, 275, 283, 1200, 63, 2764, 7, 288, 13171, 14, 1200, 63, 736, 275, 283, 83, 4796, 7, 288, 13171, 14, 3846, 63, 2697, 275, 5022, 459, 1102, 418, 503, 291, 423, 2802, 63, 1100, 14, 3846, 63, 2697, 288, 13171, 14, 719, 275, 1109, 8, 3780, 459, 719, 418, 503, 291, 423, 2802, 63, 1100, 14, 719, 503, 6928, 9, 288, 13171, 14, 3846, 63, 751, 275, 5022, 459, 2473, 418, 503, 291, 423, 2802, 63, 1100, 14, 2105, 63, 751, 288, 13171, 14, 2060, 275, 5022, 459, 2060, 418, 503, 291, 423, 2802, 63, 1100, 14, 2060, 288, 13171, 14, 4239, 63, 498, 63, 493, 275, 5022, 459, 5510, 63, 21856, 418, 503, 291, 423, 2802, 63, 1100, 14, 4239, 63, 498, 63, 493, 288, 13171, 14, 2593, 275, 1109, 8, 3780, 459, 2593, 418, 503, 445, 14, 4227, 29367, 1309, 63, 10761, 63, 8899, 9, 953, 2929, 14, 24622, 360, 4941, 1950, 3589, 450, 83, 334, 10274, 2257, 3171, 450, 13171, 14, 2105, 12, 13171, 14, 3846, 63, 2697, 9, 288, 1950, 275, 291, 423, 5555, 63, 3422, 63, 1113, 14, 2105, 63, 3422, 14, 362, 360, 18539, 297, 13171, 12, 984, 14, 6626, 9, 953, 2838, 63, 515, 275, 1950, 14, 1065, 342, 288, 2929, 14, 30448, 360, 3450, 63, 515, 26, 450, 83, 7, 450, 2838, 63, 515, 12, 13171, 14, 3846, 63, 2697, 9, 288, 340, 440, 2838, 63, 515, 26, 355, 372, 791, 4892, 356, 715, 12, 717, 283, 1328, 356, 283, 17200, 370, 1551, 5218, 14, 7754, 1937, 26, 283, 435, 717, 283, 2859, 921, 4757, 14, 4853, 14, 957, 15, 4853, 15, 1200, 63, 1757, 63, 1374, 2016, 13927, 15866, 14, 1360, 3, 17200, 13, 475, 13, 1490, 13, 5641, 936, 953, 2120, 63, 2936, 459, 4853, 63, 3450, 418, 275, 2838, 63, 515, 267, 587, 26, 288, 372, 791, 4892, 356, 715, 12, 283, 1328, 356, 283, 3225, 730, 450, 83, 365, 440, 1686, 367, 642, 859, 7, 450, 291, 423, 2802, 63, 1100, 14, 2105, 93, 398, 754, 275, 1613, 8, 3310, 2377, 12, 291, 680, 1065, 8, 2791, 12, 2120, 63, 2936, 9, 267, 372, 754, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
hongguangguo/shogun
examples/undocumented/python_modular/evaluation_cross_validation_classification.py
9
2189
#!/usr/bin/env python # # 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. # # Written (W) 2012 Heiko Strathmann # Copyright (C) 2012 Berlin Institute of Technology and Max-Planck-Society # from numpy.random import randn from numpy import * # generate some overlapping training vectors num_vectors=100 vec_distance=1 traindat=concatenate((randn(2,num_vectors)-vec_distance, randn(2,num_vectors)+vec_distance), axis=1) label_traindat=concatenate((-ones(num_vectors), ones(num_vectors))); parameter_list = [[traindat,label_traindat]] def evaluation_cross_validation_classification (traindat=traindat, label_traindat=label_traindat): from modshogun import CrossValidation, CrossValidationResult from modshogun import ContingencyTableEvaluation, ACCURACY from modshogun import StratifiedCrossValidationSplitting from modshogun import BinaryLabels from modshogun import RealFeatures from modshogun import LibLinear, L2R_L2LOSS_SVC # training data features=RealFeatures(traindat) labels=BinaryLabels(label_traindat) # classifier classifier=LibLinear(L2R_L2LOSS_SVC) # splitting strategy for 5 fold cross-validation (for classification its better # to use "StratifiedCrossValidation", but the standard # "CrossValidationSplitting" is also available splitting_strategy=StratifiedCrossValidationSplitting(labels, 5) # evaluation method evaluation_criterium=ContingencyTableEvaluation(ACCURACY) # cross-validation instance cross_validation=CrossValidation(classifier, features, labels, splitting_strategy, evaluation_criterium) cross_validation.set_autolock(False) # (optional) repeat x-val 10 times cross_validation.set_num_runs(10) # perform cross-validation and print(results) result=cross_validation.evaluate() #print("mean:", result.mean) if __name__=='__main__': print('Evaluation CrossValidationClassification') evaluation_cross_validation_classification(*parameter_list[0])
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 27694, 334, 55, 9, 6029, 5311, 16625, 428, 1239, 273, 20059, 199, 3, 1898, 334, 35, 9, 6029, 23207, 472, 1010, 25585, 402, 21580, 436, 8228, 13, 13375, 346, 13, 51, 3095, 23364, 199, 3, 199, 199, 504, 2680, 14, 2355, 492, 10261, 78, 199, 504, 2680, 492, 627, 199, 199, 3, 3550, 2005, 28281, 6093, 11102, 199, 1507, 63, 12280, 29, 1960, 199, 6046, 63, 5590, 29, 17, 199, 1239, 688, 292, 29, 13433, 1332, 10843, 8, 18, 12, 1507, 63, 12280, 7216, 6046, 63, 5590, 12, 199, 198, 10843, 8, 18, 12, 1507, 63, 12280, 6393, 6046, 63, 5590, 395, 3114, 29, 17, 9, 199, 1302, 63, 1239, 688, 292, 29, 13433, 18138, 4548, 8, 1507, 63, 12280, 395, 7869, 8, 1507, 63, 12280, 1724, 27, 199, 199, 5329, 63, 513, 275, 3474, 1239, 688, 292, 12, 1302, 63, 1239, 688, 292, 2677, 199, 199, 318, 11735, 63, 7925, 63, 6136, 63, 14368, 334, 1239, 688, 292, 29, 1239, 688, 292, 12, 1768, 63, 1239, 688, 292, 29, 1302, 63, 1239, 688, 292, 304, 272, 687, 3413, 13927, 17924, 492, 28965, 13816, 12, 28965, 13816, 2889, 272, 687, 3413, 13927, 17924, 492, 1448, 1337, 9501, 3186, 29786, 12, 16362, 1230, 22114, 272, 687, 3413, 13927, 17924, 492, 428, 1239, 8981, 14072, 13816, 8862, 1337, 272, 687, 3413, 13927, 17924, 492, 14161, 14016, 272, 687, 3413, 13927, 17924, 492, 14849, 10807, 272, 687, 3413, 13927, 17924, 492, 8003, 10608, 12, 491, 18, 50, 63, 44, 18, 28010, 63, 17675, 339, 327, 6093, 666, 272, 4534, 29, 10099, 10807, 8, 1239, 688, 292, 9, 272, 3628, 29, 6636, 14016, 8, 1302, 63, 1239, 688, 292, 9, 339, 327, 12429, 272, 12429, 29, 4728, 10608, 8, 44, 18, 50, 63, 44, 18, 28010, 63, 17675, 9, 339, 327, 26518, 10054, 367, 959, 20675, 8059, 13, 6136, 334, 509, 12505, 2399, 8034, 272, 327, 370, 675, 298, 933, 345, 8981, 14072, 13816, 401, 1325, 314, 4465, 272, 327, 298, 14072, 13816, 8862, 1337, 2, 365, 2597, 2808, 272, 26518, 63, 8590, 29, 933, 345, 8981, 14072, 13816, 8862, 1337, 8, 3512, 12, 959, 9, 339, 327, 11735, 1083, 272, 11735, 63, 14120, 453, 29, 714, 1337, 9501, 3186, 29786, 8, 1348, 7013, 22114, 9, 339, 327, 8059, 13, 6136, 1256, 272, 8059, 63, 6136, 29, 14072, 13816, 8, 14720, 12, 4534, 12, 3628, 12, 6722, 26518, 63, 8590, 12, 11735, 63, 14120, 453, 9, 272, 8059, 63, 6136, 14, 409, 63, 2495, 831, 8, 797, 9, 339, 327, 334, 4144, 9, 11982, 671, 13, 637, 1616, 5431, 272, 8059, 63, 6136, 14, 409, 63, 1507, 63, 10802, 8, 709, 9, 339, 327, 5147, 8059, 13, 6136, 436, 870, 8, 2604, 9, 272, 754, 29, 7925, 63, 6136, 14, 7383, 342, 272, 327, 1361, 480, 3670, 6783, 754, 14, 3670, 9, 199, 199, 692, 636, 354, 363, 6803, 363, 973, 3706, 199, 198, 1361, 360, 29786, 28965, 13816, 28362, 358, 199, 198, 19154, 63, 7925, 63, 6136, 63, 14368, 2031, 5329, 63, 513, 59, 16, 566, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 27694, 334, 55, 9, 6029, 5311, 16625, 428, 1239, 273, 20059, 199, 3, 1898, 334, 35, 9, 6029, 23207, 472, 1010, 25585, 402, 21580, 436, 8228, 13, 13375, 346, 13, 51, 3095, 23364, 199, 3, 199, 199, 504, 2680, 14, 2355, 492, 10261, 78, 199, 504, 2680, 492, 627, 199, 199, 3, 3550, 2005, 28281, 6093, 11102, 199, 1507, 63, 12280, 29, 1960, 199, 6046, 63, 5590, 29, 17, 199, 1239, 688, 292, 29, 13433, 1332, 10843, 8, 18, 12, 1507, 63, 12280, 7216, 6046, 63, 5590, 12, 199, 198, 10843, 8, 18, 12, 1507, 63, 12280, 6393, 6046, 63, 5590, 395, 3114, 29, 17, 9, 199, 1302, 63, 1239, 688, 292, 29, 13433, 18138, 4548, 8, 1507, 63, 12280, 395, 7869, 8, 1507, 63, 12280, 1724, 27, 199, 199, 5329, 63, 513, 275, 3474, 1239, 688, 292, 12, 1302, 63, 1239, 688, 292, 2677, 199, 199, 318, 11735, 63, 7925, 63, 6136, 63, 14368, 334, 1239, 688, 292, 29, 1239, 688, 292, 12, 1768, 63, 1239, 688, 292, 29, 1302, 63, 1239, 688, 292, 304, 272, 687, 3413, 13927, 17924, 492, 28965, 13816, 12, 28965, 13816, 2889, 272, 687, 3413, 13927, 17924, 492, 1448, 1337, 9501, 3186, 29786, 12, 16362, 1230, 22114, 272, 687, 3413, 13927, 17924, 492, 428, 1239, 8981, 14072, 13816, 8862, 1337, 272, 687, 3413, 13927, 17924, 492, 14161, 14016, 272, 687, 3413, 13927, 17924, 492, 14849, 10807, 272, 687, 3413, 13927, 17924, 492, 8003, 10608, 12, 491, 18, 50, 63, 44, 18, 28010, 63, 17675, 339, 327, 6093, 666, 272, 4534, 29, 10099, 10807, 8, 1239, 688, 292, 9, 272, 3628, 29, 6636, 14016, 8, 1302, 63, 1239, 688, 292, 9, 339, 327, 12429, 272, 12429, 29, 4728, 10608, 8, 44, 18, 50, 63, 44, 18, 28010, 63, 17675, 9, 339, 327, 26518, 10054, 367, 959, 20675, 8059, 13, 6136, 334, 509, 12505, 2399, 8034, 272, 327, 370, 675, 298, 933, 345, 8981, 14072, 13816, 401, 1325, 314, 4465, 272, 327, 298, 14072, 13816, 8862, 1337, 2, 365, 2597, 2808, 272, 26518, 63, 8590, 29, 933, 345, 8981, 14072, 13816, 8862, 1337, 8, 3512, 12, 959, 9, 339, 327, 11735, 1083, 272, 11735, 63, 14120, 453, 29, 714, 1337, 9501, 3186, 29786, 8, 1348, 7013, 22114, 9, 339, 327, 8059, 13, 6136, 1256, 272, 8059, 63, 6136, 29, 14072, 13816, 8, 14720, 12, 4534, 12, 3628, 12, 6722, 26518, 63, 8590, 12, 11735, 63, 14120, 453, 9, 272, 8059, 63, 6136, 14, 409, 63, 2495, 831, 8, 797, 9, 339, 327, 334, 4144, 9, 11982, 671, 13, 637, 1616, 5431, 272, 8059, 63, 6136, 14, 409, 63, 1507, 63, 10802, 8, 709, 9, 339, 327, 5147, 8059, 13, 6136, 436, 870, 8, 2604, 9, 272, 754, 29, 7925, 63, 6136, 14, 7383, 342, 272, 327, 1361, 480, 3670, 6783, 754, 14, 3670, 9, 199, 199, 692, 636, 354, 363, 6803, 363, 973, 3706, 199, 198, 1361, 360, 29786, 28965, 13816, 28362, 358, 199, 198, 19154, 63, 7925, 63, 6136, 63, 14368, 2031, 5329, 63, 513, 59, 16, 566, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 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0, 0 ]
dankilman/claw
claw/tests/test_configuration.py
1
9543
######## # Copyright (c) 2015 GigaSpaces Technologies Ltd. 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 logging import os import yaml import fabric.api from path import path from claw import configuration from claw import tests from claw.handlers import stub_handler class TestConfiguration(tests.BaseTest): def test_init_from_dir(self): conf = configuration.Configuration(self.workdir) self.assertEqual(conf.configuration, self.workdir.basename()) def test_init_from_current_dir(self): conf = configuration.Configuration() self.assertEqual(conf.configuration, path(os.getcwd()).basename()) def test_init_from_current_configuration(self): self.init() conf = configuration.Configuration(configuration.CURRENT_CONFIGURATION) self.assertEqual(conf.configuration, configuration.CURRENT_CONFIGURATION) self.claw.generate(tests.STUB_CONFIGURATION) conf = configuration.Configuration(configuration.CURRENT_CONFIGURATION) self.assertEqual(conf.configuration, tests.STUB_CONFIGURATION) def test_exists(self): self.init() conf = configuration.Configuration(tests.STUB_CONFIGURATION) self.assertFalse(conf.exists()) self.claw.generate(tests.STUB_CONFIGURATION) conf = configuration.Configuration(tests.STUB_CONFIGURATION) self.assertTrue(conf.exists()) blueprint = conf.blueprint(tests.STUB_BLUEPRINT) self.assertFalse(blueprint.exists()) self.claw('generate-blueprint', tests.STUB_CONFIGURATION, tests.STUB_BLUEPRINT) self.assertTrue(blueprint.exists()) def test_configuration_properties(self): conf, blueprint = self._init_configuration_and_blueprint() conf_dir = self.workdir / 'configurations' / tests.STUB_CONFIGURATION self.assertEqual(conf.dir, conf_dir) self.assertEqual(conf.manager_blueprint_dir, conf_dir / 'manager-blueprint') self.assertEqual(conf.blueprints_dir, conf_dir / 'blueprints') self.assertEqual(conf.inputs_path, conf_dir / 'inputs.yaml') self.assertEqual( conf.manager_blueprint_path, conf_dir / 'manager-blueprint' / 'manager-blueprint.yaml') self.assertEqual(conf.handler_configuration_path, conf_dir / 'handler-configuration.yaml') self.assertEqual(conf.cli_config_path, conf_dir / '.cloudify' / 'config.yaml') blueprint_dir = conf.blueprints_dir / tests.STUB_BLUEPRINT self.assertIs(blueprint.configuration, conf) self.assertEqual(blueprint.blueprint_name, tests.STUB_BLUEPRINT) self.assertEqual(blueprint.dir, blueprint_dir) self.assertEqual(blueprint.blueprint_configuration_path, blueprint_dir / 'blueprint-configuration.yaml') self.assertEqual(blueprint.inputs_path, blueprint_dir / 'inputs.yaml') self.assertEqual(blueprint.blueprint_path, blueprint_dir / 'blueprint' / 'blueprint.yaml') def test_yaml_files(self): conf, blueprint = self._init_configuration_and_blueprint() conf_dir = self.workdir / 'configurations' / tests.STUB_CONFIGURATION blueprint_dir = conf.blueprints_dir / tests.STUB_BLUEPRINT conf.cli_config_path.dirname().mkdir_p() configuration_files = [ ('inputs', conf_dir / 'inputs.yaml'), ('handler_configuration', conf_dir / 'handler-configuration.yaml'), ('manager_blueprint', conf_dir / 'manager-blueprint' / 'manager-blueprint.yaml'), ('cli_config', conf_dir / '.cloudify' / 'config.yaml'), ] blueprint_files = [ ('inputs', blueprint_dir / 'inputs.yaml'), ('blueprint', blueprint_dir / 'blueprint' / 'blueprint.yaml'), ('blueprint_configuration', blueprint_dir / 'blueprint-configuration.yaml') ] def assert_files(obj, files): content = {'some': 'value'} for _file in files: setattr(obj, _file[0], content) if isinstance(obj, configuration.Configuration): new_obj = configuration.Configuration(tests.STUB_CONFIGURATION) else: new_obj = conf.blueprint(tests.STUB_BLUEPRINT) for _file in files: self.assertEqual(content, getattr(new_obj, _file[0])) self.assertEqual(yaml.safe_load(_file[1].text()), content) assert_files(conf, configuration_files) assert_files(blueprint, blueprint_files) def test_properties(self): props_name = 'props1' main_suites_yaml_path = self.workdir / 'main-suites.yaml' main_suites_yaml = { 'variables': {'a': '123'}, 'handler_properties': { props_name: { 'a_from_var': '{{a}}', 'b': 'b_val' } } } main_suites_yaml_path.write_text(yaml.safe_dump(main_suites_yaml)) conf = self._init_configuration(main_suites_yaml_path) with conf.patch.handler_configuration as patch: patch.obj.pop('properties', None) self.assertEqual(conf.properties, {}) with conf.patch.handler_configuration as patch: patch.obj['properties'] = 'no_such_properties' self.assertEqual(conf.properties, {}) with conf.patch.handler_configuration as patch: patch.obj['properties'] = props_name self.assertEqual(conf.properties, { 'a_from_var': '123', 'b': 'b_val' }) def test_client(self): conf = self._init_configuration() self.assertEqual(conf.client._client.host, 'localhost') ip = '1.1.1.1' default_port = 80 custom_port = 12345 with conf.patch.handler_configuration as patch: patch.obj['manager_ip'] = ip self.assertEqual(conf.client._client.host, ip) self.assertEqual(conf.client._client.port, default_port) with conf.patch.handler_configuration as patch: patch.obj['manager_port'] = custom_port self.assertEqual(conf.client._client.host, ip) self.assertEqual(conf.client._client.port, custom_port) def test_claw_handler(self): conf = self._init_configuration() with conf.patch.handler_configuration as patch: patch.set_value('handler', 'stub_handler') claw_handler = conf.claw_handler self.assertTrue(isinstance(claw_handler, stub_handler.Handler)) self.assertIs(claw_handler.configuration, conf) def test_patch(self): conf, blueprint = self._init_configuration_and_blueprint() key = 'some_key' value = 'some_value' conf.cli_config_path.dirname().makedirs_p() conf.cli_config_path.write_text('{}') def _assert_patching(obj, props): for prop in props: with getattr(obj.patch, prop) as patch: patch.set_value(key, value) self.assertEqual(getattr(obj, prop)[key], value) _assert_patching(conf, ['inputs', 'manager_blueprint', 'handler_configuration', 'cli_config']) _assert_patching(blueprint, ['inputs', 'blueprint', 'blueprint_configuration']) def test_ssh(self): conf = self._init_configuration() ip = '1.1.1.1' user = 'user' key = '~/key' with conf.patch.handler_configuration as patch: patch.obj.update({ 'manager_ip': ip, 'manager_user': user, 'manager_key': key }) with conf.ssh() as ssh: self.assertEqual(ssh, fabric.api) self.assertEqual(fabric.api.env['host_string'], ip) self.assertEqual(fabric.api.env['user'], user) self.assertEqual(fabric.api.env['key_filename'], key) def test_logger(self): conf = self._init_configuration() logger = conf.logger self.assertTrue(isinstance(logger, logging.Logger)) self.assertEqual(1, len(logger.handlers)) def _init_configuration(self, suites_yaml=None): self.init(suites_yaml) self.claw.generate(tests.STUB_CONFIGURATION) return configuration.Configuration(tests.STUB_CONFIGURATION) def _init_configuration_and_blueprint(self): conf = self._init_configuration() self.claw('generate-blueprint', tests.STUB_CONFIGURATION, tests.STUB_BLUEPRINT) blueprint = conf.blueprint(tests.STUB_BLUEPRINT) return conf, blueprint
apache-2.0
[ 516, 199, 3, 1898, 334, 67, 9, 6900, 598, 29055, 23415, 19215, 12126, 14, 2900, 4481, 4644, 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, 263, 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, 516, 381, 199, 199, 646, 2050, 199, 646, 747, 199, 199, 646, 8864, 199, 646, 2630, 14, 1246, 199, 504, 931, 492, 931, 199, 199, 504, 6108, 87, 492, 2897, 199, 504, 6108, 87, 492, 2295, 199, 504, 6108, 87, 14, 5586, 492, 10098, 63, 2232, 421, 199, 533, 1379, 5688, 8, 2219, 14, 23170, 304, 339, 347, 511, 63, 826, 63, 504, 63, 694, 8, 277, 304, 267, 3743, 275, 2897, 14, 5688, 8, 277, 14, 19132, 9, 267, 291, 14, 629, 8, 2190, 14, 4758, 12, 291, 14, 19132, 14, 4846, 1012, 339, 347, 511, 63, 826, 63, 504, 63, 1818, 63, 694, 8, 277, 304, 267, 3743, 275, 2897, 14, 5688, 342, 267, 291, 14, 629, 8, 2190, 14, 4758, 12, 931, 8, 736, 14, 9458, 8801, 4846, 1012, 339, 347, 511, 63, 826, 63, 504, 63, 1818, 63, 4758, 8, 277, 304, 267, 291, 14, 826, 342, 267, 3743, 275, 2897, 14, 5688, 8, 4758, 14, 14211, 63, 22212, 9, 267, 291, 14, 629, 8, 2190, 14, 4758, 12, 586, 2897, 14, 14211, 63, 22212, 9, 267, 291, 14, 3995, 87, 14, 4208, 8, 2219, 14, 840, 2533, 63, 22212, 9, 267, 3743, 275, 2897, 14, 5688, 8, 4758, 14, 14211, 63, 22212, 9, 267, 291, 14, 629, 8, 2190, 14, 4758, 12, 2295, 14, 840, 2533, 63, 22212, 9, 339, 347, 511, 63, 2444, 8, 277, 304, 267, 291, 14, 826, 342, 267, 3743, 275, 2897, 14, 5688, 8, 2219, 14, 840, 2533, 63, 22212, 9, 267, 291, 14, 3334, 8, 2190, 14, 2444, 1012, 267, 291, 14, 3995, 87, 14, 4208, 8, 2219, 14, 840, 2533, 63, 22212, 9, 267, 3743, 275, 2897, 14, 5688, 8, 2219, 14, 840, 2533, 63, 22212, 9, 267, 291, 14, 1815, 8, 2190, 14, 2444, 1012, 267, 16808, 275, 3743, 14, 15918, 8, 2219, 14, 840, 2533, 63, 23536, 21754, 9, 267, 291, 14, 3334, 8, 15918, 14, 2444, 1012, 267, 291, 14, 3995, 87, 360, 4208, 13, 15918, 297, 2295, 14, 840, 2533, 63, 22212, 12, 2116, 2295, 14, 840, 2533, 63, 23536, 21754, 9, 267, 291, 14, 1815, 8, 15918, 14, 2444, 1012, 339, 347, 511, 63, 4758, 63, 3282, 8, 277, 304, 267, 3743, 12, 16808, 275, 291, 423, 826, 63, 4758, 63, 460, 63, 15918, 342, 398, 3743, 63, 694, 275, 291, 14, 19132, 1182, 283, 10057, 7, 1182, 2295, 14, 840, 2533, 63, 22212, 267, 291, 14, 629, 8, 2190, 14, 694, 12, 3743, 63, 694, 9, 267, 291, 14, 629, 8, 2190, 14, 2609, 63, 15918, 63, 694, 12, 586, 3743, 63, 694, 1182, 283, 2609, 13, 15918, 358, 267, 291, 14, 629, 8, 2190, 14, 15918, 83, 63, 694, 12, 586, 3743, 63, 694, 1182, 283, 15918, 83, 358, 267, 291, 14, 629, 8, 2190, 14, 3711, 63, 515, 12, 586, 3743, 63, 694, 1182, 283, 3711, 14, 5963, 358, 267, 291, 14, 629, 8, 288, 3743, 14, 2609, 63, 15918, 63, 515, 12, 288, 3743, 63, 694, 1182, 283, 2609, 13, 15918, 7, 1182, 283, 2609, 13, 15918, 14, 5963, 358, 267, 291, 14, 629, 8, 2190, 14, 2232, 63, 4758, 63, 515, 12, 586, 3743, 63, 694, 1182, 283, 2232, 13, 4758, 14, 5963, 358, 267, 291, 14, 629, 8, 2190, 14, 2764, 63, 888, 63, 515, 12, 586, 3743, 63, 694, 1182, 1987, 1251, 14525, 1399, 7, 1182, 283, 888, 14, 5963, 358, 398, 16808, 63, 694, 275, 3743, 14, 15918, 83, 63, 694, 1182, 2295, 14, 840, 2533, 63, 23536, 21754, 267, 291, 14, 3436, 8, 15918, 14, 4758, 12, 3743, 9, 267, 291, 14, 629, 8, 15918, 14, 15918, 63, 354, 12, 2295, 14, 840, 2533, 63, 23536, 21754, 9, 267, 291, 14, 629, 8, 15918, 14, 694, 12, 16808, 63, 694, 9, 267, 291, 14, 629, 8, 15918, 14, 15918, 63, 4758, 63, 515, 12, 586, 16808, 63, 694, 1182, 283, 15918, 13, 4758, 14, 5963, 358, 267, 291, 14, 629, 8, 15918, 14, 3711, 63, 515, 12, 586, 16808, 63, 694, 1182, 283, 3711, 14, 5963, 358, 267, 291, 14, 629, 8, 15918, 14, 15918, 63, 515, 12, 586, 16808, 63, 694, 1182, 283, 15918, 7, 1182, 283, 15918, 14, 5963, 358, 339, 347, 511, 63, 5963, 63, 1725, 8, 277, 304, 267, 3743, 12, 16808, 275, 291, 423, 826, 63, 4758, 63, 460, 63, 15918, 342, 267, 3743, 63, 694, 275, 291, 14, 19132, 1182, 283, 10057, 7, 1182, 2295, 14, 840, 2533, 63, 22212, 267, 16808, 63, 694, 275, 3743, 14, 15918, 83, 63, 694, 1182, 2295, 14, 840, 2533, 63, 23536, 21754, 267, 3743, 14, 2764, 63, 888, 63, 515, 14, 3475, 1252, 8215, 63, 80, 342, 398, 2897, 63, 1725, 275, 359, 288, 661, 3711, 297, 3743, 63, 694, 1182, 283, 3711, 14, 5963, 659, 288, 661, 2232, 63, 4758, 297, 3743, 63, 694, 1182, 283, 2232, 13, 4758, 14, 5963, 659, 288, 661, 2609, 63, 15918, 297, 1467, 3743, 63, 694, 1182, 283, 2609, 13, 15918, 7, 1182, 283, 2609, 13, 15918, 14, 5963, 659, 288, 661, 2764, 63, 888, 297, 3743, 63, 694, 1182, 1987, 1251, 14525, 1399, 7, 1182, 283, 888, 14, 5963, 659, 267, 1622, 267, 16808, 63, 1725, 275, 359, 288, 661, 3711, 297, 16808, 63, 694, 1182, 283, 3711 ]
[ 199, 3, 1898, 334, 67, 9, 6900, 598, 29055, 23415, 19215, 12126, 14, 2900, 4481, 4644, 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, 263, 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, 516, 381, 199, 199, 646, 2050, 199, 646, 747, 199, 199, 646, 8864, 199, 646, 2630, 14, 1246, 199, 504, 931, 492, 931, 199, 199, 504, 6108, 87, 492, 2897, 199, 504, 6108, 87, 492, 2295, 199, 504, 6108, 87, 14, 5586, 492, 10098, 63, 2232, 421, 199, 533, 1379, 5688, 8, 2219, 14, 23170, 304, 339, 347, 511, 63, 826, 63, 504, 63, 694, 8, 277, 304, 267, 3743, 275, 2897, 14, 5688, 8, 277, 14, 19132, 9, 267, 291, 14, 629, 8, 2190, 14, 4758, 12, 291, 14, 19132, 14, 4846, 1012, 339, 347, 511, 63, 826, 63, 504, 63, 1818, 63, 694, 8, 277, 304, 267, 3743, 275, 2897, 14, 5688, 342, 267, 291, 14, 629, 8, 2190, 14, 4758, 12, 931, 8, 736, 14, 9458, 8801, 4846, 1012, 339, 347, 511, 63, 826, 63, 504, 63, 1818, 63, 4758, 8, 277, 304, 267, 291, 14, 826, 342, 267, 3743, 275, 2897, 14, 5688, 8, 4758, 14, 14211, 63, 22212, 9, 267, 291, 14, 629, 8, 2190, 14, 4758, 12, 586, 2897, 14, 14211, 63, 22212, 9, 267, 291, 14, 3995, 87, 14, 4208, 8, 2219, 14, 840, 2533, 63, 22212, 9, 267, 3743, 275, 2897, 14, 5688, 8, 4758, 14, 14211, 63, 22212, 9, 267, 291, 14, 629, 8, 2190, 14, 4758, 12, 2295, 14, 840, 2533, 63, 22212, 9, 339, 347, 511, 63, 2444, 8, 277, 304, 267, 291, 14, 826, 342, 267, 3743, 275, 2897, 14, 5688, 8, 2219, 14, 840, 2533, 63, 22212, 9, 267, 291, 14, 3334, 8, 2190, 14, 2444, 1012, 267, 291, 14, 3995, 87, 14, 4208, 8, 2219, 14, 840, 2533, 63, 22212, 9, 267, 3743, 275, 2897, 14, 5688, 8, 2219, 14, 840, 2533, 63, 22212, 9, 267, 291, 14, 1815, 8, 2190, 14, 2444, 1012, 267, 16808, 275, 3743, 14, 15918, 8, 2219, 14, 840, 2533, 63, 23536, 21754, 9, 267, 291, 14, 3334, 8, 15918, 14, 2444, 1012, 267, 291, 14, 3995, 87, 360, 4208, 13, 15918, 297, 2295, 14, 840, 2533, 63, 22212, 12, 2116, 2295, 14, 840, 2533, 63, 23536, 21754, 9, 267, 291, 14, 1815, 8, 15918, 14, 2444, 1012, 339, 347, 511, 63, 4758, 63, 3282, 8, 277, 304, 267, 3743, 12, 16808, 275, 291, 423, 826, 63, 4758, 63, 460, 63, 15918, 342, 398, 3743, 63, 694, 275, 291, 14, 19132, 1182, 283, 10057, 7, 1182, 2295, 14, 840, 2533, 63, 22212, 267, 291, 14, 629, 8, 2190, 14, 694, 12, 3743, 63, 694, 9, 267, 291, 14, 629, 8, 2190, 14, 2609, 63, 15918, 63, 694, 12, 586, 3743, 63, 694, 1182, 283, 2609, 13, 15918, 358, 267, 291, 14, 629, 8, 2190, 14, 15918, 83, 63, 694, 12, 586, 3743, 63, 694, 1182, 283, 15918, 83, 358, 267, 291, 14, 629, 8, 2190, 14, 3711, 63, 515, 12, 586, 3743, 63, 694, 1182, 283, 3711, 14, 5963, 358, 267, 291, 14, 629, 8, 288, 3743, 14, 2609, 63, 15918, 63, 515, 12, 288, 3743, 63, 694, 1182, 283, 2609, 13, 15918, 7, 1182, 283, 2609, 13, 15918, 14, 5963, 358, 267, 291, 14, 629, 8, 2190, 14, 2232, 63, 4758, 63, 515, 12, 586, 3743, 63, 694, 1182, 283, 2232, 13, 4758, 14, 5963, 358, 267, 291, 14, 629, 8, 2190, 14, 2764, 63, 888, 63, 515, 12, 586, 3743, 63, 694, 1182, 1987, 1251, 14525, 1399, 7, 1182, 283, 888, 14, 5963, 358, 398, 16808, 63, 694, 275, 3743, 14, 15918, 83, 63, 694, 1182, 2295, 14, 840, 2533, 63, 23536, 21754, 267, 291, 14, 3436, 8, 15918, 14, 4758, 12, 3743, 9, 267, 291, 14, 629, 8, 15918, 14, 15918, 63, 354, 12, 2295, 14, 840, 2533, 63, 23536, 21754, 9, 267, 291, 14, 629, 8, 15918, 14, 694, 12, 16808, 63, 694, 9, 267, 291, 14, 629, 8, 15918, 14, 15918, 63, 4758, 63, 515, 12, 586, 16808, 63, 694, 1182, 283, 15918, 13, 4758, 14, 5963, 358, 267, 291, 14, 629, 8, 15918, 14, 3711, 63, 515, 12, 586, 16808, 63, 694, 1182, 283, 3711, 14, 5963, 358, 267, 291, 14, 629, 8, 15918, 14, 15918, 63, 515, 12, 586, 16808, 63, 694, 1182, 283, 15918, 7, 1182, 283, 15918, 14, 5963, 358, 339, 347, 511, 63, 5963, 63, 1725, 8, 277, 304, 267, 3743, 12, 16808, 275, 291, 423, 826, 63, 4758, 63, 460, 63, 15918, 342, 267, 3743, 63, 694, 275, 291, 14, 19132, 1182, 283, 10057, 7, 1182, 2295, 14, 840, 2533, 63, 22212, 267, 16808, 63, 694, 275, 3743, 14, 15918, 83, 63, 694, 1182, 2295, 14, 840, 2533, 63, 23536, 21754, 267, 3743, 14, 2764, 63, 888, 63, 515, 14, 3475, 1252, 8215, 63, 80, 342, 398, 2897, 63, 1725, 275, 359, 288, 661, 3711, 297, 3743, 63, 694, 1182, 283, 3711, 14, 5963, 659, 288, 661, 2232, 63, 4758, 297, 3743, 63, 694, 1182, 283, 2232, 13, 4758, 14, 5963, 659, 288, 661, 2609, 63, 15918, 297, 1467, 3743, 63, 694, 1182, 283, 2609, 13, 15918, 7, 1182, 283, 2609, 13, 15918, 14, 5963, 659, 288, 661, 2764, 63, 888, 297, 3743, 63, 694, 1182, 1987, 1251, 14525, 1399, 7, 1182, 283, 888, 14, 5963, 659, 267, 1622, 267, 16808, 63, 1725, 275, 359, 288, 661, 3711, 297, 16808, 63, 694, 1182, 283, 3711, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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091302/Lib/difflib.py
737
82544
#! /usr/bin/env python3 """ Module difflib -- helpers for computing deltas between objects. Function get_close_matches(word, possibilities, n=3, cutoff=0.6): Use SequenceMatcher to return list of the best "good enough" matches. Function context_diff(a, b): For two lists of strings, return a delta in context diff format. Function ndiff(a, b): Return a delta: the difference between `a` and `b` (lists of strings). Function restore(delta, which): Return one of the two sequences that generated an ndiff delta. Function unified_diff(a, b): For two lists of strings, return a delta in unified diff format. Class SequenceMatcher: A flexible class for comparing pairs of sequences of any type. Class Differ: For producing human-readable deltas from sequences of lines of text. Class HtmlDiff: For producing HTML side by side comparison with change highlights. """ __all__ = ['get_close_matches', 'ndiff', 'restore', 'SequenceMatcher', 'Differ','IS_CHARACTER_JUNK', 'IS_LINE_JUNK', 'context_diff', 'unified_diff', 'HtmlDiff', 'Match'] import warnings import heapq from collections import namedtuple as _namedtuple Match = _namedtuple('Match', 'a b size') def _calculate_ratio(matches, length): if length: return 2.0 * matches / length return 1.0 class SequenceMatcher: """ SequenceMatcher is a flexible class for comparing pairs of sequences of any type, so long as the sequence elements are hashable. The basic algorithm predates, and is a little fancier than, an algorithm published in the late 1980's by Ratcliff and Obershelp under the hyperbolic name "gestalt pattern matching". The basic idea is to find the longest contiguous matching subsequence that contains no "junk" elements (R-O doesn't address junk). The same idea is then applied recursively to the pieces of the sequences to the left and to the right of the matching subsequence. This does not yield minimal edit sequences, but does tend to yield matches that "look right" to people. SequenceMatcher tries to compute a "human-friendly diff" between two sequences. Unlike e.g. UNIX(tm) diff, the fundamental notion is the longest *contiguous* & junk-free matching subsequence. That's what catches peoples' eyes. The Windows(tm) windiff has another interesting notion, pairing up elements that appear uniquely in each sequence. That, and the method here, appear to yield more intuitive difference reports than does diff. This method appears to be the least vulnerable to synching up on blocks of "junk lines", though (like blank lines in ordinary text files, or maybe "<P>" lines in HTML files). That may be because this is the only method of the 3 that has a *concept* of "junk" <wink>. Example, comparing two strings, and considering blanks to be "junk": >>> s = SequenceMatcher(lambda x: x == " ", ... "private Thread currentThread;", ... "private volatile Thread currentThread;") >>> .ratio() returns a float in [0, 1], measuring the "similarity" of the sequences. As a rule of thumb, a .ratio() value over 0.6 means the sequences are close matches: >>> print(round(s.ratio(), 3)) 0.866 >>> If you're only interested in where the sequences match, .get_matching_blocks() is handy: >>> for block in s.get_matching_blocks(): ... print("a[%d] and b[%d] match for %d elements" % block) a[0] and b[0] match for 8 elements a[8] and b[17] match for 21 elements a[29] and b[38] match for 0 elements Note that the last tuple returned by .get_matching_blocks() is always a dummy, (len(a), len(b), 0), and this is the only case in which the last tuple element (number of elements matched) is 0. If you want to know how to change the first sequence into the second, use .get_opcodes(): >>> for opcode in s.get_opcodes(): ... print("%6s a[%d:%d] b[%d:%d]" % opcode) equal a[0:8] b[0:8] insert a[8:8] b[8:17] equal a[8:29] b[17:38] See the Differ class for a fancy human-friendly file differencer, which uses SequenceMatcher both to compare sequences of lines, and to compare sequences of characters within similar (near-matching) lines. See also function get_close_matches() in this module, which shows how simple code building on SequenceMatcher can be used to do useful work. Timing: Basic R-O is cubic time worst case and quadratic time expected case. SequenceMatcher is quadratic time for the worst case and has expected-case behavior dependent in a complicated way on how many elements the sequences have in common; best case time is linear. Methods: __init__(isjunk=None, a='', b='') Construct a SequenceMatcher. set_seqs(a, b) Set the two sequences to be compared. set_seq1(a) Set the first sequence to be compared. set_seq2(b) Set the second sequence to be compared. find_longest_match(alo, ahi, blo, bhi) Find longest matching block in a[alo:ahi] and b[blo:bhi]. get_matching_blocks() Return list of triples describing matching subsequences. get_opcodes() Return list of 5-tuples describing how to turn a into b. ratio() Return a measure of the sequences' similarity (float in [0,1]). quick_ratio() Return an upper bound on .ratio() relatively quickly. real_quick_ratio() Return an upper bound on ratio() very quickly. """ def __init__(self, isjunk=None, a='', b='', autojunk=True): """Construct a SequenceMatcher. Optional arg isjunk is None (the default), or a one-argument function that takes a sequence element and returns true iff the element is junk. None is equivalent to passing "lambda x: 0", i.e. no elements are considered to be junk. For example, pass lambda x: x in " \\t" if you're comparing lines as sequences of characters, and don't want to synch up on blanks or hard tabs. Optional arg a is the first of two sequences to be compared. By default, an empty string. The elements of a must be hashable. See also .set_seqs() and .set_seq1(). Optional arg b is the second of two sequences to be compared. By default, an empty string. The elements of b must be hashable. See also .set_seqs() and .set_seq2(). Optional arg autojunk should be set to False to disable the "automatic junk heuristic" that treats popular elements as junk (see module documentation for more information). """ # Members: # a # first sequence # b # second sequence; differences are computed as "what do # we need to do to 'a' to change it into 'b'?" # b2j # for x in b, b2j[x] is a list of the indices (into b) # at which x appears; junk and popular elements do not appear # fullbcount # for x in b, fullbcount[x] == the number of times x # appears in b; only materialized if really needed (used # only for computing quick_ratio()) # matching_blocks # a list of (i, j, k) triples, where a[i:i+k] == b[j:j+k]; # ascending & non-overlapping in i and in j; terminated by # a dummy (len(a), len(b), 0) sentinel # opcodes # a list of (tag, i1, i2, j1, j2) tuples, where tag is # one of # 'replace' a[i1:i2] should be replaced by b[j1:j2] # 'delete' a[i1:i2] should be deleted # 'insert' b[j1:j2] should be inserted # 'equal' a[i1:i2] == b[j1:j2] # isjunk # a user-supplied function taking a sequence element and # returning true iff the element is "junk" -- this has # subtle but helpful effects on the algorithm, which I'll # get around to writing up someday <0.9 wink>. # DON'T USE! Only __chain_b uses this. Use "in self.bjunk". # bjunk # the items in b for which isjunk is True. # bpopular # nonjunk items in b treated as junk by the heuristic (if used). self.isjunk = isjunk self.a = self.b = None self.autojunk = autojunk self.set_seqs(a, b) def set_seqs(self, a, b): """Set the two sequences to be compared. >>> s = SequenceMatcher() >>> s.set_seqs("abcd", "bcde") >>> s.ratio() 0.75 """ self.set_seq1(a) self.set_seq2(b) def set_seq1(self, a): """Set the first sequence to be compared. The second sequence to be compared is not changed. >>> s = SequenceMatcher(None, "abcd", "bcde") >>> s.ratio() 0.75 >>> s.set_seq1("bcde") >>> s.ratio() 1.0 >>> SequenceMatcher computes and caches detailed information about the second sequence, so if you want to compare one sequence S against many sequences, use .set_seq2(S) once and call .set_seq1(x) repeatedly for each of the other sequences. See also set_seqs() and set_seq2(). """ if a is self.a: return self.a = a self.matching_blocks = self.opcodes = None def set_seq2(self, b): """Set the second sequence to be compared. The first sequence to be compared is not changed. >>> s = SequenceMatcher(None, "abcd", "bcde") >>> s.ratio() 0.75 >>> s.set_seq2("abcd") >>> s.ratio() 1.0 >>> SequenceMatcher computes and caches detailed information about the second sequence, so if you want to compare one sequence S against many sequences, use .set_seq2(S) once and call .set_seq1(x) repeatedly for each of the other sequences. See also set_seqs() and set_seq1(). """ if b is self.b: return self.b = b self.matching_blocks = self.opcodes = None self.fullbcount = None self.__chain_b() # For each element x in b, set b2j[x] to a list of the indices in # b where x appears; the indices are in increasing order; note that # the number of times x appears in b is len(b2j[x]) ... # when self.isjunk is defined, junk elements don't show up in this # map at all, which stops the central find_longest_match method # from starting any matching block at a junk element ... # b2j also does not contain entries for "popular" elements, meaning # elements that account for more than 1 + 1% of the total elements, and # when the sequence is reasonably large (>= 200 elements); this can # be viewed as an adaptive notion of semi-junk, and yields an enormous # speedup when, e.g., comparing program files with hundreds of # instances of "return NULL;" ... # note that this is only called when b changes; so for cross-product # kinds of matches, it's best to call set_seq2 once, then set_seq1 # repeatedly def __chain_b(self): # Because isjunk is a user-defined (not C) function, and we test # for junk a LOT, it's important to minimize the number of calls. # Before the tricks described here, __chain_b was by far the most # time-consuming routine in the whole module! If anyone sees # Jim Roskind, thank him again for profile.py -- I never would # have guessed that. # The first trick is to build b2j ignoring the possibility # of junk. I.e., we don't call isjunk at all yet. Throwing # out the junk later is much cheaper than building b2j "right" # from the start. b = self.b self.b2j = b2j = {} for i, elt in enumerate(b): indices = b2j.setdefault(elt, []) indices.append(i) # Purge junk elements self.bjunk = junk = set() isjunk = self.isjunk if isjunk: for elt in b2j.keys(): if isjunk(elt): junk.add(elt) for elt in junk: # separate loop avoids separate list of keys del b2j[elt] # Purge popular elements that are not junk self.bpopular = popular = set() n = len(b) if self.autojunk and n >= 200: ntest = n // 100 + 1 for elt, idxs in b2j.items(): if len(idxs) > ntest: popular.add(elt) for elt in popular: # ditto; as fast for 1% deletion del b2j[elt] def isbjunk(self, item): "Deprecated; use 'item in SequenceMatcher().bjunk'." warnings.warn("'SequenceMatcher().isbjunk(item)' is deprecated;\n" "use 'item in SMinstance.bjunk' instead.", DeprecationWarning, 2) return item in self.bjunk def isbpopular(self, item): "Deprecated; use 'item in SequenceMatcher().bpopular'." warnings.warn("'SequenceMatcher().isbpopular(item)' is deprecated;\n" "use 'item in SMinstance.bpopular' instead.", DeprecationWarning, 2) return item in self.bpopular def find_longest_match(self, alo, ahi, blo, bhi): """Find longest matching block in a[alo:ahi] and b[blo:bhi]. If isjunk is not defined: Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where alo <= i <= i+k <= ahi blo <= j <= j+k <= bhi and for all (i',j',k') meeting those conditions, k >= k' i <= i' and if i == i', j <= j' In other words, of all maximal matching blocks, return one that starts earliest in a, and of all those maximal matching blocks that start earliest in a, return the one that starts earliest in b. >>> s = SequenceMatcher(None, " abcd", "abcd abcd") >>> s.find_longest_match(0, 5, 0, 9) Match(a=0, b=4, size=5) If isjunk is defined, first the longest matching block is determined as above, but with the additional restriction that no junk element appears in the block. Then that block is extended as far as possible by matching (only) junk elements on both sides. So the resulting block never matches on junk except as identical junk happens to be adjacent to an "interesting" match. Here's the same example as before, but considering blanks to be junk. That prevents " abcd" from matching the " abcd" at the tail end of the second sequence directly. Instead only the "abcd" can match, and matches the leftmost "abcd" in the second sequence: >>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd") >>> s.find_longest_match(0, 5, 0, 9) Match(a=1, b=0, size=4) If no blocks match, return (alo, blo, 0). >>> s = SequenceMatcher(None, "ab", "c") >>> s.find_longest_match(0, 2, 0, 1) Match(a=0, b=0, size=0) """ # CAUTION: stripping common prefix or suffix would be incorrect. # E.g., # ab # acab # Longest matching block is "ab", but if common prefix is # stripped, it's "a" (tied with "b"). UNIX(tm) diff does so # strip, so ends up claiming that ab is changed to acab by # inserting "ca" in the middle. That's minimal but unintuitive: # "it's obvious" that someone inserted "ac" at the front. # Windiff ends up at the same place as diff, but by pairing up # the unique 'b's and then matching the first two 'a's. a, b, b2j, isbjunk = self.a, self.b, self.b2j, self.bjunk.__contains__ besti, bestj, bestsize = alo, blo, 0 # find longest junk-free match # during an iteration of the loop, j2len[j] = length of longest # junk-free match ending with a[i-1] and b[j] j2len = {} nothing = [] for i in range(alo, ahi): # look at all instances of a[i] in b; note that because # b2j has no junk keys, the loop is skipped if a[i] is junk j2lenget = j2len.get newj2len = {} for j in b2j.get(a[i], nothing): # a[i] matches b[j] if j < blo: continue if j >= bhi: break k = newj2len[j] = j2lenget(j-1, 0) + 1 if k > bestsize: besti, bestj, bestsize = i-k+1, j-k+1, k j2len = newj2len # Extend the best by non-junk elements on each end. In particular, # "popular" non-junk elements aren't in b2j, which greatly speeds # the inner loop above, but also means "the best" match so far # doesn't contain any junk *or* popular non-junk elements. while besti > alo and bestj > blo and \ not isbjunk(b[bestj-1]) and \ a[besti-1] == b[bestj-1]: besti, bestj, bestsize = besti-1, bestj-1, bestsize+1 while besti+bestsize < ahi and bestj+bestsize < bhi and \ not isbjunk(b[bestj+bestsize]) and \ a[besti+bestsize] == b[bestj+bestsize]: bestsize += 1 # Now that we have a wholly interesting match (albeit possibly # empty!), we may as well suck up the matching junk on each # side of it too. Can't think of a good reason not to, and it # saves post-processing the (possibly considerable) expense of # figuring out what to do with it. In the case of an empty # interesting match, this is clearly the right thing to do, # because no other kind of match is possible in the regions. while besti > alo and bestj > blo and \ isbjunk(b[bestj-1]) and \ a[besti-1] == b[bestj-1]: besti, bestj, bestsize = besti-1, bestj-1, bestsize+1 while besti+bestsize < ahi and bestj+bestsize < bhi and \ isbjunk(b[bestj+bestsize]) and \ a[besti+bestsize] == b[bestj+bestsize]: bestsize = bestsize + 1 return Match(besti, bestj, bestsize) def get_matching_blocks(self): """Return list of triples describing matching subsequences. Each triple is of the form (i, j, n), and means that a[i:i+n] == b[j:j+n]. The triples are monotonically increasing in i and in j. New in Python 2.5, it's also guaranteed that if (i, j, n) and (i', j', n') are adjacent triples in the list, and the second is not the last triple in the list, then i+n != i' or j+n != j'. IOW, adjacent triples never describe adjacent equal blocks. The last triple is a dummy, (len(a), len(b), 0), and is the only triple with n==0. >>> s = SequenceMatcher(None, "abxcd", "abcd") >>> list(s.get_matching_blocks()) [Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)] """ if self.matching_blocks is not None: return self.matching_blocks la, lb = len(self.a), len(self.b) # This is most naturally expressed as a recursive algorithm, but # at least one user bumped into extreme use cases that exceeded # the recursion limit on their box. So, now we maintain a list # ('queue`) of blocks we still need to look at, and append partial # results to `matching_blocks` in a loop; the matches are sorted # at the end. queue = [(0, la, 0, lb)] matching_blocks = [] while queue: alo, ahi, blo, bhi = queue.pop() i, j, k = x = self.find_longest_match(alo, ahi, blo, bhi) # a[alo:i] vs b[blo:j] unknown # a[i:i+k] same as b[j:j+k] # a[i+k:ahi] vs b[j+k:bhi] unknown if k: # if k is 0, there was no matching block matching_blocks.append(x) if alo < i and blo < j: queue.append((alo, i, blo, j)) if i+k < ahi and j+k < bhi: queue.append((i+k, ahi, j+k, bhi)) matching_blocks.sort() # It's possible that we have adjacent equal blocks in the # matching_blocks list now. Starting with 2.5, this code was added # to collapse them. i1 = j1 = k1 = 0 non_adjacent = [] for i2, j2, k2 in matching_blocks: # Is this block adjacent to i1, j1, k1? if i1 + k1 == i2 and j1 + k1 == j2: # Yes, so collapse them -- this just increases the length of # the first block by the length of the second, and the first # block so lengthened remains the block to compare against. k1 += k2 else: # Not adjacent. Remember the first block (k1==0 means it's # the dummy we started with), and make the second block the # new block to compare against. if k1: non_adjacent.append((i1, j1, k1)) i1, j1, k1 = i2, j2, k2 if k1: non_adjacent.append((i1, j1, k1)) non_adjacent.append( (la, lb, 0) ) self.matching_blocks = non_adjacent return map(Match._make, self.matching_blocks) def get_opcodes(self): """Return list of 5-tuples describing how to turn a into b. Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the tuple preceding it, and likewise for j1 == the previous j2. The tags are strings, with these meanings: 'replace': a[i1:i2] should be replaced by b[j1:j2] 'delete': a[i1:i2] should be deleted. Note that j1==j2 in this case. 'insert': b[j1:j2] should be inserted at a[i1:i1]. Note that i1==i2 in this case. 'equal': a[i1:i2] == b[j1:j2] >>> a = "qabxcd" >>> b = "abycdf" >>> s = SequenceMatcher(None, a, b) >>> for tag, i1, i2, j1, j2 in s.get_opcodes(): ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" % ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))) delete a[0:1] (q) b[0:0] () equal a[1:3] (ab) b[0:2] (ab) replace a[3:4] (x) b[2:3] (y) equal a[4:6] (cd) b[3:5] (cd) insert a[6:6] () b[5:6] (f) """ if self.opcodes is not None: return self.opcodes i = j = 0 self.opcodes = answer = [] for ai, bj, size in self.get_matching_blocks(): # invariant: we've pumped out correct diffs to change # a[:i] into b[:j], and the next matching block is # a[ai:ai+size] == b[bj:bj+size]. So we need to pump # out a diff to change a[i:ai] into b[j:bj], pump out # the matching block, and move (i,j) beyond the match tag = '' if i < ai and j < bj: tag = 'replace' elif i < ai: tag = 'delete' elif j < bj: tag = 'insert' if tag: answer.append( (tag, i, ai, j, bj) ) i, j = ai+size, bj+size # the list of matching blocks is terminated by a # sentinel with size 0 if size: answer.append( ('equal', ai, i, bj, j) ) return answer def get_grouped_opcodes(self, n=3): """ Isolate change clusters by eliminating ranges with no changes. Return a generator of groups with up to n lines of context. Each group is in the same format as returned by get_opcodes(). >>> from pprint import pprint >>> a = list(map(str, range(1,40))) >>> b = a[:] >>> b[8:8] = ['i'] # Make an insertion >>> b[20] += 'x' # Make a replacement >>> b[23:28] = [] # Make a deletion >>> b[30] += 'y' # Make another replacement >>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes())) [[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)], [('equal', 16, 19, 17, 20), ('replace', 19, 20, 20, 21), ('equal', 20, 22, 21, 23), ('delete', 22, 27, 23, 23), ('equal', 27, 30, 23, 26)], [('equal', 31, 34, 27, 30), ('replace', 34, 35, 30, 31), ('equal', 35, 38, 31, 34)]] """ codes = self.get_opcodes() if not codes: codes = [("equal", 0, 1, 0, 1)] # Fixup leading and trailing groups if they show no changes. if codes[0][0] == 'equal': tag, i1, i2, j1, j2 = codes[0] codes[0] = tag, max(i1, i2-n), i2, max(j1, j2-n), j2 if codes[-1][0] == 'equal': tag, i1, i2, j1, j2 = codes[-1] codes[-1] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n) nn = n + n group = [] for tag, i1, i2, j1, j2 in codes: # End the current group and start a new one whenever # there is a large range with no changes. if tag == 'equal' and i2-i1 > nn: group.append((tag, i1, min(i2, i1+n), j1, min(j2, j1+n))) yield group group = [] i1, j1 = max(i1, i2-n), max(j1, j2-n) group.append((tag, i1, i2, j1 ,j2)) if group and not (len(group)==1 and group[0][0] == 'equal'): yield group def ratio(self): """Return a measure of the sequences' similarity (float in [0,1]). Where T is the total number of elements in both sequences, and M is the number of matches, this is 2.0*M / T. Note that this is 1 if the sequences are identical, and 0 if they have nothing in common. .ratio() is expensive to compute if you haven't already computed .get_matching_blocks() or .get_opcodes(), in which case you may want to try .quick_ratio() or .real_quick_ratio() first to get an upper bound. >>> s = SequenceMatcher(None, "abcd", "bcde") >>> s.ratio() 0.75 >>> s.quick_ratio() 0.75 >>> s.real_quick_ratio() 1.0 """ matches = sum(triple[-1] for triple in self.get_matching_blocks()) return _calculate_ratio(matches, len(self.a) + len(self.b)) def quick_ratio(self): """Return an upper bound on ratio() relatively quickly. This isn't defined beyond that it is an upper bound on .ratio(), and is faster to compute. """ # viewing a and b as multisets, set matches to the cardinality # of their intersection; this counts the number of matches # without regard to order, so is clearly an upper bound if self.fullbcount is None: self.fullbcount = fullbcount = {} for elt in self.b: fullbcount[elt] = fullbcount.get(elt, 0) + 1 fullbcount = self.fullbcount # avail[x] is the number of times x appears in 'b' less the # number of times we've seen it in 'a' so far ... kinda avail = {} availhas, matches = avail.__contains__, 0 for elt in self.a: if availhas(elt): numb = avail[elt] else: numb = fullbcount.get(elt, 0) avail[elt] = numb - 1 if numb > 0: matches = matches + 1 return _calculate_ratio(matches, len(self.a) + len(self.b)) def real_quick_ratio(self): """Return an upper bound on ratio() very quickly. This isn't defined beyond that it is an upper bound on .ratio(), and is faster to compute than either .ratio() or .quick_ratio(). """ la, lb = len(self.a), len(self.b) # can't have more matches than the number of elements in the # shorter sequence return _calculate_ratio(min(la, lb), la + lb) def get_close_matches(word, possibilities, n=3, cutoff=0.6): """Use SequenceMatcher to return list of the best "good enough" matches. word is a sequence for which close matches are desired (typically a string). possibilities is a list of sequences against which to match word (typically a list of strings). Optional arg n (default 3) is the maximum number of close matches to return. n must be > 0. Optional arg cutoff (default 0.6) is a float in [0, 1]. Possibilities that don't score at least that similar to word are ignored. The best (no more than n) matches among the possibilities are returned in a list, sorted by similarity score, most similar first. >>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"]) ['apple', 'ape'] >>> import keyword as _keyword >>> get_close_matches("wheel", _keyword.kwlist) ['while'] >>> get_close_matches("Apple", _keyword.kwlist) [] >>> get_close_matches("accept", _keyword.kwlist) ['except'] """ if not n > 0: raise ValueError("n must be > 0: %r" % (n,)) if not 0.0 <= cutoff <= 1.0: raise ValueError("cutoff must be in [0.0, 1.0]: %r" % (cutoff,)) result = [] s = SequenceMatcher() s.set_seq2(word) for x in possibilities: s.set_seq1(x) if s.real_quick_ratio() >= cutoff and \ s.quick_ratio() >= cutoff and \ s.ratio() >= cutoff: result.append((s.ratio(), x)) # Move the best scorers to head of list result = heapq.nlargest(n, result) # Strip scores for the best n matches return [x for score, x in result] def _count_leading(line, ch): """ Return number of `ch` characters at the start of `line`. Example: >>> _count_leading(' abc', ' ') 3 """ i, n = 0, len(line) while i < n and line[i] == ch: i += 1 return i class Differ: r""" Differ is a class for comparing sequences of lines of text, and producing human-readable differences or deltas. Differ uses SequenceMatcher both to compare sequences of lines, and to compare sequences of characters within similar (near-matching) lines. Each line of a Differ delta begins with a two-letter code: '- ' line unique to sequence 1 '+ ' line unique to sequence 2 ' ' line common to both sequences '? ' line not present in either input sequence Lines beginning with '? ' attempt to guide the eye to intraline differences, and were not present in either input sequence. These lines can be confusing if the sequences contain tab characters. Note that Differ makes no claim to produce a *minimal* diff. To the contrary, minimal diffs are often counter-intuitive, because they synch up anywhere possible, sometimes accidental matches 100 pages apart. Restricting synch points to contiguous matches preserves some notion of locality, at the occasional cost of producing a longer diff. Example: Comparing two texts. First we set up the texts, sequences of individual single-line strings ending with newlines (such sequences can also be obtained from the `readlines()` method of file-like objects): >>> text1 = ''' 1. Beautiful is better than ugly. ... 2. Explicit is better than implicit. ... 3. Simple is better than complex. ... 4. Complex is better than complicated. ... '''.splitlines(keepends=True) >>> len(text1) 4 >>> text1[0][-1] '\n' >>> text2 = ''' 1. Beautiful is better than ugly. ... 3. Simple is better than complex. ... 4. Complicated is better than complex. ... 5. Flat is better than nested. ... '''.splitlines(keepends=True) Next we instantiate a Differ object: >>> d = Differ() Note that when instantiating a Differ object we may pass functions to filter out line and character 'junk'. See Differ.__init__ for details. Finally, we compare the two: >>> result = list(d.compare(text1, text2)) 'result' is a list of strings, so let's pretty-print it: >>> from pprint import pprint as _pprint >>> _pprint(result) [' 1. Beautiful is better than ugly.\n', '- 2. Explicit is better than implicit.\n', '- 3. Simple is better than complex.\n', '+ 3. Simple is better than complex.\n', '? ++\n', '- 4. Complex is better than complicated.\n', '? ^ ---- ^\n', '+ 4. Complicated is better than complex.\n', '? ++++ ^ ^\n', '+ 5. Flat is better than nested.\n'] As a single multi-line string it looks like this: >>> print(''.join(result), end="") 1. Beautiful is better than ugly. - 2. Explicit is better than implicit. - 3. Simple is better than complex. + 3. Simple is better than complex. ? ++ - 4. Complex is better than complicated. ? ^ ---- ^ + 4. Complicated is better than complex. ? ++++ ^ ^ + 5. Flat is better than nested. Methods: __init__(linejunk=None, charjunk=None) Construct a text differencer, with optional filters. compare(a, b) Compare two sequences of lines; generate the resulting delta. """ def __init__(self, linejunk=None, charjunk=None): """ Construct a text differencer, with optional filters. The two optional keyword parameters are for filter functions: - `linejunk`: A function that should accept a single string argument, and return true iff the string is junk. The module-level function `IS_LINE_JUNK` may be used to filter out lines without visible characters, except for at most one splat ('#'). It is recommended to leave linejunk None; as of Python 2.3, the underlying SequenceMatcher class has grown an adaptive notion of "noise" lines that's better than any static definition the author has ever been able to craft. - `charjunk`: A function that should accept a string of length 1. The module-level function `IS_CHARACTER_JUNK` may be used to filter out whitespace characters (a blank or tab; **note**: bad idea to include newline in this!). Use of IS_CHARACTER_JUNK is recommended. """ self.linejunk = linejunk self.charjunk = charjunk def compare(self, a, b): r""" Compare two sequences of lines; generate the resulting delta. Each sequence must contain individual single-line strings ending with newlines. Such sequences can be obtained from the `readlines()` method of file-like objects. The delta generated also consists of newline- terminated strings, ready to be printed as-is via the writeline() method of a file-like object. Example: >>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True), ... 'ore\ntree\nemu\n'.splitlines(True))), ... end="") - one ? ^ + ore ? ^ - two - three ? - + tree + emu """ cruncher = SequenceMatcher(self.linejunk, a, b) for tag, alo, ahi, blo, bhi in cruncher.get_opcodes(): if tag == 'replace': g = self._fancy_replace(a, alo, ahi, b, blo, bhi) elif tag == 'delete': g = self._dump('-', a, alo, ahi) elif tag == 'insert': g = self._dump('+', b, blo, bhi) elif tag == 'equal': g = self._dump(' ', a, alo, ahi) else: raise ValueError('unknown tag %r' % (tag,)) for line in g: yield line def _dump(self, tag, x, lo, hi): """Generate comparison results for a same-tagged range.""" for i in range(lo, hi): yield '%s %s' % (tag, x[i]) def _plain_replace(self, a, alo, ahi, b, blo, bhi): assert alo < ahi and blo < bhi # dump the shorter block first -- reduces the burden on short-term # memory if the blocks are of very different sizes if bhi - blo < ahi - alo: first = self._dump('+', b, blo, bhi) second = self._dump('-', a, alo, ahi) else: first = self._dump('-', a, alo, ahi) second = self._dump('+', b, blo, bhi) for g in first, second: for line in g: yield line def _fancy_replace(self, a, alo, ahi, b, blo, bhi): r""" When replacing one block of lines with another, search the blocks for *similar* lines; the best-matching pair (if any) is used as a synch point, and intraline difference marking is done on the similar pair. Lots of work, but often worth it. Example: >>> d = Differ() >>> results = d._fancy_replace(['abcDefghiJkl\n'], 0, 1, ... ['abcdefGhijkl\n'], 0, 1) >>> print(''.join(results), end="") - abcDefghiJkl ? ^ ^ ^ + abcdefGhijkl ? ^ ^ ^ """ # don't synch up unless the lines have a similarity score of at # least cutoff; best_ratio tracks the best score seen so far best_ratio, cutoff = 0.74, 0.75 cruncher = SequenceMatcher(self.charjunk) eqi, eqj = None, None # 1st indices of equal lines (if any) # search for the pair that matches best without being identical # (identical lines must be junk lines, & we don't want to synch up # on junk -- unless we have to) for j in range(blo, bhi): bj = b[j] cruncher.set_seq2(bj) for i in range(alo, ahi): ai = a[i] if ai == bj: if eqi is None: eqi, eqj = i, j continue cruncher.set_seq1(ai) # computing similarity is expensive, so use the quick # upper bounds first -- have seen this speed up messy # compares by a factor of 3. # note that ratio() is only expensive to compute the first # time it's called on a sequence pair; the expensive part # of the computation is cached by cruncher if cruncher.real_quick_ratio() > best_ratio and \ cruncher.quick_ratio() > best_ratio and \ cruncher.ratio() > best_ratio: best_ratio, best_i, best_j = cruncher.ratio(), i, j if best_ratio < cutoff: # no non-identical "pretty close" pair if eqi is None: # no identical pair either -- treat it as a straight replace for line in self._plain_replace(a, alo, ahi, b, blo, bhi): yield line return # no close pair, but an identical pair -- synch up on that best_i, best_j, best_ratio = eqi, eqj, 1.0 else: # there's a close pair, so forget the identical pair (if any) eqi = None # a[best_i] very similar to b[best_j]; eqi is None iff they're not # identical # pump out diffs from before the synch point for line in self._fancy_helper(a, alo, best_i, b, blo, best_j): yield line # do intraline marking on the synch pair aelt, belt = a[best_i], b[best_j] if eqi is None: # pump out a '-', '?', '+', '?' quad for the synched lines atags = btags = "" cruncher.set_seqs(aelt, belt) for tag, ai1, ai2, bj1, bj2 in cruncher.get_opcodes(): la, lb = ai2 - ai1, bj2 - bj1 if tag == 'replace': atags += '^' * la btags += '^' * lb elif tag == 'delete': atags += '-' * la elif tag == 'insert': btags += '+' * lb elif tag == 'equal': atags += ' ' * la btags += ' ' * lb else: raise ValueError('unknown tag %r' % (tag,)) for line in self._qformat(aelt, belt, atags, btags): yield line else: # the synch pair is identical yield ' ' + aelt # pump out diffs from after the synch point for line in self._fancy_helper(a, best_i+1, ahi, b, best_j+1, bhi): yield line def _fancy_helper(self, a, alo, ahi, b, blo, bhi): g = [] if alo < ahi: if blo < bhi: g = self._fancy_replace(a, alo, ahi, b, blo, bhi) else: g = self._dump('-', a, alo, ahi) elif blo < bhi: g = self._dump('+', b, blo, bhi) for line in g: yield line def _qformat(self, aline, bline, atags, btags): r""" Format "?" output and deal with leading tabs. Example: >>> d = Differ() >>> results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n', ... ' ^ ^ ^ ', ' ^ ^ ^ ') >>> for line in results: print(repr(line)) ... '- \tabcDefghiJkl\n' '? \t ^ ^ ^\n' '+ \tabcdefGhijkl\n' '? \t ^ ^ ^\n' """ # Can hurt, but will probably help most of the time. common = min(_count_leading(aline, "\t"), _count_leading(bline, "\t")) common = min(common, _count_leading(atags[:common], " ")) common = min(common, _count_leading(btags[:common], " ")) atags = atags[common:].rstrip() btags = btags[common:].rstrip() yield "- " + aline if atags: yield "? %s%s\n" % ("\t" * common, atags) yield "+ " + bline if btags: yield "? %s%s\n" % ("\t" * common, btags) # With respect to junk, an earlier version of ndiff simply refused to # *start* a match with a junk element. The result was cases like this: # before: private Thread currentThread; # after: private volatile Thread currentThread; # If you consider whitespace to be junk, the longest contiguous match # not starting with junk is "e Thread currentThread". So ndiff reported # that "e volatil" was inserted between the 't' and the 'e' in "private". # While an accurate view, to people that's absurd. The current version # looks for matching blocks that are entirely junk-free, then extends the # longest one of those as far as possible but only with matching junk. # So now "currentThread" is matched, then extended to suck up the # preceding blank; then "private" is matched, and extended to suck up the # following blank; then "Thread" is matched; and finally ndiff reports # that "volatile " was inserted before "Thread". The only quibble # remaining is that perhaps it was really the case that " volatile" # was inserted after "private". I can live with that <wink>. import re def IS_LINE_JUNK(line, pat=re.compile(r"\s*#?\s*$").match): r""" Return 1 for ignorable line: iff `line` is blank or contains a single '#'. Examples: >>> IS_LINE_JUNK('\n') True >>> IS_LINE_JUNK(' # \n') True >>> IS_LINE_JUNK('hello\n') False """ return pat(line) is not None def IS_CHARACTER_JUNK(ch, ws=" \t"): r""" Return 1 for ignorable character: iff `ch` is a space or tab. Examples: >>> IS_CHARACTER_JUNK(' ') True >>> IS_CHARACTER_JUNK('\t') True >>> IS_CHARACTER_JUNK('\n') False >>> IS_CHARACTER_JUNK('x') False """ return ch in ws ######################################################################## ### Unified Diff ######################################################################## def _format_range_unified(start, stop): 'Convert range to the "ed" format' # Per the diff spec at http://www.unix.org/single_unix_specification/ beginning = start + 1 # lines start numbering with one length = stop - start if length == 1: return '{}'.format(beginning) if not length: beginning -= 1 # empty ranges begin at line just before the range return '{},{}'.format(beginning, length) def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'): r""" Compare two sequences of lines; generate the delta as a unified diff. Unified diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which defaults to three. By default, the diff control lines (those with ---, +++, or @@) are created with a trailing newline. This is helpful so that inputs created from file.readlines() result in diffs that are suitable for file.writelines() since both the inputs and outputs have trailing newlines. For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free. The unidiff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification times are normally expressed in the ISO 8601 format. Example: >>> for line in unified_diff('one two three four'.split(), ... 'zero one tree four'.split(), 'Original', 'Current', ... '2005-01-26 23:30:50', '2010-04-02 10:20:52', ... lineterm=''): ... print(line) # doctest: +NORMALIZE_WHITESPACE --- Original 2005-01-26 23:30:50 +++ Current 2010-04-02 10:20:52 @@ -1,4 +1,4 @@ +zero one -two -three +tree four """ started = False for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n): if not started: started = True fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' todate = '\t{}'.format(tofiledate) if tofiledate else '' yield '--- {}{}{}'.format(fromfile, fromdate, lineterm) yield '+++ {}{}{}'.format(tofile, todate, lineterm) first, last = group[0], group[-1] file1_range = _format_range_unified(first[1], last[2]) file2_range = _format_range_unified(first[3], last[4]) yield '@@ -{} +{} @@{}'.format(file1_range, file2_range, lineterm) for tag, i1, i2, j1, j2 in group: if tag == 'equal': for line in a[i1:i2]: yield ' ' + line continue if tag in {'replace', 'delete'}: for line in a[i1:i2]: yield '-' + line if tag in {'replace', 'insert'}: for line in b[j1:j2]: yield '+' + line ######################################################################## ### Context Diff ######################################################################## def _format_range_context(start, stop): 'Convert range to the "ed" format' # Per the diff spec at http://www.unix.org/single_unix_specification/ beginning = start + 1 # lines start numbering with one length = stop - start if not length: beginning -= 1 # empty ranges begin at line just before the range if length <= 1: return '{}'.format(beginning) return '{},{}'.format(beginning, beginning + length - 1) # See http://www.unix.org/single_unix_specification/ def context_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'): r""" Compare two sequences of lines; generate the delta as a context diff. Context diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which defaults to three. By default, the diff control lines (those with *** or ---) are created with a trailing newline. This is helpful so that inputs created from file.readlines() result in diffs that are suitable for file.writelines() since both the inputs and outputs have trailing newlines. For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free. The context diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification times are normally expressed in the ISO 8601 format. If not specified, the strings default to blanks. Example: >>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(True), ... 'zero\none\ntree\nfour\n'.splitlines(True), 'Original', 'Current')), ... end="") *** Original --- Current *************** *** 1,4 **** one ! two ! three four --- 1,4 ---- + zero one ! tree four """ prefix = dict(insert='+ ', delete='- ', replace='! ', equal=' ') started = False for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n): if not started: started = True fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' todate = '\t{}'.format(tofiledate) if tofiledate else '' yield '*** {}{}{}'.format(fromfile, fromdate, lineterm) yield '--- {}{}{}'.format(tofile, todate, lineterm) first, last = group[0], group[-1] yield '***************' + lineterm file1_range = _format_range_context(first[1], last[2]) yield '*** {} ****{}'.format(file1_range, lineterm) if any(tag in {'replace', 'delete'} for tag, _, _, _, _ in group): for tag, i1, i2, _, _ in group: if tag != 'insert': for line in a[i1:i2]: yield prefix[tag] + line file2_range = _format_range_context(first[3], last[4]) yield '--- {} ----{}'.format(file2_range, lineterm) if any(tag in {'replace', 'insert'} for tag, _, _, _, _ in group): for tag, _, _, j1, j2 in group: if tag != 'delete': for line in b[j1:j2]: yield prefix[tag] + line def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK): r""" Compare `a` and `b` (lists of strings); return a `Differ`-style delta. Optional keyword parameters `linejunk` and `charjunk` are for filter functions (or None): - linejunk: A function that should accept a single string argument, and return true iff the string is junk. The default is None, and is recommended; as of Python 2.3, an adaptive notion of "noise" lines is used that does a good job on its own. - charjunk: A function that should accept a string of length 1. The default is module-level function IS_CHARACTER_JUNK, which filters out whitespace characters (a blank or tab; note: bad idea to include newline in this!). Tools/scripts/ndiff.py is a command-line front-end to this function. Example: >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True), ... 'ore\ntree\nemu\n'.splitlines(keepends=True)) >>> print(''.join(diff), end="") - one ? ^ + ore ? ^ - two - three ? - + tree + emu """ return Differ(linejunk, charjunk).compare(a, b) def _mdiff(fromlines, tolines, context=None, linejunk=None, charjunk=IS_CHARACTER_JUNK): r"""Returns generator yielding marked up from/to side by side differences. Arguments: fromlines -- list of text lines to compared to tolines tolines -- list of text lines to be compared to fromlines context -- number of context lines to display on each side of difference, if None, all from/to text lines will be generated. linejunk -- passed on to ndiff (see ndiff documentation) charjunk -- passed on to ndiff (see ndiff documentation) This function returns an iterator which returns a tuple: (from line tuple, to line tuple, boolean flag) from/to line tuple -- (line num, line text) line num -- integer or None (to indicate a context separation) line text -- original line text with following markers inserted: '\0+' -- marks start of added text '\0-' -- marks start of deleted text '\0^' -- marks start of changed text '\1' -- marks end of added/deleted/changed text boolean flag -- None indicates context separation, True indicates either "from" or "to" line contains a change, otherwise False. This function/iterator was originally developed to generate side by side file difference for making HTML pages (see HtmlDiff class for example usage). Note, this function utilizes the ndiff function to generate the side by side difference markup. Optional ndiff arguments may be passed to this function and they in turn will be passed to ndiff. """ import re # regular expression for finding intraline change indices change_re = re.compile('(\++|\-+|\^+)') # create the difference iterator to generate the differences diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk) def _make_line(lines, format_key, side, num_lines=[0,0]): """Returns line of text with user's change markup and line formatting. lines -- list of lines from the ndiff generator to produce a line of text from. When producing the line of text to return, the lines used are removed from this list. format_key -- '+' return first line in list with "add" markup around the entire line. '-' return first line in list with "delete" markup around the entire line. '?' return first line in list with add/delete/change intraline markup (indices obtained from second line) None return first line in list with no markup side -- indice into the num_lines list (0=from,1=to) num_lines -- from/to current line number. This is NOT intended to be a passed parameter. It is present as a keyword argument to maintain memory of the current line numbers between calls of this function. Note, this function is purposefully not defined at the module scope so that data it needs from its parent function (within whose context it is defined) does not need to be of module scope. """ num_lines[side] += 1 # Handle case where no user markup is to be added, just return line of # text with user's line format to allow for usage of the line number. if format_key is None: return (num_lines[side],lines.pop(0)[2:]) # Handle case of intraline changes if format_key == '?': text, markers = lines.pop(0), lines.pop(0) # find intraline changes (store change type and indices in tuples) sub_info = [] def record_sub_info(match_object,sub_info=sub_info): sub_info.append([match_object.group(1)[0],match_object.span()]) return match_object.group(1) change_re.sub(record_sub_info,markers) # process each tuple inserting our special marks that won't be # noticed by an xml/html escaper. for key,(begin,end) in sub_info[::-1]: text = text[0:begin]+'\0'+key+text[begin:end]+'\1'+text[end:] text = text[2:] # Handle case of add/delete entire line else: text = lines.pop(0)[2:] # if line of text is just a newline, insert a space so there is # something for the user to highlight and see. if not text: text = ' ' # insert marks that won't be noticed by an xml/html escaper. text = '\0' + format_key + text + '\1' # Return line of text, first allow user's line formatter to do its # thing (such as adding the line number) then replace the special # marks with what the user's change markup. return (num_lines[side],text) def _line_iterator(): """Yields from/to lines of text with a change indication. This function is an iterator. It itself pulls lines from a differencing iterator, processes them and yields them. When it can it yields both a "from" and a "to" line, otherwise it will yield one or the other. In addition to yielding the lines of from/to text, a boolean flag is yielded to indicate if the text line(s) have differences in them. Note, this function is purposefully not defined at the module scope so that data it needs from its parent function (within whose context it is defined) does not need to be of module scope. """ lines = [] num_blanks_pending, num_blanks_to_yield = 0, 0 while True: # Load up next 4 lines so we can look ahead, create strings which # are a concatenation of the first character of each of the 4 lines # so we can do some very readable comparisons. while len(lines) < 4: try: lines.append(next(diff_lines_iterator)) except StopIteration: lines.append('X') s = ''.join([line[0] for line in lines]) if s.startswith('X'): # When no more lines, pump out any remaining blank lines so the # corresponding add/delete lines get a matching blank line so # all line pairs get yielded at the next level. num_blanks_to_yield = num_blanks_pending elif s.startswith('-?+?'): # simple intraline change yield _make_line(lines,'?',0), _make_line(lines,'?',1), True continue elif s.startswith('--++'): # in delete block, add block coming: we do NOT want to get # caught up on blank lines yet, just process the delete line num_blanks_pending -= 1 yield _make_line(lines,'-',0), None, True continue elif s.startswith(('--?+', '--+', '- ')): # in delete block and see a intraline change or unchanged line # coming: yield the delete line and then blanks from_line,to_line = _make_line(lines,'-',0), None num_blanks_to_yield,num_blanks_pending = num_blanks_pending-1,0 elif s.startswith('-+?'): # intraline change yield _make_line(lines,None,0), _make_line(lines,'?',1), True continue elif s.startswith('-?+'): # intraline change yield _make_line(lines,'?',0), _make_line(lines,None,1), True continue elif s.startswith('-'): # delete FROM line num_blanks_pending -= 1 yield _make_line(lines,'-',0), None, True continue elif s.startswith('+--'): # in add block, delete block coming: we do NOT want to get # caught up on blank lines yet, just process the add line num_blanks_pending += 1 yield None, _make_line(lines,'+',1), True continue elif s.startswith(('+ ', '+-')): # will be leaving an add block: yield blanks then add line from_line, to_line = None, _make_line(lines,'+',1) num_blanks_to_yield,num_blanks_pending = num_blanks_pending+1,0 elif s.startswith('+'): # inside an add block, yield the add line num_blanks_pending += 1 yield None, _make_line(lines,'+',1), True continue elif s.startswith(' '): # unchanged text, yield it to both sides yield _make_line(lines[:],None,0),_make_line(lines,None,1),False continue # Catch up on the blank lines so when we yield the next from/to # pair, they are lined up. while(num_blanks_to_yield < 0): num_blanks_to_yield += 1 yield None,('','\n'),True while(num_blanks_to_yield > 0): num_blanks_to_yield -= 1 yield ('','\n'),None,True if s.startswith('X'): raise StopIteration else: yield from_line,to_line,True def _line_pair_iterator(): """Yields from/to lines of text with a change indication. This function is an iterator. It itself pulls lines from the line iterator. Its difference from that iterator is that this function always yields a pair of from/to text lines (with the change indication). If necessary it will collect single from/to lines until it has a matching pair from/to pair to yield. Note, this function is purposefully not defined at the module scope so that data it needs from its parent function (within whose context it is defined) does not need to be of module scope. """ line_iterator = _line_iterator() fromlines,tolines=[],[] while True: # Collecting lines of text until we have a from/to pair while (len(fromlines)==0 or len(tolines)==0): from_line, to_line, found_diff = next(line_iterator) if from_line is not None: fromlines.append((from_line,found_diff)) if to_line is not None: tolines.append((to_line,found_diff)) # Once we have a pair, remove them from the collection and yield it from_line, fromDiff = fromlines.pop(0) to_line, to_diff = tolines.pop(0) yield (from_line,to_line,fromDiff or to_diff) # Handle case where user does not want context differencing, just yield # them up without doing anything else with them. line_pair_iterator = _line_pair_iterator() if context is None: while True: yield next(line_pair_iterator) # Handle case where user wants context differencing. We must do some # storage of lines until we know for sure that they are to be yielded. else: context += 1 lines_to_write = 0 while True: # Store lines up until we find a difference, note use of a # circular queue because we only need to keep around what # we need for context. index, contextLines = 0, [None]*(context) found_diff = False while(found_diff is False): from_line, to_line, found_diff = next(line_pair_iterator) i = index % context contextLines[i] = (from_line, to_line, found_diff) index += 1 # Yield lines that we have collected so far, but first yield # the user's separator. if index > context: yield None, None, None lines_to_write = context else: lines_to_write = index index = 0 while(lines_to_write): i = index % context index += 1 yield contextLines[i] lines_to_write -= 1 # Now yield the context lines after the change lines_to_write = context-1 while(lines_to_write): from_line, to_line, found_diff = next(line_pair_iterator) # If another change within the context, extend the context if found_diff: lines_to_write = context-1 else: lines_to_write -= 1 yield from_line, to_line, found_diff _file_template = """ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title></title> <style type="text/css">%(styles)s </style> </head> <body> %(table)s%(legend)s </body> </html>""" _styles = """ table.diff {font-family:Courier; border:medium;} .diff_header {background-color:#e0e0e0} td.diff_header {text-align:right} .diff_next {background-color:#c0c0c0} .diff_add {background-color:#aaffaa} .diff_chg {background-color:#ffff77} .diff_sub {background-color:#ffaaaa}""" _table_template = """ <table class="diff" id="difflib_chg_%(prefix)s_top" cellspacing="0" cellpadding="0" rules="groups" > <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> %(header_row)s <tbody> %(data_rows)s </tbody> </table>""" _legend = """ <table class="diff" summary="Legends"> <tr> <th colspan="2"> Legends </th> </tr> <tr> <td> <table border="" summary="Colors"> <tr><th> Colors </th> </tr> <tr><td class="diff_add">&nbsp;Added&nbsp;</td></tr> <tr><td class="diff_chg">Changed</td> </tr> <tr><td class="diff_sub">Deleted</td> </tr> </table></td> <td> <table border="" summary="Links"> <tr><th colspan="2"> Links </th> </tr> <tr><td>(f)irst change</td> </tr> <tr><td>(n)ext change</td> </tr> <tr><td>(t)op</td> </tr> </table></td> </tr> </table>""" class HtmlDiff(object): """For producing HTML side by side comparison with change highlights. This class can be used to create an HTML table (or a complete HTML file containing the table) showing a side by side, line by line comparison of text with inter-line and intra-line change highlights. The table can be generated in either full or contextual difference mode. The following methods are provided for HTML generation: make_table -- generates HTML for a single side by side table make_file -- generates complete HTML file with a single side by side table See tools/scripts/diff.py for an example usage of this class. """ _file_template = _file_template _styles = _styles _table_template = _table_template _legend = _legend _default_prefix = 0 def __init__(self,tabsize=8,wrapcolumn=None,linejunk=None, charjunk=IS_CHARACTER_JUNK): """HtmlDiff instance initializer Arguments: tabsize -- tab stop spacing, defaults to 8. wrapcolumn -- column number where lines are broken and wrapped, defaults to None where lines are not wrapped. linejunk,charjunk -- keyword arguments passed into ndiff() (used to by HtmlDiff() to generate the side by side HTML differences). See ndiff() documentation for argument default values and descriptions. """ self._tabsize = tabsize self._wrapcolumn = wrapcolumn self._linejunk = linejunk self._charjunk = charjunk def make_file(self,fromlines,tolines,fromdesc='',todesc='',context=False, numlines=5): """Returns HTML file of side by side comparison with change highlights Arguments: fromlines -- list of "from" lines tolines -- list of "to" lines fromdesc -- "from" file column header string todesc -- "to" file column header string context -- set to True for contextual differences (defaults to False which shows full differences). numlines -- number of context lines. When context is set True, controls number of lines displayed before and after the change. When context is False, controls the number of lines to place the "next" link anchors before the next change (so click of "next" link jumps to just before the change). """ return self._file_template % dict( styles = self._styles, legend = self._legend, table = self.make_table(fromlines,tolines,fromdesc,todesc, context=context,numlines=numlines)) def _tab_newline_replace(self,fromlines,tolines): """Returns from/to line lists with tabs expanded and newlines removed. Instead of tab characters being replaced by the number of spaces needed to fill in to the next tab stop, this function will fill the space with tab characters. This is done so that the difference algorithms can identify changes in a file when tabs are replaced by spaces and vice versa. At the end of the HTML generation, the tab characters will be replaced with a nonbreakable space. """ def expand_tabs(line): # hide real spaces line = line.replace(' ','\0') # expand tabs into spaces line = line.expandtabs(self._tabsize) # replace spaces from expanded tabs back into tab characters # (we'll replace them with markup after we do differencing) line = line.replace(' ','\t') return line.replace('\0',' ').rstrip('\n') fromlines = [expand_tabs(line) for line in fromlines] tolines = [expand_tabs(line) for line in tolines] return fromlines,tolines def _split_line(self,data_list,line_num,text): """Builds list of text lines by splitting text lines at wrap point This function will determine if the input text line needs to be wrapped (split) into separate lines. If so, the first wrap point will be determined and the first line appended to the output text line list. This function is used recursively to handle the second part of the split line to further split it. """ # if blank line or context separator, just add it to the output list if not line_num: data_list.append((line_num,text)) return # if line text doesn't need wrapping, just add it to the output list size = len(text) max = self._wrapcolumn if (size <= max) or ((size -(text.count('\0')*3)) <= max): data_list.append((line_num,text)) return # scan text looking for the wrap point, keeping track if the wrap # point is inside markers i = 0 n = 0 mark = '' while n < max and i < size: if text[i] == '\0': i += 1 mark = text[i] i += 1 elif text[i] == '\1': i += 1 mark = '' else: i += 1 n += 1 # wrap point is inside text, break it up into separate lines line1 = text[:i] line2 = text[i:] # if wrap point is inside markers, place end marker at end of first # line and start marker at beginning of second line because each # line will have its own table tag markup around it. if mark: line1 = line1 + '\1' line2 = '\0' + mark + line2 # tack on first line onto the output list data_list.append((line_num,line1)) # use this routine again to wrap the remaining text self._split_line(data_list,'>',line2) def _line_wrapper(self,diffs): """Returns iterator that splits (wraps) mdiff text lines""" # pull from/to data and flags from mdiff iterator for fromdata,todata,flag in diffs: # check for context separators and pass them through if flag is None: yield fromdata,todata,flag continue (fromline,fromtext),(toline,totext) = fromdata,todata # for each from/to line split it at the wrap column to form # list of text lines. fromlist,tolist = [],[] self._split_line(fromlist,fromline,fromtext) self._split_line(tolist,toline,totext) # yield from/to line in pairs inserting blank lines as # necessary when one side has more wrapped lines while fromlist or tolist: if fromlist: fromdata = fromlist.pop(0) else: fromdata = ('',' ') if tolist: todata = tolist.pop(0) else: todata = ('',' ') yield fromdata,todata,flag def _collect_lines(self,diffs): """Collects mdiff output into separate lists Before storing the mdiff from/to data into a list, it is converted into a single line of text with HTML markup. """ fromlist,tolist,flaglist = [],[],[] # pull from/to data and flags from mdiff style iterator for fromdata,todata,flag in diffs: try: # store HTML markup of the lines into the lists fromlist.append(self._format_line(0,flag,*fromdata)) tolist.append(self._format_line(1,flag,*todata)) except TypeError: # exceptions occur for lines where context separators go fromlist.append(None) tolist.append(None) flaglist.append(flag) return fromlist,tolist,flaglist def _format_line(self,side,flag,linenum,text): """Returns HTML markup of "from" / "to" text lines side -- 0 or 1 indicating "from" or "to" text flag -- indicates if difference on line linenum -- line number (used for line number column) text -- line text to be marked up """ try: linenum = '%d' % linenum id = ' id="%s%s"' % (self._prefix[side],linenum) except TypeError: # handle blank lines where linenum is '>' or '' id = '' # replace those things that would get confused with HTML symbols text=text.replace("&","&amp;").replace(">","&gt;").replace("<","&lt;") # make space non-breakable so they don't get compressed or line wrapped text = text.replace(' ','&nbsp;').rstrip() return '<td class="diff_header"%s>%s</td><td nowrap="nowrap">%s</td>' \ % (id,linenum,text) def _make_prefix(self): """Create unique anchor prefixes""" # Generate a unique anchor prefix so multiple tables # can exist on the same HTML page without conflicts. fromprefix = "from%d_" % HtmlDiff._default_prefix toprefix = "to%d_" % HtmlDiff._default_prefix HtmlDiff._default_prefix += 1 # store prefixes so line format method has access self._prefix = [fromprefix,toprefix] def _convert_flags(self,fromlist,tolist,flaglist,context,numlines): """Makes list of "next" links""" # all anchor names will be generated using the unique "to" prefix toprefix = self._prefix[1] # process change flags, generating middle column of next anchors/links next_id = ['']*len(flaglist) next_href = ['']*len(flaglist) num_chg, in_change = 0, False last = 0 for i,flag in enumerate(flaglist): if flag: if not in_change: in_change = True last = i # at the beginning of a change, drop an anchor a few lines # (the context lines) before the change for the previous # link i = max([0,i-numlines]) next_id[i] = ' id="difflib_chg_%s_%d"' % (toprefix,num_chg) # at the beginning of a change, drop a link to the next # change num_chg += 1 next_href[last] = '<a href="#difflib_chg_%s_%d">n</a>' % ( toprefix,num_chg) else: in_change = False # check for cases where there is no content to avoid exceptions if not flaglist: flaglist = [False] next_id = [''] next_href = [''] last = 0 if context: fromlist = ['<td></td><td>&nbsp;No Differences Found&nbsp;</td>'] tolist = fromlist else: fromlist = tolist = ['<td></td><td>&nbsp;Empty File&nbsp;</td>'] # if not a change on first line, drop a link if not flaglist[0]: next_href[0] = '<a href="#difflib_chg_%s_0">f</a>' % toprefix # redo the last link to link to the top next_href[last] = '<a href="#difflib_chg_%s_top">t</a>' % (toprefix) return fromlist,tolist,flaglist,next_href,next_id def make_table(self,fromlines,tolines,fromdesc='',todesc='',context=False, numlines=5): """Returns HTML table of side by side comparison with change highlights Arguments: fromlines -- list of "from" lines tolines -- list of "to" lines fromdesc -- "from" file column header string todesc -- "to" file column header string context -- set to True for contextual differences (defaults to False which shows full differences). numlines -- number of context lines. When context is set True, controls number of lines displayed before and after the change. When context is False, controls the number of lines to place the "next" link anchors before the next change (so click of "next" link jumps to just before the change). """ # make unique anchor prefixes so that multiple tables may exist # on the same page without conflict. self._make_prefix() # change tabs to spaces before it gets more difficult after we insert # markup fromlines,tolines = self._tab_newline_replace(fromlines,tolines) # create diffs iterator which generates side by side from/to data if context: context_lines = numlines else: context_lines = None diffs = _mdiff(fromlines,tolines,context_lines,linejunk=self._linejunk, charjunk=self._charjunk) # set up iterator to wrap lines that exceed desired width if self._wrapcolumn: diffs = self._line_wrapper(diffs) # collect up from/to lines and flags into lists (also format the lines) fromlist,tolist,flaglist = self._collect_lines(diffs) # process change flags, generating middle column of next anchors/links fromlist,tolist,flaglist,next_href,next_id = self._convert_flags( fromlist,tolist,flaglist,context,numlines) s = [] fmt = ' <tr><td class="diff_next"%s>%s</td>%s' + \ '<td class="diff_next">%s</td>%s</tr>\n' for i in range(len(flaglist)): if flaglist[i] is None: # mdiff yields None on separator lines skip the bogus ones # generated for the first line if i > 0: s.append(' </tbody> \n <tbody>\n') else: s.append( fmt % (next_id[i],next_href[i],fromlist[i], next_href[i],tolist[i])) if fromdesc or todesc: header_row = '<thead><tr>%s%s%s%s</tr></thead>' % ( '<th class="diff_next"><br /></th>', '<th colspan="2" class="diff_header">%s</th>' % fromdesc, '<th class="diff_next"><br /></th>', '<th colspan="2" class="diff_header">%s</th>' % todesc) else: header_row = '' table = self._table_template % dict( data_rows=''.join(s), header_row=header_row, prefix=self._prefix[1]) return table.replace('\0+','<span class="diff_add">'). \ replace('\0-','<span class="diff_sub">'). \ replace('\0^','<span class="diff_chg">'). \ replace('\1','</span>'). \ replace('\t','&nbsp;') del re def restore(delta, which): r""" Generate one of the two sequences that generated a delta. Given a `delta` produced by `Differ.compare()` or `ndiff()`, extract lines originating from file 1 or 2 (parameter `which`), stripping off line prefixes. Examples: >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True), ... 'ore\ntree\nemu\n'.splitlines(keepends=True)) >>> diff = list(diff) >>> print(''.join(restore(diff, 1)), end="") one two three >>> print(''.join(restore(diff, 2)), end="") ore tree emu """ try: tag = {1: "- ", 2: "+ "}[int(which)] except KeyError: raise ValueError('unknown delta choice (must be 1 or 2): %r' % which) prefixes = (" ", tag) for line in delta: if line[:2] in prefixes: yield line[2:] def _test(): import doctest, difflib return doctest.testmod(difflib) if __name__ == "__main__": _test()
gpl-3.0
[ 3168, 1182, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 624, 199, 2377, 27070, 1553, 10897, 367, 17226, 27446, 3382, 2251, 14, 199, 199, 3481, 664, 63, 1600, 63, 6742, 8, 1027, 12, 2086, 23422, 12, 302, 29, 19, 12, 17875, 29, 16, 14, 22, 304, 272, 3645, 10975, 16073, 370, 372, 769, 402, 314, 5526, 298, 8302, 8321, 2, 4450, 14, 199, 199, 3481, 1067, 63, 3028, 8, 65, 12, 330, 304, 272, 2104, 2877, 5548, 402, 3326, 12, 372, 282, 5762, 315, 1067, 3915, 1475, 14, 199, 199, 3481, 302, 3028, 8, 65, 12, 330, 304, 272, 1432, 282, 5762, 26, 314, 8865, 3382, 658, 65, 64, 436, 658, 66, 64, 334, 6717, 402, 3326, 680, 199, 199, 3481, 9066, 8, 3136, 12, 1314, 304, 272, 1432, 1373, 402, 314, 2877, 8013, 626, 4046, 376, 302, 3028, 5762, 14, 199, 199, 3481, 25344, 63, 3028, 8, 65, 12, 330, 304, 272, 2104, 2877, 5548, 402, 3326, 12, 372, 282, 5762, 315, 25344, 3915, 1475, 14, 199, 199, 2543, 10975, 16073, 26, 272, 437, 26841, 1021, 367, 20234, 6342, 402, 8013, 402, 1263, 730, 14, 199, 199, 2543, 3757, 1260, 26, 272, 2104, 27955, 11779, 13, 11875, 27446, 687, 8013, 402, 2385, 402, 1318, 14, 199, 199, 2543, 20880, 10746, 26, 272, 2104, 27955, 4163, 5366, 701, 5366, 9132, 543, 1570, 11850, 83, 14, 199, 624, 199, 199, 363, 452, 363, 275, 788, 362, 63, 1600, 63, 6742, 297, 283, 28632, 297, 283, 8011, 297, 283, 5826, 16073, 297, 1779, 283, 1341, 1260, 1673, 1311, 63, 29007, 63, 42, 8019, 297, 283, 1311, 63, 6174, 63, 42, 8019, 297, 283, 1100, 63, 3028, 297, 1779, 283, 32180, 63, 3028, 297, 283, 12957, 10746, 297, 283, 4486, 418, 199, 199, 646, 3598, 199, 646, 13295, 81, 199, 504, 5055, 492, 12863, 465, 485, 18921, 199, 199, 4486, 275, 485, 18921, 360, 4486, 297, 283, 65, 330, 1568, 358, 199, 199, 318, 485, 12063, 63, 6884, 8, 6742, 12, 2582, 304, 272, 340, 2582, 26, 267, 372, 499, 14, 16, 627, 4450, 1182, 2582, 272, 372, 413, 14, 16, 199, 199, 533, 10975, 16073, 26, 339, 408, 272, 10975, 16073, 365, 282, 26841, 1021, 367, 20234, 6342, 402, 8013, 402, 272, 1263, 730, 12, 880, 1846, 465, 314, 3414, 4008, 787, 21197, 14, 221, 710, 5678, 272, 5563, 8869, 2335, 12, 436, 365, 282, 12050, 13758, 559, 281, 2419, 12, 376, 5563, 272, 3267, 315, 314, 2465, 5851, 1257, 1159, 701, 820, 292, 2764, 556, 436, 593, 605, 609, 1357, 1334, 314, 272, 10342, 9670, 536, 298, 3199, 4478, 3851, 4877, 1674, 221, 710, 5678, 16819, 365, 370, 2342, 272, 314, 21303, 26611, 4877, 1007, 4041, 626, 3509, 949, 298, 17941, 2, 272, 4008, 334, 50, 13, 47, 3181, 1133, 2287, 24605, 680, 221, 710, 2011, 16819, 365, 2066, 6781, 272, 15035, 370, 314, 10338, 402, 314, 8013, 370, 314, 3602, 436, 370, 314, 2451, 272, 402, 314, 4877, 1007, 4041, 14, 221, 961, 1630, 440, 1995, 13460, 5283, 272, 8013, 12, 1325, 1630, 221, 7169, 370, 1995, 4450, 626, 298, 11660, 2451, 2, 370, 13135, 14, 339, 10975, 16073, 11275, 370, 4526, 282, 298, 14864, 13, 17317, 3915, 2, 3382, 2877, 272, 8013, 14, 221, 25059, 325, 14, 71, 14, 22242, 8, 7574, 9, 3915, 12, 314, 27440, 14040, 279, 949, 296, 365, 314, 272, 21303, 627, 16583, 10, 1253, 24605, 13, 4624, 4877, 1007, 4041, 14, 221, 10314, 1159, 4052, 272, 8579, 397, 4837, 411, 2978, 7, 325, 5066, 14, 221, 710, 5417, 8, 7574, 9, 4747, 3028, 965, 4573, 19604, 272, 949, 296, 12, 4092, 316, 1536, 4008, 626, 7468, 28727, 315, 1924, 3414, 14, 272, 10314, 12, 436, 314, 1083, 2348, 12, 7468, 370, 1995, 1655, 1109, 1907, 857, 8865, 272, 13924, 2419, 1630, 3915, 14, 221, 961, 1083, 11337, 370, 506, 314, 5210, 373, 21406, 461, 272, 370, 308, 5654, 316, 1536, 641, 5664, 402, 298, 17941, 2385, 401, 10617, 334, 2930, 4596, 2385, 315, 272, 24801, 1318, 1584, 12, 503, 11703, 3886, 48, 4335, 2385, 315, 4163, 1584, 680, 221, 10314, 1443, 506, 272, 2952, 642, 365, 314, 1454, 1083, 402, 314, 650, 626, 965, 282, 627, 21318, 10, 402, 272, 298, 17941, 2, 665, 87, 2292, 10827, 339, 5679, 12, 20234, 2877, 3326, 12, 436, 11201, 316, 4596, 83, 370, 506, 298, 17941, 582, 339, 1306, 308, 275, 10975, 16073, 8, 2734, 671, 26, 671, 508, 298, 3872, 272, 2263, 9326, 298, 4239, 11086, 1453, 4436, 17259, 272, 2263, 9326, 298, 4239, 5236, 23590, 11086, 1453, 4436, 15027, 272, 1306, 339, 1275, 6884, 342, 2529, 282, 2069, 315, 359, 16, 12, 413, 467, 17616, 4039, 314, 298, 21965, 2, 402, 314, 272, 8013, 14, 221, 3709, 282, 2332, 402, 21541, 12, 282, 1275, 6884, 342, 574, 1806, 378, 14, 22, 4910, 314, 272, 8013, 787, 4002, 4450, 26, 339, 1306, 870, 8, 2363, 8, 83, 14, 6884, 1062, 650, 430, 272, 378, 14, 13465, 272, 1306, 339, 982, 1265, 3984, 1454, 22201, 315, 2382, 314, 8013, 1336, 12, 272, 1275, 362, 63, 9467, 63, 4166, 342, 365, 4926, 89, 26, 339, 1306, 367, 1853, 315, 308, 14, 362, 63, 9467, 63, 4166, 837, 272, 2263, 258, 870, 480, 65, 9722, 68, 61, 436, 330, 9722, 68, 61, 1336, 367, 450, 68, 4008, 2, 450, 1853, 9, 272, 282, 59, 16, 61, 436, 330, 59, 16, 61, 1336, 367, 1695, 4008, 272, 282, 59, 24, 61, 436, 330, 59, 1196, 61, 1336, 367, 7829, 4008, 272, 282, 59, 1398, 61, 436, 330, 59, 1703, 61, 1336, 367, 378, 4008, 339, 3390, 626, 314, 2061, 2008, 2138, 701, 1275, 362, 63, 9467, 63, 4166, 342, 365, 3544, 282, 272, 7283, 12, 334, 552, 8, 65, 395, 822, 8, 66, 395, 378, 395, 436, 642, 365, 314, 1454, 1930, 315, 1314, 314, 2061, 272, 2008, 1819, 334, 1955, 402, 4008, 7838, 9, 365, 378, 14, 339, 982, 1265, 2934, 370, 5715, 4212, 370, 1570, 314, 1642, 3414, 1901, 314, 3499, 12, 272, 675, 1275, 362, 63, 22022, 837, 339, 1306, 367, 10508, 315, 308, 14, 362, 63, 22022, 837, 272, 2263, 258, 870, 3647, 22, 83, 282, 9722, 68, 2689 ]
[ 1182, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 624, 199, 2377, 27070, 1553, 10897, 367, 17226, 27446, 3382, 2251, 14, 199, 199, 3481, 664, 63, 1600, 63, 6742, 8, 1027, 12, 2086, 23422, 12, 302, 29, 19, 12, 17875, 29, 16, 14, 22, 304, 272, 3645, 10975, 16073, 370, 372, 769, 402, 314, 5526, 298, 8302, 8321, 2, 4450, 14, 199, 199, 3481, 1067, 63, 3028, 8, 65, 12, 330, 304, 272, 2104, 2877, 5548, 402, 3326, 12, 372, 282, 5762, 315, 1067, 3915, 1475, 14, 199, 199, 3481, 302, 3028, 8, 65, 12, 330, 304, 272, 1432, 282, 5762, 26, 314, 8865, 3382, 658, 65, 64, 436, 658, 66, 64, 334, 6717, 402, 3326, 680, 199, 199, 3481, 9066, 8, 3136, 12, 1314, 304, 272, 1432, 1373, 402, 314, 2877, 8013, 626, 4046, 376, 302, 3028, 5762, 14, 199, 199, 3481, 25344, 63, 3028, 8, 65, 12, 330, 304, 272, 2104, 2877, 5548, 402, 3326, 12, 372, 282, 5762, 315, 25344, 3915, 1475, 14, 199, 199, 2543, 10975, 16073, 26, 272, 437, 26841, 1021, 367, 20234, 6342, 402, 8013, 402, 1263, 730, 14, 199, 199, 2543, 3757, 1260, 26, 272, 2104, 27955, 11779, 13, 11875, 27446, 687, 8013, 402, 2385, 402, 1318, 14, 199, 199, 2543, 20880, 10746, 26, 272, 2104, 27955, 4163, 5366, 701, 5366, 9132, 543, 1570, 11850, 83, 14, 199, 624, 199, 199, 363, 452, 363, 275, 788, 362, 63, 1600, 63, 6742, 297, 283, 28632, 297, 283, 8011, 297, 283, 5826, 16073, 297, 1779, 283, 1341, 1260, 1673, 1311, 63, 29007, 63, 42, 8019, 297, 283, 1311, 63, 6174, 63, 42, 8019, 297, 283, 1100, 63, 3028, 297, 1779, 283, 32180, 63, 3028, 297, 283, 12957, 10746, 297, 283, 4486, 418, 199, 199, 646, 3598, 199, 646, 13295, 81, 199, 504, 5055, 492, 12863, 465, 485, 18921, 199, 199, 4486, 275, 485, 18921, 360, 4486, 297, 283, 65, 330, 1568, 358, 199, 199, 318, 485, 12063, 63, 6884, 8, 6742, 12, 2582, 304, 272, 340, 2582, 26, 267, 372, 499, 14, 16, 627, 4450, 1182, 2582, 272, 372, 413, 14, 16, 199, 199, 533, 10975, 16073, 26, 339, 408, 272, 10975, 16073, 365, 282, 26841, 1021, 367, 20234, 6342, 402, 8013, 402, 272, 1263, 730, 12, 880, 1846, 465, 314, 3414, 4008, 787, 21197, 14, 221, 710, 5678, 272, 5563, 8869, 2335, 12, 436, 365, 282, 12050, 13758, 559, 281, 2419, 12, 376, 5563, 272, 3267, 315, 314, 2465, 5851, 1257, 1159, 701, 820, 292, 2764, 556, 436, 593, 605, 609, 1357, 1334, 314, 272, 10342, 9670, 536, 298, 3199, 4478, 3851, 4877, 1674, 221, 710, 5678, 16819, 365, 370, 2342, 272, 314, 21303, 26611, 4877, 1007, 4041, 626, 3509, 949, 298, 17941, 2, 272, 4008, 334, 50, 13, 47, 3181, 1133, 2287, 24605, 680, 221, 710, 2011, 16819, 365, 2066, 6781, 272, 15035, 370, 314, 10338, 402, 314, 8013, 370, 314, 3602, 436, 370, 314, 2451, 272, 402, 314, 4877, 1007, 4041, 14, 221, 961, 1630, 440, 1995, 13460, 5283, 272, 8013, 12, 1325, 1630, 221, 7169, 370, 1995, 4450, 626, 298, 11660, 2451, 2, 370, 13135, 14, 339, 10975, 16073, 11275, 370, 4526, 282, 298, 14864, 13, 17317, 3915, 2, 3382, 2877, 272, 8013, 14, 221, 25059, 325, 14, 71, 14, 22242, 8, 7574, 9, 3915, 12, 314, 27440, 14040, 279, 949, 296, 365, 314, 272, 21303, 627, 16583, 10, 1253, 24605, 13, 4624, 4877, 1007, 4041, 14, 221, 10314, 1159, 4052, 272, 8579, 397, 4837, 411, 2978, 7, 325, 5066, 14, 221, 710, 5417, 8, 7574, 9, 4747, 3028, 965, 4573, 19604, 272, 949, 296, 12, 4092, 316, 1536, 4008, 626, 7468, 28727, 315, 1924, 3414, 14, 272, 10314, 12, 436, 314, 1083, 2348, 12, 7468, 370, 1995, 1655, 1109, 1907, 857, 8865, 272, 13924, 2419, 1630, 3915, 14, 221, 961, 1083, 11337, 370, 506, 314, 5210, 373, 21406, 461, 272, 370, 308, 5654, 316, 1536, 641, 5664, 402, 298, 17941, 2385, 401, 10617, 334, 2930, 4596, 2385, 315, 272, 24801, 1318, 1584, 12, 503, 11703, 3886, 48, 4335, 2385, 315, 4163, 1584, 680, 221, 10314, 1443, 506, 272, 2952, 642, 365, 314, 1454, 1083, 402, 314, 650, 626, 965, 282, 627, 21318, 10, 402, 272, 298, 17941, 2, 665, 87, 2292, 10827, 339, 5679, 12, 20234, 2877, 3326, 12, 436, 11201, 316, 4596, 83, 370, 506, 298, 17941, 582, 339, 1306, 308, 275, 10975, 16073, 8, 2734, 671, 26, 671, 508, 298, 3872, 272, 2263, 9326, 298, 4239, 11086, 1453, 4436, 17259, 272, 2263, 9326, 298, 4239, 5236, 23590, 11086, 1453, 4436, 15027, 272, 1306, 339, 1275, 6884, 342, 2529, 282, 2069, 315, 359, 16, 12, 413, 467, 17616, 4039, 314, 298, 21965, 2, 402, 314, 272, 8013, 14, 221, 3709, 282, 2332, 402, 21541, 12, 282, 1275, 6884, 342, 574, 1806, 378, 14, 22, 4910, 314, 272, 8013, 787, 4002, 4450, 26, 339, 1306, 870, 8, 2363, 8, 83, 14, 6884, 1062, 650, 430, 272, 378, 14, 13465, 272, 1306, 339, 982, 1265, 3984, 1454, 22201, 315, 2382, 314, 8013, 1336, 12, 272, 1275, 362, 63, 9467, 63, 4166, 342, 365, 4926, 89, 26, 339, 1306, 367, 1853, 315, 308, 14, 362, 63, 9467, 63, 4166, 837, 272, 2263, 258, 870, 480, 65, 9722, 68, 61, 436, 330, 9722, 68, 61, 1336, 367, 450, 68, 4008, 2, 450, 1853, 9, 272, 282, 59, 16, 61, 436, 330, 59, 16, 61, 1336, 367, 1695, 4008, 272, 282, 59, 24, 61, 436, 330, 59, 1196, 61, 1336, 367, 7829, 4008, 272, 282, 59, 1398, 61, 436, 330, 59, 1703, 61, 1336, 367, 378, 4008, 339, 3390, 626, 314, 2061, 2008, 2138, 701, 1275, 362, 63, 9467, 63, 4166, 342, 365, 3544, 282, 272, 7283, 12, 334, 552, 8, 65, 395, 822, 8, 66, 395, 378, 395, 436, 642, 365, 314, 1454, 1930, 315, 1314, 314, 2061, 272, 2008, 1819, 334, 1955, 402, 4008, 7838, 9, 365, 378, 14, 339, 982, 1265, 2934, 370, 5715, 4212, 370, 1570, 314, 1642, 3414, 1901, 314, 3499, 12, 272, 675, 1275, 362, 63, 22022, 837, 339, 1306, 367, 10508, 315, 308, 14, 362, 63, 22022, 837, 272, 2263, 258, 870, 3647, 22, 83, 282, 9722, 68, 2689, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
catapult-project/catapult
third_party/gae_ts_mon/gae_ts_mon/protobuf/google/protobuf/internal/more_messages_pb2.py
43
4177
# Generated by the protocol buffer compiler. DO NOT EDIT! # source: google/protobuf/internal/more_messages.proto import sys _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database from google.protobuf import descriptor_pb2 # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() DESCRIPTOR = _descriptor.FileDescriptor( name='google/protobuf/internal/more_messages.proto', package='google.protobuf.internal', syntax='proto2', serialized_pb=_b('\n,google/protobuf/internal/more_messages.proto\x12\x18google.protobuf.internal\"h\n\x10OutOfOrderFields\x12\x17\n\x0foptional_sint32\x18\x05 \x01(\x11\x12\x17\n\x0foptional_uint32\x18\x03 \x01(\r\x12\x16\n\x0eoptional_int32\x18\x01 \x01(\x05*\x04\x08\x04\x10\x05*\x04\x08\x02\x10\x03:C\n\x0foptional_uint64\x12*.google.protobuf.internal.OutOfOrderFields\x18\x04 \x01(\x04:B\n\x0eoptional_int64\x12*.google.protobuf.internal.OutOfOrderFields\x18\x02 \x01(\x03') ) _sym_db.RegisterFileDescriptor(DESCRIPTOR) OPTIONAL_UINT64_FIELD_NUMBER = 4 optional_uint64 = _descriptor.FieldDescriptor( name='optional_uint64', full_name='google.protobuf.internal.optional_uint64', index=0, number=4, type=4, cpp_type=4, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=True, extension_scope=None, options=None) OPTIONAL_INT64_FIELD_NUMBER = 2 optional_int64 = _descriptor.FieldDescriptor( name='optional_int64', full_name='google.protobuf.internal.optional_int64', index=1, number=2, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=True, extension_scope=None, options=None) _OUTOFORDERFIELDS = _descriptor.Descriptor( name='OutOfOrderFields', full_name='google.protobuf.internal.OutOfOrderFields', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='optional_sint32', full_name='google.protobuf.internal.OutOfOrderFields.optional_sint32', index=0, number=5, type=17, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='optional_uint32', full_name='google.protobuf.internal.OutOfOrderFields.optional_uint32', index=1, number=3, type=13, cpp_type=3, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( name='optional_int32', full_name='google.protobuf.internal.OutOfOrderFields.optional_int32', index=2, number=1, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), ], extensions=[ ], nested_types=[], enum_types=[ ], options=None, is_extendable=True, syntax='proto2', extension_ranges=[(4, 5), (2, 3), ], oneofs=[ ], serialized_start=74, serialized_end=178, ) DESCRIPTOR.message_types_by_name['OutOfOrderFields'] = _OUTOFORDERFIELDS DESCRIPTOR.extensions_by_name['optional_uint64'] = optional_uint64 DESCRIPTOR.extensions_by_name['optional_int64'] = optional_int64 OutOfOrderFields = _reflection.GeneratedProtocolMessageType('OutOfOrderFields', (_message.Message,), dict( DESCRIPTOR = _OUTOFORDERFIELDS, __module__ = 'google.protobuf.internal.more_messages_pb2' # @@protoc_insertion_point(class_scope:google.protobuf.internal.OutOfOrderFields) )) _sym_db.RegisterMessage(OutOfOrderFields) OutOfOrderFields.RegisterExtension(optional_uint64) OutOfOrderFields.RegisterExtension(optional_int64) # @@protoc_insertion_point(module_scope)
bsd-3-clause
[ 3, 17065, 701, 314, 4113, 3335, 6365, 14, 221, 3506, 2845, 24981, 1, 199, 3, 1350, 26, 6233, 15, 7204, 15, 4672, 15, 6878, 63, 3431, 14, 2625, 199, 199, 646, 984, 199, 63, 66, 29, 1274, 14, 1023, 63, 815, 59, 16, 61, 28, 19, 436, 334, 2734, 671, 26, 88, 9, 503, 334, 2734, 671, 26, 88, 14, 2143, 360, 10378, 17, 1333, 199, 504, 6233, 14, 7204, 492, 5872, 465, 485, 4120, 199, 504, 6233, 14, 7204, 492, 1245, 465, 485, 1188, 199, 504, 6233, 14, 7204, 492, 25572, 465, 485, 14906, 199, 504, 6233, 14, 7204, 492, 5272, 63, 4659, 465, 485, 5155, 63, 4659, 199, 504, 6233, 14, 7204, 492, 5872, 63, 3317, 18, 199, 3, 13365, 16311, 63, 14739, 63, 1403, 8, 12775, 9, 199, 199, 63, 3840, 63, 697, 275, 485, 5155, 63, 4659, 14, 2698, 342, 6905, 199, 7580, 275, 485, 4120, 14, 23859, 8, 523, 536, 534, 3098, 15, 7204, 15, 4672, 15, 6878, 63, 3431, 14, 2625, 297, 523, 2559, 534, 3098, 14, 7204, 14, 4672, 297, 523, 6302, 534, 2625, 18, 297, 523, 6380, 63, 3317, 3699, 66, 2258, 78, 12, 3098, 15, 7204, 15, 4672, 15, 6878, 63, 3431, 14, 2625, 60, 88, 713, 60, 88, 1085, 3098, 14, 7204, 14, 4672, 4451, 72, 60, 78, 60, 88, 709, 21383, 4738, 7304, 60, 88, 713, 60, 88, 1196, 60, 78, 60, 88, 16, 70, 4144, 63, 30171, 708, 60, 88, 1085, 60, 88, 1717, 971, 88, 614, 2961, 88, 845, 60, 88, 713, 60, 88, 1196, 60, 78, 60, 88, 16, 70, 4144, 63, 1635, 708, 60, 88, 1085, 60, 88, 1644, 971, 88, 614, 2961, 82, 60, 88, 713, 60, 88, 975, 60, 78, 60, 88, 16, 69, 4144, 63, 442, 708, 60, 88, 1085, 60, 88, 614, 971, 88, 614, 2961, 88, 1717, 7590, 88, 966, 60, 88, 2036, 60, 88, 966, 60, 88, 709, 60, 88, 1717, 7590, 88, 966, 60, 88, 2036, 60, 88, 996, 60, 88, 709, 60, 88, 1644, 26, 35, 60, 78, 60, 88, 16, 70, 4144, 63, 1635, 772, 60, 88, 713, 4856, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 60, 88, 1085, 60, 88, 966, 971, 88, 614, 2961, 88, 966, 26, 34, 60, 78, 60, 88, 16, 69, 4144, 63, 442, 772, 60, 88, 713, 4856, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 60, 88, 1085, 60, 88, 996, 971, 88, 614, 2961, 88, 1644, 358, 199, 9, 199, 63, 3840, 63, 697, 14, 7099, 23859, 8, 7580, 9, 421, 199, 21008, 63, 17459, 772, 63, 8609, 63, 9190, 275, 841, 199, 4144, 63, 1635, 772, 275, 485, 4120, 14, 8510, 8, 523, 536, 534, 4144, 63, 1635, 772, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 4144, 63, 1635, 772, 297, 1478, 29, 16, 12, 523, 1329, 29, 20, 12, 730, 29, 20, 12, 7246, 63, 466, 29, 20, 12, 1768, 29, 17, 12, 523, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 523, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 63, 466, 29, 403, 12, 523, 365, 63, 3435, 29, 549, 12, 3329, 63, 2645, 29, 403, 12, 523, 1511, 29, 403, 9, 199, 21008, 63, 2919, 772, 63, 8609, 63, 9190, 275, 499, 199, 4144, 63, 442, 772, 275, 485, 4120, 14, 8510, 8, 523, 536, 534, 4144, 63, 442, 772, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 4144, 63, 442, 772, 297, 1478, 29, 17, 12, 523, 1329, 29, 18, 12, 730, 29, 19, 12, 7246, 63, 466, 29, 18, 12, 1768, 29, 17, 12, 523, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 523, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 63, 466, 29, 403, 12, 523, 365, 63, 3435, 29, 549, 12, 3329, 63, 2645, 29, 403, 12, 523, 1511, 29, 403, 9, 421, 199, 63, 1877, 47, 2707, 11733, 12767, 275, 485, 4120, 14, 4311, 8, 523, 536, 534, 21383, 4738, 7304, 297, 523, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 297, 523, 1788, 29, 403, 12, 523, 570, 29, 7580, 12, 523, 3035, 63, 466, 29, 403, 12, 523, 1504, 1524, 272, 485, 4120, 14, 8510, 8, 489, 536, 534, 4144, 63, 30171, 708, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 14, 4144, 63, 30171, 708, 297, 1478, 29, 16, 12, 489, 1329, 29, 21, 12, 730, 29, 1196, 12, 7246, 63, 466, 29, 17, 12, 1768, 29, 17, 12, 489, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 489, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 63, 466, 29, 403, 12, 489, 365, 63, 3435, 29, 797, 12, 3329, 63, 2645, 29, 403, 12, 489, 1511, 29, 403, 395, 272, 485, 4120, 14, 8510, 8, 489, 536, 534, 4144, 63, 1635, 708, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 14, 4144, 63, 1635, 708, 297, 1478, 29, 17, 12, 489, 1329, 29, 19, 12, 730, 29, 969, 12, 7246, 63, 466, 29, 19, 12, 1768, 29, 17, 12, 489, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 489, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 63, 466, 29, 403, 12, 489, 365, 63, 3435, 29, 797, 12, 3329, 63, 2645, 29, 403, 12, 489, 1511, 29, 403, 395, 272, 485, 4120, 14, 8510, 8, 489, 536, 534, 4144, 63, 442, 708, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 14, 4144, 63, 442, 708, 297, 1478, 29, 18, 12, 489, 1329, 29, 17, 12, 730, 29, 21, 12, 7246, 63, 466, 29, 17, 12, 1768, 29, 17, 12, 489, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 489, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 63 ]
[ 17065, 701, 314, 4113, 3335, 6365, 14, 221, 3506, 2845, 24981, 1, 199, 3, 1350, 26, 6233, 15, 7204, 15, 4672, 15, 6878, 63, 3431, 14, 2625, 199, 199, 646, 984, 199, 63, 66, 29, 1274, 14, 1023, 63, 815, 59, 16, 61, 28, 19, 436, 334, 2734, 671, 26, 88, 9, 503, 334, 2734, 671, 26, 88, 14, 2143, 360, 10378, 17, 1333, 199, 504, 6233, 14, 7204, 492, 5872, 465, 485, 4120, 199, 504, 6233, 14, 7204, 492, 1245, 465, 485, 1188, 199, 504, 6233, 14, 7204, 492, 25572, 465, 485, 14906, 199, 504, 6233, 14, 7204, 492, 5272, 63, 4659, 465, 485, 5155, 63, 4659, 199, 504, 6233, 14, 7204, 492, 5872, 63, 3317, 18, 199, 3, 13365, 16311, 63, 14739, 63, 1403, 8, 12775, 9, 199, 199, 63, 3840, 63, 697, 275, 485, 5155, 63, 4659, 14, 2698, 342, 6905, 199, 7580, 275, 485, 4120, 14, 23859, 8, 523, 536, 534, 3098, 15, 7204, 15, 4672, 15, 6878, 63, 3431, 14, 2625, 297, 523, 2559, 534, 3098, 14, 7204, 14, 4672, 297, 523, 6302, 534, 2625, 18, 297, 523, 6380, 63, 3317, 3699, 66, 2258, 78, 12, 3098, 15, 7204, 15, 4672, 15, 6878, 63, 3431, 14, 2625, 60, 88, 713, 60, 88, 1085, 3098, 14, 7204, 14, 4672, 4451, 72, 60, 78, 60, 88, 709, 21383, 4738, 7304, 60, 88, 713, 60, 88, 1196, 60, 78, 60, 88, 16, 70, 4144, 63, 30171, 708, 60, 88, 1085, 60, 88, 1717, 971, 88, 614, 2961, 88, 845, 60, 88, 713, 60, 88, 1196, 60, 78, 60, 88, 16, 70, 4144, 63, 1635, 708, 60, 88, 1085, 60, 88, 1644, 971, 88, 614, 2961, 82, 60, 88, 713, 60, 88, 975, 60, 78, 60, 88, 16, 69, 4144, 63, 442, 708, 60, 88, 1085, 60, 88, 614, 971, 88, 614, 2961, 88, 1717, 7590, 88, 966, 60, 88, 2036, 60, 88, 966, 60, 88, 709, 60, 88, 1717, 7590, 88, 966, 60, 88, 2036, 60, 88, 996, 60, 88, 709, 60, 88, 1644, 26, 35, 60, 78, 60, 88, 16, 70, 4144, 63, 1635, 772, 60, 88, 713, 4856, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 60, 88, 1085, 60, 88, 966, 971, 88, 614, 2961, 88, 966, 26, 34, 60, 78, 60, 88, 16, 69, 4144, 63, 442, 772, 60, 88, 713, 4856, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 60, 88, 1085, 60, 88, 996, 971, 88, 614, 2961, 88, 1644, 358, 199, 9, 199, 63, 3840, 63, 697, 14, 7099, 23859, 8, 7580, 9, 421, 199, 21008, 63, 17459, 772, 63, 8609, 63, 9190, 275, 841, 199, 4144, 63, 1635, 772, 275, 485, 4120, 14, 8510, 8, 523, 536, 534, 4144, 63, 1635, 772, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 4144, 63, 1635, 772, 297, 1478, 29, 16, 12, 523, 1329, 29, 20, 12, 730, 29, 20, 12, 7246, 63, 466, 29, 20, 12, 1768, 29, 17, 12, 523, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 523, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 63, 466, 29, 403, 12, 523, 365, 63, 3435, 29, 549, 12, 3329, 63, 2645, 29, 403, 12, 523, 1511, 29, 403, 9, 199, 21008, 63, 2919, 772, 63, 8609, 63, 9190, 275, 499, 199, 4144, 63, 442, 772, 275, 485, 4120, 14, 8510, 8, 523, 536, 534, 4144, 63, 442, 772, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 4144, 63, 442, 772, 297, 1478, 29, 17, 12, 523, 1329, 29, 18, 12, 730, 29, 19, 12, 7246, 63, 466, 29, 18, 12, 1768, 29, 17, 12, 523, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 523, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 63, 466, 29, 403, 12, 523, 365, 63, 3435, 29, 549, 12, 3329, 63, 2645, 29, 403, 12, 523, 1511, 29, 403, 9, 421, 199, 63, 1877, 47, 2707, 11733, 12767, 275, 485, 4120, 14, 4311, 8, 523, 536, 534, 21383, 4738, 7304, 297, 523, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 297, 523, 1788, 29, 403, 12, 523, 570, 29, 7580, 12, 523, 3035, 63, 466, 29, 403, 12, 523, 1504, 1524, 272, 485, 4120, 14, 8510, 8, 489, 536, 534, 4144, 63, 30171, 708, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 14, 4144, 63, 30171, 708, 297, 1478, 29, 16, 12, 489, 1329, 29, 21, 12, 730, 29, 1196, 12, 7246, 63, 466, 29, 17, 12, 1768, 29, 17, 12, 489, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 489, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 63, 466, 29, 403, 12, 489, 365, 63, 3435, 29, 797, 12, 3329, 63, 2645, 29, 403, 12, 489, 1511, 29, 403, 395, 272, 485, 4120, 14, 8510, 8, 489, 536, 534, 4144, 63, 1635, 708, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 14, 4144, 63, 1635, 708, 297, 1478, 29, 17, 12, 489, 1329, 29, 19, 12, 730, 29, 969, 12, 7246, 63, 466, 29, 19, 12, 1768, 29, 17, 12, 489, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 489, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 63, 466, 29, 403, 12, 489, 365, 63, 3435, 29, 797, 12, 3329, 63, 2645, 29, 403, 12, 489, 1511, 29, 403, 395, 272, 485, 4120, 14, 8510, 8, 489, 536, 534, 4144, 63, 442, 708, 297, 2615, 63, 354, 534, 3098, 14, 7204, 14, 4672, 14, 21383, 4738, 7304, 14, 4144, 63, 442, 708, 297, 1478, 29, 18, 12, 489, 1329, 29, 17, 12, 730, 29, 21, 12, 7246, 63, 466, 29, 17, 12, 1768, 29, 17, 12, 489, 965, 63, 885, 63, 585, 29, 797, 12, 849, 63, 585, 29, 16, 12, 489, 1245, 63, 466, 29, 403, 12, 4952, 63, 466, 29, 403, 12, 3035, 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,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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 ]
UFOCoins/ufo
contrib/devtools/copyright_header.py
58
22374
#!/usr/bin/env python3 # Copyright (c) 2016 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. import re import fnmatch import sys import subprocess import datetime import os ################################################################################ # file filtering ################################################################################ EXCLUDE = [ # libsecp256k1: 'src/secp256k1/include/secp256k1.h', 'src/secp256k1/include/secp256k1_ecdh.h', 'src/secp256k1/include/secp256k1_recovery.h', 'src/secp256k1/include/secp256k1_schnorr.h', 'src/secp256k1/src/java/org_bitcoin_NativeSecp256k1.c', 'src/secp256k1/src/java/org_bitcoin_NativeSecp256k1.h', 'src/secp256k1/src/java/org_bitcoin_Secp256k1Context.c', 'src/secp256k1/src/java/org_bitcoin_Secp256k1Context.h', # auto generated: 'src/univalue/lib/univalue_escapes.h', 'src/qt/bitcoinstrings.cpp', 'src/chainparamsseeds.h', # other external copyrights: 'src/tinyformat.h', 'src/leveldb/util/env_win.cc', 'src/crypto/ctaes/bench.c', 'test/functional/test_framework/bignum.py', # python init: '*__init__.py', ] EXCLUDE_COMPILED = re.compile('|'.join([fnmatch.translate(m) for m in EXCLUDE])) INCLUDE = ['*.h', '*.cpp', '*.cc', '*.c', '*.py'] INCLUDE_COMPILED = re.compile('|'.join([fnmatch.translate(m) for m in INCLUDE])) def applies_to_file(filename): return ((EXCLUDE_COMPILED.match(filename) is None) and (INCLUDE_COMPILED.match(filename) is not None)) ################################################################################ # obtain list of files in repo according to INCLUDE and EXCLUDE ################################################################################ GIT_LS_CMD = 'git ls-files' def call_git_ls(): out = subprocess.check_output(GIT_LS_CMD.split(' ')) return [f for f in out.decode("utf-8").split('\n') if f != ''] def get_filenames_to_examine(): filenames = call_git_ls() return sorted([filename for filename in filenames if applies_to_file(filename)]) ################################################################################ # define and compile regexes for the patterns we are looking for ################################################################################ COPYRIGHT_WITH_C = 'Copyright \(c\)' COPYRIGHT_WITHOUT_C = 'Copyright' ANY_COPYRIGHT_STYLE = '(%s|%s)' % (COPYRIGHT_WITH_C, COPYRIGHT_WITHOUT_C) YEAR = "20[0-9][0-9]" YEAR_RANGE = '(%s)(-%s)?' % (YEAR, YEAR) YEAR_LIST = '(%s)(, %s)+' % (YEAR, YEAR) ANY_YEAR_STYLE = '(%s|%s)' % (YEAR_RANGE, YEAR_LIST) ANY_COPYRIGHT_STYLE_OR_YEAR_STYLE = ("%s %s" % (ANY_COPYRIGHT_STYLE, ANY_YEAR_STYLE)) ANY_COPYRIGHT_COMPILED = re.compile(ANY_COPYRIGHT_STYLE_OR_YEAR_STYLE) def compile_copyright_regex(copyright_style, year_style, name): return re.compile('%s %s %s' % (copyright_style, year_style, name)) EXPECTED_HOLDER_NAMES = [ "Satoshi Nakamoto\n", "The Bitcoin Core developers\n", "The Bitcoin Core developers \n", "Bitcoin Core Developers\n", "the Bitcoin Core developers\n", "The Bitcoin developers\n", "The LevelDB Authors\. All rights reserved\.\n", "BitPay Inc\.\n", "BitPay, Inc\.\n", "University of Illinois at Urbana-Champaign\.\n", "MarcoFalke\n", "Pieter Wuille\n", "Pieter Wuille +\*\n", "Pieter Wuille, Gregory Maxwell +\*\n", "Pieter Wuille, Andrew Poelstra +\*\n", "Andrew Poelstra +\*\n", "Wladimir J. van der Laan\n", "Jeff Garzik\n", "Diederik Huys, Pieter Wuille +\*\n", "Thomas Daede, Cory Fields +\*\n", "Jan-Klaas Kollhof\n", "Sam Rushing\n", "ArtForz -- public domain half-a-node\n", ] DOMINANT_STYLE_COMPILED = {} YEAR_LIST_STYLE_COMPILED = {} WITHOUT_C_STYLE_COMPILED = {} for holder_name in EXPECTED_HOLDER_NAMES: DOMINANT_STYLE_COMPILED[holder_name] = ( compile_copyright_regex(COPYRIGHT_WITH_C, YEAR_RANGE, holder_name)) YEAR_LIST_STYLE_COMPILED[holder_name] = ( compile_copyright_regex(COPYRIGHT_WITH_C, YEAR_LIST, holder_name)) WITHOUT_C_STYLE_COMPILED[holder_name] = ( compile_copyright_regex(COPYRIGHT_WITHOUT_C, ANY_YEAR_STYLE, holder_name)) ################################################################################ # search file contents for copyright message of particular category ################################################################################ def get_count_of_copyrights_of_any_style_any_holder(contents): return len(ANY_COPYRIGHT_COMPILED.findall(contents)) def file_has_dominant_style_copyright_for_holder(contents, holder_name): match = DOMINANT_STYLE_COMPILED[holder_name].search(contents) return match is not None def file_has_year_list_style_copyright_for_holder(contents, holder_name): match = YEAR_LIST_STYLE_COMPILED[holder_name].search(contents) return match is not None def file_has_without_c_style_copyright_for_holder(contents, holder_name): match = WITHOUT_C_STYLE_COMPILED[holder_name].search(contents) return match is not None ################################################################################ # get file info ################################################################################ def read_file(filename): return open(os.path.abspath(filename), 'r').read() def gather_file_info(filename): info = {} info['filename'] = filename c = read_file(filename) info['contents'] = c info['all_copyrights'] = get_count_of_copyrights_of_any_style_any_holder(c) info['classified_copyrights'] = 0 info['dominant_style'] = {} info['year_list_style'] = {} info['without_c_style'] = {} for holder_name in EXPECTED_HOLDER_NAMES: has_dominant_style = ( file_has_dominant_style_copyright_for_holder(c, holder_name)) has_year_list_style = ( file_has_year_list_style_copyright_for_holder(c, holder_name)) has_without_c_style = ( file_has_without_c_style_copyright_for_holder(c, holder_name)) info['dominant_style'][holder_name] = has_dominant_style info['year_list_style'][holder_name] = has_year_list_style info['without_c_style'][holder_name] = has_without_c_style if has_dominant_style or has_year_list_style or has_without_c_style: info['classified_copyrights'] = info['classified_copyrights'] + 1 return info ################################################################################ # report execution ################################################################################ SEPARATOR = '-'.join(['' for _ in range(80)]) def print_filenames(filenames, verbose): if not verbose: return for filename in filenames: print("\t%s" % filename) def print_report(file_infos, verbose): print(SEPARATOR) examined = [i['filename'] for i in file_infos] print("%d files examined according to INCLUDE and EXCLUDE fnmatch rules" % len(examined)) print_filenames(examined, verbose) print(SEPARATOR) print('') zero_copyrights = [i['filename'] for i in file_infos if i['all_copyrights'] == 0] print("%4d with zero copyrights" % len(zero_copyrights)) print_filenames(zero_copyrights, verbose) one_copyright = [i['filename'] for i in file_infos if i['all_copyrights'] == 1] print("%4d with one copyright" % len(one_copyright)) print_filenames(one_copyright, verbose) two_copyrights = [i['filename'] for i in file_infos if i['all_copyrights'] == 2] print("%4d with two copyrights" % len(two_copyrights)) print_filenames(two_copyrights, verbose) three_copyrights = [i['filename'] for i in file_infos if i['all_copyrights'] == 3] print("%4d with three copyrights" % len(three_copyrights)) print_filenames(three_copyrights, verbose) four_or_more_copyrights = [i['filename'] for i in file_infos if i['all_copyrights'] >= 4] print("%4d with four or more copyrights" % len(four_or_more_copyrights)) print_filenames(four_or_more_copyrights, verbose) print('') print(SEPARATOR) print('Copyrights with dominant style:\ne.g. "Copyright (c)" and ' '"<year>" or "<startYear>-<endYear>":\n') for holder_name in EXPECTED_HOLDER_NAMES: dominant_style = [i['filename'] for i in file_infos if i['dominant_style'][holder_name]] if len(dominant_style) > 0: print("%4d with '%s'" % (len(dominant_style), holder_name.replace('\n', '\\n'))) print_filenames(dominant_style, verbose) print('') print(SEPARATOR) print('Copyrights with year list style:\ne.g. "Copyright (c)" and ' '"<year1>, <year2>, ...":\n') for holder_name in EXPECTED_HOLDER_NAMES: year_list_style = [i['filename'] for i in file_infos if i['year_list_style'][holder_name]] if len(year_list_style) > 0: print("%4d with '%s'" % (len(year_list_style), holder_name.replace('\n', '\\n'))) print_filenames(year_list_style, verbose) print('') print(SEPARATOR) print('Copyrights with no "(c)" style:\ne.g. "Copyright" and "<year>" or ' '"<startYear>-<endYear>":\n') for holder_name in EXPECTED_HOLDER_NAMES: without_c_style = [i['filename'] for i in file_infos if i['without_c_style'][holder_name]] if len(without_c_style) > 0: print("%4d with '%s'" % (len(without_c_style), holder_name.replace('\n', '\\n'))) print_filenames(without_c_style, verbose) print('') print(SEPARATOR) unclassified_copyrights = [i['filename'] for i in file_infos if i['classified_copyrights'] < i['all_copyrights']] print("%d with unexpected copyright holder names" % len(unclassified_copyrights)) print_filenames(unclassified_copyrights, verbose) print(SEPARATOR) def exec_report(base_directory, verbose): original_cwd = os.getcwd() os.chdir(base_directory) filenames = get_filenames_to_examine() file_infos = [gather_file_info(f) for f in filenames] print_report(file_infos, verbose) os.chdir(original_cwd) ################################################################################ # report cmd ################################################################################ REPORT_USAGE = """ Produces a report of all copyright header notices found inside the source files of a repository. Usage: $ ./copyright_header.py report <base_directory> [verbose] Arguments: <base_directory> - The base directory of a bitcoin source code repository. [verbose] - Includes a list of every file of each subcategory in the report. """ def report_cmd(argv): if len(argv) == 2: sys.exit(REPORT_USAGE) base_directory = argv[2] if not os.path.exists(base_directory): sys.exit("*** bad <base_directory>: %s" % base_directory) if len(argv) == 3: verbose = False elif argv[3] == 'verbose': verbose = True else: sys.exit("*** unknown argument: %s" % argv[2]) exec_report(base_directory, verbose) ################################################################################ # query git for year of last change ################################################################################ GIT_LOG_CMD = "git log --pretty=format:%%ai %s" def call_git_log(filename): out = subprocess.check_output((GIT_LOG_CMD % filename).split(' ')) return out.decode("utf-8").split('\n') def get_git_change_years(filename): git_log_lines = call_git_log(filename) if len(git_log_lines) == 0: return [datetime.date.today().year] # timestamp is in ISO 8601 format. e.g. "2016-09-05 14:25:32 -0600" return [line.split(' ')[0].split('-')[0] for line in git_log_lines] def get_most_recent_git_change_year(filename): return max(get_git_change_years(filename)) ################################################################################ # read and write to file ################################################################################ def read_file_lines(filename): f = open(os.path.abspath(filename), 'r') file_lines = f.readlines() f.close() return file_lines def write_file_lines(filename, file_lines): f = open(os.path.abspath(filename), 'w') f.write(''.join(file_lines)) f.close() ################################################################################ # update header years execution ################################################################################ COPYRIGHT = 'Copyright \(c\)' YEAR = "20[0-9][0-9]" YEAR_RANGE = '(%s)(-%s)?' % (YEAR, YEAR) HOLDER = 'The Bitcoin Core developers' UPDATEABLE_LINE_COMPILED = re.compile(' '.join([COPYRIGHT, YEAR_RANGE, HOLDER])) def get_updatable_copyright_line(file_lines): index = 0 for line in file_lines: if UPDATEABLE_LINE_COMPILED.search(line) is not None: return index, line index = index + 1 return None, None def parse_year_range(year_range): year_split = year_range.split('-') start_year = year_split[0] if len(year_split) == 1: return start_year, start_year return start_year, year_split[1] def year_range_to_str(start_year, end_year): if start_year == end_year: return start_year return "%s-%s" % (start_year, end_year) def create_updated_copyright_line(line, last_git_change_year): copyright_splitter = 'Copyright (c) ' copyright_split = line.split(copyright_splitter) # Preserve characters on line that are ahead of the start of the copyright # notice - they are part of the comment block and vary from file-to-file. before_copyright = copyright_split[0] after_copyright = copyright_split[1] space_split = after_copyright.split(' ') year_range = space_split[0] start_year, end_year = parse_year_range(year_range) if end_year == last_git_change_year: return line return (before_copyright + copyright_splitter + year_range_to_str(start_year, last_git_change_year) + ' ' + ' '.join(space_split[1:])) def update_updatable_copyright(filename): file_lines = read_file_lines(filename) index, line = get_updatable_copyright_line(file_lines) if not line: print_file_action_message(filename, "No updatable copyright.") return last_git_change_year = get_most_recent_git_change_year(filename) new_line = create_updated_copyright_line(line, last_git_change_year) if line == new_line: print_file_action_message(filename, "Copyright up-to-date.") return file_lines[index] = new_line write_file_lines(filename, file_lines) print_file_action_message(filename, "Copyright updated! -> %s" % last_git_change_year) def exec_update_header_year(base_directory): original_cwd = os.getcwd() os.chdir(base_directory) for filename in get_filenames_to_examine(): update_updatable_copyright(filename) os.chdir(original_cwd) ################################################################################ # update cmd ################################################################################ UPDATE_USAGE = """ Updates all the copyright headers of "The Bitcoin Core developers" which were changed in a year more recent than is listed. For example: // Copyright (c) <firstYear>-<lastYear> The Bitcoin Core developers will be updated to: // Copyright (c) <firstYear>-<lastModifiedYear> The Bitcoin Core developers where <lastModifiedYear> is obtained from the 'git log' history. This subcommand also handles copyright headers that have only a single year. In those cases: // Copyright (c) <year> The Bitcoin Core developers will be updated to: // Copyright (c) <year>-<lastModifiedYear> The Bitcoin Core developers where the update is appropriate. Usage: $ ./copyright_header.py update <base_directory> Arguments: <base_directory> - The base directory of a bitcoin source code repository. """ def print_file_action_message(filename, action): print("%-52s %s" % (filename, action)) def update_cmd(argv): if len(argv) != 3: sys.exit(UPDATE_USAGE) base_directory = argv[2] if not os.path.exists(base_directory): sys.exit("*** bad base_directory: %s" % base_directory) exec_update_header_year(base_directory) ################################################################################ # inserted copyright header format ################################################################################ def get_header_lines(header, start_year, end_year): lines = header.split('\n')[1:-1] lines[0] = lines[0] % year_range_to_str(start_year, end_year) return [line + '\n' for line in lines] CPP_HEADER = ''' // Copyright (c) %s The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. ''' def get_cpp_header_lines_to_insert(start_year, end_year): return reversed(get_header_lines(CPP_HEADER, start_year, end_year)) PYTHON_HEADER = ''' # Copyright (c) %s The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. ''' def get_python_header_lines_to_insert(start_year, end_year): return reversed(get_header_lines(PYTHON_HEADER, start_year, end_year)) ################################################################################ # query git for year of last change ################################################################################ def get_git_change_year_range(filename): years = get_git_change_years(filename) return min(years), max(years) ################################################################################ # check for existing core copyright ################################################################################ def file_already_has_core_copyright(file_lines): index, _ = get_updatable_copyright_line(file_lines) return index != None ################################################################################ # insert header execution ################################################################################ def file_has_hashbang(file_lines): if len(file_lines) < 1: return False if len(file_lines[0]) <= 2: return False return file_lines[0][:2] == '#!' def insert_python_header(filename, file_lines, start_year, end_year): if file_has_hashbang(file_lines): insert_idx = 1 else: insert_idx = 0 header_lines = get_python_header_lines_to_insert(start_year, end_year) for line in header_lines: file_lines.insert(insert_idx, line) write_file_lines(filename, file_lines) def insert_cpp_header(filename, file_lines, start_year, end_year): header_lines = get_cpp_header_lines_to_insert(start_year, end_year) for line in header_lines: file_lines.insert(0, line) write_file_lines(filename, file_lines) def exec_insert_header(filename, style): file_lines = read_file_lines(filename) if file_already_has_core_copyright(file_lines): sys.exit('*** %s already has a copyright by The Bitcoin Core developers' % (filename)) start_year, end_year = get_git_change_year_range(filename) if style == 'python': insert_python_header(filename, file_lines, start_year, end_year) else: insert_cpp_header(filename, file_lines, start_year, end_year) ################################################################################ # insert cmd ################################################################################ INSERT_USAGE = """ Inserts a copyright header for "The Bitcoin Core developers" at the top of the file in either Python or C++ style as determined by the file extension. If the file is a Python file and it has a '#!' starting the first line, the header is inserted in the line below it. The copyright dates will be set to be: "<year_introduced>-<current_year>" where <year_introduced> is according to the 'git log' history. If <year_introduced> is equal to <current_year>, the date will be set to be: "<current_year>" If the file already has a copyright for "The Bitcoin Core developers", the script will exit. Usage: $ ./copyright_header.py insert <file> Arguments: <file> - A source file in the bitcoin repository. """ def insert_cmd(argv): if len(argv) != 3: sys.exit(INSERT_USAGE) filename = argv[2] if not os.path.isfile(filename): sys.exit("*** bad filename: %s" % filename) _, extension = os.path.splitext(filename) if extension not in ['.h', '.cpp', '.cc', '.c', '.py']: sys.exit("*** cannot insert for file extension %s" % extension) if extension == '.py': style = 'python' else: style = 'cpp' exec_insert_header(filename, style) ################################################################################ # UI ################################################################################ USAGE = """ copyright_header.py - utilities for managing copyright headers of 'The Bitcoin Core developers' in repository source files. Usage: $ ./copyright_header <subcommand> Subcommands: report update insert To see subcommand usage, run them without arguments. """ SUBCOMMANDS = ['report', 'update', 'insert'] if __name__ == "__main__": if len(sys.argv) == 1: sys.exit(USAGE) subcommand = sys.argv[1] if subcommand not in SUBCOMMANDS: sys.exit(USAGE) if subcommand == 'report': report_cmd(sys.argv) elif subcommand == 'update': update_cmd(sys.argv) elif subcommand == 'insert': insert_cmd(sys.argv)
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 3, 1898, 334, 67, 9, 7800, 710, 21158, 11672, 19782, 199, 3, 17484, 1334, 314, 10697, 2032, 4190, 12, 1937, 314, 23073, 199, 3, 570, 9685, 503, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 14, 199, 199, 646, 295, 199, 646, 15951, 199, 646, 984, 199, 646, 3873, 199, 646, 2197, 199, 646, 747, 199, 199, 13289, 199, 3, 570, 14545, 199, 13289, 199, 199, 1438, 13958, 275, 359, 272, 327, 1973, 261, 1850, 3912, 75, 17, 26, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2613, 15, 261, 1850, 3912, 75, 17, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2613, 15, 261, 1850, 3912, 75, 17, 63, 825, 7821, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2613, 15, 261, 1850, 3912, 75, 17, 63, 29920, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2613, 15, 261, 1850, 3912, 75, 17, 63, 15820, 6505, 82, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2164, 15, 6138, 15, 1308, 63, 22816, 63, 19675, 4933, 80, 3912, 75, 17, 14, 67, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2164, 15, 6138, 15, 1308, 63, 22816, 63, 19675, 4933, 80, 3912, 75, 17, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2164, 15, 6138, 15, 1308, 63, 22816, 63, 4933, 80, 3912, 75, 17, 2998, 14, 67, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2164, 15, 6138, 15, 1308, 63, 22816, 63, 4933, 80, 3912, 75, 17, 2998, 14, 72, 297, 272, 327, 2599, 4046, 26, 272, 283, 2164, 15, 5411, 585, 15, 773, 15, 5411, 585, 63, 3765, 83, 14, 72, 297, 272, 283, 2164, 15, 8440, 15, 22816, 5465, 14, 5910, 297, 272, 283, 2164, 15, 4429, 1162, 5176, 83, 14, 72, 297, 272, 327, 1163, 5957, 4248, 83, 26, 272, 283, 2164, 15, 9864, 908, 14, 72, 297, 272, 283, 2164, 15, 6972, 457, 66, 15, 1974, 15, 1813, 63, 2676, 14, 2055, 297, 272, 283, 2164, 15, 10316, 15, 319, 17499, 15, 16571, 14, 67, 297, 272, 283, 396, 15, 15481, 15, 396, 63, 4857, 15, 66, 1030, 453, 14, 647, 297, 272, 327, 2366, 4205, 26, 272, 6438, 363, 826, 4343, 647, 297, 199, 61, 199, 1438, 13958, 63, 6790, 11540, 275, 295, 14, 2014, 20137, 1370, 904, 779, 15359, 14, 5275, 8, 77, 9, 367, 333, 315, 3651, 13958, 2459, 199, 199, 18171, 275, 17855, 72, 297, 11937, 5910, 297, 11937, 2055, 297, 11937, 67, 297, 11937, 647, 418, 199, 18171, 63, 6790, 11540, 275, 295, 14, 2014, 20137, 1370, 904, 779, 15359, 14, 5275, 8, 77, 9, 367, 333, 315, 1621, 13958, 2459, 199, 199, 318, 12966, 63, 475, 63, 493, 8, 1501, 304, 272, 372, 3666, 1438, 13958, 63, 6790, 11540, 14, 1431, 8, 1501, 9, 365, 488, 9, 436, 288, 334, 18171, 63, 6790, 11540, 14, 1431, 8, 1501, 9, 365, 440, 488, 430, 199, 199, 13289, 199, 3, 3332, 769, 402, 1584, 315, 3831, 7182, 370, 1621, 13958, 436, 3651, 13958, 199, 13289, 199, 199, 20072, 63, 5296, 63, 9744, 275, 283, 3187, 9100, 13, 1725, 7, 199, 199, 318, 1240, 63, 3187, 63, 478, 837, 272, 734, 275, 3873, 14, 1074, 63, 1199, 8, 20072, 63, 5296, 63, 9744, 14, 1294, 360, 20005, 272, 372, 359, 70, 367, 289, 315, 734, 14, 2708, 480, 1624, 13, 24, 3471, 1294, 2258, 78, 358, 340, 289, 1137, 28696, 199, 199, 318, 664, 63, 10309, 63, 475, 63, 15425, 1132, 837, 272, 6203, 275, 1240, 63, 3187, 63, 478, 342, 272, 372, 3355, 779, 1501, 367, 1788, 315, 6203, 340, 673, 12966, 63, 475, 63, 493, 8, 1501, 3948, 199, 199, 13289, 199, 3, 5627, 436, 6555, 5163, 397, 367, 314, 7970, 781, 787, 10023, 367, 199, 13289, 421, 199, 32324, 5716, 63, 9139, 63, 35, 275, 283, 7384, 25445, 67, 60, 3171, 199, 32324, 5716, 63, 29946, 63, 35, 275, 283, 7384, 7, 199, 8974, 63, 32324, 5716, 63, 18466, 275, 25676, 83, 15287, 83, 3171, 450, 334, 32324, 5716, 63, 9139, 63, 35, 12, 5877, 63, 29946, 63, 35, 9, 199, 199, 19216, 275, 298, 1165, 59, 16, 13, 25, 1527, 16, 13, 25, 8480, 199, 19216, 63, 15167, 275, 25676, 83, 9, 2801, 5, 83, 5547, 7, 450, 334, 19216, 12, 1488, 15550, 9, 199, 19216, 63, 4924, 275, 25676, 83, 5130, 12, 450, 83, 20731, 450, 334, 19216, 12, 1488, 15550, 9, 199, 8974, 63, 19216, 63, 18466, 275, 25676, 83, 15287, 83, 3171, 450, 334, 19216, 63, 15167, 12, 1488, 15550, 63, 4924, 9, 199, 8974, 63, 32324, 5716, 63, 18466, 63, 726, 63, 19216, 63, 18466, 275, 19426, 83, 450, 83, 2, 450, 334, 8974, 63, 32324, 5716, 63, 18466, 12, 6059, 1821, 63, 19216, 63, 18466, 430, 199, 199, 8974, 63, 32324, 5716, 63, 6790, 11540, 275, 295, 14, 2014, 8, 8974, 63, 32324, 5716, 63, 18466, 63, 726, 63, 19216, 63, 18466, 9, 199, 199, 318, 6555, 63, 7307, 63, 3821, 8, 7307, 63, 2487, 12, 5361, 63, 2487, 12, 536, 304, 272, 372, 295, 14, 2014, 3508, 83, 450, 83, 450, 83, 7, 450, 334, 7307, 63, 2487, 12, 5361, 63, 2487, 12, 536, 430, 199, 199, 22358, 63, 40, 15744, 63, 14546, 275, 359, 272, 298, 51, 11318, 19377, 653, 1151, 455, 3459, 60, 78, 401, 272, 298, 1918, 21158, 11672, 19782, 60, 78, 401, 272, 298, 1918, 21158, 11672, 19782, 971, 78, 401, 272, 298, 4734, 9061, 11672, 23493, 60, 78, 401, 272, 298, 1589, 21158, 11672, 19782, 60, 78, 401, 272, 298, 1918, 21158, 19782, 60, 78, 401, 272, 298, 1918, 20400, 2846, 6642, 4537, 2900, 4481, 4644, 60, 3134, 78, 401, 272, 298, 4734, 10517, 3277, 60, 3134, 78, 401, 272, 298, 4734, 10517, 12, 3277, 60, 3134, 78, 401, 272, 298, 1358, 14111, 402, 473, 76, 472, 79, 374, 737, 738, 4848, 6738, 13, 1049, 5282, 65, 1030, 60, 3134, 78 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 199, 3, 1898, 334, 67, 9, 7800, 710, 21158, 11672, 19782, 199, 3, 17484, 1334, 314, 10697, 2032, 4190, 12, 1937, 314, 23073, 199, 3, 570, 9685, 503, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 14, 199, 199, 646, 295, 199, 646, 15951, 199, 646, 984, 199, 646, 3873, 199, 646, 2197, 199, 646, 747, 199, 199, 13289, 199, 3, 570, 14545, 199, 13289, 199, 199, 1438, 13958, 275, 359, 272, 327, 1973, 261, 1850, 3912, 75, 17, 26, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2613, 15, 261, 1850, 3912, 75, 17, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2613, 15, 261, 1850, 3912, 75, 17, 63, 825, 7821, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2613, 15, 261, 1850, 3912, 75, 17, 63, 29920, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2613, 15, 261, 1850, 3912, 75, 17, 63, 15820, 6505, 82, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2164, 15, 6138, 15, 1308, 63, 22816, 63, 19675, 4933, 80, 3912, 75, 17, 14, 67, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2164, 15, 6138, 15, 1308, 63, 22816, 63, 19675, 4933, 80, 3912, 75, 17, 14, 72, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2164, 15, 6138, 15, 1308, 63, 22816, 63, 4933, 80, 3912, 75, 17, 2998, 14, 67, 297, 272, 283, 2164, 15, 261, 1850, 3912, 75, 17, 15, 2164, 15, 6138, 15, 1308, 63, 22816, 63, 4933, 80, 3912, 75, 17, 2998, 14, 72, 297, 272, 327, 2599, 4046, 26, 272, 283, 2164, 15, 5411, 585, 15, 773, 15, 5411, 585, 63, 3765, 83, 14, 72, 297, 272, 283, 2164, 15, 8440, 15, 22816, 5465, 14, 5910, 297, 272, 283, 2164, 15, 4429, 1162, 5176, 83, 14, 72, 297, 272, 327, 1163, 5957, 4248, 83, 26, 272, 283, 2164, 15, 9864, 908, 14, 72, 297, 272, 283, 2164, 15, 6972, 457, 66, 15, 1974, 15, 1813, 63, 2676, 14, 2055, 297, 272, 283, 2164, 15, 10316, 15, 319, 17499, 15, 16571, 14, 67, 297, 272, 283, 396, 15, 15481, 15, 396, 63, 4857, 15, 66, 1030, 453, 14, 647, 297, 272, 327, 2366, 4205, 26, 272, 6438, 363, 826, 4343, 647, 297, 199, 61, 199, 1438, 13958, 63, 6790, 11540, 275, 295, 14, 2014, 20137, 1370, 904, 779, 15359, 14, 5275, 8, 77, 9, 367, 333, 315, 3651, 13958, 2459, 199, 199, 18171, 275, 17855, 72, 297, 11937, 5910, 297, 11937, 2055, 297, 11937, 67, 297, 11937, 647, 418, 199, 18171, 63, 6790, 11540, 275, 295, 14, 2014, 20137, 1370, 904, 779, 15359, 14, 5275, 8, 77, 9, 367, 333, 315, 1621, 13958, 2459, 199, 199, 318, 12966, 63, 475, 63, 493, 8, 1501, 304, 272, 372, 3666, 1438, 13958, 63, 6790, 11540, 14, 1431, 8, 1501, 9, 365, 488, 9, 436, 288, 334, 18171, 63, 6790, 11540, 14, 1431, 8, 1501, 9, 365, 440, 488, 430, 199, 199, 13289, 199, 3, 3332, 769, 402, 1584, 315, 3831, 7182, 370, 1621, 13958, 436, 3651, 13958, 199, 13289, 199, 199, 20072, 63, 5296, 63, 9744, 275, 283, 3187, 9100, 13, 1725, 7, 199, 199, 318, 1240, 63, 3187, 63, 478, 837, 272, 734, 275, 3873, 14, 1074, 63, 1199, 8, 20072, 63, 5296, 63, 9744, 14, 1294, 360, 20005, 272, 372, 359, 70, 367, 289, 315, 734, 14, 2708, 480, 1624, 13, 24, 3471, 1294, 2258, 78, 358, 340, 289, 1137, 28696, 199, 199, 318, 664, 63, 10309, 63, 475, 63, 15425, 1132, 837, 272, 6203, 275, 1240, 63, 3187, 63, 478, 342, 272, 372, 3355, 779, 1501, 367, 1788, 315, 6203, 340, 673, 12966, 63, 475, 63, 493, 8, 1501, 3948, 199, 199, 13289, 199, 3, 5627, 436, 6555, 5163, 397, 367, 314, 7970, 781, 787, 10023, 367, 199, 13289, 421, 199, 32324, 5716, 63, 9139, 63, 35, 275, 283, 7384, 25445, 67, 60, 3171, 199, 32324, 5716, 63, 29946, 63, 35, 275, 283, 7384, 7, 199, 8974, 63, 32324, 5716, 63, 18466, 275, 25676, 83, 15287, 83, 3171, 450, 334, 32324, 5716, 63, 9139, 63, 35, 12, 5877, 63, 29946, 63, 35, 9, 199, 199, 19216, 275, 298, 1165, 59, 16, 13, 25, 1527, 16, 13, 25, 8480, 199, 19216, 63, 15167, 275, 25676, 83, 9, 2801, 5, 83, 5547, 7, 450, 334, 19216, 12, 1488, 15550, 9, 199, 19216, 63, 4924, 275, 25676, 83, 5130, 12, 450, 83, 20731, 450, 334, 19216, 12, 1488, 15550, 9, 199, 8974, 63, 19216, 63, 18466, 275, 25676, 83, 15287, 83, 3171, 450, 334, 19216, 63, 15167, 12, 1488, 15550, 63, 4924, 9, 199, 8974, 63, 32324, 5716, 63, 18466, 63, 726, 63, 19216, 63, 18466, 275, 19426, 83, 450, 83, 2, 450, 334, 8974, 63, 32324, 5716, 63, 18466, 12, 6059, 1821, 63, 19216, 63, 18466, 430, 199, 199, 8974, 63, 32324, 5716, 63, 6790, 11540, 275, 295, 14, 2014, 8, 8974, 63, 32324, 5716, 63, 18466, 63, 726, 63, 19216, 63, 18466, 9, 199, 199, 318, 6555, 63, 7307, 63, 3821, 8, 7307, 63, 2487, 12, 5361, 63, 2487, 12, 536, 304, 272, 372, 295, 14, 2014, 3508, 83, 450, 83, 450, 83, 7, 450, 334, 7307, 63, 2487, 12, 5361, 63, 2487, 12, 536, 430, 199, 199, 22358, 63, 40, 15744, 63, 14546, 275, 359, 272, 298, 51, 11318, 19377, 653, 1151, 455, 3459, 60, 78, 401, 272, 298, 1918, 21158, 11672, 19782, 60, 78, 401, 272, 298, 1918, 21158, 11672, 19782, 971, 78, 401, 272, 298, 4734, 9061, 11672, 23493, 60, 78, 401, 272, 298, 1589, 21158, 11672, 19782, 60, 78, 401, 272, 298, 1918, 21158, 19782, 60, 78, 401, 272, 298, 1918, 20400, 2846, 6642, 4537, 2900, 4481, 4644, 60, 3134, 78, 401, 272, 298, 4734, 10517, 3277, 60, 3134, 78, 401, 272, 298, 4734, 10517, 12, 3277, 60, 3134, 78, 401, 272, 298, 1358, 14111, 402, 473, 76, 472, 79, 374, 737, 738, 4848, 6738, 13, 1049, 5282, 65, 1030, 60, 3134, 78, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
szopu/django
django/contrib/admin/views/main.py
21
16837
from collections import OrderedDict import sys from django.core.exceptions import SuspiciousOperation, ImproperlyConfigured from django.core.paginator import InvalidPage from django.core.urlresolvers import reverse from django.db import models from django.db.models.fields import FieldDoesNotExist from django.utils import six from django.utils.encoding import force_text from django.utils.translation import ugettext, ugettext_lazy from django.utils.http import urlencode from django.contrib.admin import FieldListFilter from django.contrib.admin.exceptions import ( DisallowedModelAdminLookup, DisallowedModelAdminToField, ) from django.contrib.admin.options import IncorrectLookupParameters, IS_POPUP_VAR, TO_FIELD_VAR from django.contrib.admin.utils import (quote, get_fields_from_path, lookup_needs_distinct, prepare_lookup_value) # Changelist settings ALL_VAR = 'all' ORDER_VAR = 'o' ORDER_TYPE_VAR = 'ot' PAGE_VAR = 'p' SEARCH_VAR = 'q' ERROR_FLAG = 'e' IGNORED_PARAMS = ( ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR, TO_FIELD_VAR) # Text to display within change-list table cells if the value is blank. EMPTY_CHANGELIST_VALUE = ugettext_lazy('(None)') class ChangeList(object): def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, list_max_show_all, list_editable, model_admin): self.model = model self.opts = model._meta self.lookup_opts = self.opts self.root_queryset = model_admin.get_queryset(request) self.list_display = list_display self.list_display_links = list_display_links self.list_filter = list_filter self.date_hierarchy = date_hierarchy self.search_fields = search_fields self.list_select_related = list_select_related self.list_per_page = list_per_page self.list_max_show_all = list_max_show_all self.model_admin = model_admin self.preserved_filters = model_admin.get_preserved_filters(request) # Get search parameters from the query string. try: self.page_num = int(request.GET.get(PAGE_VAR, 0)) except ValueError: self.page_num = 0 self.show_all = ALL_VAR in request.GET self.is_popup = IS_POPUP_VAR in request.GET to_field = request.GET.get(TO_FIELD_VAR) if to_field and not model_admin.to_field_allowed(request, to_field): raise DisallowedModelAdminToField("The field %s cannot be referenced." % to_field) self.to_field = to_field self.params = dict(request.GET.items()) if PAGE_VAR in self.params: del self.params[PAGE_VAR] if ERROR_FLAG in self.params: del self.params[ERROR_FLAG] if self.is_popup: self.list_editable = () else: self.list_editable = list_editable self.query = request.GET.get(SEARCH_VAR, '') self.queryset = self.get_queryset(request) self.get_results(request) if self.is_popup: title = ugettext('Select %s') else: title = ugettext('Select %s to change') self.title = title % force_text(self.opts.verbose_name) self.pk_attname = self.lookup_opts.pk.attname def get_filters_params(self, params=None): """ Returns all params except IGNORED_PARAMS """ if not params: params = self.params lookup_params = params.copy() # a dictionary of the query string # Remove all the parameters that are globally and systematically # ignored. for ignored in IGNORED_PARAMS: if ignored in lookup_params: del lookup_params[ignored] return lookup_params def get_filters(self, request): lookup_params = self.get_filters_params() use_distinct = False for key, value in lookup_params.items(): if not self.model_admin.lookup_allowed(key, value): raise DisallowedModelAdminLookup("Filtering by %s not allowed" % key) filter_specs = [] if self.list_filter: for list_filter in self.list_filter: if callable(list_filter): # This is simply a custom list filter class. spec = list_filter(request, lookup_params, self.model, self.model_admin) else: field_path = None if isinstance(list_filter, (tuple, list)): # This is a custom FieldListFilter class for a given field. field, field_list_filter_class = list_filter else: # This is simply a field name, so use the default # FieldListFilter class that has been registered for # the type of the given field. field, field_list_filter_class = list_filter, FieldListFilter.create if not isinstance(field, models.Field): field_path = field field = get_fields_from_path(self.model, field_path)[-1] spec = field_list_filter_class(field, request, lookup_params, self.model, self.model_admin, field_path=field_path) # Check if we need to use distinct() use_distinct = (use_distinct or lookup_needs_distinct(self.lookup_opts, field_path)) if spec and spec.has_output(): filter_specs.append(spec) # At this point, all the parameters used by the various ListFilters # have been removed from lookup_params, which now only contains other # parameters passed via the query string. We now loop through the # remaining parameters both to ensure that all the parameters are valid # fields and to determine if at least one of them needs distinct(). If # the lookup parameters aren't real fields, then bail out. try: for key, value in lookup_params.items(): lookup_params[key] = prepare_lookup_value(key, value) use_distinct = (use_distinct or lookup_needs_distinct(self.lookup_opts, key)) return filter_specs, bool(filter_specs), lookup_params, use_distinct except FieldDoesNotExist as e: six.reraise(IncorrectLookupParameters, IncorrectLookupParameters(e), sys.exc_info()[2]) def get_query_string(self, new_params=None, remove=None): if new_params is None: new_params = {} if remove is None: remove = [] p = self.params.copy() for r in remove: for k in list(p): if k.startswith(r): del p[k] for k, v in new_params.items(): if v is None: if k in p: del p[k] else: p[k] = v return '?%s' % urlencode(sorted(p.items())) def get_results(self, request): paginator = self.model_admin.get_paginator(request, self.queryset, self.list_per_page) # Get the number of objects, with admin filters applied. result_count = paginator.count # Get the total number of objects, with no admin filters applied. # Perform a slight optimization: # full_result_count is equal to paginator.count if no filters # were applied if self.model_admin.show_full_result_count: if self.get_filters_params() or self.params.get(SEARCH_VAR): full_result_count = self.root_queryset.count() else: full_result_count = result_count else: full_result_count = None can_show_all = result_count <= self.list_max_show_all multi_page = result_count > self.list_per_page # Get the list of objects to display on this page. if (self.show_all and can_show_all) or not multi_page: result_list = self.queryset._clone() else: try: result_list = paginator.page(self.page_num + 1).object_list except InvalidPage: raise IncorrectLookupParameters self.result_count = result_count self.show_full_result_count = self.model_admin.show_full_result_count # Admin actions are shown if there is at least one entry # or if entries are not counted because show_full_result_count is disabled self.show_admin_actions = self.show_full_result_count or bool(full_result_count) self.full_result_count = full_result_count self.result_list = result_list self.can_show_all = can_show_all self.multi_page = multi_page self.paginator = paginator def _get_default_ordering(self): ordering = [] if self.model_admin.ordering: ordering = self.model_admin.ordering elif self.lookup_opts.ordering: ordering = self.lookup_opts.ordering return ordering def get_ordering_field(self, field_name): """ Returns the proper model field name corresponding to the given field_name to use for ordering. field_name may either be the name of a proper model field or the name of a method (on the admin or model) or a callable with the 'admin_order_field' attribute. Returns None if no proper model field name can be matched. """ try: field = self.lookup_opts.get_field(field_name) return field.name except models.FieldDoesNotExist: # See whether field_name is a name of a non-field # that allows sorting. if callable(field_name): attr = field_name elif hasattr(self.model_admin, field_name): attr = getattr(self.model_admin, field_name) else: attr = getattr(self.model, field_name) return getattr(attr, 'admin_order_field', None) def get_ordering(self, request, queryset): """ Returns the list of ordering fields for the change list. First we check the get_ordering() method in model admin, then we check the object's default ordering. Then, any manually-specified ordering from the query string overrides anything. Finally, a deterministic order is guaranteed by ensuring the primary key is used as the last ordering field. """ params = self.params ordering = list(self.model_admin.get_ordering(request) or self._get_default_ordering()) if ORDER_VAR in params: # Clear ordering and used params ordering = [] order_params = params[ORDER_VAR].split('.') for p in order_params: try: none, pfx, idx = p.rpartition('-') field_name = self.list_display[int(idx)] order_field = self.get_ordering_field(field_name) if not order_field: continue # No 'admin_order_field', skip it # reverse order if order_field has already "-" as prefix if order_field.startswith('-') and pfx == "-": ordering.append(order_field[1:]) else: ordering.append(pfx + order_field) except (IndexError, ValueError): continue # Invalid ordering specified, skip it. # Add the given query's ordering fields, if any. ordering.extend(queryset.query.order_by) # Ensure that the primary key is systematically present in the list of # ordering fields so we can guarantee a deterministic order across all # database backends. pk_name = self.lookup_opts.pk.name if not (set(ordering) & {'pk', '-pk', pk_name, '-' + pk_name}): # The two sets do not intersect, meaning the pk isn't present. So # we add it. ordering.append('-pk') return ordering def get_ordering_field_columns(self): """ Returns an OrderedDict of ordering field column numbers and asc/desc """ # We must cope with more than one column having the same underlying sort # field, so we base things on column numbers. ordering = self._get_default_ordering() ordering_fields = OrderedDict() if ORDER_VAR not in self.params: # for ordering specified on ModelAdmin or model Meta, we don't know # the right column numbers absolutely, because there might be more # than one column associated with that ordering, so we guess. for field in ordering: if field.startswith('-'): field = field[1:] order_type = 'desc' else: order_type = 'asc' for index, attr in enumerate(self.list_display): if self.get_ordering_field(attr) == field: ordering_fields[index] = order_type break else: for p in self.params[ORDER_VAR].split('.'): none, pfx, idx = p.rpartition('-') try: idx = int(idx) except ValueError: continue # skip it ordering_fields[idx] = 'desc' if pfx == '-' else 'asc' return ordering_fields def get_queryset(self, request): # First, we collect all the declared list filters. (self.filter_specs, self.has_filters, remaining_lookup_params, filters_use_distinct) = self.get_filters(request) # Then, we let every list filter modify the queryset to its liking. qs = self.root_queryset for filter_spec in self.filter_specs: new_qs = filter_spec.queryset(request, qs) if new_qs is not None: qs = new_qs try: # Finally, we apply the remaining lookup parameters from the query # string (i.e. those that haven't already been processed by the # filters). qs = qs.filter(**remaining_lookup_params) except (SuspiciousOperation, ImproperlyConfigured): # Allow certain types of errors to be re-raised as-is so that the # caller can treat them in a special way. raise except Exception as e: # Every other error is caught with a naked except, because we don't # have any other way of validating lookup parameters. They might be # invalid if the keyword arguments are incorrect, or if the values # are not in the correct type, so we might get FieldError, # ValueError, ValidationError, or ?. raise IncorrectLookupParameters(e) if not qs.query.select_related: qs = self.apply_select_related(qs) # Set ordering. ordering = self.get_ordering(request, qs) qs = qs.order_by(*ordering) # Apply search results qs, search_use_distinct = self.model_admin.get_search_results( request, qs, self.query) # Remove duplicates from results, if necessary if filters_use_distinct | search_use_distinct: return qs.distinct() else: return qs def apply_select_related(self, qs): if self.list_select_related is True: return qs.select_related() if self.list_select_related is False: if self.has_related_field_in_list_display(): return qs.select_related() if self.list_select_related: return qs.select_related(*self.list_select_related) return qs def has_related_field_in_list_display(self): for field_name in self.list_display: try: field = self.lookup_opts.get_field(field_name) except models.FieldDoesNotExist: pass else: if isinstance(field.rel, models.ManyToOneRel): return True return False def url_for_result(self, result): pk = getattr(result, self.pk_attname) return reverse('admin:%s_%s_change' % (self.opts.app_label, self.opts.model_name), args=(quote(pk),), current_app=self.model_admin.admin_site.name)
bsd-3-clause
[ 504, 5055, 492, 8773, 199, 646, 984, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 428, 28651, 6044, 12, 11897, 199, 504, 1639, 14, 1018, 14, 22073, 492, 6378, 3276, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 492, 29994, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 505, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 12, 10366, 63, 6395, 199, 504, 1639, 14, 1208, 14, 1014, 492, 16511, 199, 199, 504, 1639, 14, 2828, 14, 2113, 492, 5024, 24703, 199, 504, 1639, 14, 2828, 14, 2113, 14, 3924, 492, 334, 272, 5289, 6541, 12976, 7521, 12, 5289, 6541, 12976, 1378, 792, 12, 199, 9, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1419, 492, 1010, 4525, 7521, 5976, 12, 2281, 63, 13531, 2160, 63, 5568, 12, 2296, 63, 8609, 63, 5568, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1208, 492, 334, 3513, 12, 664, 63, 955, 63, 504, 63, 515, 12, 272, 4237, 63, 10065, 63, 12926, 12, 9275, 63, 3892, 63, 585, 9, 199, 199, 3, 7743, 513, 2202, 199, 1761, 63, 5568, 275, 283, 452, 7, 199, 12125, 63, 5568, 275, 283, 79, 7, 199, 12125, 63, 2711, 63, 5568, 275, 283, 357, 7, 199, 12898, 63, 5568, 275, 283, 80, 7, 199, 15962, 63, 5568, 275, 283, 81, 7, 199, 3170, 63, 3719, 275, 283, 69, 7, 199, 199, 3203, 25517, 63, 17978, 275, 334, 272, 11727, 63, 5568, 12, 16044, 63, 5568, 12, 16044, 63, 2711, 63, 5568, 12, 5795, 7762, 63, 5568, 12, 2281, 63, 13531, 2160, 63, 5568, 12, 2296, 63, 8609, 63, 5568, 9, 199, 199, 3, 4516, 370, 2929, 4453, 1570, 13, 513, 1817, 10106, 340, 314, 574, 365, 4596, 14, 199, 13993, 63, 16062, 4924, 63, 7041, 275, 10366, 63, 6395, 14097, 403, 5942, 421, 199, 533, 7743, 1296, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 1056, 12, 1402, 12, 769, 63, 2918, 12, 769, 63, 2918, 63, 4614, 12, 288, 769, 63, 1541, 12, 1434, 63, 14861, 12, 2754, 63, 955, 12, 769, 63, 2416, 63, 2407, 12, 288, 769, 63, 529, 63, 1606, 12, 769, 63, 988, 63, 2384, 63, 452, 12, 769, 63, 10820, 12, 1402, 63, 2113, 304, 267, 291, 14, 1238, 275, 1402, 267, 291, 14, 3291, 275, 1402, 423, 2024, 267, 291, 14, 3892, 63, 3291, 275, 291, 14, 3291, 267, 291, 14, 1231, 63, 7924, 275, 1402, 63, 2113, 14, 362, 63, 7924, 8, 1069, 9, 267, 291, 14, 513, 63, 2918, 275, 769, 63, 2918, 267, 291, 14, 513, 63, 2918, 63, 4614, 275, 769, 63, 2918, 63, 4614, 267, 291, 14, 513, 63, 1541, 275, 769, 63, 1541, 267, 291, 14, 602, 63, 14861, 275, 1434, 63, 14861, 267, 291, 14, 1733, 63, 955, 275, 2754, 63, 955, 267, 291, 14, 513, 63, 2416, 63, 2407, 275, 769, 63, 2416, 63, 2407, 267, 291, 14, 513, 63, 529, 63, 1606, 275, 769, 63, 529, 63, 1606, 267, 291, 14, 513, 63, 988, 63, 2384, 63, 452, 275, 769, 63, 988, 63, 2384, 63, 452, 267, 291, 14, 1238, 63, 2113, 275, 1402, 63, 2113, 267, 291, 14, 32104, 63, 4273, 275, 1402, 63, 2113, 14, 362, 63, 32104, 63, 4273, 8, 1069, 9, 398, 327, 2372, 2754, 2633, 687, 314, 1827, 1059, 14, 267, 862, 26, 288, 291, 14, 1606, 63, 1507, 275, 1109, 8, 1069, 14, 2970, 14, 362, 8, 12898, 63, 5568, 12, 378, 430, 267, 871, 1722, 26, 288, 291, 14, 1606, 63, 1507, 275, 378, 267, 291, 14, 2384, 63, 452, 275, 11727, 63, 5568, 315, 1056, 14, 2970, 267, 291, 14, 374, 63, 16020, 275, 2281, 63, 13531, 2160, 63, 5568, 315, 1056, 14, 2970, 267, 370, 63, 698, 275, 1056, 14, 2970, 14, 362, 8, 2566, 63, 8609, 63, 5568, 9, 267, 340, 370, 63, 698, 436, 440, 1402, 63, 2113, 14, 475, 63, 698, 63, 6541, 8, 1069, 12, 370, 63, 698, 304, 288, 746, 5289, 6541, 12976, 1378, 792, 480, 1918, 901, 450, 83, 3913, 506, 11812, 2122, 450, 370, 63, 698, 9, 267, 291, 14, 475, 63, 698, 275, 370, 63, 698, 267, 291, 14, 1162, 275, 1211, 8, 1069, 14, 2970, 14, 1744, 1012, 267, 340, 510, 2962, 63, 5568, 315, 291, 14, 1162, 26, 288, 2150, 291, 14, 1162, 59, 12898, 63, 5568, 61, 267, 340, 12539, 63, 3719, 315, 291, 14, 1162, 26, 288, 2150, 291, 14, 1162, 59, 3170, 63, 3719, 61, 398, 340, 291, 14, 374, 63, 16020, 26, 288, 291, 14, 513, 63, 10820, 275, 6248, 267, 587, 26, 288, 291, 14, 513, 63, 10820, 275, 769, 63, 10820, 267, 291, 14, 1131, 275, 1056, 14, 2970, 14, 362, 8, 15962, 63, 5568, 12, 4074, 267, 291, 14, 7924, 275, 291, 14, 362, 63, 7924, 8, 1069, 9, 267, 291, 14, 362, 63, 2604, 8, 1069, 9, 267, 340, 291, 14, 374, 63, 16020, 26, 288, 2538, 275, 10366, 360, 5446, 450, 83, 358, 267, 587, 26, 288, 2538, 275, 10366, 360, 5446, 450, 83, 370, 1570, 358, 267, 291, 14, 1213, 275, 2538, 450, 3542, 63, 505, 8, 277, 14, 3291, 14, 3832, 63, 354, 9, 267, 291, 14, 2051, 63, 13651, 275, 291, 14, 3892, 63, 3291, 14, 2051, 14, 13651, 339, 347, 664, 63, 4273, 63, 1162, 8, 277, 12, 1862, 29, 403, 304, 267, 408, 267, 1803, 1006, 1862, 871, 27499, 25517, 63, 17978, 267, 408, 267, 340, 440, 1862, 26, 288, 1862, 275, 291, 14, 1162, 267, 4237, 63, 1162, 275, 1862, 14, 1574, 342, 221, 327, 282, 2600, 402, 314, 1827, 1059, 267, 327, 5852, 1006, 314, 2633, 626, 787, 26662, 436, 984, 266, 17174, 267, 327, 5525, 14, 267, 367, 5525, 315, 27499, 25517, 63, 17978, 26, 288, 340, 5525, 315, 4237, 63, 1162, 26, 355, 2150, 4237, 63, 1162, 59, 11996, 61, 267, 372, 4237, 63, 1162, 339, 347, 664, 63, 4273, 8, 277, 12, 1056, 304, 267, 4237, 63, 1162, 275, 291, 14, 362, 63, 4273, 63, 1162 ]
[ 5055, 492, 8773, 199, 646, 984, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 428, 28651, 6044, 12, 11897, 199, 504, 1639, 14, 1018, 14, 22073, 492, 6378, 3276, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 492, 29994, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 505, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 12, 10366, 63, 6395, 199, 504, 1639, 14, 1208, 14, 1014, 492, 16511, 199, 199, 504, 1639, 14, 2828, 14, 2113, 492, 5024, 24703, 199, 504, 1639, 14, 2828, 14, 2113, 14, 3924, 492, 334, 272, 5289, 6541, 12976, 7521, 12, 5289, 6541, 12976, 1378, 792, 12, 199, 9, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1419, 492, 1010, 4525, 7521, 5976, 12, 2281, 63, 13531, 2160, 63, 5568, 12, 2296, 63, 8609, 63, 5568, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1208, 492, 334, 3513, 12, 664, 63, 955, 63, 504, 63, 515, 12, 272, 4237, 63, 10065, 63, 12926, 12, 9275, 63, 3892, 63, 585, 9, 199, 199, 3, 7743, 513, 2202, 199, 1761, 63, 5568, 275, 283, 452, 7, 199, 12125, 63, 5568, 275, 283, 79, 7, 199, 12125, 63, 2711, 63, 5568, 275, 283, 357, 7, 199, 12898, 63, 5568, 275, 283, 80, 7, 199, 15962, 63, 5568, 275, 283, 81, 7, 199, 3170, 63, 3719, 275, 283, 69, 7, 199, 199, 3203, 25517, 63, 17978, 275, 334, 272, 11727, 63, 5568, 12, 16044, 63, 5568, 12, 16044, 63, 2711, 63, 5568, 12, 5795, 7762, 63, 5568, 12, 2281, 63, 13531, 2160, 63, 5568, 12, 2296, 63, 8609, 63, 5568, 9, 199, 199, 3, 4516, 370, 2929, 4453, 1570, 13, 513, 1817, 10106, 340, 314, 574, 365, 4596, 14, 199, 13993, 63, 16062, 4924, 63, 7041, 275, 10366, 63, 6395, 14097, 403, 5942, 421, 199, 533, 7743, 1296, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 1056, 12, 1402, 12, 769, 63, 2918, 12, 769, 63, 2918, 63, 4614, 12, 288, 769, 63, 1541, 12, 1434, 63, 14861, 12, 2754, 63, 955, 12, 769, 63, 2416, 63, 2407, 12, 288, 769, 63, 529, 63, 1606, 12, 769, 63, 988, 63, 2384, 63, 452, 12, 769, 63, 10820, 12, 1402, 63, 2113, 304, 267, 291, 14, 1238, 275, 1402, 267, 291, 14, 3291, 275, 1402, 423, 2024, 267, 291, 14, 3892, 63, 3291, 275, 291, 14, 3291, 267, 291, 14, 1231, 63, 7924, 275, 1402, 63, 2113, 14, 362, 63, 7924, 8, 1069, 9, 267, 291, 14, 513, 63, 2918, 275, 769, 63, 2918, 267, 291, 14, 513, 63, 2918, 63, 4614, 275, 769, 63, 2918, 63, 4614, 267, 291, 14, 513, 63, 1541, 275, 769, 63, 1541, 267, 291, 14, 602, 63, 14861, 275, 1434, 63, 14861, 267, 291, 14, 1733, 63, 955, 275, 2754, 63, 955, 267, 291, 14, 513, 63, 2416, 63, 2407, 275, 769, 63, 2416, 63, 2407, 267, 291, 14, 513, 63, 529, 63, 1606, 275, 769, 63, 529, 63, 1606, 267, 291, 14, 513, 63, 988, 63, 2384, 63, 452, 275, 769, 63, 988, 63, 2384, 63, 452, 267, 291, 14, 1238, 63, 2113, 275, 1402, 63, 2113, 267, 291, 14, 32104, 63, 4273, 275, 1402, 63, 2113, 14, 362, 63, 32104, 63, 4273, 8, 1069, 9, 398, 327, 2372, 2754, 2633, 687, 314, 1827, 1059, 14, 267, 862, 26, 288, 291, 14, 1606, 63, 1507, 275, 1109, 8, 1069, 14, 2970, 14, 362, 8, 12898, 63, 5568, 12, 378, 430, 267, 871, 1722, 26, 288, 291, 14, 1606, 63, 1507, 275, 378, 267, 291, 14, 2384, 63, 452, 275, 11727, 63, 5568, 315, 1056, 14, 2970, 267, 291, 14, 374, 63, 16020, 275, 2281, 63, 13531, 2160, 63, 5568, 315, 1056, 14, 2970, 267, 370, 63, 698, 275, 1056, 14, 2970, 14, 362, 8, 2566, 63, 8609, 63, 5568, 9, 267, 340, 370, 63, 698, 436, 440, 1402, 63, 2113, 14, 475, 63, 698, 63, 6541, 8, 1069, 12, 370, 63, 698, 304, 288, 746, 5289, 6541, 12976, 1378, 792, 480, 1918, 901, 450, 83, 3913, 506, 11812, 2122, 450, 370, 63, 698, 9, 267, 291, 14, 475, 63, 698, 275, 370, 63, 698, 267, 291, 14, 1162, 275, 1211, 8, 1069, 14, 2970, 14, 1744, 1012, 267, 340, 510, 2962, 63, 5568, 315, 291, 14, 1162, 26, 288, 2150, 291, 14, 1162, 59, 12898, 63, 5568, 61, 267, 340, 12539, 63, 3719, 315, 291, 14, 1162, 26, 288, 2150, 291, 14, 1162, 59, 3170, 63, 3719, 61, 398, 340, 291, 14, 374, 63, 16020, 26, 288, 291, 14, 513, 63, 10820, 275, 6248, 267, 587, 26, 288, 291, 14, 513, 63, 10820, 275, 769, 63, 10820, 267, 291, 14, 1131, 275, 1056, 14, 2970, 14, 362, 8, 15962, 63, 5568, 12, 4074, 267, 291, 14, 7924, 275, 291, 14, 362, 63, 7924, 8, 1069, 9, 267, 291, 14, 362, 63, 2604, 8, 1069, 9, 267, 340, 291, 14, 374, 63, 16020, 26, 288, 2538, 275, 10366, 360, 5446, 450, 83, 358, 267, 587, 26, 288, 2538, 275, 10366, 360, 5446, 450, 83, 370, 1570, 358, 267, 291, 14, 1213, 275, 2538, 450, 3542, 63, 505, 8, 277, 14, 3291, 14, 3832, 63, 354, 9, 267, 291, 14, 2051, 63, 13651, 275, 291, 14, 3892, 63, 3291, 14, 2051, 14, 13651, 339, 347, 664, 63, 4273, 63, 1162, 8, 277, 12, 1862, 29, 403, 304, 267, 408, 267, 1803, 1006, 1862, 871, 27499, 25517, 63, 17978, 267, 408, 267, 340, 440, 1862, 26, 288, 1862, 275, 291, 14, 1162, 267, 4237, 63, 1162, 275, 1862, 14, 1574, 342, 221, 327, 282, 2600, 402, 314, 1827, 1059, 267, 327, 5852, 1006, 314, 2633, 626, 787, 26662, 436, 984, 266, 17174, 267, 327, 5525, 14, 267, 367, 5525, 315, 27499, 25517, 63, 17978, 26, 288, 340, 5525, 315, 4237, 63, 1162, 26, 355, 2150, 4237, 63, 1162, 59, 11996, 61, 267, 372, 4237, 63, 1162, 339, 347, 664, 63, 4273, 8, 277, 12, 1056, 304, 267, 4237, 63, 1162, 275, 291, 14, 362, 63, 4273, 63, 1162, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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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 ]
vipulroxx/sympy
sympy/matrices/expressions/inverse.py
84
2258
from __future__ import print_function, division from sympy.core.sympify import _sympify from sympy.core import S, Basic from sympy.matrices.expressions.matexpr import ShapeError from sympy.matrices.expressions.matpow import MatPow class Inverse(MatPow): """ The multiplicative inverse of a matrix expression This is a symbolic object that simply stores its argument without evaluating it. To actually compute the inverse, use the ``.inverse()`` method of matrices. Examples ======== >>> from sympy import MatrixSymbol, Inverse >>> A = MatrixSymbol('A', 3, 3) >>> B = MatrixSymbol('B', 3, 3) >>> Inverse(A) A^-1 >>> A.inverse() == Inverse(A) True >>> (A*B).inverse() B^-1*A^-1 >>> Inverse(A*B) (A*B)^-1 """ is_Inverse = True exp = S(-1) def __new__(cls, mat): mat = _sympify(mat) if not mat.is_Matrix: raise TypeError("mat should be a matrix") if not mat.is_square: raise ShapeError("Inverse of non-square matrix %s" % mat) return Basic.__new__(cls, mat) @property def arg(self): return self.args[0] @property def shape(self): return self.arg.shape def _eval_inverse(self): return self.arg def _eval_determinant(self): from sympy.matrices.expressions.determinant import det return 1/det(self.arg) def doit(self, **hints): if hints.get('deep', True): return self.arg.doit(**hints).inverse() else: return self.arg.inverse() from sympy.assumptions.ask import ask, Q from sympy.assumptions.refine import handlers_dict def refine_Inverse(expr, assumptions): """ >>> from sympy import MatrixSymbol, Q, assuming, refine >>> X = MatrixSymbol('X', 2, 2) >>> X.I X^-1 >>> with assuming(Q.orthogonal(X)): ... print(refine(X.I)) X' """ if ask(Q.orthogonal(expr), assumptions): return expr.arg.T elif ask(Q.unitary(expr), assumptions): return expr.arg.conjugate() elif ask(Q.singular(expr), assumptions): raise ValueError("Inverse of singular matrix %s" % expr.arg) return expr handlers_dict['Inverse'] = refine_Inverse
bsd-3-clause
[ 504, 636, 2443, 363, 492, 870, 63, 1593, 12, 4629, 199, 199, 504, 5840, 14, 1018, 14, 1786, 18456, 492, 485, 1786, 18456, 199, 504, 5840, 14, 1018, 492, 428, 12, 10082, 199, 199, 504, 5840, 14, 19032, 14, 15264, 14, 17684, 31149, 492, 16528, 547, 199, 504, 5840, 14, 19032, 14, 15264, 14, 569, 8278, 492, 18619, 23432, 421, 199, 533, 1010, 2077, 8, 14817, 23432, 304, 272, 408, 272, 710, 8897, 606, 1905, 11484, 402, 282, 3634, 3965, 339, 961, 365, 282, 13673, 909, 626, 9329, 14086, 2399, 1423, 1928, 272, 27083, 652, 14, 4005, 5965, 4526, 314, 11484, 12, 675, 314, 21502, 11668, 8497, 272, 1083, 402, 12627, 14, 339, 6058, 272, 12655, 339, 1306, 687, 5840, 492, 8449, 8169, 12, 1010, 2077, 272, 1306, 437, 275, 8449, 8169, 360, 33, 297, 650, 12, 650, 9, 272, 1306, 699, 275, 8449, 8169, 360, 34, 297, 650, 12, 650, 9, 272, 1306, 1010, 2077, 8, 33, 9, 272, 437, 26185, 17, 272, 1306, 437, 14, 11668, 342, 508, 1010, 2077, 8, 33, 9, 272, 715, 272, 1306, 334, 33, 10, 34, 680, 11668, 342, 272, 699, 26185, 17, 10, 33, 26185, 17, 272, 1306, 1010, 2077, 8, 33, 10, 34, 9, 272, 334, 33, 10, 34, 18979, 13, 17, 339, 408, 272, 365, 63, 28274, 275, 715, 272, 1437, 275, 428, 2801, 17, 9, 339, 347, 636, 1222, 721, 1886, 12, 2530, 304, 267, 2530, 275, 485, 1786, 18456, 8, 569, 9, 267, 340, 440, 2530, 14, 374, 63, 6443, 26, 288, 746, 3146, 480, 569, 1077, 506, 282, 3634, 531, 267, 340, 440, 2530, 14, 374, 63, 9646, 26, 288, 746, 16528, 547, 480, 28274, 402, 2222, 13, 9646, 3634, 450, 83, 2, 450, 2530, 9, 267, 372, 10082, 855, 1222, 721, 1886, 12, 2530, 9, 339, 768, 1829, 272, 347, 1680, 8, 277, 304, 267, 372, 291, 14, 589, 59, 16, 61, 339, 768, 1829, 272, 347, 2215, 8, 277, 304, 267, 372, 291, 14, 1273, 14, 1392, 339, 347, 485, 2579, 63, 11668, 8, 277, 304, 267, 372, 291, 14, 1273, 339, 347, 485, 2579, 63, 17061, 867, 8, 277, 304, 267, 687, 5840, 14, 19032, 14, 15264, 14, 17061, 867, 492, 20894, 267, 372, 413, 15, 9886, 8, 277, 14, 1273, 9, 339, 347, 886, 390, 8, 277, 12, 1011, 12354, 304, 267, 340, 18069, 14, 362, 360, 16131, 297, 715, 304, 288, 372, 291, 14, 1273, 14, 19014, 3682, 12354, 680, 11668, 342, 267, 587, 26, 288, 372, 291, 14, 1273, 14, 11668, 342, 421, 199, 504, 5840, 14, 405, 18064, 14, 813, 492, 7198, 12, 1413, 199, 504, 5840, 14, 405, 18064, 14, 1121, 1132, 492, 8297, 63, 807, 421, 199, 318, 2984, 1132, 63, 28274, 8, 3684, 12, 21546, 304, 272, 408, 272, 1306, 687, 5840, 492, 8449, 8169, 12, 1413, 12, 18002, 12, 2984, 1132, 272, 1306, 1323, 275, 8449, 8169, 360, 56, 297, 499, 12, 499, 9, 272, 1306, 1323, 14, 41, 272, 1323, 26185, 17, 272, 1306, 543, 18002, 8, 49, 14, 11297, 19133, 8, 56, 2298, 272, 2263, 258, 870, 8, 1121, 1132, 8, 56, 14, 41, 430, 272, 1323, 7, 272, 408, 272, 340, 7198, 8, 49, 14, 11297, 19133, 8, 3684, 395, 21546, 304, 267, 372, 5348, 14, 1273, 14, 52, 272, 916, 7198, 8, 49, 14, 3248, 695, 8, 3684, 395, 21546, 304, 267, 372, 5348, 14, 1273, 14, 26000, 342, 272, 916, 7198, 8, 49, 14, 17045, 8, 3684, 395, 21546, 304, 267, 746, 1722, 480, 28274, 402, 15823, 3634, 450, 83, 2, 450, 5348, 14, 1273, 9, 339, 372, 5348, 199, 199, 5586, 63, 807, 459, 28274, 418, 275, 2984, 1132, 63, 28274, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 870, 63, 1593, 12, 4629, 199, 199, 504, 5840, 14, 1018, 14, 1786, 18456, 492, 485, 1786, 18456, 199, 504, 5840, 14, 1018, 492, 428, 12, 10082, 199, 199, 504, 5840, 14, 19032, 14, 15264, 14, 17684, 31149, 492, 16528, 547, 199, 504, 5840, 14, 19032, 14, 15264, 14, 569, 8278, 492, 18619, 23432, 421, 199, 533, 1010, 2077, 8, 14817, 23432, 304, 272, 408, 272, 710, 8897, 606, 1905, 11484, 402, 282, 3634, 3965, 339, 961, 365, 282, 13673, 909, 626, 9329, 14086, 2399, 1423, 1928, 272, 27083, 652, 14, 4005, 5965, 4526, 314, 11484, 12, 675, 314, 21502, 11668, 8497, 272, 1083, 402, 12627, 14, 339, 6058, 272, 12655, 339, 1306, 687, 5840, 492, 8449, 8169, 12, 1010, 2077, 272, 1306, 437, 275, 8449, 8169, 360, 33, 297, 650, 12, 650, 9, 272, 1306, 699, 275, 8449, 8169, 360, 34, 297, 650, 12, 650, 9, 272, 1306, 1010, 2077, 8, 33, 9, 272, 437, 26185, 17, 272, 1306, 437, 14, 11668, 342, 508, 1010, 2077, 8, 33, 9, 272, 715, 272, 1306, 334, 33, 10, 34, 680, 11668, 342, 272, 699, 26185, 17, 10, 33, 26185, 17, 272, 1306, 1010, 2077, 8, 33, 10, 34, 9, 272, 334, 33, 10, 34, 18979, 13, 17, 339, 408, 272, 365, 63, 28274, 275, 715, 272, 1437, 275, 428, 2801, 17, 9, 339, 347, 636, 1222, 721, 1886, 12, 2530, 304, 267, 2530, 275, 485, 1786, 18456, 8, 569, 9, 267, 340, 440, 2530, 14, 374, 63, 6443, 26, 288, 746, 3146, 480, 569, 1077, 506, 282, 3634, 531, 267, 340, 440, 2530, 14, 374, 63, 9646, 26, 288, 746, 16528, 547, 480, 28274, 402, 2222, 13, 9646, 3634, 450, 83, 2, 450, 2530, 9, 267, 372, 10082, 855, 1222, 721, 1886, 12, 2530, 9, 339, 768, 1829, 272, 347, 1680, 8, 277, 304, 267, 372, 291, 14, 589, 59, 16, 61, 339, 768, 1829, 272, 347, 2215, 8, 277, 304, 267, 372, 291, 14, 1273, 14, 1392, 339, 347, 485, 2579, 63, 11668, 8, 277, 304, 267, 372, 291, 14, 1273, 339, 347, 485, 2579, 63, 17061, 867, 8, 277, 304, 267, 687, 5840, 14, 19032, 14, 15264, 14, 17061, 867, 492, 20894, 267, 372, 413, 15, 9886, 8, 277, 14, 1273, 9, 339, 347, 886, 390, 8, 277, 12, 1011, 12354, 304, 267, 340, 18069, 14, 362, 360, 16131, 297, 715, 304, 288, 372, 291, 14, 1273, 14, 19014, 3682, 12354, 680, 11668, 342, 267, 587, 26, 288, 372, 291, 14, 1273, 14, 11668, 342, 421, 199, 504, 5840, 14, 405, 18064, 14, 813, 492, 7198, 12, 1413, 199, 504, 5840, 14, 405, 18064, 14, 1121, 1132, 492, 8297, 63, 807, 421, 199, 318, 2984, 1132, 63, 28274, 8, 3684, 12, 21546, 304, 272, 408, 272, 1306, 687, 5840, 492, 8449, 8169, 12, 1413, 12, 18002, 12, 2984, 1132, 272, 1306, 1323, 275, 8449, 8169, 360, 56, 297, 499, 12, 499, 9, 272, 1306, 1323, 14, 41, 272, 1323, 26185, 17, 272, 1306, 543, 18002, 8, 49, 14, 11297, 19133, 8, 56, 2298, 272, 2263, 258, 870, 8, 1121, 1132, 8, 56, 14, 41, 430, 272, 1323, 7, 272, 408, 272, 340, 7198, 8, 49, 14, 11297, 19133, 8, 3684, 395, 21546, 304, 267, 372, 5348, 14, 1273, 14, 52, 272, 916, 7198, 8, 49, 14, 3248, 695, 8, 3684, 395, 21546, 304, 267, 372, 5348, 14, 1273, 14, 26000, 342, 272, 916, 7198, 8, 49, 14, 17045, 8, 3684, 395, 21546, 304, 267, 746, 1722, 480, 28274, 402, 15823, 3634, 450, 83, 2, 450, 5348, 14, 1273, 9, 339, 372, 5348, 199, 199, 5586, 63, 807, 459, 28274, 418, 275, 2984, 1132, 63, 28274, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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,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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 ]
Kongsea/tensorflow
tensorflow/contrib/gan/python/losses/python/losses_impl.py
20
36658
# Copyright 2017 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Losses that are useful for training GANs. The losses belong to two main groups, but there are others that do not: 1) xxxxx_generator_loss 2) xxxxx_discriminator_loss Example: 1) wasserstein_generator_loss 2) wasserstein_discriminator_loss Other example: wasserstein_gradient_penalty All losses must be able to accept 1D or 2D Tensors, so as to be compatible with patchGAN style losses (https://arxiv.org/abs/1611.07004). To make these losses usable in the TFGAN framework, please create a tuple version of the losses with `losses_utils.py`. """ from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy as np from tensorflow.contrib.framework.python.ops import variables as contrib_variables_lib from tensorflow.python.framework import ops from tensorflow.python.framework import tensor_util from tensorflow.python.ops import array_ops from tensorflow.python.ops import clip_ops from tensorflow.python.ops import gradients_impl from tensorflow.python.ops import math_ops from tensorflow.python.ops import random_ops from tensorflow.python.ops import variable_scope from tensorflow.python.ops.distributions import distribution as ds from tensorflow.python.ops.losses import losses from tensorflow.python.ops.losses import util from tensorflow.python.summary import summary __all__ = [ 'acgan_discriminator_loss', 'acgan_generator_loss', 'least_squares_discriminator_loss', 'least_squares_generator_loss', 'modified_discriminator_loss', 'modified_generator_loss', 'minimax_discriminator_loss', 'minimax_generator_loss', 'wasserstein_discriminator_loss', 'wasserstein_generator_loss', 'wasserstein_gradient_penalty', 'mutual_information_penalty', 'combine_adversarial_loss', ] # Wasserstein losses from `Wasserstein GAN` (https://arxiv.org/abs/1701.07875). def wasserstein_generator_loss( discriminator_gen_outputs, weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """Wasserstein generator loss for GANs. See `Wasserstein GAN` (https://arxiv.org/abs/1701.07875) for more details. Args: discriminator_gen_outputs: Discriminator output on generated data. Expected to be in the range of (-inf, inf). weights: Optional `Tensor` whose rank is either 0, or the same rank as `discriminator_gen_outputs`, and must be broadcastable to `discriminator_gen_outputs` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add detailed summaries for the loss. Returns: A loss Tensor. The shape depends on `reduction`. """ with ops.name_scope(scope, 'generator_wasserstein_loss', ( discriminator_gen_outputs, weights)) as scope: discriminator_gen_outputs = math_ops.to_float(discriminator_gen_outputs) loss = - discriminator_gen_outputs loss = losses.compute_weighted_loss( loss, weights, scope, loss_collection, reduction) if add_summaries: summary.scalar('generator_wass_loss', loss) return loss def wasserstein_discriminator_loss( discriminator_real_outputs, discriminator_gen_outputs, real_weights=1.0, generated_weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """Wasserstein discriminator loss for GANs. See `Wasserstein GAN` (https://arxiv.org/abs/1701.07875) for more details. Args: discriminator_real_outputs: Discriminator output on real data. discriminator_gen_outputs: Discriminator output on generated data. Expected to be in the range of (-inf, inf). real_weights: Optional `Tensor` whose rank is either 0, or the same rank as `discriminator_real_outputs`, and must be broadcastable to `discriminator_real_outputs` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). generated_weights: Same as `real_weights`, but for `discriminator_gen_outputs`. scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. The shape depends on `reduction`. """ with ops.name_scope(scope, 'discriminator_wasserstein_loss', ( discriminator_real_outputs, discriminator_gen_outputs, real_weights, generated_weights)) as scope: discriminator_real_outputs = math_ops.to_float(discriminator_real_outputs) discriminator_gen_outputs = math_ops.to_float(discriminator_gen_outputs) discriminator_real_outputs.shape.assert_is_compatible_with( discriminator_gen_outputs.shape) loss_on_generated = losses.compute_weighted_loss( discriminator_gen_outputs, generated_weights, scope, loss_collection=None, reduction=reduction) loss_on_real = losses.compute_weighted_loss( discriminator_real_outputs, real_weights, scope, loss_collection=None, reduction=reduction) loss = loss_on_generated - loss_on_real util.add_loss(loss, loss_collection) if add_summaries: summary.scalar('discriminator_gen_wass_loss', loss_on_generated) summary.scalar('discriminator_real_wass_loss', loss_on_real) summary.scalar('discriminator_wass_loss', loss) return loss # ACGAN losses from `Conditional Image Synthesis With Auxiliary Classifier GANs` # (https://arxiv.org/abs/1610.09585). def acgan_discriminator_loss( discriminator_real_classification_logits, discriminator_gen_classification_logits, one_hot_labels, label_smoothing=0.0, real_weights=1.0, generated_weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """ACGAN loss for the discriminator. The ACGAN loss adds a classification loss to the conditional discriminator. Therefore, the discriminator must output a tuple consisting of (1) the real/fake prediction and (2) the logits for the classification (usually the last conv layer, flattened). For more details: ACGAN: https://arxiv.org/abs/1610.09585 Args: discriminator_real_classification_logits: Classification logits for real data. discriminator_gen_classification_logits: Classification logits for generated data. one_hot_labels: A Tensor holding one-hot labels for the batch. label_smoothing: A float in [0, 1]. If greater than 0, smooth the labels for "discriminator on real data" as suggested in https://arxiv.org/pdf/1701.00160 real_weights: Optional `Tensor` whose rank is either 0, or the same rank as `discriminator_real_outputs`, and must be broadcastable to `discriminator_real_outputs` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). generated_weights: Same as `real_weights`, but for `discriminator_gen_classification_logits`. scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. Shape depends on `reduction`. Raises: TypeError: If the discriminator does not output a tuple. """ with ops.name_scope( scope, 'acgan_discriminator_loss', (discriminator_real_classification_logits, discriminator_gen_classification_logits, one_hot_labels)) as scope: loss_on_generated = losses.softmax_cross_entropy( one_hot_labels, discriminator_gen_classification_logits, weights=generated_weights, scope=scope, loss_collection=None, reduction=reduction) loss_on_real = losses.softmax_cross_entropy( one_hot_labels, discriminator_real_classification_logits, weights=real_weights, label_smoothing=label_smoothing, scope=scope, loss_collection=None, reduction=reduction) loss = loss_on_generated + loss_on_real util.add_loss(loss, loss_collection) if add_summaries: summary.scalar('discriminator_gen_ac_loss', loss_on_generated) summary.scalar('discriminator_real_ac_loss', loss_on_real) summary.scalar('discriminator_ac_loss', loss) return loss def acgan_generator_loss( discriminator_gen_classification_logits, one_hot_labels, weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """ACGAN loss for the generator. The ACGAN loss adds a classification loss to the conditional discriminator. Therefore, the discriminator must output a tuple consisting of (1) the real/fake prediction and (2) the logits for the classification (usually the last conv layer, flattened). For more details: ACGAN: https://arxiv.org/abs/1610.09585 Args: discriminator_gen_classification_logits: Classification logits for generated data. one_hot_labels: A Tensor holding one-hot labels for the batch. weights: Optional `Tensor` whose rank is either 0, or the same rank as `discriminator_gen_classification_logits`, and must be broadcastable to `discriminator_gen_classification_logits` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. Shape depends on `reduction`. Raises: ValueError: if arg module not either `generator` or `discriminator` TypeError: if the discriminator does not output a tuple. """ with ops.name_scope( scope, 'acgan_generator_loss', (discriminator_gen_classification_logits, one_hot_labels)) as scope: loss = losses.softmax_cross_entropy( one_hot_labels, discriminator_gen_classification_logits, weights=weights, scope=scope, loss_collection=loss_collection, reduction=reduction) if add_summaries: summary.scalar('generator_ac_loss', loss) return loss # Wasserstein Gradient Penalty losses from `Improved Training of Wasserstein # GANs` (https://arxiv.org/abs/1704.00028). def wasserstein_gradient_penalty( real_data, generated_data, generator_inputs, discriminator_fn, discriminator_scope, epsilon=1e-10, weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """The gradient penalty for the Wasserstein discriminator loss. See `Improved Training of Wasserstein GANs` (https://arxiv.org/abs/1704.00028) for more details. Args: real_data: Real data. generated_data: Output of the generator. generator_inputs: Exact argument to pass to the generator, which is used as optional conditioning to the discriminator. discriminator_fn: A discriminator function that conforms to TFGAN API. discriminator_scope: If not `None`, reuse discriminators from this scope. epsilon: A small positive number added for numerical stability when computing the gradient norm. weights: Optional `Tensor` whose rank is either 0, or the same rank as `real_data` and `generated_data`, and must be broadcastable to them (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. The shape depends on `reduction`. Raises: ValueError: If the rank of data Tensors is unknown. """ with ops.name_scope(scope, 'wasserstein_gradient_penalty', (real_data, generated_data)) as scope: real_data = ops.convert_to_tensor(real_data) generated_data = ops.convert_to_tensor(generated_data) if real_data.shape.ndims is None: raise ValueError('`real_data` can\'t have unknown rank.') if generated_data.shape.ndims is None: raise ValueError('`generated_data` can\'t have unknown rank.') differences = generated_data - real_data batch_size = differences.shape[0].value or array_ops.shape(differences)[0] alpha_shape = [batch_size] + [1] * (differences.shape.ndims - 1) alpha = random_ops.random_uniform(shape=alpha_shape) interpolates = real_data + (alpha * differences) with ops.name_scope(None): # Clear scope so update ops are added properly. # Reuse variables if variables already exists. with variable_scope.variable_scope(discriminator_scope, 'gpenalty_dscope', reuse=variable_scope.AUTO_REUSE): disc_interpolates = discriminator_fn(interpolates, generator_inputs) if isinstance(disc_interpolates, tuple): # ACGAN case: disc outputs more than one tensor disc_interpolates = disc_interpolates[0] gradients = gradients_impl.gradients(disc_interpolates, interpolates)[0] gradient_squares = math_ops.reduce_sum( math_ops.square(gradients), axis=list(range(1, gradients.shape.ndims))) # Propagate shape information, if possible. if isinstance(batch_size, int): gradient_squares.set_shape([ batch_size] + gradient_squares.shape.as_list()[1:]) # For numerical stability, add epsilon to the sum before taking the square # root. Note tf.norm does not add epsilon. slopes = math_ops.sqrt(gradient_squares + epsilon) penalties = math_ops.square(slopes - 1.0) penalty = losses.compute_weighted_loss( penalties, weights, scope=scope, loss_collection=loss_collection, reduction=reduction) if add_summaries: summary.scalar('gradient_penalty_loss', penalty) return penalty # Original losses from `Generative Adversarial Nets` # (https://arxiv.org/abs/1406.2661). def minimax_discriminator_loss( discriminator_real_outputs, discriminator_gen_outputs, label_smoothing=0.25, real_weights=1.0, generated_weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """Original minimax discriminator loss for GANs, with label smoothing. Note that the authors don't recommend using this loss. A more practically useful loss is `modified_discriminator_loss`. L = - real_weights * log(sigmoid(D(x))) - generated_weights * log(1 - sigmoid(D(G(z)))) See `Generative Adversarial Nets` (https://arxiv.org/abs/1406.2661) for more details. Args: discriminator_real_outputs: Discriminator output on real data. discriminator_gen_outputs: Discriminator output on generated data. Expected to be in the range of (-inf, inf). label_smoothing: The amount of smoothing for positive labels. This technique is taken from `Improved Techniques for Training GANs` (https://arxiv.org/abs/1606.03498). `0.0` means no smoothing. real_weights: Optional `Tensor` whose rank is either 0, or the same rank as `real_data`, and must be broadcastable to `real_data` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). generated_weights: Same as `real_weights`, but for `generated_data`. scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. The shape depends on `reduction`. """ with ops.name_scope(scope, 'discriminator_minimax_loss', ( discriminator_real_outputs, discriminator_gen_outputs, real_weights, generated_weights, label_smoothing)) as scope: # -log((1 - label_smoothing) - sigmoid(D(x))) loss_on_real = losses.sigmoid_cross_entropy( array_ops.ones_like(discriminator_real_outputs), discriminator_real_outputs, real_weights, label_smoothing, scope, loss_collection=None, reduction=reduction) # -log(- sigmoid(D(G(x)))) loss_on_generated = losses.sigmoid_cross_entropy( array_ops.zeros_like(discriminator_gen_outputs), discriminator_gen_outputs, generated_weights, scope=scope, loss_collection=None, reduction=reduction) loss = loss_on_real + loss_on_generated util.add_loss(loss, loss_collection) if add_summaries: summary.scalar('discriminator_gen_minimax_loss', loss_on_generated) summary.scalar('discriminator_real_minimax_loss', loss_on_real) summary.scalar('discriminator_minimax_loss', loss) return loss def minimax_generator_loss( discriminator_gen_outputs, label_smoothing=0.0, weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """Original minimax generator loss for GANs. Note that the authors don't recommend using this loss. A more practically useful loss is `modified_generator_loss`. L = log(sigmoid(D(x))) + log(1 - sigmoid(D(G(z)))) See `Generative Adversarial Nets` (https://arxiv.org/abs/1406.2661) for more details. Args: discriminator_gen_outputs: Discriminator output on generated data. Expected to be in the range of (-inf, inf). label_smoothing: The amount of smoothing for positive labels. This technique is taken from `Improved Techniques for Training GANs` (https://arxiv.org/abs/1606.03498). `0.0` means no smoothing. weights: Optional `Tensor` whose rank is either 0, or the same rank as `discriminator_gen_outputs`, and must be broadcastable to `discriminator_gen_outputs` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. The shape depends on `reduction`. """ with ops.name_scope(scope, 'generator_minimax_loss') as scope: loss = - minimax_discriminator_loss( array_ops.ones_like(discriminator_gen_outputs), discriminator_gen_outputs, label_smoothing, weights, weights, scope, loss_collection, reduction, add_summaries=False) if add_summaries: summary.scalar('generator_minimax_loss', loss) return loss def modified_discriminator_loss( discriminator_real_outputs, discriminator_gen_outputs, label_smoothing=0.25, real_weights=1.0, generated_weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """Same as minimax discriminator loss. See `Generative Adversarial Nets` (https://arxiv.org/abs/1406.2661) for more details. Args: discriminator_real_outputs: Discriminator output on real data. discriminator_gen_outputs: Discriminator output on generated data. Expected to be in the range of (-inf, inf). label_smoothing: The amount of smoothing for positive labels. This technique is taken from `Improved Techniques for Training GANs` (https://arxiv.org/abs/1606.03498). `0.0` means no smoothing. real_weights: Optional `Tensor` whose rank is either 0, or the same rank as `discriminator_gen_outputs`, and must be broadcastable to `discriminator_gen_outputs` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). generated_weights: Same as `real_weights`, but for `discriminator_gen_outputs`. scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. The shape depends on `reduction`. """ return minimax_discriminator_loss( discriminator_real_outputs, discriminator_gen_outputs, label_smoothing, real_weights, generated_weights, scope or 'discriminator_modified_loss', loss_collection, reduction, add_summaries) def modified_generator_loss( discriminator_gen_outputs, label_smoothing=0.0, weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """Modified generator loss for GANs. L = -log(sigmoid(D(G(z)))) This is the trick used in the original paper to avoid vanishing gradients early in training. See `Generative Adversarial Nets` (https://arxiv.org/abs/1406.2661) for more details. Args: discriminator_gen_outputs: Discriminator output on generated data. Expected to be in the range of (-inf, inf). label_smoothing: The amount of smoothing for positive labels. This technique is taken from `Improved Techniques for Training GANs` (https://arxiv.org/abs/1606.03498). `0.0` means no smoothing. weights: Optional `Tensor` whose rank is either 0, or the same rank as `discriminator_gen_outputs`, and must be broadcastable to `labels` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. The shape depends on `reduction`. """ with ops.name_scope(scope, 'generator_modified_loss', [discriminator_gen_outputs]) as scope: loss = losses.sigmoid_cross_entropy( array_ops.ones_like(discriminator_gen_outputs), discriminator_gen_outputs, weights, label_smoothing, scope, loss_collection, reduction) if add_summaries: summary.scalar('generator_modified_loss', loss) return loss # Least Squares loss from `Least Squares Generative Adversarial Networks` # (https://arxiv.org/abs/1611.04076). def least_squares_generator_loss( discriminator_gen_outputs, real_label=1, weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """Least squares generator loss. This loss comes from `Least Squares Generative Adversarial Networks` (https://arxiv.org/abs/1611.04076). L = 1/2 * (D(G(z)) - `real_label`) ** 2 where D(y) are discriminator logits. Args: discriminator_gen_outputs: Discriminator output on generated data. Expected to be in the range of (-inf, inf). real_label: The value that the generator is trying to get the discriminator to output on generated data. weights: Optional `Tensor` whose rank is either 0, or the same rank as `discriminator_gen_outputs`, and must be broadcastable to `discriminator_gen_outputs` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. The shape depends on `reduction`. """ with ops.name_scope(scope, 'lsq_generator_loss', (discriminator_gen_outputs, real_label)) as scope: discriminator_gen_outputs = math_ops.to_float(discriminator_gen_outputs) loss = math_ops.squared_difference( discriminator_gen_outputs, real_label) / 2.0 loss = losses.compute_weighted_loss( loss, weights, scope, loss_collection, reduction) if add_summaries: summary.scalar('generator_lsq_loss', loss) return loss def least_squares_discriminator_loss( discriminator_real_outputs, discriminator_gen_outputs, real_label=1, fake_label=0, real_weights=1.0, generated_weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """Least squares generator loss. This loss comes from `Least Squares Generative Adversarial Networks` (https://arxiv.org/abs/1611.04076). L = 1/2 * (D(x) - `real`) ** 2 + 1/2 * (D(G(z)) - `fake_label`) ** 2 where D(y) are discriminator logits. Args: discriminator_real_outputs: Discriminator output on real data. discriminator_gen_outputs: Discriminator output on generated data. Expected to be in the range of (-inf, inf). real_label: The value that the discriminator tries to output for real data. fake_label: The value that the discriminator tries to output for fake data. real_weights: Optional `Tensor` whose rank is either 0, or the same rank as `discriminator_real_outputs`, and must be broadcastable to `discriminator_real_outputs` (i.e., all dimensions must be either `1`, or the same as the corresponding dimension). generated_weights: Same as `real_weights`, but for `discriminator_gen_outputs`. scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A loss Tensor. The shape depends on `reduction`. """ with ops.name_scope(scope, 'lsq_discriminator_loss', (discriminator_gen_outputs, real_label)) as scope: discriminator_real_outputs = math_ops.to_float(discriminator_real_outputs) discriminator_gen_outputs = math_ops.to_float(discriminator_gen_outputs) discriminator_real_outputs.shape.assert_is_compatible_with( discriminator_gen_outputs.shape) real_losses = math_ops.squared_difference( discriminator_real_outputs, real_label) / 2.0 fake_losses = math_ops.squared_difference( discriminator_gen_outputs, fake_label) / 2.0 loss_on_real = losses.compute_weighted_loss( real_losses, real_weights, scope, loss_collection=None, reduction=reduction) loss_on_generated = losses.compute_weighted_loss( fake_losses, generated_weights, scope, loss_collection=None, reduction=reduction) loss = loss_on_real + loss_on_generated util.add_loss(loss, loss_collection) if add_summaries: summary.scalar('discriminator_gen_lsq_loss', loss_on_generated) summary.scalar('discriminator_real_lsq_loss', loss_on_real) summary.scalar('discriminator_lsq_loss', loss) return loss # InfoGAN loss from `InfoGAN: Interpretable Representation Learning by # `Information Maximizing Generative Adversarial Nets` # https://arxiv.org/abs/1606.03657 def _validate_distributions(distributions): if not isinstance(distributions, (list, tuple)): raise ValueError('`distributions` must be a list or tuple. Instead, ' 'found %s.', type(distributions)) for x in distributions: if not isinstance(x, ds.Distribution): raise ValueError('`distributions` must be a list of `Distributions`. ' 'Instead, found %s.', type(x)) def _validate_information_penalty_inputs( structured_generator_inputs, predicted_distributions): """Validate input to `mutual_information_penalty`.""" _validate_distributions(predicted_distributions) if len(structured_generator_inputs) != len(predicted_distributions): raise ValueError('`structured_generator_inputs` length %i must be the same ' 'as `predicted_distributions` length %i.' % ( len(structured_generator_inputs), len(predicted_distributions))) def mutual_information_penalty( structured_generator_inputs, predicted_distributions, weights=1.0, scope=None, loss_collection=ops.GraphKeys.LOSSES, reduction=losses.Reduction.SUM_BY_NONZERO_WEIGHTS, add_summaries=False): """Returns a penalty on the mutual information in an InfoGAN model. This loss comes from an InfoGAN paper https://arxiv.org/abs/1606.03657. Args: structured_generator_inputs: A list of Tensors representing the random noise that must have high mutual information with the generator output. List length should match `predicted_distributions`. predicted_distributions: A list of tf.Distributions. Predicted by the recognizer, and used to evaluate the likelihood of the structured noise. List length should match `structured_generator_inputs`. weights: Optional `Tensor` whose rank is either 0, or the same dimensions as `structured_generator_inputs`. scope: The scope for the operations performed in computing the loss. loss_collection: collection to which this loss will be added. reduction: A `tf.losses.Reduction` to apply to loss. add_summaries: Whether or not to add summaries for the loss. Returns: A scalar Tensor representing the mutual information loss. """ _validate_information_penalty_inputs( structured_generator_inputs, predicted_distributions) with ops.name_scope(scope, 'mutual_information_loss') as scope: # Calculate the negative log-likelihood of the reconstructed noise. log_probs = [math_ops.reduce_mean(dist.log_prob(noise)) for dist, noise in zip(predicted_distributions, structured_generator_inputs)] loss = -1 * losses.compute_weighted_loss( log_probs, weights, scope, loss_collection=loss_collection, reduction=reduction) if add_summaries: summary.scalar('mutual_information_penalty', loss) return loss def _numerically_stable_global_norm(tensor_list): """Compute the global norm of a list of Tensors, with improved stability. The global norm computation sometimes overflows due to the intermediate L2 step. To avoid this, we divide by a cheap-to-compute max over the matrix elements. Args: tensor_list: A list of tensors, or `None`. Returns: A scalar tensor with the global norm. """ if np.all([x is None for x in tensor_list]): return 0.0 list_max = math_ops.reduce_max([math_ops.reduce_max(math_ops.abs(x)) for x in tensor_list if x is not None]) return list_max * clip_ops.global_norm([x / list_max for x in tensor_list if x is not None]) def _used_weight(weights_list): for weight in weights_list: if weight is not None: return tensor_util.constant_value(ops.convert_to_tensor(weight)) def _validate_args(losses_list, weight_factor, gradient_ratio): for loss in losses_list: loss.shape.assert_is_compatible_with([]) if weight_factor is None and gradient_ratio is None: raise ValueError( '`weight_factor` and `gradient_ratio` cannot both be `None.`') if weight_factor is not None and gradient_ratio is not None: raise ValueError( '`weight_factor` and `gradient_ratio` cannot both be specified.') # TODO(joelshor): Add ability to pass in gradients, to avoid recomputing. def combine_adversarial_loss(main_loss, adversarial_loss, weight_factor=None, gradient_ratio=None, gradient_ratio_epsilon=1e-6, variables=None, scalar_summaries=True, gradient_summaries=True, scope=None): """Utility to combine main and adversarial losses. This utility combines the main and adversarial losses in one of two ways. 1) Fixed coefficient on adversarial loss. Use `weight_factor` in this case. 2) Fixed ratio of gradients. Use `gradient_ratio` in this case. This is often used to make sure both losses affect weights roughly equally, as in https://arxiv.org/pdf/1705.05823. One can optionally also visualize the scalar and gradient behavior of the losses. Args: main_loss: A floating scalar Tensor indicating the main loss. adversarial_loss: A floating scalar Tensor indication the adversarial loss. weight_factor: If not `None`, the coefficient by which to multiply the adversarial loss. Exactly one of this and `gradient_ratio` must be non-None. gradient_ratio: If not `None`, the ratio of the magnitude of the gradients. Specifically, gradient_ratio = grad_mag(main_loss) / grad_mag(adversarial_loss) Exactly one of this and `weight_factor` must be non-None. gradient_ratio_epsilon: An epsilon to add to the adversarial loss coefficient denominator, to avoid division-by-zero. variables: List of variables to calculate gradients with respect to. If not present, defaults to all trainable variables. scalar_summaries: Create scalar summaries of losses. gradient_summaries: Create gradient summaries of losses. scope: Optional name scope. Returns: A floating scalar Tensor indicating the desired combined loss. Raises: ValueError: Malformed input. """ _validate_args([main_loss, adversarial_loss], weight_factor, gradient_ratio) if variables is None: variables = contrib_variables_lib.get_trainable_variables() with ops.name_scope(scope, 'adversarial_loss', values=[main_loss, adversarial_loss]): # Compute gradients if we will need them. if gradient_summaries or gradient_ratio is not None: main_loss_grad_mag = _numerically_stable_global_norm( gradients_impl.gradients(main_loss, variables)) adv_loss_grad_mag = _numerically_stable_global_norm( gradients_impl.gradients(adversarial_loss, variables)) # Add summaries, if applicable. if scalar_summaries: summary.scalar('main_loss', main_loss) summary.scalar('adversarial_loss', adversarial_loss) if gradient_summaries: summary.scalar('main_loss_gradients', main_loss_grad_mag) summary.scalar('adversarial_loss_gradients', adv_loss_grad_mag) # Combine losses in the appropriate way. # If `weight_factor` is always `0`, avoid computing the adversarial loss # tensor entirely. if _used_weight((weight_factor, gradient_ratio)) == 0: final_loss = main_loss elif weight_factor is not None: final_loss = (main_loss + array_ops.stop_gradient(weight_factor) * adversarial_loss) elif gradient_ratio is not None: grad_mag_ratio = main_loss_grad_mag / ( adv_loss_grad_mag + gradient_ratio_epsilon) adv_coeff = grad_mag_ratio / gradient_ratio summary.scalar('adversarial_coefficient', adv_coeff) final_loss = (main_loss + array_ops.stop_gradient(adv_coeff) * adversarial_loss) return final_loss
apache-2.0
[ 3, 1898, 9708, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 44, 736, 874, 626, 787, 2997, 367, 6093, 598, 879, 83, 14, 199, 199, 1918, 21289, 13511, 370, 2877, 2446, 4652, 12, 1325, 2337, 787, 11789, 626, 886, 440, 26, 199, 17, 9, 671, 5336, 63, 4679, 63, 4358, 199, 18, 9, 671, 5336, 63, 328, 24565, 63, 4358, 199, 199, 9846, 26, 199, 17, 9, 1990, 332, 1597, 262, 63, 4679, 63, 4358, 199, 18, 9, 1990, 332, 1597, 262, 63, 328, 24565, 63, 4358, 199, 199, 8632, 2893, 26, 199, 10274, 332, 1597, 262, 63, 7490, 63, 26264, 199, 199, 2422, 21289, 1471, 506, 7688, 370, 4729, 413, 36, 503, 499, 36, 28373, 12, 880, 465, 370, 506, 9025, 543, 199, 2068, 39, 879, 3449, 21289, 334, 2859, 921, 27290, 14, 1308, 15, 2101, 15, 975, 845, 14, 1780, 7979, 680, 199, 199, 1378, 1852, 3520, 21289, 18025, 315, 314, 21721, 39, 879, 10059, 12, 8749, 1218, 282, 2008, 199, 1023, 402, 314, 21289, 543, 658, 17865, 63, 1208, 14, 647, 2313, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 2828, 14, 4857, 14, 1548, 14, 1483, 492, 2860, 465, 5914, 63, 3669, 63, 773, 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, 1625, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 11353, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 12661, 63, 5472, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2196, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1750, 63, 2645, 199, 504, 3228, 14, 1548, 14, 1483, 14, 5613, 492, 4084, 465, 6364, 199, 504, 3228, 14, 1548, 14, 1483, 14, 17865, 492, 21289, 199, 504, 3228, 14, 1548, 14, 1483, 14, 17865, 492, 4884, 199, 504, 3228, 14, 1548, 14, 4705, 492, 6212, 421, 199, 363, 452, 363, 275, 359, 272, 283, 645, 24975, 63, 328, 24565, 63, 4358, 297, 272, 283, 645, 24975, 63, 4679, 63, 4358, 297, 272, 283, 11790, 63, 20956, 63, 328, 24565, 63, 4358, 297, 272, 283, 11790, 63, 20956, 63, 4679, 63, 4358, 297, 272, 283, 5540, 63, 328, 24565, 63, 4358, 297, 272, 283, 5540, 63, 4679, 63, 4358, 297, 272, 283, 827, 5744, 63, 328, 24565, 63, 4358, 297, 272, 283, 827, 5744, 63, 4679, 63, 4358, 297, 272, 283, 10274, 332, 1597, 262, 63, 328, 24565, 63, 4358, 297, 272, 283, 10274, 332, 1597, 262, 63, 4679, 63, 4358, 297, 272, 283, 10274, 332, 1597, 262, 63, 7490, 63, 26264, 297, 272, 283, 6552, 1061, 63, 11697, 63, 26264, 297, 272, 283, 13307, 63, 350, 14895, 759, 279, 63, 4358, 297, 199, 61, 421, 199, 3, 644, 305, 332, 1597, 262, 21289, 687, 658, 55, 305, 332, 1597, 262, 598, 879, 64, 334, 2859, 921, 27290, 14, 1308, 15, 2101, 15, 1196, 614, 14, 1780, 13357, 680, 199, 318, 1990, 332, 1597, 262, 63, 4679, 63, 4358, 8, 272, 487, 24565, 63, 2268, 63, 4467, 12, 272, 4931, 29, 17, 14, 16, 12, 272, 4194, 29, 403, 12, 272, 5621, 63, 3627, 29, 1483, 14, 19713, 14, 28010, 654, 12, 272, 16773, 29, 17865, 14, 29705, 14, 13285, 63, 8285, 63, 13887, 24655, 63, 25100, 51, 12, 272, 1050, 63, 19883, 29, 797, 304, 523, 408, 55, 305, 332, 1597, 262, 4306, 5621, 367, 598, 879, 83, 14, 819, 1666, 658, 55, 305, 332, 1597, 262, 598, 879, 64, 334, 2859, 921, 27290, 14, 1308, 15, 2101, 15, 1196, 614, 14, 1780, 13357, 9, 367, 1655, 2436, 14, 819, 3033, 26, 272, 487, 24565, 63, 2268, 63, 4467, 26, 5289, 1408, 827, 707, 1072, 641, 4046, 666, 14, 13796, 489, 370, 506, 315, 314, 1425, 402, 5868, 4904, 12, 10739, 680, 272, 4931, 26, 4879, 658, 3861, 64, 7447, 6915, 365, 1902, 378, 12, 503, 314, 2011, 6915, 465, 489, 658, 328, 24565, 63, 2268, 63, 4467, 3559, 436, 1471, 506, 11180, 461, 370, 489, 658, 328, 24565, 63, 2268, 63, 4467, 64, 334, 73, 14, 69, 2020, 1006, 7365, 1471, 506, 1902, 658, 17, 3559, 503, 489, 314, 2011, 465, 314, 5226, 6240, 680, 272, 4194, 26, 710, 4194, 367, 314, 5331, 10585, 315, 17226, 314, 5621, 14, 272, 5621, 63, 3627, 26, 3245, 370, 1314, 642, 5621, 911, 506, 3483, 14, 272, 16773, 26, 437, 658, 3249, 14, 17865, 14, 29705, 64, 370, 4838, 370, 5621, 14, 272, 1050, 63, 19883, 26, 7480, 503, 440, 370, 1050, 16212, 23747, 367, 314, 5621, 14, 819, 1803, 26, 272, 437, 5621, 5878, 14, 710, 2215, 8350, 641, 658, 22508, 2313, 523, 408, 523, 543, 4156, 14, 354, 63, 2645, 8, 2645, 12, 283, 4679, 63, 10274, 332, 1597, 262, 63, 4358, 297, 334, 489, 487, 24565, 63, 2268, 63, 4467, 12, 4931, 430, 465, 4194, 26, 272, 487, 24565, 63, 2268, 63, 4467, 275, 3473, 63, 1483, 14, 475, 63, 1609, 8, 328, 24565, 63, 2268, 63, 4467, 9, 339, 5621, 275, 446, 487, 24565, 63, 2268, 63, 4467, 272, 5621, 275, 21289 ]
[ 1898, 9708, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 44, 736, 874, 626, 787, 2997, 367, 6093, 598, 879, 83, 14, 199, 199, 1918, 21289, 13511, 370, 2877, 2446, 4652, 12, 1325, 2337, 787, 11789, 626, 886, 440, 26, 199, 17, 9, 671, 5336, 63, 4679, 63, 4358, 199, 18, 9, 671, 5336, 63, 328, 24565, 63, 4358, 199, 199, 9846, 26, 199, 17, 9, 1990, 332, 1597, 262, 63, 4679, 63, 4358, 199, 18, 9, 1990, 332, 1597, 262, 63, 328, 24565, 63, 4358, 199, 199, 8632, 2893, 26, 199, 10274, 332, 1597, 262, 63, 7490, 63, 26264, 199, 199, 2422, 21289, 1471, 506, 7688, 370, 4729, 413, 36, 503, 499, 36, 28373, 12, 880, 465, 370, 506, 9025, 543, 199, 2068, 39, 879, 3449, 21289, 334, 2859, 921, 27290, 14, 1308, 15, 2101, 15, 975, 845, 14, 1780, 7979, 680, 199, 199, 1378, 1852, 3520, 21289, 18025, 315, 314, 21721, 39, 879, 10059, 12, 8749, 1218, 282, 2008, 199, 1023, 402, 314, 21289, 543, 658, 17865, 63, 1208, 14, 647, 2313, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 2828, 14, 4857, 14, 1548, 14, 1483, 492, 2860, 465, 5914, 63, 3669, 63, 773, 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, 1625, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 11353, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 12661, 63, 5472, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2196, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1750, 63, 2645, 199, 504, 3228, 14, 1548, 14, 1483, 14, 5613, 492, 4084, 465, 6364, 199, 504, 3228, 14, 1548, 14, 1483, 14, 17865, 492, 21289, 199, 504, 3228, 14, 1548, 14, 1483, 14, 17865, 492, 4884, 199, 504, 3228, 14, 1548, 14, 4705, 492, 6212, 421, 199, 363, 452, 363, 275, 359, 272, 283, 645, 24975, 63, 328, 24565, 63, 4358, 297, 272, 283, 645, 24975, 63, 4679, 63, 4358, 297, 272, 283, 11790, 63, 20956, 63, 328, 24565, 63, 4358, 297, 272, 283, 11790, 63, 20956, 63, 4679, 63, 4358, 297, 272, 283, 5540, 63, 328, 24565, 63, 4358, 297, 272, 283, 5540, 63, 4679, 63, 4358, 297, 272, 283, 827, 5744, 63, 328, 24565, 63, 4358, 297, 272, 283, 827, 5744, 63, 4679, 63, 4358, 297, 272, 283, 10274, 332, 1597, 262, 63, 328, 24565, 63, 4358, 297, 272, 283, 10274, 332, 1597, 262, 63, 4679, 63, 4358, 297, 272, 283, 10274, 332, 1597, 262, 63, 7490, 63, 26264, 297, 272, 283, 6552, 1061, 63, 11697, 63, 26264, 297, 272, 283, 13307, 63, 350, 14895, 759, 279, 63, 4358, 297, 199, 61, 421, 199, 3, 644, 305, 332, 1597, 262, 21289, 687, 658, 55, 305, 332, 1597, 262, 598, 879, 64, 334, 2859, 921, 27290, 14, 1308, 15, 2101, 15, 1196, 614, 14, 1780, 13357, 680, 199, 318, 1990, 332, 1597, 262, 63, 4679, 63, 4358, 8, 272, 487, 24565, 63, 2268, 63, 4467, 12, 272, 4931, 29, 17, 14, 16, 12, 272, 4194, 29, 403, 12, 272, 5621, 63, 3627, 29, 1483, 14, 19713, 14, 28010, 654, 12, 272, 16773, 29, 17865, 14, 29705, 14, 13285, 63, 8285, 63, 13887, 24655, 63, 25100, 51, 12, 272, 1050, 63, 19883, 29, 797, 304, 523, 408, 55, 305, 332, 1597, 262, 4306, 5621, 367, 598, 879, 83, 14, 819, 1666, 658, 55, 305, 332, 1597, 262, 598, 879, 64, 334, 2859, 921, 27290, 14, 1308, 15, 2101, 15, 1196, 614, 14, 1780, 13357, 9, 367, 1655, 2436, 14, 819, 3033, 26, 272, 487, 24565, 63, 2268, 63, 4467, 26, 5289, 1408, 827, 707, 1072, 641, 4046, 666, 14, 13796, 489, 370, 506, 315, 314, 1425, 402, 5868, 4904, 12, 10739, 680, 272, 4931, 26, 4879, 658, 3861, 64, 7447, 6915, 365, 1902, 378, 12, 503, 314, 2011, 6915, 465, 489, 658, 328, 24565, 63, 2268, 63, 4467, 3559, 436, 1471, 506, 11180, 461, 370, 489, 658, 328, 24565, 63, 2268, 63, 4467, 64, 334, 73, 14, 69, 2020, 1006, 7365, 1471, 506, 1902, 658, 17, 3559, 503, 489, 314, 2011, 465, 314, 5226, 6240, 680, 272, 4194, 26, 710, 4194, 367, 314, 5331, 10585, 315, 17226, 314, 5621, 14, 272, 5621, 63, 3627, 26, 3245, 370, 1314, 642, 5621, 911, 506, 3483, 14, 272, 16773, 26, 437, 658, 3249, 14, 17865, 14, 29705, 64, 370, 4838, 370, 5621, 14, 272, 1050, 63, 19883, 26, 7480, 503, 440, 370, 1050, 16212, 23747, 367, 314, 5621, 14, 819, 1803, 26, 272, 437, 5621, 5878, 14, 710, 2215, 8350, 641, 658, 22508, 2313, 523, 408, 523, 543, 4156, 14, 354, 63, 2645, 8, 2645, 12, 283, 4679, 63, 10274, 332, 1597, 262, 63, 4358, 297, 334, 489, 487, 24565, 63, 2268, 63, 4467, 12, 4931, 430, 465, 4194, 26, 272, 487, 24565, 63, 2268, 63, 4467, 275, 3473, 63, 1483, 14, 475, 63, 1609, 8, 328, 24565, 63, 2268, 63, 4467, 9, 339, 5621, 275, 446, 487, 24565, 63, 2268, 63, 4467, 272, 5621, 275, 21289, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
k3nnyfr/s2a_fr-nsis
s2a/Python/Lib/doctest.py
10
104460
# Module doctest. # Released to the public domain 16-Jan-2001, by Tim Peters (tim@python.org). # Major enhancements and refactoring by: # Jim Fulton # Edward Loper # Provided as-is; use at your own risk; no warranty; no promises; enjoy! r"""Module doctest -- a framework for running examples in docstrings. In simplest use, end each module M to be tested with: def _test(): import doctest doctest.testmod() if __name__ == "__main__": _test() Then running the module as a script will cause the examples in the docstrings to get executed and verified: python M.py This won't display anything unless an example fails, in which case the failing example(s) and the cause(s) of the failure(s) are printed to stdout (why not stderr? because stderr is a lame hack <0.2 wink>), and the final line of output is "Test failed.". Run it with the -v switch instead: python M.py -v and a detailed report of all examples tried is printed to stdout, along with assorted summaries at the end. You can force verbose mode by passing "verbose=True" to testmod, or prohibit it by passing "verbose=False". In either of those cases, sys.argv is not examined by testmod. There are a variety of other ways to run doctests, including integration with the unittest framework, and support for running non-Python text files containing doctests. There are also many ways to override parts of doctest's default behaviors. See the Library Reference Manual for details. """ __docformat__ = 'reStructuredText en' __all__ = [ # 0, Option Flags 'register_optionflag', 'DONT_ACCEPT_TRUE_FOR_1', 'DONT_ACCEPT_BLANKLINE', 'NORMALIZE_WHITESPACE', 'ELLIPSIS', 'SKIP', 'IGNORE_EXCEPTION_DETAIL', 'COMPARISON_FLAGS', 'REPORT_UDIFF', 'REPORT_CDIFF', 'REPORT_NDIFF', 'REPORT_ONLY_FIRST_FAILURE', 'REPORTING_FLAGS', # 1. Utility Functions # 2. Example & DocTest 'Example', 'DocTest', # 3. Doctest Parser 'DocTestParser', # 4. Doctest Finder 'DocTestFinder', # 5. Doctest Runner 'DocTestRunner', 'OutputChecker', 'DocTestFailure', 'UnexpectedException', 'DebugRunner', # 6. Test Functions 'testmod', 'testfile', 'run_docstring_examples', # 7. Tester 'Tester', # 8. Unittest Support 'DocTestSuite', 'DocFileSuite', 'set_unittest_reportflags', # 9. Debugging Support 'script_from_examples', 'testsource', 'debug_src', 'debug', ] import __future__ import sys, traceback, inspect, linecache, os, re import unittest, difflib, pdb, tempfile import warnings from StringIO import StringIO from collections import namedtuple TestResults = namedtuple('TestResults', 'failed attempted') # There are 4 basic classes: # - Example: a <source, want> pair, plus an intra-docstring line number. # - DocTest: a collection of examples, parsed from a docstring, plus # info about where the docstring came from (name, filename, lineno). # - DocTestFinder: extracts DocTests from a given object's docstring and # its contained objects' docstrings. # - DocTestRunner: runs DocTest cases, and accumulates statistics. # # So the basic picture is: # # list of: # +------+ +---------+ +-------+ # |object| --DocTestFinder-> | DocTest | --DocTestRunner-> |results| # +------+ +---------+ +-------+ # | Example | # | ... | # | Example | # +---------+ # Option constants. OPTIONFLAGS_BY_NAME = {} def register_optionflag(name): # Create a new flag unless `name` is already known. return OPTIONFLAGS_BY_NAME.setdefault(name, 1 << len(OPTIONFLAGS_BY_NAME)) DONT_ACCEPT_TRUE_FOR_1 = register_optionflag('DONT_ACCEPT_TRUE_FOR_1') DONT_ACCEPT_BLANKLINE = register_optionflag('DONT_ACCEPT_BLANKLINE') NORMALIZE_WHITESPACE = register_optionflag('NORMALIZE_WHITESPACE') ELLIPSIS = register_optionflag('ELLIPSIS') SKIP = register_optionflag('SKIP') IGNORE_EXCEPTION_DETAIL = register_optionflag('IGNORE_EXCEPTION_DETAIL') COMPARISON_FLAGS = (DONT_ACCEPT_TRUE_FOR_1 | DONT_ACCEPT_BLANKLINE | NORMALIZE_WHITESPACE | ELLIPSIS | SKIP | IGNORE_EXCEPTION_DETAIL) REPORT_UDIFF = register_optionflag('REPORT_UDIFF') REPORT_CDIFF = register_optionflag('REPORT_CDIFF') REPORT_NDIFF = register_optionflag('REPORT_NDIFF') REPORT_ONLY_FIRST_FAILURE = register_optionflag('REPORT_ONLY_FIRST_FAILURE') REPORTING_FLAGS = (REPORT_UDIFF | REPORT_CDIFF | REPORT_NDIFF | REPORT_ONLY_FIRST_FAILURE) # Special string markers for use in `want` strings: BLANKLINE_MARKER = '<BLANKLINE>' ELLIPSIS_MARKER = '...' ###################################################################### ## Table of Contents ###################################################################### # 1. Utility Functions # 2. Example & DocTest -- store test cases # 3. DocTest Parser -- extracts examples from strings # 4. DocTest Finder -- extracts test cases from objects # 5. DocTest Runner -- runs test cases # 6. Test Functions -- convenient wrappers for testing # 7. Tester Class -- for backwards compatibility # 8. Unittest Support # 9. Debugging Support # 10. Example Usage ###################################################################### ## 1. Utility Functions ###################################################################### def _extract_future_flags(globs): """ Return the compiler-flags associated with the future features that have been imported into the given namespace (globs). """ flags = 0 for fname in __future__.all_feature_names: feature = globs.get(fname, None) if feature is getattr(__future__, fname): flags |= feature.compiler_flag return flags def _normalize_module(module, depth=2): """ Return the module specified by `module`. In particular: - If `module` is a module, then return module. - If `module` is a string, then import and return the module with that name. - If `module` is None, then return the calling module. The calling module is assumed to be the module of the stack frame at the given depth in the call stack. """ if inspect.ismodule(module): return module elif isinstance(module, (str, unicode)): return __import__(module, globals(), locals(), ["*"]) elif module is None: return sys.modules[sys._getframe(depth).f_globals['__name__']] else: raise TypeError("Expected a module, string, or None") def _load_testfile(filename, package, module_relative): if module_relative: package = _normalize_module(package, 3) filename = _module_relative_path(package, filename) if hasattr(package, '__loader__'): if hasattr(package.__loader__, 'get_data'): file_contents = package.__loader__.get_data(filename) # get_data() opens files as 'rb', so one must do the equivalent # conversion as universal newlines would do. return file_contents.replace(os.linesep, '\n'), filename with open(filename) as f: return f.read(), filename # Use sys.stdout encoding for ouput. _encoding = getattr(sys.__stdout__, 'encoding', None) or 'utf-8' def _indent(s, indent=4): """ Add the given number of space characters to the beginning of every non-blank line in `s`, and return the result. If the string `s` is Unicode, it is encoded using the stdout encoding and the `backslashreplace` error handler. """ if isinstance(s, unicode): s = s.encode(_encoding, 'backslashreplace') # This regexp matches the start of non-blank lines: return re.sub('(?m)^(?!$)', indent*' ', s) def _exception_traceback(exc_info): """ Return a string containing a traceback message for the given exc_info tuple (as returned by sys.exc_info()). """ # Get a traceback message. excout = StringIO() exc_type, exc_val, exc_tb = exc_info traceback.print_exception(exc_type, exc_val, exc_tb, file=excout) return excout.getvalue() # Override some StringIO methods. class _SpoofOut(StringIO): def getvalue(self): result = StringIO.getvalue(self) # If anything at all was written, make sure there's a trailing # newline. There's no way for the expected output to indicate # that a trailing newline is missing. if result and not result.endswith("\n"): result += "\n" # Prevent softspace from screwing up the next test case, in # case they used print with a trailing comma in an example. if hasattr(self, "softspace"): del self.softspace return result def truncate(self, size=None): StringIO.truncate(self, size) if hasattr(self, "softspace"): del self.softspace if not self.buf: # Reset it to an empty string, to make sure it's not unicode. self.buf = '' # Worst-case linear-time ellipsis matching. def _ellipsis_match(want, got): """ Essentially the only subtle case: >>> _ellipsis_match('aa...aa', 'aaa') False """ if ELLIPSIS_MARKER not in want: return want == got # Find "the real" strings. ws = want.split(ELLIPSIS_MARKER) assert len(ws) >= 2 # Deal with exact matches possibly needed at one or both ends. startpos, endpos = 0, len(got) w = ws[0] if w: # starts with exact match if got.startswith(w): startpos = len(w) del ws[0] else: return False w = ws[-1] if w: # ends with exact match if got.endswith(w): endpos -= len(w) del ws[-1] else: return False if startpos > endpos: # Exact end matches required more characters than we have, as in # _ellipsis_match('aa...aa', 'aaa') return False # For the rest, we only need to find the leftmost non-overlapping # match for each piece. If there's no overall match that way alone, # there's no overall match period. for w in ws: # w may be '' at times, if there are consecutive ellipses, or # due to an ellipsis at the start or end of `want`. That's OK. # Search for an empty string succeeds, and doesn't change startpos. startpos = got.find(w, startpos, endpos) if startpos < 0: return False startpos += len(w) return True def _comment_line(line): "Return a commented form of the given line" line = line.rstrip() if line: return '# '+line else: return '#' class _OutputRedirectingPdb(pdb.Pdb): """ A specialized version of the python debugger that redirects stdout to a given stream when interacting with the user. Stdout is *not* redirected when traced code is executed. """ def __init__(self, out): self.__out = out self.__debugger_used = False pdb.Pdb.__init__(self, stdout=out) # still use input() to get user input self.use_rawinput = 1 def set_trace(self, frame=None): self.__debugger_used = True if frame is None: frame = sys._getframe().f_back pdb.Pdb.set_trace(self, frame) def set_continue(self): # Calling set_continue unconditionally would break unit test # coverage reporting, as Bdb.set_continue calls sys.settrace(None). if self.__debugger_used: pdb.Pdb.set_continue(self) def trace_dispatch(self, *args): # Redirect stdout to the given stream. save_stdout = sys.stdout sys.stdout = self.__out # Call Pdb's trace dispatch method. try: return pdb.Pdb.trace_dispatch(self, *args) finally: sys.stdout = save_stdout # [XX] Normalize with respect to os.path.pardir? def _module_relative_path(module, path): if not inspect.ismodule(module): raise TypeError, 'Expected a module: %r' % module if path.startswith('/'): raise ValueError, 'Module-relative files may not have absolute paths' # Find the base directory for the path. if hasattr(module, '__file__'): # A normal module/package basedir = os.path.split(module.__file__)[0] elif module.__name__ == '__main__': # An interactive session. if len(sys.argv)>0 and sys.argv[0] != '': basedir = os.path.split(sys.argv[0])[0] else: basedir = os.curdir else: # A module w/o __file__ (this includes builtins) raise ValueError("Can't resolve paths relative to the module " + module + " (it has no __file__)") # Combine the base directory and the path. return os.path.join(basedir, *(path.split('/'))) ###################################################################### ## 2. Example & DocTest ###################################################################### ## - An "example" is a <source, want> pair, where "source" is a ## fragment of source code, and "want" is the expected output for ## "source." The Example class also includes information about ## where the example was extracted from. ## ## - A "doctest" is a collection of examples, typically extracted from ## a string (such as an object's docstring). The DocTest class also ## includes information about where the string was extracted from. class Example: """ A single doctest example, consisting of source code and expected output. `Example` defines the following attributes: - source: A single Python statement, always ending with a newline. The constructor adds a newline if needed. - want: The expected output from running the source code (either from stdout, or a traceback in case of exception). `want` ends with a newline unless it's empty, in which case it's an empty string. The constructor adds a newline if needed. - exc_msg: The exception message generated by the example, if the example is expected to generate an exception; or `None` if it is not expected to generate an exception. This exception message is compared against the return value of `traceback.format_exception_only()`. `exc_msg` ends with a newline unless it's `None`. The constructor adds a newline if needed. - lineno: The line number within the DocTest string containing this Example where the Example begins. This line number is zero-based, with respect to the beginning of the DocTest. - indent: The example's indentation in the DocTest string. I.e., the number of space characters that precede the example's first prompt. - options: A dictionary mapping from option flags to True or False, which is used to override default options for this example. Any option flags not contained in this dictionary are left at their default value (as specified by the DocTestRunner's optionflags). By default, no options are set. """ def __init__(self, source, want, exc_msg=None, lineno=0, indent=0, options=None): # Normalize inputs. if not source.endswith('\n'): source += '\n' if want and not want.endswith('\n'): want += '\n' if exc_msg is not None and not exc_msg.endswith('\n'): exc_msg += '\n' # Store properties. self.source = source self.want = want self.lineno = lineno self.indent = indent if options is None: options = {} self.options = options self.exc_msg = exc_msg def __eq__(self, other): if type(self) is not type(other): return NotImplemented return self.source == other.source and \ self.want == other.want and \ self.lineno == other.lineno and \ self.indent == other.indent and \ self.options == other.options and \ self.exc_msg == other.exc_msg def __ne__(self, other): return not self == other def __hash__(self): return hash((self.source, self.want, self.lineno, self.indent, self.exc_msg)) class DocTest: """ A collection of doctest examples that should be run in a single namespace. Each `DocTest` defines the following attributes: - examples: the list of examples. - globs: The namespace (aka globals) that the examples should be run in. - name: A name identifying the DocTest (typically, the name of the object whose docstring this DocTest was extracted from). - filename: The name of the file that this DocTest was extracted from, or `None` if the filename is unknown. - lineno: The line number within filename where this DocTest begins, or `None` if the line number is unavailable. This line number is zero-based, with respect to the beginning of the file. - docstring: The string that the examples were extracted from, or `None` if the string is unavailable. """ def __init__(self, examples, globs, name, filename, lineno, docstring): """ Create a new DocTest containing the given examples. The DocTest's globals are initialized with a copy of `globs`. """ assert not isinstance(examples, basestring), \ "DocTest no longer accepts str; use DocTestParser instead" self.examples = examples self.docstring = docstring self.globs = globs.copy() self.name = name self.filename = filename self.lineno = lineno def __repr__(self): if len(self.examples) == 0: examples = 'no examples' elif len(self.examples) == 1: examples = '1 example' else: examples = '%d examples' % len(self.examples) return ('<DocTest %s from %s:%s (%s)>' % (self.name, self.filename, self.lineno, examples)) def __eq__(self, other): if type(self) is not type(other): return NotImplemented return self.examples == other.examples and \ self.docstring == other.docstring and \ self.globs == other.globs and \ self.name == other.name and \ self.filename == other.filename and \ self.lineno == other.lineno def __ne__(self, other): return not self == other def __hash__(self): return hash((self.docstring, self.name, self.filename, self.lineno)) # This lets us sort tests by name: def __cmp__(self, other): if not isinstance(other, DocTest): return -1 return cmp((self.name, self.filename, self.lineno, id(self)), (other.name, other.filename, other.lineno, id(other))) ###################################################################### ## 3. DocTestParser ###################################################################### class DocTestParser: """ A class used to parse strings containing doctest examples. """ # This regular expression is used to find doctest examples in a # string. It defines three groups: `source` is the source code # (including leading indentation and prompts); `indent` is the # indentation of the first (PS1) line of the source code; and # `want` is the expected output (including leading indentation). _EXAMPLE_RE = re.compile(r''' # Source consists of a PS1 line followed by zero or more PS2 lines. (?P<source> (?:^(?P<indent> [ ]*) >>> .*) # PS1 line (?:\n [ ]* \.\.\. .*)*) # PS2 lines \n? # Want consists of any non-blank lines that do not start with PS1. (?P<want> (?:(?![ ]*$) # Not a blank line (?![ ]*>>>) # Not a line starting with PS1 .+$\n? # But any other line )*) ''', re.MULTILINE | re.VERBOSE) # A regular expression for handling `want` strings that contain # expected exceptions. It divides `want` into three pieces: # - the traceback header line (`hdr`) # - the traceback stack (`stack`) # - the exception message (`msg`), as generated by # traceback.format_exception_only() # `msg` may have multiple lines. We assume/require that the # exception message is the first non-indented line starting with a word # character following the traceback header line. _EXCEPTION_RE = re.compile(r""" # Grab the traceback header. Different versions of Python have # said different things on the first traceback line. ^(?P<hdr> Traceback\ \( (?: most\ recent\ call\ last | innermost\ last ) \) : ) \s* $ # toss trailing whitespace on the header. (?P<stack> .*?) # don't blink: absorb stuff until... ^ (?P<msg> \w+ .*) # a line *starts* with alphanum. """, re.VERBOSE | re.MULTILINE | re.DOTALL) # A callable returning a true value iff its argument is a blank line # or contains a single comment. _IS_BLANK_OR_COMMENT = re.compile(r'^[ ]*(#.*)?$').match def parse(self, string, name='<string>'): """ Divide the given string into examples and intervening text, and return them as a list of alternating Examples and strings. Line numbers for the Examples are 0-based. The optional argument `name` is a name identifying this string, and is only used for error messages. """ string = string.expandtabs() # If all lines begin with the same indentation, then strip it. min_indent = self._min_indent(string) if min_indent > 0: string = '\n'.join([l[min_indent:] for l in string.split('\n')]) output = [] charno, lineno = 0, 0 # Find all doctest examples in the string: for m in self._EXAMPLE_RE.finditer(string): # Add the pre-example text to `output`. output.append(string[charno:m.start()]) # Update lineno (lines before this example) lineno += string.count('\n', charno, m.start()) # Extract info from the regexp match. (source, options, want, exc_msg) = \ self._parse_example(m, name, lineno) # Create an Example, and add it to the list. if not self._IS_BLANK_OR_COMMENT(source): output.append( Example(source, want, exc_msg, lineno=lineno, indent=min_indent+len(m.group('indent')), options=options) ) # Update lineno (lines inside this example) lineno += string.count('\n', m.start(), m.end()) # Update charno. charno = m.end() # Add any remaining post-example text to `output`. output.append(string[charno:]) return output def get_doctest(self, string, globs, name, filename, lineno): """ Extract all doctest examples from the given string, and collect them into a `DocTest` object. `globs`, `name`, `filename`, and `lineno` are attributes for the new `DocTest` object. See the documentation for `DocTest` for more information. """ return DocTest(self.get_examples(string, name), globs, name, filename, lineno, string) def get_examples(self, string, name='<string>'): """ Extract all doctest examples from the given string, and return them as a list of `Example` objects. Line numbers are 0-based, because it's most common in doctests that nothing interesting appears on the same line as opening triple-quote, and so the first interesting line is called \"line 1\" then. The optional argument `name` is a name identifying this string, and is only used for error messages. """ return [x for x in self.parse(string, name) if isinstance(x, Example)] def _parse_example(self, m, name, lineno): """ Given a regular expression match from `_EXAMPLE_RE` (`m`), return a pair `(source, want)`, where `source` is the matched example's source code (with prompts and indentation stripped); and `want` is the example's expected output (with indentation stripped). `name` is the string's name, and `lineno` is the line number where the example starts; both are used for error messages. """ # Get the example's indentation level. indent = len(m.group('indent')) # Divide source into lines; check that they're properly # indented; and then strip their indentation & prompts. source_lines = m.group('source').split('\n') self._check_prompt_blank(source_lines, indent, name, lineno) self._check_prefix(source_lines[1:], ' '*indent + '.', name, lineno) source = '\n'.join([sl[indent+4:] for sl in source_lines]) # Divide want into lines; check that it's properly indented; and # then strip the indentation. Spaces before the last newline should # be preserved, so plain rstrip() isn't good enough. want = m.group('want') want_lines = want.split('\n') if len(want_lines) > 1 and re.match(r' *$', want_lines[-1]): del want_lines[-1] # forget final newline & spaces after it self._check_prefix(want_lines, ' '*indent, name, lineno + len(source_lines)) want = '\n'.join([wl[indent:] for wl in want_lines]) # If `want` contains a traceback message, then extract it. m = self._EXCEPTION_RE.match(want) if m: exc_msg = m.group('msg') else: exc_msg = None # Extract options from the source. options = self._find_options(source, name, lineno) return source, options, want, exc_msg # This regular expression looks for option directives in the # source code of an example. Option directives are comments # starting with "doctest:". Warning: this may give false # positives for string-literals that contain the string # "#doctest:". Eliminating these false positives would require # actually parsing the string; but we limit them by ignoring any # line containing "#doctest:" that is *followed* by a quote mark. _OPTION_DIRECTIVE_RE = re.compile(r'#\s*doctest:\s*([^\n\'"]*)$', re.MULTILINE) def _find_options(self, source, name, lineno): """ Return a dictionary containing option overrides extracted from option directives in the given source string. `name` is the string's name, and `lineno` is the line number where the example starts; both are used for error messages. """ options = {} # (note: with the current regexp, this will match at most once:) for m in self._OPTION_DIRECTIVE_RE.finditer(source): option_strings = m.group(1).replace(',', ' ').split() for option in option_strings: if (option[0] not in '+-' or option[1:] not in OPTIONFLAGS_BY_NAME): raise ValueError('line %r of the doctest for %s ' 'has an invalid option: %r' % (lineno+1, name, option)) flag = OPTIONFLAGS_BY_NAME[option[1:]] options[flag] = (option[0] == '+') if options and self._IS_BLANK_OR_COMMENT(source): raise ValueError('line %r of the doctest for %s has an option ' 'directive on a line with no example: %r' % (lineno, name, source)) return options # This regular expression finds the indentation of every non-blank # line in a string. _INDENT_RE = re.compile('^([ ]*)(?=\S)', re.MULTILINE) def _min_indent(self, s): "Return the minimum indentation of any non-blank line in `s`" indents = [len(indent) for indent in self._INDENT_RE.findall(s)] if len(indents) > 0: return min(indents) else: return 0 def _check_prompt_blank(self, lines, indent, name, lineno): """ Given the lines of a source string (including prompts and leading indentation), check to make sure that every prompt is followed by a space character. If any line is not followed by a space character, then raise ValueError. """ for i, line in enumerate(lines): if len(line) >= indent+4 and line[indent+3] != ' ': raise ValueError('line %r of the docstring for %s ' 'lacks blank after %s: %r' % (lineno+i+1, name, line[indent:indent+3], line)) def _check_prefix(self, lines, prefix, name, lineno): """ Check that every line in the given list starts with the given prefix; if any line does not, then raise a ValueError. """ for i, line in enumerate(lines): if line and not line.startswith(prefix): raise ValueError('line %r of the docstring for %s has ' 'inconsistent leading whitespace: %r' % (lineno+i+1, name, line)) ###################################################################### ## 4. DocTest Finder ###################################################################### class DocTestFinder: """ A class used to extract the DocTests that are relevant to a given object, from its docstring and the docstrings of its contained objects. Doctests can currently be extracted from the following object types: modules, functions, classes, methods, staticmethods, classmethods, and properties. """ def __init__(self, verbose=False, parser=DocTestParser(), recurse=True, exclude_empty=True): """ Create a new doctest finder. The optional argument `parser` specifies a class or function that should be used to create new DocTest objects (or objects that implement the same interface as DocTest). The signature for this factory function should match the signature of the DocTest constructor. If the optional argument `recurse` is false, then `find` will only examine the given object, and not any contained objects. If the optional argument `exclude_empty` is false, then `find` will include tests for objects with empty docstrings. """ self._parser = parser self._verbose = verbose self._recurse = recurse self._exclude_empty = exclude_empty def find(self, obj, name=None, module=None, globs=None, extraglobs=None): """ Return a list of the DocTests that are defined by the given object's docstring, or by any of its contained objects' docstrings. The optional parameter `module` is the module that contains the given object. If the module is not specified or is None, then the test finder will attempt to automatically determine the correct module. The object's module is used: - As a default namespace, if `globs` is not specified. - To prevent the DocTestFinder from extracting DocTests from objects that are imported from other modules. - To find the name of the file containing the object. - To help find the line number of the object within its file. Contained objects whose module does not match `module` are ignored. If `module` is False, no attempt to find the module will be made. This is obscure, of use mostly in tests: if `module` is False, or is None but cannot be found automatically, then all objects are considered to belong to the (non-existent) module, so all contained objects will (recursively) be searched for doctests. The globals for each DocTest is formed by combining `globs` and `extraglobs` (bindings in `extraglobs` override bindings in `globs`). A new copy of the globals dictionary is created for each DocTest. If `globs` is not specified, then it defaults to the module's `__dict__`, if specified, or {} otherwise. If `extraglobs` is not specified, then it defaults to {}. """ # If name was not specified, then extract it from the object. if name is None: name = getattr(obj, '__name__', None) if name is None: raise ValueError("DocTestFinder.find: name must be given " "when obj.__name__ doesn't exist: %r" % (type(obj),)) # Find the module that contains the given object (if obj is # a module, then module=obj.). Note: this may fail, in which # case module will be None. if module is False: module = None elif module is None: module = inspect.getmodule(obj) # Read the module's source code. This is used by # DocTestFinder._find_lineno to find the line number for a # given object's docstring. try: file = inspect.getsourcefile(obj) or inspect.getfile(obj) if module is not None: # Supply the module globals in case the module was # originally loaded via a PEP 302 loader and # file is not a valid filesystem path source_lines = linecache.getlines(file, module.__dict__) else: # No access to a loader, so assume it's a normal # filesystem path source_lines = linecache.getlines(file) if not source_lines: source_lines = None except TypeError: source_lines = None # Initialize globals, and merge in extraglobs. if globs is None: if module is None: globs = {} else: globs = module.__dict__.copy() else: globs = globs.copy() if extraglobs is not None: globs.update(extraglobs) if '__name__' not in globs: globs['__name__'] = '__main__' # provide a default module name # Recursively explore `obj`, extracting DocTests. tests = [] self._find(tests, obj, name, module, source_lines, globs, {}) # Sort the tests by alpha order of names, for consistency in # verbose-mode output. This was a feature of doctest in Pythons # <= 2.3 that got lost by accident in 2.4. It was repaired in # 2.4.4 and 2.5. tests.sort() return tests def _from_module(self, module, object): """ Return true if the given object is defined in the given module. """ if module is None: return True elif inspect.getmodule(object) is not None: return module is inspect.getmodule(object) elif inspect.isfunction(object): return module.__dict__ is object.func_globals elif inspect.isclass(object): return module.__name__ == object.__module__ elif hasattr(object, '__module__'): return module.__name__ == object.__module__ elif isinstance(object, property): return True # [XX] no way not be sure. else: raise ValueError("object must be a class or function") def _find(self, tests, obj, name, module, source_lines, globs, seen): """ Find tests for the given object and any contained objects, and add them to `tests`. """ if self._verbose: print 'Finding tests in %s' % name # If we've already processed this object, then ignore it. if id(obj) in seen: return seen[id(obj)] = 1 # Find a test for this object, and add it to the list of tests. test = self._get_test(obj, name, module, globs, source_lines) if test is not None: tests.append(test) # Look for tests in a module's contained objects. if inspect.ismodule(obj) and self._recurse: for valname, val in obj.__dict__.items(): valname = '%s.%s' % (name, valname) # Recurse to functions & classes. if ((inspect.isfunction(val) or inspect.isclass(val)) and self._from_module(module, val)): self._find(tests, val, valname, module, source_lines, globs, seen) # Look for tests in a module's __test__ dictionary. if inspect.ismodule(obj) and self._recurse: for valname, val in getattr(obj, '__test__', {}).items(): if not isinstance(valname, basestring): raise ValueError("DocTestFinder.find: __test__ keys " "must be strings: %r" % (type(valname),)) if not (inspect.isfunction(val) or inspect.isclass(val) or inspect.ismethod(val) or inspect.ismodule(val) or isinstance(val, basestring)): raise ValueError("DocTestFinder.find: __test__ values " "must be strings, functions, methods, " "classes, or modules: %r" % (type(val),)) valname = '%s.__test__.%s' % (name, valname) self._find(tests, val, valname, module, source_lines, globs, seen) # Look for tests in a class's contained objects. if inspect.isclass(obj) and self._recurse: for valname, val in obj.__dict__.items(): # Special handling for staticmethod/classmethod. if isinstance(val, staticmethod): val = getattr(obj, valname) if isinstance(val, classmethod): val = getattr(obj, valname).im_func # Recurse to methods, properties, and nested classes. if ((inspect.isfunction(val) or inspect.isclass(val) or isinstance(val, property)) and self._from_module(module, val)): valname = '%s.%s' % (name, valname) self._find(tests, val, valname, module, source_lines, globs, seen) def _get_test(self, obj, name, module, globs, source_lines): """ Return a DocTest for the given object, if it defines a docstring; otherwise, return None. """ # Extract the object's docstring. If it doesn't have one, # then return None (no test for this object). if isinstance(obj, basestring): docstring = obj else: try: if obj.__doc__ is None: docstring = '' else: docstring = obj.__doc__ if not isinstance(docstring, basestring): docstring = str(docstring) except (TypeError, AttributeError): docstring = '' # Find the docstring's location in the file. lineno = self._find_lineno(obj, source_lines) # Don't bother if the docstring is empty. if self._exclude_empty and not docstring: return None # Return a DocTest for this object. if module is None: filename = None else: filename = getattr(module, '__file__', module.__name__) if filename[-4:] in (".pyc", ".pyo"): filename = filename[:-1] return self._parser.get_doctest(docstring, globs, name, filename, lineno) def _find_lineno(self, obj, source_lines): """ Return a line number of the given object's docstring. Note: this method assumes that the object has a docstring. """ lineno = None # Find the line number for modules. if inspect.ismodule(obj): lineno = 0 # Find the line number for classes. # Note: this could be fooled if a class is defined multiple # times in a single file. if inspect.isclass(obj): if source_lines is None: return None pat = re.compile(r'^\s*class\s*%s\b' % getattr(obj, '__name__', '-')) for i, line in enumerate(source_lines): if pat.match(line): lineno = i break # Find the line number for functions & methods. if inspect.ismethod(obj): obj = obj.im_func if inspect.isfunction(obj): obj = obj.func_code if inspect.istraceback(obj): obj = obj.tb_frame if inspect.isframe(obj): obj = obj.f_code if inspect.iscode(obj): lineno = getattr(obj, 'co_firstlineno', None)-1 # Find the line number where the docstring starts. Assume # that it's the first line that begins with a quote mark. # Note: this could be fooled by a multiline function # signature, where a continuation line begins with a quote # mark. if lineno is not None: if source_lines is None: return lineno+1 pat = re.compile('(^|.*:)\s*\w*("|\')') for lineno in range(lineno, len(source_lines)): if pat.match(source_lines[lineno]): return lineno # We couldn't find the line number. return None ###################################################################### ## 5. DocTest Runner ###################################################################### class DocTestRunner: """ A class used to run DocTest test cases, and accumulate statistics. The `run` method is used to process a single DocTest case. It returns a tuple `(f, t)`, where `t` is the number of test cases tried, and `f` is the number of test cases that failed. >>> tests = DocTestFinder().find(_TestClass) >>> runner = DocTestRunner(verbose=False) >>> tests.sort(key = lambda test: test.name) >>> for test in tests: ... print test.name, '->', runner.run(test) _TestClass -> TestResults(failed=0, attempted=2) _TestClass.__init__ -> TestResults(failed=0, attempted=2) _TestClass.get -> TestResults(failed=0, attempted=2) _TestClass.square -> TestResults(failed=0, attempted=1) The `summarize` method prints a summary of all the test cases that have been run by the runner, and returns an aggregated `(f, t)` tuple: >>> runner.summarize(verbose=1) 4 items passed all tests: 2 tests in _TestClass 2 tests in _TestClass.__init__ 2 tests in _TestClass.get 1 tests in _TestClass.square 7 tests in 4 items. 7 passed and 0 failed. Test passed. TestResults(failed=0, attempted=7) The aggregated number of tried examples and failed examples is also available via the `tries` and `failures` attributes: >>> runner.tries 7 >>> runner.failures 0 The comparison between expected outputs and actual outputs is done by an `OutputChecker`. This comparison may be customized with a number of option flags; see the documentation for `testmod` for more information. If the option flags are insufficient, then the comparison may also be customized by passing a subclass of `OutputChecker` to the constructor. The test runner's display output can be controlled in two ways. First, an output function (`out) can be passed to `TestRunner.run`; this function will be called with strings that should be displayed. It defaults to `sys.stdout.write`. If capturing the output is not sufficient, then the display output can be also customized by subclassing DocTestRunner, and overriding the methods `report_start`, `report_success`, `report_unexpected_exception`, and `report_failure`. """ # This divider string is used to separate failure messages, and to # separate sections of the summary. DIVIDER = "*" * 70 def __init__(self, checker=None, verbose=None, optionflags=0): """ Create a new test runner. Optional keyword arg `checker` is the `OutputChecker` that should be used to compare the expected outputs and actual outputs of doctest examples. Optional keyword arg 'verbose' prints lots of stuff if true, only failures if false; by default, it's true iff '-v' is in sys.argv. Optional argument `optionflags` can be used to control how the test runner compares expected output to actual output, and how it displays failures. See the documentation for `testmod` for more information. """ self._checker = checker or OutputChecker() if verbose is None: verbose = '-v' in sys.argv self._verbose = verbose self.optionflags = optionflags self.original_optionflags = optionflags # Keep track of the examples we've run. self.tries = 0 self.failures = 0 self._name2ft = {} # Create a fake output target for capturing doctest output. self._fakeout = _SpoofOut() #///////////////////////////////////////////////////////////////// # Reporting methods #///////////////////////////////////////////////////////////////// def report_start(self, out, test, example): """ Report that the test runner is about to process the given example. (Only displays a message if verbose=True) """ if self._verbose: if example.want: out('Trying:\n' + _indent(example.source) + 'Expecting:\n' + _indent(example.want)) else: out('Trying:\n' + _indent(example.source) + 'Expecting nothing\n') def report_success(self, out, test, example, got): """ Report that the given example ran successfully. (Only displays a message if verbose=True) """ if self._verbose: out("ok\n") def report_failure(self, out, test, example, got): """ Report that the given example failed. """ out(self._failure_header(test, example) + self._checker.output_difference(example, got, self.optionflags)) def report_unexpected_exception(self, out, test, example, exc_info): """ Report that the given example raised an unexpected exception. """ out(self._failure_header(test, example) + 'Exception raised:\n' + _indent(_exception_traceback(exc_info))) def _failure_header(self, test, example): out = [self.DIVIDER] if test.filename: if test.lineno is not None and example.lineno is not None: lineno = test.lineno + example.lineno + 1 else: lineno = '?' out.append('File "%s", line %s, in %s' % (test.filename, lineno, test.name)) else: out.append('Line %s, in %s' % (example.lineno+1, test.name)) out.append('Failed example:') source = example.source out.append(_indent(source)) return '\n'.join(out) #///////////////////////////////////////////////////////////////// # DocTest Running #///////////////////////////////////////////////////////////////// def __run(self, test, compileflags, out): """ Run the examples in `test`. Write the outcome of each example with one of the `DocTestRunner.report_*` methods, using the writer function `out`. `compileflags` is the set of compiler flags that should be used to execute examples. Return a tuple `(f, t)`, where `t` is the number of examples tried, and `f` is the number of examples that failed. The examples are run in the namespace `test.globs`. """ # Keep track of the number of failures and tries. failures = tries = 0 # Save the option flags (since option directives can be used # to modify them). original_optionflags = self.optionflags SUCCESS, FAILURE, BOOM = range(3) # `outcome` state check = self._checker.check_output # Process each example. for examplenum, example in enumerate(test.examples): # If REPORT_ONLY_FIRST_FAILURE is set, then suppress # reporting after the first failure. quiet = (self.optionflags & REPORT_ONLY_FIRST_FAILURE and failures > 0) # Merge in the example's options. self.optionflags = original_optionflags if example.options: for (optionflag, val) in example.options.items(): if val: self.optionflags |= optionflag else: self.optionflags &= ~optionflag # If 'SKIP' is set, then skip this example. if self.optionflags & SKIP: continue # Record that we started this example. tries += 1 if not quiet: self.report_start(out, test, example) # Use a special filename for compile(), so we can retrieve # the source code during interactive debugging (see # __patched_linecache_getlines). filename = '<doctest %s[%d]>' % (test.name, examplenum) # Run the example in the given context (globs), and record # any exception that gets raised. (But don't intercept # keyboard interrupts.) try: # Don't blink! This is where the user's code gets run. exec compile(example.source, filename, "single", compileflags, 1) in test.globs self.debugger.set_continue() # ==== Example Finished ==== exception = None except KeyboardInterrupt: raise except: exception = sys.exc_info() self.debugger.set_continue() # ==== Example Finished ==== got = self._fakeout.getvalue() # the actual output self._fakeout.truncate(0) outcome = FAILURE # guilty until proved innocent or insane # If the example executed without raising any exceptions, # verify its output. if exception is None: if check(example.want, got, self.optionflags): outcome = SUCCESS # The example raised an exception: check if it was expected. else: exc_info = sys.exc_info() exc_msg = traceback.format_exception_only(*exc_info[:2])[-1] if not quiet: got += _exception_traceback(exc_info) # If `example.exc_msg` is None, then we weren't expecting # an exception. if example.exc_msg is None: outcome = BOOM # We expected an exception: see whether it matches. elif check(example.exc_msg, exc_msg, self.optionflags): outcome = SUCCESS # Another chance if they didn't care about the detail. elif self.optionflags & IGNORE_EXCEPTION_DETAIL: m1 = re.match(r'(?:[^:]*\.)?([^:]*:)', example.exc_msg) m2 = re.match(r'(?:[^:]*\.)?([^:]*:)', exc_msg) if m1 and m2 and check(m1.group(1), m2.group(1), self.optionflags): outcome = SUCCESS # Report the outcome. if outcome is SUCCESS: if not quiet: self.report_success(out, test, example, got) elif outcome is FAILURE: if not quiet: self.report_failure(out, test, example, got) failures += 1 elif outcome is BOOM: if not quiet: self.report_unexpected_exception(out, test, example, exc_info) failures += 1 else: assert False, ("unknown outcome", outcome) # Restore the option flags (in case they were modified) self.optionflags = original_optionflags # Record and return the number of failures and tries. self.__record_outcome(test, failures, tries) return TestResults(failures, tries) def __record_outcome(self, test, f, t): """ Record the fact that the given DocTest (`test`) generated `f` failures out of `t` tried examples. """ f2, t2 = self._name2ft.get(test.name, (0,0)) self._name2ft[test.name] = (f+f2, t+t2) self.failures += f self.tries += t __LINECACHE_FILENAME_RE = re.compile(r'<doctest ' r'(?P<name>.+)' r'\[(?P<examplenum>\d+)\]>$') def __patched_linecache_getlines(self, filename, module_globals=None): m = self.__LINECACHE_FILENAME_RE.match(filename) if m and m.group('name') == self.test.name: example = self.test.examples[int(m.group('examplenum'))] source = example.source if isinstance(source, unicode): source = source.encode('ascii', 'backslashreplace') return source.splitlines(True) else: return self.save_linecache_getlines(filename, module_globals) def run(self, test, compileflags=None, out=None, clear_globs=True): """ Run the examples in `test`, and display the results using the writer function `out`. The examples are run in the namespace `test.globs`. If `clear_globs` is true (the default), then this namespace will be cleared after the test runs, to help with garbage collection. If you would like to examine the namespace after the test completes, then use `clear_globs=False`. `compileflags` gives the set of flags that should be used by the Python compiler when running the examples. If not specified, then it will default to the set of future-import flags that apply to `globs`. The output of each example is checked using `DocTestRunner.check_output`, and the results are formatted by the `DocTestRunner.report_*` methods. """ self.test = test if compileflags is None: compileflags = _extract_future_flags(test.globs) save_stdout = sys.stdout if out is None: out = save_stdout.write sys.stdout = self._fakeout # Patch pdb.set_trace to restore sys.stdout during interactive # debugging (so it's not still redirected to self._fakeout). # Note that the interactive output will go to *our* # save_stdout, even if that's not the real sys.stdout; this # allows us to write test cases for the set_trace behavior. save_set_trace = pdb.set_trace self.debugger = _OutputRedirectingPdb(save_stdout) self.debugger.reset() pdb.set_trace = self.debugger.set_trace # Patch linecache.getlines, so we can see the example's source # when we're inside the debugger. self.save_linecache_getlines = linecache.getlines linecache.getlines = self.__patched_linecache_getlines # Make sure sys.displayhook just prints the value to stdout save_displayhook = sys.displayhook sys.displayhook = sys.__displayhook__ try: return self.__run(test, compileflags, out) finally: sys.stdout = save_stdout pdb.set_trace = save_set_trace linecache.getlines = self.save_linecache_getlines sys.displayhook = save_displayhook if clear_globs: test.globs.clear() #///////////////////////////////////////////////////////////////// # Summarization #///////////////////////////////////////////////////////////////// def summarize(self, verbose=None): """ Print a summary of all the test cases that have been run by this DocTestRunner, and return a tuple `(f, t)`, where `f` is the total number of failed examples, and `t` is the total number of tried examples. The optional `verbose` argument controls how detailed the summary is. If the verbosity is not specified, then the DocTestRunner's verbosity is used. """ if verbose is None: verbose = self._verbose notests = [] passed = [] failed = [] totalt = totalf = 0 for x in self._name2ft.items(): name, (f, t) = x assert f <= t totalt += t totalf += f if t == 0: notests.append(name) elif f == 0: passed.append( (name, t) ) else: failed.append(x) if verbose: if notests: print len(notests), "items had no tests:" notests.sort() for thing in notests: print " ", thing if passed: print len(passed), "items passed all tests:" passed.sort() for thing, count in passed: print " %3d tests in %s" % (count, thing) if failed: print self.DIVIDER print len(failed), "items had failures:" failed.sort() for thing, (f, t) in failed: print " %3d of %3d in %s" % (f, t, thing) if verbose: print totalt, "tests in", len(self._name2ft), "items." print totalt - totalf, "passed and", totalf, "failed." if totalf: print "***Test Failed***", totalf, "failures." elif verbose: print "Test passed." return TestResults(totalf, totalt) #///////////////////////////////////////////////////////////////// # Backward compatibility cruft to maintain doctest.master. #///////////////////////////////////////////////////////////////// def merge(self, other): d = self._name2ft for name, (f, t) in other._name2ft.items(): if name in d: # Don't print here by default, since doing # so breaks some of the buildbots #print "*** DocTestRunner.merge: '" + name + "' in both" \ # " testers; summing outcomes." f2, t2 = d[name] f = f + f2 t = t + t2 d[name] = f, t class OutputChecker: """ A class used to check the whether the actual output from a doctest example matches the expected output. `OutputChecker` defines two methods: `check_output`, which compares a given pair of outputs, and returns true if they match; and `output_difference`, which returns a string describing the differences between two outputs. """ def check_output(self, want, got, optionflags): """ Return True iff the actual output from an example (`got`) matches the expected output (`want`). These strings are always considered to match if they are identical; but depending on what option flags the test runner is using, several non-exact match types are also possible. See the documentation for `TestRunner` for more information about option flags. """ # Handle the common case first, for efficiency: # if they're string-identical, always return true. if got == want: return True # The values True and False replaced 1 and 0 as the return # value for boolean comparisons in Python 2.3. if not (optionflags & DONT_ACCEPT_TRUE_FOR_1): if (got,want) == ("True\n", "1\n"): return True if (got,want) == ("False\n", "0\n"): return True # <BLANKLINE> can be used as a special sequence to signify a # blank line, unless the DONT_ACCEPT_BLANKLINE flag is used. if not (optionflags & DONT_ACCEPT_BLANKLINE): # Replace <BLANKLINE> in want with a blank line. want = re.sub('(?m)^%s\s*?$' % re.escape(BLANKLINE_MARKER), '', want) # If a line in got contains only spaces, then remove the # spaces. got = re.sub('(?m)^\s*?$', '', got) if got == want: return True # This flag causes doctest to ignore any differences in the # contents of whitespace strings. Note that this can be used # in conjunction with the ELLIPSIS flag. if optionflags & NORMALIZE_WHITESPACE: got = ' '.join(got.split()) want = ' '.join(want.split()) if got == want: return True # The ELLIPSIS flag says to let the sequence "..." in `want` # match any substring in `got`. if optionflags & ELLIPSIS: if _ellipsis_match(want, got): return True # We didn't find any match; return false. return False # Should we do a fancy diff? def _do_a_fancy_diff(self, want, got, optionflags): # Not unless they asked for a fancy diff. if not optionflags & (REPORT_UDIFF | REPORT_CDIFF | REPORT_NDIFF): return False # If expected output uses ellipsis, a meaningful fancy diff is # too hard ... or maybe not. In two real-life failures Tim saw, # a diff was a major help anyway, so this is commented out. # [todo] _ellipsis_match() knows which pieces do and don't match, # and could be the basis for a kick-ass diff in this case. ##if optionflags & ELLIPSIS and ELLIPSIS_MARKER in want: ## return False # ndiff does intraline difference marking, so can be useful even # for 1-line differences. if optionflags & REPORT_NDIFF: return True # The other diff types need at least a few lines to be helpful. return want.count('\n') > 2 and got.count('\n') > 2 def output_difference(self, example, got, optionflags): """ Return a string describing the differences between the expected output for a given example (`example`) and the actual output (`got`). `optionflags` is the set of option flags used to compare `want` and `got`. """ want = example.want # If <BLANKLINE>s are being used, then replace blank lines # with <BLANKLINE> in the actual output string. if not (optionflags & DONT_ACCEPT_BLANKLINE): got = re.sub('(?m)^[ ]*(?=\n)', BLANKLINE_MARKER, got) # Check if we should use diff. if self._do_a_fancy_diff(want, got, optionflags): # Split want & got into lines. want_lines = want.splitlines(True) # True == keep line ends got_lines = got.splitlines(True) # Use difflib to find their differences. if optionflags & REPORT_UDIFF: diff = difflib.unified_diff(want_lines, got_lines, n=2) diff = list(diff)[2:] # strip the diff header kind = 'unified diff with -expected +actual' elif optionflags & REPORT_CDIFF: diff = difflib.context_diff(want_lines, got_lines, n=2) diff = list(diff)[2:] # strip the diff header kind = 'context diff with expected followed by actual' elif optionflags & REPORT_NDIFF: engine = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) diff = list(engine.compare(want_lines, got_lines)) kind = 'ndiff with -expected +actual' else: assert 0, 'Bad diff option' # Remove trailing whitespace on diff output. diff = [line.rstrip() + '\n' for line in diff] return 'Differences (%s):\n' % kind + _indent(''.join(diff)) # If we're not using diff, then simply list the expected # output followed by the actual output. if want and got: return 'Expected:\n%sGot:\n%s' % (_indent(want), _indent(got)) elif want: return 'Expected:\n%sGot nothing\n' % _indent(want) elif got: return 'Expected nothing\nGot:\n%s' % _indent(got) else: return 'Expected nothing\nGot nothing\n' class DocTestFailure(Exception): """A DocTest example has failed in debugging mode. The exception instance has variables: - test: the DocTest object being run - example: the Example object that failed - got: the actual output """ def __init__(self, test, example, got): self.test = test self.example = example self.got = got def __str__(self): return str(self.test) class UnexpectedException(Exception): """A DocTest example has encountered an unexpected exception The exception instance has variables: - test: the DocTest object being run - example: the Example object that failed - exc_info: the exception info """ def __init__(self, test, example, exc_info): self.test = test self.example = example self.exc_info = exc_info def __str__(self): return str(self.test) class DebugRunner(DocTestRunner): r"""Run doc tests but raise an exception as soon as there is a failure. If an unexpected exception occurs, an UnexpectedException is raised. It contains the test, the example, and the original exception: >>> runner = DebugRunner(verbose=False) >>> test = DocTestParser().get_doctest('>>> raise KeyError\n42', ... {}, 'foo', 'foo.py', 0) >>> try: ... runner.run(test) ... except UnexpectedException, failure: ... pass >>> failure.test is test True >>> failure.example.want '42\n' >>> exc_info = failure.exc_info >>> raise exc_info[0], exc_info[1], exc_info[2] Traceback (most recent call last): ... KeyError We wrap the original exception to give the calling application access to the test and example information. If the output doesn't match, then a DocTestFailure is raised: >>> test = DocTestParser().get_doctest(''' ... >>> x = 1 ... >>> x ... 2 ... ''', {}, 'foo', 'foo.py', 0) >>> try: ... runner.run(test) ... except DocTestFailure, failure: ... pass DocTestFailure objects provide access to the test: >>> failure.test is test True As well as to the example: >>> failure.example.want '2\n' and the actual output: >>> failure.got '1\n' If a failure or error occurs, the globals are left intact: >>> del test.globs['__builtins__'] >>> test.globs {'x': 1} >>> test = DocTestParser().get_doctest(''' ... >>> x = 2 ... >>> raise KeyError ... ''', {}, 'foo', 'foo.py', 0) >>> runner.run(test) Traceback (most recent call last): ... UnexpectedException: <DocTest foo from foo.py:0 (2 examples)> >>> del test.globs['__builtins__'] >>> test.globs {'x': 2} But the globals are cleared if there is no error: >>> test = DocTestParser().get_doctest(''' ... >>> x = 2 ... ''', {}, 'foo', 'foo.py', 0) >>> runner.run(test) TestResults(failed=0, attempted=1) >>> test.globs {} """ def run(self, test, compileflags=None, out=None, clear_globs=True): r = DocTestRunner.run(self, test, compileflags, out, False) if clear_globs: test.globs.clear() return r def report_unexpected_exception(self, out, test, example, exc_info): raise UnexpectedException(test, example, exc_info) def report_failure(self, out, test, example, got): raise DocTestFailure(test, example, got) ###################################################################### ## 6. Test Functions ###################################################################### # These should be backwards compatible. # For backward compatibility, a global instance of a DocTestRunner # class, updated by testmod. master = None def testmod(m=None, name=None, globs=None, verbose=None, report=True, optionflags=0, extraglobs=None, raise_on_error=False, exclude_empty=False): """m=None, name=None, globs=None, verbose=None, report=True, optionflags=0, extraglobs=None, raise_on_error=False, exclude_empty=False Test examples in docstrings in functions and classes reachable from module m (or the current module if m is not supplied), starting with m.__doc__. Also test examples reachable from dict m.__test__ if it exists and is not None. m.__test__ maps names to functions, classes and strings; function and class docstrings are tested even if the name is private; strings are tested directly, as if they were docstrings. Return (#failures, #tests). See help(doctest) for an overview. Optional keyword arg "name" gives the name of the module; by default use m.__name__. Optional keyword arg "globs" gives a dict to be used as the globals when executing examples; by default, use m.__dict__. A copy of this dict is actually used for each docstring, so that each docstring's examples start with a clean slate. Optional keyword arg "extraglobs" gives a dictionary that should be merged into the globals that are used to execute examples. By default, no extra globals are used. This is new in 2.4. Optional keyword arg "verbose" prints lots of stuff if true, prints only failures if false; by default, it's true iff "-v" is in sys.argv. Optional keyword arg "report" prints a summary at the end when true, else prints nothing at the end. In verbose mode, the summary is detailed, else very brief (in fact, empty if all tests passed). Optional keyword arg "optionflags" or's together module constants, and defaults to 0. This is new in 2.3. Possible values (see the docs for details): DONT_ACCEPT_TRUE_FOR_1 DONT_ACCEPT_BLANKLINE NORMALIZE_WHITESPACE ELLIPSIS SKIP IGNORE_EXCEPTION_DETAIL REPORT_UDIFF REPORT_CDIFF REPORT_NDIFF REPORT_ONLY_FIRST_FAILURE Optional keyword arg "raise_on_error" raises an exception on the first unexpected exception or failure. This allows failures to be post-mortem debugged. Advanced tomfoolery: testmod runs methods of a local instance of class doctest.Tester, then merges the results into (or creates) global Tester instance doctest.master. Methods of doctest.master can be called directly too, if you want to do something unusual. Passing report=0 to testmod is especially useful then, to delay displaying a summary. Invoke doctest.master.summarize(verbose) when you're done fiddling. """ global master # If no module was given, then use __main__. if m is None: # DWA - m will still be None if this wasn't invoked from the command # line, in which case the following TypeError is about as good an error # as we should expect m = sys.modules.get('__main__') # Check that we were actually given a module. if not inspect.ismodule(m): raise TypeError("testmod: module required; %r" % (m,)) # If no name was given, then use the module's name. if name is None: name = m.__name__ # Find, parse, and run all tests in the given module. finder = DocTestFinder(exclude_empty=exclude_empty) if raise_on_error: runner = DebugRunner(verbose=verbose, optionflags=optionflags) else: runner = DocTestRunner(verbose=verbose, optionflags=optionflags) for test in finder.find(m, name, globs=globs, extraglobs=extraglobs): runner.run(test) if report: runner.summarize() if master is None: master = runner else: master.merge(runner) return TestResults(runner.failures, runner.tries) def testfile(filename, module_relative=True, name=None, package=None, globs=None, verbose=None, report=True, optionflags=0, extraglobs=None, raise_on_error=False, parser=DocTestParser(), encoding=None): """ Test examples in the given file. Return (#failures, #tests). Optional keyword arg "module_relative" specifies how filenames should be interpreted: - If "module_relative" is True (the default), then "filename" specifies a module-relative path. By default, this path is relative to the calling module's directory; but if the "package" argument is specified, then it is relative to that package. To ensure os-independence, "filename" should use "/" characters to separate path segments, and should not be an absolute path (i.e., it may not begin with "/"). - If "module_relative" is False, then "filename" specifies an os-specific path. The path may be absolute or relative (to the current working directory). Optional keyword arg "name" gives the name of the test; by default use the file's basename. Optional keyword argument "package" is a Python package or the name of a Python package whose directory should be used as the base directory for a module relative filename. If no package is specified, then the calling module's directory is used as the base directory for module relative filenames. It is an error to specify "package" if "module_relative" is False. Optional keyword arg "globs" gives a dict to be used as the globals when executing examples; by default, use {}. A copy of this dict is actually used for each docstring, so that each docstring's examples start with a clean slate. Optional keyword arg "extraglobs" gives a dictionary that should be merged into the globals that are used to execute examples. By default, no extra globals are used. Optional keyword arg "verbose" prints lots of stuff if true, prints only failures if false; by default, it's true iff "-v" is in sys.argv. Optional keyword arg "report" prints a summary at the end when true, else prints nothing at the end. In verbose mode, the summary is detailed, else very brief (in fact, empty if all tests passed). Optional keyword arg "optionflags" or's together module constants, and defaults to 0. Possible values (see the docs for details): DONT_ACCEPT_TRUE_FOR_1 DONT_ACCEPT_BLANKLINE NORMALIZE_WHITESPACE ELLIPSIS SKIP IGNORE_EXCEPTION_DETAIL REPORT_UDIFF REPORT_CDIFF REPORT_NDIFF REPORT_ONLY_FIRST_FAILURE Optional keyword arg "raise_on_error" raises an exception on the first unexpected exception or failure. This allows failures to be post-mortem debugged. Optional keyword arg "parser" specifies a DocTestParser (or subclass) that should be used to extract tests from the files. Optional keyword arg "encoding" specifies an encoding that should be used to convert the file to unicode. Advanced tomfoolery: testmod runs methods of a local instance of class doctest.Tester, then merges the results into (or creates) global Tester instance doctest.master. Methods of doctest.master can be called directly too, if you want to do something unusual. Passing report=0 to testmod is especially useful then, to delay displaying a summary. Invoke doctest.master.summarize(verbose) when you're done fiddling. """ global master if package and not module_relative: raise ValueError("Package may only be specified for module-" "relative paths.") # Relativize the path text, filename = _load_testfile(filename, package, module_relative) # If no name was given, then use the file's name. if name is None: name = os.path.basename(filename) # Assemble the globals. if globs is None: globs = {} else: globs = globs.copy() if extraglobs is not None: globs.update(extraglobs) if '__name__' not in globs: globs['__name__'] = '__main__' if raise_on_error: runner = DebugRunner(verbose=verbose, optionflags=optionflags) else: runner = DocTestRunner(verbose=verbose, optionflags=optionflags) if encoding is not None: text = text.decode(encoding) # Read the file, convert it to a test, and run it. test = parser.get_doctest(text, globs, name, filename, 0) runner.run(test) if report: runner.summarize() if master is None: master = runner else: master.merge(runner) return TestResults(runner.failures, runner.tries) def run_docstring_examples(f, globs, verbose=False, name="NoName", compileflags=None, optionflags=0): """ Test examples in the given object's docstring (`f`), using `globs` as globals. Optional argument `name` is used in failure messages. If the optional argument `verbose` is true, then generate output even if there are no failures. `compileflags` gives the set of flags that should be used by the Python compiler when running the examples. If not specified, then it will default to the set of future-import flags that apply to `globs`. Optional keyword arg `optionflags` specifies options for the testing and output. See the documentation for `testmod` for more information. """ # Find, parse, and run all tests in the given module. finder = DocTestFinder(verbose=verbose, recurse=False) runner = DocTestRunner(verbose=verbose, optionflags=optionflags) for test in finder.find(f, name, globs=globs): runner.run(test, compileflags=compileflags) ###################################################################### ## 7. Tester ###################################################################### # This is provided only for backwards compatibility. It's not # actually used in any way. class Tester: def __init__(self, mod=None, globs=None, verbose=None, optionflags=0): warnings.warn("class Tester is deprecated; " "use class doctest.DocTestRunner instead", DeprecationWarning, stacklevel=2) if mod is None and globs is None: raise TypeError("Tester.__init__: must specify mod or globs") if mod is not None and not inspect.ismodule(mod): raise TypeError("Tester.__init__: mod must be a module; %r" % (mod,)) if globs is None: globs = mod.__dict__ self.globs = globs self.verbose = verbose self.optionflags = optionflags self.testfinder = DocTestFinder() self.testrunner = DocTestRunner(verbose=verbose, optionflags=optionflags) def runstring(self, s, name): test = DocTestParser().get_doctest(s, self.globs, name, None, None) if self.verbose: print "Running string", name (f,t) = self.testrunner.run(test) if self.verbose: print f, "of", t, "examples failed in string", name return TestResults(f,t) def rundoc(self, object, name=None, module=None): f = t = 0 tests = self.testfinder.find(object, name, module=module, globs=self.globs) for test in tests: (f2, t2) = self.testrunner.run(test) (f,t) = (f+f2, t+t2) return TestResults(f,t) def rundict(self, d, name, module=None): import types m = types.ModuleType(name) m.__dict__.update(d) if module is None: module = False return self.rundoc(m, name, module) def run__test__(self, d, name): import types m = types.ModuleType(name) m.__test__ = d return self.rundoc(m, name) def summarize(self, verbose=None): return self.testrunner.summarize(verbose) def merge(self, other): self.testrunner.merge(other.testrunner) ###################################################################### ## 8. Unittest Support ###################################################################### _unittest_reportflags = 0 def set_unittest_reportflags(flags): """Sets the unittest option flags. The old flag is returned so that a runner could restore the old value if it wished to: >>> import doctest >>> old = doctest._unittest_reportflags >>> doctest.set_unittest_reportflags(REPORT_NDIFF | ... REPORT_ONLY_FIRST_FAILURE) == old True >>> doctest._unittest_reportflags == (REPORT_NDIFF | ... REPORT_ONLY_FIRST_FAILURE) True Only reporting flags can be set: >>> doctest.set_unittest_reportflags(ELLIPSIS) Traceback (most recent call last): ... ValueError: ('Only reporting flags allowed', 8) >>> doctest.set_unittest_reportflags(old) == (REPORT_NDIFF | ... REPORT_ONLY_FIRST_FAILURE) True """ global _unittest_reportflags if (flags & REPORTING_FLAGS) != flags: raise ValueError("Only reporting flags allowed", flags) old = _unittest_reportflags _unittest_reportflags = flags return old class DocTestCase(unittest.TestCase): def __init__(self, test, optionflags=0, setUp=None, tearDown=None, checker=None): unittest.TestCase.__init__(self) self._dt_optionflags = optionflags self._dt_checker = checker self._dt_test = test self._dt_setUp = setUp self._dt_tearDown = tearDown def setUp(self): test = self._dt_test if self._dt_setUp is not None: self._dt_setUp(test) def tearDown(self): test = self._dt_test if self._dt_tearDown is not None: self._dt_tearDown(test) test.globs.clear() def runTest(self): test = self._dt_test old = sys.stdout new = StringIO() optionflags = self._dt_optionflags if not (optionflags & REPORTING_FLAGS): # The option flags don't include any reporting flags, # so add the default reporting flags optionflags |= _unittest_reportflags runner = DocTestRunner(optionflags=optionflags, checker=self._dt_checker, verbose=False) try: runner.DIVIDER = "-"*70 failures, tries = runner.run( test, out=new.write, clear_globs=False) finally: sys.stdout = old if failures: raise self.failureException(self.format_failure(new.getvalue())) def format_failure(self, err): test = self._dt_test if test.lineno is None: lineno = 'unknown line number' else: lineno = '%s' % test.lineno lname = '.'.join(test.name.split('.')[-1:]) return ('Failed doctest test for %s\n' ' File "%s", line %s, in %s\n\n%s' % (test.name, test.filename, lineno, lname, err) ) def debug(self): r"""Run the test case without results and without catching exceptions The unit test framework includes a debug method on test cases and test suites to support post-mortem debugging. The test code is run in such a way that errors are not caught. This way a caller can catch the errors and initiate post-mortem debugging. The DocTestCase provides a debug method that raises UnexpectedException errors if there is an unexpected exception: >>> test = DocTestParser().get_doctest('>>> raise KeyError\n42', ... {}, 'foo', 'foo.py', 0) >>> case = DocTestCase(test) >>> try: ... case.debug() ... except UnexpectedException, failure: ... pass The UnexpectedException contains the test, the example, and the original exception: >>> failure.test is test True >>> failure.example.want '42\n' >>> exc_info = failure.exc_info >>> raise exc_info[0], exc_info[1], exc_info[2] Traceback (most recent call last): ... KeyError If the output doesn't match, then a DocTestFailure is raised: >>> test = DocTestParser().get_doctest(''' ... >>> x = 1 ... >>> x ... 2 ... ''', {}, 'foo', 'foo.py', 0) >>> case = DocTestCase(test) >>> try: ... case.debug() ... except DocTestFailure, failure: ... pass DocTestFailure objects provide access to the test: >>> failure.test is test True As well as to the example: >>> failure.example.want '2\n' and the actual output: >>> failure.got '1\n' """ self.setUp() runner = DebugRunner(optionflags=self._dt_optionflags, checker=self._dt_checker, verbose=False) runner.run(self._dt_test, clear_globs=False) self.tearDown() def id(self): return self._dt_test.name def __eq__(self, other): if type(self) is not type(other): return NotImplemented return self._dt_test == other._dt_test and \ self._dt_optionflags == other._dt_optionflags and \ self._dt_setUp == other._dt_setUp and \ self._dt_tearDown == other._dt_tearDown and \ self._dt_checker == other._dt_checker def __ne__(self, other): return not self == other def __hash__(self): return hash((self._dt_optionflags, self._dt_setUp, self._dt_tearDown, self._dt_checker)) def __repr__(self): name = self._dt_test.name.split('.') return "%s (%s)" % (name[-1], '.'.join(name[:-1])) __str__ = __repr__ def shortDescription(self): return "Doctest: " + self._dt_test.name class SkipDocTestCase(DocTestCase): def __init__(self, module): self.module = module DocTestCase.__init__(self, None) def setUp(self): self.skipTest("DocTestSuite will not work with -O2 and above") def test_skip(self): pass def shortDescription(self): return "Skipping tests from %s" % self.module.__name__ __str__ = shortDescription def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None, **options): """ Convert doctest tests for a module to a unittest test suite. This converts each documentation string in a module that contains doctest tests to a unittest test case. If any of the tests in a doc string fail, then the test case fails. An exception is raised showing the name of the file containing the test and a (sometimes approximate) line number. The `module` argument provides the module to be tested. The argument can be either a module or a module name. If no argument is given, the calling module is used. A number of options may be provided as keyword arguments: setUp A set-up function. This is called before running the tests in each file. The setUp function will be passed a DocTest object. The setUp function can access the test globals as the globs attribute of the test passed. tearDown A tear-down function. This is called after running the tests in each file. The tearDown function will be passed a DocTest object. The tearDown function can access the test globals as the globs attribute of the test passed. globs A dictionary containing initial global variables for the tests. optionflags A set of doctest option flags expressed as an integer. """ if test_finder is None: test_finder = DocTestFinder() module = _normalize_module(module) tests = test_finder.find(module, globs=globs, extraglobs=extraglobs) if not tests and sys.flags.optimize >=2: # Skip doctests when running with -O2 suite = unittest.TestSuite() suite.addTest(SkipDocTestCase(module)) return suite elif not tests: # Why do we want to do this? Because it reveals a bug that might # otherwise be hidden. # It is probably a bug that this exception is not also raised if the # number of doctest examples in tests is zero (i.e. if no doctest # examples were found). However, we should probably not be raising # an exception at all here, though it is too late to make this change # for a maintenance release. See also issue #14649. raise ValueError(module, "has no docstrings") tests.sort() suite = unittest.TestSuite() for test in tests: if len(test.examples) == 0: continue if not test.filename: filename = module.__file__ if filename[-4:] in (".pyc", ".pyo"): filename = filename[:-1] test.filename = filename suite.addTest(DocTestCase(test, **options)) return suite class DocFileCase(DocTestCase): def id(self): return '_'.join(self._dt_test.name.split('.')) def __repr__(self): return self._dt_test.filename __str__ = __repr__ def format_failure(self, err): return ('Failed doctest test for %s\n File "%s", line 0\n\n%s' % (self._dt_test.name, self._dt_test.filename, err) ) def DocFileTest(path, module_relative=True, package=None, globs=None, parser=DocTestParser(), encoding=None, **options): if globs is None: globs = {} else: globs = globs.copy() if package and not module_relative: raise ValueError("Package may only be specified for module-" "relative paths.") # Relativize the path. doc, path = _load_testfile(path, package, module_relative) if "__file__" not in globs: globs["__file__"] = path # Find the file and read it. name = os.path.basename(path) # If an encoding is specified, use it to convert the file to unicode if encoding is not None: doc = doc.decode(encoding) # Convert it to a test, and wrap it in a DocFileCase. test = parser.get_doctest(doc, globs, name, path, 0) return DocFileCase(test, **options) def DocFileSuite(*paths, **kw): """A unittest suite for one or more doctest files. The path to each doctest file is given as a string; the interpretation of that string depends on the keyword argument "module_relative". A number of options may be provided as keyword arguments: module_relative If "module_relative" is True, then the given file paths are interpreted as os-independent module-relative paths. By default, these paths are relative to the calling module's directory; but if the "package" argument is specified, then they are relative to that package. To ensure os-independence, "filename" should use "/" characters to separate path segments, and may not be an absolute path (i.e., it may not begin with "/"). If "module_relative" is False, then the given file paths are interpreted as os-specific paths. These paths may be absolute or relative (to the current working directory). package A Python package or the name of a Python package whose directory should be used as the base directory for module relative paths. If "package" is not specified, then the calling module's directory is used as the base directory for module relative filenames. It is an error to specify "package" if "module_relative" is False. setUp A set-up function. This is called before running the tests in each file. The setUp function will be passed a DocTest object. The setUp function can access the test globals as the globs attribute of the test passed. tearDown A tear-down function. This is called after running the tests in each file. The tearDown function will be passed a DocTest object. The tearDown function can access the test globals as the globs attribute of the test passed. globs A dictionary containing initial global variables for the tests. optionflags A set of doctest option flags expressed as an integer. parser A DocTestParser (or subclass) that should be used to extract tests from the files. encoding An encoding that will be used to convert the files to unicode. """ suite = unittest.TestSuite() # We do this here so that _normalize_module is called at the right # level. If it were called in DocFileTest, then this function # would be the caller and we might guess the package incorrectly. if kw.get('module_relative', True): kw['package'] = _normalize_module(kw.get('package')) for path in paths: suite.addTest(DocFileTest(path, **kw)) return suite ###################################################################### ## 9. Debugging Support ###################################################################### def script_from_examples(s): r"""Extract script from text with examples. Converts text with examples to a Python script. Example input is converted to regular code. Example output and all other words are converted to comments: >>> text = ''' ... Here are examples of simple math. ... ... Python has super accurate integer addition ... ... >>> 2 + 2 ... 5 ... ... And very friendly error messages: ... ... >>> 1/0 ... To Infinity ... And ... Beyond ... ... You can use logic if you want: ... ... >>> if 0: ... ... blah ... ... blah ... ... ... ... Ho hum ... ''' >>> print script_from_examples(text) # Here are examples of simple math. # # Python has super accurate integer addition # 2 + 2 # Expected: ## 5 # # And very friendly error messages: # 1/0 # Expected: ## To Infinity ## And ## Beyond # # You can use logic if you want: # if 0: blah blah # # Ho hum <BLANKLINE> """ output = [] for piece in DocTestParser().parse(s): if isinstance(piece, Example): # Add the example's source code (strip trailing NL) output.append(piece.source[:-1]) # Add the expected output: want = piece.want if want: output.append('# Expected:') output += ['## '+l for l in want.split('\n')[:-1]] else: # Add non-example text. output += [_comment_line(l) for l in piece.split('\n')[:-1]] # Trim junk on both ends. while output and output[-1] == '#': output.pop() while output and output[0] == '#': output.pop(0) # Combine the output, and return it. # Add a courtesy newline to prevent exec from choking (see bug #1172785) return '\n'.join(output) + '\n' def testsource(module, name): """Extract the test sources from a doctest docstring as a script. Provide the module (or dotted name of the module) containing the test to be debugged and the name (within the module) of the object with the doc string with tests to be debugged. """ module = _normalize_module(module) tests = DocTestFinder().find(module) test = [t for t in tests if t.name == name] if not test: raise ValueError(name, "not found in tests") test = test[0] testsrc = script_from_examples(test.docstring) return testsrc def debug_src(src, pm=False, globs=None): """Debug a single doctest docstring, in argument `src`'""" testsrc = script_from_examples(src) debug_script(testsrc, pm, globs) def debug_script(src, pm=False, globs=None): "Debug a test script. `src` is the script, as a string." import pdb # Note that tempfile.NameTemporaryFile() cannot be used. As the # docs say, a file so created cannot be opened by name a second time # on modern Windows boxes, and execfile() needs to open it. srcfilename = tempfile.mktemp(".py", "doctestdebug") f = open(srcfilename, 'w') f.write(src) f.close() try: if globs: globs = globs.copy() else: globs = {} if pm: try: execfile(srcfilename, globs, globs) except: print sys.exc_info()[1] pdb.post_mortem(sys.exc_info()[2]) else: # Note that %r is vital here. '%s' instead can, e.g., cause # backslashes to get treated as metacharacters on Windows. pdb.run("execfile(%r)" % srcfilename, globs, globs) finally: os.remove(srcfilename) def debug(module, name, pm=False): """Debug a single doctest docstring. Provide the module (or dotted name of the module) containing the test to be debugged and the name (within the module) of the object with the docstring with tests to be debugged. """ module = _normalize_module(module) testsrc = testsource(module, name) debug_script(testsrc, pm, module.__dict__) ###################################################################### ## 10. Example Usage ###################################################################### class _TestClass: """ A pointless class, for sanity-checking of docstring testing. Methods: square() get() >>> _TestClass(13).get() + _TestClass(-12).get() 1 >>> hex(_TestClass(13).square().get()) '0xa9' """ def __init__(self, val): """val -> _TestClass object with associated value val. >>> t = _TestClass(123) >>> print t.get() 123 """ self.val = val def square(self): """square() -> square TestClass's associated value >>> _TestClass(13).square().get() 169 """ self.val = self.val ** 2 return self def get(self): """get() -> return TestClass's associated value. >>> x = _TestClass(-42) >>> print x.get() -42 """ return self.val __test__ = {"_TestClass": _TestClass, "string": r""" Example of a string object, searched as-is. >>> x = 1; y = 2 >>> x + y, x * y (3, 2) """, "bool-int equivalence": r""" In 2.2, boolean expressions displayed 0 or 1. By default, we still accept them. This can be disabled by passing DONT_ACCEPT_TRUE_FOR_1 to the new optionflags argument. >>> 4 == 4 1 >>> 4 == 4 True >>> 4 > 4 0 >>> 4 > 4 False """, "blank lines": r""" Blank lines can be marked with <BLANKLINE>: >>> print 'foo\n\nbar\n' foo <BLANKLINE> bar <BLANKLINE> """, "ellipsis": r""" If the ellipsis flag is used, then '...' can be used to elide substrings in the desired output: >>> print range(1000) #doctest: +ELLIPSIS [0, 1, 2, ..., 999] """, "whitespace normalization": r""" If the whitespace normalization flag is used, then differences in whitespace are ignored. >>> print range(30) #doctest: +NORMALIZE_WHITESPACE [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] """, } def _test(): testfiles = [arg for arg in sys.argv[1:] if arg and arg[0] != '-'] if not testfiles: name = os.path.basename(sys.argv[0]) if '__loader__' in globals(): # python -m name, _ = os.path.splitext(name) print("usage: {0} [-v] file ...".format(name)) return 2 for filename in testfiles: if filename.endswith(".py"): # It is a module -- insert its dir into sys.path and try to # import it. If it is part of a package, that possibly # won't work because of package imports. dirname, filename = os.path.split(filename) sys.path.insert(0, dirname) m = __import__(filename[:-3]) del sys.path[0] failures, _ = testmod(m) else: failures, _ = testfile(filename, module_relative=False) if failures: return 1 return 0 if __name__ == "__main__": sys.exit(_test())
gpl-3.0
[ 3, 5673, 8868, 14, 199, 3, 17646, 68, 370, 314, 4575, 2881, 3193, 13, 19825, 13, 8339, 12, 701, 26244, 11379, 878, 334, 2906, 32, 1548, 14, 1308, 680, 199, 3, 16593, 5857, 655, 14666, 1470, 436, 24200, 316, 701, 26, 199, 3, 258, 1603, 1017, 481, 427, 265, 199, 3, 258, 17379, 3079, 491, 2262, 199, 199, 3, 2165, 11923, 465, 13, 374, 27, 675, 737, 2195, 5705, 22633, 27, 949, 3750, 27, 949, 8023, 1388, 27, 655, 26729, 1, 199, 199, 82, 624, 2377, 8868, 1553, 282, 10059, 367, 3879, 7251, 315, 20964, 14, 199, 199, 607, 3486, 270, 675, 12, 1284, 1924, 859, 603, 370, 506, 12470, 543, 26, 199, 199, 318, 485, 396, 837, 272, 492, 8868, 272, 8868, 14, 29446, 342, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 485, 396, 342, 199, 199, 28226, 3879, 314, 859, 465, 282, 2884, 911, 7675, 314, 7251, 315, 314, 199, 1301, 5465, 370, 664, 7934, 436, 16317, 26, 199, 199, 1548, 603, 14, 647, 199, 199, 2765, 7859, 1133, 2929, 7003, 7444, 376, 2893, 6918, 12, 315, 1314, 1930, 314, 199, 25299, 2893, 8, 83, 9, 436, 314, 7675, 8, 83, 9, 402, 314, 5988, 8, 83, 9, 787, 12487, 370, 3839, 199, 8, 26460, 440, 4635, 31, 2952, 4635, 365, 282, 634, 313, 11176, 665, 16, 14, 18, 336, 2292, 27359, 436, 314, 4242, 199, 604, 402, 1072, 365, 298, 774, 3405, 15848, 199, 199, 2540, 652, 543, 314, 446, 86, 6258, 3140, 26, 199, 199, 1548, 603, 14, 647, 446, 86, 199, 199, 460, 282, 16212, 3622, 402, 1006, 7251, 16416, 365, 12487, 370, 3839, 12, 3180, 199, 1045, 2661, 1376, 23747, 737, 314, 1284, 14, 199, 199, 5556, 883, 3542, 3376, 818, 701, 9476, 298, 3832, 29, 549, 2, 370, 511, 1494, 12, 503, 557, 20215, 390, 199, 390, 701, 9476, 298, 3832, 29, 797, 1674, 221, 1010, 1902, 402, 5204, 5560, 12, 984, 14, 3020, 365, 440, 199, 15425, 1942, 701, 511, 1494, 14, 199, 199, 10924, 787, 282, 32246, 402, 1163, 15217, 370, 1255, 26721, 12, 5893, 13150, 199, 1045, 314, 2882, 10059, 12, 436, 2291, 367, 3879, 2222, 13, 4718, 1318, 199, 1725, 3035, 26721, 14, 221, 6006, 787, 2597, 5002, 15217, 370, 4278, 4184, 199, 1618, 8868, 1159, 849, 5112, 1384, 14, 221, 1666, 314, 11243, 10944, 30247, 367, 199, 5087, 14, 199, 624, 199, 199, 363, 21841, 363, 275, 283, 264, 27486, 1872, 655, 7, 199, 199, 363, 452, 363, 275, 359, 272, 327, 378, 12, 3207, 24870, 272, 283, 2683, 63, 1422, 4173, 297, 272, 283, 31874, 63, 13089, 63, 15064, 63, 2707, 63, 17, 297, 272, 283, 31874, 63, 13089, 63, 29353, 297, 272, 283, 10765, 11025, 63, 20620, 297, 272, 283, 21677, 297, 272, 283, 13525, 297, 272, 283, 11209, 63, 15375, 63, 25081, 297, 272, 283, 6790, 689, 1311, 615, 63, 4831, 297, 272, 283, 17356, 63, 53, 10596, 297, 272, 283, 17356, 63, 35, 10596, 297, 272, 283, 17356, 63, 46, 10596, 297, 272, 283, 17356, 63, 10452, 63, 12903, 63, 13989, 297, 272, 283, 17356, 1206, 63, 4831, 297, 272, 327, 413, 14, 20511, 17471, 272, 327, 499, 14, 5679, 1253, 17495, 272, 283, 9846, 297, 272, 283, 30311, 297, 272, 327, 650, 14, 5454, 396, 10191, 272, 283, 30311, 2842, 297, 272, 327, 841, 14, 5454, 396, 481, 5755, 272, 283, 30311, 11791, 297, 272, 327, 959, 14, 5454, 396, 3378, 1372, 272, 283, 3768, 13649, 297, 272, 283, 2959, 3048, 297, 272, 283, 30311, 6782, 297, 272, 283, 8708, 1726, 297, 272, 283, 7084, 7446, 297, 272, 327, 1227, 14, 1379, 17471, 272, 283, 29446, 297, 272, 283, 21091, 297, 272, 283, 1065, 63, 12485, 63, 8589, 297, 272, 327, 1520, 14, 377, 17338, 272, 283, 22403, 297, 272, 327, 1695, 14, 1910, 1770, 12502, 272, 283, 3768, 10591, 297, 272, 283, 3768, 1173, 6207, 297, 272, 283, 409, 63, 2796, 63, 3070, 2469, 297, 272, 327, 1749, 14, 14245, 1540, 12502, 272, 283, 1579, 63, 504, 63, 8589, 297, 272, 283, 396, 1365, 297, 272, 283, 1757, 63, 2164, 297, 272, 283, 1757, 297, 199, 61, 199, 199, 646, 636, 2443, 363, 199, 199, 646, 984, 12, 5190, 12, 6485, 12, 26026, 12, 747, 12, 295, 199, 646, 2882, 12, 27070, 12, 10543, 12, 5549, 199, 646, 3598, 199, 504, 5228, 492, 5228, 199, 504, 5055, 492, 12863, 199, 199, 774, 6579, 275, 12863, 360, 774, 6579, 297, 283, 4892, 22040, 358, 199, 199, 3, 6006, 787, 841, 5678, 3992, 26, 199, 3, 221, 446, 5679, 26, 282, 665, 1365, 12, 2934, 30, 4092, 12, 12254, 376, 1109, 345, 13, 12485, 1004, 1329, 14, 199, 3, 221, 446, 17495, 26, 282, 3245, 402, 7251, 12, 4565, 687, 282, 9214, 12, 12254, 199, 3, 259, 2256, 3595, 2382, 314, 9214, 20382, 687, 334, 354, 12, 1788, 12, 5874, 680, 199, 3, 221, 446, 17495, 11791, 26, 5536, 83, 5454, 2925, 687, 282, 1627, 909, 1159, 9214, 436, 199, 3, 259, 2399, 10470, 2251, 7, 20964, 14, 199, 3, 221, 446, 5454, 13649, 26, 7858, 17495, 5560, 12, 436, 11162, 15409, 11076, 14, 199, 3, 199, 3, 2002, 314, 5678, 24945, 365, 26, 199, 3, 199, 3, 17907, 769, 402, 26, 199, 3, 435, 28712, 7861, 435, 26533, 7861, 435, 375, 9018, 199, 3, 1204, 785, 92, 1553, 30311, 11791, 5118, 1204, 17495, 1204, 1553, 3768, 13649, 5118, 1204, 2604, 92, 199, 3, 435, 28712, 7861, 435, 26533, 7861, 435, 375, 9018, 199, 3, 14960, 1204, 5679, 1204, 199, 3, 14960, 1204, 257, 2263, 257, 1204, 199, 3, 14960, 1204, 5679, 1204, 199, 3, 14960, 435, 26533, 199, 199, 3, 3207, 5262, 14, 199, 199, 13352, 4831, 63, 8285, 63, 2339, 275, 1052, 199, 318, 2274, 63, 1422, 4173, 8, 354, 304, 272, 327, 2790, 282, 892, 3305, 7444, 658, 354, 64, 365, 2575, 6040, 14, 272, 372, 11662, 1075, 4831, 63, 8285, 63, 2339, 14, 5486, 8, 354, 12, 413, 5213, 822, 8, 13352, 4831, 63, 8285, 63, 2339, 430, 199, 199, 31874, 63, 13089, 63, 15064, 63, 2707, 63, 17, 275, 2274, 63, 1422, 4173, 360, 31874, 63, 13089, 63, 15064 ]
[ 5673, 8868, 14, 199, 3, 17646, 68, 370, 314, 4575, 2881, 3193, 13, 19825, 13, 8339, 12, 701, 26244, 11379, 878, 334, 2906, 32, 1548, 14, 1308, 680, 199, 3, 16593, 5857, 655, 14666, 1470, 436, 24200, 316, 701, 26, 199, 3, 258, 1603, 1017, 481, 427, 265, 199, 3, 258, 17379, 3079, 491, 2262, 199, 199, 3, 2165, 11923, 465, 13, 374, 27, 675, 737, 2195, 5705, 22633, 27, 949, 3750, 27, 949, 8023, 1388, 27, 655, 26729, 1, 199, 199, 82, 624, 2377, 8868, 1553, 282, 10059, 367, 3879, 7251, 315, 20964, 14, 199, 199, 607, 3486, 270, 675, 12, 1284, 1924, 859, 603, 370, 506, 12470, 543, 26, 199, 199, 318, 485, 396, 837, 272, 492, 8868, 272, 8868, 14, 29446, 342, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 485, 396, 342, 199, 199, 28226, 3879, 314, 859, 465, 282, 2884, 911, 7675, 314, 7251, 315, 314, 199, 1301, 5465, 370, 664, 7934, 436, 16317, 26, 199, 199, 1548, 603, 14, 647, 199, 199, 2765, 7859, 1133, 2929, 7003, 7444, 376, 2893, 6918, 12, 315, 1314, 1930, 314, 199, 25299, 2893, 8, 83, 9, 436, 314, 7675, 8, 83, 9, 402, 314, 5988, 8, 83, 9, 787, 12487, 370, 3839, 199, 8, 26460, 440, 4635, 31, 2952, 4635, 365, 282, 634, 313, 11176, 665, 16, 14, 18, 336, 2292, 27359, 436, 314, 4242, 199, 604, 402, 1072, 365, 298, 774, 3405, 15848, 199, 199, 2540, 652, 543, 314, 446, 86, 6258, 3140, 26, 199, 199, 1548, 603, 14, 647, 446, 86, 199, 199, 460, 282, 16212, 3622, 402, 1006, 7251, 16416, 365, 12487, 370, 3839, 12, 3180, 199, 1045, 2661, 1376, 23747, 737, 314, 1284, 14, 199, 199, 5556, 883, 3542, 3376, 818, 701, 9476, 298, 3832, 29, 549, 2, 370, 511, 1494, 12, 503, 557, 20215, 390, 199, 390, 701, 9476, 298, 3832, 29, 797, 1674, 221, 1010, 1902, 402, 5204, 5560, 12, 984, 14, 3020, 365, 440, 199, 15425, 1942, 701, 511, 1494, 14, 199, 199, 10924, 787, 282, 32246, 402, 1163, 15217, 370, 1255, 26721, 12, 5893, 13150, 199, 1045, 314, 2882, 10059, 12, 436, 2291, 367, 3879, 2222, 13, 4718, 1318, 199, 1725, 3035, 26721, 14, 221, 6006, 787, 2597, 5002, 15217, 370, 4278, 4184, 199, 1618, 8868, 1159, 849, 5112, 1384, 14, 221, 1666, 314, 11243, 10944, 30247, 367, 199, 5087, 14, 199, 624, 199, 199, 363, 21841, 363, 275, 283, 264, 27486, 1872, 655, 7, 199, 199, 363, 452, 363, 275, 359, 272, 327, 378, 12, 3207, 24870, 272, 283, 2683, 63, 1422, 4173, 297, 272, 283, 31874, 63, 13089, 63, 15064, 63, 2707, 63, 17, 297, 272, 283, 31874, 63, 13089, 63, 29353, 297, 272, 283, 10765, 11025, 63, 20620, 297, 272, 283, 21677, 297, 272, 283, 13525, 297, 272, 283, 11209, 63, 15375, 63, 25081, 297, 272, 283, 6790, 689, 1311, 615, 63, 4831, 297, 272, 283, 17356, 63, 53, 10596, 297, 272, 283, 17356, 63, 35, 10596, 297, 272, 283, 17356, 63, 46, 10596, 297, 272, 283, 17356, 63, 10452, 63, 12903, 63, 13989, 297, 272, 283, 17356, 1206, 63, 4831, 297, 272, 327, 413, 14, 20511, 17471, 272, 327, 499, 14, 5679, 1253, 17495, 272, 283, 9846, 297, 272, 283, 30311, 297, 272, 327, 650, 14, 5454, 396, 10191, 272, 283, 30311, 2842, 297, 272, 327, 841, 14, 5454, 396, 481, 5755, 272, 283, 30311, 11791, 297, 272, 327, 959, 14, 5454, 396, 3378, 1372, 272, 283, 3768, 13649, 297, 272, 283, 2959, 3048, 297, 272, 283, 30311, 6782, 297, 272, 283, 8708, 1726, 297, 272, 283, 7084, 7446, 297, 272, 327, 1227, 14, 1379, 17471, 272, 283, 29446, 297, 272, 283, 21091, 297, 272, 283, 1065, 63, 12485, 63, 8589, 297, 272, 327, 1520, 14, 377, 17338, 272, 283, 22403, 297, 272, 327, 1695, 14, 1910, 1770, 12502, 272, 283, 3768, 10591, 297, 272, 283, 3768, 1173, 6207, 297, 272, 283, 409, 63, 2796, 63, 3070, 2469, 297, 272, 327, 1749, 14, 14245, 1540, 12502, 272, 283, 1579, 63, 504, 63, 8589, 297, 272, 283, 396, 1365, 297, 272, 283, 1757, 63, 2164, 297, 272, 283, 1757, 297, 199, 61, 199, 199, 646, 636, 2443, 363, 199, 199, 646, 984, 12, 5190, 12, 6485, 12, 26026, 12, 747, 12, 295, 199, 646, 2882, 12, 27070, 12, 10543, 12, 5549, 199, 646, 3598, 199, 504, 5228, 492, 5228, 199, 504, 5055, 492, 12863, 199, 199, 774, 6579, 275, 12863, 360, 774, 6579, 297, 283, 4892, 22040, 358, 199, 199, 3, 6006, 787, 841, 5678, 3992, 26, 199, 3, 221, 446, 5679, 26, 282, 665, 1365, 12, 2934, 30, 4092, 12, 12254, 376, 1109, 345, 13, 12485, 1004, 1329, 14, 199, 3, 221, 446, 17495, 26, 282, 3245, 402, 7251, 12, 4565, 687, 282, 9214, 12, 12254, 199, 3, 259, 2256, 3595, 2382, 314, 9214, 20382, 687, 334, 354, 12, 1788, 12, 5874, 680, 199, 3, 221, 446, 17495, 11791, 26, 5536, 83, 5454, 2925, 687, 282, 1627, 909, 1159, 9214, 436, 199, 3, 259, 2399, 10470, 2251, 7, 20964, 14, 199, 3, 221, 446, 5454, 13649, 26, 7858, 17495, 5560, 12, 436, 11162, 15409, 11076, 14, 199, 3, 199, 3, 2002, 314, 5678, 24945, 365, 26, 199, 3, 199, 3, 17907, 769, 402, 26, 199, 3, 435, 28712, 7861, 435, 26533, 7861, 435, 375, 9018, 199, 3, 1204, 785, 92, 1553, 30311, 11791, 5118, 1204, 17495, 1204, 1553, 3768, 13649, 5118, 1204, 2604, 92, 199, 3, 435, 28712, 7861, 435, 26533, 7861, 435, 375, 9018, 199, 3, 14960, 1204, 5679, 1204, 199, 3, 14960, 1204, 257, 2263, 257, 1204, 199, 3, 14960, 1204, 5679, 1204, 199, 3, 14960, 435, 26533, 199, 199, 3, 3207, 5262, 14, 199, 199, 13352, 4831, 63, 8285, 63, 2339, 275, 1052, 199, 318, 2274, 63, 1422, 4173, 8, 354, 304, 272, 327, 2790, 282, 892, 3305, 7444, 658, 354, 64, 365, 2575, 6040, 14, 272, 372, 11662, 1075, 4831, 63, 8285, 63, 2339, 14, 5486, 8, 354, 12, 413, 5213, 822, 8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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 ]
shishaochen/TensorFlow-0.8-Win
tensorflow/python/summary/event_accumulator_test.py
6
26822
# Copyright 2015 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== from __future__ import absolute_import from __future__ import division from __future__ import print_function import os from six.moves import xrange # pylint: disable=redefined-builtin import tensorflow as tf from tensorflow.core.framework import graph_pb2 from tensorflow.core.util.event_pb2 import SessionLog from tensorflow.python.platform import gfile from tensorflow.python.platform import googletest from tensorflow.python.platform import tf_logging as logging from tensorflow.python.summary import event_accumulator as ea class _EventGenerator(object): def __init__(self): self.items = [] def Load(self): while self.items: yield self.items.pop(0) def AddScalar(self, tag, wall_time=0, step=0, value=0): event = tf.Event( wall_time=wall_time, step=step, summary=tf.Summary(value=[tf.Summary.Value(tag=tag, simple_value=value)])) self.AddEvent(event) def AddHistogram(self, tag, wall_time=0, step=0, hmin=1, hmax=2, hnum=3, hsum=4, hsum_squares=5, hbucket_limit=None, hbucket=None): histo = tf.HistogramProto(min=hmin, max=hmax, num=hnum, sum=hsum, sum_squares=hsum_squares, bucket_limit=hbucket_limit, bucket=hbucket) event = tf.Event(wall_time=wall_time, step=step, summary=tf.Summary(value=[tf.Summary.Value(tag=tag, histo=histo)])) self.AddEvent(event) def AddImage(self, tag, wall_time=0, step=0, encoded_image_string=b'imgstr', width=150, height=100): image = tf.Summary.Image(encoded_image_string=encoded_image_string, width=width, height=height) event = tf.Event(wall_time=wall_time, step=step, summary=tf.Summary(value=[tf.Summary.Value(tag=tag, image=image)])) self.AddEvent(event) def AddAudio(self, tag, wall_time=0, step=0, encoded_audio_string=b'sndstr', content_type='audio/wav', sample_rate=44100, length_frames=22050): audio = tf.Summary.Audio(encoded_audio_string=encoded_audio_string, content_type=content_type, sample_rate=sample_rate, length_frames=length_frames) event = tf.Event(wall_time=wall_time, step=step, summary=tf.Summary(value=[tf.Summary.Value(tag=tag, audio=audio)])) self.AddEvent(event) def AddEvent(self, event): self.items.append(event) class EventAccumulatorTest(tf.test.TestCase): def assertTagsEqual(self, tags1, tags2): # Make sure the two dictionaries have the same keys. self.assertItemsEqual(tags1, tags2) # Additionally, make sure each key in the dictionary maps to the same value. for key in tags1: if isinstance(tags1[key], list): # We don't care about the order of the values in lists, thus asserting # only if the items are equal. self.assertItemsEqual(tags1[key], tags2[key]) else: # Make sure the values are equal. self.assertEqual(tags1[key], tags2[key]) class MockingEventAccumulatorTest(EventAccumulatorTest): def setUp(self): super(MockingEventAccumulatorTest, self).setUp() self.stubs = googletest.StubOutForTesting() self.empty = {ea.IMAGES: [], ea.AUDIO: [], ea.SCALARS: [], ea.HISTOGRAMS: [], ea.COMPRESSED_HISTOGRAMS: [], ea.GRAPH: False, ea.RUN_METADATA: []} self._real_constructor = ea.EventAccumulator self._real_generator = ea._GeneratorFromPath def _FakeAccumulatorConstructor(generator, *args, **kwargs): ea._GeneratorFromPath = lambda x: generator return self._real_constructor(generator, *args, **kwargs) ea.EventAccumulator = _FakeAccumulatorConstructor def tearDown(self): self.stubs.CleanUp() ea.EventAccumulator = self._real_constructor ea._GeneratorFromPath = self._real_generator def testEmptyAccumulator(self): gen = _EventGenerator() x = ea.EventAccumulator(gen) x.Reload() self.assertEqual(x.Tags(), self.empty) def testTags(self): gen = _EventGenerator() gen.AddScalar('s1') gen.AddScalar('s2') gen.AddHistogram('hst1') gen.AddHistogram('hst2') gen.AddImage('im1') gen.AddImage('im2') gen.AddAudio('snd1') gen.AddAudio('snd2') acc = ea.EventAccumulator(gen) acc.Reload() self.assertTagsEqual(acc.Tags(), { ea.IMAGES: ['im1', 'im2'], ea.AUDIO: ['snd1', 'snd2'], ea.SCALARS: ['s1', 's2'], ea.HISTOGRAMS: ['hst1', 'hst2'], ea.COMPRESSED_HISTOGRAMS: ['hst1', 'hst2'], ea.GRAPH: False, ea.RUN_METADATA: [] }) def testReload(self): gen = _EventGenerator() acc = ea.EventAccumulator(gen) acc.Reload() self.assertEqual(acc.Tags(), self.empty) gen.AddScalar('s1') gen.AddScalar('s2') gen.AddHistogram('hst1') gen.AddHistogram('hst2') gen.AddImage('im1') gen.AddImage('im2') gen.AddAudio('snd1') gen.AddAudio('snd2') self.assertEqual(acc.Tags(), self.empty) acc.Reload() self.assertTagsEqual(acc.Tags(), { ea.IMAGES: ['im1', 'im2'], ea.AUDIO: ['snd1', 'snd2'], ea.SCALARS: ['s1', 's2'], ea.HISTOGRAMS: ['hst1', 'hst2'], ea.COMPRESSED_HISTOGRAMS: ['hst1', 'hst2'], ea.GRAPH: False, ea.RUN_METADATA: [] }) def testScalars(self): gen = _EventGenerator() acc = ea.EventAccumulator(gen) s1 = ea.ScalarEvent(wall_time=1, step=10, value=32) s2 = ea.ScalarEvent(wall_time=2, step=12, value=64) gen.AddScalar('s1', wall_time=1, step=10, value=32) gen.AddScalar('s2', wall_time=2, step=12, value=64) acc.Reload() self.assertEqual(acc.Scalars('s1'), [s1]) self.assertEqual(acc.Scalars('s2'), [s2]) def testHistograms(self): gen = _EventGenerator() acc = ea.EventAccumulator(gen) val1 = ea.HistogramValue(min=1, max=2, num=3, sum=4, sum_squares=5, bucket_limit=[1, 2, 3], bucket=[0, 3, 0]) val2 = ea.HistogramValue(min=-2, max=3, num=4, sum=5, sum_squares=6, bucket_limit=[2, 3, 4], bucket=[1, 3, 0]) hst1 = ea.HistogramEvent(wall_time=1, step=10, histogram_value=val1) hst2 = ea.HistogramEvent(wall_time=2, step=12, histogram_value=val2) gen.AddHistogram('hst1', wall_time=1, step=10, hmin=1, hmax=2, hnum=3, hsum=4, hsum_squares=5, hbucket_limit=[1, 2, 3], hbucket=[0, 3, 0]) gen.AddHistogram('hst2', wall_time=2, step=12, hmin=-2, hmax=3, hnum=4, hsum=5, hsum_squares=6, hbucket_limit=[2, 3, 4], hbucket=[1, 3, 0]) acc.Reload() self.assertEqual(acc.Histograms('hst1'), [hst1]) self.assertEqual(acc.Histograms('hst2'), [hst2]) def testCompressedHistograms(self): gen = _EventGenerator() acc = ea.EventAccumulator(gen, compression_bps=(0, 2500, 5000, 7500, 10000)) gen.AddHistogram('hst1', wall_time=1, step=10, hmin=1, hmax=2, hnum=3, hsum=4, hsum_squares=5, hbucket_limit=[1, 2, 3], hbucket=[0, 3, 0]) gen.AddHistogram('hst2', wall_time=2, step=12, hmin=-2, hmax=3, hnum=4, hsum=5, hsum_squares=6, hbucket_limit=[2, 3, 4], hbucket=[1, 3, 0]) acc.Reload() # Create the expected values after compressing hst1 expected_vals1 = [ea.CompressedHistogramValue(bp, val) for bp, val in [(0, 1.0), (2500, 1.25), (5000, 1.5), ( 7500, 1.75), (10000, 2.0)]] expected_cmphst1 = ea.CompressedHistogramEvent( wall_time=1, step=10, compressed_histogram_values=expected_vals1) self.assertEqual(acc.CompressedHistograms('hst1'), [expected_cmphst1]) # Create the expected values after compressing hst2 expected_vals2 = [ ea.CompressedHistogramValue(bp, val) for bp, val in [(0, -2), (2500, 2), (5000, 2 + 1 / 3), (7500, 2 + 2 / 3 ), (10000, 3)] ] expected_cmphst2 = ea.CompressedHistogramEvent( wall_time=2, step=12, compressed_histogram_values=expected_vals2) self.assertEqual(acc.CompressedHistograms('hst2'), [expected_cmphst2]) def testPercentile(self): def AssertExpectedForBps(bps, expected): output = acc._Percentile(bps, bucket_limit, cumsum_weights, histo_min, histo_max, histo_num) self.assertAlmostEqual(expected, output) gen = _EventGenerator() acc = ea.EventAccumulator(gen) bucket_limit = [1, 2, 3, 4] histo_num = 100 ## All weights in the first bucket cumsum_weights = [10000, 10000, 10000, 10000] histo_min = -1 histo_max = .9 AssertExpectedForBps(0, histo_min) AssertExpectedForBps(2500, ea._Remap(2500, 0, 10000, histo_min, histo_max)) AssertExpectedForBps(5000, ea._Remap(5000, 0, 10000, histo_min, histo_max)) AssertExpectedForBps(7500, ea._Remap(7500, 0, 10000, histo_min, histo_max)) AssertExpectedForBps(10000, histo_max) ## All weights in second bucket cumsum_weights = [0, 10000, 10000, 10000] histo_min = 1.1 histo_max = 1.8 AssertExpectedForBps(0, histo_min) AssertExpectedForBps(2500, ea._Remap(2500, 0, 10000, histo_min, histo_max)) AssertExpectedForBps(5000, ea._Remap(5000, 0, 10000, histo_min, histo_max)) AssertExpectedForBps(7500, ea._Remap(7500, 0, 10000, histo_min, histo_max)) AssertExpectedForBps(10000, histo_max) ## All weights in the last bucket cumsum_weights = [0, 0, 0, 10000] histo_min = 3.1 histo_max = 3.6 AssertExpectedForBps(0, histo_min) AssertExpectedForBps(2500, ea._Remap(2500, 0, 10000, histo_min, histo_max)) AssertExpectedForBps(5000, ea._Remap(5000, 0, 10000, histo_min, histo_max)) AssertExpectedForBps(7500, ea._Remap(7500, 0, 10000, histo_min, histo_max)) AssertExpectedForBps(10000, histo_max) ## Weights distributed between two buckets cumsum_weights = [0, 4000, 10000, 10000] histo_min = 1.1 histo_max = 2.9 AssertExpectedForBps(0, histo_min) AssertExpectedForBps(2500, ea._Remap(2500, 0, 4000, histo_min, bucket_limit[1])) AssertExpectedForBps(5000, ea._Remap(5000, 4000, 10000, bucket_limit[1], histo_max)) AssertExpectedForBps(7500, ea._Remap(7500, 4000, 10000, bucket_limit[1], histo_max)) AssertExpectedForBps(10000, histo_max) ## Weights distributed between all buckets cumsum_weights = [1000, 4000, 8000, 10000] histo_min = -1 histo_max = 3.9 AssertExpectedForBps(0, histo_min) AssertExpectedForBps(2500, ea._Remap(2500, 1000, 4000, bucket_limit[0], bucket_limit[1])) AssertExpectedForBps(5000, ea._Remap(5000, 4000, 8000, bucket_limit[1], bucket_limit[2])) AssertExpectedForBps(7500, ea._Remap(7500, 4000, 8000, bucket_limit[1], bucket_limit[2])) AssertExpectedForBps(9000, ea._Remap(9000, 8000, 10000, bucket_limit[2], histo_max)) AssertExpectedForBps(10000, histo_max) ## Most weight in first bucket cumsum_weights = [9000, 10000, 10000, 10000] histo_min = -1 histo_max = 1.1 AssertExpectedForBps(0, histo_min) AssertExpectedForBps(2500, ea._Remap(2500, 0, 9000, histo_min, bucket_limit[0])) AssertExpectedForBps(5000, ea._Remap(5000, 0, 9000, histo_min, bucket_limit[0])) AssertExpectedForBps(7500, ea._Remap(7500, 0, 9000, histo_min, bucket_limit[0])) AssertExpectedForBps(9500, ea._Remap(9500, 9000, 10000, bucket_limit[0], histo_max)) AssertExpectedForBps(10000, histo_max) def testImages(self): gen = _EventGenerator() acc = ea.EventAccumulator(gen) im1 = ea.ImageEvent(wall_time=1, step=10, encoded_image_string=b'big', width=400, height=300) im2 = ea.ImageEvent(wall_time=2, step=12, encoded_image_string=b'small', width=40, height=30) gen.AddImage('im1', wall_time=1, step=10, encoded_image_string=b'big', width=400, height=300) gen.AddImage('im2', wall_time=2, step=12, encoded_image_string=b'small', width=40, height=30) acc.Reload() self.assertEqual(acc.Images('im1'), [im1]) self.assertEqual(acc.Images('im2'), [im2]) def testAudio(self): gen = _EventGenerator() acc = ea.EventAccumulator(gen) snd1 = ea.AudioEvent(wall_time=1, step=10, encoded_audio_string=b'big', content_type='audio/wav', sample_rate=44100, length_frames=441000) snd2 = ea.AudioEvent(wall_time=2, step=12, encoded_audio_string=b'small', content_type='audio/wav', sample_rate=44100, length_frames=44100) gen.AddAudio('snd1', wall_time=1, step=10, encoded_audio_string=b'big', content_type='audio/wav', sample_rate=44100, length_frames=441000) gen.AddAudio('snd2', wall_time=2, step=12, encoded_audio_string=b'small', content_type='audio/wav', sample_rate=44100, length_frames=44100) acc.Reload() self.assertEqual(acc.Audio('snd1'), [snd1]) self.assertEqual(acc.Audio('snd2'), [snd2]) def testActivation(self): gen = _EventGenerator() acc = ea.EventAccumulator(gen) self.assertFalse(acc._activated) with self.assertRaises(RuntimeError): acc.Tags() with self.assertRaises(RuntimeError): acc.Scalars('s1') acc.Reload() self.assertTrue(acc._activated) acc._activated = False def testKeyError(self): gen = _EventGenerator() acc = ea.EventAccumulator(gen) acc.Reload() with self.assertRaises(KeyError): acc.Scalars('s1') with self.assertRaises(KeyError): acc.Scalars('hst1') with self.assertRaises(KeyError): acc.Scalars('im1') with self.assertRaises(KeyError): acc.Histograms('s1') with self.assertRaises(KeyError): acc.Histograms('im1') with self.assertRaises(KeyError): acc.Images('s1') with self.assertRaises(KeyError): acc.Images('hst1') with self.assertRaises(KeyError): acc.Audio('s1') with self.assertRaises(KeyError): acc.Audio('hst1') def testNonValueEvents(self): """Tests that non-value events in the generator don't cause early exits.""" gen = _EventGenerator() acc = ea.EventAccumulator(gen) gen.AddScalar('s1', wall_time=1, step=10, value=20) gen.AddEvent(tf.Event(wall_time=2, step=20, file_version='nots2')) gen.AddScalar('s3', wall_time=3, step=100, value=1) gen.AddHistogram('hst1') gen.AddImage('im1') gen.AddAudio('snd1') acc.Reload() self.assertTagsEqual(acc.Tags(), { ea.IMAGES: ['im1'], ea.AUDIO: ['snd1'], ea.SCALARS: ['s1', 's3'], ea.HISTOGRAMS: ['hst1'], ea.COMPRESSED_HISTOGRAMS: ['hst1'], ea.GRAPH: False, ea.RUN_METADATA: [] }) def testExpiredDataDiscardedAfterRestartForFileVersionLessThan2(self): """Tests that events are discarded after a restart is detected. If a step value is observed to be lower than what was previously seen, this should force a discard of all previous items with the same tag that are outdated. Only file versions < 2 use this out-of-order discard logic. Later versions discard events based on the step value of SessionLog.START. """ warnings = [] self.stubs.Set(logging, 'warn', warnings.append) gen = _EventGenerator() acc = ea.EventAccumulator(gen) gen.AddEvent(tf.Event(wall_time=0, step=0, file_version='brain.Event:1')) gen.AddScalar('s1', wall_time=1, step=100, value=20) gen.AddScalar('s1', wall_time=1, step=200, value=20) gen.AddScalar('s1', wall_time=1, step=300, value=20) acc.Reload() ## Check that number of items are what they should be self.assertEqual([x.step for x in acc.Scalars('s1')], [100, 200, 300]) gen.AddScalar('s1', wall_time=1, step=101, value=20) gen.AddScalar('s1', wall_time=1, step=201, value=20) gen.AddScalar('s1', wall_time=1, step=301, value=20) acc.Reload() ## Check that we have discarded 200 and 300 from s1 self.assertEqual([x.step for x in acc.Scalars('s1')], [100, 101, 201, 301]) def testOrphanedDataNotDiscardedIfFlagUnset(self): """Tests that events are not discarded if purge_orphaned_data is false. """ gen = _EventGenerator() acc = ea.EventAccumulator(gen, purge_orphaned_data=False) gen.AddEvent(tf.Event(wall_time=0, step=0, file_version='brain.Event:1')) gen.AddScalar('s1', wall_time=1, step=100, value=20) gen.AddScalar('s1', wall_time=1, step=200, value=20) gen.AddScalar('s1', wall_time=1, step=300, value=20) acc.Reload() ## Check that number of items are what they should be self.assertEqual([x.step for x in acc.Scalars('s1')], [100, 200, 300]) gen.AddScalar('s1', wall_time=1, step=101, value=20) gen.AddScalar('s1', wall_time=1, step=201, value=20) gen.AddScalar('s1', wall_time=1, step=301, value=20) acc.Reload() ## Check that we have discarded 200 and 300 from s1 self.assertEqual([x.step for x in acc.Scalars('s1')], [100, 200, 300, 101, 201, 301]) def testEventsDiscardedPerTagAfterRestartForFileVersionLessThan2(self): """Tests that event discards after restart, only affect the misordered tag. If a step value is observed to be lower than what was previously seen, this should force a discard of all previous items that are outdated, but only for the out of order tag. Other tags should remain unaffected. Only file versions < 2 use this out-of-order discard logic. Later versions discard events based on the step value of SessionLog.START. """ warnings = [] self.stubs.Set(logging, 'warn', warnings.append) gen = _EventGenerator() acc = ea.EventAccumulator(gen) gen.AddEvent(tf.Event(wall_time=0, step=0, file_version='brain.Event:1')) gen.AddScalar('s1', wall_time=1, step=100, value=20) gen.AddScalar('s1', wall_time=1, step=200, value=20) gen.AddScalar('s1', wall_time=1, step=300, value=20) gen.AddScalar('s1', wall_time=1, step=101, value=20) gen.AddScalar('s1', wall_time=1, step=201, value=20) gen.AddScalar('s1', wall_time=1, step=301, value=20) gen.AddScalar('s2', wall_time=1, step=101, value=20) gen.AddScalar('s2', wall_time=1, step=201, value=20) gen.AddScalar('s2', wall_time=1, step=301, value=20) acc.Reload() ## Check that we have discarded 200 and 300 self.assertEqual([x.step for x in acc.Scalars('s1')], [100, 101, 201, 301]) ## Check that s1 discards do not affect s2 ## i.e. check that only events from the out of order tag are discarded self.assertEqual([x.step for x in acc.Scalars('s2')], [101, 201, 301]) def testOnlySummaryEventsTriggerDiscards(self): """Test that file version event does not trigger data purge.""" gen = _EventGenerator() acc = ea.EventAccumulator(gen) gen.AddScalar('s1', wall_time=1, step=100, value=20) ev1 = tf.Event(wall_time=2, step=0, file_version='brain.Event:1') graph_bytes = graph_pb2.GraphDef().SerializeToString() ev2 = tf.Event(wall_time=3, step=0, graph_def=graph_bytes) gen.AddEvent(ev1) gen.AddEvent(ev2) acc.Reload() self.assertEqual([x.step for x in acc.Scalars('s1')], [100]) def testSessionLogStartMessageDiscardsExpiredEvents(self): """Test that SessionLog.START message discards expired events. This discard logic is preferred over the out-of-order step discard logic, but this logic can only be used for event protos which have the SessionLog enum, which was introduced to event.proto for file_version >= brain.Event:2. """ gen = _EventGenerator() acc = ea.EventAccumulator(gen) gen.AddEvent(tf.Event(wall_time=0, step=1, file_version='brain.Event:2')) gen.AddScalar('s1', wall_time=1, step=100, value=20) gen.AddScalar('s1', wall_time=1, step=200, value=20) gen.AddScalar('s1', wall_time=1, step=300, value=20) gen.AddScalar('s1', wall_time=1, step=400, value=20) gen.AddScalar('s2', wall_time=1, step=202, value=20) gen.AddScalar('s2', wall_time=1, step=203, value=20) slog = SessionLog(status=SessionLog.START) gen.AddEvent(tf.Event(wall_time=2, step=201, session_log=slog)) acc.Reload() self.assertEqual([x.step for x in acc.Scalars('s1')], [100, 200]) self.assertEqual([x.step for x in acc.Scalars('s2')], []) class RealisticEventAccumulatorTest(EventAccumulatorTest): def setUp(self): super(RealisticEventAccumulatorTest, self).setUp() def testScalarsRealistically(self): """Test accumulator by writing values and then reading them.""" def FakeScalarSummary(tag, value): value = tf.Summary.Value(tag=tag, simple_value=value) summary = tf.Summary(value=[value]) return summary directory = os.path.join(self.get_temp_dir(), 'values_dir') if gfile.IsDirectory(directory): gfile.DeleteRecursively(directory) gfile.MkDir(directory) writer = tf.train.SummaryWriter(directory, max_queue=100) with tf.Graph().as_default() as graph: _ = tf.constant([2.0, 1.0]) # Add a graph to the summary writer. writer.add_graph(graph) run_metadata = tf.RunMetadata() device_stats = run_metadata.step_stats.dev_stats.add() device_stats.device = 'test device' writer.add_run_metadata(run_metadata, 'test run') # Write a bunch of events using the writer for i in xrange(30): summ_id = FakeScalarSummary('id', i) summ_sq = FakeScalarSummary('sq', i * i) writer.add_summary(summ_id, i * 5) writer.add_summary(summ_sq, i * 5) writer.flush() # Verify that we can load those events properly acc = ea.EventAccumulator(directory) acc.Reload() self.assertTagsEqual(acc.Tags(), { ea.IMAGES: [], ea.AUDIO: [], ea.SCALARS: ['id', 'sq'], ea.HISTOGRAMS: [], ea.COMPRESSED_HISTOGRAMS: [], ea.GRAPH: True, ea.RUN_METADATA: ['test run'] }) id_events = acc.Scalars('id') sq_events = acc.Scalars('sq') self.assertEqual(30, len(id_events)) self.assertEqual(30, len(sq_events)) for i in xrange(30): self.assertEqual(i * 5, id_events[i].step) self.assertEqual(i * 5, sq_events[i].step) self.assertEqual(i, id_events[i].value) self.assertEqual(i * i, sq_events[i].value) # Write a few more events to test incremental reloading for i in xrange(30, 40): summ_id = FakeScalarSummary('id', i) summ_sq = FakeScalarSummary('sq', i * i) writer.add_summary(summ_id, i * 5) writer.add_summary(summ_sq, i * 5) writer.flush() # Verify we can now see all of the data acc.Reload() self.assertEqual(40, len(id_events)) self.assertEqual(40, len(sq_events)) for i in xrange(40): self.assertEqual(i * 5, id_events[i].step) self.assertEqual(i * 5, sq_events[i].step) self.assertEqual(i, id_events[i].value) self.assertEqual(i * i, sq_events[i].value) self.assertProtoEquals(graph.as_graph_def(add_shapes=True), acc.Graph()) if __name__ == '__main__': tf.test.main()
apache-2.0
[ 3, 1898, 6900, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 199, 199, 504, 3816, 14, 4912, 492, 4945, 221, 327, 4287, 26, 3507, 29, 27913, 13, 5351, 199, 646, 3228, 465, 2833, 199, 199, 504, 3228, 14, 1018, 14, 4857, 492, 3343, 63, 3317, 18, 199, 504, 3228, 14, 1018, 14, 1974, 14, 1430, 63, 3317, 18, 492, 8596, 2445, 199, 504, 3228, 14, 1548, 14, 3246, 492, 26532, 199, 504, 3228, 14, 1548, 14, 3246, 492, 31141, 199, 504, 3228, 14, 1548, 14, 3246, 492, 2833, 63, 4806, 465, 2050, 199, 504, 3228, 14, 1548, 14, 4705, 492, 1566, 63, 21417, 465, 24867, 421, 199, 533, 485, 2390, 7599, 8, 785, 304, 819, 347, 636, 826, 721, 277, 304, 272, 291, 14, 1744, 275, 942, 819, 347, 7190, 8, 277, 304, 272, 1830, 291, 14, 1744, 26, 489, 1995, 291, 14, 1744, 14, 1935, 8, 16, 9, 819, 347, 2654, 13090, 8, 277, 12, 1947, 12, 19882, 63, 521, 29, 16, 12, 3650, 29, 16, 12, 574, 29, 16, 304, 272, 1566, 275, 2833, 14, 2390, 8, 267, 19882, 63, 521, 29, 7567, 63, 521, 12, 267, 3650, 29, 2926, 12, 267, 6212, 29, 3249, 14, 10407, 8, 585, 1524, 3249, 14, 10407, 14, 1110, 8, 1450, 29, 1450, 12, 8962, 3486, 63, 585, 29, 585, 19563, 272, 291, 14, 1123, 2390, 8, 1430, 9, 819, 347, 2654, 25055, 8, 277, 12, 673, 1947, 12, 673, 19882, 63, 521, 29, 16, 12, 673, 3650, 29, 16, 12, 673, 394, 827, 29, 17, 12, 673, 394, 988, 29, 18, 12, 673, 394, 1507, 29, 19, 12, 673, 394, 1838, 29, 20, 12, 673, 394, 1838, 63, 20956, 29, 21, 12, 673, 394, 4623, 63, 3097, 29, 403, 12, 673, 394, 4623, 29, 403, 304, 272, 394, 7133, 275, 2833, 14, 25055, 8548, 8, 827, 29, 72, 827, 12, 2892, 1390, 29, 72, 988, 12, 2892, 1967, 29, 72, 1507, 12, 2892, 3089, 29, 72, 1838, 12, 2892, 3089, 63, 20956, 29, 72, 1838, 63, 20956, 12, 2892, 5315, 63, 3097, 29, 72, 4623, 63, 3097, 12, 2892, 5315, 29, 72, 4623, 9, 272, 1566, 275, 2833, 14, 2390, 8, 7567, 63, 521, 29, 7567, 63, 521, 12, 2151, 3650, 29, 2926, 12, 2151, 6212, 29, 3249, 14, 10407, 8, 585, 1524, 3249, 14, 10407, 14, 1110, 8, 1450, 29, 1450, 12, 17743, 394, 7133, 29, 72, 7133, 19563, 272, 291, 14, 1123, 2390, 8, 1430, 9, 819, 347, 2654, 3491, 8, 277, 12, 2049, 1947, 12, 2049, 19882, 63, 521, 29, 16, 12, 2049, 3650, 29, 16, 12, 2049, 5737, 63, 1569, 63, 875, 29, 66, 7, 4060, 495, 297, 2049, 3462, 29, 8251, 12, 2049, 4569, 29, 1960, 304, 272, 1834, 275, 2833, 14, 10407, 14, 3491, 8, 8167, 63, 1569, 63, 875, 29, 8167, 63, 1569, 63, 875, 12, 2490, 3462, 29, 2063, 12, 2490, 4569, 29, 3333, 9, 272, 1566, 275, 2833, 14, 2390, 8, 7567, 63, 521, 29, 7567, 63, 521, 12, 2151, 3650, 29, 2926, 12, 2151, 6212, 29, 3249, 14, 10407, 8, 585, 1524, 3249, 14, 10407, 14, 1110, 8, 1450, 29, 1450, 12, 17743, 1834, 29, 1569, 19563, 272, 291, 14, 1123, 2390, 8, 1430, 9, 819, 347, 2654, 15484, 8, 277, 12, 2049, 1947, 12, 2049, 19882, 63, 521, 29, 16, 12, 2049, 3650, 29, 16, 12, 2049, 5737, 63, 8130, 63, 875, 29, 66, 1159, 977, 495, 297, 2049, 1564, 63, 466, 534, 8130, 15, 19118, 297, 2049, 2690, 63, 1866, 29, 1602, 1960, 12, 2049, 2582, 63, 8444, 29, 11174, 1400, 304, 272, 10491, 275, 2833, 14, 10407, 14, 15484, 8, 8167, 63, 8130, 63, 875, 29, 8167, 63, 8130, 63, 875, 12, 2490, 1564, 63, 466, 29, 1317, 63, 466, 12, 2490, 2690, 63, 1866, 29, 3271, 63, 1866, 12, 2490, 2582, 63, 8444, 29, 1267, 63, 8444, 9, 272, 1566, 275, 2833, 14, 2390, 8, 7567, 63, 521, 29, 7567, 63, 521, 12, 2151, 3650, 29, 2926, 12, 2151, 6212, 29, 3249, 14, 10407, 8, 585, 1524, 3249, 14, 10407, 14, 1110, 8, 1450, 29, 1450, 12, 17743, 10491, 29, 8130, 19563, 272, 291, 14, 1123, 2390, 8, 1430, 9, 819, 347, 2654, 2390, 8, 277, 12, 1566, 304, 272, 291, 14, 1744, 14, 740, 8, 1430, 9, 421, 199, 533, 6763, 23384, 6109, 774, 8, 3249, 14, 396, 14, 1746, 304, 819, 347, 702, 9440, 591, 8, 277, 12, 3762, 17, 12, 3762, 18, 304, 272, 327, 4155, 3238, 314, 2877, 11196, 1172, 314, 2011, 2883, 14, 272, 291, 14, 19673, 8, 2969, 17, 12, 3762, 18, 9, 272, 327, 25448, 12, 1852, 3238, 1924, 790, 315, 314, 2600, 9033, 370, 314, 2011, 574, 14, 272, 367, 790, 315, 3762, 17, 26, 489, 340, 1228, 8, 2969, 17, 59, 498, 467, 769, 304, 267, 327, 2136, 2793, 1133, 10296, 3595, 314, 1865, 402, 314, 1338, 315, 5548, 12, 12850, 702, 316, 267, 327, 1454, 340, 314, 2974, 787, 4472, 14, 267, 291, 14, 19673, 8, 2969, 17, 59, 498, 467, 3762, 18, 59, 498, 566, 489, 587, 26, 267, 327, 4155, 3238, 314, 1338, 787, 4472, 14, 267, 291, 14, 629, 8, 2969, 17, 59, 498, 467 ]
[ 1898, 6900, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 199, 199, 504, 3816, 14, 4912, 492, 4945, 221, 327, 4287, 26, 3507, 29, 27913, 13, 5351, 199, 646, 3228, 465, 2833, 199, 199, 504, 3228, 14, 1018, 14, 4857, 492, 3343, 63, 3317, 18, 199, 504, 3228, 14, 1018, 14, 1974, 14, 1430, 63, 3317, 18, 492, 8596, 2445, 199, 504, 3228, 14, 1548, 14, 3246, 492, 26532, 199, 504, 3228, 14, 1548, 14, 3246, 492, 31141, 199, 504, 3228, 14, 1548, 14, 3246, 492, 2833, 63, 4806, 465, 2050, 199, 504, 3228, 14, 1548, 14, 4705, 492, 1566, 63, 21417, 465, 24867, 421, 199, 533, 485, 2390, 7599, 8, 785, 304, 819, 347, 636, 826, 721, 277, 304, 272, 291, 14, 1744, 275, 942, 819, 347, 7190, 8, 277, 304, 272, 1830, 291, 14, 1744, 26, 489, 1995, 291, 14, 1744, 14, 1935, 8, 16, 9, 819, 347, 2654, 13090, 8, 277, 12, 1947, 12, 19882, 63, 521, 29, 16, 12, 3650, 29, 16, 12, 574, 29, 16, 304, 272, 1566, 275, 2833, 14, 2390, 8, 267, 19882, 63, 521, 29, 7567, 63, 521, 12, 267, 3650, 29, 2926, 12, 267, 6212, 29, 3249, 14, 10407, 8, 585, 1524, 3249, 14, 10407, 14, 1110, 8, 1450, 29, 1450, 12, 8962, 3486, 63, 585, 29, 585, 19563, 272, 291, 14, 1123, 2390, 8, 1430, 9, 819, 347, 2654, 25055, 8, 277, 12, 673, 1947, 12, 673, 19882, 63, 521, 29, 16, 12, 673, 3650, 29, 16, 12, 673, 394, 827, 29, 17, 12, 673, 394, 988, 29, 18, 12, 673, 394, 1507, 29, 19, 12, 673, 394, 1838, 29, 20, 12, 673, 394, 1838, 63, 20956, 29, 21, 12, 673, 394, 4623, 63, 3097, 29, 403, 12, 673, 394, 4623, 29, 403, 304, 272, 394, 7133, 275, 2833, 14, 25055, 8548, 8, 827, 29, 72, 827, 12, 2892, 1390, 29, 72, 988, 12, 2892, 1967, 29, 72, 1507, 12, 2892, 3089, 29, 72, 1838, 12, 2892, 3089, 63, 20956, 29, 72, 1838, 63, 20956, 12, 2892, 5315, 63, 3097, 29, 72, 4623, 63, 3097, 12, 2892, 5315, 29, 72, 4623, 9, 272, 1566, 275, 2833, 14, 2390, 8, 7567, 63, 521, 29, 7567, 63, 521, 12, 2151, 3650, 29, 2926, 12, 2151, 6212, 29, 3249, 14, 10407, 8, 585, 1524, 3249, 14, 10407, 14, 1110, 8, 1450, 29, 1450, 12, 17743, 394, 7133, 29, 72, 7133, 19563, 272, 291, 14, 1123, 2390, 8, 1430, 9, 819, 347, 2654, 3491, 8, 277, 12, 2049, 1947, 12, 2049, 19882, 63, 521, 29, 16, 12, 2049, 3650, 29, 16, 12, 2049, 5737, 63, 1569, 63, 875, 29, 66, 7, 4060, 495, 297, 2049, 3462, 29, 8251, 12, 2049, 4569, 29, 1960, 304, 272, 1834, 275, 2833, 14, 10407, 14, 3491, 8, 8167, 63, 1569, 63, 875, 29, 8167, 63, 1569, 63, 875, 12, 2490, 3462, 29, 2063, 12, 2490, 4569, 29, 3333, 9, 272, 1566, 275, 2833, 14, 2390, 8, 7567, 63, 521, 29, 7567, 63, 521, 12, 2151, 3650, 29, 2926, 12, 2151, 6212, 29, 3249, 14, 10407, 8, 585, 1524, 3249, 14, 10407, 14, 1110, 8, 1450, 29, 1450, 12, 17743, 1834, 29, 1569, 19563, 272, 291, 14, 1123, 2390, 8, 1430, 9, 819, 347, 2654, 15484, 8, 277, 12, 2049, 1947, 12, 2049, 19882, 63, 521, 29, 16, 12, 2049, 3650, 29, 16, 12, 2049, 5737, 63, 8130, 63, 875, 29, 66, 1159, 977, 495, 297, 2049, 1564, 63, 466, 534, 8130, 15, 19118, 297, 2049, 2690, 63, 1866, 29, 1602, 1960, 12, 2049, 2582, 63, 8444, 29, 11174, 1400, 304, 272, 10491, 275, 2833, 14, 10407, 14, 15484, 8, 8167, 63, 8130, 63, 875, 29, 8167, 63, 8130, 63, 875, 12, 2490, 1564, 63, 466, 29, 1317, 63, 466, 12, 2490, 2690, 63, 1866, 29, 3271, 63, 1866, 12, 2490, 2582, 63, 8444, 29, 1267, 63, 8444, 9, 272, 1566, 275, 2833, 14, 2390, 8, 7567, 63, 521, 29, 7567, 63, 521, 12, 2151, 3650, 29, 2926, 12, 2151, 6212, 29, 3249, 14, 10407, 8, 585, 1524, 3249, 14, 10407, 14, 1110, 8, 1450, 29, 1450, 12, 17743, 10491, 29, 8130, 19563, 272, 291, 14, 1123, 2390, 8, 1430, 9, 819, 347, 2654, 2390, 8, 277, 12, 1566, 304, 272, 291, 14, 1744, 14, 740, 8, 1430, 9, 421, 199, 533, 6763, 23384, 6109, 774, 8, 3249, 14, 396, 14, 1746, 304, 819, 347, 702, 9440, 591, 8, 277, 12, 3762, 17, 12, 3762, 18, 304, 272, 327, 4155, 3238, 314, 2877, 11196, 1172, 314, 2011, 2883, 14, 272, 291, 14, 19673, 8, 2969, 17, 12, 3762, 18, 9, 272, 327, 25448, 12, 1852, 3238, 1924, 790, 315, 314, 2600, 9033, 370, 314, 2011, 574, 14, 272, 367, 790, 315, 3762, 17, 26, 489, 340, 1228, 8, 2969, 17, 59, 498, 467, 769, 304, 267, 327, 2136, 2793, 1133, 10296, 3595, 314, 1865, 402, 314, 1338, 315, 5548, 12, 12850, 702, 316, 267, 327, 1454, 340, 314, 2974, 787, 4472, 14, 267, 291, 14, 19673, 8, 2969, 17, 59, 498, 467, 3762, 18, 59, 498, 566, 489, 587, 26, 267, 327, 4155, 3238, 314, 1338, 787, 4472, 14, 267, 291, 14, 629, 8, 2969, 17, 59, 498, 467, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
zrhans/pythonanywhere
.virtualenvs/django19/lib/python3.4/site-packages/pip/commands/list.py
269
7251
from __future__ import absolute_import import logging from pip._vendor import pkg_resources from pip.basecommand import Command from pip.exceptions import DistributionNotFound from pip.index import FormatControl, fmt_ctl_formats, PackageFinder, Search from pip.req import InstallRequirement from pip.utils import get_installed_distributions, dist_is_editable from pip.wheel import WheelCache from pip.cmdoptions import make_option_group, index_group logger = logging.getLogger(__name__) class ListCommand(Command): """ List installed packages, including editables. Packages are listed in a case-insensitive sorted order. """ name = 'list' usage = """ %prog [options]""" summary = 'List installed packages.' def __init__(self, *args, **kw): super(ListCommand, self).__init__(*args, **kw) cmd_opts = self.cmd_opts cmd_opts.add_option( '-o', '--outdated', action='store_true', default=False, help='List outdated packages (excluding editables)') cmd_opts.add_option( '-u', '--uptodate', action='store_true', default=False, help='List uptodate packages (excluding editables)') cmd_opts.add_option( '-e', '--editable', action='store_true', default=False, help='List editable projects.') cmd_opts.add_option( '-l', '--local', action='store_true', default=False, help=('If in a virtualenv that has global access, do not list ' 'globally-installed packages.'), ) self.cmd_opts.add_option( '--user', dest='user', action='store_true', default=False, help='Only output packages installed in user-site.') cmd_opts.add_option( '--pre', action='store_true', default=False, help=("Include pre-release and development versions. By default, " "pip only finds stable versions."), ) index_opts = make_option_group(index_group, self.parser) self.parser.insert_option_group(0, index_opts) self.parser.insert_option_group(0, cmd_opts) def _build_package_finder(self, options, index_urls, session): """ Create a package finder appropriate to this list command. """ return PackageFinder( find_links=options.find_links, index_urls=index_urls, allow_external=options.allow_external, allow_unverified=options.allow_unverified, allow_all_external=options.allow_all_external, allow_all_prereleases=options.pre, trusted_hosts=options.trusted_hosts, process_dependency_links=options.process_dependency_links, session=session, ) def run(self, options, args): if options.outdated: self.run_outdated(options) elif options.uptodate: self.run_uptodate(options) elif options.editable: self.run_editables(options) else: self.run_listing(options) def run_outdated(self, options): for dist, version, typ in self.find_packages_latest_versions(options): if version > dist.parsed_version: logger.info( '%s (Current: %s Latest: %s [%s])', dist.project_name, dist.version, version, typ, ) def find_packages_latest_versions(self, options): index_urls = [options.index_url] + options.extra_index_urls if options.no_index: logger.info('Ignoring indexes: %s', ','.join(index_urls)) index_urls = [] dependency_links = [] for dist in get_installed_distributions(local_only=options.local, user_only=options.user): if dist.has_metadata('dependency_links.txt'): dependency_links.extend( dist.get_metadata_lines('dependency_links.txt'), ) with self._build_session(options) as session: finder = self._build_package_finder(options, index_urls, session) finder.add_dependency_links(dependency_links) installed_packages = get_installed_distributions( local_only=options.local, user_only=options.user, include_editables=False, ) format_control = FormatControl(set(), set()) wheel_cache = WheelCache(options.cache_dir, format_control) for dist in installed_packages: req = InstallRequirement.from_line( dist.key, None, isolated=options.isolated_mode, wheel_cache=wheel_cache ) typ = 'unknown' try: link = finder.find_requirement(req, True) # If link is None, means installed version is most # up-to-date if link is None: continue except DistributionNotFound: continue else: canonical_name = pkg_resources.safe_name(req.name).lower() formats = fmt_ctl_formats(format_control, canonical_name) search = Search( req.name, canonical_name, formats) remote_version = finder._link_package_versions( link, search).version if link.is_wheel: typ = 'wheel' else: typ = 'sdist' yield dist, remote_version, typ def run_listing(self, options): installed_packages = get_installed_distributions( local_only=options.local, user_only=options.user, ) self.output_package_listing(installed_packages) def run_editables(self, options): installed_packages = get_installed_distributions( local_only=options.local, user_only=options.user, editables_only=True, ) self.output_package_listing(installed_packages) def output_package_listing(self, installed_packages): installed_packages = sorted( installed_packages, key=lambda dist: dist.project_name.lower(), ) for dist in installed_packages: if dist_is_editable(dist): line = '%s (%s, %s)' % ( dist.project_name, dist.version, dist.location, ) else: line = '%s (%s)' % (dist.project_name, dist.version) logger.info(line) def run_uptodate(self, options): uptodate = [] for dist, version, typ in self.find_packages_latest_versions(options): if dist.parsed_version == version: uptodate.append(dist) self.output_package_listing(uptodate)
apache-2.0
[ 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 2050, 199, 199, 504, 7305, 423, 9884, 492, 5496, 63, 4435, 199, 199, 504, 7305, 14, 1095, 1531, 492, 5817, 199, 504, 7305, 14, 3924, 492, 11839, 4667, 199, 504, 7305, 14, 1080, 492, 9701, 3717, 12, 7104, 63, 8077, 63, 6321, 12, 15665, 11791, 12, 8730, 199, 504, 7305, 14, 2103, 492, 13276, 17947, 199, 504, 7305, 14, 1208, 492, 664, 63, 7657, 63, 5613, 12, 2917, 63, 374, 63, 10820, 199, 504, 7305, 14, 11798, 492, 26161, 4437, 199, 504, 7305, 14, 1760, 1419, 492, 1852, 63, 1422, 63, 923, 12, 1478, 63, 923, 421, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 3820, 3110, 8, 3110, 304, 272, 408, 272, 3820, 4903, 6117, 12, 5893, 7860, 5987, 14, 339, 9954, 7441, 787, 10532, 315, 282, 1930, 13, 15851, 3355, 1865, 14, 272, 408, 272, 536, 275, 283, 513, 7, 272, 4503, 275, 408, 489, 450, 6595, 359, 1419, 61, 624, 272, 6212, 275, 283, 1296, 4903, 6117, 3530, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 829, 304, 267, 1613, 8, 1296, 3110, 12, 291, 2843, 826, 9308, 589, 12, 1011, 829, 9, 398, 2088, 63, 3291, 275, 291, 14, 1760, 63, 3291, 398, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 79, 297, 2850, 548, 19074, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 534, 1296, 734, 19074, 6117, 334, 476, 4923, 7860, 5987, 5942, 267, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 85, 297, 2850, 384, 5766, 323, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 534, 1296, 1536, 5766, 323, 6117, 334, 476, 4923, 7860, 5987, 5942, 267, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 69, 297, 2850, 10820, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 534, 1296, 14783, 11336, 2659, 267, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 76, 297, 2850, 1832, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 7782, 3917, 315, 282, 19128, 626, 965, 2288, 2879, 12, 886, 440, 769, 283, 2116, 283, 6463, 1183, 13, 7657, 6117, 8038, 267, 776, 267, 291, 14, 1760, 63, 3291, 14, 525, 63, 1422, 8, 288, 2850, 751, 297, 288, 2053, 534, 751, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 534, 5903, 1072, 6117, 4903, 315, 922, 13, 2124, 2659, 398, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2850, 657, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 15387, 7826, 876, 13, 3221, 436, 16367, 5459, 14, 4885, 849, 12, 298, 2116, 298, 9983, 1454, 17651, 17830, 5459, 7651, 267, 776, 398, 1478, 63, 3291, 275, 1852, 63, 1422, 63, 923, 8, 1080, 63, 923, 12, 291, 14, 2087, 9, 398, 291, 14, 2087, 14, 3176, 63, 1422, 63, 923, 8, 16, 12, 1478, 63, 3291, 9, 267, 291, 14, 2087, 14, 3176, 63, 1422, 63, 923, 8, 16, 12, 2088, 63, 3291, 9, 339, 347, 485, 1506, 63, 2491, 63, 11681, 8, 277, 12, 1511, 12, 1478, 63, 3603, 12, 2351, 304, 267, 408, 267, 2790, 282, 2559, 11569, 5827, 370, 642, 769, 1414, 14, 267, 408, 267, 372, 15665, 11791, 8, 288, 2342, 63, 4614, 29, 1419, 14, 1623, 63, 4614, 12, 288, 1478, 63, 3603, 29, 1080, 63, 3603, 12, 288, 2040, 63, 5159, 29, 1419, 14, 3306, 63, 5159, 12, 288, 2040, 63, 324, 12949, 29, 1419, 14, 3306, 63, 324, 12949, 12, 288, 2040, 63, 452, 63, 5159, 29, 1419, 14, 3306, 63, 452, 63, 5159, 12, 288, 2040, 63, 452, 63, 25648, 29, 1419, 14, 657, 12, 288, 19427, 63, 5146, 29, 1419, 14, 17549, 63, 5146, 12, 288, 2112, 63, 8575, 63, 4614, 29, 1419, 14, 1412, 63, 8575, 63, 4614, 12, 288, 2351, 29, 1730, 12, 267, 776, 339, 347, 1255, 8, 277, 12, 1511, 12, 1249, 304, 267, 340, 1511, 14, 548, 19074, 26, 288, 291, 14, 1065, 63, 548, 19074, 8, 1419, 9, 267, 916, 1511, 14, 384, 5766, 323, 26, 288, 291, 14, 1065, 63, 384, 5766, 323, 8, 1419, 9, 267, 916, 1511, 14, 10820, 26, 288, 291, 14, 1065, 63, 6297, 5987, 8, 1419, 9, 267, 587, 26, 288, 291, 14, 1065, 63, 16115, 8, 1419, 9, 339, 347, 1255, 63, 548, 19074, 8, 277, 12, 1511, 304, 267, 367, 2917, 12, 1015, 12, 6211, 315, 291, 14, 1623, 63, 5154, 63, 7410, 63, 6234, 8, 1419, 304, 288, 340, 1015, 690, 2917, 14, 6751, 63, 1023, 26, 355, 2512, 14, 815, 8, 490, 1543, 83, 334, 5639, 26, 450, 83, 491, 27126, 26, 450, 83, 8978, 83, 22206, 490, 2917, 14, 1715, 63, 354, 12, 2917, 14, 1023, 12, 1015, 12, 6211, 12, 355, 776, 339, 347, 2342, 63, 5154, 63, 7410, 63, 6234, 8, 277, 12, 1511, 304, 267, 1478, 63, 3603, 275, 359, 1419, 14, 1080, 63, 633, 61, 435, 1511, 14, 2911, 63, 1080, 63, 3603, 267, 340, 1511, 14, 889, 63, 1080, 26, 288, 2512, 14, 815, 360, 32390, 10507, 26, 450, 83, 297, 12814, 904, 8, 1080, 63, 3603, 430, 288, 1478, 63, 3603, 275, 942, 398, 5936, 63, 4614, 275, 942, 267, 367, 2917, 315, 664, 63, 7657, 63, 5613, 8, 1832, 63, 2118, 29, 1419, 14, 1832, 12, 6059, 922, 63, 2118, 29, 1419, 14, 751, 304, 288, 340, 2917, 14, 1989, 63, 2343, 360, 8575, 63, 4614, 14, 2424, 735, 355, 5936, 63, 4614, 14, 2880, 8, 490, 2917, 14, 362, 63, 2343, 63, 1278, 360, 8575, 63, 4614, 14, 2424, 659, 355, 776, 398, 543, 291, 423, 1506, 63, 1730, 8, 1419, 9, 465, 2351, 26, 288, 11569, 275, 291, 423, 1506, 63, 2491, 63, 11681, 8, 1419, 12, 1478, 63, 3603, 12, 2351, 9, 288, 11569, 14, 525, 63, 8575, 63, 4614, 8, 8575, 63, 4614, 9, 953, 4903, 63, 5154, 275, 664, 63, 7657, 63, 5613, 8 ]
[ 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 2050, 199, 199, 504, 7305, 423, 9884, 492, 5496, 63, 4435, 199, 199, 504, 7305, 14, 1095, 1531, 492, 5817, 199, 504, 7305, 14, 3924, 492, 11839, 4667, 199, 504, 7305, 14, 1080, 492, 9701, 3717, 12, 7104, 63, 8077, 63, 6321, 12, 15665, 11791, 12, 8730, 199, 504, 7305, 14, 2103, 492, 13276, 17947, 199, 504, 7305, 14, 1208, 492, 664, 63, 7657, 63, 5613, 12, 2917, 63, 374, 63, 10820, 199, 504, 7305, 14, 11798, 492, 26161, 4437, 199, 504, 7305, 14, 1760, 1419, 492, 1852, 63, 1422, 63, 923, 12, 1478, 63, 923, 421, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 3820, 3110, 8, 3110, 304, 272, 408, 272, 3820, 4903, 6117, 12, 5893, 7860, 5987, 14, 339, 9954, 7441, 787, 10532, 315, 282, 1930, 13, 15851, 3355, 1865, 14, 272, 408, 272, 536, 275, 283, 513, 7, 272, 4503, 275, 408, 489, 450, 6595, 359, 1419, 61, 624, 272, 6212, 275, 283, 1296, 4903, 6117, 3530, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 829, 304, 267, 1613, 8, 1296, 3110, 12, 291, 2843, 826, 9308, 589, 12, 1011, 829, 9, 398, 2088, 63, 3291, 275, 291, 14, 1760, 63, 3291, 398, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 79, 297, 2850, 548, 19074, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 534, 1296, 734, 19074, 6117, 334, 476, 4923, 7860, 5987, 5942, 267, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 85, 297, 2850, 384, 5766, 323, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 534, 1296, 1536, 5766, 323, 6117, 334, 476, 4923, 7860, 5987, 5942, 267, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 69, 297, 2850, 10820, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 534, 1296, 14783, 11336, 2659, 267, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2475, 76, 297, 2850, 1832, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 7782, 3917, 315, 282, 19128, 626, 965, 2288, 2879, 12, 886, 440, 769, 283, 2116, 283, 6463, 1183, 13, 7657, 6117, 8038, 267, 776, 267, 291, 14, 1760, 63, 3291, 14, 525, 63, 1422, 8, 288, 2850, 751, 297, 288, 2053, 534, 751, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 534, 5903, 1072, 6117, 4903, 315, 922, 13, 2124, 2659, 398, 2088, 63, 3291, 14, 525, 63, 1422, 8, 288, 2850, 657, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 849, 29, 797, 12, 288, 1720, 15387, 7826, 876, 13, 3221, 436, 16367, 5459, 14, 4885, 849, 12, 298, 2116, 298, 9983, 1454, 17651, 17830, 5459, 7651, 267, 776, 398, 1478, 63, 3291, 275, 1852, 63, 1422, 63, 923, 8, 1080, 63, 923, 12, 291, 14, 2087, 9, 398, 291, 14, 2087, 14, 3176, 63, 1422, 63, 923, 8, 16, 12, 1478, 63, 3291, 9, 267, 291, 14, 2087, 14, 3176, 63, 1422, 63, 923, 8, 16, 12, 2088, 63, 3291, 9, 339, 347, 485, 1506, 63, 2491, 63, 11681, 8, 277, 12, 1511, 12, 1478, 63, 3603, 12, 2351, 304, 267, 408, 267, 2790, 282, 2559, 11569, 5827, 370, 642, 769, 1414, 14, 267, 408, 267, 372, 15665, 11791, 8, 288, 2342, 63, 4614, 29, 1419, 14, 1623, 63, 4614, 12, 288, 1478, 63, 3603, 29, 1080, 63, 3603, 12, 288, 2040, 63, 5159, 29, 1419, 14, 3306, 63, 5159, 12, 288, 2040, 63, 324, 12949, 29, 1419, 14, 3306, 63, 324, 12949, 12, 288, 2040, 63, 452, 63, 5159, 29, 1419, 14, 3306, 63, 452, 63, 5159, 12, 288, 2040, 63, 452, 63, 25648, 29, 1419, 14, 657, 12, 288, 19427, 63, 5146, 29, 1419, 14, 17549, 63, 5146, 12, 288, 2112, 63, 8575, 63, 4614, 29, 1419, 14, 1412, 63, 8575, 63, 4614, 12, 288, 2351, 29, 1730, 12, 267, 776, 339, 347, 1255, 8, 277, 12, 1511, 12, 1249, 304, 267, 340, 1511, 14, 548, 19074, 26, 288, 291, 14, 1065, 63, 548, 19074, 8, 1419, 9, 267, 916, 1511, 14, 384, 5766, 323, 26, 288, 291, 14, 1065, 63, 384, 5766, 323, 8, 1419, 9, 267, 916, 1511, 14, 10820, 26, 288, 291, 14, 1065, 63, 6297, 5987, 8, 1419, 9, 267, 587, 26, 288, 291, 14, 1065, 63, 16115, 8, 1419, 9, 339, 347, 1255, 63, 548, 19074, 8, 277, 12, 1511, 304, 267, 367, 2917, 12, 1015, 12, 6211, 315, 291, 14, 1623, 63, 5154, 63, 7410, 63, 6234, 8, 1419, 304, 288, 340, 1015, 690, 2917, 14, 6751, 63, 1023, 26, 355, 2512, 14, 815, 8, 490, 1543, 83, 334, 5639, 26, 450, 83, 491, 27126, 26, 450, 83, 8978, 83, 22206, 490, 2917, 14, 1715, 63, 354, 12, 2917, 14, 1023, 12, 1015, 12, 6211, 12, 355, 776, 339, 347, 2342, 63, 5154, 63, 7410, 63, 6234, 8, 277, 12, 1511, 304, 267, 1478, 63, 3603, 275, 359, 1419, 14, 1080, 63, 633, 61, 435, 1511, 14, 2911, 63, 1080, 63, 3603, 267, 340, 1511, 14, 889, 63, 1080, 26, 288, 2512, 14, 815, 360, 32390, 10507, 26, 450, 83, 297, 12814, 904, 8, 1080, 63, 3603, 430, 288, 1478, 63, 3603, 275, 942, 398, 5936, 63, 4614, 275, 942, 267, 367, 2917, 315, 664, 63, 7657, 63, 5613, 8, 1832, 63, 2118, 29, 1419, 14, 1832, 12, 6059, 922, 63, 2118, 29, 1419, 14, 751, 304, 288, 340, 2917, 14, 1989, 63, 2343, 360, 8575, 63, 4614, 14, 2424, 735, 355, 5936, 63, 4614, 14, 2880, 8, 490, 2917, 14, 362, 63, 2343, 63, 1278, 360, 8575, 63, 4614, 14, 2424, 659, 355, 776, 398, 543, 291, 423, 1506, 63, 1730, 8, 1419, 9, 465, 2351, 26, 288, 11569, 275, 291, 423, 1506, 63, 2491, 63, 11681, 8, 1419, 12, 1478, 63, 3603, 12, 2351, 9, 288, 11569, 14, 525, 63, 8575, 63, 4614, 8, 8575, 63, 4614, 9, 953, 4903, 63, 5154, 275, 664, 63, 7657, 63, 5613, 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, 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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 ]
flashycud/timestack
django/contrib/localflavor/pl/forms.py
273
5444
""" Polish-specific form helpers """ import re from django.forms import ValidationError from django.forms.fields import Select, RegexField from django.utils.translation import ugettext_lazy as _ from django.core.validators import EMPTY_VALUES class PLProvinceSelect(Select): """ A select widget with list of Polish administrative provinces as choices. """ def __init__(self, attrs=None): from pl_voivodeships import VOIVODESHIP_CHOICES super(PLProvinceSelect, self).__init__(attrs, choices=VOIVODESHIP_CHOICES) class PLCountySelect(Select): """ A select widget with list of Polish administrative units as choices. """ def __init__(self, attrs=None): from pl_administrativeunits import ADMINISTRATIVE_UNIT_CHOICES super(PLCountySelect, self).__init__(attrs, choices=ADMINISTRATIVE_UNIT_CHOICES) class PLPESELField(RegexField): """ A form field that validates as Polish Identification Number (PESEL). Checks the following rules: * the length consist of 11 digits * has a valid checksum The algorithm is documented at http://en.wikipedia.org/wiki/PESEL. """ default_error_messages = { 'invalid': _(u'National Identification Number consists of 11 digits.'), 'checksum': _(u'Wrong checksum for the National Identification Number.'), } def __init__(self, *args, **kwargs): super(PLPESELField, self).__init__(r'^\d{11}$', max_length=None, min_length=None, *args, **kwargs) def clean(self,value): super(PLPESELField, self).clean(value) if value in EMPTY_VALUES: return u'' if not self.has_valid_checksum(value): raise ValidationError(self.error_messages['checksum']) return u'%s' % value def has_valid_checksum(self, number): """ Calculates a checksum with the provided algorithm. """ multiple_table = (1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1) result = 0 for i in range(len(number)): result += int(number[i]) * multiple_table[i] return result % 10 == 0 class PLNIPField(RegexField): """ A form field that validates as Polish Tax Number (NIP). Valid forms are: XXX-XXX-YY-YY or XX-XX-YYY-YYY. Checksum algorithm based on documentation at http://wipos.p.lodz.pl/zylla/ut/nip-rego.html """ default_error_messages = { 'invalid': _(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.'), 'checksum': _(u'Wrong checksum for the Tax Number (NIP).'), } def __init__(self, *args, **kwargs): super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{2}-\d{2}-\d{3}-\d{3}$', max_length=None, min_length=None, *args, **kwargs) def clean(self,value): super(PLNIPField, self).clean(value) if value in EMPTY_VALUES: return u'' value = re.sub("[-]", "", value) if not self.has_valid_checksum(value): raise ValidationError(self.error_messages['checksum']) return u'%s' % value def has_valid_checksum(self, number): """ Calculates a checksum with the provided algorithm. """ multiple_table = (6, 5, 7, 2, 3, 4, 5, 6, 7) result = 0 for i in range(len(number)-1): result += int(number[i]) * multiple_table[i] result %= 11 if result == int(number[-1]): return True else: return False class PLREGONField(RegexField): """ A form field that validates its input is a REGON number. Valid regon number consists of 9 or 14 digits. See http://www.stat.gov.pl/bip/regon_ENG_HTML.htm for more information. """ default_error_messages = { 'invalid': _(u'National Business Register Number (REGON) consists of 9 or 14 digits.'), 'checksum': _(u'Wrong checksum for the National Business Register Number (REGON).'), } def __init__(self, *args, **kwargs): super(PLREGONField, self).__init__(r'^\d{9,14}$', max_length=None, min_length=None, *args, **kwargs) def clean(self,value): super(PLREGONField, self).clean(value) if value in EMPTY_VALUES: return u'' if not self.has_valid_checksum(value): raise ValidationError(self.error_messages['checksum']) return u'%s' % value def has_valid_checksum(self, number): """ Calculates a checksum with the provided algorithm. """ weights = ( (8, 9, 2, 3, 4, 5, 6, 7, -1), (2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8, -1), (8, 9, 2, 3, 4, 5, 6, 7, -1, 0, 0, 0, 0, 0), ) weights = [table for table in weights if len(table) == len(number)] for table in weights: checksum = sum([int(n) * w for n, w in zip(number, table)]) if checksum % 11 % 10: return False return bool(weights) class PLPostalCodeField(RegexField): """ A form field that validates as Polish postal code. Valid code is XX-XXX where X is digit. """ default_error_messages = { 'invalid': _(u'Enter a postal code in the format XX-XXX.'), } def __init__(self, *args, **kwargs): super(PLPostalCodeField, self).__init__(r'^\d{2}-\d{3}$', max_length=None, min_length=None, *args, **kwargs)
mit
[ 624, 199, 1575, 1891, 13, 6100, 1824, 10897, 199, 624, 199, 199, 646, 295, 199, 199, 504, 1639, 14, 3351, 492, 8505, 199, 504, 1639, 14, 3351, 14, 955, 492, 9496, 12, 12939, 792, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 199, 504, 1639, 14, 1018, 14, 11346, 492, 16589, 63, 15514, 199, 199, 533, 10092, 919, 86, 2855, 5446, 8, 5446, 304, 272, 408, 272, 437, 3504, 3938, 543, 769, 402, 4376, 1891, 4628, 25124, 557, 11908, 823, 465, 3415, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 3290, 29, 403, 304, 267, 687, 1620, 63, 2392, 1003, 380, 3319, 83, 492, 812, 47, 6882, 47, 4448, 40, 1772, 63, 16236, 267, 1613, 8, 2749, 919, 86, 2855, 5446, 12, 291, 2843, 826, 721, 3288, 12, 3415, 29, 10662, 6882, 47, 4448, 40, 1772, 63, 16236, 9, 199, 199, 533, 10092, 24532, 369, 5446, 8, 5446, 304, 272, 408, 272, 437, 3504, 3938, 543, 769, 402, 4376, 1891, 4628, 25124, 6204, 465, 3415, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 3290, 29, 403, 304, 267, 687, 1620, 63, 2113, 25124, 5260, 492, 29948, 21340, 14277, 63, 15505, 63, 16236, 267, 1613, 8, 2749, 24532, 369, 5446, 12, 291, 2843, 826, 721, 3288, 12, 3415, 29, 14288, 21340, 14277, 63, 15505, 63, 16236, 9, 199, 199, 533, 510, 9257, 654, 2901, 792, 8, 5103, 792, 304, 272, 408, 272, 437, 1824, 901, 626, 29280, 465, 4376, 1891, 473, 24926, 4860, 334, 48, 654, 2901, 680, 339, 13813, 314, 2569, 4713, 26, 267, 627, 314, 2582, 17568, 402, 4119, 7576, 267, 627, 965, 282, 1686, 9040, 339, 710, 5563, 365, 22751, 737, 1455, 921, 287, 14, 13961, 14, 1308, 15, 6797, 15, 48, 654, 2901, 14, 272, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 12561, 85, 7, 46, 6279, 473, 24926, 4860, 18581, 402, 4119, 7576, 8038, 267, 283, 8928, 356, 12561, 85, 7, 14858, 9040, 367, 314, 20548, 473, 24926, 4860, 8038, 272, 789, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 2749, 48, 654, 2901, 792, 12, 291, 2843, 826, 721, 82, 15542, 68, 91, 845, 19204, 288, 1390, 63, 1267, 29, 403, 12, 1748, 63, 1267, 29, 403, 12, 627, 589, 12, 1011, 958, 9, 339, 347, 3633, 8, 277, 12, 585, 304, 267, 1613, 8, 2749, 48, 654, 2901, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 399, 891, 267, 340, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 585, 304, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 8928, 1105, 267, 372, 399, 5956, 83, 7, 450, 574, 339, 347, 965, 63, 1078, 63, 8928, 8, 277, 12, 1329, 304, 267, 408, 267, 28562, 282, 9040, 543, 314, 2741, 5563, 14, 267, 408, 267, 3663, 63, 1224, 275, 334, 17, 12, 650, 12, 1520, 12, 1749, 12, 413, 12, 650, 12, 1520, 12, 1749, 12, 413, 12, 650, 12, 413, 9, 267, 754, 275, 378, 267, 367, 284, 315, 1425, 8, 552, 8, 1955, 2298, 288, 754, 847, 1109, 8, 1955, 59, 73, 566, 627, 3663, 63, 1224, 59, 73, 61, 267, 372, 754, 450, 1616, 508, 378, 199, 199, 533, 10092, 46, 1772, 792, 8, 5103, 792, 304, 272, 408, 272, 437, 1824, 901, 626, 29280, 465, 4376, 1891, 30174, 4860, 334, 46, 1772, 680, 272, 4821, 4513, 787, 26, 5787, 13, 13933, 13, 7080, 13, 7080, 503, 1323, 56, 13, 2483, 13, 28443, 13, 28443, 14, 339, 2670, 1838, 5563, 4079, 641, 3794, 737, 272, 1455, 921, 14249, 1712, 14, 80, 14, 320, 17019, 14, 1168, 15, 3605, 76, 416, 15, 337, 15, 78, 711, 13, 1135, 79, 14, 1360, 272, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 12561, 85, 7, 8468, 282, 9067, 1329, 901, 334, 46, 1772, 9, 315, 314, 1475, 5787, 13, 13933, 13, 2483, 13, 2483, 503, 1323, 56, 13, 2483, 13, 13933, 13, 13933, 8038, 267, 283, 8928, 356, 12561, 85, 7, 14858, 9040, 367, 314, 30174, 4860, 334, 46, 1772, 680, 659, 272, 789, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 2749, 46, 1772, 792, 12, 291, 2843, 826, 721, 82, 15542, 68, 91, 19, 93, 2696, 68, 91, 19, 93, 2696, 68, 91, 18, 93, 2696, 68, 91, 18, 93, 31686, 12773, 68, 91, 18, 93, 2696, 68, 91, 18, 93, 2696, 68, 91, 19, 93, 2696, 68, 91, 19, 19204, 288, 1390, 63, 1267, 29, 403, 12, 1748, 63, 1267, 29, 403, 12, 627, 589, 12, 1011, 958, 9, 339, 347, 3633, 8, 277, 12, 585, 304, 267, 1613, 8, 2749, 46, 1772, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 399, 891, 267, 574, 275, 295, 14, 954, 480, 1988, 11472, 4873, 574, 9, 267, 340, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 585, 304, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 8928, 1105, 267, 372, 399, 5956, 83, 7, 450, 574, 339, 347, 965, 63, 1078, 63, 8928, 8, 277, 12, 1329, 304, 267, 408, 267, 28562, 282, 9040, 543, 314, 2741, 5563, 14, 267, 408, 267, 3663, 63, 1224, 275, 334, 22, 12, 959, 12, 1520, 12, 499, 12, 650, 12, 841, 12, 959, 12, 1227, 12, 1520, 9, 267, 754, 275, 378, 267, 367, 284, 315, 1425, 8, 552, 8, 1955, 7216, 17, 304, 288, 754, 847, 1109, 8, 1955, 59, 73, 566, 627, 3663, 63, 1224, 59, 73, 61, 398, 754, 450, 29, 4119, 267, 340, 754, 508, 1109, 8, 1955, 1988, 17, 4682, 288, 372, 715, 267, 587, 26, 288, 372, 756, 199, 199, 533, 10092, 5616, 615, 792, 8, 5103, 792, 304, 272, 408, 272, 437, 1824, 901, 626, 29280, 2399, 1324, 365, 282, 14142, 615, 1329, 14, 339, 4821, 1295, 265, 1329, 18581, 402, 1749, 503, 4329, 7576, 14, 272, 1666, 1455, 921, 1544, 14, 3736, 14, 16294, 14, 1168, 15, 27566, 15, 1135 ]
[ 199, 1575, 1891, 13, 6100, 1824, 10897, 199, 624, 199, 199, 646, 295, 199, 199, 504, 1639, 14, 3351, 492, 8505, 199, 504, 1639, 14, 3351, 14, 955, 492, 9496, 12, 12939, 792, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 199, 504, 1639, 14, 1018, 14, 11346, 492, 16589, 63, 15514, 199, 199, 533, 10092, 919, 86, 2855, 5446, 8, 5446, 304, 272, 408, 272, 437, 3504, 3938, 543, 769, 402, 4376, 1891, 4628, 25124, 557, 11908, 823, 465, 3415, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 3290, 29, 403, 304, 267, 687, 1620, 63, 2392, 1003, 380, 3319, 83, 492, 812, 47, 6882, 47, 4448, 40, 1772, 63, 16236, 267, 1613, 8, 2749, 919, 86, 2855, 5446, 12, 291, 2843, 826, 721, 3288, 12, 3415, 29, 10662, 6882, 47, 4448, 40, 1772, 63, 16236, 9, 199, 199, 533, 10092, 24532, 369, 5446, 8, 5446, 304, 272, 408, 272, 437, 3504, 3938, 543, 769, 402, 4376, 1891, 4628, 25124, 6204, 465, 3415, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 3290, 29, 403, 304, 267, 687, 1620, 63, 2113, 25124, 5260, 492, 29948, 21340, 14277, 63, 15505, 63, 16236, 267, 1613, 8, 2749, 24532, 369, 5446, 12, 291, 2843, 826, 721, 3288, 12, 3415, 29, 14288, 21340, 14277, 63, 15505, 63, 16236, 9, 199, 199, 533, 510, 9257, 654, 2901, 792, 8, 5103, 792, 304, 272, 408, 272, 437, 1824, 901, 626, 29280, 465, 4376, 1891, 473, 24926, 4860, 334, 48, 654, 2901, 680, 339, 13813, 314, 2569, 4713, 26, 267, 627, 314, 2582, 17568, 402, 4119, 7576, 267, 627, 965, 282, 1686, 9040, 339, 710, 5563, 365, 22751, 737, 1455, 921, 287, 14, 13961, 14, 1308, 15, 6797, 15, 48, 654, 2901, 14, 272, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 12561, 85, 7, 46, 6279, 473, 24926, 4860, 18581, 402, 4119, 7576, 8038, 267, 283, 8928, 356, 12561, 85, 7, 14858, 9040, 367, 314, 20548, 473, 24926, 4860, 8038, 272, 789, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 2749, 48, 654, 2901, 792, 12, 291, 2843, 826, 721, 82, 15542, 68, 91, 845, 19204, 288, 1390, 63, 1267, 29, 403, 12, 1748, 63, 1267, 29, 403, 12, 627, 589, 12, 1011, 958, 9, 339, 347, 3633, 8, 277, 12, 585, 304, 267, 1613, 8, 2749, 48, 654, 2901, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 399, 891, 267, 340, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 585, 304, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 8928, 1105, 267, 372, 399, 5956, 83, 7, 450, 574, 339, 347, 965, 63, 1078, 63, 8928, 8, 277, 12, 1329, 304, 267, 408, 267, 28562, 282, 9040, 543, 314, 2741, 5563, 14, 267, 408, 267, 3663, 63, 1224, 275, 334, 17, 12, 650, 12, 1520, 12, 1749, 12, 413, 12, 650, 12, 1520, 12, 1749, 12, 413, 12, 650, 12, 413, 9, 267, 754, 275, 378, 267, 367, 284, 315, 1425, 8, 552, 8, 1955, 2298, 288, 754, 847, 1109, 8, 1955, 59, 73, 566, 627, 3663, 63, 1224, 59, 73, 61, 267, 372, 754, 450, 1616, 508, 378, 199, 199, 533, 10092, 46, 1772, 792, 8, 5103, 792, 304, 272, 408, 272, 437, 1824, 901, 626, 29280, 465, 4376, 1891, 30174, 4860, 334, 46, 1772, 680, 272, 4821, 4513, 787, 26, 5787, 13, 13933, 13, 7080, 13, 7080, 503, 1323, 56, 13, 2483, 13, 28443, 13, 28443, 14, 339, 2670, 1838, 5563, 4079, 641, 3794, 737, 272, 1455, 921, 14249, 1712, 14, 80, 14, 320, 17019, 14, 1168, 15, 3605, 76, 416, 15, 337, 15, 78, 711, 13, 1135, 79, 14, 1360, 272, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 12561, 85, 7, 8468, 282, 9067, 1329, 901, 334, 46, 1772, 9, 315, 314, 1475, 5787, 13, 13933, 13, 2483, 13, 2483, 503, 1323, 56, 13, 2483, 13, 13933, 13, 13933, 8038, 267, 283, 8928, 356, 12561, 85, 7, 14858, 9040, 367, 314, 30174, 4860, 334, 46, 1772, 680, 659, 272, 789, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 2749, 46, 1772, 792, 12, 291, 2843, 826, 721, 82, 15542, 68, 91, 19, 93, 2696, 68, 91, 19, 93, 2696, 68, 91, 18, 93, 2696, 68, 91, 18, 93, 31686, 12773, 68, 91, 18, 93, 2696, 68, 91, 18, 93, 2696, 68, 91, 19, 93, 2696, 68, 91, 19, 19204, 288, 1390, 63, 1267, 29, 403, 12, 1748, 63, 1267, 29, 403, 12, 627, 589, 12, 1011, 958, 9, 339, 347, 3633, 8, 277, 12, 585, 304, 267, 1613, 8, 2749, 46, 1772, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 399, 891, 267, 574, 275, 295, 14, 954, 480, 1988, 11472, 4873, 574, 9, 267, 340, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 585, 304, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 8928, 1105, 267, 372, 399, 5956, 83, 7, 450, 574, 339, 347, 965, 63, 1078, 63, 8928, 8, 277, 12, 1329, 304, 267, 408, 267, 28562, 282, 9040, 543, 314, 2741, 5563, 14, 267, 408, 267, 3663, 63, 1224, 275, 334, 22, 12, 959, 12, 1520, 12, 499, 12, 650, 12, 841, 12, 959, 12, 1227, 12, 1520, 9, 267, 754, 275, 378, 267, 367, 284, 315, 1425, 8, 552, 8, 1955, 7216, 17, 304, 288, 754, 847, 1109, 8, 1955, 59, 73, 566, 627, 3663, 63, 1224, 59, 73, 61, 398, 754, 450, 29, 4119, 267, 340, 754, 508, 1109, 8, 1955, 1988, 17, 4682, 288, 372, 715, 267, 587, 26, 288, 372, 756, 199, 199, 533, 10092, 5616, 615, 792, 8, 5103, 792, 304, 272, 408, 272, 437, 1824, 901, 626, 29280, 2399, 1324, 365, 282, 14142, 615, 1329, 14, 339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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 ]
jonahzheng/server
storage/tokudb/mysql-test/tokudb/t/change_column_multiple_columns.py
56
1497
import sys import itertools cols = [ 'a', 'b', 'c', 'd', 'e' ] old_types = [ 'VARCHAR(1)', 'VARBINARY(1)', 'INT', 'CHAR(1)', 'BINARY(1)' ] new_types = [ 'VARCHAR(2)', 'VARBINARY(2)', 'BIGINT', 'CHAR(2)', 'BINARY(2)' ] def main(): print "# this test generated by change_multiple_columns.py" print "# this test generated multiple column changes which should all fail since we support only one at a time" print "--disable_warnings" print "DROP TABLE IF EXISTS t;" print "--enable_warnings" print "SET SESSION TOKUDB_DISABLE_SLOW_ALTER=1;" print "SET SESSION DEFAULT_STORAGE_ENGINE='TokuDB';" create_cmd = "CREATE TABLE t (" for i in range(len(cols)): create_cmd += "%s %s" % (cols[i], old_types[i]) if i < len(cols)-1: create_cmd += "," print "%s);" % (create_cmd) l = range(len(cols)) for t in combinations(l, range(2,len(cols))): alter_cmd = gen_alter(t) print "--replace_regex /MariaDB/XYZ/ /MySQL/XYZ/" print "--error ER_UNSUPPORTED_EXTENSION" print "%s;" % (alter_cmd) print "DROP TABLE t;" return 0 def gen_alter(t): alter = "ALTER TABLE t " for c in range(len(t)): i = t[c] alter += "CHANGE COLUMN %s %s %s" % (cols[i], cols[i], new_types[i]) if c < len(t)-1: alter += "," return alter def combinations(l, r): c = [] for k in r: c += [ x for x in itertools.combinations(l, k) ] return c sys.exit(main())
gpl-2.0
[ 646, 984, 199, 646, 7975, 199, 199, 4574, 275, 359, 283, 65, 297, 283, 66, 297, 283, 67, 297, 283, 68, 297, 283, 69, 7, 1622, 199, 1753, 63, 1313, 275, 359, 283, 24800, 8, 17, 3196, 283, 5568, 13246, 8, 17, 3196, 283, 2919, 297, 283, 5901, 8, 17, 3196, 283, 13246, 8, 17, 3171, 1622, 199, 1222, 63, 1313, 275, 359, 283, 24800, 8, 18, 3196, 283, 5568, 13246, 8, 18, 3196, 283, 18643, 2919, 297, 283, 5901, 8, 18, 3196, 283, 13246, 8, 18, 3171, 1622, 199, 199, 318, 2446, 837, 272, 870, 5426, 642, 511, 4046, 701, 1570, 63, 6048, 63, 3406, 14, 647, 2, 272, 870, 5426, 642, 511, 4046, 3663, 2763, 4493, 1314, 1077, 1006, 2449, 3967, 781, 2291, 1454, 1373, 737, 282, 900, 2, 272, 870, 4320, 5993, 63, 5451, 2, 272, 870, 298, 14764, 9934, 8036, 23875, 307, 9426, 272, 870, 4320, 4296, 63, 5451, 2, 272, 870, 298, 3597, 428, 9577, 2296, 43, 53, 2846, 63, 13052, 63, 51, 5896, 63, 19350, 29, 17, 9426, 272, 870, 298, 3597, 428, 9577, 6186, 63, 17467, 63, 15956, 534, 29117, 85, 2846, 7, 9426, 272, 1218, 63, 1760, 275, 298, 8366, 9934, 307, 1689, 272, 367, 284, 315, 1425, 8, 552, 8, 4574, 2298, 267, 1218, 63, 1760, 847, 2071, 83, 450, 83, 2, 450, 334, 4574, 59, 73, 467, 2269, 63, 1313, 59, 73, 566, 267, 340, 284, 665, 822, 8, 4574, 7216, 17, 26, 288, 1218, 63, 1760, 847, 21147, 272, 870, 2071, 83, 27556, 450, 334, 981, 63, 1760, 9, 272, 634, 275, 1425, 8, 552, 8, 4574, 430, 272, 367, 307, 315, 15821, 8, 76, 12, 1425, 8, 18, 12, 552, 8, 4574, 15206, 267, 17355, 63, 1760, 275, 3805, 63, 11858, 8, 84, 9, 267, 870, 4320, 1814, 63, 3821, 1182, 45, 27957, 2846, 15, 16694, 15, 1182, 20784, 15, 16694, 6687, 267, 870, 4320, 705, 221, 540, 63, 1734, 15925, 63, 15498, 2, 267, 870, 2071, 83, 9426, 450, 334, 11858, 63, 1760, 9, 272, 870, 298, 14764, 9934, 307, 9426, 272, 372, 378, 199, 199, 318, 3805, 63, 11858, 8, 84, 304, 272, 17355, 275, 298, 19350, 9934, 307, 298, 272, 367, 286, 315, 1425, 8, 552, 8, 84, 2298, 267, 284, 275, 307, 59, 67, 61, 267, 17355, 847, 298, 16062, 29955, 450, 83, 450, 83, 450, 83, 2, 450, 334, 4574, 59, 73, 467, 8850, 59, 73, 467, 892, 63, 1313, 59, 73, 566, 267, 340, 286, 665, 822, 8, 84, 7216, 17, 26, 288, 17355, 847, 21147, 272, 372, 17355, 199, 199, 318, 15821, 8, 76, 12, 519, 304, 272, 286, 275, 942, 272, 367, 1022, 315, 519, 26, 267, 286, 847, 359, 671, 367, 671, 315, 7975, 14, 18026, 8, 76, 12, 1022, 9, 1622, 272, 372, 286, 199, 199, 1274, 14, 2224, 8, 973, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 984, 199, 646, 7975, 199, 199, 4574, 275, 359, 283, 65, 297, 283, 66, 297, 283, 67, 297, 283, 68, 297, 283, 69, 7, 1622, 199, 1753, 63, 1313, 275, 359, 283, 24800, 8, 17, 3196, 283, 5568, 13246, 8, 17, 3196, 283, 2919, 297, 283, 5901, 8, 17, 3196, 283, 13246, 8, 17, 3171, 1622, 199, 1222, 63, 1313, 275, 359, 283, 24800, 8, 18, 3196, 283, 5568, 13246, 8, 18, 3196, 283, 18643, 2919, 297, 283, 5901, 8, 18, 3196, 283, 13246, 8, 18, 3171, 1622, 199, 199, 318, 2446, 837, 272, 870, 5426, 642, 511, 4046, 701, 1570, 63, 6048, 63, 3406, 14, 647, 2, 272, 870, 5426, 642, 511, 4046, 3663, 2763, 4493, 1314, 1077, 1006, 2449, 3967, 781, 2291, 1454, 1373, 737, 282, 900, 2, 272, 870, 4320, 5993, 63, 5451, 2, 272, 870, 298, 14764, 9934, 8036, 23875, 307, 9426, 272, 870, 4320, 4296, 63, 5451, 2, 272, 870, 298, 3597, 428, 9577, 2296, 43, 53, 2846, 63, 13052, 63, 51, 5896, 63, 19350, 29, 17, 9426, 272, 870, 298, 3597, 428, 9577, 6186, 63, 17467, 63, 15956, 534, 29117, 85, 2846, 7, 9426, 272, 1218, 63, 1760, 275, 298, 8366, 9934, 307, 1689, 272, 367, 284, 315, 1425, 8, 552, 8, 4574, 2298, 267, 1218, 63, 1760, 847, 2071, 83, 450, 83, 2, 450, 334, 4574, 59, 73, 467, 2269, 63, 1313, 59, 73, 566, 267, 340, 284, 665, 822, 8, 4574, 7216, 17, 26, 288, 1218, 63, 1760, 847, 21147, 272, 870, 2071, 83, 27556, 450, 334, 981, 63, 1760, 9, 272, 634, 275, 1425, 8, 552, 8, 4574, 430, 272, 367, 307, 315, 15821, 8, 76, 12, 1425, 8, 18, 12, 552, 8, 4574, 15206, 267, 17355, 63, 1760, 275, 3805, 63, 11858, 8, 84, 9, 267, 870, 4320, 1814, 63, 3821, 1182, 45, 27957, 2846, 15, 16694, 15, 1182, 20784, 15, 16694, 6687, 267, 870, 4320, 705, 221, 540, 63, 1734, 15925, 63, 15498, 2, 267, 870, 2071, 83, 9426, 450, 334, 11858, 63, 1760, 9, 272, 870, 298, 14764, 9934, 307, 9426, 272, 372, 378, 199, 199, 318, 3805, 63, 11858, 8, 84, 304, 272, 17355, 275, 298, 19350, 9934, 307, 298, 272, 367, 286, 315, 1425, 8, 552, 8, 84, 2298, 267, 284, 275, 307, 59, 67, 61, 267, 17355, 847, 298, 16062, 29955, 450, 83, 450, 83, 450, 83, 2, 450, 334, 4574, 59, 73, 467, 8850, 59, 73, 467, 892, 63, 1313, 59, 73, 566, 267, 340, 286, 665, 822, 8, 84, 7216, 17, 26, 288, 17355, 847, 21147, 272, 372, 17355, 199, 199, 318, 15821, 8, 76, 12, 519, 304, 272, 286, 275, 942, 272, 367, 1022, 315, 519, 26, 267, 286, 847, 359, 671, 367, 671, 315, 7975, 14, 18026, 8, 76, 12, 1022, 9, 1622, 272, 372, 286, 199, 199, 1274, 14, 2224, 8, 973, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
mahak/ansible
test/support/windows-integration/plugins/modules/win_dsc.py
50
6598
#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright: (c) 2015, Trond Hindenes <trond@hindenes.com>, and others # Copyright: (c) 2017, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} DOCUMENTATION = r''' --- module: win_dsc version_added: "2.4" short_description: Invokes a PowerShell DSC configuration description: - Configures a resource using PowerShell DSC. - Requires PowerShell version 5.0 or newer. - Most of the options for this module are dynamic and will vary depending on the DSC Resource specified in I(resource_name). - See :doc:`/user_guide/windows_dsc` for more information on how to use this module. options: resource_name: description: - The name of the DSC Resource to use. - Must be accessible to PowerShell using any of the default paths. type: str required: yes module_version: description: - Can be used to configure the exact version of the DSC resource to be invoked. - Useful if the target node has multiple versions installed of the module containing the DSC resource. - If not specified, the module will follow standard PowerShell convention and use the highest version available. type: str default: latest free_form: description: - The M(win_dsc) module takes in multiple free form options based on the DSC resource being invoked by I(resource_name). - There is no option actually named C(free_form) so see the examples. - This module will try and convert the option to the correct type required by the DSC resource and throw a warning if it fails. - If the type of the DSC resource option is a C(CimInstance) or C(CimInstance[]), this means the value should be a dictionary or list of dictionaries based on the values required by that option. - If the type of the DSC resource option is a C(PSCredential) then there needs to be 2 options set in the Ansible task definition suffixed with C(_username) and C(_password). - If the type of the DSC resource option is an array, then a list should be provided but a comma separated string also work. Use a list where possible as no escaping is required and it works with more complex types list C(CimInstance[]). - If the type of the DSC resource option is a C(DateTime), you should use a string in the form of an ISO 8901 string to ensure the exact date is used. - Since Ansible 2.8, Ansible will now validate the input fields against the DSC resource definition automatically. Older versions will silently ignore invalid fields. type: str required: true notes: - By default there are a few builtin resources that come with PowerShell 5.0, see U(https://docs.microsoft.com/en-us/powershell/scripting/dsc/resources/resources) for more information on these resources. - Custom DSC resources can be installed with M(win_psmodule) using the I(name) option. - The DSC engine run's each task as the SYSTEM account, any resources that need to be accessed with a different account need to have C(PsDscRunAsCredential) set. - To see the valid options for a DSC resource, run the module with C(-vvv) to show the possible module invocation. Default values are not shown in this output but are applied within the DSC engine. author: - Trond Hindenes (@trondhindenes) ''' EXAMPLES = r''' - name: Extract zip file win_dsc: resource_name: Archive Ensure: Present Path: C:\Temp\zipfile.zip Destination: C:\Temp\Temp2 - name: Install a Windows feature with the WindowsFeature resource win_dsc: resource_name: WindowsFeature Name: telnet-client - name: Edit HKCU reg key under specific user win_dsc: resource_name: Registry Ensure: Present Key: HKEY_CURRENT_USER\ExampleKey ValueName: TestValue ValueData: TestData PsDscRunAsCredential_username: '{{ansible_user}}' PsDscRunAsCredential_password: '{{ansible_password}}' no_log: true - name: Create file with multiple attributes win_dsc: resource_name: File DestinationPath: C:\ansible\dsc Attributes: # can also be a comma separated string, e.g. 'Hidden, System' - Hidden - System Ensure: Present Type: Directory - name: Call DSC resource with DateTime option win_dsc: resource_name: DateTimeResource DateTimeOption: '2019-02-22T13:57:31.2311892+00:00' # more complex example using custom DSC resource and dict values - name: Setup the xWebAdministration module win_psmodule: name: xWebAdministration state: present - name: Create IIS Website with Binding and Authentication options win_dsc: resource_name: xWebsite Ensure: Present Name: DSC Website State: Started PhysicalPath: C:\inetpub\wwwroot BindingInfo: # Example of a CimInstance[] DSC parameter (list of dicts) - Protocol: https Port: 1234 CertificateStoreName: MY CertificateThumbprint: C676A89018C4D5902353545343634F35E6B3A659 HostName: DSCTest IPAddress: '*' SSLFlags: '1' - Protocol: http Port: 4321 IPAddress: '*' AuthenticationInfo: # Example of a CimInstance DSC parameter (dict) Anonymous: no Basic: true Digest: false Windows: yes ''' RETURN = r''' module_version: description: The version of the dsc resource/module used. returned: always type: str sample: "1.0.1" reboot_required: description: Flag returned from the DSC engine indicating whether or not the machine requires a reboot for the invoked changes to take effect. returned: always type: bool sample: true verbose_test: description: The verbose output as a list from executing the DSC test method. returned: Ansible verbosity is -vvv or greater type: list sample: [ "Perform operation 'Invoke CimMethod' with the following parameters, ", "[SERVER]: LCM: [Start Test ] [[File]DirectResourceAccess]", "Operation 'Invoke CimMethod' complete." ] verbose_set: description: The verbose output as a list from executing the DSC Set method. returned: Ansible verbosity is -vvv or greater and a change occurred type: list sample: [ "Perform operation 'Invoke CimMethod' with the following parameters, ", "[SERVER]: LCM: [Start Set ] [[File]DirectResourceAccess]", "Operation 'Invoke CimMethod' complete." ] '''
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 1898, 26, 334, 67, 9, 6900, 12, 377, 2641, 68, 869, 262, 848, 397, 665, 454, 7835, 32, 72, 262, 848, 397, 14, 957, 6244, 436, 11789, 199, 3, 1898, 26, 334, 67, 9, 9708, 12, 2622, 7290, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 199, 199, 8948, 275, 519, 2344, 199, 2595, 199, 578, 26, 4747, 63, 68, 551, 199, 1023, 63, 3270, 26, 298, 18, 14, 20, 2, 199, 3612, 63, 1802, 26, 30110, 22652, 282, 18879, 8529, 577, 5153, 2897, 199, 1802, 26, 199, 13, 4094, 1482, 282, 2073, 1808, 18879, 8529, 577, 5153, 14, 199, 13, 15127, 18879, 8529, 1015, 959, 14, 16, 503, 15666, 14, 199, 13, 17536, 402, 314, 1511, 367, 642, 859, 787, 8336, 436, 911, 17083, 10298, 641, 523, 314, 577, 5153, 7337, 2013, 315, 473, 8, 1927, 63, 354, 680, 199, 13, 1666, 520, 1301, 1705, 15, 751, 63, 17348, 15, 8258, 63, 68, 551, 64, 367, 1655, 2556, 641, 4212, 370, 675, 642, 859, 14, 199, 1419, 26, 523, 2073, 63, 354, 26, 272, 1369, 26, 272, 446, 710, 536, 402, 314, 577, 5153, 7337, 370, 675, 14, 272, 446, 9498, 506, 17909, 370, 18879, 8529, 1808, 1263, 402, 314, 849, 3792, 14, 272, 730, 26, 620, 272, 1415, 26, 9456, 523, 859, 63, 1023, 26, 272, 1369, 26, 272, 446, 6855, 506, 1202, 370, 7908, 314, 5835, 1015, 402, 314, 577, 5153, 2073, 370, 506, 489, 10302, 14, 272, 446, 18491, 340, 314, 1347, 1031, 965, 3663, 5459, 4903, 402, 314, 859, 489, 3035, 314, 577, 5153, 2073, 14, 272, 446, 982, 440, 2013, 12, 314, 859, 911, 2035, 4465, 18879, 8529, 16129, 489, 436, 675, 314, 15356, 1015, 2808, 14, 272, 730, 26, 620, 272, 849, 26, 8839, 523, 2867, 63, 964, 26, 272, 1369, 26, 272, 446, 710, 603, 8, 2676, 63, 68, 551, 9, 859, 6181, 315, 3663, 2867, 1824, 1511, 4079, 641, 314, 489, 577, 5153, 2073, 3769, 10302, 701, 473, 8, 1927, 63, 354, 680, 272, 446, 6006, 365, 949, 945, 5965, 4310, 445, 8, 4624, 63, 964, 9, 880, 1937, 314, 7251, 14, 272, 446, 961, 859, 911, 862, 436, 3957, 314, 945, 370, 314, 3211, 730, 1415, 489, 701, 314, 577, 5153, 2073, 436, 7978, 282, 5721, 340, 652, 6918, 14, 272, 446, 982, 314, 730, 402, 314, 577, 5153, 2073, 945, 365, 282, 445, 8, 35, 1017, 3244, 9, 503, 489, 445, 8, 35, 1017, 3244, 59, 2522, 642, 4910, 314, 574, 1077, 506, 282, 2600, 503, 769, 489, 402, 11196, 4079, 641, 314, 1338, 1415, 701, 626, 945, 14, 272, 446, 982, 314, 730, 402, 314, 577, 5153, 2073, 945, 365, 282, 445, 8, 5067, 23330, 9, 2066, 2337, 489, 4839, 370, 506, 499, 1511, 663, 315, 314, 2622, 2120, 5492, 4739, 379, 543, 489, 445, 1547, 2473, 9, 436, 445, 1547, 2060, 680, 272, 446, 982, 314, 730, 402, 314, 577, 5153, 2073, 945, 365, 376, 1625, 12, 2066, 282, 769, 1077, 506, 489, 2741, 1325, 282, 10029, 11673, 1059, 2597, 1736, 14, 3645, 282, 769, 2382, 489, 3962, 465, 949, 21375, 365, 1415, 436, 652, 5419, 543, 1655, 6114, 2943, 489, 769, 445, 8, 35, 1017, 3244, 59, 6575, 272, 446, 982, 314, 730, 402, 314, 577, 5153, 2073, 945, 365, 282, 445, 8, 3926, 395, 1265, 1077, 675, 489, 282, 1059, 315, 314, 1824, 402, 376, 9055, 17838, 614, 1059, 370, 4868, 314, 5835, 1434, 365, 489, 1202, 14, 272, 446, 9336, 2622, 499, 14, 24, 12, 2622, 911, 3063, 4107, 314, 1324, 1504, 6169, 314, 489, 577, 5153, 2073, 5492, 5847, 14, 593, 76, 424, 5459, 911, 18030, 489, 3686, 3866, 1504, 14, 272, 730, 26, 620, 272, 1415, 26, 2549, 199, 5983, 26, 199, 13, 4885, 849, 2337, 787, 282, 9284, 6762, 5944, 626, 11492, 543, 18879, 8529, 959, 14, 16, 12, 523, 1937, 738, 8, 2859, 921, 4757, 14, 17040, 14, 957, 15, 287, 13, 527, 15, 5652, 5641, 15, 1579, 316, 15, 68, 551, 15, 4435, 15, 4435, 9, 367, 523, 1655, 2556, 641, 3520, 5944, 14, 199, 13, 8388, 577, 5153, 5944, 883, 506, 4903, 543, 603, 8, 2676, 63, 1190, 578, 9, 1808, 314, 473, 8, 354, 9, 523, 945, 14, 199, 13, 710, 577, 5153, 6869, 1255, 1159, 1924, 2120, 465, 314, 20859, 2933, 12, 1263, 5944, 626, 1929, 523, 370, 506, 13810, 543, 282, 3365, 2933, 1929, 370, 1172, 445, 8, 25512, 36, 551, 2540, 2822, 23330, 9, 523, 663, 14, 199, 13, 4005, 1937, 314, 1686, 1511, 367, 282, 577, 5153, 2073, 12, 1255, 314, 859, 543, 445, 2801, 24622, 9, 370, 523, 2498, 314, 3962, 859, 19569, 14, 3758, 1338, 787, 440, 9164, 315, 642, 523, 1072, 1325, 787, 6781, 4453, 314, 577, 5153, 6869, 14, 199, 2502, 26, 199, 13, 377, 2641, 68, 869, 262, 848, 397, 8593, 454, 265, 7821, 262, 848, 397, 9, 199, 2344, 199, 199, 8918, 275, 519, 2344, 199, 13, 536, 26, 12892, 3482, 570, 523, 4747, 63, 68, 551, 26, 272, 2073, 63, 354, 26, 19521, 1912, 272, 7523, 26, 5543, 1150, 272, 6912, 26, 445, 3427, 6530, 60, 18717, 14, 3065, 272, 28505, 26, 445, 3427, 6530, 60, 6530, 18, 199, 199, 13, 536, 26, 13276, 282, 5417, 3878, 543, 314, 5417, 5968, 2073, 523, 4747, 63, 68, 551, 26, 272, 2073, 63, 354, 26, 5417, 5968, 272, 2812, 26, 26519, 13, 1258, 199, 199, 13, 536, 26, 16407, 869, 18504, 53, 1295, 790, 1334, 2488, 922, 523, 4747, 63, 68, 551, 26, 272, 2073, 63, 354, 26, 20738, 272, 7523, 26, 5543, 1150, 272, 2606, 26, 869, 3078, 63, 14211, 63, 3791, 60, 9846, 1197, 272, 1594, 985, 26, 1379, 1110, 272, 1594, 1451, 26, 1379 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 1898, 26, 334, 67, 9, 6900, 12, 377, 2641, 68, 869, 262, 848, 397, 665, 454, 7835, 32, 72, 262, 848, 397, 14, 957, 6244, 436, 11789, 199, 3, 1898, 26, 334, 67, 9, 9708, 12, 2622, 7290, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 199, 199, 8948, 275, 519, 2344, 199, 2595, 199, 578, 26, 4747, 63, 68, 551, 199, 1023, 63, 3270, 26, 298, 18, 14, 20, 2, 199, 3612, 63, 1802, 26, 30110, 22652, 282, 18879, 8529, 577, 5153, 2897, 199, 1802, 26, 199, 13, 4094, 1482, 282, 2073, 1808, 18879, 8529, 577, 5153, 14, 199, 13, 15127, 18879, 8529, 1015, 959, 14, 16, 503, 15666, 14, 199, 13, 17536, 402, 314, 1511, 367, 642, 859, 787, 8336, 436, 911, 17083, 10298, 641, 523, 314, 577, 5153, 7337, 2013, 315, 473, 8, 1927, 63, 354, 680, 199, 13, 1666, 520, 1301, 1705, 15, 751, 63, 17348, 15, 8258, 63, 68, 551, 64, 367, 1655, 2556, 641, 4212, 370, 675, 642, 859, 14, 199, 1419, 26, 523, 2073, 63, 354, 26, 272, 1369, 26, 272, 446, 710, 536, 402, 314, 577, 5153, 7337, 370, 675, 14, 272, 446, 9498, 506, 17909, 370, 18879, 8529, 1808, 1263, 402, 314, 849, 3792, 14, 272, 730, 26, 620, 272, 1415, 26, 9456, 523, 859, 63, 1023, 26, 272, 1369, 26, 272, 446, 6855, 506, 1202, 370, 7908, 314, 5835, 1015, 402, 314, 577, 5153, 2073, 370, 506, 489, 10302, 14, 272, 446, 18491, 340, 314, 1347, 1031, 965, 3663, 5459, 4903, 402, 314, 859, 489, 3035, 314, 577, 5153, 2073, 14, 272, 446, 982, 440, 2013, 12, 314, 859, 911, 2035, 4465, 18879, 8529, 16129, 489, 436, 675, 314, 15356, 1015, 2808, 14, 272, 730, 26, 620, 272, 849, 26, 8839, 523, 2867, 63, 964, 26, 272, 1369, 26, 272, 446, 710, 603, 8, 2676, 63, 68, 551, 9, 859, 6181, 315, 3663, 2867, 1824, 1511, 4079, 641, 314, 489, 577, 5153, 2073, 3769, 10302, 701, 473, 8, 1927, 63, 354, 680, 272, 446, 6006, 365, 949, 945, 5965, 4310, 445, 8, 4624, 63, 964, 9, 880, 1937, 314, 7251, 14, 272, 446, 961, 859, 911, 862, 436, 3957, 314, 945, 370, 314, 3211, 730, 1415, 489, 701, 314, 577, 5153, 2073, 436, 7978, 282, 5721, 340, 652, 6918, 14, 272, 446, 982, 314, 730, 402, 314, 577, 5153, 2073, 945, 365, 282, 445, 8, 35, 1017, 3244, 9, 503, 489, 445, 8, 35, 1017, 3244, 59, 2522, 642, 4910, 314, 574, 1077, 506, 282, 2600, 503, 769, 489, 402, 11196, 4079, 641, 314, 1338, 1415, 701, 626, 945, 14, 272, 446, 982, 314, 730, 402, 314, 577, 5153, 2073, 945, 365, 282, 445, 8, 5067, 23330, 9, 2066, 2337, 489, 4839, 370, 506, 499, 1511, 663, 315, 314, 2622, 2120, 5492, 4739, 379, 543, 489, 445, 1547, 2473, 9, 436, 445, 1547, 2060, 680, 272, 446, 982, 314, 730, 402, 314, 577, 5153, 2073, 945, 365, 376, 1625, 12, 2066, 282, 769, 1077, 506, 489, 2741, 1325, 282, 10029, 11673, 1059, 2597, 1736, 14, 3645, 282, 769, 2382, 489, 3962, 465, 949, 21375, 365, 1415, 436, 652, 5419, 543, 1655, 6114, 2943, 489, 769, 445, 8, 35, 1017, 3244, 59, 6575, 272, 446, 982, 314, 730, 402, 314, 577, 5153, 2073, 945, 365, 282, 445, 8, 3926, 395, 1265, 1077, 675, 489, 282, 1059, 315, 314, 1824, 402, 376, 9055, 17838, 614, 1059, 370, 4868, 314, 5835, 1434, 365, 489, 1202, 14, 272, 446, 9336, 2622, 499, 14, 24, 12, 2622, 911, 3063, 4107, 314, 1324, 1504, 6169, 314, 489, 577, 5153, 2073, 5492, 5847, 14, 593, 76, 424, 5459, 911, 18030, 489, 3686, 3866, 1504, 14, 272, 730, 26, 620, 272, 1415, 26, 2549, 199, 5983, 26, 199, 13, 4885, 849, 2337, 787, 282, 9284, 6762, 5944, 626, 11492, 543, 18879, 8529, 959, 14, 16, 12, 523, 1937, 738, 8, 2859, 921, 4757, 14, 17040, 14, 957, 15, 287, 13, 527, 15, 5652, 5641, 15, 1579, 316, 15, 68, 551, 15, 4435, 15, 4435, 9, 367, 523, 1655, 2556, 641, 3520, 5944, 14, 199, 13, 8388, 577, 5153, 5944, 883, 506, 4903, 543, 603, 8, 2676, 63, 1190, 578, 9, 1808, 314, 473, 8, 354, 9, 523, 945, 14, 199, 13, 710, 577, 5153, 6869, 1255, 1159, 1924, 2120, 465, 314, 20859, 2933, 12, 1263, 5944, 626, 1929, 523, 370, 506, 13810, 543, 282, 3365, 2933, 1929, 370, 1172, 445, 8, 25512, 36, 551, 2540, 2822, 23330, 9, 523, 663, 14, 199, 13, 4005, 1937, 314, 1686, 1511, 367, 282, 577, 5153, 2073, 12, 1255, 314, 859, 543, 445, 2801, 24622, 9, 370, 523, 2498, 314, 3962, 859, 19569, 14, 3758, 1338, 787, 440, 9164, 315, 642, 523, 1072, 1325, 787, 6781, 4453, 314, 577, 5153, 6869, 14, 199, 2502, 26, 199, 13, 377, 2641, 68, 869, 262, 848, 397, 8593, 454, 265, 7821, 262, 848, 397, 9, 199, 2344, 199, 199, 8918, 275, 519, 2344, 199, 13, 536, 26, 12892, 3482, 570, 523, 4747, 63, 68, 551, 26, 272, 2073, 63, 354, 26, 19521, 1912, 272, 7523, 26, 5543, 1150, 272, 6912, 26, 445, 3427, 6530, 60, 18717, 14, 3065, 272, 28505, 26, 445, 3427, 6530, 60, 6530, 18, 199, 199, 13, 536, 26, 13276, 282, 5417, 3878, 543, 314, 5417, 5968, 2073, 523, 4747, 63, 68, 551, 26, 272, 2073, 63, 354, 26, 5417, 5968, 272, 2812, 26, 26519, 13, 1258, 199, 199, 13, 536, 26, 16407, 869, 18504,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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 ]
rolobio/DictORM
dictorm/test/test_dictorm.py
1
57518
#! /usr/bin/env python import sqlite3 import unittest import psycopg2 from psycopg2.extras import DictCursor import dictorm test_db_login = { 'database': 'postgres', 'user': 'postgres', 'password': 'dictorm', 'host': 'localhost', 'port': '54321', 'connect_timeout': 3, } def _no_refs(o): if isinstance(o, dictorm.Dict): return o.no_refs() l = [] for i in o: if isinstance(i, dictorm.Dict): l.append(i.no_refs()) else: l.append(i) return l def error(*a, **kw): raise Exception() class ExtraTestMethods: @classmethod def assertDictContains(cls, d1, d2): missing = set(d2.items()).difference(set(d1.items())) if missing: raise TypeError('{0} does not contain {1}'.format(d1, missing)) def assertEqualNoRefs(self, a, b): return self.assertEqual(_no_refs(a), _no_refs(b)) def assertInNoRefs(self, a, b): return self.assertIn(_no_refs(a), _no_refs(b)) JSONB_SUPPORT = { '902': 'JSON', '903': 'JSON', } class TestPostgresql(ExtraTestMethods, unittest.TestCase): """ These tests will be run for all supported databases. """ def setUp(self): self.conn = psycopg2.connect(**test_db_login) # Change the schema depending on which version of Postgres we're using server_version = str(self.conn.server_version) self.major_version = major_version = server_version[:3] self.db = dictorm.DictDB(self.conn) self.curs = self.db.curs self.tearDown() self.curs.execute(''' CREATE TABLE person ( id BIGSERIAL PRIMARY KEY, name VARCHAR(100), other INTEGER, manager_id INTEGER REFERENCES person(id) ); CREATE TABLE department ( id SERIAL PRIMARY KEY, name TEXT ); CREATE TABLE person_department ( person_id INTEGER REFERENCES person(id), department_id INTEGER REFERENCES department(id), PRIMARY KEY (person_id, department_id) ); CREATE TABLE car ( id SERIAL PRIMARY KEY, license_plate TEXT, name TEXT, person_id INTEGER REFERENCES person(id), width INTEGER, height INTEGER ); ALTER TABLE person ADD COLUMN car_id INTEGER REFERENCES car(id); CREATE TABLE no_pk (foo VARCHAR(10)); CREATE TABLE station ( person_id INTEGER ); CREATE TABLE possession ( id SERIAL PRIMARY KEY, person_id INTEGER, description {JSON_OR_JSONB} ); '''.format(JSON_OR_JSONB=JSONB_SUPPORT.get(major_version, 'JSONB'))) self.conn.commit() self.db.refresh_tables() def tearDown(self): self.conn.rollback() self.curs.execute('''DROP SCHEMA public CASCADE; CREATE SCHEMA public; GRANT ALL ON SCHEMA public TO postgres; GRANT ALL ON SCHEMA public TO public;''') self.conn.commit() def test_get_where(self): Person = self.db['person'] self.assertEqual(0, Person.count()) bob = Person(name='Bob') self.assertEqual({'name': 'Bob'}, bob) bob.flush() self.assertDictContains(bob, {'name': 'Bob', 'id': 1}) self.assertEqual(list(Person.get_where(1)), [bob, ]) # A second flush does not fail bob.flush() self.assertDictContains(bob, {'name': 'Bob', 'id': 1}) self.assertEqual(list(Person.get_where(1)), [bob, ]) bob['name'] = 'Jon' bob.flush() self.assertDictContains(bob, {'name': 'Jon', 'id': 1}) self.assertEqual(list(Person.get_where(1)), [bob, ]) # Items are inserted in the order they are flushed alice = Person(name='Alice') dave = Person(name='Dave') dave.flush() alice.flush() # get_where with a single integer argument should produce a single # Dict row that matches that row's id self.assertEqual(list(Person.get_where(1)), [bob, ]) self.assertEqual(self.curs.rowcount, 1) # get_where with no parameters returns the entire table self.assertEqual(list(Person.get_where()), [bob, dave, alice]) def test_empty(self): Person = self.db['person'] p = Person().flush() self.assertEqual(p['id'], 1) def test_delete(self): Person = self.db['person'] bob = Person(name='Bob').flush() dave = Person(name='Dave').flush() alice = Person(name='Alice').flush() # A delete sql command can be executed on a Dict dave.delete() self.assertEqual(list(Person.get_where()), [bob, alice]) self.conn.commit() self.assertEqual(list(Person.get_where()), [bob, alice]) # get_where accepts a tuple of ids, and returns those rows if self.db.kind != dictorm.DBKind.sqlite3: self.assertEqual(list(Person.get_where(Person['id'].In([1, 3]))), [bob, alice]) # Database row survives an object deletion del bob del alice self.conn.commit() self.assertEqual(Person.count(), 2) bob, alice = Person.get_where() bob.delete() alice.delete() self.assertEqual(Person.count(), 0) def test_get_where_multiple_pks(self): Person = self.db['person'] self.assertEqual(0, Person.count()) bob = Person(name='Bob').flush() Department = self.db['department'] self.assertEqual(0, Department.count()) sales = Department(name='Sales').flush() PD = self.db['person_department'] bob_sales = PD(person_id=bob['id'], department_id=sales['id']).flush() self.assertEqual(bob_sales['person_id'], bob['id']) self.assertEqual(bob_sales['department_id'], sales['id']) # Searching person_department with two key/value pairs returns the new # row. self.assertEqual( list(PD.get_where(person_id=1, department_id=1)), [bob_sales, ]) # Test deletion with multiple Primary Keys bob_sales.delete() self.assertEqual(PD.count(), 0) def test_already_in_db(self): Person = self.db['person'] self.assertEqual(0, Person.count()) bob = Person(name='Bob').flush() bob_copy = Person.get_one(1) bob_copy.flush() self.assertEqual(bob, bob_copy) def test_dict_inits(self): Person = self.db['person'] Person({'name': 'Bob'}).flush() Person(name='Alice').flush() Person([('name', 'Steve'), ]).flush() dictorm.Dict(Person, {'name': 'Bob'}).flush() dictorm.Dict(Person, name='Alice').flush() dictorm.Dict(Person, [('name', 'Steve'), ]).flush() def test_remove_pks(self): Person = self.db['person'] self.assertEqual(0, Person.count()) bob = Person(name='Bob') self.assertEqual(bob, {'name': 'Bob'}) bob.flush() self.assertDictContains(bob, {'name': 'Bob', 'id': 1}) self.assertDictContains(bob.no_pks(), {'name': 'Bob'}) aly = Person(name='Aly') self.assertEqual(aly, {'name': 'Aly'}) aly.flush() self.assertDictContains(aly, {'name': 'Aly', 'id': 2}) self.assertDictContains(aly.no_pks(), {'name': 'Aly'}) bob.update(aly.no_pks()) bob.flush() aly.flush() self.assertDictContains(bob, {'name': 'Aly', 'id': 1}) self.assertDictContains(aly, {'name': 'Aly', 'id': 2}) def test_manytomany(self): """ Linking to person.id from person_department.person_id allows you to have multiple person_department records. person | person_department | department --------------------+------------------------------+------------------- id <-------+-+----- | person_id department_id -> | id \ \---- | person_id department_id -> | id \----- | person_id department_id -> | id """ Person = self.db['person'] Department = self.db['department'] PD = self.db['person_department'] PD.sort_by = 'person_id' PD['department'] = PD['department_id'] == Department['id'] PD['person'] = PD['person_id'] == Person['id'] Person['person_departments'] = Person['id'].many(PD['person_id']) bob = Person(name='Bob').flush() self.assertDictContains(bob, {'name': 'Bob', 'id': 1}) sales = Department(name='Sales').flush() bob_pd_sales = PD(department_id=sales['id'], person_id=bob['id']).flush() self.assertEqual(list(bob['person_departments']), [bob_pd_sales, ]) hr = Department(name='HR').flush() bob_pd_hr = PD(department_id=hr['id'], person_id=bob['id']).flush() self.assertEqual(list(bob['person_departments']), [bob_pd_sales, bob_pd_hr]) # Adding another person doesn't break the list aly = Person(name='Aly').flush() self.assertEqual(list(bob['person_departments']), [bob_pd_sales, bob_pd_hr]) aly_pd_sales = PD(department_id=sales['id'], person_id=aly['id']).flush() aly.flush() self.assertEqual(list(aly['person_departments']), [aly_pd_sales, ]) self.assertEqual(list(bob['person_departments']), [bob_pd_sales, bob_pd_hr]) # Move bob's hr to aly bob_pd_hr['person_id'] = aly['id'] aly_pd_hr = bob_pd_hr.flush() self.assertEqualNoRefs(aly['person_departments'], [aly_pd_sales, aly_pd_hr]) self.assertEqualNoRefs(bob['person_departments'], [bob_pd_sales, ]) def test_substratum_many(self): """ Creating a reference using two other references fascilitates getting rows from a third table, if the second table's contents aren't needed often, like a join table. """ Person = self.db['person'] Department = self.db['department'] PD = self.db['person_department'] # Setup the initial references Person['person_departments'] = Person['id'].many(PD['person_id']) PD['department'] = PD['department_id'] == Department['id'] # Directly access a person's departments by getting the sub-references Person['departments'] = Person['person_departments'].substratum('department') # Create the associated rows bob = Person(name='Bob').flush() # Departments sales = Department(name='Sales').flush() hr = Department(name='HR').flush() # rows linking person and department using join table "person_department" bob_pd_sales = PD(department_id=sales['id'], person_id=bob['id']).flush() bob_pd_hr = PD(department_id=hr['id'], person_id=bob['id']).flush() self.assertEqual(list(bob['departments']), [sales, hr]) self.assertEqual(list(bob['person_departments']), [bob_pd_sales, bob_pd_hr]) def test_substratum_one(self): Person = self.db['person'] Car = self.db['car'] # Setup the initial references Person['manager'] = Person['manager_id'] == Person['id'] Person['car'] = Person['car_id'] == Car['id'] Person['manager_name'] = Person['manager'].substratum('name') Person['manager_car'] = Person['manager'].substratum('car') alice_car = Car(name='Prius').flush() alice = Person(name='Alice', car_id=alice_car['id']).flush() bob = Person(name='Bob', manager_id=alice['id']).flush() alice['manager_id'] = bob['id'] alice.flush() self.assertEqualNoRefs(bob['manager_car'], alice_car) self.assertEqualNoRefs(bob['manager'], alice) # Overwriting a substratum doesn't break a flush self.assertEqual(bob['manager_name'], 'Alice') bob['manager_name'] = 'foo' bob.flush() self.assertEqual(bob['manager_name'], 'foo') def test_onetomany(self): """ person | car --------------------+-------------------------------------------------- id <----+-+---- | person_id \ \--- | person_id \---- | person_id """ Person = self.db['person'] Car = self.db['car'] Person['cars'] = Person['id'].many(Car['person_id']) bob = Person(name='Bob').flush() self.assertEqual(list(bob.get('cars')), []) toyota = Car(name='Toyota', person_id=bob['id']).flush() honda = Car(name='Honda', person_id=bob['id']).flush() ford = Car(name='Ford', person_id=bob['id']).flush() self.assertEqual(list(bob.get('cars')), [toyota, honda, ford]) self.assertEqual(list(bob['cars']), [toyota, honda, ford]) self.assertEqual(list(bob.references().keys()), ['cars', ]) def test_onetomany_alter_primary_key(self): Person = self.db['person'] bob = Person(name='Bob').flush() aly = Person(name='Aly').flush() Station = self.db['station'] Station.order_by = 'person_id' Station['person'] = Station['person_id'] == Person['id'] Person['stations'] = Person['id'].many(Station['person_id']) desk1 = Station(person_id=bob['id']).flush() desk2 = Station(person_id=bob['id']).flush() desk3 = Station(person_id=bob['id']).flush() self.assertEqual(list(bob['stations']), [desk1, desk2, desk3]) bob.delete() self.conn.commit() self.assertEqual(desk1['person_id'], 1) self.assertEqual(desk2['person_id'], 1) self.assertEqual(desk3['person_id'], 1) aly['id'] = 1 aly.flush() self.assertEqual(list(aly['stations']), [desk1, desk2, desk3]) def test_changing_pks(self): Person = self.db['person'] bob = Person(name='Bob').flush() self.assertEqual(bob['id'], 1) bob['id'] = 2 bob.flush() self.assertEqual(bob['id'], 2) def test_onetoone(self): """ person | car --------------------+-------------------------------------------------- id <----------- | person_id car_id -----------> | id """ Person = self.db['person'] Car = self.db['car'] Person['car'] = Person['car_id'] == Car['id'] Car['person'] = Car['person_id'] == Person['id'] will = Person(name='Will').flush() stratus = Car(name='Dodge Stratus', license_plate='123ABC').flush() stratus['person_id'], will['car_id'] = will['id'], stratus['id'] stratus.flush() will.flush() self.assertEqualNoRefs(will.get('car'), stratus) self.assertEqualNoRefs(will['car'], stratus) self.assertEqualNoRefs(stratus['person'], will) self.assertEqual(list(will.references().keys()), ['car', ]) def test_onetoself(self): """ person | person --------------------+-------------------------------------------------- id <----------- | manager_id """ Person = self.db['person'] Person['manager'] = Person['manager_id'] == Person['id'] alice = Person(name='Alice').flush() bob = Person(name='Bob', manager_id=alice['id']).flush() self.assertEqual(bob['manager'], alice) bob['manager_id'] = bob['id'] bob.flush() self.assertEqualNoRefs(bob['manager'], bob) self.assertEqual(list(bob.references().keys()), ['manager', ]) def test_errors(self): """ A table with no primary key(s) can be gotten, but not updated. """ Person = self.db['person'] bob = Person(name='Bob').flush() Person(name='Aly').flush() self.assertRaises(dictorm.NoPrimaryKey, Person.get_where, 1, 2) self.assertRaises(KeyError, bob.__getitem__, 'foo') self.assertRaises(dictorm.UnexpectedRows, Person.get_one) NoPk = self.db['no_pk'] foo = NoPk(foo='bar') foo.flush() self.conn.commit() self.assertEqual(foo, {'foo': 'bar'}) self.assertEqual(list(NoPk.get_where()), [{'foo': 'bar'}, ]) foo['foo'] = 'baz' self.assertRaises(dictorm.NoPrimaryKey, foo.flush) self.assertRaises(dictorm.NoPrimaryKey, NoPk.get_where, 1) def test_order_by(self): Person = self.db['person'] bob = Person(name='Bob').flush() aly = Person(name='Aly').flush() wil = Person(name='Wil').flush() self.assertEqual(list(Person.get_where()), [bob, aly, wil]) Person.order_by = 'id asc' self.assertEqual(list(Person.get_where()), [bob, aly, wil]) Person.order_by = 'id desc' self.assertEqual(list(Person.get_where()), [wil, aly, bob]) NoPk = self.db['no_pk'] NoPk(foo='bar').flush() NoPk(foo='baz').flush() self.assertEqual(NoPk.count(), 2) self.assertNotIn('ORDER BY', NoPk.curs.query.decode()) NoPk.order_by = 'foo desc' results = NoPk.get_where() self.assertEqual(len(list(results)), 2) self.assertIn('ORDER BY foo desc', results.curs.query.decode()) NoPk.order_by = None self.assertEqual(len(list(NoPk.get_where(foo='bar'))), 1) self.assertNotIn('ORDER BY', NoPk.curs.query.decode()) NoPk.order_by = 'foo desc' results = NoPk.get_where(foo='bar') self.assertEqual(len(list(results)), 1) self.assertIn('ORDER BY foo desc', results.curs.query.decode()) def test_multiple_references(self): """ person | person ---------------------+--------------- id <---------------- | manager_id person | person ---------------------+--------------- id <--+-+---------- | manager_id \ \--------- | manager_id \---------- | manager_id """ Person = self.db['person'] Person['manager'] = Person['manager_id'] == Person['id'] alice = Person(name='Alice').flush() self.assertEqual(None, alice['manager']) dave = Person(name='Dave', manager_id=alice['id']).flush() self.assertDictContains(dave, {'name': 'Dave', 'manager_id': 1, 'manager': None}) self.assertEqualNoRefs(dave['manager'], alice) bob = Person(name='Bob', manager_id=alice['id']).flush() self.assertNotEqual(bob['manager'], None) self.assertEqualNoRefs(bob['manager'], alice) # New reference, no flush required Person['subordinates'] = Person['id'].many(Person['manager_id']) self.assertEqualNoRefs(alice['subordinates'], [dave, bob]) # Changes survive a commit/flush self.conn.commit() bob.flush() alice.flush() dave.flush() self.assertEqualNoRefs(alice['subordinates'], [dave, bob]) self.assertEqualNoRefs(dave['manager'], alice) self.assertEqualNoRefs(bob['manager'], alice) PD, Department = self.db['person_department'], self.db['department'] PD['department'] = PD['department_id'] == Department['id'] Person['person_departments'] = Person['id'].many(PD['person_id']) hr = Department(name='HR').flush() sales = Department(name='Sales').flush() hr_pd = PD(department_id=hr['id'], person_id=dave['id']).flush() sales_pd = PD(department_id=sales['id'], person_id=dave['id']).flush() # All references are available on demand self.assertEqualNoRefs(dave['person_departments'], [hr_pd, sales_pd]) self.assertEqualNoRefs(alice['subordinates'], [dave, bob]) self.assertEqualNoRefs(dave['manager'], alice) self.assertEqualNoRefs(bob['manager'], alice) # You can iterate through subordinates using a for loop for sub in alice['subordinates']: for pd in sub['person_departments']: pd.delete() sub.delete() def test_empty_reference(self): """ Iterating through an empty reference does not break. """ Person = self.db['person'] Person['subordinates'] = Person['id'].many(Person['manager_id']) alice = Person(name='Alice').flush() self.assertEqual(len(alice['subordinates']), 0) self.assertEqual(len(iter(alice['subordinates'])), 0) Person['manager'] = Person['id'] == Person['manager_id'] Person['managers_manager'] = Person['manager'].substratum('manager') self.assertEqual(alice['manager'], None) # An empty substratum doesn't error self.assertEqual(alice['managers_manager'], None) def test_reexecute(self): """ References are only gotten once, until they are changed. """ Person = self.db['person'] Person['manager'] = Person['manager_id'] == Person['id'] bob = Person(name='Bob').flush() alice = Person(name='Alice', manager_id=bob['id']).flush() self.assertEqual(alice['manager'], bob) original_get_where = alice.table.get_where alice.table.get_where = error self.assertEqual(alice['manager'], bob) steve = Person(name='Steve').flush() alice.table.get_where = original_get_where alice['manager_id'] = steve['id'] alice.flush() self.assertEqualNoRefs(alice['manager'], steve) def test_modify_subdict(self): Person = self.db['person'] Car = self.db['car'] Person['car'] = Person['car_id'] == Car['id'] will = Person(name='Will').flush() stratus = Car(name='Stratus').flush() will['car_id'] = stratus['id'] will['car']['license_plate'] = 'foo' # Flush will, this should also flush car will.flush() # Get another copy of car stratus2 = Car.get_one() self.assertEqual(stratus2['license_plate'], 'foo') self.assertNotEqual(stratus, stratus2) # Flushing the original object overwrites the copy's changes stratus.flush() self.assertNotEqual(stratus['license_plate'], 'foo') self.assertNotEqual(stratus, stratus2) def test_table_equal(self): """ A Dicts hidden _table can be compared to itself or other tables. """ Person = self.db['person'] self.assertEqual(Person, self.db['person']) self.assertIs(Person, self.db['person']) will = Person(name='Will').flush() bob = Person(name='Bob').flush() self.assertEqual(will.table, bob.table) self.assertIs(will.table, bob.table) Car = self.db['car'] self.assertNotEqual(Person, Car) Person['car'] = Person['car_id'] == Car['id'] stratus = Car(name='Stratus').flush() will['car_id'] = stratus['id'] will.flush() will['car']['license_plate'] = 'foo' self.assertEqual(stratus.table, Car) self.assertIs(stratus.table, Car) self.assertEqual(will['car'].table, Car) self.assertIs(will['car'].table, Car) def test_real(self): """ An attempt at a real-world example. """ Person, Car = self.db['person'], self.db['car'] PD, Department = self.db['person_department'], self.db['department'] Possession = self.db['possession'] Person['manager'] = Person['manager_id'] == Person['id'] Person['subordinates'] = Person['id'].many(Person['manager_id']) Person['person_departments'] = Person['id'].many(PD['person_id']) Person['departments'] = Person['person_departments'].substratum('department') Person['car'] = Person['car_id'] == Car['id'] Person['possessions'] = Person['id'].many(Possession['person_id']) Car['person'] = Car['person_id'] == Person['id'] PD['person'] = Person['id'] == PD['person_id'] PD['department'] = PD['department_id'] == Department['id'] Department['person_departments'] = Department['id'].many(PD['department_id']) Department['persons'] = Department['person_departments'].substratum('person') Possession['person'] = Possession['person_id'] == Person['id'] # Milton has a car milton = Person(name='Milton').flush() miltons_car = Car(name='Ford', person_id=milton['id']).flush() milton['car_id'] = miltons_car['id'] sales = Department(name='Sales').flush() self.assertEqualNoRefs(milton['car'], miltons_car) milton.flush() miltons_car.flush() self.assertEqual(milton['car'], miltons_car) # Milton is in Sales milton_sales = PD(person_id=milton['id'], department_id=sales['id']).flush() self.assertEqualNoRefs(milton_sales, PD.get_one()) self.assertEqualNoRefs(milton_sales['person'], milton) self.assertEqualNoRefs(milton_sales['department'], sales) self.assertEqualNoRefs(milton['departments'], [sales, ]) self.assertEqualNoRefs(sales['persons'], [milton, ]) # Milton has a stapler miltons_stapler = Possession(person_id=milton['id'], description={'kind': 'stapler', 'brand': 'Swingline', 'color': 'Red'} ).flush() self.assertEqualNoRefs(miltons_stapler['person'], milton) self.assertEqualNoRefs(milton['possessions'], [miltons_stapler, ]) # Milton has a manager tom = Person(name='Tom').flush() milton['manager_id'] = tom['id'] milton.flush() self.assertEqual(milton['manager'], tom) # Tom takes milton's stapler miltons_stapler['person_id'] = tom['id'] toms_stapler = miltons_stapler.flush() self.assertEqualNoRefs(toms_stapler['person'], tom) self.assertEqualNoRefs(tom['possessions'], [toms_stapler, ]) # Peter is Tom's subordinate peter = Person(name='Peter', manager_id=tom['id']).flush() self.assertEqual(peter['manager'], tom) self.assertInNoRefs(peter, tom['subordinates']) self.assertInNoRefs(milton, tom['subordinates']) # Peter is also in sales PD(person_id=peter['id'], department_id=sales['id']).flush() self.assertInNoRefs(peter, sales['persons']) self.assertInNoRefs(milton, sales['persons']) # There are 3 people self.assertEqual(Person.count(), 3) if self.db.kind == 'postgresql': self.assertEqual(Person.count(), 3) self.assertEqual(len(Person.get_where()), 3) # There are two salesmen self.assertEqual(len(list(PD.get_where(department_id=sales['id']))), 2) # Milton's car is shared peter['car_id'] = miltons_car['id'] peter.flush() self.assertEqual(peter['car'], miltons_car) self.assertEqualNoRefs(miltons_car['person'], milton) self.assertEqualNoRefs(peter['car'], miltons_car) car_owners = Person.get_where(car_id=miltons_car['id']) self.assertEqualNoRefs(car_owners, [milton, peter]) # You can reuse a ResultsGenerator minions = tom['subordinates'] self.assertEqualNoRefs(minions, [milton, peter]) limited_minions = minions.limit(1) self.assertEqualNoRefs(limited_minions, [milton, ]) self.assertEqualNoRefs(limited_minions.order_by('id DESC'), [peter, ]) # A modified ResultsGenerator creates a new query self.assertEqualNoRefs(minions.refine(Person['name'] == 'Milton'), [milton, ]) self.assertEqualNoRefs(minions.refine(Person['name'] == 'Peter'), [peter, ]) self.assertEqualNoRefs(Person.get_where(Person['id'].IsNot(None )).order_by('id ASC'), [milton, tom, peter]) self.assertEqualNoRefs(Person.get_where(Person['id'] > 0).order_by( 'id ASC'), [milton, tom, peter]) def test_offset_limit(self): """ A result set can be refined using an offset and limit. """ Person = self.db['person'] bob = Person(name='Bob').flush() aly = Person(name='Aly').flush() tom = Person(name='Tom').flush() abe = Person(name='Abe').flush() gus = Person(name='Gus').flush() persons = Person.get_where() self.assertEqual(list(persons), [bob, aly, tom, abe, gus]) self.assertEqual(list(persons), [bob, aly, tom, abe, gus]) # Using limit and offset, but in such a way that it returns everything if self.db.kind == 'postgresql': self.assertEqual(list(persons.limit('ALL').offset(0)), [bob, aly, tom, abe, gus]) # Single refine limited = persons.limit(2) self.assertEqual(list(limited), [bob, aly]) self.assertEqual(list(limited), [bob, aly]) self.assertEqual(list(limited.offset(3)), [abe, gus]) # Multiple refinings self.assertEqual(list(persons.limit(2).offset(2)), [tom, abe]) def test_refine_comparisons(self): Person = self.db['person'] Car = self.db['car'] Person['subordinates'] = Person['id'].many(Person['manager_id']) bob = Person(name='Bob').flush() steves_car = Car().flush() steve = Person(name='Steve', car_id=steves_car['id'], manager_id=bob['id']).flush() aly = Person(name='Aly', manager_id=bob['id']).flush() frank = Person(name='Frank', manager_id=bob['id']).flush() self.assertEqual(list(bob['subordinates']), [steve, aly, frank]) self.assertEqual(list(bob['subordinates'].order_by('id DESC')), [frank, aly, steve]) self.assertEqual(list(bob['subordinates'].order_by('id DESC' ).limit(1)), [frank, ]) self.assertEqual(list(bob['subordinates'].order_by('id DESC' ).limit(1).offset(1)), [aly, ]) self.assertEqual(list(bob['subordinates'].refine(Person['car_id'] > 0)), [steve, ]) @unittest.expectedFailure def test_onetoone_cache(self): """ One-to-one relationships are cached. TODO This fails because the cached object's row was changed """ Person = self.db['person'] Person['manager'] = Person['manager_id'] == Person['id'] bob = Person(name='Bob').flush() bill = Person(name='Bill').flush() bob['manager_id'] = bill['id'] self.assertEqual(bob['manager'], bill) old_get_one = bob.table.get_one bob.table.get_one = error # Error fuction shouldn't be called, since manager is cached self.assertEqual(bob['manager'], bill) Car = self.db['car'] Person['car'] = Person['car_id'] == Car['id'] Person['manager_car'] = Person['manager'].substratum('car') bob.table.get_one = old_get_one self.assertEqual(bob['manager_car'], None) bill_car = Car(name='Prius').flush() bill['car_id'] = bill_car['id'] self.assertEqualNoRefs(bob['manager'], bill) self.assertEqualNoRefs(bob['manager_car'], bill_car) def test_results_cache(self): """ A result will not be gotten again, since it's results were cached. """ Person = self.db['person'] Person['subordinates'] = Person['id'].many(Person['manager_id']) bob = Person(name='Bob').flush() bill = Person(name='Bill').flush() alice = Person(name='Alice').flush() steve = Person(name='Steve').flush() bill['manager_id'] = bob['id'] bill.flush() alice['manager_id'] = bob['id'] alice.flush() steve['manager_id'] = bob['id'] steve.flush() subordinates = bob['subordinates'] for sub in subordinates: assert isinstance(sub, dictorm.Dict) # Error would be raised if subordinates isn't cached bob.table.get_where = error for sub in subordinates: assert isinstance(sub, dictorm.Dict) def test_reference_order(self): """ A reference definition cares about order. """ Person = self.db['person'] Person['manager'] = Person['manager_id'] == Person['id'] bob = Person(name='Bob').flush() alice = Person(name='Alice', manager_id=bob['id']).flush() self.assertEqualNoRefs(alice['manager'], bob) Person['manager'] = Person['id'] == Person['manager_id'] # Get alice again to clear cache alice = Person.get_one(id=2) self.assertEqual(alice['manager'], None) def test_columns(self): """ Table.columns is a method that gets a list of a table's columns """ Person = self.db['person'] self.assertEqual(sorted(Person.columns), ['car_id', 'id', 'manager_id', 'name', 'other']) def test_like(self): Person = self.db['person'] bob = Person(name='Bob').flush() self.assertEqualNoRefs(Person.get_where(Person['name'].Like('Bob')), [bob, ]) self.assertEqualNoRefs(Person.get_where(Person['name'].Like('%Bo%')), [bob, ]) def test_table_cls(self): class NewTable(dictorm.Table): pass self.db.table_factory = lambda: NewTable self.db.refresh_tables() self.assertIsInstance(self.db['person'], NewTable) def test_indexing(self): Person = self.db['person'] result = Person.get_where() self.assertRaises(IndexError, result.__getitem__, 0) bob = Person(name='Bob').flush() alice = Person(name='Alice').flush() steve = Person(name='Steve').flush() result = Person.get_where() self.assertEqual(result[0], bob) self.assertEqual(result[0], bob) self.assertEqual(result[2], steve) self.assertEqual(result[-1], steve) self.assertEqual(result[-1], steve) self.assertEqual(result[1:], [alice, steve]) def test_concurrent(self): """ A ResultsGenerator is on it's own transaction. Changing a row's values will not be reflected in the existing Results. """ Person = self.db['person'] bob = Person(name='Bob').flush() alice = Person(name='Alice').flush() results = Person.get_where() self.assertEqualNoRefs(results[0], bob) alice['name'] = 'Amy' alice.flush() # Gotten result contains the old value self.assertEqual(next(results)['name'], 'Alice') # Alice was changed self.assertEqual(alice['name'], 'Amy') self.conn.commit() self.assertEqual(alice['name'], 'Amy') def test_nocache(self): """ A ResultsGenerator can be told not to cache results. """ Person = self.db['person'] bob = Person(name='Bob').flush() alice = Person(name='Alice').flush() results = Person.get_where().nocache() # Cache all results, if caching was enabled self.assertEqual(next(results), bob) self.assertEqual(next(results), alice) self.assertRaises(StopIteration, next, results) # Cache is empty self.assertEqual(results.cache, []) # Cannot iterate through results more than once self.assertRaises(dictorm.NoCache, results.__getitem__, 0) def test_aggregate(self): """ A chain of many substratums creates an aggregate of the results. """ Person, Department = self.db['person'], self.db['department'] PD = self.db['person_department'] PD.pks = ['person_id', 'department_id'] # Relations PD['department'] = PD['department_id'] == Department['id'] PD['person'] = PD['person_id'] == Department['id'] Person['person_departments'] = Person['id'].many(PD['person_id']) Person['departments'] = Person['person_departments'].substratum( 'department') Person['manager'] = Person['manager_id'] == Person['id'] Person['subordinates'] = Person['id'].many(Person['manager_id']) Person['subordinates_departments'] = Person['subordinates'].aggregate( 'departments') # People, with manager bob = Person(name='Bob').flush() alice = Person(name='Alice', manager_id=bob['id']).flush() steve = Person(name='Steve', manager_id=bob['id']).flush() # Departments sales = Department(name='Sales').flush() hr = Department(name='HR').flush() it = Department(name='IT').flush() # Person_Departments PD(person_id=steve['id'], department_id=sales['id']).flush() PD(person_id=steve['id'], department_id=hr['id']).flush() PD(person_id=alice['id'], department_id=it['id']).flush() self.assertEqualNoRefs(alice['manager'], bob) self.assertEqualNoRefs(steve['manager'], bob) self.assertEqualNoRefs(bob['subordinates'], [alice, steve]) self.assertEqualNoRefs(bob['subordinates_departments'], [it, sales, hr]) def test_value_types(self): """ When a row is updated, the flush should return values of the correct type. """ Person = self.db['person'] bob = Person(name='Bob').flush() self.assertEqual(bob['id'], 1) # Update "id" using a string bob.update({'id': '1', 'name': 'Steve'}) steve = bob.flush() self.assertEqual(steve['id'], 1) # ID should be an integer self.assertEqual(steve['name'], 'Steve') def test_injection(self): """ A column name can't be used for injection """ Person = self.db['person'] bob = Person(name='Bob').flush() self.assertEqual(bob['id'], 1) self.conn.commit() # An entry can still be flushed even if a column is missing del bob['manager_id'] self.assertNotIn('manager_id', bob) bob.flush() self.assertIn('manager_id', bob) # An invalid column name raises an error self.assertRaises(dictorm.CannotUpdateColumn, bob.__setitem__, ' "; DELETE FROM person;', 'Bob') def test_operators(self): Person = self.db['person'] persons = map(lambda i: Person(name=i).flush(), ['Bob', 'Aly', 'Dave']) bob, aly, dave = persons self.assertEqual( list(Person.get_where(dictorm.And( Person['name'] == 'Bob', Person['id'] > 0))), [bob]) self.assertEqual( list(Person.get_where(dictorm.Or( Person['id'] == 2, Person['id'] == 3))), [aly, dave]) def test_raw(self): """ A raw SQL query can be executed using a Table. It expects that the query will select from its table. """ Person = self.db['person'] bob, aly = map(lambda i: Person(name=i).flush(), ['Bob', 'Aly']) persons = Person.get_raw('SELECT * FROM person') self.assertEqual(list(persons), [bob, aly]) persons = Person.get_raw('SELECT * FROM person WHERE id=%s', aly['id']) self.assertEqual(list(persons), [aly]) def test_raw_custom_column(self): """ Custom columns can be selected in a raw query. This shouldn't break the flush. :return: """ Person = self.db['person'] bob = Person(name='Bob').flush() persons = Person.get_raw('SELECT * FROM person') self.assertEqual(list(persons), [bob]) custom_bob, = Person.get_raw("SELECT *, 'bar' AS foo FROM person") self.assertIn('foo', custom_bob) # Custom column "foo" should be ignored in the flush custom_bob.flush() def test_transaction(self): """ A helper method exists on the db object to facilitate a database transaction. :return: """ Person = self.db['person'] with self.db.transaction(): bob = Person(name='Bob').flush() # Bob was created during the transaction self.assertEqual(bob, Person.get_one()) self.conn.commit() self.assertEqual({'Bob'}, set([i['name'] for i in Person.get_where()])) class FakeException(Exception): pass # The creation of Alice has an error try: with self.db.transaction(): Person(name='Alice').flush() raise FakeException('oh no') except FakeException: pass # Alice doesn't exist self.assertEqual({'Bob'}, set([i['name'] for i in Person.get_where()])) # Autocommit on success with self.db.transaction(commit=True): Person(name='Alice').flush() Person(name='Dave').flush() # New persons were committed, so rollback should have no effect self.conn.rollback() self.assertEqual({'Bob', 'Alice', 'Dave'}, set([i['name'] for i in Person.get_where()])) def test_insert_custom_columns(self): """ A Dict with custom columns is inserted, with the custom columns ignored. :return: """ Person = self.db['person'] steve = dictorm.Dict(Person, foo='bar', name='Steve').flush() self.assertEqual(steve['id'], 1) self.assertEqual(steve['name'], 'Steve') # Get the real Steve from the database real_steve = Person.get_one() # Remove the "foo", they should then be equal del steve['foo'] self.assertEqual(real_steve, steve) def test_columns_property(self): """ Table.columns and Table.columns_info are properties, and should only get their values once. Not supported under Sqlite3 """ Person = self.db['person'] original_execute = self.curs.execute col_vals = ['id', 'name', 'other', 'manager_id', 'car_id'] self.assertEqual(set(Person.columns), set(col_vals)) try: Person.curs.execute = error # Error shouldn't be raised self.assertEqual(set(Person.columns), set(col_vals)) finally: Person.curs.execute = original_execute def test_count(self): """ Simple reference counting is supported. """ Person = self.db['person'] Person['subordinates'] = Person['id'].many(Person['manager_id']) alice = Person(name='Alice').flush() dave = Person(name='Dave', manager_id=alice['id']).flush() bob = Person(name='Bob', manager_id=alice['id']).flush() self.assertIsInstance(alice['subordinates'], dictorm.ResultsGenerator) self.assertNotIn(alice._curs.query.decode(), 'SELECT *') # get len() without running a larger query self.assertEqual(len(alice['subordinates']), 2) # you can still get the same old results even after running a len() self.assertEqualNoRefs(alice['subordinates'], [dave, bob]) # the generator can be converted to a list self.assertEqualNoRefs(list(alice['subordinates']), [dave, bob]) subs = alice['subordinates'] self.assertEqual(len(subs), 2) self.assertEqualNoRefs(subs, [dave, bob]) def test_ilike(self): Person = self.db['person'] alice = Person(name='Alice').flush() self.assertEqualNoRefs(Person.get_where(Person['name'].Ilike('ali%')), [alice, ]) def test_json(self): Possession = self.db['possession'] p = Possession(description={'foo': 'bar', 'baz': 1}).flush() self.assertEqual(Possession.get_one()['description'], {'foo': 'bar', 'baz': 1}) # Testing an update of a json p['description'] = {'foo': 'baz'} p.flush() self.assertEqual(Possession.get_one()['description'], {'foo': 'baz'}) def test_offset(self): """ Postgres allows offset without limit, but not Sqlite """ Person = self.db['person'] Person['subordinates'] = Person['id'].many(Person['manager_id']) bob = Person(name='Bob').flush() self.assertEqual(list(bob['subordinates'].offset(1)), []) def test_order_by2(self): """ A result set can be refined using order by. A reference can be refined using the same technique. """ Person = self.db['person'] Person['subordinates'] = Person['id'].many(Person['manager_id']) Person['manager'] = Person['id'] == Person['manager_id'] bob = Person(name='Bob').flush() # Insert the employees with IDs that are reverse of the entrydate alice = Person(name='Alice', manager_id=bob['id'], id=3, other=2).flush() dave = Person(name='Dave', manager_id=bob['id'], id=2, other=3).flush() # Ordered by their ID by default self.assertEqualNoRefs(Person.get_where(), [bob, dave, alice]) # Refine the results by ordering by other, which is the reverse of how # they were inserted self.assertEqualNoRefs(bob['subordinates'].order_by('other ASC'), [alice, dave]) self.assertEqualNoRefs(bob['subordinates'], [dave, alice]) steve = Person(name='Steve', manager_id=alice['id'], id=4).flush() self.assertEqualNoRefs(alice['subordinates'], [steve, ]) all_subordinates = Person.get_where(Person['manager_id'].In((1, 3))) self.assertEqual(list(all_subordinates), [dave, alice, steve]) all_subordinates = Person.get_where(Person['manager_id'].In((1, 3))) self.assertEqual(list(all_subordinates.refine(name='Alice')), [alice, ]) def test_second_cursor(self): """ Dict's cursor should not interfere with another cursor. """ Person = self.db['person'] bob = Person(name='Bob').flush() aly = Person(name='Aly').flush() self.assertDictContains(bob, {'name': 'Bob', 'id': 1}) curs2 = self.conn.cursor(cursor_factory=DictCursor) persons = Person.get_where() self.assertEqual(next(persons), bob) curs2.execute('SELECT * FROM person') self.assertEqual(next(persons), aly) # Using dictorm's cursor will intefere persons = Person.get_where() self.assertEqual(next(persons), bob) persons.curs.execute('SELECT * FROM person') self.assertEqual(next(persons), bob) self.assertEqual(next(persons), aly) self.assertRaises(StopIteration, next, persons) def test_varchar(self): """ A varchar type raises an error when too many characters are passed. """ NoPk = self.db['no_pk'] # bar is short enough NoPk(foo='abcdefghij').flush() self.assertRaises(psycopg2.DataError, NoPk(foo='abcdefghijk').flush) def test_any(self): """ "= ANY" functions the same as "IN" for Postgres """ Person = self.db['person'] map(lambda i: Person(name=i).flush(), ['Bob', 'Aly', 'Dave']) self.assertEqual( list(Person.get_where(Person['id'].In([2, 3]))), list(Person.get_where(Person['id'].Any([2, 3]))) ) def test_contains(self): """ A Dict can be matched to the Table it originates from. """ Person, Car = self.db['person'], self.db['car'] steve = Person(name='Steve').flush() steve_car = Car(name='Stratus', person_id=steve['id']).flush() self.assertTrue(steve in Person) self.assertFalse(steve in Car) self.assertFalse(steve_car in Person) self.assertTrue(steve_car in Car) self.assertRaises(ValueError, Person.__contains__, 'foo') def test_arbitrary_get_keywords(self): """ Table.get_one and Table.get_where shouldn't accept arbitrary keywords. """ Person = self.db['person'] self.assertRaises(psycopg2.errors.UndefinedColumn, Person.get_one, foo='bar') self.conn.rollback() try: result = list(Person.get_where(foo='bar')) raise Exception('get_where did not raise UndefinedColumn') except psycopg2.errors.UndefinedColumn as e: pass class TestPostgres12(ExtraTestMethods, unittest.TestCase): def setUp(self): self.conn = psycopg2.connect(**test_db_login) # Change the schema depending on which version of Postgres we're using server_version = str(self.conn.server_version) major_version = server_version[:3] if not 900 >= int(major_version) >= 120: self.skipTest('These tests only apply to Postgres 12+') self.db = dictorm.DictDB(self.conn) self.curs = self.db.curs self.tearDown() self.curs.execute(''' CREATE TABLE person ( id BIGSERIAL PRIMARY KEY, name VARCHAR(100), other INTEGER, manager_id INTEGER REFERENCES person(id) ); CREATE TABLE department ( id SERIAL PRIMARY KEY, name TEXT ); CREATE TABLE person_department ( person_id INTEGER REFERENCES person(id), department_id INTEGER REFERENCES department(id), PRIMARY KEY (person_id, department_id) ); CREATE TABLE car ( id SERIAL PRIMARY KEY, license_plate TEXT, name TEXT, person_id INTEGER REFERENCES person(id), width INTEGER, height INTEGER, area INTEGER GENERATED ALWAYS AS (width * height) STORED ); ALTER TABLE person ADD COLUMN car_id INTEGER REFERENCES car(id); CREATE TABLE no_pk (foo VARCHAR(10)); CREATE TABLE station ( person_id INTEGER ); CREATE TABLE possession ( id SERIAL PRIMARY KEY, person_id INTEGER, description JSONB ); ''') self.conn.commit() self.db.refresh_tables() def tearDown(self): self.conn.rollback() self.curs.execute('''DROP SCHEMA public CASCADE; CREATE SCHEMA public; GRANT ALL ON SCHEMA public TO postgres; GRANT ALL ON SCHEMA public TO public;''') self.conn.commit() def test_generated_columns(self): """ You can't update a generated column. """ Car = self.db['car'] steve_car = Car(name='Stratus').flush() self.assertRaises(dictorm.CannotUpdateColumn, steve_car.__setitem__, 'area', 10) self.assertEqual(steve_car['area'], None) # But the car can be updated normally steve_car['width'] = 3 steve_car['height'] = 4 self.assertEqual(steve_car['area'], None) steve_car.flush() self.assertEqual(steve_car['area'], 12) class SqliteTestBase(object): def setUp(self): self.conn = sqlite3.connect(':memory:') self.db = dictorm.DictDB(self.conn) self.curs = self.db.curs self.tearDown() self.curs.executescript(''' CREATE TABLE person ( id INTEGER PRIMARY KEY, name TEXT, other INTEGER, manager_id INTEGER REFERENCES person(id) ); CREATE TABLE department ( id INTEGER PRIMARY KEY, name TEXT ); CREATE TABLE person_department ( person_id INTEGER REFERENCES person(id), department_id INTEGER REFERENCES department(id), PRIMARY KEY (person_id, department_id) ); CREATE TABLE car ( id INTEGER PRIMARY KEY, license_plate TEXT, name TEXT, person_id INTEGER REFERENCES person(id) ); ALTER TABLE person ADD COLUMN car_id INTEGER REFERENCES car(id); CREATE TABLE no_pk (foo TEXT); CREATE TABLE station ( person_id INTEGER ); CREATE TABLE possession ( id INTEGER PRIMARY KEY, person_id INTEGER, description JSON ); ''') self.conn.commit() self.db.refresh_tables() def tearDown(self): self.conn.rollback() self.curs.execute("""SELECT 'drop table ' || name || ';' FROM sqlite_master WHERE type = 'table';""") self.conn.commit() class TestSqlite(SqliteTestBase, TestPostgresql): def test_get_where(self): Person = self.db['person'] self.assertEqual(0, Person.count()) bob = Person(name='Bob') self.assertEqual({'name': 'Bob'}, bob) bob.flush() self.assertDictContains(bob, {'name': 'Bob', 'id': 1}) self.assertEqual(list(Person.get_where(1)), [bob, ]) # A second flush does not fail bob.flush() self.assertDictContains(bob, {'name': 'Bob', 'id': 1}) self.assertEqual(list(Person.get_where(1)), [bob, ]) bob['name'] = 'Jon' bob.flush() self.assertDictContains(bob, {'name': 'Jon', 'id': 1}) self.assertEqual(list(Person.get_where(1)), [bob, ]) # Items are inserted in the order they are flushed alice = Person(name='Alice') dave = Person(name='Dave') dave.flush() alice.flush() # get_where with a single integer argument should produce a single # Dict row that matches that row's id self.assertEqual(list(Person.get_where(1)), [bob, ]) # get_where with no parameters returns the entire table self.assertEqual(list(Person.get_where()), [bob, dave, alice]) # A delete sql command can be executed on a Dict dave.delete() self.assertEqual(list(Person.get_where()), [bob, alice]) self.conn.commit() self.assertEqual(list(Person.get_where()), [bob, alice]) # Database row survives an object deletion del bob del alice self.conn.commit() self.assertEqual(Person.count(), 2) bob, alice = Person.get_where() bob.delete() alice.delete() self.assertEqual(Person.count(), 0) def test_order_by(self): Person = self.db['person'] bob = Person(name='Bob').flush() aly = Person(name='Aly').flush() wil = Person(name='Wil').flush() self.assertEqual(list(Person.get_where()), [bob, aly, wil]) Person.order_by = 'id asc' self.assertEqual(list(Person.get_where()), [bob, aly, wil]) Person.order_by = 'id desc' self.assertEqual(list(Person.get_where()), [wil, aly, bob]) NoPk = self.db['no_pk'] NoPk(foo='bar').flush() NoPk(foo='baz').flush() self.assertEqual(NoPk.count(), 2) NoPk.order_by = 'foo desc' results = list(NoPk.get_where()) self.assertEqual(len(results), 2) self.assertEqual(results, [{'foo': 'baz'}, {'foo': 'bar'}]) NoPk.order_by = 'foo asc' results = list(NoPk.get_where()) self.assertEqual(len(results), 2) self.assertEqual(results, [{'foo': 'bar'}, {'foo': 'baz'}]) NoPk.order_by = None self.assertEqual(len(list(NoPk.get_where(foo='bar'))), 1) NoPk.order_by = 'foo desc' results = list(NoPk.get_where(foo='bar')) self.assertEqual(len(results), 1) self.assertEqual(results, [{'foo': 'bar'}, ]) def test_raw(self): """ A raw SQL query can be executed using a Table. It expects that the query will select from its table. """ Person = self.db['person'] bob, aly = map(lambda i: Person(name=i).flush(), ['Bob', 'Aly']) persons = Person.get_raw('SELECT * FROM person') self.assertEqual(list(persons), [bob, aly]) persons = Person.get_raw('SELECT * FROM person WHERE id=?', aly['id']) self.assertEqual(list(persons), [aly]) def test_arbitrary_get_keywords(self): """ Table.get_one and Table.get_where shouldn't accept arbitrary keywords. """ Person = self.db['person'] self.assertRaises(sqlite3.OperationalError, Person.get_one, foo='bar') try: result = list(Person.get_where(foo='bar')) raise Exception('get_where did not raise UndefinedColumn') except sqlite3.OperationalError as e: pass # These tests are inherited from Postgres, but they don't function for Sqlite test_any = None test_columns_property = None test_count = None test_ilike = None test_json = None test_offset = None test_order_by2 = None test_second_cursor = None test_varchar = None test_generated_columns = None if __name__ == '__main__': unittest.main()
apache-2.0
[ 3168, 1182, 2647, 15, 1393, 15, 1813, 2366, 199, 646, 11723, 19, 199, 646, 2882, 199, 199, 646, 15492, 18, 199, 504, 15492, 18, 14, 9975, 492, 7448, 8993, 199, 199, 646, 487, 630, 77, 199, 199, 396, 63, 697, 63, 2886, 275, 469, 272, 283, 4659, 356, 283, 10675, 297, 272, 283, 751, 356, 283, 10675, 297, 272, 283, 2060, 356, 283, 328, 630, 77, 297, 272, 283, 1102, 356, 283, 5967, 297, 272, 283, 719, 356, 283, 1477, 12638, 297, 272, 283, 2242, 63, 2593, 356, 650, 12, 199, 93, 421, 199, 318, 485, 889, 63, 7655, 8, 79, 304, 272, 340, 1228, 8, 79, 12, 487, 630, 77, 14, 2141, 304, 267, 372, 312, 14, 889, 63, 7655, 342, 272, 634, 275, 942, 272, 367, 284, 315, 312, 26, 267, 340, 1228, 8, 73, 12, 487, 630, 77, 14, 2141, 304, 288, 634, 14, 740, 8, 73, 14, 889, 63, 7655, 1012, 267, 587, 26, 288, 634, 14, 740, 8, 73, 9, 272, 372, 634, 421, 199, 318, 1125, 2031, 65, 12, 1011, 829, 304, 746, 2186, 342, 421, 199, 533, 11177, 774, 10385, 26, 339, 768, 3744, 272, 347, 702, 2141, 6906, 8, 1886, 12, 366, 17, 12, 366, 18, 304, 267, 4124, 275, 663, 8, 68, 18, 14, 1744, 8801, 9196, 8, 409, 8, 68, 17, 14, 1744, 4059, 267, 340, 4124, 26, 288, 746, 3146, 11117, 16, 93, 1630, 440, 1395, 469, 17, 5285, 908, 8, 68, 17, 12, 4124, 430, 339, 347, 26400, 1944, 25730, 8, 277, 12, 282, 12, 330, 304, 267, 372, 291, 14, 629, 1547, 889, 63, 7655, 8, 65, 395, 485, 889, 63, 7655, 8, 66, 430, 339, 347, 702, 607, 1944, 25730, 8, 277, 12, 282, 12, 330, 304, 267, 372, 291, 14, 4080, 1547, 889, 63, 7655, 8, 65, 395, 485, 889, 63, 7655, 8, 66, 430, 421, 199, 6243, 34, 63, 10640, 275, 469, 272, 283, 29929, 356, 283, 6243, 297, 272, 283, 25, 1644, 356, 283, 6243, 297, 199, 93, 421, 199, 533, 1379, 6564, 7266, 1710, 8, 7426, 774, 10385, 12, 2882, 14, 1746, 304, 272, 408, 272, 5723, 2295, 911, 506, 1255, 367, 1006, 3748, 16219, 14, 272, 408, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 1631, 275, 15492, 18, 14, 2242, 3682, 396, 63, 697, 63, 2886, 9, 398, 327, 7743, 314, 4177, 10298, 641, 1314, 1015, 402, 7711, 7266, 781, 3984, 1808, 267, 1654, 63, 1023, 275, 620, 8, 277, 14, 1631, 14, 1000, 63, 1023, 9, 267, 291, 14, 8452, 63, 1023, 275, 12160, 63, 1023, 275, 1654, 63, 1023, 1491, 19, 61, 398, 291, 14, 697, 275, 487, 630, 77, 14, 2141, 2846, 8, 277, 14, 1631, 9, 267, 291, 14, 17255, 275, 291, 14, 697, 14, 17255, 267, 291, 14, 12336, 342, 267, 291, 14, 17255, 14, 2526, 10505, 267, 16999, 9934, 4954, 334, 288, 1305, 16524, 19637, 19770, 9301, 12, 288, 536, 28490, 8, 1960, 395, 288, 1163, 17086, 12, 288, 5256, 63, 344, 17086, 26901, 22243, 4954, 8, 344, 9, 267, 20682, 267, 16999, 9934, 27669, 334, 288, 1305, 7017, 4938, 19770, 9301, 12, 288, 536, 11951, 267, 20682, 267, 16999, 9934, 4954, 63, 19623, 334, 288, 4954, 63, 344, 17086, 26901, 22243, 4954, 8, 344, 395, 288, 27669, 63, 344, 17086, 26901, 22243, 27669, 8, 344, 395, 288, 19770, 9301, 334, 5484, 63, 344, 12, 27669, 63, 344, 9, 267, 20682, 267, 16999, 9934, 9590, 334, 288, 1305, 7017, 4938, 19770, 9301, 12, 288, 4190, 63, 17673, 11951, 12, 288, 536, 11951, 12, 288, 4954, 63, 344, 17086, 26901, 22243, 4954, 8, 344, 395, 288, 3462, 17086, 12, 288, 4569, 17086, 267, 20682, 267, 12112, 1157, 9934, 4954, 21380, 29955, 9590, 63, 344, 17086, 26901, 22243, 9590, 8, 344, 2736, 267, 16999, 9934, 949, 63, 2051, 334, 1421, 28490, 8, 709, 16674, 267, 16999, 9934, 16518, 334, 288, 4954, 63, 344, 17086, 267, 20682, 267, 16999, 9934, 2086, 1730, 334, 288, 1305, 7017, 4938, 19770, 9301, 12, 288, 4954, 63, 344, 17086, 12, 288, 1369, 469, 6243, 63, 726, 63, 6243, 34, 93, 267, 20682, 267, 1449, 14, 908, 8, 6243, 63, 726, 63, 6243, 34, 29, 6243, 34, 63, 10640, 14, 362, 8, 8452, 63, 1023, 12, 283, 6243, 34, 7058, 267, 291, 14, 1631, 14, 3543, 342, 267, 291, 14, 697, 14, 6635, 63, 5987, 342, 339, 347, 6766, 8, 277, 304, 267, 291, 14, 1631, 14, 10437, 342, 267, 291, 14, 17255, 14, 2526, 10505, 14764, 428, 10364, 4575, 27751, 9947, 27, 355, 16999, 428, 10364, 4575, 27, 355, 21772, 1441, 11727, 5258, 428, 10364, 4575, 2296, 19533, 27, 355, 21772, 1441, 11727, 5258, 428, 10364, 4575, 2296, 4575, 27, 12310, 267, 291, 14, 1631, 14, 3543, 342, 339, 347, 511, 63, 362, 63, 4509, 8, 277, 304, 267, 8028, 275, 291, 14, 697, 459, 5484, 418, 267, 291, 14, 629, 8, 16, 12, 8028, 14, 835, 1012, 398, 26961, 275, 8028, 8, 354, 534, 22593, 358, 267, 291, 14, 629, 3252, 354, 356, 283, 22593, 2267, 26961, 9, 267, 26961, 14, 4939, 342, 267, 291, 14, 16443, 6906, 8, 7913, 12, 791, 354, 356, 283, 22593, 297, 283, 344, 356, 413, 1552, 267, 291, 14, 629, 8, 513, 8, 7344, 14, 362, 63, 4509, 8, 17, 1826, 359, 7913, 12, 4794, 398, 327, 437, 3499, 8976, 1630, 440, 2449, 267, 26961, 14, 4939, 342, 267, 291, 14, 16443, 6906, 8, 7913, 12, 791, 354, 356, 283, 22593, 297, 283, 344, 356, 413, 1552, 267, 291, 14, 629, 8, 513, 8, 7344, 14, 362, 63, 4509, 8, 17, 1826, 359, 7913, 12, 4794, 398, 26961, 459, 354, 418, 275, 283, 42, 265, 7, 267, 26961, 14, 4939, 342, 267, 291, 14, 16443, 6906, 8, 7913, 12, 791, 354, 356, 283, 42, 265, 297, 283, 344, 356, 413, 1552, 267, 291, 14, 629, 8, 513, 8, 7344, 14, 362, 63, 4509, 8, 17, 1826, 359, 7913, 12, 4794, 398, 327, 20720, 787, 11788, 315, 314, 1865, 2985, 787, 8976, 379, 267, 741, 1885, 275, 8028, 8, 354, 534, 28001, 358, 267, 366, 811, 275, 8028, 8, 354, 534, 36, 811, 358, 267, 366, 811, 14 ]
[ 1182, 2647, 15, 1393, 15, 1813, 2366, 199, 646, 11723, 19, 199, 646, 2882, 199, 199, 646, 15492, 18, 199, 504, 15492, 18, 14, 9975, 492, 7448, 8993, 199, 199, 646, 487, 630, 77, 199, 199, 396, 63, 697, 63, 2886, 275, 469, 272, 283, 4659, 356, 283, 10675, 297, 272, 283, 751, 356, 283, 10675, 297, 272, 283, 2060, 356, 283, 328, 630, 77, 297, 272, 283, 1102, 356, 283, 5967, 297, 272, 283, 719, 356, 283, 1477, 12638, 297, 272, 283, 2242, 63, 2593, 356, 650, 12, 199, 93, 421, 199, 318, 485, 889, 63, 7655, 8, 79, 304, 272, 340, 1228, 8, 79, 12, 487, 630, 77, 14, 2141, 304, 267, 372, 312, 14, 889, 63, 7655, 342, 272, 634, 275, 942, 272, 367, 284, 315, 312, 26, 267, 340, 1228, 8, 73, 12, 487, 630, 77, 14, 2141, 304, 288, 634, 14, 740, 8, 73, 14, 889, 63, 7655, 1012, 267, 587, 26, 288, 634, 14, 740, 8, 73, 9, 272, 372, 634, 421, 199, 318, 1125, 2031, 65, 12, 1011, 829, 304, 746, 2186, 342, 421, 199, 533, 11177, 774, 10385, 26, 339, 768, 3744, 272, 347, 702, 2141, 6906, 8, 1886, 12, 366, 17, 12, 366, 18, 304, 267, 4124, 275, 663, 8, 68, 18, 14, 1744, 8801, 9196, 8, 409, 8, 68, 17, 14, 1744, 4059, 267, 340, 4124, 26, 288, 746, 3146, 11117, 16, 93, 1630, 440, 1395, 469, 17, 5285, 908, 8, 68, 17, 12, 4124, 430, 339, 347, 26400, 1944, 25730, 8, 277, 12, 282, 12, 330, 304, 267, 372, 291, 14, 629, 1547, 889, 63, 7655, 8, 65, 395, 485, 889, 63, 7655, 8, 66, 430, 339, 347, 702, 607, 1944, 25730, 8, 277, 12, 282, 12, 330, 304, 267, 372, 291, 14, 4080, 1547, 889, 63, 7655, 8, 65, 395, 485, 889, 63, 7655, 8, 66, 430, 421, 199, 6243, 34, 63, 10640, 275, 469, 272, 283, 29929, 356, 283, 6243, 297, 272, 283, 25, 1644, 356, 283, 6243, 297, 199, 93, 421, 199, 533, 1379, 6564, 7266, 1710, 8, 7426, 774, 10385, 12, 2882, 14, 1746, 304, 272, 408, 272, 5723, 2295, 911, 506, 1255, 367, 1006, 3748, 16219, 14, 272, 408, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 1631, 275, 15492, 18, 14, 2242, 3682, 396, 63, 697, 63, 2886, 9, 398, 327, 7743, 314, 4177, 10298, 641, 1314, 1015, 402, 7711, 7266, 781, 3984, 1808, 267, 1654, 63, 1023, 275, 620, 8, 277, 14, 1631, 14, 1000, 63, 1023, 9, 267, 291, 14, 8452, 63, 1023, 275, 12160, 63, 1023, 275, 1654, 63, 1023, 1491, 19, 61, 398, 291, 14, 697, 275, 487, 630, 77, 14, 2141, 2846, 8, 277, 14, 1631, 9, 267, 291, 14, 17255, 275, 291, 14, 697, 14, 17255, 267, 291, 14, 12336, 342, 267, 291, 14, 17255, 14, 2526, 10505, 267, 16999, 9934, 4954, 334, 288, 1305, 16524, 19637, 19770, 9301, 12, 288, 536, 28490, 8, 1960, 395, 288, 1163, 17086, 12, 288, 5256, 63, 344, 17086, 26901, 22243, 4954, 8, 344, 9, 267, 20682, 267, 16999, 9934, 27669, 334, 288, 1305, 7017, 4938, 19770, 9301, 12, 288, 536, 11951, 267, 20682, 267, 16999, 9934, 4954, 63, 19623, 334, 288, 4954, 63, 344, 17086, 26901, 22243, 4954, 8, 344, 395, 288, 27669, 63, 344, 17086, 26901, 22243, 27669, 8, 344, 395, 288, 19770, 9301, 334, 5484, 63, 344, 12, 27669, 63, 344, 9, 267, 20682, 267, 16999, 9934, 9590, 334, 288, 1305, 7017, 4938, 19770, 9301, 12, 288, 4190, 63, 17673, 11951, 12, 288, 536, 11951, 12, 288, 4954, 63, 344, 17086, 26901, 22243, 4954, 8, 344, 395, 288, 3462, 17086, 12, 288, 4569, 17086, 267, 20682, 267, 12112, 1157, 9934, 4954, 21380, 29955, 9590, 63, 344, 17086, 26901, 22243, 9590, 8, 344, 2736, 267, 16999, 9934, 949, 63, 2051, 334, 1421, 28490, 8, 709, 16674, 267, 16999, 9934, 16518, 334, 288, 4954, 63, 344, 17086, 267, 20682, 267, 16999, 9934, 2086, 1730, 334, 288, 1305, 7017, 4938, 19770, 9301, 12, 288, 4954, 63, 344, 17086, 12, 288, 1369, 469, 6243, 63, 726, 63, 6243, 34, 93, 267, 20682, 267, 1449, 14, 908, 8, 6243, 63, 726, 63, 6243, 34, 29, 6243, 34, 63, 10640, 14, 362, 8, 8452, 63, 1023, 12, 283, 6243, 34, 7058, 267, 291, 14, 1631, 14, 3543, 342, 267, 291, 14, 697, 14, 6635, 63, 5987, 342, 339, 347, 6766, 8, 277, 304, 267, 291, 14, 1631, 14, 10437, 342, 267, 291, 14, 17255, 14, 2526, 10505, 14764, 428, 10364, 4575, 27751, 9947, 27, 355, 16999, 428, 10364, 4575, 27, 355, 21772, 1441, 11727, 5258, 428, 10364, 4575, 2296, 19533, 27, 355, 21772, 1441, 11727, 5258, 428, 10364, 4575, 2296, 4575, 27, 12310, 267, 291, 14, 1631, 14, 3543, 342, 339, 347, 511, 63, 362, 63, 4509, 8, 277, 304, 267, 8028, 275, 291, 14, 697, 459, 5484, 418, 267, 291, 14, 629, 8, 16, 12, 8028, 14, 835, 1012, 398, 26961, 275, 8028, 8, 354, 534, 22593, 358, 267, 291, 14, 629, 3252, 354, 356, 283, 22593, 2267, 26961, 9, 267, 26961, 14, 4939, 342, 267, 291, 14, 16443, 6906, 8, 7913, 12, 791, 354, 356, 283, 22593, 297, 283, 344, 356, 413, 1552, 267, 291, 14, 629, 8, 513, 8, 7344, 14, 362, 63, 4509, 8, 17, 1826, 359, 7913, 12, 4794, 398, 327, 437, 3499, 8976, 1630, 440, 2449, 267, 26961, 14, 4939, 342, 267, 291, 14, 16443, 6906, 8, 7913, 12, 791, 354, 356, 283, 22593, 297, 283, 344, 356, 413, 1552, 267, 291, 14, 629, 8, 513, 8, 7344, 14, 362, 63, 4509, 8, 17, 1826, 359, 7913, 12, 4794, 398, 26961, 459, 354, 418, 275, 283, 42, 265, 7, 267, 26961, 14, 4939, 342, 267, 291, 14, 16443, 6906, 8, 7913, 12, 791, 354, 356, 283, 42, 265, 297, 283, 344, 356, 413, 1552, 267, 291, 14, 629, 8, 513, 8, 7344, 14, 362, 63, 4509, 8, 17, 1826, 359, 7913, 12, 4794, 398, 327, 20720, 787, 11788, 315, 314, 1865, 2985, 787, 8976, 379, 267, 741, 1885, 275, 8028, 8, 354, 534, 28001, 358, 267, 366, 811, 275, 8028, 8, 354, 534, 36, 811, 358, 267, 366, 811, 14, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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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 ]
palaniyappanBala/thug
src/Analysis/peepdf/PDFCore.py
17
334169
# # peepdf is a tool to analyse and modify PDF files # http://peepdf.eternal-todo.com # By Jose Miguel Esparza <jesparza AT eternal-todo.com> # # Copyright (C) 2011-2014 Jose Miguel Esparza # # This file is part of peepdf. # # peepdf 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. # # peepdf 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 peepdf. If not, see <http://www.gnu.org/licenses/>. # ''' This module contains classes and methods to analyse and modify PDF files ''' import sys,os,re,hashlib,struct,aes as AES from PDFUtils import * from PDFCrypto import * from JSAnalysis import * from PDFFilters import decodeStream,encodeStream MAL_ALL = 1 MAL_HEAD = 2 MAL_EOBJ = 3 MAL_ESTREAM = 4 MAL_XREF = 5 MAL_BAD_HEAD = 6 pdfFile = None newLine = os.linesep isForceMode = False isManualAnalysis = False spacesChars = ['\x00','\x09','\x0a','\x0c','\x0d','\x20'] delimiterChars = ['<<','(','<','[','{','/','%'] monitorizedEvents = ['/OpenAction ','/AA ','/Names ','/AcroForm ', '/XFA '] monitorizedActions = ['/JS ','/JavaScript','/Launch','/SubmitForm','/ImportData'] monitorizedElements = ['/EmbeddedFiles ', '/EmbeddedFile', '/JBIG2Decode', 'getPageNthWord', 'arguments.callee', '/U3D', '/PRC', '/RichMedia', '.rawValue', 'keep.previous'] jsVulns = ['mailto', 'Collab.collectEmailInfo', 'util.printf', 'getAnnots', 'getIcon', 'spell.customDictionaryOpen', 'media.newPlayer', 'doc.printSeps', 'app.removeToolButton'] singUniqueName = 'CoolType.SING.uniqueName' bmpVuln = 'BMP/RLE heap corruption' vulnsDict = {'mailto':('mailto',['CVE-2007-5020']), 'Collab.collectEmailInfo':('Collab.collectEmailInfo',['CVE-2007-5659']), 'util.printf':('util.printf',['CVE-2008-2992']), '/JBIG2Decode':('Adobe JBIG2Decode Heap Corruption',['CVE-2009-0658']), 'getIcon':('getIcon',['CVE-2009-0927']), 'getAnnots':('getAnnots',['CVE-2009-1492']), 'spell.customDictionaryOpen':('spell.customDictionaryOpen',['CVE-2009-1493']), 'media.newPlayer':('media.newPlayer',['CVE-2009-4324']), '.rawValue':('Adobe Acrobat Bundled LibTIFF Integer Overflow',['CVE-2010-0188']), singUniqueName:(singUniqueName,['CVE-2010-2883']), 'doc.printSeps':('doc.printSeps',['CVE-2010-4091']), '/U3D':('/U3D',['CVE-2009-3953','CVE-2009-3959','CVE-2011-2462']), '/PRC':('/PRC',['CVE-2011-4369']), 'keep.previous':('Adobe Reader XFA oneOfChild Un-initialized memory vulnerability',['CVE-2013-0640']), # https://labs.portcullis.co.uk/blog/cve-2013-0640-adobe-reader-xfa-oneofchild-un-initialized-memory-vulnerability-part-1/ bmpVuln:(bmpVuln,['CVE-2013-2729']), 'app.removeToolButton':('app.removeToolButton',['CVE-2013-3346'])} jsContexts = {'global':None} class PDFObject : ''' Base class for all the PDF objects ''' def __init__(self, raw = None): ''' Constructor of a PDFObject @param raw: The raw value of the PDF object ''' self.references = [] self.type = '' self.value = '' self.rawValue = raw self.JSCode = [] self.updateNeeded = False self.containsJScode = False self.encryptedValue = raw self.encryptionKey = '' self.encrypted = False self.errors = [] self.referencesInElements = {} self.compressedIn = None def addError(self, errorMessage): ''' Add an error to the object @param errorMessage: The error message to be added (string) ''' if errorMessage not in self.errors: self.errors.append(errorMessage) def contains(self, string): ''' Look for the string inside the object content @param string: A string @return: A boolean to specify if the string has been found or not ''' value = str(self.value) rawValue = str(self.rawValue) encValue = str(self.encryptedValue) if re.findall(string,value,re.IGNORECASE) != [] or re.findall(string,rawValue,re.IGNORECASE) != [] or re.findall(string,encValue,re.IGNORECASE) != []: return True if self.containsJS(): for js in self.JSCode: if re.findall(string,js,re.IGNORECASE) != []: return True return False def containsJS(self): ''' Method to check if there are Javascript code inside the object @return: A boolean ''' return self.containsJScode def encodeChars(self): ''' Encode the content of the object if possible (only for PDFName, PDFString, PDFArray and PDFStreams) @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' return (0,'') def encrypt(self, password): ''' Encrypt the content of the object if possible @param password: The password used to encrypt the object. It's dependent on the object. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' return (0,'') def getCompressedIn(self): ''' Gets the id of the object (object stream) where the actual object is compressed @return: The id (int) of the object stream or None if it's not compressed ''' return self.compressedIn def getEncryptedValue(self): ''' Gets the encrypted value of the object @return: The encrypted value or the raw value if the object is not encrypted ''' return self.encryptedValue def getEncryptionKey(self): ''' Gets the encryption key (password) used to encrypt the object @return: The password (string) or an empty string if it's not encrypted ''' return self.encryptionKey def getErrors(self): ''' Gets the error messages found while parsing and processing the object @return: The array of errors of the object ''' return self.errors def getRawValue(self): ''' Gets the raw value of the object @return: The raw value of the object, this means without applying filters or decoding characters ''' return self.rawValue def getReferences(self): ''' Gets the referenced objects in the actual object @return: An array of references in the object (Ex. ['1 0 R','12 0 R']) ''' return self.references def getReferencesInElements(self): ''' Gets the dependencies between elements in the object and objects in the rest of the document. @return: A dictionary of dependencies of the object (Ex. {'/Length':[5,'']} or {'/Length':[5,'354']}) ''' return self.referencesInElements def getStats(self): ''' Gets the statistics of the object @return: An array of different statistics of the object (object type, compression, references, etc) ''' stats = {} stats['Object'] = self.type stats['MD5'] = hashlib.md5(self.value).hexdigest() stats['SHA1'] = hashlib.sha1(self.value).hexdigest() if self.isCompressed(): stats['Compressed in'] = str(self.compressedIn) else: stats['Compressed in'] = None stats['References'] = str(self.references) if self.containsJScode: stats['JSCode'] = True if len(self.unescapedBytes) > 0: stats['Escaped Bytes'] = True else: stats['Escaped Bytes'] = False if len(self.urlsFound) > 0: stats['URLs'] = True else: stats['URLs'] = False else: stats['JSCode'] = False if self.isFaulty(): stats['Errors'] = str(len(self.errors)) else: stats['Errors'] = None return stats def getType(self): ''' Gets the type of the object @return: The object type (bool, null, real, integer, name, string, hexstring, reference, array, dictionary, stream) ''' return self.type def getValue(self): ''' Gets the value of the object @return: The value of the object, this means after applying filters and/or decoding characters and strings ''' return self.value def isCompressed(self): ''' Specifies if the object is compressed or not @return: A boolean ''' if self.compressedIn != None: return True else: return False def isEncrypted(self): ''' Specifies if the object is encrypted or not @return: A boolean ''' return self.encrypted def isFaulty(self): ''' Specifies if the object has errors or not @return: A boolean ''' if self.errors == []: return False else: return True def replace(self, string1, string2): ''' Searches the object for the 'string1' and if it's found it's replaced by 'string2' @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' if self.value.find(string1) == -1 and self.rawValue.find(string1) == -1: return (-1,'String not found') self.value = self.value.replace(string1, string2) self.rawValue = self.rawValue.replace(string1, string2) ret = self.update() return ret def resolveReferences(self): ''' Replaces the reference to an object by its value if there are references not resolved. Ex. /Length 3 0 R @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' pass def setCompressedIn(self, id): ''' Sets the object id of the object stream containing the actual object @param id: The object id (int) ''' self.compressedIn = id def setEncryptedValue(self, value): ''' Sets the encrypted value of the object @param value: The encrypted value (string) ''' self.encryptedValue = value def setEncryptionKey(self, password): ''' Sets the password to encrypt/decrypt the object @param password: The encryption key (string) ''' self.encryptionKey = password def setRawValue(self, newRawValue): ''' Sets the raw value of the object and updates the object if some modification is needed @param newRawValue: The new raw value (string) @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.rawValue = newRawValue ret = self.update() return ret def setReferencesInElements(self, resolvedReferencesDict): ''' Sets the resolved references array @param resolvedReferencesDict: A dictionary with the resolved references ''' self.referencesInElements = resolvedReferencesDict def setValue(self, newValue): ''' Sets the value of the object @param newValue: The new value of the object (string) ''' self.value = newValue def update(self): ''' Updates the object after some modification has occurred @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.encryptedValue = self.rawValue return (0,'') def toFile(self): ''' Gets the raw or encrypted value of the object to write it to an output file @return: The raw/encrypted value of the object (string) ''' if self.encrypted: return self.getEncryptedValue() else: return self.getRawValue() class PDFBool (PDFObject) : ''' Boolean object of a PDF document ''' def __init__(self, value) : self.type = 'bool' self.errors = [] self.references = [] self.JSCode = [] self.encrypted = False self.updateNeeded = False self.containsJScode = False self.referencesInElements = {} self.value = self.rawValue = self.encryptedValue = value self.compressedIn = None class PDFNull (PDFObject) : ''' Null object of a PDF document ''' def __init__(self, content) : self.type = 'null' self.errors = [] self.JSCode = [] self.compressedIn = None self.encrypted = False self.value = self.rawValue = self.encryptedValue = content self.updateNeeded = False self.containsJScode = False self.referencesInElements = {} self.references = [] class PDFNum (PDFObject) : ''' Number object of a PDF document: can be an integer or a real number. ''' def __init__(self, num) : self.errors = [] self.JSCode = [] self.compressedIn = None self.encrypted = False self.value = num self.compressedIn = None self.updateNeeded = False self.containsJScode = False self.referencesInElements = {} self.references = [] ret = self.update() if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) def replace(self, string1, string2): if self.value.find(string1) == -1: return (-1,'String not found') self.value = self.value.replace(string1, string2) ret = self.update() return ret def update(self): self.errors = [] try: if self.value.find('.') != -1: self.type = 'real' self.rawValue = float(self.value) else: self.type = 'integer' self.rawValue = int(self.value) except: errorMessage = 'Numeric conversion error' self.addError(errorMessage) return (-1,errorMessage) self.encryptedValue = str(self.rawValue) return (0,'') def setRawValue(self, rawValue): self.rawValue = rawValue def setValue(self, value): self.value = value ret = self.update() return ret def toFile(self): return str(self.rawValue) class PDFName (PDFObject) : ''' Name object of a PDF document ''' def __init__(self, name) : self.type = 'name' self.errors = [] self.JSCode = [] self.references = [] self.compressedIn = None if name[0] == '/': self.rawValue = self.value = self.encryptedValue = name else: self.rawValue = self.value = self.encryptedValue = '/' + name self.updateNeeded = False self.containsJScode = False self.encryptedValue = '' self.encrypted = False self.referencesInElements = {} ret = self.update() if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) def update(self): self.errors = [] errorMessage = '' self.value = self.rawValue self.encryptedValue = self.rawValue hexNumbers = re.findall('#([0-9a-f]{2})', self.value, re.DOTALL | re.IGNORECASE) try: for hexNumber in hexNumbers: self.value = self.value.replace('#' + hexNumber, chr(int(hexNumber,16))) except: errorMessage = 'Error in hexadecimal conversion' self.addError(errorMessage) return (-1,errorMessage) return (0,'') def encodeChars(self): ret = encodeName(self.value) if ret[0] == -1: self.addError(ret[1]) return ret else: self.rawValue = ret[1] return (0,'') class PDFString (PDFObject) : ''' String object of a PDF document ''' def __init__(self, string) : self.type = 'string' self.errors = [] self.compressedIn = None self.encrypted = False self.value = self.rawValue = self.encryptedValue = string self.updateNeeded = False self.containsJScode = False self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] self.references = [] self.referencesInElements = {} ret = self.update() if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) def update(self, decrypt = False): ''' Updates the object after some modification has occurred @param decrypt: A boolean indicating if a decryption has been performed. By default: False. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.errors = [] self.containsJScode = False self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] self.rawValue = unescapeString(self.rawValue) self.value = self.rawValue ''' self.value = self.value.replace('\)',')') self.value = self.value.replace('\\\\','\\') self.value = self.value.replace('\\\r\\\n','') self.value = self.value.replace('\\\r','') self.value = self.value.replace('\\\n','') ''' octalNumbers = re.findall('\\\\([0-7]{1,3})', self.value, re.DOTALL) try: for octal in octalNumbers: #TODO: check!! \\\\? self.value = self.value.replace('\\' + octal, chr(int(octal,8))) except: errorMessage = 'Error in octal conversion' self.addError(errorMessage) return (-1,errorMessage) if isJavascript(self.value): self.containsJScode = True self.JSCode, self.unescapedBytes, self.urlsFound, jsErrors, jsContexts['global'] = analyseJS(self.value, jsContexts['global'], isManualAnalysis) if jsErrors != []: for jsError in jsErrors: errorMessage = 'Error analysing Javascript: '+jsError if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if self.encrypted and not decrypt: ret = self.encrypt() if ret[0] == -1: return ret return (0,'') def encodeChars(self): ret = encodeString(self.value) if ret[0] == -1: self.addError(ret[1]) return ret else: self.rawValue = ret[1] return (0,'') def encrypt(self, password = None): self.encrypted = True if password != None: self.encryptionKey = password try: self.encryptedValue = RC4(self.rawValue,self.encryptionKey) except: errorMessage = 'Error encrypting with RC4' self.addError(errorMessage) return (-1,errorMessage) return (0,'') def decrypt(self, password = None, algorithm = 'RC4'): ''' Decrypt the content of the object if possible @param password: The password used to decrypt the object. It's dependent on the object. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.encrypted = True if password != None: self.encryptionKey = password try: cleanString = unescapeString(self.encryptedValue) if algorithm == 'RC4': self.rawValue = RC4(cleanString,self.encryptionKey) elif algorithm == 'AES': ret = AES.decryptData(cleanString,self.encryptionKey) if ret[0] != -1: self.rawValue = ret[1] else: errorMessage = 'AES decryption error: '+ret[1] self.addError(errorMessage) return (-1,errorMessage) except: errorMessage = 'Error decrypting with '+str(algorithm) self.addError(errorMessage) return (-1,errorMessage) ret = self.update(decrypt = True) return (0,'') def getEncryptedValue(self): return '('+escapeString(self.encryptedValue)+')' def getJSCode(self): ''' Gets the Javascript code of the object @return: An array of Javascript code sections ''' return self.JSCode def getRawValue(self): return '('+escapeString(self.rawValue)+')' def getUnescapedBytes(self): ''' Gets the escaped bytes of the object unescaped @return: An array of unescaped bytes (string) ''' return self.unescapedBytes def getURLs(self): ''' Gets the URLs of the object @return: An array of URLs ''' return self.urlsFound class PDFHexString (PDFObject) : ''' Hexadecimal string object of a PDF document ''' def __init__(self, hex) : self.asciiValue = '' self.type = 'hexstring' self.errors = [] self.compressedIn = None self.encrypted = False self.value = '' # Value after hex decoding and decryption self.rawValue = hex # Hex characters self.encryptedValue = hex # Value after hex decoding self.updateNeeded = False self.containsJScode = False self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] self.referencesInElements = {} self.references = [] ret = self.update() if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) def update(self, decrypt = False, newHexValue = True): ''' Updates the object after some modification has occurred @param decrypt: A boolean indicating if a decryption has been performed. By default: False. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.errors = [] self.containsJScode = False self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] if not decrypt: try: if newHexValue: # New hexadecimal value self.value = '' tmpValue = self.rawValue if len(tmpValue) % 2 != 0: tmpValue += '0' self.value = tmpValue.decode('hex') else: # New decoded value self.rawValue = self.value.encode('hex') self.encryptedValue = self.value except: errorMessage = 'Error in hexadecimal conversion' self.addError(errorMessage) return (-1,errorMessage) if isJavascript(self.value): self.containsJScode = True self.JSCode, self.unescapedBytes, self.urlsFound, jsErrors, jsContexts['global'] = analyseJS(self.value, jsContexts['global'], isManualAnalysis) if jsErrors != []: for jsError in jsErrors: errorMessage = 'Error analysing Javascript: '+jsError if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if self.encrypted and not decrypt: ret = self.encrypt() if ret[0] == -1: return ret return (0,'') def encrypt(self, password = None): self.encrypted = True if password != None: self.encryptionKey = password try: self.encryptedValue = RC4(self.value,self.encryptionKey) self.rawValue = self.encryptedValue.encode('hex') except: errorMessage = 'Error encrypting with RC4' self.addError(errorMessage) return (-1,errorMessage) return (0,'') def decrypt(self, password = None, algorithm = 'RC4'): ''' Decrypt the content of the object if possible @param password: The password used to decrypt the object. It's dependent on the object. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.encrypted = True if password != None: self.encryptionKey = password try: cleanString = unescapeString(self.encryptedValue) if algorithm == 'RC4': self.value = RC4(cleanString,self.encryptionKey) elif algorithm == 'AES': ret = AES.decryptData(cleanString,self.encryptionKey) if ret[0] != -1: self.value = ret[1] else: errorMessage = 'AES decryption error: '+ret[1] self.addError(errorMessage) return (-1,errorMessage) except: errorMessage = 'Error decrypting with '+str(algorithm) self.addError(errorMessage) return (-1,errorMessage) ret = self.update(decrypt = True) return ret def getEncryptedValue(self): return '<'+self.rawValue+'>' def getJSCode(self): ''' Gets the Javascript code of the object @return: An array of Javascript code sections ''' return self.JSCode def getRawValue(self): return '<'+self.rawValue+'>' def getUnescapedBytes(self): ''' Gets the escaped bytes of the object unescaped @return: An array of unescaped bytes (string) ''' return self.unescapedBytes def getURLs(self): ''' Gets the URLs of the object @return: An array of URLs ''' return self.urlsFound class PDFReference (PDFObject) : ''' Reference object of a PDF document ''' def __init__(self, id, genNumber = '0') : self.type = 'reference' self.errors = [] self.JSCode = [] self.compressedIn = None self.encrypted = False self.value = self.rawValue = self.encryptedValue = id + ' ' + genNumber + ' R' self.id = id self.genNumber = genNumber self.updateNeeded = False self.containsJScode = False self.referencesInElements = {} self.references = [] ret = self.update() if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) def update(self): self.errors = [] self.value = self.encryptedValue = self.rawValue valueElements = self.rawValue.split() if valueElements != []: self.id = int(valueElements[0]) self.genNumber = int(valueElements[1]) else: errorMessage = 'Error getting PDFReference elements' self.addError(errorMessage) return (-1,errorMessage) return (0,'') def getGenNumber(self): ''' Gets the generation number of the reference @return: The generation number (int) ''' return self.genNumber def getId(self): ''' Gets the object id of the reference @return: The object id (int) ''' return self.id def setGenNumber(self, newGenNumber): ''' Sets the generation number of the reference @param newGenNumber: The new generation number (int) ''' self.genNumber = newGenNumber def setId(self, newId): ''' Sets the object id of the reference @param newId: The new object id (int) ''' self.id = newId class PDFArray (PDFObject) : ''' Array object of a PDF document ''' def __init__(self, rawContent = '', elements = []) : self.type = 'array' self.errors = [] self.JSCode = [] self.compressedIn = None self.encrypted = False self.encryptedValue = rawContent self.rawValue = rawContent self.elements = elements self.value = '' self.updateNeeded = False self.containsJScode = False self.referencesInElements = {} self.references = [] ret = self.update() if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) def update(self, decrypt = False): ''' Updates the object after some modification has occurred @param decrypt: A boolean indicating if a decryption has been performed. By default: False. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' errorMessage = '' self.errors = [] self.encryptedValue = '[ ' self.rawValue = '[ ' self.value = '[ ' self.references = [] self.containsJScode = False self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] for element in self.elements: if element != None: type = element.getType() if type == 'reference': self.references.append(element.getValue()) elif type == 'dictionary' or type == 'array': self.references += element.getReferences() if element.containsJS(): self.containsJScode = True self.JSCode += element.getJSCode() self.unescapedBytes += element.getUnescapedBytes() self.urlsFound += element.getURLs() if element.isFaulty(): for error in valueObject.getErrors(): self.addError('Children element contains errors: ' + error) if type in ['string','hexstring','array','dictionary'] and self.encrypted and not decrypt: ret = element.encrypt(self.encryptionKey) if ret[0] == -1: errorMessage = 'Error encrypting element' self.addError(errorMessage) self.encryptedValue += str(element.getEncryptedValue()) + ' ' self.rawValue += str(element.getRawValue()) + ' ' self.value += element.getValue() + ' ' else: errorMessage = 'None elements' self.addError(errorMessage) self.encryptedValue = self.encryptedValue[:-1] + ' ]' self.rawValue = self.rawValue[:-1] + ' ]' self.value = self.value[:-1] + ' ]' if errorMessage != '': return (-1,'Errors while updating PDFArray') else: return (0,'') def addElement(self, element): ''' Adds an element to the array @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.elements.append(element) ret = self.update() return ret def decrypt(self, password = None, algorithm = 'RC4'): ''' Decrypt the content of the object if possible @param password: The password used to decrypt the object. It's dependent on the object. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' errorMessage = '' self.encrypted = True if password != None: self.encryptionKey = password decryptedElements = [] for element in self.elements: if element != None: type = element.getType() if type in ['string','hexstring','array','dictionary']: ret = element.decrypt(self.encryptionKey, algorithm) if ret[0] == -1: errorMessage = ret[1] self.addError(errorMessage) decryptedElements.append(element) self.elements = decryptedElements ret = self.update(decrypt = True) if ret[0] == 0 and errorMessage != '': return (-1,errorMessage) return ret def encodeChars(self): errorMessage = '' encodedElements = [] for element in self.elements: if element != None: type = element.getType() if type in ['string','name','array','dictionary']: ret = element.encodeChars() if ret[0] == -1: errorMessage = ret[1] self.addError(errorMessage) encodedElements.append(element) self.elements = encodedElements ret = self.update() if ret[0] == 0 and errorMessage != '': return (-1,errorMessage) return ret def encrypt(self, password = None): self.encrypted = True if password != None: self.encryptionKey = password ret = self.update() return ret def getElementByName(self, name): ''' Gets the dictionary elements with the given name @param name: The name @return: An array of elements ''' retElements = [] for element in self.elements: if element != None: if element.getType() == 'dictionary' or element.getType() == 'array': retElements += element.getElementByName(name) else: errorMessage = 'None elements' self.addError(errorMessage) return retElements def getElementRawValues(self): ''' Gets the raw values of each element @return: An array of values ''' values = [] for element in self.elements: if element != None: values.append(element.getRawValue()) else: values.append(None) errorMessage = 'None elements' self.addError(errorMessage) return values def getElementValues(self): ''' Gets the values of each element @return: An array of values ''' values = [] for element in self.elements: if element != None: values.append(element.getValue()) else: values.append(None) errorMessage = 'None elements' self.addError(errorMessage) return values def getElements(self): ''' Gets the elements of the array object @return: An array of PDFObject elements ''' return self.elements def getNumElements(self): ''' Gets the number of elements of the array @return: The number of elements (int) ''' return len(self.elements) def hasElement(self, name): ''' Specifies if the array contains the element with the given name @param name: The element @return: A boolean ''' for element in self.elements: if element != None: if element.getType() == 'dictionary': if element.hasElement(name): return True elif element.getValue() == name: return True else: errorMessage = 'None elements' self.addError(errorMessage) else: return False def replace(self, string1, string2): errorMessage = '' stringFound = False newElements = [] if self.rawValue.find(string1) != -1: self.rawValue = self.rawValue.replace(string1, string2) stringFound = True if errorMessage == 'String not found': errorMessage = '' for element in self.elements: if element != None: ret = element.replace(string1, string2) if ret[0] == -1: if ret[1] != 'String not found' or not stringFound: errorMessage = ret[1] else: stringFound = True if errorMessage == 'String not found': errorMessage = '' newElements.append(element) else: errorMessage = 'None element while replacing strings' self.addError('None element') if not stringFound: return (-1,'String not found') self.elements = newElements ret = self.update() if ret[0] == 0 and errorMessage != '': return (-1,errorMessage) return ret def setElements(self, newElements): ''' Sets the array of elements @param newElements: The new array of elements @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.elements = newElements ret = self.update() return ret class PDFDictionary (PDFObject): def __init__(self, rawContent = '', elements = {}, rawNames = {}) : self.type = 'dictionary' self.dictType = '' self.errors = [] self.compressedIn = None self.encrypted = False self.value = '' self.updateNeeded = False self.containsJScode = False self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] self.referencesInElements = {} self.rawValue = rawContent self.encryptedValue = rawContent self.rawNames = rawNames self.elements = elements self.numElements = len(self.elements) self.references = [] ret = self.update() if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) def update(self, decrypt = False): ''' Updates the object after some modification has occurred @param decrypt: A boolean indicating if a decryption has been performed. By default: False. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.errors = [] self.references = [] self.containsJScode = False self.JSCode = [] self.dictType = '' self.unescapedBytes = [] self.urlsFound = [] errorMessage = '' self.value = '<< ' self.rawValue = '<< ' self.encryptedValue = '<< ' keys = self.elements.keys() values = self.elements.values() for i in range(len(keys)): if values[i] == None: errorMessage = 'Non-existing value for key "'+str(keys[i])+'"' if isForceMode: self.addError(errorMessage) valueObject = PDFString('') else: return (-1,errorMessage) else: valueObject = values[i] v = valueObject.getValue() type = valueObject.getType() if keys[i] == '/Type': self.dictType = v elif keys[i] == '/S': if self.dictType == '': self.dictType = '/Action ' + v else: self.dictType += ' ' + v if type == 'reference': self.references.append(v) elif type == 'dictionary' or type == 'array': self.references += valueObject.getReferences() if valueObject.containsJS(): self.containsJScode = True self.JSCode += valueObject.getJSCode() self.unescapedBytes += valueObject.getUnescapedBytes() self.urlsFound += valueObject.getURLs() if valueObject.isFaulty(): for error in valueObject.getErrors(): self.addError('Children element contains errors: ' + error) if self.rawNames.has_key(keys[i]): rawName = self.rawNames[keys[i]] rawValue = rawName.getRawValue() else: rawValue = keys[i] self.rawNames[keys[i]] = PDFName(keys[i][1:]) if type in ['string','hexstring','array','dictionary'] and self.encrypted and not decrypt: ret = valueObject.encrypt(self.encryptionKey) if ret[0] == -1: errorMessage = 'Error encrypting element' self.addError(errorMessage) self.encryptedValue += rawValue + ' ' + str(valueObject.getEncryptedValue()) + newLine self.rawValue += rawValue + ' ' + str(valueObject.getRawValue()) + newLine self.value += keys[i] + ' ' + v + newLine self.encryptedValue = self.encryptedValue[:-1] + ' >>' self.rawValue = self.rawValue[:-1] + ' >>' self.value = self.value[:-1] + ' >>' if errorMessage != '': return (-1,errorMessage) return (0,'') def decrypt(self, password = None, algorithm = 'RC4'): ''' Decrypt the content of the object if possible @param password: The password used to decrypt the object. It's dependent on the object. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.encrypted = True errorMessage = '' if password != None: self.encryptionKey = password decryptedElements = {} for key in self.elements: object = self.elements[key] objectType = object.getType() if objectType in ['string','hexstring','array','dictionary']: ret = object.decrypt(self.encryptionKey, algorithm) if ret[0] == -1: errorMessage = ret[1] self.addError(errorMessage) decryptedElements[key] = object self.elements = decryptedElements ret = self.update(decrypt = True) if ret[0] == 0 and errorMessage != '': return (-1,errorMessage) return ret def delElement(self, name, update = True): ''' Removes the element from the dictionary @param name: The element to remove @param update: A boolean indicating if it's necessary an update of the object. By default: True. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' if self.elements.has_key(name): del(self.elements[name]) if update: ret = self.update() return ret return (0,'') else: return (-1,'Element not found') def encodeChars(self): encodedElements = {} errorMessage = '' for key in self.elements: rawName = self.rawNames[key] rawName.encodeChars() self.rawNames[key] = rawName object = self.elements[key] objectType = object.getType() if objectType in ['string','name','array','dictionary']: ret = object.encodeChars() if ret[0] == -1: errorMessage = ret[1] self.addError(errorMessage) encodedElements[key] = object self.elements = encodedElements ret = self.update() if ret[0] == 0 and errorMessage != '': return (-1,errorMessage) return ret def encrypt(self, password = None): self.encrypted = True if password != None: self.encryptionKey = password ret = self.update() return ret def getDictType(self): ''' Gets the type of dictionary @return: The dictionary type (string) ''' return self.dictType def getElement(self, name): ''' Gets the element of the dictionary with the given name @param name: The name of element @return: The PDFObject or None if it's not found ''' if self.elements.has_key(name): return self.elements[name] else: return None def getElementByName(self, name, recursive = False): ''' Gets the elements with the given name @param name: The name @param recursive: A boolean indicating if the search is recursive or not. By default: False. @return: A PDFObject if recursive = False and an array of PDFObjects if recursive = True. ''' retElements = [] if self.elements.has_key(name): if recursive: retElements.append(self.elements[name]) else: return self.elements[name] if recursive: for element in self.elements.values(): if element != None and (element.getType() == 'dictionary' or element.getType() == 'array'): retElements += element.getElementByName(name) return retElements def getElements(self): ''' Gets the elements of the array object @return: An array of PDFObject elements ''' return self.elements def getJSCode(self): ''' Gets the Javascript code of the object @return: An array of Javascript code sections ''' return self.JSCode def getNumElements(self): ''' Gets the number of elements of the array @return: The number of elements (int) ''' return len(self.elements) def getStats(self): stats = {} stats['Object'] = self.type stats['MD5'] = hashlib.md5(self.value).hexdigest() stats['SHA1'] = hashlib.sha1(self.value).hexdigest() if self.isCompressed(): stats['Compressed in'] = str(self.compressedIn) else: stats['Compressed in'] = None stats['References'] = str(self.references) if self.isFaulty(): stats['Errors'] = str(len(self.errors)) else: stats['Errors'] = None if self.dictType != '': stats['Type'] = self.dictType else: stats['Type'] = None if self.elements.has_key('/Subtype'): stats['Subtype'] = self.elements['/Subtype'].getValue() else: stats['Subtype'] = None if self.elements.has_key('/S'): stats['Action type'] = self.elements['/S'].getValue() else: stats['Action type'] = None if self.containsJScode: stats['JSCode'] = True if len(self.unescapedBytes) > 0: stats['Escaped Bytes'] = True else: stats['Escaped Bytes'] = False if len(self.urlsFound) > 0: stats['URLs'] = True else: stats['URLs'] = False else: stats['JSCode'] = False return stats def getUnescapedBytes(self): ''' Gets the escaped bytes of the object unescaped @return: An array of unescaped bytes (string) ''' return self.unescapedBytes def getURLs(self): ''' Gets the URLs of the object @return: An array of URLs ''' return self.urlsFound def hasElement(self, name): ''' Specifies if the dictionary contains the element with the given name @param name: The element @return: A boolean ''' if self.elements.has_key(name): return True else: return False def replace(self, string1, string2): newElements = {} stringFound = False errorMessage = '' for key in self.elements: if key.find(string1) != -1: newKey = key.replace(string1, string2) stringFound = True if errorMessage == 'String not found': errorMessage = '' else: newKey = key newObject = self.elements[key] if newObject != None: ret = newObject.replace(string1, string2) if ret[0] == -1: if ret[1] != 'String not found' or not stringFound: errorMessage = ret[1] else: stringFound = True if errorMessage == 'String not found': errorMessage = '' newElements[newKey] = newObject if not stringFound: return (-1,'String not found') self.elements = newElements ret = self.update() if ret[0] == 0 and errorMessage != '': return (-1,errorMessage) return ret def setElement(self, name, value, update = True): ''' Sets the element with the given name to the given value. If it does not exist a new element is created. @param name: The element to add or modify @param value: The new value of the element @param update: A boolean indicating if it's necessary an update of the object. By default: True. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.elements[name] = value if update: ret = self.update() return ret return (0,'') def setElements(self, newElements): ''' Sets the dictionary of elements @param newElements: The new dictionary of elements @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.elements = newElements ret = self.update() return ret def setElementValue(self, name, value, update = True): ''' Sets the value of the element with the given name. @param name: The element to modify @param value: The new value of the element @param update: A boolean indicating if it's necessary an update of the object. By default: True. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' if self.elements.has_key(name): self.elements[name].setValue(value) if update: ret = self.update() return ret return (0,'') else: return (-1,'Element not found') class PDFStream (PDFDictionary) : ''' Stream object of a PDF document ''' def __init__(self, rawDict = '', rawStream = '', elements = {}, rawNames = {}) : global isForceMode self.type = 'stream' self.dictType = '' self.errors = [] self.compressedIn = None self.encrypted = False self.decodedStream = '' self.encodedStream = '' self.encryptedValue = rawDict self.rawValue = rawDict self.rawNames = rawNames self.elements = elements self.value = '' self.updateNeeded = False self.containsJScode = False self.rawStream = rawStream self.encryptedStream = rawStream self.xrefStream = False self.newFilters = False self.deletedFilters = False self.modifiedStream = False self.modifiedRawStream = True self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] self.referencesInElements = {} self.references = [] self.size = 0 self.filter = None self.filterParams = None self.file = None self.isEncodedStream = False self.decodingError = False if elements == {}: errorMessage = 'No dictionary in stream object' if isForceMode: self.addError(errorMessage) else: raise Exception(errorMessage) ret = self.update() if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) def update(self, onlyElements = False, decrypt = False, algorithm = 'RC4'): ''' Updates the object after some modification has occurred @param onlyElements: A boolean indicating if it's only necessary to update the stream dictionary or also the stream itself. By default: False (stream included). @param decrypt: A boolean indicating if a decryption has been performed. By default: False. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.value = '<< ' self.rawValue = '<< ' self.encryptedValue = '<< ' keys = self.elements.keys() values = self.elements.values() if not onlyElements: self.references = [] self.errors = [] self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] self.containsJScode = False self.decodingError = False # Dictionary if self.elements.has_key('/Type') and self.elements['/Type'] != None: if self.elements['/Type'].getValue() == '/XRef': self.xrefStream = True if self.elements.has_key('/Length'): length = self.elements['/Length'] if length != None: if length.getType() == 'integer': self.size = length.getRawValue() elif length.getType() == 'reference': self.updateNeeded = True self.referencesInElements['/Length'] = [length.getId(),''] else: if isForceMode: self.addError('No permitted type for /Length element') else: return (-1,'No permitted type for /Length element') else: if isForceMode: self.addError('None /Length element') else: return (-1,'None /Length element') else: if isForceMode: self.addError('Missing /Length in stream object') else: return (-1,'Missing /Length in stream object') if self.elements.has_key('/F'): self.file = self.elements['/F'].getValue() if os.path.exists(self.file): self.rawStream = open(self.file,'rb').read() else: if isForceMode: self.addError('File "'+self.file+'" does not exist (/F)') self.rawStream = '' else: return (-1,'File "'+self.file+'" does not exist (/F)') if self.elements.has_key('/Filter'): self.filter = self.elements['/Filter'] if self.newFilters or self.modifiedStream: self.encodedStream = '' self.rawStream = '' elif not self.encrypted: self.encodedStream = self.rawStream self.isEncodedStream = True elif self.elements.has_key('/FFilter'): self.filter = self.elements['/FFilter'] if self.newFilters or self.modifiedStream: self.encodedStream = '' self.rawStream = '' elif not self.encrypted: self.encodedStream = self.rawStream self.isEncodedStream = True else: self.encodedStream = '' if self.deletedFilters or self.modifiedStream: self.rawStream = self.decodedStream elif not self.encrypted: self.decodedStream = self.rawStream self.isEncodedStream = False if self.isEncodedStream: if self.elements.has_key('/DecodeParms'): self.filterParams = self.elements['/DecodeParms'] elif self.elements.has_key('/FDecodeParms'): self.filterParams = self.elements['/FDecodeParms'] elif self.elements.has_key('/DP'): self.filterParams = self.elements['/DP'] else: self.filterParams = None for i in range(len(keys)): valueElement = values[i] if valueElement == None: errorMessage = 'Stream dictionary has a None value' self.addError(errorMessage) valueElement = PDFString('') v = valueElement.getValue() type = valueElement.getType() if type == 'reference': if v not in self.references: self.references.append(v) elif type == 'dictionary' or type == 'array': self.references = list(set(self.references + valueElement.getReferences())) if valueElement.containsJS(): self.containsJScode = True self.JSCode = list(set(self.JSCode + valueElement.getJSCode())) self.unescapedBytes = list(set(self.unescapedBytes + valueElement.getUnescapedBytes())) self.urlsFound = list(set(self.urlsFound + valueElement.getURLs())) if valueElement.isFaulty(): for error in valueObject.getErrors(): self.addError('Children element contains errors: ' + error) if self.rawNames.has_key(keys[i]): rawName = self.rawNames[keys[i]] rawValue = rawName.getRawValue() else: rawValue = keys[i] self.rawNames[keys[i]] = PDFName(keys[i][1:]) if type in ['string','hexstring','array','dictionary'] and self.encrypted and not decrypt: ret = valueElement.encrypt(self.encryptionKey) if ret[0] == -1: errorMessage = ret[1]+' in child element' self.addError(errorMessage) self.encryptedValue += rawValue + ' ' + str(valueElement.getEncryptedValue()) + newLine self.rawValue += rawValue + ' ' + str(valueElement.getRawValue()) + newLine self.value += keys[i] + ' ' + v + newLine self.encryptedValue = self.encryptedValue[:-1] + ' >>' self.rawValue = self.rawValue[:-1] + ' >>' self.value = self.value[:-1] + ' >>' if not onlyElements: # Stream if self.deletedFilters or self.newFilters or self.modifiedStream or self.modifiedRawStream or self.encrypted: if self.deletedFilters: if self.encrypted: try: self.rawStream = RC4(self.decodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: self.size = len(self.decodedStream) elif self.newFilters: ret = self.encode() if ret[0] != -1: if self.encrypted: try: self.rawStream = RC4(self.encodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: self.size = len(self.encodedStream) elif self.modifiedStream: refs = re.findall('(\d{1,5}\s{1,3}\d{1,5}\s{1,3}R)', self.decodedStream) if refs != []: self.references += refs self.references = list(set(self.references)) if isJavascript(self.decodedStream): self.containsJScode = True self.JSCode, self.unescapedBytes, self.urlsFound, jsErrors, jsContexts['global'] = analyseJS(self.decodedStream, jsContexts['global'], isManualAnalysis) if jsErrors != []: for jsError in jsErrors: errorMessage = 'Error analysing Javascript: '+jsError if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if self.isEncodedStream: ret = self.encode() if ret[0] != -1: if self.encrypted: try: self.rawStream = RC4(self.encodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: self.size = len(self.encodedStream) else: if self.encrypted: try: self.rawStream = RC4(self.decodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: self.size = len(self.decodedStream) elif self.modifiedRawStream: if len(self.encodedStream) > 0 or len(self.decodedStream) > 0: self.cleanStream() if not self.updateNeeded: if self.encrypted: if self.isEncodedStream: if decrypt: try: if algorithm == 'RC4': self.encodedStream = RC4(self.encodedStream,self.encryptionKey) elif algorithm == 'AES': ret = AES.decryptData(self.encodedStream,self.encryptionKey) if ret[0] != -1: self.encodedStream = ret[1] else: errorMessage = 'AES decryption error: '+ret[1] if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) except: errorMessage = 'Error decrypting stream with '+str(algorithm) if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: self.encodedStream = self.rawStream try: self.rawStream = RC4(self.rawStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.decode() else: if not decrypt: self.decodedStream = self.rawStream try: rc4Result = RC4(self.rawStream,self.encryptionKey) if decrypt: self.decodedStream = rc4Result else: self.rawStream = rc4Result except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: if self.isEncodedStream: self.decode() self.size = len(self.rawStream) if not self.isFaultyDecoding(): refs = re.findall('(\d{1,5}\s{1,3}\d{1,5}\s{1,3}R)', self.decodedStream) if refs != []: self.references += refs self.references = list(set(self.references)) if isJavascript(self.decodedStream): self.containsJScode = True self.JSCode, self.unescapedBytes, self.urlsFound, jsErrors, jsContexts['global'] = analyseJS(self.decodedStream, jsContexts['global'], isManualAnalysis) if jsErrors != []: for jsError in jsErrors: errorMessage = 'Error analysing Javascript: '+jsError if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: if not decrypt: try: if self.isEncodedStream: self.rawStream = RC4(self.encodedStream,self.encryptionKey) else: self.rawStream = RC4(self.decodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: if self.isEncodedStream: try: if algorithm == 'RC4': self.encodedStream = RC4(self.encodedStream,self.encryptionKey) elif algorithm == 'AES': ret = AES.decryptData(self.encodedStream,self.encryptionKey) if ret[0] != -1: self.encodedStream = ret[1] else: errorMessage = 'AES decryption error: '+ret[1] if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) except: errorMessage = 'Error decrypting stream with '+str(algorithm) if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.decode() else: try: if algorithm == 'RC4': self.decodedStream = RC4(self.decodedStream,self.encryptionKey) elif algorithm == 'AES': ret = AES.decryptData(self.decodedStream,self.encryptionKey) if ret[0] != -1: self.decodedStream = ret[1] else: errorMessage = 'AES decryption error: '+ret[1] if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) except: errorMessage = 'Error decrypting stream with '+str(algorithm) if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if not self.isFaultyDecoding(): refs = re.findall('(\d{1,5}\s{1,3}\d{1,5}\s{1,3}R)', self.decodedStream) if refs != []: self.references += refs self.references = list(set(self.references)) if isJavascript(self.decodedStream): self.containsJScode = True self.JSCode, self.unescapedBytes, self.urlsFound, jsErrors, jsContexts['global'] = analyseJS(self.decodedStream, jsContexts['global'], isManualAnalysis) if jsErrors != []: for jsError in jsErrors: errorMessage = 'Error analysing Javascript: '+jsError if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if not self.modifiedRawStream: self.modifiedStream = False self.newFilters = False self.deletedFilters = False errors = self.errors try: self.setElement('/Length',PDFNum(str(self.size))) self.errors += errors except: errorMessage = 'Error creating PDFNum' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: self.modifiedRawStream = False self.modifiedStream = False self.newFilters = False self.deletedFilters = False if self.errors != []: return (-1,self.errors[-1]) else: return (0,'') def cleanStream(self): ''' Cleans the start and end of the stream ''' if self.isEncodedStream: stream = self.encodedStream tmpStream = self.encodedStream else: stream = self.decodedStream tmpStream = self.decodedStream ''' garbage = len(stream) - self.size if garbage > 0: for i in range(len(tmpStream)): if garbage == 0: break if tmpStream[i] == '\r' or tmpStream[i] == '\n': stream = stream[1:] garbage -= 1 else: break for i in range(len(tmpStream)-1,0,-1): if garbage == 0: break if tmpStream[i] == '\r' or tmpStream[i] == '\n': stream = stream[:-1] garbage -= 1 else: break ''' streamLength = len(stream) ''' if streamLength > 1 and stream[:2] == '\r\n': stream = stream[2:] streamLength -= 2 elif streamLength > 0 and (stream[0] == '\r' or stream[0] == '\n'): stream = stream[1:] streamLength -= 1 ''' if streamLength > 1 and stream[-2:] == '\r\n': stream = stream[:-2] elif streamLength > 0 and (stream[-1] == '\r' or stream[-1] == '\n'): stream = stream[:-1] if self.isEncodedStream: self.encodedStream = stream else: self.decodedStream = stream def contains(self, string): value = str(self.value) rawValue = str(self.rawValue) encValue = str(self.encryptedValue) rawStream = str(self.rawStream) encStream = str(self.encodedStream) decStream = str(self.decodedStream) if re.findall(string,value,re.IGNORECASE) != [] or re.findall(string,rawValue,re.IGNORECASE) != [] or re.findall(string,encValue,re.IGNORECASE) != [] or re.findall(string,rawStream,re.IGNORECASE) != [] or re.findall(string,encStream,re.IGNORECASE) != [] or re.findall(string,decStream,re.IGNORECASE) != []: return True if self.containsJS(): for js in self.JSCode: if re.findall(string,js,re.IGNORECASE) != []: return True return False def decode (self) : ''' Decodes the stream and stores the result in decodedStream @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' errorMessage = '' if len(self.rawStream) > 0: if self.isEncodedStream: if self.filter == None: errorMessage = 'Bad /Filter element' self.addError(errorMessage) return (-1,errorMessage) filterType = self.filter.getType() if self.filterParams != None: filterParamsType = self.filterParams.getType() if filterType == 'name': if self.filterParams == None: ret = decodeStream(self.encodedStream, self.filter.getValue(), self.filterParams) if ret[0] == -1: if self.rawStream != self.encodedStream: ret = decodeStream(self.rawStream, self.filter.getValue(), self.filterParams) if ret[0] == -1: self.decodingError = True errorMessage = 'Decoding error: '+ret[1] if isForceMode: self.addError(errorMessage) self.decodedStream = '' else: return (-1,errorMessage) else: self.decodedStream = ret[1] else: self.decodedStream = ret[1] elif filterParamsType == 'dictionary': ret = decodeStream(self.encodedStream, self.filter.getValue(), self.filterParams.getElements()) if ret[0] == -1: if self.rawStream != self.encodedStream: ret = decodeStream(self.rawStream, self.filter.getValue(), self.filterParams.getElements()) if ret[0] == -1: self.decodingError = True errorMessage = 'Decoding error: '+ret[1] if isForceMode: self.addError(errorMessage) self.decodedStream = '' else: return (-1,errorMessage) else: self.decodedStream = ret[1] else: self.decodedStream = ret[1] else: if isForceMode: errorMessage = 'Filter parameters type is not valid' self.addError(errorMessage) self.decodedStream = '' else: return (-1,'Filter parameters type is not valid') elif filterType == 'array': self.decodedStream = self.encodedStream filterElements = self.filter.getElements() for i in range(len(filterElements)): filter = filterElements[i] if filter == None: if isForceMode: errorMessage = 'Bad /Filter element in PDFArray' self.addError(errorMessage) continue return (-1,'Bad /Filter element in PDFArray') if filter.getType() == 'name': if self.filterParams == None: ret = decodeStream(self.decodedStream, filter.getValue(), self.filterParams) if ret[0] == -1: if i == 0 and self.rawStream != self.encodedStream: ret = decodeStream(self.rawStream, filter.getValue(), self.filterParams) if ret[0] == -1: self.decodingError = True errorMessage = 'Decoding error: '+ret[1] if isForceMode: self.addError(errorMessage) self.decodedStream = '' else: return (-1,errorMessage) else: self.decodedStream = ret[1] else: self.decodedStream = ret[1] elif filterParamsType == 'array': paramsArray = self.filterParams.getElements() if i >= len(paramsArray): paramsObj = None paramsDict = {} else: paramsObj = paramsArray[i] if paramsObj == None: if isForceMode: errorMessage = 'Bad /FilterParms element in PDFArray' self.addError(errorMessage) continue return (-1,'Bad /FilterParms element in PDFArray') paramsObjType = paramsObj.getType() if paramsObjType == 'dictionary': paramsDict = paramsObj.getElements() else: paramsDict = {} ret = decodeStream(self.decodedStream, filter.getValue(), paramsDict) if ret[0] == -1: if i == 0 and self.rawStream != self.encodedStream: ret = decodeStream(self.rawStream, filter.getValue(), paramsDict) if ret[0] == -1: self.decodingError = True errorMessage = 'Decoding error: '+ret[1] if isForceMode: self.addError(errorMessage) self.decodedStream = '' else: return (-1,errorMessage) else: self.decodedStream = ret[1] else: self.decodedStream = ret[1] else: if isForceMode: errorMessage = 'One of the filters parameters type is not valid' self.addError(errorMessage) self.decodedStream = '' else: return (-1,'One of the filters parameters type is not valid') else: if isForceMode: errorMessage = 'One of the filters type is not valid' self.addError(errorMessage) self.decodedStream = '' else: return (-1,'One of the filters type is not valid') else: if isForceMode: errorMessage = 'Filter type is not valid' self.addError(errorMessage) self.decodedStream = '' else: return (-1,'Filter type is not valid') if errorMessage != '': return (-1,errorMessage) else: return (0,'') else: return (-1,'Not encoded stream') else: return (-1,'Empty stream') def decrypt(self, password = None, strAlgorithm = 'RC4', altAlgorithm = 'RC4'): ''' Decrypt the content of the object if possible @param password: The password used to decrypt the object. It's dependent on the object. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' errorMessage = '' self.encrypted = True if password != None: self.encryptionKey = password decryptedElements = {} for key in self.elements: object = self.elements[key] objectType = object.getType() if objectType in ['string','hexstring','array','dictionary']: ret = object.decrypt(self.encryptionKey, strAlgorithm) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) decryptedElements[key] = object self.elements = decryptedElements ret = self.update(decrypt = True, algorithm = altAlgorithm) if ret[0] == 0 and errorMessage != '': return (-1,errorMessage) return ret def delElement(self, name, update = True): onlyElements = True if self.elements.has_key(name): if name in ['/Filter','/DecodeParm','/FFilter','/FDecodeParm']: self.deletedFilters = True onlyElements = False del(self.elements[name]) if update: ret = self.update(onlyElements = onlyElements) return ret else: return (-1,'Element not found') def encode (self) : ''' Encode the decoded stream and update the content of rawStream ''' errorMessage = '' if len(self.decodedStream) > 0: if self.filter == None: return (-1,'Bad /Filter element') filterType = self.filter.getType() if self.filterParams != None: filterParamsType = self.filterParams.getType() if filterType == 'name': if self.filterParams == None: ret = encodeStream(self.decodedStream, self.filter.getValue(), self.filterParams) if ret[0] == -1: errorMessage = 'Encoding error: '+ret[1] if isForceMode: self.addError(errorMessage) self.encodedStream = '' else: return (-1,errorMessage) else: self.rawStream = ret[1] elif filterParamsType == 'dictionary': ret = encodeStream(self.decodedStream, self.filter.getValue(), self.filterParams.getElements()) if ret[0] == -1: errorMessage = 'Encoding error: '+ret[1] if isForceMode: self.addError(errorMessage) self.encodedStream = '' else: return (-1,errorMessage) else: self.rawStream = ret[1] else: if isForceMode: errorMessage = 'Filter parameters type is not valid' self.addError(errorMessage) self.encodedStream = '' else: return (-1,'Filter parameters type is not valid') elif filterType == 'array': self.rawStream = self.decodedStream filterElements = list(self.filter.getElements()) filterElements.reverse() if self.filterParams != None and filterParamsType == 'array': paramsArray = self.filterParams.getElements() for j in range(len(paramsArray),len(filterElements)): paramsArray.append(PDFNull('Null')) paramsArray.reverse() else: paramsArray = [] for i in range(len(filterElements)): filter = filterElements[i] if filter == None: if isForceMode: errorMessage = 'Bad /Filter element in PDFArray' self.addError(errorMessage) continue return (-1,'Bad /Filter element in PDFArray') if filter.getType() == 'name': if self.filterParams == None: ret = encodeStream(self.rawStream, filter.getValue(), self.filterParams) if ret[0] == -1: errorMessage = 'Encoding error: '+ret[1] if isForceMode: self.addError(errorMessage) self.encodedStream = '' else: return (-1,errorMessage) else: self.rawStream = ret[1] elif filterParamsType == 'array': paramsObj = paramsArray[i] if paramsObj == None: if isForceMode: errorMessage = 'Bad /FilterParms element in PDFArray' self.addError(errorMessage) continue return (-1,'Bad /FilterParms element in PDFArray') paramsObjType = paramsObj.getType() if paramsObjType == 'dictionary': paramsDict = paramsObj.getElements() else: paramsDict = {} ret = encodeStream(self.rawStream, filter.getValue(), paramsDict) if ret[0] == -1: errorMessage = 'Encoding error: '+ret[1] if isForceMode: self.addError(errorMessage) self.encodedStream = '' else: return (-1,errorMessage) else: self.rawStream = ret[1] else: if isForceMode: errorMessage = 'One of the filters parameters type is not valid' self.addError(errorMessage) self.encodedStream = '' else: return (-1,'One of the filters parameters type is not valid') else: if isForceMode: errorMessage = 'One of the filters type is not valid' self.addError(errorMessage) self.encodedStream = '' else: return (-1,'One of the filters type is not valid') else: if isForceMode: errorMessage = 'Filter type is not valid' self.addError(errorMessage) self.encodedStream = '' else: return (-1,'Filter type is not valid') self.encodedStream = self.rawStream if errorMessage != '': return (-1,errorMessage) else: return (0,'') else: return (-1,'Empty stream') def encrypt(self, password = None): self.encrypted = True if password != None: self.encryptionKey = password ret = self.update() return ret def getEncryptedValue(self): return self.encryptedValue + newLine + 'stream' + newLine + self.rawStream + newLine + 'endstream' def getStats(self): stats = {} stats['Object'] = self.type stats['MD5'] = hashlib.md5(self.value).hexdigest() stats['SHA1'] = hashlib.sha1(self.value).hexdigest() stats['Stream MD5'] = hashlib.md5(self.decodedStream).hexdigest() stats['Stream SHA1'] = hashlib.sha1(self.decodedStream).hexdigest() stats['Raw Stream MD5'] = hashlib.md5(self.rawStream).hexdigest() stats['Raw Stream SHA1'] = hashlib.sha1(self.rawStream).hexdigest() if self.isCompressed(): stats['Compressed in'] = str(self.compressedIn) else: stats['Compressed in'] = None stats['References'] = str(self.references) if self.isFaulty(): stats['Errors'] = str(len(self.errors)) else: stats['Errors'] = None if self.dictType != '': stats['Type'] = self.dictType else: stats['Type'] = None if self.elements.has_key('/Subtype'): stats['Subtype'] = self.elements['/Subtype'].getValue() else: stats['Subtype'] = None if self.elements.has_key('/S'): stats['Action type'] = self.elements['/S'].getValue() else: stats['Action type'] = None stats['Length'] = str(self.size) if self.size != len(self.rawStream): stats['Real Length'] = str(len(self.rawStream)) else: stats['Real Length'] = None if self.isEncodedStream: stats['Encoded'] = True if self.file != None: stats['Stream File'] = self.file else: stats['Stream File'] = None stats['Filters'] = self.filter.getValue() if self.filterParams != None: stats['Filter Parameters'] = True else: stats['Filter Parameters'] = False if self.decodingError: stats['Decoding Errors'] = True else: stats['Decoding Errors'] = False else: stats['Encoded'] = False if self.containsJScode: stats['JSCode'] = True if len(self.unescapedBytes) > 0: stats['Escaped Bytes'] = True else: stats['Escaped Bytes'] = False if len(self.urlsFound) > 0: stats['URLs'] = True else: stats['URLs'] = False else: stats['JSCode'] = False return stats def getStream(self): ''' Gets the stream of the object @return: The stream of the object (string), this means applying filters or decoding characters ''' return self.decodedStream def getRawStream(self): ''' Gets the raw value of the stream of the object @return: The raw value of the stream (string), this means without applying filters or decoding characters ''' return self.rawStream def getRawValue(self): if self.isEncoded(): stream = self.encodedStream else: stream = self.decodedStream return self.rawValue + newLine + 'stream' + newLine + stream + newLine + 'endstream' def getValue(self): return self.value + newLine +'stream' + newLine + self.decodedStream + newLine + 'endstream' def isEncoded(self): ''' Specifies if the stream is encoded with some type of filter (/Filter) @return: A boolean ''' return self.isEncodedStream def isFaultyDecoding(self): ''' Specifies if there are any errors in the process of decoding the stream @return: A boolean ''' return self.decodingError def replace(self, string1, string2): stringFound = False # Dictionary newElements = {} errorMessage = '' for key in self.elements: if key == '/F' and self.elements[key] != None: externalFile = self.elements[key].getValue() if externalFile != self.file: self.modifiedRawStream = True self.decodedStream = '' if key.find(string1) != -1: newKey = key.replace(string1, string2) stringFound = True if errorMessage == 'String not found': errorMessage = '' else: newKey = key newObject = self.elements[key] ret = newObject.replace(string1, string2) if ret[0] == -1: if ret[1] != 'String not found' or not stringFound: errorMessage = ret[1] else: stringFound = True if errorMessage == 'String not found': errorMessage = '' newElements[newKey] = newObject # Stream if not self.modifiedRawStream: oldDecodedStream = self.decodedStream if self.decodedStream.find(string1) != -1: self.decodedStream = self.decodedStream.replace(string1,string2) stringFound = True if errorMessage == 'String not found': errorMessage = '' if oldDecodedStream != self.decodedStream: self.modifiedStream = True if not stringFound: return (-1,'String not found') self.elements = newElements ret = self.update() if ret[0] == 0 and errorMessage != '': return (-1,errorMessage) return ret def resolveReferences(self): errorMessage = '' if self.referencesInElements.has_key('/Length'): value = self.referencesInElements['/Length'][1] self.size = int(value) self.cleanStream() self.updateNeeded = False ret = self.decode() if ret[0] == -1: errorMessage = ret[1] refs = re.findall('(\d{1,5}\s{1,3}\d{1,5}\s{1,3}R)', self.decodedStream) if refs != []: self.references += refs self.references = list(set(self.references)) if isJavascript(self.decodedStream): self.containsJScode = True self.JSCode, self.unescapedBytes, self.urlsFound, jsErrors, jsContexts['global'] = analyseJS(self.decodedStream, jsContexts['global'], isManualAnalysis) if jsErrors != []: for jsError in jsErrors: errorMessage = 'Error analysing Javascript: '+jsError if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if errorMessage != '': return (-1,errorMessage) return (0,'') def setDecodedStream(self, newStream): ''' Sets the decoded value of the stream and updates the object if some modification is needed @param newStream: The new raw value (string) @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.decodedStream = newStream self.modifiedStream = True ret = self.update() return ret def setElement(self, name, value, update = True): onlyElements = True if name in ['/Filter','/DecodeParm','/FFilter','/FDecodeParm']: self.newFilters = True onlyElements = False self.elements[name] = value if update: ret = self.update(onlyElements = onlyElements) return ret return (0,'') def setElements(self, newElements): diffElements = [] oldElements = self.elements.keys() for oldElement in oldElements: if oldElement not in newElements: if oldElement in ['/Filter','/FFilter']: self.deletedFilters = True onlyElements = False break self.elements = newElements if not self.deletedFilters: for name in self.elements: if name in ['/Filter','/DecodeParm','/FFilter','/FDecodeParm']: self.newFilters = True onlyElements = False break ret = self.update() return ret def setRawStream(self, newStream): ''' Sets the raw value of the stream and updates the object if some modification is needed @param newStream: The new raw value (string) @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.rawStream = newStream self.modifiedRawStream = True ret = self.update() return ret class PDFObjectStream (PDFStream) : def __init__(self, rawDict = '', rawStream = '', elements = {}, rawNames = {}, compressedObjectsDict = {}) : global isForceMode self.type = 'stream' self.dictType = '' self.errors = [] self.compressedIn = None self.encrypted = False self.decodedStream = '' self.encodedStream = '' self.rawStream = rawStream self.newRawStream = False self.newFilters = False self.deletedFilters = False self.modifiedStream = False self.modifiedRawStream = True self.rawValue = rawDict self.encryptedValue = rawDict self.rawNames = rawNames self.value = '' # string self.updateNeeded = False self.containsJScode = False self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] self.referencesInElements = {} self.references = [] self.elements = elements self.compressedObjectsDict = compressedObjectsDict self.indexes = [] self.firstObjectOffset = 0 self.numCompressedObjects = 0 self.extends = None self.size = 0 self.filter = None self.filterParams = None self.file = None self.isEncodedStream = False self.decodingError = False if elements != {}: ret = self.update() if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) else: self.addError('No dictionary in stream object') def update(self, modifiedCompressedObjects = False, onlyElements = False, decrypt = False, algorithm = 'RC4'): ''' Updates the object after some modification has occurred @param modifiedCompressedObjects: A boolean indicating if the compressed objects hav been modified. By default: False. @param onlyElements: A boolean indicating if it's only necessary to update the stream dictionary or also the stream itself. By default: False (stream included). @param decrypt: A boolean indicating if a decryption has been performed. By default: False. @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' self.value = '<< ' self.rawValue = '<< ' self.encryptedValue = '<< ' keys = self.elements.keys() values = self.elements.values() if not onlyElements: self.errors = [] self.references = [] self.JSCode = [] self.unescapedBytes = [] self.urlsFound = [] self.containsJScode = False self.decodingError = False # Dictionary if self.elements.has_key('/First') and self.elements['/First'] != None: self.firstObjectOffset = self.elements['/First'].getRawValue() else: if isForceMode: self.addError('No /First element in the object stream or it\'s None') else: return (-1,'No /First element in the object stream or it\'s None') if self.elements.has_key('/N') and self.elements['/N'] != None: self.numCompressedObjects = self.elements['/N'].getRawValue() else: if isForceMode: self.addError('No /N element in the object stream or it\'s None') else: return (-1,'No /N element in the object stream or it\'s None') if self.elements.has_key('/Extends') and self.elements['/Extends'] != None: self.extends = self.elements['/Extends'].getValue() if self.elements.has_key('/Length'): length = self.elements['/Length'] if length != None: if length.getType() == 'integer': self.size = length.getRawValue() elif length.getType() == 'reference': self.updateNeeded = True self.referencesInElements['/Length'] = [length.getId(),''] else: if isForceMode: self.addError('No permitted type for /Length element') else: return (-1,'No permitted type for /Length element') else: if isForceMode: self.addError('None /Length element') else: return (-1,'None /Length element') else: if isForceMode: self.addError('Missing /Length in stream object') else: return (-1,'Missing /Length in stream object') if self.elements.has_key('/F'): self.file = self.elements['/F'].getValue() if os.path.exists(self.file): self.rawStream = open(self.file,'rb').read() else: if isForceMode: self.addError('File "'+self.file+'" does not exist (/F)') self.rawStream = '' else: return (-1,'File "'+self.file+'" does not exist (/F)') if self.elements.has_key('/Filter'): self.filter = self.elements['/Filter'] if self.newFilters or self.modifiedStream: self.encodedStream = '' self.rawStream = '' elif not self.encrypted: self.encodedStream = self.rawStream self.isEncodedStream = True elif self.elements.has_key('/FFilter'): self.filter = self.elements['/FFilter'] if self.newFilters or self.modifiedStream: self.encodedStream = '' self.rawStream = '' elif not self.encrypted: self.encodedStream = self.rawStream self.isEncodedStream = True else: self.encodedStream = '' if self.deletedFilters or self.modifiedStream: self.rawStream = self.decodedStream elif not self.encrypted: self.decodedStream = self.rawStream self.isEncodedStream = False if self.isEncodedStream: if self.elements.has_key('/DecodeParms'): self.filterParams = self.elements['/DecodeParms'] elif self.elements.has_key('/FDecodeParms'): self.filterParams = self.elements['/FDecodeParms'] elif self.elements.has_key('/DP'): self.filterParams = self.elements['/DP'] else: self.filterParams = None for i in range(len(keys)): valueElement = values[i] if valueElement == None: if isForceMode: errorMessage = 'Stream dictionary has a None value' self.addError(errorMessage) valueElement = PDFString('') else: return (-1,'Stream dictionary has a None value') v = valueElement.getValue() type = valueElement.getType() if type == 'reference': if v not in self.references: self.references.append(v) elif type == 'dictionary' or type == 'array': self.references = list(set(self.references + valueElement.getReferences())) if valueElement.containsJS(): self.containsJScode = True self.JSCode = list(set(self.JSCode + valueElement.getJSCode())) self.unescapedBytes = list(set(self.unescapedBytes + valueElement.getUnescapedBytes())) self.urlsFound = list(set(self.urlsFound + valueElement.getURLs())) if valueElement.isFaulty(): errorMessage = 'Child element is faulty' self.addError(errorMessage) if self.rawNames.has_key(keys[i]): rawName = self.rawNames[keys[i]] rawValue = rawName.getRawValue() else: rawValue = keys[i] self.rawNames[keys[i]] = PDFName(keys[i][1:]) if type in ['string','hexstring','array','dictionary'] and self.encrypted and not decrypt: ret = valueElement.encrypt(self.encryptionKey) if ret[0] == -1: errorMessage = ret[1]+' in child element' self.addError(errorMessage) self.encryptedValue += rawValue + ' ' + str(valueElement.getEncryptedValue()) + newLine self.rawValue += rawValue + ' ' + str(valueElement.getRawValue()) + newLine self.value += keys[i] + ' ' + v + newLine self.encryptedValue = self.encryptedValue[:-1] + ' >>' self.rawValue = self.rawValue[:-1] + ' >>' self.value = self.value[:-1] + ' >>' if not onlyElements: # Stream if self.deletedFilters or self.newFilters or self.modifiedStream or self.modifiedRawStream or modifiedCompressedObjects or self.encrypted: if self.deletedFilters: if self.encrypted: try: self.rawStream = RC4(self.decodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: self.size = len(self.decodedStream) elif self.newFilters: ret = self.encode() if ret[0] != -1: if self.encrypted: try: self.rawStream = RC4(self.encodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: self.size = len(self.encodedStream) else: if self.modifiedStream or self.modifiedRawStream: if self.modifiedStream: if self.isEncodedStream: ret = self.encode() if ret[0] != -1: if self.encrypted: try: self.rawStream = RC4(self.encodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: self.size = len(self.encodedStream) else: if self.encrypted: try: self.rawStream = RC4(self.decodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: self.size = len(self.decodedStream) elif self.modifiedRawStream: if len(self.rawStream) > 0: self.cleanStream() if not self.updateNeeded: if self.encrypted: if self.isEncodedStream: if decrypt: try: if algorithm == 'RC4': self.encodedStream = RC4(self.rawStream,self.encryptionKey) elif algorithm == 'AES': ret = AES.decryptData(self.rawStream,self.encryptionKey) if ret[0] != -1: self.encodedStream = ret[1] else: errorMessage = 'AES decryption error: '+ret[1] if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) except: errorMessage = 'Error decrypting stream with '+str(algorithm) if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: self.encodedStream = self.rawStream try: self.rawStream = RC4(self.rawStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.decode() else: try: self.decodedStream = RC4(self.rawStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: if self.isEncodedStream: self.decode() self.size = len(self.rawStream) offsetsSection = self.decodedStream[:self.firstObjectOffset] objectsSection = self.decodedStream[self.firstObjectOffset:] numbers = re.findall('\d{1,10}', offsetsSection) if numbers != [] and len(numbers) % 2 == 0: for i in range(0,len(numbers),2): id = int(numbers[i]) offset = int(numbers[i+1]) ret = PDFParser().readObject(objectsSection[offset:]) if ret[0] == -1: if isForceMode: object = None self.addError(ret[1]) else: return ret else: object = ret[1] self.compressedObjectsDict[id] = [offset,object] self.indexes.append(id) else: if isForceMode: self.addError('Missing offsets in object stream') else: return (-1,'Missing offsets in object stream') elif modifiedCompressedObjects: tmpStreamObjects = '' tmpStreamObjectsInfo = '' for objectId in self.indexes: offset = len(tmpStreamObjects) tmpStreamObjectsInfo += str(objectId)+' '+str(offset)+' ' object = self.compressedObjectsDict[objectId][1] tmpStreamObjects += object.toFile() self.compressedObjectsDict[objectId] = [offset,object] self.decodedStream = tmpStreamObjectsInfo + tmpStreamObjects self.firstObjectOffset = len(tmpStreamObjectsInfo) self.setElementValue('/First',str(self.firstObjectOffset)) self.numCompressedObjects = len(self.compressedObjectsDict) self.setElementValue('/N',str(self.numCompressedObjects)) if self.isEncodedStream: self.encode() self.size = len(self.encodedStream) else: self.size = len(self.decodedStream) else: if not decrypt: try: if self.isEncodedStream: self.rawStream = RC4(self.encodedStream,self.encryptionKey) else: self.rawStream = RC4(self.decodedStream,self.encryptionKey) except: errorMessage = 'Error encrypting stream with RC4' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.size = len(self.rawStream) else: if self.isEncodedStream: try: if algorithm == 'RC4': self.encodedStream = RC4(self.rawStream,self.encryptionKey) elif algorithm == 'AES': ret = AES.decryptData(self.rawStream,self.encryptionKey) if ret[0] != -1: self.encodedStream = ret[1] else: errorMessage = 'AES decryption error: '+ret[1] if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) except: errorMessage = 'Error decrypting stream with '+str(algorithm) if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.decode() else: try: if algorithm == 'RC4': self.decodedStream = RC4(self.rawStream,self.encryptionKey) elif algorithm == 'AES': ret = AES.decryptData(self.rawStream,self.encryptionKey) if ret[0] != -1: self.decodedStream = ret[1] else: errorMessage = 'AES decryption error: '+ret[1] if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) except: errorMessage = 'Error decrypting stream with '+str(algorithm) if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) offsetsSection = self.decodedStream[:self.firstObjectOffset] objectsSection = self.decodedStream[self.firstObjectOffset:] numbers = re.findall('\d{1,10}', offsetsSection) if numbers != [] and len(numbers) % 2 == 0: for i in range(0,len(numbers),2): id = int(numbers[i]) offset = int(numbers[i+1]) ret = PDFParser().readObject(objectsSection[offset:]) if ret[0] == -1: if isForceMode: object = None self.addError(ret[1]) else: return ret else: object = ret[1] self.compressedObjectsDict[id] = [offset,object] self.indexes.append(id) else: if isForceMode: self.addError('Missing offsets in object stream') else: return (-1,'Missing offsets in object stream') if not self.isFaultyDecoding(): refs = re.findall('(\d{1,5}\s{1,3}\d{1,5}\s{1,3}R)', self.decodedStream) if refs != []: self.references += refs self.references = list(set(self.references)) if isJavascript(self.decodedStream): self.containsJScode = True self.JSCode, self.unescapedBytes, self.urlsFound, jsErrors, jsContexts['global'] = analyseJS(self.decodedStream, jsContexts['global'], isManualAnalysis) if jsErrors != []: for jsError in jsErrors: errorMessage = 'Error analysing Javascript: '+jsError if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if not self.modifiedRawStream: self.modifiedStream = False self.newFilters = False self.deletedFilters = False errors = self.errors try: self.setElement('/Length',PDFNum(str(self.size))) self.errors += errors except: errorMessage = 'Error creating PDFNum' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: self.modifiedRawStream = False self.modifiedStream = False self.newFilters = False self.deletedFilters = False if self.errors != []: return (-1,self.errors[-1]) else: return (0,'') def getCompressedObjects(self): ''' Gets the information of the compressed objects: offset and content. @return: A dictionary with this information: {id: [offset,PDFObject]} ''' return self.compressedObjectsDict def getObjectIndex(self, id): ''' Gets the index of the object in the dictionary of compressed objects @param id: The object id @return: The index (int) or None if the object hasn't been found ''' if id not in self.indexes: return None else: return self.indexes.index(id) def replace(self, string1, string2): stringFound = False # Dictionary newElements = {} errorMessage = '' for key in self.elements: if key == '/F' and self.elements[key] != None: externalFile = self.elements[key].getValue() if externalFile != self.file: self.modifiedRawStream = True self.decodedStream = '' if key.find(string1) != -1: newKey = key.replace(string1, string2) stringFound = True if errorMessage == 'String not found': errorMessage = '' else: newKey = key newObject = self.elements[key] ret = newObject.replace(string1, string2) if ret[0] == -1: if ret[1] != 'String not found' or not stringFound: errorMessage = ret[1] else: stringFound = True if errorMessage == 'String not found': errorMessage = '' newElements[newKey] = newObject # Stream if not self.modifiedRawStream: if self.decodedStream.find(string1) != -1: modifiedObjects = True stringFound = True if errorMessage == 'String not found': errorMessage = '' for compressedObjectId in self.compressedObjectsDict: object = self.compressedObjectsDict[compressedObjectId][1] object.replace(string1,string2) self.compressedObjectsDict[compressedObjectId][1] = object if not stringFound: return (-1,'String not found') self.elements = newElements ret = self.update(modifiedObjects) if ret[0] == 0 and errorMessage != '': return (-1,errorMessage) return ret def resolveReferences(self): errorMessage = '' if self.referencesInElements.has_key('/Length'): value = self.referencesInElements['/Length'][1] self.size = int(value) self.cleanStream() self.updateNeeded = False if self.isEncodedStream: ret = self.decode() if ret[0] == -1: return ret if not self.isFaultyDecoding(): refs = re.findall('(\d{1,5}\s{1,3}\d{1,5}\s{1,3}R)', self.decodedStream) if refs != []: self.references += refs self.references = list(set(self.references)) # Extracting the compressed objects offsetsSection = self.decodedStream[:self.firstObjectOffset] objectsSection = self.decodedStream[self.firstObjectOffset:] numbers = re.findall('\d{1,10}', offsetsSection) if numbers != [] and len(numbers) % 2 == 0: for i in range(0,len(numbers),2): id = numbers[i] offset = numbers[i+1] ret = PDFParser.readObject(objectsSection[offset:]) if ret[0] == -1: if isForceMode: object = None self.addError(ret[1]) else: return ret else: object = ret[1] self.compressedObjectsDict[numbers[i]] = [offset,object] else: errorMessage = 'Missing offsets in object stream' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if errorMessage != '': return (-1,errorMessage) else: return (0,'') def setCompressedObjectId(self,id): ''' Sets the compressedIn attribute of the compressed object defined by its id @param id: The object id @return: A tuple (status,statusContent), where statusContent is empty in case status = 0 or an error message in case status = -1 ''' for compressedId in self.compressedObjectsDict: if self.compressedObjectsDict[compressedId] != None: object = self.compressedObjectsDict[compressedId][1] object.setCompressedIn(id) self.compressedObjectsDict[compressedId][1] = object else: return (-1,'Compressed object corrupted') return (0,'') class PDFIndirectObject : def __init__(self) : self.referenced = [] # int[] self.object = None # PDFObject self.offset = 0 # int self.generationNumber = 0 # int self.id = None # int self.size = 0 # int def contains(self, string): return self.object.contains(string) def getErrors(self): return self.object.getErrors() def getGenerationNumber(self): return self.generationNumber def getId(self): return self.id def getObject(self): return self.object def getOffset(self): return self.offset def getReferences(self): return self.object.getReferences() def getSize(self): return self.size def getStats(self): stats = self.object.getStats() if self.offset != -1: stats['Offset'] = str(self.offset) else: stats['Offset'] = None stats['Size'] = str(self.size) return stats def isFaulty(self): return self.object.isFaulty() def setGenerationNumber(self, generationNumber): self.generationNumber = generationNumber def setId(self, id): self.id = id def setObject(self, object): self.object = object def setOffset(self, offset): self.offset = offset def setSize(self, newSize): self.size = newSize def toFile(self): rawValue = self.object.toFile() output = str(self.id)+' '+str(self.generationNumber)+' obj' + newLine + rawValue + newLine + 'endobj' + newLine*2 self.size = len(output) return output class PDFCrossRefSection : def __init__(self) : self.errors = [] self.streamObject = None self.offset = 0 self.size = 0 self.subsections = [] # PDFCrossRefSubsection [] self.bytesPerField = [] def addEntry(self, objectId, newEntry): prevSubsection = 0 errorMessage = '' for i in range(len(self.subsections)): subsection = self.subsections[i] ret = subsection.addEntry(newEntry, objectId) if ret[0] != -1: break else: errorMessage = ret[1] self.addError(errorMessage) if subsection.getFirstObject() + subsection.getNumObjects() < objectId: prevSubsection = i else: try: newSubsection = PDFCrossRefSubSection(objectId, 1, [newEntry]) except: errorMessage = 'Error creating new PDFCrossRefSubSection' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) self.subsections.insert(prevSubsection, newSubsection) if errorMessage != '': return (-1,errorMessage) else: return (0,'') def addError(self, errorMessage): if errorMessage not in self.errors: self.errors.append(errorMessage) def addSubsection(self, subsection): self.subsections.append(subsection) def delEntry(self, objectId): prevSubsection = 0 errorMessage = '' for i in range(len(self.subsections)): subsection = self.subsections[i] numEntry = subsection.getIndex(objectId) if numEntry != None: if subsection.getNumObjects() == 1: self.subsections.remove(subsection) else: ret = subsection.delEntry(objectId) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) continue if errorMessage != '': return (-1,errorMessage) else: return (0,'') def getBytesPerField(self): return self.bytesPerField def getErrors(self): return self.errors def getFreeObjectIds(self): ids = [] for subsection in self.subsections: ids += subsection.getFreeObjectIds() return ids def getNewObjectIds(self): ids = [] for subsection in self.subsections: ids += subsection.getNewObjectIds() return ids def getOffset(self): return self.offset def getSize(self): return self.size def getStats(self): stats = {} if self.offset != -1: stats['Offset'] = str(self.offset) else: stats['Offset'] = None stats['Size'] = str(self.size) if self.inStream(): stats['Stream'] = str(self.streamObject) else: stats['Stream'] = None stats['Subsections'] = [] for i in range(len(self.subsections)): subsection = self.subsections[i] subStats = {} subStats['Entries'] = str(len(subsection.getEntries())) if subsection.isFaulty(): subStats['Errors'] = str(len(subsection.getErrors())) else: subStats['Errors'] = None stats['Subsections'].append(subStats) if self.isFaulty(): stats['Errors'] = str(len(self.errors)) else: stats['Errors'] = None return stats def getSubsectionsArray(self): return self.subsections def getSubsectionsNumber(self): return len(self.subsections) def getXrefStreamObject(self): return self.streamObject def isFaulty(self): if self.errors == []: return False else: return True def inStream(self): if self.streamObject != None: return True else: return False def setBytesPerField(self, array): self.bytesPerField = array def setOffset(self, offset): self.offset = offset def setSize(self, newSize): self.size = newSize def setXrefStreamObject(self, id): self.streamObject = id def toFile(self): output = 'xref' + newLine for subsection in self.subsections: output += subsection.toFile() return output def updateOffset(self, objectId, newOffset): for subsection in self.subsections: updatedEntry = subsection.getEntry(objectId) if updatedEntry != None: updatedEntry.setObjectOffset(newOffset) ret = subsection.setEntry(objectId, updatedEntry) if ret[0] == -1: self.addError(errorMessage) return ret else: errorMessage = 'Object entry not found' self.addError(errorMessage) return (-1,errorMessage) class PDFCrossRefSubSection: def __init__(self, firstObject, numObjects = 0, newEntries = [], offset = 0) : self.errors = [] self.offset = offset self.size = 0 self.firstObject = int(firstObject) self.numObjects = int(numObjects) self.entries = newEntries def addEntry(self, newEntry, objectId = None): if objectId == None: self.entries.append(newEntry) self.numObjects += 1 return (0,self.numObjects) else: numEntry = self.getIndex(objectId) if numEntry != None: self.entries.insert(numEntry, newEntry) self.numObjects += 1 return (0,self.numObjects) else: if self.firstObject == objectId + 1: self.entries.insert(0, newEntry) self.firstObject = objectId self.numObjects += 1 return (0,self.numObjects) elif objectId == self.firstObject + self.numObjects: self.entries.append(newEntry) self.numObjects += 1 return (0,self.numObjects) else: errorMessage = 'Unspecified error' self.addError(errorMessage) return (-1,errorMessage) return (0,self.numObjects) def addError(self, errorMessage): if errorMessage not in self.errors: self.errors.append(errorMessage) def delEntry(self, objectId): numEntry = self.getIndex(objectId) if numEntry == None: errorMessage = 'Entry not found' self.addError(errorMessage) return (-1,errorMessage) if numEntry == 0: self.entries.pop(numEntry) self.firstObject = objectId + 1 self.numObjects -= 1 elif numEntry == self.numObjects - 1: self.entries.pop(numEntry) self.numObjects -= 1 else: entry = self.entries[numEntry] numPrevFree = self.getPrevFree(numEntry) numNextFree = self.getNextFree(numEntry) nextObject = self.getObjectId(numNextFree) if numPrevFree != None: prevEntry = self.entries[numPrevFree] prevEntry.setNextObject(objectId) self.entries[numPrevFree] = prevEntry entry.setType('f') if nextObject == None: entry.setNextObject(0) else: entry.setNextObject(nextObject) entry.incGenNumber() self.entries[numEntry] = entry return (0,numEntry) def getEntries(self): return self.entries def getEntry(self, objectId): numEntry = self.getIndex(objectId) if numEntry != None: return self.entries[numEntry] else: return None def getErrors(self): return self.errors def getFirstObject(self): return self.firstObject def getFreeObjectIds(self): ids = [] for i in range(len(self.entries)): if self.entries[i].getType() == 'f': ids.append(self.getObjectId(i)) return ids def getIndex(self, objectId): objectIds = range(self.firstObject,self.firstObject+self.numObjects) if objectId in objectIds: return objectIds.index(objectId) else: return None def getNextFree(self, numEntry): for i in range(numEntry + 1,self.numObjects): if self.entries[i].getType() == 'f': return i else: return None def getNewObjectIds(self): ids = [] for i in range(len(self.entries)): if self.entries[i].getType() == 'n': ids.append(self.getObjectId(i)) return ids def getNumObjects(self): return self.numObjects def getObjectId(self, numEntry): return self.firstObject + numEntry def getOffset(self): return self.offset def getPrevFree(self, numEntry): for i in range(numEntry): if self.entries[i].getType() == 'f': return i else: return None def getSize(self): return self.size def isFaulty(self): if self.errors == []: return False else: return True def setEntry(self, objectId, newEntry): numEntry = self.getIndex(objectId) if numEntry != None: self.entries[numEntry] = newEntry return (0,numEntry) else: errorMessage = 'Entry not found' self.addError(errorMessage) return (-1,errorMessage) def setEntries(self, newEntries): self.entries = newEntries def setFirstObject(self, newFirst): self.firstObject = newFirst def setNumObjects(self, newNumObjects): self.numObjects = newNumObjects def setOffset(self, offset): self.offset = offset def setSize(self, newSize): self.size = newSize def toFile(self): output = str(self.firstObject) + ' ' + str(self.numObjects) + newLine for entry in self.entries: output += entry.toFile() return output class PDFCrossRefEntry: def __init__(self, firstValue, secondValue, type, offset = 0) : self.errors = [] self.offset = offset self.objectStream = None self.indexObject = None self.genNumber = None self.objectOffset = None self.nextObject = None self.entryType = type if type == 'f' or type == 0: self.nextObject = int(firstValue) self.genNumber = int(secondValue) elif type == 'n' or type == 1: self.objectOffset = int(firstValue) self.genNumber = int(secondValue) elif type == 2: self.objectStream = int(firstValue) self.indexObject = int(secondValue) else: if isForceMode: self.addError('Error parsing xref entry') else: return (-1,'Error parsing xref entry') def addError(self, errorMessage): if errorMessage not in self.errors: self.errors.append(errorMessage) def getEntryBytes(self, bytesPerField): bytesString = '' errorMessage = '' if self.entryType == 'f' or self.entryType == 0: type = 0 firstValue = self.nextObject secondValue = self.genNumber elif self.entryType == 'n' or self.entryType == 1: type = 1 firstValue = self.objectOffset secondValue = self.genNumber else: type = 2 firstValue = self.objectStream secondValue = self.indexObject if bytesPerField[0] != 0: ret = numToHex(type,bytesPerField[0]) if ret[0] == -1: errorMessage = ret[1] if isForceMode: self.addError(ret[1]) ret = numToHex(0,bytesPerField[0]) bytesString += ret[1] else: return ret else: bytesString += ret[1] if bytesPerField[1] != 0: ret = numToHex(firstValue,bytesPerField[1]) if ret[0] == -1: errorMessage = ret[1] if isForceMode: self.addError(ret[1]) ret = numToHex(0,bytesPerField[1]) bytesString += ret[1] else: return ret else: bytesString += ret[1] if bytesPerField[2] != 0: ret = numToHex(secondValue,bytesPerField[2]) if ret[0] == -1: errorMessage = ret[1] if isForceMode: self.addError(ret[1]) ret = numToHex(0,bytesPerField[1]) bytesString += ret[1] else: return ret else: bytesString += ret[1] if errorMessage != '': return (-1,errorMessage) return (0,bytesString) def getErrors(self): return self.errors def getGenNumber(self): return self.genNumber def getIndexObject(self): return self.indexObject def getNextObject(self): return self.nextObject def getObjectOffset(self): return self.objectOffset def getObjectStream(self): return self.objectStream def getOffset(self): return self.offset def getType(self): return self.entryType def incGenNumber(self): self.genNumber += 1 def isFaulty(self): if self.errors == []: return False else: return True def setGenNumber(self, newGenNumber): self.genNumber = newGenNumber def setIndexObject(self, index): self.indexObject = index def setNextObject(self, newNextObject): self.nextObject = newNextObject def setObjectOffset(self, newOffset): self.objectOffset = newOffset def setObjectStream(self, id): self.objectStream = id def setOffset(self, offset): self.offset = offset def setType(self, newType): self.entryType = newType def toFile(self): output = '' if self.entryType == 'n': ret = numToString(self.objectOffset,10) if ret[0] != -1: output += ret[1] elif self.entryType == 'f': ret = numToString(self.nextObject,10) if ret[0] != -1: output += ret[1] output += ' ' ret = numToString(self.genNumber, 5) if ret[0] != -1: output += ret[1] output += ' ' output += self.entryType if len(newLine) == 2: output += newLine else: output += ' ' + newLine return output class PDFBody : def __init__(self) : self.numObjects = 0 # int self.objects = {} # PDFIndirectObjects{} self.numStreams = 0 # int self.numEncodedStreams = 0 self.numDecodingErrors = 0 self.streams = [] self.nextOffset = 0 self.encodedStreams = [] self.faultyStreams = [] self.faultyObjects = [] self.containingJS = [] self.suspiciousEvents = {} self.suspiciousActions = {} self.suspiciousElements = {} self.vulns = {} self.JSCode = [] self.URLs = [] self.toUpdate = [] self.xrefStreams = [] self.objectStreams = [] self.compressedObjects = [] self.errors = [] def addCompressedObject(self, id): if id not in self.compressedObjects: self.compressedObjects.append(id) def addObjectStream(self, id): if id not in self.objectStreams: self.objectStreams.append(id) def addXrefStream(self, id): if id not in self.xrefStreams: self.xrefStreams.append(id) def containsCompressedObjects(self): if len(self.compressedObjects) > 0: return True else: return False def containsObjectStreams(self): if len(self.objectStreams) > 0: return True else: return False def containsXrefStreams(self): if len(self.xrefStreams) > 0: return True else: return False def delObject(self, id): if self.objects.has_key(id): indirectObject = self.objects[id] return self.deregisterObject(indirectObject) else: return None def deregisterObject(self, pdfIndirectObject): type = '' errorMessage = '' if pdfIndirectObject == None: errorMessage = 'Indirect Object is None' pdfFile.addError(errorMessage) return (-1,errorMessage) id = pdfIndirectObject.getId() if self.objects.has_key(id): self.objects.pop(id) pdfObject = pdfIndirectObject.getObject() if pdfObject == None: errorMessage = 'Object is None' pdfFile.addError(errorMessage) return (-1,errorMessage) objectType = pdfObject.getType() self.numObjects -= 1 if id in self.faultyObjects: self.faultyObjects.remove(id) self.updateStats(id,pdfObject,delete=True) if not pdfObject.updateNeeded: if objectType == 'stream': self.numStreams -= 1 if id in self.streams: self.streams.remove(id) if pdfObject.isEncoded(): if id in self.encodedStreams: self.encodedStreams.remove(id) self.numEncodedStreams -= 1 if id in self.faultyStreams: self.faultyStreams.remove(id) self.numDecodingErrors -= 1 if pdfObject.hasElement('/Type'): typeObject = pdfObject.getElementByName('/Type') if typeObject == None: errorMessage = '/Type element is None' if isForceMode: pdfFile.addError(errorMessage) else: return (-1,errorMessage) else: type = typeObject.getValue() if type == '/XRef': if id in self.xrefStreams: self.xrefStreams.remove(id) elif type == '/ObjStm': if id in self.objectStreams: self.objectStreams.remove(id) compressedObjectsDict = pdfObject.getCompressedObjects() for compressedId in compressedObjectsDict: if compressedId in self.compressedObjects: self.compressedObjects.remove(compressedId) self.delObject(compressedId) del(compressedObjectsDict) objectErrors = pdfObject.getErrors() if objectErrors != []: index = 0 errorsAux = list(self.errors) while True: if objectErrors[0] not in errorsAux: break indexAux = errorsAux.index(objectErrors[0]) if errorsAux[indexAux:indexAux+len(objectErrors)] == objectErrors: for i in range(len(objectErrors)): self.errors.pop(index+indexAux) break else: errorsAux = errorsAux[indexAux+len(objectErrors):] index = indexAux+len(objectErrors) if type == '': type = objectType if errorMessage != '': return (-1,errorMessage) return (0,type) def encodeChars(self): errorMessage = '' for id in self.objects: indirectObject = self.objects[id] if indirectObject != None: object = indirectObject.getObject() if object != None: objectType = object.getType() if objectType in ['string','name','array','dictionary','stream']: ret = object.encodeChars() if ret[0] == -1: errorMessage = ret[1] pdfFile.addError(errorMessage) indirectObject.setObject(object) self.deregisterObject(indirectObject) self.registerObject(indirectObject) else: errorMessage = 'Bad object found while encoding strings' pdfFile.addError(errorMessage) else: errorMessage = 'Bad indirect object found while encoding strings' pdfFile.addError(errorMessage) if errorMessage != '': return (-1,typeObject) return (0,'') def getCompressedObjects(self): return self.compressedObjects def getContainingJS(self): return self.containingJS def getEncodedStreams(self): return self.encodedStreams def getFaultyObjects(self): return self.faultyObjects def getFaultyStreams(self): return self.faultyStreams def getIndirectObject(self, id): if self.objects.has_key(id): return self.objects[id] else: return None def getJSCode(self): return self.JSCode def getNextOffset(self): return self.nextOffset def getNumDecodingErrors(self): return self.numDecodingErrors def getNumEncodedStreams(self): return self.numEncodedStreams def getNumFaultyObjects(self): return len(self.faultyObjects) def getNumObjects(self): return self.numObjects def getNumStreams(self): return self.numStreams def getObject(self, id, indirect = False): if self.objects.has_key(id): indirectObject = self.objects[id] if indirect: return indirectObject else: return indirectObject.getObject() else: return None def getObjects(self): return self.objects def getObjectsByString (self, toSearch) : matchedObjects = [] for indirectObject in self.objects.values(): if indirectObject.contains(toSearch): matchedObjects.append(indirectObject.getId()) return matchedObjects def getObjectsIds(self): sortedIdsOffsets = [] sortedIds = [] for indirectObject in self.objects.values(): sortedIdsOffsets.append([indirectObject.getId(),indirectObject.getOffset()]) sortedIdsOffsets = sorted(sortedIdsOffsets, key=lambda x: x[1]) for i in range(len(sortedIdsOffsets)): sortedIds.append(sortedIdsOffsets[i][0]) return sortedIds def getObjectStreams(self): return self.objectStreams def getStreams(self): return self.streams def getSuspiciousActions(self): return self.suspiciousActions def getSuspiciousElements(self): return self.suspiciousElements def getSuspiciousEvents(self): return self.suspiciousEvents def getURLs(self): return self.URLs def getVulns(self): return self.vulns def getXrefStreams(self): return self.xrefStreams def registerObject(self, pdfIndirectObject): type = '' errorMessage = '' if pdfIndirectObject == None: errorMessage = 'Indirect Object is None' pdfFile.addError(errorMessage) return (-1,errorMessage) id = pdfIndirectObject.getId() pdfObject = pdfIndirectObject.getObject() if pdfObject == None: errorMessage = 'Object is None' pdfFile.addError(errorMessage) return (-1,errorMessage) objectType = pdfObject.getType() self.numObjects += 1 if pdfObject.isFaulty(): self.faultyObjects.append(id) ret = self.updateStats(id,pdfObject) if ret[0] == -1: errorMessage = ret[1] if pdfObject.updateNeeded: self.toUpdate.append(id) else: if objectType == 'stream': self.numStreams += 1 self.streams.append(id) if pdfObject.isEncoded(): self.encodedStreams.append(id) self.numEncodedStreams += 1 if pdfObject.isFaultyDecoding(): self.faultyStreams.append(id) self.numDecodingErrors += 1 if pdfObject.hasElement('/Type'): typeObject = pdfObject.getElementByName('/Type') if typeObject == None: errorMessage = '/Type element is None' if isForceMode: pdfFile.addError(errorMessage) else: return (-1,errorMessage) else: type = typeObject.getValue() if type == '/XRef': self.addXrefStream(id) elif type == '/ObjStm': self.addObjectStream(id) pdfObject.setCompressedObjectId(id) compressedObjectsDict = pdfObject.getCompressedObjects() for compressedId in compressedObjectsDict: self.addCompressedObject(compressedId) offset = compressedObjectsDict[compressedId][0] compressedObject = compressedObjectsDict[compressedId][1] self.setObject(compressedId, compressedObject, offset) del(compressedObjectsDict) pdfIndirectObject.setObject(pdfObject) self.objects[id] = pdfIndirectObject self.errors += pdfObject.getErrors() if type == '': type = objectType if errorMessage != '': return (-1,errorMessage) return (0,type) def setNextOffset(self, newOffset): self.nextOffset = newOffset def setObject(self, id = None, object = None, offset = None, modification = False): errorMessage = '' if self.objects.has_key(id): pdfIndirectObject = self.objects[id] self.deregisterObject(pdfIndirectObject) pdfIndirectObject.setObject(object) if offset != None: pdfIndirectObject.setOffset(offset) size = 12 + 3*len(newLine) + len(str(object.getRawValue())) + len(str(id)) pdfIndirectObject.setSize(size) else: if modification: errorMessage = 'Object not found' if isForceMode: pdfFile.addError(errorMessage) else: return (-1,errorMessage) if id == None: id = self.numObjects+1 if offset == None: offset = self.getNextOffset() pdfIndirectObject = PDFIndirectObject() pdfIndirectObject.setId(id) pdfIndirectObject.setObject(object) pdfIndirectObject.setGenerationNumber(0) pdfIndirectObject.setOffset(offset) size = 12 + 3*len(newLine) + len(str(object.getRawValue())) + len(str(id)) pdfIndirectObject.setSize(size) self.setNextOffset(offset+size) ret = self.registerObject(pdfIndirectObject) if ret[0] == 0: if errorMessage != '': return (-1,errorMessage) else: objectType = ret[1] return (0,[id,objectType]) else: return ret def setObjects(self, objects): self.objects = objects def updateObjects(self): errorMessage = '' for id in self.toUpdate: updatedElements = {} object = self.objects[id].getObject() if object == None: errorMessage = 'Object is None' if isForceMode: pdfFile.addError(errorMessage) continue else: return (-1,errorMessage) elementsToUpdate = object.getReferencesInElements() keys = elementsToUpdate.keys() for key in keys: ref = elementsToUpdate[key] refId = ref[0] if refId in self.objects: refObject = self.objects[refId].getObject() if refObject == None: errorMessage = 'Referenced object is None' if isForceMode: pdfFile.addError(errorMessage) continue else: return (-1,errorMessage) ref[1] = refObject.getValue() updatedElements[key] = ref else: errorMessage = 'Referenced object not found' if isForceMode: pdfFile.addError(errorMessage) continue else: return (-1,errorMessage) object.setReferencesInElements(updatedElements) object.resolveReferences() if object.getType() == 'stream': self.numStreams += 1 self.streams.append(id) if object.isEncoded(): self.encodedStreams.append(id) self.numEncodedStreams += 1 if object.isFaultyDecoding(): self.faultyStreams.append(id) self.numDecodingErrors += 1 if object.hasElement('/Type'): typeObject = object.getElementByName('/Type') if typeObject == None: errorMessage = 'Referenced element is None' if isForceMode: pdfFile.addError(errorMessage) continue else: return (-1,errorMessage) else: type = typeObject.getValue() if type == '/XRef': self.addXrefStream(id) elif type == '/ObjStm': self.addObjectStream(id) object.setCompressedObjectId(id) compressedObjectsDict = object.getCompressedObjects() for compressedId in compressedObjectsDict: self.addCompressedObject(compressedId) offset = compressedObjectsDict[compressedId][0] compressedObject = compressedObjectsDict[compressedId][1] self.setObject(compressedId, compressedObject, offset) del(compressedObjectsDict) if errorMessage != '': return (-1,errorMessage) return (0,'') def updateOffsets (self) : pass def updateStats(self, id, pdfObject, delete = False): if pdfObject == None: errorMessage = 'Object is None' pdfFile.addError(errorMessage) return (-1,errorMessage) value = pdfObject.getValue() for event in monitorizedEvents: if value.find(event) != -1: printedEvent = event.strip() if self.suspiciousEvents.has_key(printedEvent): if delete: if id in self.suspiciousEvents[printedEvent]: self.suspiciousEvents[printedEvent].remove(id) elif id not in self.suspiciousEvents[printedEvent]: self.suspiciousEvents[printedEvent].append(id) elif not delete: self.suspiciousEvents[printedEvent] = [id] for action in monitorizedActions: index = value.find(action) if index != -1 and (action == '/JS ' or len(value) == index + len(action) or value[index+len(action)] in delimiterChars+spacesChars): printedAction = action.strip() if self.suspiciousActions.has_key(printedAction): if delete: if id in self.suspiciousActions[printedAction]: self.suspiciousActions[printedAction].remove(id) elif id not in self.suspiciousActions[printedAction]: self.suspiciousActions[printedAction].append(id) elif not delete: self.suspiciousActions[printedAction] = [id] for element in monitorizedElements: index = value.find(element) if index != -1 and (element == '/EmbeddedFiles ' or len(value) == index + len(element) or value[index+len(element)] in delimiterChars+spacesChars): printedElement = element.strip() if self.suspiciousElements.has_key(printedElement): if delete: if id in self.suspiciousElements[printedElement]: self.suspiciousElements[printedElement].remove(id) elif id not in self.suspiciousElements[printedElement]: self.suspiciousElements[printedElement].append(id) elif not delete: self.suspiciousElements[printedElement] = [id] if pdfObject.containsJS(): if delete: jsCodeArray = pdfObject.getJSCode() if id in self.containingJS: self.containingJS.remove(id) for jsCode in jsCodeArray: if jsCode in self.JSCode: self.JSCode.remove(jsCode) for vuln in jsVulns: if jsCode.find(vuln) != -1: if self.vulns.has_key(vuln) and id in self.vulns[vuln]: self.vulns[vuln].remove(id) else: jsCode = pdfObject.getJSCode() if id not in self.containingJS: self.containingJS.append(id) for js in jsCode: if js not in self.JSCode: self.JSCode.append(js) for code in jsCode: for vuln in jsVulns: if code.find(vuln) != -1: if self.vulns.has_key(vuln): self.vulns[vuln].append(id) else: self.vulns[vuln] = [id] ## Extra checks objectType = pdfObject.getType() if objectType == 'stream': vulnFound = None streamContent = pdfObject.getStream() if len(streamContent) > 327 and streamContent[236:240] == 'SING' and streamContent[327] != '\0': # CVE-2010-2883 # http://opensource.adobe.com/svn/opensource/tin/src/SING.cpp # http://community.websense.com/blogs/securitylabs/archive/2010/09/10/brief-analysis-on-adobe-reader-sing-table-parsing-vulnerability-cve-2010-2883.aspx vulnFound = singUniqueName elif streamContent.count('AAL/AAAC/wAAAv8A') > 1000: # CVE-2013-2729 # Adobe Reader BMP/RLE heap corruption # http://blog.binamuse.com/2013/05/readerbmprle.html vulnFound = bmpVuln if vulnFound != None: if self.suspiciousElements.has_key(vulnFound): if delete: if id in self.suspiciousElements[vulnFound]: self.suspiciousElements[vulnFound].remove(id) elif id not in self.suspiciousElements[vulnFound]: self.suspiciousElements[vulnFound].append(id) elif not delete: self.suspiciousElements[vulnFound] = [id] return (0,'') class PDFTrailer : def __init__(self, dict, lastCrossRefSection = '0', streamPresent = False): self.errors = [] self.dict = dict self.offset = 0 self.eofOffset = 0 self.size = 0 self.streamObject = None self.catalogId = None self.numObjects = None self.id = None self.infoId = None self.lastCrossRefSection = int(lastCrossRefSection) ret = self.update(streamPresent) if ret[0] == -1: if isForceMode: self.addError(ret[1]) else: raise Exception(ret[1]) def update(self, streamPresent = False): errorMessage = '' if self.dict == None: errorMessage = 'The trailer dictionary is None' self.addError(errorMessage) return (-1,errorMessage) if self.dict.hasElement('/Root'): reference = self.dict.getElementByName('/Root') if reference != None: if reference.getType() == 'reference': self.catalogId = reference.getId() else: errorMessage = 'No reference element in /Root' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: errorMessage = 'No reference element in /Root' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: if not streamPresent: errorMessage = 'Missing /Root element' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if self.dict.hasElement('/Size'): size = self.dict.getElementByName('/Size') if size != None: if size.getType() == 'integer': self.numObjects = size.getRawValue() else: errorMessage = 'No integer element in /Size' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: errorMessage = 'No integer element in /Size' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: if not streamPresent: errorMessage = 'Missing /Size element' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if self.dict.hasElement('/Info'): info = self.dict.getElementByName('/Info') if info != None: if info.getType() == 'reference': self.infoId = info.getId() else: errorMessage = 'No reference element in /Info' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) else: errorMessage = 'No reference element in /Info' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) if self.dict.hasElement('/ID'): arrayID = self.dict.getElementByName('/ID') if arrayID != None: if arrayID.getType() == 'array': self.id = arrayID.getRawValue() if errorMessage != '': return (-1,errorMessage) return (0,'') def addError(self, errorMessage): if errorMessage not in self.errors: self.errors.append(errorMessage) def encodeChars(self): ret = self.dict.encodeChars() if ret[0] == -1: self.addError(ret[1]) return ret def getCatalogId(self): return self.catalogId def getDictEntry(self, name): if self.dict.hasElement(name): return self.dict.getElementByName(name) else: return None def getEOFOffset(self): return self.eofOffset def getErrors(self): return self.errors def getID(self): return self.id def getInfoId(self): return self.infoId def getLastCrossRefSection(self): return self.lastCrossRefSection def getNumObjects(self): return self.numObjects def getOffset(self): return self.offset def getPrevCrossRefSection(self): return self.dict.getElementByName('/Prev') def getSize(self): return self.size def getStats(self): stats = {} if self.offset != -1: stats['Offset'] = str(self.offset) else: stats['Offset'] = None stats['Size'] = str(self.size) if self.inStream(): stats['Stream'] = str(self.streamObject) else: stats['Stream'] = None stats['Objects'] = str(self.numObjects) if self.dict.hasElement('/Root'): stats['Root Object'] = str(self.catalogId) else: stats['Root Object'] = None self.addError('/Root element not found') if self.dict.hasElement('/Info'): stats['Info Object'] = str(self.infoId) else: stats['Info Object'] = None if self.dict.hasElement('/ID') and self.id != None and self.id != '' and self.id != ' ': stats['ID'] = self.id else: stats['ID'] = None if self.dict.hasElement('/Encrypt'): if self.getDictEntry('/Encrypt').getType() == 'dictionary': stats['Encrypted'] = True else: stats['Encrypted'] = False self.addError('Bad type for /Encrypt element') else: stats['Encrypted'] = False if self.isFaulty(): stats['Errors'] = str(len(self.errors)) else: stats['Errors'] = None return stats def getTrailerDictionary(self): return self.dict def getXrefStreamObject(self): return self.streamObject def inStream(self): if self.streamObject != None: return True else: return False def isFaulty(self): if self.errors == []: return False else: return True def setCatalogId(self, newId): self.catalogId = newId def setDictEntry(self, entry, value): ret = self.dict.setElement(entry,value) if ret[0] == -1: errorMessage = ret[1]+' in dictionary element' self.addError(errorMessage) return (-1,errorMessage) return ret def setEOFOffset(self, offset): self.eofOffset = offset def setInfoId(self, newId): self.infoId = newId def setID(self, newId): self.id = newId def setLastCrossRefSection(self, newOffset): self.lastCrossRefSection = newOffset def setNumObjects(self, newNumObjects): self.numObjects = newNumObjects try: size = PDFNum(str(newNumObjects)) except: errorMessage = 'Error creating PDFNum' if isForceMode: self.addError(errorMessage) size = PDFNum('0') else: return (-1,errorMessage) ret = self.setDictEntry('/Size', size) return ret def setOffset(self, offset): self.offset = offset def setPrevCrossRefSection(self, newOffset): try: prevSectionObject = PDFNum(str(newOffset)) except: errorMessage = 'Error creating PDFNum' if isForceMode: self.addError(errorMessage) prevSectionObject = PDFNum('0') else: return (-1,errorMessage) ret = self.dict.setElement('/Prev', prevSectionObject) if ret[0] == -1: errorMessage = ret[1]+' in dictionary element' self.addError(errorMessage) return (-1,errorMessage) return ret def setSize(self, newSize): self.size = newSize def setTrailerDictionary(self, newDict): self.dict = newDict ret = self.update() return ret def setXrefStreamObject(self, id): self.streamObject = id def toFile(self): output = '' if self.dict.getNumElements() > 0: output += 'trailer' + newLine output += self.dict.toFile() + newLine output += 'startxref' + newLine output += str(self.lastCrossRefSection) + newLine output += '%%EOF' + newLine return output class PDFFile : def __init__(self) : self.fileName = '' self.path = '' self.size = 0 self.md5 = '' self.sha1 = '' self.sha256 = '' self.detectionRate = [] self.detectionReport = '' self.body = [] # PDFBody[] self.binary = False self.binaryChars = '' self.linearized = False self.encryptDict = None self.encrypted = False self.fileId = '' self.encryptionAlgorithms = [] self.encryptionKey = '' self.encryptionKeyLength = 128 self.ownerPass = '' self.userPass = '' self.JSCode = '' self.crossRefTable = [] # PDFCrossRefSection[] self.comments = [] # string[] self.version = '' self.headerOffset = 0 self.garbageHeader = '' self.suspiciousElements = {} self.updates = 0 self.endLine = '' self.trailer = [] # PDFTrailer[] self.errors = [] self.numObjects = 0 self.numStreams = 0 self.numEncodedStreams = 0 self.numDecodingErrors = 0 self.maxObjectId = 0 def addBody(self, newBody): if newBody != None and isinstance(newBody,PDFBody): self.body.append(newBody) return (0,'') else: return (-1,'Bad PDFBody supplied') def addCrossRefTableSection(self, newSectionArray): if newSectionArray != None and isinstance(newSectionArray,list) and len(newSectionArray) == 2 and (newSectionArray[0] == None or isinstance(newSectionArray[0],PDFCrossRefSection)) and (newSectionArray[1] == None or isinstance(newSectionArray[1],PDFCrossRefSection)): self.crossRefTable.append(newSectionArray) return (0,'') else: return (-1,'Bad PDFCrossRefSection array supplied') def addError(self, errorMessage): if errorMessage not in self.errors: self.errors.append(errorMessage) def addNumDecodingErrors(self, num): self.numDecodingErrors += num def addNumEncodedStreams(self, num): self.numEncodedStreams += num def addNumObjects(self, num): self.numObjects += num def addNumStreams(self, num): self.numStreams += num def addTrailer(self, newTrailerArray): if newTrailerArray != None and isinstance(newTrailerArray,list) and len(newTrailerArray) == 2 and (newTrailerArray[0] == None or isinstance(newTrailerArray[0],PDFTrailer)) and (newTrailerArray[1] == None or isinstance(newTrailerArray[1],PDFTrailer)): self.trailer.append(newTrailerArray) return (0,'') else: return (-1,'Bad PDFTrailer array supplied') def createObjectStream(self, version = None, id = None, objectIds = []): errorMessage = '' tmpStreamObjects = '' tmpStreamObjectsInfo = '' compressedStream = '' compressedDict = {} firstObjectOffset = '' if version == None: version = self.updates if objectIds == []: objectIds = self.body[version].getObjectsIds() numObjects = len(objectIds) if id == None: id = self.maxObjectId + 1 for compressedId in objectIds: object = self.body[version].getObject(compressedId) if object == None: errorMessage = 'Object '+str(compressedId)+' cannot be compressed: it does not exist' if isForceMode: self.addError(errorMessage) numObjects -= 1 else: return (-1,errorMessage) else: objectType = object.getType() if objectType == 'stream': errorMessage = 'Stream objects cannot be compressed' self.addError(errorMessage) numObjects -= 1 else: if objectType == 'dictionary' and object.hasElement('/U') and object.hasElement('/O') and object.hasElement('/R'): errorMessage = 'Encryption dictionaries cannot be compressed' self.addError(errorMessage) numObjects -= 1 object.setCompressedIn(id) offset = len(tmpStreamObjects) tmpStreamObjectsInfo += str(compressedId)+' '+str(offset)+' ' tmpStreamObjects += object.toFile() ret = self.body[version].setObject(compressedId,object,offset,modification = True) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) firstObjectOffset = str(len(tmpStreamObjectsInfo)) compressedStream = tmpStreamObjectsInfo + tmpStreamObjects compressedDict = {'/Type':PDFName('ObjStm'),'/N':PDFNum(str(numObjects)),'/First':PDFNum(firstObjectOffset),'/Length':PDFNum(str(len(compressedStream)))} try: objectStream = PDFObjectStream('',compressedStream,compressedDict,{},{}) except Exception,e: errorMessage = 'Error creating PDFObjectStream' if e.message != '': errorMessage += ': '+e.message self.addError(errorMessage) return (-1,errorMessage) # Filters filterObject = PDFName('FlateDecode') ret = objectStream.setElement('/Filter',filterObject) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) objectStreamOffset = self.body[version].getNextOffset() if self.encrypted: ret = computeObjectKey(id, 0, self.encryptionKey, self.encryptionKeyLength/8) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) else: key = ret[1] ret = objectStream.encrypt(key) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) self.body[version].setNextOffset(objectStreamOffset+len(objectStream.getRawValue())) self.body[version].setObject(id,objectStream,objectStreamOffset) # Xref stream ret = self.createXrefStream(version) if ret[0] == -1: return ret xrefStreamId, xrefStream = ret[1] xrefStreamOffset = self.body[version].getNextOffset() ret = self.body[version].setObject(xrefStreamId,xrefStream,xrefStreamOffset) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) self.binary = True self.binaryChars = '\xC0\xFF\xEE\xFA\xBA\xDA' if errorMessage != '': return (-1,errorMessage) return (0,id) def createXrefStream(self, version, id = None): size = 0 elementsDict = {} elementsTrailerDict = {} stream = '' errorMessage = '' indexArray = [] xrefStream = None xrefStreamId = None bytesPerFieldArray = [] if version == None: version = self.updates # Trailer update if len(self.trailer) > version: if self.trailer[version][1] != None: trailerDict = self.trailer[version][1].getTrailerDictionary() if trailerDict != None: elementsTrailerDict = dict(trailerDict.getElements()) elementsDict = dict(elementsTrailerDict) del(trailerDict) if self.trailer[version][0] != None: trailerDict = self.trailer[version][0].getTrailerDictionary() if trailerDict != None: trailerElementsDict = dict(trailerDict.getElements()) if len(trailerElementsDict) > 0: for key in trailerElementsDict: if key not in elementsTrailerDict: elementsTrailerDict[key] = trailerElementsDict[key] elementsDict[key] = trailerElementsDict[key] del(trailerElementsDict) del(trailerDict) self.createXrefStreamSection(version) if len(self.crossRefTable) <= version: errorMessage = 'Cross Reference Table not found' self.addError(errorMessage) return (-1,errorMessage) section = self.crossRefTable[version][1] xrefStreamId = section.getXrefStreamObject() bytesPerField = section.getBytesPerField() for num in bytesPerField: try: bytesPerFieldArray.append(PDFNum(str(num))) except: errorMessage = 'Error creating PDFNum in bytesPerField' return (-1,errorMessage) subsectionsNumber = section.getSubsectionsNumber() subsections = section.getSubsectionsArray() for subsection in subsections: firstObject = subsection.getFirstObject() numObjects = subsection.getNumObjects() indexArray.append(PDFNum(str(firstObject))) indexArray.append(PDFNum(str(numObjects))) entries = subsection.getEntries() for entry in entries: ret = entry.getEntryBytes(bytesPerField) if ret[0] == -1: self.addError(ret[1]) return (-1,ret[1]) stream += ret[1] if size < firstObject + numObjects: size = firstObject + numObjects elementsDict['/Type'] = PDFName('XRef') elementsDict['/Size'] = PDFNum(str(size)) elementsTrailerDict['/Size'] = PDFNum(str(size)) elementsDict['/Index'] = PDFArray('',indexArray) elementsDict['/W'] = PDFArray('',bytesPerFieldArray) elementsDict['/Length'] = PDFNum(str(len(stream))) try: xrefStream = PDFStream('',stream,elementsDict,{}) except Exception,e: errorMessage = 'Error creating PDFStream' if e.message != '': errorMessage += ': '+e.message self.addError(errorMessage) return (-1,errorMessage) # Filters filterObject = PDFName('FlateDecode') if id != None: xrefStreamObject = self.getObject(id, version) if xrefStreamObject != None: filterObject = xrefStreamObject.getElementByName('/Filter') ret = xrefStream.setElement('/Filter',filterObject) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) try: trailerStream = PDFTrailer(PDFDictionary(elements=elementsTrailerDict)) except Exception,e: errorMessage = 'Error creating PDFTrailer' if e.message != '': errorMessage += ': '+e.message self.addError(errorMessage) return (-1,errorMessage) trailerStream.setXrefStreamObject(xrefStreamId) try: trailerSection = PDFTrailer(PDFDictionary(elements=dict(elementsTrailerDict)))#PDFDictionary()) except Exception,e: errorMessage = 'Error creating PDFTrailer' if e.message != '': errorMessage += ': '+e.message self.addError(errorMessage) return (-1,errorMessage) self.trailer[version] = [trailerSection,trailerStream] if errorMessage != '': return (-1,errorMessage) return (0,[xrefStreamId,xrefStream]) def createXrefStreamSection(self, version = None): lastId = 0 lastFreeObject = 0 errorMessage = '' xrefStreamId = None xrefEntries = [PDFCrossRefEntry(0,65535,0)] if version == None: version = self.updates actualStream = self.crossRefTable[version][1] if actualStream != None: xrefStreamId = actualStream.getXrefStreamObject() sortedObjectsByOffset = self.body[version].getObjectsIds() sortedObjectsIds = sorted(sortedObjectsByOffset, key=lambda x: int(x)) indirectObjects = self.body[version].getObjects() for id in sortedObjectsIds: while id != lastId+1: lastFreeEntry = xrefEntries[lastFreeObject] lastFreeEntry.setNextObject(lastId+1) xrefEntries[lastFreeObject] = lastFreeEntry lastFreeObject = lastId+1 lastId += 1 xrefEntries.append(PDFCrossRefEntry(0,65535,0)) indirectObject = indirectObjects[id] if indirectObject != None: object = indirectObject.getObject() if object != None: if object.isCompressed(): objectStreamId = object.getCompressedIn() objectStream = self.body[version].getObject(objectStreamId) index = objectStream.getObjectIndex(id) if index == None: errorMessage = 'Compressed object not found in object stream' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) entry = PDFCrossRefEntry(objectStreamId,index,2) else: offset = indirectObject.getOffset() entry = PDFCrossRefEntry(offset,0,1) xrefEntries.append(entry) lastId = id if actualStream == None: offset += len(str(object.getRawValue())) xrefEntries.append(PDFCrossRefEntry(offset,0,1)) lastId += 1 xrefStreamId = lastId subsection = PDFCrossRefSubSection(0,lastId+1,xrefEntries) xrefSection = PDFCrossRefSection() xrefSection.addSubsection(subsection) xrefSection.setXrefStreamObject(xrefStreamId) xrefSection.setBytesPerField([1,2,2]) self.crossRefTable[version] = [None,xrefSection] if errorMessage != '': return (-1,errorMessage) return (0,lastId) def decrypt(self, password = ''): badPassword = False fatalError = False errorMessage = '' passType = None encryptionAlgorithms = [] algorithm = None stmAlgorithm = None strAlgorithm = None embedAlgorithm = None computedUserPass = '' dictO = '' dictU = '' perm = 0 revision = 0 fileId = self.getFileId() self.removeError(errorType = 'Decryption error') if self.encryptDict == None or self.encryptDict[1] == []: errorMessage = 'Decryption error: /Encrypt dictionary not found!!' if isForceMode: self.addError(errorMessage) else: return (-1,errorMessage) # Getting /Encrypt elements encDict = self.encryptDict[1] # Filter if encDict.has_key('/Filter'): filter = encDict['/Filter'] if filter != None and filter.getType() == 'name': filter = filter.getValue() if filter != '/Standard': errorMessage = 'Decryption error: Filter not supported!!' if isForceMode: fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: Bad format for /Filter!!' if isForceMode: fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: Filter not found!!' if isForceMode: fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) # Algorithm version if encDict.has_key('/V'): algVersion = encDict['/V'] if algVersion != None and algVersion.getType() == 'integer': algVersion = algVersion.getRawValue() if algVersion == 4 or algVersion == 5: stmAlgorithm = ['Identity',40] strAlgorithm = ['Identity',40] embedAlgorithm = ['Identity',40] algorithms = {} if encDict.has_key('/CF'): cfDict = encDict['/CF'] if cfDict != None and cfDict.getType() == 'dictionary': cfDict = cfDict.getElements() for cryptFilter in cfDict: cryptFilterDict = cfDict[cryptFilter] if cryptFilterDict != None and cryptFilterDict.getType() == 'dictionary': algorithms[cryptFilter] = [] defaultKeyLength = 40 cfmValue = '' cryptFilterDict = cryptFilterDict.getElements() if cryptFilterDict.has_key('/CFM'): cfmValue = cryptFilterDict['/CFM'] if cfmValue != None and cfmValue.getType() == 'name': cfmValue = cfmValue.getValue() if cfmValue == 'None': algorithms[cryptFilter].append('Identity') elif cfmValue == '/V2': algorithms[cryptFilter].append('RC4') elif cfmValue == '/AESV2': algorithms[cryptFilter].append('AES') defaultKeyLength = 128 elif cfmValue == '/AESV3': algorithms[cryptFilter].append('AES') defaultKeyLength = 256 else: errorMessage = 'Decryption error: Unsupported encryption!!' if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: Bad format for /CFM!!' if isForceMode: cfmValue = '' self.addError(errorMessage) else: return (-1, errorMessage) if cryptFilterDict.has_key('/Length') and cfmValue != '/AESV3': # Length is key length in bits keyLength = cryptFilterDict['/Length'] if keyLength != None and keyLength.getType() == 'integer': keyLength = keyLength.getRawValue() if keyLength % 8 != 0: keyLength = defaultKeyLength self.addError('Decryption error: Key length not valid!!') # Check if the length element contains bytes instead of bits as usual if keyLength < 40: keyLength *= 8 else: keyLength = defaultKeyLength self.addError('Decryption error: Bad format for /Length!!') else: keyLength = defaultKeyLength algorithms[cryptFilter].append(keyLength) else: errorMessage = 'Decryption error: Bad format for /CF!!' if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) if encDict.has_key('/StmF'): stmF = encDict['/StmF'] if stmF != None and stmF.getType() == 'name': stmF = stmF.getValue() if stmF in algorithms: stmAlgorithm = algorithms[stmF] else: errorMessage = 'Decryption error: Bad format for /StmF!!' if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) if encDict.has_key('/StrF'): strF = encDict['/StrF'] if strF != None and strF.getType() == 'name': strF = strF.getValue() if strF in algorithms: strAlgorithm = algorithms[strF] else: errorMessage = 'Decryption error: Bad format for /StrF!!' if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) if encDict.has_key('/EEF'): eeF = encDict['/EEF'] if eeF != None and eeF.getType() == 'name': eeF = eeF.getValue() if eeF in algorithms: embedAlgorithm = algorithms[eeF] else: embedAlgorithm = stmAlgorithm errorMessage = 'Decryption error: Bad format for /EEF!!' if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) else: embedAlgorithm = stmAlgorithm if stmAlgorithm not in encryptionAlgorithms: encryptionAlgorithms.append(stmAlgorithm) if strAlgorithm not in encryptionAlgorithms: encryptionAlgorithms.append(strAlgorithm) if embedAlgorithm not in encryptionAlgorithms and embedAlgorithm != ['Identity',40]: # Not showing default embedAlgorithm encryptionAlgorithms.append(embedAlgorithm) else: errorMessage = 'Decryption error: Bad format for /V!!' if isForceMode: algVersion = 0 self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: Algorithm version not found!!' if isForceMode: algVersion = 0 self.addError(errorMessage) else: return (-1, errorMessage) # Key length if encDict.has_key('/Length'): keyLength = encDict['/Length'] if keyLength != None and keyLength.getType() == 'integer': keyLength = keyLength.getRawValue() if keyLength % 8 != 0: keyLength = 40 self.addError('Decryption error: Key length not valid!!') else: keyLength = 40 self.addError('Decryption error: Bad format for /Length!!') else: keyLength = 40 # Setting algorithms if algVersion == 1 or algVersion == 2: algorithm = ['RC4',keyLength] stmAlgorithm = strAlgorithm = embedAlgorithm = algorithm elif algVersion == 3: errorMessage = 'Decryption error: Algorithm not supported!!' if isForceMode: algorithm = ['Unpublished',keyLength] stmAlgorithm = strAlgorithm = embedAlgorithm = algorithm self.addError(errorMessage) else: return (-1, errorMessage) elif algVersion == 5: algorithm = ['AES',256] if algorithm != None and algorithm not in encryptionAlgorithms: encryptionAlgorithms.append(algorithm) self.setEncryptionAlgorithms(encryptionAlgorithms) # Standard encryption: /R /P /O /U # Revision if encDict.has_key('/R'): revision = encDict['/R'] if revision != None and revision.getType() == 'integer': revision = revision.getRawValue() if revision < 2 or revision > 5: errorMessage = 'Decryption error: Algorithm revision not supported!!' if isForceMode: fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: Bad format for /R!!' if isForceMode: revision = 0 fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: Algorithm revision not found!!' if isForceMode: fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) # Permission if encDict.has_key('/P'): perm = encDict['/P'] if perm != None and perm.getType() == 'integer': perm = perm.getRawValue() else: errorMessage = 'Decryption error: Bad format for /P!!' if isForceMode: perm = 0 fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: Permission number not found!!' if isForceMode: fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) # Owner pass if encDict.has_key('/O'): dictO = encDict['/O'] if dictO != None and dictO.getType() in ['string','hexstring']: dictO = dictO.getValue() else: errorMessage = 'Decryption error: Bad format for /O!!' if isForceMode: dictO = '' fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: Owner password not found!!' if isForceMode: fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) # Owner encrypted string if encDict.has_key('/OE'): dictOE = encDict['/OE'] if dictOE != None and dictOE.getType() in ['string','hexstring']: dictOE = dictOE.getValue() else: errorMessage = 'Decryption error: Bad format for /OE!!' if isForceMode: dictOE = '' self.addError(errorMessage) else: return (-1, errorMessage) else: dictOE = '' if revision == 5: errorMessage = 'Decryption error: /OE not found!!' if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) # User pass if encDict.has_key('/U'): dictU = encDict['/U'] if dictU != None and dictU.getType() in ['string','hexstring']: dictU = dictU.getValue() else: errorMessage = 'Decryption error: Bad format for /U!!' if isForceMode: dictU = '' fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: User password not found!!' if isForceMode: fatalError = True self.addError(errorMessage) else: return (-1, errorMessage) # User encrypted string if encDict.has_key('/UE'): dictUE = encDict['/UE'] if dictUE != None and dictUE.getType() in ['string','hexstring']: dictUE = dictUE.getValue() else: errorMessage = 'Decryption error: Bad format for /UE!!' if isForceMode: dictUE = '' self.addError(errorMessage) else: return (-1, errorMessage) else: dictUE = '' if revision == 5: errorMessage = 'Decryption error: /UE not found!!' if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) # Metadata encryption if encDict.has_key('/EncryptMetadata'): encryptMetadata = encDict['/EncryptMetadata'] if encryptMetadata != None and encryptMetadata.getType() == 'bool': encryptMetadata = encryptMetadata.getValue() != 'false' else: errorMessage = 'Decryption error: Bad format for /EncryptMetadata!!' if isForceMode: encryptMetadata = True self.addError(errorMessage) else: return (-1, errorMessage) else: encryptMetadata = True if not fatalError: # Checking user password if revision != 5: ret = computeUserPass(password, dictO, fileId, perm, keyLength, revision, encryptMetadata) if ret[0] != -1: computedUserPass = ret[1] else: errorMessage = ret[1] if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) if isUserPass(password, computedUserPass, dictU, revision): passType = 'USER' elif isOwnerPass(password, dictO, dictU, computedUserPass, keyLength, revision): passType = 'OWNER' else: badPassword = True if password == '': errorMessage = 'Decryption error: Default user password not working here!!' if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Decryption error: User password not working here!!' if isForceMode: self.addError(errorMessage) else: return (-1, errorMessage) self.setOwnerPass(dictO) self.setUserPass(dictU) if not fatalError and not badPassword: ret = computeEncryptionKey(password, dictO, dictU, dictOE, dictUE, fileId, perm, keyLength, revision, encryptMetadata, passType) if ret[0] != -1: encryptionKey = ret[1] else: errorMessage = ret[1] if isForceMode: encryptionKey = '' self.addError(errorMessage) else: return (-1, errorMessage) self.setEncryptionKey(encryptionKey) self.setEncryptionKeyLength(keyLength) # Computing objects passwords and decryption numKeyBytes = self.encryptionKeyLength/8 for v in range(self.updates+1): indirectObjectsIds = list(set(self.body[v].getObjectsIds())) for id in indirectObjectsIds: indirectObject = self.body[v].getObject(id, indirect = True) if indirectObject != None: generationNum = indirectObject.getGenerationNumber() object = indirectObject.getObject() if object != None and not object.isCompressed(): objectType = object.getType() if objectType in ['string','hexstring','array','dictionary'] or (objectType == 'stream' and (object.getElement('/Type') == None or (object.getElement('/Type').getValue() not in ['/XRef','/Metadata'] or (object.getElement('/Type').getValue() == '/Metadata' and encryptMetadata)))): key = self.encryptionKey if objectType in ['string','hexstring','array','dictionary']: if revision < 5: ret = computeObjectKey(id,generationNum,self.encryptionKey,numKeyBytes,strAlgorithm[0]) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) else: key = ret[1] ret = object.decrypt(key, strAlgorithm[0]) else: if object.getElement('/Type') != None and object.getElement('/Type').getValue() == '/EmbeddedFile': if revision < 5: ret = computeObjectKey(id,generationNum,self.encryptionKey,numKeyBytes,embedAlgorithm[0]) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) else: key = ret[1] altAlgorithm = embedAlgorithm[0] else: if revision < 5: ret = computeObjectKey(id,generationNum,self.encryptionKey,numKeyBytes,stmAlgorithm[0]) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) else: key = ret[1] altAlgorithm = stmAlgorithm[0] ret = object.decrypt(key,strAlgorithm[0], altAlgorithm) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) ret = self.body[v].setObject(id,object) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) if errorMessage != '': return (-1, errorMessage) return (0,'') def deleteObject (self, id) : # Remove references too pass def encodeChars(self): errorMessage = '' for i in range(self.updates+1): ret = self.body[i].encodeChars() if ret[0] == -1: errorMessage = ret[1] self.addError(errorMessage) trailerArray = self.trailer[i] if trailerArray[0] != None: ret = trailerArray[0].encodeChars() if ret[0] == -1: errorMessage = ret[1] self.addError(errorMessage) self.trailer[i] = trailerArray if errorMessage != '': return (-1, errorMessage) return (0,'') def encrypt(self, password = ''): #TODO: AESV2 and V3 errorMessage = '' encryptDictId = None encryptMetadata = True permissionNum = 1073741823 dictOE = '' dictUE = '' ret = self.getTrailer() if ret != None: trailer,trailerStream = ret[1] if trailerStream != None: encryptDict = trailerStream.getDictEntry('/Encrypt') if encryptDict != None: encryptDictType = encryptDict.getType() if encryptDictType == 'reference': encryptDictId = encryptDict.getId() fileId = self.getMD5() if fileId == '': fileId = hashlib.md5(str(random.random())).hexdigest() md5Object = PDFString(fileId) fileIdArray = PDFArray(elements=[md5Object,md5Object]) trailerStream.setDictEntry('/ID',fileIdArray) self.setTrailer([trailer,trailerStream]) else: encryptDict = trailer.getDictEntry('/Encrypt') if encryptDict != None: encryptDictType = encryptDict.getType() if encryptDictType == 'reference': encryptDictId = encryptDict.getId() fileId = self.getMD5() if fileId == '': fileId = hashlib.md5(str(random.random())).hexdigest() md5Object = PDFString(fileId) fileIdArray = PDFArray(elements=[md5Object,md5Object]) trailer.setDictEntry('/ID',fileIdArray) self.setTrailer([trailer,trailerStream]) ret = computeOwnerPass(password,password,128,revision = 3) if ret[0] != -1: dictO = ret[1] else: if isForceMode: self.addError(ret[1]) else: return (-1,ret[1]) self.setOwnerPass(dictO) ret = computeUserPass(password,dictO,fileId,permissionNum,128,revision = 3) if ret[0] != -1: dictU = ret[1] else: if isForceMode: self.addError(ret[1]) else: return (-1,ret[1]) self.setUserPass(dictU) ret = computeEncryptionKey(password, dictO, dictU, dictOE, dictUE, fileId, permissionNum, 128, revision = 3, encryptMetadata = encryptMetadata, passwordType = 'USER') if ret[0] != -1: encryptionKey = ret[1] else: encryptionKey = '' if isForceMode: self.addError(ret[1]) else: return (-1,ret[1]) self.setEncryptionKey(encryptionKey) self.setEncryptionKeyLength(128) encryptDict = PDFDictionary(elements = {'/V':PDFNum('2'),'/Length':PDFNum('128'),'/Filter':PDFName('Standard'), '/R':PDFNum('3'),'/P':PDFNum(str(permissionNum)),'/O':PDFString(dictO),'/U':PDFString(dictU)}) if encryptDictId != None: ret = self.setObject(encryptDictId,encryptDict) if ret[0] == -1: errorMessage = '/Encrypt dictionary has not been created/modified' self.addError(errorMessage) return (-1, errorMessage) else: if trailerStream != None: trailerStream.setDictEntry('/Encrypt',encryptDict) else: trailer.setDictEntry('/Encrypt',encryptDict) self.setTrailer([trailer,trailerStream]) numKeyBytes = self.encryptionKeyLength/8 for v in range(self.updates+1): indirectObjects = self.body[v].getObjects() for id in indirectObjects: indirectObject = indirectObjects[id] if indirectObject != None: generationNum = indirectObject.getGenerationNumber() object = indirectObject.getObject() if object != None and not object.isCompressed(): objectType = object.getType() if objectType in ['string','hexstring','array','dictionary'] or (objectType == 'stream' and (object.getElement('/Type') == None or (object.getElement('/Type').getValue() not in ['/XRef','/Metadata'] or (object.getElement('/Type').getValue() == '/Metadata' and encryptMetadata)))): ret = computeObjectKey(id,generationNum,self.encryptionKey,numKeyBytes) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) else: key = ret[1] ret = object.encrypt(key) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) ret = self.body[v].setObject(id,object) if ret[0] == -1: errorMessage = ret[1] self.addError(ret[1]) else: errorMessage = 'Trailer not found' self.addError(errorMessage) if errorMessage != '': return (-1, errorMessage) self.setEncrypted(True) return (0,'') def getBasicMetadata(self, version): basicMetadata = {} # Getting creation information infoObject = self.getInfoObject(version) if infoObject != None: author = infoObject.getElementByName('/Author') if author != None and author != []: basicMetadata['author'] = author.getValue() creator = infoObject.getElementByName('/Creator') if creator != None and creator != []: basicMetadata['creator'] = creator.getValue() producer = infoObject.getElementByName('/Producer') if producer != None and producer != []: basicMetadata['producer'] = producer.getValue() creationDate = infoObject.getElementByName('/CreationDate') if creationDate != None and creationDate != []: basicMetadata['creation'] = creationDate.getValue() if not basicMetadata.has_key('author'): ids = self.getObjectsByString('<dc:creator>',version) if ids != None and ids != []: for id in ids: author = self.getMetadataElement(id, version, 'dc:creator') if author != None: basicMetadata['author'] = author break if not basicMetadata.has_key('creator'): ids = self.getObjectsByString('<xap:CreatorTool>',version) if ids != None and ids != []: for id in ids: creator = self.getMetadataElement(id, version, 'xap:CreatorTool') if creator != None: basicMetadata['creator'] = creator break if not basicMetadata.has_key('creator'): ids = self.getObjectsByString('<xmp:CreatorTool>',version) if ids != None and ids != []: for id in ids: creator = self.getMetadataElement(id, version, 'xmp:CreatorTool') if creator != None: basicMetadata['creator'] = creator break if not basicMetadata.has_key('producer'): ids = self.getObjectsByString('<pdf:Producer>',version) if ids != None and ids != []: for id in ids: producer = self.getMetadataElement(id, version, 'pdf:Producer') if producer != None: basicMetadata['producer'] = producer break if not basicMetadata.has_key('creation'): ids = self.getObjectsByString('<xap:CreateDate>',version) if ids != None and ids != []: for id in ids: creation = self.getMetadataElement(id, version, 'xap:CreateDate') if creation != None: basicMetadata['creation'] = creation break if not basicMetadata.has_key('creation'): ids = self.getObjectsByString('<xmp:CreateDate>',version) if ids != None and ids != []: for id in ids: creation = self.getMetadataElement(id, version, 'xmp:CreateDate') if creation != None: basicMetadata['creation'] = creation break if not basicMetadata.has_key('modification'): ids = self.getObjectsByString('<xap:ModifyDate>',version) if ids != None and ids != []: for id in ids: modification = self.getMetadataElement(id, version, 'xap:ModifyDate') if modification != None: basicMetadata['modification'] = modification break if not basicMetadata.has_key('modification'): ids = self.getObjectsByString('<xmp:ModifyDate>',version) if ids != None and ids != []: for id in ids: modification = self.getMetadataElement(id, version, 'xmp:ModifyDate') if modification != None: basicMetadata['modification'] = modification break return basicMetadata def getCatalogObject(self, version = None, indirect = False): if version == None: catalogObjects = [] catalogIds = self.getCatalogObjectId() for id in catalogIds: if id != None: catalogObject = self.getObject(id, version, indirect) catalogObjects.append(catalogObject) else: catalogObjects.append(None) return catalogObjects else: catalogId = self.getCatalogObjectId(version) if catalogId != None: catalogObject = self.getObject(catalogId, version, indirect) return catalogObject else: return None def getCatalogObjectId(self, version = None): if version == None: catalogIds = [] for v in range(self.updates+1): catalogId = None trailer, streamTrailer = self.trailer[v] if trailer != None: catalogId = trailer.getCatalogId() if catalogId == None and streamTrailer != None: catalogId = streamTrailer.getCatalogId() catalogIds.append(catalogId) return catalogIds else: catalogId = None trailer, streamTrailer = self.trailer[version] if trailer != None: catalogId = trailer.getCatalogId() if catalogId == None and streamTrailer != None: catalogId = streamTrailer.getCatalogId() return catalogId def getChangeLog (self, version = None) : lastVersionObjects = [] actualVersionObjects = [] addedObjects = [] removedObjects = [] modifiedObjects = [] notMatchingObjects = [] changes = [] if version == None: version = self.updates + 1 else: version += 1 for i in range(version): actualVersionObjects = self.body[i].getObjectsIds() if i != 0: xrefNewObjects = [] xrefFreeObjects = [] crossRefSection = self.crossRefTable[i][0] crossRefStreamSection = self.crossRefTable[i][1] if crossRefSection != None: xrefNewObjects += crossRefSection.getNewObjectIds() xrefFreeObjects += crossRefSection.getFreeObjectIds() if crossRefStreamSection != None: xrefNewObjects += crossRefStreamSection.getNewObjectIds() xrefFreeObjects += crossRefStreamSection.getFreeObjectIds() for id in actualVersionObjects: if id not in lastVersionObjects: addedObjects.append(id) lastVersionObjects.append(id) else: modifiedObjects.append(id) if id not in xrefNewObjects or id in xrefFreeObjects: notMatchingObjects.append(id) for id in lastVersionObjects: if id not in actualVersionObjects: if id in xrefFreeObjects: removedObjects.append(id) lastVersionObjects.remove(id) if id in xrefNewObjects: notMatchingObjects.append(id) changes.append([addedObjects,modifiedObjects,removedObjects,notMatchingObjects]) addedObjects = [] removedObjects = [] modifiedObjects = [] notMatchingObjects = [] else: lastVersionObjects = actualVersionObjects return changes def getDetectionRate(self): return self.detectionRate def getDetectionReport(self): return self.detectionReport def getEndLine(self): return self.endLine def getEncryptDict(self): return self.encryptDict def getEncryptionAlgorithms(self): return self.encryptionAlgorithms def getEncryptionKey(self): return self.encryptionKey def getEncryptionKeyLength(self): return self.encryptionKeyLength def getErrors(self): return self.errors def getFileId(self): return self.fileId def getFileName(self): return self.fileName def getGarbageHeader(self): return self.garbageHeader def getHeaderOffset(self): return self.headerOffset def getInfoObject(self, version = None, indirect = False): if version == None: infoObjects = [] infoIds = self.getInfoObjectId() for id in infoIds: if id != None: infoObject = self.getObject(id, version, indirect) infoObjects.append(infoObject) else: infoObjects.append(None) return infoObjects else: infoId = self.getInfoObjectId(version) if infoId != None: infoObject = self.getObject(infoId, version, indirect) if infoObject == None and version == 0 and self.getLinearized(): # Linearized documents can store Info object in the next update infoObject = self.getObject(infoId, None, indirect) return infoObject return infoObject else: return None def getInfoObjectId(self, version = None): if version == None: infoIds = [] for v in range(self.updates+1): infoId = None trailer, streamTrailer = self.trailer[v] if trailer != None: infoId = trailer.getInfoId() if infoId == None and streamTrailer != None: infoId = streamTrailer.getInfoId() infoIds.append(infoId) else: return infoIds else: infoId = None trailer, streamTrailer = self.trailer[version] if trailer != None: infoId = trailer.getInfoId() if infoId == None and streamTrailer != None: infoId = streamTrailer.getInfoId() return infoId def getJavascriptCode (self, version = None) : JSCode = [] if version == None: for version in range(self.updates+1): JSCode += self.body[version].getJSCode() else: if version <= self.updates and not version < 0: JSCode = self.body[version].getJSCode() return JSCode def getLinearized(self): return self.linearized def getMD5(self): return self.md5 def getMetadata (self, version = None): matchingObjects = self.getObjectsByString('/Metadata', version) return matchingObjects def getMetadataElement(self, objectId, version, element): metadataObject = self.getObject(objectId,version) if metadataObject != None: if metadataObject.getType() == 'stream': stream = metadataObject.getStream() matches = re.findall('<'+element+'>(.*)</'+element+'>',stream) if matches != []: return matches[0] else: return None else: return None else: return None def getNumUpdates(self): return self.updates def getObject (self, id, version = None, indirect = False) : ''' Returns the specified object ''' if version == None: for i in range(self.updates,-1,-1): if indirect: object = self.body[i].getIndirectObject(id) else: object = self.body[i].getObject(id) if object == None: continue else: return object else: return None else: if version > self.updates or version < 0: return None if indirect: return self.body[version].getIndirectObject(id) else: return self.body[version].getObject(id) def getObjectsByString (self, toSearch, version = None) : ''' Returns the object containing the specified string. ''' matchedObjects = [] if version == None: for i in range(self.updates + 1): matchedObjects.append(self.body[i].getObjectsByString(toSearch)) return matchedObjects else: if version > self.updates or version < 0: return None return self.body[version].getObjectsByString(toSearch) def getOffsets(self, version = None): offsetsArray = [] if version == None: versions = range(self.updates+1) else: versions = [version] for version in versions: offsets = {} trailer = None xref = None objectStreamsOffsets = {} indirectObjects = self.body[version].getObjects() sortedObjectsIds = self.body[version].getObjectsIds() compressedObjects = self.body[version].getCompressedObjects() objectStreams = self.body[version].getObjectStreams() ret = self.getXrefSection(version) if ret != None: xref, streamXref = ret[1] ret = self.getTrailer(version) if ret != None: trailer, streamTrailer = ret[1] if objectStreams != []: for objStream in objectStreams: if objStream in indirectObjects: indirectObject = indirectObjects[objStream] if indirectObject != None: objectStreamsOffsets[objStream] = indirectObject.getOffset() if version == 0: offsets['header'] = (self.headerOffset,0) for id in sortedObjectsIds: indirectObject = indirectObjects[id] if indirectObject != None: objectOffset = indirectObject.getOffset() object = indirectObject.getObject() if object != None and object.isCompressed(): compressedIn = object.getCompressedIn() if compressedIn in objectStreamsOffsets: objectOffset = objectStreamsOffsets[compressedIn] + objectOffset + 20 size = indirectObject.getSize() if offsets.has_key('objects'): offsets['objects'].append((id,objectOffset,size)) else: offsets['objects'] = [(id,objectOffset,size)] if xref != None: xrefOffset = xref.getOffset() xrefSize = xref.getSize() offsets['xref'] = (xrefOffset, xrefSize) else: offsets['xref'] = None if trailer != None: trailerOffset = trailer.getOffset() trailerSize = trailer.getSize() eofOffset = trailer.getEOFOffset() offsets['trailer'] = (trailerOffset,trailerSize) offsets['eof'] = (eofOffset,0) else: offsets['trailer'] = None offsets['eof'] = None offsets['compressed'] = compressedObjects offsetsArray.append(offsets) return offsetsArray def getOwnerPass(self): return self.ownerPass def getPath(self): return self.path def getReferencesIn (self, id, version = None) : ''' Get the references in an object ''' if version == None: for i in range(self.updates,-1,-1): indirectObjectsDict = self.body[i].getObjects() if indirectObjectsDict.has_key(id): indirectObject = indirectObjectsDict[id] if indirectObject == None: return None else: return indirectObject.getReferences() else: return None else: if version > self.updates or version < 0: return None indirectObjectsDict = self.body[version].getObjects() if indirectObjectsDict.has_key(id): indirectObject = indirectObjectsDict[id] if indirectObject == None: return None else: return indirectObject.getReferences() else: return None def getReferencesTo (self, id, version = None) : ''' Get the references to the specified object in the document ''' matchedObjects = [] if version == None: for i in range(self.updates + 1): indirectObjectsDict = self.body[i].getObjects() for indirectObject in indirectObjectsDict.values(): if indirectObject != None: object = indirectObject.getObject() if object != None: value = object.getValue() if re.findall('\D'+str(id)+'\s{1,3}\d{1,3}\s{1,3}R', value) != []: matchedObjects.append(indirectObject.id) else: if version > self.updates or version < 0: return None indirectObjectsDict = self.body[version].getObjects() for indirectObject in indirectObjectsDict.values(): if indirectObject != None: object = indirectObject.getObject() if object != None: value = object.getValue() if re.findall('\D'+str(id)+'\s{1,3}\d{1,3}\s{1,3}R', value) != []: matchedObjects.append(indirectObject.id) return matchedObjects def getSHA1(self): return self.sha1 def getSHA256(self): return self.sha256 def getSize(self): return self.size def getStats (self): stats = {} stats['File'] = self.fileName stats['MD5'] = self.md5 stats['SHA1'] = self.sha1 stats['SHA256'] = self.sha256 stats['Size'] = str(self.size) stats['Detection'] = self.detectionRate stats['Detection report'] = self.detectionReport stats['Version'] = self.version stats['Binary'] = str(self.binary) stats['Linearized'] = str(self.linearized) stats['Encrypted'] = str(self.encrypted) stats['Encryption Algorithms'] = self.encryptionAlgorithms stats['Updates'] = str(self.updates) stats['Objects'] = str(self.numObjects) stats['Streams'] = str(self.numStreams) stats['Comments'] = str(len(self.comments)) stats['Errors'] = self.errors stats['Versions'] = [] for version in range(self.updates+1): statsVersion = {} catalogId = None infoId = None trailer, streamTrailer = self.trailer[version] if trailer != None: catalogId = trailer.getCatalogId() infoId = trailer.getInfoId() if catalogId == None and streamTrailer != None: catalogId = streamTrailer.getCatalogId() if infoId == None and streamTrailer != None: infoId = streamTrailer.getInfoId() if catalogId != None: statsVersion['Catalog'] = str(catalogId) else: statsVersion['Catalog'] = None if infoId != None: statsVersion['Info'] = str(infoId) else: statsVersion['Info'] = None objectsById = sorted(self.body[version].getObjectsIds(), key=lambda x: int(x)) statsVersion['Objects'] = [str(self.body[version].getNumObjects()),objectsById] if self.body[version].containsCompressedObjects(): compressedObjects = self.body[version].getCompressedObjects() statsVersion['Compressed Objects'] = [str(len(compressedObjects)),compressedObjects] else: statsVersion['Compressed Objects'] = None numFaultyObjects = self.body[version].getNumFaultyObjects() if numFaultyObjects > 0: statsVersion['Errors'] = [str(numFaultyObjects),self.body[version].getFaultyObjects()] else: statsVersion['Errors'] = None numStreams = self.body[version].getNumStreams() statsVersion['Streams'] = [str(numStreams),self.body[version].getStreams()] if self.body[version].containsXrefStreams(): xrefStreams = self.body[version].getXrefStreams() statsVersion['Xref Streams'] = [str(len(xrefStreams)),xrefStreams] else: statsVersion['Xref Streams'] = None if self.body[version].containsObjectStreams(): objectStreams = self.body[version].getObjectStreams() statsVersion['Object Streams'] = [str(len(objectStreams)),objectStreams] else: statsVersion['Object Streams'] = None if numStreams > 0: statsVersion['Encoded'] = [str(self.body[version].getNumEncodedStreams()),self.body[version].getEncodedStreams()] numDecodingErrors = self.body[version].getNumDecodingErrors() if numDecodingErrors > 0: statsVersion['Decoding Errors'] = [str(numDecodingErrors),self.body[version].getFaultyStreams()] else: statsVersion['Decoding Errors'] = None else: statsVersion['Encoded'] = None containingJS = self.body[version].getContainingJS() if len(containingJS) > 0: statsVersion['Objects with JS code'] = [str(len(containingJS)),containingJS] else: statsVersion['Objects with JS code'] = None actions = self.body[version].getSuspiciousActions() events = self.body[version].getSuspiciousEvents() vulns = self.body[version].getVulns() elements = self.body[version].getSuspiciousElements() urls = self.body[version].getURLs() if len(events) > 0: statsVersion['Events'] = events else: statsVersion['Events'] = None if len(actions) > 0: statsVersion['Actions'] = actions else: statsVersion['Actions'] = None if len(vulns) > 0: statsVersion['Vulns'] = vulns else: statsVersion['Vulns'] = None if len(elements) > 0: statsVersion['Elements'] = elements else: statsVersion['Elements'] = None if len(urls) > 0: statsVersion['URLs'] = urls else: statsVersion['URLs'] = None stats['Versions'].append(statsVersion) return stats def getSuspiciousComponents (self) : pass def getTrailer (self, version = None) : if version == None: for i in range(self.updates,-1,-1): trailerArray = self.trailer[i] if trailerArray == None or trailerArray == []: continue else: return (i,trailerArray) else: #self.addError('Trailer not found in file') return None else: if version > self.updates or version < 0: #self.addError('Bad version getting trailer') return None trailerArray = self.trailer[version] if trailerArray == None or trailerArray == []: return None else: return (version,trailerArray) def getTree (self, version = None) : ''' Returns the logical structure (tree) of the document ''' tree = [] if version == None: versions = range(self.updates+1) else: versions = [version] for version in versions: objectsIn = {} trailer = None streamTrailer = None catalogId = None infoId = None ids = self.body[version].getObjectsIds() ret = self.getTrailer(version) if ret != None: trailer, streamTrailer = ret[1] # Getting info and catalog id if trailer != None: catalogId = trailer.getCatalogId() infoId = trailer.getInfoId() if catalogId == None and streamTrailer != None: catalogId = streamTrailer.getCatalogId() if infoId == None and streamTrailer != None: infoId = streamTrailer.getInfoId() for id in ids: referencesIds = [] object = self.getObject(id, version) if object != None: type = object.getType() if type == 'dictionary' or type == 'stream': elements = object.getElements() if infoId == id: type = '/Info' else: dictType = object.getDictType() if dictType != '': type = dictType else: if type == 'dictionary' and len(elements) == 1: type = elements.keys()[0] references = self.getReferencesIn(id, version) for i in range(len(references)): referencesIds.append(int(references[i].split()[0])) if references == None: objectsIn[id] = (type, []) else: objectsIn[id] = (type, referencesIds) tree.append([catalogId, objectsIn]) return tree def getUpdates(self): return self.updates def getURLs (self, version = None) : urls = [] if version == None: for version in range(self.updates+1): urls += self.body[version].getURLs() else: if version <= self.updates and not version < 0: urls = self.body[version].getURLs() return urls def getUserPass(self): return self.userPass def getVersion(self): return self.version def getXrefSection (self, version = None) : if version == None: for i in range(self.updates,-1,-1): xrefArray = self.crossRefTable[i] if xrefArray == None or xrefArray == []: continue else: return (i,xrefArray) else: #self.addError('Xref section not found in file') return None else: if version > self.updates or version < 0: return None xrefArray = self.crossRefTable[version] if xrefArray == None or xrefArray == []: return None else: return (version,xrefArray) def headerToFile(self, malformedOptions, headerFile): headerGarbage = '' if MAL_ALL in malformedOptions or MAL_HEAD in malformedOptions: if headerFile == None: if self.garbageHeader == '': headerGarbage = 'MZ'+'_'*100 else: headerGarbage = self.garbageHeader else: headerGarbage = open(headerFile,'rb').read() headerGarbage += newLine if MAL_ALL in malformedOptions or MAL_BAD_HEAD in malformedOptions: output = headerGarbage + '%PDF-1.\0' + newLine else: output = headerGarbage + '%PDF-' + self.version + newLine if self.binary or headerGarbage != '': self.binary = True self.binaryChars = '\xC0\xFF\xEE\xFA\xBA\xDA' output += '%' + self.binaryChars + newLine return output def isEncrypted(self): return self.encrypted def makePDF(self, pdfType, content): offset = 0 numObjects = 3 self.version = '1.7' xrefEntries = [] staticIndirectObjectSize = 13+3*len(newLine) self.setHeaderOffset(offset) if pdfType == 'open_action_js': self.binary = True self.binaryChars = '\xC0\xFF\xEE\xFA\xBA\xDA' offset = 16 else: offset = 10 # Body body = PDFBody() xrefEntries.append(PDFCrossRefEntry(0,65535,'f')) # Catalog (1) catalogElements = {'/Type':PDFName('Catalog'),'/Pages':PDFReference('2')} if pdfType == 'open_action_js': catalogElements['/OpenAction'] = PDFReference('4') catalogDictionary = PDFDictionary(elements=catalogElements) catalogSize = staticIndirectObjectSize + len(catalogDictionary.getRawValue()) body.setObject(object = catalogDictionary, offset = offset) xrefEntries.append(PDFCrossRefEntry(offset,0,'n')) offset += catalogSize # Pages root node (2) pagesDictionary = PDFDictionary(elements={'/Type':PDFName('Pages'),'/Kids':PDFArray(elements=[PDFReference('3')]),'/Count':PDFNum('1')}) pagesSize = len(pagesDictionary.getRawValue())+staticIndirectObjectSize body.setObject(object = pagesDictionary, offset = offset) xrefEntries.append(PDFCrossRefEntry(offset,0,'n')) offset += pagesSize # Page node (3) mediaBoxArray = PDFArray(elements=[PDFNum('0'),PDFNum('0'),PDFNum('600'),PDFNum('800')]) pageDictionary = PDFDictionary(elements={'/Type':PDFName('Page'),'/Parent':PDFReference('2'),'/MediaBox':mediaBoxArray,'/Resources':PDFDictionary()}) pageSize = len(pageDictionary.getRawValue())+staticIndirectObjectSize body.setObject(object = pageDictionary, offset = offset) xrefEntries.append(PDFCrossRefEntry(offset,0,'n')) offset += pageSize if pdfType == 'open_action_js': # Action object (4) actionDictionary = PDFDictionary(elements={'/Type':PDFName('Action'),'/S':PDFName('JavaScript'),'/JS':PDFReference('5')}) actionSize = len(actionDictionary.getRawValue())+staticIndirectObjectSize body.setObject(object = actionDictionary, offset = offset) xrefEntries.append(PDFCrossRefEntry(offset,0,'n')) offset += actionSize # JS stream (5) try: jsStream = PDFStream(rawStream = content, elements = {'/Length':PDFNum(str(len(content)))}) except Exception,e: errorMessage = 'Error creating PDFStream' if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) ret = jsStream.setElement('/Filter',PDFName('FlateDecode')) if ret[0] == -1: self.addError(ret[1]) return ret jsSize = len(jsStream.getRawValue())+staticIndirectObjectSize ret = body.setObject(object = jsStream, offset = offset) if ret[0] == -1: self.addError(ret[1]) return ret xrefEntries.append(PDFCrossRefEntry(offset,0,'n')) offset += jsSize numObjects = 5 body.setNextOffset(offset) self.addBody(body) self.addNumObjects(body.getNumObjects()) self.addNumStreams(body.getNumStreams()) self.addNumEncodedStreams(body.getNumEncodedStreams()) self.addNumDecodingErrors(body.getNumDecodingErrors()) # xref table subsection = PDFCrossRefSubSection(0,numObjects+1,xrefEntries) xrefSection = PDFCrossRefSection() xrefSection.addSubsection(subsection) xrefSection.setOffset(offset) xrefOffset = offset xrefSectionSize = len(xrefEntries)*20+10 xrefSection.setSize(xrefSectionSize) offset += xrefSectionSize self.addCrossRefTableSection([xrefSection,None]) # Trailer trailerDictionary = PDFDictionary(elements={'/Size':PDFNum(str(numObjects+1)),'/Root':PDFReference('1')}) trailerSize = len(trailerDictionary.getRawValue())+25 trailer = PDFTrailer(trailerDictionary,str(xrefOffset)) trailer.setOffset(offset) trailer.setSize(trailerSize) trailer.setEOFOffset(offset+trailerSize) self.addTrailer([trailer,None]) self.setSize(offset+trailerSize+5) self.updateStats() return (0,'') def replace(self, string1, string2): errorMessage = '' stringFound = False for i in range(self.updates + 1): objects = self.getObjectsByString(string1,i) for id in objects: object = self.getObject(id, i) if object != None: ret = object.replace(string1, string2) if ret[0] == -1 and not stringFound: errorMessage = ret[1] else: stringFound = True ret = self.setObject(id, object, i) if ret[0] == -1: errorMessage = ret[1] if not stringFound: return (-1,'String not found') if errorMessage != '': return (-1, errorMessage) else: return (0,'') def removeError(self, errorMessage = '', errorType = None): ''' Removes the error message from the errors array. If an errorType is given, then all the error messages belonging to this type are removed. @param errorMessage: The error message to be removed (string) @param errorType: All the error messages of this type will be removed (string) ''' if errorMessage in self.errors: self.errors.remove(errorMessage) if errorType != None: lenErrorType = len(errorType) for error in self.errors: if error[:lenErrorType] == errorType: self.errors.remove(error) def save(self, filename, version = None, malformedOptions = [], headerFile = None): maxId = 0 offset = 0 lastXrefSectionOffset = 0 prevXrefSectionOffset = 0 prevXrefStreamOffset = 0 indirectObjects = {} xrefStreamObjectId = None xrefStreamObject = None try: if version == None: version = self.updates outputFileContent = self.headerToFile(malformedOptions,headerFile) offset = len(outputFileContent) for v in range(version+1): xrefStreamObjectId = None xrefStreamObject = None sortedObjectsIds = self.body[v].getObjectsIds() indirectObjects = self.body[v].getObjects() section, streamSection = self.crossRefTable[v] trailer, streamTrailer = self.trailer[v] if section != None: numSubSectionsInXref = section.getSubsectionsNumber() else: numSubSectionsInXref = 0 if streamSection != None: numSubSectionsInXrefStream = streamSection.getSubsectionsNumber() else: numSubSectionsInXrefStream = 0 if streamSection != None: xrefStreamObjectId = streamSection.getXrefStreamObject() if indirectObjects.has_key(xrefStreamObjectId): xrefStreamObject = indirectObjects[xrefStreamObjectId] sortedObjectsIds.remove(xrefStreamObjectId) for id in sortedObjectsIds: if id > maxId: maxId = id indirectObject = indirectObjects[id] if indirectObject != None: object = indirectObject.getObject() if object != None: objectType = object.getType() if not object.isCompressed(): indirectObject.setOffset(offset) if numSubSectionsInXref != 0: ret = section.updateOffset(id, offset) if ret[0] == -1: ret = section.addEntry(id,PDFCrossRefEntry(offset,0,'n')) if ret[0] == -1: self.addError(ret[1]) if numSubSectionsInXrefStream != 0: ret = streamSection.updateOffset(id, offset) if ret[0] == -1: ret = streamSection.addEntry(id,PDFCrossRefEntry(offset,0,'n')) if ret[0] == -1: self.addError(ret[1]) objectFileOutput = indirectObject.toFile() if objectType == 'stream' and MAL_ESTREAM in malformedOptions: objectFileOutput = objectFileOutput.replace(newLine+'endstream','') elif MAL_ALL in malformedOptions or MAL_EOBJ in malformedOptions: objectFileOutput = objectFileOutput.replace(newLine+'endobj','') outputFileContent += objectFileOutput offset = len(outputFileContent) indirectObject.setSize(offset-indirectObject.getOffset()) indirectObjects[id] = indirectObject if xrefStreamObject != None: if numSubSectionsInXref != 0: ret = section.updateOffset(xrefStreamObjectId, offset) if ret[0] == -1: self.addError(ret[1]) ret = streamSection.updateOffset(xrefStreamObjectId, offset) if ret[0] == -1: self.addError(ret[1]) xrefStreamObject.setOffset(offset) if xrefStreamObjectId > maxId: maxId = xrefStreamObjectId streamSection.setSize(maxId+1) if streamTrailer != None: streamTrailer.setNumObjects(maxId+1) if prevXrefStreamOffset != 0: streamTrailer.setPrevCrossRefSection(prevXrefStreamOffset) self.trailer[v][1] = streamTrailer self.crossRefTable[v][1] = streamSection ret = self.createXrefStream(v, xrefStreamObjectId) if ret[0] == -1: return (-1,ret[1]) xrefStreamObjectId,newXrefStream = ret[1] xrefStreamObject.setObject(newXrefStream) objectFileOutput = xrefStreamObject.toFile() if MAL_ALL in malformedOptions or MAL_ESTREAM in malformedOptions: objectFileOutput = objectFileOutput.replace(newLine+'endstream','') outputFileContent += objectFileOutput prevXrefStreamOffset = offset lastXrefSectionOffset = offset offset = len(outputFileContent) xrefStreamObject.setSize(offset-xrefStreamObject.getOffset()) indirectObjects[xrefStreamObjectId] = xrefStreamObject self.body[v].setNextOffset(offset) if section != None and MAL_ALL not in malformedOptions and MAL_XREF not in malformedOptions: section.setOffset(offset) lastXrefSectionOffset = offset outputFileContent += section.toFile() offset = len(outputFileContent) section.setSize(offset-section.getOffset()) self.crossRefTable[v][0] = section if trailer != None: trailer.setLastCrossRefSection(lastXrefSectionOffset) trailer.setOffset(offset) if trailer.getCatalogId() != None and trailer.getSize() != 0: trailer.setNumObjects(maxId+1) if prevXrefSectionOffset != 0: trailer.setPrevCrossRefSection(prevXrefSectionOffset) outputFileContent += trailer.toFile() offset = len(outputFileContent) trailer.setSize(offset-trailer.getOffset()) self.trailer[v][0] = trailer prevXrefSectionOffset = lastXrefSectionOffset self.body[v].setObjects(indirectObjects) offset = len(outputFileContent) open(filename,'wb').write(outputFileContent) self.setMD5(hashlib.md5(outputFileContent).hexdigest()) self.setSize(len(outputFileContent)) self.path = os.path.realpath(filename) self.fileName = filename except: return (-1,'Unspecified error') return (0,'') def setDetectionRate(self, newRate): self.detectionRate = newRate def setDetectionReport(self, detectionReportLink): self.detectionReport = detectionReportLink def setEncryptDict(self, dict): self.encryptDict = dict def setEncrypted(self, status): self.encrypted = status def setEncryptionAlgorithms(self, encryptionAlgorithms): self.encryptionAlgorithms = encryptionAlgorithms def setEncryptionKey(self, key): self.encryptionKey = key def setEncryptionKeyLength(self, length): self.encryptionKeyLength = length def setEndLine(self, eol): self.endLine = eol def setFileId(self, fid): self.fileId = fid def setFileName(self, name): self.fileName = name def setGarbageHeader(self, garbage): self.garbageHeader = garbage def setHeaderOffset(self, offset): self.headerOffset = offset def setLinearized(self, status): self.linearized = status def setMaxObjectId(self, id): if int(id) > self.maxObjectId: self.maxObjectId = int(id) def setMD5(self, md5): self.md5 = md5 def setObject (self, id, object, version = None, mod = False): errorMessage = '' if object == None: return (-1,'Object is None') if version == None: for i in range(self.updates,-1,-1): ret = self.body[i].setObject(id, object, modification = mod) if ret[0] == -1: errorMessage = ret[1] else: objectType = object.getType() if objectType == 'dictionary' and object.hasElement('/Linearized'): self.setLinearized(True) return ret else: return (-1, errorMessage) else: if version > self.updates or version < 0: return (-1,'Bad file version') ret = self.body[version].setObject(id, object, modification = mod) if ret[0] == -1: self.addError(ret[1]) return (-1,ret[1]) else: objectType = object.getType() if objectType == 'dictionary' and object.hasElement('/Linearized'): self.setLinearized(True) return ret def setOwnerPass(self, password): self.ownerPass = password def setPath(self, path): self.path = path def setSHA1(self, sha1): self.sha1 = sha1 def setSHA256(self, sha256): self.sha256 = sha256 def setSize(self, size): self.size = size def setTrailer(self, trailerArray, version = None): errorMessage = '' if version == None: for i in range(self.updates,-1,-1): if len(self.trailer) > i: self.trailer[i] = trailerArray else: errorMessage = 'Trailer not found' self.addError(errorMessage) else: if version > self.updates or version < 0: return (-1,'Bad file version') self.trailer[version] = trailerArray if errorMessage != '': return (-1, errorMessage) return (0,'') def setUpdates(self, num): self.updates = num def setUserPass(self, password): self.userPass = password def setVersion(self, version): self.version = version def updateStats(self, recursiveUpdate = False): self.numObjects = 0 self.numStreams = 0 self.numEncodedStreams = 0 self.numDecodingErrors = 0 self.encrypted = False for v in range(self.updates+1): if recursiveUpdate: #TODO self.updateBody(v) self.updateCrossRefTable(v) self.updateTrailer(v) #body.updateObjects() self.addNumObjects(self.body[v].getNumObjects()) self.addNumStreams(self.body[v].getNumStreams()) self.addNumEncodedStreams(self.body[v].getNumEncodedStreams()) self.addNumDecodingErrors(self.body[v].getNumDecodingErrors()) trailer, streamTrailer = self.trailer[v] if trailer != None: if trailer.getDictEntry('/Encrypt') != None: self.setEncrypted(True) if streamTrailer != None: if streamTrailer.getDictEntry('/Encrypt') != None: self.setEncrypted(True) return (0,'') def updateBody (self, version) : #TODO pass def updateCrossRefTable (self, version) : #TODO pass def updateTrailer (self, version) : #TODO pass class PDFParser : def __init__(self) : self.commentChar = '%' self.comments = [] self.delimiters = [('<<','>>','dictionary'),('(',')','string'),('<','>','hexadecimal'),('[',']','array'),('{','}',''),('/','','name'),('%','','comment')] self.fileParts = [] self.charCounter = 0 def parse (self, fileName, forceMode = False, looseMode = False, manualAnalysis = False) : ''' Main method to parse a PDF document @param fileName The name of the file to be parsed @param forceMode Boolean to specify if ignore errors or not. Default value: False. @param looseMode Boolean to set the loose mode when parsing objects. Default value: False. @return A PDFFile instance ''' global isForceMode, pdfFile, isManualAnalysis isFirstBody = True linearizedFound = False errorMessage = '' versionLine = '' binaryLine = '' headerOffset = 0 garbageHeader = '' pdfFile = PDFFile() pdfFile.setPath(fileName) pdfFile.setFileName(os.path.basename(fileName)) isForceMode = forceMode isManualAnalysis = manualAnalysis # Reading the file header file = open(fileName,'rb') for line in file: if versionLine == '': pdfHeaderIndex = line.find('%PDF-') psHeaderIndex = line.find('%!PS-Adobe-') if pdfHeaderIndex != -1 or psHeaderIndex != -1: index = line.find('\r') if index != -1 and index+1 < len(line) and line[index+1] != '\n': index += 1 versionLine = line[:index] binaryLine = line[index:] break else: versionLine = line if pdfHeaderIndex != -1: headerOffset += pdfHeaderIndex else: headerOffset += psHeaderIndex pdfFile.setHeaderOffset(headerOffset) else: garbageHeader += line else: binaryLine = line break headerOffset += len(line) file.close() # Getting the specification version versionLine = versionLine.replace('\r','') versionLine = versionLine.replace('\n','') matchVersion = re.findall('%(PDF-|!PS-Adobe-\d{1,2}\.\d{1,2}\sPDF-)(\d{1,2}\.\d{1,2})',versionLine) if matchVersion == []: if forceMode: pdfFile.setVersion(versionLine) pdfFile.addError('Bad PDF header') errorMessage = 'Bad PDF header' else: sys.exit('Error: Bad PDF header!! (' + versionLine + ')') else: pdfFile.setVersion(matchVersion[0][1]) if garbageHeader != '': pdfFile.setGarbageHeader(garbageHeader) # Getting the end of line if len(binaryLine) > 3: if binaryLine[-2:] == '\r\n': pdfFile.setEndLine('\r\n') else: if binaryLine[-1] == '\r': pdfFile.setEndLine('\r') elif binaryLine[-1] == '\n': pdfFile.setEndLine('\n') else: pdfFile.setEndLine('\n') # Does it contain binary characters?? if binaryLine[0] == '%' and ord(binaryLine[1]) >= 128 and ord(binaryLine[2]) >= 128 and ord(binaryLine[3]) >= 128 and ord(binaryLine[4]) >= 128: pdfFile.binary = True pdfFile.binaryChars = binaryLine[1:5] else: pdfFile.binary = False # Reading the rest of the file fileContent = open(fileName,'rb').read() pdfFile.setSize(len(fileContent)) pdfFile.setMD5(hashlib.md5(fileContent).hexdigest()) pdfFile.setSHA1(hashlib.sha1(fileContent).hexdigest()) pdfFile.setSHA256(hashlib.sha256(fileContent).hexdigest()) # Getting the number of updates in the file while fileContent.find('%%EOF') != -1: self.readUntilSymbol(fileContent, '%%EOF') self.readUntilEndOfLine(fileContent) self.fileParts.append(fileContent[:self.charCounter]) fileContent = fileContent[self.charCounter:] self.charCounter = 0 else: if self.fileParts == []: errorMessage = '%%EOF not found' if forceMode: pdfFile.addError(errorMessage) self.fileParts.append(fileContent) else: sys.exit(errorMessage) pdfFile.setUpdates(len(self.fileParts) - 1) # Getting the body, cross reference table and trailer of each part of the file for i in range(len(self.fileParts)): bodyOffset = 0 xrefOffset = 0 trailerOffset = 0 eofOffset = 0 xrefObject = None xrefContent = None xrefSection = None xrefStreamSection = None xrefFound = False streamTrailer = None trailer = None trailerFound = False pdfIndirectObject = None if not pdfFile.isEncrypted(): encryptDict = None encryptDictId = None if pdfFile.getFileId() == '': fileId = None content = self.fileParts[i] if i == 0: bodyOffset = 0 else: bodyOffset = len(self.fileParts[i-1]) # Getting the content for each section bodyContent,xrefContent,trailerContent = self.parsePDFSections(content,forceMode,looseMode) if xrefContent != None: xrefOffset = bodyOffset + len(bodyContent) trailerOffset = xrefOffset + len(xrefContent) bodyContent = bodyContent.strip('\r\n') xrefContent = xrefContent.strip('\r\n') trailerContent = trailerContent.strip('\r\n') trailerFound = True xrefFound = True else: if trailerContent != None: xrefOffset = -1 trailerOffset = bodyOffset + len(bodyContent) bodyContent = bodyContent.strip('\r\n') trailerContent = trailerContent.strip('\r\n') else: errorMessage = 'PDF sections not found' if forceMode: pdfFile.addError(errorMessage) else: sys.exit('Error: '+errorMessage+'!!') # Converting the body content in PDFObjects body = PDFBody() rawIndirectObjects = self.getIndirectObjects(bodyContent, looseMode) if rawIndirectObjects != []: for j in range(len(rawIndirectObjects)): relativeOffset = 0 auxContent = str(bodyContent) rawObject = rawIndirectObjects[j][0] objectHeader = rawIndirectObjects[j][1] while True: index = auxContent.find(objectHeader) if index == -1: relativeOffset = index break relativeOffset += index checkHeader = bodyContent[relativeOffset-1:relativeOffset+len(objectHeader)] if not re.match('\d{1,10}'+objectHeader,checkHeader): break else: auxContent = auxContent[index+len(objectHeader):] relativeOffset += len(objectHeader) ret = self.createPDFIndirectObject(rawObject, forceMode, looseMode) if ret[0] != -1: pdfIndirectObject = ret[1] if pdfIndirectObject != None: if relativeOffset == -1: pdfIndirectObject.setOffset(relativeOffset) else: pdfIndirectObject.setOffset(bodyOffset + relativeOffset) ret = body.registerObject(pdfIndirectObject) if ret[0] == -1: pdfFile.addError(ret[1]) type = ret[1] pdfObject = pdfIndirectObject.getObject() if pdfObject != None: objectType = pdfObject.getType() if objectType == 'dictionary': if isFirstBody and not linearizedFound: if pdfObject.hasElement('/Linearized'): pdfFile.setLinearized(True) linearizedFound = True elif objectType == 'stream' and type == '/XRef': xrefObject = pdfIndirectObject ret = self.createPDFCrossRefSectionFromStream(pdfIndirectObject) if ret[0] != -1: xrefStreamSection = ret[1] else: if not forceMode: sys.exit('Error: An error has occurred while parsing an indirect object!!') else: pdfFile.addError('Object is None') else: if not forceMode: sys.exit('Error: Bad indirect object!!') else: pdfFile.addError('Indirect object is None') else: if not forceMode: sys.exit('Error: An error has occurred while parsing an indirect object!!') else: pdfFile.addError('Error parsing object: '+str(objectHeader)+' ('+str(ret[1])+')') else: pdfFile.addError('No indirect objects found in the body') if pdfIndirectObject != None: body.setNextOffset(pdfIndirectObject.getOffset()) ret = body.updateObjects() if ret[0] == -1: pdfFile.addError(ret[1]) pdfFile.addBody(body) pdfFile.addNumObjects(body.getNumObjects()) pdfFile.addNumStreams(body.getNumStreams()) pdfFile.addNumEncodedStreams(body.getNumEncodedStreams()) pdfFile.addNumDecodingErrors(body.getNumDecodingErrors()) isFirstBody = False # Converting the cross reference table content in PDFObjects if xrefContent != None: ret = self.createPDFCrossRefSection(xrefContent,xrefOffset) if ret[0] != -1: xrefSection = ret[1] pdfFile.addCrossRefTableSection([xrefSection, xrefStreamSection]) # Converting the trailer content in PDFObjects if body.containsXrefStreams(): ret = self.createPDFTrailerFromStream(xrefObject,trailerContent) if ret[0] != -1: streamTrailer = ret[1] ret = self.createPDFTrailer(trailerContent, trailerOffset, streamPresent = True) if ret[0] != -1: trailer = ret[1] if streamTrailer != None and not pdfFile.isEncrypted(): encryptDict = streamTrailer.getDictEntry('/Encrypt') if encryptDict != None: pdfFile.setEncrypted(True) elif trailer != None: encryptDict = trailer.getDictEntry('/Encrypt') if encryptDict != None: pdfFile.setEncrypted(True) if trailer != None: fileId = trailer.getDictEntry('/ID') if fileId == None: fileId = streamTrailer.getDictEntry('/ID') else: ret = self.createPDFTrailer(trailerContent, trailerOffset) if ret[0] != -1 and not pdfFile.isEncrypted(): trailer = ret[1] encryptDict = trailer.getDictEntry('/Encrypt') if encryptDict != None: pdfFile.setEncrypted(True) fileId = trailer.getDictEntry('/ID') if pdfFile.getEncryptDict() == None and encryptDict != None: objectType = encryptDict.getType() if objectType == 'reference': encryptDictId = encryptDict.getId() encryptObject = pdfFile.getObject(encryptDictId,i) if encryptObject != None: objectType = encryptObject.getType() encryptDict = encryptObject else: if i == pdfFile.updates: pdfFile.addError('/Encrypt dictionary not found') if objectType == 'dictionary': pdfFile.setEncryptDict([encryptDictId,encryptDict.getElements()]) if fileId != None and pdfFile.getFileId() == '': objectType = fileId.getType() if objectType == 'array': fileIdElements = fileId.getElements() if fileIdElements != None and fileIdElements != []: if fileIdElements[0] != None: fileId = fileIdElements[0].getValue() pdfFile.setFileId(fileId) elif fileIdElements[1] != None: fileId = fileIdElements[1].getValue() pdfFile.setFileId(fileId) pdfFile.addTrailer([trailer, streamTrailer]) if pdfFile.isEncrypted() and pdfFile.getEncryptDict() != None: ret = pdfFile.decrypt() if ret[0] == -1: pdfFile.addError(ret[1]) return (0,pdfFile) def parsePDFSections(self, content, forceMode = False, looseMode = False): ''' Method to parse the different sections of a version of a PDF document. @param content The raw content of the version of the PDF document. @param forceMode Boolean to specify if ignore errors or not. Default value: False. @param looseMode Boolean to set the loose mode when parsing objects. Default value: False. @return An array with the different sections found: body, trailer and cross reference table ''' threeSections = False bodyContent = None xrefContent = None trailerContent = None global pdfFile indexTrailer = content.find('trailer') if indexTrailer != -1: restContent = content[:indexTrailer] auxTrailer = content[indexTrailer:] indexEOF = auxTrailer.find('%%EOF') if indexEOF == -1: trailerContent = auxTrailer else: trailerContent = auxTrailer[:indexEOF+5] indexXref = restContent.find('xref') if indexXref != -1: bodyContent = restContent[:indexXref] xrefContent = restContent[indexXref:] else: bodyContent = restContent if forceMode: pdfFile.addError('Xref section not found') return [bodyContent,xrefContent,trailerContent] indexTrailer = content.find('startxref') if indexTrailer != -1: restContent = content[:indexTrailer] auxTrailer = content[indexTrailer:] indexEOF = auxTrailer.find('%%EOF') if indexEOF == -1: trailerContent = auxTrailer else: trailerContent = auxTrailer[:indexEOF+5] bodyContent = restContent return [bodyContent,xrefContent,trailerContent] return [content,xrefContent,trailerContent] def createPDFIndirectObject (self, rawIndirectObject, forceMode = False, looseMode = False) : ''' Create a PDFIndirectObject instance from the raw content of the PDF file @param rawIndirectObject string with the raw content of the PDF body. @param forceMode specifies if the parsing process should ignore errors or not (boolean). @param looseMode specifies if the parsing process should search for the endobj tag or not (boolean). @return A tuple (status,statusContent), where statusContent is the PDFIndirectObject in case status = 0 or an error in case status = -1 ''' global pdfFile try: self.charCounter = 0 pdfIndirectObject = PDFIndirectObject() ret,id = self.readUntilNotRegularChar(rawIndirectObject) pdfIndirectObject.setId(int(id)) ret,genNum = self.readUntilNotRegularChar(rawIndirectObject) pdfIndirectObject.setGenerationNumber(int(genNum)) ret = self.readSymbol(rawIndirectObject, 'obj') if ret[0] == -1: return ret rawObject = rawIndirectObject[self.charCounter:] ret = self.readObject(rawObject, forceMode = forceMode, looseMode = looseMode) if ret[0] == -1: return ret object = ret[1] pdfIndirectObject.setObject(object) ret = self.readSymbol(rawIndirectObject, 'endobj', False) pdfIndirectObject.setSize(self.charCounter) except: errorMessage = 'Unspecified parsing error' pdfFile.addError(errorMessage) return (-1, errorMessage) pdfFile.setMaxObjectId(id) return (0,pdfIndirectObject) def createPDFArray(self, rawContent): ''' Create a PDFArray instance from the raw content of the PDF file @param rawContent string with the raw content of the PDF body. @return A tuple (status,statusContent), where statusContent is the PDFArray in case status = 0 or an error in case status = -1 ''' global pdfFile realCounter = self.charCounter self.charCounter = 0 elements = [] ret = self.readObject(rawContent) if ret[0] == -1: if ret[1] != 'Empty content reading object': if isForceMode: pdfFile.addError(ret[1]) pdfObject = None else: return ret else: pdfObject = None else: pdfObject = ret[1] while pdfObject != None: elements.append(pdfObject) ret = self.readObject(rawContent[self.charCounter:]) if ret[0] == -1: if ret[1] != 'Empty content reading object': if isForceMode: pdfFile.addError(ret[1]) pdfObject = None else: return ret else: pdfObject = None else: pdfObject = ret[1] try: pdfArray = PDFArray(rawContent, elements) except Exception,e: errorMessage = 'Error creating PDFArray' if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) self.charCounter = realCounter return (0,pdfArray) def createPDFDictionary(self, rawContent): ''' Create a PDFDictionary instance from the raw content of the PDF file @param rawContent string with the raw content of the PDF body. @return A tuple (status,statusContent), where statusContent is the PDFDictionary in case status = 0 or an error in case status = -1 ''' realCounter = self.charCounter self.charCounter = 0 elements = {} rawNames = {} ret = self.readObject(rawContent[self.charCounter:], 'name') if ret[0] == -1: if ret[1] != 'Empty content reading object': if isForceMode: pdfFile.addError(ret[1]) name = None else: return ret else: name = None else: name = ret[1] while name != None: key = name.getValue() rawNames[key] = name rawValue = rawContent[self.charCounter:] ret = self.readObject(rawValue) if ret[0] == -1: if isForceMode: pdfFile.addError('Bad object for '+str(key)+' key') ret = self.readUntilSymbol(rawContent, '/') if ret[0] == -1: elements[key] = PDFString(rawValue) else: elements[key] = PDFString(ret[1]) self.readSpaces(rawContent) else: return (-1,'Bad object for '+str(key)+' key') else: value = ret[1] elements[key] = value ret = self.readObject(rawContent[self.charCounter:], 'name') if ret[0] == -1: if ret[1] != 'Empty content reading object': if isForceMode: pdfFile.addError(ret[1]) name = None else: return ret else: name = None else: name = ret[1] if name != None and name.getType() != 'name': errorMessage = 'Name object not found in dictionary key' if isForceMode: pdfFile.addError(errorMessage) name = None else: return (-1, errorMessage) try: pdfDictionary = PDFDictionary(rawContent, elements, rawNames) except Exception,e: errorMessage = 'Error creating PDFDictionary' if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) self.charCounter = realCounter return (0,pdfDictionary) def createPDFStream(self, dict, stream): ''' Create a PDFStream or PDFObjectStream instance from the raw content of the PDF file @param dict Raw content of the dictionary object. @param stream Raw content of the stream. @return A tuple (status,statusContent), where statusContent is the PDFStream or PDFObjectStream in case status = 0 or an error in case status = -1 ''' realCounter = self.charCounter self.charCounter = 0 elements = {} rawNames = {} ret = self.readObject(dict[self.charCounter:], 'name') if ret[0] == -1: if ret[1] != 'Empty content reading object': if isForceMode: pdfFile.addError(ret[1]) name = None else: return ret else: name = None else: name = ret[1] while name != None: key = name.getValue() rawNames[key] = name ret = self.readObject(dict[self.charCounter:]) if ret[0] == -1: if ret[1] != 'Empty content reading object': if isForceMode: pdfFile.addError(ret[1]) value = None else: return ret else: value = None else: value = ret[1] elements[key] = value ret = self.readObject(dict[self.charCounter:], 'name') if ret[0] == -1: if ret[1] != 'Empty content reading object': if isForceMode: pdfFile.addError(ret[1]) name = None else: return ret else: name = None else: name = ret[1] if elements.has_key('/Type') and elements['/Type'].getValue() == '/ObjStm': try: pdfStream = PDFObjectStream(dict, stream, elements, rawNames, {}) except Exception,e: errorMessage = 'Error creating PDFObjectStream' if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) else: try: pdfStream = PDFStream(dict, stream, elements, rawNames) except Exception,e: errorMessage = 'Error creating PDFStream' if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) self.charCounter = realCounter return (0,pdfStream) def createPDFCrossRefSection (self, rawContent, offset): ''' Create a PDFCrossRefSection instance from the raw content of the PDF file @param rawContent String with the raw content of the PDF body (string) @param offset Offset of the cross reference section in the PDF file (int) @return A tuple (status,statusContent), where statusContent is the PDFCrossRefSection in case status = 0 or an error in case status = -1 ''' global isForceMode,pdfFile if not isinstance(rawContent,str): return (-1,'Empty xref content') entries = [] auxOffset = 0 subSectionSize = 0 self.charCounter = 0 pdfCrossRefSection = PDFCrossRefSection() pdfCrossRefSection.setOffset(offset) pdfCrossRefSection.setSize(len(rawContent)) pdfCrossRefSubSection = None beginSubSectionRE = re.compile('(\d{1,10})\s(\d{1,10})\s*$') entryRE = re.compile('(\d{10})\s(\d{5})\s([nf])') ret = self.readSymbol(rawContent, 'xref') if ret[0] == -1: return ret auxOffset += self.charCounter lines = self.getLines(rawContent[self.charCounter:]) if lines == []: if isForceMode: pdfCrossRefSubSection = PDFCrossRefSubSection(0, offset = -1) pdfFile.addError('No entries in xref section') else: return (-1,'Error: No entries in xref section!!') else: for line in lines: match = re.findall(beginSubSectionRE,line) if match != []: if pdfCrossRefSubSection != None: pdfCrossRefSubSection.setSize(subSectionSize) pdfCrossRefSection.addSubsection(pdfCrossRefSubSection) pdfCrossRefSubSection.setEntries(entries) subSectionSize = 0 entries = [] try: pdfCrossRefSubSection = PDFCrossRefSubSection(match[0][0],match[0][1],offset = auxOffset) except: return (-1,'Error creating PDFCrossRefSubSection') else: match = re.findall(entryRE,line) if match != []: try: pdfCrossRefEntry = PDFCrossRefEntry(match[0][0],match[0][1],match[0][2], offset = auxOffset) except: return (-1,'Error creating PDFCrossRefEntry') entries.append(pdfCrossRefEntry) else: #TODO: comments in line or spaces/\n\r...? if isForceMode: if pdfCrossRefSubSection != None: pdfCrossRefSubSection.addError('Bad format for cross reference entry: '+line) else: pdfCrossRefSubSection = PDFCrossRefSubSection(0, offset = -1) pdfFile.addError('Bad xref section') else: return (-1,'Bad format for cross reference entry') auxOffset += len(line) subSectionSize += len(line) pdfCrossRefSubSection.setSize(subSectionSize) pdfCrossRefSection.addSubsection(pdfCrossRefSubSection) pdfCrossRefSubSection.setEntries(entries) return (0,pdfCrossRefSection) def createPDFCrossRefSectionFromStream (self, objectStream): ''' Create a PDFCrossRefSection instance from the raw content of the PDF file @param objectStream Object stream object (PDFIndirectObject). @return A tuple (status,statusContent), where statusContent is the PDFCrossRefSection in case status = 0 or an error in case status = -1 ''' index = 0 firstEntry = 0 entries = [] numObjects = 0 numSubsections = 1 bytesPerField = [1,2,1] entrySize = 4 subsectionIndexes = [] if objectStream != None: pdfCrossRefSection = PDFCrossRefSection() pdfCrossRefSection.setXrefStreamObject(objectStream.getId()) xrefObject = objectStream.getObject() if xrefObject != None: if xrefObject.hasElement('/Size'): sizeObject = xrefObject.getElementByName('/Size') if sizeObject != None and sizeObject.getType() == 'integer': numObjects = sizeObject.getRawValue() subsectionIndexes = [0,numObjects] else: errorMessage = 'Bad object type for /Size element' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Element /Size not found' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) if xrefObject.hasElement('/W'): bytesPerFieldObject = xrefObject.getElementByName('/W') if bytesPerFieldObject.getType() == 'array': bytesPerField = bytesPerFieldObject.getElementRawValues() if len(bytesPerField) != 3: errorMessage = 'Bad content of /W element' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) else: entrySize = 0 for num in bytesPerField: entrySize += num else: errorMessage = 'Bad object type for /W element' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) else: errorMessage = 'Element /W not found' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) if xrefObject.hasElement('/Index'): subsectionIndexesObject = xrefObject.getElementByName('/Index') if subsectionIndexesObject.getType() == 'array': subsectionIndexes = subsectionIndexesObject.getElementRawValues() if len(subsectionIndexes) % 2 != 0: errorMessage = 'Bad content of /Index element' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) else: numSubsections = len(subsectionIndexes) / 2 else: errorMessage = 'Bad object type for /Index element' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) pdfCrossRefSection.setBytesPerField(bytesPerField) stream = xrefObject.getStream() for i in range(0,len(stream),entrySize): entryBytes = stream[i:i+entrySize] try: if bytesPerField[0] == 0: f1 = 1 else: f1 = int(entryBytes[:bytesPerField[0]].encode('hex'),16) if bytesPerField[1] == 0: f2 = 0 else: f2 = int(entryBytes[bytesPerField[0]:bytesPerField[0]+bytesPerField[1]].encode('hex'),16) if bytesPerField[2] == 0: f3 = 0 else: f3 = int(entryBytes[bytesPerField[0]+bytesPerField[1]:].encode('hex'),16) except: errorMessage = 'Error in hexadecimal conversion' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) try: pdfCrossRefEntry = PDFCrossRefEntry(f2,f3,f1) except: errorMessage = 'Error creating PDFCrossRefEntry' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) entries.append(pdfCrossRefEntry) for i in range(numSubsections): firstObject = subsectionIndexes[index] numObjectsInSubsection = subsectionIndexes[index+1] try: pdfCrossRefSubSection = PDFCrossRefSubSection(firstObject,numObjectsInSubsection) except: errorMessage = 'Error creating PDFCrossRefSubSection' if isForceMode: pdfCrossRefSection.addError(errorMessage) else: return (-1, errorMessage) pdfCrossRefSubSection.setEntries(entries[firstEntry:firstEntry+numObjectsInSubsection]) pdfCrossRefSection.addSubsection(pdfCrossRefSubSection) firstentry = numObjectsInSubsection index += 2 return (0,pdfCrossRefSection) else: return (-1,'The object stream is None') else: return (-1,'The indirect object stream is None') def createPDFTrailer (self, rawContent, offset, streamPresent = False) : ''' Create a PDFTrailer instance from the raw content of the PDF file @param rawContent String with the raw content of the PDF body (string) @param offset Offset of the trailer in the PDF file (int) @param streamPresent It specifies if an object stream exists in the PDF body @return A tuple (status,statusContent), where statusContent is the PDFTrailer in case status = 0 or an error in case status = -1 ''' global pdfFile,isForceMode trailer = None self.charCounter = 0 if not isinstance(rawContent,str): return (-1,'Empty trailer content') self.readSymbol(rawContent, 'trailer') ret = self.readObject(rawContent[self.charCounter:],'dictionary') if ret[0] == -1: dict = PDFDictionary('') dict.addError('Error creating the trailer dictionary') else: dict = ret[1] ret = self.readSymbol(rawContent, 'startxref') if ret[0] == -1: try: trailer = PDFTrailer(dict, streamPresent = streamPresent) except Exception,e: errorMessage = 'Error creating PDFTrailer' if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) else: ret = self.readUntilEndOfLine(rawContent) if ret[0] == -1: if isForceMode: lastXrefSection = -1 pdfFile.addError('EOL not found while looking for the last cross reference section') else: return (-1,'EOL not found while looking for the last cross reference section') else: lastXrefSection = ret[1] try: trailer = PDFTrailer(dict, lastXrefSection, streamPresent = streamPresent) except Exception,e: errorMessage = 'Error creating PDFTrailer' if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) trailer.setOffset(offset) eofOffset = rawContent.find('%%EOF') if eofOffset == -1: trailer.setEOFOffset(eofOffset) trailer.setSize(len(rawContent)) else: trailer.setEOFOffset(offset+eofOffset) trailer.setSize(eofOffset) return (0,trailer) def createPDFTrailerFromStream (self, indirectObject, rawContent) : ''' Create a PDFTrailer instance from the raw content of the PDF file @param indirectObject Object stream object (PDFIndirectObject). @param rawContent String with the raw content of the PDF body (string) @return A tuple (status,statusContent), where statusContent is the PDFTrailer in case status = 0 or an error in case status = -1 ''' trailer = None self.charCounter = 0 trailerElements = ['/Size','/Prev','/Root','/Encrypt','/Info','/ID'] dict = {} if indirectObject != None: xrefStreamObject = indirectObject.getObject() if xrefStreamObject != None: for element in trailerElements: if xrefStreamObject.hasElement(element): dict[element] = xrefStreamObject.getElementByName(element) try: dict = PDFDictionary('',dict) except Exception,e: if isForceMode: dict = None else: errorMessage = 'Error creating PDFDictionary' if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) if not isinstance(rawContent,str): if isForceMode: lastXrefSection = -1 else: return (-1,'Empty trailer content') else: ret = self.readUntilSymbol(rawContent, 'startxref') if ret[0] == -1 and not isForceMode: return ret ret = self.readSymbol(rawContent, 'startxref') if ret[0] == -1 and not isForceMode: return ret ret = self.readUntilEndOfLine(rawContent) if ret[0] == -1: if not isForceMode: return ret lastXrefSection = -1 else: lastXrefSection = ret[1] try: trailer = PDFTrailer(dict, lastXrefSection) except Exception,e: errorMessage = 'Error creating PDFTrailer' if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) trailer.setXrefStreamObject(indirectObject.getId()) else: return (-1,'Object stream is None') else: return (-1,'Indirect object stream is None') return (0,trailer) def getIndirectObjects(self, content, looseMode = False): ''' This function returns an array of raw indirect objects of the PDF file given the raw body. @param content: string with the raw content of the PDF body. @param looseMode: boolean specifies if the parsing process should search for the endobj tag or not. @return matchingObjects: array of tuples (object_content,object_header). ''' global pdfFile matchingObjects = [] if not isinstance(content,str): return matchingObjects if not looseMode: regExp = re.compile('((\d{1,10}\s\d{1,10}\sobj).*?endobj)',re.DOTALL) matchingObjects = regExp.findall(content) else: regExp = re.compile('((\d{1,10}\s\d{1,10}\sobj).*?)\s\d{1,10}\s\d{1,10}\sobj',re.DOTALL) matchingObjectsAux = regExp.findall(content) while matchingObjectsAux != []: if matchingObjectsAux[0] != []: objectBody = matchingObjectsAux[0][0] matchingObjects.append(matchingObjectsAux[0]) content = content[content.find(objectBody)+len(objectBody):] matchingObjectsAux = regExp.findall(content) else: matchingObjectsAux = [] lastObject = re.findall('(\d{1,5}\s\d{1,5}\sobj)',content,re.DOTALL) if lastObject != []: content = content[content.find(lastObject[0]):] matchingObjects.append((content,lastObject[0])) return matchingObjects def getLines(self, content): ''' Simple function to return the lines separated by end of line characters @param content @return List with the lines, without end of line characters ''' lines = [] i = 0 while i < len(content): if content[i] == '\r': lines.append(content[:i]) if content[i+1] == '\n': i += 1 content = content[i+1:] i = 0 elif content[i] == '\n': lines.append(content[:i]) content = content[i+1:] i = 0 i += 1 if i > 0: lines.append(content) return lines def readObject(self, content, objectType = None, forceMode = False, looseMode = False): ''' Method to parse the raw body of the PDF file and obtain PDFObject instances @param content @param objectType @param forceMode @param looseMode @return A tuple (status,statusContent), where statusContent is a PDFObject instance in case status = 0 or an error in case status = -1 ''' global pdfFile if len(content) == 0 or content[:6] == 'endobj': return (-1,'Empty content reading object') pdfObject = None oldCounter = self.charCounter self.charCounter = 0 if objectType != None: objectsTypeArray = [self.delimiters[i][2] for i in range(len(self.delimiters))] index = objectsTypeArray.index(objectType) if index != -1: delimiters = [self.delimiters[index]] else: if isForceMode: pdfFile.addError('Unknown object type while parsing object') return (-1,'Unknown object type') else: sys.exit('Error: Unknown object type!!') else: delimiters = self.delimiters for delim in delimiters: ret = self.readSymbol(content, delim[0]) if ret[0] != -1: if delim[2] == 'dictionary': ret = self.readUntilClosingDelim(content, delim) if ret[0] == -1: dictContent = '' else: dictContent = ret[1] nonDictContent = content[self.charCounter:] streamFound = re.findall('[>\s]stream', nonDictContent) if streamFound: ret = self.readUntilSymbol(content, 'stream') if ret[0] == -1: return ret auxDict = ret[1] self.readSymbol(content, 'stream', False) self.readUntilEndOfLine(content) self.readSymbol(content, '\r', False) self.readSymbol(content, '\n', False) ret = self.readUntilSymbol(content, 'endstream') if ret[0] == -1: stream = content[self.charCounter:] else: stream = ret[1] self.readSymbol(content, 'endstream') ret = self.createPDFStream(dictContent, stream) if ret[0] == -1: return ret pdfObject = ret[1] break else: if ret[0] != -1: self.readSymbol(content, delim[1]) ret = self.createPDFDictionary(dictContent) if ret[0] == -1: return ret pdfObject = ret[1] else: pdfObject = PDFDictionary(content) pdfObject.addError('Closing delimiter not found in dictionary object') break elif delim[2] == 'string': ret = self.readUntilClosingDelim(content, delim) if ret[0] != -1: stringContent = ret[1] self.readSymbol(content, delim[1]) pdfObject = PDFString(stringContent) else: pdfObject = PDFString(content) pdfObject.addError('Closing delimiter not found in string object') break elif delim[2] == 'hexadecimal': ret = self.readUntilClosingDelim(content, delim) if ret[0] != -1: hexContent = ret[1] self.readSymbol(content, delim[1]) pdfObject = PDFHexString(hexContent) else: pdfObject = PDFHexString(content) pdfObject.addError('Closing delimiter not found in hexadecimal object') break elif delim[2] == 'array': ret = self.readUntilClosingDelim(content, delim) if ret[0] != -1: arrayContent = ret[1] self.readSymbol(content, delim[1]) ret = self.createPDFArray(arrayContent) if ret[0] == -1: return ret pdfObject = ret[1] else: pdfObject = PDFArray(content) pdfObject.addError('Closing delimiter not found in array object') break elif delim[2] == 'name': ret,raw = self.readUntilNotRegularChar(content) pdfObject = PDFName(raw) break elif delim[2] == 'comment': ret = self.readUntilEndOfLine(content) if ret[0] == 0: self.comments.append(ret[1]) self.readSpaces(content) pdfObject = self.readObject(content[self.charCounter:],objectType) else: return ret break else: if content[0] == 't' or content[0] == 'f': ret,raw = self.readUntilNotRegularChar(content) pdfObject = PDFBool(raw) elif content[0] == 'n': ret,raw = self.readUntilNotRegularChar(content) pdfObject = PDFNull(raw) elif re.findall('^(\d{1,10}\s{1,3}\d{1,10}\s{1,3}R)', content, re.DOTALL) != []: ret,id = self.readUntilNotRegularChar(content) ret,genNumber = self.readUntilNotRegularChar(content) ret = self.readSymbol(content, 'R') if ret[0] == -1: return ret pdfObject = PDFReference(id, genNumber) elif re.findall('^([-+]?\.?\d{1,15}\.?\d{0,15})', content, re.DOTALL) != []: ret,num = self.readUntilNotRegularChar(content) pdfObject = PDFNum(num) else: self.charCounter += oldCounter return (-1,'Object not found') self.charCounter += oldCounter return (0,pdfObject) def readSpaces(self, string): ''' Reads characters until all spaces chars have been read @param string @return A tuple (status,statusContent), where statusContent is the number of characters read in case status = 0 or an error in case status = -1 ''' if not isinstance(string,str): return (-1,'Bad string') spacesCounter = self.charCounter for i in range(self.charCounter,len(string)): if string[i] not in spacesChars: break self.charCounter += 1 spacesCounter -= self.charCounter return (0,spacesCounter) def readSymbol(self, string, symbol, deleteSpaces = True): ''' Reads a given symbol from the string, removing comments and spaces (if specified) @param string @param symbol @param deleteSpaces @return A tuple (status,statusContent), where statusContent is the number of characters read in case status = 0 or an error in case status = -1 ''' global pdfFile if not isinstance(string,str): return (-1,'Bad string') oldCharCounter = self.charCounter if self.charCounter > len(string)-1: errorMessage = 'EOF while looking for symbol "'+symbol+'"' pdfFile.addError(errorMessage) return (-1, errorMessage) while string[self.charCounter] == '%': ret = self.readUntilEndOfLine(string) if ret[0] == -1: return ret self.comments.append(ret[1]) self.readSpaces(string) symbolToRead = string[self.charCounter:self.charCounter+len(symbol)] if symbolToRead != symbol: errorMessage = 'Symbol "'+symbol+'" not found while parsing' #pdfFile.addError(errorMessage) return (-1, errorMessage) self.charCounter += len(symbol) if deleteSpaces: self.readSpaces(string) return (0,self.charCounter - oldCharCounter) def readUntilClosingDelim(self, content, delim): ''' Method that reads characters until it finds the closing delimiter @param content @param delim @return A tuple (status,statusContent), where statusContent is the characters read in case status = 0 or an error in case status = -1 ''' global pdfFile output = '' if not isinstance(content,str): return (-1,'Bad string') newContent = content[self.charCounter:] numOpeningDelims = newContent.count(delim[0]) + 1 numClosingDelims = newContent.count(delim[1]) if numClosingDelims == 0: errorMessage = 'No closing delimiter found' pdfFile.addError(errorMessage) return (-1, errorMessage) elif numClosingDelims == 1: index = newContent.rfind(delim[1]) self.charCounter += index return (0,newContent[:index]) else: indexChar = 0 prevChar = '' while indexChar != len(newContent): char = newContent[indexChar] if indexChar == len(newContent) - 1: nextChar = '' else: nextChar = newContent[indexChar+1] if char == delim[1] or (char + nextChar) == delim[1]: if char != ')' or indexChar == 0 or newContent[indexChar-1] != '\\': return (0,output) else: output += char indexChar += 1 self.charCounter += 1 elif (char == '(' and prevChar != '\\') or (char in ['[','<'] and delim[0] != '('): if (char + nextChar) != '<<': delimIndex = delimiterChars.index(char) self.charCounter += 1 ret = self.readUntilClosingDelim(content, self.delimiters[delimIndex]) if ret[0] != -1: tempObject = char + ret[1] else: return ret else: delimIndex = delimiterChars.index(char + nextChar) self.charCounter += 2 ret = self.readUntilClosingDelim(content, self.delimiters[delimIndex]) if ret[0] != -1: tempObject = char + nextChar + ret[1] else: return ret ret = self.readSymbol(content, self.delimiters[delimIndex][1], False) if ret[0] != -1: tempObject += self.delimiters[delimIndex][1] else: return ret indexChar += len(tempObject) output += tempObject else: indexChar += 1 self.charCounter += 1 output += char prevChar = char else: errorMessage = 'No closing delimiter found' pdfFile.addError(errorMessage) return (-1, errorMessage) def readUntilEndOfLine(self, content): ''' This function reads characters until the end of line @param content @return A tuple (status,statusContent), where statusContent is the characters read in case status = 0 or an error in case status = -1 ''' global pdfFile if not isinstance(content,str): return (-1,'Bad string') errorMessage = [] oldCharCounter = self.charCounter tmpContent = content[self.charCounter:] for char in tmpContent: if char == '\r' or char == '\n': return (0,content[oldCharCounter:self.charCounter]) self.charCounter += 1 else: errorMessage = 'EOL not found' pdfFile.addError(errorMessage) return (-1, errorMessage) def readUntilLastSymbol(self, string, symbol): ''' Method that reads characters until it finds the last appearance of 'symbol' @param string @param symbol @return A tuple (status,statusContent), where statusContent is the characters read in case status = 0 or an error in case status = -1 ''' global pdfFile if not isinstance(string,str): return (-1,'Bad string') newString = string[self.charCounter:] index = newString.rfind(symbol) if index == -1: errorMessage = 'Symbol "'+symbol+'" not found' pdfFile.addError(errorMessage) return (-1, errorMessage) self.charCounter += index return (0,newString[:index]) def readUntilNotRegularChar(self, string): ''' Reads the regular chars of the string until it reachs a non-regular char. Then it removes spaces chars. @param string @return A tuple (status,statusContent), where statusContent is the number of characters read in case status = 0 or an error in case status = -1 ''' readChars = '' if not isinstance(string,str): return (-1,'Bad string') notRegChars = spacesChars + delimiterChars for i in range(self.charCounter,len(string)): if string[i] in notRegChars: self.readSpaces(string) break readChars += string[i] self.charCounter += 1 return (0,readChars) def readUntilSymbol(self, string, symbol): ''' Method that reads characters until it finds the first appearance of 'symbol' @param string @param symbol @return A tuple (status,statusContent), where statusContent is the characters read in case status = 0 or an error in case status = -1 ''' global pdfFile if not isinstance(string,str): return (-1,'Bad string') newString = string[self.charCounter:] index = newString.find(symbol) if index == -1: errorMessage = 'Symbol "'+symbol+'" not found' return (-1, errorMessage) self.charCounter += index return (0,newString[:index])
gpl-2.0
[ 3, 199, 3, 259, 299, 1024, 5607, 365, 282, 4744, 370, 21297, 436, 2811, 15537, 1584, 199, 3, 259, 1455, 921, 321, 1545, 1587, 14, 69, 2147, 13, 11396, 14, 957, 199, 3, 259, 4885, 1603, 3362, 28195, 13086, 662, 22502, 8076, 665, 74, 397, 462, 8076, 15059, 325, 2147, 13, 11396, 14, 957, 30, 199, 3, 199, 3, 259, 1898, 334, 35, 9, 7760, 13, 7280, 1603, 3362, 28195, 13086, 662, 22502, 8076, 199, 3, 199, 3, 259, 961, 570, 365, 1777, 402, 299, 1024, 5607, 14, 199, 3, 199, 3, 263, 299, 1024, 5607, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 263, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 263, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 263, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 263, 299, 1024, 5607, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 263, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 263, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 259, 1666, 314, 199, 3, 263, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 263, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 263, 3180, 543, 299, 1024, 5607, 14, 259, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 2344, 272, 961, 859, 3509, 3992, 436, 3102, 370, 21297, 436, 2811, 15537, 1584, 199, 2344, 199, 199, 646, 984, 12, 736, 12, 264, 12, 24722, 12, 1820, 12, 17499, 465, 19093, 199, 504, 15537, 7535, 492, 627, 199, 504, 15537, 17134, 492, 627, 199, 504, 18001, 13182, 492, 627, 199, 504, 510, 36, 1665, 382, 878, 492, 4849, 3296, 12, 2143, 3296, 199, 199, 45, 748, 63, 1761, 275, 413, 199, 45, 748, 63, 5211, 275, 499, 199, 45, 748, 63, 37, 15862, 275, 650, 199, 45, 748, 63, 1719, 8909, 275, 841, 199, 45, 748, 63, 56, 8279, 275, 959, 199, 45, 748, 63, 9439, 63, 5211, 275, 1227, 199, 5607, 1173, 275, 488, 199, 1222, 3049, 275, 747, 14, 19254, 199, 374, 13606, 1385, 275, 756, 199, 374, 22382, 13182, 275, 756, 199, 10749, 11229, 275, 788, 60, 88, 383, 297, 1154, 88, 1643, 297, 1154, 88, 16, 65, 297, 1154, 88, 16, 67, 297, 1154, 88, 16, 68, 297, 1154, 88, 1165, 418, 199, 15104, 11229, 275, 788, 8999, 1673, 8, 1673, 28, 1673, 59, 1673, 91, 32381, 1673, 5, 418, 199, 7157, 1759, 11770, 275, 18744, 4299, 3310, 1656, 9807, 2276, 1656, 9807, 5866, 1656, 9807, 1945, 293, 2821, 1656, 1994, 56, 2078, 24710, 199, 7157, 1759, 9303, 275, 18744, 11378, 1656, 9807, 21986, 32381, 18543, 32381, 17187, 2821, 32381, 6295, 1451, 418, 199, 7157, 1759, 6255, 275, 18744, 27395, 5535, 1656, 2432, 1994, 27395, 1173, 297, 2432, 1994, 42, 18643, 18, 9400, 297, 2432, 283, 27275, 46, 273, 10155, 297, 2432, 283, 4958, 14, 915, 18387, 297, 2432, 1994, 53, 19, 36, 297, 2432, 1994, 3311, 35, 297, 2432, 1994, 50, 1158, 11398, 297, 2432, 1987, 1773, 1110, 297, 2432, 283, 3250, 14, 6352, 418, 199, 3596, 54, 348, 561, 275, 788, 26206, 297, 1779, 283, 2001, 5561, 14, 7112, 7035, 2354, 297, 1779, 283, 1974, 14, 19139, 297, 1779, 283, 362, 21761, 83, 297, 1779, 283, 362, 8954, 297, 1779, 283, 32252, 14, 4229, 11728, 4299, 297, 1779, 283, 4603, 14, 1222, 10921, 297, 1779, 283, 1301, 14, 1361, 1513, 1190, 297, 1779, 283, 571, 14, 2168, 5157, 4259, 418, 199, 1044, 11427, 985, 275, 283, 967, 393, 804, 14, 12567, 14, 3235, 985, 7, 199, 22308, 54, 348, 78, 275, 283, 34, 1658, 15, 50, 906, 13295, 1970, 5505, 296, 7, 199, 86, 348, 561, 2141, 275, 791, 26206, 17150, 26206, 297, 459, 35, 2524, 13, 9488, 13, 21, 10173, 3815, 1467, 283, 2001, 5561, 14, 7112, 7035, 2354, 17150, 2001, 5561, 14, 7112, 7035, 2354, 297, 459, 35, 2524, 13, 9488, 13, 1367, 1427, 3815, 1467, 283, 1974, 14, 19139, 17150, 1974, 14, 19139, 297, 459, 35, 2524, 13, 9300, 13, 10488, 18, 3815, 1467, 1994, 42, 18643, 18, 9400, 17150, 33, 1117, 1235, 1603, 18643, 18, 9400, 5311, 439, 7499, 5505, 296, 297, 459, 35, 2524, 13, 8664, 13, 1690, 2010, 3815, 1467, 283, 362, 8954, 17150, 362, 8954, 297, 459, 35, 2524, 13, 8664, 13, 1643, 1465, 3815, 1467, 283, 362, 21761, 83, 17150, 362, 21761, 83, 297, 459, 35, 2524, 13, 8664, 13, 1079, 2942, 3815, 1467, 283, 32252, 14, 4229, 11728, 4299, 17150, 32252, 14, 4229, 11728, 4299, 297, 459, 35, 2524, 13, 8664, 13, 1079, 3129, 3815, 1467, 283, 4603, 14, 1222, 10921, 17150, 4603, 14, 1222, 10921, 297, 459, 35, 2524, 13, 8664, 13, 10657, 20, 3815, 1467, 1987, 1773, 1110, 17150, 33, 1117, 1235, 4473, 293, 13475, 699, 725, 1146, 8003, 13247, 1665, 7225, 7259, 1659, 297, 459, 35, 2524, 13, 6542, 13, 614, 1299, 3815, 1467, 308, 316, 11427, 985, 20334, 1044, 11427, 985, 12, 459, 35, 2524, 13, 6542, 13, 10740, 19, 3815, 1467, 283, 1301, 14, 1361, 1513, 1190, 17150, 1301, 14, 1361, 1513, 1190, 297, 459, 35, 2524, 13, 6542, 13, 12443, 17, 3815, 1467, 1994, 53, 19, 36, 356, 2336, 53, 19, 36, 297, 459, 35, 2524, 13, 8664, 13, 1355, 2481, 1673, 35, 2524, 13, 8664, 13, 1355, 1427, 1673, 35, 2524, 13, 8128, 13, 1194, 2789, 3815, 1467, 1994, 3311, 35, 356, 2336, 3311, 35, 297, 459, 35, 2524, 13, 8128, 13, 20, 11939, 3815, 1467, 283, 3250, 14, 6352, 17150, 33, 1117, 1235, 23099, 1323, 2078, 1373, 3466, 3493, 1910, 13, 12486, 4402, 373, 29419, 297, 459, 35, 2524, 13, 6965, 13, 16, 12021, 3815, 327, 4178, 921, 76, 2101, 14, 719, 3119, 14392, 14, 331, 14, 3210, 15, 11486, 15, 67, 432, 13, 6965, 13, 16, 12021, 13, 5129, 1235, 13, 5503, 13, 10500, 13, 26593, 1739, 13, 324, 13, 12486, 13, 4844, 13, 86, 29419, 13, 2064, 13, 17, 15, 1467, 330 ]
[ 199, 3, 259, 299, 1024, 5607, 365, 282, 4744, 370, 21297, 436, 2811, 15537, 1584, 199, 3, 259, 1455, 921, 321, 1545, 1587, 14, 69, 2147, 13, 11396, 14, 957, 199, 3, 259, 4885, 1603, 3362, 28195, 13086, 662, 22502, 8076, 665, 74, 397, 462, 8076, 15059, 325, 2147, 13, 11396, 14, 957, 30, 199, 3, 199, 3, 259, 1898, 334, 35, 9, 7760, 13, 7280, 1603, 3362, 28195, 13086, 662, 22502, 8076, 199, 3, 199, 3, 259, 961, 570, 365, 1777, 402, 299, 1024, 5607, 14, 199, 3, 199, 3, 263, 299, 1024, 5607, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 263, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 263, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 263, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 263, 299, 1024, 5607, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 263, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 263, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 259, 1666, 314, 199, 3, 263, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 263, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 263, 3180, 543, 299, 1024, 5607, 14, 259, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 2344, 272, 961, 859, 3509, 3992, 436, 3102, 370, 21297, 436, 2811, 15537, 1584, 199, 2344, 199, 199, 646, 984, 12, 736, 12, 264, 12, 24722, 12, 1820, 12, 17499, 465, 19093, 199, 504, 15537, 7535, 492, 627, 199, 504, 15537, 17134, 492, 627, 199, 504, 18001, 13182, 492, 627, 199, 504, 510, 36, 1665, 382, 878, 492, 4849, 3296, 12, 2143, 3296, 199, 199, 45, 748, 63, 1761, 275, 413, 199, 45, 748, 63, 5211, 275, 499, 199, 45, 748, 63, 37, 15862, 275, 650, 199, 45, 748, 63, 1719, 8909, 275, 841, 199, 45, 748, 63, 56, 8279, 275, 959, 199, 45, 748, 63, 9439, 63, 5211, 275, 1227, 199, 5607, 1173, 275, 488, 199, 1222, 3049, 275, 747, 14, 19254, 199, 374, 13606, 1385, 275, 756, 199, 374, 22382, 13182, 275, 756, 199, 10749, 11229, 275, 788, 60, 88, 383, 297, 1154, 88, 1643, 297, 1154, 88, 16, 65, 297, 1154, 88, 16, 67, 297, 1154, 88, 16, 68, 297, 1154, 88, 1165, 418, 199, 15104, 11229, 275, 788, 8999, 1673, 8, 1673, 28, 1673, 59, 1673, 91, 32381, 1673, 5, 418, 199, 7157, 1759, 11770, 275, 18744, 4299, 3310, 1656, 9807, 2276, 1656, 9807, 5866, 1656, 9807, 1945, 293, 2821, 1656, 1994, 56, 2078, 24710, 199, 7157, 1759, 9303, 275, 18744, 11378, 1656, 9807, 21986, 32381, 18543, 32381, 17187, 2821, 32381, 6295, 1451, 418, 199, 7157, 1759, 6255, 275, 18744, 27395, 5535, 1656, 2432, 1994, 27395, 1173, 297, 2432, 1994, 42, 18643, 18, 9400, 297, 2432, 283, 27275, 46, 273, 10155, 297, 2432, 283, 4958, 14, 915, 18387, 297, 2432, 1994, 53, 19, 36, 297, 2432, 1994, 3311, 35, 297, 2432, 1994, 50, 1158, 11398, 297, 2432, 1987, 1773, 1110, 297, 2432, 283, 3250, 14, 6352, 418, 199, 3596, 54, 348, 561, 275, 788, 26206, 297, 1779, 283, 2001, 5561, 14, 7112, 7035, 2354, 297, 1779, 283, 1974, 14, 19139, 297, 1779, 283, 362, 21761, 83, 297, 1779, 283, 362, 8954, 297, 1779, 283, 32252, 14, 4229, 11728, 4299, 297, 1779, 283, 4603, 14, 1222, 10921, 297, 1779, 283, 1301, 14, 1361, 1513, 1190, 297, 1779, 283, 571, 14, 2168, 5157, 4259, 418, 199, 1044, 11427, 985, 275, 283, 967, 393, 804, 14, 12567, 14, 3235, 985, 7, 199, 22308, 54, 348, 78, 275, 283, 34, 1658, 15, 50, 906, 13295, 1970, 5505, 296, 7, 199, 86, 348, 561, 2141, 275, 791, 26206, 17150, 26206, 297, 459, 35, 2524, 13, 9488, 13, 21, 10173, 3815, 1467, 283, 2001, 5561, 14, 7112, 7035, 2354, 17150, 2001, 5561, 14, 7112, 7035, 2354, 297, 459, 35, 2524, 13, 9488, 13, 1367, 1427, 3815, 1467, 283, 1974, 14, 19139, 17150, 1974, 14, 19139, 297, 459, 35, 2524, 13, 9300, 13, 10488, 18, 3815, 1467, 1994, 42, 18643, 18, 9400, 17150, 33, 1117, 1235, 1603, 18643, 18, 9400, 5311, 439, 7499, 5505, 296, 297, 459, 35, 2524, 13, 8664, 13, 1690, 2010, 3815, 1467, 283, 362, 8954, 17150, 362, 8954, 297, 459, 35, 2524, 13, 8664, 13, 1643, 1465, 3815, 1467, 283, 362, 21761, 83, 17150, 362, 21761, 83, 297, 459, 35, 2524, 13, 8664, 13, 1079, 2942, 3815, 1467, 283, 32252, 14, 4229, 11728, 4299, 17150, 32252, 14, 4229, 11728, 4299, 297, 459, 35, 2524, 13, 8664, 13, 1079, 3129, 3815, 1467, 283, 4603, 14, 1222, 10921, 17150, 4603, 14, 1222, 10921, 297, 459, 35, 2524, 13, 8664, 13, 10657, 20, 3815, 1467, 1987, 1773, 1110, 17150, 33, 1117, 1235, 4473, 293, 13475, 699, 725, 1146, 8003, 13247, 1665, 7225, 7259, 1659, 297, 459, 35, 2524, 13, 6542, 13, 614, 1299, 3815, 1467, 308, 316, 11427, 985, 20334, 1044, 11427, 985, 12, 459, 35, 2524, 13, 6542, 13, 10740, 19, 3815, 1467, 283, 1301, 14, 1361, 1513, 1190, 17150, 1301, 14, 1361, 1513, 1190, 297, 459, 35, 2524, 13, 6542, 13, 12443, 17, 3815, 1467, 1994, 53, 19, 36, 356, 2336, 53, 19, 36, 297, 459, 35, 2524, 13, 8664, 13, 1355, 2481, 1673, 35, 2524, 13, 8664, 13, 1355, 1427, 1673, 35, 2524, 13, 8128, 13, 1194, 2789, 3815, 1467, 1994, 3311, 35, 356, 2336, 3311, 35, 297, 459, 35, 2524, 13, 8128, 13, 20, 11939, 3815, 1467, 283, 3250, 14, 6352, 17150, 33, 1117, 1235, 23099, 1323, 2078, 1373, 3466, 3493, 1910, 13, 12486, 4402, 373, 29419, 297, 459, 35, 2524, 13, 6965, 13, 16, 12021, 3815, 327, 4178, 921, 76, 2101, 14, 719, 3119, 14392, 14, 331, 14, 3210, 15, 11486, 15, 67, 432, 13, 6965, 13, 16, 12021, 13, 5129, 1235, 13, 5503, 13, 10500, 13, 26593, 1739, 13, 324, 13, 12486, 13, 4844, 13, 86, 29419, 13, 2064, 13, 17, 15, 1467, 330, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
jiyuren/android_kernel_oneplus_msm8994
tools/perf/scripts/python/net_dropmonitor.py
2669
1738
# Monitor the system for dropped packets and proudce a report of drop locations and counts import os import sys sys.path.append(os.environ['PERF_EXEC_PATH'] + \ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') from perf_trace_context import * from Core import * from Util import * drop_log = {} kallsyms = [] def get_kallsyms_table(): global kallsyms try: f = open("/proc/kallsyms", "r") except: return for line in f: loc = int(line.split()[0], 16) name = line.split()[2] kallsyms.append((loc, name)) kallsyms.sort() def get_sym(sloc): loc = int(sloc) # Invariant: kallsyms[i][0] <= loc for all 0 <= i <= start # kallsyms[i][0] > loc for all end <= i < len(kallsyms) start, end = -1, len(kallsyms) while end != start + 1: pivot = (start + end) // 2 if loc < kallsyms[pivot][0]: end = pivot else: start = pivot # Now (start == -1 or kallsyms[start][0] <= loc) # and (start == len(kallsyms) - 1 or loc < kallsyms[start + 1][0]) if start >= 0: symloc, name = kallsyms[start] return (name, loc - symloc) else: return (None, 0) def print_drop_table(): print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT") for i in drop_log.keys(): (sym, off) = get_sym(i) if sym == None: sym = i print "%25s %25s %25s" % (sym, off, drop_log[i]) def trace_begin(): print "Starting trace (Ctrl-C to dump results)" def trace_end(): print "Gathering kallsyms data" get_kallsyms_table() print_drop_table() # called from perf, when it finds a correspoinding event def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm, skbaddr, location, protocol): slocation = str(location) try: drop_log[slocation] = drop_log[slocation] + 1 except: drop_log[slocation] = 1
gpl-2.0
[ 3, 26504, 314, 2656, 367, 17481, 14593, 436, 557, 1181, 301, 282, 3622, 402, 5978, 9918, 436, 8242, 199, 199, 646, 747, 199, 646, 984, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 2314, 459, 17038, 63, 10276, 63, 3243, 418, 435, 971, 507, 198, 9807, 6429, 15, 1548, 15, 12387, 13, 3921, 13, 9562, 15, 773, 15, 12387, 15, 3921, 358, 199, 199, 504, 8582, 63, 3446, 63, 1100, 492, 627, 199, 504, 11672, 492, 627, 199, 504, 21248, 492, 627, 199, 199, 4824, 63, 793, 275, 1052, 199, 32483, 275, 942, 199, 199, 318, 664, 63, 32483, 63, 1224, 837, 199, 198, 2966, 1022, 452, 13807, 421, 198, 893, 26, 507, 198, 70, 275, 1551, 4769, 4687, 15, 32483, 401, 298, 82, 531, 199, 198, 2590, 26, 507, 198, 1107, 421, 198, 509, 1004, 315, 289, 26, 507, 198, 2102, 275, 1109, 8, 604, 14, 1294, 3430, 16, 467, 3193, 9, 507, 198, 354, 275, 1004, 14, 1294, 3430, 18, 61, 507, 198, 32483, 14, 740, 1332, 2102, 12, 536, 430, 199, 198, 32483, 14, 3191, 342, 199, 199, 318, 664, 63, 3840, 8, 83, 2102, 304, 199, 198, 2102, 275, 1109, 8, 83, 2102, 9, 421, 198, 3, 1010, 8759, 26, 1022, 452, 13807, 59, 73, 1527, 16, 61, 2695, 4355, 367, 1006, 378, 2695, 284, 2695, 1343, 199, 198, 3, 3322, 1022, 452, 13807, 59, 73, 1527, 16, 61, 690, 4355, 367, 1006, 1284, 2695, 284, 665, 822, 8, 32483, 9, 199, 198, 928, 12, 1284, 275, 446, 17, 12, 822, 8, 32483, 9, 199, 198, 6710, 1284, 1137, 1343, 435, 413, 26, 507, 198, 21558, 275, 334, 928, 435, 1284, 9, 5001, 499, 507, 198, 692, 4355, 665, 1022, 452, 13807, 59, 21558, 1527, 16, 2189, 686, 198, 500, 275, 22292, 507, 198, 2836, 26, 686, 198, 928, 275, 22292, 421, 198, 3, 7356, 334, 928, 508, 446, 17, 503, 1022, 452, 13807, 59, 928, 1527, 16, 61, 2695, 4355, 9, 199, 198, 3, 436, 334, 928, 508, 822, 8, 32483, 9, 446, 413, 503, 4355, 665, 1022, 452, 13807, 59, 928, 435, 413, 1527, 16, 566, 199, 198, 692, 1343, 2356, 378, 26, 507, 198, 3840, 2102, 12, 536, 275, 1022, 452, 13807, 59, 928, 61, 507, 198, 1107, 334, 354, 12, 4355, 446, 4678, 2102, 9, 199, 198, 2836, 26, 507, 198, 1107, 334, 403, 12, 378, 9, 199, 199, 318, 870, 63, 4824, 63, 1224, 837, 199, 198, 1361, 2071, 821, 83, 450, 821, 83, 450, 821, 83, 2, 450, 1689, 16575, 401, 298, 14839, 401, 298, 8760, 531, 199, 198, 509, 284, 315, 5978, 63, 793, 14, 1612, 837, 507, 198, 8, 3840, 12, 2331, 9, 275, 664, 63, 3840, 8, 73, 9, 507, 198, 692, 4678, 508, 488, 26, 686, 198, 3840, 275, 284, 507, 198, 1361, 2071, 821, 83, 450, 821, 83, 450, 821, 83, 2, 450, 334, 3840, 12, 2331, 12, 5978, 63, 793, 59, 73, 566, 421, 199, 318, 3307, 63, 5037, 837, 199, 198, 1361, 298, 14139, 3307, 334, 9778, 13, 35, 370, 5461, 2058, 2924, 199, 199, 318, 3307, 63, 500, 837, 199, 198, 1361, 298, 39, 7404, 316, 1022, 452, 13807, 666, 2, 199, 198, 362, 63, 32483, 63, 1224, 342, 199, 198, 1361, 63, 4824, 63, 1224, 342, 199, 199, 3, 2797, 687, 8582, 12, 1380, 652, 17651, 282, 1970, 470, 555, 688, 316, 1566, 199, 318, 11448, 363, 22197, 63, 6852, 8, 354, 12, 1067, 12, 5033, 12, 6513, 12, 14256, 12, 4422, 12, 1923, 12, 686, 257, 23202, 12, 2909, 12, 4113, 304, 199, 198, 83, 1985, 275, 620, 8, 1985, 9, 199, 198, 893, 26, 507, 198, 4824, 63, 793, 59, 83, 1985, 61, 275, 5978, 63, 793, 59, 83, 1985, 61, 435, 413, 199, 198, 2590, 26, 507, 198, 4824, 63, 793, 59, 83, 1985, 61, 275, 413, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 26504, 314, 2656, 367, 17481, 14593, 436, 557, 1181, 301, 282, 3622, 402, 5978, 9918, 436, 8242, 199, 199, 646, 747, 199, 646, 984, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 2314, 459, 17038, 63, 10276, 63, 3243, 418, 435, 971, 507, 198, 9807, 6429, 15, 1548, 15, 12387, 13, 3921, 13, 9562, 15, 773, 15, 12387, 15, 3921, 358, 199, 199, 504, 8582, 63, 3446, 63, 1100, 492, 627, 199, 504, 11672, 492, 627, 199, 504, 21248, 492, 627, 199, 199, 4824, 63, 793, 275, 1052, 199, 32483, 275, 942, 199, 199, 318, 664, 63, 32483, 63, 1224, 837, 199, 198, 2966, 1022, 452, 13807, 421, 198, 893, 26, 507, 198, 70, 275, 1551, 4769, 4687, 15, 32483, 401, 298, 82, 531, 199, 198, 2590, 26, 507, 198, 1107, 421, 198, 509, 1004, 315, 289, 26, 507, 198, 2102, 275, 1109, 8, 604, 14, 1294, 3430, 16, 467, 3193, 9, 507, 198, 354, 275, 1004, 14, 1294, 3430, 18, 61, 507, 198, 32483, 14, 740, 1332, 2102, 12, 536, 430, 199, 198, 32483, 14, 3191, 342, 199, 199, 318, 664, 63, 3840, 8, 83, 2102, 304, 199, 198, 2102, 275, 1109, 8, 83, 2102, 9, 421, 198, 3, 1010, 8759, 26, 1022, 452, 13807, 59, 73, 1527, 16, 61, 2695, 4355, 367, 1006, 378, 2695, 284, 2695, 1343, 199, 198, 3, 3322, 1022, 452, 13807, 59, 73, 1527, 16, 61, 690, 4355, 367, 1006, 1284, 2695, 284, 665, 822, 8, 32483, 9, 199, 198, 928, 12, 1284, 275, 446, 17, 12, 822, 8, 32483, 9, 199, 198, 6710, 1284, 1137, 1343, 435, 413, 26, 507, 198, 21558, 275, 334, 928, 435, 1284, 9, 5001, 499, 507, 198, 692, 4355, 665, 1022, 452, 13807, 59, 21558, 1527, 16, 2189, 686, 198, 500, 275, 22292, 507, 198, 2836, 26, 686, 198, 928, 275, 22292, 421, 198, 3, 7356, 334, 928, 508, 446, 17, 503, 1022, 452, 13807, 59, 928, 1527, 16, 61, 2695, 4355, 9, 199, 198, 3, 436, 334, 928, 508, 822, 8, 32483, 9, 446, 413, 503, 4355, 665, 1022, 452, 13807, 59, 928, 435, 413, 1527, 16, 566, 199, 198, 692, 1343, 2356, 378, 26, 507, 198, 3840, 2102, 12, 536, 275, 1022, 452, 13807, 59, 928, 61, 507, 198, 1107, 334, 354, 12, 4355, 446, 4678, 2102, 9, 199, 198, 2836, 26, 507, 198, 1107, 334, 403, 12, 378, 9, 199, 199, 318, 870, 63, 4824, 63, 1224, 837, 199, 198, 1361, 2071, 821, 83, 450, 821, 83, 450, 821, 83, 2, 450, 1689, 16575, 401, 298, 14839, 401, 298, 8760, 531, 199, 198, 509, 284, 315, 5978, 63, 793, 14, 1612, 837, 507, 198, 8, 3840, 12, 2331, 9, 275, 664, 63, 3840, 8, 73, 9, 507, 198, 692, 4678, 508, 488, 26, 686, 198, 3840, 275, 284, 507, 198, 1361, 2071, 821, 83, 450, 821, 83, 450, 821, 83, 2, 450, 334, 3840, 12, 2331, 12, 5978, 63, 793, 59, 73, 566, 421, 199, 318, 3307, 63, 5037, 837, 199, 198, 1361, 298, 14139, 3307, 334, 9778, 13, 35, 370, 5461, 2058, 2924, 199, 199, 318, 3307, 63, 500, 837, 199, 198, 1361, 298, 39, 7404, 316, 1022, 452, 13807, 666, 2, 199, 198, 362, 63, 32483, 63, 1224, 342, 199, 198, 1361, 63, 4824, 63, 1224, 342, 199, 199, 3, 2797, 687, 8582, 12, 1380, 652, 17651, 282, 1970, 470, 555, 688, 316, 1566, 199, 318, 11448, 363, 22197, 63, 6852, 8, 354, 12, 1067, 12, 5033, 12, 6513, 12, 14256, 12, 4422, 12, 1923, 12, 686, 257, 23202, 12, 2909, 12, 4113, 304, 199, 198, 83, 1985, 275, 620, 8, 1985, 9, 199, 198, 893, 26, 507, 198, 4824, 63, 793, 59, 83, 1985, 61, 275, 5978, 63, 793, 59, 83, 1985, 61, 435, 413, 199, 198, 2590, 26, 507, 198, 4824, 63, 793, 59, 83, 1985, 61, 275, 413, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
sbbic/core
pyuno/qa/pytests/testcollections_XIndexAccess.py
4
9978
#!/usr/bin/env python # # This file is part of the LibreOffice project. # # 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 uno from inspect import isclass from testcollections_base import CollectionsTestBase from com.sun.star.beans import PropertyValue # Tests behaviour of objects implementing XIndexAccess using the new-style # collection accessors # The objects chosen have no special meaning, they just happen to implement the # tested interfaces class TestXIndexAccess(CollectionsTestBase): def insertTestFootnotes(self, doc, count): cursor = doc.Text.createTextCursor() for i in range(count): footnote = doc.createInstance("com.sun.star.text.Footnote") footnote.Label = 'n'+str(i) doc.Text.insertTextContent(cursor, footnote, 0) def readValuesTestFixture(self, doc, count, key, expected): # Given doc.Text.setString('') self.insertTestFootnotes(doc, count) # When captured = None try: actual = doc.Footnotes[key] except Exception as e: captured = e # Then if isclass(expected) and issubclass(expected, Exception): # expected is exception self.assertNotEqual(None, captured) self.assertEqual(expected.__name__, type(captured).__name__) elif type(expected) is tuple: # expected is tuple self.assertEqual(None, captured) self.assertTrue(type(actual) is tuple) self.assertEqual(len(expected), len(actual)) for i in range(len(expected)): self.assertEqual('n'+str(expected[i]), actual[i].Label) else: # expected is value self.assertEqual(None, captured) self.assertTrue(type(actual) is not tuple) self.assertEqual('n'+str(expected), actual.Label) # Tests syntax: # num = len(obj) # Number of elements # For: # length = 0 def test_XIndexAccess_Len_0(self): # Given doc = self.createBlankTextDocument() # When count = len(doc.Footnotes) # Then self.assertEqual(0, count) # Tests syntax: # num = len(obj) # Number of elements # For: # length = 1 def test_XIndexAccess_Len_1(self): # Given doc = self.createBlankTextDocument() cursor = doc.Text.createTextCursor() footnote = doc.createInstance("com.sun.star.text.Footnote") doc.Text.insertTextContent(cursor, footnote, 0) # When count = len(doc.Footnotes) # Then self.assertEqual(1, count) # Tests syntax: # val = obj[0] # Access by index # For: # Single indices def test_XIndexAccess_ReadIndex_Single(self): doc = self.createBlankTextDocument() self.readValuesTestFixture(doc, 0, -1, IndexError) self.readValuesTestFixture(doc, 0, 0, IndexError) self.readValuesTestFixture(doc, 0, 1, IndexError) self.readValuesTestFixture(doc, 1, -3, IndexError) self.readValuesTestFixture(doc, 1, -2, IndexError) self.readValuesTestFixture(doc, 1, -1, 0) self.readValuesTestFixture(doc, 1, 0, 0) self.readValuesTestFixture(doc, 1, 1, IndexError) self.readValuesTestFixture(doc, 1, 2, IndexError) self.readValuesTestFixture(doc, 2, -4, IndexError) self.readValuesTestFixture(doc, 2, -3, IndexError) self.readValuesTestFixture(doc, 2, -2, 0) self.readValuesTestFixture(doc, 2, -1, 1) self.readValuesTestFixture(doc, 2, 0, 0) self.readValuesTestFixture(doc, 2, 1, 1) self.readValuesTestFixture(doc, 2, 2, IndexError) self.readValuesTestFixture(doc, 2, 3, IndexError) def test_XIndexAccess_ReadIndex_Single_Invalid(self): doc = self.createBlankTextDocument() self.readValuesTestFixture(doc, 0, None, TypeError) self.readValuesTestFixture(doc, 0, 'foo', TypeError) self.readValuesTestFixture(doc, 0, 12.34, TypeError) self.readValuesTestFixture(doc, 0, (0,1), TypeError) self.readValuesTestFixture(doc, 0, [0,1], TypeError) self.readValuesTestFixture(doc, 0, {'a': 'b'}, TypeError) # Tests syntax: # val1,val2 = obj[2:4] # Access by slice def test_XIndexAccess_ReadSlice(self): doc = self.createBlankTextDocument() testMax = 4 for i in range(testMax): t = tuple(range(i)) for j in [x for x in range(-testMax-2,testMax+3)] + [None]: for k in [x for x in range(-testMax-2,testMax+3)] + [None]: key = slice(j,k) expected = t[key] self.readValuesTestFixture(doc, i, key, expected) # Tests syntax: # val1,val2 = obj[0:3:2] # Access by extended slice def test_XIndexAccess_ReadExtendedSlice(self): doc = self.createBlankTextDocument() testMax = 4 for i in range(testMax): t = tuple(range(i)) for j in [x for x in range(-testMax-2,testMax+3)] + [None]: for k in [x for x in range(-testMax-2,testMax+3)] + [None]: for l in [-2,-1,2]: key = slice(j,k,l) expected = t[key] self.readValuesTestFixture(doc, i, key, expected) # Tests syntax: # if val in obj: ... # Test value presence # For: # Present element def test_XIndexAccess_In_Present(self): # Given doc = self.createBlankTextDocument() cursor = doc.Text.createTextCursor() footnote = doc.createInstance("com.sun.star.text.Footnote") footnote.setLabel('foo') doc.Text.insertTextContent(cursor, footnote, 0) footnote = doc.Footnotes.getByIndex(0); # When present = footnote in doc.Footnotes # Then self.assertTrue(present) # Tests syntax: # if val in obj: ... # Test value presence # For: # None def test_XIndexAccess_In_None(self): # Given doc = self.createBlankTextDocument() # When present = None in doc.Footnotes # Then self.assertFalse(present) # Tests syntax: # if val in obj: ... # Test value presence # For: # Absent element (string) def test_XIndexAccess_In_String(self): # Given doc = self.createBlankTextDocument() # When / Then present = "foo" in doc.Footnotes # Then self.assertFalse(present) # Tests syntax: # if val in obj: ... # Test value presence # For: # Absent element (dict) def test_XIndexAccess_In_Dict(self): # Given doc = self.createBlankTextDocument() # When / Then with self.assertRaises(TypeError): present = {} in doc.Footnotes # Tests syntax: # for val in obj: ... # Implicit iterator (values) # For: # 0 elements def test_XIndexAccess_ForIn_0(self): # Given doc = self.createBlankTextDocument() # When readFootnotes = [] for f in doc.Footnotes: readFootnotes.append(f) # Then self.assertEqual(0, len(readFootnotes)) # Tests syntax: # for val in obj: ... # Implicit iterator (values) # For: # 1 element def test_XIndexAccess_ForIn_1(self): # Given doc = self.createBlankTextDocument() cursor = doc.Text.createTextCursor() footnote = doc.createInstance("com.sun.star.text.Footnote") footnote.setLabel('foo') doc.Text.insertTextContent(cursor, footnote, 0) # When readFootnotes = [] for f in doc.Footnotes: readFootnotes.append(f) # Then self.assertEqual(1, len(readFootnotes)) self.assertEqual('foo', readFootnotes[0].Label) # Tests syntax: # for val in obj: ... # Implicit iterator (values) # For: # 2 elements def test_XIndexAccess_ForIn_2(self): # Given doc = self.createBlankTextDocument() cursor = doc.Text.createTextCursor() footnote1 = doc.createInstance("com.sun.star.text.Footnote") footnote2 = doc.createInstance("com.sun.star.text.Footnote") footnote1.setLabel('foo') footnote2.setLabel('bar') doc.Text.insertTextContent(cursor, footnote1, 0) doc.Text.insertTextContent(cursor, footnote2, 0) # When readFootnotes = [] for f in doc.Footnotes: readFootnotes.append(f) # Then self.assertEqual(2, len(readFootnotes)) self.assertEqual('foo', readFootnotes[0].Label) self.assertEqual('bar', readFootnotes[1].Label) # Tests syntax: # itr = iter(obj) # Named iterator (values) # For: # 1 element def test_XIndexAccess_Iter_0(self): # Given doc = self.createBlankTextDocument() cursor = doc.Text.createTextCursor() footnote = doc.createInstance("com.sun.star.text.Footnote") footnote.setLabel('foo') doc.Text.insertTextContent(cursor, footnote, 0) # When itr = iter(doc.Footnotes) # Then self.assertIsNotNone(next(itr)) with self.assertRaises(StopIteration): next(itr) if __name__ == '__main__': unittest.main() # vim:set shiftwidth=4 softtabstop=4 expandtab:
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 314, 8003, 264, 31166, 2199, 14, 199, 3, 199, 3, 961, 5800, 5495, 8204, 365, 5420, 370, 314, 2895, 402, 314, 17728, 1684, 199, 3, 844, 12, 373, 14, 499, 14, 16, 14, 982, 282, 1331, 402, 314, 28481, 1990, 440, 1854, 543, 642, 199, 3, 570, 12, 2047, 883, 3332, 1373, 737, 1455, 921, 12102, 14, 1308, 15, 3950, 15, 18, 14, 16, 8083, 199, 3, 199, 199, 646, 2882, 199, 646, 625, 79, 199, 199, 504, 6485, 492, 365, 533, 199, 199, 504, 511, 7882, 63, 1095, 492, 18003, 83, 14440, 199, 504, 2414, 14, 11846, 14, 7848, 14, 1235, 796, 492, 16158, 1110, 421, 199, 3, 6496, 13942, 402, 2251, 18234, 1323, 2681, 3946, 1808, 314, 892, 13, 2487, 199, 3, 3245, 31908, 199, 3, 710, 2251, 12414, 1172, 949, 4539, 11150, 12, 2985, 2951, 5992, 370, 5669, 314, 199, 3, 12470, 8386, 199, 199, 533, 1379, 56, 2681, 3946, 8, 7768, 83, 14440, 304, 339, 347, 5518, 774, 15563, 357, 5983, 8, 277, 12, 1382, 12, 2338, 304, 267, 3920, 275, 1382, 14, 1872, 14, 981, 1872, 8993, 342, 267, 367, 284, 315, 1425, 8, 835, 304, 288, 18913, 4610, 275, 1382, 14, 981, 3244, 480, 957, 14, 11846, 14, 7848, 14, 505, 14, 15563, 357, 4610, 531, 288, 18913, 4610, 14, 4314, 275, 283, 78, 6828, 495, 8, 73, 9, 288, 1382, 14, 1872, 14, 3176, 1872, 2714, 8, 3937, 12, 18913, 4610, 12, 378, 9, 339, 347, 1586, 6550, 774, 12812, 8, 277, 12, 1382, 12, 2338, 12, 790, 12, 1420, 304, 267, 327, 9138, 267, 1382, 14, 1872, 14, 409, 1558, 8355, 267, 291, 14, 3176, 774, 15563, 357, 5983, 8, 1301, 12, 2338, 9, 398, 327, 3979, 267, 17487, 275, 488, 267, 862, 26, 288, 3503, 275, 1382, 14, 15563, 357, 5983, 59, 498, 61, 267, 871, 2186, 465, 325, 26, 288, 17487, 275, 325, 398, 327, 9442, 267, 340, 365, 533, 8, 2062, 9, 436, 11602, 8, 2062, 12, 2186, 304, 288, 327, 1420, 365, 1919, 288, 291, 14, 7418, 8, 403, 12, 17487, 9, 288, 291, 14, 629, 8, 2062, 855, 354, 3108, 730, 8, 28345, 2843, 354, 3368, 267, 916, 730, 8, 2062, 9, 365, 2008, 26, 288, 327, 1420, 365, 2008, 288, 291, 14, 629, 8, 403, 12, 17487, 9, 288, 291, 14, 1815, 8, 466, 8, 6514, 9, 365, 2008, 9, 288, 291, 14, 629, 8, 552, 8, 2062, 395, 822, 8, 6514, 430, 288, 367, 284, 315, 1425, 8, 552, 8, 2062, 2298, 355, 291, 14, 629, 360, 78, 6828, 495, 8, 2062, 59, 73, 2522, 3503, 59, 73, 1055, 4314, 9, 267, 587, 26, 288, 327, 1420, 365, 574, 288, 291, 14, 629, 8, 403, 12, 17487, 9, 288, 291, 14, 1815, 8, 466, 8, 6514, 9, 365, 440, 2008, 9, 288, 291, 14, 629, 360, 78, 6828, 495, 8, 2062, 395, 3503, 14, 4314, 9, 339, 327, 6496, 6302, 26, 272, 327, 259, 1967, 275, 822, 8, 1113, 9, 4519, 327, 4860, 402, 4008, 272, 327, 2104, 26, 272, 327, 259, 2582, 275, 378, 272, 347, 511, 63, 56, 2681, 3946, 63, 3166, 63, 16, 8, 277, 304, 267, 327, 9138, 267, 1382, 275, 291, 14, 981, 28083, 1872, 5564, 342, 398, 327, 3979, 267, 2338, 275, 822, 8, 1301, 14, 15563, 357, 5983, 9, 398, 327, 9442, 267, 291, 14, 629, 8, 16, 12, 2338, 9, 339, 327, 6496, 6302, 26, 272, 327, 259, 1967, 275, 822, 8, 1113, 9, 4519, 327, 4860, 402, 4008, 272, 327, 2104, 26, 272, 327, 259, 2582, 275, 413, 272, 347, 511, 63, 56, 2681, 3946, 63, 3166, 63, 17, 8, 277, 304, 267, 327, 9138, 267, 1382, 275, 291, 14, 981, 28083, 1872, 5564, 342, 267, 3920, 275, 1382, 14, 1872, 14, 981, 1872, 8993, 342, 267, 18913, 4610, 275, 1382, 14, 981, 3244, 480, 957, 14, 11846, 14, 7848, 14, 505, 14, 15563, 357, 4610, 531, 267, 1382, 14, 1872, 14, 3176, 1872, 2714, 8, 3937, 12, 18913, 4610, 12, 378, 9, 398, 327, 3979, 267, 2338, 275, 822, 8, 1301, 14, 15563, 357, 5983, 9, 398, 327, 9442, 267, 291, 14, 629, 8, 17, 12, 2338, 9, 339, 327, 6496, 6302, 26, 272, 327, 259, 1139, 275, 1559, 59, 16, 61, 4483, 327, 11003, 701, 1478, 272, 327, 2104, 26, 272, 327, 259, 13050, 4918, 272, 347, 511, 63, 56, 2681, 3946, 63, 3284, 2681, 63, 7200, 8, 277, 304, 267, 1382, 275, 291, 14, 981, 28083, 1872, 5564, 342, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 378, 12, 446, 17, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 378, 12, 378, 12, 3515, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 378, 12, 413, 12, 3515, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 446, 19, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 446, 18, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 446, 17, 12, 260, 378, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 378, 12, 3515, 378, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 413, 12, 3515, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 499, 12, 3515, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 446, 20, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 446, 19, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 446, 18, 12, 260, 378, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 446, 17, 12, 260, 413, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 378, 12, 3515, 378, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 413, 12, 3515, 413 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 314, 8003, 264, 31166, 2199, 14, 199, 3, 199, 3, 961, 5800, 5495, 8204, 365, 5420, 370, 314, 2895, 402, 314, 17728, 1684, 199, 3, 844, 12, 373, 14, 499, 14, 16, 14, 982, 282, 1331, 402, 314, 28481, 1990, 440, 1854, 543, 642, 199, 3, 570, 12, 2047, 883, 3332, 1373, 737, 1455, 921, 12102, 14, 1308, 15, 3950, 15, 18, 14, 16, 8083, 199, 3, 199, 199, 646, 2882, 199, 646, 625, 79, 199, 199, 504, 6485, 492, 365, 533, 199, 199, 504, 511, 7882, 63, 1095, 492, 18003, 83, 14440, 199, 504, 2414, 14, 11846, 14, 7848, 14, 1235, 796, 492, 16158, 1110, 421, 199, 3, 6496, 13942, 402, 2251, 18234, 1323, 2681, 3946, 1808, 314, 892, 13, 2487, 199, 3, 3245, 31908, 199, 3, 710, 2251, 12414, 1172, 949, 4539, 11150, 12, 2985, 2951, 5992, 370, 5669, 314, 199, 3, 12470, 8386, 199, 199, 533, 1379, 56, 2681, 3946, 8, 7768, 83, 14440, 304, 339, 347, 5518, 774, 15563, 357, 5983, 8, 277, 12, 1382, 12, 2338, 304, 267, 3920, 275, 1382, 14, 1872, 14, 981, 1872, 8993, 342, 267, 367, 284, 315, 1425, 8, 835, 304, 288, 18913, 4610, 275, 1382, 14, 981, 3244, 480, 957, 14, 11846, 14, 7848, 14, 505, 14, 15563, 357, 4610, 531, 288, 18913, 4610, 14, 4314, 275, 283, 78, 6828, 495, 8, 73, 9, 288, 1382, 14, 1872, 14, 3176, 1872, 2714, 8, 3937, 12, 18913, 4610, 12, 378, 9, 339, 347, 1586, 6550, 774, 12812, 8, 277, 12, 1382, 12, 2338, 12, 790, 12, 1420, 304, 267, 327, 9138, 267, 1382, 14, 1872, 14, 409, 1558, 8355, 267, 291, 14, 3176, 774, 15563, 357, 5983, 8, 1301, 12, 2338, 9, 398, 327, 3979, 267, 17487, 275, 488, 267, 862, 26, 288, 3503, 275, 1382, 14, 15563, 357, 5983, 59, 498, 61, 267, 871, 2186, 465, 325, 26, 288, 17487, 275, 325, 398, 327, 9442, 267, 340, 365, 533, 8, 2062, 9, 436, 11602, 8, 2062, 12, 2186, 304, 288, 327, 1420, 365, 1919, 288, 291, 14, 7418, 8, 403, 12, 17487, 9, 288, 291, 14, 629, 8, 2062, 855, 354, 3108, 730, 8, 28345, 2843, 354, 3368, 267, 916, 730, 8, 2062, 9, 365, 2008, 26, 288, 327, 1420, 365, 2008, 288, 291, 14, 629, 8, 403, 12, 17487, 9, 288, 291, 14, 1815, 8, 466, 8, 6514, 9, 365, 2008, 9, 288, 291, 14, 629, 8, 552, 8, 2062, 395, 822, 8, 6514, 430, 288, 367, 284, 315, 1425, 8, 552, 8, 2062, 2298, 355, 291, 14, 629, 360, 78, 6828, 495, 8, 2062, 59, 73, 2522, 3503, 59, 73, 1055, 4314, 9, 267, 587, 26, 288, 327, 1420, 365, 574, 288, 291, 14, 629, 8, 403, 12, 17487, 9, 288, 291, 14, 1815, 8, 466, 8, 6514, 9, 365, 440, 2008, 9, 288, 291, 14, 629, 360, 78, 6828, 495, 8, 2062, 395, 3503, 14, 4314, 9, 339, 327, 6496, 6302, 26, 272, 327, 259, 1967, 275, 822, 8, 1113, 9, 4519, 327, 4860, 402, 4008, 272, 327, 2104, 26, 272, 327, 259, 2582, 275, 378, 272, 347, 511, 63, 56, 2681, 3946, 63, 3166, 63, 16, 8, 277, 304, 267, 327, 9138, 267, 1382, 275, 291, 14, 981, 28083, 1872, 5564, 342, 398, 327, 3979, 267, 2338, 275, 822, 8, 1301, 14, 15563, 357, 5983, 9, 398, 327, 9442, 267, 291, 14, 629, 8, 16, 12, 2338, 9, 339, 327, 6496, 6302, 26, 272, 327, 259, 1967, 275, 822, 8, 1113, 9, 4519, 327, 4860, 402, 4008, 272, 327, 2104, 26, 272, 327, 259, 2582, 275, 413, 272, 347, 511, 63, 56, 2681, 3946, 63, 3166, 63, 17, 8, 277, 304, 267, 327, 9138, 267, 1382, 275, 291, 14, 981, 28083, 1872, 5564, 342, 267, 3920, 275, 1382, 14, 1872, 14, 981, 1872, 8993, 342, 267, 18913, 4610, 275, 1382, 14, 981, 3244, 480, 957, 14, 11846, 14, 7848, 14, 505, 14, 15563, 357, 4610, 531, 267, 1382, 14, 1872, 14, 3176, 1872, 2714, 8, 3937, 12, 18913, 4610, 12, 378, 9, 398, 327, 3979, 267, 2338, 275, 822, 8, 1301, 14, 15563, 357, 5983, 9, 398, 327, 9442, 267, 291, 14, 629, 8, 17, 12, 2338, 9, 339, 327, 6496, 6302, 26, 272, 327, 259, 1139, 275, 1559, 59, 16, 61, 4483, 327, 11003, 701, 1478, 272, 327, 2104, 26, 272, 327, 259, 13050, 4918, 272, 347, 511, 63, 56, 2681, 3946, 63, 3284, 2681, 63, 7200, 8, 277, 304, 267, 1382, 275, 291, 14, 981, 28083, 1872, 5564, 342, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 378, 12, 446, 17, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 378, 12, 378, 12, 3515, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 378, 12, 413, 12, 3515, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 446, 19, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 446, 18, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 446, 17, 12, 260, 378, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 378, 12, 3515, 378, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 413, 12, 3515, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 413, 12, 499, 12, 3515, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 446, 20, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 446, 19, 12, 260, 7888, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 446, 18, 12, 260, 378, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 446, 17, 12, 260, 413, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 378, 12, 3515, 378, 9, 267, 291, 14, 739, 6550, 774, 12812, 8, 1301, 12, 499, 12, 413, 12, 3515, 413, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
noellekimiko/HMC-Grader
TestFiles/CS5GreenTests/hw5tests/sexChromosomeEvolutiontests.py
2
2283
import sexChromosomeEvolution as hw import unittest testScoresD = {('h4', 'c17'): -158, ('h9', 'c22'): 2374, ('h6', 'c22'): -1149, ('h4', 'c8'): -134, ('h4', 'c19'): 1140, ('h17', 'c22'): -1305, ('h7', 'c17'): -614, ('h6', 'c8'): -195, ('h17', 'c17'): -135, ('h6', 'c19'): -195, ('h9', 'c19'): -1115, ('h9', 'c17'): -1248, ('h4', 'c22'): -1126, ('h17', 'c19'): -189, ('h7', 'c8'): -666, ('h7', 'c22'): -573, ('h17', 'c8'): 1343, ('h6', 'c17'): 1043, ('h7', 'c19'): -558, ('h9', 'c8'): -1287} class MemoAlignScoreTest(unittest.TestCase): def testMemoAlign1(self): self.assertEqual(hw.memoAlignScore('','',-9,hw.blosum62,{}), 0) def testMemoAlign2(self): self.assertEqual(hw.memoAlignScore('','FGTSK',-9,hw.blosum62,{}), -45) def testMemoAlign3(self): self.assertEqual(hw.memoAlignScore('IVEKGYY','AVEYY',-9,hw.blosum62,{}), 4) def testMemoAlign4(self): self.assertEqual(hw.memoAlignScore('CIEAFGTSKQKRALNSRRMNAVGNDIVSTAVTKAAADVIDAKGVTALIQDVAQD', 'RDLPIWTSVDWKSLPATEIFNKAFSQGSDEAMYDYMAVYKKSCPQTRR',-9,hw.blosum62,{}), -48) class AllScoresTest(unittest.TestCase): def testAllScores1(self): allScoresD = hw.allScores(["h7","h9"],["c22","c7"]) self.assertEqual(sorted(allScoresD.items()), [(('h7', 'c22'), -573), (('h7', 'c7'), -1179), (('h9', 'c22'), 2374), (('h9', 'c7'), -580)]) def testAllScores2(self): allScoresD = hw.allScores(["h5"],["c1","c3"]) self.assertEqual(sorted(allScoresD.items()), [(('h5', 'c1'), -661), (('h5', 'c3'), -1581)]) def testAllScores3(self): allScoresD = hw.allScores(["h8"],["c2"]) self.assertEqual(sorted(allScoresD.items()), [(('h8', 'c2'), -331)]) def testAllScores4(self): allScoresD = hw.allScores(["h4"],["c2","c7"]) self.assertEqual(sorted(allScoresD.items()), [(('h4', 'c2'), -352), (('h4', 'c7'), -1956)]) class ClosestMatchTest(unittest.TestCase): def testClosestMatch1(self): self.assertEqual(hw.closestMatch('c22',testScoresD), 'h9') def testClosestMatch2(self): self.assertEqual(hw.closestMatch('h6',testScoresD), 'c17') def testClosestMatch3(self): self.assertEqual(hw.closestMatch('c8',testScoresD), 'h17') def testClosestMatch4(self): self.assertEqual(hw.closestMatch('h9',testScoresD), 'c22') if __name__ == '__main__': unittest.main()
mit
[ 646, 542, 88, 1049, 417, 26803, 28104, 3347, 465, 12073, 199, 199, 646, 2882, 199, 199, 396, 29654, 36, 275, 469, 360, 72, 20, 297, 283, 67, 1196, 735, 446, 11240, 12, 661, 72, 25, 297, 283, 67, 1081, 735, 6546, 1342, 12, 661, 72, 22, 297, 283, 67, 1081, 735, 446, 845, 1887, 12, 221, 199, 360, 72, 20, 297, 283, 67, 24, 735, 446, 7582, 12, 661, 72, 20, 297, 283, 67, 1167, 735, 413, 10037, 12, 661, 72, 1196, 297, 283, 67, 1081, 735, 446, 969, 1717, 12, 221, 199, 360, 72, 23, 297, 283, 67, 1196, 735, 446, 32392, 12, 661, 72, 22, 297, 283, 67, 24, 735, 446, 11874, 12, 661, 72, 1196, 297, 283, 67, 1196, 735, 446, 8312, 12, 221, 199, 360, 72, 22, 297, 283, 67, 1167, 735, 446, 11874, 12, 661, 72, 25, 297, 283, 67, 1167, 735, 446, 845, 1046, 12, 661, 72, 25, 297, 283, 67, 1196, 735, 446, 713, 2006, 12, 221, 199, 360, 72, 20, 297, 283, 67, 1081, 735, 446, 6094, 22, 12, 661, 72, 1196, 297, 283, 67, 1167, 735, 446, 11370, 12, 661, 72, 23, 297, 283, 67, 24, 735, 446, 11829, 12, 221, 199, 360, 72, 23, 297, 283, 67, 1081, 735, 446, 17037, 12, 661, 72, 1196, 297, 283, 67, 24, 735, 413, 14761, 12, 661, 72, 22, 297, 283, 67, 1196, 735, 413, 5882, 12, 221, 199, 360, 72, 23, 297, 283, 67, 1167, 735, 446, 17686, 12, 661, 72, 25, 297, 283, 67, 24, 735, 446, 713, 1555, 93, 199, 199, 533, 3194, 573, 9497, 12642, 774, 8, 2796, 14, 1746, 304, 523, 347, 511, 1352, 573, 9497, 17, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 11979, 9497, 12642, 360, 1673, 297, 13, 25, 12, 8090, 14, 25913, 1838, 2789, 12, 2440, 395, 378, 9, 523, 347, 511, 1352, 573, 9497, 18, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 11979, 9497, 12642, 360, 1673, 38, 8391, 8656, 297, 13, 25, 12, 8090, 14, 25913, 1838, 2789, 12, 2440, 395, 446, 2322, 9, 523, 347, 511, 1352, 573, 9497, 19, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 11979, 9497, 12642, 360, 5399, 14634, 7080, 1673, 26907, 7080, 297, 13, 25, 12, 8090, 14, 25913, 1838, 2789, 12, 2440, 395, 841, 9, 523, 347, 511, 1352, 573, 9497, 20, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 11979, 9497, 12642, 360, 3553, 37, 5699, 8391, 8656, 49, 23063, 748, 2709, 50, 11026, 46, 6087, 15306, 27051, 840, 6087, 15263, 2276, 1554, 5437, 7872, 39, 8156, 748, 23559, 6741, 20152, 36, 297, 283, 50, 8045, 2252, 21283, 4985, 19438, 43, 4929, 48, 1951, 4656, 22780, 5699, 18445, 8021, 1093, 1156, 57, 11446, 19273, 57, 43, 19982, 31243, 1766, 50, 297, 13, 25, 12, 8090, 14, 25913, 1838, 2789, 12, 2440, 395, 446, 2006, 9, 199, 199, 533, 2900, 29654, 774, 8, 2796, 14, 1746, 304, 523, 347, 511, 2422, 29654, 17, 8, 277, 304, 272, 1006, 29654, 36, 275, 12073, 14, 452, 29654, 5234, 72, 23, 2266, 72, 25, 30549, 67, 1081, 2266, 67, 23, 3135, 272, 291, 14, 629, 8, 5917, 8, 452, 29654, 36, 14, 1744, 4000, 3842, 360, 72, 23, 297, 283, 67, 1081, 659, 446, 17037, 395, 13636, 72, 23, 297, 283, 67, 23, 659, 446, 845, 1965, 395, 13636, 72, 25, 297, 283, 67, 1081, 659, 6546, 1342, 395, 13636, 72, 25, 297, 283, 67, 23, 659, 446, 21, 1257, 3948, 523, 347, 511, 2422, 29654, 18, 8, 277, 304, 272, 1006, 29654, 36, 275, 12073, 14, 452, 29654, 5234, 72, 21, 30549, 67, 17, 2266, 67, 19, 3135, 272, 291, 14, 629, 8, 5917, 8, 452, 29654, 36, 14, 1744, 4000, 3842, 360, 72, 21, 297, 283, 67, 17, 659, 446, 19528, 395, 13636, 72, 21, 297, 283, 67, 19, 659, 446, 1046, 2835, 3948, 523, 347, 511, 2422, 29654, 19, 8, 277, 304, 272, 1006, 29654, 36, 275, 12073, 14, 452, 29654, 5234, 72, 24, 30549, 67, 18, 3135, 272, 291, 14, 629, 8, 5917, 8, 452, 29654, 36, 14, 1744, 4000, 3842, 360, 72, 24, 297, 283, 67, 18, 659, 446, 15638, 3948, 523, 347, 511, 2422, 29654, 20, 8, 277, 304, 272, 1006, 29654, 36, 275, 12073, 14, 452, 29654, 5234, 72, 20, 30549, 67, 18, 2266, 67, 23, 3135, 272, 291, 14, 629, 8, 5917, 8, 452, 29654, 36, 14, 1744, 4000, 3842, 360, 72, 20, 297, 283, 67, 18, 659, 446, 15139, 395, 13636, 72, 20, 297, 283, 67, 23, 659, 446, 1167, 1367, 3948, 199, 199, 533, 15524, 270, 4486, 774, 8, 2796, 14, 1746, 304, 523, 347, 511, 4724, 270, 4486, 17, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 22061, 4486, 360, 67, 1081, 297, 396, 29654, 36, 395, 283, 72, 25, 358, 523, 347, 511, 4724, 270, 4486, 18, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 22061, 4486, 360, 72, 22, 297, 396, 29654, 36, 395, 283, 67, 1196, 358, 523, 347, 511, 4724, 270, 4486, 19, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 22061, 4486, 360, 67, 24, 297, 396, 29654, 36, 395, 283, 72, 1196, 358, 523, 347, 511, 4724, 270, 4486, 20, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 22061, 4486, 360, 72, 25, 297, 396, 29654, 36, 395, 283, 67, 1081, 358, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2882, 14, 973, 342, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 542, 88, 1049, 417, 26803, 28104, 3347, 465, 12073, 199, 199, 646, 2882, 199, 199, 396, 29654, 36, 275, 469, 360, 72, 20, 297, 283, 67, 1196, 735, 446, 11240, 12, 661, 72, 25, 297, 283, 67, 1081, 735, 6546, 1342, 12, 661, 72, 22, 297, 283, 67, 1081, 735, 446, 845, 1887, 12, 221, 199, 360, 72, 20, 297, 283, 67, 24, 735, 446, 7582, 12, 661, 72, 20, 297, 283, 67, 1167, 735, 413, 10037, 12, 661, 72, 1196, 297, 283, 67, 1081, 735, 446, 969, 1717, 12, 221, 199, 360, 72, 23, 297, 283, 67, 1196, 735, 446, 32392, 12, 661, 72, 22, 297, 283, 67, 24, 735, 446, 11874, 12, 661, 72, 1196, 297, 283, 67, 1196, 735, 446, 8312, 12, 221, 199, 360, 72, 22, 297, 283, 67, 1167, 735, 446, 11874, 12, 661, 72, 25, 297, 283, 67, 1167, 735, 446, 845, 1046, 12, 661, 72, 25, 297, 283, 67, 1196, 735, 446, 713, 2006, 12, 221, 199, 360, 72, 20, 297, 283, 67, 1081, 735, 446, 6094, 22, 12, 661, 72, 1196, 297, 283, 67, 1167, 735, 446, 11370, 12, 661, 72, 23, 297, 283, 67, 24, 735, 446, 11829, 12, 221, 199, 360, 72, 23, 297, 283, 67, 1081, 735, 446, 17037, 12, 661, 72, 1196, 297, 283, 67, 24, 735, 413, 14761, 12, 661, 72, 22, 297, 283, 67, 1196, 735, 413, 5882, 12, 221, 199, 360, 72, 23, 297, 283, 67, 1167, 735, 446, 17686, 12, 661, 72, 25, 297, 283, 67, 24, 735, 446, 713, 1555, 93, 199, 199, 533, 3194, 573, 9497, 12642, 774, 8, 2796, 14, 1746, 304, 523, 347, 511, 1352, 573, 9497, 17, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 11979, 9497, 12642, 360, 1673, 297, 13, 25, 12, 8090, 14, 25913, 1838, 2789, 12, 2440, 395, 378, 9, 523, 347, 511, 1352, 573, 9497, 18, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 11979, 9497, 12642, 360, 1673, 38, 8391, 8656, 297, 13, 25, 12, 8090, 14, 25913, 1838, 2789, 12, 2440, 395, 446, 2322, 9, 523, 347, 511, 1352, 573, 9497, 19, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 11979, 9497, 12642, 360, 5399, 14634, 7080, 1673, 26907, 7080, 297, 13, 25, 12, 8090, 14, 25913, 1838, 2789, 12, 2440, 395, 841, 9, 523, 347, 511, 1352, 573, 9497, 20, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 11979, 9497, 12642, 360, 3553, 37, 5699, 8391, 8656, 49, 23063, 748, 2709, 50, 11026, 46, 6087, 15306, 27051, 840, 6087, 15263, 2276, 1554, 5437, 7872, 39, 8156, 748, 23559, 6741, 20152, 36, 297, 283, 50, 8045, 2252, 21283, 4985, 19438, 43, 4929, 48, 1951, 4656, 22780, 5699, 18445, 8021, 1093, 1156, 57, 11446, 19273, 57, 43, 19982, 31243, 1766, 50, 297, 13, 25, 12, 8090, 14, 25913, 1838, 2789, 12, 2440, 395, 446, 2006, 9, 199, 199, 533, 2900, 29654, 774, 8, 2796, 14, 1746, 304, 523, 347, 511, 2422, 29654, 17, 8, 277, 304, 272, 1006, 29654, 36, 275, 12073, 14, 452, 29654, 5234, 72, 23, 2266, 72, 25, 30549, 67, 1081, 2266, 67, 23, 3135, 272, 291, 14, 629, 8, 5917, 8, 452, 29654, 36, 14, 1744, 4000, 3842, 360, 72, 23, 297, 283, 67, 1081, 659, 446, 17037, 395, 13636, 72, 23, 297, 283, 67, 23, 659, 446, 845, 1965, 395, 13636, 72, 25, 297, 283, 67, 1081, 659, 6546, 1342, 395, 13636, 72, 25, 297, 283, 67, 23, 659, 446, 21, 1257, 3948, 523, 347, 511, 2422, 29654, 18, 8, 277, 304, 272, 1006, 29654, 36, 275, 12073, 14, 452, 29654, 5234, 72, 21, 30549, 67, 17, 2266, 67, 19, 3135, 272, 291, 14, 629, 8, 5917, 8, 452, 29654, 36, 14, 1744, 4000, 3842, 360, 72, 21, 297, 283, 67, 17, 659, 446, 19528, 395, 13636, 72, 21, 297, 283, 67, 19, 659, 446, 1046, 2835, 3948, 523, 347, 511, 2422, 29654, 19, 8, 277, 304, 272, 1006, 29654, 36, 275, 12073, 14, 452, 29654, 5234, 72, 24, 30549, 67, 18, 3135, 272, 291, 14, 629, 8, 5917, 8, 452, 29654, 36, 14, 1744, 4000, 3842, 360, 72, 24, 297, 283, 67, 18, 659, 446, 15638, 3948, 523, 347, 511, 2422, 29654, 20, 8, 277, 304, 272, 1006, 29654, 36, 275, 12073, 14, 452, 29654, 5234, 72, 20, 30549, 67, 18, 2266, 67, 23, 3135, 272, 291, 14, 629, 8, 5917, 8, 452, 29654, 36, 14, 1744, 4000, 3842, 360, 72, 20, 297, 283, 67, 18, 659, 446, 15139, 395, 13636, 72, 20, 297, 283, 67, 23, 659, 446, 1167, 1367, 3948, 199, 199, 533, 15524, 270, 4486, 774, 8, 2796, 14, 1746, 304, 523, 347, 511, 4724, 270, 4486, 17, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 22061, 4486, 360, 67, 1081, 297, 396, 29654, 36, 395, 283, 72, 25, 358, 523, 347, 511, 4724, 270, 4486, 18, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 22061, 4486, 360, 72, 22, 297, 396, 29654, 36, 395, 283, 67, 1196, 358, 523, 347, 511, 4724, 270, 4486, 19, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 22061, 4486, 360, 67, 24, 297, 396, 29654, 36, 395, 283, 72, 1196, 358, 523, 347, 511, 4724, 270, 4486, 20, 8, 277, 304, 272, 291, 14, 629, 8, 8090, 14, 22061, 4486, 360, 72, 25, 297, 396, 29654, 36, 395, 283, 67, 1081, 358, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2882, 14, 973, 342, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
alexallah/django
django/forms/formsets.py
15
17870
from django.core.exceptions import ValidationError from django.forms import Form from django.forms.fields import BooleanField, IntegerField from django.forms.utils import ErrorList from django.forms.widgets import HiddenInput from django.utils.functional import cached_property from django.utils.html import html_safe from django.utils.safestring import mark_safe from django.utils.translation import gettext as _, ngettext __all__ = ('BaseFormSet', 'formset_factory', 'all_valid') # special field names TOTAL_FORM_COUNT = 'TOTAL_FORMS' INITIAL_FORM_COUNT = 'INITIAL_FORMS' MIN_NUM_FORM_COUNT = 'MIN_NUM_FORMS' MAX_NUM_FORM_COUNT = 'MAX_NUM_FORMS' ORDERING_FIELD_NAME = 'ORDER' DELETION_FIELD_NAME = 'DELETE' # default minimum number of forms in a formset DEFAULT_MIN_NUM = 0 # default maximum number of forms in a formset, to prevent memory exhaustion DEFAULT_MAX_NUM = 1000 class ManagementForm(Form): """ Keep track of how many form instances are displayed on the page. If adding new forms via JavaScript, you should increment the count field of this form as well. """ def __init__(self, *args, **kwargs): self.base_fields[TOTAL_FORM_COUNT] = IntegerField(widget=HiddenInput) self.base_fields[INITIAL_FORM_COUNT] = IntegerField(widget=HiddenInput) # MIN_NUM_FORM_COUNT and MAX_NUM_FORM_COUNT are output with the rest of # the management form, but only for the convenience of client-side # code. The POST value of them returned from the client is not checked. self.base_fields[MIN_NUM_FORM_COUNT] = IntegerField(required=False, widget=HiddenInput) self.base_fields[MAX_NUM_FORM_COUNT] = IntegerField(required=False, widget=HiddenInput) super().__init__(*args, **kwargs) @html_safe class BaseFormSet: """ A collection of instances of the same Form class. """ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, form_kwargs=None): self.is_bound = data is not None or files is not None self.prefix = prefix or self.get_default_prefix() self.auto_id = auto_id self.data = data or {} self.files = files or {} self.initial = initial self.form_kwargs = form_kwargs or {} self.error_class = error_class self._errors = None self._non_form_errors = None def __str__(self): return self.as_table() def __iter__(self): """Yield the forms in the order they should be rendered.""" return iter(self.forms) def __getitem__(self, index): """Return the form at the given index, based on the rendering order.""" return self.forms[index] def __len__(self): return len(self.forms) def __bool__(self): """ Return True since all formsets have a management form which is not included in the length. """ return True @cached_property def management_form(self): """Return the ManagementForm instance for this FormSet.""" if self.is_bound: form = ManagementForm(self.data, auto_id=self.auto_id, prefix=self.prefix) if not form.is_valid(): raise ValidationError( _('ManagementForm data is missing or has been tampered with'), code='missing_management_form', ) else: form = ManagementForm(auto_id=self.auto_id, prefix=self.prefix, initial={ TOTAL_FORM_COUNT: self.total_form_count(), INITIAL_FORM_COUNT: self.initial_form_count(), MIN_NUM_FORM_COUNT: self.min_num, MAX_NUM_FORM_COUNT: self.max_num }) return form def total_form_count(self): """Return the total number of forms in this FormSet.""" if self.is_bound: # return absolute_max if it is lower than the actual total form # count in the data; this is DoS protection to prevent clients # from forcing the server to instantiate arbitrary numbers of # forms return min(self.management_form.cleaned_data[TOTAL_FORM_COUNT], self.absolute_max) else: initial_forms = self.initial_form_count() total_forms = max(initial_forms, self.min_num) + self.extra # Allow all existing related objects/inlines to be displayed, # but don't allow extra beyond max_num. if initial_forms > self.max_num >= 0: total_forms = initial_forms elif total_forms > self.max_num >= 0: total_forms = self.max_num return total_forms def initial_form_count(self): """Return the number of forms that are required in this FormSet.""" if self.is_bound: return self.management_form.cleaned_data[INITIAL_FORM_COUNT] else: # Use the length of the initial data if it's there, 0 otherwise. initial_forms = len(self.initial) if self.initial else 0 return initial_forms @cached_property def forms(self): """Instantiate forms at first property access.""" # DoS protection is included in total_form_count() forms = [self._construct_form(i, **self.get_form_kwargs(i)) for i in range(self.total_form_count())] return forms def get_form_kwargs(self, index): """ Return additional keyword arguments for each individual formset form. index will be None if the form being constructed is a new empty form. """ return self.form_kwargs.copy() def _construct_form(self, i, **kwargs): """Instantiate and return the i-th form instance in a formset.""" defaults = { 'auto_id': self.auto_id, 'prefix': self.add_prefix(i), 'error_class': self.error_class, # Don't render the HTML 'required' attribute as it may cause # incorrect validation for extra, optional, and deleted # forms in the formset. 'use_required_attribute': False, } if self.is_bound: defaults['data'] = self.data defaults['files'] = self.files if self.initial and 'initial' not in kwargs: try: defaults['initial'] = self.initial[i] except IndexError: pass # Allow extra forms to be empty, unless they're part of # the minimum forms. if i >= self.initial_form_count() and i >= self.min_num: defaults['empty_permitted'] = True defaults.update(kwargs) form = self.form(**defaults) self.add_fields(form, i) return form @property def initial_forms(self): """Return a list of all the initial forms in this formset.""" return self.forms[:self.initial_form_count()] @property def extra_forms(self): """Return a list of all the extra forms in this formset.""" return self.forms[self.initial_form_count():] @property def empty_form(self): form = self.form( auto_id=self.auto_id, prefix=self.add_prefix('__prefix__'), empty_permitted=True, use_required_attribute=False, **self.get_form_kwargs(None) ) self.add_fields(form, None) return form @property def cleaned_data(self): """ Return a list of form.cleaned_data dicts for every form in self.forms. """ if not self.is_valid(): raise AttributeError("'%s' object has no attribute 'cleaned_data'" % self.__class__.__name__) return [form.cleaned_data for form in self.forms] @property def deleted_forms(self): """Return a list of forms that have been marked for deletion.""" if not self.is_valid() or not self.can_delete: return [] # construct _deleted_form_indexes which is just a list of form indexes # that have had their deletion widget set to True if not hasattr(self, '_deleted_form_indexes'): self._deleted_form_indexes = [] for i in range(0, self.total_form_count()): form = self.forms[i] # if this is an extra form and hasn't changed, don't consider it if i >= self.initial_form_count() and not form.has_changed(): continue if self._should_delete_form(form): self._deleted_form_indexes.append(i) return [self.forms[i] for i in self._deleted_form_indexes] @property def ordered_forms(self): """ Return a list of form in the order specified by the incoming data. Raise an AttributeError if ordering is not allowed. """ if not self.is_valid() or not self.can_order: raise AttributeError("'%s' object has no attribute 'ordered_forms'" % self.__class__.__name__) # Construct _ordering, which is a list of (form_index, order_field_value) # tuples. After constructing this list, we'll sort it by order_field_value # so we have a way to get to the form indexes in the order specified # by the form data. if not hasattr(self, '_ordering'): self._ordering = [] for i in range(0, self.total_form_count()): form = self.forms[i] # if this is an extra form and hasn't changed, don't consider it if i >= self.initial_form_count() and not form.has_changed(): continue # don't add data marked for deletion to self.ordered_data if self.can_delete and self._should_delete_form(form): continue self._ordering.append((i, form.cleaned_data[ORDERING_FIELD_NAME])) # After we're done populating self._ordering, sort it. # A sort function to order things numerically ascending, but # None should be sorted below anything else. Allowing None as # a comparison value makes it so we can leave ordering fields # blank. def compare_ordering_key(k): if k[1] is None: return (1, 0) # +infinity, larger than any number return (0, k[1]) self._ordering.sort(key=compare_ordering_key) # Return a list of form.cleaned_data dicts in the order specified by # the form data. return [self.forms[i[0]] for i in self._ordering] @classmethod def get_default_prefix(cls): return 'form' def non_form_errors(self): """ Return an ErrorList of errors that aren't associated with a particular form -- i.e., from formset.clean(). Return an empty ErrorList if there are none. """ if self._non_form_errors is None: self.full_clean() return self._non_form_errors @property def errors(self): """Return a list of form.errors for every form in self.forms.""" if self._errors is None: self.full_clean() return self._errors def total_error_count(self): """Return the number of errors across all forms in the formset.""" return len(self.non_form_errors()) +\ sum(len(form_errors) for form_errors in self.errors) def _should_delete_form(self, form): """Return whether or not the form was marked for deletion.""" return form.cleaned_data.get(DELETION_FIELD_NAME, False) def is_valid(self): """Return True if every form in self.forms is valid.""" if not self.is_bound: return False # We loop over every form.errors here rather than short circuiting on the # first failure to make sure validation gets triggered for every form. forms_valid = True # This triggers a full clean. self.errors for i in range(0, self.total_form_count()): form = self.forms[i] if self.can_delete: if self._should_delete_form(form): # This form is going to be deleted so any of its errors # should not cause the entire formset to be invalid. continue forms_valid &= form.is_valid() return forms_valid and not self.non_form_errors() def full_clean(self): """ Clean all of self.data and populate self._errors and self._non_form_errors. """ self._errors = [] self._non_form_errors = self.error_class() empty_forms_count = 0 if not self.is_bound: # Stop further processing. return for i in range(0, self.total_form_count()): form = self.forms[i] if not form.has_changed(): empty_forms_count += 1 self._errors.append(form.errors) try: if (self.validate_max and self.total_form_count() - len(self.deleted_forms) > self.max_num) or \ self.management_form.cleaned_data[TOTAL_FORM_COUNT] > self.absolute_max: raise ValidationError(ngettext( "Please submit %d or fewer forms.", "Please submit %d or fewer forms.", self.max_num) % self.max_num, code='too_many_forms', ) if (self.validate_min and self.total_form_count() - len(self.deleted_forms) - empty_forms_count < self.min_num): raise ValidationError(ngettext( "Please submit %d or more forms.", "Please submit %d or more forms.", self.min_num) % self.min_num, code='too_few_forms') # Give self.clean() a chance to do cross-form validation. self.clean() except ValidationError as e: self._non_form_errors = self.error_class(e.error_list) def clean(self): """ Hook for doing any extra formset-wide cleaning after Form.clean() has been called on every form. Any ValidationError raised by this method will not be associated with a particular form; it will be accessible via formset.non_form_errors() """ pass def has_changed(self): """Return True if data in any form differs from initial.""" return any(form.has_changed() for form in self) def add_fields(self, form, index): """A hook for adding extra fields on to each form instance.""" if self.can_order: # Only pre-fill the ordering field for initial forms. if index is not None and index < self.initial_form_count(): form.fields[ORDERING_FIELD_NAME] = IntegerField(label=_('Order'), initial=index + 1, required=False) else: form.fields[ORDERING_FIELD_NAME] = IntegerField(label=_('Order'), required=False) if self.can_delete: form.fields[DELETION_FIELD_NAME] = BooleanField(label=_('Delete'), required=False) def add_prefix(self, index): return '%s-%s' % (self.prefix, index) def is_multipart(self): """ Return True if the formset needs to be multipart, i.e. it has FileInput, or False otherwise. """ if self.forms: return self.forms[0].is_multipart() else: return self.empty_form.is_multipart() @property def media(self): # All the forms on a FormSet are the same, so you only need to # interrogate the first form for media. if self.forms: return self.forms[0].media else: return self.empty_form.media def as_table(self): "Return this formset rendered as HTML <tr>s -- excluding the <table></table>." # XXX: there is no semantic division between forms here, there # probably should be. It might make sense to render each form as a # table row with each field as a td. forms = ' '.join(form.as_table() for form in self) return mark_safe('\n'.join([str(self.management_form), forms])) def as_p(self): "Return this formset rendered as HTML <p>s." forms = ' '.join(form.as_p() for form in self) return mark_safe('\n'.join([str(self.management_form), forms])) def as_ul(self): "Return this formset rendered as HTML <li>s." forms = ' '.join(form.as_ul() for form in self) return mark_safe('\n'.join([str(self.management_form), forms])) def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, can_delete=False, max_num=None, validate_max=False, min_num=None, validate_min=False): """Return a FormSet for the given form class.""" if min_num is None: min_num = DEFAULT_MIN_NUM if max_num is None: max_num = DEFAULT_MAX_NUM # hard limit on forms instantiated, to prevent memory-exhaustion attacks # limit is simply max_num + DEFAULT_MAX_NUM (which is 2*DEFAULT_MAX_NUM # if max_num is None in the first place) absolute_max = max_num + DEFAULT_MAX_NUM attrs = {'form': form, 'extra': extra, 'can_order': can_order, 'can_delete': can_delete, 'min_num': min_num, 'max_num': max_num, 'absolute_max': absolute_max, 'validate_min': validate_min, 'validate_max': validate_max} return type(form.__name__ + 'FormSet', (formset,), attrs) def all_valid(formsets): """Return True if every formset in formsets is valid.""" valid = True for formset in formsets: if not formset.is_valid(): valid = False return valid
bsd-3-clause
[ 504, 1639, 14, 1018, 14, 3924, 492, 8505, 199, 504, 1639, 14, 3351, 492, 8204, 199, 504, 1639, 14, 3351, 14, 955, 492, 9411, 792, 12, 26141, 199, 504, 1639, 14, 3351, 14, 1208, 492, 4520, 1296, 199, 504, 1639, 14, 3351, 14, 8583, 492, 26401, 3205, 199, 504, 1639, 14, 1208, 14, 15481, 492, 6328, 63, 1829, 199, 504, 1639, 14, 1208, 14, 1360, 492, 3517, 63, 3489, 199, 504, 1639, 14, 1208, 14, 28389, 492, 2216, 63, 3489, 199, 504, 1639, 14, 1208, 14, 6893, 492, 9796, 465, 5501, 29793, 199, 199, 363, 452, 363, 275, 661, 1563, 14736, 297, 283, 10724, 63, 3702, 297, 283, 452, 63, 1078, 358, 199, 199, 3, 4539, 901, 1561, 199, 15386, 63, 3516, 63, 8760, 275, 283, 15386, 63, 11518, 7, 199, 13768, 63, 3516, 63, 8760, 275, 283, 13768, 63, 11518, 7, 199, 4896, 63, 7125, 63, 3516, 63, 8760, 275, 283, 4896, 63, 7125, 63, 11518, 7, 199, 4283, 63, 7125, 63, 3516, 63, 8760, 275, 283, 4283, 63, 7125, 63, 11518, 7, 199, 12125, 1206, 63, 8609, 63, 2339, 275, 283, 12125, 7, 199, 4424, 31133, 63, 8609, 63, 2339, 275, 283, 7014, 7, 199, 199, 3, 849, 7481, 1329, 402, 4513, 315, 282, 11068, 199, 3472, 63, 4896, 63, 7125, 275, 378, 199, 199, 3, 849, 5696, 1329, 402, 4513, 315, 282, 11068, 12, 370, 7981, 4402, 21354, 833, 1636, 199, 3472, 63, 4283, 63, 7125, 275, 5198, 421, 199, 533, 8259, 2821, 8, 2821, 304, 272, 408, 272, 14797, 4426, 402, 4212, 5002, 1824, 4454, 787, 9080, 641, 314, 2034, 14, 982, 7791, 272, 892, 4513, 4799, 15250, 12, 1265, 1077, 11609, 314, 2338, 901, 402, 642, 1824, 272, 465, 5521, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 1095, 63, 955, 59, 15386, 63, 3516, 63, 8760, 61, 275, 26141, 8, 3440, 29, 25419, 9, 267, 291, 14, 1095, 63, 955, 59, 13768, 63, 3516, 63, 8760, 61, 275, 26141, 8, 3440, 29, 25419, 9, 267, 327, 15861, 63, 7125, 63, 3516, 63, 8760, 436, 9141, 63, 7125, 63, 3516, 63, 8760, 787, 1072, 543, 314, 4618, 402, 267, 327, 314, 10041, 1824, 12, 1325, 1454, 367, 314, 16777, 402, 1890, 13, 2441, 267, 327, 1233, 14, 710, 8761, 574, 402, 3062, 2138, 687, 314, 1890, 365, 440, 7923, 14, 267, 291, 14, 1095, 63, 955, 59, 4896, 63, 7125, 63, 3516, 63, 8760, 61, 275, 26141, 8, 2427, 29, 797, 12, 3938, 29, 25419, 9, 267, 291, 14, 1095, 63, 955, 59, 4283, 63, 7125, 63, 3516, 63, 8760, 61, 275, 26141, 8, 2427, 29, 797, 12, 3938, 29, 25419, 9, 267, 1613, 11027, 826, 9308, 589, 12, 1011, 958, 9, 421, 199, 32, 1360, 63, 3489, 199, 533, 3523, 14736, 26, 272, 408, 272, 437, 3245, 402, 4454, 402, 314, 2011, 8204, 1021, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 666, 29, 403, 12, 1584, 29, 403, 12, 2599, 63, 344, 534, 344, 4970, 83, 297, 2403, 29, 403, 12, 326, 2536, 29, 403, 12, 1125, 63, 533, 29, 547, 1296, 12, 1824, 63, 958, 29, 403, 304, 267, 291, 14, 374, 63, 3556, 275, 666, 365, 440, 488, 503, 1584, 365, 440, 488, 267, 291, 14, 1861, 275, 2403, 503, 291, 14, 362, 63, 885, 63, 1861, 342, 267, 291, 14, 2495, 63, 344, 275, 2599, 63, 344, 267, 291, 14, 576, 275, 666, 503, 1052, 267, 291, 14, 1725, 275, 1584, 503, 1052, 267, 291, 14, 2747, 275, 2536, 267, 291, 14, 964, 63, 958, 275, 1824, 63, 958, 503, 1052, 267, 291, 14, 705, 63, 533, 275, 1125, 63, 533, 267, 291, 423, 2550, 275, 488, 267, 291, 423, 2865, 63, 964, 63, 2550, 275, 488, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 305, 63, 1224, 342, 339, 347, 636, 1661, 721, 277, 304, 267, 408, 22889, 314, 4513, 315, 314, 1865, 2985, 1077, 506, 8018, 1041, 267, 372, 2740, 8, 277, 14, 3351, 9, 339, 347, 636, 6095, 721, 277, 12, 1478, 304, 267, 408, 1767, 314, 1824, 737, 314, 1627, 1478, 12, 4079, 641, 314, 14066, 1865, 1041, 267, 372, 291, 14, 3351, 59, 1080, 61, 339, 347, 636, 552, 721, 277, 304, 267, 372, 822, 8, 277, 14, 3351, 9, 339, 347, 636, 2245, 721, 277, 304, 267, 408, 267, 1432, 715, 3967, 1006, 1824, 2193, 1172, 282, 10041, 1824, 1314, 365, 440, 267, 5120, 315, 314, 2582, 14, 267, 408, 267, 372, 715, 339, 768, 5245, 63, 1829, 272, 347, 10041, 63, 964, 8, 277, 304, 267, 408, 1767, 314, 8259, 2821, 1256, 367, 642, 25260, 1041, 267, 340, 291, 14, 374, 63, 3556, 26, 288, 1824, 275, 8259, 2821, 8, 277, 14, 576, 12, 2599, 63, 344, 29, 277, 14, 2495, 63, 344, 12, 2403, 29, 277, 14, 1861, 9, 288, 340, 440, 1824, 14, 374, 63, 1078, 837, 355, 746, 8505, 8, 490, 4018, 14552, 2821, 666, 365, 4124, 503, 965, 2757, 3052, 311, 16179, 543, 659, 490, 1233, 534, 4752, 63, 8110, 63, 964, 297, 355, 776, 267, 587, 26, 288, 1824, 275, 8259, 2821, 8, 2495, 63, 344, 29, 277, 14, 2495, 63, 344, 12, 2403, 29, 277, 14, 1861, 12, 2536, 3126, 355, 377, 1387, 748, 63, 3516, 63, 8760, 26, 291, 14, 2923, 63, 964, 63, 835, 1062, 355, 26105, 63, 3516, 63, 8760, 26, 291, 14, 2747, 63, 964, 63, 835, 1062, 355, 15861, 63, 7125, 63, 3516, 63, 8760, 26, 291, 14, 827, 63, 1507, 12, 355, 9141, 63, 7125, 63, 3516, 63, 8760, 26, 291, 14, 988, 63, 1507, 288, 3828, 267, 372, 1824, 339, 347, 3141, 63, 964, 63, 835, 8, 277, 304, 267, 408, 1767, 314, 3141, 1329, 402, 4513, 315, 642, 25260, 1041, 267, 340, 291, 14, 374, 63, 3556, 26, 288, 327, 372, 3679, 63, 988, 340, 652, 365, 5117, 2419, 314, 3503, 3141, 1824, 288, 327, 2338, 315, 314, 666, 27, 642, 365, 4226, 51, 23977, 370, 7981, 13431, 288, 327, 687, 31070, 314, 1654, 370, 17321, 9697, 5579, 402, 288, 327, 4513, 288, 372, 1748, 8, 277 ]
[ 1639, 14, 1018, 14, 3924, 492, 8505, 199, 504, 1639, 14, 3351, 492, 8204, 199, 504, 1639, 14, 3351, 14, 955, 492, 9411, 792, 12, 26141, 199, 504, 1639, 14, 3351, 14, 1208, 492, 4520, 1296, 199, 504, 1639, 14, 3351, 14, 8583, 492, 26401, 3205, 199, 504, 1639, 14, 1208, 14, 15481, 492, 6328, 63, 1829, 199, 504, 1639, 14, 1208, 14, 1360, 492, 3517, 63, 3489, 199, 504, 1639, 14, 1208, 14, 28389, 492, 2216, 63, 3489, 199, 504, 1639, 14, 1208, 14, 6893, 492, 9796, 465, 5501, 29793, 199, 199, 363, 452, 363, 275, 661, 1563, 14736, 297, 283, 10724, 63, 3702, 297, 283, 452, 63, 1078, 358, 199, 199, 3, 4539, 901, 1561, 199, 15386, 63, 3516, 63, 8760, 275, 283, 15386, 63, 11518, 7, 199, 13768, 63, 3516, 63, 8760, 275, 283, 13768, 63, 11518, 7, 199, 4896, 63, 7125, 63, 3516, 63, 8760, 275, 283, 4896, 63, 7125, 63, 11518, 7, 199, 4283, 63, 7125, 63, 3516, 63, 8760, 275, 283, 4283, 63, 7125, 63, 11518, 7, 199, 12125, 1206, 63, 8609, 63, 2339, 275, 283, 12125, 7, 199, 4424, 31133, 63, 8609, 63, 2339, 275, 283, 7014, 7, 199, 199, 3, 849, 7481, 1329, 402, 4513, 315, 282, 11068, 199, 3472, 63, 4896, 63, 7125, 275, 378, 199, 199, 3, 849, 5696, 1329, 402, 4513, 315, 282, 11068, 12, 370, 7981, 4402, 21354, 833, 1636, 199, 3472, 63, 4283, 63, 7125, 275, 5198, 421, 199, 533, 8259, 2821, 8, 2821, 304, 272, 408, 272, 14797, 4426, 402, 4212, 5002, 1824, 4454, 787, 9080, 641, 314, 2034, 14, 982, 7791, 272, 892, 4513, 4799, 15250, 12, 1265, 1077, 11609, 314, 2338, 901, 402, 642, 1824, 272, 465, 5521, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 1095, 63, 955, 59, 15386, 63, 3516, 63, 8760, 61, 275, 26141, 8, 3440, 29, 25419, 9, 267, 291, 14, 1095, 63, 955, 59, 13768, 63, 3516, 63, 8760, 61, 275, 26141, 8, 3440, 29, 25419, 9, 267, 327, 15861, 63, 7125, 63, 3516, 63, 8760, 436, 9141, 63, 7125, 63, 3516, 63, 8760, 787, 1072, 543, 314, 4618, 402, 267, 327, 314, 10041, 1824, 12, 1325, 1454, 367, 314, 16777, 402, 1890, 13, 2441, 267, 327, 1233, 14, 710, 8761, 574, 402, 3062, 2138, 687, 314, 1890, 365, 440, 7923, 14, 267, 291, 14, 1095, 63, 955, 59, 4896, 63, 7125, 63, 3516, 63, 8760, 61, 275, 26141, 8, 2427, 29, 797, 12, 3938, 29, 25419, 9, 267, 291, 14, 1095, 63, 955, 59, 4283, 63, 7125, 63, 3516, 63, 8760, 61, 275, 26141, 8, 2427, 29, 797, 12, 3938, 29, 25419, 9, 267, 1613, 11027, 826, 9308, 589, 12, 1011, 958, 9, 421, 199, 32, 1360, 63, 3489, 199, 533, 3523, 14736, 26, 272, 408, 272, 437, 3245, 402, 4454, 402, 314, 2011, 8204, 1021, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 666, 29, 403, 12, 1584, 29, 403, 12, 2599, 63, 344, 534, 344, 4970, 83, 297, 2403, 29, 403, 12, 326, 2536, 29, 403, 12, 1125, 63, 533, 29, 547, 1296, 12, 1824, 63, 958, 29, 403, 304, 267, 291, 14, 374, 63, 3556, 275, 666, 365, 440, 488, 503, 1584, 365, 440, 488, 267, 291, 14, 1861, 275, 2403, 503, 291, 14, 362, 63, 885, 63, 1861, 342, 267, 291, 14, 2495, 63, 344, 275, 2599, 63, 344, 267, 291, 14, 576, 275, 666, 503, 1052, 267, 291, 14, 1725, 275, 1584, 503, 1052, 267, 291, 14, 2747, 275, 2536, 267, 291, 14, 964, 63, 958, 275, 1824, 63, 958, 503, 1052, 267, 291, 14, 705, 63, 533, 275, 1125, 63, 533, 267, 291, 423, 2550, 275, 488, 267, 291, 423, 2865, 63, 964, 63, 2550, 275, 488, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 305, 63, 1224, 342, 339, 347, 636, 1661, 721, 277, 304, 267, 408, 22889, 314, 4513, 315, 314, 1865, 2985, 1077, 506, 8018, 1041, 267, 372, 2740, 8, 277, 14, 3351, 9, 339, 347, 636, 6095, 721, 277, 12, 1478, 304, 267, 408, 1767, 314, 1824, 737, 314, 1627, 1478, 12, 4079, 641, 314, 14066, 1865, 1041, 267, 372, 291, 14, 3351, 59, 1080, 61, 339, 347, 636, 552, 721, 277, 304, 267, 372, 822, 8, 277, 14, 3351, 9, 339, 347, 636, 2245, 721, 277, 304, 267, 408, 267, 1432, 715, 3967, 1006, 1824, 2193, 1172, 282, 10041, 1824, 1314, 365, 440, 267, 5120, 315, 314, 2582, 14, 267, 408, 267, 372, 715, 339, 768, 5245, 63, 1829, 272, 347, 10041, 63, 964, 8, 277, 304, 267, 408, 1767, 314, 8259, 2821, 1256, 367, 642, 25260, 1041, 267, 340, 291, 14, 374, 63, 3556, 26, 288, 1824, 275, 8259, 2821, 8, 277, 14, 576, 12, 2599, 63, 344, 29, 277, 14, 2495, 63, 344, 12, 2403, 29, 277, 14, 1861, 9, 288, 340, 440, 1824, 14, 374, 63, 1078, 837, 355, 746, 8505, 8, 490, 4018, 14552, 2821, 666, 365, 4124, 503, 965, 2757, 3052, 311, 16179, 543, 659, 490, 1233, 534, 4752, 63, 8110, 63, 964, 297, 355, 776, 267, 587, 26, 288, 1824, 275, 8259, 2821, 8, 2495, 63, 344, 29, 277, 14, 2495, 63, 344, 12, 2403, 29, 277, 14, 1861, 12, 2536, 3126, 355, 377, 1387, 748, 63, 3516, 63, 8760, 26, 291, 14, 2923, 63, 964, 63, 835, 1062, 355, 26105, 63, 3516, 63, 8760, 26, 291, 14, 2747, 63, 964, 63, 835, 1062, 355, 15861, 63, 7125, 63, 3516, 63, 8760, 26, 291, 14, 827, 63, 1507, 12, 355, 9141, 63, 7125, 63, 3516, 63, 8760, 26, 291, 14, 988, 63, 1507, 288, 3828, 267, 372, 1824, 339, 347, 3141, 63, 964, 63, 835, 8, 277, 304, 267, 408, 1767, 314, 3141, 1329, 402, 4513, 315, 642, 25260, 1041, 267, 340, 291, 14, 374, 63, 3556, 26, 288, 327, 372, 3679, 63, 988, 340, 652, 365, 5117, 2419, 314, 3503, 3141, 1824, 288, 327, 2338, 315, 314, 666, 27, 642, 365, 4226, 51, 23977, 370, 7981, 13431, 288, 327, 687, 31070, 314, 1654, 370, 17321, 9697, 5579, 402, 288, 327, 4513, 288, 372, 1748, 8, 277, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
charbull/GeminiTest
reader.py
1
1669
#!/usr/bin/env python3 import asyncio import json import datetime import websockets @asyncio.coroutine async def market_data(): """Returns the latest market data""" timestampms = [] async with websockets.connect('wss://api.gemini.com/v1/marketdata/ethusd') as websocket: var_eth_usd_price = await websocket.recv() if var_eth_usd_price: data = json.loads(var_eth_usd_price) if 'timestampms' in data: timestampms = data["timestampms"] events_array = data["events"] if events_array: var_last_item = events_array[len(events_array)-1] var_type = var_last_item["type"] var_reason = var_last_item["reason"] var_price = var_last_item["price"] var_delta = var_last_item["delta"] var_remaining = var_last_item["remaining"] var_side = var_last_item["side"] print("====> Lastest Transaction:\n"+ "-- Type: "+str(var_type)+"\n"+ "-- Reason: "+str(var_reason)+"\n"+ "-- Price: "+str(var_price)+"\n"+ "-- Delta: "+str(var_delta)+"\n"+ "-- Remaining: "+str(var_remaining)+"\n"+ "-- Side: "+str(var_side)+"\n"+ "-- Trader Retrieval Time "+str(datetime.datetime.now())) if timestampms: print("-- Gemini Time "+str(timestampms)) else: print("Something went wrong while reading the marketdata") asyncio.get_event_loop().run_until_complete(market_data())
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 646, 16195, 199, 646, 2022, 199, 646, 2197, 199, 646, 24897, 83, 421, 199, 32, 19343, 14, 16675, 199, 4146, 347, 26584, 63, 576, 837, 272, 408, 3407, 314, 8839, 26584, 666, 624, 272, 4913, 706, 275, 942, 272, 5316, 543, 24897, 83, 14, 2242, 360, 87, 385, 921, 1246, 14, 303, 18000, 14, 957, 15, 86, 17, 15, 22270, 576, 15, 12391, 31597, 358, 465, 24897, 26, 267, 2729, 63, 12391, 63, 31597, 63, 4777, 275, 5517, 24897, 14, 7637, 342, 267, 340, 2729, 63, 12391, 63, 31597, 63, 4777, 26, 288, 666, 275, 2022, 14, 3640, 8, 1391, 63, 12391, 63, 31597, 63, 4777, 9, 288, 340, 283, 3954, 706, 7, 315, 666, 26, 355, 4913, 706, 275, 666, 905, 3954, 706, 937, 953, 4474, 63, 1144, 275, 666, 905, 4368, 937, 288, 340, 4474, 63, 1144, 26, 355, 2729, 63, 2019, 63, 1053, 275, 4474, 63, 1144, 59, 552, 8, 4368, 63, 1144, 7216, 17, 61, 355, 2729, 63, 466, 275, 2729, 63, 2019, 63, 1053, 905, 466, 937, 355, 2729, 63, 5764, 275, 2729, 63, 2019, 63, 1053, 905, 5764, 937, 355, 2729, 63, 4777, 275, 2729, 63, 2019, 63, 1053, 905, 4777, 937, 355, 2729, 63, 3136, 275, 2729, 63, 2019, 63, 1053, 905, 3136, 937, 355, 2729, 63, 11266, 275, 2729, 63, 2019, 63, 1053, 905, 11266, 937, 355, 2729, 63, 2441, 275, 2729, 63, 2019, 63, 1053, 905, 2441, 937, 355, 870, 480, 532, 30, 491, 32645, 18244, 3427, 78, 7709, 1993, 4320, 2434, 26, 7210, 495, 8, 1391, 63, 466, 6393, 3212, 78, 7709, 1993, 4320, 799, 2660, 26, 7210, 495, 8, 1391, 63, 5764, 6393, 3212, 78, 7709, 1993, 4320, 20276, 26, 7210, 495, 8, 1391, 63, 4777, 6393, 3212, 78, 7709, 1993, 4320, 18464, 502, 26, 7210, 495, 8, 1391, 63, 3136, 6393, 3212, 78, 7709, 1993, 4320, 799, 26630, 26, 7210, 495, 8, 1391, 63, 11266, 6393, 3212, 78, 7709, 1993, 4320, 428, 2655, 26, 7210, 495, 8, 1391, 63, 2441, 6393, 3212, 78, 7709, 1993, 4320, 12643, 424, 8747, 322, 2579, 4703, 7210, 495, 8, 2083, 14, 2083, 14, 2131, 4059, 355, 340, 4913, 706, 26, 490, 870, 6739, 5346, 18000, 4703, 7210, 495, 8, 3954, 706, 430, 267, 587, 26, 288, 870, 480, 20641, 22396, 6835, 1830, 7664, 314, 26584, 576, 531, 421, 199, 19343, 14, 362, 63, 1430, 63, 3813, 1252, 1065, 63, 8111, 63, 4883, 8, 22270, 63, 576, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 199, 646, 16195, 199, 646, 2022, 199, 646, 2197, 199, 646, 24897, 83, 421, 199, 32, 19343, 14, 16675, 199, 4146, 347, 26584, 63, 576, 837, 272, 408, 3407, 314, 8839, 26584, 666, 624, 272, 4913, 706, 275, 942, 272, 5316, 543, 24897, 83, 14, 2242, 360, 87, 385, 921, 1246, 14, 303, 18000, 14, 957, 15, 86, 17, 15, 22270, 576, 15, 12391, 31597, 358, 465, 24897, 26, 267, 2729, 63, 12391, 63, 31597, 63, 4777, 275, 5517, 24897, 14, 7637, 342, 267, 340, 2729, 63, 12391, 63, 31597, 63, 4777, 26, 288, 666, 275, 2022, 14, 3640, 8, 1391, 63, 12391, 63, 31597, 63, 4777, 9, 288, 340, 283, 3954, 706, 7, 315, 666, 26, 355, 4913, 706, 275, 666, 905, 3954, 706, 937, 953, 4474, 63, 1144, 275, 666, 905, 4368, 937, 288, 340, 4474, 63, 1144, 26, 355, 2729, 63, 2019, 63, 1053, 275, 4474, 63, 1144, 59, 552, 8, 4368, 63, 1144, 7216, 17, 61, 355, 2729, 63, 466, 275, 2729, 63, 2019, 63, 1053, 905, 466, 937, 355, 2729, 63, 5764, 275, 2729, 63, 2019, 63, 1053, 905, 5764, 937, 355, 2729, 63, 4777, 275, 2729, 63, 2019, 63, 1053, 905, 4777, 937, 355, 2729, 63, 3136, 275, 2729, 63, 2019, 63, 1053, 905, 3136, 937, 355, 2729, 63, 11266, 275, 2729, 63, 2019, 63, 1053, 905, 11266, 937, 355, 2729, 63, 2441, 275, 2729, 63, 2019, 63, 1053, 905, 2441, 937, 355, 870, 480, 532, 30, 491, 32645, 18244, 3427, 78, 7709, 1993, 4320, 2434, 26, 7210, 495, 8, 1391, 63, 466, 6393, 3212, 78, 7709, 1993, 4320, 799, 2660, 26, 7210, 495, 8, 1391, 63, 5764, 6393, 3212, 78, 7709, 1993, 4320, 20276, 26, 7210, 495, 8, 1391, 63, 4777, 6393, 3212, 78, 7709, 1993, 4320, 18464, 502, 26, 7210, 495, 8, 1391, 63, 3136, 6393, 3212, 78, 7709, 1993, 4320, 799, 26630, 26, 7210, 495, 8, 1391, 63, 11266, 6393, 3212, 78, 7709, 1993, 4320, 428, 2655, 26, 7210, 495, 8, 1391, 63, 2441, 6393, 3212, 78, 7709, 1993, 4320, 12643, 424, 8747, 322, 2579, 4703, 7210, 495, 8, 2083, 14, 2083, 14, 2131, 4059, 355, 340, 4913, 706, 26, 490, 870, 6739, 5346, 18000, 4703, 7210, 495, 8, 3954, 706, 430, 267, 587, 26, 288, 870, 480, 20641, 22396, 6835, 1830, 7664, 314, 26584, 576, 531, 421, 199, 19343, 14, 362, 63, 1430, 63, 3813, 1252, 1065, 63, 8111, 63, 4883, 8, 22270, 63, 576, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
cm12-g600/chil360-kernel
scripts/rt-tester/rt-tester.py
11005
5307
#!/usr/bin/python # # rt-mutex tester # # (C) 2006 Thomas Gleixner <tglx@linutronix.de> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # import os import sys import getopt import shutil import string # Globals quiet = 0 test = 0 comments = 0 sysfsprefix = "/sys/devices/system/rttest/rttest" statusfile = "/status" commandfile = "/command" # Command opcodes cmd_opcodes = { "schedother" : "1", "schedfifo" : "2", "lock" : "3", "locknowait" : "4", "lockint" : "5", "lockintnowait" : "6", "lockcont" : "7", "unlock" : "8", "signal" : "11", "resetevent" : "98", "reset" : "99", } test_opcodes = { "prioeq" : ["P" , "eq" , None], "priolt" : ["P" , "lt" , None], "priogt" : ["P" , "gt" , None], "nprioeq" : ["N" , "eq" , None], "npriolt" : ["N" , "lt" , None], "npriogt" : ["N" , "gt" , None], "unlocked" : ["M" , "eq" , 0], "trylock" : ["M" , "eq" , 1], "blocked" : ["M" , "eq" , 2], "blockedwake" : ["M" , "eq" , 3], "locked" : ["M" , "eq" , 4], "opcodeeq" : ["O" , "eq" , None], "opcodelt" : ["O" , "lt" , None], "opcodegt" : ["O" , "gt" , None], "eventeq" : ["E" , "eq" , None], "eventlt" : ["E" , "lt" , None], "eventgt" : ["E" , "gt" , None], } # Print usage information def usage(): print "rt-tester.py <-c -h -q -t> <testfile>" print " -c display comments after first command" print " -h help" print " -q quiet mode" print " -t test mode (syntax check)" print " testfile: read test specification from testfile" print " otherwise from stdin" return # Print progress when not in quiet mode def progress(str): if not quiet: print str # Analyse a status value def analyse(val, top, arg): intval = int(val) if top[0] == "M": intval = intval / (10 ** int(arg)) intval = intval % 10 argval = top[2] elif top[0] == "O": argval = int(cmd_opcodes.get(arg, arg)) else: argval = int(arg) # progress("%d %s %d" %(intval, top[1], argval)) if top[1] == "eq" and intval == argval: return 1 if top[1] == "lt" and intval < argval: return 1 if top[1] == "gt" and intval > argval: return 1 return 0 # Parse the commandline try: (options, arguments) = getopt.getopt(sys.argv[1:],'chqt') except getopt.GetoptError, ex: usage() sys.exit(1) # Parse commandline options for option, value in options: if option == "-c": comments = 1 elif option == "-q": quiet = 1 elif option == "-t": test = 1 elif option == '-h': usage() sys.exit(0) # Select the input source if arguments: try: fd = open(arguments[0]) except Exception,ex: sys.stderr.write("File not found %s\n" %(arguments[0])) sys.exit(1) else: fd = sys.stdin linenr = 0 # Read the test patterns while 1: linenr = linenr + 1 line = fd.readline() if not len(line): break line = line.strip() parts = line.split(":") if not parts or len(parts) < 1: continue if len(parts[0]) == 0: continue if parts[0].startswith("#"): if comments > 1: progress(line) continue if comments == 1: comments = 2 progress(line) cmd = parts[0].strip().lower() opc = parts[1].strip().lower() tid = parts[2].strip() dat = parts[3].strip() try: # Test or wait for a status value if cmd == "t" or cmd == "w": testop = test_opcodes[opc] fname = "%s%s%s" %(sysfsprefix, tid, statusfile) if test: print fname continue while 1: query = 1 fsta = open(fname, 'r') status = fsta.readline().strip() fsta.close() stat = status.split(",") for s in stat: s = s.strip() if s.startswith(testop[0]): # Separate status value val = s[2:].strip() query = analyse(val, testop, dat) break if query or cmd == "t": break progress(" " + status) if not query: sys.stderr.write("Test failed in line %d\n" %(linenr)) sys.exit(1) # Issue a command to the tester elif cmd == "c": cmdnr = cmd_opcodes[opc] # Build command string and sys filename cmdstr = "%s:%s" %(cmdnr, dat) fname = "%s%s%s" %(sysfsprefix, tid, commandfile) if test: print fname continue fcmd = open(fname, 'w') fcmd.write(cmdstr) fcmd.close() except Exception,ex: sys.stderr.write(str(ex)) sys.stderr.write("\nSyntax error in line %d\n" %(linenr)) if not test: fd.close() sys.exit(1) # Normal exit pass print "Pass" sys.exit(0)
gpl-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 14059, 13, 19078, 17570, 199, 3, 199, 3, 334, 35, 9, 8315, 27864, 598, 274, 1148, 1372, 665, 84, 18660, 32, 472, 5373, 1148, 14, 271, 30, 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, 1015, 499, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 14, 199, 3, 199, 646, 747, 199, 646, 984, 199, 646, 12733, 199, 646, 5145, 199, 646, 1059, 199, 199, 3, 13641, 83, 199, 10243, 275, 378, 199, 396, 275, 378, 199, 6223, 275, 378, 199, 199, 1274, 2319, 1861, 275, 3286, 1274, 15, 6410, 15, 2253, 15, 2591, 396, 15, 2591, 396, 2, 199, 1205, 493, 275, 3286, 1205, 2, 199, 1531, 493, 275, 3286, 1531, 2, 199, 199, 3, 5817, 27388, 199, 1760, 63, 22022, 275, 469, 272, 298, 10487, 1848, 2, 259, 520, 298, 17, 401, 272, 298, 10487, 22976, 2, 258, 520, 298, 18, 401, 272, 298, 831, 2, 3515, 520, 298, 19, 401, 272, 298, 831, 20870, 2, 259, 520, 298, 20, 401, 272, 298, 831, 442, 2, 755, 520, 298, 21, 401, 272, 298, 831, 442, 20870, 2, 520, 298, 22, 401, 272, 298, 831, 11096, 2, 420, 520, 298, 23, 401, 272, 298, 17966, 2, 263, 520, 298, 24, 401, 272, 298, 4653, 2, 263, 520, 298, 845, 401, 272, 298, 264, 30563, 782, 2, 259, 520, 298, 2905, 401, 272, 298, 3958, 2, 260, 520, 298, 1020, 401, 272, 789, 199, 199, 396, 63, 22022, 275, 469, 272, 298, 20572, 4077, 2, 263, 520, 2097, 48, 2, 2360, 298, 4077, 2, 2360, 488, 467, 272, 298, 1359, 28934, 2, 263, 520, 2097, 48, 2, 2360, 298, 4116, 2, 2360, 488, 467, 272, 298, 1359, 974, 84, 2, 263, 520, 2097, 48, 2, 2360, 298, 3308, 2, 2360, 488, 467, 272, 298, 78, 20572, 4077, 2, 755, 520, 2097, 46, 2, 2360, 298, 4077, 2, 2360, 488, 467, 272, 298, 78, 1359, 28934, 2, 755, 520, 2097, 46, 2, 2360, 298, 4116, 2, 2360, 488, 467, 272, 298, 78, 1359, 974, 84, 2, 755, 520, 2097, 46, 2, 2360, 298, 3308, 2, 2360, 488, 467, 272, 298, 32489, 2, 420, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 378, 467, 272, 298, 893, 831, 2, 755, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 413, 467, 272, 298, 17726, 2, 755, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 499, 467, 272, 298, 17726, 15181, 2, 257, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 650, 467, 272, 298, 9325, 2, 263, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 841, 467, 272, 298, 14325, 4077, 2, 420, 520, 2097, 47, 2, 2360, 298, 4077, 2, 2360, 488, 467, 272, 298, 14325, 4116, 2, 420, 520, 2097, 47, 2, 2360, 298, 4116, 2, 2360, 488, 467, 272, 298, 14325, 3308, 2, 420, 520, 2097, 47, 2, 2360, 298, 3308, 2, 2360, 488, 467, 272, 298, 12056, 266, 81, 2, 755, 520, 2097, 37, 2, 2360, 298, 4077, 2, 2360, 488, 467, 272, 298, 1430, 4116, 2, 755, 520, 2097, 37, 2, 2360, 298, 4116, 2, 2360, 488, 467, 272, 298, 1430, 3308, 2, 755, 520, 2097, 37, 2, 2360, 298, 3308, 2, 2360, 488, 467, 272, 789, 199, 199, 3, 9101, 4503, 2556, 199, 318, 4503, 837, 272, 870, 298, 2591, 13, 8234, 14, 647, 25549, 67, 446, 72, 446, 81, 446, 84, 30, 665, 21091, 4335, 272, 870, 298, 446, 67, 259, 2929, 6786, 2410, 1642, 1414, 2, 272, 870, 298, 446, 72, 259, 1720, 2, 272, 870, 298, 446, 81, 259, 11971, 818, 2, 272, 870, 298, 446, 84, 259, 511, 818, 334, 7093, 1104, 2924, 272, 870, 298, 30530, 26, 1586, 511, 8929, 687, 30530, 2, 272, 870, 298, 4257, 687, 9009, 2, 272, 372, 199, 199, 3, 9101, 6696, 1380, 440, 315, 11971, 818, 199, 318, 6696, 8, 495, 304, 272, 340, 440, 11971, 26, 267, 870, 620, 199, 199, 3, 14279, 261, 282, 2004, 574, 199, 318, 21297, 8, 637, 12, 2746, 12, 1680, 304, 339, 26111, 275, 1109, 8, 637, 9, 339, 340, 2746, 59, 16, 61, 508, 298, 45, 582, 267, 26111, 275, 26111, 1182, 334, 709, 1011, 1109, 8, 1273, 430, 199, 198, 442, 637, 275, 26111, 450, 1616, 267, 27610, 275, 2746, 59, 18, 61, 272, 916, 2746, 59, 16, 61, 508, 298, 47, 582, 267, 27610, 275, 1109, 8, 1760, 63, 22022, 14, 362, 8, 1273, 12, 1680, 430, 272, 587, 26, 267, 27610, 275, 1109, 8, 1273, 9, 339, 327, 6696, 3647, 68, 450, 83, 450, 68, 2, 2818, 442, 637, 12, 2746, 59, 17, 467, 27610, 430, 339, 340, 2746, 59, 17, 61, 508, 298, 4077, 2, 436, 26111, 508, 27610, 26, 199, 198, 1107, 413, 272, 340, 2746, 59, 17, 61, 508, 298, 4116, 2, 436, 26111, 665, 27610, 26, 267, 372, 413, 272, 340, 2746, 59, 17, 61, 508, 298, 3308, 2, 436, 26111, 690, 27610, 26, 199, 198, 1107, 413, 272, 372, 378, 199, 199, 3, 6077, 314, 28279, 199, 893, 26, 272, 334, 1419, 12, 2368, 9, 275, 12733, 14, 18907, 8, 1274, 14, 3020, 59, 17, 8429, 7, 335, 8440, 358, 199, 2590, 12733, 14, 1002, 29368, 12, 444, 26, 272, 4503, 342, 272, 984, 14, 2224, 8, 17, 9, 199, 199, 3, 6077, 28279, 1511, 199, 509, 945, 12, 574, 315, 1511, 26, 272, 340, 945, 508, 3905, 67, 582, 267, 6786, 275, 413, 272, 916, 945, 508, 3905, 81, 582, 267, 11971, 275, 413, 272, 916, 945, 508, 3905, 84, 582, 267, 511, 275, 413, 272, 916, 945, 508, 2475, 72, 356, 267, 4503, 342, 267, 984, 14, 2224, 8, 16, 9, 199, 199, 3, 9496, 314, 1324, 1350, 199, 692, 2368, 26, 272, 862, 26, 267, 6111, 275, 1551, 8, 4958, 59, 16, 566, 272, 871, 2186, 12, 476, 26, 267, 984, 14, 3083, 14, 952, 480, 1173, 440, 1911, 450, 83, 60, 78, 2, 2818, 4958, 59, 16, 2459, 267, 984, 14, 2224 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 14059, 13, 19078, 17570, 199, 3, 199, 3, 334, 35, 9, 8315, 27864, 598, 274, 1148, 1372, 665, 84, 18660, 32, 472, 5373, 1148, 14, 271, 30, 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, 1015, 499, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 14, 199, 3, 199, 646, 747, 199, 646, 984, 199, 646, 12733, 199, 646, 5145, 199, 646, 1059, 199, 199, 3, 13641, 83, 199, 10243, 275, 378, 199, 396, 275, 378, 199, 6223, 275, 378, 199, 199, 1274, 2319, 1861, 275, 3286, 1274, 15, 6410, 15, 2253, 15, 2591, 396, 15, 2591, 396, 2, 199, 1205, 493, 275, 3286, 1205, 2, 199, 1531, 493, 275, 3286, 1531, 2, 199, 199, 3, 5817, 27388, 199, 1760, 63, 22022, 275, 469, 272, 298, 10487, 1848, 2, 259, 520, 298, 17, 401, 272, 298, 10487, 22976, 2, 258, 520, 298, 18, 401, 272, 298, 831, 2, 3515, 520, 298, 19, 401, 272, 298, 831, 20870, 2, 259, 520, 298, 20, 401, 272, 298, 831, 442, 2, 755, 520, 298, 21, 401, 272, 298, 831, 442, 20870, 2, 520, 298, 22, 401, 272, 298, 831, 11096, 2, 420, 520, 298, 23, 401, 272, 298, 17966, 2, 263, 520, 298, 24, 401, 272, 298, 4653, 2, 263, 520, 298, 845, 401, 272, 298, 264, 30563, 782, 2, 259, 520, 298, 2905, 401, 272, 298, 3958, 2, 260, 520, 298, 1020, 401, 272, 789, 199, 199, 396, 63, 22022, 275, 469, 272, 298, 20572, 4077, 2, 263, 520, 2097, 48, 2, 2360, 298, 4077, 2, 2360, 488, 467, 272, 298, 1359, 28934, 2, 263, 520, 2097, 48, 2, 2360, 298, 4116, 2, 2360, 488, 467, 272, 298, 1359, 974, 84, 2, 263, 520, 2097, 48, 2, 2360, 298, 3308, 2, 2360, 488, 467, 272, 298, 78, 20572, 4077, 2, 755, 520, 2097, 46, 2, 2360, 298, 4077, 2, 2360, 488, 467, 272, 298, 78, 1359, 28934, 2, 755, 520, 2097, 46, 2, 2360, 298, 4116, 2, 2360, 488, 467, 272, 298, 78, 1359, 974, 84, 2, 755, 520, 2097, 46, 2, 2360, 298, 3308, 2, 2360, 488, 467, 272, 298, 32489, 2, 420, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 378, 467, 272, 298, 893, 831, 2, 755, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 413, 467, 272, 298, 17726, 2, 755, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 499, 467, 272, 298, 17726, 15181, 2, 257, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 650, 467, 272, 298, 9325, 2, 263, 520, 2097, 45, 2, 2360, 298, 4077, 2, 2360, 841, 467, 272, 298, 14325, 4077, 2, 420, 520, 2097, 47, 2, 2360, 298, 4077, 2, 2360, 488, 467, 272, 298, 14325, 4116, 2, 420, 520, 2097, 47, 2, 2360, 298, 4116, 2, 2360, 488, 467, 272, 298, 14325, 3308, 2, 420, 520, 2097, 47, 2, 2360, 298, 3308, 2, 2360, 488, 467, 272, 298, 12056, 266, 81, 2, 755, 520, 2097, 37, 2, 2360, 298, 4077, 2, 2360, 488, 467, 272, 298, 1430, 4116, 2, 755, 520, 2097, 37, 2, 2360, 298, 4116, 2, 2360, 488, 467, 272, 298, 1430, 3308, 2, 755, 520, 2097, 37, 2, 2360, 298, 3308, 2, 2360, 488, 467, 272, 789, 199, 199, 3, 9101, 4503, 2556, 199, 318, 4503, 837, 272, 870, 298, 2591, 13, 8234, 14, 647, 25549, 67, 446, 72, 446, 81, 446, 84, 30, 665, 21091, 4335, 272, 870, 298, 446, 67, 259, 2929, 6786, 2410, 1642, 1414, 2, 272, 870, 298, 446, 72, 259, 1720, 2, 272, 870, 298, 446, 81, 259, 11971, 818, 2, 272, 870, 298, 446, 84, 259, 511, 818, 334, 7093, 1104, 2924, 272, 870, 298, 30530, 26, 1586, 511, 8929, 687, 30530, 2, 272, 870, 298, 4257, 687, 9009, 2, 272, 372, 199, 199, 3, 9101, 6696, 1380, 440, 315, 11971, 818, 199, 318, 6696, 8, 495, 304, 272, 340, 440, 11971, 26, 267, 870, 620, 199, 199, 3, 14279, 261, 282, 2004, 574, 199, 318, 21297, 8, 637, 12, 2746, 12, 1680, 304, 339, 26111, 275, 1109, 8, 637, 9, 339, 340, 2746, 59, 16, 61, 508, 298, 45, 582, 267, 26111, 275, 26111, 1182, 334, 709, 1011, 1109, 8, 1273, 430, 199, 198, 442, 637, 275, 26111, 450, 1616, 267, 27610, 275, 2746, 59, 18, 61, 272, 916, 2746, 59, 16, 61, 508, 298, 47, 582, 267, 27610, 275, 1109, 8, 1760, 63, 22022, 14, 362, 8, 1273, 12, 1680, 430, 272, 587, 26, 267, 27610, 275, 1109, 8, 1273, 9, 339, 327, 6696, 3647, 68, 450, 83, 450, 68, 2, 2818, 442, 637, 12, 2746, 59, 17, 467, 27610, 430, 339, 340, 2746, 59, 17, 61, 508, 298, 4077, 2, 436, 26111, 508, 27610, 26, 199, 198, 1107, 413, 272, 340, 2746, 59, 17, 61, 508, 298, 4116, 2, 436, 26111, 665, 27610, 26, 267, 372, 413, 272, 340, 2746, 59, 17, 61, 508, 298, 3308, 2, 436, 26111, 690, 27610, 26, 199, 198, 1107, 413, 272, 372, 378, 199, 199, 3, 6077, 314, 28279, 199, 893, 26, 272, 334, 1419, 12, 2368, 9, 275, 12733, 14, 18907, 8, 1274, 14, 3020, 59, 17, 8429, 7, 335, 8440, 358, 199, 2590, 12733, 14, 1002, 29368, 12, 444, 26, 272, 4503, 342, 272, 984, 14, 2224, 8, 17, 9, 199, 199, 3, 6077, 28279, 1511, 199, 509, 945, 12, 574, 315, 1511, 26, 272, 340, 945, 508, 3905, 67, 582, 267, 6786, 275, 413, 272, 916, 945, 508, 3905, 81, 582, 267, 11971, 275, 413, 272, 916, 945, 508, 3905, 84, 582, 267, 511, 275, 413, 272, 916, 945, 508, 2475, 72, 356, 267, 4503, 342, 267, 984, 14, 2224, 8, 16, 9, 199, 199, 3, 9496, 314, 1324, 1350, 199, 692, 2368, 26, 272, 862, 26, 267, 6111, 275, 1551, 8, 4958, 59, 16, 566, 272, 871, 2186, 12, 476, 26, 267, 984, 14, 3083, 14, 952, 480, 1173, 440, 1911, 450, 83, 60, 78, 2, 2818, 4958, 59, 16, 2459, 267, 984, 14, 2224, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
seem-sky/kbengine
kbe/src/lib/python/Lib/uuid.py
63
22451
r"""UUID objects (universally unique identifiers) according to RFC 4122. This module provides immutable UUID objects (class UUID) and the functions uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5 UUIDs as specified in RFC 4122. If all you want is a unique ID, you should probably call uuid1() or uuid4(). Note that uuid1() may compromise privacy since it creates a UUID containing the computer's network address. uuid4() creates a random UUID. Typical usage: >>> import uuid # make a UUID based on the host ID and current time >>> uuid.uuid1() # doctest: +SKIP UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') # make a UUID using an MD5 hash of a namespace UUID and a name >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org') UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e') # make a random UUID >>> uuid.uuid4() # doctest: +SKIP UUID('16fd2706-8baf-433b-82eb-8c7fada847da') # make a UUID using a SHA-1 hash of a namespace UUID and a name >>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org') UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d') # make a UUID from a string of hex digits (braces and hyphens ignored) >>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}') # convert a UUID to a string of hex digits in standard form >>> str(x) '00010203-0405-0607-0809-0a0b0c0d0e0f' # get the raw 16 bytes of the UUID >>> x.bytes b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f' # make a UUID from a 16-byte string >>> uuid.UUID(bytes=x.bytes) UUID('00010203-0405-0607-0809-0a0b0c0d0e0f') """ __author__ = 'Ka-Ping Yee <ping@zesty.ca>' RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE = [ 'reserved for NCS compatibility', 'specified in RFC 4122', 'reserved for Microsoft compatibility', 'reserved for future definition'] int_ = int # The built-in int type bytes_ = bytes # The built-in bytes type class UUID(object): """Instances of the UUID class represent UUIDs as specified in RFC 4122. UUID objects are immutable, hashable, and usable as dictionary keys. Converting a UUID to a string with str() yields something in the form '12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts five possible forms: a similar string of hexadecimal digits, or a tuple of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and 48-bit values respectively) as an argument named 'fields', or a string of 16 bytes (with all the integer fields in big-endian order) as an argument named 'bytes', or a string of 16 bytes (with the first three fields in little-endian order) as an argument named 'bytes_le', or a single 128-bit integer as an argument named 'int'. UUIDs have these read-only attributes: bytes the UUID as a 16-byte string (containing the six integer fields in big-endian byte order) bytes_le the UUID as a 16-byte string (with time_low, time_mid, and time_hi_version in little-endian byte order) fields a tuple of the six integer fields of the UUID, which are also available as six individual attributes and two derived attributes: time_low the first 32 bits of the UUID time_mid the next 16 bits of the UUID time_hi_version the next 16 bits of the UUID clock_seq_hi_variant the next 8 bits of the UUID clock_seq_low the next 8 bits of the UUID node the last 48 bits of the UUID time the 60-bit timestamp clock_seq the 14-bit sequence number hex the UUID as a 32-character hexadecimal string int the UUID as a 128-bit integer urn the UUID as a URN as specified in RFC 4122 variant the UUID variant (one of the constants RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE) version the UUID version number (1 through 5, meaningful only when the variant is RFC_4122) """ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None): r"""Create a UUID from either a string of 32 hexadecimal digits, a string of 16 bytes as the 'bytes' argument, a string of 16 bytes in little-endian order as the 'bytes_le' argument, a tuple of six integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version, 8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as the 'fields' argument, or a single 128-bit integer as the 'int' argument. When a string of hex digits is given, curly braces, hyphens, and a URN prefix are all optional. For example, these expressions all yield the same UUID: UUID('{12345678-1234-5678-1234-567812345678}') UUID('12345678123456781234567812345678') UUID('urn:uuid:12345678-1234-5678-1234-567812345678') UUID(bytes='\x12\x34\x56\x78'*4) UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' + '\x12\x34\x56\x78\x12\x34\x56\x78') UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678)) UUID(int=0x12345678123456781234567812345678) Exactly one of 'hex', 'bytes', 'bytes_le', 'fields', or 'int' must be given. The 'version' argument is optional; if given, the resulting UUID will have its variant and version set according to RFC 4122, overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'. """ if [hex, bytes, bytes_le, fields, int].count(None) != 4: raise TypeError('need one of hex, bytes, bytes_le, fields, or int') if hex is not None: hex = hex.replace('urn:', '').replace('uuid:', '') hex = hex.strip('{}').replace('-', '') if len(hex) != 32: raise ValueError('badly formed hexadecimal UUID string') int = int_(hex, 16) if bytes_le is not None: if len(bytes_le) != 16: raise ValueError('bytes_le is not a 16-char string') bytes = (bytes_(reversed(bytes_le[0:4])) + bytes_(reversed(bytes_le[4:6])) + bytes_(reversed(bytes_le[6:8])) + bytes_le[8:]) if bytes is not None: if len(bytes) != 16: raise ValueError('bytes is not a 16-char string') assert isinstance(bytes, bytes_), repr(bytes) int = int_.from_bytes(bytes, byteorder='big') if fields is not None: if len(fields) != 6: raise ValueError('fields is not a 6-tuple') (time_low, time_mid, time_hi_version, clock_seq_hi_variant, clock_seq_low, node) = fields if not 0 <= time_low < 1<<32: raise ValueError('field 1 out of range (need a 32-bit value)') if not 0 <= time_mid < 1<<16: raise ValueError('field 2 out of range (need a 16-bit value)') if not 0 <= time_hi_version < 1<<16: raise ValueError('field 3 out of range (need a 16-bit value)') if not 0 <= clock_seq_hi_variant < 1<<8: raise ValueError('field 4 out of range (need an 8-bit value)') if not 0 <= clock_seq_low < 1<<8: raise ValueError('field 5 out of range (need an 8-bit value)') if not 0 <= node < 1<<48: raise ValueError('field 6 out of range (need a 48-bit value)') clock_seq = (clock_seq_hi_variant << 8) | clock_seq_low int = ((time_low << 96) | (time_mid << 80) | (time_hi_version << 64) | (clock_seq << 48) | node) if int is not None: if not 0 <= int < 1<<128: raise ValueError('int is out of range (need a 128-bit value)') if version is not None: if not 1 <= version <= 5: raise ValueError('illegal version number') # Set the variant to RFC 4122. int &= ~(0xc000 << 48) int |= 0x8000 << 48 # Set the version number. int &= ~(0xf000 << 64) int |= version << 76 self.__dict__['int'] = int def __eq__(self, other): if isinstance(other, UUID): return self.int == other.int return NotImplemented def __ne__(self, other): if isinstance(other, UUID): return self.int != other.int return NotImplemented # Q. What's the value of being able to sort UUIDs? # A. Use them as keys in a B-Tree or similar mapping. def __lt__(self, other): if isinstance(other, UUID): return self.int < other.int return NotImplemented def __gt__(self, other): if isinstance(other, UUID): return self.int > other.int return NotImplemented def __le__(self, other): if isinstance(other, UUID): return self.int <= other.int return NotImplemented def __ge__(self, other): if isinstance(other, UUID): return self.int >= other.int return NotImplemented def __hash__(self): return hash(self.int) def __int__(self): return self.int def __repr__(self): return 'UUID(%r)' % str(self) def __setattr__(self, name, value): raise TypeError('UUID objects are immutable') def __str__(self): hex = '%032x' % self.int return '%s-%s-%s-%s-%s' % ( hex[:8], hex[8:12], hex[12:16], hex[16:20], hex[20:]) @property def bytes(self): bytes = bytearray() for shift in range(0, 128, 8): bytes.insert(0, (self.int >> shift) & 0xff) return bytes_(bytes) @property def bytes_le(self): bytes = self.bytes return (bytes_(reversed(bytes[0:4])) + bytes_(reversed(bytes[4:6])) + bytes_(reversed(bytes[6:8])) + bytes[8:]) @property def fields(self): return (self.time_low, self.time_mid, self.time_hi_version, self.clock_seq_hi_variant, self.clock_seq_low, self.node) @property def time_low(self): return self.int >> 96 @property def time_mid(self): return (self.int >> 80) & 0xffff @property def time_hi_version(self): return (self.int >> 64) & 0xffff @property def clock_seq_hi_variant(self): return (self.int >> 56) & 0xff @property def clock_seq_low(self): return (self.int >> 48) & 0xff @property def time(self): return (((self.time_hi_version & 0x0fff) << 48) | (self.time_mid << 32) | self.time_low) @property def clock_seq(self): return (((self.clock_seq_hi_variant & 0x3f) << 8) | self.clock_seq_low) @property def node(self): return self.int & 0xffffffffffff @property def hex(self): return '%032x' % self.int @property def urn(self): return 'urn:uuid:' + str(self) @property def variant(self): if not self.int & (0x8000 << 48): return RESERVED_NCS elif not self.int & (0x4000 << 48): return RFC_4122 elif not self.int & (0x2000 << 48): return RESERVED_MICROSOFT else: return RESERVED_FUTURE @property def version(self): # The version bits are only meaningful for RFC 4122 UUIDs. if self.variant == RFC_4122: return int((self.int >> 76) & 0xf) def _find_mac(command, args, hw_identifiers, get_index): import os, shutil executable = shutil.which(command) if executable is None: path = os.pathsep.join(('/sbin', '/usr/sbin')) executable = shutil.which(command, path=path) if executable is None: return None try: # LC_ALL to ensure English output, 2>/dev/null to prevent output on # stderr (Note: we don't have an example where the words we search for # are actually localized, but in theory some system could do so.) cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args) with os.popen(cmd) as pipe: for line in pipe: words = line.lower().split() for i in range(len(words)): if words[i] in hw_identifiers: try: return int( words[get_index(i)].replace(':', ''), 16) except (ValueError, IndexError): # Virtual interfaces, such as those provided by # VPNs, do not have a colon-delimited MAC address # as expected, but a 16-byte HWAddr separated by # dashes. These should be ignored in favor of a # real MAC address pass except OSError: pass def _ifconfig_getnode(): """Get the hardware address on Unix by running ifconfig.""" # This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes. for args in ('', '-a', '-av'): mac = _find_mac('ifconfig', args, ['hwaddr', 'ether'], lambda i: i+1) if mac: return mac import socket ip_addr = socket.gethostbyname(socket.gethostname()) # Try getting the MAC addr from arp based on our IP address (Solaris). mac = _find_mac('arp', '-an', [ip_addr], lambda i: -1) if mac: return mac # This might work on HP-UX. mac = _find_mac('lanscan', '-ai', ['lan0'], lambda i: 0) if mac: return mac return None def _ipconfig_getnode(): """Get the hardware address on Windows by running ipconfig.exe.""" import os, re dirs = ['', r'c:\windows\system32', r'c:\winnt\system32'] try: import ctypes buffer = ctypes.create_string_buffer(300) ctypes.windll.kernel32.GetSystemDirectoryA(buffer, 300) dirs.insert(0, buffer.value.decode('mbcs')) except: pass for dir in dirs: try: pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all') except OSError: continue with pipe: for line in pipe: value = line.split(':')[-1].strip().lower() if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value): return int(value.replace('-', ''), 16) def _netbios_getnode(): """Get the hardware address on Windows using NetBIOS calls. See http://support.microsoft.com/kb/118623 for details.""" import win32wnet, netbios ncb = netbios.NCB() ncb.Command = netbios.NCBENUM ncb.Buffer = adapters = netbios.LANA_ENUM() adapters._pack() if win32wnet.Netbios(ncb) != 0: return adapters._unpack() for i in range(adapters.length): ncb.Reset() ncb.Command = netbios.NCBRESET ncb.Lana_num = ord(adapters.lana[i]) if win32wnet.Netbios(ncb) != 0: continue ncb.Reset() ncb.Command = netbios.NCBASTAT ncb.Lana_num = ord(adapters.lana[i]) ncb.Callname = '*'.ljust(16) ncb.Buffer = status = netbios.ADAPTER_STATUS() if win32wnet.Netbios(ncb) != 0: continue status._unpack() bytes = status.adapter_address return ((bytes[0]<<40) + (bytes[1]<<32) + (bytes[2]<<24) + (bytes[3]<<16) + (bytes[4]<<8) + bytes[5]) # Thanks to Thomas Heller for ctypes and for his help with its use here. # If ctypes is available, use it to find system routines for UUID generation. # XXX This makes the module non-thread-safe! _uuid_generate_random = _uuid_generate_time = _UuidCreate = None try: import ctypes, ctypes.util # The uuid_generate_* routines are provided by libuuid on at least # Linux and FreeBSD, and provided by libc on Mac OS X. for libname in ['uuid', 'c']: try: lib = ctypes.CDLL(ctypes.util.find_library(libname)) except: continue if hasattr(lib, 'uuid_generate_random'): _uuid_generate_random = lib.uuid_generate_random if hasattr(lib, 'uuid_generate_time'): _uuid_generate_time = lib.uuid_generate_time if _uuid_generate_random is not None: break # found everything we were looking for # The uuid_generate_* functions are broken on MacOS X 10.5, as noted # in issue #8621 the function generates the same sequence of values # in the parent process and all children created using fork (unless # those children use exec as well). # # Assume that the uuid_generate functions are broken from 10.5 onward, # the test can be adjusted when a later version is fixed. import sys if sys.platform == 'darwin': import os if int(os.uname().release.split('.')[0]) >= 9: _uuid_generate_random = _uuid_generate_time = None # On Windows prior to 2000, UuidCreate gives a UUID containing the # hardware address. On Windows 2000 and later, UuidCreate makes a # random UUID and UuidCreateSequential gives a UUID containing the # hardware address. These routines are provided by the RPC runtime. # NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last # 6 bytes returned by UuidCreateSequential are fixed, they don't appear # to bear any relationship to the MAC address of any network device # on the box. try: lib = ctypes.windll.rpcrt4 except: lib = None _UuidCreate = getattr(lib, 'UuidCreateSequential', getattr(lib, 'UuidCreate', None)) except: pass def _unixdll_getnode(): """Get the hardware address on Unix using ctypes.""" _buffer = ctypes.create_string_buffer(16) _uuid_generate_time(_buffer) return UUID(bytes=bytes_(_buffer.raw)).node def _windll_getnode(): """Get the hardware address on Windows using ctypes.""" _buffer = ctypes.create_string_buffer(16) if _UuidCreate(_buffer) == 0: return UUID(bytes=bytes_(_buffer.raw)).node def _random_getnode(): """Get a random node ID, with eighth bit set as suggested by RFC 4122.""" import random return random.randrange(0, 1<<48) | 0x010000000000 _node = None def getnode(): """Get the hardware address as a 48-bit positive integer. The first time this runs, it may launch a separate program, which could be quite slow. If all attempts to obtain the hardware address fail, we choose a random 48-bit number with its eighth bit set to 1 as recommended in RFC 4122. """ global _node if _node is not None: return _node import sys if sys.platform == 'win32': getters = [_windll_getnode, _netbios_getnode, _ipconfig_getnode] else: getters = [_unixdll_getnode, _ifconfig_getnode] for getter in getters + [_random_getnode]: try: _node = getter() except: continue if _node is not None: return _node _last_timestamp = None def uuid1(node=None, clock_seq=None): """Generate a UUID from a host ID, sequence number, and the current time. If 'node' is not given, getnode() is used to obtain the hardware address. If 'clock_seq' is given, it is used as the sequence number; otherwise a random 14-bit sequence number is chosen.""" # When the system provides a version-1 UUID generator, use it (but don't # use UuidCreate here because its UUIDs don't conform to RFC 4122). if _uuid_generate_time and node is clock_seq is None: _buffer = ctypes.create_string_buffer(16) _uuid_generate_time(_buffer) return UUID(bytes=bytes_(_buffer.raw)) global _last_timestamp import time nanoseconds = int(time.time() * 1e9) # 0x01b21dd213814000 is the number of 100-ns intervals between the # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00. timestamp = int(nanoseconds/100) + 0x01b21dd213814000 if _last_timestamp is not None and timestamp <= _last_timestamp: timestamp = _last_timestamp + 1 _last_timestamp = timestamp if clock_seq is None: import random clock_seq = random.randrange(1<<14) # instead of stable storage time_low = timestamp & 0xffffffff time_mid = (timestamp >> 32) & 0xffff time_hi_version = (timestamp >> 48) & 0x0fff clock_seq_low = clock_seq & 0xff clock_seq_hi_variant = (clock_seq >> 8) & 0x3f if node is None: node = getnode() return UUID(fields=(time_low, time_mid, time_hi_version, clock_seq_hi_variant, clock_seq_low, node), version=1) def uuid3(namespace, name): """Generate a UUID from the MD5 hash of a namespace UUID and a name.""" from hashlib import md5 hash = md5(namespace.bytes + bytes(name, "utf-8")).digest() return UUID(bytes=hash[:16], version=3) def uuid4(): """Generate a random UUID.""" # When the system provides a version-4 UUID generator, use it. if _uuid_generate_random: _buffer = ctypes.create_string_buffer(16) _uuid_generate_random(_buffer) return UUID(bytes=bytes_(_buffer.raw)) # Otherwise, get randomness from urandom or the 'random' module. try: import os return UUID(bytes=os.urandom(16), version=4) except: import random bytes = bytes_(random.randrange(256) for i in range(16)) return UUID(bytes=bytes, version=4) def uuid5(namespace, name): """Generate a UUID from the SHA-1 hash of a namespace UUID and a name.""" from hashlib import sha1 hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest() return UUID(bytes=hash[:16], version=5) # The following standard UUIDs are for use with uuid3() or uuid5(). NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8') NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8') NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8') NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')
lgpl-3.0
[ 82, 624, 8757, 2251, 334, 324, 4380, 83, 1183, 3747, 14154, 9, 7182, 370, 7329, 841, 7507, 14, 199, 199, 2765, 859, 6571, 17092, 11134, 2251, 334, 533, 11134, 9, 436, 314, 3423, 199, 2580, 17, 1062, 5377, 19, 1062, 5377, 20, 1062, 5377, 21, 342, 367, 12999, 1015, 413, 12, 650, 12, 841, 12, 436, 959, 199, 8757, 83, 465, 2013, 315, 7329, 841, 7507, 14, 199, 199, 3917, 1006, 1265, 2934, 365, 282, 3747, 2870, 12, 1265, 1077, 8646, 1240, 5377, 17, 342, 503, 5377, 20, 1252, 199, 7443, 626, 5377, 17, 342, 1443, 1013, 417, 572, 16254, 4085, 3967, 652, 8491, 282, 11134, 3035, 199, 1589, 24189, 1159, 2784, 2287, 14, 221, 5377, 20, 342, 8491, 282, 2196, 11134, 14, 199, 199, 26876, 4503, 26, 339, 1306, 492, 5377, 339, 327, 1852, 282, 11134, 4079, 641, 314, 1591, 2870, 436, 1453, 900, 272, 1306, 5377, 14, 2580, 17, 342, 259, 327, 8868, 26, 435, 13525, 272, 11134, 360, 65, 1257, 2905, 67, 17, 65, 13, 70, 1184, 69, 13, 845, 983, 13, 3691, 17, 65, 13, 4587, 713, 18078, 1235, 17, 69, 358, 339, 327, 1852, 282, 11134, 1808, 376, 15830, 21, 2631, 402, 282, 3231, 11134, 436, 282, 536, 272, 1306, 5377, 14, 2580, 19, 8, 2580, 14, 13001, 63, 12323, 12, 283, 1548, 14, 1308, 358, 272, 11134, 360, 22, 667, 28976, 4489, 13, 1024, 24, 65, 13, 19, 696, 20, 13, 12128, 69, 13, 697, 1138, 69, 975, 1644, 1229, 69, 358, 339, 327, 1852, 282, 2196, 11134, 272, 1306, 5377, 14, 2580, 20, 342, 259, 327, 8868, 26, 435, 13525, 272, 11134, 360, 975, 2592, 1465, 1690, 13, 24, 25485, 13, 23404, 66, 13, 2564, 2871, 13, 24, 67, 23, 70, 10641, 15883, 983, 358, 339, 327, 1852, 282, 11134, 1808, 282, 12002, 13, 17, 2631, 402, 282, 3231, 11134, 436, 282, 536, 272, 1306, 5377, 14, 2580, 21, 8, 2580, 14, 13001, 63, 12323, 12, 283, 1548, 14, 1308, 358, 272, 11134, 360, 24, 15887, 969, 69, 17, 13, 19, 66, 24, 65, 13, 21, 15541, 13, 25, 66, 2710, 13, 16, 67, 25, 65, 1024, 7155, 69, 21, 68, 358, 339, 327, 1852, 282, 11134, 687, 282, 1059, 402, 6318, 7576, 334, 7828, 823, 436, 7188, 27920, 5525, 9, 272, 1306, 671, 275, 5377, 14, 8757, 11117, 4183, 996, 1644, 13, 966, 1717, 13, 1690, 1780, 13, 16, 11782, 13, 16, 65, 16, 66, 16, 67, 16, 68, 16, 69, 16, 70, 12216, 339, 327, 3957, 282, 11134, 370, 282, 1059, 402, 6318, 7576, 315, 4465, 1824, 272, 1306, 620, 8, 88, 9, 272, 283, 4183, 996, 1644, 13, 966, 1717, 13, 1690, 1780, 13, 16, 11782, 13, 16, 65, 16, 66, 16, 67, 16, 68, 16, 69, 16, 70, 7, 339, 327, 664, 314, 3066, 3193, 2783, 402, 314, 11134, 272, 1306, 671, 14, 2394, 272, 330, 1154, 88, 383, 60, 88, 614, 60, 88, 996, 60, 88, 1644, 60, 88, 966, 60, 88, 1717, 60, 88, 1690, 60, 88, 1780, 60, 88, 2036, 60, 84, 60, 78, 60, 88, 16, 66, 60, 88, 16, 67, 60, 82, 60, 88, 16, 69, 60, 88, 16, 70, 7, 339, 327, 1852, 282, 11134, 687, 282, 3193, 13, 4414, 1059, 272, 1306, 5377, 14, 8757, 8, 2394, 29, 88, 14, 2394, 9, 272, 11134, 360, 4183, 996, 1644, 13, 966, 1717, 13, 1690, 1780, 13, 16, 11782, 13, 16, 65, 16, 66, 16, 67, 16, 68, 16, 69, 16, 70, 358, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 26133, 13, 22638, 1488, 1024, 665, 4073, 32, 90, 597, 89, 14, 696, 3524, 199, 199, 26933, 63, 46, 3298, 12, 7329, 63, 20, 7507, 12, 12565, 540, 14112, 63, 29112, 26999, 12, 12565, 540, 14112, 63, 20254, 3942, 275, 359, 272, 283, 10421, 367, 653, 3298, 7163, 297, 283, 10085, 315, 7329, 841, 7507, 297, 272, 283, 10421, 367, 15332, 7163, 297, 283, 10421, 367, 6466, 5492, 418, 199, 199, 442, 63, 275, 1109, 420, 327, 710, 6137, 13, 262, 1109, 730, 199, 2394, 63, 275, 2783, 221, 327, 710, 6137, 13, 262, 2783, 730, 199, 199, 533, 11134, 8, 785, 304, 272, 408, 18194, 402, 314, 11134, 1021, 2954, 11134, 83, 465, 2013, 315, 7329, 841, 7507, 14, 272, 11134, 2251, 787, 17092, 12, 21197, 12, 436, 18025, 465, 2600, 2883, 14, 272, 23258, 282, 11134, 370, 282, 1059, 543, 620, 342, 14801, 6020, 315, 314, 1824, 272, 283, 19542, 13, 4321, 13, 4321, 13, 4321, 13, 11272, 3175, 1370, 221, 710, 11134, 3787, 11479, 272, 24187, 3962, 4513, 26, 282, 8545, 1059, 402, 20379, 7576, 12, 503, 282, 2008, 272, 402, 3816, 3000, 1504, 334, 1045, 4337, 13, 2075, 12, 3193, 13, 2075, 12, 3193, 13, 2075, 12, 1695, 13, 2075, 12, 1695, 13, 2075, 12, 436, 272, 9615, 13, 2075, 1338, 17342, 9, 465, 376, 1423, 4310, 283, 955, 297, 503, 282, 1059, 272, 402, 3193, 2783, 334, 1045, 1006, 314, 3000, 1504, 315, 7282, 13, 15009, 1865, 9, 465, 376, 272, 1423, 4310, 283, 2394, 297, 503, 282, 1059, 402, 3193, 2783, 334, 1045, 314, 1642, 7795, 272, 1504, 315, 12050, 13, 15009, 1865, 9, 465, 376, 1423, 4310, 283, 2394, 63, 274, 297, 503, 282, 272, 2849, 7960, 13, 2075, 3000, 465, 376, 1423, 4310, 283, 442, 1370, 339, 11134, 83, 1172, 3520, 1586, 13, 2118, 3004, 26, 398, 2783, 755, 314, 11134, 465, 282, 3193, 13, 4414, 1059, 334, 16133, 314, 3816, 490, 3000, 1504, 315, 7282, 13, 15009, 3696, 1865, 9, 398, 2783, 63, 274, 259, 314, 11134, 465, 282, 3193, 13, 4414, 1059, 334, 1045, 900, 63, 674, 12, 900, 63, 8523, 12, 490, 436, 900, 63, 5812, 63, 1023, 315, 12050, 13, 15009, 3696, 1865, 9, 398, 1504, 420, 282, 2008, 402, 314, 3816, 3000, 1504, 402, 314, 11134, 12, 490, 1314, 787, 2597, 2808, 465, 3816, 8212, 3004, 490, 436, 2877, 7131, 3004, 26, 953, 900, 63, 674, 4483, 314, 1642, 4337, 5821, 402, 314, 11134, 288, 900, 63, 8523, 4483, 314, 2163, 3193, 5821, 402, 314, 11134, 288, 900, 63, 5812, 63, 1023, 260, 314, 2163, 3193, 5821, 402, 314, 11134, 288, 12516, 63 ]
[ 624, 8757, 2251, 334, 324, 4380, 83, 1183, 3747, 14154, 9, 7182, 370, 7329, 841, 7507, 14, 199, 199, 2765, 859, 6571, 17092, 11134, 2251, 334, 533, 11134, 9, 436, 314, 3423, 199, 2580, 17, 1062, 5377, 19, 1062, 5377, 20, 1062, 5377, 21, 342, 367, 12999, 1015, 413, 12, 650, 12, 841, 12, 436, 959, 199, 8757, 83, 465, 2013, 315, 7329, 841, 7507, 14, 199, 199, 3917, 1006, 1265, 2934, 365, 282, 3747, 2870, 12, 1265, 1077, 8646, 1240, 5377, 17, 342, 503, 5377, 20, 1252, 199, 7443, 626, 5377, 17, 342, 1443, 1013, 417, 572, 16254, 4085, 3967, 652, 8491, 282, 11134, 3035, 199, 1589, 24189, 1159, 2784, 2287, 14, 221, 5377, 20, 342, 8491, 282, 2196, 11134, 14, 199, 199, 26876, 4503, 26, 339, 1306, 492, 5377, 339, 327, 1852, 282, 11134, 4079, 641, 314, 1591, 2870, 436, 1453, 900, 272, 1306, 5377, 14, 2580, 17, 342, 259, 327, 8868, 26, 435, 13525, 272, 11134, 360, 65, 1257, 2905, 67, 17, 65, 13, 70, 1184, 69, 13, 845, 983, 13, 3691, 17, 65, 13, 4587, 713, 18078, 1235, 17, 69, 358, 339, 327, 1852, 282, 11134, 1808, 376, 15830, 21, 2631, 402, 282, 3231, 11134, 436, 282, 536, 272, 1306, 5377, 14, 2580, 19, 8, 2580, 14, 13001, 63, 12323, 12, 283, 1548, 14, 1308, 358, 272, 11134, 360, 22, 667, 28976, 4489, 13, 1024, 24, 65, 13, 19, 696, 20, 13, 12128, 69, 13, 697, 1138, 69, 975, 1644, 1229, 69, 358, 339, 327, 1852, 282, 2196, 11134, 272, 1306, 5377, 14, 2580, 20, 342, 259, 327, 8868, 26, 435, 13525, 272, 11134, 360, 975, 2592, 1465, 1690, 13, 24, 25485, 13, 23404, 66, 13, 2564, 2871, 13, 24, 67, 23, 70, 10641, 15883, 983, 358, 339, 327, 1852, 282, 11134, 1808, 282, 12002, 13, 17, 2631, 402, 282, 3231, 11134, 436, 282, 536, 272, 1306, 5377, 14, 2580, 21, 8, 2580, 14, 13001, 63, 12323, 12, 283, 1548, 14, 1308, 358, 272, 11134, 360, 24, 15887, 969, 69, 17, 13, 19, 66, 24, 65, 13, 21, 15541, 13, 25, 66, 2710, 13, 16, 67, 25, 65, 1024, 7155, 69, 21, 68, 358, 339, 327, 1852, 282, 11134, 687, 282, 1059, 402, 6318, 7576, 334, 7828, 823, 436, 7188, 27920, 5525, 9, 272, 1306, 671, 275, 5377, 14, 8757, 11117, 4183, 996, 1644, 13, 966, 1717, 13, 1690, 1780, 13, 16, 11782, 13, 16, 65, 16, 66, 16, 67, 16, 68, 16, 69, 16, 70, 12216, 339, 327, 3957, 282, 11134, 370, 282, 1059, 402, 6318, 7576, 315, 4465, 1824, 272, 1306, 620, 8, 88, 9, 272, 283, 4183, 996, 1644, 13, 966, 1717, 13, 1690, 1780, 13, 16, 11782, 13, 16, 65, 16, 66, 16, 67, 16, 68, 16, 69, 16, 70, 7, 339, 327, 664, 314, 3066, 3193, 2783, 402, 314, 11134, 272, 1306, 671, 14, 2394, 272, 330, 1154, 88, 383, 60, 88, 614, 60, 88, 996, 60, 88, 1644, 60, 88, 966, 60, 88, 1717, 60, 88, 1690, 60, 88, 1780, 60, 88, 2036, 60, 84, 60, 78, 60, 88, 16, 66, 60, 88, 16, 67, 60, 82, 60, 88, 16, 69, 60, 88, 16, 70, 7, 339, 327, 1852, 282, 11134, 687, 282, 3193, 13, 4414, 1059, 272, 1306, 5377, 14, 8757, 8, 2394, 29, 88, 14, 2394, 9, 272, 11134, 360, 4183, 996, 1644, 13, 966, 1717, 13, 1690, 1780, 13, 16, 11782, 13, 16, 65, 16, 66, 16, 67, 16, 68, 16, 69, 16, 70, 358, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 26133, 13, 22638, 1488, 1024, 665, 4073, 32, 90, 597, 89, 14, 696, 3524, 199, 199, 26933, 63, 46, 3298, 12, 7329, 63, 20, 7507, 12, 12565, 540, 14112, 63, 29112, 26999, 12, 12565, 540, 14112, 63, 20254, 3942, 275, 359, 272, 283, 10421, 367, 653, 3298, 7163, 297, 283, 10085, 315, 7329, 841, 7507, 297, 272, 283, 10421, 367, 15332, 7163, 297, 283, 10421, 367, 6466, 5492, 418, 199, 199, 442, 63, 275, 1109, 420, 327, 710, 6137, 13, 262, 1109, 730, 199, 2394, 63, 275, 2783, 221, 327, 710, 6137, 13, 262, 2783, 730, 199, 199, 533, 11134, 8, 785, 304, 272, 408, 18194, 402, 314, 11134, 1021, 2954, 11134, 83, 465, 2013, 315, 7329, 841, 7507, 14, 272, 11134, 2251, 787, 17092, 12, 21197, 12, 436, 18025, 465, 2600, 2883, 14, 272, 23258, 282, 11134, 370, 282, 1059, 543, 620, 342, 14801, 6020, 315, 314, 1824, 272, 283, 19542, 13, 4321, 13, 4321, 13, 4321, 13, 11272, 3175, 1370, 221, 710, 11134, 3787, 11479, 272, 24187, 3962, 4513, 26, 282, 8545, 1059, 402, 20379, 7576, 12, 503, 282, 2008, 272, 402, 3816, 3000, 1504, 334, 1045, 4337, 13, 2075, 12, 3193, 13, 2075, 12, 3193, 13, 2075, 12, 1695, 13, 2075, 12, 1695, 13, 2075, 12, 436, 272, 9615, 13, 2075, 1338, 17342, 9, 465, 376, 1423, 4310, 283, 955, 297, 503, 282, 1059, 272, 402, 3193, 2783, 334, 1045, 1006, 314, 3000, 1504, 315, 7282, 13, 15009, 1865, 9, 465, 376, 272, 1423, 4310, 283, 2394, 297, 503, 282, 1059, 402, 3193, 2783, 334, 1045, 314, 1642, 7795, 272, 1504, 315, 12050, 13, 15009, 1865, 9, 465, 376, 1423, 4310, 283, 2394, 63, 274, 297, 503, 282, 272, 2849, 7960, 13, 2075, 3000, 465, 376, 1423, 4310, 283, 442, 1370, 339, 11134, 83, 1172, 3520, 1586, 13, 2118, 3004, 26, 398, 2783, 755, 314, 11134, 465, 282, 3193, 13, 4414, 1059, 334, 16133, 314, 3816, 490, 3000, 1504, 315, 7282, 13, 15009, 3696, 1865, 9, 398, 2783, 63, 274, 259, 314, 11134, 465, 282, 3193, 13, 4414, 1059, 334, 1045, 900, 63, 674, 12, 900, 63, 8523, 12, 490, 436, 900, 63, 5812, 63, 1023, 315, 12050, 13, 15009, 3696, 1865, 9, 398, 1504, 420, 282, 2008, 402, 314, 3816, 3000, 1504, 402, 314, 11134, 12, 490, 1314, 787, 2597, 2808, 465, 3816, 8212, 3004, 490, 436, 2877, 7131, 3004, 26, 953, 900, 63, 674, 4483, 314, 1642, 4337, 5821, 402, 314, 11134, 288, 900, 63, 8523, 4483, 314, 2163, 3193, 5821, 402, 314, 11134, 288, 900, 63, 5812, 63, 1023, 260, 314, 2163, 3193, 5821, 402, 314, 11134, 288, 12516, 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 ]
rimbalinux/MSISDNArea
django/contrib/admin/templatetags/admin_list.py
3
13519
import datetime from django.conf import settings from django.contrib.admin.util import lookup_field, display_for_field, label_for_field from django.contrib.admin.views.main import ALL_VAR, EMPTY_CHANGELIST_VALUE from django.contrib.admin.views.main import ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR, SEARCH_VAR from django.core.exceptions import ObjectDoesNotExist from django.db import models from django.utils import formats from django.utils.html import escape, conditional_escape from django.utils.safestring import mark_safe from django.utils.text import capfirst from django.utils.translation import ugettext as _ from django.utils.encoding import smart_unicode, force_unicode from django.template import Library register = Library() DOT = '.' def paginator_number(cl,i): """ Generates an individual page index link in a paginated list. """ if i == DOT: return u'... ' elif i == cl.page_num: return mark_safe(u'<span class="this-page">%d</span> ' % (i+1)) else: return mark_safe(u'<a href="%s"%s>%d</a> ' % (escape(cl.get_query_string({PAGE_VAR: i})), (i == cl.paginator.num_pages-1 and ' class="end"' or ''), i+1)) paginator_number = register.simple_tag(paginator_number) def pagination(cl): """ Generates the series of links to the pages in a paginated list. """ paginator, page_num = cl.paginator, cl.page_num pagination_required = (not cl.show_all or not cl.can_show_all) and cl.multi_page if not pagination_required: page_range = [] else: ON_EACH_SIDE = 3 ON_ENDS = 2 # If there are 10 or fewer pages, display links to every page. # Otherwise, do some fancy if paginator.num_pages <= 10: page_range = range(paginator.num_pages) else: # Insert "smart" pagination links, so that there are always ON_ENDS # links at either end of the list of pages, and there are always # ON_EACH_SIDE links at either end of the "current page" link. page_range = [] if page_num > (ON_EACH_SIDE + ON_ENDS): page_range.extend(range(0, ON_EACH_SIDE - 1)) page_range.append(DOT) page_range.extend(range(page_num - ON_EACH_SIDE, page_num + 1)) else: page_range.extend(range(0, page_num + 1)) if page_num < (paginator.num_pages - ON_EACH_SIDE - ON_ENDS - 1): page_range.extend(range(page_num + 1, page_num + ON_EACH_SIDE + 1)) page_range.append(DOT) page_range.extend(range(paginator.num_pages - ON_ENDS, paginator.num_pages)) else: page_range.extend(range(page_num + 1, paginator.num_pages)) need_show_all_link = cl.can_show_all and not cl.show_all and cl.multi_page return { 'cl': cl, 'pagination_required': pagination_required, 'show_all_url': need_show_all_link and cl.get_query_string({ALL_VAR: ''}), 'page_range': page_range, 'ALL_VAR': ALL_VAR, '1': 1, } pagination = register.inclusion_tag('admin/pagination.html')(pagination) def result_headers(cl): """ Generates the list column headers. """ lookup_opts = cl.lookup_opts for i, field_name in enumerate(cl.list_display): header, attr = label_for_field(field_name, cl.model, model_admin = cl.model_admin, return_attr = True ) if attr: # if the field is the action checkbox: no sorting and special class if field_name == 'action_checkbox': yield { "text": header, "class_attrib": mark_safe(' class="action-checkbox-column"') } continue # It is a non-field, but perhaps one that is sortable admin_order_field = getattr(attr, "admin_order_field", None) if not admin_order_field: yield {"text": header} continue # So this _is_ a sortable non-field. Go to the yield # after the else clause. else: admin_order_field = None th_classes = [] new_order_type = 'asc' if field_name == cl.order_field or admin_order_field == cl.order_field: th_classes.append('sorted %sending' % cl.order_type.lower()) new_order_type = {'asc': 'desc', 'desc': 'asc'}[cl.order_type.lower()] yield { "text": header, "sortable": True, "url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}), "class_attrib": mark_safe(th_classes and ' class="%s"' % ' '.join(th_classes) or '') } def _boolean_icon(field_val): BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'} return mark_safe(u'<img src="%simg/admin/icon-%s.gif" alt="%s" />' % (settings.ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val)) def items_for_result(cl, result, form): """ Generates the actual list of data. """ first = True pk = cl.lookup_opts.pk.attname for field_name in cl.list_display: row_class = '' try: f, attr, value = lookup_field(field_name, result, cl.model_admin) except (AttributeError, ObjectDoesNotExist): result_repr = EMPTY_CHANGELIST_VALUE else: if f is None: allow_tags = getattr(attr, 'allow_tags', False) boolean = getattr(attr, 'boolean', False) if boolean: allow_tags = True result_repr = _boolean_icon(value) else: result_repr = smart_unicode(value) # Strip HTML tags in the resulting text, except if the # function has an "allow_tags" attribute set to True. if not allow_tags: result_repr = escape(result_repr) else: result_repr = mark_safe(result_repr) else: if value is None: result_repr = EMPTY_CHANGELIST_VALUE if isinstance(f.rel, models.ManyToOneRel): result_repr = escape(getattr(result, f.name)) else: result_repr = display_for_field(value, f) if isinstance(f, models.DateField) or isinstance(f, models.TimeField): row_class = ' class="nowrap"' if force_unicode(result_repr) == '': result_repr = mark_safe('&nbsp;') # If list_display_links not defined, add the link tag to the first field if (first and not cl.list_display_links) or field_name in cl.list_display_links: table_tag = {True:'th', False:'td'}[first] first = False url = cl.url_for_result(result) # Convert the pk to something that can be used in Javascript. # Problem cases are long ints (23L) and non-ASCII strings. if cl.to_field: attr = str(cl.to_field) else: attr = pk value = result.serializable_value(attr) result_id = repr(force_unicode(value))[1:] yield mark_safe(u'<%s%s><a href="%s"%s>%s</a></%s>' % \ (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag)) else: # By default the fields come from ModelAdmin.list_editable, but if we pull # the fields out of the form instead of list_editable custom admins # can provide fields on a per request basis if form and field_name in form.fields: bf = form[field_name] result_repr = mark_safe(force_unicode(bf.errors) + force_unicode(bf)) else: result_repr = conditional_escape(result_repr) yield mark_safe(u'<td%s>%s</td>' % (row_class, result_repr)) if form and not form[cl.model._meta.pk.name].is_hidden: yield mark_safe(u'<td>%s</td>' % force_unicode(form[cl.model._meta.pk.name])) def results(cl): if cl.formset: for res, form in zip(cl.result_list, cl.formset.forms): yield list(items_for_result(cl, res, form)) else: for res in cl.result_list: yield list(items_for_result(cl, res, None)) def result_hidden_fields(cl): if cl.formset: for res, form in zip(cl.result_list, cl.formset.forms): if form[cl.model._meta.pk.name].is_hidden: yield mark_safe(force_unicode(form[cl.model._meta.pk.name])) def result_list(cl): """ Displays the headers and data list together """ return {'cl': cl, 'result_hidden_fields': list(result_hidden_fields(cl)), 'result_headers': list(result_headers(cl)), 'results': list(results(cl))} result_list = register.inclusion_tag("admin/change_list_results.html")(result_list) def date_hierarchy(cl): """ Displays the date hierarchy for date drill-down functionality. """ if cl.date_hierarchy: field_name = cl.date_hierarchy year_field = '%s__year' % field_name month_field = '%s__month' % field_name day_field = '%s__day' % field_name field_generic = '%s__' % field_name year_lookup = cl.params.get(year_field) month_lookup = cl.params.get(month_field) day_lookup = cl.params.get(day_field) link = lambda d: cl.get_query_string(d, [field_generic]) if not (year_lookup or month_lookup or day_lookup): # select appropriate start level date_range = cl.query_set.aggregate(first=models.Min(field_name), last=models.Max(field_name)) if date_range['first'] and date_range['last']: if date_range['first'].year == date_range['last'].year: year_lookup = date_range['first'].year if date_range['first'].month == date_range['last'].month: month_lookup = date_range['first'].month if year_lookup and month_lookup and day_lookup: day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup)) return { 'show': True, 'back': { 'link': link({year_field: year_lookup, month_field: month_lookup}), 'title': capfirst(formats.date_format(day, 'YEAR_MONTH_FORMAT')) }, 'choices': [{'title': capfirst(formats.date_format(day, 'MONTH_DAY_FORMAT'))}] } elif year_lookup and month_lookup: days = cl.query_set.filter(**{year_field: year_lookup, month_field: month_lookup}).dates(field_name, 'day') return { 'show': True, 'back': { 'link': link({year_field: year_lookup}), 'title': year_lookup }, 'choices': [{ 'link': link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}), 'title': capfirst(formats.date_format(day, 'MONTH_DAY_FORMAT')) } for day in days] } elif year_lookup: months = cl.query_set.filter(**{year_field: year_lookup}).dates(field_name, 'month') return { 'show' : True, 'back': { 'link' : link({}), 'title': _('All dates') }, 'choices': [{ 'link': link({year_field: year_lookup, month_field: month.month}), 'title': capfirst(formats.date_format(month, 'YEAR_MONTH_FORMAT')) } for month in months] } else: years = cl.query_set.dates(field_name, 'year') return { 'show': True, 'choices': [{ 'link': link({year_field: str(year.year)}), 'title': str(year.year), } for year in years] } date_hierarchy = register.inclusion_tag('admin/date_hierarchy.html')(date_hierarchy) def search_form(cl): """ Displays a search form for searching the list. """ return { 'cl': cl, 'show_result_count': cl.result_count != cl.full_result_count, 'search_var': SEARCH_VAR } search_form = register.inclusion_tag('admin/search_form.html')(search_form) def admin_list_filter(cl, spec): return {'title': spec.title(), 'choices' : list(spec.choices(cl))} admin_list_filter = register.inclusion_tag('admin/filter.html')(admin_list_filter) def admin_actions(context): """ Track the number of times the action field has been rendered on the page, so we know which value to use. """ context['action_index'] = context.get('action_index', -1) + 1 return context admin_actions = register.inclusion_tag("admin/actions.html", takes_context=True)(admin_actions)
bsd-3-clause
[ 646, 2197, 2999, 199, 504, 1639, 14, 2190, 492, 2202, 202, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1974, 492, 4237, 63, 698, 12, 2929, 63, 509, 63, 698, 12, 1768, 63, 509, 63, 698, 202, 199, 504, 1639, 14, 2828, 14, 2113, 14, 4196, 14, 973, 492, 11727, 63, 5568, 12, 16589, 63, 16062, 4924, 63, 7041, 202, 199, 504, 1639, 14, 2828, 14, 2113, 14, 4196, 14, 973, 492, 16044, 63, 5568, 12, 16044, 63, 2711, 63, 5568, 12, 510, 2962, 63, 5568, 12, 5795, 7762, 63, 5568, 202, 199, 504, 1639, 14, 1018, 14, 3924, 492, 24803, 202, 199, 504, 1639, 14, 697, 492, 1709, 202, 199, 504, 1639, 14, 1208, 492, 6752, 202, 199, 504, 1639, 14, 1208, 14, 1360, 492, 4772, 12, 12303, 63, 3765, 202, 199, 504, 1639, 14, 1208, 14, 28389, 492, 2216, 63, 3489, 202, 199, 504, 1639, 14, 1208, 14, 505, 492, 4021, 2246, 202, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 465, 485, 202, 199, 504, 1639, 14, 1208, 14, 2991, 492, 11179, 63, 2975, 12, 3542, 63, 2975, 202, 199, 504, 1639, 14, 1160, 492, 11243, 8065, 199, 2683, 275, 11243, 342, 2999, 199, 13203, 275, 7815, 2999, 199, 318, 21398, 63, 1955, 8, 429, 12, 73, 304, 1128, 408, 1128, 21687, 376, 8212, 2034, 1478, 2142, 315, 282, 9881, 23831, 769, 14, 1128, 408, 1128, 340, 284, 508, 15854, 26, 1039, 372, 399, 7, 1396, 283, 1128, 916, 284, 508, 824, 14, 1606, 63, 1507, 26, 1039, 372, 2216, 63, 3489, 8, 85, 7601, 3751, 1021, 628, 3749, 13, 1606, 14423, 68, 1108, 3751, 30, 283, 450, 334, 73, 11, 17, 430, 1128, 587, 26, 1039, 372, 2216, 63, 3489, 8, 85, 7601, 65, 4369, 5961, 83, 6808, 83, 6598, 68, 1108, 65, 30, 283, 450, 334, 3765, 8, 429, 14, 362, 63, 1131, 63, 875, 2561, 12898, 63, 5568, 26, 284, 1552, 395, 334, 73, 508, 824, 14, 22073, 14, 1507, 63, 5856, 13, 17, 436, 283, 1021, 628, 500, 4507, 503, 9929, 284, 11, 17, 430, 202, 199, 22073, 63, 1955, 275, 2274, 14, 4129, 63, 1450, 8, 22073, 63, 1955, 9, 2999, 199, 318, 21192, 8, 429, 304, 1128, 408, 1128, 21687, 314, 6779, 402, 6220, 370, 314, 6497, 315, 282, 9881, 23831, 769, 14, 1128, 408, 1128, 21398, 12, 2034, 63, 1507, 275, 824, 14, 22073, 12, 824, 14, 1606, 63, 1507, 2958, 21192, 63, 2427, 275, 334, 1397, 824, 14, 2384, 63, 452, 503, 440, 824, 14, 2425, 63, 2384, 63, 452, 9, 436, 824, 14, 3029, 63, 1606, 1128, 340, 440, 21192, 63, 2427, 26, 1039, 2034, 63, 1842, 275, 942, 1128, 587, 26, 1039, 5258, 63, 11765, 1244, 63, 28035, 275, 650, 1039, 5258, 63, 20853, 275, 499, 4341, 327, 982, 2337, 787, 1616, 503, 27392, 6497, 12, 2929, 6220, 370, 4036, 2034, 14, 1039, 327, 6630, 12, 886, 2005, 27571, 1039, 340, 21398, 14, 1507, 63, 5856, 2695, 1616, 26, 1675, 2034, 63, 1842, 275, 1425, 8, 22073, 14, 1507, 63, 5856, 9, 1039, 587, 26, 1675, 327, 15496, 298, 7853, 2, 21192, 6220, 12, 880, 626, 2337, 787, 3544, 5258, 63, 20853, 1675, 327, 6220, 737, 1902, 1284, 402, 314, 769, 402, 6497, 12, 436, 2337, 787, 3544, 1675, 327, 5258, 63, 11765, 1244, 63, 28035, 6220, 737, 1902, 1284, 402, 314, 298, 1818, 2034, 2, 2142, 14, 1675, 2034, 63, 1842, 275, 942, 1675, 340, 2034, 63, 1507, 690, 334, 615, 63, 11765, 1244, 63, 28035, 435, 5258, 63, 20853, 304, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 16, 12, 5258, 63, 11765, 1244, 63, 28035, 446, 413, 430, 2628, 2034, 63, 1842, 14, 740, 8, 13203, 9, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 446, 5258, 63, 11765, 1244, 63, 28035, 12, 2034, 63, 1507, 435, 413, 430, 1675, 587, 26, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 16, 12, 2034, 63, 1507, 435, 413, 430, 1675, 340, 2034, 63, 1507, 665, 334, 22073, 14, 1507, 63, 5856, 446, 5258, 63, 11765, 1244, 63, 28035, 446, 5258, 63, 20853, 446, 413, 304, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 435, 413, 12, 2034, 63, 1507, 435, 5258, 63, 11765, 1244, 63, 28035, 435, 413, 430, 2628, 2034, 63, 1842, 14, 740, 8, 13203, 9, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 22073, 14, 1507, 63, 5856, 446, 5258, 63, 20853, 12, 21398, 14, 1507, 63, 5856, 430, 1675, 587, 26, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 435, 413, 12, 21398, 14, 1507, 63, 5856, 430, 2958, 1929, 63, 2384, 63, 452, 63, 1073, 275, 824, 14, 2425, 63, 2384, 63, 452, 436, 440, 824, 14, 2384, 63, 452, 436, 824, 14, 3029, 63, 1606, 1128, 372, 469, 1039, 283, 429, 356, 824, 12, 1039, 283, 22793, 63, 2427, 356, 21192, 63, 2427, 12, 1039, 283, 2384, 63, 452, 63, 633, 356, 1929, 63, 2384, 63, 452, 63, 1073, 436, 824, 14, 362, 63, 1131, 63, 875, 2561, 1761, 63, 5568, 26, 283, 1604, 1039, 283, 1606, 63, 1842, 356, 2034, 63, 1842, 12, 1039, 283, 1761, 63, 5568, 356, 11727, 63, 5568, 12, 1039, 283, 17, 356, 413, 12, 1128, 789, 202, 199, 22793, 275, 2274, 14, 24265, 63, 1450, 360, 2113, 15, 22793, 14, 1360, 7533, 22793, 9, 2999, 199, 318, 754, 63, 2139, 8, 429, 304, 1128, 408, 1128, 21687, 314, 769, 2763, 2323, 14, 1128, 408, 1128, 4237, 63, 3291, 275, 824, 14, 3892, 63, 3291, 2958, 367, 284, 12, 901, 63, 354, 315, 3874, 8, 429, 14, 513, 63, 2918, 304, 1039, 1406, 12, 1921, 275, 1768, 63, 509, 63, 698, 8, 698, 63, 354, 12, 824, 14, 1238, 12, 1675, 1402, 63, 2113, 275, 824, 14, 1238, 63, 2113, 12, 1675, 372, 63, 962, 275, 715, 1039, 776, 1039, 340, 1921, 26, 1675, 327, 340, 314, 901, 365, 314, 1595, 24190, 26, 949, 13351, 436, 4539, 1021, 1675, 340, 901, 63, 354, 508, 283, 1287, 63, 13456, 356, 2628, 1995, 469, 4906, 298, 505, 582, 1406, 12, 4906, 298, 533, 63 ]
[ 2197, 2999, 199, 504, 1639, 14, 2190, 492, 2202, 202, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1974, 492, 4237, 63, 698, 12, 2929, 63, 509, 63, 698, 12, 1768, 63, 509, 63, 698, 202, 199, 504, 1639, 14, 2828, 14, 2113, 14, 4196, 14, 973, 492, 11727, 63, 5568, 12, 16589, 63, 16062, 4924, 63, 7041, 202, 199, 504, 1639, 14, 2828, 14, 2113, 14, 4196, 14, 973, 492, 16044, 63, 5568, 12, 16044, 63, 2711, 63, 5568, 12, 510, 2962, 63, 5568, 12, 5795, 7762, 63, 5568, 202, 199, 504, 1639, 14, 1018, 14, 3924, 492, 24803, 202, 199, 504, 1639, 14, 697, 492, 1709, 202, 199, 504, 1639, 14, 1208, 492, 6752, 202, 199, 504, 1639, 14, 1208, 14, 1360, 492, 4772, 12, 12303, 63, 3765, 202, 199, 504, 1639, 14, 1208, 14, 28389, 492, 2216, 63, 3489, 202, 199, 504, 1639, 14, 1208, 14, 505, 492, 4021, 2246, 202, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 465, 485, 202, 199, 504, 1639, 14, 1208, 14, 2991, 492, 11179, 63, 2975, 12, 3542, 63, 2975, 202, 199, 504, 1639, 14, 1160, 492, 11243, 8065, 199, 2683, 275, 11243, 342, 2999, 199, 13203, 275, 7815, 2999, 199, 318, 21398, 63, 1955, 8, 429, 12, 73, 304, 1128, 408, 1128, 21687, 376, 8212, 2034, 1478, 2142, 315, 282, 9881, 23831, 769, 14, 1128, 408, 1128, 340, 284, 508, 15854, 26, 1039, 372, 399, 7, 1396, 283, 1128, 916, 284, 508, 824, 14, 1606, 63, 1507, 26, 1039, 372, 2216, 63, 3489, 8, 85, 7601, 3751, 1021, 628, 3749, 13, 1606, 14423, 68, 1108, 3751, 30, 283, 450, 334, 73, 11, 17, 430, 1128, 587, 26, 1039, 372, 2216, 63, 3489, 8, 85, 7601, 65, 4369, 5961, 83, 6808, 83, 6598, 68, 1108, 65, 30, 283, 450, 334, 3765, 8, 429, 14, 362, 63, 1131, 63, 875, 2561, 12898, 63, 5568, 26, 284, 1552, 395, 334, 73, 508, 824, 14, 22073, 14, 1507, 63, 5856, 13, 17, 436, 283, 1021, 628, 500, 4507, 503, 9929, 284, 11, 17, 430, 202, 199, 22073, 63, 1955, 275, 2274, 14, 4129, 63, 1450, 8, 22073, 63, 1955, 9, 2999, 199, 318, 21192, 8, 429, 304, 1128, 408, 1128, 21687, 314, 6779, 402, 6220, 370, 314, 6497, 315, 282, 9881, 23831, 769, 14, 1128, 408, 1128, 21398, 12, 2034, 63, 1507, 275, 824, 14, 22073, 12, 824, 14, 1606, 63, 1507, 2958, 21192, 63, 2427, 275, 334, 1397, 824, 14, 2384, 63, 452, 503, 440, 824, 14, 2425, 63, 2384, 63, 452, 9, 436, 824, 14, 3029, 63, 1606, 1128, 340, 440, 21192, 63, 2427, 26, 1039, 2034, 63, 1842, 275, 942, 1128, 587, 26, 1039, 5258, 63, 11765, 1244, 63, 28035, 275, 650, 1039, 5258, 63, 20853, 275, 499, 4341, 327, 982, 2337, 787, 1616, 503, 27392, 6497, 12, 2929, 6220, 370, 4036, 2034, 14, 1039, 327, 6630, 12, 886, 2005, 27571, 1039, 340, 21398, 14, 1507, 63, 5856, 2695, 1616, 26, 1675, 2034, 63, 1842, 275, 1425, 8, 22073, 14, 1507, 63, 5856, 9, 1039, 587, 26, 1675, 327, 15496, 298, 7853, 2, 21192, 6220, 12, 880, 626, 2337, 787, 3544, 5258, 63, 20853, 1675, 327, 6220, 737, 1902, 1284, 402, 314, 769, 402, 6497, 12, 436, 2337, 787, 3544, 1675, 327, 5258, 63, 11765, 1244, 63, 28035, 6220, 737, 1902, 1284, 402, 314, 298, 1818, 2034, 2, 2142, 14, 1675, 2034, 63, 1842, 275, 942, 1675, 340, 2034, 63, 1507, 690, 334, 615, 63, 11765, 1244, 63, 28035, 435, 5258, 63, 20853, 304, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 16, 12, 5258, 63, 11765, 1244, 63, 28035, 446, 413, 430, 2628, 2034, 63, 1842, 14, 740, 8, 13203, 9, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 446, 5258, 63, 11765, 1244, 63, 28035, 12, 2034, 63, 1507, 435, 413, 430, 1675, 587, 26, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 16, 12, 2034, 63, 1507, 435, 413, 430, 1675, 340, 2034, 63, 1507, 665, 334, 22073, 14, 1507, 63, 5856, 446, 5258, 63, 11765, 1244, 63, 28035, 446, 5258, 63, 20853, 446, 413, 304, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 435, 413, 12, 2034, 63, 1507, 435, 5258, 63, 11765, 1244, 63, 28035, 435, 413, 430, 2628, 2034, 63, 1842, 14, 740, 8, 13203, 9, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 22073, 14, 1507, 63, 5856, 446, 5258, 63, 20853, 12, 21398, 14, 1507, 63, 5856, 430, 1675, 587, 26, 2628, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 435, 413, 12, 21398, 14, 1507, 63, 5856, 430, 2958, 1929, 63, 2384, 63, 452, 63, 1073, 275, 824, 14, 2425, 63, 2384, 63, 452, 436, 440, 824, 14, 2384, 63, 452, 436, 824, 14, 3029, 63, 1606, 1128, 372, 469, 1039, 283, 429, 356, 824, 12, 1039, 283, 22793, 63, 2427, 356, 21192, 63, 2427, 12, 1039, 283, 2384, 63, 452, 63, 633, 356, 1929, 63, 2384, 63, 452, 63, 1073, 436, 824, 14, 362, 63, 1131, 63, 875, 2561, 1761, 63, 5568, 26, 283, 1604, 1039, 283, 1606, 63, 1842, 356, 2034, 63, 1842, 12, 1039, 283, 1761, 63, 5568, 356, 11727, 63, 5568, 12, 1039, 283, 17, 356, 413, 12, 1128, 789, 202, 199, 22793, 275, 2274, 14, 24265, 63, 1450, 360, 2113, 15, 22793, 14, 1360, 7533, 22793, 9, 2999, 199, 318, 754, 63, 2139, 8, 429, 304, 1128, 408, 1128, 21687, 314, 769, 2763, 2323, 14, 1128, 408, 1128, 4237, 63, 3291, 275, 824, 14, 3892, 63, 3291, 2958, 367, 284, 12, 901, 63, 354, 315, 3874, 8, 429, 14, 513, 63, 2918, 304, 1039, 1406, 12, 1921, 275, 1768, 63, 509, 63, 698, 8, 698, 63, 354, 12, 824, 14, 1238, 12, 1675, 1402, 63, 2113, 275, 824, 14, 1238, 63, 2113, 12, 1675, 372, 63, 962, 275, 715, 1039, 776, 1039, 340, 1921, 26, 1675, 327, 340, 314, 901, 365, 314, 1595, 24190, 26, 949, 13351, 436, 4539, 1021, 1675, 340, 901, 63, 354, 508, 283, 1287, 63, 13456, 356, 2628, 1995, 469, 4906, 298, 505, 582, 1406, 12, 4906, 298, 533, 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, 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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 ]
emonty/pyos
samples/cloud_databases/list_flavors.py
1
1110
#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c)2012 Rackspace US, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from __future__ import print_function import os import sys import pyos pyos.set_setting("identity_type", "rackspace") creds_file = os.path.expanduser("~/.rackspace_cloud_credentials") pyos.set_credential_file(creds_file) cdb = pyos.cloud_databases flavors = cdb.list_flavors() print() print("Available Flavors:") for flavor in flavors: print("Name: %s; RAM: %s, ID: %s" % (flavor.name, flavor.ram, flavor.id)) print()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 1898, 334, 67, 9, 7409, 32679, 19635, 12, 3277, 14, 199, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 199, 646, 984, 199, 199, 646, 1134, 736, 199, 199, 647, 736, 14, 409, 63, 6031, 480, 5582, 63, 466, 401, 298, 8085, 2638, 531, 199, 15226, 63, 493, 275, 747, 14, 515, 14, 12131, 20793, 8083, 8085, 2638, 63, 4091, 63, 6942, 531, 199, 647, 736, 14, 409, 63, 15591, 63, 493, 8, 15226, 63, 493, 9, 199, 24035, 275, 1134, 736, 14, 4091, 63, 17439, 199, 199, 18664, 275, 286, 697, 14, 513, 63, 18664, 342, 199, 1361, 342, 199, 1361, 480, 11464, 481, 13579, 9107, 199, 509, 8541, 315, 23547, 26, 272, 870, 480, 985, 26, 450, 83, 27, 30207, 26, 450, 83, 12, 2870, 26, 450, 83, 2, 450, 334, 6081, 14, 354, 12, 8541, 14, 5975, 12, 8541, 14, 344, 430, 199, 1361, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 1898, 334, 67, 9, 7409, 32679, 19635, 12, 3277, 14, 199, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 199, 646, 984, 199, 199, 646, 1134, 736, 199, 199, 647, 736, 14, 409, 63, 6031, 480, 5582, 63, 466, 401, 298, 8085, 2638, 531, 199, 15226, 63, 493, 275, 747, 14, 515, 14, 12131, 20793, 8083, 8085, 2638, 63, 4091, 63, 6942, 531, 199, 647, 736, 14, 409, 63, 15591, 63, 493, 8, 15226, 63, 493, 9, 199, 24035, 275, 1134, 736, 14, 4091, 63, 17439, 199, 199, 18664, 275, 286, 697, 14, 513, 63, 18664, 342, 199, 1361, 342, 199, 1361, 480, 11464, 481, 13579, 9107, 199, 509, 8541, 315, 23547, 26, 272, 870, 480, 985, 26, 450, 83, 27, 30207, 26, 450, 83, 12, 2870, 26, 450, 83, 2, 450, 334, 6081, 14, 354, 12, 8541, 14, 5975, 12, 8541, 14, 344, 430, 199, 1361, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
sou81821/chainer
tests/chainer_tests/functions_tests/activation_tests/test_clipped_relu.py
11
2171
import unittest import numpy import chainer from chainer import cuda from chainer import functions from chainer import gradient_check from chainer import testing from chainer.testing import attr class TestClippedReLU(unittest.TestCase): def setUp(self): self.x = numpy.random.uniform(-1, 1, (3, 2)).astype(numpy.float32) # Avoid values around zero and z for stability of numerical gradient for i in range(self.x.size): if -0.01 < self.x.flat[i] < 0.01 or 0.74 < self.x.flat[i] < 0.76: self.x.flat[i] = 0.5 self.gy = numpy.random.uniform(-1, 1, (3, 2)).astype(numpy.float32) self.z = 0.75 def check_forward(self, x_data): x = chainer.Variable(x_data) y = functions.clipped_relu(x, self.z) self.assertEqual(y.data.dtype, numpy.float32) y_expect = self.x.copy() for i in numpy.ndindex(self.x.shape): if self.x[i] < 0: y_expect[i] = 0 elif self.x[i] > self.z: y_expect[i] = self.z gradient_check.assert_allclose(y_expect, y.data) def test_forward_cpu(self): self.check_forward(self.x) @attr.gpu def test_forward_gpu(self): self.check_forward(cuda.to_gpu(self.x)) def check_backward(self, x_data, y_grad): x = chainer.Variable(x_data) y = functions.clipped_relu(x, self.z) self.assertEqual(y.data.dtype, numpy.float32) y.grad = y_grad y.backward() func = y.creator f = lambda: func.forward((x.data,)) gx, = gradient_check.numerical_grad(f, (x.data,), (y.grad,)) gradient_check.assert_allclose(gx, x.grad) def test_backward_cpu(self): self.check_backward(self.x, self.gy) @attr.gpu def test_backward_gpu(self): self.check_backward(cuda.to_gpu(self.x), cuda.to_gpu(self.gy)) class TestClippedReLUZeroDim(TestClippedReLU): def setUp(self): self.x = numpy.random.uniform(-1, 1, ()).astype(numpy.float32) self.gy = numpy.random.uniform(-1, 1, ()).astype(numpy.float32) self.z = 0.75 testing.run_module(__name__, __file__)
mit
[ 646, 2882, 199, 199, 646, 2680, 199, 199, 646, 20333, 199, 504, 20333, 492, 23123, 199, 504, 20333, 492, 3423, 199, 504, 20333, 492, 6709, 63, 1074, 199, 504, 20333, 492, 5343, 199, 504, 20333, 14, 4776, 492, 1921, 421, 199, 533, 1379, 17492, 1915, 497, 20237, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 88, 275, 2680, 14, 2355, 14, 8830, 2801, 17, 12, 413, 12, 334, 19, 12, 499, 4992, 6041, 8, 4714, 14, 1609, 708, 9, 267, 327, 19503, 1338, 6818, 4697, 436, 1315, 367, 410, 3616, 402, 15470, 6709, 267, 367, 284, 315, 1425, 8, 277, 14, 88, 14, 890, 304, 288, 340, 446, 16, 14, 614, 665, 291, 14, 88, 14, 7088, 59, 73, 61, 665, 378, 14, 614, 503, 378, 14, 1342, 665, 291, 14, 88, 14, 7088, 59, 73, 61, 665, 378, 14, 2114, 26, 355, 291, 14, 88, 14, 7088, 59, 73, 61, 275, 378, 14, 21, 267, 291, 14, 4312, 275, 2680, 14, 2355, 14, 8830, 2801, 17, 12, 413, 12, 334, 19, 12, 499, 4992, 6041, 8, 4714, 14, 1609, 708, 9, 267, 291, 14, 90, 275, 378, 14, 2194, 339, 347, 1104, 63, 6688, 8, 277, 12, 671, 63, 576, 304, 267, 671, 275, 20333, 14, 2773, 8, 88, 63, 576, 9, 267, 612, 275, 3423, 14, 7548, 1915, 63, 12833, 8, 88, 12, 291, 14, 90, 9, 267, 291, 14, 629, 8, 89, 14, 576, 14, 2271, 12, 2680, 14, 1609, 708, 9, 398, 612, 63, 4921, 275, 291, 14, 88, 14, 1574, 342, 267, 367, 284, 315, 2680, 14, 977, 1080, 8, 277, 14, 88, 14, 1392, 304, 288, 340, 291, 14, 88, 59, 73, 61, 665, 378, 26, 355, 612, 63, 4921, 59, 73, 61, 275, 378, 288, 916, 291, 14, 88, 59, 73, 61, 690, 291, 14, 90, 26, 355, 612, 63, 4921, 59, 73, 61, 275, 291, 14, 90, 398, 6709, 63, 1074, 14, 479, 63, 7520, 8, 89, 63, 4921, 12, 612, 14, 576, 9, 339, 347, 511, 63, 6688, 63, 3541, 8, 277, 304, 267, 291, 14, 1074, 63, 6688, 8, 277, 14, 88, 9, 339, 768, 962, 14, 6477, 272, 347, 511, 63, 6688, 63, 6477, 8, 277, 304, 267, 291, 14, 1074, 63, 6688, 8, 16309, 14, 475, 63, 6477, 8, 277, 14, 88, 430, 339, 347, 1104, 63, 15457, 8, 277, 12, 671, 63, 576, 12, 612, 63, 6017, 304, 267, 671, 275, 20333, 14, 2773, 8, 88, 63, 576, 9, 267, 612, 275, 3423, 14, 7548, 1915, 63, 12833, 8, 88, 12, 291, 14, 90, 9, 267, 291, 14, 629, 8, 89, 14, 576, 14, 2271, 12, 2680, 14, 1609, 708, 9, 267, 612, 14, 6017, 275, 612, 63, 6017, 267, 612, 14, 15457, 342, 398, 2562, 275, 612, 14, 9986, 267, 289, 275, 2400, 26, 2562, 14, 6688, 1332, 88, 14, 576, 4641, 267, 486, 88, 12, 275, 6709, 63, 1074, 14, 10563, 8825, 63, 6017, 8, 70, 12, 334, 88, 14, 576, 4706, 334, 89, 14, 6017, 4641, 398, 6709, 63, 1074, 14, 479, 63, 7520, 8, 20777, 12, 671, 14, 6017, 9, 339, 347, 511, 63, 15457, 63, 3541, 8, 277, 304, 267, 291, 14, 1074, 63, 15457, 8, 277, 14, 88, 12, 291, 14, 4312, 9, 339, 768, 962, 14, 6477, 272, 347, 511, 63, 15457, 63, 6477, 8, 277, 304, 267, 291, 14, 1074, 63, 15457, 8, 16309, 14, 475, 63, 6477, 8, 277, 14, 88, 395, 23123, 14, 475, 63, 6477, 8, 277, 14, 4312, 430, 421, 199, 533, 1379, 17492, 1915, 497, 20237, 8681, 19156, 8, 774, 17492, 1915, 497, 20237, 304, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 88, 275, 2680, 14, 2355, 14, 8830, 2801, 17, 12, 413, 12, 334, 4992, 6041, 8, 4714, 14, 1609, 708, 9, 267, 291, 14, 4312, 275, 2680, 14, 2355, 14, 8830, 2801, 17, 12, 413, 12, 334, 4992, 6041, 8, 4714, 14, 1609, 708, 9, 267, 291, 14, 90, 275, 378, 14, 2194, 199, 199, 4776, 14, 1065, 63, 578, 3460, 354, 3108, 636, 493, 3368, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2882, 199, 199, 646, 2680, 199, 199, 646, 20333, 199, 504, 20333, 492, 23123, 199, 504, 20333, 492, 3423, 199, 504, 20333, 492, 6709, 63, 1074, 199, 504, 20333, 492, 5343, 199, 504, 20333, 14, 4776, 492, 1921, 421, 199, 533, 1379, 17492, 1915, 497, 20237, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 88, 275, 2680, 14, 2355, 14, 8830, 2801, 17, 12, 413, 12, 334, 19, 12, 499, 4992, 6041, 8, 4714, 14, 1609, 708, 9, 267, 327, 19503, 1338, 6818, 4697, 436, 1315, 367, 410, 3616, 402, 15470, 6709, 267, 367, 284, 315, 1425, 8, 277, 14, 88, 14, 890, 304, 288, 340, 446, 16, 14, 614, 665, 291, 14, 88, 14, 7088, 59, 73, 61, 665, 378, 14, 614, 503, 378, 14, 1342, 665, 291, 14, 88, 14, 7088, 59, 73, 61, 665, 378, 14, 2114, 26, 355, 291, 14, 88, 14, 7088, 59, 73, 61, 275, 378, 14, 21, 267, 291, 14, 4312, 275, 2680, 14, 2355, 14, 8830, 2801, 17, 12, 413, 12, 334, 19, 12, 499, 4992, 6041, 8, 4714, 14, 1609, 708, 9, 267, 291, 14, 90, 275, 378, 14, 2194, 339, 347, 1104, 63, 6688, 8, 277, 12, 671, 63, 576, 304, 267, 671, 275, 20333, 14, 2773, 8, 88, 63, 576, 9, 267, 612, 275, 3423, 14, 7548, 1915, 63, 12833, 8, 88, 12, 291, 14, 90, 9, 267, 291, 14, 629, 8, 89, 14, 576, 14, 2271, 12, 2680, 14, 1609, 708, 9, 398, 612, 63, 4921, 275, 291, 14, 88, 14, 1574, 342, 267, 367, 284, 315, 2680, 14, 977, 1080, 8, 277, 14, 88, 14, 1392, 304, 288, 340, 291, 14, 88, 59, 73, 61, 665, 378, 26, 355, 612, 63, 4921, 59, 73, 61, 275, 378, 288, 916, 291, 14, 88, 59, 73, 61, 690, 291, 14, 90, 26, 355, 612, 63, 4921, 59, 73, 61, 275, 291, 14, 90, 398, 6709, 63, 1074, 14, 479, 63, 7520, 8, 89, 63, 4921, 12, 612, 14, 576, 9, 339, 347, 511, 63, 6688, 63, 3541, 8, 277, 304, 267, 291, 14, 1074, 63, 6688, 8, 277, 14, 88, 9, 339, 768, 962, 14, 6477, 272, 347, 511, 63, 6688, 63, 6477, 8, 277, 304, 267, 291, 14, 1074, 63, 6688, 8, 16309, 14, 475, 63, 6477, 8, 277, 14, 88, 430, 339, 347, 1104, 63, 15457, 8, 277, 12, 671, 63, 576, 12, 612, 63, 6017, 304, 267, 671, 275, 20333, 14, 2773, 8, 88, 63, 576, 9, 267, 612, 275, 3423, 14, 7548, 1915, 63, 12833, 8, 88, 12, 291, 14, 90, 9, 267, 291, 14, 629, 8, 89, 14, 576, 14, 2271, 12, 2680, 14, 1609, 708, 9, 267, 612, 14, 6017, 275, 612, 63, 6017, 267, 612, 14, 15457, 342, 398, 2562, 275, 612, 14, 9986, 267, 289, 275, 2400, 26, 2562, 14, 6688, 1332, 88, 14, 576, 4641, 267, 486, 88, 12, 275, 6709, 63, 1074, 14, 10563, 8825, 63, 6017, 8, 70, 12, 334, 88, 14, 576, 4706, 334, 89, 14, 6017, 4641, 398, 6709, 63, 1074, 14, 479, 63, 7520, 8, 20777, 12, 671, 14, 6017, 9, 339, 347, 511, 63, 15457, 63, 3541, 8, 277, 304, 267, 291, 14, 1074, 63, 15457, 8, 277, 14, 88, 12, 291, 14, 4312, 9, 339, 768, 962, 14, 6477, 272, 347, 511, 63, 15457, 63, 6477, 8, 277, 304, 267, 291, 14, 1074, 63, 15457, 8, 16309, 14, 475, 63, 6477, 8, 277, 14, 88, 395, 23123, 14, 475, 63, 6477, 8, 277, 14, 4312, 430, 421, 199, 533, 1379, 17492, 1915, 497, 20237, 8681, 19156, 8, 774, 17492, 1915, 497, 20237, 304, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 88, 275, 2680, 14, 2355, 14, 8830, 2801, 17, 12, 413, 12, 334, 4992, 6041, 8, 4714, 14, 1609, 708, 9, 267, 291, 14, 4312, 275, 2680, 14, 2355, 14, 8830, 2801, 17, 12, 413, 12, 334, 4992, 6041, 8, 4714, 14, 1609, 708, 9, 267, 291, 14, 90, 275, 378, 14, 2194, 199, 199, 4776, 14, 1065, 63, 578, 3460, 354, 3108, 636, 493, 3368, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
amitsela/beam
sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset.py
9
4504
# # 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. # """A Julia set computing workflow: https://en.wikipedia.org/wiki/Julia_set. We use the quadratic polinomial f(z) = z*z + c, with c = -.62772 +.42193i """ from __future__ import absolute_import import argparse import apache_beam as beam from apache_beam.io import WriteToText def from_pixel(x, y, n): """Converts a NxN pixel position to a (-1..1, -1..1) complex number.""" return complex(2.0 * x / n - 1.0, 2.0 * y / n - 1.0) def get_julia_set_point_color(element, c, n, max_iterations): """Given an pixel, convert it into a point in our julia set.""" x, y = element z = from_pixel(x, y, n) for i in xrange(max_iterations): if z.real * z.real + z.imag * z.imag > 2.0: break z = z * z + c return x, y, i # pylint: disable=undefined-loop-variable def generate_julia_set_colors(pipeline, c, n, max_iterations): """Compute julia set coordinates for each point in our set.""" def point_set(n): for x in range(n): for y in range(n): yield (x, y) julia_set_colors = (pipeline | 'add points' >> beam.Create(point_set(n)) | beam.Map( get_julia_set_point_color, c, n, max_iterations)) return julia_set_colors def generate_julia_set_visualization(data, n, max_iterations): """Generate the pixel matrix for rendering the julia set as an image.""" import numpy as np # pylint: disable=wrong-import-order, wrong-import-position colors = [] for r in range(0, 256, 16): for g in range(0, 256, 16): for b in range(0, 256, 16): colors.append((r, g, b)) xy = np.zeros((n, n, 3), dtype=np.uint8) for x, y, iteration in data: xy[x, y] = colors[iteration * len(colors) / max_iterations] return xy def save_julia_set_visualization(out_file, image_array): """Save the fractal image of our julia set as a png.""" from matplotlib import pyplot as plt # pylint: disable=wrong-import-order, wrong-import-position plt.imsave(out_file, image_array, format='png') def run(argv=None): # pylint: disable=missing-docstring parser = argparse.ArgumentParser() parser.add_argument('--grid_size', dest='grid_size', default=1000, help='Size of the NxN matrix') parser.add_argument( '--coordinate_output', dest='coordinate_output', required=True, help='Output file to write the color coordinates of the image to.') parser.add_argument('--image_output', dest='image_output', default=None, help='Output file to write the resulting image to.') known_args, pipeline_args = parser.parse_known_args(argv) p = beam.Pipeline(argv=pipeline_args) n = int(known_args.grid_size) coordinates = generate_julia_set_colors(p, complex(-.62772, .42193), n, 100) # Group each coordinate triplet by its x value, then write the coordinates to # the output file with an x-coordinate grouping per line. # pylint: disable=expression-not-assigned (coordinates | 'x coord key' >> beam.Map(lambda (x, y, i): (x, (x, y, i))) | 'x coord' >> beam.GroupByKey() | 'format' >> beam.Map( lambda (k, coords): ' '.join('(%s, %s, %s)' % coord for coord in coords)) | WriteToText(known_args.coordinate_output)) # pylint: enable=expression-not-assigned return p.run().wait_until_finish() # Optionally render the image and save it to a file. # TODO(silviuc): Add this functionality. # if p.options.image_output is not None: # julia_set_image = generate_julia_set_visualization( # file_with_coordinates, n, 100) # save_julia_set_visualization(p.options.image_output, julia_set_image)
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, 624, 33, 1603, 13987, 65, 663, 17226, 10431, 26, 4178, 921, 287, 14, 13961, 14, 1308, 15, 6797, 15, 42, 13987, 65, 63, 409, 14, 199, 199, 6004, 675, 314, 16744, 19826, 3708, 16956, 289, 8, 90, 9, 275, 1315, 10, 90, 435, 286, 12, 543, 286, 275, 3568, 2789, 19518, 435, 14, 2260, 13015, 73, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 7534, 199, 199, 646, 17098, 63, 14529, 465, 17453, 199, 504, 17098, 63, 14529, 14, 2308, 492, 6990, 1378, 1872, 421, 199, 318, 687, 63, 8435, 8, 88, 12, 612, 12, 302, 304, 523, 408, 17729, 282, 653, 31985, 7148, 3421, 370, 282, 5868, 17, 703, 17, 12, 446, 17, 703, 17, 9, 6114, 1329, 1041, 523, 372, 6114, 8, 18, 14, 16, 627, 671, 1182, 302, 446, 413, 14, 16, 12, 499, 14, 16, 627, 612, 1182, 302, 446, 413, 14, 16, 9, 421, 199, 318, 664, 63, 74, 13987, 65, 63, 409, 63, 1403, 63, 2326, 8, 2108, 12, 286, 12, 302, 12, 1390, 63, 13570, 304, 523, 408, 13735, 376, 7148, 12, 3957, 652, 1901, 282, 2376, 315, 4154, 1335, 13987, 65, 663, 1041, 523, 671, 12, 612, 275, 1819, 523, 1315, 275, 687, 63, 8435, 8, 88, 12, 612, 12, 302, 9, 523, 367, 284, 315, 4945, 8, 988, 63, 13570, 304, 272, 340, 1315, 14, 3093, 627, 1315, 14, 3093, 435, 1315, 14, 14688, 627, 1315, 14, 14688, 690, 499, 14, 16, 26, 489, 2059, 272, 1315, 275, 1315, 627, 1315, 435, 286, 523, 372, 671, 12, 612, 12, 284, 221, 327, 4287, 26, 3507, 29, 10705, 13, 3813, 13, 1975, 421, 199, 318, 3550, 63, 74, 13987, 65, 63, 409, 63, 7120, 8, 7379, 12, 286, 12, 302, 12, 1390, 63, 13570, 304, 523, 408, 8564, 1335, 13987, 65, 663, 8983, 367, 1924, 2376, 315, 4154, 663, 1041, 523, 347, 2376, 63, 409, 8, 78, 304, 272, 367, 671, 315, 1425, 8, 78, 304, 489, 367, 612, 315, 1425, 8, 78, 304, 267, 1995, 334, 88, 12, 612, 9, 819, 1335, 13987, 65, 63, 409, 63, 7120, 275, 334, 7379, 1993, 1204, 283, 525, 4501, 7, 4331, 17453, 14, 2499, 8, 1403, 63, 409, 8, 78, 430, 1993, 1204, 17453, 14, 2956, 8, 2079, 664, 63, 74, 13987, 65, 63, 409, 63, 1403, 63, 2326, 12, 286, 12, 302, 12, 1390, 63, 13570, 430, 819, 372, 1335, 13987, 65, 63, 409, 63, 7120, 421, 199, 318, 3550, 63, 74, 13987, 65, 63, 409, 63, 16948, 2072, 8, 576, 12, 302, 12, 1390, 63, 13570, 304, 523, 408, 6864, 314, 7148, 3634, 367, 14066, 314, 1335, 13987, 65, 663, 465, 376, 1834, 1041, 523, 492, 2680, 465, 980, 221, 327, 4287, 26, 3507, 29, 10603, 13, 646, 13, 1648, 12, 6835, 13, 646, 13, 3124, 523, 9229, 275, 942, 523, 367, 519, 315, 1425, 8, 16, 12, 7633, 12, 3193, 304, 272, 367, 486, 315, 1425, 8, 16, 12, 7633, 12, 3193, 304, 489, 367, 330, 315, 1425, 8, 16, 12, 7633, 12, 3193, 304, 267, 9229, 14, 740, 1332, 82, 12, 486, 12, 330, 430, 819, 13222, 275, 980, 14, 4250, 1332, 78, 12, 302, 12, 650, 395, 2152, 29, 1590, 14, 1635, 24, 9, 523, 367, 671, 12, 612, 12, 8494, 315, 666, 26, 272, 13222, 59, 88, 12, 612, 61, 275, 9229, 59, 12575, 627, 822, 8, 7120, 9, 1182, 1390, 63, 13570, 61, 819, 372, 13222, 421, 199, 318, 3354, 63, 74, 13987, 65, 63, 409, 63, 16948, 2072, 8, 548, 63, 493, 12, 1834, 63, 1144, 304, 523, 408, 8229, 314, 289, 1957, 279, 1834, 402, 4154, 1335, 13987, 65, 663, 465, 282, 25296, 1041, 523, 687, 8027, 492, 1134, 2798, 465, 4488, 221, 327, 4287, 26, 3507, 29, 10603, 13, 646, 13, 1648, 12, 6835, 13, 646, 13, 3124, 523, 4488, 14, 11171, 811, 8, 548, 63, 493, 12, 1834, 63, 1144, 12, 1475, 534, 4524, 358, 421, 199, 318, 1255, 8, 3020, 29, 403, 304, 221, 327, 4287, 26, 3507, 29, 4752, 13, 12485, 819, 1798, 275, 7534, 14, 10730, 342, 523, 1798, 14, 525, 63, 2094, 4517, 3825, 63, 890, 297, 1993, 2053, 534, 3825, 63, 890, 297, 1993, 849, 29, 5279, 12, 1993, 1720, 534, 2320, 402, 314, 653, 31985, 3634, 358, 523, 1798, 14, 525, 63, 2094, 8, 489, 2850, 20493, 63, 1199, 297, 489, 2053, 534, 20493, 63, 1199, 297, 489, 1415, 29, 549, 12, 489, 1720, 534, 2959, 570, 370, 2218, 314, 3164, 8983, 402, 314, 1834, 370, 2659, 523, 1798, 14, 525, 63, 2094, 4517, 1569, 63, 1199, 297, 1993, 2053, 534, 1569, 63, 1199, 297, 1993, 849, 29, 403, 12, 1993, 1720, 534, 2959, 570, 370, 2218, 314, 9183, 1834, 370, 2659, 523, 6040, 63, 589, 12, 7679, 63, 589, 275, 1798, 14, 1122, 63, 3159, 63, 589, 8, 3020, 9, 819, 299, 275, 17453, 14, 17562, 8, 3020, 29, 7379, 63, 589, 9, 523, 302, 275, 1109, 8, 3159, 63, 589, 14, 3825, 63, 890, 9, 819, 8983, 275, 3550, 63, 74, 13987 ]
[ 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, 624, 33, 1603, 13987, 65, 663, 17226, 10431, 26, 4178, 921, 287, 14, 13961, 14, 1308, 15, 6797, 15, 42, 13987, 65, 63, 409, 14, 199, 199, 6004, 675, 314, 16744, 19826, 3708, 16956, 289, 8, 90, 9, 275, 1315, 10, 90, 435, 286, 12, 543, 286, 275, 3568, 2789, 19518, 435, 14, 2260, 13015, 73, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 7534, 199, 199, 646, 17098, 63, 14529, 465, 17453, 199, 504, 17098, 63, 14529, 14, 2308, 492, 6990, 1378, 1872, 421, 199, 318, 687, 63, 8435, 8, 88, 12, 612, 12, 302, 304, 523, 408, 17729, 282, 653, 31985, 7148, 3421, 370, 282, 5868, 17, 703, 17, 12, 446, 17, 703, 17, 9, 6114, 1329, 1041, 523, 372, 6114, 8, 18, 14, 16, 627, 671, 1182, 302, 446, 413, 14, 16, 12, 499, 14, 16, 627, 612, 1182, 302, 446, 413, 14, 16, 9, 421, 199, 318, 664, 63, 74, 13987, 65, 63, 409, 63, 1403, 63, 2326, 8, 2108, 12, 286, 12, 302, 12, 1390, 63, 13570, 304, 523, 408, 13735, 376, 7148, 12, 3957, 652, 1901, 282, 2376, 315, 4154, 1335, 13987, 65, 663, 1041, 523, 671, 12, 612, 275, 1819, 523, 1315, 275, 687, 63, 8435, 8, 88, 12, 612, 12, 302, 9, 523, 367, 284, 315, 4945, 8, 988, 63, 13570, 304, 272, 340, 1315, 14, 3093, 627, 1315, 14, 3093, 435, 1315, 14, 14688, 627, 1315, 14, 14688, 690, 499, 14, 16, 26, 489, 2059, 272, 1315, 275, 1315, 627, 1315, 435, 286, 523, 372, 671, 12, 612, 12, 284, 221, 327, 4287, 26, 3507, 29, 10705, 13, 3813, 13, 1975, 421, 199, 318, 3550, 63, 74, 13987, 65, 63, 409, 63, 7120, 8, 7379, 12, 286, 12, 302, 12, 1390, 63, 13570, 304, 523, 408, 8564, 1335, 13987, 65, 663, 8983, 367, 1924, 2376, 315, 4154, 663, 1041, 523, 347, 2376, 63, 409, 8, 78, 304, 272, 367, 671, 315, 1425, 8, 78, 304, 489, 367, 612, 315, 1425, 8, 78, 304, 267, 1995, 334, 88, 12, 612, 9, 819, 1335, 13987, 65, 63, 409, 63, 7120, 275, 334, 7379, 1993, 1204, 283, 525, 4501, 7, 4331, 17453, 14, 2499, 8, 1403, 63, 409, 8, 78, 430, 1993, 1204, 17453, 14, 2956, 8, 2079, 664, 63, 74, 13987, 65, 63, 409, 63, 1403, 63, 2326, 12, 286, 12, 302, 12, 1390, 63, 13570, 430, 819, 372, 1335, 13987, 65, 63, 409, 63, 7120, 421, 199, 318, 3550, 63, 74, 13987, 65, 63, 409, 63, 16948, 2072, 8, 576, 12, 302, 12, 1390, 63, 13570, 304, 523, 408, 6864, 314, 7148, 3634, 367, 14066, 314, 1335, 13987, 65, 663, 465, 376, 1834, 1041, 523, 492, 2680, 465, 980, 221, 327, 4287, 26, 3507, 29, 10603, 13, 646, 13, 1648, 12, 6835, 13, 646, 13, 3124, 523, 9229, 275, 942, 523, 367, 519, 315, 1425, 8, 16, 12, 7633, 12, 3193, 304, 272, 367, 486, 315, 1425, 8, 16, 12, 7633, 12, 3193, 304, 489, 367, 330, 315, 1425, 8, 16, 12, 7633, 12, 3193, 304, 267, 9229, 14, 740, 1332, 82, 12, 486, 12, 330, 430, 819, 13222, 275, 980, 14, 4250, 1332, 78, 12, 302, 12, 650, 395, 2152, 29, 1590, 14, 1635, 24, 9, 523, 367, 671, 12, 612, 12, 8494, 315, 666, 26, 272, 13222, 59, 88, 12, 612, 61, 275, 9229, 59, 12575, 627, 822, 8, 7120, 9, 1182, 1390, 63, 13570, 61, 819, 372, 13222, 421, 199, 318, 3354, 63, 74, 13987, 65, 63, 409, 63, 16948, 2072, 8, 548, 63, 493, 12, 1834, 63, 1144, 304, 523, 408, 8229, 314, 289, 1957, 279, 1834, 402, 4154, 1335, 13987, 65, 663, 465, 282, 25296, 1041, 523, 687, 8027, 492, 1134, 2798, 465, 4488, 221, 327, 4287, 26, 3507, 29, 10603, 13, 646, 13, 1648, 12, 6835, 13, 646, 13, 3124, 523, 4488, 14, 11171, 811, 8, 548, 63, 493, 12, 1834, 63, 1144, 12, 1475, 534, 4524, 358, 421, 199, 318, 1255, 8, 3020, 29, 403, 304, 221, 327, 4287, 26, 3507, 29, 4752, 13, 12485, 819, 1798, 275, 7534, 14, 10730, 342, 523, 1798, 14, 525, 63, 2094, 4517, 3825, 63, 890, 297, 1993, 2053, 534, 3825, 63, 890, 297, 1993, 849, 29, 5279, 12, 1993, 1720, 534, 2320, 402, 314, 653, 31985, 3634, 358, 523, 1798, 14, 525, 63, 2094, 8, 489, 2850, 20493, 63, 1199, 297, 489, 2053, 534, 20493, 63, 1199, 297, 489, 1415, 29, 549, 12, 489, 1720, 534, 2959, 570, 370, 2218, 314, 3164, 8983, 402, 314, 1834, 370, 2659, 523, 1798, 14, 525, 63, 2094, 4517, 1569, 63, 1199, 297, 1993, 2053, 534, 1569, 63, 1199, 297, 1993, 849, 29, 403, 12, 1993, 1720, 534, 2959, 570, 370, 2218, 314, 9183, 1834, 370, 2659, 523, 6040, 63, 589, 12, 7679, 63, 589, 275, 1798, 14, 1122, 63, 3159, 63, 589, 8, 3020, 9, 819, 299, 275, 17453, 14, 17562, 8, 3020, 29, 7379, 63, 589, 9, 523, 302, 275, 1109, 8, 3159, 63, 589, 14, 3825, 63, 890, 9, 819, 8983, 275, 3550, 63, 74, 13987, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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
#!/usr/bin/env python # -*- coding: utf-8 -*- #------------------------------------------------------------ # pelisalacarta - XBMC Plugin # Conector para cineraculo (genera vinculos desde videos de megaupload) # http://blog.tvalacarta.info/plugin-xbmc/pelisalacarta/ #------------------------------------------------------------ import urlparse,urllib2,urllib,re import sys,os,traceback from core import scrapertools from core import logger from core import config def get_video_url( page_url , premium = False , user="" , password="", video_password="" ): try : logger.info("[cineraculo.py] get_video_url(page_url='%s')" % page_url) ua=['User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7'] referer1=['Referer', 'http://www.cineraculo.com'] referer2=['Referer', 'http://www.cineraculo.com/vermegavideolink.aspx'] data = scrapertools.cache_page("http://www.cineraculo.com/vermegavideolink.aspx", headers=[ua, referer1], timeout=10000) patron = '<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="([^"]+)" />.*?' patron += '<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="([^"]+)"' matches = re.compile(patron,re.DOTALL).findall(data) code1 = urllib.quote(matches[0][0]).replace("/","%2F") code2 = urllib.quote(matches[0][1]).replace("/","%2F") url=urllib.quote(page_url).replace("/","%2F") post = "__VIEWSTATE=%s&__EVENTVALIDATION=%s&txt_megavideo_url=%s&txt_movie_title=&btn_watch=Ver" % (code1,code2,url) data = scrapertools.cache_page("http://www.cineraculo.com/vermegavideolink.aspx", post = post , headers=[ua, referer2], timeout=20000) patron = "unescape\('([^']+)'" matches = re.compile(patron,re.DOTALL).findall(data) text = '' for match in matches: text += urllib.unquote(match) #logger.info("text = " + text) m = re.compile('fromCharCode\(([^\)]+)\)').findall(text) url = "" if m != None and len(m) > 1 : def compute_expr(ex) : op_pos = ex.find('+') if op_pos != -1 : return chr(int(ex[0:op_pos]) + int(ex[op_pos+1:])) op_pos = ex.find('-') if op_pos != -1 : return chr(int(ex[0:op_pos]) - int(ex[op_pos+1:])) return '?' deobfuscated_js = "".join(map(lambda expr : compute_expr(expr), m[1].split(','))) m = re.compile('(http://[^"]+\.flv)"').search(deobfuscated_js) if m != None and m.group(1) != None : url = m.group(1) else: logger.info("URL no encontrada:\n" + deobfuscated_js) if len(url) > 0 : #hash = get_match(url, 's.aspx/([^/]+)/') #mirror = get_match(url, 's.aspx/[^/]+/([^/]+)/') return [["(Free)", url + '|User-Agent=' + ua[1] ]] except Exception as ex : logger.error("[cineracylo.py] Error al obtener la url del flujo: " + str(ex) ) traceback.print_exc(file=sys.stdout) # FIXME: ugly return [] def get_match(data, regex) : match = ""; m = re.search(regex, data) if m != None : match = m.group(1) return match def find_videos(data): import megavideo logger.info("[cineraculo.py] find_videos") return add_videos(megavideo.find_videos(data)) def add_videos(found_videos): logger.info("[cineraculo.py] add_videos") # Filter the found videos with megavideo url filtered_videos = filter( lambda video : video[1].find('www.megavideo.com') > 0 , found_videos) # Map the filtered videos to set a cineraculo server entry on them and return a copy return map( lambda video : ['[Cineraculo]', video[1], 'cineraculo'], filtered_videos)
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 17807, 4559, 199, 3, 4837, 317, 6327, 645, 29549, 446, 1323, 28994, 11349, 199, 3, 445, 368, 630, 12665, 286, 16187, 645, 13957, 334, 2038, 65, 373, 6559, 85, 11560, 18618, 271, 22010, 477, 562, 5294, 5064, 9, 199, 3, 1455, 921, 11486, 14, 84, 637, 645, 29549, 14, 815, 15, 2718, 13, 21382, 15, 321, 317, 6327, 645, 29549, 15, 199, 17807, 4559, 199, 199, 646, 7097, 12, 4078, 18, 12, 4078, 12, 264, 199, 646, 984, 12, 736, 12, 6894, 199, 199, 504, 6170, 492, 28348, 199, 504, 6170, 492, 2512, 199, 504, 6170, 492, 1101, 199, 199, 318, 664, 63, 3722, 63, 633, 8, 2034, 63, 633, 2360, 876, 23481, 275, 756, 2360, 922, 9287, 2360, 2505, 8772, 3991, 63, 2060, 9287, 3461, 272, 862, 520, 267, 2512, 14, 815, 10994, 67, 16187, 645, 13957, 14, 647, 61, 664, 63, 3722, 63, 633, 8, 1606, 63, 633, 9569, 83, 19124, 450, 2034, 63, 633, 9, 13857, 18500, 2968, 1899, 13, 7788, 297, 283, 22285, 15, 21, 14, 16, 334, 3399, 9924, 609, 27, 20619, 10444, 4403, 1323, 1616, 63, 22, 63, 24, 9, 21257, 21666, 15, 25083, 14, 2528, 14, 23, 334, 43, 4943, 12, 2839, 30506, 9, 3394, 15, 21, 14, 17, 14, 18, 428, 2756, 759, 15, 25083, 14, 2528, 14, 23, 418, 267, 25104, 17, 2968, 28900, 297, 283, 1014, 921, 1544, 14, 67, 16187, 645, 13957, 14, 957, 418, 267, 25104, 18, 2968, 28900, 297, 283, 1014, 921, 1544, 14, 67, 16187, 645, 13957, 14, 957, 15, 422, 29073, 5624, 393, 2292, 14, 26146, 418, 267, 666, 275, 28348, 14, 1637, 63, 1606, 480, 1014, 921, 1544, 14, 67, 16187, 645, 13957, 14, 957, 15, 422, 29073, 5624, 393, 2292, 14, 26146, 401, 2323, 1524, 1458, 12, 25104, 17, 467, 2653, 29, 9943, 9, 267, 32500, 275, 2650, 1210, 730, 628, 5642, 2, 536, 628, 363, 12058, 6689, 2, 1305, 628, 363, 12058, 6689, 2, 574, 32391, 7082, 6697, 7, 267, 32500, 847, 2650, 1210, 730, 628, 5642, 2, 536, 628, 363, 8193, 5600, 2594, 2, 1305, 628, 363, 8193, 5600, 2594, 2, 574, 32391, 7, 267, 4450, 275, 295, 14, 2014, 8, 10853, 2641, 12, 264, 14, 16504, 680, 6452, 8, 576, 9, 267, 1233, 17, 275, 4011, 14, 3513, 8, 6742, 59, 16, 1527, 16, 6575, 1814, 4769, 11890, 18, 38, 531, 267, 1233, 18, 275, 4011, 14, 3513, 8, 6742, 59, 16, 1527, 17, 6575, 1814, 4769, 11890, 18, 38, 531, 267, 1166, 29, 4078, 14, 3513, 8, 1606, 63, 633, 680, 1814, 4769, 11890, 18, 38, 531, 267, 2963, 275, 4396, 12058, 6689, 2458, 83, 6, 363, 8193, 5600, 2594, 2458, 83, 6, 2424, 63, 29073, 3722, 63, 633, 2458, 83, 6, 2424, 63, 10888, 63, 1213, 19167, 9633, 63, 6821, 29, 3673, 2, 450, 334, 600, 17, 12, 600, 18, 12, 633, 9, 267, 666, 275, 28348, 14, 1637, 63, 1606, 480, 1014, 921, 1544, 14, 67, 16187, 645, 13957, 14, 957, 15, 422, 29073, 5624, 393, 2292, 14, 26146, 401, 2963, 275, 2963, 2360, 2323, 1524, 1458, 12, 25104, 18, 467, 2653, 29, 27140, 9, 398, 32500, 275, 298, 22726, 60, 360, 7059, 21899, 3171, 2, 267, 4450, 275, 295, 14, 2014, 8, 10853, 2641, 12, 264, 14, 16504, 680, 6452, 8, 576, 9, 267, 1318, 275, 2125, 267, 367, 1336, 315, 4450, 26, 288, 1318, 847, 4011, 14, 12240, 8, 1431, 9, 267, 327, 2921, 14, 815, 480, 505, 275, 298, 435, 1318, 9, 2728, 333, 275, 295, 14, 2014, 360, 504, 1610, 3034, 24805, 21690, 1874, 13439, 9, 1959, 6452, 8, 505, 9, 267, 1166, 275, 3087, 267, 340, 333, 1137, 488, 436, 822, 8, 77, 9, 690, 413, 520, 288, 347, 4526, 63, 3684, 8, 476, 9, 520, 355, 1687, 63, 1712, 275, 444, 14, 1623, 360, 13854, 355, 340, 1687, 63, 1712, 1137, 446, 17, 520, 372, 8678, 8, 442, 8, 476, 59, 16, 26, 411, 63, 1712, 566, 435, 1109, 8, 476, 59, 411, 63, 1712, 11, 17, 16720, 355, 1687, 63, 1712, 275, 444, 14, 1623, 21950, 355, 340, 1687, 63, 1712, 1137, 446, 17, 520, 372, 8678, 8, 442, 8, 476, 59, 16, 26, 411, 63, 1712, 566, 446, 1109, 8, 476, 59, 411, 63, 1712, 11, 17, 16720, 355, 372, 15539, 7846, 477, 2873, 31958, 3153, 63, 3596, 275, 10587, 904, 8, 1130, 8, 2734, 5348, 520, 4526, 63, 3684, 8, 3684, 395, 333, 59, 17, 1055, 1294, 5102, 7058, 288, 333, 275, 295, 14, 2014, 14097, 1014, 921, 25153, 11, 4537, 22753, 2924, 1959, 1733, 8, 2172, 4361, 527, 3153, 63, 3596, 9, 288, 340, 333, 1137, 488, 436, 333, 14, 923, 8, 17, 9, 1137, 488, 520, 1166, 275, 333, 14, 923, 8, 17, 9, 288, 587, 26, 2512, 14, 815, 480, 2632, 949, 655, 17926, 983, 3427, 78, 2, 435, 477, 2873, 31958, 3153, 63, 3596, 9, 2728, 340, 822, 8, 633, 9, 690, 378, 520, 288, 327, 2227, 275, 664, 63, 1431, 8, 633, 12, 283, 83, 14, 26146, 15, 7059, 15251, 2447, 358, 288, 327, 12324, 275, 664, 63, 1431, 8, 633, 12, 283, 83, 14, 26146, 15, 26285, 15, 7059, 15251, 2447, 358, 288, 372, 24212, 8, 10146, 4186, 1166, 435, 11280, 1899, 13, 7788, 534, 435, 18500, 59, 17, 61, 1622, 61, 272, 871, 2186, 465, 444, 520, 267, 2512, 14, 705, 10994, 67, 16187, 4085, 320, 14, 647, 61, 4520, 741, 2607, 724, 281, 1127, 1166, 2150, 2717, 85, 743, 26, 298, 435, 620, 8, 476, 9, 776, 267, 5190, 14, 1361, 63, 2804, 8, 493, 29, 1274, 14, 2703, 9, 2286, 327, 7600, 26, 23761, 272, 372, 942, 1362, 199, 318, 664, 63, 1431, 8, 576, 12, 5163, 9, 520, 272, 1336, 275, 3087, 27, 272, 333, 275, 295, 14, 1733, 8, 3821, 12, 666, 9, 272, 340, 333, 1137, 488, 520, 267, 1336, 275, 333, 14, 923, 8, 17, 9, 272, 372, 1336, 199, 199, 318, 2342, 63, 11418, 8, 576, 304, 272, 492, 562, 5294, 3722, 272, 2512, 14, 815, 10994, 67, 16187, 645, 13957 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 17807, 4559, 199, 3, 4837, 317, 6327, 645, 29549, 446, 1323, 28994, 11349, 199, 3, 445, 368, 630, 12665, 286, 16187, 645, 13957, 334, 2038, 65, 373, 6559, 85, 11560, 18618, 271, 22010, 477, 562, 5294, 5064, 9, 199, 3, 1455, 921, 11486, 14, 84, 637, 645, 29549, 14, 815, 15, 2718, 13, 21382, 15, 321, 317, 6327, 645, 29549, 15, 199, 17807, 4559, 199, 199, 646, 7097, 12, 4078, 18, 12, 4078, 12, 264, 199, 646, 984, 12, 736, 12, 6894, 199, 199, 504, 6170, 492, 28348, 199, 504, 6170, 492, 2512, 199, 504, 6170, 492, 1101, 199, 199, 318, 664, 63, 3722, 63, 633, 8, 2034, 63, 633, 2360, 876, 23481, 275, 756, 2360, 922, 9287, 2360, 2505, 8772, 3991, 63, 2060, 9287, 3461, 272, 862, 520, 267, 2512, 14, 815, 10994, 67, 16187, 645, 13957, 14, 647, 61, 664, 63, 3722, 63, 633, 8, 1606, 63, 633, 9569, 83, 19124, 450, 2034, 63, 633, 9, 13857, 18500, 2968, 1899, 13, 7788, 297, 283, 22285, 15, 21, 14, 16, 334, 3399, 9924, 609, 27, 20619, 10444, 4403, 1323, 1616, 63, 22, 63, 24, 9, 21257, 21666, 15, 25083, 14, 2528, 14, 23, 334, 43, 4943, 12, 2839, 30506, 9, 3394, 15, 21, 14, 17, 14, 18, 428, 2756, 759, 15, 25083, 14, 2528, 14, 23, 418, 267, 25104, 17, 2968, 28900, 297, 283, 1014, 921, 1544, 14, 67, 16187, 645, 13957, 14, 957, 418, 267, 25104, 18, 2968, 28900, 297, 283, 1014, 921, 1544, 14, 67, 16187, 645, 13957, 14, 957, 15, 422, 29073, 5624, 393, 2292, 14, 26146, 418, 267, 666, 275, 28348, 14, 1637, 63, 1606, 480, 1014, 921, 1544, 14, 67, 16187, 645, 13957, 14, 957, 15, 422, 29073, 5624, 393, 2292, 14, 26146, 401, 2323, 1524, 1458, 12, 25104, 17, 467, 2653, 29, 9943, 9, 267, 32500, 275, 2650, 1210, 730, 628, 5642, 2, 536, 628, 363, 12058, 6689, 2, 1305, 628, 363, 12058, 6689, 2, 574, 32391, 7082, 6697, 7, 267, 32500, 847, 2650, 1210, 730, 628, 5642, 2, 536, 628, 363, 8193, 5600, 2594, 2, 1305, 628, 363, 8193, 5600, 2594, 2, 574, 32391, 7, 267, 4450, 275, 295, 14, 2014, 8, 10853, 2641, 12, 264, 14, 16504, 680, 6452, 8, 576, 9, 267, 1233, 17, 275, 4011, 14, 3513, 8, 6742, 59, 16, 1527, 16, 6575, 1814, 4769, 11890, 18, 38, 531, 267, 1233, 18, 275, 4011, 14, 3513, 8, 6742, 59, 16, 1527, 17, 6575, 1814, 4769, 11890, 18, 38, 531, 267, 1166, 29, 4078, 14, 3513, 8, 1606, 63, 633, 680, 1814, 4769, 11890, 18, 38, 531, 267, 2963, 275, 4396, 12058, 6689, 2458, 83, 6, 363, 8193, 5600, 2594, 2458, 83, 6, 2424, 63, 29073, 3722, 63, 633, 2458, 83, 6, 2424, 63, 10888, 63, 1213, 19167, 9633, 63, 6821, 29, 3673, 2, 450, 334, 600, 17, 12, 600, 18, 12, 633, 9, 267, 666, 275, 28348, 14, 1637, 63, 1606, 480, 1014, 921, 1544, 14, 67, 16187, 645, 13957, 14, 957, 15, 422, 29073, 5624, 393, 2292, 14, 26146, 401, 2963, 275, 2963, 2360, 2323, 1524, 1458, 12, 25104, 18, 467, 2653, 29, 27140, 9, 398, 32500, 275, 298, 22726, 60, 360, 7059, 21899, 3171, 2, 267, 4450, 275, 295, 14, 2014, 8, 10853, 2641, 12, 264, 14, 16504, 680, 6452, 8, 576, 9, 267, 1318, 275, 2125, 267, 367, 1336, 315, 4450, 26, 288, 1318, 847, 4011, 14, 12240, 8, 1431, 9, 267, 327, 2921, 14, 815, 480, 505, 275, 298, 435, 1318, 9, 2728, 333, 275, 295, 14, 2014, 360, 504, 1610, 3034, 24805, 21690, 1874, 13439, 9, 1959, 6452, 8, 505, 9, 267, 1166, 275, 3087, 267, 340, 333, 1137, 488, 436, 822, 8, 77, 9, 690, 413, 520, 288, 347, 4526, 63, 3684, 8, 476, 9, 520, 355, 1687, 63, 1712, 275, 444, 14, 1623, 360, 13854, 355, 340, 1687, 63, 1712, 1137, 446, 17, 520, 372, 8678, 8, 442, 8, 476, 59, 16, 26, 411, 63, 1712, 566, 435, 1109, 8, 476, 59, 411, 63, 1712, 11, 17, 16720, 355, 1687, 63, 1712, 275, 444, 14, 1623, 21950, 355, 340, 1687, 63, 1712, 1137, 446, 17, 520, 372, 8678, 8, 442, 8, 476, 59, 16, 26, 411, 63, 1712, 566, 446, 1109, 8, 476, 59, 411, 63, 1712, 11, 17, 16720, 355, 372, 15539, 7846, 477, 2873, 31958, 3153, 63, 3596, 275, 10587, 904, 8, 1130, 8, 2734, 5348, 520, 4526, 63, 3684, 8, 3684, 395, 333, 59, 17, 1055, 1294, 5102, 7058, 288, 333, 275, 295, 14, 2014, 14097, 1014, 921, 25153, 11, 4537, 22753, 2924, 1959, 1733, 8, 2172, 4361, 527, 3153, 63, 3596, 9, 288, 340, 333, 1137, 488, 436, 333, 14, 923, 8, 17, 9, 1137, 488, 520, 1166, 275, 333, 14, 923, 8, 17, 9, 288, 587, 26, 2512, 14, 815, 480, 2632, 949, 655, 17926, 983, 3427, 78, 2, 435, 477, 2873, 31958, 3153, 63, 3596, 9, 2728, 340, 822, 8, 633, 9, 690, 378, 520, 288, 327, 2227, 275, 664, 63, 1431, 8, 633, 12, 283, 83, 14, 26146, 15, 7059, 15251, 2447, 358, 288, 327, 12324, 275, 664, 63, 1431, 8, 633, 12, 283, 83, 14, 26146, 15, 26285, 15, 7059, 15251, 2447, 358, 288, 372, 24212, 8, 10146, 4186, 1166, 435, 11280, 1899, 13, 7788, 534, 435, 18500, 59, 17, 61, 1622, 61, 272, 871, 2186, 465, 444, 520, 267, 2512, 14, 705, 10994, 67, 16187, 4085, 320, 14, 647, 61, 4520, 741, 2607, 724, 281, 1127, 1166, 2150, 2717, 85, 743, 26, 298, 435, 620, 8, 476, 9, 776, 267, 5190, 14, 1361, 63, 2804, 8, 493, 29, 1274, 14, 2703, 9, 2286, 327, 7600, 26, 23761, 272, 372, 942, 1362, 199, 318, 664, 63, 1431, 8, 576, 12, 5163, 9, 520, 272, 1336, 275, 3087, 27, 272, 333, 275, 295, 14, 1733, 8, 3821, 12, 666, 9, 272, 340, 333, 1137, 488, 520, 267, 1336, 275, 333, 14, 923, 8, 17, 9, 272, 372, 1336, 199, 199, 318, 2342, 63, 11418, 8, 576, 304, 272, 492, 562, 5294, 3722, 272, 2512, 14, 815, 10994, 67, 16187, 645, 13957, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
lhopps/grit-i18n
grit/node/misc_unittest.py
3
17115
#!/usr/bin/env python # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. '''Unit tests for misc.GritNode''' import os import sys if __name__ == '__main__': sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) import unittest import StringIO from grit import grd_reader import grit.exception from grit import util from grit.format import rc from grit.node import misc class GritNodeUnittest(unittest.TestCase): def testUniqueNameAttribute(self): try: restree = grd_reader.Parse( util.PathFromRoot('grit/testdata/duplicate-name-input.xml')) self.fail('Expected parsing exception because of duplicate names.') except grit.exception.Parsing: pass # Expected case def testReadFirstIdsFromFile(self): test_resource_ids = os.path.join(os.path.dirname(__file__), '..', 'testdata', 'resource_ids') base_dir = os.path.dirname(test_resource_ids) src_dir, id_dict = misc._ReadFirstIdsFromFile( test_resource_ids, { 'FOO': os.path.join(base_dir, 'bar'), 'SHARED_INTERMEDIATE_DIR': os.path.join(base_dir, 'out/Release/obj/gen'), }) self.assertEqual({}, id_dict.get('bar/file.grd', None)) self.assertEqual({}, id_dict.get('out/Release/obj/gen/devtools/devtools.grd', None)) src_dir, id_dict = misc._ReadFirstIdsFromFile( test_resource_ids, { 'SHARED_INTERMEDIATE_DIR': '/outside/src_dir', }) self.assertEqual({}, id_dict.get('devtools.grd', None)) # Verifies that GetInputFiles() returns the correct list of files # corresponding to ChromeScaledImage nodes when assets are missing. def testGetInputFilesChromeScaledImage(self): xml = '''<?xml version="1.0" encoding="utf-8"?> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="default.pak" type="data_package" context="default_100_percent" /> <output filename="special.pak" type="data_package" context="special_100_percent" fallback_to_default_layout="false" /> </outputs> <release seq="1"> <structures fallback_to_low_resolution="true"> <structure type="chrome_scaled_image" name="IDR_A" file="a.png" /> <structure type="chrome_scaled_image" name="IDR_B" file="b.png" /> </structures> </release> </grit>''' grd = grd_reader.Parse(StringIO.StringIO(xml), util.PathFromRoot('grit/testdata')) expected = ['default_100_percent/a.png', 'default_100_percent/b.png', 'special_100_percent/a.png'] actual = [os.path.relpath(path, util.PathFromRoot('grit/testdata')) for path in grd.GetInputFiles()] # Convert path separator for Windows paths. actual = [path.replace('\\', '/') for path in actual] self.assertEquals(expected, actual) class IfNodeUnittest(unittest.TestCase): def testIffyness(self): grd = grd_reader.Parse(StringIO.StringIO(''' <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <release seq="3"> <messages> <if expr="'bingo' in defs"> <message name="IDS_BINGO"> Bingo! </message> </if> <if expr="'hello' in defs"> <message name="IDS_HELLO"> Hello! </message> </if> <if expr="lang == 'fr' or 'FORCE_FRENCH' in defs"> <message name="IDS_HELLO" internal_comment="French version"> Good morning </message> </if> <if expr="is_win"> <message name="IDS_ISWIN">is_win</message> </if> </messages> </release> </grit>'''), dir='.') messages_node = grd.children[0].children[0] bingo_message = messages_node.children[0].children[0] hello_message = messages_node.children[1].children[0] french_message = messages_node.children[2].children[0] is_win_message = messages_node.children[3].children[0] self.assertTrue(bingo_message.name == 'message') self.assertTrue(hello_message.name == 'message') self.assertTrue(french_message.name == 'message') grd.SetOutputLanguage('fr') grd.SetDefines({'hello': '1'}) active = set(grd.ActiveDescendants()) self.failUnless(bingo_message not in active) self.failUnless(hello_message in active) self.failUnless(french_message in active) grd.SetOutputLanguage('en') grd.SetDefines({'bingo': 1}) active = set(grd.ActiveDescendants()) self.failUnless(bingo_message in active) self.failUnless(hello_message not in active) self.failUnless(french_message not in active) grd.SetOutputLanguage('en') grd.SetDefines({'FORCE_FRENCH': '1', 'bingo': '1'}) active = set(grd.ActiveDescendants()) self.failUnless(bingo_message in active) self.failUnless(hello_message not in active) self.failUnless(french_message in active) grd.SetOutputLanguage('en') grd.SetDefines({}) self.failUnless(grd.target_platform == sys.platform) grd.SetTargetPlatform('darwin') active = set(grd.ActiveDescendants()) self.failUnless(is_win_message not in active) grd.SetTargetPlatform('win32') active = set(grd.ActiveDescendants()) self.failUnless(is_win_message in active) def testElsiness(self): grd = util.ParseGrdForUnittest(''' <messages> <if expr="True"> <then> <message name="IDS_YES1"></message> </then> <else> <message name="IDS_NO1"></message> </else> </if> <if expr="True"> <then> <message name="IDS_YES2"></message> </then> <else> </else> </if> <if expr="True"> <then> </then> <else> <message name="IDS_NO2"></message> </else> </if> <if expr="True"> <then> </then> <else> </else> </if> <if expr="False"> <then> <message name="IDS_NO3"></message> </then> <else> <message name="IDS_YES3"></message> </else> </if> <if expr="False"> <then> <message name="IDS_NO4"></message> </then> <else> </else> </if> <if expr="False"> <then> </then> <else> <message name="IDS_YES4"></message> </else> </if> <if expr="False"> <then> </then> <else> </else> </if> </messages>''') included = [msg.attrs['name'] for msg in grd.ActiveDescendants() if msg.name == 'message'] self.assertEqual(['IDS_YES1', 'IDS_YES2', 'IDS_YES3', 'IDS_YES4'], included) def testIffynessWithOutputNodes(self): grd = grd_reader.Parse(StringIO.StringIO(''' <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <outputs> <output filename="uncond1.rc" type="rc_data" /> <if expr="lang == 'fr' or 'hello' in defs"> <output filename="only_fr.adm" type="adm" /> <output filename="only_fr.plist" type="plist" /> </if> <if expr="lang == 'ru'"> <output filename="doc.html" type="document" /> </if> <output filename="uncond2.adm" type="adm" /> <output filename="iftest.h" type="rc_header"> <emit emit_type='prepend'></emit> </output> </outputs> </grit>'''), dir='.') outputs_node = grd.children[0] uncond1_output = outputs_node.children[0] only_fr_adm_output = outputs_node.children[1].children[0] only_fr_plist_output = outputs_node.children[1].children[1] doc_output = outputs_node.children[2].children[0] uncond2_output = outputs_node.children[0] self.assertTrue(uncond1_output.name == 'output') self.assertTrue(only_fr_adm_output.name == 'output') self.assertTrue(only_fr_plist_output.name == 'output') self.assertTrue(doc_output.name == 'output') self.assertTrue(uncond2_output.name == 'output') grd.SetOutputLanguage('ru') grd.SetDefines({'hello': '1'}) outputs = [output.GetFilename() for output in grd.GetOutputFiles()] self.assertEquals( outputs, ['uncond1.rc', 'only_fr.adm', 'only_fr.plist', 'doc.html', 'uncond2.adm', 'iftest.h']) grd.SetOutputLanguage('ru') grd.SetDefines({'bingo': '2'}) outputs = [output.GetFilename() for output in grd.GetOutputFiles()] self.assertEquals( outputs, ['uncond1.rc', 'doc.html', 'uncond2.adm', 'iftest.h']) grd.SetOutputLanguage('fr') grd.SetDefines({'hello': '1'}) outputs = [output.GetFilename() for output in grd.GetOutputFiles()] self.assertEquals( outputs, ['uncond1.rc', 'only_fr.adm', 'only_fr.plist', 'uncond2.adm', 'iftest.h']) grd.SetOutputLanguage('en') grd.SetDefines({'bingo': '1'}) outputs = [output.GetFilename() for output in grd.GetOutputFiles()] self.assertEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h']) grd.SetOutputLanguage('fr') grd.SetDefines({'bingo': '1'}) outputs = [output.GetFilename() for output in grd.GetOutputFiles()] self.assertNotEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h']) def testChildrenAccepted(self): grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0"?> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <release seq="3"> <includes> <if expr="'bingo' in defs"> <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> </if> <if expr="'bingo' in defs"> <if expr="'hello' in defs"> <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> </if> </if> </includes> <structures> <if expr="'bingo' in defs"> <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" /> </if> <if expr="'bingo' in defs"> <if expr="'hello' in defs"> <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" /> </if> </if> </structures> <messages> <if expr="'bingo' in defs"> <message name="IDS_BINGO">Bingo!</message> </if> <if expr="'bingo' in defs"> <if expr="'hello' in defs"> <message name="IDS_BINGO">Bingo!</message> </if> </if> </messages> </release> <translations> <if expr="'bingo' in defs"> <file lang="nl" path="nl_translations.xtb" /> </if> <if expr="'bingo' in defs"> <if expr="'hello' in defs"> <file lang="nl" path="nl_translations.xtb" /> </if> </if> </translations> </grit>'''), dir='.') def testIfBadChildrenNesting(self): # includes xml = StringIO.StringIO('''<?xml version="1.0"?> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <release seq="3"> <includes> <if expr="'bingo' in defs"> <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" /> </if> </includes> </release> </grit>''') self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) # messages xml = StringIO.StringIO('''<?xml version="1.0"?> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <release seq="3"> <messages> <if expr="'bingo' in defs"> <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" /> </if> </messages> </release> </grit>''') self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) # structures xml = StringIO.StringIO('''<?xml version="1.0"?> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <release seq="3"> <structures> <if expr="'bingo' in defs"> <message name="IDS_BINGO">Bingo!</message> </if> </structures> </release> </grit>''') # translations self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) xml = StringIO.StringIO('''<?xml version="1.0"?> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <translations> <if expr="'bingo' in defs"> <message name="IDS_BINGO">Bingo!</message> </if> </translations> </grit>''') self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) # same with nesting xml = StringIO.StringIO('''<?xml version="1.0"?> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <release seq="3"> <includes> <if expr="'bingo' in defs"> <if expr="'hello' in defs"> <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" /> </if> </if> </includes> </release> </grit>''') self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) xml = StringIO.StringIO('''<?xml version="1.0"?> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <release seq="3"> <messages> <if expr="'bingo' in defs"> <if expr="'hello' in defs"> <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" /> </if> </if> </messages> </release> </grit>''') self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) xml = StringIO.StringIO('''<?xml version="1.0"?> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <release seq="3"> <structures> <if expr="'bingo' in defs"> <if expr="'hello' in defs"> <message name="IDS_BINGO">Bingo!</message> </if> </if> </structures> </release> </grit>''') self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) xml = StringIO.StringIO('''<?xml version="1.0"?> <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> <translations> <if expr="'bingo' in defs"> <if expr="'hello' in defs"> <message name="IDS_BINGO">Bingo!</message> </if> </if> </translations> </grit>''') self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) class ReleaseNodeUnittest(unittest.TestCase): def testPseudoControl(self): grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?> <grit latest_public_release="1" source_lang_id="en-US" current_release="2" base_dir="."> <release seq="1" allow_pseudo="false"> <messages> <message name="IDS_HELLO"> Hello </message> </messages> <structures> <structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file="klonk.rc" /> </structures> </release> <release seq="2"> <messages> <message name="IDS_BINGO"> Bingo </message> </messages> <structures> <structure type="menu" name="IDC_KLONKMENU" encoding="utf-16" file="klonk.rc" /> </structures> </release> </grit>'''), util.PathFromRoot('grit/testdata')) grd.SetOutputLanguage('en') grd.RunGatherers() hello = grd.GetNodeById('IDS_HELLO') aboutbox = grd.GetNodeById('IDD_ABOUTBOX') bingo = grd.GetNodeById('IDS_BINGO') menu = grd.GetNodeById('IDC_KLONKMENU') for node in [hello, aboutbox]: self.failUnless(not node.PseudoIsAllowed()) for node in [bingo, menu]: self.failUnless(node.PseudoIsAllowed()) # TODO(benrg): There was a test here that formatting hello and aboutbox with # a pseudo language should fail, but they do not fail and the test was # broken and failed to catch it. Fix this. # Should not raise an exception since pseudo is allowed rc.FormatMessage(bingo, 'xyz-pseudo') rc.FormatStructure(menu, 'xyz-pseudo', '.') if __name__ == '__main__': unittest.main()
bsd-2-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 2344, 5072, 2295, 367, 18576, 14, 39, 11133, 1716, 2344, 421, 199, 646, 747, 199, 646, 984, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 984, 14, 515, 14, 740, 8, 736, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 20644, 703, 1333, 199, 199, 646, 2882, 199, 646, 5228, 199, 199, 504, 486, 11133, 492, 486, 6883, 63, 5503, 199, 646, 486, 11133, 14, 1971, 199, 504, 486, 11133, 492, 4884, 199, 504, 486, 11133, 14, 908, 492, 4819, 199, 504, 486, 11133, 14, 932, 492, 18576, 421, 199, 533, 598, 11133, 1716, 1358, 1770, 8, 2796, 14, 1746, 304, 523, 347, 511, 11427, 985, 1646, 8, 277, 304, 272, 862, 26, 489, 4618, 850, 275, 486, 6883, 63, 5503, 14, 4003, 8, 267, 4884, 14, 2042, 2532, 6405, 360, 7928, 84, 15, 18481, 15, 11081, 13, 354, 13, 1210, 14, 1652, 1333, 489, 291, 14, 1633, 360, 6964, 6057, 1919, 2952, 402, 9250, 1561, 2659, 272, 871, 486, 11133, 14, 1971, 14, 17412, 26, 489, 986, 221, 327, 13796, 1930, 819, 347, 511, 3284, 7147, 11506, 26637, 8, 277, 304, 272, 511, 63, 1927, 63, 1580, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 19155, 3660, 283, 18481, 297, 283, 1927, 63, 1580, 358, 272, 1300, 63, 694, 275, 747, 14, 515, 14, 3475, 8, 396, 63, 1927, 63, 1580, 9, 339, 2928, 63, 694, 12, 1305, 63, 807, 275, 18576, 423, 3284, 7147, 11506, 26637, 8, 267, 511, 63, 1927, 63, 1580, 12, 267, 469, 881, 283, 13046, 356, 747, 14, 515, 14, 904, 8, 1095, 63, 694, 12, 283, 1700, 659, 881, 283, 13772, 63, 23227, 63, 3022, 356, 747, 14, 515, 14, 904, 8, 1095, 63, 694, 12, 8179, 283, 548, 15, 9625, 15, 1113, 15, 2268, 659, 267, 3828, 272, 291, 14, 629, 16037, 1305, 63, 807, 14, 362, 360, 1700, 15, 493, 14, 2587, 68, 297, 488, 430, 272, 291, 14, 629, 16037, 267, 1305, 63, 807, 14, 362, 360, 548, 15, 9625, 15, 1113, 15, 2268, 15, 32355, 15, 32355, 14, 2587, 68, 297, 488, 430, 339, 2928, 63, 694, 12, 1305, 63, 807, 275, 18576, 423, 3284, 7147, 11506, 26637, 8, 267, 511, 63, 1927, 63, 1580, 12, 267, 469, 881, 283, 13772, 63, 23227, 63, 3022, 356, 1994, 22431, 15, 2164, 63, 694, 297, 267, 3828, 272, 291, 14, 629, 16037, 1305, 63, 807, 14, 362, 360, 32355, 14, 2587, 68, 297, 488, 430, 819, 327, 26114, 626, 2372, 3205, 5535, 342, 2529, 314, 3211, 769, 402, 1584, 523, 327, 5226, 370, 16776, 18269, 1146, 3491, 3380, 1380, 17202, 787, 4124, 14, 523, 347, 19970, 3205, 5535, 18083, 18269, 1146, 3491, 8, 277, 304, 272, 2748, 275, 28827, 31, 1652, 1015, 628, 17, 14, 16, 2, 2644, 628, 1624, 13, 24, 24327, 489, 665, 7928, 84, 8839, 63, 3455, 63, 3221, 628, 16, 2, 1453, 63, 3221, 628, 17, 1743, 267, 665, 4467, 30, 881, 665, 1199, 1788, 628, 885, 14, 22460, 2, 730, 628, 576, 63, 2491, 2, 1067, 628, 885, 63, 1960, 63, 7045, 2, 7082, 881, 665, 1199, 1788, 628, 6664, 14, 22460, 2, 730, 628, 576, 63, 2491, 2, 1067, 628, 6664, 63, 1960, 63, 7045, 2, 9567, 63, 475, 63, 885, 63, 4209, 628, 3910, 2, 7082, 267, 3068, 4467, 30, 267, 665, 3221, 5412, 628, 17, 1743, 881, 665, 13547, 9567, 63, 475, 63, 674, 63, 12588, 628, 2052, 1743, 288, 665, 6976, 730, 628, 9887, 63, 15120, 63, 1569, 2, 536, 628, 22052, 63, 33, 2, 570, 628, 65, 14, 4524, 2, 7082, 288, 665, 6976, 730, 628, 9887, 63, 15120, 63, 1569, 2, 536, 628, 22052, 63, 34, 2, 570, 628, 66, 14, 4524, 2, 7082, 881, 3068, 13547, 30, 267, 3068, 3221, 30, 489, 3068, 7928, 84, 26934, 339, 486, 6883, 275, 486, 6883, 63, 5503, 14, 4003, 8, 6424, 14, 6424, 8, 1652, 395, 4884, 14, 2042, 2532, 6405, 360, 7928, 84, 15, 18481, 1333, 272, 1420, 275, 788, 885, 63, 1960, 63, 7045, 15, 65, 14, 4524, 297, 283, 885, 63, 1960, 63, 7045, 15, 66, 14, 4524, 297, 283, 6664, 63, 1960, 63, 7045, 15, 65, 14, 4524, 418, 272, 3503, 275, 359, 736, 14, 515, 14, 12405, 8, 515, 12, 4884, 14, 2042, 2532, 6405, 360, 7928, 84, 15, 18481, 1333, 367, 931, 315, 486, 6883, 14, 1002, 3205, 5535, 5106, 272, 327, 7905, 931, 9432, 367, 5417, 3792, 14, 272, 3503, 275, 359, 515, 14, 1814, 20786, 15107, 367, 931, 315, 3503, 61, 272, 291, 14, 2947, 8, 2062, 12, 3503, 9, 421, 199, 533, 982, 1716, 1358, 1770, 8, 2796, 14, 1746, 304, 523, 347, 511, 41, 556, 89, 4171, 8, 277, 304, 272, 486, 6883, 275, 486, 6883, 63, 5503, 14, 4003, 8, 6424, 14, 6424, 10505, 489, 665, 7928, 84, 8839, 63, 3455, 63, 3221, 628, 18, 2, 1350, 63, 4159, 63, 344, 628, 287, 13, 1668, 2, 1453, 63, 3221, 628, 19, 2, 1300, 63, 694, 25356, 1743, 267, 665, 3221, 5412, 628, 19, 1743, 881, 665, 3431, 30, 288, 665, 692, 5348, 26957, 10911, 79, 7, 315, 22603, 1743, 1598, 665, 1188, 536, 628, 20857, 63, 34, 1206, 47, 1743, 355, 699, 316, 79, 1, 1598, 3068, 1188, 30, 288, 3068, 692, 30, 288, 665, 692, 5348, 26957, 5006, 7, 315, 22603, 1743, 1598, 665, 1188, 536, 628, 20857, 63, 24771, 1484, 1743, 355, 23833, 1, 1598, 3068, 1188, 30, 288, 3068, 692, 30, 288, 665, 692, 5348, 628, 4159, 508, 283, 4391, 7, 503, 283, 27240, 63, 5372, 742, 1244, 7, 315, 22603, 1743, 1598, 665, 1188, 536, 628, 20857, 63, 24771, 1484, 2, 5007, 63, 3349, 628, 38, 15148, 1015, 1743, 355, 22311, 21333, 1835, 1598, 3068, 1188, 30, 288, 3068, 692, 30, 288, 665, 692, 5348, 628, 374 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 2344, 5072, 2295, 367, 18576, 14, 39, 11133, 1716, 2344, 421, 199, 646, 747, 199, 646, 984, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 984, 14, 515, 14, 740, 8, 736, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 20644, 703, 1333, 199, 199, 646, 2882, 199, 646, 5228, 199, 199, 504, 486, 11133, 492, 486, 6883, 63, 5503, 199, 646, 486, 11133, 14, 1971, 199, 504, 486, 11133, 492, 4884, 199, 504, 486, 11133, 14, 908, 492, 4819, 199, 504, 486, 11133, 14, 932, 492, 18576, 421, 199, 533, 598, 11133, 1716, 1358, 1770, 8, 2796, 14, 1746, 304, 523, 347, 511, 11427, 985, 1646, 8, 277, 304, 272, 862, 26, 489, 4618, 850, 275, 486, 6883, 63, 5503, 14, 4003, 8, 267, 4884, 14, 2042, 2532, 6405, 360, 7928, 84, 15, 18481, 15, 11081, 13, 354, 13, 1210, 14, 1652, 1333, 489, 291, 14, 1633, 360, 6964, 6057, 1919, 2952, 402, 9250, 1561, 2659, 272, 871, 486, 11133, 14, 1971, 14, 17412, 26, 489, 986, 221, 327, 13796, 1930, 819, 347, 511, 3284, 7147, 11506, 26637, 8, 277, 304, 272, 511, 63, 1927, 63, 1580, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 19155, 3660, 283, 18481, 297, 283, 1927, 63, 1580, 358, 272, 1300, 63, 694, 275, 747, 14, 515, 14, 3475, 8, 396, 63, 1927, 63, 1580, 9, 339, 2928, 63, 694, 12, 1305, 63, 807, 275, 18576, 423, 3284, 7147, 11506, 26637, 8, 267, 511, 63, 1927, 63, 1580, 12, 267, 469, 881, 283, 13046, 356, 747, 14, 515, 14, 904, 8, 1095, 63, 694, 12, 283, 1700, 659, 881, 283, 13772, 63, 23227, 63, 3022, 356, 747, 14, 515, 14, 904, 8, 1095, 63, 694, 12, 8179, 283, 548, 15, 9625, 15, 1113, 15, 2268, 659, 267, 3828, 272, 291, 14, 629, 16037, 1305, 63, 807, 14, 362, 360, 1700, 15, 493, 14, 2587, 68, 297, 488, 430, 272, 291, 14, 629, 16037, 267, 1305, 63, 807, 14, 362, 360, 548, 15, 9625, 15, 1113, 15, 2268, 15, 32355, 15, 32355, 14, 2587, 68, 297, 488, 430, 339, 2928, 63, 694, 12, 1305, 63, 807, 275, 18576, 423, 3284, 7147, 11506, 26637, 8, 267, 511, 63, 1927, 63, 1580, 12, 267, 469, 881, 283, 13772, 63, 23227, 63, 3022, 356, 1994, 22431, 15, 2164, 63, 694, 297, 267, 3828, 272, 291, 14, 629, 16037, 1305, 63, 807, 14, 362, 360, 32355, 14, 2587, 68, 297, 488, 430, 819, 327, 26114, 626, 2372, 3205, 5535, 342, 2529, 314, 3211, 769, 402, 1584, 523, 327, 5226, 370, 16776, 18269, 1146, 3491, 3380, 1380, 17202, 787, 4124, 14, 523, 347, 19970, 3205, 5535, 18083, 18269, 1146, 3491, 8, 277, 304, 272, 2748, 275, 28827, 31, 1652, 1015, 628, 17, 14, 16, 2, 2644, 628, 1624, 13, 24, 24327, 489, 665, 7928, 84, 8839, 63, 3455, 63, 3221, 628, 16, 2, 1453, 63, 3221, 628, 17, 1743, 267, 665, 4467, 30, 881, 665, 1199, 1788, 628, 885, 14, 22460, 2, 730, 628, 576, 63, 2491, 2, 1067, 628, 885, 63, 1960, 63, 7045, 2, 7082, 881, 665, 1199, 1788, 628, 6664, 14, 22460, 2, 730, 628, 576, 63, 2491, 2, 1067, 628, 6664, 63, 1960, 63, 7045, 2, 9567, 63, 475, 63, 885, 63, 4209, 628, 3910, 2, 7082, 267, 3068, 4467, 30, 267, 665, 3221, 5412, 628, 17, 1743, 881, 665, 13547, 9567, 63, 475, 63, 674, 63, 12588, 628, 2052, 1743, 288, 665, 6976, 730, 628, 9887, 63, 15120, 63, 1569, 2, 536, 628, 22052, 63, 33, 2, 570, 628, 65, 14, 4524, 2, 7082, 288, 665, 6976, 730, 628, 9887, 63, 15120, 63, 1569, 2, 536, 628, 22052, 63, 34, 2, 570, 628, 66, 14, 4524, 2, 7082, 881, 3068, 13547, 30, 267, 3068, 3221, 30, 489, 3068, 7928, 84, 26934, 339, 486, 6883, 275, 486, 6883, 63, 5503, 14, 4003, 8, 6424, 14, 6424, 8, 1652, 395, 4884, 14, 2042, 2532, 6405, 360, 7928, 84, 15, 18481, 1333, 272, 1420, 275, 788, 885, 63, 1960, 63, 7045, 15, 65, 14, 4524, 297, 283, 885, 63, 1960, 63, 7045, 15, 66, 14, 4524, 297, 283, 6664, 63, 1960, 63, 7045, 15, 65, 14, 4524, 418, 272, 3503, 275, 359, 736, 14, 515, 14, 12405, 8, 515, 12, 4884, 14, 2042, 2532, 6405, 360, 7928, 84, 15, 18481, 1333, 367, 931, 315, 486, 6883, 14, 1002, 3205, 5535, 5106, 272, 327, 7905, 931, 9432, 367, 5417, 3792, 14, 272, 3503, 275, 359, 515, 14, 1814, 20786, 15107, 367, 931, 315, 3503, 61, 272, 291, 14, 2947, 8, 2062, 12, 3503, 9, 421, 199, 533, 982, 1716, 1358, 1770, 8, 2796, 14, 1746, 304, 523, 347, 511, 41, 556, 89, 4171, 8, 277, 304, 272, 486, 6883, 275, 486, 6883, 63, 5503, 14, 4003, 8, 6424, 14, 6424, 10505, 489, 665, 7928, 84, 8839, 63, 3455, 63, 3221, 628, 18, 2, 1350, 63, 4159, 63, 344, 628, 287, 13, 1668, 2, 1453, 63, 3221, 628, 19, 2, 1300, 63, 694, 25356, 1743, 267, 665, 3221, 5412, 628, 19, 1743, 881, 665, 3431, 30, 288, 665, 692, 5348, 26957, 10911, 79, 7, 315, 22603, 1743, 1598, 665, 1188, 536, 628, 20857, 63, 34, 1206, 47, 1743, 355, 699, 316, 79, 1, 1598, 3068, 1188, 30, 288, 3068, 692, 30, 288, 665, 692, 5348, 26957, 5006, 7, 315, 22603, 1743, 1598, 665, 1188, 536, 628, 20857, 63, 24771, 1484, 1743, 355, 23833, 1, 1598, 3068, 1188, 30, 288, 3068, 692, 30, 288, 665, 692, 5348, 628, 4159, 508, 283, 4391, 7, 503, 283, 27240, 63, 5372, 742, 1244, 7, 315, 22603, 1743, 1598, 665, 1188, 536, 628, 20857, 63, 24771, 1484, 2, 5007, 63, 3349, 628, 38, 15148, 1015, 1743, 355, 22311, 21333, 1835, 1598, 3068, 1188, 30, 288, 3068, 692, 30, 288, 665, 692, 5348, 628, 374, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
gmatteo/pymatgen
pymatgen/util/serialization.py
5
3711
# coding: utf-8 # Copyright (c) Pymatgen Development Team. # Distributed under the terms of the MIT License. """ Most features of this module has been moved to monty. Please refer to monty.json and monty.serialization documentation. """ import functools import json import pickle from pymatgen.core.periodic_table import Element def pmg_serialize(method): """ Decorator for methods that add MSON serializations keys to the dictionary. See documentation of MSON for more details """ @functools.wraps(method) def wrapper(*args, **kwargs): self = args[0] d = method(*args, **kwargs) # Add @module and @class d["@module"] = self.__class__.__module__ d["@class"] = self.__class__.__name__ return d return wrapper def json_pretty_dump(obj, filename): """ Serialize obj as a JSON formatted stream to the given filename ( pretty printing version) """ with open(filename, "wt") as fh: json.dump(obj, fh, indent=4, sort_keys=4) class PmgPickler(pickle.Pickler): """ Persistence of External Objects as described in section 12.1.5.1 of https://docs.python.org/3/library/pickle.html """ def persistent_id(self, obj): """Instead of pickling as a regular class instance, we emit a persistent ID.""" if isinstance(obj, Element): # Here, our persistent ID is simply a tuple, containing a tag and # a key return obj.__class__.__name__, obj.symbol # If obj does not have a persistent ID, return None. This means obj # needs to be pickled as usual. return None class PmgUnpickler(pickle.Unpickler): """ Persistence of External Objects as described in section 12.1.5.1 of https://docs.python.org/3/library/pickle.html """ def persistent_load(self, pid): """ This method is invoked whenever a persistent ID is encountered. Here, pid is the tuple returned by PmgPickler. """ try: type_tag, key_id = pid except Exception: # Sometimes we get a string such as ('Element', u'C') instead # of a real tuple. Use ast to evalute the expression (much safer # than eval). import ast type_tag, key_id = ast.literal_eval(pid) if type_tag == "Element": return Element(key_id) # Always raises an error if you cannot return the correct object. # Otherwise, the unpickler will think None is the object referenced # by the persistent ID. raise pickle.UnpicklingError("unsupported persistent object with pid %s" % pid) def pmg_pickle_load(filobj, **kwargs): r""" Loads a pickle file and deserialize it with PmgUnpickler. Args: filobj: File-like object **kwargs: Any of the keyword arguments supported by PmgUnpickler Returns: Deserialized object. """ return PmgUnpickler(filobj, **kwargs).load() def pmg_pickle_dump(obj, filobj, **kwargs): r""" Dump an object to a pickle file using PmgPickler. Args: obj : Object to dump. fileobj: File-like object **kwargs: Any of the keyword arguments supported by PmgPickler """ return PmgPickler(filobj, **kwargs).dump(obj) class SlotPickleMixin: """ This mixin makes it possible to pickle/unpickle objects with __slots__ defined. """ def __getstate__(self): return dict((slot, getattr(self, slot)) for slot in self.__slots__ if hasattr(self, slot)) def __setstate__(self, state): for slot, value in state.items(): setattr(self, slot, value)
mit
[ 3, 2803, 26, 2774, 13, 24, 199, 3, 1898, 334, 67, 9, 1611, 30649, 15290, 11682, 14, 199, 3, 17484, 1334, 314, 2895, 402, 314, 10697, 844, 14, 199, 199, 624, 199, 24625, 4534, 402, 642, 859, 965, 2757, 12155, 370, 3485, 369, 14, 7754, 10618, 370, 199, 2106, 369, 14, 1001, 436, 3485, 369, 14, 12161, 3794, 14, 199, 624, 199, 199, 646, 9143, 199, 646, 2022, 199, 646, 5927, 199, 199, 504, 1134, 30649, 14, 1018, 14, 20339, 63, 1224, 492, 6566, 421, 199, 318, 299, 6649, 63, 3549, 8, 765, 304, 272, 408, 272, 30684, 367, 3102, 626, 1050, 603, 3377, 3012, 12270, 2883, 272, 370, 314, 2600, 14, 1666, 3794, 402, 603, 3377, 367, 1655, 2436, 272, 408, 339, 768, 17869, 14, 13582, 8, 765, 9, 272, 347, 4975, 2031, 589, 12, 1011, 958, 304, 267, 291, 275, 1249, 59, 16, 61, 267, 366, 275, 1083, 2031, 589, 12, 1011, 958, 9, 267, 327, 2654, 768, 578, 436, 768, 533, 267, 366, 905, 32, 578, 937, 275, 291, 855, 533, 4914, 578, 363, 267, 366, 905, 32, 533, 937, 275, 291, 855, 533, 4914, 354, 363, 267, 372, 366, 339, 372, 4975, 421, 199, 318, 2022, 63, 9118, 63, 2724, 8, 1113, 12, 1788, 304, 272, 408, 272, 11973, 794, 1559, 465, 282, 4840, 7871, 2547, 370, 314, 1627, 1788, 334, 272, 7268, 16116, 1015, 9, 272, 408, 272, 543, 1551, 8, 1501, 12, 298, 9115, 531, 465, 11155, 26, 267, 2022, 14, 2724, 8, 1113, 12, 11155, 12, 4363, 29, 20, 12, 4069, 63, 1612, 29, 20, 9, 421, 199, 533, 510, 6649, 8587, 1435, 8, 8092, 14, 8587, 1435, 304, 272, 408, 272, 3492, 15284, 402, 18802, 26794, 465, 11736, 315, 3420, 3144, 14, 17, 14, 21, 14, 17, 402, 272, 4178, 921, 4757, 14, 1548, 14, 1308, 15, 19, 15, 4342, 15, 8092, 14, 1360, 272, 408, 339, 347, 16149, 63, 344, 8, 277, 12, 1559, 304, 267, 408, 13962, 13558, 402, 24394, 465, 282, 5578, 1021, 1256, 12, 781, 8689, 282, 267, 16149, 2870, 1041, 267, 340, 1228, 8, 1113, 12, 6566, 304, 288, 327, 11842, 12, 4154, 16149, 2870, 365, 9329, 282, 2008, 12, 3035, 282, 1947, 436, 288, 327, 282, 790, 288, 372, 1559, 855, 533, 4914, 354, 3108, 1559, 14, 5155, 267, 327, 982, 1559, 1630, 440, 1172, 282, 16149, 2870, 12, 372, 488, 14, 961, 4910, 1559, 267, 327, 4839, 370, 506, 18731, 465, 20195, 14, 267, 372, 488, 421, 199, 533, 510, 6649, 1358, 23468, 8, 8092, 14, 1358, 23468, 304, 272, 408, 272, 3492, 15284, 402, 18802, 26794, 465, 11736, 315, 3420, 3144, 14, 17, 14, 21, 14, 17, 402, 272, 4178, 921, 4757, 14, 1548, 14, 1308, 15, 19, 15, 4342, 15, 8092, 14, 1360, 272, 408, 339, 347, 16149, 63, 912, 8, 277, 12, 4422, 304, 267, 408, 267, 961, 1083, 365, 10302, 18119, 282, 16149, 2870, 365, 14556, 14, 267, 11842, 12, 4422, 365, 314, 2008, 2138, 701, 510, 6649, 8587, 1435, 14, 267, 408, 267, 862, 26, 288, 730, 63, 1450, 12, 790, 63, 344, 275, 4422, 267, 871, 2186, 26, 288, 327, 30094, 781, 664, 282, 1059, 4066, 465, 661, 2162, 297, 399, 7, 35, 358, 3140, 288, 327, 402, 282, 3363, 2008, 14, 3645, 6073, 370, 3468, 938, 314, 3965, 334, 77, 2133, 2937, 2412, 288, 327, 2419, 3468, 680, 288, 492, 6073, 953, 730, 63, 1450, 12, 790, 63, 344, 275, 6073, 14, 8939, 63, 2579, 8, 3150, 9, 398, 340, 730, 63, 1450, 508, 298, 2162, 582, 288, 372, 6566, 8, 498, 63, 344, 9, 267, 327, 16763, 6534, 376, 1125, 340, 1265, 3913, 372, 314, 3211, 909, 14, 267, 327, 6630, 12, 314, 625, 23468, 911, 13516, 488, 365, 314, 909, 11812, 267, 327, 701, 314, 16149, 2870, 14, 267, 746, 5927, 14, 1358, 24773, 547, 480, 15267, 16149, 909, 543, 4422, 450, 83, 2, 450, 4422, 9, 421, 199, 318, 299, 6649, 63, 8092, 63, 912, 8, 329, 25678, 12, 1011, 958, 304, 272, 519, 624, 272, 30367, 282, 5927, 570, 436, 22920, 652, 543, 510, 6649, 1358, 23468, 14, 339, 3033, 26, 267, 5883, 25678, 26, 3814, 13, 2930, 909, 267, 1011, 958, 26, 6184, 402, 314, 4252, 2368, 3748, 701, 510, 6649, 1358, 23468, 339, 1803, 26, 267, 1487, 8397, 909, 14, 272, 408, 272, 372, 510, 6649, 1358, 23468, 8, 329, 25678, 12, 1011, 958, 680, 912, 342, 421, 199, 318, 299, 6649, 63, 8092, 63, 2724, 8, 1113, 12, 5883, 25678, 12, 1011, 958, 304, 272, 519, 624, 272, 19460, 376, 909, 370, 282, 5927, 570, 1808, 510, 6649, 8587, 1435, 14, 339, 3033, 26, 267, 1559, 520, 6935, 370, 5461, 14, 267, 11099, 26, 3814, 13, 2930, 909, 267, 1011, 958, 26, 6184, 402, 314, 4252, 2368, 3748, 701, 510, 6649, 8587, 1435, 272, 408, 272, 372, 510, 6649, 8587, 1435, 8, 329, 25678, 12, 1011, 958, 680, 2724, 8, 1113, 9, 421, 199, 533, 428, 1653, 12755, 4256, 26, 272, 408, 272, 961, 20048, 7704, 652, 3962, 370, 5927, 15, 324, 8092, 2251, 543, 636, 7257, 363, 272, 3247, 14, 272, 408, 339, 347, 636, 16011, 721, 277, 304, 267, 372, 1211, 1332, 7998, 12, 2519, 8, 277, 12, 9348, 430, 367, 9348, 315, 291, 855, 7257, 363, 340, 2688, 8, 277, 12, 9348, 430, 339, 347, 636, 17212, 721, 277, 12, 1174, 304, 267, 367, 9348, 12, 574, 315, 1174, 14, 1744, 837, 288, 5371, 8, 277, 12, 9348, 12, 574, 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 ]
[ 2803, 26, 2774, 13, 24, 199, 3, 1898, 334, 67, 9, 1611, 30649, 15290, 11682, 14, 199, 3, 17484, 1334, 314, 2895, 402, 314, 10697, 844, 14, 199, 199, 624, 199, 24625, 4534, 402, 642, 859, 965, 2757, 12155, 370, 3485, 369, 14, 7754, 10618, 370, 199, 2106, 369, 14, 1001, 436, 3485, 369, 14, 12161, 3794, 14, 199, 624, 199, 199, 646, 9143, 199, 646, 2022, 199, 646, 5927, 199, 199, 504, 1134, 30649, 14, 1018, 14, 20339, 63, 1224, 492, 6566, 421, 199, 318, 299, 6649, 63, 3549, 8, 765, 304, 272, 408, 272, 30684, 367, 3102, 626, 1050, 603, 3377, 3012, 12270, 2883, 272, 370, 314, 2600, 14, 1666, 3794, 402, 603, 3377, 367, 1655, 2436, 272, 408, 339, 768, 17869, 14, 13582, 8, 765, 9, 272, 347, 4975, 2031, 589, 12, 1011, 958, 304, 267, 291, 275, 1249, 59, 16, 61, 267, 366, 275, 1083, 2031, 589, 12, 1011, 958, 9, 267, 327, 2654, 768, 578, 436, 768, 533, 267, 366, 905, 32, 578, 937, 275, 291, 855, 533, 4914, 578, 363, 267, 366, 905, 32, 533, 937, 275, 291, 855, 533, 4914, 354, 363, 267, 372, 366, 339, 372, 4975, 421, 199, 318, 2022, 63, 9118, 63, 2724, 8, 1113, 12, 1788, 304, 272, 408, 272, 11973, 794, 1559, 465, 282, 4840, 7871, 2547, 370, 314, 1627, 1788, 334, 272, 7268, 16116, 1015, 9, 272, 408, 272, 543, 1551, 8, 1501, 12, 298, 9115, 531, 465, 11155, 26, 267, 2022, 14, 2724, 8, 1113, 12, 11155, 12, 4363, 29, 20, 12, 4069, 63, 1612, 29, 20, 9, 421, 199, 533, 510, 6649, 8587, 1435, 8, 8092, 14, 8587, 1435, 304, 272, 408, 272, 3492, 15284, 402, 18802, 26794, 465, 11736, 315, 3420, 3144, 14, 17, 14, 21, 14, 17, 402, 272, 4178, 921, 4757, 14, 1548, 14, 1308, 15, 19, 15, 4342, 15, 8092, 14, 1360, 272, 408, 339, 347, 16149, 63, 344, 8, 277, 12, 1559, 304, 267, 408, 13962, 13558, 402, 24394, 465, 282, 5578, 1021, 1256, 12, 781, 8689, 282, 267, 16149, 2870, 1041, 267, 340, 1228, 8, 1113, 12, 6566, 304, 288, 327, 11842, 12, 4154, 16149, 2870, 365, 9329, 282, 2008, 12, 3035, 282, 1947, 436, 288, 327, 282, 790, 288, 372, 1559, 855, 533, 4914, 354, 3108, 1559, 14, 5155, 267, 327, 982, 1559, 1630, 440, 1172, 282, 16149, 2870, 12, 372, 488, 14, 961, 4910, 1559, 267, 327, 4839, 370, 506, 18731, 465, 20195, 14, 267, 372, 488, 421, 199, 533, 510, 6649, 1358, 23468, 8, 8092, 14, 1358, 23468, 304, 272, 408, 272, 3492, 15284, 402, 18802, 26794, 465, 11736, 315, 3420, 3144, 14, 17, 14, 21, 14, 17, 402, 272, 4178, 921, 4757, 14, 1548, 14, 1308, 15, 19, 15, 4342, 15, 8092, 14, 1360, 272, 408, 339, 347, 16149, 63, 912, 8, 277, 12, 4422, 304, 267, 408, 267, 961, 1083, 365, 10302, 18119, 282, 16149, 2870, 365, 14556, 14, 267, 11842, 12, 4422, 365, 314, 2008, 2138, 701, 510, 6649, 8587, 1435, 14, 267, 408, 267, 862, 26, 288, 730, 63, 1450, 12, 790, 63, 344, 275, 4422, 267, 871, 2186, 26, 288, 327, 30094, 781, 664, 282, 1059, 4066, 465, 661, 2162, 297, 399, 7, 35, 358, 3140, 288, 327, 402, 282, 3363, 2008, 14, 3645, 6073, 370, 3468, 938, 314, 3965, 334, 77, 2133, 2937, 2412, 288, 327, 2419, 3468, 680, 288, 492, 6073, 953, 730, 63, 1450, 12, 790, 63, 344, 275, 6073, 14, 8939, 63, 2579, 8, 3150, 9, 398, 340, 730, 63, 1450, 508, 298, 2162, 582, 288, 372, 6566, 8, 498, 63, 344, 9, 267, 327, 16763, 6534, 376, 1125, 340, 1265, 3913, 372, 314, 3211, 909, 14, 267, 327, 6630, 12, 314, 625, 23468, 911, 13516, 488, 365, 314, 909, 11812, 267, 327, 701, 314, 16149, 2870, 14, 267, 746, 5927, 14, 1358, 24773, 547, 480, 15267, 16149, 909, 543, 4422, 450, 83, 2, 450, 4422, 9, 421, 199, 318, 299, 6649, 63, 8092, 63, 912, 8, 329, 25678, 12, 1011, 958, 304, 272, 519, 624, 272, 30367, 282, 5927, 570, 436, 22920, 652, 543, 510, 6649, 1358, 23468, 14, 339, 3033, 26, 267, 5883, 25678, 26, 3814, 13, 2930, 909, 267, 1011, 958, 26, 6184, 402, 314, 4252, 2368, 3748, 701, 510, 6649, 1358, 23468, 339, 1803, 26, 267, 1487, 8397, 909, 14, 272, 408, 272, 372, 510, 6649, 1358, 23468, 8, 329, 25678, 12, 1011, 958, 680, 912, 342, 421, 199, 318, 299, 6649, 63, 8092, 63, 2724, 8, 1113, 12, 5883, 25678, 12, 1011, 958, 304, 272, 519, 624, 272, 19460, 376, 909, 370, 282, 5927, 570, 1808, 510, 6649, 8587, 1435, 14, 339, 3033, 26, 267, 1559, 520, 6935, 370, 5461, 14, 267, 11099, 26, 3814, 13, 2930, 909, 267, 1011, 958, 26, 6184, 402, 314, 4252, 2368, 3748, 701, 510, 6649, 8587, 1435, 272, 408, 272, 372, 510, 6649, 8587, 1435, 8, 329, 25678, 12, 1011, 958, 680, 2724, 8, 1113, 9, 421, 199, 533, 428, 1653, 12755, 4256, 26, 272, 408, 272, 961, 20048, 7704, 652, 3962, 370, 5927, 15, 324, 8092, 2251, 543, 636, 7257, 363, 272, 3247, 14, 272, 408, 339, 347, 636, 16011, 721, 277, 304, 267, 372, 1211, 1332, 7998, 12, 2519, 8, 277, 12, 9348, 430, 367, 9348, 315, 291, 855, 7257, 363, 340, 2688, 8, 277, 12, 9348, 430, 339, 347, 636, 17212, 721, 277, 12, 1174, 304, 267, 367, 9348, 12, 574, 315, 1174, 14, 1744, 837, 288, 5371, 8, 277, 12, 9348, 12, 574, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
dkroy/luigi
test/recursion_test.py
35
1635
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from __future__ import print_function import datetime import sys from helpers import unittest import luigi import luigi.interface from luigi.mock import MockTarget class Popularity(luigi.Task): date = luigi.DateParameter(default=datetime.date.today() - datetime.timedelta(1)) def output(self): return MockTarget('/tmp/popularity/%s.txt' % self.date.strftime('%Y-%m-%d')) def requires(self): return Popularity(self.date - datetime.timedelta(1)) def run(self): f = self.output().open('w') for line in self.input().open('r'): print(int(line.strip()) + 1, file=f) f.close() class RecursionTest(unittest.TestCase): def setUp(self): MockTarget.fs.get_all_data()['/tmp/popularity/2009-01-01.txt'] = b'0\n' def test_invoke(self): w = luigi.worker.Worker() w.add(Popularity(datetime.date(2010, 1, 1))) w.run() w.stop() self.assertEqual(MockTarget.fs.get_data('/tmp/popularity/2010-01-01.txt'), b'365\n')
apache-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 6029, 13, 7806, 428, 555, 3338, 14840, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2197, 199, 646, 984, 199, 504, 10897, 492, 2882, 199, 199, 646, 19485, 199, 646, 19485, 14, 3266, 199, 504, 19485, 14, 1805, 492, 4420, 4277, 421, 199, 533, 13244, 22504, 8, 26795, 14, 4476, 304, 272, 1434, 275, 19485, 14, 2506, 4720, 8, 885, 29, 2083, 14, 602, 14, 8136, 342, 446, 2197, 14, 7473, 8, 17, 430, 339, 347, 1072, 8, 277, 304, 267, 372, 4420, 4277, 2336, 2791, 15, 1935, 22504, 3149, 83, 14, 2424, 7, 450, 291, 14, 602, 14, 6205, 3508, 57, 3295, 77, 3295, 68, 1333, 339, 347, 5074, 8, 277, 304, 267, 372, 13244, 22504, 8, 277, 14, 602, 446, 2197, 14, 7473, 8, 17, 430, 339, 347, 1255, 8, 277, 304, 267, 289, 275, 291, 14, 1199, 1252, 1490, 360, 87, 358, 267, 367, 1004, 315, 291, 14, 1210, 1252, 1490, 360, 82, 735, 288, 870, 8, 442, 8, 604, 14, 1913, 1012, 435, 413, 12, 570, 29, 70, 9, 398, 289, 14, 1600, 342, 421, 199, 533, 18306, 438, 774, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 4420, 4277, 14, 2319, 14, 362, 63, 452, 63, 576, 12047, 15, 2791, 15, 1935, 22504, 15, 8664, 13, 614, 13, 614, 14, 2424, 418, 275, 330, 7, 16, 60, 78, 7, 339, 347, 511, 63, 15195, 8, 277, 304, 267, 336, 275, 19485, 14, 6599, 14, 12678, 342, 267, 336, 14, 525, 8, 9606, 22504, 8, 2083, 14, 602, 8, 6542, 12, 413, 12, 413, 1724, 267, 336, 14, 1065, 342, 267, 336, 14, 2379, 342, 398, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 1935, 22504, 15, 6542, 13, 614, 13, 614, 14, 2424, 659, 330, 7, 12664, 60, 78, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 6029, 13, 7806, 428, 555, 3338, 14840, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2197, 199, 646, 984, 199, 504, 10897, 492, 2882, 199, 199, 646, 19485, 199, 646, 19485, 14, 3266, 199, 504, 19485, 14, 1805, 492, 4420, 4277, 421, 199, 533, 13244, 22504, 8, 26795, 14, 4476, 304, 272, 1434, 275, 19485, 14, 2506, 4720, 8, 885, 29, 2083, 14, 602, 14, 8136, 342, 446, 2197, 14, 7473, 8, 17, 430, 339, 347, 1072, 8, 277, 304, 267, 372, 4420, 4277, 2336, 2791, 15, 1935, 22504, 3149, 83, 14, 2424, 7, 450, 291, 14, 602, 14, 6205, 3508, 57, 3295, 77, 3295, 68, 1333, 339, 347, 5074, 8, 277, 304, 267, 372, 13244, 22504, 8, 277, 14, 602, 446, 2197, 14, 7473, 8, 17, 430, 339, 347, 1255, 8, 277, 304, 267, 289, 275, 291, 14, 1199, 1252, 1490, 360, 87, 358, 267, 367, 1004, 315, 291, 14, 1210, 1252, 1490, 360, 82, 735, 288, 870, 8, 442, 8, 604, 14, 1913, 1012, 435, 413, 12, 570, 29, 70, 9, 398, 289, 14, 1600, 342, 421, 199, 533, 18306, 438, 774, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 4420, 4277, 14, 2319, 14, 362, 63, 452, 63, 576, 12047, 15, 2791, 15, 1935, 22504, 15, 8664, 13, 614, 13, 614, 14, 2424, 418, 275, 330, 7, 16, 60, 78, 7, 339, 347, 511, 63, 15195, 8, 277, 304, 267, 336, 275, 19485, 14, 6599, 14, 12678, 342, 267, 336, 14, 525, 8, 9606, 22504, 8, 2083, 14, 602, 8, 6542, 12, 413, 12, 413, 1724, 267, 336, 14, 1065, 342, 267, 336, 14, 2379, 342, 398, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 1935, 22504, 15, 6542, 13, 614, 13, 614, 14, 2424, 659, 330, 7, 12664, 60, 78, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
egaxegax/django-dbcartajs
django/contrib/localflavor/ch/forms.py
101
3963
""" Swiss-specific Form helpers """ from __future__ import absolute_import, unicode_literals import re from django.contrib.localflavor.ch.ch_states import STATE_CHOICES from django.core.validators import EMPTY_VALUES from django.forms import ValidationError from django.forms.fields import Field, RegexField, Select from django.utils.encoding import smart_text from django.utils.translation import ugettext_lazy as _ id_re = re.compile(r"^(?P<idnumber>\w{8})(?P<pos9>(\d{1}|<))(?P<checksum>\d{1})$") phone_digits_re = re.compile(r'^0([1-9]{1})\d{8}$') class CHZipCodeField(RegexField): default_error_messages = { 'invalid': _('Enter a zip code in the format XXXX.'), } def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(CHZipCodeField, self).__init__(r'^\d{4}$', max_length, min_length, *args, **kwargs) class CHPhoneNumberField(Field): """ Validate local Swiss phone number (not international ones) The correct format is '0XX XXX XX XX'. '0XX.XXX.XX.XX' and '0XXXXXXXXX' validate but are corrected to '0XX XXX XX XX'. """ default_error_messages = { 'invalid': _('Phone numbers must be in 0XX XXX XX XX format.'), } def clean(self, value): super(CHPhoneNumberField, self).clean(value) if value in EMPTY_VALUES: return '' value = re.sub('(\.|\s|/|-)', '', smart_text(value)) m = phone_digits_re.search(value) if m: return '%s %s %s %s' % (value[0:3], value[3:6], value[6:8], value[8:10]) raise ValidationError(self.error_messages['invalid']) class CHStateSelect(Select): """ A Select widget that uses a list of CH states as its choices. """ def __init__(self, attrs=None): super(CHStateSelect, self).__init__(attrs, choices=STATE_CHOICES) class CHIdentityCardNumberField(Field): """ A Swiss identity card number. Checks the following rules to determine whether the number is valid: * Conforms to the X1234567<0 or 1234567890 format. * Included checksums match calculated checksums """ default_error_messages = { 'invalid': _('Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.'), } def has_valid_checksum(self, number): given_number, given_checksum = number[:-1], number[-1] new_number = given_number calculated_checksum = 0 fragment = "" parameter = 7 first = str(number[:1]) if first.isalpha(): num = ord(first.upper()) - 65 if num < 0 or num > 8: return False new_number = str(num) + new_number[1:] new_number = new_number[:8] + '0' if not new_number.isdigit(): return False for i in range(len(new_number)): fragment = int(new_number[i])*parameter calculated_checksum += fragment if parameter == 1: parameter = 7 elif parameter == 3: parameter = 1 elif parameter ==7: parameter = 3 return str(calculated_checksum)[-1] == given_checksum def clean(self, value): super(CHIdentityCardNumberField, self).clean(value) if value in EMPTY_VALUES: return '' match = re.match(id_re, value) if not match: raise ValidationError(self.error_messages['invalid']) idnumber, pos9, checksum = match.groupdict()['idnumber'], match.groupdict()['pos9'], match.groupdict()['checksum'] if idnumber == '00000000' or \ idnumber == 'A0000000': raise ValidationError(self.error_messages['invalid']) all_digits = "%s%s%s" % (idnumber, pos9, checksum) if not self.has_valid_checksum(all_digits): raise ValidationError(self.error_messages['invalid']) return '%s%s%s' % (idnumber, pos9, checksum)
gpl-2.0
[ 624, 199, 10941, 19857, 13, 6100, 8204, 10897, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 2649, 63, 5955, 199, 199, 646, 295, 199, 199, 504, 1639, 14, 2828, 14, 320, 696, 276, 4271, 14, 335, 14, 335, 63, 4981, 492, 11377, 63, 16236, 199, 504, 1639, 14, 1018, 14, 11346, 492, 16589, 63, 15514, 199, 504, 1639, 14, 3351, 492, 8505, 199, 504, 1639, 14, 3351, 14, 955, 492, 5024, 12, 12939, 792, 12, 9496, 199, 504, 1639, 14, 1208, 14, 2991, 492, 11179, 63, 505, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 421, 199, 344, 63, 264, 275, 295, 14, 2014, 8, 82, 16136, 2229, 48, 28, 344, 1955, 3072, 87, 91, 24, 1552, 2229, 48, 28, 1712, 25, 30, 2961, 68, 91, 17, 22441, 28, 430, 2229, 48, 28, 8928, 3072, 68, 91, 17, 1552, 22550, 199, 9339, 63, 7022, 63, 264, 275, 295, 14, 2014, 8, 82, 4289, 16, 779, 17, 13, 25, 8194, 17, 30446, 68, 91, 24, 93, 9988, 199, 199, 533, 6624, 8674, 3034, 792, 8, 5103, 792, 304, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 8468, 282, 3482, 1233, 315, 314, 1475, 5787, 56, 8038, 272, 789, 339, 347, 636, 826, 721, 277, 12, 1390, 63, 1267, 29, 403, 12, 1748, 63, 1267, 29, 403, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 1244, 8674, 3034, 792, 12, 291, 2843, 826, 721, 82, 15542, 68, 91, 20, 19204, 267, 1390, 63, 1267, 12, 1748, 63, 1267, 12, 627, 589, 12, 1011, 958, 9, 199, 199, 533, 6624, 25640, 792, 8, 792, 304, 272, 408, 272, 12134, 2257, 16666, 19857, 14617, 1329, 334, 1397, 10757, 6279, 7869, 9, 272, 710, 3211, 1475, 365, 283, 16, 2483, 5787, 1323, 56, 1323, 56, 1370, 272, 283, 16, 2483, 14, 13933, 14, 2483, 14, 2483, 7, 436, 283, 16, 13312, 56, 7, 4107, 1325, 787, 30156, 370, 272, 283, 16, 2483, 5787, 1323, 56, 1323, 56, 1370, 272, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 15199, 5579, 1471, 506, 315, 378, 2483, 5787, 1323, 56, 1323, 56, 1475, 8038, 272, 789, 339, 347, 3633, 8, 277, 12, 574, 304, 267, 1613, 8, 1244, 25640, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 2125, 267, 574, 275, 295, 14, 954, 360, 2961, 14, 6113, 83, 92, 15, 28447, 3196, 3260, 11179, 63, 505, 8, 585, 430, 267, 333, 275, 14617, 63, 7022, 63, 264, 14, 1733, 8, 585, 9, 267, 340, 333, 26, 288, 372, 1543, 83, 450, 83, 450, 83, 450, 83, 7, 450, 334, 585, 59, 16, 26, 19, 467, 574, 59, 19, 26, 22, 467, 574, 59, 22, 26, 24, 467, 574, 59, 24, 26, 709, 566, 267, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 199, 199, 533, 6624, 2223, 5446, 8, 5446, 304, 272, 408, 272, 437, 9496, 3938, 626, 4440, 282, 769, 402, 6624, 6363, 465, 2399, 3415, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 3290, 29, 403, 304, 267, 1613, 8, 1244, 2223, 5446, 12, 291, 2843, 826, 721, 3288, 12, 3415, 29, 6689, 63, 16236, 9, 199, 199, 533, 6624, 10193, 13832, 3259, 792, 8, 792, 304, 272, 408, 272, 437, 16666, 19857, 8503, 12564, 1329, 14, 339, 13813, 314, 2569, 4713, 370, 6705, 3775, 314, 1329, 365, 1686, 26, 398, 627, 1448, 3351, 370, 314, 1323, 30217, 28, 16, 503, 32695, 16, 1475, 14, 267, 627, 32732, 9040, 83, 1336, 12950, 9040, 83, 339, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 8468, 282, 1686, 16666, 19857, 8503, 503, 986, 719, 12564, 1329, 315, 1323, 30217, 28, 16, 503, 32695, 16, 1475, 8038, 272, 789, 339, 347, 965, 63, 1078, 63, 8928, 8, 277, 12, 1329, 304, 267, 1627, 63, 1955, 12, 1627, 63, 8928, 275, 1329, 4439, 17, 467, 1329, 1988, 17, 61, 267, 892, 63, 1955, 275, 1627, 63, 1955, 267, 12950, 63, 8928, 275, 378, 267, 7956, 275, 3087, 267, 2725, 275, 1520, 398, 1642, 275, 620, 8, 1955, 1491, 17, 566, 267, 340, 1642, 14, 374, 4468, 837, 288, 1967, 275, 6206, 8, 2246, 14, 4142, 1012, 446, 11738, 288, 340, 1967, 665, 378, 503, 1967, 690, 1695, 26, 355, 372, 756, 288, 892, 63, 1955, 275, 620, 8, 1507, 9, 435, 892, 63, 1955, 59, 17, 2938, 288, 892, 63, 1955, 275, 892, 63, 1955, 1491, 24, 61, 435, 283, 16, 7, 398, 340, 440, 892, 63, 1955, 14, 13896, 837, 288, 372, 756, 398, 367, 284, 315, 1425, 8, 552, 8, 1222, 63, 1955, 2298, 881, 7956, 275, 1109, 8, 1222, 63, 1955, 59, 73, 19100, 5329, 881, 12950, 63, 8928, 847, 7956, 8592, 340, 2725, 508, 413, 26, 288, 2725, 275, 1520, 881, 916, 2725, 508, 650, 26, 288, 2725, 275, 413, 881, 916, 2725, 508, 23, 26, 288, 2725, 275, 650, 398, 372, 620, 8, 13494, 972, 63, 8928, 15786, 17, 61, 508, 1627, 63, 8928, 339, 347, 3633, 8, 277, 12, 574, 304, 267, 1613, 8, 1244, 10193, 13832, 3259, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 2125, 398, 1336, 275, 295, 14, 1431, 8, 344, 63, 264, 12, 574, 9, 267, 340, 440, 1336, 26, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 1305, 1955, 12, 2086, 25, 12, 9040, 275, 1336, 14, 20567, 12047, 344, 1955, 995, 1336, 14, 20567, 12047, 1712, 25, 995, 1336, 14, 20567, 12047, 8928, 418, 398, 340, 1305, 1955, 508, 283, 3607, 7, 503, 971, 1779, 1305, 1955, 508, 283, 33, 9084, 356, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 1006, 63, 7022, 275, 2071, 83, 5, 83, 5, 83, 2, 450, 334, 344, 1955, 12, 2086, 25, 12, 9040, 9, 267, 340, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 452, 63, 7022, 304, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459 ]
[ 199, 10941, 19857, 13, 6100, 8204, 10897, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 2649, 63, 5955, 199, 199, 646, 295, 199, 199, 504, 1639, 14, 2828, 14, 320, 696, 276, 4271, 14, 335, 14, 335, 63, 4981, 492, 11377, 63, 16236, 199, 504, 1639, 14, 1018, 14, 11346, 492, 16589, 63, 15514, 199, 504, 1639, 14, 3351, 492, 8505, 199, 504, 1639, 14, 3351, 14, 955, 492, 5024, 12, 12939, 792, 12, 9496, 199, 504, 1639, 14, 1208, 14, 2991, 492, 11179, 63, 505, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 421, 199, 344, 63, 264, 275, 295, 14, 2014, 8, 82, 16136, 2229, 48, 28, 344, 1955, 3072, 87, 91, 24, 1552, 2229, 48, 28, 1712, 25, 30, 2961, 68, 91, 17, 22441, 28, 430, 2229, 48, 28, 8928, 3072, 68, 91, 17, 1552, 22550, 199, 9339, 63, 7022, 63, 264, 275, 295, 14, 2014, 8, 82, 4289, 16, 779, 17, 13, 25, 8194, 17, 30446, 68, 91, 24, 93, 9988, 199, 199, 533, 6624, 8674, 3034, 792, 8, 5103, 792, 304, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 8468, 282, 3482, 1233, 315, 314, 1475, 5787, 56, 8038, 272, 789, 339, 347, 636, 826, 721, 277, 12, 1390, 63, 1267, 29, 403, 12, 1748, 63, 1267, 29, 403, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 1244, 8674, 3034, 792, 12, 291, 2843, 826, 721, 82, 15542, 68, 91, 20, 19204, 267, 1390, 63, 1267, 12, 1748, 63, 1267, 12, 627, 589, 12, 1011, 958, 9, 199, 199, 533, 6624, 25640, 792, 8, 792, 304, 272, 408, 272, 12134, 2257, 16666, 19857, 14617, 1329, 334, 1397, 10757, 6279, 7869, 9, 272, 710, 3211, 1475, 365, 283, 16, 2483, 5787, 1323, 56, 1323, 56, 1370, 272, 283, 16, 2483, 14, 13933, 14, 2483, 14, 2483, 7, 436, 283, 16, 13312, 56, 7, 4107, 1325, 787, 30156, 370, 272, 283, 16, 2483, 5787, 1323, 56, 1323, 56, 1370, 272, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 15199, 5579, 1471, 506, 315, 378, 2483, 5787, 1323, 56, 1323, 56, 1475, 8038, 272, 789, 339, 347, 3633, 8, 277, 12, 574, 304, 267, 1613, 8, 1244, 25640, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 2125, 267, 574, 275, 295, 14, 954, 360, 2961, 14, 6113, 83, 92, 15, 28447, 3196, 3260, 11179, 63, 505, 8, 585, 430, 267, 333, 275, 14617, 63, 7022, 63, 264, 14, 1733, 8, 585, 9, 267, 340, 333, 26, 288, 372, 1543, 83, 450, 83, 450, 83, 450, 83, 7, 450, 334, 585, 59, 16, 26, 19, 467, 574, 59, 19, 26, 22, 467, 574, 59, 22, 26, 24, 467, 574, 59, 24, 26, 709, 566, 267, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 199, 199, 533, 6624, 2223, 5446, 8, 5446, 304, 272, 408, 272, 437, 9496, 3938, 626, 4440, 282, 769, 402, 6624, 6363, 465, 2399, 3415, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 3290, 29, 403, 304, 267, 1613, 8, 1244, 2223, 5446, 12, 291, 2843, 826, 721, 3288, 12, 3415, 29, 6689, 63, 16236, 9, 199, 199, 533, 6624, 10193, 13832, 3259, 792, 8, 792, 304, 272, 408, 272, 437, 16666, 19857, 8503, 12564, 1329, 14, 339, 13813, 314, 2569, 4713, 370, 6705, 3775, 314, 1329, 365, 1686, 26, 398, 627, 1448, 3351, 370, 314, 1323, 30217, 28, 16, 503, 32695, 16, 1475, 14, 267, 627, 32732, 9040, 83, 1336, 12950, 9040, 83, 339, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 8468, 282, 1686, 16666, 19857, 8503, 503, 986, 719, 12564, 1329, 315, 1323, 30217, 28, 16, 503, 32695, 16, 1475, 8038, 272, 789, 339, 347, 965, 63, 1078, 63, 8928, 8, 277, 12, 1329, 304, 267, 1627, 63, 1955, 12, 1627, 63, 8928, 275, 1329, 4439, 17, 467, 1329, 1988, 17, 61, 267, 892, 63, 1955, 275, 1627, 63, 1955, 267, 12950, 63, 8928, 275, 378, 267, 7956, 275, 3087, 267, 2725, 275, 1520, 398, 1642, 275, 620, 8, 1955, 1491, 17, 566, 267, 340, 1642, 14, 374, 4468, 837, 288, 1967, 275, 6206, 8, 2246, 14, 4142, 1012, 446, 11738, 288, 340, 1967, 665, 378, 503, 1967, 690, 1695, 26, 355, 372, 756, 288, 892, 63, 1955, 275, 620, 8, 1507, 9, 435, 892, 63, 1955, 59, 17, 2938, 288, 892, 63, 1955, 275, 892, 63, 1955, 1491, 24, 61, 435, 283, 16, 7, 398, 340, 440, 892, 63, 1955, 14, 13896, 837, 288, 372, 756, 398, 367, 284, 315, 1425, 8, 552, 8, 1222, 63, 1955, 2298, 881, 7956, 275, 1109, 8, 1222, 63, 1955, 59, 73, 19100, 5329, 881, 12950, 63, 8928, 847, 7956, 8592, 340, 2725, 508, 413, 26, 288, 2725, 275, 1520, 881, 916, 2725, 508, 650, 26, 288, 2725, 275, 413, 881, 916, 2725, 508, 23, 26, 288, 2725, 275, 650, 398, 372, 620, 8, 13494, 972, 63, 8928, 15786, 17, 61, 508, 1627, 63, 8928, 339, 347, 3633, 8, 277, 12, 574, 304, 267, 1613, 8, 1244, 10193, 13832, 3259, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 2125, 398, 1336, 275, 295, 14, 1431, 8, 344, 63, 264, 12, 574, 9, 267, 340, 440, 1336, 26, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 1305, 1955, 12, 2086, 25, 12, 9040, 275, 1336, 14, 20567, 12047, 344, 1955, 995, 1336, 14, 20567, 12047, 1712, 25, 995, 1336, 14, 20567, 12047, 8928, 418, 398, 340, 1305, 1955, 508, 283, 3607, 7, 503, 971, 1779, 1305, 1955, 508, 283, 33, 9084, 356, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 1006, 63, 7022, 275, 2071, 83, 5, 83, 5, 83, 2, 450, 334, 344, 1955, 12, 2086, 25, 12, 9040, 9, 267, 340, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 452, 63, 7022, 304, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
danieljaouen/ansible
lib/ansible/plugins/action/package.py
48
3275
# (c) 2015, Ansible Inc, # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. from __future__ import (absolute_import, division, print_function) __metaclass__ = type from ansible.errors import AnsibleAction, AnsibleActionFail from ansible.plugins.action import ActionBase try: from __main__ import display except ImportError: from ansible.utils.display import Display display = Display() class ActionModule(ActionBase): TRANSFERS_FILES = False def run(self, tmp=None, task_vars=None): ''' handler for package operations ''' self._supports_check_mode = True self._supports_async = True result = super(ActionModule, self).run(tmp, task_vars) del tmp # tmp no longer has any effect module = self._task.args.get('use', 'auto') if module == 'auto': try: if self._task.delegate_to: # if we delegate, we should use delegated host's facts module = self._templar.template("{{hostvars['%s']['ansible_facts']['pkg_mgr']}}" % self._task.delegate_to) else: module = self._templar.template('{{ansible_facts.pkg_mgr}}') except Exception: pass # could not get it from template! try: if module == 'auto': facts = self._execute_module(module_name='setup', module_args=dict(filter='ansible_pkg_mgr', gather_subset='!all'), task_vars=task_vars) display.debug("Facts %s" % facts) module = facts.get('ansible_facts', {}).get('ansible_pkg_mgr', 'auto') if module != 'auto': if module not in self._shared_loader_obj.module_loader: raise AnsibleActionFail('Could not find a module for %s.' % module) else: # run the 'package' module new_module_args = self._task.args.copy() if 'use' in new_module_args: del new_module_args['use'] display.vvvv("Running %s" % module) result.update(self._execute_module(module_name=module, module_args=new_module_args, task_vars=task_vars, wrap_async=self._task.async_val)) else: raise AnsibleActionFail('Could not detect which package manager to use. Try gathering facts or setting the "use" option.') except AnsibleAction as e: result.update(e.result) finally: if not self._task.async_val: # remove a temporary path we created self._remove_tmp_path(self._connection._shell.tmpdir) return result
gpl-3.0
[ 3, 334, 67, 9, 6900, 12, 2622, 3277, 12, 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, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 3242, 14, 2550, 492, 2622, 3310, 12, 2622, 3310, 4874, 199, 504, 3242, 14, 5265, 14, 1287, 492, 10033, 1563, 199, 199, 893, 26, 272, 687, 636, 973, 363, 492, 2929, 199, 2590, 3545, 26, 272, 687, 3242, 14, 1208, 14, 2918, 492, 12175, 272, 2929, 275, 12175, 342, 421, 199, 533, 10033, 2377, 8, 3310, 1563, 304, 339, 9074, 5622, 38, 3960, 63, 9472, 275, 756, 339, 347, 1255, 8, 277, 12, 3529, 29, 403, 12, 2120, 63, 2936, 29, 403, 304, 267, 1449, 3016, 367, 2559, 5331, 1449, 398, 291, 423, 9823, 63, 1074, 63, 632, 275, 715, 267, 291, 423, 9823, 63, 4146, 275, 715, 398, 754, 275, 1613, 8, 3310, 2377, 12, 291, 680, 1065, 8, 2791, 12, 2120, 63, 2936, 9, 267, 2150, 3529, 221, 327, 3529, 949, 8088, 965, 1263, 7763, 398, 859, 275, 291, 423, 1765, 14, 589, 14, 362, 360, 1180, 297, 283, 2495, 358, 398, 340, 859, 508, 283, 2495, 356, 288, 862, 26, 355, 340, 291, 423, 1765, 14, 15286, 63, 475, 26, 221, 327, 340, 781, 13080, 12, 781, 1077, 675, 29598, 1591, 1159, 9036, 490, 859, 275, 291, 423, 26718, 14, 1160, 480, 3638, 23265, 13890, 83, 2545, 4853, 63, 5047, 2545, 4600, 63, 7755, 418, 30618, 450, 291, 423, 1765, 14, 15286, 63, 475, 9, 355, 587, 26, 490, 859, 275, 291, 423, 26718, 14, 1160, 18976, 4853, 63, 5047, 14, 4600, 63, 7755, 4863, 358, 288, 871, 2186, 26, 355, 986, 221, 327, 4293, 440, 664, 652, 687, 1978, 1, 398, 862, 26, 288, 340, 859, 508, 283, 2495, 356, 355, 9036, 275, 291, 423, 2526, 63, 578, 8, 578, 63, 354, 534, 2758, 297, 859, 63, 589, 29, 807, 8, 1541, 534, 4853, 63, 4600, 63, 7755, 297, 13082, 63, 9401, 534, 1, 452, 659, 2120, 63, 2936, 29, 1765, 63, 2936, 9, 355, 2929, 14, 1757, 480, 25821, 450, 83, 2, 450, 9036, 9, 355, 859, 275, 9036, 14, 362, 360, 4853, 63, 5047, 297, 13056, 362, 360, 4853, 63, 4600, 63, 7755, 297, 283, 2495, 358, 953, 340, 859, 1137, 283, 2495, 356, 2234, 340, 859, 440, 315, 291, 423, 5555, 63, 3422, 63, 1113, 14, 578, 63, 3422, 26, 490, 746, 2622, 3310, 4874, 360, 6531, 440, 2342, 282, 859, 367, 450, 83, 3530, 450, 859, 9, 355, 587, 26, 490, 327, 1255, 314, 283, 2491, 7, 859, 490, 892, 63, 578, 63, 589, 275, 291, 423, 1765, 14, 589, 14, 1574, 342, 490, 340, 283, 1180, 7, 315, 892, 63, 578, 63, 589, 26, 717, 2150, 892, 63, 578, 63, 589, 459, 1180, 418, 4951, 2929, 14, 30448, 480, 9602, 450, 83, 2, 450, 859, 9, 490, 754, 14, 873, 8, 277, 423, 2526, 63, 578, 8, 578, 63, 354, 29, 578, 12, 859, 63, 589, 29, 1222, 63, 578, 63, 589, 12, 2120, 63, 2936, 29, 1765, 63, 2936, 12, 4816, 63, 4146, 29, 277, 423, 1765, 14, 4146, 63, 637, 430, 288, 587, 26, 355, 746, 2622, 3310, 4874, 360, 6531, 440, 9696, 1314, 2559, 5256, 370, 675, 14, 7649, 13082, 316, 9036, 503, 4260, 314, 298, 1180, 2, 945, 2659, 398, 871, 2622, 3310, 465, 325, 26, 288, 754, 14, 873, 8, 69, 14, 1099, 9, 267, 3753, 26, 288, 340, 440, 291, 423, 1765, 14, 4146, 63, 637, 26, 355, 327, 2813, 282, 7937, 931, 781, 2737, 355, 291, 423, 2168, 63, 2791, 63, 515, 8, 277, 423, 2105, 423, 5641, 14, 8616, 9, 398, 372, 754, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 334, 67, 9, 6900, 12, 2622, 3277, 12, 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, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 3242, 14, 2550, 492, 2622, 3310, 12, 2622, 3310, 4874, 199, 504, 3242, 14, 5265, 14, 1287, 492, 10033, 1563, 199, 199, 893, 26, 272, 687, 636, 973, 363, 492, 2929, 199, 2590, 3545, 26, 272, 687, 3242, 14, 1208, 14, 2918, 492, 12175, 272, 2929, 275, 12175, 342, 421, 199, 533, 10033, 2377, 8, 3310, 1563, 304, 339, 9074, 5622, 38, 3960, 63, 9472, 275, 756, 339, 347, 1255, 8, 277, 12, 3529, 29, 403, 12, 2120, 63, 2936, 29, 403, 304, 267, 1449, 3016, 367, 2559, 5331, 1449, 398, 291, 423, 9823, 63, 1074, 63, 632, 275, 715, 267, 291, 423, 9823, 63, 4146, 275, 715, 398, 754, 275, 1613, 8, 3310, 2377, 12, 291, 680, 1065, 8, 2791, 12, 2120, 63, 2936, 9, 267, 2150, 3529, 221, 327, 3529, 949, 8088, 965, 1263, 7763, 398, 859, 275, 291, 423, 1765, 14, 589, 14, 362, 360, 1180, 297, 283, 2495, 358, 398, 340, 859, 508, 283, 2495, 356, 288, 862, 26, 355, 340, 291, 423, 1765, 14, 15286, 63, 475, 26, 221, 327, 340, 781, 13080, 12, 781, 1077, 675, 29598, 1591, 1159, 9036, 490, 859, 275, 291, 423, 26718, 14, 1160, 480, 3638, 23265, 13890, 83, 2545, 4853, 63, 5047, 2545, 4600, 63, 7755, 418, 30618, 450, 291, 423, 1765, 14, 15286, 63, 475, 9, 355, 587, 26, 490, 859, 275, 291, 423, 26718, 14, 1160, 18976, 4853, 63, 5047, 14, 4600, 63, 7755, 4863, 358, 288, 871, 2186, 26, 355, 986, 221, 327, 4293, 440, 664, 652, 687, 1978, 1, 398, 862, 26, 288, 340, 859, 508, 283, 2495, 356, 355, 9036, 275, 291, 423, 2526, 63, 578, 8, 578, 63, 354, 534, 2758, 297, 859, 63, 589, 29, 807, 8, 1541, 534, 4853, 63, 4600, 63, 7755, 297, 13082, 63, 9401, 534, 1, 452, 659, 2120, 63, 2936, 29, 1765, 63, 2936, 9, 355, 2929, 14, 1757, 480, 25821, 450, 83, 2, 450, 9036, 9, 355, 859, 275, 9036, 14, 362, 360, 4853, 63, 5047, 297, 13056, 362, 360, 4853, 63, 4600, 63, 7755, 297, 283, 2495, 358, 953, 340, 859, 1137, 283, 2495, 356, 2234, 340, 859, 440, 315, 291, 423, 5555, 63, 3422, 63, 1113, 14, 578, 63, 3422, 26, 490, 746, 2622, 3310, 4874, 360, 6531, 440, 2342, 282, 859, 367, 450, 83, 3530, 450, 859, 9, 355, 587, 26, 490, 327, 1255, 314, 283, 2491, 7, 859, 490, 892, 63, 578, 63, 589, 275, 291, 423, 1765, 14, 589, 14, 1574, 342, 490, 340, 283, 1180, 7, 315, 892, 63, 578, 63, 589, 26, 717, 2150, 892, 63, 578, 63, 589, 459, 1180, 418, 4951, 2929, 14, 30448, 480, 9602, 450, 83, 2, 450, 859, 9, 490, 754, 14, 873, 8, 277, 423, 2526, 63, 578, 8, 578, 63, 354, 29, 578, 12, 859, 63, 589, 29, 1222, 63, 578, 63, 589, 12, 2120, 63, 2936, 29, 1765, 63, 2936, 12, 4816, 63, 4146, 29, 277, 423, 1765, 14, 4146, 63, 637, 430, 288, 587, 26, 355, 746, 2622, 3310, 4874, 360, 6531, 440, 9696, 1314, 2559, 5256, 370, 675, 14, 7649, 13082, 316, 9036, 503, 4260, 314, 298, 1180, 2, 945, 2659, 398, 871, 2622, 3310, 465, 325, 26, 288, 754, 14, 873, 8, 69, 14, 1099, 9, 267, 3753, 26, 288, 340, 440, 291, 423, 1765, 14, 4146, 63, 637, 26, 355, 327, 2813, 282, 7937, 931, 781, 2737, 355, 291, 423, 2168, 63, 2791, 63, 515, 8, 277, 423, 2105, 423, 5641, 14, 8616, 9, 398, 372, 754, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
jtpaasch/armyguys
armyguys/cli/commands/loadbalancers.py
1
4802
# -*- coding: utf-8 -*- """Commands for managing load balancers.""" import click from ...jobs import loadbalancers as loadbalancer_jobs from ...jobs.exceptions import AwsError from ...jobs.exceptions import ImproperlyConfigured from ...jobs.exceptions import MissingKey from ...jobs.exceptions import Non200Response from ...jobs.exceptions import PermissionDenied from ...jobs.exceptions import ResourceAlreadyExists from ...jobs.exceptions import ResourceDoesNotExist from ...jobs.exceptions import ResourceNotCreated from ...jobs.exceptions import ResourceNotDeleted from ...jobs.exceptions import WaitTimedOut from .. import utils @click.group() def loadbalancers(): """Manage load balancers.""" pass @loadbalancers.command(name="list") @click.option( "--profile", help="An AWS profile to connect with.") @click.option( "--access-key-id", help="An AWS access key ID.") @click.option( "--access-key-secret", help="An AWS access key secret.") def list_load_balancers( profile=None, access_key_id=None, access_key_secret=None): """List load balancers.""" aws_profile = utils.get_profile(profile, access_key_id, access_key_secret) try: records = loadbalancer_jobs.fetch_all(aws_profile) except PermissionDenied: msg = "You don't have permission to view load balancers." raise click.ClickException(msg) except (MissingKey, Non200Response) as error: raise click.ClickException(str(error)) except AwsError as error: raise click.ClickException(str(error)) if records: for record in records: display_name = loadbalancer_jobs.get_display_name(record) click.echo(display_name) @loadbalancers.command(name="create") @click.argument("name") @click.option( "--listen", multiple=True, help="PROTOCOL:PORT") @click.option( "--security-group", multiple=True, help="A security group.") @click.option( "--zone", multiple=True, help="An availability zone.") @click.option( "--subnet", multiple=True, help="A subnet.") @click.option( "--vpc", help="A VPC.") @click.option( "--tag", multiple=True, help="KEY:VALUE") @click.option( "--profile", help="An AWS profile to connect with.") @click.option( "--access-key-id", help="An AWS access key ID.") @click.option( "--access-key-secret", help="An AWS access key secret.") def create_load_balancer( name, listen=None, security_group=None, zone=None, subnet=None, vpc=None, tag=None, profile=None, access_key_id=None, access_key_secret=None): """Create load balancers.""" aws_profile = utils.get_profile(profile, access_key_id, access_key_secret) tags = utils.parse_tags(tag) listeners = utils.parse_listeners(listen) try: records = loadbalancer_jobs.create( aws_profile, name, listeners, security_group, zone, subnet, vpc) except PermissionDenied: msg = "You don't have permission to create load balancers." raise click.ClickException(msg) except (MissingKey, Non200Response) as error: raise click.ClickException(str(error)) except AwsError as error: raise click.ClickException(str(error)) except (ResourceDoesNotExist, ResourceAlreadyExists, ResourceNotCreated) as error: raise click.ClickException(str(error)) if records: for record in records: display_name = loadbalancer_jobs.get_display_name(record) click.echo(display_name) @loadbalancers.command(name="delete") @click.argument("name") @click.option( "--profile", help="An AWS profile to connect with.") @click.option( "--access-key-id", help="An AWS access key ID.") @click.option( "--access-key-secret", help="An AWS access key secret.") def delete_load_balancer( name, profile=None, access_key_id=None, access_key_secret=None): """Delete load balancers.""" aws_profile = utils.get_profile(profile, access_key_id, access_key_secret) try: loadbalancer_jobs.delete(aws_profile, name) except PermissionDenied: msg = "You don't have permission to delete load balancers." raise click.ClickException(msg) except (MissingKey, Non200Response) as error: raise click.ClickException(str(error)) except AwsError as error: raise click.ClickException(str(error)) except (ResourceDoesNotExist, ResourceNotDeleted) as error: raise click.ClickException(str(error)) except WaitTimedOut as error: raise click.ClickException(str(error))
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 14680, 367, 28453, 2248, 8091, 23102, 1041, 199, 199, 646, 8968, 199, 199, 504, 2263, 6920, 492, 2248, 29674, 465, 2248, 11841, 63, 6920, 199, 199, 504, 2263, 6920, 14, 3924, 492, 437, 3569, 547, 199, 504, 2263, 6920, 14, 3924, 492, 11897, 199, 504, 2263, 6920, 14, 3924, 492, 15626, 1197, 199, 504, 2263, 6920, 14, 3924, 492, 10172, 1840, 2364, 199, 504, 2263, 6920, 14, 3924, 492, 23724, 199, 504, 2263, 6920, 14, 3924, 492, 7337, 16760, 7965, 199, 504, 2263, 6920, 14, 3924, 492, 7337, 7400, 199, 504, 2263, 6920, 14, 3924, 492, 7337, 1763, 10502, 199, 504, 2263, 6920, 14, 3924, 492, 7337, 1763, 17735, 199, 504, 2263, 6920, 14, 3924, 492, 13144, 28682, 2204, 199, 199, 504, 2508, 492, 3778, 421, 199, 32, 4891, 14, 923, 342, 199, 318, 2248, 29674, 837, 272, 408, 20588, 2248, 8091, 23102, 1041, 272, 986, 421, 199, 32, 912, 29674, 14, 1531, 8, 354, 628, 513, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2913, 401, 272, 1720, 628, 2493, 10168, 4690, 370, 4907, 543, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 344, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 2870, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 4731, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 7565, 2685, 199, 318, 769, 63, 912, 63, 29674, 8, 267, 4690, 29, 403, 12, 267, 2879, 63, 498, 63, 344, 29, 403, 12, 267, 2879, 63, 498, 63, 4731, 29, 403, 304, 272, 408, 1296, 2248, 8091, 23102, 1041, 272, 11488, 63, 2913, 275, 3778, 14, 362, 63, 2913, 8, 2913, 12, 2879, 63, 498, 63, 344, 12, 2879, 63, 498, 63, 4731, 9, 339, 862, 26, 267, 5767, 275, 2248, 11841, 63, 6920, 14, 3535, 63, 452, 8, 7231, 63, 2913, 9, 272, 871, 23724, 26, 267, 1499, 275, 298, 5556, 2793, 1133, 1172, 4983, 370, 2455, 2248, 8091, 23102, 2122, 267, 746, 8968, 14, 12040, 1726, 8, 1328, 9, 272, 871, 334, 7718, 1197, 12, 10172, 1840, 2364, 9, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 272, 871, 437, 3569, 547, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 339, 340, 5767, 26, 267, 367, 2777, 315, 5767, 26, 288, 2929, 63, 354, 275, 2248, 11841, 63, 6920, 14, 362, 63, 2918, 63, 354, 8, 3059, 9, 288, 8968, 14, 7878, 8, 2918, 63, 354, 9, 421, 199, 32, 912, 29674, 14, 1531, 8, 354, 628, 981, 531, 199, 32, 4891, 14, 2094, 480, 354, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 5859, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 9583, 26, 3657, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 4416, 13, 923, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 33, 6391, 1572, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2619, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 2493, 14962, 5718, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 5327, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 33, 6303, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 11742, 401, 272, 1720, 628, 33, 19209, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 1450, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 3078, 26, 7041, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2913, 401, 272, 1720, 628, 2493, 10168, 4690, 370, 4907, 543, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 344, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 2870, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 4731, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 7565, 2685, 199, 318, 1218, 63, 912, 63, 11841, 8, 267, 536, 12, 267, 6938, 29, 403, 12, 267, 6391, 63, 923, 29, 403, 12, 267, 5718, 29, 403, 12, 267, 6303, 29, 403, 12, 267, 12830, 29, 403, 12, 267, 1947, 29, 403, 12, 267, 4690, 29, 403, 12, 267, 2879, 63, 498, 63, 344, 29, 403, 12, 267, 2879, 63, 498, 63, 4731, 29, 403, 304, 272, 408, 2499, 2248, 8091, 23102, 1041, 272, 11488, 63, 2913, 275, 3778, 14, 362, 63, 2913, 8, 2913, 12, 2879, 63, 498, 63, 344, 12, 2879, 63, 498, 63, 4731, 9, 339, 3762, 275, 3778, 14, 1122, 63, 2969, 8, 1450, 9, 272, 19946, 275, 3778, 14, 1122, 63, 17301, 8, 5859, 9, 2286, 862, 26, 267, 5767, 275, 2248, 11841, 63, 6920, 14, 981, 8, 288, 11488, 63, 2913, 12, 288, 536, 12, 288, 19946, 12, 288, 6391, 63, 923, 12, 288, 5718, 12, 288, 6303, 12, 288, 12830, 9, 272, 871, 23724, 26, 267, 1499, 275, 298, 5556, 2793, 1133, 1172, 4983, 370, 1218, 2248, 8091, 23102, 2122, 267, 746, 8968, 14, 12040, 1726, 8, 1328, 9, 272, 871, 334, 7718, 1197, 12, 10172, 1840, 2364, 9, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 272, 871, 437, 3569, 547, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 272, 871, 334, 4031, 7400, 12, 7337, 16760, 7965, 12, 7337, 1763, 10502, 9, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 339, 340, 5767, 26, 267, 367, 2777, 315, 5767, 26, 288, 2929, 63, 354, 275, 2248, 11841, 63, 6920, 14, 362, 63, 2918, 63, 354, 8, 3059, 9, 288, 8968, 14, 7878, 8, 2918, 63, 354, 9, 421, 199, 32, 912, 29674, 14, 1531, 8, 354, 628, 1807, 531, 199, 32, 4891, 14, 2094, 480, 354, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2913, 401, 272, 1720, 628, 2493, 10168, 4690, 370, 4907, 543, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 344, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 2870, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 4731, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 7565, 2685, 199, 318, 3145, 63, 912, 63 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 14680, 367, 28453, 2248, 8091, 23102, 1041, 199, 199, 646, 8968, 199, 199, 504, 2263, 6920, 492, 2248, 29674, 465, 2248, 11841, 63, 6920, 199, 199, 504, 2263, 6920, 14, 3924, 492, 437, 3569, 547, 199, 504, 2263, 6920, 14, 3924, 492, 11897, 199, 504, 2263, 6920, 14, 3924, 492, 15626, 1197, 199, 504, 2263, 6920, 14, 3924, 492, 10172, 1840, 2364, 199, 504, 2263, 6920, 14, 3924, 492, 23724, 199, 504, 2263, 6920, 14, 3924, 492, 7337, 16760, 7965, 199, 504, 2263, 6920, 14, 3924, 492, 7337, 7400, 199, 504, 2263, 6920, 14, 3924, 492, 7337, 1763, 10502, 199, 504, 2263, 6920, 14, 3924, 492, 7337, 1763, 17735, 199, 504, 2263, 6920, 14, 3924, 492, 13144, 28682, 2204, 199, 199, 504, 2508, 492, 3778, 421, 199, 32, 4891, 14, 923, 342, 199, 318, 2248, 29674, 837, 272, 408, 20588, 2248, 8091, 23102, 1041, 272, 986, 421, 199, 32, 912, 29674, 14, 1531, 8, 354, 628, 513, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2913, 401, 272, 1720, 628, 2493, 10168, 4690, 370, 4907, 543, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 344, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 2870, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 4731, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 7565, 2685, 199, 318, 769, 63, 912, 63, 29674, 8, 267, 4690, 29, 403, 12, 267, 2879, 63, 498, 63, 344, 29, 403, 12, 267, 2879, 63, 498, 63, 4731, 29, 403, 304, 272, 408, 1296, 2248, 8091, 23102, 1041, 272, 11488, 63, 2913, 275, 3778, 14, 362, 63, 2913, 8, 2913, 12, 2879, 63, 498, 63, 344, 12, 2879, 63, 498, 63, 4731, 9, 339, 862, 26, 267, 5767, 275, 2248, 11841, 63, 6920, 14, 3535, 63, 452, 8, 7231, 63, 2913, 9, 272, 871, 23724, 26, 267, 1499, 275, 298, 5556, 2793, 1133, 1172, 4983, 370, 2455, 2248, 8091, 23102, 2122, 267, 746, 8968, 14, 12040, 1726, 8, 1328, 9, 272, 871, 334, 7718, 1197, 12, 10172, 1840, 2364, 9, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 272, 871, 437, 3569, 547, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 339, 340, 5767, 26, 267, 367, 2777, 315, 5767, 26, 288, 2929, 63, 354, 275, 2248, 11841, 63, 6920, 14, 362, 63, 2918, 63, 354, 8, 3059, 9, 288, 8968, 14, 7878, 8, 2918, 63, 354, 9, 421, 199, 32, 912, 29674, 14, 1531, 8, 354, 628, 981, 531, 199, 32, 4891, 14, 2094, 480, 354, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 5859, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 9583, 26, 3657, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 4416, 13, 923, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 33, 6391, 1572, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2619, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 2493, 14962, 5718, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 5327, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 33, 6303, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 11742, 401, 272, 1720, 628, 33, 19209, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 1450, 401, 272, 3663, 29, 549, 12, 272, 1720, 628, 3078, 26, 7041, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2913, 401, 272, 1720, 628, 2493, 10168, 4690, 370, 4907, 543, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 344, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 2870, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 4731, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 7565, 2685, 199, 318, 1218, 63, 912, 63, 11841, 8, 267, 536, 12, 267, 6938, 29, 403, 12, 267, 6391, 63, 923, 29, 403, 12, 267, 5718, 29, 403, 12, 267, 6303, 29, 403, 12, 267, 12830, 29, 403, 12, 267, 1947, 29, 403, 12, 267, 4690, 29, 403, 12, 267, 2879, 63, 498, 63, 344, 29, 403, 12, 267, 2879, 63, 498, 63, 4731, 29, 403, 304, 272, 408, 2499, 2248, 8091, 23102, 1041, 272, 11488, 63, 2913, 275, 3778, 14, 362, 63, 2913, 8, 2913, 12, 2879, 63, 498, 63, 344, 12, 2879, 63, 498, 63, 4731, 9, 339, 3762, 275, 3778, 14, 1122, 63, 2969, 8, 1450, 9, 272, 19946, 275, 3778, 14, 1122, 63, 17301, 8, 5859, 9, 2286, 862, 26, 267, 5767, 275, 2248, 11841, 63, 6920, 14, 981, 8, 288, 11488, 63, 2913, 12, 288, 536, 12, 288, 19946, 12, 288, 6391, 63, 923, 12, 288, 5718, 12, 288, 6303, 12, 288, 12830, 9, 272, 871, 23724, 26, 267, 1499, 275, 298, 5556, 2793, 1133, 1172, 4983, 370, 1218, 2248, 8091, 23102, 2122, 267, 746, 8968, 14, 12040, 1726, 8, 1328, 9, 272, 871, 334, 7718, 1197, 12, 10172, 1840, 2364, 9, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 272, 871, 437, 3569, 547, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 272, 871, 334, 4031, 7400, 12, 7337, 16760, 7965, 12, 7337, 1763, 10502, 9, 465, 1125, 26, 267, 746, 8968, 14, 12040, 1726, 8, 495, 8, 705, 430, 339, 340, 5767, 26, 267, 367, 2777, 315, 5767, 26, 288, 2929, 63, 354, 275, 2248, 11841, 63, 6920, 14, 362, 63, 2918, 63, 354, 8, 3059, 9, 288, 8968, 14, 7878, 8, 2918, 63, 354, 9, 421, 199, 32, 912, 29674, 14, 1531, 8, 354, 628, 1807, 531, 199, 32, 4891, 14, 2094, 480, 354, 531, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2913, 401, 272, 1720, 628, 2493, 10168, 4690, 370, 4907, 543, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 344, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 2870, 2685, 199, 32, 4891, 14, 1422, 8, 272, 4320, 2732, 13, 498, 13, 4731, 401, 272, 1720, 628, 2493, 10168, 2879, 790, 7565, 2685, 199, 318, 3145, 63, 912, 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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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 ]
Glottotopia/aagd
moin/local/moin/build/lib.linux-x86_64-2.6/MoinMoin/support/xappy/marshall.py
2
1315
#!/usr/bin/env python # # Copyright (C) 2007 Lemur Consulting Ltd # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. r"""marshall.py: Marshal values into strings """ __docformat__ = "restructuredtext en" import math import xapian from replaylog import log as _log def float_to_string(value): """Marshall a floating point number to a string which sorts in the appropriate manner. """ return _log(xapian.sortable_serialise, value) def date_to_string(date): """Marshall a date to a string which sorts in the appropriate manner. """ return '%04d%02d%02d' % (date.year, date.month, date.day)
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 202, 199, 3, 202, 199, 3, 1898, 334, 35, 9, 10219, 491, 5633, 300, 1448, 83, 427, 316, 12126, 202, 199, 3, 202, 199, 3, 961, 2240, 365, 2867, 2032, 27, 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, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 202, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 202, 199, 3, 202, 199, 3, 961, 2240, 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, 20712, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 3180, 202, 199, 3, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 202, 199, 3, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 11315, 13, 10067, 8217, 14, 202, 199, 82, 624, 28128, 452, 14, 647, 26, 16794, 12753, 1338, 1901, 3326, 2999, 199, 624, 202, 199, 363, 21841, 363, 275, 298, 26854, 655, 2, 2999, 199, 646, 3473, 202, 199, 646, 671, 1246, 290, 202, 199, 504, 24331, 793, 492, 943, 465, 485, 793, 2999, 199, 318, 2069, 63, 475, 63, 875, 8, 585, 304, 1128, 408, 10570, 609, 452, 282, 8402, 2376, 1329, 370, 282, 1059, 1314, 30313, 315, 314, 1128, 5827, 30800, 14, 2958, 408, 1128, 372, 485, 793, 8, 32751, 290, 14, 3191, 461, 63, 2171, 572, 12, 574, 9, 2999, 199, 318, 1434, 63, 475, 63, 875, 8, 602, 304, 1128, 408, 10570, 609, 452, 282, 1434, 370, 282, 1059, 1314, 30313, 315, 314, 5827, 30800, 14, 2958, 408, 1128, 372, 1543, 966, 68, 5, 996, 68, 5, 996, 68, 7, 450, 334, 602, 14, 3403, 12, 1434, 14, 4482, 12, 1434, 14, 2977, 9, 1223, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 202, 199, 3, 202, 199, 3, 1898, 334, 35, 9, 10219, 491, 5633, 300, 1448, 83, 427, 316, 12126, 202, 199, 3, 202, 199, 3, 961, 2240, 365, 2867, 2032, 27, 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, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 202, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 202, 199, 3, 202, 199, 3, 961, 2240, 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, 20712, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 3180, 202, 199, 3, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 202, 199, 3, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 11315, 13, 10067, 8217, 14, 202, 199, 82, 624, 28128, 452, 14, 647, 26, 16794, 12753, 1338, 1901, 3326, 2999, 199, 624, 202, 199, 363, 21841, 363, 275, 298, 26854, 655, 2, 2999, 199, 646, 3473, 202, 199, 646, 671, 1246, 290, 202, 199, 504, 24331, 793, 492, 943, 465, 485, 793, 2999, 199, 318, 2069, 63, 475, 63, 875, 8, 585, 304, 1128, 408, 10570, 609, 452, 282, 8402, 2376, 1329, 370, 282, 1059, 1314, 30313, 315, 314, 1128, 5827, 30800, 14, 2958, 408, 1128, 372, 485, 793, 8, 32751, 290, 14, 3191, 461, 63, 2171, 572, 12, 574, 9, 2999, 199, 318, 1434, 63, 475, 63, 875, 8, 602, 304, 1128, 408, 10570, 609, 452, 282, 1434, 370, 282, 1059, 1314, 30313, 315, 314, 5827, 30800, 14, 2958, 408, 1128, 372, 1543, 966, 68, 5, 996, 68, 5, 996, 68, 7, 450, 334, 602, 14, 3403, 12, 1434, 14, 4482, 12, 1434, 14, 2977, 9, 1223, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
oew1v07/scikit-image
doc/source/random_gallery.py
37
1328
# Generate a javascript snippet that links to a random gallery example import os import glob base = os.path.abspath(os.path.dirname(__file__)) example_dir = os.path.join(base, 'auto_examples') js_fn = os.path.join(base, '_static/random.js') javascript = '''\ function insert_gallery() { var images = {{IMAGES}}; var links = {{LINKS}}; ix = Math.floor(Math.random() * images.length); document.write( '{{GALLERY_DIV}}'.replace('IMG', images[ix]).replace('URL', links[ix]) ); console.log('{{GALLERY_DIV}}'.replace('IMG', images[ix]).replace('URL', links[ix])); }; ''' gallery_div = '''\ <div class="gallery_image"> <a href="URL"><img src="IMG"/></a> </div>\ ''' examples = glob.glob(os.path.join(example_dir, 'plot_*.py')) images, links = [], [] image_url = 'http://scikit-image.org/docs/dev/_images/%s.png' link_url = 'http://scikit-image.org/docs/dev/auto_examples/%s.html' for e in examples: e = os.path.basename(e) e = e[:-len('.py')] images.append(image_url % e) links.append(link_url % e) javascript = javascript.replace('{{IMAGES}}', str(images)) javascript = javascript.replace('{{LINKS}}', str(links)) javascript = javascript.replace('{{GALLERY_DIV}}', ''.join(gallery_div.split('\n'))) f = open(js_fn, 'w') f.write(javascript) f.close()
bsd-3-clause
[ 3, 7958, 282, 18910, 17440, 626, 6220, 370, 282, 2196, 486, 17787, 2893, 199, 199, 646, 747, 199, 646, 5739, 199, 199, 1095, 275, 747, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 3475, 3460, 493, 8964, 199, 2694, 63, 694, 275, 747, 14, 515, 14, 904, 8, 1095, 12, 283, 2495, 63, 8589, 358, 199, 3596, 63, 2324, 275, 747, 14, 515, 14, 904, 8, 1095, 12, 2513, 1986, 15, 2355, 14, 3596, 358, 199, 199, 9554, 275, 18087, 8410, 805, 5518, 63, 25372, 342, 469, 2126, 2729, 5935, 275, 8448, 1469, 5383, 4863, 27, 2126, 2729, 6220, 275, 8448, 7916, 51, 4863, 27, 10817, 20593, 275, 21066, 14, 11289, 8, 18568, 14, 2355, 342, 627, 5935, 14, 1267, 2736, 2126, 2213, 14, 952, 8, 199, 7, 3638, 39, 1761, 9418, 63, 27051, 4863, 1370, 1814, 360, 26246, 297, 5935, 59, 1148, 6575, 1814, 360, 2632, 297, 6220, 59, 1148, 566, 2126, 20682, 10817, 8559, 14, 793, 18976, 39, 1761, 9418, 63, 27051, 4863, 1370, 1814, 360, 26246, 297, 5935, 59, 1148, 6575, 1814, 360, 2632, 297, 6220, 59, 1148, 2459, 27, 2043, 16735, 199, 199, 2344, 199, 199, 25372, 63, 3015, 275, 18087, 199, 28, 3015, 1021, 628, 25372, 63, 1569, 1743, 489, 665, 65, 4369, 628, 2632, 8186, 4060, 2928, 628, 26246, 15313, 2957, 65, 30, 199, 1108, 3015, 3072, 199, 2344, 199, 199, 8589, 275, 5739, 14, 6463, 8, 736, 14, 515, 14, 904, 8, 2694, 63, 694, 12, 283, 2798, 63, 4856, 647, 1333, 199, 199, 4782, 12, 6220, 275, 990, 942, 199, 1569, 63, 633, 275, 283, 1014, 921, 551, 3258, 390, 13, 1569, 14, 1308, 15, 4757, 15, 2374, 15607, 4782, 3149, 83, 14, 4524, 7, 199, 1073, 63, 633, 275, 283, 1014, 921, 551, 3258, 390, 13, 1569, 14, 1308, 15, 4757, 15, 2374, 15, 2495, 63, 8589, 3149, 83, 14, 1360, 7, 199, 199, 509, 325, 315, 7251, 26, 272, 325, 275, 747, 14, 515, 14, 4846, 8, 69, 9, 272, 325, 275, 325, 4439, 552, 5175, 647, 5440, 339, 5935, 14, 740, 8, 1569, 63, 633, 450, 325, 9, 272, 6220, 14, 740, 8, 1073, 63, 633, 450, 325, 9, 199, 199, 9554, 275, 18910, 14, 1814, 18976, 1469, 5383, 29223, 620, 8, 4782, 430, 199, 9554, 275, 18910, 14, 1814, 18976, 7916, 51, 29223, 620, 8, 4614, 430, 199, 9554, 275, 18910, 14, 1814, 18976, 39, 1761, 9418, 63, 27051, 29223, 6522, 904, 8, 25372, 63, 3015, 14, 1294, 2258, 78, 7058, 199, 199, 70, 275, 1551, 8, 3596, 63, 2324, 12, 283, 87, 358, 199, 70, 14, 952, 8, 9554, 9, 199, 70, 14, 1600, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 7958, 282, 18910, 17440, 626, 6220, 370, 282, 2196, 486, 17787, 2893, 199, 199, 646, 747, 199, 646, 5739, 199, 199, 1095, 275, 747, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 3475, 3460, 493, 8964, 199, 2694, 63, 694, 275, 747, 14, 515, 14, 904, 8, 1095, 12, 283, 2495, 63, 8589, 358, 199, 3596, 63, 2324, 275, 747, 14, 515, 14, 904, 8, 1095, 12, 2513, 1986, 15, 2355, 14, 3596, 358, 199, 199, 9554, 275, 18087, 8410, 805, 5518, 63, 25372, 342, 469, 2126, 2729, 5935, 275, 8448, 1469, 5383, 4863, 27, 2126, 2729, 6220, 275, 8448, 7916, 51, 4863, 27, 10817, 20593, 275, 21066, 14, 11289, 8, 18568, 14, 2355, 342, 627, 5935, 14, 1267, 2736, 2126, 2213, 14, 952, 8, 199, 7, 3638, 39, 1761, 9418, 63, 27051, 4863, 1370, 1814, 360, 26246, 297, 5935, 59, 1148, 6575, 1814, 360, 2632, 297, 6220, 59, 1148, 566, 2126, 20682, 10817, 8559, 14, 793, 18976, 39, 1761, 9418, 63, 27051, 4863, 1370, 1814, 360, 26246, 297, 5935, 59, 1148, 6575, 1814, 360, 2632, 297, 6220, 59, 1148, 2459, 27, 2043, 16735, 199, 199, 2344, 199, 199, 25372, 63, 3015, 275, 18087, 199, 28, 3015, 1021, 628, 25372, 63, 1569, 1743, 489, 665, 65, 4369, 628, 2632, 8186, 4060, 2928, 628, 26246, 15313, 2957, 65, 30, 199, 1108, 3015, 3072, 199, 2344, 199, 199, 8589, 275, 5739, 14, 6463, 8, 736, 14, 515, 14, 904, 8, 2694, 63, 694, 12, 283, 2798, 63, 4856, 647, 1333, 199, 199, 4782, 12, 6220, 275, 990, 942, 199, 1569, 63, 633, 275, 283, 1014, 921, 551, 3258, 390, 13, 1569, 14, 1308, 15, 4757, 15, 2374, 15607, 4782, 3149, 83, 14, 4524, 7, 199, 1073, 63, 633, 275, 283, 1014, 921, 551, 3258, 390, 13, 1569, 14, 1308, 15, 4757, 15, 2374, 15, 2495, 63, 8589, 3149, 83, 14, 1360, 7, 199, 199, 509, 325, 315, 7251, 26, 272, 325, 275, 747, 14, 515, 14, 4846, 8, 69, 9, 272, 325, 275, 325, 4439, 552, 5175, 647, 5440, 339, 5935, 14, 740, 8, 1569, 63, 633, 450, 325, 9, 272, 6220, 14, 740, 8, 1073, 63, 633, 450, 325, 9, 199, 199, 9554, 275, 18910, 14, 1814, 18976, 1469, 5383, 29223, 620, 8, 4782, 430, 199, 9554, 275, 18910, 14, 1814, 18976, 7916, 51, 29223, 620, 8, 4614, 430, 199, 9554, 275, 18910, 14, 1814, 18976, 39, 1761, 9418, 63, 27051, 29223, 6522, 904, 8, 25372, 63, 3015, 14, 1294, 2258, 78, 7058, 199, 199, 70, 275, 1551, 8, 3596, 63, 2324, 12, 283, 87, 358, 199, 70, 14, 952, 8, 9554, 9, 199, 70, 14, 1600, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
mapzen/vector-datasource
vectordatasource/collision.py
2
2159
from vectordatasource.meta.python import FilterCompiler from vectordatasource.meta.python import create_matcher class CollisionRanker(object): def __init__(self, cases): def _output_fn(datum): return datum['index'] index = 1 matchers = [] for case in cases: assert isinstance(case, dict) # if it's a reserved block, check the syntax and assert that the # indices are reserved. note that reserved block indices are # inclusive of both the "from" and "to". if '_reserved' in case: # reserved should be the only key, to avoid confusion with # filter blocks. assert case.keys() == ['_reserved'] reserved = case['_reserved'] # we can reserve either a specific range of indices, or a # count. if reserved.keys() == ['count']: # just increment the index to skip. we can't collide with # anything, so there's no assertion to make. index += reserved['count'] else: from_index = reserved['from'] to_index = reserved['to'] # check that we've not used this index already. assert index <= from_index, "Unable to satisfy reserved " \ "block: already at index %d, and wanted to reserve " \ "from %d." % (index, from_index) # start counting again past the "to" reserved index. index = to_index + 1 else: matcher = create_matcher( {'filter': case, 'index': index}, _output_fn) matchers.append(matcher) index += 1 filter_compiler = FilterCompiler() ast_fn, compiled_fn = filter_compiler.compile( matchers, 'collision_rank') self.fn = compiled_fn def __call__(self, feature): shape, props, fid = feature meta = None return self.fn(shape, props, fid, meta)
mit
[ 504, 373, 449, 2181, 292, 305, 616, 14, 2024, 14, 1548, 492, 9388, 9131, 199, 504, 373, 449, 2181, 292, 305, 616, 14, 2024, 14, 1548, 492, 1218, 63, 16135, 421, 199, 533, 3626, 23656, 50, 290, 2570, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 5560, 304, 267, 347, 485, 1199, 63, 2324, 8, 18945, 304, 288, 372, 18908, 459, 1080, 418, 398, 1478, 275, 413, 267, 31679, 275, 942, 267, 367, 1930, 315, 5560, 26, 288, 702, 1228, 8, 2546, 12, 1211, 9, 953, 327, 340, 652, 1159, 282, 4644, 1853, 12, 1104, 314, 6302, 436, 702, 626, 314, 288, 327, 4918, 787, 4644, 14, 5317, 626, 4644, 1853, 4918, 787, 288, 327, 20728, 402, 3865, 314, 298, 504, 2, 436, 298, 475, 1674, 288, 340, 2513, 10421, 7, 315, 1930, 26, 355, 327, 4644, 1077, 506, 314, 1454, 790, 12, 370, 5126, 26314, 543, 355, 327, 2457, 5664, 14, 355, 702, 1930, 14, 1612, 342, 508, 4044, 10421, 418, 2234, 4644, 275, 1930, 8680, 10421, 418, 2234, 327, 781, 883, 32606, 1902, 282, 2488, 1425, 402, 4918, 12, 503, 282, 355, 327, 2338, 14, 355, 340, 4644, 14, 1612, 342, 508, 788, 835, 2565, 490, 327, 2951, 11609, 314, 1478, 370, 3372, 14, 781, 883, 1133, 1048, 8409, 543, 490, 327, 7003, 12, 880, 2337, 1159, 949, 14412, 370, 1852, 14, 490, 1478, 847, 4644, 459, 835, 418, 2234, 587, 26, 490, 687, 63, 1080, 275, 4644, 459, 504, 418, 490, 370, 63, 1080, 275, 4644, 459, 475, 418, 4951, 327, 1104, 626, 781, 9064, 440, 1202, 642, 1478, 2575, 14, 490, 702, 1478, 2695, 687, 63, 1080, 12, 298, 6005, 370, 23082, 4644, 298, 971, 717, 298, 1457, 26, 2575, 737, 1478, 450, 68, 12, 436, 13632, 370, 32606, 298, 971, 717, 298, 504, 450, 68, 2122, 450, 334, 1080, 12, 687, 63, 1080, 9, 4951, 327, 1343, 23190, 4020, 13541, 314, 298, 475, 2, 4644, 1478, 14, 490, 1478, 275, 370, 63, 1080, 435, 413, 953, 587, 26, 355, 15990, 275, 1218, 63, 16135, 8, 490, 791, 1541, 356, 1930, 12, 283, 1080, 356, 1478, 1386, 485, 1199, 63, 2324, 9, 355, 31679, 14, 740, 8, 16135, 9, 355, 1478, 847, 413, 398, 2457, 63, 5772, 275, 9388, 9131, 342, 267, 6073, 63, 2324, 12, 10311, 63, 2324, 275, 2457, 63, 5772, 14, 2014, 8, 288, 31679, 12, 283, 761, 23656, 63, 4648, 358, 398, 291, 14, 2324, 275, 10311, 63, 2324, 339, 347, 636, 1250, 721, 277, 12, 3878, 304, 267, 2215, 12, 10792, 12, 8289, 275, 3878, 267, 3404, 275, 488, 267, 372, 291, 14, 2324, 8, 1392, 12, 10792, 12, 8289, 12, 3404, 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 ]
[ 373, 449, 2181, 292, 305, 616, 14, 2024, 14, 1548, 492, 9388, 9131, 199, 504, 373, 449, 2181, 292, 305, 616, 14, 2024, 14, 1548, 492, 1218, 63, 16135, 421, 199, 533, 3626, 23656, 50, 290, 2570, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 5560, 304, 267, 347, 485, 1199, 63, 2324, 8, 18945, 304, 288, 372, 18908, 459, 1080, 418, 398, 1478, 275, 413, 267, 31679, 275, 942, 267, 367, 1930, 315, 5560, 26, 288, 702, 1228, 8, 2546, 12, 1211, 9, 953, 327, 340, 652, 1159, 282, 4644, 1853, 12, 1104, 314, 6302, 436, 702, 626, 314, 288, 327, 4918, 787, 4644, 14, 5317, 626, 4644, 1853, 4918, 787, 288, 327, 20728, 402, 3865, 314, 298, 504, 2, 436, 298, 475, 1674, 288, 340, 2513, 10421, 7, 315, 1930, 26, 355, 327, 4644, 1077, 506, 314, 1454, 790, 12, 370, 5126, 26314, 543, 355, 327, 2457, 5664, 14, 355, 702, 1930, 14, 1612, 342, 508, 4044, 10421, 418, 2234, 4644, 275, 1930, 8680, 10421, 418, 2234, 327, 781, 883, 32606, 1902, 282, 2488, 1425, 402, 4918, 12, 503, 282, 355, 327, 2338, 14, 355, 340, 4644, 14, 1612, 342, 508, 788, 835, 2565, 490, 327, 2951, 11609, 314, 1478, 370, 3372, 14, 781, 883, 1133, 1048, 8409, 543, 490, 327, 7003, 12, 880, 2337, 1159, 949, 14412, 370, 1852, 14, 490, 1478, 847, 4644, 459, 835, 418, 2234, 587, 26, 490, 687, 63, 1080, 275, 4644, 459, 504, 418, 490, 370, 63, 1080, 275, 4644, 459, 475, 418, 4951, 327, 1104, 626, 781, 9064, 440, 1202, 642, 1478, 2575, 14, 490, 702, 1478, 2695, 687, 63, 1080, 12, 298, 6005, 370, 23082, 4644, 298, 971, 717, 298, 1457, 26, 2575, 737, 1478, 450, 68, 12, 436, 13632, 370, 32606, 298, 971, 717, 298, 504, 450, 68, 2122, 450, 334, 1080, 12, 687, 63, 1080, 9, 4951, 327, 1343, 23190, 4020, 13541, 314, 298, 475, 2, 4644, 1478, 14, 490, 1478, 275, 370, 63, 1080, 435, 413, 953, 587, 26, 355, 15990, 275, 1218, 63, 16135, 8, 490, 791, 1541, 356, 1930, 12, 283, 1080, 356, 1478, 1386, 485, 1199, 63, 2324, 9, 355, 31679, 14, 740, 8, 16135, 9, 355, 1478, 847, 413, 398, 2457, 63, 5772, 275, 9388, 9131, 342, 267, 6073, 63, 2324, 12, 10311, 63, 2324, 275, 2457, 63, 5772, 14, 2014, 8, 288, 31679, 12, 283, 761, 23656, 63, 4648, 358, 398, 291, 14, 2324, 275, 10311, 63, 2324, 339, 347, 636, 1250, 721, 277, 12, 3878, 304, 267, 2215, 12, 10792, 12, 8289, 275, 3878, 267, 3404, 275, 488, 267, 372, 291, 14, 2324, 8, 1392, 12, 10792, 12, 8289, 12, 3404, 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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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
skimpax/python-rfxcom
tests/protocol/test_lighting1.py
1
2738
from unittest import TestCase from rfxcom.protocol.lighting1 import Lighting1 from rfxcom.exceptions import (InvalidPacketLength, UnknownPacketSubtype, UnknownPacketType) class Lighting1TestCase(TestCase): def setUp(self): self.data = bytearray(b'\x07\x10\x00\x01\x41\x0A\x01\x40') self.parser = Lighting1() def test_parse_frame_x10_on(self): self.data = bytearray(b'\x07\x10\x00\x01\x41\x0A\x01\x40') self.assertTrue(self.parser.validate_packet(self.data)) self.assertTrue(self.parser.can_handle(self.data)) result = self.parser.load(self.data) self.assertEquals(result, { 'id': 'A10', 'packet_length': 7, 'packet_type': 16, 'packet_type_name': "Lighting1 sensors", 'packet_subtype': 0, 'packet_subtype_name': "X10 Lightning", 'sequence_number': 1, 'house_code': 'A', 'unit_code': 10, 'command': 1, 'command_text': "On", 'signal_level': 4 }) self.assertEquals(str(self.parser), "<Lighting1 ID:A10>") def test_parse_frame_x10_off(self): self.data = bytearray(b'\x07\x10\x00\x03\x41\x0E\x00\x50') self.assertTrue(self.parser.validate_packet(self.data)) self.assertTrue(self.parser.can_handle(self.data)) result = self.parser.load(self.data) self.assertEquals(result, { 'id': 'A14', 'packet_length': 7, 'packet_type': 16, 'packet_type_name': "Lighting1 sensors", 'packet_subtype': 0, 'packet_subtype_name': "X10 Lightning", 'sequence_number': 3, 'house_code': 'A', 'unit_code': 14, 'command': 0, 'command_text': "Off", 'signal_level': 5, }) self.assertEquals(str(self.parser), "<Lighting1 ID:A14>") def test_validate_bytes_short(self): data = self.data[:1] with self.assertRaises(InvalidPacketLength): self.parser.validate_packet(data) def test_validate_unkown_packet_type(self): self.data[1] = 0xFF self.assertFalse(self.parser.can_handle(self.data)) with self.assertRaises(UnknownPacketType): self.parser.validate_packet(self.data) def test_validate_unknown_sub_type(self): self.data[2] = 0xFF self.assertFalse(self.parser.can_handle(self.data)) with self.assertRaises(UnknownPacketSubtype): self.parser.validate_packet(self.data) def test_log_namer(self): self.assertEquals(self.parser.log.name, 'rfxcom.protocol.Lighting1')
bsd-3-clause
[ 504, 2882, 492, 7640, 199, 199, 504, 519, 12220, 957, 14, 3922, 14, 4040, 316, 17, 492, 29684, 316, 17, 199, 199, 504, 519, 12220, 957, 14, 3924, 492, 334, 3364, 2726, 4625, 12, 14831, 2726, 2610, 466, 12, 3044, 14831, 22327, 9, 421, 199, 533, 29684, 316, 17, 1746, 8, 1746, 304, 339, 347, 3613, 8, 277, 304, 398, 291, 14, 576, 275, 11640, 8, 66, 1154, 88, 1780, 60, 88, 709, 60, 88, 383, 60, 88, 614, 60, 88, 2953, 60, 88, 16, 33, 60, 88, 614, 60, 88, 2167, 358, 267, 291, 14, 2087, 275, 29684, 316, 17, 342, 339, 347, 511, 63, 1122, 63, 1943, 63, 88, 709, 63, 265, 8, 277, 304, 398, 291, 14, 576, 275, 11640, 8, 66, 1154, 88, 1780, 60, 88, 709, 60, 88, 383, 60, 88, 614, 60, 88, 2953, 60, 88, 16, 33, 60, 88, 614, 60, 88, 2167, 358, 398, 291, 14, 1815, 8, 277, 14, 2087, 14, 3502, 63, 6253, 8, 277, 14, 576, 430, 267, 291, 14, 1815, 8, 277, 14, 2087, 14, 2425, 63, 2479, 8, 277, 14, 576, 430, 267, 754, 275, 291, 14, 2087, 14, 912, 8, 277, 14, 576, 9, 398, 291, 14, 2947, 8, 1099, 12, 469, 288, 283, 344, 356, 283, 33, 709, 297, 288, 283, 6253, 63, 1267, 356, 1520, 12, 288, 283, 6253, 63, 466, 356, 3193, 12, 288, 283, 6253, 63, 466, 63, 354, 356, 298, 16393, 316, 17, 19678, 401, 288, 283, 6253, 63, 10512, 356, 378, 12, 288, 283, 6253, 63, 10512, 63, 354, 356, 298, 56, 709, 29684, 1835, 401, 288, 283, 4041, 63, 1955, 356, 413, 12, 288, 283, 6740, 63, 600, 356, 283, 33, 297, 288, 283, 3248, 63, 600, 356, 1616, 12, 288, 283, 1531, 356, 413, 12, 288, 283, 1531, 63, 505, 356, 298, 3314, 401, 288, 283, 4653, 63, 1896, 356, 841, 267, 3828, 398, 291, 14, 2947, 8, 495, 8, 277, 14, 2087, 395, 3886, 16393, 316, 17, 2870, 26, 33, 709, 9579, 339, 347, 511, 63, 1122, 63, 1943, 63, 88, 709, 63, 1997, 8, 277, 304, 398, 291, 14, 576, 275, 11640, 8, 66, 1154, 88, 1780, 60, 88, 709, 60, 88, 383, 60, 88, 1644, 60, 88, 2953, 60, 88, 16, 37, 60, 88, 383, 60, 88, 1400, 358, 398, 291, 14, 1815, 8, 277, 14, 2087, 14, 3502, 63, 6253, 8, 277, 14, 576, 430, 267, 291, 14, 1815, 8, 277, 14, 2087, 14, 2425, 63, 2479, 8, 277, 14, 576, 430, 267, 754, 275, 291, 14, 2087, 14, 912, 8, 277, 14, 576, 9, 398, 291, 14, 2947, 8, 1099, 12, 469, 288, 283, 344, 356, 283, 33, 1079, 297, 288, 283, 6253, 63, 1267, 356, 1520, 12, 288, 283, 6253, 63, 466, 356, 3193, 12, 288, 283, 6253, 63, 466, 63, 354, 356, 298, 16393, 316, 17, 19678, 401, 288, 283, 6253, 63, 10512, 356, 378, 12, 288, 283, 6253, 63, 10512, 63, 354, 356, 298, 56, 709, 29684, 1835, 401, 288, 283, 4041, 63, 1955, 356, 650, 12, 288, 283, 6740, 63, 600, 356, 283, 33, 297, 288, 283, 3248, 63, 600, 356, 4329, 12, 288, 283, 1531, 356, 378, 12, 288, 283, 1531, 63, 505, 356, 298, 5195, 401, 288, 283, 4653, 63, 1896, 356, 959, 12, 267, 3828, 398, 291, 14, 2947, 8, 495, 8, 277, 14, 2087, 395, 3886, 16393, 316, 17, 2870, 26, 33, 1079, 9579, 339, 347, 511, 63, 3502, 63, 2394, 63, 3612, 8, 277, 304, 398, 666, 275, 291, 14, 576, 1491, 17, 61, 398, 543, 291, 14, 1855, 8, 3364, 2726, 4625, 304, 288, 291, 14, 2087, 14, 3502, 63, 6253, 8, 576, 9, 339, 347, 511, 63, 3502, 63, 1778, 944, 63, 6253, 63, 466, 8, 277, 304, 398, 291, 14, 576, 59, 17, 61, 275, 378, 9039, 398, 291, 14, 3334, 8, 277, 14, 2087, 14, 2425, 63, 2479, 8, 277, 14, 576, 430, 398, 543, 291, 14, 1855, 8, 5912, 22327, 304, 288, 291, 14, 2087, 14, 3502, 63, 6253, 8, 277, 14, 576, 9, 339, 347, 511, 63, 3502, 63, 5187, 63, 954, 63, 466, 8, 277, 304, 398, 291, 14, 576, 59, 18, 61, 275, 378, 9039, 398, 291, 14, 3334, 8, 277, 14, 2087, 14, 2425, 63, 2479, 8, 277, 14, 576, 430, 398, 543, 291, 14, 1855, 8, 5912, 2726, 2610, 466, 304, 288, 291, 14, 2087, 14, 3502, 63, 6253, 8, 277, 14, 576, 9, 339, 347, 511, 63, 793, 63, 354, 82, 8, 277, 304, 398, 291, 14, 2947, 8, 277, 14, 2087, 14, 793, 14, 354, 12, 283, 3941, 88, 957, 14, 3922, 14, 16393, 316, 17, 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 ]
[ 2882, 492, 7640, 199, 199, 504, 519, 12220, 957, 14, 3922, 14, 4040, 316, 17, 492, 29684, 316, 17, 199, 199, 504, 519, 12220, 957, 14, 3924, 492, 334, 3364, 2726, 4625, 12, 14831, 2726, 2610, 466, 12, 3044, 14831, 22327, 9, 421, 199, 533, 29684, 316, 17, 1746, 8, 1746, 304, 339, 347, 3613, 8, 277, 304, 398, 291, 14, 576, 275, 11640, 8, 66, 1154, 88, 1780, 60, 88, 709, 60, 88, 383, 60, 88, 614, 60, 88, 2953, 60, 88, 16, 33, 60, 88, 614, 60, 88, 2167, 358, 267, 291, 14, 2087, 275, 29684, 316, 17, 342, 339, 347, 511, 63, 1122, 63, 1943, 63, 88, 709, 63, 265, 8, 277, 304, 398, 291, 14, 576, 275, 11640, 8, 66, 1154, 88, 1780, 60, 88, 709, 60, 88, 383, 60, 88, 614, 60, 88, 2953, 60, 88, 16, 33, 60, 88, 614, 60, 88, 2167, 358, 398, 291, 14, 1815, 8, 277, 14, 2087, 14, 3502, 63, 6253, 8, 277, 14, 576, 430, 267, 291, 14, 1815, 8, 277, 14, 2087, 14, 2425, 63, 2479, 8, 277, 14, 576, 430, 267, 754, 275, 291, 14, 2087, 14, 912, 8, 277, 14, 576, 9, 398, 291, 14, 2947, 8, 1099, 12, 469, 288, 283, 344, 356, 283, 33, 709, 297, 288, 283, 6253, 63, 1267, 356, 1520, 12, 288, 283, 6253, 63, 466, 356, 3193, 12, 288, 283, 6253, 63, 466, 63, 354, 356, 298, 16393, 316, 17, 19678, 401, 288, 283, 6253, 63, 10512, 356, 378, 12, 288, 283, 6253, 63, 10512, 63, 354, 356, 298, 56, 709, 29684, 1835, 401, 288, 283, 4041, 63, 1955, 356, 413, 12, 288, 283, 6740, 63, 600, 356, 283, 33, 297, 288, 283, 3248, 63, 600, 356, 1616, 12, 288, 283, 1531, 356, 413, 12, 288, 283, 1531, 63, 505, 356, 298, 3314, 401, 288, 283, 4653, 63, 1896, 356, 841, 267, 3828, 398, 291, 14, 2947, 8, 495, 8, 277, 14, 2087, 395, 3886, 16393, 316, 17, 2870, 26, 33, 709, 9579, 339, 347, 511, 63, 1122, 63, 1943, 63, 88, 709, 63, 1997, 8, 277, 304, 398, 291, 14, 576, 275, 11640, 8, 66, 1154, 88, 1780, 60, 88, 709, 60, 88, 383, 60, 88, 1644, 60, 88, 2953, 60, 88, 16, 37, 60, 88, 383, 60, 88, 1400, 358, 398, 291, 14, 1815, 8, 277, 14, 2087, 14, 3502, 63, 6253, 8, 277, 14, 576, 430, 267, 291, 14, 1815, 8, 277, 14, 2087, 14, 2425, 63, 2479, 8, 277, 14, 576, 430, 267, 754, 275, 291, 14, 2087, 14, 912, 8, 277, 14, 576, 9, 398, 291, 14, 2947, 8, 1099, 12, 469, 288, 283, 344, 356, 283, 33, 1079, 297, 288, 283, 6253, 63, 1267, 356, 1520, 12, 288, 283, 6253, 63, 466, 356, 3193, 12, 288, 283, 6253, 63, 466, 63, 354, 356, 298, 16393, 316, 17, 19678, 401, 288, 283, 6253, 63, 10512, 356, 378, 12, 288, 283, 6253, 63, 10512, 63, 354, 356, 298, 56, 709, 29684, 1835, 401, 288, 283, 4041, 63, 1955, 356, 650, 12, 288, 283, 6740, 63, 600, 356, 283, 33, 297, 288, 283, 3248, 63, 600, 356, 4329, 12, 288, 283, 1531, 356, 378, 12, 288, 283, 1531, 63, 505, 356, 298, 5195, 401, 288, 283, 4653, 63, 1896, 356, 959, 12, 267, 3828, 398, 291, 14, 2947, 8, 495, 8, 277, 14, 2087, 395, 3886, 16393, 316, 17, 2870, 26, 33, 1079, 9579, 339, 347, 511, 63, 3502, 63, 2394, 63, 3612, 8, 277, 304, 398, 666, 275, 291, 14, 576, 1491, 17, 61, 398, 543, 291, 14, 1855, 8, 3364, 2726, 4625, 304, 288, 291, 14, 2087, 14, 3502, 63, 6253, 8, 576, 9, 339, 347, 511, 63, 3502, 63, 1778, 944, 63, 6253, 63, 466, 8, 277, 304, 398, 291, 14, 576, 59, 17, 61, 275, 378, 9039, 398, 291, 14, 3334, 8, 277, 14, 2087, 14, 2425, 63, 2479, 8, 277, 14, 576, 430, 398, 543, 291, 14, 1855, 8, 5912, 22327, 304, 288, 291, 14, 2087, 14, 3502, 63, 6253, 8, 277, 14, 576, 9, 339, 347, 511, 63, 3502, 63, 5187, 63, 954, 63, 466, 8, 277, 304, 398, 291, 14, 576, 59, 18, 61, 275, 378, 9039, 398, 291, 14, 3334, 8, 277, 14, 2087, 14, 2425, 63, 2479, 8, 277, 14, 576, 430, 398, 543, 291, 14, 1855, 8, 5912, 2726, 2610, 466, 304, 288, 291, 14, 2087, 14, 3502, 63, 6253, 8, 277, 14, 576, 9, 339, 347, 511, 63, 793, 63, 354, 82, 8, 277, 304, 398, 291, 14, 2947, 8, 277, 14, 2087, 14, 793, 14, 354, 12, 283, 3941, 88, 957, 14, 3922, 14, 16393, 316, 17, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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8 -*- # # (C) 2018 Red Hat Inc. # Copyright (C) 2018 Western Telematic Inc. <kenp@wti.com> # # GNU General Public License v3.0+ # # 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. # # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # # Module to execute WTI Plug Configuration Commands on WTI OOB and PDU devices. # WTI remote_management # from __future__ import absolute_import, division, print_function __metaclass__ = type ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community' } DOCUMENTATION = """ --- module: cpm_plugconfig version_added: "2.8" author: "Western Telematic Inc. (@wtinetworkgear)" short_description: Get and Set Plug Parameters on WTI OOB and PDU power devices description: - "Get and Set Plug Parameters on WTI OOB and PDU devices" options: cpm_action: description: - This is the Action to send the module. required: true choices: [ "getplugconfig", "setplugconfig" ] cpm_url: description: - This is the URL of the WTI device to send the module. required: true cpm_username: description: - This is the Username of the WTI device to send the module. cpm_password: description: - This is the Password of the WTI device to send the module. use_https: description: - Designates to use an https connection or http connection. required: false type: bool default: true validate_certs: description: - If false, SSL certificates will not be validated. This should only be used - on personally controlled sites using self-signed certificates. required: false type: bool default: true use_proxy: description: Flag to control if the lookup will observe HTTP proxy environment variables when present. required: false type: bool default: false plug_id: description: - This is the plug number that is to be manipulated For the getplugconfig command, the plug_id 'all' will return the status of all the plugs the user has rights to access. required: true plug_name: description: - The new name of the Plug. required: false plug_bootdelay: description: - On a reboot command, this is the time when a plug will turn on power, after it has been turned off. 0='0.5 Secs', 1='1 Sec', 2='2 Sec', 3='5 Sec', 4='15 Sec', 5='30 Sec', 6='1 Min', 7='2 Mins', 8='3 Mins', 9='5 Mins'. required: false choices: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] plug_default: description: - What the Plugs default state is when the device starts. 0 - Off, 1 - On. required: false choices: [ 0, 1 ] plug_bootpriority: description: - Prioritizes which plug gets its state changed first. The lower the number the higher the priority. Valid value can from 1 to the maximum number of plugs of the WTI unit. required: false """ EXAMPLES = """ # Get Plug parameters for all ports - name: Get the Plug parameters for ALL ports of a WTI Power device cpm_plugconfig: cpm_action: "getplugconfig" cpm_url: "rest.wti.com" cpm_username: "restpower" cpm_password: "restfulpowerpass12" use_https: true validate_certs: true plug_id: "all" # Get Plug parameters for port 2 - name: Get the Plug parameters for the given port of a WTI Power device cpm_plugconfig: cpm_action: "getplugconfig" cpm_url: "rest.wti.com" cpm_username: "restpower" cpm_password: "restfulpowerpass12" use_https: true validate_certs: false plug_id: "2" # Configure plug 5 - name: Configure parameters for Plug 5 on a given WTI Power device cpm_plugconfig: cpm_action: "setplugconfig" cpm_url: "rest.wti.com" cpm_username: "restpower" cpm_password: "restfulpowerpass12" use_https: true plug_id: "5" plug_name: "NewPlugNameFive" plug_bootdelay: "3" plug_default: "0" plug_bootpriority: "1" """ RETURN = """ data: description: The output JSON returned from the commands sent returned: always type: str """ import base64 import json from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_text, to_bytes, to_native from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError def assemble_json(cpmmodule, cpmresult): json_load = "" plugspassed = cpmmodule.params["plug_id"].split(",") for val in plugspassed: if len(json_load) == 0: json_load = '{"plugs": [' else: json_load = '%s,' % (json_load) json_load = '%s{"plug": "%s"' % (json_load, to_native(val)) if cpmmodule.params["plug_name"] is not None: json_load = '%s,"plugname": "%s"' % (json_load, to_native(cpmmodule.params["plug_name"])) if cpmmodule.params["plug_bootdelay"] is not None: json_load = '%s,"bootdelay": "%s"' % (json_load, to_native(cpmmodule.params["plug_bootdelay"])) if cpmmodule.params["plug_default"] is not None: json_load = '%s,"default": "%s"' % (json_load, to_native(cpmmodule.params["plug_default"])) if cpmmodule.params["plug_bootpriority"] is not None: json_load = '%s,"bootpriority": "%s"' % (json_load, to_native(cpmmodule.params["plug_bootpriority"])) json_load = '%s}' % (json_load) if len(json_load) > 0: json_load = '%s]}' % (json_load) return json_load def run_module(): # define the available arguments/parameters that a user can pass to # the module module_args = dict( cpm_action=dict(choices=['getplugconfig', 'setplugconfig'], required=True), cpm_url=dict(type='str', required=True), cpm_username=dict(type='str', required=True), cpm_password=dict(type='str', required=True, no_log=True), plug_id=dict(type='str', required=True), plug_name=dict(type='str', required=False), plug_bootdelay=dict(type='int', required=False, default=None, choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), plug_default=dict(type='int', required=False, default=None, choices=[0, 1]), plug_bootpriority=dict(type='int', required=False, default=None), use_https=dict(type='bool', default=True), validate_certs=dict(type='bool', default=True), use_proxy=dict(type='bool', default=False) ) result = dict( changed=False, data='', debug='' ) module = AnsibleModule(argument_spec=module_args, supports_check_mode=True) if module.check_mode: return result auth = to_text(base64.b64encode(to_bytes('{0}:{1}'.format(to_native(module.params['cpm_username']), to_native(module.params['cpm_password'])), errors='surrogate_or_strict'))) if module.params['use_https'] is True: protocol = "https://" else: protocol = "http://" Payload = None if (module.params['cpm_action'] == 'getplugconfig'): fullurl = ("%s%s/api/v2/config/powerplugconfig" % (protocol, to_native(module.params['cpm_url']))) if (module.params['plug_id'].lower() != 'all'): fullurl = '%s?plug=%s' % (fullurl, to_native(module.params['plug_id'])) method = 'GET' elif (module.params['cpm_action'] == 'setplugconfig'): Payload = assemble_json(module, result) result['debug'] = Payload fullurl = ("%s%s/api/v2/config/powerplugconfig" % (protocol, to_native(module.params['cpm_url']))) method = 'POST' try: response = open_url(fullurl, data=Payload, method=method, validate_certs=module.params['validate_certs'], use_proxy=module.params['use_proxy'], headers={'Content-Type': 'application/json', 'Authorization': "Basic %s" % auth}) if (method != 'GET'): result['changed'] = True except HTTPError as e: fail_json = dict(msg='Received HTTP error for {0} : {1}'.format(fullurl, to_native(e)), changed=False) module.fail_json(**fail_json) except URLError as e: fail_json = dict(msg='Failed lookup url for {0} : {1}'.format(fullurl, to_native(e)), changed=False) module.fail_json(**fail_json) except SSLValidationError as e: fail_json = dict(msg='Error validating the server''s certificate for {0} : {1}'.format(fullurl, to_native(e)), changed=False) module.fail_json(**fail_json) except ConnectionError as e: fail_json = dict(msg='Error connecting to for {0} : {1}'.format(fullurl, to_native(e)), changed=False) module.fail_json(**fail_json) result['data'] = json.loads(response.read()) module.exit_json(**result) def main(): run_module() 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, 334, 35, 9, 14894, 9572, 13002, 3277, 14, 199, 3, 1898, 334, 35, 9, 14894, 644, 397, 1203, 23884, 3889, 3277, 14, 665, 917, 80, 32, 87, 280, 14, 957, 30, 199, 3, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 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, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 3, 199, 3, 5673, 370, 5341, 644, 13247, 7497, 1518, 11595, 5817, 83, 641, 644, 13247, 593, 5488, 436, 510, 4980, 7256, 14, 199, 3, 644, 13247, 3982, 63, 8110, 199, 3, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 199, 199, 8490, 63, 8314, 275, 469, 272, 283, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 272, 283, 1205, 356, 788, 7780, 995, 272, 283, 4946, 63, 991, 356, 283, 9387, 7, 199, 93, 199, 199, 8948, 275, 408, 199, 2595, 199, 578, 26, 286, 7073, 63, 13963, 888, 199, 1023, 63, 3270, 26, 298, 18, 14, 24, 2, 199, 2502, 26, 298, 55, 397, 1203, 23884, 3889, 3277, 14, 8593, 87, 1346, 386, 800, 29571, 2924, 199, 3612, 63, 1802, 26, 2372, 436, 2494, 7497, 1518, 3897, 641, 644, 13247, 593, 5488, 436, 510, 4980, 7074, 7256, 199, 1802, 26, 272, 446, 298, 1002, 436, 2494, 7497, 1518, 3897, 641, 644, 13247, 593, 5488, 436, 510, 4980, 7256, 2, 199, 1419, 26, 523, 286, 7073, 63, 1287, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 10033, 370, 3222, 314, 859, 14, 272, 1415, 26, 2549, 272, 3415, 26, 359, 298, 362, 13963, 888, 401, 298, 409, 13963, 888, 2, 1622, 523, 286, 7073, 63, 633, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 2851, 402, 314, 644, 13247, 2243, 370, 3222, 314, 859, 14, 272, 1415, 26, 2549, 523, 286, 7073, 63, 2473, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 29739, 402, 314, 644, 13247, 2243, 370, 3222, 314, 859, 14, 523, 286, 7073, 63, 2060, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 13635, 402, 314, 644, 13247, 2243, 370, 3222, 314, 859, 14, 523, 675, 63, 2859, 26, 272, 1369, 26, 489, 446, 29410, 2335, 370, 675, 376, 4178, 1950, 503, 1455, 1950, 14, 272, 1415, 26, 3055, 272, 730, 26, 2155, 272, 849, 26, 2549, 523, 4107, 63, 8356, 26, 272, 1369, 26, 489, 446, 982, 3055, 12, 7799, 14512, 911, 440, 506, 16468, 14, 961, 1077, 1454, 506, 1202, 489, 446, 641, 4954, 1183, 22284, 15424, 1808, 291, 13, 1737, 14512, 14, 272, 1415, 26, 3055, 272, 730, 26, 2155, 272, 849, 26, 2549, 523, 675, 63, 3280, 26, 272, 1369, 26, 18241, 370, 3304, 340, 314, 4237, 911, 2607, 4909, 3101, 4566, 3734, 2860, 1380, 3451, 14, 272, 1415, 26, 3055, 272, 730, 26, 2155, 272, 849, 26, 3055, 523, 14202, 63, 344, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 14202, 1329, 626, 365, 370, 506, 13335, 8097, 267, 2104, 314, 664, 13963, 888, 1414, 12, 314, 14202, 63, 344, 283, 452, 7, 911, 372, 314, 2004, 402, 1006, 314, 1620, 85, 458, 314, 267, 922, 965, 4481, 370, 2879, 14, 272, 1415, 26, 2549, 523, 14202, 63, 354, 26, 272, 1369, 26, 489, 446, 710, 892, 536, 402, 314, 7497, 1518, 14, 272, 1415, 26, 3055, 523, 14202, 63, 4930, 5814, 26, 272, 1369, 26, 489, 446, 4068, 282, 19457, 1414, 12, 642, 365, 314, 900, 1380, 282, 14202, 911, 7485, 641, 7074, 12, 2410, 652, 965, 2757, 19136, 2331, 14, 267, 378, 534, 16, 14, 21, 9433, 83, 297, 413, 534, 17, 9433, 297, 499, 534, 18, 9433, 297, 650, 534, 21, 9433, 297, 841, 534, 1046, 9433, 297, 959, 534, 1216, 9433, 297, 1227, 534, 17, 10195, 297, 1520, 534, 18, 603, 3617, 297, 267, 1695, 534, 19, 603, 3617, 297, 1749, 534, 21, 603, 3617, 1370, 272, 1415, 26, 3055, 272, 3415, 26, 359, 378, 12, 413, 12, 499, 12, 650, 12, 841, 12, 959, 12, 1227, 12, 1520, 12, 1695, 12, 1749, 1622, 523, 14202, 63, 885, 26, 272, 1369, 26, 489, 446, 14791, 314, 7497, 85, 458, 849, 1174, 365, 1380, 314, 2243, 9174, 14, 378, 446, 28856, 12, 413, 446, 4068, 14, 272, 1415, 26, 3055, 272, 3415, 26, 359, 378, 12, 413, 1622, 523, 14202, 63, 4930, 6693, 26, 272, 1369, 26, 489, 446, 8538, 269, 5277, 90, 397, 1314, 14202, 7545, 2399, 1174, 2896, 1642, 14, 710, 5117, 314, 1329, 314, 10948, 314, 7464, 14, 267, 4821, 574, 883, 687, 413, 370, 314, 5696, 1329, 402, 1620, 85, 458, 402, 314, 644, 13247, 4137, 14, 272, 1415, 26, 3055, 199, 624, 199, 199, 8918, 275, 408, 199, 3, 2372, 7497, 1518, 2633, 367, 1006, 8873, 199, 13, 536, 26, 2372, 314, 7497, 1518, 2633, 367, 11727, 8873, 402, 282, 644, 13247, 18879, 2243, 523, 286, 7073, 63, 13963, 888, 26, 272, 286, 7073, 63, 1287, 26, 298, 362, 13963, 888, 2, 272, 286, 7073, 63, 633, 26, 298, 3911, 14, 87, 280, 14, 957, 2, 272, 286, 7073, 63, 2473, 26, 298, 3911, 5652, 2, 272, 286, 7073, 63, 2060, 26, 298, 3911, 1893, 5652, 1529, 713, 2, 272, 675, 63, 2859, 26, 2549, 272, 4107, 63, 8356, 26, 2549, 272, 14202, 63, 344, 26, 298, 452, 2, 199, 199, 3, 2372, 7497, 1518, 2633, 367, 1844, 499, 199, 13, 536, 26, 2372, 314, 7497, 1518, 2633, 367, 314, 1627, 1844, 402, 282, 644, 13247, 18879, 2243, 523, 286, 7073, 63, 13963, 888, 26, 272, 286, 7073, 63, 1287, 26, 298, 362, 13963, 888, 2, 272, 286, 7073, 63, 633, 26, 298, 3911, 14 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 334, 35, 9, 14894, 9572, 13002, 3277, 14, 199, 3, 1898, 334, 35, 9, 14894, 644, 397, 1203, 23884, 3889, 3277, 14, 665, 917, 80, 32, 87, 280, 14, 957, 30, 199, 3, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 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, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 3, 199, 3, 5673, 370, 5341, 644, 13247, 7497, 1518, 11595, 5817, 83, 641, 644, 13247, 593, 5488, 436, 510, 4980, 7256, 14, 199, 3, 644, 13247, 3982, 63, 8110, 199, 3, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 199, 199, 8490, 63, 8314, 275, 469, 272, 283, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 272, 283, 1205, 356, 788, 7780, 995, 272, 283, 4946, 63, 991, 356, 283, 9387, 7, 199, 93, 199, 199, 8948, 275, 408, 199, 2595, 199, 578, 26, 286, 7073, 63, 13963, 888, 199, 1023, 63, 3270, 26, 298, 18, 14, 24, 2, 199, 2502, 26, 298, 55, 397, 1203, 23884, 3889, 3277, 14, 8593, 87, 1346, 386, 800, 29571, 2924, 199, 3612, 63, 1802, 26, 2372, 436, 2494, 7497, 1518, 3897, 641, 644, 13247, 593, 5488, 436, 510, 4980, 7074, 7256, 199, 1802, 26, 272, 446, 298, 1002, 436, 2494, 7497, 1518, 3897, 641, 644, 13247, 593, 5488, 436, 510, 4980, 7256, 2, 199, 1419, 26, 523, 286, 7073, 63, 1287, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 10033, 370, 3222, 314, 859, 14, 272, 1415, 26, 2549, 272, 3415, 26, 359, 298, 362, 13963, 888, 401, 298, 409, 13963, 888, 2, 1622, 523, 286, 7073, 63, 633, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 2851, 402, 314, 644, 13247, 2243, 370, 3222, 314, 859, 14, 272, 1415, 26, 2549, 523, 286, 7073, 63, 2473, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 29739, 402, 314, 644, 13247, 2243, 370, 3222, 314, 859, 14, 523, 286, 7073, 63, 2060, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 13635, 402, 314, 644, 13247, 2243, 370, 3222, 314, 859, 14, 523, 675, 63, 2859, 26, 272, 1369, 26, 489, 446, 29410, 2335, 370, 675, 376, 4178, 1950, 503, 1455, 1950, 14, 272, 1415, 26, 3055, 272, 730, 26, 2155, 272, 849, 26, 2549, 523, 4107, 63, 8356, 26, 272, 1369, 26, 489, 446, 982, 3055, 12, 7799, 14512, 911, 440, 506, 16468, 14, 961, 1077, 1454, 506, 1202, 489, 446, 641, 4954, 1183, 22284, 15424, 1808, 291, 13, 1737, 14512, 14, 272, 1415, 26, 3055, 272, 730, 26, 2155, 272, 849, 26, 2549, 523, 675, 63, 3280, 26, 272, 1369, 26, 18241, 370, 3304, 340, 314, 4237, 911, 2607, 4909, 3101, 4566, 3734, 2860, 1380, 3451, 14, 272, 1415, 26, 3055, 272, 730, 26, 2155, 272, 849, 26, 3055, 523, 14202, 63, 344, 26, 272, 1369, 26, 489, 446, 961, 365, 314, 14202, 1329, 626, 365, 370, 506, 13335, 8097, 267, 2104, 314, 664, 13963, 888, 1414, 12, 314, 14202, 63, 344, 283, 452, 7, 911, 372, 314, 2004, 402, 1006, 314, 1620, 85, 458, 314, 267, 922, 965, 4481, 370, 2879, 14, 272, 1415, 26, 2549, 523, 14202, 63, 354, 26, 272, 1369, 26, 489, 446, 710, 892, 536, 402, 314, 7497, 1518, 14, 272, 1415, 26, 3055, 523, 14202, 63, 4930, 5814, 26, 272, 1369, 26, 489, 446, 4068, 282, 19457, 1414, 12, 642, 365, 314, 900, 1380, 282, 14202, 911, 7485, 641, 7074, 12, 2410, 652, 965, 2757, 19136, 2331, 14, 267, 378, 534, 16, 14, 21, 9433, 83, 297, 413, 534, 17, 9433, 297, 499, 534, 18, 9433, 297, 650, 534, 21, 9433, 297, 841, 534, 1046, 9433, 297, 959, 534, 1216, 9433, 297, 1227, 534, 17, 10195, 297, 1520, 534, 18, 603, 3617, 297, 267, 1695, 534, 19, 603, 3617, 297, 1749, 534, 21, 603, 3617, 1370, 272, 1415, 26, 3055, 272, 3415, 26, 359, 378, 12, 413, 12, 499, 12, 650, 12, 841, 12, 959, 12, 1227, 12, 1520, 12, 1695, 12, 1749, 1622, 523, 14202, 63, 885, 26, 272, 1369, 26, 489, 446, 14791, 314, 7497, 85, 458, 849, 1174, 365, 1380, 314, 2243, 9174, 14, 378, 446, 28856, 12, 413, 446, 4068, 14, 272, 1415, 26, 3055, 272, 3415, 26, 359, 378, 12, 413, 1622, 523, 14202, 63, 4930, 6693, 26, 272, 1369, 26, 489, 446, 8538, 269, 5277, 90, 397, 1314, 14202, 7545, 2399, 1174, 2896, 1642, 14, 710, 5117, 314, 1329, 314, 10948, 314, 7464, 14, 267, 4821, 574, 883, 687, 413, 370, 314, 5696, 1329, 402, 1620, 85, 458, 402, 314, 644, 13247, 4137, 14, 272, 1415, 26, 3055, 199, 624, 199, 199, 8918, 275, 408, 199, 3, 2372, 7497, 1518, 2633, 367, 1006, 8873, 199, 13, 536, 26, 2372, 314, 7497, 1518, 2633, 367, 11727, 8873, 402, 282, 644, 13247, 18879, 2243, 523, 286, 7073, 63, 13963, 888, 26, 272, 286, 7073, 63, 1287, 26, 298, 362, 13963, 888, 2, 272, 286, 7073, 63, 633, 26, 298, 3911, 14, 87, 280, 14, 957, 2, 272, 286, 7073, 63, 2473, 26, 298, 3911, 5652, 2, 272, 286, 7073, 63, 2060, 26, 298, 3911, 1893, 5652, 1529, 713, 2, 272, 675, 63, 2859, 26, 2549, 272, 4107, 63, 8356, 26, 2549, 272, 14202, 63, 344, 26, 298, 452, 2, 199, 199, 3, 2372, 7497, 1518, 2633, 367, 1844, 499, 199, 13, 536, 26, 2372, 314, 7497, 1518, 2633, 367, 314, 1627, 1844, 402, 282, 644, 13247, 18879, 2243, 523, 286, 7073, 63, 13963, 888, 26, 272, 286, 7073, 63, 1287, 26, 298, 362, 13963, 888, 2, 272, 286, 7073, 63, 633, 26, 298, 3911, 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, 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ccountReportGeneralLedger(models.TransientModel): _inherit = "account.common.account.report" _name = "account.report.general.ledger" _description = "General Ledger Report" initial_balance = fields.Boolean(string='Include Initial Balances', help='If you selected date, this field allow you to add a row to display the amount of debit/credit/balance that precedes the filter you\'ve set.') sortby = fields.Selection([('sort_date', 'Date'), ('sort_journal_partner', 'Journal & Partner')], string='Sort by', required=True, default='sort_date') journal_ids = fields.Many2many('account.journal', 'account_report_general_ledger_journal_rel', 'account_id', 'journal_id', string='Journals', required=True) def _print_report(self, data): data = self.pre_print_report(data) data['form'].update(self.read(['initial_balance', 'sortby'])[0]) if data['form'].get('initial_balance') and not data['form'].get('date_from'): raise UserError(_("You must define a Start Date")) records = self.env[data['model']].browse(data.get('ids', [])) return self.env['report'].with_context(landscape=True).get_action(records, 'account.report_generalledger', data=data)
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 504, 28811, 492, 1504, 12, 1709, 12, 485, 199, 504, 28811, 14, 3924, 492, 29908, 421, 199, 533, 9973, 7457, 14109, 44, 379, 836, 8, 992, 14, 14612, 14928, 1685, 304, 272, 485, 6486, 275, 298, 2048, 14, 2330, 14, 2048, 14, 3070, 2, 272, 485, 354, 275, 298, 2048, 14, 3070, 14, 10706, 14, 28771, 2, 272, 485, 1802, 275, 298, 14109, 491, 379, 836, 11774, 2, 339, 2536, 63, 7358, 275, 1504, 14, 4082, 8, 875, 534, 7826, 6026, 23928, 13236, 297, 2511, 1720, 534, 3917, 1265, 4895, 1434, 12, 642, 901, 2040, 1265, 370, 1050, 282, 1962, 370, 2929, 314, 5982, 402, 24732, 15, 9365, 15, 7358, 626, 9222, 3424, 314, 2457, 1265, 3985, 432, 663, 2659, 272, 4069, 991, 275, 1504, 14, 7713, 8318, 3191, 63, 602, 297, 283, 2506, 659, 661, 3191, 63, 7067, 63, 3899, 297, 283, 25909, 1253, 31351, 2665, 1059, 534, 14376, 701, 297, 1415, 29, 549, 12, 849, 534, 3191, 63, 602, 358, 272, 9605, 63, 1580, 275, 1504, 14, 4089, 18, 3479, 360, 2048, 14, 7067, 297, 283, 2048, 63, 3070, 63, 10706, 63, 28771, 63, 7067, 63, 3369, 297, 283, 2048, 63, 344, 297, 283, 7067, 63, 344, 297, 1059, 534, 5691, 31212, 297, 1415, 29, 549, 9, 339, 347, 485, 1361, 63, 3070, 8, 277, 12, 666, 304, 267, 666, 275, 291, 14, 657, 63, 1361, 63, 3070, 8, 576, 9, 267, 666, 459, 964, 2278, 873, 8, 277, 14, 739, 2941, 2747, 63, 7358, 297, 283, 3191, 991, 25945, 16, 566, 267, 340, 666, 459, 964, 2278, 362, 360, 2747, 63, 7358, 358, 436, 440, 666, 459, 964, 2278, 362, 360, 602, 63, 504, 735, 288, 746, 29908, 6115, 5556, 1471, 5627, 282, 7707, 6148, 2237, 267, 5767, 275, 291, 14, 1813, 59, 576, 459, 1238, 418, 1055, 4570, 8, 576, 14, 362, 360, 1580, 297, 15927, 267, 372, 291, 14, 1813, 459, 3070, 2278, 1045, 63, 1100, 8, 9688, 3588, 29, 549, 680, 362, 63, 1287, 8, 6502, 12, 283, 2048, 14, 3070, 63, 2038, 1843, 836, 297, 666, 29, 576, 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 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 504, 28811, 492, 1504, 12, 1709, 12, 485, 199, 504, 28811, 14, 3924, 492, 29908, 421, 199, 533, 9973, 7457, 14109, 44, 379, 836, 8, 992, 14, 14612, 14928, 1685, 304, 272, 485, 6486, 275, 298, 2048, 14, 2330, 14, 2048, 14, 3070, 2, 272, 485, 354, 275, 298, 2048, 14, 3070, 14, 10706, 14, 28771, 2, 272, 485, 1802, 275, 298, 14109, 491, 379, 836, 11774, 2, 339, 2536, 63, 7358, 275, 1504, 14, 4082, 8, 875, 534, 7826, 6026, 23928, 13236, 297, 2511, 1720, 534, 3917, 1265, 4895, 1434, 12, 642, 901, 2040, 1265, 370, 1050, 282, 1962, 370, 2929, 314, 5982, 402, 24732, 15, 9365, 15, 7358, 626, 9222, 3424, 314, 2457, 1265, 3985, 432, 663, 2659, 272, 4069, 991, 275, 1504, 14, 7713, 8318, 3191, 63, 602, 297, 283, 2506, 659, 661, 3191, 63, 7067, 63, 3899, 297, 283, 25909, 1253, 31351, 2665, 1059, 534, 14376, 701, 297, 1415, 29, 549, 12, 849, 534, 3191, 63, 602, 358, 272, 9605, 63, 1580, 275, 1504, 14, 4089, 18, 3479, 360, 2048, 14, 7067, 297, 283, 2048, 63, 3070, 63, 10706, 63, 28771, 63, 7067, 63, 3369, 297, 283, 2048, 63, 344, 297, 283, 7067, 63, 344, 297, 1059, 534, 5691, 31212, 297, 1415, 29, 549, 9, 339, 347, 485, 1361, 63, 3070, 8, 277, 12, 666, 304, 267, 666, 275, 291, 14, 657, 63, 1361, 63, 3070, 8, 576, 9, 267, 666, 459, 964, 2278, 873, 8, 277, 14, 739, 2941, 2747, 63, 7358, 297, 283, 3191, 991, 25945, 16, 566, 267, 340, 666, 459, 964, 2278, 362, 360, 2747, 63, 7358, 358, 436, 440, 666, 459, 964, 2278, 362, 360, 602, 63, 504, 735, 288, 746, 29908, 6115, 5556, 1471, 5627, 282, 7707, 6148, 2237, 267, 5767, 275, 291, 14, 1813, 59, 576, 459, 1238, 418, 1055, 4570, 8, 576, 14, 362, 360, 1580, 297, 15927, 267, 372, 291, 14, 1813, 459, 3070, 2278, 1045, 63, 1100, 8, 9688, 3588, 29, 549, 680, 362, 63, 1287, 8, 6502, 12, 283, 2048, 14, 3070, 63, 2038, 1843, 836, 297, 666, 29, 576, 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, 0 ]
[ 1, 1, 1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/openerp_server
openerp/osv/osv.py
8
8809
# -*- 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/>. # ############################################################################## #.apidoc title: Objects Services (OSV) from functools import wraps import logging from psycopg2 import IntegrityError, errorcodes import orm import openerp import openerp.netsvc as netsvc import openerp.pooler as pooler import openerp.sql_db as sql_db from openerp.tools.translate import translate from openerp.osv.orm import MetaModel, Model, TransientModel, AbstractModel import openerp.exceptions _logger = logging.getLogger(__name__) # Deprecated. class except_osv(Exception): def __init__(self, name, value): self.name = name self.value = value self.args = (name, value) service = None class object_proxy(object): def __init__(self): global service service = self def check(f): @wraps(f) def wrapper(self, dbname, *args, **kwargs): """ Wraps around OSV functions and normalises a few exceptions """ def tr(src, ttype): # We try to do the same as the _(), but without the frame # inspection, since we aready are wrapping an osv function # trans_obj = self.get('ir.translation') cannot work yet :( ctx = {} if not kwargs: if args and isinstance(args[-1], dict): ctx = args[-1] elif isinstance(kwargs, dict): ctx = kwargs.get('context', {}) uid = 1 if args and isinstance(args[0], (long, int)): uid = args[0] lang = ctx and ctx.get('lang') if not (lang or hasattr(src, '__call__')): return src # We open a *new* cursor here, one reason is that failed SQL # queries (as in IntegrityError) will invalidate the current one. cr = False if hasattr(src, '__call__'): # callable. We need to find the right parameters to call # the orm._sql_message(self, cr, uid, ids, context) function, # or we skip.. # our signature is f(osv_pool, dbname [,uid, obj, method, args]) try: if args and len(args) > 1: obj = self.get(args[1]) if len(args) > 3 and isinstance(args[3], (long, int, list)): ids = args[3] else: ids = [] cr = sql_db.db_connect(dbname).cursor() return src(obj, cr, uid, ids, context=(ctx or {})) except Exception: pass finally: if cr: cr.close() return False # so that the original SQL error will # be returned, it is the best we have. try: cr = sql_db.db_connect(dbname).cursor() res = translate(cr, name=False, source_type=ttype, lang=lang, source=src) if res: return res else: return src finally: if cr: cr.close() def _(src): return tr(src, 'code') try: if pooler.get_pool(dbname)._init: raise except_osv('Database not ready', 'Currently, this database is not fully loaded and can not be used.') return f(self, dbname, *args, **kwargs) except orm.except_orm, inst: raise except_osv(inst.name, inst.value) except except_osv: raise except IntegrityError, inst: osv_pool = pooler.get_pool(dbname) for key in osv_pool._sql_error.keys(): if key in inst[0]: netsvc.abort_response(1, _('Constraint Error'), 'warning', tr(osv_pool._sql_error[key], 'sql_constraint') or inst[0]) if inst.pgcode in (errorcodes.NOT_NULL_VIOLATION, errorcodes.FOREIGN_KEY_VIOLATION, errorcodes.RESTRICT_VIOLATION): msg = _('The operation cannot be completed, probably due to the following:\n- deletion: you may be trying to delete a record while other records still reference it\n- creation/update: a mandatory field is not correctly set') _logger.debug("IntegrityError", exc_info=True) try: errortxt = inst.pgerror.replace('«','"').replace('»','"') if '"public".' in errortxt: context = errortxt.split('"public".')[1] model_name = table = context.split('"')[1] else: last_quote_end = errortxt.rfind('"') last_quote_begin = errortxt.rfind('"', 0, last_quote_end) model_name = table = errortxt[last_quote_begin+1:last_quote_end].strip() model = table.replace("_",".") model_obj = osv_pool.get(model) if model_obj: model_name = model_obj._description or model_obj._name msg += _('\n\n[object with reference: %s - %s]') % (model_name, model) except Exception: pass netsvc.abort_response(1, _('Integrity Error'), 'warning', msg) else: netsvc.abort_response(1, _('Integrity Error'), 'warning', inst[0]) except Exception: _logger.exception("Uncaught exception") raise return wrapper def execute_cr(self, cr, uid, obj, method, *args, **kw): object = pooler.get_pool(cr.dbname).get(obj) if not object: raise except_osv('Object Error', 'Object %s doesn\'t exist' % str(obj)) return getattr(object, method)(cr, uid, *args, **kw) def execute_kw(self, db, uid, obj, method, args, kw=None): return self.execute(db, uid, obj, method, *args, **kw or {}) @check def execute(self, db, uid, obj, method, *args, **kw): cr = pooler.get_db(db).cursor() try: try: if method.startswith('_'): raise except_osv('Access Denied', 'Private methods (such as %s) cannot be called remotely.' % (method,)) res = self.execute_cr(cr, uid, obj, method, *args, **kw) if res is None: _logger.warning('The method %s of the object %s can not return `None` !', method, obj) cr.commit() except Exception: cr.rollback() raise finally: cr.close() return res def exec_workflow_cr(self, cr, uid, obj, method, *args): wf_service = netsvc.LocalService("workflow") return wf_service.trg_validate(uid, obj, args[0], method, cr) @check def exec_workflow(self, db, uid, obj, method, *args): cr = pooler.get_db(db).cursor() try: try: res = self.exec_workflow_cr(cr, uid, obj, method, *args) cr.commit() except Exception: cr.rollback() raise finally: cr.close() return res # deprecated - for backward compatibility. osv = Model osv_memory = TransientModel osv_abstract = AbstractModel # ;-) def start_object_proxy(): object_proxy() # 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, 199, 31827, 27703, 679, 2538, 26, 26794, 21813, 334, 3100, 54, 9, 199, 199, 504, 9143, 492, 14018, 199, 646, 2050, 199, 504, 15492, 18, 492, 26864, 12, 1125, 6021, 199, 199, 646, 9813, 199, 646, 5166, 199, 646, 5166, 14, 846, 10599, 465, 1851, 10599, 199, 646, 5166, 14, 555, 79, 1435, 465, 1115, 79, 1435, 199, 646, 5166, 14, 3009, 63, 697, 465, 3875, 63, 697, 199, 504, 5166, 14, 2537, 14, 5275, 492, 9028, 199, 504, 5166, 14, 4795, 14, 1025, 492, 6288, 1685, 12, 5822, 12, 19894, 14928, 1685, 12, 11836, 1685, 199, 646, 5166, 14, 3924, 199, 199, 63, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 3, 17993, 14, 199, 533, 871, 63, 4795, 8, 1726, 304, 272, 347, 636, 826, 721, 277, 12, 536, 12, 574, 304, 267, 291, 14, 354, 275, 536, 267, 291, 14, 585, 275, 574, 267, 291, 14, 589, 275, 334, 354, 12, 574, 9, 199, 199, 1364, 275, 488, 199, 199, 533, 909, 63, 3280, 8, 785, 304, 272, 347, 636, 826, 721, 277, 304, 267, 2288, 2435, 267, 2435, 275, 291, 339, 347, 1104, 8, 70, 304, 267, 768, 13582, 8, 70, 9, 267, 347, 4975, 8, 277, 12, 21842, 12, 627, 589, 12, 1011, 958, 304, 288, 408, 644, 8146, 6818, 4403, 54, 3423, 436, 3293, 1388, 282, 9284, 4967, 288, 408, 953, 347, 5651, 8, 2164, 12, 17860, 304, 355, 327, 2136, 862, 370, 886, 314, 2011, 465, 314, 485, 1062, 1325, 1928, 314, 2787, 355, 327, 5261, 10303, 12, 3967, 781, 282, 2179, 787, 19696, 376, 9506, 805, 355, 327, 1752, 63, 1113, 275, 291, 14, 362, 360, 723, 14, 6893, 358, 3913, 1736, 5966, 520, 8, 355, 4027, 275, 1052, 355, 340, 440, 2074, 26, 490, 340, 1249, 436, 1228, 8, 589, 1988, 17, 467, 1211, 304, 717, 4027, 275, 1249, 1988, 17, 61, 355, 916, 1228, 8, 958, 12, 1211, 304, 490, 4027, 275, 2074, 14, 362, 360, 1100, 297, 5009, 2234, 1747, 275, 413, 355, 340, 1249, 436, 1228, 8, 589, 59, 16, 467, 334, 2809, 12, 1109, 2298, 490, 1747, 275, 1249, 59, 16, 61, 2234, 6339, 275, 4027, 436, 4027, 14, 362, 360, 4159, 358, 355, 340, 440, 334, 4159, 503, 2688, 8, 2164, 12, 2560, 1250, 363, 8109, 490, 372, 2928, 2234, 327, 2136, 1551, 282, 627, 1222, 10, 3920, 2348, 12, 1373, 4499, 365, 626, 3405, 5385, 355, 327, 9212, 334, 305, 315, 26864, 9, 911, 24841, 314, 1453, 1373, 14, 355, 2467, 275, 756, 2234, 340, 2688, 8, 2164, 12, 2560, 1250, 12168, 490, 327, 4550, 14, 2136, 1929, 370, 2342, 314, 2451, 2633, 370, 1240, 490, 327, 314, 221, 9813, 423, 3009, 63, 1188, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 9, 805, 12, 490, 327, 503, 781, 3372, 703, 490, 327, 4154, 4955, 365, 289, 8, 4795, 63, 2293, 12, 21842, 359, 12, 1535, 12, 1559, 12, 1083, 12, 1249, 566, 490, 862, 26, 717, 340, 1249, 436, 822, 8, 589, 9, 690, 413, 26, 1169, 1559, 275, 291, 14, 362, 8, 589, 59, 17, 566, 1169, 340, 822, 8, 589, 9, 690, 650, 436, 1228, 8, 589, 59, 19, 467, 334, 2809, 12, 1109, 12, 769, 2298, 1816, 2762, 275, 1249, 59, 19, 61, 1169, 587, 26, 1816, 2762, 275, 942, 717, 2467, 275, 3875, 63, 697, 14, 697, 63, 2242, 8, 13238, 680, 3937, 342, 717, 372, 2928, 8, 1113, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 2687, 3799, 503, 17003, 490, 871, 2186, 26, 717, 986, 490, 3753, 26, 717, 340, 2467, 26, 2467, 14, 1600, 342, 4951, 372, 756, 327, 880, 626, 314, 3379, 5385, 1125, 911, 639, 327, 506, 2138, 12, 652, 365, 314, 5526, 781, 1172, 14, 2234, 862, 26, 490, 2467, 275, 3875, 63, 697, 14, 697, 63, 2242, 8, 13238, 680, 3937, 342, 490, 522, 275, 9028, 8, 1556, 12, 536, 29, 797, 12, 1350, 63, 466, 29, 21002, 12, 2511, 6339, 29, 4159, 12, 1350, 29, 2164, 9, 490, 340, 522, 26, 717, 372, 522, 490, 587, 26, 717, 372, 2928, 355, 3753, 26, 490, 340, 2467, 26, 2467, 14, 1600, 342, 953, 347, 12561, 2164, 304, 355, 372, 5651, 8, 2164, 12, 283, 600, 358, 953, 862, 26, 355, 340, 1115, 79, 1435, 14, 362, 63, 2293, 8, 13238, 10445, 826, 26, 490, 746, 871, 63, 4795, 360, 7243, 440, 10144, 297, 283, 31499, 12, 642, 3050, 365, 440, 9999, 6511, 436, 883, 440, 506, 1202, 2659, 355, 372, 289, 8, 277, 12, 21842, 12, 627, 589, 12, 1011, 958, 9, 288, 871, 9813, 14, 2590, 63, 1025, 12, 2727, 26, 355, 746, 871, 63, 4795, 8, 3615, 14, 354, 12, 2727, 14, 585, 9, 288, 871, 871, 63, 4795, 26, 355, 746, 288, 871, 26864, 12, 2727, 26, 355, 9506, 63, 2293, 275, 1115, 79, 1435, 14, 362, 63, 2293, 8, 13238 ]
[ 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, 199, 31827, 27703, 679, 2538, 26, 26794, 21813, 334, 3100, 54, 9, 199, 199, 504, 9143, 492, 14018, 199, 646, 2050, 199, 504, 15492, 18, 492, 26864, 12, 1125, 6021, 199, 199, 646, 9813, 199, 646, 5166, 199, 646, 5166, 14, 846, 10599, 465, 1851, 10599, 199, 646, 5166, 14, 555, 79, 1435, 465, 1115, 79, 1435, 199, 646, 5166, 14, 3009, 63, 697, 465, 3875, 63, 697, 199, 504, 5166, 14, 2537, 14, 5275, 492, 9028, 199, 504, 5166, 14, 4795, 14, 1025, 492, 6288, 1685, 12, 5822, 12, 19894, 14928, 1685, 12, 11836, 1685, 199, 646, 5166, 14, 3924, 199, 199, 63, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 3, 17993, 14, 199, 533, 871, 63, 4795, 8, 1726, 304, 272, 347, 636, 826, 721, 277, 12, 536, 12, 574, 304, 267, 291, 14, 354, 275, 536, 267, 291, 14, 585, 275, 574, 267, 291, 14, 589, 275, 334, 354, 12, 574, 9, 199, 199, 1364, 275, 488, 199, 199, 533, 909, 63, 3280, 8, 785, 304, 272, 347, 636, 826, 721, 277, 304, 267, 2288, 2435, 267, 2435, 275, 291, 339, 347, 1104, 8, 70, 304, 267, 768, 13582, 8, 70, 9, 267, 347, 4975, 8, 277, 12, 21842, 12, 627, 589, 12, 1011, 958, 304, 288, 408, 644, 8146, 6818, 4403, 54, 3423, 436, 3293, 1388, 282, 9284, 4967, 288, 408, 953, 347, 5651, 8, 2164, 12, 17860, 304, 355, 327, 2136, 862, 370, 886, 314, 2011, 465, 314, 485, 1062, 1325, 1928, 314, 2787, 355, 327, 5261, 10303, 12, 3967, 781, 282, 2179, 787, 19696, 376, 9506, 805, 355, 327, 1752, 63, 1113, 275, 291, 14, 362, 360, 723, 14, 6893, 358, 3913, 1736, 5966, 520, 8, 355, 4027, 275, 1052, 355, 340, 440, 2074, 26, 490, 340, 1249, 436, 1228, 8, 589, 1988, 17, 467, 1211, 304, 717, 4027, 275, 1249, 1988, 17, 61, 355, 916, 1228, 8, 958, 12, 1211, 304, 490, 4027, 275, 2074, 14, 362, 360, 1100, 297, 5009, 2234, 1747, 275, 413, 355, 340, 1249, 436, 1228, 8, 589, 59, 16, 467, 334, 2809, 12, 1109, 2298, 490, 1747, 275, 1249, 59, 16, 61, 2234, 6339, 275, 4027, 436, 4027, 14, 362, 360, 4159, 358, 355, 340, 440, 334, 4159, 503, 2688, 8, 2164, 12, 2560, 1250, 363, 8109, 490, 372, 2928, 2234, 327, 2136, 1551, 282, 627, 1222, 10, 3920, 2348, 12, 1373, 4499, 365, 626, 3405, 5385, 355, 327, 9212, 334, 305, 315, 26864, 9, 911, 24841, 314, 1453, 1373, 14, 355, 2467, 275, 756, 2234, 340, 2688, 8, 2164, 12, 2560, 1250, 12168, 490, 327, 4550, 14, 2136, 1929, 370, 2342, 314, 2451, 2633, 370, 1240, 490, 327, 314, 221, 9813, 423, 3009, 63, 1188, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 9, 805, 12, 490, 327, 503, 781, 3372, 703, 490, 327, 4154, 4955, 365, 289, 8, 4795, 63, 2293, 12, 21842, 359, 12, 1535, 12, 1559, 12, 1083, 12, 1249, 566, 490, 862, 26, 717, 340, 1249, 436, 822, 8, 589, 9, 690, 413, 26, 1169, 1559, 275, 291, 14, 362, 8, 589, 59, 17, 566, 1169, 340, 822, 8, 589, 9, 690, 650, 436, 1228, 8, 589, 59, 19, 467, 334, 2809, 12, 1109, 12, 769, 2298, 1816, 2762, 275, 1249, 59, 19, 61, 1169, 587, 26, 1816, 2762, 275, 942, 717, 2467, 275, 3875, 63, 697, 14, 697, 63, 2242, 8, 13238, 680, 3937, 342, 717, 372, 2928, 8, 1113, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 2687, 3799, 503, 17003, 490, 871, 2186, 26, 717, 986, 490, 3753, 26, 717, 340, 2467, 26, 2467, 14, 1600, 342, 4951, 372, 756, 327, 880, 626, 314, 3379, 5385, 1125, 911, 639, 327, 506, 2138, 12, 652, 365, 314, 5526, 781, 1172, 14, 2234, 862, 26, 490, 2467, 275, 3875, 63, 697, 14, 697, 63, 2242, 8, 13238, 680, 3937, 342, 490, 522, 275, 9028, 8, 1556, 12, 536, 29, 797, 12, 1350, 63, 466, 29, 21002, 12, 2511, 6339, 29, 4159, 12, 1350, 29, 2164, 9, 490, 340, 522, 26, 717, 372, 522, 490, 587, 26, 717, 372, 2928, 355, 3753, 26, 490, 340, 2467, 26, 2467, 14, 1600, 342, 953, 347, 12561, 2164, 304, 355, 372, 5651, 8, 2164, 12, 283, 600, 358, 953, 862, 26, 355, 340, 1115, 79, 1435, 14, 362, 63, 2293, 8, 13238, 10445, 826, 26, 490, 746, 871, 63, 4795, 360, 7243, 440, 10144, 297, 283, 31499, 12, 642, 3050, 365, 440, 9999, 6511, 436, 883, 440, 506, 1202, 2659, 355, 372, 289, 8, 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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 ]
falseen/shadowsocks
shadowsocks/crypto/hkdf.py
21
3050
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Void Copyright NO ONE # # Void License # # The code belongs to no one. Do whatever you want. # Forget about boring open source license. # # HKDF for AEAD ciphers # from __future__ import division import hmac import hashlib import sys if sys.version_info[0] == 3: def buffer(x): return x def hkdf_extract(salt, input_key_material, algorithm=hashlib.sha256): """ Extract a pseudorandom key suitable for use with hkdf_expand from the input_key_material and a salt using HMAC with the provided hash (default SHA-256). salt should be a random, application-specific byte string. If salt is None or the empty string, an all-zeros string of the same length as the hash's block size will be used instead per the RFC. See the HKDF draft RFC and paper for usage notes. """ hash_len = algorithm().digest_size if salt is None or len(salt) == 0: salt = bytearray((0,) * hash_len) return hmac.new(bytes(salt), buffer(input_key_material), algorithm)\ .digest() def hkdf_expand(pseudo_random_key, info=b"", length=32, algorithm=hashlib.sha256): """ Expand `pseudo_random_key` and `info` into a key of length `bytes` using HKDF's expand function based on HMAC with the provided hash (default SHA-256). See the HKDF draft RFC and paper for usage notes. """ hash_len = algorithm().digest_size length = int(length) if length > 255 * hash_len: raise Exception("Cannot expand to more than 255 * %d = %d " "bytes using the specified hash function" % (hash_len, 255 * hash_len)) blocks_needed = length // hash_len \ + (0 if length % hash_len == 0 else 1) # ceil okm = b"" output_block = b"" for counter in range(blocks_needed): output_block = hmac.new( pseudo_random_key, buffer(output_block + info + bytearray((counter + 1,))), algorithm ).digest() okm += output_block return okm[:length] class Hkdf(object): """ Wrapper class for HKDF extract and expand functions """ def __init__(self, salt, input_key_material, algorithm=hashlib.sha256): """ Extract a pseudorandom key from `salt` and `input_key_material` arguments. See the HKDF draft RFC for guidance on setting these values. The constructor optionally takes a `algorithm` argument defining the hash function use, defaulting to hashlib.sha256. """ self._hash = algorithm self._prk = hkdf_extract(salt, input_key_material, self._hash) def expand(self, info, length=32): """ Generate output key material based on an `info` value Arguments: - info - context to generate the OKM - length - length in bytes of the key to generate See the HKDF draft RFC for guidance. """ return hkdf_expand(self._prk, info, length, self._hash)
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 25629, 1898, 4825, 13051, 199, 3, 199, 3, 25629, 844, 199, 3, 199, 3, 710, 1233, 15006, 370, 949, 1373, 14, 4226, 15685, 1265, 2934, 14, 199, 3, 2104, 362, 3595, 330, 6854, 1551, 1350, 4190, 14, 199, 3, 199, 3, 869, 43, 3888, 367, 24475, 1554, 30377, 199, 3, 199, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 646, 20330, 199, 646, 8337, 199, 646, 984, 199, 199, 692, 984, 14, 1023, 63, 815, 59, 16, 61, 508, 650, 26, 272, 347, 3335, 8, 88, 304, 267, 372, 671, 421, 199, 318, 394, 28996, 63, 5005, 8, 12597, 12, 1324, 63, 498, 63, 9820, 12, 5563, 29, 24722, 14, 4835, 3912, 304, 272, 408, 272, 12892, 282, 299, 261, 1181, 269, 1241, 790, 11233, 367, 675, 543, 394, 28996, 63, 4441, 272, 687, 314, 1324, 63, 498, 63, 9820, 436, 282, 10105, 1808, 29817, 543, 314, 272, 2741, 2631, 334, 885, 12002, 13, 3912, 680, 339, 10105, 1077, 506, 282, 2196, 12, 4223, 13, 6100, 3696, 1059, 14, 982, 272, 10105, 365, 488, 503, 314, 2701, 1059, 12, 376, 1006, 13, 4250, 1059, 402, 314, 2011, 272, 2582, 465, 314, 2631, 1159, 1853, 1568, 911, 506, 1202, 3140, 1126, 314, 7329, 14, 339, 1666, 314, 869, 43, 3888, 11872, 7329, 436, 15220, 367, 4503, 12681, 14, 272, 408, 272, 2631, 63, 552, 275, 5563, 1252, 5671, 63, 890, 272, 340, 10105, 365, 488, 503, 822, 8, 12597, 9, 508, 378, 26, 267, 10105, 275, 11640, 1332, 16, 4258, 627, 2631, 63, 552, 9, 272, 372, 20330, 14, 1222, 8, 2394, 8, 12597, 395, 3335, 8, 1210, 63, 498, 63, 9820, 395, 5563, 2862, 267, 1275, 5671, 342, 421, 199, 318, 394, 28996, 63, 4441, 8, 22490, 63, 2355, 63, 498, 12, 2256, 29, 66, 5151, 2582, 29, 708, 12, 355, 5563, 29, 24722, 14, 4835, 3912, 304, 272, 408, 272, 18890, 658, 22490, 63, 2355, 63, 498, 64, 436, 658, 815, 64, 1901, 282, 790, 402, 2582, 658, 2394, 64, 1808, 272, 869, 43, 3888, 1159, 6544, 805, 4079, 641, 29817, 543, 314, 2741, 2631, 334, 885, 272, 12002, 13, 3912, 680, 1666, 314, 869, 43, 3888, 11872, 7329, 436, 15220, 367, 4503, 12681, 14, 272, 408, 272, 2631, 63, 552, 275, 5563, 1252, 5671, 63, 890, 272, 2582, 275, 1109, 8, 1267, 9, 272, 340, 2582, 690, 5450, 627, 2631, 63, 552, 26, 267, 746, 2186, 480, 6612, 6544, 370, 1655, 2419, 5450, 627, 450, 68, 275, 450, 68, 298, 717, 298, 2394, 1808, 314, 2013, 2631, 805, 2, 450, 717, 334, 2227, 63, 552, 12, 5450, 627, 2631, 63, 552, 430, 272, 5664, 63, 11368, 275, 2582, 5001, 2631, 63, 552, 971, 267, 435, 334, 16, 340, 2582, 450, 2631, 63, 552, 508, 378, 587, 413, 9, 221, 327, 30449, 272, 4112, 77, 275, 330, 341, 272, 1072, 63, 1457, 275, 330, 341, 272, 367, 7055, 315, 1425, 8, 4166, 63, 11368, 304, 267, 1072, 63, 1457, 275, 20330, 14, 1222, 8, 288, 15984, 63, 2355, 63, 498, 12, 288, 3335, 8, 1199, 63, 1457, 435, 2256, 435, 11640, 1332, 5337, 435, 413, 4641, 395, 288, 5563, 267, 7092, 5671, 342, 267, 4112, 77, 847, 1072, 63, 1457, 272, 372, 4112, 77, 1491, 1267, 61, 421, 199, 533, 869, 28996, 8, 785, 304, 272, 408, 272, 21947, 1021, 367, 869, 43, 3888, 5536, 436, 6544, 3423, 272, 408, 339, 347, 636, 826, 721, 277, 12, 10105, 12, 1324, 63, 498, 63, 9820, 12, 5563, 29, 24722, 14, 4835, 3912, 304, 267, 408, 268, 12892, 282, 299, 261, 1181, 269, 1241, 790, 687, 658, 12597, 64, 436, 658, 1210, 63, 498, 63, 9820, 64, 268, 2368, 14, 13359, 1666, 314, 869, 43, 3888, 11872, 7329, 367, 15593, 554, 641, 4260, 3520, 1338, 14, 268, 710, 3787, 14190, 6181, 282, 658, 8833, 64, 1423, 12669, 268, 314, 2631, 805, 675, 12, 849, 316, 370, 8337, 14, 4835, 3912, 14, 268, 408, 267, 291, 423, 2227, 275, 5563, 267, 291, 423, 2700, 75, 275, 394, 28996, 63, 5005, 8, 12597, 12, 1324, 63, 498, 63, 9820, 12, 291, 423, 2227, 9, 339, 347, 6544, 8, 277, 12, 2256, 12, 2582, 29, 708, 304, 267, 408, 267, 7958, 1072, 790, 6285, 4079, 641, 376, 658, 815, 64, 574, 398, 7628, 26, 267, 446, 2256, 446, 1067, 370, 3550, 314, 9949, 45, 267, 446, 2582, 446, 2582, 315, 2783, 402, 314, 790, 370, 3550, 398, 1666, 314, 869, 43, 3888, 11872, 7329, 367, 15593, 554, 14, 267, 408, 267, 372, 394, 28996, 63, 4441, 8, 277, 423, 2700, 75, 12, 2256, 12, 2582, 12, 291, 423, 2227, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 25629, 1898, 4825, 13051, 199, 3, 199, 3, 25629, 844, 199, 3, 199, 3, 710, 1233, 15006, 370, 949, 1373, 14, 4226, 15685, 1265, 2934, 14, 199, 3, 2104, 362, 3595, 330, 6854, 1551, 1350, 4190, 14, 199, 3, 199, 3, 869, 43, 3888, 367, 24475, 1554, 30377, 199, 3, 199, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 646, 20330, 199, 646, 8337, 199, 646, 984, 199, 199, 692, 984, 14, 1023, 63, 815, 59, 16, 61, 508, 650, 26, 272, 347, 3335, 8, 88, 304, 267, 372, 671, 421, 199, 318, 394, 28996, 63, 5005, 8, 12597, 12, 1324, 63, 498, 63, 9820, 12, 5563, 29, 24722, 14, 4835, 3912, 304, 272, 408, 272, 12892, 282, 299, 261, 1181, 269, 1241, 790, 11233, 367, 675, 543, 394, 28996, 63, 4441, 272, 687, 314, 1324, 63, 498, 63, 9820, 436, 282, 10105, 1808, 29817, 543, 314, 272, 2741, 2631, 334, 885, 12002, 13, 3912, 680, 339, 10105, 1077, 506, 282, 2196, 12, 4223, 13, 6100, 3696, 1059, 14, 982, 272, 10105, 365, 488, 503, 314, 2701, 1059, 12, 376, 1006, 13, 4250, 1059, 402, 314, 2011, 272, 2582, 465, 314, 2631, 1159, 1853, 1568, 911, 506, 1202, 3140, 1126, 314, 7329, 14, 339, 1666, 314, 869, 43, 3888, 11872, 7329, 436, 15220, 367, 4503, 12681, 14, 272, 408, 272, 2631, 63, 552, 275, 5563, 1252, 5671, 63, 890, 272, 340, 10105, 365, 488, 503, 822, 8, 12597, 9, 508, 378, 26, 267, 10105, 275, 11640, 1332, 16, 4258, 627, 2631, 63, 552, 9, 272, 372, 20330, 14, 1222, 8, 2394, 8, 12597, 395, 3335, 8, 1210, 63, 498, 63, 9820, 395, 5563, 2862, 267, 1275, 5671, 342, 421, 199, 318, 394, 28996, 63, 4441, 8, 22490, 63, 2355, 63, 498, 12, 2256, 29, 66, 5151, 2582, 29, 708, 12, 355, 5563, 29, 24722, 14, 4835, 3912, 304, 272, 408, 272, 18890, 658, 22490, 63, 2355, 63, 498, 64, 436, 658, 815, 64, 1901, 282, 790, 402, 2582, 658, 2394, 64, 1808, 272, 869, 43, 3888, 1159, 6544, 805, 4079, 641, 29817, 543, 314, 2741, 2631, 334, 885, 272, 12002, 13, 3912, 680, 1666, 314, 869, 43, 3888, 11872, 7329, 436, 15220, 367, 4503, 12681, 14, 272, 408, 272, 2631, 63, 552, 275, 5563, 1252, 5671, 63, 890, 272, 2582, 275, 1109, 8, 1267, 9, 272, 340, 2582, 690, 5450, 627, 2631, 63, 552, 26, 267, 746, 2186, 480, 6612, 6544, 370, 1655, 2419, 5450, 627, 450, 68, 275, 450, 68, 298, 717, 298, 2394, 1808, 314, 2013, 2631, 805, 2, 450, 717, 334, 2227, 63, 552, 12, 5450, 627, 2631, 63, 552, 430, 272, 5664, 63, 11368, 275, 2582, 5001, 2631, 63, 552, 971, 267, 435, 334, 16, 340, 2582, 450, 2631, 63, 552, 508, 378, 587, 413, 9, 221, 327, 30449, 272, 4112, 77, 275, 330, 341, 272, 1072, 63, 1457, 275, 330, 341, 272, 367, 7055, 315, 1425, 8, 4166, 63, 11368, 304, 267, 1072, 63, 1457, 275, 20330, 14, 1222, 8, 288, 15984, 63, 2355, 63, 498, 12, 288, 3335, 8, 1199, 63, 1457, 435, 2256, 435, 11640, 1332, 5337, 435, 413, 4641, 395, 288, 5563, 267, 7092, 5671, 342, 267, 4112, 77, 847, 1072, 63, 1457, 272, 372, 4112, 77, 1491, 1267, 61, 421, 199, 533, 869, 28996, 8, 785, 304, 272, 408, 272, 21947, 1021, 367, 869, 43, 3888, 5536, 436, 6544, 3423, 272, 408, 339, 347, 636, 826, 721, 277, 12, 10105, 12, 1324, 63, 498, 63, 9820, 12, 5563, 29, 24722, 14, 4835, 3912, 304, 267, 408, 268, 12892, 282, 299, 261, 1181, 269, 1241, 790, 687, 658, 12597, 64, 436, 658, 1210, 63, 498, 63, 9820, 64, 268, 2368, 14, 13359, 1666, 314, 869, 43, 3888, 11872, 7329, 367, 15593, 554, 641, 4260, 3520, 1338, 14, 268, 710, 3787, 14190, 6181, 282, 658, 8833, 64, 1423, 12669, 268, 314, 2631, 805, 675, 12, 849, 316, 370, 8337, 14, 4835, 3912, 14, 268, 408, 267, 291, 423, 2227, 275, 5563, 267, 291, 423, 2700, 75, 275, 394, 28996, 63, 5005, 8, 12597, 12, 1324, 63, 498, 63, 9820, 12, 291, 423, 2227, 9, 339, 347, 6544, 8, 277, 12, 2256, 12, 2582, 29, 708, 304, 267, 408, 267, 7958, 1072, 790, 6285, 4079, 641, 376, 658, 815, 64, 574, 398, 7628, 26, 267, 446, 2256, 446, 1067, 370, 3550, 314, 9949, 45, 267, 446, 2582, 446, 2582, 315, 2783, 402, 314, 790, 370, 3550, 398, 1666, 314, 869, 43, 3888, 11872, 7329, 367, 15593, 554, 14, 267, 408, 267, 372, 394, 28996, 63, 4441, 8, 277, 423, 2700, 75, 12, 2256, 12, 2582, 12, 291, 423, 2227, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
LCLS/Protein-Folding-Sims
analysis/state.py
1
1766
import sys import numpy as np import os import os.path import argparse def parse_args(args=None): parser = argparse.ArgumentParser() parser.add_argument("--h1", default=None, type=float, help='RMSD threshold to helix 1' ) parser.add_argument("--h2", default=None, type=float, help='RMSD threshold to helix 2' ) parser.add_argument("--hboth", default=None, type=float, help='RMSD threshold to both helices' ) return parser.parse_args(args) if __name__ == "__main__": args = parse_args() for path in os.listdir(): fname = os.path.join(path, 'rmsd_helix_1.csv') if os.path.isdir(path) and os.path.isfile(fname) and args.h1 is not None: rmsd = np.loadtxt(fname) state = list(map(lambda x: 1 if x < args.h1 else 0, rmsd)) np.savetxt(os.path.join(path, 'state_helix_1.csv'), np.array(state).astype(int), fmt="%d") fname = os.path.join(path, 'rmsd_helix_2.csv') if os.path.isdir(path) and os.path.isfile(fname) and args.h2 is not None: rmsd = np.loadtxt(fname) state = list(map(lambda x: 1 if x < args.h2 else 0, rmsd)) np.savetxt(os.path.join(path, 'state_helix_2.csv'), np.array(state).astype(int), fmt="%d") fname = os.path.join(path, 'rmsd_helix_both.csv') if os.path.isdir(path) and os.path.isfile(fname) and args.hboth is not None: rmsd = np.loadtxt(fname) state = list(map(lambda x: 1 if x < args.hboth else 0, rmsd)) np.savetxt(os.path.join(path, 'state_helix_both.csv'), np.array(state).astype(int), fmt="%d")
mit
[ 646, 984, 199, 646, 2680, 465, 980, 199, 199, 646, 747, 199, 646, 747, 14, 515, 199, 199, 646, 7534, 199, 199, 318, 2198, 63, 589, 8, 589, 29, 403, 304, 272, 1798, 275, 7534, 14, 10730, 342, 339, 1798, 14, 525, 63, 2094, 6739, 72, 17, 401, 288, 849, 29, 403, 12, 288, 730, 29, 1609, 12, 288, 1720, 534, 50, 3053, 36, 8765, 370, 946, 20528, 413, 7, 288, 776, 272, 1798, 14, 525, 63, 2094, 6739, 72, 18, 401, 288, 849, 29, 403, 12, 288, 730, 29, 1609, 12, 288, 1720, 534, 50, 3053, 36, 8765, 370, 946, 20528, 499, 7, 288, 776, 339, 1798, 14, 525, 63, 2094, 6739, 72, 10727, 401, 288, 849, 29, 403, 12, 288, 730, 29, 1609, 12, 288, 1720, 534, 50, 3053, 36, 8765, 370, 3865, 946, 7598, 7, 288, 776, 339, 372, 1798, 14, 1122, 63, 589, 8, 589, 9, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 1249, 275, 2198, 63, 589, 342, 339, 367, 931, 315, 747, 14, 7374, 837, 267, 6748, 275, 747, 14, 515, 14, 904, 8, 515, 12, 283, 24444, 68, 63, 426, 20528, 63, 17, 14, 4737, 358, 267, 340, 747, 14, 515, 14, 6027, 8, 515, 9, 436, 747, 14, 515, 14, 6292, 8, 5252, 9, 436, 1249, 14, 72, 17, 365, 440, 488, 26, 288, 519, 28982, 275, 980, 14, 27992, 8, 5252, 9, 288, 1174, 275, 769, 8, 1130, 8, 2734, 671, 26, 413, 340, 671, 665, 1249, 14, 72, 17, 587, 378, 12, 519, 28982, 430, 288, 980, 14, 23374, 386, 400, 8, 736, 14, 515, 14, 904, 8, 515, 12, 283, 929, 63, 426, 20528, 63, 17, 14, 4737, 659, 980, 14, 1144, 8, 929, 680, 6041, 8, 442, 395, 7104, 5961, 68, 531, 2728, 6748, 275, 747, 14, 515, 14, 904, 8, 515, 12, 283, 24444, 68, 63, 426, 20528, 63, 18, 14, 4737, 358, 267, 340, 747, 14, 515, 14, 6027, 8, 515, 9, 436, 747, 14, 515, 14, 6292, 8, 5252, 9, 436, 1249, 14, 72, 18, 365, 440, 488, 26, 288, 519, 28982, 275, 980, 14, 27992, 8, 5252, 9, 288, 1174, 275, 769, 8, 1130, 8, 2734, 671, 26, 413, 340, 671, 665, 1249, 14, 72, 18, 587, 378, 12, 519, 28982, 430, 288, 980, 14, 23374, 386, 400, 8, 736, 14, 515, 14, 904, 8, 515, 12, 283, 929, 63, 426, 20528, 63, 18, 14, 4737, 659, 980, 14, 1144, 8, 929, 680, 6041, 8, 442, 395, 7104, 5961, 68, 531, 2728, 6748, 275, 747, 14, 515, 14, 904, 8, 515, 12, 283, 24444, 68, 63, 426, 20528, 63, 10727, 14, 4737, 358, 267, 340, 747, 14, 515, 14, 6027, 8, 515, 9, 436, 747, 14, 515, 14, 6292, 8, 5252, 9, 436, 1249, 14, 72, 10727, 365, 440, 488, 26, 288, 519, 28982, 275, 980, 14, 27992, 8, 5252, 9, 288, 1174, 275, 769, 8, 1130, 8, 2734, 671, 26, 413, 340, 671, 665, 1249, 14, 72, 10727, 587, 378, 12, 519, 28982, 430, 288, 980, 14, 23374, 386, 400, 8, 736, 14, 515, 14, 904, 8, 515, 12, 283, 929, 63, 426, 20528, 63, 10727, 14, 4737, 659, 980, 14, 1144, 8, 929, 680, 6041, 8, 442, 395, 7104, 5961, 68, 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 ]
[ 984, 199, 646, 2680, 465, 980, 199, 199, 646, 747, 199, 646, 747, 14, 515, 199, 199, 646, 7534, 199, 199, 318, 2198, 63, 589, 8, 589, 29, 403, 304, 272, 1798, 275, 7534, 14, 10730, 342, 339, 1798, 14, 525, 63, 2094, 6739, 72, 17, 401, 288, 849, 29, 403, 12, 288, 730, 29, 1609, 12, 288, 1720, 534, 50, 3053, 36, 8765, 370, 946, 20528, 413, 7, 288, 776, 272, 1798, 14, 525, 63, 2094, 6739, 72, 18, 401, 288, 849, 29, 403, 12, 288, 730, 29, 1609, 12, 288, 1720, 534, 50, 3053, 36, 8765, 370, 946, 20528, 499, 7, 288, 776, 339, 1798, 14, 525, 63, 2094, 6739, 72, 10727, 401, 288, 849, 29, 403, 12, 288, 730, 29, 1609, 12, 288, 1720, 534, 50, 3053, 36, 8765, 370, 3865, 946, 7598, 7, 288, 776, 339, 372, 1798, 14, 1122, 63, 589, 8, 589, 9, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 1249, 275, 2198, 63, 589, 342, 339, 367, 931, 315, 747, 14, 7374, 837, 267, 6748, 275, 747, 14, 515, 14, 904, 8, 515, 12, 283, 24444, 68, 63, 426, 20528, 63, 17, 14, 4737, 358, 267, 340, 747, 14, 515, 14, 6027, 8, 515, 9, 436, 747, 14, 515, 14, 6292, 8, 5252, 9, 436, 1249, 14, 72, 17, 365, 440, 488, 26, 288, 519, 28982, 275, 980, 14, 27992, 8, 5252, 9, 288, 1174, 275, 769, 8, 1130, 8, 2734, 671, 26, 413, 340, 671, 665, 1249, 14, 72, 17, 587, 378, 12, 519, 28982, 430, 288, 980, 14, 23374, 386, 400, 8, 736, 14, 515, 14, 904, 8, 515, 12, 283, 929, 63, 426, 20528, 63, 17, 14, 4737, 659, 980, 14, 1144, 8, 929, 680, 6041, 8, 442, 395, 7104, 5961, 68, 531, 2728, 6748, 275, 747, 14, 515, 14, 904, 8, 515, 12, 283, 24444, 68, 63, 426, 20528, 63, 18, 14, 4737, 358, 267, 340, 747, 14, 515, 14, 6027, 8, 515, 9, 436, 747, 14, 515, 14, 6292, 8, 5252, 9, 436, 1249, 14, 72, 18, 365, 440, 488, 26, 288, 519, 28982, 275, 980, 14, 27992, 8, 5252, 9, 288, 1174, 275, 769, 8, 1130, 8, 2734, 671, 26, 413, 340, 671, 665, 1249, 14, 72, 18, 587, 378, 12, 519, 28982, 430, 288, 980, 14, 23374, 386, 400, 8, 736, 14, 515, 14, 904, 8, 515, 12, 283, 929, 63, 426, 20528, 63, 18, 14, 4737, 659, 980, 14, 1144, 8, 929, 680, 6041, 8, 442, 395, 7104, 5961, 68, 531, 2728, 6748, 275, 747, 14, 515, 14, 904, 8, 515, 12, 283, 24444, 68, 63, 426, 20528, 63, 10727, 14, 4737, 358, 267, 340, 747, 14, 515, 14, 6027, 8, 515, 9, 436, 747, 14, 515, 14, 6292, 8, 5252, 9, 436, 1249, 14, 72, 10727, 365, 440, 488, 26, 288, 519, 28982, 275, 980, 14, 27992, 8, 5252, 9, 288, 1174, 275, 769, 8, 1130, 8, 2734, 671, 26, 413, 340, 671, 665, 1249, 14, 72, 10727, 587, 378, 12, 519, 28982, 430, 288, 980, 14, 23374, 386, 400, 8, 736, 14, 515, 14, 904, 8, 515, 12, 283, 929, 63, 426, 20528, 63, 10727, 14, 4737, 659, 980, 14, 1144, 8, 929, 680, 6041, 8, 442, 395, 7104, 5961, 68, 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,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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 ]
SiriusBizniss/evetowerthing
lib/requests/packages/poster/__init__.py
2
1479
# Copyright (c) 2010 Chris AtLee # # 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. """poster module Support for streaming HTTP uploads, and multipart/form-data encoding ```poster.version``` is a 3-tuple of integers representing the version number. New releases of poster will always have a version number that compares greater than an older version of poster. New in version 0.6.""" from . import streaminghttp from . import encode version = (0, 8, 0) # Thanks JP!
mit
[ 3, 1898, 334, 67, 9, 7129, 2799, 5719, 2854, 44, 1024, 199, 3, 221, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 1331, 199, 3, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 298, 10337, 1288, 370, 7962, 199, 3, 315, 314, 2290, 1928, 10588, 12, 5893, 1928, 12305, 314, 4481, 199, 3, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 199, 3, 6866, 402, 314, 2290, 12, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 199, 3, 13985, 370, 886, 880, 12, 5420, 370, 314, 2569, 3704, 26, 199, 3, 221, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 315, 199, 3, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 221, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 1549, 199, 3, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 3169, 12, 199, 3, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 7000, 2334, 199, 3, 10610, 1549, 5877, 8164, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 199, 3, 5603, 12, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 199, 3, 2334, 4141, 14, 199, 624, 20801, 859, 199, 199, 11532, 367, 18490, 3101, 26598, 12, 436, 15193, 15, 964, 13, 576, 2644, 199, 199, 32323, 20801, 14, 1023, 32323, 365, 282, 650, 13, 2960, 402, 9446, 6144, 314, 1015, 1329, 14, 199, 4665, 19015, 402, 2086, 351, 911, 3544, 1172, 282, 1015, 1329, 626, 30827, 8932, 199, 13797, 376, 12731, 1015, 402, 2086, 351, 14, 199, 4665, 315, 1015, 378, 14, 22, 1041, 199, 199, 504, 1275, 492, 18490, 1014, 199, 504, 1275, 492, 3752, 199, 199, 1023, 275, 334, 16, 12, 1695, 12, 378, 9, 327, 3868, 25088, 1603, 48, 1, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 7129, 2799, 5719, 2854, 44, 1024, 199, 3, 221, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 1331, 199, 3, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 298, 10337, 1288, 370, 7962, 199, 3, 315, 314, 2290, 1928, 10588, 12, 5893, 1928, 12305, 314, 4481, 199, 3, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 199, 3, 6866, 402, 314, 2290, 12, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 199, 3, 13985, 370, 886, 880, 12, 5420, 370, 314, 2569, 3704, 26, 199, 3, 221, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 315, 199, 3, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 221, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 1549, 199, 3, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 3169, 12, 199, 3, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 7000, 2334, 199, 3, 10610, 1549, 5877, 8164, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 199, 3, 5603, 12, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 199, 3, 2334, 4141, 14, 199, 624, 20801, 859, 199, 199, 11532, 367, 18490, 3101, 26598, 12, 436, 15193, 15, 964, 13, 576, 2644, 199, 199, 32323, 20801, 14, 1023, 32323, 365, 282, 650, 13, 2960, 402, 9446, 6144, 314, 1015, 1329, 14, 199, 4665, 19015, 402, 2086, 351, 911, 3544, 1172, 282, 1015, 1329, 626, 30827, 8932, 199, 13797, 376, 12731, 1015, 402, 2086, 351, 14, 199, 4665, 315, 1015, 378, 14, 22, 1041, 199, 199, 504, 1275, 492, 18490, 1014, 199, 504, 1275, 492, 3752, 199, 199, 1023, 275, 334, 16, 12, 1695, 12, 378, 9, 327, 3868, 25088, 1603, 48, 1, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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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 ]
NeilT-UK/python-utilities
quantiser.py
1
7435
""" export qXXX quantiser functions, and general make_quant function use function closures to return the following pre-defined qXXX functions qE3 to qE192, the standard resistor ranges qE2 [1, 3, 10] qE5 [1, 1.6, 2.5, 4, 6.3, 10] qE10 [1, 1.25, 1.6, 2, 2.5, 3.2, 4, 5, 6.3, 8, 10] return a function that quantises according to the tuple basis make_quant(basis)""" """ Copyright (c) <2016>, <Neil Thomas>, <NeilT-UK>, <dc_fm@hotmail.com> 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. 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. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. """ # there are several different ways this function may be approached # this uses closures (because I could, and wanted to try it) # alternatively I could make a class with a __call__ method # or simply create functions manually that do it # not sure which is the best version = '1.0 December 2016' import math def make_quant(basis): """ return the quant function, preconfigured with the basis basis starts with a 1, is monotonically increasing, it defines a geometrically extendable range with a ratio of the last/first numbers >>> qE12(1.6) 1.5 >>> qE12(1.6,1) 1.8 >>> qE12(8.3, offset=4) 18.0 >>> qE12(17) 18.0 >>> '{:.4f}'.format(qE12(0.17)) '0.1800' """ def quant(x, nearest=0, offset=0): """ Quantise x nearest = 0 (default) return the geometrically nearest number nearest = -1 return the lower number (floor) nearest = 1 return the higher number (ceil) offset = 0 (default) return the number as is offset = n return the nth higher or lower quantisation step""" # sanitise the input args (slightly, should I float() it?) x_test = abs(x) if x_test<1e-100: # or whatever small test number return 0 if x<0: sign = -1 else: sign = 1 # get the basis range base0 = basis[0] base1 = basis[-1] lbm1 = len(basis)-1 # bring our test number into the basis range, exp is the range power required exp = math.floor(math.log(x_test)/math.log(base1)) x_test *= base1**(-exp) # binary search for the upper and lower bounds around ranged x ilow = 0 ihigh = lbm1 while ihigh-ilow > 1: imid = int((ilow+ihigh)/2) if x_test> basis[imid]: ilow = imid else: ihigh = imid # do we want to use the lower or upper bound? s = int(nearest) if s==0: # find nearest number, geometrically highrat = basis[ihigh]/x_test lowrat = x_test/basis[ilow] if lowrat<highrat: index = ilow else: index = ihigh elif s>0: # we want the upper index = ihigh else: # the lower index = ilow index += offset while index<0: # handle the potential wrapping into the previous range index += lbm1 exp -= 1 while index>=lbm1: # handle the potential wrapping into the next range index -= lbm1 exp += 1 return(sign*basis[index]*(base1**exp)) return quant q125 = make_quant([1, 2, 5, 10]) # nice oscilloscope and graph increments qE2 = make_quant([1, 3, 10]) # roughly 10dB steps, beloved of RF attenuators qE3 = make_quant([1.0, 2.2, 4.7, 10.0]) # very coarse resistor steps qE5 = make_quant([1.0, 1.6, 2.5, 4.0, 6.3, 10.0]) # often seen as capacitor voltages qE6 = make_quant([1.0, 1.5, 2.2, 3.3, 4.7, 6.8, 10.0]) # coarse resistor steps qE10 = make_quant([1.0, 1.25, 1.6, 2.0, 2.5, 3.2, 4.0, 5.0, 6.3, 8.0, 10.0]) # log10 approxmimation # I'm trying to learn these # for mental arithmetic qE12 = make_quant([1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2, 10.0]) # common resistor steps qE24 = make_quant([1.0, 1.1, 1.2, 1.3, 1.5, 1.6, # common professional resistor steps 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, # E12 superset 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1, 10.0]) qE48 = make_quant([1.00, 1.05, 1.10, 1.15, 1.21, 1.27, # fine resistor steps 1.33, 1.40, 1.47, 1.54, 1.62, 1.69, # NOT an E24 superset 1.78, 1.87, 1.96, 2.05, 2.15, 2.26, 2.37, 2.49, 2.61, 2.74, 2.87, 3.01, 3.16, 3.32, 3.48, 3.65, 3.83, 4.02, 4.22, 4.42, 4.64, 4.87, 5.11, 5.36, 5.62, 5.90, 6.19, 6.49, 6.81, 7.15, 7.50, 7.87, 8.25, 8.66, 9.09, 9.53, 10.0]) qE96 = make_quant([1.00, 1.02, 1.05, 1.07, 1.10, 1.13, # very fine resistor steps 1.15, 1.18, 1.21, 1.24, 1.27, 1.30, # E48 superset 1.33, 1.37, 1.40, 1.43, 1.47, 1.50, 1.54, 1.58, 1.62, 1.65, 1.69, 1.74, 1.78, 1.82, 1.87, 1.91, 1.96, 2.00, 2.05, 2.10, 2.16, 2.21, 2.36, 2.32, 2.37, 2.43, 2.49, 2.55, 2.61, 2.67, 2.74, 2.80, 2.87, 2.94, 3.01, 3.09, 3.16, 3.24, 3.32, 3.40, 3.48, 3.57, 3.65, 3.74, 3.83, 3.92, 4.02, 4.12, 4.22, 4.32, 4.42, 4.53, 4.64, 4.75, 4.87, 4.91, 5.11, 5.23, 5.36, 5.49, 5.62, 5.76, 5.90, 6.04, 6.19, 6.34, 6.49, 6.65, 6.81, 6.98, 7.15, 7.32, 7.50, 7.68, 7.87, 8.06, 8.25, 8.45, 8.66, 8.87, 9.09, 9.31, 9.59, 9.76, 10.0]) if __name__ == '__main__': import doctest doctest.testmod(verbose=True)
bsd-2-clause
[ 624, 4843, 1894, 13933, 13621, 332, 3423, 12, 436, 8605, 1852, 63, 13603, 805, 199, 199, 1180, 805, 2463, 83, 1482, 370, 372, 314, 2569, 876, 13, 4037, 1894, 13933, 3423, 199, 81, 37, 19, 370, 1894, 37, 5756, 12, 314, 4465, 28633, 8041, 12271, 199, 81, 37, 18, 221, 359, 17, 12, 650, 12, 1616, 61, 199, 81, 37, 21, 221, 359, 17, 12, 413, 14, 22, 12, 499, 14, 21, 12, 841, 12, 1227, 14, 19, 12, 1616, 61, 199, 81, 37, 709, 359, 17, 12, 413, 14, 821, 12, 413, 14, 22, 12, 499, 12, 499, 14, 21, 12, 650, 14, 18, 12, 841, 12, 959, 12, 1227, 14, 19, 12, 1695, 12, 1616, 61, 199, 199, 1107, 282, 805, 626, 13621, 874, 7182, 370, 314, 2008, 5597, 199, 1875, 63, 13603, 8, 19220, 9471, 199, 199, 624, 199, 7384, 334, 67, 9, 665, 9261, 6244, 665, 4698, 382, 27864, 6244, 665, 4698, 382, 52, 13, 26667, 6244, 665, 3833, 63, 10886, 32, 8885, 1198, 14, 957, 30, 199, 2422, 4481, 4644, 14, 199, 199, 497, 4972, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 20945, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 199, 17, 14, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 642, 2043, 769, 402, 3704, 436, 314, 2569, 6450, 14, 221, 199, 18, 14, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 4245, 12, 2043, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 3794, 2043, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 199, 24571, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 2281, 2, 2401, 199, 8974, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 199, 55, 2007, 2563, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 9315, 199, 6178, 8766, 1149, 14, 1621, 4825, 6461, 7000, 2334, 5877, 11489, 1549, 6483, 6262, 7024, 2381, 199, 8974, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 199, 8, 6446, 12, 5400, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 199, 28010, 1634, 4815, 12, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 199, 615, 1821, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 8, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 199, 26734, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 1918, 6858, 436, 406, 18540, 10470, 315, 314, 2032, 436, 3794, 787, 5204, 199, 1618, 314, 11462, 436, 1077, 440, 506, 11922, 465, 6144, 25410, 14118, 12, 221, 199, 22051, 19147, 503, 2478, 12, 402, 314, 2868, 15400, 7290, 14, 199, 624, 199, 199, 3, 2337, 787, 9978, 3365, 15217, 642, 805, 1443, 506, 4286, 4583, 199, 3, 642, 4440, 2463, 83, 1482, 334, 20684, 473, 4293, 12, 436, 13632, 370, 862, 652, 9, 199, 3, 8679, 17330, 473, 4293, 1852, 282, 1021, 543, 282, 636, 1250, 363, 1083, 199, 3, 503, 9329, 1218, 3423, 10250, 626, 886, 652, 199, 3, 440, 3238, 1314, 365, 314, 5526, 199, 199, 1023, 275, 283, 17, 14, 16, 258, 1487, 26381, 7800, 7, 199, 199, 646, 3473, 199, 199, 318, 1852, 63, 13603, 8, 19220, 304, 272, 408, 372, 314, 15381, 805, 12, 876, 11786, 543, 314, 5597, 339, 5597, 9174, 543, 282, 413, 12, 365, 3485, 357, 265, 7288, 22255, 12, 272, 652, 7890, 282, 2312, 15890, 1183, 12247, 461, 1425, 543, 282, 10463, 402, 314, 2061, 15, 2246, 5579, 258, 2286, 1306, 1894, 37, 713, 8, 17, 14, 22, 9, 272, 413, 14, 21, 339, 1306, 1894, 37, 713, 8, 17, 14, 22, 12, 17, 9, 272, 413, 14, 24, 339, 1306, 1894, 37, 713, 8, 24, 14, 19, 12, 3268, 29, 20, 9, 272, 6155, 14, 16, 2286, 1306, 1894, 37, 713, 8, 1196, 9, 272, 6155, 14, 16, 2286, 1306, 5041, 14010, 20, 70, 5285, 908, 8, 81, 37, 713, 8, 16, 14, 1196, 430, 272, 283, 16, 14, 1085, 383, 7, 2378, 408, 272, 347, 15381, 8, 88, 12, 17173, 29, 16, 12, 3268, 29, 16, 304, 267, 408, 5843, 4466, 261, 671, 398, 17173, 275, 378, 334, 885, 9, 372, 314, 2312, 15890, 1183, 17173, 1329, 267, 17173, 275, 446, 17, 3515, 372, 314, 5117, 1329, 334, 11289, 9, 267, 17173, 275, 413, 3698, 372, 314, 10948, 1329, 334, 14085, 9, 267, 3268, 275, 378, 334, 885, 9, 221, 372, 314, 1329, 465, 365, 267, 3268, 275, 302, 3322, 372, 314, 30564, 10948, 503, 5117, 13621, 20592, 3650, 624, 398, 327, 25092, 261, 314, 1324, 1249, 334, 83, 4040, 590, 12, 1077, 473, 2069, 342, 652, 17076, 267, 671, 63, 396, 275, 2853, 8, 88, 9, 267, 340, 671, 63, 396, 28, 17, 69, 13, 1960, 26, 221, 327, 503, 15685, 7425, 511, 1329, 288, 372, 378, 267, 340, 671, 28, 16, 26, 288, 2070, 275, 446, 17, 267, 587, 26, 288, 2070, 275, 413, 398, 327, 664, 314, 5597, 1425, 4960, 1300, 16, 275, 5597, 59, 16, 61, 267, 1300, 17, 275, 5597, 1988, 17, 61, 267, 11104, 77, 17, 275, 822, 8, 19220, 7216, 17, 398, 327, 330, 5985, 4154, 511, 1329, 1901, 314, 5597, 1425, 12, 1437, 365, 314, 1425, 7074, 1415, 267, 1437, 275, 3473, 14, 11289, 8, 3442, 14, 793, 8, 88, 63, 396, 2447, 3442, 14, 793, 8, 1095, 17, 430, 267, 671, 63, 396, 9000, 1300, 17, 31339, 1474, 9, 398, 327, 3366, 2754, 367, 314, 7008, 436, 5117, 10461, 6818, 1425, 68, 671, 267, 284, 674, 275, 378, 267, 284, 6260, 275, 11104, 77, 17, 267, 1830, 284, 6260, 13, 73, 674, 690, 413, 26, 288, 3416, 344, 275, 1109, 1332, 73, 674, 11, 73, 6260, 2447, 18, 9, 288, 340, 671, 63, 396, 30, 5597, 59, 1017, 344, 2189, 355, 284, 674, 275, 3416, 344, 288, 587, 26, 355, 284, 6260, 275, 3416, 344, 398, 327, 886, 781, 2934, 370, 675, 314, 5117, 503, 7008, 3914, 31, 267, 308, 275, 1109, 8, 16615, 9, 267, 340 ]
[ 4843, 1894, 13933, 13621, 332, 3423, 12, 436, 8605, 1852, 63, 13603, 805, 199, 199, 1180, 805, 2463, 83, 1482, 370, 372, 314, 2569, 876, 13, 4037, 1894, 13933, 3423, 199, 81, 37, 19, 370, 1894, 37, 5756, 12, 314, 4465, 28633, 8041, 12271, 199, 81, 37, 18, 221, 359, 17, 12, 650, 12, 1616, 61, 199, 81, 37, 21, 221, 359, 17, 12, 413, 14, 22, 12, 499, 14, 21, 12, 841, 12, 1227, 14, 19, 12, 1616, 61, 199, 81, 37, 709, 359, 17, 12, 413, 14, 821, 12, 413, 14, 22, 12, 499, 12, 499, 14, 21, 12, 650, 14, 18, 12, 841, 12, 959, 12, 1227, 14, 19, 12, 1695, 12, 1616, 61, 199, 199, 1107, 282, 805, 626, 13621, 874, 7182, 370, 314, 2008, 5597, 199, 1875, 63, 13603, 8, 19220, 9471, 199, 199, 624, 199, 7384, 334, 67, 9, 665, 9261, 6244, 665, 4698, 382, 27864, 6244, 665, 4698, 382, 52, 13, 26667, 6244, 665, 3833, 63, 10886, 32, 8885, 1198, 14, 957, 30, 199, 2422, 4481, 4644, 14, 199, 199, 497, 4972, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 20945, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 199, 17, 14, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 642, 2043, 769, 402, 3704, 436, 314, 2569, 6450, 14, 221, 199, 18, 14, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 4245, 12, 2043, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 3794, 2043, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 199, 24571, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 2281, 2, 2401, 199, 8974, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 199, 55, 2007, 2563, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 9315, 199, 6178, 8766, 1149, 14, 1621, 4825, 6461, 7000, 2334, 5877, 11489, 1549, 6483, 6262, 7024, 2381, 199, 8974, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 199, 8, 6446, 12, 5400, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 199, 28010, 1634, 4815, 12, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 199, 615, 1821, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 8, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 199, 26734, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 1918, 6858, 436, 406, 18540, 10470, 315, 314, 2032, 436, 3794, 787, 5204, 199, 1618, 314, 11462, 436, 1077, 440, 506, 11922, 465, 6144, 25410, 14118, 12, 221, 199, 22051, 19147, 503, 2478, 12, 402, 314, 2868, 15400, 7290, 14, 199, 624, 199, 199, 3, 2337, 787, 9978, 3365, 15217, 642, 805, 1443, 506, 4286, 4583, 199, 3, 642, 4440, 2463, 83, 1482, 334, 20684, 473, 4293, 12, 436, 13632, 370, 862, 652, 9, 199, 3, 8679, 17330, 473, 4293, 1852, 282, 1021, 543, 282, 636, 1250, 363, 1083, 199, 3, 503, 9329, 1218, 3423, 10250, 626, 886, 652, 199, 3, 440, 3238, 1314, 365, 314, 5526, 199, 199, 1023, 275, 283, 17, 14, 16, 258, 1487, 26381, 7800, 7, 199, 199, 646, 3473, 199, 199, 318, 1852, 63, 13603, 8, 19220, 304, 272, 408, 372, 314, 15381, 805, 12, 876, 11786, 543, 314, 5597, 339, 5597, 9174, 543, 282, 413, 12, 365, 3485, 357, 265, 7288, 22255, 12, 272, 652, 7890, 282, 2312, 15890, 1183, 12247, 461, 1425, 543, 282, 10463, 402, 314, 2061, 15, 2246, 5579, 258, 2286, 1306, 1894, 37, 713, 8, 17, 14, 22, 9, 272, 413, 14, 21, 339, 1306, 1894, 37, 713, 8, 17, 14, 22, 12, 17, 9, 272, 413, 14, 24, 339, 1306, 1894, 37, 713, 8, 24, 14, 19, 12, 3268, 29, 20, 9, 272, 6155, 14, 16, 2286, 1306, 1894, 37, 713, 8, 1196, 9, 272, 6155, 14, 16, 2286, 1306, 5041, 14010, 20, 70, 5285, 908, 8, 81, 37, 713, 8, 16, 14, 1196, 430, 272, 283, 16, 14, 1085, 383, 7, 2378, 408, 272, 347, 15381, 8, 88, 12, 17173, 29, 16, 12, 3268, 29, 16, 304, 267, 408, 5843, 4466, 261, 671, 398, 17173, 275, 378, 334, 885, 9, 372, 314, 2312, 15890, 1183, 17173, 1329, 267, 17173, 275, 446, 17, 3515, 372, 314, 5117, 1329, 334, 11289, 9, 267, 17173, 275, 413, 3698, 372, 314, 10948, 1329, 334, 14085, 9, 267, 3268, 275, 378, 334, 885, 9, 221, 372, 314, 1329, 465, 365, 267, 3268, 275, 302, 3322, 372, 314, 30564, 10948, 503, 5117, 13621, 20592, 3650, 624, 398, 327, 25092, 261, 314, 1324, 1249, 334, 83, 4040, 590, 12, 1077, 473, 2069, 342, 652, 17076, 267, 671, 63, 396, 275, 2853, 8, 88, 9, 267, 340, 671, 63, 396, 28, 17, 69, 13, 1960, 26, 221, 327, 503, 15685, 7425, 511, 1329, 288, 372, 378, 267, 340, 671, 28, 16, 26, 288, 2070, 275, 446, 17, 267, 587, 26, 288, 2070, 275, 413, 398, 327, 664, 314, 5597, 1425, 4960, 1300, 16, 275, 5597, 59, 16, 61, 267, 1300, 17, 275, 5597, 1988, 17, 61, 267, 11104, 77, 17, 275, 822, 8, 19220, 7216, 17, 398, 327, 330, 5985, 4154, 511, 1329, 1901, 314, 5597, 1425, 12, 1437, 365, 314, 1425, 7074, 1415, 267, 1437, 275, 3473, 14, 11289, 8, 3442, 14, 793, 8, 88, 63, 396, 2447, 3442, 14, 793, 8, 1095, 17, 430, 267, 671, 63, 396, 9000, 1300, 17, 31339, 1474, 9, 398, 327, 3366, 2754, 367, 314, 7008, 436, 5117, 10461, 6818, 1425, 68, 671, 267, 284, 674, 275, 378, 267, 284, 6260, 275, 11104, 77, 17, 267, 1830, 284, 6260, 13, 73, 674, 690, 413, 26, 288, 3416, 344, 275, 1109, 1332, 73, 674, 11, 73, 6260, 2447, 18, 9, 288, 340, 671, 63, 396, 30, 5597, 59, 1017, 344, 2189, 355, 284, 674, 275, 3416, 344, 288, 587, 26, 355, 284, 6260, 275, 3416, 344, 398, 327, 886, 781, 2934, 370, 675, 314, 5117, 503, 7008, 3914, 31, 267, 308, 275, 1109, 8, 16615, 9, 267, 340, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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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 ]
keuv-grvl/bioconda-recipes
recipes/biopet-validatefastq/biopet-validatefastq.py
62
3379
#!/usr/bin/env python # # Wrapper script for starting the biopet-validatefastq JAR package # # This script is written for use with the Conda package manager and is copied # from the peptide-shaker wrapper. Only the parameters are changed. # (https://github.com/bioconda/bioconda-recipes/blob/master/recipes/peptide-shaker/peptide-shaker.py) # # This file was automatically generated by the sbt-bioconda plugin. import os import subprocess import sys import shutil from os import access from os import getenv from os import X_OK jar_file = 'validatefastq-assembly-0.1.1.jar' default_jvm_mem_opts = [] # !!! End of parameter section. No user-serviceable code below this line !!! def real_dirname(path): """Return the symlink-resolved, canonicalized directory-portion of path.""" return os.path.dirname(os.path.realpath(path)) def java_executable(): """Return the executable name of the Java interpreter.""" java_home = getenv('JAVA_HOME') java_bin = os.path.join('bin', 'java') if java_home and access(os.path.join(java_home, java_bin), X_OK): return os.path.join(java_home, java_bin) else: return 'java' def jvm_opts(argv): """Construct list of Java arguments based on our argument list. The argument list passed in argv must not include the script name. The return value is a 3-tuple lists of strings of the form: (memory_options, prop_options, passthrough_options) """ mem_opts = [] prop_opts = [] pass_args = [] exec_dir = None for arg in argv: if arg.startswith('-D'): prop_opts.append(arg) elif arg.startswith('-XX'): prop_opts.append(arg) elif arg.startswith('-Xm'): mem_opts.append(arg) elif arg.startswith('--exec_dir='): exec_dir = arg.split('=')[1].strip('"').strip("'") if not os.path.exists(exec_dir): shutil.copytree(real_dirname(sys.argv[0]), exec_dir, symlinks=False, ignore=None) else: pass_args.append(arg) # In the original shell script the test coded below read: # if [ "$jvm_mem_opts" == "" ] && [ -z ${_JAVA_OPTIONS+x} ] # To reproduce the behaviour of the above shell code fragment # it is important to explictly check for equality with None # in the second condition, so a null envar value counts as True! if mem_opts == [] and getenv('_JAVA_OPTIONS') is None: mem_opts = default_jvm_mem_opts return (mem_opts, prop_opts, pass_args, exec_dir) def main(): """ PeptideShaker updates files relative to the path of the jar file. In a multiuser setting, the option --exec_dir="exec_dir" can be used as the location for the peptide-shaker distribution. If the exec_dir dies not exist, we copy the jar file, lib, and resources to the exec_dir directory. """ java = java_executable() (mem_opts, prop_opts, pass_args, exec_dir) = jvm_opts(sys.argv[1:]) jar_dir = exec_dir if exec_dir else real_dirname(sys.argv[0]) if pass_args != [] and pass_args[0].startswith('eu'): jar_arg = '-cp' else: jar_arg = '-jar' jar_path = os.path.join(jar_dir, jar_file) java_args = [java] + mem_opts + prop_opts + [jar_arg] + [jar_path] + pass_args sys.exit(subprocess.call(java_args)) if __name__ == '__main__': main()
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 21947, 2884, 367, 6617, 314, 28897, 8096, 13, 3502, 26423, 1603, 689, 2559, 199, 3, 199, 3, 961, 2884, 365, 5313, 367, 675, 543, 314, 1448, 983, 2559, 5256, 436, 365, 8876, 199, 3, 687, 314, 22602, 280, 271, 13, 25880, 4975, 14, 5972, 314, 2633, 787, 2896, 14, 199, 3, 334, 2859, 921, 5031, 14, 957, 15, 17614, 23463, 15, 17614, 23463, 13, 25200, 15, 6582, 15, 4133, 15, 25200, 15, 12636, 280, 271, 13, 25880, 15, 12636, 280, 271, 13, 25880, 14, 647, 9, 199, 3, 199, 3, 961, 570, 1990, 5847, 4046, 701, 314, 308, 13061, 13, 17614, 23463, 3589, 14, 199, 199, 646, 747, 199, 646, 3873, 199, 646, 984, 199, 646, 5145, 199, 199, 504, 747, 492, 2879, 199, 504, 747, 492, 29626, 199, 504, 747, 492, 1323, 63, 3593, 199, 199, 7338, 63, 493, 275, 283, 3502, 26423, 13, 17828, 13, 16, 14, 17, 14, 17, 14, 7338, 7, 199, 199, 885, 63, 15813, 63, 5286, 63, 3291, 275, 942, 199, 199, 3, 221, 21512, 9599, 402, 2725, 3420, 14, 3091, 922, 13, 1364, 461, 1233, 5084, 642, 1004, 221, 21512, 398, 199, 318, 3363, 63, 3475, 8, 515, 304, 272, 408, 1767, 314, 15296, 13, 13697, 12, 11358, 1759, 2082, 13, 7314, 296, 402, 931, 1041, 272, 372, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 11091, 8, 515, 430, 421, 199, 318, 12120, 63, 5904, 837, 272, 408, 1767, 314, 7286, 536, 402, 314, 9586, 12693, 1041, 272, 12120, 63, 4219, 275, 29626, 360, 42, 28520, 63, 9524, 358, 272, 12120, 63, 1393, 275, 747, 14, 515, 14, 904, 360, 1393, 297, 283, 6138, 358, 339, 340, 12120, 63, 4219, 436, 2879, 8, 736, 14, 515, 14, 904, 8, 6138, 63, 4219, 12, 12120, 63, 1393, 395, 1323, 63, 3593, 304, 267, 372, 747, 14, 515, 14, 904, 8, 6138, 63, 4219, 12, 12120, 63, 1393, 9, 272, 587, 26, 267, 372, 283, 6138, 7, 421, 199, 318, 1335, 2611, 63, 3291, 8, 3020, 304, 272, 408, 11493, 769, 402, 9586, 2368, 4079, 641, 4154, 1423, 769, 14, 339, 710, 1423, 769, 3032, 315, 9238, 1471, 440, 2387, 314, 2884, 536, 14, 272, 710, 372, 574, 365, 282, 650, 13, 2960, 5548, 402, 3326, 402, 314, 1824, 26, 489, 334, 4844, 63, 1419, 12, 5931, 63, 1419, 12, 19099, 20887, 63, 1419, 9, 272, 408, 272, 7573, 63, 3291, 275, 942, 272, 5931, 63, 3291, 275, 942, 272, 986, 63, 589, 275, 942, 272, 2146, 63, 694, 275, 488, 339, 367, 1680, 315, 9238, 26, 267, 340, 1680, 14, 2460, 3654, 36, 735, 288, 5931, 63, 3291, 14, 740, 8, 1273, 9, 267, 916, 1680, 14, 2460, 3654, 2483, 735, 288, 5931, 63, 3291, 14, 740, 8, 1273, 9, 267, 916, 1680, 14, 2460, 3654, 56, 77, 735, 288, 7573, 63, 3291, 14, 740, 8, 1273, 9, 267, 916, 1680, 14, 2460, 4517, 1628, 63, 694, 534, 304, 288, 2146, 63, 694, 275, 1680, 14, 1294, 26800, 5832, 17, 1055, 1913, 14088, 1959, 1913, 480, 9859, 288, 340, 440, 747, 14, 515, 14, 2444, 8, 1628, 63, 694, 304, 355, 5145, 14, 29296, 8, 3093, 63, 3475, 8, 1274, 14, 3020, 59, 16, 2522, 2146, 63, 694, 12, 19891, 29, 797, 12, 3686, 29, 403, 9, 267, 587, 26, 288, 986, 63, 589, 14, 740, 8, 1273, 9, 339, 327, 1010, 314, 3379, 5218, 2884, 314, 511, 1233, 68, 5084, 1586, 26, 272, 327, 257, 340, 359, 7880, 15813, 63, 5286, 63, 3291, 2, 508, 3087, 1622, 10883, 359, 446, 90, 10839, 63, 42, 28520, 63, 8808, 11, 88, 93, 1622, 272, 327, 4005, 9172, 314, 13942, 402, 314, 3432, 5218, 1233, 7956, 272, 327, 652, 365, 11012, 370, 1437, 6960, 590, 1104, 367, 16612, 543, 488, 272, 327, 315, 314, 3499, 5558, 12, 880, 282, 2973, 655, 1391, 574, 8242, 465, 715, 1, 339, 340, 7573, 63, 3291, 508, 942, 436, 29626, 6412, 42, 28520, 63, 8808, 358, 365, 488, 26, 267, 7573, 63, 3291, 275, 849, 63, 15813, 63, 5286, 63, 3291, 339, 372, 334, 5286, 63, 3291, 12, 5931, 63, 3291, 12, 986, 63, 589, 12, 2146, 63, 694, 9, 421, 199, 318, 2446, 837, 272, 408, 272, 510, 1545, 280, 271, 2662, 12630, 7029, 1584, 3847, 370, 314, 931, 402, 314, 16290, 570, 14, 272, 1010, 282, 3510, 751, 4260, 12, 314, 945, 1553, 1628, 63, 694, 628, 1628, 63, 694, 2, 272, 883, 506, 1202, 465, 314, 2909, 367, 314, 22602, 280, 271, 13, 25880, 4084, 14, 272, 982, 314, 2146, 63, 694, 487, 397, 440, 2187, 12, 272, 781, 1331, 314, 16290, 570, 12, 1973, 12, 436, 5944, 370, 314, 2146, 63, 694, 2082, 14, 272, 408, 272, 12120, 275, 12120, 63, 5904, 342, 272, 334, 5286, 63, 3291, 12, 5931, 63, 3291, 12, 986, 63, 589, 12, 2146, 63, 694, 9, 275, 1335, 2611, 63, 3291, 8, 1274, 14, 3020, 59, 17, 5728, 272, 16290, 63, 694, 275, 2146, 63, 694, 340, 2146, 63, 694, 587, 3363, 63, 3475, 8, 1274, 14, 3020, 59, 16, 566, 339, 340, 986, 63, 589, 1137, 942, 436, 986, 63, 589, 59, 16, 1055, 2460, 360, 16913, 735, 267, 16290, 63, 1273, 275, 2475, 1850, 7, 272, 587, 26, 267, 16290, 63, 1273, 275, 2475, 7338, 7, 339, 16290, 63, 515, 275, 747, 14, 515, 14, 904, 8, 7338, 63, 694, 12, 16290, 63, 493, 9, 339, 12120, 63, 589, 275, 359, 6138, 61, 435, 7573, 63, 3291, 435, 5931, 63, 3291, 435, 359, 7338, 63, 1273, 61, 435, 359, 7338, 63, 515, 61, 435, 986, 63, 589, 339, 984, 14, 2224, 8, 5781, 14, 1250, 8, 6138, 63, 589, 430, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 21947, 2884, 367, 6617, 314, 28897, 8096, 13, 3502, 26423, 1603, 689, 2559, 199, 3, 199, 3, 961, 2884, 365, 5313, 367, 675, 543, 314, 1448, 983, 2559, 5256, 436, 365, 8876, 199, 3, 687, 314, 22602, 280, 271, 13, 25880, 4975, 14, 5972, 314, 2633, 787, 2896, 14, 199, 3, 334, 2859, 921, 5031, 14, 957, 15, 17614, 23463, 15, 17614, 23463, 13, 25200, 15, 6582, 15, 4133, 15, 25200, 15, 12636, 280, 271, 13, 25880, 15, 12636, 280, 271, 13, 25880, 14, 647, 9, 199, 3, 199, 3, 961, 570, 1990, 5847, 4046, 701, 314, 308, 13061, 13, 17614, 23463, 3589, 14, 199, 199, 646, 747, 199, 646, 3873, 199, 646, 984, 199, 646, 5145, 199, 199, 504, 747, 492, 2879, 199, 504, 747, 492, 29626, 199, 504, 747, 492, 1323, 63, 3593, 199, 199, 7338, 63, 493, 275, 283, 3502, 26423, 13, 17828, 13, 16, 14, 17, 14, 17, 14, 7338, 7, 199, 199, 885, 63, 15813, 63, 5286, 63, 3291, 275, 942, 199, 199, 3, 221, 21512, 9599, 402, 2725, 3420, 14, 3091, 922, 13, 1364, 461, 1233, 5084, 642, 1004, 221, 21512, 398, 199, 318, 3363, 63, 3475, 8, 515, 304, 272, 408, 1767, 314, 15296, 13, 13697, 12, 11358, 1759, 2082, 13, 7314, 296, 402, 931, 1041, 272, 372, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 11091, 8, 515, 430, 421, 199, 318, 12120, 63, 5904, 837, 272, 408, 1767, 314, 7286, 536, 402, 314, 9586, 12693, 1041, 272, 12120, 63, 4219, 275, 29626, 360, 42, 28520, 63, 9524, 358, 272, 12120, 63, 1393, 275, 747, 14, 515, 14, 904, 360, 1393, 297, 283, 6138, 358, 339, 340, 12120, 63, 4219, 436, 2879, 8, 736, 14, 515, 14, 904, 8, 6138, 63, 4219, 12, 12120, 63, 1393, 395, 1323, 63, 3593, 304, 267, 372, 747, 14, 515, 14, 904, 8, 6138, 63, 4219, 12, 12120, 63, 1393, 9, 272, 587, 26, 267, 372, 283, 6138, 7, 421, 199, 318, 1335, 2611, 63, 3291, 8, 3020, 304, 272, 408, 11493, 769, 402, 9586, 2368, 4079, 641, 4154, 1423, 769, 14, 339, 710, 1423, 769, 3032, 315, 9238, 1471, 440, 2387, 314, 2884, 536, 14, 272, 710, 372, 574, 365, 282, 650, 13, 2960, 5548, 402, 3326, 402, 314, 1824, 26, 489, 334, 4844, 63, 1419, 12, 5931, 63, 1419, 12, 19099, 20887, 63, 1419, 9, 272, 408, 272, 7573, 63, 3291, 275, 942, 272, 5931, 63, 3291, 275, 942, 272, 986, 63, 589, 275, 942, 272, 2146, 63, 694, 275, 488, 339, 367, 1680, 315, 9238, 26, 267, 340, 1680, 14, 2460, 3654, 36, 735, 288, 5931, 63, 3291, 14, 740, 8, 1273, 9, 267, 916, 1680, 14, 2460, 3654, 2483, 735, 288, 5931, 63, 3291, 14, 740, 8, 1273, 9, 267, 916, 1680, 14, 2460, 3654, 56, 77, 735, 288, 7573, 63, 3291, 14, 740, 8, 1273, 9, 267, 916, 1680, 14, 2460, 4517, 1628, 63, 694, 534, 304, 288, 2146, 63, 694, 275, 1680, 14, 1294, 26800, 5832, 17, 1055, 1913, 14088, 1959, 1913, 480, 9859, 288, 340, 440, 747, 14, 515, 14, 2444, 8, 1628, 63, 694, 304, 355, 5145, 14, 29296, 8, 3093, 63, 3475, 8, 1274, 14, 3020, 59, 16, 2522, 2146, 63, 694, 12, 19891, 29, 797, 12, 3686, 29, 403, 9, 267, 587, 26, 288, 986, 63, 589, 14, 740, 8, 1273, 9, 339, 327, 1010, 314, 3379, 5218, 2884, 314, 511, 1233, 68, 5084, 1586, 26, 272, 327, 257, 340, 359, 7880, 15813, 63, 5286, 63, 3291, 2, 508, 3087, 1622, 10883, 359, 446, 90, 10839, 63, 42, 28520, 63, 8808, 11, 88, 93, 1622, 272, 327, 4005, 9172, 314, 13942, 402, 314, 3432, 5218, 1233, 7956, 272, 327, 652, 365, 11012, 370, 1437, 6960, 590, 1104, 367, 16612, 543, 488, 272, 327, 315, 314, 3499, 5558, 12, 880, 282, 2973, 655, 1391, 574, 8242, 465, 715, 1, 339, 340, 7573, 63, 3291, 508, 942, 436, 29626, 6412, 42, 28520, 63, 8808, 358, 365, 488, 26, 267, 7573, 63, 3291, 275, 849, 63, 15813, 63, 5286, 63, 3291, 339, 372, 334, 5286, 63, 3291, 12, 5931, 63, 3291, 12, 986, 63, 589, 12, 2146, 63, 694, 9, 421, 199, 318, 2446, 837, 272, 408, 272, 510, 1545, 280, 271, 2662, 12630, 7029, 1584, 3847, 370, 314, 931, 402, 314, 16290, 570, 14, 272, 1010, 282, 3510, 751, 4260, 12, 314, 945, 1553, 1628, 63, 694, 628, 1628, 63, 694, 2, 272, 883, 506, 1202, 465, 314, 2909, 367, 314, 22602, 280, 271, 13, 25880, 4084, 14, 272, 982, 314, 2146, 63, 694, 487, 397, 440, 2187, 12, 272, 781, 1331, 314, 16290, 570, 12, 1973, 12, 436, 5944, 370, 314, 2146, 63, 694, 2082, 14, 272, 408, 272, 12120, 275, 12120, 63, 5904, 342, 272, 334, 5286, 63, 3291, 12, 5931, 63, 3291, 12, 986, 63, 589, 12, 2146, 63, 694, 9, 275, 1335, 2611, 63, 3291, 8, 1274, 14, 3020, 59, 17, 5728, 272, 16290, 63, 694, 275, 2146, 63, 694, 340, 2146, 63, 694, 587, 3363, 63, 3475, 8, 1274, 14, 3020, 59, 16, 566, 339, 340, 986, 63, 589, 1137, 942, 436, 986, 63, 589, 59, 16, 1055, 2460, 360, 16913, 735, 267, 16290, 63, 1273, 275, 2475, 1850, 7, 272, 587, 26, 267, 16290, 63, 1273, 275, 2475, 7338, 7, 339, 16290, 63, 515, 275, 747, 14, 515, 14, 904, 8, 7338, 63, 694, 12, 16290, 63, 493, 9, 339, 12120, 63, 589, 275, 359, 6138, 61, 435, 7573, 63, 3291, 435, 5931, 63, 3291, 435, 359, 7338, 63, 1273, 61, 435, 359, 7338, 63, 515, 61, 435, 986, 63, 589, 339, 984, 14, 2224, 8, 5781, 14, 1250, 8, 6138, 63, 589, 430, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
hdinsight/hue
desktop/core/ext-py/Django-1.6.10/django/template/loader.py
117
7545
# Wrapper for loading templates from storage of some sort (e.g. filesystem, database). # # This uses the TEMPLATE_LOADERS setting, which is a list of loaders to use. # Each loader is expected to have this interface: # # callable(name, dirs=[]) # # name is the template name. # dirs is an optional list of directories to search instead of TEMPLATE_DIRS. # # The loader should return a tuple of (template_source, path). The path returned # might be shown to the user for debugging purposes, so it should identify where # the template was loaded from. # # A loader may return an already-compiled template instead of the actual # template source. In that case the path returned should be None, since the # path information is associated with the template during the compilation, # which has already been done. # # Each loader should have an "is_usable" attribute set. This is a boolean that # specifies whether the loader can be used in this Python installation. Each # loader is responsible for setting this when it's initialized. # # For example, the eggs loader (which is capable of loading templates from # Python eggs) sets is_usable to False if the "pkg_resources" module isn't # installed, because pkg_resources is necessary to read eggs. from django.core.exceptions import ImproperlyConfigured from django.template.base import Origin, Template, Context, TemplateDoesNotExist, add_to_builtins from django.conf import settings from django.utils.module_loading import import_by_path from django.utils import six template_source_loaders = None class BaseLoader(object): is_usable = False def __init__(self, *args, **kwargs): pass def __call__(self, template_name, template_dirs=None): return self.load_template(template_name, template_dirs) def load_template(self, template_name, template_dirs=None): source, display_name = self.load_template_source(template_name, template_dirs) origin = make_origin(display_name, self.load_template_source, template_name, template_dirs) try: template = get_template_from_string(source, origin, template_name) return template, None except TemplateDoesNotExist: # If compiling the template we found raises TemplateDoesNotExist, back off to # returning the source and display name for the template we were asked to load. # This allows for correct identification (later) of the actual template that does # not exist. return source, display_name def load_template_source(self, template_name, template_dirs=None): """ Returns a tuple containing the source and origin for the given template name. """ raise NotImplementedError def reset(self): """ Resets any state maintained by the loader instance (e.g., cached templates or cached loader modules). """ pass class LoaderOrigin(Origin): def __init__(self, display_name, loader, name, dirs): super(LoaderOrigin, self).__init__(display_name) self.loader, self.loadname, self.dirs = loader, name, dirs def reload(self): return self.loader(self.loadname, self.dirs)[0] def make_origin(display_name, loader, name, dirs): if settings.TEMPLATE_DEBUG and display_name: return LoaderOrigin(display_name, loader, name, dirs) else: return None def find_template_loader(loader): if isinstance(loader, (tuple, list)): loader, args = loader[0], loader[1:] else: args = [] if isinstance(loader, six.string_types): TemplateLoader = import_by_path(loader) if hasattr(TemplateLoader, 'load_template_source'): func = TemplateLoader(*args) else: # Try loading module the old way - string is full path to callable if args: raise ImproperlyConfigured("Error importing template source loader %s - can't pass arguments to function-based loader." % loader) func = TemplateLoader if not func.is_usable: import warnings warnings.warn("Your TEMPLATE_LOADERS setting includes %r, but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS." % loader) return None else: return func else: raise ImproperlyConfigured('Loader does not define a "load_template" callable template source loader') def find_template(name, dirs=None): # Calculate template_source_loaders the first time the function is executed # because putting this logic in the module-level namespace may cause # circular import errors. See Django ticket #1292. global template_source_loaders if template_source_loaders is None: loaders = [] for loader_name in settings.TEMPLATE_LOADERS: loader = find_template_loader(loader_name) if loader is not None: loaders.append(loader) template_source_loaders = tuple(loaders) for loader in template_source_loaders: try: source, display_name = loader(name, dirs) return (source, make_origin(display_name, loader, name, dirs)) except TemplateDoesNotExist: pass raise TemplateDoesNotExist(name) def get_template(template_name): """ Returns a compiled Template object for the given template name, handling template inheritance recursively. """ template, origin = find_template(template_name) if not hasattr(template, 'render'): # template needs to be compiled template = get_template_from_string(template, origin, template_name) return template def get_template_from_string(source, origin=None, name=None): """ Returns a compiled Template object for the given template code, handling template inheritance recursively. """ return Template(source, origin, name) def render_to_string(template_name, dictionary=None, context_instance=None): """ Loads the given template_name and renders it with the given dictionary as context. The template_name may be a string to load a single template using get_template, or it may be a tuple to use select_template to find one of the templates in the list. Returns a string. """ dictionary = dictionary or {} if isinstance(template_name, (list, tuple)): t = select_template(template_name) else: t = get_template(template_name) if not context_instance: return t.render(Context(dictionary)) # Add the dictionary to the context stack, ensuring it gets removed again # to keep the context_instance in the same state it started in. context_instance.update(dictionary) try: return t.render(context_instance) finally: context_instance.pop() def select_template(template_name_list): "Given a list of template names, returns the first that can be loaded." if not template_name_list: raise TemplateDoesNotExist("No template names provided") not_found = [] for template_name in template_name_list: try: return get_template(template_name) except TemplateDoesNotExist as e: if e.args[0] not in not_found: not_found.append(e.args[0]) continue # If we get here, none of the templates could be loaded raise TemplateDoesNotExist(', '.join(not_found)) add_to_builtins('django.template.loader_tags')
apache-2.0
[ 3, 21947, 367, 8697, 7009, 687, 4887, 402, 2005, 4069, 334, 69, 14, 71, 14, 10036, 12, 3050, 680, 199, 3, 199, 3, 961, 4440, 314, 24877, 63, 7405, 3960, 4260, 12, 1314, 365, 282, 769, 402, 25520, 370, 675, 14, 199, 3, 7048, 5077, 365, 1420, 370, 1172, 642, 3217, 26, 199, 3, 199, 3, 259, 4550, 8, 354, 12, 7606, 14285, 199, 3, 199, 3, 536, 365, 314, 1978, 536, 14, 199, 3, 7606, 365, 376, 2716, 769, 402, 6602, 370, 2754, 3140, 402, 24877, 63, 14455, 14, 199, 3, 199, 3, 710, 5077, 1077, 372, 282, 2008, 402, 334, 1160, 63, 1365, 12, 931, 680, 710, 931, 2138, 199, 3, 5594, 506, 9164, 370, 314, 922, 367, 10201, 12901, 12, 880, 652, 1077, 10405, 2382, 199, 3, 314, 1978, 1990, 6511, 687, 14, 199, 3, 199, 3, 437, 5077, 1443, 372, 376, 2575, 13, 8427, 1978, 3140, 402, 314, 3503, 199, 3, 1978, 1350, 14, 1010, 626, 1930, 314, 931, 2138, 1077, 506, 488, 12, 3967, 314, 199, 3, 931, 2556, 365, 4568, 543, 314, 1978, 5309, 314, 18653, 12, 199, 3, 1314, 965, 2575, 2757, 4224, 14, 199, 3, 199, 3, 7048, 5077, 1077, 1172, 376, 298, 374, 63, 14418, 2, 2225, 663, 14, 961, 365, 282, 5046, 626, 199, 3, 9314, 3775, 314, 5077, 883, 506, 1202, 315, 642, 2018, 12096, 14, 7048, 199, 3, 5077, 365, 17845, 367, 4260, 642, 1380, 652, 1159, 10038, 14, 199, 3, 199, 3, 2104, 2893, 12, 314, 22151, 5077, 334, 6777, 365, 4021, 461, 402, 8697, 7009, 687, 199, 3, 2018, 22151, 9, 5951, 365, 63, 14418, 370, 756, 340, 314, 298, 4600, 63, 4435, 2, 859, 5712, 1133, 199, 3, 4903, 12, 2952, 5496, 63, 4435, 365, 5784, 370, 1586, 22151, 14, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1160, 14, 1095, 492, 31534, 12, 5458, 12, 9470, 12, 27193, 12, 1050, 63, 475, 63, 10372, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1208, 14, 578, 63, 8786, 492, 492, 63, 991, 63, 515, 199, 504, 1639, 14, 1208, 492, 3816, 199, 199, 1160, 63, 1365, 63, 16370, 275, 488, 199, 199, 533, 3523, 5455, 8, 785, 304, 272, 365, 63, 14418, 275, 756, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 986, 339, 347, 636, 1250, 721, 277, 12, 1978, 63, 354, 12, 1978, 63, 3220, 29, 403, 304, 267, 372, 291, 14, 912, 63, 1160, 8, 1160, 63, 354, 12, 1978, 63, 3220, 9, 339, 347, 2248, 63, 1160, 8, 277, 12, 1978, 63, 354, 12, 1978, 63, 3220, 29, 403, 304, 267, 1350, 12, 2929, 63, 354, 275, 291, 14, 912, 63, 1160, 63, 1365, 8, 1160, 63, 354, 12, 1978, 63, 3220, 9, 267, 6330, 275, 1852, 63, 6493, 8, 2918, 63, 354, 12, 291, 14, 912, 63, 1160, 63, 1365, 12, 1978, 63, 354, 12, 1978, 63, 3220, 9, 267, 862, 26, 288, 1978, 275, 664, 63, 1160, 63, 504, 63, 875, 8, 1365, 12, 6330, 12, 1978, 63, 354, 9, 288, 372, 1978, 12, 488, 267, 871, 27193, 26, 288, 327, 982, 1013, 5662, 314, 1978, 781, 1911, 6534, 27193, 12, 1771, 2331, 370, 288, 327, 8152, 314, 1350, 436, 2929, 536, 367, 314, 1978, 781, 4898, 20864, 370, 2248, 14, 288, 327, 961, 6127, 367, 3211, 29193, 334, 18103, 9, 402, 314, 3503, 1978, 626, 1630, 288, 327, 440, 2187, 14, 288, 372, 1350, 12, 2929, 63, 354, 339, 347, 2248, 63, 1160, 63, 1365, 8, 277, 12, 1978, 63, 354, 12, 1978, 63, 3220, 29, 403, 304, 267, 408, 267, 1803, 282, 2008, 3035, 314, 1350, 436, 6330, 367, 314, 1627, 1978, 267, 536, 14, 398, 408, 267, 746, 4279, 339, 347, 5305, 8, 277, 304, 267, 408, 267, 799, 2193, 1263, 1174, 26391, 701, 314, 5077, 1256, 334, 69, 14, 71, 2020, 6328, 267, 7009, 503, 6328, 5077, 4621, 680, 398, 408, 267, 986, 199, 199, 533, 22865, 12834, 8, 12834, 304, 272, 347, 636, 826, 721, 277, 12, 2929, 63, 354, 12, 5077, 12, 536, 12, 7606, 304, 267, 1613, 8, 5455, 12834, 12, 291, 2843, 826, 721, 2918, 63, 354, 9, 267, 291, 14, 3422, 12, 291, 14, 912, 354, 12, 291, 14, 3220, 275, 5077, 12, 536, 12, 7606, 339, 347, 13101, 8, 277, 304, 267, 372, 291, 14, 3422, 8, 277, 14, 912, 354, 12, 291, 14, 3220, 2788, 16, 61, 199, 199, 318, 1852, 63, 6493, 8, 2918, 63, 354, 12, 5077, 12, 536, 12, 7606, 304, 272, 340, 2202, 14, 7433, 63, 5287, 436, 2929, 63, 354, 26, 267, 372, 22865, 12834, 8, 2918, 63, 354, 12, 5077, 12, 536, 12, 7606, 9, 272, 587, 26, 267, 372, 488, 199, 199, 318, 2342, 63, 1160, 63, 3422, 8, 3422, 304, 272, 340, 1228, 8, 3422, 12, 334, 2960, 12, 769, 2298, 267, 5077, 12, 1249, 275, 5077, 59, 16, 467, 5077, 59, 17, 2938, 272, 587, 26, 267, 1249, 275, 942, 272, 340, 1228, 8, 3422, 12, 3816, 14, 875, 63, 1313, 304, 267, 5458, 5455, 275, 492, 63, 991, 63, 515, 8, 3422, 9, 398, 340, 2688, 8, 4231, 5455, 12, 283, 912, 63, 1160, 63, 1365, 735, 288, 2562, 275, 5458, 5455, 2031, 589, 9, 267, 587, 26, 288, 327, 7649, 8697, 859, 314, 2269, 4340, 446, 1059, 365, 2615, 931, 370, 4550, 288, 340, 1249, 26, 355, 746, 11897, 480, 547, 16306, 1978, 1350, 5077, 450, 83, 446, 883, 1133, 986, 2368, 370, 805, 13, 6788, 5077, 2122, 450, 5077, 9, 288, 2562, 275, 5458, 5455, 398, 340, 440, 2562, 14, 374, 63, 14418, 26, 288, 492, 3598, 288, 3598, 14, 4050, 480, 14398, 24877, 63, 7405, 3960, 4260, 6952, 450, 82, 12, 1325, 2195, 2018, 12096, 3181, 1133, 2291, 626, 730, 402, 1978, 8697, 14, 24413, 12881, 626, 1004, 687, 24877, 63, 7405, 3960, 2122, 450, 5077, 9, 288, 372, 488, 267, 587, 26, 288, 372, 2562, 272, 587, 26, 267, 746, 11897, 360, 5455, 1630, 440, 5627, 282, 298, 912, 63, 1160, 2, 4550, 1978, 1350, 5077, 358, 199, 199, 318, 2342, 63, 1160 ]
[ 21947, 367, 8697, 7009, 687, 4887, 402, 2005, 4069, 334, 69, 14, 71, 14, 10036, 12, 3050, 680, 199, 3, 199, 3, 961, 4440, 314, 24877, 63, 7405, 3960, 4260, 12, 1314, 365, 282, 769, 402, 25520, 370, 675, 14, 199, 3, 7048, 5077, 365, 1420, 370, 1172, 642, 3217, 26, 199, 3, 199, 3, 259, 4550, 8, 354, 12, 7606, 14285, 199, 3, 199, 3, 536, 365, 314, 1978, 536, 14, 199, 3, 7606, 365, 376, 2716, 769, 402, 6602, 370, 2754, 3140, 402, 24877, 63, 14455, 14, 199, 3, 199, 3, 710, 5077, 1077, 372, 282, 2008, 402, 334, 1160, 63, 1365, 12, 931, 680, 710, 931, 2138, 199, 3, 5594, 506, 9164, 370, 314, 922, 367, 10201, 12901, 12, 880, 652, 1077, 10405, 2382, 199, 3, 314, 1978, 1990, 6511, 687, 14, 199, 3, 199, 3, 437, 5077, 1443, 372, 376, 2575, 13, 8427, 1978, 3140, 402, 314, 3503, 199, 3, 1978, 1350, 14, 1010, 626, 1930, 314, 931, 2138, 1077, 506, 488, 12, 3967, 314, 199, 3, 931, 2556, 365, 4568, 543, 314, 1978, 5309, 314, 18653, 12, 199, 3, 1314, 965, 2575, 2757, 4224, 14, 199, 3, 199, 3, 7048, 5077, 1077, 1172, 376, 298, 374, 63, 14418, 2, 2225, 663, 14, 961, 365, 282, 5046, 626, 199, 3, 9314, 3775, 314, 5077, 883, 506, 1202, 315, 642, 2018, 12096, 14, 7048, 199, 3, 5077, 365, 17845, 367, 4260, 642, 1380, 652, 1159, 10038, 14, 199, 3, 199, 3, 2104, 2893, 12, 314, 22151, 5077, 334, 6777, 365, 4021, 461, 402, 8697, 7009, 687, 199, 3, 2018, 22151, 9, 5951, 365, 63, 14418, 370, 756, 340, 314, 298, 4600, 63, 4435, 2, 859, 5712, 1133, 199, 3, 4903, 12, 2952, 5496, 63, 4435, 365, 5784, 370, 1586, 22151, 14, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1160, 14, 1095, 492, 31534, 12, 5458, 12, 9470, 12, 27193, 12, 1050, 63, 475, 63, 10372, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1208, 14, 578, 63, 8786, 492, 492, 63, 991, 63, 515, 199, 504, 1639, 14, 1208, 492, 3816, 199, 199, 1160, 63, 1365, 63, 16370, 275, 488, 199, 199, 533, 3523, 5455, 8, 785, 304, 272, 365, 63, 14418, 275, 756, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 986, 339, 347, 636, 1250, 721, 277, 12, 1978, 63, 354, 12, 1978, 63, 3220, 29, 403, 304, 267, 372, 291, 14, 912, 63, 1160, 8, 1160, 63, 354, 12, 1978, 63, 3220, 9, 339, 347, 2248, 63, 1160, 8, 277, 12, 1978, 63, 354, 12, 1978, 63, 3220, 29, 403, 304, 267, 1350, 12, 2929, 63, 354, 275, 291, 14, 912, 63, 1160, 63, 1365, 8, 1160, 63, 354, 12, 1978, 63, 3220, 9, 267, 6330, 275, 1852, 63, 6493, 8, 2918, 63, 354, 12, 291, 14, 912, 63, 1160, 63, 1365, 12, 1978, 63, 354, 12, 1978, 63, 3220, 9, 267, 862, 26, 288, 1978, 275, 664, 63, 1160, 63, 504, 63, 875, 8, 1365, 12, 6330, 12, 1978, 63, 354, 9, 288, 372, 1978, 12, 488, 267, 871, 27193, 26, 288, 327, 982, 1013, 5662, 314, 1978, 781, 1911, 6534, 27193, 12, 1771, 2331, 370, 288, 327, 8152, 314, 1350, 436, 2929, 536, 367, 314, 1978, 781, 4898, 20864, 370, 2248, 14, 288, 327, 961, 6127, 367, 3211, 29193, 334, 18103, 9, 402, 314, 3503, 1978, 626, 1630, 288, 327, 440, 2187, 14, 288, 372, 1350, 12, 2929, 63, 354, 339, 347, 2248, 63, 1160, 63, 1365, 8, 277, 12, 1978, 63, 354, 12, 1978, 63, 3220, 29, 403, 304, 267, 408, 267, 1803, 282, 2008, 3035, 314, 1350, 436, 6330, 367, 314, 1627, 1978, 267, 536, 14, 398, 408, 267, 746, 4279, 339, 347, 5305, 8, 277, 304, 267, 408, 267, 799, 2193, 1263, 1174, 26391, 701, 314, 5077, 1256, 334, 69, 14, 71, 2020, 6328, 267, 7009, 503, 6328, 5077, 4621, 680, 398, 408, 267, 986, 199, 199, 533, 22865, 12834, 8, 12834, 304, 272, 347, 636, 826, 721, 277, 12, 2929, 63, 354, 12, 5077, 12, 536, 12, 7606, 304, 267, 1613, 8, 5455, 12834, 12, 291, 2843, 826, 721, 2918, 63, 354, 9, 267, 291, 14, 3422, 12, 291, 14, 912, 354, 12, 291, 14, 3220, 275, 5077, 12, 536, 12, 7606, 339, 347, 13101, 8, 277, 304, 267, 372, 291, 14, 3422, 8, 277, 14, 912, 354, 12, 291, 14, 3220, 2788, 16, 61, 199, 199, 318, 1852, 63, 6493, 8, 2918, 63, 354, 12, 5077, 12, 536, 12, 7606, 304, 272, 340, 2202, 14, 7433, 63, 5287, 436, 2929, 63, 354, 26, 267, 372, 22865, 12834, 8, 2918, 63, 354, 12, 5077, 12, 536, 12, 7606, 9, 272, 587, 26, 267, 372, 488, 199, 199, 318, 2342, 63, 1160, 63, 3422, 8, 3422, 304, 272, 340, 1228, 8, 3422, 12, 334, 2960, 12, 769, 2298, 267, 5077, 12, 1249, 275, 5077, 59, 16, 467, 5077, 59, 17, 2938, 272, 587, 26, 267, 1249, 275, 942, 272, 340, 1228, 8, 3422, 12, 3816, 14, 875, 63, 1313, 304, 267, 5458, 5455, 275, 492, 63, 991, 63, 515, 8, 3422, 9, 398, 340, 2688, 8, 4231, 5455, 12, 283, 912, 63, 1160, 63, 1365, 735, 288, 2562, 275, 5458, 5455, 2031, 589, 9, 267, 587, 26, 288, 327, 7649, 8697, 859, 314, 2269, 4340, 446, 1059, 365, 2615, 931, 370, 4550, 288, 340, 1249, 26, 355, 746, 11897, 480, 547, 16306, 1978, 1350, 5077, 450, 83, 446, 883, 1133, 986, 2368, 370, 805, 13, 6788, 5077, 2122, 450, 5077, 9, 288, 2562, 275, 5458, 5455, 398, 340, 440, 2562, 14, 374, 63, 14418, 26, 288, 492, 3598, 288, 3598, 14, 4050, 480, 14398, 24877, 63, 7405, 3960, 4260, 6952, 450, 82, 12, 1325, 2195, 2018, 12096, 3181, 1133, 2291, 626, 730, 402, 1978, 8697, 14, 24413, 12881, 626, 1004, 687, 24877, 63, 7405, 3960, 2122, 450, 5077, 9, 288, 372, 488, 267, 587, 26, 288, 372, 2562, 272, 587, 26, 267, 746, 11897, 360, 5455, 1630, 440, 5627, 282, 298, 912, 63, 1160, 2, 4550, 1978, 1350, 5077, 358, 199, 199, 318, 2342, 63, 1160, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
benbenbenbenbenbenbenbenben/mitsingen
sing/models.py
1
3770
from __future__ import unicode_literals from django.db import models from django.conf import settings from django.db.models.signals import post_delete from django.dispatch.dispatcher import receiver import datetime class Song(models.Model): name = models.CharField(max_length=200) notes = models.CharField(max_length=2000) recording_file = models.FileField() tempo = models.FloatField() def __unicode__(self): return u"%s" % self.name class TimeSignature(models.Model): song = models.ForeignKey(Song, on_delete=models.CASCADE) start_beat_in_song = models.IntegerField() start_beat_in_bar = models.IntegerField() beats_per_bar = models.IntegerField() def __unicode__(self): return u"At beat %i start %i beats per bar" % (self.start_beat_in_song, self.beats_per_bar) class Singer(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) latency = models.FloatField() show_help = models.BooleanField() meetup_name = models.TextField(blank = True) registration_message = models.TextField(blank = True) class Part(models.Model): song = models.ForeignKey(Song, on_delete=models.CASCADE, related_name = 'parts') name = models.CharField(max_length=200) recording_file = models.FileField() midi_file = models.FileField(null=True, blank=True) def __unicode__(self): return u"%s" % self.name class Section(models.Model): song = models.ForeignKey(Song, on_delete=models.CASCADE) name = models.CharField(max_length=200) start = models.IntegerField() end = models.IntegerField() lyrics = models.TextField(blank = True) def __unicode__(self): return u"%s" % self.name class Performance(models.Model): song = models.ForeignKey(Song, on_delete=models.CASCADE) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) default_part = models.ForeignKey(Part, on_delete=models.CASCADE) def __unicode__(self): return u"%s performing %s" % (self.user.username, self.song.name) class Choir(models.Model): name = models.CharField(max_length=200) description = models.TextField(blank = True) members = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name = 'choirs') songs = models.ManyToManyField(Song) start_date = models.DateField(auto_now_add=False, default = datetime.date(2013, 1, 1)) end_date = models.DateField(auto_now_add=False, default = datetime.date(2100, 1, 1)) @property def is_old(self): return datetime.date.today() > self.end_date def __unicode__(self): return u"%s" % self.name class Recording(models.Model): name = models.CharField(max_length=200) recording_file = models.FileField() created = models.DateTimeField(auto_now_add=True) shared_with = models.ManyToManyField(Choir) def __unicode__(self): return u"%s" % ( self.created ) @receiver(post_delete, sender=Recording) def recording_delete(sender, instance, **kwargs): # Pass false so FileField doesn't save the model. instance.recording_file.delete(False) class PartPerformance(models.Model): performance = models.ForeignKey(Performance, on_delete=models.CASCADE) part = models.ForeignKey(Part, on_delete=models.CASCADE) recording1 = models.OneToOneField(Recording, on_delete=models.SET_NULL, null=True, related_name='recording1_of') recording2 = models.OneToOneField(Recording, on_delete=models.SET_NULL, null=True, related_name='recording2_of') recording3 = models.OneToOneField(Recording, on_delete=models.SET_NULL, null=True, related_name='recording3_of') def __unicode__(self): return u"%s %s" % (self.performance, self.part)
agpl-3.0
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 697, 14, 992, 14, 10458, 492, 2963, 63, 1807, 199, 504, 1639, 14, 6052, 14, 14913, 492, 13035, 199, 646, 2197, 199, 199, 533, 29405, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 12681, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 8269, 9, 272, 20952, 63, 493, 275, 1709, 14, 23252, 342, 272, 2388, 79, 275, 1709, 14, 13019, 342, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 291, 14, 354, 199, 199, 533, 4703, 10014, 8, 992, 14, 1685, 304, 272, 20178, 275, 1709, 14, 3190, 8, 51, 951, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 1343, 63, 12522, 63, 262, 63, 19351, 275, 1709, 14, 3901, 342, 272, 1343, 63, 12522, 63, 262, 63, 1700, 275, 1709, 14, 3901, 342, 272, 506, 1956, 63, 529, 63, 1700, 275, 1709, 14, 3901, 342, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 2, 1271, 506, 292, 450, 73, 1343, 450, 73, 506, 1956, 1126, 4681, 2, 450, 334, 277, 14, 928, 63, 12522, 63, 262, 63, 19351, 12, 291, 14, 1235, 1956, 63, 529, 63, 1700, 9, 199, 199, 533, 428, 7886, 8, 992, 14, 1685, 304, 272, 922, 275, 1709, 14, 14298, 8, 1751, 14, 5580, 63, 3791, 63, 11429, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 23967, 275, 1709, 14, 13019, 342, 272, 2498, 63, 3437, 275, 1709, 14, 5036, 342, 272, 26743, 384, 63, 354, 275, 1709, 14, 6254, 8, 2500, 275, 715, 9, 272, 10991, 63, 1188, 275, 1709, 14, 6254, 8, 2500, 275, 715, 9, 199, 199, 533, 14320, 8, 992, 14, 1685, 304, 272, 20178, 275, 1709, 14, 3190, 8, 51, 951, 12, 641, 63, 1807, 29, 992, 14, 10855, 12, 4048, 63, 354, 275, 283, 4181, 358, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 20952, 63, 493, 275, 1709, 14, 23252, 342, 272, 333, 9897, 63, 493, 275, 1709, 14, 23252, 8, 2307, 29, 549, 12, 4596, 29, 549, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 291, 14, 354, 199, 199, 533, 15247, 8, 992, 14, 1685, 304, 272, 20178, 275, 1709, 14, 3190, 8, 51, 951, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 1343, 275, 1709, 14, 3901, 342, 272, 1284, 275, 1709, 14, 3901, 342, 272, 21559, 11818, 275, 1709, 14, 6254, 8, 2500, 275, 715, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 291, 14, 354, 199, 199, 533, 32117, 8, 992, 14, 1685, 304, 272, 20178, 275, 1709, 14, 3190, 8, 51, 951, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 922, 275, 1709, 14, 3190, 8, 1751, 14, 5580, 63, 3791, 63, 11429, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 849, 63, 2064, 275, 1709, 14, 3190, 8, 8416, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 19203, 450, 83, 2, 450, 334, 277, 14, 751, 14, 2473, 12, 291, 14, 19351, 14, 354, 9, 199, 199, 533, 8802, 723, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 1369, 275, 1709, 14, 6254, 8, 2500, 275, 715, 9, 272, 7556, 275, 1709, 14, 7624, 8, 1751, 14, 5580, 63, 3791, 63, 11429, 12, 4048, 63, 354, 275, 283, 2239, 32030, 358, 272, 308, 12358, 275, 1709, 14, 7624, 8, 51, 951, 9, 272, 1343, 63, 602, 275, 1709, 14, 14071, 8, 2495, 63, 2131, 63, 525, 29, 797, 12, 849, 275, 2197, 14, 602, 8, 6965, 12, 413, 12, 413, 430, 272, 1284, 63, 602, 275, 1709, 14, 14071, 8, 2495, 63, 2131, 63, 525, 29, 797, 12, 849, 275, 2197, 14, 602, 8, 18, 1960, 12, 413, 12, 413, 430, 339, 768, 1829, 272, 347, 365, 63, 1753, 8, 277, 304, 267, 372, 2197, 14, 602, 14, 8136, 342, 690, 291, 14, 500, 63, 602, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 291, 14, 354, 199, 199, 533, 799, 5422, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 20952, 63, 493, 275, 1709, 14, 23252, 342, 272, 2737, 275, 1709, 14, 4626, 8, 2495, 63, 2131, 63, 525, 29, 549, 9, 272, 5709, 63, 1045, 275, 1709, 14, 7624, 8, 6209, 723, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 334, 288, 291, 14, 3966, 267, 776, 199, 199, 32, 10244, 8, 1932, 63, 1807, 12, 8904, 29, 26040, 9, 199, 318, 20952, 63, 1807, 8, 8114, 12, 1256, 12, 1011, 958, 304, 272, 327, 8325, 3055, 880, 3814, 792, 3181, 1133, 3354, 314, 1402, 14, 272, 1256, 14, 24616, 63, 493, 14, 1807, 8, 797, 9, 199, 199, 533, 14320, 25635, 8, 992, 14, 1685, 304, 272, 10238, 275, 1709, 14, 3190, 8, 25635, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 1777, 275, 1709, 14, 3190, 8, 8416, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 339, 20952, 17, 275, 1709, 14, 14298, 8, 26040, 12, 641, 63, 1807, 29, 992, 14, 3597, 63, 8084, 12, 2973, 29, 549, 12, 4048, 63, 354, 534, 24616, 17, 63, 1618, 358, 272, 20952, 18, 275, 1709, 14, 14298, 8, 26040, 12, 641, 63, 1807, 29, 992, 14, 3597, 63, 8084, 12, 2973, 29, 549, 12, 4048, 63, 354, 534, 24616, 18, 63, 1618, 358, 272, 20952, 19, 275, 1709, 14, 14298, 8, 26040, 12, 641, 63, 1807, 29, 992, 14, 3597, 63, 8084, 12, 2973, 29, 549, 12, 4048, 63, 354, 534, 24616, 19, 63, 1618, 358, 339, 347, 636, 2975, 721 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 697, 14, 992, 14, 10458, 492, 2963, 63, 1807, 199, 504, 1639, 14, 6052, 14, 14913, 492, 13035, 199, 646, 2197, 199, 199, 533, 29405, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 12681, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 8269, 9, 272, 20952, 63, 493, 275, 1709, 14, 23252, 342, 272, 2388, 79, 275, 1709, 14, 13019, 342, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 291, 14, 354, 199, 199, 533, 4703, 10014, 8, 992, 14, 1685, 304, 272, 20178, 275, 1709, 14, 3190, 8, 51, 951, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 1343, 63, 12522, 63, 262, 63, 19351, 275, 1709, 14, 3901, 342, 272, 1343, 63, 12522, 63, 262, 63, 1700, 275, 1709, 14, 3901, 342, 272, 506, 1956, 63, 529, 63, 1700, 275, 1709, 14, 3901, 342, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 2, 1271, 506, 292, 450, 73, 1343, 450, 73, 506, 1956, 1126, 4681, 2, 450, 334, 277, 14, 928, 63, 12522, 63, 262, 63, 19351, 12, 291, 14, 1235, 1956, 63, 529, 63, 1700, 9, 199, 199, 533, 428, 7886, 8, 992, 14, 1685, 304, 272, 922, 275, 1709, 14, 14298, 8, 1751, 14, 5580, 63, 3791, 63, 11429, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 23967, 275, 1709, 14, 13019, 342, 272, 2498, 63, 3437, 275, 1709, 14, 5036, 342, 272, 26743, 384, 63, 354, 275, 1709, 14, 6254, 8, 2500, 275, 715, 9, 272, 10991, 63, 1188, 275, 1709, 14, 6254, 8, 2500, 275, 715, 9, 199, 199, 533, 14320, 8, 992, 14, 1685, 304, 272, 20178, 275, 1709, 14, 3190, 8, 51, 951, 12, 641, 63, 1807, 29, 992, 14, 10855, 12, 4048, 63, 354, 275, 283, 4181, 358, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 20952, 63, 493, 275, 1709, 14, 23252, 342, 272, 333, 9897, 63, 493, 275, 1709, 14, 23252, 8, 2307, 29, 549, 12, 4596, 29, 549, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 291, 14, 354, 199, 199, 533, 15247, 8, 992, 14, 1685, 304, 272, 20178, 275, 1709, 14, 3190, 8, 51, 951, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 1343, 275, 1709, 14, 3901, 342, 272, 1284, 275, 1709, 14, 3901, 342, 272, 21559, 11818, 275, 1709, 14, 6254, 8, 2500, 275, 715, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 291, 14, 354, 199, 199, 533, 32117, 8, 992, 14, 1685, 304, 272, 20178, 275, 1709, 14, 3190, 8, 51, 951, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 922, 275, 1709, 14, 3190, 8, 1751, 14, 5580, 63, 3791, 63, 11429, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 849, 63, 2064, 275, 1709, 14, 3190, 8, 8416, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 19203, 450, 83, 2, 450, 334, 277, 14, 751, 14, 2473, 12, 291, 14, 19351, 14, 354, 9, 199, 199, 533, 8802, 723, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 1369, 275, 1709, 14, 6254, 8, 2500, 275, 715, 9, 272, 7556, 275, 1709, 14, 7624, 8, 1751, 14, 5580, 63, 3791, 63, 11429, 12, 4048, 63, 354, 275, 283, 2239, 32030, 358, 272, 308, 12358, 275, 1709, 14, 7624, 8, 51, 951, 9, 272, 1343, 63, 602, 275, 1709, 14, 14071, 8, 2495, 63, 2131, 63, 525, 29, 797, 12, 849, 275, 2197, 14, 602, 8, 6965, 12, 413, 12, 413, 430, 272, 1284, 63, 602, 275, 1709, 14, 14071, 8, 2495, 63, 2131, 63, 525, 29, 797, 12, 849, 275, 2197, 14, 602, 8, 18, 1960, 12, 413, 12, 413, 430, 339, 768, 1829, 272, 347, 365, 63, 1753, 8, 277, 304, 267, 372, 2197, 14, 602, 14, 8136, 342, 690, 291, 14, 500, 63, 602, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 291, 14, 354, 199, 199, 533, 799, 5422, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 20952, 63, 493, 275, 1709, 14, 23252, 342, 272, 2737, 275, 1709, 14, 4626, 8, 2495, 63, 2131, 63, 525, 29, 549, 9, 272, 5709, 63, 1045, 275, 1709, 14, 7624, 8, 6209, 723, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 399, 6808, 83, 2, 450, 334, 288, 291, 14, 3966, 267, 776, 199, 199, 32, 10244, 8, 1932, 63, 1807, 12, 8904, 29, 26040, 9, 199, 318, 20952, 63, 1807, 8, 8114, 12, 1256, 12, 1011, 958, 304, 272, 327, 8325, 3055, 880, 3814, 792, 3181, 1133, 3354, 314, 1402, 14, 272, 1256, 14, 24616, 63, 493, 14, 1807, 8, 797, 9, 199, 199, 533, 14320, 25635, 8, 992, 14, 1685, 304, 272, 10238, 275, 1709, 14, 3190, 8, 25635, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 272, 1777, 275, 1709, 14, 3190, 8, 8416, 12, 641, 63, 1807, 29, 992, 14, 10855, 9, 339, 20952, 17, 275, 1709, 14, 14298, 8, 26040, 12, 641, 63, 1807, 29, 992, 14, 3597, 63, 8084, 12, 2973, 29, 549, 12, 4048, 63, 354, 534, 24616, 17, 63, 1618, 358, 272, 20952, 18, 275, 1709, 14, 14298, 8, 26040, 12, 641, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ShortsTravel/stm-microservices
node_modules/node-gyp/gyp/pylib/gyp/input.py
578
116086
# 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. from compiler.ast import Const from compiler.ast import Dict from compiler.ast import Discard from compiler.ast import List from compiler.ast import Module from compiler.ast import Node from compiler.ast import Stmt import compiler import gyp.common import gyp.simple_copy import multiprocessing import optparse import os.path import re import shlex import signal import subprocess import sys import threading import time import traceback from gyp.common import GypError from gyp.common import OrderedSet # A list of types that are treated as linkable. linkable_types = [ 'executable', 'shared_library', 'loadable_module', 'mac_kernel_extension', ] # A list of sections that contain links to other targets. dependency_sections = ['dependencies', 'export_dependent_settings'] # base_path_sections is a list of sections defined by GYP that contain # pathnames. The generators can provide more keys, the two lists are merged # into path_sections, but you should call IsPathSection instead of using either # list directly. base_path_sections = [ 'destination', 'files', 'include_dirs', 'inputs', 'libraries', 'outputs', 'sources', ] path_sections = set() # These per-process dictionaries are used to cache build file data when loading # in parallel mode. per_process_data = {} per_process_aux_data = {} def IsPathSection(section): # If section ends in one of the '=+?!' characters, it's applied to a section # without the trailing characters. '/' is notably absent from this list, # because there's no way for a regular expression to be treated as a path. while section and section[-1:] in '=+?!': section = section[:-1] if section in path_sections: return True # Sections mathing the regexp '_(dir|file|path)s?$' are also # considered PathSections. Using manual string matching since that # is much faster than the regexp and this can be called hundreds of # thousands of times so micro performance matters. if "_" in section: tail = section[-6:] if tail[-1] == 's': tail = tail[:-1] if tail[-5:] in ('_file', '_path'): return True return tail[-4:] == '_dir' return False # base_non_configuration_keys is a list of key names that belong in the target # itself and should not be propagated into its configurations. It is merged # with a list that can come from the generator to # create non_configuration_keys. base_non_configuration_keys = [ # Sections that must exist inside targets and not configurations. 'actions', 'configurations', 'copies', 'default_configuration', 'dependencies', 'dependencies_original', 'libraries', 'postbuilds', 'product_dir', 'product_extension', 'product_name', 'product_prefix', 'rules', 'run_as', 'sources', 'standalone_static_library', 'suppress_wildcard', 'target_name', 'toolset', 'toolsets', 'type', # Sections that can be found inside targets or configurations, but that # should not be propagated from targets into their configurations. 'variables', ] non_configuration_keys = [] # Keys that do not belong inside a configuration dictionary. invalid_configuration_keys = [ 'actions', 'all_dependent_settings', 'configurations', 'dependencies', 'direct_dependent_settings', 'libraries', 'link_settings', 'sources', 'standalone_static_library', 'target_name', 'type', ] # Controls whether or not the generator supports multiple toolsets. multiple_toolsets = False # Paths for converting filelist paths to output paths: { # toplevel, # qualified_output_dir, # } generator_filelist_paths = None def GetIncludedBuildFiles(build_file_path, aux_data, included=None): """Return a list of all build files included into build_file_path. The returned list will contain build_file_path as well as all other files that it included, either directly or indirectly. Note that the list may contain files that were included into a conditional section that evaluated to false and was not merged into build_file_path's dict. aux_data is a dict containing a key for each build file or included build file. Those keys provide access to dicts whose "included" keys contain lists of all other files included by the build file. included should be left at its default None value by external callers. It is used for recursion. The returned list will not contain any duplicate entries. Each build file in the list will be relative to the current directory. """ if included == None: included = [] if build_file_path in included: return included included.append(build_file_path) for included_build_file in aux_data[build_file_path].get('included', []): GetIncludedBuildFiles(included_build_file, aux_data, included) return included def CheckedEval(file_contents): """Return the eval of a gyp file. The gyp file is restricted to dictionaries and lists only, and repeated keys are not allowed. Note that this is slower than eval() is. """ ast = compiler.parse(file_contents) assert isinstance(ast, Module) c1 = ast.getChildren() assert c1[0] is None assert isinstance(c1[1], Stmt) c2 = c1[1].getChildren() assert isinstance(c2[0], Discard) c3 = c2[0].getChildren() assert len(c3) == 1 return CheckNode(c3[0], []) def CheckNode(node, keypath): if isinstance(node, Dict): c = node.getChildren() dict = {} for n in range(0, len(c), 2): assert isinstance(c[n], Const) key = c[n].getChildren()[0] if key in dict: raise GypError("Key '" + key + "' repeated at level " + repr(len(keypath) + 1) + " with key path '" + '.'.join(keypath) + "'") kp = list(keypath) # Make a copy of the list for descending this node. kp.append(key) dict[key] = CheckNode(c[n + 1], kp) return dict elif isinstance(node, List): c = node.getChildren() children = [] for index, child in enumerate(c): kp = list(keypath) # Copy list. kp.append(repr(index)) children.append(CheckNode(child, kp)) return children elif isinstance(node, Const): return node.getChildren()[0] else: raise TypeError("Unknown AST node at key path '" + '.'.join(keypath) + "': " + repr(node)) def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check): if build_file_path in data: return data[build_file_path] if os.path.exists(build_file_path): # Open the build file for read ('r') with universal-newlines mode ('U') # to make sure platform specific newlines ('\r\n' or '\r') are converted to '\n' # which otherwise will fail eval() build_file_contents = open(build_file_path, 'rU').read() else: raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd())) build_file_data = None try: if check: build_file_data = CheckedEval(build_file_contents) else: build_file_data = eval(build_file_contents, {'__builtins__': None}, None) except SyntaxError, e: e.filename = build_file_path raise except Exception, e: gyp.common.ExceptionAppend(e, 'while reading ' + build_file_path) raise if type(build_file_data) is not dict: raise GypError("%s does not evaluate to a dictionary." % build_file_path) data[build_file_path] = build_file_data aux_data[build_file_path] = {} # Scan for includes and merge them in. if ('skip_includes' not in build_file_data or not build_file_data['skip_includes']): try: if is_target: LoadBuildFileIncludesIntoDict(build_file_data, build_file_path, data, aux_data, includes, check) else: LoadBuildFileIncludesIntoDict(build_file_data, build_file_path, data, aux_data, None, check) except Exception, e: gyp.common.ExceptionAppend(e, 'while reading includes of ' + build_file_path) raise return build_file_data def LoadBuildFileIncludesIntoDict(subdict, subdict_path, data, aux_data, includes, check): includes_list = [] if includes != None: includes_list.extend(includes) if 'includes' in subdict: for include in subdict['includes']: # "include" is specified relative to subdict_path, so compute the real # path to include by appending the provided "include" to the directory # in which subdict_path resides. relative_include = \ os.path.normpath(os.path.join(os.path.dirname(subdict_path), include)) includes_list.append(relative_include) # Unhook the includes list, it's no longer needed. del subdict['includes'] # Merge in the included files. for include in includes_list: if not 'included' in aux_data[subdict_path]: aux_data[subdict_path]['included'] = [] aux_data[subdict_path]['included'].append(include) gyp.DebugOutput(gyp.DEBUG_INCLUDES, "Loading Included File: '%s'", include) MergeDicts(subdict, LoadOneBuildFile(include, data, aux_data, None, False, check), subdict_path, include) # Recurse into subdictionaries. for k, v in subdict.iteritems(): if type(v) is dict: LoadBuildFileIncludesIntoDict(v, subdict_path, data, aux_data, None, check) elif type(v) is list: LoadBuildFileIncludesIntoList(v, subdict_path, data, aux_data, check) # This recurses into lists so that it can look for dicts. def LoadBuildFileIncludesIntoList(sublist, sublist_path, data, aux_data, check): for item in sublist: if type(item) is dict: LoadBuildFileIncludesIntoDict(item, sublist_path, data, aux_data, None, check) elif type(item) is list: LoadBuildFileIncludesIntoList(item, sublist_path, data, aux_data, check) # Processes toolsets in all the targets. This recurses into condition entries # since they can contain toolsets as well. def ProcessToolsetsInDict(data): if 'targets' in data: target_list = data['targets'] new_target_list = [] for target in target_list: # If this target already has an explicit 'toolset', and no 'toolsets' # list, don't modify it further. if 'toolset' in target and 'toolsets' not in target: new_target_list.append(target) continue if multiple_toolsets: toolsets = target.get('toolsets', ['target']) else: toolsets = ['target'] # Make sure this 'toolsets' definition is only processed once. if 'toolsets' in target: del target['toolsets'] if len(toolsets) > 0: # Optimization: only do copies if more than one toolset is specified. for build in toolsets[1:]: new_target = gyp.simple_copy.deepcopy(target) new_target['toolset'] = build new_target_list.append(new_target) target['toolset'] = toolsets[0] new_target_list.append(target) data['targets'] = new_target_list if 'conditions' in data: for condition in data['conditions']: if type(condition) is list: for condition_dict in condition[1:]: if type(condition_dict) is dict: ProcessToolsetsInDict(condition_dict) # TODO(mark): I don't love this name. It just means that it's going to load # a build file that contains targets and is expected to provide a targets dict # that contains the targets... def LoadTargetBuildFile(build_file_path, data, aux_data, variables, includes, depth, check, load_dependencies): # If depth is set, predefine the DEPTH variable to be a relative path from # this build file's directory to the directory identified by depth. if depth: # TODO(dglazkov) The backslash/forward-slash replacement at the end is a # temporary measure. This should really be addressed by keeping all paths # in POSIX until actual project generation. d = gyp.common.RelativePath(depth, os.path.dirname(build_file_path)) if d == '': variables['DEPTH'] = '.' else: variables['DEPTH'] = d.replace('\\', '/') # The 'target_build_files' key is only set when loading target build files in # the non-parallel code path, where LoadTargetBuildFile is called # recursively. In the parallel code path, we don't need to check whether the # |build_file_path| has already been loaded, because the 'scheduled' set in # ParallelState guarantees that we never load the same |build_file_path| # twice. if 'target_build_files' in data: if build_file_path in data['target_build_files']: # Already loaded. return False data['target_build_files'].add(build_file_path) gyp.DebugOutput(gyp.DEBUG_INCLUDES, "Loading Target Build File '%s'", build_file_path) build_file_data = LoadOneBuildFile(build_file_path, data, aux_data, includes, True, check) # Store DEPTH for later use in generators. build_file_data['_DEPTH'] = depth # Set up the included_files key indicating which .gyp files contributed to # this target dict. if 'included_files' in build_file_data: raise GypError(build_file_path + ' must not contain included_files key') included = GetIncludedBuildFiles(build_file_path, aux_data) build_file_data['included_files'] = [] for included_file in included: # included_file is relative to the current directory, but it needs to # be made relative to build_file_path's directory. included_relative = \ gyp.common.RelativePath(included_file, os.path.dirname(build_file_path)) build_file_data['included_files'].append(included_relative) # Do a first round of toolsets expansion so that conditions can be defined # per toolset. ProcessToolsetsInDict(build_file_data) # Apply "pre"/"early" variable expansions and condition evaluations. ProcessVariablesAndConditionsInDict( build_file_data, PHASE_EARLY, variables, build_file_path) # Since some toolsets might have been defined conditionally, perform # a second round of toolsets expansion now. ProcessToolsetsInDict(build_file_data) # Look at each project's target_defaults dict, and merge settings into # targets. if 'target_defaults' in build_file_data: if 'targets' not in build_file_data: raise GypError("Unable to find targets in build file %s" % build_file_path) index = 0 while index < len(build_file_data['targets']): # This procedure needs to give the impression that target_defaults is # used as defaults, and the individual targets inherit from that. # The individual targets need to be merged into the defaults. Make # a deep copy of the defaults for each target, merge the target dict # as found in the input file into that copy, and then hook up the # copy with the target-specific data merged into it as the replacement # target dict. old_target_dict = build_file_data['targets'][index] new_target_dict = gyp.simple_copy.deepcopy( build_file_data['target_defaults']) MergeDicts(new_target_dict, old_target_dict, build_file_path, build_file_path) build_file_data['targets'][index] = new_target_dict index += 1 # No longer needed. del build_file_data['target_defaults'] # Look for dependencies. This means that dependency resolution occurs # after "pre" conditionals and variable expansion, but before "post" - # in other words, you can't put a "dependencies" section inside a "post" # conditional within a target. dependencies = [] if 'targets' in build_file_data: for target_dict in build_file_data['targets']: if 'dependencies' not in target_dict: continue for dependency in target_dict['dependencies']: dependencies.append( gyp.common.ResolveTarget(build_file_path, dependency, None)[0]) if load_dependencies: for dependency in dependencies: try: LoadTargetBuildFile(dependency, data, aux_data, variables, includes, depth, check, load_dependencies) except Exception, e: gyp.common.ExceptionAppend( e, 'while loading dependencies of %s' % build_file_path) raise else: return (build_file_path, dependencies) def CallLoadTargetBuildFile(global_flags, build_file_path, variables, includes, depth, check, generator_input_info): """Wrapper around LoadTargetBuildFile for parallel processing. This wrapper is used when LoadTargetBuildFile is executed in a worker process. """ try: signal.signal(signal.SIGINT, signal.SIG_IGN) # Apply globals so that the worker process behaves the same. for key, value in global_flags.iteritems(): globals()[key] = value SetGeneratorGlobals(generator_input_info) result = LoadTargetBuildFile(build_file_path, per_process_data, per_process_aux_data, variables, includes, depth, check, False) if not result: return result (build_file_path, dependencies) = result # We can safely pop the build_file_data from per_process_data because it # will never be referenced by this process again, so we don't need to keep # it in the cache. build_file_data = per_process_data.pop(build_file_path) # This gets serialized and sent back to the main process via a pipe. # It's handled in LoadTargetBuildFileCallback. return (build_file_path, build_file_data, dependencies) except GypError, e: sys.stderr.write("gyp: %s\n" % e) return None except Exception, e: print >>sys.stderr, 'Exception:', e print >>sys.stderr, traceback.format_exc() return None class ParallelProcessingError(Exception): pass class ParallelState(object): """Class to keep track of state when processing input files in parallel. If build files are loaded in parallel, use this to keep track of state during farming out and processing parallel jobs. It's stored in a global so that the callback function can have access to it. """ def __init__(self): # The multiprocessing pool. self.pool = None # The condition variable used to protect this object and notify # the main loop when there might be more data to process. self.condition = None # The "data" dict that was passed to LoadTargetBuildFileParallel self.data = None # The number of parallel calls outstanding; decremented when a response # was received. self.pending = 0 # The set of all build files that have been scheduled, so we don't # schedule the same one twice. self.scheduled = set() # A list of dependency build file paths that haven't been scheduled yet. self.dependencies = [] # Flag to indicate if there was an error in a child process. self.error = False def LoadTargetBuildFileCallback(self, result): """Handle the results of running LoadTargetBuildFile in another process. """ self.condition.acquire() if not result: self.error = True self.condition.notify() self.condition.release() return (build_file_path0, build_file_data0, dependencies0) = result self.data[build_file_path0] = build_file_data0 self.data['target_build_files'].add(build_file_path0) for new_dependency in dependencies0: if new_dependency not in self.scheduled: self.scheduled.add(new_dependency) self.dependencies.append(new_dependency) self.pending -= 1 self.condition.notify() self.condition.release() def LoadTargetBuildFilesParallel(build_files, data, variables, includes, depth, check, generator_input_info): parallel_state = ParallelState() parallel_state.condition = threading.Condition() # Make copies of the build_files argument that we can modify while working. parallel_state.dependencies = list(build_files) parallel_state.scheduled = set(build_files) parallel_state.pending = 0 parallel_state.data = data try: parallel_state.condition.acquire() while parallel_state.dependencies or parallel_state.pending: if parallel_state.error: break if not parallel_state.dependencies: parallel_state.condition.wait() continue dependency = parallel_state.dependencies.pop() parallel_state.pending += 1 global_flags = { 'path_sections': globals()['path_sections'], 'non_configuration_keys': globals()['non_configuration_keys'], 'multiple_toolsets': globals()['multiple_toolsets']} if not parallel_state.pool: parallel_state.pool = multiprocessing.Pool(multiprocessing.cpu_count()) parallel_state.pool.apply_async( CallLoadTargetBuildFile, args = (global_flags, dependency, variables, includes, depth, check, generator_input_info), callback = parallel_state.LoadTargetBuildFileCallback) except KeyboardInterrupt, e: parallel_state.pool.terminate() raise e parallel_state.condition.release() parallel_state.pool.close() parallel_state.pool.join() parallel_state.pool = None if parallel_state.error: sys.exit(1) # Look for the bracket that matches the first bracket seen in a # string, and return the start and end as a tuple. For example, if # the input is something like "<(foo <(bar)) blah", then it would # return (1, 13), indicating the entire string except for the leading # "<" and trailing " blah". LBRACKETS= set('{[(') BRACKETS = {'}': '{', ']': '[', ')': '('} def FindEnclosingBracketGroup(input_str): stack = [] start = -1 for index, char in enumerate(input_str): if char in LBRACKETS: stack.append(char) if start == -1: start = index elif char in BRACKETS: if not stack: return (-1, -1) if stack.pop() != BRACKETS[char]: return (-1, -1) if not stack: return (start, index + 1) return (-1, -1) def IsStrCanonicalInt(string): """Returns True if |string| is in its canonical integer form. The canonical form is such that str(int(string)) == string. """ if type(string) is str: # This function is called a lot so for maximum performance, avoid # involving regexps which would otherwise make the code much # shorter. Regexps would need twice the time of this function. if string: if string == "0": return True if string[0] == "-": string = string[1:] if not string: return False if '1' <= string[0] <= '9': return string.isdigit() return False # This matches things like "<(asdf)", "<!(cmd)", "<!@(cmd)", "<|(list)", # "<!interpreter(arguments)", "<([list])", and even "<([)" and "<(<())". # In the last case, the inner "<()" is captured in match['content']. early_variable_re = re.compile( r'(?P<replace>(?P<type><(?:(?:!?@?)|\|)?)' r'(?P<command_string>[-a-zA-Z0-9_.]+)?' r'\((?P<is_array>\s*\[?)' r'(?P<content>.*?)(\]?)\))') # This matches the same as early_variable_re, but with '>' instead of '<'. late_variable_re = re.compile( r'(?P<replace>(?P<type>>(?:(?:!?@?)|\|)?)' r'(?P<command_string>[-a-zA-Z0-9_.]+)?' r'\((?P<is_array>\s*\[?)' r'(?P<content>.*?)(\]?)\))') # This matches the same as early_variable_re, but with '^' instead of '<'. latelate_variable_re = re.compile( r'(?P<replace>(?P<type>[\^](?:(?:!?@?)|\|)?)' r'(?P<command_string>[-a-zA-Z0-9_.]+)?' r'\((?P<is_array>\s*\[?)' r'(?P<content>.*?)(\]?)\))') # Global cache of results from running commands so they don't have to be run # more then once. cached_command_results = {} def FixupPlatformCommand(cmd): if sys.platform == 'win32': if type(cmd) is list: cmd = [re.sub('^cat ', 'type ', cmd[0])] + cmd[1:] else: cmd = re.sub('^cat ', 'type ', cmd) return cmd PHASE_EARLY = 0 PHASE_LATE = 1 PHASE_LATELATE = 2 def ExpandVariables(input, phase, variables, build_file): # Look for the pattern that gets expanded into variables if phase == PHASE_EARLY: variable_re = early_variable_re expansion_symbol = '<' elif phase == PHASE_LATE: variable_re = late_variable_re expansion_symbol = '>' elif phase == PHASE_LATELATE: variable_re = latelate_variable_re expansion_symbol = '^' else: assert False input_str = str(input) if IsStrCanonicalInt(input_str): return int(input_str) # Do a quick scan to determine if an expensive regex search is warranted. if expansion_symbol not in input_str: return input_str # Get the entire list of matches as a list of MatchObject instances. # (using findall here would return strings instead of MatchObjects). matches = list(variable_re.finditer(input_str)) if not matches: return input_str output = input_str # Reverse the list of matches so that replacements are done right-to-left. # That ensures that earlier replacements won't mess up the string in a # way that causes later calls to find the earlier substituted text instead # of what's intended for replacement. matches.reverse() for match_group in matches: match = match_group.groupdict() gyp.DebugOutput(gyp.DEBUG_VARIABLES, "Matches: %r", match) # match['replace'] is the substring to look for, match['type'] # is the character code for the replacement type (< > <! >! <| >| <@ # >@ <!@ >!@), match['is_array'] contains a '[' for command # arrays, and match['content'] is the name of the variable (< >) # or command to run (<! >!). match['command_string'] is an optional # command string. Currently, only 'pymod_do_main' is supported. # run_command is true if a ! variant is used. run_command = '!' in match['type'] command_string = match['command_string'] # file_list is true if a | variant is used. file_list = '|' in match['type'] # Capture these now so we can adjust them later. replace_start = match_group.start('replace') replace_end = match_group.end('replace') # Find the ending paren, and re-evaluate the contained string. (c_start, c_end) = FindEnclosingBracketGroup(input_str[replace_start:]) # Adjust the replacement range to match the entire command # found by FindEnclosingBracketGroup (since the variable_re # probably doesn't match the entire command if it contained # nested variables). replace_end = replace_start + c_end # Find the "real" replacement, matching the appropriate closing # paren, and adjust the replacement start and end. replacement = input_str[replace_start:replace_end] # Figure out what the contents of the variable parens are. contents_start = replace_start + c_start + 1 contents_end = replace_end - 1 contents = input_str[contents_start:contents_end] # Do filter substitution now for <|(). # Admittedly, this is different than the evaluation order in other # contexts. However, since filtration has no chance to run on <|(), # this seems like the only obvious way to give them access to filters. if file_list: processed_variables = gyp.simple_copy.deepcopy(variables) ProcessListFiltersInDict(contents, processed_variables) # Recurse to expand variables in the contents contents = ExpandVariables(contents, phase, processed_variables, build_file) else: # Recurse to expand variables in the contents contents = ExpandVariables(contents, phase, variables, build_file) # Strip off leading/trailing whitespace so that variable matches are # simpler below (and because they are rarely needed). contents = contents.strip() # expand_to_list is true if an @ variant is used. In that case, # the expansion should result in a list. Note that the caller # is to be expecting a list in return, and not all callers do # because not all are working in list context. Also, for list # expansions, there can be no other text besides the variable # expansion in the input string. expand_to_list = '@' in match['type'] and input_str == replacement if run_command or file_list: # Find the build file's directory, so commands can be run or file lists # generated relative to it. build_file_dir = os.path.dirname(build_file) if build_file_dir == '' and not file_list: # If build_file is just a leaf filename indicating a file in the # current directory, build_file_dir might be an empty string. Set # it to None to signal to subprocess.Popen that it should run the # command in the current directory. build_file_dir = None # Support <|(listfile.txt ...) which generates a file # containing items from a gyp list, generated at gyp time. # This works around actions/rules which have more inputs than will # fit on the command line. if file_list: if type(contents) is list: contents_list = contents else: contents_list = contents.split(' ') replacement = contents_list[0] if os.path.isabs(replacement): raise GypError('| cannot handle absolute paths, got "%s"' % replacement) if not generator_filelist_paths: path = os.path.join(build_file_dir, replacement) else: if os.path.isabs(build_file_dir): toplevel = generator_filelist_paths['toplevel'] rel_build_file_dir = gyp.common.RelativePath(build_file_dir, toplevel) else: rel_build_file_dir = build_file_dir qualified_out_dir = generator_filelist_paths['qualified_out_dir'] path = os.path.join(qualified_out_dir, rel_build_file_dir, replacement) gyp.common.EnsureDirExists(path) replacement = gyp.common.RelativePath(path, build_file_dir) f = gyp.common.WriteOnDiff(path) for i in contents_list[1:]: f.write('%s\n' % i) f.close() elif run_command: use_shell = True if match['is_array']: contents = eval(contents) use_shell = False # Check for a cached value to avoid executing commands, or generating # file lists more than once. The cache key contains the command to be # run as well as the directory to run it from, to account for commands # that depend on their current directory. # TODO(http://code.google.com/p/gyp/issues/detail?id=111): In theory, # someone could author a set of GYP files where each time the command # is invoked it produces different output by design. When the need # arises, the syntax should be extended to support no caching off a # command's output so it is run every time. cache_key = (str(contents), build_file_dir) cached_value = cached_command_results.get(cache_key, None) if cached_value is None: gyp.DebugOutput(gyp.DEBUG_VARIABLES, "Executing command '%s' in directory '%s'", contents, build_file_dir) replacement = '' if command_string == 'pymod_do_main': # <!pymod_do_main(modulename param eters) loads |modulename| as a # python module and then calls that module's DoMain() function, # passing ["param", "eters"] as a single list argument. For modules # that don't load quickly, this can be faster than # <!(python modulename param eters). Do this in |build_file_dir|. oldwd = os.getcwd() # Python doesn't like os.open('.'): no fchdir. if build_file_dir: # build_file_dir may be None (see above). os.chdir(build_file_dir) try: parsed_contents = shlex.split(contents) try: py_module = __import__(parsed_contents[0]) except ImportError as e: raise GypError("Error importing pymod_do_main" "module (%s): %s" % (parsed_contents[0], e)) replacement = str(py_module.DoMain(parsed_contents[1:])).rstrip() finally: os.chdir(oldwd) assert replacement != None elif command_string: raise GypError("Unknown command string '%s' in '%s'." % (command_string, contents)) else: # Fix up command with platform specific workarounds. contents = FixupPlatformCommand(contents) try: p = subprocess.Popen(contents, shell=use_shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, cwd=build_file_dir) except Exception, e: raise GypError("%s while executing command '%s' in %s" % (e, contents, build_file)) p_stdout, p_stderr = p.communicate('') if p.wait() != 0 or p_stderr: sys.stderr.write(p_stderr) # Simulate check_call behavior, since check_call only exists # in python 2.5 and later. raise GypError("Call to '%s' returned exit status %d while in %s." % (contents, p.returncode, build_file)) replacement = p_stdout.rstrip() cached_command_results[cache_key] = replacement else: gyp.DebugOutput(gyp.DEBUG_VARIABLES, "Had cache value for command '%s' in directory '%s'", contents,build_file_dir) replacement = cached_value else: if not contents in variables: if contents[-1] in ['!', '/']: # In order to allow cross-compiles (nacl) to happen more naturally, # we will allow references to >(sources/) etc. to resolve to # and empty list if undefined. This allows actions to: # 'action!': [ # '>@(_sources!)', # ], # 'action/': [ # '>@(_sources/)', # ], replacement = [] else: raise GypError('Undefined variable ' + contents + ' in ' + build_file) else: replacement = variables[contents] if type(replacement) is list: for item in replacement: if not contents[-1] == '/' and type(item) not in (str, int): raise GypError('Variable ' + contents + ' must expand to a string or list of strings; ' + 'list contains a ' + item.__class__.__name__) # Run through the list and handle variable expansions in it. Since # the list is guaranteed not to contain dicts, this won't do anything # with conditions sections. ProcessVariablesAndConditionsInList(replacement, phase, variables, build_file) elif type(replacement) not in (str, int): raise GypError('Variable ' + contents + ' must expand to a string or list of strings; ' + 'found a ' + replacement.__class__.__name__) if expand_to_list: # Expanding in list context. It's guaranteed that there's only one # replacement to do in |input_str| and that it's this replacement. See # above. if type(replacement) is list: # If it's already a list, make a copy. output = replacement[:] else: # Split it the same way sh would split arguments. output = shlex.split(str(replacement)) else: # Expanding in string context. encoded_replacement = '' if type(replacement) is list: # When expanding a list into string context, turn the list items # into a string in a way that will work with a subprocess call. # # TODO(mark): This isn't completely correct. This should # call a generator-provided function that observes the # proper list-to-argument quoting rules on a specific # platform instead of just calling the POSIX encoding # routine. encoded_replacement = gyp.common.EncodePOSIXShellList(replacement) else: encoded_replacement = replacement output = output[:replace_start] + str(encoded_replacement) + \ output[replace_end:] # Prepare for the next match iteration. input_str = output if output == input: gyp.DebugOutput(gyp.DEBUG_VARIABLES, "Found only identity matches on %r, avoiding infinite " "recursion.", output) else: # Look for more matches now that we've replaced some, to deal with # expanding local variables (variables defined in the same # variables block as this one). gyp.DebugOutput(gyp.DEBUG_VARIABLES, "Found output %r, recursing.", output) if type(output) is list: if output and type(output[0]) is list: # Leave output alone if it's a list of lists. # We don't want such lists to be stringified. pass else: new_output = [] for item in output: new_output.append( ExpandVariables(item, phase, variables, build_file)) output = new_output else: output = ExpandVariables(output, phase, variables, build_file) # Convert all strings that are canonically-represented integers into integers. if type(output) is list: for index in xrange(0, len(output)): if IsStrCanonicalInt(output[index]): output[index] = int(output[index]) elif IsStrCanonicalInt(output): output = int(output) return output # The same condition is often evaluated over and over again so it # makes sense to cache as much as possible between evaluations. cached_conditions_asts = {} def EvalCondition(condition, conditions_key, phase, variables, build_file): """Returns the dict that should be used or None if the result was that nothing should be used.""" if type(condition) is not list: raise GypError(conditions_key + ' must be a list') if len(condition) < 2: # It's possible that condition[0] won't work in which case this # attempt will raise its own IndexError. That's probably fine. raise GypError(conditions_key + ' ' + condition[0] + ' must be at least length 2, not ' + str(len(condition))) i = 0 result = None while i < len(condition): cond_expr = condition[i] true_dict = condition[i + 1] if type(true_dict) is not dict: raise GypError('{} {} must be followed by a dictionary, not {}'.format( conditions_key, cond_expr, type(true_dict))) if len(condition) > i + 2 and type(condition[i + 2]) is dict: false_dict = condition[i + 2] i = i + 3 if i != len(condition): raise GypError('{} {} has {} unexpected trailing items'.format( conditions_key, cond_expr, len(condition) - i)) else: false_dict = None i = i + 2 if result == None: result = EvalSingleCondition( cond_expr, true_dict, false_dict, phase, variables, build_file) return result def EvalSingleCondition( cond_expr, true_dict, false_dict, phase, variables, build_file): """Returns true_dict if cond_expr evaluates to true, and false_dict otherwise.""" # Do expansions on the condition itself. Since the conditon can naturally # contain variable references without needing to resort to GYP expansion # syntax, this is of dubious value for variables, but someone might want to # use a command expansion directly inside a condition. cond_expr_expanded = ExpandVariables(cond_expr, phase, variables, build_file) if type(cond_expr_expanded) not in (str, int): raise ValueError( 'Variable expansion in this context permits str and int ' + \ 'only, found ' + cond_expr_expanded.__class__.__name__) try: if cond_expr_expanded in cached_conditions_asts: ast_code = cached_conditions_asts[cond_expr_expanded] else: ast_code = compile(cond_expr_expanded, '<string>', 'eval') cached_conditions_asts[cond_expr_expanded] = ast_code if eval(ast_code, {'__builtins__': None}, variables): return true_dict return false_dict except SyntaxError, e: syntax_error = SyntaxError('%s while evaluating condition \'%s\' in %s ' 'at character %d.' % (str(e.args[0]), e.text, build_file, e.offset), e.filename, e.lineno, e.offset, e.text) raise syntax_error except NameError, e: gyp.common.ExceptionAppend(e, 'while evaluating condition \'%s\' in %s' % (cond_expr_expanded, build_file)) raise GypError(e) def ProcessConditionsInDict(the_dict, phase, variables, build_file): # Process a 'conditions' or 'target_conditions' section in the_dict, # depending on phase. # early -> conditions # late -> target_conditions # latelate -> no conditions # # Each item in a conditions list consists of cond_expr, a string expression # evaluated as the condition, and true_dict, a dict that will be merged into # the_dict if cond_expr evaluates to true. Optionally, a third item, # false_dict, may be present. false_dict is merged into the_dict if # cond_expr evaluates to false. # # Any dict merged into the_dict will be recursively processed for nested # conditionals and other expansions, also according to phase, immediately # prior to being merged. if phase == PHASE_EARLY: conditions_key = 'conditions' elif phase == PHASE_LATE: conditions_key = 'target_conditions' elif phase == PHASE_LATELATE: return else: assert False if not conditions_key in the_dict: return conditions_list = the_dict[conditions_key] # Unhook the conditions list, it's no longer needed. del the_dict[conditions_key] for condition in conditions_list: merge_dict = EvalCondition(condition, conditions_key, phase, variables, build_file) if merge_dict != None: # Expand variables and nested conditinals in the merge_dict before # merging it. ProcessVariablesAndConditionsInDict(merge_dict, phase, variables, build_file) MergeDicts(the_dict, merge_dict, build_file, build_file) def LoadAutomaticVariablesFromDict(variables, the_dict): # Any keys with plain string values in the_dict become automatic variables. # The variable name is the key name with a "_" character prepended. for key, value in the_dict.iteritems(): if type(value) in (str, int, list): variables['_' + key] = value def LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key): # Any keys in the_dict's "variables" dict, if it has one, becomes a # variable. The variable name is the key name in the "variables" dict. # Variables that end with the % character are set only if they are unset in # the variables dict. the_dict_key is the name of the key that accesses # the_dict in the_dict's parent dict. If the_dict's parent is not a dict # (it could be a list or it could be parentless because it is a root dict), # the_dict_key will be None. for key, value in the_dict.get('variables', {}).iteritems(): if type(value) not in (str, int, list): continue if key.endswith('%'): variable_name = key[:-1] if variable_name in variables: # If the variable is already set, don't set it. continue if the_dict_key is 'variables' and variable_name in the_dict: # If the variable is set without a % in the_dict, and the_dict is a # variables dict (making |variables| a varaibles sub-dict of a # variables dict), use the_dict's definition. value = the_dict[variable_name] else: variable_name = key variables[variable_name] = value def ProcessVariablesAndConditionsInDict(the_dict, phase, variables_in, build_file, the_dict_key=None): """Handle all variable and command expansion and conditional evaluation. This function is the public entry point for all variable expansions and conditional evaluations. The variables_in dictionary will not be modified by this function. """ # Make a copy of the variables_in dict that can be modified during the # loading of automatics and the loading of the variables dict. variables = variables_in.copy() LoadAutomaticVariablesFromDict(variables, the_dict) if 'variables' in the_dict: # Make sure all the local variables are added to the variables # list before we process them so that you can reference one # variable from another. They will be fully expanded by recursion # in ExpandVariables. for key, value in the_dict['variables'].iteritems(): variables[key] = value # Handle the associated variables dict first, so that any variable # references within can be resolved prior to using them as variables. # Pass a copy of the variables dict to avoid having it be tainted. # Otherwise, it would have extra automatics added for everything that # should just be an ordinary variable in this scope. ProcessVariablesAndConditionsInDict(the_dict['variables'], phase, variables, build_file, 'variables') LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key) for key, value in the_dict.iteritems(): # Skip "variables", which was already processed if present. if key != 'variables' and type(value) is str: expanded = ExpandVariables(value, phase, variables, build_file) if type(expanded) not in (str, int): raise ValueError( 'Variable expansion in this context permits str and int ' + \ 'only, found ' + expanded.__class__.__name__ + ' for ' + key) the_dict[key] = expanded # Variable expansion may have resulted in changes to automatics. Reload. # TODO(mark): Optimization: only reload if no changes were made. variables = variables_in.copy() LoadAutomaticVariablesFromDict(variables, the_dict) LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key) # Process conditions in this dict. This is done after variable expansion # so that conditions may take advantage of expanded variables. For example, # if the_dict contains: # {'type': '<(library_type)', # 'conditions': [['_type=="static_library"', { ... }]]}, # _type, as used in the condition, will only be set to the value of # library_type if variable expansion is performed before condition # processing. However, condition processing should occur prior to recursion # so that variables (both automatic and "variables" dict type) may be # adjusted by conditions sections, merged into the_dict, and have the # intended impact on contained dicts. # # This arrangement means that a "conditions" section containing a "variables" # section will only have those variables effective in subdicts, not in # the_dict. The workaround is to put a "conditions" section within a # "variables" section. For example: # {'conditions': [['os=="mac"', {'variables': {'define': 'IS_MAC'}}]], # 'defines': ['<(define)'], # 'my_subdict': {'defines': ['<(define)']}}, # will not result in "IS_MAC" being appended to the "defines" list in the # current scope but would result in it being appended to the "defines" list # within "my_subdict". By comparison: # {'variables': {'conditions': [['os=="mac"', {'define': 'IS_MAC'}]]}, # 'defines': ['<(define)'], # 'my_subdict': {'defines': ['<(define)']}}, # will append "IS_MAC" to both "defines" lists. # Evaluate conditions sections, allowing variable expansions within them # as well as nested conditionals. This will process a 'conditions' or # 'target_conditions' section, perform appropriate merging and recursive # conditional and variable processing, and then remove the conditions section # from the_dict if it is present. ProcessConditionsInDict(the_dict, phase, variables, build_file) # Conditional processing may have resulted in changes to automatics or the # variables dict. Reload. variables = variables_in.copy() LoadAutomaticVariablesFromDict(variables, the_dict) LoadVariablesFromVariablesDict(variables, the_dict, the_dict_key) # Recurse into child dicts, or process child lists which may result in # further recursion into descendant dicts. for key, value in the_dict.iteritems(): # Skip "variables" and string values, which were already processed if # present. if key == 'variables' or type(value) is str: continue if type(value) is dict: # Pass a copy of the variables dict so that subdicts can't influence # parents. ProcessVariablesAndConditionsInDict(value, phase, variables, build_file, key) elif type(value) is list: # The list itself can't influence the variables dict, and # ProcessVariablesAndConditionsInList will make copies of the variables # dict if it needs to pass it to something that can influence it. No # copy is necessary here. ProcessVariablesAndConditionsInList(value, phase, variables, build_file) elif type(value) is not int: raise TypeError('Unknown type ' + value.__class__.__name__ + \ ' for ' + key) def ProcessVariablesAndConditionsInList(the_list, phase, variables, build_file): # Iterate using an index so that new values can be assigned into the_list. index = 0 while index < len(the_list): item = the_list[index] if type(item) is dict: # Make a copy of the variables dict so that it won't influence anything # outside of its own scope. ProcessVariablesAndConditionsInDict(item, phase, variables, build_file) elif type(item) is list: ProcessVariablesAndConditionsInList(item, phase, variables, build_file) elif type(item) is str: expanded = ExpandVariables(item, phase, variables, build_file) if type(expanded) in (str, int): the_list[index] = expanded elif type(expanded) is list: the_list[index:index+1] = expanded index += len(expanded) # index now identifies the next item to examine. Continue right now # without falling into the index increment below. continue else: raise ValueError( 'Variable expansion in this context permits strings and ' + \ 'lists only, found ' + expanded.__class__.__name__ + ' at ' + \ index) elif type(item) is not int: raise TypeError('Unknown type ' + item.__class__.__name__ + \ ' at index ' + index) index = index + 1 def BuildTargetsDict(data): """Builds a dict mapping fully-qualified target names to their target dicts. |data| is a dict mapping loaded build files by pathname relative to the current directory. Values in |data| are build file contents. For each |data| value with a "targets" key, the value of the "targets" key is taken as a list containing target dicts. Each target's fully-qualified name is constructed from the pathname of the build file (|data| key) and its "target_name" property. These fully-qualified names are used as the keys in the returned dict. These keys provide access to the target dicts, the dicts in the "targets" lists. """ targets = {} for build_file in data['target_build_files']: for target in data[build_file].get('targets', []): target_name = gyp.common.QualifiedTarget(build_file, target['target_name'], target['toolset']) if target_name in targets: raise GypError('Duplicate target definitions for ' + target_name) targets[target_name] = target return targets def QualifyDependencies(targets): """Make dependency links fully-qualified relative to the current directory. |targets| is a dict mapping fully-qualified target names to their target dicts. For each target in this dict, keys known to contain dependency links are examined, and any dependencies referenced will be rewritten so that they are fully-qualified and relative to the current directory. All rewritten dependencies are suitable for use as keys to |targets| or a similar dict. """ all_dependency_sections = [dep + op for dep in dependency_sections for op in ('', '!', '/')] for target, target_dict in targets.iteritems(): target_build_file = gyp.common.BuildFile(target) toolset = target_dict['toolset'] for dependency_key in all_dependency_sections: dependencies = target_dict.get(dependency_key, []) for index in xrange(0, len(dependencies)): dep_file, dep_target, dep_toolset = gyp.common.ResolveTarget( target_build_file, dependencies[index], toolset) if not multiple_toolsets: # Ignore toolset specification in the dependency if it is specified. dep_toolset = toolset dependency = gyp.common.QualifiedTarget(dep_file, dep_target, dep_toolset) dependencies[index] = dependency # Make sure anything appearing in a list other than "dependencies" also # appears in the "dependencies" list. if dependency_key != 'dependencies' and \ dependency not in target_dict['dependencies']: raise GypError('Found ' + dependency + ' in ' + dependency_key + ' of ' + target + ', but not in dependencies') def ExpandWildcardDependencies(targets, data): """Expands dependencies specified as build_file:*. For each target in |targets|, examines sections containing links to other targets. If any such section contains a link of the form build_file:*, it is taken as a wildcard link, and is expanded to list each target in build_file. The |data| dict provides access to build file dicts. Any target that does not wish to be included by wildcard can provide an optional "suppress_wildcard" key in its target dict. When present and true, a wildcard dependency link will not include such targets. All dependency names, including the keys to |targets| and the values in each dependency list, must be qualified when this function is called. """ for target, target_dict in targets.iteritems(): toolset = target_dict['toolset'] target_build_file = gyp.common.BuildFile(target) for dependency_key in dependency_sections: dependencies = target_dict.get(dependency_key, []) # Loop this way instead of "for dependency in" or "for index in xrange" # because the dependencies list will be modified within the loop body. index = 0 while index < len(dependencies): (dependency_build_file, dependency_target, dependency_toolset) = \ gyp.common.ParseQualifiedTarget(dependencies[index]) if dependency_target != '*' and dependency_toolset != '*': # Not a wildcard. Keep it moving. index = index + 1 continue if dependency_build_file == target_build_file: # It's an error for a target to depend on all other targets in # the same file, because a target cannot depend on itself. raise GypError('Found wildcard in ' + dependency_key + ' of ' + target + ' referring to same build file') # Take the wildcard out and adjust the index so that the next # dependency in the list will be processed the next time through the # loop. del dependencies[index] index = index - 1 # Loop through the targets in the other build file, adding them to # this target's list of dependencies in place of the removed # wildcard. dependency_target_dicts = data[dependency_build_file]['targets'] for dependency_target_dict in dependency_target_dicts: if int(dependency_target_dict.get('suppress_wildcard', False)): continue dependency_target_name = dependency_target_dict['target_name'] if (dependency_target != '*' and dependency_target != dependency_target_name): continue dependency_target_toolset = dependency_target_dict['toolset'] if (dependency_toolset != '*' and dependency_toolset != dependency_target_toolset): continue dependency = gyp.common.QualifiedTarget(dependency_build_file, dependency_target_name, dependency_target_toolset) index = index + 1 dependencies.insert(index, dependency) index = index + 1 def Unify(l): """Removes duplicate elements from l, keeping the first element.""" seen = {} return [seen.setdefault(e, e) for e in l if e not in seen] def RemoveDuplicateDependencies(targets): """Makes sure every dependency appears only once in all targets's dependency lists.""" for target_name, target_dict in targets.iteritems(): for dependency_key in dependency_sections: dependencies = target_dict.get(dependency_key, []) if dependencies: target_dict[dependency_key] = Unify(dependencies) def Filter(l, item): """Removes item from l.""" res = {} return [res.setdefault(e, e) for e in l if e != item] def RemoveSelfDependencies(targets): """Remove self dependencies from targets that have the prune_self_dependency variable set.""" for target_name, target_dict in targets.iteritems(): for dependency_key in dependency_sections: dependencies = target_dict.get(dependency_key, []) if dependencies: for t in dependencies: if t == target_name: if targets[t].get('variables', {}).get('prune_self_dependency', 0): target_dict[dependency_key] = Filter(dependencies, target_name) def RemoveLinkDependenciesFromNoneTargets(targets): """Remove dependencies having the 'link_dependency' attribute from the 'none' targets.""" for target_name, target_dict in targets.iteritems(): for dependency_key in dependency_sections: dependencies = target_dict.get(dependency_key, []) if dependencies: for t in dependencies: if target_dict.get('type', None) == 'none': if targets[t].get('variables', {}).get('link_dependency', 0): target_dict[dependency_key] = \ Filter(target_dict[dependency_key], t) class DependencyGraphNode(object): """ Attributes: ref: A reference to an object that this DependencyGraphNode represents. dependencies: List of DependencyGraphNodes on which this one depends. dependents: List of DependencyGraphNodes that depend on this one. """ class CircularException(GypError): pass def __init__(self, ref): self.ref = ref self.dependencies = [] self.dependents = [] def __repr__(self): return '<DependencyGraphNode: %r>' % self.ref def FlattenToList(self): # flat_list is the sorted list of dependencies - actually, the list items # are the "ref" attributes of DependencyGraphNodes. Every target will # appear in flat_list after all of its dependencies, and before all of its # dependents. flat_list = OrderedSet() # in_degree_zeros is the list of DependencyGraphNodes that have no # dependencies not in flat_list. Initially, it is a copy of the children # of this node, because when the graph was built, nodes with no # dependencies were made implicit dependents of the root node. in_degree_zeros = set(self.dependents[:]) while in_degree_zeros: # Nodes in in_degree_zeros have no dependencies not in flat_list, so they # can be appended to flat_list. Take these nodes out of in_degree_zeros # as work progresses, so that the next node to process from the list can # always be accessed at a consistent position. node = in_degree_zeros.pop() flat_list.add(node.ref) # Look at dependents of the node just added to flat_list. Some of them # may now belong in in_degree_zeros. for node_dependent in node.dependents: is_in_degree_zero = True # TODO: We want to check through the # node_dependent.dependencies list but if it's long and we # always start at the beginning, then we get O(n^2) behaviour. for node_dependent_dependency in node_dependent.dependencies: if not node_dependent_dependency.ref in flat_list: # The dependent one or more dependencies not in flat_list. There # will be more chances to add it to flat_list when examining # it again as a dependent of those other dependencies, provided # that there are no cycles. is_in_degree_zero = False break if is_in_degree_zero: # All of the dependent's dependencies are already in flat_list. Add # it to in_degree_zeros where it will be processed in a future # iteration of the outer loop. in_degree_zeros.add(node_dependent) return list(flat_list) def FindCycles(self): """ Returns a list of cycles in the graph, where each cycle is its own list. """ results = [] visited = set() def Visit(node, path): for child in node.dependents: if child in path: results.append([child] + path[:path.index(child) + 1]) elif not child in visited: visited.add(child) Visit(child, [child] + path) visited.add(self) Visit(self, [self]) return results def DirectDependencies(self, dependencies=None): """Returns a list of just direct dependencies.""" if dependencies == None: dependencies = [] for dependency in self.dependencies: # Check for None, corresponding to the root node. if dependency.ref != None and dependency.ref not in dependencies: dependencies.append(dependency.ref) return dependencies def _AddImportedDependencies(self, targets, dependencies=None): """Given a list of direct dependencies, adds indirect dependencies that other dependencies have declared to export their settings. This method does not operate on self. Rather, it operates on the list of dependencies in the |dependencies| argument. For each dependency in that list, if any declares that it exports the settings of one of its own dependencies, those dependencies whose settings are "passed through" are added to the list. As new items are added to the list, they too will be processed, so it is possible to import settings through multiple levels of dependencies. This method is not terribly useful on its own, it depends on being "primed" with a list of direct dependencies such as one provided by DirectDependencies. DirectAndImportedDependencies is intended to be the public entry point. """ if dependencies == None: dependencies = [] index = 0 while index < len(dependencies): dependency = dependencies[index] dependency_dict = targets[dependency] # Add any dependencies whose settings should be imported to the list # if not already present. Newly-added items will be checked for # their own imports when the list iteration reaches them. # Rather than simply appending new items, insert them after the # dependency that exported them. This is done to more closely match # the depth-first method used by DeepDependencies. add_index = 1 for imported_dependency in \ dependency_dict.get('export_dependent_settings', []): if imported_dependency not in dependencies: dependencies.insert(index + add_index, imported_dependency) add_index = add_index + 1 index = index + 1 return dependencies def DirectAndImportedDependencies(self, targets, dependencies=None): """Returns a list of a target's direct dependencies and all indirect dependencies that a dependency has advertised settings should be exported through the dependency for. """ dependencies = self.DirectDependencies(dependencies) return self._AddImportedDependencies(targets, dependencies) def DeepDependencies(self, dependencies=None): """Returns an OrderedSet of all of a target's dependencies, recursively.""" if dependencies is None: # Using a list to get ordered output and a set to do fast "is it # already added" checks. dependencies = OrderedSet() for dependency in self.dependencies: # Check for None, corresponding to the root node. if dependency.ref is None: continue if dependency.ref not in dependencies: dependency.DeepDependencies(dependencies) dependencies.add(dependency.ref) return dependencies def _LinkDependenciesInternal(self, targets, include_shared_libraries, dependencies=None, initial=True): """Returns an OrderedSet of dependency targets that are linked into this target. This function has a split personality, depending on the setting of |initial|. Outside callers should always leave |initial| at its default setting. When adding a target to the list of dependencies, this function will recurse into itself with |initial| set to False, to collect dependencies that are linked into the linkable target for which the list is being built. If |include_shared_libraries| is False, the resulting dependencies will not include shared_library targets that are linked into this target. """ if dependencies is None: # Using a list to get ordered output and a set to do fast "is it # already added" checks. dependencies = OrderedSet() # Check for None, corresponding to the root node. if self.ref is None: return dependencies # It's kind of sucky that |targets| has to be passed into this function, # but that's presently the easiest way to access the target dicts so that # this function can find target types. if 'target_name' not in targets[self.ref]: raise GypError("Missing 'target_name' field in target.") if 'type' not in targets[self.ref]: raise GypError("Missing 'type' field in target %s" % targets[self.ref]['target_name']) target_type = targets[self.ref]['type'] is_linkable = target_type in linkable_types if initial and not is_linkable: # If this is the first target being examined and it's not linkable, # return an empty list of link dependencies, because the link # dependencies are intended to apply to the target itself (initial is # True) and this target won't be linked. return dependencies # Don't traverse 'none' targets if explicitly excluded. if (target_type == 'none' and not targets[self.ref].get('dependencies_traverse', True)): dependencies.add(self.ref) return dependencies # Executables, mac kernel extensions and loadable modules are already fully # and finally linked. Nothing else can be a link dependency of them, there # can only be dependencies in the sense that a dependent target might run # an executable or load the loadable_module. if not initial and target_type in ('executable', 'loadable_module', 'mac_kernel_extension'): return dependencies # Shared libraries are already fully linked. They should only be included # in |dependencies| when adjusting static library dependencies (in order to # link against the shared_library's import lib), but should not be included # in |dependencies| when propagating link_settings. # The |include_shared_libraries| flag controls which of these two cases we # are handling. if (not initial and target_type == 'shared_library' and not include_shared_libraries): return dependencies # The target is linkable, add it to the list of link dependencies. if self.ref not in dependencies: dependencies.add(self.ref) if initial or not is_linkable: # If this is a subsequent target and it's linkable, don't look any # further for linkable dependencies, as they'll already be linked into # this target linkable. Always look at dependencies of the initial # target, and always look at dependencies of non-linkables. for dependency in self.dependencies: dependency._LinkDependenciesInternal(targets, include_shared_libraries, dependencies, False) return dependencies def DependenciesForLinkSettings(self, targets): """ Returns a list of dependency targets whose link_settings should be merged into this target. """ # TODO(sbaig) Currently, chrome depends on the bug that shared libraries' # link_settings are propagated. So for now, we will allow it, unless the # 'allow_sharedlib_linksettings_propagation' flag is explicitly set to # False. Once chrome is fixed, we can remove this flag. include_shared_libraries = \ targets[self.ref].get('allow_sharedlib_linksettings_propagation', True) return self._LinkDependenciesInternal(targets, include_shared_libraries) def DependenciesToLinkAgainst(self, targets): """ Returns a list of dependency targets that are linked into this target. """ return self._LinkDependenciesInternal(targets, True) def BuildDependencyList(targets): # Create a DependencyGraphNode for each target. Put it into a dict for easy # access. dependency_nodes = {} for target, spec in targets.iteritems(): if target not in dependency_nodes: dependency_nodes[target] = DependencyGraphNode(target) # Set up the dependency links. Targets that have no dependencies are treated # as dependent on root_node. root_node = DependencyGraphNode(None) for target, spec in targets.iteritems(): target_node = dependency_nodes[target] target_build_file = gyp.common.BuildFile(target) dependencies = spec.get('dependencies') if not dependencies: target_node.dependencies = [root_node] root_node.dependents.append(target_node) else: for dependency in dependencies: dependency_node = dependency_nodes.get(dependency) if not dependency_node: raise GypError("Dependency '%s' not found while " "trying to load target %s" % (dependency, target)) target_node.dependencies.append(dependency_node) dependency_node.dependents.append(target_node) flat_list = root_node.FlattenToList() # If there's anything left unvisited, there must be a circular dependency # (cycle). if len(flat_list) != len(targets): if not root_node.dependents: # If all targets have dependencies, add the first target as a dependent # of root_node so that the cycle can be discovered from root_node. target = targets.keys()[0] target_node = dependency_nodes[target] target_node.dependencies.append(root_node) root_node.dependents.append(target_node) cycles = [] for cycle in root_node.FindCycles(): paths = [node.ref for node in cycle] cycles.append('Cycle: %s' % ' -> '.join(paths)) raise DependencyGraphNode.CircularException( 'Cycles in dependency graph detected:\n' + '\n'.join(cycles)) return [dependency_nodes, flat_list] def VerifyNoGYPFileCircularDependencies(targets): # Create a DependencyGraphNode for each gyp file containing a target. Put # it into a dict for easy access. dependency_nodes = {} for target in targets.iterkeys(): build_file = gyp.common.BuildFile(target) if not build_file in dependency_nodes: dependency_nodes[build_file] = DependencyGraphNode(build_file) # Set up the dependency links. for target, spec in targets.iteritems(): build_file = gyp.common.BuildFile(target) build_file_node = dependency_nodes[build_file] target_dependencies = spec.get('dependencies', []) for dependency in target_dependencies: try: dependency_build_file = gyp.common.BuildFile(dependency) except GypError, e: gyp.common.ExceptionAppend( e, 'while computing dependencies of .gyp file %s' % build_file) raise if dependency_build_file == build_file: # A .gyp file is allowed to refer back to itself. continue dependency_node = dependency_nodes.get(dependency_build_file) if not dependency_node: raise GypError("Dependancy '%s' not found" % dependency_build_file) if dependency_node not in build_file_node.dependencies: build_file_node.dependencies.append(dependency_node) dependency_node.dependents.append(build_file_node) # Files that have no dependencies are treated as dependent on root_node. root_node = DependencyGraphNode(None) for build_file_node in dependency_nodes.itervalues(): if len(build_file_node.dependencies) == 0: build_file_node.dependencies.append(root_node) root_node.dependents.append(build_file_node) flat_list = root_node.FlattenToList() # If there's anything left unvisited, there must be a circular dependency # (cycle). if len(flat_list) != len(dependency_nodes): if not root_node.dependents: # If all files have dependencies, add the first file as a dependent # of root_node so that the cycle can be discovered from root_node. file_node = dependency_nodes.values()[0] file_node.dependencies.append(root_node) root_node.dependents.append(file_node) cycles = [] for cycle in root_node.FindCycles(): paths = [node.ref for node in cycle] cycles.append('Cycle: %s' % ' -> '.join(paths)) raise DependencyGraphNode.CircularException( 'Cycles in .gyp file dependency graph detected:\n' + '\n'.join(cycles)) def DoDependentSettings(key, flat_list, targets, dependency_nodes): # key should be one of all_dependent_settings, direct_dependent_settings, # or link_settings. for target in flat_list: target_dict = targets[target] build_file = gyp.common.BuildFile(target) if key == 'all_dependent_settings': dependencies = dependency_nodes[target].DeepDependencies() elif key == 'direct_dependent_settings': dependencies = \ dependency_nodes[target].DirectAndImportedDependencies(targets) elif key == 'link_settings': dependencies = \ dependency_nodes[target].DependenciesForLinkSettings(targets) else: raise GypError("DoDependentSettings doesn't know how to determine " 'dependencies for ' + key) for dependency in dependencies: dependency_dict = targets[dependency] if not key in dependency_dict: continue dependency_build_file = gyp.common.BuildFile(dependency) MergeDicts(target_dict, dependency_dict[key], build_file, dependency_build_file) def AdjustStaticLibraryDependencies(flat_list, targets, dependency_nodes, sort_dependencies): # Recompute target "dependencies" properties. For each static library # target, remove "dependencies" entries referring to other static libraries, # unless the dependency has the "hard_dependency" attribute set. For each # linkable target, add a "dependencies" entry referring to all of the # target's computed list of link dependencies (including static libraries # if no such entry is already present. for target in flat_list: target_dict = targets[target] target_type = target_dict['type'] if target_type == 'static_library': if not 'dependencies' in target_dict: continue target_dict['dependencies_original'] = target_dict.get( 'dependencies', [])[:] # A static library should not depend on another static library unless # the dependency relationship is "hard," which should only be done when # a dependent relies on some side effect other than just the build # product, like a rule or action output. Further, if a target has a # non-hard dependency, but that dependency exports a hard dependency, # the non-hard dependency can safely be removed, but the exported hard # dependency must be added to the target to keep the same dependency # ordering. dependencies = \ dependency_nodes[target].DirectAndImportedDependencies(targets) index = 0 while index < len(dependencies): dependency = dependencies[index] dependency_dict = targets[dependency] # Remove every non-hard static library dependency and remove every # non-static library dependency that isn't a direct dependency. if (dependency_dict['type'] == 'static_library' and \ not dependency_dict.get('hard_dependency', False)) or \ (dependency_dict['type'] != 'static_library' and \ not dependency in target_dict['dependencies']): # Take the dependency out of the list, and don't increment index # because the next dependency to analyze will shift into the index # formerly occupied by the one being removed. del dependencies[index] else: index = index + 1 # Update the dependencies. If the dependencies list is empty, it's not # needed, so unhook it. if len(dependencies) > 0: target_dict['dependencies'] = dependencies else: del target_dict['dependencies'] elif target_type in linkable_types: # Get a list of dependency targets that should be linked into this # target. Add them to the dependencies list if they're not already # present. link_dependencies = \ dependency_nodes[target].DependenciesToLinkAgainst(targets) for dependency in link_dependencies: if dependency == target: continue if not 'dependencies' in target_dict: target_dict['dependencies'] = [] if not dependency in target_dict['dependencies']: target_dict['dependencies'].append(dependency) # Sort the dependencies list in the order from dependents to dependencies. # e.g. If A and B depend on C and C depends on D, sort them in A, B, C, D. # Note: flat_list is already sorted in the order from dependencies to # dependents. if sort_dependencies and 'dependencies' in target_dict: target_dict['dependencies'] = [dep for dep in reversed(flat_list) if dep in target_dict['dependencies']] # Initialize this here to speed up MakePathRelative. exception_re = re.compile(r'''["']?[-/$<>^]''') def MakePathRelative(to_file, fro_file, item): # If item is a relative path, it's relative to the build file dict that it's # coming from. Fix it up to make it relative to the build file dict that # it's going into. # Exception: any |item| that begins with these special characters is # returned without modification. # / Used when a path is already absolute (shortcut optimization; # such paths would be returned as absolute anyway) # $ Used for build environment variables # - Used for some build environment flags (such as -lapr-1 in a # "libraries" section) # < Used for our own variable and command expansions (see ExpandVariables) # > Used for our own variable and command expansions (see ExpandVariables) # ^ Used for our own variable and command expansions (see ExpandVariables) # # "/' Used when a value is quoted. If these are present, then we # check the second character instead. # if to_file == fro_file or exception_re.match(item): return item else: # TODO(dglazkov) The backslash/forward-slash replacement at the end is a # temporary measure. This should really be addressed by keeping all paths # in POSIX until actual project generation. ret = os.path.normpath(os.path.join( gyp.common.RelativePath(os.path.dirname(fro_file), os.path.dirname(to_file)), item)).replace('\\', '/') if item[-1] == '/': ret += '/' return ret def MergeLists(to, fro, to_file, fro_file, is_paths=False, append=True): # Python documentation recommends objects which do not support hash # set this value to None. Python library objects follow this rule. is_hashable = lambda val: val.__hash__ # If x is hashable, returns whether x is in s. Else returns whether x is in l. def is_in_set_or_list(x, s, l): if is_hashable(x): return x in s return x in l prepend_index = 0 # Make membership testing of hashables in |to| (in particular, strings) # faster. hashable_to_set = set(x for x in to if is_hashable(x)) for item in fro: singleton = False if type(item) in (str, int): # The cheap and easy case. if is_paths: to_item = MakePathRelative(to_file, fro_file, item) else: to_item = item if not (type(item) is str and item.startswith('-')): # Any string that doesn't begin with a "-" is a singleton - it can # only appear once in a list, to be enforced by the list merge append # or prepend. singleton = True elif type(item) is dict: # Make a copy of the dictionary, continuing to look for paths to fix. # The other intelligent aspects of merge processing won't apply because # item is being merged into an empty dict. to_item = {} MergeDicts(to_item, item, to_file, fro_file) elif type(item) is list: # Recurse, making a copy of the list. If the list contains any # descendant dicts, path fixing will occur. Note that here, custom # values for is_paths and append are dropped; those are only to be # applied to |to| and |fro|, not sublists of |fro|. append shouldn't # matter anyway because the new |to_item| list is empty. to_item = [] MergeLists(to_item, item, to_file, fro_file) else: raise TypeError( 'Attempt to merge list item of unsupported type ' + \ item.__class__.__name__) if append: # If appending a singleton that's already in the list, don't append. # This ensures that the earliest occurrence of the item will stay put. if not singleton or not is_in_set_or_list(to_item, hashable_to_set, to): to.append(to_item) if is_hashable(to_item): hashable_to_set.add(to_item) else: # If prepending a singleton that's already in the list, remove the # existing instance and proceed with the prepend. This ensures that the # item appears at the earliest possible position in the list. while singleton and to_item in to: to.remove(to_item) # Don't just insert everything at index 0. That would prepend the new # items to the list in reverse order, which would be an unwelcome # surprise. to.insert(prepend_index, to_item) if is_hashable(to_item): hashable_to_set.add(to_item) prepend_index = prepend_index + 1 def MergeDicts(to, fro, to_file, fro_file): # I wanted to name the parameter "from" but it's a Python keyword... for k, v in fro.iteritems(): # It would be nice to do "if not k in to: to[k] = v" but that wouldn't give # copy semantics. Something else may want to merge from the |fro| dict # later, and having the same dict ref pointed to twice in the tree isn't # what anyone wants considering that the dicts may subsequently be # modified. if k in to: bad_merge = False if type(v) in (str, int): if type(to[k]) not in (str, int): bad_merge = True elif type(v) is not type(to[k]): bad_merge = True if bad_merge: raise TypeError( 'Attempt to merge dict value of type ' + v.__class__.__name__ + \ ' into incompatible type ' + to[k].__class__.__name__ + \ ' for key ' + k) if type(v) in (str, int): # Overwrite the existing value, if any. Cheap and easy. is_path = IsPathSection(k) if is_path: to[k] = MakePathRelative(to_file, fro_file, v) else: to[k] = v elif type(v) is dict: # Recurse, guaranteeing copies will be made of objects that require it. if not k in to: to[k] = {} MergeDicts(to[k], v, to_file, fro_file) elif type(v) is list: # Lists in dicts can be merged with different policies, depending on # how the key in the "from" dict (k, the from-key) is written. # # If the from-key has ...the to-list will have this action # this character appended:... applied when receiving the from-list: # = replace # + prepend # ? set, only if to-list does not yet exist # (none) append # # This logic is list-specific, but since it relies on the associated # dict key, it's checked in this dict-oriented function. ext = k[-1] append = True if ext == '=': list_base = k[:-1] lists_incompatible = [list_base, list_base + '?'] to[list_base] = [] elif ext == '+': list_base = k[:-1] lists_incompatible = [list_base + '=', list_base + '?'] append = False elif ext == '?': list_base = k[:-1] lists_incompatible = [list_base, list_base + '=', list_base + '+'] else: list_base = k lists_incompatible = [list_base + '=', list_base + '?'] # Some combinations of merge policies appearing together are meaningless. # It's stupid to replace and append simultaneously, for example. Append # and prepend are the only policies that can coexist. for list_incompatible in lists_incompatible: if list_incompatible in fro: raise GypError('Incompatible list policies ' + k + ' and ' + list_incompatible) if list_base in to: if ext == '?': # If the key ends in "?", the list will only be merged if it doesn't # already exist. continue elif type(to[list_base]) is not list: # This may not have been checked above if merging in a list with an # extension character. raise TypeError( 'Attempt to merge dict value of type ' + v.__class__.__name__ + \ ' into incompatible type ' + to[list_base].__class__.__name__ + \ ' for key ' + list_base + '(' + k + ')') else: to[list_base] = [] # Call MergeLists, which will make copies of objects that require it. # MergeLists can recurse back into MergeDicts, although this will be # to make copies of dicts (with paths fixed), there will be no # subsequent dict "merging" once entering a list because lists are # always replaced, appended to, or prepended to. is_paths = IsPathSection(list_base) MergeLists(to[list_base], v, to_file, fro_file, is_paths, append) else: raise TypeError( 'Attempt to merge dict value of unsupported type ' + \ v.__class__.__name__ + ' for key ' + k) def MergeConfigWithInheritance(new_configuration_dict, build_file, target_dict, configuration, visited): # Skip if previously visted. if configuration in visited: return # Look at this configuration. configuration_dict = target_dict['configurations'][configuration] # Merge in parents. for parent in configuration_dict.get('inherit_from', []): MergeConfigWithInheritance(new_configuration_dict, build_file, target_dict, parent, visited + [configuration]) # Merge it into the new config. MergeDicts(new_configuration_dict, configuration_dict, build_file, build_file) # Drop abstract. if 'abstract' in new_configuration_dict: del new_configuration_dict['abstract'] def SetUpConfigurations(target, target_dict): # key_suffixes is a list of key suffixes that might appear on key names. # These suffixes are handled in conditional evaluations (for =, +, and ?) # and rules/exclude processing (for ! and /). Keys with these suffixes # should be treated the same as keys without. key_suffixes = ['=', '+', '?', '!', '/'] build_file = gyp.common.BuildFile(target) # Provide a single configuration by default if none exists. # TODO(mark): Signal an error if default_configurations exists but # configurations does not. if not 'configurations' in target_dict: target_dict['configurations'] = {'Default': {}} if not 'default_configuration' in target_dict: concrete = [i for (i, config) in target_dict['configurations'].iteritems() if not config.get('abstract')] target_dict['default_configuration'] = sorted(concrete)[0] merged_configurations = {} configs = target_dict['configurations'] for (configuration, old_configuration_dict) in configs.iteritems(): # Skip abstract configurations (saves work only). if old_configuration_dict.get('abstract'): continue # Configurations inherit (most) settings from the enclosing target scope. # Get the inheritance relationship right by making a copy of the target # dict. new_configuration_dict = {} for (key, target_val) in target_dict.iteritems(): key_ext = key[-1:] if key_ext in key_suffixes: key_base = key[:-1] else: key_base = key if not key_base in non_configuration_keys: new_configuration_dict[key] = gyp.simple_copy.deepcopy(target_val) # Merge in configuration (with all its parents first). MergeConfigWithInheritance(new_configuration_dict, build_file, target_dict, configuration, []) merged_configurations[configuration] = new_configuration_dict # Put the new configurations back into the target dict as a configuration. for configuration in merged_configurations.keys(): target_dict['configurations'][configuration] = ( merged_configurations[configuration]) # Now drop all the abstract ones. for configuration in target_dict['configurations'].keys(): old_configuration_dict = target_dict['configurations'][configuration] if old_configuration_dict.get('abstract'): del target_dict['configurations'][configuration] # Now that all of the target's configurations have been built, go through # the target dict's keys and remove everything that's been moved into a # "configurations" section. delete_keys = [] for key in target_dict: key_ext = key[-1:] if key_ext in key_suffixes: key_base = key[:-1] else: key_base = key if not key_base in non_configuration_keys: delete_keys.append(key) for key in delete_keys: del target_dict[key] # Check the configurations to see if they contain invalid keys. for configuration in target_dict['configurations'].keys(): configuration_dict = target_dict['configurations'][configuration] for key in configuration_dict.keys(): if key in invalid_configuration_keys: raise GypError('%s not allowed in the %s configuration, found in ' 'target %s' % (key, configuration, target)) def ProcessListFiltersInDict(name, the_dict): """Process regular expression and exclusion-based filters on lists. An exclusion list is in a dict key named with a trailing "!", like "sources!". Every item in such a list is removed from the associated main list, which in this example, would be "sources". Removed items are placed into a "sources_excluded" list in the dict. Regular expression (regex) filters are contained in dict keys named with a trailing "/", such as "sources/" to operate on the "sources" list. Regex filters in a dict take the form: 'sources/': [ ['exclude', '_(linux|mac|win)\\.cc$'], ['include', '_mac\\.cc$'] ], The first filter says to exclude all files ending in _linux.cc, _mac.cc, and _win.cc. The second filter then includes all files ending in _mac.cc that are now or were once in the "sources" list. Items matching an "exclude" filter are subject to the same processing as would occur if they were listed by name in an exclusion list (ending in "!"). Items matching an "include" filter are brought back into the main list if previously excluded by an exclusion list or exclusion regex filter. Subsequent matching "exclude" patterns can still cause items to be excluded after matching an "include". """ # Look through the dictionary for any lists whose keys end in "!" or "/". # These are lists that will be treated as exclude lists and regular # expression-based exclude/include lists. Collect the lists that are # needed first, looking for the lists that they operate on, and assemble # then into |lists|. This is done in a separate loop up front, because # the _included and _excluded keys need to be added to the_dict, and that # can't be done while iterating through it. lists = [] del_lists = [] for key, value in the_dict.iteritems(): operation = key[-1] if operation != '!' and operation != '/': continue if type(value) is not list: raise ValueError(name + ' key ' + key + ' must be list, not ' + \ value.__class__.__name__) list_key = key[:-1] if list_key not in the_dict: # This happens when there's a list like "sources!" but no corresponding # "sources" list. Since there's nothing for it to operate on, queue up # the "sources!" list for deletion now. del_lists.append(key) continue if type(the_dict[list_key]) is not list: value = the_dict[list_key] raise ValueError(name + ' key ' + list_key + \ ' must be list, not ' + \ value.__class__.__name__ + ' when applying ' + \ {'!': 'exclusion', '/': 'regex'}[operation]) if not list_key in lists: lists.append(list_key) # Delete the lists that are known to be unneeded at this point. for del_list in del_lists: del the_dict[del_list] for list_key in lists: the_list = the_dict[list_key] # Initialize the list_actions list, which is parallel to the_list. Each # item in list_actions identifies whether the corresponding item in # the_list should be excluded, unconditionally preserved (included), or # whether no exclusion or inclusion has been applied. Items for which # no exclusion or inclusion has been applied (yet) have value -1, items # excluded have value 0, and items included have value 1. Includes and # excludes override previous actions. All items in list_actions are # initialized to -1 because no excludes or includes have been processed # yet. list_actions = list((-1,) * len(the_list)) exclude_key = list_key + '!' if exclude_key in the_dict: for exclude_item in the_dict[exclude_key]: for index in xrange(0, len(the_list)): if exclude_item == the_list[index]: # This item matches the exclude_item, so set its action to 0 # (exclude). list_actions[index] = 0 # The "whatever!" list is no longer needed, dump it. del the_dict[exclude_key] regex_key = list_key + '/' if regex_key in the_dict: for regex_item in the_dict[regex_key]: [action, pattern] = regex_item pattern_re = re.compile(pattern) if action == 'exclude': # This item matches an exclude regex, so set its value to 0 (exclude). action_value = 0 elif action == 'include': # This item matches an include regex, so set its value to 1 (include). action_value = 1 else: # This is an action that doesn't make any sense. raise ValueError('Unrecognized action ' + action + ' in ' + name + \ ' key ' + regex_key) for index in xrange(0, len(the_list)): list_item = the_list[index] if list_actions[index] == action_value: # Even if the regex matches, nothing will change so continue (regex # searches are expensive). continue if pattern_re.search(list_item): # Regular expression match. list_actions[index] = action_value # The "whatever/" list is no longer needed, dump it. del the_dict[regex_key] # Add excluded items to the excluded list. # # Note that exclude_key ("sources!") is different from excluded_key # ("sources_excluded"). The exclude_key list is input and it was already # processed and deleted; the excluded_key list is output and it's about # to be created. excluded_key = list_key + '_excluded' if excluded_key in the_dict: raise GypError(name + ' key ' + excluded_key + ' must not be present prior ' ' to applying exclusion/regex filters for ' + list_key) excluded_list = [] # Go backwards through the list_actions list so that as items are deleted, # the indices of items that haven't been seen yet don't shift. That means # that things need to be prepended to excluded_list to maintain them in the # same order that they existed in the_list. for index in xrange(len(list_actions) - 1, -1, -1): if list_actions[index] == 0: # Dump anything with action 0 (exclude). Keep anything with action 1 # (include) or -1 (no include or exclude seen for the item). excluded_list.insert(0, the_list[index]) del the_list[index] # If anything was excluded, put the excluded list into the_dict at # excluded_key. if len(excluded_list) > 0: the_dict[excluded_key] = excluded_list # Now recurse into subdicts and lists that may contain dicts. for key, value in the_dict.iteritems(): if type(value) is dict: ProcessListFiltersInDict(key, value) elif type(value) is list: ProcessListFiltersInList(key, value) def ProcessListFiltersInList(name, the_list): for item in the_list: if type(item) is dict: ProcessListFiltersInDict(name, item) elif type(item) is list: ProcessListFiltersInList(name, item) def ValidateTargetType(target, target_dict): """Ensures the 'type' field on the target is one of the known types. Arguments: target: string, name of target. target_dict: dict, target spec. Raises an exception on error. """ VALID_TARGET_TYPES = ('executable', 'loadable_module', 'static_library', 'shared_library', 'mac_kernel_extension', 'none') target_type = target_dict.get('type', None) if target_type not in VALID_TARGET_TYPES: raise GypError("Target %s has an invalid target type '%s'. " "Must be one of %s." % (target, target_type, '/'.join(VALID_TARGET_TYPES))) if (target_dict.get('standalone_static_library', 0) and not target_type == 'static_library'): raise GypError('Target %s has type %s but standalone_static_library flag is' ' only valid for static_library type.' % (target, target_type)) def ValidateSourcesInTarget(target, target_dict, build_file, duplicate_basename_check): if not duplicate_basename_check: return if target_dict.get('type', None) != 'static_library': return sources = target_dict.get('sources', []) basenames = {} for source in sources: name, ext = os.path.splitext(source) is_compiled_file = ext in [ '.c', '.cc', '.cpp', '.cxx', '.m', '.mm', '.s', '.S'] if not is_compiled_file: continue basename = os.path.basename(name) # Don't include extension. basenames.setdefault(basename, []).append(source) error = '' for basename, files in basenames.iteritems(): if len(files) > 1: error += ' %s: %s\n' % (basename, ' '.join(files)) if error: print('static library %s has several files with the same basename:\n' % target + error + 'libtool on Mac cannot handle that. Use ' '--no-duplicate-basename-check to disable this validation.') raise GypError('Duplicate basenames in sources section, see list above') def ValidateRulesInTarget(target, target_dict, extra_sources_for_rules): """Ensures that the rules sections in target_dict are valid and consistent, and determines which sources they apply to. Arguments: target: string, name of target. target_dict: dict, target spec containing "rules" and "sources" lists. extra_sources_for_rules: a list of keys to scan for rule matches in addition to 'sources'. """ # Dicts to map between values found in rules' 'rule_name' and 'extension' # keys and the rule dicts themselves. rule_names = {} rule_extensions = {} rules = target_dict.get('rules', []) for rule in rules: # Make sure that there's no conflict among rule names and extensions. rule_name = rule['rule_name'] if rule_name in rule_names: raise GypError('rule %s exists in duplicate, target %s' % (rule_name, target)) rule_names[rule_name] = rule rule_extension = rule['extension'] if rule_extension.startswith('.'): rule_extension = rule_extension[1:] if rule_extension in rule_extensions: raise GypError(('extension %s associated with multiple rules, ' + 'target %s rules %s and %s') % (rule_extension, target, rule_extensions[rule_extension]['rule_name'], rule_name)) rule_extensions[rule_extension] = rule # Make sure rule_sources isn't already there. It's going to be # created below if needed. if 'rule_sources' in rule: raise GypError( 'rule_sources must not exist in input, target %s rule %s' % (target, rule_name)) rule_sources = [] source_keys = ['sources'] source_keys.extend(extra_sources_for_rules) for source_key in source_keys: for source in target_dict.get(source_key, []): (source_root, source_extension) = os.path.splitext(source) if source_extension.startswith('.'): source_extension = source_extension[1:] if source_extension == rule_extension: rule_sources.append(source) if len(rule_sources) > 0: rule['rule_sources'] = rule_sources def ValidateRunAsInTarget(target, target_dict, build_file): target_name = target_dict.get('target_name') run_as = target_dict.get('run_as') if not run_as: return if type(run_as) is not dict: raise GypError("The 'run_as' in target %s from file %s should be a " "dictionary." % (target_name, build_file)) action = run_as.get('action') if not action: raise GypError("The 'run_as' in target %s from file %s must have an " "'action' section." % (target_name, build_file)) if type(action) is not list: raise GypError("The 'action' for 'run_as' in target %s from file %s " "must be a list." % (target_name, build_file)) working_directory = run_as.get('working_directory') if working_directory and type(working_directory) is not str: raise GypError("The 'working_directory' for 'run_as' in target %s " "in file %s should be a string." % (target_name, build_file)) environment = run_as.get('environment') if environment and type(environment) is not dict: raise GypError("The 'environment' for 'run_as' in target %s " "in file %s should be a dictionary." % (target_name, build_file)) def ValidateActionsInTarget(target, target_dict, build_file): '''Validates the inputs to the actions in a target.''' target_name = target_dict.get('target_name') actions = target_dict.get('actions', []) for action in actions: action_name = action.get('action_name') if not action_name: raise GypError("Anonymous action in target %s. " "An action must have an 'action_name' field." % target_name) inputs = action.get('inputs', None) if inputs is None: raise GypError('Action in target %s has no inputs.' % target_name) action_command = action.get('action') if action_command and not action_command[0]: raise GypError("Empty action as command in target %s." % target_name) def TurnIntIntoStrInDict(the_dict): """Given dict the_dict, recursively converts all integers into strings. """ # Use items instead of iteritems because there's no need to try to look at # reinserted keys and their associated values. for k, v in the_dict.items(): if type(v) is int: v = str(v) the_dict[k] = v elif type(v) is dict: TurnIntIntoStrInDict(v) elif type(v) is list: TurnIntIntoStrInList(v) if type(k) is int: del the_dict[k] the_dict[str(k)] = v def TurnIntIntoStrInList(the_list): """Given list the_list, recursively converts all integers into strings. """ for index in xrange(0, len(the_list)): item = the_list[index] if type(item) is int: the_list[index] = str(item) elif type(item) is dict: TurnIntIntoStrInDict(item) elif type(item) is list: TurnIntIntoStrInList(item) def PruneUnwantedTargets(targets, flat_list, dependency_nodes, root_targets, data): """Return only the targets that are deep dependencies of |root_targets|.""" qualified_root_targets = [] for target in root_targets: target = target.strip() qualified_targets = gyp.common.FindQualifiedTargets(target, flat_list) if not qualified_targets: raise GypError("Could not find target %s" % target) qualified_root_targets.extend(qualified_targets) wanted_targets = {} for target in qualified_root_targets: wanted_targets[target] = targets[target] for dependency in dependency_nodes[target].DeepDependencies(): wanted_targets[dependency] = targets[dependency] wanted_flat_list = [t for t in flat_list if t in wanted_targets] # Prune unwanted targets from each build_file's data dict. for build_file in data['target_build_files']: if not 'targets' in data[build_file]: continue new_targets = [] for target in data[build_file]['targets']: qualified_name = gyp.common.QualifiedTarget(build_file, target['target_name'], target['toolset']) if qualified_name in wanted_targets: new_targets.append(target) data[build_file]['targets'] = new_targets return wanted_targets, wanted_flat_list def VerifyNoCollidingTargets(targets): """Verify that no two targets in the same directory share the same name. Arguments: targets: A list of targets in the form 'path/to/file.gyp:target_name'. """ # Keep a dict going from 'subdirectory:target_name' to 'foo.gyp'. used = {} for target in targets: # Separate out 'path/to/file.gyp, 'target_name' from # 'path/to/file.gyp:target_name'. path, name = target.rsplit(':', 1) # Separate out 'path/to', 'file.gyp' from 'path/to/file.gyp'. subdir, gyp = os.path.split(path) # Use '.' for the current directory '', so that the error messages make # more sense. if not subdir: subdir = '.' # Prepare a key like 'path/to:target_name'. key = subdir + ':' + name if key in used: # Complain if this target is already used. raise GypError('Duplicate target name "%s" in directory "%s" used both ' 'in "%s" and "%s".' % (name, subdir, gyp, used[key])) used[key] = gyp def SetGeneratorGlobals(generator_input_info): # Set up path_sections and non_configuration_keys with the default data plus # the generator-specific data. global path_sections path_sections = set(base_path_sections) path_sections.update(generator_input_info['path_sections']) global non_configuration_keys non_configuration_keys = base_non_configuration_keys[:] non_configuration_keys.extend(generator_input_info['non_configuration_keys']) global multiple_toolsets multiple_toolsets = generator_input_info[ 'generator_supports_multiple_toolsets'] global generator_filelist_paths generator_filelist_paths = generator_input_info['generator_filelist_paths'] def Load(build_files, variables, includes, depth, generator_input_info, check, circular_check, duplicate_basename_check, parallel, root_targets): SetGeneratorGlobals(generator_input_info) # A generator can have other lists (in addition to sources) be processed # for rules. extra_sources_for_rules = generator_input_info['extra_sources_for_rules'] # Load build files. This loads every target-containing build file into # the |data| dictionary such that the keys to |data| are build file names, # and the values are the entire build file contents after "early" or "pre" # processing has been done and includes have been resolved. # NOTE: data contains both "target" files (.gyp) and "includes" (.gypi), as # well as meta-data (e.g. 'included_files' key). 'target_build_files' keeps # track of the keys corresponding to "target" files. data = {'target_build_files': set()} # Normalize paths everywhere. This is important because paths will be # used as keys to the data dict and for references between input files. build_files = set(map(os.path.normpath, build_files)) if parallel: LoadTargetBuildFilesParallel(build_files, data, variables, includes, depth, check, generator_input_info) else: aux_data = {} for build_file in build_files: try: LoadTargetBuildFile(build_file, data, aux_data, variables, includes, depth, check, True) except Exception, e: gyp.common.ExceptionAppend(e, 'while trying to load %s' % build_file) raise # Build a dict to access each target's subdict by qualified name. targets = BuildTargetsDict(data) # Fully qualify all dependency links. QualifyDependencies(targets) # Remove self-dependencies from targets that have 'prune_self_dependencies' # set to 1. RemoveSelfDependencies(targets) # Expand dependencies specified as build_file:*. ExpandWildcardDependencies(targets, data) # Remove all dependencies marked as 'link_dependency' from the targets of # type 'none'. RemoveLinkDependenciesFromNoneTargets(targets) # Apply exclude (!) and regex (/) list filters only for dependency_sections. for target_name, target_dict in targets.iteritems(): tmp_dict = {} for key_base in dependency_sections: for op in ('', '!', '/'): key = key_base + op if key in target_dict: tmp_dict[key] = target_dict[key] del target_dict[key] ProcessListFiltersInDict(target_name, tmp_dict) # Write the results back to |target_dict|. for key in tmp_dict: target_dict[key] = tmp_dict[key] # Make sure every dependency appears at most once. RemoveDuplicateDependencies(targets) if circular_check: # Make sure that any targets in a.gyp don't contain dependencies in other # .gyp files that further depend on a.gyp. VerifyNoGYPFileCircularDependencies(targets) [dependency_nodes, flat_list] = BuildDependencyList(targets) if root_targets: # Remove, from |targets| and |flat_list|, the targets that are not deep # dependencies of the targets specified in |root_targets|. targets, flat_list = PruneUnwantedTargets( targets, flat_list, dependency_nodes, root_targets, data) # Check that no two targets in the same directory have the same name. VerifyNoCollidingTargets(flat_list) # Handle dependent settings of various types. for settings_type in ['all_dependent_settings', 'direct_dependent_settings', 'link_settings']: DoDependentSettings(settings_type, flat_list, targets, dependency_nodes) # Take out the dependent settings now that they've been published to all # of the targets that require them. for target in flat_list: if settings_type in targets[target]: del targets[target][settings_type] # Make sure static libraries don't declare dependencies on other static # libraries, but that linkables depend on all unlinked static libraries # that they need so that their link steps will be correct. gii = generator_input_info if gii['generator_wants_static_library_dependencies_adjusted']: AdjustStaticLibraryDependencies(flat_list, targets, dependency_nodes, gii['generator_wants_sorted_dependencies']) # Apply "post"/"late"/"target" variable expansions and condition evaluations. for target in flat_list: target_dict = targets[target] build_file = gyp.common.BuildFile(target) ProcessVariablesAndConditionsInDict( target_dict, PHASE_LATE, variables, build_file) # Move everything that can go into a "configurations" section into one. for target in flat_list: target_dict = targets[target] SetUpConfigurations(target, target_dict) # Apply exclude (!) and regex (/) list filters. for target in flat_list: target_dict = targets[target] ProcessListFiltersInDict(target, target_dict) # Apply "latelate" variable expansions and condition evaluations. for target in flat_list: target_dict = targets[target] build_file = gyp.common.BuildFile(target) ProcessVariablesAndConditionsInDict( target_dict, PHASE_LATELATE, variables, build_file) # Make sure that the rules make sense, and build up rule_sources lists as # needed. Not all generators will need to use the rule_sources lists, but # some may, and it seems best to build the list in a common spot. # Also validate actions and run_as elements in targets. for target in flat_list: target_dict = targets[target] build_file = gyp.common.BuildFile(target) ValidateTargetType(target, target_dict) ValidateSourcesInTarget(target, target_dict, build_file, duplicate_basename_check) ValidateRulesInTarget(target, target_dict, extra_sources_for_rules) ValidateRunAsInTarget(target, target_dict, build_file) ValidateActionsInTarget(target, target_dict, build_file) # Generators might not expect ints. Turn them into strs. TurnIntIntoStrInDict(data) # TODO(mark): Return |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. return [flat_list, targets, data]
mit
[ 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, 504, 6365, 14, 1810, 492, 13435, 199, 504, 6365, 14, 1810, 492, 7448, 199, 504, 6365, 14, 1810, 492, 5289, 5841, 199, 504, 6365, 14, 1810, 492, 3820, 199, 504, 6365, 14, 1810, 492, 5673, 199, 504, 6365, 14, 1810, 492, 5013, 199, 504, 6365, 14, 1810, 492, 1933, 2037, 199, 646, 6365, 199, 646, 4902, 14, 2330, 199, 646, 4902, 14, 4129, 63, 1574, 199, 646, 12866, 199, 646, 8691, 199, 646, 747, 14, 515, 199, 646, 295, 199, 646, 16701, 199, 646, 4673, 199, 646, 3873, 199, 646, 984, 199, 646, 5796, 199, 646, 900, 199, 646, 5190, 199, 504, 4902, 14, 2330, 492, 18151, 199, 504, 4902, 14, 2330, 492, 23617, 421, 199, 3, 437, 769, 402, 2943, 626, 787, 10184, 465, 30258, 14, 199, 1073, 461, 63, 1313, 275, 359, 523, 283, 5904, 297, 523, 283, 5555, 63, 4342, 297, 523, 283, 20722, 63, 578, 297, 523, 283, 3088, 63, 4989, 63, 3435, 297, 199, 61, 199, 199, 3, 437, 769, 402, 10189, 626, 1395, 6220, 370, 1163, 4545, 14, 199, 8575, 63, 7786, 275, 788, 5714, 297, 283, 3790, 63, 7106, 63, 1751, 418, 199, 199, 3, 1300, 63, 515, 63, 7786, 365, 282, 769, 402, 10189, 3247, 701, 25686, 626, 1395, 199, 3, 931, 1247, 14, 221, 710, 16952, 883, 5647, 1655, 2883, 12, 314, 2877, 5548, 787, 9545, 199, 3, 1901, 931, 63, 7786, 12, 1325, 1265, 1077, 1240, 6596, 2042, 8660, 3140, 402, 1808, 1902, 199, 3, 769, 5370, 14, 199, 1095, 63, 515, 63, 7786, 275, 359, 523, 283, 6881, 297, 523, 283, 1725, 297, 523, 283, 2613, 63, 3220, 297, 523, 283, 3711, 297, 523, 283, 10159, 297, 523, 283, 4467, 297, 523, 283, 4553, 297, 199, 61, 199, 515, 63, 7786, 275, 663, 342, 199, 199, 3, 5723, 1126, 13, 1412, 11196, 787, 1202, 370, 2581, 1900, 570, 666, 1380, 8697, 199, 3, 315, 9861, 818, 14, 199, 529, 63, 1412, 63, 576, 275, 1052, 199, 529, 63, 1412, 63, 10962, 63, 576, 275, 1052, 199, 199, 318, 6596, 2042, 8660, 8, 2792, 304, 523, 327, 982, 3420, 11187, 315, 1373, 402, 314, 26143, 23778, 11213, 4110, 12, 652, 1159, 6781, 370, 282, 3420, 523, 327, 1928, 314, 8520, 4110, 14, 221, 7324, 365, 440, 6665, 9552, 687, 642, 769, 12, 523, 327, 2952, 2337, 1159, 949, 4340, 367, 282, 5578, 3965, 370, 506, 10184, 465, 282, 931, 14, 523, 1830, 3420, 436, 3420, 1988, 17, 2938, 315, 26143, 23778, 27676, 272, 3420, 275, 3420, 4439, 17, 61, 819, 340, 3420, 315, 931, 63, 7786, 26, 272, 372, 715, 819, 327, 3240, 2452, 610, 2127, 314, 13156, 2513, 8, 694, 92, 493, 92, 515, 9, 83, 31, 12913, 787, 2597, 523, 327, 8652, 6912, 29881, 14, 11719, 8722, 1059, 4877, 3967, 626, 523, 327, 365, 8298, 12930, 2419, 314, 13156, 436, 642, 883, 506, 2797, 394, 725, 10428, 402, 523, 327, 294, 29737, 402, 5431, 880, 9967, 10238, 2530, 878, 14, 523, 340, 14220, 315, 3420, 26, 272, 9483, 275, 3420, 1988, 22, 2938, 272, 340, 9483, 1988, 17, 61, 508, 283, 83, 356, 489, 9483, 275, 9483, 4439, 17, 61, 272, 340, 9483, 1988, 21, 2938, 315, 12331, 493, 297, 2513, 515, 735, 489, 372, 715, 272, 372, 9483, 1988, 20, 2938, 508, 2513, 694, 7, 819, 372, 756, 199, 199, 3, 1300, 63, 2865, 63, 4758, 63, 1612, 365, 282, 769, 402, 790, 1561, 626, 13511, 315, 314, 1347, 199, 3, 6337, 436, 1077, 440, 506, 25350, 1901, 2399, 13422, 14, 221, 2779, 365, 9545, 199, 3, 543, 282, 769, 626, 883, 11492, 687, 314, 4306, 370, 199, 3, 1218, 2222, 63, 4758, 63, 1612, 14, 199, 1095, 63, 2865, 63, 4758, 63, 1612, 275, 359, 523, 327, 3240, 2452, 626, 1471, 2187, 6272, 4545, 436, 440, 13422, 14, 523, 283, 3723, 297, 523, 283, 10057, 297, 523, 283, 16847, 297, 523, 283, 885, 63, 4758, 297, 523, 283, 5714, 297, 523, 283, 5714, 63, 5043, 297, 523, 283, 10159, 297, 523, 283, 29670, 297, 523, 283, 2558, 63, 694, 297, 523, 283, 2558, 63, 3435, 297, 523, 283, 2558, 63, 354, 297, 523, 283, 2558, 63, 1861, 297, 523, 283, 4423, 297, 523, 283, 1065, 63, 305, 297, 523, 283, 4553, 297, 523, 283, 20323, 63, 1986, 63, 4342, 297, 523, 283, 17381, 63, 16692, 297, 523, 283, 1375, 63, 354, 297, 523, 283, 12081, 297, 523, 283, 30116, 297, 523, 283, 466, 297, 819, 327, 3240, 2452, 626, 883, 506, 1911, 6272, 4545, 503, 13422, 12, 1325, 626, 523, 327, 1077, 440, 506, 25350, 687, 4545, 1901, 3932, 13422, 14, 523, 283, 3669, 297, 199, 61, 199, 2865, 63, 4758, 63, 1612, 275, 942, 199, 199, 3, 17276, 626, 886, 440, 13511, 6272, 282, 2897, 2600, 14, 199, 3197, 63, 4758, 63, 1612, 275, 359, 523, 283, 3723, 297, 523, 283, 452, 63, 7106, 63, 1751, 297, 523, 283, 10057, 297, 523, 283, 5714, 297, 523, 283, 2275, 63, 7106, 63, 1751, 297, 523, 283, 10159, 297, 523, 283, 1073, 63, 1751, 297, 523, 283, 4553, 297, 523, 283, 20323, 63, 1986, 63, 4342, 297, 523, 283, 1375, 63, 354, 297, 523, 283, 466, 297, 199, 61, 199, 199, 3, 29001, 3775, 503, 440, 314, 4306, 5171, 3663, 4744, 2193, 14, 199, 6048, 63, 30116, 275, 756, 199, 199, 3, 6912, 83, 367, 13806, 26148, 3792, 370, 1072, 3792, 26, 469, 199, 3, 257, 13836, 12, 199, 3, 257, 12313, 63, 1199, 63, 694, 12, 199, 3, 789, 199, 4679, 63, 14964, 63, 3771, 275, 488, 199, 199, 318, 2372, 607, 3331, 3425, 5535, 8, 1506, 63, 493, 63, 515, 12, 11593, 63, 576, 12, 5120, 29, 403, 304, 523, 408, 1767, 282, 769, 402, 1006, 1900, 1584, 5120, 1901, 1900, 63, 493, 63, 515, 14, 819, 710, 2138, 769, 911, 1395, 1900, 63, 493, 63, 515, 465, 5521, 465, 1006, 1163, 1584, 523, 626, 652, 5120, 12 ]
[ 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, 504, 6365, 14, 1810, 492, 13435, 199, 504, 6365, 14, 1810, 492, 7448, 199, 504, 6365, 14, 1810, 492, 5289, 5841, 199, 504, 6365, 14, 1810, 492, 3820, 199, 504, 6365, 14, 1810, 492, 5673, 199, 504, 6365, 14, 1810, 492, 5013, 199, 504, 6365, 14, 1810, 492, 1933, 2037, 199, 646, 6365, 199, 646, 4902, 14, 2330, 199, 646, 4902, 14, 4129, 63, 1574, 199, 646, 12866, 199, 646, 8691, 199, 646, 747, 14, 515, 199, 646, 295, 199, 646, 16701, 199, 646, 4673, 199, 646, 3873, 199, 646, 984, 199, 646, 5796, 199, 646, 900, 199, 646, 5190, 199, 504, 4902, 14, 2330, 492, 18151, 199, 504, 4902, 14, 2330, 492, 23617, 421, 199, 3, 437, 769, 402, 2943, 626, 787, 10184, 465, 30258, 14, 199, 1073, 461, 63, 1313, 275, 359, 523, 283, 5904, 297, 523, 283, 5555, 63, 4342, 297, 523, 283, 20722, 63, 578, 297, 523, 283, 3088, 63, 4989, 63, 3435, 297, 199, 61, 199, 199, 3, 437, 769, 402, 10189, 626, 1395, 6220, 370, 1163, 4545, 14, 199, 8575, 63, 7786, 275, 788, 5714, 297, 283, 3790, 63, 7106, 63, 1751, 418, 199, 199, 3, 1300, 63, 515, 63, 7786, 365, 282, 769, 402, 10189, 3247, 701, 25686, 626, 1395, 199, 3, 931, 1247, 14, 221, 710, 16952, 883, 5647, 1655, 2883, 12, 314, 2877, 5548, 787, 9545, 199, 3, 1901, 931, 63, 7786, 12, 1325, 1265, 1077, 1240, 6596, 2042, 8660, 3140, 402, 1808, 1902, 199, 3, 769, 5370, 14, 199, 1095, 63, 515, 63, 7786, 275, 359, 523, 283, 6881, 297, 523, 283, 1725, 297, 523, 283, 2613, 63, 3220, 297, 523, 283, 3711, 297, 523, 283, 10159, 297, 523, 283, 4467, 297, 523, 283, 4553, 297, 199, 61, 199, 515, 63, 7786, 275, 663, 342, 199, 199, 3, 5723, 1126, 13, 1412, 11196, 787, 1202, 370, 2581, 1900, 570, 666, 1380, 8697, 199, 3, 315, 9861, 818, 14, 199, 529, 63, 1412, 63, 576, 275, 1052, 199, 529, 63, 1412, 63, 10962, 63, 576, 275, 1052, 199, 199, 318, 6596, 2042, 8660, 8, 2792, 304, 523, 327, 982, 3420, 11187, 315, 1373, 402, 314, 26143, 23778, 11213, 4110, 12, 652, 1159, 6781, 370, 282, 3420, 523, 327, 1928, 314, 8520, 4110, 14, 221, 7324, 365, 440, 6665, 9552, 687, 642, 769, 12, 523, 327, 2952, 2337, 1159, 949, 4340, 367, 282, 5578, 3965, 370, 506, 10184, 465, 282, 931, 14, 523, 1830, 3420, 436, 3420, 1988, 17, 2938, 315, 26143, 23778, 27676, 272, 3420, 275, 3420, 4439, 17, 61, 819, 340, 3420, 315, 931, 63, 7786, 26, 272, 372, 715, 819, 327, 3240, 2452, 610, 2127, 314, 13156, 2513, 8, 694, 92, 493, 92, 515, 9, 83, 31, 12913, 787, 2597, 523, 327, 8652, 6912, 29881, 14, 11719, 8722, 1059, 4877, 3967, 626, 523, 327, 365, 8298, 12930, 2419, 314, 13156, 436, 642, 883, 506, 2797, 394, 725, 10428, 402, 523, 327, 294, 29737, 402, 5431, 880, 9967, 10238, 2530, 878, 14, 523, 340, 14220, 315, 3420, 26, 272, 9483, 275, 3420, 1988, 22, 2938, 272, 340, 9483, 1988, 17, 61, 508, 283, 83, 356, 489, 9483, 275, 9483, 4439, 17, 61, 272, 340, 9483, 1988, 21, 2938, 315, 12331, 493, 297, 2513, 515, 735, 489, 372, 715, 272, 372, 9483, 1988, 20, 2938, 508, 2513, 694, 7, 819, 372, 756, 199, 199, 3, 1300, 63, 2865, 63, 4758, 63, 1612, 365, 282, 769, 402, 790, 1561, 626, 13511, 315, 314, 1347, 199, 3, 6337, 436, 1077, 440, 506, 25350, 1901, 2399, 13422, 14, 221, 2779, 365, 9545, 199, 3, 543, 282, 769, 626, 883, 11492, 687, 314, 4306, 370, 199, 3, 1218, 2222, 63, 4758, 63, 1612, 14, 199, 1095, 63, 2865, 63, 4758, 63, 1612, 275, 359, 523, 327, 3240, 2452, 626, 1471, 2187, 6272, 4545, 436, 440, 13422, 14, 523, 283, 3723, 297, 523, 283, 10057, 297, 523, 283, 16847, 297, 523, 283, 885, 63, 4758, 297, 523, 283, 5714, 297, 523, 283, 5714, 63, 5043, 297, 523, 283, 10159, 297, 523, 283, 29670, 297, 523, 283, 2558, 63, 694, 297, 523, 283, 2558, 63, 3435, 297, 523, 283, 2558, 63, 354, 297, 523, 283, 2558, 63, 1861, 297, 523, 283, 4423, 297, 523, 283, 1065, 63, 305, 297, 523, 283, 4553, 297, 523, 283, 20323, 63, 1986, 63, 4342, 297, 523, 283, 17381, 63, 16692, 297, 523, 283, 1375, 63, 354, 297, 523, 283, 12081, 297, 523, 283, 30116, 297, 523, 283, 466, 297, 819, 327, 3240, 2452, 626, 883, 506, 1911, 6272, 4545, 503, 13422, 12, 1325, 626, 523, 327, 1077, 440, 506, 25350, 687, 4545, 1901, 3932, 13422, 14, 523, 283, 3669, 297, 199, 61, 199, 2865, 63, 4758, 63, 1612, 275, 942, 199, 199, 3, 17276, 626, 886, 440, 13511, 6272, 282, 2897, 2600, 14, 199, 3197, 63, 4758, 63, 1612, 275, 359, 523, 283, 3723, 297, 523, 283, 452, 63, 7106, 63, 1751, 297, 523, 283, 10057, 297, 523, 283, 5714, 297, 523, 283, 2275, 63, 7106, 63, 1751, 297, 523, 283, 10159, 297, 523, 283, 1073, 63, 1751, 297, 523, 283, 4553, 297, 523, 283, 20323, 63, 1986, 63, 4342, 297, 523, 283, 1375, 63, 354, 297, 523, 283, 466, 297, 199, 61, 199, 199, 3, 29001, 3775, 503, 440, 314, 4306, 5171, 3663, 4744, 2193, 14, 199, 6048, 63, 30116, 275, 756, 199, 199, 3, 6912, 83, 367, 13806, 26148, 3792, 370, 1072, 3792, 26, 469, 199, 3, 257, 13836, 12, 199, 3, 257, 12313, 63, 1199, 63, 694, 12, 199, 3, 789, 199, 4679, 63, 14964, 63, 3771, 275, 488, 199, 199, 318, 2372, 607, 3331, 3425, 5535, 8, 1506, 63, 493, 63, 515, 12, 11593, 63, 576, 12, 5120, 29, 403, 304, 523, 408, 1767, 282, 769, 402, 1006, 1900, 1584, 5120, 1901, 1900, 63, 493, 63, 515, 14, 819, 710, 2138, 769, 911, 1395, 1900, 63, 493, 63, 515, 465, 5521, 465, 1006, 1163, 1584, 523, 626, 652, 5120, 12, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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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 ]
kaushik94/sympy
sympy/printing/mathml.py
1
74156
""" A MathML printer. """ from __future__ import print_function, division from sympy import sympify, S, Mul from sympy.core.compatibility import range, string_types, default_sort_key from sympy.core.function import _coeff_isneg from sympy.printing.conventions import split_super_sub, requires_partial from sympy.printing.precedence import \ precedence_traditional, PRECEDENCE, PRECEDENCE_TRADITIONAL from sympy.printing.pretty.pretty_symbology import greek_unicode from sympy.printing.printer import Printer import mpmath.libmp as mlib from mpmath.libmp import prec_to_dps class MathMLPrinterBase(Printer): """Contains common code required for MathMLContentPrinter and MathMLPresentationPrinter. """ _default_settings = { "order": None, "encoding": "utf-8", "fold_frac_powers": False, "fold_func_brackets": False, "fold_short_frac": None, "inv_trig_style": "abbreviated", "ln_notation": False, "long_frac_ratio": None, "mat_delim": "[", "mat_symbol_style": "plain", "mul_symbol": None, "root_notation": True, "symbol_names": {}, "mul_symbol_mathml_numbers": '&#xB7;', } def __init__(self, settings=None): Printer.__init__(self, settings) from xml.dom.minidom import Document, Text self.dom = Document() # Workaround to allow strings to remain unescaped # Based on # https://stackoverflow.com/questions/38015864/python-xml-dom-minidom-\ # please-dont-escape-my-strings/38041194 class RawText(Text): def writexml(self, writer, indent='', addindent='', newl=''): if self.data: writer.write(u'{}{}{}'.format(indent, self.data, newl)) def createRawTextNode(data): r = RawText() r.data = data r.ownerDocument = self.dom return r self.dom.createTextNode = createRawTextNode def doprint(self, expr): """ Prints the expression as MathML. """ mathML = Printer._print(self, expr) unistr = mathML.toxml() xmlbstr = unistr.encode('ascii', 'xmlcharrefreplace') res = xmlbstr.decode() return res def apply_patch(self): # Applying the patch of xml.dom.minidom bug # Date: 2011-11-18 # Description: http://ronrothman.com/public/leftbraned/xml-dom-minidom\ # -toprettyxml-and-silly-whitespace/#best-solution # Issue: http://bugs.python.org/issue4147 # Patch: http://hg.python.org/cpython/rev/7262f8f276ff/ from xml.dom.minidom import Element, Text, Node, _write_data def writexml(self, writer, indent="", addindent="", newl=""): # indent = current indentation # addindent = indentation to add to higher levels # newl = newline string writer.write(indent + "<" + self.tagName) attrs = self._get_attributes() a_names = list(attrs.keys()) a_names.sort() for a_name in a_names: writer.write(" %s=\"" % a_name) _write_data(writer, attrs[a_name].value) writer.write("\"") if self.childNodes: writer.write(">") if (len(self.childNodes) == 1 and self.childNodes[0].nodeType == Node.TEXT_NODE): self.childNodes[0].writexml(writer, '', '', '') else: writer.write(newl) for node in self.childNodes: node.writexml( writer, indent + addindent, addindent, newl) writer.write(indent) writer.write("</%s>%s" % (self.tagName, newl)) else: writer.write("/>%s" % (newl)) self._Element_writexml_old = Element.writexml Element.writexml = writexml def writexml(self, writer, indent="", addindent="", newl=""): _write_data(writer, "%s%s%s" % (indent, self.data, newl)) self._Text_writexml_old = Text.writexml Text.writexml = writexml def restore_patch(self): from xml.dom.minidom import Element, Text Element.writexml = self._Element_writexml_old Text.writexml = self._Text_writexml_old class MathMLContentPrinter(MathMLPrinterBase): """Prints an expression to the Content MathML markup language. References: https://www.w3.org/TR/MathML2/chapter4.html """ printmethod = "_mathml_content" def mathml_tag(self, e): """Returns the MathML tag for an expression.""" translate = { 'Add': 'plus', 'Mul': 'times', 'Derivative': 'diff', 'Number': 'cn', 'int': 'cn', 'Pow': 'power', 'Max': 'max', 'Min': 'min', 'Abs': 'abs', 'And': 'and', 'Or': 'or', 'Xor': 'xor', 'Not': 'not', 'Implies': 'implies', 'Symbol': 'ci', 'MatrixSymbol': 'ci', 'RandomSymbol': 'ci', 'Integral': 'int', 'Sum': 'sum', 'sin': 'sin', 'cos': 'cos', 'tan': 'tan', 'cot': 'cot', 'csc': 'csc', 'sec': 'sec', 'sinh': 'sinh', 'cosh': 'cosh', 'tanh': 'tanh', 'coth': 'coth', 'csch': 'csch', 'sech': 'sech', 'asin': 'arcsin', 'asinh': 'arcsinh', 'acos': 'arccos', 'acosh': 'arccosh', 'atan': 'arctan', 'atanh': 'arctanh', 'atan2': 'arctan', 'acot': 'arccot', 'acoth': 'arccoth', 'asec': 'arcsec', 'asech': 'arcsech', 'acsc': 'arccsc', 'acsch': 'arccsch', 'log': 'ln', 'Equality': 'eq', 'Unequality': 'neq', 'GreaterThan': 'geq', 'LessThan': 'leq', 'StrictGreaterThan': 'gt', 'StrictLessThan': 'lt', } for cls in e.__class__.__mro__: n = cls.__name__ if n in translate: return translate[n] # Not found in the MRO set n = e.__class__.__name__ return n.lower() def _print_Mul(self, expr): if _coeff_isneg(expr): x = self.dom.createElement('apply') x.appendChild(self.dom.createElement('minus')) x.appendChild(self._print_Mul(-expr)) return x from sympy.simplify import fraction numer, denom = fraction(expr) if denom is not S.One: x = self.dom.createElement('apply') x.appendChild(self.dom.createElement('divide')) x.appendChild(self._print(numer)) x.appendChild(self._print(denom)) return x coeff, terms = expr.as_coeff_mul() if coeff is S.One and len(terms) == 1: # XXX since the negative coefficient has been handled, I don't # think a coeff of 1 can remain return self._print(terms[0]) if self.order != 'old': terms = Mul._from_args(terms).as_ordered_factors() x = self.dom.createElement('apply') x.appendChild(self.dom.createElement('times')) if coeff != 1: x.appendChild(self._print(coeff)) for term in terms: x.appendChild(self._print(term)) return x def _print_Add(self, expr, order=None): args = self._as_ordered_terms(expr, order=order) lastProcessed = self._print(args[0]) plusNodes = [] for arg in args[1:]: if _coeff_isneg(arg): # use minus x = self.dom.createElement('apply') x.appendChild(self.dom.createElement('minus')) x.appendChild(lastProcessed) x.appendChild(self._print(-arg)) # invert expression since this is now minused lastProcessed = x if arg == args[-1]: plusNodes.append(lastProcessed) else: plusNodes.append(lastProcessed) lastProcessed = self._print(arg) if arg == args[-1]: plusNodes.append(self._print(arg)) if len(plusNodes) == 1: return lastProcessed x = self.dom.createElement('apply') x.appendChild(self.dom.createElement('plus')) while plusNodes: x.appendChild(plusNodes.pop(0)) return x def _print_Piecewise(self, expr): if expr.args[-1].cond != True: # We need the last conditional to be a True, otherwise the resulting # function may not return a result. raise ValueError("All Piecewise expressions must contain an " "(expr, True) statement to be used as a default " "condition. Without one, the generated " "expression may not evaluate to anything under " "some condition.") root = self.dom.createElement('piecewise') for i, (e, c) in enumerate(expr.args): if i == len(expr.args) - 1 and c == True: piece = self.dom.createElement('otherwise') piece.appendChild(self._print(e)) else: piece = self.dom.createElement('piece') piece.appendChild(self._print(e)) piece.appendChild(self._print(c)) root.appendChild(piece) return root def _print_MatrixBase(self, m): x = self.dom.createElement('matrix') for i in range(m.rows): x_r = self.dom.createElement('matrixrow') for j in range(m.cols): x_r.appendChild(self._print(m[i, j])) x.appendChild(x_r) return x def _print_Rational(self, e): if e.q == 1: # don't divide x = self.dom.createElement('cn') x.appendChild(self.dom.createTextNode(str(e.p))) return x x = self.dom.createElement('apply') x.appendChild(self.dom.createElement('divide')) # numerator xnum = self.dom.createElement('cn') xnum.appendChild(self.dom.createTextNode(str(e.p))) # denominator xdenom = self.dom.createElement('cn') xdenom.appendChild(self.dom.createTextNode(str(e.q))) x.appendChild(xnum) x.appendChild(xdenom) return x def _print_Limit(self, e): x = self.dom.createElement('apply') x.appendChild(self.dom.createElement(self.mathml_tag(e))) x_1 = self.dom.createElement('bvar') x_2 = self.dom.createElement('lowlimit') x_1.appendChild(self._print(e.args[1])) x_2.appendChild(self._print(e.args[2])) x.appendChild(x_1) x.appendChild(x_2) x.appendChild(self._print(e.args[0])) return x def _print_ImaginaryUnit(self, e): return self.dom.createElement('imaginaryi') def _print_EulerGamma(self, e): return self.dom.createElement('eulergamma') def _print_GoldenRatio(self, e): """We use unicode #x3c6 for Greek letter phi as defined here http://www.w3.org/2003/entities/2007doc/isogrk1.html""" x = self.dom.createElement('cn') x.appendChild(self.dom.createTextNode(u"\N{GREEK SMALL LETTER PHI}")) return x def _print_Exp1(self, e): return self.dom.createElement('exponentiale') def _print_Pi(self, e): return self.dom.createElement('pi') def _print_Infinity(self, e): return self.dom.createElement('infinity') def _print_NaN(self, e): return self.dom.createElement('notanumber') def _print_EmptySet(self, e): return self.dom.createElement('emptyset') def _print_BooleanTrue(self, e): return self.dom.createElement('true') def _print_BooleanFalse(self, e): return self.dom.createElement('false') def _print_NegativeInfinity(self, e): x = self.dom.createElement('apply') x.appendChild(self.dom.createElement('minus')) x.appendChild(self.dom.createElement('infinity')) return x def _print_Integral(self, e): def lime_recur(limits): x = self.dom.createElement('apply') x.appendChild(self.dom.createElement(self.mathml_tag(e))) bvar_elem = self.dom.createElement('bvar') bvar_elem.appendChild(self._print(limits[0][0])) x.appendChild(bvar_elem) if len(limits[0]) == 3: low_elem = self.dom.createElement('lowlimit') low_elem.appendChild(self._print(limits[0][1])) x.appendChild(low_elem) up_elem = self.dom.createElement('uplimit') up_elem.appendChild(self._print(limits[0][2])) x.appendChild(up_elem) if len(limits[0]) == 2: up_elem = self.dom.createElement('uplimit') up_elem.appendChild(self._print(limits[0][1])) x.appendChild(up_elem) if len(limits) == 1: x.appendChild(self._print(e.function)) else: x.appendChild(lime_recur(limits[1:])) return x limits = list(e.limits) limits.reverse() return lime_recur(limits) def _print_Sum(self, e): # Printer can be shared because Sum and Integral have the # same internal representation. return self._print_Integral(e) def _print_Symbol(self, sym): ci = self.dom.createElement(self.mathml_tag(sym)) def join(items): if len(items) > 1: mrow = self.dom.createElement('mml:mrow') for i, item in enumerate(items): if i > 0: mo = self.dom.createElement('mml:mo') mo.appendChild(self.dom.createTextNode(" ")) mrow.appendChild(mo) mi = self.dom.createElement('mml:mi') mi.appendChild(self.dom.createTextNode(item)) mrow.appendChild(mi) return mrow else: mi = self.dom.createElement('mml:mi') mi.appendChild(self.dom.createTextNode(items[0])) return mi # translate name, supers and subs to unicode characters def translate(s): if s in greek_unicode: return greek_unicode.get(s) else: return s name, supers, subs = split_super_sub(sym.name) name = translate(name) supers = [translate(sup) for sup in supers] subs = [translate(sub) for sub in subs] mname = self.dom.createElement('mml:mi') mname.appendChild(self.dom.createTextNode(name)) if not supers: if not subs: ci.appendChild(self.dom.createTextNode(name)) else: msub = self.dom.createElement('mml:msub') msub.appendChild(mname) msub.appendChild(join(subs)) ci.appendChild(msub) else: if not subs: msup = self.dom.createElement('mml:msup') msup.appendChild(mname) msup.appendChild(join(supers)) ci.appendChild(msup) else: msubsup = self.dom.createElement('mml:msubsup') msubsup.appendChild(mname) msubsup.appendChild(join(subs)) msubsup.appendChild(join(supers)) ci.appendChild(msubsup) return ci _print_MatrixSymbol = _print_Symbol _print_RandomSymbol = _print_Symbol def _print_Pow(self, e): # Here we use root instead of power if the exponent is the reciprocal # of an integer if (self._settings['root_notation'] and e.exp.is_Rational and e.exp.p == 1): x = self.dom.createElement('apply') x.appendChild(self.dom.createElement('root')) if e.exp.q != 2: xmldeg = self.dom.createElement('degree') xmlci = self.dom.createElement('ci') xmlci.appendChild(self.dom.createTextNode(str(e.exp.q))) xmldeg.appendChild(xmlci) x.appendChild(xmldeg) x.appendChild(self._print(e.base)) return x x = self.dom.createElement('apply') x_1 = self.dom.createElement(self.mathml_tag(e)) x.appendChild(x_1) x.appendChild(self._print(e.base)) x.appendChild(self._print(e.exp)) return x def _print_Number(self, e): x = self.dom.createElement(self.mathml_tag(e)) x.appendChild(self.dom.createTextNode(str(e))) return x def _print_Derivative(self, e): x = self.dom.createElement('apply') diff_symbol = self.mathml_tag(e) if requires_partial(e.expr): diff_symbol = 'partialdiff' x.appendChild(self.dom.createElement(diff_symbol)) x_1 = self.dom.createElement('bvar') for sym, times in reversed(e.variable_count): x_1.appendChild(self._print(sym)) if times > 1: degree = self.dom.createElement('degree') degree.appendChild(self._print(sympify(times))) x_1.appendChild(degree) x.appendChild(x_1) x.appendChild(self._print(e.expr)) return x def _print_Function(self, e): x = self.dom.createElement("apply") x.appendChild(self.dom.createElement(self.mathml_tag(e))) for arg in e.args: x.appendChild(self._print(arg)) return x def _print_Basic(self, e): x = self.dom.createElement(self.mathml_tag(e)) for arg in e.args: x.appendChild(self._print(arg)) return x def _print_AssocOp(self, e): x = self.dom.createElement('apply') x_1 = self.dom.createElement(self.mathml_tag(e)) x.appendChild(x_1) for arg in e.args: x.appendChild(self._print(arg)) return x def _print_Relational(self, e): x = self.dom.createElement('apply') x.appendChild(self.dom.createElement(self.mathml_tag(e))) x.appendChild(self._print(e.lhs)) x.appendChild(self._print(e.rhs)) return x def _print_list(self, seq): """MathML reference for the <list> element: http://www.w3.org/TR/MathML2/chapter4.html#contm.list""" dom_element = self.dom.createElement('list') for item in seq: dom_element.appendChild(self._print(item)) return dom_element def _print_int(self, p): dom_element = self.dom.createElement(self.mathml_tag(p)) dom_element.appendChild(self.dom.createTextNode(str(p))) return dom_element _print_Implies = _print_AssocOp _print_Not = _print_AssocOp _print_Xor = _print_AssocOp class MathMLPresentationPrinter(MathMLPrinterBase): """Prints an expression to the Presentation MathML markup language. References: https://www.w3.org/TR/MathML2/chapter3.html """ printmethod = "_mathml_presentation" def mathml_tag(self, e): """Returns the MathML tag for an expression.""" translate = { 'Number': 'mn', 'Limit': '&#x2192;', 'Derivative': '&dd;', 'int': 'mn', 'Symbol': 'mi', 'Integral': '&int;', 'Sum': '&#x2211;', 'sin': 'sin', 'cos': 'cos', 'tan': 'tan', 'cot': 'cot', 'asin': 'arcsin', 'asinh': 'arcsinh', 'acos': 'arccos', 'acosh': 'arccosh', 'atan': 'arctan', 'atanh': 'arctanh', 'acot': 'arccot', 'atan2': 'arctan', 'Equality': '=', 'Unequality': '&#x2260;', 'GreaterThan': '&#x2265;', 'LessThan': '&#x2264;', 'StrictGreaterThan': '>', 'StrictLessThan': '<', 'lerchphi': '&#x3A6;', 'zeta': '&#x3B6;', 'dirichlet_eta': '&#x3B7;', 'elliptic_k': '&#x39A;', 'lowergamma': '&#x3B3;', 'uppergamma': '&#x393;', 'gamma': '&#x393;', 'totient': '&#x3D5;', 'reduced_totient': '&#x3BB;', 'primenu': '&#x3BD;', 'primeomega': '&#x3A9;', 'fresnels': 'S', 'fresnelc': 'C', 'LambertW': 'W', 'Heaviside': '&#x398;', 'BooleanTrue': 'True', 'BooleanFalse': 'False', 'NoneType': 'None', 'mathieus': 'S', 'mathieuc': 'C', 'mathieusprime': 'S&#x2032;', 'mathieucprime': 'C&#x2032;', } def mul_symbol_selection(): if (self._settings["mul_symbol"] is None or self._settings["mul_symbol"] == 'None'): return '&InvisibleTimes;' elif self._settings["mul_symbol"] == 'times': return '&#xD7;' elif self._settings["mul_symbol"] == 'dot': return '&#xB7;' elif self._settings["mul_symbol"] == 'ldot': return '&#x2024;' elif not isinstance(self._settings["mul_symbol"], string_types): raise TypeError else: return self._settings["mul_symbol"] for cls in e.__class__.__mro__: n = cls.__name__ if n in translate: return translate[n] # Not found in the MRO set if e.__class__.__name__ == "Mul": return mul_symbol_selection() n = e.__class__.__name__ return n.lower() def parenthesize(self, item, level, strict=False): prec_val = precedence_traditional(item) if (prec_val < level) or ((not strict) and prec_val <= level): brac = self.dom.createElement('mfenced') brac.appendChild(self._print(item)) return brac else: return self._print(item) def _print_Mul(self, expr): def multiply(expr, mrow): from sympy.simplify import fraction numer, denom = fraction(expr) if denom is not S.One: frac = self.dom.createElement('mfrac') if self._settings["fold_short_frac"] and len(str(expr)) < 7: frac.setAttribute('bevelled', 'true') xnum = self._print(numer) xden = self._print(denom) frac.appendChild(xnum) frac.appendChild(xden) mrow.appendChild(frac) return mrow coeff, terms = expr.as_coeff_mul() if coeff is S.One and len(terms) == 1: mrow.appendChild(self._print(terms[0])) return mrow if self.order != 'old': terms = Mul._from_args(terms).as_ordered_factors() if coeff != 1: x = self._print(coeff) y = self.dom.createElement('mo') y.appendChild(self.dom.createTextNode(self.mathml_tag(expr))) mrow.appendChild(x) mrow.appendChild(y) for term in terms: mrow.appendChild(self.parenthesize(term, PRECEDENCE['Mul'])) if not term == terms[-1]: y = self.dom.createElement('mo') y.appendChild(self.dom.createTextNode(self.mathml_tag(expr))) mrow.appendChild(y) return mrow mrow = self.dom.createElement('mrow') if _coeff_isneg(expr): x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode('-')) mrow.appendChild(x) mrow = multiply(-expr, mrow) else: mrow = multiply(expr, mrow) return mrow def _print_Add(self, expr, order=None): mrow = self.dom.createElement('mrow') args = self._as_ordered_terms(expr, order=order) mrow.appendChild(self._print(args[0])) for arg in args[1:]: if _coeff_isneg(arg): # use minus x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode('-')) y = self._print(-arg) # invert expression since this is now minused else: x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode('+')) y = self._print(arg) mrow.appendChild(x) mrow.appendChild(y) return mrow def _print_MatrixBase(self, m): table = self.dom.createElement('mtable') for i in range(m.rows): x = self.dom.createElement('mtr') for j in range(m.cols): y = self.dom.createElement('mtd') y.appendChild(self._print(m[i, j])) x.appendChild(y) table.appendChild(x) if self._settings["mat_delim"] == '': return table brac = self.dom.createElement('mfenced') if self._settings["mat_delim"] == "[": brac.setAttribute('close', ']') brac.setAttribute('open', '[') brac.appendChild(table) return brac def _get_printed_Rational(self, e, folded=None): if e.p < 0: p = -e.p else: p = e.p x = self.dom.createElement('mfrac') if folded or self._settings["fold_short_frac"]: x.setAttribute('bevelled', 'true') x.appendChild(self._print(p)) x.appendChild(self._print(e.q)) if e.p < 0: mrow = self.dom.createElement('mrow') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('-')) mrow.appendChild(mo) mrow.appendChild(x) return mrow else: return x def _print_Rational(self, e): if e.q == 1: # don't divide return self._print(e.p) return self._get_printed_Rational(e, self._settings["fold_short_frac"]) def _print_Limit(self, e): mrow = self.dom.createElement('mrow') munder = self.dom.createElement('munder') mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode('lim')) x = self.dom.createElement('mrow') x_1 = self._print(e.args[1]) arrow = self.dom.createElement('mo') arrow.appendChild(self.dom.createTextNode(self.mathml_tag(e))) x_2 = self._print(e.args[2]) x.appendChild(x_1) x.appendChild(arrow) x.appendChild(x_2) munder.appendChild(mi) munder.appendChild(x) mrow.appendChild(munder) mrow.appendChild(self._print(e.args[0])) return mrow def _print_ImaginaryUnit(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&ImaginaryI;')) return x def _print_GoldenRatio(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&#x3A6;')) return x def _print_Exp1(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&ExponentialE;')) return x def _print_Pi(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&pi;')) return x def _print_Infinity(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&#x221E;')) return x def _print_NegativeInfinity(self, e): mrow = self.dom.createElement('mrow') y = self.dom.createElement('mo') y.appendChild(self.dom.createTextNode('-')) x = self._print_Infinity(e) mrow.appendChild(y) mrow.appendChild(x) return mrow def _print_HBar(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&#x210F;')) return x def _print_EulerGamma(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&#x3B3;')) return x def _print_TribonacciConstant(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('TribonacciConstant')) return x def _print_Dagger(self, e): msup = self.dom.createElement('msup') msup.appendChild(self._print(e.args[0])) msup.appendChild(self.dom.createTextNode('&#x2020;')) return msup def _print_Contains(self, e): mrow = self.dom.createElement('mrow') mrow.appendChild(self._print(e.args[0])) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#x2208;')) mrow.appendChild(mo) mrow.appendChild(self._print(e.args[1])) return mrow def _print_HilbertSpace(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&#x210B;')) return x def _print_ComplexSpace(self, e): msup = self.dom.createElement('msup') msup.appendChild(self.dom.createTextNode('&#x1D49E;')) msup.appendChild(self._print(e.args[0])) return msup def _print_FockSpace(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&#x2131;')) return x def _print_Integral(self, expr): intsymbols = {1: "&#x222B;", 2: "&#x222C;", 3: "&#x222D;"} mrow = self.dom.createElement('mrow') if len(expr.limits) <= 3 and all(len(lim) == 1 for lim in expr.limits): # Only up to three-integral signs exists mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode(intsymbols[len(expr.limits)])) mrow.appendChild(mo) else: # Either more than three or limits provided for lim in reversed(expr.limits): mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode(intsymbols[1])) if len(lim) == 1: mrow.appendChild(mo) if len(lim) == 2: msup = self.dom.createElement('msup') msup.appendChild(mo) msup.appendChild(self._print(lim[1])) mrow.appendChild(msup) if len(lim) == 3: msubsup = self.dom.createElement('msubsup') msubsup.appendChild(mo) msubsup.appendChild(self._print(lim[1])) msubsup.appendChild(self._print(lim[2])) mrow.appendChild(msubsup) # print function mrow.appendChild(self.parenthesize(expr.function, PRECEDENCE["Mul"], strict=True)) # print integration variables for lim in reversed(expr.limits): d = self.dom.createElement('mo') d.appendChild(self.dom.createTextNode('&dd;')) mrow.appendChild(d) mrow.appendChild(self._print(lim[0])) return mrow def _print_Sum(self, e): limits = list(e.limits) subsup = self.dom.createElement('munderover') low_elem = self._print(limits[0][1]) up_elem = self._print(limits[0][2]) summand = self.dom.createElement('mo') summand.appendChild(self.dom.createTextNode(self.mathml_tag(e))) low = self.dom.createElement('mrow') var = self._print(limits[0][0]) equal = self.dom.createElement('mo') equal.appendChild(self.dom.createTextNode('=')) low.appendChild(var) low.appendChild(equal) low.appendChild(low_elem) subsup.appendChild(summand) subsup.appendChild(low) subsup.appendChild(up_elem) mrow = self.dom.createElement('mrow') mrow.appendChild(subsup) if len(str(e.function)) == 1: mrow.appendChild(self._print(e.function)) else: fence = self.dom.createElement('mfenced') fence.appendChild(self._print(e.function)) mrow.appendChild(fence) return mrow def _print_Symbol(self, sym, style='plain'): def join(items): if len(items) > 1: mrow = self.dom.createElement('mrow') for i, item in enumerate(items): if i > 0: mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode(" ")) mrow.appendChild(mo) mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode(item)) mrow.appendChild(mi) return mrow else: mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode(items[0])) return mi # translate name, supers and subs to unicode characters def translate(s): if s in greek_unicode: return greek_unicode.get(s) else: return s name, supers, subs = split_super_sub(sym.name) name = translate(name) supers = [translate(sup) for sup in supers] subs = [translate(sub) for sub in subs] mname = self.dom.createElement('mi') mname.appendChild(self.dom.createTextNode(name)) if len(supers) == 0: if len(subs) == 0: x = mname else: x = self.dom.createElement('msub') x.appendChild(mname) x.appendChild(join(subs)) else: if len(subs) == 0: x = self.dom.createElement('msup') x.appendChild(mname) x.appendChild(join(supers)) else: x = self.dom.createElement('msubsup') x.appendChild(mname) x.appendChild(join(subs)) x.appendChild(join(supers)) # Set bold font? if style == 'bold': x.setAttribute('mathvariant', 'bold') return x def _print_MatrixSymbol(self, sym): return self._print_Symbol(sym, style=self._settings['mat_symbol_style']) _print_RandomSymbol = _print_Symbol def _print_conjugate(self, expr): enc = self.dom.createElement('menclose') enc.setAttribute('notation', 'top') enc.appendChild(self._print(expr.args[0])) return enc def _print_operator_after(self, op, expr): row = self.dom.createElement('mrow') row.appendChild(self.parenthesize(expr, PRECEDENCE["Func"])) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode(op)) row.appendChild(mo) return row def _print_factorial(self, expr): return self._print_operator_after('!', expr.args[0]) def _print_factorial2(self, expr): return self._print_operator_after('!!', expr.args[0]) def _print_binomial(self, expr): brac = self.dom.createElement('mfenced') frac = self.dom.createElement('mfrac') frac.setAttribute('linethickness', '0') frac.appendChild(self._print(expr.args[0])) frac.appendChild(self._print(expr.args[1])) brac.appendChild(frac) return brac def _print_Pow(self, e): # Here we use root instead of power if the exponent is the # reciprocal of an integer if (e.exp.is_Rational and abs(e.exp.p) == 1 and e.exp.q != 1 and self._settings['root_notation']): if e.exp.q == 2: x = self.dom.createElement('msqrt') x.appendChild(self._print(e.base)) if e.exp.q != 2: x = self.dom.createElement('mroot') x.appendChild(self._print(e.base)) x.appendChild(self._print(e.exp.q)) if e.exp.p == -1: frac = self.dom.createElement('mfrac') frac.appendChild(self._print(1)) frac.appendChild(x) return frac else: return x if e.exp.is_Rational and e.exp.q != 1: if e.exp.is_negative: top = self.dom.createElement('mfrac') top.appendChild(self._print(1)) x = self.dom.createElement('msup') x.appendChild(self.parenthesize(e.base, PRECEDENCE['Pow'])) x.appendChild(self._get_printed_Rational(-e.exp, self._settings['fold_frac_powers'])) top.appendChild(x) return top else: x = self.dom.createElement('msup') x.appendChild(self.parenthesize(e.base, PRECEDENCE['Pow'])) x.appendChild(self._get_printed_Rational(e.exp, self._settings['fold_frac_powers'])) return x if e.exp.is_negative: top = self.dom.createElement('mfrac') top.appendChild(self._print(1)) if e.exp == -1: top.appendChild(self._print(e.base)) else: x = self.dom.createElement('msup') x.appendChild(self.parenthesize(e.base, PRECEDENCE['Pow'])) x.appendChild(self._print(-e.exp)) top.appendChild(x) return top x = self.dom.createElement('msup') x.appendChild(self.parenthesize(e.base, PRECEDENCE['Pow'])) x.appendChild(self._print(e.exp)) return x def _print_Number(self, e): x = self.dom.createElement(self.mathml_tag(e)) x.appendChild(self.dom.createTextNode(str(e))) return x def _print_AccumulationBounds(self, i): brac = self.dom.createElement('mfenced') brac.setAttribute('close', u'\u27e9') brac.setAttribute('open', u'\u27e8') brac.appendChild(self._print(i.min)) brac.appendChild(self._print(i.max)) return brac def _print_Derivative(self, e): if requires_partial(e.expr): d = '&#x2202;' else: d = self.mathml_tag(e) # Determine denominator m = self.dom.createElement('mrow') dim = 0 # Total diff dimension, for numerator for sym, num in reversed(e.variable_count): dim += num if num >= 2: x = self.dom.createElement('msup') xx = self.dom.createElement('mo') xx.appendChild(self.dom.createTextNode(d)) x.appendChild(xx) x.appendChild(self._print(num)) else: x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode(d)) m.appendChild(x) y = self._print(sym) m.appendChild(y) mnum = self.dom.createElement('mrow') if dim >= 2: x = self.dom.createElement('msup') xx = self.dom.createElement('mo') xx.appendChild(self.dom.createTextNode(d)) x.appendChild(xx) x.appendChild(self._print(dim)) else: x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode(d)) mnum.appendChild(x) mrow = self.dom.createElement('mrow') frac = self.dom.createElement('mfrac') frac.appendChild(mnum) frac.appendChild(m) mrow.appendChild(frac) # Print function mrow.appendChild(self._print(e.expr)) return mrow def _print_Function(self, e): mrow = self.dom.createElement('mrow') x = self.dom.createElement('mi') if self.mathml_tag(e) == 'log' and self._settings["ln_notation"]: x.appendChild(self.dom.createTextNode('ln')) else: x.appendChild(self.dom.createTextNode(self.mathml_tag(e))) y = self.dom.createElement('mfenced') for arg in e.args: y.appendChild(self._print(arg)) mrow.appendChild(x) mrow.appendChild(y) return mrow def _print_Float(self, expr): # Based off of that in StrPrinter dps = prec_to_dps(expr._prec) str_real = mlib.to_str(expr._mpf_, dps, strip_zeros=True) # Must always have a mul symbol (as 2.5 10^{20} just looks odd) # thus we use the number separator separator = self._settings['mul_symbol_mathml_numbers'] mrow = self.dom.createElement('mrow') if 'e' in str_real: (mant, exp) = str_real.split('e') if exp[0] == '+': exp = exp[1:] mn = self.dom.createElement('mn') mn.appendChild(self.dom.createTextNode(mant)) mrow.appendChild(mn) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode(separator)) mrow.appendChild(mo) msup = self.dom.createElement('msup') mn = self.dom.createElement('mn') mn.appendChild(self.dom.createTextNode("10")) msup.appendChild(mn) mn = self.dom.createElement('mn') mn.appendChild(self.dom.createTextNode(exp)) msup.appendChild(mn) mrow.appendChild(msup) return mrow elif str_real == "+inf": return self._print_Infinity(None) elif str_real == "-inf": return self._print_NegativeInfinity(None) else: mn = self.dom.createElement('mn') mn.appendChild(self.dom.createTextNode(str_real)) return mn def _print_polylog(self, expr): mrow = self.dom.createElement('mrow') m = self.dom.createElement('msub') mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode('Li')) m.appendChild(mi) m.appendChild(self._print(expr.args[0])) mrow.appendChild(m) brac = self.dom.createElement('mfenced') brac.appendChild(self._print(expr.args[1])) mrow.appendChild(brac) return mrow def _print_Basic(self, e): mrow = self.dom.createElement('mrow') mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode(self.mathml_tag(e))) mrow.appendChild(mi) brac = self.dom.createElement('mfenced') for arg in e.args: brac.appendChild(self._print(arg)) mrow.appendChild(brac) return mrow def _print_Tuple(self, e): mrow = self.dom.createElement('mrow') x = self.dom.createElement('mfenced') for arg in e.args: x.appendChild(self._print(arg)) mrow.appendChild(x) return mrow def _print_Interval(self, i): mrow = self.dom.createElement('mrow') brac = self.dom.createElement('mfenced') if i.start == i.end: # Most often, this type of Interval is converted to a FiniteSet brac.setAttribute('close', '}') brac.setAttribute('open', '{') brac.appendChild(self._print(i.start)) else: if i.right_open: brac.setAttribute('close', ')') else: brac.setAttribute('close', ']') if i.left_open: brac.setAttribute('open', '(') else: brac.setAttribute('open', '[') brac.appendChild(self._print(i.start)) brac.appendChild(self._print(i.end)) mrow.appendChild(brac) return mrow def _print_Abs(self, expr, exp=None): mrow = self.dom.createElement('mrow') x = self.dom.createElement('mfenced') x.setAttribute('close', '|') x.setAttribute('open', '|') x.appendChild(self._print(expr.args[0])) mrow.appendChild(x) return mrow _print_Determinant = _print_Abs def _print_re_im(self, c, expr): mrow = self.dom.createElement('mrow') mi = self.dom.createElement('mi') mi.setAttribute('mathvariant', 'fraktur') mi.appendChild(self.dom.createTextNode(c)) mrow.appendChild(mi) brac = self.dom.createElement('mfenced') brac.appendChild(self._print(expr)) mrow.appendChild(brac) return mrow def _print_re(self, expr, exp=None): return self._print_re_im('R', expr.args[0]) def _print_im(self, expr, exp=None): return self._print_re_im('I', expr.args[0]) def _print_AssocOp(self, e): mrow = self.dom.createElement('mrow') mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode(self.mathml_tag(e))) mrow.appendChild(mi) for arg in e.args: mrow.appendChild(self._print(arg)) return mrow def _print_SetOp(self, expr, symbol, prec): mrow = self.dom.createElement('mrow') mrow.appendChild(self.parenthesize(expr.args[0], prec)) for arg in expr.args[1:]: x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode(symbol)) y = self.parenthesize(arg, prec) mrow.appendChild(x) mrow.appendChild(y) return mrow def _print_Union(self, expr): prec = PRECEDENCE_TRADITIONAL['Union'] return self._print_SetOp(expr, '&#x222A;', prec) def _print_Intersection(self, expr): prec = PRECEDENCE_TRADITIONAL['Intersection'] return self._print_SetOp(expr, '&#x2229;', prec) def _print_Complement(self, expr): prec = PRECEDENCE_TRADITIONAL['Complement'] return self._print_SetOp(expr, '&#x2216;', prec) def _print_SymmetricDifference(self, expr): prec = PRECEDENCE_TRADITIONAL['SymmetricDifference'] return self._print_SetOp(expr, '&#x2206;', prec) def _print_ProductSet(self, expr): prec = PRECEDENCE_TRADITIONAL['ProductSet'] return self._print_SetOp(expr, '&#x00d7;', prec) def _print_FiniteSet(self, s): return self._print_set(s.args) def _print_set(self, s): items = sorted(s, key=default_sort_key) brac = self.dom.createElement('mfenced') brac.setAttribute('close', '}') brac.setAttribute('open', '{') for item in items: brac.appendChild(self._print(item)) return brac _print_frozenset = _print_set def _print_LogOp(self, args, symbol): mrow = self.dom.createElement('mrow') if args[0].is_Boolean and not args[0].is_Not: brac = self.dom.createElement('mfenced') brac.appendChild(self._print(args[0])) mrow.appendChild(brac) else: mrow.appendChild(self._print(args[0])) for arg in args[1:]: x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode(symbol)) if arg.is_Boolean and not arg.is_Not: y = self.dom.createElement('mfenced') y.appendChild(self._print(arg)) else: y = self._print(arg) mrow.appendChild(x) mrow.appendChild(y) return mrow def _print_BasisDependent(self, expr): from sympy.vector import Vector if expr == expr.zero: # Not clear if this is ever called return self._print(expr.zero) if isinstance(expr, Vector): items = expr.separate().items() else: items = [(0, expr)] mrow = self.dom.createElement('mrow') for system, vect in items: inneritems = list(vect.components.items()) inneritems.sort(key = lambda x:x[0].__str__()) for i, (k, v) in enumerate(inneritems): if v == 1: if i: # No + for first item mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('+')) mrow.appendChild(mo) mrow.appendChild(self._print(k)) elif v == -1: mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('-')) mrow.appendChild(mo) mrow.appendChild(self._print(k)) else: if i: # No + for first item mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('+')) mrow.appendChild(mo) mbrac = self.dom.createElement('mfenced') mbrac.appendChild(self._print(v)) mrow.appendChild(mbrac) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&InvisibleTimes;')) mrow.appendChild(mo) mrow.appendChild(self._print(k)) return mrow def _print_And(self, expr): args = sorted(expr.args, key=default_sort_key) return self._print_LogOp(args, '&#x2227;') def _print_Or(self, expr): args = sorted(expr.args, key=default_sort_key) return self._print_LogOp(args, '&#x2228;') def _print_Xor(self, expr): args = sorted(expr.args, key=default_sort_key) return self._print_LogOp(args, '&#x22BB;') def _print_Implies(self, expr): return self._print_LogOp(expr.args, '&#x21D2;') def _print_Equivalent(self, expr): args = sorted(expr.args, key=default_sort_key) return self._print_LogOp(args, '&#x21D4;') def _print_Not(self, e): mrow = self.dom.createElement('mrow') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#xAC;')) mrow.appendChild(mo) if (e.args[0].is_Boolean): x = self.dom.createElement('mfenced') x.appendChild(self._print(e.args[0])) else: x = self._print(e.args[0]) mrow.appendChild(x) return mrow def _print_bool(self, e): mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode(self.mathml_tag(e))) return mi _print_BooleanTrue = _print_bool _print_BooleanFalse = _print_bool def _print_NoneType(self, e): mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode(self.mathml_tag(e))) return mi def _print_Range(self, s): dots = u"\u2026" brac = self.dom.createElement('mfenced') brac.setAttribute('close', '}') brac.setAttribute('open', '{') if s.start.is_infinite and s.stop.is_infinite: if s.step.is_positive: printset = dots, -1, 0, 1, dots else: printset = dots, 1, 0, -1, dots elif s.start.is_infinite: printset = dots, s[-1] - s.step, s[-1] elif s.stop.is_infinite: it = iter(s) printset = next(it), next(it), dots elif len(s) > 4: it = iter(s) printset = next(it), next(it), dots, s[-1] else: printset = tuple(s) for el in printset: if el == dots: mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode(dots)) brac.appendChild(mi) else: brac.appendChild(self._print(el)) return brac def _hprint_variadic_function(self, expr): args = sorted(expr.args, key=default_sort_key) mrow = self.dom.createElement('mrow') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode((str(expr.func)).lower())) mrow.appendChild(mo) brac = self.dom.createElement('mfenced') for symbol in args: brac.appendChild(self._print(symbol)) mrow.appendChild(brac) return mrow _print_Min = _print_Max = _hprint_variadic_function def _print_exp(self, expr): msup = self.dom.createElement('msup') msup.appendChild(self._print_Exp1(None)) msup.appendChild(self._print(expr.args[0])) return msup def _print_Relational(self, e): mrow = self.dom.createElement('mrow') mrow.appendChild(self._print(e.lhs)) x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode(self.mathml_tag(e))) mrow.appendChild(x) mrow.appendChild(self._print(e.rhs)) return mrow def _print_int(self, p): dom_element = self.dom.createElement(self.mathml_tag(p)) dom_element.appendChild(self.dom.createTextNode(str(p))) return dom_element def _print_BaseScalar(self, e): msub = self.dom.createElement('msub') index, system = e._id mi = self.dom.createElement('mi') mi.setAttribute('mathvariant', 'bold') mi.appendChild(self.dom.createTextNode(system._variable_names[index])) msub.appendChild(mi) mi = self.dom.createElement('mi') mi.setAttribute('mathvariant', 'bold') mi.appendChild(self.dom.createTextNode(system._name)) msub.appendChild(mi) return msub def _print_BaseVector(self, e): msub = self.dom.createElement('msub') index, system = e._id mover = self.dom.createElement('mover') mi = self.dom.createElement('mi') mi.setAttribute('mathvariant', 'bold') mi.appendChild(self.dom.createTextNode(system._vector_names[index])) mover.appendChild(mi) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('^')) mover.appendChild(mo) msub.appendChild(mover) mi = self.dom.createElement('mi') mi.setAttribute('mathvariant', 'bold') mi.appendChild(self.dom.createTextNode(system._name)) msub.appendChild(mi) return msub def _print_VectorZero(self, e): mover = self.dom.createElement('mover') mi = self.dom.createElement('mi') mi.setAttribute('mathvariant', 'bold') mi.appendChild(self.dom.createTextNode("0")) mover.appendChild(mi) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('^')) mover.appendChild(mo) return mover def _print_Cross(self, expr): mrow = self.dom.createElement('mrow') vec1 = expr._expr1 vec2 = expr._expr2 mrow.appendChild(self.parenthesize(vec1, PRECEDENCE['Mul'])) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#xD7;')) mrow.appendChild(mo) mrow.appendChild(self.parenthesize(vec2, PRECEDENCE['Mul'])) return mrow def _print_Curl(self, expr): mrow = self.dom.createElement('mrow') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#x2207;')) mrow.appendChild(mo) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#xD7;')) mrow.appendChild(mo) mrow.appendChild(self.parenthesize(expr._expr, PRECEDENCE['Mul'])) return mrow def _print_Divergence(self, expr): mrow = self.dom.createElement('mrow') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#x2207;')) mrow.appendChild(mo) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#xB7;')) mrow.appendChild(mo) mrow.appendChild(self.parenthesize(expr._expr, PRECEDENCE['Mul'])) return mrow def _print_Dot(self, expr): mrow = self.dom.createElement('mrow') vec1 = expr._expr1 vec2 = expr._expr2 mrow.appendChild(self.parenthesize(vec1, PRECEDENCE['Mul'])) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#xB7;')) mrow.appendChild(mo) mrow.appendChild(self.parenthesize(vec2, PRECEDENCE['Mul'])) return mrow def _print_Gradient(self, expr): mrow = self.dom.createElement('mrow') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#x2207;')) mrow.appendChild(mo) mrow.appendChild(self.parenthesize(expr._expr, PRECEDENCE['Mul'])) return mrow def _print_Laplacian(self, expr): mrow = self.dom.createElement('mrow') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#x2206;')) mrow.appendChild(mo) mrow.appendChild(self.parenthesize(expr._expr, PRECEDENCE['Mul'])) return mrow def _print_Integers(self, e): x = self.dom.createElement('mi') x.setAttribute('mathvariant', 'normal') x.appendChild(self.dom.createTextNode('&#x2124;')) return x def _print_Complexes(self, e): x = self.dom.createElement('mi') x.setAttribute('mathvariant', 'normal') x.appendChild(self.dom.createTextNode('&#x2102;')) return x def _print_Reals(self, e): x = self.dom.createElement('mi') x.setAttribute('mathvariant', 'normal') x.appendChild(self.dom.createTextNode('&#x211D;')) return x def _print_Naturals(self, e): x = self.dom.createElement('mi') x.setAttribute('mathvariant', 'normal') x.appendChild(self.dom.createTextNode('&#x2115;')) return x def _print_Naturals0(self, e): sub = self.dom.createElement('msub') x = self.dom.createElement('mi') x.setAttribute('mathvariant', 'normal') x.appendChild(self.dom.createTextNode('&#x2115;')) sub.appendChild(x) sub.appendChild(self._print(S.Zero)) return sub def _print_SingularityFunction(self, expr): shift = expr.args[0] - expr.args[1] power = expr.args[2] sup = self.dom.createElement('msup') brac = self.dom.createElement('mfenced') brac.setAttribute('close', u'\u27e9') brac.setAttribute('open', u'\u27e8') brac.appendChild(self._print(shift)) sup.appendChild(brac) sup.appendChild(self._print(power)) return sup def _print_NaN(self, e): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('NaN')) return x def _print_number_function(self, e, name): # Print name_arg[0] for one argument or name_arg[0](arg[1]) # for more than one argument sub = self.dom.createElement('msub') mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode(name)) sub.appendChild(mi) sub.appendChild(self._print(e.args[0])) if len(e.args) == 1: return sub # TODO: copy-pasted from _print_Function: can we do better? mrow = self.dom.createElement('mrow') y = self.dom.createElement('mfenced') for arg in e.args[1:]: y.appendChild(self._print(arg)) mrow.appendChild(sub) mrow.appendChild(y) return mrow def _print_bernoulli(self, e): return self._print_number_function(e, 'B') _print_bell = _print_bernoulli def _print_catalan(self, e): return self._print_number_function(e, 'C') def _print_euler(self, e): return self._print_number_function(e, 'E') def _print_fibonacci(self, e): return self._print_number_function(e, 'F') def _print_lucas(self, e): return self._print_number_function(e, 'L') def _print_stieltjes(self, e): return self._print_number_function(e, '&#x03B3;') def _print_tribonacci(self, e): return self._print_number_function(e, 'T') def _print_ComplexInfinity(self, e): x = self.dom.createElement('mover') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#x221E;')) x.appendChild(mo) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('~')) x.appendChild(mo) return x def _print_EmptySet(self, e): x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode('&#x2205;')) return x def _print_UniversalSet(self, e): x = self.dom.createElement('mo') x.appendChild(self.dom.createTextNode('&#x1D54C;')) return x def _print_Adjoint(self, expr): from sympy.matrices import MatrixSymbol mat = expr.arg sup = self.dom.createElement('msup') if not isinstance(mat, MatrixSymbol): brac = self.dom.createElement('mfenced') brac.appendChild(self._print(mat)) sup.appendChild(brac) else: sup.appendChild(self._print(mat)) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#x2020;')) sup.appendChild(mo) return sup def _print_Transpose(self, expr): from sympy.matrices import MatrixSymbol mat = expr.arg sup = self.dom.createElement('msup') if not isinstance(mat, MatrixSymbol): brac = self.dom.createElement('mfenced') brac.appendChild(self._print(mat)) sup.appendChild(brac) else: sup.appendChild(self._print(mat)) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('T')) sup.appendChild(mo) return sup def _print_Inverse(self, expr): from sympy.matrices import MatrixSymbol mat = expr.arg sup = self.dom.createElement('msup') if not isinstance(mat, MatrixSymbol): brac = self.dom.createElement('mfenced') brac.appendChild(self._print(mat)) sup.appendChild(brac) else: sup.appendChild(self._print(mat)) sup.appendChild(self._print(-1)) return sup def _print_MatMul(self, expr): from sympy import MatMul x = self.dom.createElement('mrow') args = expr.args if isinstance(args[0], Mul): args = args[0].as_ordered_factors() + list(args[1:]) else: args = list(args) if isinstance(expr, MatMul) and _coeff_isneg(expr): if args[0] == -1: args = args[1:] else: args[0] = -args[0] mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('-')) x.appendChild(mo) for arg in args[:-1]: x.appendChild(self.parenthesize(arg, precedence_traditional(expr), False)) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&InvisibleTimes;')) x.appendChild(mo) x.appendChild(self.parenthesize(args[-1], precedence_traditional(expr), False)) return x def _print_MatPow(self, expr): from sympy.matrices import MatrixSymbol base, exp = expr.base, expr.exp sup = self.dom.createElement('msup') if not isinstance(base, MatrixSymbol): brac = self.dom.createElement('mfenced') brac.appendChild(self._print(base)) sup.appendChild(brac) else: sup.appendChild(self._print(base)) sup.appendChild(self._print(exp)) return sup def _print_HadamardProduct(self, expr): x = self.dom.createElement('mrow') args = expr.args for arg in args[:-1]: x.appendChild( self.parenthesize(arg, precedence_traditional(expr), False)) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#x2218;')) x.appendChild(mo) x.appendChild( self.parenthesize(args[-1], precedence_traditional(expr), False)) return x def _print_ZeroMatrix(self, Z): x = self.dom.createElement('mn') x.appendChild(self.dom.createTextNode('&#x1D7D8')) return x def _print_OneMatrix(self, Z): x = self.dom.createElement('mn') x.appendChild(self.dom.createTextNode('&#x1D7D9')) return x def _print_Identity(self, I): x = self.dom.createElement('mi') x.appendChild(self.dom.createTextNode('&#x1D540;')) return x def _print_floor(self, e): mrow = self.dom.createElement('mrow') x = self.dom.createElement('mfenced') x.setAttribute('close', u'\u230B') x.setAttribute('open', u'\u230A') x.appendChild(self._print(e.args[0])) mrow.appendChild(x) return mrow def _print_ceiling(self, e): mrow = self.dom.createElement('mrow') x = self.dom.createElement('mfenced') x.setAttribute('close', u'\u2309') x.setAttribute('open', u'\u2308') x.appendChild(self._print(e.args[0])) mrow.appendChild(x) return mrow def _print_Lambda(self, e): x = self.dom.createElement('mfenced') mrow = self.dom.createElement('mrow') symbols = e.args[0] if len(symbols) == 1: symbols = self._print(symbols[0]) else: symbols = self._print(symbols) mrow.appendChild(symbols) mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('&#x21A6;')) mrow.appendChild(mo) mrow.appendChild(self._print(e.args[1])) x.appendChild(mrow) return x def _print_tuple(self, e): x = self.dom.createElement('mfenced') for i in e: x.appendChild(self._print(i)) return x def _print_IndexedBase(self, e): return self._print(e.label) def _print_Indexed(self, e): x = self.dom.createElement('msub') x.appendChild(self._print(e.base)) if len(e.indices) == 1: x.appendChild(self._print(e.indices[0])) return x x.appendChild(self._print(e.indices)) return x def _print_MatrixElement(self, e): x = self.dom.createElement('msub') x.appendChild(self.parenthesize(e.parent, PRECEDENCE["Atom"], strict = True)) brac = self.dom.createElement('mfenced') brac.setAttribute("close", "") brac.setAttribute("open", "") for i in e.indices: brac.appendChild(self._print(i)) x.appendChild(brac) return x def _print_elliptic_f(self, e): x = self.dom.createElement('mrow') mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode('&#x1d5a5;')) x.appendChild(mi) y = self.dom.createElement('mfenced') y.setAttribute("separators", "|") for i in e.args: y.appendChild(self._print(i)) x.appendChild(y) return x def _print_elliptic_e(self, e): x = self.dom.createElement('mrow') mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode('&#x1d5a4;')) x.appendChild(mi) y = self.dom.createElement('mfenced') y.setAttribute("separators", "|") for i in e.args: y.appendChild(self._print(i)) x.appendChild(y) return x def _print_elliptic_pi(self, e): x = self.dom.createElement('mrow') mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode('&#x1d6f1;')) x.appendChild(mi) y = self.dom.createElement('mfenced') if len(e.args) == 2: y.setAttribute("separators", "|") else: y.setAttribute("separators", ";|") for i in e.args: y.appendChild(self._print(i)) x.appendChild(y) return x def _print_Ei(self, e): x = self.dom.createElement('mrow') mi = self.dom.createElement('mi') mi.appendChild(self.dom.createTextNode('Ei')) x.appendChild(mi) x.appendChild(self._print(e.args)) return x def _print_expint(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msub') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('E')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) x.appendChild(y) x.appendChild(self._print(e.args[1:])) return x def _print_jacobi(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msubsup') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('P')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) y.appendChild(self._print(e.args[1:3])) x.appendChild(y) x.appendChild(self._print(e.args[3:])) return x def _print_gegenbauer(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msubsup') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('C')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) y.appendChild(self._print(e.args[1:2])) x.appendChild(y) x.appendChild(self._print(e.args[2:])) return x def _print_chebyshevt(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msub') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('T')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) x.appendChild(y) x.appendChild(self._print(e.args[1:])) return x def _print_chebyshevu(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msub') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('U')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) x.appendChild(y) x.appendChild(self._print(e.args[1:])) return x def _print_legendre(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msub') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('P')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) x.appendChild(y) x.appendChild(self._print(e.args[1:])) return x def _print_assoc_legendre(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msubsup') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('P')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) y.appendChild(self._print(e.args[1:2])) x.appendChild(y) x.appendChild(self._print(e.args[2:])) return x def _print_laguerre(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msub') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('L')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) x.appendChild(y) x.appendChild(self._print(e.args[1:])) return x def _print_assoc_laguerre(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msubsup') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('L')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) y.appendChild(self._print(e.args[1:2])) x.appendChild(y) x.appendChild(self._print(e.args[2:])) return x def _print_hermite(self, e): x = self.dom.createElement('mrow') y = self.dom.createElement('msub') mo = self.dom.createElement('mo') mo.appendChild(self.dom.createTextNode('H')) y.appendChild(mo) y.appendChild(self._print(e.args[0])) x.appendChild(y) x.appendChild(self._print(e.args[1:])) return x def mathml(expr, printer='content', **settings): """Returns the MathML representation of expr. If printer is presentation then prints Presentation MathML else prints content MathML. """ if printer == 'presentation': return MathMLPresentationPrinter(settings).doprint(expr) else: return MathMLContentPrinter(settings).doprint(expr) def print_mathml(expr, printer='content', **settings): """ Prints a pretty representation of the MathML code for expr. If printer is presentation then prints Presentation MathML else prints content MathML. Examples ======== >>> ## >>> from sympy.printing.mathml import print_mathml >>> from sympy.abc import x >>> print_mathml(x+1) #doctest: +NORMALIZE_WHITESPACE <apply> <plus/> <ci>x</ci> <cn>1</cn> </apply> >>> print_mathml(x+1, printer='presentation') <mrow> <mi>x</mi> <mo>+</mo> <mn>1</mn> </mrow> """ if printer == 'presentation': s = MathMLPresentationPrinter(settings) else: s = MathMLContentPrinter(settings) xml = s._print(sympify(expr)) s.apply_patch() pretty_xml = xml.toprettyxml() s.restore_patch() print(pretty_xml) # For backward compatibility MathMLPrinter = MathMLContentPrinter
bsd-3-clause
[ 624, 199, 33, 21066, 1698, 16639, 14, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 12, 4629, 199, 199, 504, 5840, 492, 25991, 12, 428, 12, 22578, 199, 504, 5840, 14, 1018, 14, 15390, 492, 1425, 12, 1059, 63, 1313, 12, 849, 63, 3191, 63, 498, 199, 504, 5840, 14, 1018, 14, 1593, 492, 485, 8903, 63, 374, 8705, 199, 504, 5840, 14, 26514, 14, 388, 1856, 852, 492, 3715, 63, 4792, 63, 954, 12, 5074, 63, 6672, 199, 504, 5840, 14, 26514, 14, 19571, 492, 971, 272, 13823, 63, 1239, 2603, 12, 510, 9481, 1149, 6013, 12, 510, 9481, 1149, 6013, 63, 1766, 1554, 12039, 748, 199, 504, 5840, 14, 26514, 14, 9118, 14, 9118, 63, 3840, 656, 4956, 492, 30529, 63, 2975, 199, 504, 5840, 14, 26514, 14, 11835, 492, 25716, 1058, 199, 199, 646, 6118, 3442, 14, 773, 311, 465, 333, 773, 199, 504, 6118, 3442, 14, 773, 311, 492, 13826, 63, 475, 63, 30168, 421, 199, 533, 21066, 1698, 14131, 1563, 8, 14131, 304, 272, 408, 6906, 2863, 1233, 1415, 367, 21066, 1698, 2714, 14131, 436, 272, 21066, 1698, 19794, 425, 14131, 14, 272, 408, 339, 485, 885, 63, 1751, 275, 469, 267, 298, 1648, 582, 488, 12, 267, 298, 2991, 582, 298, 1624, 13, 24, 401, 267, 298, 14011, 63, 10865, 63, 8278, 1192, 582, 756, 12, 267, 298, 14011, 63, 1532, 63, 14594, 83, 582, 756, 12, 267, 298, 14011, 63, 3612, 63, 10865, 582, 488, 12, 267, 298, 5350, 63, 599, 71, 63, 2487, 582, 298, 371, 23988, 972, 401, 267, 298, 6066, 63, 12251, 582, 756, 12, 267, 298, 2809, 63, 10865, 63, 6884, 582, 488, 12, 267, 298, 569, 63, 15966, 582, 7369, 401, 267, 298, 569, 63, 5155, 63, 2487, 582, 298, 6104, 401, 267, 298, 3703, 63, 5155, 582, 488, 12, 267, 298, 1231, 63, 12251, 582, 715, 12, 267, 298, 5155, 63, 1247, 582, 5479, 267, 298, 3703, 63, 5155, 63, 27595, 63, 10548, 582, 7673, 3, 8094, 23, 10805, 272, 789, 339, 347, 636, 826, 721, 277, 12, 2202, 29, 403, 304, 267, 25716, 1058, 855, 826, 721, 277, 12, 2202, 9, 267, 687, 2748, 14, 4556, 14, 21827, 492, 7543, 12, 4516, 398, 291, 14, 4556, 275, 7543, 342, 398, 327, 9361, 11659, 370, 2040, 3326, 370, 5706, 625, 13572, 267, 327, 21311, 641, 267, 327, 4178, 921, 23153, 14, 957, 15, 16069, 15, 1703, 614, 2010, 772, 15, 1548, 13, 1652, 13, 4556, 13, 21827, 2696, 267, 327, 19242, 8749, 13, 18671, 13, 3765, 13, 1662, 13, 5465, 15, 1703, 32473, 2635, 267, 1021, 13480, 1872, 8, 1872, 304, 288, 347, 2218, 1652, 8, 277, 12, 7060, 12, 4363, 4581, 1050, 3724, 4581, 892, 76, 9280, 355, 340, 291, 14, 576, 26, 490, 7060, 14, 952, 8, 85, 7, 2440, 2440, 11123, 908, 8, 3724, 12, 291, 14, 576, 12, 892, 76, 430, 398, 347, 1218, 7963, 32540, 8, 576, 304, 288, 519, 275, 13480, 1872, 342, 288, 519, 14, 576, 275, 666, 288, 519, 14, 30518, 275, 291, 14, 4556, 288, 372, 519, 398, 291, 14, 4556, 14, 981, 32540, 275, 1218, 7963, 32540, 339, 347, 366, 411, 672, 8, 277, 12, 5348, 304, 267, 408, 267, 9101, 83, 314, 3965, 465, 21066, 1698, 14, 267, 408, 267, 3473, 1698, 275, 25716, 1058, 423, 1361, 8, 277, 12, 5348, 9, 267, 625, 3075, 275, 3473, 1698, 14, 475, 1652, 342, 267, 2748, 66, 495, 275, 625, 3075, 14, 2143, 360, 4371, 297, 283, 1652, 24253, 1814, 358, 267, 522, 275, 2748, 66, 495, 14, 2708, 342, 267, 372, 522, 339, 347, 4838, 63, 2068, 8, 277, 304, 267, 327, 4693, 6670, 314, 3371, 402, 2748, 14, 4556, 14, 21827, 6519, 267, 327, 6148, 26, 7760, 13, 845, 13, 1085, 267, 327, 11994, 26, 1455, 921, 2641, 293, 273, 1237, 14, 957, 15, 3455, 15, 3039, 66, 1312, 379, 15, 1652, 13, 4556, 13, 21827, 60, 267, 327, 7861, 446, 2119, 21958, 1652, 13, 460, 13, 20329, 590, 13, 8506, 12645, 7010, 13, 14458, 267, 327, 13383, 26, 1455, 921, 13017, 14, 1548, 14, 1308, 15, 5237, 20, 11160, 267, 327, 19292, 26, 1455, 921, 9208, 14, 1548, 14, 1308, 15, 67, 1548, 15, 4964, 15, 23, 14820, 70, 24, 70, 13319, 556, 15, 398, 687, 2748, 14, 4556, 14, 21827, 492, 6566, 12, 4516, 12, 5013, 12, 485, 952, 63, 576, 398, 347, 2218, 1652, 8, 277, 12, 7060, 12, 4363, 8772, 1050, 3724, 8772, 892, 76, 17364, 288, 327, 4363, 275, 1453, 14311, 288, 327, 1050, 3724, 275, 14311, 370, 1050, 370, 10948, 11106, 288, 327, 892, 76, 275, 8057, 1059, 288, 7060, 14, 952, 8, 3724, 435, 3886, 2, 435, 291, 14, 20183, 9, 953, 3290, 275, 291, 423, 362, 63, 2987, 342, 288, 282, 63, 1247, 275, 769, 8, 3288, 14, 1612, 1012, 288, 282, 63, 1247, 14, 3191, 342, 953, 367, 282, 63, 354, 315, 282, 63, 1247, 26, 355, 7060, 14, 952, 480, 450, 83, 9529, 341, 450, 282, 63, 354, 9, 355, 485, 952, 63, 576, 8, 5491, 12, 3290, 59, 65, 63, 354, 1055, 585, 9, 355, 7060, 14, 952, 4582, 7230, 288, 340, 291, 14, 10626, 26, 355, 7060, 14, 952, 480, 9579, 355, 340, 334, 552, 8, 277, 14, 10626, 9, 508, 413, 436, 717, 291, 14, 10626, 59, 16, 1055, 12412, 508, 5013, 14, 3876, 63, 8063, 304, 490, 291, 14, 10626, 59, 16, 1055, 952, 1652, 8, 5491, 12, 3260, 3260, 4074, 355, 587, 26, 490, 7060, 14, 952, 8, 1222, 76, 9, 490, 367, 1031, 315, 291, 14, 10626, 26, 717, 1031, 14, 952, 1652, 8, 1169, 7060, 12, 4363, 435, 1050, 3724, 12, 1050, 3724, 12, 892, 76, 9, 490, 7060, 14, 952, 8, 3724, 9, 355, 7060, 14, 952, 23790, 5, 83, 6598, 83, 2, 450, 334, 277, 14, 20183, 12, 892, 76, 430, 288, 587, 26, 355, 7060, 14, 952, 480, 3133, 5, 83, 2, 450, 334, 1222, 76, 430, 267, 291, 423, 2162, 63, 952, 1652, 63, 1753, 275, 6566, 14, 952, 1652, 267, 6566, 14, 952, 1652, 275, 2218, 1652, 398, 347, 2218, 1652, 8, 277, 12 ]
[ 199, 33, 21066, 1698, 16639, 14, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 12, 4629, 199, 199, 504, 5840, 492, 25991, 12, 428, 12, 22578, 199, 504, 5840, 14, 1018, 14, 15390, 492, 1425, 12, 1059, 63, 1313, 12, 849, 63, 3191, 63, 498, 199, 504, 5840, 14, 1018, 14, 1593, 492, 485, 8903, 63, 374, 8705, 199, 504, 5840, 14, 26514, 14, 388, 1856, 852, 492, 3715, 63, 4792, 63, 954, 12, 5074, 63, 6672, 199, 504, 5840, 14, 26514, 14, 19571, 492, 971, 272, 13823, 63, 1239, 2603, 12, 510, 9481, 1149, 6013, 12, 510, 9481, 1149, 6013, 63, 1766, 1554, 12039, 748, 199, 504, 5840, 14, 26514, 14, 9118, 14, 9118, 63, 3840, 656, 4956, 492, 30529, 63, 2975, 199, 504, 5840, 14, 26514, 14, 11835, 492, 25716, 1058, 199, 199, 646, 6118, 3442, 14, 773, 311, 465, 333, 773, 199, 504, 6118, 3442, 14, 773, 311, 492, 13826, 63, 475, 63, 30168, 421, 199, 533, 21066, 1698, 14131, 1563, 8, 14131, 304, 272, 408, 6906, 2863, 1233, 1415, 367, 21066, 1698, 2714, 14131, 436, 272, 21066, 1698, 19794, 425, 14131, 14, 272, 408, 339, 485, 885, 63, 1751, 275, 469, 267, 298, 1648, 582, 488, 12, 267, 298, 2991, 582, 298, 1624, 13, 24, 401, 267, 298, 14011, 63, 10865, 63, 8278, 1192, 582, 756, 12, 267, 298, 14011, 63, 1532, 63, 14594, 83, 582, 756, 12, 267, 298, 14011, 63, 3612, 63, 10865, 582, 488, 12, 267, 298, 5350, 63, 599, 71, 63, 2487, 582, 298, 371, 23988, 972, 401, 267, 298, 6066, 63, 12251, 582, 756, 12, 267, 298, 2809, 63, 10865, 63, 6884, 582, 488, 12, 267, 298, 569, 63, 15966, 582, 7369, 401, 267, 298, 569, 63, 5155, 63, 2487, 582, 298, 6104, 401, 267, 298, 3703, 63, 5155, 582, 488, 12, 267, 298, 1231, 63, 12251, 582, 715, 12, 267, 298, 5155, 63, 1247, 582, 5479, 267, 298, 3703, 63, 5155, 63, 27595, 63, 10548, 582, 7673, 3, 8094, 23, 10805, 272, 789, 339, 347, 636, 826, 721, 277, 12, 2202, 29, 403, 304, 267, 25716, 1058, 855, 826, 721, 277, 12, 2202, 9, 267, 687, 2748, 14, 4556, 14, 21827, 492, 7543, 12, 4516, 398, 291, 14, 4556, 275, 7543, 342, 398, 327, 9361, 11659, 370, 2040, 3326, 370, 5706, 625, 13572, 267, 327, 21311, 641, 267, 327, 4178, 921, 23153, 14, 957, 15, 16069, 15, 1703, 614, 2010, 772, 15, 1548, 13, 1652, 13, 4556, 13, 21827, 2696, 267, 327, 19242, 8749, 13, 18671, 13, 3765, 13, 1662, 13, 5465, 15, 1703, 32473, 2635, 267, 1021, 13480, 1872, 8, 1872, 304, 288, 347, 2218, 1652, 8, 277, 12, 7060, 12, 4363, 4581, 1050, 3724, 4581, 892, 76, 9280, 355, 340, 291, 14, 576, 26, 490, 7060, 14, 952, 8, 85, 7, 2440, 2440, 11123, 908, 8, 3724, 12, 291, 14, 576, 12, 892, 76, 430, 398, 347, 1218, 7963, 32540, 8, 576, 304, 288, 519, 275, 13480, 1872, 342, 288, 519, 14, 576, 275, 666, 288, 519, 14, 30518, 275, 291, 14, 4556, 288, 372, 519, 398, 291, 14, 4556, 14, 981, 32540, 275, 1218, 7963, 32540, 339, 347, 366, 411, 672, 8, 277, 12, 5348, 304, 267, 408, 267, 9101, 83, 314, 3965, 465, 21066, 1698, 14, 267, 408, 267, 3473, 1698, 275, 25716, 1058, 423, 1361, 8, 277, 12, 5348, 9, 267, 625, 3075, 275, 3473, 1698, 14, 475, 1652, 342, 267, 2748, 66, 495, 275, 625, 3075, 14, 2143, 360, 4371, 297, 283, 1652, 24253, 1814, 358, 267, 522, 275, 2748, 66, 495, 14, 2708, 342, 267, 372, 522, 339, 347, 4838, 63, 2068, 8, 277, 304, 267, 327, 4693, 6670, 314, 3371, 402, 2748, 14, 4556, 14, 21827, 6519, 267, 327, 6148, 26, 7760, 13, 845, 13, 1085, 267, 327, 11994, 26, 1455, 921, 2641, 293, 273, 1237, 14, 957, 15, 3455, 15, 3039, 66, 1312, 379, 15, 1652, 13, 4556, 13, 21827, 60, 267, 327, 7861, 446, 2119, 21958, 1652, 13, 460, 13, 20329, 590, 13, 8506, 12645, 7010, 13, 14458, 267, 327, 13383, 26, 1455, 921, 13017, 14, 1548, 14, 1308, 15, 5237, 20, 11160, 267, 327, 19292, 26, 1455, 921, 9208, 14, 1548, 14, 1308, 15, 67, 1548, 15, 4964, 15, 23, 14820, 70, 24, 70, 13319, 556, 15, 398, 687, 2748, 14, 4556, 14, 21827, 492, 6566, 12, 4516, 12, 5013, 12, 485, 952, 63, 576, 398, 347, 2218, 1652, 8, 277, 12, 7060, 12, 4363, 8772, 1050, 3724, 8772, 892, 76, 17364, 288, 327, 4363, 275, 1453, 14311, 288, 327, 1050, 3724, 275, 14311, 370, 1050, 370, 10948, 11106, 288, 327, 892, 76, 275, 8057, 1059, 288, 7060, 14, 952, 8, 3724, 435, 3886, 2, 435, 291, 14, 20183, 9, 953, 3290, 275, 291, 423, 362, 63, 2987, 342, 288, 282, 63, 1247, 275, 769, 8, 3288, 14, 1612, 1012, 288, 282, 63, 1247, 14, 3191, 342, 953, 367, 282, 63, 354, 315, 282, 63, 1247, 26, 355, 7060, 14, 952, 480, 450, 83, 9529, 341, 450, 282, 63, 354, 9, 355, 485, 952, 63, 576, 8, 5491, 12, 3290, 59, 65, 63, 354, 1055, 585, 9, 355, 7060, 14, 952, 4582, 7230, 288, 340, 291, 14, 10626, 26, 355, 7060, 14, 952, 480, 9579, 355, 340, 334, 552, 8, 277, 14, 10626, 9, 508, 413, 436, 717, 291, 14, 10626, 59, 16, 1055, 12412, 508, 5013, 14, 3876, 63, 8063, 304, 490, 291, 14, 10626, 59, 16, 1055, 952, 1652, 8, 5491, 12, 3260, 3260, 4074, 355, 587, 26, 490, 7060, 14, 952, 8, 1222, 76, 9, 490, 367, 1031, 315, 291, 14, 10626, 26, 717, 1031, 14, 952, 1652, 8, 1169, 7060, 12, 4363, 435, 1050, 3724, 12, 1050, 3724, 12, 892, 76, 9, 490, 7060, 14, 952, 8, 3724, 9, 355, 7060, 14, 952, 23790, 5, 83, 6598, 83, 2, 450, 334, 277, 14, 20183, 12, 892, 76, 430, 288, 587, 26, 355, 7060, 14, 952, 480, 3133, 5, 83, 2, 450, 334, 1222, 76, 430, 267, 291, 423, 2162, 63, 952, 1652, 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 ]
bright-sparks/chromium-spacewalk
build/android/buildbot/bb_host_steps.py
45
4630
#!/usr/bin/env python # Copyright 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import os import sys import bb_utils import bb_annotations sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from pylib import constants SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave') VALID_HOST_TESTS = set(['check_webview_licenses', 'findbugs']) DIR_BUILD_ROOT = os.path.dirname(constants.DIR_SOURCE_ROOT) # Short hand for RunCmd which is used extensively in this file. RunCmd = bb_utils.RunCmd def SrcPath(*path): return os.path.join(constants.DIR_SOURCE_ROOT, *path) def CheckWebViewLicenses(_): bb_annotations.PrintNamedStep('check_licenses') RunCmd([SrcPath('android_webview', 'tools', 'webview_licenses.py'), 'scan'], warning_code=1) def RunHooks(build_type): RunCmd([SrcPath('build', 'landmines.py')]) build_path = SrcPath('out', build_type) landmine_path = os.path.join(build_path, '.landmines_triggered') clobber_env = os.environ.get('BUILDBOT_CLOBBER') if clobber_env or os.path.isfile(landmine_path): bb_annotations.PrintNamedStep('Clobber') if not clobber_env: print 'Clobbering due to triggered landmines:' with open(landmine_path) as f: print f.read() RunCmd(['rm', '-rf', build_path]) bb_annotations.PrintNamedStep('runhooks') RunCmd(['gclient', 'runhooks'], halt_on_failure=True) def Compile(options): RunHooks(options.target) cmd = [os.path.join(SLAVE_SCRIPTS_DIR, 'compile.py'), '--build-tool=ninja', '--compiler=goma', '--target=%s' % options.target, '--goma-dir=%s' % bb_utils.GOMA_DIR] bb_annotations.PrintNamedStep('compile') if options.build_targets: build_targets = options.build_targets.split(',') cmd += ['--build-args', ' '.join(build_targets)] RunCmd(cmd, halt_on_failure=True, cwd=DIR_BUILD_ROOT) def ZipBuild(options): bb_annotations.PrintNamedStep('zip_build') RunCmd([ os.path.join(SLAVE_SCRIPTS_DIR, 'zip_build.py'), '--src-dir', constants.DIR_SOURCE_ROOT, '--exclude-files', 'lib.target,gen,android_webview,jingle_unittests'] + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT) def ExtractBuild(options): bb_annotations.PrintNamedStep('extract_build') RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'extract_build.py')] + bb_utils.EncodeProperties(options), cwd=DIR_BUILD_ROOT) def FindBugs(options): bb_annotations.PrintNamedStep('findbugs') build_type = [] if options.target == 'Release': build_type = ['--release-build'] RunCmd([SrcPath('build', 'android', 'findbugs_diff.py')] + build_type) RunCmd([SrcPath( 'tools', 'android', 'findbugs_plugin', 'test', 'run_findbugs_plugin_tests.py')] + build_type) def BisectPerfRegression(options): args = [] if options.extra_src: args = ['--extra_src', options.extra_src] RunCmd([SrcPath('tools', 'prepare-bisect-perf-regression.py'), '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)]) RunCmd([SrcPath('tools', 'run-bisect-perf-regression.py'), '-w', os.path.join(constants.DIR_SOURCE_ROOT, os.pardir)] + args) def GetHostStepCmds(): return [ ('compile', Compile), ('extract_build', ExtractBuild), ('check_webview_licenses', CheckWebViewLicenses), ('bisect_perf_regression', BisectPerfRegression), ('findbugs', FindBugs), ('zip_build', ZipBuild) ] def GetHostStepsOptParser(): parser = bb_utils.GetParser() parser.add_option('--steps', help='Comma separated list of host tests.') parser.add_option('--build-targets', default='', help='Comma separated list of build targets.') parser.add_option('--experimental', action='store_true', help='Indicate whether to compile experimental targets.') parser.add_option('--extra_src', default='', help='Path to extra source file. If this is supplied, ' 'bisect script will use it to override default behavior.') return parser def main(argv): parser = GetHostStepsOptParser() options, args = parser.parse_args(argv[1:]) if args: return sys.exit('Unused args %s' % args) setattr(options, 'target', options.factory_properties.get('target', 'Debug')) setattr(options, 'extra_src', options.factory_properties.get('extra_src', '')) if options.steps: bb_utils.RunSteps(options.steps.split(','), GetHostStepCmds(), options) if __name__ == '__main__': sys.exit(main(sys.argv))
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 6171, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 646, 747, 199, 646, 984, 199, 199, 646, 14027, 63, 1208, 199, 646, 14027, 63, 11270, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 11541, 1333, 199, 504, 29219, 492, 5262, 421, 199, 4929, 26907, 63, 10484, 51, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 2501, 63, 1208, 14, 5342, 63, 8248, 63, 3022, 12, 283, 6429, 297, 283, 12384, 358, 199, 5600, 63, 5449, 63, 7569, 275, 663, 2941, 1074, 63, 2520, 1345, 63, 2383, 297, 283, 1623, 13017, 1105, 199, 199, 3022, 63, 8248, 63, 5441, 275, 747, 14, 515, 14, 3475, 8, 5559, 14, 3022, 63, 10187, 63, 5441, 9, 199, 199, 3, 20124, 4926, 367, 3378, 7874, 1314, 365, 1202, 2178, 9840, 315, 642, 570, 14, 199, 2540, 7874, 275, 14027, 63, 1208, 14, 2540, 7874, 421, 199, 318, 428, 1195, 2042, 2031, 515, 304, 523, 372, 747, 14, 515, 14, 904, 8, 5559, 14, 3022, 63, 10187, 63, 5441, 12, 627, 515, 9, 421, 199, 318, 2670, 5926, 2768, 3761, 83, 1547, 304, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 1074, 63, 2383, 358, 523, 3378, 7874, 779, 21261, 2042, 360, 6238, 63, 2520, 1345, 297, 283, 2537, 297, 283, 2520, 1345, 63, 2383, 14, 647, 659, 283, 6282, 995, 268, 5721, 63, 600, 29, 17, 9, 421, 199, 318, 3378, 8481, 83, 8, 1506, 63, 466, 304, 523, 3378, 7874, 779, 21261, 2042, 360, 1506, 297, 283, 9688, 827, 397, 14, 647, 2023, 523, 1900, 63, 515, 275, 428, 1195, 2042, 360, 548, 297, 1900, 63, 466, 9, 523, 20078, 19153, 63, 515, 275, 747, 14, 515, 14, 904, 8, 1506, 63, 515, 12, 1987, 9688, 827, 397, 63, 21142, 358, 523, 286, 22669, 63, 1813, 275, 747, 14, 2314, 14, 362, 360, 18637, 2846, 1387, 63, 10353, 5342, 540, 358, 523, 340, 286, 22669, 63, 1813, 503, 747, 14, 515, 14, 6292, 8, 9688, 19153, 63, 515, 304, 272, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 35, 22669, 358, 272, 340, 440, 286, 22669, 63, 1813, 26, 489, 870, 283, 35, 22669, 316, 7037, 370, 15572, 20078, 827, 397, 4881, 489, 543, 1551, 8, 9688, 19153, 63, 515, 9, 465, 289, 26, 267, 870, 289, 14, 739, 342, 272, 3378, 7874, 2941, 5682, 297, 2475, 3941, 297, 1900, 63, 515, 566, 819, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 1065, 7922, 358, 523, 3378, 7874, 2941, 71, 1258, 297, 283, 1065, 7922, 995, 394, 4478, 63, 265, 63, 5328, 29, 549, 9, 421, 199, 318, 24562, 8, 1419, 304, 523, 3378, 8481, 83, 8, 1419, 14, 1375, 9, 523, 2088, 275, 359, 736, 14, 515, 14, 904, 8, 4929, 26907, 63, 10484, 51, 63, 3022, 12, 283, 2014, 14, 647, 659, 268, 2850, 1506, 13, 3557, 29, 8675, 297, 268, 2850, 5772, 29, 1939, 391, 297, 268, 2850, 1375, 2458, 83, 7, 450, 1511, 14, 1375, 12, 268, 2850, 1939, 391, 13, 694, 2458, 83, 7, 450, 14027, 63, 1208, 14, 13160, 2054, 63, 3022, 61, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 2014, 358, 523, 340, 1511, 14, 1506, 63, 4684, 26, 272, 1900, 63, 4684, 275, 1511, 14, 1506, 63, 4684, 14, 1294, 11917, 272, 2088, 847, 14574, 1506, 13, 589, 297, 283, 1987, 904, 8, 1506, 63, 4684, 1874, 523, 3378, 7874, 8, 1760, 12, 394, 4478, 63, 265, 63, 5328, 29, 549, 12, 8288, 29, 3022, 63, 8248, 63, 5441, 9, 421, 199, 318, 16688, 3425, 8, 1419, 304, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 3065, 63, 1506, 358, 523, 3378, 7874, 779, 489, 747, 14, 515, 14, 904, 8, 4929, 26907, 63, 10484, 51, 63, 3022, 12, 283, 3065, 63, 1506, 14, 647, 659, 489, 2850, 2164, 13, 694, 297, 5262, 14, 3022, 63, 10187, 63, 5441, 12, 489, 2850, 5473, 13, 1725, 297, 283, 773, 14, 1375, 12, 2268, 12, 6238, 63, 2520, 1345, 12, 74, 2361, 63, 31053, 418, 489, 435, 14027, 63, 1208, 14, 9686, 8516, 8, 1419, 395, 8288, 29, 3022, 63, 8248, 63, 5441, 9, 421, 199, 318, 12892, 3425, 8, 1419, 304, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 5005, 63, 1506, 358, 523, 3378, 7874, 779, 736, 14, 515, 14, 904, 8, 4929, 26907, 63, 10484, 51, 63, 3022, 12, 283, 5005, 63, 1506, 14, 647, 5440, 268, 435, 14027, 63, 1208, 14, 9686, 8516, 8, 1419, 395, 8288, 29, 3022, 63, 8248, 63, 5441, 9, 421, 199, 318, 6668, 1713, 458, 8, 1419, 304, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 1623, 13017, 358, 523, 1900, 63, 466, 275, 942, 523, 340, 1511, 14, 1375, 508, 283, 9625, 356, 272, 1900, 63, 466, 275, 14574, 3221, 13, 1506, 418, 523, 3378, 7874, 779, 21261, 2042, 360, 1506, 297, 283, 6238, 297, 283, 1623, 13017, 63, 3028, 14, 647, 5440, 435, 1900, 63, 466, 9, 523, 3378, 7874, 779, 21261, 2042, 8, 489, 283, 2537, 297, 283, 6238, 297, 283, 1623, 13017, 63, 2718, 297, 283, 396, 297, 489, 283, 1065, 63, 1623, 13017, 63, 2718, 63, 2219, 14, 647, 5440, 435, 1900, 63, 466, 9, 421, 199, 318, 699, 13133, 12387, 13013, 8, 1419, 304, 523, 1249, 275, 942, 523, 340, 1511, 14, 2911, 63, 2164, 26, 272, 1249, 275, 14574, 2911, 63, 2164, 297, 1511, 14, 2911, 63, 2164, 61, 523, 3378, 7874, 779, 21261, 2042, 360, 2537, 297, 283, 6726, 13, 23247, 13, 9452, 13, 12513, 14, 647, 659, 881, 2475, 87, 297, 747, 14, 515, 14, 904, 8, 5559, 14, 3022, 63, 10187, 63, 5441, 12, 747, 14, 21386, 3948, 523, 3378, 7874, 779, 21261, 2042, 360, 2537, 297, 283, 1065, 13, 23247, 13, 9452, 13, 12513, 14, 647, 659, 881, 2475, 87, 297, 747, 14, 515, 14, 904, 8, 5559, 14, 3022, 63, 10187 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 6171, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 646, 747, 199, 646, 984, 199, 199, 646, 14027, 63, 1208, 199, 646, 14027, 63, 11270, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 11541, 1333, 199, 504, 29219, 492, 5262, 421, 199, 4929, 26907, 63, 10484, 51, 63, 3022, 275, 747, 14, 515, 14, 904, 8, 2501, 63, 1208, 14, 5342, 63, 8248, 63, 3022, 12, 283, 6429, 297, 283, 12384, 358, 199, 5600, 63, 5449, 63, 7569, 275, 663, 2941, 1074, 63, 2520, 1345, 63, 2383, 297, 283, 1623, 13017, 1105, 199, 199, 3022, 63, 8248, 63, 5441, 275, 747, 14, 515, 14, 3475, 8, 5559, 14, 3022, 63, 10187, 63, 5441, 9, 199, 199, 3, 20124, 4926, 367, 3378, 7874, 1314, 365, 1202, 2178, 9840, 315, 642, 570, 14, 199, 2540, 7874, 275, 14027, 63, 1208, 14, 2540, 7874, 421, 199, 318, 428, 1195, 2042, 2031, 515, 304, 523, 372, 747, 14, 515, 14, 904, 8, 5559, 14, 3022, 63, 10187, 63, 5441, 12, 627, 515, 9, 421, 199, 318, 2670, 5926, 2768, 3761, 83, 1547, 304, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 1074, 63, 2383, 358, 523, 3378, 7874, 779, 21261, 2042, 360, 6238, 63, 2520, 1345, 297, 283, 2537, 297, 283, 2520, 1345, 63, 2383, 14, 647, 659, 283, 6282, 995, 268, 5721, 63, 600, 29, 17, 9, 421, 199, 318, 3378, 8481, 83, 8, 1506, 63, 466, 304, 523, 3378, 7874, 779, 21261, 2042, 360, 1506, 297, 283, 9688, 827, 397, 14, 647, 2023, 523, 1900, 63, 515, 275, 428, 1195, 2042, 360, 548, 297, 1900, 63, 466, 9, 523, 20078, 19153, 63, 515, 275, 747, 14, 515, 14, 904, 8, 1506, 63, 515, 12, 1987, 9688, 827, 397, 63, 21142, 358, 523, 286, 22669, 63, 1813, 275, 747, 14, 2314, 14, 362, 360, 18637, 2846, 1387, 63, 10353, 5342, 540, 358, 523, 340, 286, 22669, 63, 1813, 503, 747, 14, 515, 14, 6292, 8, 9688, 19153, 63, 515, 304, 272, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 35, 22669, 358, 272, 340, 440, 286, 22669, 63, 1813, 26, 489, 870, 283, 35, 22669, 316, 7037, 370, 15572, 20078, 827, 397, 4881, 489, 543, 1551, 8, 9688, 19153, 63, 515, 9, 465, 289, 26, 267, 870, 289, 14, 739, 342, 272, 3378, 7874, 2941, 5682, 297, 2475, 3941, 297, 1900, 63, 515, 566, 819, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 1065, 7922, 358, 523, 3378, 7874, 2941, 71, 1258, 297, 283, 1065, 7922, 995, 394, 4478, 63, 265, 63, 5328, 29, 549, 9, 421, 199, 318, 24562, 8, 1419, 304, 523, 3378, 8481, 83, 8, 1419, 14, 1375, 9, 523, 2088, 275, 359, 736, 14, 515, 14, 904, 8, 4929, 26907, 63, 10484, 51, 63, 3022, 12, 283, 2014, 14, 647, 659, 268, 2850, 1506, 13, 3557, 29, 8675, 297, 268, 2850, 5772, 29, 1939, 391, 297, 268, 2850, 1375, 2458, 83, 7, 450, 1511, 14, 1375, 12, 268, 2850, 1939, 391, 13, 694, 2458, 83, 7, 450, 14027, 63, 1208, 14, 13160, 2054, 63, 3022, 61, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 2014, 358, 523, 340, 1511, 14, 1506, 63, 4684, 26, 272, 1900, 63, 4684, 275, 1511, 14, 1506, 63, 4684, 14, 1294, 11917, 272, 2088, 847, 14574, 1506, 13, 589, 297, 283, 1987, 904, 8, 1506, 63, 4684, 1874, 523, 3378, 7874, 8, 1760, 12, 394, 4478, 63, 265, 63, 5328, 29, 549, 12, 8288, 29, 3022, 63, 8248, 63, 5441, 9, 421, 199, 318, 16688, 3425, 8, 1419, 304, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 3065, 63, 1506, 358, 523, 3378, 7874, 779, 489, 747, 14, 515, 14, 904, 8, 4929, 26907, 63, 10484, 51, 63, 3022, 12, 283, 3065, 63, 1506, 14, 647, 659, 489, 2850, 2164, 13, 694, 297, 5262, 14, 3022, 63, 10187, 63, 5441, 12, 489, 2850, 5473, 13, 1725, 297, 283, 773, 14, 1375, 12, 2268, 12, 6238, 63, 2520, 1345, 12, 74, 2361, 63, 31053, 418, 489, 435, 14027, 63, 1208, 14, 9686, 8516, 8, 1419, 395, 8288, 29, 3022, 63, 8248, 63, 5441, 9, 421, 199, 318, 12892, 3425, 8, 1419, 304, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 5005, 63, 1506, 358, 523, 3378, 7874, 779, 736, 14, 515, 14, 904, 8, 4929, 26907, 63, 10484, 51, 63, 3022, 12, 283, 5005, 63, 1506, 14, 647, 5440, 268, 435, 14027, 63, 1208, 14, 9686, 8516, 8, 1419, 395, 8288, 29, 3022, 63, 8248, 63, 5441, 9, 421, 199, 318, 6668, 1713, 458, 8, 1419, 304, 523, 14027, 63, 11270, 14, 5375, 7989, 7801, 360, 1623, 13017, 358, 523, 1900, 63, 466, 275, 942, 523, 340, 1511, 14, 1375, 508, 283, 9625, 356, 272, 1900, 63, 466, 275, 14574, 3221, 13, 1506, 418, 523, 3378, 7874, 779, 21261, 2042, 360, 1506, 297, 283, 6238, 297, 283, 1623, 13017, 63, 3028, 14, 647, 5440, 435, 1900, 63, 466, 9, 523, 3378, 7874, 779, 21261, 2042, 8, 489, 283, 2537, 297, 283, 6238, 297, 283, 1623, 13017, 63, 2718, 297, 283, 396, 297, 489, 283, 1065, 63, 1623, 13017, 63, 2718, 63, 2219, 14, 647, 5440, 435, 1900, 63, 466, 9, 421, 199, 318, 699, 13133, 12387, 13013, 8, 1419, 304, 523, 1249, 275, 942, 523, 340, 1511, 14, 2911, 63, 2164, 26, 272, 1249, 275, 14574, 2911, 63, 2164, 297, 1511, 14, 2911, 63, 2164, 61, 523, 3378, 7874, 779, 21261, 2042, 360, 2537, 297, 283, 6726, 13, 23247, 13, 9452, 13, 12513, 14, 647, 659, 881, 2475, 87, 297, 747, 14, 515, 14, 904, 8, 5559, 14, 3022, 63, 10187, 63, 5441, 12, 747, 14, 21386, 3948, 523, 3378, 7874, 779, 21261, 2042, 360, 2537, 297, 283, 1065, 13, 23247, 13, 9452, 13, 12513, 14, 647, 659, 881, 2475, 87, 297, 747, 14, 515, 14, 904, 8, 5559, 14, 3022, 63, 10187, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ltilve/ChromiumGStreamerBackend
third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test.py
210
9375
#! /usr/bin/python # # Protocol Buffers - Google's data interchange format # Copyright 2008 Google Inc. All rights reserved. # http://code.google.com/p/protobuf/ # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Tests for google.protobuf.descriptor_pool.""" __author__ = 'matthewtoia@google.com (Matt Toia)' import unittest from google.protobuf import descriptor_pb2 from google.protobuf.internal import factory_test1_pb2 from google.protobuf.internal import factory_test2_pb2 from google.protobuf import descriptor from google.protobuf import descriptor_database from google.protobuf import descriptor_pool class DescriptorPoolTest(unittest.TestCase): def setUp(self): self.pool = descriptor_pool.DescriptorPool() self.factory_test1_fd = descriptor_pb2.FileDescriptorProto.FromString( factory_test1_pb2.DESCRIPTOR.serialized_pb) self.factory_test2_fd = descriptor_pb2.FileDescriptorProto.FromString( factory_test2_pb2.DESCRIPTOR.serialized_pb) self.pool.Add(self.factory_test1_fd) self.pool.Add(self.factory_test2_fd) def testFindFileByName(self): name1 = 'net/proto2/python/internal/factory_test1.proto' file_desc1 = self.pool.FindFileByName(name1) self.assertIsInstance(file_desc1, descriptor.FileDescriptor) self.assertEquals(name1, file_desc1.name) self.assertEquals('net.proto2.python.internal', file_desc1.package) self.assertIn('Factory1Message', file_desc1.message_types_by_name) name2 = 'net/proto2/python/internal/factory_test2.proto' file_desc2 = self.pool.FindFileByName(name2) self.assertIsInstance(file_desc2, descriptor.FileDescriptor) self.assertEquals(name2, file_desc2.name) self.assertEquals('net.proto2.python.internal', file_desc2.package) self.assertIn('Factory2Message', file_desc2.message_types_by_name) def testFindFileByNameFailure(self): try: self.pool.FindFileByName('Does not exist') self.fail('Expected KeyError') except KeyError: pass def testFindFileContainingSymbol(self): file_desc1 = self.pool.FindFileContainingSymbol( 'net.proto2.python.internal.Factory1Message') self.assertIsInstance(file_desc1, descriptor.FileDescriptor) self.assertEquals('net/proto2/python/internal/factory_test1.proto', file_desc1.name) self.assertEquals('net.proto2.python.internal', file_desc1.package) self.assertIn('Factory1Message', file_desc1.message_types_by_name) file_desc2 = self.pool.FindFileContainingSymbol( 'net.proto2.python.internal.Factory2Message') self.assertIsInstance(file_desc2, descriptor.FileDescriptor) self.assertEquals('net/proto2/python/internal/factory_test2.proto', file_desc2.name) self.assertEquals('net.proto2.python.internal', file_desc2.package) self.assertIn('Factory2Message', file_desc2.message_types_by_name) def testFindFileContainingSymbolFailure(self): try: self.pool.FindFileContainingSymbol('Does not exist') self.fail('Expected KeyError') except KeyError: pass def testFindMessageTypeByName(self): msg1 = self.pool.FindMessageTypeByName( 'net.proto2.python.internal.Factory1Message') self.assertIsInstance(msg1, descriptor.Descriptor) self.assertEquals('Factory1Message', msg1.name) self.assertEquals('net.proto2.python.internal.Factory1Message', msg1.full_name) self.assertEquals(None, msg1.containing_type) nested_msg1 = msg1.nested_types[0] self.assertEquals('NestedFactory1Message', nested_msg1.name) self.assertEquals(msg1, nested_msg1.containing_type) nested_enum1 = msg1.enum_types[0] self.assertEquals('NestedFactory1Enum', nested_enum1.name) self.assertEquals(msg1, nested_enum1.containing_type) self.assertEquals(nested_msg1, msg1.fields_by_name[ 'nested_factory_1_message'].message_type) self.assertEquals(nested_enum1, msg1.fields_by_name[ 'nested_factory_1_enum'].enum_type) msg2 = self.pool.FindMessageTypeByName( 'net.proto2.python.internal.Factory2Message') self.assertIsInstance(msg2, descriptor.Descriptor) self.assertEquals('Factory2Message', msg2.name) self.assertEquals('net.proto2.python.internal.Factory2Message', msg2.full_name) self.assertIsNone(msg2.containing_type) nested_msg2 = msg2.nested_types[0] self.assertEquals('NestedFactory2Message', nested_msg2.name) self.assertEquals(msg2, nested_msg2.containing_type) nested_enum2 = msg2.enum_types[0] self.assertEquals('NestedFactory2Enum', nested_enum2.name) self.assertEquals(msg2, nested_enum2.containing_type) self.assertEquals(nested_msg2, msg2.fields_by_name[ 'nested_factory_2_message'].message_type) self.assertEquals(nested_enum2, msg2.fields_by_name[ 'nested_factory_2_enum'].enum_type) self.assertTrue(msg2.fields_by_name['int_with_default'].has_default) self.assertEquals( 1776, msg2.fields_by_name['int_with_default'].default_value) self.assertTrue(msg2.fields_by_name['double_with_default'].has_default) self.assertEquals( 9.99, msg2.fields_by_name['double_with_default'].default_value) self.assertTrue(msg2.fields_by_name['string_with_default'].has_default) self.assertEquals( 'hello world', msg2.fields_by_name['string_with_default'].default_value) self.assertTrue(msg2.fields_by_name['bool_with_default'].has_default) self.assertFalse(msg2.fields_by_name['bool_with_default'].default_value) self.assertTrue(msg2.fields_by_name['enum_with_default'].has_default) self.assertEquals( 1, msg2.fields_by_name['enum_with_default'].default_value) msg3 = self.pool.FindMessageTypeByName( 'net.proto2.python.internal.Factory2Message.NestedFactory2Message') self.assertEquals(nested_msg2, msg3) def testFindMessageTypeByNameFailure(self): try: self.pool.FindMessageTypeByName('Does not exist') self.fail('Expected KeyError') except KeyError: pass def testFindEnumTypeByName(self): enum1 = self.pool.FindEnumTypeByName( 'net.proto2.python.internal.Factory1Enum') self.assertIsInstance(enum1, descriptor.EnumDescriptor) self.assertEquals(0, enum1.values_by_name['FACTORY_1_VALUE_0'].number) self.assertEquals(1, enum1.values_by_name['FACTORY_1_VALUE_1'].number) nested_enum1 = self.pool.FindEnumTypeByName( 'net.proto2.python.internal.Factory1Message.NestedFactory1Enum') self.assertIsInstance(nested_enum1, descriptor.EnumDescriptor) self.assertEquals( 0, nested_enum1.values_by_name['NESTED_FACTORY_1_VALUE_0'].number) self.assertEquals( 1, nested_enum1.values_by_name['NESTED_FACTORY_1_VALUE_1'].number) enum2 = self.pool.FindEnumTypeByName( 'net.proto2.python.internal.Factory2Enum') self.assertIsInstance(enum2, descriptor.EnumDescriptor) self.assertEquals(0, enum2.values_by_name['FACTORY_2_VALUE_0'].number) self.assertEquals(1, enum2.values_by_name['FACTORY_2_VALUE_1'].number) nested_enum2 = self.pool.FindEnumTypeByName( 'net.proto2.python.internal.Factory2Message.NestedFactory2Enum') self.assertIsInstance(nested_enum2, descriptor.EnumDescriptor) self.assertEquals( 0, nested_enum2.values_by_name['NESTED_FACTORY_2_VALUE_0'].number) self.assertEquals( 1, nested_enum2.values_by_name['NESTED_FACTORY_2_VALUE_1'].number) def testFindEnumTypeByNameFailure(self): try: self.pool.FindEnumTypeByName('Does not exist') self.fail('Expected KeyError') except KeyError: pass def testUserDefinedDB(self): db = descriptor_database.DescriptorDatabase() self.pool = descriptor_pool.DescriptorPool(db) db.Add(self.factory_test1_fd) db.Add(self.factory_test2_fd) self.testFindMessageTypeByName() if __name__ == '__main__': unittest.main()
bsd-3-clause
[ 3168, 1182, 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 11557, 699, 3043, 1192, 446, 4475, 1159, 666, 1640, 1461, 1475, 199, 3, 1898, 9079, 4475, 3277, 14, 221, 2900, 4481, 4644, 14, 199, 3, 1455, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 7204, 15, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 2925, 367, 6233, 14, 7204, 14, 4120, 63, 2293, 1041, 199, 199, 363, 2502, 363, 275, 283, 569, 29640, 475, 4674, 32, 3098, 14, 957, 334, 45, 6796, 4005, 4674, 3171, 199, 199, 646, 2882, 199, 504, 6233, 14, 7204, 492, 5872, 63, 3317, 18, 199, 504, 6233, 14, 7204, 14, 4672, 492, 6434, 63, 396, 17, 63, 3317, 18, 199, 504, 6233, 14, 7204, 14, 4672, 492, 6434, 63, 396, 18, 63, 3317, 18, 199, 504, 6233, 14, 7204, 492, 5872, 199, 504, 6233, 14, 7204, 492, 5872, 63, 4659, 199, 504, 6233, 14, 7204, 492, 5872, 63, 2293, 421, 199, 533, 28131, 5453, 774, 8, 2796, 14, 1746, 304, 819, 347, 3613, 8, 277, 304, 272, 291, 14, 2293, 275, 5872, 63, 2293, 14, 4311, 5453, 342, 272, 291, 14, 3702, 63, 396, 17, 63, 2592, 275, 5872, 63, 3317, 18, 14, 23859, 8548, 14, 7671, 8, 267, 6434, 63, 396, 17, 63, 3317, 18, 14, 7580, 14, 8397, 63, 3317, 9, 272, 291, 14, 3702, 63, 396, 18, 63, 2592, 275, 5872, 63, 3317, 18, 14, 23859, 8548, 14, 7671, 8, 267, 6434, 63, 396, 18, 63, 3317, 18, 14, 7580, 14, 8397, 63, 3317, 9, 272, 291, 14, 2293, 14, 1123, 8, 277, 14, 3702, 63, 396, 17, 63, 2592, 9, 272, 291, 14, 2293, 14, 1123, 8, 277, 14, 3702, 63, 396, 18, 63, 2592, 9, 819, 347, 511, 6591, 1173, 11190, 8, 277, 304, 272, 536, 17, 275, 283, 846, 15, 2625, 18, 15, 1548, 15, 4672, 15, 3702, 63, 396, 17, 14, 2625, 7, 272, 570, 63, 3257, 17, 275, 291, 14, 2293, 14, 6591, 1173, 11190, 8, 354, 17, 9, 272, 291, 14, 6926, 8, 493, 63, 3257, 17, 12, 5872, 14, 23859, 9, 272, 291, 14, 2947, 8, 354, 17, 12, 570, 63, 3257, 17, 14, 354, 9, 272, 291, 14, 2947, 360, 846, 14, 2625, 18, 14, 1548, 14, 4672, 297, 570, 63, 3257, 17, 14, 2491, 9, 272, 291, 14, 4080, 360, 2927, 17, 2209, 297, 570, 63, 3257, 17, 14, 1188, 63, 1313, 63, 991, 63, 354, 9, 339, 536, 18, 275, 283, 846, 15, 2625, 18, 15, 1548, 15, 4672, 15, 3702, 63, 396, 18, 14, 2625, 7, 272, 570, 63, 3257, 18, 275, 291, 14, 2293, 14, 6591, 1173, 11190, 8, 354, 18, 9, 272, 291, 14, 6926, 8, 493, 63, 3257, 18, 12, 5872, 14, 23859, 9, 272, 291, 14, 2947, 8, 354, 18, 12, 570, 63, 3257, 18, 14, 354, 9, 272, 291, 14, 2947, 360, 846, 14, 2625, 18, 14, 1548, 14, 4672, 297, 570, 63, 3257, 18, 14, 2491, 9, 272, 291, 14, 4080, 360, 2927, 18, 2209, 297, 570, 63, 3257, 18, 14, 1188, 63, 1313, 63, 991, 63, 354, 9, 819, 347, 511, 6591, 1173, 11190, 6782, 8, 277, 304, 272, 862, 26, 489, 291, 14, 2293, 14, 6591, 1173, 11190, 360, 6586, 440, 2187, 358, 489, 291, 14, 1633, 360, 6964, 4067, 358, 272, 871, 4067, 26, 489, 986, 819, 347, 511, 6591, 1173, 714, 24522, 8169, 8, 277, 304, 272, 570, 63, 3257, 17, 275, 291, 14, 2293, 14, 6591, 1173, 714, 24522, 8169, 8, 267, 283, 846, 14, 2625, 18, 14, 1548, 14, 4672, 14, 2927, 17, 2209, 358, 272, 291, 14, 6926, 8, 493, 63, 3257, 17, 12, 5872, 14, 23859, 9, 272, 291, 14, 2947, 360, 846, 15, 2625, 18, 15, 1548, 15, 4672, 15, 3702, 63, 396, 17, 14, 2625, 297, 1993, 570, 63, 3257, 17, 14, 354, 9, 272, 291, 14, 2947, 360, 846, 14, 2625, 18, 14, 1548, 14, 4672, 297, 570, 63, 3257, 17, 14, 2491, 9, 272, 291, 14, 4080, 360, 2927, 17, 2209, 297, 570, 63, 3257, 17, 14, 1188, 63, 1313, 63, 991, 63, 354, 9, 339, 570, 63, 3257, 18, 275, 291, 14, 2293, 14, 6591, 1173, 714, 24522, 8169, 8, 267, 283, 846, 14, 2625, 18, 14, 1548, 14, 4672, 14, 2927, 18, 2209, 358, 272, 291, 14, 6926, 8, 493, 63 ]
[ 1182, 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 11557, 699, 3043, 1192, 446, 4475, 1159, 666, 1640, 1461, 1475, 199, 3, 1898, 9079, 4475, 3277, 14, 221, 2900, 4481, 4644, 14, 199, 3, 1455, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 7204, 15, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 2925, 367, 6233, 14, 7204, 14, 4120, 63, 2293, 1041, 199, 199, 363, 2502, 363, 275, 283, 569, 29640, 475, 4674, 32, 3098, 14, 957, 334, 45, 6796, 4005, 4674, 3171, 199, 199, 646, 2882, 199, 504, 6233, 14, 7204, 492, 5872, 63, 3317, 18, 199, 504, 6233, 14, 7204, 14, 4672, 492, 6434, 63, 396, 17, 63, 3317, 18, 199, 504, 6233, 14, 7204, 14, 4672, 492, 6434, 63, 396, 18, 63, 3317, 18, 199, 504, 6233, 14, 7204, 492, 5872, 199, 504, 6233, 14, 7204, 492, 5872, 63, 4659, 199, 504, 6233, 14, 7204, 492, 5872, 63, 2293, 421, 199, 533, 28131, 5453, 774, 8, 2796, 14, 1746, 304, 819, 347, 3613, 8, 277, 304, 272, 291, 14, 2293, 275, 5872, 63, 2293, 14, 4311, 5453, 342, 272, 291, 14, 3702, 63, 396, 17, 63, 2592, 275, 5872, 63, 3317, 18, 14, 23859, 8548, 14, 7671, 8, 267, 6434, 63, 396, 17, 63, 3317, 18, 14, 7580, 14, 8397, 63, 3317, 9, 272, 291, 14, 3702, 63, 396, 18, 63, 2592, 275, 5872, 63, 3317, 18, 14, 23859, 8548, 14, 7671, 8, 267, 6434, 63, 396, 18, 63, 3317, 18, 14, 7580, 14, 8397, 63, 3317, 9, 272, 291, 14, 2293, 14, 1123, 8, 277, 14, 3702, 63, 396, 17, 63, 2592, 9, 272, 291, 14, 2293, 14, 1123, 8, 277, 14, 3702, 63, 396, 18, 63, 2592, 9, 819, 347, 511, 6591, 1173, 11190, 8, 277, 304, 272, 536, 17, 275, 283, 846, 15, 2625, 18, 15, 1548, 15, 4672, 15, 3702, 63, 396, 17, 14, 2625, 7, 272, 570, 63, 3257, 17, 275, 291, 14, 2293, 14, 6591, 1173, 11190, 8, 354, 17, 9, 272, 291, 14, 6926, 8, 493, 63, 3257, 17, 12, 5872, 14, 23859, 9, 272, 291, 14, 2947, 8, 354, 17, 12, 570, 63, 3257, 17, 14, 354, 9, 272, 291, 14, 2947, 360, 846, 14, 2625, 18, 14, 1548, 14, 4672, 297, 570, 63, 3257, 17, 14, 2491, 9, 272, 291, 14, 4080, 360, 2927, 17, 2209, 297, 570, 63, 3257, 17, 14, 1188, 63, 1313, 63, 991, 63, 354, 9, 339, 536, 18, 275, 283, 846, 15, 2625, 18, 15, 1548, 15, 4672, 15, 3702, 63, 396, 18, 14, 2625, 7, 272, 570, 63, 3257, 18, 275, 291, 14, 2293, 14, 6591, 1173, 11190, 8, 354, 18, 9, 272, 291, 14, 6926, 8, 493, 63, 3257, 18, 12, 5872, 14, 23859, 9, 272, 291, 14, 2947, 8, 354, 18, 12, 570, 63, 3257, 18, 14, 354, 9, 272, 291, 14, 2947, 360, 846, 14, 2625, 18, 14, 1548, 14, 4672, 297, 570, 63, 3257, 18, 14, 2491, 9, 272, 291, 14, 4080, 360, 2927, 18, 2209, 297, 570, 63, 3257, 18, 14, 1188, 63, 1313, 63, 991, 63, 354, 9, 819, 347, 511, 6591, 1173, 11190, 6782, 8, 277, 304, 272, 862, 26, 489, 291, 14, 2293, 14, 6591, 1173, 11190, 360, 6586, 440, 2187, 358, 489, 291, 14, 1633, 360, 6964, 4067, 358, 272, 871, 4067, 26, 489, 986, 819, 347, 511, 6591, 1173, 714, 24522, 8169, 8, 277, 304, 272, 570, 63, 3257, 17, 275, 291, 14, 2293, 14, 6591, 1173, 714, 24522, 8169, 8, 267, 283, 846, 14, 2625, 18, 14, 1548, 14, 4672, 14, 2927, 17, 2209, 358, 272, 291, 14, 6926, 8, 493, 63, 3257, 17, 12, 5872, 14, 23859, 9, 272, 291, 14, 2947, 360, 846, 15, 2625, 18, 15, 1548, 15, 4672, 15, 3702, 63, 396, 17, 14, 2625, 297, 1993, 570, 63, 3257, 17, 14, 354, 9, 272, 291, 14, 2947, 360, 846, 14, 2625, 18, 14, 1548, 14, 4672, 297, 570, 63, 3257, 17, 14, 2491, 9, 272, 291, 14, 4080, 360, 2927, 17, 2209, 297, 570, 63, 3257, 17, 14, 1188, 63, 1313, 63, 991, 63, 354, 9, 339, 570, 63, 3257, 18, 275, 291, 14, 2293, 14, 6591, 1173, 714, 24522, 8169, 8, 267, 283, 846, 14, 2625, 18, 14, 1548, 14, 4672, 14, 2927, 18, 2209, 358, 272, 291, 14, 6926, 8, 493, 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,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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 ]
pychess/pychess
lib/pychess/widgets/playerinfoDialog.py
1
2716
from gi.repository import Gtk, GObject firstRun = True def run(widgets): global firstRun if firstRun: initialize(widgets) firstRun = False widgets["player_info"].show_all() def initialize(widgets): def addColumns(treeview, *columns): model = Gtk.ListStore(*((str, ) * len(columns))) treeview.set_model(model) treeview.get_selection().set_mode(Gtk.SelectionMode.NONE) for i, name in enumerate(columns): crt = Gtk.CellRendererText() column = Gtk.TreeViewColumn(name, crt, text=i) treeview.append_column(column) addColumns(widgets["results_view"], "", "Games", "Won", "Drawn", "Lost", "Score") model = widgets["results_view"].get_model() model.append(("White", "67", "28", "24", "15", "59%")) model.append(("Black", "66", "26", "23", "17", "56%")) model.append(("Total", "133", "54", "47", "32", "58%")) addColumns(widgets["rating_view"], "Current", "Initial", "Lowest", "Highest", "Average") model = widgets["rating_view"].get_model() model.append(("1771", "1734", "1659", "1791", "1700")) widgets["history_view"].set_model(Gtk.ListStore(object)) widgets["history_view"].get_selection().set_mode(Gtk.SelectionMode.NONE) widgets["history_view"].append_column( Gtk.TreeViewColumn("Player Rating History", HistoryCellRenderer(), data=0)) widgets["history_view"].get_model().append((1, )) def hide_window(button, *args): widgets["player_info"].hide() return True widgets["player_info"].connect("delete-event", hide_window) widgets["player_info_close_button"].connect("clicked", hide_window) class HistoryCellRenderer(Gtk.CellRenderer): __gproperties__ = { "data": (GObject.TYPE_PYOBJECT, "Data", "Data", GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE), } def __init__(self): self.__gobject_init__() self.data = None def do_set_property(self, pspec, value): setattr(self, pspec.name, value) def do_get_property(self, pspec): return getattr(self, pspec.name) def on_render(self, window, widget, background_area, rect, expose_area, flags): if not self.data: return cairo = window.cairo_create() x_loc, y_loc, width, height = rect.x, rect.y, rect.width, rect.height cairo.rectangle(x_loc + 1, y_loc + 1, x_loc + width - 2, y_loc + height - 2) cairo.set_source_rgb(0.45, 0.45, 0.45) cairo.stroke() def on_get_size(self, widget, cell_area=None): return (0, 0, -1, 130)
gpl-3.0
[ 504, 18895, 14, 8421, 492, 11424, 12, 31264, 421, 199, 2246, 2540, 275, 715, 421, 199, 318, 1255, 8, 8583, 304, 272, 2288, 1642, 2540, 272, 340, 1642, 2540, 26, 267, 8265, 8, 8583, 9, 267, 1642, 2540, 275, 756, 272, 11114, 905, 6147, 63, 815, 4140, 2384, 63, 452, 342, 421, 199, 318, 8265, 8, 8583, 304, 272, 347, 1050, 15086, 8, 32440, 12, 627, 3406, 304, 267, 1402, 275, 11424, 14, 1296, 5502, 2031, 1332, 495, 12, 776, 627, 822, 8, 3406, 1724, 267, 3123, 1345, 14, 409, 63, 1238, 8, 1238, 9, 267, 3123, 1345, 14, 362, 63, 5592, 1252, 409, 63, 632, 8, 18891, 14, 7713, 1385, 14, 9185, 9, 267, 367, 284, 12, 536, 315, 3874, 8, 3406, 304, 288, 2467, 84, 275, 11424, 14, 8108, 11355, 1872, 342, 288, 2763, 275, 11424, 14, 32656, 4547, 8, 354, 12, 2467, 84, 12, 1318, 29, 73, 9, 288, 3123, 1345, 14, 740, 63, 2301, 8, 2301, 9, 339, 1050, 15086, 8, 8583, 905, 2604, 63, 1345, 2255, 4873, 298, 11454, 83, 401, 298, 55, 265, 401, 298, 9654, 78, 401, 298, 14074, 401, 2049, 298, 12642, 531, 272, 1402, 275, 11114, 905, 2604, 63, 1345, 4140, 362, 63, 1238, 342, 272, 1402, 14, 740, 9313, 19803, 401, 298, 1822, 401, 298, 1651, 401, 298, 1194, 401, 298, 1046, 401, 298, 1427, 5, 2237, 272, 1402, 14, 740, 9313, 23405, 401, 298, 1272, 401, 298, 1479, 401, 298, 1789, 401, 298, 1196, 401, 298, 1367, 5, 2237, 272, 1402, 14, 740, 9313, 7316, 401, 298, 10456, 401, 298, 1477, 401, 298, 2417, 401, 298, 708, 401, 298, 2010, 5, 2237, 339, 1050, 15086, 8, 8583, 905, 10417, 63, 1345, 2255, 298, 5639, 401, 298, 5733, 401, 298, 10281, 597, 401, 2049, 298, 40, 12527, 401, 298, 17400, 531, 272, 1402, 275, 11114, 905, 10417, 63, 1345, 4140, 362, 63, 1238, 342, 272, 1402, 14, 740, 9313, 8881, 17, 401, 298, 1196, 1082, 401, 298, 975, 1427, 401, 298, 1196, 3328, 401, 298, 1196, 383, 2237, 339, 11114, 905, 5570, 63, 1345, 4140, 409, 63, 1238, 8, 18891, 14, 1296, 5502, 8, 785, 430, 272, 11114, 905, 5570, 63, 1345, 4140, 362, 63, 5592, 1252, 409, 63, 632, 8, 18891, 14, 7713, 1385, 14, 9185, 9, 272, 11114, 905, 5570, 63, 1345, 4140, 740, 63, 2301, 8, 267, 11424, 14, 32656, 4547, 480, 10921, 820, 1958, 27829, 401, 2574, 27829, 8108, 11355, 1062, 2574, 666, 29, 16, 430, 272, 11114, 905, 5570, 63, 1345, 4140, 362, 63, 1238, 1252, 740, 1332, 17, 12, 5082, 339, 347, 13714, 63, 3806, 8, 3887, 12, 627, 589, 304, 267, 11114, 905, 6147, 63, 815, 4140, 8191, 342, 267, 372, 715, 339, 11114, 905, 6147, 63, 815, 4140, 2242, 480, 1807, 13, 1430, 401, 13714, 63, 3806, 9, 272, 11114, 905, 6147, 63, 815, 63, 1600, 63, 3887, 4140, 2242, 480, 11276, 401, 13714, 63, 3806, 9, 421, 199, 533, 27829, 8108, 11355, 8, 18891, 14, 8108, 11355, 304, 272, 636, 71, 3282, 363, 275, 469, 267, 298, 576, 582, 267, 334, 39, 1692, 14, 2711, 63, 4521, 9868, 12, 298, 1451, 401, 298, 1451, 401, 31264, 14, 4098, 6381, 14, 5670, 2617, 1204, 31264, 14, 4098, 6381, 14, 6524, 649, 2617, 395, 272, 789, 339, 347, 636, 826, 721, 277, 304, 267, 291, 855, 71, 785, 63, 826, 4533, 267, 291, 14, 576, 275, 488, 339, 347, 886, 63, 409, 63, 1829, 8, 277, 12, 299, 1650, 12, 574, 304, 267, 5371, 8, 277, 12, 299, 1650, 14, 354, 12, 574, 9, 339, 347, 886, 63, 362, 63, 1829, 8, 277, 12, 299, 1650, 304, 267, 372, 2519, 8, 277, 12, 299, 1650, 14, 354, 9, 339, 347, 641, 63, 3352, 8, 277, 12, 4353, 12, 3938, 12, 8020, 63, 6789, 12, 8626, 12, 23705, 63, 6789, 12, 2116, 3285, 304, 267, 340, 440, 291, 14, 576, 26, 288, 372, 267, 1704, 14352, 275, 4353, 14, 21562, 63, 981, 342, 267, 671, 63, 2102, 12, 612, 63, 2102, 12, 3462, 12, 4569, 275, 8626, 14, 88, 12, 8626, 14, 89, 12, 8626, 14, 2063, 12, 8626, 14, 3333, 267, 1704, 14352, 14, 19954, 8, 88, 63, 2102, 435, 413, 12, 612, 63, 2102, 435, 413, 12, 671, 63, 2102, 435, 3462, 446, 499, 12, 612, 63, 2102, 435, 4569, 446, 499, 9, 267, 1704, 14352, 14, 409, 63, 1365, 63, 10090, 8, 16, 14, 2322, 12, 378, 14, 2322, 12, 378, 14, 2322, 9, 267, 1704, 14352, 14, 11473, 342, 339, 347, 641, 63, 362, 63, 890, 8, 277, 12, 3938, 12, 4917, 63, 6789, 29, 403, 304, 267, 372, 334, 16, 12, 378, 12, 446, 17, 12, 21334, 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 ]
[ 18895, 14, 8421, 492, 11424, 12, 31264, 421, 199, 2246, 2540, 275, 715, 421, 199, 318, 1255, 8, 8583, 304, 272, 2288, 1642, 2540, 272, 340, 1642, 2540, 26, 267, 8265, 8, 8583, 9, 267, 1642, 2540, 275, 756, 272, 11114, 905, 6147, 63, 815, 4140, 2384, 63, 452, 342, 421, 199, 318, 8265, 8, 8583, 304, 272, 347, 1050, 15086, 8, 32440, 12, 627, 3406, 304, 267, 1402, 275, 11424, 14, 1296, 5502, 2031, 1332, 495, 12, 776, 627, 822, 8, 3406, 1724, 267, 3123, 1345, 14, 409, 63, 1238, 8, 1238, 9, 267, 3123, 1345, 14, 362, 63, 5592, 1252, 409, 63, 632, 8, 18891, 14, 7713, 1385, 14, 9185, 9, 267, 367, 284, 12, 536, 315, 3874, 8, 3406, 304, 288, 2467, 84, 275, 11424, 14, 8108, 11355, 1872, 342, 288, 2763, 275, 11424, 14, 32656, 4547, 8, 354, 12, 2467, 84, 12, 1318, 29, 73, 9, 288, 3123, 1345, 14, 740, 63, 2301, 8, 2301, 9, 339, 1050, 15086, 8, 8583, 905, 2604, 63, 1345, 2255, 4873, 298, 11454, 83, 401, 298, 55, 265, 401, 298, 9654, 78, 401, 298, 14074, 401, 2049, 298, 12642, 531, 272, 1402, 275, 11114, 905, 2604, 63, 1345, 4140, 362, 63, 1238, 342, 272, 1402, 14, 740, 9313, 19803, 401, 298, 1822, 401, 298, 1651, 401, 298, 1194, 401, 298, 1046, 401, 298, 1427, 5, 2237, 272, 1402, 14, 740, 9313, 23405, 401, 298, 1272, 401, 298, 1479, 401, 298, 1789, 401, 298, 1196, 401, 298, 1367, 5, 2237, 272, 1402, 14, 740, 9313, 7316, 401, 298, 10456, 401, 298, 1477, 401, 298, 2417, 401, 298, 708, 401, 298, 2010, 5, 2237, 339, 1050, 15086, 8, 8583, 905, 10417, 63, 1345, 2255, 298, 5639, 401, 298, 5733, 401, 298, 10281, 597, 401, 2049, 298, 40, 12527, 401, 298, 17400, 531, 272, 1402, 275, 11114, 905, 10417, 63, 1345, 4140, 362, 63, 1238, 342, 272, 1402, 14, 740, 9313, 8881, 17, 401, 298, 1196, 1082, 401, 298, 975, 1427, 401, 298, 1196, 3328, 401, 298, 1196, 383, 2237, 339, 11114, 905, 5570, 63, 1345, 4140, 409, 63, 1238, 8, 18891, 14, 1296, 5502, 8, 785, 430, 272, 11114, 905, 5570, 63, 1345, 4140, 362, 63, 5592, 1252, 409, 63, 632, 8, 18891, 14, 7713, 1385, 14, 9185, 9, 272, 11114, 905, 5570, 63, 1345, 4140, 740, 63, 2301, 8, 267, 11424, 14, 32656, 4547, 480, 10921, 820, 1958, 27829, 401, 2574, 27829, 8108, 11355, 1062, 2574, 666, 29, 16, 430, 272, 11114, 905, 5570, 63, 1345, 4140, 362, 63, 1238, 1252, 740, 1332, 17, 12, 5082, 339, 347, 13714, 63, 3806, 8, 3887, 12, 627, 589, 304, 267, 11114, 905, 6147, 63, 815, 4140, 8191, 342, 267, 372, 715, 339, 11114, 905, 6147, 63, 815, 4140, 2242, 480, 1807, 13, 1430, 401, 13714, 63, 3806, 9, 272, 11114, 905, 6147, 63, 815, 63, 1600, 63, 3887, 4140, 2242, 480, 11276, 401, 13714, 63, 3806, 9, 421, 199, 533, 27829, 8108, 11355, 8, 18891, 14, 8108, 11355, 304, 272, 636, 71, 3282, 363, 275, 469, 267, 298, 576, 582, 267, 334, 39, 1692, 14, 2711, 63, 4521, 9868, 12, 298, 1451, 401, 298, 1451, 401, 31264, 14, 4098, 6381, 14, 5670, 2617, 1204, 31264, 14, 4098, 6381, 14, 6524, 649, 2617, 395, 272, 789, 339, 347, 636, 826, 721, 277, 304, 267, 291, 855, 71, 785, 63, 826, 4533, 267, 291, 14, 576, 275, 488, 339, 347, 886, 63, 409, 63, 1829, 8, 277, 12, 299, 1650, 12, 574, 304, 267, 5371, 8, 277, 12, 299, 1650, 14, 354, 12, 574, 9, 339, 347, 886, 63, 362, 63, 1829, 8, 277, 12, 299, 1650, 304, 267, 372, 2519, 8, 277, 12, 299, 1650, 14, 354, 9, 339, 347, 641, 63, 3352, 8, 277, 12, 4353, 12, 3938, 12, 8020, 63, 6789, 12, 8626, 12, 23705, 63, 6789, 12, 2116, 3285, 304, 267, 340, 440, 291, 14, 576, 26, 288, 372, 267, 1704, 14352, 275, 4353, 14, 21562, 63, 981, 342, 267, 671, 63, 2102, 12, 612, 63, 2102, 12, 3462, 12, 4569, 275, 8626, 14, 88, 12, 8626, 14, 89, 12, 8626, 14, 2063, 12, 8626, 14, 3333, 267, 1704, 14352, 14, 19954, 8, 88, 63, 2102, 435, 413, 12, 612, 63, 2102, 435, 413, 12, 671, 63, 2102, 435, 3462, 446, 499, 12, 612, 63, 2102, 435, 4569, 446, 499, 9, 267, 1704, 14352, 14, 409, 63, 1365, 63, 10090, 8, 16, 14, 2322, 12, 378, 14, 2322, 12, 378, 14, 2322, 9, 267, 1704, 14352, 14, 11473, 342, 339, 347, 641, 63, 362, 63, 890, 8, 277, 12, 3938, 12, 4917, 63, 6789, 29, 403, 304, 267, 372, 334, 16, 12, 378, 12, 446, 17, 12, 21334, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
bmoar/ansible
lib/ansible/playbook/role/__init__.py
13
15291
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type from six import iteritems, string_types import inspect import os from hashlib import sha1 from ansible.errors import AnsibleError, AnsibleParserError from ansible.parsing import DataLoader from ansible.playbook.attribute import FieldAttribute from ansible.playbook.base import Base from ansible.playbook.become import Become from ansible.playbook.conditional import Conditional from ansible.playbook.helpers import load_list_of_blocks from ansible.playbook.role.include import RoleInclude from ansible.playbook.role.metadata import RoleMetadata from ansible.playbook.taggable import Taggable from ansible.plugins import get_all_plugin_loaders from ansible.utils.vars import combine_vars __all__ = ['Role', 'hash_params'] # FIXME: this should be a utility function, but can't be a member of # the role due to the fact that it would require the use of self # in a static method. This is also used in the base class for # strategies (ansible/plugins/strategy/__init__.py) def hash_params(params): if not isinstance(params, dict): return params else: s = set() for k,v in iteritems(params): if isinstance(v, dict): s.update((k, hash_params(v))) elif isinstance(v, list): things = [] for item in v: things.append(hash_params(item)) s.update((k, tuple(things))) else: s.update((k, v)) return frozenset(s) class Role(Base, Become, Conditional, Taggable): def __init__(self, play=None): self._role_name = None self._role_path = None self._role_params = dict() self._loader = None self._metadata = None self._play = play self._parents = [] self._dependencies = [] self._task_blocks = [] self._handler_blocks = [] self._default_vars = dict() self._role_vars = dict() self._had_task_run = dict() self._completed = dict() super(Role, self).__init__() def __repr__(self): return self.get_name() def get_name(self): return self._role_name @staticmethod def load(role_include, play, parent_role=None): try: # The ROLE_CACHE is a dictionary of role names, with each entry # containing another dictionary corresponding to a set of parameters # specified for a role as the key and the Role() object itself. # We use frozenset to make the dictionary hashable. params = role_include.get_role_params() if role_include.when is not None: params['when'] = role_include.when if role_include.tags is not None: params['tags'] = role_include.tags hashed_params = hash_params(params) if role_include.role in play.ROLE_CACHE: for (entry, role_obj) in iteritems(play.ROLE_CACHE[role_include.role]): if hashed_params == entry: if parent_role: role_obj.add_parent(parent_role) return role_obj r = Role(play=play) r._load_role_data(role_include, parent_role=parent_role) if role_include.role not in play.ROLE_CACHE: play.ROLE_CACHE[role_include.role] = dict() if parent_role: if parent_role.when: new_when = parent_role.when[:] new_when.extend(r.when or []) r.when = new_when if parent_role.tags: new_tags = parent_role.tags[:] new_tags.extend(r.tags or []) r.tags = new_tags play.ROLE_CACHE[role_include.role][hashed_params] = r return r except RuntimeError: # FIXME: needs a better way to access the ds in the role include raise AnsibleError("A recursion loop was detected with the roles specified. Make sure child roles do not have dependencies on parent roles", obj=role_include._ds) def _load_role_data(self, role_include, parent_role=None): self._role_name = role_include.role self._role_path = role_include.get_role_path() self._role_params = role_include.get_role_params() self._variable_manager = role_include.get_variable_manager() self._loader = role_include.get_loader() if parent_role: self.add_parent(parent_role) # copy over all field attributes, except for when and tags, which # are special cases and need to preserve pre-existing values for (attr_name, _) in iteritems(self._get_base_attributes()): if attr_name not in ('when', 'tags'): setattr(self, attr_name, getattr(role_include, attr_name)) current_when = getattr(self, 'when')[:] current_when.extend(role_include.when) setattr(self, 'when', current_when) current_tags = getattr(self, 'tags')[:] current_tags.extend(role_include.tags) setattr(self, 'tags', current_tags) # dynamically load any plugins from the role directory for name, obj in get_all_plugin_loaders(): if obj.subdir: plugin_path = os.path.join(self._role_path, obj.subdir) if os.path.isdir(plugin_path): obj.add_directory(plugin_path) # load the role's other files, if they exist metadata = self._load_role_yaml('meta') if metadata: self._metadata = RoleMetadata.load(metadata, owner=self, loader=self._loader) self._dependencies = self._load_dependencies() else: self._metadata = RoleMetadata() task_data = self._load_role_yaml('tasks') if task_data: self._task_blocks = load_list_of_blocks(task_data, play=self._play, role=self, loader=self._loader) handler_data = self._load_role_yaml('handlers') if handler_data: self._handler_blocks = load_list_of_blocks(handler_data, play=self._play, role=self, use_handlers=True, loader=self._loader) # vars and default vars are regular dictionaries self._role_vars = self._load_role_yaml('vars') if self._role_vars is None: self._role_vars = dict() elif not isinstance(self._role_vars, dict): raise AnsibleParserError("The vars/main.yml file for role '%s' must contain a dictionary of variables" % self._role_name) self._default_vars = self._load_role_yaml('defaults') if self._default_vars is None: self._default_vars = dict() elif not isinstance(self._default_vars, dict): raise AnsibleParserError("The default/main.yml file for role '%s' must contain a dictionary of variables" % self._role_name) def _load_role_yaml(self, subdir): file_path = os.path.join(self._role_path, subdir) if self._loader.path_exists(file_path) and self._loader.is_directory(file_path): main_file = self._resolve_main(file_path) if self._loader.path_exists(main_file): return self._loader.load_from_file(main_file) return None def _resolve_main(self, basepath): ''' flexibly handle variations in main filenames ''' possible_mains = ( os.path.join(basepath, 'main.yml'), os.path.join(basepath, 'main.yaml'), os.path.join(basepath, 'main.json'), os.path.join(basepath, 'main'), ) if sum([self._loader.is_file(x) for x in possible_mains]) > 1: raise AnsibleError("found multiple main files at %s, only one allowed" % (basepath)) else: for m in possible_mains: if self._loader.is_file(m): return m # exactly one main file return possible_mains[0] # zero mains (we still need to return something) def _load_dependencies(self): ''' Recursively loads role dependencies from the metadata list of dependencies, if it exists ''' deps = [] if self._metadata: for role_include in self._metadata.dependencies: r = Role.load(role_include, play=self._play, parent_role=self) deps.append(r) return deps #------------------------------------------------------------------------------ # other functions def add_parent(self, parent_role): ''' adds a role to the list of this roles parents ''' assert isinstance(parent_role, Role) if parent_role not in self._parents: self._parents.append(parent_role) def get_parents(self): return self._parents def get_default_vars(self): # FIXME: get these from dependent roles too default_vars = dict() for dep in self.get_all_dependencies(): default_vars = combine_vars(default_vars, dep.get_default_vars()) default_vars = combine_vars(default_vars, self._default_vars) return default_vars def get_inherited_vars(self, dep_chain=[]): inherited_vars = dict() for parent in dep_chain: inherited_vars = combine_vars(inherited_vars, parent._role_vars) inherited_vars = combine_vars(inherited_vars, parent._role_params) return inherited_vars def get_vars(self, dep_chain=[]): all_vars = self.get_inherited_vars(dep_chain) for dep in self.get_all_dependencies(): all_vars = combine_vars(all_vars, dep.get_vars()) all_vars = combine_vars(all_vars, self._role_vars) all_vars = combine_vars(all_vars, self._role_params) return all_vars def get_direct_dependencies(self): return self._dependencies[:] def get_all_dependencies(self): ''' Returns a list of all deps, built recursively from all child dependencies, in the proper order in which they should be executed or evaluated. ''' child_deps = [] for dep in self.get_direct_dependencies(): for child_dep in dep.get_all_dependencies(): child_deps.append(child_dep) child_deps.append(dep) return child_deps def get_task_blocks(self): return self._task_blocks[:] def get_handler_blocks(self): block_list = [] for dep in self.get_direct_dependencies(): dep_blocks = dep.get_handler_blocks() block_list.extend(dep_blocks) block_list.extend(self._handler_blocks) return block_list def has_run(self, host): ''' Returns true if this role has been iterated over completely and at least one task was run ''' return host.name in self._completed and not self._metadata.allow_duplicates def compile(self, play, dep_chain=[]): ''' Returns the task list for this role, which is created by first recursively compiling the tasks for all direct dependencies, and then adding on the tasks for this role. The role compile() also remembers and saves the dependency chain with each task, so tasks know by which route they were found, and can correctly take their parent's tags/conditionals into account. ''' block_list = [] # update the dependency chain here new_dep_chain = dep_chain + [self] deps = self.get_direct_dependencies() for dep in deps: dep_blocks = dep.compile(play=play, dep_chain=new_dep_chain) for dep_block in dep_blocks: new_dep_block = dep_block.copy() new_dep_block._dep_chain = new_dep_chain new_dep_block._play = play block_list.append(new_dep_block) block_list.extend(self._task_blocks) return block_list def serialize(self, include_deps=True): res = super(Role, self).serialize() res['_role_name'] = self._role_name res['_role_path'] = self._role_path res['_role_vars'] = self._role_vars res['_role_params'] = self._role_params res['_default_vars'] = self._default_vars res['_had_task_run'] = self._had_task_run.copy() res['_completed'] = self._completed.copy() if self._metadata: res['_metadata'] = self._metadata.serialize() if include_deps: deps = [] for role in self.get_direct_dependencies(): deps.append(role.serialize()) res['_dependencies'] = deps parents = [] for parent in self._parents: parents.append(parent.serialize(include_deps=False)) res['_parents'] = parents return res def deserialize(self, data, include_deps=True): self._role_name = data.get('_role_name', '') self._role_path = data.get('_role_path', '') self._role_vars = data.get('_role_vars', dict()) self._role_params = data.get('_role_params', dict()) self._default_vars = data.get('_default_vars', dict()) self._had_task_run = data.get('_had_task_run', dict()) self._completed = data.get('_completed', dict()) if include_deps: deps = [] for dep in data.get('_dependencies', []): r = Role() r.deserialize(dep) deps.append(r) setattr(self, '_dependencies', deps) parent_data = data.get('_parents', []) parents = [] for parent in parent_data: r = Role() r.deserialize(parent, include_deps=False) parents.append(r) setattr(self, '_parents', parents) metadata_data = data.get('_metadata') if metadata_data: m = RoleMetadata() m.deserialize(metadata_data) self._metadata = m super(Role, self).deserialize(data) def set_loader(self, loader): self._loader = loader for parent in self._parents: parent.set_loader(loader) for dep in self.get_direct_dependencies(): dep.set_loader(loader)
gpl-3.0
[ 3, 334, 67, 9, 6029, 13, 7280, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 3816, 492, 10849, 12, 1059, 63, 1313, 199, 199, 646, 6485, 199, 646, 747, 199, 199, 504, 8337, 492, 7793, 17, 199, 199, 504, 3242, 14, 2550, 492, 13358, 12, 31775, 199, 504, 3242, 14, 11059, 492, 3918, 5455, 199, 504, 3242, 14, 14205, 14, 3215, 492, 5024, 1646, 199, 504, 3242, 14, 14205, 14, 1095, 492, 3523, 199, 504, 3242, 14, 14205, 14, 13970, 492, 6423, 4352, 199, 504, 3242, 14, 14205, 14, 14353, 492, 24191, 199, 504, 3242, 14, 14205, 14, 7546, 492, 2248, 63, 513, 63, 1618, 63, 4166, 199, 504, 3242, 14, 14205, 14, 3756, 14, 2613, 492, 18033, 7826, 199, 504, 3242, 14, 14205, 14, 3756, 14, 2343, 492, 18033, 5142, 199, 504, 3242, 14, 14205, 14, 1450, 16725, 492, 8053, 16725, 199, 504, 3242, 14, 5265, 492, 664, 63, 452, 63, 2718, 63, 16370, 199, 504, 3242, 14, 1208, 14, 2936, 492, 13323, 63, 2936, 421, 199, 363, 452, 363, 275, 788, 7422, 297, 283, 2227, 63, 1162, 418, 199, 199, 3, 7600, 26, 642, 1077, 506, 282, 11420, 805, 12, 1325, 883, 1133, 506, 282, 3653, 402, 199, 3, 263, 314, 4719, 7037, 370, 314, 10572, 626, 652, 3955, 4409, 314, 675, 402, 291, 199, 3, 263, 315, 282, 2955, 1083, 14, 961, 365, 2597, 1202, 315, 314, 1300, 1021, 367, 199, 3, 263, 32647, 334, 4853, 15, 5265, 15, 8590, 22128, 826, 4343, 647, 9, 199, 318, 2631, 63, 1162, 8, 1162, 304, 272, 340, 440, 1228, 8, 1162, 12, 1211, 304, 267, 372, 1862, 272, 587, 26, 267, 308, 275, 663, 342, 267, 367, 1022, 12, 86, 315, 10849, 8, 1162, 304, 288, 340, 1228, 8, 86, 12, 1211, 304, 355, 308, 14, 873, 1332, 75, 12, 2631, 63, 1162, 8, 86, 1724, 288, 916, 1228, 8, 86, 12, 769, 304, 355, 7645, 275, 942, 355, 367, 1242, 315, 373, 26, 490, 7645, 14, 740, 8, 2227, 63, 1162, 8, 1053, 430, 355, 308, 14, 873, 1332, 75, 12, 2008, 8, 25970, 1724, 288, 587, 26, 355, 308, 14, 873, 1332, 75, 12, 373, 430, 267, 372, 9522, 8, 83, 9, 199, 199, 533, 18033, 8, 1563, 12, 6423, 4352, 12, 24191, 12, 8053, 16725, 304, 339, 347, 636, 826, 721, 277, 12, 5232, 29, 403, 304, 267, 291, 423, 3756, 63, 354, 263, 275, 488, 267, 291, 423, 3756, 63, 515, 263, 275, 488, 267, 291, 423, 3756, 63, 1162, 420, 275, 1211, 342, 267, 291, 423, 3422, 3698, 275, 488, 398, 291, 423, 2343, 260, 275, 488, 267, 291, 423, 2802, 3777, 275, 5232, 267, 291, 423, 8859, 3515, 275, 942, 267, 291, 423, 5714, 258, 275, 942, 267, 291, 423, 1765, 63, 4166, 420, 275, 942, 267, 291, 423, 2232, 63, 4166, 257, 275, 942, 267, 291, 423, 885, 63, 2936, 258, 275, 1211, 342, 267, 291, 423, 3756, 63, 2936, 263, 275, 1211, 342, 267, 291, 423, 72, 350, 63, 1765, 63, 1065, 258, 275, 1211, 342, 267, 291, 423, 12634, 263, 275, 1211, 342, 398, 1613, 8, 7422, 12, 291, 2843, 826, 4533, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 291, 14, 362, 63, 354, 342, 339, 347, 664, 63, 354, 8, 277, 304, 267, 372, 291, 423, 3756, 63, 354, 339, 768, 4639, 272, 347, 2248, 8, 3756, 63, 2613, 12, 5232, 12, 1676, 63, 3756, 29, 403, 304, 267, 862, 26, 288, 327, 710, 9769, 906, 63, 8677, 365, 282, 2600, 402, 4719, 1561, 12, 543, 1924, 2397, 288, 327, 3035, 4573, 2600, 5226, 370, 282, 663, 402, 2633, 288, 327, 2013, 367, 282, 4719, 465, 314, 790, 436, 314, 18033, 342, 909, 6337, 14, 288, 327, 2136, 675, 9522, 370, 1852, 314, 2600, 21197, 14, 953, 1862, 275, 4719, 63, 2613, 14, 362, 63, 3756, 63, 1162, 342, 288, 340, 4719, 63, 2613, 14, 6526, 365, 440, 488, 26, 355, 1862, 459, 6526, 418, 275, 4719, 63, 2613, 14, 6526, 288, 340, 4719, 63, 2613, 14, 2969, 365, 440, 488, 26, 355, 1862, 459, 2969, 418, 275, 4719, 63, 2613, 14, 2969, 288, 19871, 63, 1162, 275, 2631, 63, 1162, 8, 1162, 9, 288, 340, 4719, 63, 2613, 14, 3756, 315, 5232, 14, 15468, 63, 8677, 26, 355, 367, 334, 2373, 12, 4719, 63, 1113, 9, 315, 10849, 8, 2802, 14, 15468, 63, 8677, 59, 3756, 63, 2613, 14, 3756, 4682, 490, 340, 19871, 63, 1162, 508, 2397, 26, 717, 340, 1676, 63, 3756, 26, 1169, 4719, 63, 1113, 14, 525, 63, 1708, 8, 1708, 63, 3756, 9, 717, 372, 4719, 63, 1113, 953, 519, 275, 18033, 8, 2802, 29, 2802, 9, 288, 519, 423, 912, 63, 3756, 63, 576, 8, 3756, 63, 2613, 12, 1676, 63, 3756, 29, 1708, 63, 3756, 9, 953, 340, 4719, 63, 2613, 14, 3756, 440, 315, 5232, 14, 15468, 63, 8677, 26, 355, 5232, 14, 15468, 63, 8677, 59, 3756, 63, 2613, 14, 3756, 61, 275 ]
[ 334, 67, 9, 6029, 13, 7280, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 504, 3816, 492, 10849, 12, 1059, 63, 1313, 199, 199, 646, 6485, 199, 646, 747, 199, 199, 504, 8337, 492, 7793, 17, 199, 199, 504, 3242, 14, 2550, 492, 13358, 12, 31775, 199, 504, 3242, 14, 11059, 492, 3918, 5455, 199, 504, 3242, 14, 14205, 14, 3215, 492, 5024, 1646, 199, 504, 3242, 14, 14205, 14, 1095, 492, 3523, 199, 504, 3242, 14, 14205, 14, 13970, 492, 6423, 4352, 199, 504, 3242, 14, 14205, 14, 14353, 492, 24191, 199, 504, 3242, 14, 14205, 14, 7546, 492, 2248, 63, 513, 63, 1618, 63, 4166, 199, 504, 3242, 14, 14205, 14, 3756, 14, 2613, 492, 18033, 7826, 199, 504, 3242, 14, 14205, 14, 3756, 14, 2343, 492, 18033, 5142, 199, 504, 3242, 14, 14205, 14, 1450, 16725, 492, 8053, 16725, 199, 504, 3242, 14, 5265, 492, 664, 63, 452, 63, 2718, 63, 16370, 199, 504, 3242, 14, 1208, 14, 2936, 492, 13323, 63, 2936, 421, 199, 363, 452, 363, 275, 788, 7422, 297, 283, 2227, 63, 1162, 418, 199, 199, 3, 7600, 26, 642, 1077, 506, 282, 11420, 805, 12, 1325, 883, 1133, 506, 282, 3653, 402, 199, 3, 263, 314, 4719, 7037, 370, 314, 10572, 626, 652, 3955, 4409, 314, 675, 402, 291, 199, 3, 263, 315, 282, 2955, 1083, 14, 961, 365, 2597, 1202, 315, 314, 1300, 1021, 367, 199, 3, 263, 32647, 334, 4853, 15, 5265, 15, 8590, 22128, 826, 4343, 647, 9, 199, 318, 2631, 63, 1162, 8, 1162, 304, 272, 340, 440, 1228, 8, 1162, 12, 1211, 304, 267, 372, 1862, 272, 587, 26, 267, 308, 275, 663, 342, 267, 367, 1022, 12, 86, 315, 10849, 8, 1162, 304, 288, 340, 1228, 8, 86, 12, 1211, 304, 355, 308, 14, 873, 1332, 75, 12, 2631, 63, 1162, 8, 86, 1724, 288, 916, 1228, 8, 86, 12, 769, 304, 355, 7645, 275, 942, 355, 367, 1242, 315, 373, 26, 490, 7645, 14, 740, 8, 2227, 63, 1162, 8, 1053, 430, 355, 308, 14, 873, 1332, 75, 12, 2008, 8, 25970, 1724, 288, 587, 26, 355, 308, 14, 873, 1332, 75, 12, 373, 430, 267, 372, 9522, 8, 83, 9, 199, 199, 533, 18033, 8, 1563, 12, 6423, 4352, 12, 24191, 12, 8053, 16725, 304, 339, 347, 636, 826, 721, 277, 12, 5232, 29, 403, 304, 267, 291, 423, 3756, 63, 354, 263, 275, 488, 267, 291, 423, 3756, 63, 515, 263, 275, 488, 267, 291, 423, 3756, 63, 1162, 420, 275, 1211, 342, 267, 291, 423, 3422, 3698, 275, 488, 398, 291, 423, 2343, 260, 275, 488, 267, 291, 423, 2802, 3777, 275, 5232, 267, 291, 423, 8859, 3515, 275, 942, 267, 291, 423, 5714, 258, 275, 942, 267, 291, 423, 1765, 63, 4166, 420, 275, 942, 267, 291, 423, 2232, 63, 4166, 257, 275, 942, 267, 291, 423, 885, 63, 2936, 258, 275, 1211, 342, 267, 291, 423, 3756, 63, 2936, 263, 275, 1211, 342, 267, 291, 423, 72, 350, 63, 1765, 63, 1065, 258, 275, 1211, 342, 267, 291, 423, 12634, 263, 275, 1211, 342, 398, 1613, 8, 7422, 12, 291, 2843, 826, 4533, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 291, 14, 362, 63, 354, 342, 339, 347, 664, 63, 354, 8, 277, 304, 267, 372, 291, 423, 3756, 63, 354, 339, 768, 4639, 272, 347, 2248, 8, 3756, 63, 2613, 12, 5232, 12, 1676, 63, 3756, 29, 403, 304, 267, 862, 26, 288, 327, 710, 9769, 906, 63, 8677, 365, 282, 2600, 402, 4719, 1561, 12, 543, 1924, 2397, 288, 327, 3035, 4573, 2600, 5226, 370, 282, 663, 402, 2633, 288, 327, 2013, 367, 282, 4719, 465, 314, 790, 436, 314, 18033, 342, 909, 6337, 14, 288, 327, 2136, 675, 9522, 370, 1852, 314, 2600, 21197, 14, 953, 1862, 275, 4719, 63, 2613, 14, 362, 63, 3756, 63, 1162, 342, 288, 340, 4719, 63, 2613, 14, 6526, 365, 440, 488, 26, 355, 1862, 459, 6526, 418, 275, 4719, 63, 2613, 14, 6526, 288, 340, 4719, 63, 2613, 14, 2969, 365, 440, 488, 26, 355, 1862, 459, 2969, 418, 275, 4719, 63, 2613, 14, 2969, 288, 19871, 63, 1162, 275, 2631, 63, 1162, 8, 1162, 9, 288, 340, 4719, 63, 2613, 14, 3756, 315, 5232, 14, 15468, 63, 8677, 26, 355, 367, 334, 2373, 12, 4719, 63, 1113, 9, 315, 10849, 8, 2802, 14, 15468, 63, 8677, 59, 3756, 63, 2613, 14, 3756, 4682, 490, 340, 19871, 63, 1162, 508, 2397, 26, 717, 340, 1676, 63, 3756, 26, 1169, 4719, 63, 1113, 14, 525, 63, 1708, 8, 1708, 63, 3756, 9, 717, 372, 4719, 63, 1113, 953, 519, 275, 18033, 8, 2802, 29, 2802, 9, 288, 519, 423, 912, 63, 3756, 63, 576, 8, 3756, 63, 2613, 12, 1676, 63, 3756, 29, 1708, 63, 3756, 9, 953, 340, 4719, 63, 2613, 14, 3756, 440, 315, 5232, 14, 15468, 63, 8677, 26, 355, 5232, 14, 15468, 63, 8677, 59, 3756, 63, 2613, 14, 3756, 61, 275, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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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 ]
ArnossArnossi/django
django/conf/locale/en_AU/formats.py
504
2117
# -*- encoding: utf-8 -*- # This file is distributed under the same license as the Django package. # from __future__ import unicode_literals # The *_FORMAT strings use the Django date format syntax, # see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date DATE_FORMAT = 'j M Y' # '25 Oct 2006' TIME_FORMAT = 'P' # '2:30 p.m.' DATETIME_FORMAT = 'j M Y, P' # '25 Oct 2006, 2:30 p.m.' YEAR_MONTH_FORMAT = 'F Y' # 'October 2006' MONTH_DAY_FORMAT = 'j F' # '25 October' SHORT_DATE_FORMAT = 'd/m/Y' # '25/10/2006' SHORT_DATETIME_FORMAT = 'd/m/Y P' # '25/10/2006 2:30 p.m.' FIRST_DAY_OF_WEEK = 0 # Sunday # The *_INPUT_FORMATS strings use the Python strftime format syntax, # see http://docs.python.org/library/datetime.html#strftime-strptime-behavior DATE_INPUT_FORMATS = [ '%d/%m/%Y', '%d/%m/%y', # '25/10/2006', '25/10/06' # '%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006' # '%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006' # '%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006' # '%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006' ] DATETIME_INPUT_FORMATS = [ '%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59' '%Y-%m-%d %H:%M:%S.%f', # '2006-10-25 14:30:59.000200' '%Y-%m-%d %H:%M', # '2006-10-25 14:30' '%Y-%m-%d', # '2006-10-25' '%d/%m/%Y %H:%M:%S', # '25/10/2006 14:30:59' '%d/%m/%Y %H:%M:%S.%f', # '25/10/2006 14:30:59.000200' '%d/%m/%Y %H:%M', # '25/10/2006 14:30' '%d/%m/%Y', # '25/10/2006' '%d/%m/%y %H:%M:%S', # '25/10/06 14:30:59' '%d/%m/%y %H:%M:%S.%f', # '25/10/06 14:30:59.000200' '%d/%m/%y %H:%M', # '25/10/06 14:30' '%d/%m/%y', # '25/10/06' ] DECIMAL_SEPARATOR = '.' THOUSAND_SEPARATOR = ',' NUMBER_GROUPING = 3
bsd-3-clause
[ 3, 1882, 2644, 26, 2774, 13, 24, 1882, 199, 3, 961, 570, 365, 1854, 1334, 314, 2011, 4190, 465, 314, 5634, 2559, 14, 199, 3, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 3, 710, 20841, 4807, 3326, 675, 314, 5634, 1434, 1475, 6302, 12, 199, 3, 1937, 1455, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 2374, 15, 1121, 15, 5876, 15, 10372, 12645, 602, 199, 5390, 63, 4807, 275, 283, 74, 603, 1488, 7, 7861, 327, 283, 821, 18365, 8315, 7, 199, 4961, 63, 4807, 275, 283, 48, 7, 9668, 327, 283, 18, 26, 1216, 299, 14, 77, 3530, 199, 12488, 63, 4807, 275, 283, 74, 603, 1488, 12, 510, 7, 3322, 327, 283, 821, 18365, 8315, 12, 499, 26, 1216, 299, 14, 77, 3530, 199, 19216, 63, 16413, 63, 4807, 275, 283, 38, 1488, 7, 5185, 327, 283, 17584, 22459, 8315, 7, 199, 16413, 63, 11655, 63, 4807, 275, 283, 74, 481, 7, 4483, 327, 283, 821, 18365, 22459, 7, 199, 13003, 63, 5390, 63, 4807, 275, 283, 68, 15, 77, 15, 57, 7, 3777, 327, 283, 821, 15, 709, 15, 7968, 7, 199, 13003, 63, 12488, 63, 4807, 275, 283, 68, 15, 77, 15, 57, 510, 7, 755, 327, 283, 821, 15, 709, 15, 7968, 499, 26, 1216, 299, 14, 77, 3530, 199, 12903, 63, 11655, 63, 3359, 63, 24929, 275, 378, 7861, 327, 428, 24759, 199, 199, 3, 710, 20841, 7321, 63, 14019, 3326, 675, 314, 2018, 14053, 1475, 6302, 12, 199, 3, 1937, 1455, 921, 4757, 14, 1548, 14, 1308, 15, 4342, 15, 2083, 14, 1360, 3, 6205, 13, 9866, 13, 17537, 199, 5390, 63, 7321, 63, 14019, 275, 359, 272, 1543, 68, 3149, 77, 3149, 57, 297, 1543, 68, 3149, 77, 3149, 89, 297, 3777, 327, 283, 821, 15, 709, 15, 7968, 297, 283, 821, 15, 709, 15, 1690, 7, 272, 327, 1543, 66, 450, 68, 450, 57, 297, 1543, 66, 450, 68, 12, 450, 57, 297, 3515, 327, 283, 17584, 5661, 8315, 297, 283, 17584, 5661, 12, 8315, 7, 272, 327, 1543, 68, 450, 66, 450, 57, 297, 1543, 68, 450, 66, 12, 450, 57, 297, 3515, 327, 283, 821, 18365, 8315, 297, 283, 821, 18365, 12, 8315, 7, 272, 327, 1543, 34, 450, 68, 450, 57, 297, 1543, 34, 450, 68, 12, 450, 57, 297, 3515, 327, 283, 17584, 22459, 5661, 8315, 297, 283, 17584, 22459, 5661, 12, 8315, 7, 272, 327, 1543, 68, 450, 34, 450, 57, 297, 1543, 68, 450, 34, 12, 450, 57, 297, 3515, 327, 283, 821, 18365, 22459, 8315, 297, 283, 821, 18365, 22459, 12, 8315, 7, 199, 61, 199, 12488, 63, 7321, 63, 14019, 275, 359, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 297, 4483, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 4111, 70, 297, 3777, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 26, 1427, 14, 25080, 7, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 297, 7861, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 7, 272, 1543, 57, 3295, 77, 3295, 68, 297, 12793, 327, 283, 7968, 13, 709, 13, 821, 7, 272, 1543, 68, 3149, 77, 3149, 57, 450, 40, 2689, 45, 2689, 51, 297, 4483, 327, 283, 821, 15, 709, 15, 7968, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 3149, 77, 3149, 57, 450, 40, 2689, 45, 2689, 51, 4111, 70, 297, 3777, 327, 283, 821, 15, 709, 15, 7968, 4329, 26, 1216, 26, 1427, 14, 25080, 7, 272, 1543, 68, 3149, 77, 3149, 57, 450, 40, 2689, 45, 297, 7861, 327, 283, 821, 15, 709, 15, 7968, 4329, 26, 1216, 7, 272, 1543, 68, 3149, 77, 3149, 57, 297, 12793, 327, 283, 821, 15, 709, 15, 7968, 7, 272, 1543, 68, 3149, 77, 3149, 89, 450, 40, 2689, 45, 2689, 51, 297, 4483, 327, 283, 821, 15, 709, 15, 1690, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 3149, 77, 3149, 89, 450, 40, 2689, 45, 2689, 51, 4111, 70, 297, 3777, 327, 283, 821, 15, 709, 15, 1690, 4329, 26, 1216, 26, 1427, 14, 25080, 7, 272, 1543, 68, 3149, 77, 3149, 89, 450, 40, 2689, 45, 297, 7861, 327, 283, 821, 15, 709, 15, 1690, 4329, 26, 1216, 7, 272, 1543, 68, 3149, 77, 3149, 89, 297, 12793, 327, 283, 821, 15, 709, 15, 1690, 7, 199, 61, 199, 23925, 63, 15828, 275, 7815, 199, 28714, 63, 15828, 275, 13647, 199, 9190, 63, 7823, 1206, 275, 650, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2644, 26, 2774, 13, 24, 1882, 199, 3, 961, 570, 365, 1854, 1334, 314, 2011, 4190, 465, 314, 5634, 2559, 14, 199, 3, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 3, 710, 20841, 4807, 3326, 675, 314, 5634, 1434, 1475, 6302, 12, 199, 3, 1937, 1455, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 2374, 15, 1121, 15, 5876, 15, 10372, 12645, 602, 199, 5390, 63, 4807, 275, 283, 74, 603, 1488, 7, 7861, 327, 283, 821, 18365, 8315, 7, 199, 4961, 63, 4807, 275, 283, 48, 7, 9668, 327, 283, 18, 26, 1216, 299, 14, 77, 3530, 199, 12488, 63, 4807, 275, 283, 74, 603, 1488, 12, 510, 7, 3322, 327, 283, 821, 18365, 8315, 12, 499, 26, 1216, 299, 14, 77, 3530, 199, 19216, 63, 16413, 63, 4807, 275, 283, 38, 1488, 7, 5185, 327, 283, 17584, 22459, 8315, 7, 199, 16413, 63, 11655, 63, 4807, 275, 283, 74, 481, 7, 4483, 327, 283, 821, 18365, 22459, 7, 199, 13003, 63, 5390, 63, 4807, 275, 283, 68, 15, 77, 15, 57, 7, 3777, 327, 283, 821, 15, 709, 15, 7968, 7, 199, 13003, 63, 12488, 63, 4807, 275, 283, 68, 15, 77, 15, 57, 510, 7, 755, 327, 283, 821, 15, 709, 15, 7968, 499, 26, 1216, 299, 14, 77, 3530, 199, 12903, 63, 11655, 63, 3359, 63, 24929, 275, 378, 7861, 327, 428, 24759, 199, 199, 3, 710, 20841, 7321, 63, 14019, 3326, 675, 314, 2018, 14053, 1475, 6302, 12, 199, 3, 1937, 1455, 921, 4757, 14, 1548, 14, 1308, 15, 4342, 15, 2083, 14, 1360, 3, 6205, 13, 9866, 13, 17537, 199, 5390, 63, 7321, 63, 14019, 275, 359, 272, 1543, 68, 3149, 77, 3149, 57, 297, 1543, 68, 3149, 77, 3149, 89, 297, 3777, 327, 283, 821, 15, 709, 15, 7968, 297, 283, 821, 15, 709, 15, 1690, 7, 272, 327, 1543, 66, 450, 68, 450, 57, 297, 1543, 66, 450, 68, 12, 450, 57, 297, 3515, 327, 283, 17584, 5661, 8315, 297, 283, 17584, 5661, 12, 8315, 7, 272, 327, 1543, 68, 450, 66, 450, 57, 297, 1543, 68, 450, 66, 12, 450, 57, 297, 3515, 327, 283, 821, 18365, 8315, 297, 283, 821, 18365, 12, 8315, 7, 272, 327, 1543, 34, 450, 68, 450, 57, 297, 1543, 34, 450, 68, 12, 450, 57, 297, 3515, 327, 283, 17584, 22459, 5661, 8315, 297, 283, 17584, 22459, 5661, 12, 8315, 7, 272, 327, 1543, 68, 450, 34, 450, 57, 297, 1543, 68, 450, 34, 12, 450, 57, 297, 3515, 327, 283, 821, 18365, 22459, 8315, 297, 283, 821, 18365, 22459, 12, 8315, 7, 199, 61, 199, 12488, 63, 7321, 63, 14019, 275, 359, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 297, 4483, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 4111, 70, 297, 3777, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 26, 1427, 14, 25080, 7, 272, 1543, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 297, 7861, 327, 283, 7968, 13, 709, 13, 821, 4329, 26, 1216, 7, 272, 1543, 57, 3295, 77, 3295, 68, 297, 12793, 327, 283, 7968, 13, 709, 13, 821, 7, 272, 1543, 68, 3149, 77, 3149, 57, 450, 40, 2689, 45, 2689, 51, 297, 4483, 327, 283, 821, 15, 709, 15, 7968, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 3149, 77, 3149, 57, 450, 40, 2689, 45, 2689, 51, 4111, 70, 297, 3777, 327, 283, 821, 15, 709, 15, 7968, 4329, 26, 1216, 26, 1427, 14, 25080, 7, 272, 1543, 68, 3149, 77, 3149, 57, 450, 40, 2689, 45, 297, 7861, 327, 283, 821, 15, 709, 15, 7968, 4329, 26, 1216, 7, 272, 1543, 68, 3149, 77, 3149, 57, 297, 12793, 327, 283, 821, 15, 709, 15, 7968, 7, 272, 1543, 68, 3149, 77, 3149, 89, 450, 40, 2689, 45, 2689, 51, 297, 4483, 327, 283, 821, 15, 709, 15, 1690, 4329, 26, 1216, 26, 1427, 7, 272, 1543, 68, 3149, 77, 3149, 89, 450, 40, 2689, 45, 2689, 51, 4111, 70, 297, 3777, 327, 283, 821, 15, 709, 15, 1690, 4329, 26, 1216, 26, 1427, 14, 25080, 7, 272, 1543, 68, 3149, 77, 3149, 89, 450, 40, 2689, 45, 297, 7861, 327, 283, 821, 15, 709, 15, 1690, 4329, 26, 1216, 7, 272, 1543, 68, 3149, 77, 3149, 89, 297, 12793, 327, 283, 821, 15, 709, 15, 1690, 7, 199, 61, 199, 23925, 63, 15828, 275, 7815, 199, 28714, 63, 15828, 275, 13647, 199, 9190, 63, 7823, 1206, 275, 650, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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- """ pygments.plugin ~~~~~~~~~~~~~~~ Pygments setuptools plugin interface. The methods defined here also work if setuptools isn't installed but they just return nothing. lexer plugins:: [pygments.lexers] yourlexer = yourmodule:YourLexer formatter plugins:: [pygments.formatters] yourformatter = yourformatter:YourFormatter /.ext = yourformatter:YourFormatter As you can see, you can define extensions for the formatter with a leading slash. syntax plugins:: [pygments.styles] yourstyle = yourstyle:YourStyle filter plugin:: [pygments.filter] yourfilter = yourfilter:YourFilter :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ try: import pkg_resources except ImportError: pkg_resources = None LEXER_ENTRY_POINT = 'pygments.lexers' FORMATTER_ENTRY_POINT = 'pygments.formatters' STYLE_ENTRY_POINT = 'pygments.styles' FILTER_ENTRY_POINT = 'pygments.filters' def find_plugin_lexers(): if pkg_resources is None: return for entrypoint in pkg_resources.iter_entry_points(LEXER_ENTRY_POINT): yield entrypoint.load() def find_plugin_formatters(): if pkg_resources is None: return for entrypoint in pkg_resources.iter_entry_points(FORMATTER_ENTRY_POINT): yield entrypoint.name, entrypoint.load() def find_plugin_styles(): if pkg_resources is None: return for entrypoint in pkg_resources.iter_entry_points(STYLE_ENTRY_POINT): yield entrypoint.name, entrypoint.load() def find_plugin_filters(): if pkg_resources is None: return for entrypoint in pkg_resources.iter_entry_points(FILTER_ENTRY_POINT): yield entrypoint.name, entrypoint.load()
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 13277, 14, 2718, 272, 32202, 23597, 339, 14493, 9116, 3589, 3217, 14, 710, 3102, 3247, 272, 2348, 2597, 1736, 340, 9116, 5712, 1133, 4903, 1325, 2985, 2951, 272, 372, 6548, 14, 339, 10426, 8963, 447, 398, 359, 12173, 14, 12245, 61, 267, 2195, 11729, 275, 2195, 578, 26, 14398, 5838, 339, 9698, 8963, 447, 398, 359, 12173, 14, 24270, 61, 267, 2195, 8911, 275, 2195, 8911, 26, 14398, 7772, 267, 1182, 14, 832, 275, 2195, 8911, 26, 14398, 7772, 339, 3709, 1265, 883, 1937, 12, 1265, 883, 5627, 5478, 367, 314, 9698, 272, 543, 282, 9186, 14457, 14, 339, 6302, 8963, 447, 398, 359, 12173, 14, 12955, 61, 267, 2195, 2487, 275, 2195, 2487, 26, 14398, 6609, 339, 2457, 3589, 447, 398, 359, 12173, 14, 1541, 61, 267, 2195, 1541, 275, 2195, 1541, 26, 14398, 4131, 2378, 520, 7307, 26, 1898, 8315, 13, 6965, 701, 314, 14493, 8099, 12, 1937, 10610, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 2436, 14, 199, 624, 199, 893, 26, 272, 492, 5496, 63, 4435, 199, 2590, 3545, 26, 272, 5496, 63, 4435, 275, 488, 199, 199, 8066, 540, 63, 7285, 63, 7217, 275, 283, 12173, 14, 12245, 7, 199, 4807, 1157, 63, 7285, 63, 7217, 275, 283, 12173, 14, 24270, 7, 199, 18466, 63, 7285, 63, 7217, 275, 283, 12173, 14, 12955, 7, 199, 9905, 63, 7285, 63, 7217, 275, 283, 12173, 14, 4273, 7, 421, 199, 318, 2342, 63, 2718, 63, 12245, 837, 272, 340, 5496, 63, 4435, 365, 488, 26, 267, 372, 272, 367, 2397, 1403, 315, 5496, 63, 4435, 14, 1661, 63, 2373, 63, 3438, 8, 8066, 540, 63, 7285, 63, 7217, 304, 267, 1995, 2397, 1403, 14, 912, 342, 421, 199, 318, 2342, 63, 2718, 63, 24270, 837, 272, 340, 5496, 63, 4435, 365, 488, 26, 267, 372, 272, 367, 2397, 1403, 315, 5496, 63, 4435, 14, 1661, 63, 2373, 63, 3438, 8, 4807, 1157, 63, 7285, 63, 7217, 304, 267, 1995, 2397, 1403, 14, 354, 12, 2397, 1403, 14, 912, 342, 421, 199, 318, 2342, 63, 2718, 63, 12955, 837, 272, 340, 5496, 63, 4435, 365, 488, 26, 267, 372, 272, 367, 2397, 1403, 315, 5496, 63, 4435, 14, 1661, 63, 2373, 63, 3438, 8, 18466, 63, 7285, 63, 7217, 304, 267, 1995, 2397, 1403, 14, 354, 12, 2397, 1403, 14, 912, 342, 421, 199, 318, 2342, 63, 2718, 63, 4273, 837, 272, 340, 5496, 63, 4435, 365, 488, 26, 267, 372, 272, 367, 2397, 1403, 315, 5496, 63, 4435, 14, 1661, 63, 2373, 63, 3438, 8, 9905, 63, 7285, 63, 7217, 304, 267, 1995, 2397, 1403, 14, 354, 12, 2397, 1403, 14, 912, 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 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 13277, 14, 2718, 272, 32202, 23597, 339, 14493, 9116, 3589, 3217, 14, 710, 3102, 3247, 272, 2348, 2597, 1736, 340, 9116, 5712, 1133, 4903, 1325, 2985, 2951, 272, 372, 6548, 14, 339, 10426, 8963, 447, 398, 359, 12173, 14, 12245, 61, 267, 2195, 11729, 275, 2195, 578, 26, 14398, 5838, 339, 9698, 8963, 447, 398, 359, 12173, 14, 24270, 61, 267, 2195, 8911, 275, 2195, 8911, 26, 14398, 7772, 267, 1182, 14, 832, 275, 2195, 8911, 26, 14398, 7772, 339, 3709, 1265, 883, 1937, 12, 1265, 883, 5627, 5478, 367, 314, 9698, 272, 543, 282, 9186, 14457, 14, 339, 6302, 8963, 447, 398, 359, 12173, 14, 12955, 61, 267, 2195, 2487, 275, 2195, 2487, 26, 14398, 6609, 339, 2457, 3589, 447, 398, 359, 12173, 14, 1541, 61, 267, 2195, 1541, 275, 2195, 1541, 26, 14398, 4131, 2378, 520, 7307, 26, 1898, 8315, 13, 6965, 701, 314, 14493, 8099, 12, 1937, 10610, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 2436, 14, 199, 624, 199, 893, 26, 272, 492, 5496, 63, 4435, 199, 2590, 3545, 26, 272, 5496, 63, 4435, 275, 488, 199, 199, 8066, 540, 63, 7285, 63, 7217, 275, 283, 12173, 14, 12245, 7, 199, 4807, 1157, 63, 7285, 63, 7217, 275, 283, 12173, 14, 24270, 7, 199, 18466, 63, 7285, 63, 7217, 275, 283, 12173, 14, 12955, 7, 199, 9905, 63, 7285, 63, 7217, 275, 283, 12173, 14, 4273, 7, 421, 199, 318, 2342, 63, 2718, 63, 12245, 837, 272, 340, 5496, 63, 4435, 365, 488, 26, 267, 372, 272, 367, 2397, 1403, 315, 5496, 63, 4435, 14, 1661, 63, 2373, 63, 3438, 8, 8066, 540, 63, 7285, 63, 7217, 304, 267, 1995, 2397, 1403, 14, 912, 342, 421, 199, 318, 2342, 63, 2718, 63, 24270, 837, 272, 340, 5496, 63, 4435, 365, 488, 26, 267, 372, 272, 367, 2397, 1403, 315, 5496, 63, 4435, 14, 1661, 63, 2373, 63, 3438, 8, 4807, 1157, 63, 7285, 63, 7217, 304, 267, 1995, 2397, 1403, 14, 354, 12, 2397, 1403, 14, 912, 342, 421, 199, 318, 2342, 63, 2718, 63, 12955, 837, 272, 340, 5496, 63, 4435, 365, 488, 26, 267, 372, 272, 367, 2397, 1403, 315, 5496, 63, 4435, 14, 1661, 63, 2373, 63, 3438, 8, 18466, 63, 7285, 63, 7217, 304, 267, 1995, 2397, 1403, 14, 354, 12, 2397, 1403, 14, 912, 342, 421, 199, 318, 2342, 63, 2718, 63, 4273, 837, 272, 340, 5496, 63, 4435, 365, 488, 26, 267, 372, 272, 367, 2397, 1403, 315, 5496, 63, 4435, 14, 1661, 63, 2373, 63, 3438, 8, 9905, 63, 7285, 63, 7217, 304, 267, 1995, 2397, 1403, 14, 354, 12, 2397, 1403, 14, 912, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
hefen1/chromium
components/cronet/tools/cronet_licenses.py
59
2832
#!/usr/bin/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. """Generates the contents of an Cronet LICENSE file for the third-party code. It makes use of src/tools/licenses.py and the README.chromium files on which it depends. Based on android_webview/tools/webview_licenses.py. """ import optparse import os import sys import textwrap REPOSITORY_ROOT = os.path.abspath(os.path.join( os.path.dirname(__file__), '..', '..', '..')) sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools')) import licenses def _ReadFile(path): """Reads a file from disk. Args: path: The path of the file to read, relative to the root of the repository. Returns: The contents of the file as a string. """ return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read() def GenerateLicense(): """Generates the contents of an Cronet LICENSE file for the third-party code. Returns: The contents of the LICENSE file. """ # TODO(mef): Generate list of third_party libraries using checkdeps. third_party_dirs = [ "libevent", "ashmem", "zlib", "modp_b64", "boringssl" ] # Start with Chromium's LICENSE file content = [_ReadFile('LICENSE')] # Add necessary third_party. for directory in sorted(third_party_dirs): metadata = licenses.ParseDir("third_party/" + directory, REPOSITORY_ROOT, require_license_file=True) content.append("-" * 20) content.append(directory) content.append("-" * 20) license_file = metadata['License File'] if license_file and license_file != licenses.NOT_SHIPPED: content.append(_ReadFile(license_file)) return '\n'.join(content) def main(): class FormatterWithNewLines(optparse.IndentedHelpFormatter): def format_description(self, description): paras = description.split('\n') formatted_paras = [textwrap.fill(para, self.width) for para in paras] return '\n'.join(formatted_paras) + '\n' parser = optparse.OptionParser(formatter=FormatterWithNewLines(), usage='%prog command [options]') parser.description = (__doc__ + '\nCommands:\n' \ ' license [filename]\n' \ ' Generate Cronet LICENSE to filename or stdout.\n') (_, args) = parser.parse_args() if not args: parser.print_help() return 1 if args[0] == 'license': if len(args) > 1: print 'Saving license to %s' % args[1] f = open(args[1], "w") try: f.write(GenerateLicense()) finally: f.close() else: print GenerateLicense() return 0 parser.print_help() return 1 if __name__ == '__main__': sys.exit(main())
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1548, 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, 199, 624, 20551, 314, 4072, 402, 376, 30277, 25759, 5113, 570, 367, 314, 10919, 13, 7522, 1233, 14, 199, 199, 7940, 7704, 675, 402, 2928, 15, 2537, 15, 2383, 14, 647, 436, 314, 27781, 14, 13211, 1584, 641, 1314, 199, 390, 8350, 14, 21311, 641, 15516, 63, 2520, 1345, 15, 2537, 15, 2520, 1345, 63, 2383, 14, 647, 14, 199, 624, 199, 199, 646, 8691, 199, 646, 747, 199, 646, 984, 199, 646, 13390, 199, 199, 907, 27998, 5347, 63, 5441, 275, 747, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 904, 8, 272, 747, 14, 515, 14, 3475, 3460, 493, 10139, 19155, 19155, 11541, 1333, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 515, 14, 904, 8, 907, 27998, 5347, 63, 5441, 12, 283, 2537, 1333, 199, 646, 12378, 199, 199, 318, 485, 32356, 8, 515, 304, 523, 408, 23614, 282, 570, 687, 4543, 14, 523, 3033, 26, 272, 931, 26, 710, 931, 402, 314, 570, 370, 1586, 12, 3847, 370, 314, 1738, 402, 314, 7611, 14, 523, 1803, 26, 272, 710, 4072, 402, 314, 570, 465, 282, 1059, 14, 523, 408, 523, 372, 1551, 8, 736, 14, 515, 14, 904, 8, 907, 27998, 5347, 63, 5441, 12, 931, 395, 283, 4848, 1959, 739, 342, 421, 199, 318, 7958, 3761, 837, 523, 408, 20551, 314, 4072, 402, 376, 30277, 25759, 5113, 570, 367, 314, 10919, 13, 7522, 1233, 14, 523, 1803, 26, 272, 710, 4072, 402, 314, 5113, 570, 14, 523, 408, 523, 327, 3254, 8, 278, 70, 304, 7958, 769, 402, 10919, 63, 7522, 8363, 1808, 1104, 5846, 14, 523, 10919, 63, 7522, 63, 3220, 275, 359, 272, 298, 773, 1430, 401, 272, 298, 1119, 5286, 401, 272, 298, 15371, 401, 272, 298, 1494, 80, 63, 66, 772, 401, 272, 298, 66, 6854, 4266, 2, 523, 1622, 819, 327, 7707, 543, 12051, 1159, 5113, 570, 523, 1564, 275, 15500, 32356, 360, 3961, 5440, 819, 327, 2654, 5784, 10919, 63, 7522, 14, 523, 367, 2082, 315, 3355, 8, 11470, 63, 7522, 63, 3220, 304, 272, 3341, 275, 12378, 14, 4003, 3567, 480, 11470, 63, 7522, 6687, 435, 2082, 12, 5363, 27998, 5347, 63, 5441, 12, 639, 4409, 63, 1682, 63, 493, 29, 549, 9, 272, 1564, 14, 740, 6096, 2, 627, 3388, 9, 272, 1564, 14, 740, 8, 3619, 9, 272, 1564, 14, 740, 6096, 2, 627, 3388, 9, 272, 4190, 63, 493, 275, 3341, 459, 3761, 3814, 418, 272, 340, 4190, 63, 493, 436, 4190, 63, 493, 1137, 12378, 14, 4609, 63, 3234, 1772, 19359, 26, 489, 1564, 14, 740, 1547, 32356, 8, 1682, 63, 493, 430, 819, 372, 1557, 78, 1370, 904, 8, 1317, 9, 421, 199, 318, 2446, 837, 523, 1021, 31084, 3007, 4665, 9863, 8, 2992, 1122, 14, 607, 14032, 22779, 304, 272, 347, 1475, 63, 1802, 8, 277, 12, 1369, 304, 489, 623, 305, 275, 1369, 14, 1294, 2258, 78, 358, 489, 7871, 63, 462, 305, 275, 359, 505, 3823, 14, 4498, 8, 12227, 12, 291, 14, 2063, 9, 367, 12665, 315, 623, 305, 61, 489, 372, 1557, 78, 1370, 904, 8, 15317, 63, 462, 305, 9, 435, 1557, 78, 7, 819, 1798, 275, 8691, 14, 14553, 8, 8911, 29, 7772, 3007, 4665, 9863, 1062, 639, 4503, 9569, 6595, 1414, 359, 1419, 10374, 523, 1798, 14, 1802, 275, 25373, 1301, 363, 435, 2432, 1557, 78, 14680, 3427, 78, 7, 971, 2432, 283, 221, 4190, 359, 1501, 7272, 78, 7, 971, 2432, 283, 259, 7958, 30277, 25759, 5113, 370, 1788, 503, 3839, 3134, 78, 358, 523, 27017, 1249, 9, 275, 1798, 14, 1122, 63, 589, 342, 523, 340, 440, 1249, 26, 272, 1798, 14, 1361, 63, 3437, 342, 272, 372, 413, 819, 340, 1249, 59, 16, 61, 508, 283, 1682, 356, 272, 340, 822, 8, 589, 9, 690, 413, 26, 489, 870, 283, 30125, 4190, 370, 450, 83, 7, 450, 1249, 59, 17, 61, 489, 289, 275, 1551, 8, 589, 59, 17, 467, 298, 87, 531, 489, 862, 26, 267, 289, 14, 952, 8, 6864, 3761, 1012, 489, 3753, 26, 267, 289, 14, 1600, 342, 272, 587, 26, 489, 870, 7958, 3761, 342, 272, 372, 378, 819, 1798, 14, 1361, 63, 3437, 342, 523, 372, 413, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 984, 14, 2224, 8, 973, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 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, 199, 624, 20551, 314, 4072, 402, 376, 30277, 25759, 5113, 570, 367, 314, 10919, 13, 7522, 1233, 14, 199, 199, 7940, 7704, 675, 402, 2928, 15, 2537, 15, 2383, 14, 647, 436, 314, 27781, 14, 13211, 1584, 641, 1314, 199, 390, 8350, 14, 21311, 641, 15516, 63, 2520, 1345, 15, 2537, 15, 2520, 1345, 63, 2383, 14, 647, 14, 199, 624, 199, 199, 646, 8691, 199, 646, 747, 199, 646, 984, 199, 646, 13390, 199, 199, 907, 27998, 5347, 63, 5441, 275, 747, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 904, 8, 272, 747, 14, 515, 14, 3475, 3460, 493, 10139, 19155, 19155, 11541, 1333, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 515, 14, 904, 8, 907, 27998, 5347, 63, 5441, 12, 283, 2537, 1333, 199, 646, 12378, 199, 199, 318, 485, 32356, 8, 515, 304, 523, 408, 23614, 282, 570, 687, 4543, 14, 523, 3033, 26, 272, 931, 26, 710, 931, 402, 314, 570, 370, 1586, 12, 3847, 370, 314, 1738, 402, 314, 7611, 14, 523, 1803, 26, 272, 710, 4072, 402, 314, 570, 465, 282, 1059, 14, 523, 408, 523, 372, 1551, 8, 736, 14, 515, 14, 904, 8, 907, 27998, 5347, 63, 5441, 12, 931, 395, 283, 4848, 1959, 739, 342, 421, 199, 318, 7958, 3761, 837, 523, 408, 20551, 314, 4072, 402, 376, 30277, 25759, 5113, 570, 367, 314, 10919, 13, 7522, 1233, 14, 523, 1803, 26, 272, 710, 4072, 402, 314, 5113, 570, 14, 523, 408, 523, 327, 3254, 8, 278, 70, 304, 7958, 769, 402, 10919, 63, 7522, 8363, 1808, 1104, 5846, 14, 523, 10919, 63, 7522, 63, 3220, 275, 359, 272, 298, 773, 1430, 401, 272, 298, 1119, 5286, 401, 272, 298, 15371, 401, 272, 298, 1494, 80, 63, 66, 772, 401, 272, 298, 66, 6854, 4266, 2, 523, 1622, 819, 327, 7707, 543, 12051, 1159, 5113, 570, 523, 1564, 275, 15500, 32356, 360, 3961, 5440, 819, 327, 2654, 5784, 10919, 63, 7522, 14, 523, 367, 2082, 315, 3355, 8, 11470, 63, 7522, 63, 3220, 304, 272, 3341, 275, 12378, 14, 4003, 3567, 480, 11470, 63, 7522, 6687, 435, 2082, 12, 5363, 27998, 5347, 63, 5441, 12, 639, 4409, 63, 1682, 63, 493, 29, 549, 9, 272, 1564, 14, 740, 6096, 2, 627, 3388, 9, 272, 1564, 14, 740, 8, 3619, 9, 272, 1564, 14, 740, 6096, 2, 627, 3388, 9, 272, 4190, 63, 493, 275, 3341, 459, 3761, 3814, 418, 272, 340, 4190, 63, 493, 436, 4190, 63, 493, 1137, 12378, 14, 4609, 63, 3234, 1772, 19359, 26, 489, 1564, 14, 740, 1547, 32356, 8, 1682, 63, 493, 430, 819, 372, 1557, 78, 1370, 904, 8, 1317, 9, 421, 199, 318, 2446, 837, 523, 1021, 31084, 3007, 4665, 9863, 8, 2992, 1122, 14, 607, 14032, 22779, 304, 272, 347, 1475, 63, 1802, 8, 277, 12, 1369, 304, 489, 623, 305, 275, 1369, 14, 1294, 2258, 78, 358, 489, 7871, 63, 462, 305, 275, 359, 505, 3823, 14, 4498, 8, 12227, 12, 291, 14, 2063, 9, 367, 12665, 315, 623, 305, 61, 489, 372, 1557, 78, 1370, 904, 8, 15317, 63, 462, 305, 9, 435, 1557, 78, 7, 819, 1798, 275, 8691, 14, 14553, 8, 8911, 29, 7772, 3007, 4665, 9863, 1062, 639, 4503, 9569, 6595, 1414, 359, 1419, 10374, 523, 1798, 14, 1802, 275, 25373, 1301, 363, 435, 2432, 1557, 78, 14680, 3427, 78, 7, 971, 2432, 283, 221, 4190, 359, 1501, 7272, 78, 7, 971, 2432, 283, 259, 7958, 30277, 25759, 5113, 370, 1788, 503, 3839, 3134, 78, 358, 523, 27017, 1249, 9, 275, 1798, 14, 1122, 63, 589, 342, 523, 340, 440, 1249, 26, 272, 1798, 14, 1361, 63, 3437, 342, 272, 372, 413, 819, 340, 1249, 59, 16, 61, 508, 283, 1682, 356, 272, 340, 822, 8, 589, 9, 690, 413, 26, 489, 870, 283, 30125, 4190, 370, 450, 83, 7, 450, 1249, 59, 17, 61, 489, 289, 275, 1551, 8, 589, 59, 17, 467, 298, 87, 531, 489, 862, 26, 267, 289, 14, 952, 8, 6864, 3761, 1012, 489, 3753, 26, 267, 289, 14, 1600, 342, 272, 587, 26, 489, 870, 7958, 3761, 342, 272, 372, 378, 819, 1798, 14, 1361, 63, 3437, 342, 523, 372, 413, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 523, 984, 14, 2224, 8, 973, 1012, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Volcanoscar/omim
3party/freetype/src/tools/docmaker/tohtml.py
109
21251
# # tohtml.py # # A sub-class container of the `Formatter' class to produce HTML. # # Copyright 2002-2015 by # David Turner. # # This file is part of the FreeType project, and may only be used, # modified, and distributed under the terms of the FreeType project # license, LICENSE.TXT. By continuing to use, modify, or distribute # this file you indicate that you have read the license and # understand and accept it fully. # The parent class is contained in file `formatter.py'. from sources import * from content import * from formatter import * import time # The following strings define the HTML header used by all generated pages. html_header_1 = """\ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>\ """ html_header_2 = """\ API Reference</title> <style type="text/css"> a:link { color: #0000EF; } a:visited { color: #51188E; } a:hover { color: #FF0000; } body { font-family: Verdana, Geneva, Arial, Helvetica, serif; color: #000000; background: #FFFFFF; width: 87%; margin: auto; } div.section { width: 75%; margin: auto; } div.section hr { margin: 4ex 0 1ex 0; } div.section h4 { background-color: #EEEEFF; font-size: medium; font-style: oblique; font-weight: bold; margin: 3ex 0 1.5ex 9%; padding: 0.3ex 0 0.3ex 1%; } div.section p { margin: 1.5ex 0 1.5ex 10%; } div.section pre { margin: 3ex 0 3ex 9%; background-color: #D6E8FF; padding: 2ex 0 2ex 1%; } div.section table.fields { width: 90%; margin: 1.5ex 0 1.5ex 10%; } div.section table.toc { width: 95%; margin: 1.5ex 0 1.5ex 5%; } div.timestamp { text-align: center; font-size: 69%; margin: 1.5ex 0 1.5ex 0; } h1 { text-align: center; } h3 { font-size: medium; margin: 4ex 0 1.5ex 0; } p { text-align: justify; } pre.colored { color: blue; } span.keyword { font-family: monospace; text-align: left; white-space: pre; color: darkblue; } table.fields td.val { font-weight: bold; text-align: right; width: 30%; vertical-align: baseline; padding: 1ex 1em 1ex 0; } table.fields td.desc { vertical-align: baseline; padding: 1ex 0 1ex 1em; } table.fields td.desc p:first-child { margin: 0; } table.fields td.desc p { margin: 1.5ex 0 0 0; } table.index { margin: 6ex auto 6ex auto; border: 0; border-collapse: separate; border-spacing: 1em 0.3ex; } table.index tr { padding: 0; } table.index td { padding: 0; } table.index-toc-link { width: 100%; border: 0; border-spacing: 0; margin: 1ex 0 1ex 0; } table.index-toc-link td.left { padding: 0 0.5em 0 0.5em; font-size: 83%; text-align: left; } table.index-toc-link td.middle { padding: 0 0.5em 0 0.5em; font-size: 83%; text-align: center; } table.index-toc-link td.right { padding: 0 0.5em 0 0.5em; font-size: 83%; text-align: right; } table.synopsis { margin: 6ex auto 6ex auto; border: 0; border-collapse: separate; border-spacing: 2em 0.6ex; } table.synopsis tr { padding: 0; } table.synopsis td { padding: 0; } table.toc td.link { width: 30%; text-align: right; vertical-align: baseline; padding: 1ex 1em 1ex 0; } table.toc td.desc { vertical-align: baseline; padding: 1ex 0 1ex 1em; text-align: left; } table.toc td.desc p:first-child { margin: 0; text-align: left; } table.toc td.desc p { margin: 1.5ex 0 0 0; text-align: left; } </style> </head> <body> """ html_header_3l = """ <table class="index-toc-link"><tr><td class="left">[<a href="\ """ html_header_3r = """ <table class="index-toc-link"><tr><td class="right">[<a href="\ """ html_header_4 = """\ ">Index</a>]</td><td class="right">[<a href="\ """ html_header_5t = """\ ">TOC</a>]</td></tr></table> <h1>\ """ html_header_5i = """\ ">Index</a>]</td></tr></table> <h1>\ """ html_header_6 = """\ API Reference</h1> """ # The HTML footer used by all generated pages. html_footer = """\ </body> </html>\ """ # The header and footer used for each section. section_title_header = "<h1>" section_title_footer = "</h1>" # The header and footer used for code segments. code_header = '<pre class="colored">' code_footer = '</pre>' # Paragraph header and footer. para_header = "<p>" para_footer = "</p>" # Block header and footer. block_header = '<div class="section">' block_footer_start = """\ <hr> <table class="index-toc-link"><tr><td class="left">[<a href="\ """ block_footer_middle = """\ ">Index</a>]</td>\ <td class="middle">[<a href="#">Top</a>]</td>\ <td class="right">[<a href="\ """ block_footer_end = """\ ">TOC</a>]</td></tr></table></div> """ # Description header/footer. description_header = "" description_footer = "" # Marker header/inter/footer combination. marker_header = "<h4>" marker_inter = "</h4>" marker_footer = "" # Header location header/footer. header_location_header = "<p>" header_location_footer = "</p>" # Source code extracts header/footer. source_header = "<pre>" source_footer = "</pre>" # Chapter header/inter/footer. chapter_header = """\ <div class="section"> <h2>\ """ chapter_inter = '</h2>' chapter_footer = '</div>' # Index footer. index_footer_start = """\ <hr> <table class="index-toc-link"><tr><td class="right">[<a href="\ """ index_footer_end = """\ ">TOC</a>]</td></tr></table> """ # TOC footer. toc_footer_start = """\ <hr> <table class="index-toc-link"><tr><td class="left">[<a href="\ """ toc_footer_end = """\ ">Index</a>]</td></tr></table> """ # Source language keyword coloration and styling. keyword_prefix = '<span class="keyword">' keyword_suffix = '</span>' section_synopsis_header = '<h2>Synopsis</h2>' section_synopsis_footer = '' # Translate a single line of source to HTML. This converts `<', `>', and # `&' into `&lt;',`&gt;', and `&amp;'. # def html_quote( line ): result = string.replace( line, "&", "&amp;" ) result = string.replace( result, "<", "&lt;" ) result = string.replace( result, ">", "&gt;" ) return result ################################################################ ## ## HTML FORMATTER CLASS ## class HtmlFormatter( Formatter ): def __init__( self, processor, project_title, file_prefix ): Formatter.__init__( self, processor ) global html_header_1 global html_header_2 global html_header_3l, html_header_3r global html_header_4 global html_header_5t, html_header_5i global html_header_6 global html_footer if file_prefix: file_prefix = file_prefix + "-" else: file_prefix = "" self.headers = processor.headers self.project_title = project_title self.file_prefix = file_prefix self.html_header = ( html_header_1 + project_title + html_header_2 + html_header_3l + file_prefix + "index.html" + html_header_4 + file_prefix + "toc.html" + html_header_5t + project_title + html_header_6 ) self.html_index_header = ( html_header_1 + project_title + html_header_2 + html_header_3r + file_prefix + "toc.html" + html_header_5t + project_title + html_header_6 ) self.html_toc_header = ( html_header_1 + project_title + html_header_2 + html_header_3l + file_prefix + "index.html" + html_header_5i + project_title + html_header_6 ) self.html_footer = ( '<div class="timestamp">generated on ' + time.asctime( time.localtime( time.time() ) ) + "</div>" + html_footer ) self.columns = 3 def make_section_url( self, section ): return self.file_prefix + section.name + ".html" def make_block_url( self, block, name = None ): if name == None: name = block.name return self.make_section_url( block.section ) + "#" + name def make_html_word( self, word ): """Analyze a simple word to detect cross-references and markup.""" # handle cross-references m = re_crossref.match( word ) if m: try: name = m.group( 1 ) rest = m.group( 2 ) block = self.identifiers[name] url = self.make_block_url( block ) return '<a href="' + url + '">' + name + '</a>' + rest except: # we detected a cross-reference to an unknown item sys.stderr.write( "WARNING: undefined cross reference" + " '" + name + "'.\n" ) return '?' + name + '?' + rest # handle markup for italic and bold m = re_italic.match( word ) if m: name = m.group( 1 ) rest = m.group( 2 ) return '<i>' + name + '</i>' + rest m = re_bold.match( word ) if m: name = m.group( 1 ) rest = m.group( 2 ) return '<b>' + name + '</b>' + rest return html_quote( word ) def make_html_para( self, words ): """Convert words of a paragraph into tagged HTML text. Also handle cross references.""" line = "" if words: line = self.make_html_word( words[0] ) for word in words[1:]: line = line + " " + self.make_html_word( word ) # handle hyperlinks line = re_url.sub( r'<a href="\1">\1</a>', line ) # convert `...' quotations into real left and right single quotes line = re.sub( r"(^|\W)`(.*?)'(\W|$)", r'\1&lsquo;\2&rsquo;\3', line ) # convert tilde into non-breakable space line = string.replace( line, "~", "&nbsp;" ) return para_header + line + para_footer def make_html_code( self, lines ): """Convert a code sequence to HTML.""" line = code_header + '\n' for l in lines: line = line + html_quote( l ) + '\n' return line + code_footer def make_html_items( self, items ): """Convert a field's content into HTML.""" lines = [] for item in items: if item.lines: lines.append( self.make_html_code( item.lines ) ) else: lines.append( self.make_html_para( item.words ) ) return string.join( lines, '\n' ) def print_html_items( self, items ): print self.make_html_items( items ) def print_html_field( self, field ): if field.name: print( '<table><tr valign="top"><td><b>' + field.name + "</b></td><td>" ) print self.make_html_items( field.items ) if field.name: print "</td></tr></table>" def html_source_quote( self, line, block_name = None ): result = "" while line: m = re_source_crossref.match( line ) if m: name = m.group( 2 ) prefix = html_quote( m.group( 1 ) ) length = len( m.group( 0 ) ) if name == block_name: # this is the current block name, if any result = result + prefix + '<b>' + name + '</b>' elif re_source_keywords.match( name ): # this is a C keyword result = ( result + prefix + keyword_prefix + name + keyword_suffix ) elif name in self.identifiers: # this is a known identifier block = self.identifiers[name] id = block.name # link to a field ID if possible for markup in block.markups: if markup.tag == 'values': for field in markup.fields: if field.name: id = name result = ( result + prefix + '<a href="' + self.make_block_url( block, id ) + '">' + name + '</a>' ) else: result = result + html_quote( line[:length] ) line = line[length:] else: result = result + html_quote( line ) line = [] return result def print_html_field_list( self, fields ): print '<table class="fields">' for field in fields: print ( '<tr><td class="val" id="' + field.name + '">' + field.name + '</td><td class="desc">' ) self.print_html_items( field.items ) print "</td></tr>" print "</table>" def print_html_markup( self, markup ): table_fields = [] for field in markup.fields: if field.name: # We begin a new series of field or value definitions. We # record them in the `table_fields' list before outputting # all of them as a single table. table_fields.append( field ) else: if table_fields: self.print_html_field_list( table_fields ) table_fields = [] self.print_html_items( field.items ) if table_fields: self.print_html_field_list( table_fields ) # # formatting the index # def index_enter( self ): print self.html_index_header self.index_items = {} def index_name_enter( self, name ): block = self.identifiers[name] url = self.make_block_url( block ) self.index_items[name] = url def index_exit( self ): # `block_index' already contains the sorted list of index names count = len( self.block_index ) rows = ( count + self.columns - 1 ) // self.columns print '<table class="index">' for r in range( rows ): line = "<tr>" for c in range( self.columns ): i = r + c * rows if i < count: bname = self.block_index[r + c * rows] url = self.index_items[bname] line = ( line + '<td><a href="' + url + '">' + bname + '</a></td>' ) else: line = line + '<td></td>' line = line + "</tr>" print line print "</table>" print( index_footer_start + self.file_prefix + "toc.html" + index_footer_end ) print self.html_footer self.index_items = {} def index_dump( self, index_filename = None ): if index_filename == None: index_filename = self.file_prefix + "index.html" Formatter.index_dump( self, index_filename ) # # formatting the table of contents # def toc_enter( self ): print self.html_toc_header print "<h1>Table of Contents</h1>" def toc_chapter_enter( self, chapter ): print chapter_header + string.join( chapter.title ) + chapter_inter print '<table class="toc">' def toc_section_enter( self, section ): print ( '<tr><td class="link">' + '<a href="' + self.make_section_url( section ) + '">' + section.title + '</a></td><td class="desc">' ) print self.make_html_para( section.abstract ) def toc_section_exit( self, section ): print "</td></tr>" def toc_chapter_exit( self, chapter ): print "</table>" print chapter_footer def toc_index( self, index_filename ): print( chapter_header + '<a href="' + index_filename + '">Global Index</a>' + chapter_inter + chapter_footer ) def toc_exit( self ): print( toc_footer_start + self.file_prefix + "index.html" + toc_footer_end ) print self.html_footer def toc_dump( self, toc_filename = None, index_filename = None ): if toc_filename == None: toc_filename = self.file_prefix + "toc.html" if index_filename == None: index_filename = self.file_prefix + "index.html" Formatter.toc_dump( self, toc_filename, index_filename ) # # formatting sections # def section_enter( self, section ): print self.html_header print section_title_header + section.title + section_title_footer maxwidth = 0 for b in section.blocks.values(): if len( b.name ) > maxwidth: maxwidth = len( b.name ) width = 70 # XXX magic number if maxwidth > 0: # print section synopsis print section_synopsis_header print '<table class="synopsis">' columns = width // maxwidth if columns < 1: columns = 1 count = len( section.block_names ) # don't handle last entry if it is empty if section.block_names[-1] == "/empty/": count -= 1 rows = ( count + columns - 1 ) // columns for r in range( rows ): line = "<tr>" for c in range( columns ): i = r + c * rows line = line + '<td>' if i < count: name = section.block_names[i] if name == "/empty/": # it can happen that a complete row is empty, and # without a proper `filler' the browser might # collapse the row to a much smaller height (or # even omit it completely) line = line + "&nbsp;" else: line = ( line + '<a href="#' + name + '">' + name + '</a>' ) line = line + '</td>' line = line + "</tr>" print line print "</table>" print section_synopsis_footer print description_header print self.make_html_items( section.description ) print description_footer def block_enter( self, block ): print block_header # place html anchor if needed if block.name: print( '<h3 id="' + block.name + '">' + block.name + '</h3>' ) # dump the block C source lines now if block.code: header = '' for f in self.headers.keys(): if block.source.filename.find( f ) >= 0: header = self.headers[f] + ' (' + f + ')' break # if not header: # sys.stderr.write( # "WARNING: No header macro for" # + " '" + block.source.filename + "'.\n" ) if header: print ( header_location_header + 'Defined in ' + header + '.' + header_location_footer ) print source_header for l in block.code: print self.html_source_quote( l, block.name ) print source_footer def markup_enter( self, markup, block ): if markup.tag == "description": print description_header else: print marker_header + markup.tag + marker_inter self.print_html_markup( markup ) def markup_exit( self, markup, block ): if markup.tag == "description": print description_footer else: print marker_footer def block_exit( self, block ): print( block_footer_start + self.file_prefix + "index.html" + block_footer_middle + self.file_prefix + "toc.html" + block_footer_end ) def section_exit( self, section ): print html_footer def section_dump_all( self ): for section in self.sections: self.section_dump( section, self.file_prefix + section.name + '.html' ) # eof
apache-2.0
[ 3, 199, 3, 221, 370, 1360, 14, 647, 199, 3, 199, 3, 259, 437, 1007, 13, 533, 3970, 402, 314, 658, 7772, 7, 1021, 370, 7389, 4163, 14, 199, 3, 199, 3, 221, 1898, 14790, 13, 7806, 701, 199, 3, 221, 20232, 16147, 281, 14, 199, 3, 199, 3, 221, 961, 570, 365, 1777, 402, 314, 2868, 804, 2199, 12, 436, 1443, 1454, 506, 1202, 12, 199, 3, 221, 6042, 12, 436, 1854, 1334, 314, 2895, 402, 314, 2868, 804, 2199, 199, 3, 221, 4190, 12, 5113, 14, 17715, 14, 221, 4885, 32620, 370, 675, 12, 2811, 12, 503, 11207, 199, 3, 221, 642, 570, 1265, 6623, 626, 1265, 1172, 1586, 314, 4190, 436, 199, 3, 221, 20647, 436, 4729, 652, 9999, 14, 199, 199, 3, 710, 1676, 1021, 365, 10470, 315, 570, 658, 8911, 14, 647, 1370, 421, 199, 504, 5274, 492, 627, 199, 504, 1564, 492, 627, 199, 504, 9698, 492, 627, 199, 199, 646, 900, 421, 199, 3, 710, 2569, 3326, 5627, 314, 4163, 1406, 1202, 701, 1006, 4046, 6497, 14, 199, 1360, 63, 1291, 63, 17, 275, 9638, 199, 11230, 16556, 4163, 21755, 21486, 55, 19, 35, 501, 21156, 4163, 841, 14, 614, 19894, 1588, 279, 501, 742, 2, 199, 2, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 1360, 20, 15, 320, 3362, 14, 15662, 1743, 199, 28, 1360, 30, 199, 28, 2993, 30, 199, 28, 2024, 1455, 13, 20146, 628, 2714, 13, 804, 2, 1564, 628, 505, 15, 1360, 27, 5960, 29, 1624, 13, 24, 1743, 199, 28, 1213, 3072, 199, 624, 199, 199, 1360, 63, 1291, 63, 18, 275, 9638, 199, 3261, 10944, 1108, 1213, 30, 199, 28, 2487, 730, 628, 505, 15, 3919, 1743, 523, 282, 26, 1073, 469, 3164, 26, 327, 993, 14153, 27, 789, 523, 282, 26, 21736, 469, 3164, 26, 327, 27176, 1299, 37, 27, 789, 523, 282, 26, 22797, 469, 3164, 26, 327, 1665, 993, 27, 789, 819, 2396, 469, 5023, 13, 6606, 26, 5444, 68, 6738, 12, 598, 6349, 3042, 12, 437, 1383, 12, 869, 25911, 12, 542, 20546, 27, 268, 3164, 26, 327, 3273, 27, 268, 8020, 26, 327, 6968, 1665, 27, 268, 3462, 26, 10513, 5, 27, 268, 11042, 26, 2599, 27, 789, 819, 9073, 14, 2792, 469, 3462, 26, 13098, 5, 27, 355, 11042, 26, 2599, 27, 789, 523, 9073, 14, 2792, 16140, 469, 11042, 26, 841, 476, 378, 413, 476, 378, 27, 789, 523, 9073, 14, 2792, 394, 20, 469, 8020, 13, 2326, 26, 327, 8699, 8699, 1665, 27, 673, 5023, 13, 890, 26, 21576, 27, 673, 5023, 13, 2487, 26, 2607, 317, 544, 27, 673, 5023, 13, 3463, 26, 17268, 27, 673, 11042, 26, 650, 476, 378, 413, 14, 21, 476, 1749, 5, 27, 673, 6273, 26, 378, 14, 19, 476, 378, 378, 14, 19, 476, 413, 5, 27, 789, 523, 9073, 14, 2792, 299, 469, 11042, 26, 413, 14, 21, 476, 378, 413, 14, 21, 476, 1616, 5, 27, 789, 523, 9073, 14, 2792, 876, 469, 11042, 26, 650, 476, 378, 650, 476, 1749, 5, 27, 490, 8020, 13, 2326, 26, 327, 36, 22, 37, 24, 1665, 27, 490, 6273, 26, 499, 476, 378, 499, 476, 413, 5, 27, 789, 523, 9073, 14, 2792, 1817, 14, 955, 469, 3462, 26, 9137, 5, 27, 2490, 11042, 26, 413, 14, 21, 476, 378, 413, 14, 21, 476, 1616, 5, 27, 789, 523, 9073, 14, 2792, 1817, 14, 13255, 469, 3462, 26, 16102, 5, 27, 2079, 11042, 26, 413, 14, 21, 476, 378, 413, 14, 21, 476, 959, 5, 27, 789, 523, 9073, 14, 3954, 469, 1318, 13, 5743, 26, 8126, 27, 2116, 5023, 13, 890, 26, 14610, 5, 27, 2116, 11042, 26, 413, 14, 21, 476, 378, 413, 14, 21, 476, 378, 27, 789, 819, 394, 17, 469, 1318, 13, 5743, 26, 8126, 27, 789, 523, 394, 19, 469, 5023, 13, 890, 26, 21576, 27, 2126, 11042, 26, 841, 476, 378, 413, 14, 21, 476, 378, 27, 789, 819, 299, 469, 1318, 13, 5743, 26, 2951, 2021, 27, 789, 819, 876, 14, 331, 21252, 469, 3164, 26, 10030, 27, 789, 819, 13598, 14, 6691, 469, 5023, 13, 6606, 26, 3485, 17601, 27, 326, 1318, 13, 5743, 26, 3602, 27, 326, 10424, 13, 2638, 26, 876, 27, 326, 3164, 26, 23531, 6304, 27, 789, 819, 1817, 14, 955, 12749, 14, 637, 469, 5023, 13, 3463, 26, 17268, 27, 717, 1318, 13, 5743, 26, 2451, 27, 717, 3462, 26, 4233, 5, 27, 717, 13763, 13, 5743, 26, 18828, 27, 717, 6273, 26, 413, 476, 413, 5633, 413, 476, 378, 27, 789, 523, 1817, 14, 955, 12749, 14, 3257, 469, 13763, 13, 5743, 26, 18828, 27, 586, 6273, 26, 413, 476, 378, 413, 476, 413, 5633, 27, 789, 523, 1817, 14, 955, 12749, 14, 3257, 299, 26, 2246, 13, 1739, 469, 11042, 26, 378, 27, 789, 523, 1817, 14, 955, 12749, 14, 3257, 299, 469, 11042, 26, 413, 14, 21, 476, 378, 378, 378, 27, 789, 523, 1817, 14, 1080, 469, 11042, 26, 1227, 476, 2599, 1227, 476, 2599, 27, 355, 9162, 26, 378, 27, 355, 9162, 13, 20681, 26, 7396, 27, 355, 9162, 13, 15880, 26, 413, 5633, 378, 14, 19, 476, 27, 789, 523, 1817, 14, 1080, 5651, 469, 6273, 26, 378, 27, 789, 523, 1817, 14, 1080, 12749, 469, 6273, 26, 378, 27, 789, 523, 1817, 14, 1080, 13, 13255, 13, 1073, 469, 3462, 26, 2948, 5, 27, 586, 9162, 26, 378, 27, 586, 9162, 13, 15880, 26, 378, 27, 586, 11042, 26, 413, 476, 378, 413, 476, 378, 27, 789, 523, 1817, 14, 1080, 13, 13255, 13, 1073, 12749, 14, 3039, 469, 6273, 26, 378, 378, 14, 21, 5633, 378, 378, 14, 21, 5633, 27, 639, 5023, 13, 890, 26, 20582, 5, 27, 639, 1318, 13, 5743, 26, 3602, 27, 789, 523, 1817, 14, 1080, 13, 13255, 13, 1073, 12749, 14, 14885, 469, 6273, 26, 378, 378, 14, 21, 5633, 378, 378, 14, 21, 5633, 27, 3521, 5023, 13, 890, 26, 20582, 5, 27, 3521, 1318, 13, 5743, 26, 8126, 27, 789, 523, 1817, 14, 1080, 13, 13255, 13, 1073, 12749, 14, 1019, 469, 6273, 26, 378, 378, 14, 21, 5633, 378, 378 ]
[ 199, 3, 221, 370, 1360, 14, 647, 199, 3, 199, 3, 259, 437, 1007, 13, 533, 3970, 402, 314, 658, 7772, 7, 1021, 370, 7389, 4163, 14, 199, 3, 199, 3, 221, 1898, 14790, 13, 7806, 701, 199, 3, 221, 20232, 16147, 281, 14, 199, 3, 199, 3, 221, 961, 570, 365, 1777, 402, 314, 2868, 804, 2199, 12, 436, 1443, 1454, 506, 1202, 12, 199, 3, 221, 6042, 12, 436, 1854, 1334, 314, 2895, 402, 314, 2868, 804, 2199, 199, 3, 221, 4190, 12, 5113, 14, 17715, 14, 221, 4885, 32620, 370, 675, 12, 2811, 12, 503, 11207, 199, 3, 221, 642, 570, 1265, 6623, 626, 1265, 1172, 1586, 314, 4190, 436, 199, 3, 221, 20647, 436, 4729, 652, 9999, 14, 199, 199, 3, 710, 1676, 1021, 365, 10470, 315, 570, 658, 8911, 14, 647, 1370, 421, 199, 504, 5274, 492, 627, 199, 504, 1564, 492, 627, 199, 504, 9698, 492, 627, 199, 199, 646, 900, 421, 199, 3, 710, 2569, 3326, 5627, 314, 4163, 1406, 1202, 701, 1006, 4046, 6497, 14, 199, 1360, 63, 1291, 63, 17, 275, 9638, 199, 11230, 16556, 4163, 21755, 21486, 55, 19, 35, 501, 21156, 4163, 841, 14, 614, 19894, 1588, 279, 501, 742, 2, 199, 2, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 1360, 20, 15, 320, 3362, 14, 15662, 1743, 199, 28, 1360, 30, 199, 28, 2993, 30, 199, 28, 2024, 1455, 13, 20146, 628, 2714, 13, 804, 2, 1564, 628, 505, 15, 1360, 27, 5960, 29, 1624, 13, 24, 1743, 199, 28, 1213, 3072, 199, 624, 199, 199, 1360, 63, 1291, 63, 18, 275, 9638, 199, 3261, 10944, 1108, 1213, 30, 199, 28, 2487, 730, 628, 505, 15, 3919, 1743, 523, 282, 26, 1073, 469, 3164, 26, 327, 993, 14153, 27, 789, 523, 282, 26, 21736, 469, 3164, 26, 327, 27176, 1299, 37, 27, 789, 523, 282, 26, 22797, 469, 3164, 26, 327, 1665, 993, 27, 789, 819, 2396, 469, 5023, 13, 6606, 26, 5444, 68, 6738, 12, 598, 6349, 3042, 12, 437, 1383, 12, 869, 25911, 12, 542, 20546, 27, 268, 3164, 26, 327, 3273, 27, 268, 8020, 26, 327, 6968, 1665, 27, 268, 3462, 26, 10513, 5, 27, 268, 11042, 26, 2599, 27, 789, 819, 9073, 14, 2792, 469, 3462, 26, 13098, 5, 27, 355, 11042, 26, 2599, 27, 789, 523, 9073, 14, 2792, 16140, 469, 11042, 26, 841, 476, 378, 413, 476, 378, 27, 789, 523, 9073, 14, 2792, 394, 20, 469, 8020, 13, 2326, 26, 327, 8699, 8699, 1665, 27, 673, 5023, 13, 890, 26, 21576, 27, 673, 5023, 13, 2487, 26, 2607, 317, 544, 27, 673, 5023, 13, 3463, 26, 17268, 27, 673, 11042, 26, 650, 476, 378, 413, 14, 21, 476, 1749, 5, 27, 673, 6273, 26, 378, 14, 19, 476, 378, 378, 14, 19, 476, 413, 5, 27, 789, 523, 9073, 14, 2792, 299, 469, 11042, 26, 413, 14, 21, 476, 378, 413, 14, 21, 476, 1616, 5, 27, 789, 523, 9073, 14, 2792, 876, 469, 11042, 26, 650, 476, 378, 650, 476, 1749, 5, 27, 490, 8020, 13, 2326, 26, 327, 36, 22, 37, 24, 1665, 27, 490, 6273, 26, 499, 476, 378, 499, 476, 413, 5, 27, 789, 523, 9073, 14, 2792, 1817, 14, 955, 469, 3462, 26, 9137, 5, 27, 2490, 11042, 26, 413, 14, 21, 476, 378, 413, 14, 21, 476, 1616, 5, 27, 789, 523, 9073, 14, 2792, 1817, 14, 13255, 469, 3462, 26, 16102, 5, 27, 2079, 11042, 26, 413, 14, 21, 476, 378, 413, 14, 21, 476, 959, 5, 27, 789, 523, 9073, 14, 3954, 469, 1318, 13, 5743, 26, 8126, 27, 2116, 5023, 13, 890, 26, 14610, 5, 27, 2116, 11042, 26, 413, 14, 21, 476, 378, 413, 14, 21, 476, 378, 27, 789, 819, 394, 17, 469, 1318, 13, 5743, 26, 8126, 27, 789, 523, 394, 19, 469, 5023, 13, 890, 26, 21576, 27, 2126, 11042, 26, 841, 476, 378, 413, 14, 21, 476, 378, 27, 789, 819, 299, 469, 1318, 13, 5743, 26, 2951, 2021, 27, 789, 819, 876, 14, 331, 21252, 469, 3164, 26, 10030, 27, 789, 819, 13598, 14, 6691, 469, 5023, 13, 6606, 26, 3485, 17601, 27, 326, 1318, 13, 5743, 26, 3602, 27, 326, 10424, 13, 2638, 26, 876, 27, 326, 3164, 26, 23531, 6304, 27, 789, 819, 1817, 14, 955, 12749, 14, 637, 469, 5023, 13, 3463, 26, 17268, 27, 717, 1318, 13, 5743, 26, 2451, 27, 717, 3462, 26, 4233, 5, 27, 717, 13763, 13, 5743, 26, 18828, 27, 717, 6273, 26, 413, 476, 413, 5633, 413, 476, 378, 27, 789, 523, 1817, 14, 955, 12749, 14, 3257, 469, 13763, 13, 5743, 26, 18828, 27, 586, 6273, 26, 413, 476, 378, 413, 476, 413, 5633, 27, 789, 523, 1817, 14, 955, 12749, 14, 3257, 299, 26, 2246, 13, 1739, 469, 11042, 26, 378, 27, 789, 523, 1817, 14, 955, 12749, 14, 3257, 299, 469, 11042, 26, 413, 14, 21, 476, 378, 378, 378, 27, 789, 523, 1817, 14, 1080, 469, 11042, 26, 1227, 476, 2599, 1227, 476, 2599, 27, 355, 9162, 26, 378, 27, 355, 9162, 13, 20681, 26, 7396, 27, 355, 9162, 13, 15880, 26, 413, 5633, 378, 14, 19, 476, 27, 789, 523, 1817, 14, 1080, 5651, 469, 6273, 26, 378, 27, 789, 523, 1817, 14, 1080, 12749, 469, 6273, 26, 378, 27, 789, 523, 1817, 14, 1080, 13, 13255, 13, 1073, 469, 3462, 26, 2948, 5, 27, 586, 9162, 26, 378, 27, 586, 9162, 13, 15880, 26, 378, 27, 586, 11042, 26, 413, 476, 378, 413, 476, 378, 27, 789, 523, 1817, 14, 1080, 13, 13255, 13, 1073, 12749, 14, 3039, 469, 6273, 26, 378, 378, 14, 21, 5633, 378, 378, 14, 21, 5633, 27, 639, 5023, 13, 890, 26, 20582, 5, 27, 639, 1318, 13, 5743, 26, 3602, 27, 789, 523, 1817, 14, 1080, 13, 13255, 13, 1073, 12749, 14, 14885, 469, 6273, 26, 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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 ]
sebastic/QGIS
python/ext-libs/pytz/exceptions.py
657
1333
''' Custom exceptions raised by pytz. ''' __all__ = [ 'UnknownTimeZoneError', 'InvalidTimeError', 'AmbiguousTimeError', 'NonExistentTimeError', ] class UnknownTimeZoneError(KeyError): '''Exception raised when pytz is passed an unknown timezone. >>> isinstance(UnknownTimeZoneError(), LookupError) True This class is actually a subclass of KeyError to provide backwards compatibility with code relying on the undocumented behavior of earlier pytz releases. >>> isinstance(UnknownTimeZoneError(), KeyError) True ''' pass class InvalidTimeError(Exception): '''Base class for invalid time exceptions.''' class AmbiguousTimeError(InvalidTimeError): '''Exception raised when attempting to create an ambiguous wallclock time. At the end of a DST transition period, a particular wallclock time will occur twice (once before the clocks are set back, once after). Both possibilities may be correct, unless further information is supplied. See DstTzInfo.normalize() for more info ''' class NonExistentTimeError(InvalidTimeError): '''Exception raised when attempting to create a wallclock time that cannot exist. At the start of a DST transition period, the wallclock time jumps forward. The instants jumped over never occur. '''
gpl-2.0
[ 2344, 199, 7223, 4967, 4915, 701, 15444, 14, 199, 2344, 199, 199, 363, 452, 363, 275, 359, 272, 283, 5912, 32515, 547, 297, 283, 3364, 1366, 547, 297, 283, 29209, 20357, 1366, 547, 297, 272, 283, 6932, 920, 13298, 1366, 547, 297, 272, 1622, 421, 199, 533, 14831, 32515, 547, 8, 10230, 304, 272, 1449, 1726, 4915, 1380, 15444, 365, 3032, 376, 5809, 7137, 14, 339, 1306, 1228, 8, 5912, 32515, 547, 1062, 19021, 9, 272, 715, 339, 961, 1021, 365, 5965, 282, 5516, 402, 4067, 370, 5647, 8552, 272, 7163, 543, 1233, 295, 6670, 641, 314, 625, 29383, 5953, 402, 14119, 272, 15444, 19015, 14, 339, 1306, 1228, 8, 5912, 32515, 547, 1062, 4067, 9, 272, 715, 272, 1449, 272, 986, 421, 199, 533, 6378, 1366, 547, 8, 1726, 304, 272, 1449, 1563, 1021, 367, 3866, 900, 4967, 10595, 421, 199, 533, 437, 887, 20357, 1366, 547, 8, 3364, 1366, 547, 304, 272, 1449, 1726, 4915, 1380, 19595, 370, 1218, 376, 26711, 19882, 9597, 900, 14, 339, 2854, 314, 1284, 402, 282, 22782, 14116, 6247, 12, 282, 6770, 19882, 9597, 900, 911, 272, 4781, 13373, 334, 5089, 2544, 314, 12516, 83, 787, 663, 1771, 12, 5403, 2410, 680, 17650, 272, 2086, 23422, 1443, 506, 3211, 12, 7444, 9848, 2556, 365, 6841, 14, 339, 1666, 577, 270, 52, 90, 2354, 14, 7721, 342, 367, 1655, 2256, 272, 1449, 421, 199, 533, 10172, 920, 13298, 1366, 547, 8, 3364, 1366, 547, 304, 272, 1449, 1726, 4915, 1380, 19595, 370, 1218, 282, 19882, 9597, 900, 626, 272, 3913, 2187, 14, 339, 2854, 314, 1343, 402, 282, 22782, 14116, 6247, 12, 314, 19882, 9597, 900, 14882, 83, 7568, 14, 272, 710, 2727, 2285, 14882, 379, 1806, 7078, 4781, 14, 272, 1449, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 7223, 4967, 4915, 701, 15444, 14, 199, 2344, 199, 199, 363, 452, 363, 275, 359, 272, 283, 5912, 32515, 547, 297, 283, 3364, 1366, 547, 297, 283, 29209, 20357, 1366, 547, 297, 272, 283, 6932, 920, 13298, 1366, 547, 297, 272, 1622, 421, 199, 533, 14831, 32515, 547, 8, 10230, 304, 272, 1449, 1726, 4915, 1380, 15444, 365, 3032, 376, 5809, 7137, 14, 339, 1306, 1228, 8, 5912, 32515, 547, 1062, 19021, 9, 272, 715, 339, 961, 1021, 365, 5965, 282, 5516, 402, 4067, 370, 5647, 8552, 272, 7163, 543, 1233, 295, 6670, 641, 314, 625, 29383, 5953, 402, 14119, 272, 15444, 19015, 14, 339, 1306, 1228, 8, 5912, 32515, 547, 1062, 4067, 9, 272, 715, 272, 1449, 272, 986, 421, 199, 533, 6378, 1366, 547, 8, 1726, 304, 272, 1449, 1563, 1021, 367, 3866, 900, 4967, 10595, 421, 199, 533, 437, 887, 20357, 1366, 547, 8, 3364, 1366, 547, 304, 272, 1449, 1726, 4915, 1380, 19595, 370, 1218, 376, 26711, 19882, 9597, 900, 14, 339, 2854, 314, 1284, 402, 282, 22782, 14116, 6247, 12, 282, 6770, 19882, 9597, 900, 911, 272, 4781, 13373, 334, 5089, 2544, 314, 12516, 83, 787, 663, 1771, 12, 5403, 2410, 680, 17650, 272, 2086, 23422, 1443, 506, 3211, 12, 7444, 9848, 2556, 365, 6841, 14, 339, 1666, 577, 270, 52, 90, 2354, 14, 7721, 342, 367, 1655, 2256, 272, 1449, 421, 199, 533, 10172, 920, 13298, 1366, 547, 8, 3364, 1366, 547, 304, 272, 1449, 1726, 4915, 1380, 19595, 370, 1218, 282, 19882, 9597, 900, 626, 272, 3913, 2187, 14, 339, 2854, 314, 1343, 402, 282, 22782, 14116, 6247, 12, 314, 19882, 9597, 900, 14882, 83, 7568, 14, 272, 710, 2727, 2285, 14882, 379, 1806, 7078, 4781, 14, 272, 1449, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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,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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 ]
opoplawski/ansible-modules-core
cloud/openstack/os_auth.py
131
2039
#!/usr/bin/python # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. # # This module is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software. If not, see <http://www.gnu.org/licenses/>. try: import shade from shade import meta HAS_SHADE = True except ImportError: HAS_SHADE = False DOCUMENTATION = ''' --- module: os_auth short_description: Retrieve an auth token version_added: "2.0" author: "Monty Taylor (@emonty)" description: - Retrieve an auth token from an OpenStack Cloud requirements: - "python >= 2.6" - "shade" extends_documentation_fragment: openstack ''' EXAMPLES = ''' # Authenticate to the cloud and retrieve the service catalog - os_auth: cloud: rax-dfw - debug: var=service_catalog ''' def main(): argument_spec = openstack_full_argument_spec() module_kwargs = openstack_module_kwargs() module = AnsibleModule(argument_spec, **module_kwargs) if not HAS_SHADE: module.fail_json(msg='shade is required for this module') try: cloud = shade.openstack_cloud(**module.params) module.exit_json( changed=False, ansible_facts=dict( auth_token=cloud.auth_token, service_catalog=cloud.service_catalog)) except shade.OpenStackCloudException as e: module.fail_json(msg=e.message) # this is magic, see lib/ansible/module_common.py from ansible.module_utils.basic import * from ansible.module_utils.openstack import * if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 334, 67, 9, 6900, 27849, 13, 29471, 15290, 15878, 12, 491, 14, 48, 14, 199, 3, 199, 3, 961, 859, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2032, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2032, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 893, 26, 272, 492, 32250, 272, 687, 32250, 492, 3404, 272, 7509, 63, 8461, 1093, 275, 715, 199, 2590, 3545, 26, 272, 7509, 63, 8461, 1093, 275, 756, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 747, 63, 1178, 199, 3612, 63, 1802, 26, 13939, 376, 1790, 1526, 199, 1023, 63, 3270, 26, 298, 18, 14, 16, 2, 199, 2502, 26, 298, 6671, 369, 377, 1187, 25339, 8593, 69, 2106, 369, 2924, 199, 1802, 26, 272, 446, 13939, 376, 1790, 1526, 687, 376, 14260, 8142, 199, 7538, 26, 272, 446, 298, 1548, 2356, 499, 14, 22, 2, 272, 446, 298, 31170, 2, 199, 11036, 63, 9970, 63, 7677, 26, 13869, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 3590, 7672, 370, 314, 8002, 436, 8044, 314, 2435, 10594, 199, 13, 747, 63, 1178, 26, 272, 8002, 26, 16937, 13, 1587, 87, 199, 13, 3105, 26, 2729, 29, 1364, 63, 7959, 199, 2344, 199, 199, 318, 2446, 837, 339, 1423, 63, 1650, 275, 13869, 63, 2861, 63, 2094, 63, 1650, 342, 272, 859, 63, 958, 275, 13869, 63, 578, 63, 958, 342, 272, 859, 275, 6953, 8, 2094, 63, 1650, 12, 1011, 578, 63, 958, 9, 339, 340, 440, 7509, 63, 8461, 1093, 26, 267, 859, 14, 1633, 63, 1001, 8, 1328, 534, 31170, 365, 1415, 367, 642, 859, 358, 339, 862, 26, 267, 8002, 275, 32250, 14, 8512, 63, 4091, 3682, 578, 14, 1162, 9, 267, 859, 14, 2224, 63, 1001, 8, 288, 2896, 29, 797, 12, 288, 3242, 63, 5047, 29, 807, 8, 1598, 1790, 63, 1418, 29, 4091, 14, 1178, 63, 1418, 12, 1598, 2435, 63, 7959, 29, 4091, 14, 1364, 63, 7959, 430, 272, 871, 32250, 14, 26208, 9089, 1726, 465, 325, 26, 267, 859, 14, 1633, 63, 1001, 8, 1328, 29, 69, 14, 1188, 9, 199, 199, 3, 642, 365, 10628, 12, 1937, 1973, 15, 4853, 15, 578, 63, 2330, 14, 647, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 627, 199, 504, 3242, 14, 578, 63, 1208, 14, 8512, 492, 627, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 334, 67, 9, 6900, 27849, 13, 29471, 15290, 15878, 12, 491, 14, 48, 14, 199, 3, 199, 3, 961, 859, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2032, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2032, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 893, 26, 272, 492, 32250, 272, 687, 32250, 492, 3404, 272, 7509, 63, 8461, 1093, 275, 715, 199, 2590, 3545, 26, 272, 7509, 63, 8461, 1093, 275, 756, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 747, 63, 1178, 199, 3612, 63, 1802, 26, 13939, 376, 1790, 1526, 199, 1023, 63, 3270, 26, 298, 18, 14, 16, 2, 199, 2502, 26, 298, 6671, 369, 377, 1187, 25339, 8593, 69, 2106, 369, 2924, 199, 1802, 26, 272, 446, 13939, 376, 1790, 1526, 687, 376, 14260, 8142, 199, 7538, 26, 272, 446, 298, 1548, 2356, 499, 14, 22, 2, 272, 446, 298, 31170, 2, 199, 11036, 63, 9970, 63, 7677, 26, 13869, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 3590, 7672, 370, 314, 8002, 436, 8044, 314, 2435, 10594, 199, 13, 747, 63, 1178, 26, 272, 8002, 26, 16937, 13, 1587, 87, 199, 13, 3105, 26, 2729, 29, 1364, 63, 7959, 199, 2344, 199, 199, 318, 2446, 837, 339, 1423, 63, 1650, 275, 13869, 63, 2861, 63, 2094, 63, 1650, 342, 272, 859, 63, 958, 275, 13869, 63, 578, 63, 958, 342, 272, 859, 275, 6953, 8, 2094, 63, 1650, 12, 1011, 578, 63, 958, 9, 339, 340, 440, 7509, 63, 8461, 1093, 26, 267, 859, 14, 1633, 63, 1001, 8, 1328, 534, 31170, 365, 1415, 367, 642, 859, 358, 339, 862, 26, 267, 8002, 275, 32250, 14, 8512, 63, 4091, 3682, 578, 14, 1162, 9, 267, 859, 14, 2224, 63, 1001, 8, 288, 2896, 29, 797, 12, 288, 3242, 63, 5047, 29, 807, 8, 1598, 1790, 63, 1418, 29, 4091, 14, 1178, 63, 1418, 12, 1598, 2435, 63, 7959, 29, 4091, 14, 1364, 63, 7959, 430, 272, 871, 32250, 14, 26208, 9089, 1726, 465, 325, 26, 267, 859, 14, 1633, 63, 1001, 8, 1328, 29, 69, 14, 1188, 9, 199, 199, 3, 642, 365, 10628, 12, 1937, 1973, 15, 4853, 15, 578, 63, 2330, 14, 647, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 627, 199, 504, 3242, 14, 578, 63, 1208, 14, 8512, 492, 627, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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,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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 ]
narogon/linuxcnc
lib/python/hal.py
32
2238
#!/usr/bin/env python # vim: sts=4 sw=4 et """ This module allows the creation of userspace HAL components in Python. This includes pins and parameters of the various HAL types. Typical usage: import hal, time h = hal.component("component-name") # create pins and parameters with calls to h.newpin and h.newparam h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN) h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT) h.ready() # mark the component as 'ready' try: while 1: # act on changed input pins; update values on output pins time.sleep(1) h['out'] = h['in'] except KeyboardInterrupt: pass When the component is requested to exit with 'halcmd unload', a KeyboardInterrupt exception will be raised. """ import _hal from _hal import * class _ItemWrap(object): def __new__(cls, item): if not isinstance(item, _hal.item): raise TypeError("Constructor argument must be _hal.item: %s" % type(item)) self = object.__new__(cls) return self._item_wrap(item) def _item_wrap(self, item): for f in ['get', 'set', 'get_type', 'get_name', 'get_dir', 'is_pin', '__repr__']: setattr(self, f, getattr(item, f)) return self def __init__(self, item): self._item = item name = property(lambda s: s._item.get_name()) type = property(lambda s: s._item.get_type()) dir = property(lambda s: s._item.get_dir()) value = property(lambda s: s._item.get(), lambda s,v: s._item.set(v)) class Pin(_ItemWrap): def __init__(self, item): _ItemWrap.__init__(self, item) if not item.is_pin(): raise TypeError("Must be constructed from pin object") class Param(_ItemWrap): def __init__(self, item): _ItemWrap.__init__(self, item) if item.is_pin(): raise TypeError("Must be constructed from param object") class component(_hal.component): def newpin(self, *a, **kw): return Pin(_hal.component.newpin(self, *a, **kw)) def newparam(self, *a, **kw): return Param(_hal.component.newparam(self, *a, **kw)) def getpin(self, *a, **kw): return Pin(_hal.component.getpin(self, *a, **kw)) def getparam(self, *a, **kw): return Param(_hal.component.getparam(self, *a, **kw))
lgpl-2.1
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 6695, 26, 23014, 29, 20, 5584, 29, 20, 10844, 199, 199, 624, 199, 199, 2765, 859, 6127, 314, 7143, 402, 922, 2638, 869, 748, 7323, 315, 2018, 14, 199, 2765, 6952, 30541, 436, 2633, 402, 314, 7750, 869, 748, 2943, 14, 199, 199, 26876, 4503, 26, 199, 199, 646, 22939, 12, 900, 199, 72, 275, 22939, 14, 3173, 480, 3173, 13, 354, 531, 199, 3, 1218, 30541, 436, 2633, 543, 4882, 370, 394, 14, 1222, 7751, 436, 394, 14, 1222, 635, 199, 72, 14, 1222, 7751, 480, 262, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 72, 14, 1222, 7751, 480, 548, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 1877, 9, 199, 72, 14, 2179, 342, 327, 2216, 314, 3931, 465, 283, 2179, 7, 199, 199, 893, 26, 272, 1830, 413, 26, 267, 327, 2454, 641, 2896, 1324, 30541, 27, 1678, 1338, 641, 1072, 30541, 267, 900, 14, 4532, 8, 17, 9, 267, 394, 459, 548, 418, 275, 394, 459, 262, 418, 199, 2590, 13483, 26, 986, 421, 199, 11423, 314, 3931, 365, 5839, 370, 4458, 543, 283, 19785, 1760, 625, 912, 297, 282, 199, 31538, 1919, 911, 506, 4915, 14, 199, 624, 199, 199, 646, 485, 19785, 199, 504, 485, 19785, 492, 627, 199, 199, 533, 485, 2081, 15991, 8, 785, 304, 272, 347, 636, 1222, 721, 1886, 12, 1242, 304, 267, 340, 440, 1228, 8, 1053, 12, 485, 19785, 14, 1053, 304, 288, 746, 3146, 480, 11447, 1423, 1471, 506, 485, 19785, 14, 1053, 26, 450, 83, 2, 450, 730, 8, 1053, 430, 267, 291, 275, 909, 855, 1222, 721, 1886, 9, 267, 372, 291, 423, 1053, 63, 3823, 8, 1053, 9, 339, 347, 485, 1053, 63, 3823, 8, 277, 12, 1242, 304, 267, 367, 289, 315, 788, 362, 297, 283, 409, 297, 283, 362, 63, 466, 297, 283, 362, 63, 354, 297, 283, 362, 63, 694, 297, 283, 374, 63, 7751, 297, 2560, 2722, 363, 2565, 288, 5371, 8, 277, 12, 289, 12, 2519, 8, 1053, 12, 289, 430, 267, 372, 291, 339, 347, 636, 826, 721, 277, 12, 1242, 304, 267, 291, 423, 1053, 275, 1242, 339, 536, 275, 3324, 8, 2734, 308, 26, 308, 423, 1053, 14, 362, 63, 354, 1012, 272, 730, 275, 3324, 8, 2734, 308, 26, 308, 423, 1053, 14, 362, 63, 466, 1012, 272, 2935, 221, 275, 3324, 8, 2734, 308, 26, 308, 423, 1053, 14, 362, 63, 694, 1012, 339, 574, 275, 3324, 8, 2734, 308, 26, 308, 423, 1053, 14, 362, 1062, 2400, 308, 12, 86, 26, 308, 423, 1053, 14, 409, 8, 86, 430, 199, 199, 533, 26486, 1547, 2081, 15991, 304, 272, 347, 636, 826, 721, 277, 12, 1242, 304, 267, 485, 2081, 15991, 855, 826, 721, 277, 12, 1242, 9, 267, 340, 440, 1242, 14, 374, 63, 7751, 837, 288, 746, 3146, 480, 13757, 506, 14701, 687, 10713, 909, 531, 199, 199, 533, 12608, 1547, 2081, 15991, 304, 272, 347, 636, 826, 721, 277, 12, 1242, 304, 267, 485, 2081, 15991, 855, 826, 721, 277, 12, 1242, 9, 267, 340, 1242, 14, 374, 63, 7751, 837, 288, 746, 3146, 480, 13757, 506, 14701, 687, 1215, 909, 531, 199, 199, 533, 3931, 1547, 19785, 14, 3173, 304, 272, 347, 892, 7751, 8, 277, 12, 627, 65, 12, 1011, 829, 304, 372, 26486, 1547, 19785, 14, 3173, 14, 1222, 7751, 8, 277, 12, 627, 65, 12, 1011, 829, 430, 272, 347, 892, 635, 8, 277, 12, 627, 65, 12, 1011, 829, 304, 372, 12608, 1547, 19785, 14, 3173, 14, 1222, 635, 8, 277, 12, 627, 65, 12, 1011, 829, 430, 339, 347, 664, 7751, 8, 277, 12, 627, 65, 12, 1011, 829, 304, 372, 26486, 1547, 19785, 14, 3173, 14, 362, 7751, 8, 277, 12, 627, 65, 12, 1011, 829, 430, 272, 347, 664, 635, 8, 277, 12, 627, 65, 12, 1011, 829, 304, 372, 12608, 1547, 19785, 14, 3173, 14, 362, 635, 8, 277, 12, 627, 65, 12, 1011, 829, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 6695, 26, 23014, 29, 20, 5584, 29, 20, 10844, 199, 199, 624, 199, 199, 2765, 859, 6127, 314, 7143, 402, 922, 2638, 869, 748, 7323, 315, 2018, 14, 199, 2765, 6952, 30541, 436, 2633, 402, 314, 7750, 869, 748, 2943, 14, 199, 199, 26876, 4503, 26, 199, 199, 646, 22939, 12, 900, 199, 72, 275, 22939, 14, 3173, 480, 3173, 13, 354, 531, 199, 3, 1218, 30541, 436, 2633, 543, 4882, 370, 394, 14, 1222, 7751, 436, 394, 14, 1222, 635, 199, 72, 14, 1222, 7751, 480, 262, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 72, 14, 1222, 7751, 480, 548, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 1877, 9, 199, 72, 14, 2179, 342, 327, 2216, 314, 3931, 465, 283, 2179, 7, 199, 199, 893, 26, 272, 1830, 413, 26, 267, 327, 2454, 641, 2896, 1324, 30541, 27, 1678, 1338, 641, 1072, 30541, 267, 900, 14, 4532, 8, 17, 9, 267, 394, 459, 548, 418, 275, 394, 459, 262, 418, 199, 2590, 13483, 26, 986, 421, 199, 11423, 314, 3931, 365, 5839, 370, 4458, 543, 283, 19785, 1760, 625, 912, 297, 282, 199, 31538, 1919, 911, 506, 4915, 14, 199, 624, 199, 199, 646, 485, 19785, 199, 504, 485, 19785, 492, 627, 199, 199, 533, 485, 2081, 15991, 8, 785, 304, 272, 347, 636, 1222, 721, 1886, 12, 1242, 304, 267, 340, 440, 1228, 8, 1053, 12, 485, 19785, 14, 1053, 304, 288, 746, 3146, 480, 11447, 1423, 1471, 506, 485, 19785, 14, 1053, 26, 450, 83, 2, 450, 730, 8, 1053, 430, 267, 291, 275, 909, 855, 1222, 721, 1886, 9, 267, 372, 291, 423, 1053, 63, 3823, 8, 1053, 9, 339, 347, 485, 1053, 63, 3823, 8, 277, 12, 1242, 304, 267, 367, 289, 315, 788, 362, 297, 283, 409, 297, 283, 362, 63, 466, 297, 283, 362, 63, 354, 297, 283, 362, 63, 694, 297, 283, 374, 63, 7751, 297, 2560, 2722, 363, 2565, 288, 5371, 8, 277, 12, 289, 12, 2519, 8, 1053, 12, 289, 430, 267, 372, 291, 339, 347, 636, 826, 721, 277, 12, 1242, 304, 267, 291, 423, 1053, 275, 1242, 339, 536, 275, 3324, 8, 2734, 308, 26, 308, 423, 1053, 14, 362, 63, 354, 1012, 272, 730, 275, 3324, 8, 2734, 308, 26, 308, 423, 1053, 14, 362, 63, 466, 1012, 272, 2935, 221, 275, 3324, 8, 2734, 308, 26, 308, 423, 1053, 14, 362, 63, 694, 1012, 339, 574, 275, 3324, 8, 2734, 308, 26, 308, 423, 1053, 14, 362, 1062, 2400, 308, 12, 86, 26, 308, 423, 1053, 14, 409, 8, 86, 430, 199, 199, 533, 26486, 1547, 2081, 15991, 304, 272, 347, 636, 826, 721, 277, 12, 1242, 304, 267, 485, 2081, 15991, 855, 826, 721, 277, 12, 1242, 9, 267, 340, 440, 1242, 14, 374, 63, 7751, 837, 288, 746, 3146, 480, 13757, 506, 14701, 687, 10713, 909, 531, 199, 199, 533, 12608, 1547, 2081, 15991, 304, 272, 347, 636, 826, 721, 277, 12, 1242, 304, 267, 485, 2081, 15991, 855, 826, 721, 277, 12, 1242, 9, 267, 340, 1242, 14, 374, 63, 7751, 837, 288, 746, 3146, 480, 13757, 506, 14701, 687, 1215, 909, 531, 199, 199, 533, 3931, 1547, 19785, 14, 3173, 304, 272, 347, 892, 7751, 8, 277, 12, 627, 65, 12, 1011, 829, 304, 372, 26486, 1547, 19785, 14, 3173, 14, 1222, 7751, 8, 277, 12, 627, 65, 12, 1011, 829, 430, 272, 347, 892, 635, 8, 277, 12, 627, 65, 12, 1011, 829, 304, 372, 12608, 1547, 19785, 14, 3173, 14, 1222, 635, 8, 277, 12, 627, 65, 12, 1011, 829, 430, 339, 347, 664, 7751, 8, 277, 12, 627, 65, 12, 1011, 829, 304, 372, 26486, 1547, 19785, 14, 3173, 14, 362, 7751, 8, 277, 12, 627, 65, 12, 1011, 829, 430, 272, 347, 664, 635, 8, 277, 12, 627, 65, 12, 1011, 829, 304, 372, 12608, 1547, 19785, 14, 3173, 14, 362, 635, 8, 277, 12, 627, 65, 12, 1011, 829, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
guanquan94/orbis
reviews_user/views.py
1
4607
from urllib import quote_plus from account.decorators import login_required from annoying.decorators import render_to from django.contrib import messages from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.urlresolvers import reverse from django.db.models import Q from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import render, get_object_or_404, redirect from django.utils import timezone from .forms import PostForm from .models import Post # Create your views here. #CRUD @login_required def post_create(request): if not request.user.is_staff or not request.user.is_superuser: raise Http404 # if not request.user.is_authenticated(): # raise Http404 form = PostForm(request.POST or None, request.FILES or None) if form.is_valid(): instance = form.save(commit=False) instance.user = request.user instance.save() messages.success(request, "Successfully Created") return HttpResponseRedirect(instance.get_absolute_url()) # else: # messages.error(request, "Not Successfully Created") context = { "form": form, } return render(request, "post_form.html", context) @login_required def post_detail(request, slug=None): #Replace Retrieve with Detail instance = get_object_or_404(Post, slug=slug) if instance.publish > timezone.now().date() or instance.draft: if not request.user.is_staff or not request.user.is_superuser: raise Http404 share_string = quote_plus(instance.content) context = { "title": instance.title, "instance": instance, "share_string": share_string, "has_watched": request.user in instance.watchers.all(), } return render(request, "post_detail.html", context) @login_required def post_list(request): today = timezone.now().date() queryset_list = Post.objects.active() #filter(draft=False).filter(publish__lte=timezone.now()) #.order_by("-timestamp") if request.user.is_staff or request.user.is_superuser: queryset_list = Post.objects.all() query = request.GET.get("q") if query: queryset_list = queryset_list.filter( Q(title__icontains=query)| Q(content__icontains=query)| Q(user__first_name__icontains=query)| Q(user__last_name__icontains=query) ).distinct() paginator = Paginator(queryset_list, 10) # Show 25 contacts per page page_request_var = "abc" #You can change this anytime! page = request.GET.get(page_request_var) try: queryset = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. queryset = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. queryset = paginator.page(paginator.num_pages) context = { "object_list": queryset, "title": "List", "page_request_var": page_request_var, "today": today, } return render(request, "post_list.html", context) @login_required def post_update(request, slug=None): if not request.user.is_staff or not request.user.is_superuser: raise Http404 instance = get_object_or_404(Post, slug=slug) form = PostForm(request.POST or None, request.FILES or None, instance=instance) if form.is_valid(): instance = form.save(commit=False) instance.save() messages.success(request, "<a href='#'>Item</a> Saved", extra_tags='html_safe') return HttpResponseRedirect(instance.get_absolute_url()) context = { "title": instance.title, "instance": instance, "form": form, } return render(request, "post_form.html", context) @login_required def post_delete(request, slug=None): if not request.user.is_staff or not request.user.is_superuser: raise Http404 instance = get_object_or_404(Post, slug=slug) instance.delete() messages.success(request, "Successfully Deleted") return redirect("list") @login_required def post_watch(request, slug=None): instance = get_object_or_404(Post, slug=slug) instance.watchers.add(request.user) messages.success(request, "Added") return redirect(reverse('detail', kwargs={"slug": slug})) @login_required def post_unwatch(request, slug=None): instance = get_object_or_404(Post, slug=slug) instance.watchers.remove(request.user) messages.success(request, "Removed") return redirect(reverse('detail', kwargs={"slug": slug})) @login_required @render_to('watchlist_self.html') def ViewWatchers(request): return {'post_self': Post.objects.filter(watchers=request.user).order_by("title"),} @login_required @render_to('watchlist_others.html') def ViewOtherWatchers(request, username): return {'post_others': Post.objects.filter(watchers__username=username).order_by("title"), 'friendname': username}
mit
[ 504, 4011, 492, 6313, 63, 6666, 199, 199, 504, 2933, 14, 11582, 492, 4676, 63, 2427, 199, 504, 22984, 22440, 14, 11582, 492, 3795, 63, 475, 199, 504, 1639, 14, 2828, 492, 3788, 199, 504, 1639, 14, 1018, 14, 22073, 492, 28006, 8566, 12, 9630, 3276, 12, 10331, 1763, 2493, 2674, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 697, 14, 992, 492, 1413, 199, 504, 1639, 14, 1014, 492, 6183, 12, 14935, 12, 4760, 5188, 199, 504, 1639, 14, 17469, 492, 3795, 12, 664, 63, 785, 63, 269, 63, 5188, 12, 4660, 199, 504, 1639, 14, 1208, 492, 7137, 199, 199, 504, 1275, 3351, 492, 7711, 2821, 199, 504, 1275, 992, 492, 7711, 421, 199, 3, 2790, 2195, 6858, 2348, 14, 199, 3, 2944, 3383, 199, 32, 2886, 63, 2427, 199, 318, 2963, 63, 981, 8, 1069, 304, 199, 198, 692, 440, 1056, 14, 751, 14, 374, 63, 7018, 503, 440, 1056, 14, 751, 14, 374, 63, 11434, 26, 507, 198, 3730, 4760, 5188, 421, 198, 3, 340, 440, 1056, 14, 751, 14, 374, 63, 12177, 837, 199, 198, 3, 221, 198, 3730, 4760, 5188, 18118, 198, 964, 275, 7711, 2821, 8, 1069, 14, 4030, 503, 488, 12, 1056, 14, 9472, 503, 488, 9, 199, 198, 692, 1824, 14, 374, 63, 1078, 837, 507, 198, 842, 275, 1824, 14, 2117, 8, 3543, 29, 797, 9, 507, 198, 842, 14, 751, 275, 1056, 14, 751, 507, 198, 842, 14, 2117, 342, 507, 198, 3431, 14, 3742, 8, 1069, 12, 298, 25001, 18208, 531, 507, 198, 1107, 14935, 8, 842, 14, 362, 63, 6116, 63, 633, 1012, 199, 198, 3, 587, 26, 507, 198, 3, 3788, 14, 705, 8, 1069, 12, 298, 1763, 22318, 5836, 18208, 531, 199, 198, 1100, 275, 469, 507, 198, 2, 964, 582, 1824, 12, 199, 198, 93, 199, 198, 1107, 3795, 8, 1069, 12, 298, 1932, 63, 964, 14, 1360, 401, 1067, 9, 421, 199, 32, 2886, 63, 2427, 199, 318, 2963, 63, 5506, 8, 1069, 12, 8889, 29, 403, 304, 327, 11328, 13939, 543, 13302, 199, 198, 842, 275, 664, 63, 785, 63, 269, 63, 5188, 8, 6564, 12, 8889, 29, 5464, 9, 199, 198, 692, 1256, 14, 4763, 690, 7137, 14, 2131, 1252, 602, 342, 503, 1256, 14, 7185, 26, 507, 198, 692, 440, 1056, 14, 751, 14, 374, 63, 7018, 503, 440, 1056, 14, 751, 14, 374, 63, 11434, 26, 686, 198, 3730, 4760, 5188, 199, 198, 6251, 63, 875, 275, 6313, 63, 6666, 8, 842, 14, 1317, 9, 199, 198, 1100, 275, 469, 507, 198, 2, 1213, 582, 1256, 14, 1213, 12, 507, 198, 2, 842, 582, 1256, 12, 507, 198, 2, 6251, 63, 875, 582, 8663, 63, 875, 12, 507, 198, 2, 1989, 63, 6821, 379, 582, 1056, 14, 751, 315, 1256, 14, 6821, 1192, 14, 452, 1062, 199, 198, 93, 199, 198, 1107, 3795, 8, 1069, 12, 298, 1932, 63, 5506, 14, 1360, 401, 1067, 9, 421, 199, 32, 2886, 63, 2427, 199, 318, 2963, 63, 513, 8, 1069, 304, 199, 198, 8136, 275, 7137, 14, 2131, 1252, 602, 342, 199, 198, 7924, 63, 513, 275, 7711, 14, 1462, 14, 2682, 342, 327, 1541, 8, 7185, 29, 797, 680, 1541, 8, 4763, 363, 20740, 29, 7145, 14, 2131, 1012, 327, 14, 1648, 63, 991, 6096, 3954, 531, 199, 198, 692, 1056, 14, 751, 14, 374, 63, 7018, 503, 1056, 14, 751, 14, 374, 63, 11434, 26, 507, 198, 7924, 63, 513, 275, 7711, 14, 1462, 14, 452, 342, 421, 198, 1131, 275, 1056, 14, 2970, 14, 362, 480, 81, 531, 199, 198, 692, 1827, 26, 507, 198, 7924, 63, 513, 275, 7594, 63, 513, 14, 1541, 8, 686, 198, 49, 8, 1213, 363, 30314, 29, 1131, 8636, 686, 198, 49, 8, 1317, 363, 30314, 29, 1131, 8636, 686, 198, 49, 8, 751, 363, 2246, 63, 354, 363, 30314, 29, 1131, 8636, 686, 198, 49, 8, 751, 363, 2019, 63, 354, 363, 30314, 29, 1131, 9, 686, 198, 680, 12926, 342, 199, 198, 22073, 275, 28006, 8566, 8, 7924, 63, 513, 12, 1616, 9, 327, 12968, 5661, 27989, 1126, 2034, 199, 198, 1606, 63, 1069, 63, 1391, 275, 298, 3175, 2, 327, 5556, 883, 1570, 642, 1263, 521, 1, 199, 198, 1606, 275, 1056, 14, 2970, 14, 362, 8, 1606, 63, 1069, 63, 1391, 9, 199, 198, 893, 26, 507, 198, 7924, 275, 21398, 14, 1606, 8, 1606, 9, 199, 198, 2590, 10331, 1763, 2493, 2674, 26, 507, 198, 3, 982, 2034, 365, 440, 376, 3000, 12, 28503, 1642, 2034, 14, 507, 198, 7924, 275, 21398, 14, 1606, 8, 17, 9, 199, 198, 2590, 9630, 3276, 26, 507, 198, 3, 982, 2034, 365, 734, 402, 1425, 334, 69, 14, 71, 14, 221, 5008, 395, 28503, 2061, 2034, 402, 2058, 14, 507, 198, 7924, 275, 21398, 14, 1606, 8, 22073, 14, 1507, 63, 5856, 9, 421, 198, 1100, 275, 469, 507, 198, 2, 785, 63, 513, 582, 7594, 12, 507, 198, 2, 1213, 582, 298, 1296, 401, 507, 198, 2, 1606, 63, 1069, 63, 1391, 582, 2034, 63, 1069, 63, 1391, 12, 507, 198, 2, 8136, 582, 11168, 12, 199, 198, 93, 199, 198, 1107, 3795, 8, 1069, 12, 298, 1932, 63, 513, 14, 1360, 401, 1067, 9, 421, 199, 32, 2886, 63, 2427, 199, 318, 2963, 63, 873, 8, 1069, 12, 8889, 29, 403, 304, 199, 198, 692, 440, 1056, 14, 751, 14, 374, 63, 7018, 503, 440, 1056, 14, 751, 14, 374, 63, 11434, 26, 507, 198, 3730, 4760, 5188, 199, 198, 842, 275, 664, 63, 785, 63, 269, 63, 5188, 8, 6564, 12, 8889, 29, 5464, 9, 199, 198, 964, 275, 7711, 2821, 8, 1069, 14, 4030, 503, 488, 12, 1056, 14, 9472, 503, 488, 12, 1256, 29, 842, 9, 199, 198, 692, 1824, 14, 374, 63, 1078, 837, 507, 198, 842, 275, 1824, 14, 2117, 8, 3543, 29, 797, 9, 507, 198, 842, 14, 2117, 342, 507, 198, 3431, 14, 3742, 8, 1069, 12, 3886, 65, 4369, 26431, 8423, 2081, 1108, 65, 30, 29026, 401, 2402, 63, 2969, 534, 1360, 63, 3489, 358, 507, 198, 1107, 14935, 8, 842, 14, 362, 63, 6116, 63, 633, 1012, 199 ]
[ 4011, 492, 6313, 63, 6666, 199, 199, 504, 2933, 14, 11582, 492, 4676, 63, 2427, 199, 504, 22984, 22440, 14, 11582, 492, 3795, 63, 475, 199, 504, 1639, 14, 2828, 492, 3788, 199, 504, 1639, 14, 1018, 14, 22073, 492, 28006, 8566, 12, 9630, 3276, 12, 10331, 1763, 2493, 2674, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 697, 14, 992, 492, 1413, 199, 504, 1639, 14, 1014, 492, 6183, 12, 14935, 12, 4760, 5188, 199, 504, 1639, 14, 17469, 492, 3795, 12, 664, 63, 785, 63, 269, 63, 5188, 12, 4660, 199, 504, 1639, 14, 1208, 492, 7137, 199, 199, 504, 1275, 3351, 492, 7711, 2821, 199, 504, 1275, 992, 492, 7711, 421, 199, 3, 2790, 2195, 6858, 2348, 14, 199, 3, 2944, 3383, 199, 32, 2886, 63, 2427, 199, 318, 2963, 63, 981, 8, 1069, 304, 199, 198, 692, 440, 1056, 14, 751, 14, 374, 63, 7018, 503, 440, 1056, 14, 751, 14, 374, 63, 11434, 26, 507, 198, 3730, 4760, 5188, 421, 198, 3, 340, 440, 1056, 14, 751, 14, 374, 63, 12177, 837, 199, 198, 3, 221, 198, 3730, 4760, 5188, 18118, 198, 964, 275, 7711, 2821, 8, 1069, 14, 4030, 503, 488, 12, 1056, 14, 9472, 503, 488, 9, 199, 198, 692, 1824, 14, 374, 63, 1078, 837, 507, 198, 842, 275, 1824, 14, 2117, 8, 3543, 29, 797, 9, 507, 198, 842, 14, 751, 275, 1056, 14, 751, 507, 198, 842, 14, 2117, 342, 507, 198, 3431, 14, 3742, 8, 1069, 12, 298, 25001, 18208, 531, 507, 198, 1107, 14935, 8, 842, 14, 362, 63, 6116, 63, 633, 1012, 199, 198, 3, 587, 26, 507, 198, 3, 3788, 14, 705, 8, 1069, 12, 298, 1763, 22318, 5836, 18208, 531, 199, 198, 1100, 275, 469, 507, 198, 2, 964, 582, 1824, 12, 199, 198, 93, 199, 198, 1107, 3795, 8, 1069, 12, 298, 1932, 63, 964, 14, 1360, 401, 1067, 9, 421, 199, 32, 2886, 63, 2427, 199, 318, 2963, 63, 5506, 8, 1069, 12, 8889, 29, 403, 304, 327, 11328, 13939, 543, 13302, 199, 198, 842, 275, 664, 63, 785, 63, 269, 63, 5188, 8, 6564, 12, 8889, 29, 5464, 9, 199, 198, 692, 1256, 14, 4763, 690, 7137, 14, 2131, 1252, 602, 342, 503, 1256, 14, 7185, 26, 507, 198, 692, 440, 1056, 14, 751, 14, 374, 63, 7018, 503, 440, 1056, 14, 751, 14, 374, 63, 11434, 26, 686, 198, 3730, 4760, 5188, 199, 198, 6251, 63, 875, 275, 6313, 63, 6666, 8, 842, 14, 1317, 9, 199, 198, 1100, 275, 469, 507, 198, 2, 1213, 582, 1256, 14, 1213, 12, 507, 198, 2, 842, 582, 1256, 12, 507, 198, 2, 6251, 63, 875, 582, 8663, 63, 875, 12, 507, 198, 2, 1989, 63, 6821, 379, 582, 1056, 14, 751, 315, 1256, 14, 6821, 1192, 14, 452, 1062, 199, 198, 93, 199, 198, 1107, 3795, 8, 1069, 12, 298, 1932, 63, 5506, 14, 1360, 401, 1067, 9, 421, 199, 32, 2886, 63, 2427, 199, 318, 2963, 63, 513, 8, 1069, 304, 199, 198, 8136, 275, 7137, 14, 2131, 1252, 602, 342, 199, 198, 7924, 63, 513, 275, 7711, 14, 1462, 14, 2682, 342, 327, 1541, 8, 7185, 29, 797, 680, 1541, 8, 4763, 363, 20740, 29, 7145, 14, 2131, 1012, 327, 14, 1648, 63, 991, 6096, 3954, 531, 199, 198, 692, 1056, 14, 751, 14, 374, 63, 7018, 503, 1056, 14, 751, 14, 374, 63, 11434, 26, 507, 198, 7924, 63, 513, 275, 7711, 14, 1462, 14, 452, 342, 421, 198, 1131, 275, 1056, 14, 2970, 14, 362, 480, 81, 531, 199, 198, 692, 1827, 26, 507, 198, 7924, 63, 513, 275, 7594, 63, 513, 14, 1541, 8, 686, 198, 49, 8, 1213, 363, 30314, 29, 1131, 8636, 686, 198, 49, 8, 1317, 363, 30314, 29, 1131, 8636, 686, 198, 49, 8, 751, 363, 2246, 63, 354, 363, 30314, 29, 1131, 8636, 686, 198, 49, 8, 751, 363, 2019, 63, 354, 363, 30314, 29, 1131, 9, 686, 198, 680, 12926, 342, 199, 198, 22073, 275, 28006, 8566, 8, 7924, 63, 513, 12, 1616, 9, 327, 12968, 5661, 27989, 1126, 2034, 199, 198, 1606, 63, 1069, 63, 1391, 275, 298, 3175, 2, 327, 5556, 883, 1570, 642, 1263, 521, 1, 199, 198, 1606, 275, 1056, 14, 2970, 14, 362, 8, 1606, 63, 1069, 63, 1391, 9, 199, 198, 893, 26, 507, 198, 7924, 275, 21398, 14, 1606, 8, 1606, 9, 199, 198, 2590, 10331, 1763, 2493, 2674, 26, 507, 198, 3, 982, 2034, 365, 440, 376, 3000, 12, 28503, 1642, 2034, 14, 507, 198, 7924, 275, 21398, 14, 1606, 8, 17, 9, 199, 198, 2590, 9630, 3276, 26, 507, 198, 3, 982, 2034, 365, 734, 402, 1425, 334, 69, 14, 71, 14, 221, 5008, 395, 28503, 2061, 2034, 402, 2058, 14, 507, 198, 7924, 275, 21398, 14, 1606, 8, 22073, 14, 1507, 63, 5856, 9, 421, 198, 1100, 275, 469, 507, 198, 2, 785, 63, 513, 582, 7594, 12, 507, 198, 2, 1213, 582, 298, 1296, 401, 507, 198, 2, 1606, 63, 1069, 63, 1391, 582, 2034, 63, 1069, 63, 1391, 12, 507, 198, 2, 8136, 582, 11168, 12, 199, 198, 93, 199, 198, 1107, 3795, 8, 1069, 12, 298, 1932, 63, 513, 14, 1360, 401, 1067, 9, 421, 199, 32, 2886, 63, 2427, 199, 318, 2963, 63, 873, 8, 1069, 12, 8889, 29, 403, 304, 199, 198, 692, 440, 1056, 14, 751, 14, 374, 63, 7018, 503, 440, 1056, 14, 751, 14, 374, 63, 11434, 26, 507, 198, 3730, 4760, 5188, 199, 198, 842, 275, 664, 63, 785, 63, 269, 63, 5188, 8, 6564, 12, 8889, 29, 5464, 9, 199, 198, 964, 275, 7711, 2821, 8, 1069, 14, 4030, 503, 488, 12, 1056, 14, 9472, 503, 488, 12, 1256, 29, 842, 9, 199, 198, 692, 1824, 14, 374, 63, 1078, 837, 507, 198, 842, 275, 1824, 14, 2117, 8, 3543, 29, 797, 9, 507, 198, 842, 14, 2117, 342, 507, 198, 3431, 14, 3742, 8, 1069, 12, 3886, 65, 4369, 26431, 8423, 2081, 1108, 65, 30, 29026, 401, 2402, 63, 2969, 534, 1360, 63, 3489, 358, 507, 198, 1107, 14935, 8, 842, 14, 362, 63, 6116, 63, 633, 1012, 199, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
SnappleCap/oh-mainline
vendor/packages/PyYaml/tests/lib/test_errors.py
56
1994
import yaml, test_emitter def test_loader_error(error_filename, verbose=False): try: list(yaml.load_all(open(error_filename, 'rb'))) except yaml.YAMLError, exc: if verbose: print "%s:" % exc.__class__.__name__, exc else: raise AssertionError("expected an exception") test_loader_error.unittest = ['.loader-error'] def test_loader_error_string(error_filename, verbose=False): try: list(yaml.load_all(open(error_filename, 'rb').read())) except yaml.YAMLError, exc: if verbose: print "%s:" % exc.__class__.__name__, exc else: raise AssertionError("expected an exception") test_loader_error_string.unittest = ['.loader-error'] def test_loader_error_single(error_filename, verbose=False): try: yaml.load(open(error_filename, 'rb').read()) except yaml.YAMLError, exc: if verbose: print "%s:" % exc.__class__.__name__, exc else: raise AssertionError("expected an exception") test_loader_error_single.unittest = ['.single-loader-error'] def test_emitter_error(error_filename, verbose=False): events = list(yaml.load(open(error_filename, 'rb'), Loader=test_emitter.EventsLoader)) try: yaml.emit(events) except yaml.YAMLError, exc: if verbose: print "%s:" % exc.__class__.__name__, exc else: raise AssertionError("expected an exception") test_emitter_error.unittest = ['.emitter-error'] def test_dumper_error(error_filename, verbose=False): code = open(error_filename, 'rb').read() try: import yaml from StringIO import StringIO exec code except yaml.YAMLError, exc: if verbose: print "%s:" % exc.__class__.__name__, exc else: raise AssertionError("expected an exception") test_dumper_error.unittest = ['.dumper-error'] if __name__ == '__main__': import test_appliance test_appliance.run(globals())
agpl-3.0
[ 199, 646, 8864, 12, 511, 63, 8159, 351, 199, 199, 318, 511, 63, 3422, 63, 705, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 862, 26, 267, 769, 8, 5963, 14, 912, 63, 452, 8, 1490, 8, 705, 63, 1501, 12, 283, 4848, 7058, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 3422, 63, 705, 14, 2796, 275, 18953, 3422, 13, 705, 418, 199, 199, 318, 511, 63, 3422, 63, 705, 63, 875, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 862, 26, 267, 769, 8, 5963, 14, 912, 63, 452, 8, 1490, 8, 705, 63, 1501, 12, 283, 4848, 1959, 739, 4059, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 3422, 63, 705, 63, 875, 14, 2796, 275, 18953, 3422, 13, 705, 418, 199, 199, 318, 511, 63, 3422, 63, 705, 63, 4780, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 862, 26, 267, 8864, 14, 912, 8, 1490, 8, 705, 63, 1501, 12, 283, 4848, 1959, 739, 1012, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 3422, 63, 705, 63, 4780, 14, 2796, 275, 18953, 4780, 13, 3422, 13, 705, 418, 199, 199, 318, 511, 63, 8159, 351, 63, 705, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 4474, 275, 769, 8, 5963, 14, 912, 8, 1490, 8, 705, 63, 1501, 12, 283, 4848, 659, 490, 22865, 29, 396, 63, 8159, 351, 14, 11770, 5455, 430, 272, 862, 26, 267, 8864, 14, 8159, 8, 4368, 9, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 8159, 351, 63, 705, 14, 2796, 275, 18953, 8159, 351, 13, 705, 418, 199, 199, 318, 511, 63, 2724, 281, 63, 705, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 1233, 275, 1551, 8, 705, 63, 1501, 12, 283, 4848, 1959, 739, 342, 272, 862, 26, 267, 492, 8864, 267, 687, 5228, 492, 5228, 267, 2146, 1233, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 2724, 281, 63, 705, 14, 2796, 275, 18953, 2724, 281, 13, 705, 418, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 492, 511, 63, 19858, 272, 511, 63, 19858, 14, 1065, 8, 8473, 1012, 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 ]
[ 646, 8864, 12, 511, 63, 8159, 351, 199, 199, 318, 511, 63, 3422, 63, 705, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 862, 26, 267, 769, 8, 5963, 14, 912, 63, 452, 8, 1490, 8, 705, 63, 1501, 12, 283, 4848, 7058, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 3422, 63, 705, 14, 2796, 275, 18953, 3422, 13, 705, 418, 199, 199, 318, 511, 63, 3422, 63, 705, 63, 875, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 862, 26, 267, 769, 8, 5963, 14, 912, 63, 452, 8, 1490, 8, 705, 63, 1501, 12, 283, 4848, 1959, 739, 4059, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 3422, 63, 705, 63, 875, 14, 2796, 275, 18953, 3422, 13, 705, 418, 199, 199, 318, 511, 63, 3422, 63, 705, 63, 4780, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 862, 26, 267, 8864, 14, 912, 8, 1490, 8, 705, 63, 1501, 12, 283, 4848, 1959, 739, 1012, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 3422, 63, 705, 63, 4780, 14, 2796, 275, 18953, 4780, 13, 3422, 13, 705, 418, 199, 199, 318, 511, 63, 8159, 351, 63, 705, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 4474, 275, 769, 8, 5963, 14, 912, 8, 1490, 8, 705, 63, 1501, 12, 283, 4848, 659, 490, 22865, 29, 396, 63, 8159, 351, 14, 11770, 5455, 430, 272, 862, 26, 267, 8864, 14, 8159, 8, 4368, 9, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 8159, 351, 63, 705, 14, 2796, 275, 18953, 8159, 351, 13, 705, 418, 199, 199, 318, 511, 63, 2724, 281, 63, 705, 8, 705, 63, 1501, 12, 3376, 29, 797, 304, 272, 1233, 275, 1551, 8, 705, 63, 1501, 12, 283, 4848, 1959, 739, 342, 272, 862, 26, 267, 492, 8864, 267, 687, 5228, 492, 5228, 267, 2146, 1233, 272, 871, 8864, 14, 23103, 547, 12, 3178, 26, 267, 340, 3376, 26, 288, 870, 2071, 83, 5424, 450, 3178, 855, 533, 4914, 354, 3108, 3178, 272, 587, 26, 267, 746, 9070, 480, 2062, 376, 1919, 531, 199, 199, 396, 63, 2724, 281, 63, 705, 14, 2796, 275, 18953, 2724, 281, 13, 705, 418, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 492, 511, 63, 19858, 272, 511, 63, 19858, 14, 1065, 8, 8473, 1012, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
actus/koin
share/qt/extract_strings_qt.py
2945
1844
#!/usr/bin/python ''' Extract _("...") strings for translation and convert to Qt4 stringdefs so that they can be picked up by Qt linguist. ''' from subprocess import Popen, PIPE import glob import operator OUT_CPP="src/qt/bitcoinstrings.cpp" EMPTY=['""'] def parse_po(text): """ Parse 'po' format produced by xgettext. Return a list of (msgid,msgstr) tuples. """ messages = [] msgid = [] msgstr = [] in_msgid = False in_msgstr = False for line in text.split('\n'): line = line.rstrip('\r') if line.startswith('msgid '): if in_msgstr: messages.append((msgid, msgstr)) in_msgstr = False # message start in_msgid = True msgid = [line[6:]] elif line.startswith('msgstr '): in_msgid = False in_msgstr = True msgstr = [line[7:]] elif line.startswith('"'): if in_msgid: msgid.append(line) if in_msgstr: msgstr.append(line) if in_msgstr: messages.append((msgid, msgstr)) return messages files = glob.glob('src/*.cpp') + glob.glob('src/*.h') # xgettext -n --keyword=_ $FILES child = Popen(['xgettext','--output=-','-n','--keyword=_'] + files, stdout=PIPE) (out, err) = child.communicate() messages = parse_po(out) f = open(OUT_CPP, 'w') f.write("""#include <QtGlobal> // Automatically generated by extract_strings.py #ifdef __GNUC__ #define UNUSED __attribute__((unused)) #else #define UNUSED #endif """) f.write('static const char UNUSED *bitcoin_strings[] = {\n') messages.sort(key=operator.itemgetter(0)) for (msgid, msgstr) in messages: if msgid != EMPTY: f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid))) f.write('};') f.close()
mit
[ 3381, 2647, 15, 1393, 15, 1548, 199, 2344, 199, 12147, 3824, 12594, 3326, 367, 7761, 436, 3957, 370, 3959, 20, 1059, 8710, 880, 626, 199, 29002, 883, 506, 29438, 1536, 701, 3959, 634, 14659, 631, 14, 199, 2344, 199, 504, 3873, 492, 13995, 12, 22773, 199, 646, 5739, 199, 646, 4182, 199, 199, 1877, 63, 14533, 628, 2164, 15, 8440, 15, 22816, 5465, 14, 5910, 2, 199, 13993, 2968, 341, 418, 199, 199, 318, 2198, 63, 555, 8, 505, 304, 272, 408, 272, 6077, 283, 555, 7, 1475, 13584, 701, 671, 5152, 14, 272, 1432, 282, 769, 402, 334, 15245, 12, 23367, 9, 6346, 14, 272, 408, 272, 3788, 275, 942, 272, 17879, 275, 942, 272, 1499, 495, 275, 942, 272, 315, 63, 15245, 275, 756, 272, 315, 63, 23367, 275, 756, 339, 367, 1004, 315, 1318, 14, 1294, 2258, 78, 735, 267, 1004, 275, 1004, 14, 6735, 2258, 82, 358, 267, 340, 1004, 14, 2460, 360, 15245, 18927, 288, 340, 315, 63, 23367, 26, 355, 3788, 14, 740, 1332, 15245, 12, 1499, 495, 430, 355, 315, 63, 23367, 275, 756, 288, 327, 1245, 1343, 288, 315, 63, 15245, 275, 715, 7846, 17879, 275, 359, 604, 59, 22, 21316, 267, 916, 1004, 14, 2460, 360, 23367, 18927, 288, 315, 63, 15245, 275, 756, 288, 315, 63, 23367, 275, 715, 288, 1499, 495, 275, 359, 604, 59, 23, 21316, 267, 916, 1004, 14, 2460, 14088, 735, 288, 340, 315, 63, 15245, 26, 355, 17879, 14, 740, 8, 604, 9, 288, 340, 315, 63, 23367, 26, 355, 1499, 495, 14, 740, 8, 604, 9, 339, 340, 315, 63, 23367, 26, 267, 3788, 14, 740, 1332, 15245, 12, 1499, 495, 430, 339, 372, 3788, 199, 199, 1725, 275, 5739, 14, 6463, 360, 2164, 20362, 5910, 358, 435, 5739, 14, 6463, 360, 2164, 20362, 72, 358, 9948, 199, 3, 671, 5152, 446, 78, 1553, 6691, 3699, 2672, 9472, 199, 1739, 275, 13995, 2941, 88, 5152, 28280, 1199, 4022, 21810, 78, 28280, 6691, 3699, 418, 435, 1584, 12, 3839, 29, 6089, 9, 199, 8, 548, 12, 2329, 9, 275, 1982, 14, 10664, 342, 199, 199, 3431, 275, 2198, 63, 555, 8, 548, 9, 9948, 199, 70, 275, 1551, 8, 1877, 63, 14533, 12, 283, 87, 358, 199, 70, 14, 952, 4852, 3, 2613, 665, 4238, 7025, 30, 199, 501, 9195, 17174, 4046, 701, 5536, 63, 5465, 14, 647, 199, 3, 27737, 636, 17732, 35, 363, 199, 3, 4640, 738, 27726, 636, 3215, 721, 8, 8618, 430, 199, 3, 2836, 199, 3, 4640, 738, 27726, 199, 3, 13739, 199, 6141, 199, 70, 14, 952, 360, 1986, 950, 1495, 738, 27726, 627, 22816, 63, 5465, 8607, 275, 9459, 78, 358, 199, 3431, 14, 3191, 8, 498, 29, 3856, 14, 20832, 8, 16, 430, 199, 509, 334, 15245, 12, 1499, 495, 9, 315, 3788, 26, 272, 340, 17879, 1137, 16589, 26, 267, 289, 14, 952, 360, 19229, 63, 26376, 1951, 63, 2826, 1938, 480, 22816, 13, 1018, 401, 450, 83, 26323, 78, 7, 450, 17485, 78, 1370, 904, 8, 15245, 1724, 199, 70, 14, 952, 360, 93, 10784, 199, 70, 14, 1600, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 2344, 199, 12147, 3824, 12594, 3326, 367, 7761, 436, 3957, 370, 3959, 20, 1059, 8710, 880, 626, 199, 29002, 883, 506, 29438, 1536, 701, 3959, 634, 14659, 631, 14, 199, 2344, 199, 504, 3873, 492, 13995, 12, 22773, 199, 646, 5739, 199, 646, 4182, 199, 199, 1877, 63, 14533, 628, 2164, 15, 8440, 15, 22816, 5465, 14, 5910, 2, 199, 13993, 2968, 341, 418, 199, 199, 318, 2198, 63, 555, 8, 505, 304, 272, 408, 272, 6077, 283, 555, 7, 1475, 13584, 701, 671, 5152, 14, 272, 1432, 282, 769, 402, 334, 15245, 12, 23367, 9, 6346, 14, 272, 408, 272, 3788, 275, 942, 272, 17879, 275, 942, 272, 1499, 495, 275, 942, 272, 315, 63, 15245, 275, 756, 272, 315, 63, 23367, 275, 756, 339, 367, 1004, 315, 1318, 14, 1294, 2258, 78, 735, 267, 1004, 275, 1004, 14, 6735, 2258, 82, 358, 267, 340, 1004, 14, 2460, 360, 15245, 18927, 288, 340, 315, 63, 23367, 26, 355, 3788, 14, 740, 1332, 15245, 12, 1499, 495, 430, 355, 315, 63, 23367, 275, 756, 288, 327, 1245, 1343, 288, 315, 63, 15245, 275, 715, 7846, 17879, 275, 359, 604, 59, 22, 21316, 267, 916, 1004, 14, 2460, 360, 23367, 18927, 288, 315, 63, 15245, 275, 756, 288, 315, 63, 23367, 275, 715, 288, 1499, 495, 275, 359, 604, 59, 23, 21316, 267, 916, 1004, 14, 2460, 14088, 735, 288, 340, 315, 63, 15245, 26, 355, 17879, 14, 740, 8, 604, 9, 288, 340, 315, 63, 23367, 26, 355, 1499, 495, 14, 740, 8, 604, 9, 339, 340, 315, 63, 23367, 26, 267, 3788, 14, 740, 1332, 15245, 12, 1499, 495, 430, 339, 372, 3788, 199, 199, 1725, 275, 5739, 14, 6463, 360, 2164, 20362, 5910, 358, 435, 5739, 14, 6463, 360, 2164, 20362, 72, 358, 9948, 199, 3, 671, 5152, 446, 78, 1553, 6691, 3699, 2672, 9472, 199, 1739, 275, 13995, 2941, 88, 5152, 28280, 1199, 4022, 21810, 78, 28280, 6691, 3699, 418, 435, 1584, 12, 3839, 29, 6089, 9, 199, 8, 548, 12, 2329, 9, 275, 1982, 14, 10664, 342, 199, 199, 3431, 275, 2198, 63, 555, 8, 548, 9, 9948, 199, 70, 275, 1551, 8, 1877, 63, 14533, 12, 283, 87, 358, 199, 70, 14, 952, 4852, 3, 2613, 665, 4238, 7025, 30, 199, 501, 9195, 17174, 4046, 701, 5536, 63, 5465, 14, 647, 199, 3, 27737, 636, 17732, 35, 363, 199, 3, 4640, 738, 27726, 636, 3215, 721, 8, 8618, 430, 199, 3, 2836, 199, 3, 4640, 738, 27726, 199, 3, 13739, 199, 6141, 199, 70, 14, 952, 360, 1986, 950, 1495, 738, 27726, 627, 22816, 63, 5465, 8607, 275, 9459, 78, 358, 199, 3431, 14, 3191, 8, 498, 29, 3856, 14, 20832, 8, 16, 430, 199, 509, 334, 15245, 12, 1499, 495, 9, 315, 3788, 26, 272, 340, 17879, 1137, 16589, 26, 267, 289, 14, 952, 360, 19229, 63, 26376, 1951, 63, 2826, 1938, 480, 22816, 13, 1018, 401, 450, 83, 26323, 78, 7, 450, 17485, 78, 1370, 904, 8, 15245, 1724, 199, 70, 14, 952, 360, 93, 10784, 199, 70, 14, 1600, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
havard024/prego
venv/lib/python2.7/site-packages/whoosh/util/varints.py
95
3198
# Copyright 2007 Matt Chaput. 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. # # THIS SOFTWARE IS PROVIDED BY MATT CHAPUT ``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 MATT CHAPUT 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. # # The views and conclusions contained in the software and documentation are # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of Matt Chaput. from array import array from whoosh.compat import array_tobytes, xrange # Varint cache # Build a cache of the varint byte sequences for the first N integers, so we # don't have to constantly recalculate them on the fly. This makes a small but # noticeable difference. def _varint(i): a = array("B") while (i & ~0x7F) != 0: a.append((i & 0x7F) | 0x80) i = i >> 7 a.append(i) return array_tobytes(a) _varint_cache_size = 512 _varint_cache = [] for i in xrange(0, _varint_cache_size): _varint_cache.append(_varint(i)) _varint_cache = tuple(_varint_cache) def varint(i): """Encodes the given integer into a string of the minimum number of bytes. """ if i < len(_varint_cache): return _varint_cache[i] return _varint(i) def varint_to_int(vi): b = ord(vi[0]) p = 1 i = b & 0x7f shift = 7 while b & 0x80 != 0: b = ord(vi[p]) p += 1 i |= (b & 0x7F) << shift shift += 7 return i def signed_varint(i): """Zig-zag encodes a signed integer into a varint. """ if i >= 0: return varint(i << 1) return varint((i << 1) ^ (~0)) def decode_signed_varint(i): """Zig-zag decodes an integer value. """ if not i & 1: return i >> 1 return (i >> 1) ^ (~0) def read_varint(readfn): """ Reads a variable-length encoded integer. :param readfn: a callable that reads a given number of bytes, like file.read(). """ b = ord(readfn(1)) i = b & 0x7F shift = 7 while b & 0x80 != 0: b = ord(readfn(1)) i |= (b & 0x7F) << shift shift += 7 return i
mit
[ 3, 1898, 10219, 31653, 2799, 439, 337, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 3, 199, 3, 259, 413, 14, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 199, 3, 755, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 199, 3, 259, 499, 14, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 755, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 755, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 603, 11712, 6624, 1282, 934, 1124, 1179, 2281, 891, 2401, 1821, 7168, 1549, 199, 3, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 2990, 1634, 199, 3, 3169, 2401, 3092, 2381, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 199, 3, 6461, 7000, 603, 11712, 6624, 1282, 934, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 199, 3, 9716, 12, 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, 7126, 12, 199, 3, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 199, 3, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 3, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 199, 3, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 3, 199, 3, 710, 6858, 436, 406, 18540, 10470, 315, 314, 2032, 436, 3794, 787, 199, 3, 5204, 402, 314, 11462, 436, 1077, 440, 506, 11922, 465, 6144, 25410, 199, 3, 14118, 12, 1902, 19147, 503, 2478, 12, 402, 31653, 2799, 439, 337, 14, 199, 199, 504, 1625, 492, 1625, 199, 199, 504, 3963, 22267, 14, 5819, 492, 1625, 63, 32557, 12, 4945, 421, 199, 3, 21084, 442, 2581, 199, 199, 3, 6516, 282, 2581, 402, 314, 2729, 442, 3696, 8013, 367, 314, 1642, 653, 9446, 12, 880, 781, 199, 3, 2793, 1133, 1172, 370, 4413, 590, 295, 12063, 3062, 641, 314, 23158, 14, 961, 7704, 282, 7425, 1325, 199, 3, 4245, 461, 8865, 14, 199, 199, 318, 485, 1391, 442, 8, 73, 304, 272, 282, 275, 1625, 480, 34, 531, 272, 1830, 334, 73, 1253, 6146, 16, 88, 23, 38, 9, 1137, 378, 26, 267, 282, 14, 740, 1332, 73, 1253, 378, 88, 23, 38, 9, 1204, 378, 88, 1257, 9, 267, 284, 275, 284, 4331, 1520, 272, 282, 14, 740, 8, 73, 9, 272, 372, 1625, 63, 32557, 8, 65, 9, 421, 199, 63, 1391, 442, 63, 1637, 63, 890, 275, 10574, 199, 63, 1391, 442, 63, 1637, 275, 942, 199, 509, 284, 315, 4945, 8, 16, 12, 485, 1391, 442, 63, 1637, 63, 890, 304, 272, 485, 1391, 442, 63, 1637, 14, 740, 1547, 1391, 442, 8, 73, 430, 199, 63, 1391, 442, 63, 1637, 275, 2008, 1547, 1391, 442, 63, 1637, 9, 421, 199, 318, 2729, 442, 8, 73, 304, 272, 408, 1327, 6021, 314, 1627, 3000, 1901, 282, 1059, 402, 314, 7481, 1329, 221, 402, 2783, 14, 272, 408, 272, 340, 284, 665, 822, 1547, 1391, 442, 63, 1637, 304, 267, 372, 485, 1391, 442, 63, 1637, 59, 73, 61, 272, 372, 485, 1391, 442, 8, 73, 9, 421, 199, 318, 2729, 442, 63, 475, 63, 442, 8, 433, 304, 272, 330, 275, 6206, 8, 433, 59, 16, 566, 272, 299, 275, 413, 272, 284, 275, 330, 1253, 378, 88, 23, 70, 272, 7706, 275, 1520, 272, 1830, 330, 1253, 378, 88, 1257, 1137, 378, 26, 267, 330, 275, 6206, 8, 433, 59, 80, 566, 267, 299, 847, 413, 267, 284, 8901, 334, 66, 1253, 378, 88, 23, 38, 9, 5213, 7706, 267, 7706, 847, 1520, 272, 372, 284, 421, 199, 318, 10514, 63, 1391, 442, 8, 73, 304, 272, 408, 58, 528, 13, 90, 643, 3752, 83, 282, 10514, 3000, 1901, 282, 2729, 442, 14, 272, 408, 339, 340, 284, 2356, 378, 26, 267, 372, 2729, 442, 8, 73, 5213, 413, 9, 272, 372, 2729, 442, 1332, 73, 5213, 413, 9, 7167, 31742, 16, 430, 421, 199, 318, 4849, 63, 1737, 63, 1391, 442, 8, 73, 304, 272, 408, 58, 528, 13, 90, 643, 4849, 83, 376, 3000, 574, 14, 272, 408, 339, 340, 440, 284, 1253, 413, 26, 267, 372, 284, 4331, 413, 272, 372, 334, 73, 4331, 413, 9, 7167, 31742, 16, 9, 421, 199, 318, 1586, 63, 1391, 442, 8, 739, 2324, 304, 272, 408, 272, 26129, 282, 1750, 13, 1267, 5737, 3000, 14, 339, 520, 635, 1586, 2324, 26, 282, 4550, 626, 11597, 282, 1627, 1329, 402, 2783, 12, 267, 2839, 570, 14, 739, 1252, 272, 408, 339, 330, 275, 6206, 8, 739, 2324, 8, 17, 430, 272, 284, 275, 330, 1253, 378, 88, 23, 38, 339, 7706, 275, 1520, 272, 1830, 330, 1253, 378, 88, 1257, 1137, 378, 26, 267, 330, 275, 6206, 8, 739, 2324, 8, 17, 430, 267, 284, 8901, 334, 66, 1253, 378, 88, 23, 38, 9, 5213, 7706, 267, 7706, 847, 1520, 272, 372, 284, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 10219, 31653, 2799, 439, 337, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 3, 199, 3, 259, 413, 14, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 199, 3, 755, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 199, 3, 259, 499, 14, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 755, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 755, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 603, 11712, 6624, 1282, 934, 1124, 1179, 2281, 891, 2401, 1821, 7168, 1549, 199, 3, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 2990, 1634, 199, 3, 3169, 2401, 3092, 2381, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 199, 3, 6461, 7000, 603, 11712, 6624, 1282, 934, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 199, 3, 9716, 12, 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, 7126, 12, 199, 3, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 199, 3, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 3, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 199, 3, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 3, 199, 3, 710, 6858, 436, 406, 18540, 10470, 315, 314, 2032, 436, 3794, 787, 199, 3, 5204, 402, 314, 11462, 436, 1077, 440, 506, 11922, 465, 6144, 25410, 199, 3, 14118, 12, 1902, 19147, 503, 2478, 12, 402, 31653, 2799, 439, 337, 14, 199, 199, 504, 1625, 492, 1625, 199, 199, 504, 3963, 22267, 14, 5819, 492, 1625, 63, 32557, 12, 4945, 421, 199, 3, 21084, 442, 2581, 199, 199, 3, 6516, 282, 2581, 402, 314, 2729, 442, 3696, 8013, 367, 314, 1642, 653, 9446, 12, 880, 781, 199, 3, 2793, 1133, 1172, 370, 4413, 590, 295, 12063, 3062, 641, 314, 23158, 14, 961, 7704, 282, 7425, 1325, 199, 3, 4245, 461, 8865, 14, 199, 199, 318, 485, 1391, 442, 8, 73, 304, 272, 282, 275, 1625, 480, 34, 531, 272, 1830, 334, 73, 1253, 6146, 16, 88, 23, 38, 9, 1137, 378, 26, 267, 282, 14, 740, 1332, 73, 1253, 378, 88, 23, 38, 9, 1204, 378, 88, 1257, 9, 267, 284, 275, 284, 4331, 1520, 272, 282, 14, 740, 8, 73, 9, 272, 372, 1625, 63, 32557, 8, 65, 9, 421, 199, 63, 1391, 442, 63, 1637, 63, 890, 275, 10574, 199, 63, 1391, 442, 63, 1637, 275, 942, 199, 509, 284, 315, 4945, 8, 16, 12, 485, 1391, 442, 63, 1637, 63, 890, 304, 272, 485, 1391, 442, 63, 1637, 14, 740, 1547, 1391, 442, 8, 73, 430, 199, 63, 1391, 442, 63, 1637, 275, 2008, 1547, 1391, 442, 63, 1637, 9, 421, 199, 318, 2729, 442, 8, 73, 304, 272, 408, 1327, 6021, 314, 1627, 3000, 1901, 282, 1059, 402, 314, 7481, 1329, 221, 402, 2783, 14, 272, 408, 272, 340, 284, 665, 822, 1547, 1391, 442, 63, 1637, 304, 267, 372, 485, 1391, 442, 63, 1637, 59, 73, 61, 272, 372, 485, 1391, 442, 8, 73, 9, 421, 199, 318, 2729, 442, 63, 475, 63, 442, 8, 433, 304, 272, 330, 275, 6206, 8, 433, 59, 16, 566, 272, 299, 275, 413, 272, 284, 275, 330, 1253, 378, 88, 23, 70, 272, 7706, 275, 1520, 272, 1830, 330, 1253, 378, 88, 1257, 1137, 378, 26, 267, 330, 275, 6206, 8, 433, 59, 80, 566, 267, 299, 847, 413, 267, 284, 8901, 334, 66, 1253, 378, 88, 23, 38, 9, 5213, 7706, 267, 7706, 847, 1520, 272, 372, 284, 421, 199, 318, 10514, 63, 1391, 442, 8, 73, 304, 272, 408, 58, 528, 13, 90, 643, 3752, 83, 282, 10514, 3000, 1901, 282, 2729, 442, 14, 272, 408, 339, 340, 284, 2356, 378, 26, 267, 372, 2729, 442, 8, 73, 5213, 413, 9, 272, 372, 2729, 442, 1332, 73, 5213, 413, 9, 7167, 31742, 16, 430, 421, 199, 318, 4849, 63, 1737, 63, 1391, 442, 8, 73, 304, 272, 408, 58, 528, 13, 90, 643, 4849, 83, 376, 3000, 574, 14, 272, 408, 339, 340, 440, 284, 1253, 413, 26, 267, 372, 284, 4331, 413, 272, 372, 334, 73, 4331, 413, 9, 7167, 31742, 16, 9, 421, 199, 318, 1586, 63, 1391, 442, 8, 739, 2324, 304, 272, 408, 272, 26129, 282, 1750, 13, 1267, 5737, 3000, 14, 339, 520, 635, 1586, 2324, 26, 282, 4550, 626, 11597, 282, 1627, 1329, 402, 2783, 12, 267, 2839, 570, 14, 739, 1252, 272, 408, 339, 330, 275, 6206, 8, 739, 2324, 8, 17, 430, 272, 284, 275, 330, 1253, 378, 88, 23, 38, 339, 7706, 275, 1520, 272, 1830, 330, 1253, 378, 88, 1257, 1137, 378, 26, 267, 330, 275, 6206, 8, 739, 2324, 8, 17, 430, 267, 284, 8901, 334, 66, 1253, 378, 88, 23, 38, 9, 5213, 7706, 267, 7706, 847, 1520, 272, 372, 284, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
PyORBIT-Collaboration/JPARC_Accelerator
JPARC_Linac/jparc_linac_model/jparc_linac_bunch_generator.py
2
3411
#!/usr/bin/env python #-------------------------------------------------------- # The classes will generates bunches for pyORBIT J-PARC linac # at the entrance of LI_MEBT1 accelerator line (by default) # It is parallel, but it is not efficient. #-------------------------------------------------------- import math import sys import os import random import orbit_mpi from orbit_mpi import mpi_comm from orbit_mpi import mpi_datatype from orbit_mpi import mpi_op from orbit.bunch_generators import TwissContainer from orbit.bunch_generators import KVDist2D, KVDist3D from orbit.bunch_generators import GaussDist2D, GaussDist3D from orbit.bunch_generators import WaterBagDist2D, WaterBagDist3D from orbit.bunch_generators import TwissAnalysis from bunch import Bunch class JPARC_Linac_BunchGenerator: """ Generates the pyORBIT JPARC Linac Bunches. Twiss parameters has the following units: x in [m], xp in [rad] and the X and Y emittances are un-normalized. The longitudinal emittance is in [GeV*m]. """ def __init__(self,twissX, twissY, twissZ, frequency = 324.0e+6): self.twiss = (twissX, twissY, twissZ) self.bunch_frequency = frequency self.bunch = Bunch() syncPart = self.bunch.getSyncParticle() #set H- mass #self.bunch.mass(0.9382723 + 2*0.000511) self.bunch.mass(0.939294) self.bunch.charge(-1.0) syncPart.kinEnergy(0.003) self.c = 2.99792458e+8 # speed of light in m/sec self.beam_current = 40.0 # beam current in mA self.rf_wave_lenght = self.c/self.bunch_frequency self.si_e_charge = 1.6021773e-19 def getKinEnergy(self): """ Returns the kinetic energy in GeV """ return self.bunch.getSyncParticle().kinEnergy() def setKinEnergy(self, e_kin = 0.003): """ Sets the kinetic energy in GeV """ self.bunch.getSyncParticle().kinEnergy(e_kin) def getZtoPhaseCoeff(self,bunch): """ Returns the coefficient to calculate phase in degrees from the z-coordinate. """ bunch_lambda = bunch.getSyncParticle().beta()*self.rf_wave_lenght phase_coeff = 360./bunch_lambda return phase_coeff def getBeamCurrent(self): """ Returns the beam currect in mA """ return self.beam_current def setBeamCurrent(self, current): """ Sets the beam currect in mA """ self.beam_current = current def getBunch(self, nParticles = 0, distributorClass = WaterBagDist3D, cut_off = -1.): """ Returns the pyORBIT bunch with particular number of particles. """ comm = orbit_mpi.mpi_comm.MPI_COMM_WORLD rank = orbit_mpi.MPI_Comm_rank(comm) size = orbit_mpi.MPI_Comm_size(comm) data_type = mpi_datatype.MPI_DOUBLE main_rank = 0 bunch = Bunch() self.bunch.copyEmptyBunchTo(bunch) macrosize = (self.beam_current*1.0e-3/self.bunch_frequency) macrosize /= (math.fabs(bunch.charge())*self.si_e_charge) distributor = None if(distributorClass == WaterBagDist3D): distributor = distributorClass(self.twiss[0],self.twiss[1],self.twiss[2]) else: distributor = distributorClass(self.twiss[0],self.twiss[1],self.twiss[2], cut_off) bunch.getSyncParticle().time(0.) for i in range(nParticles): (x,xp,y,yp,z,dE) = distributor.getCoordinates() (x,xp,y,yp,z,dE) = orbit_mpi.MPI_Bcast((x,xp,y,yp,z,dE),data_type,main_rank,comm) if(i%size == rank): bunch.addParticle(x,xp,y,yp,z,dE) nParticlesGlobal = bunch.getSizeGlobal() bunch.macroSize(macrosize/nParticlesGlobal) return bunch
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 17807, 518, 199, 3, 710, 3992, 911, 12821, 22219, 397, 367, 1134, 726, 11970, 1603, 13, 4014, 35, 7403, 645, 221, 199, 3, 737, 314, 29966, 554, 402, 3782, 63, 3635, 19162, 17, 1066, 27139, 1004, 334, 991, 849, 9, 199, 3, 2779, 365, 9861, 12, 1325, 652, 365, 440, 13402, 14, 199, 17807, 518, 199, 199, 646, 3473, 199, 646, 984, 199, 646, 747, 199, 646, 2196, 199, 199, 646, 503, 2075, 63, 13213, 199, 504, 503, 2075, 63, 13213, 492, 26806, 63, 1404, 199, 504, 503, 2075, 63, 13213, 492, 26806, 63, 14184, 199, 504, 503, 2075, 63, 13213, 492, 26806, 63, 411, 199, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 377, 87, 19857, 4076, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 1804, 54, 12012, 18, 36, 12, 1804, 54, 12012, 19, 36, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 598, 23822, 12012, 18, 36, 12, 598, 23822, 12012, 19, 36, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 644, 6618, 31641, 12012, 18, 36, 12, 644, 6618, 31641, 12012, 19, 36, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 377, 87, 19857, 13182, 199, 199, 504, 22219, 492, 699, 4689, 199, 199, 533, 1603, 4014, 35, 63, 27889, 645, 63, 34, 4689, 7599, 26, 199, 198, 624, 199, 198, 20551, 314, 1134, 726, 11970, 1603, 4014, 35, 29730, 645, 699, 4689, 397, 14, 199, 198, 22879, 19857, 2633, 965, 314, 2569, 6204, 26, 671, 315, 359, 77, 467, 21499, 315, 359, 9525, 61, 199, 198, 460, 314, 1323, 436, 1488, 8689, 84, 13236, 787, 625, 13, 12916, 14, 710, 1846, 390, 1181, 1582, 8689, 84, 554, 9948, 198, 374, 315, 359, 4240, 54, 10, 77, 1055, 199, 198, 624, 199, 198, 318, 636, 826, 721, 277, 12, 8122, 19857, 56, 12, 8900, 19857, 57, 12, 8900, 19857, 58, 12, 9857, 275, 650, 1194, 14, 16, 69, 11, 22, 304, 507, 198, 277, 14, 8122, 19857, 275, 334, 8122, 19857, 56, 12, 8900, 19857, 57, 12, 8900, 19857, 58, 9, 507, 198, 277, 14, 66, 4689, 63, 11132, 275, 9857, 507, 198, 277, 14, 66, 4689, 275, 699, 4689, 342, 507, 198, 5186, 8416, 275, 291, 14, 66, 4689, 14, 362, 10878, 14986, 342, 507, 198, 3, 409, 869, 13, 12250, 507, 198, 3, 277, 14, 66, 4689, 14, 11535, 8, 16, 14, 25, 1703, 1465, 1789, 435, 499, 10, 16, 14, 15646, 845, 9, 507, 198, 277, 14, 66, 4689, 14, 11535, 8, 16, 14, 31281, 10693, 9, 507, 198, 277, 14, 66, 4689, 14, 16441, 2801, 17, 14, 16, 9, 507, 198, 5186, 8416, 14, 19269, 9900, 8, 16, 14, 8262, 9, 507, 198, 277, 14, 67, 275, 499, 14, 1020, 1965, 1194, 2010, 69, 11, 24, 259, 327, 8112, 402, 10540, 315, 333, 15, 3321, 507, 198, 277, 14, 14529, 63, 1818, 275, 6335, 14, 16, 221, 327, 17453, 1453, 315, 333, 33, 507, 198, 277, 14, 3941, 63, 10024, 63, 552, 913, 275, 291, 14, 67, 15, 277, 14, 66, 4689, 63, 11132, 507, 198, 277, 14, 338, 63, 69, 63, 16441, 275, 413, 14, 28384, 8881, 19, 69, 13, 1167, 18118, 198, 318, 664, 43, 262, 9900, 8, 277, 304, 507, 198, 624, 507, 198, 3407, 314, 1022, 1132, 764, 12304, 315, 5346, 54, 507, 198, 624, 507, 198, 1107, 291, 14, 66, 4689, 14, 362, 10878, 14986, 1252, 19269, 9900, 342, 18118, 198, 318, 663, 43, 262, 9900, 8, 277, 12, 325, 63, 19269, 275, 378, 14, 8262, 304, 507, 198, 624, 507, 198, 9899, 314, 1022, 1132, 764, 12304, 315, 5346, 54, 507, 198, 624, 507, 198, 277, 14, 66, 4689, 14, 362, 10878, 14986, 1252, 19269, 9900, 8, 69, 63, 19269, 9, 18118, 198, 318, 664, 58, 475, 10521, 967, 3609, 8, 277, 12, 66, 4689, 304, 507, 198, 624, 507, 198, 3407, 314, 9421, 370, 8671, 7669, 315, 14358, 687, 314, 1315, 13, 20493, 14, 507, 198, 624, 507, 198, 66, 4689, 63, 2734, 275, 22219, 14, 362, 10878, 14986, 1252, 5683, 25608, 277, 14, 3941, 63, 10024, 63, 552, 913, 11083, 198, 6971, 63, 8903, 275, 19434, 13186, 66, 4689, 63, 2734, 507, 198, 1107, 7669, 63, 8903, 18118, 198, 318, 664, 3655, 455, 5639, 8, 277, 304, 507, 198, 624, 507, 198, 3407, 314, 17453, 1094, 1201, 315, 333, 33, 507, 198, 624, 507, 198, 1107, 291, 14, 14529, 63, 1818, 18118, 198, 318, 663, 3655, 455, 5639, 8, 277, 12, 1453, 304, 507, 198, 624, 507, 198, 9899, 221, 314, 17453, 1094, 1201, 315, 333, 33, 507, 198, 624, 507, 198, 277, 14, 14529, 63, 1818, 275, 1453, 8299, 198, 318, 664, 34, 4689, 8, 277, 12, 302, 14986, 83, 275, 378, 12, 29573, 4139, 2543, 275, 644, 6618, 31641, 12012, 19, 36, 12, 10415, 63, 1997, 275, 446, 17, 14, 304, 507, 198, 624, 507, 198, 3407, 314, 1134, 726, 11970, 22219, 543, 6770, 1329, 402, 26115, 14, 507, 198, 624, 507, 198, 1404, 275, 503, 2075, 63, 13213, 14, 13213, 63, 1404, 14, 28983, 63, 5378, 63, 22125, 507, 198, 4648, 275, 503, 2075, 63, 13213, 14, 28983, 63, 5150, 63, 4648, 8, 1404, 9, 507, 198, 890, 275, 503, 2075, 63, 13213, 14, 28983, 63, 5150, 63, 890, 8, 1404, 9, 1057, 507, 198, 576, 63, 466, 275, 26806, 63, 14184, 14, 28983, 63, 14989, 1057, 507, 198, 973, 63, 4648, 275, 378, 1057, 507, 198, 66, 4689, 275, 699, 4689, 342, 507, 198, 277, 14, 66, 4689, 14, 1574, 4699, 34, 4689, 1378, 8, 66, 4689, 9, 1057, 507, 198, 11300, 890, 275, 334, 277, 14, 14529, 63, 1818, 10, 17, 14, 16, 69, 13, 19, 15, 277, 14, 66, 4689, 63, 11132, 9, 507, 198, 11300, 890, 12257, 334, 3442, 14, 70, 2101, 8, 66, 4689, 14, 16441, 1012, 10, 277, 14, 338, 63, 69, 63, 16441, 9, 507, 198, 20231, 4139, 275, 488, 507, 198, 692, 8, 20231, 4139, 2543, 508, 644, 6618, 31641, 12012, 19, 36, 304, 686, 198, 20231, 4139, 275, 29573, 4139, 2543, 8, 277, 14, 8122, 19857, 59 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 17807, 518, 199, 3, 710, 3992, 911, 12821, 22219, 397, 367, 1134, 726, 11970, 1603, 13, 4014, 35, 7403, 645, 221, 199, 3, 737, 314, 29966, 554, 402, 3782, 63, 3635, 19162, 17, 1066, 27139, 1004, 334, 991, 849, 9, 199, 3, 2779, 365, 9861, 12, 1325, 652, 365, 440, 13402, 14, 199, 17807, 518, 199, 199, 646, 3473, 199, 646, 984, 199, 646, 747, 199, 646, 2196, 199, 199, 646, 503, 2075, 63, 13213, 199, 504, 503, 2075, 63, 13213, 492, 26806, 63, 1404, 199, 504, 503, 2075, 63, 13213, 492, 26806, 63, 14184, 199, 504, 503, 2075, 63, 13213, 492, 26806, 63, 411, 199, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 377, 87, 19857, 4076, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 1804, 54, 12012, 18, 36, 12, 1804, 54, 12012, 19, 36, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 598, 23822, 12012, 18, 36, 12, 598, 23822, 12012, 19, 36, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 644, 6618, 31641, 12012, 18, 36, 12, 644, 6618, 31641, 12012, 19, 36, 199, 504, 503, 2075, 14, 66, 4689, 63, 20748, 492, 377, 87, 19857, 13182, 199, 199, 504, 22219, 492, 699, 4689, 199, 199, 533, 1603, 4014, 35, 63, 27889, 645, 63, 34, 4689, 7599, 26, 199, 198, 624, 199, 198, 20551, 314, 1134, 726, 11970, 1603, 4014, 35, 29730, 645, 699, 4689, 397, 14, 199, 198, 22879, 19857, 2633, 965, 314, 2569, 6204, 26, 671, 315, 359, 77, 467, 21499, 315, 359, 9525, 61, 199, 198, 460, 314, 1323, 436, 1488, 8689, 84, 13236, 787, 625, 13, 12916, 14, 710, 1846, 390, 1181, 1582, 8689, 84, 554, 9948, 198, 374, 315, 359, 4240, 54, 10, 77, 1055, 199, 198, 624, 199, 198, 318, 636, 826, 721, 277, 12, 8122, 19857, 56, 12, 8900, 19857, 57, 12, 8900, 19857, 58, 12, 9857, 275, 650, 1194, 14, 16, 69, 11, 22, 304, 507, 198, 277, 14, 8122, 19857, 275, 334, 8122, 19857, 56, 12, 8900, 19857, 57, 12, 8900, 19857, 58, 9, 507, 198, 277, 14, 66, 4689, 63, 11132, 275, 9857, 507, 198, 277, 14, 66, 4689, 275, 699, 4689, 342, 507, 198, 5186, 8416, 275, 291, 14, 66, 4689, 14, 362, 10878, 14986, 342, 507, 198, 3, 409, 869, 13, 12250, 507, 198, 3, 277, 14, 66, 4689, 14, 11535, 8, 16, 14, 25, 1703, 1465, 1789, 435, 499, 10, 16, 14, 15646, 845, 9, 507, 198, 277, 14, 66, 4689, 14, 11535, 8, 16, 14, 31281, 10693, 9, 507, 198, 277, 14, 66, 4689, 14, 16441, 2801, 17, 14, 16, 9, 507, 198, 5186, 8416, 14, 19269, 9900, 8, 16, 14, 8262, 9, 507, 198, 277, 14, 67, 275, 499, 14, 1020, 1965, 1194, 2010, 69, 11, 24, 259, 327, 8112, 402, 10540, 315, 333, 15, 3321, 507, 198, 277, 14, 14529, 63, 1818, 275, 6335, 14, 16, 221, 327, 17453, 1453, 315, 333, 33, 507, 198, 277, 14, 3941, 63, 10024, 63, 552, 913, 275, 291, 14, 67, 15, 277, 14, 66, 4689, 63, 11132, 507, 198, 277, 14, 338, 63, 69, 63, 16441, 275, 413, 14, 28384, 8881, 19, 69, 13, 1167, 18118, 198, 318, 664, 43, 262, 9900, 8, 277, 304, 507, 198, 624, 507, 198, 3407, 314, 1022, 1132, 764, 12304, 315, 5346, 54, 507, 198, 624, 507, 198, 1107, 291, 14, 66, 4689, 14, 362, 10878, 14986, 1252, 19269, 9900, 342, 18118, 198, 318, 663, 43, 262, 9900, 8, 277, 12, 325, 63, 19269, 275, 378, 14, 8262, 304, 507, 198, 624, 507, 198, 9899, 314, 1022, 1132, 764, 12304, 315, 5346, 54, 507, 198, 624, 507, 198, 277, 14, 66, 4689, 14, 362, 10878, 14986, 1252, 19269, 9900, 8, 69, 63, 19269, 9, 18118, 198, 318, 664, 58, 475, 10521, 967, 3609, 8, 277, 12, 66, 4689, 304, 507, 198, 624, 507, 198, 3407, 314, 9421, 370, 8671, 7669, 315, 14358, 687, 314, 1315, 13, 20493, 14, 507, 198, 624, 507, 198, 66, 4689, 63, 2734, 275, 22219, 14, 362, 10878, 14986, 1252, 5683, 25608, 277, 14, 3941, 63, 10024, 63, 552, 913, 11083, 198, 6971, 63, 8903, 275, 19434, 13186, 66, 4689, 63, 2734, 507, 198, 1107, 7669, 63, 8903, 18118, 198, 318, 664, 3655, 455, 5639, 8, 277, 304, 507, 198, 624, 507, 198, 3407, 314, 17453, 1094, 1201, 315, 333, 33, 507, 198, 624, 507, 198, 1107, 291, 14, 14529, 63, 1818, 18118, 198, 318, 663, 3655, 455, 5639, 8, 277, 12, 1453, 304, 507, 198, 624, 507, 198, 9899, 221, 314, 17453, 1094, 1201, 315, 333, 33, 507, 198, 624, 507, 198, 277, 14, 14529, 63, 1818, 275, 1453, 8299, 198, 318, 664, 34, 4689, 8, 277, 12, 302, 14986, 83, 275, 378, 12, 29573, 4139, 2543, 275, 644, 6618, 31641, 12012, 19, 36, 12, 10415, 63, 1997, 275, 446, 17, 14, 304, 507, 198, 624, 507, 198, 3407, 314, 1134, 726, 11970, 22219, 543, 6770, 1329, 402, 26115, 14, 507, 198, 624, 507, 198, 1404, 275, 503, 2075, 63, 13213, 14, 13213, 63, 1404, 14, 28983, 63, 5378, 63, 22125, 507, 198, 4648, 275, 503, 2075, 63, 13213, 14, 28983, 63, 5150, 63, 4648, 8, 1404, 9, 507, 198, 890, 275, 503, 2075, 63, 13213, 14, 28983, 63, 5150, 63, 890, 8, 1404, 9, 1057, 507, 198, 576, 63, 466, 275, 26806, 63, 14184, 14, 28983, 63, 14989, 1057, 507, 198, 973, 63, 4648, 275, 378, 1057, 507, 198, 66, 4689, 275, 699, 4689, 342, 507, 198, 277, 14, 66, 4689, 14, 1574, 4699, 34, 4689, 1378, 8, 66, 4689, 9, 1057, 507, 198, 11300, 890, 275, 334, 277, 14, 14529, 63, 1818, 10, 17, 14, 16, 69, 13, 19, 15, 277, 14, 66, 4689, 63, 11132, 9, 507, 198, 11300, 890, 12257, 334, 3442, 14, 70, 2101, 8, 66, 4689, 14, 16441, 1012, 10, 277, 14, 338, 63, 69, 63, 16441, 9, 507, 198, 20231, 4139, 275, 488, 507, 198, 692, 8, 20231, 4139, 2543, 508, 644, 6618, 31641, 12012, 19, 36, 304, 686, 198, 20231, 4139, 275, 29573, 4139, 2543, 8, 277, 14, 8122, 19857, 59, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
shail2810/nova
nova/tests/unit/api/openstack/compute/test_extended_server_attributes.py
33
8459
# Copyright 2011 OpenStack Foundation # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from oslo_config import cfg from oslo_serialization import jsonutils import webob from nova.api.openstack import wsgi as os_wsgi from nova import compute from nova import db from nova import exception from nova import objects from nova import test from nova.tests.unit.api.openstack import fakes NAME_FMT = cfg.CONF.instance_name_template UUID1 = '00000000-0000-0000-0000-000000000001' UUID2 = '00000000-0000-0000-0000-000000000002' UUID3 = '00000000-0000-0000-0000-000000000003' UUID4 = '00000000-0000-0000-0000-000000000004' UUID5 = '00000000-0000-0000-0000-000000000005' def fake_compute_get(*args, **kwargs): return fakes.stub_instance_obj( None, 1, uuid=UUID3, host="host-fake", node="node-fake", reservation_id="r-1", launch_index=0, kernel_id=UUID4, ramdisk_id=UUID5, display_name="hostname-1", root_device_name="/dev/vda", user_data="userdata") def fake_compute_get_all(*args, **kwargs): inst_list = [ fakes.stub_instance_obj( None, 1, uuid=UUID1, host="host-1", node="node-1", reservation_id="r-1", launch_index=0, kernel_id=UUID4, ramdisk_id=UUID5, display_name="hostname-1", root_device_name="/dev/vda", user_data="userdata"), fakes.stub_instance_obj( None, 2, uuid=UUID2, host="host-2", node="node-2", reservation_id="r-2", launch_index=1, kernel_id=UUID4, ramdisk_id=UUID5, display_name="hostname-2", root_device_name="/dev/vda", user_data="userdata"), ] return objects.InstanceList(objects=inst_list) class ExtendedServerAttributesTestV21(test.TestCase): content_type = 'application/json' prefix = 'OS-EXT-SRV-ATTR:' fake_url = '/v2/fake' wsgi_api_version = os_wsgi.DEFAULT_API_VERSION def setUp(self): super(ExtendedServerAttributesTestV21, self).setUp() fakes.stub_out_nw_api(self.stubs) self.stubs.Set(compute.api.API, 'get', fake_compute_get) self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all) self.stubs.Set(db, 'instance_get_by_uuid', fake_compute_get) def _make_request(self, url): req = fakes.HTTPRequest.blank(url) req.headers['Accept'] = self.content_type req.headers = {os_wsgi.API_VERSION_REQUEST_HEADER: self.wsgi_api_version} res = req.get_response( fakes.wsgi_app_v21(init_only=('servers', 'os-extended-server-attributes'))) return res def _get_server(self, body): return jsonutils.loads(body).get('server') def _get_servers(self, body): return jsonutils.loads(body).get('servers') def assertServerAttributes(self, server, host, node, instance_name): self.assertEqual(server.get('%shost' % self.prefix), host) self.assertEqual(server.get('%sinstance_name' % self.prefix), instance_name) self.assertEqual(server.get('%shypervisor_hostname' % self.prefix), node) def test_show(self): url = self.fake_url + '/servers/%s' % UUID3 res = self._make_request(url) self.assertEqual(res.status_int, 200) self.assertServerAttributes(self._get_server(res.body), host='host-fake', node='node-fake', instance_name=NAME_FMT % 1) def test_detail(self): url = self.fake_url + '/servers/detail' res = self._make_request(url) self.assertEqual(res.status_int, 200) for i, server in enumerate(self._get_servers(res.body)): self.assertServerAttributes(server, host='host-%s' % (i + 1), node='node-%s' % (i + 1), instance_name=NAME_FMT % (i + 1)) def test_no_instance_passthrough_404(self): def fake_compute_get(*args, **kwargs): raise exception.InstanceNotFound(instance_id='fake') self.stubs.Set(compute.api.API, 'get', fake_compute_get) url = self.fake_url + '/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115' res = self._make_request(url) self.assertEqual(res.status_int, 404) class ExtendedServerAttributesTestV2(ExtendedServerAttributesTestV21): def setUp(self): super(ExtendedServerAttributesTestV2, self).setUp() self.flags( osapi_compute_extension=[ 'nova.api.openstack.compute.contrib.select_extensions'], osapi_compute_ext_list=['Extended_server_attributes']) def _make_request(self, url): req = webob.Request.blank(url) req.headers['Accept'] = self.content_type res = req.get_response(fakes.wsgi_app(init_only=('servers',))) return res class ExtendedServerAttributesTestV23(ExtendedServerAttributesTestV21): wsgi_api_version = '2.3' def assertServerAttributes(self, server, host, node, instance_name, reservation_id, launch_index, kernel_id, ramdisk_id, hostname, root_device_name, user_data): super(ExtendedServerAttributesTestV23, self).assertServerAttributes( server, host, node, instance_name) self.assertEqual(server.get('%sreservation_id' % self.prefix), reservation_id) self.assertEqual(server.get('%slaunch_index' % self.prefix), launch_index) self.assertEqual(server.get('%skernel_id' % self.prefix), kernel_id) self.assertEqual(server.get('%sramdisk_id' % self.prefix), ramdisk_id) self.assertEqual(server.get('%shostname' % self.prefix), hostname) self.assertEqual(server.get('%sroot_device_name' % self.prefix), root_device_name) self.assertEqual(server.get('%suser_data' % self.prefix), user_data) def test_show(self): url = self.fake_url + '/servers/%s' % UUID3 res = self._make_request(url) self.assertEqual(res.status_int, 200) self.assertServerAttributes(self._get_server(res.body), host='host-fake', node='node-fake', instance_name=NAME_FMT % 1, reservation_id="r-1", launch_index=0, kernel_id=UUID4, ramdisk_id=UUID5, hostname="hostname-1", root_device_name="/dev/vda", user_data="userdata") def test_detail(self): url = self.fake_url + '/servers/detail' res = self._make_request(url) self.assertEqual(res.status_int, 200) for i, server in enumerate(self._get_servers(res.body)): self.assertServerAttributes(server, host='host-%s' % (i + 1), node='node-%s' % (i + 1), instance_name=NAME_FMT % (i + 1), reservation_id="r-%s" % (i + 1), launch_index=i, kernel_id=UUID4, ramdisk_id=UUID5, hostname="hostname-%s" % (i + 1), root_device_name="/dev/vda", user_data="userdata")
apache-2.0
[ 3, 1898, 7760, 14260, 2752, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 11258, 63, 888, 492, 4810, 199, 504, 11258, 63, 12161, 492, 18705, 199, 646, 14568, 199, 199, 504, 5913, 14, 1246, 14, 8512, 492, 12464, 465, 747, 63, 6508, 199, 504, 5913, 492, 4526, 199, 504, 5913, 492, 1592, 199, 504, 5913, 492, 1919, 199, 504, 5913, 492, 2251, 199, 504, 5913, 492, 511, 199, 504, 5913, 14, 2219, 14, 3248, 14, 1246, 14, 8512, 492, 14063, 421, 199, 2339, 63, 22831, 275, 4810, 14, 3103, 14, 842, 63, 354, 63, 1160, 199, 8757, 17, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 20625, 614, 7, 199, 8757, 18, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 20625, 996, 7, 199, 8757, 19, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 3607, 16861, 7, 199, 8757, 20, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 20625, 966, 7, 199, 8757, 21, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 3607, 15646, 7, 421, 199, 318, 4026, 63, 3357, 63, 362, 2031, 589, 12, 1011, 958, 304, 272, 372, 14063, 14, 5811, 63, 842, 63, 1113, 8, 267, 488, 12, 413, 12, 5377, 29, 8757, 19, 12, 1591, 628, 1102, 13, 3183, 401, 267, 1031, 628, 932, 13, 3183, 401, 267, 25476, 63, 344, 628, 82, 13, 17, 401, 10623, 63, 1080, 29, 16, 12, 267, 5114, 63, 344, 29, 8757, 20, 12, 21394, 4032, 63, 344, 29, 8757, 21, 12, 267, 2929, 63, 354, 628, 4269, 13, 17, 401, 267, 1738, 63, 1782, 63, 354, 9555, 2374, 15, 86, 983, 401, 267, 922, 63, 576, 628, 751, 576, 531, 421, 199, 318, 4026, 63, 3357, 63, 362, 63, 452, 2031, 589, 12, 1011, 958, 304, 272, 2727, 63, 513, 275, 359, 267, 14063, 14, 5811, 63, 842, 63, 1113, 8, 288, 488, 12, 413, 12, 5377, 29, 8757, 17, 12, 1591, 628, 1102, 13, 17, 401, 1031, 628, 932, 13, 17, 401, 288, 25476, 63, 344, 628, 82, 13, 17, 401, 10623, 63, 1080, 29, 16, 12, 288, 5114, 63, 344, 29, 8757, 20, 12, 21394, 4032, 63, 344, 29, 8757, 21, 12, 288, 2929, 63, 354, 628, 4269, 13, 17, 401, 288, 1738, 63, 1782, 63, 354, 9555, 2374, 15, 86, 983, 401, 288, 922, 63, 576, 628, 751, 576, 1288, 267, 14063, 14, 5811, 63, 842, 63, 1113, 8, 288, 488, 12, 499, 12, 5377, 29, 8757, 18, 12, 1591, 628, 1102, 13, 18, 401, 1031, 628, 932, 13, 18, 401, 288, 25476, 63, 344, 628, 82, 13, 18, 401, 10623, 63, 1080, 29, 17, 12, 288, 5114, 63, 344, 29, 8757, 20, 12, 21394, 4032, 63, 344, 29, 8757, 21, 12, 288, 2929, 63, 354, 628, 4269, 13, 18, 401, 288, 1738, 63, 1782, 63, 354, 9555, 2374, 15, 86, 983, 401, 288, 922, 63, 576, 628, 751, 576, 1288, 272, 1622, 272, 372, 2251, 14, 3244, 1296, 8, 1462, 29, 3615, 63, 513, 9, 421, 199, 533, 13706, 3120, 5379, 774, 54, 2025, 8, 396, 14, 1746, 304, 272, 1564, 63, 466, 275, 283, 3578, 15, 1001, 7, 272, 2403, 275, 283, 3100, 13, 2472, 13, 31546, 13, 5280, 4881, 272, 4026, 63, 633, 275, 1994, 86, 18, 15, 3183, 7, 272, 12464, 63, 1246, 63, 1023, 275, 747, 63, 6508, 14, 3472, 63, 3735, 63, 4612, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 14107, 3120, 5379, 774, 54, 2025, 12, 291, 680, 5996, 342, 267, 14063, 14, 5811, 63, 548, 63, 13100, 63, 1246, 8, 277, 14, 8957, 9, 267, 291, 14, 8957, 14, 1084, 8, 3357, 14, 1246, 14, 3735, 12, 283, 362, 297, 4026, 63, 3357, 63, 362, 9, 267, 291, 14, 8957, 14, 1084, 8, 3357, 14, 1246, 14, 3735, 12, 283, 362, 63, 452, 297, 4026, 63, 3357, 63, 362, 63, 452, 9, 267, 291, 14, 8957, 14, 1084, 8, 697, 12, 283, 842, 63, 362, 63, 991, 63, 2580, 297, 4026, 63, 3357, 63, 362, 9, 339, 347, 485, 1875, 63, 1069, 8, 277, 12, 1166, 304, 267, 2648, 275, 14063, 14, 21053, 14, 2500, 8, 633, 9, 267, 2648, 14, 2139, 459, 8422, 418, 275, 291, 14, 1317, 63, 466, 267, 2648, 14, 2139, 275, 469, 736, 63, 6508, 14, 3735, 63, 4612, 63, 6780, 63, 7311, 26, 2432, 291, 14, 6508, 63, 1246, 63, 1023, 93, 267, 522, 275, 2648, 14, 362, 63, 1310, 8, 288, 14063, 14, 6508, 63, 571, 63, 86, 2025, 8, 826, 63, 2118, 7782, 5871, 297, 5101, 283, 736, 13, 10525, 13, 1000, 13, 2987, 7058, 267, 372, 522, 339, 347, 485, 362, 63, 1000, 8, 277, 12, 2396, 304, 267, 372, 18705, 14, 3640, 8, 2030, 680, 362, 360, 1000, 358, 339, 347, 485, 362, 63, 5871, 8, 277, 12, 2396, 304, 267, 372, 18705, 14, 3640, 8, 2030, 680, 362, 360, 5871, 358, 339, 347, 702, 3120, 5379, 8, 277, 12, 1654, 12, 1591, 12, 1031, 12, 1256, 63, 354, 304, 267, 291, 14, 629, 8, 1000, 14, 362, 3508, 83, 1102, 7, 450, 291, 14, 1861, 395, 1591, 9, 267, 291, 14, 629, 8, 1000, 14, 362, 3508, 83, 842, 63, 354, 7, 450, 291, 14, 1861, 395, 586, 1256, 63, 354, 9, 267, 291, 14, 629, 8, 1000 ]
[ 1898, 7760, 14260, 2752, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 11258, 63, 888, 492, 4810, 199, 504, 11258, 63, 12161, 492, 18705, 199, 646, 14568, 199, 199, 504, 5913, 14, 1246, 14, 8512, 492, 12464, 465, 747, 63, 6508, 199, 504, 5913, 492, 4526, 199, 504, 5913, 492, 1592, 199, 504, 5913, 492, 1919, 199, 504, 5913, 492, 2251, 199, 504, 5913, 492, 511, 199, 504, 5913, 14, 2219, 14, 3248, 14, 1246, 14, 8512, 492, 14063, 421, 199, 2339, 63, 22831, 275, 4810, 14, 3103, 14, 842, 63, 354, 63, 1160, 199, 8757, 17, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 20625, 614, 7, 199, 8757, 18, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 20625, 996, 7, 199, 8757, 19, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 3607, 16861, 7, 199, 8757, 20, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 20625, 966, 7, 199, 8757, 21, 275, 283, 3607, 13, 993, 13, 993, 13, 993, 13, 3607, 15646, 7, 421, 199, 318, 4026, 63, 3357, 63, 362, 2031, 589, 12, 1011, 958, 304, 272, 372, 14063, 14, 5811, 63, 842, 63, 1113, 8, 267, 488, 12, 413, 12, 5377, 29, 8757, 19, 12, 1591, 628, 1102, 13, 3183, 401, 267, 1031, 628, 932, 13, 3183, 401, 267, 25476, 63, 344, 628, 82, 13, 17, 401, 10623, 63, 1080, 29, 16, 12, 267, 5114, 63, 344, 29, 8757, 20, 12, 21394, 4032, 63, 344, 29, 8757, 21, 12, 267, 2929, 63, 354, 628, 4269, 13, 17, 401, 267, 1738, 63, 1782, 63, 354, 9555, 2374, 15, 86, 983, 401, 267, 922, 63, 576, 628, 751, 576, 531, 421, 199, 318, 4026, 63, 3357, 63, 362, 63, 452, 2031, 589, 12, 1011, 958, 304, 272, 2727, 63, 513, 275, 359, 267, 14063, 14, 5811, 63, 842, 63, 1113, 8, 288, 488, 12, 413, 12, 5377, 29, 8757, 17, 12, 1591, 628, 1102, 13, 17, 401, 1031, 628, 932, 13, 17, 401, 288, 25476, 63, 344, 628, 82, 13, 17, 401, 10623, 63, 1080, 29, 16, 12, 288, 5114, 63, 344, 29, 8757, 20, 12, 21394, 4032, 63, 344, 29, 8757, 21, 12, 288, 2929, 63, 354, 628, 4269, 13, 17, 401, 288, 1738, 63, 1782, 63, 354, 9555, 2374, 15, 86, 983, 401, 288, 922, 63, 576, 628, 751, 576, 1288, 267, 14063, 14, 5811, 63, 842, 63, 1113, 8, 288, 488, 12, 499, 12, 5377, 29, 8757, 18, 12, 1591, 628, 1102, 13, 18, 401, 1031, 628, 932, 13, 18, 401, 288, 25476, 63, 344, 628, 82, 13, 18, 401, 10623, 63, 1080, 29, 17, 12, 288, 5114, 63, 344, 29, 8757, 20, 12, 21394, 4032, 63, 344, 29, 8757, 21, 12, 288, 2929, 63, 354, 628, 4269, 13, 18, 401, 288, 1738, 63, 1782, 63, 354, 9555, 2374, 15, 86, 983, 401, 288, 922, 63, 576, 628, 751, 576, 1288, 272, 1622, 272, 372, 2251, 14, 3244, 1296, 8, 1462, 29, 3615, 63, 513, 9, 421, 199, 533, 13706, 3120, 5379, 774, 54, 2025, 8, 396, 14, 1746, 304, 272, 1564, 63, 466, 275, 283, 3578, 15, 1001, 7, 272, 2403, 275, 283, 3100, 13, 2472, 13, 31546, 13, 5280, 4881, 272, 4026, 63, 633, 275, 1994, 86, 18, 15, 3183, 7, 272, 12464, 63, 1246, 63, 1023, 275, 747, 63, 6508, 14, 3472, 63, 3735, 63, 4612, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 14107, 3120, 5379, 774, 54, 2025, 12, 291, 680, 5996, 342, 267, 14063, 14, 5811, 63, 548, 63, 13100, 63, 1246, 8, 277, 14, 8957, 9, 267, 291, 14, 8957, 14, 1084, 8, 3357, 14, 1246, 14, 3735, 12, 283, 362, 297, 4026, 63, 3357, 63, 362, 9, 267, 291, 14, 8957, 14, 1084, 8, 3357, 14, 1246, 14, 3735, 12, 283, 362, 63, 452, 297, 4026, 63, 3357, 63, 362, 63, 452, 9, 267, 291, 14, 8957, 14, 1084, 8, 697, 12, 283, 842, 63, 362, 63, 991, 63, 2580, 297, 4026, 63, 3357, 63, 362, 9, 339, 347, 485, 1875, 63, 1069, 8, 277, 12, 1166, 304, 267, 2648, 275, 14063, 14, 21053, 14, 2500, 8, 633, 9, 267, 2648, 14, 2139, 459, 8422, 418, 275, 291, 14, 1317, 63, 466, 267, 2648, 14, 2139, 275, 469, 736, 63, 6508, 14, 3735, 63, 4612, 63, 6780, 63, 7311, 26, 2432, 291, 14, 6508, 63, 1246, 63, 1023, 93, 267, 522, 275, 2648, 14, 362, 63, 1310, 8, 288, 14063, 14, 6508, 63, 571, 63, 86, 2025, 8, 826, 63, 2118, 7782, 5871, 297, 5101, 283, 736, 13, 10525, 13, 1000, 13, 2987, 7058, 267, 372, 522, 339, 347, 485, 362, 63, 1000, 8, 277, 12, 2396, 304, 267, 372, 18705, 14, 3640, 8, 2030, 680, 362, 360, 1000, 358, 339, 347, 485, 362, 63, 5871, 8, 277, 12, 2396, 304, 267, 372, 18705, 14, 3640, 8, 2030, 680, 362, 360, 5871, 358, 339, 347, 702, 3120, 5379, 8, 277, 12, 1654, 12, 1591, 12, 1031, 12, 1256, 63, 354, 304, 267, 291, 14, 629, 8, 1000, 14, 362, 3508, 83, 1102, 7, 450, 291, 14, 1861, 395, 1591, 9, 267, 291, 14, 629, 8, 1000, 14, 362, 3508, 83, 842, 63, 354, 7, 450, 291, 14, 1861, 395, 586, 1256, 63, 354, 9, 267, 291, 14, 629, 8, 1000, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
simon-pepin/scikit-learn
sklearn/ensemble/tests/test_base.py
284
1328
""" Testing for the base module (sklearn.ensemble.base). """ # Authors: Gilles Louppe # License: BSD 3 clause from numpy.testing import assert_equal from nose.tools import assert_true from sklearn.utils.testing import assert_raise_message from sklearn.datasets import load_iris from sklearn.ensemble import BaggingClassifier from sklearn.linear_model import Perceptron def test_base(): # Check BaseEnsemble methods. ensemble = BaggingClassifier(base_estimator=Perceptron(), n_estimators=3) iris = load_iris() ensemble.fit(iris.data, iris.target) ensemble.estimators_ = [] # empty the list and create estimators manually ensemble._make_estimator() ensemble._make_estimator() ensemble._make_estimator() ensemble._make_estimator(append=False) assert_equal(3, len(ensemble)) assert_equal(3, len(ensemble.estimators_)) assert_true(isinstance(ensemble[0], Perceptron)) def test_base_zero_n_estimators(): # Check that instantiating a BaseEnsemble with n_estimators<=0 raises # a ValueError. ensemble = BaggingClassifier(base_estimator=Perceptron(), n_estimators=0) iris = load_iris() assert_raise_message(ValueError, "n_estimators must be greater than zero, got 0.", ensemble.fit, iris.data, iris.target)
bsd-3-clause
[ 624, 199, 9029, 367, 314, 1300, 859, 334, 27993, 14, 15628, 14, 1095, 680, 199, 624, 199, 199, 3, 6642, 26, 598, 382, 2978, 3835, 384, 321, 199, 3, 844, 26, 6289, 650, 8502, 199, 199, 504, 2680, 14, 4776, 492, 702, 63, 1452, 199, 504, 11354, 14, 2537, 492, 702, 63, 2052, 199, 199, 504, 6357, 14, 1208, 14, 4776, 492, 702, 63, 3730, 63, 1188, 199, 504, 6357, 14, 12281, 492, 2248, 63, 11885, 199, 504, 6357, 14, 15628, 492, 699, 643, 1540, 8508, 199, 504, 6357, 14, 6676, 63, 1238, 492, 3492, 301, 4695, 265, 421, 199, 318, 511, 63, 1095, 837, 272, 327, 2670, 3523, 1327, 8834, 3102, 14, 272, 19965, 275, 699, 643, 1540, 8508, 8, 1095, 63, 8627, 29, 2623, 301, 4695, 265, 1062, 302, 63, 10646, 29, 19, 9, 339, 12192, 275, 2248, 63, 11885, 342, 272, 19965, 14, 3269, 8, 11885, 14, 576, 12, 12192, 14, 1375, 9, 272, 19965, 14, 10646, 63, 275, 942, 221, 327, 2701, 314, 769, 436, 1218, 23155, 10250, 339, 19965, 423, 1875, 63, 8627, 342, 272, 19965, 423, 1875, 63, 8627, 342, 272, 19965, 423, 1875, 63, 8627, 342, 272, 19965, 423, 1875, 63, 8627, 8, 740, 29, 797, 9, 339, 702, 63, 1452, 8, 19, 12, 822, 8, 15628, 430, 272, 702, 63, 1452, 8, 19, 12, 822, 8, 15628, 14, 10646, 13309, 339, 702, 63, 2052, 8, 6074, 8, 15628, 59, 16, 467, 3492, 301, 4695, 265, 430, 421, 199, 318, 511, 63, 1095, 63, 4262, 63, 78, 63, 10646, 837, 272, 327, 2670, 626, 9034, 1958, 282, 3523, 1327, 8834, 543, 302, 63, 10646, 12932, 16, 6534, 272, 327, 282, 1722, 14, 272, 19965, 275, 699, 643, 1540, 8508, 8, 1095, 63, 8627, 29, 2623, 301, 4695, 265, 1062, 302, 63, 10646, 29, 16, 9, 272, 12192, 275, 2248, 63, 11885, 342, 272, 702, 63, 3730, 63, 1188, 8, 3393, 12, 586, 298, 78, 63, 10646, 1471, 506, 8932, 2419, 4697, 12, 4788, 378, 4765, 586, 19965, 14, 3269, 12, 12192, 14, 576, 12, 12192, 14, 1375, 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 ]
[ 199, 9029, 367, 314, 1300, 859, 334, 27993, 14, 15628, 14, 1095, 680, 199, 624, 199, 199, 3, 6642, 26, 598, 382, 2978, 3835, 384, 321, 199, 3, 844, 26, 6289, 650, 8502, 199, 199, 504, 2680, 14, 4776, 492, 702, 63, 1452, 199, 504, 11354, 14, 2537, 492, 702, 63, 2052, 199, 199, 504, 6357, 14, 1208, 14, 4776, 492, 702, 63, 3730, 63, 1188, 199, 504, 6357, 14, 12281, 492, 2248, 63, 11885, 199, 504, 6357, 14, 15628, 492, 699, 643, 1540, 8508, 199, 504, 6357, 14, 6676, 63, 1238, 492, 3492, 301, 4695, 265, 421, 199, 318, 511, 63, 1095, 837, 272, 327, 2670, 3523, 1327, 8834, 3102, 14, 272, 19965, 275, 699, 643, 1540, 8508, 8, 1095, 63, 8627, 29, 2623, 301, 4695, 265, 1062, 302, 63, 10646, 29, 19, 9, 339, 12192, 275, 2248, 63, 11885, 342, 272, 19965, 14, 3269, 8, 11885, 14, 576, 12, 12192, 14, 1375, 9, 272, 19965, 14, 10646, 63, 275, 942, 221, 327, 2701, 314, 769, 436, 1218, 23155, 10250, 339, 19965, 423, 1875, 63, 8627, 342, 272, 19965, 423, 1875, 63, 8627, 342, 272, 19965, 423, 1875, 63, 8627, 342, 272, 19965, 423, 1875, 63, 8627, 8, 740, 29, 797, 9, 339, 702, 63, 1452, 8, 19, 12, 822, 8, 15628, 430, 272, 702, 63, 1452, 8, 19, 12, 822, 8, 15628, 14, 10646, 13309, 339, 702, 63, 2052, 8, 6074, 8, 15628, 59, 16, 467, 3492, 301, 4695, 265, 430, 421, 199, 318, 511, 63, 1095, 63, 4262, 63, 78, 63, 10646, 837, 272, 327, 2670, 626, 9034, 1958, 282, 3523, 1327, 8834, 543, 302, 63, 10646, 12932, 16, 6534, 272, 327, 282, 1722, 14, 272, 19965, 275, 699, 643, 1540, 8508, 8, 1095, 63, 8627, 29, 2623, 301, 4695, 265, 1062, 302, 63, 10646, 29, 16, 9, 272, 12192, 275, 2248, 63, 11885, 342, 272, 702, 63, 3730, 63, 1188, 8, 3393, 12, 586, 298, 78, 63, 10646, 1471, 506, 8932, 2419, 4697, 12, 4788, 378, 4765, 586, 19965, 14, 3269, 12, 12192, 14, 576, 12, 12192, 14, 1375, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Phonebooth/depot_tools
third_party/boto/file/connection.py
111
1480
# Copyright 2010 Google Inc. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, dis- # tribute, sublicense, and/or sell copies of the Software, and to permit # persons to whom the Software is furnished to do so, subject to the fol- # lowing conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # File representation of connection, for use with "file://" URIs. from bucket import Bucket class FileConnection(object): def __init__(self, file_storage_uri): # FileConnections are per-file storage URI. self.file_storage_uri = file_storage_uri def get_bucket(self, bucket_name, validate=True, headers=None): return Bucket(bucket_name, self.file_storage_uri.object_name)
bsd-3-clause
[ 3, 1898, 7129, 4475, 3277, 14, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 199, 3, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 2153, 13, 199, 3, 28420, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 199, 3, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 314, 1699, 13, 199, 3, 28486, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 199, 3, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 28471, 13, 199, 3, 28463, 12, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 199, 3, 7000, 2334, 17632, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 199, 3, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 199, 3, 3814, 6025, 402, 1950, 12, 367, 675, 543, 298, 493, 30443, 30143, 14, 199, 199, 504, 5315, 492, 31479, 199, 199, 533, 3814, 3225, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 570, 63, 3494, 63, 2302, 304, 267, 327, 3814, 22122, 787, 1126, 13, 493, 4887, 9022, 14, 267, 291, 14, 493, 63, 3494, 63, 2302, 275, 570, 63, 3494, 63, 2302, 339, 347, 664, 63, 4623, 8, 277, 12, 5315, 63, 354, 12, 4107, 29, 549, 12, 2323, 29, 403, 304, 267, 372, 31479, 8, 4623, 63, 354, 12, 291, 14, 493, 63, 3494, 63, 2302, 14, 785, 63, 354, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 7129, 4475, 3277, 14, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 199, 3, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 2153, 13, 199, 3, 28420, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 199, 3, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 314, 1699, 13, 199, 3, 28486, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 199, 3, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 28471, 13, 199, 3, 28463, 12, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 199, 3, 7000, 2334, 17632, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 199, 3, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 199, 3, 3814, 6025, 402, 1950, 12, 367, 675, 543, 298, 493, 30443, 30143, 14, 199, 199, 504, 5315, 492, 31479, 199, 199, 533, 3814, 3225, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 570, 63, 3494, 63, 2302, 304, 267, 327, 3814, 22122, 787, 1126, 13, 493, 4887, 9022, 14, 267, 291, 14, 493, 63, 3494, 63, 2302, 275, 570, 63, 3494, 63, 2302, 339, 347, 664, 63, 4623, 8, 277, 12, 5315, 63, 354, 12, 4107, 29, 549, 12, 2323, 29, 403, 304, 267, 372, 31479, 8, 4623, 63, 354, 12, 291, 14, 493, 63, 3494, 63, 2302, 14, 785, 63, 354, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Gitlab11/odoo
openerp/addons/test_limits/models.py
435
1034
# -*- coding: utf-8 -*- import time import openerp class m(openerp.osv.osv.Model): """ This model exposes a few methods that will consume between 'almost no resource' and 'a lot of resource'. """ _name = 'test.limits.model' def consume_nothing(self, cr, uid, context=None): return True def consume_memory(self, cr, uid, size, context=None): l = [0] * size return True def leak_memory(self, cr, uid, size, context=None): if not hasattr(self, 'l'): self.l = [] self.l.append([0] * size) return True def consume_time(self, cr, uid, seconds, context=None): time.sleep(seconds) return True def consume_cpu_time(self, cr, uid, seconds, context=None): t0 = time.clock() t1 = time.clock() while t1 - t0 < seconds: for i in xrange(10000000): x = i * i t1 = time.clock() return True # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 900, 199, 199, 646, 5166, 199, 199, 533, 333, 8, 11267, 14, 4795, 14, 4795, 14, 1685, 304, 272, 408, 961, 1402, 444, 10553, 282, 9284, 3102, 626, 911, 9451, 3382, 283, 4398, 949, 267, 2073, 7, 436, 283, 65, 13918, 402, 2073, 1370, 272, 408, 272, 485, 354, 275, 283, 396, 14, 9368, 14, 1238, 7, 339, 347, 9451, 63, 16323, 8, 277, 12, 2467, 12, 1747, 12, 1067, 29, 403, 304, 267, 372, 715, 339, 347, 9451, 63, 4844, 8, 277, 12, 2467, 12, 1747, 12, 1568, 12, 1067, 29, 403, 304, 267, 634, 275, 359, 16, 61, 627, 1568, 267, 372, 715, 339, 347, 25831, 63, 4844, 8, 277, 12, 2467, 12, 1747, 12, 1568, 12, 1067, 29, 403, 304, 267, 340, 440, 2688, 8, 277, 12, 283, 76, 735, 288, 291, 14, 76, 275, 942, 267, 291, 14, 76, 14, 740, 779, 16, 61, 627, 1568, 9, 267, 372, 715, 339, 347, 9451, 63, 521, 8, 277, 12, 2467, 12, 1747, 12, 4696, 12, 1067, 29, 403, 304, 267, 900, 14, 4532, 8, 4515, 9, 267, 372, 715, 339, 347, 9451, 63, 3541, 63, 521, 8, 277, 12, 2467, 12, 1747, 12, 4696, 12, 1067, 29, 403, 304, 267, 307, 16, 275, 900, 14, 9597, 342, 267, 307, 17, 275, 900, 14, 9597, 342, 267, 1830, 307, 17, 446, 307, 16, 665, 4696, 26, 288, 367, 284, 315, 4945, 8, 17, 9084, 304, 355, 671, 275, 284, 627, 284, 288, 307, 17, 275, 900, 14, 9597, 342, 267, 372, 715, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 900, 199, 199, 646, 5166, 199, 199, 533, 333, 8, 11267, 14, 4795, 14, 4795, 14, 1685, 304, 272, 408, 961, 1402, 444, 10553, 282, 9284, 3102, 626, 911, 9451, 3382, 283, 4398, 949, 267, 2073, 7, 436, 283, 65, 13918, 402, 2073, 1370, 272, 408, 272, 485, 354, 275, 283, 396, 14, 9368, 14, 1238, 7, 339, 347, 9451, 63, 16323, 8, 277, 12, 2467, 12, 1747, 12, 1067, 29, 403, 304, 267, 372, 715, 339, 347, 9451, 63, 4844, 8, 277, 12, 2467, 12, 1747, 12, 1568, 12, 1067, 29, 403, 304, 267, 634, 275, 359, 16, 61, 627, 1568, 267, 372, 715, 339, 347, 25831, 63, 4844, 8, 277, 12, 2467, 12, 1747, 12, 1568, 12, 1067, 29, 403, 304, 267, 340, 440, 2688, 8, 277, 12, 283, 76, 735, 288, 291, 14, 76, 275, 942, 267, 291, 14, 76, 14, 740, 779, 16, 61, 627, 1568, 9, 267, 372, 715, 339, 347, 9451, 63, 521, 8, 277, 12, 2467, 12, 1747, 12, 4696, 12, 1067, 29, 403, 304, 267, 900, 14, 4532, 8, 4515, 9, 267, 372, 715, 339, 347, 9451, 63, 3541, 63, 521, 8, 277, 12, 2467, 12, 1747, 12, 4696, 12, 1067, 29, 403, 304, 267, 307, 16, 275, 900, 14, 9597, 342, 267, 307, 17, 275, 900, 14, 9597, 342, 267, 1830, 307, 17, 446, 307, 16, 665, 4696, 26, 288, 367, 284, 315, 4945, 8, 17, 9084, 304, 355, 671, 275, 284, 627, 284, 288, 307, 17, 275, 900, 14, 9597, 342, 267, 372, 715, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
wyc/django
tests/annotations/models.py
238
2901
# coding: utf-8 from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Author(models.Model): name = models.CharField(max_length=100) age = models.IntegerField() friends = models.ManyToManyField('self', blank=True) def __str__(self): return self.name @python_2_unicode_compatible class Publisher(models.Model): name = models.CharField(max_length=255) num_awards = models.IntegerField() def __str__(self): return self.name @python_2_unicode_compatible class Book(models.Model): isbn = models.CharField(max_length=9) name = models.CharField(max_length=255) pages = models.IntegerField() rating = models.FloatField() price = models.DecimalField(decimal_places=2, max_digits=6) authors = models.ManyToManyField(Author) contact = models.ForeignKey(Author, models.CASCADE, related_name='book_contact_set') publisher = models.ForeignKey(Publisher, models.CASCADE) pubdate = models.DateField() def __str__(self): return self.name @python_2_unicode_compatible class Store(models.Model): name = models.CharField(max_length=255) books = models.ManyToManyField(Book) original_opening = models.DateTimeField() friday_night_closing = models.TimeField() def __str__(self): return self.name @python_2_unicode_compatible class DepartmentStore(Store): chain = models.CharField(max_length=255) def __str__(self): return '%s - %s ' % (self.chain, self.name) @python_2_unicode_compatible class Employee(models.Model): # The order of these fields matter, do not change. Certain backends # rely on field ordering to perform database conversions, and this # model helps to test that. first_name = models.CharField(max_length=20) manager = models.BooleanField(default=False) last_name = models.CharField(max_length=20) store = models.ForeignKey(Store, models.CASCADE) age = models.IntegerField() salary = models.DecimalField(max_digits=8, decimal_places=2) def __str__(self): return '%s %s' % (self.first_name, self.last_name) @python_2_unicode_compatible class Company(models.Model): name = models.CharField(max_length=200) motto = models.CharField(max_length=200, null=True, blank=True) ticker_name = models.CharField(max_length=10, null=True, blank=True) description = models.CharField(max_length=200, null=True, blank=True) def __str__(self): return ('Company(name=%s, motto=%s, ticker_name=%s, description=%s)' % (self.name, self.motto, self.ticker_name, self.description) ) @python_2_unicode_compatible class Ticket(models.Model): active_at = models.DateTimeField() duration = models.DurationField() def __str__(self): return '{} - {}'.format(self.active_at, self.duration)
bsd-3-clause
[ 3, 2803, 26, 2774, 13, 24, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 1208, 14, 2991, 492, 2366, 63, 18, 63, 2975, 63, 6490, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 6529, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 272, 11437, 275, 1709, 14, 3901, 342, 272, 26157, 275, 1709, 14, 7624, 360, 277, 297, 4596, 29, 549, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 19952, 281, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 2299, 9, 272, 1967, 63, 31255, 275, 1709, 14, 3901, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 8944, 8, 992, 14, 1685, 304, 272, 365, 10472, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 25, 9, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 2299, 9, 272, 6497, 275, 1709, 14, 3901, 342, 272, 18360, 275, 1709, 14, 13019, 342, 272, 8033, 275, 1709, 14, 15975, 8, 6355, 63, 10696, 29, 18, 12, 1390, 63, 7022, 29, 22, 9, 272, 11462, 275, 1709, 14, 7624, 8, 5949, 9, 272, 8966, 275, 1709, 14, 3190, 8, 5949, 12, 1709, 14, 10855, 12, 4048, 63, 354, 534, 2706, 63, 7811, 63, 409, 358, 272, 19704, 275, 1709, 14, 3190, 8, 27341, 12, 1709, 14, 10855, 9, 272, 7974, 602, 275, 1709, 14, 14071, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 13874, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 2299, 9, 272, 19040, 275, 1709, 14, 7624, 8, 8696, 9, 272, 3379, 63, 21849, 275, 1709, 14, 4626, 342, 272, 289, 322, 2977, 63, 14873, 63, 11707, 275, 1709, 14, 27115, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 1487, 12493, 5502, 8, 5502, 304, 272, 6036, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 2299, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 446, 450, 83, 283, 450, 334, 277, 14, 4429, 12, 291, 14, 354, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 24089, 8, 992, 14, 1685, 304, 272, 327, 710, 1865, 402, 3520, 1504, 17247, 12, 886, 440, 1570, 14, 11002, 877, 14745, 272, 327, 19687, 641, 901, 7794, 370, 5147, 3050, 24796, 12, 436, 642, 272, 327, 1402, 22577, 370, 511, 626, 14, 272, 1642, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1165, 9, 272, 5256, 275, 1709, 14, 5036, 8, 885, 29, 797, 9, 272, 2061, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1165, 9, 272, 3877, 275, 1709, 14, 3190, 8, 5502, 12, 1709, 14, 10855, 9, 272, 11437, 275, 1709, 14, 3901, 342, 272, 18641, 695, 275, 1709, 14, 15975, 8, 988, 63, 7022, 29, 24, 12, 6107, 63, 10696, 29, 18, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 450, 83, 7, 450, 334, 277, 14, 2246, 63, 354, 12, 291, 14, 2019, 63, 354, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 15878, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 333, 357, 475, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 12, 2973, 29, 549, 12, 4596, 29, 549, 9, 272, 32721, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 2973, 29, 549, 12, 4596, 29, 549, 9, 272, 1369, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 12, 2973, 29, 549, 12, 4596, 29, 549, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 661, 16063, 8, 354, 2458, 83, 12, 333, 357, 475, 2458, 83, 12, 32721, 63, 354, 2458, 83, 12, 1369, 2458, 83, 3171, 288, 450, 334, 277, 14, 354, 12, 291, 14, 30034, 475, 12, 291, 14, 28572, 63, 354, 12, 291, 14, 1802, 9, 267, 776, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 21932, 8, 992, 14, 1685, 304, 272, 4702, 63, 292, 275, 1709, 14, 4626, 342, 272, 7373, 275, 1709, 14, 13283, 792, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 9005, 446, 9499, 908, 8, 277, 14, 2682, 63, 292, 12, 291, 14, 5553, 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 ]
[ 2803, 26, 2774, 13, 24, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 1208, 14, 2991, 492, 2366, 63, 18, 63, 2975, 63, 6490, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 6529, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 272, 11437, 275, 1709, 14, 3901, 342, 272, 26157, 275, 1709, 14, 7624, 360, 277, 297, 4596, 29, 549, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 19952, 281, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 2299, 9, 272, 1967, 63, 31255, 275, 1709, 14, 3901, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 8944, 8, 992, 14, 1685, 304, 272, 365, 10472, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 25, 9, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 2299, 9, 272, 6497, 275, 1709, 14, 3901, 342, 272, 18360, 275, 1709, 14, 13019, 342, 272, 8033, 275, 1709, 14, 15975, 8, 6355, 63, 10696, 29, 18, 12, 1390, 63, 7022, 29, 22, 9, 272, 11462, 275, 1709, 14, 7624, 8, 5949, 9, 272, 8966, 275, 1709, 14, 3190, 8, 5949, 12, 1709, 14, 10855, 12, 4048, 63, 354, 534, 2706, 63, 7811, 63, 409, 358, 272, 19704, 275, 1709, 14, 3190, 8, 27341, 12, 1709, 14, 10855, 9, 272, 7974, 602, 275, 1709, 14, 14071, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 13874, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 2299, 9, 272, 19040, 275, 1709, 14, 7624, 8, 8696, 9, 272, 3379, 63, 21849, 275, 1709, 14, 4626, 342, 272, 289, 322, 2977, 63, 14873, 63, 11707, 275, 1709, 14, 27115, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 1487, 12493, 5502, 8, 5502, 304, 272, 6036, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 2299, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 446, 450, 83, 283, 450, 334, 277, 14, 4429, 12, 291, 14, 354, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 24089, 8, 992, 14, 1685, 304, 272, 327, 710, 1865, 402, 3520, 1504, 17247, 12, 886, 440, 1570, 14, 11002, 877, 14745, 272, 327, 19687, 641, 901, 7794, 370, 5147, 3050, 24796, 12, 436, 642, 272, 327, 1402, 22577, 370, 511, 626, 14, 272, 1642, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1165, 9, 272, 5256, 275, 1709, 14, 5036, 8, 885, 29, 797, 9, 272, 2061, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1165, 9, 272, 3877, 275, 1709, 14, 3190, 8, 5502, 12, 1709, 14, 10855, 9, 272, 11437, 275, 1709, 14, 3901, 342, 272, 18641, 695, 275, 1709, 14, 15975, 8, 988, 63, 7022, 29, 24, 12, 6107, 63, 10696, 29, 18, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 450, 83, 7, 450, 334, 277, 14, 2246, 63, 354, 12, 291, 14, 2019, 63, 354, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 15878, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 9, 272, 333, 357, 475, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 12, 2973, 29, 549, 12, 4596, 29, 549, 9, 272, 32721, 63, 354, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 2973, 29, 549, 12, 4596, 29, 549, 9, 272, 1369, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1840, 12, 2973, 29, 549, 12, 4596, 29, 549, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 661, 16063, 8, 354, 2458, 83, 12, 333, 357, 475, 2458, 83, 12, 32721, 63, 354, 2458, 83, 12, 1369, 2458, 83, 3171, 288, 450, 334, 277, 14, 354, 12, 291, 14, 30034, 475, 12, 291, 14, 28572, 63, 354, 12, 291, 14, 1802, 9, 267, 776, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 21932, 8, 992, 14, 1685, 304, 272, 4702, 63, 292, 275, 1709, 14, 4626, 342, 272, 7373, 275, 1709, 14, 13283, 792, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 9005, 446, 9499, 908, 8, 277, 14, 2682, 63, 292, 12, 291, 14, 5553, 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, 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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2006 Michael Bayer mike_mp@zzzcomputing.com # # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php """provides a connection pool implementation, which optionally manages connections on a thread local basis. Also provides a DBAPI2 transparency layer so that pools can be managed automatically, based on module type and connect arguments, simply by calling regular DBAPI connect() methods.""" import Queue, weakref, string, cPickle try: import thread except: import dummythread as thread proxies = {} def manage(module, **params): """given a DBAPI2 module and pool management parameters, returns a proxy for the module that will automatically pool connections. Options are delivered to an underlying DBProxy object. Arguments: module : a DBAPI2 database module. Options: echo=False : if set to True, connections being pulled and retrieved from/to the pool will be logged to the standard output, as well as pool sizing information. use_threadlocal=True : if set to True, repeated calls to connect() within the same application thread will be guaranteed to return the same connection object, if one has already been retrieved from the pool and has not been returned yet. This allows code to retrieve a connection from the pool, and then while still holding on to that connection, to call other functions which also ask the pool for a connection of the same arguments; those functions will act upon the same connection that the calling method is using. poolclass=QueuePool : the default class used by the pool module to provide pooling. QueuePool uses the Python Queue.Queue class to maintain a list of available connections. pool_size=5 : used by QueuePool - the size of the pool to be maintained. This is the largest number of connections that will be kept persistently in the pool. Note that the pool begins with no connections; once this number of connections is requested, that number of connections will remain. max_overflow=10 : the maximum overflow size of the pool. When the number of checked-out connections reaches the size set in pool_size, additional connections will be returned up to this limit. When those additional connections are returned to the pool, they are disconnected and discarded. It follows then that the total number of simultaneous connections the pool will allow is pool_size + max_overflow, and the total number of "sleeping" connections the pool will allow is pool_size. max_overflow can be set to -1 to indicate no overflow limit; no limit will be placed on the total number of concurrent connections. """ try: return proxies[module] except KeyError: return proxies.setdefault(module, DBProxy(module, **params)) def clear_managers(): """removes all current DBAPI2 managers. all pools and connections are disposed.""" for manager in proxies.values(): manager.close() proxies.clear() class Pool(object): def __init__(self, echo = False, use_threadlocal = True): self._threadconns = weakref.WeakValueDictionary() self._use_threadlocal = use_threadlocal self._echo = echo def connect(self): if not self._use_threadlocal: return ConnectionFairy(self) try: agent = self._threadconns[thread.get_ident()] if not agent.alive: agent = ConnectionFairy(self) self._threadconns[thread.get_ident()] = agent return agent except KeyError: agent = ConnectionFairy(self) self._threadconns[thread.get_ident()] = agent return agent def get(self): raise NotImplementedError() def return_conn(self, conn, alive=True): raise NotImplementedError() def log(self, msg): print msg class ConnectionFairy(object): def __init__(self, pool): self.pool = pool try: self.connection = pool.get() except: self.connection = None raise self.alive = True def cursor(self): return CursorFairy(self, self.connection.cursor()) def __getattr__(self, key): return getattr(self.connection, key) def __del__(self): if self.connection is not None: if self.alive: self.pool.return_conn(self.connection) self.pool = None self.connection = None class CursorFairy(object): def __init__(self, parent, cursor): self.parent = parent self.cursor = cursor def __getattr__(self, key): return getattr(self.cursor, key) class SingletonThreadPool(Pool): """Maintains one connection per each thread, never moving to another thread. this is used for SQLite and other databases with a similar restriction.""" def __init__(self, creator, **params): params['use_threadlocal'] = False Pool.__init__(self, **params) self._conns = {} self._creator = creator def return_conn(self, conn): pass def get(self): try: return self._conns[thread.get_ident()] except KeyError: return self._conns.setdefault(thread.get_ident(), self._creator()) class QueuePool(Pool): """uses Queue.Queue to maintain a fixed-size list of connections.""" def __init__(self, creator, pool_size = 5, max_overflow = 10, **params): Pool.__init__(self, **params) self._creator = creator self._pool = Queue.Queue(pool_size) self._overflow = 0 - pool_size self._max_overflow = max_overflow def return_conn(self, conn): if self._echo: self.log("return connection to pool") try: self._pool.put(conn, False) except Queue.Full: self._overflow -= 1 def get(self): if self._echo: self.log("get connection from pool") self.log(self.status()) try: return self._pool.get(self._max_overflow > -1 and self._overflow >= self._max_overflow) except Queue.Empty: self._overflow += 1 return self._creator() def __del__(self): while True: try: conn = self._pool.get(False) conn.close() except Queue.Empty: break def status(self): tup = (self.size(), self.checkedin(), self.overflow(), self.checkedout()) return "Pool size: %d Connections in pool: %d Current Overflow: %d Current Checked out connections: %d" % tup def size(self): return self._pool.maxsize def checkedin(self): return self._pool.qsize() def overflow(self): return self._overflow def checkedout(self): return self._pool.maxsize - self._pool.qsize() + self._overflow class DBProxy(object): """proxies a DBAPI2 connect() call to a pooled connection keyed to the specific connect parameters.""" def __init__(self, module, poolclass = QueuePool, **params): """ module is a DBAPI2 module poolclass is a Pool class, defaulting to QueuePool. other parameters are sent to the Pool object's constructor. """ self.module = module self.params = params self.poolclass = poolclass self.pools = {} def close(self): for key in self.pools.keys(): del self.pools[key] def __del__(self): self.close() def get_pool(self, *args, **params): key = self._serialize(*args, **params) try: return self.pools[key] except KeyError: pool = self.poolclass(lambda: self.module.connect(*args, **params), **self.params) self.pools[key] = pool return pool def connect(self, *args, **params): """connects to a database using this DBProxy's module and the given connect arguments. if the arguments match an existing pool, the connection will be returned from the pool's current thread-local connection instance, or if there is no thread-local connection instance it will be checked out from the set of pooled connections. If the pool has no available connections and allows new connections to be created, a new database connection will be made.""" return self.get_pool(*args, **params).connect() def _serialize(self, *args, **params): return cPickle.dumps([args, params])
gpl-2.0
[ 3, 4203, 14, 647, 446, 8113, 20699, 367, 14303, 199, 3, 1898, 334, 35, 9, 11811, 12, 7968, 16922, 29434, 281, 333, 7455, 63, 311, 32, 29414, 863, 4655, 14, 957, 199, 3, 199, 3, 961, 859, 365, 1777, 402, 14303, 436, 365, 14286, 1334, 199, 3, 314, 10697, 844, 26, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 421, 199, 624, 20121, 282, 1950, 4203, 4514, 12, 1314, 14190, 31965, 6947, 199, 265, 282, 2462, 2257, 5597, 14, 221, 6121, 6571, 282, 27980, 18, 1752, 27292, 4045, 880, 626, 20092, 883, 199, 1235, 12883, 5847, 12, 4079, 641, 859, 730, 436, 4907, 2368, 12, 199, 9329, 701, 6358, 5578, 27980, 4907, 342, 3102, 1041, 199, 199, 646, 10703, 12, 13852, 12, 1059, 12, 17572, 199, 199, 893, 26, 272, 492, 2462, 199, 2590, 26, 272, 492, 7283, 2671, 465, 2462, 199, 199, 17128, 275, 1052, 199, 199, 318, 9635, 8, 578, 12, 1011, 1162, 304, 272, 408, 11809, 282, 27980, 18, 859, 436, 4203, 10041, 2633, 12, 2529, 282, 4566, 367, 314, 859, 272, 626, 911, 5847, 4203, 6947, 14, 221, 8394, 787, 28218, 370, 376, 8793, 6249, 4936, 272, 909, 14, 339, 7628, 26, 272, 859, 520, 282, 27980, 18, 3050, 859, 14, 2286, 8394, 26, 272, 11343, 29, 797, 520, 340, 663, 370, 715, 12, 6947, 3769, 25239, 1146, 436, 12396, 687, 15, 475, 314, 4203, 911, 272, 506, 10367, 370, 314, 4465, 1072, 12, 465, 5521, 465, 4203, 308, 9147, 2556, 14, 339, 675, 63, 2671, 1832, 29, 549, 520, 340, 663, 370, 715, 12, 10877, 4882, 370, 4907, 342, 4453, 314, 2011, 272, 4223, 2462, 911, 506, 17334, 370, 372, 314, 2011, 1950, 909, 12, 340, 1373, 965, 272, 2575, 2757, 12396, 687, 314, 4203, 436, 965, 440, 2757, 2138, 5966, 14, 961, 6127, 1233, 370, 272, 8044, 282, 1950, 687, 314, 4203, 12, 436, 2066, 1830, 5139, 17573, 641, 370, 626, 1950, 12, 272, 370, 1240, 1163, 3423, 1314, 2597, 7198, 314, 4203, 367, 282, 1950, 402, 314, 2011, 2368, 27, 272, 5204, 3423, 911, 2454, 12188, 314, 2011, 1950, 626, 314, 6358, 1083, 365, 1808, 14, 339, 4203, 533, 29, 3737, 5453, 520, 314, 849, 1021, 1202, 701, 314, 4203, 859, 370, 5647, 20699, 14, 272, 10703, 5453, 4440, 314, 2018, 10703, 14, 3737, 1021, 370, 11075, 282, 769, 402, 2808, 6947, 14, 339, 4203, 63, 890, 29, 21, 520, 1202, 701, 10703, 5453, 446, 314, 1568, 402, 314, 4203, 370, 506, 26391, 14, 961, 365, 314, 272, 17451, 1329, 402, 6947, 626, 911, 506, 16204, 16149, 590, 315, 314, 4203, 14, 3390, 626, 314, 272, 4203, 22241, 543, 949, 6947, 27, 5403, 642, 1329, 402, 6947, 365, 5839, 12, 626, 272, 1329, 402, 6947, 911, 5706, 14, 339, 1390, 63, 14108, 29, 709, 520, 314, 5696, 15784, 1568, 402, 314, 4203, 14, 3979, 314, 1329, 402, 7923, 13, 548, 272, 6947, 12276, 397, 314, 1568, 663, 315, 4203, 63, 890, 12, 4722, 6947, 911, 506, 2138, 1536, 272, 370, 642, 2304, 14, 3979, 5204, 4722, 6947, 787, 2138, 370, 314, 4203, 12, 2985, 787, 272, 25602, 436, 22002, 14, 2779, 11924, 2066, 626, 314, 3141, 1329, 402, 27008, 272, 6947, 314, 4203, 911, 2040, 365, 4203, 63, 890, 435, 1390, 63, 14108, 12, 436, 314, 3141, 1329, 402, 272, 298, 4532, 316, 2, 6947, 314, 4203, 911, 2040, 365, 4203, 63, 890, 14, 1390, 63, 14108, 883, 506, 663, 370, 446, 17, 370, 272, 6623, 949, 15784, 2304, 27, 949, 2304, 911, 506, 15090, 641, 314, 3141, 1329, 402, 23002, 272, 6947, 14, 2286, 408, 272, 862, 26, 267, 372, 14942, 59, 578, 61, 272, 871, 4067, 26, 267, 372, 14942, 14, 5486, 8, 578, 12, 6249, 4936, 8, 578, 12, 1011, 1162, 430, 258, 199, 199, 318, 5436, 63, 16259, 837, 272, 408, 264, 4912, 1006, 1453, 27980, 18, 19680, 14, 221, 1006, 20092, 436, 6947, 787, 2153, 5824, 1041, 272, 367, 5256, 315, 14942, 14, 1459, 837, 267, 5256, 14, 1600, 342, 272, 14942, 14, 3584, 342, 10813, 199, 533, 15553, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 11343, 275, 756, 12, 675, 63, 2671, 1832, 275, 715, 304, 267, 291, 423, 2671, 30039, 275, 13852, 14, 18889, 1110, 11728, 342, 267, 291, 423, 1180, 63, 2671, 1832, 275, 675, 63, 2671, 1832, 267, 291, 423, 7878, 275, 11343, 5493, 347, 4907, 8, 277, 304, 267, 340, 440, 291, 423, 1180, 63, 2671, 1832, 26, 288, 372, 8113, 1906, 73, 651, 8, 277, 9, 10631, 862, 26, 288, 6631, 275, 291, 423, 2671, 30039, 59, 2671, 14, 362, 63, 5425, 5106, 288, 340, 440, 6631, 14, 9631, 26, 355, 6631, 275, 8113, 1906, 73, 651, 8, 277, 9, 288, 291, 423, 2671, 30039, 59, 2671, 14, 362, 63, 5425, 5106, 275, 6631, 288, 372, 6631, 267, 871, 4067, 26, 288, 6631, 275, 8113, 1906, 73, 651, 8, 277, 9, 288, 291, 423, 2671, 30039, 59, 2671, 14, 362, 63, 5425, 5106, 275, 6631, 288, 372, 6631, 15567, 347, 664, 8, 277, 304, 267, 746, 4279, 342, 5493, 347, 372, 63, 1631, 8, 277, 12, 2557, 12, 19708, 29, 549, 304, 267, 746, 4279, 342, 339, 347, 943, 8, 277, 12, 1499, 304, 267, 870, 1499, 199, 199, 533, 8113, 1906, 73, 651, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 4203, 304, 267, 291, 14, 2293, 275, 4203, 267, 862, 26, 288, 291, 14, 2105, 275, 4203, 14, 362, 342, 267, 871, 26, 288, 291, 14, 2105, 275, 488, 288, 746, 267, 291, 14, 9631, 275, 715, 272, 347, 3920, 8, 277, 304, 267, 372, 20385, 1906, 73, 651, 8, 277, 12, 291, 14, 2105, 14, 3937, 1012, 272, 347, 636, 5675, 721, 277, 12, 790, 304, 267, 372, 2519, 8, 277, 14, 2105, 12, 790, 9, 272, 347, 636, 2264, 721, 277, 304, 267, 340, 291, 14, 2105, 365, 440, 488, 26, 288, 340, 291, 14, 9631, 26, 355, 291, 14, 2293, 14, 1107, 63, 1631, 8, 277, 14, 2105, 9, 288, 291, 14, 2293, 275, 488, 288, 291, 14, 2105, 275, 488, 1467, 199, 533, 20385, 1906, 73, 651, 8 ]
[ 4203, 14, 647, 446, 8113, 20699, 367, 14303, 199, 3, 1898, 334, 35, 9, 11811, 12, 7968, 16922, 29434, 281, 333, 7455, 63, 311, 32, 29414, 863, 4655, 14, 957, 199, 3, 199, 3, 961, 859, 365, 1777, 402, 14303, 436, 365, 14286, 1334, 199, 3, 314, 10697, 844, 26, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 421, 199, 624, 20121, 282, 1950, 4203, 4514, 12, 1314, 14190, 31965, 6947, 199, 265, 282, 2462, 2257, 5597, 14, 221, 6121, 6571, 282, 27980, 18, 1752, 27292, 4045, 880, 626, 20092, 883, 199, 1235, 12883, 5847, 12, 4079, 641, 859, 730, 436, 4907, 2368, 12, 199, 9329, 701, 6358, 5578, 27980, 4907, 342, 3102, 1041, 199, 199, 646, 10703, 12, 13852, 12, 1059, 12, 17572, 199, 199, 893, 26, 272, 492, 2462, 199, 2590, 26, 272, 492, 7283, 2671, 465, 2462, 199, 199, 17128, 275, 1052, 199, 199, 318, 9635, 8, 578, 12, 1011, 1162, 304, 272, 408, 11809, 282, 27980, 18, 859, 436, 4203, 10041, 2633, 12, 2529, 282, 4566, 367, 314, 859, 272, 626, 911, 5847, 4203, 6947, 14, 221, 8394, 787, 28218, 370, 376, 8793, 6249, 4936, 272, 909, 14, 339, 7628, 26, 272, 859, 520, 282, 27980, 18, 3050, 859, 14, 2286, 8394, 26, 272, 11343, 29, 797, 520, 340, 663, 370, 715, 12, 6947, 3769, 25239, 1146, 436, 12396, 687, 15, 475, 314, 4203, 911, 272, 506, 10367, 370, 314, 4465, 1072, 12, 465, 5521, 465, 4203, 308, 9147, 2556, 14, 339, 675, 63, 2671, 1832, 29, 549, 520, 340, 663, 370, 715, 12, 10877, 4882, 370, 4907, 342, 4453, 314, 2011, 272, 4223, 2462, 911, 506, 17334, 370, 372, 314, 2011, 1950, 909, 12, 340, 1373, 965, 272, 2575, 2757, 12396, 687, 314, 4203, 436, 965, 440, 2757, 2138, 5966, 14, 961, 6127, 1233, 370, 272, 8044, 282, 1950, 687, 314, 4203, 12, 436, 2066, 1830, 5139, 17573, 641, 370, 626, 1950, 12, 272, 370, 1240, 1163, 3423, 1314, 2597, 7198, 314, 4203, 367, 282, 1950, 402, 314, 2011, 2368, 27, 272, 5204, 3423, 911, 2454, 12188, 314, 2011, 1950, 626, 314, 6358, 1083, 365, 1808, 14, 339, 4203, 533, 29, 3737, 5453, 520, 314, 849, 1021, 1202, 701, 314, 4203, 859, 370, 5647, 20699, 14, 272, 10703, 5453, 4440, 314, 2018, 10703, 14, 3737, 1021, 370, 11075, 282, 769, 402, 2808, 6947, 14, 339, 4203, 63, 890, 29, 21, 520, 1202, 701, 10703, 5453, 446, 314, 1568, 402, 314, 4203, 370, 506, 26391, 14, 961, 365, 314, 272, 17451, 1329, 402, 6947, 626, 911, 506, 16204, 16149, 590, 315, 314, 4203, 14, 3390, 626, 314, 272, 4203, 22241, 543, 949, 6947, 27, 5403, 642, 1329, 402, 6947, 365, 5839, 12, 626, 272, 1329, 402, 6947, 911, 5706, 14, 339, 1390, 63, 14108, 29, 709, 520, 314, 5696, 15784, 1568, 402, 314, 4203, 14, 3979, 314, 1329, 402, 7923, 13, 548, 272, 6947, 12276, 397, 314, 1568, 663, 315, 4203, 63, 890, 12, 4722, 6947, 911, 506, 2138, 1536, 272, 370, 642, 2304, 14, 3979, 5204, 4722, 6947, 787, 2138, 370, 314, 4203, 12, 2985, 787, 272, 25602, 436, 22002, 14, 2779, 11924, 2066, 626, 314, 3141, 1329, 402, 27008, 272, 6947, 314, 4203, 911, 2040, 365, 4203, 63, 890, 435, 1390, 63, 14108, 12, 436, 314, 3141, 1329, 402, 272, 298, 4532, 316, 2, 6947, 314, 4203, 911, 2040, 365, 4203, 63, 890, 14, 1390, 63, 14108, 883, 506, 663, 370, 446, 17, 370, 272, 6623, 949, 15784, 2304, 27, 949, 2304, 911, 506, 15090, 641, 314, 3141, 1329, 402, 23002, 272, 6947, 14, 2286, 408, 272, 862, 26, 267, 372, 14942, 59, 578, 61, 272, 871, 4067, 26, 267, 372, 14942, 14, 5486, 8, 578, 12, 6249, 4936, 8, 578, 12, 1011, 1162, 430, 258, 199, 199, 318, 5436, 63, 16259, 837, 272, 408, 264, 4912, 1006, 1453, 27980, 18, 19680, 14, 221, 1006, 20092, 436, 6947, 787, 2153, 5824, 1041, 272, 367, 5256, 315, 14942, 14, 1459, 837, 267, 5256, 14, 1600, 342, 272, 14942, 14, 3584, 342, 10813, 199, 533, 15553, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 11343, 275, 756, 12, 675, 63, 2671, 1832, 275, 715, 304, 267, 291, 423, 2671, 30039, 275, 13852, 14, 18889, 1110, 11728, 342, 267, 291, 423, 1180, 63, 2671, 1832, 275, 675, 63, 2671, 1832, 267, 291, 423, 7878, 275, 11343, 5493, 347, 4907, 8, 277, 304, 267, 340, 440, 291, 423, 1180, 63, 2671, 1832, 26, 288, 372, 8113, 1906, 73, 651, 8, 277, 9, 10631, 862, 26, 288, 6631, 275, 291, 423, 2671, 30039, 59, 2671, 14, 362, 63, 5425, 5106, 288, 340, 440, 6631, 14, 9631, 26, 355, 6631, 275, 8113, 1906, 73, 651, 8, 277, 9, 288, 291, 423, 2671, 30039, 59, 2671, 14, 362, 63, 5425, 5106, 275, 6631, 288, 372, 6631, 267, 871, 4067, 26, 288, 6631, 275, 8113, 1906, 73, 651, 8, 277, 9, 288, 291, 423, 2671, 30039, 59, 2671, 14, 362, 63, 5425, 5106, 275, 6631, 288, 372, 6631, 15567, 347, 664, 8, 277, 304, 267, 746, 4279, 342, 5493, 347, 372, 63, 1631, 8, 277, 12, 2557, 12, 19708, 29, 549, 304, 267, 746, 4279, 342, 339, 347, 943, 8, 277, 12, 1499, 304, 267, 870, 1499, 199, 199, 533, 8113, 1906, 73, 651, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 4203, 304, 267, 291, 14, 2293, 275, 4203, 267, 862, 26, 288, 291, 14, 2105, 275, 4203, 14, 362, 342, 267, 871, 26, 288, 291, 14, 2105, 275, 488, 288, 746, 267, 291, 14, 9631, 275, 715, 272, 347, 3920, 8, 277, 304, 267, 372, 20385, 1906, 73, 651, 8, 277, 12, 291, 14, 2105, 14, 3937, 1012, 272, 347, 636, 5675, 721, 277, 12, 790, 304, 267, 372, 2519, 8, 277, 14, 2105, 12, 790, 9, 272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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 ]
Fillll/reddit2telegram
reddit2telegram/channels/r_battlestations/app.py
1
1028
#encoding:utf-8 from utils import weighted_random_subreddit # Subreddit that will be a source of content subreddit = weighted_random_subreddit({ 'battlestations': 1.0, # If we want get content from several subreddits # please provide here 'subreddit': probability # 'any_other_subreddit': 0.02 }) # Telegram channel with @reddit2telegram_bot as an admin t_channel = '@r_battlestations' def send_post(submission, r2t): return r2t.send_simple(submission, # Submission should have at least min_upvotes_limit upvotes. min_upvotes_limit=40, # If you do not want text submissions, just pass False. text=True, # If you want gifs, just pass True or text you want under gif. gif=True, # If you want images, just pass True or text you want under image. img=True, # If you want albums, just pass True or text you want under albums. album=True, # If you do not want othe submissions, just pass False. other=False )
mit
[ 3, 2991, 26, 1624, 13, 24, 199, 199, 504, 3778, 492, 14609, 63, 2355, 63, 954, 18374, 421, 199, 3, 4804, 18374, 626, 911, 506, 282, 1350, 402, 1564, 199, 954, 18374, 275, 14609, 63, 2355, 63, 954, 18374, 2561, 272, 283, 29787, 270, 1298, 356, 413, 14, 16, 12, 272, 327, 982, 781, 2934, 664, 1564, 687, 9978, 1007, 581, 15256, 272, 327, 8749, 5647, 2348, 283, 954, 18374, 356, 12224, 272, 327, 283, 1629, 63, 1848, 63, 954, 18374, 356, 378, 14, 996, 199, 1552, 199, 3, 23884, 1679, 3623, 543, 768, 18374, 18, 15253, 1679, 63, 3018, 465, 376, 4628, 199, 84, 63, 2775, 275, 10267, 82, 63, 29787, 270, 1298, 7, 421, 199, 318, 3222, 63, 1932, 8, 12542, 12, 519, 18, 84, 304, 272, 372, 519, 18, 84, 14, 2254, 63, 4129, 8, 12542, 12, 267, 327, 4804, 2250, 1077, 1172, 737, 5210, 1748, 63, 384, 16660, 63, 3097, 1536, 16660, 14, 267, 1748, 63, 384, 16660, 63, 3097, 29, 2167, 12, 267, 327, 982, 1265, 886, 440, 2934, 1318, 30399, 12, 2951, 986, 756, 14, 267, 1318, 29, 549, 12, 267, 327, 982, 1265, 2934, 486, 20985, 12, 2951, 986, 715, 503, 1318, 1265, 2934, 1334, 486, 692, 14, 267, 486, 692, 29, 549, 12, 267, 327, 982, 1265, 2934, 5935, 12, 2951, 986, 715, 503, 1318, 1265, 2934, 1334, 1834, 14, 267, 6050, 29, 549, 12, 267, 327, 982, 1265, 2934, 16379, 83, 12, 2951, 986, 715, 503, 1318, 1265, 2934, 1334, 16379, 83, 14, 267, 16379, 29, 549, 12, 267, 327, 982, 1265, 886, 440, 2934, 312, 1589, 30399, 12, 2951, 986, 756, 14, 267, 1163, 29, 797, 272, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2991, 26, 1624, 13, 24, 199, 199, 504, 3778, 492, 14609, 63, 2355, 63, 954, 18374, 421, 199, 3, 4804, 18374, 626, 911, 506, 282, 1350, 402, 1564, 199, 954, 18374, 275, 14609, 63, 2355, 63, 954, 18374, 2561, 272, 283, 29787, 270, 1298, 356, 413, 14, 16, 12, 272, 327, 982, 781, 2934, 664, 1564, 687, 9978, 1007, 581, 15256, 272, 327, 8749, 5647, 2348, 283, 954, 18374, 356, 12224, 272, 327, 283, 1629, 63, 1848, 63, 954, 18374, 356, 378, 14, 996, 199, 1552, 199, 3, 23884, 1679, 3623, 543, 768, 18374, 18, 15253, 1679, 63, 3018, 465, 376, 4628, 199, 84, 63, 2775, 275, 10267, 82, 63, 29787, 270, 1298, 7, 421, 199, 318, 3222, 63, 1932, 8, 12542, 12, 519, 18, 84, 304, 272, 372, 519, 18, 84, 14, 2254, 63, 4129, 8, 12542, 12, 267, 327, 4804, 2250, 1077, 1172, 737, 5210, 1748, 63, 384, 16660, 63, 3097, 1536, 16660, 14, 267, 1748, 63, 384, 16660, 63, 3097, 29, 2167, 12, 267, 327, 982, 1265, 886, 440, 2934, 1318, 30399, 12, 2951, 986, 756, 14, 267, 1318, 29, 549, 12, 267, 327, 982, 1265, 2934, 486, 20985, 12, 2951, 986, 715, 503, 1318, 1265, 2934, 1334, 486, 692, 14, 267, 486, 692, 29, 549, 12, 267, 327, 982, 1265, 2934, 5935, 12, 2951, 986, 715, 503, 1318, 1265, 2934, 1334, 1834, 14, 267, 6050, 29, 549, 12, 267, 327, 982, 1265, 2934, 16379, 83, 12, 2951, 986, 715, 503, 1318, 1265, 2934, 1334, 16379, 83, 14, 267, 16379, 29, 549, 12, 267, 327, 982, 1265, 886, 440, 2934, 312, 1589, 30399, 12, 2951, 986, 756, 14, 267, 1163, 29, 797, 272, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
75651/kbengine_cloud
kbe/res/scripts/common/Lib/site-packages/setuptools/command/upload_docs.py
332
6811
# -*- coding: utf-8 -*- """upload_docs Implements a Distutils 'upload_docs' subcommand (upload documentation to PyPI's pythonhosted.org). """ import os import socket import zipfile import tempfile import sys import shutil from base64 import standard_b64encode from pkg_resources import iter_entry_points from distutils import log from distutils.errors import DistutilsOptionError from distutils.command.upload import upload from setuptools.compat import httplib, urlparse, unicode, iteritems, PY3 errors = 'surrogateescape' if PY3 else 'strict' # This is not just a replacement for byte literals # but works as a general purpose encoder def b(s, encoding='utf-8'): if isinstance(s, unicode): return s.encode(encoding, errors) return s class upload_docs(upload): description = 'Upload documentation to PyPI' user_options = [ ('repository=', 'r', "url of repository [default: %s]" % upload.DEFAULT_REPOSITORY), ('show-response', None, 'display full response text from server'), ('upload-dir=', None, 'directory to upload'), ] boolean_options = upload.boolean_options def has_sphinx(self): if self.upload_dir is None: for ep in iter_entry_points('distutils.commands', 'build_sphinx'): return True sub_commands = [('build_sphinx', has_sphinx)] def initialize_options(self): upload.initialize_options(self) self.upload_dir = None self.target_dir = None def finalize_options(self): upload.finalize_options(self) if self.upload_dir is None: if self.has_sphinx(): build_sphinx = self.get_finalized_command('build_sphinx') self.target_dir = build_sphinx.builder_target_dir else: build = self.get_finalized_command('build') self.target_dir = os.path.join(build.build_base, 'docs') else: self.ensure_dirname('upload_dir') self.target_dir = self.upload_dir self.announce('Using upload directory %s' % self.target_dir) def create_zipfile(self, filename): zip_file = zipfile.ZipFile(filename, "w") try: self.mkpath(self.target_dir) # just in case for root, dirs, files in os.walk(self.target_dir): if root == self.target_dir and not files: raise DistutilsOptionError( "no files found in upload directory '%s'" % self.target_dir) for name in files: full = os.path.join(root, name) relative = root[len(self.target_dir):].lstrip(os.path.sep) dest = os.path.join(relative, name) zip_file.write(full, dest) finally: zip_file.close() def run(self): # Run sub commands for cmd_name in self.get_sub_commands(): self.run_command(cmd_name) tmp_dir = tempfile.mkdtemp() name = self.distribution.metadata.get_name() zip_file = os.path.join(tmp_dir, "%s.zip" % name) try: self.create_zipfile(zip_file) self.upload_file(zip_file) finally: shutil.rmtree(tmp_dir) def upload_file(self, filename): f = open(filename, 'rb') content = f.read() f.close() meta = self.distribution.metadata data = { ':action': 'doc_upload', 'name': meta.get_name(), 'content': (os.path.basename(filename), content), } # set up the authentication credentials = b(self.username + ':' + self.password) credentials = standard_b64encode(credentials) if PY3: credentials = credentials.decode('ascii') auth = "Basic " + credentials # Build up the MIME payload for the POST data boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' sep_boundary = b('\n--') + b(boundary) end_boundary = sep_boundary + b('--') body = [] for key, values in iteritems(data): title = '\nContent-Disposition: form-data; name="%s"' % key # handle multiple entries for the same name if not isinstance(values, list): values = [values] for value in values: if type(value) is tuple: title += '; filename="%s"' % value[0] value = value[1] else: value = b(value) body.append(sep_boundary) body.append(b(title)) body.append(b("\n\n")) body.append(value) if value and value[-1:] == b('\r'): body.append(b('\n')) # write an extra newline (lurve Macs) body.append(end_boundary) body.append(b("\n")) body = b('').join(body) self.announce("Submitting documentation to %s" % (self.repository), log.INFO) # build the Request # We can't use urllib2 since we need to send the Basic # auth right with the first request schema, netloc, url, params, query, fragments = \ urlparse(self.repository) assert not params and not query and not fragments if schema == 'http': conn = httplib.HTTPConnection(netloc) elif schema == 'https': conn = httplib.HTTPSConnection(netloc) else: raise AssertionError("unsupported schema "+schema) data = '' try: conn.connect() conn.putrequest("POST", url) content_type = 'multipart/form-data; boundary=%s' % boundary conn.putheader('Content-type', content_type) conn.putheader('Content-length', str(len(body))) conn.putheader('Authorization', auth) conn.endheaders() conn.send(body) except socket.error: e = sys.exc_info()[1] self.announce(str(e), log.ERROR) return r = conn.getresponse() if r.status == 200: self.announce('Server response (%s): %s' % (r.status, r.reason), log.INFO) elif r.status == 301: location = r.getheader('Location') if location is None: location = 'https://pythonhosted.org/%s/' % meta.get_name() self.announce('Upload successful. Visit %s' % location, log.INFO) else: self.announce('Upload failed (%s): %s' % (r.status, r.reason), log.ERROR) if self.show_response: print('-'*75, r.read(), '-'*75)
lgpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 5064, 63, 4757, 199, 199, 29452, 282, 12577, 283, 5064, 63, 4757, 7, 21474, 334, 5064, 3794, 370, 199, 2713, 2252, 1159, 2366, 24127, 14, 1308, 680, 199, 624, 199, 199, 646, 747, 199, 646, 2838, 199, 646, 10392, 199, 646, 5549, 199, 646, 984, 199, 646, 5145, 199, 199, 504, 1300, 772, 492, 4465, 63, 66, 772, 2143, 199, 504, 5496, 63, 4435, 492, 2740, 63, 2373, 63, 3438, 199, 199, 504, 7065, 492, 943, 199, 504, 7065, 14, 2550, 492, 31484, 199, 504, 7065, 14, 1531, 14, 5064, 492, 5802, 199, 199, 504, 9116, 14, 5819, 492, 8809, 12, 7097, 12, 2649, 12, 10849, 12, 7843, 19, 199, 199, 2550, 275, 283, 16380, 3765, 7, 340, 7843, 19, 587, 283, 4768, 7, 421, 199, 3, 961, 365, 440, 2951, 282, 8343, 367, 3696, 18041, 199, 3, 1325, 5419, 465, 282, 8605, 12016, 10295, 199, 318, 330, 8, 83, 12, 2644, 534, 1624, 13, 24, 735, 272, 340, 1228, 8, 83, 12, 2649, 304, 267, 372, 308, 14, 2143, 8, 2991, 12, 2552, 9, 272, 372, 308, 421, 199, 533, 5802, 63, 4757, 8, 5064, 304, 339, 1369, 275, 283, 10301, 3794, 370, 24330, 7, 339, 922, 63, 1419, 275, 359, 267, 661, 8421, 4009, 283, 82, 297, 268, 298, 633, 402, 7611, 359, 885, 26, 450, 83, 8480, 450, 5802, 14, 3472, 63, 907, 27998, 5347, 395, 267, 661, 2384, 13, 1310, 297, 488, 12, 268, 283, 2918, 2615, 1177, 1318, 687, 1654, 659, 267, 661, 5064, 13, 694, 4009, 488, 12, 283, 3619, 370, 5802, 659, 267, 1622, 272, 5046, 63, 1419, 275, 5802, 14, 4871, 63, 1419, 339, 347, 965, 63, 8008, 8, 277, 304, 267, 340, 291, 14, 5064, 63, 694, 365, 488, 26, 288, 367, 5442, 315, 2740, 63, 2373, 63, 3438, 360, 13350, 14, 4405, 297, 283, 1506, 63, 8008, 735, 355, 372, 715, 339, 1007, 63, 4405, 275, 4274, 1506, 63, 8008, 297, 965, 63, 8008, 1874, 339, 347, 8265, 63, 1419, 8, 277, 304, 267, 5802, 14, 8489, 63, 1419, 8, 277, 9, 267, 291, 14, 5064, 63, 694, 275, 488, 267, 291, 14, 1375, 63, 694, 275, 488, 339, 347, 17284, 63, 1419, 8, 277, 304, 267, 5802, 14, 14450, 63, 1419, 8, 277, 9, 267, 340, 291, 14, 5064, 63, 694, 365, 488, 26, 288, 340, 291, 14, 1989, 63, 8008, 837, 355, 1900, 63, 8008, 275, 291, 14, 362, 63, 19231, 63, 1531, 360, 1506, 63, 8008, 358, 355, 291, 14, 1375, 63, 694, 275, 1900, 63, 8008, 14, 5649, 63, 1375, 63, 694, 288, 587, 26, 355, 1900, 275, 291, 14, 362, 63, 19231, 63, 1531, 360, 1506, 358, 355, 291, 14, 1375, 63, 694, 275, 747, 14, 515, 14, 904, 8, 1506, 14, 1506, 63, 1095, 12, 283, 4757, 358, 267, 587, 26, 288, 291, 14, 7505, 63, 3475, 360, 5064, 63, 694, 358, 288, 291, 14, 1375, 63, 694, 275, 291, 14, 5064, 63, 694, 267, 291, 14, 17803, 360, 10369, 5802, 2082, 450, 83, 7, 450, 291, 14, 1375, 63, 694, 9, 339, 347, 1218, 63, 18717, 8, 277, 12, 1788, 304, 267, 3482, 63, 493, 275, 10392, 14, 15016, 8, 1501, 12, 298, 87, 531, 267, 862, 26, 288, 291, 14, 3880, 515, 8, 277, 14, 1375, 63, 694, 9, 221, 327, 2951, 315, 1930, 288, 367, 1738, 12, 7606, 12, 1584, 315, 747, 14, 7757, 8, 277, 14, 1375, 63, 694, 304, 355, 340, 1738, 508, 291, 14, 1375, 63, 694, 436, 440, 1584, 26, 490, 746, 31484, 8, 717, 298, 889, 1584, 1911, 315, 5802, 2082, 1543, 83, 4065, 717, 450, 291, 14, 1375, 63, 694, 9, 355, 367, 536, 315, 1584, 26, 490, 2615, 275, 747, 14, 515, 14, 904, 8, 1231, 12, 536, 9, 490, 3847, 275, 1738, 59, 552, 8, 277, 14, 1375, 63, 694, 304, 1055, 10124, 8, 736, 14, 515, 14, 4127, 9, 490, 2053, 275, 747, 14, 515, 14, 904, 8, 6188, 12, 536, 9, 490, 3482, 63, 493, 14, 952, 8, 2861, 12, 2053, 9, 267, 3753, 26, 288, 3482, 63, 493, 14, 1600, 342, 339, 347, 1255, 8, 277, 304, 267, 327, 3378, 1007, 3718, 267, 367, 2088, 63, 354, 315, 291, 14, 362, 63, 954, 63, 4405, 837, 288, 291, 14, 1065, 63, 1531, 8, 1760, 63, 354, 9, 398, 3529, 63, 694, 275, 5549, 14, 11983, 342, 267, 536, 275, 291, 14, 4972, 14, 2343, 14, 362, 63, 354, 342, 267, 3482, 63, 493, 275, 747, 14, 515, 14, 904, 8, 2791, 63, 694, 12, 2071, 83, 14, 3065, 2, 450, 536, 9, 267, 862, 26, 288, 291, 14, 981, 63, 18717, 8, 3065, 63, 493, 9, 288, 291, 14, 5064, 63, 493, 8, 3065, 63, 493, 9, 267, 3753, 26, 288, 5145, 14, 9242, 8, 2791, 63, 694, 9, 339, 347, 5802, 63, 493, 8, 277, 12, 1788, 304, 267, 289, 275, 1551, 8, 1501, 12, 283, 4848, 358, 267, 1564, 275, 289, 14, 739, 342, 267, 289, 14, 1600, 342, 267, 3404, 275, 291, 14, 4972, 14, 2343, 267, 666, 275, 469, 288, 7596, 1287, 356, 283, 1301, 63, 5064, 297, 288, 283, 354, 356, 3404, 14, 362, 63, 354, 1062, 288, 283, 1317, 356, 334, 736, 14, 515, 14, 4846, 8, 1501, 395, 1564, 395, 267, 789, 267, 327, 663, 1536, 314, 6299, 267, 6235, 275, 330, 8, 277, 14, 2473, 435, 10871, 435, 291, 14, 2060, 9, 267, 6235, 275, 4465, 63, 66, 772, 2143, 8, 6942, 9, 267, 340, 7843, 19, 26, 288, 6235, 275, 6235, 14, 2708, 360, 4371, 358, 267, 1790, 275, 298, 6845, 298, 435, 6235, 398, 327, 6516, 1536, 314, 14735, 4886, 367, 314, 8761, 666, 267, 8424, 275, 283, 10965, 31916, 8656, 38, 42, 8045, 39, 3177, 13332, 19, 38, 24100, 32259, 907, 2194, 772, 1465, 1367, 1342, 708, 1477, 7, 267, 7375, 63, 9891, 275, 330, 2258, 78, 306, 358, 435, 330, 8, 9891, 9, 267, 1284, 63, 9891, 275, 7375, 63, 9891, 435, 330, 4517, 358, 267, 2396, 275, 942, 267, 367, 790, 12, 1338, 315, 10849, 8, 576, 304, 288, 2538, 275 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 5064, 63, 4757, 199, 199, 29452, 282, 12577, 283, 5064, 63, 4757, 7, 21474, 334, 5064, 3794, 370, 199, 2713, 2252, 1159, 2366, 24127, 14, 1308, 680, 199, 624, 199, 199, 646, 747, 199, 646, 2838, 199, 646, 10392, 199, 646, 5549, 199, 646, 984, 199, 646, 5145, 199, 199, 504, 1300, 772, 492, 4465, 63, 66, 772, 2143, 199, 504, 5496, 63, 4435, 492, 2740, 63, 2373, 63, 3438, 199, 199, 504, 7065, 492, 943, 199, 504, 7065, 14, 2550, 492, 31484, 199, 504, 7065, 14, 1531, 14, 5064, 492, 5802, 199, 199, 504, 9116, 14, 5819, 492, 8809, 12, 7097, 12, 2649, 12, 10849, 12, 7843, 19, 199, 199, 2550, 275, 283, 16380, 3765, 7, 340, 7843, 19, 587, 283, 4768, 7, 421, 199, 3, 961, 365, 440, 2951, 282, 8343, 367, 3696, 18041, 199, 3, 1325, 5419, 465, 282, 8605, 12016, 10295, 199, 318, 330, 8, 83, 12, 2644, 534, 1624, 13, 24, 735, 272, 340, 1228, 8, 83, 12, 2649, 304, 267, 372, 308, 14, 2143, 8, 2991, 12, 2552, 9, 272, 372, 308, 421, 199, 533, 5802, 63, 4757, 8, 5064, 304, 339, 1369, 275, 283, 10301, 3794, 370, 24330, 7, 339, 922, 63, 1419, 275, 359, 267, 661, 8421, 4009, 283, 82, 297, 268, 298, 633, 402, 7611, 359, 885, 26, 450, 83, 8480, 450, 5802, 14, 3472, 63, 907, 27998, 5347, 395, 267, 661, 2384, 13, 1310, 297, 488, 12, 268, 283, 2918, 2615, 1177, 1318, 687, 1654, 659, 267, 661, 5064, 13, 694, 4009, 488, 12, 283, 3619, 370, 5802, 659, 267, 1622, 272, 5046, 63, 1419, 275, 5802, 14, 4871, 63, 1419, 339, 347, 965, 63, 8008, 8, 277, 304, 267, 340, 291, 14, 5064, 63, 694, 365, 488, 26, 288, 367, 5442, 315, 2740, 63, 2373, 63, 3438, 360, 13350, 14, 4405, 297, 283, 1506, 63, 8008, 735, 355, 372, 715, 339, 1007, 63, 4405, 275, 4274, 1506, 63, 8008, 297, 965, 63, 8008, 1874, 339, 347, 8265, 63, 1419, 8, 277, 304, 267, 5802, 14, 8489, 63, 1419, 8, 277, 9, 267, 291, 14, 5064, 63, 694, 275, 488, 267, 291, 14, 1375, 63, 694, 275, 488, 339, 347, 17284, 63, 1419, 8, 277, 304, 267, 5802, 14, 14450, 63, 1419, 8, 277, 9, 267, 340, 291, 14, 5064, 63, 694, 365, 488, 26, 288, 340, 291, 14, 1989, 63, 8008, 837, 355, 1900, 63, 8008, 275, 291, 14, 362, 63, 19231, 63, 1531, 360, 1506, 63, 8008, 358, 355, 291, 14, 1375, 63, 694, 275, 1900, 63, 8008, 14, 5649, 63, 1375, 63, 694, 288, 587, 26, 355, 1900, 275, 291, 14, 362, 63, 19231, 63, 1531, 360, 1506, 358, 355, 291, 14, 1375, 63, 694, 275, 747, 14, 515, 14, 904, 8, 1506, 14, 1506, 63, 1095, 12, 283, 4757, 358, 267, 587, 26, 288, 291, 14, 7505, 63, 3475, 360, 5064, 63, 694, 358, 288, 291, 14, 1375, 63, 694, 275, 291, 14, 5064, 63, 694, 267, 291, 14, 17803, 360, 10369, 5802, 2082, 450, 83, 7, 450, 291, 14, 1375, 63, 694, 9, 339, 347, 1218, 63, 18717, 8, 277, 12, 1788, 304, 267, 3482, 63, 493, 275, 10392, 14, 15016, 8, 1501, 12, 298, 87, 531, 267, 862, 26, 288, 291, 14, 3880, 515, 8, 277, 14, 1375, 63, 694, 9, 221, 327, 2951, 315, 1930, 288, 367, 1738, 12, 7606, 12, 1584, 315, 747, 14, 7757, 8, 277, 14, 1375, 63, 694, 304, 355, 340, 1738, 508, 291, 14, 1375, 63, 694, 436, 440, 1584, 26, 490, 746, 31484, 8, 717, 298, 889, 1584, 1911, 315, 5802, 2082, 1543, 83, 4065, 717, 450, 291, 14, 1375, 63, 694, 9, 355, 367, 536, 315, 1584, 26, 490, 2615, 275, 747, 14, 515, 14, 904, 8, 1231, 12, 536, 9, 490, 3847, 275, 1738, 59, 552, 8, 277, 14, 1375, 63, 694, 304, 1055, 10124, 8, 736, 14, 515, 14, 4127, 9, 490, 2053, 275, 747, 14, 515, 14, 904, 8, 6188, 12, 536, 9, 490, 3482, 63, 493, 14, 952, 8, 2861, 12, 2053, 9, 267, 3753, 26, 288, 3482, 63, 493, 14, 1600, 342, 339, 347, 1255, 8, 277, 304, 267, 327, 3378, 1007, 3718, 267, 367, 2088, 63, 354, 315, 291, 14, 362, 63, 954, 63, 4405, 837, 288, 291, 14, 1065, 63, 1531, 8, 1760, 63, 354, 9, 398, 3529, 63, 694, 275, 5549, 14, 11983, 342, 267, 536, 275, 291, 14, 4972, 14, 2343, 14, 362, 63, 354, 342, 267, 3482, 63, 493, 275, 747, 14, 515, 14, 904, 8, 2791, 63, 694, 12, 2071, 83, 14, 3065, 2, 450, 536, 9, 267, 862, 26, 288, 291, 14, 981, 63, 18717, 8, 3065, 63, 493, 9, 288, 291, 14, 5064, 63, 493, 8, 3065, 63, 493, 9, 267, 3753, 26, 288, 5145, 14, 9242, 8, 2791, 63, 694, 9, 339, 347, 5802, 63, 493, 8, 277, 12, 1788, 304, 267, 289, 275, 1551, 8, 1501, 12, 283, 4848, 358, 267, 1564, 275, 289, 14, 739, 342, 267, 289, 14, 1600, 342, 267, 3404, 275, 291, 14, 4972, 14, 2343, 267, 666, 275, 469, 288, 7596, 1287, 356, 283, 1301, 63, 5064, 297, 288, 283, 354, 356, 3404, 14, 362, 63, 354, 1062, 288, 283, 1317, 356, 334, 736, 14, 515, 14, 4846, 8, 1501, 395, 1564, 395, 267, 789, 267, 327, 663, 1536, 314, 6299, 267, 6235, 275, 330, 8, 277, 14, 2473, 435, 10871, 435, 291, 14, 2060, 9, 267, 6235, 275, 4465, 63, 66, 772, 2143, 8, 6942, 9, 267, 340, 7843, 19, 26, 288, 6235, 275, 6235, 14, 2708, 360, 4371, 358, 267, 1790, 275, 298, 6845, 298, 435, 6235, 398, 327, 6516, 1536, 314, 14735, 4886, 367, 314, 8761, 666, 267, 8424, 275, 283, 10965, 31916, 8656, 38, 42, 8045, 39, 3177, 13332, 19, 38, 24100, 32259, 907, 2194, 772, 1465, 1367, 1342, 708, 1477, 7, 267, 7375, 63, 9891, 275, 330, 2258, 78, 306, 358, 435, 330, 8, 9891, 9, 267, 1284, 63, 9891, 275, 7375, 63, 9891, 435, 330, 4517, 358, 267, 2396, 275, 942, 267, 367, 790, 12, 1338, 315, 10849, 8, 576, 304, 288, 2538, 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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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 ]
Godiyos/python-for-android
python-modules/twisted/twisted/internet/test/process_helper.py
145
1081
# A program which exits after starting a child which inherits its # stdin/stdout/stderr and keeps them open until stdin is closed. import sys, os def grandchild(): sys.stdout.write('grandchild started') sys.stdout.flush() sys.stdin.read() def main(): if sys.argv[1] == 'child': if sys.argv[2] == 'windows': import win32api as api, win32process as proc info = proc.STARTUPINFO() info.hStdInput = api.GetStdHandle(api.STD_INPUT_HANDLE) info.hStdOutput = api.GetStdHandle(api.STD_OUTPUT_HANDLE) info.hStdError = api.GetStdHandle(api.STD_ERROR_HANDLE) python = sys.executable scriptDir = os.path.dirname(__file__) scriptName = os.path.basename(__file__) proc.CreateProcess( None, " ".join((python, scriptName, "grandchild")), None, None, 1, 0, os.environ, scriptDir, info) else: if os.fork() == 0: grandchild() else: grandchild() if __name__ == '__main__': main()
apache-2.0
[ 199, 3, 437, 2240, 1314, 20100, 2410, 6617, 282, 1982, 1314, 21592, 2399, 199, 3, 9009, 15, 2703, 15, 3083, 436, 18578, 3062, 1551, 5133, 9009, 365, 6876, 14, 199, 199, 646, 984, 12, 747, 199, 199, 318, 26881, 1739, 837, 272, 984, 14, 2703, 14, 952, 360, 22655, 1739, 8239, 358, 272, 984, 14, 2703, 14, 4939, 342, 272, 984, 14, 6626, 14, 739, 342, 199, 199, 318, 2446, 837, 272, 340, 984, 14, 3020, 59, 17, 61, 508, 283, 1739, 356, 267, 340, 984, 14, 3020, 59, 18, 61, 508, 283, 8258, 356, 288, 492, 4747, 708, 1246, 465, 2986, 12, 4747, 708, 1412, 465, 6499, 288, 2256, 275, 6499, 14, 7363, 2160, 4531, 342, 288, 2256, 14, 72, 11976, 3205, 275, 2986, 14, 1002, 11976, 5940, 8, 1246, 14, 18472, 63, 7321, 63, 15885, 9, 288, 2256, 14, 72, 11976, 2959, 275, 2986, 14, 1002, 11976, 5940, 8, 1246, 14, 18472, 63, 8414, 63, 15885, 9, 288, 2256, 14, 72, 11976, 547, 275, 2986, 14, 1002, 11976, 5940, 8, 1246, 14, 18472, 63, 3170, 63, 15885, 9, 288, 2366, 275, 984, 14, 5904, 288, 2884, 3567, 275, 747, 14, 515, 14, 3475, 3460, 493, 3368, 288, 2884, 985, 275, 747, 14, 515, 14, 4846, 3460, 493, 3368, 288, 6499, 14, 2499, 3498, 8, 355, 488, 12, 298, 3680, 904, 1332, 1548, 12, 2884, 985, 12, 298, 22655, 1739, 8150, 488, 12, 355, 488, 12, 413, 12, 378, 12, 747, 14, 2314, 12, 2884, 3567, 12, 2256, 9, 267, 587, 26, 288, 340, 747, 14, 11796, 342, 508, 378, 26, 355, 26881, 1739, 342, 272, 587, 26, 267, 26881, 1739, 342, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 3, 437, 2240, 1314, 20100, 2410, 6617, 282, 1982, 1314, 21592, 2399, 199, 3, 9009, 15, 2703, 15, 3083, 436, 18578, 3062, 1551, 5133, 9009, 365, 6876, 14, 199, 199, 646, 984, 12, 747, 199, 199, 318, 26881, 1739, 837, 272, 984, 14, 2703, 14, 952, 360, 22655, 1739, 8239, 358, 272, 984, 14, 2703, 14, 4939, 342, 272, 984, 14, 6626, 14, 739, 342, 199, 199, 318, 2446, 837, 272, 340, 984, 14, 3020, 59, 17, 61, 508, 283, 1739, 356, 267, 340, 984, 14, 3020, 59, 18, 61, 508, 283, 8258, 356, 288, 492, 4747, 708, 1246, 465, 2986, 12, 4747, 708, 1412, 465, 6499, 288, 2256, 275, 6499, 14, 7363, 2160, 4531, 342, 288, 2256, 14, 72, 11976, 3205, 275, 2986, 14, 1002, 11976, 5940, 8, 1246, 14, 18472, 63, 7321, 63, 15885, 9, 288, 2256, 14, 72, 11976, 2959, 275, 2986, 14, 1002, 11976, 5940, 8, 1246, 14, 18472, 63, 8414, 63, 15885, 9, 288, 2256, 14, 72, 11976, 547, 275, 2986, 14, 1002, 11976, 5940, 8, 1246, 14, 18472, 63, 3170, 63, 15885, 9, 288, 2366, 275, 984, 14, 5904, 288, 2884, 3567, 275, 747, 14, 515, 14, 3475, 3460, 493, 3368, 288, 2884, 985, 275, 747, 14, 515, 14, 4846, 3460, 493, 3368, 288, 6499, 14, 2499, 3498, 8, 355, 488, 12, 298, 3680, 904, 1332, 1548, 12, 2884, 985, 12, 298, 22655, 1739, 8150, 488, 12, 355, 488, 12, 413, 12, 378, 12, 747, 14, 2314, 12, 2884, 3567, 12, 2256, 9, 267, 587, 26, 288, 340, 747, 14, 11796, 342, 508, 378, 26, 355, 26881, 1739, 342, 272, 587, 26, 267, 26881, 1739, 342, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 2446, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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/usr/bin/env python # ---------------------------------------------------------------------- # Numenta Platform for Intelligent Computing (NuPIC) # Copyright (C) 2013, Numenta, Inc. Unless you have an agreement # with Numenta, Inc., for a separate license for this software code, the # following terms and conditions apply: # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero Public License version 3 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Affero Public License for more details. # # You should have received a copy of the GNU Affero Public License # along with this program. If not, see http://www.gnu.org/licenses. # # http://numenta.org/licenses/ # ---------------------------------------------------------------------- import unittest2 as unittest from nupic.bindings.algorithms import SpatialPooler as CPPSpatialPooler import spatial_pooler_py_api_test spatial_pooler_py_api_test.SpatialPooler = CPPSpatialPooler SpatialPoolerCPPAPITest = spatial_pooler_py_api_test.SpatialPoolerAPITest if __name__ == "__main__": unittest.main()
agpl-3.0
[ 3168, 1182, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 20359, 199, 3, 22783, 16078, 367, 8883, 24024, 27799, 334, 21988, 26769, 9, 199, 3, 1898, 334, 35, 9, 6171, 12, 22783, 12, 3277, 14, 221, 4158, 1265, 1172, 376, 25025, 199, 3, 543, 22783, 12, 3277, 2020, 367, 282, 7396, 4190, 367, 642, 2032, 1233, 12, 314, 199, 3, 2569, 2895, 436, 3704, 4838, 26, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1684, 844, 1015, 650, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 199, 3, 1666, 314, 1664, 4265, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 14, 199, 3, 199, 3, 1455, 921, 78, 18952, 14, 1308, 15, 2383, 15, 199, 3, 20359, 199, 199, 646, 2882, 18, 465, 2882, 199, 199, 504, 26084, 14, 10880, 14, 24365, 492, 13423, 48, 1534, 1435, 465, 19701, 5067, 9491, 48, 1534, 1435, 199, 199, 646, 11469, 63, 555, 79, 1435, 63, 647, 63, 1246, 63, 396, 199, 199, 11679, 63, 555, 79, 1435, 63, 647, 63, 1246, 63, 396, 14, 18075, 48, 1534, 1435, 275, 19701, 5067, 9491, 48, 1534, 1435, 199, 18075, 48, 1534, 1435, 14533, 2642, 597, 275, 11469, 63, 555, 79, 1435, 63, 647, 63, 1246, 63, 396, 14, 18075, 48, 1534, 1435, 2642, 597, 4388, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 523, 2882, 14, 973, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1182, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 20359, 199, 3, 22783, 16078, 367, 8883, 24024, 27799, 334, 21988, 26769, 9, 199, 3, 1898, 334, 35, 9, 6171, 12, 22783, 12, 3277, 14, 221, 4158, 1265, 1172, 376, 25025, 199, 3, 543, 22783, 12, 3277, 2020, 367, 282, 7396, 4190, 367, 642, 2032, 1233, 12, 314, 199, 3, 2569, 2895, 436, 3704, 4838, 26, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1684, 844, 1015, 650, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 199, 3, 1666, 314, 1664, 4265, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 14, 199, 3, 199, 3, 1455, 921, 78, 18952, 14, 1308, 15, 2383, 15, 199, 3, 20359, 199, 199, 646, 2882, 18, 465, 2882, 199, 199, 504, 26084, 14, 10880, 14, 24365, 492, 13423, 48, 1534, 1435, 465, 19701, 5067, 9491, 48, 1534, 1435, 199, 199, 646, 11469, 63, 555, 79, 1435, 63, 647, 63, 1246, 63, 396, 199, 199, 11679, 63, 555, 79, 1435, 63, 647, 63, 1246, 63, 396, 14, 18075, 48, 1534, 1435, 275, 19701, 5067, 9491, 48, 1534, 1435, 199, 18075, 48, 1534, 1435, 14533, 2642, 597, 275, 11469, 63, 555, 79, 1435, 63, 647, 63, 1246, 63, 396, 14, 18075, 48, 1534, 1435, 2642, 597, 4388, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 523, 2882, 14, 973, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
andreikop/enki
enki/lib/buffpopen.py
3
5426
""" buffpopen --- Buffered subprocess. Popen implementation ======================================================= This implementation allows to read and write output without blocking """ import subprocess import threading import os import copy import time import shlex from queue import Queue, Empty, Full # python 3.x class BufferedPopen: """Bufferred version of Popen. Never locks, but uses unlimited buffers. May eat all the system memory, if something goes wrong. """ def __init__(self, command): self._command = command self._inQueue = Queue(8192) self._outQueue = Queue(8192) self._errQueue = Queue(8192) self._inThread = None self._outThread = None self._errThread = None self._popen = None def start(self, args): """Start the process """ env = copy.copy(os.environ) env['COLUMNS'] = str(2**16) # Don't need to break lines in the mit scheme. It will be done by text edit env['LINES'] = '25' if hasattr(subprocess, 'STARTUPINFO'): # windows only # On Windows, subprocess will pop up a command window by default when run from # Pyinstaller with the --noconsole option. Avoid this distraction. si = subprocess.STARTUPINFO() si.dwFlags |= subprocess.STARTF_USESHOWWINDOW # Windows doesn't search the path by default. Pass it an environment so it will. env = os.environ else: si = None env = None self._popen = subprocess.Popen(shlex.split(self._command) + args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=si, env=env, bufsize=0) self._inThread = threading.Thread(target=self._writeInputThread, name='enki.lib.buffpopen.input') self._outThread = threading.Thread(target=self._readOutputThread, kwargs={'pipe': self._popen.stdout}, name='enki.lib.buffpopen.stdout') self._errThread = threading.Thread(target=self._readOutputThread, kwargs={'pipe': self._popen.stderr}, name='enki.lib.buffpopen.stderr') self._mustDie = False self._inThread.start() self._outThread.start() # self._errThread.start() def stop(self): """Stop the process """ self._mustDie = True if self._popen is not None: try: self._popen.terminate() except OSError: # OK, it is already dead pass for i in range(5): if self._popen.poll() is None: time.sleep(0.04) else: break else: self._popen.kill() self._popen.wait() self._popen = None if self._inThread is not None and self._inThread.is_alive(): self._inThread.join() if self._outThread is not None and self._outThread.is_alive(): self._outThread.join() if self._errThread is not None and self._errThread.is_alive(): self._errThread.join() def isAlive(self): """Check if process is alive """ return self._popen.poll() is None def _readOutputThread(self, pipe): """Reader thread function. Reads output from process to queue """ # andreikop: Reading output by one character is not effective, but, I don't know # how to implement non-blocking reading of not full lines better def readChar(): pendingData = b'' while True: data = pipe.read(1) try: text = (pendingData + data).decode('utf8') except UnicodeDecodeError: pendingData += data continue else: return text text = readChar() while text and not self._mustDie: try: self._outQueue.put(text, False) except Full: time.sleep(0.01) continue text = readChar() def _writeInputThread(self): """Writer thread function. Writes data from input queue to process """ while not self._mustDie: try: text = self._inQueue.get(True, 0.1) except Empty: continue data = text.encode('utf8') self._popen.stdin.write(data) def write(self, text): """Write data to the subprocess """ if not self.isAlive(): return # Ooops, the process is dead. It doesn't need any output self._inQueue.put(text) # TODO test on big blocks of text. Make nonblocking even if queue is full def readOutput(self): """Read stdout data from the subprocess """ text = '' while not self._outQueue.empty() and len(text) < 256: text += self._outQueue.get(False) return text
gpl-2.0
[ 624, 199, 16830, 12207, 10894, 26832, 3873, 14, 13995, 4514, 199, 12813, 18673, 199, 199, 2765, 4514, 6127, 370, 1586, 436, 2218, 1072, 1928, 14592, 199, 624, 199, 199, 646, 3873, 199, 646, 5796, 199, 646, 747, 199, 646, 1331, 199, 646, 900, 199, 646, 16701, 199, 199, 504, 4126, 492, 10703, 12, 9630, 12, 16579, 221, 327, 2366, 650, 14, 88, 421, 199, 533, 26832, 7942, 26, 272, 408, 3299, 581, 1015, 402, 13995, 14, 272, 5612, 422, 23340, 12, 1325, 4440, 625, 14136, 19383, 14, 10162, 325, 292, 1006, 314, 2656, 4402, 12, 340, 6020, 13538, 6835, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1414, 304, 267, 291, 423, 1531, 275, 1414, 398, 291, 423, 262, 3737, 275, 10703, 8, 31526, 9, 267, 291, 423, 548, 3737, 275, 10703, 8, 31526, 9, 267, 291, 423, 1508, 3737, 275, 10703, 8, 31526, 9, 398, 291, 423, 262, 4436, 275, 488, 267, 291, 423, 548, 4436, 275, 488, 267, 291, 423, 1508, 4436, 275, 488, 267, 291, 423, 12207, 275, 488, 339, 347, 1343, 8, 277, 12, 1249, 304, 267, 408, 3162, 314, 2112, 267, 408, 267, 2589, 275, 1331, 14, 1574, 8, 736, 14, 2314, 9, 267, 2589, 459, 28427, 418, 275, 620, 8, 18, 538, 975, 9, 221, 327, 7529, 1133, 1929, 370, 2059, 2385, 315, 314, 30714, 5687, 14, 2779, 911, 506, 4224, 701, 1318, 5283, 267, 2589, 459, 23023, 418, 275, 283, 821, 7, 398, 340, 2688, 8, 5781, 12, 283, 7363, 2160, 4531, 735, 221, 327, 10061, 1454, 288, 327, 4068, 5417, 12, 3873, 911, 4560, 1536, 282, 1414, 4353, 701, 849, 1380, 1255, 687, 288, 327, 1611, 17047, 543, 314, 1553, 889, 6614, 945, 14, 19503, 642, 2917, 6156, 14, 288, 13877, 275, 3873, 14, 7363, 2160, 4531, 342, 288, 13877, 14, 10772, 6381, 8901, 3873, 14, 7363, 38, 63, 1668, 654, 16210, 15480, 288, 327, 5417, 3181, 1133, 2754, 314, 931, 701, 849, 14, 8325, 652, 376, 3734, 880, 652, 911, 14, 288, 2589, 275, 747, 14, 2314, 267, 587, 26, 288, 13877, 275, 488, 288, 2589, 275, 488, 398, 291, 423, 12207, 275, 3873, 14, 7942, 8, 32507, 14, 1294, 8, 277, 423, 1531, 9, 435, 1249, 12, 4318, 9009, 29, 5781, 14, 6089, 12, 4318, 3839, 29, 5781, 14, 6089, 12, 4318, 4635, 29, 5781, 14, 13850, 12, 4318, 14210, 815, 29, 338, 12, 2589, 29, 1813, 12, 4318, 17080, 29, 16, 9, 398, 291, 423, 262, 4436, 275, 5796, 14, 4436, 8, 1375, 29, 277, 423, 952, 3205, 4436, 12, 5101, 536, 534, 287, 8810, 14, 773, 14, 16830, 12207, 14, 1210, 358, 267, 291, 423, 548, 4436, 275, 5796, 14, 4436, 8, 1375, 29, 277, 423, 739, 2959, 4436, 12, 5644, 2074, 3713, 4990, 356, 291, 423, 12207, 14, 2703, 1386, 5644, 536, 534, 287, 8810, 14, 773, 14, 16830, 12207, 14, 2703, 358, 267, 291, 423, 1508, 4436, 275, 5796, 14, 4436, 8, 1375, 29, 277, 423, 739, 2959, 4436, 12, 5644, 2074, 3713, 4990, 356, 291, 423, 12207, 14, 3083, 1386, 5644, 536, 534, 287, 8810, 14, 773, 14, 16830, 12207, 14, 3083, 358, 398, 291, 423, 7790, 1341, 69, 275, 756, 267, 291, 423, 262, 4436, 14, 928, 342, 267, 291, 423, 548, 4436, 14, 928, 342, 267, 327, 291, 423, 1508, 4436, 14, 928, 342, 339, 347, 3631, 8, 277, 304, 267, 408, 6293, 314, 2112, 267, 408, 267, 291, 423, 7790, 1341, 69, 275, 715, 398, 340, 291, 423, 12207, 365, 440, 488, 26, 288, 862, 26, 355, 291, 423, 12207, 14, 14478, 342, 288, 871, 6440, 26, 221, 327, 9949, 12, 652, 365, 2575, 12314, 355, 986, 953, 367, 284, 315, 1425, 8, 21, 304, 355, 340, 291, 423, 12207, 14, 6843, 342, 365, 488, 26, 490, 900, 14, 4532, 8, 16, 14, 966, 9, 355, 587, 26, 490, 2059, 288, 587, 26, 355, 291, 423, 12207, 14, 8997, 342, 355, 291, 423, 12207, 14, 2573, 342, 355, 291, 423, 12207, 275, 488, 398, 340, 291, 423, 262, 4436, 365, 440, 488, 436, 291, 423, 262, 4436, 14, 374, 63, 9631, 837, 288, 291, 423, 262, 4436, 14, 904, 342, 267, 340, 291, 423, 548, 4436, 365, 440, 488, 436, 291, 423, 548, 4436, 14, 374, 63, 9631, 837, 288, 291, 423, 548, 4436, 14, 904, 342, 267, 340, 291, 423, 1508, 4436, 365, 440, 488, 436, 291, 423, 1508, 4436, 14, 374, 63, 9631, 837, 288, 291, 423, 1508, 4436, 14, 904, 342, 339, 347, 365, 23692, 8, 277, 304, 267, 408, 1799, 340, 2112, 365, 19708, 267, 408, 267, 372, 291, 423, 12207, 14, 6843, 342, 365, 488, 339, 347, 485, 739, 2959, 4436, 8, 277, 12, 5200, 304, 267, 408, 5929, 2462, 805, 14, 26129, 1072, 687, 2112, 370, 4126, 267, 408, 267, 327, 436, 264, 3258, 411, 26, 799, 5384, 1072, 701, 1373, 4528, 365, 440, 15826, 12, 1325, 12, 473, 2793, 1133, 5715, 267, 327, 4212, 370, 5669, 2222, 13, 13091, 7664, 402, 440, 2615, 2385, 8034, 267, 347, 1586, 1610, 837, 288, 9413, 1451, 275, 330, 891, 288, 1830, 715, 26, 355, 666, 275, 5200, 14, 739, 8, 17, 9, 355, 862, 26, 490, 1318, 275, 334, 6455, 1451, 435, 666, 680, 2708, 360, 1624, 24, 358, 355, 871, 18965, 26, 490, 9413, 1451, 847, 666, 490, 1980, 355, 587, 26, 490, 372, 1318, 398, 1318, 275, 1586, 1610, 342, 267, 1830, 1318, 436, 440, 291, 423, 7790, 1341, 69, 26, 288, 862, 26, 355, 291, 423, 548, 3737, 14, 524, 8, 505, 12, 756, 9, 288, 871, 16579, 26, 355, 900, 14, 4532, 8, 16, 14, 614, 9, 355, 1980, 953, 1318, 275, 1586, 1610, 342, 339, 347, 485, 952, 3205, 4436, 8, 277, 304, 267, 408, 6261, 2462, 805, 14, 30753, 666, 687, 1324, 4126, 370, 2112, 267, 408, 267, 1830, 440, 291, 423, 7790, 1341, 69, 26, 288, 862, 26, 355, 1318, 275, 291, 423, 262, 3737, 14, 362, 8, 549, 12, 378, 14, 17, 9, 288, 871, 9630, 26, 355, 1980, 953, 666, 275, 1318, 14, 2143, 360, 1624, 24, 358, 288, 291, 423, 12207, 14, 6626, 14, 952, 8, 576, 9, 339, 347 ]
[ 199, 16830, 12207, 10894, 26832, 3873, 14, 13995, 4514, 199, 12813, 18673, 199, 199, 2765, 4514, 6127, 370, 1586, 436, 2218, 1072, 1928, 14592, 199, 624, 199, 199, 646, 3873, 199, 646, 5796, 199, 646, 747, 199, 646, 1331, 199, 646, 900, 199, 646, 16701, 199, 199, 504, 4126, 492, 10703, 12, 9630, 12, 16579, 221, 327, 2366, 650, 14, 88, 421, 199, 533, 26832, 7942, 26, 272, 408, 3299, 581, 1015, 402, 13995, 14, 272, 5612, 422, 23340, 12, 1325, 4440, 625, 14136, 19383, 14, 10162, 325, 292, 1006, 314, 2656, 4402, 12, 340, 6020, 13538, 6835, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1414, 304, 267, 291, 423, 1531, 275, 1414, 398, 291, 423, 262, 3737, 275, 10703, 8, 31526, 9, 267, 291, 423, 548, 3737, 275, 10703, 8, 31526, 9, 267, 291, 423, 1508, 3737, 275, 10703, 8, 31526, 9, 398, 291, 423, 262, 4436, 275, 488, 267, 291, 423, 548, 4436, 275, 488, 267, 291, 423, 1508, 4436, 275, 488, 267, 291, 423, 12207, 275, 488, 339, 347, 1343, 8, 277, 12, 1249, 304, 267, 408, 3162, 314, 2112, 267, 408, 267, 2589, 275, 1331, 14, 1574, 8, 736, 14, 2314, 9, 267, 2589, 459, 28427, 418, 275, 620, 8, 18, 538, 975, 9, 221, 327, 7529, 1133, 1929, 370, 2059, 2385, 315, 314, 30714, 5687, 14, 2779, 911, 506, 4224, 701, 1318, 5283, 267, 2589, 459, 23023, 418, 275, 283, 821, 7, 398, 340, 2688, 8, 5781, 12, 283, 7363, 2160, 4531, 735, 221, 327, 10061, 1454, 288, 327, 4068, 5417, 12, 3873, 911, 4560, 1536, 282, 1414, 4353, 701, 849, 1380, 1255, 687, 288, 327, 1611, 17047, 543, 314, 1553, 889, 6614, 945, 14, 19503, 642, 2917, 6156, 14, 288, 13877, 275, 3873, 14, 7363, 2160, 4531, 342, 288, 13877, 14, 10772, 6381, 8901, 3873, 14, 7363, 38, 63, 1668, 654, 16210, 15480, 288, 327, 5417, 3181, 1133, 2754, 314, 931, 701, 849, 14, 8325, 652, 376, 3734, 880, 652, 911, 14, 288, 2589, 275, 747, 14, 2314, 267, 587, 26, 288, 13877, 275, 488, 288, 2589, 275, 488, 398, 291, 423, 12207, 275, 3873, 14, 7942, 8, 32507, 14, 1294, 8, 277, 423, 1531, 9, 435, 1249, 12, 4318, 9009, 29, 5781, 14, 6089, 12, 4318, 3839, 29, 5781, 14, 6089, 12, 4318, 4635, 29, 5781, 14, 13850, 12, 4318, 14210, 815, 29, 338, 12, 2589, 29, 1813, 12, 4318, 17080, 29, 16, 9, 398, 291, 423, 262, 4436, 275, 5796, 14, 4436, 8, 1375, 29, 277, 423, 952, 3205, 4436, 12, 5101, 536, 534, 287, 8810, 14, 773, 14, 16830, 12207, 14, 1210, 358, 267, 291, 423, 548, 4436, 275, 5796, 14, 4436, 8, 1375, 29, 277, 423, 739, 2959, 4436, 12, 5644, 2074, 3713, 4990, 356, 291, 423, 12207, 14, 2703, 1386, 5644, 536, 534, 287, 8810, 14, 773, 14, 16830, 12207, 14, 2703, 358, 267, 291, 423, 1508, 4436, 275, 5796, 14, 4436, 8, 1375, 29, 277, 423, 739, 2959, 4436, 12, 5644, 2074, 3713, 4990, 356, 291, 423, 12207, 14, 3083, 1386, 5644, 536, 534, 287, 8810, 14, 773, 14, 16830, 12207, 14, 3083, 358, 398, 291, 423, 7790, 1341, 69, 275, 756, 267, 291, 423, 262, 4436, 14, 928, 342, 267, 291, 423, 548, 4436, 14, 928, 342, 267, 327, 291, 423, 1508, 4436, 14, 928, 342, 339, 347, 3631, 8, 277, 304, 267, 408, 6293, 314, 2112, 267, 408, 267, 291, 423, 7790, 1341, 69, 275, 715, 398, 340, 291, 423, 12207, 365, 440, 488, 26, 288, 862, 26, 355, 291, 423, 12207, 14, 14478, 342, 288, 871, 6440, 26, 221, 327, 9949, 12, 652, 365, 2575, 12314, 355, 986, 953, 367, 284, 315, 1425, 8, 21, 304, 355, 340, 291, 423, 12207, 14, 6843, 342, 365, 488, 26, 490, 900, 14, 4532, 8, 16, 14, 966, 9, 355, 587, 26, 490, 2059, 288, 587, 26, 355, 291, 423, 12207, 14, 8997, 342, 355, 291, 423, 12207, 14, 2573, 342, 355, 291, 423, 12207, 275, 488, 398, 340, 291, 423, 262, 4436, 365, 440, 488, 436, 291, 423, 262, 4436, 14, 374, 63, 9631, 837, 288, 291, 423, 262, 4436, 14, 904, 342, 267, 340, 291, 423, 548, 4436, 365, 440, 488, 436, 291, 423, 548, 4436, 14, 374, 63, 9631, 837, 288, 291, 423, 548, 4436, 14, 904, 342, 267, 340, 291, 423, 1508, 4436, 365, 440, 488, 436, 291, 423, 1508, 4436, 14, 374, 63, 9631, 837, 288, 291, 423, 1508, 4436, 14, 904, 342, 339, 347, 365, 23692, 8, 277, 304, 267, 408, 1799, 340, 2112, 365, 19708, 267, 408, 267, 372, 291, 423, 12207, 14, 6843, 342, 365, 488, 339, 347, 485, 739, 2959, 4436, 8, 277, 12, 5200, 304, 267, 408, 5929, 2462, 805, 14, 26129, 1072, 687, 2112, 370, 4126, 267, 408, 267, 327, 436, 264, 3258, 411, 26, 799, 5384, 1072, 701, 1373, 4528, 365, 440, 15826, 12, 1325, 12, 473, 2793, 1133, 5715, 267, 327, 4212, 370, 5669, 2222, 13, 13091, 7664, 402, 440, 2615, 2385, 8034, 267, 347, 1586, 1610, 837, 288, 9413, 1451, 275, 330, 891, 288, 1830, 715, 26, 355, 666, 275, 5200, 14, 739, 8, 17, 9, 355, 862, 26, 490, 1318, 275, 334, 6455, 1451, 435, 666, 680, 2708, 360, 1624, 24, 358, 355, 871, 18965, 26, 490, 9413, 1451, 847, 666, 490, 1980, 355, 587, 26, 490, 372, 1318, 398, 1318, 275, 1586, 1610, 342, 267, 1830, 1318, 436, 440, 291, 423, 7790, 1341, 69, 26, 288, 862, 26, 355, 291, 423, 548, 3737, 14, 524, 8, 505, 12, 756, 9, 288, 871, 16579, 26, 355, 900, 14, 4532, 8, 16, 14, 614, 9, 355, 1980, 953, 1318, 275, 1586, 1610, 342, 339, 347, 485, 952, 3205, 4436, 8, 277, 304, 267, 408, 6261, 2462, 805, 14, 30753, 666, 687, 1324, 4126, 370, 2112, 267, 408, 267, 1830, 440, 291, 423, 7790, 1341, 69, 26, 288, 862, 26, 355, 1318, 275, 291, 423, 262, 3737, 14, 362, 8, 549, 12, 378, 14, 17, 9, 288, 871, 9630, 26, 355, 1980, 953, 666, 275, 1318, 14, 2143, 360, 1624, 24, 358, 288, 291, 423, 12207, 14, 6626, 14, 952, 8, 576, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
laurenrevere/osf.io
addons/owncloud/migrations/0001_initial.py
28
1511
# -*- coding: utf-8 -*- # Generated by Django 1.9 on 2017-03-23 20:34 from __future__ import unicode_literals from django.db import migrations, models import osf.models.base import osf.utils.datetime_aware_jsonfield class Migration(migrations.Migration): initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='NodeSettings', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('_id', models.CharField(db_index=True, default=osf.models.base.generate_object_id, max_length=24, unique=True)), ('deleted', models.BooleanField(default=False)), ('folder_id', models.TextField(blank=True, null=True)), ], options={ 'abstract': False, }, ), migrations.CreateModel( name='UserSettings', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('_id', models.CharField(db_index=True, default=osf.models.base.generate_object_id, max_length=24, unique=True)), ('deleted', models.BooleanField(default=False)), ('oauth_grants', osf.utils.datetime_aware_jsonfield.DateTimeAwareJSONField(blank=True, default=dict)), ], options={ 'abstract': False, }, ), ]
apache-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 17065, 701, 5634, 413, 14, 25, 641, 9708, 13, 1644, 13, 1789, 3388, 26, 1082, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 1639, 14, 697, 492, 6180, 12, 1709, 199, 646, 747, 70, 14, 992, 14, 1095, 199, 646, 747, 70, 14, 1208, 14, 2083, 63, 14600, 63, 1001, 698, 421, 199, 533, 12090, 8, 7685, 14, 9816, 304, 339, 2536, 275, 715, 339, 5124, 275, 359, 272, 1622, 339, 5331, 275, 359, 267, 6180, 14, 14907, 8, 288, 536, 534, 1716, 5268, 297, 288, 1504, 1524, 355, 661, 344, 297, 1709, 14, 4378, 8, 2495, 63, 3966, 29, 549, 12, 5062, 63, 498, 29, 549, 12, 8437, 29, 797, 12, 3376, 63, 354, 534, 998, 3855, 355, 12331, 344, 297, 1709, 14, 2183, 8, 697, 63, 1080, 29, 549, 12, 849, 29, 20923, 14, 992, 14, 1095, 14, 4208, 63, 785, 63, 344, 12, 1390, 63, 1267, 29, 1194, 12, 3747, 29, 549, 1826, 355, 661, 6062, 297, 1709, 14, 5036, 8, 885, 29, 797, 1826, 355, 661, 3741, 63, 344, 297, 1709, 14, 6254, 8, 2500, 29, 549, 12, 2973, 29, 549, 1826, 288, 2156, 288, 1511, 3126, 355, 283, 6198, 356, 756, 12, 288, 1660, 267, 2318, 267, 6180, 14, 14907, 8, 288, 536, 534, 1899, 5268, 297, 288, 1504, 1524, 355, 661, 344, 297, 1709, 14, 4378, 8, 2495, 63, 3966, 29, 549, 12, 5062, 63, 498, 29, 549, 12, 8437, 29, 797, 12, 3376, 63, 354, 534, 998, 3855, 355, 12331, 344, 297, 1709, 14, 2183, 8, 697, 63, 1080, 29, 549, 12, 849, 29, 20923, 14, 992, 14, 1095, 14, 4208, 63, 785, 63, 344, 12, 1390, 63, 1267, 29, 1194, 12, 3747, 29, 549, 1826, 355, 661, 6062, 297, 1709, 14, 5036, 8, 885, 29, 797, 1826, 355, 661, 6126, 63, 2587, 2285, 297, 747, 70, 14, 1208, 14, 2083, 63, 14600, 63, 1001, 698, 14, 3926, 24290, 30796, 8, 2500, 29, 549, 12, 849, 29, 807, 1826, 288, 2156, 288, 1511, 3126, 355, 283, 6198, 356, 756, 12, 288, 1660, 267, 2318, 272, 1622, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 17065, 701, 5634, 413, 14, 25, 641, 9708, 13, 1644, 13, 1789, 3388, 26, 1082, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 1639, 14, 697, 492, 6180, 12, 1709, 199, 646, 747, 70, 14, 992, 14, 1095, 199, 646, 747, 70, 14, 1208, 14, 2083, 63, 14600, 63, 1001, 698, 421, 199, 533, 12090, 8, 7685, 14, 9816, 304, 339, 2536, 275, 715, 339, 5124, 275, 359, 272, 1622, 339, 5331, 275, 359, 267, 6180, 14, 14907, 8, 288, 536, 534, 1716, 5268, 297, 288, 1504, 1524, 355, 661, 344, 297, 1709, 14, 4378, 8, 2495, 63, 3966, 29, 549, 12, 5062, 63, 498, 29, 549, 12, 8437, 29, 797, 12, 3376, 63, 354, 534, 998, 3855, 355, 12331, 344, 297, 1709, 14, 2183, 8, 697, 63, 1080, 29, 549, 12, 849, 29, 20923, 14, 992, 14, 1095, 14, 4208, 63, 785, 63, 344, 12, 1390, 63, 1267, 29, 1194, 12, 3747, 29, 549, 1826, 355, 661, 6062, 297, 1709, 14, 5036, 8, 885, 29, 797, 1826, 355, 661, 3741, 63, 344, 297, 1709, 14, 6254, 8, 2500, 29, 549, 12, 2973, 29, 549, 1826, 288, 2156, 288, 1511, 3126, 355, 283, 6198, 356, 756, 12, 288, 1660, 267, 2318, 267, 6180, 14, 14907, 8, 288, 536, 534, 1899, 5268, 297, 288, 1504, 1524, 355, 661, 344, 297, 1709, 14, 4378, 8, 2495, 63, 3966, 29, 549, 12, 5062, 63, 498, 29, 549, 12, 8437, 29, 797, 12, 3376, 63, 354, 534, 998, 3855, 355, 12331, 344, 297, 1709, 14, 2183, 8, 697, 63, 1080, 29, 549, 12, 849, 29, 20923, 14, 992, 14, 1095, 14, 4208, 63, 785, 63, 344, 12, 1390, 63, 1267, 29, 1194, 12, 3747, 29, 549, 1826, 355, 661, 6062, 297, 1709, 14, 5036, 8, 885, 29, 797, 1826, 355, 661, 6126, 63, 2587, 2285, 297, 747, 70, 14, 1208, 14, 2083, 63, 14600, 63, 1001, 698, 14, 3926, 24290, 30796, 8, 2500, 29, 549, 12, 849, 29, 807, 1826, 288, 2156, 288, 1511, 3126, 355, 283, 6198, 356, 756, 12, 288, 1660, 267, 2318, 272, 1622, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
homecon/homecon
homecon/plugins/weather.py
2
11099
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import logging import datetime import asyncio import ephem import numpy as np from .. import core from .. import util class Weather(core.plugin.Plugin): """ Class to control the HomeCon weather functions """ def initialize(self): # add forecast states core.states.add('weather/forecast/lastupdate', config={'datatype': 'number', 'quantity':'', 'unit':'','label':'', 'description':'', 'private':True}) for i in range(7): core.states.add('weather/forecast/daily/{}'.format(i), config={'datatype': 'dict', 'quantity':'', 'unit':'','label':'', 'description':'', 'log':False, 'private':True}) for i in range(24*7): core.states.add('weather/forecast/hourly/{}'.format(i), config={'datatype': 'dict', 'quantity':'', 'unit':'','label':'', 'description':'', 'log':False, 'private':True}) # add weather states core.states.add('weather/temperature', config={'datatype': 'number', 'quantity':'temperature', 'unit':'°C' , 'label':'Ambient', 'description':''}) core.states.add('weather/cloudcover', config={'datatype': 'number', 'quantity':'' , 'unit':'' , 'label':'Cloud cover' , 'description':''}) core.states.add('weather/sun/azimuth', config={'datatype': 'number', 'quantity':'angle' , 'unit':'°', 'label':'Azimuth' , 'description':''}) core.states.add('weather/sun/altitude', config={'datatype': 'number', 'quantity':'angle' , 'unit':'°', 'label':'Altitude' , 'description':''}) core.states.add('weather/irradiancedirect', config={'datatype': 'number', 'quantity':'irradiance' , 'unit':'W/m2', 'label':'Direct' , 'description':''}) core.states.add('weather/irradiancediffuse', config={'datatype': 'number', 'quantity':'irradiance' , 'unit':'W/m2', 'label':'Diffuse', 'description':''}) # schedule sun position updating self._loop.create_task(self.schedule_sunposition()) logging.debug('Weather plugin Initialized') async def schedule_sunposition(self): """ Schedule updating of the suns position """ while True: # timestamps dt_ref = datetime.datetime(1970, 1, 1) dt_now = datetime.datetime.utcnow() dt_when = dt_now + datetime.timedelta(minutes=2) timestamp_now = int( (dt_now-dt_ref).total_seconds() ) timestamp_when = int( (dt_when-dt_ref).total_seconds() ) # calculate the suns position latitude = core.states['settings/location/latitude'].value # N+ longitude = core.states['settings/location/longitude'].value # E+ elevation = core.states['settings/location/elevation'].value if elevation is None: elevation = 0 logging.warning('No elevation supplied, assuming 0 m') azimuth = None altitude = None if not latitude is None and not longitude is None: azimuth,altitude = util.weather.sunposition(latitude,longitude,elevation) azimuth = round(float(azimuth),2) altitude = round(float(altitude),2) core.states['weather/sun/azimuth'].value = azimuth core.states['weather/sun/altitude'].value = altitude # sleep until the next call await asyncio.sleep(timestamp_when-timestamp_now) def ambienttemperature(self): """ Estimate the ambient temperature from the forecast and measurements """ dt_ref = datetime.datetime(1970, 1, 1) dt_now = datetime.datetime.utcnow() timestamp_now = (dt_now-dt_ref).total_seconds() # get the prediction closest to now timestamps = [] values = [] for i in range(48): forecast = core.states['weather/forecast/hourly/{}'.format(i)].value if not forecast is None: timestamps.append(forecast['timestamp']) values.append(forecast['temperature']) if forecast['timestamp'] > timestamp_now: break if len(timestamps)>0: value_forecast = np.interp(timestamp_now,timestamps,values) else: value_forecast = None # get ambient temperature measurements value_sensors = [] confidence_sensors = [] for sensor in core.components.find(type='ambienttemperaturesensor'): val = sensor.states['value'].value if not val is None: value_sensors.append( val ) confidence_sensors.append( sensor.config['confidence'] ) # combine if not value_forecast is None: value_sensors.append(value_forecast) confidence_sensors.append(0.5) if len(value_sensors) > 0: value = sum([v*c for v,c in zip(value_sensors,confidence_sensors)])/sum(confidence_sensors) else: value = None return value def cloudcover(self): """ Estimate the cloudcover from the forecast and measurements """ dt_ref = datetime.datetime(1970, 1, 1) dt_now = datetime.datetime.utcnow() timestamp_now = (dt_now-dt_ref).total_seconds() # get the prediction closest to now timestamps = [] values = [] for i in range(48): forecast = core.states['weather/forecast/hourly/{}'.format(i)].value if not forecast is None: timestamps.append(forecast['timestamp']) values.append(forecast['cloudcover']) if forecast['timestamp'] > timestamp_now: break if len(timestamps)>0: value_forecast = np.interp(timestamp_now,timestamps,values) else: value_forecast = None # get cloudcover measurements value_sensors = [] confidence_sensors = [] solar_azimuth = core.states['weather/sun/azimuth'].value solar_altitude = core.states['weather/sun/altitude'].value if not solar_azimuth is None and not solar_altitude is None: I_direct_clearsky,I_diffuse_clearsky = util.weather.clearskyirrradiance(solar_azimuth,solar_altitude) if not I_direct_clearsky is None and not I_diffuse_clearsky is None: for sensor in core.components.find(type='irradiancesensor'): val = sensor.states['value'].value surface_azimuth = sensor.config['azimuth'] surface_tilt = sensor.config['tilt'] if not val is None: tempcloudcover = np.linspace(1.0,0.0,6) tempirradiance = [] for c in tempcloudcover: I_direct_cloudy , I_diffuse_cloudy = util.weather.cloudyskyirrradiance(I_direct_clearsky,I_diffuse_clearsky,c,solar_azimuth,solar_altitude) I_total_surface, I_direct_surface, I_diffuse_surface, I_ground_surface = util.weather.incidentirradiance(I_direct_cloudy,I_diffuse_cloudy,solar_azimuth,solar_altitude,surface_azimuth,surface_tilt) tempirradiance.append(I_total_surface) tempirradiance = np.array(tempirradiance) if max(tempirradiance) > 0: cloudcover = np.interp(val,tempirradiance,tempcloudcover) cloudcover = max(0,min(1,cloudcover)) value_sensors.append( cloudcover ) confidence_sensors.append( sensor.config['confidence'] ) # combine if not value_forecast is None: value_sensors.append(value_forecast) confidence_sensors.append(0.5) if len(value_sensors) > 0: value = sum([v*c for v,c in zip(value_sensors,confidence_sensors)])/sum(confidence_sensors) else: value = None return value def listen_state_changed(self,event): if event.data['state'].path == 'weather/sun/altitude' or event.data['state'].path == 'weather/cloudcover': cloudcover = core.states['weather/cloudcover'].value if cloudcover is None: cloudcover = 0 # update the irradiance solar_azimuth = core.states['weather/sun/azimuth'].value solar_altitude = core.states['weather/sun/altitude'].value if not solar_azimuth is None and not solar_altitude is None: I_direct_clearsky,I_diffuse_clearsky = util.weather.clearskyirrradiance(solar_azimuth,solar_altitude) I_direct_cloudy,I_diffuse_cloudy = util.weather.cloudyskyirrradiance(I_direct_clearsky,I_diffuse_clearsky,cloudcover,solar_azimuth,solar_altitude) core.states['weather/irradiancedirect'].value = round(float(I_direct_cloudy),2) core.states['weather/irradiancediffuse'].value = round(float(I_diffuse_cloudy),2) if 'component' in event.data['state'].config: component = core.components[event.data['state'].config['component']] if component.type == 'ambienttemperaturesensor': ambienttemperature = self.ambienttemperature() if not ambienttemperature is None: core.states['weather/temperature'].value = round(ambienttemperature,2) if component.type == 'irradiancesensor': cloudcover = self.cloudcover() if not cloudcover is None: core.states['weather/cloudcover'].value = round(cloudcover,3) def listen_forecast_updated(self,event): core.states['weather/temperature'].value = round(self.ambienttemperature(),2) core.states['weather/cloudcover'].value = round(self.cloudcover(),3) class Ambienttemperaturesensor(core.component.Component): """ a class implementing a temperature sensor """ default_config = { 'confidence': 0.5, } linked_states = { 'value': { 'default_config': {}, 'fixed_config': {}, }, } core.components.register(Ambienttemperaturesensor) class Irradiancesensor(core.component.Component): """ a class implementing an irradiance sensor """ default_config = { 'azimuth': 0, 'tilt': 0, 'confidence': 0.5, } linked_states = { 'value': { 'default_config': {}, 'fixed_config': {}, }, } core.components.register(Irradiancesensor)
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 202, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 2999, 199, 646, 2050, 202, 199, 646, 2197, 202, 199, 646, 16195, 202, 199, 646, 5442, 27037, 202, 199, 646, 2680, 465, 980, 2999, 199, 504, 2508, 492, 6170, 202, 199, 504, 2508, 492, 4884, 2999, 199, 533, 2136, 7404, 8, 1018, 14, 2718, 14, 5061, 304, 1128, 408, 1128, 8089, 370, 3304, 314, 14621, 714, 29643, 3423, 11787, 408, 2958, 347, 8265, 8, 277, 304, 13594, 327, 1050, 11257, 2931, 6363, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 29693, 15, 2019, 873, 297, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 297, 283, 3248, 5242, 1673, 1302, 5242, 297, 283, 1802, 5242, 297, 283, 4239, 356, 549, 1552, 4341, 367, 284, 315, 1425, 8, 23, 304, 1675, 6170, 14, 4981, 14, 525, 360, 23026, 15, 29693, 15, 18621, 30837, 908, 8, 73, 395, 1101, 3713, 14184, 356, 283, 807, 297, 283, 10577, 5242, 297, 283, 3248, 5242, 1673, 1302, 5242, 297, 283, 1802, 5242, 297, 283, 793, 356, 797, 12, 283, 4239, 356, 549, 1552, 13594, 367, 284, 315, 1425, 8, 1194, 10, 23, 304, 1675, 6170, 14, 4981, 14, 525, 360, 23026, 15, 29693, 15, 5180, 590, 30837, 908, 8, 73, 395, 1101, 3713, 14184, 356, 283, 807, 297, 283, 10577, 5242, 297, 283, 3248, 5242, 1673, 1302, 5242, 297, 283, 1802, 5242, 297, 283, 793, 356, 797, 12, 283, 4239, 356, 549, 1552, 1223, 4341, 327, 1050, 29643, 6363, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 12954, 297, 755, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 12954, 297, 283, 3248, 5242, 127, 109, 35, 7, 221, 2360, 283, 1302, 5242, 29209, 6792, 297, 283, 1802, 356, 891, 1552, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 4091, 5899, 297, 263, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 356, 891, 3698, 2360, 283, 3248, 356, 891, 259, 2360, 283, 1302, 5242, 9089, 8486, 7, 2360, 283, 1802, 356, 891, 1552, 4341, 6170, 14, 4981, 14, 525, 360, 23026, 15, 11846, 15, 4651, 26720, 297, 755, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 4593, 7, 2360, 283, 3248, 5242, 127, 109, 297, 283, 1302, 5242, 32171, 26720, 7, 2360, 283, 1802, 356, 891, 1552, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 11846, 15, 27539, 297, 420, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 4593, 7, 2360, 283, 3248, 5242, 127, 109, 297, 283, 1302, 5242, 2439, 7951, 7, 2360, 283, 1802, 356, 891, 1552, 4341, 6170, 14, 4981, 14, 525, 360, 23026, 15, 723, 12841, 554, 2275, 297, 221, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 723, 12841, 554, 7, 2360, 283, 3248, 5242, 55, 15, 77, 18, 297, 283, 1302, 5242, 16281, 7, 2360, 283, 1802, 356, 891, 1552, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 723, 12841, 554, 3028, 1180, 297, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 723, 12841, 554, 7, 2360, 283, 3248, 5242, 55, 15, 77, 18, 297, 283, 1302, 5242, 10746, 1180, 297, 283, 1802, 356, 891, 1552, 1223, 4341, 327, 8732, 26668, 3421, 12928, 1039, 291, 423, 3813, 14, 981, 63, 1765, 8, 277, 14, 7211, 63, 11846, 3124, 1012, 4341, 2050, 14, 1757, 360, 55, 4489, 728, 3589, 6026, 1759, 358, 10060, 2958, 5316, 347, 8732, 63, 11846, 3124, 8, 277, 304, 1039, 408, 1039, 24317, 12928, 402, 314, 26668, 83, 3421, 4341, 408, 4341, 1830, 715, 26, 1675, 327, 22496, 1675, 4487, 63, 1121, 275, 2197, 14, 2083, 8, 21740, 12, 413, 12, 413, 9, 1675, 4487, 63, 2131, 275, 2197, 14, 2083, 14, 10779, 342, 1675, 4487, 63, 6526, 275, 4487, 63, 2131, 435, 2197, 14, 7473, 8, 10430, 29, 18, 9, 11556, 4913, 63, 2131, 275, 1109, 8, 334, 3583, 63, 2131, 13, 3583, 63, 1121, 680, 2923, 63, 4515, 342, 776, 1675, 4913, 63, 6526, 275, 1109, 8, 334, 3583, 63, 6526, 13, 3583, 63, 1121, 680, 2923, 63, 4515, 342, 776, 10060, 1675, 327, 8671, 314, 26668, 83, 3421, 1675, 18896, 275, 6170, 14, 4981, 459, 1751, 15, 1985, 15, 13331, 2278, 585, 259, 327, 653, 11, 1675, 18154, 275, 6170, 14, 4981, 459, 1751, 15, 1985, 15, 13803, 2278, 585, 257, 327, 662, 11, 1675, 12993, 4255, 275, 6170, 14, 4981, 459, 1751, 15, 1985, 15, 32568, 2278, 585, 11556, 340, 12993, 4255, 365, 488, 26, 2628, 12993, 4255, 275, 378, 2628, 2050, 14, 3764, 360, 1944, 12993, 4255, 6841, 12, 18002, 378, 333, 358, 11556, 24978, 26720, 275, 488, 1675, 29534, 275, 488, 1675, 340, 440, 18896, 365, 488, 436, 440, 18154, 365, 488, 26, 2628, 24978, 26720, 12, 27539, 275, 4884, 14, 23026, 14, 11846, 3124, 8, 13331, 12, 13803, 12, 32568, 9, 2628, 24978, 26720, 275, 6168, 8, 1609, 8, 4651, 26720, 395, 18, 9, 2628, 29534, 275, 6168, 8, 1609, 8, 27539, 395, 18, 9, 11556, 6170, 14, 4981, 459, 23026, 15, 11846, 15, 4651, 26720, 2278, 585, 275, 24978, 26720, 1675, 6170, 14, 4981, 459, 23026, 15, 11846, 15, 27539, 2278, 585, 275, 29534, 11556, 327, 9435, 5133, 314, 2163, 1240, 1675, 5517, 16195, 14, 4532, 8, 3954, 63, 6526, 13, 3954, 63, 2131, 9, 10060, 2958, 347, 16353, 6792, 12954, 8, 277, 304, 1039, 408, 1039, 15896, 6897, 314, 16353, 6792, 14843, 687, 314, 11257, 2931, 436, 32619, 4341, 408, 4341, 4487, 63, 1121, 275, 2197, 14, 2083, 8, 21740, 12, 413, 12, 413, 9, 1039, 4487, 63, 2131, 275, 2197, 14, 2083, 14, 10779, 342, 1039, 4913, 63, 2131, 275, 334, 3583, 63, 2131, 13, 3583, 63, 1121, 680, 2923, 63, 4515, 342, 4341, 327, 664, 314, 12044, 18284, 370, 3063, 1039, 22496, 275, 942, 1039, 1338, 275, 942, 1039, 367, 284, 315, 1425, 8, 2006, 304, 1675, 11257, 2931, 275, 6170, 14, 4981, 459, 23026, 15, 29693, 15, 5180, 590, 30837, 908, 8, 73, 22509, 585, 11556, 340, 440, 11257, 2931, 365, 488, 26, 2628, 22496, 14, 740, 8, 29693, 459, 3954, 1105, 2628, 1338, 14, 740, 8, 29693, 459, 12954, 1105, 24216, 340, 11257 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 202, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 2999, 199, 646, 2050, 202, 199, 646, 2197, 202, 199, 646, 16195, 202, 199, 646, 5442, 27037, 202, 199, 646, 2680, 465, 980, 2999, 199, 504, 2508, 492, 6170, 202, 199, 504, 2508, 492, 4884, 2999, 199, 533, 2136, 7404, 8, 1018, 14, 2718, 14, 5061, 304, 1128, 408, 1128, 8089, 370, 3304, 314, 14621, 714, 29643, 3423, 11787, 408, 2958, 347, 8265, 8, 277, 304, 13594, 327, 1050, 11257, 2931, 6363, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 29693, 15, 2019, 873, 297, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 297, 283, 3248, 5242, 1673, 1302, 5242, 297, 283, 1802, 5242, 297, 283, 4239, 356, 549, 1552, 4341, 367, 284, 315, 1425, 8, 23, 304, 1675, 6170, 14, 4981, 14, 525, 360, 23026, 15, 29693, 15, 18621, 30837, 908, 8, 73, 395, 1101, 3713, 14184, 356, 283, 807, 297, 283, 10577, 5242, 297, 283, 3248, 5242, 1673, 1302, 5242, 297, 283, 1802, 5242, 297, 283, 793, 356, 797, 12, 283, 4239, 356, 549, 1552, 13594, 367, 284, 315, 1425, 8, 1194, 10, 23, 304, 1675, 6170, 14, 4981, 14, 525, 360, 23026, 15, 29693, 15, 5180, 590, 30837, 908, 8, 73, 395, 1101, 3713, 14184, 356, 283, 807, 297, 283, 10577, 5242, 297, 283, 3248, 5242, 1673, 1302, 5242, 297, 283, 1802, 5242, 297, 283, 793, 356, 797, 12, 283, 4239, 356, 549, 1552, 1223, 4341, 327, 1050, 29643, 6363, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 12954, 297, 755, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 12954, 297, 283, 3248, 5242, 127, 109, 35, 7, 221, 2360, 283, 1302, 5242, 29209, 6792, 297, 283, 1802, 356, 891, 1552, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 4091, 5899, 297, 263, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 356, 891, 3698, 2360, 283, 3248, 356, 891, 259, 2360, 283, 1302, 5242, 9089, 8486, 7, 2360, 283, 1802, 356, 891, 1552, 4341, 6170, 14, 4981, 14, 525, 360, 23026, 15, 11846, 15, 4651, 26720, 297, 755, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 4593, 7, 2360, 283, 3248, 5242, 127, 109, 297, 283, 1302, 5242, 32171, 26720, 7, 2360, 283, 1802, 356, 891, 1552, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 11846, 15, 27539, 297, 420, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 4593, 7, 2360, 283, 3248, 5242, 127, 109, 297, 283, 1302, 5242, 2439, 7951, 7, 2360, 283, 1802, 356, 891, 1552, 4341, 6170, 14, 4981, 14, 525, 360, 23026, 15, 723, 12841, 554, 2275, 297, 221, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 723, 12841, 554, 7, 2360, 283, 3248, 5242, 55, 15, 77, 18, 297, 283, 1302, 5242, 16281, 7, 2360, 283, 1802, 356, 891, 1552, 1039, 6170, 14, 4981, 14, 525, 360, 23026, 15, 723, 12841, 554, 3028, 1180, 297, 1101, 3713, 14184, 356, 283, 1955, 297, 283, 10577, 5242, 723, 12841, 554, 7, 2360, 283, 3248, 5242, 55, 15, 77, 18, 297, 283, 1302, 5242, 10746, 1180, 297, 283, 1802, 356, 891, 1552, 1223, 4341, 327, 8732, 26668, 3421, 12928, 1039, 291, 423, 3813, 14, 981, 63, 1765, 8, 277, 14, 7211, 63, 11846, 3124, 1012, 4341, 2050, 14, 1757, 360, 55, 4489, 728, 3589, 6026, 1759, 358, 10060, 2958, 5316, 347, 8732, 63, 11846, 3124, 8, 277, 304, 1039, 408, 1039, 24317, 12928, 402, 314, 26668, 83, 3421, 4341, 408, 4341, 1830, 715, 26, 1675, 327, 22496, 1675, 4487, 63, 1121, 275, 2197, 14, 2083, 8, 21740, 12, 413, 12, 413, 9, 1675, 4487, 63, 2131, 275, 2197, 14, 2083, 14, 10779, 342, 1675, 4487, 63, 6526, 275, 4487, 63, 2131, 435, 2197, 14, 7473, 8, 10430, 29, 18, 9, 11556, 4913, 63, 2131, 275, 1109, 8, 334, 3583, 63, 2131, 13, 3583, 63, 1121, 680, 2923, 63, 4515, 342, 776, 1675, 4913, 63, 6526, 275, 1109, 8, 334, 3583, 63, 6526, 13, 3583, 63, 1121, 680, 2923, 63, 4515, 342, 776, 10060, 1675, 327, 8671, 314, 26668, 83, 3421, 1675, 18896, 275, 6170, 14, 4981, 459, 1751, 15, 1985, 15, 13331, 2278, 585, 259, 327, 653, 11, 1675, 18154, 275, 6170, 14, 4981, 459, 1751, 15, 1985, 15, 13803, 2278, 585, 257, 327, 662, 11, 1675, 12993, 4255, 275, 6170, 14, 4981, 459, 1751, 15, 1985, 15, 32568, 2278, 585, 11556, 340, 12993, 4255, 365, 488, 26, 2628, 12993, 4255, 275, 378, 2628, 2050, 14, 3764, 360, 1944, 12993, 4255, 6841, 12, 18002, 378, 333, 358, 11556, 24978, 26720, 275, 488, 1675, 29534, 275, 488, 1675, 340, 440, 18896, 365, 488, 436, 440, 18154, 365, 488, 26, 2628, 24978, 26720, 12, 27539, 275, 4884, 14, 23026, 14, 11846, 3124, 8, 13331, 12, 13803, 12, 32568, 9, 2628, 24978, 26720, 275, 6168, 8, 1609, 8, 4651, 26720, 395, 18, 9, 2628, 29534, 275, 6168, 8, 1609, 8, 27539, 395, 18, 9, 11556, 6170, 14, 4981, 459, 23026, 15, 11846, 15, 4651, 26720, 2278, 585, 275, 24978, 26720, 1675, 6170, 14, 4981, 459, 23026, 15, 11846, 15, 27539, 2278, 585, 275, 29534, 11556, 327, 9435, 5133, 314, 2163, 1240, 1675, 5517, 16195, 14, 4532, 8, 3954, 63, 6526, 13, 3954, 63, 2131, 9, 10060, 2958, 347, 16353, 6792, 12954, 8, 277, 304, 1039, 408, 1039, 15896, 6897, 314, 16353, 6792, 14843, 687, 314, 11257, 2931, 436, 32619, 4341, 408, 4341, 4487, 63, 1121, 275, 2197, 14, 2083, 8, 21740, 12, 413, 12, 413, 9, 1039, 4487, 63, 2131, 275, 2197, 14, 2083, 14, 10779, 342, 1039, 4913, 63, 2131, 275, 334, 3583, 63, 2131, 13, 3583, 63, 1121, 680, 2923, 63, 4515, 342, 4341, 327, 664, 314, 12044, 18284, 370, 3063, 1039, 22496, 275, 942, 1039, 1338, 275, 942, 1039, 367, 284, 315, 1425, 8, 2006, 304, 1675, 11257, 2931, 275, 6170, 14, 4981, 459, 23026, 15, 29693, 15, 5180, 590, 30837, 908, 8, 73, 22509, 585, 11556, 340, 440, 11257, 2931, 365, 488, 26, 2628, 22496, 14, 740, 8, 29693, 459, 3954, 1105, 2628, 1338, 14, 740, 8, 29693, 459, 12954, 1105, 24216, 340, 11257, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Bysmyyr/chromium-crosswalk
build/android/devil/android/logcat_monitor_test.py
7
6779
#!/usr/bin/env python # Copyright 2015 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. # pylint: disable=protected-access import itertools import os import sys import unittest from devil.android import logcat_monitor from devil.android.sdk import adb_wrapper from pylib import constants sys.path.append(os.path.join( constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) import mock # pylint: disable=F0401 def _CreateTestLog(raw_logcat=None): test_adb = adb_wrapper.AdbWrapper('0123456789abcdef') test_adb.Logcat = mock.Mock(return_value=(l for l in raw_logcat)) test_log = logcat_monitor.LogcatMonitor(test_adb, clear=False) return test_log class LogcatMonitorTest(unittest.TestCase): _TEST_THREADTIME_LOGCAT_DATA = [ '01-01 01:02:03.456 7890 0987 V LogcatMonitorTest: ' 'verbose logcat monitor test message 1', '01-01 01:02:03.457 8901 1098 D LogcatMonitorTest: ' 'debug logcat monitor test message 2', '01-01 01:02:03.458 9012 2109 I LogcatMonitorTest: ' 'info logcat monitor test message 3', '01-01 01:02:03.459 0123 3210 W LogcatMonitorTest: ' 'warning logcat monitor test message 4', '01-01 01:02:03.460 1234 4321 E LogcatMonitorTest: ' 'error logcat monitor test message 5', '01-01 01:02:03.461 2345 5432 F LogcatMonitorTest: ' 'fatal logcat monitor test message 6', '01-01 01:02:03.462 3456 6543 D LogcatMonitorTest: ' 'ignore me',] def assertIterEqual(self, expected_iter, actual_iter): for expected, actual in itertools.izip_longest(expected_iter, actual_iter): self.assertIsNotNone( expected, msg='actual has unexpected elements starting with %s' % str(actual)) self.assertIsNotNone( actual, msg='actual is missing elements starting with %s' % str(expected)) self.assertEqual(actual.group('proc_id'), expected[0]) self.assertEqual(actual.group('thread_id'), expected[1]) self.assertEqual(actual.group('log_level'), expected[2]) self.assertEqual(actual.group('component'), expected[3]) self.assertEqual(actual.group('message'), expected[4]) with self.assertRaises(StopIteration): next(actual_iter) with self.assertRaises(StopIteration): next(expected_iter) def testWaitFor_success(self): test_log = _CreateTestLog( raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA) actual_match = test_log.WaitFor(r'.*(fatal|error) logcat monitor.*', None) self.assertTrue(actual_match) self.assertEqual( '01-01 01:02:03.460 1234 4321 E LogcatMonitorTest: ' 'error logcat monitor test message 5', actual_match.group(0)) self.assertEqual('error', actual_match.group(1)) def testWaitFor_failure(self): test_log = _CreateTestLog( raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA) actual_match = test_log.WaitFor( r'.*My Success Regex.*', r'.*(fatal|error) logcat monitor.*') self.assertIsNone(actual_match) def testFindAll_defaults(self): test_log = _CreateTestLog( raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA) expected_results = [ ('7890', '0987', 'V', 'LogcatMonitorTest', 'verbose logcat monitor test message 1'), ('8901', '1098', 'D', 'LogcatMonitorTest', 'debug logcat monitor test message 2'), ('9012', '2109', 'I', 'LogcatMonitorTest', 'info logcat monitor test message 3'), ('0123', '3210', 'W', 'LogcatMonitorTest', 'warning logcat monitor test message 4'), ('1234', '4321', 'E', 'LogcatMonitorTest', 'error logcat monitor test message 5'), ('2345', '5432', 'F', 'LogcatMonitorTest', 'fatal logcat monitor test message 6')] actual_results = test_log.FindAll(r'\S* logcat monitor test message \d') self.assertIterEqual(iter(expected_results), actual_results) def testFindAll_defaults_miss(self): test_log = _CreateTestLog( raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA) expected_results = [] actual_results = test_log.FindAll(r'\S* nothing should match this \d') self.assertIterEqual(iter(expected_results), actual_results) def testFindAll_filterProcId(self): test_log = _CreateTestLog( raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA) actual_results = test_log.FindAll( r'\S* logcat monitor test message \d', proc_id=1234) expected_results = [ ('1234', '4321', 'E', 'LogcatMonitorTest', 'error logcat monitor test message 5')] self.assertIterEqual(iter(expected_results), actual_results) def testFindAll_filterThreadId(self): test_log = _CreateTestLog( raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA) actual_results = test_log.FindAll( r'\S* logcat monitor test message \d', thread_id=2109) expected_results = [ ('9012', '2109', 'I', 'LogcatMonitorTest', 'info logcat monitor test message 3')] self.assertIterEqual(iter(expected_results), actual_results) def testFindAll_filterLogLevel(self): test_log = _CreateTestLog( raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA) actual_results = test_log.FindAll( r'\S* logcat monitor test message \d', log_level=r'[DW]') expected_results = [ ('8901', '1098', 'D', 'LogcatMonitorTest', 'debug logcat monitor test message 2'), ('0123', '3210', 'W', 'LogcatMonitorTest', 'warning logcat monitor test message 4'),] self.assertIterEqual(iter(expected_results), actual_results) def testFindAll_filterComponent(self): test_log = _CreateTestLog( raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA) actual_results = test_log.FindAll(r'.*', component='LogcatMonitorTest') expected_results = [ ('7890', '0987', 'V', 'LogcatMonitorTest', 'verbose logcat monitor test message 1'), ('8901', '1098', 'D', 'LogcatMonitorTest', 'debug logcat monitor test message 2'), ('9012', '2109', 'I', 'LogcatMonitorTest', 'info logcat monitor test message 3'), ('0123', '3210', 'W', 'LogcatMonitorTest', 'warning logcat monitor test message 4'), ('1234', '4321', 'E', 'LogcatMonitorTest', 'error logcat monitor test message 5'), ('2345', '5432', 'F', 'LogcatMonitorTest', 'fatal logcat monitor test message 6'), ('3456', '6543', 'D', 'LogcatMonitorTest', 'ignore me'),] self.assertIterEqual(iter(expected_results), actual_results) if __name__ == '__main__': unittest.main(verbosity=2)
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 6900, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 3, 4287, 26, 3507, 29, 6798, 13, 2732, 199, 199, 646, 7975, 199, 646, 747, 199, 646, 984, 199, 646, 2882, 199, 199, 504, 4866, 382, 14, 6238, 492, 943, 3385, 63, 7157, 199, 504, 4866, 382, 14, 6238, 14, 9277, 492, 28173, 63, 5029, 199, 504, 29219, 492, 5262, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 515, 14, 904, 8, 272, 5262, 14, 3022, 63, 10187, 63, 5441, 12, 283, 11470, 63, 7522, 297, 283, 647, 1805, 1333, 199, 646, 1683, 327, 4287, 26, 3507, 29, 38, 28025, 421, 199, 318, 485, 2499, 774, 2445, 8, 1773, 63, 793, 3385, 29, 403, 304, 523, 511, 63, 13741, 275, 28173, 63, 5029, 14, 33, 697, 4590, 360, 11371, 10678, 358, 523, 511, 63, 13741, 14, 2445, 3385, 275, 1683, 14, 3346, 8, 1107, 63, 585, 2687, 76, 367, 634, 315, 3066, 63, 793, 3385, 430, 523, 511, 63, 793, 275, 943, 3385, 63, 7157, 14, 2445, 3385, 13189, 8, 396, 63, 13741, 12, 5436, 29, 797, 9, 523, 372, 511, 63, 793, 421, 199, 533, 5297, 3385, 13189, 774, 8, 2796, 14, 1746, 304, 819, 485, 2864, 63, 16103, 4961, 63, 4947, 11206, 63, 3998, 275, 359, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 11419, 221, 1520, 13173, 221, 21798, 1555, 812, 5297, 3385, 13189, 774, 26, 283, 288, 283, 3832, 943, 3385, 8372, 511, 1245, 413, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 27603, 221, 17838, 614, 221, 1616, 2905, 577, 5297, 3385, 13189, 774, 26, 283, 288, 283, 1757, 943, 3385, 8372, 511, 1245, 499, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 28645, 221, 1749, 11533, 221, 499, 6996, 473, 5297, 3385, 13189, 774, 26, 283, 288, 283, 815, 943, 3385, 8372, 511, 1245, 650, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 28976, 221, 378, 4288, 221, 4337, 709, 644, 5297, 3385, 13189, 774, 26, 283, 288, 283, 3764, 943, 3385, 8372, 511, 1245, 841, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 30231, 221, 14763, 221, 841, 12638, 662, 5297, 3385, 13189, 774, 26, 283, 288, 283, 705, 943, 3385, 8372, 511, 1245, 959, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 26127, 221, 499, 9908, 221, 959, 10657, 481, 5297, 3385, 13189, 774, 26, 283, 288, 283, 16208, 943, 3385, 8372, 511, 1245, 1227, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 24509, 221, 8177, 1367, 221, 1227, 20103, 577, 5297, 3385, 13189, 774, 26, 283, 288, 283, 4247, 562, 297, 61, 819, 347, 702, 3315, 591, 8, 277, 12, 1420, 63, 1661, 12, 3503, 63, 1661, 304, 272, 367, 1420, 12, 3503, 315, 7975, 14, 565, 711, 63, 20820, 8, 2062, 63, 1661, 12, 3503, 63, 1661, 304, 489, 291, 14, 10389, 8, 881, 1420, 12, 881, 1499, 534, 6514, 965, 10537, 4008, 6617, 543, 450, 83, 7, 450, 620, 8, 6514, 430, 489, 291, 14, 10389, 8, 881, 3503, 12, 881, 1499, 534, 6514, 365, 4124, 4008, 6617, 543, 450, 83, 7, 450, 620, 8, 2062, 430, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 4687, 63, 344, 659, 1420, 59, 16, 566, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 2671, 63, 344, 659, 1420, 59, 17, 566, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 793, 63, 1896, 659, 1420, 59, 18, 566, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 3173, 659, 1420, 59, 19, 566, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 1188, 659, 1420, 59, 20, 566, 339, 543, 291, 14, 1855, 8, 30139, 304, 489, 2163, 8, 6514, 63, 1661, 9, 272, 543, 291, 14, 1855, 8, 30139, 304, 489, 2163, 8, 2062, 63, 1661, 9, 819, 347, 511, 21433, 63, 3742, 8, 277, 304, 272, 511, 63, 793, 275, 485, 2499, 774, 2445, 8, 267, 3066, 63, 793, 3385, 29, 466, 8, 277, 10445, 2864, 63, 16103, 4961, 63, 4947, 11206, 63, 3998, 9, 272, 3503, 63, 1431, 275, 511, 63, 793, 14, 21433, 8, 82, 1370, 5830, 16208, 92, 705, 9, 943, 3385, 8372, 16110, 488, 9, 272, 291, 14, 1815, 8, 6514, 63, 1431, 9, 272, 291, 14, 629, 8, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 30231, 221, 14763, 221, 841, 12638, 662, 5297, 3385, 13189, 774, 26, 283, 288, 283, 705, 943, 3385, 8372, 511, 1245, 959, 297, 267, 3503, 63, 1431, 14, 923, 8, 16, 430, 272, 291, 14, 629, 360, 705, 297, 3503, 63, 1431, 14, 923, 8, 17, 430, 819, 347, 511, 21433, 63, 5328, 8, 277, 304, 272, 511, 63, 793, 275, 485, 2499, 774, 2445, 8, 267, 3066, 63, 793, 3385, 29, 466, 8, 277, 10445, 2864, 63, 16103, 4961, 63, 4947, 11206, 63, 3998, 9, 272, 3503, 63, 1431, 275, 511, 63, 793, 14, 21433, 8, 267, 519, 24898, 5713, 22318, 12939, 16110, 519, 1370, 5830, 16208, 92, 705, 9, 943, 3385, 8372, 24915, 272, 291, 14, 7702, 8, 6514, 63, 1431, 9, 819, 347, 511, 6591, 2422, 63, 4322, 8, 277, 304, 272, 511, 63, 793, 275, 485, 2499, 774, 2445, 8, 267, 3066, 63, 793, 3385, 29, 466, 8, 277, 10445, 2864, 63, 16103, 4961, 63, 4947, 11206, 63, 3998, 9, 272, 1420, 63, 2604, 275, 359, 267, 661, 23, 13173, 297, 283, 1643, 1555, 297, 283, 54, 297, 283, 2445, 3385, 13189, 774, 297, 268, 283, 3832, 943, 3385, 8372, 511, 1245, 413, 659, 267, 661, 1407, 614, 297, 283, 709, 2905, 297, 283, 36, 297, 283, 2445, 3385, 13189, 774, 297, 268, 283, 1757, 943, 3385, 8372, 511, 1245, 499, 659, 267, 661, 25, 11533, 297, 283, 18, 6996, 297, 283, 41, 297, 283, 2445, 3385, 13189, 774, 297, 268, 283, 815, 943, 3385, 8372, 511 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 6900, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 3, 4287, 26, 3507, 29, 6798, 13, 2732, 199, 199, 646, 7975, 199, 646, 747, 199, 646, 984, 199, 646, 2882, 199, 199, 504, 4866, 382, 14, 6238, 492, 943, 3385, 63, 7157, 199, 504, 4866, 382, 14, 6238, 14, 9277, 492, 28173, 63, 5029, 199, 504, 29219, 492, 5262, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 515, 14, 904, 8, 272, 5262, 14, 3022, 63, 10187, 63, 5441, 12, 283, 11470, 63, 7522, 297, 283, 647, 1805, 1333, 199, 646, 1683, 327, 4287, 26, 3507, 29, 38, 28025, 421, 199, 318, 485, 2499, 774, 2445, 8, 1773, 63, 793, 3385, 29, 403, 304, 523, 511, 63, 13741, 275, 28173, 63, 5029, 14, 33, 697, 4590, 360, 11371, 10678, 358, 523, 511, 63, 13741, 14, 2445, 3385, 275, 1683, 14, 3346, 8, 1107, 63, 585, 2687, 76, 367, 634, 315, 3066, 63, 793, 3385, 430, 523, 511, 63, 793, 275, 943, 3385, 63, 7157, 14, 2445, 3385, 13189, 8, 396, 63, 13741, 12, 5436, 29, 797, 9, 523, 372, 511, 63, 793, 421, 199, 533, 5297, 3385, 13189, 774, 8, 2796, 14, 1746, 304, 819, 485, 2864, 63, 16103, 4961, 63, 4947, 11206, 63, 3998, 275, 359, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 11419, 221, 1520, 13173, 221, 21798, 1555, 812, 5297, 3385, 13189, 774, 26, 283, 288, 283, 3832, 943, 3385, 8372, 511, 1245, 413, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 27603, 221, 17838, 614, 221, 1616, 2905, 577, 5297, 3385, 13189, 774, 26, 283, 288, 283, 1757, 943, 3385, 8372, 511, 1245, 499, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 28645, 221, 1749, 11533, 221, 499, 6996, 473, 5297, 3385, 13189, 774, 26, 283, 288, 283, 815, 943, 3385, 8372, 511, 1245, 650, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 28976, 221, 378, 4288, 221, 4337, 709, 644, 5297, 3385, 13189, 774, 26, 283, 288, 283, 3764, 943, 3385, 8372, 511, 1245, 841, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 30231, 221, 14763, 221, 841, 12638, 662, 5297, 3385, 13189, 774, 26, 283, 288, 283, 705, 943, 3385, 8372, 511, 1245, 959, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 26127, 221, 499, 9908, 221, 959, 10657, 481, 5297, 3385, 13189, 774, 26, 283, 288, 283, 16208, 943, 3385, 8372, 511, 1245, 1227, 297, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 24509, 221, 8177, 1367, 221, 1227, 20103, 577, 5297, 3385, 13189, 774, 26, 283, 288, 283, 4247, 562, 297, 61, 819, 347, 702, 3315, 591, 8, 277, 12, 1420, 63, 1661, 12, 3503, 63, 1661, 304, 272, 367, 1420, 12, 3503, 315, 7975, 14, 565, 711, 63, 20820, 8, 2062, 63, 1661, 12, 3503, 63, 1661, 304, 489, 291, 14, 10389, 8, 881, 1420, 12, 881, 1499, 534, 6514, 965, 10537, 4008, 6617, 543, 450, 83, 7, 450, 620, 8, 6514, 430, 489, 291, 14, 10389, 8, 881, 3503, 12, 881, 1499, 534, 6514, 365, 4124, 4008, 6617, 543, 450, 83, 7, 450, 620, 8, 2062, 430, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 4687, 63, 344, 659, 1420, 59, 16, 566, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 2671, 63, 344, 659, 1420, 59, 17, 566, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 793, 63, 1896, 659, 1420, 59, 18, 566, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 3173, 659, 1420, 59, 19, 566, 489, 291, 14, 629, 8, 6514, 14, 923, 360, 1188, 659, 1420, 59, 20, 566, 339, 543, 291, 14, 1855, 8, 30139, 304, 489, 2163, 8, 6514, 63, 1661, 9, 272, 543, 291, 14, 1855, 8, 30139, 304, 489, 2163, 8, 2062, 63, 1661, 9, 819, 347, 511, 21433, 63, 3742, 8, 277, 304, 272, 511, 63, 793, 275, 485, 2499, 774, 2445, 8, 267, 3066, 63, 793, 3385, 29, 466, 8, 277, 10445, 2864, 63, 16103, 4961, 63, 4947, 11206, 63, 3998, 9, 272, 3503, 63, 1431, 275, 511, 63, 793, 14, 21433, 8, 82, 1370, 5830, 16208, 92, 705, 9, 943, 3385, 8372, 16110, 488, 9, 272, 291, 14, 1815, 8, 6514, 63, 1431, 9, 272, 291, 14, 629, 8, 267, 283, 614, 13, 614, 17163, 26, 996, 26, 1644, 14, 30231, 221, 14763, 221, 841, 12638, 662, 5297, 3385, 13189, 774, 26, 283, 288, 283, 705, 943, 3385, 8372, 511, 1245, 959, 297, 267, 3503, 63, 1431, 14, 923, 8, 16, 430, 272, 291, 14, 629, 360, 705, 297, 3503, 63, 1431, 14, 923, 8, 17, 430, 819, 347, 511, 21433, 63, 5328, 8, 277, 304, 272, 511, 63, 793, 275, 485, 2499, 774, 2445, 8, 267, 3066, 63, 793, 3385, 29, 466, 8, 277, 10445, 2864, 63, 16103, 4961, 63, 4947, 11206, 63, 3998, 9, 272, 3503, 63, 1431, 275, 511, 63, 793, 14, 21433, 8, 267, 519, 24898, 5713, 22318, 12939, 16110, 519, 1370, 5830, 16208, 92, 705, 9, 943, 3385, 8372, 24915, 272, 291, 14, 7702, 8, 6514, 63, 1431, 9, 819, 347, 511, 6591, 2422, 63, 4322, 8, 277, 304, 272, 511, 63, 793, 275, 485, 2499, 774, 2445, 8, 267, 3066, 63, 793, 3385, 29, 466, 8, 277, 10445, 2864, 63, 16103, 4961, 63, 4947, 11206, 63, 3998, 9, 272, 1420, 63, 2604, 275, 359, 267, 661, 23, 13173, 297, 283, 1643, 1555, 297, 283, 54, 297, 283, 2445, 3385, 13189, 774, 297, 268, 283, 3832, 943, 3385, 8372, 511, 1245, 413, 659, 267, 661, 1407, 614, 297, 283, 709, 2905, 297, 283, 36, 297, 283, 2445, 3385, 13189, 774, 297, 268, 283, 1757, 943, 3385, 8372, 511, 1245, 499, 659, 267, 661, 25, 11533, 297, 283, 18, 6996, 297, 283, 41, 297, 283, 2445, 3385, 13189, 774, 297, 268, 283, 815, 943, 3385, 8372, 511, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ehealthafrica-ci/onadata
onadata/apps/viewer/migrations/0017_remove_odk_prefix.py
13
12530
# -*- coding: utf-8 -*- from south.db import db from south.v2 import SchemaMigration from onadata.libs.data.db import rename_table_pending_creates class Migration(SchemaMigration): def forwards(self, orm): db.rename_table('odk_viewer_columnrename', 'viewer_columnrename') db.rename_table('odk_viewer_export', 'viewer_export') db.rename_table('odk_viewer_instancemodification', 'viewer_instancemodification') db.rename_table('odk_viewer_parsedinstance', 'viewer_parsedinstance') rename_table_pending_creates('odk_viewer', 'viewer') def backwards(self, orm): db.rename_table('viewer_columnrename', 'odk_viewer_columnrename') db.rename_table('viewer_export', 'odk_viewer_export') db.rename_table('viewer_instancemodification', 'viewer_instancemodification') db.rename_table('viewer_parsedinstance', 'odk_viewer_parsedinstance') models = { u'auth.group': { 'Meta': {'object_name': 'Group'}, u'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': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) }, u'auth.permission': { 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, u'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': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), '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': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) }, u'contenttypes.contenttype': { 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), u'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'}) }, 'logger.instance': { 'Meta': {'object_name': 'Instance'}, 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'date_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), 'deleted_at': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'null': 'True'}), 'geom': ('django.contrib.gis.db.models.fields.GeometryCollectionField', [], {'null': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'json': ('jsonfield.fields.JSONField', [], {'default': '{}'}), 'status': ('django.db.models.fields.CharField', [], {'default': "u'submitted_via_web'", 'max_length': '20'}), 'survey_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['logger.SurveyType']"}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'instances'", 'null': 'True', 'to': u"orm['auth.User']"}), 'uuid': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '249'}), 'xform': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'instances'", 'null': 'True', 'to': "orm['logger.XForm']"}), 'xml': ('django.db.models.fields.TextField', [], {}) }, 'logger.surveytype': { 'Meta': {'object_name': 'SurveyType'}, u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'slug': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}) }, 'logger.xform': { 'Meta': {'ordering': "('id_string',)", 'unique_together': "(('user', 'id_string'), ('user', 'sms_id_string'))", 'object_name': 'XForm'}, 'allows_sms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'bamboo_dataset': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '60'}), 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'date_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), 'description': ('django.db.models.fields.TextField', [], {'default': "u''", 'null': 'True'}), 'downloadable': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'encrypted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'has_start_time': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'id_string': ('django.db.models.fields.SlugField', [], {'max_length': '100'}), 'instances_with_geopoints': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'is_crowd_form': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'json': ('django.db.models.fields.TextField', [], {'default': "u''"}), 'last_submission_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), 'num_of_submissions': ('django.db.models.fields.IntegerField', [], {'default': '-1'}), 'shared': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'shared_data': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'sms_id_string': ('django.db.models.fields.SlugField', [], {'default': "''", 'max_length': '100'}), 'title': ('django.db.models.fields.CharField', [], {'max_length': '64'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'xforms'", 'null': 'True', 'to': u"orm['auth.User']"}), 'uuid': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '32'}), 'xls': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True'}), 'xml': ('django.db.models.fields.TextField', [], {}) }, u'taggit.tag': { 'Meta': {'object_name': 'Tag'}, u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}), 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'}) }, u'taggit.taggeditem': { 'Meta': {'object_name': 'TaggedItem'}, 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'taggit_taggeditem_tagged_items'", 'to': u"orm['contenttypes.ContentType']"}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}), 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'taggit_taggeditem_items'", 'to': u"orm['taggit.Tag']"}) }, 'viewer.columnrename': { 'Meta': {'object_name': 'ColumnRename'}, 'column_name': ('django.db.models.fields.CharField', [], {'max_length': '32'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'xpath': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}) }, 'viewer.export': { 'Meta': {'unique_together': "(('xform', 'filename'),)", 'object_name': 'Export'}, 'created_on': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'auto_now_add': 'True', 'blank': 'True'}), 'export_type': ('django.db.models.fields.CharField', [], {'default': "'xls'", 'max_length': '10'}), 'export_url': ('django.db.models.fields.URLField', [], {'default': 'None', 'max_length': '200', 'null': 'True'}), 'filedir': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'filename': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'internal_status': ('django.db.models.fields.SmallIntegerField', [], {'default': '0', 'max_length': '1'}), 'task_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'time_of_last_submission': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'null': 'True'}), 'xform': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['logger.XForm']"}) }, 'viewer.instancemodification': { 'Meta': {'object_name': 'InstanceModification'}, 'action': ('django.db.models.fields.CharField', [], {'max_length': '50'}), 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'date_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'instance': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'modifications'", 'to': "orm['logger.Instance']"}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True'}), 'xpath': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, 'viewer.parsedinstance': { 'Meta': {'object_name': 'ParsedInstance'}, 'end_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'instance': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'parsed_instance'", 'unique': 'True', 'to': "orm['logger.Instance']"}), 'lat': ('django.db.models.fields.FloatField', [], {'null': 'True'}), 'lng': ('django.db.models.fields.FloatField', [], {'null': 'True'}), 'start_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}) } } complete_apps = ['viewer']
bsd-2-clause
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 12919, 14, 697, 492, 1592, 199, 504, 12919, 14, 86, 18, 492, 24765, 199, 199, 504, 641, 1517, 14, 8450, 14, 576, 14, 697, 492, 11441, 63, 1224, 63, 6455, 63, 28219, 421, 199, 533, 12090, 8, 24822, 304, 339, 347, 17465, 8, 277, 12, 9813, 304, 267, 1592, 14, 8165, 63, 1224, 360, 364, 75, 63, 16645, 63, 2301, 8165, 297, 283, 16645, 63, 2301, 8165, 358, 267, 1592, 14, 8165, 63, 1224, 360, 364, 75, 63, 16645, 63, 3790, 297, 283, 16645, 63, 3790, 358, 267, 1592, 14, 8165, 63, 1224, 360, 364, 75, 63, 16645, 63, 842, 20945, 297, 2432, 283, 16645, 63, 842, 20945, 358, 267, 1592, 14, 8165, 63, 1224, 360, 364, 75, 63, 16645, 63, 6751, 842, 297, 283, 16645, 63, 6751, 842, 358, 398, 11441, 63, 1224, 63, 6455, 63, 28219, 360, 364, 75, 63, 16645, 297, 283, 16645, 358, 339, 347, 8552, 8, 277, 12, 9813, 304, 267, 1592, 14, 8165, 63, 1224, 360, 16645, 63, 2301, 8165, 297, 283, 364, 75, 63, 16645, 63, 2301, 8165, 358, 267, 1592, 14, 8165, 63, 1224, 360, 16645, 63, 3790, 297, 283, 364, 75, 63, 16645, 63, 3790, 358, 267, 1592, 14, 8165, 63, 1224, 360, 16645, 63, 842, 20945, 297, 2432, 283, 16645, 63, 842, 20945, 358, 267, 1592, 14, 8165, 63, 1224, 360, 16645, 63, 6751, 842, 297, 283, 364, 75, 63, 16645, 63, 6751, 842, 358, 339, 1709, 275, 469, 267, 399, 7, 1178, 14, 923, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 2448, 2267, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 3235, 356, 283, 549, 297, 283, 988, 63, 1267, 356, 283, 1257, 1604, 288, 283, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 3071, 267, 1660, 267, 399, 7, 1178, 14, 5693, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 7340, 85, 7, 1317, 63, 466, 363, 571, 63, 1302, 297, 399, 7, 1317, 63, 466, 363, 1238, 297, 399, 7, 11879, 18106, 283, 3235, 63, 6314, 356, 298, 1332, 85, 7, 1317, 63, 466, 297, 399, 7, 11879, 9878, 283, 785, 63, 354, 356, 283, 7980, 2267, 288, 283, 11879, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 1317, 63, 466, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 10778, 14, 11282, 6097, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1400, 3071, 267, 1660, 267, 399, 7, 1178, 14, 751, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 1899, 2267, 288, 283, 602, 63, 11806, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2123, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 297, 990, 791, 988, 63, 1267, 356, 283, 2194, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2246, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2634, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 1178, 14, 2448, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 1604, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 374, 63, 2682, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 549, 1604, 288, 283, 374, 63, 7018, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 374, 63, 11434, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 2019, 63, 2886, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2019, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 3933, 1604, 288, 283, 751, 63, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2473, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 3235, 356, 283, 549, 297, 283, 988, 63, 1267, 356, 283, 1216, 3071, 267, 1660, 267, 399, 7, 10778, 14, 20735, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 354, 21099, 283, 3235, 63, 6314, 356, 9510, 571, 63, 1302, 297, 283, 1238, 9878, 283, 785, 63, 354, 356, 283, 11282, 297, 283, 697, 63, 1224, 356, 3546, 1176, 63, 1317, 63, 466, 15208, 288, 283, 571, 63, 1302, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 399, 7, 344 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 12919, 14, 697, 492, 1592, 199, 504, 12919, 14, 86, 18, 492, 24765, 199, 199, 504, 641, 1517, 14, 8450, 14, 576, 14, 697, 492, 11441, 63, 1224, 63, 6455, 63, 28219, 421, 199, 533, 12090, 8, 24822, 304, 339, 347, 17465, 8, 277, 12, 9813, 304, 267, 1592, 14, 8165, 63, 1224, 360, 364, 75, 63, 16645, 63, 2301, 8165, 297, 283, 16645, 63, 2301, 8165, 358, 267, 1592, 14, 8165, 63, 1224, 360, 364, 75, 63, 16645, 63, 3790, 297, 283, 16645, 63, 3790, 358, 267, 1592, 14, 8165, 63, 1224, 360, 364, 75, 63, 16645, 63, 842, 20945, 297, 2432, 283, 16645, 63, 842, 20945, 358, 267, 1592, 14, 8165, 63, 1224, 360, 364, 75, 63, 16645, 63, 6751, 842, 297, 283, 16645, 63, 6751, 842, 358, 398, 11441, 63, 1224, 63, 6455, 63, 28219, 360, 364, 75, 63, 16645, 297, 283, 16645, 358, 339, 347, 8552, 8, 277, 12, 9813, 304, 267, 1592, 14, 8165, 63, 1224, 360, 16645, 63, 2301, 8165, 297, 283, 364, 75, 63, 16645, 63, 2301, 8165, 358, 267, 1592, 14, 8165, 63, 1224, 360, 16645, 63, 3790, 297, 283, 364, 75, 63, 16645, 63, 3790, 358, 267, 1592, 14, 8165, 63, 1224, 360, 16645, 63, 842, 20945, 297, 2432, 283, 16645, 63, 842, 20945, 358, 267, 1592, 14, 8165, 63, 1224, 360, 16645, 63, 6751, 842, 297, 283, 364, 75, 63, 16645, 63, 6751, 842, 358, 339, 1709, 275, 469, 267, 399, 7, 1178, 14, 923, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 2448, 2267, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 3235, 356, 283, 549, 297, 283, 988, 63, 1267, 356, 283, 1257, 1604, 288, 283, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 3071, 267, 1660, 267, 399, 7, 1178, 14, 5693, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 7340, 85, 7, 1317, 63, 466, 363, 571, 63, 1302, 297, 399, 7, 1317, 63, 466, 363, 1238, 297, 399, 7, 11879, 18106, 283, 3235, 63, 6314, 356, 298, 1332, 85, 7, 1317, 63, 466, 297, 399, 7, 11879, 9878, 283, 785, 63, 354, 356, 283, 7980, 2267, 288, 283, 11879, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 1317, 63, 466, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 10778, 14, 11282, 6097, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1400, 3071, 267, 1660, 267, 399, 7, 1178, 14, 751, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 1899, 2267, 288, 283, 602, 63, 11806, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2123, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 297, 990, 791, 988, 63, 1267, 356, 283, 2194, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2246, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2634, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 1178, 14, 2448, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 1604, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 374, 63, 2682, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 549, 1604, 288, 283, 374, 63, 7018, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 374, 63, 11434, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 2019, 63, 2886, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2019, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 3933, 1604, 288, 283, 751, 63, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2473, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 3235, 356, 283, 549, 297, 283, 988, 63, 1267, 356, 283, 1216, 3071, 267, 1660, 267, 399, 7, 10778, 14, 20735, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 354, 21099, 283, 3235, 63, 6314, 356, 9510, 571, 63, 1302, 297, 283, 1238, 9878, 283, 785, 63, 354, 356, 283, 11282, 297, 283, 697, 63, 1224, 356, 3546, 1176, 63, 1317, 63, 466, 15208, 288, 283, 571, 63, 1302, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 399, 7, 344, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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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 ]
chuan9/chromium-crosswalk
chrome/test/chromedriver/test/webserver.py
68
6705
# Copyright 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import BaseHTTPServer import os import threading class Responder(object): """Sends a HTTP response. Used with TestWebServer.""" def __init__(self, handler): self._handler = handler def SendResponse(self, body): """Sends OK response with body.""" self.SendHeaders(len(body)) self.SendBody(body) def SendResponseFromFile(self, path): """Sends OK response with the given file as the body.""" with open(path, 'r') as f: self.SendResponse(f.read()) def SendHeaders(self, content_length=None): """Sends headers for OK response.""" self._handler.send_response(200) if content_length: self._handler.send_header('Content-Length', content_length) self._handler.end_headers() def SendError(self, code): """Sends response for the given HTTP error code.""" self._handler.send_error(code) def SendBody(self, body): """Just sends the body, no headers.""" self._handler.wfile.write(body) class Request(object): """An HTTP request.""" def __init__(self, handler): self._handler = handler def GetPath(self): return self._handler.path def GetHeader(self, name): return self._handler.headers.getheader(name) class _BaseServer(BaseHTTPServer.HTTPServer): """Internal server that throws if timed out waiting for a request.""" def __init__(self, on_request, server_cert_and_key_path=None): """Starts the server. It is an HTTP server if parameter server_cert_and_key_path is not provided. Otherwise, it is an HTTPS server. Args: server_cert_and_key_path: path to a PEM file containing the cert and key. if it is None, start the server as an HTTP one. """ class _Handler(BaseHTTPServer.BaseHTTPRequestHandler): """Internal handler that just asks the server to handle the request.""" def do_GET(self): if self.path.endswith('favicon.ico'): self.send_error(404) return on_request(Request(self), Responder(self)) def log_message(self, *args, **kwargs): """Overriddes base class method to disable logging.""" pass BaseHTTPServer.HTTPServer.__init__(self, ('127.0.0.1', 0), _Handler) if server_cert_and_key_path is not None: self._is_https_enabled = True self._server.socket = ssl.wrap_socket( self._server.socket, certfile=server_cert_and_key_path, server_side=True) else: self._is_https_enabled = False def handle_timeout(self): """Overridden from SocketServer.""" raise RuntimeError('Timed out waiting for http request') def GetUrl(self): """Returns the base URL of the server.""" postfix = '://127.0.0.1:%s' % self.server_port if self._is_https_enabled: return 'https' + postfix return 'http' + postfix class WebServer(object): """An HTTP or HTTPS server that serves on its own thread. Serves files from given directory but may use custom data for specific paths. """ def __init__(self, root_dir, server_cert_and_key_path=None): """Starts the server. It is an HTTP server if parameter server_cert_and_key_path is not provided. Otherwise, it is an HTTPS server. Args: root_dir: root path to serve files from. This parameter is required. server_cert_and_key_path: path to a PEM file containing the cert and key. if it is None, start the server as an HTTP one. """ self._root_dir = os.path.abspath(root_dir) self._server = _BaseServer(self._OnRequest, server_cert_and_key_path) self._thread = threading.Thread(target=self._server.serve_forever) self._thread.daemon = True self._thread.start() self._path_data_map = {} self._path_callback_map = {} self._path_maps_lock = threading.Lock() def _OnRequest(self, request, responder): path = request.GetPath().split('?')[0] # Serve from path -> callback and data maps. self._path_maps_lock.acquire() try: if path in self._path_callback_map: body = self._path_callback_map[path](request) if body: responder.SendResponse(body) else: responder.SendError(503) return if path in self._path_data_map: responder.SendResponse(self._path_data_map[path]) return finally: self._path_maps_lock.release() # Serve from file. path = os.path.normpath( os.path.join(self._root_dir, *path.split('/'))) if not path.startswith(self._root_dir): responder.SendError(403) return if not os.path.exists(path): responder.SendError(404) return responder.SendResponseFromFile(path) def SetDataForPath(self, path, data): self._path_maps_lock.acquire() try: self._path_data_map[path] = data finally: self._path_maps_lock.release() def SetCallbackForPath(self, path, func): self._path_maps_lock.acquire() try: self._path_callback_map[path] = func finally: self._path_maps_lock.release() def GetUrl(self): """Returns the base URL of the server.""" return self._server.GetUrl() def Shutdown(self): """Shuts down the server synchronously.""" self._server.shutdown() self._thread.join() class SyncWebServer(object): """WebServer for testing. Incoming requests are blocked until explicitly handled. This was designed for single thread use. All requests should be handled on the same thread. """ def __init__(self): self._server = _BaseServer(self._OnRequest) # Recognized by SocketServer. self._server.timeout = 10 self._on_request = None def _OnRequest(self, request, responder): self._on_request(responder) self._on_request = None def Respond(self, on_request): """Blocks until request comes in, then calls given handler function. Args: on_request: Function that handles the request. Invoked with single parameter, an instance of Responder. """ if self._on_request: raise RuntimeError('Must handle 1 request at a time.') self._on_request = on_request while self._on_request: # Don't use handle_one_request, because it won't work with the timeout. self._server.handle_request() def RespondWithContent(self, content): """Blocks until request comes in, then handles it with the given content.""" def SendContent(responder): responder.SendResponse(content) self.Respond(SendContent) def GetUrl(self): return self._server.GetUrl()
bsd-3-clause
[ 3, 1898, 6171, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 646, 3523, 14938, 199, 646, 747, 199, 646, 5796, 421, 199, 533, 3591, 23621, 8, 785, 304, 523, 408, 26276, 282, 3101, 1177, 14, 8051, 543, 1379, 5926, 3120, 1041, 819, 347, 636, 826, 721, 277, 12, 3016, 304, 272, 291, 423, 2232, 275, 3016, 819, 347, 10217, 2364, 8, 277, 12, 2396, 304, 272, 408, 26276, 9949, 1177, 543, 2396, 1041, 272, 291, 14, 6795, 9883, 8, 552, 8, 2030, 430, 272, 291, 14, 6795, 8173, 8, 2030, 9, 819, 347, 10217, 2364, 26637, 8, 277, 12, 931, 304, 272, 408, 26276, 9949, 1177, 543, 314, 1627, 570, 465, 314, 2396, 1041, 272, 543, 1551, 8, 515, 12, 283, 82, 358, 465, 289, 26, 489, 291, 14, 6795, 2364, 8, 70, 14, 739, 1012, 819, 347, 10217, 9883, 8, 277, 12, 1564, 63, 1267, 29, 403, 304, 272, 408, 26276, 2323, 367, 9949, 1177, 1041, 272, 291, 423, 2232, 14, 2254, 63, 1310, 8, 1840, 9, 272, 340, 1564, 63, 1267, 26, 489, 291, 423, 2232, 14, 2254, 63, 1291, 360, 2714, 13, 4625, 297, 1564, 63, 1267, 9, 272, 291, 423, 2232, 14, 500, 63, 2139, 342, 819, 347, 10217, 547, 8, 277, 12, 1233, 304, 272, 408, 26276, 1177, 367, 314, 1627, 3101, 1125, 1233, 1041, 272, 291, 423, 2232, 14, 2254, 63, 705, 8, 600, 9, 819, 347, 10217, 8173, 8, 277, 12, 2396, 304, 272, 408, 22850, 16178, 314, 2396, 12, 949, 2323, 1041, 272, 291, 423, 2232, 14, 18076, 14, 952, 8, 2030, 9, 421, 199, 533, 4784, 8, 785, 304, 523, 408, 2493, 3101, 1056, 1041, 819, 347, 636, 826, 721, 277, 12, 3016, 304, 272, 291, 423, 2232, 275, 3016, 819, 347, 2372, 2042, 8, 277, 304, 272, 372, 291, 423, 2232, 14, 515, 819, 347, 2372, 2567, 8, 277, 12, 536, 304, 272, 372, 291, 423, 2232, 14, 2139, 14, 19958, 8, 354, 9, 421, 199, 533, 485, 1563, 3120, 8, 1563, 14938, 14, 14938, 304, 523, 408, 8405, 1654, 626, 24266, 340, 18590, 734, 10923, 367, 282, 1056, 1041, 819, 347, 636, 826, 721, 277, 12, 641, 63, 1069, 12, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 29, 403, 304, 272, 408, 32142, 314, 1654, 14, 339, 2779, 365, 376, 3101, 1654, 340, 2725, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 365, 440, 2741, 14, 272, 6630, 12, 652, 365, 376, 14147, 1654, 14, 339, 3033, 26, 489, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 26, 931, 370, 282, 25957, 570, 3035, 314, 6250, 436, 790, 14, 1816, 340, 652, 365, 488, 12, 1343, 314, 1654, 465, 376, 3101, 1373, 14, 272, 408, 272, 1021, 485, 2461, 8, 1563, 14938, 14, 1563, 23518, 304, 489, 408, 8405, 3016, 626, 2951, 465, 6080, 314, 1654, 370, 2429, 314, 1056, 1041, 2541, 347, 886, 63, 2970, 8, 277, 304, 267, 340, 291, 14, 515, 14, 4130, 360, 22229, 14, 12802, 735, 881, 291, 14, 2254, 63, 705, 8, 5188, 9, 881, 372, 267, 641, 63, 1069, 8, 2017, 8, 277, 395, 3591, 23621, 8, 277, 430, 2541, 347, 943, 63, 1188, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 408, 5674, 1677, 3424, 1300, 1021, 1083, 370, 3507, 2050, 1041, 267, 986, 339, 3523, 14938, 14, 14938, 855, 826, 721, 277, 12, 661, 4195, 14, 16, 14, 16, 14, 17, 297, 378, 395, 485, 2461, 9, 339, 340, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 365, 440, 488, 26, 489, 291, 423, 374, 63, 2859, 63, 3827, 275, 715, 489, 291, 423, 1000, 14, 3450, 275, 6149, 14, 3823, 63, 3450, 8, 881, 291, 423, 1000, 14, 3450, 12, 27660, 29, 1000, 63, 4736, 63, 460, 63, 498, 63, 515, 12, 881, 1654, 63, 2441, 29, 549, 9, 272, 587, 26, 489, 291, 423, 374, 63, 2859, 63, 3827, 275, 756, 819, 347, 2429, 63, 2593, 8, 277, 304, 272, 408, 5674, 8639, 687, 17766, 3120, 1041, 272, 746, 6064, 360, 28682, 734, 10923, 367, 1455, 1056, 358, 819, 347, 2372, 6417, 8, 277, 304, 272, 408, 3407, 314, 1300, 2851, 402, 314, 1654, 1041, 272, 31478, 275, 283, 921, 4195, 14, 16, 14, 16, 14, 17, 2689, 83, 7, 450, 291, 14, 1000, 63, 719, 272, 340, 291, 423, 374, 63, 2859, 63, 3827, 26, 489, 372, 283, 2859, 7, 435, 31478, 272, 372, 283, 1014, 7, 435, 31478, 421, 199, 533, 6001, 3120, 8, 785, 304, 523, 408, 2493, 3101, 503, 14147, 1654, 626, 23739, 641, 2399, 5705, 2462, 14, 819, 3739, 2310, 1584, 687, 1627, 2082, 1325, 1443, 675, 3537, 666, 367, 2488, 3792, 14, 523, 408, 819, 347, 636, 826, 721, 277, 12, 1738, 63, 694, 12, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 29, 403, 304, 272, 408, 32142, 314, 1654, 14, 339, 2779, 365, 376, 3101, 1654, 340, 2725, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 365, 440, 2741, 14, 272, 6630, 12, 652, 365, 376, 14147, 1654, 14, 339, 3033, 26, 489, 1738, 63, 694, 26, 1738, 931, 370, 14062, 1584, 687, 14, 961, 2725, 365, 1415, 14, 489, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 26, 931, 370, 282, 25957, 570, 3035, 314, 6250, 436, 790, 14, 1816, 340, 652, 365, 488, 12, 1343, 314, 1654, 465, 376, 3101, 1373, 14, 272, 408, 272, 291, 423, 1231, 63, 694, 275, 747, 14, 515, 14, 4832, 8, 1231, 63, 694, 9, 272, 291, 423, 1000, 275, 485, 1563, 3120, 8, 277, 423, 3314, 2017, 12, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 9, 272, 291, 423, 2671, 275, 5796, 14, 4436, 8, 1375, 29, 277, 423, 1000, 14, 4909, 63, 21327, 9, 272, 291, 423, 2671, 14, 10824, 275, 715, 272, 291, 423, 2671, 14, 928, 342, 272, 291, 423, 515, 63, 576, 63, 1130, 275, 1052, 272, 291, 423, 515, 63, 3058, 63, 1130, 275, 1052, 272, 291, 423, 515, 63 ]
[ 1898, 6171, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 646, 3523, 14938, 199, 646, 747, 199, 646, 5796, 421, 199, 533, 3591, 23621, 8, 785, 304, 523, 408, 26276, 282, 3101, 1177, 14, 8051, 543, 1379, 5926, 3120, 1041, 819, 347, 636, 826, 721, 277, 12, 3016, 304, 272, 291, 423, 2232, 275, 3016, 819, 347, 10217, 2364, 8, 277, 12, 2396, 304, 272, 408, 26276, 9949, 1177, 543, 2396, 1041, 272, 291, 14, 6795, 9883, 8, 552, 8, 2030, 430, 272, 291, 14, 6795, 8173, 8, 2030, 9, 819, 347, 10217, 2364, 26637, 8, 277, 12, 931, 304, 272, 408, 26276, 9949, 1177, 543, 314, 1627, 570, 465, 314, 2396, 1041, 272, 543, 1551, 8, 515, 12, 283, 82, 358, 465, 289, 26, 489, 291, 14, 6795, 2364, 8, 70, 14, 739, 1012, 819, 347, 10217, 9883, 8, 277, 12, 1564, 63, 1267, 29, 403, 304, 272, 408, 26276, 2323, 367, 9949, 1177, 1041, 272, 291, 423, 2232, 14, 2254, 63, 1310, 8, 1840, 9, 272, 340, 1564, 63, 1267, 26, 489, 291, 423, 2232, 14, 2254, 63, 1291, 360, 2714, 13, 4625, 297, 1564, 63, 1267, 9, 272, 291, 423, 2232, 14, 500, 63, 2139, 342, 819, 347, 10217, 547, 8, 277, 12, 1233, 304, 272, 408, 26276, 1177, 367, 314, 1627, 3101, 1125, 1233, 1041, 272, 291, 423, 2232, 14, 2254, 63, 705, 8, 600, 9, 819, 347, 10217, 8173, 8, 277, 12, 2396, 304, 272, 408, 22850, 16178, 314, 2396, 12, 949, 2323, 1041, 272, 291, 423, 2232, 14, 18076, 14, 952, 8, 2030, 9, 421, 199, 533, 4784, 8, 785, 304, 523, 408, 2493, 3101, 1056, 1041, 819, 347, 636, 826, 721, 277, 12, 3016, 304, 272, 291, 423, 2232, 275, 3016, 819, 347, 2372, 2042, 8, 277, 304, 272, 372, 291, 423, 2232, 14, 515, 819, 347, 2372, 2567, 8, 277, 12, 536, 304, 272, 372, 291, 423, 2232, 14, 2139, 14, 19958, 8, 354, 9, 421, 199, 533, 485, 1563, 3120, 8, 1563, 14938, 14, 14938, 304, 523, 408, 8405, 1654, 626, 24266, 340, 18590, 734, 10923, 367, 282, 1056, 1041, 819, 347, 636, 826, 721, 277, 12, 641, 63, 1069, 12, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 29, 403, 304, 272, 408, 32142, 314, 1654, 14, 339, 2779, 365, 376, 3101, 1654, 340, 2725, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 365, 440, 2741, 14, 272, 6630, 12, 652, 365, 376, 14147, 1654, 14, 339, 3033, 26, 489, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 26, 931, 370, 282, 25957, 570, 3035, 314, 6250, 436, 790, 14, 1816, 340, 652, 365, 488, 12, 1343, 314, 1654, 465, 376, 3101, 1373, 14, 272, 408, 272, 1021, 485, 2461, 8, 1563, 14938, 14, 1563, 23518, 304, 489, 408, 8405, 3016, 626, 2951, 465, 6080, 314, 1654, 370, 2429, 314, 1056, 1041, 2541, 347, 886, 63, 2970, 8, 277, 304, 267, 340, 291, 14, 515, 14, 4130, 360, 22229, 14, 12802, 735, 881, 291, 14, 2254, 63, 705, 8, 5188, 9, 881, 372, 267, 641, 63, 1069, 8, 2017, 8, 277, 395, 3591, 23621, 8, 277, 430, 2541, 347, 943, 63, 1188, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 408, 5674, 1677, 3424, 1300, 1021, 1083, 370, 3507, 2050, 1041, 267, 986, 339, 3523, 14938, 14, 14938, 855, 826, 721, 277, 12, 661, 4195, 14, 16, 14, 16, 14, 17, 297, 378, 395, 485, 2461, 9, 339, 340, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 365, 440, 488, 26, 489, 291, 423, 374, 63, 2859, 63, 3827, 275, 715, 489, 291, 423, 1000, 14, 3450, 275, 6149, 14, 3823, 63, 3450, 8, 881, 291, 423, 1000, 14, 3450, 12, 27660, 29, 1000, 63, 4736, 63, 460, 63, 498, 63, 515, 12, 881, 1654, 63, 2441, 29, 549, 9, 272, 587, 26, 489, 291, 423, 374, 63, 2859, 63, 3827, 275, 756, 819, 347, 2429, 63, 2593, 8, 277, 304, 272, 408, 5674, 8639, 687, 17766, 3120, 1041, 272, 746, 6064, 360, 28682, 734, 10923, 367, 1455, 1056, 358, 819, 347, 2372, 6417, 8, 277, 304, 272, 408, 3407, 314, 1300, 2851, 402, 314, 1654, 1041, 272, 31478, 275, 283, 921, 4195, 14, 16, 14, 16, 14, 17, 2689, 83, 7, 450, 291, 14, 1000, 63, 719, 272, 340, 291, 423, 374, 63, 2859, 63, 3827, 26, 489, 372, 283, 2859, 7, 435, 31478, 272, 372, 283, 1014, 7, 435, 31478, 421, 199, 533, 6001, 3120, 8, 785, 304, 523, 408, 2493, 3101, 503, 14147, 1654, 626, 23739, 641, 2399, 5705, 2462, 14, 819, 3739, 2310, 1584, 687, 1627, 2082, 1325, 1443, 675, 3537, 666, 367, 2488, 3792, 14, 523, 408, 819, 347, 636, 826, 721, 277, 12, 1738, 63, 694, 12, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 29, 403, 304, 272, 408, 32142, 314, 1654, 14, 339, 2779, 365, 376, 3101, 1654, 340, 2725, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 365, 440, 2741, 14, 272, 6630, 12, 652, 365, 376, 14147, 1654, 14, 339, 3033, 26, 489, 1738, 63, 694, 26, 1738, 931, 370, 14062, 1584, 687, 14, 961, 2725, 365, 1415, 14, 489, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 26, 931, 370, 282, 25957, 570, 3035, 314, 6250, 436, 790, 14, 1816, 340, 652, 365, 488, 12, 1343, 314, 1654, 465, 376, 3101, 1373, 14, 272, 408, 272, 291, 423, 1231, 63, 694, 275, 747, 14, 515, 14, 4832, 8, 1231, 63, 694, 9, 272, 291, 423, 1000, 275, 485, 1563, 3120, 8, 277, 423, 3314, 2017, 12, 1654, 63, 4736, 63, 460, 63, 498, 63, 515, 9, 272, 291, 423, 2671, 275, 5796, 14, 4436, 8, 1375, 29, 277, 423, 1000, 14, 4909, 63, 21327, 9, 272, 291, 423, 2671, 14, 10824, 275, 715, 272, 291, 423, 2671, 14, 928, 342, 272, 291, 423, 515, 63, 576, 63, 1130, 275, 1052, 272, 291, 423, 515, 63, 3058, 63, 1130, 275, 1052, 272, 291, 423, 515, 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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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 ]
entropy1337/infernal-twin
Modules/build/pip/build/lib.linux-i686-2.7/pip/utils/ui.py
316
6774
from __future__ import absolute_import from __future__ import division import itertools import sys from signal import signal, SIGINT, default_int_handler from pip.compat import WINDOWS from pip.utils import format_size from pip.utils.logging import get_indentation from pip._vendor import six from pip._vendor.progress.bar import Bar, IncrementalBar from pip._vendor.progress.helpers import WritelnMixin from pip._vendor.progress.spinner import Spinner try: from pip._vendor import colorama # Lots of different errors can come from this, including SystemError and # ImportError. except Exception: colorama = None def _select_progress_class(preferred, fallback): encoding = getattr(preferred.file, "encoding", None) # If we don't know what encoding this file is in, then we'll just assume # that it doesn't support unicode and use the ASCII bar. if not encoding: return fallback # Collect all of the possible characters we want to use with the preferred # bar. characters = [ getattr(preferred, "empty_fill", six.text_type()), getattr(preferred, "fill", six.text_type()), ] characters += list(getattr(preferred, "phases", [])) # Try to decode the characters we're using for the bar using the encoding # of the given file, if this works then we'll assume that we can use the # fancier bar and if not we'll fall back to the plaintext bar. try: six.text_type().join(characters).encode(encoding) except UnicodeEncodeError: return fallback else: return preferred _BaseBar = _select_progress_class(IncrementalBar, Bar) class InterruptibleMixin(object): """ Helper to ensure that self.finish() gets called on keyboard interrupt. This allows downloads to be interrupted without leaving temporary state (like hidden cursors) behind. This class is similar to the progress library's existing SigIntMixin helper, but as of version 1.2, that helper has the following problems: 1. It calls sys.exit(). 2. It discards the existing SIGINT handler completely. 3. It leaves its own handler in place even after an uninterrupted finish, which will have unexpected delayed effects if the user triggers an unrelated keyboard interrupt some time after a progress-displaying download has already completed, for example. """ def __init__(self, *args, **kwargs): """ Save the original SIGINT handler for later. """ super(InterruptibleMixin, self).__init__(*args, **kwargs) self.original_handler = signal(SIGINT, self.handle_sigint) # If signal() returns None, the previous handler was not installed from # Python, and we cannot restore it. This probably should not happen, # but if it does, we must restore something sensible instead, at least. # The least bad option should be Python's default SIGINT handler, which # just raises KeyboardInterrupt. if self.original_handler is None: self.original_handler = default_int_handler def finish(self): """ Restore the original SIGINT handler after finishing. This should happen regardless of whether the progress display finishes normally, or gets interrupted. """ super(InterruptibleMixin, self).finish() signal(SIGINT, self.original_handler) def handle_sigint(self, signum, frame): """ Call self.finish() before delegating to the original SIGINT handler. This handler should only be in place while the progress display is active. """ self.finish() self.original_handler(signum, frame) class DownloadProgressMixin(object): def __init__(self, *args, **kwargs): super(DownloadProgressMixin, self).__init__(*args, **kwargs) self.message = (" " * (get_indentation() + 2)) + self.message @property def downloaded(self): return format_size(self.index) @property def download_speed(self): # Avoid zero division errors... if self.avg == 0.0: return "..." return format_size(1 / self.avg) + "/s" @property def pretty_eta(self): if self.eta: return "eta %s" % self.eta_td return "" def iter(self, it, n=1): for x in it: yield x self.next(n) self.finish() class WindowsMixin(object): def __init__(self, *args, **kwargs): # The Windows terminal does not support the hide/show cursor ANSI codes # even with colorama. So we'll ensure that hide_cursor is False on # Windows. # This call neds to go before the super() call, so that hide_cursor # is set in time. The base progress bar class writes the "hide cursor" # code to the terminal in its init, so if we don't set this soon # enough, we get a "hide" with no corresponding "show"... if WINDOWS and self.hide_cursor: self.hide_cursor = False super(WindowsMixin, self).__init__(*args, **kwargs) # Check if we are running on Windows and we have the colorama module, # if we do then wrap our file with it. if WINDOWS and colorama: self.file = colorama.AnsiToWin32(self.file) # The progress code expects to be able to call self.file.isatty() # but the colorama.AnsiToWin32() object doesn't have that, so we'll # add it. self.file.isatty = lambda: self.file.wrapped.isatty() # The progress code expects to be able to call self.file.flush() # but the colorama.AnsiToWin32() object doesn't have that, so we'll # add it. self.file.flush = lambda: self.file.wrapped.flush() class DownloadProgressBar(WindowsMixin, InterruptibleMixin, DownloadProgressMixin, _BaseBar): file = sys.stdout message = "%(percent)d%%" suffix = "%(downloaded)s %(download_speed)s %(pretty_eta)s" class DownloadProgressSpinner(WindowsMixin, InterruptibleMixin, DownloadProgressMixin, WritelnMixin, Spinner): file = sys.stdout suffix = "%(downloaded)s %(download_speed)s" def next_phase(self): if not hasattr(self, "_phaser"): self._phaser = itertools.cycle(self.phases) return next(self._phaser) def update(self): message = self.message % self phase = self.next_phase() suffix = self.suffix % self line = ''.join([ message, " " if message else "", phase, " " if suffix else "", suffix, ]) self.writeln(line)
gpl-3.0
[ 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 646, 7975, 199, 646, 984, 199, 504, 4673, 492, 4673, 12, 15522, 2919, 12, 849, 63, 442, 63, 2232, 199, 199, 504, 7305, 14, 5819, 492, 20896, 1649, 5035, 199, 504, 7305, 14, 1208, 492, 1475, 63, 890, 199, 504, 7305, 14, 1208, 14, 4806, 492, 664, 63, 25152, 199, 504, 7305, 423, 9884, 492, 3816, 199, 504, 7305, 423, 9884, 14, 5734, 14, 1700, 492, 12377, 12, 14684, 5281, 199, 504, 7305, 423, 9884, 14, 5734, 14, 7546, 492, 6990, 6066, 4256, 199, 504, 7305, 423, 9884, 14, 5734, 14, 681, 5216, 492, 8360, 5216, 199, 199, 893, 26, 272, 687, 7305, 423, 9884, 492, 3164, 14541, 199, 3, 491, 16673, 402, 3365, 2552, 883, 11492, 687, 642, 12, 5893, 6187, 547, 436, 199, 3, 3545, 14, 199, 2590, 2186, 26, 272, 3164, 14541, 275, 488, 421, 199, 318, 485, 2416, 63, 5734, 63, 533, 8, 17477, 12, 9567, 304, 272, 2644, 275, 2519, 8, 17477, 14, 493, 12, 298, 2991, 401, 488, 9, 339, 327, 982, 781, 2793, 1133, 5715, 4052, 2644, 642, 570, 365, 315, 12, 2066, 781, 7171, 2951, 5534, 272, 327, 626, 652, 3181, 1133, 2291, 2649, 436, 675, 314, 10485, 4681, 14, 272, 340, 440, 2644, 26, 267, 372, 9567, 339, 327, 19649, 1006, 402, 314, 3962, 4110, 781, 2934, 370, 675, 543, 314, 14388, 272, 327, 4681, 14, 272, 4110, 275, 359, 267, 2519, 8, 17477, 12, 298, 1667, 63, 4498, 401, 3816, 14, 505, 63, 466, 4000, 267, 2519, 8, 17477, 12, 298, 4498, 401, 3816, 14, 505, 63, 466, 4000, 272, 1622, 272, 4110, 847, 769, 8, 5675, 8, 17477, 12, 298, 14236, 401, 15927, 339, 327, 7649, 370, 4849, 314, 4110, 781, 3984, 1808, 367, 314, 4681, 1808, 314, 2644, 272, 327, 402, 314, 1627, 570, 12, 340, 642, 5419, 2066, 781, 7171, 5534, 626, 781, 883, 675, 314, 272, 327, 13758, 559, 281, 4681, 436, 340, 440, 781, 7171, 11264, 1771, 370, 314, 18577, 4681, 14, 272, 862, 26, 267, 3816, 14, 505, 63, 466, 1252, 904, 8, 16516, 680, 2143, 8, 2991, 9, 272, 871, 24094, 26, 267, 372, 9567, 272, 587, 26, 267, 372, 14388, 421, 199, 63, 1563, 5281, 275, 485, 2416, 63, 5734, 63, 533, 8, 10287, 5281, 12, 12377, 9, 421, 199, 533, 6551, 5505, 21602, 4256, 8, 785, 304, 272, 408, 272, 11642, 370, 4868, 626, 291, 14, 8192, 342, 7545, 2797, 641, 18716, 26791, 14, 339, 961, 6127, 28242, 370, 506, 31366, 1928, 23188, 7937, 1174, 272, 334, 2930, 8752, 18809, 1384, 9, 22172, 14, 339, 961, 1021, 365, 8545, 370, 314, 6696, 3555, 1159, 3411, 14625, 3241, 4256, 272, 5922, 12, 1325, 465, 402, 1015, 413, 14, 18, 12, 626, 5922, 965, 314, 2569, 8826, 26, 339, 413, 14, 2779, 4882, 984, 14, 2224, 1252, 272, 499, 14, 2779, 4339, 5596, 314, 3411, 15522, 2919, 3016, 14793, 14, 272, 650, 14, 2779, 16733, 2399, 5705, 3016, 315, 4192, 2755, 2410, 376, 625, 1058, 15692, 9578, 12, 2126, 1314, 911, 1172, 10537, 24725, 22414, 340, 314, 922, 18899, 376, 2126, 625, 2407, 18716, 26791, 2005, 900, 2410, 282, 6696, 13, 2918, 316, 2126, 5235, 965, 2575, 9709, 12, 367, 2893, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 408, 267, 11063, 314, 3379, 15522, 2919, 3016, 367, 2945, 14, 267, 408, 267, 1613, 8, 2620, 5505, 21602, 4256, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 398, 291, 14, 5043, 63, 2232, 275, 4673, 8, 21223, 12, 291, 14, 2479, 63, 4093, 442, 9, 398, 327, 982, 4673, 342, 2529, 488, 12, 314, 4136, 3016, 1990, 440, 4903, 687, 267, 327, 2018, 12, 436, 781, 3913, 9066, 652, 14, 961, 8646, 1077, 440, 5992, 12, 267, 327, 1325, 340, 652, 1630, 12, 781, 1471, 9066, 6020, 27962, 3140, 12, 737, 5210, 14, 267, 327, 710, 5210, 4875, 945, 1077, 506, 2018, 1159, 849, 15522, 2919, 3016, 12, 1314, 267, 327, 2951, 6534, 13483, 14, 267, 340, 291, 14, 5043, 63, 2232, 365, 488, 26, 288, 291, 14, 5043, 63, 2232, 275, 849, 63, 442, 63, 2232, 339, 347, 9578, 8, 277, 304, 267, 408, 267, 22379, 314, 3379, 15522, 2919, 3016, 2410, 9578, 316, 14, 398, 961, 1077, 5992, 15270, 402, 3775, 314, 6696, 2929, 9578, 397, 267, 12252, 12, 503, 7545, 31366, 14, 267, 408, 267, 1613, 8, 2620, 5505, 21602, 4256, 12, 291, 680, 8192, 342, 267, 4673, 8, 21223, 12, 291, 14, 5043, 63, 2232, 9, 339, 347, 2429, 63, 4093, 442, 8, 277, 12, 2070, 453, 12, 2787, 304, 267, 408, 267, 6523, 291, 14, 8192, 342, 2544, 18703, 1958, 370, 314, 3379, 15522, 2919, 3016, 14, 398, 961, 3016, 1077, 1454, 506, 315, 4192, 1830, 314, 6696, 2929, 365, 267, 4702, 14, 267, 408, 267, 291, 14, 8192, 342, 267, 291, 14, 5043, 63, 2232, 8, 1037, 453, 12, 2787, 9, 421, 199, 533, 17955, 11504, 4256, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 11950, 11504, 4256, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 1188, 275, 1689, 298, 627, 334, 362, 63, 25152, 342, 435, 499, 430, 435, 291, 14, 1188, 339, 768, 1829, 272, 347, 13557, 8, 277, 304, 267, 372, 1475, 63, 890, 8, 277, 14, 1080, 9, 339, 768, 1829, 272, 347, 5235, 63, 7625, 8, 277, 304, 267, 327, 19503, 4697, 4629, 2552, 1396, 267, 340, 291, 14, 8595, 508, 378, 14, 16, 26, 288, 372, 298, 11500, 267, 372, 1475, 63, 890, 8, 17, 1182, 291, 14, 8595, 9, 435, 3286, 83, 2, 339, 768, 1829, 272, 347, 7268, 63, 1841, 8, 277, 304, 267, 340, 291, 14, 1841, 26, 288, 372, 298, 1841, 450, 83, 2, 450, 291, 14, 1841, 63, 2076, 267, 372, 3087, 339, 347, 2740, 8, 277, 12, 652, 12, 302, 29, 17, 304, 267, 367, 671, 315, 652, 26, 288, 1995, 671, 288, 291, 14, 2184, 8, 78, 9, 267, 291, 14, 8192, 342, 421 ]
[ 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 646, 7975, 199, 646, 984, 199, 504, 4673, 492, 4673, 12, 15522, 2919, 12, 849, 63, 442, 63, 2232, 199, 199, 504, 7305, 14, 5819, 492, 20896, 1649, 5035, 199, 504, 7305, 14, 1208, 492, 1475, 63, 890, 199, 504, 7305, 14, 1208, 14, 4806, 492, 664, 63, 25152, 199, 504, 7305, 423, 9884, 492, 3816, 199, 504, 7305, 423, 9884, 14, 5734, 14, 1700, 492, 12377, 12, 14684, 5281, 199, 504, 7305, 423, 9884, 14, 5734, 14, 7546, 492, 6990, 6066, 4256, 199, 504, 7305, 423, 9884, 14, 5734, 14, 681, 5216, 492, 8360, 5216, 199, 199, 893, 26, 272, 687, 7305, 423, 9884, 492, 3164, 14541, 199, 3, 491, 16673, 402, 3365, 2552, 883, 11492, 687, 642, 12, 5893, 6187, 547, 436, 199, 3, 3545, 14, 199, 2590, 2186, 26, 272, 3164, 14541, 275, 488, 421, 199, 318, 485, 2416, 63, 5734, 63, 533, 8, 17477, 12, 9567, 304, 272, 2644, 275, 2519, 8, 17477, 14, 493, 12, 298, 2991, 401, 488, 9, 339, 327, 982, 781, 2793, 1133, 5715, 4052, 2644, 642, 570, 365, 315, 12, 2066, 781, 7171, 2951, 5534, 272, 327, 626, 652, 3181, 1133, 2291, 2649, 436, 675, 314, 10485, 4681, 14, 272, 340, 440, 2644, 26, 267, 372, 9567, 339, 327, 19649, 1006, 402, 314, 3962, 4110, 781, 2934, 370, 675, 543, 314, 14388, 272, 327, 4681, 14, 272, 4110, 275, 359, 267, 2519, 8, 17477, 12, 298, 1667, 63, 4498, 401, 3816, 14, 505, 63, 466, 4000, 267, 2519, 8, 17477, 12, 298, 4498, 401, 3816, 14, 505, 63, 466, 4000, 272, 1622, 272, 4110, 847, 769, 8, 5675, 8, 17477, 12, 298, 14236, 401, 15927, 339, 327, 7649, 370, 4849, 314, 4110, 781, 3984, 1808, 367, 314, 4681, 1808, 314, 2644, 272, 327, 402, 314, 1627, 570, 12, 340, 642, 5419, 2066, 781, 7171, 5534, 626, 781, 883, 675, 314, 272, 327, 13758, 559, 281, 4681, 436, 340, 440, 781, 7171, 11264, 1771, 370, 314, 18577, 4681, 14, 272, 862, 26, 267, 3816, 14, 505, 63, 466, 1252, 904, 8, 16516, 680, 2143, 8, 2991, 9, 272, 871, 24094, 26, 267, 372, 9567, 272, 587, 26, 267, 372, 14388, 421, 199, 63, 1563, 5281, 275, 485, 2416, 63, 5734, 63, 533, 8, 10287, 5281, 12, 12377, 9, 421, 199, 533, 6551, 5505, 21602, 4256, 8, 785, 304, 272, 408, 272, 11642, 370, 4868, 626, 291, 14, 8192, 342, 7545, 2797, 641, 18716, 26791, 14, 339, 961, 6127, 28242, 370, 506, 31366, 1928, 23188, 7937, 1174, 272, 334, 2930, 8752, 18809, 1384, 9, 22172, 14, 339, 961, 1021, 365, 8545, 370, 314, 6696, 3555, 1159, 3411, 14625, 3241, 4256, 272, 5922, 12, 1325, 465, 402, 1015, 413, 14, 18, 12, 626, 5922, 965, 314, 2569, 8826, 26, 339, 413, 14, 2779, 4882, 984, 14, 2224, 1252, 272, 499, 14, 2779, 4339, 5596, 314, 3411, 15522, 2919, 3016, 14793, 14, 272, 650, 14, 2779, 16733, 2399, 5705, 3016, 315, 4192, 2755, 2410, 376, 625, 1058, 15692, 9578, 12, 2126, 1314, 911, 1172, 10537, 24725, 22414, 340, 314, 922, 18899, 376, 2126, 625, 2407, 18716, 26791, 2005, 900, 2410, 282, 6696, 13, 2918, 316, 2126, 5235, 965, 2575, 9709, 12, 367, 2893, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 408, 267, 11063, 314, 3379, 15522, 2919, 3016, 367, 2945, 14, 267, 408, 267, 1613, 8, 2620, 5505, 21602, 4256, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 398, 291, 14, 5043, 63, 2232, 275, 4673, 8, 21223, 12, 291, 14, 2479, 63, 4093, 442, 9, 398, 327, 982, 4673, 342, 2529, 488, 12, 314, 4136, 3016, 1990, 440, 4903, 687, 267, 327, 2018, 12, 436, 781, 3913, 9066, 652, 14, 961, 8646, 1077, 440, 5992, 12, 267, 327, 1325, 340, 652, 1630, 12, 781, 1471, 9066, 6020, 27962, 3140, 12, 737, 5210, 14, 267, 327, 710, 5210, 4875, 945, 1077, 506, 2018, 1159, 849, 15522, 2919, 3016, 12, 1314, 267, 327, 2951, 6534, 13483, 14, 267, 340, 291, 14, 5043, 63, 2232, 365, 488, 26, 288, 291, 14, 5043, 63, 2232, 275, 849, 63, 442, 63, 2232, 339, 347, 9578, 8, 277, 304, 267, 408, 267, 22379, 314, 3379, 15522, 2919, 3016, 2410, 9578, 316, 14, 398, 961, 1077, 5992, 15270, 402, 3775, 314, 6696, 2929, 9578, 397, 267, 12252, 12, 503, 7545, 31366, 14, 267, 408, 267, 1613, 8, 2620, 5505, 21602, 4256, 12, 291, 680, 8192, 342, 267, 4673, 8, 21223, 12, 291, 14, 5043, 63, 2232, 9, 339, 347, 2429, 63, 4093, 442, 8, 277, 12, 2070, 453, 12, 2787, 304, 267, 408, 267, 6523, 291, 14, 8192, 342, 2544, 18703, 1958, 370, 314, 3379, 15522, 2919, 3016, 14, 398, 961, 3016, 1077, 1454, 506, 315, 4192, 1830, 314, 6696, 2929, 365, 267, 4702, 14, 267, 408, 267, 291, 14, 8192, 342, 267, 291, 14, 5043, 63, 2232, 8, 1037, 453, 12, 2787, 9, 421, 199, 533, 17955, 11504, 4256, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 11950, 11504, 4256, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 1188, 275, 1689, 298, 627, 334, 362, 63, 25152, 342, 435, 499, 430, 435, 291, 14, 1188, 339, 768, 1829, 272, 347, 13557, 8, 277, 304, 267, 372, 1475, 63, 890, 8, 277, 14, 1080, 9, 339, 768, 1829, 272, 347, 5235, 63, 7625, 8, 277, 304, 267, 327, 19503, 4697, 4629, 2552, 1396, 267, 340, 291, 14, 8595, 508, 378, 14, 16, 26, 288, 372, 298, 11500, 267, 372, 1475, 63, 890, 8, 17, 1182, 291, 14, 8595, 9, 435, 3286, 83, 2, 339, 768, 1829, 272, 347, 7268, 63, 1841, 8, 277, 304, 267, 340, 291, 14, 1841, 26, 288, 372, 298, 1841, 450, 83, 2, 450, 291, 14, 1841, 63, 2076, 267, 372, 3087, 339, 347, 2740, 8, 277, 12, 652, 12, 302, 29, 17, 304, 267, 367, 671, 315, 652, 26, 288, 1995, 671, 288, 291, 14, 2184, 8, 78, 9, 267, 291, 14, 8192, 342, 421, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Desterly/android_kernel_motorola_msm8994
tools/perf/scripts/python/failed-syscalls-by-pid.py
11180
2058
# failed system call counts, by pid # (c) 2010, Tom Zanussi <tzanussi@gmail.com> # Licensed under the terms of the GNU GPL License version 2 # # Displays system-wide failed system call totals, broken down by pid. # If a [comm] arg is specified, only syscalls called by [comm] are displayed. import os import sys sys.path.append(os.environ['PERF_EXEC_PATH'] + \ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') from perf_trace_context import * from Core import * from Util import * usage = "perf script -s syscall-counts-by-pid.py [comm|pid]\n"; for_comm = None for_pid = None if len(sys.argv) > 2: sys.exit(usage) if len(sys.argv) > 1: try: for_pid = int(sys.argv[1]) except: for_comm = sys.argv[1] syscalls = autodict() def trace_begin(): print "Press control+C to stop and show the summary" def trace_end(): print_error_totals() def raw_syscalls__sys_exit(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, id, ret): if (for_comm and common_comm != for_comm) or \ (for_pid and common_pid != for_pid ): return if ret < 0: try: syscalls[common_comm][common_pid][id][ret] += 1 except TypeError: syscalls[common_comm][common_pid][id][ret] = 1 def print_error_totals(): if for_comm is not None: print "\nsyscall errors for %s:\n\n" % (for_comm), else: print "\nsyscall errors:\n\n", print "%-30s %10s\n" % ("comm [pid]", "count"), print "%-30s %10s\n" % ("------------------------------", \ "----------"), comm_keys = syscalls.keys() for comm in comm_keys: pid_keys = syscalls[comm].keys() for pid in pid_keys: print "\n%s [%d]\n" % (comm, pid), id_keys = syscalls[comm][pid].keys() for id in id_keys: print " syscall: %-16s\n" % syscall_name(id), ret_keys = syscalls[comm][pid][id].keys() for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True): print " err = %-20s %10d\n" % (strerror(ret), val),
gpl-2.0
[ 3, 3405, 2656, 1240, 8242, 12, 701, 4422, 199, 3, 334, 67, 9, 7129, 12, 21644, 29385, 665, 29453, 32, 6799, 14, 957, 30, 199, 3, 3909, 1334, 314, 2895, 402, 314, 1664, 14629, 844, 1015, 499, 199, 3, 199, 3, 28750, 2656, 13, 13062, 3405, 2656, 1240, 23576, 12, 10529, 3224, 701, 4422, 14, 199, 3, 982, 282, 359, 1404, 61, 1680, 365, 2013, 12, 1454, 19473, 2797, 701, 359, 1404, 61, 787, 9080, 14, 199, 199, 646, 747, 199, 646, 984, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 2314, 459, 17038, 63, 10276, 63, 3243, 418, 435, 971, 199, 198, 9807, 6429, 15, 1548, 15, 12387, 13, 3921, 13, 9562, 15, 773, 15, 12387, 15, 3921, 358, 199, 199, 504, 8582, 63, 3446, 63, 1100, 492, 627, 199, 504, 11672, 492, 627, 199, 504, 21248, 492, 627, 199, 199, 3807, 275, 298, 9452, 2884, 446, 83, 18901, 13, 6851, 13, 991, 13, 3150, 14, 647, 359, 1404, 92, 3150, 7272, 78, 11436, 199, 199, 509, 63, 1404, 275, 488, 199, 509, 63, 3150, 275, 488, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 690, 499, 26, 199, 198, 1274, 14, 2224, 8, 3807, 9, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 690, 413, 26, 199, 198, 893, 26, 507, 198, 509, 63, 3150, 275, 1109, 8, 1274, 14, 3020, 59, 17, 566, 199, 198, 2590, 26, 507, 198, 509, 63, 1404, 275, 984, 14, 3020, 59, 17, 61, 199, 199, 14507, 275, 27477, 342, 199, 199, 318, 3307, 63, 5037, 837, 199, 198, 1361, 298, 14414, 3304, 11, 35, 370, 3631, 436, 2498, 314, 6212, 2, 199, 199, 318, 3307, 63, 500, 837, 199, 198, 1361, 63, 705, 63, 17552, 342, 199, 199, 318, 3066, 63, 14507, 363, 1274, 63, 2224, 8, 1430, 63, 354, 12, 1067, 12, 2863, 63, 3541, 12, 199, 198, 2330, 63, 4855, 12, 2863, 63, 9618, 12, 2863, 63, 3150, 12, 2863, 63, 1404, 12, 199, 198, 344, 12, 2203, 304, 199, 198, 692, 334, 509, 63, 1404, 436, 2863, 63, 1404, 1137, 367, 63, 1404, 9, 503, 971, 21979, 334, 509, 63, 3150, 221, 436, 2863, 63, 3150, 221, 1137, 367, 63, 3150, 3461, 507, 198, 1107, 421, 198, 692, 2203, 665, 378, 26, 507, 198, 893, 26, 686, 198, 14507, 59, 2330, 63, 1404, 1527, 2330, 63, 3150, 1527, 344, 1527, 3292, 61, 847, 413, 507, 198, 2590, 3146, 26, 686, 198, 14507, 59, 2330, 63, 1404, 1527, 2330, 63, 3150, 1527, 344, 1527, 3292, 61, 275, 413, 199, 199, 318, 870, 63, 705, 63, 17552, 837, 272, 340, 367, 63, 1404, 365, 440, 488, 26, 6722, 870, 1867, 26605, 2552, 367, 450, 83, 3427, 78, 60, 78, 2, 450, 334, 509, 63, 1404, 395, 272, 587, 26, 6722, 870, 1867, 26605, 2552, 3427, 78, 60, 78, 401, 339, 870, 18301, 1216, 83, 221, 450, 709, 83, 60, 78, 2, 450, 1689, 1404, 359, 3150, 11472, 298, 835, 1288, 272, 870, 18301, 1216, 83, 221, 450, 709, 83, 60, 78, 2, 450, 1689, 777, 10965, 401, 971, 639, 298, 9460, 1288, 339, 1923, 63, 1612, 275, 19473, 14, 1612, 342, 272, 367, 1923, 315, 1923, 63, 1612, 26, 6722, 4422, 63, 1612, 275, 19473, 59, 1404, 1055, 1612, 342, 6722, 367, 4422, 315, 4422, 63, 1612, 26, 15075, 870, 1867, 78, 5, 83, 8978, 68, 7272, 78, 2, 450, 334, 1404, 12, 4422, 395, 15075, 1305, 63, 1612, 275, 19473, 59, 1404, 1527, 3150, 1055, 1612, 342, 15075, 367, 1305, 315, 1305, 63, 1612, 26, 24449, 870, 298, 221, 18901, 26, 19752, 975, 83, 60, 78, 2, 450, 18901, 63, 354, 8, 344, 395, 24449, 2203, 63, 1612, 275, 19473, 59, 1404, 1527, 3150, 1527, 344, 1055, 1612, 342, 24449, 367, 2203, 12, 1139, 315, 3355, 8, 14507, 59, 1404, 1527, 3150, 1527, 344, 1055, 4611, 1062, 790, 275, 2400, 8, 75, 12, 373, 304, 334, 86, 12, 1022, 395, 221, 3837, 275, 715, 304, 1871, 259, 870, 298, 259, 2329, 275, 19752, 1165, 83, 221, 450, 709, 68, 60, 78, 2, 450, 334, 20395, 8, 3292, 395, 1139, 395, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 3405, 2656, 1240, 8242, 12, 701, 4422, 199, 3, 334, 67, 9, 7129, 12, 21644, 29385, 665, 29453, 32, 6799, 14, 957, 30, 199, 3, 3909, 1334, 314, 2895, 402, 314, 1664, 14629, 844, 1015, 499, 199, 3, 199, 3, 28750, 2656, 13, 13062, 3405, 2656, 1240, 23576, 12, 10529, 3224, 701, 4422, 14, 199, 3, 982, 282, 359, 1404, 61, 1680, 365, 2013, 12, 1454, 19473, 2797, 701, 359, 1404, 61, 787, 9080, 14, 199, 199, 646, 747, 199, 646, 984, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 2314, 459, 17038, 63, 10276, 63, 3243, 418, 435, 971, 199, 198, 9807, 6429, 15, 1548, 15, 12387, 13, 3921, 13, 9562, 15, 773, 15, 12387, 15, 3921, 358, 199, 199, 504, 8582, 63, 3446, 63, 1100, 492, 627, 199, 504, 11672, 492, 627, 199, 504, 21248, 492, 627, 199, 199, 3807, 275, 298, 9452, 2884, 446, 83, 18901, 13, 6851, 13, 991, 13, 3150, 14, 647, 359, 1404, 92, 3150, 7272, 78, 11436, 199, 199, 509, 63, 1404, 275, 488, 199, 509, 63, 3150, 275, 488, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 690, 499, 26, 199, 198, 1274, 14, 2224, 8, 3807, 9, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 690, 413, 26, 199, 198, 893, 26, 507, 198, 509, 63, 3150, 275, 1109, 8, 1274, 14, 3020, 59, 17, 566, 199, 198, 2590, 26, 507, 198, 509, 63, 1404, 275, 984, 14, 3020, 59, 17, 61, 199, 199, 14507, 275, 27477, 342, 199, 199, 318, 3307, 63, 5037, 837, 199, 198, 1361, 298, 14414, 3304, 11, 35, 370, 3631, 436, 2498, 314, 6212, 2, 199, 199, 318, 3307, 63, 500, 837, 199, 198, 1361, 63, 705, 63, 17552, 342, 199, 199, 318, 3066, 63, 14507, 363, 1274, 63, 2224, 8, 1430, 63, 354, 12, 1067, 12, 2863, 63, 3541, 12, 199, 198, 2330, 63, 4855, 12, 2863, 63, 9618, 12, 2863, 63, 3150, 12, 2863, 63, 1404, 12, 199, 198, 344, 12, 2203, 304, 199, 198, 692, 334, 509, 63, 1404, 436, 2863, 63, 1404, 1137, 367, 63, 1404, 9, 503, 971, 21979, 334, 509, 63, 3150, 221, 436, 2863, 63, 3150, 221, 1137, 367, 63, 3150, 3461, 507, 198, 1107, 421, 198, 692, 2203, 665, 378, 26, 507, 198, 893, 26, 686, 198, 14507, 59, 2330, 63, 1404, 1527, 2330, 63, 3150, 1527, 344, 1527, 3292, 61, 847, 413, 507, 198, 2590, 3146, 26, 686, 198, 14507, 59, 2330, 63, 1404, 1527, 2330, 63, 3150, 1527, 344, 1527, 3292, 61, 275, 413, 199, 199, 318, 870, 63, 705, 63, 17552, 837, 272, 340, 367, 63, 1404, 365, 440, 488, 26, 6722, 870, 1867, 26605, 2552, 367, 450, 83, 3427, 78, 60, 78, 2, 450, 334, 509, 63, 1404, 395, 272, 587, 26, 6722, 870, 1867, 26605, 2552, 3427, 78, 60, 78, 401, 339, 870, 18301, 1216, 83, 221, 450, 709, 83, 60, 78, 2, 450, 1689, 1404, 359, 3150, 11472, 298, 835, 1288, 272, 870, 18301, 1216, 83, 221, 450, 709, 83, 60, 78, 2, 450, 1689, 777, 10965, 401, 971, 639, 298, 9460, 1288, 339, 1923, 63, 1612, 275, 19473, 14, 1612, 342, 272, 367, 1923, 315, 1923, 63, 1612, 26, 6722, 4422, 63, 1612, 275, 19473, 59, 1404, 1055, 1612, 342, 6722, 367, 4422, 315, 4422, 63, 1612, 26, 15075, 870, 1867, 78, 5, 83, 8978, 68, 7272, 78, 2, 450, 334, 1404, 12, 4422, 395, 15075, 1305, 63, 1612, 275, 19473, 59, 1404, 1527, 3150, 1055, 1612, 342, 15075, 367, 1305, 315, 1305, 63, 1612, 26, 24449, 870, 298, 221, 18901, 26, 19752, 975, 83, 60, 78, 2, 450, 18901, 63, 354, 8, 344, 395, 24449, 2203, 63, 1612, 275, 19473, 59, 1404, 1527, 3150, 1527, 344, 1055, 1612, 342, 24449, 367, 2203, 12, 1139, 315, 3355, 8, 14507, 59, 1404, 1527, 3150, 1527, 344, 1055, 4611, 1062, 790, 275, 2400, 8, 75, 12, 373, 304, 334, 86, 12, 1022, 395, 221, 3837, 275, 715, 304, 1871, 259, 870, 298, 259, 2329, 275, 19752, 1165, 83, 221, 450, 709, 68, 60, 78, 2, 450, 334, 20395, 8, 3292, 395, 1139, 395, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
anant-dev/django
django/db/backends/base/base.py
184
23050
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() try: while self.run_on_commit: sids, func = self.run_on_commit.pop(0) func() finally: self.run_on_commit = [] 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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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 ]
GEHC-Surgery/ITK
Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/ParseAttributes.py
42
18708
#!/usr/bin/env python # vim: set fileencoding=iso-8859-1 """ $ pdftotext -layout -nopgbrk -f 303 -l 305 07_03pu.pdf page303.txt $ python ParseAttributes.py page273-1000.txt out.txt > log2 $ grep ADD log2 | grep -v "Notes:" | grep -v "Note:" | grep -v "C.8" | grep -v "C.7" """ import re,os """ """ class Attribute: # Cstor def __init__(self): self._Name = '' self._Tag = '(0000,0000)' self._Type = '' self._Description= '' def SetInit(self,s): # Should be something like: # Blue Palette Color Lookup Table (0028,1103) 1C Specifies the format of the Blue Palette patt = re.compile("^(.*)(\\([0-9A-Fx]+,[0-9A-F]+\\))\s+([1-3C]+)\s+(.*)\s*$") m = patt.match(s) if not m: print s assert 0 self._Name = m.group(1).strip() self._Tag = m.group(2).strip() self._Type = m.group(3).strip() self._Description = m.group(4).strip() def SetName(self,s): self._Name = s def AppendName(self,s): self._Name += " " self._Name += s.strip() def SetTag(self,s): self._Tag = s def SetType(self,s): self._Type = s def SetDescription(self,s): self._Description = s def AppendDescription(self,s): self._Description += " " self._Description += s.strip() def GetAsXML(self): description = self._Description.replace('"','&quot;') description = description.replace('&','&amp;') return "<entry group=\""+self._Tag[1:5]+"\" element=\""+self._Tag[6:10]+"\" name=\""+self._Name.replace('&','&amp;')+"\" type=\""+self._Type+"\" description=\""+description+"\"></entry>" def Print(self): print self.GetAsXML() class Part3Parser: # Cstor def __init__(self): self._InputFilename = '' self._OutputFilename = '' self._Buffer = '' self._CurrentAttribute = Attribute() self._IsInTable = False self._Shift = 0 def SetInputFileName(self,s): self._InputFilename = s def SetOutputFileName(self,s): self._OutputFilename = s def IsComment(self,s): if len(s) == 0: return True patt1 = re.compile("^\s+- Standard -\s*$") patt2 = re.compile("^\s*PS 3.3 - 2007\s*") patt3 = re.compile("^\s*Page\s+[0-9]+\s*$") patt4 = re.compile("^\s*Notes:$") m1 = patt1.match(s) m2 = patt2.match(s) m3 = patt3.match(s) m4 = patt4.match(s) if(m1 or m2 or m3 or m4): print "Comment:", s return True if self.IsTableDescription(s): return True return False def IsStartTable(self,s): #patt = re.compile("^\s+Table C[0-9a-z\.-]+.*\s+$") patt = re.compile("^\s+Table\s+C.[0-9A-Za-z-.]+\s*$") m = patt.match(s) assert self._IsInTable != True self._IsInTable = False if s.strip() == 'Table C.7-23' or s.strip() == 'Table C.7-24' \ or s.strip() == 'Table C.7.6.10-1' \ or s.strip() == 'Table C.7-25' \ or s.strip() == 'Table C.7-26' \ or s.strip() == 'Table C.7-27' \ or s.strip() == 'Table C.8-8' \ or s.strip() == 'Table C.8-19' \ or s.strip() == 'Table C.8-20' \ or s.strip() == 'Table C.8-21' \ or s.strip() == 'Table C.8-22' \ or s.strip() == 'Table C.8-23' \ or s.strip() == 'Table C.8-80' \ or s.strip() == 'Table C.8-83' \ or s.strip() == 'Table C.8-84' \ or s.strip() == 'Table C.8-85' \ or s.strip() == 'Table C.8-86' \ or s.strip() == 'Table C.8-108' \ or s.strip() == 'Table C.8-109' \ or s.strip() == 'Table C.8-110' \ or s.strip() == 'Table C.8-111' \ or s.strip() == 'Table C.8-112' \ or s.strip() == 'Table C.8-115' \ or s.strip() == 'Table C.8-116' \ or s.strip() == 'Table C.8-127' \ or s.strip() == 'Table C.8-128' \ or s.strip() == 'Table C.8-129' \ or s.strip() == 'Table C.8-130' \ or s.strip() == 'Table C.8-131' \ or s.strip() == 'Table C.8-132' \ or s.strip() == 'Table C.8-133' \ or s.strip() == 'Table C.8-134' \ or s.strip() == 'Table C.8.19.2-2' \ or s.strip() == 'Table C.10-10' \ or s.strip() == 'Table C.11-4' \ or s.strip() == 'Table C.12-2' \ or s.strip() == 'Table C.12-3' \ or s.strip() == 'Table C.12-4' \ or s.strip() == 'Table C.12-5' \ or s.strip() == 'Table C.12-7' \ or s.strip() == 'Table C.13-1' \ or s.strip() == 'Table C.13-2' \ or s.strip() == 'Table C.13-3' \ or s.strip() == 'Table C.13-4' \ or s.strip() == 'Table C.13-5' \ or s.strip() == 'Table C.13-7' \ or s.strip() == 'Table C.13-8' \ or s.strip() == 'Table C.13-9' \ or s.strip() == 'Table C.13-13' \ or s.strip() == 'Table C.14-1' \ or s.strip() == 'Table C.17.3-7' \ or s.strip() == 'Table C.17.3-8' \ or s.strip() == 'Table C.22.1-1': # C.11-4, C.13-*, C.22.1-1: Does not even comes with column type !!! # C.12-7 is difficult to parse # C.7.6.16-1 is insane... # TODO: Last line of C.19-1... return False if(m): print "Start", s self._IsInTable = True return True # grrrrr: Table C.8-37 - RT SERIES MODULE ATTRIBUTES patt = re.compile("^\s+Table\s+C.[0-9A-Za-z-]+\s*[-]*\s*([A-Z/\s-]+)\s*$") #patt = re.compile("^\s+Table\s+C.[0-9A-Za-z-]+[-\s]+([A-Z/\s-]+)\s*$") m = patt.match(s) if(m): print "Start", s self._IsInTable = True return True print "IsTable failed with:", s return False def IsEndTable(self,s): assert self._IsInTable == True assert not self.IsComment(s) self._IsInTable = False return True def IsTableName(self,s): patt = re.compile("^\s*[A-Z/\s-]+ATTRIBUTES\s*$") #MACRO/MODULE m = patt.match(s) if(m): print "Table Name", s return True patt = re.compile("^\s+[A-Za-z\s]+Attributes\s*$") #MACRO/MODULE m = patt.match(s) if(m): print "Table Name", s return True # PALETTE COLOR LOOKUP MODULE patt = re.compile("^\s+[A-Z\s]+MODULE\s*$") #MACRO/MODULE m = patt.match(s) if(m): print "Table Name", s return True # MR IMAGE AND SPECTROSCOPY INSTANCE MACRO patt = re.compile("^\s+[A-Z\s]+MACRO\s*$") #MACRO/MODULE m = patt.match(s) if(m): print "Table Name", s return True # Enhanced XA/XRF Image Module Table patt = re.compile("^\s+[A-Z/a-z\s]+Module Table\s*$") m = patt.match(s) if(m): print "Table Name", s return True # Presentation LUT Module #patt = re.compile("^\s+Presentation LUT Module\s*$") #m = patt.match(s) #if(m): # print "Table Name", s # return True print "TableName failed with:", s return False def IsTableName2(self,s): # grrrrr: Table C.8-37 - RT SERIES MODULE ATTRIBUTES # Table C.8-39--RT DOSE MODULE ATTRIBUTES patt = re.compile("^\s+Table\s+C.[0-9A-Za-z-]+\s*[-]*\s*([A-Z/\s-]+)\s*$") m = patt.match(s) # The previous regex would think : Table C.7-17A # is correct...I don't know how to fix the regex, so discard result if # len(m.group(1)) <= 1 if(m and len(m.group(1)) > 1): print "Table Name:", m.group(1) assert self.IsTableName( m.group(1) ) return True print "TableName2 failed with:", s return False def IsTableDescription(self,s): patt = re.compile("^\s*Attribute Name\s+Tag\s+Type\s+Attribute Description\s*$") m = patt.match(s) if(m): print "Table Description:", s return True # Around page 574 patt = re.compile("^\s*Attribute [Nn]ame\s+Tag\s+Type\s+Description\s*$") m = patt.match(s) if(m): print "Table Description:", s return True return False def IsFirstLineAttribute(self,s): # Line should look like: # Bits Stored ... (0028,0101) ... 1 ... Number of bits stored for each pixel patt = re.compile("^\s*(.*)\\([0-9A-Fx]+,[0-9A-F]+\\)\s+([1-3C]+).*\s*$") #MACRO/MODULE m = patt.match(s) if(m): s1 = m.group(1).strip() if s1 == '': return False #print "First Line Attribute:", s1, s return True #print "No:", s return False def IsIncludeTable(self,s): # Need to support : "Include `Image Pixel Macro' Table C.7-11b" #assert self._Shift == 0 #print "Include:", s #patt = re.compile("^>*Include `(.*)' Table [A-Z0-9a-z-.]+$") #m = patt.match(s) #if m: # return True #patt = re.compile("^>*Include [`|'](.*)' Table [A-Z0-9a-z-.]+\s+Defined Context ID is.*$") #m = patt.match(s) #return m #print "FALLBACK" patt = re.compile("^>*\s*Include [`'\"]*([A-Za-z/ -]*)['\"]* \\(*Table [A-Z0-9a-z-.]+\\)*.*$") m = patt.match(s) #if not m: # print "FAIL", s return m def IsNextLineAttribute(self,s): if self._Shift == 0: print "IsNextLineAttribute failed with", s return False if len(s) <= self._Shift: print "IsNextLineAttribute failed with", s return False blank = s[0:self._Shift] blank = blank.strip() #print "BLANK:", blank if blank == '': self._CurrentAttribute.AppendDescription( s ) return True # The following is really ugly ... need to be fixed if blank == 'Descriptor' or blank == 'Data' or blank == 'Center Name' \ or blank == 'Description' \ or blank == 'Sequence' \ or blank == 'Distance' \ or blank == 'Index' \ or blank == 'Reordering' \ or blank == 'Time' \ or blank == 'Device Number' \ or blank == 'Justification' \ or blank == 'Shape' \ or blank == 'Relationship' \ or blank == 'in Float' \ or blank == 'Displacement' \ or blank == 'Technique Description' \ or blank == 'Left Vertical Edge' \ or blank == 'State Sequence' \ or blank == 'In-plane' \ or blank == 'Certification Number' \ or blank == 'Right Vertical Edge' \ or blank == 'Accumulated' \ or blank == 'Equivalent Thickness' \ or blank == 'Distances' \ or blank == 'Definition' \ or blank == 'Upper Horizontal Edge' \ or blank == 'Modification' \ or blank == 'Power Ratio' \ or blank == 'Lower Horizontal Edge' \ or blank == 'Device Distance' \ or blank == 'Sensing Region' \ or blank == 'Control Sensing Region' \ or blank == 'Water Equivalent Thickness' \ or blank == 'Columns' \ or blank == 'Rows' \ or blank == 'Ratio' \ or blank == 'Display Grayscale Value' \ or blank == 'Display CIELab Value' \ or blank == 'UID' \ or blank == 'Units' \ or blank == 'Pointer' \ or blank == 'Value' \ or blank == 'Annotation' \ or blank == 'Pointer Private Creator' \ or blank == 'Creator' \ or blank == 'Value Mapping Sequence' \ or blank == 'Performed Procedure' \ or blank == 'MAC Sequence' \ or blank == 'Class UID' \ or blank == 'Instance UID' \ or blank == 'Syntax UID' \ or blank == 'Used' \ or blank == 'Identifier' \ or blank == 'Datetime' \ or blank == 'plane Phase Steps' \ or blank == '(Patient)' \ or blank == 'Collection Center' \ or blank == 'Technique' \ or blank == 'Interpretation' \ or blank == 'Representation' \ or blank == 'Configuration' \ or blank == 'Compression' \ or blank == 'Reference Code' \ or blank == 'Encoding Steps' \ or blank == 'Steps in-plane' \ or blank == 'Steps out-of-plane' \ or blank == 'Type' \ or blank == 'Explanation' \ or blank == 'Mapped' \ or blank == 'Calibration' \ or blank == 'Manufactured' \ or blank == 'Thickness' \ or blank == 'Reference Sequence' \ or blank == 'Reference Number' \ or blank == 'Transmission' \ or blank == 'Matrix' \ or blank == 'Comment' \ or blank == 'Setup Sequence' \ or blank == 'Setup Number' \ or blank == 'Fraction' \ or blank == 'Tolerance' \ or blank == 'Number' \ or blank == 'Day' \ or blank == 'Parameters' \ or blank == 'Coefficient' \ or blank == 'Specification Point' \ or blank == 'Identification Sequence' \ or blank == 'Reference UID' \ or blank == 'Synchronized' \ or blank == 'Description Code Sequence' \ or blank == 'Concentration' \ or blank == 'Procedure Step' \ or blank == 'Manufacturer' \ or blank == 'Lookup Table Data' \ or blank == 'Version' \ or blank == 'Images' \ or blank == 'Wavelength' \ or blank == 'Code Sequence' \ or blank == 'Housing' \ or blank == 'Exposure' \ or blank == 'Beam' \ or blank == 'Angle' \ or blank == 'Rotation Angle' \ or blank == 'Corner' \ or blank == 'Factor' \ or blank == 'Product' \ or blank == "Manufacturer's Model Name" \ or blank == 'Qualifier Code' \ or blank == 'Mapping Instance Sequence' \ or blank == 'Channels' \ or blank == 'Samples' \ or blank == 'Transformation Comment' \ or blank == 'Pixels' \ or blank == 'Correction Factor' \ or blank == 'Group' \ or blank == 'Amount' \ or blank == 'Priority' \ or blank == 'Group Name' \ or blank == 'Frame Rate' \ or blank == 'Presence' \ or blank == 'Sequencing' \ or blank == 'Orientation' \ or blank == 'Inverted' \ or blank == 'Numbers' \ or blank == 'Flag' \ or blank == 'Annotation Flag' \ or blank == 'Demographics Flag' \ or blank == 'Techniques Flag' \ or blank == 'Group Description' \ or blank == 'Handling' \ or blank == 'Initial View Direction' \ or blank == 'Identification Code Sequence' \ or blank == 'Identification Code' \ or blank == 'Category' \ or blank == 'Spatial Position' \ or blank == 'Creation Datetime' \ or blank == 'Grayscale Bit Depth' \ or blank == 'Bit Depth' \ or blank == 'Repaint Time' \ or blank == 'Definition Sequence' \ or blank == 'Procedure Code' \ or blank == 'Referenced' \ or blank == 'Reference' \ or blank == 'Usage Flag' \ or blank == 'Horizontal Dimension' \ or blank == 'Dimension' \ or blank == 'Direction' \ or blank == 'Registration Sequence' \ or blank == 'Transformation Matrix' \ or blank == 'Transformation Matrix Type' \ or blank == 'Step Sequence': self._CurrentAttribute.AppendName( blank ) self._CurrentAttribute.AppendDescription( s[self._Shift:] ) return True else: print "ADD KEYWORD:", blank return False def FindShiftValue(self,s): # Line should look like: # Bits Stored ... (0028,0101) ... 1 ... Number of bits stored for each pixel patt = re.compile("^[A-Za-z0-9µ /()'>-]+\s+\\([0-9A-Fx]+,[0-9A-F]+\\)\s+[1-3][C]*\s+(.*)$") m = patt.match(s) if(m): # worse case happen around page 448 with `Required` # worse case happen around page 475 with `LOG`... self._Shift = s.find( m.group(1) ) - 17 return self._Shift print "OUCH:", s return 0 def Open(self): #self._Infile = file(self._InputFilename, 'r') #for line in self._Infile.readlines(): # line = line[:-1] # remove '\n' # if( self.IsStartTable(line) ): # print line.next() cmd_input = open(self._InputFilename,'r') outfile = open(self._OutputFilename, 'w') # To support some weird output from pdftotext outfile.write( '<?xml version="1.0" encoding="ISO-8859-1"?>' ) outfile.write( '<tables>' ) for line_ori in cmd_input: #while line.startswith('%') : # skip comment lines #print "!!!",line #line= cmd_input.next() line = line_ori[:-1] if( self.IsStartTable(line) ): table_name_found = self.IsTableName2(line) line2 = line # Okay table is on next line: if ( not table_name_found ): line2 = cmd_input.next()[:-1] table_name_found = self.IsTableName(line2) # Either way we need to find the table name assert table_name_found if( table_name_found ): line3 = cmd_input.next()[:-1] if( self.IsTableDescription(line3) ): # Ok we found a table outfile.write( "<table ref=\""+line.strip()+"\" name=\""+line2.strip()+"\">" ) buffer = '' self._CurrentAttribute = Attribute() self._Shift = 0 for subline_ori in cmd_input: subline = subline_ori[:-1] if( self.IsIncludeTable(subline)): # BUG DO NOT SUPPORT MULTI_LINE INCLUDE #print "Include Table:", subline if( subline != '' ): outfile.write( "<include ref=\""+\ subline.replace('"','&quot;')+"\"/>" ) outfile.write( '\n' ) elif( self.IsFirstLineAttribute(subline)): #print "Previous Buffer was: ", buffer if( buffer != '' ): outfile.write( self._CurrentAttribute.GetAsXML() ) outfile.write( '\n' ) self._CurrentAttribute.SetInit(subline) self.FindShiftValue(subline) assert self._Shift != 0 buffer = subline else: if( not self.IsComment(subline) ): #print "Found Comment: ", subline if( self.IsNextLineAttribute(subline) ): buffer += ' ' + subline.strip() else: print "Wotsit:", subline self._Shift = 0 self._IsInTable = False if( buffer != '' ): outfile.write( self._CurrentAttribute.GetAsXML() ) outfile.write( '\n' ) outfile.write( '</table>' ) break #print "Working on: ", subline if not subline_ori: break else: print "Problem with:", line, line2 #line = cmd_input.next() if not line_ori: break cmd_input.close() outfile.write( '</tables>' ) self.Write() def Write(self): print "Write" # Main function to call for parsing def Parse(self): self.Open() if __name__ == "__main__": argc = len(os.sys.argv ) if ( argc < 3 ): print "Sorry, wrong list of args" os.sys.exit(1) #error inputfilename = os.sys.argv[1] outputfilename = os.sys.argv[2] tempfile = "/tmp/mytemp2" dp = Part3Parser() dp.SetInputFileName( inputfilename ) dp.SetOutputFileName( tempfile ) dp.Parse()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 6695, 26, 663, 570, 2991, 29, 4595, 13, 4830, 13, 17, 199, 199, 624, 199, 4, 11249, 475, 505, 446, 4209, 446, 20443, 71, 3289, 75, 446, 70, 25989, 446, 76, 650, 1717, 24937, 63, 1644, 3165, 14, 5607, 2034, 11810, 14, 2424, 199, 199, 4, 2366, 221, 6077, 5379, 14, 647, 2034, 15000, 13, 5279, 14, 2424, 734, 14, 2424, 690, 943, 18, 199, 4, 20595, 21380, 943, 18, 1204, 20595, 446, 86, 298, 18685, 5424, 1204, 20595, 446, 86, 298, 7443, 5424, 1204, 20595, 446, 86, 298, 35, 14, 24, 2, 1204, 20595, 446, 86, 298, 35, 14, 23, 2, 199, 199, 624, 199, 646, 295, 12, 736, 199, 199, 624, 199, 199, 624, 199, 533, 3882, 26, 523, 327, 445, 8041, 523, 347, 636, 826, 721, 277, 304, 272, 291, 423, 985, 275, 2125, 272, 291, 423, 1931, 275, 8189, 993, 12, 993, 3171, 272, 291, 423, 804, 275, 2125, 272, 291, 423, 5831, 29, 2125, 523, 347, 2494, 9346, 8, 277, 12, 83, 304, 272, 327, 7719, 506, 6020, 2839, 26, 272, 327, 22447, 510, 22116, 11581, 12785, 6957, 755, 334, 30963, 12, 6019, 19, 9, 258, 413, 35, 257, 11015, 314, 1475, 402, 314, 22447, 510, 22116, 272, 299, 6796, 275, 295, 14, 2014, 18523, 19276, 5130, 1103, 779, 16, 13, 25, 33, 13, 38, 88, 2807, 14343, 16, 13, 25, 33, 13, 38, 2807, 1103, 25105, 83, 11, 779, 17, 13, 19, 35, 18096, 83, 15622, 2795, 2862, 83, 10, 22550, 272, 333, 275, 299, 6796, 14, 1431, 8, 83, 9, 272, 340, 440, 333, 26, 489, 870, 308, 489, 702, 378, 272, 291, 423, 985, 275, 333, 14, 923, 8, 17, 680, 1913, 342, 272, 291, 423, 1931, 275, 333, 14, 923, 8, 18, 680, 1913, 342, 272, 291, 423, 804, 275, 333, 14, 923, 8, 19, 680, 1913, 342, 272, 291, 423, 5831, 275, 333, 14, 923, 8, 20, 680, 1913, 342, 523, 347, 2494, 985, 8, 277, 12, 83, 304, 272, 291, 423, 985, 275, 308, 523, 347, 18726, 985, 8, 277, 12, 83, 304, 272, 291, 423, 985, 847, 298, 298, 272, 291, 423, 985, 847, 308, 14, 1913, 342, 523, 347, 2494, 1931, 8, 277, 12, 83, 304, 272, 291, 423, 1931, 275, 308, 523, 347, 2494, 804, 8, 277, 12, 83, 304, 272, 291, 423, 804, 275, 308, 523, 347, 2494, 5831, 8, 277, 12, 83, 304, 272, 291, 423, 5831, 275, 308, 523, 347, 18726, 5831, 8, 277, 12, 83, 304, 272, 291, 423, 5831, 847, 298, 298, 272, 291, 423, 5831, 847, 308, 14, 1913, 342, 523, 347, 2372, 2822, 4317, 8, 277, 304, 272, 1369, 275, 291, 423, 5831, 14, 1814, 14088, 1673, 6, 5184, 10784, 272, 1369, 275, 1369, 14, 1814, 20040, 1673, 6, 5282, 10784, 272, 372, 3886, 2373, 1572, 9529, 341, 11, 277, 423, 1931, 59, 17, 26, 21, 2807, 3212, 2, 1819, 9529, 341, 11, 277, 423, 1931, 59, 22, 26, 709, 2807, 3212, 2, 536, 9529, 341, 11, 277, 423, 985, 14, 1814, 20040, 1673, 6, 5282, 10784, 25789, 2, 730, 9529, 341, 11, 277, 423, 804, 25789, 2, 1369, 9529, 341, 11, 1802, 25789, 10070, 2373, 4335, 523, 347, 9101, 8, 277, 304, 272, 870, 291, 14, 1002, 2822, 4317, 342, 199, 199, 533, 14320, 19, 2842, 26, 523, 327, 445, 8041, 523, 347, 636, 826, 721, 277, 304, 272, 291, 423, 3205, 8117, 275, 2125, 272, 291, 423, 2959, 8117, 275, 2125, 272, 291, 423, 3299, 275, 2125, 272, 291, 423, 5639, 1646, 275, 3882, 342, 272, 291, 423, 1831, 607, 3186, 275, 756, 272, 291, 423, 14379, 275, 378, 819, 347, 2494, 3205, 7733, 8, 277, 12, 83, 304, 272, 291, 423, 3205, 8117, 275, 308, 819, 347, 2494, 32441, 8, 277, 12, 83, 304, 272, 291, 423, 2959, 8117, 275, 308, 819, 347, 6596, 7488, 8, 277, 12, 83, 304, 272, 340, 822, 8, 83, 9, 508, 378, 26, 489, 372, 715, 272, 299, 6796, 17, 275, 295, 14, 2014, 480, 12773, 83, 16341, 9739, 446, 60, 83, 10, 22550, 272, 299, 6796, 18, 275, 295, 14, 2014, 480, 12773, 83, 10, 5067, 650, 14, 19, 446, 10219, 60, 83, 10, 531, 272, 299, 6796, 19, 275, 295, 14, 2014, 480, 12773, 83, 10, 3276, 60, 83, 21324, 16, 13, 25, 24621, 83, 10, 22550, 272, 299, 6796, 20, 275, 295, 14, 2014, 480, 12773, 83, 10, 18685, 26, 22550, 272, 333, 17, 275, 299, 6796, 17, 14, 1431, 8, 83, 9, 272, 333, 18, 275, 299, 6796, 18, 14, 1431, 8, 83, 9, 272, 333, 19, 275, 299, 6796, 19, 14, 1431, 8, 83, 9, 272, 333, 20, 275, 299, 6796, 20, 14, 1431, 8, 83, 9, 272, 340, 8, 77, 17, 503, 333, 18, 503, 333, 19, 503, 333, 20, 304, 489, 870, 298, 7488, 6783, 308, 489, 372, 715, 272, 340, 291, 14, 1831, 3186, 5831, 8, 83, 304, 489, 372, 715, 272, 372, 756, 819, 347, 6596, 3162, 3186, 8, 277, 12, 83, 304, 272, 327, 80, 6796, 275, 295, 14, 2014, 480, 12773, 83, 11, 3186, 445, 59, 16, 13, 25, 65, 13, 90, 4537, 20253, 17910, 83, 11, 22550, 272, 299, 6796, 275, 295, 14, 2014, 480, 12773, 83, 11, 3186, 60, 83, 11, 35, 24097, 16, 13, 25, 33, 13, 13163, 13, 90, 30858, 24621, 83, 10, 22550, 272, 333, 275, 299, 6796, 14, 1431, 8, 83, 9, 272, 702, 291, 423, 1831, 607, 3186, 1137, 715, 272, 291, 423, 1831, 607, 3186, 275, 756, 272, 340, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 1789, 7, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 1194, 7, 971, 489, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 14, 22, 14, 709, 13, 17, 7, 971, 489, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 821, 7, 971, 489, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 1479, 7, 971, 489, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 1465, 7, 971, 489 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 6695, 26, 663, 570, 2991, 29, 4595, 13, 4830, 13, 17, 199, 199, 624, 199, 4, 11249, 475, 505, 446, 4209, 446, 20443, 71, 3289, 75, 446, 70, 25989, 446, 76, 650, 1717, 24937, 63, 1644, 3165, 14, 5607, 2034, 11810, 14, 2424, 199, 199, 4, 2366, 221, 6077, 5379, 14, 647, 2034, 15000, 13, 5279, 14, 2424, 734, 14, 2424, 690, 943, 18, 199, 4, 20595, 21380, 943, 18, 1204, 20595, 446, 86, 298, 18685, 5424, 1204, 20595, 446, 86, 298, 7443, 5424, 1204, 20595, 446, 86, 298, 35, 14, 24, 2, 1204, 20595, 446, 86, 298, 35, 14, 23, 2, 199, 199, 624, 199, 646, 295, 12, 736, 199, 199, 624, 199, 199, 624, 199, 533, 3882, 26, 523, 327, 445, 8041, 523, 347, 636, 826, 721, 277, 304, 272, 291, 423, 985, 275, 2125, 272, 291, 423, 1931, 275, 8189, 993, 12, 993, 3171, 272, 291, 423, 804, 275, 2125, 272, 291, 423, 5831, 29, 2125, 523, 347, 2494, 9346, 8, 277, 12, 83, 304, 272, 327, 7719, 506, 6020, 2839, 26, 272, 327, 22447, 510, 22116, 11581, 12785, 6957, 755, 334, 30963, 12, 6019, 19, 9, 258, 413, 35, 257, 11015, 314, 1475, 402, 314, 22447, 510, 22116, 272, 299, 6796, 275, 295, 14, 2014, 18523, 19276, 5130, 1103, 779, 16, 13, 25, 33, 13, 38, 88, 2807, 14343, 16, 13, 25, 33, 13, 38, 2807, 1103, 25105, 83, 11, 779, 17, 13, 19, 35, 18096, 83, 15622, 2795, 2862, 83, 10, 22550, 272, 333, 275, 299, 6796, 14, 1431, 8, 83, 9, 272, 340, 440, 333, 26, 489, 870, 308, 489, 702, 378, 272, 291, 423, 985, 275, 333, 14, 923, 8, 17, 680, 1913, 342, 272, 291, 423, 1931, 275, 333, 14, 923, 8, 18, 680, 1913, 342, 272, 291, 423, 804, 275, 333, 14, 923, 8, 19, 680, 1913, 342, 272, 291, 423, 5831, 275, 333, 14, 923, 8, 20, 680, 1913, 342, 523, 347, 2494, 985, 8, 277, 12, 83, 304, 272, 291, 423, 985, 275, 308, 523, 347, 18726, 985, 8, 277, 12, 83, 304, 272, 291, 423, 985, 847, 298, 298, 272, 291, 423, 985, 847, 308, 14, 1913, 342, 523, 347, 2494, 1931, 8, 277, 12, 83, 304, 272, 291, 423, 1931, 275, 308, 523, 347, 2494, 804, 8, 277, 12, 83, 304, 272, 291, 423, 804, 275, 308, 523, 347, 2494, 5831, 8, 277, 12, 83, 304, 272, 291, 423, 5831, 275, 308, 523, 347, 18726, 5831, 8, 277, 12, 83, 304, 272, 291, 423, 5831, 847, 298, 298, 272, 291, 423, 5831, 847, 308, 14, 1913, 342, 523, 347, 2372, 2822, 4317, 8, 277, 304, 272, 1369, 275, 291, 423, 5831, 14, 1814, 14088, 1673, 6, 5184, 10784, 272, 1369, 275, 1369, 14, 1814, 20040, 1673, 6, 5282, 10784, 272, 372, 3886, 2373, 1572, 9529, 341, 11, 277, 423, 1931, 59, 17, 26, 21, 2807, 3212, 2, 1819, 9529, 341, 11, 277, 423, 1931, 59, 22, 26, 709, 2807, 3212, 2, 536, 9529, 341, 11, 277, 423, 985, 14, 1814, 20040, 1673, 6, 5282, 10784, 25789, 2, 730, 9529, 341, 11, 277, 423, 804, 25789, 2, 1369, 9529, 341, 11, 1802, 25789, 10070, 2373, 4335, 523, 347, 9101, 8, 277, 304, 272, 870, 291, 14, 1002, 2822, 4317, 342, 199, 199, 533, 14320, 19, 2842, 26, 523, 327, 445, 8041, 523, 347, 636, 826, 721, 277, 304, 272, 291, 423, 3205, 8117, 275, 2125, 272, 291, 423, 2959, 8117, 275, 2125, 272, 291, 423, 3299, 275, 2125, 272, 291, 423, 5639, 1646, 275, 3882, 342, 272, 291, 423, 1831, 607, 3186, 275, 756, 272, 291, 423, 14379, 275, 378, 819, 347, 2494, 3205, 7733, 8, 277, 12, 83, 304, 272, 291, 423, 3205, 8117, 275, 308, 819, 347, 2494, 32441, 8, 277, 12, 83, 304, 272, 291, 423, 2959, 8117, 275, 308, 819, 347, 6596, 7488, 8, 277, 12, 83, 304, 272, 340, 822, 8, 83, 9, 508, 378, 26, 489, 372, 715, 272, 299, 6796, 17, 275, 295, 14, 2014, 480, 12773, 83, 16341, 9739, 446, 60, 83, 10, 22550, 272, 299, 6796, 18, 275, 295, 14, 2014, 480, 12773, 83, 10, 5067, 650, 14, 19, 446, 10219, 60, 83, 10, 531, 272, 299, 6796, 19, 275, 295, 14, 2014, 480, 12773, 83, 10, 3276, 60, 83, 21324, 16, 13, 25, 24621, 83, 10, 22550, 272, 299, 6796, 20, 275, 295, 14, 2014, 480, 12773, 83, 10, 18685, 26, 22550, 272, 333, 17, 275, 299, 6796, 17, 14, 1431, 8, 83, 9, 272, 333, 18, 275, 299, 6796, 18, 14, 1431, 8, 83, 9, 272, 333, 19, 275, 299, 6796, 19, 14, 1431, 8, 83, 9, 272, 333, 20, 275, 299, 6796, 20, 14, 1431, 8, 83, 9, 272, 340, 8, 77, 17, 503, 333, 18, 503, 333, 19, 503, 333, 20, 304, 489, 870, 298, 7488, 6783, 308, 489, 372, 715, 272, 340, 291, 14, 1831, 3186, 5831, 8, 83, 304, 489, 372, 715, 272, 372, 756, 819, 347, 6596, 3162, 3186, 8, 277, 12, 83, 304, 272, 327, 80, 6796, 275, 295, 14, 2014, 480, 12773, 83, 11, 3186, 445, 59, 16, 13, 25, 65, 13, 90, 4537, 20253, 17910, 83, 11, 22550, 272, 299, 6796, 275, 295, 14, 2014, 480, 12773, 83, 11, 3186, 60, 83, 11, 35, 24097, 16, 13, 25, 33, 13, 13163, 13, 90, 30858, 24621, 83, 10, 22550, 272, 333, 275, 299, 6796, 14, 1431, 8, 83, 9, 272, 702, 291, 423, 1831, 607, 3186, 1137, 715, 272, 291, 423, 1831, 607, 3186, 275, 756, 272, 340, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 1789, 7, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 1194, 7, 971, 489, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 14, 22, 14, 709, 13, 17, 7, 971, 489, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 821, 7, 971, 489, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 1479, 7, 971, 489, 503, 308, 14, 1913, 342, 508, 283, 3186, 445, 14, 23, 13, 1465, 7, 971, 489, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
liangazhou/django-rdp
packages/Django-1.8.6/build/lib/django/contrib/sessions/backends/cache.py
45
2594
from django.conf import settings from django.contrib.sessions.backends.base import CreateError, SessionBase from django.core.cache import caches from django.utils.six.moves import range KEY_PREFIX = "django.contrib.sessions.cache" class SessionStore(SessionBase): """ A cache-based session store. """ def __init__(self, session_key=None): self._cache = caches[settings.SESSION_CACHE_ALIAS] super(SessionStore, self).__init__(session_key) @property def cache_key(self): return KEY_PREFIX + self._get_or_create_session_key() def load(self): try: session_data = self._cache.get(self.cache_key, None) except Exception: # Some backends (e.g. memcache) raise an exception on invalid # cache keys. If this happens, reset the session. See #17810. session_data = None if session_data is not None: return session_data self._session_key = None return {} def create(self): # Because a cache can fail silently (e.g. memcache), we don't know if # we are failing to create a new session because of a key collision or # because the cache is missing. So we try for a (large) number of times # and then raise an exception. That's the risk you shoulder if using # cache backing. for i in range(10000): self._session_key = self._get_new_session_key() try: self.save(must_create=True) except CreateError: continue self.modified = True return raise RuntimeError( "Unable to create a new session key. " "It is likely that the cache is unavailable.") def save(self, must_create=False): if self.session_key is None: return self.create() if must_create: func = self._cache.add else: func = self._cache.set result = func(self.cache_key, self._get_session(no_load=must_create), self.get_expiry_age()) if must_create and not result: raise CreateError def exists(self, session_key): return session_key and (KEY_PREFIX + session_key) in self._cache def delete(self, session_key=None): if session_key is None: if self.session_key is None: return session_key = self.session_key self._cache.delete(KEY_PREFIX + session_key) @classmethod def clear_expired(cls): pass
apache-2.0
[ 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 2828, 14, 11676, 14, 7765, 14, 1095, 492, 2790, 547, 12, 8596, 1563, 199, 504, 1639, 14, 1018, 14, 1637, 492, 18014, 199, 504, 1639, 14, 1208, 14, 4174, 14, 4912, 492, 1425, 199, 199, 3078, 63, 6351, 275, 298, 1176, 14, 2828, 14, 11676, 14, 1637, 2, 421, 199, 533, 8596, 5502, 8, 4434, 1563, 304, 272, 408, 272, 437, 2581, 13, 6788, 2351, 3877, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 2351, 63, 498, 29, 403, 304, 267, 291, 423, 1637, 275, 18014, 59, 1751, 14, 12763, 63, 8677, 63, 12644, 61, 267, 1613, 8, 4434, 5502, 12, 291, 2843, 826, 721, 1730, 63, 498, 9, 339, 768, 1829, 272, 347, 2581, 63, 498, 8, 277, 304, 267, 372, 9301, 63, 6351, 435, 291, 423, 362, 63, 269, 63, 981, 63, 1730, 63, 498, 342, 339, 347, 2248, 8, 277, 304, 267, 862, 26, 288, 2351, 63, 576, 275, 291, 423, 1637, 14, 362, 8, 277, 14, 1637, 63, 498, 12, 488, 9, 267, 871, 2186, 26, 288, 327, 6601, 14745, 334, 69, 14, 71, 14, 21598, 9, 746, 376, 1919, 641, 3866, 288, 327, 2581, 2883, 14, 982, 642, 10986, 12, 5305, 314, 2351, 14, 1666, 327, 11175, 709, 14, 288, 2351, 63, 576, 275, 488, 267, 340, 2351, 63, 576, 365, 440, 488, 26, 288, 372, 2351, 63, 576, 267, 291, 423, 1730, 63, 498, 275, 488, 267, 372, 1052, 339, 347, 1218, 8, 277, 304, 267, 327, 13821, 282, 2581, 883, 2449, 18030, 334, 69, 14, 71, 14, 21598, 395, 781, 2793, 1133, 5715, 340, 267, 327, 781, 787, 18648, 370, 1218, 282, 892, 2351, 2952, 402, 282, 790, 25061, 503, 267, 327, 2952, 314, 2581, 365, 4124, 14, 2002, 781, 862, 367, 282, 334, 9629, 9, 1329, 402, 5431, 267, 327, 436, 2066, 746, 376, 1919, 14, 10314, 1159, 314, 22633, 1265, 930, 348, 424, 340, 1808, 267, 327, 2581, 21094, 14, 267, 367, 284, 315, 1425, 8, 9943, 304, 288, 291, 423, 1730, 63, 498, 275, 291, 423, 362, 63, 1222, 63, 1730, 63, 498, 342, 288, 862, 26, 355, 291, 14, 2117, 8, 7790, 63, 981, 29, 549, 9, 288, 871, 2790, 547, 26, 355, 1980, 288, 291, 14, 5540, 275, 715, 288, 372, 267, 746, 6064, 8, 288, 298, 6005, 370, 1218, 282, 892, 2351, 790, 14, 298, 288, 298, 7940, 365, 12060, 626, 314, 2581, 365, 18735, 2685, 339, 347, 3354, 8, 277, 12, 1471, 63, 981, 29, 797, 304, 267, 340, 291, 14, 1730, 63, 498, 365, 488, 26, 288, 372, 291, 14, 981, 342, 267, 340, 1471, 63, 981, 26, 288, 2562, 275, 291, 423, 1637, 14, 525, 267, 587, 26, 288, 2562, 275, 291, 423, 1637, 14, 409, 267, 754, 275, 2562, 8, 277, 14, 1637, 63, 498, 12, 1993, 291, 423, 362, 63, 1730, 8, 889, 63, 912, 29, 7790, 63, 981, 395, 1993, 291, 14, 362, 63, 16844, 63, 474, 1012, 267, 340, 1471, 63, 981, 436, 440, 754, 26, 288, 746, 2790, 547, 339, 347, 3495, 8, 277, 12, 2351, 63, 498, 304, 267, 372, 2351, 63, 498, 436, 334, 3078, 63, 6351, 435, 2351, 63, 498, 9, 315, 291, 423, 1637, 339, 347, 3145, 8, 277, 12, 2351, 63, 498, 29, 403, 304, 267, 340, 2351, 63, 498, 365, 488, 26, 288, 340, 291, 14, 1730, 63, 498, 365, 488, 26, 355, 372, 288, 2351, 63, 498, 275, 291, 14, 1730, 63, 498, 267, 291, 423, 1637, 14, 1807, 8, 3078, 63, 6351, 435, 2351, 63, 498, 9, 339, 768, 3744, 272, 347, 5436, 63, 16340, 8, 1886, 304, 267, 986, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 2828, 14, 11676, 14, 7765, 14, 1095, 492, 2790, 547, 12, 8596, 1563, 199, 504, 1639, 14, 1018, 14, 1637, 492, 18014, 199, 504, 1639, 14, 1208, 14, 4174, 14, 4912, 492, 1425, 199, 199, 3078, 63, 6351, 275, 298, 1176, 14, 2828, 14, 11676, 14, 1637, 2, 421, 199, 533, 8596, 5502, 8, 4434, 1563, 304, 272, 408, 272, 437, 2581, 13, 6788, 2351, 3877, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 2351, 63, 498, 29, 403, 304, 267, 291, 423, 1637, 275, 18014, 59, 1751, 14, 12763, 63, 8677, 63, 12644, 61, 267, 1613, 8, 4434, 5502, 12, 291, 2843, 826, 721, 1730, 63, 498, 9, 339, 768, 1829, 272, 347, 2581, 63, 498, 8, 277, 304, 267, 372, 9301, 63, 6351, 435, 291, 423, 362, 63, 269, 63, 981, 63, 1730, 63, 498, 342, 339, 347, 2248, 8, 277, 304, 267, 862, 26, 288, 2351, 63, 576, 275, 291, 423, 1637, 14, 362, 8, 277, 14, 1637, 63, 498, 12, 488, 9, 267, 871, 2186, 26, 288, 327, 6601, 14745, 334, 69, 14, 71, 14, 21598, 9, 746, 376, 1919, 641, 3866, 288, 327, 2581, 2883, 14, 982, 642, 10986, 12, 5305, 314, 2351, 14, 1666, 327, 11175, 709, 14, 288, 2351, 63, 576, 275, 488, 267, 340, 2351, 63, 576, 365, 440, 488, 26, 288, 372, 2351, 63, 576, 267, 291, 423, 1730, 63, 498, 275, 488, 267, 372, 1052, 339, 347, 1218, 8, 277, 304, 267, 327, 13821, 282, 2581, 883, 2449, 18030, 334, 69, 14, 71, 14, 21598, 395, 781, 2793, 1133, 5715, 340, 267, 327, 781, 787, 18648, 370, 1218, 282, 892, 2351, 2952, 402, 282, 790, 25061, 503, 267, 327, 2952, 314, 2581, 365, 4124, 14, 2002, 781, 862, 367, 282, 334, 9629, 9, 1329, 402, 5431, 267, 327, 436, 2066, 746, 376, 1919, 14, 10314, 1159, 314, 22633, 1265, 930, 348, 424, 340, 1808, 267, 327, 2581, 21094, 14, 267, 367, 284, 315, 1425, 8, 9943, 304, 288, 291, 423, 1730, 63, 498, 275, 291, 423, 362, 63, 1222, 63, 1730, 63, 498, 342, 288, 862, 26, 355, 291, 14, 2117, 8, 7790, 63, 981, 29, 549, 9, 288, 871, 2790, 547, 26, 355, 1980, 288, 291, 14, 5540, 275, 715, 288, 372, 267, 746, 6064, 8, 288, 298, 6005, 370, 1218, 282, 892, 2351, 790, 14, 298, 288, 298, 7940, 365, 12060, 626, 314, 2581, 365, 18735, 2685, 339, 347, 3354, 8, 277, 12, 1471, 63, 981, 29, 797, 304, 267, 340, 291, 14, 1730, 63, 498, 365, 488, 26, 288, 372, 291, 14, 981, 342, 267, 340, 1471, 63, 981, 26, 288, 2562, 275, 291, 423, 1637, 14, 525, 267, 587, 26, 288, 2562, 275, 291, 423, 1637, 14, 409, 267, 754, 275, 2562, 8, 277, 14, 1637, 63, 498, 12, 1993, 291, 423, 362, 63, 1730, 8, 889, 63, 912, 29, 7790, 63, 981, 395, 1993, 291, 14, 362, 63, 16844, 63, 474, 1012, 267, 340, 1471, 63, 981, 436, 440, 754, 26, 288, 746, 2790, 547, 339, 347, 3495, 8, 277, 12, 2351, 63, 498, 304, 267, 372, 2351, 63, 498, 436, 334, 3078, 63, 6351, 435, 2351, 63, 498, 9, 315, 291, 423, 1637, 339, 347, 3145, 8, 277, 12, 2351, 63, 498, 29, 403, 304, 267, 340, 2351, 63, 498, 365, 488, 26, 288, 340, 291, 14, 1730, 63, 498, 365, 488, 26, 355, 372, 288, 2351, 63, 498, 275, 291, 14, 1730, 63, 498, 267, 291, 423, 1637, 14, 1807, 8, 3078, 63, 6351, 435, 2351, 63, 498, 9, 339, 768, 3744, 272, 347, 5436, 63, 16340, 8, 1886, 304, 267, 986, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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