Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# __coconut_hash__ = 0x4c19e3b9
# Compiled with Coconut version 1.4.0-post_dev2 [Ernest Scribbler]
# Coconut Header: -------------------------------------------------------------
from __future__ import print_function, absolute_import, unicode_literals, division
import sys as _coconut_sys
if _coconut_sys.version_info < (3,):
from __builtin__ import chr, filter, hex, input, int, map, object, oct, open, print, range, str, zip, filter, reversed, enumerate, raw_input, xrange
py_chr, py_hex, py_input, py_int, py_map, py_object, py_oct, py_open, py_print, py_range, py_str, py_zip, py_filter, py_reversed, py_enumerate, py_raw_input, py_xrange = chr, hex, input, int, map, object, oct, open, print, range, str, zip, filter, reversed, enumerate, raw_input, xrange
_coconut_NotImplemented, _coconut_raw_input, _coconut_xrange, _coconut_int, _coconut_long, _coconut_print, _coconut_str, _coconut_unicode, _coconut_repr = NotImplemented, raw_input, xrange, int, long, print, str, unicode, repr
from future_builtins import *
chr, str = unichr, unicode
from io import open
class object(object):
__slots__ = ()
def __ne__(self, other):
eq = self == other
if eq is _coconut_NotImplemented:
return eq
return not eq
class int(_coconut_int):
__slots__ = ()
if hasattr(_coconut_int, "__doc__"):
__doc__ = _coconut_int.__doc__
class __metaclass__(type):
def __instancecheck__(cls, inst):
return _coconut.isinstance(inst, (_coconut_int, _coconut_long))
def __subclasscheck__(cls, subcls):
return _coconut.issubclass(subcls, (_coconut_int, _coconut_long))
class range(object):
return _coconut.iter(out)
def __getitem__(self, index):
return _coconut_igetitem(_coconut.iter(self), index)
def __reversed__(self):
return _coconut_reversed(_coconut.iter(self))
def __len__(self):
return _coconut.len(self.iter)
def __repr__(self):
return "reiterable(%r)" % (self.iter,)
def __reduce__(self):
return (self.__class__, (self.iter,))
def __copy__(self):
return self.__class__(_coconut.copy.copy(self.iter))
def __fmap__(self, func):
return _coconut_map(func, self)
class scan(object):
"""Reduce func over iterable, yielding intermediate results,
optionally starting from initializer."""
__slots__ = ("func", "iter", "initializer")
empty_initializer = _coconut.object()
def __init__(self, function, iterable, initializer=empty_initializer):
self.func = function
self.iter = iterable
self.initializer = initializer
def __iter__(self):
acc = self.initializer
if acc is not self.empty_initializer:
yield acc
for item in self.iter:
if acc is self.empty_initializer:
acc = item
else:
if _coconut.isinstance(index, _coconut.slice):
return self.__class__(_coconut_igetitem(self.iter, index), self.start + (0 if index.start is None else index.start if index.start >= 0 else len(self.iter) + index.start))
return (self.start + index, _coconut_igetitem(self.iter, index))
def __len__(self):
return _coconut.len(self.iter)
def __repr__(self):
return "enumerate(%r, %r)" % (self.iter, self.start)
def __reduce__(self):
return (self.__class__, (self.iter, self.start))
def __reduce_ex__(self, _):
return self.__reduce__()
def __copy__(self):
return self.__class__(_coconut.copy.copy(self.iter), self.start)
def __fmap__(self, func):
return _coconut_map(func, self)
class count(object):
"""count(start, step) returns an infinite iterator starting at start and increasing by step.
If step is set to 0, count will infinitely repeat its first argument."""
__slots__ = ("start", "step")
def __init__(self, start=0, step=1):
self.start = start
self.step = step
def __iter__(self):
while True:
yield self.start
if self.step:
self.start += self.step
def __contains__(self, elem):
if not self.step:
return elem == self.start
if elem < self.start:
return False
"""Coconut uses Python 3 "input" instead of Python 2 "raw_input"."""
raise _coconut.NameError('Coconut uses Python 3 "input" instead of Python 2 "raw_input"')
def xrange(*args):
"""Coconut uses Python 3 "range" instead of Python 2 "xrange"."""
raise _coconut.NameError('Coconut uses Python 3 "range" instead of Python 2 "xrange"')
if _coconut_sys.version_info < (2, 7):
import functools as _coconut_functools, copy_reg as _coconut_copy_reg
def _coconut_new_partial(func, args, keywords):
return _coconut_functools.partial(func, *(args if args is not None else ()), **(keywords if keywords is not None else {}))
_coconut_copy_reg.constructor(_coconut_new_partial)
def _coconut_reduce_partial(self):
return (_coconut_new_partial, (self.func, self.args, self.keywords))
_coconut_copy_reg.pickle(_coconut_functools.partial, _coconut_reduce_partial)
else:
from builtins import chr, filter, hex, input, int, map, object, oct, open, print, range, str, zip, filter, reversed, enumerate
py_chr, py_hex, py_input, py_int, py_map, py_object, py_oct, py_open, py_print, py_range, py_str, py_zip, py_filter, py_reversed, py_enumerate = chr, hex, input, int, map, object, oct, open, print, range, str, zip, filter, reversed, enumerate
_coconut_str = str
class _coconut(object):
import collections, copy, functools, types, itertools, operator, types, weakref
if _coconut_sys.version_info < (3, 2):
try:
from backports.functools_lru_cache import lru_cache
functools.lru_cache = lru_cache
except ImportError: pass
if _coconut_sys.version_info < (3,):
import cPickle as pickle
else:
import pickle
if _coconut_sys.version_info >= (2, 7):
OrderedDict = collections.OrderedDict
else:
OrderedDict = dict
if not self.step:
return self
raise _coconut.TypeError(repr(self) + " object is not reversible")
def __repr__(self):
return "count(%r, %r)" % (self.start, self.step)
def __hash__(self):
return _coconut.hash((self.start, self.step))
def __reduce__(self):
return (self.__class__, (self.start, self.step))
def __copy__(self):
return self.__class__(self.start, self.step)
def __eq__(self, other):
return isinstance(other, self.__class__) and self.start == other.start and self.step == other.step
def __fmap__(self, func):
return _coconut_map(func, self)
class groupsof(object):
"""groupsof(n, iterable) splits iterable into groups of size n.
If the length of the iterable is not divisible by n, the last group may be of size < n."""
__slots__ = ("group_size", "iter")
def __init__(self, n, iterable):
self.iter = iterable
try:
self.group_size = _coconut.int(n)
except _coconut.ValueError:
raise _coconut.TypeError("group size must be an int; not %r" % (n,))
if self.group_size <= 0:
raise _coconut.ValueError("group size must be > 0; not %r" % (self.group_size,))
def __iter__(self):
iterator = _coconut.iter(self.iter)
loop = True
while loop:
group = []
def _coconut_igetitem(iterable, index):
if isinstance(iterable, (_coconut_reversed, _coconut_map, _coconut.zip, _coconut_enumerate, _coconut_count, _coconut.abc.Sequence)):
return iterable[index]
if not _coconut.isinstance(index, _coconut.slice):
if index < 0:
return _coconut.collections.deque(iterable, maxlen=-index)[0]
return _coconut.next(_coconut.itertools.islice(iterable, index, index + 1))
if index.start is not None and index.start < 0 and (index.stop is None or index.stop < 0) and index.step is None:
queue = _coconut.collections.deque(iterable, maxlen=-index.start)
if index.stop is not None:
queue = _coconut.list(queue)[:index.stop - index.start]
return queue
if (index.start is not None and index.start < 0) or (index.stop is not None and index.stop < 0) or (index.step is not None and index.step < 0):
return _coconut.list(iterable)[index]
return _coconut.itertools.islice(iterable, index.start, index.stop, index.step)
class _coconut_base_compose(object):
__slots__ = ("func", "funcstars")
def __init__(self, func, *funcstars):
self.func = func
self.funcstars = []
for f, star in funcstars:
if isinstance(f, _coconut_base_compose):
self.funcstars.append((f.func, star))
self.funcstars += f.funcstars
else:
self.funcstars.append((f, star))
def __call__(self, *args, **kwargs):
arg = self.func(*args, **kwargs)
for f, star in self.funcstars:
arg = f(*arg) if star else f(arg)
return arg
def __repr__(self):
def _coconut_bool_or(a, b): return a or b
def _coconut_none_coalesce(a, b): return a if a is not None else b
def _coconut_minus(a, *rest):
if not rest:
return -a
for b in rest:
a = a - b
return a
@_coconut.functools.wraps(_coconut.itertools.tee)
def tee(iterable, n=2):
if n >= 0 and _coconut.isinstance(iterable, (_coconut.tuple, _coconut.frozenset)):
return (iterable,) * n
if n > 0 and (_coconut.hasattr(iterable, "__copy__") or _coconut.isinstance(iterable, _coconut.abc.Sequence)):
return (iterable,) + _coconut.tuple(_coconut.copy.copy(iterable) for _ in _coconut.range(n - 1))
return _coconut.itertools.tee(iterable, n)
class reiterable(object):
"""Allows an iterator to be iterated over multiple times."""
__slots__ = ("iter",)
def __init__(self, iterable):
self.iter = iterable
def __iter__(self):
self.iter, out = _coconut_tee(self.iter)
return _coconut.iter(out)
def __getitem__(self, index):
return _coconut_igetitem(_coconut.iter(self), index)
def __reversed__(self):
return _coconut_reversed(_coconut.iter(self))
def __len__(self):
return _coconut.len(self.iter)
def __repr__(self):
return "reiterable(%r)" % (self.iter,)
def __reduce__(self):
__slots__ = ()
def __ne__(self, other):
eq = self == other
if eq is _coconut_NotImplemented:
return eq
return not eq
class int(_coconut_int):
__slots__ = ()
if hasattr(_coconut_int, "__doc__"):
__doc__ = _coconut_int.__doc__
class __metaclass__(type):
def __instancecheck__(cls, inst):
return _coconut.isinstance(inst, (_coconut_int, _coconut_long))
def __subclasscheck__(cls, subcls):
return _coconut.issubclass(subcls, (_coconut_int, _coconut_long))
class range(object):
__slots__ = ("_xrange",)
if hasattr(_coconut_xrange, "__doc__"):
__doc__ = _coconut_xrange.__doc__
def __init__(self, *args):
self._xrange = _coconut_xrange(*args)
def __iter__(self):
return _coconut.iter(self._xrange)
def __reversed__(self):
return _coconut.reversed(self._xrange)
def __len__(self):
return _coconut.len(self._xrange)
def __contains__(self, elem):
return elem in self._xrange
def __getitem__(self, index):
if _coconut.isinstance(index, _coconut.slice):
args = _coconut.slice(*self._args)
if k == key:
to_tee, store_pos = v, i
break
else: # no break
to_tee = func(*args, **kwargs)
store_pos = None
to_store, to_return = _coconut_tee(to_tee)
if store_pos is None:
backup_tee_store.append([key, to_store])
else:
backup_tee_store[store_pos][1] = to_store
else:
tee_store[key], to_return = _coconut_tee(tee_store.get(key) or func(*args, **kwargs))
return to_return
return recursive_iterator_func
class _coconut_FunctionMatchErrorContext(object):
from threading import local; threadlocal_var = local(); del local
__slots__ = ('exc_class', 'taken')
def __init__(self, exc_class):
self.exc_class = exc_class
self.taken = False
def __enter__(self):
try:
self.threadlocal_var.contexts.append(self)
except AttributeError:
self.threadlocal_var.contexts = [self]
def __exit__(self, type, value, traceback):
self.threadlocal_var.contexts.pop()
@classmethod
def get(cls):
try:
ctx = cls.threadlocal_var.contexts[-1]
if acc is self.empty_initializer:
acc = item
else:
acc = self.func(acc, item)
yield acc
def __len__(self):
return _coconut.len(self.iter)
def __repr__(self):
return "scan(%r, %r)" % (self.func, self.iter)
def __reduce__(self):
return (self.__class__, (self.func, self.iter))
def __copy__(self):
return self.__class__(self.func, _coconut.copy.copy(self.iter))
def __fmap__(self, func):
return _coconut_map(func, self)
class reversed(object):
__slots__ = ("iter",)
if hasattr(_coconut.map, "__doc__"):
__doc__ = _coconut.reversed.__doc__
def __new__(cls, iterable):
if _coconut.isinstance(iterable, _coconut.range):
return iterable[::-1]
if not _coconut.hasattr(iterable, "__reversed__") or _coconut.isinstance(iterable, (_coconut.list, _coconut.tuple)):
return _coconut.object.__new__(cls)
return _coconut.reversed(iterable)
def __init__(self, iterable):
self.iter = iterable
def __iter__(self):
return _coconut.iter(_coconut.reversed(self.iter))
def __getitem__(self, index):
if _coconut.isinstance(index, _coconut.slice):
return _coconut_igetitem(self.iter, _coconut.slice(-(index.start + 1) if index.start is not None else None, -(index.stop + 1) if index.stop else None, -(index.step if index.step is not None else 1)))