import twisted.python.failure
import twisted.web.error
import scrapy.item


class Autoresponder(object):
    # The purpose of Autoresponder is to be initialized during a run
    # of a test case and used to iterate over scrapy Request objects
    # until finally there are no more Requests to execute.
    #
    # Instead of passing the Requests to the 'net, it handles them
    # through the configuration you pass it.
    #
    # Successful (status=200) Responses can be generated by configuring
    # url2filename.
    #
    # Error responses (status usually 4xx) can be generated by configuring
    # url2errors.
    def __init__(self, url2filename, url2errors=None):
        self.url2filename = url2filename
        if url2errors is None:
           url2errors = {}
        self.url2errors = url2errors

    @staticmethod
    def manufacture_http_failure(status_code):
        error = twisted.web.error.Error(code=status_code)
        failure = twisted.python.failure.Failure(
            exc_value=error, exc_type=twisted.web.error.Error)
        return failure

    def respond_recursively(self, request_iterable):
        items = []
        work_queue = []
        work_queue.extend(request_iterable)
        while work_queue:
            thing = work_queue.pop(0)
            if isinstance(thing, scrapy.item.Item):
                items.append(thing)
                continue

            request = thing
            if request.url in self.url2filename:
                raise NotImplemented

            if request.url in self.url2errors:
                status_code = self.url2errors[request.url]
                failure = (
                    Autoresponder.manufacture_http_failure(status_code))
                results = request.errback(failure)
                if results:
                    if isinstance(results, scrapy.item.Item):
                        results = [results]
                        work_queue.extend(results)
        return items

@@ -48,16 +48,35 @@
 b.error%0A
+import scrapy.http%0A
 import s
@@ -1496,28 +1496,561 @@
     
-raise NotImplemented
+filename = self.url2filename%5Brequest.url%5D%0A                with open(filename) as f:%0A                    data = f.read()%0A                response = scrapy.http.HtmlResponse(url=request.url,%0A                                                    body=data)%0A                response.request = request%0A                results = request.callback(response)%0A                if results:%0A                    if isinstance(results, scrapy.item.Item):%0A                        results = %5Bresults%5D%0A                    work_queue.extend(results)%0A                continue
 %0A%0A  
@@ -2431,32 +2431,32 @@
 lts = %5Bresults%5D%0A
-
                 
@@ -2482,32 +2482,85 @@
 extend(results)%0A
+                continue%0A%0A            raise KeyError%0A
         return i

Add implementation for using data from files, not just errors