pep8 bits
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 08 Jul 2016 09:59:18 +0200
changeset 11417 5e5e224239c3
parent 11416 9c2fbb872e91
child 11424 1451f040555f
pep8 bits
cubicweb/__init__.py
cubicweb/hooks/syncschema.py
cubicweb/hooks/test/unittest_syncschema.py
cubicweb/schema.py
cubicweb/server/__init__.py
cubicweb/server/sources/native.py
cubicweb/server/sqlutils.py
cubicweb/server/test/unittest_schema2sql.py
cubicweb/server/test/unittest_schemaserial.py
--- 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
--- a/cubicweb/hooks/syncschema.py	Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/hooks/syncschema.py	Fri Jul 08 09:59:18 2016 +0200
@@ -45,7 +45,7 @@
 
 # core entity and relation types which can't be removed
 CORE_TYPES = BASE_TYPES | SCHEMA_TYPES | META_RTYPES | set(
-    ('CWUser', 'CWGroup','login', 'upassword', 'name', 'in_group'))
+    ('CWUser', 'CWGroup', 'login', 'upassword', 'name', 'in_group'))
 
 
 def get_constraints(cnx, entity):
@@ -76,7 +76,8 @@
     table = SQL_PREFIX + etype
     column = SQL_PREFIX + rtype
     try:
-        cnx.system_sql(str('ALTER TABLE %s ADD %s integer REFERENCES entities (eid)' % (table, column)),
+        cnx.system_sql(str('ALTER TABLE %s ADD %s integer REFERENCES entities (eid)'
+                           % (table, column)),
                        rollback_on_failure=False)
         cnx.info('added column %s to table %s', column, table)
     except Exception:
@@ -240,7 +241,7 @@
       CWAttribute entities
     * add <meta rtype> relation by creating the necessary CWRelation entity
     """
-    entity = None # make pylint happy
+    entity = None  # make pylint happy
 
     def precommit_event(self):
         cnx = self.cnx
@@ -360,11 +361,11 @@
                     op.add_data(objtype)
                     op.add_data(subjtype)
         # update the in-memory schema first
-        self.oldvalues = dict( (attr, getattr(rschema, attr)) for attr in self.values)
+        self.oldvalues = dict((attr, getattr(rschema, attr)) for attr in self.values)
         self.rschema.__dict__.update(self.values)
         # then make necessary changes to the system source database
         if 'inlined' not in self.values:
-            return # nothing to do
+            return  # nothing to do
         inlined = self.values['inlined']
         # check in-lining is possible when inlined
         if inlined:
@@ -376,7 +377,7 @@
         if not inlined:
             # need to create the relation if it has not been already done by
             # another event of the same transaction
-            if not rschema.type in cnx.transaction_data.get('createdtables', ()):
+            if rschema.type not in cnx.transaction_data.get('createdtables', ()):
                 # create the necessary table
                 for sql in y2sql.rschema2sql(rschema):
                     sqlexec(sql)
@@ -389,7 +390,6 @@
                 sqlexec('INSERT INTO %s_relation SELECT %s, %s FROM %s WHERE NOT %s IS NULL'
                         % (rtype, eidcolumn, column, table, column))
             # drop existant columns
-            #if cnx.repo.system_source.dbhelper.alter_column_support:
             for etype in rschema.subjects():
                 DropColumn.get_instance(cnx).add_data((str(etype), rtype))
         else:
@@ -427,7 +427,7 @@
 
 class CWComputedRTypeUpdateOp(MemSchemaOperation):
     """actually update some properties of a computed relation definition"""
-    rschema = entity = rule = None # make pylint happy
+    rschema = entity = rule = None  # make pylint happy
     old_rule = None
 
     def precommit_event(self):
@@ -449,7 +449,7 @@
 
     constraints are handled by specific hooks
     """
-    entity = None # make pylint happy
+    entity = None  # make pylint happy
 
     def init_rdef(self, **kwargs):
         entity = self.entity
@@ -524,7 +524,7 @@
         try:
             eschema = schema.eschema(rdefdef.subject)
         except KeyError:
-            return # entity type currently being added
+            return  # entity type currently being added
         # propagate attribute to children classes
         rschema = schema.rschema(rdefdef.name)
         # if relation type has been inserted in the same transaction, its final
@@ -535,7 +535,7 @@
         if default is not None:
             default = convert_default_value(self.rdefdef, default)
             cnx.system_sql('UPDATE %s SET %s=%%(default)s' % (table, column),
-                               {'default': default})
+                           {'default': default})
         # if attribute is computed, compute it
         if getattr(entity, 'formula', None):
             # add rtype attribute for RelationDefinitionSchema api compat, this
@@ -563,7 +563,7 @@
 
     constraints are handled by specific hooks
     """
-    entity = None # make pylint happy
+    entity = None  # make pylint happy
 
     def precommit_event(self):
         cnx = self.cnx
@@ -607,7 +607,7 @@
 
 class RDefDelOp(MemSchemaOperation):
     """an actual relation has been removed"""
-    rdef = None # make pylint happy
+    rdef = None  # make pylint happy
 
     def precommit_event(self):
         cnx = self.cnx
@@ -670,7 +670,7 @@
 
 class RDefUpdateOp(MemSchemaOperation):
     """actually update some properties of a relation definition"""
-    rschema = rdefkey = values = None # make pylint happy
+    rschema = rdefkey = values = None  # make pylint happy
     rdef = oldvalues = None
     indexed_changed = null_allowed_changed = False
 
@@ -678,15 +678,15 @@
         cnx = self.cnx
         rdef = self.rdef = self.rschema.rdefs[self.rdefkey]
         # update the in-memory schema first
-        self.oldvalues = dict( (attr, getattr(rdef, attr)) for attr in self.values)
+        self.oldvalues = dict((attr, getattr(rdef, attr)) for attr in self.values)
         rdef.update(self.values)
         # then make necessary changes to the system source database
         syssource = cnx.repo.system_source
         if 'indexed' in self.values:
             syssource.update_rdef_indexed(cnx, rdef)
             self.indexed_changed = True
-        if 'cardinality' in self.values and rdef.rtype.final \
-              and self.values['cardinality'][0] != self.oldvalues['cardinality'][0]:
+        if ('cardinality' in self.values and rdef.rtype.final
+                and self.values['cardinality'][0] != self.oldvalues['cardinality'][0]):
             syssource.update_rdef_null_allowed(self.cnx, rdef)
             self.null_allowed_changed = True
         if 'fulltextindexed' in self.values:
@@ -717,7 +717,7 @@
 
 class CWConstraintDelOp(MemSchemaOperation):
     """actually remove a constraint of a relation definition"""
-    rdef = oldcstr = newcstr = None # make pylint happy
+    rdef = oldcstr = newcstr = None  # make pylint happy
     size_cstr_changed = unique_changed = False
 
     def precommit_event(self):
@@ -775,7 +775,7 @@
 
 class CWConstraintAddOp(CWConstraintDelOp):
     """actually update constraint of a relation definition"""
-    entity = None # make pylint happy
+    entity = None  # make pylint happy
 
     def precommit_event(self):
         cnx = self.cnx
@@ -820,7 +820,7 @@
 
 
 class CWUniqueTogetherConstraintAddOp(MemSchemaOperation):
-    entity = None # make pylint happy
+    entity = None  # make pylint happy
 
     def precommit_event(self):
         cnx = self.cnx
@@ -841,8 +841,8 @@
 
 
 class CWUniqueTogetherConstraintDelOp(MemSchemaOperation):
-    entity = cstrname = None # for pylint
-    cols = () # for pylint
+    entity = cstrname = None  # make pylint happy
+    cols = ()  # make pylint happy
 
     def insert_index(self):
         # We need to run before CWConstraintDelOp: if a size constraint is
@@ -873,7 +873,7 @@
 
 class MemSchemaCWETypeDel(MemSchemaOperation):
     """actually remove the entity type from the instance's schema"""
-    etype = None # make pylint happy
+    etype = None  # make pylint happy
 
     def postcommit_event(self):
         # del_entity_type also removes entity's relations
@@ -882,7 +882,7 @@
 
 class MemSchemaCWRTypeAdd(MemSchemaOperation):
     """actually add the relation type to the instance's schema"""
-    rtypedef = None # make pylint happy
+    rtypedef = None  # make pylint happy
 
     def precommit_event(self):
         self.cnx.vreg.schema.add_relation_type(self.rtypedef)
@@ -893,7 +893,7 @@
 
 class MemSchemaCWRTypeDel(MemSchemaOperation):
     """actually remove the relation type from the instance's schema"""
-    rtype = None # make pylint happy
+    rtype = None  # make pylint happy
 
     def postcommit_event(self):
         try:
@@ -906,7 +906,7 @@
 class MemSchemaPermissionAdd(MemSchemaOperation):
     """synchronize schema when a *_permission relation has been added on a group
     """
-    eid = action = group_eid = expr = None # make pylint happy
+    eid = action = group_eid = expr = None  # make pylint happy
 
     def precommit_event(self):
         """the observed connections.cnxset has been commited"""
@@ -961,7 +961,7 @@
 
 
 class MemSchemaSpecializesAdd(MemSchemaOperation):
-    etypeeid = parentetypeeid = None # make pylint happy
+    etypeeid = parentetypeeid = None  # make pylint happy
 
     def precommit_event(self):
         eschema = self.cnx.vreg.schema.schema_by_eid(self.etypeeid)
