The following issues were found
Lib/test/test_getpass.py
40 issues
Line: 55
Column: 9
def test_flushes_stream_after_prompt(self):
# see issue 1703
stream = mock.Mock(spec=StringIO)
input = StringIO('input_string')
getpass._raw_input('some_prompt', stream, input=input)
stream.flush.assert_called_once_with()
def test_uses_stderr_as_default(self):
input = StringIO('input_string')
Reported by Pylint.
Line: 56
Column: 9
# see issue 1703
stream = mock.Mock(spec=StringIO)
input = StringIO('input_string')
getpass._raw_input('some_prompt', stream, input=input)
stream.flush.assert_called_once_with()
def test_uses_stderr_as_default(self):
input = StringIO('input_string')
prompt = 'some_prompt'
Reported by Pylint.
Line: 60
Column: 9
stream.flush.assert_called_once_with()
def test_uses_stderr_as_default(self):
input = StringIO('input_string')
prompt = 'some_prompt'
with mock.patch('sys.stderr') as stderr:
getpass._raw_input(prompt, input=input)
stderr.write.assert_called_once_with(prompt)
Reported by Pylint.
Line: 63
Column: 13
input = StringIO('input_string')
prompt = 'some_prompt'
with mock.patch('sys.stderr') as stderr:
getpass._raw_input(prompt, input=input)
stderr.write.assert_called_once_with(prompt)
@mock.patch('sys.stdin')
def test_uses_stdin_as_default_input(self, mock_input):
mock_input.readline.return_value = 'input_string'
Reported by Pylint.
Line: 69
Column: 9
@mock.patch('sys.stdin')
def test_uses_stdin_as_default_input(self, mock_input):
mock_input.readline.return_value = 'input_string'
getpass._raw_input(stream=StringIO())
mock_input.readline.assert_called_once_with()
@mock.patch('sys.stdin')
def test_uses_stdin_as_different_locale(self, mock_input):
stream = TextIOWrapper(BytesIO(), encoding="ascii")
Reported by Pylint.
Line: 76
Column: 9
def test_uses_stdin_as_different_locale(self, mock_input):
stream = TextIOWrapper(BytesIO(), encoding="ascii")
mock_input.readline.return_value = "Hasło: "
getpass._raw_input(prompt="Hasło: ",stream=stream)
mock_input.readline.assert_called_once_with()
def test_raises_on_empty_input(self):
input = StringIO('')
Reported by Pylint.
Line: 81
Column: 9
def test_raises_on_empty_input(self):
input = StringIO('')
self.assertRaises(EOFError, getpass._raw_input, input=input)
def test_trims_trailing_newline(self):
input = StringIO('test\n')
self.assertEqual('test', getpass._raw_input(input=input))
Reported by Pylint.
Line: 82
Column: 37
def test_raises_on_empty_input(self):
input = StringIO('')
self.assertRaises(EOFError, getpass._raw_input, input=input)
def test_trims_trailing_newline(self):
input = StringIO('test\n')
self.assertEqual('test', getpass._raw_input(input=input))
Reported by Pylint.
Line: 85
Column: 9
self.assertRaises(EOFError, getpass._raw_input, input=input)
def test_trims_trailing_newline(self):
input = StringIO('test\n')
self.assertEqual('test', getpass._raw_input(input=input))
# Some of these tests are a bit white-box. The functional requirement is that
# the password input be taken directly from the tty, and that it not be echoed
Reported by Pylint.
Line: 86
Column: 34
def test_trims_trailing_newline(self):
input = StringIO('test\n')
self.assertEqual('test', getpass._raw_input(input=input))
# Some of these tests are a bit white-box. The functional requirement is that
# the password input be taken directly from the tty, and that it not be echoed
# on the screen, unless we are falling back to stderr/stdin.
Reported by Pylint.
Lib/test/test_dict_version.py
40 issues
Line: 47
Column: 9
def test_constructor(self):
# new empty dictionaries must all have an unique version
empty1 = self.new_dict()
empty2 = self.new_dict()
empty3 = self.new_dict()
# non-empty dictionaries must also have an unique version
nonempty1 = self.new_dict(x='x')
Reported by Pylint.
Line: 48
Column: 9
def test_constructor(self):
# new empty dictionaries must all have an unique version
empty1 = self.new_dict()
empty2 = self.new_dict()
empty3 = self.new_dict()
# non-empty dictionaries must also have an unique version
nonempty1 = self.new_dict(x='x')
nonempty2 = self.new_dict(x='x', y='y')
Reported by Pylint.
Line: 49
Column: 9
# new empty dictionaries must all have an unique version
empty1 = self.new_dict()
empty2 = self.new_dict()
empty3 = self.new_dict()
# non-empty dictionaries must also have an unique version
nonempty1 = self.new_dict(x='x')
nonempty2 = self.new_dict(x='x', y='y')
Reported by Pylint.
Line: 52
Column: 9
empty3 = self.new_dict()
# non-empty dictionaries must also have an unique version
nonempty1 = self.new_dict(x='x')
nonempty2 = self.new_dict(x='x', y='y')
def test_copy(self):
d = self.new_dict(a=1, b=2)
Reported by Pylint.
Line: 53
Column: 9
# non-empty dictionaries must also have an unique version
nonempty1 = self.new_dict(x='x')
nonempty2 = self.new_dict(x='x', y='y')
def test_copy(self):
d = self.new_dict(a=1, b=2)
d2 = self.check_version_dont_change(d, d.copy)
Reported by Pylint.
Line: 12
Column: 1
_testcapi = import_helper.import_module('_testcapi')
class DictVersionTests(unittest.TestCase):
type2test = dict
def setUp(self):
self.seen_versions = set()
self.dict = None
Reported by Pylint.
Line: 19
Column: 5
self.seen_versions = set()
self.dict = None
def check_version_unique(self, mydict):
version = _testcapi.dict_get_version(mydict)
self.assertNotIn(version, self.seen_versions)
self.seen_versions.add(version)
def check_version_changed(self, mydict, method, *args, **kw):
Reported by Pylint.
Line: 24
Column: 5
self.assertNotIn(version, self.seen_versions)
self.seen_versions.add(version)
def check_version_changed(self, mydict, method, *args, **kw):
result = method(*args, **kw)
self.check_version_unique(mydict)
return result
def check_version_dont_change(self, mydict, method, *args, **kw):
Reported by Pylint.
Line: 29
Column: 5
self.check_version_unique(mydict)
return result
def check_version_dont_change(self, mydict, method, *args, **kw):
version1 = _testcapi.dict_get_version(mydict)
self.seen_versions.add(version1)
result = method(*args, **kw)
Reported by Pylint.
Line: 40
Column: 5
return result
def new_dict(self, *args, **kw):
d = self.type2test(*args, **kw)
self.check_version_unique(d)
return d
def test_constructor(self):
Reported by Pylint.
Lib/selectors.py
40 issues
Line: 350
Column: 26
def __init__(self):
super().__init__()
self._selector = self._selector_cls()
def register(self, fileobj, events, data=None):
key = super().register(fileobj, events, data)
poller_events = 0
if events & EVENT_READ:
Reported by Pylint.
Line: 421
Column: 24
return ready
for fd, event in fd_event_list:
events = 0
if event & ~self._EVENT_READ:
events |= EVENT_WRITE
if event & ~self._EVENT_WRITE:
events |= EVENT_READ
key = self._key_from_fd(fd)
Reported by Pylint.
Line: 423
Column: 24
events = 0
if event & ~self._EVENT_READ:
events |= EVENT_WRITE
if event & ~self._EVENT_WRITE:
events |= EVENT_READ
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
Reported by Pylint.
Line: 493
Column: 25
class DevpollSelector(_PollLikeSelector):
"""Solaris /dev/poll selector."""
_selector_cls = select.devpoll
_EVENT_READ = select.POLLIN
_EVENT_WRITE = select.POLLOUT
def fileno(self):
return self._selector.fileno()
Reported by Pylint.
Line: 512
Column: 30
def __init__(self):
super().__init__()
self._selector = select.kqueue()
def fileno(self):
return self._selector.fileno()
def register(self, fileobj, events, data=None):
Reported by Pylint.
Line: 521
Column: 49
key = super().register(fileobj, events, data)
try:
if events & EVENT_READ:
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
select.KQ_EV_ADD)
self._selector.control([kev], 0, 0)
if events & EVENT_WRITE:
kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
select.KQ_EV_ADD)
Reported by Pylint.
Line: 521
Column: 27
key = super().register(fileobj, events, data)
try:
if events & EVENT_READ:
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
select.KQ_EV_ADD)
self._selector.control([kev], 0, 0)
if events & EVENT_WRITE:
kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
select.KQ_EV_ADD)
Reported by Pylint.
Line: 522
Column: 41
try:
if events & EVENT_READ:
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
select.KQ_EV_ADD)
self._selector.control([kev], 0, 0)
if events & EVENT_WRITE:
kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
select.KQ_EV_ADD)
self._selector.control([kev], 0, 0)
Reported by Pylint.
Line: 525
Column: 27
select.KQ_EV_ADD)
self._selector.control([kev], 0, 0)
if events & EVENT_WRITE:
kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
select.KQ_EV_ADD)
self._selector.control([kev], 0, 0)
except:
super().unregister(fileobj)
raise
Reported by Pylint.
Line: 525
Column: 49
select.KQ_EV_ADD)
self._selector.control([kev], 0, 0)
if events & EVENT_WRITE:
kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
select.KQ_EV_ADD)
self._selector.control([kev], 0, 0)
except:
super().unregister(fileobj)
raise
Reported by Pylint.
Lib/test/test_devpoll.py
40 issues
Line: 28
Column: 13
# Basic functional test of poll object
# Create a bunch of pipe and test that poll works with them.
p = select.devpoll()
NUM_PIPES = 12
MSG = b" This is a test."
MSG_LEN = len(MSG)
readers = []
Reported by Pylint.
Line: 75
Column: 20
self.assertEqual(bufs, [MSG] * NUM_PIPES)
def test_timeout_overflow(self):
pollster = select.devpoll()
w, r = os.pipe()
pollster.register(w)
pollster.poll(-1)
self.assertRaises(OverflowError, pollster.poll, -2)
Reported by Pylint.
Line: 95
Column: 19
open_file = open(__file__, "rb")
self.addCleanup(open_file.close)
fd = open_file.fileno()
devpoll = select.devpoll()
# test fileno() method and closed attribute
self.assertIsInstance(devpoll.fileno(), int)
self.assertFalse(devpoll.closed)
Reported by Pylint.
Line: 116
Column: 19
self.assertRaises(ValueError, devpoll.unregister, fd)
def test_fd_non_inheritable(self):
devpoll = select.devpoll()
self.addCleanup(devpoll.close)
self.assertEqual(os.get_inheritable(devpoll.fileno()), False)
def test_events_mask_overflow(self):
pollster = select.devpoll()
Reported by Pylint.
Line: 121
Column: 20
self.assertEqual(os.get_inheritable(devpoll.fileno()), False)
def test_events_mask_overflow(self):
pollster = select.devpoll()
w, r = os.pipe()
pollster.register(w)
# Issue #17919
self.assertRaises(ValueError, pollster.register, 0, -1)
self.assertRaises(OverflowError, pollster.register, 0, 1 << 64)
Reported by Pylint.
Line: 133
Column: 20
@cpython_only
def test_events_mask_overflow_c_limits(self):
from _testcapi import USHRT_MAX
pollster = select.devpoll()
w, r = os.pipe()
pollster.register(w)
# Issue #17919
self.assertRaises(OverflowError, pollster.register, 0, USHRT_MAX + 1)
self.assertRaises(OverflowError, pollster.modify, 1, USHRT_MAX + 1)
Reported by Pylint.
Line: 38
Column: 13
r2w = {}
w2r = {}
for i in range(NUM_PIPES):
rd, wr = os.pipe()
p.register(rd)
p.modify(rd, select.POLLIN)
p.register(wr, select.POLLOUT)
readers.append(rd)
Reported by Pylint.
Line: 76
Column: 12
def test_timeout_overflow(self):
pollster = select.devpoll()
w, r = os.pipe()
pollster.register(w)
pollster.poll(-1)
self.assertRaises(OverflowError, pollster.poll, -2)
self.assertRaises(OverflowError, pollster.poll, -1 << 31)
Reported by Pylint.
Line: 122
Column: 12
def test_events_mask_overflow(self):
pollster = select.devpoll()
w, r = os.pipe()
pollster.register(w)
# Issue #17919
self.assertRaises(ValueError, pollster.register, 0, -1)
self.assertRaises(OverflowError, pollster.register, 0, 1 << 64)
self.assertRaises(ValueError, pollster.modify, 1, -1)
Reported by Pylint.
Line: 134
Column: 12
def test_events_mask_overflow_c_limits(self):
from _testcapi import USHRT_MAX
pollster = select.devpoll()
w, r = os.pipe()
pollster.register(w)
# Issue #17919
self.assertRaises(OverflowError, pollster.register, 0, USHRT_MAX + 1)
self.assertRaises(OverflowError, pollster.modify, 1, USHRT_MAX + 1)
Reported by Pylint.
Lib/test/test_json/test_scanstring.py
40 issues
Line: 7
Column: 22
class TestScanstring:
def test_scanstring(self):
scanstring = self.json.decoder.scanstring
self.assertEqual(
scanstring('"z\U0001d120x"', 1, True),
('z\U0001d120x', 5))
self.assertEqual(
Reported by Pylint.
Line: 8
Column: 9
class TestScanstring:
def test_scanstring(self):
scanstring = self.json.decoder.scanstring
self.assertEqual(
scanstring('"z\U0001d120x"', 1, True),
('z\U0001d120x', 5))
self.assertEqual(
scanstring('"\\u007b"', 1, True),
Reported by Pylint.
Line: 12
Column: 9
scanstring('"z\U0001d120x"', 1, True),
('z\U0001d120x', 5))
self.assertEqual(
scanstring('"\\u007b"', 1, True),
('{', 8))
self.assertEqual(
scanstring('"A JSON payload should be an object or array, not a string."', 1, True),
Reported by Pylint.
Line: 16
Column: 9
scanstring('"\\u007b"', 1, True),
('{', 8))
self.assertEqual(
scanstring('"A JSON payload should be an object or array, not a string."', 1, True),
('A JSON payload should be an object or array, not a string.', 60))
self.assertEqual(
scanstring('["Unclosed array"', 2, True),
Reported by Pylint.
Line: 20
Column: 9
scanstring('"A JSON payload should be an object or array, not a string."', 1, True),
('A JSON payload should be an object or array, not a string.', 60))
self.assertEqual(
scanstring('["Unclosed array"', 2, True),
('Unclosed array', 17))
self.assertEqual(
scanstring('["extra comma",]', 2, True),
Reported by Pylint.
Line: 24
Column: 9
scanstring('["Unclosed array"', 2, True),
('Unclosed array', 17))
self.assertEqual(
scanstring('["extra comma",]', 2, True),
('extra comma', 14))
self.assertEqual(
scanstring('["double extra comma",,]', 2, True),
Reported by Pylint.
Line: 28
Column: 9
scanstring('["extra comma",]', 2, True),
('extra comma', 14))
self.assertEqual(
scanstring('["double extra comma",,]', 2, True),
('double extra comma', 21))
self.assertEqual(
scanstring('["Comma after the close"],', 2, True),
Reported by Pylint.
Line: 32
Column: 9
scanstring('["double extra comma",,]', 2, True),
('double extra comma', 21))
self.assertEqual(
scanstring('["Comma after the close"],', 2, True),
('Comma after the close', 24))
self.assertEqual(
scanstring('["Extra close"]]', 2, True),
Reported by Pylint.
Line: 36
Column: 9
scanstring('["Comma after the close"],', 2, True),
('Comma after the close', 24))
self.assertEqual(
scanstring('["Extra close"]]', 2, True),
('Extra close', 14))
self.assertEqual(
scanstring('{"Extra comma": true,}', 2, True),
Reported by Pylint.
Line: 40
Column: 9
scanstring('["Extra close"]]', 2, True),
('Extra close', 14))
self.assertEqual(
scanstring('{"Extra comma": true,}', 2, True),
('Extra comma', 14))
self.assertEqual(
scanstring('{"Extra value after close": true} "misplaced quoted value"', 2, True),
Reported by Pylint.
Lib/cmd.py
40 issues
Line: 287
Column: 24
return dir(self.__class__)
def complete_help(self, *args):
commands = set(self.completenames(*args))
topics = set(a[5:] for a in self.get_names()
if a.startswith('help_' + args[0]))
return list(commands | topics)
def do_help(self, arg):
Reported by Pylint.
Line: 109
Column: 17
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try:
Reported by Pylint.
Line: 157
Column: 29
"""
return line
def postcmd(self, stop, line):
"""Hook method executed just after a command dispatch is finished."""
return stop
def preloop(self):
"""Hook method executed once when the cmdloop() method is called."""
Reported by Pylint.
Line: 163
Column: 9
def preloop(self):
"""Hook method executed once when the cmdloop() method is called."""
pass
def postloop(self):
"""Hook method executed once when the cmdloop() method is about to
return.
Reported by Pylint.
Line: 170
Column: 9
return.
"""
pass
def parseline(self, line):
"""Parse the line into a command name and a string containing
the arguments. Returns a tuple containing (command, args, line).
'command' and 'args' may be None if the line couldn't be parsed.
Reported by Pylint.
Line: 238
Column: 1
"""
self.stdout.write('*** Unknown syntax: %s\n'%line)
def completedefault(self, *ignored):
"""Method called to complete an input line when no command-specific
complete_*() method is available.
By default, it returns an empty list.
Reported by Pylint.
Line: 247
Column: 1
"""
return []
def completenames(self, text, *ignored):
dotext = 'do_'+text
return [a[3:] for a in self.get_names() if a.startswith(dotext)]
def complete(self, text, state):
"""Return the next possible completion for 'text'.
Reported by Pylint.
Line: 265
Column: 28
begidx = readline.get_begidx() - stripped
endidx = readline.get_endidx() - stripped
if begidx>0:
cmd, args, foo = self.parseline(line)
if cmd == '':
compfunc = self.completedefault
else:
try:
compfunc = getattr(self, 'complete_' + cmd)
Reported by Pylint.
Line: 265
Column: 22
begidx = readline.get_begidx() - stripped
endidx = readline.get_endidx() - stripped
if begidx>0:
cmd, args, foo = self.parseline(line)
if cmd == '':
compfunc = self.completedefault
else:
try:
compfunc = getattr(self, 'complete_' + cmd)
Reported by Pylint.
Line: 275
Column: 13
compfunc = self.completedefault
else:
compfunc = self.completenames
self.completion_matches = compfunc(text, line, begidx, endidx)
try:
return self.completion_matches[state]
except IndexError:
return None
Reported by Pylint.
Lib/distutils/tests/test_sdist.py
40 issues
Line: 13
Column: 5
from test.support.warnings_helper import check_warnings
try:
import zlib
ZLIB_SUPPORT = True
except ImportError:
ZLIB_SUPPORT = False
try:
Reported by Pylint.
Line: 111
Column: 9
self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx')
# now building a sdist
dist, cmd = self.get_cmd()
# zip is available universally
# (tar might not be installed under win32)
cmd.formats = ['zip']
Reported by Pylint.
Line: 143
Column: 9
"The gzip command is not found")
def test_make_distribution(self):
# now building a sdist
dist, cmd = self.get_cmd()
# creating a gztar then a tar
cmd.formats = ['gztar', 'tar']
cmd.ensure_finalized()
cmd.run()
Reported by Pylint.
Line: 251
Column: 9
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_metadata_check_option(self):
# testing the `medata-check` option
dist, cmd = self.get_cmd(metadata={})
# this should raise some warnings !
# with the `check` subcommand
cmd.ensure_finalized()
cmd.run()
Reported by Pylint.
Line: 257
Column: 9
# with the `check` subcommand
cmd.ensure_finalized()
cmd.run()
warnings = [msg for msg in self.get_logs(WARN) if
msg.startswith('warning: check:')]
self.assertEqual(len(warnings), 2)
# trying with a complete set of metadata
self.clear_logs()
Reported by Pylint.
Line: 273
Column: 9
def test_check_metadata_deprecated(self):
# makes sure make_metadata is deprecated
dist, cmd = self.get_cmd()
with check_warnings() as w:
warnings.simplefilter("always")
cmd.check_metadata()
self.assertEqual(len(w.warnings), 1)
Reported by Pylint.
Line: 276
Column: 13
dist, cmd = self.get_cmd()
with check_warnings() as w:
warnings.simplefilter("always")
cmd.check_metadata()
self.assertEqual(len(w.warnings), 1)
def test_show_formats(self):
with captured_stdout() as stdout:
show_formats()
Reported by Pylint.
Line: 290
Column: 9
self.assertEqual(len(output), num_formats)
def test_finalize_options(self):
dist, cmd = self.get_cmd()
cmd.finalize_options()
# default options set by finalize
self.assertEqual(cmd.manifest, 'MANIFEST')
self.assertEqual(cmd.template, 'MANIFEST.in')
Reported by Pylint.
Line: 313
Column: 9
# of a traceback when parsing an invalid manifest template
def _check_template(self, content):
dist, cmd = self.get_cmd()
os.chdir(self.tmp_dir)
self.write_file('MANIFEST.in', content)
cmd.ensure_finalized()
cmd.filelist = FileList()
cmd.read_template()
Reported by Pylint.
Line: 319
Column: 9
cmd.ensure_finalized()
cmd.filelist = FileList()
cmd.read_template()
warnings = self.get_logs(WARN)
self.assertEqual(len(warnings), 1)
def test_invalid_template_unknown_command(self):
self._check_template('taunt knights *')
Reported by Pylint.
Lib/test/test_pulldom.py
40 issues
Line: 35
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml-bad-pulldom
# fragment.
# Test with a filename:
handler = pulldom.parse(tstfile)
self.addCleanup(handler.stream.close)
list(handler)
# Test with a file object:
with open(tstfile, "rb") as fin:
Reported by Bandit.
Line: 41
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml-bad-pulldom
# Test with a file object:
with open(tstfile, "rb") as fin:
list(pulldom.parse(fin))
def test_parse_semantics(self):
"""Test DOMEventStream parsing semantics."""
items = pulldom.parseString(SMALL_SAMPLE)
Reported by Bandit.
Line: 46
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml-bad-pulldom
def test_parse_semantics(self):
"""Test DOMEventStream parsing semantics."""
items = pulldom.parseString(SMALL_SAMPLE)
evt, node = next(items)
# Just check the node is a Document:
self.assertTrue(hasattr(node, "createElement"))
self.assertEqual(pulldom.START_DOCUMENT, evt)
evt, node = next(items)
Reported by Bandit.
Line: 60
Column: 3
evt, node = next(items)
self.assertEqual(pulldom.CHARACTERS, evt) # Line break
evt, node = next(items)
# XXX - A comment should be reported here!
# self.assertEqual(pulldom.COMMENT, evt)
# Line break after swallowed comment:
self.assertEqual(pulldom.CHARACTERS, evt)
evt, node = next(items)
self.assertEqual("title", node.tagName)
Reported by Pylint.
Line: 101
Column: 3
self.assertEqual(pulldom.CHARACTERS, evt)
evt, node = next(items)
self.assertEqual(pulldom.END_ELEMENT, evt)
# XXX No END_DOCUMENT item is ever obtained:
#evt, node = next(items)
#self.assertEqual(pulldom.END_DOCUMENT, evt)
def test_expandItem(self):
"""Ensure expandItem works as expected."""
Reported by Pylint.
Line: 107
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml-bad-pulldom
def test_expandItem(self):
"""Ensure expandItem works as expected."""
items = pulldom.parseString(SMALL_SAMPLE)
# Loop through the nodes until we get to a "title" start tag:
for evt, item in items:
if evt == pulldom.START_ELEMENT and item.tagName == "title":
items.expandNode(item)
self.assertEqual(1, len(item.childNodes))
Reported by Bandit.
Line: 120
Column: 32
for evt, node in items:
if evt == pulldom.START_ELEMENT:
break
self.assertEqual("hr", node.tagName,
"expandNode did not leave DOMEventStream in the correct state.")
# Attempt to expand a standalone element:
items.expandNode(node)
self.assertEqual(next(items)[0], pulldom.CHARACTERS)
evt, node = next(items)
Reported by Pylint.
Line: 123
Column: 26
self.assertEqual("hr", node.tagName,
"expandNode did not leave DOMEventStream in the correct state.")
# Attempt to expand a standalone element:
items.expandNode(node)
self.assertEqual(next(items)[0], pulldom.CHARACTERS)
evt, node = next(items)
self.assertEqual(node.tagName, "p")
items.expandNode(node)
next(items) # Skip character data
Reported by Pylint.
Line: 140
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml-bad-pulldom
@unittest.expectedFailure
def test_comment(self):
"""PullDOM does not receive "comment" events."""
items = pulldom.parseString(SMALL_SAMPLE)
for evt, _ in items:
if evt == pulldom.COMMENT:
break
else:
self.fail("No comment was encountered")
Reported by Bandit.
Line: 150
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml-bad-pulldom
@unittest.expectedFailure
def test_end_document(self):
"""PullDOM does not receive "end-document" events."""
items = pulldom.parseString(SMALL_SAMPLE)
# Read all of the nodes up to and including </html>:
for evt, node in items:
if evt == pulldom.END_ELEMENT and node.tagName == "html":
break
try:
Reported by Bandit.
Lib/venv/__init__.py
40 issues
Line: 117
Column: 22
prompt = self.prompt if self.prompt is not None else context.env_name
context.prompt = '(%s) ' % prompt
create_if_needed(env_dir)
executable = sys._base_executable
dirname, exename = os.path.split(os.path.abspath(executable))
context.executable = executable
context.python_dir = dirname
context.python_exe = exename
if sys.platform == 'win32':
Reported by Pylint.
Line: 182
Column: 24
os.symlink(os.path.basename(src), dst)
else:
os.symlink(src, dst)
except Exception: # may need to use a more specific exception
logger.warning('Unable to symlink %r to %r', src, dst)
force_copy = True
if force_copy:
shutil.copyfile(src, dst)
else:
Reported by Pylint.
Line: 201
Column: 24
else:
os.symlink(src, dst)
return
except Exception: # may need to use a more specific exception
logger.warning('Unable to symlink %r to %r', src, dst)
# On Windows, we rewrite symlinks to our base python.exe into
# copies of venvlauncher.exe
basename, ext = os.path.splitext(os.path.basename(src))
Reported by Pylint.
Line: 245
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b103_set_bad_file_permissions.html
if os.name != 'nt':
copier(context.executable, path)
if not os.path.islink(path):
os.chmod(path, 0o755)
for suffix in ('python', 'python3', f'python3.{sys.version_info[1]}'):
path = os.path.join(binpath, suffix)
if not os.path.exists(path):
# Issue 18807: make copies if
# symlinks are not wanted
Reported by Bandit.
Line: 253
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b103_set_bad_file_permissions.html
# symlinks are not wanted
copier(context.env_exe, path, relative_symlinks_ok=True)
if not os.path.islink(path):
os.chmod(path, 0o755)
else:
if self.symlinks:
# For symlinking, we need a complete copy of the root directory
# If symlinks fail, you'll get unnecessary copies of files, but
# we assume that if you've opted into symlinks on Windows then
Reported by Bandit.
Line: 281
Column: 27
if sysconfig.is_python_build(True):
# copy init.tcl
for root, dirs, files in os.walk(context.python_dir):
if 'init.tcl' in files:
tcldir = os.path.basename(root)
tcldir = os.path.join(context.env_dir, 'Lib', tcldir)
if not os.path.exists(tcldir):
os.makedirs(tcldir)
Reported by Pylint.
Line: 324
Column: 9
:param context: The information for the environment creation request
being processed.
"""
pass
def replace_variables(self, text, context):
"""
Replace variable placeholders in script text with context-specific
variables.
Reported by Pylint.
Line: 395
Column: 9
shutil.copymode(srcfile, dstfile)
def upgrade_dependencies(self, context):
logger.debug(
f'Upgrading {CORE_VENV_DEPS} packages in {context.bin_path}'
)
if sys.platform == 'win32':
python_exe = os.path.join(context.bin_path, 'python.exe')
else:
Reported by Pylint.
Line: 498
Column: 12
try:
main()
rc = 0
except Exception as e:
print('Error: %s' % e, file=sys.stderr)
sys.exit(rc)
Reported by Pylint.
Line: 10
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
import logging
import os
import shutil
import subprocess
import sys
import sysconfig
import types
Reported by Bandit.
Lib/test/test_symtable.py
40 issues
Line: 191
Column: 9
# Test that annotations for nonlocals are valid after the
# variable is declared as nonlocal.
st6 = symtable.symtable('def g():\n'
' x = 2\n'
' def f():\n'
' nonlocal x\n'
' x: int',
'test', 'exec')
Reported by Pylint.
Line: 234
Column: 9
symtable.symtable("pass", list(b"spam"), "exec")
def test_eval(self):
symbols = symtable.symtable("42", "?", "eval")
def test_single(self):
symbols = symtable.symtable("42", "?", "single")
def test_exec(self):
Reported by Pylint.
Line: 237
Column: 9
symbols = symtable.symtable("42", "?", "eval")
def test_single(self):
symbols = symtable.symtable("42", "?", "single")
def test_exec(self):
symbols = symtable.symtable("def f(x): return x", "?", "exec")
def test_bytes(self):
Reported by Pylint.
Line: 240
Column: 9
symbols = symtable.symtable("42", "?", "single")
def test_exec(self):
symbols = symtable.symtable("def f(x): return x", "?", "exec")
def test_bytes(self):
top = symtable.symtable(TEST_CODE.encode('utf8'), "?", "exec")
self.assertIsNotNone(find_block(top, "Mine"))
Reported by Pylint.
Line: 46
Column: 1
"""
def find_block(block, name):
for ch in block.get_children():
if ch.get_name() == name:
return ch
Reported by Pylint.
Line: 46
Column: 1
"""
def find_block(block, name):
for ch in block.get_children():
if ch.get_name() == name:
return ch
Reported by Pylint.
Line: 47
Column: 9
def find_block(block, name):
for ch in block.get_children():
if ch.get_name() == name:
return ch
class SymtableTest(unittest.TestCase):
Reported by Pylint.
Line: 52
Column: 1
return ch
class SymtableTest(unittest.TestCase):
top = symtable.symtable(TEST_CODE, "?", "exec")
# These correspond to scopes in TEST_CODE
Mine = find_block(top, "Mine")
a_method = find_block(Mine, "a_method")
Reported by Pylint.
Line: 52
Column: 1
return ch
class SymtableTest(unittest.TestCase):
top = symtable.symtable(TEST_CODE, "?", "exec")
# These correspond to scopes in TEST_CODE
Mine = find_block(top, "Mine")
a_method = find_block(Mine, "a_method")
Reported by Pylint.
Line: 61
Column: 5
spam = find_block(top, "spam")
internal = find_block(spam, "internal")
other_internal = find_block(spam, "other_internal")
foo = find_block(top, "foo")
def test_type(self):
self.assertEqual(self.top.get_type(), "module")
self.assertEqual(self.Mine.get_type(), "class")
self.assertEqual(self.a_method.get_type(), "function")
Reported by Pylint.