# Path: lib/robot/running/userkeyword.py
# class UserLibrary(BaseLibrary):
#     supports_named_arguments = True # this attribute is for libdoc
# 
#     def __init__(self, user_keywords, path=None):
#         self.name = self._get_name_for_resource_file(path)
#         self.handlers = utils.NormalizedDict(ignore=['_'])
#         self.embedded_arg_handlers = []
#         for kw in user_keywords:
#             try:
#                 handler = EmbeddedArgsTemplate(kw, self.name)
#             except DataError, err:
#                 LOGGER.error("Creating user keyword '%s' failed: %s"
#                              % (kw.name, unicode(err)))
#                 continue
#             except TypeError:
#                 handler = UserKeywordHandler(kw, self.name)
#             else:
#                 self.embedded_arg_handlers.append(handler)
#             if handler.name in self.handlers:
#                 error = "Keyword '%s' defined multiple times." % handler.name
#                 handler = UserErrorHandler(handler.name, error)
#             self.handlers[handler.name] = handler
# 
#     def _get_name_for_resource_file(self, path):
#         if path is None:
#             return None
#         return os.path.splitext(os.path.basename(path))[0]
# 
#     def has_handler(self, name):
#         if BaseLibrary.has_handler(self, name):
#             return True
#         for template in self.embedded_arg_handlers:
#             try:
#                 EmbeddedArgs(name, template)
#             except TypeError:
#                 pass
#             else:
#                 return True
#         return False
# 
#     def get_handler(self, name):
#         try:
#             return BaseLibrary.get_handler(self, name)
#         except DataError, error:
#             found = self._get_embedded_arg_handlers(name)
#             if not found:
#                 raise error
#             if len(found) == 1:
#                 return found[0]
#             self._raise_multiple_matching_keywords_found(name, found)
# 
#     def _get_embedded_arg_handlers(self, name):
#         found = []
#         for template in self.embedded_arg_handlers:
#             try:
#                 found.append(EmbeddedArgs(name, template))
#             except TypeError:
#                 pass
#         return found
# 
#     def _raise_multiple_matching_keywords_found(self, name, found):
#         names = utils.seq2str([f.orig_name for f in found])
#         if self.name is None:
#             where = "Test case file"
#         else:
#             where = "Resource file '%s'" % self.name
#         raise DataError("%s contains multiple keywords matching name '%s'\n"
#                         "Found: %s" % (where, name, names))
# 
# Path: lib/robot/running/runkwregister.py
# RUN_KW_REGISTER = _RunKeywordRegister()
# 
# Path: lib/robot/running/handlers.py
# class _XTimesHandler(_RunKeywordHandler):
# 
#     def __init__(self, handler, name):
#         _RunKeywordHandler.__init__(self, handler.library, handler.name,
#                                     handler._handler_method)
#         self.name = name
#         self._doc = "*DEPRECATED* Replace X times syntax with 'Repeat Keyword'."
# 
#     def run(self, context, args):
#         resolved_times = context.namespace.variables.replace_string(self.name)
#         _RunnableHandler.run(self, context, [resolved_times] + args)
# 
#     @property
#     def longname(self):
#         return self.name
# 
# Path: lib/robot/running/context.py
# EXECUTION_CONTEXTS = ExecutionContexts()


import os
import sys
import copy
from robot import utils
from robot.errors import DataError
from robot.variables import GLOBAL_VARIABLES, is_scalar_var
from robot.common import UserErrorHandler
from robot.output import LOGGER
from robot.parsing.settings import Library, Variables, Resource
from .userkeyword import UserLibrary
from .importer import Importer, ImportCache
from .runkwregister import RUN_KW_REGISTER
from .handlers import _XTimesHandler
from .context import EXECUTION_CONTEXTS
        times = name[:-1].strip()
        if is_scalar_var(times):
            return True
        try:
            int(times)
        except ValueError:
            return False
        else:
            return True

    def _get_bdd_style_handler(self, name):
        for prefix in ['given ', 'when ', 'then ', 'and ']:
            if name.lower().startswith(prefix):
                handler = self._get_handler(name[len(prefix):])
                if handler:
                    handler = copy.copy(handler)
                    handler.name = name
                return handler
        return None

    def _get_implicit_handler(self, name):
        for method in [self._get_handler_from_test_case_file_user_keywords,
                       self._get_handler_from_resource_file_user_keywords,
                       self._get_handler_from_library_keywords]:
            handler = method(name)
            if handler:
                return handler
        return None

    def _get_handler_from_test_case_file_user_keywords(self, name):

