def contains_components(self, address, components):

expected = len(components)<EOL>got = <NUM_LIT:0><EOL>parsed = parse_address(address)<EOL>self.assertTrue(parsed)<EOL>for s, c in parsed:<EOL><INDENT>if components.get(c, None) == s:<EOL><INDENT>got += <NUM_LIT:1><EOL><DEDENT><DEDENT>self.assertEqual(expected, got)<EOL>

Test whether address parse contains specific components.


def have_expansion_in_common(self, str1, str2, **kw):

expansions1 = expand_address(str1, **kw)<EOL>expansions2 = expand_address(str2, **kw)<EOL>self.assertTrue(set(expansions1) & set(expansions2))<EOL>

Test whether strings have at least one shared expansion.


def validate_fragment(self, fragment=None, fragment_dict=None):

fragment_dict = fragment_dict if fragment_dict else fragment.to_dict()<EOL>assert fragment_dict['<STR_LIT:content>'] == TEST_HTML<EOL>assert fragment_dict['<STR_LIT>'] == TEST_JS_INIT_FN<EOL>assert fragment_dict['<STR_LIT>'] == EXPECTED_JS_INIT_VERSION<EOL>assert fragment_dict['<STR_LIT>'] == TEST_JSON_INIT_ARGS<EOL>assert fragment_dict['<STR_LIT>'] == EXPECTED_RESOURCES<EOL>

Validates that the fields of a fragment are all correct.


@abstractmethod<EOL><INDENT>def render_to_fragment(self, request, **kwargs):  <DEDENT>

raise NotImplementedError()<EOL>


if resource.mimetype == "<STR_LIT>":<EOL><INDENT>if resource.kind == "<STR_LIT:text>":<EOL><INDENT>return u"<STR_LIT>" % resource.data<EOL><DEDENT>elif resource.kind == "<STR_LIT:url>":<EOL><INDENT>return u"<STR_LIT>" % resource.data<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>" % resource.kind)<EOL><DEDENT><DEDENT>elif resource.mimetype == "<STR_LIT>":<EOL><INDENT>if resource.kind == "<STR_LIT:text>":<EOL><INDENT>return u"<STR_LIT>" % resource.data<EOL><DEDENT>elif resource.kind == "<STR_LIT:url>":<EOL><INDENT>return u"<STR_LIT>" % resource.data<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>" % resource.kind)<EOL><DEDENT><DEDENT>elif resource.mimetype == "<STR_LIT>":<EOL><INDENT>assert resource.kind == "<STR_LIT:text>"<EOL>return resource.data<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>" % resource.mimetype)<EOL><DEDENT>

Returns `resource` wrapped in the appropriate html tag for it's mimetype.


assert isinstance(content, six.text_type)<EOL>self.content += content<EOL>

Add content to this fragment.

`content` is a Unicode string, HTML to append to the body of the
fragment.  It must not contain a ``<body>`` tag, or otherwise assume
that it is the only content on the page.


<EOL>return '<STR_LIT:\n>'.join(<EOL>self.resource_to_html(resource)<EOL>for resource in self.resources<EOL>if resource.placement == placement<EOL>)<EOL>

Get some resource HTML for this Fragment.

`placement` is "head" or "foot".

Returns a unicode string, the HTML for the head or foot of the page.


for fragment in fragments:<EOL><INDENT>self.add_fragment_resources(fragment)<EOL><DEDENT>

Add all the resources from `fragments` to my resources.

This is used to aggregate resources from a sequence of fragments that
should be considered part of the current fragment.

The content from the Fragments is ignored.  The caller must collect
together the content into this Fragment's content.


return {<EOL>'<STR_LIT:content>': self.content,<EOL>'<STR_LIT>': [r._asdict() for r in self.resources],  <EOL>'<STR_LIT>': self.js_init_fn,<EOL>'<STR_LIT>': self.js_init_version,<EOL>'<STR_LIT>': self.json_init_args<EOL>}<EOL>

Returns the fragment in a dictionary representation.


def WritingBloomFilter(num_elements, max_fp_prob, filename=None,<EOL>ignore_case=False, want_lock=False,<EOL>fdatasync_on_close=True):

new_filter = _hydra.BloomFilter.getFilter(<EOL>num_elements, max_fp_prob,<EOL>filename=filename, ignore_case=ignore_case,<EOL>read_only=False, want_lock=want_lock,<EOL>fdatasync_on_close=fdatasync_on_close)<EOL>if filename:<EOL><INDENT>with open('<STR_LIT>'.format(filename), '<STR_LIT:w>') as descriptor:<EOL><INDENT>descriptor.write("<STR_LIT>".format(num_elements))<EOL>descriptor.write("<STR_LIT>".format(max_fp_prob))<EOL>descriptor.write("<STR_LIT>".format(ignore_case))<EOL><DEDENT><DEDENT>return new_filter<EOL>

Create a read/write bloom filter with an upperbound of
(num_elements, max_fp_prob) as a specification and using filename
as the backing datastore.


def getlist(self, section, option, *, raw=False, vars=None,<EOL>fallback=None):

val = self.get(section, option, raw=raw, vars=vars, fallback=fallback)<EOL>values = []<EOL>if val:<EOL><INDENT>for line in val.split("<STR_LIT:\n>"):<EOL><INDENT>values += [s.strip() for s in line.split("<STR_LIT:U+002C>")]<EOL><DEDENT><DEDENT>return values<EOL>

Return the [section] option values as a list.
        The list items must be delimited with commas and/or newlines.


