The following issues were found

Lib/sqlite3/test/transactions.py
20 issues
Missing module docstring
Error

Line: 1 Column: 1

              # pysqlite2/test/transactions.py: tests transactions
#
# Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
#
# This file is part of pysqlite.
#
# This software is provided 'as-is', without any express or implied
# warranty.  In no event will the authors be held liable for any damages
# arising from the use of this software.

            

Reported by Pylint.

Multiple imports on one line (os, unittest)
Error

Line: 23 Column: 1

              #    misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.

import os, unittest
import sqlite3 as sqlite

def get_db_path():
    return "sqlite_testdb"


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 1

              import os, unittest
import sqlite3 as sqlite

def get_db_path():
    return "sqlite_testdb"

class TransactionTests(unittest.TestCase):
    def setUp(self):
        try:

            

Reported by Pylint.

Missing class docstring
Error

Line: 29 Column: 1

              def get_db_path():
    return "sqlite_testdb"

class TransactionTests(unittest.TestCase):
    def setUp(self):
        try:
            os.remove(get_db_path())
        except OSError:
            pass

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 54 Column: 5

                      except OSError:
            pass

    def test_dml_does_not_auto_commit_before(self):
        self.cur1.execute("create table test(i)")
        self.cur1.execute("insert into test(i) values (5)")
        self.cur1.execute("create table test2(j)")
        self.cur2.execute("select i from test")
        res = self.cur2.fetchall()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 62 Column: 5

                      res = self.cur2.fetchall()
        self.assertEqual(len(res), 0)

    def test_insert_starts_transaction(self):
        self.cur1.execute("create table test(i)")
        self.cur1.execute("insert into test(i) values (5)")
        self.cur2.execute("select i from test")
        res = self.cur2.fetchall()
        self.assertEqual(len(res), 0)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 69 Column: 5

                      res = self.cur2.fetchall()
        self.assertEqual(len(res), 0)

    def test_update_starts_transaction(self):
        self.cur1.execute("create table test(i)")
        self.cur1.execute("insert into test(i) values (5)")
        self.con1.commit()
        self.cur1.execute("update test set i=6")
        self.cur2.execute("select i from test")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 78 Column: 5

                      res = self.cur2.fetchone()[0]
        self.assertEqual(res, 5)

    def test_delete_starts_transaction(self):
        self.cur1.execute("create table test(i)")
        self.cur1.execute("insert into test(i) values (5)")
        self.con1.commit()
        self.cur1.execute("delete from test")
        self.cur2.execute("select i from test")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 87 Column: 5

                      res = self.cur2.fetchall()
        self.assertEqual(len(res), 1)

    def test_replace_starts_transaction(self):
        self.cur1.execute("create table test(i)")
        self.cur1.execute("insert into test(i) values (5)")
        self.con1.commit()
        self.cur1.execute("replace into test(i) values (6)")
        self.cur2.execute("select i from test")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 97 Column: 5

                      self.assertEqual(len(res), 1)
        self.assertEqual(res[0][0], 5)

    def test_toggle_auto_commit(self):
        self.cur1.execute("create table test(i)")
        self.cur1.execute("insert into test(i) values (5)")
        self.con1.isolation_level = None
        self.assertEqual(self.con1.isolation_level, None)
        self.cur2.execute("select i from test")

            

Reported by Pylint.

Lib/multiprocessing/popen_spawn_win32.py
19 issues
Unable to import 'msvcrt'
Error

Line: 2 Column: 1

              import os
import msvcrt
import signal
import sys
import _winapi

from .context import reduction, get_spawning_popen, set_spawning_popen
from . import spawn
from . import util

            

Reported by Pylint.

Unable to import '_winapi'
Error

Line: 5 Column: 1

              import msvcrt
import signal
import sys
import _winapi

from .context import reduction, get_spawning_popen, set_spawning_popen
from . import spawn
from . import util


            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 7 Column: 1

              import sys
import _winapi

from .context import reduction, get_spawning_popen, set_spawning_popen
from . import spawn
from . import util

__all__ = ['Popen']


            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 8 Column: 1

              import _winapi

from .context import reduction, get_spawning_popen, set_spawning_popen
from . import spawn
from . import util

__all__ = ['Popen']

#

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 9 Column: 1

              
from .context import reduction, get_spawning_popen, set_spawning_popen
from . import spawn
from . import util

__all__ = ['Popen']

