Beispiel #1
0
 def __init__(self, config, url):
     super(HTTPComm, self).__init__()
     self.config = config
     self.lastpoll = -1
     self.url = url
     self.own_msgids = set()
     self.http_interface = HTTPInterface()
Beispiel #2
0
class HTTPComm(CommBase):

  def __init__(self, config, url):
    super(HTTPComm, self).__init__()
    self.config = config
    self.lastpoll = -1
    self.url = url
    self.own_msgids = set()
    self.http_interface = HTTPInterface()

  def post_message(self, content):
    msgid = make_random_id()
    content['msgid'] = msgid
    self.own_msgids.add(msgid)
    return self.http_interface.post(self.url, content)
  
  def poll(self):
    messages = []
    url = self.url
    if self.lastpoll == -1:
      interval = self.config['offer_expiry_interval']
      url = url + "?from_timestamp_rel=%s" % interval
    else:
      url = url + '?from_serial=%s' % (self.lastpoll+1)
    for envelope in self.http_interface.poll(url):
      if int(envelope.get('serial',0)) > self.lastpoll: 
        self.lastpoll = int(envelope.get('serial',0))
      content = envelope.get('content',None)
      if content and content.get('msgid', '') not in self.own_msgids:
        messages.append(content)
    return messages
Beispiel #3
0
class HTTPComm(CommBase):
    def __init__(self, config, url):
        super(HTTPComm, self).__init__()
        self.config = config
        self.lastpoll = -1
        self.url = url
        self.own_msgids = set()
        self.http_interface = HTTPInterface()

    def post_message(self, content):
        msgid = make_random_id()
        content['msgid'] = msgid
        self.own_msgids.add(msgid)
        return self.http_interface.post(self.url, content)

    def poll(self):
        messages = []
        url = self.url
        if self.lastpoll == -1:
            interval = self.config['offer_expiry_interval']
            url = url + "?from_timestamp_rel=%s" % interval
        else:
            url = url + '?from_serial=%s' % (self.lastpoll + 1)
        for envelope in self.http_interface.poll(url):
            if int(envelope.get('serial', 0)) > self.lastpoll:
                self.lastpoll = int(envelope.get('serial', 0))
            content = envelope.get('content', None)
            if content and content.get('msgid', '') not in self.own_msgids:
                messages.append(content)
        return messages
Beispiel #4
0
 def __init__(self, config, url):
   super(HTTPComm, self).__init__()
   self.config = config
   self.lastpoll = -1
   self.url = url
   self.own_msgids = set()
   self.http_interface = HTTPInterface()