@@ -973,7 +973,7 @@
 
 
 class MemSchemaSpecializesDel(MemSchemaOperation):
-    etypeeid = parentetypeeid = None # make pylint happy
+    etypeeid = parentetypeeid = None  # make pylint happy
 
     def precommit_event(self):
         try:
@@ -1077,9 +1077,9 @@
             raise validation_error(self.entity, {None: _("can't be deleted")})
         # delete relation definitions using this relation type
         self._cw.execute('DELETE CWAttribute X WHERE X relation_type Y, Y eid %(x)s',
-                        {'x': self.entity.eid})
+                         {'x': self.entity.eid})
         self._cw.execute('DELETE CWRelation X WHERE X relation_type Y, Y eid %(x)s',
-                        {'x': self.entity.eid})
+                         {'x': self.entity.eid})
         MemSchemaCWRTypeDel(self._cw, rtype=name)
 
 
@@ -1185,10 +1185,8 @@
         pendingrdefs = cnx.transaction_data.setdefault('pendingrdefs', set())
         # first delete existing relation if necessary
         if rschema.final:
-            rdeftype = 'CWAttribute'
             pendingrdefs.add((subjschema, rschema))
         else:
-            rdeftype = 'CWRelation'
             pendingrdefs.add((subjschema, rschema, objschema))
         RDefDelOp(cnx, rdef=rdef)
 
@@ -1309,6 +1307,7 @@
         else:
             CWConstraintDelOp(self._cw, rdef=rdef, oldcstr=cstr)
 
+
 # unique_together constraints
 # XXX: use setoperations and before_add_relation here (on constraint_of and relations)
 class AfterAddCWUniqueTogetherConstraintHook(SyncSchemaHook):
@@ -1351,7 +1350,7 @@
         if self._cw.entity_metas(self.eidto)['type'] == 'CWGroup':
             MemSchemaPermissionAdd(self._cw, action=action, eid=self.eidfrom,
                                    group_eid=self.eidto)
-        else: # RQLExpression
+        else:  # RQLExpression
             expr = self._cw.entity_from_eid(self.eidto).expression
             MemSchemaPermissionAdd(self._cw, action=action, eid=self.eidfrom,
                                    expr=expr)
@@ -1372,13 +1371,12 @@
         if self._cw.entity_metas(self.eidto)['type'] == 'CWGroup':
             MemSchemaPermissionDel(self._cw, action=action, eid=self.eidfrom,
                                    group_eid=self.eidto)
-        else: # RQLExpression
+        else:  # RQLExpression
             expr = self._cw.entity_from_eid(self.eidto).expression
             MemSchemaPermissionDel(self._cw, action=action, eid=self.eidfrom,
                                    expr=expr)
 
 
