Update of /cvsroot/pywin32/pywin32/com/win32com/client
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14888/com/win32com/client
Modified Files:
Tag: py3k
__init__.py build.py dynamic.py gencache.py genpy.py makepy.py
Log Message:
Merge various changes from trunk and py3k-integration bzr branch
Index: makepy.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/makepy.py,v
retrieving revision 1.25.2.3
retrieving revision 1.25.2.4
diff -C2 -d -r1.25.2.3 -r1.25.2.4
*** makepy.py 31 Aug 2008 18:46:46 -0000 1.25.2.3
--- makepy.py 26 Nov 2008 07:17:39 -0000 1.25.2.4
***************
*** 255,258 ****
--- 255,260 ----
for typelib, info in typelibs:
+ gen = genpy.Generator(typelib, info.dll, progress, bUnicodeToString=bUnicodeToString, bBuildHidden=bBuildHidden)
+
if file is None:
this_name = gencache.GetGeneratedFileName(info.clsid, info.lcid, info.major, info.minor)
***************
*** 270,292 ****
else:
outputName = full_name + ".py"
! # generate to a temp file (so errors don't leave a 1/2
! # generated file) and one which can handle unicode!
! try:
! os.unlink(outputName)
! except os.error:
! pass
! encoding = 'mbcs' # could make this a param.
! fileUse = open(outputName + ".temp", "wt", encoding=encoding)
progress.LogBeginGenerate(outputName)
else:
fileUse = file
! gen = genpy.Generator(typelib, info.dll, progress, bUnicodeToString=bUnicodeToString, bBuildHidden=bBuildHidden)
!
! gen.generate(fileUse, bForDemand)
!
! if file is None:
! fileUse.close()
! os.rename(outputName + ".temp", outputName)
if bToGenDir:
progress.SetDescription("Importing module")
--- 272,287 ----
else:
outputName = full_name + ".py"
! fileUse = gen.open_writer(outputName)
progress.LogBeginGenerate(outputName)
else:
fileUse = file
! worked = False
! try:
! gen.generate(fileUse, bForDemand)
! worked = True
! finally:
! if file is None:
! gen.finish_writer(outputName, fileUse, worked)
if bToGenDir:
progress.SetDescription("Importing module")
Index: dynamic.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/dynamic.py,v
retrieving revision 1.22.2.3
retrieving revision 1.22.2.4
diff -C2 -d -r1.22.2.3 -r1.22.2.4
*** dynamic.py 3 Oct 2008 01:09:55 -0000 1.22.2.3
--- dynamic.py 26 Nov 2008 07:17:39 -0000 1.22.2.4
***************
*** 16,20 ****
--- 16,23 ----
"""
+ import sys
import traceback
+ import types
+
import pythoncom
import winerror
***************
*** 22,26 ****
- import types
from pywintypes import IIDType
--- 25,28 ----
***************
*** 63,73 ****
print()
# get the type objects for IDispatch and IUnknown
dispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]
iunkType = pythoncom.TypeIIDs[pythoncom.IID_IUnknown]
_defaultDispatchItem=build.DispatchItem
def _GetGoodDispatch(IDispatch, clsctx = pythoncom.CLSCTX_SERVER):
! if isinstance(IDispatch, (str, IIDType)):
try:
IDispatch = pythoncom.connect(IDispatch)
--- 65,83 ----
print()
+ # A helper to create method objects on the fly
+ if sys.version_info > (3,0):
+ def MakeMethod(func, inst, cls):
+ return types.MethodType(func, inst) # class not needed in py3k
+ else:
+ MakeMethod = types.MethodType # all args used in py2k.
+
# get the type objects for IDispatch and IUnknown
dispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]
iunkType = pythoncom.TypeIIDs[pythoncom.IID_IUnknown]
+ _GoodDispatchTypes=(str, IIDType, unicode)
_defaultDispatchItem=build.DispatchItem
def _GetGoodDispatch(IDispatch, clsctx = pythoncom.CLSCTX_SERVER):
! if isinstance(IDispatch, _GoodDispatchTypes):
try:
IDispatch = pythoncom.connect(IDispatch)
***************
*** 169,173 ****
def __bool__(self):
! return 1 # ie "if object:" should always be "true" - without this, __len__ is tried.
# _Possibly_ want to defer to __len__ if available, but Im not sure this is
# desirable???
--- 179,183 ----
def __bool__(self):
! return True # ie "if object:" should always be "true" - without this, __len__ is tried.
# _Possibly_ want to defer to __len__ if available, but Im not sure this is
# desirable???
***************
*** 300,304 ****
# Save the function in map.
fn = self._builtMethods_[name] = tempNameSpace[name]
! newMeth = types.MethodType(fn, self)
return newMeth
except:
--- 310,314 ----
# Save the function in map.
fn = self._builtMethods_[name] = tempNameSpace[name]
! newMeth = MakeMethod(fn, self, self.__class__)
return newMeth
except:
***************
*** 310,314 ****
"""Cleanup object - like a close - to force cleanup when you dont
want to rely on Python's reference counting."""
! for childCont in list(self._mapCachedItems_.values()):
childCont._Release_()
self._mapCachedItems_ = {}
--- 320,324 ----
"""Cleanup object - like a close - to force cleanup when you dont
want to rely on Python's reference counting."""
! for childCont in self._mapCachedItems_.itervalues():
childCont._Release_()
self._mapCachedItems_ = {}
***************
*** 434,438 ****
# If a known method, create new instance and return.
try:
! return types.MethodType(self._builtMethods_[attr], self)
except KeyError:
pass
--- 444,448 ----
# If a known method, create new instance and return.
try:
! return MakeMethod(self._builtMethods_[attr], self, self.__class__)
except KeyError:
pass
***************
*** 485,489 ****
self._olerepr_.mapFuncs[attr] = retEntry
return self._make_method_(attr)
! raise pythoncom.com_error(details)
debug_attr_print("OLE returned ", ret)
return self._get_good_object_(ret)
--- 495,499 ----
self._olerepr_.mapFuncs[attr] = retEntry
return self._make_method_(attr)
! raise
debug_attr_print("OLE returned ", ret)
return self._get_good_object_(ret)
Index: __init__.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/__init__.py,v
retrieving revision 1.34.4.3
retrieving revision 1.34.4.4
diff -C2 -d -r1.34.4.3 -r1.34.4.4
*** __init__.py 3 Oct 2008 01:09:55 -0000 1.34.4.3
--- __init__.py 26 Nov 2008 07:17:39 -0000 1.34.4.4
***************
*** 6,13 ****
# dispatch object, the known class will be used. This contrasts
# with dynamic.Dispatch behaviour, where dynamic objects are always used.
! import builtins
! # For some bizarre reason, __builtins__ fails with attribute error on __dict__ here?
# This can go away
! NeedUnicodeConversions = not hasattr(builtins, "unicode")
import pythoncom
--- 6,12 ----
# dispatch object, the known class will be used. This contrasts
# with dynamic.Dispatch behaviour, where dynamic objects are always used.
!
# This can go away
! NeedUnicodeConversions = False
import pythoncom
***************
*** 259,267 ****
clsid = disp_class.CLSID
# Create a new class that derives from 3 classes - the dispatch class, the event sink class and the user class.
! import new
events_class = getevents(clsid)
if events_class is None:
raise ValueError("This COM object does not support events.")
! result_class = new.classobj("COMEventClass", (disp_class, events_class, user_event_class), {"__setattr__" : _event_setattr_})
instance = result_class(disp._oleobj_) # This only calls the first base class __init__.
events_class.__init__(instance, instance)
--- 258,271 ----
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("COMEventClass", (disp_class, events_class, user_event_class), {"__setattr__" : _event_setattr_})
instance = result_class(disp._oleobj_) # This only calls the first base class __init__.
events_class.__init__(instance, instance)
***************
*** 469,474 ****
if _PyIDispatchType==type(obj):
return Dispatch(obj, obUserName, resultCLSID, UnicodeToString=NeedUnicodeConversions)
- ## elif NeedUnicodeConversions and UnicodeType==type(obj):
- ## return str(obj)
return obj
--- 473,476 ----
Index: build.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/build.py,v
retrieving revision 1.31.2.3
retrieving revision 1.31.2.4
diff -C2 -d -r1.31.2.3 -r1.31.2.4
*** build.py 3 Oct 2008 01:09:55 -0000 1.31.2.3
--- build.py 26 Nov 2008 07:17:39 -0000 1.31.2.4
***************
*** 578,582 ****
else:
firstOptArg = numArgs - numOptArgs
! for arg in range(numArgs):
try:
argName = names[arg+1]
--- 578,582 ----
else:
firstOptArg = numArgs - numOptArgs
! for arg in xrange(numArgs):
try:
argName = names[arg+1]
***************
*** 604,608 ****
argName = MakePublicAttributeName(argName)
-
# insanely long lines with an 'encoding' flag crashes python 2.4.0
# keep 5 args per line
--- 604,607 ----
Index: genpy.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/genpy.py,v
retrieving revision 1.55.2.2
retrieving revision 1.55.2.3
diff -C2 -d -r1.55.2.2 -r1.55.2.3
*** genpy.py 31 Aug 2008 09:33:17 -0000 1.55.2.2
--- genpy.py 26 Nov 2008 07:17:39 -0000 1.55.2.3
***************
*** 23,27 ****
error = "makepy.error"
! makepy_version = "0.4.97" # Written to generated file.
GEN_FULL="full"
--- 23,27 ----
error = "makepy.error"
! makepy_version = "0.4.98" # Written to generated file.
GEN_FULL="full"
***************
*** 98,101 ****
--- 98,102 ----
# classes.
class WritableItem:
+ # __cmp__ used for sorting in py2x...
def __cmp__(self, other):
"Compare for sorting"
***************
*** 103,106 ****
--- 104,112 ----
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
+ if self.order == other.order:
+ return self.doc < other.doc
+ return self.order < other.order
def __repr__(self):
return "OleItem: doc=%s, order=%d" % (repr(self.doc), self.order)
***************
*** 128,132 ****
# (no longer necessary for new style code, but still used for old code.
def WriteAliasesForItem(item, aliasItems, stream):
! for alias in list(aliasItems.values()):
if item.doc and alias.aliasDoc and (alias.aliasDoc[0]==item.doc[0]):
alias.WriteAliasItem(aliasItems, stream)
--- 134,138 ----
# (no longer necessary for new style code, but still used for old code.
def WriteAliasesForItem(item, aliasItems, stream):
! for alias in aliasItems.itervalues():
if item.doc and alias.aliasDoc and (alias.aliasDoc[0]==item.doc[0]):
alias.WriteAliasItem(aliasItems, stream)
***************
*** 205,210 ****
if vdesc[4] == pythoncom.VAR_CONST:
val = vdesc[1]
! if isinstance(val, int):
! use=val
else:
use = repr(str(val))
--- 211,221 ----
if vdesc[4] == pythoncom.VAR_CONST:
val = vdesc[1]
! if sys.version_info <= (2,4) and (isinstance(val, int) or isinstance(val, long)):
! if val==0x80000000L: # special case
! use = "0x80000000L" # 'L' for future warning
! elif val > 0x80000000L or val < 0: # avoid a FutureWarning
! use = long(val)
! else:
! use = hex(val)
else:
use = repr(str(val))
***************
*** 645,649 ****
def CollectOleItemInfosFromType(self):
ret = []
! for i in range(self.typelib.GetTypeInfoCount()):
info = self.typelib.GetTypeInfo(i)
infotype = self.typelib.GetTypeInfoType(i)
--- 656,660 ----
def CollectOleItemInfosFromType(self):
ret = []
! for i in xrange(self.typelib.GetTypeInfoCount()):
info = self.typelib.GetTypeInfo(i)
infotype = self.typelib.GetTypeInfoType(i)
***************
*** 756,759 ****
--- 767,797 ----
return oleItems, enumItems, recordItems, vtableItems
+ def open_writer(self, filename, encoding="mbcs"):
+ # A place to put code to open a file with the appropriate encoding.
+ # Does *not* set self.file - just opens and returns a file.
+ # Actually *deletes* the filename asked for and returns a handle to a
+ # temp file - finish_writer then puts everything back in place. This
+ # is so errors don't leave a 1/2 generated file around causing bizarre
+ # errors later.
+ # Could be a classmethod one day...
+ try:
+ os.unlink(filename)
+ except os.error:
+ pass
+ filename = filename + ".temp"
+ if sys.version_info > (3,0):
+ ret = open(filename, "wt", encoding=encoding)
+ else:
+ import codecs # not available in py3k.
+ ret = codecs.open(filename, "wt", encoding)
+ return ret
+
+ def finish_writer(self, filename, f, worked):
+ f.close()
+ if worked:
+ os.rename(filename + ".temp", filename)
+ else:
+ os.unlink(filename + ".temp")
+
def generate(self, file, is_for_demand = 0):
if is_for_demand:
***************
*** 777,780 ****
--- 815,823 ----
self.bHaveWrittenCoClassBaseClass = 0
self.bHaveWrittenEventBaseClass = 0
+ # You must provide a file correctly configured for writing unicode.
+ # We assert this is it may indicate somewhere in pywin32 that needs
+ # upgrading.
+ assert self.file.encoding, self.file
+ encoding = self.file.encoding # or "mbcs"
print('# -*- coding: mbcs -*-', file=self.file) # Is this always correct?
***************
*** 831,835 ****
print("class constants:", file=stream)
values = list(enumItems.values())
! ## values.sort()
for oleitem in values:
oleitem.WriteEnumerationItems(stream)
--- 874,878 ----
print("class constants:", file=stream)
values = list(enumItems.values())
! values.sort()
for oleitem in values:
oleitem.WriteEnumerationItems(stream)
***************
*** 838,843 ****
if self.generate_type == GEN_FULL:
! values = [v for v in oleItems.values() if v is not None]
! ## values.sort()
for oleitem in values:
self.progress.Tick()
--- 881,886 ----
if self.generate_type == GEN_FULL:
! values = [v for v in oleItems.itervalues() if v is not None]
! values.sort()
for oleitem in values:
self.progress.Tick()
***************
*** 845,849 ****
values = list(vtableItems.values())
! ## values.sort()
for oleitem in values:
self.progress.Tick()
--- 888,892 ----
values = list(vtableItems.values())
! values.sort()
for oleitem in values:
self.progress.Tick()
***************
*** 853,858 ****
print('RecordMap = {', file=stream)
! values = list(recordItems.values())
! for record in values:
if str(record.clsid) == pythoncom.IID_NULL:
print("\t###%s: %s, # Typedef disabled because it doesn't have a non-null GUID" % (repr(record.doc[0]), repr(str(record.clsid))), file=stream)
--- 896,900 ----
print('RecordMap = {', file=stream)
! for record in recordItems.itervalues():
if str(record.clsid) == pythoncom.IID_NULL:
print("\t###%s: %s, # Typedef disabled because it doesn't have a non-null GUID" % (repr(record.doc[0]), repr(str(record.clsid))), file=stream)
***************
*** 865,869 ****
if self.generate_type == GEN_FULL:
print('CLSIDToClassMap = {', file=stream)
! for item in list(oleItems.values()):
if item is not None and item.bWritten:
print("\t'%s' : %s," % (str(item.clsid), item.python_name), file=stream)
--- 907,911 ----
if self.generate_type == GEN_FULL:
print('CLSIDToClassMap = {', file=stream)
! for item in oleItems.itervalues():
if item is not None and item.bWritten:
print("\t'%s' : %s," % (str(item.clsid), item.python_name), file=stream)
***************
*** 873,877 ****
print("VTablesToPackageMap = {}", file=stream)
print("VTablesToClassMap = {", file=stream)
! for item in list(vtableItems.values()):
print("\t'%s' : '%s'," % (item.clsid,item.python_name), file=stream)
print('}', file=stream)
--- 915,919 ----
print("VTablesToPackageMap = {}", file=stream)
print("VTablesToClassMap = {", file=stream)
! for item in vtableItems.itervalues():
print("\t'%s' : '%s'," % (item.clsid,item.python_name), file=stream)
print('}', file=stream)
***************
*** 881,885 ****
print('CLSIDToClassMap = {}', file=stream)
print('CLSIDToPackageMap = {', file=stream)
! for item in list(oleItems.values()):
if item is not None:
print("\t'%s' : %s," % (str(item.clsid), repr(item.python_name)), file=stream)
--- 923,927 ----
print('CLSIDToClassMap = {}', file=stream)
print('CLSIDToPackageMap = {', file=stream)
! for item in oleItems.itervalues():
if item is not None:
print("\t'%s' : %s," % (str(item.clsid), repr(item.python_name)), file=stream)
***************
*** 887,891 ****
print("VTablesToClassMap = {}", file=stream)
print("VTablesToPackageMap = {", file=stream)
! for item in list(vtableItems.values()):
print("\t'%s' : '%s'," % (item.clsid,item.python_name), file=stream)
print('}', file=stream)
--- 929,933 ----
print("VTablesToClassMap = {}", file=stream)
print("VTablesToPackageMap = {", file=stream)
! for item in vtableItems.itervalues():
print("\t'%s' : '%s'," % (item.clsid,item.python_name), file=stream)
print('}', file=stream)
***************
*** 895,906 ****
# Bit of a hack - build a temp map of iteItems + vtableItems - coClasses
map = {}
! for item in list(oleItems.values()):
if item is not None and not isinstance(item, CoClassItem):
map[item.python_name] = item.clsid
! for item in list(vtableItems.values()): # No nones or CoClasses in this map
map[item.python_name] = item.clsid
print("NamesToIIDMap = {", file=stream)
! for name, iid in list(map.items()):
print("\t'%s' : '%s'," % (name, iid), file=stream)
print('}', file=stream)
--- 937,948 ----
# Bit of a hack - build a temp map of iteItems + vtableItems - coClasses
map = {}
! for item in oleItems.itervalues():
if item is not None and not isinstance(item, CoClassItem):
map[item.python_name] = item.clsid
! for item in vtableItems.itervalues(): # No nones or CoClasses in this map
map[item.python_name] = item.clsid
print("NamesToIIDMap = {", file=stream)
! for name, iid in map.iteritems():
print("\t'%s' : '%s'," % (name, iid), file=stream)
print('}', file=stream)
***************
*** 960,966 ****
# Make a map of iid: dispitem, vtableitem)
items = {}
! for key, value in list(oleItems.items()):
items[key] = (value,None)
! for key, value in list(vtableItems.items()):
existing = items.get(key, None)
if existing is not None:
--- 1002,1008 ----
# Make a map of iid: dispitem, vtableitem)
items = {}
! for key, value in oleItems.iteritems():
items[key] = (value,None)
! for key, value in vtableItems.iteritems():
existing = items.get(key, None)
if existing is not None:
***************
*** 971,978 ****
self.progress.SetDescription("Generating...", len(items))
! for oleitem, vtableitem in list(items.values()):
an_item = oleitem or vtableitem
assert not self.file, "already have a file?"
! self.file = open(os.path.join(dir, an_item.python_name) + ".py", "w")
try:
if oleitem is not None:
--- 1013,1024 ----
self.progress.SetDescription("Generating...", len(items))
! for oleitem, vtableitem in items.itervalues():
an_item = oleitem or vtableitem
assert not self.file, "already have a file?"
! # like makepy.py, we gen to a .temp file so failure doesn't
! # leave a 1/2 generated mess.
! out_name = os.path.join(dir, an_item.python_name) + ".py"
! worked = False
! self.file = self.open_writer(out_name)
try:
if oleitem is not None:
***************
*** 981,986 ****
self.do_gen_child_item(vtableitem)
self.progress.Tick()
finally:
! self.file.close()
self.file = None
finally:
--- 1027,1033 ----
self.do_gen_child_item(vtableitem)
self.progress.Tick()
+ worked = True
finally:
! self.finish_writer(out_name, self.file, worked)
self.file = None
finally:
Index: gencache.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/gencache.py,v
retrieving revision 1.32.2.1
retrieving revision 1.32.2.2
diff -C2 -d -r1.32.2.1 -r1.32.2.2
*** gencache.py 29 Aug 2008 08:58:53 -0000 1.32.2.1
--- gencache.py 26 Nov 2008 07:17:39 -0000 1.32.2.2
***************
*** 49,52 ****
--- 49,57 ----
demandGeneratedTypeLibraries = {}
+ try:
+ import cPickle as pickle
+ except ImportError:
+ import pickle
+
def __init__():
# Initialize the module. Called once explicitly at module import below.
***************
*** 61,65 ****
raise RuntimeError("Trying to write to a readonly gencache ('%s')!" \
% win32com.__gen_path__)
- import pickle
f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb")
try:
--- 66,69 ----
***************
*** 71,78 ****
def _LoadDicts():
- import pickle
# Load the dictionary from a .zip file if that is where we live.
if hasattr(win32com, "__loader__"):
! import io
loader = win32com.__loader__
arc_path = loader.archive
--- 75,84 ----
def _LoadDicts():
# Load the dictionary from a .zip file if that is where we live.
if hasattr(win32com, "__loader__"):
! try:
! import cStringIO as io
! except ImportError:
! import io
loader = win32com.__loader__
arc_path = loader.archive
***************
*** 536,539 ****
--- 542,546 ----
mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], bForDemand=bForDemand)
GetModuleForCLSID(disp_clsid)
+ # Get the class from the module.
from . import CLSIDToClass
disp_class = CLSIDToClass.GetClass(str(disp_clsid))
***************
*** 553,569 ****
dict = mod.CLSIDToClassMap
info = str(typelibclsid), lcid, major, minor
! for clsid, cls in list(dict.items()):
clsidToTypelib[clsid] = info
dict = mod.CLSIDToPackageMap
! for clsid, name in list(dict.items()):
clsidToTypelib[clsid] = info
dict = mod.VTablesToClassMap
! for clsid, cls in list(dict.items()):
clsidToTypelib[clsid] = info
dict = mod.VTablesToPackageMap
! for clsid, cls in list(dict.items()):
clsidToTypelib[clsid] = info
--- 560,576 ----
dict = mod.CLSIDToClassMap
info = str(typelibclsid), lcid, major, minor
! for clsid, cls in dict.iteritems():
clsidToTypelib[clsid] = info
dict = mod.CLSIDToPackageMap
! for clsid, name in dict.iteritems():
clsidToTypelib[clsid] = info
dict = mod.VTablesToClassMap
! for clsid, cls in dict.iteritems():
clsidToTypelib[clsid] = info
dict = mod.VTablesToPackageMap
! for clsid, cls in dict.iteritems():
clsidToTypelib[clsid] = info
***************
*** 652,658 ****
# Build a unique dir
d = {}
! for clsid, (typelibCLSID, lcid, major, minor) in list(clsidToTypelib.items()):
d[typelibCLSID, lcid, major, minor] = None
! for typelibCLSID, lcid, major, minor in list(d.keys()):
mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
print("%s - %s" % (mod.__doc__, typelibCLSID))
--- 659,665 ----
# Build a unique dir
d = {}
! for clsid, (typelibCLSID, lcid, major, minor) in clsidToTypelib.iteritems():
d[typelibCLSID, lcid, major, minor] = None
! for typelibCLSID, lcid, major, minor in d.iterkeys():
mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
print("%s - %s" % (mod.__doc__, typelibCLSID))
|