1111
1111
interface_names.add(alt_interface)
1112
1112
# Is this a D-Bus signal?
1113
1113
if getattr(attribute, "_dbus_is_signal", False):
1114
if sys.version == 2:
1115
# Extract the original non-method undecorated
1116
# function by black magic
1117
nonmethod_func = (dict(
1118
zip(attribute.func_code.co_freevars,
1119
attribute.__closure__))
1120
["func"].cell_contents)
1122
nonmethod_func = attribute
1114
# Extract the original non-method undecorated
1115
# function by black magic
1116
nonmethod_func = (dict(
1117
zip(attribute.func_code.co_freevars,
1118
attribute.__closure__))
1119
["func"].cell_contents)
1123
1120
# Create a new, but exactly alike, function
1124
1121
# object, and decorate it to be a new D-Bus signal
1125
1122
# with the alternate D-Bus interface name
1126
if sys.version == 2:
1127
new_function = types.FunctionType(
1128
nonmethod_func.func_code,
1129
nonmethod_func.func_globals,
1130
nonmethod_func.func_name,
1131
nonmethod_func.func_defaults,
1132
nonmethod_func.func_closure)
1134
new_function = types.FunctionType(
1135
nonmethod_func.__code__,
1136
nonmethod_func.__globals__,
1137
nonmethod_func.__name__,
1138
nonmethod_func.__defaults__,
1139
nonmethod_func.__closure__)
1140
1123
new_function = (dbus.service.signal(
1142
attribute._dbus_signature)(new_function))
1124
alt_interface, attribute._dbus_signature)
1125
(types.FunctionType(
1126
nonmethod_func.func_code,
1127
nonmethod_func.func_globals,
1128
nonmethod_func.func_name,
1129
nonmethod_func.func_defaults,
1130
nonmethod_func.func_closure)))
1143
1131
# Copy annotations, if any
1145
1133
new_function._dbus_annotations = dict(
2195
2182
# avoid excessive use of external libraries.
2197
2184
# New type for defining tokens, syntax, and semantics all-in-one
2185
Token = collections.namedtuple("Token",
2186
("regexp", # To match token; if
2187
# "value" is not None,
2188
# must have a "group"
2190
"value", # datetime.timedelta or
2192
"followers")) # Tokens valid after
2198
2194
Token = collections.namedtuple("Token", (
2199
2195
"regexp", # To match token; if "value" is not None, must have
2200
2196
# a "group" containing digits
2235
2231
# Define starting values
2236
2232
value = datetime.timedelta() # Value so far
2237
2233
found_token = None
2238
followers = frozenset((token_duration, )) # Following valid tokens
2234
followers = frozenset((token_duration,)) # Following valid tokens
2239
2235
s = duration # String left to parse
2240
2236
# Loop until end token is found
2241
2237
while found_token is not token_end: