Skip to content

Commit

Permalink
Cleanup unsupported python code (except for adodbapi) (mhammond#1990)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Aug 10, 2023
1 parent 630ffa3 commit ba9e475
Show file tree
Hide file tree
Showing 60 changed files with 139 additions and 339 deletions.
9 changes: 4 additions & 5 deletions Pythonwin/pywin/debugger/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,12 @@ def user_exception(self, frame, exc_info):
if self.get_option(OPT_STOP_EXCEPTIONS):
frame.f_locals["__exception__"] = exc_type, exc_value
print("Unhandled exception while debugging...")
# on both py2k and py3k, we may be called with exc_value
# We may be called with exc_value
# being the args to the exception, or it may already be
# instantiated (IOW, PyErr_Normalize() hasn't been
# called on the args). In py2k this is fine, but in
# py3k, traceback.print_exception fails. So on py3k
# we instantiate an exception instance to print.
if sys.version_info > (3,) and not isinstance(exc_value, BaseException):
# called on the args). traceback.print_exception fails.
# So we instantiate an exception instance to print.
if not isinstance(exc_value, BaseException):
# they are args - may be a single item or already a tuple
if not isinstance(exc_value, tuple):
exc_value = (exc_value,)
Expand Down
22 changes: 5 additions & 17 deletions Pythonwin/pywin/framework/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ def OnButHomePage(self, id, code):
)


def Win32RawInput(prompt=None):
"Provide raw_input() for gui apps"
def Win32Input(prompt=None):
"Provide input() for gui apps"
# flush stderr/out first.
try:
sys.stdout.flush()
Expand All @@ -416,22 +416,10 @@ def Win32RawInput(prompt=None):
return ret


def Win32Input(prompt=None):
"Provide input() for gui apps"
return eval(input(prompt))


def HookInput():
try:
raw_input
# must be py2x...
sys.modules["__builtin__"].raw_input = Win32RawInput
sys.modules["__builtin__"].input = Win32Input
except NameError:
# must be py3k
import code

sys.modules["builtins"].input = Win32RawInput
import code

sys.modules["builtins"].input = Win32Input


def HaveGoodGUI():
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/mdi_pychecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
## the PATH. Example pychecker.bat:
##
## REM pychecker.bat
## C:\bin\python.exe C:\PYTHON23\Lib\site-packages\pychecker\checker.py %1 %2 %3 %4 %5 %6 %7 %8 %9
## C:\bin\python.exe C:\PythonXX\Lib\site-packages\pychecker\checker.py %1 %2 %3 %4 %5 %6 %7 %8 %9
##
## Adding it as default module in PythonWin:
##
Expand Down
7 changes: 3 additions & 4 deletions Pythonwin/pywin/framework/scriptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def IsOnPythonPath(path):
# must check that the command line arg's path is in sys.path
for syspath in sys.path:
try:
# Python 1.5 and later allows an empty sys.path entry.
# sys.path can have an empty entry.
if syspath and win32ui.FullPath(syspath) == path:
return 1
except win32ui.error as details:
Expand Down Expand Up @@ -305,7 +305,7 @@ def RunScript(defName=None, defArgs=None, bShowDialog=1, debuggingType=None):
# ignores any encoding decls (bad!). If we use binary mode we get
# the raw bytes and Python looks at the encoding (good!) but \r\n
# chars stay in place so Python throws a syntax error (bad!).
# So: so the binary thing and manually normalize \r\n.
# So: do the binary thing and manually normalize \r\n.
try:
f = open(script, "rb")
except IOError as exc:
Expand Down Expand Up @@ -438,8 +438,7 @@ def ImportFile():
newPath = None
# note that some packages (*cough* email *cough*) use "lazy importers"
# meaning sys.modules can change as a side-effect of looking at
# module.__file__ - so we must take a copy (ie, items() in py2k,
# list(items()) in py3k)
# module.__file__ - so we must take a copy (ie, list(items()))
for key, mod in list(sys.modules.items()):
if getattr(mod, "__file__", None):
fname = mod.__file__
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/stdin.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def readlines(self, *sizehint):
"""

def fake_input(prompt=None):
"""Replacement for raw_input() which pulls lines out of global test_input.
"""Replacement for input() which pulls lines out of global test_input.
For testing only!
"""
global test_input
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/idle/PyParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def set_str(self, str):
# no way to tell the differences between output, >>> etc and
# user input. Indeed, IDLE's first output line makes the rest
# look like it's in an unclosed paren!:
# Python 1.5.2 (#0, Apr 13 1999, ...
# Python X.X.X (#0, Apr 13 1999, ...