-
 class UpdateFTIndexOp(hook.DataOperationMixIn, hook.SingleLastOperation):
     """operation to update full text indexation of entity whose schema change
 
@@ -1410,11 +1408,8 @@
             cnx.cnxset.commit()
 
 
-
-
 # specializes synchronization hooks ############################################
 
-
 class AfterAddSpecializesHook(SyncSchemaHook):
     __regid__ = 'syncaddspecializes'
     __select__ = SyncSchemaHook.__select__ & hook.match_rtype('specializes')
--- a/cubicweb/hooks/test/unittest_syncschema.py	Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/hooks/test/unittest_syncschema.py	Fri Jul 08 09:59:18 2016 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2014 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.
@@ -17,9 +17,8 @@
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
 """cubicweb.server.hooks.syncschema unit and functional tests"""
 
-from logilab.common.testlib import unittest_main
+from yams.constraints import BoundaryConstraint
 
-from yams.constraints import BoundaryConstraint
 from cubicweb import ValidationError, Binary
 from cubicweb.schema import META_RTYPES
 from cubicweb.devtools import startpgcluster, stoppgcluster, PostgresApptestConfiguration
@@ -87,7 +86,7 @@
             attreid = cnx.execute('INSERT CWAttribute X: X cardinality "11", '
                                   'X defaultval %(default)s, X indexed TRUE, '
                                   'X relation_type RT, X from_entity E, X to_entity F '
-                                   'WHERE RT name "name", E name "Societe2", '
+                                  'WHERE RT name "name", E name "Societe2", '
                                   'F name "String"',
                                    {'default': Binary.zpickle('noname')})[0][0]
             self._set_attr_perms(cnx, attreid)
@@ -111,8 +110,8 @@
             self.assertEqual(rset.rows, [[s2eid]])
             # check that when a relation definition is deleted, existing relations are deleted
             rdefeid = cnx.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, '
-                                   '   X from_entity E, X to_entity E '
-                                   'WHERE RT name "concerne2", E name "CWUser"')[0][0]
+                                  '   X from_entity E, X to_entity E '
+                                  'WHERE RT name "concerne2", E name "CWUser"')[0][0]
             self._set_perms(cnx, rdefeid)
             cnx.commit()
             cnx.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid})
@@ -136,10 +135,10 @@
         with self.admin_access.repo_cnx() as cnx:
             META_RTYPES.add('custom_meta')
             cnx.execute('INSERT CWRType X: X name "custom_meta", X description "", '
-                         'X final FALSE, X symmetric FALSE')
+                        'X final FALSE, X symmetric FALSE')
             cnx.commit()
             eeid = cnx.execute('INSERT CWEType X: X name "NEWEtype", '
-                                'X description "", X final FALSE')[0][0]
+                               'X description "", X final FALSE')[0][0]
             self._set_perms(cnx, eeid)
             cnx.commit()
             META_RTYPES.remove('custom_meta')
@@ -148,15 +147,15 @@
         with self.admin_access.repo_cnx() as cnx:
             META_RTYPES.add('custom_meta')
             cnx.execute('INSERT CWRType X: X name "custom_meta", X description "", '
-                         'X final FALSE, X symmetric FALSE')
+                        'X final FALSE, X symmetric FALSE')
             cnx.commit()
             rdefeid = cnx.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, '
-                                   '   X from_entity E, X to_entity E '
-                                   'WHERE RT name "custom_meta", E name "CWUser"')[0][0]
+                                  '   X from_entity E, X to_entity E '
+                                  'WHERE RT name "custom_meta", E name "CWUser"')[0][0]
             self._set_perms(cnx, rdefeid)
             cnx.commit()
             eeid = cnx.execute('INSERT CWEType X: X name "NEWEtype", '
-                                'X description "", X final FALSE')[0][0]
+                               'X description "", X final FALSE')[0][0]
             self._set_perms(cnx, eeid)
             cnx.commit()
             META_RTYPES.remove('custom_meta')
@@ -178,14 +177,14 @@
                                                     'S name N')]
             self.assertIn('subdiv', snames)
 
-
     def test_perms_synchronization_1(self):
         with self.admin_access.repo_cnx() as cnx:
             schema = self.repo.schema
             self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers', 'users')))
             self.assertTrue(cnx.execute('Any X, Y WHERE X is CWEType, X name "CWUser", '
                                         'Y is CWGroup, Y name "users"')[0])
-            cnx.execute('DELETE X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"')
+            cnx.execute('DELETE X read_permission Y '
+                        'WHERE X is CWEType, X name "CWUser", Y name "users"')
             self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers', 'users', )))
             cnx.commit()
             self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers',)))
@@ -228,7 +227,7 @@
             cnx.execute('DELETE X read_permission Y WHERE X eid %s' % eeid)
             cnx.execute('SET X final FALSE WHERE X eid %s' % eeid)
             cnx.execute('SET X read_permission Y WHERE X eid %s, Y eid in (%s, %s)'
-                         % (eeid, groupeids[0], groupeids[1]))
+                        % (eeid, groupeids[0], groupeids[1]))
             cnx.commit()
             cnx.execute('Any X WHERE X is CWEType, X name "CWEType"')
 
@@ -244,7 +243,7 @@
                 self.assertFalse(self.schema['state_of'].inlined)
                 self.assertFalse(self.index_exists(cnx, 'State', 'state_of'))
                 rset = cnx.execute('Any X, Y WHERE X state_of Y')
-                self.assertEqual(len(rset), 2) # user states
+                self.assertEqual(len(rset), 2)  # user states
             finally:
                 cnx.execute('SET X inlined TRUE WHERE X name "state_of"')
                 self.assertFalse(self.schema['state_of'].inlined)
@@ -293,8 +292,8 @@
     def test_required_change_1(self):
         with self.admin_access.repo_cnx() as cnx:
             cnx.execute('SET DEF cardinality "?1" '
-                         'WHERE DEF relation_type RT, DEF from_entity E,'
-                         'RT name "title", E name "Bookmark"')
+                        'WHERE DEF relation_type RT, DEF from_entity E,'
+                        'RT name "title", E name "Bookmark"')
             cnx.commit()
             # should now be able to add bookmark without title
             cnx.execute('INSERT Bookmark X: X path "/view"')
@@ -303,24 +302,25 @@
     def test_required_change_2(self):
         with self.admin_access.repo_cnx() as cnx:
             cnx.execute('SET DEF cardinality "11" '
-                         'WHERE DEF relation_type RT, DEF from_entity E,'
-                         'RT name "surname", E name "CWUser"')
+                        'WHERE DEF relation_type RT, DEF from_entity E,'
+                        'RT name "surname", E name "CWUser"')
             cnx.execute('SET U surname "Doe" WHERE U surname NULL')
             cnx.commit()
             # should not be able anymore to add cwuser without surname
             self.assertRaises(ValidationError, self.create_user, cnx, "toto")
             cnx.rollback()
             cnx.execute('SET DEF cardinality "?1" '
-                         'WHERE DEF relation_type RT, DEF from_entity E,'
-                         'RT name "surname", E name "CWUser"')
+                        'WHERE DEF relation_type RT, DEF from_entity E,'
+                        'RT name "surname", E name "CWUser"')
             cnx.commit()
 
     def test_add_attribute_to_base_class(self):
         with self.admin_access.repo_cnx() as cnx:
-            attreid = cnx.execute('INSERT CWAttribute X: X cardinality "11", X defaultval %(default)s, '
-                                   'X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F '
-                                   'WHERE RT name "messageid", E name "BaseTransition", F name "String"',
-                                   {'default': Binary.zpickle('noname')})[0][0]
+            attreid = cnx.execute(
+                'INSERT CWAttribute X: X cardinality "11", X defaultval %(default)s, '
+                'X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F '
+                'WHERE RT name "messageid", E name "BaseTransition", F name "String"',
+                {'default': Binary.zpickle('noname')})[0][0]
             assert cnx.execute('SET X read_permission Y WHERE X eid %(x)s, Y name "managers"',
                                {'x': attreid})
             cnx.commit()
@@ -357,12 +357,12 @@
             rset = cnx.execute('Any X WHERE X has_text "rick.roll"')
             self.assertIn(cnx.user.eid, [item[0] for item in rset])
             assert cnx.execute('SET R fulltext_container NULL '
-                                'WHERE R name "use_email"')
+                               'WHERE R name "use_email"')
             cnx.commit()
             rset = cnx.execute('Any X WHERE X has_text "rick.roll"')
             self.assertIn(target.eid, [item[0] for item in rset])
             assert cnx.execute('SET R fulltext_container "subject" '
-                                'WHERE R name "use_email"')
+                               'WHERE R name "use_email"')
             cnx.commit()
             rset = cnx.execute('Any X WHERE X has_text "rick.roll"')
             self.assertIn(cnx.user.eid, [item[0] for item in rset])
@@ -375,10 +375,10 @@
                 # bug in schema reloading, constraint's eid not restored
                 self.skipTest('start me alone')
             cnx.execute('SET X value %(v)s WHERE X eid %(x)s',
-                         {'x': cstr.eid, 'v': u"u'normal', u'auto', u'new'"})
+                        {'x': cstr.eid, 'v': u"u'normal', u'auto', u'new'"})
             cnx.execute('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, '
                         'EDEF constrained_by X WHERE CT name %(ct)s, EDEF eid %(x)s',
-                         {'ct': 'SizeConstraint', 'value': u'max=10', 'x': rdef.eid})
+                        {'ct': 'SizeConstraint', 'value': u'max=10', 'x': rdef.eid})
             cnx.commit()
             cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
             self.assertEqual(cstr.values, (u'normal', u'auto', u'new'))
@@ -405,4 +405,5 @@
 
 
 if __name__ == '__main__':
-    unittest_main()
+    import unittest
+    unittest.main()
--- a/cubicweb/schema.py	Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/schema.py	Fri Jul 08 09:59:18 2016 +0200
@@ -32,16 +32,15 @@
 from logilab.common import tempattr
 from logilab.common.decorators import cached, clear_cache, monkeypatch, cachedproperty
 from logilab.common.logging_ext import set_log_methods
-from logilab.common.deprecation import deprecated, class_moved, moved
+from logilab.common.deprecation import deprecated
 from logilab.common.textutils import splitstrip
 from logilab.common.graph import get_cycles
 
 import yams
 from yams import BadSchemaDefinition, buildobjs as ybo
 from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema, \
-     RelationDefinitionSchema, PermissionMixIn, role_name
-from yams.constraints import (BaseConstraint, FormatConstraint, BoundaryConstraint,
-                              IntervalBoundConstraint, StaticVocabularyConstraint,
+    RelationDefinitionSchema, PermissionMixIn, role_name
+from yams.constraints import (BaseConstraint, FormatConstraint,
                               cstr_json_dumps, cstr_json_loads)
 from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader,
                          cleanup_sys_modules, fill_schema_from_namespace)
@@ -68,7 +67,7 @@
 META_RTYPES = set((
     'owned_by', 'created_by', 'is', 'is_instance_of', 'identity',
     'eid', 'creation_date', 'cw_source', 'modification_date', 'has_text', 'cwuri',
-    ))
+))
 WORKFLOW_RTYPES = set(('custom_workflow', 'in_state', 'wf_info_for'))
 WORKFLOW_DEF_RTYPES = set(('workflow_of', 'state_of', 'transition_of',
                            'initial_state', 'default_workflow',
@@ -98,7 +97,7 @@
     'constraint_of', 'relations',
     'read_permission', 'add_permission',
     'delete_permission', 'update_permission',
-    ))
+))
 
 WORKFLOW_TYPES = set(('Transition', 'State', 'TrInfo', 'Workflow',
                       'WorkflowTransition', 'BaseTransition',
@@ -117,11 +116,13 @@
 ybo.ETYPE_PROPERTIES += ('eid',)
 ybo.RTYPE_PROPERTIES += ('eid',)
 
+
 def build_schema_from_namespace(items):
     schema = CubicWebSchema('noname')
     fill_schema_from_namespace(schema, items, register_base_types=False)
     return schema
 
+
 # Bases for manipulating RQL in schema #########################################
 
 def guess_rrqlexpr_mainvars(expression):
@@ -138,6 +139,7 @@
                                   % expression)
     return mainvars
 
+
 def split_expression(rqlstring):
     for expr in rqlstring.split(','):
         for noparen1 in expr.split('('):
@@ -145,6 +147,7 @@
                 for word in noparen2.split():
                     yield word
 
+
 def normalize_expression(rqlstring):
     """normalize an rql expression to ease schema synchronization (avoid
     suppressing and reinserting an expression if only a space has been
@@ -163,35 +166,35 @@
     if len(formula_rqlst.children) != 1:
         raise BadSchemaDefinition('computed attribute %(attr)s on %(etype)s: '
                                   'can not use UNION in formula %(form)r' %
-                                  {'attr' : rdef.rtype,
-                                   'etype' : rdef.subject.type,
-                                   'form' : rdef.formula})
+                                  {'attr': rdef.rtype,
+                                   'etype': rdef.subject.type,
+                                   'form': rdef.formula})
     select = formula_rqlst.children[0]
     if len(select.selection) != 1:
         raise BadSchemaDefinition('computed attribute %(attr)s on %(etype)s: '
                                   'can only select one term in formula %(form)r' %
-                                  {'attr' : rdef.rtype,
-                                   'etype' : rdef.subject.type,
-                                   'form' : rdef.formula})
+                                  {'attr': rdef.rtype,
+                                   'etype': rdef.subject.type,
+                                   'form': rdef.formula})
     term = select.selection[0]
     types = set(term.get_type(sol) for sol in select.solutions)
     if len(types) != 1:
         raise BadSchemaDefinition('computed attribute %(attr)s on %(etype)s: '
                                   'multiple possible types (%(types)s) for formula %(form)r' %
-                                  {'attr' : rdef.rtype,
-                                   'etype' : rdef.subject.type,
-                                   'types' : list(types),
-                                   'form' : rdef.formula})
+                                  {'attr': rdef.rtype,
+                                   'etype': rdef.subject.type,
+                                   'types': list(types),
+                                   'form': rdef.formula})
     computed_type = types.pop()
     expected_type = rdef.object.type
     if computed_type != expected_type:
         raise BadSchemaDefinition('computed attribute %(attr)s on %(etype)s: '
                                   'computed attribute type (%(comp_type)s) mismatch with '
                                   'specified type (%(attr_type)s)' %
-                                  {'attr' : rdef.rtype,
-                                   'etype' : rdef.subject.type,
-                                   'comp_type' : computed_type,
-                                   'attr_type' : expected_type})
+                                  {'attr': rdef.rtype,
+                                   'etype': rdef.subject.type,
+                                   'comp_type': computed_type,
+                                   'attr_type': expected_type})
 
 
 class RQLExpression(object):
@@ -200,7 +203,7 @@
     """
     # these are overridden by set_log_methods below
     # only defining here to prevent pylint from complaining
-    info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
+    info = warning = error = critical = exception = debug = lambda msg, *a, **kw: None
     # to be defined in concrete classes
     predefined_variables = None
 
@@ -222,7 +225,7 @@
         :param mainvars: names of the variables being selected.
 
         """
-        self.eid = eid # eid of the entity representing this rql expression
+        self.eid = eid  # eid of the entity representing this rql expression
         assert mainvars, 'bad mainvars %s' % mainvars
         if isinstance(mainvars, string_types):
             mainvars = set(splitstrip(mainvars))
@@ -268,8 +271,10 @@
 
     def __deepcopy__(self, memo):
         return self.__class__(self.expression, self.mainvars)
+
     def __getstate__(self):
         return (self.expression, self.mainvars)
+
     def __setstate__(self, state):
         self.__init__(*state)
 
@@ -280,7 +285,8 @@
         defined = set(split_expression(self.expression))
         for varname in self.predefined_variables:
             if varname in defined:
-                select.add_eid_restriction(select.get_variable(varname), varname.lower(), 'Substitute')
+                select.add_eid_restriction(select.get_variable(varname), varname.lower(),
+                                           'Substitute')
         return select
 
     # permission rql expression specific stuff #################################
