the new pyflakes is stricter, complaining about function definitions that overshadow earlier definitions or imports. Fix some of its complaints.

This commit is contained in:
Brian Warner 2007-12-18 18:47:28 -07:00
parent 318b63fbc7
commit 50bc0d2fb3
2 changed files with 20 additions and 31 deletions

View File

@ -248,10 +248,6 @@ class Encode(unittest.TestCase):
# 4 segments: 25,25,25,25 # 4 segments: 25,25,25,25
return self.do_encode(25, 100, 100, 4, 7, 8) return self.do_encode(25, 100, 100, 4, 7, 8)
def test_send_101(self):
# encode a 101 byte file (in 5 segments: 25,25,25,25,1) to 100 shares
return self.do_encode(25, self.make_data(101), 100, 5, 15, 8)
def test_send_124(self): def test_send_124(self):
# 5 segments: 25, 25, 25, 25, 24 # 5 segments: 25, 25, 25, 25, 24
return self.do_encode(25, 124, 100, 5, 15, 8) return self.do_encode(25, 124, 100, 5, 15, 8)

View File

@ -12,7 +12,8 @@ from allmydata.util import fileutil
import simplejson import simplejson
from allmydata.interfaces import IDownloadTarget, IDirectoryNode, IFileNode, \ from allmydata.interfaces import IDownloadTarget, IDirectoryNode, IFileNode, \
IMutableFileNode IMutableFileNode
from allmydata import upload, download from allmydata import download
from allmydata.upload import FileHandle, FileName
from allmydata import provisioning from allmydata import provisioning
from allmydata import get_package_versions_string from allmydata import get_package_versions_string
from zope.interface import implements, Interface from zope.interface import implements, Interface
@ -727,9 +728,7 @@ class POSTHandler(rend.Page):
raise RuntimeError("mkdir requires a name") raise RuntimeError("mkdir requires a name")
d = self._check_replacement(name) d = self._check_replacement(name)
d.addCallback(lambda res: self._node.create_empty_directory(name)) d.addCallback(lambda res: self._node.create_empty_directory(name))
def _done(res): d.addCallback(lambda res: "directory created")
return "directory created"
d.addCallback(_done)
elif t == "uri": elif t == "uri":
if not name: if not name:
raise RuntimeError("set-uri requires a name") raise RuntimeError("set-uri requires a name")
@ -739,9 +738,7 @@ class POSTHandler(rend.Page):
newuri = req.fields["uri"].value.strip() newuri = req.fields["uri"].value.strip()
d = self._check_replacement(name) d = self._check_replacement(name)
d.addCallback(lambda res: self._node.set_uri(name, newuri)) d.addCallback(lambda res: self._node.set_uri(name, newuri))
def _done(res): d.addCallback(lambda res: newuri)
return newuri
d.addCallback(_done)
elif t == "delete": elif t == "delete":
if name is None: if name is None:
# apparently an <input type="hidden" name="name" value=""> # apparently an <input type="hidden" name="name" value="">
@ -754,9 +751,7 @@ class POSTHandler(rend.Page):
# buttons ourselves. # buttons ourselves.
name = '' name = ''
d = self._node.delete(name) d = self._node.delete(name)
def _done(res): d.addCallback(lambda res: "thing deleted")
return "thing deleted"
d.addCallback(_done)
elif t == "rename": elif t == "rename":
from_name = 'from_name' in req.fields and req.fields["from_name"].value from_name = 'from_name' in req.fields and req.fields["from_name"].value
if from_name is not None: if from_name is not None:
@ -783,9 +778,7 @@ class POSTHandler(rend.Page):
def rm_src(junk): def rm_src(junk):
return self._node.delete(from_name) return self._node.delete(from_name)
d.addCallback(rm_src) d.addCallback(rm_src)
def _done(res): d.addCallback(lambda res: "thing renamed")
return "thing renamed"
d.addCallback(_done)
elif t == "upload": elif t == "upload":
if "mutable" in req.fields: if "mutable" in req.fields:
@ -798,7 +791,7 @@ class POSTHandler(rend.Page):
# SDMF: files are small, and we can only upload data. # SDMF: files are small, and we can only upload data.
contents.file.seek(0) contents.file.seek(0)
data = contents.file.read() data = contents.file.read()
uploadable = upload.FileHandle(contents.file) uploadable = FileHandle(contents.file)
d = self._check_replacement(name) d = self._check_replacement(name)
d.addCallback(lambda res: self._node.has_child(name)) d.addCallback(lambda res: self._node.has_child(name))
def _checked(present): def _checked(present):
@ -827,7 +820,7 @@ class POSTHandler(rend.Page):
name = name.strip() name = name.strip()
if not name: if not name:
raise RuntimeError("upload requires a name") raise RuntimeError("upload requires a name")
uploadable = upload.FileHandle(contents.file) uploadable = FileHandle(contents.file)
d = self._check_replacement(name) d = self._check_replacement(name)
d.addCallback(lambda res: self._node.add_file(name, uploadable)) d.addCallback(lambda res: self._node.add_file(name, uploadable))
def _done(newnode): def _done(newnode):
@ -841,21 +834,21 @@ class POSTHandler(rend.Page):
data = contents.file.read() data = contents.file.read()
# TODO: 'name' handling needs review # TODO: 'name' handling needs review
d = defer.succeed(self._node) d = defer.succeed(self._node)
def _got_child(child_node): def _got_child_overwrite(child_node):
child_node.replace(data) child_node.replace(data)
return child_node.get_uri() return child_node.get_uri()
d.addCallback(_got_child) d.addCallback(_got_child_overwrite)
elif t == "check": elif t == "check":
d = self._node.get(name) d = self._node.get(name)
def _got_child(child_node): def _got_child_check(child_node):
d2 = child_node.check() d2 = child_node.check()
def _done(res): def _done(res):
log.msg("checked %s, results %s" % (child_node, res)) log.msg("checked %s, results %s" % (child_node, res))
return str(res) return str(res)
d2.addCallback(_done) d2.addCallback(_done)
return d2 return d2
d.addCallback(_got_child) d.addCallback(_got_child_check)
else: else:
print "BAD t=%s" % t print "BAD t=%s" % t
return "BAD t=%s" % t return "BAD t=%s" % t
@ -979,7 +972,7 @@ class PUTHandler(rend.Page):
return d return d
def _upload_file(self, node, contents, name): def _upload_file(self, node, contents, name):
uploadable = upload.FileHandle(contents) uploadable = FileHandle(contents)
d = node.add_file(name, uploadable) d = node.add_file(name, uploadable)
def _done(filenode): def _done(filenode):
log.msg("webish upload complete") log.msg("webish upload complete")
@ -988,7 +981,7 @@ class PUTHandler(rend.Page):
return d return d
def _upload_localfile(self, node, localfile, name): def _upload_localfile(self, node, localfile, name):
uploadable = upload.FileName(localfile) uploadable = FileName(localfile)
d = node.add_file(name, uploadable) d = node.add_file(name, uploadable)
d.addCallback(lambda filenode: filenode.get_uri()) d.addCallback(lambda filenode: filenode.get_uri())
return d return d
@ -1172,17 +1165,17 @@ class VDrive(rend.Page):
# the node must exist, and our operation will be performed on the # the node must exist, and our operation will be performed on the
# node itself. # node itself.
d = self.get_child_at_path(path) d = self.get_child_at_path(path)
def _got(node): def _got_POST(node):
return POSTHandler(node, replace), () return POSTHandler(node, replace), ()
d.addCallback(_got) d.addCallback(_got_POST)
elif method == "DELETE": elif method == "DELETE":
# the node must exist, and our operation will be performed on its # the node must exist, and our operation will be performed on its
# parent node. # parent node.
assert path # you can't delete the root assert path # you can't delete the root
d = self.get_child_at_path(path[:-1]) d = self.get_child_at_path(path[:-1])
def _got(node): def _got_DELETE(node):
return DELETEHandler(node, path[-1]), () return DELETEHandler(node, path[-1]), ()
d.addCallback(_got) d.addCallback(_got_DELETE)
elif method in ("PUT",): elif method in ("PUT",):
# the node may or may not exist, and our operation may involve # the node may or may not exist, and our operation may involve
# all the ancestors of the node. # all the ancestors of the node.
@ -1207,7 +1200,7 @@ class URIPUTHandler(rend.Page):
if t == "": if t == "":
# "PUT /uri", to create an unlinked file. This is like PUT but # "PUT /uri", to create an unlinked file. This is like PUT but
# without the associated set_uri. # without the associated set_uri.
uploadable = upload.FileHandle(req.content) uploadable = FileHandle(req.content)
d = IClient(ctx).upload(uploadable) d = IClient(ctx).upload(uploadable)
# that fires with the URI of the new file # that fires with the URI of the new file
return d return d
@ -1234,7 +1227,7 @@ class URIPOSTHandler(rend.Page):
if t in ("", "upload"): if t in ("", "upload"):
# "POST /uri", to create an unlinked file. # "POST /uri", to create an unlinked file.
fileobj = req.fields["file"].file fileobj = req.fields["file"].file
uploadable = upload.FileHandle(fileobj) uploadable = FileHandle(fileobj)
d = IClient(ctx).upload(uploadable) d = IClient(ctx).upload(uploadable)
# that fires with the URI of the new file # that fires with the URI of the new file
return d return d