A function to check whether a file-like object supports binary mode.

    Parameters:
     fp - The file-like object to check for binary mode support.
    Returns:
     True if the file-like object supports binary mode, False otherwise.
436135
def file_object_supports_binary(fp):
    # type: (BinaryIO) -> bool
    '''
    
    '''
    if hasattr(fp, 'mode'):
        return 'b' in fp.mode

    # Python 3
    if sys.version_info >= (3, 0):
        return isinstance(fp, (io.RawIOBase, io.BufferedIOBase))

    # Python 2
    return isinstance(fp, (cStringIO.OutputType, cStringIO.InputType, io.RawIOBase, io.BufferedIOBase))
1104636
def match_file(self, f, update_file=False):
        
        if self.map_func is not None:
            val = self.map_func(f)
        else:
            m = self.regex.search(f.path)
            val = m.group(1) if m is not None else None

        return self._astype(val)
594058
def get_filelikeobject(filename: str = None,
                       blob: bytes = None) -> BinaryIO:
    
    if not filename and not blob:
        raise ValueError("no filename and no blob")
    if filename and blob:
        raise ValueError("specify either filename or blob")
    if filename:
        return open(filename, 'rb')
    else:
        return io.BytesIO(blob)
50886
def supports_color():
    
    unsupported_platform = (sys.platform in ('win32', 'Pocket PC'))
    # isatty is not always implemented, #6223.
    is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
    if unsupported_platform or not is_a_tty:
        return False
    return True
935209
def is_binary(filename):
    
    logger.debug('is_binary: %(filename)r', locals())

    # Check if the file extension is in a list of known binary types
    binary_extensions = ['pyc', 'iso', 'zip', 'pdf']
    for ext in binary_extensions:
        if filename.endswith(ext):
            return True

    # Check if the starting chunk is a binary string
    chunk = get_starting_chunk(filename)
    return is_binary_string(chunk)
374182
def is_binary_file(file):
    

    file_handle = open(file, "rb")
    try:
        chunk_size = 1024
        while True:
            chunk = file_handle.read(chunk_size)
            if chr(0) in chunk:
                return True
            if len(chunk) < chunk_size:
                break
    finally:
        file_handle.close()
    return False
1353535
def contains_shebang(f):
    
    first_line = f.readline()
    if first_line in shebangs.values():
        return True
    return False
75155
def canProcessFilename(cls, filename):
        
        supported_patterns = cls._extpattern_to_mime.keys()
        for pattern in supported_patterns:
            if fnmatch.fnmatch(filename, pattern):
                return True
        return False
1138024
def to_fp(self, sort, rm=None):
        
        if rm is None:
            rm = fp.RM.default()

        return fpToFP(rm, self, sort)
239016
def has_fast_mps_support():
    
    lib = _load_tcmps_lib()
    if lib is None:
        return False

    c_bool = _ctypes.c_bool()
    ret = lib.TCMPSHasHighPowerMetalDevice(_ctypes.byref(c_bool))
    return ret == 0 and c_bool.value
1047913
private static boolean isPosix() {
    Method getDefaultMethod = ZTZipReflectionUtil.getDeclaredMethod(
        ZTZipReflectionUtil.getClassForName("java.nio.file.FileSystems", Object.class), "getDefault");
    Method supportedFileAttributeViewsMethod = ZTZipReflectionUtil.getDeclaredMethod(
        ZTZipReflectionUtil.getClassForName("java.nio.file.FileSystem", Object.class), "supportedFileAttributeViews");
    
    Object fileSystem = ZTZipReflectionUtil.invoke(getDefaultMethod, null);
    @SuppressWarnings("unchecked")
    Set<String> views = (Set<String>) ZTZipReflectionUtil.invoke(supportedFileAttributeViewsMethod, fileSystem);
    
    return views.contains("posix");
  }
848865
function open_fp($option = 'r')
    {

        if (empty($option) || !is_string($option)) return false;

        switch (true) {
            case (strpos($option, 'r') !== false) :
                $mode = LOCK_SH;
                break;
            case (strpos($option, 'a') !== false || strpos($option, 'w') !== false) :
                $mode = LOCK_EX;
                break;
            default :
                $mode = LOCK_EX;
                break;
        }
        $this->readable = true;

        if (($this->fp = fopen($this->file, $option)) !== false) {
            $this->lock($mode);
            // sets the fopen option based on it reduces
            // reopening of a file
            $this->_option = (string)$option;

            return true;
        }

        return false;
    }
294190
def is_binary(self, subpath=None):
        
        mimetype = self.mimetype_for(subpath)
        return mimetype is not None and mimetype.startswith('image/')
1074362
def file_supports_color(file_obj):
    
    plat = sys.platform
    supported_platform = plat != 'Pocket PC' and (plat != 'win32' or
                                                  'ANSICON' in os.environ)

    is_a_tty = hasattr(file_obj, 'isatty') and file_obj.isatty()
    if not supported_platform or not is_a_tty:
        return False
    return True
602612
def open(cls, fp):
        
        if hasattr(fp, 'read'):
            self = cls(PSD.read(fp))
        else:
            with open(fp, 'rb') as f:
                self = cls(PSD.read(f))
        return self
1132146
private static boolean shouldCheckBuffer(PrintNode node) {
    if (!(node.getExpr().getRoot() instanceof FunctionNode)) {
      return true;
    }

    FunctionNode fn = (FunctionNode) node.getExpr().getRoot();
    if (!(fn.getSoyFunction() instanceof BuiltinFunction)) {
      return true;
    }

    BuiltinFunction bfn = (BuiltinFunction) fn.getSoyFunction();
    if (bfn != BuiltinFunction.XID && bfn != BuiltinFunction.CSS) {
      return true;
    }

    return false;
  }
1374424
def _isbool(string):
    
    return isinstance(string, _bool_type) or\
        (isinstance(string, (_binary_type, _text_type))
         and
         string in ("True", "False"))