def find_good_parse_start(self, use_ps1, is_char_in_string=None):
str, pos = self.str, None
Expand Down
13 changes: 6 additions & 7 deletions Pythonwin/pywin/idle/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ Pythonwin IDLE directory
------------------------

This directory contains IDLE extensions used by
Pythonwin. In ALL cases, the files in this directory that also appear
in the main IDLE directory should be indentical to the latest available
for IDLE.
Pythonwin. The files in this directory that also appear in the main IDLE
directory are intended be indentical to the latest available for IDLE.

Eg, If you have Python 1.5.2 installed, the files in this
directory will be later than the IDLE versions. If you use IDLE from
the CVS sources, then the files should be identical.
If you use IDLE from the CVS sources, then the files should be
identical. If you have a Python version installed that is more recent
than when this release was made, then you may notice differences.

Pythonwin will look for IDLE extensions first in this directory, then on
the global sys.path. Thus, if you have IDLE installed and run it from
the CVS sources, you may remove most of the extensions from this
directory, and the latest CVS version will then be used.
directory, and the latest CVS version will then be used.
5 changes: 3 additions & 2 deletions Pythonwin/pywin/mfc/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ def items(self):
def values(self):
return list(self.data.values())

# XXX - needs py3k work!
def has_key(self, key):
def __contains__(self, key):
return key in self.data

has_key = __contains__


class PrintDialog(Dialog):
"Base class for a print dialog"
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/mfc/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __getattr__(
if o is not None:
return getattr(o, attr)
# Only raise this error for non "internal" names -
# Python may be calling __len__, __nonzero__, etc, so
# Python may be calling __len__, __bool__, etc, so
# we dont want this exception
if attr[0] != "_" and attr[-1] != "_":
raise win32ui.error("The MFC object has died.")
Expand Down
19 changes: 4 additions & 15 deletions Pythonwin/pywin/tools/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,10 @@ def IsExpandable(self):
return 1

def GetSubList(self):
ret = []
# ret.append( MakeHLI( self.myobject.func_argcount, "Arg Count" ))
try:
ret.append(MakeHLI(self.myobject.func_argdefs, "Arg Defs"))
except AttributeError:
pass
try:
code = self.myobject.__code__
globs = self.myobject.__globals__
except AttributeError:
# must be py2.5 or earlier...
code = self.myobject.func_code
globs = self.myobject.func_globals
ret.append(MakeHLI(code, "Code"))
ret.append(MakeHLI(globs, "Globals"))
ret = [
MakeHLI(self.myobject.__code__, "Code"),
MakeHLI(self.myobject.__globals__, "Globals"),
]
self.InsertDocString(ret)
return ret

Expand Down
11 changes: 2 additions & 9 deletions Pythonwin/pywin/tools/hierlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# choice. However, you should investigate using the tree control directly
# to provide maximum flexibility (but with extra work).

import sys

import commctrl
import win32api
Expand Down Expand Up @@ -123,12 +122,8 @@ def DeleteAllItems(self):
def HierTerm(self):
# Dont want notifies as we kill the list.
parent = self.notify_parent # GetParentFrame()
if sys.version_info[0] < 3:
parent.HookNotify(None, commctrl.TVN_ITEMEXPANDINGA)
parent.HookNotify(None, commctrl.TVN_SELCHANGEDA)
else:
parent.HookNotify(None, commctrl.TVN_ITEMEXPANDINGW)
parent.HookNotify(None, commctrl.TVN_SELCHANGEDW)
parent.HookNotify(None, commctrl.TVN_ITEMEXPANDINGW)
parent.HookNotify(None, commctrl.TVN_SELCHANGEDW)
parent.HookNotify(None, commctrl.NM_DBLCLK)

self.DeleteAllItems()
Expand Down Expand Up @@ -351,11 +346,9 @@ def GetBitmapColumn(self):
def GetSelectedBitmapColumn(self):
return None # same as other

# for py3k/rich-comp sorting compatibility.
def __lt__(self, other):
# we want unrelated items to be sortable...
return id(self) < id(other)

# for py3k/rich-comp equality compatibility.
def __eq__(self, other):
return False
8 changes: 4 additions & 4 deletions com/win32com/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def __init__(self, oobj=None):
"__int__",
"__iter__",
"__len__",
"__nonzero__",
"__bool__",
]:
if hasattr(dispobj, maybe):
setattr(self, maybe, getattr(self, "__maybe" + maybe))
Expand Down Expand Up @@ -673,16 +673,16 @@ def __maybe__iter__(self):
def __maybe__len__(self):
return self.__dict__["_dispobj_"].__len__()

