deps = []<EOL>def specForDependency(name, version_spec, istest):<EOL><INDENT>shrinkwrap = self.getShrinkwrapMapping()<EOL>shrinkwrap_version_req = None<EOL>if name in shrinkwrap:<EOL><INDENT>shrinkwrap_version_req = shrinkwrap[name]<EOL>logger.debug(<EOL>'<STR_LIT>', self.getName(), shrinkwrap_version_req, name<EOL>)<EOL><DEDENT>return pack.DependencySpec(<EOL>name,<EOL>version_spec,<EOL>istest,<EOL>shrinkwrap_version_req = shrinkwrap_version_req,<EOL>specifying_module = self.getName()<EOL>)<EOL><DEDENT>deps += [specForDependency(x[<NUM_LIT:0>], x[<NUM_LIT:1>], False) for x in self.description.get('<STR_LIT>', {}).items()]<EOL>target_deps = self.description.get('<STR_LIT>', {})<EOL>if target is not None:<EOL><INDENT>for conf_key, target_conf_deps in target_deps.items():<EOL><INDENT>if _truthyConfValue(target.getConfigValue(conf_key)) or conf_key in target.getSimilarTo_Deprecated():<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>' %<EOL>(conf_key, self.getName())<EOL>)<EOL>deps += [specForDependency(x[<NUM_LIT:0>], x[<NUM_LIT:1>], False) for x in target_conf_deps.items()]<EOL><DEDENT><DEDENT><DEDENT>deps += [specForDependency(x[<NUM_LIT:0>], x[<NUM_LIT:1>], True) for x in self.description.get('<STR_LIT>', {}).items()]<EOL>target_deps = self.description.get('<STR_LIT>', {})<EOL>if target is not None:<EOL><INDENT>for conf_key, target_conf_deps in target_deps.items():<EOL><INDENT>if _truthyConfValue(target.getConfigValue(conf_key)) or conf_key in target.getSimilarTo_Deprecated():<EOL><INDENT>logger.debug(<EOL>'<STR_LIT>' %<EOL>(conf_key, self.getName())<EOL>)<EOL>deps += [specForDependency(x[<NUM_LIT:0>], x[<NUM_LIT:1>], True) for x in target_conf_deps.items()]<EOL><DEDENT><DEDENT><DEDENT>seen = set()<EOL>r = []<EOL>for dep in deps:<EOL><INDENT>if not dep.name in seen:<EOL><INDENT>r.append(dep)<EOL>seen.add(dep.name)<EOL><DEDENT><DEDENT>return r<EOL>

Returns [DependencySpec]

            These are returned in the order that they are listed in the
            component description file: this is so that dependency resolution
            proceeds in a predictable way.


path = _splitPath(path)<EOL>for config in self.configs.values():<EOL><INDENT>cur = config<EOL>for el in path:<EOL><INDENT>if el in cur:<EOL><INDENT>cur = cur[el]<EOL><DEDENT>else:<EOL><INDENT>cur = None<EOL>break<EOL><DEDENT><DEDENT>if cur is not None:<EOL><INDENT>return cur<EOL><DEDENT><DEDENT>return None<EOL>

return a configuration value

            usage:
                get('section.property')

            Note that currently array indexes are not supported. You must
            get the whole array.

            returns None if any path element or the property is missing


return registry_access.unpublish(<EOL>self.getRegistryNamespace(),<EOL>self.getName(),<EOL>self.getVersion(),<EOL>registry=registry<EOL>)<EOL>

Try to un-publish the current version. Return a description of any
            errors that occured, or None if successful.


return self.error<EOL>

If this isn't a valid component/target, return some sort of
            explanation about why that is.


return self.version_req<EOL>

return the dependency specification ignoring any shrinkwrap


if self.origin_info is None:<EOL><INDENT>self.origin_info = {}<EOL>try:<EOL><INDENT>self.origin_info = ordered_json.load(os.path.join(self.path, Origin_Info_Fname))<EOL><DEDENT>except IOError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return self.origin_info.get('<STR_LIT:url>', None)<EOL>

Read the .yotta_origin.json file (if present), and return the value
            of the 'url' property


return self.version<EOL>

Return the version as specified by the package file.
            This will always be a real version: 1.2.3, not a hash or a URL.

            Note that a component installed through a URL still provides a real
            version - so if the first component to depend on some component C
            depends on it via a URI, and a second component depends on a
            specific version 1.2.3, dependency resolution will only succeed if
            the version of C obtained from the URL happens to be 1.2.3


script = self.description.get('<STR_LIT>', {}).get(scriptname, None)<EOL>if script is not None:<EOL><INDENT>if isinstance(script, str) or isinstance(script, type(u'<STR_LIT>')):<EOL><INDENT>import shlex<EOL>script = shlex.split(script)<EOL><DEDENT>if len(script) and script[<NUM_LIT:0>].lower().endswith('<STR_LIT>'):<EOL><INDENT>if not os.path.isabs(script[<NUM_LIT:0>]):<EOL><INDENT>absscript = os.path.abspath(os.path.join(self.path, script[<NUM_LIT:0>]))<EOL>logger.debug('<STR_LIT>', script[<NUM_LIT:0>], absscript)<EOL>script[<NUM_LIT:0>] = absscript<EOL><DEDENT>import sys<EOL>script = [sys.executable] + script<EOL><DEDENT><DEDENT>return script<EOL>

Return the specified script command. If the first part of the
            command is a .py file, then the current python interpreter is
            prepended.

            If the script is a single string, rather than an array, it is
            shlex-split.


<EOL>if os.path.exists(program) and os.access(program, os.X_OK):<EOL><INDENT>return program<EOL><DEDENT>for path in os.environ['<STR_LIT>'].split(os.pathsep):<EOL><INDENT>path = path.strip('<STR_LIT:">')<EOL>for ext in os.environ.get('<STR_LIT>', '<STR_LIT>').split(os.pathsep):<EOL><INDENT>progpath = os.path.join(path, program + ext)<EOL>if os.path.exists(progpath) and os.access(progpath, os.X_OK):<EOL><INDENT>return progpath<EOL><DEDENT><DEDENT><DEDENT>return None<EOL>

look for "program" in PATH (respecting PATHEXT), and return the path to
        it, or None if it was not found


def generateRecursive(self, component, all_components, builddir=None, modbuilddir=None, processed_components=None, application=None):

assert(self.configured)<EOL>if builddir is None:<EOL><INDENT>builddir = self.buildroot<EOL><DEDENT>if modbuilddir is None:<EOL><INDENT>modbuilddir = os.path.join(builddir, '<STR_LIT>')<EOL><DEDENT>if processed_components is None:<EOL><INDENT>processed_components = dict()<EOL><DEDENT>if not self.target:<EOL><INDENT>yield '<STR_LIT>' % self.target<EOL><DEDENT>toplevel = not len(processed_components)<EOL>logger.debug('<STR_LIT>' % (component, self.target))<EOL>recursive_deps = component.getDependenciesRecursive(<EOL>available_components = all_components,<EOL>target = self.target,<EOL>available_only = True,<EOL>test = True<EOL>)<EOL>dependencies = component.getDependencies(<EOL>all_components,<EOL>target = self.target,<EOL>available_only = True,<EOL>test = True<EOL>)<EOL>for name, dep in dependencies.items():<EOL><INDENT>if not dep:<EOL><INDENT>if dep.isTestDependency():<EOL><INDENT>logger.debug('<STR_LIT>' % (name, component))<EOL><DEDENT>else:<EOL><INDENT>yield '<STR_LIT>' % (name, component)<EOL><DEDENT><DEDENT><DEDENT>processed_components[component.getName()] = component<EOL>new_dependencies = OrderedDict([(name,c) for name,c in dependencies.items() if c and not name in processed_components])<EOL>self.generate(builddir, modbuilddir, component, new_dependencies, dependencies, recursive_deps, application, toplevel)<EOL>logger.debug('<STR_LIT>' % component)<EOL>for d in recursive_deps.values():<EOL><INDENT>logger.debug('<STR_LIT>' % d)<EOL><DEDENT>processed_components.update(new_dependencies)<EOL>for name, c in new_dependencies.items():<EOL><INDENT>for error in self.generateRecursive(<EOL>c, all_components, os.path.join(modbuilddir, name), modbuilddir, processed_components, application=application<EOL>):<EOL><INDENT>yield error<EOL><DEDENT><DEDENT>

generate top-level CMakeLists for this component and its
            dependencies: the CMakeLists are all generated in self.buildroot,
            which MUST be out-of-source

            !!! NOTE: experimenting with a slightly different way of doing
            things here, this function is a generator that yields any errors
            produced, so the correct use is:

            for error in gen.generateRecursive(...):
                print(error)


def configure(self, component, all_dependencies):

r = {}<EOL>builddir = self.buildroot<EOL>available_dependencies = OrderedDict((k, v) for k, v in all_dependencies.items() if v)<EOL>self.set_toplevel_definitions = '<STR_LIT>'<EOL>if self.build_info_include_file is None:<EOL><INDENT>self.build_info_include_file, build_info_definitions = self.getBuildInfo(component.path, builddir)<EOL>self.set_toplevel_definitions += build_info_definitions<EOL><DEDENT>if self.config_include_file is None:<EOL><INDENT>self.config_include_file, config_definitions, self.config_json_file = self._getConfigData(available_dependencies, component, builddir, self.build_info_include_file)<EOL>self.set_toplevel_definitions += config_definitions<EOL><DEDENT>self.configured = True<EOL>return {<EOL>'<STR_LIT>': self.config_include_file,<EOL>'<STR_LIT>': self.config_json_file,<EOL>'<STR_LIT>': self.build_info_include_file<EOL>}<EOL>

Ensure all config-time files have been generated. Return a
            dictionary of generated items.


def generate(<EOL>self, builddir, modbuilddir, component, active_dependencies, immediate_dependencies, all_dependencies, application, toplevel<EOL>):

