def grab(bbox=None, childprocess=None, backend=None):

if childprocess is None:<EOL><INDENT>childprocess = childprocess_default_value()<EOL><DEDENT>return _grab(<EOL>to_file=False, childprocess=childprocess, backend=backend, bbox=bbox)<EOL>

Copy the contents of the screen to PIL image memory.

    :param bbox: optional bounding box (x1,y1,x2,y2)
    :param childprocess: pyscreenshot can cause an error,
            if it is used on more different virtual displays
            and back-end is not in different process.
            Some back-ends are always different processes: scrot, imagemagick
            The default is False if the program was started inside IDLE,
            otherwise it is True.
    :param backend: back-end can be forced if set (examples:scrot, wx,..),
                    otherwise back-end is automatic


def grab_to_file(filename, childprocess=None, backend=None):

if childprocess is None:<EOL><INDENT>childprocess = childprocess_default_value()<EOL><DEDENT>return _grab(to_file=True, childprocess=childprocess,<EOL>backend=backend, filename=filename)<EOL>

Copy the contents of the screen to a file. Internal function! Use
    PIL.Image.save() for saving image to file.

    :param filename: file for saving
    :param childprocess: see :py:func:`grab`
    :param backend: see :py:func:`grab`


return Loader().all_names<EOL>

Back-end names as a list.

    :return: back-ends as string list


if childprocess is None:<EOL><INDENT>childprocess = childprocess_default_value()<EOL><DEDENT>if not childprocess:<EOL><INDENT>return _backend_version(backend)<EOL><DEDENT>else:<EOL><INDENT>return run_in_childprocess(_backend_version, None, backend)<EOL><DEDENT>

Back-end version.

    :param backend: back-end (examples:scrot, wx,..)
    :param childprocess: see :py:func:`grab`
    :return: version as string


idle = '<STR_LIT>' in sys.modules<EOL>if idle:<EOL><INDENT>log.debug('<STR_LIT>')<EOL><DEDENT>return idle<EOL>

True if program was started inside IDLE.

    The implementation is a HACK, because there is no correct solution.


if not isinstance(values, Iterable) or isinstance(values, (str, bytes)):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if isinstance(nb_class, float) and int(nb_class) == nb_class:<EOL><INDENT>nb_class = int(nb_class)<EOL><DEDENT>if not isinstance(nb_class, int):<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>.format(type(nb_class)))<EOL><DEDENT>nb_values = len(values)<EOL>if np and isinstance(values, np.ndarray):<EOL><INDENT>values = values[np.argwhere(np.isfinite(values)).reshape(-<NUM_LIT:1>)]<EOL><DEDENT>else:<EOL><INDENT>values = [i for i in values if isfinite(i)]<EOL><DEDENT>if len(values) != nb_values:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL>nb_values = len(values)<EOL><DEDENT>if nb_class >= nb_values or nb_class < <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return jenks._jenks_breaks(values, nb_class)<EOL>

Compute jenks natural breaks on a sequence of `values`, given `nb_class`,
the number of desired class.

Parameters
----------
values : array-like
    The Iterable sequence of numbers (integer/float) to be used.
nb_class : int
    The desired number of class (as some other functions requests
    a `k` value, `nb_class` is like `k` + 1). Have to be lesser than
    the length of `values` and greater than 2.

Returns
-------
breaks : tuple of floats
    The computed break values, including minimum and maximum, in order
    to have all the bounds for building `nb_class` class,
    so the returned tuple has a length of `nb_class` + 1.

Examples
--------
Using nb_class = 3, expecting 4 break values , including min and max :

>>> jenks_breaks(
        [1.3, 7.1, 7.3, 2.3, 3.9, 4.1, 7.8, 1.2, 4.3, 7.3, 5.0, 4.3],
        nb_class = 3)  # Should output (1.2, 2.3, 5.0, 7.8)


length = len(self.look_ahead)<EOL>if length <= i:<EOL><INDENT>try:<EOL><INDENT>self.look_ahead.extend([next(self.iterable)<EOL>for _ in range(length, i + <NUM_LIT:1>)])<EOL><DEDENT>except StopIteration:<EOL><INDENT>return self.default<EOL><DEDENT><DEDENT>self.value = self.look_ahead[i]<EOL>return self.value<EOL>

Look ahead of the iterable by some number of values with advancing
        past them.

        If the requested look ahead is past the end of the iterable then None is
        returned.


self.markers.append(list())<EOL>


marker = self.markers.pop()<EOL>if reset:<EOL><INDENT>marker.extend(self.look_ahead)<EOL>self.look_ahead = marker<EOL><DEDENT>elif self.markers:<EOL><INDENT>self.markers[-<NUM_LIT:1>].extend(marker)<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT>

Pop a marker off of the marker stack. If reset is True then the
        iterator will be returned to the state it was in before the
        corresponding call to push_marker().


try:<EOL><INDENT>self.value = self.list[self.marker + i]<EOL><DEDENT>except IndexError:<EOL><INDENT>return self.default<EOL><DEDENT>return self.value<EOL>


self.saved_markers.append(self.marker)<EOL>


saved = self.saved_markers.pop()<EOL>if reset:<EOL><INDENT>self.marker = saved<EOL><DEDENT>elif self.saved_markers:<EOL><INDENT>self.saved_markers[-<NUM_LIT:1>] = saved<EOL><DEDENT>


return (isinstance(self.tokens.look(i), Annotation)<EOL>and not self.tokens.look(i + <NUM_LIT:1>).value == '<STR_LIT>')<EOL>

Returns true if the position is the start of an annotation application
        (as opposed to an annotation declaration)


return (isinstance(self.tokens.look(i), Annotation)<EOL>and self.tokens.look(i + <NUM_LIT:1>).value == '<STR_LIT>')<EOL>


template = """<STR_LIT>"""<EOL>return template % content_to_add<EOL>

returns an example java class with the
        given content_to_add contained within a method.


def filter_type_in_method(clazz, the_type, method_name):

for path, node in clazz.filter(the_type):<EOL><INDENT>for p in reversed(path):<EOL><INDENT>if isinstance(p, tree.MethodDeclaration):<EOL><INDENT>if p.name == method_name:<EOL><INDENT>yield path, node<EOL><DEDENT><DEDENT><DEDENT><DEDENT>

yields the result of filtering the given class for the given
        type inside the given method identified by its name.


def assert_contains_lambda_expression_in_m(<EOL>self, clazz, method_name='<STR_LIT>'):

matches = list(filter_type_in_method(<EOL>clazz, tree.LambdaExpression, method_name))<EOL>if not matches:<EOL><INDENT>self.fail('<STR_LIT>')<EOL><DEDENT>return matches<EOL>

asserts that the given tree contains a method with the supplied
            method name containing a lambda expression.


def assert_contains_method_reference_expression_in_m(<EOL>self, clazz, method_name='<STR_LIT>'):

matches = list(filter_type_in_method(<EOL>clazz, tree.MethodReference, method_name))<EOL>if not matches:<EOL><INDENT>self.fail('<STR_LIT>')<EOL><DEDENT>return matches<EOL>

asserts that the given class contains a method with the supplied
            method name containing a method reference.


try:<EOL><INDENT>BLOCKSIZE = <NUM_LIT><EOL>hasher = hashlib.sha1()<EOL>with io.open(a_file, "<STR_LIT:rb>") as fh:<EOL><INDENT>buf = fh.read(BLOCKSIZE)<EOL>while len(buf) > <NUM_LIT:0>:<EOL><INDENT>hasher.update(buf)<EOL>buf = fh.read(BLOCKSIZE)<EOL><DEDENT><DEDENT>the_hash = hasher.hexdigest()<EOL><DEDENT>except IOError:<EOL><INDENT>errmes = "<STR_LIT>".format(a_file)<EOL>sys.stdout.write(errmes)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>except:<EOL><INDENT>errmes = "<STR_LIT>"<EOL>sys.stdout.write(errmes)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>return the_hash<EOL>

Returns sha1 hash of the file supplied as an argument


sprint = settings["<STR_LIT>"]<EOL>error = settings["<STR_LIT:error>"]<EOL>sprint("<STR_LIT>",<EOL>level="<STR_LIT>")<EOL>if not from_store or '<STR_LIT>' not in from_store:<EOL><INDENT>errmes = ["<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>"]<EOL>errmes = "<STR_LIT:U+0020>".join(errmes)<EOL>error(errmes)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>

This function gives us the option to emit errors or warnings
after sake upgrades


if settings:<EOL><INDENT>error = settings["<STR_LIT:error>"]<EOL><DEDENT>else:<EOL><INDENT>error = ERROR_FN<EOL><DEDENT>try:<EOL><INDENT>BLOCKSIZE = <NUM_LIT><EOL>hasher = hashlib.sha1()<EOL>with io.open(a_file, "<STR_LIT:rb>") as fh:<EOL><INDENT>buf = fh.read(BLOCKSIZE)<EOL>while len(buf) > <NUM_LIT:0>:<EOL><INDENT>hasher.update(buf)<EOL>buf = fh.read(BLOCKSIZE)<EOL><DEDENT><DEDENT>the_hash = hasher.hexdigest()<EOL><DEDENT>except IOError:<EOL><INDENT>errmes = "<STR_LIT>".format(a_file)<EOL>error(errmes)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>except:<EOL><INDENT>errmes = "<STR_LIT>"<EOL>error(errmes)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>return the_hash<EOL>


if sys.version_info[<NUM_LIT:0>] < <NUM_LIT:3>:<EOL><INDENT>fn_open = open<EOL><DEDENT>else:<EOL><INDENT>fn_open = io.open<EOL><DEDENT>with fn_open("<STR_LIT>", "<STR_LIT:w>") as fh:<EOL><INDENT>fh.write("<STR_LIT>")<EOL>fh.write('<STR_LIT>'.format(constants.VERSION))<EOL>if sha_dict:<EOL><INDENT>fh.write(yaml.dump(sha_dict))<EOL><DEDENT>fh.write("<STR_LIT>")<EOL><DEDENT>

Writes a sha1 dictionary stored in memory to
the .shastore file


global ERROR_FN<EOL>sprint = settings["<STR_LIT>"]<EOL>error = settings["<STR_LIT:error>"]<EOL>ERROR_FN = error<EOL>sha_dict = {}<EOL>all_files = []<EOL>for target in G.nodes(data=True):<EOL><INDENT>sprint("<STR_LIT>".format(target[<NUM_LIT:0>]),<EOL>level="<STR_LIT>")<EOL>if '<STR_LIT>' in target[<NUM_LIT:1>]:<EOL><INDENT>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>deplist = []<EOL>for dep in target[<NUM_LIT:1>]['<STR_LIT>']:<EOL><INDENT>glist = glob.glob(dep)<EOL>if glist:<EOL><INDENT>for oneglob in glist:<EOL><INDENT>deplist.append(oneglob)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>deplist.append(dep)<EOL><DEDENT><DEDENT>target[<NUM_LIT:1>]['<STR_LIT>'] = list(deplist)<EOL>for dep in target[<NUM_LIT:1>]['<STR_LIT>']:<EOL><INDENT>sprint("<STR_LIT>".format(dep), level="<STR_LIT>")<EOL>all_files.append(dep)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in target[<NUM_LIT:1>]:<EOL><INDENT>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>for out in acts.get_all_outputs(target[<NUM_LIT:1>]):<EOL><INDENT>sprint("<STR_LIT>".format(out), level="<STR_LIT>")<EOL>all_files.append(out)<EOL><DEDENT><DEDENT><DEDENT>if len(all_files):<EOL><INDENT>sha_dict['<STR_LIT>'] = {}<EOL>extant_files = []<EOL>for item in all_files:<EOL><INDENT>if item not in extant_files and os.path.isfile(item):<EOL><INDENT>extant_files.append(item)<EOL><DEDENT><DEDENT>pool = Pool()<EOL>results = pool.map(get_sha, extant_files)<EOL>pool.close()<EOL>pool.join()<EOL>for fn, sha in zip(extant_files, results):<EOL><INDENT>sha_dict['<STR_LIT>'][fn] = {'<STR_LIT>': sha}<EOL><DEDENT>return sha_dict<EOL><DEDENT>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>

Takes sha1 hash of all dependencies and outputs of all targets

Args:
    The graph we are going to build
    The settings dictionary

Returns:
    A dictionary where the keys are the filenames and the
    value is the sha1 hash


def needs_to_run(G, target, in_mem_shas, from_store, settings):

force = settings["<STR_LIT>"]<EOL>sprint = settings["<STR_LIT>"]<EOL>if(force):<EOL><INDENT>sprint("<STR_LIT>".format(target),<EOL>level="<STR_LIT>")<EOL>return True<EOL><DEDENT>node_dict = get_the_node_dict(G, target)<EOL>if '<STR_LIT>' in node_dict:<EOL><INDENT>for output in acts.get_all_outputs(node_dict):<EOL><INDENT>if not os.path.isfile(output):<EOL><INDENT>outstr = "<STR_LIT>"<EOL>sprint(outstr.format(output), level="<STR_LIT>")<EOL>return True<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' not in node_dict:<EOL><INDENT>sprint("<STR_LIT>".format(target),<EOL>level="<STR_LIT>")<EOL>return True<EOL><DEDENT>for dep in node_dict['<STR_LIT>']:<EOL><INDENT>if ('<STR_LIT>' in in_mem_shas and dep not in in_mem_shas['<STR_LIT>'] or<EOL>'<STR_LIT>' not in in_mem_shas):<EOL><INDENT>outstr = "<STR_LIT>"<EOL>sprint(outstr.format(dep), level="<STR_LIT>")<EOL>return True<EOL><DEDENT>now_sha = in_mem_shas['<STR_LIT>'][dep]['<STR_LIT>']<EOL>if ('<STR_LIT>' in from_store and dep not in from_store['<STR_LIT>'] or<EOL>'<STR_LIT>' not in from_store):<EOL><INDENT>outst = "<STR_LIT>"<EOL>sprint(outst.format(dep), level="<STR_LIT>")<EOL>return True<EOL><DEDENT>old_sha = from_store['<STR_LIT>'][dep]['<STR_LIT>']<EOL>if now_sha != old_sha:<EOL><INDENT>outstr = "<STR_LIT>"<EOL>sprint(outstr.format(dep), level="<STR_LIT>")<EOL>return True<EOL><DEDENT><DEDENT>sprint("<STR_LIT>".format(target), level="<STR_LIT>")<EOL>return False<EOL>

