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, bfs11303):
    bfs11305 = self.bfs11306(bfs11303)
    if (not bfs11305):
      raise LicenseInvalid(bfs11305.message)


  def bfs11306(self, bfs11310):
    raise NotImplementedError()


class bfs11307(License):
  def bfs11306(self, bfs11311):
    return bfs11313(True, 'Development license (eternally valid).')


class bfs11312(License):
  bfs11314 = 0
  bfs11316 = 1
  bfs11315 = 'dstn;heaf402321'
  bfs11317 = 'Unfortunately, your Helium license has expired. Please obtain a new one from\n\thttp://heliumhq.com'
  bfs11320 = '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'
  bfs11321 = 'Unfortunately, your Helium license is invalid. Please obtain a new one from\n\thttp://heliumhq.com'
  def __init__(self, bfs11322, bfs11235, bfs11323, bfs11325, seed=None):
    self.bfs11132 = bfs11322.read()
    self.bfs11322 = bfs11322
    self.bfs11235 = bfs11235
    self.bfs11323 = bfs11323
    self.bfs11325 = bfs11325
    self.random = Random(seed)
    self.bfs11324 = None

  def bfs11306(self, bfs11326):
    if (self.bfs11324 is None):
      self.bfs11324 = self.bfs11330(bfs11326)

    return self.bfs11324

  def bfs11330(self, bfs11327):
    if self.bfs11331():
      return bfs11313(False, self.bfs11317)

    if self.bfs11332():
      return self.bfs11333(bfs11327)

    return bfs11313(True, ('Licensed to ' + self.bfs11132.bfs10233))

  def bfs11331(self):
    bfs11335 = self.bfs11323.bfs11334()
    return self.bfs11132.bfs11147(bfs11335)

  def bfs11332(self):
    if self.bfs11132.bfs10231:
      if (not self.bfs11132.bfs11150()):
        return True

      if self.bfs11336():
        return True


    if self.bfs11132.is_online:
      return (self.bfs11325 or (self.random.random() <= 0.05))

    return False

  def bfs11336(self):
    bfs11337 = self.bfs11235.bfs10232()
    bfs11341 = self.bfs11132.bfs11142
    return (bfs11337 != bfs11341)

  def bfs11333(self, bfs11340):
    bfs11342 = bfs11340.bfs10224(self.bfs11132, self.bfs11235)
    bfs10231 = self.bfs11132.bfs10231
    if (not bfs11342):
      if (bfs10231 and self.bfs11336()):
        return bfs11313(False, self.bfs11320)
      else:
        return bfs11313(False, self.bfs11321)

    else:
      if (bfs11342 == self.bfs11315):
        bfs11343 = (not bfs10231)
      else:
        if (not bfs10231):
          bfs11343 = False
        else:
          try:
            self.bfs11132.bfs11151(bfs11342)
          except ValueError, bfs11344:
            raise bfs10201(bfs11344)

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




      if bfs11343:
        message = ('Licensed to ' + self.bfs11132.bfs10233)
      else:
        message = self.bfs11321


    return bfs11313(bfs11343, message)


class bfs11313(object):
  def __init__(self, bfs11306, message):
    self.bfs11306 = bfs11306
    self.message = message

  def __nonzero__(self):
    return self.bfs11306


