Permalink
Browse files

Add __repr__ method for Extracted to simplify testing and general usa…

…bility.
  • Loading branch information...
1 parent 566229f commit 11564590202f539248032b41ec3b5c425fc93e94 @lethain committed Nov 23, 2012
Showing with 22 additions and 0 deletions.
  1. +22 −0 extraction/__init__.py
View
@@ -74,6 +74,28 @@ def __init__(self, titles=None, descriptions=None, images=None, urls=None, feeds
# a technique returns additional types of data
self._unexpected_values = kwargs
+ def __repr__(self):
+ "String representation of extracted results."
+ details = (("title", self.titles),
+ ("url", self.urls),
+ ("image", self.images),
+ ("feed", self.feeds),
+ ("description", self.descriptions),
+ )
+
+ details_strs = []
+ max_shown = 50
+ for name, values, in details:
+ if values:
+ value = values[0]
+ count = len(values)
+ if count -1 > 0:
+ details_strs.append("(%s: '%s', %s more)" % (name, value[:max_shown], count-1))
+ else:
+ details_strs.append("(%s: '%s')" % (name, value[:max_shown]))
+
+ return "<%s: %s>" % (self.__class__.__name__, ", ".join(details_strs))
+
@property
def title(self):
"Return the best title, if any."

0 comments on commit 1156459

Please sign in to comment.