files.new_contents: # Copyright 2017 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  import imp
  import operator
  import sys
  import time
  import csv
  import inspect
  from inspect import signature
  from datetime import datetime, timedelta
  
  import abc
  import re
  from adapt.intent import Intent, IntentBuilder
  from os.path import join, abspath, dirname, basename, exists
  from threading import Event
  
  from mycroft import dialog
  from mycroft.api import DeviceApi
  from mycroft.audio import wait_while_speaking
  from mycroft.client.enclosure.api import EnclosureAPI
  from mycroft.configuration import Configuration
  from mycroft.dialog import DialogLoader
  from mycroft.filesystem import FileSystemAccess
  from mycroft.messagebus.message import Message
  from mycroft.metrics import report_metric, report_timing, Stopwatch
  from mycroft.skills.settings import SkillSettings
  from mycroft.skills.skill_data import (load_vocabulary, load_regex, to_alnum,
                                         munge_regex, munge_intent_parser)
  from mycroft.util import resolve_resource_file
  from mycroft.util.log import LOG
  
  MainModule = '__init__'
  
  
  def dig_for_message():
      """
          Dig Through the stack for message.
      """
      stack = inspect.stack()
      # Limit search to 10 frames back
  
  [... the rest is omitted ...]
files.new_path: mycroft/skills/core.py
files.old_contents: # Copyright 2017 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  import imp
  import operator
  import sys
  import time
  import csv
  import inspect
  from inspect import signature
  from datetime import datetime, timedelta
  
  import abc
  import re
  from adapt.intent import Intent, IntentBuilder
  from os.path import join, abspath, dirname, basename, exists
  from threading import Event
  
  from mycroft import dialog
  from mycroft.api import DeviceApi
  from mycroft.audio import wait_while_speaking
  from mycroft.client.enclosure.api import EnclosureAPI
  from mycroft.configuration import Configuration
  from mycroft.dialog import DialogLoader
  from mycroft.filesystem import FileSystemAccess
  from mycroft.messagebus.message import Message
  from mycroft.metrics import report_metric, report_timing, Stopwatch
  from mycroft.skills.settings import SkillSettings
  from mycroft.skills.skill_data import (load_vocabulary, load_regex, to_letters,
                                         munge_regex, munge_intent_parser)
  from mycroft.util import resolve_resource_file
  from mycroft.util.log import LOG
  
  MainModule = '__init__'
  
  
  def dig_for_message():
      """
          Dig Through the stack for message.
      """
      stack = inspect.stack()
      # Limit search to 10 frames back
  
  [... the rest is omitted ...]
files.old_path: mycroft/skills/core.py
files.new_contents: # Copyright 2017 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  import time
  from adapt.context import ContextManagerFrame
  from adapt.engine import IntentDeterminationEngine
  
  from mycroft.configuration import Configuration
  from mycroft.messagebus.message import Message
  from mycroft.skills.core import open_intent_envelope
  from mycroft.util.log import LOG
  from mycroft.util.parse import normalize
  from mycroft.metrics import report_timing, Stopwatch
  
  
  class ContextManager(object):
      """
      ContextManager
      Use to track context throughout the course of a conversational session.
      How to manage a session's lifecycle is not captured here.
      """
  
      def __init__(self, timeout):
          self.frame_stack = []
          self.timeout = timeout * 60  # minutes to seconds
  
      def clear_context(self):
          self.frame_stack = []
  
      def remove_context(self, context_id):
          self.frame_stack = [(f, t) for (f, t) in self.frame_stack
                              if context_id in f.entities[0].get('data', [])]
  
      def inject_context(self, entity, metadata=None):
          """
          Args:
              entity(object): Format example...
                                 {'data': 'Entity tag as <str>',
                                  'key': 'entity proper name as <str>',
                                  'confidence': <float>'
                                 }
  
  
  [... the rest is omitted ...]
files.new_path: mycroft/skills/intent_service.py
files.old_contents: # Copyright 2017 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  import time
  from adapt.context import ContextManagerFrame
  from adapt.engine import IntentDeterminationEngine
  
  from mycroft.configuration import Configuration
  from mycroft.messagebus.message import Message
  from mycroft.skills.core import open_intent_envelope
  from mycroft.util.log import LOG
  from mycroft.util.parse import normalize
  from mycroft.metrics import report_timing, Stopwatch
  
  
  class ContextManager(object):
      """
      ContextManager
      Use to track context throughout the course of a conversational session.
      How to manage a session's lifecycle is not captured here.
      """
  
      def __init__(self, timeout):
          self.frame_stack = []
          self.timeout = timeout * 60  # minutes to seconds
  
      def clear_context(self):
          self.frame_stack = []
  
      def remove_context(self, context_id):
          self.frame_stack = [(f, t) for (f, t) in self.frame_stack
                              if context_id in f.entities[0].get('data', [])]
  
      def inject_context(self, entity, metadata=None):
          """
          Args:
              entity(object): Format example...
                                 {'data': 'Entity tag as <str>',
                                  'key': 'entity proper name as <str>',
                                  'confidence': <float>'
                                 }
  
  
  [... the rest is omitted ...]