Determines if a target needs to run. This can happen in two ways:
(a) If a dependency of the target has changed
(b) If an output of the target is missing

Args:
    The graph we are going to build
    The name of the target
    The dictionary of the current shas held in memory
    The dictionary of the shas from the shastore
    The settings dictionary

Returns:
    True if the target needs to be run
    False if not


sprint = settings["<STR_LIT>"]<EOL>quiet = settings["<STR_LIT>"]<EOL>error = settings["<STR_LIT:error>"]<EOL>enhanced_errors = True<EOL>the_shell = None<EOL>if settings["<STR_LIT>"]:<EOL><INDENT>enhanced_errors = False<EOL><DEDENT>if "<STR_LIT>" in settings:<EOL><INDENT>the_shell = settings["<STR_LIT>"]<EOL><DEDENT>windows_p = sys.platform == "<STR_LIT:win32>"<EOL>STDOUT = None<EOL>STDERR = None<EOL>if quiet:<EOL><INDENT>STDOUT = PIPE<EOL>STDERR = PIPE<EOL><DEDENT>commands = commands.rstrip()<EOL>sprint("<STR_LIT>".format(commands), level="<STR_LIT>")<EOL>if not quiet:<EOL><INDENT>sprint(commands)<EOL><DEDENT>if the_shell:<EOL><INDENT>tmp = shlex.split(the_shell)<EOL>the_shell = tmp[<NUM_LIT:0>]<EOL>tmp = tmp[<NUM_LIT:1>:]<EOL>if enhanced_errors and not windows_p:<EOL><INDENT>tmp.append("<STR_LIT>")<EOL><DEDENT>tmp.append(commands)<EOL>commands = tmp<EOL><DEDENT>else:<EOL><INDENT>if enhanced_errors and not windows_p:<EOL><INDENT>commands = ["<STR_LIT>", commands]<EOL><DEDENT><DEDENT>p = Popen(commands, shell=True, stdout=STDOUT, stderr=STDERR,<EOL>executable=the_shell)<EOL>out, err = p.communicate()<EOL>if p.returncode:<EOL><INDENT>if quiet:<EOL><INDENT>error(err.decode(locale.getpreferredencoding()))<EOL><DEDENT>error("<STR_LIT>")<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>

Runs the commands supplied as an argument
It will exit the program if the commands return a
non-zero code

Args:
    the commands to run
    The settings dictionary


def run_the_target(G, target, settings):

sprint = settings["<STR_LIT>"]<EOL>sprint("<STR_LIT>".format(target))<EOL>the_formula = get_the_node_dict(G, target)["<STR_LIT>"]<EOL>run_commands(the_formula, settings)<EOL>

Wrapper function that sends to commands in a target's 'formula'
to run_commands()

Args:
    The graph we are going to build
    The target to run
    The settings dictionary


for node in G.nodes(data=True):<EOL><INDENT>if node[<NUM_LIT:0>] == name:<EOL><INDENT>return node[<NUM_LIT:1>]<EOL><DEDENT><DEDENT>

Helper function that returns the node data
of the node with the name supplied


parents = []<EOL>for item in list_of_nodes:<EOL><INDENT>anc = G.predecessors(item)<EOL>for one in anc:<EOL><INDENT>parents.append(one)<EOL><DEDENT><DEDENT>return parents<EOL>

Returns a list of nodes that are the parents
from all of the nodes given as an argument.
This is for use in the parallel topo sort


sinks = []<EOL>for node in G:<EOL><INDENT>if not len(list(G.successors(node))):<EOL><INDENT>sinks.append(node)<EOL><DEDENT><DEDENT>return sinks<EOL>

A sink is a node with no children.
This means that this is the end of the line,
and it should be run last in topo sort. This
returns a list of all sinks in a graph


levels = []<EOL>ends = get_sinks(G)<EOL>levels.append(ends)<EOL>while get_direct_ancestors(G, ends):<EOL><INDENT>ends = get_direct_ancestors(G, ends)<EOL>levels.append(ends)<EOL><DEDENT>levels.reverse()<EOL>return levels<EOL>

For the parallel topo sort to work, the targets have
to be executed in layers such that there is no
dependency relationship between any nodes in a layer.
What is returned is a list of lists representing all
the layers, or levels


seen = []<EOL>final = []<EOL>for line in levels:<EOL><INDENT>new_line = []<EOL>for item in line:<EOL><INDENT>if item not in seen:<EOL><INDENT>seen.append(item)<EOL>new_line.append(item)<EOL><DEDENT><DEDENT>final.append(new_line)<EOL><DEDENT>return final<EOL>

