Scrapy, a fast high-level web crawling & scraping framework for Python.
fixed priority handling on the new scheduler so that it's backwards compatible (ie. bigger priorities are higher). also fixed a few documentation bugs related to requests priority
Pablo Hoffman9d97e73a24f2
diff --git a/docs/topics/request-response.rst b/docs/topics/request-response.rstindex baeec8701..089c8bcd5 100644--- a/docs/topics/request-response.rst+++ b/docs/topics/request-response.rst@@ -77,11 +77,10 @@ Request objectsbody to ``str`` (if given as ``unicode``).:type encoding: string- :param priority: the priority of this request (defaults to ``0.0``).- The priority is used by the scheduler to define the order used to return- requests. It can also be used to feed priorities externally, for- example, using an offline long-term scheduler.- :type encoding: int or float+ :param priority: the priority of this request (defaults to ``0``).+ The priority is used by the scheduler to define the order used to process+ requests.+ :type priority: int:param dont_filter: indicates that this request should not be filtered bythe scheduler. This is used when you want to perform an identicaldiff --git a/docs/topics/settings.rst b/docs/topics/settings.rstindex b218ba8f4..61f1d0b21 100644--- a/docs/topics/settings.rst+++ b/docs/topics/settings.rst@@ -338,7 +338,7 @@ DEPTH_PRIORITYDefault: ``1``-An integer that is used to set the request priority based on request depth.+An integer that is used to adjust the request priority based on its depth.To crawl in `breadth-first order`_, set :setting:`DEPTH_PRIORITY` to ``1``.diff --git a/scrapy/contrib/spidermiddleware/depth.py b/scrapy/contrib/spidermiddleware/depth.pyindex 978e7baef..20390280e 100644--- a/scrapy/contrib/spidermiddleware/depth.py+++ b/scrapy/contrib/spidermiddleware/depth.py@@ -47,7 +47,7 @@ class DepthMiddleware(object):depth = response.request.meta['depth'] + 1request.meta['depth'] = depthif self.prio:- request.priority += depth * self.prio+ request.priority -= depth * self.prioif self.maxdepth and depth > self.maxdepth:log.msg("Ignoring link (depth > %d): %s " % (self.maxdepth, request.url), \level=log.DEBUG, spider=spider)diff --git a/scrapy/core/scheduler.py b/scrapy/core/scheduler.pyindex f6f414411..ba3dccc4e 100644--- a/scrapy/core/scheduler.py+++ b/scrapy/core/scheduler.py@@ -58,7 +58,7 @@ class Scheduler(object):returntry:reqd = request_to_dict(request, self.spider)- self.dqs.push(reqd, request.priority)+ self.dqs.push(reqd, -request.priority)except ValueError: # non serializable requestreturnelse:@@ -67,7 +67,7 @@ class Scheduler(object):def _mqpush(self, request):stats.inc_value('scheduler/memory_enqueued', spider=self.spider)- self.mqs.push(request, request.priority)+ self.mqs.push(request, -request.priority)def _dqpop(self):if self.dqs: