changeset 1983:bb2f526d961c

fix some stuff discovered by pycharm code inspection some changes fix yet undiscovered bugs (e.g. due to wrong names), other changes are rather cosmetic or improve docstrings.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 11 Feb 2013 18:48:03 +0100
parents d3b108fa83b2
children 9f241b520200 e22169dbfd44
files MoinMoin/app.py MoinMoin/apps/admin/views.py MoinMoin/apps/frontend/views.py MoinMoin/auth/ldap_login.py MoinMoin/conftest.py MoinMoin/converter/docbook_in.py MoinMoin/converter/docbook_out.py MoinMoin/converter/html_in.py MoinMoin/converter/moinwiki_out.py MoinMoin/converter/pygments_in.py MoinMoin/converter/rst_in.py MoinMoin/converter/rst_out.py MoinMoin/script/maint/moinshell.py MoinMoin/script/maint/set_meta.py MoinMoin/search/analyzers.py MoinMoin/storage/middleware/protecting.py MoinMoin/storage/middleware/routing.py MoinMoin/util/forms.py MoinMoin/util/interwiki.py MoinMoin/util/iri.py
diffstat 20 files changed, 29 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/app.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/app.py	Mon Feb 11 18:48:03 2013 +0100
@@ -109,8 +109,6 @@
 
             Rule('/<itemname:wikipage>')
             Rule('/<itemname:wikipage>/edit')