@@ -298,8 +304,8 @@
                     prefix, action, suffix = rel.r_type.split('_')
                 except ValueError:
                     continue
-                if prefix != 'has' or suffix != 'permission' or \
-                       not action in ('add', 'delete', 'update', 'read'):
+                if (prefix != 'has' or suffix != 'permission' or
+                        action not in ('add', 'delete', 'update', 'read')):
                     continue
                 if found is None:
                     found = []
@@ -399,7 +405,6 @@
                                     self.expression)
 
 
-
 # rql expressions for use in permission definition #############################
 
 class ERQLExpression(RQLExpression):
@@ -414,7 +419,7 @@
                 if creating:
                     return self._check(_cw, creating=True, **kwargs)
                 return False
-            assert creating == False
+            assert not creating
             return self._check(_cw, x=eid, **kwargs)
         return self._check(_cw, **kwargs)
 
@@ -434,11 +439,9 @@
 
     def check_permission_definitions(self):
         super(CubicWebRelationDefinitionSchema, self).check_permission_definitions()
-        schema = self.subject.schema
         for action, groups in self.permissions.items():
             for group_or_rqlexpr in groups:
-                if action == 'read' and \
-                       isinstance(group_or_rqlexpr, RQLExpression):
+                if action == 'read' and isinstance(group_or_rqlexpr, RQLExpression):
                     msg = "can't use rql expression for read permission of %s"
                     raise BadSchemaDefinition(msg % self)
                 if self.final and isinstance(group_or_rqlexpr, RRQLExpression):
@@ -448,6 +451,7 @@
                     msg = "can't use ERQLExpression on %s, use a RRQLExpression"
                     raise BadSchemaDefinition(msg % self)
 
+
 def vargraph(rqlst):
     """ builds an adjacency graph of variables from the rql syntax tree, e.g:
     Any O,S WHERE T subworkflow_exit S, T subworkflow WF, O state_of WF
@@ -463,7 +467,6 @@
         else:
             vargraph.setdefault(lhsvarname, []).append(rhsvarname)
             vargraph.setdefault(rhsvarname, []).append(lhsvarname)
-            #vargraph[(lhsvarname, rhsvarname)] = relation.r_type
     return vargraph
 
 
@@ -512,31 +515,32 @@
 
 
 PUB_SYSTEM_ENTITY_PERMS = {
-    'read':   ('managers', 'users', 'guests',),
-    'add':    ('managers',),
+    'read': ('managers', 'users', 'guests',),
+    'add': ('managers',),
     'delete': ('managers',),
     'update': ('managers',),
-    }
+}
 PUB_SYSTEM_REL_PERMS = {
-    'read':   ('managers', 'users', 'guests',),
-    'add':    ('managers',),
+    'read': ('managers', 'users', 'guests',),
+    'add': ('managers',),
     'delete': ('managers',),
-    }
+}
 PUB_SYSTEM_ATTR_PERMS = {
-    'read':   ('managers', 'users', 'guests',),
+    'read': ('managers', 'users', 'guests',),
     'add': ('managers',),
     'update': ('managers',),
-    }
+}
 RO_REL_PERMS = {
-    'read':   ('managers', 'users', 'guests',),
-    'add':    (),
+    'read': ('managers', 'users', 'guests',),
+    'add': (),
     'delete': (),
-    }
+}
 RO_ATTR_PERMS = {
-    'read':   ('managers', 'users', 'guests',),
+    'read': ('managers', 'users', 'guests',),
     'add': ybo.DEFAULT_ATTRPERMS['add'],
     'update': (),
-    }
+}
+
 
 # XXX same algorithm as in reorder_cubes and probably other place,
 # may probably extract a generic function
@@ -569,6 +573,7 @@
                         continue
     return eschemas
 
+
 def bw_normalize_etype(etype):
     if etype in ETYPE_NAME_MAP:
         msg = '%s has been renamed to %s, please update your code' % (
@@ -577,6 +582,7 @@
         etype = ETYPE_NAME_MAP[etype]
     return etype
 
+
 def display_name(req, key, form='', context=None):
     """return a internationalized string for the key (schema entity or relation
     name) in a given form
@@ -602,6 +608,7 @@
     return display_name(req, self.type, form, context)
 ERSchema.display_name = ERSchema_display_name
 
+
 @cached
 def get_groups(self, action):
     """return the groups authorized to perform <action> on entities of
@@ -614,13 +621,13 @@
     :return: names of the groups with the given permission
     """
     assert action in self.ACTIONS, action
-    #assert action in self._groups, '%s %s' % (self, action)
     try:
         return frozenset(g for g in self.permissions[action] if isinstance(g, string_types))
     except KeyError:
         return ()
 PermissionMixIn.get_groups = get_groups
 
+
 @cached
 def get_rqlexprs(self, action):
     """return the rql expressions representing queries to check the user is allowed
@@ -633,14 +640,13 @@
     :return: the rql expressions with the given permission
     """
     assert action in self.ACTIONS, action
-    #assert action in self._rqlexprs, '%s %s' % (self, action)
     try:
         return tuple(g for g in self.permissions[action] if not isinstance(g, string_types))
     except KeyError:
         return ()
 PermissionMixIn.get_rqlexprs = get_rqlexprs
 
-orig_set_action_permissions = PermissionMixIn.set_action_permissions
+
 def set_action_permissions(self, action, permissions):
     """set the groups and rql expressions allowing to perform <action> on
     entities of this type
@@ -654,8 +660,10 @@
     orig_set_action_permissions(self, action, tuple(permissions))
     clear_cache(self, 'get_rqlexprs')
     clear_cache(self, 'get_groups')
+orig_set_action_permissions = PermissionMixIn.set_action_permissions
 PermissionMixIn.set_action_permissions = set_action_permissions
 
+
 def has_local_role(self, action):
     """return true if the action *may* be granted locally (i.e. either rql
     expressions or the owners group are used in security definition)
@@ -671,6 +679,7 @@
     return False
 PermissionMixIn.has_local_role = has_local_role
 
+
 def may_have_permission(self, action, req):
     if action != 'read' and not (self.has_local_role('read') or
                                  self.has_perm(req, 'read')):
@@ -678,6 +687,7 @@
     return self.has_local_role(action) or self.has_perm(req, action)
 PermissionMixIn.may_have_permission = may_have_permission
 
+
 def has_perm(self, _cw, action, **kwargs):
     """return true if the action is granted globally or locally"""
     try:
@@ -713,8 +723,8 @@
     # NB: give _cw to user.owns since user is not be bound to a transaction on
     # the repository side
     if 'owners' in groups and (
-          kwargs.get('creating')
-          or ('eid' in kwargs and _cw.user.owns(kwargs['eid']))):
+            kwargs.get('creating')
+            or ('eid' in kwargs and _cw.user.owns(kwargs['eid']))):
         if DBG:
             print('check_perm: %r %r: user is owner or creation time' %
                   (action, _self_str))
@@ -873,7 +883,7 @@
             # avoid deleting the relation type accidentally...
             self.schema['has_text'].del_relation_def(self, self.schema['String'])
 
-    def schema_entity(self): # XXX @property for consistency with meta
+    def schema_entity(self):  # XXX @property for consistency with meta
         """return True if this entity type is used to build the schema"""
         return self.type in SCHEMA_TYPES
 
@@ -911,7 +921,7 @@
     def meta(self):
         return self.type in META_RTYPES
 
-    def schema_relation(self): # XXX @property for consistency with meta
+    def schema_relation(self):  # XXX @property for consistency with meta
         """return True if this relation type is used to build the schema"""
         return self.type in SCHEMA_TYPES
 
@@ -937,7 +947,7 @@
             else:
                 subjtype = objtype = None
         else:
-            assert not 'eid' in kwargs, kwargs
+            assert 'eid' not in kwargs, kwargs
             assert action in ('read', 'add', 'delete')
             if 'fromeid' in kwargs:
                 subjtype = _cw.entity_metas(kwargs['fromeid'])['type']
@@ -1001,6 +1011,7 @@
         rschema.final = False
 
     etype_name_re = r'[A-Z][A-Za-z0-9]*[a-z]+[A-Za-z0-9]*$'
+
     def add_entity_type(self, edef):
         edef.name = str(edef.name)
         edef.name = bw_normalize_etype(edef.name)
@@ -1056,7 +1067,7 @@
             try:
                 self._eid_index[rdef.eid] = rdefs
             except AttributeError:
-                pass # not a serialized schema
+                pass  # not a serialized schema
         return rdefs
 
     def del_relation_type(self, rtype):
@@ -1112,8 +1123,7 @@
             select.add_type_restriction(select.defined_vars['X'], str(rdef.subject))
             analyzer.visit(select)
             _check_valid_formula(rdef, rqlst)
-            rdef.formula_select = select # avoid later recomputation
-
+            rdef.formula_select = select  # avoid later recomputation
 
     def finalize_computed_relations(self):
         """Build relation definitions for computed relations
@@ -1209,7 +1219,7 @@
     def repo_check(self, session, eidfrom, rtype, eidto):
         """raise ValidationError if the relation doesn't satisfy the constraint
         """
-        pass # this is a vocabulary constraint, not enforced
+        pass  # this is a vocabulary constraint, not enforced
 
 
 class RepoEnforcedRQLConstraintMixIn(object):
@@ -1304,6 +1314,7 @@
 
 from yams.buildobjs import _add_relation as yams_add_relation
 
+
 class workflowable_definition(ybo.metadefinition):
     """extends default EntityType's metaclass to add workflow relations
     (i.e. in_state, wf_info_for and custom_workflow). This is the default
