=== modified file 'mandos' --- mandos 2014-07-25 23:32:04 +0000 +++ mandos 2014-07-25 23:39:49 +0000 @@ -401,13 +401,6 @@ return ret -def timedelta_to_milliseconds(td): - "Convert a datetime.timedelta() to milliseconds" - return ((td.days * 24 * 60 * 60 * 1000) - + (td.seconds * 1000) - + (td.microseconds // 1000)) - - class Client(object): """A representation of a client host served by this server. @@ -468,21 +461,6 @@ "enabled": "True", } - def timeout_milliseconds(self): - "Return the 'timeout' attribute in milliseconds" - return timedelta_to_milliseconds(self.timeout) - - def extended_timeout_milliseconds(self): - "Return the 'extended_timeout' attribute in milliseconds" - return timedelta_to_milliseconds(self.extended_timeout) - - def interval_milliseconds(self): - "Return the 'interval' attribute in milliseconds" - return timedelta_to_milliseconds(self.interval) - - def approval_delay_milliseconds(self): - return timedelta_to_milliseconds(self.approval_delay) - @staticmethod def config_parser(config): """Construct a new dict of client settings of this form: @@ -625,14 +603,16 @@ if self.checker_initiator_tag is not None: gobject.source_remove(self.checker_initiator_tag) self.checker_initiator_tag = (gobject.timeout_add - (self.interval_milliseconds(), + (int(self.interval + .total_seconds() * 1000), self.start_checker)) # Schedule a disable() when 'timeout' has passed if self.disable_initiator_tag is not None: gobject.source_remove(self.disable_initiator_tag) self.disable_initiator_tag = (gobject.timeout_add - (self.timeout_milliseconds(), - self.disable)) + (int(self.timeout + .total_seconds() * 1000), + self.disable)) # Also start a new checker *right now*. self.start_checker() @@ -669,8 +649,8 @@ self.disable_initiator_tag = None if getattr(self, "enabled", False): self.disable_initiator_tag = (gobject.timeout_add - (timedelta_to_milliseconds - (timeout), self.disable)) + (int(timeout.total_seconds() + * 1000), self.disable)) self.expires = datetime.datetime.utcnow() + timeout def need_approval(self): @@ -1305,21 +1285,23 @@ approval_delay = notifychangeproperty(dbus.UInt64, "ApprovalDelay", type_func = - timedelta_to_milliseconds) + lambda td: td.total_seconds() + * 1000) approval_duration = notifychangeproperty( dbus.UInt64, "ApprovalDuration", - type_func = timedelta_to_milliseconds) + type_func = lambda td: td.total_seconds() * 1000) host = notifychangeproperty(dbus.String, "Host") timeout = notifychangeproperty(dbus.UInt64, "Timeout", - type_func = - timedelta_to_milliseconds) + type_func = lambda td: + td.total_seconds() * 1000) extended_timeout = notifychangeproperty( dbus.UInt64, "ExtendedTimeout", - type_func = timedelta_to_milliseconds) + type_func = lambda td: td.total_seconds() * 1000) interval = notifychangeproperty(dbus.UInt64, "Interval", type_func = - timedelta_to_milliseconds) + lambda td: td.total_seconds() + * 1000) checker_command = notifychangeproperty(dbus.String, "Checker") del notifychangeproperty @@ -1368,9 +1350,8 @@ def approve(self, value=True): self.approved = value - gobject.timeout_add(timedelta_to_milliseconds - (self.approval_duration), - self._reset_approved) + gobject.timeout_add(int(self.approval_duration.total_seconds() + * 1000), self._reset_approved) self.send_changedstate() ## D-Bus methods, signals & properties @@ -1479,7 +1460,8 @@ access="readwrite") def ApprovalDelay_dbus_property(self, value=None): if value is None: # get - return dbus.UInt64(self.approval_delay_milliseconds()) + return dbus.UInt64(self.approval_delay.total_seconds() + * 1000) self.approval_delay = datetime.timedelta(0, 0, 0, value) # ApprovalDuration - property @@ -1487,8 +1469,8 @@ access="readwrite") def ApprovalDuration_dbus_property(self, value=None): if value is None: # get - return dbus.UInt64(timedelta_to_milliseconds( - self.approval_duration)) + return dbus.UInt64(self.approval_duration.total_seconds() + * 1000) self.approval_duration = datetime.timedelta(0, 0, 0, value) # Name - property @@ -1560,7 +1542,7 @@ access="readwrite") def Timeout_dbus_property(self, value=None): if value is None: # get - return dbus.UInt64(self.timeout_milliseconds()) + return dbus.UInt64(self.timeout.total_seconds() * 1000) old_timeout = self.timeout self.timeout = datetime.timedelta(0, 0, 0, value) # Reschedule disabling @@ -1577,15 +1559,16 @@ gobject.source_remove(self.disable_initiator_tag) self.disable_initiator_tag = ( gobject.timeout_add( - timedelta_to_milliseconds(self.expires - now), - self.disable)) + int((self.expires - now).total_seconds() + * 1000), self.disable)) # ExtendedTimeout - property @dbus_service_property(_interface, signature="t", access="readwrite") def ExtendedTimeout_dbus_property(self, value=None): if value is None: # get - return dbus.UInt64(self.extended_timeout_milliseconds()) + return dbus.UInt64(self.extended_timeout.total_seconds() + * 1000) self.extended_timeout = datetime.timedelta(0, 0, 0, value) # Interval - property @@ -1593,7 +1576,7 @@ access="readwrite") def Interval_dbus_property(self, value=None): if value is None: # get - return dbus.UInt64(self.interval_milliseconds()) + return dbus.UInt64(self.interval.total_seconds() * 1000) self.interval = datetime.timedelta(0, 0, 0, value) if getattr(self, "checker_initiator_tag", None) is None: return @@ -1759,8 +1742,8 @@ if self.server.use_dbus: # Emit D-Bus signal client.NeedApproval( - client.approval_delay_milliseconds(), - client.approved_by_default) + client.approval_delay.total_seconds() + * 1000, client.approved_by_default) else: logger.warning("Client %s was not approved", client.name) @@ -1772,9 +1755,7 @@ #wait until timeout or approved time = datetime.datetime.now() client.changedstate.acquire() - client.changedstate.wait( - float(timedelta_to_milliseconds(delay) - / 1000)) + client.changedstate.wait(delay.total_seconds()) client.changedstate.release() time2 = datetime.datetime.now() if (time2 - time) >= delay: === modified file 'mandos-ctl' --- mandos-ctl 2014-07-25 23:32:04 +0000 +++ mandos-ctl 2014-07-25 23:39:49 +0000 @@ -74,12 +74,6 @@ client_interface = domain + ".Mandos.Client" version = "1.6.7" -def timedelta_to_milliseconds(td): - """Convert a datetime.timedelta object to milliseconds""" - return ((td.days * 24 * 60 * 60 * 1000) - + (td.seconds * 1000) - + (td.microseconds // 1000)) - def milliseconds_to_string(ms): td = datetime.timedelta(0, 0, 0, ms) return ("{days}{hours:02}:{minutes:02}:{seconds:02}" @@ -411,8 +405,8 @@ """Set a Client D-Bus property, converted from a string to milliseconds.""" set_client_prop(prop, - timedelta_to_milliseconds - (string_to_delta(value))) + string_to_delta(value).total_seconds() + * 1000) if options.remove: mandos_serv.RemoveClient(client.__dbus_object_path__) if options.enable: