The following issues were found
Modules/cjkcodecs/_codecs_kr.c
12 issues
Line: 17
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
#define EUCKR_JAMO_FIRSTBYTE 0xA4
#define EUCKR_JAMO_FILLER 0xD4
static const unsigned char u2cgk_choseong[19] = {
0xa1, 0xa2, 0xa4, 0xa7, 0xa8, 0xa9, 0xb1, 0xb2,
0xb3, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,
0xbc, 0xbd, 0xbe
};
static const unsigned char u2cgk_jungseong[21] = {
Reported by FlawFinder.
Line: 22
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
0xb3, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,
0xbc, 0xbd, 0xbe
};
static const unsigned char u2cgk_jungseong[21] = {
0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6,
0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
0xcf, 0xd0, 0xd1, 0xd2, 0xd3
};
static const unsigned char u2cgk_jongseong[28] = {
Reported by FlawFinder.
Line: 27
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
0xcf, 0xd0, 0xd1, 0xd2, 0xd3
};
static const unsigned char u2cgk_jongseong[28] = {
0xd4, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0,
0xb1, 0xb2, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xba,
0xbb, 0xbc, 0xbd, 0xbe
};
Reported by FlawFinder.
Line: 235
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
* JOHAB codec
*/
static const unsigned char u2johabidx_choseong[32] = {
0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14,
};
static const unsigned char u2johabidx_jungseong[32] = {
Reported by FlawFinder.
Line: 240
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14,
};
static const unsigned char u2johabidx_jungseong[32] = {
0x03, 0x04, 0x05, 0x06, 0x07,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x1a, 0x1b, 0x1c, 0x1d,
};
Reported by FlawFinder.
Line: 246
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x1a, 0x1b, 0x1c, 0x1d,
};
static const unsigned char u2johabidx_jongseong[32] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
};
Reported by FlawFinder.
Line: 323
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
#define FILL 0xfd
#define NONE 0xff
static const unsigned char johabidx_choseong[32] = {
NONE, FILL, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
0x0e, 0x0f, 0x10, 0x11, 0x12, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
};
Reported by FlawFinder.
Line: 329
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
0x0e, 0x0f, 0x10, 0x11, 0x12, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
};
static const unsigned char johabidx_jungseong[32] = {
NONE, NONE, FILL, 0x00, 0x01, 0x02, 0x03, 0x04,
NONE, NONE, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
NONE, NONE, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
NONE, NONE, 0x11, 0x12, 0x13, 0x14, NONE, NONE,
};
Reported by FlawFinder.
Line: 335
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
NONE, NONE, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
NONE, NONE, 0x11, 0x12, 0x13, 0x14, NONE, NONE,
};
static const unsigned char johabidx_jongseong[32] = {
NONE, FILL, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
0x0f, 0x10, NONE, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, NONE, NONE,
};
Reported by FlawFinder.
Line: 342
Column: 23
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, NONE, NONE,
};
static const unsigned char johabjamo_choseong[32] = {
NONE, FILL, 0x31, 0x32, 0x34, 0x37, 0x38, 0x39,
0x41, 0x42, 0x43, 0x45, 0x46, 0x47, 0x48, 0x49,
0x4a, 0x4b, 0x4c, 0x4d, 0x4e, NONE, NONE, NONE,
NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
};
Reported by FlawFinder.
Tools/peg_generator/pegen/grammar_visualizer.py
12 issues
Line: 55
Column: 26
args = argparser.parse_args()
try:
grammar, parser, tokenizer = build_parser(args.filename)
except Exception as err:
print("ERROR: Failed to parse grammar file", file=sys.stderr)
sys.exit(1)
visitor = ASTGrammarPrinter()
Reported by Pylint.
Line: 55
Column: 18
args = argparser.parse_args()
try:
grammar, parser, tokenizer = build_parser(args.filename)
except Exception as err:
print("ERROR: Failed to parse grammar file", file=sys.stderr)
sys.exit(1)
visitor = ASTGrammarPrinter()
Reported by Pylint.
Line: 56
Column: 5
try:
grammar, parser, tokenizer = build_parser(args.filename)
except Exception as err:
print("ERROR: Failed to parse grammar file", file=sys.stderr)
sys.exit(1)
visitor = ASTGrammarPrinter()
visitor.print_grammar_ast(grammar)
Reported by Pylint.
Line: 56
Column: 12
try:
grammar, parser, tokenizer = build_parser(args.filename)
except Exception as err:
print("ERROR: Failed to parse grammar file", file=sys.stderr)
sys.exit(1)
visitor = ASTGrammarPrinter()
visitor.print_grammar_ast(grammar)
Reported by Pylint.
Line: 1
Column: 1
import argparse
import sys
from typing import Any, Iterator, Callable
from pegen.build import build_parser
from pegen.grammar import Grammar, Rule
argparser = argparse.ArgumentParser(
Reported by Pylint.
Line: 15
Column: 1
argparser.add_argument("filename", help="Grammar description")
class ASTGrammarPrinter:
def children(self, node: Rule) -> Iterator[Any]:
for value in node:
if isinstance(value, list):
yield from value
else:
Reported by Pylint.
Line: 16
Column: 5
class ASTGrammarPrinter:
def children(self, node: Rule) -> Iterator[Any]:
for value in node:
if isinstance(value, list):
yield from value
else:
yield value
Reported by Pylint.
Line: 16
Column: 5
class ASTGrammarPrinter:
def children(self, node: Rule) -> Iterator[Any]:
for value in node:
if isinstance(value, list):
yield from value
else:
yield value
Reported by Pylint.
Line: 23
Column: 5
else:
yield value
def name(self, node: Rule) -> str:
if not list(self.children(node)):
return repr(node)
return node.__class__.__name__
def print_grammar_ast(self, grammar: Grammar, printer: Callable[..., None] = print) -> None:
Reported by Pylint.
Line: 28
Column: 5
return repr(node)
return node.__class__.__name__
def print_grammar_ast(self, grammar: Grammar, printer: Callable[..., None] = print) -> None:
for rule in grammar.rules.values():
printer(self.print_nodes_recursively(rule))
def print_nodes_recursively(self, node: Rule, prefix: str = "", istail: bool = True) -> str:
Reported by Pylint.
Lib/unittest/_log.py
12 issues
Line: 4
Column: 1
import logging
import collections
from .case import _BaseTestCaseContext
_LoggingWatcher = collections.namedtuple("_LoggingWatcher",
["records", "output"])
Reported by Pylint.
Line: 45
Column: 22
def __enter__(self):
if isinstance(self.logger_name, logging.Logger):
logger = self.logger = self.logger_name
else:
logger = self.logger = logging.getLogger(self.logger_name)
formatter = logging.Formatter(self.LOGGING_FORMAT)
handler = _CapturingHandler()
handler.setLevel(self.level)
Reported by Pylint.
Line: 47
Column: 22
if isinstance(self.logger_name, logging.Logger):
logger = self.logger = self.logger_name
else:
logger = self.logger = logging.getLogger(self.logger_name)
formatter = logging.Formatter(self.LOGGING_FORMAT)
handler = _CapturingHandler()
handler.setLevel(self.level)
handler.setFormatter(formatter)
self.watcher = handler.watcher
Reported by Pylint.
Line: 52
Column: 9
handler = _CapturingHandler()
handler.setLevel(self.level)
handler.setFormatter(formatter)
self.watcher = handler.watcher
self.old_handlers = logger.handlers[:]
self.old_level = logger.level
self.old_propagate = logger.propagate
logger.handlers = [handler]
logger.setLevel(self.level)
Reported by Pylint.
Line: 53
Column: 9
handler.setLevel(self.level)
handler.setFormatter(formatter)
self.watcher = handler.watcher
self.old_handlers = logger.handlers[:]
self.old_level = logger.level
self.old_propagate = logger.propagate
logger.handlers = [handler]
logger.setLevel(self.level)
logger.propagate = False
Reported by Pylint.
Line: 54
Column: 9
handler.setFormatter(formatter)
self.watcher = handler.watcher
self.old_handlers = logger.handlers[:]
self.old_level = logger.level
self.old_propagate = logger.propagate
logger.handlers = [handler]
logger.setLevel(self.level)
logger.propagate = False
if self.no_logs:
Reported by Pylint.
Line: 55
Column: 9
self.watcher = handler.watcher
self.old_handlers = logger.handlers[:]
self.old_level = logger.level
self.old_propagate = logger.propagate
logger.handlers = [handler]
logger.setLevel(self.level)
logger.propagate = False
if self.no_logs:
return
Reported by Pylint.
Line: 1
Column: 1
import logging
import collections
from .case import _BaseTestCaseContext
_LoggingWatcher = collections.namedtuple("_LoggingWatcher",
["records", "output"])
Reported by Pylint.
Line: 28
Column: 1
self.watcher.output.append(msg)
class _AssertLogsContext(_BaseTestCaseContext):
"""A context manager for assertLogs() and assertNoLogs() """
LOGGING_FORMAT = "%(levelname)s:%(name)s:%(message)s"
def __init__(self, test_case, logger_name, level, no_logs):
Reported by Pylint.
Line: 43
Column: 5
self.msg = None
self.no_logs = no_logs
def __enter__(self):
if isinstance(self.logger_name, logging.Logger):
logger = self.logger = self.logger_name
else:
logger = self.logger = logging.getLogger(self.logger_name)
formatter = logging.Formatter(self.LOGGING_FORMAT)
Reported by Pylint.
Modules/_cursesmodule.c
12 issues
Line: 1410
else {
rtn = mvwgetch(self->win, y, x);
}
Py_END_ALLOW_THREADS
return rtn;
}
/*[clinic input]
Reported by Cppcheck.
Line: 309
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
{
long value;
#ifdef HAVE_NCURSESW
wchar_t buffer[2];
#endif
if (PyUnicode_Check(obj)) {
#ifdef HAVE_NCURSESW
if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {
Reported by FlawFinder.
Line: 672
Column: 9
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
if (encoding == NULL) {
#if defined(MS_WINDOWS)
char *buffer[100];
UINT cp;
cp = GetConsoleOutputCP();
if (cp != 0) {
PyOS_snprintf(buffer, sizeof(buffer), "cp%u", cp);
encoding = buffer;
Reported by FlawFinder.
Line: 749
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
int type;
chtype cch = 0;
#ifdef HAVE_NCURSESW
wchar_t wstr[2];
cchar_t wcval;
#endif
const char *funcname;
#ifdef HAVE_NCURSESW
Reported by FlawFinder.
Line: 1541
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
{
int x, y, n;
char rtn[1024]; /* This should be big enough.. I hope */
int rtn2;
switch (PyTuple_Size(args)) {
case 0:
Py_BEGIN_ALLOW_THREADS
Reported by FlawFinder.
Line: 1745
Column: 5
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
{
int x, y, n;
char rtn[1024]; /* This should be big enough.. I hope */
int rtn2;
switch (PyTuple_Size(args)) {
case 0:
rtn2 = winnstr(self->win,rtn, 1023);
Reported by FlawFinder.
Line: 2162
Column: 10
CWE codes:
377
FILE *fp;
PyObject *res = NULL;
fp = tmpfile();
if (fp == NULL)
return PyErr_SetFromErrno(PyExc_OSError);
if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)
goto exit;
res = PyCursesCheckERR(putwin(self->win, fp), "putwin");
Reported by FlawFinder.
Line: 2172
Column: 9
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
goto exit;
fseek(fp, 0, 0);
while (1) {
char buf[BUFSIZ];
Py_ssize_t n = fread(buf, 1, BUFSIZ, fp);
_Py_IDENTIFIER(write);
if (n <= 0)
break;
Reported by FlawFinder.
Line: 3053
Column: 10
CWE codes:
377
PyCursesInitialised;
fp = tmpfile();
if (fp == NULL)
return PyErr_SetFromErrno(PyExc_OSError);
if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)
goto error;
Reported by FlawFinder.
Line: 4444
Column: 9
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
wchar_t *wch)
{
if (PyUnicode_Check(obj)) {
wchar_t buffer[2];
if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {
PyErr_Format(PyExc_TypeError,
"expect str of length 1 or int, "
"got a str of length %zi",
PyUnicode_GET_LENGTH(obj));
Reported by FlawFinder.
Modules/_io/textio.c
12 issues
Line: 41
Column: 16
CWE codes:
327
Suggestion:
Use a more secure technique for acquiring random values
_Py_IDENTIFIER(reset);
_Py_IDENTIFIER(seek);
_Py_IDENTIFIER(seekable);
_Py_IDENTIFIER(setstate);
_Py_IDENTIFIER(strict);
_Py_IDENTIFIER(tell);
_Py_IDENTIFIER(writable);
/* TextIOBase */
Reported by FlawFinder.
Line: 347
Column: 9
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
kind = PyUnicode_KIND(modified);
out = PyUnicode_DATA(modified);
PyUnicode_WRITE(kind, out, 0, '\r');
memcpy(out + kind, PyUnicode_DATA(output), kind * output_len);
Py_DECREF(output);
output = modified; /* output remains ready */
self->pendingcr = 0;
output_len++;
}
Reported by FlawFinder.
Line: 1586
Column: 13
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
return -1;
}
}
memcpy(buf + pos, src, len);
pos += len;
}
assert(pos == self->pending_bytes_count);
}
Reported by FlawFinder.
Line: 2361
Column: 14
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
static int
textiowrapper_parse_cookie(cookie_type *cookie, PyObject *cookieObj)
{
unsigned char buffer[COOKIE_BUF_LEN];
PyLongObject *cookieLong = (PyLongObject *)PyNumber_Long(cookieObj);
if (cookieLong == NULL)
return -1;
if (_PyLong_AsByteArray(cookieLong, buffer, sizeof(buffer),
Reported by FlawFinder.
Line: 2385
Column: 14
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
static PyObject *
textiowrapper_build_cookie(cookie_type *cookie)
{
unsigned char buffer[COOKIE_BUF_LEN];
memcpy(buffer + OFF_START_POS, &cookie->start_pos, sizeof(cookie->start_pos));
memcpy(buffer + OFF_DEC_FLAGS, &cookie->dec_flags, sizeof(cookie->dec_flags));
memcpy(buffer + OFF_BYTES_TO_FEED, &cookie->bytes_to_feed, sizeof(cookie->bytes_to_feed));
memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip));
Reported by FlawFinder.
Line: 2387
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
{
unsigned char buffer[COOKIE_BUF_LEN];
memcpy(buffer + OFF_START_POS, &cookie->start_pos, sizeof(cookie->start_pos));
memcpy(buffer + OFF_DEC_FLAGS, &cookie->dec_flags, sizeof(cookie->dec_flags));
memcpy(buffer + OFF_BYTES_TO_FEED, &cookie->bytes_to_feed, sizeof(cookie->bytes_to_feed));
memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip));
memcpy(buffer + OFF_NEED_EOF, &cookie->need_eof, sizeof(cookie->need_eof));
Reported by FlawFinder.
Line: 2388
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
unsigned char buffer[COOKIE_BUF_LEN];
memcpy(buffer + OFF_START_POS, &cookie->start_pos, sizeof(cookie->start_pos));
memcpy(buffer + OFF_DEC_FLAGS, &cookie->dec_flags, sizeof(cookie->dec_flags));
memcpy(buffer + OFF_BYTES_TO_FEED, &cookie->bytes_to_feed, sizeof(cookie->bytes_to_feed));
memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip));
memcpy(buffer + OFF_NEED_EOF, &cookie->need_eof, sizeof(cookie->need_eof));
return _PyLong_FromByteArray(buffer, sizeof(buffer),
Reported by FlawFinder.
Line: 2389
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
memcpy(buffer + OFF_START_POS, &cookie->start_pos, sizeof(cookie->start_pos));
memcpy(buffer + OFF_DEC_FLAGS, &cookie->dec_flags, sizeof(cookie->dec_flags));
memcpy(buffer + OFF_BYTES_TO_FEED, &cookie->bytes_to_feed, sizeof(cookie->bytes_to_feed));
memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip));
memcpy(buffer + OFF_NEED_EOF, &cookie->need_eof, sizeof(cookie->need_eof));
return _PyLong_FromByteArray(buffer, sizeof(buffer),
PY_LITTLE_ENDIAN, 0);
Reported by FlawFinder.
Line: 2390
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
memcpy(buffer + OFF_START_POS, &cookie->start_pos, sizeof(cookie->start_pos));
memcpy(buffer + OFF_DEC_FLAGS, &cookie->dec_flags, sizeof(cookie->dec_flags));
memcpy(buffer + OFF_BYTES_TO_FEED, &cookie->bytes_to_feed, sizeof(cookie->bytes_to_feed));
memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip));
memcpy(buffer + OFF_NEED_EOF, &cookie->need_eof, sizeof(cookie->need_eof));
return _PyLong_FromByteArray(buffer, sizeof(buffer),
PY_LITTLE_ENDIAN, 0);
}
Reported by FlawFinder.
Line: 2391
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
memcpy(buffer + OFF_DEC_FLAGS, &cookie->dec_flags, sizeof(cookie->dec_flags));
memcpy(buffer + OFF_BYTES_TO_FEED, &cookie->bytes_to_feed, sizeof(cookie->bytes_to_feed));
memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip));
memcpy(buffer + OFF_NEED_EOF, &cookie->need_eof, sizeof(cookie->need_eof));
return _PyLong_FromByteArray(buffer, sizeof(buffer),
PY_LITTLE_ENDIAN, 0);
}
Reported by FlawFinder.
Lib/test/test_binhex.py
12 issues
Line: 17
Column: 1
binhex = import_helper.import_fresh_module('binhex')
class BinHexTestCase(unittest.TestCase):
def setUp(self):
# binhex supports only file names encodable to Latin1
self.fname1 = os_helper.TESTFN_ASCII + "1"
self.fname2 = os_helper.TESTFN_ASCII + "2"
Reported by Pylint.
Line: 23
Column: 1
# binhex supports only file names encodable to Latin1
self.fname1 = os_helper.TESTFN_ASCII + "1"
self.fname2 = os_helper.TESTFN_ASCII + "2"
self.fname3 = os_helper.TESTFN_ASCII + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__"
def tearDown(self):
os_helper.unlink(self.fname1)
os_helper.unlink(self.fname2)
os_helper.unlink(self.fname3)
Reported by Pylint.
Line: 32
Column: 5
DATA = b'Jack is my hero'
def test_binhex(self):
with open(self.fname1, 'wb') as f:
f.write(self.DATA)
binhex.binhex(self.fname1, self.fname2)
Reported by Pylint.
Line: 33
Column: 41
DATA = b'Jack is my hero'
def test_binhex(self):
with open(self.fname1, 'wb') as f:
f.write(self.DATA)
binhex.binhex(self.fname1, self.fname2)
binhex.hexbin(self.fname2, self.fname1)
Reported by Pylint.
Line: 40
Column: 41
binhex.hexbin(self.fname2, self.fname1)
with open(self.fname1, 'rb') as f:
finish = f.readline()
self.assertEqual(self.DATA, finish)
def test_binhex_error_on_long_filename(self):
Reported by Pylint.
Line: 47
Column: 1
def test_binhex_error_on_long_filename(self):
"""
The testcase fails if no exception is raised when a filename parameter provided to binhex.binhex()
is too long, or if the exception raised in binhex.binhex() is not an instance of binhex.Error.
"""
f3 = open(self.fname3, 'wb')
f3.close()
Reported by Pylint.
Line: 48
Column: 1
def test_binhex_error_on_long_filename(self):
"""
The testcase fails if no exception is raised when a filename parameter provided to binhex.binhex()
is too long, or if the exception raised in binhex.binhex() is not an instance of binhex.Error.
"""
f3 = open(self.fname3, 'wb')
f3.close()
self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2)
Reported by Pylint.
Line: 50
Column: 9
The testcase fails if no exception is raised when a filename parameter provided to binhex.binhex()
is too long, or if the exception raised in binhex.binhex() is not an instance of binhex.Error.
"""
f3 = open(self.fname3, 'wb')
f3.close()
self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2)
def test_binhex_line_endings(self):
Reported by Pylint.
Line: 55
Column: 5
self.assertRaises(binhex.Error, binhex.binhex, self.fname3, self.fname2)
def test_binhex_line_endings(self):
# bpo-29566: Ensure the line endings are those for macOS 9
with open(self.fname1, 'wb') as f:
f.write(self.DATA)
binhex.binhex(self.fname1, self.fname2)
Reported by Pylint.
Line: 57
Column: 41
def test_binhex_line_endings(self):
# bpo-29566: Ensure the line endings are those for macOS 9
with open(self.fname1, 'wb') as f:
f.write(self.DATA)
binhex.binhex(self.fname1, self.fname2)
with open(self.fname2, 'rb') as fp:
Reported by Pylint.
Lib/test/support/warnings_helper.py
12 issues
Line: 151
Column: 13
"""
# Clear the warning registry of the calling module
# in order to re-raise the warnings.
frame = sys._getframe(2)
registry = frame.f_globals.get('__warningregistry__')
if registry:
registry.clear()
with warnings.catch_warnings(record=True) as w:
# Set filter "always" to record all warnings. Because
Reported by Pylint.
Line: 1
Column: 1
import contextlib
import functools
import re
import sys
import warnings
def check_syntax_warning(testcase, statement, errtext='',
*, lineno=1, offset=None):
Reported by Pylint.
Line: 8
Column: 1
import warnings
def check_syntax_warning(testcase, statement, errtext='',
*, lineno=1, offset=None):
# Test also that a warning is emitted only once.
from test.support import check_syntax_error
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always', SyntaxWarning)
Reported by Pylint.
Line: 11
Column: 5
def check_syntax_warning(testcase, statement, errtext='',
*, lineno=1, offset=None):
# Test also that a warning is emitted only once.
from test.support import check_syntax_error
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always', SyntaxWarning)
compile(statement, '<testcase>', 'exec')
testcase.assertEqual(len(warns), 1, warns)
Reported by Pylint.
Line: 54
Column: 1
return decorator
class WarningsRecorder(object):
"""Convenience wrapper for the warnings list returned on
entry to the warnings.catch_warnings() context manager.
"""
def __init__(self, warnings_list):
self._warnings = warnings_list
Reported by Pylint.
Line: 63
Column: 9
self._last = 0
def __getattr__(self, attr):
if len(self._warnings) > self._last:
return getattr(self._warnings[-1], attr)
elif attr in warnings.WarningMessage._WARNING_DETAILS:
return None
raise AttributeError("%r has no attribute %r" % (self, attr))
Reported by Pylint.
Line: 70
Column: 5
raise AttributeError("%r has no attribute %r" % (self, attr))
@property
def warnings(self):
return self._warnings[self._last:]
def reset(self):
self._last = len(self._warnings)
Reported by Pylint.
Line: 73
Column: 5
def warnings(self):
return self._warnings[self._last:]
def reset(self):
self._last = len(self._warnings)
@contextlib.contextmanager
def check_warnings(*filters, **kwargs):
Reported by Pylint.
Line: 115
Column: 5
Other keyword arguments are passed to warnings.filterwarnings().
"""
from test.support import gc_collect
with warnings.catch_warnings(record=True) as warns:
warnings.filterwarnings('always',
message=message,
category=category)
yield
Reported by Pylint.
Line: 155
Column: 50
registry = frame.f_globals.get('__warningregistry__')
if registry:
registry.clear()
with warnings.catch_warnings(record=True) as w:
# Set filter "always" to record all warnings. Because
# test_warnings swap the module, we need to look up in
# the sys.modules dictionary.
sys.modules['warnings'].simplefilter("always")
yield WarningsRecorder(w)
Reported by Pylint.
Lib/test/test_keyword.py
12 issues
Line: 26
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
def test_all_keywords_fail_to_be_used_as_names(self):
for key in keyword.kwlist:
with self.assertRaises(SyntaxError):
exec(f"{key} = 42")
def test_async_and_await_are_keywords(self):
self.assertIn("async", keyword.kwlist)
self.assertIn("await", keyword.kwlist)
Reported by Bandit.
Line: 26
Column: 17
def test_all_keywords_fail_to_be_used_as_names(self):
for key in keyword.kwlist:
with self.assertRaises(SyntaxError):
exec(f"{key} = 42")
def test_async_and_await_are_keywords(self):
self.assertIn("async", keyword.kwlist)
self.assertIn("await", keyword.kwlist)
Reported by Pylint.
Line: 1
Column: 1
import keyword
import unittest
class Test_iskeyword(unittest.TestCase):
def test_true_is_a_keyword(self):
self.assertTrue(keyword.iskeyword('True'))
def test_uppercase_true_is_not_a_keyword(self):
Reported by Pylint.
Line: 5
Column: 1
import unittest
class Test_iskeyword(unittest.TestCase):
def test_true_is_a_keyword(self):
self.assertTrue(keyword.iskeyword('True'))
def test_uppercase_true_is_not_a_keyword(self):
self.assertFalse(keyword.iskeyword('TRUE'))
Reported by Pylint.
Line: 5
Column: 1
import unittest
class Test_iskeyword(unittest.TestCase):
def test_true_is_a_keyword(self):
self.assertTrue(keyword.iskeyword('True'))
def test_uppercase_true_is_not_a_keyword(self):
self.assertFalse(keyword.iskeyword('TRUE'))
Reported by Pylint.
Line: 6
Column: 5
class Test_iskeyword(unittest.TestCase):
def test_true_is_a_keyword(self):
self.assertTrue(keyword.iskeyword('True'))
def test_uppercase_true_is_not_a_keyword(self):
self.assertFalse(keyword.iskeyword('TRUE'))
Reported by Pylint.
Line: 9
Column: 5
def test_true_is_a_keyword(self):
self.assertTrue(keyword.iskeyword('True'))
def test_uppercase_true_is_not_a_keyword(self):
self.assertFalse(keyword.iskeyword('TRUE'))
def test_none_value_is_not_a_keyword(self):
self.assertFalse(keyword.iskeyword(None))
Reported by Pylint.
Line: 12
Column: 5
def test_uppercase_true_is_not_a_keyword(self):
self.assertFalse(keyword.iskeyword('TRUE'))
def test_none_value_is_not_a_keyword(self):
self.assertFalse(keyword.iskeyword(None))
# This is probably an accident of the current implementation, but should be
# preserved for backward compatibility.
def test_changing_the_kwlist_does_not_affect_iskeyword(self):
Reported by Pylint.
Line: 17
Column: 5
# This is probably an accident of the current implementation, but should be
# preserved for backward compatibility.
def test_changing_the_kwlist_does_not_affect_iskeyword(self):
oldlist = keyword.kwlist
self.addCleanup(setattr, keyword, 'kwlist', oldlist)
keyword.kwlist = ['its', 'all', 'eggs', 'beans', 'and', 'a', 'slice']
self.assertFalse(keyword.iskeyword('eggs'))
Reported by Pylint.
Line: 23
Column: 5
keyword.kwlist = ['its', 'all', 'eggs', 'beans', 'and', 'a', 'slice']
self.assertFalse(keyword.iskeyword('eggs'))
def test_all_keywords_fail_to_be_used_as_names(self):
for key in keyword.kwlist:
with self.assertRaises(SyntaxError):
exec(f"{key} = 42")
def test_async_and_await_are_keywords(self):
Reported by Pylint.
Lib/test/badsyntax_future7.py
12 issues
Line: 3
Column: 54
"""This is a test"""
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
def f(x):
def g(y):
return x + y
return g
Reported by Pylint.
Line: 3
Column: 39
"""This is a test"""
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
def f(x):
def g(y):
return x + y
return g
Reported by Pylint.
Line: 3
Column: 54
"""This is a test"""
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
def f(x):
def g(y):
return x + y
return g
Reported by Pylint.
Line: 3
Column: 1
"""This is a test"""
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
def f(x):
def g(y):
return x + y
return g
Reported by Pylint.
Line: 3
Column: 39
"""This is a test"""
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
def f(x):
def g(y):
return x + y
return g
Reported by Pylint.
Line: 3
Column: 54
"""This is a test"""
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
def f(x):
def g(y):
return x + y
return g
Reported by Pylint.
Line: 6
Column: 1
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 6
Column: 1
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 6
Column: 1
from __future__ import nested_scopes; import string; from __future__ import \
nested_scopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 7
Column: 5
nested_scopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Lib/test/test_json/test_pass2.py
12 issues
Line: 12
Column: 15
class TestPass2:
def test_parse(self):
# test in/out equivalence and parsing
res = self.loads(JSON)
out = self.dumps(res)
self.assertEqual(res, self.loads(out))
class TestPyPass2(TestPass2, PyTest): pass
Reported by Pylint.
Line: 13
Column: 15
def test_parse(self):
# test in/out equivalence and parsing
res = self.loads(JSON)
out = self.dumps(res)
self.assertEqual(res, self.loads(out))
class TestPyPass2(TestPass2, PyTest): pass
class TestCPass2(TestPass2, CTest): pass
Reported by Pylint.
Line: 14
Column: 9
# test in/out equivalence and parsing
res = self.loads(JSON)
out = self.dumps(res)
self.assertEqual(res, self.loads(out))
class TestPyPass2(TestPass2, PyTest): pass
class TestCPass2(TestPass2, CTest): pass
Reported by Pylint.
Line: 14
Column: 31
# test in/out equivalence and parsing
res = self.loads(JSON)
out = self.dumps(res)
self.assertEqual(res, self.loads(out))
class TestPyPass2(TestPass2, PyTest): pass
class TestCPass2(TestPass2, CTest): pass
Reported by Pylint.
Line: 1
Column: 1
from test.test_json import PyTest, CTest
# from http://json.org/JSON_checker/test/pass2.json
JSON = r'''
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
'''
class TestPass2:
Reported by Pylint.
Line: 9
Column: 1
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
'''
class TestPass2:
def test_parse(self):
# test in/out equivalence and parsing
res = self.loads(JSON)
out = self.dumps(res)
self.assertEqual(res, self.loads(out))
Reported by Pylint.
Line: 9
Column: 1
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
'''
class TestPass2:
def test_parse(self):
# test in/out equivalence and parsing
res = self.loads(JSON)
out = self.dumps(res)
self.assertEqual(res, self.loads(out))
Reported by Pylint.
Line: 10
Column: 5
'''
class TestPass2:
def test_parse(self):
# test in/out equivalence and parsing
res = self.loads(JSON)
out = self.dumps(res)
self.assertEqual(res, self.loads(out))
Reported by Pylint.
Line: 17
Column: 39
self.assertEqual(res, self.loads(out))
class TestPyPass2(TestPass2, PyTest): pass
class TestCPass2(TestPass2, CTest): pass
Reported by Pylint.
Line: 17
Column: 1
self.assertEqual(res, self.loads(out))
class TestPyPass2(TestPass2, PyTest): pass
class TestCPass2(TestPass2, CTest): pass
Reported by Pylint.