def ghcommit_role(name, rawtext, text, lineno, inliner, options={}, content=[]):

app = inliner.document.settings.env.app<EOL>try:<EOL><INDENT>base = app.config.github_project_url<EOL>if not base:<EOL><INDENT>raise AttributeError<EOL><DEDENT>if not base.endswith('<STR_LIT:/>'):<EOL><INDENT>base += '<STR_LIT:/>'<EOL><DEDENT><DEDENT>except AttributeError as err:<EOL><INDENT>raise ValueError('<STR_LIT>' % str(err))<EOL><DEDENT>ref = base + text<EOL>node = nodes.reference(rawtext, text[:<NUM_LIT:6>], refuri=ref, **options)<EOL>return [node], []<EOL>

Link to a GitHub commit.

    Returns 2 part tuple containing list of nodes to insert into the
    document and a list of system messages.  Both are allowed to be
    empty.

    :param name: The role name used in the document.
    :param rawtext: The entire markup snippet, with role.
    :param text: The text marked with the role.
    :param lineno: The line number where rawtext appears in the input.
    :param inliner: The inliner instance that called us.
    :param options: Directive options for customization.
    :param content: The directive content for customization.


app.info('<STR_LIT>')<EOL>app.add_role('<STR_LIT>', ghissue_role)<EOL>app.add_role('<STR_LIT>', ghissue_role)<EOL>app.add_role('<STR_LIT>', ghuser_role)<EOL>app.add_role('<STR_LIT>', ghcommit_role)<EOL>app.add_config_value('<STR_LIT>', None, '<STR_LIT>')<EOL>return<EOL>

Install the plugin.

    :param app: Sphinx application context.


@st.composite<EOL>def lists_pairs_nodup(draw, elements=IMMUTABLES, min_size=<NUM_LIT:0>, max_size=LISTS_MAX_SIZE):

n = draw(st.integers(min_value=min_size, max_value=max_size))<EOL>size_n_sets = st.sets(elements, min_size=n, max_size=n)<EOL>keys = draw(size_n_sets)<EOL>vals = draw(size_n_sets)<EOL>return list(izip(keys, vals))<EOL>

Generate a list of pairs from the given elements with no duplication.


@st.composite<EOL>def bidicts(draw, bi_types=BIDICT_TYPES, init_items=LISTS_PAIRS_NODUP):

bi_cls = draw(bi_types)<EOL>items = draw(init_items)<EOL>bi = bi_cls(items)<EOL>return bi if draw(RAND).choice((True, False)) else bi.inv<EOL>


def load_profile(name=getenv('<STR_LIT>') or '<STR_LIT:default>'):

Load the Hypothesis profile with the given name.


<EOL>self._fwdm = self._fwdm_cls()<EOL>self._invm = self._invm_cls()<EOL>self._init_inv()  <EOL>if args or kw:<EOL><INDENT>self._update(True, None, *args, **kw)<EOL><DEDENT>

Make a new bidirectional dictionary.
        The signature is the same as that of regular dictionaries.
        Items passed in are added in the order they are passed,
        respecting the current duplication policies in the process.

        *See also* :attr:`on_dup_key`, :attr:`on_dup_val`, :attr:`on_dup_kv`


if cls._fwdm_cls is cls._invm_cls:<EOL><INDENT>return cls<EOL><DEDENT>if not getattr(cls, '<STR_LIT>', None):<EOL><INDENT>class _Inv(cls):<EOL><INDENT>_fwdm_cls = cls._invm_cls<EOL>_invm_cls = cls._fwdm_cls<EOL>_inv_cls_ = cls<EOL><DEDENT>_Inv.__name__ = cls.__name__ + '<STR_LIT>'<EOL>cls._inv_cls_ = _Inv<EOL><DEDENT>return cls._inv_cls_<EOL>

The inverse of this bidict type, i.e. one with *_fwdm_cls* and *_invm_cls* swapped.


<EOL>if self._inv is not None:<EOL><INDENT>return self._inv<EOL><DEDENT>inv = self._invweak()<EOL>if inv is not None:<EOL><INDENT>return inv<EOL><DEDENT>self._init_inv()  <EOL>return self._inv<EOL>

The inverse of this bidict.

        *See also* :attr:`inv`


return self.inverse<EOL>


state = {}<EOL>for cls in self.__class__.__mro__:<EOL><INDENT>slots = getattr(cls, '<STR_LIT>', ())<EOL>for slot in slots:<EOL><INDENT>if hasattr(self, slot):<EOL><INDENT>state[slot] = getattr(self, slot)<EOL><DEDENT><DEDENT><DEDENT>state.pop('<STR_LIT>', None)<EOL>state.pop('<STR_LIT>', None)<EOL>return state<EOL>

Needed to enable pickling due to use of :attr:`__slots__` and weakrefs.

        *See also* :meth:`object.__getstate__`


for slot, value in iteritems(state):<EOL><INDENT>setattr(self, slot, value)<EOL><DEDENT>

Implemented because use of :attr:`__slots__` would prevent unpickling otherwise.

        *See also* :meth:`object.__setstate__`


clsname = self.__class__.__name__<EOL>if not self:<EOL><INDENT>return '<STR_LIT>' % clsname<EOL><DEDENT>return '<STR_LIT>' % (clsname, self._repr_delegate(iteritems(self)))<EOL>


if not isinstance(other, Mapping) or len(self) != len(other):<EOL><INDENT>return False<EOL><DEDENT>selfget = self.get<EOL>return all(selfget(k, _MISS) == v for (k, v) in iteritems(other))<EOL>

u"""*x.__eq__(other)　⟺　x == other*

        Equivalent to *dict(x.items()) == dict(other.items())*
        but more efficient.

        Note that :meth:`bidict's __eq__() <bidict.bidict.__eq__>` implementation
        is inherited by subclasses,
        in particular by the ordered bidict subclasses,
        so even with ordered bidicts,
        :ref:`== comparison is order-insensitive <eq-order-insensitive>`.

        *See also* :meth:`bidict.FrozenOrderedBidict.equals_order_sensitive`


def _dedup_item(self, key, val, on_dup):

fwdm = self._fwdm<EOL>invm = self._invm<EOL>oldval = fwdm.get(key, _MISS)<EOL>oldkey = invm.get(val, _MISS)<EOL>isdupkey = oldval is not _MISS<EOL>isdupval = oldkey is not _MISS<EOL>dedup_result = _DedupResult(isdupkey, isdupval, oldkey, oldval)<EOL>if isdupkey and isdupval:<EOL><INDENT>if self._isdupitem(key, val, dedup_result):<EOL><INDENT>return _NOOP<EOL><DEDENT>if on_dup.kv is RAISE:<EOL><INDENT>raise KeyAndValueDuplicationError(key, val)<EOL><DEDENT>elif on_dup.kv is IGNORE:<EOL><INDENT>return _NOOP<EOL><DEDENT>assert on_dup.kv is OVERWRITE, '<STR_LIT>' % on_dup.kv<EOL><DEDENT>elif isdupkey:<EOL><INDENT>if on_dup.key is RAISE:<EOL><INDENT>raise KeyDuplicationError(key)<EOL><DEDENT>elif on_dup.key is IGNORE:<EOL><INDENT>return _NOOP<EOL><DEDENT>assert on_dup.key is OVERWRITE, '<STR_LIT>' % on_dup.key<EOL><DEDENT>elif isdupval:<EOL><INDENT>if on_dup.val is RAISE:<EOL><INDENT>raise ValueDuplicationError(val)<EOL><DEDENT>elif on_dup.val is IGNORE:<EOL><INDENT>return _NOOP<EOL><DEDENT>assert on_dup.val is OVERWRITE, '<STR_LIT>' % on_dup.val<EOL><DEDENT>return dedup_result<EOL>

Check *key* and *val* for any duplication in self.

Handle any duplication as per the duplication policies given in *on_dup*.

(key, val) already present is construed as a no-op, not a duplication.

If duplication is found and the corresponding duplication policy is
:attr:`~bidict.RAISE`, raise the appropriate error.

If duplication is found and the corresponding duplication policy is
:attr:`~bidict.IGNORE`, return *None*.

If duplication is found and the corresponding duplication policy is
:attr:`~bidict.OVERWRITE`,
or if no duplication is found,
return the _DedupResult *(isdupkey, isdupval, oldkey, oldval)*.


def _update_with_rollback(self, on_dup, *args, **kw):

writelog = []<EOL>appendlog = writelog.append<EOL>dedup_item = self._dedup_item<EOL>write_item = self._write_item<EOL>for (key, val) in _iteritems_args_kw(*args, **kw):<EOL><INDENT>try:<EOL><INDENT>dedup_result = dedup_item(key, val, on_dup)<EOL><DEDENT>except DuplicationError:<EOL><INDENT>undo_write = self._undo_write<EOL>for dedup_result, write_result in reversed(writelog):<EOL><INDENT>undo_write(dedup_result, write_result)<EOL><DEDENT>raise<EOL><DEDENT>if dedup_result is not _NOOP:<EOL><INDENT>write_result = write_item(key, val, dedup_result)<EOL>appendlog((dedup_result, write_result))<EOL><DEDENT><DEDENT>


<EOL>copy = self.__class__.__new__(self.__class__)<EOL>copy._fwdm = self._fwdm.copy()  <EOL>copy._invm = self._invm.copy()  <EOL>copy._init_inv()  <EOL>return copy<EOL>


return self.copy()<EOL>

Used for the copy protocol.

        *See also* the :mod:`copy` module


return len(self._fwdm)<EOL>


<EOL>return iter(self._fwdm)<EOL>


return self._fwdm[key]<EOL>


return self.inverse.keys()<EOL>

A set-like object providing a view on the contained values.

        Note that because the values of a :class:`~bidict.BidirectionalMapping`
        are the keys of its inverse,
        this returns a :class:`~collections.abc.KeysView`
        rather than a :class:`~collections.abc.ValuesView`,
        which has the advantages of constant-time containment checks
        and supporting set operations.


return iteritems(arg) if isinstance(arg, Mapping) else iter(arg)<EOL>

Yield the items in *arg*.

    If *arg* is a :class:`~collections.abc.Mapping`, return an iterator over its items.
    Otherwise return an iterator over *arg* itself.


args_len = len(args)<EOL>if args_len > <NUM_LIT:1>:<EOL><INDENT>raise TypeError('<STR_LIT>' % args_len)<EOL><DEDENT>itemchain = None<EOL>if args:<EOL><INDENT>arg = args[<NUM_LIT:0>]<EOL>if arg:<EOL><INDENT>itemchain = _iteritems_mapping_or_iterable(arg)<EOL><DEDENT><DEDENT>if kw:<EOL><INDENT>iterkw = iteritems(kw)<EOL>itemchain = chain(itemchain, iterkw) if itemchain else iterkw<EOL><DEDENT>return itemchain or _NULL_IT<EOL>

Yield the items from the positional argument (if given) and then any from *kw*.

    :raises TypeError: if more than one positional argument is given.


inv = getattr(arg, '<STR_LIT>', None)<EOL>if callable(inv):<EOL><INDENT>return inv()<EOL><DEDENT>return ((val, key) for (key, val) in _iteritems_mapping_or_iterable(arg))<EOL>

Yield the inverse items of the provided object.

    If *arg* has a :func:`callable` ``__inverted__`` attribute,
    return the result of calling it.

    Otherwise, return an iterator over the items in `arg`,
    inverting each item on the fly.

    *See also* :attr:`bidict.BidirectionalMapping.__inverted__`


if getattr(self, '<STR_LIT>', None) is None:<EOL><INDENT>self._hash = ItemsView(self)._hash()<EOL><DEDENT>return self._hash<EOL>

The hash of this bidict as determined by its items.


<EOL>raise NotImplementedError<EOL>

The inverse of this bidirectional mapping instance.

        *See also* :attr:`bidict.BidictBase.inverse`, :attr:`bidict.BidictBase.inv`

        :raises NotImplementedError: Meant to be overridden in subclasses.


return iteritems(self.inverse)<EOL>

Get an iterator over the items in :attr:`inverse`.

        This is functionally equivalent to iterating over the items in the
        forward mapping and inverting each one on the fly, but this provides a
        more efficient implementation: Assuming the already-inverted items
        are stored in :attr:`inverse`, just return an iterator over them directly.

        Providing this default implementation enables external functions,
        particularly :func:`~bidict.inverted`, to use this optimized
        implementation when available, instead of having to invert on the fly.

        *See also* :func:`bidict.inverted`


@classmethod<EOL><INDENT>def __subclasshook__(cls, C):  <DEDENT>

if cls is not BidirectionalMapping:  <EOL><INDENT>return NotImplemented<EOL><DEDENT>if not Mapping.__subclasshook__(C):<EOL><INDENT>return NotImplemented<EOL><DEDENT>mro = getattr(C, '<STR_LIT>', None)<EOL>if mro is None:  <EOL><INDENT>return NotImplemented<EOL><DEDENT>if not any(B.__dict__.get('<STR_LIT>') for B in mro):<EOL><INDENT>return NotImplemented<EOL><DEDENT>return True<EOL>

Check if *C* is a :class:`~collections.abc.Mapping`
        that also provides an ``inverse`` attribute,
        thus conforming to the :class:`BidirectionalMapping` interface,
        in which case it will be considered a (virtual) C
        even if it doesn't explicitly extend it.


on_dup = self._get_on_dup()<EOL>self._put(key, val, on_dup)<EOL>

Set the value for *key* to *val*.

If *key* is already associated with *val*, this is a no-op.

If *key* is already associated with a different value,
the old value will be replaced with *val*,
as with dict's :meth:`__setitem__`.

If *val* is already associated with a different key,
an exception is raised
to protect against accidental removal of the key
that's currently associated with *val*.

Use :meth:`put` instead if you want to specify different policy in
the case that the provided key or value duplicates an existing one.
Or use :meth:`forceput` to unconditionally associate *key* with *val*,
replacing any existing items as necessary to preserve uniqueness.

:raises bidict.ValueDuplicationError: if *val* duplicates that of an
    existing item.

:raises bidict.KeyAndValueDuplicationError: if *key* duplicates the key of an
    existing item and *val* duplicates the value of a different
    existing item.


def put(self, key, val, on_dup_key=RAISE, on_dup_val=RAISE, on_dup_kv=None):

on_dup = self._get_on_dup((on_dup_key, on_dup_val, on_dup_kv))<EOL>self._put(key, val, on_dup)<EOL>

Associate *key* with *val* with the specified duplication policies.

If *on_dup_kv* is ``None``, the *on_dup_val* policy will be used for it.

For example, if all given duplication policies are :attr:`~bidict.RAISE`,
then *key* will be associated with *val* if and only if
*key* is not already associated with an existing value and
*val* is not already associated with an existing key,
otherwise an exception will be raised.

If *key* is already associated with *val*, this is a no-op.

:raises bidict.KeyDuplicationError: if attempting to insert an item
    whose key only duplicates an existing item's, and *on_dup_key* is
    :attr:`~bidict.RAISE`.

:raises bidict.ValueDuplicationError: if attempting to insert an item
    whose value only duplicates an existing item's, and *on_dup_val* is
    :attr:`~bidict.RAISE`.

:raises bidict.KeyAndValueDuplicationError: if attempting to insert an
    item whose key duplicates one existing item's, and whose value
    duplicates another existing item's, and *on_dup_kv* is
    :attr:`~bidict.RAISE`.


self._put(key, val, self._ON_DUP_OVERWRITE)<EOL>

Associate *key* with *val* unconditionally.

Replace any existing mappings containing key *key* or value *val*
as necessary to preserve uniqueness.


self._fwdm.clear()<EOL>self._invm.clear()<EOL>


try:<EOL><INDENT>return self._pop(key)<EOL><DEDENT>except KeyError:<EOL><INDENT>if default is _MISS:<EOL><INDENT>raise<EOL><DEDENT>return default<EOL><DEDENT>

u"""*x.pop(k[, d]) → v*

        Remove specified key and return the corresponding value.

        :raises KeyError: if *key* is not found and no *default* is provided.


