Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
No longer switch off getpass on import. Fixes #988 (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz authored May 21, 2019
1 parent 2ef2bd9 commit ba04a8e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 57 deletions.
13 changes: 0 additions & 13 deletions src/ptvsd/_vendored/pydevd/_pydev_bundle/fix_getpass.py

This file was deleted.

18 changes: 12 additions & 6 deletions src/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_console_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
import signal

try:
import cStringIO as StringIO #may not always be available @UnusedImport
import cStringIO as StringIO # may not always be available @UnusedImport
except:
try:
import StringIO #@Reimport
import StringIO # @Reimport
except:
import io as StringIO


# =======================================================================================================================
# BaseStdIn
# =======================================================================================================================
class BaseStdIn:

def __init__(self, original_stdin=sys.stdin, *args, **kwargs):
try:
self.encoding = sys.stdin.encoding
Expand All @@ -32,7 +34,7 @@ def __init__(self, original_stdin=sys.stdin, *args, **kwargs):
try:
self.errors = sys.stdin.errors # Who knew? sys streams have an errors attribute!
except:
#Not sure if it's available in all Python versions...
# Not sure if it's available in all Python versions...
pass

def readline(self, *args, **kwargs):
Expand Down Expand Up @@ -85,7 +87,7 @@ def readline(self, *args, **kwargs):
server = xmlrpclib.Server('http://%s:%s' % (self.host, self.client_port))
requested_input = server.RequestInput()
if not requested_input:
return '\n' #Yes, a readline must return something (otherwise we can get an EOFError on the input() call).
return '\n' # Yes, a readline must return something (otherwise we can get an EOFError on the input() call).
else:
# readline should end with '\n' (not doing so makes IPython 5 remove the last *valid* character).
requested_input += '\n'
Expand All @@ -98,6 +100,7 @@ def readline(self, *args, **kwargs):
def close(self, *args, **kwargs):
pass # expected in StdIn


#=======================================================================================================================
# DebugConsoleStdIn
#=======================================================================================================================
Expand Down Expand Up @@ -127,6 +130,7 @@ def readline(self, *args, **kwargs):


class CodeFragment:

def __init__(self, text, is_single_line=True):
self.text = text
self.is_single_line = is_single_line
Expand All @@ -141,6 +145,7 @@ def append(self, code_fragment):
# BaseInterpreterInterface
# =======================================================================================================================
class BaseInterpreterInterface:

def __init__(self, mainThread, connect_status_queue=None):
self.mainThread = mainThread
self.interruptable = False
Expand Down Expand Up @@ -511,6 +516,7 @@ def loadFullValue(self, seq, scope_attrs):
t.start()

def changeVariable(self, attr, value):

def do_change_variable():
Exec('%s=%s' % (attr, value), self.get_namespace(), self.get_namespace())

Expand Down Expand Up @@ -544,11 +550,10 @@ def do_connect_to_debugger():
# Try to import the packages needed to attach the debugger
import pydevd
from _pydev_imps._pydev_saved_modules import threading

except:
# This happens on Jython embedded in host eclipse
traceback.print_exc()
sys.stderr.write('pydevd is not available, cannot connect\n', )
sys.stderr.write('pydevd is not available, cannot connect\n')

from _pydevd_bundle.pydevd_constants import set_thread_id
from _pydev_bundle import pydev_localhost
Expand Down Expand Up @@ -604,6 +609,7 @@ def enableGui(self, guiname):
As with IPython, enabling multiple GUIs isn't an error, but
only the last one's main loop runs and it may not work
'''

def do_enable_gui():
from _pydev_bundle.pydev_versioncheck import versionok_for_gui
if versionok_for_gui():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'threading.py':LIB_FILE,
'dis.py':LIB_FILE,

#things from pydev that we don't want to trace
# things from pydev that we don't want to trace
'_pydev_execfile.py':PYDEV_FILE,
'__main__pydevd_gen_debug_adapter_protocol.py': PYDEV_FILE,
'_pydev_BaseHTTPServer.py': PYDEV_FILE,
Expand All @@ -41,7 +41,6 @@
'_pydev_uuid_old.py': PYDEV_FILE,
'_pydev_xmlrpclib.py': PYDEV_FILE,
'django_debug.py': PYDEV_FILE,
'fix_getpass.py': PYDEV_FILE,
'jinja2_debug.py': PYDEV_FILE,
'pycompletionserver.py': PYDEV_FILE,
'pydev_app_engine_debug_startup.py': PYDEV_FILE,
Expand Down
13 changes: 9 additions & 4 deletions src/ptvsd/_vendored/pydevd/build_tools/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import struct



def is_python_64bit():
return (struct.calcsize('P') == 8)


root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))


def get_cython_contents(filename):
if filename.endswith('.pyc'):
filename = filename[:-1]
Expand Down Expand Up @@ -47,7 +48,7 @@ def get_cython_contents(filename):

if strip == '#':
continue

assert strip.startswith('# '), 'Line inside # IFDEF CYTHON must start with "# ". Found: %s' % (strip,)
new_contents.append(line.replace('# ', '', 1))

Expand All @@ -60,9 +61,9 @@ def get_cython_contents(filename):

assert state == 'regular', 'Error: # IFDEF CYTHON found without # ENDIF'


return ''.join(new_contents)


def _generate_cython_from_files(target, modules):
contents = ['''from __future__ import print_function
Expand All @@ -78,6 +79,7 @@ def _generate_cython_from_files(target, modules):
with open(target, 'w') as stream:
stream.write(''.join(contents))