def __maybe__nonzero__(self):
return self.__dict__["_dispobj_"].__nonzero__()
def __maybe__bool__(self):
return self.__dict__["_dispobj_"].__bool__()


# A very simple VARIANT class. Only to be used with poorly-implemented COM
# objects. If an object accepts an arg which is a simple "VARIANT", but still
# is very pickly about the actual variant type (eg, isn't happy with a VT_I4,
# which it would get from a Python integer), you can use this to force a
# particular VT.
class VARIANT(object):
class VARIANT:
def __init__(self, vt, value):
self.varianttype = vt
self._value = value
Expand Down
9 changes: 2 additions & 7 deletions com/win32com/client/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import datetime
import string
import sys
from keyword import iskeyword

import pythoncom
Expand All @@ -30,8 +29,6 @@
# literals like a quote char and backslashes makes life a little painful to
# always render the string perfectly - so just punt and fall-back to a repr()
def _makeDocString(s):
if sys.version_info < (3,):
s = s.encode("mbcs")
return repr(s)


Expand Down Expand Up @@ -631,8 +628,7 @@ def _BuildArgList(fdesc, names):
while len(names) < numArgs:
names.append("arg%d" % (len(names),))
# As per BuildCallList(), avoid huge lines.
# Hack a "\n" at the end of every 5th name - "strides" would be handy
# here but don't exist in 2.2
# Hack a "\n" at the end of every 5th name
for i in range(0, len(names), 5):
names[i] = names[i] + "\n\t\t\t"
return "," + ", ".join(names)
Expand Down Expand Up @@ -667,7 +663,7 @@ def MakePublicAttributeName(className, is_global=False):
# it would get picked up below
className = "NONE"
elif iskeyword(className):
# most keywords are lower case (except True, False etc in py3k)
# most keywords are lower case (except True, False, etc)
ret = className.capitalize()
# but those which aren't get forced upper.
if ret == className:
Expand Down Expand Up @@ -769,7 +765,6 @@ def BuildCallList(
defArgVal = defUnnamedArg

argName = MakePublicAttributeName(argName)
# insanely long lines with an 'encoding' flag crashes python 2.4.0
# keep 5 args per line
# This may still fail if the arg names are insane, but that seems
# unlikely. See also _BuildArgList()
Expand Down
4 changes: 2 additions & 2 deletions com/win32com/client/combrowse.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def GetSubList(self):
HLIHeadingRegisterdTypeLibs(),
]

