Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete aliases except unicode-related in non-adodbapi code #2087

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 6 additions & 9 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,7 +139,7 @@ def readlines(self, *sizehint):
Sell you soul to the devil, baby
"""

def fake_raw_input(prompt=None):
def fake_input(prompt=None):
"""Replacement for raw_input() which pulls lines out of global test_input.
For testing only!
"""
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()
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
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
14 changes: 2 additions & 12 deletions com/win32com/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,10 @@ class object that derives from three classes:
# If the clsid was an object, get the clsid
clsid = disp_class.CLSID
# Create a new class that derives from 3 classes - the dispatch class, the event sink class and the user class.
# 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
events_class = getevents(clsid)
if events_class is None:
raise ValueError("This COM object does not support events.")
result_class = new_type(
result_class = type(
"COMEventClass",
(disp_class, events_class, user_event_class),
{"__setattr__": _event_setattr_},
Expand Down Expand Up @@ -401,14 +395,10 @@ def WithEvents(disp, user_event_class):
clsid = disp_class.CLSID
# Create a new class that derives from 2 classes - the event sink
# class and the user class.
try:
from types import ClassType as new_type
except ImportError:
new_type = type # py3k
events_class = getevents(clsid)
if events_class is None:
raise ValueError("This COM object does not support events.")
result_class = new_type("COMEventClass", (events_class, user_event_class), {})
result_class = type("COMEventClass", (events_class, user_event_class), {})
instance = result_class(disp) # This only calls the first base class __init__.
if hasattr(user_event_class, "__init__"):
user_event_class.__init__(instance)
Expand Down
32 changes: 16 additions & 16 deletions com/win32com/client/genpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@
# does not use this map at runtime - all Alias/Enum have already
# been translated.
mapVTToTypeString = {
pythoncom.VT_I2: "types.IntType",
pythoncom.VT_I4: "types.IntType",
pythoncom.VT_R4: "types.FloatType",
pythoncom.VT_R8: "types.FloatType",
pythoncom.VT_BSTR: "types.StringType",
pythoncom.VT_BOOL: "types.IntType",
pythoncom.VT_VARIANT: "types.TypeType",
pythoncom.VT_I1: "types.IntType",
pythoncom.VT_UI1: "types.IntType",
pythoncom.VT_UI2: "types.IntType",
pythoncom.VT_UI4: "types.IntType",
pythoncom.VT_I8: "types.LongType",
pythoncom.VT_UI8: "types.LongType",
pythoncom.VT_INT: "types.IntType",
pythoncom.VT_DATE: "pythoncom.PyTimeType",
pythoncom.VT_UINT: "types.IntType",
pythoncom.VT_I2: "int",
pythoncom.VT_I4: "int",
pythoncom.VT_R4: "float",
pythoncom.VT_R8: "float",
pythoncom.VT_BSTR: "str",
pythoncom.VT_BOOL: "int",
pythoncom.VT_VARIANT: "type",
pythoncom.VT_I1: "int",
pythoncom.VT_UI1: "int",
pythoncom.VT_UI2: "int",
pythoncom.VT_UI4: "int",
pythoncom.VT_I8: "int",
pythoncom.VT_UI8: "int",
pythoncom.VT_INT: "int",
pythoncom.VT_DATE: "datetime.date",
pythoncom.VT_UINT: "int",
}


Expand Down
3 changes: 1 addition & 2 deletions com/win32com/test/testPyComTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import win32com.client.connect
import win32timezone
import winerror
from pywin32_testutil import str2memory
from win32com.client import VARIANT, CastTo, DispatchBaseClass, constants
from win32com.test.util import CheckClean, RegisterPythonServer

Expand Down Expand Up @@ -264,7 +263,7 @@ def TestCommon(o, is_generated):
)

# and binary
TestApplyResult(o.SetBinSafeArray, (str2memory("foo\0bar"),), 7)
TestApplyResult(o.SetBinSafeArray, (memoryview(b"foo\0bar"),), 7)

progress("Checking properties")
o.LongProp = 3
Expand Down
16 changes: 5 additions & 11 deletions com/win32com/test/testShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
import struct
import sys

import win32timezone

try:
sys_maxsize = sys.maxsize # 2.6 and later - maxsize != maxint on 64bits
except AttributeError:
sys_maxsize = sys.maxint

import pythoncom
import pywintypes
import win32com.test.util
import win32con
import win32timezone
from win32com.shell import shell
from win32com.shell.shellcon import *
from win32com.storagecon import *
Expand Down Expand Up @@ -168,7 +162,7 @@ def testComplex(self):
ftCreationTime=ctime,
ftLastAccessTime=atime,
ftLastWriteTime=wtime,
nFileSize=sys_maxsize + 1,
nFileSize=sys.maxsize + 1,
)
self._testRT(d)

Expand All @@ -184,7 +178,7 @@ def testUnicode(self):
ftCreationTime=ctime,
ftLastAccessTime=atime,
ftLastWriteTime=wtime,
nFileSize=sys_maxsize + 1,
nFileSize=sys.maxsize + 1,
),
dict(
cFileName="foo2.txt",
Expand All @@ -194,7 +188,7 @@ def testUnicode(self):
ftCreationTime=ctime,
ftLastAccessTime=atime,
ftLastWriteTime=wtime,
nFileSize=sys_maxsize + 1,
nFileSize=sys.maxsize + 1,
),
dict(
cFileName="foo\xa9.txt",
Expand All @@ -204,7 +198,7 @@ def testUnicode(self):
ftCreationTime=ctime,
ftLastAccessTime=atime,
ftLastWriteTime=wtime,
nFileSize=sys_maxsize + 1,
nFileSize=sys.maxsize + 1,
),
]
s = shell.FILEGROUPDESCRIPTORAsString(d, 1)
Expand Down
5 changes: 2 additions & 3 deletions com/win32com/test/testvb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import win32com.client.dynamic
import win32com.client.gencache
import winerror
from pywin32_testutil import str2memory
from win32com.server.util import NewCollection, wrap
from win32com.test import util

Expand Down Expand Up @@ -86,8 +85,8 @@ def TestVB(vbtest, bUseGenerated):
vbtest.VariantProperty = 10
if vbtest.VariantProperty != 10:
raise error("Could not set the variant integer property correctly.")
vbtest.VariantProperty = str2memory("raw\0data")
if vbtest.VariantProperty != str2memory("raw\0data"):
vbtest.VariantProperty = memoryview(b"raw\0data")
if vbtest.VariantProperty != memoryview(b"raw\0data"):
raise error("Could not set the variant buffer property correctly.")
vbtest.StringProperty = "Hello from Python"
if vbtest.StringProperty != "Hello from Python":
Expand Down
21 changes: 8 additions & 13 deletions com/win32comext/mapi/mapiutil.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# General utilities for MAPI and MAPI objects.
# We used to use these old names from the 'types' module...
TupleType = tuple
ListType = list
IntType = int
import pythoncom
from pywintypes import TimeType

Expand Down Expand Up @@ -103,13 +100,13 @@ def GetProperties(obj, propList):
If the property fetch fails, the result is None.
"""
bRetList = 1
if not isinstance(propList, (TupleType, ListType)):
if not isinstance(propList, (tuple, list)):
bRetList = 0
propList = (propList,)
realPropList = []
rc = []
for prop in propList:
if not isinstance(prop, IntType): # Integer
if not isinstance(prop, int):
props = ((mapi.PS_PUBLIC_STRINGS, prop),)
propIds = obj.GetIDsFromNames(props, 0)
prop = mapitags.PROP_TAG(
Expand Down Expand Up @@ -145,19 +142,17 @@ def GetAllProperties(obj, make_tag_names=True):


_MapiTypeMap = {
type(0.0): mapitags.PT_DOUBLE,
type(0): mapitags.PT_I4,
type(b""): mapitags.PT_STRING8, # bytes
type(""): mapitags.PT_UNICODE, # str
float: mapitags.PT_DOUBLE,
int: mapitags.PT_I4,
bytes: mapitags.PT_STRING8,
str: mapitags.PT_UNICODE,
type(None): mapitags.PT_UNSPECIFIED,
# In Python 2.2.2, bool isn't a distinct type (type(1==1) is type(0)).
# (markh thinks the above is trying to say that in 2020, we probably *do*
# want bool in this map? :)
bool: mapitags.PT_BOOLEAN,
}


def SetPropertyValue(obj, prop, val):
if not isinstance(prop, IntType):
if not isinstance(prop, int):
props = ((mapi.PS_PUBLIC_STRINGS, prop),)
propIds = obj.GetIDsFromNames(props, mapi.MAPI_CREATE)
if val == (1 == 1) or val == (1 == 0):
Expand Down
25 changes: 8 additions & 17 deletions isapi/samples/redirector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@
# any excludes.

import sys

from isapi import isapicon, threaded_extension

try:
from urllib.request import urlopen
except ImportError:
# py3k spelling...
from urllib.request import urlopen
from urllib.request import urlopen

import win32api

from isapi import isapicon, threaded_extension

# sys.isapidllhandle will exist when we are loaded by the IIS framework.
# In this case we redirect our output to the win32traceutil collector.
if hasattr(sys, "isapidllhandle"):
Expand Down Expand Up @@ -84,15 +79,11 @@ def Dispatch(self, ecb):
print("Opening %s" % new_url)
fp = urlopen(new_url)
headers = fp.info()
# subtle py3k breakage: in py3k, str(headers) has normalized \r\n
# back to \n and also stuck an extra \n term. py2k leaves the
# \r\n from the server in tact and finishes with a single term.
if sys.version_info < (3, 0):
header_text = str(headers) + "\r\n"
else:
# take *all* trailing \n off, replace remaining with
# \r\n, then add the 2 trailing \r\n.
header_text = str(headers).rstrip("\n").replace("\n", "\r\n") + "\r\n\r\n"
# subtle breakage: str(headers) normalizes \r\n
# back to \n and also sticks an extra \n term.
# take *all* trailing \n off, replace remaining with
# \r\n, then add the 2 trailing \r\n.
header_text = str(headers).rstrip("\n").replace("\n", "\r\n") + "\r\n\r\n"
ecb.SendResponseHeaders("200 OK", header_text, False)
ecb.WriteClient(fp.read())
ecb.DoneWithSession()
Expand Down
5 changes: 2 additions & 3 deletions win32/Demos/BackupRead_BackupWrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import win32con
import win32file
import win32security
from pywin32_testutil import ob2memory
from win32com import storagecon

all_sd_info = (
Expand Down Expand Up @@ -115,7 +114,7 @@
open(tempfile + ":anotherstream").read() == open(outfile + ":anotherstream").read()
), "anotherstream contents differ !"
assert (
ob2memory(win32security.GetFileSecurity(tempfile, all_sd_info))[:]
== ob2memory(win32security.GetFileSecurity(outfile, all_sd_info))[:]
memoryview(win32security.GetFileSecurity(tempfile, all_sd_info))[:]
== memoryview(win32security.GetFileSecurity(outfile, all_sd_info))[:]
), "Security descriptors are different !"
## also should check Summary Info programatically
Loading