-
-        :param map: the :class:`Map`.
         """
         regex = '[^/]+?(/[^/]+?)*'
         weight = 200
--- a/MoinMoin/apps/admin/views.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/apps/admin/views.py	Mon Feb 11 18:48:03 2013 +0100
@@ -101,7 +101,7 @@
 @admin.route('/sysitems_upgrade', methods=['GET', 'POST', ])
 @require_permission(SUPERUSER)
 def sysitems_upgrade():
-    from MoinMoin.storage.backends import upgrade_sysitems
+    from MoinMoin.storage.backends import upgrade_sysitems  # XXX broken import, either fix or kill this
     from MoinMoin.storage.error import BackendError
     if request.method == 'GET':
         action = 'syspages_upgrade'
--- a/MoinMoin/apps/frontend/views.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/apps/frontend/views.py	Mon Feb 11 18:48:03 2013 +0100
@@ -430,11 +430,6 @@
 @frontend.route('/+content/<itemname:item_name>', defaults=dict(rev=CURRENT))
 def content_item(item_name, rev):
     """ same as show_item, but we only show the content """
-    # first check whether we have a valid search query:
-    search_form = SearchForm.from_flat(request.values)
-    if search_form.validate():
-        return _search(search_form, item_name)
-    search_form['submit'].set_default()  # XXX from_flat() kills all values
     item_displayed.send(app._get_current_object(),
                         item_name=item_name)
     try:
@@ -1131,16 +1126,16 @@
 
 @frontend.route('/+verifyemail', methods=['GET'])
 def verifyemail():
-    u = None
+    u = token = None
     if 'username' in request.values and 'token' in request.values:
         u = user.User(auth_username=request.values['username'])
         token = request.values['token']
-    if u and u.disabled and u.validate_recovery_token(token):
+    if u and u.disabled and token and u.validate_recovery_token(token):
         u.profile[DISABLED] = False
         u.save()
         flash(_("Your account has been activated, you can log in now."), "info")
     else:
-        flash(_('Your token is invalid!'), "error")
+        flash(_('Your username and/or token is invalid!'), "error")
     return redirect(url_for('.show_root'))
 
 
--- a/MoinMoin/auth/ldap_login.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/auth/ldap_login.py	Mon Feb 11 18:48:03 2013 +0100
@@ -133,6 +133,7 @@
             try:
                 u = None
                 dn = None
+                server = self.server_uri
                 coding = self.coding
                 logging.debug("Setting misc. ldap options...")
                 ldap.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3)  # ldap v2 is outdated
@@ -152,7 +153,6 @@
                         if value is not None:
                             ldap.set_option(option, value)
 
-                server = self.server_uri
                 logging.debug("Trying to initialize {0!r}.".format(server))
                 l = ldap.initialize(server)
                 logging.debug("Connected to LDAP server {0!r}.".format(server))
--- a/MoinMoin/conftest.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/conftest.py	Mon Feb 11 18:48:03 2013 +0100
@@ -32,8 +32,7 @@
 import py
 import MoinMoin.log
 
-""" Logging for tests to avoid useless output like timing information on stderr on test failures
-"""
+# Logging for tests to avoid useless output like timing information on stderr on test failures
 Moindir = py.path.local(__file__).dirname
 config_file = Moindir + '/_tests/test_logging.conf'
 MoinMoin.log.load_config(config_file)
--- a/MoinMoin/converter/docbook_in.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/converter/docbook_in.py	Mon Feb 11 18:48:03 2013 +0100
@@ -981,7 +981,7 @@
         href = element.get(docbook.url)
         # Since it is an element of DocBook v.4,
         # The namespace does not always work, so we will try to retrive the attribute whatever
-        if not(href):
+        if not href:
             for key, value in element.attrib.iteritems():
                 if key.name == 'url' and allowed_uri_scheme(value):
                     href = value
--- a/MoinMoin/converter/docbook_out.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/converter/docbook_out.py	Mon Feb 11 18:48:03 2013 +0100
@@ -335,7 +335,7 @@
                     if child.tag.name == 'note-body':
                         body = self.do_children(child)
         # We process note only with note-body child
-        if not(body):
+        if not body:
             return
 
         body = self.new(docbook.simpara, attrib={}, children=body)
@@ -441,7 +441,7 @@
         for item in element:
             if item.tag.uri == moin_page and item.tag.name == 'body':
                 c = self.do_children(item)
-                if not(c):
+                if not c:
                     self.section_children = sorted(self.section_children.items(),
                                                    reverse=True)
                     section = None
--- a/MoinMoin/converter/html_in.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/converter/html_in.py	Mon Feb 11 18:48:03 2013 +0100
@@ -480,7 +480,7 @@
         # of <dt><dd>
         for child in element:
             # We need one dt tag, and one dd tag, a have a pair
-            if (child.tag.name == 'dt' or child.tag.name == 'dd'):
+            if child.tag.name == 'dt' or child.tag.name == 'dd':
                 number_pair = number_pair + 1
 
             # The following code is similar to do_children method
@@ -494,7 +494,7 @@
             else:
                 pair.append(r)
 
-            if (number_pair == 2):
+            if number_pair == 2:
                 # We have two elements of the pair
                 # So we can put it into a <list-item> element
                 list_item_element = ET.Element(moin_page.list_item,
--- a/MoinMoin/converter/moinwiki_out.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/converter/moinwiki_out.py	Mon Feb 11 18:48:03 2013 +0100
@@ -414,7 +414,7 @@
         if hr_class:
             try:
                 height = int(hr_class.split(hr_class_prefix)[1]) - 1
-                if (0 <= height <= 5):
+                if 0 <= height <= 5:
                     hr_ending = (u'-' * height) + hr_ending
             except:
                 raise ElementException('page:separator has invalid class {0}'.format(hr_class))
--- a/MoinMoin/converter/pygments_in.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/converter/pygments_in.py	Mon Feb 11 18:48:03 2013 +0100
@@ -122,7 +122,7 @@
 else:
     # we have no Pygments, minimal Converter replacement, so highlight view does not crash
     class Converter(object):
-        def __init__(self, lexer=None, mimetype=None):
+        def __init__(self, lexer=None, contenttype=None):
             pass
 
         def __call__(self, content, arguments=None):
--- a/MoinMoin/converter/rst_in.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/converter/rst_in.py	Mon Feb 11 18:48:03 2013 +0100
@@ -626,8 +626,8 @@
     visitor_attributes = []
 
     def translate(self):
-        self.visitor = visitor = NodeVisitor(self.document)
-        self.document.walkabout(visitor)
+        self.visitor = visitor = NodeVisitor()
+        walkabout(self.document, visitor)
         self.output = visitor.tree()
 
 
--- a/MoinMoin/converter/rst_out.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/converter/rst_out.py	Mon Feb 11 18:48:03 2013 +0100
@@ -65,7 +65,7 @@
         self.j = 0
         self.table.append(row)
         if self.i > 0:
-            if len(self.table[-2]) > (self.j):
+            if len(self.table[-2]) > self.j:
                 self.add_cell(self.table[-2][self.j][0],
                                 self.table[-2][self.j][1] - 1, Cell(''))
         return row
--- a/MoinMoin/script/maint/moinshell.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/script/maint/moinshell.py	Mon Feb 11 18:48:03 2013 +0100
@@ -44,7 +44,7 @@
                 Option('--no-ipython',
                        action="store_true",
                        dest='no_ipython',
-                       default=not(self.use_ipython)), )
+                       default=not self.use_ipython), )
 
     def get_context(self):
         """
