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 -*-
1
#!/usr/bin/python3 -bbI
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
253
def rfc3339_duration_to_delta(duration):
251
254
"""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)
256
>>> rfc3339_duration_to_delta("P7D") == datetime.timedelta(7)
258
>>> rfc3339_duration_to_delta("PT60S") == datetime.timedelta(0, 60)
260
>>> rfc3339_duration_to_delta("PT60M") == datetime.timedelta(hours=1)
263
>>> rfc3339_duration_to_delta("P60M") == datetime.timedelta(1680)
265
>>> rfc3339_duration_to_delta("PT24H") == datetime.timedelta(1)
267
>>> rfc3339_duration_to_delta("P1W") == datetime.timedelta(7)
269
>>> rfc3339_duration_to_delta("PT5M30S") == datetime.timedelta(0, 330)
271
>>> rfc3339_duration_to_delta("P1DT3M20S") == datetime.timedelta(1, 200)
269
273
>>> # Can not be empty:
270
274
>>> rfc3339_duration_to_delta("")
271
275
Traceback (most recent call last):
381
385
"""Parse an interval string as documented by Mandos before 1.6.1,
382
386
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)
388
>>> parse_pre_1_6_1_interval('7d') == datetime.timedelta(days=7)
390
>>> parse_pre_1_6_1_interval('60s') == datetime.timedelta(0, 60)
392
>>> parse_pre_1_6_1_interval('60m') == datetime.timedelta(hours=1)
394
>>> parse_pre_1_6_1_interval('24h') == datetime.timedelta(days=1)
396
>>> parse_pre_1_6_1_interval('1w') == datetime.timedelta(days=7)
398
>>> parse_pre_1_6_1_interval('5m 30s') == datetime.timedelta(0, 330)
400
>>> parse_pre_1_6_1_interval('') == datetime.timedelta(0)
398
402
>>> # Ignore unknown characters, allow any order and repetitions
399
>>> parse_pre_1_6_1_interval('2dxy7zz11y3m5m')
400
datetime.timedelta(2, 480, 18000)
403
>>> parse_pre_1_6_1_interval('2dxy7zz11y3m5m') == datetime.timedelta(2, 480, 18000)
580
584
self.client_interface, key,
583
class SilenceLogger(object):
584
588
"Simple context manager to silence a particular logger"
585
589
def __init__(self, loggername):
586
590
self.logger = logging.getLogger(loggername)
714
class command(object):
715
719
"""A namespace for command classes"""
718
722
"""Abstract base class for commands"""
719
723
def run(self, clients, bus=None):
720
724
"""Normal commands should implement run_on_one_client(),
1310
1314
class Test_dbus_python_adapter_SystemBus(TestCaseWithAssertLogs):
1312
1316
def MockDBusPython_func(self, func):
1313
class mock_dbus_python(object):
1317
class mock_dbus_python:
1314
1318
"""mock dbus-python module"""
1315
class exceptions(object):
1316
1320
"""Pseudo-namespace"""
1317
1321
class DBusException(Exception):
1319
class SystemBus(object):
1321
1325
def get_object(busname, objectpath):
1322
1326
DBusObject = collections.namedtuple(
1554
1558
self.call_method(bus, "methodname", "busname",
1555
1559
"objectpath", "interface")
1557
class fake_dbus_python_raises_exception_on_connect(object):
1561
class fake_dbus_python_raises_exception_on_connect:
1558
1562
"""fake dbus-python module"""
1559
class exceptions(object):
1560
1564
"""Pseudo-namespace"""
1561
1565
class DBusException(Exception):
1572
1576
class Test_dbus_python_adapter_CachingBus(unittest.TestCase):
1573
class mock_dbus_python(object):
1577
class mock_dbus_python:
1574
1578
"""mock dbus-python modules"""
1575
class SystemBus(object):
1577
1581
def get_object(busname, objectpath):
1578
1582
return Unique()
1624
1628
class Test_pydbus_adapter_SystemBus(TestCaseWithAssertLogs):
1626
1630
def Stub_pydbus_func(self, func):
1627
class stub_pydbus(object):
1628
1632
"""stub pydbus module"""
1629
class SystemBus(object):
1631
1635
def get(busname, objectpath):
1632
1636
DBusObject = collections.namedtuple(
1678
1682
self.call_method(bus, "methodname", "busname",
1679
1683
"objectpath", "interface")
1681
class fake_pydbus_raises_exception_on_connect(object):
1685
class fake_pydbus_raises_exception_on_connect:
1682
1686
"""fake dbus-python module"""
1684
1688
def SystemBus(cls):
1688
1692
return Bus(get=get)
1690
1694
def test_set_property_uses_setattr(self):
1691
class Object(object):
1694
class pydbus_spy(object):
1695
class SystemBus(object):
1697
1701
def get(busname, objectpath):
1698
1702
return {"interface": obj}
1705
1709
def test_get_suppresses_xml_deprecation_warning(self):
1706
1710
if sys.version_info.major >= 3:
1708
class stub_pydbus_get(object):
1709
class SystemBus(object):
1712
class stub_pydbus_get:
1711
1715
def get(busname, objectpath):
1712
1716
warnings.warn_explicit(
2003
2007
def test_manual_page_example_1(self):
2004
self.assert_command_from_args("--verbose".split(),
2008
self.assert_command_from_args("",
2005
2009
command.PrintTable,
2009
2013
def test_manual_page_example_2(self):
2010
2014
self.assert_command_from_args(