# Path: robottools/library/inspector/keyword.py
# class KeywordInspector(object):
# 
#     def __init__(self, handler):
#         self._handler = handler
# 
#     @property
#     def __doc__(self):
#         return "%s\n\n%s" % (repr(self), self._handler.doc)
# 
#     @property
#     def arguments(self):
#         return KeywordArgumentsInspector(self._handler.arguments)
# 
#     def __eq__(self, other):
#         return isinstance(other, KeywordInspector) and \
#             self._handler == other._handler
# 
#     def __getattr__(self, name):
#         return getattr(self._handler, name)
# 
#     def __dir__(self):
#         return ['name', 'doc', 'shortdoc']
# 
#     def __str__(self):
#         return self._handler.longname
# 
#     def __repr__(self):
#         return '[Keyword] %s [ %s ]' % (self, self.arguments)
# 
# Path: robottools/testrobot/handler.py
# class Handler(with_metaclass(HandlerMeta, object)):
#     """A wrapper base class for instances of classes
#     from ``robot.running.handlers``.
# 
#     * Implements a custom :meth:`.resolve_arguments`,
#       which supports passing arbitrary python objects
#       as keyword argument values.
#     """
#     # HACK
#     def resolve_arguments(self, args_and_kwargs, variables=None):
#         """More Pythonic argument handling for interactive
#         :class:`robottools.testrobot.keyword.Keyword` calls.
# 
#         Original ``resolve_arguments`` methods from ``robot.running.handlers``
#         expect as first argument a single list of Keyword arguments
#         coming from an RFW script::
# 
#            ['arg0', 'arg1', ..., 'name=value', ...]
# 
#         So there is no chance to pass unstringified named argument values.
#         Only unstringified positional arguments are possible.
# 
#         This wrapper method takes a normal Python `args_and_kwargs` pair
#         instead as first argument::
# 
#            (arg0, arg1, ...), {name: value, ...}
# 
#         It resolves the named arguments stringified via the original method
#         but returns the original Python values::
# 
#            [arg0, arg1, ...], [(name, value), ...]
# 
#         Only strings are untouched.
#         So RFW ``'...${variable}...'`` substitution still works.
#         """
#         posargs, kwargs = args_and_kwargs
#         rfwargs = list(posargs)
#         # prepare 'key=value' strings for original RFW method
#         for name, value in dictitems(kwargs):
#             if not isstring(value):
#                 value = repr(value)
#             rfwargs.append(u'%s=%s' % (name, value))
#         posargs, rfwkwargs = self._resolve_arguments(rfwargs, variables)
#         # and replace values with original non-string objects after resolving
#         kwargslist = []
#         if isdict(rfwkwargs):
#             # ==> RFW < 3.0
#             rfwkwargs = dictitems(rfwkwargs)
#         for name, rfwvalue in rfwkwargs:
#             value = kwargs[name]
#             if isstring(value):
#                 value = rfwvalue
#             kwargslist.append((name, value))
#         if hasattr(self, 'run'):
#             # ==> RFW < 3.0
#             return posargs, dict(kwargslist)
#         # RFW >= 3.0
#         return posargs, kwargslist


import sys
import robot.running
from six import reraise, text_type as unicode
from robot.errors import HandlerExecutionFailed, ExecutionFailed
    from robot.running.steprunner import StepRunner
    from robot.running.statusreporter import StatusReporter
    from robot.running.keywordrunner import NormalRunner
from robottools.library.inspector.keyword import KeywordInspector
from .handler import Handler
    # Robot 2.8
    def _report_failure(self, context):
        debug_fail(context)

    # Robot >= 2.9
    def __enter__(self):
        if NormalRunner:
            # Robot 2.9
            # HACK: monkey-patch robot.running's NormalRunner
            # to catch the Keyword exception
            robot.running.keywordrunner.NormalRunner = DebugNormalRunner
        if StatusReporter:
            # Robot 3.0
            # HACK: monkey-patch robot.running's StatusReporter._get_failure()
            # to catch the Keyword exception
            robot.running.statusreporter.StatusReporter._get_failure \
                = debug_get_failure

    def __exit__(self, *exc):
        if NormalRunner:
            robot.running.keywordrunner.NormalRunner = NormalRunner
        if StatusReporter:
            robot.running.statusreporter.StatusReporter._get_failure \
                = _get_failure


class Keyword(KeywordInspector):
    def __init__(self, handler, context, debug=False):
        KeywordInspector.__init__(self, handler)
        if not isinstance(handler, Handler):