--- a/MoinMoin/script/maint/set_meta.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/script/maint/set_meta.py	Mon Feb 11 18:48:03 2013 +0100
@@ -49,7 +49,7 @@
 
         if query:
             qp = app.storage.query_parser([NAME_EXACT, ])
-            q = qp.parse(query_text)
+            q = qp.parse(query)
         else:
             q = Every()
 
--- a/MoinMoin/search/analyzers.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/search/analyzers.py	Mon Feb 11 18:48:03 2013 +0100
@@ -71,7 +71,7 @@
 
     def __init__(self, acl_rights_contents):
         """
-        :param cfg: wiki config
+        :param acl_rights_contents: ACL for contents
         """
         self._acl_rights_contents = acl_rights_contents
 
--- a/MoinMoin/storage/middleware/protecting.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/storage/middleware/protecting.py	Mon Feb 11 18:48:03 2013 +0100
@@ -55,7 +55,7 @@
     def __init__(self, indexer, user, acl_mapping):
         """
         :param indexer: indexing middleware instance
-        :param user_name: the user's name (used for checking permissions)
+        :param user: a User instance (used for checking permissions)
         :param acl_mapping: list of (name_prefix, acls) tuples, longest prefix first, '' last
                             acls = dict with before, default, after, hierarchic entries
         """
--- a/MoinMoin/storage/middleware/routing.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/storage/middleware/routing.py	Mon Feb 11 18:48:03 2013 +0100
@@ -45,7 +45,7 @@
         }
 
         :type namespaces: list of tuples of namespace specifier -> backend names
-        :param mapping: [(namespace, backend_name), ...]
+        :param namespaces: [(namespace, backend_name), ...]
         :type backends: dict backend names -> backends
         :param backends: {backend_name: backend, ...}
         """
@@ -66,7 +66,7 @@
         find the backend it belongs to, the itemname without namespace
         spec and the namespace of the backend.
 
-        :param fq_name: fully-qualified itemnames
+        :param fq_names: fully-qualified itemnames
         :returns: tuple of (backend name, local item name, namespace)
         """
         fq_name = fq_names[0]
@@ -74,7 +74,7 @@
             if fq_name.startswith(namespace):
                 item_names = [fq_name[len(namespace):] for fq_name in fq_names]
                 return backend_name, item_names, namespace.rstrip(':')
-        raise AssertionError("No backend found for {0!r}. Namespaces: {1!r}".format(itemname, self.namespaces))
+        raise AssertionError("No backend found for {0!r}. Namespaces: {1!r}".format(fq_name, self.namespaces))
 
     def __iter__(self):
         # Note: yields enough information so we can retrieve the revision from
--- a/MoinMoin/util/forms.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/util/forms.py	Mon Feb 11 18:48:03 2013 +0100
@@ -37,7 +37,7 @@
 
 
 def required_filter(tagname, attributes, contents, context, bind):
-    if (bind is not None and not bind.optional):
+    if bind is not None and not bind.optional:
         attributes[u'class'] = u'required'
         if tagname == 'input':
             attributes[u'required'] = u'required'
--- a/MoinMoin/util/interwiki.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/util/interwiki.py	Mon Feb 11 18:48:03 2013 +0100
@@ -71,6 +71,8 @@
                 item_name = u'{0}:{1}'.format(namespace, item_name)
             if wiki_name:
                 url = u'{0}:{1}'.format(wiki_name, item_name)
+            else:
+                url = item_name
             url = u'/{0}'.format(url)
         else:
             if (rev is None or rev == CURRENT) and endpoint == 'frontend.show_item':
@@ -197,7 +199,7 @@
     """
     Get the (fully qualified) interwiki name of a local item name.
 
-    :param item_ame: item name (unicode)
+    :param item_name: item name (unicode)
     :rtype: unicode
     :returns: wiki_name:item_name
     """
--- a/MoinMoin/util/iri.py	Mon Feb 11 14:34:12 2013 +0100
+++ b/MoinMoin/util/iri.py	Mon Feb 11 18:48:03 2013 +0100
@@ -322,7 +322,8 @@
         """
         Quote all illegal characters.
 
-        :param rules: List of unicode ranges
+        :param input: the string to quote
+        :param url: True for URI, False for IRI
         :param requote: Input string is already quoted
         :returns: Quoted string
         """