from bfs.bfs10143.bfs10147 import LicenseInvalid
from helium.bfs10143.bfs10147 import bfs10201
from logging import getLogger
from random import Random
class License(object):
  def bfs10523(self, bfs11320):
    bfs11321 = self.bfs11322(bfs11320)
    if (not bfs11321):
      raise LicenseInvalid(bfs11321.message)


  def bfs11322(self, bfs11323):
    raise NotImplementedError()


class bfs11325(License):
  def bfs11322(self, bfs11324):
    return bfs11326(True, 'Development license (eternally valid).')


class bfs11330(License):
  bfs11327 = 0
  bfs11331 = 1
  bfs11332 = 'dstn;heaf402321'
  bfs11333 = 'Unfortunately, your Helium license has expired. Please obtain a new one from\n\thttp://heliumhq.com'
  bfs11335 = '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'
  bfs11334 = 'Unfortunately, your Helium license is invalid. Please obtain a new one from\n\thttp://heliumhq.com'
  def __init__(self, bfs11336, bfs10227, bfs11337, bfs11341, seed=None):
    self.bfs10230 = bfs11336.read()
    self.bfs11336 = bfs11336
    self.bfs10227 = bfs10227
    self.bfs11337 = bfs11337
    self.bfs11341 = bfs11341
    self.random = Random(seed)
    self.bfs11340 = None

  def bfs11322(self, bfs11342):
    if (self.bfs11340 is None):
      self.bfs11340 = self.bfs11343(bfs11342)

    return self.bfs11340

  def bfs11343(self, bfs11344):
    if self.bfs11346():
      return bfs11326(False, self.bfs11333)

    if self.bfs11345():
      return self.bfs11347(bfs11344)

    return bfs11326(True, ('Licensed to ' + self.bfs10230.bfs10233))

  def bfs11346(self):
    bfs11350 = self.bfs11337.bfs11351()
    return self.bfs10230.bfs11165(bfs11350)

  def bfs11345(self):
    if self.bfs10230.bfs10231:
      if (not self.bfs10230.bfs11164()):
        return True

      if self.bfs11352():
        return True


    if self.bfs10230.is_online:
      return (self.bfs11341 or (self.random.random() <= 0.05))

    return False

  def bfs11352(self):
    bfs11353 = self.bfs10227.bfs10232()
    bfs11355 = self.bfs10230.bfs11157
    return (bfs11353 != bfs11355)

  def bfs11347(self, bfs11354):
    bfs11356 = bfs11354.bfs10224(self.bfs10230, self.bfs10227)
    bfs10231 = self.bfs10230.bfs10231
    if (not bfs11356):
      if (bfs10231 and self.bfs11352()):
        return bfs11326(False, self.bfs11335)
      else:
        return bfs11326(False, self.bfs11334)

    else:
      if (bfs11356 == self.bfs11332):
        bfs11360 = (not bfs10231)
      else:
        if (not bfs10231):
          bfs11360 = False
        else:
          try:
            self.bfs10230.bfs11166(bfs11356)
          except ValueError as bfs11357:
            raise bfs10201(bfs11357)

          bfs11360 = (not self.bfs11352())
          if bfs11360:
            try:
              self.bfs11336.write(self.bfs10230)
            except (OSError, IOError):
              getLogger(__name__).warn('Could not write to license file %s.', self.bfs11336.file_path, exc_info=True)




      if bfs11360:
        message = ('Licensed to ' + self.bfs10230.bfs10233)
      else:
        message = self.bfs11334


    return bfs11326(bfs11360, message)


class bfs11326(object):
  def __init__(self, bfs11322, message):
    self.bfs11322 = bfs11322
    self.message = message

  def __bool__(self):
    return self.bfs11322