from shutil import copy2, Error, copystat<EOL>names = os.listdir(src)<EOL>if not Path(dst).exists():<EOL><INDENT>os.makedirs(dst)<EOL><DEDENT>errors = []<EOL>for name in names:<EOL><INDENT>srcname = os.path.join(src, name)<EOL>dstname = os.path.join(dst, name)<EOL>try:<EOL><INDENT>if symlinks and os.path.islink(srcname):<EOL><INDENT>linkto = os.readlink(srcname)<EOL>os.symlink(linkto, dstname)<EOL><DEDENT>elif os.path.isdir(srcname):<EOL><INDENT>copytree(srcname, dstname, symlinks)<EOL><DEDENT>else:<EOL><INDENT>copy2(srcname, dstname)<EOL><DEDENT><DEDENT>except OSError as why:<EOL><INDENT>errors.append((srcname, dstname, str(why)))<EOL><DEDENT>except Error as err:<EOL><INDENT>errors.extend(err.args[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>try:<EOL><INDENT>copystat(src, dst)<EOL><DEDENT>except OSError as why:<EOL><INDENT>if why.winerror is None:<EOL><INDENT>errors.extend((src, dst, str(why)))<EOL><DEDENT><DEDENT>if errors:<EOL><INDENT>raise Error(errors)<EOL><DEDENT>

Modified from shutil.copytree docs code sample, merges files rather than
requiring dst to not exist.


e, m, tb = sys.exc_info()<EOL>if tb is not None:<EOL><INDENT>_debugger.post_mortem(tb)<EOL><DEDENT>else:<EOL><INDENT>_debugger.set_trace()<EOL><DEDENT>

If called in the context of an exception, calls post_mortem; otherwise
    set_trace.
    ``ipdb`` is preferred over ``pdb`` if installed.


return {<EOL>"<STR_LIT:version>": <NUM_LIT:1>,<EOL>"<STR_LIT>": {"<STR_LIT>": {"<STR_LIT>": format},<EOL>"<STR_LIT>": {"<STR_LIT>": "<STR_LIT>"},<EOL>},<EOL>"<STR_LIT>": {"<STR_LIT>": {"<STR_LIT:class>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>},<EOL>},<EOL>"<STR_LIT:root>": {"<STR_LIT>": level,<EOL>"<STR_LIT>": ["<STR_LIT>"],<EOL>},<EOL>"<STR_LIT>": {},<EOL>}<EOL>

Returns a default logging config in dict format.

         Compatible with logging.config.dictConfig(), this default set the root
         logger to `level` with `sys.stdout` console handler using a formatter
         initialized with `format`. A simple 'brief' formatter is defined that
         shows only the message portion any log entries.


try:<EOL><INDENT>return load_pem_public_key(pubkey.encode(), default_backend())<EOL><DEDENT>except ValueError:<EOL><INDENT>pubkey = pubkey.replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT>')<EOL>return load_pem_public_key(pubkey.encode(), default_backend())<EOL><DEDENT>

Load public RSA key, with work-around for keys using
    incorrect header/footer format.

    Read more about RSA encryption with cryptography:
    https://cryptography.io/latest/hazmat/primitives/asymmetric/rsa/


return <NUM_LIT:5><EOL>

The fifth num in the fibonacci sequence.


return ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>

The Famous Five is the name of a series of children's
        adventure novels by English author Enid Blyton.


return '<STR_LIT>'<EOL>

A five on the flipside should be upside down.


<EOL>return self.item_description(item)<EOL>

This can be overridden to set turbo contents.

        :param item:

        :rtype: str|unicode


def configure_analytics_yandex(self, ident, params=None):

params = params or {}<EOL>data = {<EOL>'<STR_LIT:type>': '<STR_LIT>',<EOL>'<STR_LIT:id>': ident,<EOL>}<EOL>if params:<EOL><INDENT>data['<STR_LIT>'] = '<STR_LIT:%s>' % params<EOL><DEDENT>self.analytics.append(data)<EOL>

Configure Yandex Metrika analytics counter.

        :param str|unicode ident: Metrika counter ID.

        :param dict params: Additional params.


def configure_ad_yandex(self, ident, turbo_id='<STR_LIT>'):

self.ads.append({<EOL>'<STR_LIT:type>': '<STR_LIT>',<EOL>'<STR_LIT:id>': ident,<EOL>'<STR_LIT>': turbo_id,<EOL>})<EOL>

Configure Yandex Advertisement Network.

        :param str|unicode ident: Ad ID.

        :param str|unicode turbo_id: ID of a place (figure) on Turbo page where to put an Ad block.


contents = read_file(os.path.join('<STR_LIT>', '<STR_LIT>'))<EOL>version = re.search('<STR_LIT>', contents)<EOL>version = version.group(<NUM_LIT:1>).replace('<STR_LIT:U+002CU+0020>', '<STR_LIT:.>').strip()<EOL>return version<EOL>

Returns version number, without module import (which can lead to ImportError
    if some dependencies are unavailable before install.


raise NotImplementedError<EOL>

\
        Like everything else, a bunch of two-tuples containing a regex to match
        and a callback that takes arguments from the regex


def worker_ping_handler(self, nick, message, channel):

return '<STR_LIT>' % platform.node()<EOL>

\
        Respond to pings sent periodically by the BotnetBot


gevent.sleep(<NUM_LIT:10>) <EOL>while not self.registered.is_set():<EOL><INDENT>self.respond('<STR_LIT>' % platform.node(), nick=self.boss)<EOL>gevent.sleep(<NUM_LIT:30>)<EOL><DEDENT>

\
        Register the worker with the boss


self.finished.add(nick)<EOL>

\
        Indicate that the worker with the given nick has finished this task


return (<EOL>(self.nick_re, self.new_nick),<EOL>(self.nick_change_re, self.handle_nick_change),<EOL>(self.ping_re, self.handle_ping),<EOL>(self.part_re, self.handle_part),<EOL>(self.join_re, self.handle_join),<EOL>(self.quit_re, self.handle_quit),<EOL>(self.chanmsg_re, self.handle_channel_message),<EOL>(self.privmsg_re, self.handle_private_message),<EOL>(self.registered_re, self.handle_registered),<EOL>)<EOL>

\
        Low-level dispatching of socket data based on regex matching, in general
        handles

        * In event a nickname is taken, registers under a different one
        * Responds to periodic PING messages from server
        * Dispatches to registered callbacks when
            - any user leaves or enters a room currently connected to
            - a channel message is observed
            - a private message is received


if self._registered or force:<EOL><INDENT>self._sock_file.write('<STR_LIT>' % data)<EOL>self._sock_file.flush()<EOL><DEDENT>else:<EOL><INDENT>self._out_buffer.append(data)<EOL><DEDENT>

\
        Send raw data over the wire if connection is registered. Otherewise,
        save the data to an output buffer for transmission later on.
        If the force flag is true, always send data, regardless of
        registration status.


\
        Hook for registering custom callbacks for dispatch patterns


def respond(self, message, channel=None, nick=None):

self.conn.respond(message, channel, nick)<EOL>

\
        Wraps the connection object's respond() method


def run_bot(bot_class, host, port, nick, channels=None, ssl=None):

conn = IRCConnection(host, port, nick, ssl)<EOL>bot_instance = bot_class(conn)<EOL>while <NUM_LIT:1>:<EOL><INDENT>if not conn.connect():<EOL><INDENT>break<EOL><DEDENT>channels = channels or []<EOL>for channel in channels:<EOL><INDENT>conn.join(channel)<EOL><DEDENT>conn.enter_event_loop()<EOL><DEDENT>

\
    Convenience function to start a bot on the given network, optionally joining
    some channels


patterns = self.dispatch_patterns()<EOL>self.logger.debug('<STR_LIT>')<EOL>while <NUM_LIT:1>:<EOL><INDENT>try:<EOL><INDENT>data = self._sock_file.readline()<EOL><DEDENT>except socket.error:<EOL><INDENT>data = None<EOL><DEDENT>if not data:<EOL><INDENT>self.logger.info('<STR_LIT>')<EOL>self.close()<EOL>return True<EOL><DEDENT>data = data.rstrip()<EOL>for pattern, callback in patterns:<EOL><INDENT>match = pattern.match(data)<EOL>if match:<EOL><INDENT>callback(**match.groupdict())<EOL><DEDENT><DEDENT><DEDENT>

\
        Main loop of the IRCConnection - reads from the socket and dispatches
        based on regex matching


self.conn.register_callbacks((<EOL>(re.compile(pattern), callback)for pattern, callback in self.command_patterns()<EOL>))<EOL>

\
        Hook for registering callbacks with connection -- handled by __init__()


if HAS_ASTROPY:<EOL><INDENT>from astropy.units import UnitBase<EOL>if isinstance(target_unit, UnitBase):<EOL><INDENT>return ASTROPY<EOL><DEDENT><DEDENT>if HAS_PINT:<EOL><INDENT>from pint.unit import UnitsContainer<EOL>if hasattr(target_unit, '<STR_LIT>') and isinstance(target_unit.dimensionality, UnitsContainer):<EOL><INDENT>return PINT<EOL><DEDENT><DEDENT>if HAS_QUANTITIES:<EOL><INDENT>from quantities.unitquantity import IrreducibleUnit<EOL>from quantities import Quantity<EOL>if isinstance(target_unit, IrreducibleUnit) or isinstance(target_unit, Quantity):<EOL><INDENT>return QUANTITIES<EOL><DEDENT><DEDENT>raise TraitError("<STR_LIT>".format(type(target_unit).__name__))<EOL>

Identify whether the user is requesting unit validation against
astropy.units, pint, or quantities.


app = get_app()<EOL>snapshot = app.get_snapshot(old_name)<EOL>if not snapshot:<EOL><INDENT>click.echo("<STR_LIT>" % old_name)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>new_snapshot = app.get_snapshot(new_name)<EOL>if new_snapshot:<EOL><INDENT>click.echo("<STR_LIT>" % new_name)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>app.rename_snapshot(snapshot, new_name)<EOL>click.echo("<STR_LIT>" % (old_name, new_name))<EOL>


click.echo("<STR_LIT>" % __version__)<EOL>


index_sql = super(PostgresDbWriter, self).write_indexes(table)<EOL>for sql in index_sql:<EOL><INDENT>self.execute(sql)<EOL><DEDENT>

Send DDL to create the specified `table` indexes

        :Parameters:
          - `table`: an instance of a :py:class:`mysql2pgsql.lib.mysql_reader.MysqlReader.Table` object that represents the table to read/write.

        Returns None


self.conn.close()<EOL>

Closes connection to the PostgreSQL server


table_sql, serial_key_sql = super(PostgresDbWriter, self).write_table(table)<EOL>for sql in serial_key_sql + table_sql:<EOL><INDENT>self.execute(sql)<EOL><DEDENT>

Send DDL to create the specified `table`

        :Parameters:
          - `table`: an instance of a :py:class:`mysql2pgsql.lib.mysql_reader.MysqlReader.Table` object that represents the table to read/write.

        Returns None


def get_search_results(self, request, queryset, search_term):

search_term = search_term.replace('<STR_LIT:->', '<STR_LIT>')<EOL>return super().get_search_results(request, queryset, search_term)<EOL>


def parse_notification_xml(xml: str) -> Union[AliasRegistration, Payment]:

body = fromstring(xml).find('<STR_LIT:body>')<EOL>transaction = body.find('<STR_LIT>')<EOL>_user_parameters = transaction.find('<STR_LIT>')<EOL>def get_named_parameter(name):<EOL><INDENT>return _user_parameters.find("<STR_LIT>" + name + "<STR_LIT>")<EOL><DEDENT>def success():<EOL><INDENT>return transaction.get('<STR_LIT:status>') == '<STR_LIT:success>'<EOL><DEDENT>def parse_success():<EOL><INDENT>computed_signature = sign_web(body.get('<STR_LIT>'), transaction.find('<STR_LIT>').text,<EOL>transaction.find('<STR_LIT>').text,<EOL>transaction.find('<STR_LIT>').text)<EOL>sign2 = get_named_parameter('<STR_LIT>').text<EOL>if computed_signature != sign2:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>success = transaction.find('<STR_LIT:success>')<EOL>d = dict(<EOL>response_code=success.find('<STR_LIT>').text,<EOL>response_message=success.find('<STR_LIT>').text,<EOL>authorization_code=success.find('<STR_LIT>').text,<EOL>acquirer_authorization_code=success.find('<STR_LIT>').text,<EOL>)<EOL>return {k: v for k, v in d.items() if v is not None}<EOL><DEDENT>def parse_error():<EOL><INDENT>error = transaction.find('<STR_LIT:error>')<EOL>d = dict(<EOL>error_code=error.find('<STR_LIT>').text,<EOL>error_message=error.find('<STR_LIT>').text,<EOL>error_detail=error.find('<STR_LIT>').text)<EOL>acquirer_error_code = get_named_parameter('<STR_LIT>')<EOL>if acquirer_error_code is not None:<EOL><INDENT>d['<STR_LIT>'] = acquirer_error_code.text<EOL><DEDENT>return {k: v for k, v in d.items() if v is not None}<EOL><DEDENT>def parse_common_attributes():<EOL><INDENT>d = dict(<EOL>transaction_id=transaction.find('<STR_LIT>').text,<EOL>merchant_id=body.get('<STR_LIT>'),<EOL>client_ref=transaction.get('<STR_LIT>'),<EOL>amount=parse_money(transaction))<EOL>payment_method = transaction.find('<STR_LIT>')<EOL>if payment_method is not None:<EOL><INDENT>d['<STR_LIT>'] = payment_method.text<EOL><DEDENT>request_type = transaction.find('<STR_LIT>')<EOL>if request_type is not None:<EOL><INDENT>d['<STR_LIT>'] = request_type.text<EOL><DEDENT>credit_card_country = get_named_parameter('<STR_LIT>')<EOL>if credit_card_country is not None:<EOL><INDENT>d['<STR_LIT>'] = credit_card_country.text<EOL><DEDENT>expiry_month = get_named_parameter('<STR_LIT>')<EOL>if expiry_month is not None:<EOL><INDENT>d['<STR_LIT>'] = int(expiry_month.text)<EOL><DEDENT>expiry_year = get_named_parameter('<STR_LIT>')<EOL>if expiry_year is not None:<EOL><INDENT>d['<STR_LIT>'] = int(expiry_year.text)<EOL><DEDENT>return d<EOL><DEDENT>use_alias_parameter = get_named_parameter('<STR_LIT>')<EOL>if use_alias_parameter is not None and use_alias_parameter.text == '<STR_LIT:true>':<EOL><INDENT>d = dict(parse_common_attributes())<EOL>masked_card_number = get_named_parameter('<STR_LIT>')<EOL>if masked_card_number is not None:<EOL><INDENT>d['<STR_LIT>'] = masked_card_number.text<EOL><DEDENT>card_alias = get_named_parameter('<STR_LIT>')<EOL>if card_alias is not None:<EOL><INDENT>d['<STR_LIT>'] = card_alias.text<EOL><DEDENT>if success():<EOL><INDENT>d['<STR_LIT:success>'] = True<EOL>d.update(parse_success())<EOL><DEDENT>else:<EOL><INDENT>d['<STR_LIT:success>'] = False<EOL>d.update(parse_error())<EOL><DEDENT>return AliasRegistration(**d)<EOL><DEDENT>else:<EOL><INDENT>if success():<EOL><INDENT>d = dict(success=True)<EOL>cardno = get_named_parameter('<STR_LIT>')<EOL>if cardno is not None:<EOL><INDENT>d['<STR_LIT>'] = cardno.text<EOL><DEDENT>d.update(parse_common_attributes())<EOL>d.update(parse_success())<EOL>return Payment(**d)<EOL><DEDENT>else:<EOL><INDENT>d = dict(success=False)<EOL>d.update(parse_common_attributes())<EOL>d.update(parse_error())<EOL>return Payment(**d)<EOL><DEDENT><DEDENT>

Both alias registration and payments are received here.
We can differentiate them by looking at the use-alias user-parameter (and verifying the amount is o).


output = self.render(options)<EOL>if hasattr(output, '<STR_LIT>'):<EOL><INDENT>output.save(fp, format=self.writer.format)<EOL><DEDENT>else:<EOL><INDENT>fp.write(output)<EOL><DEDENT>

Renders the barcode and writes it to the file like object
        `fp`.

        :parameters:
            fp : File like object
                Object to write the raw data in.
            options : Dict
                The same as in `self.render`.


for key, val in options.items():<EOL><INDENT>key = key.lstrip('<STR_LIT:_>')<EOL>if hasattr(self, key):<EOL><INDENT>setattr(self, key, val)<EOL><DEDENT><DEDENT>

Sets the given options as instance attributes (only
        if they are known).

        :parameters:
            options : Dict
                All known instance attributes and more if the childclass
                has defined them before this call.

        :rtype: None


code = self.build()<EOL>for i, line in enumerate(code):<EOL><INDENT>code[i] = line.replace('<STR_LIT:1>', '<STR_LIT:|>').replace('<STR_LIT:0>', '<STR_LIT:U+0020>')<EOL><DEDENT>return '<STR_LIT:\n>'.join(code)<EOL>

Returns an ascii representation of the barcode.

        :rtype: String


Abort the authentication. The result is either the failure tuple
(``(SASLState.FAILURE, None)``) or a :class:`SASLFailure` exception if
the response from the peer did not indicate abortion (e.g. another
error was returned by the peer or the peer indicated success).


@abc.abstractmethod<EOL><INDENT>@asyncio.coroutine<EOL>def initiate(self, mechanism, payload=None):<DEDENT>

Send a SASL initiation request for the given `mechanism`. Depending on
the `mechanism`, an initial `payload` *may* be given. The `payload` is
then a :class:`bytes` object which needs to be passed as initial
payload during the initiation request.

Wait for a reply by the peer and return the reply as a next-state tuple
in the format documented at :class:`SASLInterface`.


@asyncio.coroutine<EOL><INDENT>@abc.abstractmethod<EOL>def authenticate(self, sm, token):<DEDENT>

Execute the mechanism identified by `token` (the non-:data:`None` value
which has been returned by :meth:`any_supported` before) using the
given :class:`SASLStateMachine` `sm`.

If authentication fails, an appropriate exception is raised
(:class:`AuthenticationFailure`). If the authentication fails for a
reason unrelated to credentials, :class:`SASLFailure` is raised.


<EOL>if not chars:<EOL><INDENT>return<EOL><DEDENT>has_RandALCat = any(is_RandALCat(c) for c in chars)<EOL>if not has_RandALCat:<EOL><INDENT>return<EOL><DEDENT>has_LCat = any(is_LCat(c) for c in chars)<EOL>if has_LCat:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if not is_RandALCat(chars[<NUM_LIT:0>]) or not is_RandALCat(chars[-<NUM_LIT:1>]):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>

Check proper bidirectionality as per stringprep. Operates on a list of
unicode characters provided in `chars`.


Process the given `string` using the SASLprep profile. In the error cases
defined in `RFC 3454`_ (stringprep), a :class:`ValueError` is raised.


violator = check_against_tables(chars, bad_tables)<EOL>if violator is not None:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>".format(ord(violator)))<EOL><DEDENT>

Check against prohibited output, by checking whether any of the characters
from `chars` are in any of the `bad_tables`.

Operates in-place on a list of code points from `chars`.


Implement the ``trace`` profile specified in :rfc:`4505`.


for c in chars:<EOL><INDENT>if any(in_table(c) for in_table in tables):<EOL><INDENT>return c<EOL><DEDENT><DEDENT>return None<EOL>

Perform a check against the table predicates in `tables`. `tables` must be
a reusable iterable containing characteristic functions of character sets,
that is, functions which return :data:`True` if the character is in the
table.

The function returns the first character occuring in any of the tables or
:data:`None` if no character matches.


i = <NUM_LIT:0><EOL>while i < len(chars):<EOL><INDENT>c = chars[i]<EOL>if stringprep.in_table_c12(c):<EOL><INDENT>chars[i] = "<STR_LIT>"<EOL><DEDENT>elif stringprep.in_table_b1(c):<EOL><INDENT>del chars[i]<EOL>continue<EOL><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>

Perform the stringprep mapping step of SASLprep. Operates in-place on a
list of unicode characters provided in `chars`.


bad_tables = (<EOL>stringprep.in_table_a1,)<EOL>violator = check_against_tables(chars, bad_tables)<EOL>if violator is not None:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>".format(ord(violator)))<EOL><DEDENT>

Check that `chars` does not contain any unassigned code points as per
the given list of `bad_tables`.

Operates on a list of unicode code points provided in `chars`.


def __init__(self, geometry_string, options={}, *args, **kwargs):

<EOL>self.geometry_string = geometry_string<EOL>self.options = options<EOL>super(HyperlinkedSorlImageField, self).__init__(*args, **kwargs)<EOL>

Create an instance of the HyperlinkedSorlImageField image serializer.

Args:
    geometry_string (str): The size of your cropped image.
    options (Optional[dict]): A dict of sorl options.
    *args: (Optional) Default serializers.ImageField arguments.
    **kwargs: (Optional) Default serializers.ImageField keyword
    arguments.

For a description of sorl geometry strings and additional sorl options,
please see https://sorl-thumbnail.readthedocs.org/en/latest/examples.html?highlight=geometry#low-level-api-examples


return isinstance(node, Name) and node.id in self.current_except_names<EOL>

Checks if the node is a bare exception name from an except block.


if version_info >= (<NUM_LIT:3>, <NUM_LIT:6>):<EOL><INDENT>if self.within_logging_statement():<EOL><INDENT>if any(isinstance(i, FormattedValue) for i in node.values):<EOL><INDENT>if self.within_logging_argument():<EOL><INDENT>self.violations.append((node, FSTRING_VIOLATION))<EOL>super(LoggingVisitor, self).generic_visit(node)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>


if self.should_check_whitelist(node):<EOL><INDENT>if node.arg not in self.whitelist and not node.arg.startswith("<STR_LIT>"):<EOL><INDENT>self.violations.append((self.current_logging_call, WHITELIST_VIOLATION.format(node.arg)))<EOL><DEDENT><DEDENT>if self.should_check_extra_exception(node):<EOL><INDENT>self.check_exception_arg(node.value)<EOL><DEDENT>super(LoggingVisitor, self).generic_visit(node)<EOL>


if self.should_check_whitelist(node):<EOL><INDENT>for key in node.keys:<EOL><INDENT>if key.s in self.whitelist or key.s.startswith("<STR_LIT>"):<EOL><INDENT>continue<EOL><DEDENT>self.violations.append((self.current_logging_call, WHITELIST_VIOLATION.format(key.s)))<EOL><DEDENT><DEDENT>if self.should_check_extra_exception(node):<EOL><INDENT>for value in node.values:<EOL><INDENT>self.check_exception_arg(value)<EOL><DEDENT><DEDENT>super(LoggingVisitor, self).generic_visit(node)<EOL>


if self.current_logging_level not in ('<STR_LIT:error>', '<STR_LIT>'):<EOL><INDENT>return<EOL><DEDENT>for kw in node.keywords:<EOL><INDENT>if kw.arg == '<STR_LIT>':<EOL><INDENT>if self.current_logging_level == '<STR_LIT:error>':<EOL><INDENT>violation = ERROR_EXC_INFO_VIOLATION<EOL><DEDENT>else:<EOL><INDENT>violation = REDUNDANT_EXC_INFO_VIOLATION<EOL><DEDENT>self.violations.append((node, violation))<EOL><DEDENT><DEDENT>

Reports a violation if exc_info keyword is used with logging.error or logging.exception.


<EOL>if self.within_logging_statement():<EOL><INDENT>if self.within_logging_argument() and self.is_format_call(node):<EOL><INDENT>self.violations.append((node, STRING_FORMAT_VIOLATION))<EOL>super(LoggingVisitor, self).generic_visit(node)<EOL>return<EOL><DEDENT><DEDENT>logging_level = self.detect_logging_level(node)<EOL>if logging_level and self.current_logging_level is None:<EOL><INDENT>self.current_logging_level = logging_level<EOL><DEDENT>if logging_level is None:<EOL><INDENT>super(LoggingVisitor, self).generic_visit(node)<EOL>return<EOL><DEDENT>self.current_logging_call = node<EOL>if logging_level == "<STR_LIT>":<EOL><INDENT>self.violations.append((node, WARN_VIOLATION))<EOL><DEDENT>self.check_exc_info(node)<EOL>for index, child in enumerate(iter_child_nodes(node)):<EOL><INDENT>if index == <NUM_LIT:1>:<EOL><INDENT>self.current_logging_argument = child<EOL><DEDENT>if index >= <NUM_LIT:1>:<EOL><INDENT>self.check_exception_arg(child)<EOL><DEDENT>if index > <NUM_LIT:1> and isinstance(child, keyword) and child.arg == "<STR_LIT>":<EOL><INDENT>self.current_extra_keyword = child<EOL><DEDENT>super(LoggingVisitor, self).visit(child)<EOL>self.current_logging_argument = None<EOL>self.current_extra_keyword = None<EOL><DEDENT>self.current_logging_call = None<EOL>self.current_logging_level = None<EOL>

Visit a function call.

We expect every logging statement and string format to be a function call.


return (<EOL>isinstance(node, Call)<EOL>and isinstance(node.func, Name)<EOL>and node.func.id in ('<STR_LIT:str>', '<STR_LIT>')<EOL>and node.args<EOL>and self.is_bare_exception(node.args[<NUM_LIT:0>])<EOL>)<EOL>

Checks if the node is the expression str(e) or unicode(e), where e is an exception name from an except block


try:<EOL><INDENT>if self.get_id_attr(node.func.value) == "<STR_LIT>":<EOL><INDENT>return None<EOL><DEDENT>if node.func.attr in LOGGING_LEVELS:<EOL><INDENT>return node.func.attr<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>return None<EOL>

Heuristic to decide whether an AST Call is a logging call.


def getplan(self, size="<STR_LIT>", axes=None, padding=None):

from numpy import dtype as gettype<EOL>plan = self.vshape<EOL>if axes is None:<EOL><INDENT>if isinstance(size, str):<EOL><INDENT>axes = arange(len(self.vshape))<EOL><DEDENT>else:<EOL><INDENT>axes = arange(len(size))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>axes = asarray(axes, '<STR_LIT:int>')<EOL><DEDENT>pad = array(len(self.vshape)*[<NUM_LIT:0>, ])<EOL>if padding is not None:<EOL><INDENT>pad[axes] = padding<EOL><DEDENT>if isinstance(size, tuple):<EOL><INDENT>plan[axes] = size<EOL><DEDENT>elif isinstance(size, str):<EOL><INDENT>size = <NUM_LIT> * float(size)<EOL>elsize = gettype(self.dtype).itemsize<EOL>nelements = prod(self.vshape)<EOL>dims = self.vshape[self.vmask(axes)]<EOL>if size <= elsize:<EOL><INDENT>s = ones(len(axes))<EOL><DEDENT>else:<EOL><INDENT>remsize = <NUM_LIT:1.0> * nelements * elsize<EOL>s = []<EOL>for (i, d) in enumerate(dims):<EOL><INDENT>minsize = remsize/d<EOL>if minsize >= size:<EOL><INDENT>s.append(<NUM_LIT:1>)<EOL>remsize = minsize<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>s.append(min(d, floor(size/minsize)))<EOL>s[i+<NUM_LIT:1>:] = plan[i+<NUM_LIT:1>:]<EOL>break<EOL><DEDENT><DEDENT><DEDENT>plan[axes] = s<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return plan, pad<EOL>

Identify a plan for chunking values along each dimension.

Generates an ndarray with the size (in number of elements) of chunks
in each dimension. If provided, will estimate chunks for only a
subset of axes, leaving all others to the full size of the axis.

Parameters
----------
size : string or tuple
     If str, the average size (in KB) of the chunks in all value dimensions.
     If int/tuple, an explicit specification of the number chunks in
     each moving value dimension.

axes : tuple, optional, default=None
      One or more axes to estimate chunks for, if provided any
      other axes will use one chunk.

padding : tuple or int, option, default=None
    Size over overlapping padding between chunks in each dimension.
    If tuple, specifies padding along each chunked dimension; if int,
    all dimensions use same padding; if None, no padding


def process_record(val):<EOL><INDENT>newval = empty(<NUM_LIT:1>, dtype="<STR_LIT:object>")<EOL>newval[<NUM_LIT:0>]  = func(val)<EOL>return newval<EOL><DEDENT>rdd = self._rdd.mapValues(process_record)<EOL>nchunks = self.getnumber(self.plan, self.vshape)<EOL>newshape = tuple([int(s) for s in r_[self.kshape, nchunks]])<EOL>newsplit = len(self.shape)<EOL>return BoltArraySpark(rdd, shape=newshape, split=newsplit, ordered=self._ordered, dtype="<STR_LIT:object>")<EOL>

Apply a generic array -> object to each subarray

The resulting object is a BoltArraySpark of dtype object where the
blocked dimensions are replaced with indices indication block ID.


@staticmethod<EOL><INDENT>def ones(shape, context=None, axis=(<NUM_LIT:0>,), dtype=float64, npartitions=None):<DEDENT>

from numpy import ones<EOL>return ConstructSpark._wrap(ones, shape, context, axis, dtype, npartitions)<EOL>

Create a spark bolt array of ones.

Parameters
----------
shape : tuple
    The desired shape of the array.

context : SparkContext
    A context running Spark. (see pyspark)

axis : tuple, optional, default=(0,)
    Which axes to distribute the array along. The resulting
    distributed object will use keys to represent these axes,
    with the remaining axes represented by values.

dtype : data-type, optional, default=float64
    The desired data-type for the array. If None, will
    be determined from the data. (see numpy)

npartitions : int
    Number of partitions for parallization.

Returns
-------
BoltArraySpark


new = tupleize(shape)<EOL>old_key_size = prod(self.keys.shape)<EOL>old_value_size = prod(self.values.shape)<EOL>for i in range(len(new)):<EOL><INDENT>new_key_size = prod(new[:i])<EOL>new_value_size = prod(new[i:])<EOL>if new_key_size == old_key_size and new_value_size == old_value_size:<EOL><INDENT>return i<EOL><DEDENT><DEDENT>return -<NUM_LIT:1><EOL>

Check if the requested reshape can be broken into independant reshapes
on the keys and values. If it can, returns the index in the new shape
separating keys from values, otherwise returns -1


def chunk(self, size="<STR_LIT>", axis=None, padding=None):

if type(size) is not str:<EOL><INDENT>size = tupleize((size))<EOL><DEDENT>axis = tupleize((axis))<EOL>padding = tupleize((padding))<EOL>from bolt.spark.chunk import ChunkedArray<EOL>chnk = ChunkedArray(rdd=self._rdd, shape=self._shape, split=self._split, dtype=self._dtype)<EOL>return chnk._chunk(size, axis, padding)<EOL>

Chunks records of a distributed array.

Chunking breaks arrays into subarrays, using an specified
size of chunks along each value dimension. Can alternatively
specify an average chunk byte size (in kilobytes) and the size of
chunks (as ints) will be computed automatically.

Parameters
----------
size : tuple, int, or str, optional, default = "150"
    A string giving the size in kilobytes, or a tuple with the size
    of chunks along each dimension.

axis : int or tuple, optional, default = None
    One or more axis to chunk array along, if None
    will use all axes,

padding: tuple or int, default = None
    Number of elements per dimension that will overlap with the adjacent chunk.
    If a tuple, specifies padding along each chunked dimension; if a int, same
    padding will be applied to all chunked dimensions.

Returns
-------
ChunkedArray


def max(self, axis=None, keepdims=False):

from numpy import maximum<EOL>return self._stat(axis, func=maximum, keepdims=keepdims)<EOL>

Return the maximum of the array over the given axis.

Parameters
----------
axis : tuple or int, optional, default=None
    Axis to compute statistic over, if None
    will compute over all axes

keepdims : boolean, optional, default=False
    Keep axis remaining after operation with size 1.


def std(self, axis=None, keepdims=False):

return self._stat(axis, name='<STR_LIT>', keepdims=keepdims)<EOL>

Return the standard deviation of the array over the given axis.

Parameters
----------
axis : tuple or int, optional, default=None
    Axis to compute statistic over, if None
    will compute over all axes

keepdims : boolean, optional, default=False
    Keep axis remaining after operation with size 1.


if len(axes) == <NUM_LIT:0>:<EOL><INDENT>p = arange(self.ndim-<NUM_LIT:1>, -<NUM_LIT:1>, -<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>p = asarray(argpack(axes))<EOL><DEDENT>istransposeable(p, range(self.ndim))<EOL>split = self.split<EOL>new_keys, new_values = p[:split], p[split:]<EOL>swapping_keys = sort(new_values[new_values < split])<EOL>swapping_values = sort(new_keys[new_keys >= split])<EOL>stationary_keys = sort(new_keys[new_keys < split])<EOL>stationary_values = sort(new_values[new_values >= split])<EOL>p_swap = r_[stationary_keys, swapping_values, swapping_keys, stationary_values]<EOL>p_swap_inv = argsort(p_swap)<EOL>p_x = p_swap_inv[p]<EOL>p_keys, p_values = p_x[:split], p_x[split:]-split<EOL>arr = self.swap(swapping_keys, swapping_values-split)<EOL>arr = arr.keys.transpose(tuple(p_keys.tolist()))<EOL>arr = arr.values.transpose(tuple(p_values.tolist()))<EOL>return arr<EOL>

Return an array with the axes transposed.

This operation will incur a swap unless the
desiured permutation can be obtained
only by transpoing the keys or the values.

Parameters
----------
axes : None, tuple of ints, or n ints
    If None, will reverse axis order.


key_slices = index[<NUM_LIT:0>:self.split]<EOL>value_slices = index[self.split:]<EOL>def key_check(key):<EOL><INDENT>def inrange(k, s):<EOL><INDENT>if s.step > <NUM_LIT:0>:<EOL><INDENT>return s.start <= k < s.stop<EOL><DEDENT>else:<EOL><INDENT>return s.stop < k <= s.start<EOL><DEDENT><DEDENT>def check(k, s):<EOL><INDENT>return inrange(k, s) and mod(k - s.start, s.step) == <NUM_LIT:0><EOL><DEDENT>out = [check(k, s) for k, s in zip(key, key_slices)]<EOL>return all(out)<EOL><DEDENT>def key_func(key):<EOL><INDENT>return tuple([(k - s.start)/s.step for k, s in zip(key, key_slices)])<EOL><DEDENT>filtered = self._rdd.filter(lambda kv: key_check(kv[<NUM_LIT:0>]))<EOL>if self._split == self.ndim:<EOL><INDENT>rdd = filtered.map(lambda kv: (key_func(kv[<NUM_LIT:0>]), kv[<NUM_LIT:1>]))<EOL><DEDENT>else:<EOL><INDENT>value_slices = [s if s.stop != -<NUM_LIT:1> else slice(s.start, None, s.step) for s in value_slices]<EOL>rdd = filtered.map(lambda kv: (key_func(kv[<NUM_LIT:0>]), kv[<NUM_LIT:1>][value_slices]))<EOL><DEDENT>shape = tuple([int(ceil((s.stop - s.start) / float(s.step))) for s in index])<EOL>split = self.split<EOL>return rdd, shape, split<EOL>


if not any([d == <NUM_LIT:1> for d in self.shape]):<EOL><INDENT>return self<EOL><DEDENT>if axis is None:<EOL><INDENT>drop = where(asarray(self.shape) == <NUM_LIT:1>)[<NUM_LIT:0>]<EOL><DEDENT>elif isinstance(axis, int):<EOL><INDENT>drop = asarray((axis,))<EOL><DEDENT>elif isinstance(axis, tuple):<EOL><INDENT>drop = asarray(axis)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if any([self.shape[i] > <NUM_LIT:1> for i in drop]):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if any(asarray(drop) < self.split):<EOL><INDENT>kmask = set([d for d in drop if d < self.split])<EOL>kfunc = lambda k: tuple([kk for ii, kk in enumerate(k) if ii not in kmask])<EOL><DEDENT>else:<EOL><INDENT>kfunc = lambda k: k<EOL><DEDENT>if any(asarray(drop) >= self.split):<EOL><INDENT>vmask = tuple([d - self.split for d in drop if d >= self.split])<EOL>vfunc = lambda v: v.squeeze(vmask)<EOL><DEDENT>else:<EOL><INDENT>vfunc = lambda v: v<EOL><DEDENT>rdd = self._rdd.map(lambda kv: (kfunc(kv[<NUM_LIT:0>]), vfunc(kv[<NUM_LIT:1>])))<EOL>shape = tuple([ss for ii, ss in enumerate(self.shape) if ii not in drop])<EOL>split = len([d for d in range(self.keys.ndim) if d not in drop])<EOL>return self._constructor(rdd, shape=shape, split=split).__finalize__(self)<EOL>

Remove one or more single-dimensional axes from the array.

Parameters
----------
axis : tuple or int
    One or more singleton axes to remove.


return self._rdd<EOL>

Return the underlying RDD of the bolt array.


<EOL>inshape(self.shape, axis)<EOL>tokeys = [(a - self.split) for a in axis if a >= self.split]<EOL>tovalues = [a for a in range(self.split) if a not in axis]<EOL>if tokeys or tovalues:<EOL><INDENT>return self.swap(tovalues, tokeys)<EOL><DEDENT>else:<EOL><INDENT>return self<EOL><DEDENT>

Align spark bolt array so that axes for iteration are in the keys.

This operation is applied before most functional operators.
It ensures that the specified axes are valid, and swaps
key/value axes so that functional operators can be applied
over the correct records.

Parameters
----------
axis: tuple[int]
    One or more axes that wil be iterated over by a functional operator

Returns
-------
BoltArraySpark


return self._split<EOL>

Axis at which the array is split into keys/values.


raise NotImplementedError<EOL>

Return an array with two axes interchanged.


raise NotImplementedError<EOL>


raise NotImplementedError<EOL>

Return the minimum of the array elements over the given axis or axes.


raise NotImplementedError<EOL>

Return the maximum of the array elements over the given axis or axes.


raise NotImplementedError<EOL>

Transpose by reversing the order of the axes.


if not isinstance(arrays, tuple):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>arrays = tuple([asarray(a) for a in arrays])<EOL>from numpy import concatenate<EOL>return BoltArrayLocal(concatenate(arrays, axis))<EOL>

Join a sequence of arrays together.

Parameters
----------
arrays : tuple
    A sequence of array-like e.g. (a1, a2, ...)

axis : int, optional, default=0
    The axis along which the arrays will be joined.

Returns
-------
BoltArrayLocal


if self.shape == ():<EOL><INDENT>return self.toarray().reshape(<NUM_LIT:1>)[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return self<EOL><DEDENT>

Returns the single scalar element contained in an array of shape (), if
the array has that shape. Returns self otherwise.


def map(self, func, axis=(<NUM_LIT:0>,)):

axes = sorted(tupleize(axis))<EOL>key_shape = [self.shape[axis] for axis in axes]<EOL>reshaped = self._align(axes, key_shape=key_shape)<EOL>mapped = asarray(list(map(func, reshaped)))<EOL>elem_shape = mapped[<NUM_LIT:0>].shape<EOL>linearized_shape_inv = key_shape + list(elem_shape)<EOL>reordered = mapped.reshape(*linearized_shape_inv)<EOL>return self._constructor(reordered)<EOL>

Apply a function across an axis.

Array will be aligned so that the desired set of axes
are in the keys, which may require a transpose/reshape.

Parameters
----------
func : function
    Function of a single array to apply

axis : tuple or int, optional, default=(0,)
    Axis or multiple axes to apply function along.

Returns
-------
BoltArrayLocal


def reduce(self, func, axis=<NUM_LIT:0>):

axes = sorted(tupleize(axis))<EOL>if isinstance(func, ufunc):<EOL><INDENT>inshape(self.shape, axes)<EOL>reduced = func.reduce(self, axis=tuple(axes))<EOL><DEDENT>else:<EOL><INDENT>reshaped = self._align(axes)<EOL>reduced = reduce(func, reshaped)<EOL><DEDENT>new_array = self._constructor(reduced)<EOL>expected_shape = [self.shape[i] for i in range(len(self.shape)) if i not in axes]<EOL>if new_array.shape != tuple(expected_shape):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return new_array<EOL>

Reduce an array along an axis.

Applies an associative/commutative function of two arguments
cumulatively to all arrays along an axis. Array will be aligned
so that the desired set of axes are in the keys, which may
require a transpose/reshape.

Parameters
----------
func : function
    Function of two arrays that returns a single array

axis : tuple or int, optional, default=(0,)
    Axis or multiple axes to reduce along.

Returns
-------
BoltArrayLocal


def tospark(self, sc, axis=<NUM_LIT:0>):

from bolt import array<EOL>return array(self.toarray(), sc, axis=axis)<EOL>

Converts a BoltArrayLocal into a BoltArraySpark

Parameters
----------
sc : SparkContext
    The SparkContext which will be used to create the BoltArraySpark

axis : tuple or int, optional, default=0
    The axis (or axes) across which this array will be parallelized

Returns
-------
BoltArraySpark


from bolt import array<EOL>return array(self.toarray(), sc, axis=axis).tordd()<EOL>

Converts a BoltArrayLocal into an RDD

Parameters
----------
sc : SparkContext
    The SparkContext which will be used to create the BoltArraySpark

axis : tuple or int, optional, default=0
    The axis (or axes) across which this array will be parallelized

Returns
-------
RDD[(tuple, ndarray)]


for d in range(arry.ndim, arry.ndim+extra):<EOL><INDENT>arry = expand_dims(arry, axis=d)<EOL><DEDENT>return arry<EOL>

Expand dimensions by iteratively append empty axes.

Parameters
----------
arry : ndarray
    The original array

extra : int
    The number of empty axes to append


if type(vals[<NUM_LIT:0>]) is ndarray:<EOL><INDENT>return concatenate(vals, axis=depth)<EOL><DEDENT>else:<EOL><INDENT>return concatenate([allstack(x, depth+<NUM_LIT:1>) for x in vals], axis=depth)<EOL><DEDENT>

If an ndarray has been split into multiple chunks by splitting it along
each axis at a number of locations, this function rebuilds the
original array from chunks.

Parameters
----------
vals : nested lists of ndarrays
    each level of nesting of the lists representing a dimension of
    the original array.


new, old = tupleize(new), tupleize(old)<EOL>if not prod(new) == prod(old):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>

Check to see if a proposed tuple of axes is a valid reshaping of
the old axes by ensuring that they can be factored.

Parameters
----------
new : tuple
    tuple of proposed axes

old : tuple
    tuple of old axes


return lookup(*args, **kwargs).dispatch('<STR_LIT>', *args, **kwargs)<EOL>


import random<EOL>random.seed(<NUM_LIT>)<EOL>filtered = b.filter(lambda x: False)<EOL>res = filtered.toarray()<EOL>assert res.shape == (<NUM_LIT:0>,)<EOL>filtered = b.filter(lambda x: True)<EOL>res = filtered.toarray()<EOL>assert res.shape == b.shape<EOL>def filter_half(x):<EOL><INDENT>random.seed(x.tostring())<EOL>return random.random()<EOL><DEDENT>filtered = b.filter(lambda x: filter_half(x) < <NUM_LIT:0.5>)<EOL>res = filtered.toarray()<EOL>assert res.shape[<NUM_LIT:1>:] == b.shape[<NUM_LIT:1>:]<EOL>assert res.shape[<NUM_LIT:0>] <= b.shape[<NUM_LIT:0>]<EOL>if not b.mode == "<STR_LIT>":<EOL><INDENT>filtered = b.filter(lambda x: filter_half(x) < <NUM_LIT:0.5>, sort=True)<EOL>res = filtered.toarray()<EOL>assert res.shape[<NUM_LIT:1>:] == b.shape[<NUM_LIT:1>:]<EOL>assert res.shape[<NUM_LIT:0>] <= b.shape[<NUM_LIT:0>]<EOL><DEDENT>filtered = b.filter(lambda x: filter_half(x) < <NUM_LIT:0.5>, axis=<NUM_LIT:1>)<EOL>res = filtered.toarray()<EOL>assert res.shape[<NUM_LIT:0>] <= b.shape[<NUM_LIT:1>]<EOL>assert res.shape[<NUM_LIT:1>] == b.shape[<NUM_LIT:0>]<EOL>assert res.shape[<NUM_LIT:2>] == b.shape[<NUM_LIT:2>]<EOL>filtered = b.filter(lambda x: filter_half(x) < <NUM_LIT:0.5>, axis=<NUM_LIT:2>)<EOL>res = filtered.toarray()<EOL>assert res.shape[<NUM_LIT:0>] <= b.shape[<NUM_LIT:2>]<EOL>assert res.shape[<NUM_LIT:1>] == b.shape[<NUM_LIT:0>]<EOL>assert res.shape[<NUM_LIT:2>] == b.shape[<NUM_LIT:1>]<EOL>filtered = b.filter(lambda x: False, axis=(<NUM_LIT:0>, <NUM_LIT:1>))<EOL>res = filtered.toarray()<EOL>assert res.shape == (<NUM_LIT:0>,)<EOL>filtered = b.filter(lambda x: True)<EOL>res = filtered.toarray()<EOL>assert res.shape == b.shape<EOL>filtered = b.filter(lambda x: filter_half(x) < <NUM_LIT:0.5>, axis=(<NUM_LIT:0>, <NUM_LIT:1>))<EOL>res = filtered.toarray()<EOL>assert res.shape[<NUM_LIT:0>] <= b.shape[<NUM_LIT:0>]*b.shape[<NUM_LIT:1>]<EOL>assert res.shape[<NUM_LIT:1>] == b.shape[<NUM_LIT:2>]<EOL>

A set of tests for the filter operator

Parameters
----------
arr: `ndarray`
    A 3D ndarray used in the construction of `b` (used to check results)
b: `BoltArray`
    The BoltArray to be used for testing


if options is not None:<EOL><INDENT>args = argumentsParser.parse_args(options)<EOL><DEDENT>else:<EOL><INDENT>args = argumentsParser.parse_args()<EOL><DEDENT>return args<EOL>


for i in range(<NUM_LIT:0>, len(l), n):<EOL><INDENT>yield l[i:i + n]<EOL><DEDENT>


@_convert_f_to_seqs(<NUM_LIT:2>)<EOL>def floyd(seqs, f=None, start=None, key=lambda x: x):

tortise, hare = seqs<EOL>yield hare.next()<EOL>tortise_value = tortise.next()<EOL>hare_value = hare.next()<EOL>while hare_value != tortise_value:<EOL><INDENT>yield hare_value<EOL>yield hare.next()<EOL>hare_value = hare.next()<EOL>tortise_value = tortise.next()<EOL><DEDENT>if f is None:<EOL><INDENT>raise CycleDetected()<EOL><DEDENT>hare_value = f(hare_value)<EOL>first = <NUM_LIT:0><EOL>tortise_value = start<EOL>while key(tortise_value) != key(hare_value):<EOL><INDENT>tortise_value = f(tortise_value)<EOL>hare_value = f(hare_value)<EOL>first += <NUM_LIT:1><EOL><DEDENT>period = <NUM_LIT:1><EOL>hare_value = f(tortise_value)<EOL>while key(tortise_value) != key(hare_value):<EOL><INDENT>hare_value = f(hare_value)<EOL>period += <NUM_LIT:1><EOL><DEDENT>raise CycleDetected(period=period, first=first)<EOL>

Floyd's Cycle Detector.

    See help(cycle_detector) for more context.

    Args:

      *args: Two iterators issueing the exact same sequence:
      -or-
      f, start: Function and starting state for finite state machine

    Yields:

      Values yielded by sequence_a if it terminates, undefined if a
      cycle is found.

    Raises:

      CycleFound if exception is found; if called with f and `start`,
      the parametres `first` and `period` will be defined indicating
      the offset of start of the cycle and the cycle's period.


@classmethod<EOL><INDENT>def start(cls, now, number, firstweekday=calendar.SATURDAY, **options):<DEDENT>

week = cls.mask(now, firstweekday=firstweekday, **options)<EOL>days = (number - <NUM_LIT:1>) * cls.DAYS_IN_WEEK<EOL>return week - timedelta(days=days)<EOL>

Return the starting datetime: ``number`` of weeks before ``now``.

``firstweekday`` determines when the week starts. It defaults
to Saturday.


@classmethod<EOL><INDENT>def mask(cls, dt, **options):<DEDENT>

return dt.replace(minute=<NUM_LIT:0>, second=<NUM_LIT:0>, microsecond=<NUM_LIT:0>)<EOL>

Return a datetime with the same value as ``dt``, to a
resolution of hours.


return dt.replace(month=<NUM_LIT:1>, day=<NUM_LIT:1>,<EOL>hour=<NUM_LIT:0>, minute=<NUM_LIT:0>, second=<NUM_LIT:0>, microsecond=<NUM_LIT:0>)<EOL>

Return a datetime with the same value as ``dt``, to a
resolution of years.


return dt.replace(hour=<NUM_LIT:0>, minute=<NUM_LIT:0>, second=<NUM_LIT:0>, microsecond=<NUM_LIT:0>)<EOL>

Return a datetime with the same value as ``dt``, to a
resolution of days.


raise NotImplemented<EOL>

Return a datetime with the same value as ``dt``, keeping only
significant values.


def dates_to_keep(dates,<EOL>years=<NUM_LIT:0>, months=<NUM_LIT:0>, weeks=<NUM_LIT:0>, days=<NUM_LIT:0>, firstweekday=SATURDAY,<EOL>now=None):

datetimes = to_keep((datetime.combine(d, time()) for d in dates),<EOL>years=years, months=months, weeks=weeks, days=days,<EOL>hours=<NUM_LIT:0>, minutes=<NUM_LIT:0>, seconds=<NUM_LIT:0>,<EOL>firstweekday=firstweekday, now=now)<EOL>return set(dt.date() for dt in datetimes)<EOL>

Return a set of dates that should be kept, out of ``dates``.

See ``to_keep`` for a description of arguments.


return (int(x) & <NUM_LIT>).to_bytes(<NUM_LIT:4>, "<STR_LIT>")<EOL>

Convert a 32-bit integer to little-endian.


def _exec_module(<EOL>self,<EOL>fullname: str,<EOL>loader_state: Mapping[str, str],<EOL>path_stats: Mapping[str, int],<EOL>module: types.ModuleType,<EOL>):

filename = loader_state["<STR_LIT:filename>"]<EOL>cache_filename = loader_state["<STR_LIT>"]<EOL>with timed(<EOL>lambda duration: logger.debug(<EOL>f"<STR_LIT>"<EOL>)<EOL>):<EOL><INDENT>all_bytecode = []<EOL>def add_bytecode(bytecode: types.CodeType):<EOL><INDENT>all_bytecode.append(bytecode)<EOL><DEDENT>logger.debug(f"<STR_LIT>")<EOL>forms = reader.read_file(filename, resolver=runtime.resolve_alias)<EOL>compiler.compile_module(  <EOL>forms,<EOL>compiler.CompilerContext(filename=filename),<EOL>module,<EOL>collect_bytecode=add_bytecode,<EOL>)<EOL><DEDENT>cache_file_bytes = _basilisp_bytecode(<EOL>path_stats["<STR_LIT>"], path_stats["<STR_LIT:size>"], all_bytecode<EOL>)<EOL>self._cache_bytecode(filename, cache_filename, cache_file_bytes)<EOL>

Load and execute a non-cached Basilisp module.


return int.from_bytes(int_bytes, "<STR_LIT>")<EOL>

Convert 4 bytes in little-endian to an integer.


i = next_name_id()<EOL>return f"<STR_LIT>"<EOL>

Generate a unique function name with the given prefix.


def munge(s: str, allow_builtins: bool = False) -> str:

new_str = []<EOL>for c in s:<EOL><INDENT>new_str.append(_MUNGE_REPLACEMENTS.get(c, c))<EOL><DEDENT>new_s = "<STR_LIT>".join(new_str)<EOL>if keyword.iskeyword(new_s):<EOL><INDENT>return f"<STR_LIT>"<EOL><DEDENT>if not allow_builtins and new_s in builtins.__dict__:<EOL><INDENT>return f"<STR_LIT>"<EOL><DEDENT>return new_s<EOL>

Replace characters which are not valid in Python symbols
    with valid replacement strings.


s = rest(o)<EOL>if not s:<EOL><INDENT>return None<EOL><DEDENT>return s<EOL>

Calls rest on o. If o returns an empty sequence or None, returns None.
    Otherwise, returns the elements after the first in o.


def decorator(f):<EOL><INDENT>for k, v in kwargs.items():<EOL><INDENT>setattr(f, k, v)<EOL><DEDENT>return f<EOL><DEDENT>return decorator<EOL>

Decorator to set attributes on a function. Returns the original
    function after setting the attributes named by the keyword arguments.


@classmethod<EOL><INDENT>def __refer_all(cls, refers: lmap.Map, other_ns_interns: lmap.Map) -> lmap.Map:<DEDENT>

final_refers = refers<EOL>for entry in other_ns_interns:<EOL><INDENT>s: sym.Symbol = entry.key<EOL>var: Var = entry.value<EOL>if not var.is_private:<EOL><INDENT>final_refers = final_refers.assoc(s, var)<EOL><DEDENT><DEDENT>return final_refers<EOL>

Refer all _public_ interns from another namespace.


def deref(o, timeout_s=None, timeout_val=None):

if isinstance(o, IDeref):<EOL><INDENT>return o.deref()<EOL><DEDENT>elif isinstance(o, IBlockingDeref):<EOL><INDENT>return o.deref(timeout_s, timeout_val)<EOL><DEDENT>raise TypeError(f"<STR_LIT>")<EOL>

Dereference a Deref object and return its contents.

    If o is an object implementing IBlockingDeref and timeout_s and
    timeout_val are supplied, deref will wait at most timeout_s seconds,
    returning timeout_val if timeout_s seconds elapse and o has not
    returned.


def add_alias(self, alias: sym.Symbol, namespace: "<STR_LIT>") -> None:

self._aliases.swap(lambda m: m.assoc(alias, namespace))<EOL>

Add a Symbol alias for the given Namespace.


@staticmethod<EOL><INDENT>def intern_unbound(<EOL>ns: sym.Symbol, name: sym.Symbol, dynamic: bool = False, meta=None<EOL>) -> "<STR_LIT>":<DEDENT>

var_ns = Namespace.get_or_create(ns)<EOL>return var_ns.intern(name, Var(var_ns, name, dynamic=dynamic, meta=meta))<EOL>

Create a new unbound `Var` instance to the symbol `name` in namespace `ns`.


@classmethod<EOL><INDENT>def remove(cls, name: sym.Symbol) -> Optional["<STR_LIT>"]:<DEDENT>

while True:<EOL><INDENT>oldval: lmap.Map = cls._NAMESPACES.deref()<EOL>ns: Optional[Namespace] = oldval.entry(name, None)<EOL>newval = oldval<EOL>if ns is not None:<EOL><INDENT>newval = oldval.dissoc(name)<EOL><DEDENT>if cls._NAMESPACES.compare_and_set(oldval, newval):<EOL><INDENT>return ns<EOL><DEDENT><DEDENT>

Remove the namespace bound to the symbol `name` in the global
        namespace cache and return that namespace.
        Return None if the namespace did not exist in the cache.


def add_import(<EOL>self, sym: sym.Symbol, module: types.ModuleType, *aliases: sym.Symbol<EOL>) -> None:

self._imports.swap(lambda m: m.assoc(sym, module))<EOL>if aliases:<EOL><INDENT>self._import_aliases.swap(<EOL>lambda m: m.assoc(<EOL>*itertools.chain.from_iterable([(alias, sym) for alias in aliases])<EOL>)<EOL>)<EOL><DEDENT>

Add the Symbol as an imported Symbol in this Namespace. If aliases are given,
        the aliases will be applied to the


@staticmethod<EOL><INDENT>def find_in_ns(ns_sym: sym.Symbol, name_sym: sym.Symbol) -> "<STR_LIT>":<DEDENT>

ns = Namespace.get(ns_sym)<EOL>if ns:<EOL><INDENT>return ns.find(name_sym)<EOL><DEDENT>return None<EOL>

Return the value current bound to the name `name_sym` in the namespace
        specified by `ns_sym`.


if isinstance(args, tuple):<EOL><INDENT>return llist.list(args)<EOL><DEDENT>raise TypeError("<STR_LIT>")<EOL>

Collect Python starred arguments into a Basilisp list.


if o is None:<EOL><INDENT>return None<EOL><DEDENT>if isinstance(o, ISeq):<EOL><INDENT>s = o.rest<EOL>if s is None:<EOL><INDENT>return lseq.EMPTY<EOL><DEDENT>return s<EOL><DEDENT>n = to_seq(o)<EOL>if n is None:<EOL><INDENT>return lseq.EMPTY<EOL><DEDENT>return n.rest<EOL>

If o is a ISeq, return the elements after the first in o. If o is None,
    returns an empty seq. Otherwise, coerces o to a seq and returns the rest.


@property<EOL><INDENT>def interns(self) -> VarMap:<DEDENT>

return self._interns.deref()<EOL>

A mapping between a symbolic name and a Var. The Var may point to
        code, data, or nothing, if it is unbound. Vars in `interns` are
        interned in _this_ namespace.


def set_current_ns(<EOL>ns_name: str,<EOL>module: types.ModuleType = None,<EOL>ns_var_name: str = NS_VAR_NAME,<EOL>ns_var_ns: str = NS_VAR_NS,<EOL>) -> Var:

symbol = sym.Symbol(ns_name)<EOL>ns = Namespace.get_or_create(symbol, module=module)<EOL>ns_var_sym = sym.Symbol(ns_var_name, ns=ns_var_ns)<EOL>ns_var = Maybe(Var.find(ns_var_sym)).or_else_raise(<EOL>lambda: RuntimeException(<EOL>f"<STR_LIT>"<EOL>)<EOL>)<EOL>ns_var.push_bindings(ns)<EOL>logger.debug(f"<STR_LIT>")<EOL>return ns_var<EOL>

Set the value of the dynamic variable `*ns*` in the current thread.


@staticmethod<EOL><INDENT>def __get_or_create(<EOL>ns_cache: NamespaceMap,<EOL>name: sym.Symbol,<EOL>module: types.ModuleType = None,<EOL>core_ns_name=CORE_NS,<EOL>) -> lmap.Map:<DEDENT>

ns = ns_cache.entry(name, None)<EOL>if ns is not None:<EOL><INDENT>return ns_cache<EOL><DEDENT>new_ns = Namespace(name, module=module)<EOL>if name.name != core_ns_name:<EOL><INDENT>core_ns = ns_cache.entry(sym.symbol(core_ns_name), None)<EOL>assert core_ns is not None, "<STR_LIT>"<EOL>new_ns.refer_all(core_ns)<EOL><DEDENT>return ns_cache.assoc(name, new_ns)<EOL>

Private swap function used by `get_or_create` to atomically swap
        the new namespace map into the global cache.


@staticmethod<EOL><INDENT>def __completion_matcher(text: str) -> CompletionMatcher:<DEDENT>

def is_match(entry: Tuple[sym.Symbol, Any]) -> bool:<EOL><INDENT>return entry[<NUM_LIT:0>].name.startswith(text)<EOL><DEDENT>return is_match<EOL>

Return a function which matches any symbol keys from map entries
        against the given text.


@functools.wraps(f)<EOL>def partial_f(*inner_args):<EOL><INDENT>return f(*itertools.chain(args, inner_args))<EOL><DEDENT>return partial_f<EOL>

Return a function which is the partial application of f with args.


@property<EOL><INDENT>def aliases(self) -> NamespaceMap:<DEDENT>

return self._aliases.deref()<EOL>

A mapping between a symbolic alias and another Namespace. The
        fully qualified name of a namespace is also an alias for itself.


if o is None:<EOL><INDENT>return None<EOL><DEDENT>if isinstance(o, ISeq):<EOL><INDENT>return o.first<EOL><DEDENT>s = to_seq(o)<EOL>if s is None:<EOL><INDENT>return None<EOL><DEDENT>return s.first<EOL>

If o is a ISeq, return the first element from o. If o is None, return
    None. Otherwise, coerces o to a Seq and returns the first.


def resolve_var(s: sym.Symbol, ns: Optional[Namespace] = None) -> Optional[Var]:

return Var.find(resolve_alias(s, ns))<EOL>

Resolve the aliased symbol to a Var from the specified
    namespace, or the current namespace if none is specified.


@functools.singledispatch<EOL>def to_lisp(o, keywordize_keys: bool = True):

if not isinstance(o, (dict, frozenset, list, set, tuple)):<EOL><INDENT>return o<EOL><DEDENT>else:  <EOL><INDENT>return _to_lisp_backup(o, keywordize_keys=keywordize_keys)<EOL><DEDENT>

Recursively convert Python collections into Lisp collections.


def get_import(self, sym: sym.Symbol) -> Optional[types.ModuleType]:

mod = self.imports.entry(sym, None)<EOL>if mod is None:<EOL><INDENT>alias = self.import_aliases.get(sym, None)<EOL>if alias is None:<EOL><INDENT>return None<EOL><DEDENT>return self.imports.entry(alias, None)<EOL><DEDENT>return mod<EOL>

Return the module if a moduled named by sym has been imported into
        this Namespace, None otherwise.

        First try to resolve a module directly with the given name. If no module
        can be resolved, attempt to resolve the module using import aliases.


@staticmethod<EOL><INDENT>def find_safe(ns_qualified_sym: sym.Symbol) -> "<STR_LIT>":<DEDENT>

v = Var.find(ns_qualified_sym)<EOL>if v is None:<EOL><INDENT>raise RuntimeException(<EOL>f"<STR_LIT>"<EOL>)<EOL><DEDENT>return v<EOL>

Return the Var currently bound to the name in the namespace specified
        by `ns_qualified_sym`. If no Var is bound to that name, raise an exception.

        This is a utility method to return useful debugging information when code
        refers to an invalid symbol at runtime.


if isinstance(coll, IAssociative):<EOL><INDENT>return coll.contains(k)<EOL><DEDENT>return k in coll<EOL>


if m is None:<EOL><INDENT>return lmap.Map.empty().assoc(k, f(None, *args))<EOL><DEDENT>if isinstance(m, IAssociative):<EOL><INDENT>old_v = m.entry(k)<EOL>new_v = f(old_v, *args)<EOL>return m.assoc(k, new_v)<EOL><DEDENT>raise TypeError(<EOL>f"<STR_LIT>"<EOL>)<EOL>

Updates the value for key k in associative data structure m with the return value from
    calling f(old_v, *args). If m is None, use an empty map. If k is not in m, old_v will be
    None.


def get_alias(self, alias: sym.Symbol) -> "<STR_LIT>":

return self.aliases.entry(alias, None)<EOL>

Get the Namespace aliased by Symbol or None if it does not exist.


try:<EOL><INDENT>i = iter(s)<EOL>return _Sequence(i, next(i))<EOL><DEDENT>except StopIteration:<EOL><INDENT>return EMPTY<EOL><DEDENT>


def multifn(dispatch: DispatchFunction, default=None) -> MultiFunction[T]:

name = sym.symbol(dispatch.__qualname__, ns=dispatch.__module__)<EOL>return MultiFunction(name, dispatch, default)<EOL>

Decorator function which can be used to make Python multi functions.


@property<EOL><INDENT>@abstractmethod<EOL>def is_assignable(self) -> bool:<DEDENT>

True if this Node can be assigned in a set! form, False otherwise.


@property<EOL><INDENT>@abstractmethod<EOL>def op(self) -> NodeOp:<DEDENT>

Enumerated keyword uniquely identifying this type of Node.

        The type and NodeOp should always be in sync.

        Having a simple enum value in addition to the type allows us to use
        switch-like syntax with Python dictionaries in compiler code, which
        is much faster than performing isinstance checks.


def visit_Expr(self, node: ast.Expr) -> Optional[ast.Expr]:

if isinstance(<EOL>node.value,<EOL>(<EOL>ast.Constant,  <EOL>ast.Name,<EOL>ast.NameConstant,<EOL>ast.Num,<EOL>ast.Str,<EOL>),<EOL>):<EOL><INDENT>return None<EOL><DEDENT>return node<EOL>

Eliminate no-op constant expressions which are in the tree
        as standalone statements.


def visit_While(self, node: ast.While) -> Optional[ast.AST]:

new_node = self.generic_visit(node)<EOL>assert isinstance(new_node, ast.While)<EOL>return ast.copy_location(<EOL>ast.While(<EOL>test=new_node.test,<EOL>body=_filter_dead_code(new_node.body),<EOL>orelse=_filter_dead_code(new_node.orelse),<EOL>),<EOL>new_node,<EOL>)<EOL>


@wraps(f)<EOL>def _parse_form(ctx: ParserContext, form: Union[LispForm, ISeq]) -> Node:<EOL><INDENT>form_loc = _loc(form)<EOL>if form_loc is None:<EOL><INDENT>return f(ctx, form)<EOL><DEDENT>else:<EOL><INDENT>return f(ctx, form).fix_missing_locations(form_loc)<EOL><DEDENT><DEDENT>return _parse_form<EOL>

Attach any available location information from the input form to
    the node environment returned from the parsing function.


def _assert_recur_is_tail(node: Node) -> None:

if node.op == NodeOp.DO:<EOL><INDENT>assert isinstance(node, Do)<EOL>for child in node.statements:<EOL><INDENT>_assert_no_recur(child)<EOL><DEDENT>_assert_recur_is_tail(node.ret)<EOL><DEDENT>elif node.op in {NodeOp.FN, NodeOp.FN_METHOD, NodeOp.METHOD}:<EOL><INDENT>assert isinstance(node, (Fn, FnMethod, Method))<EOL>node.visit(_assert_recur_is_tail)<EOL><DEDENT>elif node.op == NodeOp.IF:<EOL><INDENT>assert isinstance(node, If)<EOL>_assert_no_recur(node.test)<EOL>_assert_recur_is_tail(node.then)<EOL>_assert_recur_is_tail(node.else_)<EOL><DEDENT>elif node.op in {NodeOp.LET, NodeOp.LETFN}:<EOL><INDENT>assert isinstance(node, (Let, LetFn))<EOL>for binding in node.bindings:<EOL><INDENT>assert binding.init is not None<EOL>_assert_no_recur(binding.init)<EOL><DEDENT>_assert_recur_is_tail(node.body)<EOL><DEDENT>elif node.op == NodeOp.LOOP:<EOL><INDENT>assert isinstance(node, Loop)<EOL>for binding in node.bindings:<EOL><INDENT>assert binding.init is not None<EOL>_assert_no_recur(binding.init)<EOL><DEDENT><DEDENT>elif node.op == NodeOp.RECUR:<EOL><INDENT>pass<EOL><DEDENT>elif node.op == NodeOp.TRY:<EOL><INDENT>assert isinstance(node, Try)<EOL>_assert_recur_is_tail(node.body)<EOL>for catch in node.catches:<EOL><INDENT>_assert_recur_is_tail(catch)<EOL><DEDENT>if node.finally_:<EOL><INDENT>_assert_no_recur(node.finally_)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>node.visit(_assert_no_recur)<EOL><DEDENT>

Assert that `recur` forms only appear in the tail position of this
    or child AST nodes.

    `recur` forms may only appear in `do` nodes (both literal and synthetic
    `do` nodes) and in either the :then or :else expression of an `if` node.


def parse_ast(ctx: ParserContext, form: ReaderForm) -> Node:

return _parse_ast(ctx, form).assoc(top_level=True)<EOL>

Take a Lisp form as an argument and produce a Basilisp syntax
    tree matching the clojure.tools.analyzer AST spec.


def put_new_symbol(  <EOL>self,<EOL>s: sym.Symbol,<EOL>binding: Binding,<EOL>warn_on_shadowed_name: bool = True,<EOL>warn_on_shadowed_var: bool = True,<EOL>warn_if_unused: bool = True,<EOL>):

st = self.symbol_table<EOL>if warn_on_shadowed_name and self.warn_on_shadowed_name:<EOL><INDENT>if st.find_symbol(s) is not None:<EOL><INDENT>logger.warning(f"<STR_LIT>")<EOL><DEDENT><DEDENT>if (<EOL>warn_on_shadowed_name or warn_on_shadowed_var<EOL>) and self.warn_on_shadowed_var:<EOL><INDENT>if self.current_ns.find(s) is not None:<EOL><INDENT>logger.warning(f"<STR_LIT>")<EOL><DEDENT><DEDENT>if s.meta is not None and s.meta.entry(SYM_NO_WARN_WHEN_UNUSED_META_KEY, None):<EOL><INDENT>warn_if_unused = False<EOL><DEDENT>st.new_symbol(s, binding, warn_if_unused=warn_if_unused)<EOL>

Add a new symbol to the symbol table.

        This function allows individual warnings to be disabled for one run
        by supplying keyword arguments temporarily disabling those warnings.
        In certain cases, we do not want to issue warnings again for a
        previously checked case, so this is a simple way of disabling these
        warnings for those cases.

        If WARN_ON_SHADOWED_NAME compiler option is active and the
        warn_on_shadowed_name keyword argument is True, then a warning will be
        emitted if a local name is shadowed by another local name. Note that
        WARN_ON_SHADOWED_NAME implies WARN_ON_SHADOWED_VAR.

        If WARN_ON_SHADOWED_VAR compiler option is active and the
        warn_on_shadowed_var keyword argument is True, then a warning will be
        emitted if a named var is shadowed by a local name.


@wraps(gen_node)<EOL>def with_meta(<EOL>ctx: ParserContext,<EOL>form: Union[llist.List, lmap.Map, ISeq, lset.Set, vec.Vector],<EOL>) -> Node:<EOL><INDENT>assert not ctx.is_quoted, "<STR_LIT>"<EOL>descriptor = gen_node(ctx, form)<EOL>if isinstance(form, IMeta):<EOL><INDENT>assert isinstance(form.meta, (lmap.Map, type(None)))<EOL>form_meta = _clean_meta(form.meta)<EOL>if form_meta is not None:<EOL><INDENT>meta_ast = _parse_ast(ctx, form_meta)<EOL>assert isinstance(meta_ast, MapNode) or (<EOL>isinstance(meta_ast, Const) and meta_ast.type == ConstType.MAP<EOL>)<EOL>return WithMeta(<EOL>form=form, meta=meta_ast, expr=descriptor, env=ctx.get_node_env()<EOL>)<EOL><DEDENT><DEDENT>return descriptor<EOL><DEDENT>return with_meta<EOL>

Wraps the node generated by gen_node in a :with-meta AST node if the
    original form has meta.

    :with-meta AST nodes are used for non-quoted collection literals and for
    function expressions.


return (<EOL>Maybe(v.meta)<EOL>.map(lambda m: m.entry(SYM_MACRO_META_KEY, None))  <EOL>.or_else_get(False)<EOL>)<EOL>

Return True if the Var holds a macro function.


def compile_module(<EOL>forms: Iterable[ReaderForm],<EOL>ctx: CompilerContext,<EOL>module: types.ModuleType,<EOL>collect_bytecode: Optional[BytecodeCollector] = None,<EOL>) -> None:

_bootstrap_module(ctx.generator_context, ctx.py_ast_optimizer, module)<EOL>for form in forms:<EOL><INDENT>nodes = gen_py_ast(ctx.generator_context, parse_ast(ctx.parser_context, form))<EOL>_incremental_compile_module(<EOL>ctx.py_ast_optimizer,<EOL>nodes,<EOL>module,<EOL>source_filename=ctx.filename,<EOL>collect_bytecode=collect_bytecode,<EOL>)<EOL><DEDENT>

Compile an entire Basilisp module into Python bytecode which can be
    executed as a Python module.

    This function is designed to generate bytecode which can be used for the
    Basilisp import machinery, to allow callers to import Basilisp modules from
    Python code.


def gen_py_ast(ctx: GeneratorContext, lisp_ast: Node) -> GeneratedPyAST:

op: NodeOp = lisp_ast.op<EOL>assert op is not None, "<STR_LIT>"<EOL>handle_node = _NODE_HANDLERS.get(op)<EOL>assert (<EOL>handle_node is not None<EOL>), f"<STR_LIT>"<EOL>return handle_node(ctx, lisp_ast)<EOL>

Take a Lisp AST node as an argument and produce zero or more Python
    AST nodes.

    This is the primary entrypoint for generating AST nodes from Lisp
    syntax. It may be called recursively to compile child forms.


@_with_ast_loc<EOL>def _quote_to_py_ast(ctx: GeneratorContext, node: Quote) -> GeneratedPyAST:

assert node.op == NodeOp.QUOTE<EOL>return _const_node_to_py_ast(ctx, node.expr)<EOL>

Return a Python AST Node for a `quote` expression.


return genname("<STR_LIT>" + munge(Maybe(s).or_else_get(_FN_PREFIX)))<EOL>

Generate a safe Python function name from a function name symbol.
    If no symbol is provided, generate a name with a default prefix.


@property<EOL><INDENT>def use_var_indirection(self) -> bool:<DEDENT>

return self._opts.entry(USE_VAR_INDIRECTION, False)<EOL>

If True, compile all variable references using Var.find indirection.


@_with_ast_loc<EOL>def _local_sym_to_py_ast(<EOL>ctx: GeneratorContext, node: Local, is_assigning: bool = False<EOL>) -> GeneratedPyAST:

assert node.op == NodeOp.LOCAL<EOL>sym_entry = ctx.symbol_table.find_symbol(sym.symbol(node.name))<EOL>assert sym_entry is not None<EOL>if node.local == LocalType.FIELD:<EOL><INDENT>this_entry = ctx.symbol_table.find_symbol(ctx.current_this)<EOL>assert this_entry is not None, "<STR_LIT>"<EOL>return GeneratedPyAST(<EOL>node=_load_attr(<EOL>f"<STR_LIT>",<EOL>ctx=ast.Store() if is_assigning else ast.Load(),<EOL>)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>return GeneratedPyAST(<EOL>node=ast.Name(<EOL>id=sym_entry.munged, ctx=ast.Store() if is_assigning else ast.Load()<EOL>)<EOL>)<EOL><DEDENT>

Generate a Python AST node for accessing a locally defined Python variable.


def statementize(e: ast.AST) -> ast.AST:

Transform non-statements into ast.Expr nodes so they can
    stand alone as statements.


@_with_ast_loc_deps<EOL>def _if_to_py_ast(ctx: GeneratorContext, node: If) -> GeneratedPyAST:

assert node.op == NodeOp.IF<EOL>test_ast = gen_py_ast(ctx, node.test)<EOL>result_name = genname(_IF_RESULT_PREFIX)<EOL>then_ast = __if_body_to_py_ast(ctx, node.then, result_name)<EOL>else_ast = __if_body_to_py_ast(ctx, node.else_, result_name)<EOL>test_name = genname(_IF_TEST_PREFIX)<EOL>test_assign = ast.Assign(<EOL>targets=[ast.Name(id=test_name, ctx=ast.Store())], value=test_ast.node<EOL>)<EOL>ifstmt = ast.If(<EOL>test=ast.BoolOp(<EOL>op=ast.Or(),<EOL>values=[<EOL>ast.Compare(<EOL>left=ast.NameConstant(None),<EOL>ops=[ast.Is()],<EOL>comparators=[ast.Name(id=test_name, ctx=ast.Load())],<EOL>),<EOL>ast.Compare(<EOL>left=ast.NameConstant(False),<EOL>ops=[ast.Is()],<EOL>comparators=[ast.Name(id=test_name, ctx=ast.Load())],<EOL>),<EOL>],<EOL>),<EOL>values=[],<EOL>body=list(map(statementize, chain(else_ast.dependencies, [else_ast.node]))),<EOL>orelse=list(map(statementize, chain(then_ast.dependencies, [then_ast.node]))),<EOL>)<EOL>return GeneratedPyAST(<EOL>node=ast.Name(id=result_name, ctx=ast.Load()),<EOL>dependencies=list(chain(test_ast.dependencies, [test_assign, ifstmt])),<EOL>)<EOL>

Generate an intermediate if statement which assigns to a temporary
    variable, which is returned as the expression value at the end of
    evaluation.

    Every expression in Basilisp is true if it is not the literal values nil
    or false. This function compiles direct checks for the test value against
    the Python values None and False to accommodate this behavior.

    Note that the if and else bodies are switched in compilation so that we
    can perform a short-circuit or comparison, rather than exhaustively checking
    for both false and nil each time.


@_with_ast_loc_deps<EOL>def __multi_arity_fn_to_py_ast(  <EOL>ctx: GeneratorContext,<EOL>node: Fn,<EOL>methods: Collection[FnMethod],<EOL>def_name: Optional[str] = None,<EOL>meta_node: Optional[MetaNode] = None,<EOL>) -> GeneratedPyAST:

assert node.op == NodeOp.FN<EOL>assert all([method.op == NodeOp.FN_METHOD for method in methods])<EOL>lisp_fn_name = node.local.name if node.local is not None else None<EOL>py_fn_name = __fn_name(lisp_fn_name) if def_name is None else munge(def_name)<EOL>py_fn_node = ast.AsyncFunctionDef if node.is_async else ast.FunctionDef<EOL>arity_to_name = {}<EOL>rest_arity_name: Optional[str] = None<EOL>fn_defs = []<EOL>for method in methods:<EOL><INDENT>arity_name = f"<STR_LIT>"<EOL>if method.is_variadic:<EOL><INDENT>rest_arity_name = arity_name<EOL><DEDENT>else:<EOL><INDENT>arity_to_name[method.fixed_arity] = arity_name<EOL><DEDENT>with ctx.new_symbol_table(arity_name), ctx.new_recur_point(<EOL>method.loop_id, RecurType.FN, is_variadic=node.is_variadic<EOL>):<EOL><INDENT>if lisp_fn_name is not None:<EOL><INDENT>ctx.symbol_table.new_symbol(<EOL>sym.symbol(lisp_fn_name), py_fn_name, LocalType.FN<EOL>)<EOL><DEDENT>fn_args, varg, fn_body_ast = __fn_args_to_py_ast(<EOL>ctx, method.params, method.body<EOL>)<EOL>fn_defs.append(<EOL>py_fn_node(<EOL>name=arity_name,<EOL>args=ast.arguments(<EOL>args=fn_args,<EOL>kwarg=None,<EOL>vararg=varg,<EOL>kwonlyargs=[],<EOL>defaults=[],<EOL>kw_defaults=[],<EOL>),<EOL>body=fn_body_ast,<EOL>decorator_list=[_TRAMPOLINE_FN_NAME]<EOL>if ctx.recur_point.has_recur<EOL>else [],<EOL>returns=None,<EOL>)<EOL>)<EOL><DEDENT><DEDENT>dispatch_fn_ast = __multi_arity_dispatch_fn(<EOL>ctx,<EOL>py_fn_name,<EOL>arity_to_name,<EOL>default_name=rest_arity_name,<EOL>max_fixed_arity=node.max_fixed_arity,<EOL>meta_node=meta_node,<EOL>is_async=node.is_async,<EOL>)<EOL>return GeneratedPyAST(<EOL>node=dispatch_fn_ast.node,<EOL>dependencies=list(chain(fn_defs, dispatch_fn_ast.dependencies)),<EOL>)<EOL>

Return a Python AST node for a function with multiple arities.


@property<EOL><INDENT>def warn_on_var_indirection(self) -> bool:<DEDENT>

return not self.use_var_indirection and self._opts.entry(<EOL>WARN_ON_VAR_INDIRECTION, True<EOL>)<EOL>

If True, warn when a Var reference cannot be direct linked (iff
        use_var_indirection is False)..


def __var_find_to_py_ast(<EOL>var_name: str, ns_name: str, py_var_ctx: ast.AST<EOL>) -> GeneratedPyAST:

Generate Var.find calls for the named symbol.


return (<EOL>Maybe(v.meta)<EOL>.map(lambda m: m.get(SYM_REDEF_META_KEY, None))  <EOL>.or_else_get(False)<EOL>)<EOL>

Return True if the Var can be redefined.


def _load_attr(name: str, ctx: ast.AST = ast.Load()) -> ast.Attribute:

attrs = name.split("<STR_LIT:.>")<EOL>def attr_node(node, idx):<EOL><INDENT>if idx >= len(attrs):<EOL><INDENT>node.ctx = ctx<EOL>return node<EOL><DEDENT>return attr_node(<EOL>ast.Attribute(value=node, attr=attrs[idx], ctx=ast.Load()), idx + <NUM_LIT:1><EOL>)<EOL><DEDENT>return attr_node(ast.Name(id=attrs[<NUM_LIT:0>], ctx=ast.Load()), <NUM_LIT:1>)<EOL>

Generate recursive Python Attribute AST nodes for resolving nested
    names.


def py_module_preamble(ctx: GeneratorContext,) -> GeneratedPyAST:

preamble: List[ast.AST] = []<EOL>preamble.extend(_module_imports(ctx))<EOL>preamble.append(_from_module_import())<EOL>preamble.append(_ns_var())<EOL>return GeneratedPyAST(node=ast.NameConstant(None), dependencies=preamble)<EOL>

Bootstrap a new module with imports and other boilerplate.


@_with_ast_loc<EOL>def _maybe_host_form_to_py_ast(<EOL>_: GeneratorContext, node: MaybeHostForm<EOL>) -> GeneratedPyAST:

assert node.op == NodeOp.MAYBE_HOST_FORM<EOL>return GeneratedPyAST(<EOL>node=_load_attr(<EOL>f"<STR_LIT>"<EOL>)<EOL>)<EOL>

Generate a Python AST node for accessing a potential Python module
    variable name with a namespace.


def _with_meta_to_py_ast(<EOL>ctx: GeneratorContext, node: WithMeta, **kwargs<EOL>) -> GeneratedPyAST:

assert node.op == NodeOp.WITH_META<EOL>handle_expr = _WITH_META_EXPR_HANDLER.get(node.expr.op)<EOL>assert (<EOL>handle_expr is not None<EOL>), "<STR_LIT>"<EOL>return handle_expr(ctx, node.expr, meta_node=node.meta, **kwargs)<EOL>

Generate a Python AST node for Python interop method calls.


@_with_ast_loc<EOL>def _set_bang_to_py_ast(ctx: GeneratorContext, node: SetBang) -> GeneratedPyAST:

assert node.op == NodeOp.SET_BANG<EOL>val_temp_name = genname("<STR_LIT>")<EOL>val_ast = gen_py_ast(ctx, node.val)<EOL>target = node.target<EOL>assert isinstance(<EOL>target, (HostField, Local, VarRef)<EOL>), f"<STR_LIT>"<EOL>if isinstance(target, HostField):<EOL><INDENT>target_ast = _interop_prop_to_py_ast(ctx, target, is_assigning=True)<EOL><DEDENT>elif isinstance(target, VarRef):<EOL><INDENT>target_ast = _var_sym_to_py_ast(ctx, target, is_assigning=True)<EOL><DEDENT>elif isinstance(target, Local):<EOL><INDENT>target_ast = _local_sym_to_py_ast(ctx, target, is_assigning=True)<EOL><DEDENT>else:  <EOL><INDENT>raise GeneratorException(<EOL>f"<STR_LIT>", lisp_ast=target<EOL>)<EOL><DEDENT>return GeneratedPyAST(<EOL>node=ast.Name(id=val_temp_name, ctx=ast.Load()),<EOL>dependencies=list(<EOL>chain(<EOL>val_ast.dependencies,<EOL>[<EOL>ast.Assign(<EOL>targets=[ast.Name(id=val_temp_name, ctx=ast.Store())],<EOL>value=val_ast.node,<EOL>)<EOL>],<EOL>target_ast.dependencies,<EOL>[ast.Assign(targets=[target_ast.node], value=val_ast.node)],<EOL>)<EOL>),<EOL>)<EOL>

Return a Python AST Node for a `set!` expression.


@_with_ast_loc_deps<EOL>def _import_to_py_ast(ctx: GeneratorContext, node: Import) -> GeneratedPyAST:

assert node.op == NodeOp.IMPORT<EOL>last = None<EOL>deps: List[ast.AST] = []<EOL>for alias in node.aliases:<EOL><INDENT>safe_name = munge(alias.name)<EOL>try:<EOL><INDENT>module = importlib.import_module(safe_name)<EOL>if alias.alias is not None:<EOL><INDENT>ctx.add_import(sym.symbol(alias.name), module, sym.symbol(alias.alias))<EOL><DEDENT>else:<EOL><INDENT>ctx.add_import(sym.symbol(alias.name), module)<EOL><DEDENT><DEDENT>except ModuleNotFoundError as e:<EOL><INDENT>raise ImportError(<EOL>f"<STR_LIT>", node.form, node<EOL>) from e<EOL><DEDENT>py_import_alias = (<EOL>munge(alias.alias)<EOL>if alias.alias is not None<EOL>else safe_name.split("<STR_LIT:.>", maxsplit=<NUM_LIT:1>)[<NUM_LIT:0>]<EOL>)<EOL>deps.append(<EOL>ast.Assign(<EOL>targets=[ast.Name(id=py_import_alias, ctx=ast.Store())],<EOL>value=ast.Call(<EOL>func=_load_attr("<STR_LIT>"),<EOL>args=[ast.Str(safe_name)],<EOL>keywords=[],<EOL>),<EOL>)<EOL>)<EOL>last = ast.Name(id=py_import_alias, ctx=ast.Load())<EOL>deps.append(<EOL>ast.Call(<EOL>func=_load_attr(f"<STR_LIT>"),<EOL>args=[<EOL>ast.Call(<EOL>func=_NEW_SYM_FN_NAME, args=[ast.Str(safe_name)], keywords=[]<EOL>),<EOL>last,<EOL>],<EOL>keywords=[],<EOL>)<EOL>)<EOL><DEDENT>assert last is not None, "<STR_LIT>"<EOL>return GeneratedPyAST(node=last, dependencies=deps)<EOL>

Return a Python AST node for a Basilisp `import*` expression.


def map(kvs: Mapping[K, V], meta=None) -> Map[K, V]:

return Map(pmap(initial=kvs), meta=meta)<EOL>


return Map(pmap(initial=kvs))<EOL>

Creates a new map from keyword arguments.


def _read_meta(ctx: ReaderContext) -> IMeta:

start = ctx.reader.advance()<EOL>assert start == "<STR_LIT>"<EOL>meta = _read_next_consuming_comment(ctx)<EOL>meta_map: Optional[lmap.Map[LispForm, LispForm]] = None<EOL>if isinstance(meta, symbol.Symbol):<EOL><INDENT>meta_map = lmap.map({keyword.keyword("<STR_LIT>"): meta})<EOL><DEDENT>elif isinstance(meta, keyword.Keyword):<EOL><INDENT>meta_map = lmap.map({meta: True})<EOL><DEDENT>elif isinstance(meta, lmap.Map):<EOL><INDENT>meta_map = meta<EOL><DEDENT>else:<EOL><INDENT>raise SyntaxError(<EOL>f"<STR_LIT>"<EOL>)<EOL><DEDENT>obj_with_meta = _read_next_consuming_comment(ctx)<EOL>try:<EOL><INDENT>return obj_with_meta.with_meta(meta_map)  <EOL><DEDENT>except AttributeError:<EOL><INDENT>raise SyntaxError(<EOL>f"<STR_LIT>"<EOL>)<EOL><DEDENT>

Read metadata and apply that to the next object in the
    input stream.


def _read_reader_macro(ctx: ReaderContext) -> LispReaderForm:

start = ctx.reader.advance()<EOL>assert start == "<STR_LIT:#>"<EOL>token = ctx.reader.peek()<EOL>if token == "<STR_LIT:{>":<EOL><INDENT>return _read_set(ctx)<EOL><DEDENT>elif token == "<STR_LIT:(>":<EOL><INDENT>return _read_function(ctx)<EOL><DEDENT>elif token == "<STR_LIT:'>":<EOL><INDENT>ctx.reader.advance()<EOL>s = _read_sym(ctx)<EOL>return llist.l(_VAR, s)<EOL><DEDENT>elif token == '<STR_LIT:">':<EOL><INDENT>return _read_regex(ctx)<EOL><DEDENT>elif token == "<STR_LIT:_>":<EOL><INDENT>ctx.reader.advance()<EOL>_read_next(ctx)  <EOL>return COMMENT<EOL><DEDENT>elif ns_name_chars.match(token):<EOL><INDENT>s = _read_sym(ctx)<EOL>assert isinstance(s, symbol.Symbol)<EOL>v = _read_next_consuming_comment(ctx)<EOL>if s in ctx.data_readers:<EOL><INDENT>f = ctx.data_readers[s]<EOL>return f(v)<EOL><DEDENT>else:<EOL><INDENT>raise SyntaxError(f"<STR_LIT>")<EOL><DEDENT><DEDENT>raise SyntaxError(f"<STR_LIT>")<EOL>

Return a data structure evaluated as a reader
    macro from the input stream.


@_with_loc<EOL>def _read_map(ctx: ReaderContext) -> lmap.Map:

reader = ctx.reader<EOL>start = reader.advance()<EOL>assert start == "<STR_LIT:{>"<EOL>d: MutableMapping[Any, Any] = {}<EOL>while True:<EOL><INDENT>if reader.peek() == "<STR_LIT:}>":<EOL><INDENT>reader.next_token()<EOL>break<EOL><DEDENT>k = _read_next(ctx)<EOL>if k is COMMENT:<EOL><INDENT>continue<EOL><DEDENT>while True:<EOL><INDENT>if reader.peek() == "<STR_LIT:}>":<EOL><INDENT>raise SyntaxError("<STR_LIT>")<EOL><DEDENT>v = _read_next(ctx)<EOL>if v is COMMENT:<EOL><INDENT>continue<EOL><DEDENT>if k in d:<EOL><INDENT>raise SyntaxError(f"<STR_LIT>")<EOL><DEDENT>break<EOL><DEDENT>d[k] = v<EOL><DEDENT>return lmap.map(d)<EOL>


def _read_regex(ctx: ReaderContext) -> Pattern:

s = _read_str(ctx, allow_arbitrary_escapes=True)<EOL>try:<EOL><INDENT>return langutil.regex_from_str(s)<EOL><DEDENT>except re.error:<EOL><INDENT>raise SyntaxError(f"<STR_LIT>")<EOL><DEDENT>

Read a regex reader macro from the input stream.


return self._buffer[self._idx]<EOL>

Peek at the next character in the stream.


def _read_namespaced(<EOL>ctx: ReaderContext, allowed_suffix: Optional[str] = None<EOL>) -> Tuple[Optional[str], str]:

ns: List[str] = []<EOL>name: List[str] = []<EOL>reader = ctx.reader<EOL>has_ns = False<EOL>while True:<EOL><INDENT>token = reader.peek()<EOL>if token == "<STR_LIT:/>":<EOL><INDENT>reader.next_token()<EOL>if has_ns:<EOL><INDENT>raise SyntaxError("<STR_LIT>")<EOL><DEDENT>elif len(name) == <NUM_LIT:0>:<EOL><INDENT>name.append("<STR_LIT:/>")<EOL><DEDENT>else:<EOL><INDENT>if "<STR_LIT:/>" in name:<EOL><INDENT>raise SyntaxError("<STR_LIT>")<EOL><DEDENT>has_ns = True<EOL>ns = name<EOL>name = []<EOL><DEDENT><DEDENT>elif ns_name_chars.match(token):<EOL><INDENT>reader.next_token()<EOL>name.append(token)<EOL><DEDENT>elif allowed_suffix is not None and token == allowed_suffix:<EOL><INDENT>reader.next_token()<EOL>name.append(token)<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>ns_str = None if not has_ns else "<STR_LIT>".join(ns)<EOL>name_str = "<STR_LIT>".join(name)<EOL>if ns_str is None:<EOL><INDENT>if "<STR_LIT:/>" in name_str and name_str != "<STR_LIT:/>":<EOL><INDENT>raise SyntaxError("<STR_LIT>")<EOL><DEDENT><DEDENT>assert ns_str is None or len(ns_str) > <NUM_LIT:0><EOL>return ns_str, name_str<EOL>

Read a namespaced token from the input stream.


def _is_unquote(form: ReaderForm) -> bool:

try:<EOL><INDENT>return form.first == _UNQUOTE  <EOL><DEDENT>except AttributeError:<EOL><INDENT>return False<EOL><DEDENT>


if newline_chars.match(c):<EOL><INDENT>self._col.append(<NUM_LIT:0>)<EOL>self._line.append(self._line[-<NUM_LIT:1>] + <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>self._col.append(self._col[-<NUM_LIT:1>] + <NUM_LIT:1>)<EOL>self._line.append(self._line[-<NUM_LIT:1>])<EOL><DEDENT>

Update the internal line and column buffers after a new character
        is added.

        The column number is set to 0, so the first character on the next line
        is column number 1.


def _read_coll(<EOL>ctx: ReaderContext,<EOL>f: Callable[[Collection[Any]], Union[llist.List, lset.Set, vector.Vector]],<EOL>end_token: str,<EOL>coll_name: str,<EOL>):

coll: List = []<EOL>reader = ctx.reader<EOL>while True:<EOL><INDENT>token = reader.peek()<EOL>if token == "<STR_LIT>":<EOL><INDENT>raise SyntaxError(f"<STR_LIT>")<EOL><DEDENT>if whitespace_chars.match(token):<EOL><INDENT>reader.advance()<EOL>continue<EOL><DEDENT>if token == end_token:<EOL><INDENT>reader.next_token()<EOL>return f(coll)<EOL><DEDENT>elem = _read_next(ctx)<EOL>if elem is COMMENT:<EOL><INDENT>continue<EOL><DEDENT>coll.append(elem)<EOL><DEDENT>

Read a collection from the input stream and create the
    collection using f.


def symbol(name: str, ns: Optional[str] = None, meta=None) -> Symbol:

return Symbol(name, ns=ns, meta=meta)<EOL>


def v(*members: T, meta: Optional[IPersistentMap] = None) -> Vector[T]:

return Vector(pvector(members), meta=meta)<EOL>


if isinstance(lvl, int):<EOL><INDENT>return lvl - <NUM_LIT:1><EOL><DEDENT>return lvl<EOL>

Decrement the print level if it is numeric.


@abstractmethod<EOL><INDENT>def _lrepr(self, **kwargs) -> str:<DEDENT>

raise NotImplementedError()<EOL>

Private Lisp representation method. Callers (including object
        internal callers) should not call this method directly, but instead
        should use the module function .lrepr().


return dict(kwargs, print_level=_dec_print_level(kwargs["<STR_LIT>"]))<EOL>

Process keyword arguments, decreasing the print-level. Should be called
    after examining the print level for the current level.


def _lrepr_fallback(  <EOL>o: Any,<EOL>human_readable: bool = False,<EOL>print_dup: bool = PRINT_DUP,<EOL>print_length: PrintCountSetting = PRINT_LENGTH,<EOL>print_level: PrintCountSetting = PRINT_LEVEL,<EOL>print_meta: bool = PRINT_META,<EOL>print_readably: bool = PRINT_READABLY,<EOL>) -> str:

kwargs = {<EOL>"<STR_LIT>": human_readable,<EOL>"<STR_LIT>": print_dup,<EOL>"<STR_LIT>": print_length,<EOL>"<STR_LIT>": print_level,<EOL>"<STR_LIT>": print_meta,<EOL>"<STR_LIT>": print_readably,<EOL>}<EOL>if isinstance(o, bool):<EOL><INDENT>return _lrepr_bool(o)<EOL><DEDENT>elif o is None:<EOL><INDENT>return _lrepr_nil(o)<EOL><DEDENT>elif isinstance(o, str):<EOL><INDENT>return _lrepr_str(<EOL>o, human_readable=human_readable, print_readably=print_readably<EOL>)<EOL><DEDENT>elif isinstance(o, dict):<EOL><INDENT>return _lrepr_py_dict(o, **kwargs)<EOL><DEDENT>elif isinstance(o, list):<EOL><INDENT>return _lrepr_py_list(o, **kwargs)<EOL><DEDENT>elif isinstance(o, set):<EOL><INDENT>return _lrepr_py_set(o, **kwargs)<EOL><DEDENT>elif isinstance(o, tuple):<EOL><INDENT>return _lrepr_py_tuple(o, **kwargs)<EOL><DEDENT>elif isinstance(o, complex):<EOL><INDENT>return _lrepr_complex(o)<EOL><DEDENT>elif isinstance(o, datetime.datetime):<EOL><INDENT>return _lrepr_datetime(o)<EOL><DEDENT>elif isinstance(o, Decimal):<EOL><INDENT>return _lrepr_decimal(o, print_dup=print_dup)<EOL><DEDENT>elif isinstance(o, Fraction):<EOL><INDENT>return _lrepr_fraction(o)<EOL><DEDENT>elif isinstance(o, Pattern):<EOL><INDENT>return _lrepr_pattern(o)<EOL><DEDENT>elif isinstance(o, uuid.UUID):<EOL><INDENT>return _lrepr_uuid(o)<EOL><DEDENT>else:<EOL><INDENT>return repr(o)<EOL><DEDENT>

Fallback function for lrepr for subclasses of standard types.

    The singledispatch used for standard lrepr dispatches using an exact
    type match on the first argument, so we will only hit this function
    for subclasses of common Python types like strings or lists.


def s(*members: T, meta=None) -> Set[T]:

return Set(pset(members), meta=meta)<EOL>


def eval_stream(stream, ctx: compiler.CompilerContext, module: types.ModuleType):

last = None<EOL>for form in reader.read(stream, resolver=runtime.resolve_alias):<EOL><INDENT>last = compiler.compile_and_exec_form(form, ctx, module)<EOL><DEDENT>return last<EOL>

Evaluate the forms in stdin into a Python module AST node.


def eval_str(s: str, ctx: compiler.CompilerContext, module: types.ModuleType, eof: Any):

last = eof<EOL>for form in reader.read_str(s, resolver=runtime.resolve_alias, eof=eof):<EOL><INDENT>last = compiler.compile_and_exec_form(form, ctx, module)<EOL><DEDENT>return last<EOL>

Evaluate the forms in a string into a Python module AST node.


runtime.init_ns_var()<EOL>runtime.bootstrap()<EOL>importer.hook_imports()<EOL>importlib.import_module("<STR_LIT>")<EOL>

Initialize the runtime environment for evaluation.


_reset_collected_tests()<EOL>filename = self.fspath.basename<EOL>self.fspath.pyimport()<EOL>ns = _current_ns()<EOL>tests = _collected_tests()<EOL>assert tests is not None, "<STR_LIT>"<EOL>for test in tests:<EOL><INDENT>f: TestFunction = test.value<EOL>yield BasilispTestItem(test.name.name, self, f, ns, filename)<EOL><DEDENT>

Collect all of the tests in the namespace (module) given.

        Basilisp's test runner imports the namespace which will (as a side
        effect) collect all of the test functions in a namespace (represented
        by `deftest` forms in Basilisp) into an atom in `basilisp.test`.
        BasilispFile.collect fetches those test functions and generates
        BasilispTestItems for PyTest to run the tests.


var = Maybe(runtime.Var.find(_CURRENT_NS_SYM)).or_else_raise(<EOL>lambda: runtime.RuntimeException(f"<STR_LIT>")<EOL>)<EOL>ns = var.value.deref()<EOL>return ns.name<EOL>

Fetch the current namespace from basilisp.test/current-ns.


if isinstance(excinfo.value, TestFailuresInfo):<EOL><INDENT>exc = excinfo.value<EOL>failures = exc.data.entry(_FAILURES_KW)<EOL>messages = []<EOL>for details in failures:<EOL><INDENT>type_ = details.entry(_TYPE_KW)<EOL>if type_ == _FAILURE_KW:<EOL><INDENT>messages.append(self._failure_msg(details))<EOL><DEDENT>elif type_ == _ERROR_KW:<EOL><INDENT>exc = details.entry(_ACTUAL_KW)<EOL>line = details.entry(_LINE_KW)<EOL>messages.append(self._error_msg(exc, line=line))<EOL><DEDENT>else:<EOL><INDENT>assert False, "<STR_LIT>"<EOL><DEDENT><DEDENT>return "<STR_LIT>".join(messages)<EOL><DEDENT>elif isinstance(excinfo.value, Exception):<EOL><INDENT>return self._error_msg(excinfo.value)<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Representation function called when self.runtest() raises an
        exception.


def get_interaction_energy(ampal_objs, ff=None, assign_ff=True):

if ff is None:<EOL><INDENT>ff = FORCE_FIELDS['<STR_LIT>']<EOL><DEDENT>if assign_ff:<EOL><INDENT>for ampal_obj in ampal_objs:<EOL><INDENT>assign_force_field(ampal_obj, ff)<EOL><DEDENT><DEDENT>interactions = find_inter_ampal(ampal_objs, ff.distance_cutoff)<EOL>buff_score = score_interactions(interactions, ff)<EOL>return buff_score<EOL>

Calculates the interaction energy between AMPAL objects.

    Parameters
    ----------
    ampal_objs: [AMPAL Object]
        A list of any AMPAL objects with `get_atoms` methods.
    ff: BuffForceField, optional
        The force field to be used for scoring. If no force field is
        provided then the most current version of the BUDE force field
        will be used.
    assign_ff: bool, optional
        If true, then force field assignment on the AMPAL object will be
        will be updated.

    Returns
    -------
    BUFF_score: BUFFScore
        A BUFFScore object with information about each of the interactions and
        the atoms involved.


max_rad = <NUM_LIT:0><EOL>max_npnp = <NUM_LIT:0><EOL>for res, _ in self.items():<EOL><INDENT>if res != '<STR_LIT>':<EOL><INDENT>for _, ff_params in self[res].items():<EOL><INDENT>if max_rad < ff_params[<NUM_LIT:1>]:<EOL><INDENT>max_rad = ff_params[<NUM_LIT:1>]<EOL><DEDENT>if max_npnp < ff_params[<NUM_LIT:4>]:<EOL><INDENT>max_npnp = ff_params[<NUM_LIT:4>]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return max_rad, max_npnp<EOL>

Finds the maximum radius and npnp in the force field.

        Returns
        -------
        (max_rad, max_npnp): (float, float)
            Maximum radius and npnp distance in the loaded force field.


if hasattr(ampal_obj, '<STR_LIT>'):<EOL><INDENT>atoms = ampal_obj.get_atoms(ligands=True, inc_alt_states=True)<EOL><DEDENT>else:<EOL><INDENT>atoms = ampal_obj.get_atoms(inc_alt_states=True)<EOL><DEDENT>for atom in atoms:<EOL><INDENT>w_str = None<EOL>a_ff_id = None<EOL>if atom.element == '<STR_LIT:H>':<EOL><INDENT>continue<EOL><DEDENT>elif atom.parent.mol_code.upper() in ff:<EOL><INDENT>if atom.res_label.upper() in ff[atom.parent.mol_code]:<EOL><INDENT>a_ff_id = (atom.parent.mol_code.upper(),<EOL>atom.res_label.upper())<EOL><DEDENT>elif atom.res_label.upper() in ff['<STR_LIT>']:<EOL><INDENT>a_ff_id = ('<STR_LIT>', atom.res_label.upper())<EOL><DEDENT>else:<EOL><INDENT>w_str = ('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>').format(<EOL>atom.res_label, atom.parent.mol_code)<EOL><DEDENT><DEDENT>elif atom.res_label.upper() in ff['<STR_LIT>']:<EOL><INDENT>a_ff_id = ('<STR_LIT>', atom.res_label.upper())<EOL><DEDENT>else:<EOL><INDENT>w_str = ('<STR_LIT>'<EOL>'<STR_LIT>').format(<EOL>atom.res_label, atom.parent.mol_code)<EOL><DEDENT>if w_str:<EOL><INDENT>warnings.warn(w_str, NotParameterisedWarning)<EOL><DEDENT>atom.tags['<STR_LIT>'] = a_ff_id<EOL><DEDENT>return<EOL>

Assigns force field parameters to Atoms in the AMPAL object.

    Parameters
    ----------
    ampal_obj : AMPAL Object
        Any AMPAL object with a `get_atoms` method.
    ff: BuffForceField
        The force field to be used for scoring.


if inspect.ismethod(meth):<EOL><INDENT>if sys.version_info < (<NUM_LIT:3>,<NUM_LIT:0>):<EOL><INDENT>return meth.im_class if meth.im_self is None else meth.im_self<EOL><DEDENT>else:<EOL><INDENT>return meth.__self__<EOL><DEDENT><DEDENT>

Returns the instance owning the supplied instancemethod or
the class owning the supplied classmethod.


objs = []<EOL>for k, obj in objlist:<EOL><INDENT>if hasattr(k, '<STR_LIT>'):<EOL><INDENT>k = k.__name__<EOL><DEDENT>else:<EOL><INDENT>k = as_unicode(k)<EOL><DEDENT>objs.append((k, obj))<EOL><DEDENT>return objs<EOL>

Given a list of objects, returns a dictionary mapping from
string name for the object to the object itself.


target = obj.ref['<STR_LIT:id>']<EOL>load_mime = '<STR_LIT>'<EOL>exec_mime = '<STR_LIT>'<EOL>bokeh_script, bokeh_div, _ = bokeh.embed.notebook.notebook_content(obj, comm.id)<EOL>publish_display_data(data={'<STR_LIT>': encode_utf8(bokeh_div)})<EOL>JS = '<STR_LIT:\n>'.join([PYVIZ_PROXY, JupyterCommManager.js_manager])<EOL>publish_display_data(data={load_mime: JS, '<STR_LIT>': JS})<EOL>msg_handler = bokeh_msg_handler.format(plot_id=target)<EOL>comm_js = comm.js_template.format(plot_id=target, comm_id=comm.id, msg_handler=msg_handler)<EOL>bokeh_js = '<STR_LIT:\n>'.join([comm_js, bokeh_script])<EOL>publish_display_data(data={exec_mime: '<STR_LIT>', '<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': bokeh_js},<EOL>metadata={exec_mime: {'<STR_LIT:id>': target}})<EOL>

Displays bokeh output inside a notebook.


def copy(self, obj_id, folder_id, move=False):

if folder_id.startswith('<STR_LIT>'):<EOL><INDENT>log.info( '<STR_LIT>'<EOL>'<STR_LIT>' )<EOL>folder_id = self.info(folder_id)['<STR_LIT:id>']<EOL><DEDENT>return super(OneDriveAPI, self).copy(obj_id, folder_id, move=move)<EOL>

Copy specified file (object) to a folder.
                Note that folders cannot be copied, this is an API limitation.


def put( self, path_or_tuple, folder_id='<STR_LIT>',<EOL>overwrite=None, downsize=None, bits_api_fallback=True ):

api_overwrite = self._translate_api_flag(overwrite, '<STR_LIT>', ['<STR_LIT>'])<EOL>api_downsize = self._translate_api_flag(downsize, '<STR_LIT>')<EOL>name, src = self._process_upload_source(path_or_tuple)<EOL>if not isinstance(bits_api_fallback, (int, float, long)):<EOL><INDENT>bits_api_fallback = bool(bits_api_fallback)<EOL><DEDENT>if bits_api_fallback is not False:<EOL><INDENT>if bits_api_fallback is True: bits_api_fallback = self.api_put_max_bytes<EOL>src.seek(<NUM_LIT:0>, os.SEEK_END)<EOL>if src.tell() >= bits_api_fallback:<EOL><INDENT>if bits_api_fallback > <NUM_LIT:0>: <EOL><INDENT>log.info(<EOL>'<STR_LIT>',<EOL>*((float(v) / <NUM_LIT:2>**<NUM_LIT:20>) for v in [src.tell(), bits_api_fallback]) )<EOL><DEDENT>if overwrite is not None and api_overwrite != '<STR_LIT:true>':<EOL><INDENT>raise NoAPISupportError( '<STR_LIT>'<EOL>'<STR_LIT>'.format(overwrite) )<EOL><DEDENT>if downsize is not None:<EOL><INDENT>log.info( '<STR_LIT>'<EOL>'<STR_LIT>', downsize )<EOL><DEDENT>file_id = self.put_bits(path_or_tuple, folder_id=folder_id) <EOL>return self.info(file_id)<EOL><DEDENT><DEDENT>return self( self._api_url_join(folder_id, '<STR_LIT>', name),<EOL>dict(overwrite=api_overwrite, downsize_photo_uploads=api_downsize),<EOL>data=src, method='<STR_LIT>', auth_header=True )<EOL>

Upload a file (object), possibly overwriting (default behavior)
                        a file with the same "name" attribute, if it exists.

                First argument can be either path to a local file or tuple
                        of "(name, file)", where "file" can be either a file-like object
                        or just a string of bytes.

                overwrite option can be set to False to allow two identically-named
                        files or "ChooseNewName" to let OneDrive derive some similar
                        unique name. Behavior of this option mimics underlying API.

                downsize is a true/false API flag, similar to overwrite.

                bits_api_fallback can be either True/False or an integer (number of
                        bytes), and determines whether method will fall back to using BITS API
                        (as implemented by "put_bits" method) for large files. Default "True"
                        (bool) value will use non-BITS file size limit (api_put_max_bytes, ~100 MiB)
                        as a fallback threshold, passing False will force using single-request uploads.


return op.itemgetter('<STR_LIT>', '<STR_LIT>')(super(OneDriveAPI, self).get_quota())<EOL>

Return tuple of (bytes_available, bytes_quota).


url = urlparse.urlparse(url)<EOL>url_qs = dict(it.chain.from_iterable(<EOL>urlparse.parse_qsl(v) for v in [url.query, url.fragment] ))<EOL>if url_qs.get('<STR_LIT:error>'):<EOL><INDENT>raise APIAuthError(<EOL>'<STR_LIT>'.format(url_qs['<STR_LIT:error>'], url_qs.get('<STR_LIT>')) )<EOL><DEDENT>self.auth_code = url_qs['<STR_LIT:code>']<EOL>return self.auth_code<EOL>

Process tokens and errors from redirect_uri.


return self(obj_id)<EOL>

Return metadata of a specified object.
                See http://msdn.microsoft.com/en-us/library/live/hh243648.aspx
                        for the list and description of metadata keys for each object type.


return self(obj_id, method='<STR_LIT>', data=data, auth_header=True)<EOL>

Update metadata with of a specified object.
                See http://msdn.microsoft.com/en-us/library/live/hh243648.aspx
                        for the list of RW keys for each object type.