Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mhammond/pywin32 into distu…
Browse files Browse the repository at this point in the history
…tils-direct-replacements
  • Loading branch information
Avasam committed Nov 1, 2023
2 parents 4c10d3a + 378fcb7 commit 5cf6729
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 86 deletions.
6 changes: 3 additions & 3 deletions Pythonwin/pywin/framework/bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def MatchDocType(self, fileName, fileType):
# magic=file.readline()
# if magic <> "P6\n":
# raise TypeError, "The file is not a PPM format file"
# rowcollist=string.split(file.readline())
# cols=string.atoi(rowcollist[0])
# rows=string.atoi(rowcollist[1])
# rowcollist=file.readline().split()
# cols=int(rowcollist[0])
# rows=int(rowcollist[1])
# file.readline() # whats this one?
# self.bitmap.LoadPPMFile(file,(cols,rows))

Expand Down
2 changes: 0 additions & 2 deletions Pythonwin/pywin/idle/PyParse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import string
import sys

# Reason last stmt is continued (or C_NONE if it's not).
Expand Down Expand Up @@ -362,7 +361,6 @@ def get_continuation_type(self):
# if continuation is C_BRACKET, index of last open bracket

def _study2(self):
_ws = string.whitespace
if self.study_level >= 2:
return
self._study1()
Expand Down
4 changes: 2 additions & 2 deletions com/help/active_directory.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ <h3><a name="discovery">Discovery</a></h3>

for i in servers:
ex_servers.append(i.cn)
print '\texchange servers',string.join(ex_servers)
print '\texchange servers'," ".join(ex_servers)

ex_first_store='CN=First Storage Group,CN=InformationStore,CN=%s,CN=Servers,CN=%s,%s'%(ex_servers[-1],admin_grp,ex_admin_grps)

ex_stores=[]

for i in win32com.client.GetObject('LDAP://'+ex_first_store):
ex_stores.append('cn='+i.cn+','+ex_first_store)
print '\tExchange stores:',string.join(ex_stores,"',")
print '\tExchange stores:',"',".join(ex_stores)
</code>

<h3><a name="opends">Making the object</a></h3>
Expand Down
6 changes: 3 additions & 3 deletions com/help/adsi.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ <h3><a name="dlist"></A>Recursively listing all unique members of a distribution
dsobj = ldap.OpenDSObject(path,logon_ex,password,0)
dsobj.Getinfo()
if dsobj.Class=='organizationalPerson':
user_dict[string.capitalize(dsobj.cn)]=dsobj.uid
user_dict[dsobj.cn.capitalize()]=dsobj.uid
elif dsobj.Class=='groupOfNames':
for i in dsobj.Members():
if i.Class=='organizationalPerson':
user_dict[string.capitalize(i.cn)]=i.uid
user_dict[i.cn.capitalize()]=i.uid
elif type(i.member)==types.TupleType:
for j in i.member:
newpath='LDAP://'+server+'/'+j
Expand All @@ -241,7 +241,7 @@ <h3><a name="dlist"></A>Recursively listing all unique members of a distribution
newpath='LDAP://'+server+'/'+i.member
getmembers(newpath)
elif dsobj.Class=='Remote-Address':
User_dict[string.capitalize(dsobj.cn)]=dsobj.uid
User_dict[dsobj.cn.capitalize()]=dsobj.uid
elif dsobj.Class=='Public-Folder':
pass
else:
Expand Down
3 changes: 1 addition & 2 deletions com/win32com/makegw/makegwenum.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
# INTERNAL FUNCTIONS
#
#
import string


def is_interface_enum(enumtype):
return not (enumtype[0] in string.uppercase and enumtype[2] in string.uppercase)
return not (enumtype[0].isupper() and enumtype[2].isupper())


