context.py
Go to the documentation of this file.
1 # Copyright 2017 Mycroft AI Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 from functools import wraps
16 
17 """
18  Helper decorators for handling context from skills.
19 """
20 
21 
22 def adds_context(context, words=''):
23  """
24  Adds context to context manager.
25  """
26  def context_add_decorator(func):
27  @wraps(func)
28  def func_wrapper(*args, **kwargs):
29  ret = func(*args, **kwargs)
30  args[0].set_context(context)
31  return ret
32  return func_wrapper
33  return context_add_decorator
34 
35 
36 def removes_context(context):
37  """
38  Removes context from the context manager.
39  """
40  def context_removes_decorator(func):
41  @wraps(func)
42  def func_wrapper(*args, **kwargs):
43  ret = func(*args, **kwargs)
44  args[0].remove_context(context)
45  return ret
46  return func_wrapper
47  return context_removes_decorator
def adds_context(context, words='')
Definition: context.py:22
def removes_context(context)
Definition: context.py:36


mycroft_ros
Author(s):
autogenerated on Mon Apr 26 2021 02:35:40