from nevow import loaders, appserver
from nevow.inevow import IRequest
from nevow.util import resource_filename
+from allmydata import blacklist
from allmydata.interfaces import ExistingChildError, NoSuchChildError, \
FileTooLargeError, NotEnoughSharesError, NoSharesError, \
EmptyPathnameComponentError, MustBeDeepImmutableError, \
def boolean_of_arg(arg):
# TODO: ""
- assert arg.lower() in ("true", "t", "1", "false", "f", "0", "on", "off")
+ if arg.lower() not in ("true", "t", "1", "false", "f", "0", "on", "off"):
+ raise WebError("invalid boolean argument: %r" % (arg,), http.BAD_REQUEST)
return arg.lower() in ("true", "t", "1", "on")
def parse_replace_arg(replace):
if replace.lower() == "only-files":
return replace
- else:
+ try:
return boolean_of_arg(replace)
+ except WebError:
+ raise WebError("invalid replace= argument: %r" % (replace,), http.BAD_REQUEST)
-def parse_mutable_type_arg(arg):
+def get_format(req, default="CHK"):
+ arg = get_arg(req, "format", None)
if not arg:
- return None # interpreted by the caller as "let the nodemaker decide"
+ if boolean_of_arg(get_arg(req, "mutable", "false")):
+ return "SDMF"
+ return default
+ if arg.upper() == "CHK":
+ return "CHK"
+ elif arg.upper() == "SDMF":
+ return "SDMF"
+ elif arg.upper() == "MDMF":
+ return "MDMF"
+ else:
+ raise WebError("Unknown format: %s, I know CHK, SDMF, MDMF" % arg,
+ http.BAD_REQUEST)
- arg = arg.lower()
- if arg == "mdmf":
- return MDMF_VERSION
- elif arg == "sdmf":
+def get_mutable_type(file_format): # accepts result of get_format()
+ if file_format == "SDMF":
return SDMF_VERSION
-
- return "invalid"
+ elif file_format == "MDMF":
+ return MDMF_VERSION
+ else:
+ # this is also used to identify which formats are mutable. Use
+ # if get_mutable_type(file_format) is not None:
+ # do_mutable()
+ # else:
+ # do_immutable()
+ return None
def parse_offset_arg(offset):
"The cap is being passed in a read slot (ro_uri), or was retrieved "
"from a read slot as an unknown cap.") % quoted_name
return (t, http.BAD_REQUEST)
+ if f.check(blacklist.FileProhibited):
+ t = "Access Prohibited: %s" % quote_output(f.value.reason, encoding="utf-8", quotemarks=False)
+ return (t, http.FORBIDDEN)
if f.check(WebError):
return (f.value.text, f.value.code)
if f.check(FileTooLargeError):