# Path: lib/robot/running/keywords.py
# class Keywords(object):
# 
#     def __init__(self, steps, template=None):
#         self._keywords = []
#         self._templated = bool(template)
#         if self._templated:
#             steps = [s.apply_template(template) for s in steps]
#         for s in steps:
#             self._add_step(s, template)
# 
#     def _add_step(self, step, template):
#         if step.is_comment():
#             return
#         if step.is_for_loop():
#             keyword = ForLoop(step, template)
#         else:
#             keyword = Keyword(step.keyword, step.args, step.assign)
#         self.add_keyword(keyword)
# 
#     def add_keyword(self, keyword):
#         self._keywords.append(keyword)
# 
#     def run(self, context):
#         errors = []
#         for kw in self._keywords:
#             try:
#                 kw.run(context)
#             except ExecutionFailed, err:
#                 errors.extend(err.get_errors())
#                 if not err.can_continue(context.teardown, self._templated,
#                                         context.dry_run):
#                     break
#         if errors:
#             raise ExecutionFailures(errors)
# 
#     def __nonzero__(self):
#         return bool(self._keywords)
# 
#     def __iter__(self):
#         return iter(self._keywords)
# 
# class Keyword(BaseKeyword):
# 
#     def __init__(self, name, args, assign=None, type='kw'):
#         BaseKeyword.__init__(self, name, args, type=type)
#         self.assign = assign or []
#         self.handler_name = name
# 
#     def run(self, context):
#         handler = self._start(context)
#         try:
#             return_value = self._run(handler, context)
#         except ExecutionFailed, err:
#             self.status = 'FAIL' if not err.exit_for_loop else 'PASS'
#             self._end(context, error=err)
#             raise
#         else:
#             if not (context.dry_run and handler.type == 'library'):
#                 self.status = 'PASS'
#             self._end(context, return_value)
#             return return_value
# 
#     def _start(self, context):
#         handler = context.get_handler(self.handler_name)
#         handler.init_keyword(context.get_current_vars())
#         self.name = self._get_name(handler.longname)
#         self.doc = handler.shortdoc
#         self.timeout = getattr(handler, 'timeout', '')
#         self.starttime = get_timestamp()
#         context.start_keyword(self)
#         if self.doc.startswith('*DEPRECATED*'):
#             msg = self.doc.replace('*DEPRECATED*', '', 1).strip()
#             name = self.name.split('} = ', 1)[-1]  # Remove possible variable
#             context.warn("Keyword '%s' is deprecated. %s" % (name, msg))
#         return handler
# 
#     def _get_name(self, handler_longname):
#         if not self.assign:
#             return handler_longname
#         return '%s = %s' % (', '.join(a.rstrip('= ') for a in self.assign),
#                             handler_longname)
# 
#     def _run(self, handler, context):
#         try:
#             return handler.run(context, self.args[:])
#         except ExecutionFailed:
#             raise
#         except:
#             self._report_failure(context)
# 
#     def _end(self, context, return_value=None, error=None):
#         self.endtime = get_timestamp()
#         self.elapsedtime = get_elapsed_time(self.starttime, self.endtime)
#         if error and self.type == 'teardown':
#             self.message = unicode(error)
#         try:
#             if not error or error.can_continue(context.teardown):
#                 self._set_variables(context, return_value, error)
#         finally:
#             context.end_keyword(self)
# 
#     def _set_variables(self, context, return_value, error):
#         if error:
#             return_value = error.return_value
#         try:
#             VariableAssigner(self.assign).assign(context, return_value)
#         except DataError, err:
#             self.status = 'FAIL'
#             msg = unicode(err)
#             context.output.fail(msg)
#             raise ExecutionFailed(msg, syntax=True)
# 
#     def _report_failure(self, context):
#         failure = HandlerExecutionFailed()
#         if not failure.exit_for_loop:
#             context.output.fail(failure.full_message)
#             if failure.traceback:
#                 context.output.debug(failure.traceback)
#         raise failure
# 
# Path: lib/robot/running/runkwregister.py
# RUN_KW_REGISTER = _RunKeywordRegister()


from robot import utils
from robot.errors import DataError
from robot.variables import is_list_var
from .arguments import (PythonKeywordArguments, JavaKeywordArguments,
                        DynamicKeywordArguments, RunKeywordArguments,
                        PythonInitArguments, JavaInitArguments)
from .keywords import Keywords, Keyword
from .outputcapture import OutputCapturer
from .runkwregister import RUN_KW_REGISTER
from .signalhandler import STOP_SIGNAL_MONITOR
    from org.python.core import PyReflectedFunction, PyReflectedConstructor
#  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.

from __future__ import with_statement




if utils.is_jython:

    def _is_java_init(init):
        return isinstance(init, PyReflectedConstructor)
    def _is_java_method(method):
        return hasattr(method, 'im_func') \
               and isinstance(method.im_func, PyReflectedFunction)
else:
    _is_java_init = _is_java_method = lambda item: False


def Handler(library, name, method):
    if RUN_KW_REGISTER.is_run_keyword(library.orig_name, name):
        return _RunKeywordHandler(library, name, method)
    if _is_java_method(method):
        return _JavaHandler(library, name, method)
    else:
        return _PythonHandler(library, name, method)


def DynamicHandler(library, name, method, doc, argspec):

