from bfs.bfs10131.errors import bfs10136
from helium.bfs10131.errors import bfs10171
from random import Random
import logging
bfs10106 = logging.getLogger(__name__)
bfs10106.setLevel(logging.INFO)
class License(object):
  def bfs10470(self, bfs11230):
    bfs11232 = self.bfs11234(bfs11230)
    if (not bfs11232):
      raise bfs10136(bfs11232.message)


  def bfs11234(self, bfs11233):
    raise NotImplementedError()


class bfs11235(License):
  def bfs11234(self, bfs11236):
    return bfs11237(True, 'Development license (eternally valid).')


class bfs11241(License):
  bfs11240 = 0
  bfs11242 = 1
  bfs11243 = 'dstn;heaf402321'
  bfs11244 = 'Unfortunately, your Helium license has expired. Please obtain a new one from\n\thttp://heliumhq.com'
  bfs11246 = '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'
  bfs11245 = 'Unfortunately, your Helium license is invalid. Please obtain a new one from\n\thttp://heliumhq.com'
  def __init__(self, bfs11247, bfs11174, bfs11250, bfs11251, seed=None):
    self.bfs11071 = bfs11247.read()
    self.bfs11247 = bfs11247
    self.bfs11174 = bfs11174
    self.bfs11250 = bfs11250
    self.bfs11251 = bfs11251
    self.random = Random(seed)
    self.bfs11253 = None

  def bfs11234(self, bfs11252):
    if (self.bfs11253 is None):
      self.bfs11253 = self.bfs11254(bfs11252)

    return self.bfs11253

  def bfs11254(self, bfs11256):
    if self.bfs11255():
      return bfs11237(False, self.bfs11244)

    if self.bfs11257():
      return self.bfs11261(bfs11256)

    return bfs11237(True, ('Licensed to ' + self.bfs11071.bfs10213))

  def bfs11255(self):
    bfs11260 = self.bfs11250.bfs11262()
    return self.bfs11071.bfs11107(bfs11260)

  def bfs11257(self):
    if self.bfs11071.bfs10210:
      if (not self.bfs11071.bfs11106()):
        return True

      if self.bfs11263():
        return True


    if self.bfs11071.is_online:
      return (self.bfs11251 or (self.random.random() <= 0.05))

    return False

  def bfs11263(self):
    bfs11265 = self.bfs11174.bfs10212()
    bfs11264 = self.bfs11071.bfs11102
    return (bfs11265 != bfs11264)

  def bfs11261(self, bfs11266):
    bfs11267 = bfs11266.bfs10203(self.bfs11071, self.bfs11174)
    bfs10210 = self.bfs11071.bfs10210
    if (not bfs11267):
      if (bfs10210 and self.bfs11263()):
        return bfs11237(False, self.bfs11246)
      else:
        return bfs11237(False, self.bfs11245)

    else:
      if (bfs11267 == self.bfs11243):
        bfs11270 = (not bfs10210)
      else:
        if (not bfs10210):
          bfs11270 = False
        else:
          try:
            self.bfs11071.bfs11110(bfs11267)
          except ValueError as bfs11271:
            raise bfs10171(bfs11271)

          bfs11270 = (not self.bfs11263())
          if bfs11270:
            try:
              self.bfs11247.write(self.bfs11071)
            except (OSError, IOError):
              bfs10106.warn(('Could not write to license file %s.' % self.bfs11247.file_path), exc_info=True)




      if bfs11270:
        message = ('Licensed to ' + self.bfs11071.bfs10213)
      else:
        message = self.bfs11245


    return bfs11237(bfs11270, message)


class bfs11237(object):
  def __init__(self, bfs11234, message):
    self.bfs11234 = bfs11234
    self.message = message

  def __bool__(self):
    return self.bfs11234