def _write_enumifc_cpp(f, interface):
Expand Down
5 changes: 2 additions & 3 deletions com/win32com/test/testDCOM.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
The Python.Interpreter object must be installed on the local machine,
but no special DCOM configuration should be necessary.
"""
import string
import sys

# NOTE: If you configured the object locally using dcomcnfg, you could
Expand All @@ -23,7 +22,7 @@


def test(serverName):
if string.lower(serverName) == string.lower(win32api.GetComputerName()):
if serverName.lower() == win32api.GetComputerName().lower():
print("You must specify a remote server name, not the local machine!")
return

Expand All @@ -34,7 +33,7 @@ def test(serverName):
ob = win32com.client.DispatchEx("Python.Interpreter", serverName, clsctx=clsctx)
ob.Exec("import win32api")
actualName = ob.Eval("win32api.GetComputerName()")
if string.lower(serverName) != string.lower(actualName):
if serverName.lower() != actualName.lower():
print(
"Error: The object created on server '%s' reported its name as '%s'"
% (serverName, actualName)
Expand Down
9 changes: 4 additions & 5 deletions com/win32comext/adsi/demos/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import string
import sys

import pythoncom
Expand Down Expand Up @@ -31,12 +30,12 @@ def DumpRoot():
# Reading attributeSchema and classSchema Objects
def _DumpClass(child):
attrs = "Abstract lDAPDisplayName schemaIDGUID schemaNamingContext attributeSyntax oMSyntax"
_DumpTheseAttributes(child, string.split(attrs))
_DumpTheseAttributes(child, attrs.split())


def _DumpAttribute(child):
attrs = "lDAPDisplayName schemaIDGUID adminDescription adminDisplayName rDNAttID defaultHidingValue defaultObjectCategory systemOnly defaultSecurityDescriptor"
_DumpTheseAttributes(child, string.split(attrs))
_DumpTheseAttributes(child, attrs.split())


def _DumpTheseAttributes(child, attrs):
Expand Down Expand Up @@ -144,15 +143,15 @@ def DumpSchema2():
schema = ADsGetObject(path, IID_IADsContainer)
nclass = nprop = nsyntax = 0
for item in schema:
item_class = string.lower(item.Class)
item_class = item.Class.lower()
if item_class == "class":
items = []
if item.Abstract:
items.append("Abstract")
if item.Auxiliary:
items.append("Auxiliary")
# if item.Structural: items.append("Structural")
desc = string.join(items, ", ")
desc = ", ".join(items)
import win32com.util

iid_name = win32com.util.IIDToInterfaceName(item.PrimaryInterface)
Expand Down
7 changes: 3 additions & 4 deletions com/win32comext/axdebug/debugger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import string
import sys

import pythoncom
Expand Down Expand Up @@ -46,7 +45,7 @@ def BuildModule(module, built_nodes, rootNode, create_node_fn, create_node_args)
keep = module.__name__
keep = keep and (built_nodes.get(module) is None)
if keep and hasattr(module, "__file__"):
keep = string.lower(os.path.splitext(module.__file__)[1]) not in [
keep = os.path.splitext(module.__file__)[1].lower() not in [
".pyd",
".dll",
]
Expand All @@ -59,10 +58,10 @@ def BuildModule(module, built_nodes, rootNode, create_node_fn, create_node_args)
node.realNode = realNode

# Split into parent nodes.
parts = string.split(module.__name__, ".")
parts = module.__name__.split(".")
if parts[-1][:8] == "__init__":
parts = parts[:-1]
parent = string.join(parts[:-1], ".")
parent = ".".join(parts[:-1])
parentNode = rootNode
if parent:
parentModule = sys.modules[parent]
Expand Down
5 changes: 2 additions & 3 deletions com/win32comext/axdebug/expressions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import io
import string
import sys
import traceback
from pprint import pprint
Expand All @@ -15,7 +14,7 @@
def MakeNiceString(ob):
stream = io.StringIO()
pprint(ob, stream)
return string.strip(stream.getvalue())
return stream.getvalue().strip()


class ProvideExpressionContexts(gateways.ProvideExpressionContexts):
Expand Down Expand Up @@ -65,7 +64,7 @@ def Start(self, callback):
sys.exc_info()[0], sys.exc_info()[1]
)
# l is a list of strings with trailing "\n"
self.result = string.join((s[:-1] for s in l), "\n")
self.result = "\n".join(s[:-1] for s in l)
self.hresult = winerror.E_FAIL
finally:
self.isComplete = 1
Expand Down
4 changes: 2 additions & 2 deletions com/win32comext/axscript/demos/client/ie/calc.htm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
PendingOp = NullOp
else:
FlagNewNum = 1
Accum = PendingOp( Accum, string.atof(ReadOut) )
Accum = PendingOp( Accum, float(ReadOut) )
ax.document.Keypad.ReadOut.Value = str(Accum)
PendingOp = fn

Expand All @@ -65,7 +65,7 @@
ClearEntry_OnClick()

def Neg_OnClick():
ax.document.Keypad.ReadOut.Value = str(-string.atof(ax.document.Keypad.ReadOut.Value))
ax.document.Keypad.ReadOut.Value = str(-float(ax.document.Keypad.ReadOut.Value))
</SCRIPT>


Expand Down
2 changes: 1 addition & 1 deletion com/win32comext/axscript/server/axsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, objModel={}, engine=None, lcid=0):
self.lcid = lcid
self.objModel = {}
for name, object in objModel.items():
# Gregs code did string.lower this - I think that is callers job if he wants!
# Gregs code did str.lower this - I think that is callers job if he wants!
self.objModel[name] = object

self.engine = None
Expand Down
50 changes: 23 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@
"""
# Originally by Thomas Heller, started in 2000 or so.
import glob
import logging
import os
import platform
import re
import shutil
import subprocess
import sys
import winreg
import logging
from pathlib import Path
from tempfile import gettempdir
from typing import Iterable, List, Tuple, Union