@@ -1352,7 +1363,8 @@
 CONSTRAINTS['RQLConstraint'] = RQLConstraint
 CONSTRAINTS['RQLUniqueConstraint'] = RQLUniqueConstraint
 CONSTRAINTS['RQLVocabularyConstraint'] = RQLVocabularyConstraint
-CONSTRAINTS.pop('MultipleStaticVocabularyConstraint', None) # don't want this in cw yams schema
+# don't want MultipleStaticVocabularyConstraint in cw yams schema
+CONSTRAINTS.pop('MultipleStaticVocabularyConstraint', None)
 PyFileReader.context.update(CONSTRAINTS)
 
 
@@ -1373,7 +1385,7 @@
         # bootstraping, ignore cubes
         filepath = join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'bootstrap.py')
         self.info('loading %s', filepath)
-        with tempattr(ybo, 'PACKAGE', 'cubicweb'): # though we don't care here
+        with tempattr(ybo, 'PACKAGE', 'cubicweb'):  # though we don't care here
             self.handle_file(filepath)
 
     def unhandled_file(self, filepath):
@@ -1382,7 +1394,8 @@
 
     # these are overridden by set_log_methods below
     # only defining here to prevent pylint from complaining
-    info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
+    info = warning = error = critical = exception = debug = lambda msg, *a, **kw: None
+
 
 class CubicWebSchemaLoader(BootstrapSchemaLoader):
     """cubicweb specific schema loader, automatically adding metadata to the
@@ -1423,7 +1436,7 @@
 
     # these are overridden by set_log_methods below
     # only defining here to prevent pylint from complaining
-    info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
+    info = warning = error = critical = exception = debug = lambda msg, *a, **kw: None
 
 
 set_log_methods(CubicWebSchemaLoader, getLogger('cubicweb.schemaloader'))
@@ -1435,6 +1448,7 @@
 MAY_USE_TEMPLATE_FORMAT = set(('managers',))
 NEED_PERM_FORMATS = [_('text/cubicweb-page-template')]
 
+
 @monkeypatch(FormatConstraint)
 def vocabulary(self, entity=None, form=None):
     cw = None
@@ -1443,11 +1457,11 @@
     elif form is not None:
         cw = form._cw
     if cw is not None:
-        if hasattr(cw, 'write_security'): # test it's a session and not a request
+        if hasattr(cw, 'write_security'):  # test it's a session and not a request
             # cw is a server session
-            hasperm = not cw.write_security or \
-                      not cw.is_hook_category_activated('integrity') or \
-                      cw.user.matching_groups(MAY_USE_TEMPLATE_FORMAT)
+            hasperm = (not cw.write_security or
+                       not cw.is_hook_category_activated('integrity') or
+                       cw.user.matching_groups(MAY_USE_TEMPLATE_FORMAT))
         else:
             hasperm = cw.user.matching_groups(MAY_USE_TEMPLATE_FORMAT)
         if hasperm:
@@ -1456,22 +1470,27 @@
 
 # XXX itou for some Statement methods
 from rql import stmts
-orig_get_etype = stmts.ScopeNode.get_etype
+
+
 def bw_get_etype(self, name):
     return orig_get_etype(self, bw_normalize_etype(name))
+orig_get_etype = stmts.ScopeNode.get_etype
 stmts.ScopeNode.get_etype = bw_get_etype
 
-orig_add_main_variable_delete = stmts.Delete.add_main_variable
+
 def bw_add_main_variable_delete(self, etype, vref):
     return orig_add_main_variable_delete(self, bw_normalize_etype(etype), vref)
+orig_add_main_variable_delete = stmts.Delete.add_main_variable
 stmts.Delete.add_main_variable = bw_add_main_variable_delete
 
-orig_add_main_variable_insert = stmts.Insert.add_main_variable
+
 def bw_add_main_variable_insert(self, etype, vref):
     return orig_add_main_variable_insert(self, bw_normalize_etype(etype), vref)
+orig_add_main_variable_insert = stmts.Insert.add_main_variable
 stmts.Insert.add_main_variable = bw_add_main_variable_insert
 
-orig_set_statement_type = stmts.Select.set_statement_type
+
 def bw_set_statement_type(self, etype):
     return orig_set_statement_type(self, bw_normalize_etype(etype))
+orig_set_statement_type = stmts.Select.set_statement_type
 stmts.Select.set_statement_type = bw_set_statement_type
--- a/cubicweb/server/__init__.py	Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/server/__init__.py	Fri Jul 08 09:59:18 2016 +0200
@@ -24,9 +24,6 @@
 
 __docformat__ = "restructuredtext en"
 
-import sys
-from os.path import join, exists
-from glob import glob
 from contextlib import contextmanager
 
 from six import text_type, string_types
@@ -39,9 +36,9 @@
 
 from yams import BASE_GROUPS
 
-from cubicweb import CW_SOFTWARE_ROOT
 from cubicweb.appobject import AppObject
 
+
 class ShuttingDown(BaseException):
     """raised when trying to access some resources while the repository is
     shutting down. Inherit from BaseException so that `except Exception` won't
@@ -90,7 +87,7 @@
 #: more verbosity
 DBG_MORE = 128
 #: all level enabled
-DBG_ALL  = DBG_RQL + DBG_SQL + DBG_REPO + DBG_MS + DBG_HOOKS + DBG_OPS + DBG_SEC + DBG_MORE
+DBG_ALL = DBG_RQL + DBG_SQL + DBG_REPO + DBG_MS + DBG_HOOKS + DBG_OPS + DBG_SEC + DBG_MORE
 
 _SECURITY_ITEMS = []
 _SECURITY_CAPS = ['read', 'add', 'update', 'delete', 'transition']
@@ -98,6 +95,7 @@
 #: current debug mode
 DEBUG = 0
 
+
 @contextmanager
 def tunesecurity(items=(), capabilities=()):
     """Context manager to use in conjunction with DBG_SEC.
@@ -136,6 +134,7 @@
     _SECURITY_ITEMS[:] = olditems
     _SECURITY_CAPS[:] = oldactions
 
+
 def set_debug(debugmode):
     """change the repository debugging mode"""
     global DEBUG
@@ -148,6 +147,7 @@
     else:
         DEBUG |= debugmode
 
+
 class debugged(object):
     """Context manager and decorator to help debug the repository.
 
@@ -184,7 +184,6 @@
     def __call__(self, func):
         """decorate function"""
         def wrapped(*args, **kwargs):
-            _clevel = DEBUG
             set_debug(self.debugmode)
             try:
                 return func(*args, **kwargs)
@@ -192,6 +191,7 @@
                 set_debug(self._clevel)
         return wrapped
 
+
 # database initialization ######################################################
 
 def create_user(session, login, pwd, *groups):
@@ -203,6 +203,7 @@
                         {'u': user.eid, 'group': text_type(group)})
     return user
 