# Path: lib/robot/running/keywords.py
# class Keywords(object):
# 
#     def __init__(self, steps, template=None):
#         self._keywords = []
#         self._templated = bool(template)
#         if self._templated:
#             steps = [s.apply_template(template) for s in steps]
#         for s in steps:
#             self._add_step(s, template)
# 
#     def _add_step(self, step, template):
#         if step.is_comment():
#             return
#         if step.is_for_loop():
#             keyword = ForLoop(step, template)
#         else:
#             keyword = Keyword(step.keyword, step.args, step.assign)
#         self.add_keyword(keyword)
# 
#     def add_keyword(self, keyword):
#         self._keywords.append(keyword)
# 
#     def run(self, context):
#         errors = []
#         for kw in self._keywords:
#             try:
#                 kw.run(context)
#             except ExecutionFailed, err:
#                 errors.extend(err.get_errors())
#                 if not err.can_continue(context.teardown, self._templated,
#                                         context.dry_run):
#                     break
#         if errors:
#             raise ExecutionFailures(errors)
# 
#     def __nonzero__(self):
#         return bool(self._keywords)
# 
#     def __iter__(self):
#         return iter(self._keywords)
# 
# class Keyword(BaseKeyword):
# 
#     def __init__(self, name, args, assign=None, type='kw'):
#         BaseKeyword.__init__(self, name, args, type=type)
#         self.assign = assign or []
#         self.handler_name = name
# 
#     def run(self, context):
#         handler = self._start(context)
#         try:
#             return_value = self._run(handler, context)
#         except ExecutionFailed, err:
#             self.status = 'FAIL' if not err.exit_for_loop else 'PASS'
#             self._end(context, error=err)
#             raise
#         else:
#             if not (context.dry_run and handler.type == 'library'):
#                 self.status = 'PASS'
#             self._end(context, return_value)
#             return return_value
# 
#     def _start(self, context):
#         handler = context.get_handler(self.handler_name)
#         handler.init_keyword(context.get_current_vars())
#         self.name = self._get_name(handler.longname)
#         self.doc = handler.shortdoc
#         self.timeout = getattr(handler, 'timeout', '')
#         self.starttime = get_timestamp()
#         context.start_keyword(self)
#         if self.doc.startswith('*DEPRECATED*'):
#             msg = self.doc.replace('*DEPRECATED*', '', 1).strip()
#             name = self.name.split('} = ', 1)[-1]  # Remove possible variable
#             context.warn("Keyword '%s' is deprecated. %s" % (name, msg))
#         return handler
# 
#     def _get_name(self, handler_longname):
#         if not self.assign:
#             return handler_longname
#         return '%s = %s' % (', '.join(a.rstrip('= ') for a in self.assign),
#                             handler_longname)
# 
#     def _run(self, handler, context):
#         try:
#             return handler.run(context, self.args[:])
#         except ExecutionFailed:
#             raise
#         except:
#             self._report_failure(context)
# 
#     def _end(self, context, return_value=None, error=None):
#         self.endtime = get_timestamp()
#         self.elapsedtime = get_elapsed_time(self.starttime, self.endtime)
#         if error and self.type == 'teardown':
#             self.message = unicode(error)
#         try:
#             if not error or error.can_continue(context.teardown):
#                 self._set_variables(context, return_value, error)
#         finally:
#             context.end_keyword(self)
# 
#     def _set_variables(self, context, return_value, error):
#         if error:
#             return_value = error.return_value
#         try:
#             VariableAssigner(self.assign).assign(context, return_value)
#         except DataError, err:
#             self.status = 'FAIL'
#             msg = unicode(err)
#             context.output.fail(msg)
#             raise ExecutionFailed(msg, syntax=True)
# 
#     def _report_failure(self, context):
#         failure = HandlerExecutionFailed()
#         if not failure.exit_for_loop:
#             context.output.fail(failure.full_message)
#             if failure.traceback:
#                 context.output.debug(failure.traceback)
#         raise failure
# 
# Path: lib/robot/running/runkwregister.py
# RUN_KW_REGISTER = _RunKeywordRegister()


# Path: lib/robot/running/handlers.py
from robot import utils
from robot.errors import DataError
from robot.variables import is_list_var
from .arguments import (PythonKeywordArguments, JavaKeywordArguments,
                        DynamicKeywordArguments, RunKeywordArguments,
                        PythonInitArguments, JavaInitArguments)
from .keywords import Keywords, Keyword
from .outputcapture import OutputCapturer
from .runkwregister import RUN_KW_REGISTER
from .signalhandler import STOP_SIGNAL_MONITOR
    from org.python.core import PyReflectedFunction, PyReflectedConstructor

#  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.

from __future__ import with_statement




if utils.is_jython:

    def _is_java_init(init):
        return isinstance(init, PyReflectedConstructor)
    def _is_java_method(method):
        return hasattr(method, 'im_func') \
               and isinstance(method.im_func, PyReflectedFunction)
else:
    _is_java_init = _is_java_method = lambda item: False


def Handler(library, name, method):
    if RUN_KW_REGISTER.is_run_keyword(library.orig_name, name):
        return _RunKeywordHandler(library, name, method)
    if _is_java_method(method):
        return _JavaHandler(library, name, method)
    else:
        return _PythonHandler(library, name, method)


def DynamicHandler(library, name, method, doc, argspec):

    if RUN_KW_REGISTER.is_run_keyword(library.orig_name, name):