server/sources/__init__.py
changeset 9402 2c48c091b6a2
parent 9292 4b3e657d17ab
child 9445 65d93a4fd11c
child 9492 c7fc56eecd1a
equal deleted inserted replaced
9127:aff75b69db92 9402:2c48c091b6a2
    19 
    19 
    20 __docformat__ = "restructuredtext en"
    20 __docformat__ = "restructuredtext en"
    21 
    21 
    22 import itertools
    22 import itertools
    23 from os.path import join, splitext
    23 from os.path import join, splitext
       
    24 from time import time
    24 from datetime import datetime, timedelta
    25 from datetime import datetime, timedelta
    25 from logging import getLogger
    26 from logging import getLogger
    26 
    27 
    27 from logilab.common import configuration
    28 from logilab.common import configuration
    28 from logilab.common.deprecation import deprecated
    29 from logilab.common.deprecation import deprecated
    35 from cubicweb.server.edition import EditedEntity
    36 from cubicweb.server.edition import EditedEntity
    36 
    37 
    37 
    38 
    38 def dbg_st_search(uri, union, varmap, args, cachekey=None, prefix='rql for'):
    39 def dbg_st_search(uri, union, varmap, args, cachekey=None, prefix='rql for'):
    39     if server.DEBUG & server.DBG_RQL:
    40     if server.DEBUG & server.DBG_RQL:
       
    41         global t
    40         print '  %s %s source: %s' % (prefix, uri, repr(union.as_string()))
    42         print '  %s %s source: %s' % (prefix, uri, repr(union.as_string()))
       
    43         t = time()
    41         if varmap:
    44         if varmap:
    42             print '    using varmap', varmap
    45             print '    using varmap', varmap
    43         if server.DEBUG & server.DBG_MORE:
    46         if server.DEBUG & server.DBG_MORE:
    44             print '    args', repr(args)
    47             print '    args', repr(args)
    45             print '    cache key', cachekey
    48             print '    cache key', cachekey
    49     return True
    52     return True
    50 
    53 
    51 def dbg_results(results):
    54 def dbg_results(results):
    52     if server.DEBUG & server.DBG_RQL:
    55     if server.DEBUG & server.DBG_RQL:
    53         if len(results) > 10:
    56         if len(results) > 10:
    54             print '  -->', results[:10], '...', len(results)
    57             print '  -->', results[:10], '...', len(results),
    55         else:
    58         else:
    56             print '  -->', results
    59             print '  -->', results,
       
    60         print 'time: ', time() - t
    57     # return true so it can be used as assertion (and so be killed by python -O)
    61     # return true so it can be used as assertion (and so be killed by python -O)
    58     return True
    62     return True
    59 
    63 
    60 class TimedCache(dict):
    64 class TimedCache(dict):
    61     def __init__(self, ttl):
    65     def __init__(self, ttl):
   177                 msg = _('specifying %s is mandatory' % optname)
   181                 msg = _('specifying %s is mandatory' % optname)
   178                 raise ValidationError(eid, {role_name('config', 'subject'): msg})
   182                 raise ValidationError(eid, {role_name('config', 'subject'): msg})
   179             elif value is not None:
   183             elif value is not None:
   180                 # type check
   184                 # type check
   181                 try:
   185                 try:
   182                     value = configuration.convert(value, optdict, optname)
   186                     value = configuration._validate(value, optdict, optname)
   183                 except Exception as ex:
   187                 except Exception as ex:
   184                     msg = unicode(ex) # XXX internationalization
   188                     msg = unicode(ex) # XXX internationalization
   185                     raise ValidationError(eid, {role_name('config', 'subject'): msg})
   189                     raise ValidationError(eid, {role_name('config', 'subject'): msg})
   186             processed[optname] = value
   190             processed[optname] = value
   187         # cw < 3.10 bw compat
   191         # cw < 3.10 bw compat