VirtualBox

Changeset 21288 in vbox for trunk/src/VBox/Main/glue


Ignore:
Timestamp:
Jul 7, 2009 7:06:59 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49626
Message:

Python: case-insensitive attribute lookup for MS COM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/vboxapi.py

    r20926 r21288  
    100100        return out
    101101
     102def ComifyName(name):
     103    return name[0].capitalize()+name[1:]   
     104
     105_COMForward = { 'getattr' : None,
     106                'setattr' : None}
     107         
     108def CustomGetAttr(self, attr):
     109    # fastpath
     110    if self.__class__.__dict__.get(attr) != None:
     111        return self.__class__.__dict__.get(attr)
     112
     113    # try case-insensitivity workaround for class attributes (COM methods)
     114    for k in self.__class__.__dict__.keys():
     115        if k.lower() == attr.lower():
     116            self.__class__.__dict__[attr] = self.__class__.__dict__[k]
     117            return getattr(self, k)
     118    try:
     119        return _COMForward['getattr'](self,ComifyName(attr))
     120    except AttributeError:
     121        return _COMForward['getattr'](self,attr)
     122
     123def CustomSetAttr(self, attr, value):
     124    try:
     125        return _COMForward['setattr'](self, ComifyName(attr), value)
     126    except AttributeError:
     127        return _COMForward['setattr'](self, attr, value)
     128
    102129class PlatformMSCOM:
    103130    # Class to fake access to constants in style of foo.bar.boo
     
    163190    VBOX_TLB_MAJOR = 1
    164191    VBOX_TLB_MINOR = 0
    165 
     192   
    166193    def __init__(self, params):
    167194            from win32com import universal
    168             from win32com.client import gencache, DispatchWithEvents, Dispatch
     195            from win32com.client import gencache, DispatchBaseClass
    169196            from win32com.client import constants, getevents
    170197            import win32com
     
    179206            self.handles = []
    180207            self.handles.append(handle)
    181 
     208            _COMForward['getattr'] = DispatchBaseClass.__dict__['__getattr__']
     209            DispatchBaseClass.__dict__['__getattr__'] = CustomGetAttr           
     210            _COMForward['setattr'] = DispatchBaseClass.__dict__['__setattr__']
     211            DispatchBaseClass.__dict__['__setattr__'] = CustomSetAttr           
     212            win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
     213            win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
    182214
    183215    def getSessionObject(self, vbox):
     
    278310
    279311    def getPerfCollector(self, vbox):
    280         # MS COM cannot invoke performance collector methods yet
    281         return None
     312        return PerfCollector(vbox)
    282313
    283314
     
    463494
    464495    def getPerfCollector(self, vbox):
    465         return self.platform.getPerfCollector(vbox)       
     496        return PerfCollector(vbox)       
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette