server/sources/__init__.py
changeset 10622 3cc6154b94a3
parent 10589 7c23b7de2b8d
child 10651 9ca33768473c
equal deleted inserted replaced
10621:987fbc88f097 10622:3cc6154b94a3
    22 
    22 
    23 from time import time
    23 from time import time
    24 from logging import getLogger
    24 from logging import getLogger
    25 from base64 import b64decode
    25 from base64 import b64decode
    26 
    26 
       
    27 from six import text_type
       
    28 
    27 from logilab.common import configuration
    29 from logilab.common import configuration
    28 from logilab.common.deprecation import deprecated
    30 from logilab.common.deprecation import deprecated
    29 
    31 
    30 from yams.schema import role_name
    32 from yams.schema import role_name
    31 
    33 
   137     def restore(self, backupfile, confirm, drop, format='native'):
   139     def restore(self, backupfile, confirm, drop, format='native'):
   138         """method called to restore a backup of source's data"""
   140         """method called to restore a backup of source's data"""
   139         pass
   141         pass
   140 
   142 
   141     @classmethod
   143     @classmethod
   142     def check_conf_dict(cls, eid, confdict, _=unicode, fail_if_unknown=True):
   144     def check_conf_dict(cls, eid, confdict, _=text_type, fail_if_unknown=True):
   143         """check configuration of source entity. Return config dict properly
   145         """check configuration of source entity. Return config dict properly
   144         typed with defaults set.
   146         typed with defaults set.
   145         """
   147         """
   146         processed = {}
   148         processed = {}
   147         for optname, optdict in cls.options:
   149         for optname, optdict in cls.options:
   154             elif value is not None:
   156             elif value is not None:
   155                 # type check
   157                 # type check
   156                 try:
   158                 try:
   157                     value = configuration._validate(value, optdict, optname)
   159                     value = configuration._validate(value, optdict, optname)
   158                 except Exception as ex:
   160                 except Exception as ex:
   159                     msg = unicode(ex) # XXX internationalization
   161                     msg = text_type(ex) # XXX internationalization
   160                     raise ValidationError(eid, {role_name('config', 'subject'): msg})
   162                     raise ValidationError(eid, {role_name('config', 'subject'): msg})
   161             processed[optname] = value
   163             processed[optname] = value
   162         # cw < 3.10 bw compat
   164         # cw < 3.10 bw compat
   163         try:
   165         try:
   164             processed['adapter'] = confdict['adapter']
   166             processed['adapter'] = confdict['adapter']