2
# -*- after-save-hook: (lambda () (let ((command (if (fboundp 'file-local-name) (file-local-name (buffer-file-name)) (or (file-remote-p (buffer-file-name) 'localname) (buffer-file-name))))) (if (= (progn (if (get-buffer "*Test*") (kill-buffer "*Test*")) (process-file-shell-command (format "%s --test" (shell-quote-argument command)) nil "*Test*")) 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w))) (progn (with-current-buffer "*Test*" (compilation-mode)) (display-buffer "*Test*" '(display-buffer-in-side-window)))))); coding: utf-8 -*-
2
# -*- after-save-hook: (lambda () (let ((command (if (fboundp 'file-local-name) (file-local-name (buffer-file-name)) (or (file-remote-p (buffer-file-name) 'localname) (buffer-file-name))))) (if (= (progn (if (get-buffer "*Test*") (kill-buffer "*Test*")) (process-file-shell-command (format "%s --check" (shell-quote-argument command)) nil "*Test*")) 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w))) (progn (with-current-buffer "*Test*" (compilation-mode)) (display-buffer "*Test*" '(display-buffer-in-side-window)))))); coding: utf-8 -*-
4
4
# Mandos Monitor - Control and monitor the Mandos server
250
250
def rfc3339_duration_to_delta(duration):
251
251
"""Parse an RFC 3339 "duration" and return a datetime.timedelta
253
>>> rfc3339_duration_to_delta("P7D")
254
datetime.timedelta(7)
255
>>> rfc3339_duration_to_delta("PT60S")
256
datetime.timedelta(0, 60)
257
>>> rfc3339_duration_to_delta("PT60M")
258
datetime.timedelta(0, 3600)
259
>>> rfc3339_duration_to_delta("P60M")
260
datetime.timedelta(1680)
261
>>> rfc3339_duration_to_delta("PT24H")
262
datetime.timedelta(1)
263
>>> rfc3339_duration_to_delta("P1W")
264
datetime.timedelta(7)
265
>>> rfc3339_duration_to_delta("PT5M30S")
266
datetime.timedelta(0, 330)
267
>>> rfc3339_duration_to_delta("P1DT3M20S")
268
datetime.timedelta(1, 200)
253
>>> rfc3339_duration_to_delta("P7D") == datetime.timedelta(7)
255
>>> rfc3339_duration_to_delta("PT60S") == datetime.timedelta(0, 60)
257
>>> rfc3339_duration_to_delta("PT60M") == datetime.timedelta(hours=1)
260
>>> rfc3339_duration_to_delta("P60M") == datetime.timedelta(1680)
262
>>> rfc3339_duration_to_delta("PT24H") == datetime.timedelta(1)
264
>>> rfc3339_duration_to_delta("P1W") == datetime.timedelta(7)
266
>>> rfc3339_duration_to_delta("PT5M30S") == datetime.timedelta(0, 330)
268
>>> rfc3339_duration_to_delta("P1DT3M20S") == datetime.timedelta(1, 200)
269
270
>>> # Can not be empty:
270
271
>>> rfc3339_duration_to_delta("")
271
272
Traceback (most recent call last):
381
382
"""Parse an interval string as documented by Mandos before 1.6.1,
382
383
and return a datetime.timedelta
384
>>> parse_pre_1_6_1_interval('7d')
385
datetime.timedelta(7)
386
>>> parse_pre_1_6_1_interval('60s')
387
datetime.timedelta(0, 60)
388
>>> parse_pre_1_6_1_interval('60m')
389
datetime.timedelta(0, 3600)
390
>>> parse_pre_1_6_1_interval('24h')
391
datetime.timedelta(1)
392
>>> parse_pre_1_6_1_interval('1w')
393
datetime.timedelta(7)
394
>>> parse_pre_1_6_1_interval('5m 30s')
395
datetime.timedelta(0, 330)
396
>>> parse_pre_1_6_1_interval('')
397
datetime.timedelta(0)
385
>>> parse_pre_1_6_1_interval('7d') == datetime.timedelta(days=7)
387
>>> parse_pre_1_6_1_interval('60s') == datetime.timedelta(0, 60)
389
>>> parse_pre_1_6_1_interval('60m') == datetime.timedelta(hours=1)
391
>>> parse_pre_1_6_1_interval('24h') == datetime.timedelta(days=1)
393
>>> parse_pre_1_6_1_interval('1w') == datetime.timedelta(days=7)
395
>>> parse_pre_1_6_1_interval('5m 30s') == datetime.timedelta(0, 330)
397
>>> parse_pre_1_6_1_interval('') == datetime.timedelta(0)
398
399
>>> # Ignore unknown characters, allow any order and repetitions
399
>>> parse_pre_1_6_1_interval('2dxy7zz11y3m5m')
400
datetime.timedelta(2, 480, 18000)
400
>>> parse_pre_1_6_1_interval('2dxy7zz11y3m5m') == datetime.timedelta(2, 480, 18000)
2003
2004
def test_manual_page_example_1(self):
2004
self.assert_command_from_args("--verbose".split(),
2005
self.assert_command_from_args("",
2005
2006
command.PrintTable,
2009
2010
def test_manual_page_example_2(self):
2010
2011
self.assert_command_from_args(