# setuptools must be imported before distutils because it monkey-patches it.
# distutils is also removed in Python 3.12 and deprecated with setuptools
from setuptools import Extension
from setuptools import setup
from setuptools.command.build_ext import build_ext
from setuptools import Extension, setup
from setuptools.command.build import build
from setuptools.command.build_ext import build_ext
from setuptools.command.install import install
from setuptools.command.install_lib import install_lib

from distutils.command.install_data import install_data

# https://github.com/pypa/setuptools/pull/4069
from distutils.dep_util import newer_group
from distutils.filelist import FileList
from tempfile import gettempdir
from distutils.command.install_data import install_data
from distutils.command.install_lib import install_lib
from distutils.core import Extension

# some modules need a static CRT to avoid problems caused by them having a
# manifest.
Expand Down Expand Up @@ -2122,41 +2123,36 @@ def finalize_options(self):
swig_include_files = "mapilib adsilib".split()


# Helper to allow our script specifications to include wildcards.
def expand_modules(module_dir):
flist = FileList()
flist.findall(module_dir)
flist.include_pattern("*.py", anchor=0)
return [os.path.splitext(name)[0] for name in flist.files]
def expand_modules(module_dir: Union[str, os.PathLike]):
"""Helper to allow our script specifications to include wildcards."""
return [str(path.with_suffix("")) for path in Path(module_dir).rglob("*.py")]


# NOTE: somewhat counter-intuitively, a result list a-la:
# [('Lib/site-packages\\pythonwin', ('pythonwin/license.txt',)),]
# will 'do the right thing' in terms of installing licence.txt into
# 'Lib/site-packages/pythonwin/licence.txt'. We exploit this to
# get 'com/win32com/whatever' installed to 'win32com/whatever'
def convert_data_files(files):
ret = []
def convert_data_files(files: Iterable[str]):
ret: List[Tuple[str, Tuple[str]]] = []
for file in files:
file = os.path.normpath(file)
if file.find("*") >= 0:
flist = FileList()
flist.findall(os.path.dirname(file))
flist.include_pattern(os.path.basename(file), anchor=0)
# We never want CVS
flist.exclude_pattern(re.compile(r".*\\CVS\\"), is_regex=1, anchor=0)
flist.exclude_pattern("*.pyc", anchor=0)
flist.exclude_pattern("*.pyo", anchor=0)
if not flist.files:
files_use = (
str(path)
for path in Path(file).parent.rglob(os.path.basename(file))
# We never want CVS
if not ("\\CVS\\" in file or path.suffix in {".pyc", ".pyo"})
)
if not files_use:
raise RuntimeError("No files match '%s'" % file)
files_use = flist.files
else:
if not os.path.isfile(file):
raise RuntimeError("No file '%s'" % file)
files_use = (file,)
for fname in files_use:
path_use = os.path.dirname(fname)
if path_use.startswith("com/") or path_use.startswith("com\\"):
if path_use.startswith("com\\"):
path_use = path_use[4:]
ret.append((path_use, (fname,)))
return ret
Expand Down Expand Up @@ -2253,8 +2249,8 @@ def convert_optional_data_files(files):
if "bdist_wininst" in sys.argv:
# fixup https://github.com/pypa/setuptools/issues/3284
def maybe_fixup_exes():
from distutils.command import bdist_wininst
import site
from distutils.command import bdist_wininst