+
 def init_repository(config, interactive=True, drop=False, vreg=None,
                     init_config=None):
     """initialise a repository database by creating tables add filling them
@@ -289,18 +290,18 @@
             cnx.create_entity('CWGroup', name=text_type(group))
         admin = create_user(cnx, login, pwd, u'managers')
         cnx.execute('SET X owned_by U WHERE X is IN (CWGroup,CWSource), U eid %(u)s',
-                        {'u': admin.eid})
+                    {'u': admin.eid})
         cnx.commit()
     repo.shutdown()
     # re-login using the admin user
-    config._cubes = None # avoid assertion error
+    config._cubes = None  # avoid assertion error
     repo = get_repository(config=config)
     # replace previous schema by the new repo's one. This is necessary so that we give the proper
     # schema to `initialize_schema` above since it will initialize .eid attribute of schema elements
     schema = repo.schema
     with connect(repo, login, password=pwd) as cnx:
         with cnx.security_enabled(False, False):
-            repo.system_source.eid = ssource.eid # redo this manually
+            repo.system_source.eid = ssource.eid  # redo this manually
             handler = config.migration_handler(schema, interactive=False,
                                                cnx=cnx, repo=repo)
             # serialize the schema
@@ -348,7 +349,7 @@
 
 
 # sqlite'stored procedures have to be registered at connection opening time
-from logilab.database import SQL_CONNECT_HOOKS
+from logilab.database import SQL_CONNECT_HOOKS  # noqa
 
 # add to this set relations which should have their add security checking done
 # *BEFORE* adding the actual relation (done after by default)
--- a/cubicweb/server/sources/native.py	Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/server/sources/native.py	Fri Jul 08 09:59:18 2016 +0200
@@ -70,6 +70,7 @@
 NONSYSTEM_ETYPES = set()
 NONSYSTEM_RELATIONS = set()
 
+
 class LogCursor(object):
     def __init__(self, cursor):
         self.cu = cursor
@@ -142,12 +143,13 @@
     """check linked entity has not been redirected for this relation"""
     card = rdef.role_cardinality(role)
     if card in '?1' and tentity.related(rdef.rtype, role):
-        raise _UndoException(tentity._cw._(
+        msg = tentity._cw._(
             "Can't restore %(role)s relation %(rtype)s to entity %(eid)s which "
             "is already linked using this relation.")
-                            % {'role': neg_role(role),
-                               'rtype': rdef.rtype,
-                               'eid': tentity.eid})
+        raise _UndoException(msg % {'role': neg_role(role),
+                                    'rtype': rdef.rtype,
+                                    'eid': tentity.eid})
+
 
 def _undo_rel_info(cnx, subj, rtype, obj):
     entities = []
@@ -155,26 +157,27 @@
         try:
             entities.append(cnx.entity_from_eid(eid))
         except UnknownEid:
-            raise _UndoException(cnx._(
+            msg = cnx._(
                 "Can't restore relation %(rtype)s, %(role)s entity %(eid)s"
                 " doesn't exist anymore.")
-                                % {'role': cnx._(role),
-                                   'rtype': cnx._(rtype),
-                                   'eid': eid})
+            raise _UndoException(msg % {'role': cnx._(role),
+                                        'rtype': cnx._(rtype),
+                                        'eid': eid})
     sentity, oentity = entities
     try:
         rschema = cnx.vreg.schema.rschema(rtype)
         rdef = rschema.rdefs[(sentity.cw_etype, oentity.cw_etype)]
     except KeyError:
-        raise _UndoException(cnx._(
+        msg = cnx._(
             "Can't restore relation %(rtype)s between %(subj)s and "
             "%(obj)s, that relation does not exists anymore in the "
             "schema.")
-                            % {'rtype': cnx._(rtype),
-                               'subj': subj,
-                               'obj': obj})
+        raise _UndoException(msg % {'rtype': cnx._(rtype),
+                                    'subj': subj,
+                                    'obj': obj})
     return sentity, oentity, rdef
 
+
 def _undo_has_later_transaction(cnx, eid):
     return cnx.system_sql('''\
 SELECT T.tx_uuid FROM transactions AS TREF, transactions AS T
@@ -270,56 +273,56 @@
     sqlgen_class = SQLGenerator
     options = (
         ('db-driver',
-         {'type' : 'string',
+         {'type': 'string',
           'default': 'postgres',
           # XXX use choice type
           'help': 'database driver (postgres, sqlite, sqlserver2005)',
           'group': 'native-source', 'level': 0,
           }),
         ('db-host',
-         {'type' : 'string',
+         {'type': 'string',
           'default': '',
           'help': 'database host',
           'group': 'native-source', 'level': 1,
           }),
         ('db-port',
-         {'type' : 'string',
+         {'type': 'string',
           'default': '',
           'help': 'database port',
           'group': 'native-source', 'level': 1,
           }),
         ('db-name',
-         {'type' : 'string',
+         {'type': 'string',
           'default': Method('default_instance_id'),
           'help': 'database name',
           'group': 'native-source', 'level': 0,
           }),
         ('db-namespace',
-         {'type' : 'string',
+         {'type': 'string',
           'default': '',
           'help': 'database namespace (schema) name',
           'group': 'native-source', 'level': 1,
           }),
         ('db-user',
-         {'type' : 'string',
+         {'type': 'string',
           'default': CubicWebNoAppConfiguration.mode == 'user' and getlogin() or 'cubicweb',
           'help': 'database user',
           'group': 'native-source', 'level': 0,
           }),
         ('db-password',
-         {'type' : 'password',
+         {'type': 'password',
           'default': '',
           'help': 'database password',
           'group': 'native-source', 'level': 0,
           }),
         ('db-encoding',
-         {'type' : 'string',
+         {'type': 'string',
           'default': 'utf8',
           'help': 'database encoding',
           'group': 'native-source', 'level': 1,
           }),
         ('db-extra-arguments',
-         {'type' : 'string',
+         {'type': 'string',
           'default': '',
           'help': 'set to "Trusted_Connection" if you are using SQLServer and '
                   'want trusted authentication for the database connection',
@@ -421,7 +424,6 @@
         else:
             raise ValueError('Unknown format %r' % format)
 
-
     def restore(self, backupfile, confirm, drop, format='native'):
         """method called to restore a backup of source's data"""
         if self.repo.config.init_cnxset_pool:
@@ -438,13 +440,12 @@
             if self.repo.config.init_cnxset_pool:
                 self.open_source_connections()
 
-
     def init(self, activated, source_entity):
         try:
             # test if 'asource' column exists
             query = self.dbhelper.sql_add_limit_offset('SELECT asource FROM entities', 1)
             source_entity._cw.system_sql(query)
-        except Exception as ex:
+        except Exception:
             self.eid_type_source = self.eid_type_source_pre_131
         super(NativeSQLSource, self).init(activated, source_entity)
         self.init_creating(source_entity._cw.cnxset)
@@ -499,7 +500,7 @@
         try:
             self._rql_sqlgen.schema = schema
         except AttributeError:
-            pass # __init__
+            pass  # __init__
         for authentifier in self.authentifiers:
             authentifier.set_schema(self.schema)
         clear_cache(self, 'need_fti_indexation')
@@ -508,17 +509,17 @@
         """return true if the given entity's type is handled by this adapter
         if write is true, return true only if it's a RW support
         """
-        return not etype in NONSYSTEM_ETYPES
+        return etype not in NONSYSTEM_ETYPES
 
     def support_relation(self, rtype, write=False):
         """return true if the given relation's type is handled by this adapter
         if write is true, return true only if it's a RW support
         """
         if write:
-            return not rtype in NONSYSTEM_RELATIONS
+            return rtype not in NONSYSTEM_RELATIONS
         # due to current multi-sources implementation, the system source
         # can't claim not supporting a relation
-        return True #not rtype == 'content_for'
+        return True  #not rtype == 'content_for'
 
     @statsd_timeit
     def authenticate(self, cnx, login, **kwargs):
@@ -596,7 +597,7 @@
                             to_restore = handler(entity, attr)
                             restore_values.append((entity, attr, to_restore))
         try:
-            yield # 2/ execute the source's instructions
+            yield  # 2/ execute the source's instructions
         finally:
             # 3/ restore original values
             for entity, attr, value in restore_values:
@@ -631,7 +632,7 @@
             if cnx.ertype_supports_undo(entity.cw_etype):
                 attrs = [SQL_PREFIX + r.type
                          for r in entity.e_schema.subject_relations()
-                         if (r.final or r.inlined) and not r in VIRTUAL_RTYPES]
+                         if (r.final or r.inlined) and r not in VIRTUAL_RTYPES]
                 changes = self._save_attrs(cnx, entity, attrs)
                 self._record_tx_action(cnx, 'tx_entity_actions', u'D',
                                        etype=text_type(entity.cw_etype), eid=entity.eid,
@@ -642,12 +643,12 @@
 
     def add_relation(self, cnx, subject, rtype, object, inlined=False):
         """add a relation to the source"""
-        self._add_relations(cnx,  rtype, [(subject, object)], inlined)
+        self._add_relations(cnx, rtype, [(subject, object)], inlined)
         if cnx.ertype_supports_undo(rtype):
             self._record_tx_action(cnx, 'tx_relation_actions', u'A',
                                    eid_from=subject, rtype=text_type(rtype), eid_to=object)
 
-    def add_relations(self, cnx,  rtype, subj_obj_list, inlined=False):
+    def add_relations(self, cnx, rtype, subj_obj_list, inlined=False):
         """add a relations to the source"""
         self._add_relations(cnx, rtype, subj_obj_list, inlined)
         if cnx.ertype_supports_undo(rtype):
@@ -662,7 +663,7 @@
             attrs = [{'eid_from': subject, 'eid_to': object}
                      for subject, object in subj_obj_list]
             sql.append((self.sqlgen.insert('%s_relation' % rtype, attrs[0]), attrs))
-        else: # used by data import
+        else:  # used by data import
             etypes = {}
             for subject, object in subj_obj_list:
                 etype = cnx.entity_metas(subject)['type']
@@ -674,7 +675,7 @@
                 attrs = [{'cw_eid': subject, SQL_PREFIX + rtype: object}
                          for subject, object in subj_obj_list]
                 sql.append((self.sqlgen.update(SQL_PREFIX + etype, attrs[0],
-                                     ['cw_eid']),
+                                               ['cw_eid']),
                             attrs))
         for statement, attrs in sql:
             self.doexecmany(cnx, statement, attrs)
@@ -694,7 +695,7 @@
             column = SQL_PREFIX + rtype
             sql = 'UPDATE %s SET %s=NULL WHERE %seid=%%(eid)s' % (table, column,
                                                                   SQL_PREFIX)
-            attrs = {'eid' : subject}
+            attrs = {'eid': subject}
         else:
             attrs = {'eid_from': subject, 'eid_to': object}
             sql = self.sqlgen.delete('%s_relation' % rtype, attrs)
@@ -716,7 +717,7 @@
                 # during test we get those message when trying to alter sqlite
                 # db schema
                 self.info("sql: %r\n args: %s\ndbms message: %r",
-                              query, args, ex.args[0])
+                          query, args, ex.args[0])
             if rollback:
                 try:
                     cnx.cnxset.rollback()
@@ -847,7 +848,7 @@
             self.exception('failed to query entities table for eid %s', eid)
         raise UnknownEid(eid)
 
-    def eid_type_source(self, cnx, eid): # pylint: disable=E0202
+    def eid_type_source(self, cnx, eid):  # pylint: disable=E0202
         """return a tuple (type, extid, source) for the entity with id <eid>"""
         sql = 'SELECT type, extid, asource FROM entities WHERE eid=%s' % eid
         res = self._eid_type_source(cnx, eid, sql)
@@ -916,15 +917,18 @@
         # insert core relations: is, is_instance_of and cw_source
 
         if entity.e_schema.eid is not None:  # else schema has not yet been serialized
