from bfs.bfs10101.bfs10102 import LicenseInvalid
from helium.bfs10101.bfs10102 import bfs10136
from logging import getLogger
from random import Random
class License(object):
  def bfs10360(self, bfs10144):
    bfs10063 = self.bfs11003(bfs10144)
    if (not bfs10063):
      raise LicenseInvalid(bfs10063.message)


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


class bfs11005(License):
  def bfs11003(self, bfs10144):
    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, bfs10147, bfs11020, bfs11017, seed=None):
    self.bfs10145 = bfs11016.read()
    self.bfs11016 = bfs11016
    self.bfs10147 = bfs10147
    self.bfs11020 = bfs11020
    self.bfs11017 = bfs11017
    self.random = Random(seed)
    self.bfs11021 = None

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

    return self.bfs11021

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

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

    return bfs11007(True, ('Licensed to ' + self.bfs10145.bfs10154))

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

  def bfs11024(self):
    if self.bfs10145.bfs10152:
      if (not self.bfs10145.bfs10670()):
        return True

      if self.bfs11031():
        return True


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

    return False

  def bfs11031(self):
    bfs11030 = self.bfs10147.bfs10151()
    bfs11032 = self.bfs10145.bfs10662
    return (bfs11030 != bfs11032)

  def bfs11025(self, bfs10144):
    bfs10171 = bfs10144.bfs10146(self.bfs10145, self.bfs10147)
    bfs10152 = self.bfs10145.bfs10152
    if (not bfs10171):
      if (bfs10152 and self.bfs11031()):
        return bfs11007(False, self.bfs11014)
      else:
        return bfs11007(False, self.bfs11015)

    else:
      if (bfs10171 == self.bfs11011):
        bfs10063 = (not bfs10152)
      else:
        if (not bfs10152):
          bfs10063 = False
        else:
          try:
            self.bfs10145.bfs10667(bfs10171)
          except ValueError as bfs11033:
            raise bfs10136(bfs11033)

          bfs10063 = (not self.bfs11031())
          if bfs10063:
            try:
              self.bfs11016.write(self.bfs10145)
            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.bfs10145.bfs10154)
      else:
        message = self.bfs11015


    return bfs11007(bfs10063, message)


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

  def __bool__(self):
    return self.bfs11003