#
#

            

Reported by Pylint.

Access to a protected member _base_executable of a client class
Error

Line: 25 Column: 39

              def _path_eq(p1, p2):
    return p1 == p2 or os.path.normcase(p1) == os.path.normcase(p2)

WINENV = not _path_eq(sys.executable, sys._base_executable)


def _close_handles(*handles):
    for handle in handles:
        _winapi.CloseHandle(handle)

            

Reported by Pylint.

Unused variable 'tid'
Error

Line: 73 Column: 30

                      with open(wfd, 'wb', closefd=True) as to_child:
            # start process
            try:
                hp, ht, pid, tid = _winapi.CreateProcess(
                    python_exe, cmd,
                    None, None, False, 0, env, None, None)
                _winapi.CloseHandle(ht)
            except:
                _winapi.CloseHandle(rhandle)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import os
import msvcrt
import signal
import sys
import _winapi

from .context import reduction, get_spawning_popen, set_spawning_popen
from . import spawn
from . import util

            

Reported by Pylint.

Argument name "p1" doesn't conform to snake_case naming style
Error

Line: 22 Column: 1

              WINSERVICE = sys.executable.lower().endswith("pythonservice.exe")


def _path_eq(p1, p2):
    return p1 == p2 or os.path.normcase(p1) == os.path.normcase(p2)

WINENV = not _path_eq(sys.executable, sys._base_executable)



            

Reported by Pylint.

Argument name "p2" doesn't conform to snake_case naming style
Error

Line: 22 Column: 1

              WINSERVICE = sys.executable.lower().endswith("pythonservice.exe")


def _path_eq(p1, p2):
    return p1 == p2 or os.path.normcase(p1) == os.path.normcase(p2)

WINENV = not _path_eq(sys.executable, sys._base_executable)



            

Reported by Pylint.

Lib/test/support/interpreters.py
19 issues
Module '_xxsubinterpreters' has no 'is_isolated' member
Error

Line: 77 Column: 30

                      if self._isolated is None:
            # XXX The low-level function has not been added yet.
            # See bpo-....
            self._isolated = _interpreters.is_isolated(self._id)
        return self._isolated

    def is_running(self):
        """Return whether or not the identified interpreter is running."""
        return _interpreters.is_running(self._id)

            

Reported by Pylint.

Redefining built-in 'id'
Error

Line: 24 Column: 5

              
def create(*, isolated=True):
    """Return a new (idle) Python interpreter."""
    id = _interpreters.create(isolated=isolated)
    return Interpreter(id, isolated=isolated)


def list_all():
    """Return all existing interpreters."""

            

Reported by Pylint.

Redefining built-in 'id'
Error

Line: 35 Column: 5

              
def get_current():
    """Return the currently running interpreter."""
    id = _interpreters.get_current()
    return Interpreter(id)


def get_main():
    """Return the main interpreter."""

            

Reported by Pylint.

Redefining built-in 'id'
Error

Line: 41 Column: 5

              
def get_main():
    """Return the main interpreter."""
    id = _interpreters.get_main()
    return Interpreter(id)


class Interpreter:
    """A single Python interpreter."""

            

Reported by Pylint.

Redefining built-in 'id'
Error

Line: 48 Column: 24

              class Interpreter:
    """A single Python interpreter."""

    def __init__(self, id, *, isolated=None):
        if not isinstance(id, (int, _interpreters.InterpreterID)):
            raise TypeError(f'id must be an int, got {id!r}')
        self._id = id
        self._isolated = isolated


            

Reported by Pylint.

XXX The low-level function has not been added yet.
Error

Line: 75 Column: 3

                  @property
    def isolated(self):
        if self._isolated is None:
            # XXX The low-level function has not been added yet.
            # See bpo-....
            self._isolated = _interpreters.is_isolated(self._id)
        return self._isolated

    def is_running(self):

            

Reported by Pylint.

Redefining built-in 'id'
Error

Line: 119 Column: 24

              class _ChannelEnd:
    """The base class for RecvChannel and SendChannel."""

    def __init__(self, id):
        if not isinstance(id, (int, _interpreters.ChannelID)):
            raise TypeError(f'id must be an int, got {id!r}')
        self._id = id

    def __repr__(self):

            

Reported by Pylint.

XXX We are missing a low-level channel_send_wait().
Error

