Smudge magic bytes with raw bytes
427392
def smudgeraw(target, offset, magicbytes):
    
    magicbytes = magicbytes.replace('\\x', '').decode('hex')

    _backup_bytes(target, offset, len(magicbytes))
    _smudge_bytes(target, offset, magicbytes)
381484
def bytes(self):
        """"""
        addrbyte = b'\x00\x00\x00'
        if self.addr is not None:
            addrbyte = self.addr
        return addrbyte
837953
def get_bytes_to_image_callback(image_dims=(224, 224)):
    """"""
    from keras.preprocessing import image
    import numpy as np
    from PIL import Image
    from io import BytesIO

    def preprocess_image_bytes(data_bytes):
        """Process image bytes for ImageNet."""
        try:
            img = Image.open(BytesIO(data_bytes))  # open image
        except OSError as e:
            raise ValueError('Please provide a raw image')
        img = img.resize(image_dims, Image.ANTIALIAS)  # model requires 224x224 pixels
        x = image.img_to_array(img)  # convert image to numpy array
        x = np.expand_dims(x, axis=0)  # model expects dim 0 to be iterable across images
        return x
    return preprocess_image_bytes
323877
def _get_file_magic_name(self, buffer):
        
        default = "Unknown"
        ftype = None

        try:
            # Magic is optional
            import magic
        except ImportError:
            return default

        try:
            # There are several implementations of magic,
            # unfortunately all called magic
            # We use this one: https://github.com/ahupp/python-magic/
            getattr(magic, "MagicException")
        except AttributeError:
            # Looks like no magic was installed
            return default

        try:
            ftype = magic.from_buffer(buffer[:1024])
        except magic.MagicError as e:
            log.exception("Error getting the magic type!")
            return default

        if not ftype:
            return default
        else:
            return self._patch_magic(buffer, ftype)
650208
function unpack(multibuffer) {
  var buffs = []
  var offset = 0
  var length

  while (offset < multibuffer.length) {
    length = vdecode(multibuffer.slice(offset))
    offset += vdecode.bytes
    buffs.push(multibuffer.slice(offset, offset + length))
    offset += length
  }

  return buffs
}
311324
def guess_mimetype(blob):
    
    mimetype = 'application/octet-stream'
    # this is a bit of a hack to support different versions of python magic.
    # Hopefully at some point this will no longer be necessary
    #
    # the version with open() is the bindings shipped with the file source from
    # http://darwinsys.com/file/ - this is what is used by the python-magic
    # package on Debian/Ubuntu. However, it is not available on pypi/via pip.
    #
    # the version with from_buffer() is available at
    # https://github.com/ahupp/python-magic and directly installable via pip.
    #
    # for more detail see https://github.com/pazz/alot/pull/588
    if hasattr(magic, 'open'):
        m = magic.open(magic.MAGIC_MIME_TYPE)
        m.load()
        magictype = m.buffer(blob)
    elif hasattr(magic, 'from_buffer'):
        # cf. issue #841
        magictype = magic.from_buffer(blob, mime=True) or magictype
    else:
        raise Exception('Unknown magic API')

    # libmagic does not always return proper mimetype strings, cf. issue #459
    if re.match(r'\w+\/\w+', magictype):
        mimetype = magictype
    return mimetype
938309
def raw(mime='application/octet-stream'):
    '''
    
    '''
    def dfn(fn):
        tags = getattr(fn, 'tags', set())
        tags.add('raw')
        fn.tags = tags
        fn.mime = getattr(fn, 'mime', mime)
        return fn
    return dfn
555279
function stripBOM (file) {
  var buffer = file.data;

  if (file.encoding === 'utf8' || file.encoding === 'utf-8') {
    // Check for the UTF-8 byte order mark (0xEFBBBF)
    if (buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
      return buffer.slice(3);
    }
  }

  return buffer;
}
1037611
def _magic_data(filename=os.path.join(here, 'magic_data.json')):
    
    with open(filename) as f:
        data = json.load(f)
    headers = [_create_puremagic(x) for x in data['headers']]
    footers = [_create_puremagic(x) for x in data['footers']]
    return headers, footers
658702
def imagemagick(color_count, img, magick_command):
    """"""
    flags = ["-resize", "25%", "-colors", str(color_count),
             "-unique-colors", "txt:-"]
    img += "[0]"

    return subprocess.check_output([*magick_command, img, *flags]).splitlines()
1166267
def force_bytes(bytes_or_unicode, encoding='utf-8', errors='backslashreplace'):
	''
	if isinstance(bytes_or_unicode, bytes): return bytes_or_unicode
	return bytes_or_unicode.encode(encoding, errors)
1314988
def from_buffer(buffer, mime=False):
    
    m = _get_magic_type(mime)
    return m.from_buffer(buffer)
