# Path: xpathwebdriver/logger.py
# class Logger(object):
#     default_level = logging.INFO
#     handler_level = logging.DEBUG
#     default_fmt = '%(levelname)s %(asctime)s: %(message)s'
#     default_datefmt = '%H:%M:%S'
# 
#     def __init__(self, name=None, output=None, level=None, color=False):
#         if not level:
#             level = self.default_level
#         if not output:
#             if not name:
#                 output = logging.getLogger()
#             else:
#                 output = logging.getLogger(name)
#         self.output = output
#         self.color = color
#         if not logging.root.handlers:
#             self._config_handler()
#             self.set_fmt()
#             self.setLevel(level)
# 
#     def _config_handler(self):
#         if not self.output.handlers:
#             if self.color:
#                 hdlr = ColorStreamHandler()
#             else:
#                 hdlr = logging.StreamHandler()
#             hdlr.setLevel(self.handler_level)
#             self.output.addHandler(hdlr)
# 
#     def set_fmt(self, fmt=None, datefmt=None):
#         datefmt = datefmt or self.default_datefmt
#         fmt = fmt or self.default_fmt
#         hdlr = self.output.handlers[0]
#         fmt = logging.Formatter(fmt=fmt,
#                                 datefmt=datefmt
#                                 )
#         hdlr.setFormatter(fmt)
# 
#     def set_pre_post(self, pre='', post=''):
#         if pre:
#             pre = '[%s] ' % pre.strip()
#         self.set_fmt(fmt=pre + self.default_fmt + post)
# 
#     def _log(self, method, msg, args):
#         getattr(self.output, method)(msg, *args)
# 
#     def critical(self, msg, *args):
#         self._log('critical', msg, args)
# 
#     def error(self, msg, *args):
#         self._log('error', msg, args)
# 
#     def warning(self, msg, *args):
#         self._log('warning', msg, args)
# 
#     def info(self, msg, *args):
#         self._log('info', msg, args)
# 
#     def debug(self, msg, *args):
#         self._log('debug', msg, args)
# 
#     def exception(self, msg, *args):
#         self._log('exception', msg, args)
# 
#     def c(self, msg, *args):
#         self.critical(msg, *args)
# 
#     def e(self, msg, *args):
#         self.error(msg, *args)
# 
#     def exc(self, msg, *args):
#         self.exception(msg, *args)
# 
#     def w(self, msg, *args):
#         self.warning(msg, *args)
# 
#     def i(self, msg, *args):
#         self.info(msg, *args)
# 
#     def d(self, msg, *args):
#         self.debug(msg, *args)
# 
#     def verbose(self, msg):
#         self.output.debug(str(msg))
# 
#     def v(self, msg, *args):
#         self.debug(msg, *args)
# 
#     def printFilePath(self, file_path, line=None, error=False):
#         if error:
#             out = self.e
#         else:
#             out = self.d
#         if not line:
#             line = 1
#         msg = '  File "%s", line %d\n' % (file_path, line)
#         out(msg)
# 
#     def setLevel(self, level):
#         if hasattr(self.output, 'setLevel'):
#             self.output.setLevel(level)
#         else:
#             self.w('Cannot set logging level')
# 
#     def __call__(self, msg):
#         self.info(msg)
# 
# Path: xpathwebdriver/solve_settings.py
# def solve_settings(module_name=None, file_path=None):
#     global global_settings
#     if not global_settings:
#         file_path = file_path or os.environ.get('XPATHWD_SETTINGS_FILE')
#         if file_path:
#             if not os.path.exists(file_path):
#                 raise LookupError(f'No such settings file {file_path}')
#             spec = importlib.util.spec_from_file_location('xpathwebdriver_custom_settings_file', file_path)
#             mod = importlib.util.module_from_spec(spec)
#         else:
#             module_name = module_name or os.environ.get('XPATHWD_SETTINGS_MODULE',
#                                                         'xpathwebdriver.default_settings')
#             mod = importlib.import_module(module_name)
#         _register_settings_module(mod)
#     return global_settings
# 
# def register_settings(settings_path):
#     '''
#     Register settings given specific module path.
#     :param settings_path:
#     '''
#     if isinstance(settings_path, str):
#         solve_settings(file_path=settings_path)
#     else:
#         register_settings_instance(settings_path)
#     set_log_level()


import rel_imp; rel_imp.init()
import logging
import re
import os
from .logger import Logger
from .solve_settings import solve_settings, register_settings
# -*- coding: utf-8 -*-
'''
xpathwebdriver

Copyright (c) 2014, Juju inc.
Copyright (c) 2011-2013, Joaquin G. Duo
'''


class singleton_decorator(object):

    '''
      Singleton pattern decorator.
      There will be only one instance of the decorated class.
    '''

    def __init__(self, class_):
        self.class_ = class_
        self.instance = None

    def __call__(self, *a, **ad):
        if self.instance is None:
            self.instance = self.class_(*a, **ad)
        return self.instance


class XpathWdBase(object):