-            self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
-                                         (entity.eid, entity.e_schema.eid))
+            self._handle_is_relation_sql(
+                cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
+                (entity.eid, entity.e_schema.eid))
             for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
-                self._handle_is_relation_sql(cnx,
-                                             'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
-                                             (entity.eid, eschema.eid))
+                self._handle_is_relation_sql(
+                    cnx,
+                    'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
+                    (entity.eid, eschema.eid))
         if source.eid is not None:  # else the source has not yet been inserted
-            self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
-                                         (entity.eid, source.eid))
+            self._handle_is_relation_sql(
+                cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
+                (entity.eid, source.eid))
         # now we can update the full text index
         if self.need_fti_indexation(entity.cw_etype):
             self.index_entity(cnx, entity=entity)
@@ -969,9 +973,9 @@
         if actionfilters:
             # we will need subqueries to filter transactions according to
             # actions done
-            tearestr = {} # filters on the tx_entity_actions table
-            trarestr = {} # filters on the tx_relation_actions table
-            genrestr = {} # generic filters, appliyable to both table
+            tearestr = {}  # filters on the tx_entity_actions table
+            trarestr = {}  # filters on the tx_relation_actions table
+            genrestr = {}  # generic filters, appliyable to both table
             # unless public explicitly set to false, we only consider public
             # actions
             if actionfilters.pop('public', True):
@@ -982,7 +986,7 @@
                     # filtering on etype implies filtering on entity actions
                     # only, and with no eid specified
                     assert actionfilters.get('action', 'C') in 'CUD'
-                    assert not 'eid' in actionfilters
+                    assert 'eid' not in actionfilters
                     tearestr['etype'] = text_type(val)
                 elif key == 'eid':
                     # eid filter may apply to 'eid' of tx_entity_actions or to
@@ -1046,8 +1050,8 @@
                                   'etype', 'eid', 'changes'))
         with cnx.ensure_cnx_set:
             cu = self.doexec(cnx, sql, restr)
-            actions = [tx.EntityAction(a,p,o,et,e,c and pickle.loads(self.binary_to_str(c)))
-                       for a,p,o,et,e,c in cu.fetchall()]
+            actions = [tx.EntityAction(a, p, o, et, e, c and pickle.loads(self.binary_to_str(c)))
+                       for a, p, o, et, e, c in cu.fetchall()]
         sql = self.sqlgen.select('tx_relation_actions', restr,
                                  ('txa_action', 'txa_public', 'txa_order',
                                   'rtype', 'eid_from', 'eid_to'))
@@ -1146,12 +1150,12 @@
         for column, value in changes.items():
             rtype = column[len(SQL_PREFIX):]
             if rtype == "eid":
-                continue # XXX should even `eid` be stored in action changes?
+                continue  # XXX should even `eid` be stored in action changes?
             try:
                 rschema = getrschema[rtype]
             except KeyError:
                 err(cnx._("can't restore relation %(rtype)s of entity %(eid)s, "
-                              "this relation does not exist in the schema anymore.")
+                          "this relation does not exist in the schema anymore.")
                     % {'rtype': rtype, 'eid': eid})
             if not rschema.final:
                 if not rschema.inlined:
@@ -1160,11 +1164,11 @@
                 elif value is not None:
                     # not a deletion: we must put something in edited
                     try:
-                        entity._cw.entity_from_eid(value) # check target exists
+                        entity._cw.entity_from_eid(value)  # check target exists
                         edited[rtype] = value
                     except UnknownEid:
                         err(cnx._("can't restore entity %(eid)s of type %(eschema)s, "
-                                      "target of %(rtype)s (eid %(value)s) does not exist any longer")
+                                  "target of %(rtype)s (eid %(value)s) does not exist any longer")
                             % locals())
                         changes[column] = None
             elif eschema.destination(rtype) in ('Bytes', 'Password'):
@@ -1183,7 +1187,6 @@
         err = errors.append
         eid = action.eid
         etype = action.etype
-        _ = cnx._
         # get an entity instance
         try:
             entity = self.repo.vreg['etypes'].etype_class(etype)(cnx)
@@ -1239,8 +1242,7 @@
         # we should find an efficient way to do this (keeping current veolidf
         # massive deletion performance)
         if _undo_has_later_transaction(cnx, eid):
-            msg = cnx._('some later transaction(s) touch entity, undo them '
-                            'first')
+            msg = cnx._('some later transaction(s) touch entity, undo them first')
             raise ValidationError(eid, {None: msg})
         etype = action.etype
         # get an entity instance
@@ -1277,7 +1279,7 @@
             entity = cnx.entity_from_eid(action.eid)
         except UnknownEid:
             err(cnx._("can't restore state of entity %s, it has been "
-                          "deleted inbetween") % action.eid)
+                      "deleted inbetween") % action.eid)
             return errors
         self._reedit_entity(entity, action.changes, err)
         entity.cw_edited.check()
@@ -1346,10 +1348,9 @@
         try:
             for entity in entities:
                 cursor_unindex_object(entity.eid, cursor)
-        except Exception: # let KeyboardInterrupt / SystemExit propagate
+        except Exception:  # let KeyboardInterrupt / SystemExit propagate
             self.exception('error while unindexing %s', entity)
 
-
     def fti_index_entities(self, cnx, entities):
         """add text content of created/modified entities to the full text index
         """
@@ -1362,7 +1363,7 @@
                 cursor_index_object(entity.eid,
                                     entity.cw_adapt_to('IFTIndexable'),
                                     cursor)
-        except Exception: # let KeyboardInterrupt / SystemExit propagate
+        except Exception:  # let KeyboardInterrupt / SystemExit propagate
             self.exception('error while indexing %s', entity)
 
 
@@ -1391,6 +1392,7 @@
         source.fti_unindex_entities(cnx, to_reindex)
         source.fti_index_entities(cnx, to_reindex)
 
+
 def sql_schema(driver):
     """Yield SQL statements to create system tables in the database."""
     helper = get_db_helper(driver)
@@ -1488,6 +1490,7 @@
         """set the instance'schema"""
         pass
 
