cubicweb/server/sources/__init__.py
changeset 11767 432f87a63057
parent 11763 39df042f4ab4
child 11774 51c160677afe
equal deleted inserted replaced
11766:d8de1ac21f36 11767:432f87a63057
     1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """cubicweb server sources support"""
    18 """cubicweb server sources support"""
       
    19 
    19 from __future__ import print_function
    20 from __future__ import print_function
    20 
       
    21 __docformat__ = "restructuredtext en"
       
    22 
    21 
    23 from time import time
    22 from time import time
    24 from logging import getLogger
    23 from logging import getLogger
    25 from base64 import b64decode
       
    26 
    24 
    27 from six import text_type
    25 from six import text_type
    28 
    26 
    29 from logilab.common import configuration
    27 from logilab.common import configuration
    30 from logilab.common.textutils import unormalize
    28 from logilab.common.textutils import unormalize
    31 from logilab.common.deprecation import deprecated
       
    32 
    29 
    33 from yams.schema import role_name
    30 from yams.schema import role_name
    34 
    31 
    35 from cubicweb import ValidationError, set_log_methods, server
    32 from cubicweb import ValidationError, set_log_methods, server
    36 from cubicweb.server import SOURCE_TYPES
    33 from cubicweb.server import SOURCE_TYPES
    37 from cubicweb.server.edition import EditedEntity
       
    38 
    34 
    39 
    35 
    40 def dbg_st_search(uri, union, args, cachekey=None, prefix='rql for'):
    36 def dbg_st_search(uri, union, args, cachekey=None, prefix='rql for'):
    41     if server.DEBUG & server.DBG_RQL:
    37     if server.DEBUG & server.DBG_RQL:
    42         global t
    38         global t
    47             print('    cache key', cachekey)
    43             print('    cache key', cachekey)
    48             print('    solutions', ','.join(str(s.solutions)
    44             print('    solutions', ','.join(str(s.solutions)
    49                                             for s in union.children))
    45                                             for s in union.children))
    50     # return true so it can be used as assertion (and so be killed by python -O)
    46     # return true so it can be used as assertion (and so be killed by python -O)
    51     return True
    47     return True
       
    48 
    52 
    49 
    53 def dbg_results(results):
    50 def dbg_results(results):
    54     if server.DEBUG & server.DBG_RQL:
    51     if server.DEBUG & server.DBG_RQL:
    55         if len(results) > 10:
    52         if len(results) > 10:
    56             print('  -->', results[:10], '...', len(results), end=' ')
    53             print('  -->', results[:10], '...', len(results), end=' ')
   390     try:
   387     try:
   391         return SOURCE_TYPES[source_type]
   388         return SOURCE_TYPES[source_type]
   392     except KeyError:
   389     except KeyError:
   393         raise RuntimeError('Unknown source type %r' % source_type)
   390         raise RuntimeError('Unknown source type %r' % source_type)
   394 
   391 
       
   392 
   395 def get_source(type, source_config, repo, eid):
   393 def get_source(type, source_config, repo, eid):
   396     """return a source adapter according to the adapter field in the source's
   394     """return a source adapter according to the adapter field in the source's
   397     configuration
   395     configuration
   398     """
   396     """
   399     return source_adapter(type)(repo, source_config, eid)
   397     return source_adapter(type)(repo, source_config, eid)