files.old_path: mycroft/skills/intent_service.py
files.new_contents: # Copyright 2017 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  import gc
  import os
  import sys
  import time
  from itertools import chain
  from threading import Timer, Thread, Event
  
  import monotonic
  from glob import glob
  from os.path import exists, join, basename, dirname, expanduser, isfile
  from msm import MycroftSkillsManager, SkillRepo
  
  import mycroft.lock
  from mycroft import dialog
  from mycroft.api import is_paired, BackendDown
  from mycroft.client.enclosure.api import EnclosureAPI
  from mycroft.configuration import Configuration
  from mycroft.messagebus.client.ws import WebsocketClient
  from mycroft.messagebus.message import Message
  from mycroft.skills.core import load_skill, create_skill_descriptor, \
      MainModule, FallbackSkill
  from mycroft.skills.event_scheduler import EventScheduler
  from mycroft.skills.intent_service import IntentService
  from mycroft.skills.padatious_service import PadatiousService
  from mycroft.util import (
      connected, wait_while_speaking, reset_sigint_handler,
      create_echo_function, create_daemon, wait_for_exit_signal
  )
  from mycroft.util.log import LOG
  
  ws = None
  event_scheduler = None
  skill_manager = None
  
  [... the rest is omitted ...]
files.new_path: mycroft/skills/main.py
files.old_contents: # Copyright 2017 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  import gc
  import os
  import sys
  import time
  from itertools import chain
  from threading import Timer, Thread, Event
  
  import monotonic
  from glob import glob
  from os.path import exists, join, basename, dirname, expanduser, isfile
  from msm import MycroftSkillsManager, SkillRepo
  
  import mycroft.lock
  from mycroft import dialog
  from mycroft.api import is_paired, BackendDown
  from mycroft.client.enclosure.api import EnclosureAPI
  from mycroft.configuration import Configuration
  from mycroft.messagebus.client.ws import WebsocketClient
  from mycroft.messagebus.message import Message
  from mycroft.skills.core import load_skill, create_skill_descriptor, \
      MainModule, FallbackSkill
  from mycroft.skills.event_scheduler import EventScheduler
  from mycroft.skills.intent_service import IntentService
  from mycroft.skills.padatious_service import PadatiousService
  from mycroft.util import (
      connected, wait_while_speaking, reset_sigint_handler,
      create_echo_function, create_daemon, wait_for_exit_signal
  )
  from mycroft.util.log import LOG
  
  ws = None
  event_scheduler = None
  skill_manager = None
  
  [... the rest is omitted ...]
