Pārlūkot izejas kodu

__repr__ and __str__ for everything per #5 and #22.

tags/v0.1^2
Ben Kurtovic pirms 12 gadiem
vecāks
revīzija
d87c226417
4 mainītis faili ar 45 papildinājumiem un 2 dzēšanām
  1. +9
    -2
      earwigbot/wiki/copyvios/__init__.py
  2. +19
    -0
      earwigbot/wiki/copyvios/markov.py
  3. +9
    -0
      earwigbot/wiki/copyvios/parsers.py
  4. +8
    -0
      earwigbot/wiki/copyvios/search.py

+ 9
- 2
earwigbot/wiki/copyvios/__init__.py Parādīt failu

@@ -48,8 +48,15 @@ class CopyvioCheckResult(object):
self.delta_chain = chains[1]

def __repr__(self):
r = "CopyvioCheckResult(violation={0!r}, confidence={1!r}, url={2!r}, queries={3|r})"
return r.format(self.violation, self.confidence, self.url, self.queries)
"""Return the canonical string representation of the result."""
res = "CopyvioCheckResult(violation={0!r}, confidence={1!r}, url={2!r}, queries={3|r})"
return res.format(self.violation, self.confidence, self.url,
self.queries)

def __str__(self):
"""Return a nice string representation of the result."""
res = "<CopyvioCheckResult ({0} with {1} conf)>"
return res.format(self.violation, self.confidence)


class CopyvioMixIn(object):


+ 19
- 0
earwigbot/wiki/copyvios/markov.py Parādīt failu

@@ -42,6 +42,14 @@ class MarkovChain(object):
except KeyError:
pass

def __repr__(self):
"""Return the canonical string representation of the MarkovChain."""
return "MarkovChain(text={0!r})".format(self.text)

def __str__(self):
"""Return a nice string representation of the MarkovChain."""
return "<MarkovChain of size {0}>".format(self.size())

def size(self):
count = 0
for node in self.chain.itervalues():
@@ -53,6 +61,7 @@ class MarkovChain(object):
class MarkovChainIntersection(MarkovChain):
def __init__(self, mc1, mc2):
self.chain = defaultdict(lambda: defaultdict(lambda: 0))
self.mc1, self.mc2 = mc1, mc2
c1 = mc1.chain
c2 = mc2.chain

@@ -63,3 +72,13 @@ class MarkovChainIntersection(MarkovChain):
if node in nodes2:
count2 = nodes2[node]
self.chain[word][node] = min(count1, count2)

def __repr__(self):
"""Return the canonical string representation of the intersection."""
res = "MarkovChainIntersection(mc1={0!r}, mc2={1!r})"
return res.format(self.mc1, self.mc2)

def __str__(self):
"""Return a nice string representation of the intersection."""
res = "<MarkovChainIntersection of size {0} ({1} ^ {2})>"
return res.format(self.size(), self.mc1, self.mc2)

+ 9
- 0
earwigbot/wiki/copyvios/parsers.py Parādīt failu

@@ -23,6 +23,15 @@
__all__ = ["BaseTextParser", "ArticleTextParser", "HTMLTextParser"]

class BaseTextParser(object):
def __repr__(self):
"""Return the canonical string representation of the text parser."""
return "{0}(text={1!r})".format(self.__class__.__name__, self.text)

def __str__(self):
"""Return a nice string representation of the text parser."""
name = self.__class__.__name__
return "<{0} of text with size {1}>".format(name, len(text))

def __init__(self, text):
self.text = text



+ 8
- 0
earwigbot/wiki/copyvios/search.py Parādīt failu

@@ -37,6 +37,14 @@ class BaseSearchEngine(object):
"""Store credentials 'cred' for searching later on."""
self.cred = cred

def __repr__(self):
"""Return the canonical string representation of the search engine."""
return "{0}()".format(self.__class__.__name__)

def __str__(self):
"""Return a nice string representation of the search engine."""
return "<{0}>".format(self.__class__.__name__)

def search(self, query):
"""Use this engine to search for 'query'.



Notiek ielāde…
Atcelt
Saglabāt