+
 class LoginPasswordAuthentifier(BaseAuthentifier):
     passwd_rql = 'Any P WHERE X is CWUser, X login %(login)s, X upassword P'
     auth_rql = (u'Any X WHERE X is CWUser, X login %(login)s, X upassword %(pwd)s, '
@@ -1496,7 +1499,7 @@
 
     def set_schema(self, schema):
         """set the instance'schema"""
-        if 'CWUser' in schema: # probably an empty schema if not true...
+        if 'CWUser' in schema:  # probably an empty schema if not true...
             # rql syntax trees used to authenticate users
             self._passwd_rqlst = self.source.compile_rql(self.passwd_rql, self._sols)
             self._auth_rqlst = self.source.compile_rql(self.auth_rql, self._sols)
@@ -1508,7 +1511,7 @@
         two queries are needed since passwords are stored crypted, so we have
         to fetch the salt first
         """
-        args = {'login': login, 'pwd' : None}
+        args = {'login': login, 'pwd': None}
         if password is not None:
             rset = self.source.syntax_tree_search(cnx, self._passwd_rqlst, args)
             try:
@@ -1529,15 +1532,15 @@
             # before 3.14.7), update with a fresh one
             if pwd is not None and pwd.getvalue():
                 verify, newhash = verify_and_update(password, pwd.getvalue())
-                if not verify: # should not happen, but...
+                if not verify:  # should not happen, but...
                     raise AuthenticationError('bad password')
                 if newhash:
-                    cnx.system_sql("UPDATE %s SET %s=%%(newhash)s WHERE %s=%%(login)s" % (
-                                        SQL_PREFIX + 'CWUser',
-                                        SQL_PREFIX + 'upassword',
-                                        SQL_PREFIX + 'login'),
-                                       {'newhash': self.source._binary(newhash.encode('ascii')),
-                                        'login': login})
+                    cnx.system_sql("UPDATE %s SET %s=%%(newhash)s WHERE %s=%%(login)s"
+                                   % (SQL_PREFIX + 'CWUser',
+                                      SQL_PREFIX + 'upassword',
+                                      SQL_PREFIX + 'login'),
+                                   {'newhash': self.source._binary(newhash.encode('ascii')),
+                                    'login': login})
                     cnx.commit()
             return user
         except IndexError:
@@ -1548,11 +1551,11 @@
     def authenticate(self, cnx, login, **authinfo):
         # email_auth flag prevent from infinite recursion (call to
         # repo.check_auth_info at the end of this method may lead us here again)
-        if not '@' in login or authinfo.pop('email_auth', None):
+        if '@' not in login or authinfo.pop('email_auth', None):
             raise AuthenticationError('not an email')
         rset = cnx.execute('Any L WHERE U login L, U primary_email M, '
-                               'M address %(login)s', {'login': login},
-                               build_descr=False)
+                           'M address %(login)s', {'login': login},
+                           build_descr=False)
         if rset.rowcount != 1:
             raise AuthenticationError('unexisting email')
         login = rset.rows[0][0]
@@ -1637,7 +1640,7 @@
             eschema = self.schema.eschema(etype)
             if eschema.final:
                 continue
-            etype_tables.append('%s%s'%(prefix, etype))
+            etype_tables.append('%s%s' % (prefix, etype))
         for rtype in self.schema.relations():
             rschema = self.schema.rschema(rtype)
             if rschema.final or rschema.inlined or rschema in VIRTUAL_RTYPES:
@@ -1689,7 +1692,7 @@
                 serialized = self._serialize(table, columns, rows)
                 archive.writestr('tables/%s.%04d' % (table, i), serialized)
                 self.logger.debug('wrote rows %d to %d (out of %d) to %s.%04d',
-                                  start, start+len(rows)-1,
+                                  start, start + len(rows) - 1,
                                   rowcount,
                                   table, i)
         else:
@@ -1795,7 +1798,6 @@
             self.cnx.commit()
         self.logger.info('inserted %d rows', row_count)
 
-
     def _parse_versions(self, version_str):
         versions = set()
         for line in version_str.splitlines():
--- a/cubicweb/server/sqlutils.py	Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/server/sqlutils.py	Fri Jul 08 09:59:18 2016 +0200
@@ -152,6 +152,8 @@
 
 
 _SQL_DROP_ALL_USER_TABLES_FILTER_FUNCTION = re.compile('^(?!(sql|pg)_)').match
+
+
 def sql_drop_all_user_tables(driver_or_helper, sqlcursor):
     """Return ths sql to drop all tables found in the database system."""
     if not getattr(driver_or_helper, 'list_tables', None):
@@ -159,14 +161,16 @@
     else:
         dbhelper = driver_or_helper
 
-    cmds = [dbhelper.sql_drop_sequence('entities_id_seq')]
+    stmts = [dbhelper.sql_drop_sequence('entities_id_seq')]
     # for mssql, we need to drop views before tables
     if hasattr(dbhelper, 'list_views'):
-        cmds += ['DROP VIEW %s;' % name
-                 for name in filter(_SQL_DROP_ALL_USER_TABLES_FILTER_FUNCTION, dbhelper.list_views(sqlcursor))]
-    cmds += ['DROP TABLE %s;' % name
-             for name in filter(_SQL_DROP_ALL_USER_TABLES_FILTER_FUNCTION, dbhelper.list_tables(sqlcursor))]
-    return '\n'.join(cmds)
+        stmts += ['DROP VIEW %s;' % name
+                  for name in filter(_SQL_DROP_ALL_USER_TABLES_FILTER_FUNCTION,
+                                     dbhelper.list_views(sqlcursor))]
+    stmts += ['DROP TABLE %s;' % name
+              for name in filter(_SQL_DROP_ALL_USER_TABLES_FILTER_FUNCTION,
+                                 dbhelper.list_tables(sqlcursor))]
+    return stmts
 
 
 class ConnectionWrapper(object):
@@ -199,7 +203,7 @@
 
     def close(self, i_know_what_i_do=False):
         """close all connections in the set"""
-        if i_know_what_i_do is not True: # unexpected closing safety belt
+        if i_know_what_i_do is not True:  # unexpected closing safety belt
             raise RuntimeError('connections set shouldn\'t be closed')
         try:
             self.cu.close()
@@ -216,7 +220,7 @@
 
     def cnxset_freed(self):
         """connections set is being freed from a session"""
-        pass # no nothing by default
+        pass  # no nothing by default
 
     def reconnect(self):
         """reopen a connection for this source or all sources if none specified
@@ -267,6 +271,7 @@
             self._cnx = self._source.get_connection()
             self._cu = self._cnx.cursor()
         return self._cnx
+
     @cnx.setter
     def cnx(self, value):
         self._cnx = value
@@ -277,6 +282,7 @@
             self._cnx = self._source.get_connection()
             self._cu = self._cnx.cursor()
         return self._cu
+
     @cu.setter
     def cu(self, value):
         self._cu = value
@@ -434,7 +440,7 @@
                     # than add_entity (native) as this behavior
                     # may also be used for update.
                     value = converters[atype](value)
-                elif atype == 'Password': # XXX could be done using a TYPE_CONVERTERS callback
+                elif atype == 'Password':  # XXX could be done using a TYPE_CONVERTERS callback
                     # if value is a Binary instance, this mean we got it
                     # from a query result and so it is already encrypted
                     if isinstance(value, Binary):
@@ -444,13 +450,13 @@
                     value = self._binary(value)
                 elif isinstance(value, Binary):
                     value = self._binary(value.getvalue())
-            attrs[SQL_PREFIX+str(attr)] = value
-        attrs[SQL_PREFIX+'eid'] = entity.eid
+            attrs[SQL_PREFIX + str(attr)] = value
+        attrs[SQL_PREFIX + 'eid'] = entity.eid
         return attrs
 
     # these are overridden by set_log_methods below
     # only defining here to prevent pylint from complaining
-    info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
+    info = warning = error = critical = exception = debug = lambda msg, *a, **kw: None
 
 set_log_methods(SQLAdapterMixIn, getLogger('cubicweb.sqladapter'))
 
@@ -510,9 +516,11 @@
     class group_concat(object):
         def __init__(self):
             self.values = set()
+
         def step(self, value):
             if value is not None:
                 self.values.add(value)
+
         def finalize(self):
             return ', '.join(text_type(v) for v in self.values)
 
@@ -536,11 +544,12 @@
     cnx.create_function("TEXT_LIMIT_SIZE", 2, limit_size2)
 
     from logilab.common.date import strptime
+
     def weekday(ustr):
         try:
             dt = strptime(ustr, '%Y-%m-%d %H:%M:%S')
         except:
-            dt =  strptime(ustr, '%Y-%m-%d')
+            dt = strptime(ustr, '%Y-%m-%d')
         # expect sunday to be 1, saturday 7 while weekday method return 0 for
         # monday
         return (dt.weekday() + 1) % 7
--- a/cubicweb/server/test/unittest_schema2sql.py	Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/server/test/unittest_schema2sql.py	Fri Jul 08 09:59:18 2016 +0200
@@ -24,6 +24,7 @@
 from logilab.database import get_db_helper
 
 from yams.reader import SchemaLoader
+
 from cubicweb.server import schema2sql
 
 schema2sql.SET_DEFAULT = True
--- a/cubicweb/server/test/unittest_schemaserial.py	Fri Jul 08 10:17:42 2016 +0200
+++ b/cubicweb/server/test/unittest_schemaserial.py	Fri Jul 08 09:59:18 2016 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2014 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.
@@ -58,6 +58,7 @@
                'FormatConstraint': 'FormatConstraint_eid',
                }
 
+
 class Schema2RQLTC(TestCase):
 
     def test_eschema2rql1(self):
@@ -71,8 +72,8 @@
 
     def test_eschema2rql2(self):
         self.assertListEqual([
-                ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
-                 {'description': u'', 'final': True, 'name': u'String'})],
+            ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
+             {'description': u'', 'final': True, 'name': u'String'})],
                              list(eschema2rql(schema.eschema('String'))))
 
     def test_eschema2rql_specialization(self):
@@ -87,7 +88,7 @@
         expected = [('INSERT CWEType X: X description %(description)s,X final %(final)s,'
                      'X name %(name)s',
                      {'description': u'',
-                     'name': u'BabarTestType', 'final': True},)]
+                      'name': u'BabarTestType', 'final': True},)]
         got = list(eschema2rql(schema.eschema('BabarTestType')))
         self.assertListEqual(expected, got)
 
@@ -99,7 +100,7 @@
              {'description': u'link a relation definition to its relation type',
               'symmetric': False,
               'name': u'relation_type',
-              'final' : False,
+              'final': False,
               'fulltext_container': None,
               'inlined': True}),
 
@@ -124,7 +125,8 @@
               'ordernum': 1, 'cardinality': u'1*'}),
             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
              'WHERE CT eid %(ct)s, EDEF eid %(x)s',
-             {'x': None, 'ct': u'RQLConstraint_eid', 'value': u'{"expression": "O final FALSE", "mainvars": ["O"], "msg": null}'}),
+             {'x': None, 'ct': u'RQLConstraint_eid',
+              'value': u'{"expression": "O final FALSE", "mainvars": ["O"], "msg": null}'}),
         ],
                              list(rschema2rql(schema.rschema('relation_type'), cstrtypemap)))
 
@@ -184,13 +186,13 @@
             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
-            {'cardinality': u'**',
-             'composite': None,
-             'description': u'groups allowed to add entities/relations of this type',
-             'oe': None,
-             'ordernum': 9999,
-             'rt': None,
-             'se': None}),
+             {'cardinality': u'**',
+              'composite': None,
+              'description': u'groups allowed to add entities/relations of this type',
+              'oe': None,
+              'ordernum': 9999,
+              'rt': None,
+              'se': None}),
             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
@@ -387,10 +389,10 @@
 class Perms2RQLTC(TestCase):
     GROUP_MAPPING = {
         'managers': 0,
-        'users':  1,
+        'users': 1,
         'guests': 2,
         'owners': 3,
-        }
+    }
 
     def test_eperms2rql1(self):
         self.assertListEqual([('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
@@ -422,9 +424,6 @@
                               for rql, kwargs in erperms2rql(schema.rschema('name').rdef('CWEType', 'String'),
                                                              self.GROUP_MAPPING)])
 
-    #def test_perms2rql(self):
-    #    self.assertListEqual(perms2rql(schema, self.GROUP_MAPPING),
-    #                         ['INSERT CWEType X: X name 'Societe', X final FALSE'])
 
 class ComputedAttributeAndRelationTC(CubicWebTC):
     appid = 'data-cwep002'
@@ -442,6 +441,7 @@
         self.assertEqual('Any SUM(SA) GROUPBY X WHERE P works_for X, P salary SA',
                          schema['total_salary'].rdefs['Company', 'Int'].formula)
 
+
 if __name__ == '__main__':
     from unittest import main
     main()