Exemplo n.º 1
0
  def flush(self, scheduled=False):
    if scheduled:
      self.schedule = None
      
    if not self.buffer or not self.subscriptions:
      return
        
    t = time.time()
    
    if t < self.throttle:
      if not self.schedule:
        self.schedule = reactor.callLater(self.throttle - t, self.flush, True)
      return
    else:
      # process the rest of the packet
      if not scheduled:
        if not self.schedule:
          self.schedule = reactor.callLater(0, self.flush, True)
        return
        
    self.throttle = t + config.UPDATE_FREQ

    encdata = json.dumps(self.buffer)
    self.buffer = []
    self.buflen = 0

    newsubs = []
    for x in self.subscriptions:
      if x.write(encdata):
        newsubs.append(x)

    self.subscriptions = newsubs
    if self.closed and not self.subscriptions:
      cleanupSession(self.id)
Exemplo n.º 2
0
def get_options():
  options = dict(
    networkName=config.NETWORK_NAME,
    networkServices=[config.AUTH_SERVICE],
    loginRegex=config.AUTH_OK_REGEX,
    appTitle=config.APP_TITLE,
    baseURL=config.BASE_URL,
    staticBaseURL=config.STATIC_BASE_URL,
    dynamicBaseURL=config.DYNAMIC_BASE_URL,
    validateNickname=False
  )
  
  if hasattr(config, "NICKNAME_VALIDATE") and config.NICKNAME_VALIDATE:
    options["nickValidation"] = dict(
      minLen=config.NICKNAME_MINIMUM_LENGTH,
      maxLen=config.NICKNAME_MAXIMUM_LENGTH,
      validFirstChar=config.NICKNAME_VALID_FIRST_CHAR,
      validSubChars=config.NICKNAME_VALID_SUBSEQUENT_CHARS
    )
    
  return json.dumps(options)
Exemplo n.º 3
0
  return md5.md5(os.urandom(16)).hexdigest()

class BufferOverflowException(Exception):
  pass

class AJAXException(Exception):
  pass
  
class IDGenerationException(Exception):
  pass

class PassthruException(Exception):
  pass
  
NOT_DONE_YET = None
EMPTY_JSON_LIST = json.dumps([])

def jsondump(fn):
  def decorator(*args, **kwargs):
    try:
      x = fn(*args, **kwargs)
      if x is None:
        return server.NOT_DONE_YET
      x = (True, x)
    except AJAXException, e:
      x = (False, e[0])
    except PassthruException, e:
      return str(e)
      
    return json.dumps(x)
  return decorator