# setuptools can't find .exe stubs in `site-packages/setuptools/_distutils`
# but they might exist in the original `lib/distutils`.
Expand Down
18 changes: 8 additions & 10 deletions win32/help/event.d
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def date2sec(self,evt_date):
reg_result=regexp.search(evt_date)
date=reg_result.group(1)
the_time=reg_result.group(2)
(mon,day,yr)=map(lambda x: string.atoi(x),string.split(date,'/'))
(hr,min,sec)=map(lambda x: string.atoi(x),string.split(the_time,':'))
(mon,day,yr)=map(lambda x: int(x),date.split('/'))
(hr,min,sec)=map(lambda x: int(x),the_time.split(':'))
tup=[yr,mon,day,hr,min,sec,0,0,0]
sec=time.mktime(tup)
return sec
Expand All @@ -86,7 +86,6 @@ import win32con
import winerror
import time
import re
import string
import sys
import traceback
Expand All @@ -99,8 +98,8 @@ def date2sec(evt_date):
reg_result=regexp.search(evt_date)
date=reg_result.group(1)
the_time=reg_result.group(2)
(mon,day,yr)=map(lambda x: string.atoi(x),string.split(date,'/'))
(hr,min,sec)=map(lambda x: string.atoi(x),string.split(the_time,':'))
(mon,day,yr)=map(lambda x: int(x),date.split('/'))
(hr,min,sec)=map(lambda x: int(x),the_time.split(':'))
tup=[yr,mon,day,hr,min,sec,0,0,0]
sec=time.mktime(tup)
Expand Down Expand Up @@ -146,7 +145,7 @@ try:
evt_id=str(winerror.HRESULT_CODE(ev_obj.EventID))
evt_type=str(evt_dict[ev_obj.EventType])
msg = str(win32evtlogutil.SafeFormatMessage(ev_obj, logtype))
print string.join((the_time,computer,src,cat,record,evt_id,evt_type,msg[0:15]),':')
print(':'.join((the_time,computer,src,cat,record,evt_id,evt_type,msg[0:15])))
if seconds < begin_sec-28800: break #get out of while loop as well
win32evtlog.CloseEventLog(hand)
Expand Down Expand Up @@ -275,7 +274,6 @@ import win32con
import winerror
import time
import re
import string
import sys
import threading
import traceback
Expand Down Expand Up @@ -323,7 +321,7 @@ class thread_it ( threading.Thread ) :
evt_id=str(winerror.HRESULT_CODE(ev_obj.EventID))
evt_type=str(evt_dict[ev_obj.EventType])
msg = str(win32evtlogutil.SafeFormatMessage(ev_obj, logtype))
results=string.join((now_time,the_time,computer,src,cat,record,evt_id,evt_type,msg[0:15]),':')
results=':'.join((now_time,the_time,computer,src,cat,record,evt_id,evt_type,msg[0:15]))
self.data.append(results)
if seconds < begin_sec-28800: break
win32evtlog.CloseEventLog(hand)
Expand All @@ -340,8 +338,8 @@ class thread_it ( threading.Thread ) :
date=reg_result.group(1)
the_time=reg_result.group(2)
(mon,day,yr)=map(lambda x: string.atoi(x),string.split(date,'/'))
(hr,min,sec)=map(lambda x: string.atoi(x),string.split(the_time,':'))
(mon,day,yr)=map(lambda x: int(x),date.split('/'))
(hr,min,sec)=map(lambda x: int(x),the_time.split(':'))
tup=[yr,mon,day,hr,min,sec,0,0,0]
sec=time.mktime(tup)
Expand Down
Loading

0 comments on commit 5cf6729

Please sign in to comment.