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


import os
import re
from robot.common import BaseLibrary, UserErrorHandler
from robot.errors import DataError, ExecutionFailed, UserKeywordExecutionFailed
from robot.variables import is_list_var, VariableSplitter
from robot.output import LOGGER
from robot import utils
from .keywords import Keywords
from .fixture import Teardown
from .timeouts import KeywordTimeout
from .arguments import UserKeywordArguments
#  See the License for the specific language governing permissions and
#  limitations under the License.





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


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


# Path: lib/robot/running/userkeyword.py
import os
import re
from robot.common import BaseLibrary, UserErrorHandler
from robot.errors import DataError, ExecutionFailed, UserKeywordExecutionFailed
from robot.variables import is_list_var, VariableSplitter
from robot.output import LOGGER
from robot import utils
from .keywords import Keywords
from .fixture import Teardown
from .timeouts import KeywordTimeout
from .arguments import UserKeywordArguments

#  See the License for the specific language governing permissions and
#  limitations under the License.





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):