websupport: pep8 fixes

This commit is contained in:
Georg Brandl 2015-03-08 17:04:59 +01:00
parent b5c2279e05
commit 3047a23a66
6 changed files with 24 additions and 24 deletions

View File

@ -110,7 +110,7 @@ def parse_stop_word(source):
"""
result = set()
for line in source.splitlines():
line = line.split('|')[0] # remove comment
line = line.split('|')[0] # remove comment
result.update(line.split())
return result
@ -292,7 +292,7 @@ class IndexBuilder(object):
if otype:
# use unicode() to fire translation proxies
onames[typeindex] = (domainname, type,
text_type(domain.get_type_name(otype)))
text_type(domain.get_type_name(otype)))
else:
onames[typeindex] = (domainname, type, type)
if anchor == fullname:
@ -360,7 +360,7 @@ class IndexBuilder(object):
except KeyError:
self._stem_cache[word] = self.lang.stem(word)
return self._stem_cache[word]
_filter = self.lang.word_filter
_filter = self.lang.word_filter
for word in visitor.found_title_words:
word = stem(word)
@ -375,7 +375,6 @@ class IndexBuilder(object):
def context_for_searchtool(self):
return dict(
search_language_stemming_code = self.lang.js_stemmer_code,
search_language_stop_words =
jsdump.dumps(sorted(self.lang.stopwords)),
search_language_stop_words = jsdump.dumps(sorted(self.lang.stopwords)),
search_scorer_tool = self.js_scorer_code,
)

View File

@ -32,13 +32,13 @@ class WebSupport(object):
with the web support package should occur through this class.
"""
def __init__(self,
srcdir=None, # only required for building
builddir='', # the dir with data/static/doctrees subdirs
datadir=None, # defaults to builddir/data
staticdir=None, # defaults to builddir/static
doctreedir=None, # defaults to builddir/doctrees
search=None, # defaults to no search
storage=None, # defaults to SQLite in datadir
srcdir=None, # only required for building
builddir='', # the dir with data/static/doctrees subdirs
datadir=None, # defaults to builddir/data
staticdir=None, # defaults to builddir/static
doctreedir=None, # defaults to builddir/doctrees
search=None, # defaults to no search
storage=None, # defaults to SQLite in datadir
status=sys.stdout,
warning=sys.stderr,
moderation_callback=None,
@ -216,7 +216,7 @@ class WebSupport(object):
'q': q,
'search_performed': True,
'search_results': results,
'docroot': '../', # XXX
'docroot': '../', # XXX
'_': _,
}
document = {

View File

@ -76,6 +76,6 @@ class XapianSearch(BaseSearch):
context = self.extract_context(m.document.get_data())
results.append((m.document.get_value(self.DOC_PATH),
m.document.get_value(self.DOC_TITLE),
''.join(context) ))
''.join(context)))
return results

View File

@ -9,6 +9,7 @@
:license: BSD, see LICENSE for details.
"""
class StorageBackend(object):
def pre_build(self):
"""Called immediately before the build process begins. Use this

View File

@ -13,7 +13,7 @@
from datetime import datetime
from sqlalchemy import Column, Integer, Text, String, Boolean, \
ForeignKey, DateTime
ForeignKey, DateTime
from sqlalchemy.orm import relation, sessionmaker, aliased
from sqlalchemy.ext.declarative import declarative_base
@ -160,7 +160,7 @@ class Comment(Base):
filter(Comment.id == parent_id).one().path
session.close()
self.node_id = parent_path.split('.')[0]
self.path = '%s.%s' % (parent_path, self.id)
self.path = '%s.%s' % (parent_path, self.id)
def serializable(self, vote=0):
"""Creates a serializable representation of the comment. This is

View File

@ -15,17 +15,17 @@ import sqlalchemy
from sqlalchemy.orm import aliased
from sqlalchemy.sql import func
if sqlalchemy.__version__[:3] < '0.5':
raise ImportError('SQLAlchemy version 0.5 or greater is required for this '
'storage backend; you have version %s' % sqlalchemy.__version__)
from sphinx.websupport.errors import CommentNotAllowedError, \
UserNotAuthorizedError
UserNotAuthorizedError
from sphinx.websupport.storage import StorageBackend
from sphinx.websupport.storage.sqlalchemy_db import Base, Node, \
Comment, CommentVote, Session
Comment, CommentVote, Session
from sphinx.websupport.storage.differ import CombinedHtmlDiff
if sqlalchemy.__version__[:3] < '0.5':
raise ImportError('SQLAlchemy version 0.5 or greater is required for this '
'storage backend; you have version %s' % sqlalchemy.__version__)
class SQLAlchemyStorage(StorageBackend):
"""
@ -120,8 +120,8 @@ class SQLAlchemyStorage(StorageBackend):
func.count('*').label('comment_count')).group_by(
Comment.node_id).subquery()
nodes = session.query(Node.id, subquery.c.comment_count).outerjoin(
(subquery, Node.id==subquery.c.node_id)).filter(
Node.document==docname)
(subquery, Node.id == subquery.c.node_id)).filter(
Node.document == docname)
session.close()
session.commit()
return dict([(k, v or 0) for k, v in nodes])