from bfs.bfs10063.bfs10255 import bfs10256
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 bfs10415(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, bfs10414):
    return (self.target == bfs10414.target)

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


class bfs10420(bfs10415):
  def __init__(self, target):
    super(bfs10420, self).__init__(target)
    self.bfs10417 = None

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

  def bfs10422(self, web_element):
    if (not self.bfs10417):
      return 0

    if hasattr(self.bfs10417, 'location'):
      try:
        bfs10423 = self.bfs10417.location
      except StaleElementReferenceException:
        return 0
      else:
        return bfs10423.bfs10351(web_element.location)

    else:
      return 0


  def find_elements_by_name(self, name):
    return (self.target.find_elements_by_name(name) or [])

  def find_elements_by_xpath(self, bfs10424):
    return (self.target.find_elements_by_xpath(bfs10424) or [])

  def find_elements_by_css_selector(self, bfs10425):
    return (self.target.find_elements_by_css_selector(bfs10425) or [])

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

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

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


@decorator
def bfs10433(bfs10104, *args, **bfs10430):
  try:
    return bfs10104(*args, **bfs10430)
  except URLError, bfs10432:
    if bfs10431(bfs10432):
      raise StaleElementReferenceException('The Selenium server this element belonged to is no longer available.')
    else:
      raise 



def bfs10431(bfs10435):
  try:
    bfs10434 = 10061
    return (bfs10435.args[0][0] == bfs10434)
  except (IndexError, TypeError):
    return False


class bfs10436(bfs10415):
  def __init__(self, target):
    super(bfs10436, self).__init__(target)
    self.bfs10440 = None

  @property
  @bfs10433
  def location(self):
    if (self.bfs10440 is None):
      location = self.target.location
      (x, y) = (location['x'], location['y'])
      size = self.target.size
      (width, height) = (size['width'], size['height'])
      self.bfs10440 = bfs10256(x, y, width, height)

    return self.bfs10440

  def is_displayed(self):
    try:
      return (self.target.is_displayed() and self.location.bfs10323(bfs10256(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 bfs10437(object):
  def __init__(self, driver, bfs10441=None):
    if (bfs10441 is None):
      bfs10441 = []

    self.driver = driver
    self.bfs10441 = bfs10441

  def __iter__(self):
    yield []
    for bfs10442 in xrange(sys.maxint):
      try:
        self.driver.switch_to.frame(bfs10442)
      except (StaleElementReferenceException, NoSuchFrameException):
        break
      else:
        bfs10443 = (self.bfs10441 + [bfs10442])
        for bfs10444 in bfs10437(self.driver, bfs10443):
          yield ([bfs10442] + bfs10444)

        try:
          self.switch_to_frame(self.bfs10441)
        except NoSuchFrameException:
          raise bfs10445()




  def switch_to_frame(self, bfs10447):
    self.driver.switch_to.default_content()
    for bfs10446 in bfs10447:
      self.driver.switch_to.frame(bfs10446)



class bfs10445(Exception):
  pass

