X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=src%2Fallmydata%2Fweb%2Fcommon.py;h=5cfe84d9a4a09237669dc913280c08a78cc994f0;hb=9fabb924867e164e1c6d4d805761db6c39652cf7;hp=f4229bb24dad1632f07841ada78c97b79e70faba;hpb=20b77ef4ff0d508434666ac6cc8a51d957e727c1;p=tahoe-lafs%2Ftahoe-lafs.git diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index f4229bb2..5cfe84d9 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -1,5 +1,7 @@ +import time import simplejson + from twisted.web import http, server from twisted.python import log from zope.interface import Interface @@ -13,6 +15,7 @@ from allmydata.interfaces import ExistingChildError, NoSuchChildError, \ MustBeReadonlyError, MustNotBeUnknownRWError, SDMF_VERSION, MDMF_VERSION from allmydata.mutable.common import UnrecoverableFileError from allmydata.util import abbreviate +from allmydata.util.time_format import format_time, format_delta from allmydata.util.encodingutil import to_str, quote_output @@ -207,6 +210,18 @@ def text_plain(text, ctx): req.setHeader("content-length", b"%d" % len(text)) return text +def spaces_to_nbsp(text): + return unicode(text).replace(u' ', u'\u00A0') + +def render_time_delta(time_1, time_2): + return spaces_to_nbsp(format_delta(time_1, time_2)) + +def render_time(t): + return spaces_to_nbsp(format_time(time.localtime(t))) + +def render_time_attr(t): + return format_time(time.localtime(t)) + class WebError(Exception): def __init__(self, text, code=http.BAD_REQUEST): self.text = text