from helium.bfs10101.bfs10102 import bfs10136
from base64 import b64encode
from logging import getLogger
from socket import timeout
from urllib.parse import urlencode
from urllib.request import urlopen
from urllib.error import URLError
from helium.bfs10060.bfs10137 import bfs10140
class bfs10143(object):
  def bfs10146(self, bfs10145, bfs10147):
    raise NotImplementedError()


class bfs10150(bfs10143):
  def __init__(self, config):
    self.config = config

  def bfs10146(self, bfs10145, bfs10147):
    key = bfs10145.code
    if bfs10145.bfs10152:
      key += bfs10147.bfs10151()

    bfs10153 = {'email': bfs10145.bfs10154, 'key': key, 'p1': b64encode(str(bfs10147.bfs10155())), 'p2': b64encode(str(bfs10147.bfs10157())), 'p3': b64encode(str(bfs10147.bfs10156())), 'p4': b64encode(str(bfs10147.bfs10160())), 'p5': b64encode(str(bfs10147.bfs10161())), 'p6': b64encode(str(bfs10147.bfs10163())), 'p7': b64encode(str(bfs10147.bfs10162()))}
    return self.get(self.config.bfs10164(bfs10153))

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


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

  def bfs10164(self, bfs10153):
    bfs10170 = self.bfs10166.copy()
    bfs10170.update(bfs10153)
    return (self.url + urlencode(bfs10170))


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

    return bfs10140(bfs10171.read())


class bfs10172(bfs10150):
  def __init__(self, config, bfs10174):
    super(bfs10172, self).__init__(config)
    self.bfs10174 = bfs10174

  def get(self, url):
    self.bfs10174.get(url)
    return bfs10140(self.bfs10174.page_source)