if not self:<EOL><INDENT>raise KeyError('<STR_LIT>')<EOL><DEDENT>key, val = self._fwdm.popitem()<EOL>del self._invm[val]<EOL>return key, val<EOL>

u"""*x.popitem() → (k, v)*

        Remove and return some item as a (key, value) pair.

        :raises KeyError: if *x* is empty.


if args or kw:<EOL><INDENT>self._update(False, None, *args, **kw)<EOL><DEDENT>

Like :meth:`putall` with default duplication policies.


self._update(False, self._ON_DUP_OVERWRITE, *args, **kw)<EOL>


def putall(self, items, on_dup_key=RAISE, on_dup_val=RAISE, on_dup_kv=None):

if items:<EOL><INDENT>on_dup = self._get_on_dup((on_dup_key, on_dup_val, on_dup_kv))<EOL>self._update(False, on_dup, items)<EOL><DEDENT>

Like a bulk :meth:`put`.

If one of the given items causes an exception to be raised,
none of the items is inserted.


def namedbidict(typename, keyname, valname, base_type=bidict):

<EOL>if not issubclass(base_type, BidirectionalMapping):<EOL><INDENT>raise TypeError(base_type)<EOL><DEDENT>names = (typename, keyname, valname)<EOL>if not all(map(_VALID_NAME.match, names)) or keyname == valname:<EOL><INDENT>raise ValueError(names)<EOL><DEDENT>class _Named(base_type):  <EOL><INDENT>__slots__ = ()<EOL>def _getfwd(self):<EOL><INDENT>return self.inverse if self._isinv else self<EOL><DEDENT>def _getinv(self):<EOL><INDENT>return self if self._isinv else self.inverse<EOL><DEDENT>@property<EOL>def _keyname(self):<EOL><INDENT>return valname if self._isinv else keyname<EOL><DEDENT>@property<EOL>def _valname(self):<EOL><INDENT>return keyname if self._isinv else valname<EOL><DEDENT>def __reduce__(self):<EOL><INDENT>return (_make_empty, (typename, keyname, valname, base_type), self.__getstate__())<EOL><DEDENT><DEDENT>bname = base_type.__name__<EOL>fname = valname + '<STR_LIT>'<EOL>iname = keyname + '<STR_LIT>'<EOL>names = dict(typename=typename, bname=bname, keyname=keyname, valname=valname)<EOL>fdoc = u'<STR_LIT>'.format(**names)<EOL>idoc = u'<STR_LIT>'.format(**names)<EOL>setattr(_Named, fname, property(_Named._getfwd, doc=fdoc))  <EOL>setattr(_Named, iname, property(_Named._getinv, doc=idoc))  <EOL>_Named.__name__ = typename<EOL>return _Named<EOL>

r"""Create a new subclass of *base_type* with custom accessors.

    Analagous to :func:`collections.namedtuple`.

    The new class's ``__name__`` will be set to *typename*.

    Instances of it will provide access to their
    :attr:`inverse <BidirectionalMapping.inverse>`\s
    via the custom *keyname*\_for property,
    and access to themselves
    via the custom *valname*\_for property.

    *See also* the :ref:`namedbidict usage documentation
    <other-bidict-types:\:func\:\`~bidict.namedbidict\`>`

    :raises ValueError: if any of the *typename*, *keyname*, or *valname*
        strings does not match ``%s``, or if *keyname == valname*.

    :raises TypeError: if *base_type* is not a subclass of
        :class:`BidirectionalMapping`.
        (This function requires slightly more of *base_type*,
        e.g. the availability of an ``_isinv`` attribute,
        but all the :ref:`concrete bidict types
        <other-bidict-types:Bidict Types Diagram>`
        that the :mod:`bidict` module provides can be passed in.
        Check out the code if you actually need to pass in something else.)


def _make_empty(typename, keyname, valname, base_type):

cls = namedbidict(typename, keyname, valname, base_type=base_type)<EOL>return cls()<EOL>

Create a named bidict with the indicated arguments and return an empty instance.
    Used to make :func:`bidict.namedbidict` instances picklable.


self._fwdm.clear()<EOL>self._invm.clear()<EOL>self._sntl.nxt = self._sntl.prv = self._sntl<EOL>


if not self:<EOL><INDENT>raise KeyError('<STR_LIT>')<EOL><DEDENT>key = next((reversed if last else iter)(self))<EOL>val = self._pop(key)<EOL>return key, val<EOL>

u"""*x.popitem() → (k, v)*

        Remove and return the most recently added item as a (key, value) pair
        if *last* is True, else the least recently added item.

        :raises KeyError: if *x* is empty.


node = self._fwdm[key]<EOL>node.prv.nxt = node.nxt<EOL>node.nxt.prv = node.prv<EOL>sntl = self._sntl<EOL>if last:<EOL><INDENT>last = sntl.prv<EOL>node.prv = last<EOL>node.nxt = sntl<EOL>sntl.prv = last.nxt = node<EOL><DEDENT>else:<EOL><INDENT>first = sntl.nxt<EOL>node.prv = sntl<EOL>node.nxt = first<EOL>sntl.nxt = first.prv = node<EOL><DEDENT>

Move an existing key to the beginning or end of this ordered bidict.

        The item is moved to the end if *last* is True, else to the beginning.

        :raises KeyError: if the key does not exist


return dict(_prv=self.prv, _nxt=self.nxt)<EOL>

Return the instance state dictionary
        but with weakrefs converted to strong refs
        so that it can be pickled.

        *See also* :meth:`object.__getstate__`


self._setprv(state['<STR_LIT>'])<EOL>self._setnxt(state['<STR_LIT>'])<EOL>


attr = '<STR_LIT>' if reverse else '<STR_LIT>'<EOL>node = getattr(self, attr)<EOL>while node:<EOL><INDENT>yield node<EOL>node = getattr(node, attr)<EOL><DEDENT>

Iterator yielding nodes in the requested order,
        i.e. traverse the linked list via :attr:`nxt`
        (or :attr:`prv` if *reverse* is truthy)
        until reaching a falsy (i.e. sentinel) node.


self._sntl = _Sentinel()<EOL>super(OrderedBidictBase, self).__init__(*args, **kw)<EOL>

Make a new ordered bidirectional mapping.
        The signature is the same as that of regular dictionaries.
        Items passed in are added in the order they are passed,
        respecting this bidict type's duplication policies along the way.
        The order in which items are inserted is remembered,
        similar to :class:`collections.OrderedDict`.


<EOL>copy = self.__class__.__new__(self.__class__)<EOL>sntl = _Sentinel()<EOL>fwdm = self._fwdm.copy()<EOL>invm = self._invm.copy()<EOL>cur = sntl<EOL>nxt = sntl.nxt<EOL>for (key, val) in iteritems(self):<EOL><INDENT>nxt = _Node(cur, sntl)<EOL>cur.nxt = fwdm[key] = invm[val] = nxt<EOL>cur = nxt<EOL><DEDENT>sntl.prv = nxt<EOL>copy._sntl = sntl  <EOL>copy._fwdm = fwdm  <EOL>copy._invm = invm  <EOL>copy._init_inv()  <EOL>return copy<EOL>


def _isdupitem(self, key, val, dedup_result):

isdupkey, isdupval, nodeinv, nodefwd = dedup_result<EOL>isdupitem = nodeinv is nodefwd<EOL>if isdupitem:<EOL><INDENT>assert isdupkey<EOL>assert isdupval<EOL><DEDENT>return isdupitem<EOL>

Return whether (key, val) duplicates an existing item.


fwdm_inv = self._fwdm.inverse<EOL>for node in self._sntl.__iter__(reverse=reverse):<EOL><INDENT>yield fwdm_inv[node]<EOL><DEDENT>

An iterator over this bidict's items in order.


for key in self.__iter__(reverse=True):<EOL><INDENT>yield key<EOL><DEDENT>

An iterator over this bidict's items in reverse order.


<EOL>if not isinstance(other, Mapping) or len(self) != len(other):<EOL><INDENT>return False<EOL><DEDENT>return all(i == j for (i, j) in izip(iteritems(self), iteritems(other)))<EOL>

Order-sensitive equality check.

        *See also* :ref:`eq-order-insensitive`


<EOL>


url = self.root_url + "<STR_LIT>"<EOL>values = {}<EOL>values["<STR_LIT:username>"] = user<EOL>return self._query(url, values)<EOL>


def send_notification(self, to=None, msg=None, label=None,<EOL>title=None, uri=None):

url = self.root_url + "<STR_LIT>"<EOL>values = {}<EOL>if to is not None:<EOL><INDENT>values["<STR_LIT:to>"] = to<EOL><DEDENT>if msg is not None:<EOL><INDENT>values["<STR_LIT>"] = msg<EOL><DEDENT>if label is not None:<EOL><INDENT>values["<STR_LIT:label>"] = label<EOL><DEDENT>if title is not None:<EOL><INDENT>values["<STR_LIT:title>"] = title<EOL><DEDENT>if uri is not None:<EOL><INDENT>values["<STR_LIT>"] = uri<EOL><DEDENT>return self._query(url, values)<EOL>

method to send a message to a user

            Parameters:
                to -> recipient
                msg -> message to send
                label -> application description
                title -> name of the notification event
                uri -> callback uri


def send_message(self, to=None, msg=None):

url = self.root_url + "<STR_LIT>"<EOL>values = {}<EOL>if to is not None:<EOL><INDENT>values["<STR_LIT:to>"] = to<EOL><DEDENT>if msg is not None:<EOL><INDENT>values["<STR_LIT>"] = msg<EOL><DEDENT>return self._query(url, values)<EOL>

method to send a message to a user

            Parameters:
                to -> recipient
                msg -> message to send


auth = encodestring('<STR_LIT>' % (self.user, self.secret)).replace('<STR_LIT:\n>', '<STR_LIT>')<EOL>if data is not None: <EOL><INDENT>values = urllib.parse.urlencode(data)<EOL>request = urllib.request.Request(url, values)<EOL>request.add_header("<STR_LIT>", "<STR_LIT>" % auth)<EOL><DEDENT>else: <EOL><INDENT>request = urllib.request.Request(url)<EOL>request.add_header("<STR_LIT>", "<STR_LIT>" % auth)<EOL><DEDENT>try:<EOL><INDENT>response = urllib.request.urlopen(request)<EOL><DEDENT>except IOError as e: <EOL><INDENT>return {"<STR_LIT:status>" : "<STR_LIT:error>",<EOL>"<STR_LIT>" : e.code,<EOL>"<STR_LIT>" : e.msg<EOL>}<EOL><DEDENT>return json.loads(response.read())<EOL>

query method to do HTTP POST/GET

            Parameters:
                url -> the url to POST/GET
                data -> header_data as a dict (only for POST)

            Returns:
                Parsed JSON data as dict
                or
                None on error


usage = "<STR_LIT>"<EOL>parser = OptionParser(usage, version="<STR_LIT>" + notifo.__version__)<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", action="<STR_LIT:store>", dest="<STR_LIT:user>",<EOL>help="<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", action="<STR_LIT:store>", dest="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", action="<STR_LIT:store>", dest="<STR_LIT:name>",<EOL>help="<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", action="<STR_LIT:store>", dest="<STR_LIT:label>",<EOL>help="<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", action="<STR_LIT:store>", dest="<STR_LIT:title>",<EOL>help="<STR_LIT>")<EOL>parser.add_option("<STR_LIT:-c>", "<STR_LIT>", action="<STR_LIT:store>", dest="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>parser.add_option("<STR_LIT>", "<STR_LIT>", action="<STR_LIT:store_true>", dest="<STR_LIT:message>",<EOL>default=False, help="<STR_LIT>")<EOL>(options, args) = parser.parse_args()<EOL>return (parser, options, args)<EOL>


<EOL>(parser, options, args) = init_parser()<EOL>result = None<EOL>if not options.user:<EOL><INDENT>parser.error("<STR_LIT>")<EOL><DEDENT>if not options.secret:<EOL><INDENT>parser.error("<STR_LIT>")<EOL><DEDENT>if not options.name:<EOL><INDENT>parser.error("<STR_LIT>")<EOL><DEDENT>if len(args) < <NUM_LIT:1>:<EOL><INDENT>result = notifo.subscribe_user(options.user, options.secret, options.name)<EOL><DEDENT>else:<EOL><INDENT>params = {}<EOL>params["<STR_LIT:to>"] = options.name<EOL>m = '<STR_LIT>'<EOL>for a in args:<EOL><INDENT>m = "<STR_LIT>" %(m, a)<EOL><DEDENT>params["<STR_LIT>"] = m<EOL>if options.message == True:<EOL><INDENT>result = notifo.send_message(options.user, options.secret, **params)<EOL><DEDENT>else:<EOL><INDENT>if options.label:<EOL><INDENT>params["<STR_LIT:label>"] = options.label<EOL><DEDENT>if options.title:<EOL><INDENT>params["<STR_LIT:title>"] = options.title<EOL><DEDENT>if options.callback:<EOL><INDENT>params["<STR_LIT>"] = options.callback<EOL><DEDENT>result = notifo.send_notification(options.user,options.secret,<EOL>**params)<EOL><DEDENT><DEDENT>if result is None:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>


def __init__(<EOL>self, attrs=None, mode=None, theme=None, config=None, dependencies=(),<EOL>js_var_format=None, addon_js=(), addon_css=(), custom_mode=None, custom_js=(),<EOL>keymap=None, custom_css=None, **kwargs):

super(CodeMirrorTextarea, self).__init__(attrs=attrs, **kwargs)<EOL>mode = mode or custom_mode or CODEMIRROR_MODE<EOL>if utils.isstring(mode):<EOL><INDENT>mode = { '<STR_LIT:name>': mode }<EOL><DEDENT>self.mode_name = mode['<STR_LIT:name>']<EOL>self.custom_mode = custom_mode<EOL>self.dependencies = dependencies<EOL>self.addon_js = addon_js<EOL>self.addon_css = addon_css<EOL>self.custom_js = custom_js<EOL>self.custom_css = custom_css<EOL>self.keymap = keymap<EOL>self.js_var_format = js_var_format or CODEMIRROR_JS_VAR_FORMAT<EOL>theme = theme or CODEMIRROR_THEME<EOL>theme_css_filename = THEME_CSS_FILENAME_RE.search(theme).group(<NUM_LIT:0>)<EOL>if theme_css_filename == '<STR_LIT:default>':<EOL><INDENT>self.theme_css = []<EOL><DEDENT>else:<EOL><INDENT>self.theme_css = [theme_css_filename]<EOL><DEDENT>config = config or {}<EOL>self.option_json = utils.CodeMirrorJSONEncoder().encode(dict(chain(<EOL>CODEMIRROR_CONFIG.items(),<EOL>config.items(),<EOL>[('<STR_LIT>', mode), ('<STR_LIT>', theme)])))<EOL>

u"""Constructor of CodeMirrorTextarea

        Attribute:
            path          - CodeMirror directory URI (DEFAULT = settings.CODEMIRROR_PATH)
            mode          - Name of language or a modal configuration object as described in CodeMirror docs.
                            Used to autoload an appropriate language plugin js file according to filename conventions.
                            (DEFAULT = settings.CODEMIRROR_MODE)
            theme         - Name of theme. Also autoloads theme plugin css according to filename conventions.
                            (DEFAULT = settings.CODEMIRROR_THEME)
            config        - The rest of the options passed into CodeMirror as a python map.
                            (updated from settings.CODEMIRROR_CONFIG)
            dependencies  - Some modes depend on others, you can pass extra modes dependencies with this argument.
                            For example for mode="htmlmixed", you must pass dependencies=("xml", "javascript", "css").
            js_var_format - A format string interpolated with the form field name to name a global JS variable that will
                            hold the CodeMirror editor object. For example with js_var_format="%s_editor" and a field
                            named "code", the JS variable name would be "code_editor". If None is passed, no global
                            variable is created (DEFAULT = settings.CODEMIRROR_JS_VAR_FORMAT)
            addon_js      - Various addons are available for CodeMirror. You can pass the names of any addons to load
                            with this argument. For example, for mode="django", you must pass addon_js=("mode/overlay", ).
            addon_css     - Some addons require corresponding CSS files. Since not every addon requires a CSS file, and
                            the names of these files do not always follow a convention, they must be listed separately.
                            For example, addon_css=("display/fullscreen", ).
            custom_mode   - To use a custom mode (i.e. one not included in the standard CodeMirror distribution), set this to
                            the name, or configuration object, of the mode, and ensure "mode" is None. For example,
                            custom_mode="my_custom_mode".
            custom_js     - To include other Javascript files with this widget that are not defined in the CodeMirror package,
                            set this to a list of pathnames. If "custom_mode" is defined, this will probably contain the path
                            of the file defining that mode. Paths in this list will not be prepended with settings.CODEMIRROR_PATH.
                            For example, custom_js=("site_js/my_custom_mode.js", )
            keymap        - The name of a keymap to use. Keymaps are located in settings.CODEMIRROR_PATH/keymap. Default: None.
            custom_css    - To include other CSS files with this widget that are not defined in the CodeMirror package,
                            set this to a list of pathnames. Paths in this list will not be prepended with any path.
                            For example, custom_css=("site_css/my_styles.css", )

        Example:
            *-------------------------------*
            + static
              + codemirror
                + lib
                  - codemirror.js
                  - codemirror.css
                + mode
                  + python
                    - python.js
                + theme
                  + cobalt.css
                + addon
                  + display
                    - fullscreen.js
                    - fullscreen.css
              + site_js
                - my_custom_mode.js
            *-------------------------------*
            CODEMIRROR_PATH = "codemirror"

            codemirror = CodeMirrorTextarea(mode="python", theme="cobalt", config={ 'fixedGutter': True })
            document = forms.TextField(widget=codemirror)


