from bfs.bfs10135.errors import bfs10141
from helium.bfs10135.errors import bfs10174
from random import Random
import logging
bfs10107 = logging.getLogger(__name__)
bfs10107.setLevel(logging.INFO)
class License(object):
  def bfs10456(self, bfs11205):
    bfs11204 = self.bfs11206(bfs11205)
    if (not bfs11204):
      raise bfs10141(bfs11204.message)


  def bfs11206(self, bfs11210):
    raise NotImplementedError()


class bfs11207(License):
  def bfs11206(self, bfs11211):
    return bfs11212(True, 'Development license (eternally valid).')


class bfs11213(License):
  bfs11214 = 0
  bfs11215 = 1
  bfs11217 = 'dstn;heaf402321'
  bfs11216 = 'Unfortunately, your Helium license has expired. Please obtain a new one from\n\thttp://heliumhq.com'
  bfs11220 = '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'
  bfs11222 = 'Unfortunately, your Helium license is invalid. Please obtain a new one from\n\thttp://heliumhq.com'
  def __init__(self, bfs11221, bfs11157, bfs11223, bfs11224, seed=None):
    self.bfs11054 = bfs11221.read()
    self.bfs11221 = bfs11221
    self.bfs11157 = bfs11157
    self.bfs11223 = bfs11223
    self.bfs11224 = bfs11224
    self.random = Random(seed)
    self.bfs11226 = None

  def bfs11206(self, bfs11225):
    if (self.bfs11226 is None):
      self.bfs11226 = self.bfs11227(bfs11225)

    return self.bfs11226

  def bfs11227(self, bfs11231):
    if self.bfs11230():
      return bfs11212(False, self.bfs11216)

    if self.bfs11232():
      return self.bfs11234(bfs11231)

    return bfs11212(True, ('Licensed to ' + self.bfs11054.bfs10214))

  def bfs11230(self):
    bfs11233 = self.bfs11223.bfs11235()
    return self.bfs11054.bfs11071(bfs11233)

  def bfs11232(self):
    if self.bfs11054.bfs10211:
      if (not self.bfs11054.bfs11073()):
        return True

      if self.bfs11236():
        return True


    if self.bfs11054.is_online:
      return (self.bfs11224 or (self.random.random() <= 0.05))

    return False

  def bfs11236(self):
    bfs11237 = self.bfs11157.bfs10213()
    bfs11241 = self.bfs11054.bfs11063
    return (bfs11237 != bfs11241)

  def bfs11234(self, bfs11240):
    bfs11242 = bfs11240.bfs10206(self.bfs11054, self.bfs11157)
    bfs10211 = self.bfs11054.bfs10211
    if (not bfs11242):
      if (bfs10211 and self.bfs11236()):
        return bfs11212(False, self.bfs11220)
      else:
        return bfs11212(False, self.bfs11222)

    else:
      if (bfs11242 == self.bfs11217):
        bfs11243 = (not bfs10211)
      else:
        if (not bfs10211):
          bfs11243 = False
        else:
          try:
            self.bfs11054.bfs11072(bfs11242)
          except ValueError, bfs11244:
            raise bfs10174(bfs11244)

          bfs11243 = (not self.bfs11236())
          if bfs11243:
            try:
              self.bfs11221.write(self.bfs11054)
            except (OSError, IOError):
              bfs10107.warn(('Could not write to license file %s.' % self.bfs11221.file_path), exc_info=True)




      if bfs11243:
        message = ('Licensed to ' + self.bfs11054.bfs10214)
      else:
        message = self.bfs11222


    return bfs11212(bfs11243, message)


class bfs11212(object):
  def __init__(self, bfs11206, message):
    self.bfs11206 = bfs11206
    self.message = message

  def __nonzero__(self):
    return self.bfs11206


