Skip to content

Commit

Permalink
Merge branch 'main' into remove-redundant-object-subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Aug 10, 2023
2 parents e9834cb + ba9e475 commit 22bef47
Show file tree
Hide file tree
Showing 82 changed files with 264 additions and 667 deletions.
1 change: 0 additions & 1 deletion AutoDuck/py2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def ad_escape(s):


Print = __builtins__.__dict__["print"]
long = int


class DocInfo:
Expand Down
16 changes: 5 additions & 11 deletions Pythonwin/pywin/debugger/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@
from pywin.mfc import afxres, dialog, object, window
from pywin.tools import browser, hierlist

# import win32traceutil
if win32ui.UNICODE:
LVN_ENDLABELEDIT = commctrl.LVN_ENDLABELEDITW
else:
LVN_ENDLABELEDIT = commctrl.LVN_ENDLABELEDITA

from .dbgcon import *

LVN_ENDLABELEDIT = commctrl.LVN_ENDLABELEDITW
error = "pywin.debugger.error"


Expand Down Expand Up @@ -700,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
3 changes: 0 additions & 3 deletions Pythonwin/pywin/framework/editor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# This really isnt necessary with Scintilla, and scintilla
# is getting so deeply embedded that it was too much work.

import sys

import win32con
import win32ui

defaultCharacterFormat = (-402653169, 0, 200, 0, 0, 0, 49, "Courier New")
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def ColorizeInteractiveCode(self, cdoc, styleStart, stylePyStart):
return
state = styleStart
# As per comments in Colorize(), we work with the raw utf8
# bytes. To avoid too muych py3k pain, we treat each utf8 byte
# bytes. To avoid too much pain, we treat each utf8 byte
# as a latin-1 unicode character - we only use it to compare
# against ascii chars anyway...
chNext = cdoc[0:1].decode("latin-1")
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
17 changes: 7 additions & 10 deletions Pythonwin/pywin/framework/stdin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# any purpose.
"""Provides a class Stdin which can be used to emulate the regular old
sys.stdin for the PythonWin interactive window. Right now it just pops
up a raw_input() dialog. With luck, someone will integrate it into the
up a input() dialog. With luck, someone will integrate it into the
actual PythonWin interactive window someday.
WARNING: Importing this file automatically replaces sys.stdin with an
Expand All @@ -18,15 +18,12 @@
"""
import sys

try:
get_input_line = raw_input # py2x
except NameError:
get_input_line = input # py3k
get_input_line = input


class Stdin:
def __init__(self):
self.real_file = sys.stdin # NOTE: Likely to be None in py3k
self.real_file = sys.stdin # NOTE: Likely to be None
self.buffer = ""
self.closed = False

Expand Down Expand Up @@ -142,8 +139,8 @@ def readlines(self, *sizehint):
Sell you soul to the devil, baby
"""

def fake_raw_input(prompt=None):
"""Replacement for raw_input() which pulls lines out of global test_input.
def fake_input(prompt=None):
"""Replacement for input() which pulls lines out of global test_input.
For testing only!
"""
global test_input
Expand All @@ -157,7 +154,7 @@ def fake_raw_input(prompt=None):
raise EOFError()
return result

get_input_line = fake_raw_input
get_input_line = fake_input

# Some completely inadequate tests, just to make sure the code's not totally broken
try:
Expand All @@ -169,6 +166,6 @@ def fake_raw_input(prompt=None):
print(x.readline(3))
print(x.readlines())
finally:
get_input_line = raw_input
get_input_line = input
else:
sys.stdin = Stdin()
5 changes: 1 addition & 4 deletions Pythonwin/pywin/framework/toolmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ def HandleToolCommand(cmd, code):
import commctrl
from pywin.mfc import dialog

if win32ui.UNICODE:
LVN_ENDLABELEDIT = commctrl.LVN_ENDLABELEDITW
else:
LVN_ENDLABELEDIT = commctrl.LVN_ENDLABELEDITA
LVN_ENDLABELEDIT = commctrl.LVN_ENDLABELEDITW


class ToolMenuPropPage(dialog.PropertyPage):
Expand Down
15 changes: 2 additions & 13 deletions Pythonwin/pywin/idle/AutoIndent.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import sys
import tokenize

from pywin import default_scintilla_encoding

from . import PyParse

if sys.version_info < (3,):
# in py2k, tokenize() takes a 'token eater' callback, while
# generate_tokens is a generator that works with str objects.
token_generator = tokenize.generate_tokens
else:
# in py3k tokenize() is the generator working with 'byte' objects, and
# token_generator is the 'undocumented b/w compat' function that
# theoretically works with str objects - but actually seems to fail)
token_generator = tokenize.tokenize


class AutoIndent:
menudefs = [
Expand Down Expand Up @@ -516,7 +505,7 @@ def readline(self):
val = ""
else:
val = self.text.get(mark, mark + " lineend+1c")
# hrm - not sure this is correct in py3k - the source code may have
# hrm - not sure this is correct - the source code may have
# an encoding declared, but the data will *always* be in
# default_scintilla_encoding - so if anyone looks at the encoding decl
# in the source they will be wrong. I think. Maybe. Or something...
Expand All @@ -531,7 +520,7 @@ def run(self):
tokenize.tabsize = self.tabwidth
try:
try:
for typ, token, start, end, line in token_generator(self.readline):
for typ, token, start, end, line in tokenize.tokenize(self.readline):
if typ == NAME and token in OPENERS:
self.blkopenline = line
elif typ == INDENT and self.blkopenline:
Expand Down
6 changes: 1 addition & 5 deletions Pythonwin/pywin/idle/PyParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ def dump(*stuff):
_tran[ord(ch)] = ")"
for ch in "\"'\\\n#":
_tran[ord(ch)] = ch
# We are called with unicode strings, and str.translate is one of the few
# py2k functions which can't 'do the right thing' - so take care to ensure
# _tran is full of unicode...
_tran = "".join(_tran)
del ch


Expand Down Expand Up @@ -154,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.
9 changes: 1 addition & 8 deletions Pythonwin/pywin/mfc/activex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@

from . import window

# XXX - we are still "classic style" classes in py2x, so we need can't yet
# use 'type()' everywhere - revisit soon, as py2x will move to new-style too...
try:
from types import ClassType as new_type
except ImportError:
new_type = type # py3k


class Control(window.Wnd):
"""An ActiveX control base class. A new class must be derived from both
Expand Down Expand Up @@ -78,7 +71,7 @@ def MakeControlClass(controlClass, name=None):
"""
if name is None:
name = controlClass.__name__
return new_type("OCX" + name, (Control, controlClass), {})
return type("OCX" + name, (Control, controlClass), {})


def MakeControlInstance(controlClass, name=None):
Expand Down
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
21 changes: 5 additions & 16 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 Expand Up @@ -309,7 +298,7 @@ def GetSubList(self):
return ret


# In Python 1.6, strings and Unicode have builtin methods, but we dont really want to see these
# strings and Unicode have builtin methods, but we dont really want to see these
class HLIString(HLIPythonObject):
def IsExpandable(self):
return 0
Expand Down
Loading

0 comments on commit 22bef47

Please sign in to comment.