def render(self, name, value, attrs=None):

if self.js_var_format is not None:<EOL><INDENT>js_var_bit = '<STR_LIT>' % (self.js_var_format % name)<EOL><DEDENT>else:<EOL><INDENT>js_var_bit = '<STR_LIT>'<EOL><DEDENT>output = [super(CodeMirrorTextarea, self).render(name, value, attrs),<EOL>'<STR_LIT>' %<EOL>(js_var_bit, '<STR_LIT>' % name, self.option_json)]<EOL>return mark_safe('<STR_LIT:\n>'.join(output))<EOL>


self.js = js<EOL>

js is a string containing valid Javascript code.


def object_iter(obj, parent=None, parent_key=None, idx=None,<EOL>siblings=None):

obj_node = Node(value=obj, parent=parent, parent_key=parent_key,<EOL>siblings=siblings, idx=idx)<EOL>if isinstance(obj, list):<EOL><INDENT>_siblings = len(obj)<EOL>for i, elem in enumerate(obj):<EOL><INDENT>for node in object_iter(elem, obj_node, None, i + <NUM_LIT:1>, _siblings):<EOL><INDENT>yield node<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(obj, collections.Mapping):<EOL><INDENT>for key in obj:<EOL><INDENT>for node in object_iter(obj[key], obj_node, key):<EOL><INDENT>yield node<EOL><DEDENT><DEDENT><DEDENT>yield obj_node<EOL>

Yields each node of object graph in postorder.


parser = Parser(obj)<EOL>try:<EOL><INDENT>return parser.parse(selector)<EOL><DEDENT>except SelectorSyntaxError as e:<EOL><INDENT>log.exception(e)<EOL>return False<EOL><DEDENT>

Appy selector to obj and return matching nodes.

    If only one node is found, return it, otherwise return a list of matches.
    Returns False on syntax error. None if no results found.


self.obj = obj<EOL>

Create a parser for a particular object.


log.debug(self.obj)<EOL>tokens = lex(selector)<EOL>if self.peek(tokens, '<STR_LIT>') == '<STR_LIT:*>':<EOL><INDENT>self.match(tokens, '<STR_LIT>')<EOL>results = list(object_iter(self.obj))<EOL><DEDENT>else:<EOL><INDENT>results = self.selector_production(tokens)<EOL><DEDENT>results = [node.value for node in results]<EOL>if len(results) == <NUM_LIT:1>:<EOL><INDENT>return results[<NUM_LIT:0>]<EOL><DEDENT>elif not len(results):<EOL><INDENT>return None<EOL><DEDENT>return results<EOL>

Accept a list of tokens. Returns matched nodes of self.obj.


validators = []<EOL>if self.peek(tokens, '<STR_LIT:type>'):<EOL><INDENT>type_ = self.match(tokens, '<STR_LIT:type>')<EOL>validators.append(self.type_production(type_))<EOL><DEDENT>if self.peek(tokens, '<STR_LIT>'):<EOL><INDENT>key = self.match(tokens, '<STR_LIT>')<EOL>validators.append(self.key_production(key))<EOL><DEDENT>if self.peek(tokens, '<STR_LIT>'):<EOL><INDENT>pclass = self.match(tokens, '<STR_LIT>')<EOL>validators.append(self.pclass_production(pclass))<EOL><DEDENT>if self.peek(tokens, '<STR_LIT>'):<EOL><INDENT>nth_func = self.match(tokens, '<STR_LIT>')<EOL>validators.append(self.nth_child_production(nth_func, tokens))<EOL><DEDENT>if self.peek(tokens, '<STR_LIT>'):<EOL><INDENT>pclass_func = self.match(tokens, '<STR_LIT>')<EOL>validators.append(self.pclass_func_production(pclass_func, tokens))<EOL><DEDENT>if not len(validators):<EOL><INDENT>raise SelectorSyntaxError('<STR_LIT>')<EOL><DEDENT>results = self._match_nodes(validators, self.obj)<EOL>if self.peek(tokens, '<STR_LIT>'):<EOL><INDENT>operator = self.match(tokens, '<STR_LIT>')<EOL>rvals = self.selector_production(tokens)<EOL>if operator == '<STR_LIT:U+002C>':<EOL><INDENT>results.extend(rvals)<EOL><DEDENT>elif operator == '<STR_LIT:>>':<EOL><INDENT>results = self.parents(results, rvals)<EOL><DEDENT>elif operator == '<STR_LIT>':<EOL><INDENT>results = self.siblings(results, rvals)<EOL><DEDENT>elif operator == '<STR_LIT:U+0020>':<EOL><INDENT>results = self.ancestors(results, rvals)<EOL><DEDENT>else:<EOL><INDENT>raise SelectorSyntaxError("<STR_LIT>"<EOL>% operator)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if len(tokens):<EOL><INDENT>rvals = self.selector_production(tokens)<EOL>results = self.ancestors(results, rvals)<EOL><DEDENT><DEDENT>return results<EOL>


return [node for node in rhs if node.parent in lhs]<EOL>

Find nodes in rhs which have parents in lhs.


def _search(node):<EOL><INDENT>if node in lhs:<EOL><INDENT>return True<EOL><DEDENT>if not node.parent:<EOL><INDENT>return False<EOL><DEDENT>return _search(node.parent)<EOL><DEDENT>return [node for node in rhs if _search(node)]<EOL>

Return nodes from rhs which have ancestors in lhs.


parents = [node.parent for node in lhs]<EOL>return [node for node in rhs if node.parent in parents]<EOL>

Find nodes in rhs having common parents in lhs.


def nth_child_production(self, lexeme, tokens):

args = self.match(tokens, '<STR_LIT>')<EOL>pat = self.nth_child_pat.match(args)<EOL>if pat.group(<NUM_LIT:5>):<EOL><INDENT>a = <NUM_LIT:2><EOL>b = <NUM_LIT:1> if pat.group(<NUM_LIT:5>) == '<STR_LIT>' else <NUM_LIT:0><EOL><DEDENT>elif pat.group(<NUM_LIT:6>):<EOL><INDENT>a = <NUM_LIT:0><EOL>b = int(pat.group(<NUM_LIT:6>))<EOL><DEDENT>else:<EOL><INDENT>sign = pat.group(<NUM_LIT:1>) if pat.group(<NUM_LIT:1>) else '<STR_LIT:+>'<EOL>coef = pat.group(<NUM_LIT:2>) if pat.group(<NUM_LIT:2>) else '<STR_LIT:1>'<EOL>a = eval(sign + coef)<EOL>b = eval(pat.group(<NUM_LIT:3>) + pat.group(<NUM_LIT:4>)) if pat.group(<NUM_LIT:3>) else <NUM_LIT:0><EOL><DEDENT>reverse = False<EOL>if lexeme == '<STR_LIT>':<EOL><INDENT>reverse = True<EOL><DEDENT>def validate(node):<EOL><INDENT>"""<STR_LIT>"""<EOL>if not node.siblings:<EOL><INDENT>return False<EOL><DEDENT>idx = node.idx - <NUM_LIT:1><EOL>tot = node.siblings<EOL>if reverse:<EOL><INDENT>idx = tot - idx<EOL><DEDENT>else:<EOL><INDENT>idx += <NUM_LIT:1><EOL><DEDENT>if a == <NUM_LIT:0>:<EOL><INDENT>m = b == idx<EOL><DEDENT>else:<EOL><INDENT>mod = (idx - b) % a<EOL>m = not mod and (idx * a + b) >= <NUM_LIT:0><EOL><DEDENT>return m<EOL><DEDENT>return validate<EOL>

Parse args and pass them to pclass_func_validator.


def _match_nodes(self, validators, obj):

results = []<EOL>for node in object_iter(obj):<EOL><INDENT>if all([validate(node) for validate in validators]):<EOL><INDENT>results.append(node)<EOL><DEDENT><DEDENT>return results<EOL>

Apply each validator in validators to each node in obj.

        Return each node in obj which matches all validators.


return self.__str__().__hash__()<EOL>

Since the IEML string for any proposition AST is unique, it can be used as a hash


super().__init__()<EOL>self.model = usl(model)<EOL>if not isinstance(self.model, Topic):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>self.paths = [path(p) for p in path_list]<EOL>if any(p.cardinal != <NUM_LIT:1> for p in self.paths):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>self.multiples = []<EOL>self.result = []<EOL>self.build()<EOL>

:param model:
:param path_list:
:param translation_rule:


def get_translations(self, translation_template, mapping=None):

if mapping is None:<EOL><INDENT>mapping = {m['<STR_LIT:path>']: str(m['<STR_LIT:path>']) for m in self.multiples}<EOL><DEDENT>def _replace(u):<EOL><INDENT>translation = copy.deepcopy(translation_template)<EOL>for m in self.multiples:<EOL><INDENT>for l in LANGUAGES:<EOL><INDENT>translation[l] = translation[l].replace(mapping[m['<STR_LIT:path>']], u[m['<STR_LIT:path>']].translations[l])<EOL><DEDENT><DEDENT>return translation<EOL><DEDENT>return {u: _replace(u) for u in self.__iter__()}<EOL>

:param translation_template: str, a string with special string embedded to determine where to put the variation
translations
:param mapping: dict {path -> str} where str is the special string in translation template to replace with the
term translation
:return: dict {usl -> dict { str (language) ->  str}}


if obj.__class__ not in path.context.accept:<EOL><INDENT>result = set()<EOL>for ctx in path.context.accept:<EOL><INDENT>result |= {e for u in obj[ctx] for e in _resolve_path(u, path)}<EOL><DEDENT>return result<EOL><DEDENT>if isinstance(obj, Text):<EOL><INDENT>if path.index is not None:<EOL><INDENT>return {obj.children[path.index]}<EOL><DEDENT>return set(obj.children)<EOL><DEDENT>if isinstance(obj, (Fact, Theory)):<EOL><INDENT>return _resolve_path_tree_graph(obj.tree_graph, path)<EOL><DEDENT>if isinstance(obj, Topic):<EOL><INDENT>if path.kind == '<STR_LIT:r>':<EOL><INDENT>if path.index is not None:<EOL><INDENT>return {obj.root[path.index]}<EOL><DEDENT>return set(obj.root)<EOL><DEDENT>else:<EOL><INDENT>if path.index is not None:<EOL><INDENT>return {obj.flexing[path.index]}<EOL><DEDENT>return set(obj.flexing)<EOL><DEDENT><DEDENT>


