Skip to content

Commit

Permalink
Update Python2 string module usage (#2127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Sep 22, 2023
1 parent 03a8bb1 commit 22efab5
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 59 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
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
11 changes: 5 additions & 6 deletions win32/help/security_directories.html
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ <h3><A NAME="#Extend_Get_py">Python code</a></h3>
import os
import sys
import win32net
import string
import time
import copy
import getopt
Expand Down Expand Up @@ -383,7 +382,7 @@ <h3><A NAME="#Extend_Get_py">Python code</a></h3>
#get the server for the domain -- it has to be a primary dc
group=0
resume=0
sys_id=string.strip(sys_id)
sys_id=sys_id.strip()
if D_group.has_key(sys_id):
group=1
elif D_except.has_key(sys_id):
Expand All @@ -405,7 +404,7 @@ <h3><A NAME="#Extend_Get_py">Python code</a></h3>
def get_perm_base(file):
all_perms=fileperm.get_perms(file)
for (domain_id,mask) in all_perms.items():
(domain,sys_id)=string.split(domain_id,'\\',1)
(domain,sys_id)=domain_id.split('\\',1)
mask_name=get_mask(mask)
Results.append(file+','+sys_id+','+mask_name)

Expand All @@ -414,7 +413,7 @@ <h3><A NAME="#Extend_Get_py">Python code</a></h3>
perm_list.append(file)
all_perms=fileperm.get_perms(file)
for (domain_id,mask) in all_perms.items():
(domain,sys_id)=string.split(domain_id,'\\',1)
(domain,sys_id)=domain_id.split('\\',1)
print domain,sys_id
sys_id=str(sys_id)
mask_name=get_mask(mask)
Expand All @@ -435,8 +434,8 @@ <h3><A NAME="#Extend_Get_py">Python code</a></h3>
continue
all_perms=fileperm.get_perms(file)
for (domain_id,mask) in all_perms.items():
if string.find(domain_id,'\\')!=-1:
(domain,sys_id)=string.split(domain_id,'\\',1)
if domain_id.find('\\')!=-1:
(domain,sys_id)=domain_id.split('\\',1)
else:
sys_id=domain_id
mask_name=get_mask(mask)
Expand Down
3 changes: 1 addition & 2 deletions win32/scripts/VersionStamp/BrandProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# stamp DLL/EXE files with version information.

import os
import string
import sys

import bulkstamp
Expand Down Expand Up @@ -77,7 +76,7 @@ def usage(msg):
if opt == "-a":
bAuto = 1
if opt == "-f":
infile, outfile = string.split(val, "=", 2)
infile, outfile = val.split("=", 2)
stampFiles.append((infile, outfile))
if opt == "-d":
desc = val
Expand Down
9 changes: 4 additions & 5 deletions win32/scripts/VersionStamp/vssutil.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import string
import time
import traceback

Expand Down Expand Up @@ -37,7 +36,7 @@ def test(projectName):

def SubstituteInString(inString, evalEnv):
substChar = "$"
fields = string.split(inString, substChar)
fields = inString.split(substChar)
newFields = []
for i in range(len(fields)):
didSubst = 0
Expand All @@ -52,7 +51,7 @@ def SubstituteInString(inString, evalEnv):
print("Could not substitute", strVal)
if not didSubst:
newFields.append(strVal)
return string.join(map(str, newFields), "")
return "".join(map(str, newFields))


def SubstituteInFile(inName, outName, evalEnv):
Expand Down Expand Up @@ -102,7 +101,7 @@ def VssLog(project, linePrefix="", noLabels=5, maxItems=150):
)
if labelNum > noLabels:
break
return string.join(lines, "\n")
return "\n".join(lines)


def SubstituteVSSInFile(projectName, inName, outName):
Expand Down Expand Up @@ -171,7 +170,7 @@ def MakeNewBuildNo(project, buildDesc=None, auto=0, bRebrand=0):
oldBuild = "<None>"
else:
try:
buildNo = string.atoi(buildNo)
buildNo = int(buildNo)
if not bRebrand:
buildNo = buildNo + 1
buildNo = str(buildNo)
Expand Down
Loading

0 comments on commit 22efab5

Please sign in to comment.