Skip to content

Commit

Permalink
PY3 port scrapy.contrib.feedexport
Browse files Browse the repository at this point in the history
  • Loading branch information
kmike committed Aug 1, 2014
1 parent 51bd9f7 commit e2c1226
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions scrapy/contrib/feedexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from six.moves.urllib.parse import urlparse
from ftplib import FTP

from zope.interface import Interface, implements
from zope.interface import Interface, implementer
from twisted.internet import defer, threads
from w3lib.url import file_uri_to_path

Expand All @@ -35,10 +35,9 @@ def store(file):
"""Store the given file stream"""


@implementer(IFeedStorage)
class BlockingFeedStorage(object):

implements(IFeedStorage)

def open(self, spider):
return TemporaryFile(prefix='feed-')

Expand All @@ -49,10 +48,9 @@ def _store_in_thread(self, file):
raise NotImplementedError


@implementer(IFeedStorage)
class StdoutFeedStorage(object):

implements(IFeedStorage)

def __init__(self, uri, _stdout=sys.stdout):
self._stdout = _stdout

Expand All @@ -62,9 +60,9 @@ def open(self, spider):
def store(self, file):
pass

class FileFeedStorage(object):

implements(IFeedStorage)
@implementer(IFeedStorage)
class FileFeedStorage(object):

def __init__(self, uri):
self.path = file_uri_to_path(uri)
Expand All @@ -78,6 +76,7 @@ def open(self, spider):
def store(self, file):
file.close()


class S3FeedStorage(BlockingFeedStorage):

def __init__(self, uri):
Expand Down Expand Up @@ -131,6 +130,7 @@ def __init__(self, file, exporter, storage, uri):
self.uri = uri
self.itemcount = 0


class FeedExporter(object):

def __init__(self, settings):
Expand Down
2 changes: 0 additions & 2 deletions tests/py3-ignores.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ tests/test_command_shell.py
tests/test_commands.py
tests/test_command_version.py
tests/test_contrib_exporter.py
tests/test_contrib_feedexport.py
tests/test_contrib_linkextractors.py
tests/test_contrib_loader.py
tests/test_crawl.py
Expand Down Expand Up @@ -92,7 +91,6 @@ scrapy/contrib/downloadermiddleware/cookies.py
scrapy/contrib/downloadermiddleware/ajaxcrawl.py
scrapy/contrib/statsmailer.py
scrapy/contrib/memusage.py
scrapy/contrib/feedexport.py
scrapy/commands/deploy.py
scrapy/commands/bench.py
scrapy/telnet.py
Expand Down
11 changes: 7 additions & 4 deletions tests/test_contrib_feedexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ def test_interface(self):
def _assert_stores(self, storage, path):
spider = Spider("default")
file = storage.open(spider)
file.write("content")
file.write(b"content")
yield storage.store(file)
self.failUnless(os.path.exists(path))
self.failUnlessEqual(open(path).read(), "content")
with open(path, 'rb') as fp:
self.failUnlessEqual(fp.read(), b"content")


class FTPFeedStorageTest(unittest.TestCase):
Expand All @@ -65,10 +66,12 @@ def _assert_stores(self, storage, path):
file.write(b"content")
yield storage.store(file)
self.failUnless(os.path.exists(path))
self.failUnlessEqual(open(path).read(), b"content")
with open(path, 'rb') as fp:
self.failUnlessEqual(fp.read(), b"content")
# again, to check s3 objects are overwritten
yield storage.store(BytesIO(b"new content"))
self.failUnlessEqual(open(path).read(), b"new content")
with open(path, 'rb') as fp:
self.failUnlessEqual(fp.read(), b"new content")


class S3FeedStorageTest(unittest.TestCase):
Expand Down

0 comments on commit e2c1226

Please sign in to comment.