if not rules:<EOL><INDENT>raise ResolveError("<STR_LIT>")<EOL><DEDENT>if len(rules) == <NUM_LIT:1> and rules[<NUM_LIT:0>][<NUM_LIT:0>] is None:<EOL><INDENT>return rules[<NUM_LIT:0>][<NUM_LIT:1>]<EOL><DEDENT>if any(r[<NUM_LIT:0>] is None for r in rules):<EOL><INDENT>raise ResolveError("<STR_LIT>")<EOL><DEDENT>if any(not isinstance(r[<NUM_LIT:0>], Path) for r in rules):<EOL><INDENT>raise ResolveError("<STR_LIT>")<EOL><DEDENT>r0 = rules[<NUM_LIT:0>]<EOL>types = _inferred_types(*r0)<EOL>for r in rules[<NUM_LIT:1>:]:<EOL><INDENT>types = types.intersection(_inferred_types(*r))<EOL><DEDENT>if not types:<EOL><INDENT>raise ResolveError("<STR_LIT>")<EOL><DEDENT>if len(types) > <NUM_LIT:1>:<EOL><INDENT>raise ResolveError("<STR_LIT>")<EOL><DEDENT>type = next(types.__iter__())<EOL>if type == Topic:<EOL><INDENT>error, deps = _build_deps_topic(rules)<EOL>if error:<EOL><INDENT>return<EOL><DEDENT>flexing = None<EOL>if deps['<STR_LIT:f>']:<EOL><INDENT>flexing = deps['<STR_LIT:f>']<EOL><DEDENT>if not deps['<STR_LIT:r>']:<EOL><INDENT>raise ResolveError("<STR_LIT>")<EOL><DEDENT>return topic(deps['<STR_LIT:r>'], flexing)<EOL><DEDENT>if type == Text:<EOL><INDENT>error, deps = _build_deps_text(rules)<EOL>if error:<EOL><INDENT>return<EOL><DEDENT>return text(deps)<EOL><DEDENT>if type in (Theory, Fact):<EOL><INDENT>error, deps = _build_deps_tree_graph(rules)<EOL>if error:<EOL><INDENT>return<EOL><DEDENT>if type == Fact:<EOL><INDENT>clauses = []<EOL>for s, a, m in deps:<EOL><INDENT>clauses.append((s, a, m))<EOL><DEDENT>return fact(clauses)<EOL><DEDENT>else:<EOL><INDENT>clauses = []<EOL>for s, a, m in deps:<EOL><INDENT>clauses.append((s, a, m))<EOL><DEDENT>return theory(clauses)<EOL><DEDENT><DEDENT>raise ResolveError("<STR_LIT>"%type.__name__)<EOL>

Resolve the context of the rules (the type of this element), and building the ieml element.
:param rules:
:return:


<EOL>with self.lock:<EOL><INDENT>try:<EOL><INDENT>return self.parser.parse(s, lexer=self.lexer, debug=False)<EOL><DEDENT>except CannotParse as e:<EOL><INDENT>e.s = s<EOL>raise e<EOL><DEDENT><DEDENT>

Parses the input string, and returns a reference to the created AST's root


if len(p[<NUM_LIT:1>].children) == <NUM_LIT:1>:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>].children[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL><DEDENT>


p[<NUM_LIT:0>] = AdditivePath(p[<NUM_LIT:1>])<EOL>


if len(p) == <NUM_LIT:2>:<EOL><INDENT>p[<NUM_LIT:0>] = [p[<NUM_LIT:1>]]<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>] + [p[<NUM_LIT:3>]]<EOL><DEDENT>

path_sum : ctx_path
                  | path_sum PLUS ctx_path


if len(p[<NUM_LIT:1>]) == <NUM_LIT:1>:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>][<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = ContextPath(p[<NUM_LIT:1>])<EOL><DEDENT>


ctx_coords : multiplicative_path
                        | ctx_coords COLON multiplicative_path


p[<NUM_LIT:0>] = MultiplicativePath(p[<NUM_LIT:1>])<EOL>


if len(p) == <NUM_LIT:2>:<EOL><INDENT>p[<NUM_LIT:0>] = [p[<NUM_LIT:1>]]<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>] + [p[<NUM_LIT:2>]]<EOL><DEDENT>

product : additive_path_p
                    | coordinate
                    | product additive_path_p
                    | product coordinate


p[<NUM_LIT:0>] = p[<NUM_LIT:2>]<EOL>

additive_path_p : LPAREN additive_path RPAREN


if len(p) == <NUM_LIT:2>:<EOL><INDENT>p[<NUM_LIT:0>] = Coordinate(p[<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = Coordinate(p[<NUM_LIT:1>], int(p[<NUM_LIT:2>]))<EOL><DEDENT>

coordinate : COORD_KIND
                        | COORD_KIND COORD_INDEX


with self.lock:<EOL><INDENT>try:<EOL><INDENT>return self.parser.parse(s, lexer=self.lexer)<EOL><DEDENT>except InvalidIEMLObjectArgument as e:<EOL><INDENT>raise CannotParse(s, str(e))<EOL><DEDENT>except CannotParse as e:<EOL><INDENT>e.s = s<EOL>raise e<EOL><DEDENT><DEDENT>


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

proposition :  word
                        | topic
                        | fact
                        | theory
                        | text


if len(p) == <NUM_LIT:3>:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>] + [p[<NUM_LIT:2>][<NUM_LIT:1>:-<NUM_LIT:1>]]<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = [p[<NUM_LIT:1>][<NUM_LIT:1>:-<NUM_LIT:1>]]<EOL><DEDENT>

literal_list : literal_list LITERAL
                        | LITERAL


try:<EOL><INDENT>term = self._get_term(p[<NUM_LIT:1> if len(p) == <NUM_LIT:2> else <NUM_LIT:2>])<EOL><DEDENT>except TermNotFoundInDictionary as e:<EOL><INDENT>raise CannotParse(self._ieml, str(e))<EOL><DEDENT>if len(p) == <NUM_LIT:5>:<EOL><INDENT>p[<NUM_LIT:0>] = Word(term, literals=p[<NUM_LIT:4>])<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = Word(term)<EOL><DEDENT>

word : TERM
                | LBRACKET TERM RBRACKET
                | LBRACKET TERM RBRACKET literal_list


<EOL>if len(p) == <NUM_LIT:4>:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>] + [p[<NUM_LIT:3>]]<EOL><DEDENT>elif len(p) == <NUM_LIT:3>:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>] + [p[<NUM_LIT:2>]]<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = [p[<NUM_LIT:1>]]<EOL><DEDENT>

word_sum : word_sum PLUS word
                    | word
            clauses_sum : clauses_sum PLUS clause
                    | clause
            superclauses_sum : superclauses_sum PLUS superclause
                    | superclause


p[<NUM_LIT:0>] = sorted(p[<NUM_LIT:2>])<EOL>


if len(p) == <NUM_LIT:4>:<EOL><INDENT>p[<NUM_LIT:0>] = Topic(root=tuple(p[<NUM_LIT:2>]), flexing=())<EOL><DEDENT>elif len(p) == <NUM_LIT:5>:<EOL><INDENT>p[<NUM_LIT:0>] = Topic(root=tuple(p[<NUM_LIT:2>]), flexing=(), literals=p[<NUM_LIT:4>])<EOL><DEDENT>elif len(p) == <NUM_LIT:6>:<EOL><INDENT>p[<NUM_LIT:0>] = Topic(root=tuple(p[<NUM_LIT:2>]), flexing=tuple(p[<NUM_LIT:4>]))<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = Topic(root=tuple(p[<NUM_LIT:2>]), flexing=tuple(p[<NUM_LIT:4>]), literals=p[<NUM_LIT:6>])<EOL><DEDENT>

topic : LBRACKET morpheme RBRACKET
                | LBRACKET morpheme RBRACKET literal_list
                | LBRACKET morpheme TIMES morpheme RBRACKET
                | LBRACKET morpheme TIMES morpheme RBRACKET literal_list


<EOL>p[<NUM_LIT:0>] = (p[<NUM_LIT:2>], p[<NUM_LIT:4>], p[<NUM_LIT:6>])<EOL>

clause : LPAREN topic TIMES topic TIMES topic RPAREN


if len(p) == <NUM_LIT:4>:<EOL><INDENT>p[<NUM_LIT:0>] = Fact(p[<NUM_LIT:2>])<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = Fact(p[<NUM_LIT:2>], literals=p[<NUM_LIT:4>])<EOL><DEDENT>

fact : LBRACKET clauses_sum RBRACKET
                | LBRACKET clauses_sum RBRACKET literal_list


superclause : LPAREN fact TIMES fact TIMES fact RPAREN


if len(p) == <NUM_LIT:4>:<EOL><INDENT>p[<NUM_LIT:0>] = Theory(p[<NUM_LIT:2>])<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = Theory(p[<NUM_LIT:2>], literals=p[<NUM_LIT:4>])<EOL><DEDENT>

theory : LBRACKET superclauses_sum RBRACKET
                  | LBRACKET superclauses_sum RBRACKET literal_list


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

closed_proposition : topic
                               | fact
                               | theory


if len(p) == <NUM_LIT:2>:<EOL><INDENT>p[<NUM_LIT:0>] = [p[<NUM_LIT:1>]]<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>] + [p[<NUM_LIT:4>]]<EOL><DEDENT>

closed_proposition_list :  closed_proposition_list SLASH SLASH closed_proposition
                                    | closed_proposition


p[<NUM_LIT:0>] = Text(p[<NUM_LIT:2>])<EOL>

text : SLASH closed_proposition_list SLASH


<EOL>self.transitions = defaultdict(list)<EOL>for t in list_transitions:<EOL><INDENT>self.transitions[t[<NUM_LIT:0>]].append((t[<NUM_LIT:1>], t))<EOL><DEDENT>self.nodes = sorted(set(self.transitions) | {e[<NUM_LIT:0>] for l in self.transitions.values() for e in l})<EOL>for s in self.transitions:<EOL><INDENT>self.transitions[s].sort(key=lambda t: self.nodes.index(t[<NUM_LIT:0>]))<EOL><DEDENT>self.nodes_index = {n: i for i, n in enumerate(self.nodes)}<EOL>_count = len(self.nodes)<EOL>self.array = numpy.zeros((len(self.nodes), len(self.nodes)), dtype=bool)<EOL>for t in self.transitions:<EOL><INDENT>for end in self.transitions[t]:<EOL><INDENT>self.array[self.nodes_index[t]][self.nodes_index[end[<NUM_LIT:0>]]] = True<EOL><DEDENT><DEDENT>parents_count = numpy.dot(self.array.transpose().astype(dtype=int), numpy.ones((_count,), dtype=int))<EOL>no_parents = parents_count == <NUM_LIT:0><EOL>roots_count = numpy.count_nonzero(no_parents)<EOL>if roots_count == <NUM_LIT:0>:<EOL><INDENT>raise InvalidTreeStructure('<STR_LIT>')<EOL><DEDENT>elif roots_count > <NUM_LIT:1>:<EOL><INDENT>raise InvalidTreeStructure('<STR_LIT>')<EOL><DEDENT>self.root = self.nodes[no_parents.nonzero()[<NUM_LIT:0>][<NUM_LIT:0>]]<EOL>if (parents_count > <NUM_LIT:1>).any():<EOL><INDENT>raise InvalidTreeStructure('<STR_LIT>')<EOL><DEDENT>def __stage():<EOL><INDENT>current = [self.root]<EOL>while current:<EOL><INDENT>yield current<EOL>current = [child[<NUM_LIT:0>] for parent in current for child in self.transitions[parent]]<EOL><DEDENT><DEDENT>self.stages = list(__stage())<EOL>

Transitions list must be the (start, end, data) the data will be stored as the transition tag
:param list_transitions:


def is_connexe_tilling(coords):<EOL><INDENT>shape_t = self.shape<EOL>size = <NUM_LIT:1><EOL>for i, indexes in enumerate(zip(*coords)):<EOL><INDENT>indexes = sorted(set(indexes))<EOL>size *= len(indexes)<EOL>missing = [j for j in range(shape_t[i]) if j not in indexes]<EOL>transitions = [j for j in missing if (j + <NUM_LIT:1>) % shape_t[i] not in missing]<EOL>if len(transitions) > <NUM_LIT:1>:<EOL><INDENT>step = int(shape_t[i] / len(transitions))<EOL>if any((j + step)%shape_t[i] not in transitions for j in transitions):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>if len(indexes) < <NUM_LIT:2> and i != <NUM_LIT:2>:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>if len(coords) == size:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL><DEDENT>def is_dim_subset(coords):<EOL><INDENT>"""<STR_LIT>"""<EOL>shape_ts0 = tuple(len(set(indexes)) for indexes in zip(*coords))<EOL>shape_t = self.shape<EOL>if shape_ts0[<NUM_LIT:0>] == shape_t[<NUM_LIT:0>]:<EOL><INDENT>return True, shape_ts0[<NUM_LIT:1>]<EOL><DEDENT>if shape_ts0[<NUM_LIT:1>] == shape_t[<NUM_LIT:1>]:<EOL><INDENT>return True, shape_ts0[<NUM_LIT:0>]<EOL><DEDENT>return False, <NUM_LIT:0><EOL><DEDENT>if script not in self.script:<EOL><INDENT>return False, False<EOL><DEDENT>if self.rank != <NUM_LIT:0> and self.rank % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>return False, False<EOL><DEDENT>coords = sorted([self.index_of(ss) for ss in script.singular_sequences])<EOL>is_dim, count = is_dim_subset(coords)<EOL>if is_dim and count == <NUM_LIT:1>:<EOL><INDENT>return True, True<EOL><DEDENT>if is_connexe_tilling(coords) or is_dim:<EOL><INDENT>return True, False<EOL><DEDENT>return False, False<EOL>

:param term:
:return: is_accepting, is_regular


if isinstance(self.parent, TableSet):<EOL><INDENT>return False, False<EOL><DEDENT>tables = [table for table in self.script.tables_script if table in script]<EOL>if len(tables) >= <NUM_LIT:1> and {ss for t in tables for ss in t.singular_sequences} == set(script.singular_sequences):<EOL><INDENT>return True, False<EOL><DEDENT>return False, False<EOL>

True when the term is a subset of this term tables. If the parent of this term is already a TableSet,return
always false (only one main tableset)
:param term:
:return:


