import os, sha
-from zope.interface import Interface, implements
+from zope.interface import implements
from twisted.python import failure, log
from twisted.internet import defer
from twisted.application import service
from allmydata.util.deferredutil import DeferredListShouldSucceed
from allmydata import codec
from allmydata.uri import unpack_uri
+from allmydata.interfaces import IDownloadTarget, IDownloader
class NotEnoughPeersError(Exception):
pass
def netstring(s):
return "%d:%s," % (len(s), s)
-class IDownloadTarget(Interface):
- def open():
- """Called before any calls to write() or close()."""
- def write(data):
- pass
- def close():
- pass
- def fail():
- """fail() is called to indicate that the download has failed. No
- further methods will be invoked on the IDownloadTarget after fail()."""
- def register_canceller(cb):
- """The FileDownloader uses this to register a no-argument function
- that the target can call to cancel the download. Once this canceller
- is invoked, no further calls to write() or close() will be made."""
- def finish(self):
- """When the FileDownloader is done, this finish() function will be
- called. Whatever it returns will be returned to the invoker of
- Downloader.download.
- """
-
class FileName:
implements(IDownloadTarget)
def __init__(self, filename):
def finish(self):
pass
-class IDownloader(Interface):
- def download(uri, target):
- pass
-
class Downloader(service.MultiService):
"""I am a service that allows file downloading.
"""
PathDoesNotExistError,
)
from allmydata.upload import IUploadable
+from allmydata.interfaces import IDownloader
from allmydata.filetree.nodemaker import NodeMaker
# create subtrees. That means a Downloader and a reference to the
# queen.
self._queen = queen
+ assert IDownloader(downloader)
self._downloader = downloader
self._node_maker = NodeMaker()
self._cache = {}
of 'required_shares' passed into the original
ICodecEncode.set_params() call.
"""
+
+class IDownloadTarget(Interface):
+ def open():
+ """Called before any calls to write() or close()."""
+ def write(data):
+ """Output some data to the target."""
+ def close():
+ """Inform the target that there is no more data to be written."""
+ def fail():
+ """fail() is called to indicate that the download has failed. No
+ further methods will be invoked on the IDownloadTarget after fail()."""
+ def register_canceller(cb):
+ """The FileDownloader uses this to register a no-argument function
+ that the target can call to cancel the download. Once this canceller
+ is invoked, no further calls to write() or close() will be made."""
+ def finish(self):
+ """When the FileDownloader is done, this finish() function will be
+ called. Whatever it returns will be returned to the invoker of
+ Downloader.download.
+ """
+
+class IDownloader(Interface):
+ def download(uri, target):
+ """Perform a CHK download, sending the data to the given target.
+ 'target' must provide IDownloadTarget."""
+
+class IUploadable(Interface):
+ def get_filehandle():
+ """Return a filehandle from which the data to be uploaded can be
+ read. It must implement .read, .seek, and .tell (since the latter two
+ are used to determine the length of the data)."""
+ def close_filehandle(f):
+ """The upload is finished. This provides the same filehandle as was
+ returned by get_filehandle. This is an appropriate place to close the
+ filehandle."""
+
+class IUploader(Interface):
+ def upload(uploadable):
+ """Upload the file. 'uploadable' must impement IUploadable. This
+ returns a Deferred which fires with the URI of the file."""
+
+ def upload_ssk(write_capability, new_version, uploadable):
+ pass # TODO
-#from zope.interface import implements
+from zope.interface import implements
from twisted.trial import unittest
from twisted.internet import defer
-#from allmydata.filetree.interfaces import IOpener, IDirectoryNode
+from allmydata.interfaces import IDownloader, IUploader
#from allmydata.filetree.directory import (ImmutableDirectorySubTree,
# SubTreeNode,
# CHKDirectorySubTree)
#print "open", subtree_specification, subtree_specification.serialize(), parent_is_mutable
return defer.succeed(self.objects[subtree_specification.serialize()])
+
class FakeWorkQueue(object):
implements(workqueue.IWorkQueue)
def __init__(self):
IFileNode, NoSuchDirectoryError,
NoSuchChildError)
from allmydata.filetree.file import CHKFileNode
+from allmydata.interfaces import IDownloader
from allmydata.util import bencode
class InPairs(unittest.TestCase):
pairs = list(directory.in_pairs(l))
self.failUnlessEqual(pairs, [(0,1), (2,3), (4,5), (6,7)])
+class StubDownloader(object):
+ implements(IDownloader)
+
class Stuff(unittest.TestCase):
def makeVirtualDrive(self, basedir, root_node=None):
wq = workqueue.WorkQueue(os.path.join(basedir, "1.workqueue"))
- dl = None
+ dl = StubDownloader()
if not root_node:
root_node = directory.LocalFileSubTreeNode()
root_node.new("rootdirtree.save")
self.failUnlessEqual(c1a, c2a)
def testDirectory(self):
- stm = vdrive.SubTreeMaker(None, None)
+ stm = vdrive.SubTreeMaker(None, StubDownloader())
# create an empty directory (stored locally)
subtree = directory.LocalFileSubTree()
-from zope.interface import Interface, implements
+from zope.interface import implements
from twisted.python import failure, log
from twisted.internet import defer
from twisted.application import service
from allmydata.util.deferredutil import DeferredListShouldSucceed
from allmydata import codec
from allmydata.uri import pack_uri
+from allmydata.interfaces import IUploadable, IUploader
from cStringIO import StringIO
import sha
def netstring(s):
return "%d:%s," % (len(s), s)
-class IUploadable(Interface):
- def get_filehandle():
- pass
- def close_filehandle(f):
- pass
-
class FileName:
implements(IUploadable)
def __init__(self, filename):
# the originator of the filehandle reserves the right to close it
pass
-class IUploader(Interface):
- def upload(uploadable):
- """Upload the file. 'uploadable' must impement IUploadable. This
- returns a Deferred which fires with the URI of the file."""
-
- def upload_ssk(write_capability, new_version, uploadable):
- pass # TODO
-
class Uploader(service.MultiService):
"""I am a service that allows file uploading.
"""
+ implements(IUploader)
name = "uploader"
uploader_class = FileUploader
debug = False
from twisted.python import util, log
from nevow import inevow, rend, loaders, appserver, url, tags as T
from allmydata.util import idlib
-from allmydata.download import IDownloadTarget#, IDownloader
+from allmydata.interfaces import IDownloadTarget#, IDownloader
from allmydata import upload
from zope.interface import implements, Interface
import urllib