Line: 183 Column: 3

                      This blocks until the object is received.
        """
        _interpreters.channel_send(self._id, obj)
        # XXX We are missing a low-level channel_send_wait().
        # See bpo-32604 and gh-19829.
        # Until that shows up we fake it:
        time.sleep(2)

    def send_nowait(self, obj):

            

Reported by Pylint.

XXX Note that at the moment channel_send() only ever returns
Error

Line: 194 Column: 3

                      If the object is immediately received then return True
        (else False).  Otherwise this is the same as send().
        """
        # XXX Note that at the moment channel_send() only ever returns
        # None.  This should be fixed when channel_send_wait() is added.
        # See bpo-32604 and gh-19829.
        return _interpreters.channel_send(self._id, obj)

            

Reported by Pylint.

Variable name "id" doesn't conform to snake_case naming style
Error

Line: 24 Column: 5

              
def create(*, isolated=True):
    """Return a new (idle) Python interpreter."""
    id = _interpreters.create(isolated=isolated)
    return Interpreter(id, isolated=isolated)


def list_all():
    """Return all existing interpreters."""

            

Reported by Pylint.

Lib/multiprocessing/dummy/connection.py
19 issues
Unused argument 'address'
Error

Line: 20 Column: 24

              
class Listener(object):

    def __init__(self, address=None, family=None, backlog=1):
        self._backlog_queue = Queue(backlog)

    def accept(self):
        return Connection(*self._backlog_queue.get())


            

Reported by Pylint.

Unused argument 'family'
Error

Line: 20 Column: 38

              
class Listener(object):

    def __init__(self, address=None, family=None, backlog=1):
        self._backlog_queue = Queue(backlog)

    def accept(self):
        return Connection(*self._backlog_queue.get())


            

Reported by Pylint.

Unused argument 'duplex'
Error

Line: 46 Column: 10

                  return Connection(_in, _out)


def Pipe(duplex=True):
    a, b = Queue(), Queue()
    return Connection(a, b), Connection(b, a)


class Connection(object):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #
# Analogue of `multiprocessing.connection` which uses queues instead of sockets
#
# multiprocessing/dummy/connection.py
#
# Copyright (c) 2006-2008, R Oudkerk
# Licensed to PSF under a Contributor Agreement.
#


            

Reported by Pylint.

Class 'Listener' inherits from object, can be safely removed from bases in python3
Error

Line: 18 Column: 1

              families = [None]


class Listener(object):

    def __init__(self, address=None, family=None, backlog=1):
        self._backlog_queue = Queue(backlog)

    def accept(self):

            

Reported by Pylint.

Missing class docstring
Error

Line: 18 Column: 1

              families = [None]


class Listener(object):

    def __init__(self, address=None, family=None, backlog=1):
        self._backlog_queue = Queue(backlog)

    def accept(self):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 5

                  def __init__(self, address=None, family=None, backlog=1):
        self._backlog_queue = Queue(backlog)

    def accept(self):
        return Connection(*self._backlog_queue.get())

    def close(self):
        self._backlog_queue = None


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 5

                  def accept(self):
        return Connection(*self._backlog_queue.get())

    def close(self):
        self._backlog_queue = None

    @property
    def address(self):
        return self._backlog_queue

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 30 Column: 5

                      self._backlog_queue = None

    @property
    def address(self):
        return self._backlog_queue

    def __enter__(self):
        return self


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 40 Column: 1

                      self.close()


def Client(address):
    _in, _out = Queue(), Queue()
    address.put((_out, _in))
    return Connection(_in, _out)



            

Reported by Pylint.

Lib/test/test_ioctl.py
19 issues
Consider explicitly re-raising using the 'from' keyword
Error

Line: 13 Column: 5

              try:
    tty = open("/dev/tty", "rb")
except OSError:
    raise unittest.SkipTest("Unable to open /dev/tty")
else:
    with tty:
        # Skip if another process is in foreground
        r = fcntl.ioctl(tty, termios.TIOCGPGRP, "    ")
    rpgrp = struct.unpack("i", r)[0]

            

Reported by Pylint.

Redefining name 'tty' from outer scope (line 11)
Error

Line: 34 Column: 40

                      # If this process has been put into the background, TIOCGPGRP returns
        # the session ID instead of the process group id.
        ids = (os.getpgrp(), os.getsid(0))
        with open("/dev/tty", "rb") as tty:
            r = fcntl.ioctl(tty, termios.TIOCGPGRP, "    ")
            rpgrp = struct.unpack("i", r)[0]
            self.assertIn(rpgrp, ids)

    def _check_ioctl_mutate_len(self, nbytes=None):

            

