From acebe63d0a243628d1776f703f9de864bb586a55 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Sun, 5 Oct 2008 06:58:39 +0000 Subject: [PATCH] added __nonzero__ method to XPathSelector --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40298 --- scrapy/trunk/scrapy/xpath/selector.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scrapy/trunk/scrapy/xpath/selector.py b/scrapy/trunk/scrapy/xpath/selector.py index 3902efe27..4709da696 100644 --- a/scrapy/trunk/scrapy/xpath/selector.py +++ b/scrapy/trunk/scrapy/xpath/selector.py @@ -84,6 +84,9 @@ class XPathSelector(object): """Register namespace so that it can be used in XPath queries""" self.doc.xpathContext.xpathRegisterNs(prefix, uri) + def __nonzero__(self): + return bool(self.extract()) + def __str__(self): return "<%s (%s) xpath=%s>" % (type(self).__name__, getattr(self.xmlNode, 'name', type(self.xmlNode).__name__), self.expr)