def __cmp__(self, other):
return cmp(self.name, other.name)
def __lt__(self, other):
return self.name < other.name


class HLICOM(browser.HLIPythonObject):
Expand Down
15 changes: 3 additions & 12 deletions com/win32com/client/genpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,7 @@ def WriteSinkEventMap(obj, stream):
# MI is used to join my writable helpers, and the OLE
# classes.
class WritableItem:
# __cmp__ used for sorting in py2x...
def __cmp__(self, other):
"Compare for sorting"
ret = cmp(self.order, other.order)
if ret == 0 and self.doc:
ret = cmp(self.doc[0], other.doc[0])
return ret

# ... but not used in py3k - __lt__ minimum needed there
def __lt__(self, other): # py3k variant
def __lt__(self, other):
if self.order == other.order:
return self.doc < other.doc
return self.order < other.order
Expand Down Expand Up @@ -747,12 +738,12 @@ def WriteClassBody(self, generator):
)
for line in ret:
print(line, file=stream)
# Also include a __nonzero__
# Also include a __bool__
print(
"\t#This class has a __len__ - this is needed so 'if object:' always returns TRUE.",
file=stream,
)
print("\tdef __nonzero__(self):", file=stream)
print("\tdef __bool__(self):", file=stream)
print("\t\treturn True", file=stream)


Expand Down
10 changes: 2 additions & 8 deletions com/win32com/client/makepy.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@

bForDemandDefault = 0 # Default value of bForDemand - toggle this to change the world - see also gencache.py

error = "makepy.error"


def usage():
sys.stderr.write(usageHelp)
Expand Down Expand Up @@ -407,7 +405,7 @@ def main():
elif o == "-d":
bForDemand = not bForDemand

except (getopt.error, error) as msg:
except getopt.error as msg:
sys.stderr.write(str(msg) + "\n")
usage()

Expand All @@ -427,12 +425,8 @@ def main():
path = os.path.dirname(outputName)
if path != "" and not os.path.exists(path):
os.makedirs(path)
if sys.version_info > (3, 0):
f = open(outputName, "wt", encoding="mbcs")
else:
import codecs # not available in py3k.
f = open(outputName, "wt", encoding="mbcs")

f = codecs.open(outputName, "w", "mbcs")
else:
f = None

Expand Down
4 changes: 2 additions & 2 deletions com/win32com/client/selecttlb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __getitem__(self, item):
return self.ver_desc
raise IndexError("Cant index me!")

def __lt__(self, other): # rich-cmp/py3k-friendly version
def __lt__(self, other):
me = (
(self.ver_desc or "").lower(),
(self.desc or "").lower(),
Expand All @@ -42,7 +42,7 @@ def __lt__(self, other): # rich-cmp/py3k-friendly version
)
return me < them

def __eq__(self, other): # rich-cmp/py3k-friendly version
def __eq__(self, other):
return (
(self.ver_desc or "").lower() == (other.ver_desc or "").lower()
and (self.desc or "").lower() == (other.desc or "").lower()
Expand Down
3 changes: 0 additions & 3 deletions com/win32com/demos/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pythoncom
import win32com.server.connect
import win32com.server.util
from win32com.server.exception import Exception

# This is the IID of the Events interface both Client and Server support.
IID_IConnectDemoEvents = pythoncom.MakeIID("{A4988850-49C3-11d0-AE5D-52342E000000}")
Expand Down Expand Up @@ -50,8 +49,6 @@ def __init__(self):
# A client must implement QI, and respond to a query for the Event interface.
# In addition, it must provide a COM object (which server.util.wrap) does.
def _query_interface_(self, iid):
import win32com.server.util

# Note that this seems like a necessary hack. I am responding to IID_IConnectDemoEvents
# but only creating an IDispatch gateway object.
if iid == IID_IConnectDemoEvents:
Expand Down
Loading

0 comments on commit ba9e475

Please sign in to comment.