'Check that an open() call always has an encoding set.'

def _check_open_encoding(self, node):

    try:
        mode_arg = utils.get_argument_from_call(node, position=1, keyword='mode')
    except utils.NoSuchArgumentError:
        mode_arg = None
    _encoding = None
    try:
        _encoding = utils.get_argument_from_call(node, position=2)
    except utils.NoSuchArgumentError:
        try:
            _encoding = utils.get_argument_from_call(node, keyword='encoding')
        except utils.NoSuchArgumentError:
            pass
    if (_encoding is None):
        if (mode_arg is None):
            mode = None
        else:
            mode = utils.safe_infer(mode_arg)
        if ((mode is not None) and (not isinstance(mode, astroid.Const))):
            return
        if (mode is None):
            self.add_message('open-without-encoding', node=node)
        elif ('b' in getattr(mode, 'value', '')):
            return
        else:
            self.add_message('open-without-encoding', node=node)