instance = super(Script, cls).__new__(cls)<EOL>if '<STR_LIT:str>' in kwargs:<EOL><INDENT>instance._str = kwargs['<STR_LIT:str>']<EOL><DEDENT>return instance<EOL>

Need this to pickle scripts, the pickler use __hash__ method before unpickling the
object attribute. Then need to pass the _str.


return self._str.__hash__()<EOL>

Since the IEML string for any proposition AST is supposed to be unique, it can be used as a hash


_sum = []<EOL>for f in facto_list:<EOL><INDENT>if isinstance(f, Script):<EOL><INDENT>_sum.append(f)<EOL><DEDENT>else:<EOL><INDENT>_sum.append(MultiplicativeScript(children=(pack_factorisation(l_f) for l_f in f)))<EOL><DEDENT><DEDENT>if len(_sum) == <NUM_LIT:1>:<EOL><INDENT>return _sum[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return AdditiveScript(children=_sum)<EOL><DEDENT>

:param facto_list: list of parser or tuple of factorisation
:return:


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>

term : script_lvl_0
                | additive_script_lvl_0
                | script_lvl_1
                | additive_script_lvl_1
                | script_lvl_2
                | additive_script_lvl_2
                | script_lvl_3
                | additive_script_lvl_3
                | script_lvl_4
                | additive_script_lvl_4
                | script_lvl_5
                | additive_script_lvl_5
                | script_lvl_6
                | additive_script_lvl_6


if p[<NUM_LIT:1>] == '<STR_LIT:E>':<EOL><INDENT>p[<NUM_LIT:0>] = NullScript(layer=<NUM_LIT:0>)<EOL><DEDENT>elif p[<NUM_LIT:1>] in REMARKABLE_ADDITION:<EOL><INDENT>p[<NUM_LIT:0>] = AdditiveScript(character=p[<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = MultiplicativeScript(character=p[<NUM_LIT:1>])<EOL><DEDENT>

script_lvl_0 : PRIMITIVE LAYER0_MARK
                            | REMARKABLE_ADDITION LAYER0_MARK


p[<NUM_LIT:0>] = AdditiveScript(children=p[<NUM_LIT:1>])<EOL>


if len(p) == <NUM_LIT:4>:<EOL><INDENT>p[<NUM_LIT:3>].append(p[<NUM_LIT:1>])<EOL>p[<NUM_LIT:0>] = p[<NUM_LIT:3>]<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = [p[<NUM_LIT:1>]]<EOL><DEDENT>

sum_lvl_0 : script_lvl_0
                    | script_lvl_0 PLUS sum_lvl_0


if isinstance(p[<NUM_LIT:1>], AdditiveScript):<EOL><INDENT>if len(p) == <NUM_LIT:3>:<EOL><INDENT>p[<NUM_LIT:0>] = MultiplicativeScript(substance=p[<NUM_LIT:1>])<EOL><DEDENT>elif len(p) == <NUM_LIT:4>:<EOL><INDENT>p[<NUM_LIT:0>] = MultiplicativeScript(substance=p[<NUM_LIT:1>],<EOL>attribute=p[<NUM_LIT:2>])<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = MultiplicativeScript(substance=p[<NUM_LIT:1>],<EOL>attribute=p[<NUM_LIT:2>],<EOL>mode=p[<NUM_LIT:3>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = MultiplicativeScript(character=p[<NUM_LIT:1>])<EOL><DEDENT>

script_lvl_1 : additive_script_lvl_0 LAYER1_MARK
                        | additive_script_lvl_0 additive_script_lvl_0 LAYER1_MARK
                        | additive_script_lvl_0 additive_script_lvl_0 additive_script_lvl_0 LAYER1_MARK
                        | REMARKABLE_MULTIPLICATION LAYER1_MARK


sum_lvl_1 : script_lvl_1
                    |  script_lvl_1 PLUS sum_lvl_1


if _default_version is None:<EOL><INDENT>set_default_dictionary_version(latest_dictionary_version())<EOL><DEDENT>return _default_version<EOL>

Return the default dictionary version. The version is the latest version installed on
the system by default. If there is none installed yet, it download and install the latest version
available online.
To upgrade to a newer version, you can run `set_default_dictionary_version(latest_dictionary_version())`

:return: the default dictionary version


def create_dictionary_version(old_version=None, add=None, update=None, remove=None, diff=None):

v = latest_dictionary_version()<EOL>last_date = v.date<EOL>while True:<EOL><INDENT>new_date = datetime.datetime.utcnow()<EOL>if new_date != last_date:<EOL><INDENT>break<EOL><DEDENT><DEDENT>new_version_name = version_name(new_date)<EOL>if old_version is None:<EOL><INDENT>old_version = v<EOL><DEDENT>old_version.load()<EOL>state = {<EOL>'<STR_LIT:version>': _date_to_str(new_date),<EOL>'<STR_LIT>': copy.deepcopy(old_version.terms),<EOL>'<STR_LIT>': copy.deepcopy(old_version.roots),<EOL>'<STR_LIT>': copy.deepcopy(old_version.inhibitions),<EOL>'<STR_LIT>': copy.deepcopy(old_version.translations),<EOL>'<STR_LIT>': {**copy.deepcopy(old_version.diff),<EOL>str(old_version): diff if diff else {}},<EOL>'<STR_LIT>': {**copy.deepcopy(old_version.history),<EOL>new_version_name: {}}<EOL>}<EOL>if remove is not None:<EOL><INDENT>state['<STR_LIT>'] = list(set(state['<STR_LIT>']).difference(remove))<EOL>state['<STR_LIT>'] = list(set(state['<STR_LIT>']).difference(remove))<EOL>for r in remove:<EOL><INDENT>if r in state['<STR_LIT>']:<EOL><INDENT>del state['<STR_LIT>'][r]<EOL><DEDENT>for l in LANGUAGES:<EOL><INDENT>if r in state['<STR_LIT>'][l]:<EOL><INDENT>del state['<STR_LIT>'][l][r]<EOL><DEDENT><DEDENT>state['<STR_LIT>'][str(old_version)][r] = None<EOL>state['<STR_LIT>'][new_version_name][r] = '<STR_LIT:->'<EOL><DEDENT><DEDENT>if add is not None:<EOL><INDENT>if '<STR_LIT>' in add:<EOL><INDENT>state['<STR_LIT>'] = list(set(state['<STR_LIT>']).union(add['<STR_LIT>']))<EOL>for t in add['<STR_LIT>']:<EOL><INDENT>state['<STR_LIT>'][new_version_name][t] = '<STR_LIT:+>'<EOL><DEDENT><DEDENT>if '<STR_LIT>' in add:<EOL><INDENT>state['<STR_LIT>'] = list(set(state['<STR_LIT>']).union(add['<STR_LIT>']))<EOL>for t in add['<STR_LIT>']:<EOL><INDENT>state['<STR_LIT>'][new_version_name][t] = '<STR_LIT:+>'<EOL><DEDENT><DEDENT>if '<STR_LIT>' in add:<EOL><INDENT>if set(state['<STR_LIT>']).intersection(set(add['<STR_LIT>'])):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>state['<STR_LIT>'] = {**state['<STR_LIT>'], **add['<STR_LIT>']}<EOL><DEDENT>if '<STR_LIT>' in add:<EOL><INDENT>if any(set(state['<STR_LIT>'][l]).intersection(set(add['<STR_LIT>'][l])) for l in LANGUAGES):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"%'<STR_LIT:U+002CU+0020>'.join(['<STR_LIT>'%(l, '<STR_LIT:U+002CU+0020>'.join('<STR_LIT>'%str(t) for t in set(state['<STR_LIT>'][l]).intersection(set(add['<STR_LIT>'][l])))) for l in LANGUAGES]))<EOL><DEDENT>state['<STR_LIT>'] = {l: {**state['<STR_LIT>'][l], **add['<STR_LIT>'][l]} for l in LANGUAGES}<EOL><DEDENT><DEDENT>if update is not None:<EOL><INDENT>if '<STR_LIT>' in update:<EOL><INDENT>for s, l in update['<STR_LIT>'].items():<EOL><INDENT>if s not in state['<STR_LIT>']:<EOL><INDENT>continue<EOL><DEDENT>state['<STR_LIT>'][s] = l<EOL><DEDENT><DEDENT>if '<STR_LIT>' in update:<EOL><INDENT>state['<STR_LIT>'] = {l: {**state['<STR_LIT>'][l], **update['<STR_LIT>'][l]} for l in LANGUAGES}<EOL><DEDENT>if '<STR_LIT>' in update:<EOL><INDENT>state['<STR_LIT>'] = set(t for t in state['<STR_LIT>'] if t not in update['<STR_LIT>'])<EOL>roots = set(state['<STR_LIT>']).intersection(update['<STR_LIT>'])<EOL>state['<STR_LIT>'] = set(t for t in state['<STR_LIT>'] if t not in update['<STR_LIT>'])<EOL>for t_old in update['<STR_LIT>']:<EOL><INDENT>t_new = update['<STR_LIT>'][t_old]<EOL>state['<STR_LIT>'][new_version_name][t_old] = '<STR_LIT:->'<EOL>state['<STR_LIT>'][new_version_name][t_new] = '<STR_LIT:+>'<EOL>state['<STR_LIT>'][str(old_version)][t_old] = t_new<EOL>state['<STR_LIT>'].add(t_new)<EOL>if t_old in roots:<EOL><INDENT>state['<STR_LIT>'].add(t_new)<EOL><DEDENT>for l in LANGUAGES:<EOL><INDENT>state['<STR_LIT>'][l][t_new] = state['<STR_LIT>'][l][t_old]<EOL>del state['<STR_LIT>'][l][t_old]<EOL><DEDENT>if t_old in state['<STR_LIT>']:<EOL><INDENT>state['<STR_LIT>'][t_new] = state['<STR_LIT>'][t_old]<EOL>del state['<STR_LIT>'][t_old]<EOL><DEDENT><DEDENT>state['<STR_LIT>'] = list(state['<STR_LIT>'])<EOL>state['<STR_LIT>'] = list(state['<STR_LIT>'])<EOL><DEDENT><DEDENT>dictionary_version = DictionaryVersion(new_date)<EOL>dictionary_version.__setstate__(state)<EOL>from ieml.dictionary import Dictionary<EOL>if set(old_version.terms) == set(state['<STR_LIT>']) and set(old_version.roots) == set(state['<STR_LIT>']) andall(old_version.inhibitions[s] == state['<STR_LIT>'][s] for s in old_version.inhibitions):<EOL><INDENT>old_dict_state = Dictionary(old_version).__getstate__()<EOL>d = Dictionary.__new__(Dictionary)<EOL>rel_graph = RelationsGraph.__new__(RelationsGraph)<EOL>rel_graph.__setstate__({<EOL>'<STR_LIT>': d,<EOL>'<STR_LIT>': old_dict_state['<STR_LIT>'].__getstate__()['<STR_LIT>']<EOL>})<EOL>state = {<EOL>'<STR_LIT:version>': dictionary_version,<EOL>'<STR_LIT>': rel_graph,<EOL>'<STR_LIT>': old_dict_state['<STR_LIT>'],<EOL>}<EOL>d.__setstate__(state)<EOL>save_dictionary_to_cache(d)<EOL><DEDENT>else:<EOL><INDENT>Dictionary(dictionary_version)<EOL><DEDENT>return dictionary_version<EOL>

:param old_version: the dictionary version to build the new version from
:param add: a dict with the element to add {'terms': list of script to add,
                                            'roots': list of script to add root paradigm,
                                            'inhibitions': dict {root_p: list of relations to inhibits in this root p}
                                            'translations': dict {language: {script: traduction}}}
:param update: a dict to update the translations and inhibtions or the terms (new mapping)
        map terms|inhibitions|translations -> old -> new
:param remove: a list of term to remove, they are removed from root, terms, inhibitions and translations
:return:


if self.loaded:<EOL><INDENT>return<EOL><DEDENT>file_name = "<STR_LIT>" % str(self)<EOL>file = os.path.join(VERSIONS_FOLDER, file_name)<EOL>if not os.path.isfile(file):<EOL><INDENT>DICTIONARY_BUCKET_URL = get_configuration().get('<STR_LIT>', '<STR_LIT>')<EOL>url = urllib.parse.urljoin(DICTIONARY_BUCKET_URL, file_name)<EOL>logger.log(logging.INFO, "<STR_LIT>" % (file_name, url))<EOL>urlretrieve(url, file)<EOL><DEDENT>with open(file, '<STR_LIT:r>') as fp:<EOL><INDENT>self.__setstate__(json.load(fp))<EOL><DEDENT>

Download the dictionary version and cache the retrieved file.
:return: None


return np.matrix(sum(self.relations.values()).todense(), dtype=bool)<EOL>

A boolean matrix, m[i, j] == True if there is a relation term(i) -> term(j)
:return: a np.matrix (len(dictionary), len(dictionary)) of boolean


if self.level >= Topic:<EOL><INDENT>self.topics_pool = set(self.topic() for i in range(self.pool_size))<EOL><DEDENT>if self.level >= Fact:<EOL><INDENT>self.facts_pool = set(self.fact() for i in range(self.pool_size))<EOL><DEDENT>if self.level >= Theory:<EOL><INDENT>self.theories_pool = set(self.theory() for i in range(self.pool_size))<EOL><DEDENT>if self.level >= Text:<EOL><INDENT>self.propositions_pool = set(chain.from_iterable((self.topics_pool, self.facts_pool, self.theories_pool)))<EOL><DEDENT>

Slow method, retrieve all the terms from the database.
:return:


cells_to_usls = defaultdict(set)<EOL>tables = set()<EOL>for u in usls:<EOL><INDENT>for t in u.objects(Term):<EOL><INDENT>for c in t.singular_sequences:<EOL><INDENT>if not cells_to_usls[c]:<EOL><INDENT>tables.update(c.relations.contained)<EOL><DEDENT>cells_to_usls[c].add(u)<EOL><DEDENT><DEDENT><DEDENT>if allowed_terms:<EOL><INDENT>allowed_terms = set(allowed_terms)<EOL>tables = tables & allowed_terms<EOL>cells_to_usls = {c: l for c, l in cells_to_usls.items() if c in allowed_terms}<EOL><DEDENT>tables_to_usls = {<EOL>table: list(set(u for c in table.singular_sequences for u in cells_to_usls[c]))<EOL>for table in tables if not isinstance(table, TableSet)<EOL>}<EOL>return tables_to_usls<EOL>

`usls` is an iterable of usl.

    return a mapping term -> usl list


projection = project_usls_on_dictionary(usls_data)<EOL>all_terms = set(c for u in usls_data for t in u.objects(Term) for c in t.singular_sequences)<EOL>if metric is None:<EOL><INDENT>metric = lambda e: len(e['<STR_LIT>']) * len(all_terms.intersection(e['<STR_LIT>'].singular_sequences))<EOL><DEDENT>return sorted(({<EOL>'<STR_LIT>': table,<EOL>'<STR_LIT>': usls,<EOL>'<STR_LIT>': list(set(chain.from_iterable(usls_data[u] for u in usls)))<EOL>} for table, usls in projection.items()), key=metric, reverse=True)<EOL>

usls_data: usl => data[]
:param usls_data:
:return:


def f(w1):<EOL><INDENT>count = [set(w0.root).intersection(w1.root),<EOL>set(w0.flexing).intersection(w1.flexing),<EOL>set(w0.root).intersection(w1.flexing) | set(w1.root).intersection(w0.flexing)]<EOL>if any(count):<EOL><INDENT>return max((<NUM_LIT:1>,<NUM_LIT:2>,<NUM_LIT:3>), key=lambda i: len(count[i - <NUM_LIT:1>]))<EOL><DEDENT>else:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT><DEDENT>return f<EOL>

0 -> no terms idd
1 -> most term idd are shared in root morphem
2 -> most term idd are shared in flexing morphem
3 -> most term idd are shared root <-> flexing (crossed)
:param w0:
:param w1:
:return:


root_w0_relations = set(chain.from_iterable(relations[t.index, :].indices for t in w0.root))<EOL>flexing_w0_relations = set(chain.from_iterable(relations[t.index, :].indices for t in w0.flexing))<EOL>def f(w1):<EOL><INDENT>root_w1 = set(t.index for t in w1.root)<EOL>flexing_w1 = set(t.index for t in w1.flexing)<EOL>count = [root_w0_relations.intersection(root_w1),<EOL>flexing_w0_relations.intersection(flexing_w1),<EOL>root_w0_relations.intersection(flexing_w1) | flexing_w0_relations.intersection(root_w1)]<EOL>if any(count):<EOL><INDENT>return max((<NUM_LIT:1>,<NUM_LIT:2>,<NUM_LIT:3>), key=lambda i: len(count[i - <NUM_LIT:1>]))<EOL><DEDENT>else:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT><DEDENT>return f<EOL>


usl_list = list(usl_list)<EOL>indexes = {<EOL>u: i for i, u in enumerate(usl_list)<EOL>}<EOL>order_mat = np.zeros(shape=(len(usl_list), len(usl_list)), dtype=int)<EOL>for u in usl_list:<EOL><INDENT>sorted_list = QuerySort(u).sort(collection=usl_list)<EOL>for i, u_s in enumerate(sorted_list):<EOL><INDENT>order_mat[indexes[u], indexes[u_s]] = i<EOL><DEDENT><DEDENT>return order_mat<EOL>

Compute the ordering of a list of usls from each usl and return the matrix m s.t.
for each u in usl_list at index i, [usl_list[j] for j in m[i, :]] is the list sorted
by proximity from u.
 of the result
:param usl_list: a list of usls
:return: a (len(usl_list), len(usl_list)) np.array


return self.__str__().__hash__()<EOL>


return self.children.__iter__()<EOL>

Enables the syntactic sugar of iterating directly on an element without accessing "children


version0.load()<EOL>version1.load()<EOL>deleted = set(version0.terms) - set(version1.terms)<EOL>added = set(version1.terms) - set(version0.terms)<EOL>print("<STR_LIT>".format(str(version0)))<EOL>print("<STR_LIT:\n>".join(("<STR_LIT>".format(str(d), version0.translations['<STR_LIT>'][d]) for d in deleted)))<EOL>print("<STR_LIT>".format(str(version1)))<EOL>print("<STR_LIT:\n>".join(("<STR_LIT>".format(str(d), version1.translations['<STR_LIT>'][d]) for d in added)))<EOL>

Display the terms added and removed between two versions
:param version0:
:param version1:
:return:


result = {}<EOL>try:<EOL><INDENT>response = urllib.request.urlopen('<STR_LIT>'+ quote_plus(descriptor.rstrip('<STR_LIT>')) + '<STR_LIT>')<EOL><DEDENT>except IOError:<EOL><INDENT>return result<EOL><DEDENT>else:<EOL><INDENT>html = response.read()<EOL>soup = BeautifulSoup(html, '<STR_LIT>')<EOL>for language in ("<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>"):<EOL><INDENT>titles_list = [el.attrs["<STR_LIT:title>"] for el in soup.select('<STR_LIT>'%language)if "<STR_LIT:title>" in el.attrs]<EOL>if titles_list:  <EOL><INDENT>result[language.lower()] = set(titles_list)<EOL><DEDENT><DEDENT><DEDENT>return result<EOL>

:param descriptor:
:return: a dict language -> set of str representing the drived t$erm in that language


if isinstance(s, AdditiveScript):<EOL><INDENT>return AdditiveScript([_rotate_sc(_s) for _s in s])<EOL><DEDENT>else:<EOL><INDENT>return _rotate_sc(s)<EOL><DEDENT>


subst, attr, mode = s<EOL>subst0, subst1, _mode = subst<EOL>assert isinstance(_mode, NullScript)<EOL>return m(m(m(subst0)) ,m(m(subst1), attr) ,m(mode))<EOL>


subst, attr, mode = s<EOL>attr0, attr1, attr2 = attr<EOL>assert isinstance(attr1, NullScript) and isinstance(attr2, NullScript)<EOL>subst, subst1, subst2 = subst<EOL>assert isinstance(subst1, NullScript) and isinstance(subst2, NullScript)<EOL>subst0, subst1, subst2 = subst<EOL>assert isinstance(subst2, NullScript)<EOL>return m(m(m(subst0)), m(m(subst1), attr0), mode)<EOL>


subst, attr, mode = s<EOL>assert isinstance(mode, NullScript)<EOL>return m(subst, attr, script('<STR_LIT>'))<EOL>


subst, attr, mode = s<EOL>assert isinstance(mode, NullScript)<EOL>return m(subst, script('<STR_LIT>'), attr)<EOL>


subst, attr, mode = s<EOL>assert isinstance(mode, NullScript)<EOL>if isinstance(subst, AdditiveScript):<EOL><INDENT>subst = AdditiveScript([_insert_attr_f(_s) for _s in subst])<EOL><DEDENT>else:<EOL><INDENT>subst = _insert_attr_f(subst)<EOL><DEDENT>return m(subst ,attr)<EOL>


subst, attr, mode = s<EOL>return m(subst, attr, script("<STR_LIT>"))<EOL>


version = DictionaryVersion(latest_dictionary_version())<EOL>version.load()<EOL>to_remove = []<EOL>to_add = {<EOL>'<STR_LIT>': [],<EOL>'<STR_LIT>': [],<EOL>'<STR_LIT>': {},<EOL>'<STR_LIT>': {l: {} for l in LANGUAGES}<EOL>}<EOL>for root, func in to_translate.items():<EOL><INDENT>root = script(root)<EOL>terms = list(filter(lambda s: s in root, map(script, version.terms)))<EOL>new_root = func(root)<EOL>new_terms = [func(s) for s in terms]<EOL>to_add['<STR_LIT>'].extend(map(str, new_terms))<EOL>to_add['<STR_LIT>'].append(str(new_root))<EOL>to_add['<STR_LIT>'].update({str(new_root): version.inhibitions[root]})<EOL>for l in LANGUAGES:<EOL><INDENT>to_add['<STR_LIT>'][l].update({str(func(s)): version.translations[l][s] for s in terms})<EOL><DEDENT>to_remove.extend(map(str, terms))<EOL><DEDENT>return create_dictionary_version(version, add=to_add, remove=to_remove)<EOL>

translate the root paradigms in key in argument, with the function in value
:param to_translate:
:return:


subst, attr, mode = s<EOL>return m(subst, mode)<EOL>


subst, attr, mode = s<EOL>assert isinstance(mode, NullScript)<EOL>if isinstance(subst, AdditiveScript):<EOL><INDENT>subst = AdditiveScript([_remove_attr_f(_s) for _s in subst])<EOL><DEDENT>else:<EOL><INDENT>subst = _remove_attr_f(subst)<EOL><DEDENT>return m(subst, attr)<EOL>


subst, attr, mode = s<EOL>attr_s, attr_a, attr_m = attr<EOL>assert isinstance(attr_m, NullScript)<EOL>subst_s, subst_a, subst_m = subst<EOL>assert isinstance(subst_m, NullScript)<EOL>first_M = subst_s.children[<NUM_LIT:0>].children[<NUM_LIT:0>]<EOL>return m(m(mode, m(attr_a)), m(m(m(m(first_M, attr_s.children[<NUM_LIT:0>].children[<NUM_LIT:0>])))), m(m(subst_a)))<EOL>


subst, attr, mode = s<EOL>return m(script('<STR_LIT>'),<EOL>m(subst.children[<NUM_LIT:0>].children[<NUM_LIT:0>], subst.children[<NUM_LIT:1>].children[<NUM_LIT:0>]),<EOL>m(attr.children[<NUM_LIT:0>].children[<NUM_LIT:0>], attr.children[<NUM_LIT:1>].children[<NUM_LIT:0>]))<EOL>


subst, attr, mode = s<EOL>return m(m(subst), m(attr), script("<STR_LIT>"))<EOL>


def set_bSU_subst(s):<EOL><INDENT>subst, attr, mode = s<EOL>return m(script("<STR_LIT>"), attr, mode)<EOL><DEDENT>if isinstance(s, AdditiveScript):<EOL><INDENT>return AdditiveScript([set_bSU_subst(i) for i in s.children])<EOL><DEDENT>else:<EOL><INDENT>return set_bSU_subst(s)<EOL><DEDENT>


subst, attr, mode = s<EOL>return m(script("<STR_LIT>"), m(m(m(attr.children[<NUM_LIT:0>], subst.children[<NUM_LIT:0>]))))<EOL>


subst, attr, mode = s<EOL>return m(translate_ecosystem_intl_col(subst), m(m(attr)))<EOL>


def create_tcp_rpc_system(hostname=None, port_range=(<NUM_LIT:0>,), ping_interval=<NUM_LIT:1>, ping_timeout=<NUM_LIT:0.5>):

def ownid_factory(listeningport):<EOL><INDENT>port = listeningport.getHost().port<EOL>return "<STR_LIT>" %(hostname, port)<EOL><DEDENT>def make_client_endpoint(peer):<EOL><INDENT>host, port = peer.split("<STR_LIT::>")<EOL>if host == socket.getfqdn():<EOL><INDENT>host = "<STR_LIT:localhost>"<EOL><DEDENT>return endpoints.TCP4ClientEndpoint(reactor, host, int(port), timeout=<NUM_LIT:5>)<EOL><DEDENT>if hostname is None:<EOL><INDENT>hostname = socket.getfqdn()<EOL><DEDENT>server_endpointA = TCP4ServerRangeEndpoint(reactor, port_range)<EOL>pool = connectionpool.ConnectionPool(server_endpointA, make_client_endpoint, ownid_factory)<EOL>return RPCSystem(pool, ping_interval=ping_interval, ping_timeout=ping_timeout)<EOL>

Creates a TCP based :class:`RPCSystem`.

:param port_range: List of ports to try. If `[0]`, an arbitrary free
    port will be used.


def __init__(self, connectionpool, ping_interval = <NUM_LIT:5>*<NUM_LIT>, ping_timeout = <NUM_LIT>):

self._connectionpool = connectionpool<EOL>self._connectionpool.register_type(self._MESSAGE_TYPE)<EOL>self._opened = False<EOL>self._functions = bidict.bidict()<EOL>self._remote_to_local = {}<EOL>self._local_to_remote = {}<EOL>self._ping_interval = ping_interval<EOL>self._ping_timeout = ping_timeout<EOL>self._ping_loop = task.LoopingCall(self._ping_loop_iteration)<EOL>self._ping_current_iteration = None <EOL>self._functions[self._PING] = self._ping<EOL>

:param connectionpool: Messaging system to use for low-level communication.

:param ping_interval: Every `ping_interval` seconds we send for each unfinished
   call a message to our peers asking conformation that they are still working
   on it. If the peer has somehow 'lost' the call, or if we don't get a reply
   within `ping_timeout` seconds, the call will fail.

   This protects against unnoticed loss of connection, or if the remote process
   dies unexpectantly. In such cases the call might otherwise hang forever .

 :param ping_interval: See `ping_interval`-


return self._connectionpool.pre_connect(peer)<EOL>

Ensures that we have an open connection to the given peer.

Returns the peer id. This should be equal to the given one, but
it might not if the given peer was, say, the IP and the peer
actually identifies itself with a host name. The returned peer
is the real one that should be used. This can be handy if we aren't
100% sure of the peer's identity.


logging.debug("<STR_LIT>")<EOL>d = self._connectionpool.open(self._packet_received)<EOL>def opened(_):<EOL><INDENT>logging.debug("<STR_LIT>")<EOL>self._opened = True<EOL>logging.debug("<STR_LIT>")<EOL>self._ping_loop.start(self._ping_interval, now=False)<EOL><DEDENT>d.addCallback(opened)<EOL>return d<EOL>

Opens the port.

:returns: Deferred that callbacks when we are ready to make and receive calls.


assert self._opened, "<STR_LIT>"<EOL>logger.debug("<STR_LIT>")<EOL>self._ping_loop.stop()<EOL>if self._ping_current_iteration:<EOL><INDENT>self._ping_current_iteration.cancel()<EOL><DEDENT>return self._connectionpool.close()<EOL>

Stop listing for new connections and close all open connections.

:returns: Deferred that calls back once everything is closed.


assert self._opened, "<STR_LIT>"<EOL>logging.debug("<STR_LIT>" % repr(function))<EOL>if function in ~self._functions:<EOL><INDENT>functionid = self._functions[:function]<EOL><DEDENT>else:<EOL><INDENT>functionid = uuid.uuid1()<EOL>self._functions[functionid] = function<EOL><DEDENT>return "<STR_LIT>" % (self._connectionpool.ownid, functionid.hex)<EOL>

Registers the given callable in the system (if it isn't already)
and returns the URL that can be used to invoke the given function from remote.


assert self._opened, "<STR_LIT>"<EOL>logging.debug("<STR_LIT>" % repr(url))<EOL>parseresult = urlparse.urlparse(url)<EOL>scheme = parseresult.scheme<EOL>path = parseresult.path.split("<STR_LIT:/>")<EOL>if scheme != "<STR_LIT>":<EOL><INDENT>raise ValueError("<STR_LIT>" % repr(url))<EOL><DEDENT>if len(path) != <NUM_LIT:3> or path[<NUM_LIT:0>] != "<STR_LIT>" or path[<NUM_LIT:1>] != "<STR_LIT>":<EOL><INDENT>raise ValueError("<STR_LIT>" % repr(url))<EOL><DEDENT>try:<EOL><INDENT>functionid = uuid.UUID(path[<NUM_LIT:2>])<EOL><DEDENT>except ValueError:<EOL><INDENT>raise ValueError("<STR_LIT>" % repr(url))<EOL><DEDENT>return _RPCFunctionStub(parseresult.netloc, functionid, self)<EOL>

Create a callable that will invoke the given remote function.

The stub will return a deferred even if the remote function does not.


deferredList = []<EOL>for peerid, callid in list(self._local_to_remote):<EOL><INDENT>if (peerid, callid) not in self._local_to_remote:<EOL><INDENT>continue <EOL><DEDENT>logger.debug("<STR_LIT>")<EOL>d = self._invoke_function(peerid, self._PING, (self._connectionpool.ownid, callid), {})<EOL>def failed(failure):<EOL><INDENT>if (peerid, callid) in self._local_to_remote:<EOL><INDENT>d = self._local_to_remote.pop((peerid, callid))<EOL>d.errback(failure)<EOL><DEDENT><DEDENT>def success(value):<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>return value<EOL><DEDENT>d.addCallbacks(success, failed)<EOL>deferredList.append(d)<EOL><DEDENT>d = defer.DeferredList(deferredList)<EOL>def done(_):<EOL><INDENT>self._ping_current_iteration = None<EOL><DEDENT>self._ping_current_iteration = d<EOL>d.addBoth(done)<EOL>return d<EOL>

Called every `ping_interval` seconds.
Invokes `_ping()` remotely for every ongoing call.


if not (peerid, callid) in self._remote_to_local:<EOL><INDENT>logger.warn("<STR_LIT>" % (callid, peerid))<EOL><DEDENT>

Called from remote to ask if a call made to here is still in progress.


def __init__(self, stream_server_endpoint, make_client_endpoint, ownid_factory):

self.stream_server_endpoint = stream_server_endpoint<EOL>self.ownid_factory = ownid_factory<EOL>self.make_client_endpoint = make_client_endpoint<EOL>self._listeningport = None<EOL>self._connections = {}<EOL>self._ongoing_sends = set()<EOL>self.connection_established = None<EOL>self._typenames = set()<EOL>self._dummy_protocol = packetprotocol.PacketProtocol()<EOL>

:param stream_server_endpoint: `IStreamServerEndpoint` implementation. We will listen
  on this for incomming connections.

:param make_client_endpoint: Invoked when we need to connect to a peer. Returns
  `IStreamClientEndpoint` implementation that we can use to connect to that peer's
  `stream_server_endpoint`.

:param ownid: Identification string (such as hostname and port) that peers can use
  to connect to us.


<EOL>self._dummy_protocol.register_type(typename)<EOL>self._typenames.add(typename)<EOL>

Registers a type name so that it may be used to send and receive packages.

:param typename: Name of the packet type. A method with the same name and a
    "on_" prefix should be added to handle incomming packets.

:raises ValueError: If there is a hash code collision.


def port_open(listeningport):<EOL><INDENT>self._listeningport = listeningport<EOL>self.ownid = self.ownid_factory(listeningport)<EOL>logger.debug("<STR_LIT>" % self.ownid)<EOL>return None<EOL><DEDENT>logger.debug("<STR_LIT>")<EOL>self.packet_received = packet_received<EOL>d = self.stream_server_endpoint.listen(PoolFactory(self, self._typenames))<EOL>d.addCallback(port_open)<EOL>return d<EOL>

Opens the port.

:param packet_received: Callback which is invoked when we received a packet.
  Is passed the peer, typename, and data.

:returns: Deferred that callbacks when we are ready to receive.


if peer in self._connections:<EOL><INDENT>return defer.succeed(peer)<EOL><DEDENT>else:<EOL><INDENT>d = self._connect(peer, exact_peer=False)<EOL>def connected(p):<EOL><INDENT>return p.peer<EOL><DEDENT>d.addCallback(connected)<EOL>return d<EOL><DEDENT>


def attempt_to_send(_):<EOL><INDENT>if peer not in self._connections:<EOL><INDENT>d = self._connect(peer)<EOL>d.addCallback(attempt_to_send)<EOL>return d<EOL><DEDENT>else:<EOL><INDENT>conn = self._connections[peer][<NUM_LIT:0>]<EOL>conn.send_packet(typename, data)            <EOL>return defer.succeed(None)<EOL><DEDENT><DEDENT>d = attempt_to_send(None)<EOL>self._ongoing_sends.add(d)<EOL>def send_completed(result):<EOL><INDENT>if d in self._ongoing_sends:<EOL><INDENT>self._ongoing_sends.remove(d)<EOL><DEDENT>return result<EOL><DEDENT>d.addBoth(send_completed)<EOL>return d<EOL>


def cancel_sends(_):<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>while self._ongoing_sends:<EOL><INDENT>d = self._ongoing_sends.pop()<EOL>d.cancel()<EOL><DEDENT><DEDENT>def close_connections(_):<EOL><INDENT>all_connections = [c for conns in self._connections.itervalues() for c in conns]<EOL>logger.debug("<STR_LIT>" % len(all_connections))<EOL>for c in all_connections:<EOL><INDENT>c.transport.loseConnection()<EOL><DEDENT>ds = [c.wait_for_close() for c in all_connections]<EOL>d = defer.DeferredList(ds, fireOnOneErrback=True)<EOL>def allclosed(_):<EOL><INDENT>logger.debug("<STR_LIT>")<EOL><DEDENT>d.addCallback(allclosed)<EOL>return d<EOL><DEDENT>logger.debug("<STR_LIT>")<EOL>d = defer.maybeDeferred(self._listeningport.stopListening)<EOL>d.addCallback(cancel_sends)<EOL>d.addCallback(close_connections)<EOL>return d<EOL>


self._parts.append(s)<EOL>self._len += len(s)<EOL>

Append `s` to the queue.

Equivalent to::

    queue += s

if `queue` where a regular string.


if self._len < n:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>self._len -= n<EOL>def part_generator(n):<EOL><INDENT>"""<STR_LIT>"""<EOL>remaining = n<EOL>while remaining:<EOL><INDENT>part = self._parts.popleft()<EOL>if len(part) <= remaining:<EOL><INDENT>yield part<EOL>remaining -= len(part)<EOL><DEDENT>else:<EOL><INDENT>yield part[:remaining]<EOL>self._parts.appendleft(part[remaining:])<EOL>remaining = <NUM_LIT:0><EOL><DEDENT><DEDENT><DEDENT>return "<STR_LIT>".join(part_generator(n))<EOL>

Remove and return the first `n` characters from the queue.
Throws an error if there are less than `n` characters in the queue.

Equivalent to::

    s = queue[:n]
    queue = queue[n:]

if `queue` where a regular string.


if self._len < n:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>self._len -= n<EOL>remaining = n<EOL>while remaining:<EOL><INDENT>part = self._parts.popleft()<EOL>if len(part) <= remaining:<EOL><INDENT>remaining -= len(part)<EOL><DEDENT>else:<EOL><INDENT>self._parts.appendleft(part[remaining:])<EOL>remaining = <NUM_LIT:0><EOL><DEDENT><DEDENT>

Removes `n` bytes from the beginning of the queue.

Throws an error if there are less than `n` characters in the queue.

Equivalent to::

    queue = queue[n:]

if `queue` where a regular string.


if self._len < n:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>def part_generator(n):<EOL><INDENT>"""<STR_LIT>"""<EOL>remaining = n<EOL>for part in self._parts:<EOL><INDENT>if len(part) <= remaining:<EOL><INDENT>yield part<EOL>remaining -= len(part)<EOL><DEDENT>else:<EOL><INDENT>yield part[:remaining]<EOL>remaining = <NUM_LIT:0> <EOL><DEDENT>if remaining == <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>return "<STR_LIT>".join(part_generator(n))<EOL>

Return the first `n` characters from the queue without
removing them.
Throws an error if there are less than `n` characters in the queue.

Equivalent to::

    s = queue[:n]

if `queue` where a regular string.


return "<STR_LIT>".join(self._parts)<EOL>

Returns all bytes currently in the queue without removing them.


return self._len<EOL>

Returns the number of characters in the queue.


return binascii.crc32(typename) & <NUM_LIT><EOL>


typekey = typehash(typename)<EOL>if typekey in self._type_register:<EOL><INDENT>raise ValueError("<STR_LIT>" % repr(self._type_register[typekey]))<EOL><DEDENT>self._type_register[typekey] = typename<EOL>


self._unprocessed_data.enqueue(data)<EOL>while True:<EOL><INDENT>if len(self._unprocessed_data) < self._header.size:<EOL><INDENT>return <EOL><DEDENT>hdr_data = self._unprocessed_data.peek(self._header.size)<EOL>packet_length, typekey = self._header.unpack(hdr_data)<EOL>total_length = self._header.size + packet_length<EOL>if len(self._unprocessed_data) < total_length:<EOL><INDENT>return <EOL><DEDENT>self._unprocessed_data.drop(self._header.size)<EOL>packet = self._unprocessed_data.dequeue(packet_length)<EOL>self._start_receive = None<EOL>typename = self._type_register.get(typekey, None)<EOL>if typename is None:<EOL><INDENT>self.on_unregistered_type(typekey, packet)<EOL><DEDENT>else:<EOL><INDENT>self.packet_received(typename, packet)<EOL><DEDENT><DEDENT>

Do not overwrite this method. Instead implement `on_...` methods for the
registered typenames to handle incomming packets.


def send_packet(self, typename, packet):

typekey = typehash(typename)<EOL>if typename != self._type_register.get(typekey, None):<EOL><INDENT>raise ValueError("<STR_LIT>" % repr(typename))<EOL><DEDENT>hdr = self._header.pack(len(packet), typekey)<EOL>self.transport.writeSequence([hdr, packet])<EOL>

Send a packet.

:param typename: A previously registered typename.

:param packet: String with the content of the packet.


def on_unregistered_type(self, typekey, packet):

log.msg("<STR_LIT>" % (typekey, type(self).__name__))<EOL>self.transport.loseConnection()<EOL>

Invoked if a packet with an unregistered type was received.

Default behaviour is to log and close the connection.


public_child = self.hdkeychain<EOL>chain_step_bytes = <NUM_LIT:4><EOL>max_bits_per_step = <NUM_LIT:2>**<NUM_LIT><EOL>chain_steps = [<EOL>int(chain_path[i:i+chain_step_bytes*<NUM_LIT:2>], <NUM_LIT:16>) % max_bits_per_step<EOL>for i in range(<NUM_LIT:0>, len(chain_path), chain_step_bytes*<NUM_LIT:2>)<EOL>]<EOL>for step in chain_steps:<EOL><INDENT>public_child = public_child.get_child(step)<EOL><DEDENT>return PublicKeychain(public_child)<EOL>

A descendant is a child many steps down.


vbytes, depth, fingerprint, i, chaincode, key = rawtuple<EOL>i = encode(i, <NUM_LIT>, <NUM_LIT:4>)<EOL>chaincode = encode(hash_to_int(chaincode), <NUM_LIT>, <NUM_LIT:32>)<EOL>keydata = b'<STR_LIT:\x00>'  +key[:-<NUM_LIT:1>] if vbytes in PRIVATE else key<EOL>bindata = vbytes + from_int_to_byte(depth % <NUM_LIT>) + fingerprint + i + chaincode + keydata<EOL>return changebase(bindata + bin_dbl_sha256(bindata)[:<NUM_LIT:4>], <NUM_LIT>, <NUM_LIT>)<EOL>

Derived from code from pybitcointools (https://github.com/vbuterin/pybitcointools)
by Vitalik Buterin


dbin = changebase(data, <NUM_LIT>, <NUM_LIT>)<EOL>if bin_dbl_sha256(dbin[:-<NUM_LIT:4>])[:<NUM_LIT:4>] != dbin[-<NUM_LIT:4>:]:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>vbytes = dbin[<NUM_LIT:0>:<NUM_LIT:4>]<EOL>depth = from_byte_to_int(dbin[<NUM_LIT:4>])<EOL>fingerprint = dbin[<NUM_LIT:5>:<NUM_LIT:9>]<EOL>i = decode(dbin[<NUM_LIT:9>:<NUM_LIT>], <NUM_LIT>)<EOL>chaincode = dbin[<NUM_LIT>:<NUM_LIT>]<EOL>key = dbin[<NUM_LIT>:<NUM_LIT>]+b'<STR_LIT>' if vbytes in PRIVATE else dbin[<NUM_LIT>:<NUM_LIT>]<EOL>return (vbytes, depth, fingerprint, i, chaincode, key)<EOL>


@utils.command()<EOL>@click.option("<STR_LIT>", type=str, default="<STR_LIT:default>")<EOL>@click.pass_context<EOL>def highlight_info(ctx, style):

Outputs the CSS which can be customized for highlighted code


def _code_support(self, language, caller):

code = caller()<EOL>lines = code.splitlines()<EOL>first_nonempty_line_index = <NUM_LIT:0><EOL>while not lines[first_nonempty_line_index]:<EOL><INDENT>first_nonempty_line_index += <NUM_LIT:1><EOL><DEDENT>len_to_trim = len(lines[first_nonempty_line_index]) - len(<EOL>lines[first_nonempty_line_index].lstrip()<EOL>)<EOL>lines = [x[len_to_trim:] for x in lines]<EOL>code = "<STR_LIT:\n>".join(lines)<EOL>if language:<EOL><INDENT>lexer = get_lexer_by_name(language, stripall=True)<EOL><DEDENT>else:<EOL><INDENT>lexer = guess_lexer(code)<EOL><DEDENT>highlighted = highlight(code, lexer, HtmlFormatter())<EOL>return highlighted<EOL>


markdown_content = caller()<EOL>html_content = markdown.markdown(<EOL>markdown_content,<EOL>extensions=[<EOL>"<STR_LIT>",<EOL>CodeHiliteExtension(css_class="<STR_LIT>"),<EOL>"<STR_LIT>",<EOL>],<EOL>)<EOL>return html_content<EOL>


self.load()<EOL>

Reload the config and entire jinja environment


def watch_port_events(port, chip, pin_function_maps, event_queue,<EOL>return_after_kbdint=False):

<EOL>gpio25 = open(GPIO_INTERRUPT_DEVICE_VALUE, '<STR_LIT:r>')  <EOL>epoll = select.epoll()<EOL>epoll.register(gpio25, select.EPOLLIN | select.EPOLLET)<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>events = epoll.poll()<EOL><DEDENT>except KeyboardInterrupt as e:<EOL><INDENT>if return_after_kbdint:<EOL><INDENT>return<EOL><DEDENT>else:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT>except IOError as e:<EOL><INDENT>if e.errno != errno.EINTR:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>if port == pifacecommon.mcp23s17.GPIOA:<EOL><INDENT>interrupt_flag = chip.intfa.value<EOL><DEDENT>else:<EOL><INDENT>interrupt_flag = chip.intfb.value<EOL><DEDENT>if interrupt_flag == <NUM_LIT:0>:<EOL><INDENT>continue  <EOL><DEDENT>else:<EOL><INDENT>if port == pifacecommon.mcp23s17.GPIOA:<EOL><INDENT>interrupt_capture = chip.intcapa.value<EOL><DEDENT>else:<EOL><INDENT>interrupt_capture = chip.intcapb.value<EOL><DEDENT>event_queue.add_event(InterruptEvent(<EOL>interrupt_flag, interrupt_capture, chip, time.time()))<EOL><DEDENT><DEDENT>epoll.close()<EOL>

Waits for a port event. When a port event occurs it is placed onto the
    event queue.

    :param port: The port we are waiting for interrupts on (GPIOA/GPIOB).
    :type port: int
    :param chip: The chip we are waiting for interrupts on.
    :type chip: :class:`pifacecommon.mcp23s17.MCP23S17`
    :param pin_function_maps: A list of classes that have inheritted from
        :class:`FunctionMap`\ s describing what to do with events.
    :type pin_function_maps: list
    :param event_queue: A queue to put events on.
    :type event_queue: :py:class:`multiprocessing.Queue`


def handle_events(<EOL>function_maps, event_queue, event_matches_function_map,<EOL>terminate_signal):

while True:<EOL><INDENT>event = event_queue.get()<EOL>if event == terminate_signal:<EOL><INDENT>return<EOL><DEDENT>functions = map(<EOL>lambda fm: fm.callback<EOL>if event_matches_function_map(event, fm) else None,<EOL>function_maps)<EOL>functions = filter(lambda f: f is not None, functions)<EOL>for function in functions:<EOL><INDENT>function(event)<EOL><DEDENT><DEDENT>

Waits for events on the event queue and calls the registered functions.

    :param function_maps: A list of classes that have inheritted from
        :class:`FunctionMap`\ s describing what to do with events.
    :type function_maps: list
    :param event_queue: A queue to put events on.
    :type event_queue: :py:class:`multiprocessing.Queue`
    :param event_matches_function_map: A function that determines if the given
        event and :class:`FunctionMap` match.
    :type event_matches_function_map: function
    :param terminate_signal: The signal that, when placed on the event queue,
        causes this function to exit.


try:<EOL><INDENT>with open(GPIO_INTERRUPT_DEVICE_VALUE):<EOL><INDENT>return<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>with open(GPIO_EXPORT_FILE, '<STR_LIT:w>') as export_file:<EOL><INDENT>export_file.write(str(GPIO_INTERRUPT_PIN))<EOL><DEDENT>wait_until_file_exists(GPIO_INTERRUPT_DEVICE_VALUE)<EOL><DEDENT>

Bring the interrupt pin on the GPIO into Linux userspace.


with open(GPIO_UNEXPORT_FILE, '<STR_LIT:w>') as unexport_file:<EOL><INDENT>unexport_file.write(str(GPIO_INTERRUPT_PIN))<EOL><DEDENT>

Remove the GPIO interrupt pin from Linux userspace.


<EOL>start_time = time.time()<EOL>time_limit = start_time + FILE_IO_TIMEOUT<EOL>while time.time() < time_limit:<EOL><INDENT>try:<EOL><INDENT>with open(GPIO_INTERRUPT_DEVICE_EDGE, '<STR_LIT:w>') as gpio_edge:<EOL><INDENT>gpio_edge.write(edge)<EOL>return<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>

Set the interrupt edge on the userspace GPIO pin.

    :param edge: The interrupt edge ('none', 'falling', 'rising').
    :type edge: string


start_time = time.time()<EOL>time_limit = start_time + FILE_IO_TIMEOUT<EOL>while time.time() < time_limit:<EOL><INDENT>try:<EOL><INDENT>with open(filename):<EOL><INDENT>return<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>raise Timeout("<STR_LIT>" % filename)<EOL>

Wait until a file exists.

    :param filename: The name of the file to wait for.
    :type filename: string


<EOL>for pin_function_map in self.pin_function_maps:<EOL><INDENT>if _event_matches_pin_function_map(event, pin_function_map):<EOL><INDENT>pin_settle_time = pin_function_map.settle_time<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT>threshold_time = self.last_event_time[event.pin_num] + pin_settle_time<EOL>if event.timestamp > threshold_time:<EOL><INDENT>self.put(event)<EOL>self.last_event_time[event.pin_num] = event.timestamp<EOL><DEDENT>

Adds events to the queue. Will ignore events that occur before the
        settle time for that pin/direction. Such events are assumed to be
        bouncing.


def register(self, pin_num, direction, callback,<EOL>settle_time=DEFAULT_SETTLE_TIME):

self.pin_function_maps.append(<EOL>PinFunctionMap(pin_num, direction, callback, settle_time))<EOL>

Registers a pin number and direction to a callback function.

        :param pin_num: The pin pin number.
        :type pin_num: int
        :param direction: The event direction
            (use: IODIR_ON/IODIR_OFF/IODIR_BOTH)
        :type direction: int
        :param callback: The function to run when event is detected.
        :type callback: function
        :param settle_time: Time within which subsequent events are ignored.
        :type settle_time: int


def deregister(self, pin_num=None, direction=None):

to_delete = []<EOL>for i, function_map in enumerate(self.pin_function_maps):<EOL><INDENT>if ( pin_num == None<EOL>or ( function_map.pin_num == pin_num<EOL>and ( direction == None<EOL>or function_map.direction == direction ) ) ):<EOL><INDENT>to_delete.append(i)<EOL><DEDENT><DEDENT>for i in reversed(to_delete):<EOL><INDENT>del self.pin_function_maps[i]<EOL><DEDENT>

De-registers callback functions

        :param pin_num: The pin number. If None then all functions are de-registered
        :type pin_num: int
        :param direction: The event direction. If None then all functions for the
                          given pin are de-registered
        :type direction:int


self.detector.start()<EOL>self.dispatcher.start()<EOL>

When activated the :class:`PortEventListener` will run callbacks
        associated with pins/directions.


self.event_queue.put(self.TERMINATE_SIGNAL)<EOL>self.dispatcher.join()<EOL>self.detector.terminate()<EOL>self.detector.join()<EOL>

When deactivated the :class:`PortEventListener` will not run
        anything.


try:<EOL><INDENT>bring_gpio_interrupt_into_userspace()<EOL>set_gpio_interrupt_edge()<EOL><DEDENT>except Timeout as e:<EOL><INDENT>raise InterruptEnableException(<EOL>"<STR_LIT>" %<EOL>(GPIO_INTERRUPT_PIN, e.message)<EOL>)<EOL><DEDENT>


set_gpio_interrupt_edge('<STR_LIT:none>')<EOL>deactivate_gpio_interrupt()<EOL>


def __init__(self, bus=<NUM_LIT:0>, chip_select=<NUM_LIT:0>, spi_callback=None, speed_hz=<NUM_LIT>):

self.bus = bus<EOL>self.chip_select = chip_select<EOL>self.spi_callback = spi_callback<EOL>self.speed_hz = speed_hz<EOL>self.fd = None<EOL>spi_device = "<STR_LIT>" % (SPIDEV, self.bus, self.chip_select)<EOL>self.open_fd(spi_device)<EOL>

Initialises the SPI device file descriptor.

        :param bus: The SPI device bus number
        :type bus: int
        :param chip_select: The SPI device chip_select number
        :param chip_select: int
        :raises: InitError


<EOL>wbuffer = ctypes.create_string_buffer(bytes_to_send,<EOL>len(bytes_to_send))<EOL>rbuffer = ctypes.create_string_buffer(len(bytes_to_send))<EOL>transfer = spi_ioc_transfer(<EOL>tx_buf=ctypes.addressof(wbuffer),<EOL>rx_buf=ctypes.addressof(rbuffer),<EOL>len=ctypes.sizeof(wbuffer),<EOL>speed_hz=ctypes.c_uint32(self.speed_hz)<EOL>)<EOL>if self.spi_callback is not None:<EOL><INDENT>self.spi_callback(bytes_to_send)<EOL><DEDENT>ioctl(self.fd, SPI_IOC_MESSAGE(<NUM_LIT:1>), transfer)<EOL>return ctypes.string_at(rbuffer, ctypes.sizeof(rbuffer))<EOL>

Sends bytes via the SPI bus.

        :param bytes_to_send: The bytes to send on the SPI device.
        :type bytes_to_send: bytes
        :returns: bytes -- returned bytes from SPI device
        :raises: InitError


<EOL>board_addr_pattern = (self.hardware_addr << <NUM_LIT:1>) & <NUM_LIT><EOL>rw_cmd_pattern = read_write_cmd & <NUM_LIT:1>  <EOL>return <NUM_LIT> | board_addr_pattern | rw_cmd_pattern<EOL>

Returns an SPI control byte.

        The MCP23S17 is a slave SPI device. The slave address contains
        four fixed bits and three user-defined hardware address bits
        (if enabled via IOCON.HAEN) (pins A2, A1 and A0) with the
        read/write bit filling out the control byte::

            +--------------------+
            |0|1|0|0|A2|A1|A0|R/W|
            +--------------------+
             7 6 5 4 3  2  1   0

        :param read_write_cmd: Read or write command.
        :type read_write_cmd: int


return self._pyver_read(address)<EOL>

Returns the value of the address specified.

        :param address: The address to read from.
        :type address: int


self._pyver_write(data, address)<EOL>

Writes data to the address specified.

        :param data: The data to write.
        :type data: int
        :param address: The address to write to.
        :type address: int


value = self.read(address)<EOL>bit_mask = get_bit_mask(bit_num)<EOL>return <NUM_LIT:1> if value & bit_mask else <NUM_LIT:0><EOL>

Returns the bit specified from the address.

        :param bit_num: The bit number to read from.
        :type bit_num: int
        :param address: The address to read from.
        :type address: int
        :returns: int -- the bit value from the address


def write_bit(self, value, bit_num, address):

bit_mask = get_bit_mask(bit_num)<EOL>old_byte = self.read(address)<EOL>if value:<EOL><INDENT>new_byte = old_byte | bit_mask<EOL><DEDENT>else:<EOL><INDENT>new_byte = old_byte & ~bit_mask<EOL><DEDENT>self.write(new_byte, address)<EOL>

Writes the value given to the bit in the address specified.

        :param value: The value to write.
        :type value: int
        :param bit_num: The bit number to write to.
        :type bit_num: int
        :param address: The address to write to.
        :type address: int


self.read(INTCAPA if port == GPIOA else INTCAPB)<EOL>

Clears the interrupt flags by 'read'ing the capture register.


return <NUM_LIT:1> << (bit_num)<EOL>

Returns as bit mask with bit_num set.

    :param bit_num: The bit number.
    :type bit_num: int
    :returns: int -- the bit mask
    :raises: RangeError

    >>> bin(pifacecommon.core.get_bit_mask(0))
    1
    >>> pifacecommon.core.get_bit_mask(1)
    2
    >>> bin(pifacecommon.core.get_bit_mask(3))
    '0b1000'


if bit_pattern == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>bit_num = <NUM_LIT:0>  <EOL>while (bit_pattern & <NUM_LIT:1>) == <NUM_LIT:0>:<EOL><INDENT>bit_pattern = bit_pattern >> <NUM_LIT:1><EOL>bit_num += <NUM_LIT:1><EOL>if bit_num > <NUM_LIT:7>:<EOL><INDENT>bit_num = <NUM_LIT:0><EOL>break<EOL><DEDENT><DEDENT>return bit_num<EOL>

Returns the lowest bit num from a given bit pattern. Returns None if no
    bits set.

    :param bit_pattern: The bit pattern.
    :type bit_pattern: int
    :returns: int -- the bit number
    :returns: None -- no bits set

    >>> pifacecommon.core.get_bit_num(0)
    None
    >>> pifacecommon.core.get_bit_num(0b1)
    0
    >>> pifacecommon.core.get_bit_num(0b11000)
    3


<EOL>seconds = microseconds / float(<NUM_LIT>)<EOL>time.sleep(seconds)<EOL>

Sleeps for the given number of microseconds.

    :param microseconds: Number of microseconds to sleep for.
    :type microseconds: int


return self.fetch_json(<EOL>uri_path='<STR_LIT>' + self.id,<EOL>query_params=query_params or {}<EOL>)<EOL>

Get all information for this board. Returns a dictionary of values.


lists = self.get_lists_json(self.base_uri, query_params=query_params)<EOL>lists_list = []<EOL>for list_json in lists:<EOL><INDENT>lists_list.append(self.create_list(list_json))<EOL><DEDENT>return lists_list<EOL>

Get the lists attached to this board. Returns a list of List objects.

Returns:
    list(List): The lists attached to this board


labels = self.get_labels_json(self.base_uri, query_params=query_params)<EOL>labels_list = []<EOL>for label_json in labels:<EOL><INDENT>labels_list.append(self.create_label(label_json))<EOL><DEDENT>return labels_list<EOL>

Get the labels attached to this board. Returns a label of Label
objects.

Returns:
    list(Label): The labels attached to this board


cards = self.get_cards_json(self.base_uri, query_params=query_params)<EOL>cards_list = []<EOL>for card_json in cards:<EOL><INDENT>cards_list.append(self.create_card(card_json))<EOL><DEDENT>return cards_list<EOL>

Get the cards for this board. Returns a list of Card objects.

Returns:
    list(Card): The cards attached to this board


def get_card(self, card_id, **query_params):

card_json = self.fetch_json(<EOL>uri_path=self.base_uri + '<STR_LIT>' + card_id<EOL>)<EOL>return self.create_card(card_json)<EOL>

Get a Card for a given card id. Returns a Card object.

Returns:
    Card: The card with the given card_id


checklists = self.getChecklistsJson( self.base_uri )<EOL>checklists_list = []<EOL>for checklist_json in checklists:<EOL><INDENT>checklists_list.append( self.createChecklist( checklist_json ) )<EOL><DEDENT>return checklists_list<EOL>

Get the checklists for this board. Returns a list of Checklist objects.