from bfs.bfs10076.bfs10233 import bfs10235
from decorator import decorator
from selenium.common.exceptions import StaleElementReferenceException, NoSuchFrameException
from selenium.webdriver.common.action_chains import ActionChains
from urllib2 import URLError
import sys
class bfs10373(object):
  def __init__(self, target):
    self.target = target

  def __getattr__(self, item):
    return getattr(self.target, item)

  def unwrap(self):
    return self.target

  def __hash__(self):
    return hash(self.target)

  def __eq__(self, bfs10374):
    return (self.target == bfs10374.target)

  def __ne__(self, bfs10376):
    return (not (self == bfs10376))


class bfs10375(bfs10373):
  def __init__(self, target):
    super(bfs10375, self).__init__(target)
    self.bfs10377 = None

  def bfs10400(self):
    return ActionChains(self.target)

  def bfs10402(self, web_element):
    if (not self.bfs10377):
      return 0

    if hasattr(self.bfs10377, 'location'):
      try:
        bfs10401 = self.bfs10377.location
      except StaleElementReferenceException:
        return 0
      else:
        return bfs10401.bfs10326(web_element.location)

    else:
      return 0


  def bfs10404(self):
    return (self.browser_name == 'firefox')

  @property
  def browser_name(self):
    return self.target.capabilities['browserName']

  def bfs10403(self):
    return (self.browser_name == 'internet explorer')


@decorator
def bfs10410(bfs10405, *args, **bfs10406):
  try:
    return bfs10405(*args, **bfs10406)
  except URLError, bfs10407:
    if bfs10411(bfs10407):
      raise StaleElementReferenceException('The Selenium server this element belonged to is no longer available.')
    else:
      raise 



def bfs10411(bfs10412):
  try:
    bfs10413 = 10061
    return (bfs10412.args[0][0] == bfs10413)
  except (IndexError, TypeError):
    return False


class bfs10415(bfs10373):
  def __init__(self, target):
    super(bfs10415, self).__init__(target)
    self.bfs10414 = None

  @property
  @bfs10410
  def location(self):
    if (self.bfs10414 is None):
      location = self.target.location
      (x, y) = (location['x'], location['y'])
      size = self.target.size
      (width, height) = (size['width'], size['height'])
      self.bfs10414 = bfs10235(x, y, width, height)

    return self.bfs10414

  def is_displayed(self):
    try:
      return (self.target.is_displayed() and self.location.bfs10301(bfs10235(0, 0, sys.maxint, sys.maxint)))
    except StaleElementReferenceException:
      return False


  def __repr__(self):
    return ('<%s>%s</%s>' % (self.tag_name, self.target.text, self.tag_name))


class bfs10416(object):
  def __init__(self, driver, bfs10420=None):
    if (bfs10420 is None):
      bfs10420 = []

    self.driver = driver
    self.bfs10420 = bfs10420

  def __iter__(self):
    yield []
    bfs10417 = 0
    while True:
      try:
        self.driver.switch_to.frame(bfs10417)
      except (StaleElementReferenceException, NoSuchFrameException):
        break
      else:
        bfs10421 = (self.bfs10420 + [bfs10417])
        for bfs10423 in bfs10416(self.driver, bfs10421):
          yield ([bfs10417] + bfs10423)

        self.switch_to_frame(self.bfs10420)
        bfs10417 += 1



  def switch_to_frame(self, bfs10422):
    self.driver.switch_to.default_content()
    for bfs10424 in bfs10422:
      self.driver.switch_to.frame(bfs10424)



