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


import rel_imp; rel_imp.init()
import sys
import time
import os
import parsel
from functools import wraps
from contextlib import contextmanager
from urllib.parse import urlparse, urlunparse, urljoin, parse_qsl, unquote_plus
from selenium import webdriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.common.exceptions import WebDriverException,\
    TimeoutException
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
from .logger import Logger
from .validators import is_valid_netloc
    @wraps(method)
    def wrapper(self, xpath, *a, **kw):
        max_wait = wrapper._implicit_max_wait or self._implicit_max_wait
        condition = wrapper._implicit_wait_condition or self._implicit_wait_condition
        if max_wait:
            self.wait_condition(condition(xpath), max_wait)
        return method(self, xpath, *a, **kw)
    wrapper._implicit_max_wait = None
    wrapper._implicit_wait_condition = None
    return wrapper


class XpathBrowser:
    '''
    Class for making Webdriver more xpath-friendly.
    This class is designed to be framework independent, to be reused by other
    testing frameworks.
    '''
    Url = Url

    def __init__(self, webdriver, base_url=None, logger=None, settings=None):
        '''
        :param base_url: common base url (e.g: http://example.com, http://example.com/some/common/path) 
            Used to build URL for all methods accepting the "path" argument. 
        :param webdriver: selenium's webdriver object (connected to Firefox, Chrome, etc...)
        :param logger: You can optionally pass a xpathwebdriver.Logger instance (or a child class's instance)  
        :param settings: xpathwebdriver settings object.
        '''
        settings = settings or {}
        self.settings = settings

# 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/xpath_browser.py
import rel_imp; rel_imp.init()
import sys
import time
import os
import parsel
from functools import wraps
from contextlib import contextmanager
from urllib.parse import urlparse, urlunparse, urljoin, parse_qsl, unquote_plus
from selenium import webdriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.common.exceptions import WebDriverException,\
    TimeoutException
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
from .logger import Logger
from .validators import is_valid_netloc

    @wraps(method)
    def wrapper(self, xpath, *a, **kw):
        max_wait = wrapper._implicit_max_wait or self._implicit_max_wait
        condition = wrapper._implicit_wait_condition or self._implicit_wait_condition
        if max_wait:
            self.wait_condition(condition(xpath), max_wait)
        return method(self, xpath, *a, **kw)
    wrapper._implicit_max_wait = None
    wrapper._implicit_wait_condition = None
    return wrapper


class XpathBrowser:
    '''
    Class for making Webdriver more xpath-friendly.
    This class is designed to be framework independent, to be reused by other
    testing frameworks.
    '''
    Url = Url

    def __init__(self, webdriver, base_url=None, logger=None, settings=None):
        '''
        :param base_url: common base url (e.g: http://example.com, http://example.com/some/common/path) 
            Used to build URL for all methods accepting the "path" argument. 
        :param webdriver: selenium's webdriver object (connected to Firefox, Chrome, etc...)
        :param logger: You can optionally pass a xpathwebdriver.Logger instance (or a child class's instance)  
        :param settings: xpathwebdriver settings object.
        '''
        settings = settings or {}
        self.settings = settings

        self.log = logger or settings.get('logger', Logger(self.__class__.__name__))