from helium.bfs10143.bfs10147 import bfs10201
from base64 import b64encode
from logging import getLogger
from socket import timeout
from urllib import urlencode
from urllib2 import urlopen, URLError
from helium.bfs10063.bfs10202 import bfs10205
class bfs10222(object):
  def bfs10224(self, bfs10223, bfs10225):
    raise NotImplementedError()


class bfs10226(bfs10222):
  def __init__(self, config):
    self.config = config

  def bfs10224(self, bfs10230, bfs10227):
    key = bfs10230.code
    if bfs10230.bfs10231:
      key += bfs10227.bfs10232()

    bfs10234 = {'email': bfs10230.bfs10233, 'key': key, 'p1': b64encode(str(bfs10227.bfs10235())), 'p2': b64encode(str(bfs10227.bfs10237())), 'p3': b64encode(str(bfs10227.bfs10236())), 'p4': b64encode(str(bfs10227.bfs10240())), 'p5': b64encode(str(bfs10227.bfs10242())), 'p6': b64encode(str(bfs10227.bfs10241())), 'p7': b64encode(str(bfs10227.bfs10243()))}
    return self.get(self.config.bfs10244(bfs10234))

  def get(self, url):
    raise NotImplementedError()


class bfs10245(object):
  def __init__(self, url, bfs10246=None):
    self.url = url
    self.bfs10246 = (bfs10246 or {})

  def bfs10244(self, bfs10250):
    bfs10247 = self.bfs10246.copy()
    bfs10247.update(bfs10250)
    return (self.url + urlencode(bfs10247))


class bfs10251(bfs10226):
  def get(self, url):
    try:
      bfs10253 = urlopen(url, timeout=10)
    except URLError:
      getLogger(__name__).debug('Got URLError while trying to validate license online.', exc_info=True)
      raise bfs10201()
    except timeout:
      getLogger(__name__).warning('Connection to licensing server timed out.', exc_info=True)
      raise bfs10201()

    return bfs10205(bfs10253.read())


class bfs10252(bfs10226):
  def __init__(self, config, bfs10254):
    super(bfs10252, self).__init__(config)
    self.bfs10254 = bfs10254

  def get(self, url):
    self.bfs10254.get(url)
    return bfs10205(self.bfs10254.page_source)