include_root_dirs = '<STR_LIT>'<EOL>if application is not None and component is not application:<EOL><INDENT>include_root_dirs += '<STR_LIT>' % replaceBackslashes(application.path)<EOL><DEDENT>include_sys_dirs = '<STR_LIT>'<EOL>include_other_dirs = '<STR_LIT>'<EOL>for name, c in itertools.chain(((component.getName(), component),), all_dependencies.items()):<EOL><INDENT>if c is not component and c.isTestDependency():<EOL><INDENT>continue<EOL><DEDENT>include_root_dirs += '<STR_LIT>' % replaceBackslashes(c.path)<EOL>dep_sys_include_dirs = c.getExtraSysIncludes()<EOL>for d in dep_sys_include_dirs:<EOL><INDENT>include_sys_dirs += '<STR_LIT>' % replaceBackslashes(os.path.join(c.path, d))<EOL><DEDENT>dep_extra_include_dirs = c.getExtraIncludes()<EOL>for d in dep_extra_include_dirs:<EOL><INDENT>include_other_dirs += '<STR_LIT>' % replaceBackslashes(os.path.join(c.path, d))<EOL><DEDENT><DEDENT>add_depend_subdirs = '<STR_LIT>'<EOL>for name, c in active_dependencies.items():<EOL><INDENT>depend_subdir = replaceBackslashes(os.path.join(modbuilddir, name))<EOL>relpath = replaceBackslashes(os.path.relpath(depend_subdir, self.buildroot))<EOL>add_depend_subdirs +='<STR_LIT>''<STR_LIT>''<STR_LIT>''<STR_LIT>'% (depend_subdir, relpath)<EOL><DEDENT>delegate_to_existing = None<EOL>delegate_build_dir = None<EOL>module_is_empty = False<EOL>if os.path.isfile(os.path.join(component.path, '<STR_LIT>')) and not component.ignores('<STR_LIT>'):<EOL><INDENT>delegate_to_existing = component.path<EOL>add_own_subdirs = []<EOL>logger.debug("<STR_LIT>", builddir)<EOL>delegate_build_dir = os.path.join(builddir, '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>self._validateListedSubdirsExist(component)<EOL>subdirs = self._listSubDirectories(component, toplevel)<EOL>manual_subdirs      = subdirs['<STR_LIT>']<EOL>autogen_subdirs     = subdirs['<STR_LIT>']<EOL>binary_subdirs      = subdirs['<STR_LIT>']<EOL>lib_subdirs         = subdirs['<STR_LIT>']<EOL>test_subdirs        = subdirs['<STR_LIT:test>']<EOL>resource_subdirs    = subdirs['<STR_LIT>']<EOL>header_subdirs      = subdirs['<STR_LIT>']<EOL>logger.debug("<STR_LIT>", component, lib_subdirs, binary_subdirs)<EOL>add_own_subdirs = []<EOL>for f in manual_subdirs:<EOL><INDENT>if os.path.isfile(os.path.join(component.path, f, '<STR_LIT>')):<EOL><INDENT>if f in test_subdirs and component.isTestDependency():<EOL><INDENT>continue<EOL><DEDENT>add_own_subdirs.append(<EOL>(os.path.join(component.path, f), f)<EOL>)<EOL><DEDENT><DEDENT>all_subdirs = manual_subdirs + [x[<NUM_LIT:0>] for x in autogen_subdirs]<EOL>if component.isTestDependency():<EOL><INDENT>if len(autogen_subdirs) + len(add_own_subdirs) == <NUM_LIT:0>:<EOL><INDENT>module_is_empty = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if len(autogen_subdirs) + len(add_own_subdirs) <= len(test_subdirs):<EOL><INDENT>module_is_empty = True<EOL><DEDENT><DEDENT>for f, source_files in autogen_subdirs:<EOL><INDENT>if f in test_subdirs:<EOL><INDENT>if component.isTestDependency():<EOL><INDENT>continue<EOL><DEDENT>self.generateTestDirList(<EOL>builddir, f, source_files, component, immediate_dependencies, toplevel=toplevel, module_is_empty=module_is_empty<EOL>)<EOL><DEDENT>else:<EOL><INDENT>if f in binary_subdirs:<EOL><INDENT>is_executable = True<EOL>object_name = binary_subdirs[f]<EOL><DEDENT>else:<EOL><INDENT>assert(f in lib_subdirs)<EOL>object_name = lib_subdirs[f]<EOL><DEDENT>for header_dir, header_files in header_subdirs:<EOL><INDENT>source_files.extend(header_files)<EOL><DEDENT>self.generateSubDirList(<EOL>builddir = builddir,<EOL>dirname = f,<EOL>source_files = source_files,<EOL>component = component,<EOL>all_subdirs = all_subdirs,<EOL>immediate_dependencies = immediate_dependencies,<EOL>object_name = object_name,<EOL>resource_subdirs = resource_subdirs,<EOL>is_executable = (f in binary_subdirs)<EOL>)<EOL><DEDENT>add_own_subdirs.append(<EOL>(os.path.join(builddir, f), f)<EOL>)<EOL><DEDENT>if component.isTestDependency():<EOL><INDENT>test_subdirs = []<EOL><DEDENT>if module_is_empty:<EOL><INDENT>if len(binary_subdirs):<EOL><INDENT>logger.warning('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>add_own_subdirs.append(self.createDummyLib(<EOL>component, builddir, [x[<NUM_LIT:0>] for x in immediate_dependencies.items() if not x[<NUM_LIT:1>].isTestDependency()]<EOL>))<EOL><DEDENT><DEDENT><DEDENT>toolchain_file_path = os.path.join(builddir, '<STR_LIT>')<EOL>if toplevel:<EOL><INDENT>template = jinja_environment.get_template('<STR_LIT>')<EOL>file_contents = template.render({  <EOL>"<STR_LIT>": self.target.getToolchainFiles()<EOL>})<EOL>self._writeFile(toolchain_file_path, file_contents)<EOL><DEDENT>template = jinja_environment.get_template('<STR_LIT>')<EOL>relpath = os.path.relpath(builddir, self.buildroot)<EOL>file_contents = template.render({ <EOL>"<STR_LIT>": toplevel,<EOL>"<STR_LIT>": self.target.getName(),<EOL>"<STR_LIT>": self.set_toplevel_definitions,<EOL>"<STR_LIT>": toolchain_file_path,<EOL>"<STR_LIT>": component,<EOL>"<STR_LIT>": relpath,<EOL>"<STR_LIT>": include_root_dirs,<EOL>"<STR_LIT>": include_sys_dirs,<EOL>"<STR_LIT>": include_other_dirs,<EOL>"<STR_LIT>": add_depend_subdirs,<EOL>"<STR_LIT>": add_own_subdirs,<EOL>"<STR_LIT>": self.config_include_file,<EOL>"<STR_LIT>": delegate_to_existing,<EOL>"<STR_LIT>": delegate_build_dir,<EOL>"<STR_LIT>": active_dependencies,<EOL>"<STR_LIT>": module_is_empty,<EOL>"<STR_LIT>": self.target.getAdditionalIncludes()<EOL>})<EOL>self._writeFile(os.path.join(builddir, '<STR_LIT>'), file_contents)<EOL>

active_dependencies is the dictionary of components that need to be
            built for this component, but will not already have been built for
            another component.


<EOL>s = b'<STR_LIT>'<EOL>n = int(n)<EOL>pack = struct.pack<EOL>while n > <NUM_LIT:0>:<EOL><INDENT>s = pack('<STR_LIT>', n & <NUM_LIT>) + s<EOL>n = n >> <NUM_LIT:32><EOL><DEDENT>for i in range(len(s)):<EOL><INDENT>if s[i] != '<STR_LIT>':<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>s = '<STR_LIT>'<EOL>i = <NUM_LIT:0><EOL><DEDENT>s = s[i:]<EOL>if blocksize > <NUM_LIT:0> and len(s) % blocksize:<EOL><INDENT>s = (blocksize - len(s) % blocksize) * '<STR_LIT>' + s<EOL><DEDENT>return s<EOL>

long_to_bytes(n:long, blocksize:int) : string
    Convert a long integer to a byte string.

    If optional blocksize is given and greater than zero, pad the front of the
    byte string with binary zeros so that the length is a multiple of
    blocksize.


if cache_key is None:<EOL><INDENT>raise NotInCache('<STR_LIT>')<EOL><DEDENT>cache_key = _encodeCacheKey(cache_key)<EOL>cache_dir = folders.cacheDirectory()<EOL>fsutils.mkDirP(cache_dir)<EOL>path = os.path.join(cache_dir, cache_key)<EOL>logger.debug('<STR_LIT>', path, to_directory)<EOL>try:<EOL><INDENT>unpackFrom(path, to_directory)<EOL>try:<EOL><INDENT>shutil.copy(path + '<STR_LIT>', os.path.join(to_directory, '<STR_LIT>'))<EOL><DEDENT>except IOError as e:<EOL><INDENT>if e.errno == errno.ENOENT:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>cache_logger.debug('<STR_LIT>', cache_key, to_directory)<EOL>return<EOL><DEDENT>except IOError as e:<EOL><INDENT>if e.errno == errno.ENOENT:<EOL><INDENT>cache_logger.debug('<STR_LIT>', cache_key)<EOL>raise NotInCache('<STR_LIT>')<EOL><DEDENT><DEDENT>except OSError as e:<EOL><INDENT>if e.errno == errno.ENOTEMPTY:<EOL><INDENT>logger.error('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>

If the specified cache key exists, unpack the tarball into the
        specified directory, otherwise raise NotInCache (a KeyError subclass).


def _downloadToCache(stream, hashinfo={}, origin_info=dict()):

hash_name  = None<EOL>hash_value = None<EOL>m = None<EOL>if len(hashinfo):<EOL><INDENT>for h in ('<STR_LIT>',):<EOL><INDENT>if h in hashinfo:<EOL><INDENT>hash_name  = h<EOL>hash_value = hashinfo[h]<EOL>m = getattr(hashlib, h)()<EOL>break<EOL><DEDENT><DEDENT>if not hash_name:<EOL><INDENT>logger.warning('<STR_LIT>', hashinfo)<EOL><DEDENT><DEDENT>cache_dir = folders.cacheDirectory()<EOL>fsutils.mkDirP(cache_dir)<EOL>file_size = <NUM_LIT:0><EOL>(download_file, download_fname) = tempfile.mkstemp(dir=cache_dir, suffix='<STR_LIT>')<EOL>with os.fdopen(download_file, '<STR_LIT:wb>') as f:<EOL><INDENT>f.seek(<NUM_LIT:0>)<EOL>for chunk in stream.iter_content(<NUM_LIT>):<EOL><INDENT>f.write(chunk)<EOL>if hash_name:<EOL><INDENT>m.update(chunk)<EOL><DEDENT><DEDENT>if hash_name:<EOL><INDENT>calculated_hash = m.hexdigest()<EOL>logger.debug(<EOL>'<STR_LIT>' % (<EOL>hash_name, calculated_hash, hash_value<EOL>)<EOL>)<EOL>if hash_value and (hash_value != calculated_hash):<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT><DEDENT>file_size = f.tell()<EOL>logger.debug('<STR_LIT>', file_size, download_fname)<EOL>f.truncate()<EOL><DEDENT>extended_origin_info = {<EOL>'<STR_LIT>': hashinfo,<EOL>'<STR_LIT:size>': file_size<EOL>}<EOL>extended_origin_info.update(origin_info)<EOL>ordered_json.dump(download_fname + '<STR_LIT>', extended_origin_info)<EOL>return os.path.basename(download_fname)<EOL>

Download the specified stream to a temporary cache directory, and
        returns a cache key that can be used to access/remove the file.
        You should use either removeFromCache(cache_key) or _moveCachedFile to
        move the downloaded file to a known key after downloading.


@sometimesPruneCache(<NUM_LIT>)<EOL>def unpackTarballStream(stream, into_directory, hash={}, cache_key=None, origin_info=dict()):

cache_key = _encodeCacheKey(cache_key)<EOL>if getMaxCachedModules() == <NUM_LIT:0>:<EOL><INDENT>cache_key = None<EOL><DEDENT>new_cache_key = _downloadToCache(stream, hash, origin_info)<EOL>unpackFromCache(new_cache_key, into_directory)<EOL>if cache_key is None:<EOL><INDENT>removeFromCache(new_cache_key)<EOL><DEDENT>else:<EOL><INDENT>_moveCachedFile(new_cache_key, cache_key)<EOL><DEDENT>

Unpack a responses stream that contains a tarball into a directory. If
        a hash is provided, then it will be used as a cache key (for future
        requests you can try to retrieve the key value from the cache first,
        before making the request)


@classmethod<EOL><INDENT>def createFromSource(cls, vs, name=None):<DEDENT>

return GitComponent(vs.location, vs.spec, vs.semantic_spec)<EOL>

returns a git component for any git:// url, or None if this is not
            a git component.

            Normally version will be empty, unless the original url was of the
            form 'git://...#version', which can be used to grab a particular
            tag or branch, or ...#>=1.2.3, which can be used to specify
            semantic version specifications on tags.


return [GitCloneVersion('<STR_LIT>', t, self) for t in self.vcs.tags()]<EOL>

return a list of GitCloneVersion objects for all tags


return [GitCloneVersion('<STR_LIT>', b, self) for b in self.vcs.branches()]<EOL>

return a list of GitCloneVersion objects for the tip of each branch


<EOL>from yotta.lib import sourceparse<EOL>errors = []<EOL>available_versions = {}<EOL>for mod in dependency_list.get('<STR_LIT>', []):<EOL><INDENT>available_versions[mod['<STR_LIT:name>']] = mod['<STR_LIT:version>']<EOL><DEDENT>for mod in dependency_list.get('<STR_LIT>', []):<EOL><INDENT>for spec_info in mod.get('<STR_LIT>', []):<EOL><INDENT>name = spec_info['<STR_LIT:name>']<EOL>spec = spec_info['<STR_LIT:version>']<EOL>if spec_info.get('<STR_LIT>', False):<EOL><INDENT>continue<EOL><DEDENT>if not name in available_versions:<EOL><INDENT>errors.append('<STR_LIT>' % (<EOL>name, mod['<STR_LIT:name>']<EOL>))<EOL><DEDENT>else:<EOL><INDENT>available_version = available_versions[name]<EOL>parsed_spec = sourceparse.parseSourceURL(spec)<EOL>if not parsed_spec.semanticSpecMatches(available_version):<EOL><INDENT>errors.append('<STR_LIT>' % (<EOL>name, available_version, parsed_spec.semanticSpec(), mod['<STR_LIT:name>']<EOL>))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return errors<EOL>

return a list of errors encountered (e.g. dependency missing or
        specification not met


mean, cov = _mean_cov(<EOL>offset, G, heritability, causal_variants, causal_variance, random_state<EOL>)<EOL>link = LogLink()<EOL>lik = PoissonProdLik(link)<EOL>sampler = GGPSampler(lik, mean, cov)<EOL>return sampler.sample(random_state)<EOL>

Poisson likelihood sampling.

    Parameters
    ----------
    random_state : random_state
        Set the initial random state.

    Example
    -------

    .. doctest::

        >>> from glimix_core.random import poisson_sample
        >>> from numpy.random import RandomState
        >>> offset = -0.5
        >>> G = [[0.5, -1], [2, 1]]
        >>> poisson_sample(offset, G, random_state=RandomState(0))
        array([0, 6])


link = LogitLink()<EOL>mean, cov = _mean_cov(<EOL>offset, G, heritability, causal_variants, causal_variance, random_state<EOL>)<EOL>lik = BinomialProdLik(ntrials, link)<EOL>sampler = GGPSampler(lik, mean, cov)<EOL>return sampler.sample(random_state)<EOL>

Binomial likelihood sampling.

    Parameters
    ----------
    random_state : random_state
        Set the initial random state.

    Example
    -------

    .. doctest::

        >>> from glimix_core.random import binomial_sample
        >>> from numpy.random import RandomState
        >>> ntrials = [5, 15]
        >>> offset = 0.5
        >>> G = [[1, -1], [2, 1]]
        >>> binomial_sample(ntrials, offset, G, random_state=RandomState(0))
        array([ 2., 14.])


return unvec(self._vecB.value, (self.X.shape[<NUM_LIT:1>], self.A.shape[<NUM_LIT:0>]))<EOL>


self._A = asarray(A, float)<EOL>self._X = asarray(X, float)<EOL>vecB = zeros((X.shape[<NUM_LIT:1>], A.shape[<NUM_LIT:0>])).ravel()<EOL>self._vecB = Vector(vecB)<EOL>self._nparams = vecB.size<EOL>Function.__init__(self, "<STR_LIT>", vecB=self._vecB)<EOL>

Constructor.

Parameters
----------
A : array_like
    p×p array.
X : array_like
    n×c array.


return self._X<EOL>


return self._nparams<EOL>


return self._A<EOL>


return add.reduce([mean.value() for mean in self._means])<EOL>

Sum of mean vectors, 𝐟₀ + 𝐟₁ + ….

Returns
-------
𝐦 : ndarray
    𝐟₀ + 𝐟₁ + ….


grad = {}<EOL>for i, f in enumerate(self._means):<EOL><INDENT>for varname, g in f.gradient().items():<EOL><INDENT>grad[f"<STR_LIT>"] = g<EOL><DEDENT><DEDENT>return grad<EOL>

Sum of mean function derivatives.

Returns
-------
∂𝐦 : dict
    ∂𝐟₀ + ∂𝐟₁ + ….


self._offset = Scalar(<NUM_LIT:0.0>)<EOL>self._offset.bounds = (-<NUM_LIT>, +<NUM_LIT:200>)<EOL>self._n = n<EOL>Function.__init__(self, "<STR_LIT>", offset=self._offset)<EOL>

Constructor.

Parameters
----------
n : int
    Size of the 𝟏 array.


return dict(offset=ones(self._n))<EOL>

Gradient of the offset function.

Returns
-------
offset : (n,) ndarray
    Vector 𝟏.


return self._X @ self._effsizes<EOL>

Linear mean function.

Returns
-------
𝐦 : (n,) ndarray
    X𝜶.


X = asarray(X, float)<EOL>m = X.shape[<NUM_LIT:1>]<EOL>self._effsizes = Vector(zeros(m))<EOL>self._effsizes.bounds = [(-<NUM_LIT>, +<NUM_LIT:200>)] * m<EOL>self._X = X<EOL>Function.__init__(self, "<STR_LIT>", effsizes=self._effsizes)<EOL>

Constructor.

Parameters
----------
X : array_like
    Covariates X, from X𝜶.


return self._I.shape[<NUM_LIT:0>]<EOL>

Dimension of the matrix, d.

It corresponds to the number of rows and to the number of columns.


return self.scale * self._I<EOL>

Covariance matrix.

Returns
-------
K : ndarray
    s⋅I, for scale s and a d×d identity matrix I.


self._dim = dim<EOL>self._I = eye(dim)<EOL>self._logscale = Scalar(<NUM_LIT:0.0>)<EOL>Function.__init__(self, "<STR_LIT>", logscale=self._logscale)<EOL>self._logscale.bounds = (-<NUM_LIT>, +<NUM_LIT:10>)<EOL>

Constructor.

Parameters
----------
dim : int
    Matrix dimension, d.


return self.scale * self._K0<EOL>

Covariance matrix, s⋅K₀.

Returns
-------
K : ndarray
    s⋅K₀.


return float(exp(self._logscale.value))<EOL>


n = self._L.shape[<NUM_LIT:0>]<EOL>return (n, n)<EOL>


Listen to parameters change.

Parameters
----------
func : callable
    Function to be called when a parameter changes.


return self._Lu.value<EOL>


m = len(self._tril1[<NUM_LIT:0>])<EOL>self._L[self._tril1] = self._Lu.value[:m]<EOL>self._L[self._diag] = exp(self._Lu.value[m:])<EOL>return self._L<EOL>

Lower-triangular matrix L such that K = LLᵀ + ϵI.

Returns
-------
L : (d, d) ndarray
    Lower-triangular matrix.


L = self.L<EOL>self._grad_Lu[:] = <NUM_LIT:0><EOL>for i in range(len(self._tril1[<NUM_LIT:0>])):<EOL><INDENT>row = self._tril1[<NUM_LIT:0>][i]<EOL>col = self._tril1[<NUM_LIT:1>][i]<EOL>self._grad_Lu[row, :, i] = L[:, col]<EOL>self._grad_Lu[:, row, i] += L[:, col]<EOL><DEDENT>m = len(self._tril1[<NUM_LIT:0>])<EOL>for i in range(len(self._diag[<NUM_LIT:0>])):<EOL><INDENT>row = self._diag[<NUM_LIT:0>][i]<EOL>col = self._diag[<NUM_LIT:1>][i]<EOL>self._grad_Lu[row, :, m + i] = L[row, col] * L[:, col]<EOL>self._grad_Lu[:, row, m + i] += L[row, col] * L[:, col]<EOL><DEDENT>return {"<STR_LIT>": self._grad_Lu}<EOL>

Derivative of the covariance matrix over the parameters of L.

Returns
-------
Lu : ndarray
    Derivative of K over the lower triangular part of L.


K = dot(self.L, self.L.T)<EOL>return K + self._epsilon * eye(K.shape[<NUM_LIT:0>])<EOL>

Covariance matrix.

Returns
-------
K : ndarray
    Matrix K = LLᵀ + ϵI, for a very small positive number ϵ.


grad = {}<EOL>for i, f in enumerate(self._covariances):<EOL><INDENT>for varname, g in f.gradient().items():<EOL><INDENT>grad[f"<STR_LIT>"] = g<EOL><DEDENT><DEDENT>return grad<EOL>

Sum of covariance function derivatives.

Returns
-------
dict
    ∂K₀ + ∂K₁ + ⋯


return add.reduce([cov.value() for cov in self._covariances])<EOL>

r"""
        Sum of covariance matrices.

        Returns
        -------
        K : ndarray
            K₀ + K₁ + ⋯


self._covariances = [c for c in covariances]<EOL>Function.__init__(self, "<STR_LIT>", composite=self._covariances)<EOL>

Constructor.

Parameters
----------
covariances : list
    List of covariance functions.


self._L = ones((n, m))<EOL>self._Lu = Vector(self._L.ravel())<EOL>Function.__init__(self, "<STR_LIT>", Lu=self._Lu)<EOL>

Constructor.

Parameters
----------
n : int
    Covariance dimension.
m : int
    Upper limit of the covariance matrix rank.


return self._L<EOL>

Matrix L from K = LLᵀ.

Returns
-------
L : (n, m) ndarray
    Parametric matrix.


L = self.L<EOL>n = self.L.shape[<NUM_LIT:0>]<EOL>grad = {"<STR_LIT>": zeros((n, n, n * self._L.shape[<NUM_LIT:1>]))}<EOL>for ii in range(self._L.shape[<NUM_LIT:0>] * self._L.shape[<NUM_LIT:1>]):<EOL><INDENT>row = ii // self._L.shape[<NUM_LIT:1>]<EOL>col = ii % self._L.shape[<NUM_LIT:1>]<EOL>grad["<STR_LIT>"][row, :, ii] = L[:, col]<EOL>grad["<STR_LIT>"][:, row, ii] += L[:, col]<EOL><DEDENT>return grad<EOL>

Derivative of the covariance matrix over the lower triangular, flat part of L.

It is equal to

    ∂K/∂Lᵢⱼ = ALᵀ + LAᵀ,

where Aᵢⱼ is an n×m matrix of zeros except at [Aᵢⱼ]ᵢⱼ=1.

Returns
-------
Lu : ndarray
    Derivative of K over the lower-triangular, flat part of L.


return dot(self.L, self.L.T)<EOL>

Covariance matrix.

Returns
-------
K : (n, n) ndarray
    K = LLᵀ.


self._cache = {"<STR_LIT>": None}<EOL>self._C0 = LRFreeFormCov(dim, rank)<EOL>self._C0.name = "<STR_LIT>"<EOL>self._C1 = FreeFormCov(dim)<EOL>self._C1.name = "<STR_LIT>"<EOL>G = atleast_2d(asarray(G, float))<EOL>self._G = G<EOL>self._Sxe = None<EOL>self._Sx = None<EOL>self._Lx = None<EOL>self._LxG = None<EOL>self._diag_LxGGLx = None<EOL>self._Lxe = None<EOL>self._LxGe = None<EOL>self._diag_LxGGLxe = None<EOL>Function.__init__(<EOL>self, "<STR_LIT>", composite=[("<STR_LIT>", self._C0), ("<STR_LIT>", self._C1)]<EOL>)<EOL>self._C0.listen(self._parameters_update)<EOL>self._C1.listen(self._parameters_update)<EOL>

Constructor.

Parameters
----------
dim : int
    Dimension d for the square matrices C₀ and C₁.
rank : int
    Maximum rank of the C₁ matrix.


return self._C1<EOL>


from scipy.linalg import svd<EOL>from numpy_sugar.linalg import ddot<EOL>U, S, _ = svd(self._G, full_matrices=False, check_finite=False)<EOL>if U.shape[<NUM_LIT:1>] < self._G.shape[<NUM_LIT:1>]:<EOL><INDENT>return ddot(U, S)<EOL><DEDENT>return self._G<EOL>

Result of US from the SVD decomposition G = USVᵀ.


self._C0.listen(func)<EOL>self._C1.listen(func)<EOL>


self._init_svd()<EOL>return -log(self._De).sum() + self.G.shape[<NUM_LIT:0>] * self.C1.logdet()<EOL>

Implements log|K| = - log|D| + n⋅log|C₁|.

Returns
-------
logdet : float
    Log-determinant of K.


return dict(logscale=self.value())<EOL>

Derivative of the covariance matrix over log(s).

Returns
-------
logscale : ndarray
    s⋅XXᵀ.


self._logscale = Scalar(<NUM_LIT:0.0>)<EOL>self._X = X<EOL>Function.__init__(self, "<STR_LIT>", logscale=self._logscale)<EOL>self._logscale.bounds = (-<NUM_LIT>, +<NUM_LIT:10>)<EOL>

Constructor.

Parameters
----------
X : array_like
    Matrix X from K = s⋅XXᵀ.


return sqrt(self.null_beta_covariance.diagonal())<EOL>

Standard errors of the optimal 𝜷.

Returns
-------
beta_se : ndarray
    Square root of the diagonal of the beta covariance.


def _bstar_1effect(beta, alpha, yTBy, yTBX, yTBM, XTBX, XTBM, MTBM):

from numpy_sugar import epsilon<EOL>from numpy_sugar.linalg import dotd<EOL>from numpy import sum<EOL>r = full(MTBM[<NUM_LIT:0>].shape[<NUM_LIT:0>], yTBy)<EOL>r -= <NUM_LIT:2> * add.reduce([dot(i, beta) for i in yTBX])<EOL>r -= <NUM_LIT:2> * add.reduce([i * alpha for i in yTBM])<EOL>r += add.reduce([dotd(beta.T, dot(i, beta)) for i in XTBX])<EOL>r += add.reduce([dotd(beta.T, i * alpha) for i in XTBM])<EOL>r += add.reduce([sum(alpha * i * beta, axis=<NUM_LIT:0>) for i in XTBM])<EOL>r += add.reduce([alpha * i.ravel() * alpha for i in MTBM])<EOL>return clip(r, epsilon.tiny, inf)<EOL>

Same as :func:`_bstar_set` but for single-effect.


def _bstar_set(beta, alpha, yTBy, yTBX, yTBM, XTBX, XTBM, MTBM):

from numpy_sugar import epsilon<EOL>r = yTBy<EOL>r -= <NUM_LIT:2> * add.reduce([i @ beta for i in yTBX])<EOL>r -= <NUM_LIT:2> * add.reduce([i @ alpha for i in yTBM])<EOL>r += add.reduce([beta.T @ i @ beta for i in XTBX])<EOL>r += <NUM_LIT:2> * add.reduce([beta.T @ i @ alpha for i in XTBM])<EOL>r += add.reduce([alpha.T @ i @ alpha for i in MTBM])<EOL>return clip(r, epsilon.tiny, inf)<EOL>

Compute -2𝐲ᵀBEⱼ𝐛ⱼ + (𝐛ⱼEⱼ)ᵀBEⱼ𝐛ⱼ.

For 𝐛ⱼ = [𝜷ⱼᵀ 𝜶ⱼᵀ]ᵀ.


from numpy_sugar.linalg import ddot<EOL>from numpy_sugar import is_all_finite<EOL>M = asarray(M, float)<EOL>if M.shape[<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>return {<EOL>"<STR_LIT>": self.null_lml(),<EOL>"<STR_LIT>": self.null_beta,<EOL>"<STR_LIT>": self.null_beta_se,<EOL>"<STR_LIT>": empty((<NUM_LIT:0>)),<EOL>"<STR_LIT>": empty((<NUM_LIT:0>)),<EOL>"<STR_LIT>": self.null_scale,<EOL>}<EOL><DEDENT>if not is_all_finite(M):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>MTQ = [dot(M.T, Q) for Q in self._QS[<NUM_LIT:0>] if Q.size > <NUM_LIT:0>]<EOL>yTBM = [dot(i, j.T) for (i, j) in zip(self._yTQDi, MTQ)]<EOL>XTBM = [dot(i, j.T) for (i, j) in zip(self._XTQDi, MTQ)]<EOL>D = self._D<EOL>MTBM = [ddot(i, <NUM_LIT:1> / j) @ i.T for i, j in zip(MTQ, D) if j.min() > <NUM_LIT:0>]<EOL>return self._multicovariate_set(yTBM, XTBM, MTBM)<EOL>

LML, fixed-effect sizes, and scale of the candidate set.

Parameters
----------
M : array_like
    Fixed-effects set.

Returns
-------
lml : float
    Log of the marginal likelihood.
effsizes0 : ndarray
    Covariates fixed-effect sizes.
effsizes0_se : ndarray
    Covariates fixed-effect size standard errors.
effsizes1 : ndarray
    Candidate set fixed-effect sizes.
effsizes1_se : ndarray
    Candidate fixed-effect size standard errors.
scale : ndarray
    Optimal scale.


self._Y = asarray(Y, float)<EOL>self._A = asarray(A, float)<EOL>self._X = asarray(X, float)<EOL>self._G = asarray(G, float)<EOL>self._H = terms["<STR_LIT:H>"]<EOL>self._logdetK = terms["<STR_LIT>"]<EOL>self._W = terms["<STR_LIT>"]<EOL>self._yKiy = terms["<STR_LIT>"]<EOL>self._WA = terms["<STR_LIT>"]<EOL>self._WL0 = terms["<STR_LIT>"]<EOL>self._Lz = terms["<STR_LIT>"]<EOL>self._XRiM = terms["<STR_LIT>"]<EOL>self._ZiXRiy = terms["<STR_LIT>"]<EOL>self._ZiXRiM = terms["<STR_LIT>"]<EOL>self._MRiM = terms["<STR_LIT>"]<EOL>self._MRiXZiXRiM = terms["<STR_LIT>"]<EOL>self._MRiy = terms["<STR_LIT>"]<EOL>self._MRiXZiXRiy = terms["<STR_LIT>"]<EOL>

Constructor.

Parameters
----------
Y : (n, p) array_like
    Outcome matrix.
A : (n, n) array_like
    Trait-by-trait design matrix.
X : (n, c) array_like
    Covariates design matrix.
G : (n, r) array_like
    Matrix G from the GGᵀ term.
terms : dict
    Pre-computed terms.


return rsolve(self._MKiM, self._MKiy)<EOL>

Optimal 𝛃 according to the marginal likelihood.

It is compute by solving the equation ::

    MᵀK⁻¹M𝛃 = MᵀK⁻¹𝐲,

for 𝐲 = vec(Y) and M = (A ⊗ X)vec(𝚩).

Returns
-------
effsizes : ndarray
    Optimal 𝛃.


Standard errors of the optimal 𝛃.

Returns
-------
beta_se : ndarray
    Square root of the diagonal of the beta covariance.


from numpy import empty<EOL>from numpy.linalg import multi_dot<EOL>from numpy_sugar import epsilon, is_all_finite<EOL>from scipy.linalg import cho_solve<EOL>A1 = asarray(A1, float)<EOL>X1 = asarray(X1, float)<EOL>if not is_all_finite(A1):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_all_finite(X1):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if A1.shape[<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>beta_se = sqrt(self.null_beta_covariance.diagonal())<EOL>return {<EOL>"<STR_LIT>": self.null_lml(),<EOL>"<STR_LIT>": unvec(self.null_beta, (self._ncovariates, -<NUM_LIT:1>)),<EOL>"<STR_LIT>": unvec(beta_se, (self._ncovariates, -<NUM_LIT:1>)),<EOL>"<STR_LIT>": empty((<NUM_LIT:0>,)),<EOL>"<STR_LIT>": empty((<NUM_LIT:0>,)),<EOL>"<STR_LIT>": self.null_scale,<EOL>}<EOL><DEDENT>X1X1 = X1.T @ X1<EOL>XX1 = self._X.T @ X1<EOL>AWA1 = self._WA.T @ A1<EOL>A1W = A1.T @ self._W<EOL>GX1 = self._G.T @ X1<EOL>MRiM1 = kron(AWA1, XX1)<EOL>M1RiM1 = kron(A1W @ A1, X1X1)<EOL>M1Riy = vec(multi_dot([X1.T, self._Y, A1W.T]))<EOL>XRiM1 = kron(self._WL0.T @ A1, GX1)<EOL>ZiXRiM1 = cho_solve(self._Lz, XRiM1)<EOL>MRiXZiXRiM1 = self._XRiM.T @ ZiXRiM1<EOL>M1RiXZiXRiM1 = XRiM1.T @ ZiXRiM1<EOL>M1RiXZiXRiy = XRiM1.T @ self._ZiXRiy<EOL>T0 = [[self._MRiM, MRiM1], [MRiM1.T, M1RiM1]]<EOL>T1 = [[self._MRiXZiXRiM, MRiXZiXRiM1], [MRiXZiXRiM1.T, M1RiXZiXRiM1]]<EOL>T2 = [self._MRiy, M1Riy]<EOL>T3 = [self._MRiXZiXRiy, M1RiXZiXRiy]<EOL>MKiM = block(T0) - block(T1)<EOL>MKiy = block(T2) - block(T3)<EOL>beta = rsolve(MKiM, MKiy)<EOL>mKiy = beta.T @ MKiy<EOL>cp = self._ntraits * self._ncovariates<EOL>effsizes0 = unvec(beta[:cp], (self._ncovariates, self._ntraits))<EOL>effsizes1 = unvec(beta[cp:], (X1.shape[<NUM_LIT:1>], A1.shape[<NUM_LIT:1>]))<EOL>np = self._nsamples * self._ntraits<EOL>sqrtdot = self._yKiy - mKiy<EOL>scale = clip(sqrtdot / np, epsilon.tiny, inf)<EOL>lml = self._static_lml() / <NUM_LIT:2> - np * safe_log(scale) / <NUM_LIT:2> - np / <NUM_LIT:2><EOL>effsizes_se = sqrt(clip(scale * pinv(MKiM).diagonal(), epsilon.tiny, inf))<EOL>effsizes0_se = unvec(effsizes_se[:cp], (self._ncovariates, self._ntraits))<EOL>effsizes1_se = unvec(effsizes_se[cp:], (X1.shape[<NUM_LIT:1>], A1.shape[<NUM_LIT:1>]))<EOL>return {<EOL>"<STR_LIT>": lml,<EOL>"<STR_LIT>": effsizes0,<EOL>"<STR_LIT>": effsizes1,<EOL>"<STR_LIT>": scale,<EOL>"<STR_LIT>": effsizes0_se,<EOL>"<STR_LIT>": effsizes1_se,<EOL>}<EOL>

LML, fixed-effect sizes, and scale of the candidate set.

Parameters
----------
A1 : (p, e) array_like
    Trait-by-environments design matrix.
X1 : (n, m) array_like
    Variants set matrix.

Returns
-------
lml : float
    Log of the marginal likelihood for the set.
effsizes0 : (c, p) ndarray
    Fixed-effect sizes for the covariates.
effsizes0_se : (c, p) ndarray
    Fixed-effect size standard errors for the covariates.
effsizes1 : (m, e) ndarray
    Fixed-effect sizes for the candidates.
effsizes1_se : (m, e) ndarray
    Fixed-effect size standard errors for the candidates.
scale : float
    Optimal scale.


np = self._nsamples * self._ntraits<EOL>scale = self.null_scale<EOL>return self._static_lml() / <NUM_LIT:2> - np * safe_log(scale) / <NUM_LIT:2> - np / <NUM_LIT:2><EOL>

Log of the marginal likelihood for the null hypothesis.

It is implemented as ::

    2·log(p(Y)) = -n·p·log(2𝜋s) - log｜K｜ - n·p,

for which s and 𝚩 are optimal.

Returns
-------
lml : float
    Log of the marginal likelihood.


return self.null_scale * pinv(self._H)<EOL>

Covariance of the optimal 𝛃 according to the marginal likelihood.

Returns
-------
effsizes-covariance : ndarray
    s(MᵀK⁻¹M)⁻¹.


return self._X["<STR_LIT:X>"].shape[<NUM_LIT:1>]<EOL>


if param == "<STR_LIT>":<EOL><INDENT>self._unfix("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>self._fix[param] = False<EOL><DEDENT>

Enable parameter optimization.

Parameters
----------
param : str
    Possible values are ``"delta"``, ``"beta"``, and ``"scale"``.


if not self._fix["<STR_LIT>"]:<EOL><INDENT>self._update_beta()<EOL><DEDENT>if not self._fix["<STR_LIT>"]:<EOL><INDENT>self._update_scale()<EOL><DEDENT>return self.lml()<EOL>


return len(self._y)<EOL>


s = self.scale<EOL>D = self._D<EOL>n = len(self._y)<EOL>lml = -self._df * log2pi - n * log(s)<EOL>lml -= sum(npsum(log(d)) for d in D)<EOL>d = (mTQ - yTQ for (mTQ, yTQ) in zip(self._mTQ, self._yTQ))<EOL>lml -= sum((i / j) @ i for (i, j) in zip(d, D)) / s<EOL>return lml / <NUM_LIT:2><EOL>

Log of the marginal likelihood for arbitrary scale.

Returns
-------
lml : float
    Log of the marginal likelihood.


from numpy_sugar.linalg import rsolve<EOL>return rsolve(self._X["<STR_LIT>"], rsolve(self._X["<STR_LIT>"], self.mean()))<EOL>

Fixed-effect sizes.

Returns
-------
effect-sizes : numpy.ndarray
    Optimal fixed-effect sizes.

Notes
-----
Setting the derivative of log(p(𝐲)) over effect sizes equal
to zero leads to solutions 𝜷 from equation ::

    (QᵀX)ᵀD⁻¹(QᵀX)𝜷 = (QᵀX)ᵀD⁻¹(Qᵀ𝐲).


return self.scale * self.delta<EOL>

Second variance.

Returns
-------
v1 : float
    s𝛿.


assert self._optimal["<STR_LIT>"]<EOL>n = len(self._y)<EOL>lml = -self._df * log2pi - self._df - n * log(self.scale)<EOL>lml -= sum(npsum(log(D)) for D in self._D)<EOL>return lml / <NUM_LIT:2><EOL>

Log of the marginal likelihood for optimal scale.

Implementation for unrestricted LML::

Returns
-------
lml : float
    Log of the marginal likelihood.


return self._mean.A<EOL>

A from the equation 𝐦 = (A ⊗ X) vec(B).

Returns
-------
A : ndarray
    A.


H = self._terms["<STR_LIT:H>"]<EOL>return inv(H)<EOL>

Estimates the covariance-matrix of the optimal beta.

Returns
-------
beta-covariance : ndarray
    (MᵀK⁻¹M)⁻¹.

References
----------
.. Rencher, A. C., & Schaalje, G. B. (2008). Linear models in statistics. John
   Wiley & Sons.


return self._cov.value()<EOL>

Covariance K = C₀ ⊗ GGᵀ + C₁ ⊗ I.

Returns
-------
covariance : ndarray
    K.


self._terms<EOL>return asarray(self._mean.B, float)<EOL>

Fixed-effect sizes B from 𝐦 = (A ⊗ X) vec(B).

Returns
-------
fixed-effects : ndarray
    B from 𝐦 = (A ⊗ X) vec(B).


from scipy.linalg import cho_solve<EOL>terms = self._terms<EOL>dC0 = self._cov.C0.gradient()["<STR_LIT>"]<EOL>dC1 = self._cov.C1.gradient()["<STR_LIT>"]<EOL>b = terms["<STR_LIT:b>"]<EOL>W = terms["<STR_LIT>"]<EOL>Lh = terms["<STR_LIT>"]<EOL>Lz = terms["<STR_LIT>"]<EOL>WA = terms["<STR_LIT>"]<EOL>WL0 = terms["<STR_LIT>"]<EOL>YW = terms["<STR_LIT>"]<EOL>MRiM = terms["<STR_LIT>"]<EOL>MRiy = terms["<STR_LIT>"]<EOL>XRiM = terms["<STR_LIT>"]<EOL>XRiy = terms["<STR_LIT>"]<EOL>ZiXRiM = terms["<STR_LIT>"]<EOL>ZiXRiy = terms["<STR_LIT>"]<EOL>WdC0 = _mdot(W, dC0)<EOL>WdC1 = _mdot(W, dC1)<EOL>AWdC0 = _mdot(WA.T, dC0)<EOL>AWdC1 = _mdot(WA.T, dC1)<EOL>MR0M = _mkron(_mdot(AWdC0, WA), self._XGGX)<EOL>MR1M = _mkron(_mdot(AWdC1, WA), self._XX)<EOL>MR0X = _mkron(_mdot(AWdC0, WL0), self._XGGG)<EOL>MR1X = _mkron(_mdot(AWdC1, WL0), self._GX.T)<EOL>MR0y = vec(_mdot(self._XGGY, _mdot(WdC0, WA)))<EOL>MR1y = vec(_mdot(self._XY, WdC1, WA))<EOL>XR0X = _mkron(_mdot(WL0.T, dC0, WL0), self._GGGG)<EOL>XR1X = _mkron(_mdot(WL0.T, dC1, WL0), self._GG)<EOL>XR0y = vec(_mdot(self._GGGY, WdC0, WL0))<EOL>XR1y = vec(_mdot(self._GY, WdC1, WL0))<EOL>yR0y = vec(_mdot(self._GY, WdC0)).T @ vec(self._GY @ W)<EOL>yR1y = (YW.T * _mdot(self._Y, WdC1).T).T.sum(axis=(<NUM_LIT:0>, <NUM_LIT:1>))<EOL>ZiXR0X = cho_solve(Lz, XR0X)<EOL>ZiXR1X = cho_solve(Lz, XR1X)<EOL>ZiXR0y = cho_solve(Lz, XR0y)<EOL>ZiXR1y = cho_solve(Lz, XR1y)<EOL>MK0y = MR0y - _mdot(XRiM.T, ZiXR0y) - _mdot(MR0X, ZiXRiy)<EOL>MK0y += _mdot(XRiM.T, ZiXR0X, ZiXRiy)<EOL>MK1y = MR1y - _mdot(XRiM.T, ZiXR1y) - _mdot(MR1X, ZiXRiy)<EOL>MK1y += _mdot(XRiM.T, ZiXR1X, ZiXRiy)<EOL>yK0y = yR0y - <NUM_LIT:2> * XR0y.T @ ZiXRiy + ZiXRiy.T @ _mdot(XR0X, ZiXRiy)<EOL>yK1y = yR1y - <NUM_LIT:2> * XR1y.T @ ZiXRiy + ZiXRiy.T @ _mdot(XR1X, ZiXRiy)<EOL>MR0XZiXRiM = _mdot(MR0X, ZiXRiM)<EOL>MK0M = MR0M - MR0XZiXRiM - MR0XZiXRiM.transpose([<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:2>])<EOL>MK0M += _mdot(ZiXRiM.T, XR0X, ZiXRiM)<EOL>MR1XZiXRiM = _mdot(MR1X, ZiXRiM)<EOL>MK1M = MR1M - MR1XZiXRiM - MR1XZiXRiM.transpose([<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:2>])<EOL>MK1M += _mdot(ZiXRiM.T, XR1X, ZiXRiM)<EOL>MK0m = _mdot(MK0M, b)<EOL>mK0y = b.T @ MK0y<EOL>mK0m = b.T @ MK0m<EOL>MK1m = _mdot(MK1M, b)<EOL>mK1y = b.T @ MK1y<EOL>mK1m = b.T @ MK1m<EOL>XRim = XRiM @ b<EOL>MRim = MRiM @ b<EOL>db = {"<STR_LIT>": cho_solve(Lh, MK0m - MK0y), "<STR_LIT>": cho_solve(Lh, MK1m - MK1y)}<EOL>grad = {<EOL>"<STR_LIT>": -trace(WdC0) * self._trGG + trace(ZiXR0X),<EOL>"<STR_LIT>": -trace(WdC1) * self.nsamples + trace(ZiXR1X),<EOL>}<EOL>if self._restricted:<EOL><INDENT>grad["<STR_LIT>"] += cho_solve(Lh, MK0M).diagonal().sum(<NUM_LIT:1>)<EOL>grad["<STR_LIT>"] += cho_solve(Lh, MK1M).diagonal().sum(<NUM_LIT:1>)<EOL><DEDENT>mKiM = MRim.T - XRim.T @ ZiXRiM<EOL>yKiM = MRiy.T - XRiy.T @ ZiXRiM<EOL>grad["<STR_LIT>"] += yK0y - <NUM_LIT:2> * mK0y + mK0m - <NUM_LIT:2> * _mdot(mKiM, db["<STR_LIT>"])<EOL>grad["<STR_LIT>"] += <NUM_LIT:2> * _mdot(yKiM, db["<STR_LIT>"])<EOL>grad["<STR_LIT>"] += yK1y - <NUM_LIT:2> * mK1y + mK1m - <NUM_LIT:2> * _mdot(mKiM, db["<STR_LIT>"])<EOL>grad["<STR_LIT>"] += <NUM_LIT:2> * _mdot(yKiM, db["<STR_LIT>"])<EOL>grad["<STR_LIT>"] /= <NUM_LIT:2><EOL>grad["<STR_LIT>"] /= <NUM_LIT:2><EOL>return grad<EOL>

Gradient of the log of the marginal likelihood.

Let 𝐲 = vec(Y), 𝕂 = K⁻¹∂(K)K⁻¹, and H = MᵀK⁻¹M. The gradient is given by::

    2⋅∂log(p(𝐲)) = -tr(K⁻¹∂K) - tr(H⁻¹∂H) + 𝐲ᵀ𝕂𝐲 - 𝐦ᵀ𝕂(2⋅𝐲-𝐦)
        - 2⋅(𝐦-𝐲)ᵀK⁻¹∂(𝐦).

Observe that

    ∂𝛃 = -H⁻¹(∂H)𝛃 - H⁻¹Mᵀ𝕂𝐲 and ∂H = -Mᵀ𝕂M.

Let Z = I + XᵀR⁻¹X and 𝓡 = R⁻¹(∂K)R⁻¹. We use Woodbury matrix identity to
write ::

    𝐲ᵀ𝕂𝐲 = 𝐲ᵀ𝓡𝐲 - 2(𝐲ᵀ𝓡X)Z⁻¹(XᵀR⁻¹𝐲) + (𝐲ᵀR⁻¹X)Z⁻¹(Xᵀ𝓡X)Z⁻¹(XᵀR⁻¹𝐲)
    Mᵀ𝕂M = Mᵀ𝓡M - 2(Mᵀ𝓡X)Z⁻¹(XᵀR⁻¹M) + (MᵀR⁻¹X)Z⁻¹(Xᵀ𝓡X)Z⁻¹(XᵀR⁻¹M)
    Mᵀ𝕂𝐲 = Mᵀ𝓡𝐲 - (MᵀR⁻¹X)Z⁻¹(Xᵀ𝓡𝐲) - (Mᵀ𝓡X)Z⁻¹(XᵀR⁻¹𝐲)
          + (MᵀR⁻¹X)Z⁻¹(Xᵀ𝓡X)Z⁻¹(XᵀR⁻¹𝐲)
    H⁻¹   = MᵀR⁻¹M - (MᵀR⁻¹X)Z⁻¹(XᵀR⁻¹M),

where we have used parentheses to separate expressions
that we will compute separately. For example, we have ::

    𝐲ᵀ𝓡𝐲 = 𝐲ᵀ(U₁S₁⁻¹U₁ᵀ ⊗ I)(∂C₀ ⊗ GGᵀ)(U₁S₁⁻¹U₁ᵀ ⊗ I)𝐲
          = 𝐲ᵀ(U₁S₁⁻¹U₁ᵀ∂C₀ ⊗ G)(U₁S₁⁻¹U₁ᵀ ⊗ Gᵀ)𝐲
          = vec(GᵀYU₁S₁⁻¹U₁ᵀ∂C₀)ᵀvec(GᵀYU₁S₁⁻¹U₁ᵀ),

when the derivative is over the parameters of C₀. Otherwise, we have

    𝐲ᵀ𝓡𝐲 = vec(YU₁S₁⁻¹U₁ᵀ∂C₁)ᵀvec(YU₁S₁⁻¹U₁ᵀ).

The above equations can be more compactly written as

    𝐲ᵀ𝓡𝐲 = vec(EᵢᵀYW∂Cᵢ)ᵀvec(EᵢᵀYW),

where W = U₁S₁⁻¹U₁ᵀ, E₀ = G, and E₁ = I. We will now just state the results for
the other instances of the aBc form, which follow similar derivations::

    Xᵀ𝓡X = (L₀ᵀW∂CᵢWL₀) ⊗ (GᵀEᵢEᵢᵀG)
    Mᵀ𝓡y = (AᵀW∂Cᵢ⊗XᵀEᵢ)vec(EᵢᵀYW) = vec(XᵀEᵢEᵢᵀYW∂CᵢWA)
    Mᵀ𝓡X = AᵀW∂CᵢWL₀ ⊗ XᵀEᵢEᵢᵀG
    Mᵀ𝓡M = AᵀW∂CᵢWA ⊗ XᵀEᵢEᵢᵀX
    Xᵀ𝓡𝐲 = GᵀEᵢEᵢᵀYW∂CᵢWL₀

From Woodbury matrix identity and Kronecker product properties we have ::

    tr(K⁻¹∂K) = tr[W∂Cᵢ]tr[EᵢEᵢᵀ] - tr[Z⁻¹(Xᵀ𝓡X)]
    tr(H⁻¹∂H) = - tr[(MᵀR⁻¹M)(Mᵀ𝕂M)] + tr[(MᵀR⁻¹X)Z⁻¹(XᵀR⁻¹M)(Mᵀ𝕂M)]

Note also that ::

    ∂𝛃 = H⁻¹Mᵀ𝕂M𝛃 - H⁻¹Mᵀ𝕂𝐲.

Returns
-------
C0.Lu : ndarray
    Gradient of the log of the marginal likelihood over C₀ parameters.
C1.Lu : ndarray
    Gradient of the log of the marginal likelihood over C₁ parameters.


return self._mean.X.shape[<NUM_LIT:1>]<EOL>


from scipy.linalg import cho_factor<EOL>from numpy_sugar.linalg import ddot, sum2diag<EOL>if self._L_cache is not None:<EOL><INDENT>return self._L_cache<EOL><DEDENT>Q = self._cov["<STR_LIT>"][<NUM_LIT:0>][<NUM_LIT:0>]<EOL>S = self._cov["<STR_LIT>"][<NUM_LIT:1>]<EOL>B = dot(Q.T, ddot(self._site.tau, Q, left=True))<EOL>sum2diag(B, <NUM_LIT:1.0> / S, out=B)<EOL>self._L_cache = cho_factor(B, lower=True)[<NUM_LIT:0>]<EOL>return self._L_cache<EOL>

r"""Cholesky decomposition of :math:`\mathrm B`.

        .. math::

            \mathrm B = \mathrm Q^{\intercal}\tilde{\mathrm{T}}\mathrm Q
                + \mathrm{S}^{-1}


if self._mean is None or self._cov is None:<EOL><INDENT>return<EOL><DEDENT>Q = self._cov["<STR_LIT>"][<NUM_LIT:0>][<NUM_LIT:0>]<EOL>S = self._cov["<STR_LIT>"][<NUM_LIT:1>]<EOL>if S.size > <NUM_LIT:0>:<EOL><INDENT>self.tau[:] = <NUM_LIT:1> / npsum((Q * sqrt(S)) ** <NUM_LIT:2>, axis=<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>self.tau[:] = <NUM_LIT:0.0><EOL><DEDENT>self.eta[:] = self._mean<EOL>self.eta[:] *= self.tau<EOL>

r"""Initialize the mean and covariance of the posterior.

        Given that :math:`\tilde{\mathrm T}` is a matrix of zeros right before
        the first EP iteration, we have

        .. math::

            \boldsymbol\mu = \mathrm K^{-1} \mathbf m ~\text{ and }~
            \Sigma = \mathrm K

        as the initial posterior mean and covariance.


from numpy_sugar.linalg import rsolve as _rsolve<EOL>try:<EOL><INDENT>beta = _rsolve(A, y)<EOL><DEDENT>except LinAlgError:<EOL><INDENT>msg = "<STR_LIT>"<EOL>msg += "<STR_LIT>"<EOL>warnings.warn(msg, RuntimeWarning)<EOL>beta = zeros(A.shape[<NUM_LIT:0>])<EOL><DEDENT>return beta<EOL>


from numpy_sugar import epsilon<EOL>n = _norm(A00, A01)<EOL>u0 = A00 - n<EOL>u1 = A01<EOL>nu = _norm(u0, u1)<EOL>with errstate(invalid="<STR_LIT:ignore>", divide="<STR_LIT:ignore>"):<EOL><INDENT>v0 = nan_to_num(u0 / nu)<EOL>v1 = nan_to_num(u1 / nu)<EOL><DEDENT>B00 = <NUM_LIT:1> - <NUM_LIT:2> * v0 * v0<EOL>B01 = <NUM_LIT:0> - <NUM_LIT:2> * v0 * v1<EOL>B11 = <NUM_LIT:1> - <NUM_LIT:2> * v1 * v1<EOL>D00 = B00 * A00 + B01 * A01<EOL>D01 = B00 * A01 + B01 * A11<EOL>D11 = B01 * A01 + B11 * A11<EOL>b0 = y0 - <NUM_LIT:2> * y0 * v0 * v0 - <NUM_LIT:2> * y1 * v0 * v1<EOL>b1 = y1 - <NUM_LIT:2> * y0 * v1 * v0 - <NUM_LIT:2> * y1 * v1 * v1<EOL>n = _norm(D00, D01)<EOL>u0 = D00 - n<EOL>u1 = D01<EOL>nu = _norm(u0, u1)<EOL>with errstate(invalid="<STR_LIT:ignore>", divide="<STR_LIT:ignore>"):<EOL><INDENT>v0 = nan_to_num(u0 / nu)<EOL>v1 = nan_to_num(u1 / nu)<EOL><DEDENT>E00 = <NUM_LIT:1> - <NUM_LIT:2> * v0 * v0<EOL>E01 = <NUM_LIT:0> - <NUM_LIT:2> * v0 * v1<EOL>E11 = <NUM_LIT:1> - <NUM_LIT:2> * v1 * v1<EOL>F00 = E00 * D00 + E01 * D01<EOL>F01 = E01 * D11<EOL>F11 = E11 * D11<EOL>F11 = (npy_abs(F11) > epsilon.small) * F11<EOL>with errstate(divide="<STR_LIT:ignore>", invalid="<STR_LIT:ignore>"):<EOL><INDENT>Fi00 = nan_to_num(F00 / F00 / F00)<EOL>Fi11 = nan_to_num(F11 / F11 / F11)<EOL>Fi10 = nan_to_num(-(F01 / F00) * Fi11)<EOL><DEDENT>c0 = Fi00 * b0<EOL>c1 = Fi10 * b0 + Fi11 * b1<EOL>x0 = E00 * c0 + E01 * c1<EOL>x1 = E01 * c0 + E11 * c1<EOL>return array([x0, x1])<EOL>

Solver for the linear equations of two variables and equations only.

It uses Householder reductions to solve A𝐱 = 𝐲 in a robust manner.

Parameters
----------
A : array_like
    Coefficient matrix.
y : array_like
    Ordinate values.

Returns
-------
ndarray
    Solution 𝐱.


from numpy_sugar.linalg import ddot, sum2diag<EOL>if self._cache["<STR_LIT:value>"] is not None:<EOL><INDENT>return self._cache["<STR_LIT:value>"]<EOL><DEDENT>scale = exp(self.logscale)<EOL>delta = <NUM_LIT:1> / (<NUM_LIT:1> + exp(-self.logitdelta))<EOL>v0 = scale * (<NUM_LIT:1> - delta)<EOL>v1 = scale * delta<EOL>mu = self.eta / self.tau<EOL>n = len(mu)<EOL>if self._QS is None:<EOL><INDENT>K = zeros((n, n))<EOL><DEDENT>else:<EOL><INDENT>Q0 = self._QS[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>S0 = self._QS[<NUM_LIT:1>]<EOL>K = dot(ddot(Q0, S0), Q0.T)<EOL><DEDENT>A = sum2diag(sum2diag(v0 * K, v1), <NUM_LIT:1> / self.tau)<EOL>m = mu - self.mean()<EOL>v = -n * log(<NUM_LIT:2> * pi)<EOL>v -= slogdet(A)[<NUM_LIT:1>]<EOL>v -= dot(m, solve(A, m))<EOL>self._cache["<STR_LIT:value>"] = v / <NUM_LIT:2><EOL>return self._cache["<STR_LIT:value>"]<EOL>

r"""Log of the marginal likelihood.

        Formally,

        .. math::

            - \frac{n}{2}\log{2\pi} - \frac{1}{2} \log{\left|
                v_0 \mathrm K + v_1 \mathrm I + \tilde{\Sigma} \right|}
                    - \frac{1}{2}
                    \left(\tilde{\boldsymbol\mu} -
                    \mathrm X\boldsymbol\beta\right)^{\intercal}
                    \left( v_0 \mathrm K + v_1 \mathrm I +
                    \tilde{\Sigma} \right)^{-1}
                    \left(\tilde{\boldsymbol\mu} -
                    \mathrm X\boldsymbol\beta\right)

        Returns
        -------
        float
            :math:`\log{p(\tilde{\boldsymbol\mu})}`


from numpy_sugar.linalg import rsolve<EOL>Sigma = self.posteriori_covariance()<EOL>eta = self._ep._posterior.eta<EOL>return dot(Sigma, eta + rsolve(GLMM.covariance(self), self.mean()))<EOL>

r""" Mean of the estimated posteriori.

        This is also the maximum a posteriori estimation of the latent variable.


return self.scale * self.delta<EOL>

r"""Second variance.

        Returns
        -------
        float
            :math:`v_1 = s \delta`


return self.value()<EOL>

r"""Log of the marginal likelihood.

        Returns
        -------
        float
            :math:`\log p(\mathbf y)`


from numpy_sugar.linalg import ddot, sum2diag<EOL>Q0 = self._QS[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>S0 = self._QS[<NUM_LIT:1>]<EOL>return sum2diag(dot(ddot(Q0, self.v0 * S0), Q0.T), self.v1)<EOL>

r"""Covariance of the prior.

        Returns
        -------
        :class:`numpy.ndarray`
            :math:`v_0 \mathrm K + v_1 \mathrm I`.


return asarray(self._variables.get("<STR_LIT>").value, float)<EOL>

r"""Fixed-effect sizes.

        Returns
        -------
        :class:`numpy.ndarray`
            :math:`\boldsymbol\beta`.


return dot(self._X, self.beta)<EOL>

r"""Mean of the prior.

        Returns
        -------
        :class:`numpy.ndarray`
            :math:`\mathrm X\boldsymbol\beta`.


self._update_approx()<EOL>g = self._ep.lml_derivatives(self._X)<EOL>ed = exp(-self.logitdelta)<EOL>es = exp(self.logscale)<EOL>grad = dict()<EOL>grad["<STR_LIT>"] = g["<STR_LIT>"] * (ed / (<NUM_LIT:1> + ed)) / (<NUM_LIT:1> + ed)<EOL>grad["<STR_LIT>"] = g["<STR_LIT>"] * es<EOL>grad["<STR_LIT>"] = g["<STR_LIT>"]<EOL>return grad<EOL>

r"""Gradient of the log of the marginal likelihood.

        Returns
        -------
        dict
            Map between variables to their gradient values.


return x<EOL>


return self._link.inv(x)<EOL>

r"""Mean of the number of successful trials.


return self._outcome<EOL>


return "<STR_LIT>"<EOL>


return self._noccurrences<EOL>

r"""Get or set an array of number of occurrences.


return len(self.nsuccesses)<EOL>


return len(self.outcome)<EOL>


def _call_multi_fortran_z_attr(self, names, data_types, num_elems,<EOL>entry_nums, attr_nums, var_names,<EOL>input_type_code, func, data_offset=None):

<EOL>idx, = np.where(data_types == input_type_code)<EOL>if len(idx) > <NUM_LIT:0>:<EOL><INDENT>max_num = num_elems[idx].max()<EOL>sub_num_elems = num_elems[idx]<EOL>sub_names = np.array(names)[idx]<EOL>sub_var_names = np.array(var_names)[idx]<EOL>sub_entry_nums = entry_nums[idx]<EOL>sub_attr_nums = attr_nums[idx]<EOL>status, data = func(self.fname, sub_attr_nums, sub_entry_nums,<EOL>len(sub_attr_nums), max_num, len(self.fname))<EOL>if (status == <NUM_LIT:0>).all():<EOL><INDENT>if data_offset is not None:<EOL><INDENT>data = data.astype(int)<EOL>idx, idy, = np.where(data < <NUM_LIT:0>)<EOL>data[idx, idy] += data_offset<EOL><DEDENT>self._process_return_multi_z_attr(data, sub_names,<EOL>sub_var_names, sub_num_elems)<EOL><DEDENT>else:<EOL><INDENT>idx, = np.where(status != <NUM_LIT:0>)<EOL>raise IOError(fortran_cdf.statusreporter(status[idx][<NUM_LIT:0>]))<EOL><DEDENT><DEDENT>

Calls Fortran function that reads attribute data.

        data_offset translates unsigned into signed.
        If number read in is negative, offset added.


self.data = {}<EOL>file_var_names = self.z_variable_info.keys()<EOL>dim_sizes = []<EOL>rec_nums = []<EOL>data_types = []<EOL>names = []<EOL>for i, name in enumerate(file_var_names):<EOL><INDENT>dim_sizes.extend(self.z_variable_info[name]['<STR_LIT>'])<EOL>rec_nums.append(self.z_variable_info[name]['<STR_LIT>'])<EOL>data_types.append(self.z_variable_info[name]['<STR_LIT>'])<EOL>names.append(name.ljust(<NUM_LIT>))<EOL><DEDENT>dim_sizes = np.array(dim_sizes)<EOL>rec_nums = np.array(rec_nums)<EOL>data_types = np.array(data_types)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_real4)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT:float>'],<EOL>fortran_cdf.get_multi_z_real4)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_real8)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_real8)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_int4)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_int4,<EOL>data_offset=<NUM_LIT:2> ** <NUM_LIT:32>)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_int2)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_int2,<EOL>data_offset=<NUM_LIT:2> ** <NUM_LIT:16>)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_int1)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_int1,<EOL>data_offset=<NUM_LIT:2> ** <NUM_LIT:8>)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_int1)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_real8,<EOL>epoch=True)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, <NUM_LIT:2> * dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_epoch16,<EOL>epoch16=True)<EOL>self._call_multi_fortran_z(names, data_types, rec_nums, dim_sizes,<EOL>self.cdf_data_types['<STR_LIT>'],<EOL>fortran_cdf.get_multi_z_tt2000,<EOL>epoch=True)<EOL>self.data_loaded = True<EOL>

Loads all variables from CDF.

        Note this routine is called automatically
        upon instantiation.


num = copy.deepcopy(self._num_attrs)<EOL>fname = copy.deepcopy(self.fname)<EOL>out = fortran_cdf.inquire_all_attr(fname, num, len(fname))<EOL>status = out[<NUM_LIT:0>]<EOL>names = out[<NUM_LIT:1>].astype('<STR_LIT>')<EOL>scopes = out[<NUM_LIT:2>]<EOL>max_gentries = out[<NUM_LIT:3>]<EOL>max_rentries = out[<NUM_LIT:4>]<EOL>max_zentries = out[<NUM_LIT:5>]<EOL>attr_nums = out[<NUM_LIT:6>]<EOL>global_attrs_info = {}<EOL>var_attrs_info = {}<EOL>if status == <NUM_LIT:0>:<EOL><INDENT>for name, scope, gentry, rentry, zentry, num in zip(names, scopes, max_gentries,<EOL>max_rentries, max_zentries,<EOL>attr_nums):<EOL><INDENT>name = '<STR_LIT>'.join(name)<EOL>name = name.rstrip()<EOL>nug = {}<EOL>nug['<STR_LIT>'] = scope<EOL>nug['<STR_LIT>'] = gentry<EOL>nug['<STR_LIT>'] = rentry<EOL>nug['<STR_LIT>'] = zentry<EOL>nug['<STR_LIT>'] = num<EOL>flag = (gentry == <NUM_LIT:0>) & (rentry == <NUM_LIT:0>) & (zentry == <NUM_LIT:0>)<EOL>if not flag:<EOL><INDENT>if scope == <NUM_LIT:1>:<EOL><INDENT>global_attrs_info[name] = nug<EOL><DEDENT>elif scope == <NUM_LIT:2>:<EOL><INDENT>var_attrs_info[name] = nug<EOL><DEDENT><DEDENT><DEDENT>self.global_attrs_info = global_attrs_info<EOL>self.var_attrs_info = var_attrs_info<EOL><DEDENT>else:<EOL><INDENT>raise IOError(fortran_cdf.statusreporter(status))<EOL><DEDENT>

Read all attribute properties, g, r, and z attributes


name = copy.deepcopy(self.fname)<EOL>stats = fortran_cdf.inquire(name)<EOL>status = stats[<NUM_LIT:0>]<EOL>if status == <NUM_LIT:0>:<EOL><INDENT>self._num_dims = stats[<NUM_LIT:1>]<EOL>self._dim_sizes = stats[<NUM_LIT:2>]<EOL>self._encoding = stats[<NUM_LIT:3>]<EOL>self._majority = stats[<NUM_LIT:4>]<EOL>self._max_rec = stats[<NUM_LIT:5>]<EOL>self._num_r_vars = stats[<NUM_LIT:6>]<EOL>self._num_z_vars = stats[<NUM_LIT:7>]<EOL>self._num_attrs = stats[<NUM_LIT:8>]<EOL><DEDENT>else:<EOL><INDENT>raise IOError(fortran_cdf.statusreporter(status))<EOL><DEDENT>

Maps to fortran CDF_Inquire.

        Assigns parameters returned by CDF_Inquire
        to pysatCDF instance. Not intended
        for regular direct use by user.


self.z_variable_info = {}<EOL>self.z_variable_names_by_num = {}<EOL>info = fortran_cdf.z_var_all_inquire(self.fname, self._num_z_vars,<EOL>len(self.fname))<EOL>status = info[<NUM_LIT:0>]<EOL>data_types = info[<NUM_LIT:1>]<EOL>num_elems = info[<NUM_LIT:2>]<EOL>rec_varys = info[<NUM_LIT:3>]<EOL>dim_varys = info[<NUM_LIT:4>]<EOL>num_dims = info[<NUM_LIT:5>]<EOL>dim_sizes = info[<NUM_LIT:6>]<EOL>rec_nums = info[<NUM_LIT:7>]<EOL>var_nums = info[<NUM_LIT:8>]<EOL>var_names = info[<NUM_LIT:9>]<EOL>if status == <NUM_LIT:0>:<EOL><INDENT>for i in np.arange(len(data_types)):<EOL><INDENT>out = {}<EOL>out['<STR_LIT>'] = data_types[i]<EOL>out['<STR_LIT>'] = num_elems[i]<EOL>out['<STR_LIT>'] = rec_varys[i]<EOL>out['<STR_LIT>'] = dim_varys[i]<EOL>out['<STR_LIT>'] = num_dims[i]<EOL>out['<STR_LIT>'] = dim_sizes[i, :<NUM_LIT:1>]<EOL>if out['<STR_LIT>'][<NUM_LIT:0>] == <NUM_LIT:0>:<EOL><INDENT>out['<STR_LIT>'][<NUM_LIT:0>] += <NUM_LIT:1><EOL><DEDENT>out['<STR_LIT>'] = rec_nums[i]<EOL>out['<STR_LIT>'] = var_nums[i]<EOL>var_name = '<STR_LIT>'.join(var_names[i].astype('<STR_LIT>'))<EOL>out['<STR_LIT>'] = var_name.rstrip()<EOL>self.z_variable_info[out['<STR_LIT>']] = out<EOL>self.z_variable_names_by_num[out['<STR_LIT>']] = var_name<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise IOError(fortran_cdf.statusreporter(status))<EOL><DEDENT>

Gets all CDF z-variable information, not data though.

        Maps to calls using var_inquire. Gets information on
        data type, number of elements, number of dimensions, etc.


def _process_return_multi_z_attr(self, data, attr_names, var_names, sub_num_elems):

<EOL>for i, (attr_name, var_name, num_e) in enumerate(zip(attr_names, var_names, sub_num_elems)):<EOL><INDENT>if var_name not in self.meta.keys():<EOL><INDENT>self.meta[var_name] = {}<EOL><DEDENT>if num_e == <NUM_LIT:1>:<EOL><INDENT>self.meta[var_name][attr_name] = data[i, <NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>if data[i].dtype == '<STR_LIT>':<EOL><INDENT>self.meta[var_name][attr_name] = '<STR_LIT>'.join(data[i, <NUM_LIT:0>:num_e].astype('<STR_LIT>')).rstrip()<EOL><DEDENT>else:<EOL><INDENT>self.meta[var_name][attr_name] = data[i, <NUM_LIT:0>:num_e]<EOL><DEDENT><DEDENT><DEDENT>

process and attach data from fortran_cdf.get_multi_*


<EOL>

Runs after every method to clean up previous testing.


<EOL>

Runs before every method to create a clean testing setup.


kwargs['<STR_LIT>'] = Bucket<EOL>super(S3Connection, self).__init__(*args, **kwargs)<EOL>

Set the base class for bucket objects created in the connection to
        the MimicDB bucket class.


def _get_file_internal(self, *args, **kwargs):

super(Key, self)._get_file_internal(*args, **kwargs)<EOL>mimicdb.backend.sadd(tpl.bucket % self.bucket.name, self.name)<EOL>mimicdb.backend.hmset(tpl.key % (self.bucket.name, self.name),<EOL>dict(size=self.size, md5=self.md5))<EOL>

Called internally for any type of download. After download finishes,
        make sure the key is in the bucket set and save the metadata.


self._name = value<EOL>if value:<EOL><INDENT>meta = mimicdb.backend.hgetall(tpl.key % (self.bucket.name, value))<EOL>if meta:<EOL><INDENT>mimicdb.backend.sadd(tpl.bucket % self.bucket.name, value)<EOL>self._load_meta(meta['<STR_LIT:size>'], meta['<STR_LIT>'])<EOL><DEDENT><DEDENT>

Key name can be set by Key.key or Key.name. Key.key sets Key.name
        internally, so just handle this property. When changing the key
        name, try to load it's metadata from MimicDB. If it's not available,
        the key hasn't been uploaded, downloaded or synced so don't add it to
        the bucket set (it also might have just been deleted,
        see boto.s3.bucket.py#785)


if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.local_hashes = {}<EOL><DEDENT>self.size = int(size)<EOL>if (re.match('<STR_LIT>', md5)):<EOL><INDENT>self.md5 = md5<EOL><DEDENT>

Set key attributes to retrived metadata. Might be extended in the
        future to support more attributes.


if kwargs.pop('<STR_LIT>', None):<EOL><INDENT>headers = kwargs.get('<STR_LIT>', args[<NUM_LIT:4>] if len(args) > <NUM_LIT:4> else None) or dict()<EOL>headers['<STR_LIT>'] = True<EOL>kwargs['<STR_LIT>'] = headers<EOL>for key in super(Bucket, self).list(*args, **kwargs):<EOL><INDENT>yield key<EOL><DEDENT><DEDENT>else:<EOL><INDENT>prefix = kwargs.get('<STR_LIT>', args[<NUM_LIT:0>] if args else '<STR_LIT>')<EOL>for key in mimicdb.backend.smembers(tpl.bucket % self.name):<EOL><INDENT>if key.startswith(prefix):<EOL><INDENT>k = Key(self, key)<EOL>meta = mimicdb.backend.hgetall(tpl.key % (self.name, key))<EOL>if meta:<EOL><INDENT>k._load_meta(meta['<STR_LIT:size>'], meta['<STR_LIT>'])<EOL><DEDENT>yield k<EOL><DEDENT><DEDENT><DEDENT>

Return an iterable of keys from MimicDB.

        :param boolean force: If true, API call is forced to S3


headers = kwargs.get('<STR_LIT>', args[<NUM_LIT:2>] if len(args) > <NUM_LIT:2> else None) or dict()<EOL>if '<STR_LIT>' in headers:<EOL><INDENT>keys = super(Bucket, self)._get_all(*args, **kwargs)<EOL>for key in keys:<EOL><INDENT>mimicdb.backend.sadd(tpl.bucket % self.name, key.name)<EOL>mimicdb.backend.hmset(tpl.key % (self.name, key.name), dict(size=key.size, md5=key.etag.strip('<STR_LIT:">')))<EOL>key.name = key.name<EOL><DEDENT>return keys<EOL><DEDENT>prefix = kwargs.get('<STR_LIT>', '<STR_LIT>')<EOL>return list(self.list(prefix=prefix))<EOL>

If 'force' is in the headers, retrieve the list of keys from S3.
        Otherwise, use the list() function to retrieve the keys from MimicDB.


ikeys = iter(kwargs.get('<STR_LIT>', args[<NUM_LIT:0>] if args else []))<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>key = ikeys.next()<EOL><DEDENT>except StopIteration:<EOL><INDENT>break<EOL><DEDENT>if isinstance(key, basestring):<EOL><INDENT>mimicdb.backend.srem(tpl.bucket % self.name, key)<EOL>mimicdb.backend.delete(tpl.key % (self.name, key))<EOL><DEDENT>elif isinstance(key, BotoKey) or isinstance(key, Key):<EOL><INDENT>mimicdb.backend.srem(tpl.bucket % self.name, key.name)<EOL>mimicdb.backend.delete(tpl.key % (self.name, key.name))<EOL><DEDENT><DEDENT>return super(Bucket, self).delete_keys(*args, **kwargs)<EOL>

Remove each key or key name in an iterable from the bucket set.


self.sessions = []<EOL>

Clear all GenePattern sessions from the sessions list
:return:


for i in range(len(self.sessions)):<EOL><INDENT>session = self.sessions[i]<EOL>if session.url == server_url:<EOL><INDENT>return i<EOL><DEDENT><DEDENT>return -<NUM_LIT:1><EOL>

Returns a registered GPServer object with a matching GenePattern server url
Returns -1 if no matching result was found
:param server_url:
:return:


<EOL>if isinstance(server, int):<EOL><INDENT>if server >= len(self.sessions):<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>return self.sessions[server]<EOL><DEDENT><DEDENT>index = self._get_index(server)<EOL>if index == -<NUM_LIT:1>:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>return self.sessions[index]<EOL><DEDENT>

Returns a registered GPServer object with a matching GenePattern server url or index
Returns None if no matching result was found
:param server:
:return:


Display a widget, text or other media in a notebook without the need to import IPython at the top level.

Also handles wrapping GenePattern Python Library content in widgets.
:param content:
:return:


mode = _get_networking_mode(app)<EOL>ports_list = None<EOL>if mode == '<STR_LIT:host>':<EOL><INDENT>ports_list = _get_port_definitions(app)<EOL><DEDENT>elif mode == '<STR_LIT>':<EOL><INDENT>ports_list = _get_port_definitions(app)<EOL>if ports_list is None:<EOL><INDENT>ports_list = _get_container_port_mappings(app)<EOL><DEDENT><DEDENT>elif mode == '<STR_LIT>':<EOL><INDENT>ports_list = _get_ip_address_discovery_ports(app)<EOL>if not ports_list:<EOL><INDENT>ports_list = _get_container_port_mappings(app)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>".format(mode))<EOL><DEDENT>return len(ports_list)<EOL>

Get the number of ports for the given app JSON. This roughly follows the
logic in marathon-lb for finding app IPs/ports, although we are only
interested in the quantity of ports an app should have and don't consider
the specific IPs/ports of individual tasks:
https://github.com/mesosphere/marathon-lb/blob/v1.10.3/utils.py#L393-L415

:param app: The app JSON from the Marathon API.
:return: The number of ports for the app.


was_signalled, self._signalled_usr1 = self._signalled_usr1, False<EOL>return was_signalled<EOL>

Check and reset the ``_signalled_usr1`` flag.


was_signalled, self._signalled_hup = self._signalled_hup, False<EOL>return was_signalled<EOL>

Check and reset the ``_signalled_hup`` flag.


return self._kv_data.get(path)<EOL>

Read KV data at the given path. Returns the data and metadata.


return json.loads(request.content.read().decode('<STR_LIT:utf-8>'))<EOL>

Read the body of a request and decode it as JSON. The counterpart to
``marathon_acme.server.write_request_json`` but only used in tests.


return datetime.strptime(timestamp, '<STR_LIT>')<EOL>

Parse Marathon's ISO8601-like timestamps into a datetime.


matching_dict = {<EOL>'<STR_LIT>': Equals(event_type),<EOL>'<STR_LIT>': After(_parse_marathon_event_timestamp,<EOL>matches_time_or_just_before(datetime.utcnow()))<EOL>}<EOL>matching_dict.update(kwargs)<EOL>return MatchesDict(matching_dict)<EOL>

Match a dict (deserialized from JSON) as a Marathon event. Matches the
event type and checks for a recent timestamp.

:param event_type: The event type ('eventType' field value)
:param kwargs: Any other matchers to apply to the dict


d = Deferred()<EOL>self._waiting.append(d)<EOL>return d<EOL>

Get a deferred that will be fired when the connection is closed.


if line.startswith('<STR_LIT::>'):<EOL><INDENT>return None, None<EOL><DEDENT>if '<STR_LIT::>' not in line:<EOL><INDENT>return line, '<STR_LIT>'<EOL><DEDENT>field, value = line.split('<STR_LIT::>', <NUM_LIT:1>)<EOL>value = value[<NUM_LIT:1>:] if value.startswith('<STR_LIT:U+0020>') else value<EOL>return field, value<EOL>


def __init__(<EOL>self, handler, max_length=MAX_LENGTH, timeout=None, reactor=None):

self._handler = handler<EOL>self._max_length = max_length<EOL>self._timeout = timeout<EOL>if reactor is None:<EOL><INDENT>from twisted.internet import reactor as _reactor<EOL>reactor = _reactor<EOL><DEDENT>self._reactor = reactor<EOL>self._waiting = []<EOL>self._buffer = b'<STR_LIT>'<EOL>self._reset_event_data()<EOL>

:param handler:
    A 2-args callable that will be called back with the event and data
    when a complete message is received.
:param int max_length:
    The maximum length in bytes of a single line in an SSE event that
    will be accepted.
:param float timeout:
    Amount of time in seconds to wait for some data to be received
    before timing out. (Default: None - no timeout).
:param reactor:
    Reactor to use to timeout the connection.


log_level_filter = LogLevelFilterPredicate(<EOL>LogLevel.levelWithName(log_level))<EOL>log_level_filter.setLogLevelForNamespace(<EOL>'<STR_LIT>', LogLevel.warn)<EOL>log_observer = FilteringLogObserver(<EOL>textFileLogObserver(sys.stdout), [log_level_filter])<EOL>globalLogPublisher.addObserver(log_observer)<EOL>

Initialise the logging by adding an observer to the global log publisher.

:param str log_level: The minimum log level to log messages for.


@app.route('<STR_LIT>', branch=True, methods=['<STR_LIT:GET>'])<EOL><INDENT>def acme_challenge(self, request):<DEDENT>

return self.responder_resource<EOL>

Respond to ACME challenge validation requests on
``/.well-known/acme-challenge/`` using the ACME responder resource.


@app.route('<STR_LIT>', methods=['<STR_LIT:GET>'])<EOL><INDENT>def acme_challenge_ping(self, request):<DEDENT>

request.setResponseCode(OK)<EOL>write_request_json(request, {'<STR_LIT:message>': '<STR_LIT>'})<EOL>

Respond to requests on ``/.well-known/acme-challenge/ping`` to debug
path routing issues.


raw_headers = headers.getRawHeaders(key)<EOL>if raw_headers is None:<EOL><INDENT>return None<EOL><DEDENT>header, _ = cgi.parse_header(raw_headers[-<NUM_LIT:1>])<EOL>return header<EOL>

Get a single value for the given key out of the given set of headers.

:param twisted.web.http_headers.Headers headers:
    The set of headers in which to look for the header value
:param str key:
    The header key


if url is None:<EOL><INDENT>url = self.url<EOL><DEDENT>if url is None:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>')<EOL><DEDENT>split_result = urisplit(url)<EOL>userinfo = split_result.userinfo<EOL>compose_kwargs = {}<EOL>for key in ['<STR_LIT>', '<STR_LIT:host>', '<STR_LIT:port>', '<STR_LIT:path>', '<STR_LIT>']:<EOL><INDENT>if key in kwargs:<EOL><INDENT>compose_kwargs[key] = kwargs.pop(key)<EOL><DEDENT>else:<EOL><INDENT>compose_kwargs[key] = getattr(split_result, key)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>compose_kwargs['<STR_LIT>'] = kwargs.pop('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>compose_kwargs['<STR_LIT>'] = split_result.query<EOL><DEDENT>if '<STR_LIT>' not in kwargs and userinfo is not None:<EOL><INDENT>kwargs['<STR_LIT>'] = tuple(userinfo.split('<STR_LIT::>', <NUM_LIT:2>))<EOL><DEDENT>return uricompose(**compose_kwargs)<EOL>

Compose a URL starting with the given URL (or self.url if that URL is
None) and using the values in kwargs.

:param str url:
    The base URL to use. If None, ``self.url`` will be used instead.
:param dict kwargs:
    A dictionary of values to override in the base URL. Relevant keys
    will be popped from the dictionary.


def __init__(self, url=None, client=None, timeout=DEFAULT_TIMEOUT,<EOL>reactor=None):

self.url = url<EOL>self._timeout = timeout<EOL>self._client, self._reactor = default_client(reactor, client)<EOL>

Create a client with the specified default URL.


def request(self, method, url=None, **kwargs):

url = self._compose_url(url, kwargs)<EOL>kwargs.setdefault('<STR_LIT>', self._timeout)<EOL>d = self._client.request(method, url, reactor=self._reactor, **kwargs)<EOL>d.addCallback(self._log_request_response, method, url, kwargs)<EOL>d.addErrback(self._log_request_error, url)<EOL>return d<EOL>

Perform a request.

:param: method:
    The HTTP method to use (example is `GET`).
:param: url:
    The URL to use. The default value is the URL this client was
    created with (`self.url`) (example is `http://localhost:8080`)
:param: kwargs:
    Any other parameters that will be passed to `treq.request`, for
    example headers. Or any URL parameters to override, for example
    path, query or fragment.


def HasRequestProperties(method, url, query=None):

if query is None:<EOL><INDENT>query = {}<EOL><DEDENT>return MatchesStructure(<EOL>method=Equals(method.encode('<STR_LIT:ascii>')),<EOL>path=Equals(url.encode('<STR_LIT:ascii>')),<EOL>uri=After(lambda u: urisplit(u).getquerydict(), Equals(query))<EOL>)<EOL>

Check if a HTTP request object has certain properties.

Parses the query dict from the request URI rather than using the request
"args" property as the args do not include query parameters that have no
value.

:param str method:
    The HTTP method.
:param str url:
    The HTTP URL, without any query parameters. Should already be percent
    encoded.
:param dict query:
    A dictionary of HTTP query parameters.


self.agents[location] = agent<EOL>

Add an agent for URIs with the specified location.
:param bytes location:
    The URI authority/location (e.g. b'example.com:80')
:param agent: The twisted.web.iweb.IAgent to use for the location


@classmethod<EOL><INDENT>def from_env(cls, reactor=None, env=os.environ):<DEDENT>

address = env.get('<STR_LIT>', '<STR_LIT>')<EOL>token = env.get('<STR_LIT>', '<STR_LIT>')<EOL>ca_cert = env.get('<STR_LIT>')<EOL>tls_server_name = env.get('<STR_LIT>')<EOL>client_cert = env.get('<STR_LIT>')<EOL>client_key = env.get('<STR_LIT>')<EOL>cf = ClientPolicyForHTTPS.from_pem_files(<EOL>caKey=ca_cert, privateKey=client_key, certKey=client_cert,<EOL>tls_server_name=tls_server_name<EOL>)<EOL>client, reactor = default_client(reactor, contextFactory=cf)<EOL>return cls(address, token, client=client, reactor=reactor)<EOL>

Create a Vault client with configuration from the environment. Supports
a limited number of the available config options:
https://www.vaultproject.io/docs/commands/index.html#environment-variables
https://github.com/hashicorp/vault/blob/v0.11.3/api/client.go#L28-L40

Supported:
- ``VAULT_ADDR``
- ``VAULT_CACERT``
- ``VAULT_CLIENT_CERT``
- ``VAULT_CLIENT_KEY``
- ``VAULT_TLS_SERVER_NAME``
- ``VAULT_TOKEN``

Not currently supported:
- ``VAULT_CAPATH``
- ``VAULT_CLIENT_TIMEOUT``
- ``VAULT_MAX_RETRIES``
- ``VAULT_MFA``
- ``VAULT_RATE_LIMIT``
- ``VAULT_SKIP_VERIFY``
- ``VAULT_WRAP_TTL``


def read_kv2(self, path, version=None, mount_path='<STR_LIT>'):

params = {}<EOL>if version is not None:<EOL><INDENT>params['<STR_LIT:version>'] = version<EOL><DEDENT>read_path = '<STR_LIT>'.format(mount_path, path)<EOL>return self.read(read_path, **params)<EOL>

Read some data from a key/value version 2 secret engine.


def create_or_update_kv2(self, path, data, cas=None, mount_path='<STR_LIT>'):

params = {<EOL>'<STR_LIT>': {},<EOL>'<STR_LIT:data>': data<EOL>}<EOL>if cas is not None:<EOL><INDENT>params['<STR_LIT>']['<STR_LIT>'] = cas<EOL><DEDENT>write_path = '<STR_LIT>'.format(mount_path, path)<EOL>return self.write(write_path, **params)<EOL>

Create or update some data in a key/value version 2 secret engine.

:raises CasError:
    Raises an error if the ``cas`` value, when provided, doesn't match
    Vault's version for the key.


d = self.request('<STR_LIT>', '<STR_LIT>' + path, json=data)<EOL>return d.addCallback(self._handle_response, check_cas=True)<EOL>

Write data to Vault. Returns the JSON-decoded response.


d = self.request('<STR_LIT:GET>', '<STR_LIT>' + path, params=params)<EOL>return d.addCallback(self._handle_response)<EOL>

Read data from Vault. Returns the JSON-decoded response.


def __init__(self, url, token, *args, **kwargs):

super(VaultClient, self).__init__(*args, url=url, **kwargs)<EOL>self._token = token<EOL>

:param url: the URL for Vault
:param token: the Vault auth token


return self.get_json_field('<STR_LIT>', path='<STR_LIT>')<EOL>

Get the currently running Marathon apps, returning a list of app
definitions.


def sse_content(response, handler, **sse_kwargs):

<EOL>raise_for_not_ok_status(response)<EOL>raise_for_header(response, '<STR_LIT:Content-Type>', '<STR_LIT>')<EOL>finished, _ = _sse_content_with_protocol(response, handler, **sse_kwargs)<EOL>return finished<EOL>

Callback to collect the Server-Sent Events content of a response. Callbacks
passed will receive event data.

:param response:
    The response from the SSE request.
:param handler:
    The handler for the SSE protocol.


if response.code != OK:<EOL><INDENT>raise HTTPError('<STR_LIT>' % (<EOL>response.code, uridecode(response.request.absoluteURI)))<EOL><DEDENT>return response<EOL>

Raises a `requests.exceptions.HTTPError` if the response has a non-200
status code.


pem_objects = []<EOL>for key in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>pem_objects.extend(pem.parse(cert_data[key].encode('<STR_LIT:utf-8>')))<EOL><DEDENT>return pem_objects<EOL>

Given a non-None response from the Vault key/value store, convert the
key/values into a list of PEM objects.


Generate a wildcard (subject name '*') self-signed certificate valid for
10 years.

https://cryptography.io/en/latest/x509/tutorial/#creating-a-self-signed-certificate

:return: Bytes representation of the PEM certificate data


acme_key_file = pem_path.child(u'<STR_LIT>')<EOL>if acme_key_file.exists():<EOL><INDENT>key = _load_pem_private_key_bytes(acme_key_file.getContent())<EOL><DEDENT>else:<EOL><INDENT>key = generate_private_key(u'<STR_LIT>')<EOL>acme_key_file.setContent(_dump_pem_private_key_bytes(key))<EOL><DEDENT>return succeed(JWKRSA(key=key))<EOL>

Set up a client key if one does not exist already.

https://gist.github.com/glyph/27867a478bb71d8b6046fbfb176e1a33#file-local-certs-py-L32-L50

:type pem_path: twisted.python.filepath.FilePath
:param pem_path:
    The path to the certificate directory to use.
:rtype: twisted.internet.defer.Deferred


def errback(failure):<EOL><INDENT>failure.trap(txacme_ServerError)<EOL>acme_error = failure.value.message<EOL>if acme_error.code in ['<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>self.log.error(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>', code=acme_error.code, domain=domain,<EOL>detail=acme_error.detail)<EOL><DEDENT>else:<EOL><INDENT>return failure<EOL><DEDENT><DEDENT>d = self.txacme_service.issue_cert(domain)<EOL>return d.addErrback(errback)<EOL>

Issue a certificate for the given domain.


def __init__(self, marathon_client, group, cert_store, mlb_client,<EOL>txacme_client_creator, reactor, email=None,<EOL>allow_multiple_certs=False):

self.marathon_client = marathon_client<EOL>self.group = group<EOL>self.reactor = reactor<EOL>responder = HTTP01Responder()<EOL>self.server = MarathonAcmeServer(responder.resource)<EOL>mlb_cert_store = MlbCertificateStore(cert_store, mlb_client)<EOL>self.txacme_service = AcmeIssuingService(<EOL>mlb_cert_store, txacme_client_creator, reactor, [responder], email)<EOL>self._allow_multiple_certs = allow_multiple_certs<EOL>self._server_listening = None<EOL>

Create the marathon-acme service.

:param marathon_client: The Marathon API client.
:param group: The name of the marathon-lb group.
:param cert_store: The ``ICertificateStore`` instance to use.
:param mlb_clinet: The marathon-lb API client.
:param txacme_client_creator: Callable to create the txacme client.
:param reactor: The reactor to use.
:param email: The ACME registration email.
:param allow_multiple_certs:
    Whether to allow multiple certificates per app port.


tpl = TableLogger(columns='<STR_LIT>')<EOL>for f in os.listdir('<STR_LIT:.>'):<EOL><INDENT>size = os.stat(f).st_size<EOL>date_created = datetime.fromtimestamp(os.path.getctime(f))<EOL>date_modified = datetime.fromtimestamp(os.path.getmtime(f))<EOL>tpl(f, date_created, date_modified, size)<EOL><DEDENT>

Prints file details in the current directory


fmt = self.fmt(value)<EOL>if len(fmt) > self.col_width:<EOL><INDENT>fmt = fmt[:self.col_width - <NUM_LIT:3>] + '<STR_LIT>'<EOL><DEDENT>fmt = self.just(fmt, self.col_width)<EOL>return fmt<EOL>

Formats a given value

Args:
    value: value to format

Returns:
    str: formatted value


if PY2:<EOL><INDENT>buf = io.BytesIO()<EOL>csvwriter = csv.writer(buf)<EOL>csvwriter.writerow([c.strip().encode(self.encoding) for c in row])<EOL>csv_line = buf.getvalue().decode(self.encoding).rstrip()<EOL><DEDENT>else:<EOL><INDENT>buf = io.StringIO()<EOL>csvwriter = csv.writer(buf)<EOL>csvwriter.writerow([c.strip() for c in row])<EOL>csv_line = buf.getvalue().rstrip()<EOL><DEDENT>return csv_line<EOL>

Converts row values into a csv line

        Args:
            row: a list of row cells as unicode
        Returns:
            csv_line (unicode)


if len(self.formatters) == <NUM_LIT:0>:<EOL><INDENT>self.setup(*args)<EOL><DEDENT>row_cells = []<EOL>if self.rownum:<EOL><INDENT>row_cells.append(<NUM_LIT:0>)<EOL><DEDENT>if self.timestamp:<EOL><INDENT>row_cells.append(datetime.datetime.now())<EOL><DEDENT>if self.time_diff:<EOL><INDENT>row_cells.append(<NUM_LIT:0>)<EOL><DEDENT>row_cells.extend(args)<EOL>if len(row_cells) != len(self.formatters):<EOL><INDENT>raise ValueError('<STR_LIT>'.format(<EOL>len(self.formatters), len(row_cells)))<EOL><DEDENT>line = self.format_row(*row_cells)<EOL>self.print_line(line)<EOL>

Prints a formatted row

        Args:
            args: row cells


formatters = []<EOL>col_offset = <NUM_LIT:0><EOL>if self.rownum:<EOL><INDENT>formatters.append(fmt.RowNumberFormatter.setup(<NUM_LIT:0>))<EOL>col_offset += <NUM_LIT:1><EOL><DEDENT>if self.timestamp:<EOL><INDENT>formatters.append(fmt.DatetimeFormatter.setup(<EOL>datetime.datetime.now(),<EOL>fmt='<STR_LIT>'.format,<EOL>col_width=<NUM_LIT>))<EOL>col_offset += <NUM_LIT:1><EOL><DEDENT>if self.time_diff:<EOL><INDENT>formatters.append(fmt.TimeDeltaFormatter.setup(<NUM_LIT:0>))<EOL>col_offset += <NUM_LIT:1><EOL><DEDENT>for coli, value in enumerate(args):<EOL><INDENT>fmt_class = type2fmt.get(type(value), fmt.GenericFormatter)<EOL>kwargs = {}<EOL>if self.default_colwidth is not None:<EOL><INDENT>kwargs['<STR_LIT>'] = self.default_colwidth<EOL><DEDENT>if coli in self.column_widths:<EOL><INDENT>kwargs['<STR_LIT>'] = self.column_widths[coli]<EOL><DEDENT>elif self.columns and self.columns[coli + col_offset] in self.column_widths:<EOL><INDENT>kwargs['<STR_LIT>'] = self.column_widths[self.columns[coli + col_offset]]<EOL><DEDENT>if fmt_class == fmt.FloatFormatter and self.float_format is not None:<EOL><INDENT>kwargs['<STR_LIT>'] = self.float_format<EOL><DEDENT>if coli in self.column_formatters:<EOL><INDENT>kwargs['<STR_LIT>'] = self.column_formatters[coli]<EOL><DEDENT>elif self.columns and self.columns[coli + col_offset] in self.column_formatters:<EOL><INDENT>kwargs['<STR_LIT>'] = self.column_formatters[self.columns[coli + col_offset]]<EOL><DEDENT>formatter = fmt_class.setup(value, **kwargs)<EOL>formatters.append(formatter)<EOL><DEDENT>self.formatters = formatters<EOL>

Setup formatters by observing the first row.

        Args:
            *args: row cells


if isinstance(val, str):<EOL><INDENT>val = val.lower()<EOL><DEDENT>return val in ['<STR_LIT:true>', '<STR_LIT>', '<STR_LIT:yes>', True]<EOL>

Helper function to turn a string representation of "true" into
boolean True.


bits = token.split_contents()<EOL>if len(bits) < <NUM_LIT:2>:<EOL><INDENT>raise TemplateSyntaxError("<STR_LIT>"<EOL>"<STR_LIT>" % bits[<NUM_LIT:0>])<EOL><DEDENT>page = parser.compile_filter(bits[<NUM_LIT:1>])<EOL>kwargs = {}<EOL>bits = bits[<NUM_LIT:2>:]<EOL>kwarg_re = re.compile(r'<STR_LIT>')<EOL>if len(bits):<EOL><INDENT>for bit in bits:<EOL><INDENT>match = kwarg_re.match(bit)<EOL>if not match:<EOL><INDENT>raise TemplateSyntaxError("<STR_LIT>")<EOL><DEDENT>name, value = match.groups()<EOL>kwargs[name] = parser.compile_filter(value)<EOL><DEDENT><DEDENT>return BootstrapPagerNode(page, kwargs)<EOL>

Renders a Page object as a Twitter Bootstrap styled pager bar.
Compatible with Bootstrap 2.x and 3.x only.

Example::

    {% bootstrap_pager page_obj %}

Named Parameters::

    previous_label - The label to show for the Previous link (defaults to "Previous Page")

    next_label - The label to show for the Next link (defualts to "Next Page")

    previous_title - The link title for the previous link (defaults to "Previous Page")

    next_title - The link title for the next link (defaults to "Next Page")

    url_view_name - The named URL to use. Defaults to None. If None, then the
                    default template simply appends the url parameter as a
                    relative URL link, eg: 1

    url_param_name - The name of the parameter to use in the URL. If
                     url_view_name is set to None, this string is used as the
                     parameter name in the relative URL path. If a URL
                     name is specified, this string is used as the
                     parameter name passed into the reverse() method for
                     the URL.

    url_extra_args - This is used only in conjunction with url_view_name.
                    When referencing a URL, additional arguments may be
                    passed in as a list.

    url_extra_kwargs - This is used only in conjunction with url_view_name.
                       When referencing a URL, additional named arguments
                       may be passed in as a dictionary.

    url_get_params - The other get parameters to pass, only the page
                     number will be overwritten. Use this to preserve
                     filters.

    url_anchor - The anchor to use in URLs. Defaults to None.

    extra_pager_classes - A space separated list of CSS class names
                          that will be added to the top level

                          HTML element. This could be  used to,
                          as an example, add a class to prevent
                          the pager from showing up when printing.


def get_page_url(page_num, current_app, url_view_name, url_extra_args, url_extra_kwargs, url_param_name, url_get_params, url_anchor):

if url_view_name is not None:<EOL><INDENT>url_extra_kwargs[url_param_name] = page_num<EOL>try:<EOL><INDENT>url = reverse(url_view_name, args=url_extra_args, kwargs=url_extra_kwargs, current_app=current_app)<EOL><DEDENT>except NoReverseMatch as e:  <EOL><INDENT>if settings.SETTINGS_MODULE:<EOL><INDENT>if django.VERSION < (<NUM_LIT:1>, <NUM_LIT:9>, <NUM_LIT:0>):<EOL><INDENT>separator  = '<STR_LIT:.>'<EOL><DEDENT>else:<EOL><INDENT>separator  = '<STR_LIT::>' <EOL><DEDENT>project_name = settings.SETTINGS_MODULE.split('<STR_LIT:.>')[<NUM_LIT:0>]<EOL>try:<EOL><INDENT>url = reverse(project_name + separator + url_view_name, args=url_extra_args, kwargs=url_extra_kwargs, current_app=current_app)<EOL><DEDENT>except NoReverseMatch:<EOL><INDENT>raise e <EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise e <EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>url = '<STR_LIT>'<EOL>url_get_params = url_get_params or QueryDict(url)<EOL>url_get_params = url_get_params.copy()<EOL>url_get_params[url_param_name] = str(page_num)<EOL><DEDENT>if len(url_get_params) > <NUM_LIT:0>:<EOL><INDENT>if not isinstance(url_get_params, QueryDict):<EOL><INDENT>tmp = QueryDict(mutable=True)<EOL>tmp.update(url_get_params)<EOL>url_get_params = tmp<EOL><DEDENT>url += '<STR_LIT:?>' + url_get_params.urlencode()<EOL><DEDENT>if (url_anchor is not None):<EOL><INDENT>url += '<STR_LIT:#>' + url_anchor<EOL><DEDENT>return url<EOL>

Helper function to return a valid URL string given the template tag parameters


bits = token.split_contents()<EOL>if len(bits) < <NUM_LIT:2>:<EOL><INDENT>raise TemplateSyntaxError("<STR_LIT>"<EOL>"<STR_LIT>" % bits[<NUM_LIT:0>])<EOL><DEDENT>page = parser.compile_filter(bits[<NUM_LIT:1>])<EOL>kwargs = {}<EOL>bits = bits[<NUM_LIT:2>:]<EOL>kwarg_re = re.compile(r'<STR_LIT>')<EOL>if len(bits):<EOL><INDENT>for bit in bits:<EOL><INDENT>match = kwarg_re.match(bit)<EOL>if not match:<EOL><INDENT>raise TemplateSyntaxError("<STR_LIT>")<EOL><DEDENT>name, value = match.groups()<EOL>kwargs[name] = parser.compile_filter(value)<EOL><DEDENT><DEDENT>return BootstrapPaginationNode(page, kwargs)<EOL>

Renders a Page object as a Twitter Bootstrap styled pagination bar.
Compatible with Bootstrap 3.x and 4.x only.

Example::

    {% bootstrap_paginate page_obj range=10 %}

Named Parameters::

    range - The size of the pagination bar (ie, if set to 10 then, at most,
            10 page numbers will display at any given time) Defaults to
            None, which shows all pages.

    size - Accepts "small", and "large". Defaults to
                None which is the standard size.

    show_prev_next - Accepts "true" or "false". Determines whether or not
                    to show the previous and next page links. Defaults to
                    "true"

    show_first_last - Accepts "true" or "false". Determines whether or not
                      to show the first and last page links. Defaults to
                      "false"

    previous_label - The text to display for the previous page link.
                     Defaults to "←"

    next_label - The text to display for the next page link. Defaults to
                 "→"

    first_label - The text to display for the first page link. Defaults to
                  "«"

    last_label - The text to display for the last page link. Defaults to
                 "»"

    url_view_name - The named URL to use. Defaults to None. If None, then the
                    default template simply appends the url parameter as a
                    relative URL link, eg: 1

    url_param_name - The name of the parameter to use in the URL. If
                     url_view_name is set to None, this string is used as the
                     parameter name in the relative URL path. If a URL
                     name is specified, this string is used as the
                     parameter name passed into the reverse() method for
                     the URL.

    url_extra_args - This is used only in conjunction with url_view_name.
                     When referencing a URL, additional arguments may be
                     passed in as a list.

    url_extra_kwargs - This is used only in conjunction with url_view_name.
                       When referencing a URL, additional named arguments
                       may be passed in as a dictionary.

    url_get_params - The other get parameters to pass, only the page
                     number will be overwritten. Use this to preserve
                     filters.

    url_anchor - The anchor to use in URLs. Defaults to None.

    extra_pagination_classes - A space separated list of CSS class names
                               that will be added to the top level

                               HTML element. In particular, this can be
                               utilized in Bootstrap 4 installatinos  to
                               add the appropriate alignment classes from
                               Flexbox utilites, eg:  justify-content-center


return self.semantics in ('<STR_LIT>', '<STR_LIT>')<EOL>


b = [bytes([self._opcode])]<EOL>for offset in reversed(range(self.operand_size)):<EOL><INDENT>b.append(bytes([(self.operand >> offset * <NUM_LIT:8>) & <NUM_LIT>]))<EOL><DEDENT>return b'<STR_LIT>'.join(b)<EOL>


def assemble_one(asmcode, pc=<NUM_LIT:0>, fork=DEFAULT_FORK):

try:<EOL><INDENT>instruction_table = instruction_tables[fork]<EOL>asmcode = asmcode.strip().split('<STR_LIT:U+0020>')<EOL>instr = instruction_table[asmcode[<NUM_LIT:0>].upper()]<EOL>if pc:<EOL><INDENT>instr.pc = pc<EOL><DEDENT>if instr.operand_size > <NUM_LIT:0>:<EOL><INDENT>assert len(asmcode) == <NUM_LIT:2><EOL>instr.operand = int(asmcode[<NUM_LIT:1>], <NUM_LIT:0>)<EOL><DEDENT>return instr<EOL><DEDENT>except:<EOL><INDENT>raise AssembleError("<STR_LIT>" % pc)<EOL><DEDENT>

Assemble one EVM instruction from its textual representation.

        :param asmcode: assembly code for one instruction
        :type asmcode: str
        :param pc: program counter of the instruction(optional)
        :type pc: int
        :param fork: fork name (optional)
        :type fork: str
        :return: An Instruction object
        :rtype: Instruction

        Example use::

            >>> print assemble_one('LT')


return self._opcode == other._opcode andself._name == other._name andself._operand == other._operand andself._operand_size == other._operand_size andself._pops == other._pops andself._pushes == other._pushes andself._fee == other._fee andself._pc == other._pc andself._description == other._description<EOL>

Instructions are equal if all features match


def assemble_all(asmcode, pc=<NUM_LIT:0>, fork=DEFAULT_FORK):

asmcode = asmcode.split('<STR_LIT:\n>')<EOL>asmcode = iter(asmcode)<EOL>for line in asmcode:<EOL><INDENT>if not line.strip():<EOL><INDENT>continue<EOL><DEDENT>instr = assemble_one(line, pc=pc, fork=fork)<EOL>yield instr<EOL>pc += instr.size<EOL><DEDENT>

Assemble a sequence of textual representation of EVM instructions

        :param asmcode: assembly code for any number of instructions
        :type asmcode: str
        :param pc: program counter of the first instruction(optional)
        :type pc: int
        :param fork: fork name (optional)
        :type fork: str
        :return: An generator of Instruction objects
        :rtype: generator[Instructions]

        Example use::

            >>> assemble_one('''PUSH1 0x60\n \
                            PUSH1 0x40\n \
                            MSTORE\n \
                            PUSH1 0x2\n \
                            PUSH2 0x108\n \
                            PUSH1 0x0\n \
                            POP\n \
                            SSTORE\n \
                            PUSH1 0x40\n \
                            MLOAD\n \
                            ''')


return self.semantics in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>

True if the instruction is a transaction terminator


True if the instruction is a transaction initiator


return self._operand_size<EOL>


return self.group == '<STR_LIT>'<EOL>

True if the instruction access enviromental data


return self.operand_size > <NUM_LIT:0><EOL>

True if the instruction uses an immediate operand


return self._pushes<EOL>


return self.semantics in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>

True if the instruction is a basic block terminator


if self._name == '<STR_LIT>':<EOL><INDENT>return '<STR_LIT>' % self.operand_size<EOL><DEDENT>elif self._name == '<STR_LIT>':<EOL><INDENT>return '<STR_LIT>' % self.pops<EOL><DEDENT>elif self._name == '<STR_LIT>':<EOL><INDENT>return '<STR_LIT>' % (self.pops - <NUM_LIT:1>)<EOL><DEDENT>elif self._name == '<STR_LIT>':<EOL><INDENT>return '<STR_LIT>' % (self.pops - <NUM_LIT:2>)<EOL><DEDENT>return self._name<EOL>


return self._opcode<EOL>


return self.name<EOL>


return self.semantics in (<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>

True if the instruction is an arithmetic operation


return self.semantics in '<STR_LIT>'<EOL>

True if the instruction reads from the storage


True if the instruction writes to memory


buf = iter(buf)<EOL>try:<EOL><INDENT>operand = <NUM_LIT:0><EOL>for _ in range(self.operand_size):<EOL><INDENT>operand <<= <NUM_LIT:8><EOL>operand |= next(buf)<EOL><DEDENT>self._operand = operand<EOL><DEDENT>except StopIteration:<EOL><INDENT>raise ParseError("<STR_LIT>")<EOL><DEDENT>

Parses an operand from buf

            :param buf: a buffer
            :type buf: iterator/generator/string


def assemble_hex(asmcode, pc=<NUM_LIT:0>, fork=DEFAULT_FORK):

if isinstance(asmcode, list):<EOL><INDENT>return '<STR_LIT>' + hexlify(b'<STR_LIT>'.join([x.bytes for x in asmcode])).decode('<STR_LIT:ascii>')<EOL><DEDENT>return '<STR_LIT>' + hexlify(assemble(asmcode, pc=pc, fork=fork)).decode('<STR_LIT:ascii>')<EOL>

Assemble an EVM program

        :param asmcode: an evm assembler program
        :type asmcode: str | iterator[Instruction]
        :param pc: program counter of the first instruction(optional)
        :type pc: int
        :param fork: fork name (optional)
        :type fork: str
        :return: the hex representation of the bytecode
        :rtype: str

        Example use::

            >>> assemble_hex('''PUSH1 0x60\n \
                                       BLOCKHASH\n \
                                       MSTORE\n \
                                       PUSH1 0x2\n \
                                       PUSH2 0x100\n \
                                    ''')
            ...
            "0x6060604052600261010"


def disassemble_hex(bytecode, pc=<NUM_LIT:0>, fork=DEFAULT_FORK):

if bytecode.startswith('<STR_LIT>'):<EOL><INDENT>bytecode = bytecode[<NUM_LIT:2>:]<EOL><DEDENT>bytecode = unhexlify(bytecode)<EOL>return disassemble(bytecode, pc=pc, fork=fork)<EOL>

Disassemble an EVM bytecode

        :param bytecode: canonical representation of an evm bytecode (hexadecimal)
        :type bytecode: str
        :param pc: program counter of the first instruction(optional)
        :type pc: int
        :param fork: fork name (optional)
        :type fork: str
        :return: the text representation of the assembler code
        :rtype: str

        Example use::

            >>> disassemble_hex("0x6060604052600261010")
            ...
            PUSH1 0x60
            BLOCKHASH
            MSTORE
            PUSH1 0x2
            PUSH2 0x100


return self.pushes > <NUM_LIT:0><EOL>

True if the instruction writes to the stack


def _shell(cmd, check=True, stdin=None, stdout=None, stderr=None):

return subprocess.run(cmd, shell=True, check=check, stdin=stdin, stdout=stdout, stderr=stderr)<EOL>

Runs a subprocess shell with check=True by default


result = temple.utils.shell('<STR_LIT>', stdout=subprocess.PIPE)<EOL>return result.stdout.decode('<STR_LIT:utf8>').strip()<EOL>


def _apply_template(template, target, *, checkout, extra_context):

with tempfile.TemporaryDirectory() as tempdir:<EOL><INDENT>repo_dir = cc_main.cookiecutter(<EOL>template,<EOL>checkout=checkout,<EOL>no_input=True,<EOL>output_dir=tempdir,<EOL>extra_context=extra_context)<EOL>for item in os.listdir(repo_dir):<EOL><INDENT>src = os.path.join(repo_dir, item)<EOL>dst = os.path.join(target, item)<EOL>if os.path.isdir(src):<EOL><INDENT>if os.path.exists(dst):<EOL><INDENT>shutil.rmtree(dst)<EOL><DEDENT>shutil.copytree(src, dst)<EOL><DEDENT>else:<EOL><INDENT>if os.path.exists(dst):<EOL><INDENT>os.remove(dst)<EOL><DEDENT>shutil.copy2(src, dst)<EOL><DEDENT><DEDENT><DEDENT>

Apply a template to a temporary directory and then copy results to target.