There are repeats in the output from get_levels(). We
want only the earliest occurrence (after it's reversed)


levels = get_levels(G)<EOL>return remove_redundancies(levels)<EOL>

Returns a list of list such that the inner lists
can be executed in parallel (no interdependencies)
and the outer lists ought to be run in order to
satisfy dependencies


def parallel_run_these(G, list_of_targets, in_mem_shas, from_store,<EOL>settings, dont_update_shas_of):

verbose = settings["<STR_LIT>"]<EOL>quiet = settings["<STR_LIT>"]<EOL>error = settings["<STR_LIT:error>"]<EOL>sprint = settings["<STR_LIT>"]<EOL>if len(list_of_targets) == <NUM_LIT:1>:<EOL><INDENT>target = list_of_targets[<NUM_LIT:0>]<EOL>sprint("<STR_LIT>".format(target),<EOL>level="<STR_LIT>")<EOL>run_the_target(G, target, settings)<EOL>node_dict = get_the_node_dict(G, target)<EOL>if "<STR_LIT>" in node_dict:<EOL><INDENT>for output in acts.get_all_outputs(node_dict):<EOL><INDENT>if output not in dont_update_shas_of:<EOL><INDENT>in_mem_shas['<STR_LIT>'][output] = {"<STR_LIT>": get_sha(output,<EOL>settings)}<EOL>in_mem_shas[output] = get_sha(output, settings)<EOL>write_shas_to_shastore(in_mem_shas)<EOL><DEDENT><DEDENT><DEDENT>if "<STR_LIT>" in node_dict:<EOL><INDENT>for dep in acts.get_all_dependencies(node_dict):<EOL><INDENT>if dep not in dont_update_shas_of:<EOL><INDENT>in_mem_shas['<STR_LIT>'][dep] = {"<STR_LIT>": get_sha(dep, settings)}<EOL>write_shas_to_shastore(in_mem_shas)<EOL><DEDENT><DEDENT><DEDENT>return True<EOL><DEDENT>a_failure_occurred = False<EOL>out = "<STR_LIT>"<EOL>sprint(out.format("<STR_LIT:U+002CU+0020>".join(list_of_targets)))<EOL>info = [(target, get_the_node_dict(G, target))<EOL>for target in list_of_targets]<EOL>commands = [item[<NUM_LIT:1>]['<STR_LIT>'].rstrip() for item in info]<EOL>if not quiet:<EOL><INDENT>procs = [Popen(command, shell=True) for command in commands]<EOL><DEDENT>else:<EOL><INDENT>procs = [Popen(command, shell=True, stdout=PIPE, stderr=PIPE)<EOL>for command in commands]<EOL><DEDENT>for index, process in enumerate(procs):<EOL><INDENT>if process.wait():<EOL><INDENT>error("<STR_LIT>".format(info[index][<NUM_LIT:0>]))<EOL>a_failure_occurred = True<EOL><DEDENT>else:<EOL><INDENT>if "<STR_LIT>" in info[index][<NUM_LIT:1>]:<EOL><INDENT>for output in acts.get_all_outputs(info[index][<NUM_LIT:1>]):<EOL><INDENT>if output not in dont_update_shas_of:<EOL><INDENT>in_mem_shas['<STR_LIT>'][output] = {"<STR_LIT>": get_sha(output,<EOL>settings)}<EOL>write_shas_to_shastore(in_mem_shas)<EOL><DEDENT><DEDENT><DEDENT>if "<STR_LIT>" in info[index][<NUM_LIT:1>]:<EOL><INDENT>for dep in acts.get_all_dependencies(info[index][<NUM_LIT:1>]):<EOL><INDENT>if dep not in dont_update_shas_of:<EOL><INDENT>in_mem_shas['<STR_LIT>'][dep] = {"<STR_LIT>": get_sha(dep, settings)}<EOL>write_shas_to_shastore(in_mem_shas)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if a_failure_occurred:<EOL><INDENT>error("<STR_LIT>")<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>return True<EOL>

The parallel equivalent of "run_this_target()"
It receives a list of targets to execute in parallel.
Unlike "run_this_target()" it has to update the shas
(in memory and in the store) within the function.
This is because one of the targets may fail but many can
succeed, and those outputs need to be updated

Args:
    G
    A graph
    A list of targets that we need to build in parallel
    The dictionary containing the in-memory sha store
    The dictionary containing the contents of the .shastore file
    The settings dictionary
    A list of outputs to not update shas of


def merge_from_store_and_in_mems(from_store, in_mem_shas, dont_update_shas_of):

if not from_store:<EOL><INDENT>for item in dont_update_shas_of:<EOL><INDENT>if item in in_mem_shas['<STR_LIT>']:<EOL><INDENT>del in_mem_shas['<STR_LIT>'][item]<EOL><DEDENT><DEDENT>return in_mem_shas<EOL><DEDENT>for key in from_store['<STR_LIT>']:<EOL><INDENT>if key not in in_mem_shas['<STR_LIT>'] and key not in dont_update_shas_of:<EOL><INDENT>in_mem_shas['<STR_LIT>'][key] = from_store['<STR_LIT>'][key]<EOL><DEDENT><DEDENT>for item in dont_update_shas_of:<EOL><INDENT>if item in in_mem_shas['<STR_LIT>']:<EOL><INDENT>del in_mem_shas['<STR_LIT>'][item]<EOL><DEDENT><DEDENT>return in_mem_shas<EOL>

If we don't merge the shas from the sha store and if we build a
subgraph, the .shastore will only contain the shas of the files
from the subgraph and the rest of the graph will have to be
rebuilt


def build_this_graph(G, settings, dont_update_shas_of=None):

verbose = settings["<STR_LIT>"]<EOL>quiet = settings["<STR_LIT>"]<EOL>force = settings["<STR_LIT>"]<EOL>recon = settings["<STR_LIT>"]<EOL>parallel = settings["<STR_LIT>"]<EOL>error = settings["<STR_LIT:error>"]<EOL>sprint = settings["<STR_LIT>"]<EOL>if not dont_update_shas_of:<EOL><INDENT>dont_update_shas_of = []<EOL><DEDENT>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>if not nx.is_directed_acyclic_graph(G):<EOL><INDENT>errmes = "<STR_LIT>"<EOL>errmes += "<STR_LIT>"<EOL>errmes += "<STR_LIT>"<EOL>error(errmes)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>in_mem_shas = take_shas_of_all_files(G, settings)<EOL>from_store = {}<EOL>if not os.path.isfile("<STR_LIT>"):<EOL><INDENT>write_shas_to_shastore(in_mem_shas)<EOL>in_mem_shas = {}<EOL>in_mem_shas['<STR_LIT>'] = {}<EOL><DEDENT>with io.open("<STR_LIT>", "<STR_LIT:r>") as fh:<EOL><INDENT>shas_on_disk = fh.read()<EOL><DEDENT>from_store = yaml.load(shas_on_disk)<EOL>check_shastore_version(from_store, settings)<EOL>if not from_store:<EOL><INDENT>write_shas_to_shastore(in_mem_shas)<EOL>in_mem_shas = {}<EOL>in_mem_shas['<STR_LIT>'] = {}<EOL>with io.open("<STR_LIT>", "<STR_LIT:r>") as fh:<EOL><INDENT>shas_on_disk = fh.read()<EOL><DEDENT>from_store = yaml.load(shas_on_disk)<EOL><DEDENT>if parallel:<EOL><INDENT>for line in parallel_sort(G):<EOL><INDENT>line = sorted(line)<EOL>out = "<STR_LIT>"<EOL>sprint(out.format("<STR_LIT:U+002CU+0020>".join(line)), level="<STR_LIT>")<EOL>to_build = []<EOL>for item in line:<EOL><INDENT>if needs_to_run(G, item, in_mem_shas, from_store, settings):<EOL><INDENT>to_build.append(item)<EOL><DEDENT><DEDENT>if to_build:<EOL><INDENT>if recon:<EOL><INDENT>if len(to_build) == <NUM_LIT:1>:<EOL><INDENT>out = "<STR_LIT>"<EOL>sprint(out.format(to_build[<NUM_LIT:0>]))<EOL><DEDENT>else:<EOL><INDENT>out = "<STR_LIT>"<EOL>sprint(out.format("<STR_LIT:U+002CU+0020>".join(to_build)))<EOL><DEDENT>continue<EOL><DEDENT>parallel_run_these(G, to_build, in_mem_shas, from_store,<EOL>settings, dont_update_shas_of)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>targets = []<EOL>for line in parallel_sort(G):<EOL><INDENT>for item in sorted(line):<EOL><INDENT>targets.append(item)<EOL><DEDENT><DEDENT>for target in targets:<EOL><INDENT>outstr = "<STR_LIT>"<EOL>sprint(outstr.format(target), level="<STR_LIT>")<EOL>if needs_to_run(G, target, in_mem_shas, from_store, settings):<EOL><INDENT>if recon:<EOL><INDENT>sprint("<STR_LIT>".format(target))<EOL>continue<EOL><DEDENT>run_the_target(G, target, settings)<EOL>node_dict = get_the_node_dict(G, target)<EOL>if "<STR_LIT>" in node_dict:<EOL><INDENT>for output in acts.get_all_outputs(node_dict):<EOL><INDENT>if output not in dont_update_shas_of:<EOL><INDENT>in_mem_shas['<STR_LIT>'][output] = {"<STR_LIT>": get_sha(output,<EOL>settings)}<EOL>write_shas_to_shastore(in_mem_shas)<EOL><DEDENT><DEDENT><DEDENT>if "<STR_LIT>" in node_dict:<EOL><INDENT>for dep in acts.get_all_dependencies(node_dict):<EOL><INDENT>if dep not in dont_update_shas_of:<EOL><INDENT>in_mem_shas['<STR_LIT>'][dep] = {"<STR_LIT>": get_sha(dep,<EOL>settings)}<EOL>write_shas_to_shastore(in_mem_shas)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if recon:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>in_mem_shas = take_shas_of_all_files(G, settings)<EOL>if in_mem_shas:<EOL><INDENT>in_mem_shas = merge_from_store_and_in_mems(from_store, in_mem_shas,<EOL>dont_update_shas_of)<EOL>write_shas_to_shastore(in_mem_shas)<EOL><DEDENT>sprint("<STR_LIT>", color=True)<EOL>return <NUM_LIT:0><EOL>

This is the master function that performs the building.

Args:
    A graph (often a subgraph)
    The settings dictionary
    An optional list of files to not update the shas of
      (needed when building specific targets)

Returns:
    0 if successful
    UN-success results in a fatal error so it will return 0 or nothing


sprint = settings["<STR_LIT>"]<EOL>error = settings["<STR_LIT:error>"]<EOL>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>if not sakefile:<EOL><INDENT>error("<STR_LIT>")<EOL>return False<EOL><DEDENT>if len(sakefile.keys()) != len(set(sakefile.keys())):<EOL><INDENT>error("<STR_LIT>")<EOL>return False<EOL><DEDENT>for target in sakefile:<EOL><INDENT>if target == "<STR_LIT:all>":<EOL><INDENT>if not check_target_integrity(target, sakefile["<STR_LIT:all>"], all=True):<EOL><INDENT>error("<STR_LIT>")<EOL>return False<EOL><DEDENT>continue<EOL><DEDENT>if "<STR_LIT>" not in sakefile[target]:<EOL><INDENT>if not check_target_integrity(target, sakefile[target],<EOL>meta=True):<EOL><INDENT>errmes = "<STR_LIT>".format(target)<EOL>error(errmes)<EOL>return False<EOL><DEDENT>for atom_target in sakefile[target]:<EOL><INDENT>if atom_target == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>if not check_target_integrity(atom_target,<EOL>sakefile[target][atom_target],<EOL>parent=target):<EOL><INDENT>errmes = "<STR_LIT>".format(<EOL>atom_target)<EOL>error(errmes)<EOL>return False<EOL><DEDENT><DEDENT>continue<EOL><DEDENT>if not check_target_integrity(target, sakefile[target]):<EOL><INDENT>errmes = "<STR_LIT>".format(target)<EOL>error(errmes)<EOL>return False<EOL><DEDENT><DEDENT>return True<EOL>

Checks the format of the sakefile dictionary
to ensure it conforms to specification

Args:
    A dictionary that is the parsed Sakefile (from sake.py)
    The setting dictionary (for print functions)
Returns:
    True if the Sakefile is conformant
    False if not


def check_target_integrity(key, values, meta=False, all=False, parent=None):

<EOL>if all:<EOL><INDENT>if not values:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>return True<EOL><DEDENT>errmes = "<STR_LIT>"<EOL>if meta:<EOL><INDENT>if "<STR_LIT>" not in values:<EOL><INDENT>sys.stderr.write(errmes.format(key))<EOL>return False<EOL><DEDENT>if len(values.keys()) == <NUM_LIT:1>:<EOL><INDENT>sys.stderr.write("<STR_LIT>".format(key))<EOL>return False<EOL><DEDENT>return True<EOL><DEDENT>expected_fields = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>expected_fields = set(expected_fields)<EOL>try:<EOL><INDENT>our_keys_set = set(values.keys())<EOL><DEDENT>except:<EOL><INDENT>sys.stderr.write("<STR_LIT>".format(key))<EOL>sys.stderr.write("<STR_LIT>".format(<EOL>parent))<EOL>sys.stderr.write("<STR_LIT>")<EOL>return False<EOL><DEDENT>ignored_fields = set([field for field in our_keys_setif field.strip().startswith("<STR_LIT>")])<EOL>difference = our_keys_set - expected_fields - ignored_fields<EOL>if difference:<EOL><INDENT>print("<STR_LIT>")<EOL>for item in difference:<EOL><INDENT>print("<STR_LIT>" + item)<EOL><DEDENT><DEDENT>if "<STR_LIT>" not in values:<EOL><INDENT>sys.stderr.write(errmes.format(key))<EOL>return False<EOL><DEDENT>if "<STR_LIT>" not in values:<EOL><INDENT>sys.stderr.write("<STR_LIT>".format(key))<EOL>return False<EOL><DEDENT>return True<EOL>

Checks the integrity of a specific target. Gets called
multiple times from check_integrity()

Args:
    The target name
    The dictionary values of that target
    A boolean representing whether it is a meta-target
    A boolean representing whether it is the "all" target
    A string representing name of parent (default None)

Returns:
    True is the target is conformant
    False if not


verbose = settings["<STR_LIT>"]<EOL>def sprint(message, level=None, color=False):<EOL><INDENT>if level=="<STR_LIT>" and not verbose:<EOL><INDENT>return<EOL><DEDENT>prepend = "<STR_LIT>"<EOL>postfix = "<STR_LIT>"<EOL>if settings["<STR_LIT>"] and color:<EOL><INDENT>prepend = "<STR_LIT>"<EOL>postfix = "<STR_LIT>"<EOL><DEDENT>print("<STR_LIT>".format(prepend, message, postfix))<EOL>sys.stdout.flush()<EOL><DEDENT>def warn(message, level=None, color=True):<EOL><INDENT>if level=="<STR_LIT>" and not verbose:<EOL><INDENT>return<EOL><DEDENT>prepend = "<STR_LIT>"<EOL>postfix = "<STR_LIT>"<EOL>if settings["<STR_LIT>"] and color:<EOL><INDENT>prepend = "<STR_LIT>"<EOL>postfix = "<STR_LIT>"<EOL><DEDENT>print("<STR_LIT>".format(prepend, message, postfix))<EOL>sys.stdout.flush()<EOL><DEDENT>def error(message, level=None, color=True):<EOL><INDENT>if level=="<STR_LIT>" and not verbose:<EOL><INDENT>return<EOL><DEDENT>prepend = "<STR_LIT>"<EOL>postfix = "<STR_LIT>"<EOL>if settings["<STR_LIT>"] and color:<EOL><INDENT>prepend = "<STR_LIT>"<EOL>postfix = "<STR_LIT>"<EOL><DEDENT>print("<STR_LIT>".format(prepend, message, postfix), file=sys.stderr)<EOL>sys.stderr.flush()<EOL><DEDENT>return sprint, warn, error<EOL>

This returns the appropriate print functions
in a tuple
The print function are:
    - sprint - for standard printing
    - warn - for warnings
    - error - for errors
This will all be the same if color is False.

The returned print functions will contain an optional parameter
that specifies the output level (verbose or not). If not verbose,
the print function will ignore the message.


error = settings["<STR_LIT:error>"]<EOL>if settings["<STR_LIT>"]:<EOL><INDENT>custom = settings["<STR_LIT>"]<EOL>if not os.path.isfile(custom):<EOL><INDENT>error("<STR_LIT>", custom)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>return custom<EOL><DEDENT>for name in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>if os.path.isfile(name):<EOL><INDENT>return name<EOL><DEDENT><DEDENT>error("<STR_LIT>")<EOL>sys.exit(<NUM_LIT:1>)<EOL>

Returns the filename of the appropriate sakefile


def clean_path(a_path, force_os=None, force_start=None):

if not force_start:<EOL><INDENT>force_start = os.curdir<EOL><DEDENT>if force_os == "<STR_LIT>":<EOL><INDENT>import ntpath<EOL>return ntpath.relpath(ntpath.normpath(a_path),<EOL>start=force_start)<EOL><DEDENT>if force_os == "<STR_LIT>":<EOL><INDENT>import posixpath<EOL>return posixpath.relpath(posixpath.normpath(a_path),<EOL>start=force_start)<EOL><DEDENT>return os.path.relpath(os.path.normpath(a_path),<EOL>start=force_start)<EOL>

This function is used to normalize the path (of an output or
dependency) and also provide the path in relative form. It is
relative to the current working directory


if '<STR_LIT:U+0020>' in target_name:<EOL><INDENT>return '<STR_LIT>'.format(target_name)<EOL><DEDENT>return target_name<EOL>

This function is used by sake help. Since sakefiles allow
for targets with spaces in them, sake help needs to quote
all targets with spaces. This takes a target name and
quotes it if necessary


full_string = "<STR_LIT>"<EOL>errmes = "<STR_LIT>"<EOL>outerlines = []<EOL>for target in sakefile:<EOL><INDENT>if target == "<STR_LIT:all>":<EOL><INDENT>continue<EOL><DEDENT>middle_lines = []<EOL>if "<STR_LIT>" not in sakefile[target]:<EOL><INDENT>innerstr = "<STR_LIT>".format(escp(target),<EOL>sakefile[target]["<STR_LIT>"])<EOL>inner = []<EOL>for atom_target in sakefile[target]:<EOL><INDENT>if atom_target == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>inner.append("<STR_LIT>".format(escp(atom_target),<EOL>sakefile[target][atom_target]["<STR_LIT>"]))<EOL><DEDENT>if inner:<EOL><INDENT>innerstr += '<STR_LIT:\n>'.join(sorted(inner))<EOL><DEDENT>middle_lines.append(innerstr)<EOL><DEDENT>else:<EOL><INDENT>middle_lines.append("<STR_LIT>".format(escp(target),<EOL>sakefile[target]["<STR_LIT>"]))<EOL><DEDENT>if middle_lines:<EOL><INDENT>outerlines.append('<STR_LIT:\n>'.join(sorted(middle_lines)))<EOL><DEDENT><DEDENT>if outerlines:<EOL><INDENT>full_string += '<STR_LIT:\n>'.join(sorted(outerlines))<EOL><DEDENT>what_clean_does = "<STR_LIT>"<EOL>full_string += "<STR_LIT>".format(what_clean_does)<EOL>what_visual_does = "<STR_LIT>"<EOL>full_string += "<STR_LIT>".format(what_visual_does)<EOL>full_string = re.sub("<STR_LIT>", "<STR_LIT>", full_string)<EOL>return full_string<EOL>

Returns the prettily formatted help strings (for printing)

Args:
    A dictionary that is the parsed Sakefile (from sake.py)

NOTE:
    the list sorting in this function is required for this
    function to be deterministic


macros = {}<EOL>for arg in args:<EOL><INDENT>try:<EOL><INDENT>var, val = arg.split('<STR_LIT:=>', <NUM_LIT:1>)<EOL><DEDENT>except ValueError:<EOL><INDENT>var = arg<EOL>val = '<STR_LIT:1>'<EOL><DEDENT>macros[var] = val<EOL><DEDENT>return macros<EOL>

This parses a list of define argument in the form of -DNAME=VALUE or -DNAME (
which is treated as -DNAME=1).


includes = {}<EOL>result = []<EOL>pattern = re.compile("<STR_LIT>", re.UNICODE)<EOL>ipattern = re.compile("<STR_LIT>", re.UNICODE)<EOL>for line in raw_text.split("<STR_LIT:\n>"):<EOL><INDENT>line = string.Template(line).safe_substitute(macros)<EOL>result.append(line)<EOL>if line.startswith("<STR_LIT>"):<EOL><INDENT>match = pattern.match(line)<EOL>try:<EOL><INDENT>var, opt, val, or_ = match.group(<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:4>)<EOL><DEDENT>except:<EOL><INDENT>raise InvalidMacroError("<STR_LIT>".format(line))<EOL><DEDENT>if or_:<EOL><INDENT>if var not in macros:<EOL><INDENT>raise InvalidMacroError("<STR_LIT>".format(var, or_))<EOL><DEDENT><DEDENT>elif not (opt and var in macros):<EOL><INDENT>macros[var] = val<EOL><DEDENT><DEDENT>elif line.startswith("<STR_LIT>"):<EOL><INDENT>match = ipattern.match(line)<EOL>try:<EOL><INDENT>filename = match.group(<NUM_LIT:1>)<EOL><DEDENT>except:<EOL><INDENT>error("<STR_LIT>".format(line))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>try:<EOL><INDENT>with io.open(filename, '<STR_LIT:r>') as f:<EOL><INDENT>includes[filename] = expand_macros(f.read(), macros)<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>if match.group(<NUM_LIT:2>):<EOL><INDENT>if match.group(<NUM_LIT:2>).startswith('<STR_LIT>'):<EOL><INDENT>sprint(match.group(<NUM_LIT:3>))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>error("<STR_LIT>".format(filename))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return "<STR_LIT:\n>".join(result), includes<EOL>

this gets called before the sakefile is parsed. it looks for
macros defined anywhere in the sakefile (the start of the line
is '#!') and then replaces all occurences of '$variable' with the
value defined in the macro. it then returns the contents of the
file with the macros expanded.


def check_for_dep_in_outputs(dep, verbose, G):

if verbose:<EOL><INDENT>print("<STR_LIT>".format(dep))<EOL><DEDENT>ret_list = []<EOL>for node in G.nodes(data=True):<EOL><INDENT>if "<STR_LIT>" not in node[<NUM_LIT:1>]:<EOL><INDENT>continue<EOL><DEDENT>for out in node[<NUM_LIT:1>]['<STR_LIT>']:<EOL><INDENT>if fnmatch.fnmatch(out, dep):<EOL><INDENT>ret_list.append(node[<NUM_LIT:0>])<EOL>break<EOL><DEDENT><DEDENT><DEDENT>return ret_list<EOL>

Function to help construct_graph() identify dependencies

Args:
    A dependency
    A flag indication verbosity
    A (populated) NetworkX DiGraph

Returns:
    A list of targets that build given dependency


<EOL>ties = []<EOL>dep_dict = {}<EOL>for node in G.nodes(data=True):<EOL><INDENT>if '<STR_LIT>' in node[<NUM_LIT:1>]:<EOL><INDENT>for item in node[<NUM_LIT:1>]['<STR_LIT>']:<EOL><INDENT>if item not in dep_dict:<EOL><INDENT>dep_dict[item] = []<EOL><DEDENT>dep_dict[item].append(node[<NUM_LIT:0>])<EOL><DEDENT><DEDENT><DEDENT>for item in dep_dict:<EOL><INDENT>if len(list(set(dep_dict[item]))) > <NUM_LIT:1>:<EOL><INDENT>ties.append(list(set(dep_dict[item])))<EOL><DEDENT><DEDENT>return ties<EOL>

If you specify a target that shares a dependency with another target,
both targets need to be updated. This is because running one will resolve
the sha mismatch and sake will think that the other one doesn't have to
run. This is called a "tie". This function will find such ties.


my_ties = []<EOL>for original_target in original_targets:<EOL><INDENT>for item in the_ties:<EOL><INDENT>if original_target in item:<EOL><INDENT>for thing in item:<EOL><INDENT>my_ties.append(thing)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>my_ties = list(set(my_ties))<EOL>if my_ties:<EOL><INDENT>ties_message = "<STR_LIT>"<EOL>ties_message += "<STR_LIT>"<EOL>for item in sorted(my_ties):<EOL><INDENT>ties_message += "<STR_LIT>".format(item)<EOL><DEDENT>return list(set(my_ties+original_targets)), ties_message<EOL><DEDENT>return original_targets, "<STR_LIT>"<EOL>

This function gets called when a target is specified to ensure
that all 'tied' targets also get included in the subgraph to
be built


verbose = settings["<STR_LIT>"]<EOL>sprint = settings["<STR_LIT>"]<EOL>G = nx.DiGraph()<EOL>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>for target in sakefile:<EOL><INDENT>if target == "<STR_LIT:all>":<EOL><INDENT>continue<EOL><DEDENT>if "<STR_LIT>" not in sakefile[target]:<EOL><INDENT>for atomtarget in sakefile[target]:<EOL><INDENT>if atomtarget == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>sprint("<STR_LIT>".format(atomtarget), level="<STR_LIT>")<EOL>data_dict = sakefile[target][atomtarget]<EOL>data_dict["<STR_LIT>"] = target<EOL>G.add_node(atomtarget, **data_dict)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>sprint("<STR_LIT>".format(target), level="<STR_LIT>")<EOL>G.add_node(target, **sakefile[target])<EOL><DEDENT><DEDENT>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>for node in G.nodes(data=True):<EOL><INDENT>sprint("<STR_LIT>".format(node[<NUM_LIT:0>]),<EOL>level="<STR_LIT>")<EOL>for k, v in node[<NUM_LIT:1>].items():<EOL><INDENT>if v is None: node[<NUM_LIT:1>][k] = []<EOL><DEDENT>if "<STR_LIT>" in node[<NUM_LIT:1>]:<EOL><INDENT>for index, out in enumerate(node[<NUM_LIT:1>]['<STR_LIT>']):<EOL><INDENT>node[<NUM_LIT:1>]['<STR_LIT>'][index] = clean_path(node[<NUM_LIT:1>]['<STR_LIT>'][index])<EOL><DEDENT><DEDENT>if "<STR_LIT>" not in node[<NUM_LIT:1>]:<EOL><INDENT>continue<EOL><DEDENT>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>connects = []<EOL>for index, dep in enumerate(node[<NUM_LIT:1>]['<STR_LIT>']):<EOL><INDENT>dep = os.path.normpath(dep)<EOL>shrt = "<STR_LIT>"<EOL>node[<NUM_LIT:1>]['<STR_LIT>'][index] = clean_path(node[<NUM_LIT:1>][shrt][index])<EOL><DEDENT><DEDENT>for node in G.nodes(data=True):<EOL><INDENT>connects = []<EOL>if "<STR_LIT>" not in node[<NUM_LIT:1>]:<EOL><INDENT>continue<EOL><DEDENT>for dep in node[<NUM_LIT:1>]['<STR_LIT>']:<EOL><INDENT>matches = check_for_dep_in_outputs(dep, verbose, G)<EOL>if not matches:<EOL><INDENT>continue<EOL><DEDENT>for match in matches:<EOL><INDENT>sprint("<STR_LIT>".format(match), level="<STR_LIT>")<EOL>connects.append(match)<EOL><DEDENT><DEDENT>if connects:<EOL><INDENT>for connect in connects:<EOL><INDENT>G.add_edge(connect, node[<NUM_LIT:0>])<EOL><DEDENT><DEDENT><DEDENT>return G<EOL>

Takes the sakefile dictionary and builds a NetworkX graph

Args:
    A dictionary that is the parsed Sakefile (from sake.py)
    The settings dictionary

Returns:
    A NetworkX graph


outlist = []<EOL>for item in node_dict['<STR_LIT>']:<EOL><INDENT>glist = glob.glob(item)<EOL>if glist:<EOL><INDENT>for oneglob in glist:<EOL><INDENT>outlist.append(oneglob)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>outlist.append(item)<EOL><DEDENT><DEDENT>return outlist<EOL>

This function takes a node dictionary and returns a list of
the node's output files. Some of the entries in the 'output'
attribute may be globs, and without this function, sake won't
know how to handle that. This will unglob all globs and return
the true list of *all* outputs.


deplist = []<EOL>for item in node_dict['<STR_LIT>']:<EOL><INDENT>glist = glob.glob(item)<EOL>if glist:<EOL><INDENT>for oneglob in glist:<EOL><INDENT>deplist.append(oneglob)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>deplist.append(item)<EOL><DEDENT><DEDENT>return deplist<EOL>


quiet = settings["<STR_LIT>"]<EOL>recon = settings["<STR_LIT>"]<EOL>sprint = settings["<STR_LIT>"]<EOL>error = settings["<STR_LIT:error>"]<EOL>all_outputs = []<EOL>for node in G.nodes(data=True):<EOL><INDENT>if "<STR_LIT>" in node[<NUM_LIT:1>]:<EOL><INDENT>for item in get_all_outputs(node[<NUM_LIT:1>]):<EOL><INDENT>all_outputs.append(item)<EOL><DEDENT><DEDENT><DEDENT>all_outputs.append("<STR_LIT>")<EOL>retcode = <NUM_LIT:0><EOL>for item in sorted(all_outputs):<EOL><INDENT>if os.path.isfile(item):<EOL><INDENT>if recon:<EOL><INDENT>sprint("<STR_LIT>".format(item))<EOL>continue<EOL><DEDENT>sprint("<STR_LIT>", level="<STR_LIT>")<EOL>try:<EOL><INDENT>os.remove(item)<EOL>sprint("<STR_LIT>", level="<STR_LIT>")<EOL><DEDENT>except:<EOL><INDENT>errmes = "<STR_LIT>"<EOL>error(errmes.format(item))<EOL>retcode = <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>if not retcode and not recon:<EOL><INDENT>sprint("<STR_LIT>", color=True)<EOL><DEDENT>return retcode<EOL>

Removes all the output files from all targets. Takes
the graph as the only argument

Args:
    The networkx graph object
    The settings dictionary

Returns:
    0 if successful
    1 if removing even one file failed


with io.open(filename, "<STR_LIT:w>") as fh:<EOL><INDENT>fh.write("<STR_LIT>")<EOL>edge_list = G.edges()<EOL>node_list = set(G.nodes())<EOL>if edge_list:<EOL><INDENT>for edge in sorted(edge_list):<EOL><INDENT>source, targ = edge<EOL>node_list = node_list - set(source)<EOL>node_list = node_list - set(targ)<EOL>line = '<STR_LIT>'<EOL>fh.write(line.format(source, targ))<EOL><DEDENT><DEDENT>if node_list:<EOL><INDENT>for node in sorted(node_list):<EOL><INDENT>line = '<STR_LIT>'.format(node)<EOL>fh.write(line)<EOL><DEDENT><DEDENT>fh.write("<STR_LIT:}>")<EOL><DEDENT>

Writes the graph G in dot file format for graphviz visualization.

Args:
    a Networkx graph
    A filename to name the dot files


def visualize(G, settings, filename="<STR_LIT>", no_graphviz=False):

error = settings["<STR_LIT:error>"]<EOL>if no_graphviz:<EOL><INDENT>write_dot_file(G, filename)<EOL>return <NUM_LIT:0><EOL><DEDENT>write_dot_file(G, "<STR_LIT>")<EOL>renderer = "<STR_LIT>"<EOL>if re.search("<STR_LIT>", filename, re.IGNORECASE):<EOL><INDENT>renderer = "<STR_LIT>"<EOL><DEDENT>elif re.search("<STR_LIT>", filename, re.IGNORECASE):<EOL><INDENT>renderer = "<STR_LIT>"<EOL><DEDENT>elif re.search("<STR_LIT>", filename, re.IGNORECASE):<EOL><INDENT>renderer = "<STR_LIT>"<EOL><DEDENT>elif re.search("<STR_LIT>", filename, re.IGNORECASE):<EOL><INDENT>renderer = "<STR_LIT>"<EOL><DEDENT>elif re.search("<STR_LIT>", filename, re.IGNORECASE):<EOL><INDENT>renderer = "<STR_LIT>"<EOL><DEDENT>elif re.search("<STR_LIT>", filename, re.IGNORECASE):<EOL><INDENT>renderer = "<STR_LIT>"<EOL><DEDENT>elif re.search("<STR_LIT>", filename, re.IGNORECASE):<EOL><INDENT>renderer = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>renderer = "<STR_LIT>"<EOL>filename += "<STR_LIT>"<EOL><DEDENT>command = "<STR_LIT>".format(renderer, filename)<EOL>p = Popen(command, shell=True)<EOL>p.communicate()<EOL>if p.returncode:<EOL><INDENT>errmes = "<STR_LIT>"<EOL>os.remove("<STR_LIT>")<EOL>error(errmes)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>os.remove("<STR_LIT>")<EOL>return <NUM_LIT:0><EOL>

Uses networkX to draw a graphviz dot file either (a) calls the
graphviz command "dot" to turn it into a SVG and remove the
dotfile (default), or (b) if no_graphviz is True, just output
the graphviz dot file

Args:
    a NetworkX DiGraph
    the settings dictionary
    a filename (a default is provided
    a flag indicating whether graphviz should *not* be called

Returns:
    0 if everything worked
    will cause fatal error on failure


schema_path = os.path.join(os.path.dirname(__file__),<EOL>'<STR_LIT>')<EOL>with open(schema_path, '<STR_LIT:r>') as jsonfp:<EOL><INDENT>schema = json.load(jsonfp)<EOL><DEDENT>jsonschema.validate(definition, schema)<EOL>assert definition['<STR_LIT>'] in definition['<STR_LIT>'],'<STR_LIT>'<EOL>assert set(definition.get('<STR_LIT>', [])) <= set(definition['<STR_LIT>']),'<STR_LIT>'<EOL>assert set(definition.get('<STR_LIT>', [])) <= set(definition.get('<STR_LIT>', [])),'<STR_LIT>'<EOL>assert set(definition.get('<STR_LIT>', {}).values()) <= set(definition['<STR_LIT>']),'<STR_LIT>'<EOL>

This static method validates a BioMapMapper definition.
It returns None on success and throws an exception otherwise.


pass<EOL>

Validates data with respect to the data definition.


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

Returns a list with all keys which are supported by the mapper.


return self['<STR_LIT:name>']<EOL>


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

Returns the name of the data associated with the mapper.


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


return self.get('<STR_LIT>', {})<EOL>

Returns a mapping from supported keys to official
Miriam namespace ids (as a dictionary).


return self.get('<STR_LIT>', [])<EOL>

Returns a list of supported keys whose values
are scalar and possibly non-unique across data
entries.


return self.get('<STR_LIT>', [])<EOL>

Returns a list of supported keys whose values are
from some kind of (usually more complex) data structure
(a nested dictionary for example), ie whose values
are not strings for arrays of strings. Compound-valued
keys can not be used to map FROM.


return self.get('<STR_LIT>', {})<EOL>

Returns a list of key synonyms (as a dictionary).


return self.get('<STR_LIT>', [])<EOL>

Returns all list-values keys for which it is assured
that for any two values of that key the set of the
entries of that value are disjoint (do not have an
element in common).


return self.get('<STR_LIT>', [])<EOL>

Returns a list of supported keys whose values are
list of strings.


return self._name<EOL>


return self._definition<EOL>


return self.db.get_mapper_data(self.name)<EOL>

Return the entirety of the data as a list.


return [namespace for namespace in self.definition.miriam_mapping]<EOL>

Returns a list of the supported MIRIAM namespaces.


def __call__(self, ID_s, FROM=None, TO=None):

return self.map(ID_s, FROM, TO)<EOL>

A simpler interface to Mapper.map which makes the mapper callable.


def io_mode(ID_s):<EOL><INDENT>'''<STR_LIT>'''<EOL>unlist_return = False<EOL>list_of_lists = False<EOL>if isinstance(ID_s, str):<EOL><INDENT>ID_s = [ID_s]<EOL>unlist_return = True<EOL><DEDENT>elif isinstance(ID_s, list):<EOL><INDENT>if len(ID_s) > <NUM_LIT:0> and isinstance(ID_s[<NUM_LIT:0>], list):<EOL><INDENT>list_of_lists = True<EOL><DEDENT><DEDENT>return ID_s, unlist_return, list_of_lists<EOL><DEDENT>if FROM == TO:<EOL><INDENT>return ID_s<EOL><DEDENT>ID_s, unlist_return, list_of_lists = io_mode(ID_s)<EOL>if list_of_lists:<EOL><INDENT>mapped_ids = [self.map(ID, FROM, TO, target_as_set, no_match_sub) for ID in ID_s]<EOL><DEDENT>else:<EOL><INDENT>mapped_ids = self._map(ID_s, FROM, TO, target_as_set, no_match_sub)<EOL><DEDENT>if unlist_return:<EOL><INDENT>return mapped_ids[<NUM_LIT:0>]<EOL><DEDENT>return Mapping(ID_s, mapped_ids)<EOL>

The main method of this class and the essence of the package.
It allows to "map" stuff.

Args:

    ID_s: Nested lists with strings as leafs (plain strings also possible)
    FROM (str): Origin key for the mapping (default: main key)
    TO (str): Destination key for the mapping (default: main key)
    target_as_set (bool): Whether to summarize the output as a set (removes duplicates)
    no_match_sub: Object representing the status of an ID not being able to be matched
                  (default: None)

Returns:

    Mapping: a mapping object capturing the result of the mapping request


key = self.definition.main_key if key is None else key<EOL>key = self.definition.key_synonyms.get(key, key)<EOL>entries = self._get_all(key)<EOL>if key in self.definition.scalar_nonunique_keys:<EOL><INDENT>return set(entries)<EOL><DEDENT>return entries<EOL>

Returns all data entries for a particular key. Default is the main key.

Args:

    key (str): key whose values to return (default: main key)

Returns:

    List of all data entries for the key


pass<EOL>

Backend-specific implementation of Mapper.get_all.


if fmt is None:<EOL><INDENT>return {'<STR_LIT>': None, '<STR_LIT>': None, '<STR_LIT>': None}<EOL><DEDENT>tz_marker = None<EOL>match = re.search('<STR_LIT>', fmt)<EOL>if match:<EOL><INDENT>tz_marker = match.group('<STR_LIT>')<EOL>if len(set(tz_marker.strip())) != <NUM_LIT:1>:  <EOL><INDENT>raise ValueError(fmt)<EOL><DEDENT>fmt = fmt[:match.start()]<EOL><DEDENT>date_patterns = {<EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>}<EOL>time_patterns = {"<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"}<EOL>translate = {<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT:M>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT:d>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>}<EOL>for dt_sep in '<STR_LIT>':  <EOL><INDENT>if dt_sep in fmt:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>dt_sep = None<EOL><DEDENT>if dt_sep:<EOL><INDENT>dfmt, tfmt = fmt.split(dt_sep)<EOL><DEDENT>elif no_date:<EOL><INDENT>dfmt, tfmt = None, fmt<EOL><DEDENT>else:<EOL><INDENT>dfmt, tfmt = fmt, None<EOL><DEDENT>msecs = None  <EOL>if tfmt and '<STR_LIT:.>' in tfmt:  <EOL><INDENT>tfmt, msecs = tfmt.split('<STR_LIT:.>')  <EOL>if set(msecs) != {'<STR_LIT:S>'}:  <EOL><INDENT>raise ValueError(fmt)<EOL><DEDENT>msecs = len(msecs)   <EOL><DEDENT>if (dfmt and dfmt not in date_patterns) or (tfmt and tfmt not in time_patterns):<EOL><INDENT>raise ValueError(fmt)<EOL><DEDENT>regex, format = '<STR_LIT>', '<STR_LIT>'  <EOL>if dfmt:<EOL><INDENT>for d_sep in '<STR_LIT>':  <EOL><INDENT>if d_sep in dfmt:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')  <EOL><DEDENT>for i, part in enumerate(dfmt.split(d_sep)):<EOL><INDENT>if i > <NUM_LIT:0>:<EOL><INDENT>format += d_sep<EOL>regex += re.escape(d_sep)<EOL><DEDENT>f, r = translate[part]<EOL>format += f<EOL>regex += r<EOL><DEDENT><DEDENT>if dt_sep:<EOL><INDENT>format += dt_sep<EOL>regex += re.escape(dt_sep)<EOL><DEDENT>if tfmt:<EOL><INDENT>for i, part in enumerate(tfmt.split('<STR_LIT::>')):<EOL><INDENT>if i > <NUM_LIT:0>:<EOL><INDENT>format += '<STR_LIT::>'<EOL>regex += re.escape('<STR_LIT::>')<EOL><DEDENT>f, r = translate[part]<EOL>format += f<EOL>regex += r<EOL><DEDENT><DEDENT>if msecs:<EOL><INDENT>format += '<STR_LIT>' % msecs<EOL>regex += '<STR_LIT>' % msecs<EOL><DEDENT>return {'<STR_LIT>': re.compile(regex), '<STR_LIT>': format, '<STR_LIT>': tz_marker}<EOL>


tables = {}<EOL>for tname, table in tg.tabledict.items():<EOL><INDENT>t = TableSpec.from_table_metadata(table)<EOL>tables[t.name] = t<EOL>for at in t.many_to_many.values():<EOL><INDENT>tables[at.name] = at<EOL><DEDENT><DEDENT>ordered = OrderedDict()<EOL>i = <NUM_LIT:0><EOL>while tables and i < <NUM_LIT:100>:<EOL><INDENT>i += <NUM_LIT:1><EOL>for table in list(tables.keys()):<EOL><INDENT>if all((ref[<NUM_LIT:1>] in ordered) or ref[<NUM_LIT:1>] == table for ref in tables[table].foreign_keys):<EOL><INDENT>ordered[table] = tables.pop(table)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if tables:  <EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return list(ordered.values())<EOL>

Convert the table and column descriptions of a `TableGroup` into specifications for the
DB schema.

:param ds:
:return: A pair (tables, reference_tables).


if not self.csvw:<EOL><INDENT>return<EOL><DEDENT>c, cname = self.csvw, translate(self.name)<EOL>constraints = []<EOL>if (c.minimum is not None) or (c.maximum is not None):<EOL><INDENT>func = {<EOL>'<STR_LIT:date>': '<STR_LIT:date>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}.get(self.csvw_type)<EOL>if c.minimum is not None:<EOL><INDENT>if func:<EOL><INDENT>constraints.append("<STR_LIT>".format(cname, c.minimum, func))<EOL><DEDENT>else:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.minimum))<EOL><DEDENT><DEDENT>if c.maximum is not None:<EOL><INDENT>if func:<EOL><INDENT>constraints.append("<STR_LIT>".format(cname, c.maximum, func))<EOL><DEDENT>else:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.maximum))<EOL><DEDENT><DEDENT><DEDENT>elif any(cc is not None for cc in [c.length, c.minLength, c.maxLength]):<EOL><INDENT>if c.length:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.length))<EOL><DEDENT>if c.minLength:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.minLength))<EOL><DEDENT>if c.maxLength:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.maxLength))<EOL><DEDENT><DEDENT>return '<STR_LIT>'.join(constraints)<EOL>

We try to convert as many data constraints as possible into SQLite CHECK constraints.

:param translate:
:return:


col_translate = partial(translate, self.name)<EOL>clauses = [col.sql(col_translate) for col in self.columns]<EOL>if self.primary_key:<EOL><INDENT>clauses.append('<STR_LIT>'.format(quoted(<EOL>*[col_translate(c) for c in self.primary_key])))<EOL><DEDENT>for fk, ref, refcols in self.foreign_keys:<EOL><INDENT>clauses.append('<STR_LIT>'.format(<EOL>quoted(*[col_translate(c) for c in fk]),<EOL>quoted(translate(ref)),<EOL>quoted(*[translate(ref, c) for c in refcols])))<EOL><DEDENT>return "<STR_LIT>".format(<EOL>translate(self.name), '<STR_LIT>'.join(clauses))<EOL>

:param translate:
:return: The SQL statement to create the table.


<EOL>return column or table<EOL>

A callable with this signature can be passed into DB creation to control the names
of the schema objects.

:param table: Name of the table before translation
:param column: Name of a column of `table` before translation
:return: Translated table name if `column is None` else translated column name


def association_table_context(self, table, column, fkey):

<EOL>return fkey, column<EOL>

Context for association tables is created calling this method.

:param table:
:param column:
:param fkey:
:return: a pair (foreign key, context)


def write(self, _force=False, _exists_ok=False, **items):

if self.fname and self.fname.exists():<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>with self.connection() as db:<EOL><INDENT>for table in self.tables:<EOL><INDENT>db.execute(table.sql(translate=self.translate))<EOL><DEDENT>db.execute('<STR_LIT>')<EOL>db.commit()<EOL>refs = defaultdict(list)  <EOL>for t in self.tables:<EOL><INDENT>if t.name not in items:<EOL><INDENT>continue<EOL><DEDENT>rows, keys = [], []<EOL>cols = {c.name: c for c in t.columns}<EOL>for i, row in enumerate(items[t.name]):<EOL><INDENT>pk = row[t.primary_key[<NUM_LIT:0>]]if t.primary_key and len(t.primary_key) == <NUM_LIT:1> else None<EOL>values = []<EOL>for k, v in row.items():<EOL><INDENT>if k in t.many_to_many:<EOL><INDENT>assert pk<EOL>at = t.many_to_many[k]<EOL>atkey = tuple([at.name] + [c.name for c in at.columns])<EOL>for vv in v:<EOL><INDENT>fkey, context = self.association_table_context(t, k, vv)<EOL>refs[atkey].append((pk, fkey, context))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>col = cols[k]<EOL>if isinstance(v, list):<EOL><INDENT>v = (col.separator or '<STR_LIT:;>').join(<EOL>col.convert(vv) for vv in v)<EOL><DEDENT>else:<EOL><INDENT>v = col.convert(v) if v is not None else None<EOL><DEDENT>if i == <NUM_LIT:0>:<EOL><INDENT>keys.append(col.name)<EOL><DEDENT>values.append(v)<EOL><DEDENT><DEDENT>rows.append(tuple(values))<EOL><DEDENT>insert(db, self.translate, t.name, keys, *rows)<EOL><DEDENT>for atkey, rows in refs.items():<EOL><INDENT>insert(db, self.translate, atkey[<NUM_LIT:0>], atkey[<NUM_LIT:1>:], *rows)<EOL><DEDENT>db.commit()<EOL><DEDENT>

Creates a db file with the core schema.

:param force: If `True` an existing db file will be overwritten.


def iterrows(lines_or_file, namedtuples=False, dicts=False, encoding='<STR_LIT:utf-8>', **kw):

if namedtuples and dicts:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>elif namedtuples:<EOL><INDENT>_reader = NamedTupleReader<EOL><DEDENT>elif dicts:<EOL><INDENT>_reader = UnicodeDictReader<EOL><DEDENT>else:<EOL><INDENT>_reader = UnicodeReader<EOL><DEDENT>with _reader(lines_or_file, encoding=encoding, **fix_kw(kw)) as r:<EOL><INDENT>for item in r:<EOL><INDENT>yield item<EOL><DEDENT><DEDENT>

Convenience factory function for csv reader.

    :param lines_or_file: Content to be read. Either a file handle, a file path or a list\
    of strings.
    :param namedtuples: Yield namedtuples.
    :param dicts: Yield dicts.
    :param encoding: Encoding of the content.
    :param kw: Keyword parameters are passed through to csv.reader.
    :return: A generator over the rows.


if not isinstance(fname, pathlib.Path):<EOL><INDENT>assert isinstance(fname, string_types)<EOL>fname = pathlib.Path(fname)<EOL><DEDENT>assert fname.is_file()<EOL>with tempfile.NamedTemporaryFile(delete=False) as fp:<EOL><INDENT>tmp = pathlib.Path(fp.name)<EOL><DEDENT>with UnicodeReader(fname, **kw) as reader_:<EOL><INDENT>with UnicodeWriter(tmp, **kw) as writer:<EOL><INDENT>for i, row in enumerate(reader_):<EOL><INDENT>row = visitor(i, row)<EOL>if row is not None:<EOL><INDENT>writer.writerow(row)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>shutil.move(str(tmp), str(fname))<EOL>

Utility function to rewrite rows in tsv files.

    :param fname: Path of the dsv file to operate on.
    :param visitor: A callable that takes a line-number and a row as input and returns a \
    (modified) row or None to filter out the row.
    :param kw: Keyword parameters are passed through to csv.reader/csv.writer.


def filter_rows_as_dict(fname, filter_, **kw):

filter_ = DictFilter(filter_)<EOL>rewrite(fname, filter_, **kw)<EOL>return filter_.removed<EOL>

Rewrite a dsv file, filtering the rows.

    :param fname: Path to dsv file
    :param filter_: callable which accepts a `dict` with a row's data as single argument\
    returning a `Boolean` indicating whether to keep the row (`True`) or to discard it \
    `False`.
    :param kw: Keyword arguments to be passed `UnicodeReader` and `UnicodeWriter`.
    :return: The number of rows that have been removed.


<EOL>row = super(UnicodeReaderWithLineNumber, self).__next__()<EOL>return self.lineno + <NUM_LIT:1>, row<EOL>

:return: a pair (1-based line number in the input, row)


return attr.ib(<EOL>default=None,<EOL>validator=attr.validators.optional(attr.validators.instance_of(URITemplate)),<EOL>converter=lambda v: v if v is None else URITemplate(v))<EOL>

Note: We do not currently provide support for supplying the "_" variables like "_row"
when expanding a URI template.

.. seealso:: http://w3c.github.io/csvw/metadata/#uri-template-properties


if hasattr(base, '<STR_LIT>'):<EOL><INDENT>return base / self.string<EOL><DEDENT>return urljoin(base, self.string)<EOL>

Resolve a `Link` relative to `base`.

:param base:
:return: Either a string, representing a URL, or a `pathlib.Path` object, representing \
a local file.


if isinstance(v, text_type):<EOL><INDENT>return cls(base=v)<EOL><DEDENT>if isinstance(v, dict):<EOL><INDENT>return cls(**DescriptionBase.partition_properties(v))<EOL><DEDENT>if isinstance(v, cls):<EOL><INDENT>return v<EOL><DEDENT>raise ValueError(v)<EOL>

:param v: Initialization data for `cls`; either a single string that is the main datatype \
of the values of the cell or a datatype description object, i.e. a `dict` or a `cls`
instance.
:return: An instance of `cls`


def iterdicts(self, log=None, with_metadata=False, fname=None, _Row=collections.OrderedDict):

dialect = self._get_dialect()<EOL>fname = fname or self.url.resolve(self._parent.base)<EOL>colnames, virtualcols, requiredcols = [], [], set()<EOL>for col in self.tableSchema.columns:<EOL><INDENT>if col.virtual:<EOL><INDENT>if col.valueUrl:<EOL><INDENT>virtualcols.append((col.header, col.valueUrl))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>colnames.append(col.header)<EOL><DEDENT>if col.required:<EOL><INDENT>requiredcols.add(col.header)<EOL><DEDENT><DEDENT>with UnicodeReaderWithLineNumber(fname, dialect=dialect) as reader:<EOL><INDENT>reader = iter(reader)<EOL>if dialect.header:<EOL><INDENT>try:<EOL><INDENT>_, header = next(reader)<EOL><DEDENT>except StopIteration:  <EOL><INDENT>return<EOL><DEDENT><DEDENT>else:<EOL><INDENT>header = colnames<EOL><DEDENT>if header == colnames:<EOL><INDENT>header_cols = list(zip(header, self.tableSchema.columns))<EOL><DEDENT>else:<EOL><INDENT>header_cols = [(h, self.tableSchema.get_column(h)) for h in header]<EOL><DEDENT>header_cols = [(j, h, c) for j, (h, c) in enumerate(header_cols)]<EOL>missing = requiredcols - set(c.header for j, h, c in header_cols if c)<EOL>if missing:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(fname, missing))<EOL><DEDENT>for lineno, row in reader:<EOL><INDENT>required = {h: j for j, h, c in header_cols if c and c.required}<EOL>res = _Row()<EOL>error = False<EOL>for (j, k, col), v in zip(header_cols, row):<EOL><INDENT>if col:<EOL><INDENT>if k in required:<EOL><INDENT>del required[k]<EOL><DEDENT>try:<EOL><INDENT>res[col.header] = col.read(v)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>log_or_raise(<EOL>'<STR_LIT>'.format(fname, lineno, j + <NUM_LIT:1>, k, e),<EOL>log=log)<EOL>error = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>res[k] = v<EOL><DEDENT><DEDENT>for k, j in required.items():<EOL><INDENT>if k not in res:<EOL><INDENT>log_or_raise(<EOL>'<STR_LIT>'.format(<EOL>fname, lineno, j + <NUM_LIT:1>, k, '<STR_LIT>'),<EOL>log=log)<EOL>error = True<EOL><DEDENT><DEDENT>for key, valueUrl in virtualcols:<EOL><INDENT>res[key] = valueUrl.expand(**res)<EOL><DEDENT>if not error:<EOL><INDENT>if with_metadata:<EOL><INDENT>yield fname, lineno, res<EOL><DEDENT>else:<EOL><INDENT>yield res<EOL><DEDENT><DEDENT><DEDENT><DEDENT>

Iterate over the rows of the table

        Create an iterator that maps the information in each row to a `dict` whose keys are
        the column names of the table and whose values are the values in the corresponding
        table cells, or for virtual columns (which have no values) the valueUrl for that
        column. This includes columns not specified in the table specification.

        :param log: Logger object (default None) The object that reports parsing errors.\
        If none is given, parsing errors raise ValueError instead.
        :param bool with_metadata: (default False) Also yield fname and lineno
        :param fname: file-like, pathlib.Path, or str (default None)\
        The file to be read. Defaults to inheriting from a parent object, if one exists.
        :return: A generator of dicts or triples (fname, lineno, dict) if with_metadata


return {tname: list(t.iterdicts()) for tname, t in self.tabledict.items()}<EOL>


fname = pathlib.Path(fname)<EOL>for tname, rows in items.items():<EOL><INDENT>self.tabledict[tname].write(rows, base=fname.parent)<EOL><DEDENT>self.to_file(fname)<EOL>

Write a TableGroup's data and metadata to files.

:param fname:
:param items:
:return:


dest = pathlib.Path(dest)<EOL>for table in self.tables:<EOL><INDENT>shutil.copy(str(table.url.resolve(self.base)), str(table.url.resolve(dest)))<EOL><DEDENT>self._fname = dest / self._fname.name<EOL>self.to_file(self._fname)<EOL>

Write a TableGroup's data and metadata to files relative to `dest`, adapting the `base`
attribute.

:param dest:
:return:


return self._fname.parent<EOL>

We only support data in the filesystem, thus we make sure `base` is a `pathlib.Path`.


s = s.replace('<STR_LIT:->', '<STR_LIT:_>').replace('<STR_LIT:.>', '<STR_LIT:_>').replace('<STR_LIT:U+0020>', '<STR_LIT:_>')<EOL>if s in keyword.kwlist:<EOL><INDENT>return s + '<STR_LIT:_>'<EOL><DEDENT>s = '<STR_LIT:_>'.join(slug(ss, lowercase=False) for ss in s.split('<STR_LIT:_>'))<EOL>if not s:<EOL><INDENT>s = '<STR_LIT:_>'<EOL><DEDENT>if s[<NUM_LIT:0>] not in string.ascii_letters + '<STR_LIT:_>':<EOL><INDENT>s = '<STR_LIT:_>' + s<EOL><DEDENT>return s<EOL>

Convert a string into a valid python attribute name.
    This function is called to convert ASCII strings to something that can pass as
    python attribute name, to be used with namedtuples.

    >>> str(normalize_name('class'))
    'class_'
    >>> str(normalize_name('a-name'))
    'a_name'
    >>> str(normalize_name('a n\u00e4me'))
    'a_name'
    >>> str(normalize_name('Name'))
    'Name'
    >>> str(normalize_name(''))
    '_'
    >>> str(normalize_name('1'))
    '_1'


def slug(s, remove_whitespace=True, lowercase=True):

res = '<STR_LIT>'.join(c for c in unicodedata.normalize('<STR_LIT>', s)<EOL>if unicodedata.category(c) != '<STR_LIT>')<EOL>if lowercase:<EOL><INDENT>res = res.lower()<EOL><DEDENT>for c in string.punctuation:<EOL><INDENT>res = res.replace(c, '<STR_LIT>')<EOL><DEDENT>res = re.sub('<STR_LIT>', '<STR_LIT>' if remove_whitespace else '<STR_LIT:U+0020>', res)<EOL>res = res.encode('<STR_LIT:ascii>', '<STR_LIT:ignore>').decode('<STR_LIT:ascii>')<EOL>assert re.match('<STR_LIT>', res)<EOL>return res<EOL>

Condensed version of s, containing only lowercase alphanumeric characters.

    >>> str(slug('A B. \u00e4C'))
    'abac'


days = int(hours // <NUM_LIT:8>)<EOL>hours_left = hours % <NUM_LIT:8><EOL>return days, hours_left<EOL>

Convert the given amount of hours to a 2-tuple `(days, hours)`.


pass<EOL>


prefix = '<STR_LIT>' if number <= <NUM_LIT:0> else '<STR_LIT:+>'<EOL>number_str = '<STR_LIT>'.format(prefix, number, precision=precision)<EOL>return number_str<EOL>

Return the given number as a string with a sign in front of it, ie. `+` if the number is positive, `-` otherwise.


return date - datetime.timedelta(days=date.weekday())<EOL>

Return the first day of the week for the given date.


return date + datetime.timedelta(days=(<NUM_LIT:6> - date.weekday()))<EOL>

Return the last day of the week for the given date.


backend = plugins_registry.get_backends_by_class(ZebraBackend)[<NUM_LIT:0>]<EOL>timesheet_collection = get_timesheet_collection_for_context(ctx, None)<EOL>hours_to_be_pushed = timesheet_collection.get_hours(pushed=False, ignored=False, unmapped=False)<EOL>today = datetime.date.today()<EOL>user_info = backend.get_user_info()<EOL>timesheets = backend.get_timesheets(get_first_dow(today), get_last_dow(today))<EOL>total_duration = sum([float(timesheet['<STR_LIT:time>']) for timesheet in timesheets])<EOL>vacation = hours_to_days(user_info['<STR_LIT>']['<STR_LIT>'])<EOL>vacation_balance = '<STR_LIT>'.format(*vacation)<EOL>hours_balance = user_info['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>click.echo("<STR_LIT>".format(signed_number(hours_balance)))<EOL>click.echo("<STR_LIT>".format(signed_number(hours_balance + hours_to_be_pushed)))<EOL>click.echo("<STR_LIT>".format(total_duration))<EOL>click.echo("<STR_LIT>".format(vacation_balance))<EOL>

Show Zebra balance.

Like the hours balance, vacation left, etc.


def to_zebra_value(value):<EOL><INDENT>transform_funcs = {<EOL>bool: lambda v: '<STR_LIT:true>' if v else '<STR_LIT:false>',<EOL>}<EOL>return transform_funcs.get(type(value), lambda v: v)(value)<EOL><DEDENT>return {param: to_zebra_value(value) for param, value in params.items()}<EOL>

Transforms the given `params` dict to values that are understood by Zebra (eg. False is represented as 'false')


message_type_kwargs = {<EOL>'<STR_LIT>': {'<STR_LIT>': '<STR_LIT>'},<EOL>'<STR_LIT:error>': {'<STR_LIT>': '<STR_LIT>'},<EOL>}<EOL>for message in response_json.get('<STR_LIT>', []):<EOL><INDENT>click.secho(message['<STR_LIT:text>'], **message_type_kwargs.get(message['<STR_LIT:type>'], {}))<EOL><DEDENT>

Show all messages in the `messages` key of the given dict.


def update_alias_mapping(settings, alias, new_mapping):

mapping = aliases_database[alias]<EOL>new_mapping = Mapping(mapping=new_mapping, backend=mapping.backend)<EOL>aliases_database[alias] = new_mapping<EOL>settings.add_alias(alias, new_mapping)<EOL>settings.write_config()<EOL>

Override `alias` mapping in the user configuration file with the given `new_mapping`, which should be a tuple with
2 or 3 elements (in the form `(project_id, activity_id, role_id)`).


if not data:<EOL><INDENT>return None<EOL><DEDENT>return Message(<EOL>id=data['<STR_LIT:message>']['<STR_LIT>'],<EOL>platform=self.platform,<EOL>text=data['<STR_LIT:message>']['<STR_LIT:text>'],<EOL>user=data['<STR_LIT>']['<STR_LIT:id>'],<EOL>timestamp=data['<STR_LIT>'],<EOL>raw=data,<EOL>chat=None,  <EOL>)<EOL>

Return a Message instance according to the data received from
Facebook Messenger API.


@click.group(invoke_without_command=True)<EOL>@click.option('<STR_LIT>', '<STR_LIT>', is_flag=True, default=False)<EOL>@click.pass_context<EOL>def cli(ctx, version):

<EOL>if not ctx.invoked_subcommand and version:<EOL><INDENT>click.echo(bottery.__version__)<EOL>ctx.exit()<EOL><DEDENT>elif not ctx.invoked_subcommand:<EOL><INDENT>click.echo(ctx.get_help())<EOL>ctx.exit()<EOL><DEDENT>


raise NotImplementedError('<STR_LIT>')<EOL>


Build Message instance according to the data received from the
platform API.


Called by App instance to configure the platform


view = self.discovery_view(message)<EOL>if not view:<EOL><INDENT>return<EOL><DEDENT>if inspect.iscoroutinefunction(view):<EOL><INDENT>response = await view(message)<EOL><DEDENT>else:<EOL><INDENT>response = view(message)<EOL><DEDENT>return self.prepare_response(response, message)<EOL>

Get response running the view with await syntax if it is a
coroutine function, otherwise just run it the normal way.


for handler in self.registered_handlers:<EOL><INDENT>if handler.check(message):<EOL><INDENT>return handler.view<EOL><DEDENT><DEDENT>return None<EOL>

Use the new message to search for a registered view according
to its pattern.


message = self.build_message(data)<EOL>if not message:<EOL><INDENT>logger.error(<EOL>'<STR_LIT>',<EOL>self.engine_name,<EOL>data<EOL>)<EOL>return<EOL><DEDENT>logger.info('<STR_LIT>', self.engine_name,<EOL>message.user, message.text)<EOL>response = await self.get_response(message)<EOL>if response:<EOL><INDENT>await self.send_response(response)<EOL><DEDENT>

For each new message, build its platform specific message
object and get a response.


message_data = data.get('<STR_LIT:message>') or data.get('<STR_LIT>')<EOL>if not message_data:<EOL><INDENT>return None<EOL><DEDENT>edited = '<STR_LIT>' in data<EOL>return Message(<EOL>id=message_data['<STR_LIT>'],<EOL>platform=self.platform,<EOL>text=message_data.get('<STR_LIT:text>', '<STR_LIT>'),<EOL>user=TelegramUser(message_data['<STR_LIT>']),<EOL>chat=TelegramChat(message_data['<STR_LIT>']),<EOL>timestamp=message_data['<STR_LIT:date>'],<EOL>raw=data,<EOL>edited=edited,<EOL>)<EOL>

Return a Message instance according to the data received from
Telegram API.
https://core.telegram.org/bots/api#update


if message.chat.type == '<STR_LIT>':<EOL><INDENT>return message.user.id<EOL><DEDENT>return message.chat.id<EOL>

Telegram chat type can be either "private", "group", "supergroup" or
"channel".
Return user ID if it is of type "private", chat ID otherwise.


return itertools.chain(<EOL>[<NUM_LIT>, <NUM_LIT>, <NUM_LIT>],<EOL>range(<NUM_LIT>, <NUM_LIT>+<NUM_LIT:1>),<EOL>range(<NUM_LIT>, <NUM_LIT>+<NUM_LIT:1>),<EOL>range(<NUM_LIT>, <NUM_LIT>)<EOL>)<EOL>

only those can be used in an XML document


def rng(s, e):<EOL><INDENT>return range(ord(s), ord(e)+<NUM_LIT:1>)<EOL><DEDENT>return itertools.chain(<EOL>[ord('<STR_LIT::>')],<EOL>rng('<STR_LIT:A>', '<STR_LIT>'),<EOL>[ord('<STR_LIT:_>')],<EOL>rng('<STR_LIT:a>', '<STR_LIT:z>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>')<EOL>)<EOL>


def rng(s, e):<EOL><INDENT>return range(ord(s), ord(e)+<NUM_LIT:1>)<EOL><DEDENT>return itertools.chain(<EOL>valid_xml_name_char_start(),<EOL>[ord('<STR_LIT:->')],<EOL>[ord('<STR_LIT:.>')],<EOL>rng('<STR_LIT:0>', '<STR_LIT>'),<EOL>[ord('<STR_LIT>')],<EOL>rng('<STR_LIT>', '<STR_LIT>'),<EOL>rng('<STR_LIT>', '<STR_LIT>')<EOL>)<EOL>


for x in range(<NUM_LIT:1>, <NUM_LIT>): yield x<EOL>


return __TEXT_ESCAPE_PATTERN.sub(lambda mtc: __TEXT_ESCAPE[mtc.group()], text)<EOL>


return __ATTR_ESCAPE_PATTERN.sub(lambda mtc: __ATTR_ESCAPE[mtc.group()], text)<EOL>


if __PI_TEXT_CHECK_PATTERN.search(text):<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>

validates XML Processing Instruction text


if __COMMENT_TEXT_CHECK_PATTERN.search(text):<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>


bad_chars = __INVALID_XML_CHARS & set(text)<EOL>if bad_chars:<EOL><INDENT>for offset,c in enumerate(text):<EOL><INDENT>if c in bad_chars:<EOL><INDENT>raise RuntimeError('<STR_LIT>' + repr(c) + '<STR_LIT>' + str(offset))<EOL><DEDENT><DEDENT><DEDENT>


if len(name) == <NUM_LIT:0>:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if __INVALID_NAME_CHARS & set(name):<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>if name[<NUM_LIT:0>] in __INVALID_NAME_START_CHARS:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>


if xml.tag is et.Comment:<EOL><INDENT>yield {'<STR_LIT:type>': COMMENT, '<STR_LIT:text>': xml.text}<EOL>return<EOL><DEDENT>if xml.tag is et.PI:<EOL><INDENT>if xml.text:<EOL><INDENT>yield {'<STR_LIT:type>': PI, '<STR_LIT:target>': xml.target, '<STR_LIT:text>': xml.text}<EOL><DEDENT>else:<EOL><INDENT>yield {'<STR_LIT:type>': PI, '<STR_LIT:target>': xml.target}<EOL><DEDENT>return<EOL><DEDENT>obj = _elt2obj(xml)<EOL>obj['<STR_LIT:type>'] = ENTER<EOL>yield obj<EOL>assert type(xml.tag) is str, xml<EOL>if xml.text:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': xml.text}<EOL><DEDENT>for c in xml:<EOL><INDENT>for x in scan(c): yield x<EOL>if c.tail:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': c.tail}<EOL><DEDENT><DEDENT>yield {'<STR_LIT:type>': EXIT}<EOL>


root = None<EOL>last_closed_elt = None<EOL>stack = []<EOL>for obj in events:<EOL><INDENT>if obj['<STR_LIT:type>'] == ENTER:<EOL><INDENT>elt = _obj2elt(obj, nsmap=nsmap)<EOL>if stack:<EOL><INDENT>stack[-<NUM_LIT:1>].append(elt)<EOL><DEDENT>elif root is not None:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>root = elt<EOL><DEDENT>stack.append(elt)<EOL>last_closed_elt = None<EOL><DEDENT>elif obj['<STR_LIT:type>'] == EXIT:<EOL><INDENT>last_closed_elt = stack.pop()<EOL><DEDENT>elif obj['<STR_LIT:type>'] == COMMENT:<EOL><INDENT>elt = et.Comment(obj['<STR_LIT:text>'])<EOL>stack[-<NUM_LIT:1>].append(elt)<EOL><DEDENT>elif obj['<STR_LIT:type>'] == PI:<EOL><INDENT>elt = et.PI(obj['<STR_LIT:target>'])<EOL>if obj.get('<STR_LIT:text>'):<EOL><INDENT>elt.text = obj['<STR_LIT:text>']<EOL><DEDENT>stack[-<NUM_LIT:1>].append(elt)<EOL><DEDENT>elif obj['<STR_LIT:type>'] == TEXT:<EOL><INDENT>text = obj['<STR_LIT:text>']<EOL>if text:<EOL><INDENT>if last_closed_elt is None:<EOL><INDENT>stack[-<NUM_LIT:1>].text = (stack[-<NUM_LIT:1>].text or '<STR_LIT>') + text<EOL><DEDENT>else:<EOL><INDENT>last_closed_elt.tail = (last_closed_elt.tail or '<STR_LIT>') + text<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>assert False, obj<EOL><DEDENT><DEDENT>if root is None:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>return root<EOL>


for event, elt in et.iterparse(filename, events= ('<STR_LIT:start>', '<STR_LIT:end>', '<STR_LIT>', '<STR_LIT>'), huge_tree=True):<EOL><INDENT>if event == '<STR_LIT:start>':<EOL><INDENT>obj = _elt2obj(elt)<EOL>obj['<STR_LIT:type>'] = ENTER<EOL>yield obj<EOL>if elt.text:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': elt.text}<EOL><DEDENT><DEDENT>elif event == '<STR_LIT:end>':<EOL><INDENT>yield {'<STR_LIT:type>': EXIT}<EOL>if elt.tail:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': elt.tail}<EOL><DEDENT>elt.clear()<EOL><DEDENT>elif event == '<STR_LIT>':<EOL><INDENT>yield {'<STR_LIT:type>': COMMENT, '<STR_LIT:text>': elt.text}<EOL><DEDENT>elif event == '<STR_LIT>':<EOL><INDENT>yield {'<STR_LIT:type>': PI, '<STR_LIT:text>': elt.text}<EOL><DEDENT>else:<EOL><INDENT>assert False, (event, elt)<EOL><DEDENT><DEDENT>


stack = <NUM_LIT:0><EOL>for obj in events:<EOL><INDENT>if obj['<STR_LIT:type>'] == ENTER:<EOL><INDENT>stack += <NUM_LIT:1><EOL><DEDENT>elif obj['<STR_LIT:type>'] == EXIT:<EOL><INDENT>if stack == <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>stack -= <NUM_LIT:1><EOL><DEDENT>yield obj<EOL><DEDENT>


text = []<EOL>for obj in events:<EOL><INDENT>if obj['<STR_LIT:type>'] == TEXT:<EOL><INDENT>text.append(obj['<STR_LIT:text>'])<EOL><DEDENT>else:<EOL><INDENT>if text:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': '<STR_LIT>'.join(text)}<EOL>text.clear()<EOL><DEDENT>yield obj<EOL><DEDENT><DEDENT>if text:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': '<STR_LIT>'.join(text)}<EOL><DEDENT>

merges each run of successive text events into one text event


stack = []<EOL>for obj in events:<EOL><INDENT>if obj['<STR_LIT:type>'] == ENTER:<EOL><INDENT>stack.append(obj)<EOL>yield obj, None<EOL><DEDENT>elif obj['<STR_LIT:type>'] == EXIT:<EOL><INDENT>yield obj, stack.pop()<EOL><DEDENT>else:<EOL><INDENT>yield obj, None<EOL><DEDENT><DEDENT>

locates ENTER peer for each EXIT object. Convenient when selectively
    filtering out XML markup


return '<STR_LIT>'.join(o['<STR_LIT:text>'] for o in events if o['<STR_LIT:type>']==TEXT)<EOL>


if self._dtype is not None:<EOL><INDENT>iter2array(x, dtype=self._dtype)<EOL><DEDENT>else:<EOL><INDENT>iter2array(x)<EOL><DEDENT>return self<EOL>

Do nothing and return the estimator unchanged

        This method is just there to implement the usual API and hence work in pipelines.


def get_n_splits(self, X=None, y=None, groups=None):

return self.n_splits<EOL>

Returns the number of splitting iterations in the cross-validator
        Parameters
        ----------
        X : object
            Always ignored, exists for compatibility.
            ``np.zeros(n_samples)`` may be used as a placeholder.
        y : object
            Always ignored, exists for compatibility.
            ``np.zeros(n_samples)`` may be used as a placeholder.
        groups : array-like, with shape (n_samples,)
            Group labels for the samples used while splitting the dataset into
            train/test set.
        Returns
        -------
        n_splits : int
            Returns the number of splitting iterations in the cross-validator.


def split(self, X, y=None, groups=None):

X, y, groups = indexable(X, y, groups)<EOL>cgrs = [~r for r in X]<EOL>condition_structure = defaultdict(set)<EOL>for structure, condition in zip(cgrs, groups):<EOL><INDENT>condition_structure[condition].add(structure)<EOL><DEDENT>train_data = defaultdict(list)<EOL>test_data = []<EOL>for n, (structure, condition) in enumerate(zip(cgrs, groups)):<EOL><INDENT>train_data[structure].append(n)<EOL>if len(condition_structure[condition]) > <NUM_LIT:1>:<EOL><INDENT>test_data.append(n)<EOL><DEDENT><DEDENT>if self.n_splits > len(train_data):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (self.n_splits, len(train_data)))<EOL><DEDENT>structures_weight = sorted(((x, len(y)) for x, y in train_data.items()), key=lambda x: x[<NUM_LIT:1>], reverse=True)<EOL>fold_mean_size = len(cgrs) // self.n_splits<EOL>if structures_weight[<NUM_LIT:0>][<NUM_LIT:1>] > fold_mean_size:<EOL><INDENT>warning('<STR_LIT>')<EOL><DEDENT>for idx in range(self.n_repeats):<EOL><INDENT>train_folds = [[] for _ in range(self.n_splits)]<EOL>for structure, structure_length in structures_weight:<EOL><INDENT>if self.shuffle:<EOL><INDENT>check_random_state(self.random_state).shuffle(train_folds)<EOL><DEDENT>for fold in train_folds[:-<NUM_LIT:1>]:<EOL><INDENT>if len(fold) + structure_length <= fold_mean_size:<EOL><INDENT>fold.extend(train_data[structure])<EOL>break<EOL><DEDENT>else:<EOL><INDENT>roulette_param = (structure_length - fold_mean_size + len(fold)) / structure_length<EOL>if random() > roulette_param:<EOL><INDENT>fold.extend(train_data[structure])<EOL>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>train_folds[-<NUM_LIT:1>].extend(train_data[structure])<EOL><DEDENT><DEDENT>test_folds = [[] for _ in range(self.n_splits)]<EOL>for test, train in zip(test_folds, train_folds):<EOL><INDENT>for index in train:<EOL><INDENT>if index in test_data:<EOL><INDENT>test.append(index)<EOL><DEDENT><DEDENT><DEDENT>for i in range(self.n_splits):<EOL><INDENT>train_index = []<EOL>for fold in train_folds[:i]:<EOL><INDENT>train_index.extend(fold)<EOL><DEDENT>for fold in train_folds[i+<NUM_LIT:1>:]:<EOL><INDENT>train_index.extend(fold)<EOL><DEDENT>test_index = test_folds[i]<EOL>yield array(train_index), array(test_index)<EOL><DEDENT><DEDENT>