def generate_dont_trace_files():
template = '''# Important: Autogenerated file.
Expand All @@ -100,7 +102,7 @@ def generate_dont_trace_files():
'threading.py':LIB_FILE,
'dis.py':LIB_FILE,
#things from pydev that we don't want to trace
# things from pydev that we don't want to trace
'_pydev_execfile.py':PYDEV_FILE,
%(pydev_files)s
}
Expand Down Expand Up @@ -163,13 +165,15 @@ def generate_dont_trace_files():
with open(os.path.join(root_dir, '_pydevd_bundle', 'pydevd_dont_trace_files.py'), 'w') as stream:
stream.write(contents)


def remove_if_exists(f):
try:
if os.path.exists(f):
os.remove(f)
except:
import traceback;traceback.print_exc()


def generate_cython_module():
remove_if_exists(os.path.join(root_dir, '_pydevd_bundle', 'pydevd_cython.pyx'))

Expand All @@ -187,6 +191,7 @@ def generate_cython_module():
else:
os.environ['PYDEVD_USE_CYTHON'] = curr


if __name__ == '__main__':
generate_dont_trace_files()
generate_cython_module()
63 changes: 34 additions & 29 deletions src/ptvsd/_vendored/pydevd/pydevconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from _pydevd_bundle.pydevd_constants import INTERACTIVE_MODE_AVAILABLE, dict_keys

import traceback
from _pydev_bundle import fix_getpass, pydev_log
fix_getpass.fix_getpass()
from _pydev_bundle import pydev_log

from _pydevd_bundle import pydevd_vars, pydevd_save_locals

Expand Down Expand Up @@ -185,36 +184,43 @@ def init_mpl_in_console(interpreter):

if sys.platform != 'win32':

def pid_exists(pid):
# Note that this function in the face of errors will conservatively consider that
# the pid is still running (because we'll exit the current process when it's
# no longer running, so, we need to be 100% sure it actually exited).
if not hasattr(os, 'kill'): # Jython may not have it.

import errno
if pid == 0:
# According to "man 2 kill" PID 0 has a special meaning:
# it refers to <<every process in the process group of the
# calling process>> so we don't want to go any further.
# If we get here it means this UNIX platform *does* have
# a process with id 0.
def pid_exists(pid):
return True
try:
os.kill(pid, 0)
except OSError as err:
if err.errno == errno.ESRCH:
# ESRCH == No such process
return False
elif err.errno == errno.EPERM:
# EPERM clearly means there's a process to deny access to

else:

def pid_exists(pid):
# Note that this function in the face of errors will conservatively consider that
# the pid is still running (because we'll exit the current process when it's
# no longer running, so, we need to be 100% sure it actually exited).

import errno
if pid == 0:
# According to "man 2 kill" PID 0 has a special meaning:
# it refers to <<every process in the process group of the
# calling process>> so we don't want to go any further.
# If we get here it means this UNIX platform *does* have
# a process with id 0.
return True
try:
os.kill(pid, 0)
except OSError as err:
if err.errno == errno.ESRCH:
# ESRCH == No such process
return False
elif err.errno == errno.EPERM:
# EPERM clearly means there's a process to deny access to
return True
else:
# According to "man 2 kill" possible error values are
# (EINVAL, EPERM, ESRCH) therefore we should never get
# here. If we do, although it's an error, consider it
# exists (see first comment in this function).
return True
else:
# According to "man 2 kill" possible error values are
# (EINVAL, EPERM, ESRCH) therefore we should never get
# here. If we do, although it's an error, consider it
# exists (see first comment in this function).
return True
else:
return True

else:

Expand Down Expand Up @@ -304,8 +310,7 @@ def process_exec_queue(interpreter):
except SystemExit:
raise
except:
type, value, tb = sys.exc_info()
traceback.print_exception(type, value, tb, file=sys.__stderr__)
pydev_log.exception('Error processing queue on pydevconsole.')
exit()


Expand Down
3 changes: 0 additions & 3 deletions src/ptvsd/_vendored/pydevd/pydevd.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import traceback
import weakref

from _pydev_bundle import fix_getpass
from _pydev_bundle import pydev_imports, pydev_log
from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding
from _pydev_bundle.pydev_is_thread_alive import is_thread_alive
Expand Down Expand Up @@ -2327,8 +2326,6 @@ def main():
pid = ''
sys.stderr.write("pydev debugger: starting%s\n" % pid)

fix_getpass.fix_getpass()

pydev_log.debug("Executing file %s" % setup['file'])
pydev_log.debug("arguments: %s" % str(sys.argv))

Expand Down

0 comments on commit ba04a8e

Please sign in to comment.