dbapi.py
branchstable
changeset 4705 8ae13d059850
parent 4592 ddbab12acae0
child 4716 55b6a3262071
equal deleted inserted replaced
4704:a1ac5a453146 4705:8ae13d059850
    28 def _fake_property_value(self, name):
    28 def _fake_property_value(self, name):
    29     try:
    29     try:
    30         return super(dbapi.DBAPIRequest, self).property_value(name)
    30         return super(dbapi.DBAPIRequest, self).property_value(name)
    31     except KeyError:
    31     except KeyError:
    32         return ''
    32         return ''
    33 
       
    34 def _fix_cls_attrs(reg, appobject):
       
    35     appobject.vreg = reg.vreg
       
    36     appobject.schema = reg.schema
       
    37     appobject.config = reg.config
       
    38 
    33 
    39 def multiple_connections_fix():
    34 def multiple_connections_fix():
    40     """some monkey patching necessary when an application has to deal with
    35     """some monkey patching necessary when an application has to deal with
    41     several connections to different repositories. It tries to hide buggy class
    36     several connections to different repositories. It tries to hide buggy class
    42     attributes since classes are not designed to be shared among multiple
    37     attributes since classes are not designed to be shared among multiple
    43     registries.
    38     registries.
    44     """
    39     """
    45     defaultcls = cwvreg.VRegistry.REGISTRY_FACTORY[None]
    40     defaultcls = cwvreg.VRegistry.REGISTRY_FACTORY[None]
    46     orig_select_best = defaultcls.orig_select_best = defaultcls._select_best
       
    47     @monkeypatch(defaultcls)
       
    48     def _select_best(self, appobjects, *args, **kwargs):
       
    49         """return an instance of the most specific object according
       
    50         to parameters
       
    51 
       
    52         raise NoSelectableObject if no object apply
       
    53         """
       
    54         for appobjectcls in appobjects:
       
    55             _fix_cls_attrs(self, appobjectcls)
       
    56         selected = orig_select_best(self, appobjects, *args, **kwargs)
       
    57         # redo the same thing on the instance so it won't use equivalent class
       
    58         # attributes (which may change)
       
    59         _fix_cls_attrs(self, selected)
       
    60         return selected
       
    61 
    41 
    62     etypescls = cwvreg.VRegistry.REGISTRY_FACTORY['etypes']
    42     etypescls = cwvreg.VRegistry.REGISTRY_FACTORY['etypes']
    63     orig_etype_class = etypescls.orig_etype_class = etypescls.etype_class
    43     orig_etype_class = etypescls.orig_etype_class = etypescls.etype_class
    64     @monkeypatch(defaultcls)
    44     @monkeypatch(defaultcls)
    65     def etype_class(self, etype):
    45     def etype_class(self, etype):
    72             return usercls
    52             return usercls
    73         usercls.e_schema = self.schema.eschema(etype)
    53         usercls.e_schema = self.schema.eschema(etype)
    74         return usercls
    54         return usercls
    75 
    55 
    76 def multiple_connections_unfix():
    56 def multiple_connections_unfix():
    77     defaultcls = cwvreg.VRegistry.REGISTRY_FACTORY[None]
       
    78     defaultcls.select_best = defaultcls.orig_select_best
       
    79     etypescls = cwvreg.VRegistry.REGISTRY_FACTORY['etypes']
    57     etypescls = cwvreg.VRegistry.REGISTRY_FACTORY['etypes']
    80     etypescls.etype_class = etypescls.orig_etype_class
    58     etypescls.etype_class = etypescls.orig_etype_class
    81 
    59 
    82 class ConnectionProperties(object):
    60 class ConnectionProperties(object):
    83     def __init__(self, cnxtype=None, lang=None, close=True, log=False):
    61     def __init__(self, cnxtype=None, lang=None, close=True, log=False):