from bfs.bfs10101.bfs10102 import bfs10105
from helium.bfs10101.bfs10102 import bfs10140
from logging import getLogger
from random import Random
class License(object):
  def bfs10362(self, bfs10147):
    bfs10063 = self.bfs11003(bfs10147)
    if (not bfs10063):
      raise bfs10105(bfs10063.message)


  def bfs11003(self, bfs10147):
    raise NotImplementedError()


class bfs11005(License):
  def bfs11003(self, bfs10147):
    return bfs11007(True, 'Development license (eternally valid).')


class bfs11006(License):
  bfs11010 = 0
  bfs11012 = 1
  bfs11011 = 'dstn;heaf402321'
  bfs11013 = 'Unfortunately, your Helium license has expired. Please obtain a new one from\n\thttp://heliumhq.com'
  bfs11014 = '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'
  bfs11015 = 'Unfortunately, your Helium license is invalid. Please obtain a new one from\n\thttp://heliumhq.com'
  def __init__(self, bfs11016, bfs10152, bfs11020, bfs11017, seed=None):
    self.bfs10150 = bfs11016.read()
    self.bfs11016 = bfs11016
    self.bfs10152 = bfs10152
    self.bfs11020 = bfs11020
    self.bfs11017 = bfs11017
    self.random = Random(seed)
    self.bfs11021 = None

  def bfs11003(self, bfs10147):
    if (self.bfs11021 is None):
      self.bfs11021 = self.bfs11023(bfs10147)

    return self.bfs11021

  def bfs11023(self, bfs10147):
    if self.bfs11022():
      return bfs11007(False, self.bfs11013)

    if self.bfs11024():
      return self.bfs11025(bfs10147)

    return bfs11007(True, ('Licensed to ' + self.bfs10150.bfs10156))

  def bfs11022(self):
    bfs11026 = self.bfs11020.bfs11027()
    return self.bfs10150.bfs10666(bfs11026)

  def bfs11024(self):
    if self.bfs10150.bfs10154:
      if (not self.bfs10150.bfs10670()):
        return True

      if self.bfs11031():
        return True


    if self.bfs10150.is_online:
      return (self.bfs11017 or (self.random.random() <= 0.05))

    return False

  def bfs11031(self):
    bfs11030 = self.bfs10152.bfs10155()
    bfs11032 = self.bfs10150.bfs10662
    return (bfs11030 != bfs11032)

  def bfs11025(self, bfs10147):
    bfs10173 = bfs10147.bfs10151(self.bfs10150, self.bfs10152)
    bfs10154 = self.bfs10150.bfs10154
    if (not bfs10173):
      if (bfs10154 and self.bfs11031()):
        return bfs11007(False, self.bfs11014)
      else:
        return bfs11007(False, self.bfs11015)

    else:
      if (bfs10173 == self.bfs11011):
        bfs10063 = (not bfs10154)
      else:
        if (not bfs10154):
          bfs10063 = False
        else:
          try:
            self.bfs10150.bfs10667(bfs10173)
          except ValueError, bfs11033:
            raise bfs10140(bfs11033)

          bfs10063 = (not self.bfs11031())
          if bfs10063:
            try:
              self.bfs11016.write(self.bfs10150)
            except (OSError, IOError):
              getLogger(__name__).warn('Could not write to license file %s.', self.bfs11016.file_path, exc_info=True)




      if bfs10063:
        message = ('Licensed to ' + self.bfs10150.bfs10156)
      else:
        message = self.bfs11015


    return bfs11007(bfs10063, message)


class bfs11007(object):
  def __init__(self, bfs11003, message):
    self.bfs11003 = bfs11003
    self.message = message

  def __nonzero__(self):
    return self.bfs11003