# Path: lib/robot/running/userkeyword.py
# class UserLibrary(BaseLibrary):
#     supports_named_arguments = True # this attribute is for libdoc
# 
#     def __init__(self, user_keywords, path=None):
#         self.name = self._get_name_for_resource_file(path)
#         self.handlers = utils.NormalizedDict(ignore=['_'])
#         self.embedded_arg_handlers = []
#         for kw in user_keywords:
#             try:
#                 handler = EmbeddedArgsTemplate(kw, self.name)
#             except DataError, err:
#                 LOGGER.error("Creating user keyword '%s' failed: %s"
#                              % (kw.name, unicode(err)))
#                 continue
#             except TypeError:
#                 handler = UserKeywordHandler(kw, self.name)
#             else:
#                 self.embedded_arg_handlers.append(handler)
#             if handler.name in self.handlers:
#                 error = "Keyword '%s' defined multiple times." % handler.name
#                 handler = UserErrorHandler(handler.name, error)
#             self.handlers[handler.name] = handler
# 
#     def _get_name_for_resource_file(self, path):
#         if path is None:
#             return None
#         return os.path.splitext(os.path.basename(path))[0]
# 
#     def has_handler(self, name):
#         if BaseLibrary.has_handler(self, name):
#             return True
#         for template in self.embedded_arg_handlers:
#             try:
#                 EmbeddedArgs(name, template)
#             except TypeError:
#                 pass
#             else:
#                 return True
#         return False
# 
#     def get_handler(self, name):
#         try:
#             return BaseLibrary.get_handler(self, name)
#         except DataError, error:
#             found = self._get_embedded_arg_handlers(name)
#             if not found:
#                 raise error
#             if len(found) == 1:
#                 return found[0]
#             self._raise_multiple_matching_keywords_found(name, found)
# 
#     def _get_embedded_arg_handlers(self, name):
#         found = []
#         for template in self.embedded_arg_handlers:
#             try:
#                 found.append(EmbeddedArgs(name, template))
#             except TypeError:
#                 pass
#         return found
# 
#     def _raise_multiple_matching_keywords_found(self, name, found):
#         names = utils.seq2str([f.orig_name for f in found])
#         if self.name is None:
#             where = "Test case file"
#         else:
#             where = "Resource file '%s'" % self.name
#         raise DataError("%s contains multiple keywords matching name '%s'\n"
#                         "Found: %s" % (where, name, names))
# 
# Path: lib/robot/running/runkwregister.py
# RUN_KW_REGISTER = _RunKeywordRegister()
# 
# Path: lib/robot/running/handlers.py
# class _XTimesHandler(_RunKeywordHandler):
# 
#     def __init__(self, handler, name):
#         _RunKeywordHandler.__init__(self, handler.library, handler.name,
#                                     handler._handler_method)
#         self.name = name
#         self._doc = "*DEPRECATED* Replace X times syntax with 'Repeat Keyword'."
# 
#     def run(self, context, args):
#         resolved_times = context.namespace.variables.replace_string(self.name)
#         _RunnableHandler.run(self, context, [resolved_times] + args)
# 
#     @property
#     def longname(self):
#         return self.name
# 
# Path: lib/robot/running/context.py
# EXECUTION_CONTEXTS = ExecutionContexts()


# Path: lib/robot/running/namespace.py
import os
import sys
import copy
from robot import utils
from robot.errors import DataError
from robot.variables import GLOBAL_VARIABLES, is_scalar_var
from robot.common import UserErrorHandler
from robot.output import LOGGER
from robot.parsing.settings import Library, Variables, Resource
from .userkeyword import UserLibrary
from .importer import Importer, ImportCache
from .runkwregister import RUN_KW_REGISTER
from .handlers import _XTimesHandler
from .context import EXECUTION_CONTEXTS

        times = name[:-1].strip()
        if is_scalar_var(times):
            return True
        try:
            int(times)
        except ValueError:
            return False
        else:
            return True

    def _get_bdd_style_handler(self, name):
        for prefix in ['given ', 'when ', 'then ', 'and ']:
            if name.lower().startswith(prefix):
                handler = self._get_handler(name[len(prefix):])
                if handler:
                    handler = copy.copy(handler)
                    handler.name = name
                return handler
        return None

    def _get_implicit_handler(self, name):
        for method in [self._get_handler_from_test_case_file_user_keywords,
                       self._get_handler_from_resource_file_user_keywords,
                       self._get_handler_from_library_keywords]:
            handler = method(name)
            if handler:
                return handler
        return None

    def _get_handler_from_test_case_file_user_keywords(self, name):

        if self.suite.user_keywords.has_handler(name):