Mercurial > p > roundup > code
diff roundup/cgi/timestamp.py @ 6045:5ec3171580a6
flake whitespace changes.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 07 Jan 2020 21:50:57 -0500 |
| parents | 59842a3e8108 |
| children | 07ce4e4110f5 |
line wrap: on
line diff
--- a/roundup/cgi/timestamp.py Tue Jan 07 21:38:56 2020 -0500 +++ b/roundup/cgi/timestamp.py Tue Jan 07 21:50:57 2020 -0500 @@ -7,22 +7,25 @@ from roundup.i18n import _ from roundup.anypy.strings import b2s, s2b + def pack_timestamp(): return b2s(base64.b64encode(struct.pack("i", int(time.time()))).strip()) + def unpack_timestamp(s): try: - timestamp = struct.unpack("i",base64.b64decode(s2b(s)))[0] - except (struct.error, binascii.Error, TypeError) as e: + timestamp = struct.unpack("i", base64.b64decode(s2b(s)))[0] + except (struct.error, binascii.Error, TypeError): raise FormError(_("Form is corrupted.")) return timestamp + class Timestamped: - def timecheck(self,field,delay): + def timecheck(self, field, delay): try: created = unpack_timestamp(self.form[field].value) except KeyError: - raise FormError(_("Form is corrupted, missing: %s."%field)) + raise FormError(_("Form is corrupted, missing: %s." % field)) if time.time() - created < delay: raise FormError(_("Responding to form too quickly.")) return True