Reported by Pylint.

Redefining name 'r' from outer scope (line 17)
Error

Line: 35 Column: 13

                      # the session ID instead of the process group id.
        ids = (os.getpgrp(), os.getsid(0))
        with open("/dev/tty", "rb") as tty:
            r = fcntl.ioctl(tty, termios.TIOCGPGRP, "    ")
            rpgrp = struct.unpack("i", r)[0]
            self.assertIn(rpgrp, ids)

    def _check_ioctl_mutate_len(self, nbytes=None):
        buf = array.array('i')

            

Reported by Pylint.

Redefining name 'rpgrp' from outer scope (line 18)
Error

Line: 36 Column: 13

                      ids = (os.getpgrp(), os.getsid(0))
        with open("/dev/tty", "rb") as tty:
            r = fcntl.ioctl(tty, termios.TIOCGPGRP, "    ")
            rpgrp = struct.unpack("i", r)[0]
            self.assertIn(rpgrp, ids)

    def _check_ioctl_mutate_len(self, nbytes=None):
        buf = array.array('i')
        intsize = buf.itemsize

            

Reported by Pylint.

Redefining name 'tty' from outer scope (line 11)
Error

Line: 51 Column: 40

                          self.assertEqual(len(buf) * intsize, nbytes)   # sanity check
        else:
            buf.append(fill)
        with open("/dev/tty", "rb") as tty:
            r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, True)
        rpgrp = buf[0]
        self.assertEqual(r, 0)
        self.assertIn(rpgrp, ids)


            

Reported by Pylint.

Redefining name 'r' from outer scope (line 17)
Error

Line: 52 Column: 13

                      else:
            buf.append(fill)
        with open("/dev/tty", "rb") as tty:
            r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, True)
        rpgrp = buf[0]
        self.assertEqual(r, 0)
        self.assertIn(rpgrp, ids)

    def test_ioctl_mutate(self):

            

Reported by Pylint.

Redefining name 'rpgrp' from outer scope (line 18)
Error

Line: 53 Column: 9

                          buf.append(fill)
        with open("/dev/tty", "rb") as tty:
            r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, True)
        rpgrp = buf[0]
        self.assertEqual(r, 0)
        self.assertIn(rpgrp, ids)

    def test_ioctl_mutate(self):
        self._check_ioctl_mutate_len()

            

Reported by Pylint.

Unused variable 'new_winsz'
Error

Line: 84 Column: 13

              
            our_winsz = struct.pack("HHHH",80,25,0,0)
            # test both with a positive and potentially negative ioctl code
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz)
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
        finally:
            os.close(mfd)
            os.close(sfd)


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import array
import unittest
from test.support import get_attribute
from test.support.import_helper import import_module
import os, struct
fcntl = import_module('fcntl')
termios = import_module('termios')
get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature


            

Reported by Pylint.

Multiple imports on one line (os, struct)
Error

Line: 5 Column: 1

              import unittest
from test.support import get_attribute
from test.support.import_helper import import_module
import os, struct
fcntl = import_module('fcntl')
termios = import_module('termios')
get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature

try:

            

Reported by Pylint.

Lib/test/test_bufio.py
19 issues
Instance of 'BufferSizeTest' has no 'open' member
Error

Line: 25 Column: 13

              
        # Since C doesn't guarantee we can write/read arbitrary bytes in text
        # files, use binary mode.
        f = self.open(os_helper.TESTFN, "wb")
        try:
            # write once with \n and once without
            f.write(s)
            f.write(b"\n")
            f.write(s)

            

Reported by Pylint.

Instance of 'BufferSizeTest' has no 'assertEqual' member
Error

Line: 34 Column: 13

                          f.close()
            f = open(os_helper.TESTFN, "rb")
            line = f.readline()
            self.assertEqual(line, s + b"\n")
            line = f.readline()
            self.assertEqual(line, s)
            line = f.readline()
            self.assertFalse(line) # Must be at EOF
            f.close()

            

Reported by Pylint.

Instance of 'BufferSizeTest' has no 'assertEqual' member
Error

