55# comtypes version numbers follow semver (http://semver.org/) and PEP 440
66__version__ = "1.1.11"
77
8+ if sys .version_info >= (3 , 0 ):
9+ text_type = str
10+ else :
11+ text_type = unicode
12+
813import logging
914class NullHandler (logging .Handler ):
1015 """A Handler that does nothing."""
@@ -488,7 +493,7 @@ def _make_dispmethods(self, methods):
488493 if is_prop :
489494 self .__map_case__ [name [5 :].lower ()] = name [5 :]
490495
491- for (name , nargs ), methods in list ( properties .items () ):
496+ for (name , nargs ), methods in properties .items ():
492497 # methods contains [propget or None, propput or None, propputref or None]
493498 if methods [1 ] is not None and methods [2 ] is not None :
494499 # both propput and propputref.
@@ -655,7 +660,7 @@ def call_with_inout(self_, *args, **kw):
655660 return rescode
656661
657662 rescode = list (rescode )
658- for outnum , o in list ( outargs .items () ):
663+ for outnum , o in outargs .items ():
659664 rescode [outnum ] = o .__ctypes_from_outparam__ ()
660665 return rescode
661666 return call_with_inout
@@ -670,7 +675,7 @@ def _make_methods(self, methods):
670675 except KeyError :
671676 raise AttributeError ("this class must define an _iid_" )
672677 else :
673- iid = str (iid )
678+ iid = text_type (iid )
674679## if iid in com_interface_registry:
675680## # Warn when multiple interfaces are defined with identical iids.
676681## # This would also trigger if we reload() a module that contains
@@ -779,7 +784,7 @@ def _make_methods(self, methods):
779784 self .__map_case__ [name [5 :].lower ()] = name [5 :]
780785
781786 # create public properties / attribute accessors
782- for (name , doc , nargs ), methods in list ( properties .items () ):
787+ for (name , doc , nargs ), methods in properties .items ():
783788 # methods contains [propget or None, propput or None, propputref or None]
784789 if methods [1 ] is not None and methods [2 ] is not None :
785790 # both propput and propputref.
@@ -891,11 +896,51 @@ def __repr__(self):
891896
892897################################################################
893898
899+ def add_metaclass (metaclass ):
900+ """Class decorator from six.py for creating a class with a metaclass.
901+
902+ Copyright (c) 2010-2020 Benjamin Peterson
903+
904+ Permission is hereby granted, free of charge, to any person obtaining a copy of
905+ this software and associated documentation files (the "Software"), to deal in
906+ the Software without restriction, including without limitation the rights to
907+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
908+ the Software, and to permit persons to whom the Software is furnished to do so,
909+ subject to the following conditions:
910+
911+ The above copyright notice and this permission notice shall be included in all
912+ copies or substantial portions of the Software.
913+
914+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
915+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
916+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
917+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
918+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
919+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
920+ """
921+ def wrapper (cls ):
922+ orig_vars = cls .__dict__ .copy ()
923+ slots = orig_vars .get ('__slots__' )
924+ if slots is not None :
925+ if isinstance (slots , text_type ):
926+ slots = [slots ]
927+ for slots_var in slots :
928+ orig_vars .pop (slots_var )
929+ orig_vars .pop ('__dict__' , None )
930+ orig_vars .pop ('__weakref__' , None )
931+ if hasattr (cls , '__qualname__' ):
932+ orig_vars ['__qualname__' ] = cls .__qualname__
933+ return metaclass (cls .__name__ , cls .__bases__ , orig_vars )
934+ return wrapper
935+
936+ ################################################################
937+
894938class _compointer_meta (type (c_void_p ), _cominterface_meta ):
895939 "metaclass for COM interface pointer classes"
896940 # no functionality, but needed to avoid a metaclass conflict
897941
898- class _compointer_base (c_void_p , metaclass = _compointer_meta ):
942+ @add_metaclass (_compointer_meta )
943+ class _compointer_base (c_void_p ):
899944 "base class for COM interface pointer classes"
900945 def __del__ (self , _debug = logger .debug ):
901946 "Release the COM refcount we own."
@@ -1016,7 +1061,7 @@ def from_param(cls, value):
10161061################################################################
10171062# IDL stuff
10181063
1019- class helpstring (str ):
1064+ class helpstring (text_type ):
10201065 "Specifies the helpstring for a COM method or property."
10211066
10221067class defaultvalue (object ):
@@ -1122,7 +1167,8 @@ def COMMETHOD(idlflags, restype, methodname, *argspec):
11221167################################################################
11231168# IUnknown, the root of all evil...
11241169
1125- class IUnknown (object , metaclass = _cominterface_meta ):
1170+ @add_metaclass (_cominterface_meta )
1171+ class IUnknown (object ):
11261172 """The most basic COM interface.
11271173
11281174 Each subclasses of IUnknown must define these class attributes:
@@ -1200,7 +1246,7 @@ def CoGetObject(displayname, interface):
12001246 interface = IUnknown
12011247 punk = POINTER (interface )()
12021248 # Do we need a way to specify the BIND_OPTS parameter?
1203- _ole32 .CoGetObject (str (displayname ),
1249+ _ole32 .CoGetObject (text_type (displayname ),
12041250 None ,
12051251 byref (interface ._iid_ ),
12061252 byref (punk ))
@@ -1379,6 +1425,7 @@ def CoCreateInstanceEx(clsid, interface=None,
13791425
13801426from comtypes ._meta import _coclass_meta
13811427
1382- class CoClass (COMObject , metaclass = _coclass_meta ):
1428+ @add_metaclass (_coclass_meta )
1429+ class CoClass (COMObject ):
13831430 pass
13841431################################################################
0 commit comments