示例#1
0
文件: main.py 项目: laisun/bandit
def _get_options_from_ini(ini_path, target):
    """Return a dictionary of config options or None if we can't load any."""
    ini_file = None

    if ini_path:
        ini_file = ini_path
    else:
        bandit_files = []

        for t in target:
            for root, dirnames, filenames in os.walk(t):
                for filename in fnmatch.filter(filenames, '.bandit'):
                    bandit_files.append(os.path.join(root, filename))

        if len(bandit_files) > 1:
            logger.error(
                'Multiple .bandit files found - scan separately or '
                'choose one with --ini\n\t%s', ', '.join(bandit_files))
            sys.exit(2)

        elif len(bandit_files) == 1:
            ini_file = bandit_files[0]
            logger.info('Found project level .bandit file: %s',
                        bandit_files[0])

    if ini_file:
        return utils.parse_ini_file(ini_file)
    else:
        return None
示例#2
0
文件: main.py 项目: b5y/bandit
def _get_options_from_ini(ini_path, target):
    """Return a dictionary of config options or None if we can't load any."""
    ini_file = None

    if ini_path:
        ini_file = ini_path
    else:
        bandit_files = []

        for t in target:
            for root, dirnames, filenames in os.walk(t):
                for filename in fnmatch.filter(filenames, '.bandit'):
                    bandit_files.append(os.path.join(root, filename))

        if len(bandit_files) > 1:
            logger.error('Multiple .bandit files found - scan separately or '
                         'choose one with --ini\n\t%s',
                         ', '.join(bandit_files))
            sys.exit(2)

        elif len(bandit_files) == 1:
            ini_file = bandit_files[0]
            logger.info('Found project level .bandit file: %s',
                        bandit_files[0])

    if ini_file:
        return utils.parse_ini_file(ini_file)
    else:
        return None
示例#3
0
    def test_parse_ini_file(self):

        tests = [{'content': "[bandit]\nexclude=/abc,/def",
                  'expected': {'exclude': '/abc,/def'}},

                 {'content': '[Blabla]\nsomething=something',
                  'expected': None}]

        with tempfile.NamedTemporaryFile('r+') as t:
            for test in tests:
                f = open(t.name, 'w')
                f.write(test['content'])
                f.close()

                self.assertEqual(b_utils.parse_ini_file(t.name),
                                 test['expected'])
示例#4
0
文件: test_util.py 项目: zwcdp/bandit
    def test_parse_ini_file(self):

        tests = [{
            'content': "[bandit]\nexclude=/abc,/def",
            'expected': {
                'exclude': '/abc,/def'
            }
        }, {
            'content': '[Blabla]\nsomething=something',
            'expected': None
        }]

        with tempfile.NamedTemporaryFile('r+') as t:
            for test in tests:
                with open(t.name, 'w') as f:
                    f.write(test['content'])

                self.assertEqual(b_utils.parse_ini_file(t.name),
                                 test['expected'])
示例#5
0
文件: test_util.py 项目: PyCQA/bandit
    def test_parse_ini_file(self):

        tests = [
            {
                "content": "[bandit]\nexclude=/abc,/def",
                "expected": {
                    "exclude": "/abc,/def"
                },
            },
            {
                "content": "[Blabla]\nsomething=something",
                "expected": None
            },
        ]

        with tempfile.NamedTemporaryFile("r+") as t:
            for test in tests:
                with open(t.name, "w") as f:
                    f.write(test["content"])

                self.assertEqual(b_utils.parse_ini_file(t.name),
                                 test["expected"])