Line: 36 Column: 13

                          line = f.readline()
            self.assertEqual(line, s + b"\n")
            line = f.readline()
            self.assertEqual(line, s)
            line = f.readline()
            self.assertFalse(line) # Must be at EOF
            f.close()
        finally:
            os_helper.unlink(os_helper.TESTFN)

            

Reported by Pylint.

Instance of 'BufferSizeTest' has no 'assertFalse' member
Error

Line: 38 Column: 13

                          line = f.readline()
            self.assertEqual(line, s)
            line = f.readline()
            self.assertFalse(line) # Must be at EOF
            f.close()
        finally:
            os_helper.unlink(os_helper.TESTFN)

    def drive_one(self, pattern):

            

Reported by Pylint.

Instance of 'BufferSizeTest' has no 'assertEqual' member
Error

Line: 52 Column: 13

                          # stdio buffer sizes, and "off by one" errors on both sides.
            q, r = divmod(length, len(pattern))
            teststring = pattern * q + pattern[:r]
            self.assertEqual(len(teststring), length)
            self.try_one(teststring)
            self.try_one(teststring + b"x")
            self.try_one(teststring[:-1])

    def test_primepat(self):

            

Reported by Pylint.

Unused support imported from test
Error

Line: 2 Column: 1

              import unittest
from test import support
from test.support import os_helper

import io # C implementation.
import _pyio as pyio # Python implementation.

# Simple test to ensure that optimizations in the IO library deliver the
# expected results.  For best testing, run this under a debug-build Python too

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import unittest
from test import support
from test.support import os_helper

import io # C implementation.
import _pyio as pyio # Python implementation.

# Simple test to ensure that optimizations in the IO library deliver the
# expected results.  For best testing, run this under a debug-build Python too

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

              lengths = list(range(1, 257)) + [512, 1000, 1024, 2048, 4096, 8192, 10000,
                                 16384, 32768, 65536, 1000000]

class BufferSizeTest:
    def try_one(self, s):
        # Write s + "\n" + s to file, then open it and ensure that successive
        # .readline()s deliver what we wrote.

        # Ensure we can open TESTFN for writing.

            

Reported by Pylint.

Argument name "s" doesn't conform to snake_case naming style
Error

Line: 16 Column: 5

                                               16384, 32768, 65536, 1000000]

class BufferSizeTest:
    def try_one(self, s):
        # Write s + "\n" + s to file, then open it and ensure that successive
        # .readline()s deliver what we wrote.

        # Ensure we can open TESTFN for writing.
        os_helper.unlink(os_helper.TESTFN)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 5

                                               16384, 32768, 65536, 1000000]

class BufferSizeTest:
    def try_one(self, s):
        # Write s + "\n" + s to file, then open it and ensure that successive
        # .readline()s deliver what we wrote.

        # Ensure we can open TESTFN for writing.
        os_helper.unlink(os_helper.TESTFN)

            

Reported by Pylint.

Parser/tokenizer.c
19 issues
strcpy - Does not check for buffer overflows when copying to destination [MS-banned]
Security

Line: 343 Column: 5 CWE codes: 120
Suggestion: Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)

                      tok->done = E_NOMEM;
        return -1;
    }
    strcpy(new_str + current_size, line);

    tok->interactive_src_start = new_str;
    tok->interactive_src_end = new_str + current_size + line_size;
    return 0;
}

            

Reported by FlawFinder.

strcpy - Does not check for buffer overflows when copying to destination [MS-banned]
Security

Line: 884 Column: 9 CWE codes: 120
Suggestion: Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)

                          tok->done = E_NOMEM;
            return 0;
        }
        strcpy(newtok, buf);
        Py_DECREF(u);
    }
    if (tok->fp_interactive &&
        tok_concatenate_interactive_new_line(tok, newtok) == -1) {
        PyMem_Free(newtok);

            

Reported by FlawFinder.

strcpy - Does not check for buffer overflows when copying to destination [MS-banned]
Security

Line: 2113 Column: 13 CWE codes: 120
Suggestion: Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)

                  if (tok->encoding) {
        encoding = (char *)PyMem_Malloc(strlen(tok->encoding) + 1);
        if (encoding) {
            strcpy(encoding, tok->encoding);
        }
    }
    PyTokenizer_Free(tok);
    return encoding;
}

            

Reported by FlawFinder.

memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 101 Column: 5 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                      tok->done = E_NOMEM;
        return NULL;
    }
    memcpy(result, s, len);
    result[len] = '\0';
    return result;
}

static char *

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 123 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

              static const char *
