cubicweb/__init__.py
changeset 11417 5e5e224239c3
parent 11281 2cb8b383a519
child 11457 d404fd8499dd
--- a/cubicweb/__init__.py	Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/__init__.py	Fri Jul 08 09:59:18 2016 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -59,14 +59,14 @@
 CW_SOFTWARE_ROOT = __path__[0]
 
 
-from cubicweb.__pkginfo__ import version as __version__
+from cubicweb.__pkginfo__ import version as __version__   # noqa
 
 
 set_log_methods(sys.modules[__name__], logging.getLogger('cubicweb'))
 
 # make all exceptions accessible from the package
-from cubicweb._exceptions import *
-from logilab.common.registry import ObjectNotFound, NoSelectableObject, RegistryNotFound
+from cubicweb._exceptions import *  # noqa
+from logilab.common.registry import ObjectNotFound, NoSelectableObject, RegistryNotFound  # noqa
 
 
 # '_' is available to mark internationalized string but should not be used to
@@ -81,10 +81,6 @@
 def typed_eid(eid):
     return int(eid)
 
-#def log_thread(f, w, a):
-#    print f.f_code.co_filename, f.f_code.co_name
-#import threading
-#threading.settrace(log_thread)
 
 class Binary(BytesIO):
     """class to hold binary data. Use BytesIO to prevent use of unicode data"""
@@ -92,13 +88,13 @@
 
     def __init__(self, buf=b''):
         assert isinstance(buf, self._allowed_types), \
-               "Binary objects must use bytes/buffer objects, not %s" % buf.__class__
+            "Binary objects must use bytes/buffer objects, not %s" % buf.__class__
         # don't call super, BytesIO may be an old-style class (on python < 2.7.4)
         BytesIO.__init__(self, buf)
 
     def write(self, data):
         assert isinstance(data, self._allowed_types), \
-               "Binary objects must use bytes/buffer objects, not %s" % data.__class__
+            "Binary objects must use bytes/buffer objects, not %s" % data.__class__
         # don't call super, BytesIO may be an old-style class (on python < 2.7.4)
         BytesIO.write(self, data)
 
@@ -114,7 +110,7 @@
             while True:
                 # the 16kB chunksize comes from the shutil module
                 # in stdlib
-                chunk = self.read(16*1024)
+                chunk = self.read(16 * 1024)
                 if not chunk:
                     break
                 fobj.write(chunk)
@@ -135,7 +131,7 @@
                 while True:
                     # the 16kB chunksize comes from the shutil module
                     # in stdlib
-                    chunk = fobj.read(16*1024)
+                    chunk = fobj.read(16 * 1024)
                     if not chunk:
                         break
                     binary.write(chunk)
@@ -149,7 +145,6 @@
             return False
         return self.getvalue() == other.getvalue()
 
-
     # Binary helpers to store/fetch python objects
 
     @classmethod
@@ -168,6 +163,7 @@
     return isinstance(value, (binary_type, Binary))
 BASE_CHECKERS['Password'] = check_password
 
+
 def str_or_binary(value):
     if isinstance(value, Binary):
         return value
@@ -182,17 +178,20 @@
 #     to help in cube renaming
 CW_MIGRATION_MAP = {}
 
+
 def neg_role(role):
     if role == 'subject':
         return 'object'
     return 'subject'
 
+
 def role(obj):
     try:
         return obj.role
     except AttributeError:
         return neg_role(obj.target)
 
+
 def target(obj):
     try:
         return obj.target
@@ -220,7 +219,7 @@
         self.callbacks = {}
 
     def bind(self, event, callback, *args, **kwargs):
-        self.callbacks.setdefault(event, []).append( (callback, args, kwargs) )
+        self.callbacks.setdefault(event, []).append((callback, args, kwargs))
 
     def emit(self, event, context=None):
         for callback, args, kwargs in self.callbacks.get(event, ()):
@@ -231,6 +230,7 @@
 
 CW_EVENT_MANAGER = CubicWebEventManager()
 
+
 def onevent(event, *args, **kwargs):
     """decorator to ease event / callback binding
 
@@ -249,6 +249,7 @@
 
 from yams.schema import role_name as rname
 
+
 def validation_error(entity, errors, substitutions=None, i18nvalues=None):
     """easy way to retrieve a :class:`cubicweb.ValidationError` for an entity or eid.
 
@@ -272,7 +273,7 @@
 
 # exceptions ##################################################################
 
-class ProgrammingError(Exception): #DatabaseError):
+class ProgrammingError(Exception):
     """Exception raised for errors that are related to the database's operation
     and not necessarily under the control of the programmer, e.g. an unexpected
     disconnect occurs, the data source name is not found, a transaction could