Generate indices to split data into training and test set.
        Parameters
        ----------
        X : array-like, of length n_samples
            Training data, includes reaction's containers
        y : array-like, of length n_samples
            The target variable for supervised learning problems.
        groups : array-like, with shape (n_samples,)
            Group labels for the samples used while splitting the dataset into
            train/test set.
        Yields
        ------
        train : ndarray
            The training set indices for that split.
        test : ndarray
            The testing set indices for that split.


return len(set(groups))<EOL>


X, y, groups = indexable(X, y, groups)<EOL>cgrs = [~r for r in X]<EOL>structure_condition = defaultdict(set)<EOL>for structure, condition in zip(cgrs, groups):<EOL><INDENT>structure_condition[structure].add(condition)<EOL><DEDENT>train_data = defaultdict(list)<EOL>test_data = []<EOL>for n, (structure, condition) in enumerate(zip(cgrs, groups)):<EOL><INDENT>train_data[condition].append(n)<EOL>if len(structure_condition[structure]) > <NUM_LIT:1>:<EOL><INDENT>test_data.append(n)<EOL><DEDENT><DEDENT>for condition, indexes in train_data.items():<EOL><INDENT>test_index = [index for index in indexes if index in test_data]<EOL>if test_index:<EOL><INDENT>train_index = [i for cond, ind in train_data.items() if cond != condition for i in ind]<EOL>yield array(train_index), array(test_index)<EOL><DEDENT><DEDENT>


