pylint style fixes stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 26 Feb 2010 13:24:47 +0100
branchstable
changeset 4721 8f63691ccb7f
parent 4720 ddf4f19eb07a
child 4722 9c13d5db03d9
pylint style fixes
cwctl.py
dbapi.py
devtools/dataimport.py
ext/xhtml2fo.py
hooks/notification.py
hooks/storages.py
hooks/syncschema.py
migration.py
rqlrewrite.py
server/migractions.py
server/msplanner.py
server/pool.py
server/rqlannotation.py
server/session.py
server/sources/storages.py
setup.py
toolsutils.py
web/htmlwidgets.py
web/views/basecontrollers.py
web/views/debug.py
web/views/navigation.py
web/views/old_calendar.py
web/views/plots.py
web/views/sparql.py
web/views/treeview.py
wsgi/handler.py
--- a/cwctl.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/cwctl.py	Fri Feb 26 13:24:47 2010 +0100
@@ -17,8 +17,10 @@
 try:
     from os import kill, getpgid
 except ImportError:
-    def kill(*args): pass
-    def getpgid(): pass
+    def kill(*args):
+        """win32 kill implementation"""
+    def getpgid():
+        """win32 getpgid implementation"""
 
 from os.path import exists, join, isfile, isdir, dirname, abspath
 
@@ -166,7 +168,7 @@
 
 # base commands ###############################################################
 
-def version_strictly_lower(a,b):
+def version_strictly_lower(a, b):
     from logilab.common.changelog import Version
     if a:
         a = Version(a)
@@ -228,11 +230,11 @@
             if hasattr(info,'__depends_cubes__'):
                 use = info.__depends_cubes__
                 if not isinstance(use, dict):
-                    use = dict((key,None) for key in use)
+                    use = dict((key, None) for key in use)
                     self.warnings.append('cube %s should define __depends_cubes__ as a dict not a list')
             else:
                 self.warnings.append('cube %s should define __depends_cubes__' % cube)
-                use = dict((key,None) for key in info.__use__)
+                use = dict((key, None) for key in info.__use__)
             for name, constraint in use.items():
                 self.constraints.setdefault(name,set())
                 if constraint:
--- a/dbapi.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/dbapi.py	Fri Feb 26 13:24:47 2010 +0100
@@ -200,7 +200,7 @@
         except KeyError:
             # this occurs usually during test execution
             self._ = self.__ = unicode
-            self.pgettext = lambda x,y: y
+            self.pgettext = lambda x, y: y
         self.debug('request default language: %s', self.lang)
 
     def decorate_rset(self, rset):
--- a/devtools/dataimport.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/devtools/dataimport.py	Fri Feb 26 13:24:47 2010 +0100
@@ -152,7 +152,7 @@
 
 def confirm(question):
     """A confirm function that asks for yes/no/abort and exits on abort."""
-    answer = shellutils.ASK.ask(question, ('Y','n','abort'), 'Y')
+    answer = shellutils.ASK.ask(question, ('Y', 'n', 'abort'), 'Y')
     if answer == 'abort':
         sys.exit(1)
     return answer == 'Y'
@@ -275,11 +275,12 @@
 
 def check_doubles(buckets):
     """Extract the keys that have more than one item in their bucket."""
-    return [(key, len(value)) for key,value in buckets.items() if len(value) > 1]
+    return [(k, len(v)) for k, v in buckets.items() if len(v) > 1]
 
 def check_doubles_not_none(buckets):
     """Extract the keys that have more than one item in their bucket."""
-    return [(key, len(value)) for key,value in buckets.items() if key is not None and len(value) > 1]
+    return [(k, len(v)) for k, v in buckets.items()
+            if k is not None and len(v) > 1]
 
 
 # object stores #################################################################
@@ -430,12 +431,14 @@
         return entity
 
     def _put(self, type, item):
-        query = ('INSERT %s X: ' % type) + ', '.join(['X %s %%(%s)s' % (key,key) for key in item])
+        query = ('INSERT %s X: ' % type) + ', '.join('X %s %%(%s)s' % (k, k)
+                                                     for k in item])
         return self.rql(query, item)[0][0]
 
     def relate(self, eid_from, rtype, eid_to):
         # if reverse relation is found, eids are exchanged
-        eid_from, rtype, eid_to = super(RQLObjectStore, self).relate(eid_from, rtype, eid_to)
+        eid_from, rtype, eid_to = super(RQLObjectStore, self).relate(
+            eid_from, rtype, eid_to)
         self.rql('SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype,
                   {'x': int(eid_from), 'y': int(eid_to)}, ('x', 'y'))
 