989706
def dump_raw(self, text, stream=None):
        """"""
        encrypted = self.vault.encrypt(text)
        if stream:
            stream.write(encrypted)
        else:
            return encrypted
602535
private void findMagic() throws BitcoinBlockReadException {
	// search if first byte of any magic matches
	// search up to maximum size of a bitcoin block
	int currentSeek=0;
	while(currentSeek!=this.maxSizeBitcoinBlock) {
		int firstByte=-1;
		try {
			this.bin.mark(4); // magic is always 4 bytes
			firstByte=this.bin.read();
		} catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}
		if (firstByte==-1) { 
			throw new BitcoinBlockReadException("Error: Did not find defined magic within current stream");
		}
		try {
			if (checkForMagicBytes(firstByte)) {
				return;
			}
		} catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}
		if (currentSeek==this.maxSizeBitcoinBlock) { 
			throw new BitcoinBlockReadException("Error: Cannot seek to a block start, because no valid block found within the maximum size of a Bitcoin block. Check data or increase maximum size of Bitcoin block.");
		}
	// increase by one byte if magic not found yet
		try {
			this.bin.reset();
			if (this.bin.skip(1)!=1) {
				LOG.error("Error cannot skip 1 byte in InputStream");
			}
		} catch (IOException e) {
			LOG.error(e);
			throw new BitcoinBlockReadException(e.toString());
		}
	currentSeek++;
	}
}
778893
def _run_smoove(full_bams, sr_bams, disc_bams, work_dir, items):
    
    batch = sshared.get_cur_batch(items)
    ext = "-%s-svs" % batch if batch else "-svs"
    name = "%s%s" % (dd.get_sample_name(items[0]), ext)
    out_file = os.path.join(work_dir, "%s-smoove.genotyped.vcf.gz" % name)
    sv_exclude_bed = sshared.prepare_exclude_file(items, out_file)
    old_out_file = os.path.join(work_dir, "%s%s-prep.vcf.gz"
                                % (os.path.splitext(os.path.basename(items[0]["align_bam"]))[0], ext))
    if utils.file_exists(old_out_file):
        return old_out_file, sv_exclude_bed
    if not utils.file_exists(out_file):
        with file_transaction(items[0], out_file) as tx_out_file:
            cores = dd.get_num_cores(items[0])
            out_dir = os.path.dirname(tx_out_file)
            ref_file = dd.get_ref_file(items[0])
            full_bams = " ".join(_prepare_smoove_bams(full_bams, sr_bams, disc_bams, items,
                                                      os.path.dirname(tx_out_file)))
            std_excludes = ["~^GL", "~^HLA", "~_random", "~^chrUn", "~alt", "~decoy"]
            def _is_std_exclude(n):
                clean_excludes = [x.replace("~", "").replace("^", "") for x in std_excludes]
                return any([n.startswith(x) or n.endswith(x) for x in clean_excludes])
            exclude_chrs = [c.name for c in ref.file_contigs(ref_file)
                            if not chromhacks.is_nonalt(c.name) and not _is_std_exclude(c.name)]
            exclude_chrs = "--excludechroms '%s'" % ",".join(std_excludes + exclude_chrs)
            exclude_bed = ("--exclude %s" % sv_exclude_bed) if utils.file_exists(sv_exclude_bed) else ""
            tempdir = os.path.dirname(tx_out_file)
            cmd = ("export TMPDIR={tempdir} && "
                   "smoove call --processes {cores} --genotype --removepr --fasta {ref_file} "
                   "--name {name} --outdir {out_dir} "
                   "{exclude_bed} {exclude_chrs} {full_bams}")
            with utils.chdir(tempdir):
                try:
                    do.run(cmd.format(**locals()), "smoove lumpy calling", items[0])
                except subprocess.CalledProcessError as msg:
                    if _allowed_errors(msg):
                        vcfutils.write_empty_vcf(tx_out_file, config=items[0]["config"],
                                                 samples=[dd.get_sample_name(d) for d in items])
                    else:
                        logger.exception()
                        raise
    vcfutils.bgzip_and_index(out_file, items[0]["config"])
    return out_file, sv_exclude_bed
390535
function (bytes) {
                var str = '';
                for (var i = 0, l = bytes.length; i < l; i++) {
                    if (bytes[i] < 0x7F) {
                        str += String.fromCharCode(bytes[i]);
                    }
                    else {
                        str += '%' + (256 + bytes[i]).toString(16).slice(1);
                    }
                }

                return unescape(str);
            }
888298
function magicBuffer(buf, cb) {
  try {
    buf = bufferUtils.toBuffer(buf);
    (0, _magic2.default)(buf, cb);
  } catch (err) {
    cb(err);
  }
}