from bfs.bfs10077.bfs10230 import bfs10227
from decorator import decorator
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.action_chains import ActionChains
from urllib2 import URLError
import sys
class bfs10367(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, bfs10366):
    return (self.target == bfs10366.target)

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


class bfs10371(bfs10367):
  def __init__(self, target):
    super(bfs10371, self).__init__(target)
    self.bfs10372 = None

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

  def bfs10376(self, web_element):
    if (not self.bfs10372):
      return 0

    if hasattr(self.bfs10372, 'location'):
      try:
        bfs10374 = self.bfs10372.location
      except StaleElementReferenceException:
        return 0
      else:
        return bfs10374.bfs10323(web_element.location)

    else:
      return 0


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

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

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


@decorator
def bfs10403(bfs10400, *args, **bfs10401):
  try:
    return bfs10400(*args, **bfs10401)
  except URLError, bfs10402:
    if bfs10404(bfs10402):
      raise StaleElementReferenceException('The Selenium server this element belonged to is no longer available.')
    else:
      raise 



def bfs10404(bfs10405):
  try:
    bfs10406 = 10061
    return (bfs10405.args[0][0] == bfs10406)
  except (IndexError, TypeError):
    return False


class bfs10407(bfs10367):
  def __init__(self, target):
    super(bfs10407, self).__init__(target)
    self.bfs10411 = None

  @property
  @bfs10403
  def location(self):
    if (self.bfs10411 is None):
      location = self.target.location
      (x, y) = (location['x'], location['y'])
      size = self.target.size
      (width, height) = (size['width'], size['height'])
      self.bfs10411 = bfs10227(x, y, width, height)

    return self.bfs10411

  def is_displayed(self):
    try:
      return (self.target.is_displayed() and self.location.bfs10274(bfs10227(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))