files.old_path: mycroft/skills/main.py
files.new_contents: # Copyright 2018 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  
  """Module containing methods needed to load skill
  data such as dialogs, intents and regular expressions.
  """
  
  from os import listdir
  from os.path import splitext, join
  import re
  
  from mycroft.messagebus.message import Message
  
  
  def load_vocab_from_file(path, vocab_type, emitter):
      """Load Mycroft vocabulary from file
      The vocab is sent to the intent handler using the message bus
  
      Args:
          path:           path to vocabulary file (*.voc)
          vocab_type:     keyword name
          emitter:        emitter to access the message bus
          skill_id(str):  skill id
      """
      if path.endswith('.voc'):
          with open(path, 'r') as voc_file:
              for line in voc_file.readlines():
                  if line.startswith("#"):
                      continue
                  parts = line.strip().split("|")
                  entity = parts[0]
                  emitter.emit(Message("register_vocab", {
                      'start': entity, 'end': vocab_type
                  }))
                  for alias in parts[1:]:
                      emitter.emit(Message("register_vocab", {
                          'start': alias, 'end': vocab_type, 'alias_of': entity
                      }))
  
  
  def load_regex_from_file(path, emitter,
  
  [... the rest is omitted ...]
files.new_path: mycroft/skills/skill_data.py
files.old_contents: # Copyright 2018 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  
  """Module containing methods needed to load skill
  data such as dialogs, intents and regular expressions.
  """
  
  from os import listdir
  from os.path import splitext, join
  import re
  
  from mycroft.messagebus.message import Message
  
  
  def load_vocab_from_file(path, vocab_type, emitter):
      """Load Mycroft vocabulary from file
      The vocab is sent to the intent handler using the message bus
  
      Args:
          path:           path to vocabulary file (*.voc)
          vocab_type:     keyword name
          emitter:        emitter to access the message bus
          skill_id(str):  skill id
      """
      if path.endswith('.voc'):
          with open(path, 'r') as voc_file:
              for line in voc_file.readlines():
                  if line.startswith("#"):
                      continue
                  parts = line.strip().split("|")
                  entity = parts[0]
                  emitter.emit(Message("register_vocab", {
                      'start': entity, 'end': vocab_type
                  }))
                  for alias in parts[1:]:
                      emitter.emit(Message("register_vocab", {
                          'start': alias, 'end': vocab_type, 'alias_of': entity
                      }))
  
  
  def load_regex_from_file(path, emitter,
  
  [... the rest is omitted ...]
files.old_path: mycroft/skills/skill_data.py
files.new_contents: # -*- coding: utf-8 -*-
  # Copyright 2017 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  import sys
  import unittest
  
  import mock
  from adapt.intent import IntentBuilder
  from os.path import join, dirname, abspath
  from re import error
  from datetime import datetime
  
  from mycroft.configuration import Configuration
  from mycroft.messagebus.message import Message
  from mycroft.skills.skill_data import load_regex_from_file, load_regex, \
      load_vocab_from_file, load_vocabulary
  from mycroft.skills.core import MycroftSkill, load_skill, \
      create_skill_descriptor, open_intent_envelope
  
  from mycroft.configuration.config import LocalConf, DEFAULT_CONFIG
  
  BASE_CONF = LocalConf(DEFAULT_CONFIG)
  
  
  class MockEmitter(object):
      def __init__(self):
          self.reset()
  
      def emit(self, message):
          self.types.append(message.type)
          self.results.append(message.data)
  
      def get_types(self):
          return self.types
  
      def get_results(self):
          return self.results
  
      def on(self, event, f):
          pass
  
      def reset(self):
          self.types = []
          self.results = []
  
  
  class MycroftSkillTest(unittest.TestCase):
      emitter = MockEmitter()
      regex_path = abspath
  
  [... the rest is omitted ...]
files.new_path: test/unittests/skills/core.py
files.old_contents: # -*- coding: utf-8 -*-
  # Copyright 2017 Mycroft AI Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #    http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  #
  import sys
  import unittest
  
  import mock
  from adapt.intent import IntentBuilder
  from os.path import join, dirname, abspath
  from re import error
  from datetime import datetime
  
  from mycroft.configuration import Configuration
  from mycroft.messagebus.message import Message
  from mycroft.skills.skill_data import load_regex_from_file, load_regex, \
      load_vocab_from_file, load_vocabulary
  from mycroft.skills.core import MycroftSkill, load_skill, \
      create_skill_descriptor, open_intent_envelope
  
  from mycroft.configuration.config import LocalConf, DEFAULT_CONFIG
  
  BASE_CONF = LocalConf(DEFAULT_CONFIG)
  
  
  class MockEmitter(object):
      def __init__(self):
          self.reset()
  
      def emit(self, message):
          self.types.append(message.type)
          self.results.append(message.data)
  
      def get_types(self):
          return self.types
  
      def get_results(self):
          return self.results
  
      def on(self, event, f):
          pass
  
      def reset(self):
          self.types = []
          self.results = []
  
  
  class MycroftSkillTest(unittest.TestCase):
      emitter = MockEmitter()
      regex_path = abspath
  
  [... the rest is omitted ...]
files.old_path: test/unittests/skills/core.py