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, bfs11313):
    bfs11312 = self.bfs11314(bfs11313)
    if (not bfs11312):
      raise LicenseInvalid(bfs11312.message)


  def bfs11314(self, bfs11316):
    raise NotImplementedError()


class bfs11315(License):
  def bfs11314(self, bfs11317):
    return bfs11320(True, 'Development license (eternally valid).')


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

  def bfs11314(self, bfs11335):
    if (self.bfs11333 is None):
      self.bfs11333 = self.bfs11334(bfs11335)

    return self.bfs11333

  def bfs11334(self, bfs11336):
    if self.bfs11337():
      return bfs11320(False, self.bfs11324)

    if self.bfs11341():
      return self.bfs11340(bfs11336)

    return bfs11320(True, ('Licensed to ' + self.bfs11140.bfs10233))

  def bfs11337(self):
    bfs11342 = self.bfs11331.bfs11343()
    return self.bfs11140.bfs11155(bfs11342)

  def bfs11341(self):
    if self.bfs11140.bfs10231:
      if (not self.bfs11140.bfs11156()):
        return True

      if self.bfs11344():
        return True


    if self.bfs11140.is_online:
      return (self.bfs11332 or (self.random.random() <= 0.05))

    return False

  def bfs11344(self):
    bfs11346 = self.bfs11243.bfs10232()
    bfs11345 = self.bfs11140.bfs11150
    return (bfs11346 != bfs11345)

  def bfs11340(self, bfs11347):
    bfs11350 = bfs11347.bfs10224(self.bfs11140, self.bfs11243)
    bfs10231 = self.bfs11140.bfs10231
    if (not bfs11350):
      if (bfs10231 and self.bfs11344()):
        return bfs11320(False, self.bfs11326)
      else:
        return bfs11320(False, self.bfs11330)

    else:
      if (bfs11350 == self.bfs11325):
        bfs11351 = (not bfs10231)
      else:
        if (not bfs10231):
          bfs11351 = False
        else:
          try:
            self.bfs11140.bfs11157(bfs11350)
          except ValueError, bfs11352:
            raise bfs10201(bfs11352)

          bfs11351 = (not self.bfs11344())
          if bfs11351:
            try:
              self.bfs11327.write(self.bfs11140)
            except (OSError, IOError):
              getLogger(__name__).warn('Could not write to license file %s.', self.bfs11327.file_path, exc_info=True)




      if bfs11351:
        message = ('Licensed to ' + self.bfs11140.bfs10233)
      else:
        message = self.bfs11330


    return bfs11320(bfs11351, message)


class bfs11320(object):
  def __init__(self, bfs11314, message):
    self.bfs11314 = bfs11314
    self.message = message

  def __nonzero__(self):
    return self.bfs11314


