cubicweb/__init__.py
branch3.24
changeset 11811 f09efeead7f9
parent 11767 432f87a63057
child 11821 7534b32c45e3
equal deleted inserted replaced
11810:2e03bb4372b2 11811:f09efeead7f9
    27 import pkgutil
    27 import pkgutil
    28 import sys
    28 import sys
    29 import warnings
    29 import warnings
    30 import zlib
    30 import zlib
    31 
    31 
    32 warnings.filterwarnings('ignore', category=UserWarning,
       
    33                         message='.*was already imported',
       
    34                         module='.*pygments')
       
    35 
       
    36 
       
    37 from six import PY2, binary_type, text_type
    32 from six import PY2, binary_type, text_type
    38 from six.moves import builtins
    33 from six.moves import builtins
       
    34 
       
    35 from logilab.common.deprecation import deprecated
       
    36 from logilab.common.logging_ext import set_log_methods
       
    37 from yams.constraints import BASE_CONVERTERS, BASE_CHECKERS
       
    38 from yams.schema import role_name as rname
       
    39 
       
    40 from cubicweb.__pkginfo__ import version as __version__   # noqa
       
    41 
       
    42 # make all exceptions accessible from the package
       
    43 from logilab.common.registry import ObjectNotFound, NoSelectableObject, RegistryNotFound  # noqa
       
    44 from yams import ValidationError
       
    45 from cubicweb._exceptions import *  # noqa
    39 
    46 
    40 if PY2:
    47 if PY2:
    41     # http://bugs.python.org/issue10211
    48     # http://bugs.python.org/issue10211
    42     from StringIO import StringIO as BytesIO
    49     from StringIO import StringIO as BytesIO
    43 else:
    50 else:
    44     from io import BytesIO
    51     from io import BytesIO
    45 
    52 
    46 from logilab.common.deprecation import deprecated
       
    47 from logilab.common.logging_ext import set_log_methods
       
    48 from yams.constraints import BASE_CONVERTERS, BASE_CHECKERS
       
    49 
       
    50 # ignore the pygments UserWarnings
    53 # ignore the pygments UserWarnings
    51 warnings.filterwarnings('ignore', category=UserWarning,
    54 warnings.filterwarnings('ignore', category=UserWarning,
    52                         message='.*was already imported',
    55                         message='.*was already imported',
    53                         module='.*pygments')
    56                         module='.*pygments')
    54 
    57 
    55 # pre python 2.7.2 safety
    58 # pre python 2.7.2 safety
    56 logging.basicConfig()
    59 logging.basicConfig()
       
    60 set_log_methods(sys.modules[__name__], logging.getLogger('cubicweb'))
    57 
    61 
    58 # this is necessary for i18n devtools test where chdir is done while __path__ is relative, which
    62 # this is necessary for i18n devtools test where chdir is done while __path__ is relative, which
    59 # breaks later imports
    63 # breaks later imports
    60 __path__[0] = os.path.abspath(__path__[0])
    64 __path__[0] = os.path.abspath(__path__[0])  # noqa
    61 CW_SOFTWARE_ROOT = __path__[0]
    65 CW_SOFTWARE_ROOT = __path__[0]  # noqa
    62 
       
    63 
       
    64 from cubicweb.__pkginfo__ import version as __version__   # noqa
       
    65 
       
    66 
       
    67 set_log_methods(sys.modules[__name__], logging.getLogger('cubicweb'))
       
    68 
       
    69 # make all exceptions accessible from the package
       
    70 from cubicweb._exceptions import *  # noqa
       
    71 from logilab.common.registry import ObjectNotFound, NoSelectableObject, RegistryNotFound  # noqa
       
    72 
    66 
    73 
    67 
    74 # '_' is available to mark internationalized string but should not be used to
    68 # '_' is available to mark internationalized string but should not be used to
    75 # do the actual translation
    69 # do the actual translation
    76 _ = text_type
    70 _ = text_type
   247         CW_EVENT_MANAGER.bind(event, func, *args, **kwargs)
   241         CW_EVENT_MANAGER.bind(event, func, *args, **kwargs)
   248         return func
   242         return func
   249     return _decorator
   243     return _decorator
   250 
   244 
   251 
   245 
   252 from yams.schema import role_name as rname
       
   253 
       
   254 
       
   255 def validation_error(entity, errors, substitutions=None, i18nvalues=None):
   246 def validation_error(entity, errors, substitutions=None, i18nvalues=None):
   256     """easy way to retrieve a :class:`cubicweb.ValidationError` for an entity or eid.
   247     """easy way to retrieve a :class:`cubicweb.ValidationError` for an entity or eid.
   257 
   248 
   258     You may also have 2-tuple as error keys, :func:`yams.role_name` will be
   249     You may also have 2-tuple as error keys, :func:`yams.role_name` will be
   259     called automatically for them.
   250     called automatically for them.