from bfs.bfs10135.errors import bfs10141
from helium.bfs10135.errors import bfs10174
from random import Random
import logging
bfs10107 = logging.getLogger(__name__)
bfs10107.setLevel(logging.INFO)
class License(object):
  def bfs10463(self, bfs11214):
    bfs11215 = self.bfs11217(bfs11214)
    if (not bfs11215):
      raise bfs10141(bfs11215.message)


  def bfs11217(self, bfs11216):
    raise NotImplementedError()


class bfs11220(License):
  def bfs11217(self, bfs11222):
    return bfs11221(True, 'Development license (eternally valid).')


class bfs11223(License):
  bfs11224 = 0
  bfs11226 = 1
  bfs11225 = 'dstn;heaf402321'
  bfs11227 = 'Unfortunately, your Helium license has expired. Please obtain a new one from\n\thttp://heliumhq.com'
  bfs11231 = 'Unfortunately, your Helium license is already in use on another computer. To use it on this machine, please contact support at\n\thttp://heliumhq.com'
  bfs11230 = 'Unfortunately, your Helium license is invalid. Please obtain a new one from\n\thttp://heliumhq.com'
  def __init__(self, bfs11232, bfs11170, bfs11234, bfs11233, seed=None):
    self.bfs11063 = bfs11232.read()
    self.bfs11232 = bfs11232
    self.bfs11170 = bfs11170
    self.bfs11234 = bfs11234
    self.bfs11233 = bfs11233
    self.random = Random(seed)
    self.bfs11235 = None

  def bfs11217(self, bfs11236):
    if (self.bfs11235 is None):
      self.bfs11235 = self.bfs11237(bfs11236)

    return self.bfs11235

  def bfs11237(self, bfs11241):
    if self.bfs11240():
      return bfs11221(False, self.bfs11227)

    if self.bfs11242():
      return self.bfs11243(bfs11241)

    return bfs11221(True, ('Licensed to ' + self.bfs11063.bfs10214))

  def bfs11240(self):
    bfs11244 = self.bfs11234.bfs11246()
    return self.bfs11063.bfs11102(bfs11244)

  def bfs11242(self):
    if self.bfs11063.bfs10211:
      if (not self.bfs11063.bfs11101()):
        return True

      if self.bfs11245():
        return True


    if self.bfs11063.is_online:
      return (self.bfs11233 or (self.random.random() <= 0.05))

    return False

  def bfs11245(self):
    bfs11247 = self.bfs11170.bfs10213()
    bfs11250 = self.bfs11063.bfs11074
    return (bfs11247 != bfs11250)

  def bfs11243(self, bfs11251):
    bfs11253 = bfs11251.bfs10206(self.bfs11063, self.bfs11170)
    bfs10211 = self.bfs11063.bfs10211
    if (not bfs11253):
      if (bfs10211 and self.bfs11245()):
        return bfs11221(False, self.bfs11231)
      else:
        return bfs11221(False, self.bfs11230)

    else:
      if (bfs11253 == self.bfs11225):
        bfs11252 = (not bfs10211)
      else:
        if (not bfs10211):
          bfs11252 = False
        else:
          try:
            self.bfs11063.bfs11103(bfs11253)
          except ValueError as bfs11254:
            raise bfs10174(bfs11254)

          bfs11252 = (not self.bfs11245())
          if bfs11252:
            try:
              self.bfs11232.write(self.bfs11063)
            except (OSError, IOError):
              bfs10107.warn(('Could not write to license file %s.' % self.bfs11232.file_path), exc_info=True)




      if bfs11252:
        message = ('Licensed to ' + self.bfs11063.bfs10214)
      else:
        message = self.bfs11230


    return bfs11221(bfs11252, message)


class bfs11221(object):
  def __init__(self, bfs11217, message):
    self.bfs11217 = bfs11217
    self.message = message

  def __bool__(self):
    return self.bfs11217