@@ -513,7 +516,7 @@
                   % (len(self.store.eids), len(self.store.types),
                      len(self.store.relations), nberrors))
         if self.errors:
-            if self.askerror==2 or (self.askerror and confirm('Display errors ?')):
+            if self.askerror == 2 or (self.askerror and confirm('Display errors ?')):
                 from pprint import pformat
                 for errkey, error in self.errors.items():
                     self.tell("\n%s (%s): %d\n" % (error[0], errkey, len(error[1])))
--- a/ext/xhtml2fo.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/ext/xhtml2fo.py	Fri Feb 26 13:24:47 2010 +0100
@@ -64,7 +64,7 @@
                              u'bottom': self.page_bmargin*cm,
                              u'left'  : self.page_lmargin*cm,
                              u'right' : self.page_rmargin*cm })
-        pm.add_peripheral_region(u"end",self.hf_height)
+        pm.add_peripheral_region(u"end", self.hf_height)
         dims = {}
         dims[u"bottom"] = self.hf_height + 0.25
         pm.set_main_region_margins(dims)
@@ -82,41 +82,39 @@
         props = { u"force-page-count": u"no-force",
                   u"initial-page-number": u"1",
                   u"format": u"1", }
-        self._output_properties(ps,props)
+        self._output_properties(ps, props)
 
         sc = self.create_staticcontent(ps, u"end")
         sc_bl = self.create_block(sc)
         attrs = { u"hyphenate": u"false", }
-        attrs[u"font-size"] = u"%.1fpt" %(self.font_size*0.7)
+        attrs[u"font-size"] = u"%.1fpt" % (self.font_size * 0.7)
         attrs[u"language"] = self.lang
         attrs[u"text-align"] = u"center"
-        self._output_properties(sc_bl,attrs)
+        self._output_properties(sc_bl, attrs)
         sc_bl.text = u"Page" + u" " # ### Should be localised!
         pn = self.create_pagenumber(sc_bl)
         pn.tail = u"/"
-        lpn = self.create_pagenumbercitation( sc_bl,
-                                              u"last-block-of-report-%d" % params[u"context_pos"]
-                                              )
+        self.create_pagenumbercitation(
+            sc_bl, u"last-block-of-report-%d" % params[u"context_pos"])
 
-
-        fl = self.create_flow(ps,u"body")
+        fl = self.create_flow(ps, u"body")
         bl = self.create_block(fl)
 
         # Sets on the highest block element the properties of the XHTML body
         # element. These properties (at the least the inheritable ones) will
         # be inherited by all the future FO elements.
-        bodies = list(self.in_tree.getiterator(QName(XHTML_NS,u"body")))
+        bodies = list(self.in_tree.getiterator(QName(XHTML_NS, u"body")))
         if len(bodies) > 0:
             attrs = self._extract_properties([bodies[0]])
         else:
             attrs = default_styles[u"body"].copy()
-        attrs[u"font-size"] = u"%.1fpt" %self.font_size
+        attrs[u"font-size"] = u"%.1fpt" % self.font_size
         attrs[u"language"] = self.lang
         self._output_properties(bl,attrs)
 
         # Processes the report content
-        self._copy_text(in_elt,bl)
-        self._process_nodes(in_elt.getchildren(),bl)
+        self._copy_text(in_elt, bl)
+        self._process_nodes(in_elt.getchildren(), bl)
 
         # Inserts an empty block at the end of the report in order to be able
         # to compute the last page number of this report.
@@ -130,7 +128,7 @@
         """
         Visit function called when starting the process of the input tree.
         """
