Smudge magic bytes with a known type
323870
def smudge(newtype, target):
    

    db = smudge_db.get()

    magic_bytes = db[newtype]['magic']
    magic_offset = db[newtype]['offset']

    _backup_bytes(target, magic_offset, len(magic_bytes))
    _smudge_bytes(target, magic_offset, magic_bytes)
599555
def from_raw(self, raw: RawScalar) -> Optional[bytes]:
        """"""
        try:
            return base64.b64decode(raw, validate=True)
        except TypeError:
            return None
44200
def get_content_type(*names):
    """"""
    for name in names:
        if name is not None:
            mimetype, encoding = mimetypes.guess_type(name)
            if mimetype is not None:
                if isinstance(mimetype, bytes):
                    return mimetype.decode("ascii")
                else:
                    return mimetype
    else:
        return "application/octet-stream"
908872
def read_bytes(fo, writer_schema=None, reader_schema=None):
    """"""
    size = read_long(fo)
    return fo.read(size)
877289
def _get_mime_type(self, buff):
        
        if self._magic is not None:
            return self._magic.id_buffer(buff)
        else:
            try:
                return mimetypes.guess_type("f." + imghdr.what(0, buff))[0]
            except (IOError, TypeError):
                logging.warning("Couldn't detect content type of avatar image"
                                ". Specify the 'contentType' parameter explicitly.")
                return None
467176
def extern_store_bytes(self, context_handle, bytes_ptr, bytes_len):
    """"""
    c = self._ffi.from_handle(context_handle)
    return c.to_value(binary_type(self._ffi.buffer(bytes_ptr, bytes_len)))
481866
def _magic(header, footer, mime, ext=None):
    
    if not header:
        raise ValueError("Input was empty")
    info = _identify_all(header, footer, ext)[0]
    if mime:
        return info.mime_type
    return info.extension if not \
        isinstance(info.extension, list) else info[0].extension
869463
def guess_encoding(blob):
    
    # 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_ENCODING)
        m.load()
        return m.buffer(blob)
    elif hasattr(magic, 'from_buffer'):
        m = magic.Magic(mime_encoding=True)
        return m.from_buffer(blob)
    else:
        raise Exception('Unknown magic API')
753314
def cast_bytes(s, encoding=None):
    """"""
    if not isinstance(s, bytes):
        return encode(s, encoding)
    return s
66518
Type sigToType(byte[] sig, int offset, int len) {
        signature = sig;
        sigp = offset;
        siglimit = offset + len;
        return sigToType();
    }
324124
private boolean validMagicNumber(byte[] magicNumberBuffer)
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "validMagicNumber", new java.lang.Object[] { RLSUtils.toHexString(magicNumberBuffer, RLSUtils.MAX_DISPLAY_BYTES), this });

        boolean incorrectByteDetected = false;
        int currentByte = 0;

        while ((!incorrectByteDetected) && (currentByte < LogFileHeader.MAGIC_NUMBER.length))
        {
            if (magicNumberBuffer[currentByte] != LogFileHeader.MAGIC_NUMBER[currentByte])
            {
                incorrectByteDetected = true;
            }
            currentByte++;
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, "validMagicNumber", new Boolean(!incorrectByteDetected));
        return !incorrectByteDetected;
    }
527904
def sanitize_type(raw_type):
    """"""
    cleaned = get_printable(raw_type).strip()
    for bad in [
            r'__drv_aliasesMem', r'__drv_freesMem',
            r'__drv_strictTypeMatch\(\w+\)',
            r'__out_data_source\(\w+\)',
            r'_In_NLS_string_\(\w+\)',
            r'_Frees_ptr_', r'_Frees_ptr_opt_', r'opt_',
            r'\(Mem\) '
    ]:
        cleaned = re.sub(bad, '', cleaned).strip()
    if cleaned in ['_EXCEPTION_RECORD *', '_EXCEPTION_POINTERS *']:
        cleaned = cleaned.strip('_')
    cleaned = cleaned.replace('[]', '*')
    return cleaned
77357
def guess_filetype(filepath):
    """"""
    # If we have python-magic, use it to determine file type
    typ = None

    # Some specific checks for known file suffixes
    _fn = filepath.lower()
    _name, _ext = os.path.splitext(_fn)
    if _ext in known_types:
        typ = known_types[_ext]

    if typ is None and have_magic:
        try:
            # it seems there are conflicting versions of a 'magic'
            # module for python floating around...*sigh*
            if hasattr(magic, 'from_file'):
                typ = magic.from_file(filepath, mime=True)

            elif magic_tester is not None:
                descrip = magic_tester.file(filepath)
                if descrip.startswith("FITS image data"):
                    return ('image', 'fits')

        except Exception as e:
            pass

    if typ is None:
        # if no magic, or magic fails, fall back to mimetypes
        try:
            typ, enc = mimetypes.guess_type(filepath)

        except Exception as e:
            # fail
            pass

    if typ:
        typ, subtyp = typ.split('/')
        return (typ, subtyp)

    raise ValueError("Can't determine file type of '%s'" % (filepath))
1145160
def _is_ctype(self, ctype):
        """"""
        if not self.valid:
            return False
        mime = self.content_type
        return self.ContentMimetypes.get(mime) == ctype
1086071
def byte2int(s, index=0):
    
    if six.PY2:
        return ord(s[index])
    return s[index]
1247231
def _guess_content_type(url):
    '''
    
    '''
    OCTET_STREAM = 'application/octet-stream'
    n = url.rfind('.')
    if n == -1:
        return OCTET_STREAM
    return mimetypes.types_map.get(url[n:].lower(), OCTET_STREAM)
1228541
def StripTypeInfo(rendered_data):
  """"""

  if isinstance(rendered_data, (list, tuple)):
    return [StripTypeInfo(d) for d in rendered_data]
  elif isinstance(rendered_data, dict):
    if "value" in rendered_data and "type" in rendered_data:
      return StripTypeInfo(rendered_data["value"])
    else:
      result = {}
      for k, v in iteritems(rendered_data):
        result[k] = StripTypeInfo(v)
      return result
  else:
    return rendered_data