# Path: robottools/library/inspector/keyword.py
# class KeywordInspector(object):
# 
#     def __init__(self, handler):
#         self._handler = handler
# 
#     @property
#     def __doc__(self):
#         return "%s\n\n%s" % (repr(self), self._handler.doc)
# 
#     @property
#     def arguments(self):
#         return KeywordArgumentsInspector(self._handler.arguments)
# 
#     def __eq__(self, other):
#         return isinstance(other, KeywordInspector) and \
#             self._handler == other._handler
# 
#     def __getattr__(self, name):
#         return getattr(self._handler, name)
# 
#     def __dir__(self):
#         return ['name', 'doc', 'shortdoc']
# 
#     def __str__(self):
#         return self._handler.longname
# 
#     def __repr__(self):
#         return '[Keyword] %s [ %s ]' % (self, self.arguments)
# 
# Path: robottools/testrobot/handler.py
# class Handler(with_metaclass(HandlerMeta, object)):
#     """A wrapper base class for instances of classes
#     from ``robot.running.handlers``.
# 
#     * Implements a custom :meth:`.resolve_arguments`,
#       which supports passing arbitrary python objects
#       as keyword argument values.
#     """
#     # HACK
#     def resolve_arguments(self, args_and_kwargs, variables=None):
#         """More Pythonic argument handling for interactive
#         :class:`robottools.testrobot.keyword.Keyword` calls.
# 
#         Original ``resolve_arguments`` methods from ``robot.running.handlers``
#         expect as first argument a single list of Keyword arguments
#         coming from an RFW script::
# 
#            ['arg0', 'arg1', ..., 'name=value', ...]
# 
#         So there is no chance to pass unstringified named argument values.
#         Only unstringified positional arguments are possible.
# 
#         This wrapper method takes a normal Python `args_and_kwargs` pair
#         instead as first argument::
# 
#            (arg0, arg1, ...), {name: value, ...}
# 
#         It resolves the named arguments stringified via the original method
#         but returns the original Python values::
# 
#            [arg0, arg1, ...], [(name, value), ...]
# 
#         Only strings are untouched.
#         So RFW ``'...${variable}...'`` substitution still works.
#         """
#         posargs, kwargs = args_and_kwargs
#         rfwargs = list(posargs)
#         # prepare 'key=value' strings for original RFW method
#         for name, value in dictitems(kwargs):
#             if not isstring(value):
#                 value = repr(value)
#             rfwargs.append(u'%s=%s' % (name, value))
#         posargs, rfwkwargs = self._resolve_arguments(rfwargs, variables)
#         # and replace values with original non-string objects after resolving
#         kwargslist = []
#         if isdict(rfwkwargs):
#             # ==> RFW < 3.0
#             rfwkwargs = dictitems(rfwkwargs)
#         for name, rfwvalue in rfwkwargs:
#             value = kwargs[name]
#             if isstring(value):
#                 value = rfwvalue
#             kwargslist.append((name, value))
#         if hasattr(self, 'run'):
#             # ==> RFW < 3.0
#             return posargs, dict(kwargslist)
#         # RFW >= 3.0
#         return posargs, kwargslist


# Path: robottools/testrobot/keyword.py
import sys
import robot.running
from six import reraise, text_type as unicode
from robot.errors import HandlerExecutionFailed, ExecutionFailed
    from robot.running.steprunner import StepRunner
    from robot.running.statusreporter import StatusReporter
    from robot.running.keywordrunner import NormalRunner
from robottools.library.inspector.keyword import KeywordInspector
from .handler import Handler

    # Robot 2.8
    def _report_failure(self, context):
        debug_fail(context)

    # Robot >= 2.9
    def __enter__(self):
        if NormalRunner:
            # Robot 2.9
            # HACK: monkey-patch robot.running's NormalRunner
            # to catch the Keyword exception
            robot.running.keywordrunner.NormalRunner = DebugNormalRunner
        if StatusReporter:
            # Robot 3.0
            # HACK: monkey-patch robot.running's StatusReporter._get_failure()
            # to catch the Keyword exception
            robot.running.statusreporter.StatusReporter._get_failure \
                = debug_get_failure

    def __exit__(self, *exc):
        if NormalRunner:
            robot.running.keywordrunner.NormalRunner = NormalRunner
        if StatusReporter:
            robot.running.statusreporter.StatusReporter._get_failure \
                = _get_failure


class Keyword(KeywordInspector):
    def __init__(self, handler, context, debug=False):
        KeywordInspector.__init__(self, handler)
        if not isinstance(handler, Handler):

            handler.__class__ = Handler[handler.__class__]