# Path: xpathwebdriver/logger.py
# class Logger(object):
#     default_level = logging.INFO
#     handler_level = logging.DEBUG
#     default_fmt = '%(levelname)s %(asctime)s: %(message)s'
#     default_datefmt = '%H:%M:%S'
# 
#     def __init__(self, name=None, output=None, level=None, color=False):
#         if not level:
#             level = self.default_level
#         if not output:
#             if not name:
#                 output = logging.getLogger()
#             else:
#                 output = logging.getLogger(name)
#         self.output = output
#         self.color = color
#         if not logging.root.handlers:
#             self._config_handler()
#             self.set_fmt()
#             self.setLevel(level)
# 
#     def _config_handler(self):
#         if not self.output.handlers:
#             if self.color:
#                 hdlr = ColorStreamHandler()
#             else:
#                 hdlr = logging.StreamHandler()
#             hdlr.setLevel(self.handler_level)
#             self.output.addHandler(hdlr)
# 
#     def set_fmt(self, fmt=None, datefmt=None):
#         datefmt = datefmt or self.default_datefmt
#         fmt = fmt or self.default_fmt
#         hdlr = self.output.handlers[0]
#         fmt = logging.Formatter(fmt=fmt,
#                                 datefmt=datefmt
#                                 )
#         hdlr.setFormatter(fmt)
# 
#     def set_pre_post(self, pre='', post=''):
#         if pre:
#             pre = '[%s] ' % pre.strip()
#         self.set_fmt(fmt=pre + self.default_fmt + post)
# 
#     def _log(self, method, msg, args):
#         getattr(self.output, method)(msg, *args)
# 
#     def critical(self, msg, *args):
#         self._log('critical', msg, args)
# 
#     def error(self, msg, *args):
#         self._log('error', msg, args)
# 
#     def warning(self, msg, *args):
#         self._log('warning', msg, args)
# 
#     def info(self, msg, *args):
#         self._log('info', msg, args)
# 
#     def debug(self, msg, *args):
#         self._log('debug', msg, args)
# 
#     def exception(self, msg, *args):
#         self._log('exception', msg, args)
# 
#     def c(self, msg, *args):
#         self.critical(msg, *args)
# 
#     def e(self, msg, *args):
#         self.error(msg, *args)
# 
#     def exc(self, msg, *args):
#         self.exception(msg, *args)
# 
#     def w(self, msg, *args):
#         self.warning(msg, *args)
# 
#     def i(self, msg, *args):
#         self.info(msg, *args)
# 
#     def d(self, msg, *args):
#         self.debug(msg, *args)
# 
#     def verbose(self, msg):
#         self.output.debug(str(msg))
# 
#     def v(self, msg, *args):
#         self.debug(msg, *args)
# 
#     def printFilePath(self, file_path, line=None, error=False):
#         if error:
#             out = self.e
#         else:
#             out = self.d
#         if not line:
#             line = 1
#         msg = '  File "%s", line %d\n' % (file_path, line)
#         out(msg)
# 
#     def setLevel(self, level):
#         if hasattr(self.output, 'setLevel'):
#             self.output.setLevel(level)
#         else:
#             self.w('Cannot set logging level')
# 
#     def __call__(self, msg):
#         self.info(msg)
# 
# Path: xpathwebdriver/solve_settings.py
# def solve_settings(module_name=None, file_path=None):
#     global global_settings
#     if not global_settings:
#         file_path = file_path or os.environ.get('XPATHWD_SETTINGS_FILE')
#         if file_path:
#             if not os.path.exists(file_path):
#                 raise LookupError(f'No such settings file {file_path}')
#             spec = importlib.util.spec_from_file_location('xpathwebdriver_custom_settings_file', file_path)
#             mod = importlib.util.module_from_spec(spec)
#         else:
#             module_name = module_name or os.environ.get('XPATHWD_SETTINGS_MODULE',
#                                                         'xpathwebdriver.default_settings')
#             mod = importlib.import_module(module_name)
#         _register_settings_module(mod)
#     return global_settings
# 
# def register_settings(settings_path):
#     '''
#     Register settings given specific module path.
#     :param settings_path:
#     '''
#     if isinstance(settings_path, str):
#         solve_settings(file_path=settings_path)
#     else:
#         register_settings_instance(settings_path)
#     set_log_level()


# Path: xpathwebdriver/base.py
import rel_imp; rel_imp.init()
import logging
import re
import os
from .logger import Logger
from .solve_settings import solve_settings, register_settings

# -*- coding: utf-8 -*-
'''
xpathwebdriver

Copyright (c) 2014, Juju inc.
Copyright (c) 2011-2013, Joaquin G. Duo
'''


class singleton_decorator(object):

    '''
      Singleton pattern decorator.
      There will be only one instance of the decorated class.
    '''

    def __init__(self, class_):
        self.class_ = class_
        self.instance = None

    def __call__(self, *a, **ad):
        if self.instance is None:
            self.instance = self.class_(*a, **ad)
        return self.instance


class XpathWdBase(object):

    log = Logger('xpath root', color=solve_settings().get('log_color'))