Commits

Georg Brandl  committed cb0cab4

Small code style changes, remove unused imports.

  • Participants
  • Parent commits 3482889

Comments (0)

Files changed (11)

File sphinx/builders/__init__.py

         """
         Cleanup any resources.  The default implementation does nothing.
         """
+        pass
 
 
 BUILTIN_BUILDERS = {

File sphinx/util/__init__.py

     res += traceback.format_exception_only(typ, val)
     return ''.join(res)
 
+
 class PeekableIterator(object):
     """
     An iterator which wraps any iterable and makes it possible to peek to see
         return self
 
     def next(self):
-        """
-        Returns the next item from the iterator.
-        """
+        """Return the next item from the iterator."""
         if self.remaining:
             return self.remaining.popleft()
         return self._iterator.next()
 
     def push(self, item):
-        """
-        Pushes the `item` on the internal stack, it will be returned on the
+        """Push the `item` on the internal stack, it will be returned on the
         next :meth:`next` call.
         """
         self.remaining.append(item)
 
     def peek(self):
-        """
-        Returns the next item without changing the state of the iterator.
-        """
+        """Return the next item without changing the state of the iterator."""
         item = self.next()
         self.push(item)
         return item

File sphinx/versioning.py

 except ImportError:
     from itertools import zip_longest
 
-from sphinx.util import PeekableIterator
 
 # anything below that ratio is considered equal/changed
 VERSIONING_RATIO = 65
 
+
 def add_uids(doctree, condition):
-    """
-    Adds a unique id to every node in the `doctree` which matches the condition
-    and yields it.
+    """Add a unique id to every node in the `doctree` which matches the
+    condition and yield the nodes.
 
     :param doctree:
         A :class:`docutils.nodes.document` instance.
         node.uid = uuid4().hex
         yield node
 
+
 def merge_doctrees(old, new, condition):
-    """
-    Merges the `old` doctree with the `new` one while looking at nodes matching
-    the `condition`.
+    """Merge the `old` doctree with the `new` one while looking at nodes
+    matching the `condition`.
 
     Each node which replaces another one or has been added to the `new` doctree
     will be yielded.
         new_node.uid = uuid4().hex
         yield new_node
 
+
 def get_ratio(old, new):
-    """
-    Returns a "similiarity ratio" representing the similarity between the two
-    strings where 0 is equal and anything above less than equal.
+    """Return a "similiarity ratio" (in percent) representing the similarity
+    between the two strings where 0 is equal and anything above less than equal.
     """
     if not all([old, new]):
         return VERSIONING_RATIO
     return levenshtein_distance(old, new) / (len(old) / 100.0)
 
+
 def levenshtein_distance(a, b):
+    """Return the Levenshtein edit distance between two strings *a* and *b*."""
     if a == b:
         return 0
     if len(a) < len(b):

File sphinx/websupport/__init__.py

 import cPickle as pickle
 import posixpath
 from os import path
-from datetime import datetime
 
 from jinja2 import Environment, FileSystemLoader
 
 from sphinx.application import Sphinx
 from sphinx.util.osutil import ensuredir
 from sphinx.util.jsonimpl import dumps as dump_json
-from sphinx.websupport.search import BaseSearch, search_adapters
+from sphinx.websupport.search import BaseSearch, SEARCH_ADAPTERS
 from sphinx.websupport.storage import StorageBackend
 from sphinx.websupport.errors import *
 
+
 class WebSupportApp(Sphinx):
     def __init__(self, *args, **kwargs):
         self.staticdir = kwargs.pop('staticdir', None)
         self.storage = kwargs.pop('storage', None)
         Sphinx.__init__(self, *args, **kwargs)
 
+
 class WebSupport(object):
     """The main API class for the web support package. All interactions
     with the web support package should occur through this class.
         if isinstance(search, BaseSearch):
             self.search = search
         else:
-            mod, cls = search_adapters[search or 'null']
+            mod, cls = SEARCH_ADAPTERS[search or 'null']
             mod = 'sphinx.websupport.search.' + mod
             SearchClass = getattr(__import__(mod, None, None, [cls]), cls)
             search_path = path.join(self.datadir, 'search')
         :param username: The username of the user making the request.
         :param moderator: Whether the user making the request is a moderator.
         """
-        parts = [self.base_comment_opts]
+        # XXX parts is not used?
+        #parts = [self.base_comment_opts]
         rv = self.base_comment_opts.copy()
         if username:
             rv.update({

File sphinx/websupport/search/__init__.py

 
 import re
 
+
 class BaseSearch(object):
     def __init__(self, path):
         pass
 
     def query(self, q):
         """Called by the web support api to get search results. This method
-        compiles the regular expression to be used when
-        :meth:`extracting context <extract_context>`, then calls
-        :meth:`handle_query`. You won't want to override this unless you
-        don't want to use the included :meth:`extract_context` method.
-        Override :meth:`handle_query` instead.
+        compiles the regular expression to be used when :meth:`extracting
+        context <extract_context>`, then calls :meth:`handle_query`.  You
+        won't want to override this unless you don't want to use the included
+        :meth:`extract_context` method.  Override :meth:`handle_query` instead.
 
         :param q: the search query string.
         """
         raise NotImplementedError()
 
     def extract_context(self, text, length=240):
-        """Extract the context for the search query from the documents
+        """Extract the context for the search query from the document's
         full `text`.
 
         :param text: the full text of the document to create the context for
         except TypeError:
             return context
 
-# The build in search adapters.
-search_adapters = {
+# The built-in search adapters.
+SEARCH_ADAPTERS = {
     'xapian': ('xapiansearch', 'XapianSearch'),
     'whoosh': ('whooshsearch', 'WhooshSearch'),
-    'null': ('nullsearch', 'NullSearch')
-    }
+    'null':   ('nullsearch', 'NullSearch'),
+}

File sphinx/websupport/search/nullsearch.py

 """
 
 from sphinx.websupport.search import BaseSearch
-from sphinx.websupport.errors import *
+from sphinx.websupport.errors import NullSearchException
+
 
 class NullSearch(BaseSearch):
     """A search adapter that does nothing. Used when no search adapter

File sphinx/websupport/search/whooshsearch.py

 """
 
 from whoosh import index
-from whoosh.fields import Schema, ID, TEXT, STORED
+from whoosh.fields import Schema, ID, TEXT
 from whoosh.analysis import StemmingAnalyzer
-from whoosh import highlight
 
 from sphinx.util.osutil import ensuredir
 from sphinx.websupport.search import BaseSearch
 
+
 class WhooshSearch(BaseSearch):
     """The whoosh search adapter for sphinx web support."""
 

File sphinx/websupport/search/xapiansearch.py

     :license: BSD, see LICENSE for details.
 """
 
-from os import path
-
 import xapian
 
 from sphinx.util.osutil import ensuredir
 from sphinx.websupport.search import BaseSearch
 
+
 class XapianSearch(BaseSearch):
     # Adapted from the GSOC 2009 webapp project.
 

File sphinx/websupport/storage/db.py

 """
 
 from datetime import datetime
-from uuid import uuid4
 
-from sqlalchemy import Column, Integer, Text, String, Boolean, ForeignKey,\
-                       DateTime
-from sqlalchemy.schema import UniqueConstraint
+from sqlalchemy import Column, Integer, Text, String, Boolean, \
+     ForeignKey, DateTime
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import relation, sessionmaker, aliased
 
         self.document = document
         self.source = source
 
+
 class Comment(Base):
     """An individual Comment being stored."""
     __tablename__ = db_prefix + 'comments'
 
         return '%s %s ago' % dt if dt[0] == 1 else '%s %ss ago' % dt
 
+
 class CommentVote(Base):
     """A vote a user has made on a Comment."""
     __tablename__ = db_prefix + 'commentvote'

File sphinx/websupport/storage/differ.py

 from cgi import escape
 from difflib import Differ
 
+
 class CombinedHtmlDiff(object):
     """Create an HTML representation of the differences between two pieces
     of text.

File sphinx/websupport/storage/sqlalchemystorage.py

 from sqlalchemy.orm import aliased
 from sqlalchemy.sql import func
 
-from sphinx.websupport.errors import *
+from sphinx.websupport.errors import CommentNotAllowedError, \
+     UserNotAuthorizedError
 from sphinx.websupport.storage import StorageBackend
-from sphinx.websupport.storage.db import Base, Node, Comment, CommentVote,\
-                                          Session
+from sphinx.websupport.storage.db import Base, Node, Comment, \
+     CommentVote, Session
 from sphinx.websupport.storage.differ import CombinedHtmlDiff
 
+
 class SQLAlchemyStorage(StorageBackend):
-    """A :class:`~sphinx.websupport.storage.StorageBackend` using
-    SQLAlchemy.
     """
+    A :class:`.StorageBackend` using SQLAlchemy.
+    """
+
     def __init__(self, engine):
         self.engine = engine
         Base.metadata.bind = engine
     def accept_comment(self, comment_id):
         session = Session()
 
+        # XXX assignment to "comment" needed?
         comment = session.query(Comment).filter(
             Comment.id == comment_id).update(
             {Comment.displayed: True})