ZEO and COM

drs drs at ecp.cc
Fri Jul 11 22:41:45 CEST 2003


please let me know if there is a better place to post this ...

I am trying to create a shared dictionary which can be accessed via COM.  To
that end, I have written the code below (at the end).

So far this works from a single computer, but if another computer tries to
share the data it is unable to see changes, and throws exceptions when it
tries to rewrite data.

Does anyone know how I can make all connections aware of changes?

Any ideas?

Thanks

This is w/ ZODB3 3.1.2, Python 2.2, win2k

-doug

#-----------------
from ZEO import ClientStorage
from ZODB import DB

class ecp_ZEOCOM:

    _reg_clsid_ = '{F7B8D35F-7B24-4B84-A8B6-34880132A854}'
    _public_methods_ = [
        'open',
        'keys',
        'has_key',
        'get_item',
        'set_item',
        'del_item'
        ]
    _reg_progid_ = 'ecp.ZEOCOM'

    def open(self, IP, Port):
        addr = (str(IP), int(Port))
        self.storage = ClientStorage.ClientStorage(addr)
        dbl = DB(self.storage)
        conn = dbl.open()
        self.db = conn.root()

    def get_item(self, key):
        self.storage.sync()
        try: return self.db[str(key)]
        except: return ''

    def set_item(self, key, value):
        self.storage.sync()
        self.db[str(key)] = value
        get_transaction().commit()

    def del_item(self, key):
        self.storage.sync()
        del self.db[str(key)]
        get_transaction().commit()

    def keys(self):
        self.storage.sync()
        x = self.db.keys()
        x.sort()
        return x

    def has_key(self, key):
        self.storage.sync()
        return self.db.has_key(key)

def register():
    import win32com.server.register
    win32com.server.register.UseCommandLine(ecp_ZEOCOM)

if __name__ == '__main__': register()
#-----------------







More information about the Python-list mailing list