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, bfs11232):
    bfs11234 = self.bfs11233(bfs11232)
    if (not bfs11234):
      raise bfs10136(bfs11234.message)


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


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


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

  def bfs11233(self, bfs11254):
    if (self.bfs11252 is None):
      self.bfs11252 = self.bfs11256(bfs11254)

    return self.bfs11252

  def bfs11256(self, bfs11255):
    if self.bfs11257():
      return bfs11241(False, self.bfs11246)

    if self.bfs11261():
      return self.bfs11260(bfs11255)

    return bfs11241(True, ('Licensed to ' + self.bfs11073.bfs10213))

  def bfs11257(self):
    bfs11262 = self.bfs11251.bfs11263()
    return self.bfs11073.bfs11106(bfs11262)

  def bfs11261(self):
    if self.bfs11073.bfs10210:
      if (not self.bfs11073.bfs11110()):
        return True

      if self.bfs11265():
        return True


    if self.bfs11073.is_online:
      return (self.bfs11253 or (self.random.random() <= 0.05))

    return False

  def bfs11265(self):
    bfs11264 = self.bfs11175.bfs10212()
    bfs11266 = self.bfs11073.bfs11101
    return (bfs11264 != bfs11266)

  def bfs11260(self, bfs11267):
    bfs11270 = bfs11267.bfs10203(self.bfs11073, self.bfs11175)
    bfs10210 = self.bfs11073.bfs10210
    if (not bfs11270):
      if (bfs10210 and self.bfs11265()):
        return bfs11241(False, self.bfs11245)
      else:
        return bfs11241(False, self.bfs11247)

    else:
      if (bfs11270 == self.bfs11244):
        bfs11271 = (not bfs10210)
      else:
        if (not bfs10210):
          bfs11271 = False
        else:
          try:
            self.bfs11073.bfs11112(bfs11270)
          except ValueError, bfs11273:
            raise bfs10171(bfs11273)

          bfs11271 = (not self.bfs11265())
          if bfs11271:
            try:
              self.bfs11250.write(self.bfs11073)
            except (OSError, IOError):
              bfs10106.warn(('Could not write to license file %s.' % self.bfs11250.file_path), exc_info=True)




      if bfs11271:
        message = ('Licensed to ' + self.bfs11073.bfs10213)
      else:
        message = self.bfs11247


    return bfs11241(bfs11271, message)


class bfs11241(object):
  def __init__(self, bfs11233, message):
    self.bfs11233 = bfs11233
    self.message = message

  def __nonzero__(self):
    return self.bfs11233


