Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@example(bidict({1: 1, 2: 2}), [(1, 3), (1, 2)], {'on_dup_key': OVERWRITE})
@example(bidict({1: 1, 2: 2}), [(3, 1), (2, 4)], {'on_dup_val': OVERWRITE})
@example(bidict({1: 1, 2: 2}), [(1, 2), (1, 1)], {'on_dup_kv': OVERWRITE})
def test_putall_same_as_put_for_each_item(bi, items, dup_policies):
"""*bi.putall(items) <==> for i in items: bi.put(i)* for all duplication policies."""
check = bi.copy()
expect = bi.copy()
checkexc = None
expectexc = None
for (key, val) in items:
try:
expect.put(key, val, **dup_policies)
except BidictException as exc:
expectexc = type(exc)
expect = bi # Bulk updates fail clean -> roll back to original state.
break
try:
from collections import defaultdict
from itertools import chain, filterfalse, takewhile, repeat
import bidict
from ._utils import maybe_double, SAFE_CHARS, SYMBOL_MAP
from nutshell.common.classes import TableRange, ColorMixin, ColorRange
from nutshell.common.utils import random, multisplit
from nutshell.common.errors import *
TWO_STATE = str.maketrans('bo', '.A')
class IShouldntHaveToDoThisBidict(bidict.bidict):
"""Why is this not an __init__ parameter"""
on_dup_val = bidict.OVERWRITE
class Icon:
_rRUNS = re.compile(r'(\d*)([$.A-Z]|[p-y][A-O])')
def __init__(self, rle, height, x, y):
if height not in (7, 15, 31):
raise ValueError(f"Need to declare valid height (not '{height!r}')")
self.height = height
self._fill = ['..' * height]
self._rle = rle
_split = ''.join(
maybe_double(val) * int(run_length or 1)
for run_length, val in
self._rRUNS.findall(self._rle)
).split('$$')
from functools import partial
from itertools import chain, cycle, islice, zip_longest
import bidict
import lark
from nutshell.common.classes import TableRange
from nutshell.common.utils import printv, printq
from nutshell.common.errors import *
from . import _napkins as napkins, _utils as utils, _symmetries as symmetries
from ._classes import SpecialVar, VarName
from .lark_assets import NUTSHELL_GRAMMAR, Preprocess, Variable, _classes
class Bidict(bidict.bidict):
on_dup_kv = bidict.OVERWRITE
class Table:
CARDINALS = utils.generate_cardinals({
'oneDimensional': ('W', 'E'),
'vonNeumann': ('N', 'E', 'S', 'W'),
'hexagonal': ('N', 'E', 'SE', 'S', 'W', 'NW'),
'Moore': ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'),
})
TRLENS = {k: len(v) for k, v in CARDINALS.items()}
hush = True
def __init__(self, tbl, start=0, *, dep: ['@NUTSHELL'] = None):
self._src = tbl
self._src[:] = [i.split('#')[0].strip() for i in tbl] # Lark chokes on comments for reasons unknown otherwise :/
self._start = start