dbapi.py
changeset 167 b726c12af78f
parent 0 b97547f5f1fa
child 169 0e031b66cb0b
equal deleted inserted replaced
166:879d78d37d47 167:b726c12af78f
    43         return Repository(config, vreg=vreg)
    43         return Repository(config, vreg=vreg)
    44     else: # method == 'pyro'
    44     else: # method == 'pyro'
    45         from Pyro import core, naming, config as pyroconfig
    45         from Pyro import core, naming, config as pyroconfig
    46         from Pyro.errors import NamingError, ProtocolError
    46         from Pyro.errors import NamingError, ProtocolError
    47         core.initClient(banner=0)
    47         core.initClient(banner=0)
    48         pyroconfig.PYRO_NS_DEFAULTGROUP = ':' + config['pyro-ns-group']
    48         nsid = ':%s.%s' % (config['pyro-ns-group'], database)
    49         locator = naming.NameServerLocator()
    49         locator = naming.NameServerLocator()
    50         # resolve the Pyro object
    50         # resolve the Pyro object
    51         try:
    51         try:
    52             nshost, nsport = config['pyro-ns-host'], config['pyro-ns-port']
    52             nshost, nsport = config['pyro-ns-host'], config['pyro-ns-port']
    53             uri = locator.getNS(nshost, nsport).resolve(database)
    53             uri = locator.getNS(nshost, nsport) .resolve(nsid)
    54         except ProtocolError:
    54         except ProtocolError:
    55             raise ConnectionError('Could not connect to the Pyro name server '
    55             raise ConnectionError('Could not connect to the Pyro name server '
    56                                   '(host: %s:%i)' % (nshost, nsport))
    56                                   '(host: %s:%i)' % (nshost, nsport))
    57         except NamingError:
    57         except NamingError, ex:
    58             raise ConnectionError('Could not get repository for %s '
    58             raise ConnectionError('Could not get repository for %s '
    59                                   '(not registered in Pyro),'
    59                                   '(not registered in Pyro), '
    60                                   'you may have to restart your server-side '
    60                                   'you may have to restart your server-side '
    61                                   'application' % database)
    61                                   'application' % nsid)
    62         return core.getProxyForURI(uri)
    62         return core.getProxyForURI(uri)
    63         
    63         
    64 def repo_connect(repo, user, password, cnxprops=None):
    64 def repo_connect(repo, user, password, cnxprops=None):
    65     """Constructor to create a new connection to the CubicWeb repository.
    65     """Constructor to create a new connection to the CubicWeb repository.
    66     
    66