jenkins-bot has submitted this change and it was merged.
Change subject: PEP257 pywikibot/ ......................................................................
PEP257 pywikibot/
Address all remaining pep257 issues, mostly in pywikibot. Set the mandatory docstrings job to include all files. Remove the ignore list from the non-mandatory docstrings job.
Change-Id: Ie3960ca8e15dde25bfba6d1afacc0b4d0362b357 --- M generate_family_file.py M pywikibot/comms/__init__.py M pywikibot/comms/threadedhttp.py M pywikibot/compat/__init__.py M pywikibot/data/wikidataquery.py M pywikibot/diff.py M pywikibot/exceptions.py M pywikibot/families/test_family.py M pywikibot/logentries.py M pywikibot/login.py M pywikibot/throttle.py M pywikibot/titletranslate.py M pywikibot/userinterfaces/__init__.py M pywikibot/userinterfaces/cgi_interface.py M pywikibot/userinterfaces/gui.py M pywikibot/userinterfaces/terminal_interface_base.py M pywikibot/userinterfaces/terminal_interface_unix.py M pywikibot/userinterfaces/terminal_interface_win32.py M pywikibot/userinterfaces/win32_unicode.py M pywikibot/xmlreader.py M tox.ini 21 files changed, 204 insertions(+), 113 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/generate_family_file.py b/generate_family_file.py index f98de19..1850339 100644 --- a/generate_family_file.py +++ b/generate_family_file.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- """ This script generates a family file from a given URL. -Hackish, etc. Regexps, yes. Sorry, jwz.
+Hackish, etc. Regexps, yes. Sorry, jwz. """ from __future__ import (absolute_import, division, print_function, unicode_literals) @@ -54,6 +54,9 @@
class WikiHTMLPageParser(HTMLParser): + + """Wiki HTML page parser.""" + def __init__(self, *args, **kwargs): HTMLParser.__init__(self, *args, **kwargs) self.generator = None @@ -69,6 +72,9 @@
class FamilyFileGenerator(object): + + """Family file creator.""" + def __init__(self, url=None, name=None, dointerwiki=None): if url is None: url = raw_input("Please insert URL to wiki: ") @@ -216,6 +222,9 @@
class Wiki(object): + + """Minimal wiki site class.""" + REwgEnableApi = re.compile(r'wgEnableAPI ?= ?true') REwgServer = re.compile(r'wgServer ?= ?"([^"]*)"') REwgScriptPath = re.compile(r'wgScriptPath ?= ?"([^"]*)"') diff --git a/pywikibot/comms/__init__.py b/pywikibot/comms/__init__.py index df0dcca..3b768bb 100644 --- a/pywikibot/comms/__init__.py +++ b/pywikibot/comms/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""Communication layer.""" # # (C) Pywikibot team, 2007-2008 # diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py index 4279454..a34de00 100644 --- a/pywikibot/comms/threadedhttp.py +++ b/pywikibot/comms/threadedhttp.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -""" Httplib2 threaded cookie layer +""" Httplib2 threaded cookie layer.
This class extends httplib2, adding support for: - Cookies, guarded for cross-site redirects @@ -42,6 +42,7 @@
class ConnectionPool(object): + """A thread-safe connection pool."""
def __init__(self, maxnum=5): @@ -119,19 +120,22 @@
class LockableCookieJar(cookielib.LWPCookieJar): + """CookieJar with integrated Lock object.""" + def __init__(self, *args, **kwargs): cookielib.LWPCookieJar.__init__(self, *args, **kwargs) self.lock = threading.Lock()
class Http(httplib2.Http): + """Subclass of httplib2.Http that stores cookies.
Overrides httplib2's internal redirect support to prevent cookies being eaten by the wrong sites. - """ + def __init__(self, *args, **kwargs): """ Constructor. @@ -297,6 +301,7 @@
class HttpRequest(object): + """Object wrapper for HTTP requests that need to block origin thread.
Usage: @@ -322,8 +327,8 @@ self.data will be either: * a tuple of (dict, unicode) if the request was successful * an exception - """ + def __init__(self, *args, **kwargs): """ Constructor. @@ -337,7 +342,9 @@
class HttpProcessor(threading.Thread): + """Thread object to spawn multiple HTTP connection threads.""" + def __init__(self, queue, cookiejar, connection_pool): """ Constructor. @@ -408,10 +415,12 @@ # ========================================================================
class DummyRequest(object): + """Simulated urllib2.Request object for httplib2.
- Implements only what's necessary for cookielib.CookieJar to work. + Implements only what's necessary for cookielib.CookieJar to work. """ + def __init__(self, url, headers=None): self.url = url self.headers = headers @@ -453,10 +462,12 @@
class DummyResponse(object): + """Simulated urllib2.Request object for httplib2.
- Implements only what's necessary for cookielib.CookieJar to work. + Implements only what's necessary for cookielib.CookieJar to work. """ + def __init__(self, response): self.response = response
@@ -465,10 +476,12 @@
class DummyMessage(object): + """Simulated mimetools.Message object for httplib2.
- Implements only what's necessary for cookielib.CookieJar to work. + Implements only what's necessary for cookielib.CookieJar to work. """ + def __init__(self, response): self.response = response
diff --git a/pywikibot/compat/__init__.py b/pywikibot/compat/__init__.py index e69de29..49d9f46 100644 --- a/pywikibot/compat/__init__.py +++ b/pywikibot/compat/__init__.py @@ -0,0 +1 @@ +"""Package to provide compatibility with compat scripts.""" diff --git a/pywikibot/data/wikidataquery.py b/pywikibot/data/wikidataquery.py index 4e4f583..7a0626b 100644 --- a/pywikibot/data/wikidataquery.py +++ b/pywikibot/data/wikidataquery.py @@ -26,11 +26,14 @@ def listify(x): """ If given a non-list, encapsulate in a single-element list. + + @rtype: list """ return x if isinstance(x, list) else [x]
class QuerySet(): + """ A QuerySet represents a set of queries or other query sets.
@@ -43,6 +46,8 @@ def __init__(self, q): """ Initialise a query set from a Query or another QuerySet. + + @type q: Query or QuerySet """ self.qs = [q]
@@ -54,10 +59,9 @@ this QuerySet, nest the current one in parens before joining - this makes the implicit grouping of the API explicit.
- @return a new query set representing the joining of this one and + @return: a new query set representing the joining of this one and the arguments """ - if len(self.qs) > 1 and joiner != self.joiner: left = QuerySet(self) else: @@ -73,12 +77,16 @@ def AND(self, args): """ Add the given args (Queries or QuerySets) to the Query set as a logical conjuction (AND). + + @type args: Query or QuerySet """ return self.addJoiner(args, "AND")
def OR(self, args): """ Add the given args (Queries or QuerySets) to the Query set as a logical disjunction (OR). + + @type args: Query or QuerySet """ return self.addJoiner(args, "OR")
@@ -88,7 +96,6 @@
@rtype: str """ - def bracketIfQuerySet(q): if isinstance(q, QuerySet) and q.joiner != self.joiner: return "(%s)" % q @@ -121,12 +128,16 @@ def AND(self, ands): """ Produce a query set ANDing this query and all the given query/sets. + + @type ands: Query or list of Query """ return QuerySet(self).addJoiner(ands, "AND")
def OR(self, ors): """ Produce a query set ORing this query and all the given query/sets. + + @type ors: Query or list of Query """ return QuerySet(self).addJoiner(ors, "OR")
@@ -141,6 +152,8 @@ def formatList(self, l): """ Format and comma-join a list. + + @type l: list """ return ",".join([self.formatItem(x) for x in l])
@@ -148,6 +161,8 @@ def isOrContainsOnlyTypes(items, types): """ Either this item is one of the given types, or it is a list of only those types. + + @rtype: bool """ if isinstance(items, list): for x in items: @@ -221,6 +236,7 @@
class HasClaim(Query): + """ This is a Query of the form "claim[prop:val]".
@@ -261,19 +277,20 @@
class NoClaim(HasClaim): + + """Query of the form noclaim[PROPERTY].""" + queryType = "noclaim"
class StringClaim(HasClaim): - """ - Query of the form string[PROPERTY:"STRING",...]. - """ + + """Query of the form string[PROPERTY:"STRING",...].""" + queryType = "string"
def formatItem(self, x): - """ - Strings need quote-wrapping. - """ + """Add quotes around string.""" return '"%s"' % x
def validate(self): @@ -281,9 +298,9 @@
class Tree(Query): - """ - Query of the form tree[ITEM,...][PROPERTY,...]<PROPERTY,...>. - """ + + """Query of the form tree[ITEM,...][PROPERTY,...]<PROPERTY,...>.""" + queryType = "tree"
def __init__(self, item, forward=[], reverse=[]): @@ -294,7 +311,6 @@ @param forward List of forward properties, can be empty @param reverse List of reverse properties, can be empty """ - # check sensible things coming in, as we lose info once we do # type conversion if not self.isOrContainsOnlyTypes(item, [int, ItemPage]): @@ -323,9 +339,9 @@
class Around(Query): - """ - A query in the form around[PROPERTY,LATITUDE,LONGITUDE,RADIUS]. - """ + + """A query in the form around[PROPERTY,LATITUDE,LONGITUDE,RADIUS].""" + queryType = "around"
def __init__(self, prop, coord, rad): @@ -344,6 +360,7 @@
class Between(Query): + """ A query in the form between[PROP, BEGIN, END].
@@ -354,6 +371,7 @@ @param begin WbTime object representign the beginning of the period @param end WbTime object representing the end of the period """ + queryType = "between"
def __init__(self, prop, begin=None, end=None): @@ -375,6 +393,7 @@
class Link(Query): + """ A query in the form link[LINK,...], which also includes nolink.
@@ -396,14 +415,19 @@
class NoLink(Link): + + """A query in the form nolink[..].""" + queryType = "nolink"
def fromClaim(claim): """ Construct from a pywikibot.page Claim object. - """
+ @type claim: L{pywikibot.page.Claim} + @rtype: L{Query} + """ if not isinstance(claim, Claim): raise TypeError("claim must be a page.Claim")
@@ -417,6 +441,7 @@
class WikidataQuery(): + """ An interface to the WikidataQuery API.
@@ -464,6 +489,8 @@ def getCacheFilename(self, queryStr): """ Encode a query into a unique and universally safe format. + + @rtype: unicode """ encQuery = hashlib.sha1(queryStr.encode('utf8')).hexdigest() + ".wdq_cache" return os.path.join(self.cacheDir, encQuery) @@ -474,7 +501,6 @@
Returns None if the data is not there or if it is too old. """ - if self.cacheMaxAge <= 0: return None
@@ -503,7 +529,6 @@
No return value. """ - if self.cacheMaxAge <= 0: return
@@ -527,6 +552,8 @@ def getDataFromHost(self, queryStr): """ Go and fetch a query from the host's API. + + @rtype: dict """ url = self.getUrl(queryStr)
@@ -550,7 +577,6 @@
@return Python dict of the interpreted JSON or None on failure """ - fullQueryString = self.getQueryString(q, labels, props)
# try to get cached data first diff --git a/pywikibot/diff.py b/pywikibot/diff.py index e118770..e7bffe2 100644 --- a/pywikibot/diff.py +++ b/pywikibot/diff.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -""" -User-interface related functions -""" +"""Diff module.""" # # (C) Pywikibot team, 2014 # @@ -21,6 +19,7 @@
class Hunk(object): + """One change hunk between a and b.
a and b: two sequences of lines. @@ -61,14 +60,12 @@
def get_header(self): """Provide header of unified diff.""" - a_rng = difflib._format_range_unified(*self.a_rng) b_rng = difflib._format_range_unified(*self.b_rng) return '@@ -{} +{} @@{}'.format(a_rng, b_rng, '\n')
def create_diff(self): """Generator of diff text for this hunk, without formatting.""" - # make sure each line ends with '\n' to prevent # behaviour like http://bugs.python.org/issue2142 def check_line(l): @@ -94,7 +91,6 @@
def format_diff(self): """Color diff lines.""" - diff = iter(self.diff)
l1, l2 = '', next(diff) @@ -123,7 +119,6 @@ line_ref: string.
""" - color = line[0]
if line_ref is None: @@ -167,23 +162,25 @@
class PatchManager(object): + """Apply patches to text_a to obtain a new text.
If all hunks are approved, text_b will be obtained. - letter by letter. - """
def __init__(self, text_a, text_b, n=0, by_letter=False): """Constructor.
- text_a: string - text_b: string - n: int, line of context as defined in difflib.get_grouped_opcodes(). - by_letter: if text_a and text_b are single lines, comparison can be done - + @param text_a: base text + @type text_a: basestring + @param text_b: target text + @type text_b: basestring + @param n: line of context as defined in difflib.get_grouped_opcodes(). + @type n: int + @param by_letter: if text_a and text_b are single lines, comparison can be done + letter by letter. + @type by_letter: bool """ - if '\n' in text_a or '\n' in text_b: self.a = text_a.splitlines(1) self.b = text_b.splitlines(1) @@ -210,9 +207,7 @@ [-1, (i1, i2), (-1, -1)] -> block a[i1:i2] does not change from a to b then is there is no corresponding hunk. [hunk index, (i1, i2), (j1, j2)] -> block a[i1:i2] becomes b[j1:j2] - """ - blocks = [] i2 = 0 for hunk_idx, group in enumerate(self.groups): @@ -240,8 +235,7 @@ pywikibot.output(hunk.header + hunk.diff_text)
def review_hunks(self): - "Review hunks." - + """Review hunks.""" help_msg = ['y -> accept this hunk', 'n -> do not accept this hunk', 's -> do not accept this hunk and stop reviewing', @@ -292,7 +286,6 @@
def apply(self): """Apply changes. If there are undecided changes, ask to review.""" - if any(h.reviewed == h.PENDING for h in self.hunks): pywikibot.output("There are unreviewed hunks.\n" "Please review them before proceeding.\n") @@ -325,7 +318,6 @@ by_letter: if text_a and text_b are single lines, comparison can be done
""" - patch = PatchManager(oldtext, newtext, n=n, by_letter=by_letter) pywikibot.output('\03{{lightpurple}}\n{:*^50}\03{{default}}\n'.format(' ALL CHANGES '))
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py index 95d3111..90b2e5c 100644 --- a/pywikibot/exceptions.py +++ b/pywikibot/exceptions.py @@ -56,7 +56,7 @@ from pywikibot.tools import UnicodeMixin
-class Error(UnicodeMixin, Exception): +class Error(UnicodeMixin, Exception): # noqa
"""Pywikibot error"""
@@ -108,7 +108,7 @@ return self.page
-class PageSaveRelatedError(PageRelatedError): +class PageSaveRelatedError(PageRelatedError): # noqa
"""Saving the page has failed"""
@@ -145,12 +145,12 @@
class NoUsername(Error):
- """Username is not in user-config.py""" + """Username is not in user-config.py."""
pass
-class NoPage(PageRelatedError): +class NoPage(PageRelatedError): # noqa
"""Page does not exist"""
@@ -159,7 +159,7 @@ pass
-class SiteDefinitionError(Error): +class SiteDefinitionError(Error): # noqa
"""Site does not exist"""
@@ -172,21 +172,21 @@ NoSuchSite = SiteDefinitionError
-class UnknownSite(SiteDefinitionError): +class UnknownSite(SiteDefinitionError): # noqa
"""Site does not exist in Family"""
pass
-class UnknownFamily(SiteDefinitionError): +class UnknownFamily(SiteDefinitionError): # noqa
"""Family is not registered"""
pass
-class IsRedirectPage(PageRelatedError): +class IsRedirectPage(PageRelatedError): # noqa
"""Page is a redirect page"""
@@ -195,7 +195,7 @@ pass
-class IsNotRedirectPage(PageRelatedError): +class IsNotRedirectPage(PageRelatedError): # noqa
"""Page is not a redirect page"""
@@ -206,7 +206,7 @@
class CircularRedirect(PageRelatedError):
- """Page is a circular redirect + """Page is a circular redirect.
Exception argument is the redirect target; this may be the same title as this page or a different title (in which case the target page directly @@ -217,14 +217,14 @@ message = u"Page %s is a circular redirect."
-class InvalidTitle(Error): +class InvalidTitle(Error): # noqa
"""Invalid page title"""
pass
-class LockedPage(PageSaveRelatedError): +class LockedPage(PageSaveRelatedError): # noqa
"""Page is locked"""
@@ -233,7 +233,7 @@ pass
-class LockedNoPage(LockedPage): +class LockedNoPage(LockedPage): # noqa
"""Title is locked against creation"""
@@ -242,7 +242,7 @@ pass
-class CascadeLockedPage(LockedPage): +class CascadeLockedPage(LockedPage): # noqa
"""Page is locked due to cascading protection"""
@@ -251,7 +251,7 @@ pass
-class SectionError(Error): +class SectionError(Error): # noqa
"""The section specified by # does not exist"""
@@ -270,7 +270,7 @@ pass
-class EditConflict(PageSaveRelatedError): +class EditConflict(PageSaveRelatedError): # noqa
"""There has been an edit conflict while uploading the page"""
@@ -279,7 +279,7 @@ pass
-class PageDeletedConflict(EditConflict): +class PageDeletedConflict(EditConflict): # noqa
"""Page was deleted since being retrieved"""
@@ -288,7 +288,7 @@ pass
-class PageCreatedConflict(EditConflict): +class PageCreatedConflict(EditConflict): # noqa
"""Page was created by another user"""
@@ -317,7 +317,7 @@ super(SpamfilterError, self).__init__(page)
-class ServerError(Error): +class ServerError(Error): # noqa
"""Got unexpected server response"""
@@ -331,7 +331,7 @@ pass
-class Server504Error(Error): +class Server504Error(Error): # noqa
"""Server timed out with HTTP 504 code"""
@@ -349,14 +349,14 @@ pass
-class UserBlocked(Error): +class UserBlocked(Error): # noqa
"""Your username or IP has been blocked"""
pass
-class PageNotFound(Error): +class PageNotFound(Error): # noqa
"""Page not found in list"""
@@ -383,23 +383,29 @@
class UserActionRefuse(Error): + + """User action was refused.""" + pass
class WikiBaseError(Error): + + """Wikibase related error.""" + pass
class CoordinateGlobeUnknownException(WikiBaseError, NotImplementedError):
- """ This globe is not implemented yet in either WikiBase or pywikibot """ + """This globe is not implemented yet in either WikiBase or pywikibot."""
pass
class EntityTypeUnknownException(WikiBaseError):
- """The requested entity type is not recognised on this site""" + """The requested entity type is not recognised on this site."""
pass
diff --git a/pywikibot/families/test_family.py b/pywikibot/families/test_family.py index c2cc459..8d72b7c 100644 --- a/pywikibot/families/test_family.py +++ b/pywikibot/families/test_family.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- - +"""Family module for test.wikipedia.org.""" __version__ = '$Id$'
from pywikibot import family @@ -7,6 +7,9 @@
# The test wikipedia family class Family(family.WikimediaFamily): + + """Family class for test.wikipedia.org.""" + def __init__(self): super(Family, self).__init__() self.name = 'test' diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py index dfcb883..cdfe41b 100644 --- a/pywikibot/logentries.py +++ b/pywikibot/logentries.py @@ -83,6 +83,9 @@
class BlockEntry(LogEntry): + + """Block log entry.""" + _expectedType = 'block'
def __init__(self, apidata): @@ -162,22 +165,37 @@
class ProtectEntry(LogEntry): + + """Protection log entry.""" + _expectedType = 'protect'
class RightsEntry(LogEntry): + + """Rights log entry.""" + _expectedType = 'rights'
class DeleteEntry(LogEntry): + + """Deletion log entry.""" + _expectedType = 'delete'
class UploadEntry(LogEntry): + + """Upload log entry.""" + _expectedType = 'upload'
class MoveEntry(LogEntry): + + """Move log entry.""" + _expectedType = 'move'
def new_ns(self): @@ -200,14 +218,23 @@
class ImportEntry(LogEntry): + + """Import log entry.""" + _expectedType = 'import'
class PatrolEntry(LogEntry): + + """Patrol log entry.""" + _expectedType = 'patrol'
class NewUsersEntry(LogEntry): + + """New user log entry.""" + _expectedType = 'newusers'
# TODO entries for merge,suppress,makebot,gblblock,renameuser,globalauth,gblrights ? diff --git a/pywikibot/login.py b/pywikibot/login.py index 13eef79..ee05bd1 100644 --- a/pywikibot/login.py +++ b/pywikibot/login.py @@ -32,6 +32,9 @@
class LoginManager: + + """Site login manager.""" + @deprecated_args(username="user", verbose=None) def __init__(self, password=None, sysop=False, site=None, user=None): if site is not None: diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py index 003b522..5cdc30d 100644 --- a/pywikibot/throttle.py +++ b/pywikibot/throttle.py @@ -27,7 +27,7 @@
class Throttle(object):
- """Control rate of access to wiki server + """Control rate of access to wiki server.
Calling this object blocks the calling thread until at least 'delay' seconds have passed since the previous call. @@ -36,6 +36,7 @@ rate of access.
""" + def __init__(self, site, mindelay=None, maxdelay=None, writedelay=None, multiplydelay=True): self.lock = threading.RLock() diff --git a/pywikibot/titletranslate.py b/pywikibot/titletranslate.py index 891f7c9..cf60b41 100644 --- a/pywikibot/titletranslate.py +++ b/pywikibot/titletranslate.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""Title translate module.""" # # (C) Rob W.W. Hooft, 2003 # (C) Yuri Astrakhan, 2005 @@ -18,7 +19,7 @@ def translate(page, hints=None, auto=True, removebrackets=False, site=None, family=None): """ - Goes through all entries in 'hints'. Returns a list of links to pages. + Return a list of links to pages on other sites based on hints.
Entries for single page titles list those pages. Page titles for entries such as "all:" or "xyz:" or "20:" are first built from the page title of @@ -122,9 +123,7 @@
def getPoisonedLinks(pl): - """Return a list of known corrupted links that should be removed if seen - - """ + """Return a list of known corrupted links that should be removed if seen.""" result = [] pywikibot.output(u'getting poisoned links for %s' % pl.title()) dictName, value = date.getAutoFormat(pl.site.code, pl.title()) diff --git a/pywikibot/userinterfaces/__init__.py b/pywikibot/userinterfaces/__init__.py index 5041b19..120ec4e 100644 --- a/pywikibot/userinterfaces/__init__.py +++ b/pywikibot/userinterfaces/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""User interfaces.""" # # (C) Pywikibot team, 2007 # diff --git a/pywikibot/userinterfaces/cgi_interface.py b/pywikibot/userinterfaces/cgi_interface.py index 21fd9ff..79572f7 100644 --- a/pywikibot/userinterfaces/cgi_interface.py +++ b/pywikibot/userinterfaces/cgi_interface.py @@ -1,7 +1,11 @@ +"""CGI user interface.""" import sys
class UI: + + """CGI user interface.""" + def __init__(self): pass
diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py index f141d9b..d29ac00 100644 --- a/pywikibot/userinterfaces/gui.py +++ b/pywikibot/userinterfaces/gui.py @@ -32,12 +32,14 @@
class TextEditor(ScrolledText): + """A text widget with some editing enhancements.
A lot of code here is copied or adapted from the idlelib/EditorWindow.py file in the standard Python distribution.
""" + def __init__(self, master=None, **kwargs): # get default settings from user's IDLE configuration currentTheme = idleConf.CurrentTheme() @@ -231,6 +233,8 @@
class EditBoxWindow(Tkinter.Frame):
+ """Edit box window.""" + def __init__(self, parent=None, **kwargs): if parent is None: # create a new window @@ -387,6 +391,8 @@ # the following class isn't used anywhere in the framework: #### class ListBoxWindow:
+ """List box window.""" + # called when user pushes the OK button. # closes the window. def pressedOK(self): diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py index ee234e2..e08c50b 100755 --- a/pywikibot/userinterfaces/terminal_interface_base.py +++ b/pywikibot/userinterfaces/terminal_interface_base.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""Base for terminal user interfaces.""" # # (C) Pywikibot team, 2003-2014 # @@ -41,6 +42,9 @@
class UI: + + """Base for terminal user interfaces.""" + def __init__(self): self.stdin = sys.stdin self.stdout = sys.stdout @@ -61,7 +65,6 @@ others write theirs to sys.stderr.
""" - if default_stream == 'stdout': default_stream = self.stdout elif default_stream == 'stderr': @@ -187,7 +190,6 @@ Unlike raw_input, this function automatically adds a space after the question. """ - # sound the terminal bell to notify the user if config.ring_bell: sys.stdout.write('\07') @@ -350,6 +352,7 @@
class TerminalHandler(logging.Handler): + """A handler class that writes logging records to a terminal.
This class does not close the stream, @@ -391,16 +394,21 @@
class TerminalFormatter(logging.Formatter): + + """Terminal logging formatter.""" + pass
class MaxLevelFilter(logging.Filter): + """Filter that only passes records at or below a specific level.
(setting handler level only passes records at or *above* a specified level, so this provides the opposite functionality)
""" + def __init__(self, level=None): self.level = level
diff --git a/pywikibot/userinterfaces/terminal_interface_unix.py b/pywikibot/userinterfaces/terminal_interface_unix.py index da6f43e..bb6384d 100755 --- a/pywikibot/userinterfaces/terminal_interface_unix.py +++ b/pywikibot/userinterfaces/terminal_interface_unix.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""User interface for unix terminals.""" # # (C) Pywikibot team, 2003-2014 # @@ -31,6 +32,9 @@
class UnixUI(terminal_interface_base.UI): + + """User interface for unix terminals.""" + def printColorized(self, text, targetStream): totalcount = 0 for key, value in unixColors.items(): diff --git a/pywikibot/userinterfaces/terminal_interface_win32.py b/pywikibot/userinterfaces/terminal_interface_win32.py index 098ae80..7e3fd89 100755 --- a/pywikibot/userinterfaces/terminal_interface_win32.py +++ b/pywikibot/userinterfaces/terminal_interface_win32.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""User interface for Win32 terminals.""" # # (C) Pywikibot team, 2003-2013 # @@ -40,12 +41,18 @@
# Compat for python <= 2.5 class Win32BaseUI(terminal_interface_base.UI): + + """User interface for Win32 terminals without ctypes.""" + def __init__(self): terminal_interface_base.UI.__init__(self) self.encoding = 'ascii'
class Win32CtypesUI(Win32BaseUI): + + """User interface for Win32 terminals using ctypes.""" + def __init__(self): Win32BaseUI.__init__(self) from .win32_unicode import stdin, stdout, stderr, argv diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py index ae9048d..b92b273 100755 --- a/pywikibot/userinterfaces/win32_unicode.py +++ b/pywikibot/userinterfaces/win32_unicode.py @@ -1,4 +1,4 @@ -# Stdout, stderr and argv support: +""" Stdout, stderr and argv support for unicode. """ ############################################## # Support for unicode in windows cmd.exe # Posted on Stack Overflow [1], available under CC-BY-SA [2] @@ -121,6 +121,9 @@ LPVOID)(("ReadConsoleW", windll.kernel32))
class UnicodeInput: + + """Unicode terminal input class.""" + def __init__(self, hConsole, name, bufsize=1024): self._hConsole = hConsole self.bufsize = bufsize @@ -144,6 +147,9 @@ LPVOID)(("WriteConsoleW", windll.kernel32))
class UnicodeOutput: + + """Unicode terminal output class.""" + def __init__(self, hConsole, stream, fileno, name): self._hConsole = hConsole self._stream = stream diff --git a/pywikibot/xmlreader.py b/pywikibot/xmlreader.py index 4f19a73..dceeb4b 100644 --- a/pywikibot/xmlreader.py +++ b/pywikibot/xmlreader.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- - """ +XML reading module. + Each XmlEntry object represents a page, as read from an XML source
The XmlDump class reads a pages_current XML dump (like the ones offered on @@ -77,6 +78,7 @@
There surely are more elegant ways to do this. """ + def __init__(self, filename, handler): threading.Thread.__init__(self) self.filename = filename @@ -98,6 +100,7 @@ If True, parse all revisions instead of only the latest one. Default: False. """ + def __init__(self, filename, allrevisions=False): self.filename = filename if allrevisions: diff --git a/tox.ini b/tox.ini index 2ece018..5aa95f7 100644 --- a/tox.ini +++ b/tox.ini @@ -14,41 +14,12 @@ deps = flake8
[testenv:flake8-docstrings] -commands = flake8 {posargs} --ignore=D102,D103,E122,E127,E241,E265 +commands = flake8 {posargs} deps = flake8>=2.2.5 flake8-docstrings
[testenv:flake8-docstrings-mandatory] -# Add any new file which is pep257 compatible -commands = flake8 --ignore=D102,D103,E122,E127,E241,E265 \ - ./setup.py \ - ./generate_user_files.py \ - ./pywikibot/__init__.py \ - ./pywikibot/bot.py \ - ./pywikibot/botirc.py \ - ./pywikibot/config2.py \ - ./pywikibot/echo.py \ - ./pywikibot/editor.py \ - ./pywikibot/family.py \ - ./pywikibot/fixes.py \ - ./pywikibot/i18n.py \ - ./pywikibot/interwiki_graph.py \ - ./pywikibot/page.py \ - ./pywikibot/plural.py \ - ./pywikibot/site.py \ - ./pywikibot/pagegenerators.py \ - ./pywikibot/tools.py \ - ./pywikibot/version.py \ - ./pywikibot/weblib.py \ - ./pywikibot/comms/http.py \ - ./pywikibot/compat/userlib.py \ - ./pywikibot/compat/catlib.py \ - ./pywikibot/compat/query.py \ - ./pywikibot/data/__init__.py \ - ./pywikibot/data/api.py \ - ./pywikibot/userinterfaces/transliteration.py \ - ./pywikibot/userinterfaces/terminal_interface.py \ - ./scripts/ ./tests/ +commands = flake8 --ignore=D102,D103,E122,E127,E241,E265
deps = flake8>=2.2.5 flake8-docstrings
pywikibot-commits@lists.wikimedia.org