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, bfs11316):
    bfs11315 = self.bfs11317(bfs11316)
    if (not bfs11315):
      raise LicenseInvalid(bfs11315.message)


  def bfs11317(self, bfs11320):
    raise NotImplementedError()


class bfs11321(License):
  def bfs11317(self, bfs11322):
    return bfs11323(True, 'Development license (eternally valid).')


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

  def bfs11317(self, bfs11337):
    if (self.bfs11336 is None):
      self.bfs11336 = self.bfs11341(bfs11337)

    return self.bfs11336

  def bfs11341(self, bfs11340):
    if self.bfs11342():
      return bfs11323(False, self.bfs11327)

    if self.bfs11343():
      return self.bfs11344(bfs11340)

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

  def bfs11342(self):
    bfs11346 = self.bfs11335.bfs11345()
    return self.bfs10230.bfs11160(bfs11346)

  def bfs11343(self):
    if self.bfs10230.bfs10231:
      if (not self.bfs10230.bfs11162()):
        return True

      if self.bfs11347():
        return True


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

    return False

  def bfs11347(self):
    bfs11350 = self.bfs10227.bfs10232()
    bfs11351 = self.bfs10230.bfs11153
    return (bfs11350 != bfs11351)

  def bfs11344(self, bfs11352):
    bfs11353 = bfs11352.bfs10224(self.bfs10230, self.bfs10227)
    bfs10231 = self.bfs10230.bfs10231
    if (not bfs11353):
      if (bfs10231 and self.bfs11347()):
        return bfs11323(False, self.bfs11331)
      else:
        return bfs11323(False, self.bfs11332)

    else:
      if (bfs11353 == self.bfs11330):
        bfs11355 = (not bfs10231)
      else:
        if (not bfs10231):
          bfs11355 = False
        else:
          try:
            self.bfs10230.bfs11163(bfs11353)
          except ValueError, bfs11354:
            raise bfs10201(bfs11354)

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




      if bfs11355:
        message = ('Licensed to ' + self.bfs10230.bfs10233)
      else:
        message = self.bfs11332


    return bfs11323(bfs11355, message)


class bfs11323(object):
  def __init__(self, bfs11317, message):
    self.bfs11317 = bfs11317
    self.message = message

  def __nonzero__(self):
    return self.bfs11317


