from bfs.bfs10060.bfs10200 import bfs10177
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 bfs10277(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, bfs10235):
    return (self.target == bfs10235.target)

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


class bfs10276(bfs10277):
  def __init__(self, target):
    super(bfs10276, self).__init__(target)
    self.bfs10300 = None

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

  def bfs10302(self, web_element):
    if (not self.bfs10300):
      return 0

    if hasattr(self.bfs10300, 'location'):
      try:
        bfs10303 = self.bfs10300.location
      except StaleElementReferenceException:
        return 0
      else:
        return bfs10303.bfs10255(web_element.location)

    else:
      return 0


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

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

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


@decorator
def bfs10311(bfs10030, *args, **bfs10066):
  try:
    return bfs10030(*args, **bfs10066)
  except URLError, bfs10305:
    if bfs10307(bfs10305):
      raise StaleElementReferenceException('The Selenium server this element belonged to is no longer available.')
    else:
      raise 



def bfs10307(bfs10305):
  try:
    bfs10310 = 10061
    return (bfs10305.args[0][0] == bfs10310)
  except (IndexError, TypeError):
    return False


class bfs10312(bfs10277):
  def __init__(self, target):
    super(bfs10312, self).__init__(target)
    self.bfs10314 = None

  @property
  @bfs10311
  def location(self):
    if (self.bfs10314 is None):
      location = self.target.location
      (x, y) = (location['x'], location['y'])
      size = self.target.size
      (width, height) = (size['width'], size['height'])
      self.bfs10314 = bfs10177(x, y, width, height)

    return self.bfs10314

  def is_displayed(self):
    try:
      return (self.target.is_displayed() and self.location.bfs10234(bfs10177(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 bfs10313(object):
  def __init__(self, driver, bfs10315=None):
    if (bfs10315 is None):
      bfs10315 = []

    self.driver = driver
    self.bfs10315 = bfs10315

  def __iter__(self):
    yield []
    bfs10317 = 0
    while True:
      try:
        self.driver.switch_to.frame(bfs10317)
      except (StaleElementReferenceException, NoSuchFrameException):
        break
      else:
        bfs10316 = (self.bfs10315 + [bfs10317])
        for bfs10063 in bfs10313(self.driver, bfs10316):
          yield ([bfs10317] + bfs10063)

        self.switch_to_frame(self.bfs10315)
        bfs10317 += 1



  def switch_to_frame(self, bfs10320):
    self.driver.switch_to.default_content()
    for bfs10321 in bfs10320:
      self.driver.switch_to.frame(bfs10321)