if isinstance(data, Path):<EOL><INDENT>with data.open('<STR_LIT:rb>') as f:<EOL><INDENT>data = f.read()<EOL><DEDENT><DEDENT>elif isinstance(data, StringIO):<EOL><INDENT>data = data.read().encode()<EOL><DEDENT>elif isinstance(data, BytesIO):<EOL><INDENT>data = data.read()<EOL><DEDENT>elif hasattr(data, '<STR_LIT>'):  <EOL><INDENT>data = data.read()<EOL>if isinstance(data, str):<EOL><INDENT>data = data.encode()<EOL><DEDENT><DEDENT>elif isinstance(data, str):<EOL><INDENT>data = data.encode()<EOL><DEDENT>elif not isinstance(data, bytes):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>p = run(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>'], input=data, stdout=PIPE)<EOL><DEDENT>except FileNotFoundError as e:<EOL><INDENT>raise ConfigurationError from e<EOL><DEDENT>if p.returncode != <NUM_LIT:0>:<EOL><INDENT>raise ConfigurationError(p.stderr.decode())<EOL><DEDENT>with BytesIO(p.stdout) as f, MRVread(f) as r:<EOL><INDENT>return iter2array(r)<EOL><DEDENT>

molconvert wrapper
:param data: buffer or string or path to file
:return: array of molecules of reactions


<EOL>X = check_array(X)<EOL>self.tree = BallTree(X, leaf_size=self.leaf_size, metric=self.metric)<EOL>dist_train = self.tree.query(X, k=<NUM_LIT:2>)[<NUM_LIT:0>]<EOL>if self.threshold == '<STR_LIT>':<EOL><INDENT>self.threshold_value = <NUM_LIT:0.5> * sqrt(var(dist_train[:, <NUM_LIT:1>])) + mean(dist_train[:, <NUM_LIT:1>])<EOL><DEDENT>elif self.threshold == '<STR_LIT>':<EOL><INDENT>if y is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>y = check_array(y, accept_sparse='<STR_LIT>', ensure_2d=False, dtype=None)<EOL>self.threshold_value = <NUM_LIT:0><EOL>score = <NUM_LIT:0><EOL>Y_pred, Y_true, AD = [], [], []<EOL>cv = KFold(n_splits=<NUM_LIT:5>, random_state=<NUM_LIT:1>, shuffle=True)<EOL>for train_index, test_index in cv.split(X):<EOL><INDENT>x_train = safe_indexing(X, train_index)<EOL>x_test = safe_indexing(X, test_index)<EOL>y_train = safe_indexing(y, train_index)<EOL>y_test = safe_indexing(y, test_index)<EOL>data_test = safe_indexing(dist_train[:, <NUM_LIT:1>], test_index)<EOL>if self.reg_model is None:<EOL><INDENT>reg_model = RandomForestRegressor(n_estimators=<NUM_LIT>, random_state=<NUM_LIT:1>).fit(x_train, y_train)<EOL><DEDENT>else:<EOL><INDENT>reg_model = clone(self.reg_model).fit(x_train, y_train)<EOL><DEDENT>Y_pred.append(reg_model.predict(x_test))<EOL>Y_true.append(y_test)<EOL>AD.append(data_test)<EOL><DEDENT>AD_ = unique(hstack(AD))<EOL>for z in AD_:<EOL><INDENT>AD_new = hstack(AD) <= z<EOL>if self.score == '<STR_LIT>':<EOL><INDENT>val = balanced_accuracy_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>elif self.score == '<STR_LIT>':<EOL><INDENT>val = rmse_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>if val >= score:<EOL><INDENT>score = val<EOL>self.threshold_value = z<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>self.threshold_value = self.threshold<EOL><DEDENT>return self<EOL>

Fit distance-based AD.

        Parameters
        ----------
        X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Use ``dtype=np.float32`` for maximum
            efficiency.

        Returns
        -------
        self : object
            Returns self.


<EOL>check_is_fitted(self, ['<STR_LIT>'])<EOL>X = check_array(X)<EOL>return self.tree.query(X)[<NUM_LIT:0>].flatten()<EOL>

Returns the value of the nearest neighbor from the training set.

        Parameters
        ----------
         X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        y : array, shape (n_samples,)


<EOL>check_is_fitted(self, ['<STR_LIT>'])<EOL>X = check_array(X)<EOL>return self.tree.query(X)[<NUM_LIT:0>].flatten() <= self.threshold_value<EOL>

Predict if a particular sample is an outlier or not.

        Parameters
        ----------
         X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        y : array, shape (n_samples,)
            For each observations, tells whether or not (True or False) it should
            be considered as an inlier according to the fitted model.


<EOL>X = check_array(X)<EOL>self._x_min = X.min(axis=<NUM_LIT:0>) <EOL>self._x_max = X.max(axis=<NUM_LIT:0>) <EOL>return self<EOL>

Find min and max values of every feature.

        Parameters
        ----------
        X : {array-like, sparse matrix}, shape (n_samples, n_features)
            The training input samples.
        y : Ignored
            not used, present for API consistency by convention.

        Returns
        -------
        self : object


<EOL>check_is_fitted(self, ['<STR_LIT>', '<STR_LIT>'])<EOL>X = check_array(X)<EOL>return ((X - self._x_min).min(axis=<NUM_LIT:1>) >= <NUM_LIT:0>) & ((self._x_max - X).min(axis=<NUM_LIT:1>) >= <NUM_LIT:0>)<EOL>

Predict if a particular sample is an outlier or not.

        Parameters
        ----------
        X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        is_inlier : array, shape (n_samples,)
                   For each observations, tells whether or not (True or False) it should
                   be considered as an inlier according to the fitted model.


<EOL>X = check_array(X)<EOL>self.inverse_influence_matrix = self.__make_inverse_matrix(X)<EOL>if self.threshold == '<STR_LIT>':<EOL><INDENT>self.threshold_value = <NUM_LIT:3> * (<NUM_LIT:1> + X.shape[<NUM_LIT:1>]) / X.shape[<NUM_LIT:0>]<EOL><DEDENT>elif self.threshold == '<STR_LIT>':<EOL><INDENT>if y is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>y = check_array(y, accept_sparse='<STR_LIT>', ensure_2d=False, dtype=None)<EOL>self.threshold_value = <NUM_LIT:0><EOL>score = <NUM_LIT:0><EOL>Y_pred, Y_true, AD = [], [], []<EOL>cv = KFold(n_splits=<NUM_LIT:5>, random_state=<NUM_LIT:1>, shuffle=True)<EOL>for train_index, test_index in cv.split(X):<EOL><INDENT>x_train = safe_indexing(X, train_index)<EOL>x_test = safe_indexing(X, test_index)<EOL>y_train = safe_indexing(y, train_index)<EOL>y_test = safe_indexing(y, test_index)<EOL>if self.reg_model is None:<EOL><INDENT>reg_model = RandomForestRegressor(n_estimators=<NUM_LIT>, random_state=<NUM_LIT:1>).fit(x_train, y_train)<EOL><DEDENT>else:<EOL><INDENT>reg_model = clone(self.reg_model).fit(x_train, y_train)<EOL><DEDENT>Y_pred.append(reg_model.predict(x_test))<EOL>Y_true.append(y_test)<EOL>ad_model = self.__make_inverse_matrix(x_train)<EOL>AD.append(self.__find_leverages(x_test, ad_model))<EOL><DEDENT>AD_ = unique(hstack(AD))<EOL>for z in AD_:<EOL><INDENT>AD_new = hstack(AD) <= z<EOL>if self.score == '<STR_LIT>':<EOL><INDENT>val = balanced_accuracy_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>elif self.score == '<STR_LIT>':<EOL><INDENT>val = rmse_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>if val >= score:<EOL><INDENT>score = val<EOL>self.threshold_value = z<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>self.threshold_value = self.threshold<EOL><DEDENT>return self<EOL>

Learning is to find the inverse matrix for X and calculate the threshold.

        Parameters
        ----------
        X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Use ``dtype=np.float32`` for maximum
            efficiency.
        y : array-like, shape = [n_samples] or [n_samples, n_outputs]
            The target values (real numbers in regression).

        Returns
        -------
        self : object


<EOL>check_is_fitted(self, ['<STR_LIT>'])<EOL>X = check_array(X)<EOL>return self.__find_leverages(X, self.inverse_influence_matrix)<EOL>

Predict the distances for X to center of the training set.

        Parameters
        ----------
        X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        leverages: array of shape = [n_samples]
                   The objects distances to center of the training set.


<EOL>check_is_fitted(self, ['<STR_LIT>'])<EOL>X = check_array(X)<EOL>return self.__find_leverages(X, self.inverse_influence_matrix) <= self.threshold_value<EOL>

Predict inside or outside AD for X.

        Parameters
        ----------
        X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        ad : array of shape = [n_samples]
            Array contains True (reaction in AD) and False (reaction residing outside AD).


X = iter2array(X, dtype=ReactionContainer)<EOL>self._train_signatures = {self.__get_signature(x) for x in X}<EOL>return self<EOL>

Fit structure-based AD. The training model  memorizes the unique set of reaction signature.

        Parameters
        ----------
        X : after read rdf file

        Returns
        -------
        self : object


check_is_fitted(self, ['<STR_LIT>'])<EOL>X = iter2array(X, dtype=ReactionContainer)<EOL>return array([self.__get_signature(x) in self._train_signatures for x in X])<EOL>

Reaction is considered belonging to model’s AD
        if its reaction signature coincides with ones used in training set.

        Parameters
        ----------
        X : after read rdf file

        Returns
        -------
        self : array contains True (reaction in AD) and False (reaction residing outside AD).


def __init__(self, temperature=None, pressure=None, solvents=None, amounts=None,<EOL>default_temperature=<NUM_LIT> * C, default_pressure=<NUM_LIT:1> * bar,<EOL>default_first_solvent='<STR_LIT>', default_first_amount=<NUM_LIT:1>):

if solvents:<EOL><INDENT>if <NUM_LIT:1> < len(solvents) != len(amounts):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>elif amounts and len(amounts) > <NUM_LIT:1>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>self.__temperature = temperature<EOL>self.__pressure = pressure<EOL>self.__solvents = solvents<EOL>self.__amounts = amounts<EOL>self.__default_temperature = default_temperature<EOL>self.__default_pressure = default_pressure<EOL>self.__default_first_solvent = default_first_solvent<EOL>self.__default_first_amount = default_first_amount<EOL>

Dictionary to Conditions mapper

        :param temperature: name of temperature key
        :param pressure: name of pressure key
        :param solvents: names of solvents keys
        :param amounts: names of solvents amounts keys


return ['<STR_LIT>', '<STR_LIT>'] + [f'<STR_LIT>' for x in range(<NUM_LIT:1>, self.max_solvents + <NUM_LIT:1>)] +[f'<STR_LIT>' for x in range(<NUM_LIT:1>, self.max_solvents + <NUM_LIT:1>)]<EOL>

Get feature names.

        Returns
        -------
        feature_names : list of strings
            Names of the features produced by transform.


def __init__(self, templates, balance_groups=False):

self.templates = templates<EOL>self.balance_groups = balance_groups<EOL>self.__init()<EOL>

CGR standardization and reaction balancing

:param templates: CGRTemplates. list of rules for graph modifications.
:param balance_groups: if True: for unbalanced reactions contains multiple attached functional groups in
    products and one of them described in reagents - will be restored information about all equal groups.
    for example:

        R + B1-X-> B'1-R'-B'2 + X'

    where B' is transformed B, R and X same.
    we know what B'1 and B'2 is equal and B'1 is transformed B1 =>
    this groups most likely appeared from a single reagent. we can add copy of B-X to reagents.
    results will be:

        R + B1-X1 + B2-X2 -> B'1-R'-B'2 + X'1 + X'2


def __init__(self, fragment_type=<NUM_LIT:3>, min_length=<NUM_LIT:2>, max_length=<NUM_LIT:10>, cgr_dynbonds=<NUM_LIT:0>, doallways=False,<EOL>useformalcharge=False, header=None, workpath='<STR_LIT:.>', version=None, verbose=False, remove_rare_ratio=<NUM_LIT:0>,<EOL>return_domain=False):

self.fragment_type = fragment_type<EOL>self.min_length = min_length<EOL>self.max_length = max_length<EOL>self.cgr_dynbonds = cgr_dynbonds<EOL>self.doallways = doallways<EOL>self.useformalcharge = useformalcharge<EOL>self.version = version<EOL>self.verbose = verbose<EOL>self.header = header<EOL>self.remove_rare_ratio = remove_rare_ratio<EOL>self.return_domain = return_domain<EOL>self.__init_header()<EOL>self.set_work_path(workpath)<EOL>

ISIDA Fragmentor wrapper

:param workpath: path for temp files.
:param version: fragmentor version. need for selecting Fragmentor executables named as fragmentor-{version}
:param header: if None descriptors will be generated on train set
               if False Fragmentor will work in headless mode. in this mod fit unusable and Fragmentor return
                   all found descriptors
               else path string to existing header file acceptable
:param remove_rare_ratio: if descriptors found on train less then given ratio it will be removed from header.
                          if partial fit used, be sure to use finalize method.
                          unusable if headless mode set
:param return_domain: add AD bool column. if False molecule has new features


if self.__head_less:<EOL><INDENT>warn(f'<STR_LIT>')<EOL><DEDENT>elif not self.__head_generate:<EOL><INDENT>warn(f'<STR_LIT>')<EOL><DEDENT>elif not self.__head_dict:<EOL><INDENT>raise NotFittedError(f'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>if self.remove_rare_ratio:<EOL><INDENT>self.__clean_head(*self.__head_rare)<EOL>self.__prepare_header()<EOL>self.__head_rare = None<EOL><DEDENT>self.__head_generate = False<EOL><DEDENT>


if not self.__head_less:<EOL><INDENT>if not self.__head_generate:<EOL><INDENT>self.__head_generate = True<EOL><DEDENT>if self.__head_dict:<EOL><INDENT>self.__head_dump = self.__head_dict = None<EOL><DEDENT>if self.__head_rare is not None:<EOL><INDENT>self.__head_rare = None<EOL><DEDENT>self.delete_work_path()<EOL><DEDENT>

Reset internal data-dependent state.
        __init__ parameters are not touched.


if self.__head_less:<EOL><INDENT>raise AttributeError(f'<STR_LIT>')<EOL><DEDENT>elif not self.__head_dict:<EOL><INDENT>raise NotFittedError(f'<STR_LIT>')<EOL><DEDENT>return list(self.__head_dict.values())<EOL>


x = iter2array(x, dtype=(MoleculeContainer, CGRContainer))<EOL>if self.__head_less:<EOL><INDENT>warn(f'<STR_LIT>')<EOL>return self<EOL><DEDENT>self._reset()<EOL>self.__prepare(x)<EOL>return self<EOL>


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


expr_stack = []<EOL>def push_first(strg, loc, toks):<EOL><INDENT>expr_stack.append(toks[<NUM_LIT:0>])<EOL><DEDENT>def push_u_minus(strg, loc, toks):<EOL><INDENT>if toks and toks[<NUM_LIT:0>] == '<STR_LIT:->':<EOL><INDENT>expr_stack.append('<STR_LIT>')<EOL><DEDENT><DEDENT>point = Literal('<STR_LIT:.>')<EOL>_e = CaselessLiteral('<STR_LIT:E>')<EOL>fnumber = Combine(Word('<STR_LIT>' + nums, nums) +<EOL>Optional(point + Optional(Word(nums))) +<EOL>Optional(_e + Word('<STR_LIT>' + nums, nums)))<EOL>ident = Word(alphas, alphas + nums + '<STR_LIT>')<EOL>plus = Literal("<STR_LIT:+>")<EOL>minus = Literal("<STR_LIT:->")<EOL>mult = Literal("<STR_LIT:*>")<EOL>div = Literal("<STR_LIT:/>")<EOL>lpar = Literal("<STR_LIT:(>").suppress()<EOL>rpar = Literal("<STR_LIT:)>").suppress()<EOL>addop = plus | minus<EOL>multop = mult | div<EOL>expop = Literal("<STR_LIT>")<EOL>_pi = CaselessLiteral("<STR_LIT>")<EOL>x = CaselessLiteral("<STR_LIT:X>")<EOL>expr = Forward()<EOL>atom = (Optional("<STR_LIT:->") + (x | _pi | _e | fnumber | ident + lpar + expr + rpar).setParseAction(push_first) |<EOL>(lpar + expr.suppress() + rpar)).setParseAction(push_u_minus)<EOL>factor = Forward()<EOL>factor << atom + ZeroOrMore((expop + factor).setParseAction(push_first))<EOL>term = factor + ZeroOrMore((multop + factor).setParseAction(push_first))<EOL>expr << term + ZeroOrMore((addop + term).setParseAction(push_first))<EOL>expr.parseString(expression)<EOL>return expr_stack<EOL>

adopted from Paul McGuire example. http://pyparsing.wikispaces.com/file/view/fourFn.py


return list(header)<EOL>


pass<EOL>

empty command to allow help messages to work


parser.add_argument('<STR_LIT>', '<STR_LIT>',  help='<STR_LIT>', required=True)<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>',    help='<STR_LIT>', action='<STR_LIT:store_true>')<EOL>


env_config = parse_env_config(config, args.environment)<EOL>helper.rebuild_environment(args.environment)<EOL>if not args.dont_wait:<EOL><INDENT>helper.wait_for_environments(args.environment, health='<STR_LIT>', status='<STR_LIT>')<EOL><DEDENT>