コード例 #1
0
ファイル: test_message.py プロジェクト: silentsound/baiocas
 def test_to_json(self):
     assert Message.to_json([]) == dumps([])
     message = Message(channel='/test', id='1')
     assert Message.to_json(message) == dumps([message])
     messages = [
         Message(channel='/test1', id='1'),
         Message(channel='/test2', id='2')
     ]
     assert Message.to_json(messages) == dumps(messages)
コード例 #2
0
 def test_to_json(self):
     assert Message.to_json([]) == dumps([])
     message = Message(channel='/test', id='1')
     assert Message.to_json(message) == dumps([message])
     messages = [
         Message(channel='/test1', id='1'),
         Message(channel='/test2', id='2')
     ]
     assert Message.to_json(messages) == dumps(messages)
コード例 #3
0
ファイル: long_polling.py プロジェクト: silentsound/baiocas
    def _prepare_request(self, messages):

        # Determine the URL for the messages
        url = self.url
        if self._append_message_type and len(messages) == 1 and messages[0].channel.is_meta():
            message_type = '/'.join(messages[0].channel.parts()[1:])
            if not url.endswith('/'):
                url += '/'
            url += message_type

        # Get the headers for the request
        headers = HTTPHeaders()
        for header, values in self.get_headers().iteritems():
            for value in values:
                headers.add(header, value)
        for header, value in headers.get_all():
            self.log.debug('Request header %s: %s' % (header, value))

        # Get the body for the request
        body = Message.to_json(messages, encoding='utf8')
        self.log.debug('Request body (length: %d): %s' % (len(body), body))

        # Get the timeout (in seconds)
        timeout = self.get_timeout(messages) / 1000.0
        self.log.debug('Request timeout: %ss' % timeout)

        # Build and return the request
        return HTTPRequest(
            url,
            method='POST',
            headers=headers,
            body=body,
            connect_timeout=timeout,
            request_timeout=timeout
        )
コード例 #4
0
ファイル: long_polling.py プロジェクト: ViViDboarder/baiocas
    def _prepare_request(self, messages):

        # Determine the URL for the messages
        url = self.url
        if self._append_message_type and len(messages) == 1 and messages[0].channel.is_meta():
            message_type = '/'.join(messages[0].channel.parts()[1:])
            if not url.endswith('/'):
                url += '/'
            url += message_type

        # Get the headers for the request
        headers = HTTPHeaders()
        for header, values in self.get_headers().items():
            for value in values:
                headers.add(header, value)
        for header, value in headers.get_all():
            self.log.debug('Request header %s: %s' % (header, value))

        # Get the body for the request
        body = Message.to_json(messages, encoding='utf8')
        self.log.debug('Request body (length: %d): %s' % (len(body), body))

        # Get the timeout (in seconds)
        timeout = self.get_timeout(messages) / 1000.0
        self.log.debug('Request timeout: %ss' % timeout)

        # Build and return the request
        return HTTPRequest(
            url,
            method='POST',
            headers=headers,
            body=body,
            connect_timeout=timeout,
            request_timeout=timeout
        )
コード例 #5
0
ファイル: test_message.py プロジェクト: silentsound/baiocas
 def test_to_json_with_encoding(self):
     message = Message(channel=u'/caf\xe9', id='1')
     value = dumps([message], ensure_ascii=False).encode('utf8')
     assert Message.to_json(message, encoding='utf8') == value
コード例 #6
0
 def test_to_json_with_encoding(self):
     message = Message(channel='/caf\xe9', id='1')
     value = dumps([message], ensure_ascii=False).encode('utf8')
     assert Message.to_json(message, encoding='utf8') == value