get_normal_name(const char *s)  /* for utf-8 and latin-1 */
{
    char buf[13];
    int i;
    for (i = 0; i < 12; i++) {
        int c = s[i];
        if (c == '\0')
            break;

            

Reported by FlawFinder.

memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 417 Column: 5 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                  if (!tok_reserve_buf(tok, buflen + 1)) {
        goto error;
    }
    memcpy(tok->inp, buf, buflen);
    tok->inp += buflen;
    *tok->inp = '\0';
    if (tok->fp_interactive &&
        tok_concatenate_interactive_new_line(tok, buf) == -1) {
        goto error;

            

Reported by FlawFinder.

open - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 445 Column: 20 CWE codes: 362

              fp_setreadl(struct tok_state *tok, const char* enc)
{
    PyObject *readline, *io, *stream;
    _Py_IDENTIFIER(open);
    _Py_IDENTIFIER(readline);
    int fd;
    long pos;

    fd = fileno(tok->fp);

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 650 Column: 11 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

                  PyObject* utf8 = NULL;
    char *str;
    const char *s;
    const char *newl[2] = {NULL, NULL};
    int lineno = 0;
    tok->input = str = translate_newlines(input, single, tok);
    if (str == NULL)
        return NULL;
    tok->enc = NULL;

            

Reported by FlawFinder.

memcpy - Does not check for buffer overflows when copying to destination
Security

Line: 912 Column: 9 CWE codes: 120
Suggestion: Make sure destination can always hold the source data

                          PyMem_Free(newtok);
            return 0;
        }
        memcpy(tok->cur, newtok, size + 1);
        PyMem_Free(newtok);
        tok->inp += size;
        tok->multi_line_start = tok->buf + cur_multi_line_start;
    }
    else {

            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 1310 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

                      }
        Py_DECREF(s);
        // PyUnicode_FromFormatV() does not support %X
        char hex[9];
        (void)PyOS_snprintf(hex, sizeof(hex), "%04X", ch);
        if (Py_UNICODE_ISPRINTABLE(ch)) {
            syntaxerror(tok, "invalid character '%c' (U+%s)", ch, hex);
        }
        else {

            

Reported by FlawFinder.

Lib/textwrap.py
19 issues
Value 'margin' is unsubscriptable
Error

Line: 459 Column: 30

                      else:
            for i, (x, y) in enumerate(zip(margin, indent)):
                if x != y:
                    margin = margin[:i]
                    break

    # sanity check (testing/debugging only)
    if 0 and margin:
        for line in text.split("\n"):

            

Reported by Pylint.

XXX this is not locale- or charset-aware -- string.lowercase
Error

Line: 108 Column: 3

                  wordsep_simple_re = re.compile(r'(%s+)' % whitespace)
    del whitespace

    # XXX this is not locale- or charset-aware -- string.lowercase
    # is US-ASCII only (and therefore English-only)
    sentence_end_re = re.compile(r'[a-z]'             # lowercase letter
                                 r'[\.\!\?]'          # sentence-ending punct.
                                 r'[\"\']?'           # optional end-of-quote
                                 r'\Z')               # end of chunk

            

Reported by Pylint.

Redefining name 'indent' from outer scope (line 473)
Error

Line: 259 Column: 17

                          raise ValueError("invalid width %r (must be > 0)" % self.width)
        if self.max_lines is not None:
            if self.max_lines > 1:
                indent = self.subsequent_indent
            else:
                indent = self.initial_indent
            if len(indent) + len(self.placeholder.lstrip()) > self.width:
                raise ValueError("placeholder too large for max width")


            

Reported by Pylint.

Redefining name 'indent' from outer scope (line 473)
Error

Line: 440 Column: 9

                  margin = None
    text = _whitespace_only_re.sub('', text)
    indents = _leading_whitespace_re.findall(text)
    for indent in indents:
        if margin is None:
            margin = indent

        # Current line more deeply indented than previous winner:
        # no change (previous winner is still on top).

            

Reported by Pylint.

Constant name "_whitespace" doesn't conform to UPPER_CASE naming style
Error

Line: 15 Column: 1

              # Hardcode the recognized whitespace characters to the US-ASCII
# whitespace characters.  The main reason for doing this is that
# some Unicode spaces (like \u00a0) are non-breaking whitespaces.
_whitespace = '\t\n\x0b\x0c\r '

class TextWrapper:
    """
    Object for wrapping/filling text.  The public interface consists of
    the wrap() and fill() methods; the other methods are just there for

            

Reported by Pylint.

Too many instance attributes (12/7)
Error

Line: 17 Column: 1

              # some Unicode spaces (like \u00a0) are non-breaking whitespaces.
_whitespace = '\t\n\x0b\x0c\r '

class TextWrapper:
    """
    Object for wrapping/filling text.  The public interface consists of
    the wrap() and fill() methods; the other methods are just there for
    subclasses to override in order to tweak the default behaviour.
    If you want to completely replace the main wrapping algorithm,

            

Reported by Pylint.

Too many arguments (11/5)
Error

Line: 115 Column: 5

                                               r'[\"\']?'           # optional end-of-quote
                                 r'\Z')               # end of chunk

    def __init__(self,
                 width=70,
                 initial_indent="",
                 subsequent_indent="",
                 expand_tabs=True,
                 replace_whitespace=True,

            

Reported by Pylint.

Too many branches (22/12)
Error

Line: 241 Column: 5

                      # cur_len will be zero, so the next line will be entirely
        # devoted to the long word that we can't handle right now.

    def _wrap_chunks(self, chunks):
        """_wrap_chunks(chunks : [string]) -> [string]

        Wrap a sequence of text chunks and return a list of lines of
        length 'self.width' or less.  (If 'break_long_words' is false,
        some lines may be longer than this.)  Chunks correspond roughly

            

Reported by Pylint.

Too many nested blocks (6/5)
Error

Line: 269 Column: 9

                      # from a stack of chucks.
        chunks.reverse()

        while chunks:

            # Start the list of chunks that will make up the current line.
            # cur_len is just the length of all the chunks in cur_line.
            cur_line = []
            cur_len = 0

            

Reported by Pylint.

Variable name "l" doesn't conform to snake_case naming style
Error

Line: 291 Column: 17

                              del chunks[-1]

            while chunks:
                l = len(chunks[-1])

                # Can at least squeeze this chunk onto the current line.
                if cur_len + l <= width:
                    cur_line.append(chunks.pop())
                    cur_len += l

            

Reported by Pylint.

Lib/turtledemo/colormixer.py
19 issues
No name 'mainloop' in module 'turtle'
Error

Line: 3 Column: 1

              # colormixer

from turtle import Screen, Turtle, mainloop

class ColorTurtle(Turtle):

    def __init__(self, x, y):
        Turtle.__init__(self)
        self.shape("turtle")

            

Reported by Pylint.

Unused argument 'x'
Error

Line: 28 Column: 21

                      self.pencolor("gray25")
        self.ondrag(self.shift)

    def shift(self, x, y):
        self.sety(max(0,min(y,1)))
        self._color[self.x] = self.ycor()
        self.fillcolor(self._color)
        setbgcolor()


            

Reported by Pylint.

Global variable 'green' undefined at the module level
Error

Line: 38 Column: 5

                  screen.bgcolor(red.ycor(), green.ycor(), blue.ycor())

def main():
    global screen, red, green, blue
    screen = Screen()
    screen.delay(0)
    screen.setworldcoordinates(-1, -0.3, 3, 1.3)

    red = ColorTurtle(0, .5)

            

Reported by Pylint.

Global variable 'screen' undefined at the module level
Error

Line: 38 Column: 5

                  screen.bgcolor(red.ycor(), green.ycor(), blue.ycor())

def main():
    global screen, red, green, blue
    screen = Screen()
    screen.delay(0)
    screen.setworldcoordinates(-1, -0.3, 3, 1.3)

    red = ColorTurtle(0, .5)

            

Reported by Pylint.

Global variable 'red' undefined at the module level
Error

Line: 38 Column: 5

                  screen.bgcolor(red.ycor(), green.ycor(), blue.ycor())

def main():
    global screen, red, green, blue
    screen = Screen()
    screen.delay(0)
    screen.setworldcoordinates(-1, -0.3, 3, 1.3)

    red = ColorTurtle(0, .5)

            

Reported by Pylint.

Global variable 'blue' undefined at the module level
Error

Line: 38 Column: 5

                  screen.bgcolor(red.ycor(), green.ycor(), blue.ycor())

def main():
    global screen, red, green, blue
    screen = Screen()
    screen.delay(0)
    screen.setworldcoordinates(-1, -0.3, 3, 1.3)

    red = ColorTurtle(0, .5)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # colormixer

from turtle import Screen, Turtle, mainloop

class ColorTurtle(Turtle):

    def __init__(self, x, y):
        Turtle.__init__(self)
        self.shape("turtle")

            

Reported by Pylint.

Missing class docstring
Error

Line: 5 Column: 1

              
from turtle import Screen, Turtle, mainloop

class ColorTurtle(Turtle):

    def __init__(self, x, y):
        Turtle.__init__(self)
        self.shape("turtle")
        self.resizemode("user")

            

Reported by Pylint.

Attribute name "x" doesn't conform to snake_case naming style
Error

Line: 14 Column: 9

                      self.shapesize(3,3,5)
        self.pensize(10)
        self._color = [0,0,0]
        self.x = x
        self._color[x] = y
        self.color(self._color)
        self.speed(0)
        self.left(90)
        self.pu()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 5

                      self.pencolor("gray25")
        self.ondrag(self.shift)

    def shift(self, x, y):
        self.sety(max(0,min(y,1)))
        self._color[self.x] = self.ycor()
        self.fillcolor(self._color)
        setbgcolor()


            

Reported by Pylint.

Lib/wsgiref/simple_server.py
19 issues
Instance of 'ServerHandler' has no 'log_request' member
Error

Line: 34 Column: 13

              
    def close(self):
        try:
            self.request_handler.log_request(
                self.status.split(' ',1)[0], self.bytes_sent
            )
        finally:
            SimpleHandler.close(self)


            

Reported by Pylint.

Attribute 'base_environ' defined outside __init__
Error

Line: 55 Column: 15

              
    def setup_environ(self):
        # Set up base environment
        env = self.base_environ = {}
        env['SERVER_NAME'] = self.server_name
        env['GATEWAY_INTERFACE'] = 'CGI/1.1'
        env['SERVER_PORT'] = str(self.server_port)
        env['REMOTE_HOST']=''
        env['CONTENT_LENGTH']=''

            

Reported by Pylint.

Attribute 'request_handler' defined outside __init__
Error

Line: 133 Column: 9

                          self.rfile, self.wfile, self.get_stderr(), self.get_environ(),
            multithread=False,
        )
        handler.request_handler = self      # backpointer for logging
        handler.run(self.server.get_app())



def demo_app(environ,start_response):

            

Reported by Pylint.

Constant name "server_version" doesn't conform to UPPER_CASE naming style
Error

Line: 23 Column: 1

              __all__ = ['WSGIServer', 'WSGIRequestHandler', 'demo_app', 'make_server']


server_version = "WSGIServer/" + __version__
sys_version = python_implementation() + "/" + sys.version.split()[0]
software_version = server_version + ' ' + sys_version


class ServerHandler(SimpleHandler):

            

Reported by Pylint.

Missing class docstring
Error

Line: 28 Column: 1

              software_version = server_version + ' ' + sys_version


class ServerHandler(SimpleHandler):

    server_software = software_version

    def close(self):
        try:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 53 Column: 5

                      HTTPServer.server_bind(self)
        self.setup_environ()

    def setup_environ(self):
        # Set up base environment
        env = self.base_environ = {}
        env['SERVER_NAME'] = self.server_name
        env['GATEWAY_INTERFACE'] = 'CGI/1.1'
        env['SERVER_PORT'] = str(self.server_port)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 63 Column: 5

                      env['CONTENT_LENGTH']=''
        env['SCRIPT_NAME'] = ''

    def get_app(self):
        return self.application

    def set_app(self,application):
        self.application = application


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 66 Column: 5

                  def get_app(self):
        return self.application

    def set_app(self,application):
        self.application = application



class WSGIRequestHandler(BaseHTTPRequestHandler):

            

Reported by Pylint.

Missing class docstring
Error

Line: 71 Column: 1

              


class WSGIRequestHandler(BaseHTTPRequestHandler):

    server_version = "WSGIServer/" + __version__

    def get_environ(self):
        env = self.server.base_environ.copy()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 75 Column: 5

              
    server_version = "WSGIServer/" + __version__

    def get_environ(self):
        env = self.server.base_environ.copy()
        env['SERVER_PROTOCOL'] = self.request_version
        env['SERVER_SOFTWARE'] = self.server_version
        env['REQUEST_METHOD'] = self.command
        if '?' in self.path:

            

Reported by Pylint.