-        content = [ d for d in self.in_tree.getiterator(QName(XHTML_NS,u"div"))
+        content = [ d for d in self.in_tree.getiterator(QName(XHTML_NS, u"div"))
                     if d.get(u"id") == self.section ]
         # Asks the process of the report elements with a specific visit
         # function
--- a/hooks/notification.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/hooks/notification.py	Fri Feb 26 13:24:47 2010 +0100
@@ -29,8 +29,8 @@
     category = 'notification'
 
     def select_view(self, vid, rset, row=0, col=0):
-        return self._cw.vreg['views'].select_or_none(vid, self._cw,
-                                                     rset=rset, row=0, col=0)
+        return self._cw.vreg['views'].select_or_none(vid, self._cw, rset=rset,
+                                                     row=row, col=col)
 
 
 class StatusChangeHook(NotificationHook):
--- a/hooks/storages.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/hooks/storages.py	Fri Feb 26 13:24:47 2010 +0100
@@ -26,8 +26,9 @@
     events = ('before_update_entity', )
 
     def __call__(self):
-        for attr in ETYPE_ATTR_STORAGE.get(self.entity.__regid__, ()):
-            ETYPE_ATTR_STORAGE[self.entity.__regid__][attr].entity_updated(self.entity, attr)
+        etype = self.entity.__regid__
+        for attr in ETYPE_ATTR_STORAGE.get(etype, ()):
+            ETYPE_ATTR_STORAGE[etype][attr].entity_updated(self.entity, attr)
 
 class PreDeleteEntityHook(BFSSHook):
     """"""
@@ -35,5 +36,6 @@
     events = ('before_delete_entity', )
 
     def __call__(self):
-        for attr in ETYPE_ATTR_STORAGE.get(self.entity.__regid__, ()):
-            ETYPE_ATTR_STORAGE[self.entity.__regid__][attr].entity_deleted(self.entity, attr)
+        etype = self.entity.__regid__
+        for attr in ETYPE_ATTR_STORAGE.get(etype, ()):
+            ETYPE_ATTR_STORAGE[etype][attr].entity_deleted(self.entity, attr)
--- a/hooks/syncschema.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/hooks/syncschema.py	Fri Feb 26 13:24:47 2010 +0100
@@ -85,6 +85,7 @@
     session.transaction_data.setdefault('createdattrs', []).append(
         '%s.%s' % (etype, rtype))
 
+
 def check_valid_changes(session, entity, ro_attrs=('name', 'final')):
     errors = {}
     # don't use getattr(entity, attr), we would get the modified value if any
@@ -1137,20 +1138,22 @@
     def postcommit_event(self):
         session = self.session
         source = session.repo.system_source
-        to_reindex = session.transaction_data.get('fti_update_etypes',())
-        self.info('%i etypes need full text indexed reindexation', len(to_reindex))
+        to_reindex = session.transaction_data.get('fti_update_etypes', ())
+        self.info('%i etypes need full text indexed reindexation',
+                  len(to_reindex))
         schema = self.session.repo.vreg.schema
         for etype in to_reindex:
             rset = session.execute('Any X WHERE X is %s' % etype)
-            self.info('Reindexing full text index for %i entity of type %s', len(rset), etype)
+            self.info('Reindexing full text index for %i entity of type %s',
+                      len(rset), etype)
             still_fti = list(schema[etype].indexable_attributes())
             for entity in rset.entities():
                 try:
-                  source.fti_unindex_entity(session, entity.eid)
-                  for container in entity.fti_containers():
-                      if still_fti or container is not entity:
-                          session.repo.index_entity(session, container)
-                except Exception, ex:
+                    source.fti_unindex_entity(session, entity.eid)
+                    for container in entity.fti_containers():
+                        if still_fti or container is not entity:
+                            session.repo.index_entity(session, container)
+                except Exception:
                     self.critical('Error while updating Full Text Index for'
                                   ' entity %s', entity.eid, exc_info=True)
         if len(to_reindex):
--- a/migration.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/migration.py	Fri Feb 26 13:24:47 2010 +0100
@@ -193,7 +193,7 @@
 
         if `retry` is true the r[etry] answer may return 2
         """
-        possibleanswers = ['y','n']
+        possibleanswers = ['y', 'n']
         if abort:
             possibleanswers.append('abort')
         if shell:
--- a/rqlrewrite.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/rqlrewrite.py	Fri Feb 26 13:24:47 2010 +0100
@@ -109,7 +109,10 @@
     return newsolutions
 
 
-class Unsupported(Exception): pass
+class Unsupported(Exception):
+    """raised when an rql expression can't be inserted in some rql query
+    because it create an unresolvable query (eg no solutions found)
+    """
 
 
 class RQLRewriter(object):
@@ -440,9 +443,9 @@
                 while argname in self.kwargs:
                     argname = select.allocate_varname()
                 # insert "U eid %(u)s"
-                var = select.get_variable(self.u_varname)
-                select.add_constant_restriction(select.get_variable(self.u_varname),
-                                                'eid', unicode(argname), 'Substitute')
+                select.add_constant_restriction(
+                    select.get_variable(self.u_varname),
+                    'eid', unicode(argname), 'Substitute')
                 self.kwargs[argname] = self.session.user.eid
             return self.u_varname
         key = (self.current_expr, self.varmap, vname)
--- a/server/migractions.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/server/migractions.py	Fri Feb 26 13:24:47 2010 +0100
@@ -155,7 +155,7 @@
             else:
                 bkup = tarfile.open(backupfile, 'w|gz')
                 for filename in os.listdir(tmpdir):
-                    bkup.add(osp.join(tmpdir,filename), filename)
+                    bkup.add(osp.join(tmpdir, filename), filename)
                 bkup.close()
                 # call hooks
                 repo.hm.call_hooks('server_backup', repo=repo, timestamp=timestamp)
@@ -731,7 +731,7 @@
                         if (rschema.rdef(subjschema, objschema).infered
                             or (instschema.has_relation(rschema) and
                                 (subjschema, objschema) in instschema[rschema].rdefs)):
-                                continue
+                            continue
                         self.cmd_add_relation_definition(
                             subjschema.type, rschema.type, objschema.type)
         if auto:
--- a/server/msplanner.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/server/msplanner.py	Fri Feb 26 13:24:47 2010 +0100
@@ -271,7 +271,7 @@
         for source in self._sourcesterms:
             print '-', source
             for term, sols in self._sourcesterms[source].items():
-                print '  -', term, id(term), ':' ,sols
+                print '  -', term, id(term), ':', sols
 
     def copy_solutions(self, solindices):
         return [self._solutions[solidx].copy() for solidx in solindices]
@@ -683,11 +683,11 @@
                         # go to the next iteration directly!
                         continue
                     if not sourceterms:
-                         try:
-                             del self._sourcesterms[source]
-                         except KeyError:
-                             # XXX already cleaned
-                             pass
+                        try:
+                            del self._sourcesterms[source]
+                        except KeyError:
+                            # XXX already cleaned
+                            pass
                 # set of terms which should be additionaly selected when
                 # possible
                 needsel = set()
--- a/server/pool.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/server/pool.py	Fri Feb 26 13:24:47 2010 +0100
@@ -87,7 +87,7 @@
         # implementation details of flying insert requires the system source
         # first
         yield self.source_cnxs['system'][0]
-        for uri, (source, cursor) in self.source_cnxs.items():
+        for uri, (source, cnx) in self.source_cnxs.items():
             if uri == 'system':
                 continue
             yield source
--- a/server/rqlannotation.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/server/rqlannotation.py	Fri Feb 26 13:24:47 2010 +0100
@@ -130,7 +130,8 @@
 
 
 
-class CantSelectPrincipal(Exception): pass
+class CantSelectPrincipal(Exception):
+    """raised when no 'principal' variable can be found"""
 
 def _select_principal(sqlscope, relations, _sort=lambda x:x):
     """given a list of rqlst relations, select one which will be used to
--- a/server/session.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/server/session.py	Fri Feb 26 13:24:47 2010 +0100
@@ -225,7 +225,7 @@
                 self.pgettext = pgettext
             except KeyError:
                 self._ = self.__ = unicode
-                self.pgettext = lambda x,y: y
+                self.pgettext = lambda x, y: y
         self.lang = language
 
     def change_property(self, prop, value):
--- a/server/sources/storages.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/server/sources/storages.py	Fri Feb 26 13:24:47 2010 +0100
@@ -62,7 +62,7 @@
             else:
                 fpath = self.new_fs_path(entity, attr)
                 # bytes storage used to store file's path
-                entity[attr]= Binary(fpath)
+                entity[attr] = Binary(fpath)
                 file(fpath, 'w').write(value.getvalue())
                 AddFileOp(entity._cw, filepath=fpath)
         # else entity[attr] is expected to be an already existant file path
--- a/setup.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/setup.py	Fri Feb 26 13:24:47 2010 +0100
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-"""
+"""Generic Setup script, takes package info from __pkginfo__.py file
 
 :organization: Logilab
 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -8,9 +8,6 @@
 """
 # pylint: disable-msg=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
 #
-# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
-# http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
 # This program is free software; you can redistribute it and/or modify it under
 # the terms of the GNU General Public License as published by the Free Software
 # Foundation; either version 2 of the License, or (at your option) any later
@@ -23,7 +20,6 @@
 # You should have received a copy of the GNU General Public License along with
 # this program; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-""" Generic Setup script, takes package info from __pkginfo__.py file """
 
 import os
 import sys
--- a/toolsutils.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/toolsutils.py	Fri Feb 26 13:24:47 2010 +0100
@@ -82,7 +82,7 @@
         if askconfirm:
             print
             print diffs
-            action = ASK.ask('Replace ?', ('N','y','q'), 'N')
+            action = ASK.ask('Replace ?', ('N', 'y', 'q'), 'N')
         else:
             action = 'y'
         if action == 'y':
--- a/web/htmlwidgets.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/web/htmlwidgets.py	Fri Feb 26 13:24:47 2010 +0100
@@ -280,7 +280,7 @@
         if value is None:
             return u''
         elif isinstance(value, int):
-            return u'%09d'%value
+            return u'%09d' % value
         else:
             return unicode(value)
 
--- a/web/views/basecontrollers.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/web/views/basecontrollers.py	Fri Feb 26 13:24:47 2010 +0100
@@ -402,7 +402,7 @@
 
     @xhtmlize
     def js_reledit_form(self):
-        args = dict((x,self._cw.form[x])
+        args = dict((x, self._cw.form[x])
                     for x in frozenset(('rtype', 'role', 'reload', 'landing_zone')))
         entity = self._cw.entity_from_eid(int(self._cw.form['eid']))
         # note: default is reserved in js land
--- a/web/views/debug.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/web/views/debug.py	Fri Feb 26 13:24:47 2010 +0100
@@ -122,7 +122,7 @@
         self.w(u'<p>%s</p>\n' % ' - '.join('<a href="/_registry#%s">%s</a>'
                                            % (key, key) for key in keys))
         for key in keys:
-            self.w(u'<h2><a name="%s">%s</a></h2>' % (key,key))
+            self.w(u'<h2><a name="%s">%s</a></h2>' % (key, key))
             items = self._cw.vreg[key].items()
             if items:
                 self.w(u'<table><tbody>')
--- a/web/views/navigation.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/web/views/navigation.py	Fri Feb 26 13:24:47 2010 +0100
@@ -158,7 +158,7 @@
     context = 'navbottom'
     order = 10
     def call(self, view=None):
-        entity = self.cw_rset.get_entity(0,0)
+        entity = self.cw_rset.get_entity(0, 0)
         previous = entity.previous_entity()
         next = entity.next_entity()
         if previous or next:
--- a/web/views/old_calendar.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/web/views/old_calendar.py	Fri Feb 26 13:24:47 2010 +0100
@@ -109,7 +109,7 @@
         self._cw.add_css('cubicweb.calendar.css')
         schedule = {}
         for row in xrange(len(self.cw_rset.rows)):
-            entity = self.cw_rset.get_entity(row,0)
+            entity = self.cw_rset.get_entity(row, 0)
             infos = u'<div class="event">'
             infos += self._cw.view(itemvid, self.cw_rset, row=row)
             infos += u'</div>'
--- a/web/views/plots.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/web/views/plots.py	Fri Feb 26 13:24:47 2010 +0100
@@ -94,7 +94,7 @@
         #     datetime labels on tooltips is to insert an additional column
         #     cf. function onPlotHover in cubicweb.flot.js
         if self.timemode:
-            plot = [(datetime2ticks(x), y, datetime2ticks(x)) for x,y in plot]
+            plot = [(datetime2ticks(x), y, datetime2ticks(x)) for x, y in plot]
         return dumps(plot)
 
     def _render(self, req, width=500, height=400):
--- a/web/views/sparql.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/web/views/sparql.py	Fri Feb 26 13:24:47 2010 +0100
@@ -1,7 +1,7 @@
 """SPARQL integration
 
 :organization: Logilab
-:copyright: 2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:copyright: 2009-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
--- a/web/views/treeview.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/web/views/treeview.py	Fri Feb 26 13:24:47 2010 +0100
@@ -175,8 +175,8 @@
             if treeid.startswith('throw_away'):
                 divtail = ''
             else:
-                divtail = """ onclick="asyncRemoteExec('node_clicked', '%s', '%s')" """ %\
-                    (treeid, entity.eid)
+                divtail = """ onclick="asyncRemoteExec('node_clicked', '%s', '%s')" """ % (
+                    treeid, entity.eid)
             w(u'<div class="%s"%s></div>' % (u' '.join(divclasses), divtail))
 
             # add empty <ul> because jquery's treeview plugin checks for
--- a/wsgi/handler.py	Fri Feb 26 13:21:13 2010 +0100
+++ b/wsgi/handler.py	Fri Feb 26 13:24:47 2010 +0100
@@ -10,7 +10,7 @@
 
 from cubicweb import AuthenticationError
 from cubicweb.web import (NotFound, Redirect, DirectResponse, StatusResponse,
-                       ExplicitLogin)
+                          ExplicitLogin)
 from cubicweb.web.application import CubicWebPublisher
 from cubicweb.wsgi.request import CubicWebWsgiRequest