Run external hex editor on a packet or bytes. Set editor in conf.prog.hexedit
559766
def hexedit(x):
    """"""
    x = bytes(x)
    fname = get_temp_file()
    with open(fname,"wb") as f:
      f.write(x)
    subprocess.call([conf.prog.hexedit, fname])
    with open(fname, "rb") as f:
      x = f.read()
    return x
918507
def mode(self, set_bytes):
        
        self._mode = set_bytes
        data = [self.ISS_CMD, self.ISS_SET_MODE] + set_bytes
        self.write_data(data)
        response = self.read_data(2)
        if response[0] == 0:
            error_dict = {
                0x05: 'Unknown Command',
                0x06: 'Internal Error 1',
                0x07: 'Internal Error 2'
            }
            try:
                raise USBISSError(error_dict[response(1)])
            except KeyError:
                raise USBISSError('Undocumented Error')
125413
def open_with_external_spyder(self, text):
        """"""
        match = get_error_match(to_text_string(text))
        if match:
            fname, lnb = match.groups()
            builtins.open_in_spyder(fname, int(lnb))
409316
def run(command, **kw):
    """"""
    # Windows low-level subprocess API wants str for current working
    # directory.
    if sys.platform == 'win32':
        _cwd = kw.get('cwd', None)
        if _cwd is not None:
            kw['cwd'] = _cwd.decode()
    try:
        # In Python 3, iterating over bytes yield integers, so we call
        # `splitlines()` to force Python 3 to give us lines instead.
        return check_output(command, **kw).splitlines()
    except CalledProcessError:
        return ()
    except FileNotFoundError:
        print("The {} binary was not found. Skipping directory {}.\n"
              .format(command[0], kw['cwd'].decode("UTF-8")))
        return ()
813028
function fromHex(hex, binary, offset) {
  if (binary) {
    binary.write(hex, offset, "hex");
    return binary;
  }
  return new Buffer(hex, 'hex');
}
910930
def run_pylint(self):
        """"""
        if (self.get_option('save_before', True)
                and not self.main.editor.save()):
            return
        self.switch_to_plugin()
        self.analyze(self.main.editor.get_current_filename())
1252463
def run(self, command):
        
        if isinstance(command, basestring):
            command = command.split()
        else:
            command = list(command)
        self.external.omero_cli(command)
1041284
def encoding_and_executable(notebook, metadata, ext):
    """"""
    lines = []
    comment = _SCRIPT_EXTENSIONS.get(ext, {}).get('comment')
    jupytext_metadata = metadata.get('jupytext', {})

    if ext not in ['.Rmd', '.md'] and 'executable' in jupytext_metadata:
        lines.append(comment + '!' + jupytext_metadata.pop('executable'))

    if 'encoding' in jupytext_metadata:
        lines.append(jupytext_metadata.pop('encoding'))
    elif ext not in ['.Rmd', '.md']:
        for cell in notebook.cells:
            try:
                cell.source.encode('ascii')
            except (UnicodeEncodeError, UnicodeDecodeError):
                lines.append(comment + _UTF8_HEADER)
                break

    return lines
355525
def pack_ihex(type_, address, size, data):
    

    line = '{:02X}{:04X}{:02X}'.format(size, address, type_)

    if data:
        line += binascii.hexlify(data).decode('ascii').upper()

    return ':{}{:02X}'.format(line, crc_ihex(line))
1070939
def random_hex(length):
    """"""
    return escape.to_unicode(binascii.hexlify(os.urandom(length))[length:])
498111
def _sethex(self, hexstring):
        """"""
        hexstring = tidy_input_string(hexstring)
        # remove any 0x if present
        hexstring = hexstring.replace('0x', '')
        length = len(hexstring)
        if length % 2:
            hexstring += '0'
        try:
            try:
                data = bytearray.fromhex(hexstring)
            except TypeError:
                # Python 2.6 needs a unicode string (a bug). 2.7 and 3.x work fine.
                data = bytearray.fromhex(unicode(hexstring))
        except ValueError:
            raise CreationError("Invalid symbol in hex initialiser.")
        self._setbytes_unsafe(data, length * 4, 0)
609381
def _run_command(self, packet):
        
        create_temp_cli = self.client_states is None

        if create_temp_cli:
            # If this client doesn't have a CLI. Create a Fake CLI where the
            # window containing this pane, is the active one. (The CLI instance
            # will be removed before the render function is called, so it doesn't
            # hurt too much and makes the code easier.)
            pane_id = int(packet['pane_id'])
            self._create_app()
            with set_app(self.client_state.app):
                self.pymux.arrangement.set_active_window_from_pane_id(pane_id)

        with set_app(self.client_state.app):
            try:
                self.pymux.handle_command(packet['data'])
            finally:
                self._close_connection()
928558
def run_treefix(input, stree_file, smap_file, a_ext=".fasta", \
                o_ext=".dnd", n_ext = ".treefix.dnd", **kwargs):
    
    cl = TreeFixCommandline(input=input, \
            stree_file=stree_file, smap_file=smap_file, a_ext=a_ext, \
            o=o_ext, n=n_ext, **kwargs)
    outtreefile = input.rsplit(o_ext, 1)[0] + n_ext
    print("TreeFix:", cl, file=sys.stderr)
    r, e = cl.run()

    if e:
        print("***TreeFix could not run", file=sys.stderr)
        return None
    else:
        logging.debug("new tree written to {0}".format(outtreefile))
        return outtreefile
1201432
def bin2hex(fin, fout, offset=0):
    
    h = IntelHex()
    try:
        h.loadbin(fin, offset)
    except IOError:
        e = sys.exc_info()[1]     # current exception
        txt = 'ERROR: unable to load bin file:', str(e)
        print(txt)
        return 1

    try:
        h.tofile(fout, format='hex')
    except IOError:
        e = sys.exc_info()[1]     # current exception
        txt = "ERROR: Could not write to file: %s: %s" % (fout, str(e))
        print(txt)
        return 1

    return 0
464046
def run_file_or_script (script=None, file_name='script_from_command_line',
                        argv=None, params=None, **kwargs):
    """"""
    runner= Ayrton (**kwargs)

    if params is None:
        params= ExecParams ()

    if script is None:
        v= runner.run_file (file_name, argv, params)
    else:
        if not isinstance(script, bytes):
            # the problem here it's that the parser expects the source as bytes
            # so we must encode the source before passing it
            script = script.encode()
        v= runner.run_script (script, file_name, argv, params)

    return v
1112604
def execute(self, payload, *args, flavour: ModuleType, **kwargs):
        
        if args or kwargs:
            payload = functools.partial(payload, *args, **kwargs)
        return self._meta_runner.run_payload(payload, flavour=flavour)
148747
def run_open(state, module, *args, **kwargs):
    
    from ..core import which, ensure_project, inline_activate_virtual_environment

    # Ensure that virtualenv is available.
    ensure_project(
        three=state.three, python=state.python,
        validate=False, pypi_mirror=state.pypi_mirror,
    )
    c = delegator.run(
        '{0} -c "import {1}; print({1}.__file__);"'.format(which("python"), module)
    )
    try:
        assert c.return_code == 0
    except AssertionError:
        echo(crayons.red("Module not found!"))
        sys.exit(1)
    if "__init__.py" in c.out:
        p = os.path.dirname(c.out.strip().rstrip("cdo"))
    else:
        p = c.out.strip().rstrip("cdo")
    echo(crayons.normal("Opening {0!r} in your EDITOR.".format(p), bold=True))
    inline_activate_virtual_environment()
    edit(filename=p)
    return 0